.\" Man page generated from reStructuredText. . . .nr rst2man-indent-level 0 . .de1 rstReportMargin \\$1 \\n[an-margin] level \\n[rst2man-indent-level] level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] - \\n[rst2man-indent0] \\n[rst2man-indent1] \\n[rst2man-indent2] .. .de1 INDENT .\" .rstReportMargin pre: . RS \\$1 . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin] . nr rst2man-indent-level +1 .\" .rstReportMargin post: .. .de UNINDENT . RE .\" indent \\n[an-margin] .\" old: \\n[rst2man-indent\\n[rst2man-indent-level]] .nr rst2man-indent-level -1 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]] .in \\n[rst2man-indent\\n[rst2man-indent-level]]u .. .TH "TIFFCOLOR" "3tiff" "Nov 26, 2023" "4.6" "LibTIFF" .SH NAME TIFFcolor \- color conversion routines .SH SYNOPSIS .INDENT 0.0 .INDENT 3.5 .sp .EX #include .EE .UNINDENT .UNINDENT .INDENT 0.0 .TP .B int TIFFYCbCrToRGBInit(TIFFYCbCrToRGB *ycbcr, float *luma, float *refBlackWhite) .UNINDENT .INDENT 0.0 .TP .B void TIFFYCbCrtoRGB(TIFFYCbCrToRGB *ycbcr, uint32_t Y, int32_t Cb, int32_t Cr, uint32_t *R, uint32_t *G, uint32_t *B) .UNINDENT .INDENT 0.0 .TP .B int TIFFCIELabToRGBInit(TIFFCIELabToRGB *cielab, const TIFFDisplay *displayw, float *refWhite) .UNINDENT .INDENT 0.0 .TP .B void TIFFCIELabToXYZ(TIFFCIELabToRGB *cielab, uint32_t L, int32_t a, int32_t b, float *X, float *Y, float *Z) .UNINDENT .INDENT 0.0 .TP .B void TIFFXYZToRGB(TIFFCIELabToRGB *cielab, float X, float Y, float Z, uint32_t *R, uint32_t *G, uint32_t *B) .UNINDENT .SH DESCRIPTION .sp 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 \fBlibtiff\fP implements several color conversion routines itself. In particular, these routines used in the \fI\%TIFFRGBAImage\fP interface. .sp \fI\%TIFFYCbCrToRGBInit()\fP used to initialize \fIYCbCr\fP to \fIRGB\fP conversion state. Allocating and freeing of the \fIycbcr\fP structure belongs to programmer. \fBTIFFYCbCrToRGB\fP is defined in \fBtiffio.h\fP as: .INDENT 0.0 .INDENT 3.5 .sp .EX typedef struct { /* YCbCr\->RGB support */ TIFFRGBValue* clamptab; /* range clamping table */ int* Cr_r_tab; int* Cb_b_tab; int32_t* Cr_g_tab; int32_t* Cb_g_tab; int32_t* Y_tab; } TIFFYCbCrToRGB; .EE .UNINDENT .UNINDENT .sp \fIluma\fP 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 YCbCr images are discussed). \fBTIFFTAG_YCBCRCOEFFICIENTS\fP hold these values in TIFF file. \fIrefBlackWhite\fP 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 colorimetry fields are discussed). \fBTIFFTAG_REFERENCEBLACKWHITE\fP is responsible for storing these values in TIFF file. The following code snippet should help to understand the the technique: .INDENT 0.0 .INDENT 3.5 .sp .EX float *luma, *refBlackWhite; uint16_t hs, vs; /* Initialize structures */ ycbcr = (TIFFYCbCrToRGB*) _TIFFmalloc(TIFFroundup(sizeof(TIFFYCbCrToRGB), sizeof(long)) + 4*256*sizeof(TIFFRGBValue) + 2*256*sizeof(int) + 3*256*sizeof(int32_t)); if (ycbcr == NULL) { TIFFError(\(dqYCbCr\->RGB\(dq, \(dqNo space for YCbCr\->RGB conversion state\(dq); exit(0); } TIFFGetFieldDefaulted(tif, TIFFTAG_YCBCRCOEFFICIENTS, &luma); TIFFGetFieldDefaulted(tif, TIFFTAG_REFERENCEBLACKWHITE, &refBlackWhite); if (TIFFYCbCrToRGBInit(ycbcr, luma, refBlackWhite) < 0) { exit(0); } /* Start conversion */ uint32_t r, g, b; uint32_t Y; int32_t Cb, Cr; for each pixel in image { TIFFYCbCrtoRGB(img\->ycbcr, Y, Cb, Cr, &r, &g, &b); } /* Free state structure */ _TIFFfree(ycbcr); .EE .UNINDENT .UNINDENT .sp \fI\%TIFFCIELabToRGBInit()\fP initializes the \fICIE L*a*b* 1976\fP to \fIRGB\fP conversion state. \fBTIFFCIELabToRGB\fP is defined as: .INDENT 0.0 .INDENT 3.5 .sp .EX #define CIELABTORGB_TABLE_RANGE 1500 typedef struct { /* CIE Lab 1976\->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; .EE .UNINDENT .UNINDENT .sp \fIdisplay\fP is a display device description, declared as: .INDENT 0.0 .INDENT 3.5 .sp .EX typedef struct { float d_mat[3][3]; /* XYZ \-> luminance matrix */ float d_YCR; /* Light o/p for reference white */ float d_YCG; float d_YCB; uint32_t d_Vrwr; /* Pixel values for ref. white */ uint32_t d_Vrwg; uint32_t 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; .EE .UNINDENT .UNINDENT .sp For example, one can use sRGB device, which has the following parameters: .INDENT 0.0 .INDENT 3.5 .sp .EX TIFFDisplay display_sRGB = { { /* XYZ \-> 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 */ }; .EE .UNINDENT .UNINDENT .sp \fIrefWhite\fP is a color temperature of the reference white. The \fBTIFFTAG_WHITEPOINT\fP contains the chromaticity of the white point of the image from where the reference white can be calculated using following formulae: .INDENT 0.0 .INDENT 3.5 .sp .EX refWhite_Y = 100.0 refWhite_X = whitePoint_x / whitePoint_y * refWhite_Y refWhite_Z = (1.0 \- whitePoint_x \- whitePoint_y) / whitePoint_y * refWhite_X .EE .UNINDENT .UNINDENT .sp The conversion itself performed in two steps: at the first one we will convert \fICIE L*a*b* 1976\fP to \fICIE XYZ\fP using the \fI\%TIFFCIELabToXYZ()\fP routine, and at the second step we will convert \fICIE XYZ\fP to \fIRGB\fP using \fI\%TIFFXYZToRGB()\fP\&. Look at the code sample below: .INDENT 0.0 .INDENT 3.5 .sp .EX float *whitePoint; float refWhite[3]; /* Initialize structures */ img\->cielab = (TIFFCIELabToRGB *) _TIFFmalloc(sizeof(TIFFCIELabToRGB)); if (!cielab) { TIFFError(\(dqCIE L*a*b*\->RGB\(dq, \(dqNo space for CIE L*a*b*\->RGB conversion state.\(dq); exit(0); } TIFFGetFieldDefaulted(tif, TIFFTAG_WHITEPOINT, &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, &display_sRGB, refWhite) < 0) { TIFFError(\(dqCIE L*a*b*\->RGB\(dq, \(dqFailed to initialize CIE L*a*b*\->RGB conversion state.\(dq); _TIFFfree(cielab); exit(0); } /* Now we can start to convert */ uint32_t r, g, b; uint32_t L; int32_t a, b; float X, Y, Z; for each pixel in image { TIFFCIELabToXYZ(cielab, L, a, b, &X, &Y, &Z); TIFFXYZToRGB(cielab, X, Y, Z, &r, &g, &b); } /* Don\(aqt forget to free the state structure */ _TIFFfree(cielab); .EE .UNINDENT .UNINDENT .SH SEE ALSO .sp \fI\%TIFFRGBAImage\fP (3tiff), \fI\%libtiff\fP (3tiff) .SH AUTHOR LibTIFF contributors .SH COPYRIGHT 1988-2023, LibTIFF contributors .\" Generated by docutils manpage writer. .