]>
git.saurik.com Git - wxWidgets.git/blob - src/tiff/test/rewrite_tag.c
187ae1117bd63c2db20a2058d6dae9df2e75b06e
4 * Copyright (c) 2007, Frank Warmerdam <warmerdam@pobox.com>
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.
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.
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
29 * Module to test _TIFFRewriteField().
32 #include "tif_config.h"
43 const uint32 width
= 10;
44 const uint32 length
= 40;
45 const uint32 rows_per_strip
= 1;
52 unsigned char buf
[10] = {0,0,0,0,0,0,0,0,0,0};
55 const char *filename
= "test_packbits.tif";
57 /* Test whether we can write tags. */
58 tif
= TIFFOpen(filename
, "w");
61 fprintf (stderr
, "Can't create test TIFF file %s.\n", filename
);
65 if (!TIFFSetField(tif
, TIFFTAG_COMPRESSION
, COMPRESSION_PACKBITS
)) {
66 fprintf (stderr
, "Can't set Compression tag.\n");
69 if (!TIFFSetField(tif
, TIFFTAG_IMAGEWIDTH
, width
)) {
70 fprintf (stderr
, "Can't set ImageWidth tag.\n");
73 if (!TIFFSetField(tif
, TIFFTAG_IMAGELENGTH
, length
)) {
74 fprintf (stderr
, "Can't set ImageLength tag.\n");
77 if (!TIFFSetField(tif
, TIFFTAG_BITSPERSAMPLE
, 8)) {
78 fprintf (stderr
, "Can't set BitsPerSample tag.\n");
81 if (!TIFFSetField(tif
, TIFFTAG_SAMPLESPERPIXEL
, 1)) {
82 fprintf (stderr
, "Can't set SamplesPerPixel tag.\n");
85 if (!TIFFSetField(tif
, TIFFTAG_ROWSPERSTRIP
, rows_per_strip
)) {
86 fprintf (stderr
, "Can't set SamplesPerPixel tag.\n");
89 if (!TIFFSetField(tif
, TIFFTAG_PLANARCONFIG
, PLANARCONFIG_CONTIG
)) {
90 fprintf (stderr
, "Can't set PlanarConfiguration tag.\n");
94 for (i
= 0; i
< length
; i
++ )
96 if( !TIFFWriteEncodedStrip( tif
, i
, buf
, 10 ) )
98 fprintf (stderr
, "Can't write image data.\n");
105 /* Test whether we can write tags. */
107 tif
= TIFFOpen(filename
, "r+");
110 fprintf (stderr
, "Can't create test TIFF file %s.\n", filename
);
117 if( !TIFFWriteEncodedStrip( tif
, 6, buf
, 10 ) )
119 fprintf (stderr
, "Can't write image data.\n");
130 /* Something goes wrong; close file and return unsuccessful status. */
132 /* unlink(filename); */
138 /************************************************************************/
140 /************************************************************************/
141 int rewrite_test( const char *filename
, int length
, int bigtiff
,
147 unsigned char buf
[10] = {5,6,7,8,9,10,11,12,13,14};
148 uint64
*rowoffset
, *rowbytes
;
149 uint64
*upd_rowoffset
;
150 uint64
*upd_bytecount
;
152 /* Test whether we can write tags. */
154 tif
= TIFFOpen(filename
, "w8");
156 tif
= TIFFOpen(filename
, "w4");
159 fprintf (stderr
, "Can't create test TIFF file %s.\n", filename
);
163 if (!TIFFSetField(tif
, TIFFTAG_COMPRESSION
, COMPRESSION_PACKBITS
)) {
164 fprintf (stderr
, "Can't set Compression tag.\n");
167 if (!TIFFSetField(tif
, TIFFTAG_IMAGEWIDTH
, width
)) {
168 fprintf (stderr
, "Can't set ImageWidth tag.\n");
171 if (!TIFFSetField(tif
, TIFFTAG_IMAGELENGTH
, length
)) {
172 fprintf (stderr
, "Can't set ImageLength tag.\n");
175 if (!TIFFSetField(tif
, TIFFTAG_BITSPERSAMPLE
, 8)) {
176 fprintf (stderr
, "Can't set BitsPerSample tag.\n");
179 if (!TIFFSetField(tif
, TIFFTAG_SAMPLESPERPIXEL
, 1)) {
180 fprintf (stderr
, "Can't set SamplesPerPixel tag.\n");
183 if (!TIFFSetField(tif
, TIFFTAG_ROWSPERSTRIP
, rows_per_strip
)) {
184 fprintf (stderr
, "Can't set SamplesPerPixel tag.\n");
187 if (!TIFFSetField(tif
, TIFFTAG_PLANARCONFIG
, PLANARCONFIG_CONTIG
)) {
188 fprintf (stderr
, "Can't set PlanarConfiguration tag.\n");
192 for (i
= 0; i
< length
; i
++ )
194 if( !TIFFWriteScanline( tif
, buf
, i
, 0 ) )
196 fprintf (stderr
, "Can't write image data.\n");
203 /* Ok, now test whether we can read written values. */
204 tif
= TIFFOpen(filename
, "r+");
206 fprintf (stderr
, "Can't open test TIFF file %s.\n", filename
);
210 if( !TIFFGetField( tif
, TIFFTAG_STRIPOFFSETS
, &rowoffset
) )
212 fprintf (stderr
, "Can't fetch STRIPOFFSETS.\n");
216 if( !TIFFGetField( tif
, TIFFTAG_STRIPBYTECOUNTS
, &rowbytes
) )
218 fprintf (stderr
, "Can't fetch STRIPBYTECOUNTS.\n");
222 upd_rowoffset
= (uint64
*) _TIFFmalloc(sizeof(uint64
) * length
);
223 for( i
= 0; i
< length
; i
++ )
224 upd_rowoffset
[i
] = base_value
+ i
*10;
226 if( !_TIFFRewriteField( tif
, TIFFTAG_STRIPOFFSETS
, TIFF_LONG8
,
227 length
, upd_rowoffset
) )
229 fprintf (stderr
, "Can't rewrite STRIPOFFSETS.\n");
233 _TIFFfree( upd_rowoffset
);
235 upd_bytecount
= (uint64
*) _TIFFmalloc(sizeof(uint64
) * length
);
236 for( i
= 0; i
< length
; i
++ )
237 upd_bytecount
[i
] = 100 + i
*10;
239 if( !_TIFFRewriteField( tif
, TIFFTAG_STRIPBYTECOUNTS
, TIFF_LONG8
,
240 length
, upd_bytecount
) )
242 fprintf (stderr
, "Can't rewrite STRIPBYTECOUNTS.\n");
246 _TIFFfree( upd_bytecount
);
250 /* Reopen file and read back to verify contents */
252 tif
= TIFFOpen(filename
, "r");
254 fprintf (stderr
, "Can't open test TIFF file %s.\n", filename
);
258 if( !TIFFGetField( tif
, TIFFTAG_STRIPOFFSETS
, &rowoffset
) )
260 fprintf (stderr
, "Can't fetch STRIPOFFSETS.\n");
264 for( i
= 0; i
< length
; i
++ )
266 uint64 expect
= base_value
+ i
*10;
268 if( rowoffset
[i
] != expect
)
271 "%s:STRIPOFFSETS[%d]: Got %X:%08X instead of %X:%08X.\n",
273 (int) (rowoffset
[i
] >> 32),
274 (int) (rowoffset
[i
]&0xFFFFFFFF),
275 (int) (expect
>> 32),
276 (int) (expect
& 0xFFFFFFFF) );
281 if( !TIFFGetField( tif
, TIFFTAG_STRIPBYTECOUNTS
, &rowbytes
) )
283 fprintf (stderr
, "Can't fetch STRIPBYTECOUNTS.\n");
287 for( i
= 0; i
< length
; i
++ )
289 uint64 expect
= 100 + i
*10;
291 if( rowbytes
[i
] != expect
)
294 "%s:STRIPBYTECOUNTS[%d]: Got %X:%08X instead of %X:%08X.\n",
296 (int) (rowbytes
[i
] >> 32),
297 (int) (rowbytes
[i
] & 0xFFFFFFFF),
298 (int) (expect
>> 32),
299 (int) (expect
& 0xFFFFFFFF) );
306 /* All tests passed; delete file and exit with success status. */
311 /* Something goes wrong; close file and return unsuccessful status. */
313 /* unlink(filename); */
319 /************************************************************************/
321 /************************************************************************/
323 main(int argc
, char **argv
)
329 failure
|= test_packbits();
331 /* test fairly normal use */
332 failure
|= rewrite_test( "rewrite1.tif", 10, 0, 100 );
333 failure
|= rewrite_test( "rewrite2.tif", 10, 1, 100 );
335 /* test case of fitting all in directory entry */
336 failure
|= rewrite_test( "rewrite3.tif", 1, 0, 100 );
337 failure
|= rewrite_test( "rewrite4.tif", 1, 1, 100 );
339 /* test with very large values that don't fit in 4bytes (bigtiff only) */
340 failure
|= rewrite_test( "rewrite5.tif", 1000, 1, 0x6000000000ULL
);
341 failure
|= rewrite_test( "rewrite6.tif", 1, 1, 0x6000000000ULL
);
346 /* vim: set ts=8 sts=8 sw=8 noet: */