Debian Codegraph @

texk/xdvipsk/thirdparty/libtiff/test/strip_rw.c

raw
1 /*
2 * Copyright (c) 2004, Andrey Kiselev <[email protected]>
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 "test_arrays.h"
39 #include "tiffio.h"
40
41 extern int create_image_striped(const char *, uint32_t, uint32_t, uint32_t,
42 uint16_t, uint16_t, uint16_t, uint16_t,
43 uint16_t, uint16_t, const tdata_t,
44 const tsize_t);
45 extern int read_image_striped(const char *, uint32_t, uint32_t, uint32_t,
46 uint16_t, uint16_t, uint16_t, uint16_t, uint16_t,
47 uint16_t, const tdata_t, const tsize_t);
48
49 const char *filename = "strip_test.tiff";
50
51 int main(int argc, char **argv)
52 {
53 uint32_t rowsperstrip;
54 uint16_t compression;
55 uint16_t spp, bps, photometric, sampleformat, planarconfig;
56 (void)argc;
57 (void)argv;
58
59 /*
60 * Test two special cases: image consisting from single line and image
61 * consisting from single column.
62 */
63 rowsperstrip = 1;
64 compression = COMPRESSION_NONE;
65 spp = 1;
66 bps = 8;
67 photometric = PHOTOMETRIC_MINISBLACK;
68 sampleformat = SAMPLEFORMAT_UINT;
69 planarconfig = PLANARCONFIG_CONTIG;
70
71 if (create_image_striped(filename, XSIZE * YSIZE, 1, rowsperstrip,
72 compression, spp, bps, photometric, sampleformat,
73 planarconfig, (const tdata_t)byte_array1,
74 byte_array1_size) < 0)
75 {
76 fprintf(stderr, "Can't create TIFF file %s.\n", filename);
77 goto failure;
78 }
79 if (read_image_striped(filename, XSIZE * YSIZE, 1, rowsperstrip,
80 compression, spp, bps, photometric, sampleformat,
81 planarconfig, (const tdata_t)byte_array1,
82 byte_array1_size) < 0)
83 {
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, sampleformat,
91 planarconfig, (const tdata_t)byte_array1,
92 byte_array1_size) < 0)
93 {
94 fprintf(stderr, "Can't create TIFF file %s.\n", filename);
95 goto failure;
96 }
97 if (read_image_striped(filename, 1, XSIZE * YSIZE, rowsperstrip,
98 compression, spp, bps, photometric, sampleformat,
99 planarconfig, (const tdata_t)byte_array1,
100 byte_array1_size) < 0)
101 {
102 fprintf(stderr, "Can't read TIFF file %s.\n", filename);
103 goto failure;
104 }
105 unlink(filename);
106
107 /*
108 * Test one-channel image with different parameters.
109 */
110 rowsperstrip = 1;
111 spp = 1;
112 bps = 8;
113 photometric = PHOTOMETRIC_MINISBLACK;
114 sampleformat = SAMPLEFORMAT_UINT;
115 planarconfig = PLANARCONFIG_CONTIG;
116
117 if (create_image_striped(filename, XSIZE, YSIZE, rowsperstrip, compression,
118 spp, bps, photometric, sampleformat, planarconfig,
119 (const tdata_t)byte_array1, byte_array1_size) < 0)
120 {
121 fprintf(stderr, "Can't create TIFF file %s.\n", filename);
122 goto failure;
123 }
124 if (read_image_striped(filename, XSIZE, YSIZE, rowsperstrip, compression,
125 spp, bps, photometric, sampleformat, planarconfig,
126 (const tdata_t)byte_array1, byte_array1_size) < 0)
127 {
128 fprintf(stderr, "Can't read TIFF file %s.\n", filename);
129 goto failure;
130 }
131 unlink(filename);
132
133 rowsperstrip = YSIZE;
134 if (create_image_striped(filename, XSIZE, YSIZE, rowsperstrip, compression,
135 spp, bps, photometric, sampleformat, planarconfig,
136 (const tdata_t)byte_array1, byte_array1_size) < 0)
137 {
138 fprintf(stderr, "Can't create TIFF file %s.\n", filename);
139 goto failure;
140 }
141 if (read_image_striped(filename, XSIZE, YSIZE, rowsperstrip, compression,
142 spp, bps, photometric, sampleformat, planarconfig,
143 (const tdata_t)byte_array1, byte_array1_size) < 0)
144 {
145 fprintf(stderr, "Can't read TIFF file %s.\n", filename);
146 goto failure;
147 }
148 unlink(filename);
149
150 return 0;
151
152 failure:
153 unlink(filename);
154 return 1;
155 }