KoColor && CMYK -> RGB
Boudewijn Rempt
boud at valdyas.org
Fri Oct 24 00:09:19 CEST 2003
Well, my CMYK strategy works now without crashes -- and it gets called, too,
so that's nice. But I fear that there might be a bug in KoColor. Since
KoColor isn't used anywhere but on in Krita, but is still in the koffice lib,
I crossposted. Is there still anyone maintaining this useful class?
Anyway, given a nice, white RGB color (255, 255, 255), this function
gives (255, 255, 255, 255) -- which is as black as can be.
void KoColor::RGBtoCMYK(int R, int G, int B, int *C, int *M, int *Y, int *K)
{
int min = (R < G) ? R : G;
*K = (min < B) ? min : B;
*C = 255 - (R - *K);
*M = 255 - (G - *K);
*Y = 255 - (B - *K);
}
The color conversion website (http://www.easyrgb.com/math.php?MATH=M11#text11)
doesn't give a direct rgb-> cmyk, but advises:
//inp_R = From 0 to 255
//inp_G = From 0 to 255
//inp_B = From 0 to 255
out_C = 1 - ( inp_R / 255 )
out_M = 1 - ( inp_G / 255 )
out_Y = 1 - ( inp_B / 255 )
followed by:
//inp_C = From 0 to 1
//inp_M = From 0 to 1
//inp_Y = From 0 to 1
var_K = 1
if ( inp_C < var_K ) var_K = inp_C
if ( inp_M < var_K ) var_K = inp_M
if ( inp_Y < var_K ) var_K = inp_Y
out_C = ( inp_C - var_K ) / (1 - var_K )
out_M = ( inp_M - var_K ) / (1 - var_K )
out_Y = ( inp_Y - var_K ) / (1 - var_K )
out_K = var_K
Which is obviously rather more costly, with all the divisions... I'm hacking
this in for now, to see what it does, but does anyone have a nice bit of math
that makes this cheaper?
--
Boudewijn Rempt | http://www.valdyas.org/index2.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: signature
Url : http://mail.kde.org/pipermail/kimageshop/attachments/20031023/be235761/attachment.bin
More information about the kimageshop
mailing list