Emit coverage masks: merge brightness into alpha, flat colour in RGB - #100
Merged
Merged
Conversation
The pixel pipeline previously multiplied the target colour by the normalized brightness, so an anti-aliased or midtone pixel came out as a darker shade of the tint at full alpha. That output is only correct composited over black. Fold the brightness into the alpha channel instead and paint the colour channels flat, so the output is a coverage mask: every pixel carries exactly the target colour, and the whole shape, anti-aliasing included, lives in the alpha. Coverage is the product of the source alpha and the normalized intensity, so a half lit opaque pixel and a fully lit half transparent pixel both describe half coverage. Two consequences worth naming: - Transparent pixels are now painted with the target colour rather than zeroed. A uniform colour field gives Resize nothing to blend inward at the edges, which is what the zeroing was guarding against in the first place. - The bounding box is measured against the merged alpha rather than the source alpha. A region that flattens to black is now invisible rather than opaque black, so including it would pad the canvas out around artwork that is no longer there. Two gold masters change, the two fixtures carrying real tonal variation. The other six regenerate byte for byte, which confirms the change only touches artwork that had brightness to move. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vmky7mf8J6sb6TSDeEgQCM
Both still described the tool as producing a single-colour silhouette, which stopped being accurate with the coverage change. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vmky7mf8J6sb6TSDeEgQCM
SonarCloud flagged two code smells on the new coverage pass: - S3358, a nested ternary in the intensity calculation - S3776, cognitive complexity of 18 against the 15 allowed Pulling the per-pixel intensity out into its own method resolves both, and gives the three branches somewhere to explain themselves in prose rather than in a stacked conditional. Behaviour is unchanged: the gold masters still match byte for byte. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vmky7mf8J6sb6TSDeEgQCM
|
matt-edmondson
deleted the
claude/icon-brightness-alpha-blend-hobmed
branch
September 14, 2026 06:48
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



What changed
ProcessImagepreviously multiplied the target colour by the normalized brightness, so an anti-aliased or midtone pixel came out as a darker shade of the tint at full alpha. That output is only correct when composited over black.It now folds the brightness into the alpha channel and paints the colour channels flat, so the output is a coverage mask: every pixel carries exactly the target colour, and the whole shape — anti-aliasing included — lives in the alpha channel.
Coverage is the product of the two, so a half lit opaque pixel and a fully lit half transparent pixel both describe half coverage.
Two consequences worth calling out
Resizeinto a halo. A uniform colour field removes that failure mode entirely — every weighted average of one colour is that colour — so painting through is both simpler and strictly safer. The PNG encoder still clears those channels on write viaPngTransparentColorMode.Clear.--coloris unchanged and still selects the colour; it is simply flat across the output now. The alpha component of an#RRGGBBAAvalue is ignored, as it always was — now documented, since alpha is what carries the coverage.Gold masters
Two of the eight expectations change —
midtone-grey-shapeandcolorful-icon, the two fixtures carrying real tonal variation. The other six regenerate byte for byte, which confirms the change only touches artwork that had brightness to move.The diff was reviewed visually (old on the left, new on the right, over a checkerboard):
midtone-grey-shape: was a solid disc in a blue darker than the requested#3366CC; is now exactly#3366CCat partial coverage. Its source tops out at channel 95, so the normalization has only a dim pixel to scale against and the whole mask comes out translucent. That factor (184/255) was always there — it previously showed up as a darker colour instead of as transparency.colorful-icon: the dim circle was rendered dark red next to a bright red arrow; both are now flat#FF0000, with the circle at partial coverage and the arrow fully opaque.Regenerated with the same CLI invocations as
regenerate.ps1(PowerShell is not available in this environment, so the loop was run directly; the tool arguments are identical, so the bytes are).Tests
dotnet test— 69 passed, 0 failed, in both Debug and Release. Four new tests plus one rewritten:FoldsBrightnessIntoTheAlphaChannel— a white patch and a grey-80 patch come out at alpha 255 and 105 with identical RGBMultipliesSourceAlphaIntoTheCoverage— source alpha carries through into the coverageDropsUnlitArtworkFromTheCoverage— an unlit region falls outside the crop rather than padding it outPaintsEveryPixelTheFlatTargetColour— no pixel modulates the colour channelsNormalizesMidtoneArtworkUpToFullIntensity→...UpToFullCoverage— the old assertion became vacuous once RGB is flat, so it now asserts the alphaREADME and CLAUDE.md are updated to describe the coverage pipeline.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Vmky7mf8J6sb6TSDeEgQCM
Generated by Claude Code