/* * Construct any mapping table used * by the associated put routine. */ static int buildMap(TIFFRGBAImage* img) { switch (img->photometric) { case PHOTOMETRIC_RGB: case PHOTOMETRIC_YCBCR: case PHOTOMETRIC_SEPARATED: if (img->bitspersample == 8) break; /* fall thru... */ case PHOTOMETRIC_MINISBLACK: case PHOTOMETRIC_MINISWHITE: if (!setupMap(img)) return (0); break; case PHOTOMETRIC_PALETTE: /* * Convert 16-bit colormap to 8-bit (unless it looks * like an old-style 8-bit colormap). */ if (checkcmap(img) == 16) cvtcmap(img); else TIFFWarning(TIFFFileName(img->tif), "Assuming 8-bit colormap"); /* * Use mapping table and colormap to construct * unpacking tables for samples < 8 bits. */ if (img->bitspersample <= 8 && !makecmap(img)) return (0); break; } return (1); }
boolean TIFFRasterImpl::gt(u_long w, u_long h) { u_short minsamplevalue; u_short maxsamplevalue; u_short planarconfig; RGBvalue* Map = nil; if (!TIFFGetField(tif_, TIFFTAG_MINSAMPLEVALUE, &minsamplevalue)) { minsamplevalue = 0; } if (!TIFFGetField(tif_, TIFFTAG_MAXSAMPLEVALUE, &maxsamplevalue)) { maxsamplevalue = (1<<bitspersample_)-1; } switch (photometric_) { case PHOTOMETRIC_RGB: if (minsamplevalue == 0 && maxsamplevalue == 255) { break; } /* fall thru... */ case PHOTOMETRIC_MINISBLACK: case PHOTOMETRIC_MINISWHITE: { register int x, range; range = maxsamplevalue - minsamplevalue; Map = new RGBvalue[range + 1]; if (Map == nil) { TIFFError( TIFFFileName(tif_), "No space for photometric conversion table" ); return false; } if (photometric_ == PHOTOMETRIC_MINISWHITE) { for (x = 0; x <= range; x++) { Map[x] = ((range - x) * 255) / range; } } else { for (x = 0; x <= range; x++) { Map[x] = (x * 255) / range; } } if (photometric_ != PHOTOMETRIC_RGB && bitspersample_ != 8) { /* * Use photometric mapping table to construct * unpacking tables for samples < 8 bits. */ if (!makebwmap(Map)) { return false; } delete Map; /* no longer need Map, free it */ Map = nil; } break; } case PHOTOMETRIC_PALETTE: if (!TIFFGetField( tif_, TIFFTAG_COLORMAP, &redcmap_, &greencmap_, &bluecmap_) ) { TIFFError(TIFFFileName(tif_), "Missing required \"Colormap\" tag"); return (false); } /* * Convert 16-bit colormap to 8-bit (unless it looks * like an old-style 8-bit colormap). */ if ( checkcmap( 1 << bitspersample_, redcmap_, greencmap_, bluecmap_ ) == 16 ) { int i; for (i = (1 << bitspersample_) - 1; i > 0; i--) { #define CVT(x) (((x) * 255) / ((1L<<16)-1)) redcmap_[i] = (u_short) CVT(redcmap_[i]); greencmap_[i] = (u_short) CVT(greencmap_[i]); bluecmap_[i] = (u_short) CVT(bluecmap_[i]); } } if (bitspersample_ <= 8) { /* * Use mapping table and colormap to construct * unpacking tables for samples < 8 bits. */ if (!makecmap(redcmap_, greencmap_, bluecmap_)) { return false; } } break; } TIFFGetField(tif_, TIFFTAG_PLANARCONFIG, &planarconfig); boolean e; if (planarconfig == PLANARCONFIG_SEPARATE && samplesperpixel_ > 1) { e = TIFFIsTiled(tif_) ? gtTileSeparate(Map, h, w) : gtStripSeparate(Map, h, w); } else { e = TIFFIsTiled(tif_) ? gtTileContig(Map, h, w) : gtStripContig(Map, h, w); } delete Map; return e; }