]>
Commit | Line | Data |
---|---|---|
8414a40c VZ |
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 LONG 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 CheckLongField(TIFF *, ttag_t, uint32); | |
43 | ||
44 | const char *filename = "long_test.tiff"; | |
45 | ||
46 | static struct Tags { | |
47 | ttag_t tag; | |
48 | short count; | |
49 | uint32 value; | |
50 | } long_tags[] = { | |
51 | { TIFFTAG_SUBFILETYPE, 1, FILETYPE_REDUCEDIMAGE|FILETYPE_PAGE|FILETYPE_MASK } | |
52 | }; | |
53 | #define NTAGS (sizeof (long_tags) / sizeof (long_tags[0])) | |
54 | ||
55 | const uint32 width = 1; | |
56 | const uint32 length = 1; | |
57 | const uint32 rows_per_strip = 1; | |
58 | ||
59 | int | |
60 | main(int argc, char **argv) | |
61 | { | |
62 | TIFF *tif; | |
80ed523f | 63 | unsigned int i; |
8414a40c | 64 | unsigned char buf[3] = { 0, 127, 255 }; |
80ed523f VZ |
65 | (void) argc; |
66 | (void) argv; | |
8414a40c VZ |
67 | |
68 | /* Test whether we can write tags. */ | |
69 | tif = TIFFOpen(filename, "w"); | |
70 | if (!tif) { | |
71 | fprintf (stderr, "Can't create test TIFF file %s.\n", filename); | |
72 | return 1; | |
73 | } | |
74 | ||
75 | if (!TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, width)) { | |
76 | fprintf (stderr, "Can't set ImageWidth tag.\n"); | |
77 | goto failure; | |
78 | } | |
79 | if (!TIFFSetField(tif, TIFFTAG_IMAGELENGTH, length)) { | |
80 | fprintf (stderr, "Can't set ImageLength tag.\n"); | |
81 | goto failure; | |
82 | } | |
83 | if (!TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 8)) { | |
84 | fprintf (stderr, "Can't set BitsPerSample tag.\n"); | |
85 | goto failure; | |
86 | } | |
87 | if (!TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 3)) { | |
88 | fprintf (stderr, "Can't set SamplesPerPixel tag.\n"); | |
89 | goto failure; | |
90 | } | |
91 | if (!TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, rows_per_strip)) { | |
92 | fprintf (stderr, "Can't set SamplesPerPixel tag.\n"); | |
93 | goto failure; | |
94 | } | |
95 | if (!TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG)) { | |
96 | fprintf (stderr, "Can't set PlanarConfiguration tag.\n"); | |
97 | goto failure; | |
98 | } | |
99 | if (!TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB)) { | |
100 | fprintf (stderr, "Can't set PhotometricInterpretation tag.\n"); | |
101 | goto failure; | |
102 | } | |
103 | ||
104 | for (i = 0; i < NTAGS; i++) { | |
105 | if (!TIFFSetField(tif, long_tags[i].tag, | |
106 | long_tags[i].value)) { | |
107 | fprintf(stderr, "Can't set tag %d.\n", | |
108 | (int)long_tags[i].tag); | |
109 | goto failure; | |
110 | } | |
111 | } | |
112 | ||
113 | /* Write dummy pixel data. */ | |
114 | if (!TIFFWriteScanline(tif, buf, 0, 0) < 0) { | |
115 | fprintf (stderr, "Can't write image data.\n"); | |
116 | goto failure; | |
117 | } | |
118 | ||
119 | TIFFClose(tif); | |
120 | ||
121 | /* Ok, now test whether we can read written values. */ | |
122 | tif = TIFFOpen(filename, "r"); | |
123 | if (!tif) { | |
124 | fprintf (stderr, "Can't open test TIFF file %s.\n", filename); | |
125 | return 1; | |
126 | } | |
127 | ||
128 | if (CheckLongField(tif, TIFFTAG_IMAGEWIDTH, width) < 0) | |
129 | goto failure; | |
130 | ||
131 | if (CheckLongField(tif, TIFFTAG_IMAGELENGTH, length) < 0) | |
132 | goto failure; | |
133 | ||
134 | if (CheckLongField(tif, TIFFTAG_ROWSPERSTRIP, rows_per_strip) < 0) | |
135 | goto failure; | |
136 | ||
137 | for (i = 0; i < NTAGS; i++) { | |
138 | if (CheckLongField(tif, long_tags[i].tag, | |
139 | long_tags[i].value) < 0) | |
140 | goto failure; | |
141 | } | |
142 | ||
143 | TIFFClose(tif); | |
144 | ||
145 | /* All tests passed; delete file and exit with success status. */ | |
146 | unlink(filename); | |
147 | return 0; | |
148 | ||
149 | failure: | |
150 | /* Something goes wrong; close file and return unsuccessful status. */ | |
151 | TIFFClose(tif); | |
152 | unlink(filename); | |
153 | return 1; | |
154 | } | |
155 | ||
156 | /* vim: set ts=8 sts=8 sw=8 noet: */ |