2
|
1 |
/*
|
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
3 |
*
|
|
4 |
* This code is free software; you can redistribute it and/or modify it
|
|
5 |
* under the terms of the GNU General Public License version 2 only, as
|
5506
|
6 |
* published by the Free Software Foundation. Oracle designates this
|
2
|
7 |
* particular file as subject to the "Classpath" exception as provided
|
5506
|
8 |
* by Oracle in the LICENSE file that accompanied this code.
|
2
|
9 |
*
|
|
10 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
11 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
12 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
13 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
14 |
* accompanied this code).
|
|
15 |
*
|
|
16 |
* You should have received a copy of the GNU General Public License version
|
|
17 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
18 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
19 |
*
|
5506
|
20 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
21 |
* or visit www.oracle.com if you need additional information or have any
|
|
22 |
* questions.
|
2
|
23 |
*/
|
|
24 |
|
|
25 |
/* pngtest.c - a simple test program to test libpng
|
|
26 |
*
|
|
27 |
* This file is available under and governed by the GNU General Public
|
|
28 |
* License version 2 only, as published by the Free Software Foundation.
|
|
29 |
* However, the following notice accompanied the original version of this
|
|
30 |
* file and, per its terms, should not be removed:
|
|
31 |
*
|
29913
|
32 |
* Last changed in libpng 1.6.15 [November 20, 2014]
|
|
33 |
* Copyright (c) 1998-2014 Glenn Randers-Pehrson
|
2
|
34 |
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
|
|
35 |
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
|
|
36 |
*
|
10576
|
37 |
* This code is released under the libpng license.
|
|
38 |
* For conditions of distribution and use, see the disclaimer
|
|
39 |
* and license in png.h
|
|
40 |
*
|
2
|
41 |
* This program reads in a PNG image, writes it out again, and then
|
|
42 |
* compares the two files. If the files are identical, this shows that
|
|
43 |
* the basic chunk handling, filtering, and (de)compression code is working
|
|
44 |
* properly. It does not currently test all of the transforms, although
|
|
45 |
* it probably should.
|
|
46 |
*
|
|
47 |
* The program will report "FAIL" in certain legitimate cases:
|
|
48 |
* 1) when the compression level or filter selection method is changed.
|
|
49 |
* 2) when the maximum IDAT size (PNG_ZBUF_SIZE in pngconf.h) is not 8192.
|
|
50 |
* 3) unknown unsafe-to-copy ancillary chunks or unknown critical chunks
|
|
51 |
* exist in the input file.
|
|
52 |
* 4) others not listed here...
|
|
53 |
* In these cases, it is best to check with another tool such as "pngcheck"
|
|
54 |
* to see what the differences between the two files are.
|
|
55 |
*
|
|
56 |
* If a filename is given on the command-line, then this file is used
|
|
57 |
* for the input, rather than the default "pngtest.png". This allows
|
|
58 |
* testing a wide variety of files easily. You can also test a number
|
|
59 |
* of files at once by typing "pngtest -m file1.png file2.png ..."
|
|
60 |
*/
|
|
61 |
|
10576
|
62 |
#define _POSIX_SOURCE 1
|
2
|
63 |
|
29913
|
64 |
#include <stdio.h>
|
|
65 |
#include <stdlib.h>
|
|
66 |
#include <string.h>
|
|
67 |
|
|
68 |
/* Defined so I can write to a file on gui/windowing platforms */
|
|
69 |
/* #define STDERR stderr */
|
|
70 |
#define STDERR stdout /* For DOS */
|
|
71 |
|
10576
|
72 |
#include "png.h"
|
29913
|
73 |
|
|
74 |
/* Known chunks that exist in pngtest.png must be supported or pngtest will fail
|
|
75 |
* simply as a result of re-ordering them. This may be fixed in 1.7
|
|
76 |
*
|
|
77 |
* pngtest allocates a single row buffer for each row and overwrites it,
|
|
78 |
* therefore if the write side doesn't support the writing of interlaced images
|
|
79 |
* nothing can be done for an interlaced image (and the code below will fail
|
|
80 |
* horribly trying to write extra data after writing garbage).
|
|
81 |
*/
|
|
82 |
#if defined PNG_READ_SUPPORTED && /* else nothing can be done */\
|
|
83 |
defined PNG_READ_bKGD_SUPPORTED &&\
|
|
84 |
defined PNG_READ_cHRM_SUPPORTED &&\
|
|
85 |
defined PNG_READ_gAMA_SUPPORTED &&\
|
|
86 |
defined PNG_READ_oFFs_SUPPORTED &&\
|
|
87 |
defined PNG_READ_pCAL_SUPPORTED &&\
|
|
88 |
defined PNG_READ_pHYs_SUPPORTED &&\
|
|
89 |
defined PNG_READ_sBIT_SUPPORTED &&\
|
|
90 |
defined PNG_READ_sCAL_SUPPORTED &&\
|
|
91 |
defined PNG_READ_sRGB_SUPPORTED &&\
|
|
92 |
defined PNG_READ_tEXt_SUPPORTED &&\
|
|
93 |
defined PNG_READ_tIME_SUPPORTED &&\
|
|
94 |
defined PNG_READ_zTXt_SUPPORTED &&\
|
|
95 |
defined PNG_WRITE_INTERLACING_SUPPORTED
|
|
96 |
|
|
97 |
#ifdef PNG_ZLIB_HEADER
|
|
98 |
# include PNG_ZLIB_HEADER /* defined by pnglibconf.h from 1.7 */
|
|
99 |
#else
|
|
100 |
# include "zlib.h"
|
|
101 |
#endif
|
|
102 |
|
10576
|
103 |
/* Copied from pngpriv.h but only used in error messages below. */
|
|
104 |
#ifndef PNG_ZBUF_SIZE
|
|
105 |
# define PNG_ZBUF_SIZE 8192
|
|
106 |
#endif
|
29913
|
107 |
#define FCLOSE(file) fclose(file)
|
10576
|
108 |
|
|
109 |
#ifndef PNG_STDIO_SUPPORTED
|
|
110 |
typedef FILE * png_FILE_p;
|
2
|
111 |
#endif
|
|
112 |
|
10576
|
113 |
/* Makes pngtest verbose so we can find problems. */
|
2
|
114 |
#ifndef PNG_DEBUG
|
|
115 |
# define PNG_DEBUG 0
|
|
116 |
#endif
|
|
117 |
|
10576
|
118 |
#if PNG_DEBUG > 1
|
|
119 |
# define pngtest_debug(m) ((void)fprintf(stderr, m "\n"))
|
|
120 |
# define pngtest_debug1(m,p1) ((void)fprintf(stderr, m "\n", p1))
|
|
121 |
# define pngtest_debug2(m,p1,p2) ((void)fprintf(stderr, m "\n", p1, p2))
|
|
122 |
#else
|
|
123 |
# define pngtest_debug(m) ((void)0)
|
|
124 |
# define pngtest_debug1(m,p1) ((void)0)
|
|
125 |
# define pngtest_debug2(m,p1,p2) ((void)0)
|
|
126 |
#endif
|
|
127 |
|
2
|
128 |
#if !PNG_DEBUG
|
10576
|
129 |
# define SINGLE_ROWBUF_ALLOC /* Makes buffer overruns easier to nail */
|
2
|
130 |
#endif
|
|
131 |
|
|
132 |
/* Turn on CPU timing
|
|
133 |
#define PNGTEST_TIMING
|
|
134 |
*/
|
|
135 |
|
10576
|
136 |
#ifndef PNG_FLOATING_POINT_SUPPORTED
|
2
|
137 |
#undef PNGTEST_TIMING
|
|
138 |
#endif
|
|
139 |
|
|
140 |
#ifdef PNGTEST_TIMING
|
|
141 |
static float t_start, t_stop, t_decode, t_encode, t_misc;
|
|
142 |
#include <time.h>
|
|
143 |
#endif
|
|
144 |
|
10576
|
145 |
#ifdef PNG_TIME_RFC1123_SUPPORTED
|
|
146 |
#define PNG_tIME_STRING_LENGTH 29
|
|
147 |
static int tIME_chunk_present = 0;
|
|
148 |
static char tIME_string[PNG_tIME_STRING_LENGTH] = "tIME chunk is not present";
|
2
|
149 |
#endif
|
|
150 |
|
|
151 |
static int verbose = 0;
|
29913
|
152 |
static int strict = 0;
|
|
153 |
static int relaxed = 0;
|
|
154 |
static int unsupported_chunks = 0; /* chunk unsupported by libpng in input */
|
|
155 |
static int error_count = 0; /* count calls to png_error */
|
|
156 |
static int warning_count = 0; /* count calls to png_warning */
|
2
|
157 |
|
|
158 |
/* Define png_jmpbuf() in case we are using a pre-1.0.6 version of libpng */
|
|
159 |
#ifndef png_jmpbuf
|
|
160 |
# define png_jmpbuf(png_ptr) png_ptr->jmpbuf
|
|
161 |
#endif
|
|
162 |
|
29913
|
163 |
/* Defines for unknown chunk handling if required. */
|
|
164 |
#ifndef PNG_HANDLE_CHUNK_ALWAYS
|
|
165 |
# define PNG_HANDLE_CHUNK_ALWAYS 3
|
|
166 |
#endif
|
|
167 |
#ifndef PNG_HANDLE_CHUNK_IF_SAFE
|
|
168 |
# define PNG_HANDLE_CHUNK_IF_SAFE 2
|
|
169 |
#endif
|
|
170 |
|
|
171 |
/* Utility to save typing/errors, the argument must be a name */
|
|
172 |
#define MEMZERO(var) ((void)memset(&var, 0, sizeof var))
|
|
173 |
|
10576
|
174 |
/* Example of using row callbacks to make a simple progress meter */
|
|
175 |
static int status_pass = 1;
|
|
176 |
static int status_dots_requested = 0;
|
|
177 |
static int status_dots = 1;
|
|
178 |
|
29913
|
179 |
static void PNGCBAPI
|
2
|
180 |
read_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass)
|
|
181 |
{
|
10576
|
182 |
if (png_ptr == NULL || row_number > PNG_UINT_31_MAX)
|
|
183 |
return;
|
|
184 |
|
|
185 |
if (status_pass != pass)
|
|
186 |
{
|
|
187 |
fprintf(stdout, "\n Pass %d: ", pass);
|
|
188 |
status_pass = pass;
|
|
189 |
status_dots = 31;
|
|
190 |
}
|
|
191 |
|
|
192 |
status_dots--;
|
|
193 |
|
|
194 |
if (status_dots == 0)
|
|
195 |
{
|
|
196 |
fprintf(stdout, "\n ");
|
|
197 |
status_dots=30;
|
|
198 |
}
|
|
199 |
|
|
200 |
fprintf(stdout, "r");
|
2
|
201 |
}
|
|
202 |
|
29913
|
203 |
#ifdef PNG_WRITE_SUPPORTED
|
|
204 |
static void PNGCBAPI
|
2
|
205 |
write_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass)
|
|
206 |
{
|
10576
|
207 |
if (png_ptr == NULL || row_number > PNG_UINT_31_MAX || pass > 7)
|
|
208 |
return;
|
|
209 |
|
|
210 |
fprintf(stdout, "w");
|
2
|
211 |
}
|
29913
|
212 |
#endif
|
2
|
213 |
|
|
214 |
|
10576
|
215 |
#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
|
2
|
216 |
/* Example of using user transform callback (we don't transform anything,
|
10576
|
217 |
* but merely examine the row filters. We set this to 256 rather than
|
|
218 |
* 5 in case illegal filter values are present.)
|
|
219 |
*/
|
2
|
220 |
static png_uint_32 filters_used[256];
|
29913
|
221 |
static void PNGCBAPI
|
2
|
222 |
count_filters(png_structp png_ptr, png_row_infop row_info, png_bytep data)
|
|
223 |
{
|
10576
|
224 |
if (png_ptr != NULL && row_info != NULL)
|
|
225 |
++filters_used[*(data - 1)];
|
2
|
226 |
}
|
|
227 |
#endif
|
|
228 |
|
10576
|
229 |
#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
|
|
230 |
/* Example of using user transform callback (we don't transform anything,
|
|
231 |
* but merely count the zero samples)
|
|
232 |
*/
|
2
|
233 |
|
|
234 |
static png_uint_32 zero_samples;
|
|
235 |
|
29913
|
236 |
static void PNGCBAPI
|
2
|
237 |
count_zero_samples(png_structp png_ptr, png_row_infop row_info, png_bytep data)
|
|
238 |
{
|
|
239 |
png_bytep dp = data;
|
10576
|
240 |
if (png_ptr == NULL)
|
|
241 |
return;
|
2
|
242 |
|
10576
|
243 |
/* Contents of row_info:
|
2
|
244 |
* png_uint_32 width width of row
|
|
245 |
* png_uint_32 rowbytes number of bytes in row
|
|
246 |
* png_byte color_type color type of pixels
|
|
247 |
* png_byte bit_depth bit depth of samples
|
|
248 |
* png_byte channels number of channels (1-4)
|
|
249 |
* png_byte pixel_depth bits per pixel (depth*channels)
|
|
250 |
*/
|
|
251 |
|
10576
|
252 |
/* Counts the number of zero samples (or zero pixels if color_type is 3 */
|
2
|
253 |
|
10576
|
254 |
if (row_info->color_type == 0 || row_info->color_type == 3)
|
2
|
255 |
{
|
10576
|
256 |
int pos = 0;
|
2
|
257 |
png_uint_32 n, nstop;
|
10576
|
258 |
|
|
259 |
for (n = 0, nstop=row_info->width; n<nstop; n++)
|
2
|
260 |
{
|
10576
|
261 |
if (row_info->bit_depth == 1)
|
2
|
262 |
{
|
10576
|
263 |
if (((*dp << pos++ ) & 0x80) == 0)
|
|
264 |
zero_samples++;
|
|
265 |
|
|
266 |
if (pos == 8)
|
2
|
267 |
{
|
|
268 |
pos = 0;
|
|
269 |
dp++;
|
|
270 |
}
|
|
271 |
}
|
10576
|
272 |
|
|
273 |
if (row_info->bit_depth == 2)
|
2
|
274 |
{
|
10576
|
275 |
if (((*dp << (pos+=2)) & 0xc0) == 0)
|
|
276 |
zero_samples++;
|
|
277 |
|
|
278 |
if (pos == 8)
|
2
|
279 |
{
|
|
280 |
pos = 0;
|
|
281 |
dp++;
|
|
282 |
}
|
|
283 |
}
|
10576
|
284 |
|
|
285 |
if (row_info->bit_depth == 4)
|
2
|
286 |
{
|
10576
|
287 |
if (((*dp << (pos+=4)) & 0xf0) == 0)
|
|
288 |
zero_samples++;
|
|
289 |
|
|
290 |
if (pos == 8)
|
2
|
291 |
{
|
|
292 |
pos = 0;
|
|
293 |
dp++;
|
|
294 |
}
|
|
295 |
}
|
10576
|
296 |
|
|
297 |
if (row_info->bit_depth == 8)
|
|
298 |
if (*dp++ == 0)
|
|
299 |
zero_samples++;
|
|
300 |
|
|
301 |
if (row_info->bit_depth == 16)
|
2
|
302 |
{
|
10576
|
303 |
if ((*dp | *(dp+1)) == 0)
|
|
304 |
zero_samples++;
|
2
|
305 |
dp+=2;
|
|
306 |
}
|
|
307 |
}
|
|
308 |
}
|
10576
|
309 |
else /* Other color types */
|
2
|
310 |
{
|
|
311 |
png_uint_32 n, nstop;
|
|
312 |
int channel;
|
|
313 |
int color_channels = row_info->channels;
|
29913
|
314 |
if (row_info->color_type > 3)
|
|
315 |
color_channels--;
|
2
|
316 |
|
10576
|
317 |
for (n = 0, nstop=row_info->width; n<nstop; n++)
|
2
|
318 |
{
|
|
319 |
for (channel = 0; channel < color_channels; channel++)
|
|
320 |
{
|
10576
|
321 |
if (row_info->bit_depth == 8)
|
|
322 |
if (*dp++ == 0)
|
|
323 |
zero_samples++;
|
|
324 |
|
|
325 |
if (row_info->bit_depth == 16)
|
2
|
326 |
{
|
10576
|
327 |
if ((*dp | *(dp+1)) == 0)
|
|
328 |
zero_samples++;
|
|
329 |
|
2
|
330 |
dp+=2;
|
|
331 |
}
|
|
332 |
}
|
10576
|
333 |
if (row_info->color_type > 3)
|
2
|
334 |
{
|
|
335 |
dp++;
|
10576
|
336 |
if (row_info->bit_depth == 16)
|
|
337 |
dp++;
|
2
|
338 |
}
|
|
339 |
}
|
|
340 |
}
|
|
341 |
}
|
29913
|
342 |
#endif /* WRITE_USER_TRANSFORM */
|
2
|
343 |
|
10576
|
344 |
#ifndef PNG_STDIO_SUPPORTED
|
2
|
345 |
/* START of code to validate stdio-free compilation */
|
10576
|
346 |
/* These copies of the default read/write functions come from pngrio.c and
|
|
347 |
* pngwio.c. They allow "don't include stdio" testing of the library.
|
|
348 |
* This is the function that does the actual reading of data. If you are
|
|
349 |
* not reading from a standard C stream, you should create a replacement
|
|
350 |
* read_data function and use it at run time with png_set_read_fn(), rather
|
|
351 |
* than changing the library.
|
|
352 |
*/
|
|
353 |
|
|
354 |
#ifdef PNG_IO_STATE_SUPPORTED
|
|
355 |
void
|
|
356 |
pngtest_check_io_state(png_structp png_ptr, png_size_t data_length,
|
|
357 |
png_uint_32 io_op);
|
|
358 |
void
|
|
359 |
pngtest_check_io_state(png_structp png_ptr, png_size_t data_length,
|
|
360 |
png_uint_32 io_op)
|
|
361 |
{
|
|
362 |
png_uint_32 io_state = png_get_io_state(png_ptr);
|
|
363 |
int err = 0;
|
|
364 |
|
|
365 |
/* Check if the current operation (reading / writing) is as expected. */
|
|
366 |
if ((io_state & PNG_IO_MASK_OP) != io_op)
|
|
367 |
png_error(png_ptr, "Incorrect operation in I/O state");
|
|
368 |
|
|
369 |
/* Check if the buffer size specific to the current location
|
|
370 |
* (file signature / header / data / crc) is as expected.
|
|
371 |
*/
|
|
372 |
switch (io_state & PNG_IO_MASK_LOC)
|
|
373 |
{
|
|
374 |
case PNG_IO_SIGNATURE:
|
|
375 |
if (data_length > 8)
|
|
376 |
err = 1;
|
|
377 |
break;
|
|
378 |
case PNG_IO_CHUNK_HDR:
|
|
379 |
if (data_length != 8)
|
|
380 |
err = 1;
|
|
381 |
break;
|
|
382 |
case PNG_IO_CHUNK_DATA:
|
|
383 |
break; /* no restrictions here */
|
|
384 |
case PNG_IO_CHUNK_CRC:
|
|
385 |
if (data_length != 4)
|
|
386 |
err = 1;
|
|
387 |
break;
|
|
388 |
default:
|
|
389 |
err = 1; /* uninitialized */
|
|
390 |
}
|
29913
|
391 |
if (err != 0)
|
10576
|
392 |
png_error(png_ptr, "Bad I/O state or buffer size");
|
|
393 |
}
|
|
394 |
#endif
|
2
|
395 |
|
10576
|
396 |
static void PNGCBAPI
|
2
|
397 |
pngtest_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
|
398 |
{
|
10576
|
399 |
png_size_t check = 0;
|
|
400 |
png_voidp io_ptr;
|
2
|
401 |
|
|
402 |
/* fread() returns 0 on error, so it is OK to store this in a png_size_t
|
|
403 |
* instead of an int, which is what fread() actually returns.
|
|
404 |
*/
|
10576
|
405 |
io_ptr = png_get_io_ptr(png_ptr);
|
|
406 |
if (io_ptr != NULL)
|
|
407 |
{
|
|
408 |
check = fread(data, 1, length, (png_FILE_p)io_ptr);
|
|
409 |
}
|
2
|
410 |
|
|
411 |
if (check != length)
|
|
412 |
{
|
10576
|
413 |
png_error(png_ptr, "Read Error");
|
2
|
414 |
}
|
10576
|
415 |
|
|
416 |
#ifdef PNG_IO_STATE_SUPPORTED
|
|
417 |
pngtest_check_io_state(png_ptr, length, PNG_IO_READING);
|
|
418 |
#endif
|
2
|
419 |
}
|
|
420 |
|
10576
|
421 |
#ifdef PNG_WRITE_FLUSH_SUPPORTED
|
|
422 |
static void PNGCBAPI
|
2
|
423 |
pngtest_flush(png_structp png_ptr)
|
|
424 |
{
|
10576
|
425 |
/* Do nothing; fflush() is said to be just a waste of energy. */
|
|
426 |
PNG_UNUSED(png_ptr) /* Stifle compiler warning */
|
2
|
427 |
}
|
|
428 |
#endif
|
|
429 |
|
|
430 |
/* This is the function that does the actual writing of data. If you are
|
10576
|
431 |
* not writing to a standard C stream, you should create a replacement
|
|
432 |
* write_data function and use it at run time with png_set_write_fn(), rather
|
|
433 |
* than changing the library.
|
|
434 |
*/
|
|
435 |
static void PNGCBAPI
|
2
|
436 |
pngtest_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
|
437 |
{
|
10576
|
438 |
png_size_t check;
|
2
|
439 |
|
10576
|
440 |
check = fwrite(data, 1, length, (png_FILE_p)png_get_io_ptr(png_ptr));
|
|
441 |
|
2
|
442 |
if (check != length)
|
|
443 |
{
|
|
444 |
png_error(png_ptr, "Write Error");
|
|
445 |
}
|
10576
|
446 |
|
|
447 |
#ifdef PNG_IO_STATE_SUPPORTED
|
|
448 |
pngtest_check_io_state(png_ptr, length, PNG_IO_WRITING);
|
|
449 |
#endif
|
2
|
450 |
}
|
29913
|
451 |
#endif /* !STDIO */
|
2
|
452 |
|
|
453 |
/* This function is called when there is a warning, but the library thinks
|
|
454 |
* it can continue anyway. Replacement functions don't have to do anything
|
|
455 |
* here if you don't want to. In the default configuration, png_ptr is
|
|
456 |
* not used, but it is passed in case it may be useful.
|
|
457 |
*/
|
29913
|
458 |
typedef struct
|
|
459 |
{
|
|
460 |
PNG_CONST char *file_name;
|
|
461 |
} pngtest_error_parameters;
|
|
462 |
|
10576
|
463 |
static void PNGCBAPI
|
2
|
464 |
pngtest_warning(png_structp png_ptr, png_const_charp message)
|
|
465 |
{
|
|
466 |
PNG_CONST char *name = "UNKNOWN (ERROR!)";
|
29913
|
467 |
pngtest_error_parameters *test =
|
|
468 |
(pngtest_error_parameters*)png_get_error_ptr(png_ptr);
|
|
469 |
|
|
470 |
++warning_count;
|
10576
|
471 |
|
29913
|
472 |
if (test != NULL && test->file_name != NULL)
|
|
473 |
name = test->file_name;
|
10576
|
474 |
|
29913
|
475 |
fprintf(STDERR, "%s: libpng warning: %s\n", name, message);
|
2
|
476 |
}
|
|
477 |
|
|
478 |
/* This is the default error handling function. Note that replacements for
|
|
479 |
* this function MUST NOT RETURN, or the program will likely crash. This
|
|
480 |
* function is used by default, or if the program supplies NULL for the
|
|
481 |
* error function pointer in png_set_error_fn().
|
|
482 |
*/
|
10576
|
483 |
static void PNGCBAPI
|
2
|
484 |
pngtest_error(png_structp png_ptr, png_const_charp message)
|
|
485 |
{
|
29913
|
486 |
++error_count;
|
|
487 |
|
2
|
488 |
pngtest_warning(png_ptr, message);
|
|
489 |
/* We can return because png_error calls the default handler, which is
|
10576
|
490 |
* actually OK in this case.
|
|
491 |
*/
|
2
|
492 |
}
|
29913
|
493 |
|
2
|
494 |
/* END of code to validate stdio-free compilation */
|
|
495 |
|
|
496 |
/* START of code to validate memory allocation and deallocation */
|
|
497 |
#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
|
|
498 |
|
|
499 |
/* Allocate memory. For reasonable files, size should never exceed
|
10576
|
500 |
* 64K. However, zlib may allocate more then 64K if you don't tell
|
|
501 |
* it not to. See zconf.h and png.h for more information. zlib does
|
|
502 |
* need to allocate exactly 64K, so whatever you call here must
|
|
503 |
* have the ability to do that.
|
|
504 |
*
|
|
505 |
* This piece of code can be compiled to validate max 64K allocations
|
|
506 |
* by setting MAXSEG_64K in zlib zconf.h *or* PNG_MAX_MALLOC_64K.
|
|
507 |
*/
|
2
|
508 |
typedef struct memory_information
|
|
509 |
{
|
10576
|
510 |
png_alloc_size_t size;
|
2
|
511 |
png_voidp pointer;
|
29913
|
512 |
struct memory_information *next;
|
2
|
513 |
} memory_information;
|
29913
|
514 |
typedef memory_information *memory_infop;
|
2
|
515 |
|
|
516 |
static memory_infop pinformation = NULL;
|
|
517 |
static int current_allocation = 0;
|
|
518 |
static int maximum_allocation = 0;
|
|
519 |
static int total_allocation = 0;
|
|
520 |
static int num_allocations = 0;
|
|
521 |
|
10576
|
522 |
png_voidp PNGCBAPI png_debug_malloc PNGARG((png_structp png_ptr,
|
|
523 |
png_alloc_size_t size));
|
|
524 |
void PNGCBAPI png_debug_free PNGARG((png_structp png_ptr, png_voidp ptr));
|
2
|
525 |
|
|
526 |
png_voidp
|
10576
|
527 |
PNGCBAPI png_debug_malloc(png_structp png_ptr, png_alloc_size_t size)
|
2
|
528 |
{
|
|
529 |
|
|
530 |
/* png_malloc has already tested for NULL; png_create_struct calls
|
10576
|
531 |
* png_debug_malloc directly, with png_ptr == NULL which is OK
|
|
532 |
*/
|
2
|
533 |
|
|
534 |
if (size == 0)
|
|
535 |
return (NULL);
|
|
536 |
|
|
537 |
/* This calls the library allocator twice, once to get the requested
|
|
538 |
buffer and once to get a new free list entry. */
|
|
539 |
{
|
|
540 |
/* Disable malloc_fn and free_fn */
|
|
541 |
memory_infop pinfo;
|
|
542 |
png_set_mem_fn(png_ptr, NULL, NULL, NULL);
|
|
543 |
pinfo = (memory_infop)png_malloc(png_ptr,
|
29913
|
544 |
(sizeof *pinfo));
|
2
|
545 |
pinfo->size = size;
|
|
546 |
current_allocation += size;
|
|
547 |
total_allocation += size;
|
|
548 |
num_allocations ++;
|
10576
|
549 |
|
2
|
550 |
if (current_allocation > maximum_allocation)
|
|
551 |
maximum_allocation = current_allocation;
|
10576
|
552 |
|
|
553 |
pinfo->pointer = png_malloc(png_ptr, size);
|
2
|
554 |
/* Restore malloc_fn and free_fn */
|
10576
|
555 |
|
|
556 |
png_set_mem_fn(png_ptr,
|
|
557 |
NULL, png_debug_malloc, png_debug_free);
|
|
558 |
|
2
|
559 |
if (size != 0 && pinfo->pointer == NULL)
|
|
560 |
{
|
|
561 |
current_allocation -= size;
|
|
562 |
total_allocation -= size;
|
|
563 |
png_error(png_ptr,
|
10576
|
564 |
"out of memory in pngtest->png_debug_malloc");
|
2
|
565 |
}
|
10576
|
566 |
|
2
|
567 |
pinfo->next = pinformation;
|
|
568 |
pinformation = pinfo;
|
|
569 |
/* Make sure the caller isn't assuming zeroed memory. */
|
29913
|
570 |
memset(pinfo->pointer, 0xdd, pinfo->size);
|
10576
|
571 |
|
29913
|
572 |
if (verbose != 0)
|
10576
|
573 |
printf("png_malloc %lu bytes at %p\n", (unsigned long)size,
|
|
574 |
pinfo->pointer);
|
|
575 |
|
2
|
576 |
return (png_voidp)(pinfo->pointer);
|
|
577 |
}
|
|
578 |
}
|
|
579 |
|
|
580 |
/* Free a pointer. It is removed from the list at the same time. */
|
10576
|
581 |
void PNGCBAPI
|
2
|
582 |
png_debug_free(png_structp png_ptr, png_voidp ptr)
|
|
583 |
{
|
|
584 |
if (png_ptr == NULL)
|
|
585 |
fprintf(STDERR, "NULL pointer to png_debug_free.\n");
|
10576
|
586 |
|
2
|
587 |
if (ptr == 0)
|
|
588 |
{
|
|
589 |
#if 0 /* This happens all the time. */
|
|
590 |
fprintf(STDERR, "WARNING: freeing NULL pointer\n");
|
|
591 |
#endif
|
|
592 |
return;
|
|
593 |
}
|
|
594 |
|
|
595 |
/* Unlink the element from the list. */
|
|
596 |
{
|
29913
|
597 |
memory_infop *ppinfo = &pinformation;
|
10576
|
598 |
|
2
|
599 |
for (;;)
|
|
600 |
{
|
|
601 |
memory_infop pinfo = *ppinfo;
|
10576
|
602 |
|
2
|
603 |
if (pinfo->pointer == ptr)
|
|
604 |
{
|
|
605 |
*ppinfo = pinfo->next;
|
|
606 |
current_allocation -= pinfo->size;
|
|
607 |
if (current_allocation < 0)
|
|
608 |
fprintf(STDERR, "Duplicate free of memory\n");
|
|
609 |
/* We must free the list element too, but first kill
|
|
610 |
the memory that is to be freed. */
|
29913
|
611 |
memset(ptr, 0x55, pinfo->size);
|
|
612 |
if (pinfo != NULL)
|
|
613 |
free(pinfo);
|
10576
|
614 |
pinfo = NULL;
|
2
|
615 |
break;
|
|
616 |
}
|
10576
|
617 |
|
2
|
618 |
if (pinfo->next == NULL)
|
|
619 |
{
|
29913
|
620 |
fprintf(STDERR, "Pointer %p not found\n", ptr);
|
2
|
621 |
break;
|
|
622 |
}
|
10576
|
623 |
|
2
|
624 |
ppinfo = &pinfo->next;
|
|
625 |
}
|
|
626 |
}
|
|
627 |
|
|
628 |
/* Finally free the data. */
|
29913
|
629 |
if (verbose != 0)
|
10576
|
630 |
printf("Freeing %p\n", ptr);
|
|
631 |
|
29913
|
632 |
if (ptr != NULL)
|
|
633 |
free(ptr);
|
10576
|
634 |
ptr = NULL;
|
2
|
635 |
}
|
29913
|
636 |
#endif /* USER_MEM && DEBUG */
|
2
|
637 |
/* END of code to test memory allocation/deallocation */
|
|
638 |
|
10576
|
639 |
|
29913
|
640 |
#ifdef PNG_READ_USER_CHUNKS_SUPPORTED
|
10576
|
641 |
/* Demonstration of user chunk support of the sTER and vpAg chunks */
|
|
642 |
|
|
643 |
/* (sTER is a public chunk not yet known by libpng. vpAg is a private
|
|
644 |
chunk used in ImageMagick to store "virtual page" size). */
|
|
645 |
|
29913
|
646 |
static struct user_chunk_data
|
|
647 |
{
|
|
648 |
png_const_infop info_ptr;
|
|
649 |
png_uint_32 vpAg_width, vpAg_height;
|
|
650 |
png_byte vpAg_units;
|
|
651 |
png_byte sTER_mode;
|
|
652 |
int location[2];
|
|
653 |
}
|
|
654 |
user_chunk_data;
|
|
655 |
|
|
656 |
/* Used for location and order; zero means nothing. */
|
|
657 |
#define have_sTER 0x01
|
|
658 |
#define have_vpAg 0x02
|
|
659 |
#define before_PLTE 0x10
|
|
660 |
#define before_IDAT 0x20
|
|
661 |
#define after_IDAT 0x40
|
|
662 |
|
|
663 |
static void
|
|
664 |
init_callback_info(png_const_infop info_ptr)
|
|
665 |
{
|
|
666 |
MEMZERO(user_chunk_data);
|
|
667 |
user_chunk_data.info_ptr = info_ptr;
|
|
668 |
}
|
|
669 |
|
|
670 |
static int
|
|
671 |
set_location(png_structp png_ptr, struct user_chunk_data *data, int what)
|
|
672 |
{
|
|
673 |
int location;
|
10576
|
674 |
|
29913
|
675 |
if ((data->location[0] & what) != 0 || (data->location[1] & what) != 0)
|
|
676 |
return 0; /* already have one of these */
|
|
677 |
|
|
678 |
/* Find where we are (the code below zeroes info_ptr to indicate that the
|
|
679 |
* chunks before the first IDAT have been read.)
|
|
680 |
*/
|
|
681 |
if (data->info_ptr == NULL) /* after IDAT */
|
|
682 |
location = what | after_IDAT;
|
|
683 |
|
|
684 |
else if (png_get_valid(png_ptr, data->info_ptr, PNG_INFO_PLTE) != 0)
|
|
685 |
location = what | before_IDAT;
|
|
686 |
|
|
687 |
else
|
|
688 |
location = what | before_PLTE;
|
10576
|
689 |
|
29913
|
690 |
if (data->location[0] == 0)
|
|
691 |
data->location[0] = location;
|
|
692 |
|
|
693 |
else
|
|
694 |
data->location[1] = location;
|
|
695 |
|
|
696 |
return 1; /* handled */
|
|
697 |
}
|
|
698 |
|
|
699 |
static int PNGCBAPI
|
|
700 |
read_user_chunk_callback(png_struct *png_ptr, png_unknown_chunkp chunk)
|
10576
|
701 |
{
|
29913
|
702 |
struct user_chunk_data *my_user_chunk_data =
|
|
703 |
(struct user_chunk_data*)png_get_user_chunk_ptr(png_ptr);
|
|
704 |
|
|
705 |
if (my_user_chunk_data == NULL)
|
|
706 |
png_error(png_ptr, "lost user chunk pointer");
|
10576
|
707 |
|
|
708 |
/* Return one of the following:
|
|
709 |
* return (-n); chunk had an error
|
|
710 |
* return (0); did not recognize
|
|
711 |
* return (n); success
|
|
712 |
*
|
|
713 |
* The unknown chunk structure contains the chunk data:
|
|
714 |
* png_byte name[5];
|
|
715 |
* png_byte *data;
|
|
716 |
* png_size_t size;
|
|
717 |
*
|
|
718 |
* Note that libpng has already taken care of the CRC handling.
|
|
719 |
*/
|
|
720 |
|
|
721 |
if (chunk->name[0] == 115 && chunk->name[1] == 84 && /* s T */
|
|
722 |
chunk->name[2] == 69 && chunk->name[3] == 82) /* E R */
|
|
723 |
{
|
|
724 |
/* Found sTER chunk */
|
|
725 |
if (chunk->size != 1)
|
|
726 |
return (-1); /* Error return */
|
|
727 |
|
|
728 |
if (chunk->data[0] != 0 && chunk->data[0] != 1)
|
|
729 |
return (-1); /* Invalid mode */
|
|
730 |
|
29913
|
731 |
if (set_location(png_ptr, my_user_chunk_data, have_sTER) != 0)
|
|
732 |
{
|
|
733 |
my_user_chunk_data->sTER_mode=chunk->data[0];
|
|
734 |
return (1);
|
|
735 |
}
|
|
736 |
|
|
737 |
else
|
|
738 |
return (0); /* duplicate sTER - give it to libpng */
|
10576
|
739 |
}
|
|
740 |
|
|
741 |
if (chunk->name[0] != 118 || chunk->name[1] != 112 || /* v p */
|
|
742 |
chunk->name[2] != 65 || chunk->name[3] != 103) /* A g */
|
|
743 |
return (0); /* Did not recognize */
|
|
744 |
|
|
745 |
/* Found ImageMagick vpAg chunk */
|
|
746 |
|
|
747 |
if (chunk->size != 9)
|
|
748 |
return (-1); /* Error return */
|
|
749 |
|
29913
|
750 |
if (set_location(png_ptr, my_user_chunk_data, have_vpAg) == 0)
|
|
751 |
return (0); /* duplicate vpAg */
|
10576
|
752 |
|
29913
|
753 |
my_user_chunk_data->vpAg_width = png_get_uint_31(png_ptr, chunk->data);
|
|
754 |
my_user_chunk_data->vpAg_height = png_get_uint_31(png_ptr, chunk->data + 4);
|
|
755 |
my_user_chunk_data->vpAg_units = chunk->data[8];
|
10576
|
756 |
|
|
757 |
return (1);
|
29913
|
758 |
}
|
10576
|
759 |
|
29913
|
760 |
#ifdef PNG_WRITE_SUPPORTED
|
|
761 |
static void
|
|
762 |
write_sTER_chunk(png_structp write_ptr)
|
|
763 |
{
|
|
764 |
png_byte sTER[5] = {115, 84, 69, 82, '\0'};
|
|
765 |
|
|
766 |
if (verbose != 0)
|
|
767 |
fprintf(STDERR, "\n stereo mode = %d\n", user_chunk_data.sTER_mode);
|
|
768 |
|
|
769 |
png_write_chunk(write_ptr, sTER, &user_chunk_data.sTER_mode, 1);
|
10576
|
770 |
}
|
29913
|
771 |
|
|
772 |
static void
|
|
773 |
write_vpAg_chunk(png_structp write_ptr)
|
|
774 |
{
|
|
775 |
png_byte vpAg[5] = {118, 112, 65, 103, '\0'};
|
|
776 |
|
|
777 |
png_byte vpag_chunk_data[9];
|
|
778 |
|
|
779 |
if (verbose != 0)
|
|
780 |
fprintf(STDERR, " vpAg = %lu x %lu, units = %d\n",
|
|
781 |
(unsigned long)user_chunk_data.vpAg_width,
|
|
782 |
(unsigned long)user_chunk_data.vpAg_height,
|
|
783 |
user_chunk_data.vpAg_units);
|
|
784 |
|
|
785 |
png_save_uint_32(vpag_chunk_data, user_chunk_data.vpAg_width);
|
|
786 |
png_save_uint_32(vpag_chunk_data + 4, user_chunk_data.vpAg_height);
|
|
787 |
vpag_chunk_data[8] = user_chunk_data.vpAg_units;
|
|
788 |
png_write_chunk(write_ptr, vpAg, vpag_chunk_data, 9);
|
|
789 |
}
|
|
790 |
|
|
791 |
static void
|
|
792 |
write_chunks(png_structp write_ptr, int location)
|
|
793 |
{
|
|
794 |
int i;
|
|
795 |
|
|
796 |
/* Notice that this preserves the original chunk order, however chunks
|
|
797 |
* intercepted by the callback will be written *after* chunks passed to
|
|
798 |
* libpng. This will actually reverse a pair of sTER chunks or a pair of
|
|
799 |
* vpAg chunks, resulting in an error later. This is not worth worrying
|
|
800 |
* about - the chunks should not be duplicated!
|
|
801 |
*/
|
|
802 |
for (i=0; i<2; ++i)
|
|
803 |
{
|
|
804 |
if (user_chunk_data.location[i] == (location | have_sTER))
|
|
805 |
write_sTER_chunk(write_ptr);
|
|
806 |
|
|
807 |
else if (user_chunk_data.location[i] == (location | have_vpAg))
|
|
808 |
write_vpAg_chunk(write_ptr);
|
|
809 |
}
|
|
810 |
}
|
|
811 |
#endif /* WRITE */
|
|
812 |
#else /* !READ_USER_CHUNKS */
|
|
813 |
# define write_chunks(pp,loc) ((void)0)
|
10576
|
814 |
#endif
|
|
815 |
/* END of code to demonstrate user chunk support */
|
|
816 |
|
29913
|
817 |
/* START of code to check that libpng has the required text support; this only
|
|
818 |
* checks for the write support because if read support is missing the chunk
|
|
819 |
* will simply not be reported back to pngtest.
|
|
820 |
*/
|
|
821 |
#ifdef PNG_TEXT_SUPPORTED
|
|
822 |
static void
|
|
823 |
pngtest_check_text_support(png_const_structp png_ptr, png_textp text_ptr,
|
|
824 |
int num_text)
|
|
825 |
{
|
|
826 |
while (num_text > 0)
|
|
827 |
{
|
|
828 |
switch (text_ptr[--num_text].compression)
|
|
829 |
{
|
|
830 |
case PNG_TEXT_COMPRESSION_NONE:
|
|
831 |
break;
|
|
832 |
|
|
833 |
case PNG_TEXT_COMPRESSION_zTXt:
|
|
834 |
# ifndef PNG_WRITE_zTXt_SUPPORTED
|
|
835 |
++unsupported_chunks;
|
|
836 |
# endif
|
|
837 |
break;
|
|
838 |
|
|
839 |
case PNG_ITXT_COMPRESSION_NONE:
|
|
840 |
case PNG_ITXT_COMPRESSION_zTXt:
|
|
841 |
# ifndef PNG_WRITE_iTXt_SUPPORTED
|
|
842 |
++unsupported_chunks;
|
|
843 |
# endif
|
|
844 |
break;
|
|
845 |
|
|
846 |
default:
|
|
847 |
/* This is an error */
|
|
848 |
png_error(png_ptr, "invalid text chunk compression field");
|
|
849 |
break;
|
|
850 |
}
|
|
851 |
}
|
|
852 |
}
|
|
853 |
#endif
|
|
854 |
/* END of code to check that libpng has the required text support */
|
|
855 |
|
2
|
856 |
/* Test one file */
|
29913
|
857 |
static int
|
2
|
858 |
test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
|
859 |
{
|
|
860 |
static png_FILE_p fpin;
|
|
861 |
static png_FILE_p fpout; /* "static" prevents setjmp corruption */
|
29913
|
862 |
pngtest_error_parameters error_parameters;
|
2
|
863 |
png_structp read_ptr;
|
|
864 |
png_infop read_info_ptr, end_info_ptr;
|
|
865 |
#ifdef PNG_WRITE_SUPPORTED
|
|
866 |
png_structp write_ptr;
|
|
867 |
png_infop write_info_ptr;
|
|
868 |
png_infop write_end_info_ptr;
|
29913
|
869 |
int interlace_preserved = 1;
|
2
|
870 |
#else
|
|
871 |
png_structp write_ptr = NULL;
|
|
872 |
png_infop write_info_ptr = NULL;
|
|
873 |
png_infop write_end_info_ptr = NULL;
|
|
874 |
#endif
|
|
875 |
png_bytep row_buf;
|
|
876 |
png_uint_32 y;
|
|
877 |
png_uint_32 width, height;
|
29913
|
878 |
int num_pass = 1, pass;
|
2
|
879 |
int bit_depth, color_type;
|
|
880 |
|
|
881 |
row_buf = NULL;
|
29913
|
882 |
error_parameters.file_name = inname;
|
2
|
883 |
|
|
884 |
if ((fpin = fopen(inname, "rb")) == NULL)
|
|
885 |
{
|
|
886 |
fprintf(STDERR, "Could not find input file %s\n", inname);
|
|
887 |
return (1);
|
|
888 |
}
|
|
889 |
|
|
890 |
if ((fpout = fopen(outname, "wb")) == NULL)
|
|
891 |
{
|
|
892 |
fprintf(STDERR, "Could not open output file %s\n", outname);
|
|
893 |
FCLOSE(fpin);
|
|
894 |
return (1);
|
|
895 |
}
|
|
896 |
|
10576
|
897 |
pngtest_debug("Allocating read and write structures");
|
2
|
898 |
#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
|
10576
|
899 |
read_ptr =
|
|
900 |
png_create_read_struct_2(PNG_LIBPNG_VER_STRING, NULL,
|
|
901 |
NULL, NULL, NULL, png_debug_malloc, png_debug_free);
|
2
|
902 |
#else
|
10576
|
903 |
read_ptr =
|
|
904 |
png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
2
|
905 |
#endif
|
29913
|
906 |
png_set_error_fn(read_ptr, &error_parameters, pngtest_error,
|
|
907 |
pngtest_warning);
|
10576
|
908 |
|
2
|
909 |
#ifdef PNG_WRITE_SUPPORTED
|
|
910 |
#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
|
10576
|
911 |
write_ptr =
|
|
912 |
png_create_write_struct_2(PNG_LIBPNG_VER_STRING, NULL,
|
|
913 |
NULL, NULL, NULL, png_debug_malloc, png_debug_free);
|
2
|
914 |
#else
|
10576
|
915 |
write_ptr =
|
|
916 |
png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
2
|
917 |
#endif
|
29913
|
918 |
png_set_error_fn(write_ptr, &error_parameters, pngtest_error,
|
|
919 |
pngtest_warning);
|
2
|
920 |
#endif
|
10576
|
921 |
pngtest_debug("Allocating read_info, write_info and end_info structures");
|
2
|
922 |
read_info_ptr = png_create_info_struct(read_ptr);
|
|
923 |
end_info_ptr = png_create_info_struct(read_ptr);
|
|
924 |
#ifdef PNG_WRITE_SUPPORTED
|
|
925 |
write_info_ptr = png_create_info_struct(write_ptr);
|
|
926 |
write_end_info_ptr = png_create_info_struct(write_ptr);
|
|
927 |
#endif
|
|
928 |
|
29913
|
929 |
#ifdef PNG_READ_USER_CHUNKS_SUPPORTED
|
|
930 |
init_callback_info(read_info_ptr);
|
|
931 |
png_set_read_user_chunk_fn(read_ptr, &user_chunk_data,
|
|
932 |
read_user_chunk_callback);
|
|
933 |
#endif
|
|
934 |
|
2
|
935 |
#ifdef PNG_SETJMP_SUPPORTED
|
10576
|
936 |
pngtest_debug("Setting jmpbuf for read struct");
|
2
|
937 |
if (setjmp(png_jmpbuf(read_ptr)))
|
|
938 |
{
|
|
939 |
fprintf(STDERR, "%s -> %s: libpng read error\n", inname, outname);
|
10576
|
940 |
png_free(read_ptr, row_buf);
|
|
941 |
row_buf = NULL;
|
2
|
942 |
png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr);
|
|
943 |
#ifdef PNG_WRITE_SUPPORTED
|
|
944 |
png_destroy_info_struct(write_ptr, &write_end_info_ptr);
|
|
945 |
png_destroy_write_struct(&write_ptr, &write_info_ptr);
|
|
946 |
#endif
|
|
947 |
FCLOSE(fpin);
|
|
948 |
FCLOSE(fpout);
|
|
949 |
return (1);
|
|
950 |
}
|
|
951 |
|
|
952 |
#ifdef PNG_WRITE_SUPPORTED
|
10576
|
953 |
pngtest_debug("Setting jmpbuf for write struct");
|
|
954 |
|
2
|
955 |
if (setjmp(png_jmpbuf(write_ptr)))
|
|
956 |
{
|
|
957 |
fprintf(STDERR, "%s -> %s: libpng write error\n", inname, outname);
|
|
958 |
png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr);
|
|
959 |
png_destroy_info_struct(write_ptr, &write_end_info_ptr);
|
|
960 |
#ifdef PNG_WRITE_SUPPORTED
|
|
961 |
png_destroy_write_struct(&write_ptr, &write_info_ptr);
|
|
962 |
#endif
|
|
963 |
FCLOSE(fpin);
|
|
964 |
FCLOSE(fpout);
|
|
965 |
return (1);
|
|
966 |
}
|
|
967 |
#endif
|
|
968 |
#endif
|
29913
|
969 |
|
|
970 |
if (strict != 0)
|
|
971 |
{
|
|
972 |
/* Treat png_benign_error() as errors on read */
|
|
973 |
png_set_benign_errors(read_ptr, 0);
|
|
974 |
|
|
975 |
#ifdef PNG_WRITE_SUPPORTED
|
|
976 |
/* Treat them as errors on write */
|
|
977 |
png_set_benign_errors(write_ptr, 0);
|
2
|
978 |
#endif
|
|
979 |
|
29913
|
980 |
/* if strict is not set, then app warnings and errors are treated as
|
|
981 |
* warnings in release builds, but not in unstable builds; this can be
|
|
982 |
* changed with '--relaxed'.
|
|
983 |
*/
|
|
984 |
}
|
|
985 |
|
|
986 |
else if (relaxed != 0)
|
|
987 |
{
|
|
988 |
/* Allow application (pngtest) errors and warnings to pass */
|
|
989 |
png_set_benign_errors(read_ptr, 1);
|
|
990 |
|
|
991 |
#ifdef PNG_WRITE_SUPPORTED
|
|
992 |
png_set_benign_errors(write_ptr, 1);
|
|
993 |
#endif
|
|
994 |
}
|
|
995 |
|
10576
|
996 |
pngtest_debug("Initializing input and output streams");
|
|
997 |
#ifdef PNG_STDIO_SUPPORTED
|
2
|
998 |
png_init_io(read_ptr, fpin);
|
|
999 |
# ifdef PNG_WRITE_SUPPORTED
|
|
1000 |
png_init_io(write_ptr, fpout);
|
|
1001 |
# endif
|
|
1002 |
#else
|
|
1003 |
png_set_read_fn(read_ptr, (png_voidp)fpin, pngtest_read_data);
|
|
1004 |
# ifdef PNG_WRITE_SUPPORTED
|
|
1005 |
png_set_write_fn(write_ptr, (png_voidp)fpout, pngtest_write_data,
|
10576
|
1006 |
# ifdef PNG_WRITE_FLUSH_SUPPORTED
|
2
|
1007 |
pngtest_flush);
|
|
1008 |
# else
|
|
1009 |
NULL);
|
|
1010 |
# endif
|
|
1011 |
# endif
|
|
1012 |
#endif
|
10576
|
1013 |
|
|
1014 |
if (status_dots_requested == 1)
|
2
|
1015 |
{
|
|
1016 |
#ifdef PNG_WRITE_SUPPORTED
|
|
1017 |
png_set_write_status_fn(write_ptr, write_row_callback);
|
|
1018 |
#endif
|
|
1019 |
png_set_read_status_fn(read_ptr, read_row_callback);
|
|
1020 |
}
|
10576
|
1021 |
|
2
|
1022 |
else
|
|
1023 |
{
|
|
1024 |
#ifdef PNG_WRITE_SUPPORTED
|
10576
|
1025 |
png_set_write_status_fn(write_ptr, NULL);
|
2
|
1026 |
#endif
|
10576
|
1027 |
png_set_read_status_fn(read_ptr, NULL);
|
2
|
1028 |
}
|
|
1029 |
|
10576
|
1030 |
#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
|
2
|
1031 |
{
|
10576
|
1032 |
int i;
|
|
1033 |
|
|
1034 |
for (i = 0; i<256; i++)
|
|
1035 |
filters_used[i] = 0;
|
|
1036 |
|
|
1037 |
png_set_read_user_transform_fn(read_ptr, count_filters);
|
2
|
1038 |
}
|
|
1039 |
#endif
|
10576
|
1040 |
#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
|
|
1041 |
zero_samples = 0;
|
2
|
1042 |
png_set_write_user_transform_fn(write_ptr, count_zero_samples);
|
|
1043 |
#endif
|
|
1044 |
|
29913
|
1045 |
#ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED
|
|
1046 |
/* Preserve all the unknown chunks, if possible. If this is disabled then,
|
|
1047 |
* even if the png_{get,set}_unknown_chunks stuff is enabled, we can't use
|
|
1048 |
* libpng to *save* the unknown chunks on read (because we can't switch the
|
|
1049 |
* save option on!)
|
|
1050 |
*
|
|
1051 |
* Notice that if SET_UNKNOWN_CHUNKS is *not* supported read will discard all
|
|
1052 |
* unknown chunks and write will write them all.
|
|
1053 |
*/
|
|
1054 |
#ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED
|
2
|
1055 |
png_set_keep_unknown_chunks(read_ptr, PNG_HANDLE_CHUNK_ALWAYS,
|
10576
|
1056 |
NULL, 0);
|
2
|
1057 |
#endif
|
10576
|
1058 |
#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
|
29913
|
1059 |
png_set_keep_unknown_chunks(write_ptr, PNG_HANDLE_CHUNK_ALWAYS,
|
10576
|
1060 |
NULL, 0);
|
2
|
1061 |
#endif
|
29913
|
1062 |
#endif
|
2
|
1063 |
|
10576
|
1064 |
pngtest_debug("Reading info struct");
|
2
|
1065 |
png_read_info(read_ptr, read_info_ptr);
|
|
1066 |
|
29913
|
1067 |
#ifdef PNG_READ_USER_CHUNKS_SUPPORTED
|
|
1068 |
/* This is a bit of a hack; there is no obvious way in the callback function
|
|
1069 |
* to determine that the chunks before the first IDAT have been read, so
|
|
1070 |
* remove the info_ptr (which is only used to determine position relative to
|
|
1071 |
* PLTE) here to indicate that we are after the IDAT.
|
|
1072 |
*/
|
|
1073 |
user_chunk_data.info_ptr = NULL;
|
|
1074 |
#endif
|
|
1075 |
|
10576
|
1076 |
pngtest_debug("Transferring info struct");
|
2
|
1077 |
{
|
|
1078 |
int interlace_type, compression_type, filter_type;
|
|
1079 |
|
|
1080 |
if (png_get_IHDR(read_ptr, read_info_ptr, &width, &height, &bit_depth,
|
29913
|
1081 |
&color_type, &interlace_type, &compression_type, &filter_type) != 0)
|
2
|
1082 |
{
|
|
1083 |
png_set_IHDR(write_ptr, write_info_ptr, width, height, bit_depth,
|
|
1084 |
color_type, interlace_type, compression_type, filter_type);
|
29913
|
1085 |
#ifndef PNG_READ_INTERLACING_SUPPORTED
|
|
1086 |
/* num_pass will not be set below, set it here if the image is
|
|
1087 |
* interlaced: what happens is that write interlacing is *not* turned
|
|
1088 |
* on an the partial interlaced rows are written directly.
|
|
1089 |
*/
|
|
1090 |
switch (interlace_type)
|
|
1091 |
{
|
|
1092 |
case PNG_INTERLACE_NONE:
|
|
1093 |
num_pass = 1;
|
|
1094 |
break;
|
|
1095 |
|
|
1096 |
case PNG_INTERLACE_ADAM7:
|
|
1097 |
num_pass = 7;
|
|
1098 |
break;
|
|
1099 |
|
|
1100 |
default:
|
|
1101 |
png_error(read_ptr, "invalid interlace type");
|
|
1102 |
/*NOT REACHED*/
|
|
1103 |
}
|
2
|
1104 |
#endif
|
|
1105 |
}
|
|
1106 |
}
|
10576
|
1107 |
#ifdef PNG_FIXED_POINT_SUPPORTED
|
|
1108 |
#ifdef PNG_cHRM_SUPPORTED
|
2
|
1109 |
{
|
|
1110 |
png_fixed_point white_x, white_y, red_x, red_y, green_x, green_y, blue_x,
|
|
1111 |
blue_y;
|
10576
|
1112 |
|
|
1113 |
if (png_get_cHRM_fixed(read_ptr, read_info_ptr, &white_x, &white_y,
|
29913
|
1114 |
&red_x, &red_y, &green_x, &green_y, &blue_x, &blue_y) != 0)
|
2
|
1115 |
{
|
|
1116 |
png_set_cHRM_fixed(write_ptr, write_info_ptr, white_x, white_y, red_x,
|
|
1117 |
red_y, green_x, green_y, blue_x, blue_y);
|
|
1118 |
}
|
|
1119 |
}
|
|
1120 |
#endif
|
10576
|
1121 |
#ifdef PNG_gAMA_SUPPORTED
|
2
|
1122 |
{
|
|
1123 |
png_fixed_point gamma;
|
|
1124 |
|
29913
|
1125 |
if (png_get_gAMA_fixed(read_ptr, read_info_ptr, &gamma) != 0)
|
2
|
1126 |
png_set_gAMA_fixed(write_ptr, write_info_ptr, gamma);
|
|
1127 |
}
|
|
1128 |
#endif
|
|
1129 |
#else /* Use floating point versions */
|
10576
|
1130 |
#ifdef PNG_FLOATING_POINT_SUPPORTED
|
|
1131 |
#ifdef PNG_cHRM_SUPPORTED
|
2
|
1132 |
{
|
|
1133 |
double white_x, white_y, red_x, red_y, green_x, green_y, blue_x,
|
|
1134 |
blue_y;
|
10576
|
1135 |
|
2
|
1136 |
if (png_get_cHRM(read_ptr, read_info_ptr, &white_x, &white_y, &red_x,
|
29913
|
1137 |
&red_y, &green_x, &green_y, &blue_x, &blue_y) != 0)
|
2
|
1138 |
{
|
|
1139 |
png_set_cHRM(write_ptr, write_info_ptr, white_x, white_y, red_x,
|
|
1140 |
red_y, green_x, green_y, blue_x, blue_y);
|
|
1141 |
}
|
|
1142 |
}
|
|
1143 |
#endif
|
10576
|
1144 |
#ifdef PNG_gAMA_SUPPORTED
|
2
|
1145 |
{
|
|
1146 |
double gamma;
|
|
1147 |
|
29913
|
1148 |
if (png_get_gAMA(read_ptr, read_info_ptr, &gamma) != 0)
|
2
|
1149 |
png_set_gAMA(write_ptr, write_info_ptr, gamma);
|
|
1150 |
}
|
|
1151 |
#endif
|
10576
|
1152 |
#endif /* Floating point */
|
|
1153 |
#endif /* Fixed point */
|
|
1154 |
#ifdef PNG_iCCP_SUPPORTED
|
2
|
1155 |
{
|
|
1156 |
png_charp name;
|
10576
|
1157 |
png_bytep profile;
|
2
|
1158 |
png_uint_32 proflen;
|
|
1159 |
int compression_type;
|
|
1160 |
|
|
1161 |
if (png_get_iCCP(read_ptr, read_info_ptr, &name, &compression_type,
|
29913
|
1162 |
&profile, &proflen) != 0)
|
2
|
1163 |
{
|
|
1164 |
png_set_iCCP(write_ptr, write_info_ptr, name, compression_type,
|
|
1165 |
profile, proflen);
|
|
1166 |
}
|
|
1167 |
}
|
|
1168 |
#endif
|
10576
|
1169 |
#ifdef PNG_sRGB_SUPPORTED
|
2
|
1170 |
{
|
|
1171 |
int intent;
|
|
1172 |
|
29913
|
1173 |
if (png_get_sRGB(read_ptr, read_info_ptr, &intent) != 0)
|
2
|
1174 |
png_set_sRGB(write_ptr, write_info_ptr, intent);
|
|
1175 |
}
|
|
1176 |
#endif
|
|
1177 |
{
|
|
1178 |
png_colorp palette;
|
|
1179 |
int num_palette;
|
|
1180 |
|
29913
|
1181 |
if (png_get_PLTE(read_ptr, read_info_ptr, &palette, &num_palette) != 0)
|
2
|
1182 |
png_set_PLTE(write_ptr, write_info_ptr, palette, num_palette);
|
|
1183 |
}
|
10576
|
1184 |
#ifdef PNG_bKGD_SUPPORTED
|
2
|
1185 |
{
|
|
1186 |
png_color_16p background;
|
|
1187 |
|
29913
|
1188 |
if (png_get_bKGD(read_ptr, read_info_ptr, &background) != 0)
|
2
|
1189 |
{
|
|
1190 |
png_set_bKGD(write_ptr, write_info_ptr, background);
|
|
1191 |
}
|
|
1192 |
}
|
|
1193 |
#endif
|
10576
|
1194 |
#ifdef PNG_hIST_SUPPORTED
|
2
|
1195 |
{
|
|
1196 |
png_uint_16p hist;
|
|
1197 |
|
29913
|
1198 |
if (png_get_hIST(read_ptr, read_info_ptr, &hist) != 0)
|
2
|
1199 |
png_set_hIST(write_ptr, write_info_ptr, hist);
|
|
1200 |
}
|
|
1201 |
#endif
|
10576
|
1202 |
#ifdef PNG_oFFs_SUPPORTED
|
2
|
1203 |
{
|
|
1204 |
png_int_32 offset_x, offset_y;
|
|
1205 |
int unit_type;
|
|
1206 |
|
10576
|
1207 |
if (png_get_oFFs(read_ptr, read_info_ptr, &offset_x, &offset_y,
|
29913
|
1208 |
&unit_type) != 0)
|
2
|
1209 |
{
|
|
1210 |
png_set_oFFs(write_ptr, write_info_ptr, offset_x, offset_y, unit_type);
|
|
1211 |
}
|
|
1212 |
}
|
|
1213 |
#endif
|
10576
|
1214 |
#ifdef PNG_pCAL_SUPPORTED
|
2
|
1215 |
{
|
|
1216 |
png_charp purpose, units;
|
|
1217 |
png_charpp params;
|
|
1218 |
png_int_32 X0, X1;
|
|
1219 |
int type, nparams;
|
|
1220 |
|
|
1221 |
if (png_get_pCAL(read_ptr, read_info_ptr, &purpose, &X0, &X1, &type,
|
29913
|
1222 |
&nparams, &units, ¶ms) != 0)
|
2
|
1223 |
{
|
|
1224 |
png_set_pCAL(write_ptr, write_info_ptr, purpose, X0, X1, type,
|
|
1225 |
nparams, units, params);
|
|
1226 |
}
|
|
1227 |
}
|
|
1228 |
#endif
|
10576
|
1229 |
#ifdef PNG_pHYs_SUPPORTED
|
2
|
1230 |
{
|
|
1231 |
png_uint_32 res_x, res_y;
|
|
1232 |
int unit_type;
|
|
1233 |
|
29913
|
1234 |
if (png_get_pHYs(read_ptr, read_info_ptr, &res_x, &res_y,
|
|
1235 |
&unit_type) != 0)
|
2
|
1236 |
png_set_pHYs(write_ptr, write_info_ptr, res_x, res_y, unit_type);
|
|
1237 |
}
|
|
1238 |
#endif
|
10576
|
1239 |
#ifdef PNG_sBIT_SUPPORTED
|
2
|
1240 |
{
|
|
1241 |
png_color_8p sig_bit;
|
|
1242 |
|
29913
|
1243 |
if (png_get_sBIT(read_ptr, read_info_ptr, &sig_bit) != 0)
|
2
|
1244 |
png_set_sBIT(write_ptr, write_info_ptr, sig_bit);
|
|
1245 |
}
|
|
1246 |
#endif
|
10576
|
1247 |
#ifdef PNG_sCAL_SUPPORTED
|
29913
|
1248 |
#if defined(PNG_FLOATING_POINT_SUPPORTED) && \
|
|
1249 |
defined(PNG_FLOATING_ARITHMETIC_SUPPORTED)
|
2
|
1250 |
{
|
|
1251 |
int unit;
|
|
1252 |
double scal_width, scal_height;
|
|
1253 |
|
|
1254 |
if (png_get_sCAL(read_ptr, read_info_ptr, &unit, &scal_width,
|
29913
|
1255 |
&scal_height) != 0)
|
2
|
1256 |
{
|
|
1257 |
png_set_sCAL(write_ptr, write_info_ptr, unit, scal_width, scal_height);
|
|
1258 |
}
|
|
1259 |
}
|
|
1260 |
#else
|
|
1261 |
#ifdef PNG_FIXED_POINT_SUPPORTED
|
|
1262 |
{
|
|
1263 |
int unit;
|
|
1264 |
png_charp scal_width, scal_height;
|
|
1265 |
|
|
1266 |
if (png_get_sCAL_s(read_ptr, read_info_ptr, &unit, &scal_width,
|
29913
|
1267 |
&scal_height) != 0)
|
2
|
1268 |
{
|
10576
|
1269 |
png_set_sCAL_s(write_ptr, write_info_ptr, unit, scal_width,
|
|
1270 |
scal_height);
|
2
|
1271 |
}
|
|
1272 |
}
|
|
1273 |
#endif
|
|
1274 |
#endif
|
|
1275 |
#endif
|
10576
|
1276 |
#ifdef PNG_TEXT_SUPPORTED
|
2
|
1277 |
{
|
|
1278 |
png_textp text_ptr;
|
|
1279 |
int num_text;
|
|
1280 |
|
|
1281 |
if (png_get_text(read_ptr, read_info_ptr, &text_ptr, &num_text) > 0)
|
|
1282 |
{
|
10576
|
1283 |
pngtest_debug1("Handling %d iTXt/tEXt/zTXt chunks", num_text);
|
29913
|
1284 |
|
|
1285 |
pngtest_check_text_support(read_ptr, text_ptr, num_text);
|
|
1286 |
|
|
1287 |
if (verbose != 0)
|
|
1288 |
{
|
|
1289 |
int i;
|
|
1290 |
|
|
1291 |
printf("\n");
|
|
1292 |
for (i=0; i<num_text; i++)
|
|
1293 |
{
|
|
1294 |
printf(" Text compression[%d]=%d\n",
|
|
1295 |
i, text_ptr[i].compression);
|
|
1296 |
}
|
|
1297 |
}
|
|
1298 |
|
2
|
1299 |
png_set_text(write_ptr, write_info_ptr, text_ptr, num_text);
|
|
1300 |
}
|
|
1301 |
}
|
|
1302 |
#endif
|
10576
|
1303 |
#ifdef PNG_tIME_SUPPORTED
|
2
|
1304 |
{
|
|
1305 |
png_timep mod_time;
|
|
1306 |
|
29913
|
1307 |
if (png_get_tIME(read_ptr, read_info_ptr, &mod_time) != 0)
|
2
|
1308 |
{
|
|
1309 |
png_set_tIME(write_ptr, write_info_ptr, mod_time);
|
10576
|
1310 |
#ifdef PNG_TIME_RFC1123_SUPPORTED
|
29913
|
1311 |
if (png_convert_to_rfc1123_buffer(tIME_string, mod_time) != 0)
|
|
1312 |
tIME_string[(sizeof tIME_string) - 1] = '\0';
|
10576
|
1313 |
|
29913
|
1314 |
else
|
|
1315 |
{
|
|
1316 |
strncpy(tIME_string, "*** invalid time ***", (sizeof tIME_string));
|
|
1317 |
tIME_string[(sizeof tIME_string) - 1] = '\0';
|
|
1318 |
}
|
|
1319 |
|
2
|
1320 |
tIME_chunk_present++;
|
29913
|
1321 |
#endif /* TIME_RFC1123 */
|
2
|
1322 |
}
|
|
1323 |
}
|
|
1324 |
#endif
|
10576
|
1325 |
#ifdef PNG_tRNS_SUPPORTED
|
2
|
1326 |
{
|
10576
|
1327 |
png_bytep trans_alpha;
|
2
|
1328 |
int num_trans;
|
10576
|
1329 |
png_color_16p trans_color;
|
2
|
1330 |
|
10576
|
1331 |
if (png_get_tRNS(read_ptr, read_info_ptr, &trans_alpha, &num_trans,
|
29913
|
1332 |
&trans_color) != 0)
|
2
|
1333 |
{
|
10576
|
1334 |
int sample_max = (1 << bit_depth);
|
|
1335 |
/* libpng doesn't reject a tRNS chunk with out-of-range samples */
|
|
1336 |
if (!((color_type == PNG_COLOR_TYPE_GRAY &&
|
|
1337 |
(int)trans_color->gray > sample_max) ||
|
|
1338 |
(color_type == PNG_COLOR_TYPE_RGB &&
|
|
1339 |
((int)trans_color->red > sample_max ||
|
|
1340 |
(int)trans_color->green > sample_max ||
|
|
1341 |
(int)trans_color->blue > sample_max))))
|
|
1342 |
png_set_tRNS(write_ptr, write_info_ptr, trans_alpha, num_trans,
|
|
1343 |
trans_color);
|
2
|
1344 |
}
|
|
1345 |
}
|
|
1346 |
#endif
|
10576
|
1347 |
#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
|
2
|
1348 |
{
|
|
1349 |
png_unknown_chunkp unknowns;
|
10576
|
1350 |
int num_unknowns = png_get_unknown_chunks(read_ptr, read_info_ptr,
|
2
|
1351 |
&unknowns);
|
10576
|
1352 |
|
29913
|
1353 |
if (num_unknowns != 0)
|
2
|
1354 |
{
|
|
1355 |
png_set_unknown_chunks(write_ptr, write_info_ptr, unknowns,
|
|
1356 |
num_unknowns);
|
29913
|
1357 |
#if PNG_LIBPNG_VER < 10600
|
10576
|
1358 |
/* Copy the locations from the read_info_ptr. The automatically
|
29913
|
1359 |
* generated locations in write_end_info_ptr are wrong prior to 1.6.0
|
|
1360 |
* because they are reset from the write pointer (removed in 1.6.0).
|
10576
|
1361 |
*/
|
29913
|
1362 |
{
|
|
1363 |
int i;
|
|
1364 |
for (i = 0; i < num_unknowns; i++)
|
|
1365 |
png_set_unknown_chunk_location(write_ptr, write_info_ptr, i,
|
|
1366 |
unknowns[i].location);
|
|
1367 |
}
|
|
1368 |
#endif
|
2
|
1369 |
}
|
|
1370 |
}
|
|
1371 |
#endif
|
|
1372 |
|
|
1373 |
#ifdef PNG_WRITE_SUPPORTED
|
10576
|
1374 |
pngtest_debug("Writing info struct");
|
2
|
1375 |
|
29913
|
1376 |
/* Write the info in two steps so that if we write the 'unknown' chunks here
|
|
1377 |
* they go to the correct place.
|
|
1378 |
*/
|
|
1379 |
png_write_info_before_PLTE(write_ptr, write_info_ptr);
|
|
1380 |
|
|
1381 |
write_chunks(write_ptr, before_PLTE); /* before PLTE */
|
|
1382 |
|
2
|
1383 |
png_write_info(write_ptr, write_info_ptr);
|
10576
|
1384 |
|
29913
|
1385 |
write_chunks(write_ptr, before_IDAT); /* after PLTE */
|
2
|
1386 |
#endif
|
|
1387 |
|
|
1388 |
#ifdef SINGLE_ROWBUF_ALLOC
|
10576
|
1389 |
pngtest_debug("Allocating row buffer...");
|
2
|
1390 |
row_buf = (png_bytep)png_malloc(read_ptr,
|
|
1391 |
png_get_rowbytes(read_ptr, read_info_ptr));
|
10576
|
1392 |
|
|
1393 |
pngtest_debug1("\t0x%08lx", (unsigned long)row_buf);
|
2
|
1394 |
#endif /* SINGLE_ROWBUF_ALLOC */
|
10576
|
1395 |
pngtest_debug("Writing row data");
|
2
|
1396 |
|
29913
|
1397 |
#ifdef PNG_READ_INTERLACING_SUPPORTED
|
2
|
1398 |
num_pass = png_set_interlace_handling(read_ptr);
|
29913
|
1399 |
if (png_set_interlace_handling(write_ptr) != num_pass)
|
|
1400 |
png_error(write_ptr, "png_set_interlace_handling: inconsistent num_pass");
|
2
|
1401 |
#endif
|
|
1402 |
|
|
1403 |
#ifdef PNGTEST_TIMING
|
|
1404 |
t_stop = (float)clock();
|
|
1405 |
t_misc += (t_stop - t_start);
|
|
1406 |
t_start = t_stop;
|
|
1407 |
#endif
|
|
1408 |
for (pass = 0; pass < num_pass; pass++)
|
|
1409 |
{
|
10576
|
1410 |
pngtest_debug1("Writing row data for pass %d", pass);
|
2
|
1411 |
for (y = 0; y < height; y++)
|
|
1412 |
{
|
|
1413 |
#ifndef SINGLE_ROWBUF_ALLOC
|
10576
|
1414 |
pngtest_debug2("Allocating row buffer (pass %d, y = %u)...", pass, y);
|
29913
|
1415 |
|
2
|
1416 |
row_buf = (png_bytep)png_malloc(read_ptr,
|
|
1417 |
png_get_rowbytes(read_ptr, read_info_ptr));
|
10576
|
1418 |
|
29913
|
1419 |
pngtest_debug2("\t0x%08lx (%lu bytes)", (unsigned long)row_buf,
|
|
1420 |
(unsigned long)png_get_rowbytes(read_ptr, read_info_ptr));
|
10576
|
1421 |
|
2
|
1422 |
#endif /* !SINGLE_ROWBUF_ALLOC */
|
10576
|
1423 |
png_read_rows(read_ptr, (png_bytepp)&row_buf, NULL, 1);
|
2
|
1424 |
|
|
1425 |
#ifdef PNG_WRITE_SUPPORTED
|
|
1426 |
#ifdef PNGTEST_TIMING
|
|
1427 |
t_stop = (float)clock();
|
|
1428 |
t_decode += (t_stop - t_start);
|
|
1429 |
t_start = t_stop;
|
|
1430 |
#endif
|
|
1431 |
png_write_rows(write_ptr, (png_bytepp)&row_buf, 1);
|
|
1432 |
#ifdef PNGTEST_TIMING
|
|
1433 |
t_stop = (float)clock();
|
|
1434 |
t_encode += (t_stop - t_start);
|
|
1435 |
t_start = t_stop;
|
|
1436 |
#endif
|
29913
|
1437 |
#endif /* WRITE */
|
2
|
1438 |
|
|
1439 |
#ifndef SINGLE_ROWBUF_ALLOC
|
10576
|
1440 |
pngtest_debug2("Freeing row buffer (pass %d, y = %u)", pass, y);
|
2
|
1441 |
png_free(read_ptr, row_buf);
|
10576
|
1442 |
row_buf = NULL;
|
2
|
1443 |
#endif /* !SINGLE_ROWBUF_ALLOC */
|
|
1444 |
}
|
|
1445 |
}
|
|
1446 |
|
29913
|
1447 |
#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
|
|
1448 |
# ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
|
|
1449 |
png_free_data(read_ptr, read_info_ptr, PNG_FREE_UNKN, -1);
|
|
1450 |
# endif
|
|
1451 |
# ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
|
|
1452 |
png_free_data(write_ptr, write_info_ptr, PNG_FREE_UNKN, -1);
|
|
1453 |
# endif
|
2
|
1454 |
#endif
|
|
1455 |
|
10576
|
1456 |
pngtest_debug("Reading and writing end_info data");
|
2
|
1457 |
|
|
1458 |
png_read_end(read_ptr, end_info_ptr);
|
10576
|
1459 |
#ifdef PNG_TEXT_SUPPORTED
|
2
|
1460 |
{
|
|
1461 |
png_textp text_ptr;
|
|
1462 |
int num_text;
|
|
1463 |
|
|
1464 |
if (png_get_text(read_ptr, end_info_ptr, &text_ptr, &num_text) > 0)
|
|
1465 |
{
|
10576
|
1466 |
pngtest_debug1("Handling %d iTXt/tEXt/zTXt chunks", num_text);
|
29913
|
1467 |
|
|
1468 |
pngtest_check_text_support(read_ptr, text_ptr, num_text);
|
|
1469 |
|
|
1470 |
if (verbose != 0)
|
|
1471 |
{
|
|
1472 |
int i;
|
|
1473 |
|
|
1474 |
printf("\n");
|
|
1475 |
for (i=0; i<num_text; i++)
|
|
1476 |
{
|
|
1477 |
printf(" Text compression[%d]=%d\n",
|
|
1478 |
i, text_ptr[i].compression);
|
|
1479 |
}
|
|
1480 |
}
|
|
1481 |
|
2
|
1482 |
png_set_text(write_ptr, write_end_info_ptr, text_ptr, num_text);
|
|
1483 |
}
|
|
1484 |
}
|
|
1485 |
#endif
|
10576
|
1486 |
#ifdef PNG_tIME_SUPPORTED
|
2
|
1487 |
{
|
|
1488 |
png_timep mod_time;
|
|
1489 |
|
29913
|
1490 |
if (png_get_tIME(read_ptr, end_info_ptr, &mod_time) != 0)
|
2
|
1491 |
{
|
|
1492 |
png_set_tIME(write_ptr, write_end_info_ptr, mod_time);
|
10576
|
1493 |
#ifdef PNG_TIME_RFC1123_SUPPORTED
|
29913
|
1494 |
if (png_convert_to_rfc1123_buffer(tIME_string, mod_time) != 0)
|
|
1495 |
tIME_string[(sizeof tIME_string) - 1] = '\0';
|
10576
|
1496 |
|
29913
|
1497 |
else
|
|
1498 |
{
|
|
1499 |
strncpy(tIME_string, "*** invalid time ***", sizeof tIME_string);
|
|
1500 |
tIME_string[(sizeof tIME_string)-1] = '\0';
|
|
1501 |
}
|
|
1502 |
|
2
|
1503 |
tIME_chunk_present++;
|
29913
|
1504 |
#endif /* TIME_RFC1123 */
|
2
|
1505 |
}
|
|
1506 |
}
|
|
1507 |
#endif
|
10576
|
1508 |
#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
|
2
|
1509 |
{
|
|
1510 |
png_unknown_chunkp unknowns;
|
10576
|
1511 |
int num_unknowns = png_get_unknown_chunks(read_ptr, end_info_ptr,
|
2
|
1512 |
&unknowns);
|
10576
|
1513 |
|
29913
|
1514 |
if (num_unknowns != 0)
|
2
|
1515 |
{
|
|
1516 |
png_set_unknown_chunks(write_ptr, write_end_info_ptr, unknowns,
|
|
1517 |
num_unknowns);
|
29913
|
1518 |
#if PNG_LIBPNG_VER < 10600
|
10576
|
1519 |
/* Copy the locations from the read_info_ptr. The automatically
|
29913
|
1520 |
* generated locations in write_end_info_ptr are wrong prior to 1.6.0
|
|
1521 |
* because they are reset from the write pointer (removed in 1.6.0).
|
10576
|
1522 |
*/
|
29913
|
1523 |
{
|
|
1524 |
int i;
|
|
1525 |
for (i = 0; i < num_unknowns; i++)
|
|
1526 |
png_set_unknown_chunk_location(write_ptr, write_end_info_ptr, i,
|
|
1527 |
unknowns[i].location);
|
|
1528 |
}
|
|
1529 |
#endif
|
2
|
1530 |
}
|
|
1531 |
}
|
|
1532 |
#endif
|
29913
|
1533 |
|
2
|
1534 |
#ifdef PNG_WRITE_SUPPORTED
|
29913
|
1535 |
#ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED
|
|
1536 |
/* Normally one would use Z_DEFAULT_STRATEGY for text compression.
|
|
1537 |
* This is here just to make pngtest replicate the results from libpng
|
|
1538 |
* versions prior to 1.5.4, and to test this new API.
|
|
1539 |
*/
|
|
1540 |
png_set_text_compression_strategy(write_ptr, Z_FILTERED);
|
|
1541 |
#endif
|
|
1542 |
|
|
1543 |
/* When the unknown vpAg/sTER chunks are written by pngtest the only way to
|
|
1544 |
* do it is to write them *before* calling png_write_end. When unknown
|
|
1545 |
* chunks are written by libpng, however, they are written just before IEND.
|
|
1546 |
* There seems to be no way round this, however vpAg/sTER are not expected
|
|
1547 |
* after IDAT.
|
|
1548 |
*/
|
|
1549 |
write_chunks(write_ptr, after_IDAT);
|
|
1550 |
|
2
|
1551 |
png_write_end(write_ptr, write_end_info_ptr);
|
|
1552 |
#endif
|
|
1553 |
|
|
1554 |
#ifdef PNG_EASY_ACCESS_SUPPORTED
|
29913
|
1555 |
if (verbose != 0)
|
2
|
1556 |
{
|
|
1557 |
png_uint_32 iwidth, iheight;
|
|
1558 |
iwidth = png_get_image_width(write_ptr, write_info_ptr);
|
|
1559 |
iheight = png_get_image_height(write_ptr, write_info_ptr);
|
10576
|
1560 |
fprintf(STDERR, "\n Image width = %lu, height = %lu\n",
|
2
|
1561 |
(unsigned long)iwidth, (unsigned long)iheight);
|
|
1562 |
}
|
|
1563 |
#endif
|
|
1564 |
|
10576
|
1565 |
pngtest_debug("Destroying data structs");
|
2
|
1566 |
#ifdef SINGLE_ROWBUF_ALLOC
|
10576
|
1567 |
pngtest_debug("destroying row_buf for read_ptr");
|
2
|
1568 |
png_free(read_ptr, row_buf);
|
10576
|
1569 |
row_buf = NULL;
|
2
|
1570 |
#endif /* SINGLE_ROWBUF_ALLOC */
|
10576
|
1571 |
pngtest_debug("destroying read_ptr, read_info_ptr, end_info_ptr");
|
2
|
1572 |
png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr);
|
|
1573 |
#ifdef PNG_WRITE_SUPPORTED
|
10576
|
1574 |
pngtest_debug("destroying write_end_info_ptr");
|
2
|
1575 |
png_destroy_info_struct(write_ptr, &write_end_info_ptr);
|
10576
|
1576 |
pngtest_debug("destroying write_ptr, write_info_ptr");
|
2
|
1577 |
png_destroy_write_struct(&write_ptr, &write_info_ptr);
|
|
1578 |
#endif
|
10576
|
1579 |
pngtest_debug("Destruction complete.");
|
2
|
1580 |
|
|
1581 |
FCLOSE(fpin);
|
|
1582 |
FCLOSE(fpout);
|
|
1583 |
|
29913
|
1584 |
/* Summarize any warnings or errors and in 'strict' mode fail the test.
|
|
1585 |
* Unsupported chunks can result in warnings, in that case ignore the strict
|
|
1586 |
* setting, otherwise fail the test on warnings as well as errors.
|
|
1587 |
*/
|
|
1588 |
if (error_count > 0)
|
|
1589 |
{
|
|
1590 |
/* We don't really expect to get here because of the setjmp handling
|
|
1591 |
* above, but this is safe.
|
|
1592 |
*/
|
|
1593 |
fprintf(STDERR, "\n %s: %d libpng errors found (%d warnings)",
|
|
1594 |
inname, error_count, warning_count);
|
|
1595 |
|
|
1596 |
if (strict != 0)
|
|
1597 |
return (1);
|
|
1598 |
}
|
|
1599 |
|
|
1600 |
# ifdef PNG_WRITE_SUPPORTED
|
|
1601 |
/* If there we no write support nothing was written! */
|
|
1602 |
else if (unsupported_chunks > 0)
|
|
1603 |
{
|
|
1604 |
fprintf(STDERR, "\n %s: unsupported chunks (%d)%s",
|
|
1605 |
inname, unsupported_chunks, strict ? ": IGNORED --strict!" : "");
|
|
1606 |
}
|
|
1607 |
# endif
|
|
1608 |
|
|
1609 |
else if (warning_count > 0)
|
|
1610 |
{
|
|
1611 |
fprintf(STDERR, "\n %s: %d libpng warnings found",
|
|
1612 |
inname, warning_count);
|
|
1613 |
|
|
1614 |
if (strict != 0)
|
|
1615 |
return (1);
|
|
1616 |
}
|
|
1617 |
|
10576
|
1618 |
pngtest_debug("Opening files for comparison");
|
2
|
1619 |
if ((fpin = fopen(inname, "rb")) == NULL)
|
|
1620 |
{
|
|
1621 |
fprintf(STDERR, "Could not find file %s\n", inname);
|
|
1622 |
return (1);
|
|
1623 |
}
|
|
1624 |
|
|
1625 |
if ((fpout = fopen(outname, "rb")) == NULL)
|
|
1626 |
{
|
|
1627 |
fprintf(STDERR, "Could not find file %s\n", outname);
|
|
1628 |
FCLOSE(fpin);
|
|
1629 |
return (1);
|
|
1630 |
}
|
|
1631 |
|
29913
|
1632 |
#ifdef PNG_WRITE_SUPPORTED /* else nothing was written */
|
|
1633 |
if (interlace_preserved != 0) /* else the files will be changed */
|
2
|
1634 |
{
|
29913
|
1635 |
for (;;)
|
|
1636 |
{
|
|
1637 |
static int wrote_question = 0;
|
|
1638 |
png_size_t num_in, num_out;
|
|
1639 |
char inbuf[256], outbuf[256];
|
2
|
1640 |
|
29913
|
1641 |
num_in = fread(inbuf, 1, sizeof inbuf, fpin);
|
|
1642 |
num_out = fread(outbuf, 1, sizeof outbuf, fpout);
|
2
|
1643 |
|
29913
|
1644 |
if (num_in != num_out)
|
|
1645 |
{
|
|
1646 |
fprintf(STDERR, "\nFiles %s and %s are of a different size\n",
|
|
1647 |
inname, outname);
|
10576
|
1648 |
|
29913
|
1649 |
if (wrote_question == 0 && unsupported_chunks == 0)
|
|
1650 |
{
|
|
1651 |
fprintf(STDERR,
|
2
|
1652 |
" Was %s written with the same maximum IDAT chunk size (%d bytes),",
|
29913
|
1653 |
inname, PNG_ZBUF_SIZE);
|
|
1654 |
fprintf(STDERR,
|
|
1655 |
"\n filtering heuristic (libpng default), compression");
|
|
1656 |
fprintf(STDERR,
|
|
1657 |
" level (zlib default),\n and zlib version (%s)?\n\n",
|
|
1658 |
ZLIB_VERSION);
|
|
1659 |
wrote_question = 1;
|
|
1660 |
}
|
|
1661 |
|
|
1662 |
FCLOSE(fpin);
|
|
1663 |
FCLOSE(fpout);
|
|
1664 |
|
|
1665 |
if (strict != 0 && unsupported_chunks == 0)
|
|
1666 |
return (1);
|
|
1667 |
|
|
1668 |
else
|
|
1669 |
return (0);
|
2
|
1670 |
}
|
10576
|
1671 |
|
29913
|
1672 |
if (num_in == 0)
|
|
1673 |
break;
|
2
|
1674 |
|
29913
|
1675 |
if (memcmp(inbuf, outbuf, num_in))
|
2
|
1676 |
{
|
29913
|
1677 |
fprintf(STDERR, "\nFiles %s and %s are different\n", inname,
|
|
1678 |
outname);
|
|
1679 |
|
|
1680 |
if (wrote_question == 0 && unsupported_chunks == 0)
|
|
1681 |
{
|
|
1682 |
fprintf(STDERR,
|
2
|
1683 |
" Was %s written with the same maximum IDAT chunk size (%d bytes),",
|
29913
|
1684 |
inname, PNG_ZBUF_SIZE);
|
|
1685 |
fprintf(STDERR,
|
|
1686 |
"\n filtering heuristic (libpng default), compression");
|
|
1687 |
fprintf(STDERR,
|
|
1688 |
" level (zlib default),\n and zlib version (%s)?\n\n",
|
|
1689 |
ZLIB_VERSION);
|
|
1690 |
wrote_question = 1;
|
|
1691 |
}
|
|
1692 |
|
|
1693 |
FCLOSE(fpin);
|
|
1694 |
FCLOSE(fpout);
|
|
1695 |
|
|
1696 |
/* NOTE: the unsupported_chunks escape is permitted here because
|
|
1697 |
* unsupported text chunk compression will result in the compression
|
|
1698 |
* mode being changed (to NONE) yet, in the test case, the result
|
|
1699 |
* can be exactly the same size!
|
|
1700 |
*/
|
|
1701 |
if (strict != 0 && unsupported_chunks == 0)
|
|
1702 |
return (1);
|
|
1703 |
|
|
1704 |
else
|
|
1705 |
return (0);
|
2
|
1706 |
}
|
|
1707 |
}
|
|
1708 |
}
|
29913
|
1709 |
#endif /* WRITE */
|
2
|
1710 |
|
|
1711 |
FCLOSE(fpin);
|
|
1712 |
FCLOSE(fpout);
|
|
1713 |
|
|
1714 |
return (0);
|
|
1715 |
}
|
|
1716 |
|
10576
|
1717 |
/* Input and output filenames */
|
2
|
1718 |
#ifdef RISCOS
|
|
1719 |
static PNG_CONST char *inname = "pngtest/png";
|
|
1720 |
static PNG_CONST char *outname = "pngout/png";
|
|
1721 |
#else
|
|
1722 |
static PNG_CONST char *inname = "pngtest.png";
|
|
1723 |
static PNG_CONST char *outname = "pngout.png";
|
|
1724 |
#endif
|
|
1725 |
|
|
1726 |
int
|
|
1727 |
main(int argc, char *argv[])
|
|
1728 |
{
|
|
1729 |
int multiple = 0;
|
|
1730 |
int ierror = 0;
|
|
1731 |
|
10576
|
1732 |
fprintf(STDERR, "\n Testing libpng version %s\n", PNG_LIBPNG_VER_STRING);
|
2
|
1733 |
fprintf(STDERR, " with zlib version %s\n", ZLIB_VERSION);
|
10576
|
1734 |
fprintf(STDERR, "%s", png_get_copyright(NULL));
|
2
|
1735 |
/* Show the version of libpng used in building the library */
|
10576
|
1736 |
fprintf(STDERR, " library (%lu):%s",
|
2
|
1737 |
(unsigned long)png_access_version_number(),
|
|
1738 |
png_get_header_version(NULL));
|
10576
|
1739 |
|
2
|
1740 |
/* Show the version of libpng used in building the application */
|
10576
|
1741 |
fprintf(STDERR, " pngtest (%lu):%s", (unsigned long)PNG_LIBPNG_VER,
|
2
|
1742 |
PNG_HEADER_VERSION_STRING);
|
|
1743 |
|
|
1744 |
/* Do some consistency checking on the memory allocation settings, I'm
|
10576
|
1745 |
* not sure this matters, but it is nice to know, the first of these
|
|
1746 |
* tests should be impossible because of the way the macros are set
|
|
1747 |
* in pngconf.h
|
|
1748 |
*/
|
2
|
1749 |
#if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K)
|
|
1750 |
fprintf(STDERR, " NOTE: Zlib compiled for max 64k, libpng not\n");
|
|
1751 |
#endif
|
|
1752 |
/* I think the following can happen. */
|
|
1753 |
#if !defined(MAXSEG_64K) && defined(PNG_MAX_MALLOC_64K)
|
|
1754 |
fprintf(STDERR, " NOTE: libpng compiled for max 64k, zlib not\n");
|
|
1755 |
#endif
|
|
1756 |
|
|
1757 |
if (strcmp(png_libpng_ver, PNG_LIBPNG_VER_STRING))
|
|
1758 |
{
|
|
1759 |
fprintf(STDERR,
|
|
1760 |
"Warning: versions are different between png.h and png.c\n");
|
|
1761 |
fprintf(STDERR, " png.h version: %s\n", PNG_LIBPNG_VER_STRING);
|
|
1762 |
fprintf(STDERR, " png.c version: %s\n\n", png_libpng_ver);
|
|
1763 |
++ierror;
|
|
1764 |
}
|
|
1765 |
|
|
1766 |
if (argc > 1)
|
|
1767 |
{
|
|
1768 |
if (strcmp(argv[1], "-m") == 0)
|
|
1769 |
{
|
|
1770 |
multiple = 1;
|
|
1771 |
status_dots_requested = 0;
|
|
1772 |
}
|
10576
|
1773 |
|
2
|
1774 |
else if (strcmp(argv[1], "-mv") == 0 ||
|
|
1775 |
strcmp(argv[1], "-vm") == 0 )
|
|
1776 |
{
|
|
1777 |
multiple = 1;
|
|
1778 |
verbose = 1;
|
|
1779 |
status_dots_requested = 1;
|
|
1780 |
}
|
10576
|
1781 |
|
2
|
1782 |
else if (strcmp(argv[1], "-v") == 0)
|
|
1783 |
{
|
|
1784 |
verbose = 1;
|
|
1785 |
status_dots_requested = 1;
|
|
1786 |
inname = argv[2];
|
|
1787 |
}
|
10576
|
1788 |
|
29913
|
1789 |
else if (strcmp(argv[1], "--strict") == 0)
|
|
1790 |
{
|
|
1791 |
status_dots_requested = 0;
|
|
1792 |
verbose = 1;
|
|
1793 |
inname = argv[2];
|
|
1794 |
strict++;
|
|
1795 |
relaxed = 0;
|
|
1796 |
}
|
|
1797 |
|
|
1798 |
else if (strcmp(argv[1], "--relaxed") == 0)
|
|
1799 |
{
|
|
1800 |
status_dots_requested = 0;
|
|
1801 |
verbose = 1;
|
|
1802 |
inname = argv[2];
|
|
1803 |
strict = 0;
|
|
1804 |
relaxed++;
|
|
1805 |
}
|
|
1806 |
|
2
|
1807 |
else
|
|
1808 |
{
|
|
1809 |
inname = argv[1];
|
|
1810 |
status_dots_requested = 0;
|
|
1811 |
}
|
|
1812 |
}
|
|
1813 |
|
29913
|
1814 |
if (multiple == 0 && argc == 3 + verbose)
|
10576
|
1815 |
outname = argv[2 + verbose];
|
2
|
1816 |
|
29913
|
1817 |
if ((multiple == 0 && argc > 3 + verbose) ||
|
|
1818 |
(multiple != 0 && argc < 2))
|
2
|
1819 |
{
|
|
1820 |
fprintf(STDERR,
|
|
1821 |
"usage: %s [infile.png] [outfile.png]\n\t%s -m {infile.png}\n",
|
|
1822 |
argv[0], argv[0]);
|
|
1823 |
fprintf(STDERR,
|
|
1824 |
" reads/writes one PNG file (without -m) or multiple files (-m)\n");
|
|
1825 |
fprintf(STDERR,
|
|
1826 |
" with -m %s is used as a temporary file\n", outname);
|
|
1827 |
exit(1);
|
|
1828 |
}
|
|
1829 |
|
29913
|
1830 |
if (multiple != 0)
|
2
|
1831 |
{
|
|
1832 |
int i;
|
|
1833 |
#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
|
|
1834 |
int allocation_now = current_allocation;
|
|
1835 |
#endif
|
|
1836 |
for (i=2; i<argc; ++i)
|
|
1837 |
{
|
|
1838 |
int kerror;
|
10576
|
1839 |
fprintf(STDERR, "\n Testing %s:", argv[i]);
|
29913
|
1840 |
#if PNG_DEBUG > 0
|
|
1841 |
fprintf(STDERR, "\n");
|
|
1842 |
#endif
|
2
|
1843 |
kerror = test_one_file(argv[i], outname);
|
|
1844 |
if (kerror == 0)
|
|
1845 |
{
|
10576
|
1846 |
#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
|
|
1847 |
int k;
|
|
1848 |
#endif
|
|
1849 |
#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
|
2
|
1850 |
fprintf(STDERR, "\n PASS (%lu zero samples)\n",
|
|
1851 |
(unsigned long)zero_samples);
|
|
1852 |
#else
|
|
1853 |
fprintf(STDERR, " PASS\n");
|
|
1854 |
#endif
|
10576
|
1855 |
#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
|
|
1856 |
for (k = 0; k<256; k++)
|
29913
|
1857 |
if (filters_used[k] != 0)
|
2
|
1858 |
fprintf(STDERR, " Filter %d was used %lu times\n",
|
10576
|
1859 |
k, (unsigned long)filters_used[k]);
|
2
|
1860 |
#endif
|
10576
|
1861 |
#ifdef PNG_TIME_RFC1123_SUPPORTED
|
|
1862 |
if (tIME_chunk_present != 0)
|
|
1863 |
fprintf(STDERR, " tIME = %s\n", tIME_string);
|
|
1864 |
|
2
|
1865 |
tIME_chunk_present = 0;
|
29913
|
1866 |
#endif /* TIME_RFC1123 */
|
2
|
1867 |
}
|
10576
|
1868 |
|
2
|
1869 |
else
|
|
1870 |
{
|
|
1871 |
fprintf(STDERR, " FAIL\n");
|
|
1872 |
ierror += kerror;
|
|
1873 |
}
|
|
1874 |
#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
|
|
1875 |
if (allocation_now != current_allocation)
|
|
1876 |
fprintf(STDERR, "MEMORY ERROR: %d bytes lost\n",
|
10576
|
1877 |
current_allocation - allocation_now);
|
|
1878 |
|
2
|
1879 |
if (current_allocation != 0)
|
|
1880 |
{
|
|
1881 |
memory_infop pinfo = pinformation;
|
|
1882 |
|
|
1883 |
fprintf(STDERR, "MEMORY ERROR: %d bytes still allocated\n",
|
|
1884 |
current_allocation);
|
10576
|
1885 |
|
2
|
1886 |
while (pinfo != NULL)
|
|
1887 |
{
|
29913
|
1888 |
fprintf(STDERR, " %lu bytes at %p\n",
|
10576
|
1889 |
(unsigned long)pinfo->size,
|
29913
|
1890 |
pinfo->pointer);
|
2
|
1891 |
pinfo = pinfo->next;
|
|
1892 |
}
|
|
1893 |
}
|
|
1894 |
#endif
|
|
1895 |
}
|
|
1896 |
#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
|
|
1897 |
fprintf(STDERR, " Current memory allocation: %10d bytes\n",
|
|
1898 |
current_allocation);
|
|
1899 |
fprintf(STDERR, " Maximum memory allocation: %10d bytes\n",
|
|
1900 |
maximum_allocation);
|
|
1901 |
fprintf(STDERR, " Total memory allocation: %10d bytes\n",
|
|
1902 |
total_allocation);
|
|
1903 |
fprintf(STDERR, " Number of allocations: %10d\n",
|
|
1904 |
num_allocations);
|
|
1905 |
#endif
|
|
1906 |
}
|
10576
|
1907 |
|
2
|
1908 |
else
|
|
1909 |
{
|
|
1910 |
int i;
|
10576
|
1911 |
for (i = 0; i<3; ++i)
|
2
|
1912 |
{
|
|
1913 |
int kerror;
|
|
1914 |
#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
|
|
1915 |
int allocation_now = current_allocation;
|
|
1916 |
#endif
|
10576
|
1917 |
if (i == 1)
|
|
1918 |
status_dots_requested = 1;
|
|
1919 |
|
|
1920 |
else if (verbose == 0)
|
|
1921 |
status_dots_requested = 0;
|
|
1922 |
|
2
|
1923 |
if (i == 0 || verbose == 1 || ierror != 0)
|
29913
|
1924 |
{
|
10576
|
1925 |
fprintf(STDERR, "\n Testing %s:", inname);
|
29913
|
1926 |
#if PNG_DEBUG > 0
|
|
1927 |
fprintf(STDERR, "\n");
|
|
1928 |
#endif
|
|
1929 |
}
|
10576
|
1930 |
|
2
|
1931 |
kerror = test_one_file(inname, outname);
|
10576
|
1932 |
|
|
1933 |
if (kerror == 0)
|
2
|
1934 |
{
|
10576
|
1935 |
if (verbose == 1 || i == 2)
|
2
|
1936 |
{
|
10576
|
1937 |
#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
|
2
|
1938 |
int k;
|
|
1939 |
#endif
|
10576
|
1940 |
#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
|
2
|
1941 |
fprintf(STDERR, "\n PASS (%lu zero samples)\n",
|
|
1942 |
(unsigned long)zero_samples);
|
|
1943 |
#else
|
|
1944 |
fprintf(STDERR, " PASS\n");
|
|
1945 |
#endif
|
10576
|
1946 |
#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
|
|
1947 |
for (k = 0; k<256; k++)
|
29913
|
1948 |
if (filters_used[k] != 0)
|
2
|
1949 |
fprintf(STDERR, " Filter %d was used %lu times\n",
|
10576
|
1950 |
k, (unsigned long)filters_used[k]);
|
2
|
1951 |
#endif
|
10576
|
1952 |
#ifdef PNG_TIME_RFC1123_SUPPORTED
|
|
1953 |
if (tIME_chunk_present != 0)
|
|
1954 |
fprintf(STDERR, " tIME = %s\n", tIME_string);
|
29913
|
1955 |
#endif /* TIME_RFC1123 */
|
2
|
1956 |
}
|
|
1957 |
}
|
10576
|
1958 |
|
2
|
1959 |
else
|
|
1960 |
{
|
10576
|
1961 |
if (verbose == 0 && i != 2)
|
29913
|
1962 |
{
|
10576
|
1963 |
fprintf(STDERR, "\n Testing %s:", inname);
|
29913
|
1964 |
#if PNG_DEBUG > 0
|
|
1965 |
fprintf(STDERR, "\n");
|
|
1966 |
#endif
|
|
1967 |
}
|
10576
|
1968 |
|
2
|
1969 |
fprintf(STDERR, " FAIL\n");
|
|
1970 |
ierror += kerror;
|
|
1971 |
}
|
|
1972 |
#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
|
|
1973 |
if (allocation_now != current_allocation)
|
|
1974 |
fprintf(STDERR, "MEMORY ERROR: %d bytes lost\n",
|
10576
|
1975 |
current_allocation - allocation_now);
|
|
1976 |
|
2
|
1977 |
if (current_allocation != 0)
|
|
1978 |
{
|
|
1979 |
memory_infop pinfo = pinformation;
|
|
1980 |
|
|
1981 |
fprintf(STDERR, "MEMORY ERROR: %d bytes still allocated\n",
|
|
1982 |
current_allocation);
|
10576
|
1983 |
|
2
|
1984 |
while (pinfo != NULL)
|
|
1985 |
{
|
29913
|
1986 |
fprintf(STDERR, " %lu bytes at %p\n",
|
|
1987 |
(unsigned long)pinfo->size, pinfo->pointer);
|
2
|
1988 |
pinfo = pinfo->next;
|
|
1989 |
}
|
|
1990 |
}
|
|
1991 |
#endif
|
|
1992 |
}
|
|
1993 |
#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
|
|
1994 |
fprintf(STDERR, " Current memory allocation: %10d bytes\n",
|
|
1995 |
current_allocation);
|
|
1996 |
fprintf(STDERR, " Maximum memory allocation: %10d bytes\n",
|
|
1997 |
maximum_allocation);
|
|
1998 |
fprintf(STDERR, " Total memory allocation: %10d bytes\n",
|
|
1999 |
total_allocation);
|
|
2000 |
fprintf(STDERR, " Number of allocations: %10d\n",
|
|
2001 |
num_allocations);
|
|
2002 |
#endif
|
|
2003 |
}
|
|
2004 |
|
|
2005 |
#ifdef PNGTEST_TIMING
|
|
2006 |
t_stop = (float)clock();
|
|
2007 |
t_misc += (t_stop - t_start);
|
|
2008 |
t_start = t_stop;
|
10576
|
2009 |
fprintf(STDERR, " CPU time used = %.3f seconds",
|
2
|
2010 |
(t_misc+t_decode+t_encode)/(float)CLOCKS_PER_SEC);
|
10576
|
2011 |
fprintf(STDERR, " (decoding %.3f,\n",
|
2
|
2012 |
t_decode/(float)CLOCKS_PER_SEC);
|
10576
|
2013 |
fprintf(STDERR, " encoding %.3f ,",
|
2
|
2014 |
t_encode/(float)CLOCKS_PER_SEC);
|
10576
|
2015 |
fprintf(STDERR, " other %.3f seconds)\n\n",
|
2
|
2016 |
t_misc/(float)CLOCKS_PER_SEC);
|
|
2017 |
#endif
|
|
2018 |
|
|
2019 |
if (ierror == 0)
|
10576
|
2020 |
fprintf(STDERR, " libpng passes test\n");
|
|
2021 |
|
2
|
2022 |
else
|
10576
|
2023 |
fprintf(STDERR, " libpng FAILS test\n");
|
|
2024 |
|
2
|
2025 |
return (int)(ierror != 0);
|
|
2026 |
}
|
29913
|
2027 |
#else
|
|
2028 |
int
|
|
2029 |
main(void)
|
|
2030 |
{
|
|
2031 |
fprintf(STDERR,
|
|
2032 |
" test ignored because libpng was not built with read support\n");
|
|
2033 |
/* And skip this test */
|
|
2034 |
return PNG_LIBPNG_VER < 10600 ? 0 : 77;
|
|
2035 |
}
|
|
2036 |
#endif
|
2
|
2037 |
|
|
2038 |
/* Generate a compiler error if there is an old png.h in the search path. */
|
29913
|
2039 |
typedef png_libpng_version_1_6_16 Your_png_h_is_not_version_1_6_16;
|