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

« back to all changes in this revision

Viewing changes to html/man/TIFFcolor.3t.html

  • Committer: Bazaar Package Importer
  • Author(s): Fabio M. Di Nitto
  • Date: 2004-10-14 07:57:59 UTC
  • Revision ID: james.westby@ubuntu.com-20041014075759-a77e7zuaetya8cp0
Tags: upstream-3.6.1
ImportĀ upstreamĀ versionĀ 3.6.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<html>
 
2
<head>
 
3
<meta name="generator" content="groff -Thtml, see www.gnu.org">
 
4
<meta name="Content-Style" content="text/css">
 
5
<title>COLOR</title>
 
6
</head>
 
7
<body>
 
8
 
 
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>
 
14
 
 
15
<hr>
 
16
<!-- Creator     : groff version 1.17.2 -->
 
17
<!-- CreationDate: Mon Dec 22 00:39:20 2003 -->
 
18
<a name="NAME"></a>
 
19
<h2>NAME</h2>
 
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>
 
26
<h2>SYNOPSIS</h2>
 
27
 
 
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 &lt;tiffio.h&gt;</b></td></table>
 
33
 
 
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&quot;</i><b>);&quot;<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>
 
46
 
 
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&quot;</i><b>,</b><i>uint32</i><b>*&quot;</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>
 
64
<h2>DESCRIPTION</h2>
 
65
 
 
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>
 
77
 
 
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>
 
86
as</td></table>
 
87
 
 
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-&gt;RGB support */
 
93
        TIFFRGBValue* clamptab; /* range clamping table */
 
94
        int*         Cr_r_tab;
 
95
        int*         Cb_b_tab;
 
96
        int32*       Cr_g_tab;
 
97
        int32*       Cb_g_tab;
 
98
        int32*        Y_tab;
 
99
} TIFFYCbCrToRGB;
 
100
</pre></td></table>
 
101
 
 
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>
 
118
 
 
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;
 
124
uint16 hs, vs;
 
125
 
 
126
/* Initialize structures */
 
127
ycbcr = (TIFFYCbCrToRGB*)
 
128
     _TIFFmalloc(TIFFroundup(sizeof(TIFFYCbCrToRGB), sizeof(long))
 
129
          + 4*256*sizeof(TIFFRGBValue)
 
130
          + 2*256*sizeof(int)
 
131
          + 3*256*sizeof(int32));
 
132
if (ycbcr == NULL) {
 
133
        TIFFError(&quot;YCbCr-&gt;RGB&quot;,
 
134
          &quot;No space for YCbCr-&gt;RGB conversion state&quot;);
 
135
        exit(0);
 
136
}
 
137
 
 
138
TIFFGetFieldDefaulted(tif, TIFFTAG_YCBCRCOEFFICIENTS, &amp;luma);
 
139
TIFFGetFieldDefaulted(tif, TIFFTAG_REFERENCEBLACKWHITE, &amp;refBlackWhite);
 
140
if (TIFFYCbCrToRGBInit(ycbcr, luma, refBlackWhite) &lt; 0)
 
141
     exit(0);
 
142
 
 
143
/* Start conversion */
 
144
uint32 r, g, b;
 
145
uint32 Y;
 
146
int32 Cb, Cr;
 
147
 
 
148
for each pixel in image
 
149
     TIFFYCbCrtoRGB(img-&gt;ycbcr, Y, Cb, Cr, &amp;r, &amp;g, &amp;b);
 
150
 
 
151
/* Free state structure */
 
152
_TIFFfree(ycbcr);
 
153
</pre></td></table>
 
154
 
 
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>
 
162
 
 
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
 
168
 
 
169
typedef struct {              /* CIE Lab 1976-&gt;RGB support */
 
170
     int  range;              /* Size of conversion table */
 
171
     float     rstep, gstep, bstep;
 
172
     float     X0, Y0, Z0;         /* Reference white point */
 
173
     TIFFDisplay display;
 
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 */
 
177
} TIFFCIELabToRGB;
 
178
</pre></td></table>
 
179
 
 
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
 
185
as</td></table>
 
186
 
 
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 -&gt; luminance matrix */
 
193
     float d_YCR;       /* Light o/p for reference white */
 
194
     float d_YCG;
 
195
     float d_YCB;
 
196
     int d_Vrwr;        /* Pixel values for ref. white */
 
197
     int d_Vrwg;
 
198
     int d_Vrwb;
 
199
     float d_Y0R;       /* Residual light for black pixel */
 
200
     float d_Y0G;
 
201
     float d_Y0B;
 
202
     float d_gammaR;    /* Gamma values for the three guns */
 
203
     float d_gammaG;
 
204
     float d_gammaB;
 
205
} TIFFDisplay;
 
206
</pre></td></table>
 
207
 
 
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>
 
214
 
 
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 -&gt; luminance matrix */
 
221
          {  3.2410F, -1.5374F, -0.4986F },
 
222
          {  -0.9692F, 1.8760F, 0.0416F },
 
223
          {  0.0556F, -0.2040F, 1.0570F }
 
224
     },
 
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 */
 
229
};
 
230
</pre></td></table>
 
231
 
 
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>
 
241
 
 
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>
 
250
 
 
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
 
260
below:</td></table>
 
261
 
 
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;
 
267
float   refWhite[3];
 
268
 
 
269
/* Initialize structures */
 
270
img-&gt;cielab = (TIFFCIELabToRGB *)
 
271
     _TIFFmalloc(sizeof(TIFFCIELabToRGB));
 
272
if (!cielab) {
 
273
     TIFFError(&quot;CIE L*a*b*-&gt;RGB&quot;,
 
274
          &quot;No space for CIE L*a*b*-&gt;RGB conversion state.&quot;);
 
275
     exit(0);
 
276
}
 
277
 
 
278
TIFFGetFieldDefaulted(tif, TIFFTAG_WHITEPOINT, &amp;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, &amp;display_sRGB, refWhite) &lt; 0) {
 
284
     TIFFError(&quot;CIE L*a*b*-&gt;RGB&quot;,
 
285
          &quot;Failed to initialize CIE L*a*b*-&gt;RGB conversion state.&quot;);
 
286
     _TIFFfree(cielab);
 
287
     exit(0);
 
288
}
 
289
 
 
290
/* Now we can start to convert */
 
291
uint32 r, g, b;
 
292
uint32 L;
 
293
int32 a, b;
 
294
float X, Y, Z;
 
295
 
 
296
for each pixel in image
 
297
     TIFFCIELabToXYZ(cielab, L, a, b, &amp;X, &amp;Y, &amp;Z);
 
298
     TIFFXYZToRGB(cielab, X, Y, Z, &amp;r, &amp;g, &amp;b);
 
299
 
 
300
/* Don't forget to free the state structure */
 
301
_TIFFfree(cielab);
 
302
</pre></td></table>
 
303
<a name="SEE ALSO"></a>
 
304
<h2>SEE ALSO</h2>
 
305
 
 
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>
 
311
<hr>
 
312
</body>
 
313
</html>