Merge branch 'issue-80' into 'master'

tiffinfo: fix dump of Tiled images

Closes #80

See merge request libtiff/libtiff!144
This commit is contained in:
Olivier Paquet 2020-04-18 14:05:15 +00:00
commit 4a91774d5d

View File

@ -407,11 +407,11 @@ ShowRawWords(uint16* pp, uint32 n)
putchar('\n');
}
void
TIFFReadRawData(TIFF* tif, int bitrev)
static void
TIFFReadRawDataStriped(TIFF* tif, int bitrev)
{
tstrip_t nstrips = TIFFNumberOfStrips(tif);
const char* what = TIFFIsTiled(tif) ? "Tile" : "Strip";
const char* what = "Strip";
uint64* stripbc=NULL;
TIFFGetField(tif, TIFFTAG_STRIPBYTECOUNTS, &stripbc);
@ -455,6 +455,66 @@ TIFFReadRawData(TIFF* tif, int bitrev)
}
}
static void
TIFFReadRawDataTiled(TIFF* tif, int bitrev)
{
const char* what = "Tile";
uint32 ntiles = TIFFNumberOfTiles(tif);
uint64 *tilebc;
TIFFGetField(tif, TIFFTAG_TILEBYTECOUNTS, &tilebc);
if (tilebc != NULL && ntiles > 0) {
uint64 bufsize = 0;
tdata_t buf = NULL;
uint32 t;
for (t = 0; t < ntiles; t++) {
if (buf == NULL || tilebc[t] > bufsize) {
buf = _TIFFrealloc(buf, (tmsize_t)tilebc[t]);
bufsize = tilebc[t];
}
if (buf == NULL) {
fprintf(stderr,
"Cannot allocate buffer to read tile %lu\n",
(unsigned long) t);
break;
}
if (TIFFReadRawTile(tif, t, buf, (tmsize_t)tilebc[t]) < 0) {
fprintf(stderr, "Error reading tile %lu\n",
(unsigned long) t);
if (stoponerr)
break;
} else if (showdata) {
if (bitrev) {
TIFFReverseBits(buf, (tmsize_t)tilebc[t]);
printf("%s %lu: (bit reversed)\n ",
what, (unsigned long) t);
} else {
printf("%s %lu:\n ", what,
(unsigned long) t);
}
if (showwords) {
ShowRawWords((uint16*) buf, (uint32)(tilebc[t]>>1));
} else {
ShowRawBytes((unsigned char*) buf, (uint32) tilebc[t]);
}
}
}
if (buf != NULL)
_TIFFfree(buf);
}
}
void
TIFFReadRawData(TIFF* tif, int bitrev)
{
if (TIFFIsTiled(tif)) {
TIFFReadRawDataTiled(tif, bitrev);
} else {
TIFFReadRawDataStriped(tif, bitrev);
}
}
static void
tiffinfo(TIFF* tif, uint16 order, long flags, int is_image)
{