Fix alpha-channel check in IsImageOnlyTransparent and CopyRectangle rect math#12579
Conversation
|
@niksedk Unfortunately, I hit an error while trying to use the custom Copilot setup steps configured for this repository and had to close this PR. The error I am seeing is: Once you or someone with the necessary access fixes the problem, please unassign and then reassign issue #0 to me and I'll retry. Thanks! |
There was a problem hiding this comment.
Pull request overview
This PR fixes several small but correctness-impacting issues in bitmap handling and HTML italic tag cleanup, improving OCR/image processing reliability and tag normalization.
Changes:
- Fix alpha-channel detection in
IsImageOnlyTransparentfor bothNikseBitmapand the OCR copyNikseBitmap2. - Correct
CopyRectangle(SKRect)to constructSKRectIusingRight/Bottomrather thanWidth/Height. - Fix duplicated
EndsWith(...)conditions inHtmlUtil.FixInvalidItalicTagsfor 2-line edge cases.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/libuilogic/Ocr/NikseBitmap2.cs | Fix alpha-byte indexing when checking transparency. |
| src/libse/Common/NikseBitmap.cs | Fix CopyRectangle(SKRect) rect construction and alpha-byte indexing for transparency checks. |
| src/libse/Common/HtmlUtil.cs | Fix incorrect line index usage in italic tag repair conditions. |
| var rect = new SKRectI((int)section.Left, (int)section.Top, (int)section.Right, (int)section.Bottom); | ||
| return CopyRectangle(rect); |
AI-generated bug fix pull requestsFor future AI-generated bug fix PRs, please limit each pull request to 1–3 related fixes (depending on their size and complexity). Smaller, focused PRs are much easier to review, test, and merge. Please also include a brief manual comment describing how you personally verified each fix. AI-generated code can contain mistakes or unintended side effects, so every submitted change should be tested and validated by the contributor before opening the PR. |
The loop tested _bitmapData[i] (blue in BGRA) instead of the alpha byte at i+3, so an opaque all-black image was reported as fully transparent. Fix both the libse and OCR-duplicate implementations. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The SKRectI constructor takes (left, top, right, bottom), but the overload passed Width/Height as the right/bottom coordinates, which is only correct when Left and Top are both 0. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The clamp statements had the same Rectangle(x, y, width, height) to SKRectI(left, top, right, bottom) porting bug as the SKRect overload: they passed width/height values as right/bottom. Clamp bottom to Height and right to Width directly, matching the SE 4 original's intent. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Pin the alpha-vs-blue regression (opaque black must not be "only transparent") for both NikseBitmap and the OCR NikseBitmap2, and the CopyRectangle offset/clamping rect math. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
96b431b to
b42230d
Compare
|
Thanks for the PR! The two bitmap fixes are verified and merged (with the The two
🤖 Generated with Claude Code |
…aired The two-line branches for "only four </i> tags" / "only four <i> tags" had an asymmetric condition (lines[1].EndsWith checked twice, lines[0]'s end never) - identical in SE 4, and load-bearing: shapes it matched were repaired to whole-line italics, but near-miss shapes (e.g. second line not starting with the tag, or all four tags on the first line) fell through and the function returned the invalid tags unchanged. Rather than tightening the condition (which would repair fewer shapes - see PR SubtitleEdit#12579 review), generalize it: under the count guard the stray tags carry no pairing information, so strip them from each line that contains one and wrap that line in proper <i>...</i>; tag-less lines are kept as-is. Output is byte-identical for every previously matched shape, and the fall-through shapes now come out as valid italics. Tests pin both the long-standing shapes and the newly repaired ones. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Verified fixes for latent bitmap bugs, plus tests pinning them:
NikseBitmap.IsImageOnlyTransparenttested the blue byte instead of alpha (_bitmapData[i]in BGRA data) — an opaque blue-less image (black/yellow/red/green text) was reported as fully transparent, dropping line parts in the OCR image splitter. The identical bug in the OCR duplicateNikseBitmap2is fixed in the same commit.NikseBitmap.CopyRectangle(SKRect)passed width/height intoSKRectI's (left, top, right, bottom) constructor — correct only when the section starts at the origin. The clamping statements in theSKRectIoverload had the sameRectangle(x, y, w, h)→SKRectI(l, t, r, b)porting bug and are fixed as a follow-up commit, matching the SE 4 original's clamp-to-bitmap intent.NikseBitmapandNikseBitmap2.The two
FixInvalidItalicTagscommits from the original version of this PR were dropped after review — see comment below.All 508 libse and 14 libuilogic tests pass.
🤖 Generated with Claude Code