/*
- * "$Id: image-colorspace.c 4767 2005-10-10 19:23:23Z mike $"
+ * "$Id: image-colorspace.c 6649 2007-07-11 21:46:42Z mike $"
*
* Colorspace conversions for the Common UNIX Printing System (CUPS).
*
- * Copyright 1993-2005 by Easy Software Products.
+ * Copyright 2007 by Apple Inc.
+ * Copyright 1993-2006 by Easy Software Products.
*
* The color saturation/hue matrix stuff is provided thanks to Mr. Paul
* Haeberli at "http://www.sgi.com/grafica/matrix/index.html".
*
* These coded instructions, statements, and computer programs are the
- * property of Easy Software Products and are protected by Federal
- * copyright law. Distribution and use rights are outlined in the file
- * "LICENSE.txt" which should have been included with this file. If this
- * file is missing or damaged please contact Easy Software Products
- * at:
- *
- * Attn: CUPS Licensing Information
- * Easy Software Products
- * 44141 Airport View Drive, Suite 204
- * Hollywood, Maryland 20636 USA
- *
- * Voice: (301) 373-9600
- * EMail: cups-info@cups.org
- * WWW: http://www.cups.org
+ * property of Apple Inc. and are protected by Federal copyright
+ * law. Distribution and use rights are outlined in the file "LICENSE.txt"
+ * which should have been included with this file. If this file is
+ * file is missing or damaged, see the license at "http://www.cups.org/".
*
* This file is subject to the Apple OS-Developed Software exception.
*
else
*out++ = 0;
- if (cupsImageColorSpace >= CUPS_CSPACE_CIELab)
+ if (cupsImageColorSpace == CUPS_CSPACE_CIELab ||
+ cupsImageColorSpace >= CUPS_CSPACE_ICC1)
rgb_to_lab(out - 3);
else if (cupsImageColorSpace == CUPS_CSPACE_CIEXYZ)
rgb_to_xyz(out - 3);
if (in != out)
memcpy(out, in, count * 3);
- if (cupsImageColorSpace >= CUPS_CSPACE_CIEXYZ)
+ if (cupsImageColorSpace == CUPS_CSPACE_CIELab ||
+ cupsImageColorSpace >= CUPS_CSPACE_ICC1)
{
while (count > 0)
{
- if (cupsImageColorSpace >= CUPS_CSPACE_CIELab)
- rgb_to_lab(out);
- else
- rgb_to_xyz(out);
+ rgb_to_lab(out);
+
+ out += 3;
+ count --;
+ }
+ }
+ else if (cupsImageColorSpace == CUPS_CSPACE_CIEXYZ)
+ {
+ while (count > 0)
+ {
+ rgb_to_xyz(out);
out += 3;
count --;
* Set the destination colorspace...
*/
- cupsImageColorSpace = cs;
+ cupsImageColorSpace = cs;
/*
* Don't use color profiles in colorimetric colorspaces...
*/
- if (cs >= CUPS_CSPACE_CIEXYZ)
+ if (cs == CUPS_CSPACE_CIEXYZ ||
+ cs == CUPS_CSPACE_CIELab ||
+ cs >= CUPS_CSPACE_ICC1)
cupsImageHaveProfile = 0;
}
*out++ = *in;
*out++ = *in++;
- if (cupsImageColorSpace >= CUPS_CSPACE_CIELab)
+ if (cupsImageColorSpace == CUPS_CSPACE_CIELab ||
+ cupsImageColorSpace >= CUPS_CSPACE_ICC1)
rgb_to_lab(out - 3);
else if (cupsImageColorSpace == CUPS_CSPACE_CIEXYZ)
rgb_to_xyz(out - 3);
* Convert sRGB to linear RGB...
*/
- r = pow(val[0] / 255.0, 0.58823529412);
- g = pow(val[1] / 255.0, 0.58823529412);
- b = pow(val[2] / 255.0, 0.58823529412);
+ r = pow((val[0] / 255.0 + 0.055) / 1.055, 2.4);
+ g = pow((val[1] / 255.0 + 0.055) / 1.055, 2.4);
+ b = pow((val[2] / 255.0 + 0.055) / 1.055, 2.4);
/*
* Convert to CIE XYZ...
* numbers are from 0 to 255.
*/
- ciel *= 2.55;
- ciea += 128;
- cieb += 128;
+ ciel = ciel * 2.55 + 0.5;
+ ciea += 128.5;
+ cieb += 128.5;
/*
* Output 8-bit values...
val[0] = 255;
if (ciea < 0.0)
- val[1] = 128;
+ val[1] = 0;
else if (ciea < 255.0)
val[1] = (int)ciea;
else
val[1] = 255;
if (cieb < 0.0)
- val[2] = 128;
+ val[2] = 0;
else if (cieb < 255.0)
val[2] = (int)cieb;
else
* Convert sRGB to linear RGB...
*/
- r = pow(val[0] / 255.0, 0.58823529412);
- g = pow(val[1] / 255.0, 0.58823529412);
- b = pow(val[2] / 255.0, 0.58823529412);
+ r = pow((val[0] / 255.0 + 0.055) / 1.055, 2.4);
+ g = pow((val[1] / 255.0 + 0.055) / 1.055, 2.4);
+ b = pow((val[2] / 255.0 + 0.055) / 1.055, 2.4);
/*
* Convert to CIE XYZ...
ciez = 0.019334 * r + 0.119193 * g + 0.950227 * b;
/*
- * Output 8-bit values...
+ * Encode as 8-bit XYZ...
*/
- if (ciex < 0.0)
+ if (ciex < 0.0f)
val[0] = 0;
- else if (ciex < 255.0)
- val[0] = (int)ciex;
+ else if (ciex < 1.1f)
+ val[0] = (int)(231.8181f * ciex + 0.5);
else
val[0] = 255;
- if (ciey < 0.0)
+ if (ciey < 0.0f)
val[1] = 0;
- else if (ciey < 255.0)
- val[1] = (int)ciey;
+ else if (ciey < 1.1f)
+ val[1] = (int)(231.8181f * ciey + 0.5);
else
val[1] = 255;
- if (ciez < 0.0)
+ if (ciez < 0.0f)
val[2] = 0;
- else if (ciez < 255.0)
- val[2] = (int)ciez;
+ else if (ciez < 1.1f)
+ val[2] = (int)(231.8181f * ciez + 0.5);
else
val[2] = 255;
}
/*
- * End of "$Id: image-colorspace.c 4767 2005-10-10 19:23:23Z mike $".
+ * End of "$Id: image-colorspace.c 6649 2007-07-11 21:46:42Z mike $".
*/