The algorithm that im.convert("CMYK") uses is this: (C code)
static void
rgb2cmyk(UINT8* out, const UINT8* in, int xsize)
{
int x;
for (x = 0; x < xsize; x++) {
/* Note: no undercolour removal */
*out++ = ~(*in++);
*out++ = ~(*in++);
*out++ = ~(*in++);
*out++ = 0; in++;
}
}
All numbers are in the inclusive range [0, 255] in this case. If "in"
was 0, then out is 255, so it's like the algorithm on the page you
mentouned for RGB->CMY, where the value 255 corresponds to 1.0, and K is
simply set to 0 all the time.
Using numeric or numarray, it is probably possible to do the CMY->CMYK
conversion step described on the page you mentioned, and have the
resulting code run fairly quickly.
As for conversions from RGB to other 3-component color systems, you can
use the "im.convert(mode, matrix)" function with the right matrix. An
example is in the documentation for converting to the XYZ colorspace.
This block of code, common to many of the conversion functions on that
web page you mentioned, has to do with doing gamma conversion:
if ( var_R > 0.0031308 ) var_R = 1.055 * ( var_R ^ ( 1 / 2.4 ) ) - 0.055
else var_R = 12.92 * var_R
if ( var_G > 0.0031308 ) var_G = 1.055 * ( var_G ^ ( 1 / 2.4 ) ) - 0.055
else var_G = 12.92 * var_G
if ( var_B > 0.0031308 ) var_B = 1.055 * ( var_B ^ ( 1 / 2.4 ) ) - 0.055
else var_B = 12.92 * var_B
To perform this step in PIL, you would use the im.point method with a
properly initialized table.
Jeff
pgpGUHFNw3Bed.pgp
Description: PGP signature
_______________________________________________ Image-SIG maillist - [email protected] http://mail.python.org/mailman/listinfo/image-sig
