static int TIFFWriteTransferFunction(TIFF* tif, TIFFDirEntry* dir) { TIFFDirectory* td = &tif->tif_dir; tsize_t n = (1L<<td->td_bitspersample) * sizeof (uint16); uint16** tf = td->td_transferfunction; int ncols; /* * Check if the table can be written as a single column, * or if it must be written as 3 columns. Note that we * write a 3-column tag if there are 2 samples/pixel and * a single column of data won't suffice--hmm. */ switch (td->td_samplesperpixel - td->td_extrasamples) { default: if (_TIFFmemcmp(tf[0], tf[2], n)) { ncols = 3; break; } case 2: if (_TIFFmemcmp(tf[0], tf[1], n)) { ncols = 3; break; } case 1: case 0: ncols = 1; } return (TIFFWriteShortTable(tif, TIFFTAG_TRANSFERFUNCTION, dir, ncols, tf)); }
static tileContigRoutine initYCbCrConversion(TIFFRGBAImage* img) { uint16 hs, vs; if (img->ycbcr == NULL) { img->ycbcr = (TIFFYCbCrToRGB*) _TIFFmalloc( TIFFroundup(sizeof (TIFFYCbCrToRGB), sizeof (long)) + 4*256*sizeof (TIFFRGBValue) + 2*256*sizeof (int) + 2*256*sizeof (int32) ); if (img->ycbcr == NULL) { TIFFError(TIFFFileName(img->tif), "No space for YCbCr->RGB conversion state"); return (NULL); } TIFFYCbCrToRGBInit(img->ycbcr, img->tif); } else { float* coeffs; TIFFGetFieldDefaulted(img->tif, TIFFTAG_YCBCRCOEFFICIENTS, &coeffs); if (_TIFFmemcmp(coeffs, img->ycbcr->coeffs, 3*sizeof (float)) != 0) TIFFYCbCrToRGBInit(img->ycbcr, img->tif); } /* * The 6.0 spec says that subsampling must be * one of 1, 2, or 4, and that vertical subsampling * must always be <= horizontal subsampling; so * there are only a few possibilities and we just * enumerate the cases. */ TIFFGetFieldDefaulted(img->tif, TIFFTAG_YCBCRSUBSAMPLING, &hs, &vs); switch ((hs<<4)|vs) { case 0x44: return (putcontig8bitYCbCr44tile); case 0x42: return (putcontig8bitYCbCr42tile); case 0x41: return (putcontig8bitYCbCr41tile); case 0x22: return (putcontig8bitYCbCr22tile); case 0x21: return (putcontig8bitYCbCr21tile); case 0x11: return (putcontig8bitYCbCr11tile); } return (NULL); }