blob: 1dc22761688163d94d2ee187083d397e12c74f32 [file] [log] [blame]
Andreas Dilger02ad0ef1997-01-17 01:34:35 -06001
Guy Schalnat4ee97b01996-01-16 01:51:56 -06002/* pngtest.c - a simple test program to test libpng
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -06003 *
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -06004 * libpng 1.0.5d - November 29, 1999
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -06005 * For conditions of distribution and use, see copyright notice in png.h
6 * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
7 * Copyright (c) 1996, 1997 Andreas Dilger
Glenn Randers-Pehrsonc9442291999-01-06 21:50:16 -06008 * Copyright (c) 1998, 1999 Glenn Randers-Pehrson
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -06009 *
10 * This program reads in a PNG image, writes it out again, and then
11 * compares the two files. If the files are identical, this shows that
12 * the basic chunk handling, filtering, and (de)compression code is working
13 * properly. It does not currently test all of the transforms, although
14 * it probably should.
15 *
Glenn Randers-Pehrson345bc271998-06-14 14:43:31 -050016 * The program will report "FAIL" in certain legitimate cases:
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -060017 * 1) when the compression level or filter selection method is changed.
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -050018 * 2) when the chunk size is not 8K.
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -060019 * 3) unknown ancillary chunks exist in the input file.
20 * 4) others not listed here...
21 * In these cases, it is best to check with another tool such as "pngcheck"
22 * to see what the differences between the two images are.
23 *
24 * If a filename is given on the command-line, then this file is used
25 * for the input, rather than the default "pngtest.png". This allows
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -050026 * testing a wide variety of files easily. You can also test a number
27 * of files at once by typing "pngtest -m file1.png file2.png ..."
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -060028 */
Guy Schalnat0d580581995-07-20 02:43:20 -050029
30#include <stdio.h>
31#include <stdlib.h>
Andreas Dilger47a0c421997-05-16 02:46:07 -050032
33/* Makes pngtest verbose so we can find problems (needs to be before png.h) */
34#ifndef PNG_DEBUG
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -060035#define PNG_DEBUG 0
Glenn Randers-Pehrsonea3bcd71998-03-07 14:33:00 -060036#endif
Andreas Dilger47a0c421997-05-16 02:46:07 -050037
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -050038/* Turn on CPU timing
39#define PNGTEST_TIMING
40*/
41
42#ifdef PNGTEST_TIMING
43static float t_start, t_stop, t_decode, t_encode, t_misc;
44#include <time.h>
45#endif
46
Guy Schalnat0d580581995-07-20 02:43:20 -050047#include "png.h"
48
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -050049#ifdef PNGTEST_TIMING
50static float t_start, t_stop, t_decode, t_encode, t_misc;
51#if !defined(PNG_READ_tIME_SUPPORTED) && !defined(PNG_WRITE_tIME_SUPPORTED)
52#include <time.h>
53#endif
54#endif
55
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -050056#if defined(PNG_TIME_RFC1123_SUPPORTED)
57static int tIME_chunk_present=0;
Glenn Randers-Pehrson345bc271998-06-14 14:43:31 -050058static char tIME_string[30] = "no tIME chunk present in file";
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -050059#endif /* PNG_TIME_RFC1123_SUPPORTED */
60
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050061static int verbose = 0;
62
Glenn Randers-Pehrsonea3bcd71998-03-07 14:33:00 -060063int test_one_file PNGARG((PNG_CONST char *inname, PNG_CONST char *outname));
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -060064
Guy Schalnat0d580581995-07-20 02:43:20 -050065#ifdef __TURBOC__
66#include <mem.h>
67#endif
68
69/* defined so I can write to a file on gui/windowing platforms */
Guy Schalnat6d764711995-12-19 03:22:19 -060070/* #define STDERR stderr */
Guy Schalnatb2e01bd1996-01-26 01:38:47 -060071#define STDERR stdout /* for DOS */
Guy Schalnat0d580581995-07-20 02:43:20 -050072
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -060073/* example of using row callbacks to make a simple progress meter */
74static int status_pass=1;
75static int status_dots_requested=0;
76static int status_dots=1;
Glenn Randers-Pehrsonea3bcd71998-03-07 14:33:00 -060077
Glenn Randers-Pehrson7cd899c1998-03-07 16:17:42 -060078void
79read_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass)
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -060080{
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050081 if(png_ptr == NULL || row_number > PNG_MAX_UINT) return;
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -060082 if(status_pass != pass)
83 {
84 fprintf(stdout,"\n Pass %d: ",pass);
85 status_pass = pass;
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050086 status_dots = 31;
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -060087 }
88 status_dots--;
89 if(status_dots == 0)
90 {
91 fprintf(stdout, "\n ");
92 status_dots=30;
93 }
94 fprintf(stdout, "r");
95}
Glenn Randers-Pehrsonea3bcd71998-03-07 14:33:00 -060096
Glenn Randers-Pehrson7cd899c1998-03-07 16:17:42 -060097void
98write_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass)
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -060099{
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500100 if(png_ptr == NULL || row_number > PNG_MAX_UINT || pass > 7) return;
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600101 fprintf(stdout, "w");
102}
103
104
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500105#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
106/* Example of using user transform callback (we don't transform anything,
107 but merely examine the row filters. We set this to 256 rather than
108 5 in case illegal filter values are present.) */
109static png_uint_32 filters_used[256];
110void
111count_filters(png_structp png_ptr, png_row_infop row_info, png_bytep data)
112{
113 if(png_ptr != NULL && row_info != NULL)
114 ++filters_used[*(data-1)];
115}
116#endif
117
Glenn Randers-Pehrson38d73af1998-03-07 21:30:44 -0600118#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600119/* example of using user transform callback (we don't transform anything,
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -0500120 but merely count the zero samples) */
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600121
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -0500122static png_uint_32 zero_samples;
Glenn Randers-Pehrsonea3bcd71998-03-07 14:33:00 -0600123
Glenn Randers-Pehrson7cd899c1998-03-07 16:17:42 -0600124void
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -0500125count_zero_samples(png_structp png_ptr, png_row_infop row_info, png_bytep data)
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600126{
127 png_bytep dp = data;
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600128 if(png_ptr == NULL)return;
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600129
130 /* contents of row_info:
131 * png_uint_32 width width of row
132 * png_uint_32 rowbytes number of bytes in row
133 * png_byte color_type color type of pixels
134 * png_byte bit_depth bit depth of samples
135 * png_byte channels number of channels (1-4)
136 * png_byte pixel_depth bits per pixel (depth*channels)
137 */
138
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500139
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -0500140 /* counts the number of zero samples (or zero pixels if color_type is 3 */
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600141
142 if(row_info->color_type == 0 || row_info->color_type == 3)
143 {
144 int pos=0;
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -0500145 png_uint_32 n, nstop;
146 for (n=0, nstop=row_info->width; n<nstop; n++)
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600147 {
148 if(row_info->bit_depth == 1)
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -0500149 {
150 if(((*dp << pos++ )& 0x80) == 0) zero_samples++;
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600151 if(pos == 8)
152 {
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -0500153 pos = 0;
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600154 dp++;
155 }
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -0500156 }
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600157 if(row_info->bit_depth == 2)
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -0500158 {
159 if(((*dp << (pos+=2))& 0xc0) == 0) zero_samples++;
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600160 if(pos == 8)
161 {
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -0500162 pos = 0;
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600163 dp++;
164 }
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -0500165 }
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600166 if(row_info->bit_depth == 4)
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -0500167 {
168 if(((*dp << (pos+=4))& 0xf0) == 0) zero_samples++;
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600169 if(pos == 8)
170 {
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -0500171 pos = 0;
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600172 dp++;
173 }
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -0500174 }
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600175 if(row_info->bit_depth == 8)
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -0500176 if(*dp++ == 0) zero_samples++;
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600177 if(row_info->bit_depth == 16)
178 {
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -0500179 if((*dp | *(dp+1)) == 0) zero_samples++;
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600180 dp+=2;
181 }
182 }
183 }
184 else /* other color types */
185 {
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -0500186 png_uint_32 n, nstop;
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600187 int channel;
188 int color_channels = row_info->channels;
189 if(row_info->color_type > 3)color_channels--;
190
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -0500191 for (n=0, nstop=row_info->width; n<nstop; n++)
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600192 {
193 for (channel = 0; channel < color_channels; channel++)
194 {
195 if(row_info->bit_depth == 8)
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -0500196 if(*dp++ == 0) zero_samples++;
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600197 if(row_info->bit_depth == 16)
198 {
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -0500199 if((*dp | *(dp+1)) == 0) zero_samples++;
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600200 dp+=2;
201 }
202 }
203 if(row_info->color_type > 3)
204 {
205 dp++;
206 if(row_info->bit_depth == 16)dp++;
207 }
208 }
209 }
210}
Glenn Randers-Pehrson38d73af1998-03-07 21:30:44 -0600211#endif /* PNG_WRITE_USER_TRANSFORM_SUPPORTED */
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600212
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600213static int wrote_question = 0;
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600214
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -0600215#if defined(PNG_NO_STDIO)
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600216/* START of code to validate stdio-free compilation */
217/* These copies of the default read/write functions come from pngrio.c and */
218/* pngwio.c. They allow "don't include stdio" testing of the library. */
Glenn Randers-Pehrson8686fff1998-05-21 09:27:50 -0500219/* This is the function that does the actual reading of data. If you are
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600220 not reading from a standard C stream, you should create a replacement
221 read_data function and use it at run time with png_set_read_fn(), rather
222 than changing the library. */
223#ifndef USE_FAR_KEYWORD
224static void
225png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
226{
227 png_size_t check;
228
229 /* fread() returns 0 on error, so it is OK to store this in a png_size_t
230 * instead of an int, which is what fread() actually returns.
231 */
232 check = (png_size_t)fread(data, (png_size_t)1, length,
233 (FILE *)png_ptr->io_ptr);
234
235 if (check != length)
236 {
237 png_error(png_ptr, "Read Error");
238 }
239}
Guy Schalnate5a37791996-06-05 15:50:50 -0500240#else
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600241/* this is the model-independent version. Since the standard I/O library
242 can't handle far buffers in the medium and small models, we have to copy
243 the data.
244*/
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600245
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600246#define NEAR_BUF_SIZE 1024
247#define MIN(a,b) (a <= b ? a : b)
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600248
Glenn Randers-Pehrson7cd899c1998-03-07 16:17:42 -0600249static void
250png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600251{
252 int check;
253 png_byte *n_data;
254 FILE *io_ptr;
255
256 /* Check if data really is near. If so, use usual code. */
257 n_data = (png_byte *)CVT_PTR_NOCHECK(data);
258 io_ptr = (FILE *)CVT_PTR(png_ptr->io_ptr);
259 if ((png_bytep)n_data == data)
260 {
261 check = fread(n_data, 1, length, io_ptr);
262 }
263 else
264 {
265 png_byte buf[NEAR_BUF_SIZE];
266 png_size_t read, remaining, err;
267 check = 0;
268 remaining = length;
269 do
270 {
271 read = MIN(NEAR_BUF_SIZE, remaining);
272 err = fread(buf, (png_size_t)1, read, io_ptr);
273 png_memcpy(data, buf, read); /* copy far buffer to near buffer */
274 if(err != read)
275 break;
276 else
277 check += err;
278 data += read;
279 remaining -= read;
280 }
281 while (remaining != 0);
282 }
283 if (check != length)
284 {
285 png_error(png_ptr, "read Error");
286 }
287}
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -0600288#endif /* USE_FAR_KEYWORD */
Guy Schalnat0d580581995-07-20 02:43:20 -0500289
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600290#if defined(PNG_WRITE_FLUSH_SUPPORTED)
Glenn Randers-Pehrson7cd899c1998-03-07 16:17:42 -0600291static void
292png_default_flush(png_structp png_ptr)
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600293{
294 FILE *io_ptr;
295 io_ptr = (FILE *)CVT_PTR((png_ptr->io_ptr));
296 if (io_ptr != NULL)
297 fflush(io_ptr);
298}
299#endif
Guy Schalnat0d580581995-07-20 02:43:20 -0500300
Glenn Randers-Pehrson8686fff1998-05-21 09:27:50 -0500301/* This is the function that does the actual writing of data. If you are
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600302 not writing to a standard C stream, you should create a replacement
303 write_data function and use it at run time with png_set_write_fn(), rather
304 than changing the library. */
305#ifndef USE_FAR_KEYWORD
306static void
307png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
308{
309 png_uint_32 check;
310
311 check = fwrite(data, 1, length, (FILE *)(png_ptr->io_ptr));
312 if (check != length)
313 {
314 png_error(png_ptr, "Write Error");
315 }
316}
317#else
318/* this is the model-independent version. Since the standard I/O library
319 can't handle far buffers in the medium and small models, we have to copy
320 the data.
321*/
322
323#define NEAR_BUF_SIZE 1024
324#define MIN(a,b) (a <= b ? a : b)
325
326static void
327png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
328{
329 png_uint_32 check;
330 png_byte *near_data; /* Needs to be "png_byte *" instead of "png_bytep" */
331 FILE *io_ptr;
332
333 /* Check if data really is near. If so, use usual code. */
334 near_data = (png_byte *)CVT_PTR_NOCHECK(data);
335 io_ptr = (FILE *)CVT_PTR(png_ptr->io_ptr);
336 if ((png_bytep)near_data == data)
337 {
338 check = fwrite(near_data, 1, length, io_ptr);
339 }
340 else
341 {
342 png_byte buf[NEAR_BUF_SIZE];
343 png_size_t written, remaining, err;
344 check = 0;
345 remaining = length;
346 do
347 {
348 written = MIN(NEAR_BUF_SIZE, remaining);
349 png_memcpy(buf, data, written); /* copy far buffer to near buffer */
350 err = fwrite(buf, 1, written, io_ptr);
351 if (err != written)
352 break;
353 else
354 check += err;
355 data += written;
356 remaining -= written;
357 }
358 while (remaining != 0);
359 }
360 if (check != length)
361 {
362 png_error(png_ptr, "Write Error");
363 }
364}
365
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -0600366#endif /* USE_FAR_KEYWORD */
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600367
368/* This function is called when there is a warning, but the library thinks
369 * it can continue anyway. Replacement functions don't have to do anything
370 * here if you don't want to. In the default configuration, png_ptr is
371 * not used, but it is passed in case it may be useful.
372 */
373static void
374png_default_warning(png_structp png_ptr, png_const_charp message)
375{
376 PNG_CONST char *name = "UNKNOWN (ERROR!)";
377 if (png_ptr != NULL && png_ptr->error_ptr != NULL)
378 name = png_ptr->error_ptr;
379 fprintf(STDERR, "%s: libpng warning: %s\n", name, message);
380}
381
382/* This is the default error handling function. Note that replacements for
383 * this function MUST NOT RETURN, or the program will likely crash. This
384 * function is used by default, or if the program supplies NULL for the
385 * error function pointer in png_set_error_fn().
386 */
387static void
388png_default_error(png_structp png_ptr, png_const_charp message)
389{
390 png_default_warning(png_ptr, message);
Glenn Randers-Pehrson8686fff1998-05-21 09:27:50 -0500391 /* We can return because png_error calls the default handler, which is
392 * actually OK in this case. */
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600393}
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -0600394#endif /* PNG_NO_STDIO */
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600395/* END of code to validate stdio-free compilation */
396
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600397/* START of code to validate memory allocation and deallocation */
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500398#ifdef PNG_USER_MEM_SUPPORTED
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600399
400/* Allocate memory. For reasonable files, size should never exceed
401 64K. However, zlib may allocate more then 64K if you don't tell
402 it not to. See zconf.h and png.h for more information. zlib does
403 need to allocate exactly 64K, so whatever you call here must
404 have the ability to do that.
405
406 This piece of code can be compiled to validate max 64K allocations
407 by setting MAXSEG_64K in zlib zconf.h *or* PNG_MAX_MALLOC_64K. */
408typedef struct memory_information {
409 png_uint_32 size;
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500410 png_voidp pointer;
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600411 struct memory_information FAR *next;
412} memory_information;
413typedef memory_information FAR *memory_infop;
414
415static memory_infop pinformation = NULL;
416static int current_allocation = 0;
417static int maximum_allocation = 0;
418
419extern PNG_EXPORT(png_voidp,png_debug_malloc) PNGARG((png_structp png_ptr,
420 png_uint_32 size));
421extern PNG_EXPORT(void,png_debug_free) PNGARG((png_structp png_ptr,
422 png_voidp ptr));
423
424png_voidp
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500425png_debug_malloc(png_structp png_ptr, png_uint_32 size) {
426
427 /* png_malloc has already tested for NULL; png_create_struct calls
428 png_debug_malloc directly, with png_ptr == NULL which is OK */
429
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600430 if (size == 0)
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -0600431 return (png_voidp)(NULL);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600432
433 /* This calls the library allocator twice, once to get the requested
434 buffer and once to get a new free list entry. */
435 {
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500436 memory_infop pinfo = png_malloc_default(png_ptr, sizeof *pinfo);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600437 pinfo->size = size;
438 current_allocation += size;
439 if (current_allocation > maximum_allocation)
440 maximum_allocation = current_allocation;
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500441 pinfo->pointer = png_malloc_default(png_ptr, size);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600442 pinfo->next = pinformation;
443 pinformation = pinfo;
444 /* Make sure the caller isn't assuming zeroed memory. */
445 png_memset(pinfo->pointer, 0xdd, pinfo->size);
Glenn Randers-Pehrson6d8f3b01999-10-23 08:39:18 -0500446#if PNG_DEBUG
447 if(verbose)
448 printf("png_malloc %d bytes at %x\n",size,pinfo->pointer);
449#endif
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -0600450 return (png_voidp)(pinfo->pointer);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600451 }
452}
453
454/* Free a pointer. It is removed from the list at the same time. */
455void
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500456png_debug_free(png_structp png_ptr, png_voidp ptr)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600457{
458 if (png_ptr == NULL)
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500459 fprintf(STDERR, "NULL pointer to png_debug_free.\n");
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600460 if (ptr == 0) {
461#if 0 /* This happens all the time. */
462 fprintf(STDERR, "WARNING: freeing NULL pointer\n");
463#endif
464 return;
465 }
466
467 /* Unlink the element from the list. */
468 {
469 memory_infop FAR *ppinfo = &pinformation;
470 for (;;) {
471 memory_infop pinfo = *ppinfo;
472 if (pinfo->pointer == ptr) {
473 *ppinfo = pinfo->next;
474 current_allocation -= pinfo->size;
475 if (current_allocation < 0)
476 fprintf(STDERR, "Duplicate free of memory\n");
477 /* We must free the list element too, but first kill
Glenn Randers-Pehrson8686fff1998-05-21 09:27:50 -0500478 the memory that is to be freed. */
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600479 memset(ptr, 0x55, pinfo->size);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500480 png_free_default(png_ptr, pinfo);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600481 break;
482 }
483 if (pinfo->next == NULL) {
484 fprintf(STDERR, "Pointer %x not found\n", ptr);
485 break;
486 }
487 ppinfo = &pinfo->next;
488 }
489 }
490
491 /* Finally free the data. */
Glenn Randers-Pehrson6d8f3b01999-10-23 08:39:18 -0500492#if PNG_DEBUG
493 if(verbose)
494 printf("Freeing %x\n",ptr);
495#endif
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500496 png_free_default(png_ptr, ptr);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600497}
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500498#endif /* PNG_USER_MEM_SUPPORTED */
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600499/* END of code to test memory allocation/deallocation */
500
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600501/* Test one file */
Glenn Randers-Pehrson7cd899c1998-03-07 16:17:42 -0600502int
503test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
Guy Schalnat0d580581995-07-20 02:43:20 -0500504{
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -0600505 static FILE *fpin, *fpout; /* "static" prevents setjmp corruption */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500506 png_structp read_ptr, write_ptr;
Glenn Randers-Pehrson6d8f3b01999-10-23 08:39:18 -0500507 png_infop read_info_ptr, write_info_ptr, end_info_ptr, write_end_info_ptr;
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600508 png_bytep row_buf;
Guy Schalnat0d580581995-07-20 02:43:20 -0500509 png_uint_32 y;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500510 png_uint_32 width, height;
511 int num_pass, pass;
512 int bit_depth, color_type;
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600513#ifdef USE_FAR_KEYWORD
514 jmp_buf jmpbuf;
515#endif
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600516
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600517 char inbuf[256], outbuf[256];
518
Guy Schalnate5a37791996-06-05 15:50:50 -0500519 row_buf = (png_bytep)NULL;
Guy Schalnat0d580581995-07-20 02:43:20 -0500520
Andreas Dilger47a0c421997-05-16 02:46:07 -0500521 if ((fpin = fopen(inname, "rb")) == NULL)
Guy Schalnat0f716451995-11-28 11:22:13 -0600522 {
523 fprintf(STDERR, "Could not find input file %s\n", inname);
Glenn Randers-Pehrsonb2120021998-01-31 20:07:59 -0600524 return (1);
Guy Schalnat0f716451995-11-28 11:22:13 -0600525 }
Guy Schalnat0d580581995-07-20 02:43:20 -0500526
Andreas Dilger47a0c421997-05-16 02:46:07 -0500527 if ((fpout = fopen(outname, "wb")) == NULL)
Guy Schalnat0f716451995-11-28 11:22:13 -0600528 {
Guy Schalnate5a37791996-06-05 15:50:50 -0500529 fprintf(STDERR, "Could not open output file %s\n", outname);
Guy Schalnat0f716451995-11-28 11:22:13 -0600530 fclose(fpin);
Glenn Randers-Pehrsonb2120021998-01-31 20:07:59 -0600531 return (1);
Guy Schalnat0f716451995-11-28 11:22:13 -0600532 }
Guy Schalnat0d580581995-07-20 02:43:20 -0500533
Andreas Dilger47a0c421997-05-16 02:46:07 -0500534 png_debug(0, "Allocating read and write structures\n");
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500535#ifdef PNG_USER_MEM_SUPPORTED
536 read_ptr = png_create_read_struct_2(PNG_LIBPNG_VER_STRING, (png_voidp)NULL,
537 (png_error_ptr)NULL, (png_error_ptr)NULL, (png_voidp)NULL,
538 (png_malloc_ptr)png_debug_malloc, (png_free_ptr)png_debug_free);
539#else
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600540 read_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, (png_voidp)NULL,
Andreas Dilger47a0c421997-05-16 02:46:07 -0500541 (png_error_ptr)NULL, (png_error_ptr)NULL);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500542#endif
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600543#if defined(PNG_NO_STDIO)
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -0600544 png_set_error_fn(read_ptr, (png_voidp)inname, png_default_error,
545 png_default_warning);
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600546#endif
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500547#ifdef PNG_USER_MEM_SUPPORTED
548 write_ptr = png_create_write_struct_2(PNG_LIBPNG_VER_STRING, (png_voidp)NULL,
549 (png_error_ptr)NULL, (png_error_ptr)NULL, (png_voidp)NULL,
550 (png_malloc_ptr)png_debug_malloc, (png_free_ptr)png_debug_free);
551#else
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600552 write_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, (png_voidp)NULL,
Guy Schalnate5a37791996-06-05 15:50:50 -0500553 (png_error_ptr)NULL, (png_error_ptr)NULL);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500554#endif
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600555#if defined(PNG_NO_STDIO)
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -0600556 png_set_error_fn(write_ptr, (png_voidp)inname, png_default_error,
557 png_default_warning);
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600558#endif
Andreas Dilger47a0c421997-05-16 02:46:07 -0500559 png_debug(0, "Allocating read_info, write_info and end_info structures\n");
560 read_info_ptr = png_create_info_struct(read_ptr);
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -0600561 write_info_ptr = png_create_info_struct(write_ptr);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500562 end_info_ptr = png_create_info_struct(read_ptr);
Glenn Randers-Pehrson6d8f3b01999-10-23 08:39:18 -0500563 write_end_info_ptr = png_create_info_struct(write_ptr);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500564#ifdef PNG_USER_MEM_SUPPORTED
565#endif
Guy Schalnate5a37791996-06-05 15:50:50 -0500566
Andreas Dilger47a0c421997-05-16 02:46:07 -0500567 png_debug(0, "Setting jmpbuf for read struct\n");
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600568#ifdef USE_FAR_KEYWORD
569 if (setjmp(jmpbuf))
570#else
Guy Schalnate5a37791996-06-05 15:50:50 -0500571 if (setjmp(read_ptr->jmpbuf))
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600572#endif
Guy Schalnat0f716451995-11-28 11:22:13 -0600573 {
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600574 fprintf(STDERR, "%s -> %s: libpng read error\n", inname, outname);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500575 png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr);
Glenn Randers-Pehrson6d8f3b01999-10-23 08:39:18 -0500576 png_destroy_info_struct(write_ptr, &write_end_info_ptr);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500577 png_destroy_write_struct(&write_ptr, &write_info_ptr);
Guy Schalnat0f716451995-11-28 11:22:13 -0600578 fclose(fpin);
579 fclose(fpout);
Glenn Randers-Pehrsonb2120021998-01-31 20:07:59 -0600580 return (1);
Guy Schalnat0f716451995-11-28 11:22:13 -0600581 }
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600582#ifdef USE_FAR_KEYWORD
583 png_memcpy(read_ptr->jmpbuf,jmpbuf,sizeof(jmp_buf));
584#endif
Andreas Dilger47a0c421997-05-16 02:46:07 -0500585
586 png_debug(0, "Setting jmpbuf for write struct\n");
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600587#ifdef USE_FAR_KEYWORD
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600588 if (setjmp(jmpbuf))
589#else
Guy Schalnate5a37791996-06-05 15:50:50 -0500590 if (setjmp(write_ptr->jmpbuf))
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600591#endif
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600592 {
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600593 fprintf(STDERR, "%s -> %s: libpng write error\n", inname, outname);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500594 png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr);
Glenn Randers-Pehrson6d8f3b01999-10-23 08:39:18 -0500595 png_destroy_info_struct(write_ptr, &write_end_info_ptr);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500596 png_destroy_write_struct(&write_ptr, &write_info_ptr);
Guy Schalnat0f716451995-11-28 11:22:13 -0600597 fclose(fpin);
598 fclose(fpout);
Glenn Randers-Pehrsonb2120021998-01-31 20:07:59 -0600599 return (1);
Guy Schalnat0f716451995-11-28 11:22:13 -0600600 }
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600601#ifdef USE_FAR_KEYWORD
602 png_memcpy(write_ptr->jmpbuf,jmpbuf,sizeof(jmp_buf));
603#endif
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600604
Andreas Dilger47a0c421997-05-16 02:46:07 -0500605 png_debug(0, "Initializing input and output streams\n");
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600606#if !defined(PNG_NO_STDIO)
Guy Schalnate5a37791996-06-05 15:50:50 -0500607 png_init_io(read_ptr, fpin);
608 png_init_io(write_ptr, fpout);
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600609#else
610 png_set_read_fn(read_ptr, (png_voidp)fpin, png_default_read_data);
611 png_set_write_fn(write_ptr, (png_voidp)fpout, png_default_write_data,
612#if defined(PNG_WRITE_FLUSH_SUPPORTED)
613 png_default_flush);
614#else
615 NULL);
616#endif
617#endif
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600618 if(status_dots_requested == 1)
619 {
620 png_set_write_status_fn(write_ptr, write_row_callback);
621 png_set_read_status_fn(read_ptr, read_row_callback);
622 }
623 else
624 {
625 png_set_write_status_fn(write_ptr, NULL);
626 png_set_read_status_fn(read_ptr, NULL);
627 }
628
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500629#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
630 {
631 int i;
632 for(i=0; i<256; i++)
633 filters_used[i]=0;
634 png_set_read_user_transform_fn(read_ptr, count_filters);
635 }
636#endif
637#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
638 zero_samples=0;
639 png_set_write_user_transform_fn(write_ptr, count_zero_samples);
640#endif
Guy Schalnat0d580581995-07-20 02:43:20 -0500641
Andreas Dilger47a0c421997-05-16 02:46:07 -0500642 png_debug(0, "Reading info struct\n");
643 png_read_info(read_ptr, read_info_ptr);
Guy Schalnat0d580581995-07-20 02:43:20 -0500644
Andreas Dilger47a0c421997-05-16 02:46:07 -0500645 png_debug(0, "Transferring info struct\n");
646 {
647 int interlace_type, compression_type, filter_type;
Guy Schalnat0d580581995-07-20 02:43:20 -0500648
Andreas Dilger47a0c421997-05-16 02:46:07 -0500649 if (png_get_IHDR(read_ptr, read_info_ptr, &width, &height, &bit_depth,
650 &color_type, &interlace_type, &compression_type, &filter_type))
651 {
652 png_set_IHDR(write_ptr, write_info_ptr, width, height, bit_depth,
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600653#if defined(PNG_WRITE_INTERLACING_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500654 color_type, interlace_type, compression_type, filter_type);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600655#else
656 color_type, PNG_INTERLACE_NONE, compression_type, filter_type);
657#endif
Andreas Dilger47a0c421997-05-16 02:46:07 -0500658 }
659 }
660#if defined(PNG_READ_bKGD_SUPPORTED) && defined(PNG_WRITE_bKGD_SUPPORTED)
661 {
662 png_color_16p background;
663
664 if (png_get_bKGD(read_ptr, read_info_ptr, &background))
665 {
666 png_set_bKGD(write_ptr, write_info_ptr, background);
667 }
668 }
669#endif
670#if defined(PNG_READ_cHRM_SUPPORTED) && defined(PNG_WRITE_cHRM_SUPPORTED)
671 {
672 double white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
673
674 if (png_get_cHRM(read_ptr, read_info_ptr, &white_x, &white_y, &red_x,
675 &red_y, &green_x, &green_y, &blue_x, &blue_y))
676 {
677 png_set_cHRM(write_ptr, write_info_ptr, white_x, white_y, red_x,
678 red_y, green_x, green_y, blue_x, blue_y);
679 }
680 }
681#endif
682#if defined(PNG_READ_gAMA_SUPPORTED) && defined(PNG_WRITE_gAMA_SUPPORTED)
683 {
684 double gamma;
685
686 if (png_get_gAMA(read_ptr, read_info_ptr, &gamma))
687 {
688 png_set_gAMA(write_ptr, write_info_ptr, gamma);
689 }
690 }
691#endif
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600692#if defined(PNG_READ_sRGB_SUPPORTED) && defined(PNG_WRITE_sRGB_SUPPORTED)
693 {
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -0600694 int intent;
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600695
696 if (png_get_sRGB(read_ptr, read_info_ptr, &intent))
697 {
698 png_set_sRGB(write_ptr, write_info_ptr, intent);
699 }
700 }
701#endif
Andreas Dilger47a0c421997-05-16 02:46:07 -0500702#if defined(PNG_READ_hIST_SUPPORTED) && defined(PNG_WRITE_hIST_SUPPORTED)
703 {
704 png_uint_16p hist;
705
706 if (png_get_hIST(read_ptr, read_info_ptr, &hist))
707 {
708 png_set_hIST(write_ptr, write_info_ptr, hist);
709 }
710 }
711#endif
712#if defined(PNG_READ_oFFs_SUPPORTED) && defined(PNG_WRITE_oFFs_SUPPORTED)
713 {
714 png_uint_32 offset_x, offset_y;
715 int unit_type;
716
717 if (png_get_oFFs(read_ptr, read_info_ptr,&offset_x,&offset_y,&unit_type))
718 {
719 png_set_oFFs(write_ptr, write_info_ptr, offset_x, offset_y, unit_type);
720 }
721 }
722#endif
723#if defined(PNG_READ_pCAL_SUPPORTED) && defined(PNG_WRITE_pCAL_SUPPORTED)
724 {
725 png_charp purpose, units;
726 png_charpp params;
727 png_int_32 X0, X1;
728 int type, nparams;
729
730 if (png_get_pCAL(read_ptr, read_info_ptr, &purpose, &X0, &X1, &type,
731 &nparams, &units, &params))
732 {
733 png_set_pCAL(write_ptr, write_info_ptr, purpose, X0, X1, type,
734 nparams, units, params);
735 }
736 }
737#endif
738#if defined(PNG_READ_pHYs_SUPPORTED) && defined(PNG_WRITE_pHYs_SUPPORTED)
739 {
740 png_uint_32 res_x, res_y;
741 int unit_type;
742
743 if (png_get_pHYs(read_ptr, read_info_ptr, &res_x, &res_y, &unit_type))
744 {
745 png_set_pHYs(write_ptr, write_info_ptr, res_x, res_y, unit_type);
746 }
747 }
748#endif
749 {
750 png_colorp palette;
751 int num_palette;
752
753 if (png_get_PLTE(read_ptr, read_info_ptr, &palette, &num_palette))
754 {
755 png_set_PLTE(write_ptr, write_info_ptr, palette, num_palette);
756 }
757 }
758#if defined(PNG_READ_sBIT_SUPPORTED) && defined(PNG_WRITE_sBIT_SUPPORTED)
759 {
760 png_color_8p sig_bit;
761
762 if (png_get_sBIT(read_ptr, read_info_ptr, &sig_bit))
763 {
764 png_set_sBIT(write_ptr, write_info_ptr, sig_bit);
765 }
766 }
767#endif
768#if (defined(PNG_READ_tEXt_SUPPORTED) && defined(PNG_WRITE_tEXt_SUPPORTED)) || \
769 (defined(PNG_READ_zTXt_SUPPORTED) && defined(PNG_WRITE_zTXt_SUPPORTED))
770 {
771 png_textp text_ptr;
772 int num_text;
773
774 if (png_get_text(read_ptr, read_info_ptr, &text_ptr, &num_text) > 0)
775 {
776 png_debug1(0, "Handling %d tEXt/zTXt chunks\n", num_text);
777 png_set_text(write_ptr, write_info_ptr, text_ptr, num_text);
778 }
779 }
780#endif
781#if defined(PNG_READ_tIME_SUPPORTED) && defined(PNG_WRITE_tIME_SUPPORTED)
782 {
783 png_timep mod_time;
784
785 if (png_get_tIME(read_ptr, read_info_ptr, &mod_time))
786 {
787 png_set_tIME(write_ptr, write_info_ptr, mod_time);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500788#if defined(PNG_TIME_RFC1123_SUPPORTED)
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500789 /* we have to use png_strcpy instead of "=" because the string
790 pointed to by png_convert_to_rfc1123() gets free'ed before
791 we use it */
792 png_strcpy(tIME_string,png_convert_to_rfc1123(read_ptr, mod_time));
793 tIME_chunk_present++;
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500794#endif /* PNG_TIME_RFC1123_SUPPORTED */
Glenn Randers-Pehrsonc9442291999-01-06 21:50:16 -0600795 }
Andreas Dilger47a0c421997-05-16 02:46:07 -0500796 }
797#endif
798#if defined(PNG_READ_tRNS_SUPPORTED) && defined(PNG_WRITE_tRNS_SUPPORTED)
799 {
800 png_bytep trans;
801 int num_trans;
802 png_color_16p trans_values;
803
804 if (png_get_tRNS(read_ptr, read_info_ptr, &trans, &num_trans,
805 &trans_values))
806 {
807 png_set_tRNS(write_ptr, write_info_ptr, trans, num_trans,
808 trans_values);
809 }
810 }
811#endif
812
813 png_debug(0, "\nWriting info struct\n");
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600814
815/* If we wanted, we could write info in two steps:
816 png_write_info_before_PLTE(write_ptr, write_info_ptr);
817 */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500818 png_write_info(write_ptr, write_info_ptr);
819
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -0600820 png_debug(0, "\nAllocating row buffer \n");
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600821 row_buf = (png_bytep)png_malloc(read_ptr,
Andreas Dilger47a0c421997-05-16 02:46:07 -0500822 png_get_rowbytes(read_ptr, read_info_ptr));
823 if (row_buf == NULL)
Guy Schalnat0f716451995-11-28 11:22:13 -0600824 {
Guy Schalnate5a37791996-06-05 15:50:50 -0500825 fprintf(STDERR, "No memory to allocate row buffer\n");
Andreas Dilger47a0c421997-05-16 02:46:07 -0500826 png_destroy_read_struct(&read_ptr, &read_info_ptr, (png_infopp)NULL);
Glenn Randers-Pehrson6d8f3b01999-10-23 08:39:18 -0500827 png_destroy_info_struct(write_ptr, &write_end_info_ptr);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500828 png_destroy_write_struct(&write_ptr, &write_info_ptr);
Guy Schalnat0f716451995-11-28 11:22:13 -0600829 fclose(fpin);
830 fclose(fpout);
Glenn Randers-Pehrsonb2120021998-01-31 20:07:59 -0600831 return (1);
Guy Schalnat0f716451995-11-28 11:22:13 -0600832 }
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -0600833 png_debug(0, "Writing row data\n");
Guy Schalnat0d580581995-07-20 02:43:20 -0500834
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -0500835#if defined(PNG_READ_INTERLACING_SUPPORTED) || \
836 defined(PNG_WRITE_INTERLACING_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500837 num_pass = png_set_interlace_handling(read_ptr);
838 png_set_interlace_handling(write_ptr);
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -0500839#else
840 num_pass=1;
841#endif
Guy Schalnat0d580581995-07-20 02:43:20 -0500842
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -0500843#ifdef PNGTEST_TIMING
844 t_stop = (float)clock();
845 t_misc += (t_stop - t_start);
846 t_start = t_stop;
847#endif
Guy Schalnat0f716451995-11-28 11:22:13 -0600848 for (pass = 0; pass < num_pass; pass++)
849 {
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -0600850 png_debug1(0, "Writing row data for pass %d\n",pass);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500851 for (y = 0; y < height; y++)
Guy Schalnat0f716451995-11-28 11:22:13 -0600852 {
Andreas Dilger47a0c421997-05-16 02:46:07 -0500853 png_read_rows(read_ptr, (png_bytepp)&row_buf, (png_bytepp)NULL, 1);
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -0500854#ifdef PNGTEST_TIMING
855 t_stop = (float)clock();
856 t_decode += (t_stop - t_start);
857 t_start = t_stop;
858#endif
Guy Schalnate5a37791996-06-05 15:50:50 -0500859 png_write_rows(write_ptr, (png_bytepp)&row_buf, 1);
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -0500860#ifdef PNGTEST_TIMING
861 t_stop = (float)clock();
862 t_encode += (t_stop - t_start);
863 t_start = t_stop;
864#endif
Guy Schalnat0f716451995-11-28 11:22:13 -0600865 }
866 }
Guy Schalnat0d580581995-07-20 02:43:20 -0500867
Andreas Dilger47a0c421997-05-16 02:46:07 -0500868 png_debug(0, "Reading and writing end_info data\n");
869 png_read_end(read_ptr, end_info_ptr);
Glenn Randers-Pehrson6d8f3b01999-10-23 08:39:18 -0500870#if (defined(PNG_READ_tEXt_SUPPORTED) && defined(PNG_WRITE_tEXt_SUPPORTED)) || \
871 (defined(PNG_READ_zTXt_SUPPORTED) && defined(PNG_WRITE_zTXt_SUPPORTED))
872 {
873 png_textp text_ptr;
874 int num_text;
875
876 if (png_get_text(read_ptr, end_info_ptr, &text_ptr, &num_text) > 0)
877 {
Glenn Randers-Pehrson6d8f3b01999-10-23 08:39:18 -0500878 png_debug1(0, "Handling %d tEXt/zTXt chunks\n", num_text);
879 png_set_text(write_ptr, write_end_info_ptr, text_ptr, num_text);
880 }
881 }
882#endif
883#if defined(PNG_READ_tIME_SUPPORTED) && defined(PNG_WRITE_tIME_SUPPORTED)
884 {
885 png_timep mod_time;
886
887 if (png_get_tIME(read_ptr, end_info_ptr, &mod_time))
888 {
889 png_set_tIME(write_ptr, write_end_info_ptr, mod_time);
890#if defined(PNG_TIME_RFC1123_SUPPORTED)
891 /* we have to use png_strcpy instead of "=" because the string
892 pointed to by png_convert_to_rfc1123() gets free'ed before
893 we use it */
894 png_strcpy(tIME_string,png_convert_to_rfc1123(read_ptr, mod_time));
895 tIME_chunk_present++;
896#endif /* PNG_TIME_RFC1123_SUPPORTED */
897 }
898 }
899#endif
900 png_write_end(write_ptr, write_end_info_ptr);
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600901
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600902#ifdef PNG_EASY_ACCESS_SUPPORTED
903 if(verbose)
904 {
905 png_uint_32 iwidth, iheight;
906 iwidth = png_get_image_width(write_ptr, write_info_ptr);
907 iheight = png_get_image_height(write_ptr, write_info_ptr);
908 fprintf(STDERR, "Image width = %lu, height = %lu\n",
909 iwidth, iheight);
910 }
911#endif
Guy Schalnat0d580581995-07-20 02:43:20 -0500912
Andreas Dilger47a0c421997-05-16 02:46:07 -0500913 png_debug(0, "Destroying data structs\n");
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -0600914 png_free(read_ptr, row_buf);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500915 png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr);
Glenn Randers-Pehrson6d8f3b01999-10-23 08:39:18 -0500916 png_destroy_info_struct(write_ptr, &write_end_info_ptr);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500917 png_destroy_write_struct(&write_ptr, &write_info_ptr);
Guy Schalnat0d580581995-07-20 02:43:20 -0500918
Guy Schalnat0f716451995-11-28 11:22:13 -0600919 fclose(fpin);
920 fclose(fpout);
Guy Schalnat0d580581995-07-20 02:43:20 -0500921
Andreas Dilger47a0c421997-05-16 02:46:07 -0500922 png_debug(0, "Opening files for comparison\n");
923 if ((fpin = fopen(inname, "rb")) == NULL)
Guy Schalnat0f716451995-11-28 11:22:13 -0600924 {
Guy Schalnate5a37791996-06-05 15:50:50 -0500925 fprintf(STDERR, "Could not find file %s\n", inname);
Glenn Randers-Pehrsonb2120021998-01-31 20:07:59 -0600926 return (1);
Guy Schalnat0f716451995-11-28 11:22:13 -0600927 }
Guy Schalnat0d580581995-07-20 02:43:20 -0500928
Andreas Dilger47a0c421997-05-16 02:46:07 -0500929 if ((fpout = fopen(outname, "rb")) == NULL)
Guy Schalnat0f716451995-11-28 11:22:13 -0600930 {
Guy Schalnate5a37791996-06-05 15:50:50 -0500931 fprintf(STDERR, "Could not find file %s\n", outname);
Guy Schalnat0f716451995-11-28 11:22:13 -0600932 fclose(fpin);
Glenn Randers-Pehrsonb2120021998-01-31 20:07:59 -0600933 return (1);
Guy Schalnat0f716451995-11-28 11:22:13 -0600934 }
Andreas Dilger47a0c421997-05-16 02:46:07 -0500935
Glenn Randers-Pehrsonea3bcd71998-03-07 14:33:00 -0600936 for(;;)
Guy Schalnat0f716451995-11-28 11:22:13 -0600937 {
Andreas Dilger47a0c421997-05-16 02:46:07 -0500938 png_size_t num_in, num_out;
Guy Schalnat0d580581995-07-20 02:43:20 -0500939
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600940 num_in = fread(inbuf, 1, 1, fpin);
941 num_out = fread(outbuf, 1, 1, fpout);
Guy Schalnat0d580581995-07-20 02:43:20 -0500942
Guy Schalnat0f716451995-11-28 11:22:13 -0600943 if (num_in != num_out)
944 {
Guy Schalnate5a37791996-06-05 15:50:50 -0500945 fprintf(STDERR, "Files %s and %s are of a different size\n",
946 inname, outname);
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600947 if(wrote_question == 0)
948 {
949 fprintf(STDERR,
950 " Was %s written with the same chunk size (8k),",inname);
951 fprintf(STDERR,
952 " filtering\n heuristic (libpng default), compression");
953 fprintf(STDERR,
954 " level (zlib default)\n and zlib version (%s)?\n\n",
955 ZLIB_VERSION);
956 wrote_question=1;
957 }
Guy Schalnat0f716451995-11-28 11:22:13 -0600958 fclose(fpin);
959 fclose(fpout);
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600960 return (0);
Guy Schalnat0f716451995-11-28 11:22:13 -0600961 }
Guy Schalnat0d580581995-07-20 02:43:20 -0500962
Guy Schalnat0f716451995-11-28 11:22:13 -0600963 if (!num_in)
964 break;
Guy Schalnat0d580581995-07-20 02:43:20 -0500965
Andreas Dilger47a0c421997-05-16 02:46:07 -0500966 if (png_memcmp(inbuf, outbuf, num_in))
Guy Schalnat0f716451995-11-28 11:22:13 -0600967 {
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500968 fprintf(STDERR, "\nFiles %s and %s are different\n", inname, outname);
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600969 if(wrote_question == 0)
970 {
971 fprintf(STDERR,
972 " Was %s written with the same chunk size (8k),",inname);
973 fprintf(STDERR,
974 " filtering\n heuristic (libpng default), compression");
975 fprintf(STDERR,
976 " level (zlib default)\n and zlib version (%s)?\n\n",
977 ZLIB_VERSION);
978 wrote_question=1;
979 }
Guy Schalnat0f716451995-11-28 11:22:13 -0600980 fclose(fpin);
981 fclose(fpout);
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600982 return (0);
Guy Schalnat0f716451995-11-28 11:22:13 -0600983 }
984 }
985
986 fclose(fpin);
987 fclose(fpout);
Guy Schalnat0d580581995-07-20 02:43:20 -0500988
Glenn Randers-Pehrsonb2120021998-01-31 20:07:59 -0600989 return (0);
Guy Schalnat0d580581995-07-20 02:43:20 -0500990}
Guy Schalnat51f0eb41995-09-26 05:22:39 -0500991
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600992/* input and output filenames */
993#ifdef RISCOS
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500994static PNG_CONST char *inname = "pngtest/png";
995static PNG_CONST char *outname = "pngout/png";
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600996#else
Glenn Randers-Pehrson983ec161998-03-07 11:24:03 -0600997static PNG_CONST char *inname = "pngtest.png";
998static PNG_CONST char *outname = "pngout.png";
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600999#endif
1000
1001int
1002main(int argc, char *argv[])
1003{
1004 int multiple = 0;
1005 int ierror = 0;
1006
1007 fprintf(STDERR, "Testing libpng version %s\n", PNG_LIBPNG_VER_STRING);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001008 fprintf(STDERR, " with zlib version %s\n", ZLIB_VERSION);
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001009 fprintf(STDERR,"%s",png_get_copyright(NULL));
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -06001010 /* Show the version of libpng used in building the library */
1011 fprintf(STDERR," library:%s",png_get_header_version(NULL));
1012 /* Show the version of libpng used in building the application */
1013 fprintf(STDERR," pngtest:%s",PNG_HEADER_VERSION_STRING);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001014
1015 /* Do some consistency checking on the memory allocation settings, I'm
1016 not sure this matters, but it is nice to know, the first of these
1017 tests should be impossible because of the way the macros are set
1018 in pngconf.h */
Glenn Randers-Pehrsonea3bcd71998-03-07 14:33:00 -06001019#if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001020 fprintf(STDERR, " NOTE: Zlib compiled for max 64k, libpng not\n");
Glenn Randers-Pehrsonea3bcd71998-03-07 14:33:00 -06001021#endif
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001022 /* I think the following can happen. */
Glenn Randers-Pehrsonea3bcd71998-03-07 14:33:00 -06001023#if !defined(MAXSEG_64K) && defined(PNG_MAX_MALLOC_64K)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001024 fprintf(STDERR, " NOTE: libpng compiled for max 64k, zlib not\n");
Glenn Randers-Pehrsonea3bcd71998-03-07 14:33:00 -06001025#endif
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -06001026
1027 if (strcmp(png_libpng_ver, PNG_LIBPNG_VER_STRING))
1028 {
1029 fprintf(STDERR,
1030 "Warning: versions are different between png.h and png.c\n");
1031 fprintf(STDERR, " png.h version: %s\n", PNG_LIBPNG_VER_STRING);
1032 fprintf(STDERR, " png.c version: %s\n\n", png_libpng_ver);
1033 ++ierror;
1034 }
1035
1036 if (argc > 1)
1037 {
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001038 if (strcmp(argv[1], "-m") == 0)
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06001039 {
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001040 multiple = 1;
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06001041 status_dots_requested = 0;
1042 }
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001043 else if (strcmp(argv[1], "-mv") == 0 ||
1044 strcmp(argv[1], "-vm") == 0 )
1045 {
1046 multiple = 1;
1047 verbose = 1;
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06001048 status_dots_requested = 1;
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001049 }
1050 else if (strcmp(argv[1], "-v") == 0)
1051 {
1052 verbose = 1;
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06001053 status_dots_requested = 1;
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001054 inname = argv[2];
1055 }
1056 else
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06001057 {
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001058 inname = argv[1];
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06001059 status_dots_requested = 0;
1060 }
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -06001061 }
1062
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001063 if (!multiple && argc == 3+verbose)
1064 outname = argv[2+verbose];
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -06001065
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001066 if ((!multiple && argc > 3+verbose) || (multiple && argc < 2))
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -06001067 {
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -06001068 fprintf(STDERR,
1069 "usage: %s [infile.png] [outfile.png]\n\t%s -m {infile.png}\n",
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -06001070 argv[0], argv[0]);
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -06001071 fprintf(STDERR,
1072 " reads/writes one PNG file (without -m) or multiple files (-m)\n");
1073 fprintf(STDERR,
1074 " with -m %s is used as a temporary file\n", outname);
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -06001075 exit(1);
1076 }
1077
1078 if (multiple)
1079 {
1080 int i;
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001081#ifdef PNG_USER_MEM_SUPPORTED
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001082 int allocation_now = current_allocation;
1083#endif
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -06001084 for (i=2; i<argc; ++i)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001085 {
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05001086 int k, kerror;
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -06001087 fprintf(STDERR, "Testing %s:",argv[i]);
1088 kerror = test_one_file(argv[i], outname);
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001089 if (kerror == 0)
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001090 {
Glenn Randers-Pehrson38d73af1998-03-07 21:30:44 -06001091#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
Glenn Randers-Pehrson6d8f3b01999-10-23 08:39:18 -05001092 fprintf(STDERR, "\n PASS (%lu zero samples)\n",zero_samples);
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06001093#else
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001094 fprintf(STDERR, " PASS\n");
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001095#endif
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05001096#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
1097 for (k=0; k<256; k++)
1098 if(filters_used[k])
1099 fprintf(STDERR, " Filter %d was used %lu times\n",
1100 k,filters_used[k]);
1101#endif
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001102#if defined(PNG_TIME_RFC1123_SUPPORTED)
1103 if(tIME_chunk_present != 0)
1104 fprintf(STDERR, " tIME = %s\n",tIME_string);
1105 tIME_chunk_present = 0;
1106#endif /* PNG_TIME_RFC1123_SUPPORTED */
1107 }
1108 else
1109 {
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -06001110 fprintf(STDERR, " FAIL\n");
1111 ierror += kerror;
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001112 }
1113#ifdef PNG_USER_MEM_SUPPORTED
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001114 if (allocation_now != current_allocation)
1115 fprintf(STDERR, "MEMORY ERROR: %d bytes lost\n",
1116 current_allocation-allocation_now);
1117 if (current_allocation != 0) {
1118 memory_infop pinfo = pinformation;
1119
1120 fprintf(STDERR, "MEMORY ERROR: %d bytes still allocated\n",
1121 current_allocation);
1122 while (pinfo != NULL) {
1123 fprintf(STDERR, " %d bytes at %x\n", pinfo->size, pinfo->pointer);
1124 pinfo = pinfo->next;
1125 }
Glenn Randers-Pehrson2687fcc1998-01-07 20:54:20 -06001126 }
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001127#endif
1128 }
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001129#ifdef PNG_USER_MEM_SUPPORTED
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -05001130 fprintf(STDERR, " Current memory allocation: %d bytes\n",
1131 current_allocation);
1132 fprintf(STDERR, " Maximum memory allocation: %d bytes\n",
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001133 maximum_allocation);
1134#endif
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -06001135 }
1136 else
1137 {
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -06001138 int i;
1139 for (i=0; i<3; ++i) {
1140 int kerror;
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001141#ifdef PNG_USER_MEM_SUPPORTED
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001142 int allocation_now = current_allocation;
1143#endif
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06001144 if (i == 1) status_dots_requested = 1;
1145 else if(verbose == 0)status_dots_requested = 0;
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001146 if (i == 0 || verbose == 1 || ierror != 0)
1147 fprintf(STDERR, "Testing %s:",inname);
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -06001148 kerror = test_one_file(inname, outname);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001149 if(kerror == 0)
1150 {
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06001151 if(verbose == 1 || i == 2)
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001152 {
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05001153 int k;
Glenn Randers-Pehrson38d73af1998-03-07 21:30:44 -06001154#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
Glenn Randers-Pehrson6d8f3b01999-10-23 08:39:18 -05001155 fprintf(STDERR, "\n PASS (%lu zero samples)\n",zero_samples);
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06001156#else
1157 fprintf(STDERR, " PASS\n");
1158#endif
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05001159#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
1160 for (k=0; k<256; k++)
1161 if(filters_used[k])
1162 fprintf(STDERR, " Filter %d was used %lu times\n",
1163 k,filters_used[k]);
1164#endif
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001165#if defined(PNG_TIME_RFC1123_SUPPORTED)
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05001166 if(tIME_chunk_present != 0)
1167 fprintf(STDERR, " tIME = %s\n",tIME_string);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001168#endif /* PNG_TIME_RFC1123_SUPPORTED */
1169 }
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001170 }
1171 else
1172 {
1173 if(verbose == 0 && i != 2)
1174 fprintf(STDERR, "Testing %s:",inname);
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -06001175 fprintf(STDERR, " FAIL\n");
1176 ierror += kerror;
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001177 }
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001178#ifdef PNG_USER_MEM_SUPPORTED
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001179 if (allocation_now != current_allocation)
1180 fprintf(STDERR, "MEMORY ERROR: %d bytes lost\n",
1181 current_allocation-allocation_now);
1182 if (current_allocation != 0) {
1183 memory_infop pinfo = pinformation;
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001184
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001185 fprintf(STDERR, "MEMORY ERROR: %d bytes still allocated\n",
1186 current_allocation);
1187 while (pinfo != NULL) {
1188 fprintf(STDERR, " %d bytes at %x\n", pinfo->size, pinfo->pointer);
1189 pinfo = pinfo->next;
1190 }
1191 }
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001192#endif
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -06001193 }
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001194#ifdef PNG_USER_MEM_SUPPORTED
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -05001195 fprintf(STDERR, " Current memory allocation: %d bytes\n",
1196 current_allocation);
1197 fprintf(STDERR, " Maximum memory allocation: %d bytes\n",
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001198 maximum_allocation);
1199#endif
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -06001200 }
1201
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -05001202#ifdef PNGTEST_TIMING
1203 t_stop = (float)clock();
1204 t_misc += (t_stop - t_start);
1205 t_start = t_stop;
1206 fprintf(STDERR," CPU time used = %.3f seconds",
1207 (t_misc+t_decode+t_encode)/(float)CLOCKS_PER_SEC);
1208 fprintf(STDERR," (decoding %.3f,\n",
1209 t_decode/(float)CLOCKS_PER_SEC);
1210 fprintf(STDERR," encoding %.3f ,",
1211 t_encode/(float)CLOCKS_PER_SEC);
1212 fprintf(STDERR," other %.3f seconds)\n\n",
1213 t_misc/(float)CLOCKS_PER_SEC);
1214#endif
1215
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -06001216 if (ierror == 0)
1217 fprintf(STDERR, "libpng passes test\n");
1218 else
1219 fprintf(STDERR, "libpng FAILS test\n");
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06001220 return (int)(ierror != 0);
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -06001221}
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001222
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -05001223/* Generate a compiler error if there is an old png.h in the search path. */
1224void
1225png_check_pngtest_version
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -06001226 (version_1_0_5d png_h_is_not_version_1_0_5d)
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -05001227{
Glenn Randers-Pehrson074af5e1999-11-28 23:32:18 -06001228 if(png_h_is_not_version_1_0_5d == NULL) return;
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -05001229}