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

Add support for CYMK JPEGs #1

Open
neonichu opened this issue Mar 11, 2015 · 0 comments
Open

Add support for CYMK JPEGs #1

neonichu opened this issue Mar 11, 2015 · 0 comments

Comments

@neonichu
Copy link
Contributor

Can be based off this:

template <J_COLOR_SPACE colorSpace>
void setPixel(ImageFrame& buffer, ImageFrame::PixelData* currentAddress, JSAMPARRAY samples, int column)
{
    JSAMPLE* jsample = *samples + column * (colorSpace == JCS_RGB ? 3 : 4);

    switch (colorSpace) {
        case JCS_RGB:
            buffer.setRGBA(currentAddress, jsample[0], jsample[1], jsample[2], 0xFF);
            break;
        case JCS_CMYK:
            // Source is 'Inverted CMYK', output is RGB.
            // See: http://www.easyrgb.com/math.php?MATH=M12#text12
            // Or: http://www.ilkeratalay.com/colorspacesfaq.php#rgb
            // From CMYK to CMY:
            // X =   X    * (1 -   K   ) +   K  [for X = C, M, or Y]
            // Thus, from Inverted CMYK to CMY is:
            // X = (1-iX) * (1 - (1-iK)) + (1-iK) => 1 - iX*iK
            // From CMY (0..1) to RGB (0..1):
            // R = 1 - C => 1 - (1 - iC*iK) => iC*iK  [G and B similar]
            unsigned k = jsample[3];
            buffer.setRGBA(currentAddress, jsample[0] * k / 255, jsample[1] * k / 255, jsample[2] * k / 255, 0xFF);
            break;
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant