Skip to content

Fix for UnrollAnyWordsPremul when extra channels are present - #582

Merged
mm2 merged 1 commit into
mm2:masterfrom
mircomir:work/mircomir/premult_16bit_fix
Jun 17, 2026
Merged

Fix for UnrollAnyWordsPremul when extra channels are present#582
mm2 merged 1 commit into
mm2:masterfrom
mircomir:work/mircomir/premult_16bit_fix

Conversation

@mircomir

Copy link
Copy Markdown
Contributor

I add skipping of extras as in UnrollAnyWords().

I had a problem with a TIFF image saved by Photoshop. Before using it in LittleCMS, I always convert the image from Planar to Chunky and tell LittleCMS that I don't want premultiplied alpha on output. I noticed the problem with the CMYK-to-RGB conversion.

I'm attaching a 16-bit CMYK TIFF with premultiplied alpha and an extra channel already converted to chunky with another software (Photoshop displays it correctly).

testcard16_cmykp5.tif

@mm2

mm2 commented Jun 17, 2026

Copy link
Copy Markdown
Owner

The current code only supports premultiplied alpha when one, and only one, extra channel is present, and that extra channel is the alpha channel.

This restriction is intentional. There are scenarios, such as premultiplied‑alpha output, where your proposed change would break the pipeline.

The most evident issue is when more than one extra channel is provided, there is no reliable way to determine which of them is the alpha channel.

If you really need this very specific decoder and you are aware of the side effects, you can implement your own unroll logic using a plug‑in. See the “Formatters Plug‑in” section in the Plug‑in API documentation.

@mircomir

Copy link
Copy Markdown
Contributor Author

The current code only supports premultiplied alpha when one, and only one, extra channel is present, and that extra channel is the alpha channel.

This restriction is intentional. There are scenarios, such as premultiplied‑alpha output, where your proposed change would break the pipeline.

I'll check it again, but if I remember correctly:

  1. It works with the same 8-bit image (the premultiplied is the first of the extras).
  2. It also works correctly with premultiplied RGB alphas and multiple extra channels.

@mm2

mm2 commented Jun 17, 2026

Copy link
Copy Markdown
Owner
  1. It works with the same 8-bit image (the premultiplied is the first of the extras).
  2. It also works correctly with premultiplied RGB alphas and multiple extra channels.

You are completely right, as UnrollChunkyBytes() is doing this thing. At that point I am not sure if remove this functionality, which was never intended, or expand words also and replicate the alpha-is-first behavior.

@mircomir

Copy link
Copy Markdown
Contributor Author
  1. It works with the same 8-bit image (the premultiplied is the first of the extras).
  2. It also works correctly with premultiplied RGB alphas and multiple extra channels.

You are completely right, as UnrollChunkyBytes() is doing this thing. At that point I am not sure if remove this functionality, which was never intended, or expand words also and replicate the alpha-is-first behavior.

I think it makes sense to say that alpha should be first.
Besides, it's already that way throughout the code. I haven't tried them, but UnrollDoublesToFloat and UnrollFloatsToFloat also add Extra to the accumulator.

If I may, I'd prefer this solution, which also maintains backwards compatibility with 8-bit. :)

PS: If it helps with your choice, Photoshop also set alpha first when I saved the image as a TIFF.

@mircomir

Copy link
Copy Markdown
Contributor Author

PS: If it helps with your choice, Photoshop also set alpha first when I saved the image as a TIFF.

Same 8-bit test case saved by Photoshop. If you need them, feel free to use them. These are the ones I normally use in testing KDE Image Formats.

testcard8_cmykp5.tif

@mm2

mm2 commented Jun 17, 2026

Copy link
Copy Markdown
Owner

After seeing other cases are already using first extra as alpha, I gladly take your PR. Thank you!

@mm2
mm2 merged commit cc51277 into mm2:master Jun 17, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants