Fix hatch-pet chroma-key halo and webp transparent-RGB loss#400
Open
shmulc8 wants to merge 1 commit into
Open
Conversation
Two related issues caused a magenta/chroma-key tinted halo around extracted pet sprites: 1. extract_strip_frames.remove_chroma_background only zeroed alpha on chroma-keyed pixels, leaving the original chroma RGB intact. The subsequent LANCZOS resize in fit_to_cell blends RGB and alpha independently, so transparent chroma-RGB neighbors leak color into sprite edges and create a visible tinted halo. Zero RGB together with alpha so the resize cannot pull chroma color into edges. 2. compose_atlas.save_outputs writes the WebP with lossless=True but without exact=True, which lets libwebp rewrite RGB on transparent pixels during compression. Pair lossless with exact so transparent- pixel RGB is preserved.
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.
Summary
Two related fixes in the curated
hatch-petskill that together cause a magenta (or other chroma-key) tinted halo around extracted pet sprites in the final spritesheet.Root cause
scripts/extract_strip_frames.py—remove_chroma_backgroundonly zeros alpha on chroma-keyed pixels and keeps the original RGB:The subsequent
fit_to_cellresize usesImage.Resampling.LANCZOS, which interpolates RGB and alpha independently. Transparent pixels still carrying chroma RGB then leak color into neighboring partially-opaque edge pixels during downscaling, producing a faint tinted halo (e.g.(127, 0, 127, 2),(85, 0, 85, 3)for a magenta key) around every sprite.scripts/compose_atlas.py—save_outputswrites the WebP atlas withlossless=Truebut withoutexact=True. Withoutexact=True, libwebp is free to overwrite RGB on fully-transparent pixels during compression for better packing. Combined with Update readme with initial text; add gitignore #1, this can also re-introduce non-zero RGB on alpha=0 pixels in the published atlas, which any renderer that ignores the alpha channel will display as solid chroma-key color.Fixes
remove_chroma_background, set chroma-keyed pixels to(0, 0, 0, 0)so the resize cannot pull chroma color into sprite edges.save_outputs, passexact=Truealongsidelossless=Trueso transparent-pixel RGB is preserved as-written.Both changes are tiny and surgical — no behavior change for non-chroma-key pixels.
Test plan
extract_strip_frames.pyon a strip with a magenta (#FF00FF) chroma-key background and verify post-extraction frames have no(R≈B, G≈0, alpha>0)pixels along sprite edges.compose_atlas.py --webp-output ...and verify with PIL that there are no chroma-family RGB values onalpha==0pixels in the saved WebP.