~ubuntu-branches/ubuntu/karmic/tiff/karmic-security

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
<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>