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

Possibility of implementing YCCK color transform as available in some jpeg files? #142

Open
richardpl opened this issue Jan 29, 2021 · 8 comments

Comments

@richardpl
Copy link

For more info read:
http://halicery.com/Image%20Decoders/JPEG/JPEG%20notes/CMYK.html

@sekrit-twc
Copy link
Owner

sekrit-twc commented Jan 30, 2021

After studying this issue, it appears that CMYK is functionally equivalent to RGBA, as K functions as an inverse alpha mask. The missing capability is CMY<-->RGB conversion, as YCC is merely YUV transform applied to CMY. Support for RGBA has been added since z.lib 3.0, so this feature is tractable.

@sekrit-twc
Copy link
Owner

Still debating whether to implement this internally. It is possible to transform YCCK/CMYK to YUV/RGB with an I/O callback:

YUV:
Y = 1 - ((1 - K) * Y + K)
U = -((1 - K) * C0)
V = -((1 - K) * C1)

RGB:
R = 1 - ((1 - K) * C + K)
G = 1 - ((1 - K) * M + K)
B = 1 - ((1 - K) * Y + K)

or more abstractly

Negative = (1 - K) * Negative_K + K * Black
Positive = Black - Negative

where Black = [1 0 0] for YCC and [1 1 1] for CMY

@richardpl
Copy link
Author

what are C0 and C1 values?

@sekrit-twc
Copy link
Owner

First and second negative chroma channels. Per "YCC".

@sekrit-twc
Copy link
Owner

@richardpl Can you provide a raw dump of YCCK or CMYK image data?

@richardpl
Copy link
Author

Relevant file can be downloaded from here:

http://trac.ffmpeg.org/ticket/9085

@sekrit-twc
Copy link
Owner

The FFmpeg tracker only has a JPEG file. If I open it in an image viewer, I only get the decoded RGB. Please upload the raw YCCK pixel data.

@Artoria2e5
Copy link

Artoria2e5 commented Jul 16, 2023

The JPEG is fine; the viewer is the problem. Unfortunately there are very few formats that hold CMYK, so converting is tough.

djpeg produces the attached pnm, but I cannot verify whether it is correct. It is probably CMYK and not YCCK still. I mean, you expect djpeg to give you RGB and not YCC, and it's the same here. If you want the guts, you need to get the library out.
Channel.pnm.zip

The YCCK thing is also just a big hack given the CMYK/RGB transform, but we all know that. The point is that it gives coding gain.

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

No branches or pull requests

4 participants
@richardpl @sekrit-twc @Artoria2e5 and others