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