-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Using -define tiff:alpha=associated
results in modified semi-transparent areas
#7578
Comments
Associated alpha "premultiplies", ie it multiples each colour sample by alpha before saving. If Associated does what you want apart from the premultiplying, then I suppose a workaround is to first divide the colour samples by alpha. Untested:
For non-opaque pixels When IM or Gimp reads this image, it is too bright. But it might be a workaround for Adobe InDesign. If this workaround works, then it would seem to be a problem with InDesign. |
@snibgo Thanks a lot for your quick reply! Unfortunately this does not work. It makes the colors brighter, but does not fix the semi-transparent areas ("revert-premultiply" is your script): I tried some things like this as a workaround, because my thinking was similar to yours, that the premultiplication does change the color values. But none of my tryouts worked either. The problem with InDesign is, that it does not seem to like non-associated tiff files. In Photoshop and Gimp those are correctly displayed. So I cannot blame IM for this. |
I've had a quick look at IM's source, and I don't think IM does any alpha associated or unassociated processing when saving TIFF files. It just sets a flag. I suppose the tiff library (libtiff) uses that flag. EDIT: Another experiment for you to try:
|
In IM 7, use magick, not magick convert. |
@snibgo Thanks for the additional tryouts, but they did not succeed unfortunately. By the way: The changes to the semi-transparent pixels are also visible in the Windows image preview and in Gimp as well. Probably in other image viewers as well, so it does not look like an InDesign issue. Can you point me to the IM source code, so I can have a look there as well? |
I put my detailed IM commands and the Gimp comparison into the discussion: #2839 (reply in thread) Would be great if anybody could try to reproduce the issue on her/his machine, so we can be sure that it is not a local, e.g. Windows or version problem. |
On this page, click on "Code" at top-left. Reading and writing tiffs is in coders/tiff.c. |
Using IM 7.1.1.37 on Mac OSX Ventura with libpng 1.6.39 and libtiff 4.6.0, the following produces virtually identical input PNG and output TIFFs
What are your versions of libpng and libtiff?. (especially the latter) |
I have libtiff 4.6.0 and libpng 1.6.43:
The unassociated and undefined TIFFs look like the original for me as well, but the associated TIFF does not. Which is what I am hoping to get. |
The backgrounds look transparent to me. Perhaps the issue is with your Adobe inDesign and how it reads the Tiffs, not with Imagemagick. In my Adobe Photoshop, the backgrounds are transparent. So it seems to me that it is an inDesign issue. Check with Adobe! |
@fmw42 Yes, that's probably the case, in Photoshop and Gimp the backgrounds are transparent for me as well. That's why I want to use the associated image which background is transparent in InDesign as well. I just did the comparison between the original image and the associated image in the way you compared the original to the unassociated/undefined versions:
So it looks to me that the images are really different. Could you check if an associated version that you generated on your machine is different as well? If so, it really looks like a bug in ImageMagick or some library that ImageMagick is using, doesn't it? |
We expect them to be different, as one has unassociated alpha and the other has associated alpha. |
Just found the pieces of code that Gimp does when the color values should not be saved: I guess the second link just sets a flag in the tiff, like Just throwing around some ideas 🙂 |
From GIMP: This looks like IM using unassociated in place of associated for alpha.
This looks like premultiplying or not.
A software engineers will have to comment further. But to see it looks like GIMP is doing the same as IM when setting alpha to unassociated and whatever else (not premultiply with alpha) that is needed when setting alpha to unassociated. So it looks to me that GIMP and IM are doing the same thing. But you could review the IM code to verify that. Also I showed in a previous comment that Imagemagick is doing a pixel-by-pixel compare of tiff with png and the results are identical. |
Yes, unassociated images are identical to the original PNGs. But the associated images are neither identical to the original PNG nor the image that Gimp produces. The associated ( |
As snibgo said, the associated image has different alpha blending than unassociated and so would not be expected to look the same. You cannot have the transparency you want with associated. That is just not how it works. (GIMP is changing there associated to unassociated to display it the way you want) |
Are you saying GIMP is just changing the displayed image? This is something I cannot confirm. In #7578 (comment) I did the comparison with Of course I cannot decide which way is the correct one, but I'd like to achieve the version that GIMP generates with IM. Do you have the possibility to generate a TIFF from the original image with GIMP? Maybe this helps to understand the differences between the generated associated images from IM vs. GIMP. |
Yay, I finally arrived at my desired result! Not really sure why it works as it does, but of course I want to share it here to help other devs with the same problem or the IM devs to get a hint what is wrong with the default command. So, this is the original command and result:
After playing around a bit with the
It is still not completely identical to the original, but it is identical to the image produced by GIMP:
So |
For the sake of completeness, here is the original image and all generated ones: |
Thanks for solving this, and telling us about your solution, @coeing. I don't know why " |
Yes, |
ImageMagick version
7.1.0-60
Operating system
Windows
Operating system, version and so on
Windows 11
Description
There is already a longer discussion about it: #2839
The short version:
-define tiff:alpha=associated
results in the correct output, but unfortunately Adobe InDesign does not handle the background as transparent in that case (Photoshop and Gimp do)-define tiff:alpha=associated
makes the background transparent, but modifies the semi-transparent areas of the imageSteps to Reproduce
magick convert original.png -define tiff:alpha=associated associated.tiff
Images
The text was updated successfully, but these errors were encountered: