Repository navigation
fix(modifiers): pivot the contrast adjustment on mid grey - #133
Merged
Merged
Conversation
The linear() call used 255 * (1 - a) as offset, which keeps white fixed and makes a positive level darken every tone below it. A light grey of 175 went down to 135 at level 50, where GD and Imagick push it up to about 234. Pivot on mid grey instead, on the value range that goes with the interpretation of the image, so 16-bit and scRGB sources get the same behavior as 8-bit ones.
Member
|
Thanks. |
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.
ContrastModifiercallslinear($a, $b)with$b = 255 * (1 - $a). That keeps white fixed, so a positive level darkens every tone below it instead of spreading them around mid grey. Measured on a flat grey image,contrast(50), red channel:The offset is now computed from mid grey. Mid grey depends on the interpretation of the image, the same ranges
RotateModifieruses: 65535 for RGB16/GREY16, 1 for scRGB, 255 otherwise. Without that a 16-bit source would pivot near black.The existing
testApplyexpected the darker color, so its value changes (0095ebto00bbff). New tests cover positive and negative levels, with and without alpha, and a 16-bit source.The effect is still weaker than GD and Imagick (175 goes to 198, not ~234). GD squares the factor and Imagick uses a sigmoid, I did not try to match either one. Happy to change it if you prefer one of them.