fix(plugin-color): compute sepia output channels from the original pixel#1412
Open
spokodev wants to merge 1 commit into
Open
fix(plugin-color): compute sepia output channels from the original pixel#1412spokodev wants to merge 1 commit into
spokodev wants to merge 1 commit into
Conversation
sepia overwrote red, then read that new red when computing green, then read the new red and green when computing blue, so the green and blue outputs were wrong for any non-grayscale pixel. Hold the original r, g, b and derive each output channel from them. Regenerate the sepia snapshot, which had captured the incorrect output.
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.
sepia()returns wrong colors for any non-grayscale pixel. The sepia matrix needs each output channel to be a linear combination of the original r, g, b, but the code overwritesredfirst, then computesgreenfrom the newred, thenbluefrom the newredandgreen:For a pure red pixel (255, 0, 0) the correct sepia output is (100, 88, 69); the current code returns (100, 34, 45).
This is a regression: the same bug was reported (#346) and fixed (#483) in 2018, and the v1 TypeScript rewrite reintroduced it.
Fix
Hold the original channels and derive each output from them, matching the merged 2018 fix.
Testing
Added a test that drives
sepiaagainst a known red pixel and asserts (100, 88, 69). It fails before this change. The existingpackages/jimpsepia snapshot had captured the buggy output (64-22-2D); it is rebuilt to the corrected values (64-58-45). Full plugin-color suite stays green.