~ubuntu-branches/ubuntu/saucy/tiff/saucy-security

« back to all changes in this revision

Viewing changes to libtiff/tif_print.c

  • Committer: Package Import Robot
  • Author(s): Jay Berkenbilt
  • Date: 2012-06-24 13:45:42 UTC
  • mfrom: (1.1.8)
  • mto: This revision was merged to the branch mainline in revision 26.
  • Revision ID: package-import@ubuntu.com-20120624134542-2xxi2i0ytrcddfdx
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: tif_print.c,v 1.54 2011-04-02 20:54:09 bfriesen Exp $ */
 
1
/* $Id: tif_print.c,v 1.59 2012-06-13 01:08:51 fwarmerdam Exp $ */
2
2
 
3
3
/*
4
4
 * Copyright (c) 1988-1997 Sam Leffler
34
34
 
35
35
#include <ctype.h>
36
36
 
 
37
static void
 
38
_TIFFprintAsciiBounded(FILE* fd, const char* cp, int max_chars);
 
39
 
37
40
static const char *photoNames[] = {
38
41
    "min-is-white",                             /* PHOTOMETRIC_MINISWHITE */
39
42
    "min-is-black",                             /* PHOTOMETRIC_MINISBLACK */
135
138
}
136
139
 
137
140
static int
138
 
_TIFFPrettyPrintField(TIFF* tif, FILE* fd, uint32 tag,
 
141
_TIFFPrettyPrintField(TIFF* tif, const TIFFField *fip, FILE* fd, uint32 tag,
139
142
                      uint32 value_count, void *raw_data)
140
143
{
141
144
        (void) tif;
 
145
 
 
146
        /* do not try to pretty print auto-defined fields */
 
147
        if (strncmp(fip->field_name,"Tag ", 4) == 0) {
 
148
                return 0;
 
149
        }
142
150
        
143
151
        switch (tag)
144
152
        {
145
153
                case TIFFTAG_INKSET:
146
 
                        fprintf(fd, "  Ink Set: ");
147
 
                        switch (*((uint16*)raw_data)) {
 
154
                        if (value_count == 2 && fip->field_type == TIFF_SHORT) {
 
155
                                fprintf(fd, "  Ink Set: ");
 
156
                                switch (*((uint16*)raw_data)) {
148
157
                                case INKSET_CMYK:
149
158
                                        fprintf(fd, "CMYK\n");
150
159
                                        break;
151
160
                                default:
152
161
                                        fprintf(fd, "%u (0x%x)\n",
153
 
                                            *((uint16*)raw_data),
154
 
                                            *((uint16*)raw_data));
 
162
                                                *((uint16*)raw_data),
 
163
                                                *((uint16*)raw_data));
155
164
                                        break;
 
165
                                }
 
166
                                return 1;
156
167
                        }
157
 
                        return 1;
 
168
                        return 0;
 
169
 
158
170
                case TIFFTAG_DOTRANGE:
159
 
                        fprintf(fd, "  Dot Range: %u-%u\n",
160
 
                            ((uint16*)raw_data)[0], ((uint16*)raw_data)[1]);
161
 
                        return 1;
 
171
                        if (value_count == 2 && fip->field_type == TIFF_SHORT) {
 
172
                                fprintf(fd, "  Dot Range: %u-%u\n",
 
173
                                        ((uint16*)raw_data)[0], ((uint16*)raw_data)[1]);
 
174
                                return 1;
 
175
                        }
 
176
                        return 0;
 
177
 
162
178
                case TIFFTAG_WHITEPOINT:
163
 
                        fprintf(fd, "  White Point: %g-%g\n",
164
 
                            ((float *)raw_data)[0], ((float *)raw_data)[1]);
165
 
                        return 1;
 
179
                        if (value_count == 2 && fip->field_type == TIFF_RATIONAL) {
 
180
                                fprintf(fd, "  White Point: %g-%g\n",
 
181
                                        ((float *)raw_data)[0], ((float *)raw_data)[1]);
 
182
                                return 1;
 
183
                        } 
 
184
                        return 0;
 
185
 
166
186
                case TIFFTAG_XMLPACKET:
167
187
                {
168
188
                        uint32 i;
182
202
                            "  RichTIFFIPTC Data: <present>, %lu bytes\n",
183
203
                            (unsigned long) value_count * 4);
184
204
                        return 1;
 
205
 
185
206
                case TIFFTAG_PHOTOSHOP:
186
207
                        fprintf(fd, "  Photoshop Data: <present>, %lu bytes\n",
187
208
                            (unsigned long) value_count);
188
209
                        return 1;
 
210
 
189
211
                case TIFFTAG_ICCPROFILE:
190
212
                        fprintf(fd, "  ICC Profile: <present>, %lu bytes\n",
191
213
                            (unsigned long) value_count);
192
214
                        return 1;
 
215
 
193
216
                case TIFFTAG_STONITS:
194
 
                        fprintf(fd,
195
 
                            "  Sample to Nits conversion factor: %.4e\n",
196
 
                            *((double*)raw_data));
197
 
                        return 1;
 
217
                        if (value_count == 1 && fip->field_type == TIFF_DOUBLE) { 
 
218
                                fprintf(fd,
 
219
                                        "  Sample to Nits conversion factor: %.4e\n",
 
220
                                        *((double*)raw_data));
 
221
                                return 1;
 
222
                        }
 
223
                        return 0;
198
224
        }
199
225
 
200
226
        return 0;
364
390
                fprintf(fd, "  Ink Names: ");
365
391
                i = td->td_samplesperpixel;
366
392
                sep = "";
367
 
                for (cp = td->td_inknames; i > 0; cp = strchr(cp,'\0')+1, i--) {
 
393
                for (cp = td->td_inknames; 
 
394
                     i > 0 && cp < td->td_inknames + td->td_inknameslen; 
 
395
                     cp = strchr(cp,'\0')+1, i--) {
 
396
                        int max_chars = 
 
397
                                td->td_inknameslen - (cp - td->td_inknames);
368
398
                        fputs(sep, fd);
369
 
                        _TIFFprintAscii(fd, cp);
 
399
                        _TIFFprintAsciiBounded(fd, cp, max_chars);
370
400
                        sep = ", ";
371
401
                }
372
402
                fputs("\n", fd);
449
479
        if (TIFFFieldSet(tif,FIELD_MAXSAMPLEVALUE))
450
480
                fprintf(fd, "  Max Sample Value: %u\n", td->td_maxsamplevalue);
451
481
        if (TIFFFieldSet(tif,FIELD_SMINSAMPLEVALUE)) {
 
482
                int count = (tif->tif_flags & TIFF_PERSAMPLE) ? td->td_samplesperpixel : 1;
452
483
                fprintf(fd, "  SMin Sample Value:");
453
 
                for (i = 0; i < td->td_samplesperpixel; ++i)
 
484
                for (i = 0; i < count; ++i)
454
485
                        fprintf(fd, " %g", td->td_sminsamplevalue[i]);
455
486
                fprintf(fd, "\n");
456
487
        }
457
488
        if (TIFFFieldSet(tif,FIELD_SMAXSAMPLEVALUE)) {
 
489
                int count = (tif->tif_flags & TIFF_PERSAMPLE) ? td->td_samplesperpixel : 1;
458
490
                fprintf(fd, "  SMax Sample Value:");
459
 
                for (i = 0; i < td->td_samplesperpixel; ++i)
 
491
                for (i = 0; i < count; ++i)
460
492
                        fprintf(fd, " %g", td->td_smaxsamplevalue[i]);
461
493
                fprintf(fd, "\n");
462
494
        }
548
580
                                continue;
549
581
 
550
582
                        if(fip->field_passcount) {
551
 
                                if(TIFFGetField(tif, tag, &value_count, &raw_data) != 1)
 
583
                                if (fip->field_readcount == TIFF_VARIABLE2 ) {
 
584
                                        if(TIFFGetField(tif, tag, &value_count, &raw_data) != 1)
 
585
                                                continue;
 
586
                                } else if (fip->field_readcount == TIFF_VARIABLE2 ) {
 
587
                                        uint16 small_value_count;
 
588
                                        if(TIFFGetField(tif, tag, &small_value_count, &raw_data) != 1)
 
589
                                                continue;
 
590
                                        value_count = small_value_count;
 
591
                                } else {
 
592
                                        assert (fip->field_readcount == TIFF_VARIABLE
 
593
                                                || fip->field_readcount == TIFF_VARIABLE2);
552
594
                                        continue;
 
595
                                } 
553
596
                        } else {
554
597
                                if (fip->field_readcount == TIFF_VARIABLE
555
598
                                    || fip->field_readcount == TIFF_VARIABLE2)
558
601
                                        value_count = td->td_samplesperpixel;
559
602
                                else
560
603
                                        value_count = fip->field_readcount;
561
 
                                if ((fip->field_type == TIFF_ASCII
562
 
                                    || fip->field_readcount == TIFF_VARIABLE
563
 
                                    || fip->field_readcount == TIFF_VARIABLE2
564
 
                                    || fip->field_readcount == TIFF_SPP
565
 
                                    || value_count > 1)
566
 
                                    && fip->field_tag != TIFFTAG_PAGENUMBER
567
 
                                    && fip->field_tag != TIFFTAG_HALFTONEHINTS
568
 
                                    && fip->field_tag != TIFFTAG_YCBCRSUBSAMPLING
569
 
                                    && fip->field_tag != TIFFTAG_DOTRANGE) {
 
604
                                if (fip->field_tag == TIFFTAG_DOTRANGE
 
605
                                    && strcmp(fip->field_name,"DotRange") == 0) {
 
606
                                        /* TODO: This is an evil exception and should not have been
 
607
                                           handled this way ... likely best if we move it into
 
608
                                           the directory structure with an explicit field in 
 
609
                                           libtiff 4.1 and assign it a FIELD_ value */
 
610
                                        static uint16 dotrange[2];
 
611
                                        raw_data = dotrange;
 
612
                                        TIFFGetField(tif, tag, dotrange+0, dotrange+1);
 
613
                                } else if (fip->field_type == TIFF_ASCII
 
614
                                           || fip->field_readcount == TIFF_VARIABLE
 
615
                                           || fip->field_readcount == TIFF_VARIABLE2
 
616
                                           || fip->field_readcount == TIFF_SPP
 
617
                                           || value_count > 1) {
570
618
                                        if(TIFFGetField(tif, tag, &raw_data) != 1)
571
619
                                                continue;
572
 
                                } else if (fip->field_tag != TIFFTAG_PAGENUMBER
573
 
                                    && fip->field_tag != TIFFTAG_HALFTONEHINTS
574
 
                                    && fip->field_tag != TIFFTAG_YCBCRSUBSAMPLING
575
 
                                    && fip->field_tag != TIFFTAG_DOTRANGE) {
 
620
                                } else {
576
621
                                        raw_data = _TIFFmalloc(
577
622
                                            _TIFFDataSize(fip->field_type)
578
623
                                            * value_count);
581
626
                                                _TIFFfree(raw_data);
582
627
                                                continue;
583
628
                                        }
584
 
                                } else {
585
 
                                        /*
586
 
                                         * XXX: Should be fixed and removed,
587
 
                                         * see the notes related to
588
 
                                         * TIFFTAG_PAGENUMBER,
589
 
                                         * TIFFTAG_HALFTONEHINTS,
590
 
                                         * TIFFTAG_YCBCRSUBSAMPLING and
591
 
                                         * TIFFTAG_DOTRANGE tags in tif_dir.c.
592
 
                                         */
593
 
                                        char *tmp;
594
 
                                        raw_data = _TIFFmalloc(
595
 
                                            _TIFFDataSize(fip->field_type)
596
 
                                            * value_count);
597
 
                                        tmp = raw_data;
598
 
                                        mem_alloc = 1;
599
 
                                        if(TIFFGetField(tif, tag, tmp,
600
 
                                            tmp + _TIFFDataSize(fip->field_type)) != 1) {
601
 
                                                _TIFFfree(raw_data);
602
 
                                                continue;
603
 
                                        }
604
629
                                }
605
630
                        }
606
631
 
610
635
                         * _TIFFPrettyPrintField() fall down and print it as
611
636
                         * any other tag.
612
637
                         */
613
 
                        if (!_TIFFPrettyPrintField(tif, fd, tag, value_count, raw_data))
 
638
                        if (!_TIFFPrettyPrintField(tif, fip, fd, tag, value_count, raw_data))
614
639
                                _TIFFPrintField(fd, fip, value_count, raw_data);
615
640
 
616
641
                        if(mem_alloc)
648
673
void
649
674
_TIFFprintAscii(FILE* fd, const char* cp)
650
675
{
651
 
        for (; *cp != '\0'; cp++) {
 
676
        _TIFFprintAsciiBounded( fd, cp, strlen(cp));
 
677
}
 
678
 
 
679
static void
 
680
_TIFFprintAsciiBounded(FILE* fd, const char* cp, int max_chars)
 
681
{
 
682
        for (; max_chars > 0 && *cp != '\0'; cp++, max_chars--) {
652
683
                const char* tp;
653
684
 
654
685
                if (isprint((int)*cp)) {