3
<meta name="generator" content="groff -Thtml, see www.gnu.org">
4
<meta name="Content-Style" content="text/css">
9
<h1 align=center>COLOR</h1>
10
<a href="#NAME">NAME</a><br>
11
<a href="#SYNOPSIS">SYNOPSIS</a><br>
12
<a href="#DESCRIPTION">DESCRIPTION</a><br>
13
<a href="#SEE ALSO">SEE ALSO</a><br>
16
<!-- Creator : groff version 1.17.2 -->
17
<!-- CreationDate: Mon Dec 22 00:39:20 2003 -->
20
<table width="100%" border=0 rules="none" frame="void"
21
cols="2" cellspacing="0" cellpadding="0">
22
<tr valign="top" align="left">
23
<td width="10%"></td><td width="90%">
24
TIFFYCbCrToRGBInit, TIFFYCbCrtoRGB, TIFFCIELabToRGBInit, TIFFCIELabToXYZ, TIFFXYZToRGB - color conversion routines.</td></table>
25
<a name="SYNOPSIS"></a>
28
<table width="100%" border=0 rules="none" frame="void"
29
cols="2" cellspacing="0" cellpadding="0">
30
<tr valign="top" align="left">
31
<td width="10%"></td><td width="90%">
32
<b>#include <tiffio.h></b></td></table>
34
<table width="100%" border=0 rules="none" frame="void"
35
cols="2" cellspacing="0" cellpadding="0">
36
<tr valign="top" align="left">
37
<td width="10%"></td><td width="90%">
38
<b>int TIFFYCbCrToRGBInit(TIFFYCbCrToRGB
39
*</b><i>ycbcr</i><b>, float *</b><i>luma</i><b>, float
40
*</b><i>refBlackWhite"</i><b>);"<br>
41
void TIFFYCbCrtoRGB(TIFFYCbCrToRGB *</b><i>ycbcr</i><b>,
42
uint32</b> <i>Y</i><b>, int32</b> <i>Cb</i><b>, int32</b>
43
<i>Cr</i><b>, uint32 *</b><i>R</i><b>, uint32
44
*</b><i>G</i><b>, uint32 *</b><i>B</i>
45
<b>);</b></td></table>
47
<table width="100%" border=0 rules="none" frame="void"
48
cols="2" cellspacing="0" cellpadding="0">
49
<tr valign="top" align="left">
50
<td width="10%"></td><td width="90%">
51
<b>int TIFFCIELabToRGBInit(TIFFCIELabToRGB
52
*</b><i>cielab</i><b>, TIFFDisplay *</b><i>display</i><b>,
53
float *</b><i>refWhite</i><b>);<br>
54
void TIFFCIELabToXYZ(TIFFCIELabToRGB *</b><i>cielab</i><b>,
55
uint32</b> <i>L</i><b>, int32</b> <i>a</i><b>, int32</b>
56
<i>b</i><b>, float *</b><i>X</i><b>, float *</b><i>Y</i><b>,
57
float *</b><i>Z</i><b>);<br>
58
void TIFFXYZToRGB(TIFFCIELabToRGB *</b><i>cielab</i><b>,
59
float</b> <i>X</i><b>, float</b> <i>Y</i><b>, float</b>
60
<i>Z"</i><b>,</b><i>uint32</i><b>*"</b><i>R</i><b>,
61
uint32 *</b><i>G</i><b>, uint32
62
*</b><i>B</i><b>);</b></td></table>
63
<a name="DESCRIPTION"></a>
66
<table width="100%" border=0 rules="none" frame="void"
67
cols="2" cellspacing="0" cellpadding="0">
68
<tr valign="top" align="left">
69
<td width="10%"></td><td width="90%">
70
TIFF supports several color spaces for images stored in that
71
format. There is usually a problem of application to handle
72
the data properly and convert between different colorspaces
73
for displaying and printing purposes. To simplify this task
74
libtiff implements several color conversion routines itself.
75
In particular, these routines used in
76
<b>TIFFRGBAImage(3T)</b> interface.</td></table>
78
<table width="100%" border=0 rules="none" frame="void"
79
cols="2" cellspacing="0" cellpadding="0">
80
<tr valign="top" align="left">
81
<td width="10%"></td><td width="90%">
82
<b>TIFFYCbCrToRGBInit()</b> used to initialize <i>YCbCr</i>
83
to <i>RGB</i> conversion state. Allocating and freeing of
84
the <i>ycbcr</i> structure belongs to programmer.
85
<i>TIFFYCbCrToRGB</i> defined in <b>tiffio.h</b>
88
<table width="100%" border=0 rules="none" frame="void"
89
cols="2" cellspacing="0" cellpadding="0">
90
<tr valign="top" align="left">
91
<td width="21%"></td><td width="79%">
92
<pre>typedef struct { /* YCbCr->RGB support */
93
TIFFRGBValue* clamptab; /* range clamping table */
102
<table width="100%" border=0 rules="none" frame="void"
103
cols="2" cellspacing="0" cellpadding="0">
104
<tr valign="top" align="left">
105
<td width="10%"></td><td width="90%">
106
<i>luma</i> is a float array of three values representing
107
proportions of the red, green and blue in luminance, Y (see
108
section 21 of the TIFF 6.0 specification, where the YCbCr
109
images discussed). <i>TIFFTAG_YCBCRCOEFFICIENTS</i> holds
110
that values in TIFF file. <i>refBlackWhite</i> is a float
111
array of 6 values which specifies a pair of headroom and
112
footroom image data values (codes) for each image component
113
(see section 20 of the TIFF 6.0 specification where the
114
colorinmetry fields discussed).
115
<i>TIFFTAG_REFERENCEBLACKWHITE</i> is responsible for
116
storing these values in TIFF file. Following code snippet
117
should helps to understand the the technique:</td></table>
119
<table width="100%" border=0 rules="none" frame="void"
120
cols="2" cellspacing="0" cellpadding="0">
121
<tr valign="top" align="left">
122
<td width="21%"></td><td width="79%">
123
<pre>float *luma, *refBlackWhite;
126
/* Initialize structures */
127
ycbcr = (TIFFYCbCrToRGB*)
128
_TIFFmalloc(TIFFroundup(sizeof(TIFFYCbCrToRGB), sizeof(long))
129
+ 4*256*sizeof(TIFFRGBValue)
131
+ 3*256*sizeof(int32));
133
TIFFError("YCbCr->RGB",
134
"No space for YCbCr->RGB conversion state");
138
TIFFGetFieldDefaulted(tif, TIFFTAG_YCBCRCOEFFICIENTS, &luma);
139
TIFFGetFieldDefaulted(tif, TIFFTAG_REFERENCEBLACKWHITE, &refBlackWhite);
140
if (TIFFYCbCrToRGBInit(ycbcr, luma, refBlackWhite) < 0)
143
/* Start conversion */
148
for each pixel in image
149
TIFFYCbCrtoRGB(img->ycbcr, Y, Cb, Cr, &r, &g, &b);
151
/* Free state structure */
155
<table width="100%" border=0 rules="none" frame="void"
156
cols="2" cellspacing="0" cellpadding="0">
157
<tr valign="top" align="left">
158
<td width="10%"></td><td width="90%">
159
<b>TIFFCIELabToRGBInit()</b> initializes the <i>CIE L*a*b*
160
1976</i> to <i>RGB</i> conversion state.
161
<b>TIFFCIELabToRGB</b> defined as</td></table>
163
<table width="100%" border=0 rules="none" frame="void"
164
cols="2" cellspacing="0" cellpadding="0">
165
<tr valign="top" align="left">
166
<td width="21%"></td><td width="79%">
167
<pre>#define CIELABTORGB_TABLE_RANGE 1500
169
typedef struct { /* CIE Lab 1976->RGB support */
170
int range; /* Size of conversion table */
171
float rstep, gstep, bstep;
172
float X0, Y0, Z0; /* Reference white point */
174
float Yr2r[CIELABTORGB_TABLE_RANGE + 1]; /* Conversion of Yr to r */
175
float Yg2g[CIELABTORGB_TABLE_RANGE + 1]; /* Conversion of Yg to g */
176
float Yb2b[CIELABTORGB_TABLE_RANGE + 1]; /* Conversion of Yb to b */
180
<table width="100%" border=0 rules="none" frame="void"
181
cols="2" cellspacing="0" cellpadding="0">
182
<tr valign="top" align="left">
183
<td width="10%"></td><td width="90%">
184
<i>display</i> is a display device description, declared
187
<table width="100%" border=0 rules="none" frame="void"
188
cols="2" cellspacing="0" cellpadding="0">
189
<tr valign="top" align="left">
190
<td width="21%"></td><td width="79%">
191
<pre>typedef struct {
192
float d_mat[3][3]; /* XYZ -> luminance matrix */
193
float d_YCR; /* Light o/p for reference white */
196
int d_Vrwr; /* Pixel values for ref. white */
199
float d_Y0R; /* Residual light for black pixel */
202
float d_gammaR; /* Gamma values for the three guns */
208
<table width="100%" border=0 rules="none" frame="void"
209
cols="2" cellspacing="0" cellpadding="0">
210
<tr valign="top" align="left">
211
<td width="10%"></td><td width="90%">
212
For example, the one can use sRGB device, which has the
213
following parameters:</td></table>
215
<table width="100%" border=0 rules="none" frame="void"
216
cols="2" cellspacing="0" cellpadding="0">
217
<tr valign="top" align="left">
218
<td width="21%"></td><td width="79%">
219
<pre>TIFFDisplay display_sRGB = {
220
{ /* XYZ -> luminance matrix */
221
{ 3.2410F, -1.5374F, -0.4986F },
222
{ -0.9692F, 1.8760F, 0.0416F },
223
{ 0.0556F, -0.2040F, 1.0570F }
225
100.0F, 100.0F, 100.0F, /* Light o/p for reference white */
226
255, 255, 255, /* Pixel values for ref. white */
227
1.0F, 1.0F, 1.0F, /* Residual light o/p for black pixel */
228
2.4F, 2.4F, 2.4F, /* Gamma values for the three guns */
232
<table width="100%" border=0 rules="none" frame="void"
233
cols="2" cellspacing="0" cellpadding="0">
234
<tr valign="top" align="left">
235
<td width="10%"></td><td width="90%">
236
<i>refWhite</i> is a color temperature of the reference
237
white. The <i>TIFFTAG_WHITEPOINT</i> contains the
238
chromaticity of the white point of the image from where the
239
reference white can be calculated using following
240
formulae:</td></table>
242
<table width="100%" border=0 rules="none" frame="void"
243
cols="2" cellspacing="0" cellpadding="0">
244
<tr valign="top" align="left">
245
<td width="21%"></td><td width="79%">
246
refWhite_Y = 100.0<br>
247
refWhite_X = whitePoint_x / whitePoint_y * refWhite_Y<br>
248
refWhite_Z = (1.0 - whitePoint_x - whitePoint_y) /
249
whitePoint_y * refWhite_X</td></table>
251
<table width="100%" border=0 rules="none" frame="void"
252
cols="2" cellspacing="0" cellpadding="0">
253
<tr valign="top" align="left">
254
<td width="10%"></td><td width="90%">
255
The conversion itself performed in two steps: at the first
256
one we will convert <i>CIE L*a*b* 1976</i> to <i>CIE XYZ</i>
257
using <b>TIFFCIELabToXYZ()</b> routine, and at the second
258
step we will convert <i>CIE XYZ</i> to <i>RGB</i> using
259
<b>TIFFXYZToRGB().</b> Look at the code sample
262
<table width="100%" border=0 rules="none" frame="void"
263
cols="2" cellspacing="0" cellpadding="0">
264
<tr valign="top" align="left">
265
<td width="21%"></td><td width="79%">
266
<pre>float *whitePoint;
269
/* Initialize structures */
270
img->cielab = (TIFFCIELabToRGB *)
271
_TIFFmalloc(sizeof(TIFFCIELabToRGB));
273
TIFFError("CIE L*a*b*->RGB",
274
"No space for CIE L*a*b*->RGB conversion state.");
278
TIFFGetFieldDefaulted(tif, TIFFTAG_WHITEPOINT, &whitePoint);
279
refWhite[1] = 100.0F;
280
refWhite[0] = whitePoint[0] / whitePoint[1] * refWhite[1];
281
refWhite[2] = (1.0F - whitePoint[0] - whitePoint[1])
282
/ whitePoint[1] * refWhite[1];
283
if (TIFFCIELabToRGBInit(cielab, &display_sRGB, refWhite) < 0) {
284
TIFFError("CIE L*a*b*->RGB",
285
"Failed to initialize CIE L*a*b*->RGB conversion state.");
290
/* Now we can start to convert */
296
for each pixel in image
297
TIFFCIELabToXYZ(cielab, L, a, b, &X, &Y, &Z);
298
TIFFXYZToRGB(cielab, X, Y, Z, &r, &g, &b);
300
/* Don't forget to free the state structure */
303
<a name="SEE ALSO"></a>
306
<table width="100%" border=0 rules="none" frame="void"
307
cols="2" cellspacing="0" cellpadding="0">
308
<tr valign="top" align="left">
309
<td width="10%"></td><td width="90%">
310
<i>libtiff</i>(3T),<i>TIFFRGBAImage(3T)</i></td></table>