Alien-FreeImage
view release on metacpan or search on metacpan
src/Source/LibTIFF4/tif_dir.c view on Meta::CPAN
case TIFFTAG_TILELENGTH:
v32 = (uint32) va_arg(ap, uint32);
if (v32 % 16) {
if (tif->tif_mode != O_RDONLY)
goto badvalue32;
TIFFWarningExt(tif->tif_clientdata, tif->tif_name,
"Nonstandard tile length %d, convert file", v32);
}
td->td_tilelength = v32;
tif->tif_flags |= TIFF_ISTILED;
break;
case TIFFTAG_TILEDEPTH:
v32 = (uint32) va_arg(ap, uint32);
if (v32 == 0)
goto badvalue32;
td->td_tiledepth = v32;
break;
case TIFFTAG_DATATYPE:
v = (uint16) va_arg(ap, uint16_vap);
switch (v) {
case DATATYPE_VOID: v = SAMPLEFORMAT_VOID; break;
case DATATYPE_INT: v = SAMPLEFORMAT_INT; break;
case DATATYPE_UINT: v = SAMPLEFORMAT_UINT; break;
case DATATYPE_IEEEFP: v = SAMPLEFORMAT_IEEEFP;break;
default: goto badvalue;
}
td->td_sampleformat = (uint16) v;
break;
case TIFFTAG_SAMPLEFORMAT:
v = (uint16) va_arg(ap, uint16_vap);
if (v < SAMPLEFORMAT_UINT || SAMPLEFORMAT_COMPLEXIEEEFP < v)
goto badvalue;
td->td_sampleformat = (uint16) v;
/* Try to fix up the SWAB function for complex data. */
if( td->td_sampleformat == SAMPLEFORMAT_COMPLEXINT
&& td->td_bitspersample == 32
&& tif->tif_postdecode == _TIFFSwab32BitData )
tif->tif_postdecode = _TIFFSwab16BitData;
else if( (td->td_sampleformat == SAMPLEFORMAT_COMPLEXINT
|| td->td_sampleformat == SAMPLEFORMAT_COMPLEXIEEEFP)
&& td->td_bitspersample == 64
&& tif->tif_postdecode == _TIFFSwab64BitData )
tif->tif_postdecode = _TIFFSwab32BitData;
break;
case TIFFTAG_IMAGEDEPTH:
td->td_imagedepth = (uint32) va_arg(ap, uint32);
break;
case TIFFTAG_SUBIFD:
if ((tif->tif_flags & TIFF_INSUBIFD) == 0) {
td->td_nsubifd = (uint16) va_arg(ap, uint16_vap);
_TIFFsetLong8Array(&td->td_subifd, (uint64*) va_arg(ap, uint64*),
(long) td->td_nsubifd);
} else {
TIFFErrorExt(tif->tif_clientdata, module,
"%s: Sorry, cannot nest SubIFDs",
tif->tif_name);
status = 0;
}
break;
case TIFFTAG_YCBCRPOSITIONING:
td->td_ycbcrpositioning = (uint16) va_arg(ap, uint16_vap);
break;
case TIFFTAG_YCBCRSUBSAMPLING:
td->td_ycbcrsubsampling[0] = (uint16) va_arg(ap, uint16_vap);
td->td_ycbcrsubsampling[1] = (uint16) va_arg(ap, uint16_vap);
break;
case TIFFTAG_TRANSFERFUNCTION:
v = (td->td_samplesperpixel - td->td_extrasamples) > 1 ? 3 : 1;
for (i = 0; i < v; i++)
_TIFFsetShortArray(&td->td_transferfunction[i],
va_arg(ap, uint16*), 1L<<td->td_bitspersample);
break;
case TIFFTAG_REFERENCEBLACKWHITE:
/* XXX should check for null range */
_TIFFsetFloatArray(&td->td_refblackwhite, va_arg(ap, float*), 6);
break;
case TIFFTAG_INKNAMES:
v = (uint16) va_arg(ap, uint16_vap);
s = va_arg(ap, char*);
v = checkInkNamesString(tif, v, s);
status = v > 0;
if( v > 0 ) {
_TIFFsetNString(&td->td_inknames, s, v);
td->td_inknameslen = v;
}
break;
case TIFFTAG_PERSAMPLE:
v = (uint16) va_arg(ap, uint16_vap);
if( v == PERSAMPLE_MULTI )
tif->tif_flags |= TIFF_PERSAMPLE;
else
tif->tif_flags &= ~TIFF_PERSAMPLE;
break;
default: {
TIFFTagValue *tv;
int tv_size, iCustom;
/*
* This can happen if multiple images are open with different
* codecs which have private tags. The global tag information
* table may then have tags that are valid for one file but not
* the other. If the client tries to set a tag that is not valid
* for the image's codec then we'll arrive here. This
* happens, for example, when tiffcp is used to convert between
* compression schemes and codec-specific tags are blindly copied.
*/
if(fip->field_bit != FIELD_CUSTOM) {
TIFFErrorExt(tif->tif_clientdata, module,
"%s: Invalid %stag \"%s\" (not supported by codec)",
tif->tif_name, isPseudoTag(tag) ? "pseudo-" : "",
fip->field_name);
status = 0;
break;
}
/*
* Find the existing entry for this custom value.
*/
tv = NULL;
for (iCustom = 0; iCustom < td->td_customValueCount; iCustom++) {
if (td->td_customValues[iCustom].info->field_tag == tag) {
tv = td->td_customValues + iCustom;
if (tv->value != NULL) {
src/Source/LibTIFF4/tif_dir.c view on Meta::CPAN
break;
case TIFFTAG_COLORMAP:
*va_arg(ap, uint16**) = td->td_colormap[0];
*va_arg(ap, uint16**) = td->td_colormap[1];
*va_arg(ap, uint16**) = td->td_colormap[2];
break;
case TIFFTAG_STRIPOFFSETS:
case TIFFTAG_TILEOFFSETS:
_TIFFFillStriles( tif );
*va_arg(ap, uint64**) = td->td_stripoffset;
break;
case TIFFTAG_STRIPBYTECOUNTS:
case TIFFTAG_TILEBYTECOUNTS:
_TIFFFillStriles( tif );
*va_arg(ap, uint64**) = td->td_stripbytecount;
break;
case TIFFTAG_MATTEING:
*va_arg(ap, uint16*) =
(td->td_extrasamples == 1 &&
td->td_sampleinfo[0] == EXTRASAMPLE_ASSOCALPHA);
break;
case TIFFTAG_EXTRASAMPLES:
*va_arg(ap, uint16*) = td->td_extrasamples;
*va_arg(ap, uint16**) = td->td_sampleinfo;
break;
case TIFFTAG_TILEWIDTH:
*va_arg(ap, uint32*) = td->td_tilewidth;
break;
case TIFFTAG_TILELENGTH:
*va_arg(ap, uint32*) = td->td_tilelength;
break;
case TIFFTAG_TILEDEPTH:
*va_arg(ap, uint32*) = td->td_tiledepth;
break;
case TIFFTAG_DATATYPE:
switch (td->td_sampleformat) {
case SAMPLEFORMAT_UINT:
*va_arg(ap, uint16*) = DATATYPE_UINT;
break;
case SAMPLEFORMAT_INT:
*va_arg(ap, uint16*) = DATATYPE_INT;
break;
case SAMPLEFORMAT_IEEEFP:
*va_arg(ap, uint16*) = DATATYPE_IEEEFP;
break;
case SAMPLEFORMAT_VOID:
*va_arg(ap, uint16*) = DATATYPE_VOID;
break;
}
break;
case TIFFTAG_SAMPLEFORMAT:
*va_arg(ap, uint16*) = td->td_sampleformat;
break;
case TIFFTAG_IMAGEDEPTH:
*va_arg(ap, uint32*) = td->td_imagedepth;
break;
case TIFFTAG_SUBIFD:
*va_arg(ap, uint16*) = td->td_nsubifd;
*va_arg(ap, uint64**) = td->td_subifd;
break;
case TIFFTAG_YCBCRPOSITIONING:
*va_arg(ap, uint16*) = td->td_ycbcrpositioning;
break;
case TIFFTAG_YCBCRSUBSAMPLING:
*va_arg(ap, uint16*) = td->td_ycbcrsubsampling[0];
*va_arg(ap, uint16*) = td->td_ycbcrsubsampling[1];
break;
case TIFFTAG_TRANSFERFUNCTION:
*va_arg(ap, uint16**) = td->td_transferfunction[0];
if (td->td_samplesperpixel - td->td_extrasamples > 1) {
*va_arg(ap, uint16**) = td->td_transferfunction[1];
*va_arg(ap, uint16**) = td->td_transferfunction[2];
}
break;
case TIFFTAG_REFERENCEBLACKWHITE:
*va_arg(ap, float**) = td->td_refblackwhite;
break;
case TIFFTAG_INKNAMES:
*va_arg(ap, char**) = td->td_inknames;
break;
default:
{
int i;
/*
* This can happen if multiple images are open
* with different codecs which have private
* tags. The global tag information table may
* then have tags that are valid for one file
* but not the other. If the client tries to
* get a tag that is not valid for the image's
* codec then we'll arrive here.
*/
if( fip->field_bit != FIELD_CUSTOM )
{
TIFFErrorExt(tif->tif_clientdata, "_TIFFVGetField",
"%s: Invalid %stag \"%s\" "
"(not supported by codec)",
tif->tif_name,
isPseudoTag(tag) ? "pseudo-" : "",
fip->field_name);
ret_val = 0;
break;
}
/*
* Do we have a custom value?
*/
ret_val = 0;
for (i = 0; i < td->td_customValueCount; i++) {
TIFFTagValue *tv = td->td_customValues + i;
if (tv->info->field_tag != tag)
continue;
if (fip->field_passcount) {
if (fip->field_readcount == TIFF_VARIABLE2)
*va_arg(ap, uint32*) = (uint32)tv->count;
else /* Assume TIFF_VARIABLE */
*va_arg(ap, uint16*) = (uint16)tv->count;
*va_arg(ap, void **) = tv->value;
ret_val = 1;
} else if (fip->field_tag == TIFFTAG_DOTRANGE
&& strcmp(fip->field_name,"DotRange") == 0) {
src/Source/LibTIFF4/tif_dir.c view on Meta::CPAN
* Return the value of a field in the
* internal directory structure.
*/
int
TIFFGetField(TIFF* tif, uint32 tag, ...)
{
int status;
va_list ap;
va_start(ap, tag);
status = TIFFVGetField(tif, tag, ap);
va_end(ap);
return (status);
}
/*
* Like TIFFGetField, but taking a varargs
* parameter list. This routine is useful
* for building higher-level interfaces on
* top of the library.
*/
int
TIFFVGetField(TIFF* tif, uint32 tag, va_list ap)
{
const TIFFField* fip = TIFFFindField(tif, tag, TIFF_ANY);
return (fip && (isPseudoTag(tag) || TIFFFieldSet(tif, fip->field_bit)) ?
(*tif->tif_tagmethods.vgetfield)(tif, tag, ap) : 0);
}
#define CleanupField(member) { \
if (td->member) { \
_TIFFfree(td->member); \
td->member = 0; \
} \
}
/*
* Release storage associated with a directory.
*/
void
TIFFFreeDirectory(TIFF* tif)
{
TIFFDirectory *td = &tif->tif_dir;
int i;
_TIFFmemset(td->td_fieldsset, 0, FIELD_SETLONGS);
CleanupField(td_sminsamplevalue);
CleanupField(td_smaxsamplevalue);
CleanupField(td_colormap[0]);
CleanupField(td_colormap[1]);
CleanupField(td_colormap[2]);
CleanupField(td_sampleinfo);
CleanupField(td_subifd);
CleanupField(td_inknames);
CleanupField(td_refblackwhite);
CleanupField(td_transferfunction[0]);
CleanupField(td_transferfunction[1]);
CleanupField(td_transferfunction[2]);
CleanupField(td_stripoffset);
CleanupField(td_stripbytecount);
TIFFClrFieldBit(tif, FIELD_YCBCRSUBSAMPLING);
TIFFClrFieldBit(tif, FIELD_YCBCRPOSITIONING);
/* Cleanup custom tag values */
for( i = 0; i < td->td_customValueCount; i++ ) {
if (td->td_customValues[i].value)
_TIFFfree(td->td_customValues[i].value);
}
td->td_customValueCount = 0;
CleanupField(td_customValues);
#if defined(DEFER_STRILE_LOAD)
_TIFFmemset( &(td->td_stripoffset_entry), 0, sizeof(TIFFDirEntry));
_TIFFmemset( &(td->td_stripbytecount_entry), 0, sizeof(TIFFDirEntry));
#endif
}
#undef CleanupField
/*
* Client Tag extension support (from Niles Ritter).
*/
static TIFFExtendProc _TIFFextender = (TIFFExtendProc) NULL;
TIFFExtendProc
TIFFSetTagExtender(TIFFExtendProc extender)
{
TIFFExtendProc prev = _TIFFextender;
_TIFFextender = extender;
return (prev);
}
/*
* Setup for a new directory. Should we automatically call
* TIFFWriteDirectory() if the current one is dirty?
*
* The newly created directory will not exist on the file till
* TIFFWriteDirectory(), TIFFFlush() or TIFFClose() is called.
*/
int
TIFFCreateDirectory(TIFF* tif)
{
TIFFDefaultDirectory(tif);
tif->tif_diroff = 0;
tif->tif_nextdiroff = 0;
tif->tif_curoff = 0;
tif->tif_row = (uint32) -1;
tif->tif_curstrip = (uint32) -1;
return 0;
}
int
TIFFCreateCustomDirectory(TIFF* tif, const TIFFFieldArray* infoarray)
{
TIFFDefaultDirectory(tif);
/*
* Reset the field definitions to match the application provided list.
* Hopefully TIFFDefaultDirectory() won't have done anything irreversable
* based on it's assumption this is an image directory.
*/
_TIFFSetupFields(tif, infoarray);
tif->tif_diroff = 0;
tif->tif_nextdiroff = 0;
tif->tif_curoff = 0;
tif->tif_row = (uint32) -1;
tif->tif_curstrip = (uint32) -1;
return 0;
}
int
TIFFCreateEXIFDirectory(TIFF* tif)
{
const TIFFFieldArray* exifFieldArray;
exifFieldArray = _TIFFGetExifFields();
return TIFFCreateCustomDirectory(tif, exifFieldArray);
}
/*
* Setup a default directory structure.
*/
int
TIFFDefaultDirectory(TIFF* tif)
{
register TIFFDirectory* td = &tif->tif_dir;
const TIFFFieldArray* tiffFieldArray;
tiffFieldArray = _TIFFGetFields();
_TIFFSetupFields(tif, tiffFieldArray);
_TIFFmemset(td, 0, sizeof (*td));
td->td_fillorder = FILLORDER_MSB2LSB;
td->td_bitspersample = 1;
td->td_threshholding = THRESHHOLD_BILEVEL;
td->td_orientation = ORIENTATION_TOPLEFT;
td->td_samplesperpixel = 1;
td->td_rowsperstrip = (uint32) -1;
td->td_tilewidth = 0;
td->td_tilelength = 0;
td->td_tiledepth = 1;
td->td_stripbytecountsorted = 1; /* Our own arrays always sorted. */
td->td_resolutionunit = RESUNIT_INCH;
td->td_sampleformat = SAMPLEFORMAT_UINT;
td->td_imagedepth = 1;
td->td_ycbcrsubsampling[0] = 2;
td->td_ycbcrsubsampling[1] = 2;
td->td_ycbcrpositioning = YCBCRPOSITION_CENTERED;
tif->tif_postdecode = _TIFFNoPostDecode;
tif->tif_foundfield = NULL;
tif->tif_tagmethods.vsetfield = _TIFFVSetField;
tif->tif_tagmethods.vgetfield = _TIFFVGetField;
tif->tif_tagmethods.printdir = NULL;
/*
* Give client code a chance to install their own
* tag extensions & methods, prior to compression overloads,
* but do some prior cleanup first. (http://trac.osgeo.org/gdal/ticket/5054)
*/
if (tif->tif_nfieldscompat > 0) {
uint32 i;
for (i = 0; i < tif->tif_nfieldscompat; i++) {
if (tif->tif_fieldscompat[i].allocated_size)
_TIFFfree(tif->tif_fieldscompat[i].fields);
}
_TIFFfree(tif->tif_fieldscompat);
tif->tif_nfieldscompat = 0;
tif->tif_fieldscompat = NULL;
}
if (_TIFFextender)
(*_TIFFextender)(tif);
(void) TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
/*
* NB: The directory is marked dirty as a result of setting
* up the default compression scheme. However, this really
* isn't correct -- we want TIFF_DIRTYDIRECT to be set only
* if the user does something. We could just do the setup
* by hand, but it seems better to use the normal mechanism
* (i.e. TIFFSetField).
*/
tif->tif_flags &= ~TIFF_DIRTYDIRECT;
/*
* As per http://bugzilla.remotesensing.org/show_bug.cgi?id=19
* we clear the ISTILED flag when setting up a new directory.
* Should we also be clearing stuff like INSUBIFD?
*/
tif->tif_flags &= ~TIFF_ISTILED;
return (1);
}
static int
TIFFAdvanceDirectory(TIFF* tif, uint64* nextdir, uint64* off)
{
static const char module[] = "TIFFAdvanceDirectory";
if (isMapped(tif))
{
uint64 poff=*nextdir;
if (!(tif->tif_flags&TIFF_BIGTIFF))
{
tmsize_t poffa,poffb,poffc,poffd;
uint16 dircount;
uint32 nextdir32;
poffa=(tmsize_t)poff;
poffb=poffa+sizeof(uint16);
if (((uint64)poffa!=poff)||(poffb<poffa)||(poffb<(tmsize_t)sizeof(uint16))||(poffb>tif->tif_size))
{
( run in 0.421 second using v1.01-cache-2.11-cpan-f6376fbd888 )