1 /*
2 * Copyright (c) 2004, Andrey Kiselev <dron@ak4719.spb.edu>
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and
5 * its documentation for any purpose is hereby granted without fee, provided
6 * that (i) the above copyright notices and this permission notice appear in
7 * all copies of the software and related documentation, and (ii) the names of
8 * Sam Leffler and Silicon Graphics may not be used in any advertising or
9 * publicity relating to the software without the specific, prior written
10 * permission of Sam Leffler and Silicon Graphics.
11 *
12 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
13 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
14 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
15 *
16 * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
17 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
18 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
19 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
20 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
21 * OF THIS SOFTWARE.
22 */
23
24 /*
25 * TIFF Library
26 *
27 * Test libtiff input/output routines.
28 */
29
30 #include "tif_config.h"
31
32 #include <stdio.h>
33
34 #ifdef HAVE_UNISTD_H
35 # include <unistd.h>
36 #endif
37
38 #include "tiffio.h"
39 #include "test_arrays.h"
40
41 extern int
42 create_image_striped(const char *, uint32, uint32, uint32, uint16, uint16,
43 uint16, uint16, uint16, uint16, const tdata_t,
44 const tsize_t);
45 extern int
46 read_image_striped(const char *, uint32, uint32, uint32, uint16, uint16,
47 uint16, uint16, uint16, uint16, const tdata_t,
48 const tsize_t);
49
50 const char *filename = "strip_test.tiff";
51
52 int
main(int argc,char ** argv)53 main(int argc, char **argv)
54 {
55 uint32 rowsperstrip;
56 uint16 compression;
57 uint16 spp, bps, photometric, sampleformat, planarconfig;
58 (void) argc;
59 (void) argv;
60
61 /*
62 * Test two special cases: image consisting from single line and image
63 * consisting from single column.
64 */
65 rowsperstrip = 1;
66 compression = COMPRESSION_NONE;
67 spp = 1;
68 bps = 8;
69 photometric = PHOTOMETRIC_MINISBLACK;
70 sampleformat = SAMPLEFORMAT_UINT;
71 planarconfig = PLANARCONFIG_CONTIG;
72
73 if (create_image_striped(filename, XSIZE * YSIZE, 1, rowsperstrip,
74 compression, spp, bps, photometric,
75 sampleformat, planarconfig,
76 (const tdata_t) byte_array1, byte_array1_size) < 0) {
77 fprintf (stderr, "Can't create TIFF file %s.\n", filename);
78 goto failure;
79 }
80 if (read_image_striped(filename, XSIZE * YSIZE, 1, rowsperstrip,
81 compression, spp, bps, photometric,
82 sampleformat, planarconfig,
83 (const tdata_t) byte_array1, byte_array1_size) < 0) {
84 fprintf (stderr, "Can't read TIFF file %s.\n", filename);
85 goto failure;
86 }
87 unlink(filename);
88
89 if (create_image_striped(filename, 1, XSIZE * YSIZE, rowsperstrip,
90 compression, spp, bps, photometric,
91 sampleformat, planarconfig,
92 (const tdata_t) byte_array1, byte_array1_size) < 0) {
93 fprintf (stderr, "Can't create TIFF file %s.\n", filename);
94 goto failure;
95 }
96 if (read_image_striped(filename, 1, XSIZE * YSIZE, rowsperstrip,
97 compression, spp, bps, photometric,
98 sampleformat, planarconfig,
99 (const tdata_t) byte_array1, byte_array1_size) < 0) {
100 fprintf (stderr, "Can't read TIFF file %s.\n", filename);
101 goto failure;
102 }
103 unlink(filename);
104
105 /*
106 * Test one-channel image with different parameters.
107 */
108 rowsperstrip = 1;
109 spp = 1;
110 bps = 8;
111 photometric = PHOTOMETRIC_MINISBLACK;
112 sampleformat = SAMPLEFORMAT_UINT;
113 planarconfig = PLANARCONFIG_CONTIG;
114
115 if (create_image_striped(filename, XSIZE, YSIZE, rowsperstrip,
116 compression, spp, bps, photometric,
117 sampleformat, planarconfig,
118 (const tdata_t) byte_array1, byte_array1_size) < 0) {
119 fprintf (stderr, "Can't create TIFF file %s.\n", filename);
120 goto failure;
121 }
122 if (read_image_striped(filename, XSIZE, YSIZE, rowsperstrip,
123 compression, spp, bps, photometric,
124 sampleformat, planarconfig,
125 (const tdata_t) byte_array1, byte_array1_size) < 0) {
126 fprintf (stderr, "Can't read TIFF file %s.\n", filename);
127 goto failure;
128 }
129 unlink(filename);
130
131 rowsperstrip = YSIZE;
132 if (create_image_striped(filename, XSIZE, YSIZE, rowsperstrip,
133 compression, spp, bps, photometric,
134 sampleformat, planarconfig,
135 (const tdata_t) byte_array1, byte_array1_size) < 0) {
136 fprintf (stderr, "Can't create TIFF file %s.\n", filename);
137 goto failure;
138 }
139 if (read_image_striped(filename, XSIZE, YSIZE, rowsperstrip,
140 compression, spp, bps, photometric,
141 sampleformat, planarconfig,
142 (const tdata_t) byte_array1, byte_array1_size) < 0) {
143 fprintf (stderr, "Can't read TIFF file %s.\n", filename);
144 goto failure;
145 }
146 unlink(filename);
147
148 return 0;
149
150 failure:
151 unlink(filename);
152 return 1;
153 }
154
155 /* vim: set ts=8 sts=8 sw=8 noet: */
156