1 <!-- Creator : groff version 1.18.1 -->
2 <!-- CreationDate: Mon Mar 13 18:03:08 2006 -->
5 <meta name=
"generator" content=
"groff -Thtml, see www.gnu.org">
6 <meta name=
"Content-Style" content=
"text/css">
11 <h1 align=center
>COLOR
</h1>
12 <a href=
"#NAME">NAME
</a><br>
13 <a href=
"#SYNOPSIS">SYNOPSIS
</a><br>
14 <a href=
"#DESCRIPTION">DESCRIPTION
</a><br>
15 <a href=
"#SEE ALSO">SEE ALSO
</a><br>
21 <table width=
"100%" border=
0 rules=
"none" frame=
"void"
22 cols=
"2" cellspacing=
"0" cellpadding=
"0">
23 <tr valign=
"top" align=
"left">
26 <p>TIFFYCbCrToRGBInit, TIFFYCbCrtoRGB, TIFFCIELabToRGBInit,
27 TIFFCIELabToXYZ, TIFFXYZToRGB
− color conversion
31 <a name=
"SYNOPSIS"></a>
34 <table width=
"100%" border=
0 rules=
"none" frame=
"void"
35 cols=
"2" cellspacing=
"0" cellpadding=
"0">
36 <tr valign=
"top" align=
"left">
39 <p><b>#include
<tiffio.h
></b></p>
41 <p><b>int TIFFYCbCrToRGBInit(TIFFYCbCrToRGB
42 *
</b><i>ycbcr
</i><b>, float *
</b><i>luma
</i><b>, float
43 *
</b><i>refBlackWhite
"</i><b>);
"<br>
44 void TIFFYCbCrtoRGB(TIFFYCbCrToRGB *
</b><i>ycbcr
</i><b>,
45 uint32
</b> <i>Y
</i><b>, int32
</b> <i>Cb
</i><b>, int32
</b>
46 <i>Cr
</i><b>, uint32 *
</b><i>R
</i><b>, uint32
47 *
</b><i>G
</i><b>, uint32 *
</b><i>B
</i> <b>);
</b></p>
49 <p><b>int TIFFCIELabToRGBInit(TIFFCIELabToRGB
50 *
</b><i>cielab
</i><b>, TIFFDisplay *
</b><i>display
</i><b>,
51 float *
</b><i>refWhite
</i><b>);
<br>
52 void TIFFCIELabToXYZ(TIFFCIELabToRGB *
</b><i>cielab
</i><b>,
53 uint32
</b> <i>L
</i><b>, int32
</b> <i>a
</i><b>, int32
</b>
54 <i>b
</i><b>, float *
</b><i>X
</i><b>, float *
</b><i>Y
</i><b>,
55 float *
</b><i>Z
</i><b>);
<br>
56 void TIFFXYZToRGB(TIFFCIELabToRGB *
</b><i>cielab
</i><b>,
57 float
</b> <i>X
</i><b>, float
</b> <i>Y
</i><b>, float
</b>
58 <i>Z
"</i><b>,
</b><i>uint32
</i><b>*
"</b><i>R
</i><b>,
59 uint32 *
</b><i>G
</i><b>, uint32 *
</b><i>B
</i><b>);
</b></p>
62 <a name=
"DESCRIPTION"></a>
65 <table width=
"100%" border=
0 rules=
"none" frame=
"void"
66 cols=
"2" cellspacing=
"0" cellpadding=
"0">
67 <tr valign=
"top" align=
"left">
70 <p>TIFF supports several color spaces for images stored in
71 that format. There is usually a problem of application to
72 handle the data properly and convert between different
73 colorspaces for displaying and printing purposes. To
74 simplify this task libtiff implements several color
75 conversion routines itself. In particular, these routines
76 used in
<b>TIFFRGBAImage(
3TIFF)
</b> interface.
</p>
78 <p><b>TIFFYCbCrToRGBInit()
</b> used to initialize
79 <i>YCbCr
</i> to
<i>RGB
</i> conversion state. Allocating and
80 freeing of the
<i>ycbcr
</i> structure belongs to programmer.
81 <i>TIFFYCbCrToRGB
</i> defined in
<b>tiffio.h
</b> as
</p>
85 <table width=
"100%" border=
0 rules=
"none" frame=
"void"
86 cols=
"2" cellspacing=
"0" cellpadding=
"0">
87 <tr valign=
"top" align=
"left">
90 <pre>typedef struct { /* YCbCr-
>RGB support */
91 TIFFRGBValue* clamptab; /* range clamping table */
97 <table width=
"100%" border=
0 rules=
"none" frame=
"void"
98 cols=
"5" cellspacing=
"0" cellpadding=
"0">
99 <tr valign=
"top" align=
"left">
102 <td width=
"28%"></td>
103 <td width=
"-3%"></td>
104 <td width=
"12%"></td>
112 <tr valign=
"top" align=
"left">
113 <td width=
"28%"></td>
114 <td width=
"-3%"></td>
115 <td width=
"12%"></td>
123 <tr valign=
"top" align=
"left">
124 <td width=
"28%"></td>
125 <td width=
"-3%"></td>
126 <td width=
"12%"></td>
134 <tr valign=
"top" align=
"left">
135 <td width=
"28%"></td>
136 <td width=
"-3%"></td>
137 <td width=
"12%"></td>
146 <table width=
"100%" border=
0 rules=
"none" frame=
"void"
147 cols=
"2" cellspacing=
"0" cellpadding=
"0">
148 <tr valign=
"top" align=
"left">
149 <td width=
"17%"></td>
152 } TIFFYCbCrToRGB;
</p></td>
155 <table width=
"100%" border=
0 rules=
"none" frame=
"void"
156 cols=
"2" cellspacing=
"0" cellpadding=
"0">
157 <tr valign=
"top" align=
"left">
160 <p><i>luma
</i> is a float array of three values representing
161 proportions of the red, green and blue in luminance, Y (see
162 section
21 of the TIFF
6.0 specification, where the YCbCr
163 images discussed).
<i>TIFFTAG_YCBCRCOEFFICIENTS
</i> holds
164 that values in TIFF file.
<i>refBlackWhite
</i> is a float
165 array of
6 values which specifies a pair of headroom and
166 footroom image data values (codes) for each image component
167 (see section
20 of the TIFF
6.0 specification where the
168 colorinmetry fields discussed).
169 <i>TIFFTAG_REFERENCEBLACKWHITE
</i> is responsible for
170 storing these values in TIFF file. Following code snippet
171 should helps to understand the the technique:
</p>
175 <table width=
"100%" border=
0 rules=
"none" frame=
"void"
176 cols=
"2" cellspacing=
"0" cellpadding=
"0">
177 <tr valign=
"top" align=
"left">
178 <td width=
"17%"></td>
180 <pre>float *luma, *refBlackWhite;
183 /* Initialize structures */
184 ycbcr = (TIFFYCbCrToRGB*)
190 <table width=
"100%" border=
0 rules=
"none" frame=
"void"
191 cols=
"2" cellspacing=
"0" cellpadding=
"0">
192 <tr valign=
"top" align=
"left">
193 <td width=
"24%"></td>
196 <p>_TIFFmalloc(TIFFroundup(sizeof(TIFFYCbCrToRGB),
199 <tr valign=
"top" align=
"left">
200 <td width=
"24%"></td>
203 <p>+
4*
256*sizeof(TIFFRGBValue)
</p>
205 <tr valign=
"top" align=
"left">
206 <td width=
"24%"></td>
209 <p>+
2*
256*sizeof(int)
</p>
211 <tr valign=
"top" align=
"left">
212 <td width=
"24%"></td>
215 <p>+
3*
256*sizeof(int32));
</p>
219 <table width=
"100%" border=
0 rules=
"none" frame=
"void"
220 cols=
"2" cellspacing=
"0" cellpadding=
"0">
221 <tr valign=
"top" align=
"left">
222 <td width=
"17%"></td>
224 <p>if (ycbcr == NULL) {
<br>
225 TIFFError(
"YCbCr-
>RGB
",
</p></td>
228 <table width=
"100%" border=
0 rules=
"none" frame=
"void"
229 cols=
"4" cellspacing=
"0" cellpadding=
"0">
230 <tr valign=
"top" align=
"left">
231 <td width=
"24%"></td>
236 <p>"No space for YCbCr-
>RGB conversion
243 <table width=
"100%" border=
0 rules=
"none" frame=
"void"
244 cols=
"2" cellspacing=
"0" cellpadding=
"0">
245 <tr valign=
"top" align=
"left">
246 <td width=
"17%"></td>
251 <p>TIFFGetFieldDefaulted(tif, TIFFTAG_YCBCRCOEFFICIENTS,
253 TIFFGetFieldDefaulted(tif, TIFFTAG_REFERENCEBLACKWHITE,
254 &refBlackWhite);
<br>
255 if (TIFFYCbCrToRGBInit(ycbcr, luma, refBlackWhite)
<
259 <table width=
"100%" border=
0 rules=
"none" frame=
"void"
260 cols=
"2" cellspacing=
"0" cellpadding=
"0">
261 <tr valign=
"top" align=
"left">
262 <td width=
"24%"></td>
269 <table width=
"100%" border=
0 rules=
"none" frame=
"void"
270 cols=
"2" cellspacing=
"0" cellpadding=
"0">
271 <tr valign=
"top" align=
"left">
272 <td width=
"17%"></td>
274 <p>/* Start conversion */
<br>
279 <p>for each pixel in image
</p></td>
282 <table width=
"100%" border=
0 rules=
"none" frame=
"void"
283 cols=
"2" cellspacing=
"0" cellpadding=
"0">
284 <tr valign=
"top" align=
"left">
285 <td width=
"24%"></td>
288 <p>TIFFYCbCrtoRGB(img-
>ycbcr, Y, Cb, Cr,
&r,
&g,
293 <table width=
"100%" border=
0 rules=
"none" frame=
"void"
294 cols=
"2" cellspacing=
"0" cellpadding=
"0">
295 <tr valign=
"top" align=
"left">
296 <td width=
"17%"></td>
298 <p>/* Free state structure */
<br>
299 _TIFFfree(ycbcr);
</p></td>
302 <table width=
"100%" border=
0 rules=
"none" frame=
"void"
303 cols=
"2" cellspacing=
"0" cellpadding=
"0">
304 <tr valign=
"top" align=
"left">
307 <p><b>TIFFCIELabToRGBInit()
</b> initializes the
<i>CIE
308 L*a*b*
1976</i> to
<i>RGB
</i> conversion state.
309 <b>TIFFCIELabToRGB
</b> defined as
</p>
313 <table width=
"100%" border=
0 rules=
"none" frame=
"void"
314 cols=
"2" cellspacing=
"0" cellpadding=
"0">
315 <tr valign=
"top" align=
"left">
316 <td width=
"17%"></td>
318 <pre>#define CIELABTORGB_TABLE_RANGE
1500
325 <table width=
"100%" border=
0 rules=
"none" frame=
"void"
326 cols=
"9" cellspacing=
"0" cellpadding=
"0">
327 <tr valign=
"top" align=
"left">
328 <td width=
"17%"></td>
331 <p>typedef struct {
</p>
340 <p>/* CIE Lab
1976-
>RGB support */
</p>
345 <tr valign=
"top" align=
"left">
346 <td width=
"17%"></td>
362 <p>/* Size of conversion table */
</p>
367 <tr valign=
"top" align=
"left">
368 <td width=
"17%"></td>
378 <p>rstep, gstep, bstep;
</p>
385 <tr valign=
"top" align=
"left">
386 <td width=
"17%"></td>
402 <p>/* Reference white point */
</p>
406 <tr valign=
"top" align=
"left">
407 <td width=
"17%"></td>
411 <p>TIFFDisplay display;
</p>
420 <tr valign=
"top" align=
"left">
421 <td width=
"17%"></td>
431 <p>Yr2r[CIELABTORGB_TABLE_RANGE +
1]; /* Conversion of Yr
439 <tr valign=
"top" align=
"left">
440 <td width=
"17%"></td>
450 <p>Yg2g[CIELABTORGB_TABLE_RANGE +
1]; /* Conversion of Yg
458 <tr valign=
"top" align=
"left">
459 <td width=
"17%"></td>
469 <p>Yb2b[CIELABTORGB_TABLE_RANGE +
1]; /* Conversion of Yb
479 <table width=
"100%" border=
0 rules=
"none" frame=
"void"
480 cols=
"2" cellspacing=
"0" cellpadding=
"0">
481 <tr valign=
"top" align=
"left">
482 <td width=
"17%"></td>
484 <p>} TIFFCIELabToRGB;
</p></td>
487 <table width=
"100%" border=
0 rules=
"none" frame=
"void"
488 cols=
"2" cellspacing=
"0" cellpadding=
"0">
489 <tr valign=
"top" align=
"left">
492 <p><i>display
</i> is a display device description, declared
497 <table width=
"100%" border=
0 rules=
"none" frame=
"void"
498 cols=
"2" cellspacing=
"0" cellpadding=
"0">
499 <tr valign=
"top" align=
"left">
500 <td width=
"17%"></td>
502 <pre>typedef struct {
508 <table width=
"100%" border=
0 rules=
"none" frame=
"void"
509 cols=
"2" cellspacing=
"0" cellpadding=
"0">
510 <tr valign=
"top" align=
"left">
511 <td width=
"24%"></td>
514 <p>float d_mat[
3][
3]; /* XYZ -
> luminance matrix */
</p>
516 <tr valign=
"top" align=
"left">
517 <td width=
"24%"></td>
520 <p>float d_YCR; /* Light o/p for reference white */
</p>
522 <tr valign=
"top" align=
"left">
523 <td width=
"24%"></td>
528 <tr valign=
"top" align=
"left">
529 <td width=
"24%"></td>
534 <tr valign=
"top" align=
"left">
535 <td width=
"24%"></td>
538 <p>uint32 d_Vrwr; /* Pixel values for ref. white */
</p>
540 <tr valign=
"top" align=
"left">
541 <td width=
"24%"></td>
544 <p>uint32 d_Vrwg;
</p>
546 <tr valign=
"top" align=
"left">
547 <td width=
"24%"></td>
550 <p>uint32 d_Vrwb;
</p>
552 <tr valign=
"top" align=
"left">
553 <td width=
"24%"></td>
556 <p>float d_Y0R; /* Residual light for black pixel */
</p>
558 <tr valign=
"top" align=
"left">
559 <td width=
"24%"></td>
564 <tr valign=
"top" align=
"left">
565 <td width=
"24%"></td>
570 <tr valign=
"top" align=
"left">
571 <td width=
"24%"></td>
574 <p>float d_gammaR; /* Gamma values for the three guns
577 <tr valign=
"top" align=
"left">
578 <td width=
"24%"></td>
581 <p>float d_gammaG;
</p>
583 <tr valign=
"top" align=
"left">
584 <td width=
"24%"></td>
587 <p>float d_gammaB;
</p>
591 <table width=
"100%" border=
0 rules=
"none" frame=
"void"
592 cols=
"2" cellspacing=
"0" cellpadding=
"0">
593 <tr valign=
"top" align=
"left">
594 <td width=
"17%"></td>
596 <p>} TIFFDisplay;
</p></td>
599 <table width=
"100%" border=
0 rules=
"none" frame=
"void"
600 cols=
"2" cellspacing=
"0" cellpadding=
"0">
601 <tr valign=
"top" align=
"left">
604 <p>For example, the one can use sRGB device, which has the
605 following parameters:
</p>
609 <table width=
"100%" border=
0 rules=
"none" frame=
"void"
610 cols=
"2" cellspacing=
"0" cellpadding=
"0">
611 <tr valign=
"top" align=
"left">
612 <td width=
"17%"></td>
614 <pre>TIFFDisplay display_sRGB = {
620 <table width=
"100%" border=
0 rules=
"none" frame=
"void"
621 cols=
"5" cellspacing=
"0" cellpadding=
"0">
622 <tr valign=
"top" align=
"left">
623 <td width=
"24%"></td>
627 <p>{ /* XYZ -
> luminance matrix */
</p>
632 <tr valign=
"top" align=
"left">
633 <td width=
"24%"></td>
639 <p>{
3.2410F, -
1.5374F, -
0.4986F },
</p>
643 <tr valign=
"top" align=
"left">
644 <td width=
"24%"></td>
650 <p>{ -
0.9692F,
1.8760F,
0.0416F },
</p>
654 <tr valign=
"top" align=
"left">
655 <td width=
"24%"></td>
661 <p>{
0.0556F, -
0.2040F,
1.0570F }
</p>
665 <tr valign=
"top" align=
"left">
666 <td width=
"24%"></td>
676 <tr valign=
"top" align=
"left">
677 <td width=
"24%"></td>
681 <p>100.0F,
100.0F,
100.0F, /* Light o/p for reference white
687 <tr valign=
"top" align=
"left">
688 <td width=
"24%"></td>
692 <p>255,
255,
255, /* Pixel values for ref. white */
</p>
697 <tr valign=
"top" align=
"left">
698 <td width=
"24%"></td>
702 <p>1.0F,
1.0F,
1.0F, /* Residual light o/p for black pixel
708 <tr valign=
"top" align=
"left">
709 <td width=
"24%"></td>
713 <p>2.4F,
2.4F,
2.4F, /* Gamma values for the three guns
721 <table width=
"100%" border=
0 rules=
"none" frame=
"void"
722 cols=
"2" cellspacing=
"0" cellpadding=
"0">
723 <tr valign=
"top" align=
"left">
724 <td width=
"17%"></td>
729 <table width=
"100%" border=
0 rules=
"none" frame=
"void"
730 cols=
"2" cellspacing=
"0" cellpadding=
"0">
731 <tr valign=
"top" align=
"left">
734 <p><i>refWhite
</i> is a color temperature of the reference
735 white. The
<i>TIFFTAG_WHITEPOINT
</i> contains the
736 chromaticity of the white point of the image from where the
737 reference white can be calculated using following
742 <table width=
"100%" border=
0 rules=
"none" frame=
"void"
743 cols=
"2" cellspacing=
"0" cellpadding=
"0">
744 <tr valign=
"top" align=
"left">
745 <td width=
"17%"></td>
747 <p>refWhite_Y =
100.0<br>
748 refWhite_X = whitePoint_x / whitePoint_y * refWhite_Y
<br>
749 refWhite_Z = (
1.0 - whitePoint_x - whitePoint_y) /
750 whitePoint_y * refWhite_X
</p></td>
753 <table width=
"100%" border=
0 rules=
"none" frame=
"void"
754 cols=
"2" cellspacing=
"0" cellpadding=
"0">
755 <tr valign=
"top" align=
"left">
758 <p>The conversion itself performed in two steps: at the
759 first one we will convert
<i>CIE L*a*b*
1976</i> to
<i>CIE
760 XYZ
</i> using
<b>TIFFCIELabToXYZ()
</b> routine, and at the
761 second step we will convert
<i>CIE XYZ
</i> to
<i>RGB
</i>
762 using
<b>TIFFXYZToRGB().
</b> Look at the code sample
767 <table width=
"100%" border=
0 rules=
"none" frame=
"void"
768 cols=
"2" cellspacing=
"0" cellpadding=
"0">
769 <tr valign=
"top" align=
"left">
770 <td width=
"17%"></td>
772 <pre>float *whitePoint;
775 /* Initialize structures */
776 img-
>cielab = (TIFFCIELabToRGB *)
782 <table width=
"100%" border=
0 rules=
"none" frame=
"void"
783 cols=
"2" cellspacing=
"0" cellpadding=
"0">
784 <tr valign=
"top" align=
"left">
785 <td width=
"24%"></td>
788 <p>_TIFFmalloc(sizeof(TIFFCIELabToRGB));
</p>
792 <table width=
"100%" border=
0 rules=
"none" frame=
"void"
793 cols=
"2" cellspacing=
"0" cellpadding=
"0">
794 <tr valign=
"top" align=
"left">
795 <td width=
"17%"></td>
797 <p>if (!cielab) {
</p></td>
800 <table width=
"100%" border=
0 rules=
"none" frame=
"void"
801 cols=
"5" cellspacing=
"0" cellpadding=
"0">
802 <tr valign=
"top" align=
"left">
803 <td width=
"24%"></td>
807 <p>TIFFError(
"CIE L*a*b*-
>RGB
",
</p>
812 <tr valign=
"top" align=
"left">
813 <td width=
"24%"></td>
819 <p>"No space for CIE L*a*b*-
>RGB conversion
824 <tr valign=
"top" align=
"left">
825 <td width=
"24%"></td>
836 <table width=
"100%" border=
0 rules=
"none" frame=
"void"
837 cols=
"2" cellspacing=
"0" cellpadding=
"0">
838 <tr valign=
"top" align=
"left">
839 <td width=
"17%"></td>
843 <p>TIFFGetFieldDefaulted(tif, TIFFTAG_WHITEPOINT,
844 &whitePoint);
<br>
845 refWhite[
1] =
100.0F;
<br>
846 refWhite[
0] = whitePoint[
0] / whitePoint[
1] *
848 refWhite[
2] = (
1.0F - whitePoint[
0] -
849 whitePoint[
1])
</p></td>
852 <table width=
"100%" border=
0 rules=
"none" frame=
"void"
853 cols=
"2" cellspacing=
"0" cellpadding=
"0">
854 <tr valign=
"top" align=
"left">
855 <td width=
"24%"></td>
858 <p>/ whitePoint[
1] * refWhite[
1];
</p>
862 <table width=
"100%" border=
0 rules=
"none" frame=
"void"
863 cols=
"2" cellspacing=
"0" cellpadding=
"0">
864 <tr valign=
"top" align=
"left">
865 <td width=
"17%"></td>
867 <p>if (TIFFCIELabToRGBInit(cielab,
&display_sRGB,
868 refWhite)
< 0) {
</p></td>
871 <table width=
"100%" border=
0 rules=
"none" frame=
"void"
872 cols=
"5" cellspacing=
"0" cellpadding=
"0">
873 <tr valign=
"top" align=
"left">
874 <td width=
"24%"></td>
878 <p>TIFFError(
"CIE L*a*b*-
>RGB
",
</p>
883 <tr valign=
"top" align=
"left">
884 <td width=
"24%"></td>
890 <p>"Failed to initialize CIE L*a*b*-
>RGB conversion
895 <tr valign=
"top" align=
"left">
896 <td width=
"24%"></td>
900 <p>_TIFFfree(cielab);
</p>
905 <tr valign=
"top" align=
"left">
906 <td width=
"24%"></td>
917 <table width=
"100%" border=
0 rules=
"none" frame=
"void"
918 cols=
"2" cellspacing=
"0" cellpadding=
"0">
919 <tr valign=
"top" align=
"left">
920 <td width=
"17%"></td>
924 <p>/* Now we can start to convert */
<br>
930 <p>for each pixel in image
</p></td>
933 <table width=
"100%" border=
0 rules=
"none" frame=
"void"
934 cols=
"2" cellspacing=
"0" cellpadding=
"0">
935 <tr valign=
"top" align=
"left">
936 <td width=
"24%"></td>
939 <p>TIFFCIELabToXYZ(cielab, L, a, b,
&X,
&Y,
942 <tr valign=
"top" align=
"left">
943 <td width=
"24%"></td>
946 <p>TIFFXYZToRGB(cielab, X, Y, Z,
&r,
&g,
951 <table width=
"100%" border=
0 rules=
"none" frame=
"void"
952 cols=
"2" cellspacing=
"0" cellpadding=
"0">
953 <tr valign=
"top" align=
"left">
954 <td width=
"17%"></td>
956 <p>/* Don
’t forget to free the state structure */
<br>
957 _TIFFfree(cielab);
</p></td>
959 <a name=
"SEE ALSO"></a>
962 <table width=
"100%" border=
0 rules=
"none" frame=
"void"
963 cols=
"2" cellspacing=
"0" cellpadding=
"0">
964 <tr valign=
"top" align=
"left">
967 <p><b>TIFFRGBAImage
</b>(
3TIFF)
<b>libtiff
</b>(
3TIFF),
</p>
969 <p>Libtiff library home page:
970 <b>http://www.remotesensing.org/libtiff/
</b></p>