Skip to content

Convert CMYK to RGB like Google Chrome - #2699

Merged
homm merged 1 commit into
python-pillow:masterfrom
uploadcare:better-cmyk
Aug 31, 2017
Merged

homm merged 1 commit into
python-pillow:masterfrom
uploadcare:better-cmyk

Conversation

@homm

@homm homm commented Aug 28, 2017

Copy link
Copy Markdown
Member

There is no easy way to convert CMYK to RGB without complicated color management. But there are some approximations. Pillow used to use the simplest one, which, for example, could be found there. It is not too accurate and produces very dark images. On the other hand, I found this formulas which produces far better result.

C = ( C * ( 1 - K ) + K )
M = ( M * ( 1 - K ) + K )
Y = ( Y * ( 1 - K ) + K )

R = ( 1 - C ) * 255
G = ( 1 - M ) * 255
B = ( 1 - Y ) * 255

or in one equation:

R = 255 - K - C * ( 255 - K ) / 255
G = 255 - K - M * ( 255 - K ) / 255
B = 255 - K - Y * ( 255 - K ) / 255

Original CMYK image opened in Safari (and probably how it should looks like with correct color management)
_out_cmyk

Converted to RGB using the new formula and also CMYK image looks absolutely the same in Google Chrome
_out_new

Converted to RGB using the old formula
_out_old

@homm

homm commented Aug 28, 2017

Copy link
Copy Markdown
Member Author

Another example:

_out_cmyk _out_new _out_old

@znerol

znerol commented Aug 29, 2017 •

Copy link
Copy Markdown

I'm all for better CMYK handling. Wouldn't it be easier to better to simply read the icc profile from the image and then use ImageCms.profileToProfile if LittleCMS is available?

@wiredfool

Copy link
Copy Markdown
Member

I think doing things intelligently when we have lcms and image profiles is a good change in general, but it's going to be intrusive and a noticeable change in behavior for people relying on the library.

This PR makes sense in absence of that.

@homm
homm merged commit 4029998 into python-pillow:master Aug 31, 2017
@homm
homm deleted the better-cmyk branch August 31, 2017 13:46
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.

3 participants