-/* $Id: tif_print.c,v 1.54 2011-04-02 20:54:09 bfriesen Exp $ */
+/* $Id: tif_print.c,v 1.62 2015-08-19 02:31:04 bfriesen Exp $ */
/*
* Copyright (c) 1988-1997 Sam Leffler
#include <ctype.h>
+static void
+_TIFFprintAsciiBounded(FILE* fd, const char* cp, size_t max_chars);
+
static const char *photoNames[] = {
"min-is-white", /* PHOTOMETRIC_MINISWHITE */
"min-is-black", /* PHOTOMETRIC_MINISBLACK */
"YCbCr", /* PHOTOMETRIC_YCBCR */
"7 (0x7)",
"CIE L*a*b*", /* PHOTOMETRIC_CIELAB */
+ "ICC L*a*b*", /* PHOTOMETRIC_ICCLAB */
+ "ITU L*a*b*" /* PHOTOMETRIC_ITULAB */
};
#define NPHOTONAMES (sizeof (photoNames) / sizeof (photoNames[0]))
}
static int
-_TIFFPrettyPrintField(TIFF* tif, FILE* fd, uint32 tag,
+_TIFFPrettyPrintField(TIFF* tif, const TIFFField *fip, FILE* fd, uint32 tag,
uint32 value_count, void *raw_data)
{
(void) tif;
+
+ /* do not try to pretty print auto-defined fields */
+ if (strncmp(fip->field_name,"Tag ", 4) == 0) {
+ return 0;
+ }
switch (tag)
{
case TIFFTAG_INKSET:
- fprintf(fd, " Ink Set: ");
- switch (*((uint16*)raw_data)) {
+ if (value_count == 2 && fip->field_type == TIFF_SHORT) {
+ fprintf(fd, " Ink Set: ");
+ switch (*((uint16*)raw_data)) {
case INKSET_CMYK:
fprintf(fd, "CMYK\n");
break;
default:
fprintf(fd, "%u (0x%x)\n",
- *((uint16*)raw_data),
- *((uint16*)raw_data));
+ *((uint16*)raw_data),
+ *((uint16*)raw_data));
break;
+ }
+ return 1;
}
- return 1;
+ return 0;
+
case TIFFTAG_DOTRANGE:
- fprintf(fd, " Dot Range: %u-%u\n",
- ((uint16*)raw_data)[0], ((uint16*)raw_data)[1]);
- return 1;
+ if (value_count == 2 && fip->field_type == TIFF_SHORT) {
+ fprintf(fd, " Dot Range: %u-%u\n",
+ ((uint16*)raw_data)[0], ((uint16*)raw_data)[1]);
+ return 1;
+ }
+ return 0;
+
case TIFFTAG_WHITEPOINT:
- fprintf(fd, " White Point: %g-%g\n",
- ((float *)raw_data)[0], ((float *)raw_data)[1]);
- return 1;
+ if (value_count == 2 && fip->field_type == TIFF_RATIONAL) {
+ fprintf(fd, " White Point: %g-%g\n",
+ ((float *)raw_data)[0], ((float *)raw_data)[1]);
+ return 1;
+ }
+ return 0;
+
case TIFFTAG_XMLPACKET:
{
uint32 i;
" RichTIFFIPTC Data: <present>, %lu bytes\n",
(unsigned long) value_count * 4);
return 1;
+
case TIFFTAG_PHOTOSHOP:
fprintf(fd, " Photoshop Data: <present>, %lu bytes\n",
(unsigned long) value_count);
return 1;
+
case TIFFTAG_ICCPROFILE:
fprintf(fd, " ICC Profile: <present>, %lu bytes\n",
(unsigned long) value_count);
return 1;
+
case TIFFTAG_STONITS:
- fprintf(fd,
- " Sample to Nits conversion factor: %.4e\n",
- *((double*)raw_data));
- return 1;
+ if (value_count == 1 && fip->field_type == TIFF_DOUBLE) {
+ fprintf(fd,
+ " Sample to Nits conversion factor: %.4e\n",
+ *((double*)raw_data));
+ return 1;
+ }
+ return 0;
}
return 0;
fprintf(fd, " Ink Names: ");
i = td->td_samplesperpixel;
sep = "";
- for (cp = td->td_inknames; i > 0; cp = strchr(cp,'\0')+1, i--) {
+ for (cp = td->td_inknames;
+ i > 0 && cp < td->td_inknames + td->td_inknameslen;
+ cp = strchr(cp,'\0')+1, i--) {
+ size_t max_chars =
+ td->td_inknameslen - (cp - td->td_inknames);
fputs(sep, fd);
- _TIFFprintAscii(fd, cp);
+ _TIFFprintAsciiBounded(fd, cp, max_chars);
sep = ", ";
}
fputs("\n", fd);
if (TIFFFieldSet(tif,FIELD_MAXSAMPLEVALUE))
fprintf(fd, " Max Sample Value: %u\n", td->td_maxsamplevalue);
if (TIFFFieldSet(tif,FIELD_SMINSAMPLEVALUE)) {
+ int count = (tif->tif_flags & TIFF_PERSAMPLE) ? td->td_samplesperpixel : 1;
fprintf(fd, " SMin Sample Value:");
- for (i = 0; i < td->td_samplesperpixel; ++i)
+ for (i = 0; i < count; ++i)
fprintf(fd, " %g", td->td_sminsamplevalue[i]);
fprintf(fd, "\n");
}
if (TIFFFieldSet(tif,FIELD_SMAXSAMPLEVALUE)) {
+ int count = (tif->tif_flags & TIFF_PERSAMPLE) ? td->td_samplesperpixel : 1;
fprintf(fd, " SMax Sample Value:");
- for (i = 0; i < td->td_samplesperpixel; ++i)
+ for (i = 0; i < count; ++i)
fprintf(fd, " %g", td->td_smaxsamplevalue[i]);
fprintf(fd, "\n");
}
continue;
if(fip->field_passcount) {
- if(TIFFGetField(tif, tag, &value_count, &raw_data) != 1)
+ if (fip->field_readcount == TIFF_VARIABLE2 ) {
+ if(TIFFGetField(tif, tag, &value_count, &raw_data) != 1)
+ continue;
+ } else if (fip->field_readcount == TIFF_VARIABLE ) {
+ uint16 small_value_count;
+ if(TIFFGetField(tif, tag, &small_value_count, &raw_data) != 1)
+ continue;
+ value_count = small_value_count;
+ } else {
+ assert (fip->field_readcount == TIFF_VARIABLE
+ || fip->field_readcount == TIFF_VARIABLE2);
continue;
+ }
} else {
if (fip->field_readcount == TIFF_VARIABLE
|| fip->field_readcount == TIFF_VARIABLE2)
value_count = td->td_samplesperpixel;
else
value_count = fip->field_readcount;
- if ((fip->field_type == TIFF_ASCII
- || fip->field_readcount == TIFF_VARIABLE
- || fip->field_readcount == TIFF_VARIABLE2
- || fip->field_readcount == TIFF_SPP
- || value_count > 1)
- && fip->field_tag != TIFFTAG_PAGENUMBER
- && fip->field_tag != TIFFTAG_HALFTONEHINTS
- && fip->field_tag != TIFFTAG_YCBCRSUBSAMPLING
- && fip->field_tag != TIFFTAG_DOTRANGE) {
+ if (fip->field_tag == TIFFTAG_DOTRANGE
+ && strcmp(fip->field_name,"DotRange") == 0) {
+ /* TODO: This is an evil exception and should not have been
+ handled this way ... likely best if we move it into
+ the directory structure with an explicit field in
+ libtiff 4.1 and assign it a FIELD_ value */
+ static uint16 dotrange[2];
+ raw_data = dotrange;
+ TIFFGetField(tif, tag, dotrange+0, dotrange+1);
+ } else if (fip->field_type == TIFF_ASCII
+ || fip->field_readcount == TIFF_VARIABLE
+ || fip->field_readcount == TIFF_VARIABLE2
+ || fip->field_readcount == TIFF_SPP
+ || value_count > 1) {
if(TIFFGetField(tif, tag, &raw_data) != 1)
continue;
- } else if (fip->field_tag != TIFFTAG_PAGENUMBER
- && fip->field_tag != TIFFTAG_HALFTONEHINTS
- && fip->field_tag != TIFFTAG_YCBCRSUBSAMPLING
- && fip->field_tag != TIFFTAG_DOTRANGE) {
- raw_data = _TIFFmalloc(
- _TIFFDataSize(fip->field_type)
- * value_count);
- mem_alloc = 1;
- if(TIFFGetField(tif, tag, raw_data) != 1) {
- _TIFFfree(raw_data);
- continue;
- }
} else {
- /*
- * XXX: Should be fixed and removed,
- * see the notes related to
- * TIFFTAG_PAGENUMBER,
- * TIFFTAG_HALFTONEHINTS,
- * TIFFTAG_YCBCRSUBSAMPLING and
- * TIFFTAG_DOTRANGE tags in tif_dir.c.
- */
- char *tmp;
raw_data = _TIFFmalloc(
_TIFFDataSize(fip->field_type)
* value_count);
- tmp = raw_data;
mem_alloc = 1;
- if(TIFFGetField(tif, tag, tmp,
- tmp + _TIFFDataSize(fip->field_type)) != 1) {
+ if(TIFFGetField(tif, tag, raw_data) != 1) {
_TIFFfree(raw_data);
continue;
}
* _TIFFPrettyPrintField() fall down and print it as
* any other tag.
*/
- if (!_TIFFPrettyPrintField(tif, fd, tag, value_count, raw_data))
+ if (!_TIFFPrettyPrintField(tif, fip, fd, tag, value_count, raw_data))
_TIFFPrintField(fd, fip, value_count, raw_data);
if(mem_alloc)
void
_TIFFprintAscii(FILE* fd, const char* cp)
{
- for (; *cp != '\0'; cp++) {
+ _TIFFprintAsciiBounded( fd, cp, strlen(cp));
+}
+
+static void
+_TIFFprintAsciiBounded(FILE* fd, const char* cp, size_t max_chars)
+{
+ for (; max_chars > 0 && *cp != '\0'; cp++, max_chars--) {
const char* tp;
if (isprint((int)*cp)) {