Alien-FreeImage
view release on metacpan or search on metacpan
src/Source/LibTIFF4/tif_getimage.c view on Meta::CPAN
if (img->PALmap == NULL) {
TIFFErrorExt(img->tif->tif_clientdata, TIFFFileName(img->tif), "No space for Palette mapping table");
return (0);
}
p = (uint32*)(img->PALmap + 256);
for (i = 0; i < 256; i++) {
TIFFRGBValue c;
img->PALmap[i] = p;
#define CMAP(x) c = (TIFFRGBValue) x; *p++ = PACK(r[c]&0xff, g[c]&0xff, b[c]&0xff);
switch (bitspersample) {
case 1:
CMAP(i>>7);
CMAP((i>>6)&1);
CMAP((i>>5)&1);
CMAP((i>>4)&1);
CMAP((i>>3)&1);
CMAP((i>>2)&1);
CMAP((i>>1)&1);
CMAP(i&1);
break;
case 2:
CMAP(i>>6);
CMAP((i>>4)&3);
CMAP((i>>2)&3);
CMAP(i&3);
break;
case 4:
CMAP(i>>4);
CMAP(i&0xf);
break;
case 8:
CMAP(i);
break;
}
#undef CMAP
}
return (1);
}
/*
* 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
TIFFWarningExt(img->tif->tif_clientdata, 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);
}
/*
* Select the appropriate conversion routine for packed data.
*/
static int
PickContigCase(TIFFRGBAImage* img)
{
img->get = TIFFIsTiled(img->tif) ? gtTileContig : gtStripContig;
img->put.contig = NULL;
switch (img->photometric) {
case PHOTOMETRIC_RGB:
switch (img->bitspersample) {
case 8:
if (img->alpha == EXTRASAMPLE_ASSOCALPHA)
img->put.contig = putRGBAAcontig8bittile;
else if (img->alpha == EXTRASAMPLE_UNASSALPHA)
{
if (BuildMapUaToAa(img))
img->put.contig = putRGBUAcontig8bittile;
}
else
img->put.contig = putRGBcontig8bittile;
break;
case 16:
if (img->alpha == EXTRASAMPLE_ASSOCALPHA)
{
if (BuildMapBitdepth16To8(img))
img->put.contig = putRGBAAcontig16bittile;
}
else if (img->alpha == EXTRASAMPLE_UNASSALPHA)
{
if (BuildMapBitdepth16To8(img) &&
BuildMapUaToAa(img))
img->put.contig = putRGBUAcontig16bittile;
}
else
{
if (BuildMapBitdepth16To8(img))
img->put.contig = putRGBcontig16bittile;
}
break;
}
break;
case PHOTOMETRIC_SEPARATED:
( run in 0.449 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )