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

Improvements for non-rgb modes and transparency #319

Merged
merged 4 commits into from
Jun 15, 2022

Conversation

Etienne-Gautier
Copy link
Contributor

@Etienne-Gautier Etienne-Gautier commented Jun 14, 2022

Context

Proposing a number of improvements to better support other image modes (mainly using CMYK) in layer.topil and layer.composite. As listed below:

  • Apply icc profile to non-rgb images (by converting them to RGB image mode). As stated in the pillow documentation, the output image mode is by default the same as the input image mode. When applying the ICC profile on a CMYK image to convert it to sRGB profile, we need to explicitly set the output image mode to something that is RGB.
  • Enable transparency for images not in RGB or L image mode (i.e. CMYK) in layer.topil() when the icc_profile is enabled. This is done by changing the order of operation: apply the ICC profile first without transparency, then apply the transparency on the result of the ICC transformation (RGB image).

This PR also brings all these improvements to layer.composite() by re-using the post-process logic.

  • Fixing inverted colors in CMYK mode for composite layer.
  • Adding ability to apply the ICC profile to composite layer.
  • Working transparency for CMYK images when icc_profile is enabled.

This is a test PSD file, using created using the CMYK 8-bit image mode (I had to zip because github doesn't allow PSD file upload): CMYK-psd-tools-demo.psd.zip

The test file is has the following layers:
Screen Shot 2022-06-14 at 3 26 20 pm

This is what layer.topil() returns on the "cat layer" (pixel layer)
MAC7uHBSFBM

This is what layer.composite() returns for the shape layer that clips the pixel layer of a dog. It's hard to see in github, but there is some proper transparency on this image, not just a white background:
MAC7uGHaeRU.

Let me know if you have any feedback or suggestions, I am happy to take that onboard

@kyamagu
Copy link
Contributor

kyamagu commented Jun 14, 2022

@Etienne-Gautier Thanks, but the test fails for duotone and multichannel PSD files. Are they expected to be LA mode in PIL? If so, please fix the tests.

Copy link
Contributor

@kyamagu kyamagu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kyamagu kyamagu merged commit f54b135 into psd-tools:main Jun 15, 2022
@kyamagu kyamagu mentioned this pull request Jun 18, 2022
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.

None yet

2 participants