Backtestshugorun-20261002-200313#12536
images: Opacity problem with Resize + Padding with PNG output
Better
Our patch was judged better than the merged fix.
In this judgment, Patch A = our agent, Patch B = the merged fix.
Both patches fix the same root cause. Hex color strings are parsed into `color.RGBA`, which Go treats as alpha-premultiplied. A transparent color like `#00f7` (B=0xff > A=0x77) is therefore an invalid premultiplied value and gets corrupted when drawn onto a PNG/RGBA destination. Both switch `hexStringToColorGo` to return `color.NRGBA` for transparent colors, and both make `ColorGoToHexString` and the luminance calculation read the non-premultiplied channels. Both regenerate the same `padding-transparent-chained.png` golden, so on the reported Resize + Padding + PNG scenario they are equivalent in correctness.
The differences are in scope, risk and tests.
Patch B bundles a separate behavioral change in `resources/image.go`. It skips source-palette clamping for every Filter action on paletted PNGs, which its own comment attributes to a different problem. This changes output for all filters on indexed PNGs: they no longer stay paletted, so file sizes and appearance change. It also required regenerating the `overlay.png` and `text.png` goldens. That is unrelated to the padding-opacity issue and adds regression risk.
Patch B also normalizes every `Color` to NRGBA inside `init()` and reworks `AddColorToPalette` equality. These are broader edits that ripple into palette handling. It also rewrites an existing test expectation (`color.RGBA{...,A:0x80}` -> `color.NRGBA`) instead of only adding coverage.
Patch A is minimal. It returns plain `RGBA` for opaque colors, preserving existing behavior, and `NRGBA` only for transparent ones. Its small `colorGoToRGBA8` helper is used consistently for hex output and luminance.
Patch A's tests are much stronger:
- Unit tests for parsing and hex round-tripping of transparent colors.
- A filter test checking padding and text draw identically onto premultiplied and non-premultiplied destinations.
- An end-to-end integration test that resizes to PNG, pads with `#00f7` and decodes the published file to assert the exact NRGBA pixel. This directly reproduces the issue scenario.
Patch B adds only a couple of parse-table entries and relies on golden images.
With equal core correctness, Patch A wins on its targeted scope, lower risk and substantially better tests.
The judge saw only the two patches, labelled A and B in random order, with issue links and version numbers removed. The reasoning above is shown verbatim.
Solve
1h 10m
Wall-clock time in the container
Full test suite
No new failures
3,760 passed · 99 skipped · 3,861 total
Contamination audit
Clean
No sign the agent saw the real fix
Patch size
175vs 58 merged
Changed lines, ours vs merged