I'm coding an application that needs a color picker that converts RGB values

into CMYK percentages. It will work just like the color dialog in Adobe

Photoshop. I just need the algorithm that converts the numbers, I'm not

worried about creating device-dependent color models for printing...yet.

I've a tested a few algorithms I've found in books and from internet and

they give me roughly the same values. The problem is when I test these

values with Photoshop's algorithm they're off by quite a bit.

Any help would be greatly appreciated.

The following examples are not yielding accurate values

RGB to CMY

c = 255 - red;

m = 255 - grn;

y = 255 - blu;

CMY to CMYK

k = Math.min( c, Math.min( m, y ) );

c = 255*( c - k ) / (255 - k);

m = 255*( m - k ) / (255 - k);

y = 255*( y - k ) / (255 - k);

RGB to CMYK

m = Math.max(red, Math.max( grn, blu ));

K = 255 - m;

C = 255 * (m - red) / m;

M = 255 * (m - grn) / m;

Y = 255 * (m - blu) / m;