libtiff/html/man/TIFFcolor.3t.html

314 lines
11 KiB
HTML
Raw Normal View History

2003-12-21 16:47:11 -05:00
<html>
<head>
<meta name="generator" content="groff -Thtml, see www.gnu.org">
<meta name="Content-Style" content="text/css">
<title>COLOR</title>
</head>
<body>
<h1 align=center>COLOR</h1>
<a href="#NAME">NAME</a><br>
<a href="#SYNOPSIS">SYNOPSIS</a><br>
<a href="#DESCRIPTION">DESCRIPTION</a><br>
<a href="#SEE ALSO">SEE ALSO</a><br>
<hr>
<!-- Creator : groff version 1.17.2 -->
<!-- CreationDate: Mon Dec 22 00:39:20 2003 -->
<a name="NAME"></a>
<h2>NAME</h2>
<table width="100%" border=0 rules="none" frame="void"
cols="2" cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="10%"></td><td width="90%">
TIFFYCbCrToRGBInit, TIFFYCbCrtoRGB, TIFFCIELabToRGBInit, TIFFCIELabToXYZ, TIFFXYZToRGB - color conversion routines.</td></table>
<a name="SYNOPSIS"></a>
<h2>SYNOPSIS</h2>
<table width="100%" border=0 rules="none" frame="void"
cols="2" cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="10%"></td><td width="90%">
<b>#include &lt;tiffio.h&gt;</b></td></table>
<table width="100%" border=0 rules="none" frame="void"
cols="2" cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="10%"></td><td width="90%">
<b>int TIFFYCbCrToRGBInit(TIFFYCbCrToRGB
*</b><i>ycbcr</i><b>, float *</b><i>luma</i><b>, float
*</b><i>refBlackWhite&quot;</i><b>);&quot;<br>
void TIFFYCbCrtoRGB(TIFFYCbCrToRGB *</b><i>ycbcr</i><b>,
uint32</b> <i>Y</i><b>, int32</b> <i>Cb</i><b>, int32</b>
<i>Cr</i><b>, uint32 *</b><i>R</i><b>, uint32
*</b><i>G</i><b>, uint32 *</b><i>B</i>
<b>);</b></td></table>
<table width="100%" border=0 rules="none" frame="void"
cols="2" cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="10%"></td><td width="90%">
<b>int TIFFCIELabToRGBInit(TIFFCIELabToRGB
*</b><i>cielab</i><b>, TIFFDisplay *</b><i>display</i><b>,
float *</b><i>refWhite</i><b>);<br>
void TIFFCIELabToXYZ(TIFFCIELabToRGB *</b><i>cielab</i><b>,
uint32</b> <i>L</i><b>, int32</b> <i>a</i><b>, int32</b>
<i>b</i><b>, float *</b><i>X</i><b>, float *</b><i>Y</i><b>,
float *</b><i>Z</i><b>);<br>
void TIFFXYZToRGB(TIFFCIELabToRGB *</b><i>cielab</i><b>,
float</b> <i>X</i><b>, float</b> <i>Y</i><b>, float</b>
<i>Z&quot;</i><b>,</b><i>uint32</i><b>*&quot;</b><i>R</i><b>,
uint32 *</b><i>G</i><b>, uint32
*</b><i>B</i><b>);</b></td></table>
<a name="DESCRIPTION"></a>
<h2>DESCRIPTION</h2>
<table width="100%" border=0 rules="none" frame="void"
cols="2" cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="10%"></td><td width="90%">
TIFF supports several color spaces for images stored in that
format. There is usually a problem of application to handle
the data properly and convert between different colorspaces
for displaying and printing purposes. To simplify this task
libtiff implements several color conversion routines itself.
In particular, these routines used in
<b>TIFFRGBAImage(3T)</b> interface.</td></table>
<table width="100%" border=0 rules="none" frame="void"
cols="2" cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="10%"></td><td width="90%">
<b>TIFFYCbCrToRGBInit()</b> used to initialize <i>YCbCr</i>
to <i>RGB</i> conversion state. Allocating and freeing of
the <i>ycbcr</i> structure belongs to programmer.
<i>TIFFYCbCrToRGB</i> defined in <b>tiffio.h</b>
as</td></table>
<table width="100%" border=0 rules="none" frame="void"
cols="2" cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="21%"></td><td width="79%">
<pre>typedef struct { /* YCbCr-&gt;RGB support */
TIFFRGBValue* clamptab; /* range clamping table */
int* Cr_r_tab;
int* Cb_b_tab;
int32* Cr_g_tab;
int32* Cb_g_tab;
int32* Y_tab;
} TIFFYCbCrToRGB;
</pre></td></table>
<table width="100%" border=0 rules="none" frame="void"
cols="2" cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="10%"></td><td width="90%">
<i>luma</i> is a float array of three values representing
proportions of the red, green and blue in luminance, Y (see
section 21 of the TIFF 6.0 specification, where the YCbCr
images discussed). <i>TIFFTAG_YCBCRCOEFFICIENTS</i> holds
that values in TIFF file. <i>refBlackWhite</i> is a float
array of 6 values which specifies a pair of headroom and
footroom image data values (codes) for each image component
(see section 20 of the TIFF 6.0 specification where the
colorinmetry fields discussed).
<i>TIFFTAG_REFERENCEBLACKWHITE</i> is responsible for
storing these values in TIFF file. Following code snippet
should helps to understand the the technique:</td></table>
<table width="100%" border=0 rules="none" frame="void"
cols="2" cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="21%"></td><td width="79%">
<pre>float *luma, *refBlackWhite;
uint16 hs, vs;
/* Initialize structures */
ycbcr = (TIFFYCbCrToRGB*)
_TIFFmalloc(TIFFroundup(sizeof(TIFFYCbCrToRGB), sizeof(long))
+ 4*256*sizeof(TIFFRGBValue)
+ 2*256*sizeof(int)
+ 3*256*sizeof(int32));
if (ycbcr == NULL) {
TIFFError(&quot;YCbCr-&gt;RGB&quot;,
&quot;No space for YCbCr-&gt;RGB conversion state&quot;);
exit(0);
}
TIFFGetFieldDefaulted(tif, TIFFTAG_YCBCRCOEFFICIENTS, &amp;luma);
TIFFGetFieldDefaulted(tif, TIFFTAG_REFERENCEBLACKWHITE, &amp;refBlackWhite);
if (TIFFYCbCrToRGBInit(ycbcr, luma, refBlackWhite) &lt; 0)
exit(0);
/* Start conversion */
uint32 r, g, b;
uint32 Y;
int32 Cb, Cr;
for each pixel in image
TIFFYCbCrtoRGB(img-&gt;ycbcr, Y, Cb, Cr, &amp;r, &amp;g, &amp;b);
/* Free state structure */
_TIFFfree(ycbcr);
</pre></td></table>
<table width="100%" border=0 rules="none" frame="void"
cols="2" cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="10%"></td><td width="90%">
<b>TIFFCIELabToRGBInit()</b> initializes the <i>CIE L*a*b*
1976</i> to <i>RGB</i> conversion state.
<b>TIFFCIELabToRGB</b> defined as</td></table>
<table width="100%" border=0 rules="none" frame="void"
cols="2" cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="21%"></td><td width="79%">
<pre>#define CIELABTORGB_TABLE_RANGE 1500
typedef struct { /* CIE Lab 1976-&gt;RGB support */
int range; /* Size of conversion table */
float rstep, gstep, bstep;
float X0, Y0, Z0; /* Reference white point */
TIFFDisplay display;
float Yr2r[CIELABTORGB_TABLE_RANGE + 1]; /* Conversion of Yr to r */
float Yg2g[CIELABTORGB_TABLE_RANGE + 1]; /* Conversion of Yg to g */
float Yb2b[CIELABTORGB_TABLE_RANGE + 1]; /* Conversion of Yb to b */
} TIFFCIELabToRGB;
</pre></td></table>
<table width="100%" border=0 rules="none" frame="void"
cols="2" cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="10%"></td><td width="90%">
<i>display</i> is a display device description, declared
as</td></table>
<table width="100%" border=0 rules="none" frame="void"
cols="2" cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="21%"></td><td width="79%">
<pre>typedef struct {
float d_mat[3][3]; /* XYZ -&gt; luminance matrix */
float d_YCR; /* Light o/p for reference white */
float d_YCG;
float d_YCB;
int d_Vrwr; /* Pixel values for ref. white */
int d_Vrwg;
int d_Vrwb;
float d_Y0R; /* Residual light for black pixel */
float d_Y0G;
float d_Y0B;
float d_gammaR; /* Gamma values for the three guns */
float d_gammaG;
float d_gammaB;
} TIFFDisplay;
</pre></td></table>
<table width="100%" border=0 rules="none" frame="void"
cols="2" cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="10%"></td><td width="90%">
For example, the one can use sRGB device, which has the
following parameters:</td></table>
<table width="100%" border=0 rules="none" frame="void"
cols="2" cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="21%"></td><td width="79%">
<pre>TIFFDisplay display_sRGB = {
{ /* XYZ -&gt; luminance matrix */
{ 3.2410F, -1.5374F, -0.4986F },
{ -0.9692F, 1.8760F, 0.0416F },
{ 0.0556F, -0.2040F, 1.0570F }
},
100.0F, 100.0F, 100.0F, /* Light o/p for reference white */
255, 255, 255, /* Pixel values for ref. white */
1.0F, 1.0F, 1.0F, /* Residual light o/p for black pixel */
2.4F, 2.4F, 2.4F, /* Gamma values for the three guns */
};
</pre></td></table>
<table width="100%" border=0 rules="none" frame="void"
cols="2" cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="10%"></td><td width="90%">
<i>refWhite</i> is a color temperature of the reference
white. The <i>TIFFTAG_WHITEPOINT</i> contains the
chromaticity of the white point of the image from where the
reference white can be calculated using following
formulae:</td></table>
<table width="100%" border=0 rules="none" frame="void"
cols="2" cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="21%"></td><td width="79%">
refWhite_Y = 100.0<br>
refWhite_X = whitePoint_x / whitePoint_y * refWhite_Y<br>
refWhite_Z = (1.0 - whitePoint_x - whitePoint_y) /
whitePoint_y * refWhite_X</td></table>
<table width="100%" border=0 rules="none" frame="void"
cols="2" cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="10%"></td><td width="90%">
The conversion itself performed in two steps: at the first
one we will convert <i>CIE L*a*b* 1976</i> to <i>CIE XYZ</i>
using <b>TIFFCIELabToXYZ()</b> routine, and at the second
step we will convert <i>CIE XYZ</i> to <i>RGB</i> using
<b>TIFFXYZToRGB().</b> Look at the code sample
below:</td></table>
<table width="100%" border=0 rules="none" frame="void"
cols="2" cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="21%"></td><td width="79%">
<pre>float *whitePoint;
float refWhite[3];
/* Initialize structures */
img-&gt;cielab = (TIFFCIELabToRGB *)
_TIFFmalloc(sizeof(TIFFCIELabToRGB));
if (!cielab) {
TIFFError(&quot;CIE L*a*b*-&gt;RGB&quot;,
&quot;No space for CIE L*a*b*-&gt;RGB conversion state.&quot;);
exit(0);
}
TIFFGetFieldDefaulted(tif, TIFFTAG_WHITEPOINT, &amp;whitePoint);
refWhite[1] = 100.0F;
refWhite[0] = whitePoint[0] / whitePoint[1] * refWhite[1];
refWhite[2] = (1.0F - whitePoint[0] - whitePoint[1])
/ whitePoint[1] * refWhite[1];
if (TIFFCIELabToRGBInit(cielab, &amp;display_sRGB, refWhite) &lt; 0) {
TIFFError(&quot;CIE L*a*b*-&gt;RGB&quot;,
&quot;Failed to initialize CIE L*a*b*-&gt;RGB conversion state.&quot;);
_TIFFfree(cielab);
exit(0);
}
/* Now we can start to convert */
uint32 r, g, b;
uint32 L;
int32 a, b;
float X, Y, Z;
for each pixel in image
TIFFCIELabToXYZ(cielab, L, a, b, &amp;X, &amp;Y, &amp;Z);
TIFFXYZToRGB(cielab, X, Y, Z, &amp;r, &amp;g, &amp;b);
/* Don't forget to free the state structure */
_TIFFfree(cielab);
</pre></td></table>
<a name="SEE ALSO"></a>
<h2>SEE ALSO</h2>
<table width="100%" border=0 rules="none" frame="void"
cols="2" cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="10%"></td><td width="90%">
<i>libtiff</i>(3T),<i>TIFFRGBAImage(3T)</i></td></table>
<hr>
</body>
</html>