some indentation restoration, no content change

This commit is contained in:
Joris Van Damme 2006-03-26 16:39:30 +00:00
parent 84281a8949
commit 0993cc0252

View File

@ -1,4 +1,4 @@
/* $Id: tif_getimage.c,v 1.50 2006-03-25 03:09:24 joris Exp $ */ /* $Id: tif_getimage.c,v 1.51 2006-03-26 16:39:30 joris Exp $ */
/* /*
* Copyright (c) 1991-1997 Sam Leffler * Copyright (c) 1991-1997 Sam Leffler
@ -221,221 +221,224 @@ isCCITTCompression(TIFF* tif)
int int
TIFFRGBAImageBegin(TIFFRGBAImage* img, TIFF* tif, int stop, char emsg[1024]) TIFFRGBAImageBegin(TIFFRGBAImage* img, TIFF* tif, int stop, char emsg[1024])
{ {
uint16* sampleinfo; uint16* sampleinfo;
uint16 extrasamples; uint16 extrasamples;
uint16 planarconfig; uint16 planarconfig;
uint16 compress; uint16 compress;
int colorchannels; int colorchannels;
uint16 *red_orig, *green_orig, *blue_orig; uint16 *red_orig, *green_orig, *blue_orig;
int n_color; int n_color;
/* Initialize to normal values */ /* Initialize to normal values */
img->row_offset = 0; img->row_offset = 0;
img->col_offset = 0; img->col_offset = 0;
img->redcmap = NULL; img->redcmap = NULL;
img->greencmap = NULL; img->greencmap = NULL;
img->bluecmap = NULL; img->bluecmap = NULL;
img->req_orientation = ORIENTATION_BOTLEFT; /* It is the default */ img->req_orientation = ORIENTATION_BOTLEFT; /* It is the default */
img->tif = tif; img->tif = tif;
img->stoponerr = stop; img->stoponerr = stop;
TIFFGetFieldDefaulted(tif, TIFFTAG_BITSPERSAMPLE, &img->bitspersample); TIFFGetFieldDefaulted(tif, TIFFTAG_BITSPERSAMPLE, &img->bitspersample);
switch (img->bitspersample) { switch (img->bitspersample) {
case 1: case 2: case 4: case 1:
case 8: case 16: case 2:
break; case 4:
default: case 8:
sprintf(emsg, "Sorry, can not handle images with %d-bit samples", case 16:
img->bitspersample); break;
return (0); default:
} sprintf(emsg, "Sorry, can not handle images with %d-bit samples",
img->alpha = 0; img->bitspersample);
TIFFGetFieldDefaulted(tif, TIFFTAG_SAMPLESPERPIXEL, &img->samplesperpixel); return (0);
TIFFGetFieldDefaulted(tif, TIFFTAG_EXTRASAMPLES, }
&extrasamples, &sampleinfo); img->alpha = 0;
if (extrasamples >= 1) TIFFGetFieldDefaulted(tif, TIFFTAG_SAMPLESPERPIXEL, &img->samplesperpixel);
{ TIFFGetFieldDefaulted(tif, TIFFTAG_EXTRASAMPLES,
switch (sampleinfo[0]) { &extrasamples, &sampleinfo);
case EXTRASAMPLE_UNSPECIFIED: /* Workaround for some images without */ if (extrasamples >= 1)
if (img->samplesperpixel > 3) /* correct info about alpha channel */ {
img->alpha = EXTRASAMPLE_ASSOCALPHA; switch (sampleinfo[0]) {
break; case EXTRASAMPLE_UNSPECIFIED: /* Workaround for some images without */
case EXTRASAMPLE_ASSOCALPHA: /* data is pre-multiplied */ if (img->samplesperpixel > 3) /* correct info about alpha channel */
case EXTRASAMPLE_UNASSALPHA: /* data is not pre-multiplied */ img->alpha = EXTRASAMPLE_ASSOCALPHA;
img->alpha = sampleinfo[0]; break;
break; case EXTRASAMPLE_ASSOCALPHA: /* data is pre-multiplied */
case EXTRASAMPLE_UNASSALPHA: /* data is not pre-multiplied */
img->alpha = sampleinfo[0];
break;
}
} }
}
#ifdef DEFAULT_EXTRASAMPLE_AS_ALPHA #ifdef DEFAULT_EXTRASAMPLE_AS_ALPHA
if( !TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &img->photometric)) if( !TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &img->photometric))
img->photometric = PHOTOMETRIC_MINISWHITE; img->photometric = PHOTOMETRIC_MINISWHITE;
if( extrasamples == 0 if( extrasamples == 0
&& img->samplesperpixel == 4 && img->samplesperpixel == 4
&& img->photometric == PHOTOMETRIC_RGB ) && img->photometric == PHOTOMETRIC_RGB )
{ {
img->alpha = EXTRASAMPLE_ASSOCALPHA; img->alpha = EXTRASAMPLE_ASSOCALPHA;
extrasamples = 1; extrasamples = 1;
} }
#endif #endif
colorchannels = img->samplesperpixel - extrasamples; colorchannels = img->samplesperpixel - extrasamples;
TIFFGetFieldDefaulted(tif, TIFFTAG_COMPRESSION, &compress); TIFFGetFieldDefaulted(tif, TIFFTAG_COMPRESSION, &compress);
TIFFGetFieldDefaulted(tif, TIFFTAG_PLANARCONFIG, &planarconfig); TIFFGetFieldDefaulted(tif, TIFFTAG_PLANARCONFIG, &planarconfig);
if (!TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &img->photometric)) { if (!TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &img->photometric)) {
switch (colorchannels) { switch (colorchannels) {
case 1: case 1:
if (isCCITTCompression(tif)) if (isCCITTCompression(tif))
img->photometric = PHOTOMETRIC_MINISWHITE; img->photometric = PHOTOMETRIC_MINISWHITE;
else else
img->photometric = PHOTOMETRIC_MINISBLACK; img->photometric = PHOTOMETRIC_MINISBLACK;
break; break;
case 3: case 3:
img->photometric = PHOTOMETRIC_RGB; img->photometric = PHOTOMETRIC_RGB;
break; break;
default: default:
sprintf(emsg, "Missing needed %s tag", photoTag); sprintf(emsg, "Missing needed %s tag", photoTag);
return (0); return (0);
} }
}
switch (img->photometric) {
case PHOTOMETRIC_PALETTE:
if (!TIFFGetField(tif, TIFFTAG_COLORMAP,
&red_orig, &green_orig, &blue_orig)) {
sprintf(emsg, "Missing required \"Colormap\" tag");
return (0);
} }
switch (img->photometric) {
case PHOTOMETRIC_PALETTE:
if (!TIFFGetField(tif, TIFFTAG_COLORMAP,
&red_orig, &green_orig, &blue_orig)) {
sprintf(emsg, "Missing required \"Colormap\" tag");
return (0);
}
/* copy the colormaps so we can modify them */ /* copy the colormaps so we can modify them */
n_color = (1L << img->bitspersample); n_color = (1L << img->bitspersample);
img->redcmap = (uint16 *) _TIFFmalloc(sizeof(uint16)*n_color); img->redcmap = (uint16 *) _TIFFmalloc(sizeof(uint16)*n_color);
img->greencmap = (uint16 *) _TIFFmalloc(sizeof(uint16)*n_color); img->greencmap = (uint16 *) _TIFFmalloc(sizeof(uint16)*n_color);
img->bluecmap = (uint16 *) _TIFFmalloc(sizeof(uint16)*n_color); img->bluecmap = (uint16 *) _TIFFmalloc(sizeof(uint16)*n_color);
if( !img->redcmap || !img->greencmap || !img->bluecmap ) { if( !img->redcmap || !img->greencmap || !img->bluecmap ) {
sprintf(emsg, "Out of memory for colormap copy"); sprintf(emsg, "Out of memory for colormap copy");
return (0); return (0);
} }
_TIFFmemcpy( img->redcmap, red_orig, n_color * 2 ); _TIFFmemcpy( img->redcmap, red_orig, n_color * 2 );
_TIFFmemcpy( img->greencmap, green_orig, n_color * 2 ); _TIFFmemcpy( img->greencmap, green_orig, n_color * 2 );
_TIFFmemcpy( img->bluecmap, blue_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);
return (0);
}
break;
case PHOTOMETRIC_YCBCR:
if (planarconfig != PLANARCONFIG_CONTIG) {
sprintf(emsg, "Sorry, can not handle YCbCr images with %s=%d",
"Planarconfiguration", planarconfig);
return (0);
}
/* 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_OJPEG:
case COMPRESSION_JPEG:
TIFFSetField(tif, TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RGB);
img->photometric = PHOTOMETRIC_RGB;
break;
default: /* fall thru... */
/* do nothing */; case PHOTOMETRIC_MINISWHITE:
break; case PHOTOMETRIC_MINISBLACK:
} if (planarconfig == PLANARCONFIG_CONTIG
break; && img->samplesperpixel != 1
case PHOTOMETRIC_RGB: && img->bitspersample < 8 ) {
if (colorchannels < 3) { sprintf(emsg,
sprintf(emsg, "Sorry, can not handle RGB image with %s=%d", "Sorry, can not handle contiguous data with %s=%d, "
"Color channels", colorchannels); "and %s=%d and Bits/Sample=%d",
return (0); photoTag, img->photometric,
"Samples/pixel", img->samplesperpixel,
img->bitspersample);
return (0);
}
break;
case PHOTOMETRIC_YCBCR:
if (planarconfig != PLANARCONFIG_CONTIG) {
sprintf(emsg, "Sorry, can not handle YCbCr images with %s=%d",
"Planarconfiguration", planarconfig);
return (0);
}
/* 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_OJPEG:
case COMPRESSION_JPEG:
TIFFSetField(tif, TIFFTAG_JPEGCOLORMODE, JPEGCOLORMODE_RGB);
img->photometric = PHOTOMETRIC_RGB;
break;
default:
/* do nothing */;
break;
}
break;
case PHOTOMETRIC_RGB:
if (colorchannels < 3) {
sprintf(emsg, "Sorry, can not handle RGB image with %s=%d",
"Color channels", colorchannels);
return (0);
}
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);
return (0);
}
if (img->samplesperpixel < 4) {
sprintf(emsg, "Sorry, can not handle separated image with %s=%d",
"Samples/pixel", img->samplesperpixel);
return (0);
}
}
break;
case PHOTOMETRIC_LOGL:
if (compress != COMPRESSION_SGILOG) {
sprintf(emsg, "Sorry, LogL data must have %s=%d",
"Compression", COMPRESSION_SGILOG);
return (0);
}
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);
return (0);
}
if (planarconfig != PLANARCONFIG_CONTIG) {
sprintf(emsg, "Sorry, can not handle LogLuv images with %s=%d",
"Planarconfiguration", planarconfig);
return (0);
}
TIFFSetField(tif, TIFFTAG_SGILOGDATAFMT, SGILOGDATAFMT_8BIT);
img->photometric = PHOTOMETRIC_RGB; /* little white lie */
img->bitspersample = 8;
break;
case PHOTOMETRIC_CIELAB:
break;
default:
sprintf(emsg, "Sorry, can not handle image with %s=%d",
photoTag, img->photometric);
return (0);
} }
break; img->Map = NULL;
case PHOTOMETRIC_SEPARATED: { img->BWmap = NULL;
uint16 inkset; img->PALmap = NULL;
TIFFGetFieldDefaulted(tif, TIFFTAG_INKSET, &inkset); img->ycbcr = NULL;
if (inkset != INKSET_CMYK) { img->cielab = NULL;
sprintf(emsg, "Sorry, can not handle separated image with %s=%d", TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &img->width);
"InkSet", inkset); TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &img->height);
return (0); TIFFGetFieldDefaulted(tif, TIFFTAG_ORIENTATION, &img->orientation);
img->isContig =
!(planarconfig == PLANARCONFIG_SEPARATE && colorchannels > 1);
if (img->isContig) {
img->get = TIFFIsTiled(tif) ? gtTileContig : gtStripContig;
if (!pickTileContigCase(img)) {
sprintf(emsg, "Sorry, can not handle image");
return 0;
}
} else {
img->get = TIFFIsTiled(tif) ? gtTileSeparate : gtStripSeparate;
if (!pickTileSeparateCase(img)) {
sprintf(emsg, "Sorry, can not handle image");
return 0;
}
} }
if (img->samplesperpixel < 4) { return 1;
sprintf(emsg, "Sorry, can not handle separated image with %s=%d",
"Samples/pixel", img->samplesperpixel);
return (0);
}
break;
}
case PHOTOMETRIC_LOGL:
if (compress != COMPRESSION_SGILOG) {
sprintf(emsg, "Sorry, LogL data must have %s=%d",
"Compression", COMPRESSION_SGILOG);
return (0);
}
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);
return (0);
}
if (planarconfig != PLANARCONFIG_CONTIG) {
sprintf(emsg, "Sorry, can not handle LogLuv images with %s=%d",
"Planarconfiguration", planarconfig);
return (0);
}
TIFFSetField(tif, TIFFTAG_SGILOGDATAFMT, SGILOGDATAFMT_8BIT);
img->photometric = PHOTOMETRIC_RGB; /* little white lie */
img->bitspersample = 8;
break;
case PHOTOMETRIC_CIELAB:
break;
default:
sprintf(emsg, "Sorry, can not handle image with %s=%d",
photoTag, img->photometric);
return (0);
}
img->Map = NULL;
img->BWmap = NULL;
img->PALmap = NULL;
img->ycbcr = NULL;
img->cielab = NULL;
TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &img->width);
TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &img->height);
TIFFGetFieldDefaulted(tif, TIFFTAG_ORIENTATION, &img->orientation);
img->isContig =
!(planarconfig == PLANARCONFIG_SEPARATE && colorchannels > 1);
if (img->isContig) {
img->get = TIFFIsTiled(tif) ? gtTileContig : gtStripContig;
if (!pickTileContigCase(img)) {
sprintf(emsg, "Sorry, can not handle image");
return 0;
}
} else {
img->get = TIFFIsTiled(tif) ? gtTileSeparate : gtStripSeparate;
if (!pickTileSeparateCase(img)) {
sprintf(emsg, "Sorry, can not handle image");
return 0;
}
}
return 1;
} }
int int