]>
git.saurik.com Git - wxWidgets.git/blob - src/tiff/test/strip.c
1e13fa88fdb4ed4b9b580a11fa9ae6f15a41a93f
3 * Copyright (c) 2004, Andrey Kiselev <dron@ak4719.spb.edu>
5 * Permission to use, copy, modify, distribute, and sell this software and
6 * its documentation for any purpose is hereby granted without fee, provided
7 * that (i) the above copyright notices and this permission notice appear in
8 * all copies of the software and related documentation, and (ii) the names of
9 * Sam Leffler and Silicon Graphics may not be used in any advertising or
10 * publicity relating to the software without the specific, prior written
11 * permission of Sam Leffler and Silicon Graphics.
13 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
14 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
15 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
17 * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
18 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
19 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
20 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
21 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
28 * Functions to test strip interface of libtiff.
37 write_strips(TIFF
*tif
, const tdata_t array
, const tsize_t size
)
39 tstrip_t strip
, nstrips
;
40 tsize_t stripsize
, offset
;
42 stripsize
= TIFFStripSize(tif
);
44 fprintf (stderr
, "Wrong size of strip.\n");
48 nstrips
= TIFFNumberOfStrips(tif
);
49 for (offset
= 0, strip
= 0;
50 offset
< size
&& strip
< nstrips
;
51 offset
+=stripsize
, strip
++) {
53 * Properly write last strip.
55 tsize_t bufsize
= size
- offset
;
56 if (bufsize
> stripsize
)
59 if (TIFFWriteEncodedStrip(tif
, strip
, (char *)array
+ offset
,
60 bufsize
) != bufsize
) {
61 fprintf (stderr
, "Can't write strip %lu.\n",
62 (unsigned long)strip
);
71 read_strips(TIFF
*tif
, const tdata_t array
, const tsize_t size
)
73 tstrip_t strip
, nstrips
;
74 tsize_t stripsize
, offset
;
77 stripsize
= TIFFStripSize(tif
);
79 fprintf (stderr
, "Wrong size of strip.\n");
83 buf
= _TIFFmalloc(stripsize
);
85 fprintf (stderr
, "Can't allocate space for strip buffer.\n");
89 nstrips
= TIFFNumberOfStrips(tif
);
90 for (offset
= 0, strip
= 0;
91 offset
< size
&& strip
< nstrips
;
92 offset
+=stripsize
, strip
++) {
94 * Properly read last strip.
96 tsize_t bufsize
= size
- offset
;
97 if (bufsize
> stripsize
)
100 if (TIFFReadEncodedStrip(tif
, strip
, buf
, -1) != bufsize
) {
101 fprintf (stderr
, "Can't read strip %lu.\n",
102 (unsigned long)strip
);
105 if (memcmp(buf
, (char *)array
+ offset
, bufsize
) != 0) {
106 fprintf (stderr
, "Wrong data read for strip %lu.\n",
107 (unsigned long)strip
);
119 create_image_striped(const char *name
, uint32 width
, uint32 length
,
120 uint32 rowsperstrip
, uint16 compression
,
121 uint16 spp
, uint16 bps
, uint16 photometric
,
122 uint16 sampleformat
, uint16 planarconfig
,
123 const tdata_t array
, const tsize_t size
)
127 /* Test whether we can write tags. */
128 tif
= TIFFOpen(name
, "w");
132 if (!TIFFSetField(tif
, TIFFTAG_IMAGEWIDTH
, width
)) {
133 fprintf (stderr
, "Can't set ImageWidth tag.\n");
136 if (!TIFFSetField(tif
, TIFFTAG_IMAGELENGTH
, length
)) {
137 fprintf (stderr
, "Can't set ImageLength tag.\n");
140 if (!TIFFSetField(tif
, TIFFTAG_BITSPERSAMPLE
, bps
)) {
141 fprintf (stderr
, "Can't set BitsPerSample tag.\n");
144 if (!TIFFSetField(tif
, TIFFTAG_SAMPLESPERPIXEL
, spp
)) {
145 fprintf (stderr
, "Can't set SamplesPerPixel tag.\n");
148 if (!TIFFSetField(tif
, TIFFTAG_ROWSPERSTRIP
, rowsperstrip
)) {
149 fprintf (stderr
, "Can't set RowsPerStrip tag.\n");
152 if (!TIFFSetField(tif
, TIFFTAG_PLANARCONFIG
, planarconfig
)) {
153 fprintf (stderr
, "Can't set PlanarConfiguration tag.\n");
156 if (!TIFFSetField(tif
, TIFFTAG_PHOTOMETRIC
, photometric
)) {
157 fprintf (stderr
, "Can't set PhotometricInterpretation tag.\n");
161 if (write_strips(tif
, array
, size
) < 0) {
162 fprintf (stderr
, "Can't write image data.\n");
172 fprintf (stderr
, "Can't create test TIFF file %s:\n"
173 " ImageWidth=%ld, ImageLength=%ld, RowsPerStrip=%ld, Compression=%d,\n"
174 " BitsPerSample=%d, SamplesPerPixel=%d, SampleFormat=%d,\n"
175 " PlanarConfiguration=%d, PhotometricInterpretation=%d.\n",
176 name
, (long) width
, (long) length
, (long) rowsperstrip
,
177 compression
, bps
, spp
, sampleformat
, planarconfig
,
183 read_image_striped(const char *name
, uint32 width
, uint32 length
,
184 uint32 rowsperstrip
, uint16 compression
,
185 uint16 spp
, uint16 bps
, uint16 photometric
,
186 uint16 sampleformat
, uint16 planarconfig
,
187 const tdata_t array
, const tsize_t size
)
193 /* Test whether we can read written values. */
194 tif
= TIFFOpen(name
, "r");
198 if (TIFFIsTiled(tif
)) {
199 fprintf (stderr
, "Can't read image %s, it is tiled.\n",
203 if (!TIFFGetField(tif
, TIFFTAG_IMAGEWIDTH
, &value_u32
)
204 || value_u32
!= width
) {
205 fprintf (stderr
, "Can't get tag %d.\n", TIFFTAG_IMAGEWIDTH
);
208 if (!TIFFGetField(tif
, TIFFTAG_IMAGELENGTH
, &value_u32
)
209 || value_u32
!= length
) {
210 fprintf (stderr
, "Can't get tag %d.\n", TIFFTAG_IMAGELENGTH
);
213 if (!TIFFGetField(tif
, TIFFTAG_BITSPERSAMPLE
, &value_u16
)
214 || value_u16
!= bps
) {
215 fprintf (stderr
, "Can't get tag %d.\n", TIFFTAG_BITSPERSAMPLE
);
218 if (!TIFFGetField(tif
, TIFFTAG_PHOTOMETRIC
, &value_u16
)
219 || value_u16
!= photometric
) {
220 fprintf (stderr
, "Can't get tag %d.\n", TIFFTAG_PHOTOMETRIC
);
223 if (!TIFFGetField(tif
, TIFFTAG_SAMPLESPERPIXEL
, &value_u16
)
224 || value_u16
!= spp
) {
225 fprintf (stderr
, "Can't get tag %d.\n", TIFFTAG_SAMPLESPERPIXEL
);
228 if (!TIFFGetField(tif
, TIFFTAG_ROWSPERSTRIP
, &value_u32
)
229 || value_u32
!= rowsperstrip
) {
230 fprintf (stderr
, "Can't get tag %d.\n", TIFFTAG_ROWSPERSTRIP
);
233 if (!TIFFGetField(tif
, TIFFTAG_PLANARCONFIG
, &value_u16
)
234 || value_u16
!= planarconfig
) {
235 fprintf (stderr
, "Can't get tag %d.\n", TIFFTAG_PLANARCONFIG
);
239 if (read_strips(tif
, array
, size
) < 0) {
240 fprintf (stderr
, "Can't read image data.\n");
250 fprintf (stderr
, "Can't read test TIFF file %s:\n"
251 " ImageWidth=%ld, ImageLength=%ld, RowsPerStrip=%ld, Compression=%d,\n"
252 " BitsPerSample=%d, SamplesPerPixel=%d, SampleFormat=%d,\n"
253 " PlanarConfiguration=%d, PhotometricInterpretation=%d.\n",
254 name
, (long) width
, (long) length
, (long) rowsperstrip
,
255 compression
, bps
, spp
, sampleformat
, planarconfig
,
261 write_scanlines(TIFF
*tif
, const tdata_t array
, const tsize_t size
)
264 tsize_t scanlinesize
, offset
;
267 if (!TIFFGetField(tif
, TIFFTAG_IMAGELENGTH
, &length
)) {
268 fprintf (stderr
, "Can't get tag %d.\n", TIFFTAG_IMAGELENGTH
);
272 scanlinesize
= TIFFScanlineSize(tif
);
274 fprintf (stderr
, "Wrong size of scanline.\n");
278 for (offset
= 0, row
= 0; row
< length
; offset
+=scanlinesize
, row
++) {
279 if (TIFFWriteScanline(tif
, (char *)array
+ offset
, row
, 0) < 0) {
281 "Can't write image data at row %lu.\n", (long) row
);
289 /* vim: set ts=8 sts=8 sw=8 noet: */