Document domain parameter of wxTranslations::GetTranslatedString().
[wxWidgets.git] / src / tiff / test / short_tag.c
1
2 /*
3 * Copyright (c) 2004, Andrey Kiselev <dron@ak4719.spb.edu>
4 *
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.
12 *
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.
16 *
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
22 * OF THIS SOFTWARE.
23 */
24
25 /*
26 * TIFF Library
27 *
28 * Module to test SHORT tags read/write functions.
29 */
30
31 #include "tif_config.h"
32
33 #include <stdio.h>
34
35 #ifdef HAVE_UNISTD_H
36 # include <unistd.h>
37 #endif
38
39 #include "tiffio.h"
40 #include "tifftest.h"
41
42 static const char filename[] = "short_test.tiff";
43
44 #define SPP 3 /* Samples per pixel */
45 const uint16 width = 1;
46 const uint16 length = 1;
47 const uint16 bps = 8;
48 const uint16 photometric = PHOTOMETRIC_RGB;
49 const uint16 rows_per_strip = 1;
50 const uint16 planarconfig = PLANARCONFIG_CONTIG;
51
52 static const struct {
53 const ttag_t tag;
54 const uint16 value;
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 }
65 };
66 #define NSINGLETAGS (sizeof(short_single_tags) / sizeof(short_single_tags[0]))
67
68 static const struct {
69 const ttag_t tag;
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} }
76 };
77 #define NPAIREDTAGS (sizeof(short_paired_tags) / sizeof(short_paired_tags[0]))
78
79 int
80 main()
81 {
82 TIFF *tif;
83 size_t i;
84 unsigned char buf[SPP] = { 0, 127, 255 };
85
86 /* Test whether we can write tags. */
87 tif = TIFFOpen(filename, "w");
88 if (!tif) {
89 fprintf (stderr, "Can't create test TIFF file %s.\n", filename);
90 return 1;
91 }
92
93 if (!TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, width)) {
94 fprintf (stderr, "Can't set ImageWidth tag.\n");
95 goto failure;
96 }
97 if (!TIFFSetField(tif, TIFFTAG_IMAGELENGTH, length)) {
98 fprintf (stderr, "Can't set ImageLength tag.\n");
99 goto failure;
100 }
101 if (!TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, bps)) {
102 fprintf (stderr, "Can't set BitsPerSample tag.\n");
103 goto failure;
104 }
105 if (!TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, SPP)) {
106 fprintf (stderr, "Can't set SamplesPerPixel tag.\n");
107 goto failure;
108 }
109 if (!TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, rows_per_strip)) {
110 fprintf (stderr, "Can't set SamplesPerPixel tag.\n");
111 goto failure;
112 }
113 if (!TIFFSetField(tif, TIFFTAG_PLANARCONFIG, planarconfig)) {
114 fprintf (stderr, "Can't set PlanarConfiguration tag.\n");
115 goto failure;
116 }
117 if (!TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, photometric)) {
118 fprintf (stderr, "Can't set PhotometricInterpretation tag.\n");
119 goto failure;
120 }
121
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);
127 goto failure;
128 }
129 }
130
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);
137 goto failure;
138 }
139 }
140
141 /* Write dummy pixel data. */
142 if (!TIFFWriteScanline(tif, buf, 0, 0) < 0) {
143 fprintf (stderr, "Can't write image data.\n");
144 goto failure;
145 }
146
147 TIFFClose(tif);
148
149 /* Ok, now test whether we can read written values. */
150 tif = TIFFOpen(filename, "r");
151 if (!tif) {
152 fprintf (stderr, "Can't open test TIFF file %s.\n", filename);
153 return 1;
154 }
155
156 if (CheckLongField(tif, TIFFTAG_IMAGEWIDTH, width) < 0)
157 goto failure;
158
159 if (CheckLongField(tif, TIFFTAG_IMAGELENGTH, length) < 0)
160 goto failure;
161
162 if (CheckShortField(tif, TIFFTAG_BITSPERSAMPLE, bps) < 0)
163 goto failure;
164
165 if (CheckShortField(tif, TIFFTAG_PHOTOMETRIC, photometric) < 0)
166 goto failure;
167
168 if (CheckShortField(tif, TIFFTAG_SAMPLESPERPIXEL, SPP) < 0)
169 goto failure;
170
171 if (CheckLongField(tif, TIFFTAG_ROWSPERSTRIP, rows_per_strip) < 0)
172 goto failure;
173
174 if (CheckShortField(tif, TIFFTAG_PLANARCONFIG, planarconfig) < 0)
175 goto failure;
176
177 for (i = 0; i < NSINGLETAGS; i++) {
178 if (CheckShortField(tif, short_single_tags[i].tag,
179 short_single_tags[i].value) < 0)
180 goto failure;
181 }
182
183 for (i = 0; i < NPAIREDTAGS; i++) {
184 if (CheckShortPairedField(tif, short_paired_tags[i].tag,
185 short_paired_tags[i].values) < 0)
186 goto failure;
187 }
188
189 TIFFClose(tif);
190
191 /* All tests passed; delete file and exit with success status. */
192 unlink(filename);
193 return 0;
194
195 failure:
196 /*
197 * Something goes wrong; close file and return unsuccessful status.
198 * Do not remove the file for further manual investigation.
199 */
200 TIFFClose(tif);
201 return 1;
202 }
203
204 /* vim: set ts=8 sts=8 sw=8 noet: */