]> git.saurik.com Git - wxWidgets.git/blob - src/tiff/test/short_tag.c
Use wxMarkupParser in wxStaticText for dealing with markup.
[wxWidgets.git] / src / tiff / test / short_tag.c
1 /* $Id$ */
2
3 /*
4 * Copyright (c) 2004, Andrey Kiselev <dron@ak4719.spb.edu>
5 *
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.
13 *
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.
17 *
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
23 * OF THIS SOFTWARE.
24 */
25
26 /*
27 * TIFF Library
28 *
29 * Module to test SHORT tags read/write functions.
30 */
31
32 #include "tif_config.h"
33
34 #include <stdio.h>
35
36 #ifdef HAVE_UNISTD_H
37 # include <unistd.h>
38 #endif
39
40 #include "tiffio.h"
41
42 extern int CheckShortField(TIFF *, ttag_t, uint16);
43
44 const char *filename = "short_test.tiff";
45
46 #define SPP 3 /* Samples per pixel */
47 const uint16 width = 1;
48 const uint16 length = 1;
49 const uint16 bps = 8;
50 const uint16 photometric = PHOTOMETRIC_RGB;
51 const uint16 rows_per_strip = 1;
52 const uint16 planarconfig = PLANARCONFIG_CONTIG;
53
54 static struct SingleTags {
55 ttag_t tag;
56 uint16 value;
57 } short_single_tags[] = {
58 { TIFFTAG_COMPRESSION, COMPRESSION_NONE },
59 { TIFFTAG_FILLORDER, FILLORDER_MSB2LSB },
60 { TIFFTAG_ORIENTATION, ORIENTATION_BOTRIGHT },
61 { TIFFTAG_RESOLUTIONUNIT, RESUNIT_INCH },
62 { TIFFTAG_INKSET, INKSET_MULTIINK },
63 { TIFFTAG_MINSAMPLEVALUE, 23 },
64 { TIFFTAG_MAXSAMPLEVALUE, 241 },
65 { TIFFTAG_NUMBEROFINKS, SPP },
66 { TIFFTAG_SAMPLEFORMAT, SAMPLEFORMAT_UINT }
67 /*{ TIFFTAG_IMAGEDEPTH, 1 },
68 { TIFFTAG_TILEDEPTH, 1 }*/
69 };
70 #define NSINGLETAGS (sizeof(short_single_tags) / sizeof(short_single_tags[0]))
71
72 int
73 main(int argc, char **argv)
74 {
75 TIFF *tif;
76 int i;
77 unsigned char buf[3] = { 0, 127, 255 };
78
79 /* Test whether we can write tags. */
80 tif = TIFFOpen(filename, "w");
81 if (!tif) {
82 fprintf (stderr, "Can't create test TIFF file %s.\n", filename);
83 return 1;
84 }
85
86 if (!TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, width)) {
87 fprintf (stderr, "Can't set ImageWidth tag.\n");
88 goto failure;
89 }
90 if (!TIFFSetField(tif, TIFFTAG_IMAGELENGTH, length)) {
91 fprintf (stderr, "Can't set ImageLength tag.\n");
92 goto failure;
93 }
94 if (!TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, bps)) {
95 fprintf (stderr, "Can't set BitsPerSample tag.\n");
96 goto failure;
97 }
98 if (!TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, SPP)) {
99 fprintf (stderr, "Can't set SamplesPerPixel tag.\n");
100 goto failure;
101 }
102 if (!TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, rows_per_strip)) {
103 fprintf (stderr, "Can't set SamplesPerPixel tag.\n");
104 goto failure;
105 }
106 if (!TIFFSetField(tif, TIFFTAG_PLANARCONFIG, planarconfig)) {
107 fprintf (stderr, "Can't set PlanarConfiguration tag.\n");
108 goto failure;
109 }
110 if (!TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, photometric)) {
111 fprintf (stderr, "Can't set PhotometricInterpretation tag.\n");
112 goto failure;
113 }
114
115 for (i = 0; i < NSINGLETAGS; i++) {
116 if (!TIFFSetField(tif, short_single_tags[i].tag,
117 short_single_tags[i].value)) {
118 fprintf(stderr, "Can't set tag %d.\n",
119 (int)short_single_tags[i].tag);
120 goto failure;
121 }
122 }
123
124 /* Write dummy pixel data. */
125 if (!TIFFWriteScanline(tif, buf, 0, 0) < 0) {
126 fprintf (stderr, "Can't write image data.\n");
127 goto failure;
128 }
129
130 TIFFClose(tif);
131
132 /* Ok, now test whether we can read written values. */
133 tif = TIFFOpen(filename, "r");
134 if (!tif) {
135 fprintf (stderr, "Can't open test TIFF file %s.\n", filename);
136 return 1;
137 }
138
139 if (CheckLongField(tif, TIFFTAG_IMAGEWIDTH, width) < 0)
140 goto failure;
141
142 if (CheckLongField(tif, TIFFTAG_IMAGELENGTH, length) < 0)
143 goto failure;
144
145 if (CheckShortField(tif, TIFFTAG_BITSPERSAMPLE, bps) < 0)
146 goto failure;
147
148 if (CheckShortField(tif, TIFFTAG_PHOTOMETRIC, photometric) < 0)
149 goto failure;
150
151 if (CheckShortField(tif, TIFFTAG_SAMPLESPERPIXEL, SPP) < 0)
152 goto failure;
153
154 if (CheckLongField(tif, TIFFTAG_ROWSPERSTRIP, rows_per_strip) < 0)
155 goto failure;
156
157 if (CheckShortField(tif, TIFFTAG_PLANARCONFIG, planarconfig) < 0)
158 goto failure;
159
160 for (i = 0; i < NSINGLETAGS; i++) {
161 if (CheckShortField(tif, short_single_tags[i].tag,
162 short_single_tags[i].value) < 0)
163 goto failure;
164 }
165
166 TIFFClose(tif);
167
168 /* All tests passed; delete file and exit with success status. */
169 unlink(filename);
170 return 0;
171
172 failure:
173 /* Something goes wrong; close file and return unsuccessful status. */
174 TIFFClose(tif);
175 unlink(filename);
176 return 1;
177 }
178
179 /* vim: set ts=8 sts=8 sw=8 noet: */