37 # define TIFFCvtIEEEFloatToNative(tif, n, fp) 38 # define TIFFCvtIEEEDoubleToNative(tif, n, dp) 45 static void MissingRequired(
TIFF*,
const char*);
62 static void ChopUpSingleUncompressedStrip(
TIFF*);
72 static const char module[] =
"TIFFReadDirectory";
83 int diroutoforderwarning = 0;
104 "%s: Failed to allocate space for IFD list",
120 "%s: Seek error accessing TIFF directory",
126 "%s: Can not read TIFF directory count",
134 "to read TIFF directory");
139 "%.100s: Can not read TIFF directory",
152 "%s: Can not read TIFF directory count",
162 "to read TIFF directory");
167 "%s: Can not read TIFF directory",
220 for (dp = dir, n = dircount; n > 0; n--, dp++) {
226 if (!TIFFFetchNormalTag(tif, dp))
235 for (dp = dir, n = dircount; n > 0; n--, dp++) {
246 if (!diroutoforderwarning) {
248 "%s: invalid TIFF directory; tags are not sorted in ascending order",
250 diroutoforderwarning = 1;
254 while (fix < tif->tif_nfields &&
262 "%s: unknown field with tag %d (0x%x) encountered",
274 while (fix < tif->tif_nfields &&
291 && fix < tif->tif_nfields) {
298 "%s: wrong data type %d for \"%s\"; tag ignored",
312 if (!CheckDirCount(tif, dp, expected))
332 if (!TIFFFetchPerSampleLongs(tif, dp, &v) ||
336 if (!TIFFFetchPerSampleShorts(tif, dp, &iv)
357 if (!TIFFFetchNormalTag(tif, dp))
368 MissingRequired(tif,
"ImageLength");
386 "%s: cannot handle zero number of %s",
395 isTiled(tif) ?
"TileOffsets" :
"StripOffsets");
402 for (dp = dir, n = dircount; n > 0; n--, dp++) {
434 if (!TIFFFetchPerSampleLongs(tif, dp, &v) ||
438 if (!TIFFFetchPerSampleShorts(tif, dp, &iv) ||
447 if (!TIFFFetchPerSampleAnys(tif, dp, &dv) ||
454 if (!TIFFFetchStripThing(tif, dp,
460 if (!TIFFFetchStripThing(tif, dp,
476 if (!CheckDirCount(tif, dp, 3 * v))
483 "to read \"TransferFunction\" tag");
485 if (TIFFFetchData(tif, dp, cp)) {
505 (
void) TIFFFetchShortPair(tif, dp);
508 (
void) TIFFFetchRefBlackWhite(tif, dp);
527 (
void) TIFFFetchNormalTag(tif, dp);
536 MissingRequired(tif,
"Colormap");
552 MissingRequired(tif,
"StripByteCounts");
556 "%s: TIFF directory is missing required " 557 "\"%s\" field, calculating from imagelength",
560 if (EstimateStripByteCounts(tif, dir, dircount) < 0)
572 #define BYTECOUNTLOOKSBAD \ 573 ( (td->td_stripbytecount[0] == 0 && td->td_stripoffset[0] != 0) || \ 574 (td->td_compression == COMPRESSION_NONE && \ 575 td->td_stripbytecount[0] > TIFFGetFileSize(tif) - td->td_stripoffset[0]) || \ 576 (tif->tif_mode == O_RDONLY && \ 577 td->td_compression == COMPRESSION_NONE && \ 578 td->td_stripbytecount[0] < TIFFScanlineSize(tif) * td->td_imagelength) ) 590 "%s: Bogus \"%s\" field, ignoring and calculating from imagelength",
593 if(EstimateStripByteCounts(tif, dir, dircount) < 0)
605 "%s: Wrong \"%s\" field, ignoring and calculating from imagelength",
608 if (EstimateStripByteCounts(tif, dir, dircount) < 0)
630 for (strip = 1; strip < td->
td_nstrips; strip++) {
652 ChopUpSingleUncompressedStrip(tif);
699 static const char module[] =
"TIFFReadCustomDirectory";
712 if (!
SeekOK(tif, diroff)) {
714 "%s: Seek error accessing TIFF directory",
720 "%s: Can not read TIFF directory count",
728 "to read TIFF custom directory");
733 "%.100s: Can not read TIFF directory",
742 "%s: Can not read TIFF directory count",
752 "to read TIFF custom directory");
757 "%s: Can not read TIFF directory",
769 for (dp = dir, i = dircount; i > 0; i--, dp++) {
778 while (fix < tif->tif_nfields &&
786 "%s: unknown field with tag %d (0x%x) encountered",
797 while (fix < tif->tif_nfields &&
814 && fix < tif->tif_nfields) {
821 "%s: wrong data type %d for \"%s\"; tag ignored",
835 if (!CheckDirCount(tif, dp, expected))
839 (
void) TIFFFetchNormalTag(tif, dp);
859 size_t exifFieldInfoCount;
869 static const char module[] =
"EstimateStripByteCounts";
879 "for \"StripByteCounts\" array");
889 for (dp = dir, n = dircount; n > 0; n--, dp++)
894 "%s: Cannot determine size of unknown tag type %d",
902 space = filesize - space;
932 MissingRequired(
TIFF* tif,
const char* tagname)
934 static const char module[] =
"MissingRequired";
937 "%s: TIFF directory is missing required \"%s\" field",
952 "incorrect count for field \"%s\" (%lu, expecting %lu); tag ignored",
958 "incorrect count for field \"%s\" (%lu, expecting %lu); tag trimmed",
1015 "Error fetching data for field \"%s\"",
1033 return (TIFFFetchData(tif, dir, cp));
1044 "%s: Rational with zero denominator (num = %lu)",
1049 *rv = ((float)
num / (
float)denom);
1051 *rv = ((float)(int32)
num / (float)(int32)denom);
1067 return (!TIFFFetchData(tif, dir, (
char *)l) ||
1068 !cvtRational(tif, dir, l[0], l[1], &v) ? 1.0
f : v);
1129 return (TIFFFetchData(tif, dir, (
char*)
v) != 0);
1152 return (TIFFFetchData(tif, dir, (
char *)
v) != 0);
1167 return TIFFFetchByteArray(tif, dir, v)
1174 return TIFFFetchShortArray(tif, dir, v)
1192 return (TIFFFetchData(tif, dir, (
char*) v) != 0);
1206 "to fetch array of rationals");
1208 if (TIFFFetchData(tif, dir, (
char *)l)) {
1211 ok = cvtRational(tif, dir,
1212 l[2*i+0], l[2*i+1], &v[i]);
1233 }
else if (TIFFFetchData(tif, dir, (
char*) v)) {
1246 if (TIFFFetchData(tif, dir, (
char*) v)) {
1272 if (!TIFFFetchByteArray(tif, dir, (
uint8*) v))
1286 if (!TIFFFetchShortArray(tif, dir, (
uint16*)
v))
1300 if (!TIFFFetchLongArray(tif, dir, (
uint32*)
v))
1307 int32* vp = (int32*) v;
1314 if (!TIFFFetchRationalArray(tif, dir, (
float*)
v))
1316 {
float* vp = (
float*) v;
1322 if (!TIFFFetchFloatArray(tif, dir, (
float*)
v))
1324 {
float* vp = (
float*) v;
1330 return (TIFFFetchDoubleArray(tif, dir, (
double*)
v));
1336 "cannot read TIFF_ANY type %d for field \"%s\"",
1350 static const char mesg[] =
"to fetch tag value";
1362 ok = cp && TIFFFetchByteArray(tif, dp, (
uint8*) cp);
1368 ok = cp && TIFFFetchShortArray(tif, dp, (
uint16*) cp);
1374 ok = cp && TIFFFetchLongArray(tif, dp, (
uint32*) cp);
1380 ok = cp && TIFFFetchRationalArray(tif, dp, (
float*) cp);
1385 ok = cp && TIFFFetchFloatArray(tif, dp, (
float*) cp);
1390 ok = cp && TIFFFetchDoubleArray(tif, dp, (
double*) cp);
1400 if( (ok = (cp && TIFFFetchString(tif, dp, cp))) != 0 )
1411 }
else if (CheckDirCount(tif, dp, 1)) {
1454 TIFFFetchFloat(tif, dp)
1455 : TIFFFetchRational(tif, dp));
1463 ok = (TIFFFetchDoubleArray(tif, dp, &v) &&
1473 if( (ok = (TIFFFetchString(tif, dp, c) != 0)) != 0 ) {
1486 #define NITEMS(x) (sizeof (x) / sizeof (x[0])) 1498 if (CheckDirCount(tif, dir, (
uint32) samples)) {
1504 "to fetch per-sample values");
1505 if (v && TIFFFetchShortArray(tif, dir, v)) {
1508 if( samples < check_count )
1511 for (i = 1; i < check_count; i++)
1514 "Cannot handle different per-sample values for field \"%s\"",
1539 if (CheckDirCount(tif, dir, (
uint32) samples)) {
1545 "to fetch per-sample values");
1546 if (v && TIFFFetchLongArray(tif, dir, v)) {
1550 if( samples < check_count )
1552 for (i = 1; i < check_count; i++)
1555 "Cannot handle different per-sample values for field \"%s\"",
1579 if (CheckDirCount(tif, dir, (
uint32) samples)) {
1585 "to fetch per-sample values");
1586 if (v && TIFFFetchAnyArray(tif, dir, v)) {
1589 if( samples < check_count )
1592 for (i = 1; i < check_count; i++)
1595 "Cannot handle different per-sample values for field \"%s\"",
1620 CheckDirCount(tif, dir, (
uint32) nstrips);
1627 nstrips,
sizeof (
uint32),
"for strip array")) ==
NULL)
1640 if( (status = TIFFFetchShortArray(tif, dir, dp)) != 0 ) {
1650 }
else if( nstrips != (
int) dir->
tdir_count ) {
1658 status = TIFFFetchLongArray(tif, dir, dp);
1670 status = TIFFFetchLongArray(tif, dir, lp);
1681 static const char mesg[] =
"for \"ReferenceBlackWhite\" array";
1686 return (TIFFFetchNormalTag(tif, dir));
1692 if( (ok = (cp && TIFFFetchLongArray(tif, dir, (
uint32*) cp))) != 0) {
1693 float*
fp = (
float*)
1695 if( (ok = (fp !=
NULL)) != 0 ) {
1698 fp[i] = (
float)((
uint32*) cp)[
i];
1716 ChopUpSingleUncompressedStrip(
TIFF* tif)
1722 tstrip_t strip, nstrips, rowsperstrip;
1731 stripbytes = rowbytes;
1733 }
else if (rowbytes > 0 ) {
1735 stripbytes = rowbytes * rowsperstrip;
1750 "for chopped \"StripByteCounts\" array");
1752 "for chopped \"StripOffsets\" array");
1753 if (newcounts ==
NULL || newoffsets ==
NULL) {
1758 if (newcounts !=
NULL)
1760 if (newoffsets !=
NULL)
1768 for (strip = 0; strip < nstrips; strip++) {
1769 if (stripbytes > (
tsize_t) bytecount)
1770 stripbytes = bytecount;
1771 newcounts[strip] = stripbytes;
1772 newoffsets[strip] =
offset;
1773 offset += stripbytes;
1774 bytecount -= stripbytes;
#define TIFFTAG_SUBFILETYPE
int TIFFReadDirectory(TIFF *tif)
const TIFFFieldInfo * _TIFFGetExifFieldInfo(size_t *)
#define TIFFTAG_BITSPERSAMPLE
void TIFFWarningExt(thandle_t fd, const char *module, const char *fmt,...)
#define TIFFTAG_ROWSPERSTRIP
#define FIELD_STRIPOFFSETS
#define TIFFTAG_STRIPBYTECOUNTS
#define TIFFCvtIEEEFloatToNative(tif, n, fp)
#define TIFFTAG_EXTRASAMPLES
#define STRIP_SIZE_DEFAULT
#define FIELD_IMAGEDIMENSIONS
#define TIFFhowmany(x, y)
#define TIFFTAG_IMAGEWIDTH
#define TIFFTAG_MINSAMPLEVALUE
tsize_t TIFFScanlineSize(TIFF *tif)
#define TIFFTAG_STRIPOFFSETS
#define TIFFTAG_YCBCRSUBSAMPLING
void TIFFSwabArrayOfShort(uint16 *wp, register unsigned long n)
#define TIFFTAG_SMINSAMPLEVALUE
#define TIFFTAG_REFERENCEBLACKWHITE
#define TIFFTAG_PLANARCONFIG
typedef void(APIENTRY *GLDEBUGPROCARB)(GLenum source
#define TIFFTAG_TILEBYTECOUNTS
void _TIFFmemcpy(tdata_t d, const tdata_t s, tsize_t c)
#define FIELD_MAXSAMPLEVALUE
GLenum GLuint GLenum GLsizei const GLchar * buf
#define TIFFSetFieldBit(tif, field)
#define TIFFTAG_TILEWIDTH
#define FIELD_STRIPBYTECOUNTS
void TIFFMergeFieldInfo(TIFF *, const TIFFFieldInfo[], int)
#define TIFFTAG_TILELENGTH
unsigned char field_passcount
tsize_t TIFFVTileSize(TIFF *tif, uint32 nrows)
#define TIFFTAG_IMAGELENGTH
#define TIFFTAG_TILEOFFSETS
#define TIFFTAG_SAMPLESPERPIXEL
#define PHOTOMETRIC_PALETTE
int TIFFReadCustomDirectory(TIFF *tif, toff_t diroff, const TIFFFieldInfo info[], size_t n)
void TIFFFreeDirectory(TIFF *tif)
int td_stripbytecountsorted
int TIFFReadEXIFDirectory(TIFF *tif, toff_t diroff)
void TIFFSwabShort(uint16 *wp)
ttile_t TIFFNumberOfTiles(TIFF *tif)
#define TIFFTAG_HALFTONEHINTS
void * _TIFFrealloc(tdata_t p, tsize_t s)
void TIFFErrorExt(thandle_t fd, const char *module, const char *fmt,...)
void TIFFSwabArrayOfLong(register uint32 *lp, register unsigned long n)
#define TIFFFieldSet(tif, field)
#define TIFFTAG_PAGENUMBER
#define FIELD_COMPRESSION
#define FIELD_ROWSPERSTRIP
#define TIFFTAG_TRANSFERFUNCTION
TIFFFieldInfo ** tif_fieldinfo
#define TIFFTAG_COMPRESSION
#define PLANARCONFIG_SEPARATE
#define FILETYPE_REDUCEDIMAGE
TIFFVoidMethod tif_cleanup
#define TIFFExtractData(tif, type, v)
#define TIFFGetFileSize(tif)
void _TIFFmemset(tdata_t p, int v, tsize_t c)
tstrip_t TIFFNumberOfStrips(TIFF *tif)
#define TIFFTAG_SMAXSAMPLEVALUE
if(!abbox) return FT_THROW(Invalid_Argument)
uint16 td_samplesperpixel
int TIFFDataWidth(TIFFDataType type)
void TIFFSwabArrayOfDouble(double *dp, register unsigned long n)
#define OFILETYPE_REDUCEDIMAGE
const TIFFFieldInfo * _TIFFFieldWithTag(TIFF *tif, ttag_t tag)
GLubyte GLubyte GLubyte GLubyte w
#define TIFFTAG_TILEDEPTH
#define TIFFTAG_IMAGEDEPTH
#define BYTECOUNTLOOKSBAD
void TIFFSwabLong(uint32 *lp)
tsize_t TIFFTileSize(TIFF *tif)
#define FIELD_TILEDIMENSIONS
int TIFFSetField(TIFF *tif, ttag_t tag,...)
tstrip_t td_stripsperimage
int TIFFDefaultDirectory(TIFF *tif)
tsize_t TIFFStripSize(TIFF *tif)
GLuint GLuint GLsizei count
#define ReadOK(file, buffer, len)
tdata_t _TIFFCheckMalloc(TIFF *tif, size_t nmemb, size_t elem_size, const char *what)
void _TIFFfree(tdata_t p)
#define TIFFTAG_SAMPLEFORMAT
#define TIFFCvtIEEEDoubleToNative(tif, n, dp)
#define TIFFTAG_OSUBFILETYPE
#define TIFFTAG_MAXSAMPLEVALUE
#define PLANARCONFIG_CONTIG
TIFFFieldInfo * _TIFFCreateAnonFieldInfo(TIFF *tif, ttag_t tag, TIFFDataType dt)
void _TIFFSetupFieldInfo(TIFF *, const TIFFFieldInfo[], size_t)
uint32 * td_stripbytecount