0
|
1 |
/* $Id: strip_rw.c,v 1.5 2006/03/23 14:54:02 dron Exp $ */
|
|
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 |
* Test libtiff input/output routines.
|
|
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 |
#include "test_arrays.h"
|
|
42 |
|
|
43 |
extern int
|
|
44 |
create_image_striped(const char *, uint32, uint32, uint32, uint16, uint16,
|
|
45 |
uint16, uint16, uint16, uint16, const tdata_t,
|
|
46 |
const tsize_t);
|
|
47 |
extern int
|
|
48 |
read_image_striped(const char *, uint32, uint32, uint32, uint16, uint16,
|
|
49 |
uint16, uint16, uint16, uint16, const tdata_t,
|
|
50 |
const tsize_t);
|
|
51 |
|
|
52 |
const char *filename = "strip_test.tiff";
|
|
53 |
|
|
54 |
int
|
|
55 |
main(int argc, char **argv)
|
|
56 |
{
|
|
57 |
uint32 rowsperstrip;
|
|
58 |
uint16 compression;
|
|
59 |
uint16 spp, bps, photometric, sampleformat, planarconfig;
|
|
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: */
|