|
kusano |
7d535a |
/* $Id: tiffdump.c,v 1.26 2012-06-15 21:51:54 fwarmerdam Exp $ */
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/*
|
|
kusano |
7d535a |
* Copyright (c) 1988-1997 Sam Leffler
|
|
kusano |
7d535a |
* Copyright (c) 1991-1997 Silicon Graphics, Inc.
|
|
kusano |
7d535a |
*
|
|
kusano |
7d535a |
* Permission to use, copy, modify, distribute, and sell this software and
|
|
kusano |
7d535a |
* its documentation for any purpose is hereby granted without fee, provided
|
|
kusano |
7d535a |
* that (i) the above copyright notices and this permission notice appear in
|
|
kusano |
7d535a |
* all copies of the software and related documentation, and (ii) the names of
|
|
kusano |
7d535a |
* Sam Leffler and Silicon Graphics may not be used in any advertising or
|
|
kusano |
7d535a |
* publicity relating to the software without the specific, prior written
|
|
kusano |
7d535a |
* permission of Sam Leffler and Silicon Graphics.
|
|
kusano |
7d535a |
*
|
|
kusano |
7d535a |
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
|
|
kusano |
7d535a |
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
|
|
kusano |
7d535a |
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
|
kusano |
7d535a |
*
|
|
kusano |
7d535a |
* IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
|
|
kusano |
7d535a |
* ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
|
|
kusano |
7d535a |
* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
|
kusano |
7d535a |
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
|
|
kusano |
7d535a |
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
|
kusano |
7d535a |
* OF THIS SOFTWARE.
|
|
kusano |
7d535a |
*/
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#include "tif_config.h"
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#include <stdio.h></stdio.h>
|
|
kusano |
7d535a |
#include <stdlib.h></stdlib.h>
|
|
kusano |
7d535a |
#include <string.h></string.h>
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#ifdef HAVE_UNISTD_H
|
|
kusano |
7d535a |
# include <unistd.h></unistd.h>
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#ifdef HAVE_FCNTL_H
|
|
kusano |
7d535a |
# include <fcntl.h></fcntl.h>
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#ifdef HAVE_SYS_TYPES_H
|
|
kusano |
7d535a |
# include <sys types.h=""></sys>
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#ifdef HAVE_IO_H
|
|
kusano |
7d535a |
# include <io.h></io.h>
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#ifdef NEED_LIBPORT
|
|
kusano |
7d535a |
# include "libport.h"
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#ifndef HAVE_GETOPT
|
|
kusano |
7d535a |
extern int getopt(int, char**, char*);
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#include "tiffio.h"
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#ifndef O_BINARY
|
|
kusano |
7d535a |
# define O_BINARY 0
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
static union
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
TIFFHeaderClassic classic;
|
|
kusano |
7d535a |
TIFFHeaderBig big;
|
|
kusano |
7d535a |
TIFFHeaderCommon common;
|
|
kusano |
7d535a |
} hdr;
|
|
kusano |
7d535a |
char* appname;
|
|
kusano |
7d535a |
char* curfile;
|
|
kusano |
7d535a |
int swabflag;
|
|
kusano |
7d535a |
int bigendian;
|
|
kusano |
7d535a |
int bigtiff;
|
|
kusano |
7d535a |
uint32 maxitems = 24; /* maximum indirect data items to print */
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
const char* bytefmt = "%s%#02x"; /* BYTE */
|
|
kusano |
7d535a |
const char* sbytefmt = "%s%d"; /* SBYTE */
|
|
kusano |
7d535a |
const char* shortfmt = "%s%u"; /* SHORT */
|
|
kusano |
7d535a |
const char* sshortfmt = "%s%d"; /* SSHORT */
|
|
kusano |
7d535a |
const char* longfmt = "%s%lu"; /* LONG */
|
|
kusano |
7d535a |
const char* slongfmt = "%s%ld"; /* SLONG */
|
|
kusano |
7d535a |
const char* ifdfmt = "%s%#04lx"; /* IFD offset */
|
|
kusano |
7d535a |
#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
|
|
kusano |
7d535a |
const char* long8fmt = "%s%I64u"; /* LONG8 */
|
|
kusano |
7d535a |
const char* slong8fmt = "%s%I64d"; /* SLONG8 */
|
|
kusano |
7d535a |
const char* ifd8fmt = "%s%#08I64x"; /* IFD offset8*/
|
|
kusano |
7d535a |
#else
|
|
kusano |
7d535a |
const char* long8fmt = "%s%llu"; /* LONG8 */
|
|
kusano |
7d535a |
const char* slong8fmt = "%s%lld"; /* SLONG8 */
|
|
kusano |
7d535a |
const char* ifd8fmt = "%s%#08llx"; /* IFD offset8*/
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
const char* rationalfmt = "%s%g"; /* RATIONAL */
|
|
kusano |
7d535a |
const char* srationalfmt = "%s%g"; /* SRATIONAL */
|
|
kusano |
7d535a |
const char* floatfmt = "%s%g"; /* FLOAT */
|
|
kusano |
7d535a |
const char* doublefmt = "%s%g"; /* DOUBLE */
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
static void dump(int, uint64);
|
|
kusano |
7d535a |
extern int optind;
|
|
kusano |
7d535a |
extern char* optarg;
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
void
|
|
kusano |
7d535a |
usage()
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
fprintf(stderr, "usage: %s [-h] [-o offset] [-m maxitems] file.tif ...\n", appname);
|
|
kusano |
7d535a |
exit(-1);
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
int
|
|
kusano |
7d535a |
main(int argc, char* argv[])
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
int one = 1, fd;
|
|
kusano |
7d535a |
int multiplefiles = (argc > 1);
|
|
kusano |
7d535a |
int c;
|
|
kusano |
7d535a |
uint64 diroff = 0;
|
|
kusano |
7d535a |
bigendian = (*(char *)&one == 0);
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
appname = argv[0];
|
|
kusano |
7d535a |
while ((c = getopt(argc, argv, "m:o:h")) != -1) {
|
|
kusano |
7d535a |
switch (c) {
|
|
kusano |
7d535a |
case 'h': /* print values in hex */
|
|
kusano |
7d535a |
shortfmt = "%s%#x";
|
|
kusano |
7d535a |
sshortfmt = "%s%#x";
|
|
kusano |
7d535a |
longfmt = "%s%#lx";
|
|
kusano |
7d535a |
slongfmt = "%s%#lx";
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
case 'o':
|
|
kusano |
7d535a |
diroff = (uint64) strtoul(optarg, NULL, 0);
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
case 'm':
|
|
kusano |
7d535a |
maxitems = strtoul(optarg, NULL, 0);
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
default:
|
|
kusano |
7d535a |
usage();
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
if (optind >= argc)
|
|
kusano |
7d535a |
usage();
|
|
kusano |
7d535a |
for (; optind < argc; optind++) {
|
|
kusano |
7d535a |
fd = open(argv[optind], O_RDONLY|O_BINARY, 0);
|
|
kusano |
7d535a |
if (fd < 0) {
|
|
kusano |
7d535a |
perror(argv[0]);
|
|
kusano |
7d535a |
return (-1);
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
if (multiplefiles)
|
|
kusano |
7d535a |
printf("%s:\n", argv[optind]);
|
|
kusano |
7d535a |
curfile = argv[optind];
|
|
kusano |
7d535a |
swabflag = 0;
|
|
kusano |
7d535a |
bigtiff = 0;
|
|
kusano |
7d535a |
dump(fd, diroff);
|
|
kusano |
7d535a |
close(fd);
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
return (0);
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#define ord(e) ((int)e)
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
static uint64 ReadDirectory(int, unsigned, uint64);
|
|
kusano |
7d535a |
static void ReadError(char*);
|
|
kusano |
7d535a |
static void Error(const char*, ...);
|
|
kusano |
7d535a |
static void Fatal(const char*, ...);
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
static void
|
|
kusano |
7d535a |
dump(int fd, uint64 diroff)
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
unsigned i;
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
lseek(fd, (off_t) 0, 0);
|
|
kusano |
7d535a |
if (read(fd, (char*) &hdr, sizeof (TIFFHeaderCommon)) != sizeof (TIFFHeaderCommon))
|
|
kusano |
7d535a |
ReadError("TIFF header");
|
|
kusano |
7d535a |
if (hdr.common.tiff_magic != TIFF_BIGENDIAN
|
|
kusano |
7d535a |
&& hdr.common.tiff_magic != TIFF_LITTLEENDIAN &&
|
|
kusano |
7d535a |
#if HOST_BIGENDIAN
|
|
kusano |
7d535a |
/* MDI is sensitive to the host byte order, unlike TIFF */
|
|
kusano |
7d535a |
MDI_BIGENDIAN != hdr.common.tiff_magic
|
|
kusano |
7d535a |
#else
|
|
kusano |
7d535a |
MDI_LITTLEENDIAN != hdr.common.tiff_magic
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
) {
|
|
kusano |
7d535a |
Fatal("Not a TIFF or MDI file, bad magic number %u (%#x)",
|
|
kusano |
7d535a |
hdr.common.tiff_magic, hdr.common.tiff_magic);
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
if (hdr.common.tiff_magic == TIFF_BIGENDIAN
|
|
kusano |
7d535a |
|| hdr.common.tiff_magic == MDI_BIGENDIAN)
|
|
kusano |
7d535a |
swabflag = !bigendian;
|
|
kusano |
7d535a |
else
|
|
kusano |
7d535a |
swabflag = bigendian;
|
|
kusano |
7d535a |
if (swabflag)
|
|
kusano |
7d535a |
TIFFSwabShort(&hdr.common.tiff_version);
|
|
kusano |
7d535a |
if (hdr.common.tiff_version==42)
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
if (read(fd, (char*) &hdr.classic.tiff_diroff, 4) != 4)
|
|
kusano |
7d535a |
ReadError("TIFF header");
|
|
kusano |
7d535a |
if (swabflag)
|
|
kusano |
7d535a |
TIFFSwabLong(&hdr.classic.tiff_diroff);
|
|
kusano |
7d535a |
printf("Magic: %#x <%s-endian> Version: %#x <%s>\n",
|
|
kusano |
7d535a |
hdr.classic.tiff_magic,
|
|
kusano |
7d535a |
hdr.classic.tiff_magic == TIFF_BIGENDIAN ? "big" : "little",
|
|
kusano |
7d535a |
42,"ClassicTIFF");
|
|
kusano |
7d535a |
if (diroff == 0)
|
|
kusano |
7d535a |
diroff = hdr.classic.tiff_diroff;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
else if (hdr.common.tiff_version==43)
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
if (read(fd, (char*) &hdr.big.tiff_offsetsize, 12) != 12)
|
|
kusano |
7d535a |
ReadError("TIFF header");
|
|
kusano |
7d535a |
if (swabflag)
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
TIFFSwabShort(&hdr.big.tiff_offsetsize);
|
|
kusano |
7d535a |
TIFFSwabShort(&hdr.big.tiff_unused);
|
|
kusano |
7d535a |
TIFFSwabLong8(&hdr.big.tiff_diroff);
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
printf("Magic: %#x <%s-endian> Version: %#x <%s>\n",
|
|
kusano |
7d535a |
hdr.big.tiff_magic,
|
|
kusano |
7d535a |
hdr.big.tiff_magic == TIFF_BIGENDIAN ? "big" : "little",
|
|
kusano |
7d535a |
43,"BigTIFF");
|
|
kusano |
7d535a |
printf("OffsetSize: %#x Unused: %#x\n",
|
|
kusano |
7d535a |
hdr.big.tiff_offsetsize,hdr.big.tiff_unused);
|
|
kusano |
7d535a |
if (diroff == 0)
|
|
kusano |
7d535a |
diroff = hdr.big.tiff_diroff;
|
|
kusano |
7d535a |
bigtiff = 1;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
else
|
|
kusano |
7d535a |
Fatal("Not a TIFF file, bad version number %u (%#x)",
|
|
kusano |
7d535a |
hdr.common.tiff_version, hdr.common.tiff_version);
|
|
kusano |
7d535a |
for (i = 0; diroff != 0; i++) {
|
|
kusano |
7d535a |
if (i > 0)
|
|
kusano |
7d535a |
putchar('\n');
|
|
kusano |
7d535a |
diroff = ReadDirectory(fd, i, diroff);
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
static const int datawidth[] = {
|
|
kusano |
7d535a |
0, /* 00 = undefined */
|
|
kusano |
7d535a |
1, /* 01 = TIFF_BYTE */
|
|
kusano |
7d535a |
1, /* 02 = TIFF_ASCII */
|
|
kusano |
7d535a |
2, /* 03 = TIFF_SHORT */
|
|
kusano |
7d535a |
4, /* 04 = TIFF_LONG */
|
|
kusano |
7d535a |
8, /* 05 = TIFF_RATIONAL */
|
|
kusano |
7d535a |
1, /* 06 = TIFF_SBYTE */
|
|
kusano |
7d535a |
1, /* 07 = TIFF_UNDEFINED */
|
|
kusano |
7d535a |
2, /* 08 = TIFF_SSHORT */
|
|
kusano |
7d535a |
4, /* 09 = TIFF_SLONG */
|
|
kusano |
7d535a |
8, /* 10 = TIFF_SRATIONAL */
|
|
kusano |
7d535a |
4, /* 11 = TIFF_FLOAT */
|
|
kusano |
7d535a |
8, /* 12 = TIFF_DOUBLE */
|
|
kusano |
7d535a |
4, /* 13 = TIFF_IFD */
|
|
kusano |
7d535a |
0, /* 14 = undefined */
|
|
kusano |
7d535a |
0, /* 15 = undefined */
|
|
kusano |
7d535a |
8, /* 16 = TIFF_LONG8 */
|
|
kusano |
7d535a |
8, /* 17 = TIFF_SLONG8 */
|
|
kusano |
7d535a |
8, /* 18 = TIFF_IFD8 */
|
|
kusano |
7d535a |
};
|
|
kusano |
7d535a |
#define NWIDTHS (sizeof (datawidth) / sizeof (datawidth[0]))
|
|
kusano |
7d535a |
static void PrintTag(FILE*, uint16);
|
|
kusano |
7d535a |
static void PrintType(FILE*, uint16);
|
|
kusano |
7d535a |
static void PrintData(FILE*, uint16, uint32, unsigned char*);
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/*
|
|
kusano |
7d535a |
* Read the next TIFF directory from a file
|
|
kusano |
7d535a |
* and convert it to the internal format.
|
|
kusano |
7d535a |
* We read directories sequentially.
|
|
kusano |
7d535a |
*/
|
|
kusano |
7d535a |
static uint64
|
|
kusano |
7d535a |
ReadDirectory(int fd, unsigned int ix, uint64 off)
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
uint16 dircount;
|
|
kusano |
7d535a |
uint32 direntrysize;
|
|
kusano |
7d535a |
void* dirmem = NULL;
|
|
kusano |
7d535a |
uint64 nextdiroff = 0;
|
|
kusano |
7d535a |
uint32 n;
|
|
kusano |
7d535a |
uint8* dp;
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
if (off == 0) /* no more directories */
|
|
kusano |
7d535a |
goto done;
|
|
kusano |
7d535a |
#if defined(__WIN32__) && defined(_MSC_VER)
|
|
kusano |
7d535a |
if (_lseeki64(fd, (__int64)off, SEEK_SET) != (__int64)off) {
|
|
kusano |
7d535a |
#else
|
|
kusano |
7d535a |
if (lseek(fd, (off_t)off, SEEK_SET) != (off_t)off) {
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
Fatal("Seek error accessing TIFF directory");
|
|
kusano |
7d535a |
goto done;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
if (!bigtiff) {
|
|
kusano |
7d535a |
if (read(fd, (char*) &dircount, sizeof (uint16)) != sizeof (uint16)) {
|
|
kusano |
7d535a |
ReadError("directory count");
|
|
kusano |
7d535a |
goto done;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
if (swabflag)
|
|
kusano |
7d535a |
TIFFSwabShort(&dircount);
|
|
kusano |
7d535a |
direntrysize = 12;
|
|
kusano |
7d535a |
} else {
|
|
kusano |
7d535a |
uint64 dircount64 = 0;
|
|
kusano |
7d535a |
if (read(fd, (char*) &dircount64, sizeof (uint64)) != sizeof (uint64)) {
|
|
kusano |
7d535a |
ReadError("directory count");
|
|
kusano |
7d535a |
goto done;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
if (swabflag)
|
|
kusano |
7d535a |
TIFFSwabLong8(&dircount64);
|
|
kusano |
7d535a |
if (dircount64>0xFFFF) {
|
|
kusano |
7d535a |
Error("Sanity check on directory count failed");
|
|
kusano |
7d535a |
goto done;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
dircount = (uint16)dircount64;
|
|
kusano |
7d535a |
direntrysize = 20;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
dirmem = _TIFFmalloc(dircount * direntrysize);
|
|
kusano |
7d535a |
if (dirmem == NULL) {
|
|
kusano |
7d535a |
Fatal("No space for TIFF directory");
|
|
kusano |
7d535a |
goto done;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
n = read(fd, (char*) dirmem, dircount*direntrysize);
|
|
kusano |
7d535a |
if (n != dircount*direntrysize) {
|
|
kusano |
7d535a |
n /= direntrysize;
|
|
kusano |
7d535a |
Error(
|
|
kusano |
7d535a |
#if defined(__WIN32__) && defined(_MSC_VER)
|
|
kusano |
7d535a |
"Could only read %lu of %u entries in directory at offset %#I64x",
|
|
kusano |
7d535a |
(unsigned long)n, dircount, (unsigned __int64) off);
|
|
kusano |
7d535a |
#else
|
|
kusano |
7d535a |
"Could only read %lu of %u entries in directory at offset %#llx",
|
|
kusano |
7d535a |
(unsigned long)n, dircount, (unsigned long long) off);
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
dircount = n;
|
|
kusano |
7d535a |
nextdiroff = 0;
|
|
kusano |
7d535a |
} else {
|
|
kusano |
7d535a |
if (!bigtiff) {
|
|
kusano |
7d535a |
uint32 nextdiroff32;
|
|
kusano |
7d535a |
if (read(fd, (char*) &nextdiroff32, sizeof (uint32)) != sizeof (uint32))
|
|
kusano |
7d535a |
nextdiroff32 = 0;
|
|
kusano |
7d535a |
if (swabflag)
|
|
kusano |
7d535a |
TIFFSwabLong(&nextdiroff32);
|
|
kusano |
7d535a |
nextdiroff = nextdiroff32;
|
|
kusano |
7d535a |
} else {
|
|
kusano |
7d535a |
if (read(fd, (char*) &nextdiroff, sizeof (uint64)) != sizeof (uint64))
|
|
kusano |
7d535a |
nextdiroff = 0;
|
|
kusano |
7d535a |
if (swabflag)
|
|
kusano |
7d535a |
TIFFSwabLong8(&nextdiroff);
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
|
|
kusano |
7d535a |
printf("Directory %u: offset %I64u (%#I64x) next %I64u (%#I64x)\n", ix,
|
|
kusano |
7d535a |
(unsigned __int64)off, (unsigned __int64)off,
|
|
kusano |
7d535a |
(unsigned __int64)nextdiroff, (unsigned __int64)nextdiroff);
|
|
kusano |
7d535a |
#else
|
|
kusano |
7d535a |
printf("Directory %u: offset %llu (%#llx) next %llu (%#llx)\n", ix,
|
|
kusano |
7d535a |
(unsigned long long)off, (unsigned long long)off,
|
|
kusano |
7d535a |
(unsigned long long)nextdiroff, (unsigned long long)nextdiroff);
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
for (dp = (uint8*)dirmem, n = dircount; n > 0; n--) {
|
|
kusano |
7d535a |
uint16 tag;
|
|
kusano |
7d535a |
uint16 type;
|
|
kusano |
7d535a |
uint16 typewidth;
|
|
kusano |
7d535a |
uint64 count;
|
|
kusano |
7d535a |
uint64 datasize;
|
|
kusano |
7d535a |
int datafits;
|
|
kusano |
7d535a |
void* datamem;
|
|
kusano |
7d535a |
uint64 dataoffset;
|
|
kusano |
7d535a |
int datatruncated;
|
|
kusano |
7d535a |
tag = *(uint16*)dp;
|
|
kusano |
7d535a |
if (swabflag)
|
|
kusano |
7d535a |
TIFFSwabShort(&tag);
|
|
kusano |
7d535a |
dp += sizeof(uint16);
|
|
kusano |
7d535a |
type = *(uint16*)dp;
|
|
kusano |
7d535a |
dp += sizeof(uint16);
|
|
kusano |
7d535a |
if (swabflag)
|
|
kusano |
7d535a |
TIFFSwabShort(&type);
|
|
kusano |
7d535a |
PrintTag(stdout, tag);
|
|
kusano |
7d535a |
putchar(' ');
|
|
kusano |
7d535a |
PrintType(stdout, type);
|
|
kusano |
7d535a |
putchar(' ');
|
|
kusano |
7d535a |
if (!bigtiff)
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
uint32 count32;
|
|
kusano |
7d535a |
count32 = *(uint32*)dp;
|
|
kusano |
7d535a |
if (swabflag)
|
|
kusano |
7d535a |
TIFFSwabLong(&count32);
|
|
kusano |
7d535a |
dp += sizeof(uint32);
|
|
kusano |
7d535a |
count = count32;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
else
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
count = *(uint64*)dp;
|
|
kusano |
7d535a |
if (swabflag)
|
|
kusano |
7d535a |
TIFFSwabLong8(&count);
|
|
kusano |
7d535a |
dp += sizeof(uint64);
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
|
|
kusano |
7d535a |
printf("%I64u<", (unsigned __int64)count);
|
|
kusano |
7d535a |
#else
|
|
kusano |
7d535a |
printf("%llu<", (unsigned long long)count);
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
if (type >= NWIDTHS)
|
|
kusano |
7d535a |
typewidth = 0;
|
|
kusano |
7d535a |
else
|
|
kusano |
7d535a |
typewidth = datawidth[type];
|
|
kusano |
7d535a |
datasize = count*typewidth;
|
|
kusano |
7d535a |
datafits = 1;
|
|
kusano |
7d535a |
datamem = dp;
|
|
kusano |
7d535a |
dataoffset = 0;
|
|
kusano |
7d535a |
datatruncated = 0;
|
|
kusano |
7d535a |
if (!bigtiff)
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
if (datasize>4)
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
uint32 dataoffset32;
|
|
kusano |
7d535a |
datafits = 0;
|
|
kusano |
7d535a |
datamem = NULL;
|
|
kusano |
7d535a |
dataoffset32 = *(uint32*)dp;
|
|
kusano |
7d535a |
if (swabflag)
|
|
kusano |
7d535a |
TIFFSwabLong(&dataoffset32);
|
|
kusano |
7d535a |
dataoffset = dataoffset32;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
dp += sizeof(uint32);
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
else
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
if (datasize>8)
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
datafits = 0;
|
|
kusano |
7d535a |
datamem = NULL;
|
|
kusano |
7d535a |
dataoffset = *(uint64*)dp;
|
|
kusano |
7d535a |
if (swabflag)
|
|
kusano |
7d535a |
TIFFSwabLong8(&dataoffset);
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
dp += sizeof(uint64);
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
if (datasize>0x10000)
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
datatruncated = 1;
|
|
kusano |
7d535a |
count = 0x10000/typewidth;
|
|
kusano |
7d535a |
datasize = count*typewidth;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
if (count>maxitems)
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
datatruncated = 1;
|
|
kusano |
7d535a |
count = maxitems;
|
|
kusano |
7d535a |
datasize = count*typewidth;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
if (!datafits)
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
datamem = _TIFFmalloc((uint32)datasize);
|
|
kusano |
7d535a |
if (datamem) {
|
|
kusano |
7d535a |
#if defined(__WIN32__) && defined(_MSC_VER)
|
|
kusano |
7d535a |
if (_lseeki64(fd, (__int64)dataoffset, SEEK_SET)
|
|
kusano |
7d535a |
!= (__int64)dataoffset)
|
|
kusano |
7d535a |
#else
|
|
kusano |
7d535a |
if (lseek(fd, (off_t)dataoffset, 0) !=
|
|
kusano |
7d535a |
(off_t)dataoffset)
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
Error(
|
|
kusano |
7d535a |
"Seek error accessing tag %u value", tag);
|
|
kusano |
7d535a |
_TIFFfree(datamem);
|
|
kusano |
7d535a |
datamem = NULL;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
if (read(fd, datamem, (size_t)datasize) != (TIFF_SSIZE_T)datasize)
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
Error(
|
|
kusano |
7d535a |
"Read error accessing tag %u value", tag);
|
|
kusano |
7d535a |
_TIFFfree(datamem);
|
|
kusano |
7d535a |
datamem = NULL;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
} else
|
|
kusano |
7d535a |
Error("No space for data for tag %u",tag);
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
if (datamem)
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
if (swabflag)
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
switch (type)
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
case TIFF_BYTE:
|
|
kusano |
7d535a |
case TIFF_ASCII:
|
|
kusano |
7d535a |
case TIFF_SBYTE:
|
|
kusano |
7d535a |
case TIFF_UNDEFINED:
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
case TIFF_SHORT:
|
|
kusano |
7d535a |
case TIFF_SSHORT:
|
|
kusano |
7d535a |
TIFFSwabArrayOfShort((uint16*)datamem,(tmsize_t)count);
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
case TIFF_LONG:
|
|
kusano |
7d535a |
case TIFF_SLONG:
|
|
kusano |
7d535a |
case TIFF_FLOAT:
|
|
kusano |
7d535a |
case TIFF_IFD:
|
|
kusano |
7d535a |
TIFFSwabArrayOfLong((uint32*)datamem,(tmsize_t)count);
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
case TIFF_RATIONAL:
|
|
kusano |
7d535a |
case TIFF_SRATIONAL:
|
|
kusano |
7d535a |
TIFFSwabArrayOfLong((uint32*)datamem,(tmsize_t)count*2);
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
case TIFF_DOUBLE:
|
|
kusano |
7d535a |
case TIFF_LONG8:
|
|
kusano |
7d535a |
case TIFF_SLONG8:
|
|
kusano |
7d535a |
case TIFF_IFD8:
|
|
kusano |
7d535a |
TIFFSwabArrayOfLong8((uint64*)datamem,(tmsize_t)count);
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
PrintData(stdout,type,(uint32)count,datamem);
|
|
kusano |
7d535a |
if (datatruncated)
|
|
kusano |
7d535a |
printf(" ...");
|
|
kusano |
7d535a |
if (!datafits)
|
|
kusano |
7d535a |
_TIFFfree(datamem);
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
printf(">\n");
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
done:
|
|
kusano |
7d535a |
if (dirmem)
|
|
kusano |
7d535a |
_TIFFfree((char *)dirmem);
|
|
kusano |
7d535a |
return (nextdiroff);
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
static const struct tagname {
|
|
kusano |
7d535a |
uint16 tag;
|
|
kusano |
7d535a |
const char* name;
|
|
kusano |
7d535a |
} tagnames[] = {
|
|
kusano |
7d535a |
{ TIFFTAG_SUBFILETYPE, "SubFileType" },
|
|
kusano |
7d535a |
{ TIFFTAG_OSUBFILETYPE, "OldSubFileType" },
|
|
kusano |
7d535a |
{ TIFFTAG_IMAGEWIDTH, "ImageWidth" },
|
|
kusano |
7d535a |
{ TIFFTAG_IMAGELENGTH, "ImageLength" },
|
|
kusano |
7d535a |
{ TIFFTAG_BITSPERSAMPLE, "BitsPerSample" },
|
|
kusano |
7d535a |
{ TIFFTAG_COMPRESSION, "Compression" },
|
|
kusano |
7d535a |
{ TIFFTAG_PHOTOMETRIC, "Photometric" },
|
|
kusano |
7d535a |
{ TIFFTAG_THRESHHOLDING, "Threshholding" },
|
|
kusano |
7d535a |
{ TIFFTAG_CELLWIDTH, "CellWidth" },
|
|
kusano |
7d535a |
{ TIFFTAG_CELLLENGTH, "CellLength" },
|
|
kusano |
7d535a |
{ TIFFTAG_FILLORDER, "FillOrder" },
|
|
kusano |
7d535a |
{ TIFFTAG_DOCUMENTNAME, "DocumentName" },
|
|
kusano |
7d535a |
{ TIFFTAG_IMAGEDESCRIPTION, "ImageDescription" },
|
|
kusano |
7d535a |
{ TIFFTAG_MAKE, "Make" },
|
|
kusano |
7d535a |
{ TIFFTAG_MODEL, "Model" },
|
|
kusano |
7d535a |
{ TIFFTAG_STRIPOFFSETS, "StripOffsets" },
|
|
kusano |
7d535a |
{ TIFFTAG_ORIENTATION, "Orientation" },
|
|
kusano |
7d535a |
{ TIFFTAG_SAMPLESPERPIXEL, "SamplesPerPixel" },
|
|
kusano |
7d535a |
{ TIFFTAG_ROWSPERSTRIP, "RowsPerStrip" },
|
|
kusano |
7d535a |
{ TIFFTAG_STRIPBYTECOUNTS, "StripByteCounts" },
|
|
kusano |
7d535a |
{ TIFFTAG_MINSAMPLEVALUE, "MinSampleValue" },
|
|
kusano |
7d535a |
{ TIFFTAG_MAXSAMPLEVALUE, "MaxSampleValue" },
|
|
kusano |
7d535a |
{ TIFFTAG_XRESOLUTION, "XResolution" },
|
|
kusano |
7d535a |
{ TIFFTAG_YRESOLUTION, "YResolution" },
|
|
kusano |
7d535a |
{ TIFFTAG_PLANARCONFIG, "PlanarConfig" },
|
|
kusano |
7d535a |
{ TIFFTAG_PAGENAME, "PageName" },
|
|
kusano |
7d535a |
{ TIFFTAG_XPOSITION, "XPosition" },
|
|
kusano |
7d535a |
{ TIFFTAG_YPOSITION, "YPosition" },
|
|
kusano |
7d535a |
{ TIFFTAG_FREEOFFSETS, "FreeOffsets" },
|
|
kusano |
7d535a |
{ TIFFTAG_FREEBYTECOUNTS, "FreeByteCounts" },
|
|
kusano |
7d535a |
{ TIFFTAG_GRAYRESPONSEUNIT, "GrayResponseUnit" },
|
|
kusano |
7d535a |
{ TIFFTAG_GRAYRESPONSECURVE,"GrayResponseCurve" },
|
|
kusano |
7d535a |
{ TIFFTAG_GROUP3OPTIONS, "Group3Options" },
|
|
kusano |
7d535a |
{ TIFFTAG_GROUP4OPTIONS, "Group4Options" },
|
|
kusano |
7d535a |
{ TIFFTAG_RESOLUTIONUNIT, "ResolutionUnit" },
|
|
kusano |
7d535a |
{ TIFFTAG_PAGENUMBER, "PageNumber" },
|
|
kusano |
7d535a |
{ TIFFTAG_COLORRESPONSEUNIT,"ColorResponseUnit" },
|
|
kusano |
7d535a |
{ TIFFTAG_TRANSFERFUNCTION, "TransferFunction" },
|
|
kusano |
7d535a |
{ TIFFTAG_SOFTWARE, "Software" },
|
|
kusano |
7d535a |
{ TIFFTAG_DATETIME, "DateTime" },
|
|
kusano |
7d535a |
{ TIFFTAG_ARTIST, "Artist" },
|
|
kusano |
7d535a |
{ TIFFTAG_HOSTCOMPUTER, "HostComputer" },
|
|
kusano |
7d535a |
{ TIFFTAG_PREDICTOR, "Predictor" },
|
|
kusano |
7d535a |
{ TIFFTAG_WHITEPOINT, "Whitepoint" },
|
|
kusano |
7d535a |
{ TIFFTAG_PRIMARYCHROMATICITIES,"PrimaryChromaticities" },
|
|
kusano |
7d535a |
{ TIFFTAG_COLORMAP, "Colormap" },
|
|
kusano |
7d535a |
{ TIFFTAG_HALFTONEHINTS, "HalftoneHints" },
|
|
kusano |
7d535a |
{ TIFFTAG_TILEWIDTH, "TileWidth" },
|
|
kusano |
7d535a |
{ TIFFTAG_TILELENGTH, "TileLength" },
|
|
kusano |
7d535a |
{ TIFFTAG_TILEOFFSETS, "TileOffsets" },
|
|
kusano |
7d535a |
{ TIFFTAG_TILEBYTECOUNTS, "TileByteCounts" },
|
|
kusano |
7d535a |
{ TIFFTAG_BADFAXLINES, "BadFaxLines" },
|
|
kusano |
7d535a |
{ TIFFTAG_CLEANFAXDATA, "CleanFaxData" },
|
|
kusano |
7d535a |
{ TIFFTAG_CONSECUTIVEBADFAXLINES, "ConsecutiveBadFaxLines" },
|
|
kusano |
7d535a |
{ TIFFTAG_SUBIFD, "SubIFD" },
|
|
kusano |
7d535a |
{ TIFFTAG_INKSET, "InkSet" },
|
|
kusano |
7d535a |
{ TIFFTAG_INKNAMES, "InkNames" },
|
|
kusano |
7d535a |
{ TIFFTAG_NUMBEROFINKS, "NumberOfInks" },
|
|
kusano |
7d535a |
{ TIFFTAG_DOTRANGE, "DotRange" },
|
|
kusano |
7d535a |
{ TIFFTAG_TARGETPRINTER, "TargetPrinter" },
|
|
kusano |
7d535a |
{ TIFFTAG_EXTRASAMPLES, "ExtraSamples" },
|
|
kusano |
7d535a |
{ TIFFTAG_SAMPLEFORMAT, "SampleFormat" },
|
|
kusano |
7d535a |
{ TIFFTAG_SMINSAMPLEVALUE, "SMinSampleValue" },
|
|
kusano |
7d535a |
{ TIFFTAG_SMAXSAMPLEVALUE, "SMaxSampleValue" },
|
|
kusano |
7d535a |
{ TIFFTAG_JPEGPROC, "JPEGProcessingMode" },
|
|
kusano |
7d535a |
{ TIFFTAG_JPEGIFOFFSET, "JPEGInterchangeFormat" },
|
|
kusano |
7d535a |
{ TIFFTAG_JPEGIFBYTECOUNT, "JPEGInterchangeFormatLength" },
|
|
kusano |
7d535a |
{ TIFFTAG_JPEGRESTARTINTERVAL,"JPEGRestartInterval" },
|
|
kusano |
7d535a |
{ TIFFTAG_JPEGLOSSLESSPREDICTORS,"JPEGLosslessPredictors" },
|
|
kusano |
7d535a |
{ TIFFTAG_JPEGPOINTTRANSFORM,"JPEGPointTransform" },
|
|
kusano |
7d535a |
{ TIFFTAG_JPEGTABLES, "JPEGTables" },
|
|
kusano |
7d535a |
{ TIFFTAG_JPEGQTABLES, "JPEGQTables" },
|
|
kusano |
7d535a |
{ TIFFTAG_JPEGDCTABLES, "JPEGDCTables" },
|
|
kusano |
7d535a |
{ TIFFTAG_JPEGACTABLES, "JPEGACTables" },
|
|
kusano |
7d535a |
{ TIFFTAG_YCBCRCOEFFICIENTS,"YCbCrCoefficients" },
|
|
kusano |
7d535a |
{ TIFFTAG_YCBCRSUBSAMPLING, "YCbCrSubsampling" },
|
|
kusano |
7d535a |
{ TIFFTAG_YCBCRPOSITIONING, "YCbCrPositioning" },
|
|
kusano |
7d535a |
{ TIFFTAG_REFERENCEBLACKWHITE, "ReferenceBlackWhite" },
|
|
kusano |
7d535a |
{ TIFFTAG_REFPTS, "IgReferencePoints (Island Graphics)" },
|
|
kusano |
7d535a |
{ TIFFTAG_REGIONTACKPOINT, "IgRegionTackPoint (Island Graphics)" },
|
|
kusano |
7d535a |
{ TIFFTAG_REGIONWARPCORNERS,"IgRegionWarpCorners (Island Graphics)" },
|
|
kusano |
7d535a |
{ TIFFTAG_REGIONAFFINE, "IgRegionAffine (Island Graphics)" },
|
|
kusano |
7d535a |
{ TIFFTAG_MATTEING, "OBSOLETE Matteing (Silicon Graphics)" },
|
|
kusano |
7d535a |
{ TIFFTAG_DATATYPE, "OBSOLETE DataType (Silicon Graphics)" },
|
|
kusano |
7d535a |
{ TIFFTAG_IMAGEDEPTH, "ImageDepth (Silicon Graphics)" },
|
|
kusano |
7d535a |
{ TIFFTAG_TILEDEPTH, "TileDepth (Silicon Graphics)" },
|
|
kusano |
7d535a |
{ 32768, "OLD BOGUS Matteing tag" },
|
|
kusano |
7d535a |
{ TIFFTAG_COPYRIGHT, "Copyright" },
|
|
kusano |
7d535a |
{ TIFFTAG_ICCPROFILE, "ICC Profile" },
|
|
kusano |
7d535a |
{ TIFFTAG_JBIGOPTIONS, "JBIG Options" },
|
|
kusano |
7d535a |
{ TIFFTAG_STONITS, "StoNits" },
|
|
kusano |
7d535a |
};
|
|
kusano |
7d535a |
#define NTAGS (sizeof (tagnames) / sizeof (tagnames[0]))
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
static void
|
|
kusano |
7d535a |
PrintTag(FILE* fd, uint16 tag)
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
const struct tagname *tp;
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
for (tp = tagnames; tp < &tagnames[NTAGS]; tp++)
|
|
kusano |
7d535a |
if (tp->tag == tag) {
|
|
kusano |
7d535a |
fprintf(fd, "%s (%u)", tp->name, tag);
|
|
kusano |
7d535a |
return;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
fprintf(fd, "%u (%#x)", tag, tag);
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
static void
|
|
kusano |
7d535a |
PrintType(FILE* fd, uint16 type)
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
static const char *typenames[] = {
|
|
kusano |
7d535a |
"0",
|
|
kusano |
7d535a |
"BYTE",
|
|
kusano |
7d535a |
"ASCII",
|
|
kusano |
7d535a |
"SHORT",
|
|
kusano |
7d535a |
"LONG",
|
|
kusano |
7d535a |
"RATIONAL",
|
|
kusano |
7d535a |
"SBYTE",
|
|
kusano |
7d535a |
"UNDEFINED",
|
|
kusano |
7d535a |
"SSHORT",
|
|
kusano |
7d535a |
"SLONG",
|
|
kusano |
7d535a |
"SRATIONAL",
|
|
kusano |
7d535a |
"FLOAT",
|
|
kusano |
7d535a |
"DOUBLE",
|
|
kusano |
7d535a |
"IFD",
|
|
kusano |
7d535a |
"14",
|
|
kusano |
7d535a |
"15",
|
|
kusano |
7d535a |
"LONG8",
|
|
kusano |
7d535a |
"SLONG8",
|
|
kusano |
7d535a |
"IFD8"
|
|
kusano |
7d535a |
};
|
|
kusano |
7d535a |
#define NTYPES (sizeof (typenames) / sizeof (typenames[0]))
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
if (type < NTYPES)
|
|
kusano |
7d535a |
fprintf(fd, "%s (%u)", typenames[type], type);
|
|
kusano |
7d535a |
else
|
|
kusano |
7d535a |
fprintf(fd, "%u (%#x)", type, type);
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
#undef NTYPES
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#include <ctype.h></ctype.h>
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
static void
|
|
kusano |
7d535a |
PrintASCII(FILE* fd, uint32 cc, const unsigned char* cp)
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
for (; cc > 0; cc--, cp++) {
|
|
kusano |
7d535a |
const char* tp;
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
if (isprint(*cp)) {
|
|
kusano |
7d535a |
fputc(*cp, fd);
|
|
kusano |
7d535a |
continue;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
for (tp = "\tt\bb\rr\nn\vv"; *tp; tp++)
|
|
kusano |
7d535a |
if (*tp++ == *cp)
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
if (*tp)
|
|
kusano |
7d535a |
fprintf(fd, "\\%c", *tp);
|
|
kusano |
7d535a |
else if (*cp)
|
|
kusano |
7d535a |
fprintf(fd, "\\%03o", *cp);
|
|
kusano |
7d535a |
else
|
|
kusano |
7d535a |
fprintf(fd, "\\0");
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
static void
|
|
kusano |
7d535a |
PrintData(FILE* fd, uint16 type, uint32 count, unsigned char* data)
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
char* sep = "";
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
switch (type) {
|
|
kusano |
7d535a |
case TIFF_BYTE:
|
|
kusano |
7d535a |
while (count-- > 0)
|
|
kusano |
7d535a |
fprintf(fd, bytefmt, sep, *data++), sep = " ";
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
case TIFF_SBYTE:
|
|
kusano |
7d535a |
while (count-- > 0)
|
|
kusano |
7d535a |
fprintf(fd, sbytefmt, sep, *(char *)data++), sep = " ";
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
case TIFF_UNDEFINED:
|
|
kusano |
7d535a |
while (count-- > 0)
|
|
kusano |
7d535a |
fprintf(fd, bytefmt, sep, *data++), sep = " ";
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
case TIFF_ASCII:
|
|
kusano |
7d535a |
PrintASCII(fd, count, data);
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
case TIFF_SHORT: {
|
|
kusano |
7d535a |
uint16 *wp = (uint16*)data;
|
|
kusano |
7d535a |
while (count-- > 0)
|
|
kusano |
7d535a |
fprintf(fd, shortfmt, sep, *wp++), sep = " ";
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
case TIFF_SSHORT: {
|
|
kusano |
7d535a |
int16 *wp = (int16*)data;
|
|
kusano |
7d535a |
while (count-- > 0)
|
|
kusano |
7d535a |
fprintf(fd, sshortfmt, sep, *wp++), sep = " ";
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
case TIFF_LONG: {
|
|
kusano |
7d535a |
uint32 *lp = (uint32*)data;
|
|
kusano |
7d535a |
while (count-- > 0) {
|
|
kusano |
7d535a |
fprintf(fd, longfmt, sep, (unsigned long) *lp++);
|
|
kusano |
7d535a |
sep = " ";
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
case TIFF_SLONG: {
|
|
kusano |
7d535a |
int32 *lp = (int32*)data;
|
|
kusano |
7d535a |
while (count-- > 0)
|
|
kusano |
7d535a |
fprintf(fd, slongfmt, sep, (long) *lp++), sep = " ";
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
case TIFF_LONG8: {
|
|
kusano |
7d535a |
uint64 *llp = (uint64*)data;
|
|
kusano |
7d535a |
while (count-- > 0) {
|
|
kusano |
7d535a |
#if defined(__WIN32__) && defined(_MSC_VER)
|
|
kusano |
7d535a |
fprintf(fd, long8fmt, sep, (unsigned __int64) *llp++);
|
|
kusano |
7d535a |
#else
|
|
kusano |
7d535a |
fprintf(fd, long8fmt, sep, (unsigned long long) *llp++);
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
sep = " ";
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
case TIFF_SLONG8: {
|
|
kusano |
7d535a |
int64 *llp = (int64*)data;
|
|
kusano |
7d535a |
while (count-- > 0)
|
|
kusano |
7d535a |
#if defined(__WIN32__) && defined(_MSC_VER)
|
|
kusano |
7d535a |
fprintf(fd, slong8fmt, sep, (__int64) *llp++), sep = " ";
|
|
kusano |
7d535a |
#else
|
|
kusano |
7d535a |
fprintf(fd, slong8fmt, sep, (long long) *llp++), sep = " ";
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
case TIFF_RATIONAL: {
|
|
kusano |
7d535a |
uint32 *lp = (uint32*)data;
|
|
kusano |
7d535a |
while (count-- > 0) {
|
|
kusano |
7d535a |
if (lp[1] == 0)
|
|
kusano |
7d535a |
fprintf(fd, "%sNan (%lu/%lu)", sep,
|
|
kusano |
7d535a |
(unsigned long) lp[0],
|
|
kusano |
7d535a |
(unsigned long) lp[1]);
|
|
kusano |
7d535a |
else
|
|
kusano |
7d535a |
fprintf(fd, rationalfmt, sep,
|
|
kusano |
7d535a |
(double)lp[0] / (double)lp[1]);
|
|
kusano |
7d535a |
sep = " ";
|
|
kusano |
7d535a |
lp += 2;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
case TIFF_SRATIONAL: {
|
|
kusano |
7d535a |
int32 *lp = (int32*)data;
|
|
kusano |
7d535a |
while (count-- > 0) {
|
|
kusano |
7d535a |
if (lp[1] == 0)
|
|
kusano |
7d535a |
fprintf(fd, "%sNan (%ld/%ld)", sep,
|
|
kusano |
7d535a |
(long) lp[0], (long) lp[1]);
|
|
kusano |
7d535a |
else
|
|
kusano |
7d535a |
fprintf(fd, srationalfmt, sep,
|
|
kusano |
7d535a |
(double)lp[0] / (double)lp[1]);
|
|
kusano |
7d535a |
sep = " ";
|
|
kusano |
7d535a |
lp += 2;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
case TIFF_FLOAT: {
|
|
kusano |
7d535a |
float *fp = (float *)data;
|
|
kusano |
7d535a |
while (count-- > 0)
|
|
kusano |
7d535a |
fprintf(fd, floatfmt, sep, *fp++), sep = " ";
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
case TIFF_DOUBLE: {
|
|
kusano |
7d535a |
double *dp = (double *)data;
|
|
kusano |
7d535a |
while (count-- > 0)
|
|
kusano |
7d535a |
fprintf(fd, doublefmt, sep, *dp++), sep = " ";
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
case TIFF_IFD: {
|
|
kusano |
7d535a |
uint32 *lp = (uint32*)data;
|
|
kusano |
7d535a |
while (count-- > 0) {
|
|
kusano |
7d535a |
fprintf(fd, ifdfmt, sep, (unsigned long) *lp++);
|
|
kusano |
7d535a |
sep = " ";
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
case TIFF_IFD8: {
|
|
kusano |
7d535a |
uint64 *llp = (uint64*)data;
|
|
kusano |
7d535a |
while (count-- > 0) {
|
|
kusano |
7d535a |
#if defined(__WIN32__) && defined(_MSC_VER)
|
|
kusano |
7d535a |
fprintf(fd, ifd8fmt, sep, (unsigned __int64) *llp++);
|
|
kusano |
7d535a |
#else
|
|
kusano |
7d535a |
fprintf(fd, ifd8fmt, sep, (unsigned long long) *llp++);
|
|
kusano |
7d535a |
#endif
|
|
kusano |
7d535a |
sep = " ";
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
break;
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
static void
|
|
kusano |
7d535a |
ReadError(char* what)
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
Fatal("Error while reading %s", what);
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
#include <stdarg.h></stdarg.h>
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
static void
|
|
kusano |
7d535a |
vError(FILE* fd, const char* fmt, va_list ap)
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
fprintf(fd, "%s: ", curfile);
|
|
kusano |
7d535a |
vfprintf(fd, fmt, ap);
|
|
kusano |
7d535a |
fprintf(fd, ".\n");
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
static void
|
|
kusano |
7d535a |
Error(const char* fmt, ...)
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
va_list ap;
|
|
kusano |
7d535a |
va_start(ap, fmt);
|
|
kusano |
7d535a |
vError(stderr, fmt, ap);
|
|
kusano |
7d535a |
va_end(ap);
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
static void
|
|
kusano |
7d535a |
Fatal(const char* fmt, ...)
|
|
kusano |
7d535a |
{
|
|
kusano |
7d535a |
va_list ap;
|
|
kusano |
7d535a |
va_start(ap, fmt);
|
|
kusano |
7d535a |
vError(stderr, fmt, ap);
|
|
kusano |
7d535a |
va_end(ap);
|
|
kusano |
7d535a |
exit(-1);
|
|
kusano |
7d535a |
}
|
|
kusano |
7d535a |
|
|
kusano |
7d535a |
/* vim: set ts=8 sts=8 sw=8 noet: */
|
|
kusano |
7d535a |
/*
|
|
kusano |
7d535a |
* Local Variables:
|
|
kusano |
7d535a |
* mode: c
|
|
kusano |
7d535a |
* c-basic-offset: 8
|
|
kusano |
7d535a |
* fill-column: 78
|
|
kusano |
7d535a |
* End:
|
|
kusano |
7d535a |
*/
|