Alien-FreeImage
view release on metacpan or search on metacpan
src/Source/LibTIFF4/tif_getimage.c view on Meta::CPAN
switch (colorchannels) {
case 1:
if (isCCITTCompression(tif))
img->photometric = PHOTOMETRIC_MINISWHITE;
else
img->photometric = PHOTOMETRIC_MINISBLACK;
break;
case 3:
img->photometric = PHOTOMETRIC_RGB;
break;
default:
sprintf(emsg, "Missing needed %s tag", photoTag);
goto fail_return;
}
}
switch (img->photometric) {
case PHOTOMETRIC_PALETTE:
if (!TIFFGetField(tif, TIFFTAG_COLORMAP,
&red_orig, &green_orig, &blue_orig)) {
sprintf(emsg, "Missing required \"Colormap\" tag");
goto fail_return;
}
/* copy the colormaps so we can modify them */
n_color = (1L << img->bitspersample);
img->redcmap = (uint16 *) _TIFFmalloc(sizeof(uint16)*n_color);
img->greencmap = (uint16 *) _TIFFmalloc(sizeof(uint16)*n_color);
img->bluecmap = (uint16 *) _TIFFmalloc(sizeof(uint16)*n_color);
if( !img->redcmap || !img->greencmap || !img->bluecmap ) {
sprintf(emsg, "Out of memory for colormap copy");
goto fail_return;
}
_TIFFmemcpy( img->redcmap, red_orig, n_color * 2 );
_TIFFmemcpy( img->greencmap, green_orig, n_color * 2 );
_TIFFmemcpy( img->bluecmap, blue_orig, n_color * 2 );
/* fall thru... */
case PHOTOMETRIC_MINISWHITE:
case PHOTOMETRIC_MINISBLACK:
if (planarconfig == PLANARCONFIG_CONTIG
&& img->samplesperpixel != 1
&& img->bitspersample < 8 ) {
sprintf(emsg,
"Sorry, can not handle contiguous data with %s=%d, "
"and %s=%d and Bits/Sample=%d",
photoTag, img->photometric,
"Samples/pixel", img->samplesperpixel,
img->bitspersample);
goto fail_return;
}
break;
case PHOTOMETRIC_YCBCR:
/* It would probably be nice to have a reality check here. */
if (planarconfig == PLANARCONFIG_CONTIG)
/* can rely on libjpeg to convert to RGB */
/* XXX should restore current state on exit */
switch (compress) {
case COMPRESSION_JPEG:
/*
* TODO: when complete tests verify complete desubsampling
* and YCbCr handling, remove use of TIFFTAG_JPEGCOLORMODE in
* favor of tif_getimage.c native handling
*/
TIFFSetField(tif, TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RGB);
img->photometric = PHOTOMETRIC_RGB;
break;
default:
/* do nothing */;
break;
}
/*
* TODO: if at all meaningful and useful, make more complete
* support check here, or better still, refactor to let supporting
* code decide whether there is support and what meaningfull
* error to return
*/
break;
case PHOTOMETRIC_RGB:
if (colorchannels < 3) {
sprintf(emsg, "Sorry, can not handle RGB image with %s=%d",
"Color channels", colorchannels);
goto fail_return;
}
break;
case PHOTOMETRIC_SEPARATED:
{
uint16 inkset;
TIFFGetFieldDefaulted(tif, TIFFTAG_INKSET, &inkset);
if (inkset != INKSET_CMYK) {
sprintf(emsg, "Sorry, can not handle separated image with %s=%d",
"InkSet", inkset);
goto fail_return;
}
if (img->samplesperpixel < 4) {
sprintf(emsg, "Sorry, can not handle separated image with %s=%d",
"Samples/pixel", img->samplesperpixel);
goto fail_return;
}
}
break;
case PHOTOMETRIC_LOGL:
if (compress != COMPRESSION_SGILOG) {
sprintf(emsg, "Sorry, LogL data must have %s=%d",
"Compression", COMPRESSION_SGILOG);
goto fail_return;
}
TIFFSetField(tif, TIFFTAG_SGILOGDATAFMT, SGILOGDATAFMT_8BIT);
img->photometric = PHOTOMETRIC_MINISBLACK; /* little white lie */
img->bitspersample = 8;
break;
case PHOTOMETRIC_LOGLUV:
if (compress != COMPRESSION_SGILOG && compress != COMPRESSION_SGILOG24) {
sprintf(emsg, "Sorry, LogLuv data must have %s=%d or %d",
"Compression", COMPRESSION_SGILOG, COMPRESSION_SGILOG24);
goto fail_return;
}
if (planarconfig != PLANARCONFIG_CONTIG) {
sprintf(emsg, "Sorry, can not handle LogLuv images with %s=%d",
"Planarconfiguration", planarconfig);
return (0);
src/Source/LibTIFF4/tif_getimage.c view on Meta::CPAN
img->ycbcr = NULL;
img->cielab = NULL;
img->UaToAa = NULL;
img->Bitdepth16To8 = NULL;
TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &img->width);
TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &img->height);
TIFFGetFieldDefaulted(tif, TIFFTAG_ORIENTATION, &img->orientation);
img->isContig =
!(planarconfig == PLANARCONFIG_SEPARATE && img->samplesperpixel > 1);
if (img->isContig) {
if (!PickContigCase(img)) {
sprintf(emsg, "Sorry, can not handle image");
goto fail_return;
}
} else {
if (!PickSeparateCase(img)) {
sprintf(emsg, "Sorry, can not handle image");
goto fail_return;
}
}
return 1;
fail_return:
_TIFFfree( img->redcmap );
_TIFFfree( img->greencmap );
_TIFFfree( img->bluecmap );
img->redcmap = img->greencmap = img->bluecmap = NULL;
return 0;
}
int
TIFFRGBAImageGet(TIFFRGBAImage* img, uint32* raster, uint32 w, uint32 h)
{
if (img->get == NULL) {
TIFFErrorExt(img->tif->tif_clientdata, TIFFFileName(img->tif), "No \"get\" routine setup");
return (0);
}
if (img->put.any == NULL) {
TIFFErrorExt(img->tif->tif_clientdata, TIFFFileName(img->tif),
"No \"put\" routine setupl; probably can not handle image format");
return (0);
}
return (*img->get)(img, raster, w, h);
}
/*
* Read the specified image into an ABGR-format rastertaking in account
* specified orientation.
*/
int
TIFFReadRGBAImageOriented(TIFF* tif,
uint32 rwidth, uint32 rheight, uint32* raster,
int orientation, int stop)
{
char emsg[1024] = "";
TIFFRGBAImage img;
int ok;
if (TIFFRGBAImageOK(tif, emsg) && TIFFRGBAImageBegin(&img, tif, stop, emsg)) {
img.req_orientation = orientation;
/* XXX verify rwidth and rheight against width and height */
ok = TIFFRGBAImageGet(&img, raster+(rheight-img.height)*rwidth,
rwidth, img.height);
TIFFRGBAImageEnd(&img);
} else {
TIFFErrorExt(tif->tif_clientdata, TIFFFileName(tif), "%s", emsg);
ok = 0;
}
return (ok);
}
/*
* Read the specified image into an ABGR-format raster. Use bottom left
* origin for raster by default.
*/
int
TIFFReadRGBAImage(TIFF* tif,
uint32 rwidth, uint32 rheight, uint32* raster, int stop)
{
return TIFFReadRGBAImageOriented(tif, rwidth, rheight, raster,
ORIENTATION_BOTLEFT, stop);
}
static int
setorientation(TIFFRGBAImage* img)
{
switch (img->orientation) {
case ORIENTATION_TOPLEFT:
case ORIENTATION_LEFTTOP:
if (img->req_orientation == ORIENTATION_TOPRIGHT ||
img->req_orientation == ORIENTATION_RIGHTTOP)
return FLIP_HORIZONTALLY;
else if (img->req_orientation == ORIENTATION_BOTRIGHT ||
img->req_orientation == ORIENTATION_RIGHTBOT)
return FLIP_HORIZONTALLY | FLIP_VERTICALLY;
else if (img->req_orientation == ORIENTATION_BOTLEFT ||
img->req_orientation == ORIENTATION_LEFTBOT)
return FLIP_VERTICALLY;
else
return 0;
case ORIENTATION_TOPRIGHT:
case ORIENTATION_RIGHTTOP:
if (img->req_orientation == ORIENTATION_TOPLEFT ||
img->req_orientation == ORIENTATION_LEFTTOP)
return FLIP_HORIZONTALLY;
else if (img->req_orientation == ORIENTATION_BOTRIGHT ||
img->req_orientation == ORIENTATION_RIGHTBOT)
return FLIP_VERTICALLY;
else if (img->req_orientation == ORIENTATION_BOTLEFT ||
img->req_orientation == ORIENTATION_LEFTBOT)
return FLIP_HORIZONTALLY | FLIP_VERTICALLY;
else
return 0;
case ORIENTATION_BOTRIGHT:
case ORIENTATION_RIGHTBOT:
if (img->req_orientation == ORIENTATION_TOPLEFT ||
img->req_orientation == ORIENTATION_LEFTTOP)
return FLIP_HORIZONTALLY | FLIP_VERTICALLY;
else if (img->req_orientation == ORIENTATION_TOPRIGHT ||
img->req_orientation == ORIENTATION_RIGHTTOP)
return FLIP_VERTICALLY;
( run in 0.431 second using v1.01-cache-2.11-cpan-524268b4103 )