blob: e8e5fad014b0ee548d98629e1e2b3c33bd89cf2f [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-Pehrson15dac0b2000-07-10 07:48:54 -05004 * libpng 1.0.8beta2 - July 10, 2000
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -06005 * For conditions of distribution and use, see copyright notice in png.h
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06006 * Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
Glenn Randers-Pehrsond4366722000-06-04 14:29:29 -05007 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
8 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
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-Pehrson61c32d92000-02-04 23:40:16 -060018 * 2) when the maximum IDAT size (PNG_ZBUF_SIZE in pngconf.h) is not 8192.
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"
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -060022 * to see what the differences between the two files are.
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -060023 *
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
Glenn Randers-Pehrson316f97a2000-07-08 13:19:41 -050030#if defined(_WIN32_WCE)
31# if _WIN32_WCE < 211
32 __error__ (f|w)printf functions are not supported on old WindowsCE.;
33# endif
34# include <windows.h>
35# include <stdlib.h>
36# define READFILE(file, data, length, check) \
Glenn Randers-Pehrson15dac0b2000-07-10 07:48:54 -050037 if (ReadFile(file, data, length, &check,NULL)) check = 0
38# define WRITEFILE(file, data, length, check)) \
39 if (WriteFile(file, data, length, &check, NULL)) check = 0
Glenn Randers-Pehrson316f97a2000-07-08 13:19:41 -050040# define FCLOSE(file) CloseHandle(file)
41#else
42# include <stdio.h>
43# include <stdlib.h>
44# include <assert.h>
45# define READFILE(file, data, length, check) \
46 check=(png_size_t)fread(data,(png_size_t)1,length,file)
47# define WRITEFILE(file, data, length, check) \
Glenn Randers-Pehrson15dac0b2000-07-10 07:48:54 -050048 check=(png_size_t)fwrite(data,(png_size_t)1, length, file)
Glenn Randers-Pehrson316f97a2000-07-08 13:19:41 -050049# define FCLOSE(file) fclose(file)
50#endif
Andreas Dilger47a0c421997-05-16 02:46:07 -050051
52/* Makes pngtest verbose so we can find problems (needs to be before png.h) */
53#ifndef PNG_DEBUG
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -060054#define PNG_DEBUG 0
Glenn Randers-Pehrsonea3bcd71998-03-07 14:33:00 -060055#endif
Andreas Dilger47a0c421997-05-16 02:46:07 -050056
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -050057/* Turn on CPU timing
58#define PNGTEST_TIMING
59*/
60
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -060061#ifdef PNG_NO_FLOATING_POINT_SUPPORTED
62#undef PNGTEST_TIMING
63#endif
64
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -050065#ifdef PNGTEST_TIMING
66static float t_start, t_stop, t_decode, t_encode, t_misc;
67#include <time.h>
68#endif
69
Guy Schalnat0d580581995-07-20 02:43:20 -050070#include "png.h"
71
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -060072/* Define png_jmpbuf() in case we are using a pre-1.0.6 version of libpng */
73#ifndef png_jmpbuf
74# define png_jmpbuf(png_ptr) png_ptr->jmpbuf
75#endif
76
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -050077#ifdef PNGTEST_TIMING
78static float t_start, t_stop, t_decode, t_encode, t_misc;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -060079#if !defined(PNG_tIME_SUPPORTED)
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -050080#include <time.h>
81#endif
82#endif
83
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -050084#if defined(PNG_TIME_RFC1123_SUPPORTED)
85static int tIME_chunk_present=0;
Glenn Randers-Pehrson345bc271998-06-14 14:43:31 -050086static char tIME_string[30] = "no tIME chunk present in file";
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -060087#endif
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -050088
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -050089static int verbose = 0;
90
Glenn Randers-Pehrsonea3bcd71998-03-07 14:33:00 -060091int test_one_file PNGARG((PNG_CONST char *inname, PNG_CONST char *outname));
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -060092
Guy Schalnat0d580581995-07-20 02:43:20 -050093#ifdef __TURBOC__
94#include <mem.h>
95#endif
96
97/* defined so I can write to a file on gui/windowing platforms */
Guy Schalnat6d764711995-12-19 03:22:19 -060098/* #define STDERR stderr */
Guy Schalnatb2e01bd1996-01-26 01:38:47 -060099#define STDERR stdout /* for DOS */
Guy Schalnat0d580581995-07-20 02:43:20 -0500100
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600101/* example of using row callbacks to make a simple progress meter */
102static int status_pass=1;
103static int status_dots_requested=0;
104static int status_dots=1;
Glenn Randers-Pehrsonea3bcd71998-03-07 14:33:00 -0600105
Glenn Randers-Pehrson7cd899c1998-03-07 16:17:42 -0600106void
107read_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass)
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600108{
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500109 if(png_ptr == NULL || row_number > PNG_MAX_UINT) return;
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600110 if(status_pass != pass)
111 {
112 fprintf(stdout,"\n Pass %d: ",pass);
113 status_pass = pass;
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500114 status_dots = 31;
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600115 }
116 status_dots--;
117 if(status_dots == 0)
118 {
119 fprintf(stdout, "\n ");
120 status_dots=30;
121 }
122 fprintf(stdout, "r");
123}
Glenn Randers-Pehrsonea3bcd71998-03-07 14:33:00 -0600124
Glenn Randers-Pehrson7cd899c1998-03-07 16:17:42 -0600125void
126write_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass)
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600127{
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500128 if(png_ptr == NULL || row_number > PNG_MAX_UINT || pass > 7) return;
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600129 fprintf(stdout, "w");
130}
131
132
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500133#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
134/* Example of using user transform callback (we don't transform anything,
135 but merely examine the row filters. We set this to 256 rather than
136 5 in case illegal filter values are present.) */
137static png_uint_32 filters_used[256];
138void
139count_filters(png_structp png_ptr, png_row_infop row_info, png_bytep data)
140{
141 if(png_ptr != NULL && row_info != NULL)
142 ++filters_used[*(data-1)];
143}
144#endif
145
Glenn Randers-Pehrson38d73af1998-03-07 21:30:44 -0600146#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600147/* example of using user transform callback (we don't transform anything,
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -0500148 but merely count the zero samples) */
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600149
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -0500150static png_uint_32 zero_samples;
Glenn Randers-Pehrsonea3bcd71998-03-07 14:33:00 -0600151
Glenn Randers-Pehrson7cd899c1998-03-07 16:17:42 -0600152void
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -0500153count_zero_samples(png_structp png_ptr, png_row_infop row_info, png_bytep data)
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600154{
155 png_bytep dp = data;
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600156 if(png_ptr == NULL)return;
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600157
158 /* contents of row_info:
159 * png_uint_32 width width of row
160 * png_uint_32 rowbytes number of bytes in row
161 * png_byte color_type color type of pixels
162 * png_byte bit_depth bit depth of samples
163 * png_byte channels number of channels (1-4)
164 * png_byte pixel_depth bits per pixel (depth*channels)
165 */
166
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500167
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -0500168 /* counts the number of zero samples (or zero pixels if color_type is 3 */
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600169
170 if(row_info->color_type == 0 || row_info->color_type == 3)
171 {
172 int pos=0;
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -0500173 png_uint_32 n, nstop;
174 for (n=0, nstop=row_info->width; n<nstop; n++)
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600175 {
176 if(row_info->bit_depth == 1)
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -0500177 {
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600178 if(((*dp << pos++ ) & 0x80) == 0) zero_samples++;
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600179 if(pos == 8)
180 {
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -0500181 pos = 0;
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600182 dp++;
183 }
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -0500184 }
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600185 if(row_info->bit_depth == 2)
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -0500186 {
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600187 if(((*dp << (pos+=2)) & 0xc0) == 0) zero_samples++;
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600188 if(pos == 8)
189 {
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -0500190 pos = 0;
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600191 dp++;
192 }
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -0500193 }
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600194 if(row_info->bit_depth == 4)
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -0500195 {
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600196 if(((*dp << (pos+=4)) & 0xf0) == 0) zero_samples++;
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600197 if(pos == 8)
198 {
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -0500199 pos = 0;
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600200 dp++;
201 }
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -0500202 }
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600203 if(row_info->bit_depth == 8)
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -0500204 if(*dp++ == 0) zero_samples++;
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600205 if(row_info->bit_depth == 16)
206 {
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -0500207 if((*dp | *(dp+1)) == 0) zero_samples++;
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600208 dp+=2;
209 }
210 }
211 }
212 else /* other color types */
213 {
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -0500214 png_uint_32 n, nstop;
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600215 int channel;
216 int color_channels = row_info->channels;
217 if(row_info->color_type > 3)color_channels--;
218
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -0500219 for (n=0, nstop=row_info->width; n<nstop; n++)
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600220 {
221 for (channel = 0; channel < color_channels; channel++)
222 {
223 if(row_info->bit_depth == 8)
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -0500224 if(*dp++ == 0) zero_samples++;
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600225 if(row_info->bit_depth == 16)
226 {
Glenn Randers-Pehrson896239b1998-04-21 15:03:57 -0500227 if((*dp | *(dp+1)) == 0) zero_samples++;
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600228 dp+=2;
229 }
230 }
231 if(row_info->color_type > 3)
232 {
233 dp++;
234 if(row_info->bit_depth == 16)dp++;
235 }
236 }
237 }
238}
Glenn Randers-Pehrson38d73af1998-03-07 21:30:44 -0600239#endif /* PNG_WRITE_USER_TRANSFORM_SUPPORTED */
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600240
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -0600241static int wrote_question = 0;
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600242
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -0600243#if defined(PNG_NO_STDIO)
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600244/* START of code to validate stdio-free compilation */
245/* These copies of the default read/write functions come from pngrio.c and */
246/* pngwio.c. They allow "don't include stdio" testing of the library. */
Glenn Randers-Pehrson8686fff1998-05-21 09:27:50 -0500247/* This is the function that does the actual reading of data. If you are
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600248 not reading from a standard C stream, you should create a replacement
249 read_data function and use it at run time with png_set_read_fn(), rather
250 than changing the library. */
251#ifndef USE_FAR_KEYWORD
252static void
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500253pngtest_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600254{
255 png_size_t check;
256
257 /* fread() returns 0 on error, so it is OK to store this in a png_size_t
258 * instead of an int, which is what fread() actually returns.
259 */
Glenn Randers-Pehrson316f97a2000-07-08 13:19:41 -0500260 READFILE((png_FILE_p)png_ptr->io_ptr, data, length, check);
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600261
262 if (check != length)
263 {
264 png_error(png_ptr, "Read Error");
265 }
266}
Guy Schalnate5a37791996-06-05 15:50:50 -0500267#else
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600268/* this is the model-independent version. Since the standard I/O library
269 can't handle far buffers in the medium and small models, we have to copy
270 the data.
271*/
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600272
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600273#define NEAR_BUF_SIZE 1024
274#define MIN(a,b) (a <= b ? a : b)
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600275
Glenn Randers-Pehrson7cd899c1998-03-07 16:17:42 -0600276static void
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500277pngtest_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600278{
279 int check;
280 png_byte *n_data;
Glenn Randers-Pehrson316f97a2000-07-08 13:19:41 -0500281 png_FILE_p io_ptr;
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600282
283 /* Check if data really is near. If so, use usual code. */
284 n_data = (png_byte *)CVT_PTR_NOCHECK(data);
Glenn Randers-Pehrson316f97a2000-07-08 13:19:41 -0500285 io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600286 if ((png_bytep)n_data == data)
287 {
Glenn Randers-Pehrson316f97a2000-07-08 13:19:41 -0500288 READFILE(io_ptr, n_data, length, check);
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600289 }
290 else
291 {
292 png_byte buf[NEAR_BUF_SIZE];
293 png_size_t read, remaining, err;
294 check = 0;
295 remaining = length;
296 do
297 {
298 read = MIN(NEAR_BUF_SIZE, remaining);
Glenn Randers-Pehrson316f97a2000-07-08 13:19:41 -0500299 READFILE(io_ptr, buf, 1, err);
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600300 png_memcpy(data, buf, read); /* copy far buffer to near buffer */
301 if(err != read)
302 break;
303 else
304 check += err;
305 data += read;
306 remaining -= read;
307 }
308 while (remaining != 0);
309 }
310 if (check != length)
311 {
312 png_error(png_ptr, "read Error");
313 }
314}
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -0600315#endif /* USE_FAR_KEYWORD */
Guy Schalnat0d580581995-07-20 02:43:20 -0500316
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600317#if defined(PNG_WRITE_FLUSH_SUPPORTED)
Glenn Randers-Pehrson7cd899c1998-03-07 16:17:42 -0600318static void
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500319pngtest_flush(png_structp png_ptr)
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600320{
Glenn Randers-Pehrson316f97a2000-07-08 13:19:41 -0500321#if !defined(_WIN32_WCE)
322 png_FILE_p io_ptr;
323 io_ptr = (png_FILE_p)CVT_PTR((png_ptr->io_ptr));
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600324 if (io_ptr != NULL)
325 fflush(io_ptr);
Glenn Randers-Pehrson316f97a2000-07-08 13:19:41 -0500326#endif
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600327}
328#endif
Guy Schalnat0d580581995-07-20 02:43:20 -0500329
Glenn Randers-Pehrson8686fff1998-05-21 09:27:50 -0500330/* This is the function that does the actual writing of data. If you are
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600331 not writing to a standard C stream, you should create a replacement
332 write_data function and use it at run time with png_set_write_fn(), rather
333 than changing the library. */
334#ifndef USE_FAR_KEYWORD
335static void
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500336pngtest_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600337{
338 png_uint_32 check;
339
Glenn Randers-Pehrson316f97a2000-07-08 13:19:41 -0500340 WRITEFILE((png_FILE_p)png_ptr->io_ptr, data, 1, check);
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600341 if (check != length)
342 {
343 png_error(png_ptr, "Write Error");
344 }
345}
346#else
347/* this is the model-independent version. Since the standard I/O library
348 can't handle far buffers in the medium and small models, we have to copy
349 the data.
350*/
351
352#define NEAR_BUF_SIZE 1024
353#define MIN(a,b) (a <= b ? a : b)
354
355static void
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500356pngtest_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600357{
358 png_uint_32 check;
359 png_byte *near_data; /* Needs to be "png_byte *" instead of "png_bytep" */
Glenn Randers-Pehrson316f97a2000-07-08 13:19:41 -0500360 png_FILE_p io_ptr;
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600361
362 /* Check if data really is near. If so, use usual code. */
363 near_data = (png_byte *)CVT_PTR_NOCHECK(data);
Glenn Randers-Pehrson316f97a2000-07-08 13:19:41 -0500364 io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600365 if ((png_bytep)near_data == data)
366 {
Glenn Randers-Pehrson316f97a2000-07-08 13:19:41 -0500367 WRITEFILE(io_ptr, near_data, 1, check);
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600368 }
369 else
370 {
371 png_byte buf[NEAR_BUF_SIZE];
372 png_size_t written, remaining, err;
373 check = 0;
374 remaining = length;
375 do
376 {
377 written = MIN(NEAR_BUF_SIZE, remaining);
378 png_memcpy(buf, data, written); /* copy far buffer to near buffer */
Glenn Randers-Pehrson316f97a2000-07-08 13:19:41 -0500379 WRITEFILE(io_ptr, written, 1, err);
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600380 if (err != written)
381 break;
382 else
383 check += err;
384 data += written;
385 remaining -= written;
386 }
387 while (remaining != 0);
388 }
389 if (check != length)
390 {
391 png_error(png_ptr, "Write Error");
392 }
393}
394
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -0600395#endif /* USE_FAR_KEYWORD */
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600396
397/* This function is called when there is a warning, but the library thinks
398 * it can continue anyway. Replacement functions don't have to do anything
399 * here if you don't want to. In the default configuration, png_ptr is
400 * not used, but it is passed in case it may be useful.
401 */
402static void
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500403pngtest_warning(png_structp png_ptr, png_const_charp message)
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600404{
405 PNG_CONST char *name = "UNKNOWN (ERROR!)";
406 if (png_ptr != NULL && png_ptr->error_ptr != NULL)
407 name = png_ptr->error_ptr;
408 fprintf(STDERR, "%s: libpng warning: %s\n", name, message);
409}
410
411/* This is the default error handling function. Note that replacements for
412 * this function MUST NOT RETURN, or the program will likely crash. This
413 * function is used by default, or if the program supplies NULL for the
414 * error function pointer in png_set_error_fn().
415 */
416static void
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500417pngtest_error(png_structp png_ptr, png_const_charp message)
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600418{
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500419 pngtest_warning(png_ptr, message);
Glenn Randers-Pehrson8686fff1998-05-21 09:27:50 -0500420 /* We can return because png_error calls the default handler, which is
421 * actually OK in this case. */
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600422}
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -0600423#endif /* PNG_NO_STDIO */
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600424/* END of code to validate stdio-free compilation */
425
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600426/* START of code to validate memory allocation and deallocation */
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500427#ifdef PNG_USER_MEM_SUPPORTED
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600428
429/* Allocate memory. For reasonable files, size should never exceed
430 64K. However, zlib may allocate more then 64K if you don't tell
431 it not to. See zconf.h and png.h for more information. zlib does
432 need to allocate exactly 64K, so whatever you call here must
433 have the ability to do that.
434
435 This piece of code can be compiled to validate max 64K allocations
436 by setting MAXSEG_64K in zlib zconf.h *or* PNG_MAX_MALLOC_64K. */
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600437typedef struct memory_information
438{
Glenn Randers-Pehrson316f97a2000-07-08 13:19:41 -0500439 png_uint_32 size;
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500440 png_voidp pointer;
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600441 struct memory_information FAR *next;
442} memory_information;
443typedef memory_information FAR *memory_infop;
444
445static memory_infop pinformation = NULL;
446static int current_allocation = 0;
447static int maximum_allocation = 0;
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500448static int total_allocation = 0;
449static int num_allocations = 0;
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600450
451extern PNG_EXPORT(png_voidp,png_debug_malloc) PNGARG((png_structp png_ptr,
452 png_uint_32 size));
453extern PNG_EXPORT(void,png_debug_free) PNGARG((png_structp png_ptr,
454 png_voidp ptr));
455
456png_voidp
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600457png_debug_malloc(png_structp png_ptr, png_uint_32 size)
458{
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500459
460 /* png_malloc has already tested for NULL; png_create_struct calls
461 png_debug_malloc directly, with png_ptr == NULL which is OK */
462
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600463 if (size == 0)
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -0600464 return (png_voidp)(NULL);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600465
466 /* This calls the library allocator twice, once to get the requested
467 buffer and once to get a new free list entry. */
468 {
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500469 memory_infop pinfo = png_malloc_default(png_ptr, sizeof *pinfo);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600470 pinfo->size = size;
471 current_allocation += size;
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500472 total_allocation += size;
473 num_allocations ++;
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600474 if (current_allocation > maximum_allocation)
475 maximum_allocation = current_allocation;
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500476 pinfo->pointer = png_malloc_default(png_ptr, size);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600477 pinfo->next = pinformation;
478 pinformation = pinfo;
479 /* Make sure the caller isn't assuming zeroed memory. */
480 png_memset(pinfo->pointer, 0xdd, pinfo->size);
Glenn Randers-Pehrson6d8f3b01999-10-23 08:39:18 -0500481#if PNG_DEBUG
482 if(verbose)
483 printf("png_malloc %d bytes at %x\n",size,pinfo->pointer);
484#endif
Glenn Randers-Pehrson316f97a2000-07-08 13:19:41 -0500485 assert(pinfo->size != 12345678);
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -0600486 return (png_voidp)(pinfo->pointer);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600487 }
488}
489
490/* Free a pointer. It is removed from the list at the same time. */
491void
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500492png_debug_free(png_structp png_ptr, png_voidp ptr)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600493{
494 if (png_ptr == NULL)
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500495 fprintf(STDERR, "NULL pointer to png_debug_free.\n");
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600496 if (ptr == 0)
497 {
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600498#if 0 /* This happens all the time. */
499 fprintf(STDERR, "WARNING: freeing NULL pointer\n");
500#endif
501 return;
502 }
503
504 /* Unlink the element from the list. */
505 {
506 memory_infop FAR *ppinfo = &pinformation;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600507 for (;;)
508 {
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600509 memory_infop pinfo = *ppinfo;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600510 if (pinfo->pointer == ptr)
511 {
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600512 *ppinfo = pinfo->next;
513 current_allocation -= pinfo->size;
514 if (current_allocation < 0)
515 fprintf(STDERR, "Duplicate free of memory\n");
516 /* We must free the list element too, but first kill
Glenn Randers-Pehrson8686fff1998-05-21 09:27:50 -0500517 the memory that is to be freed. */
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600518 memset(ptr, 0x55, pinfo->size);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500519 png_free_default(png_ptr, pinfo);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600520 break;
521 }
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600522 if (pinfo->next == NULL)
523 {
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600524 fprintf(STDERR, "Pointer %x not found\n", ptr);
525 break;
526 }
527 ppinfo = &pinfo->next;
528 }
529 }
530
531 /* Finally free the data. */
Glenn Randers-Pehrson6d8f3b01999-10-23 08:39:18 -0500532#if PNG_DEBUG
533 if(verbose)
534 printf("Freeing %x\n",ptr);
535#endif
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500536 png_free_default(png_ptr, ptr);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600537}
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500538#endif /* PNG_USER_MEM_SUPPORTED */
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600539/* END of code to test memory allocation/deallocation */
540
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600541/* Test one file */
Glenn Randers-Pehrson7cd899c1998-03-07 16:17:42 -0600542int
543test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
Guy Schalnat0d580581995-07-20 02:43:20 -0500544{
Glenn Randers-Pehrson316f97a2000-07-08 13:19:41 -0500545 static png_FILE_p fpin;
546 static png_FILE_p fpout; /* "static" prevents setjmp corruption */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500547 png_structp read_ptr, write_ptr;
Glenn Randers-Pehrson6d8f3b01999-10-23 08:39:18 -0500548 png_infop read_info_ptr, write_info_ptr, end_info_ptr, write_end_info_ptr;
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600549 png_bytep row_buf;
Guy Schalnat0d580581995-07-20 02:43:20 -0500550 png_uint_32 y;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500551 png_uint_32 width, height;
552 int num_pass, pass;
553 int bit_depth, color_type;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600554#ifdef PNG_SETJMP_SUPPORTED
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600555#ifdef USE_FAR_KEYWORD
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -0600556 jmp_buf jmpbuf;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600557#endif
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600558#endif
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600559
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600560 char inbuf[256], outbuf[256];
561
Guy Schalnate5a37791996-06-05 15:50:50 -0500562 row_buf = (png_bytep)NULL;
Guy Schalnat0d580581995-07-20 02:43:20 -0500563
Andreas Dilger47a0c421997-05-16 02:46:07 -0500564 if ((fpin = fopen(inname, "rb")) == NULL)
Guy Schalnat0f716451995-11-28 11:22:13 -0600565 {
566 fprintf(STDERR, "Could not find input file %s\n", inname);
Glenn Randers-Pehrsonb2120021998-01-31 20:07:59 -0600567 return (1);
Guy Schalnat0f716451995-11-28 11:22:13 -0600568 }
Guy Schalnat0d580581995-07-20 02:43:20 -0500569
Andreas Dilger47a0c421997-05-16 02:46:07 -0500570 if ((fpout = fopen(outname, "wb")) == NULL)
Guy Schalnat0f716451995-11-28 11:22:13 -0600571 {
Guy Schalnate5a37791996-06-05 15:50:50 -0500572 fprintf(STDERR, "Could not open output file %s\n", outname);
Guy Schalnat0f716451995-11-28 11:22:13 -0600573 fclose(fpin);
Glenn Randers-Pehrsonb2120021998-01-31 20:07:59 -0600574 return (1);
Guy Schalnat0f716451995-11-28 11:22:13 -0600575 }
Guy Schalnat0d580581995-07-20 02:43:20 -0500576
Andreas Dilger47a0c421997-05-16 02:46:07 -0500577 png_debug(0, "Allocating read and write structures\n");
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500578#ifdef PNG_USER_MEM_SUPPORTED
579 read_ptr = png_create_read_struct_2(PNG_LIBPNG_VER_STRING, (png_voidp)NULL,
580 (png_error_ptr)NULL, (png_error_ptr)NULL, (png_voidp)NULL,
581 (png_malloc_ptr)png_debug_malloc, (png_free_ptr)png_debug_free);
582#else
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600583 read_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, (png_voidp)NULL,
Andreas Dilger47a0c421997-05-16 02:46:07 -0500584 (png_error_ptr)NULL, (png_error_ptr)NULL);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500585#endif
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600586#if defined(PNG_NO_STDIO)
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500587 png_set_error_fn(read_ptr, (png_voidp)inname, pngtest_error,
588 pngtest_warning);
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600589#endif
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500590#ifdef PNG_USER_MEM_SUPPORTED
591 write_ptr = png_create_write_struct_2(PNG_LIBPNG_VER_STRING, (png_voidp)NULL,
592 (png_error_ptr)NULL, (png_error_ptr)NULL, (png_voidp)NULL,
593 (png_malloc_ptr)png_debug_malloc, (png_free_ptr)png_debug_free);
594#else
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600595 write_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, (png_voidp)NULL,
Guy Schalnate5a37791996-06-05 15:50:50 -0500596 (png_error_ptr)NULL, (png_error_ptr)NULL);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500597#endif
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600598#if defined(PNG_NO_STDIO)
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500599 png_set_error_fn(write_ptr, (png_voidp)inname, pngtest_error,
600 pngtest_warning);
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600601#endif
Andreas Dilger47a0c421997-05-16 02:46:07 -0500602 png_debug(0, "Allocating read_info, write_info and end_info structures\n");
603 read_info_ptr = png_create_info_struct(read_ptr);
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -0600604 write_info_ptr = png_create_info_struct(write_ptr);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500605 end_info_ptr = png_create_info_struct(read_ptr);
Glenn Randers-Pehrson6d8f3b01999-10-23 08:39:18 -0500606 write_end_info_ptr = png_create_info_struct(write_ptr);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500607#ifdef PNG_USER_MEM_SUPPORTED
608#endif
Guy Schalnate5a37791996-06-05 15:50:50 -0500609
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600610#ifdef PNG_SETJMP_SUPPORTED
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -0600611 png_debug(0, "Setting jmpbuf for read struct\n");
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600612#ifdef USE_FAR_KEYWORD
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -0600613 if (setjmp(jmpbuf))
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600614#else
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -0600615 if (setjmp(png_jmpbuf(read_ptr)))
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600616#endif
Guy Schalnat0f716451995-11-28 11:22:13 -0600617 {
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600618 fprintf(STDERR, "%s -> %s: libpng read error\n", inname, outname);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500619 png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr);
Glenn Randers-Pehrson6d8f3b01999-10-23 08:39:18 -0500620 png_destroy_info_struct(write_ptr, &write_end_info_ptr);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500621 png_destroy_write_struct(&write_ptr, &write_info_ptr);
Guy Schalnat0f716451995-11-28 11:22:13 -0600622 fclose(fpin);
623 fclose(fpout);
Glenn Randers-Pehrsonb2120021998-01-31 20:07:59 -0600624 return (1);
Guy Schalnat0f716451995-11-28 11:22:13 -0600625 }
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600626#ifdef USE_FAR_KEYWORD
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -0600627 png_memcpy(png_jmpbuf(read_ptr),jmpbuf,sizeof(jmp_buf));
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600628#endif
Andreas Dilger47a0c421997-05-16 02:46:07 -0500629
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -0600630 png_debug(0, "Setting jmpbuf for write struct\n");
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600631#ifdef USE_FAR_KEYWORD
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -0600632 if (setjmp(jmpbuf))
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600633#else
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -0600634 if (setjmp(png_jmpbuf(write_ptr)))
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600635#endif
Guy Schalnatb2e01bd1996-01-26 01:38:47 -0600636 {
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600637 fprintf(STDERR, "%s -> %s: libpng write error\n", inname, outname);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500638 png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr);
Glenn Randers-Pehrson6d8f3b01999-10-23 08:39:18 -0500639 png_destroy_info_struct(write_ptr, &write_end_info_ptr);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500640 png_destroy_write_struct(&write_ptr, &write_info_ptr);
Guy Schalnat0f716451995-11-28 11:22:13 -0600641 fclose(fpin);
642 fclose(fpout);
Glenn Randers-Pehrsonb2120021998-01-31 20:07:59 -0600643 return (1);
Guy Schalnat0f716451995-11-28 11:22:13 -0600644 }
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600645#ifdef USE_FAR_KEYWORD
Glenn Randers-Pehrson520a7642000-03-21 05:13:06 -0600646 png_memcpy(png_jmpbuf(write_ptr),jmpbuf,sizeof(jmp_buf));
Andreas Dilger02ad0ef1997-01-17 01:34:35 -0600647#endif
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600648#endif
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600649
Andreas Dilger47a0c421997-05-16 02:46:07 -0500650 png_debug(0, "Initializing input and output streams\n");
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600651#if !defined(PNG_NO_STDIO)
Guy Schalnate5a37791996-06-05 15:50:50 -0500652 png_init_io(read_ptr, fpin);
653 png_init_io(write_ptr, fpout);
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600654#else
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500655 png_set_read_fn(read_ptr, (png_voidp)fpin, pngtest_read_data);
656 png_set_write_fn(write_ptr, (png_voidp)fpout, pngtest_write_data,
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600657#if defined(PNG_WRITE_FLUSH_SUPPORTED)
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -0500658 pngtest_flush);
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -0600659#else
660 NULL);
661#endif
662#endif
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -0600663 if(status_dots_requested == 1)
664 {
665 png_set_write_status_fn(write_ptr, write_row_callback);
666 png_set_read_status_fn(read_ptr, read_row_callback);
667 }
668 else
669 {
670 png_set_write_status_fn(write_ptr, NULL);
671 png_set_read_status_fn(read_ptr, NULL);
672 }
673
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -0500674#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
675 {
676 int i;
677 for(i=0; i<256; i++)
678 filters_used[i]=0;
679 png_set_read_user_transform_fn(read_ptr, count_filters);
680 }
681#endif
682#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
683 zero_samples=0;
684 png_set_write_user_transform_fn(write_ptr, count_zero_samples);
685#endif
Guy Schalnat0d580581995-07-20 02:43:20 -0500686
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600687#define HANDLE_CHUNK_IF_SAFE 2
688#define HANDLE_CHUNK_ALWAYS 3
689#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
690 png_set_keep_unknown_chunks(read_ptr, HANDLE_CHUNK_ALWAYS, NULL, 0);
691#endif
692#if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
693 png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_IF_SAFE, NULL, 0);
694#endif
695
Andreas Dilger47a0c421997-05-16 02:46:07 -0500696 png_debug(0, "Reading info struct\n");
697 png_read_info(read_ptr, read_info_ptr);
Guy Schalnat0d580581995-07-20 02:43:20 -0500698
Andreas Dilger47a0c421997-05-16 02:46:07 -0500699 png_debug(0, "Transferring info struct\n");
700 {
701 int interlace_type, compression_type, filter_type;
Guy Schalnat0d580581995-07-20 02:43:20 -0500702
Andreas Dilger47a0c421997-05-16 02:46:07 -0500703 if (png_get_IHDR(read_ptr, read_info_ptr, &width, &height, &bit_depth,
704 &color_type, &interlace_type, &compression_type, &filter_type))
705 {
706 png_set_IHDR(write_ptr, write_info_ptr, width, height, bit_depth,
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600707#if defined(PNG_WRITE_INTERLACING_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500708 color_type, interlace_type, compression_type, filter_type);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -0600709#else
710 color_type, PNG_INTERLACE_NONE, compression_type, filter_type);
711#endif
Andreas Dilger47a0c421997-05-16 02:46:07 -0500712 }
713 }
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -0500714#if defined(PNG_FIXED_POINT_SUPPORTED)
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600715#if defined(PNG_cHRM_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500716 {
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600717 png_fixed_point white_x, white_y, red_x, red_y, green_x, green_y, blue_x,
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600718 blue_y;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600719 if (png_get_cHRM_fixed(read_ptr, read_info_ptr, &white_x, &white_y, &red_x,
Andreas Dilger47a0c421997-05-16 02:46:07 -0500720 &red_y, &green_x, &green_y, &blue_x, &blue_y))
721 {
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600722 png_set_cHRM_fixed(write_ptr, write_info_ptr, white_x, white_y, red_x,
Andreas Dilger47a0c421997-05-16 02:46:07 -0500723 red_y, green_x, green_y, blue_x, blue_y);
724 }
725 }
726#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600727#if defined(PNG_gAMA_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500728 {
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600729 png_fixed_point gamma;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500730
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600731 if (png_get_gAMA_fixed(read_ptr, read_info_ptr, &gamma))
Andreas Dilger47a0c421997-05-16 02:46:07 -0500732 {
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600733 png_set_gAMA_fixed(write_ptr, write_info_ptr, gamma);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500734 }
735 }
736#endif
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -0500737#else /* Use floating point versions */
738#if defined(PNG_FLOATING_POINT_SUPPORTED)
739#if defined(PNG_cHRM_SUPPORTED)
740 {
741 double white_x, white_y, red_x, red_y, green_x, green_y, blue_x,
742 blue_y;
743 if (png_get_cHRM(read_ptr, read_info_ptr, &white_x, &white_y, &red_x,
744 &red_y, &green_x, &green_y, &blue_x, &blue_y))
745 {
746 png_set_cHRM(write_ptr, write_info_ptr, white_x, white_y, red_x,
747 red_y, green_x, green_y, blue_x, blue_y);
748 }
749 }
750#endif
751#if defined(PNG_gAMA_SUPPORTED)
752 {
753 double gamma;
754
755 if (png_get_gAMA(read_ptr, read_info_ptr, &gamma))
756 {
757 png_set_gAMA(write_ptr, write_info_ptr, gamma);
758 }
759 }
760#endif
761#endif /* floating point */
762#endif /* fixed point */
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600763#if defined(PNG_iCCP_SUPPORTED)
764 {
765 png_charp name;
766 png_charp profile;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600767 png_uint_32 proflen;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600768 int compression_type;
769
770 if (png_get_iCCP(read_ptr, read_info_ptr, &name, &compression_type,
771 &profile, &proflen))
772 {
773 png_set_iCCP(write_ptr, write_info_ptr, name, compression_type,
774 profile, proflen);
775 }
776 }
777#endif
778#if defined(PNG_sRGB_SUPPORTED)
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600779 {
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -0600780 int intent;
Glenn Randers-Pehrsonb6ce43d1998-01-01 07:13:13 -0600781
782 if (png_get_sRGB(read_ptr, read_info_ptr, &intent))
783 {
784 png_set_sRGB(write_ptr, write_info_ptr, intent);
785 }
786 }
787#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600788 {
789 png_colorp palette;
790 int num_palette;
791
792 if (png_get_PLTE(read_ptr, read_info_ptr, &palette, &num_palette))
793 {
794 png_set_PLTE(write_ptr, write_info_ptr, palette, num_palette);
795 }
796 }
797#if defined(PNG_bKGD_SUPPORTED)
798 {
799 png_color_16p background;
800
801 if (png_get_bKGD(read_ptr, read_info_ptr, &background))
802 {
803 png_set_bKGD(write_ptr, write_info_ptr, background);
804 }
805 }
806#endif
807#if defined(PNG_hIST_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500808 {
809 png_uint_16p hist;
810
811 if (png_get_hIST(read_ptr, read_info_ptr, &hist))
812 {
813 png_set_hIST(write_ptr, write_info_ptr, hist);
814 }
815 }
816#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600817#if defined(PNG_oFFs_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500818 {
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600819 png_int_32 offset_x, offset_y;
Andreas Dilger47a0c421997-05-16 02:46:07 -0500820 int unit_type;
821
822 if (png_get_oFFs(read_ptr, read_info_ptr,&offset_x,&offset_y,&unit_type))
823 {
824 png_set_oFFs(write_ptr, write_info_ptr, offset_x, offset_y, unit_type);
825 }
826 }
827#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600828#if defined(PNG_pCAL_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500829 {
830 png_charp purpose, units;
831 png_charpp params;
832 png_int_32 X0, X1;
833 int type, nparams;
834
835 if (png_get_pCAL(read_ptr, read_info_ptr, &purpose, &X0, &X1, &type,
836 &nparams, &units, &params))
837 {
838 png_set_pCAL(write_ptr, write_info_ptr, purpose, X0, X1, type,
839 nparams, units, params);
840 }
841 }
842#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600843#if defined(PNG_pHYs_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500844 {
845 png_uint_32 res_x, res_y;
846 int unit_type;
847
848 if (png_get_pHYs(read_ptr, read_info_ptr, &res_x, &res_y, &unit_type))
849 {
850 png_set_pHYs(write_ptr, write_info_ptr, res_x, res_y, unit_type);
851 }
852 }
853#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600854#if defined(PNG_sBIT_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500855 {
856 png_color_8p sig_bit;
857
858 if (png_get_sBIT(read_ptr, read_info_ptr, &sig_bit))
859 {
860 png_set_sBIT(write_ptr, write_info_ptr, sig_bit);
861 }
862 }
863#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600864#if defined(PNG_sCAL_SUPPORTED)
865#ifdef PNG_FLOATING_POINT_SUPPORTED
866 {
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600867 int unit;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600868 double width, height;
869
870 if (png_get_sCAL(read_ptr, read_info_ptr, &unit, &width, &height))
871 {
872 png_set_sCAL(write_ptr, write_info_ptr, unit, width, height);
873 }
874 }
875#else
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600876#ifdef PNG_FIXED_POINT_SUPPORTED
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600877 {
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600878 int unit;
879 png_charp width, height;
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600880
881 if (png_get_sCAL_s(read_ptr, read_info_ptr, &unit, &width, &height))
882 {
883 png_set_sCAL_s(write_ptr, write_info_ptr, unit, width, height);
884 }
885 }
886#endif
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600887#endif
888#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600889#if defined(PNG_TEXT_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500890 {
891 png_textp text_ptr;
892 int num_text;
893
894 if (png_get_text(read_ptr, read_info_ptr, &text_ptr, &num_text) > 0)
895 {
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600896 png_debug1(0, "Handling %d iTXt/tEXt/zTXt chunks\n", num_text);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500897 png_set_text(write_ptr, write_info_ptr, text_ptr, num_text);
898 }
899 }
900#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600901#if defined(PNG_tIME_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500902 {
903 png_timep mod_time;
904
905 if (png_get_tIME(read_ptr, read_info_ptr, &mod_time))
906 {
907 png_set_tIME(write_ptr, write_info_ptr, mod_time);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500908#if defined(PNG_TIME_RFC1123_SUPPORTED)
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500909 /* we have to use png_strcpy instead of "=" because the string
910 pointed to by png_convert_to_rfc1123() gets free'ed before
911 we use it */
912 png_strcpy(tIME_string,png_convert_to_rfc1123(read_ptr, mod_time));
913 tIME_chunk_present++;
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -0500914#endif /* PNG_TIME_RFC1123_SUPPORTED */
Glenn Randers-Pehrsonc9442291999-01-06 21:50:16 -0600915 }
Andreas Dilger47a0c421997-05-16 02:46:07 -0500916 }
917#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -0600918#if defined(PNG_tRNS_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500919 {
920 png_bytep trans;
921 int num_trans;
922 png_color_16p trans_values;
923
924 if (png_get_tRNS(read_ptr, read_info_ptr, &trans, &num_trans,
925 &trans_values))
926 {
927 png_set_tRNS(write_ptr, write_info_ptr, trans, num_trans,
928 trans_values);
929 }
930 }
931#endif
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600932#if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
933 {
934 png_unknown_chunkp unknowns;
935 int num_unknowns = (int)png_get_unknown_chunks(read_ptr, read_info_ptr,
936 &unknowns);
937 if (num_unknowns)
938 {
939 png_size_t i;
940 png_set_unknown_chunks(write_ptr, write_info_ptr, unknowns,
941 num_unknowns);
942 /* copy the locations from the read_info_ptr. The automatically
943 generated locations in write_info_ptr are wrong because we
944 haven't written anything yet */
945 for (i = 0; i < (png_size_t)num_unknowns; i++)
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -0500946 png_set_unknown_chunk_location(write_ptr, write_info_ptr, i,
947 unknowns[i].location);
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -0600948 }
949 }
950#endif
Andreas Dilger47a0c421997-05-16 02:46:07 -0500951
952 png_debug(0, "\nWriting info struct\n");
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -0600953
954/* If we wanted, we could write info in two steps:
955 png_write_info_before_PLTE(write_ptr, write_info_ptr);
956 */
Andreas Dilger47a0c421997-05-16 02:46:07 -0500957 png_write_info(write_ptr, write_info_ptr);
958
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -0600959 png_debug(0, "\nAllocating row buffer \n");
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -0600960 row_buf = (png_bytep)png_malloc(read_ptr,
Andreas Dilger47a0c421997-05-16 02:46:07 -0500961 png_get_rowbytes(read_ptr, read_info_ptr));
962 if (row_buf == NULL)
Guy Schalnat0f716451995-11-28 11:22:13 -0600963 {
Guy Schalnate5a37791996-06-05 15:50:50 -0500964 fprintf(STDERR, "No memory to allocate row buffer\n");
Andreas Dilger47a0c421997-05-16 02:46:07 -0500965 png_destroy_read_struct(&read_ptr, &read_info_ptr, (png_infopp)NULL);
Glenn Randers-Pehrson6d8f3b01999-10-23 08:39:18 -0500966 png_destroy_info_struct(write_ptr, &write_end_info_ptr);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500967 png_destroy_write_struct(&write_ptr, &write_info_ptr);
Guy Schalnat0f716451995-11-28 11:22:13 -0600968 fclose(fpin);
969 fclose(fpout);
Glenn Randers-Pehrsonb2120021998-01-31 20:07:59 -0600970 return (1);
Guy Schalnat0f716451995-11-28 11:22:13 -0600971 }
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -0600972 png_debug(0, "Writing row data\n");
Guy Schalnat0d580581995-07-20 02:43:20 -0500973
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -0500974#if defined(PNG_READ_INTERLACING_SUPPORTED) || \
975 defined(PNG_WRITE_INTERLACING_SUPPORTED)
Andreas Dilger47a0c421997-05-16 02:46:07 -0500976 num_pass = png_set_interlace_handling(read_ptr);
977 png_set_interlace_handling(write_ptr);
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -0500978#else
979 num_pass=1;
980#endif
Guy Schalnat0d580581995-07-20 02:43:20 -0500981
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -0500982#ifdef PNGTEST_TIMING
983 t_stop = (float)clock();
984 t_misc += (t_stop - t_start);
985 t_start = t_stop;
986#endif
Guy Schalnat0f716451995-11-28 11:22:13 -0600987 for (pass = 0; pass < num_pass; pass++)
988 {
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -0600989 png_debug1(0, "Writing row data for pass %d\n",pass);
Andreas Dilger47a0c421997-05-16 02:46:07 -0500990 for (y = 0; y < height; y++)
Guy Schalnat0f716451995-11-28 11:22:13 -0600991 {
Andreas Dilger47a0c421997-05-16 02:46:07 -0500992 png_read_rows(read_ptr, (png_bytepp)&row_buf, (png_bytepp)NULL, 1);
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -0500993#ifdef PNGTEST_TIMING
994 t_stop = (float)clock();
995 t_decode += (t_stop - t_start);
996 t_start = t_stop;
997#endif
Guy Schalnate5a37791996-06-05 15:50:50 -0500998 png_write_rows(write_ptr, (png_bytepp)&row_buf, 1);
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -0500999#ifdef PNGTEST_TIMING
1000 t_stop = (float)clock();
1001 t_encode += (t_stop - t_start);
1002 t_start = t_stop;
1003#endif
Guy Schalnat0f716451995-11-28 11:22:13 -06001004 }
1005 }
Guy Schalnat0d580581995-07-20 02:43:20 -05001006
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001007#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001008 png_free_data(read_ptr, read_info_ptr, PNG_FREE_UNKN, -1);
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001009#endif
1010#if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
Glenn Randers-Pehrsona77ef622000-02-18 13:48:52 -06001011 png_free_data(write_ptr, write_info_ptr, PNG_FREE_UNKN, -1);
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001012#endif
1013
Andreas Dilger47a0c421997-05-16 02:46:07 -05001014 png_debug(0, "Reading and writing end_info data\n");
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001015
Andreas Dilger47a0c421997-05-16 02:46:07 -05001016 png_read_end(read_ptr, end_info_ptr);
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001017#if defined(PNG_TEXT_SUPPORTED)
Glenn Randers-Pehrson6d8f3b01999-10-23 08:39:18 -05001018 {
1019 png_textp text_ptr;
1020 int num_text;
1021
1022 if (png_get_text(read_ptr, end_info_ptr, &text_ptr, &num_text) > 0)
1023 {
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001024 png_debug1(0, "Handling %d iTXt/tEXt/zTXt chunks\n", num_text);
Glenn Randers-Pehrson6d8f3b01999-10-23 08:39:18 -05001025 png_set_text(write_ptr, write_end_info_ptr, text_ptr, num_text);
1026 }
1027 }
1028#endif
Glenn Randers-Pehrson166c5a31999-12-10 09:43:02 -06001029#if defined(PNG_tIME_SUPPORTED)
Glenn Randers-Pehrson6d8f3b01999-10-23 08:39:18 -05001030 {
1031 png_timep mod_time;
1032
1033 if (png_get_tIME(read_ptr, end_info_ptr, &mod_time))
1034 {
1035 png_set_tIME(write_ptr, write_end_info_ptr, mod_time);
1036#if defined(PNG_TIME_RFC1123_SUPPORTED)
1037 /* we have to use png_strcpy instead of "=" because the string
1038 pointed to by png_convert_to_rfc1123() gets free'ed before
1039 we use it */
1040 png_strcpy(tIME_string,png_convert_to_rfc1123(read_ptr, mod_time));
1041 tIME_chunk_present++;
1042#endif /* PNG_TIME_RFC1123_SUPPORTED */
1043 }
1044 }
1045#endif
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001046#if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
1047 {
1048 png_unknown_chunkp unknowns;
1049 int num_unknowns;
1050 num_unknowns = (int)png_get_unknown_chunks(read_ptr, end_info_ptr,
1051 &unknowns);
1052 if (num_unknowns)
1053 {
1054 png_size_t i;
1055 png_set_unknown_chunks(write_ptr, write_end_info_ptr, unknowns,
1056 num_unknowns);
1057 /* copy the locations from the read_info_ptr. The automatically
1058 generated locations in write_end_info_ptr are wrong because we
1059 haven't written the end_info yet */
1060 for (i = 0; i < (png_size_t)num_unknowns; i++)
Glenn Randers-Pehrson228bd392000-04-23 23:14:02 -05001061 png_set_unknown_chunk_location(write_ptr, write_end_info_ptr, i,
1062 unknowns[i].location);
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001063 }
1064 }
1065#endif
Glenn Randers-Pehrson6d8f3b01999-10-23 08:39:18 -05001066 png_write_end(write_ptr, write_end_info_ptr);
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001067
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001068#ifdef PNG_EASY_ACCESS_SUPPORTED
1069 if(verbose)
1070 {
1071 png_uint_32 iwidth, iheight;
1072 iwidth = png_get_image_width(write_ptr, write_info_ptr);
1073 iheight = png_get_image_height(write_ptr, write_info_ptr);
1074 fprintf(STDERR, "Image width = %lu, height = %lu\n",
1075 iwidth, iheight);
1076 }
1077#endif
Guy Schalnat0d580581995-07-20 02:43:20 -05001078
Andreas Dilger47a0c421997-05-16 02:46:07 -05001079 png_debug(0, "Destroying data structs\n");
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -06001080 png_free(read_ptr, row_buf);
Andreas Dilger47a0c421997-05-16 02:46:07 -05001081 png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr);
Glenn Randers-Pehrson6d8f3b01999-10-23 08:39:18 -05001082 png_destroy_info_struct(write_ptr, &write_end_info_ptr);
Andreas Dilger47a0c421997-05-16 02:46:07 -05001083 png_destroy_write_struct(&write_ptr, &write_info_ptr);
Guy Schalnat0d580581995-07-20 02:43:20 -05001084
Guy Schalnat0f716451995-11-28 11:22:13 -06001085 fclose(fpin);
1086 fclose(fpout);
Guy Schalnat0d580581995-07-20 02:43:20 -05001087
Andreas Dilger47a0c421997-05-16 02:46:07 -05001088 png_debug(0, "Opening files for comparison\n");
1089 if ((fpin = fopen(inname, "rb")) == NULL)
Guy Schalnat0f716451995-11-28 11:22:13 -06001090 {
Guy Schalnate5a37791996-06-05 15:50:50 -05001091 fprintf(STDERR, "Could not find file %s\n", inname);
Glenn Randers-Pehrsonb2120021998-01-31 20:07:59 -06001092 return (1);
Guy Schalnat0f716451995-11-28 11:22:13 -06001093 }
Guy Schalnat0d580581995-07-20 02:43:20 -05001094
Andreas Dilger47a0c421997-05-16 02:46:07 -05001095 if ((fpout = fopen(outname, "rb")) == NULL)
Guy Schalnat0f716451995-11-28 11:22:13 -06001096 {
Guy Schalnate5a37791996-06-05 15:50:50 -05001097 fprintf(STDERR, "Could not find file %s\n", outname);
Guy Schalnat0f716451995-11-28 11:22:13 -06001098 fclose(fpin);
Glenn Randers-Pehrsonb2120021998-01-31 20:07:59 -06001099 return (1);
Guy Schalnat0f716451995-11-28 11:22:13 -06001100 }
Andreas Dilger47a0c421997-05-16 02:46:07 -05001101
Glenn Randers-Pehrsonea3bcd71998-03-07 14:33:00 -06001102 for(;;)
Guy Schalnat0f716451995-11-28 11:22:13 -06001103 {
Andreas Dilger47a0c421997-05-16 02:46:07 -05001104 png_size_t num_in, num_out;
Guy Schalnat0d580581995-07-20 02:43:20 -05001105
Glenn Randers-Pehrson316f97a2000-07-08 13:19:41 -05001106 READFILE(fpin, inbuf, 1, num_in);
1107 READFILE(fpout, outbuf, 1, num_out);
Guy Schalnat0d580581995-07-20 02:43:20 -05001108
Guy Schalnat0f716451995-11-28 11:22:13 -06001109 if (num_in != num_out)
1110 {
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001111 fprintf(STDERR, "\nFiles %s and %s are of a different size\n",
Guy Schalnate5a37791996-06-05 15:50:50 -05001112 inname, outname);
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001113 if(wrote_question == 0)
1114 {
1115 fprintf(STDERR,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001116 " Was %s written with the same maximum IDAT chunk size (%d bytes),",
1117 inname,PNG_ZBUF_SIZE);
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001118 fprintf(STDERR,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001119 "\n filtering heuristic (libpng default), compression");
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001120 fprintf(STDERR,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001121 " level (zlib default),\n and zlib version (%s)?\n\n",
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001122 ZLIB_VERSION);
1123 wrote_question=1;
1124 }
Guy Schalnat0f716451995-11-28 11:22:13 -06001125 fclose(fpin);
1126 fclose(fpout);
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001127 return (0);
Guy Schalnat0f716451995-11-28 11:22:13 -06001128 }
Guy Schalnat0d580581995-07-20 02:43:20 -05001129
Guy Schalnat0f716451995-11-28 11:22:13 -06001130 if (!num_in)
1131 break;
Guy Schalnat0d580581995-07-20 02:43:20 -05001132
Andreas Dilger47a0c421997-05-16 02:46:07 -05001133 if (png_memcmp(inbuf, outbuf, num_in))
Guy Schalnat0f716451995-11-28 11:22:13 -06001134 {
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05001135 fprintf(STDERR, "\nFiles %s and %s are different\n", inname, outname);
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001136 if(wrote_question == 0)
1137 {
1138 fprintf(STDERR,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001139 " Was %s written with the same maximum IDAT chunk size (%d bytes),",
1140 inname,PNG_ZBUF_SIZE);
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001141 fprintf(STDERR,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001142 "\n filtering heuristic (libpng default), compression");
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001143 fprintf(STDERR,
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001144 " level (zlib default),\n and zlib version (%s)?\n\n",
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001145 ZLIB_VERSION);
1146 wrote_question=1;
1147 }
Guy Schalnat0f716451995-11-28 11:22:13 -06001148 fclose(fpin);
1149 fclose(fpout);
Glenn Randers-Pehrsoncbe52d81998-02-28 07:00:24 -06001150 return (0);
Guy Schalnat0f716451995-11-28 11:22:13 -06001151 }
1152 }
1153
1154 fclose(fpin);
1155 fclose(fpout);
Guy Schalnat0d580581995-07-20 02:43:20 -05001156
Glenn Randers-Pehrsonb2120021998-01-31 20:07:59 -06001157 return (0);
Guy Schalnat0d580581995-07-20 02:43:20 -05001158}
Guy Schalnat51f0eb41995-09-26 05:22:39 -05001159
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -06001160/* input and output filenames */
1161#ifdef RISCOS
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05001162static PNG_CONST char *inname = "pngtest/png";
1163static PNG_CONST char *outname = "pngout/png";
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -06001164#else
Glenn Randers-Pehrson983ec161998-03-07 11:24:03 -06001165static PNG_CONST char *inname = "pngtest.png";
1166static PNG_CONST char *outname = "pngout.png";
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -06001167#endif
1168
1169int
1170main(int argc, char *argv[])
1171{
1172 int multiple = 0;
1173 int ierror = 0;
1174
1175 fprintf(STDERR, "Testing libpng version %s\n", PNG_LIBPNG_VER_STRING);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001176 fprintf(STDERR, " with zlib version %s\n", ZLIB_VERSION);
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001177 fprintf(STDERR,"%s",png_get_copyright(NULL));
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -06001178 /* Show the version of libpng used in building the library */
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05001179 fprintf(STDERR," library (%lu):%s", png_access_version_number(),
1180 png_get_header_version(NULL));
Glenn Randers-Pehrson5379b241999-11-27 10:22:33 -06001181 /* Show the version of libpng used in building the application */
Glenn Randers-Pehrson13944802000-06-24 07:42:42 -05001182 fprintf(STDERR," pngtest (%lu):%s", (unsigned long)PNG_LIBPNG_VER,
Glenn Randers-Pehrson1ef65b62000-05-12 06:19:53 -05001183 PNG_HEADER_VERSION_STRING);
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05001184 fprintf(STDERR," sizeof(png_struct)=%d, sizeof(png_info)=%d\n",
1185 sizeof(png_struct), sizeof(png_info));
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001186
1187 /* Do some consistency checking on the memory allocation settings, I'm
1188 not sure this matters, but it is nice to know, the first of these
1189 tests should be impossible because of the way the macros are set
1190 in pngconf.h */
Glenn Randers-Pehrsonea3bcd71998-03-07 14:33:00 -06001191#if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001192 fprintf(STDERR, " NOTE: Zlib compiled for max 64k, libpng not\n");
Glenn Randers-Pehrsonea3bcd71998-03-07 14:33:00 -06001193#endif
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001194 /* I think the following can happen. */
Glenn Randers-Pehrsonea3bcd71998-03-07 14:33:00 -06001195#if !defined(MAXSEG_64K) && defined(PNG_MAX_MALLOC_64K)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001196 fprintf(STDERR, " NOTE: libpng compiled for max 64k, zlib not\n");
Glenn Randers-Pehrsonea3bcd71998-03-07 14:33:00 -06001197#endif
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -06001198
1199 if (strcmp(png_libpng_ver, PNG_LIBPNG_VER_STRING))
1200 {
1201 fprintf(STDERR,
1202 "Warning: versions are different between png.h and png.c\n");
1203 fprintf(STDERR, " png.h version: %s\n", PNG_LIBPNG_VER_STRING);
1204 fprintf(STDERR, " png.c version: %s\n\n", png_libpng_ver);
1205 ++ierror;
1206 }
1207
1208 if (argc > 1)
1209 {
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001210 if (strcmp(argv[1], "-m") == 0)
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06001211 {
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001212 multiple = 1;
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06001213 status_dots_requested = 0;
1214 }
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001215 else if (strcmp(argv[1], "-mv") == 0 ||
1216 strcmp(argv[1], "-vm") == 0 )
1217 {
1218 multiple = 1;
1219 verbose = 1;
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06001220 status_dots_requested = 1;
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001221 }
1222 else if (strcmp(argv[1], "-v") == 0)
1223 {
1224 verbose = 1;
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06001225 status_dots_requested = 1;
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001226 inname = argv[2];
1227 }
1228 else
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06001229 {
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001230 inname = argv[1];
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06001231 status_dots_requested = 0;
1232 }
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -06001233 }
1234
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001235 if (!multiple && argc == 3+verbose)
1236 outname = argv[2+verbose];
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -06001237
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001238 if ((!multiple && argc > 3+verbose) || (multiple && argc < 2))
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -06001239 {
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -06001240 fprintf(STDERR,
1241 "usage: %s [infile.png] [outfile.png]\n\t%s -m {infile.png}\n",
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -06001242 argv[0], argv[0]);
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -06001243 fprintf(STDERR,
1244 " reads/writes one PNG file (without -m) or multiple files (-m)\n");
1245 fprintf(STDERR,
1246 " with -m %s is used as a temporary file\n", outname);
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -06001247 exit(1);
1248 }
1249
1250 if (multiple)
1251 {
1252 int i;
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001253#ifdef PNG_USER_MEM_SUPPORTED
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001254 int allocation_now = current_allocation;
1255#endif
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -06001256 for (i=2; i<argc; ++i)
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001257 {
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05001258#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
1259 int k;
1260#endif
1261 int kerror;
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -06001262 fprintf(STDERR, "Testing %s:",argv[i]);
1263 kerror = test_one_file(argv[i], outname);
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001264 if (kerror == 0)
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001265 {
Glenn Randers-Pehrson38d73af1998-03-07 21:30:44 -06001266#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
Glenn Randers-Pehrson6d8f3b01999-10-23 08:39:18 -05001267 fprintf(STDERR, "\n PASS (%lu zero samples)\n",zero_samples);
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06001268#else
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001269 fprintf(STDERR, " PASS\n");
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001270#endif
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05001271#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
1272 for (k=0; k<256; k++)
1273 if(filters_used[k])
1274 fprintf(STDERR, " Filter %d was used %lu times\n",
1275 k,filters_used[k]);
1276#endif
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001277#if defined(PNG_TIME_RFC1123_SUPPORTED)
1278 if(tIME_chunk_present != 0)
1279 fprintf(STDERR, " tIME = %s\n",tIME_string);
1280 tIME_chunk_present = 0;
1281#endif /* PNG_TIME_RFC1123_SUPPORTED */
1282 }
1283 else
1284 {
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -06001285 fprintf(STDERR, " FAIL\n");
1286 ierror += kerror;
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001287 }
1288#ifdef PNG_USER_MEM_SUPPORTED
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001289 if (allocation_now != current_allocation)
1290 fprintf(STDERR, "MEMORY ERROR: %d bytes lost\n",
1291 current_allocation-allocation_now);
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001292 if (current_allocation != 0)
1293 {
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001294 memory_infop pinfo = pinformation;
1295
1296 fprintf(STDERR, "MEMORY ERROR: %d bytes still allocated\n",
1297 current_allocation);
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001298 while (pinfo != NULL)
1299 {
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001300 fprintf(STDERR, " %d bytes at %x\n", pinfo->size, pinfo->pointer);
1301 pinfo = pinfo->next;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001302 }
Glenn Randers-Pehrson2687fcc1998-01-07 20:54:20 -06001303 }
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001304#endif
1305 }
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001306#ifdef PNG_USER_MEM_SUPPORTED
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -05001307 fprintf(STDERR, " Current memory allocation: %10d bytes\n",
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -05001308 current_allocation);
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -05001309 fprintf(STDERR, " Maximum memory allocation: %10d bytes\n",
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001310 maximum_allocation);
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -05001311 fprintf(STDERR, " Total memory allocation: %10d bytes\n",
1312 total_allocation);
1313 fprintf(STDERR, " Number of allocations: %10d\n",
1314 num_allocations);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001315#endif
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -06001316 }
1317 else
1318 {
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -06001319 int i;
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001320 for (i=0; i<3; ++i)
1321 {
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -06001322 int kerror;
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001323#ifdef PNG_USER_MEM_SUPPORTED
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001324 int allocation_now = current_allocation;
1325#endif
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06001326 if (i == 1) status_dots_requested = 1;
1327 else if(verbose == 0)status_dots_requested = 0;
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001328 if (i == 0 || verbose == 1 || ierror != 0)
1329 fprintf(STDERR, "Testing %s:",inname);
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -06001330 kerror = test_one_file(inname, outname);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001331 if(kerror == 0)
1332 {
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06001333 if(verbose == 1 || i == 2)
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001334 {
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05001335#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05001336 int k;
Glenn Randers-Pehrson6942d532000-05-01 09:31:54 -05001337#endif
Glenn Randers-Pehrson38d73af1998-03-07 21:30:44 -06001338#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
Glenn Randers-Pehrson6d8f3b01999-10-23 08:39:18 -05001339 fprintf(STDERR, "\n PASS (%lu zero samples)\n",zero_samples);
Glenn Randers-Pehrson08a33431998-03-07 06:06:55 -06001340#else
1341 fprintf(STDERR, " PASS\n");
1342#endif
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05001343#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
1344 for (k=0; k<256; k++)
1345 if(filters_used[k])
1346 fprintf(STDERR, " Filter %d was used %lu times\n",
1347 k,filters_used[k]);
1348#endif
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001349#if defined(PNG_TIME_RFC1123_SUPPORTED)
Glenn Randers-Pehrson4393a9a1999-09-17 12:27:26 -05001350 if(tIME_chunk_present != 0)
1351 fprintf(STDERR, " tIME = %s\n",tIME_string);
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001352#endif /* PNG_TIME_RFC1123_SUPPORTED */
1353 }
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001354 }
1355 else
1356 {
1357 if(verbose == 0 && i != 2)
1358 fprintf(STDERR, "Testing %s:",inname);
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -06001359 fprintf(STDERR, " FAIL\n");
1360 ierror += kerror;
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001361 }
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001362#ifdef PNG_USER_MEM_SUPPORTED
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001363 if (allocation_now != current_allocation)
1364 fprintf(STDERR, "MEMORY ERROR: %d bytes lost\n",
1365 current_allocation-allocation_now);
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001366 if (current_allocation != 0)
1367 {
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001368 memory_infop pinfo = pinformation;
Glenn Randers-Pehrson5c6aeb21998-12-29 11:47:59 -06001369
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001370 fprintf(STDERR, "MEMORY ERROR: %d bytes still allocated\n",
1371 current_allocation);
Glenn Randers-Pehrson61c32d92000-02-04 23:40:16 -06001372 while (pinfo != NULL)
1373 {
1374 fprintf(STDERR," %d bytes at %x\n",
1375 pinfo->size, pinfo->pointer);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001376 pinfo = pinfo->next;
1377 }
1378 }
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001379#endif
Glenn Randers-Pehrsonc4a2ae61998-01-16 22:06:18 -06001380 }
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001381#ifdef PNG_USER_MEM_SUPPORTED
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -05001382 fprintf(STDERR, " Current memory allocation: %10d bytes\n",
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -05001383 current_allocation);
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -05001384 fprintf(STDERR, " Maximum memory allocation: %10d bytes\n",
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001385 maximum_allocation);
Glenn Randers-Pehrson104622b2000-05-29 08:58:03 -05001386 fprintf(STDERR, " Total memory allocation: %10d bytes\n",
1387 total_allocation);
1388 fprintf(STDERR, " Number of allocations: %10d\n",
1389 num_allocations);
Glenn Randers-Pehrson46f61e21998-01-30 21:45:12 -06001390#endif
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -06001391 }
1392
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -05001393#ifdef PNGTEST_TIMING
1394 t_stop = (float)clock();
1395 t_misc += (t_stop - t_start);
1396 t_start = t_stop;
1397 fprintf(STDERR," CPU time used = %.3f seconds",
1398 (t_misc+t_decode+t_encode)/(float)CLOCKS_PER_SEC);
1399 fprintf(STDERR," (decoding %.3f,\n",
1400 t_decode/(float)CLOCKS_PER_SEC);
1401 fprintf(STDERR," encoding %.3f ,",
1402 t_encode/(float)CLOCKS_PER_SEC);
1403 fprintf(STDERR," other %.3f seconds)\n\n",
1404 t_misc/(float)CLOCKS_PER_SEC);
1405#endif
1406
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -06001407 if (ierror == 0)
1408 fprintf(STDERR, "libpng passes test\n");
1409 else
1410 fprintf(STDERR, "libpng FAILS test\n");
Glenn Randers-Pehrson0f881d61998-02-07 10:20:57 -06001411 return (int)(ierror != 0);
Glenn Randers-Pehrson70e3f541998-01-03 22:40:55 -06001412}
Glenn Randers-Pehrsonf7d1a171998-06-06 15:31:35 -05001413
Glenn Randers-Pehrsonbcfd15d1999-10-01 14:22:25 -05001414/* Generate a compiler error if there is an old png.h in the search path. */
Glenn Randers-Pehrson15dac0b2000-07-10 07:48:54 -05001415typedef version_1_0_8beta2 your_png_h_is_not_version_1_0_8beta2;