Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport the ClosestColor improvement from 7.1.0-58 to ImageMagick-6. #257

Merged
merged 3 commits into from
Aug 12, 2023

Conversation

yoya
Copy link
Contributor

@yoya yoya commented Aug 4, 2023

Prerequisites

  • I have written a descriptive pull-request title
  • I have verified that there are no overlapping pull-requests open
  • I have verified that I am following the existing coding patterns and practices as demonstrated in the repository.

Description

Backport the ClosestColor improvement from 7.1.0-58 to ImageMagick-6.
Only for alpha calculation and does not reflect Hue support reverting.

  • Since ImageMagick-6.9.12-71, the color reduction process for alpha images has been broken until 6 main:HEAD.
  • ImageMagick-7.1.0-56 had a similar breakage, which was fixed in ImageMagick-7.1.0-58
  • ImageMagick-7 ClosestColor function fix has not been backported to ImageMagick-6.

The difference is noticeable in images where RGB is flat and A is used to represent the vision

test image

% magick -size 640x480 xc:gray  \( logo: -type grayscale \)  \
          -compose CopyOpacity -composite  logo-trans.png
logo-trans.png (RGB component) (alpha component)
logo-trans logo-trans-noalpha logo-trans-alpha

-colors 2 behavior by version

% convert logo-trans.png -colors 2  colors2.png
... 6.9.12-70 6.9.12-71 ... 6.9.12-72 6.9.12-73 ... 6.9.12-93 main:HEAD
6 9 12-70-colors2 6 9 12-71-colors2 6 9 12-73-colors2
... 7.1.0-55 7.1.0-56 ... 7.1.0-57 7.1.0-58 ... 7.1.1-15 main:HEAD
7 1 0-55-colors2 7 1 1-15-colors2 7 1 0-58-colors2

reference code

remarks

I don't know why Hue support was reverted, so I have only ported the alpha calculation fixes in this commit.
If Hue needs to be addressed as well, someone please make an additional commit.

ImageMagick-7 changes the type of alpha, beta, and distance from MagickRealType to double, but I have not included it in the backporting because of the possibility that it was just caught up in the revert process.

@yoya
Copy link
Contributor Author

yoya commented Aug 4, 2023

I also backported hue support reverting, which is inseparable from the correction of the alpha calculation for color reduction.

@urban-warrior urban-warrior merged commit 3ca8d40 into ImageMagick:main Aug 12, 2023
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants