summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'tiff/tools/tiffinfo.c')
-rw-r--r--tiff/tools/tiffinfo.c161
1 files changed, 79 insertions, 82 deletions
diff --git a/tiff/tools/tiffinfo.c b/tiff/tools/tiffinfo.c
index 2271c9d1..6921a0c5 100644
--- a/tiff/tools/tiffinfo.c
+++ b/tiff/tools/tiffinfo.c
@@ -23,6 +23,7 @@
*/
#include "tif_config.h"
+#include "libport.h"
#include <stdio.h>
#include <stdlib.h>
@@ -36,10 +37,6 @@
# include <unistd.h>
#endif
-#ifdef NEED_LIBPORT
-# include "libport.h"
-#endif
-
#include "tiffiop.h"
#ifndef EXIT_SUCCESS
@@ -58,7 +55,7 @@ static int readdata = 0; /* read data in file */
static int stoponerr = 1; /* stop on first read error */
static void usage(int);
-static void tiffinfo(TIFF*, uint16, long, int);
+static void tiffinfo(TIFF*, uint16_t, long, int);
static void
PrivateErrorHandler(const char* module, const char* fmt, va_list ap)
@@ -72,14 +69,14 @@ int
main(int argc, char* argv[])
{
int dirnum = -1, multiplefiles, c;
- uint16 order = 0;
+ uint16_t order = 0;
TIFF* tif;
#if !HAVE_DECL_OPTARG
extern int optind;
extern char* optarg;
#endif
long flags = 0;
- uint64 diroff = 0;
+ uint64_t diroff = 0;
int chopstrips = 0; /* disable strip chopping */
while ((c = getopt(argc, argv, "f:o:cdDSjilmrsvwz0123456789h")) != -1)
@@ -131,10 +128,12 @@ main(int argc, char* argv[])
break;
case 'h':
usage(EXIT_SUCCESS);
- /*NOTREACHED*/
+ /*NOTREACHED*/
+ break;
case '?':
usage(EXIT_FAILURE);
/*NOTREACHED*/
+ break;
}
if (optind >= argc)
usage(EXIT_FAILURE);
@@ -172,43 +171,41 @@ main(int argc, char* argv[])
return (status);
}
-static const char* stuff[] = {
-"usage: tiffinfo [options] input...",
-"where options are:",
-" -D read data",
-" -i ignore read errors",
-" -c display data for grey/color response curve or colormap",
-" -d display raw/decoded image data",
-" -f lsb2msb force lsb-to-msb FillOrder for input",
-" -f msb2lsb force msb-to-lsb FillOrder for input",
-" -j show JPEG tables",
-" -o offset set initial directory offset",
-" -r read/display raw image data instead of decoded data",
-" -s display strip offsets and byte counts",
-" -w display raw data in words rather than bytes",
-" -z enable strip chopping",
-" -# set initial directory (first directory is # 0)",
-NULL
-};
+static const char usage_info[] =
+"Display information about TIFF files\n\n"
+"usage: tiffinfo [options] input...\n"
+"where options are:\n"
+" -D read data\n"
+" -i ignore read errors\n"
+" -c display data for grey/color response curve or colormap\n"
+" -d display raw/decoded image data\n"
+" -f lsb2msb force lsb-to-msb FillOrder for input\n"
+" -f msb2lsb force msb-to-lsb FillOrder for input\n"
+" -j show JPEG tables\n"
+" -o offset set initial directory offset\n"
+" -r read/display raw image data instead of decoded data\n"
+" -s display strip offsets and byte counts\n"
+" -w display raw data in words rather than bytes\n"
+" -z enable strip chopping\n"
+" -# set initial directory (first directory is # 0)\n"
+;
static void
usage(int code)
{
- int i;
FILE * out = (code == EXIT_SUCCESS) ? stdout : stderr;
fprintf(out, "%s\n\n", TIFFGetVersion());
- for (i = 0; stuff[i] != NULL; i++)
- fprintf(out, "%s\n", stuff[i]);
+ fprintf(out, "%s", usage_info);
exit(code);
}
static void
-ShowStrip(tstrip_t strip, unsigned char* pp, uint32 nrow, tsize_t scanline)
+ShowStrip(tstrip_t strip, unsigned char* pp, uint32_t nrow, tsize_t scanline)
{
register tsize_t cc;
- printf("Strip %lu:\n", (unsigned long) strip);
+ printf("Strip %"PRIu32":\n", strip);
while (nrow-- > 0) {
for (cc = 0; cc < scanline; cc++) {
printf(" %02x", *pp++);
@@ -227,13 +224,13 @@ TIFFReadContigStripData(TIFF* tif)
buf = (unsigned char *)_TIFFmalloc(TIFFStripSize(tif));
if (buf) {
- uint32 row, h=0;
- uint32 rowsperstrip = (uint32)-1;
+ uint32_t row, h=0;
+ uint32_t rowsperstrip = (uint32_t)-1;
TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &h);
TIFFGetField(tif, TIFFTAG_ROWSPERSTRIP, &rowsperstrip);
for (row = 0; row < h; row += rowsperstrip) {
- uint32 nrow = (row+rowsperstrip > h ?
+ uint32_t nrow = (row + rowsperstrip > h ?
h-row : rowsperstrip);
tstrip_t strip = TIFFComputeStrip(tif, row, 0);
if (TIFFReadEncodedStrip(tif, strip, buf, nrow*scanline) < 0) {
@@ -254,8 +251,8 @@ TIFFReadSeparateStripData(TIFF* tif)
buf = (unsigned char *)_TIFFmalloc(TIFFStripSize(tif));
if (buf) {
- uint32 row, h=0;
- uint32 rowsperstrip = (uint32)-1;
+ uint32_t row, h=0;
+ uint32_t rowsperstrip = (uint32_t)-1;
tsample_t s, samplesperpixel=0;
TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &h);
@@ -263,7 +260,7 @@ TIFFReadSeparateStripData(TIFF* tif)
TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &samplesperpixel);
for (row = 0; row < h; row += rowsperstrip) {
for (s = 0; s < samplesperpixel; s++) {
- uint32 nrow = (row+rowsperstrip > h ?
+ uint32_t nrow = (row + rowsperstrip > h ?
h-row : rowsperstrip);
tstrip_t strip = TIFFComputeStrip(tif, row, s);
if (TIFFReadEncodedStrip(tif, strip, buf, nrow*scanline) < 0) {
@@ -278,17 +275,17 @@ TIFFReadSeparateStripData(TIFF* tif)
}
static void
-ShowTile(uint32 row, uint32 col, tsample_t sample,
- unsigned char* pp, uint32 nrow, tsize_t rowsize)
+ShowTile(uint32_t row, uint32_t col, tsample_t sample,
+ unsigned char* pp, uint32_t nrow, tsize_t rowsize)
{
- uint32 cc;
+ uint32_t cc;
- printf("Tile (%lu,%lu", (unsigned long) row, (unsigned long) col);
+ printf("Tile (%" PRIu32 ",%" PRIu32 "", row, col);
if (sample != (tsample_t) -1)
- printf(",%u", sample);
+ printf(",%" PRIu16, sample);
printf("):\n");
while (nrow-- > 0) {
- for (cc = 0; cc < (uint32) rowsize; cc++) {
+ for (cc = 0; cc < (uint32_t) rowsize; cc++) {
printf(" %02x", *pp++);
if (((cc+1) % 24) == 0)
putchar('\n');
@@ -306,8 +303,8 @@ TIFFReadContigTileData(TIFF* tif)
buf = (unsigned char *)_TIFFmalloc(tilesize);
if (buf) {
- uint32 tw=0, th=0, w=0, h=0;
- uint32 row, col;
+ uint32_t tw=0, th=0, w=0, h=0;
+ uint32_t row, col;
TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &w);
TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &h);
@@ -341,8 +338,8 @@ TIFFReadSeparateTileData(TIFF* tif)
buf = (unsigned char *)_TIFFmalloc(tilesize);
if (buf) {
- uint32 tw=0, th=0, w=0, h=0;
- uint32 row, col;
+ uint32_t tw=0, th=0, w=0, h=0;
+ uint32_t row, col;
tsample_t s, samplesperpixel=0;
TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &w);
@@ -374,7 +371,7 @@ TIFFReadSeparateTileData(TIFF* tif)
void
TIFFReadData(TIFF* tif)
{
- uint16 config = PLANARCONFIG_CONTIG;
+ uint16_t config = PLANARCONFIG_CONTIG;
TIFFGetField(tif, TIFFTAG_PLANARCONFIG, &config);
if (TIFFIsTiled(tif)) {
@@ -391,9 +388,9 @@ TIFFReadData(TIFF* tif)
}
static void
-ShowRawBytes(unsigned char* pp, uint32 n)
+ShowRawBytes(unsigned char* pp, uint32_t n)
{
- uint32 i;
+ uint32_t i;
for (i = 0; i < n; i++) {
printf(" %02x", *pp++);
@@ -404,12 +401,12 @@ ShowRawBytes(unsigned char* pp, uint32 n)
}
static void
-ShowRawWords(uint16* pp, uint32 n)
+ShowRawWords(uint16_t* pp, uint32_t n)
{
- uint32 i;
+ uint32_t i;
for (i = 0; i < n; i++) {
- printf(" %04x", *pp++);
+ printf(" %04" PRIx16, *pp++);
if (((i+1) % 15) == 0)
printf("\n ");
}
@@ -421,42 +418,42 @@ TIFFReadRawDataStriped(TIFF* tif, int bitrev)
{
tstrip_t nstrips = TIFFNumberOfStrips(tif);
const char* what = "Strip";
- uint64* stripbc=NULL;
+ uint64_t* stripbc=NULL;
TIFFGetField(tif, TIFFTAG_STRIPBYTECOUNTS, &stripbc);
if (stripbc != NULL && nstrips > 0) {
- uint32 bufsize = (uint32) stripbc[0];
+ uint32_t bufsize = (uint32_t) stripbc[0];
tdata_t buf = _TIFFmalloc(bufsize);
tstrip_t s;
for (s = 0; s < nstrips; s++) {
if (stripbc[s] > bufsize) {
buf = _TIFFrealloc(buf, (tmsize_t)stripbc[s]);
- bufsize = (uint32) stripbc[s];
+ bufsize = (uint32_t) stripbc[s];
}
if (buf == NULL) {
fprintf(stderr,
- "Cannot allocate buffer to read strip %lu\n",
- (unsigned long) s);
+ "Cannot allocate buffer to read strip %"PRIu32"\n",
+ s);
break;
}
if (TIFFReadRawStrip(tif, s, buf, (tmsize_t) stripbc[s]) < 0) {
- fprintf(stderr, "Error reading strip %lu\n",
- (unsigned long) s);
+ fprintf(stderr, "Error reading strip %"PRIu32"\n",
+ s);
if (stoponerr)
break;
} else if (showdata) {
if (bitrev) {
TIFFReverseBits(buf, (tmsize_t)stripbc[s]);
- printf("%s %lu: (bit reversed)\n ",
- what, (unsigned long) s);
+ printf("%s %"PRIu32": (bit reversed)\n ",
+ what, s);
} else
- printf("%s %lu:\n ", what,
- (unsigned long) s);
+ printf("%s %"PRIu32":\n ", what,
+ s);
if (showwords)
- ShowRawWords((uint16*) buf, (uint32) stripbc[s]>>1);
+ ShowRawWords((uint16_t*) buf, (uint32_t) stripbc[s] >> 1);
else
- ShowRawBytes((unsigned char*) buf, (uint32) stripbc[s]);
+ ShowRawBytes((unsigned char*) buf, (uint32_t) stripbc[s]);
}
}
if (buf != NULL)
@@ -468,14 +465,14 @@ static void
TIFFReadRawDataTiled(TIFF* tif, int bitrev)
{
const char* what = "Tile";
- uint32 ntiles = TIFFNumberOfTiles(tif);
- uint64 *tilebc;
+ uint32_t ntiles = TIFFNumberOfTiles(tif);
+ uint64_t *tilebc;
TIFFGetField(tif, TIFFTAG_TILEBYTECOUNTS, &tilebc);
if (tilebc != NULL && ntiles > 0) {
- uint64 bufsize = 0;
+ uint64_t bufsize = 0;
tdata_t buf = NULL;
- uint32 t;
+ uint32_t t;
for (t = 0; t < ntiles; t++) {
if (buf == NULL || tilebc[t] > bufsize) {
@@ -484,28 +481,28 @@ TIFFReadRawDataTiled(TIFF* tif, int bitrev)
}
if (buf == NULL) {
fprintf(stderr,
- "Cannot allocate buffer to read tile %lu\n",
- (unsigned long) t);
+ "Cannot allocate buffer to read tile %"PRIu32"\n",
+ t);
break;
}
if (TIFFReadRawTile(tif, t, buf, (tmsize_t)tilebc[t]) < 0) {
- fprintf(stderr, "Error reading tile %lu\n",
- (unsigned long) t);
+ fprintf(stderr, "Error reading tile %"PRIu32"\n",
+ 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);
+ printf("%s %"PRIu32": (bit reversed)\n ",
+ what, t);
} else {
- printf("%s %lu:\n ", what,
- (unsigned long) t);
+ printf("%s %"PRIu32":\n ", what,
+ t);
}
if (showwords) {
- ShowRawWords((uint16*) buf, (uint32)(tilebc[t]>>1));
+ ShowRawWords((uint16_t*) buf, (uint32_t)(tilebc[t] >> 1));
} else {
- ShowRawBytes((unsigned char*) buf, (uint32) tilebc[t]);
+ ShowRawBytes((unsigned char*) buf, (uint32_t) tilebc[t]);
}
}
}
@@ -525,14 +522,14 @@ TIFFReadRawData(TIFF* tif, int bitrev)
}
static void
-tiffinfo(TIFF* tif, uint16 order, long flags, int is_image)
+tiffinfo(TIFF* tif, uint16_t order, long flags, int is_image)
{
TIFFPrintDirectory(tif, stdout, flags);
if (!readdata || !is_image)
return;
if (rawdata) {
if (order) {
- uint16 o;
+ uint16_t o;
TIFFGetFieldDefaulted(tif,
TIFFTAG_FILLORDER, &o);
TIFFReadRawData(tif, o != order);