]>
git.saurik.com Git - wxWidgets.git/blob - src/tiff/test/short_tag.c
3 * Copyright (c) 2004, Andrey Kiselev <dron@ak4719.spb.edu>
5 * Permission to use, copy, modify, distribute, and sell this software and
6 * its documentation for any purpose is hereby granted without fee, provided
7 * that (i) the above copyright notices and this permission notice appear in
8 * all copies of the software and related documentation, and (ii) the names of
9 * Sam Leffler and Silicon Graphics may not be used in any advertising or
10 * publicity relating to the software without the specific, prior written
11 * permission of Sam Leffler and Silicon Graphics.
13 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
14 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
15 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
17 * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
18 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
19 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
20 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
21 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
28 * Module to test SHORT tags read/write functions.
31 #include "tif_config.h"
42 static const char filename
[] = "short_test.tiff";
44 #define SPP 3 /* Samples per pixel */
45 const uint16 width
= 1;
46 const uint16 length
= 1;
48 const uint16 photometric
= PHOTOMETRIC_RGB
;
49 const uint16 rows_per_strip
= 1;
50 const uint16 planarconfig
= PLANARCONFIG_CONTIG
;
55 } short_single_tags
[] = {
56 { TIFFTAG_COMPRESSION
, COMPRESSION_NONE
},
57 { TIFFTAG_FILLORDER
, FILLORDER_MSB2LSB
},
58 { TIFFTAG_ORIENTATION
, ORIENTATION_BOTRIGHT
},
59 { TIFFTAG_RESOLUTIONUNIT
, RESUNIT_INCH
},
60 { TIFFTAG_MINSAMPLEVALUE
, 23 },
61 { TIFFTAG_MAXSAMPLEVALUE
, 241 },
62 { TIFFTAG_INKSET
, INKSET_MULTIINK
},
63 { TIFFTAG_NUMBEROFINKS
, SPP
},
64 { TIFFTAG_SAMPLEFORMAT
, SAMPLEFORMAT_UINT
}
66 #define NSINGLETAGS (sizeof(short_single_tags) / sizeof(short_single_tags[0]))
70 const uint16 values
[2];
71 } short_paired_tags
[] = {
72 { TIFFTAG_PAGENUMBER
, {1, 1} },
73 { TIFFTAG_HALFTONEHINTS
, {0, 255} },
74 { TIFFTAG_DOTRANGE
, {8, 16} },
75 { TIFFTAG_YCBCRSUBSAMPLING
, {2, 1} }
77 #define NPAIREDTAGS (sizeof(short_paired_tags) / sizeof(short_paired_tags[0]))
84 unsigned char buf
[SPP
] = { 0, 127, 255 };
86 /* Test whether we can write tags. */
87 tif
= TIFFOpen(filename
, "w");
89 fprintf (stderr
, "Can't create test TIFF file %s.\n", filename
);
93 if (!TIFFSetField(tif
, TIFFTAG_IMAGEWIDTH
, width
)) {
94 fprintf (stderr
, "Can't set ImageWidth tag.\n");
97 if (!TIFFSetField(tif
, TIFFTAG_IMAGELENGTH
, length
)) {
98 fprintf (stderr
, "Can't set ImageLength tag.\n");
101 if (!TIFFSetField(tif
, TIFFTAG_BITSPERSAMPLE
, bps
)) {
102 fprintf (stderr
, "Can't set BitsPerSample tag.\n");
105 if (!TIFFSetField(tif
, TIFFTAG_SAMPLESPERPIXEL
, SPP
)) {
106 fprintf (stderr
, "Can't set SamplesPerPixel tag.\n");
109 if (!TIFFSetField(tif
, TIFFTAG_ROWSPERSTRIP
, rows_per_strip
)) {
110 fprintf (stderr
, "Can't set SamplesPerPixel tag.\n");
113 if (!TIFFSetField(tif
, TIFFTAG_PLANARCONFIG
, planarconfig
)) {
114 fprintf (stderr
, "Can't set PlanarConfiguration tag.\n");
117 if (!TIFFSetField(tif
, TIFFTAG_PHOTOMETRIC
, photometric
)) {
118 fprintf (stderr
, "Can't set PhotometricInterpretation tag.\n");
122 for (i
= 0; i
< NSINGLETAGS
; i
++) {
123 if (!TIFFSetField(tif
, short_single_tags
[i
].tag
,
124 short_single_tags
[i
].value
)) {
125 fprintf(stderr
, "Can't set tag %lu.\n",
126 (unsigned long)short_single_tags
[i
].tag
);
131 for (i
= 0; i
< NPAIREDTAGS
; i
++) {
132 if (!TIFFSetField(tif
, short_paired_tags
[i
].tag
,
133 short_paired_tags
[i
].values
[0],
134 short_paired_tags
[i
].values
[1])) {
135 fprintf(stderr
, "Can't set tag %lu.\n",
136 (unsigned long)short_paired_tags
[i
].tag
);
141 /* Write dummy pixel data. */
142 if (!TIFFWriteScanline(tif
, buf
, 0, 0) < 0) {
143 fprintf (stderr
, "Can't write image data.\n");
149 /* Ok, now test whether we can read written values. */
150 tif
= TIFFOpen(filename
, "r");
152 fprintf (stderr
, "Can't open test TIFF file %s.\n", filename
);
156 if (CheckLongField(tif
, TIFFTAG_IMAGEWIDTH
, width
) < 0)
159 if (CheckLongField(tif
, TIFFTAG_IMAGELENGTH
, length
) < 0)
162 if (CheckShortField(tif
, TIFFTAG_BITSPERSAMPLE
, bps
) < 0)
165 if (CheckShortField(tif
, TIFFTAG_PHOTOMETRIC
, photometric
) < 0)
168 if (CheckShortField(tif
, TIFFTAG_SAMPLESPERPIXEL
, SPP
) < 0)
171 if (CheckLongField(tif
, TIFFTAG_ROWSPERSTRIP
, rows_per_strip
) < 0)
174 if (CheckShortField(tif
, TIFFTAG_PLANARCONFIG
, planarconfig
) < 0)
177 for (i
= 0; i
< NSINGLETAGS
; i
++) {
178 if (CheckShortField(tif
, short_single_tags
[i
].tag
,
179 short_single_tags
[i
].value
) < 0)
183 for (i
= 0; i
< NPAIREDTAGS
; i
++) {
184 if (CheckShortPairedField(tif
, short_paired_tags
[i
].tag
,
185 short_paired_tags
[i
].values
) < 0)
191 /* All tests passed; delete file and exit with success status. */
197 * Something goes wrong; close file and return unsuccessful status.
198 * Do not remove the file for further manual investigation.
204 /* vim: set ts=8 sts=8 sw=8 noet: */