libtiff/html/man/TIFFcolor.3tiff.html
Bob Friesenhahn c3402403ea * html/man/Makefile.am (htmldoc): Fix htmldoc rule so that it can
be used if build directory is not the same as source directory.
* man/{TIFFGetField.3tiff, man/TIFFSetField.3tiff}: Documented
TIFFTAG_PHOTOSHOP, TIFFTAG_RICHTIFFIPTC, and TIFFTAG_XMLPACKET,
and re-sorted tag names in alphabetical order.
2006-01-02 23:50:44 +00:00

825 lines
19 KiB
HTML

<!-- Creator : groff version 1.19.2 -->
<!-- CreationDate: Mon Jan 2 17:41:35 2006 -->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="generator" content="groff -Thtml, see www.gnu.org">
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<meta name="Content-Style" content="text/css">
<style type="text/css">
p { margin-top: 0; margin-bottom: 0; }
pre { margin-top: 0; margin-bottom: 0; }
table { margin-top: 0; margin-bottom: 0; }
</style>
<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>
<a name="NAME"></a>
<h2>NAME</h2>
<p style="margin-left:11%; margin-top: 1em">TIFFYCbCrToRGBInit,
TIFFYCbCrtoRGB, TIFFCIELabToRGBInit, TIFFCIELabToXYZ,
TIFFXYZToRGB &minus; color conversion routines.</p>
<a name="SYNOPSIS"></a>
<h2>SYNOPSIS</h2>
<p style="margin-left:11%; margin-top: 1em"><b>#include
&lt;tiffio.h&gt;</b></p>
<p style="margin-left:11%; margin-top: 1em"><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></p>
<p style="margin-left:11%; margin-top: 1em"><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></p>
<a name="DESCRIPTION"></a>
<h2>DESCRIPTION</h2>
<p style="margin-left:11%; margin-top: 1em">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(3TIFF)</b> interface.</p>
<p style="margin-left:11%; margin-top: 1em"><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</p>
<p style="margin-left:22%; margin-top: 1em">typedef struct
{ /* YCbCr-&gt;RGB support */ <br>
TIFFRGBValue* clamptab; /* range clamping table */</p>
<table width="100%" border=0 rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<p valign="top">int*</p><td width="34%"></td>
<td width="-26%"></td>
<td width="15%"></td>
<td width="8%"></td>
<td width="69%">
<p valign="top">Cr_r_tab; <br>
int*</p></td>
<tr valign="top" align="left">
<td width="34%"></td>
<td width="-26%"></td>
<td width="15%"></td>
<td width="8%"></td>
<td width="69%">
<p valign="top">Cb_b_tab; <br>
int32*</p></td>
<tr valign="top" align="left">
<td width="34%"></td>
<td width="-26%"></td>
<td width="15%"></td>
<td width="8%"></td>
<td width="69%">
<p valign="top">Cr_g_tab; <br>
int32*</p></td>
<tr valign="top" align="left">
<td width="34%"></td>
<td width="-26%"></td>
<td width="15%"></td>
<td width="8%"></td>
<td width="69%">
<p valign="top">Cb_g_tab;</p></td>
</table>
<p style="margin-left:22%;">int32* Y_tab; <br>
} TIFFYCbCrToRGB;</p>
<p style="margin-left:11%; margin-top: 1em"><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:</p>
<p style="margin-left:22%; margin-top: 1em">float *luma,
*refBlackWhite; <br>
uint16 hs, vs;</p>
<p style="margin-left:22%; margin-top: 1em">/* Initialize
structures */ <br>
ycbcr = (TIFFYCbCrToRGB*)</p>
<table width="100%" border=0 rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">
<p valign="top">_TIFFmalloc(TIFFroundup(sizeof(TIFFYCbCrToRGB),
sizeof(long))</p> </td>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">
<p valign="top">+ 4*256*sizeof(TIFFRGBValue)</p></td>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">
<p valign="top">+ 2*256*sizeof(int)</p></td>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">
<p valign="top">+ 3*256*sizeof(int32));</p></td>
</table>
<p style="margin-left:22%;">if (ycbcr == NULL) { <br>
TIFFError(&quot;YCbCr-&gt;RGB&quot;,</p>
<table width="100%" border=0 rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%"></td>
<td width="8%">
</td>
<td width="77%">
</td>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%"></td>
<td width="8%"></td>
<td width="77%">
<p valign="top">&quot;No space for YCbCr-&gt;RGB conversion
state&quot;);</p> </td>
</table>
<p style="margin-left:22%;">exit(0); <br>
}</p>
<p style="margin-left:22%; margin-top: 1em">TIFFGetFieldDefaulted(tif,
TIFFTAG_YCBCRCOEFFICIENTS, &amp;luma); <br>
TIFFGetFieldDefaulted(tif, TIFFTAG_REFERENCEBLACKWHITE,
&amp;refBlackWhite); <br>
if (TIFFYCbCrToRGBInit(ycbcr, luma, refBlackWhite) &lt;
0)</p>
<table width="100%" border=0 rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">
<p valign="top">exit(0);</p></td>
</table>
<p style="margin-left:22%; margin-top: 1em">/* Start
conversion */ <br>
uint32 r, g, b; <br>
uint32 Y; <br>
int32 Cb, Cr;</p>
<p style="margin-left:22%; margin-top: 1em">for each pixel
in image</p>
<table width="100%" border=0 rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">
<p valign="top">TIFFYCbCrtoRGB(img-&gt;ycbcr, Y, Cb, Cr,
&amp;r, &amp;g, &amp;b);</p></td>
</table>
<p style="margin-left:22%; margin-top: 1em">/* Free state
structure */ <br>
_TIFFfree(ycbcr);</p>
<p style="margin-left:11%; margin-top: 1em"><b>TIFFCIELabToRGBInit()</b>
initializes the <i>CIE L*a*b* 1976</i> to <i>RGB</i>
conversion state. <b>TIFFCIELabToRGB</b> defined as</p>
<p style="margin-left:22%; margin-top: 1em">#define
CIELABTORGB_TABLE_RANGE 1500</p>
<table width="100%" border=0 rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="22%"></td>
<td width="-14%"></td>
<td width="7%"></td>
<td width="8%">
<p valign="top">typedef struct {</p></td>
<td width="8%"></td>
<td width="7%"></td>
<td width="8%"></td>
<td width="8%">
</td>
<td width="46%">
<p valign="top">/* CIE Lab 1976-&gt;RGB support */</p></td>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="-14%"></td>
<td width="7%"></td>
<td width="8%">
</td>
<td width="8%">
<p valign="top">int</p></td>
<td width="7%">
<p valign="top">range;</p></td>
<td width="8%"></td>
<td width="8%">
</td>
<td width="46%">
<p valign="top">/* Size of conversion table */</p></td>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="-14%"></td>
<td width="7%"></td>
<td width="8%">
</td>
<td width="8%">
<p valign="top">float</p></td>
<td width="7%"></td>
<td width="8%">
<p valign="top">rstep, gstep, bstep;</p></td>
<td width="8%"></td>
<td width="46%">
</td>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="-14%"></td>
<td width="7%"></td>
<td width="8%">
</td>
<td width="8%">
<p valign="top">float</p></td>
<td width="7%"></td>
<td width="8%">
<p valign="top">X0, Y0, Z0;</p></td>
<td width="8%"></td>
<td width="46%">
<p valign="top">/* Reference white point */</p></td>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="-14%"></td>
<td width="7%"></td>
<td width="8%"></td>
<td width="8%">
<p valign="top">TIFFDisplay display;</p></td>
<td width="7%"></td>
<td width="8%"></td>
<td width="8%"></td>
<td width="46%">
</td>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="-14%"></td>
<td width="7%"></td>
<td width="8%">
</td>
<td width="8%">
<p valign="top">float</p></td>
<td width="7%"></td>
<td width="8%">
<p valign="top">Yr2r[CIELABTORGB_TABLE_RANGE + 1]; /*
Conversion of Yr to r */</p></td>
<td width="8%"></td>
<td width="46%">
</td>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="-14%"></td>
<td width="7%"></td>
<td width="8%">
</td>
<td width="8%">
<p valign="top">float</p></td>
<td width="7%"></td>
<td width="8%">
<p valign="top">Yg2g[CIELABTORGB_TABLE_RANGE + 1]; /*
Conversion of Yg to g */</p></td>
<td width="8%"></td>
<td width="46%">
</td>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="-14%"></td>
<td width="7%"></td>
<td width="8%">
</td>
<td width="8%">
<p valign="top">float</p></td>
<td width="7%"></td>
<td width="8%">
<p valign="top">Yb2b[CIELABTORGB_TABLE_RANGE + 1]; /*
Conversion of Yb to b */</p></td>
<td width="8%"></td>
<td width="46%">
</td>
</table>
<p style="margin-left:22%;">} TIFFCIELabToRGB;</p>
<p style="margin-left:11%; margin-top: 1em"><i>display</i>
is a display device description, declared as</p>
<p style="margin-left:22%; margin-top: 1em">typedef struct
{</p>
<table width="100%" border=0 rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">
<p valign="top">float d_mat[3][3]; /* XYZ -&gt; luminance
matrix */</p></td>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">
<p valign="top">float d_YCR; /* Light o/p for reference
white */</p></td>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">
<p valign="top">float d_YCG;</p></td>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">
<p valign="top">float d_YCB;</p></td>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">
<p valign="top">uint32 d_Vrwr; /* Pixel values for ref.
white */</p></td>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">
<p valign="top">uint32 d_Vrwg;</p></td>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">
<p valign="top">uint32 d_Vrwb;</p></td>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">
<p valign="top">float d_Y0R; /* Residual light for black
pixel */</p></td>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">
<p valign="top">float d_Y0G;</p></td>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">
<p valign="top">float d_Y0B;</p></td>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">
<p valign="top">float d_gammaR; /* Gamma values for the
three guns */</p></td>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">
<p valign="top">float d_gammaG;</p></td>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">
<p valign="top">float d_gammaB;</p></td>
</table>
<p style="margin-left:22%;">} TIFFDisplay;</p>
<p style="margin-left:11%; margin-top: 1em">For example,
the one can use sRGB device, which has the following
parameters:</p>
<p style="margin-left:22%; margin-top: 1em">TIFFDisplay
display_sRGB = {</p>
<table width="100%" border=0 rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%"></td>
<td width="8%"></td>
<td width="77%">
<p valign="top">{ /* XYZ -&gt; luminance matrix */</p></td>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%"></td>
<td width="8%">
</td>
<td width="77%">
</td>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%"></td>
<td width="8%"></td>
<td width="77%">
<p valign="top">{ 3.2410F, -1.5374F, -0.4986F },</p></td>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%"></td>
<td width="8%">
</td>
<td width="77%">
</td>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%"></td>
<td width="8%"></td>
<td width="77%">
<p valign="top">{ -0.9692F, 1.8760F, 0.0416F },</p></td>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%"></td>
<td width="8%">
</td>
<td width="77%">
</td>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%"></td>
<td width="8%"></td>
<td width="77%">
<p valign="top">{ 0.0556F, -0.2040F, 1.0570F }</p></td>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%"></td>
<td width="8%">
</td>
<td width="77%">
<p valign="top">},</p></td>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%"></td>
<td width="8%"></td>
<td width="77%">
</td>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%"></td>
<td width="8%"></td>
<td width="77%">
<p valign="top">100.0F, 100.0F, 100.0F, /* Light o/p for
reference white */</p></td>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%"></td>
<td width="8%"></td>
<td width="77%">
<p valign="top">255, 255, 255, /* Pixel values for ref.
white */</p></td>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%"></td>
<td width="8%"></td>
<td width="77%">
<p valign="top">1.0F, 1.0F, 1.0F, /* Residual light o/p for
black pixel */</p></td>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%"></td>
<td width="8%"></td>
<td width="77%">
<p valign="top">2.4F, 2.4F, 2.4F, /* Gamma values for the
three guns */</p></td>
</table>
<p style="margin-left:22%;">};</p>
<p style="margin-left:11%; margin-top: 1em"><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:</p>
<p style="margin-left:22%; margin-top: 1em">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</p>
<p style="margin-left:11%; margin-top: 1em">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:</p>
<p style="margin-left:22%; margin-top: 1em">float
*whitePoint; <br>
float refWhite[3];</p>
<p style="margin-left:22%; margin-top: 1em">/* Initialize
structures */ <br>
img-&gt;cielab = (TIFFCIELabToRGB *)</p>
<table width="100%" border=0 rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">
<p valign="top">_TIFFmalloc(sizeof(TIFFCIELabToRGB));</p></td>
</table>
<p style="margin-left:22%;">if (!cielab) {</p>
<table width="100%" border=0 rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%"></td>
<td width="8%"></td>
<td width="77%">
<p valign="top">TIFFError(&quot;CIE
L*a*b*-&gt;RGB&quot;,</p> </td>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%"></td>
<td width="8%">
</td>
<td width="77%">
</td>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%"></td>
<td width="8%"></td>
<td width="77%">
<p valign="top">&quot;No space for CIE L*a*b*-&gt;RGB
conversion state.&quot;);</p></td>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%"></td>
<td width="8%"></td>
<td width="77%">
<p valign="top">exit(0);</p></td>
</table>
<p style="margin-left:22%;">}</p>
<p style="margin-left:22%; margin-top: 1em">TIFFGetFieldDefaulted(tif,
TIFFTAG_WHITEPOINT, &amp;whitePoint); <br>
refWhite[1] = 100.0F; <br>
refWhite[0] = whitePoint[0] / whitePoint[1] * refWhite[1];
<br>
refWhite[2] = (1.0F - whitePoint[0] - whitePoint[1])</p>
<table width="100%" border=0 rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">
<p valign="top">/ whitePoint[1] * refWhite[1];</p></td>
</table>
<p style="margin-left:22%;">if (TIFFCIELabToRGBInit(cielab,
&amp;display_sRGB, refWhite) &lt; 0) {</p>
<table width="100%" border=0 rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%"></td>
<td width="8%"></td>
<td width="77%">
<p valign="top">TIFFError(&quot;CIE
L*a*b*-&gt;RGB&quot;,</p> </td>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%"></td>
<td width="8%">
</td>
<td width="77%">
</td>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%"></td>
<td width="8%"></td>
<td width="77%">
<p valign="top">&quot;Failed to initialize CIE
L*a*b*-&gt;RGB conversion state.&quot;);</p></td>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%"></td>
<td width="8%"></td>
<td width="77%">
<p valign="top">_TIFFfree(cielab);</p></td>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="7%"></td>
<td width="8%"></td>
<td width="77%">
<p valign="top">exit(0);</p></td>
</table>
<p style="margin-left:22%;">}</p>
<p style="margin-left:22%; margin-top: 1em">/* Now we can
start to convert */ <br>
uint32 r, g, b; <br>
uint32 L; <br>
int32 a, b; <br>
float X, Y, Z;</p>
<p style="margin-left:22%; margin-top: 1em">for each pixel
in image</p>
<table width="100%" border=0 rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">
<p valign="top">TIFFCIELabToXYZ(cielab, L, a, b, &amp;X,
&amp;Y, &amp;Z);</p></td>
<tr valign="top" align="left">
<td width="8%"></td>
<td width="92%">
<p valign="top">TIFFXYZToRGB(cielab, X, Y, Z, &amp;r,
&amp;g, &amp;b);</p></td>
</table>
<p style="margin-left:22%; margin-top: 1em">/* Don&rsquo;t
forget to free the state structure */ <br>
_TIFFfree(cielab);</p>
<a name="SEE ALSO"></a>
<h2>SEE ALSO</h2>
<p style="margin-left:11%; margin-top: 1em"><b>TIFFRGBAImage</b>(3TIFF)
<b>libtiff</b>(3TIFF),</p>
<p style="margin-left:11%; margin-top: 1em">Libtiff library
home page: <b>http://www.remotesensing.org/libtiff/</b></p>
<hr>
</body>
</html>