Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 1 | |
Guy Schalnat | 4ee97b0 | 1996-01-16 01:51:56 -0600 | [diff] [blame] | 2 | /* pngtest.c - a simple test program to test libpng |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 3 | * |
Glenn Randers-Pehrson | 5fea36f | 2004-07-28 08:20:44 -0500 | [diff] [blame^] | 4 | * libpng 1.2.6beta4 - July 28, 2004 |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 5 | * For conditions of distribution and use, see copyright notice in png.h |
Glenn Randers-Pehrson | 5b5dcf8 | 2004-07-17 22:45:44 -0500 | [diff] [blame] | 6 | * Copyright (c) 1998-2004 Glenn Randers-Pehrson |
Glenn Randers-Pehrson | d436672 | 2000-06-04 14:29:29 -0500 | [diff] [blame] | 7 | * (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-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 9 | * |
| 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-Pehrson | 345bc27 | 1998-06-14 14:43:31 -0500 | [diff] [blame] | 16 | * The program will report "FAIL" in certain legitimate cases: |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 17 | * 1) when the compression level or filter selection method is changed. |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 18 | * 2) when the maximum IDAT size (PNG_ZBUF_SIZE in pngconf.h) is not 8192. |
Glenn Randers-Pehrson | 5e5c1e1 | 2000-11-10 12:26:19 -0600 | [diff] [blame] | 19 | * 3) unknown unsafe-to-copy ancillary chunks or unknown critical chunks |
| 20 | * exist in the input file. |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 21 | * 4) others not listed here... |
| 22 | * In these cases, it is best to check with another tool such as "pngcheck" |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 23 | * to see what the differences between the two files are. |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 24 | * |
| 25 | * If a filename is given on the command-line, then this file is used |
| 26 | * for the input, rather than the default "pngtest.png". This allows |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 27 | * testing a wide variety of files easily. You can also test a number |
| 28 | * of files at once by typing "pngtest -m file1.png file2.png ..." |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 29 | */ |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 30 | |
Glenn Randers-Pehrson | 5fea36f | 2004-07-28 08:20:44 -0500 | [diff] [blame^] | 31 | #include "png.h" |
| 32 | |
Glenn Randers-Pehrson | 316f97a | 2000-07-08 13:19:41 -0500 | [diff] [blame] | 33 | #if defined(_WIN32_WCE) |
| 34 | # if _WIN32_WCE < 211 |
| 35 | __error__ (f|w)printf functions are not supported on old WindowsCE.; |
| 36 | # endif |
| 37 | # include <windows.h> |
| 38 | # include <stdlib.h> |
| 39 | # define READFILE(file, data, length, check) \ |
Glenn Randers-Pehrson | 15dac0b | 2000-07-10 07:48:54 -0500 | [diff] [blame] | 40 | if (ReadFile(file, data, length, &check,NULL)) check = 0 |
| 41 | # define WRITEFILE(file, data, length, check)) \ |
| 42 | if (WriteFile(file, data, length, &check, NULL)) check = 0 |
Glenn Randers-Pehrson | 316f97a | 2000-07-08 13:19:41 -0500 | [diff] [blame] | 43 | # define FCLOSE(file) CloseHandle(file) |
| 44 | #else |
| 45 | # include <stdio.h> |
| 46 | # include <stdlib.h> |
| 47 | # include <assert.h> |
| 48 | # define READFILE(file, data, length, check) \ |
| 49 | check=(png_size_t)fread(data,(png_size_t)1,length,file) |
| 50 | # define WRITEFILE(file, data, length, check) \ |
Glenn Randers-Pehrson | 15dac0b | 2000-07-10 07:48:54 -0500 | [diff] [blame] | 51 | check=(png_size_t)fwrite(data,(png_size_t)1, length, file) |
Glenn Randers-Pehrson | 316f97a | 2000-07-08 13:19:41 -0500 | [diff] [blame] | 52 | # define FCLOSE(file) fclose(file) |
| 53 | #endif |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 54 | |
Glenn Randers-Pehrson | be9de0f | 2001-01-22 08:52:16 -0600 | [diff] [blame] | 55 | #if defined(PNG_NO_STDIO) |
Glenn Randers-Pehrson | 3097f61 | 2001-05-07 14:52:45 -0500 | [diff] [blame] | 56 | # if defined(_WIN32_WCE) |
| 57 | typedef HANDLE png_FILE_p; |
| 58 | # else |
| 59 | typedef FILE * png_FILE_p; |
| 60 | # endif |
Glenn Randers-Pehrson | be9de0f | 2001-01-22 08:52:16 -0600 | [diff] [blame] | 61 | #endif |
| 62 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 63 | /* Makes pngtest verbose so we can find problems (needs to be before png.h) */ |
| 64 | #ifndef PNG_DEBUG |
Glenn Randers-Pehrson | 3097f61 | 2001-05-07 14:52:45 -0500 | [diff] [blame] | 65 | # define PNG_DEBUG 0 |
| 66 | #endif |
| 67 | |
| 68 | #if !PNG_DEBUG |
Glenn Randers-Pehrson | d1e8c86 | 2002-06-20 06:54:34 -0500 | [diff] [blame] | 69 | # define SINGLE_ROWBUF_ALLOC /* makes buffer overruns easier to nail */ |
Glenn Randers-Pehrson | ea3bcd7 | 1998-03-07 14:33:00 -0600 | [diff] [blame] | 70 | #endif |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 71 | |
Glenn Randers-Pehrson | bcfd15d | 1999-10-01 14:22:25 -0500 | [diff] [blame] | 72 | /* Turn on CPU timing |
| 73 | #define PNGTEST_TIMING |
| 74 | */ |
| 75 | |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 76 | #ifdef PNG_NO_FLOATING_POINT_SUPPORTED |
| 77 | #undef PNGTEST_TIMING |
| 78 | #endif |
| 79 | |
Glenn Randers-Pehrson | bcfd15d | 1999-10-01 14:22:25 -0500 | [diff] [blame] | 80 | #ifdef PNGTEST_TIMING |
| 81 | static float t_start, t_stop, t_decode, t_encode, t_misc; |
| 82 | #include <time.h> |
| 83 | #endif |
| 84 | |
Glenn Randers-Pehrson | 520a764 | 2000-03-21 05:13:06 -0600 | [diff] [blame] | 85 | /* Define png_jmpbuf() in case we are using a pre-1.0.6 version of libpng */ |
| 86 | #ifndef png_jmpbuf |
| 87 | # define png_jmpbuf(png_ptr) png_ptr->jmpbuf |
| 88 | #endif |
| 89 | |
Glenn Randers-Pehrson | bcfd15d | 1999-10-01 14:22:25 -0500 | [diff] [blame] | 90 | #ifdef PNGTEST_TIMING |
| 91 | static float t_start, t_stop, t_decode, t_encode, t_misc; |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 92 | #if !defined(PNG_tIME_SUPPORTED) |
Glenn Randers-Pehrson | bcfd15d | 1999-10-01 14:22:25 -0500 | [diff] [blame] | 93 | #include <time.h> |
| 94 | #endif |
| 95 | #endif |
| 96 | |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 97 | #if defined(PNG_TIME_RFC1123_SUPPORTED) |
| 98 | static int tIME_chunk_present=0; |
Glenn Randers-Pehrson | 345bc27 | 1998-06-14 14:43:31 -0500 | [diff] [blame] | 99 | static char tIME_string[30] = "no tIME chunk present in file"; |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 100 | #endif |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 101 | |
Glenn Randers-Pehrson | 4393a9a | 1999-09-17 12:27:26 -0500 | [diff] [blame] | 102 | static int verbose = 0; |
| 103 | |
Glenn Randers-Pehrson | ea3bcd7 | 1998-03-07 14:33:00 -0600 | [diff] [blame] | 104 | int test_one_file PNGARG((PNG_CONST char *inname, PNG_CONST char *outname)); |
Glenn Randers-Pehrson | c4a2ae6 | 1998-01-16 22:06:18 -0600 | [diff] [blame] | 105 | |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 106 | #ifdef __TURBOC__ |
| 107 | #include <mem.h> |
| 108 | #endif |
| 109 | |
| 110 | /* defined so I can write to a file on gui/windowing platforms */ |
Guy Schalnat | 6d76471 | 1995-12-19 03:22:19 -0600 | [diff] [blame] | 111 | /* #define STDERR stderr */ |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 112 | #define STDERR stdout /* for DOS */ |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 113 | |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 114 | /* example of using row callbacks to make a simple progress meter */ |
| 115 | static int status_pass=1; |
| 116 | static int status_dots_requested=0; |
| 117 | static int status_dots=1; |
Glenn Randers-Pehrson | ea3bcd7 | 1998-03-07 14:33:00 -0600 | [diff] [blame] | 118 | |
Glenn Randers-Pehrson | 7cd899c | 1998-03-07 16:17:42 -0600 | [diff] [blame] | 119 | void |
Glenn Randers-Pehrson | 2ae022d | 2002-07-01 22:23:46 -0500 | [diff] [blame] | 120 | #ifdef PNG_1_0_X |
| 121 | PNGAPI |
| 122 | #endif |
Glenn Randers-Pehrson | 4766a24 | 2000-07-17 06:17:09 -0500 | [diff] [blame] | 123 | read_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass); |
Glenn Randers-Pehrson | 0cc2f95 | 2002-10-03 06:32:37 -0500 | [diff] [blame] | 124 | void |
Glenn Randers-Pehrson | 2ae022d | 2002-07-01 22:23:46 -0500 | [diff] [blame] | 125 | #ifdef PNG_1_0_X |
| 126 | PNGAPI |
| 127 | #endif |
Glenn Randers-Pehrson | 7cd899c | 1998-03-07 16:17:42 -0600 | [diff] [blame] | 128 | read_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass) |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 129 | { |
Glenn Randers-Pehrson | 5fea36f | 2004-07-28 08:20:44 -0500 | [diff] [blame^] | 130 | if(png_ptr == NULL || row_number > PNG_UINT_31_MAX) return; |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 131 | if(status_pass != pass) |
| 132 | { |
| 133 | fprintf(stdout,"\n Pass %d: ",pass); |
| 134 | status_pass = pass; |
Glenn Randers-Pehrson | 4393a9a | 1999-09-17 12:27:26 -0500 | [diff] [blame] | 135 | status_dots = 31; |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 136 | } |
| 137 | status_dots--; |
| 138 | if(status_dots == 0) |
| 139 | { |
| 140 | fprintf(stdout, "\n "); |
| 141 | status_dots=30; |
| 142 | } |
| 143 | fprintf(stdout, "r"); |
| 144 | } |
Glenn Randers-Pehrson | ea3bcd7 | 1998-03-07 14:33:00 -0600 | [diff] [blame] | 145 | |
Glenn Randers-Pehrson | 0cc2f95 | 2002-10-03 06:32:37 -0500 | [diff] [blame] | 146 | void |
Glenn Randers-Pehrson | 2ae022d | 2002-07-01 22:23:46 -0500 | [diff] [blame] | 147 | #ifdef PNG_1_0_X |
| 148 | PNGAPI |
| 149 | #endif |
Glenn Randers-Pehrson | 4766a24 | 2000-07-17 06:17:09 -0500 | [diff] [blame] | 150 | write_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass); |
Glenn Randers-Pehrson | 0cc2f95 | 2002-10-03 06:32:37 -0500 | [diff] [blame] | 151 | void |
Glenn Randers-Pehrson | 2ae022d | 2002-07-01 22:23:46 -0500 | [diff] [blame] | 152 | #ifdef PNG_1_0_X |
| 153 | PNGAPI |
| 154 | #endif |
Glenn Randers-Pehrson | 7cd899c | 1998-03-07 16:17:42 -0600 | [diff] [blame] | 155 | write_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass) |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 156 | { |
Glenn Randers-Pehrson | 5fea36f | 2004-07-28 08:20:44 -0500 | [diff] [blame^] | 157 | if(png_ptr == NULL || row_number > PNG_UINT_31_MAX || pass > 7) return; |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 158 | fprintf(stdout, "w"); |
| 159 | } |
| 160 | |
| 161 | |
Glenn Randers-Pehrson | 4393a9a | 1999-09-17 12:27:26 -0500 | [diff] [blame] | 162 | #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) |
| 163 | /* Example of using user transform callback (we don't transform anything, |
| 164 | but merely examine the row filters. We set this to 256 rather than |
| 165 | 5 in case illegal filter values are present.) */ |
| 166 | static png_uint_32 filters_used[256]; |
| 167 | void |
Glenn Randers-Pehrson | 2ae022d | 2002-07-01 22:23:46 -0500 | [diff] [blame] | 168 | #ifdef PNG_1_0_X |
| 169 | PNGAPI |
| 170 | #endif |
Glenn Randers-Pehrson | 4766a24 | 2000-07-17 06:17:09 -0500 | [diff] [blame] | 171 | count_filters(png_structp png_ptr, png_row_infop row_info, png_bytep data); |
| 172 | void |
Glenn Randers-Pehrson | 2ae022d | 2002-07-01 22:23:46 -0500 | [diff] [blame] | 173 | #ifdef PNG_1_0_X |
| 174 | PNGAPI |
| 175 | #endif |
Glenn Randers-Pehrson | 4393a9a | 1999-09-17 12:27:26 -0500 | [diff] [blame] | 176 | count_filters(png_structp png_ptr, png_row_infop row_info, png_bytep data) |
| 177 | { |
| 178 | if(png_ptr != NULL && row_info != NULL) |
| 179 | ++filters_used[*(data-1)]; |
| 180 | } |
| 181 | #endif |
| 182 | |
Glenn Randers-Pehrson | 38d73af | 1998-03-07 21:30:44 -0600 | [diff] [blame] | 183 | #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 184 | /* example of using user transform callback (we don't transform anything, |
Glenn Randers-Pehrson | 896239b | 1998-04-21 15:03:57 -0500 | [diff] [blame] | 185 | but merely count the zero samples) */ |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 186 | |
Glenn Randers-Pehrson | 896239b | 1998-04-21 15:03:57 -0500 | [diff] [blame] | 187 | static png_uint_32 zero_samples; |
Glenn Randers-Pehrson | ea3bcd7 | 1998-03-07 14:33:00 -0600 | [diff] [blame] | 188 | |
Glenn Randers-Pehrson | 7cd899c | 1998-03-07 16:17:42 -0600 | [diff] [blame] | 189 | void |
Glenn Randers-Pehrson | 2ae022d | 2002-07-01 22:23:46 -0500 | [diff] [blame] | 190 | #ifdef PNG_1_0_X |
| 191 | PNGAPI |
| 192 | #endif |
Glenn Randers-Pehrson | 4766a24 | 2000-07-17 06:17:09 -0500 | [diff] [blame] | 193 | count_zero_samples(png_structp png_ptr, png_row_infop row_info, png_bytep data); |
| 194 | void |
Glenn Randers-Pehrson | 2ae022d | 2002-07-01 22:23:46 -0500 | [diff] [blame] | 195 | #ifdef PNG_1_0_X |
| 196 | PNGAPI |
| 197 | #endif |
Glenn Randers-Pehrson | 896239b | 1998-04-21 15:03:57 -0500 | [diff] [blame] | 198 | count_zero_samples(png_structp png_ptr, png_row_infop row_info, png_bytep data) |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 199 | { |
| 200 | png_bytep dp = data; |
Glenn Randers-Pehrson | 5c6aeb2 | 1998-12-29 11:47:59 -0600 | [diff] [blame] | 201 | if(png_ptr == NULL)return; |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 202 | |
| 203 | /* contents of row_info: |
| 204 | * png_uint_32 width width of row |
| 205 | * png_uint_32 rowbytes number of bytes in row |
| 206 | * png_byte color_type color type of pixels |
| 207 | * png_byte bit_depth bit depth of samples |
| 208 | * png_byte channels number of channels (1-4) |
| 209 | * png_byte pixel_depth bits per pixel (depth*channels) |
| 210 | */ |
| 211 | |
Glenn Randers-Pehrson | 4393a9a | 1999-09-17 12:27:26 -0500 | [diff] [blame] | 212 | |
Glenn Randers-Pehrson | 896239b | 1998-04-21 15:03:57 -0500 | [diff] [blame] | 213 | /* counts the number of zero samples (or zero pixels if color_type is 3 */ |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 214 | |
| 215 | if(row_info->color_type == 0 || row_info->color_type == 3) |
| 216 | { |
| 217 | int pos=0; |
Glenn Randers-Pehrson | 896239b | 1998-04-21 15:03:57 -0500 | [diff] [blame] | 218 | png_uint_32 n, nstop; |
| 219 | for (n=0, nstop=row_info->width; n<nstop; n++) |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 220 | { |
| 221 | if(row_info->bit_depth == 1) |
Glenn Randers-Pehrson | 896239b | 1998-04-21 15:03:57 -0500 | [diff] [blame] | 222 | { |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 223 | if(((*dp << pos++ ) & 0x80) == 0) zero_samples++; |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 224 | if(pos == 8) |
| 225 | { |
Glenn Randers-Pehrson | 896239b | 1998-04-21 15:03:57 -0500 | [diff] [blame] | 226 | pos = 0; |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 227 | dp++; |
| 228 | } |
Glenn Randers-Pehrson | 896239b | 1998-04-21 15:03:57 -0500 | [diff] [blame] | 229 | } |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 230 | if(row_info->bit_depth == 2) |
Glenn Randers-Pehrson | 896239b | 1998-04-21 15:03:57 -0500 | [diff] [blame] | 231 | { |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 232 | if(((*dp << (pos+=2)) & 0xc0) == 0) zero_samples++; |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 233 | if(pos == 8) |
| 234 | { |
Glenn Randers-Pehrson | 896239b | 1998-04-21 15:03:57 -0500 | [diff] [blame] | 235 | pos = 0; |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 236 | dp++; |
| 237 | } |
Glenn Randers-Pehrson | 896239b | 1998-04-21 15:03:57 -0500 | [diff] [blame] | 238 | } |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 239 | if(row_info->bit_depth == 4) |
Glenn Randers-Pehrson | 896239b | 1998-04-21 15:03:57 -0500 | [diff] [blame] | 240 | { |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 241 | if(((*dp << (pos+=4)) & 0xf0) == 0) zero_samples++; |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 242 | if(pos == 8) |
| 243 | { |
Glenn Randers-Pehrson | 896239b | 1998-04-21 15:03:57 -0500 | [diff] [blame] | 244 | pos = 0; |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 245 | dp++; |
| 246 | } |
Glenn Randers-Pehrson | 896239b | 1998-04-21 15:03:57 -0500 | [diff] [blame] | 247 | } |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 248 | if(row_info->bit_depth == 8) |
Glenn Randers-Pehrson | 896239b | 1998-04-21 15:03:57 -0500 | [diff] [blame] | 249 | if(*dp++ == 0) zero_samples++; |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 250 | if(row_info->bit_depth == 16) |
| 251 | { |
Glenn Randers-Pehrson | 896239b | 1998-04-21 15:03:57 -0500 | [diff] [blame] | 252 | if((*dp | *(dp+1)) == 0) zero_samples++; |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 253 | dp+=2; |
| 254 | } |
| 255 | } |
| 256 | } |
| 257 | else /* other color types */ |
| 258 | { |
Glenn Randers-Pehrson | 896239b | 1998-04-21 15:03:57 -0500 | [diff] [blame] | 259 | png_uint_32 n, nstop; |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 260 | int channel; |
| 261 | int color_channels = row_info->channels; |
| 262 | if(row_info->color_type > 3)color_channels--; |
| 263 | |
Glenn Randers-Pehrson | 896239b | 1998-04-21 15:03:57 -0500 | [diff] [blame] | 264 | for (n=0, nstop=row_info->width; n<nstop; n++) |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 265 | { |
| 266 | for (channel = 0; channel < color_channels; channel++) |
| 267 | { |
| 268 | if(row_info->bit_depth == 8) |
Glenn Randers-Pehrson | 896239b | 1998-04-21 15:03:57 -0500 | [diff] [blame] | 269 | if(*dp++ == 0) zero_samples++; |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 270 | if(row_info->bit_depth == 16) |
| 271 | { |
Glenn Randers-Pehrson | 896239b | 1998-04-21 15:03:57 -0500 | [diff] [blame] | 272 | if((*dp | *(dp+1)) == 0) zero_samples++; |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 273 | dp+=2; |
| 274 | } |
| 275 | } |
| 276 | if(row_info->color_type > 3) |
| 277 | { |
| 278 | dp++; |
| 279 | if(row_info->bit_depth == 16)dp++; |
| 280 | } |
| 281 | } |
| 282 | } |
| 283 | } |
Glenn Randers-Pehrson | 38d73af | 1998-03-07 21:30:44 -0600 | [diff] [blame] | 284 | #endif /* PNG_WRITE_USER_TRANSFORM_SUPPORTED */ |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 285 | |
Glenn Randers-Pehrson | cbe52d8 | 1998-02-28 07:00:24 -0600 | [diff] [blame] | 286 | static int wrote_question = 0; |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 287 | |
Glenn Randers-Pehrson | c4a2ae6 | 1998-01-16 22:06:18 -0600 | [diff] [blame] | 288 | #if defined(PNG_NO_STDIO) |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 289 | /* START of code to validate stdio-free compilation */ |
| 290 | /* These copies of the default read/write functions come from pngrio.c and */ |
| 291 | /* pngwio.c. They allow "don't include stdio" testing of the library. */ |
Glenn Randers-Pehrson | 8686fff | 1998-05-21 09:27:50 -0500 | [diff] [blame] | 292 | /* This is the function that does the actual reading of data. If you are |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 293 | not reading from a standard C stream, you should create a replacement |
| 294 | read_data function and use it at run time with png_set_read_fn(), rather |
| 295 | than changing the library. */ |
Glenn Randers-Pehrson | be9de0f | 2001-01-22 08:52:16 -0600 | [diff] [blame] | 296 | |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 297 | #ifndef USE_FAR_KEYWORD |
| 298 | static void |
Glenn Randers-Pehrson | 104622b | 2000-05-29 08:58:03 -0500 | [diff] [blame] | 299 | pngtest_read_data(png_structp png_ptr, png_bytep data, png_size_t length) |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 300 | { |
| 301 | png_size_t check; |
| 302 | |
| 303 | /* fread() returns 0 on error, so it is OK to store this in a png_size_t |
| 304 | * instead of an int, which is what fread() actually returns. |
| 305 | */ |
Glenn Randers-Pehrson | 316f97a | 2000-07-08 13:19:41 -0500 | [diff] [blame] | 306 | READFILE((png_FILE_p)png_ptr->io_ptr, data, length, check); |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 307 | |
| 308 | if (check != length) |
| 309 | { |
Glenn Randers-Pehrson | 3097f61 | 2001-05-07 14:52:45 -0500 | [diff] [blame] | 310 | png_error(png_ptr, "Read Error!"); |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 311 | } |
| 312 | } |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 313 | #else |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 314 | /* this is the model-independent version. Since the standard I/O library |
| 315 | can't handle far buffers in the medium and small models, we have to copy |
| 316 | the data. |
| 317 | */ |
Glenn Randers-Pehrson | 5c6aeb2 | 1998-12-29 11:47:59 -0600 | [diff] [blame] | 318 | |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 319 | #define NEAR_BUF_SIZE 1024 |
| 320 | #define MIN(a,b) (a <= b ? a : b) |
Glenn Randers-Pehrson | 5c6aeb2 | 1998-12-29 11:47:59 -0600 | [diff] [blame] | 321 | |
Glenn Randers-Pehrson | 7cd899c | 1998-03-07 16:17:42 -0600 | [diff] [blame] | 322 | static void |
Glenn Randers-Pehrson | 104622b | 2000-05-29 08:58:03 -0500 | [diff] [blame] | 323 | pngtest_read_data(png_structp png_ptr, png_bytep data, png_size_t length) |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 324 | { |
| 325 | int check; |
| 326 | png_byte *n_data; |
Glenn Randers-Pehrson | 316f97a | 2000-07-08 13:19:41 -0500 | [diff] [blame] | 327 | png_FILE_p io_ptr; |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 328 | |
| 329 | /* Check if data really is near. If so, use usual code. */ |
| 330 | n_data = (png_byte *)CVT_PTR_NOCHECK(data); |
Glenn Randers-Pehrson | 316f97a | 2000-07-08 13:19:41 -0500 | [diff] [blame] | 331 | io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr); |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 332 | if ((png_bytep)n_data == data) |
| 333 | { |
Glenn Randers-Pehrson | 316f97a | 2000-07-08 13:19:41 -0500 | [diff] [blame] | 334 | READFILE(io_ptr, n_data, length, check); |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 335 | } |
| 336 | else |
| 337 | { |
| 338 | png_byte buf[NEAR_BUF_SIZE]; |
| 339 | png_size_t read, remaining, err; |
| 340 | check = 0; |
| 341 | remaining = length; |
| 342 | do |
| 343 | { |
| 344 | read = MIN(NEAR_BUF_SIZE, remaining); |
Glenn Randers-Pehrson | 316f97a | 2000-07-08 13:19:41 -0500 | [diff] [blame] | 345 | READFILE(io_ptr, buf, 1, err); |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 346 | png_memcpy(data, buf, read); /* copy far buffer to near buffer */ |
| 347 | if(err != read) |
| 348 | break; |
| 349 | else |
| 350 | check += err; |
| 351 | data += read; |
| 352 | remaining -= read; |
| 353 | } |
| 354 | while (remaining != 0); |
| 355 | } |
| 356 | if (check != length) |
| 357 | { |
| 358 | png_error(png_ptr, "read Error"); |
| 359 | } |
| 360 | } |
Glenn Randers-Pehrson | c4a2ae6 | 1998-01-16 22:06:18 -0600 | [diff] [blame] | 361 | #endif /* USE_FAR_KEYWORD */ |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 362 | |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 363 | #if defined(PNG_WRITE_FLUSH_SUPPORTED) |
Glenn Randers-Pehrson | 7cd899c | 1998-03-07 16:17:42 -0600 | [diff] [blame] | 364 | static void |
Glenn Randers-Pehrson | 104622b | 2000-05-29 08:58:03 -0500 | [diff] [blame] | 365 | pngtest_flush(png_structp png_ptr) |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 366 | { |
Glenn Randers-Pehrson | 316f97a | 2000-07-08 13:19:41 -0500 | [diff] [blame] | 367 | #if !defined(_WIN32_WCE) |
| 368 | png_FILE_p io_ptr; |
| 369 | io_ptr = (png_FILE_p)CVT_PTR((png_ptr->io_ptr)); |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 370 | if (io_ptr != NULL) |
| 371 | fflush(io_ptr); |
Glenn Randers-Pehrson | 316f97a | 2000-07-08 13:19:41 -0500 | [diff] [blame] | 372 | #endif |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 373 | } |
| 374 | #endif |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 375 | |
Glenn Randers-Pehrson | 8686fff | 1998-05-21 09:27:50 -0500 | [diff] [blame] | 376 | /* This is the function that does the actual writing of data. If you are |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 377 | not writing to a standard C stream, you should create a replacement |
| 378 | write_data function and use it at run time with png_set_write_fn(), rather |
| 379 | than changing the library. */ |
| 380 | #ifndef USE_FAR_KEYWORD |
| 381 | static void |
Glenn Randers-Pehrson | 104622b | 2000-05-29 08:58:03 -0500 | [diff] [blame] | 382 | pngtest_write_data(png_structp png_ptr, png_bytep data, png_size_t length) |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 383 | { |
| 384 | png_uint_32 check; |
| 385 | |
Glenn Randers-Pehrson | 5e5c1e1 | 2000-11-10 12:26:19 -0600 | [diff] [blame] | 386 | WRITEFILE((png_FILE_p)png_ptr->io_ptr, data, length, check); |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 387 | if (check != length) |
| 388 | { |
| 389 | png_error(png_ptr, "Write Error"); |
| 390 | } |
| 391 | } |
| 392 | #else |
| 393 | /* this is the model-independent version. Since the standard I/O library |
| 394 | can't handle far buffers in the medium and small models, we have to copy |
| 395 | the data. |
| 396 | */ |
| 397 | |
| 398 | #define NEAR_BUF_SIZE 1024 |
| 399 | #define MIN(a,b) (a <= b ? a : b) |
| 400 | |
| 401 | static void |
Glenn Randers-Pehrson | 104622b | 2000-05-29 08:58:03 -0500 | [diff] [blame] | 402 | pngtest_write_data(png_structp png_ptr, png_bytep data, png_size_t length) |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 403 | { |
| 404 | png_uint_32 check; |
| 405 | png_byte *near_data; /* Needs to be "png_byte *" instead of "png_bytep" */ |
Glenn Randers-Pehrson | 316f97a | 2000-07-08 13:19:41 -0500 | [diff] [blame] | 406 | png_FILE_p io_ptr; |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 407 | |
| 408 | /* Check if data really is near. If so, use usual code. */ |
| 409 | near_data = (png_byte *)CVT_PTR_NOCHECK(data); |
Glenn Randers-Pehrson | 316f97a | 2000-07-08 13:19:41 -0500 | [diff] [blame] | 410 | io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr); |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 411 | if ((png_bytep)near_data == data) |
| 412 | { |
Glenn Randers-Pehrson | 5e5c1e1 | 2000-11-10 12:26:19 -0600 | [diff] [blame] | 413 | WRITEFILE(io_ptr, near_data, length, check); |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 414 | } |
| 415 | else |
| 416 | { |
| 417 | png_byte buf[NEAR_BUF_SIZE]; |
| 418 | png_size_t written, remaining, err; |
| 419 | check = 0; |
| 420 | remaining = length; |
| 421 | do |
| 422 | { |
| 423 | written = MIN(NEAR_BUF_SIZE, remaining); |
| 424 | png_memcpy(buf, data, written); /* copy far buffer to near buffer */ |
Glenn Randers-Pehrson | 5e5c1e1 | 2000-11-10 12:26:19 -0600 | [diff] [blame] | 425 | WRITEFILE(io_ptr, buf, written, err); |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 426 | if (err != written) |
| 427 | break; |
| 428 | else |
| 429 | check += err; |
| 430 | data += written; |
| 431 | remaining -= written; |
| 432 | } |
| 433 | while (remaining != 0); |
| 434 | } |
| 435 | if (check != length) |
| 436 | { |
| 437 | png_error(png_ptr, "Write Error"); |
| 438 | } |
| 439 | } |
| 440 | |
Glenn Randers-Pehrson | c4a2ae6 | 1998-01-16 22:06:18 -0600 | [diff] [blame] | 441 | #endif /* USE_FAR_KEYWORD */ |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 442 | |
| 443 | /* This function is called when there is a warning, but the library thinks |
| 444 | * it can continue anyway. Replacement functions don't have to do anything |
| 445 | * here if you don't want to. In the default configuration, png_ptr is |
| 446 | * not used, but it is passed in case it may be useful. |
| 447 | */ |
| 448 | static void |
Glenn Randers-Pehrson | 104622b | 2000-05-29 08:58:03 -0500 | [diff] [blame] | 449 | pngtest_warning(png_structp png_ptr, png_const_charp message) |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 450 | { |
| 451 | PNG_CONST char *name = "UNKNOWN (ERROR!)"; |
| 452 | if (png_ptr != NULL && png_ptr->error_ptr != NULL) |
| 453 | name = png_ptr->error_ptr; |
| 454 | fprintf(STDERR, "%s: libpng warning: %s\n", name, message); |
| 455 | } |
| 456 | |
| 457 | /* This is the default error handling function. Note that replacements for |
| 458 | * this function MUST NOT RETURN, or the program will likely crash. This |
| 459 | * function is used by default, or if the program supplies NULL for the |
| 460 | * error function pointer in png_set_error_fn(). |
| 461 | */ |
| 462 | static void |
Glenn Randers-Pehrson | 104622b | 2000-05-29 08:58:03 -0500 | [diff] [blame] | 463 | pngtest_error(png_structp png_ptr, png_const_charp message) |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 464 | { |
Glenn Randers-Pehrson | 104622b | 2000-05-29 08:58:03 -0500 | [diff] [blame] | 465 | pngtest_warning(png_ptr, message); |
Glenn Randers-Pehrson | 8686fff | 1998-05-21 09:27:50 -0500 | [diff] [blame] | 466 | /* We can return because png_error calls the default handler, which is |
| 467 | * actually OK in this case. */ |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 468 | } |
Glenn Randers-Pehrson | c4a2ae6 | 1998-01-16 22:06:18 -0600 | [diff] [blame] | 469 | #endif /* PNG_NO_STDIO */ |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 470 | /* END of code to validate stdio-free compilation */ |
| 471 | |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 472 | /* START of code to validate memory allocation and deallocation */ |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 473 | #ifdef PNG_USER_MEM_SUPPORTED |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 474 | |
| 475 | /* Allocate memory. For reasonable files, size should never exceed |
| 476 | 64K. However, zlib may allocate more then 64K if you don't tell |
| 477 | it not to. See zconf.h and png.h for more information. zlib does |
| 478 | need to allocate exactly 64K, so whatever you call here must |
| 479 | have the ability to do that. |
| 480 | |
| 481 | This piece of code can be compiled to validate max 64K allocations |
| 482 | by setting MAXSEG_64K in zlib zconf.h *or* PNG_MAX_MALLOC_64K. */ |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 483 | typedef struct memory_information |
| 484 | { |
Glenn Randers-Pehrson | 316f97a | 2000-07-08 13:19:41 -0500 | [diff] [blame] | 485 | png_uint_32 size; |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 486 | png_voidp pointer; |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 487 | struct memory_information FAR *next; |
| 488 | } memory_information; |
| 489 | typedef memory_information FAR *memory_infop; |
| 490 | |
| 491 | static memory_infop pinformation = NULL; |
| 492 | static int current_allocation = 0; |
| 493 | static int maximum_allocation = 0; |
Glenn Randers-Pehrson | 104622b | 2000-05-29 08:58:03 -0500 | [diff] [blame] | 494 | static int total_allocation = 0; |
| 495 | static int num_allocations = 0; |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 496 | |
Glenn Randers-Pehrson | b182893 | 2001-06-23 08:03:17 -0500 | [diff] [blame] | 497 | png_voidp png_debug_malloc PNGARG((png_structp png_ptr, png_uint_32 size)); |
| 498 | void png_debug_free PNGARG((png_structp png_ptr, png_voidp ptr)); |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 499 | |
| 500 | png_voidp |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 501 | png_debug_malloc(png_structp png_ptr, png_uint_32 size) |
| 502 | { |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 503 | |
| 504 | /* png_malloc has already tested for NULL; png_create_struct calls |
| 505 | png_debug_malloc directly, with png_ptr == NULL which is OK */ |
| 506 | |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 507 | if (size == 0) |
Glenn Randers-Pehrson | 3f54925 | 2001-10-27 07:35:13 -0500 | [diff] [blame] | 508 | return (NULL); |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 509 | |
| 510 | /* This calls the library allocator twice, once to get the requested |
| 511 | buffer and once to get a new free list entry. */ |
| 512 | { |
Glenn Randers-Pehrson | 3097f61 | 2001-05-07 14:52:45 -0500 | [diff] [blame] | 513 | memory_infop pinfo = (memory_infop)png_malloc_default(png_ptr, |
Glenn Randers-Pehrson | 5fea36f | 2004-07-28 08:20:44 -0500 | [diff] [blame^] | 514 | (png_uint_32)png_sizeof (*pinfo)); |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 515 | pinfo->size = size; |
| 516 | current_allocation += size; |
Glenn Randers-Pehrson | 104622b | 2000-05-29 08:58:03 -0500 | [diff] [blame] | 517 | total_allocation += size; |
| 518 | num_allocations ++; |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 519 | if (current_allocation > maximum_allocation) |
| 520 | maximum_allocation = current_allocation; |
Glenn Randers-Pehrson | 3097f61 | 2001-05-07 14:52:45 -0500 | [diff] [blame] | 521 | pinfo->pointer = (png_voidp)png_malloc_default(png_ptr, size); |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 522 | pinfo->next = pinformation; |
| 523 | pinformation = pinfo; |
| 524 | /* Make sure the caller isn't assuming zeroed memory. */ |
| 525 | png_memset(pinfo->pointer, 0xdd, pinfo->size); |
Glenn Randers-Pehrson | 6d8f3b0 | 1999-10-23 08:39:18 -0500 | [diff] [blame] | 526 | #if PNG_DEBUG |
| 527 | if(verbose) |
Glenn Randers-Pehrson | b182893 | 2001-06-23 08:03:17 -0500 | [diff] [blame] | 528 | printf("png_malloc %lu bytes at %x\n",size,pinfo->pointer); |
Glenn Randers-Pehrson | 6d8f3b0 | 1999-10-23 08:39:18 -0500 | [diff] [blame] | 529 | #endif |
Glenn Randers-Pehrson | 316f97a | 2000-07-08 13:19:41 -0500 | [diff] [blame] | 530 | assert(pinfo->size != 12345678); |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 531 | return (png_voidp)(pinfo->pointer); |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 532 | } |
| 533 | } |
| 534 | |
| 535 | /* Free a pointer. It is removed from the list at the same time. */ |
| 536 | void |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 537 | png_debug_free(png_structp png_ptr, png_voidp ptr) |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 538 | { |
| 539 | if (png_ptr == NULL) |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 540 | fprintf(STDERR, "NULL pointer to png_debug_free.\n"); |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 541 | if (ptr == 0) |
| 542 | { |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 543 | #if 0 /* This happens all the time. */ |
| 544 | fprintf(STDERR, "WARNING: freeing NULL pointer\n"); |
| 545 | #endif |
| 546 | return; |
| 547 | } |
| 548 | |
| 549 | /* Unlink the element from the list. */ |
| 550 | { |
| 551 | memory_infop FAR *ppinfo = &pinformation; |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 552 | for (;;) |
| 553 | { |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 554 | memory_infop pinfo = *ppinfo; |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 555 | if (pinfo->pointer == ptr) |
| 556 | { |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 557 | *ppinfo = pinfo->next; |
| 558 | current_allocation -= pinfo->size; |
| 559 | if (current_allocation < 0) |
| 560 | fprintf(STDERR, "Duplicate free of memory\n"); |
| 561 | /* We must free the list element too, but first kill |
Glenn Randers-Pehrson | 8686fff | 1998-05-21 09:27:50 -0500 | [diff] [blame] | 562 | the memory that is to be freed. */ |
Glenn Randers-Pehrson | 3097f61 | 2001-05-07 14:52:45 -0500 | [diff] [blame] | 563 | png_memset(ptr, 0x55, pinfo->size); |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 564 | png_free_default(png_ptr, pinfo); |
Glenn Randers-Pehrson | 4766a24 | 2000-07-17 06:17:09 -0500 | [diff] [blame] | 565 | pinfo=NULL; |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 566 | break; |
| 567 | } |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 568 | if (pinfo->next == NULL) |
| 569 | { |
Glenn Randers-Pehrson | b182893 | 2001-06-23 08:03:17 -0500 | [diff] [blame] | 570 | fprintf(STDERR, "Pointer %x not found\n", (unsigned int)ptr); |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 571 | break; |
| 572 | } |
| 573 | ppinfo = &pinfo->next; |
| 574 | } |
| 575 | } |
| 576 | |
| 577 | /* Finally free the data. */ |
Glenn Randers-Pehrson | 6d8f3b0 | 1999-10-23 08:39:18 -0500 | [diff] [blame] | 578 | #if PNG_DEBUG |
| 579 | if(verbose) |
| 580 | printf("Freeing %x\n",ptr); |
| 581 | #endif |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 582 | png_free_default(png_ptr, ptr); |
Glenn Randers-Pehrson | 4766a24 | 2000-07-17 06:17:09 -0500 | [diff] [blame] | 583 | ptr=NULL; |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 584 | } |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 585 | #endif /* PNG_USER_MEM_SUPPORTED */ |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 586 | /* END of code to test memory allocation/deallocation */ |
| 587 | |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 588 | /* Test one file */ |
Glenn Randers-Pehrson | 7cd899c | 1998-03-07 16:17:42 -0600 | [diff] [blame] | 589 | int |
| 590 | test_one_file(PNG_CONST char *inname, PNG_CONST char *outname) |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 591 | { |
Glenn Randers-Pehrson | 316f97a | 2000-07-08 13:19:41 -0500 | [diff] [blame] | 592 | static png_FILE_p fpin; |
| 593 | static png_FILE_p fpout; /* "static" prevents setjmp corruption */ |
Glenn Randers-Pehrson | 3097f61 | 2001-05-07 14:52:45 -0500 | [diff] [blame] | 594 | png_structp read_ptr; |
| 595 | png_infop read_info_ptr, end_info_ptr; |
| 596 | #ifdef PNG_WRITE_SUPPORTED |
| 597 | png_structp write_ptr; |
| 598 | png_infop write_info_ptr; |
| 599 | png_infop write_end_info_ptr; |
| 600 | #else |
| 601 | png_structp write_ptr = NULL; |
| 602 | png_infop write_info_ptr = NULL; |
| 603 | png_infop write_end_info_ptr = NULL; |
| 604 | #endif |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 605 | png_bytep row_buf; |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 606 | png_uint_32 y; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 607 | png_uint_32 width, height; |
| 608 | int num_pass, pass; |
| 609 | int bit_depth, color_type; |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 610 | #ifdef PNG_SETJMP_SUPPORTED |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 611 | #ifdef USE_FAR_KEYWORD |
Glenn Randers-Pehrson | 520a764 | 2000-03-21 05:13:06 -0600 | [diff] [blame] | 612 | jmp_buf jmpbuf; |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 613 | #endif |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 614 | #endif |
Glenn Randers-Pehrson | 5c6aeb2 | 1998-12-29 11:47:59 -0600 | [diff] [blame] | 615 | |
Glenn Randers-Pehrson | ff9c947 | 2000-07-11 07:12:36 -0500 | [diff] [blame] | 616 | #if defined(_WIN32_WCE) |
| 617 | TCHAR path[MAX_PATH]; |
| 618 | #endif |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 619 | char inbuf[256], outbuf[256]; |
| 620 | |
Glenn Randers-Pehrson | 3f54925 | 2001-10-27 07:35:13 -0500 | [diff] [blame] | 621 | row_buf = NULL; |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 622 | |
Glenn Randers-Pehrson | ff9c947 | 2000-07-11 07:12:36 -0500 | [diff] [blame] | 623 | #if defined(_WIN32_WCE) |
| 624 | MultiByteToWideChar(CP_ACP, 0, inname, -1, path, MAX_PATH); |
| 625 | if ((fpin = CreateFile(path, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL)) == INVALID_HANDLE_VALUE) |
| 626 | #else |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 627 | if ((fpin = fopen(inname, "rb")) == NULL) |
Glenn Randers-Pehrson | ff9c947 | 2000-07-11 07:12:36 -0500 | [diff] [blame] | 628 | #endif |
Guy Schalnat | 0f71645 | 1995-11-28 11:22:13 -0600 | [diff] [blame] | 629 | { |
| 630 | fprintf(STDERR, "Could not find input file %s\n", inname); |
Glenn Randers-Pehrson | b212002 | 1998-01-31 20:07:59 -0600 | [diff] [blame] | 631 | return (1); |
Guy Schalnat | 0f71645 | 1995-11-28 11:22:13 -0600 | [diff] [blame] | 632 | } |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 633 | |
Glenn Randers-Pehrson | ff9c947 | 2000-07-11 07:12:36 -0500 | [diff] [blame] | 634 | #if defined(_WIN32_WCE) |
| 635 | MultiByteToWideChar(CP_ACP, 0, outname, -1, path, MAX_PATH); |
| 636 | if ((fpout = CreateFile(path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL)) == INVALID_HANDLE_VALUE) |
| 637 | #else |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 638 | if ((fpout = fopen(outname, "wb")) == NULL) |
Glenn Randers-Pehrson | ff9c947 | 2000-07-11 07:12:36 -0500 | [diff] [blame] | 639 | #endif |
Guy Schalnat | 0f71645 | 1995-11-28 11:22:13 -0600 | [diff] [blame] | 640 | { |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 641 | fprintf(STDERR, "Could not open output file %s\n", outname); |
Glenn Randers-Pehrson | ff9c947 | 2000-07-11 07:12:36 -0500 | [diff] [blame] | 642 | FCLOSE(fpin); |
Glenn Randers-Pehrson | b212002 | 1998-01-31 20:07:59 -0600 | [diff] [blame] | 643 | return (1); |
Guy Schalnat | 0f71645 | 1995-11-28 11:22:13 -0600 | [diff] [blame] | 644 | } |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 645 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 646 | png_debug(0, "Allocating read and write structures\n"); |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 647 | #ifdef PNG_USER_MEM_SUPPORTED |
Glenn Randers-Pehrson | 3f54925 | 2001-10-27 07:35:13 -0500 | [diff] [blame] | 648 | read_ptr = png_create_read_struct_2(PNG_LIBPNG_VER_STRING, png_voidp_NULL, |
| 649 | png_error_ptr_NULL, png_error_ptr_NULL, png_voidp_NULL, |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 650 | (png_malloc_ptr)png_debug_malloc, (png_free_ptr)png_debug_free); |
| 651 | #else |
Glenn Randers-Pehrson | 3f54925 | 2001-10-27 07:35:13 -0500 | [diff] [blame] | 652 | read_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, png_voidp_NULL, |
| 653 | png_error_ptr_NULL, png_error_ptr_NULL); |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 654 | #endif |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 655 | #if defined(PNG_NO_STDIO) |
Glenn Randers-Pehrson | 104622b | 2000-05-29 08:58:03 -0500 | [diff] [blame] | 656 | png_set_error_fn(read_ptr, (png_voidp)inname, pngtest_error, |
| 657 | pngtest_warning); |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 658 | #endif |
Glenn Randers-Pehrson | 3097f61 | 2001-05-07 14:52:45 -0500 | [diff] [blame] | 659 | #ifdef PNG_WRITE_SUPPORTED |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 660 | #ifdef PNG_USER_MEM_SUPPORTED |
Glenn Randers-Pehrson | 3f54925 | 2001-10-27 07:35:13 -0500 | [diff] [blame] | 661 | write_ptr = png_create_write_struct_2(PNG_LIBPNG_VER_STRING, png_voidp_NULL, |
| 662 | png_error_ptr_NULL, png_error_ptr_NULL, png_voidp_NULL, |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 663 | (png_malloc_ptr)png_debug_malloc, (png_free_ptr)png_debug_free); |
| 664 | #else |
Glenn Randers-Pehrson | 3f54925 | 2001-10-27 07:35:13 -0500 | [diff] [blame] | 665 | write_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, png_voidp_NULL, |
| 666 | png_error_ptr_NULL, png_error_ptr_NULL); |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 667 | #endif |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 668 | #if defined(PNG_NO_STDIO) |
Glenn Randers-Pehrson | 104622b | 2000-05-29 08:58:03 -0500 | [diff] [blame] | 669 | png_set_error_fn(write_ptr, (png_voidp)inname, pngtest_error, |
| 670 | pngtest_warning); |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 671 | #endif |
Glenn Randers-Pehrson | 3097f61 | 2001-05-07 14:52:45 -0500 | [diff] [blame] | 672 | #endif |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 673 | png_debug(0, "Allocating read_info, write_info and end_info structures\n"); |
| 674 | read_info_ptr = png_create_info_struct(read_ptr); |
Glenn Randers-Pehrson | 1fd5fb3 | 2001-05-06 05:34:26 -0500 | [diff] [blame] | 675 | end_info_ptr = png_create_info_struct(read_ptr); |
Glenn Randers-Pehrson | 3097f61 | 2001-05-07 14:52:45 -0500 | [diff] [blame] | 676 | #ifdef PNG_WRITE_SUPPORTED |
| 677 | write_info_ptr = png_create_info_struct(write_ptr); |
Glenn Randers-Pehrson | 6d8f3b0 | 1999-10-23 08:39:18 -0500 | [diff] [blame] | 678 | write_end_info_ptr = png_create_info_struct(write_ptr); |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 679 | #endif |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 680 | |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 681 | #ifdef PNG_SETJMP_SUPPORTED |
Glenn Randers-Pehrson | 520a764 | 2000-03-21 05:13:06 -0600 | [diff] [blame] | 682 | png_debug(0, "Setting jmpbuf for read struct\n"); |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 683 | #ifdef USE_FAR_KEYWORD |
Glenn Randers-Pehrson | 520a764 | 2000-03-21 05:13:06 -0600 | [diff] [blame] | 684 | if (setjmp(jmpbuf)) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 685 | #else |
Glenn Randers-Pehrson | 520a764 | 2000-03-21 05:13:06 -0600 | [diff] [blame] | 686 | if (setjmp(png_jmpbuf(read_ptr))) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 687 | #endif |
Guy Schalnat | 0f71645 | 1995-11-28 11:22:13 -0600 | [diff] [blame] | 688 | { |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 689 | fprintf(STDERR, "%s -> %s: libpng read error\n", inname, outname); |
Glenn Randers-Pehrson | d020e9d | 2002-06-28 09:34:00 -0500 | [diff] [blame] | 690 | if (row_buf) |
| 691 | png_free(read_ptr, row_buf); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 692 | png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr); |
Glenn Randers-Pehrson | 3097f61 | 2001-05-07 14:52:45 -0500 | [diff] [blame] | 693 | #ifdef PNG_WRITE_SUPPORTED |
Glenn Randers-Pehrson | 6d8f3b0 | 1999-10-23 08:39:18 -0500 | [diff] [blame] | 694 | png_destroy_info_struct(write_ptr, &write_end_info_ptr); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 695 | png_destroy_write_struct(&write_ptr, &write_info_ptr); |
Glenn Randers-Pehrson | 3097f61 | 2001-05-07 14:52:45 -0500 | [diff] [blame] | 696 | #endif |
Glenn Randers-Pehrson | ff9c947 | 2000-07-11 07:12:36 -0500 | [diff] [blame] | 697 | FCLOSE(fpin); |
| 698 | FCLOSE(fpout); |
Glenn Randers-Pehrson | b212002 | 1998-01-31 20:07:59 -0600 | [diff] [blame] | 699 | return (1); |
Guy Schalnat | 0f71645 | 1995-11-28 11:22:13 -0600 | [diff] [blame] | 700 | } |
Glenn Randers-Pehrson | 5c6aeb2 | 1998-12-29 11:47:59 -0600 | [diff] [blame] | 701 | #ifdef USE_FAR_KEYWORD |
Glenn Randers-Pehrson | 5fea36f | 2004-07-28 08:20:44 -0500 | [diff] [blame^] | 702 | png_memcpy(png_jmpbuf(read_ptr),jmpbuf,png_sizeof(jmp_buf)); |
Glenn Randers-Pehrson | 5c6aeb2 | 1998-12-29 11:47:59 -0600 | [diff] [blame] | 703 | #endif |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 704 | |
Glenn Randers-Pehrson | 3097f61 | 2001-05-07 14:52:45 -0500 | [diff] [blame] | 705 | #ifdef PNG_WRITE_SUPPORTED |
Glenn Randers-Pehrson | 520a764 | 2000-03-21 05:13:06 -0600 | [diff] [blame] | 706 | png_debug(0, "Setting jmpbuf for write struct\n"); |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 707 | #ifdef USE_FAR_KEYWORD |
Glenn Randers-Pehrson | 520a764 | 2000-03-21 05:13:06 -0600 | [diff] [blame] | 708 | if (setjmp(jmpbuf)) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 709 | #else |
Glenn Randers-Pehrson | 520a764 | 2000-03-21 05:13:06 -0600 | [diff] [blame] | 710 | if (setjmp(png_jmpbuf(write_ptr))) |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 711 | #endif |
Guy Schalnat | b2e01bd | 1996-01-26 01:38:47 -0600 | [diff] [blame] | 712 | { |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 713 | fprintf(STDERR, "%s -> %s: libpng write error\n", inname, outname); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 714 | png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr); |
Glenn Randers-Pehrson | 6d8f3b0 | 1999-10-23 08:39:18 -0500 | [diff] [blame] | 715 | png_destroy_info_struct(write_ptr, &write_end_info_ptr); |
Glenn Randers-Pehrson | 3097f61 | 2001-05-07 14:52:45 -0500 | [diff] [blame] | 716 | #ifdef PNG_WRITE_SUPPORTED |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 717 | png_destroy_write_struct(&write_ptr, &write_info_ptr); |
Glenn Randers-Pehrson | 3097f61 | 2001-05-07 14:52:45 -0500 | [diff] [blame] | 718 | #endif |
Glenn Randers-Pehrson | ff9c947 | 2000-07-11 07:12:36 -0500 | [diff] [blame] | 719 | FCLOSE(fpin); |
| 720 | FCLOSE(fpout); |
Glenn Randers-Pehrson | b212002 | 1998-01-31 20:07:59 -0600 | [diff] [blame] | 721 | return (1); |
Guy Schalnat | 0f71645 | 1995-11-28 11:22:13 -0600 | [diff] [blame] | 722 | } |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 723 | #ifdef USE_FAR_KEYWORD |
Glenn Randers-Pehrson | 5fea36f | 2004-07-28 08:20:44 -0500 | [diff] [blame^] | 724 | png_memcpy(png_jmpbuf(write_ptr),jmpbuf,png_sizeof(jmp_buf)); |
Andreas Dilger | 02ad0ef | 1997-01-17 01:34:35 -0600 | [diff] [blame] | 725 | #endif |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 726 | #endif |
Glenn Randers-Pehrson | 3097f61 | 2001-05-07 14:52:45 -0500 | [diff] [blame] | 727 | #endif |
Glenn Randers-Pehrson | 5c6aeb2 | 1998-12-29 11:47:59 -0600 | [diff] [blame] | 728 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 729 | png_debug(0, "Initializing input and output streams\n"); |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 730 | #if !defined(PNG_NO_STDIO) |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 731 | png_init_io(read_ptr, fpin); |
Glenn Randers-Pehrson | 3097f61 | 2001-05-07 14:52:45 -0500 | [diff] [blame] | 732 | # ifdef PNG_WRITE_SUPPORTED |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 733 | png_init_io(write_ptr, fpout); |
Glenn Randers-Pehrson | 3097f61 | 2001-05-07 14:52:45 -0500 | [diff] [blame] | 734 | # endif |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 735 | #else |
Glenn Randers-Pehrson | 104622b | 2000-05-29 08:58:03 -0500 | [diff] [blame] | 736 | png_set_read_fn(read_ptr, (png_voidp)fpin, pngtest_read_data); |
Glenn Randers-Pehrson | 8b6a889 | 2001-05-18 04:54:50 -0500 | [diff] [blame] | 737 | # ifdef PNG_WRITE_SUPPORTED |
Glenn Randers-Pehrson | 104622b | 2000-05-29 08:58:03 -0500 | [diff] [blame] | 738 | png_set_write_fn(write_ptr, (png_voidp)fpout, pngtest_write_data, |
Glenn Randers-Pehrson | 8b6a889 | 2001-05-18 04:54:50 -0500 | [diff] [blame] | 739 | # if defined(PNG_WRITE_FLUSH_SUPPORTED) |
Glenn Randers-Pehrson | 104622b | 2000-05-29 08:58:03 -0500 | [diff] [blame] | 740 | pngtest_flush); |
Glenn Randers-Pehrson | 8b6a889 | 2001-05-18 04:54:50 -0500 | [diff] [blame] | 741 | # else |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 742 | NULL); |
Glenn Randers-Pehrson | 8b6a889 | 2001-05-18 04:54:50 -0500 | [diff] [blame] | 743 | # endif |
| 744 | # endif |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 745 | #endif |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 746 | if(status_dots_requested == 1) |
| 747 | { |
Glenn Randers-Pehrson | 3097f61 | 2001-05-07 14:52:45 -0500 | [diff] [blame] | 748 | #ifdef PNG_WRITE_SUPPORTED |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 749 | png_set_write_status_fn(write_ptr, write_row_callback); |
Glenn Randers-Pehrson | 3097f61 | 2001-05-07 14:52:45 -0500 | [diff] [blame] | 750 | #endif |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 751 | png_set_read_status_fn(read_ptr, read_row_callback); |
| 752 | } |
| 753 | else |
| 754 | { |
Glenn Randers-Pehrson | 3097f61 | 2001-05-07 14:52:45 -0500 | [diff] [blame] | 755 | #ifdef PNG_WRITE_SUPPORTED |
Glenn Randers-Pehrson | 3f54925 | 2001-10-27 07:35:13 -0500 | [diff] [blame] | 756 | png_set_write_status_fn(write_ptr, png_write_status_ptr_NULL); |
Glenn Randers-Pehrson | 3097f61 | 2001-05-07 14:52:45 -0500 | [diff] [blame] | 757 | #endif |
Glenn Randers-Pehrson | 3f54925 | 2001-10-27 07:35:13 -0500 | [diff] [blame] | 758 | png_set_read_status_fn(read_ptr, png_read_status_ptr_NULL); |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 759 | } |
| 760 | |
Glenn Randers-Pehrson | 4393a9a | 1999-09-17 12:27:26 -0500 | [diff] [blame] | 761 | #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) |
| 762 | { |
| 763 | int i; |
| 764 | for(i=0; i<256; i++) |
| 765 | filters_used[i]=0; |
| 766 | png_set_read_user_transform_fn(read_ptr, count_filters); |
| 767 | } |
| 768 | #endif |
| 769 | #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) |
| 770 | zero_samples=0; |
| 771 | png_set_write_user_transform_fn(write_ptr, count_zero_samples); |
| 772 | #endif |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 773 | |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 774 | #define HANDLE_CHUNK_IF_SAFE 2 |
| 775 | #define HANDLE_CHUNK_ALWAYS 3 |
| 776 | #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) |
Glenn Randers-Pehrson | 6c97ddb | 2001-10-24 22:01:19 -0500 | [diff] [blame] | 777 | png_set_keep_unknown_chunks(read_ptr, HANDLE_CHUNK_ALWAYS, |
Glenn Randers-Pehrson | 3f54925 | 2001-10-27 07:35:13 -0500 | [diff] [blame] | 778 | png_bytep_NULL, 0); |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 779 | #endif |
| 780 | #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED) |
Glenn Randers-Pehrson | 6c97ddb | 2001-10-24 22:01:19 -0500 | [diff] [blame] | 781 | png_set_keep_unknown_chunks(write_ptr, HANDLE_CHUNK_IF_SAFE, |
Glenn Randers-Pehrson | 3f54925 | 2001-10-27 07:35:13 -0500 | [diff] [blame] | 782 | png_bytep_NULL, 0); |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 783 | #endif |
| 784 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 785 | png_debug(0, "Reading info struct\n"); |
| 786 | png_read_info(read_ptr, read_info_ptr); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 787 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 788 | png_debug(0, "Transferring info struct\n"); |
| 789 | { |
| 790 | int interlace_type, compression_type, filter_type; |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 791 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 792 | if (png_get_IHDR(read_ptr, read_info_ptr, &width, &height, &bit_depth, |
| 793 | &color_type, &interlace_type, &compression_type, &filter_type)) |
| 794 | { |
| 795 | png_set_IHDR(write_ptr, write_info_ptr, width, height, bit_depth, |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 796 | #if defined(PNG_WRITE_INTERLACING_SUPPORTED) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 797 | color_type, interlace_type, compression_type, filter_type); |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 798 | #else |
| 799 | color_type, PNG_INTERLACE_NONE, compression_type, filter_type); |
| 800 | #endif |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 801 | } |
| 802 | } |
Glenn Randers-Pehrson | 6942d53 | 2000-05-01 09:31:54 -0500 | [diff] [blame] | 803 | #if defined(PNG_FIXED_POINT_SUPPORTED) |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 804 | #if defined(PNG_cHRM_SUPPORTED) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 805 | { |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 806 | png_fixed_point white_x, white_y, red_x, red_y, green_x, green_y, blue_x, |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 807 | blue_y; |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 808 | if (png_get_cHRM_fixed(read_ptr, read_info_ptr, &white_x, &white_y, &red_x, |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 809 | &red_y, &green_x, &green_y, &blue_x, &blue_y)) |
| 810 | { |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 811 | png_set_cHRM_fixed(write_ptr, write_info_ptr, white_x, white_y, red_x, |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 812 | red_y, green_x, green_y, blue_x, blue_y); |
| 813 | } |
| 814 | } |
| 815 | #endif |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 816 | #if defined(PNG_gAMA_SUPPORTED) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 817 | { |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 818 | png_fixed_point gamma; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 819 | |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 820 | if (png_get_gAMA_fixed(read_ptr, read_info_ptr, &gamma)) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 821 | { |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 822 | png_set_gAMA_fixed(write_ptr, write_info_ptr, gamma); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 823 | } |
| 824 | } |
| 825 | #endif |
Glenn Randers-Pehrson | 6942d53 | 2000-05-01 09:31:54 -0500 | [diff] [blame] | 826 | #else /* Use floating point versions */ |
| 827 | #if defined(PNG_FLOATING_POINT_SUPPORTED) |
| 828 | #if defined(PNG_cHRM_SUPPORTED) |
| 829 | { |
| 830 | double white_x, white_y, red_x, red_y, green_x, green_y, blue_x, |
| 831 | blue_y; |
| 832 | if (png_get_cHRM(read_ptr, read_info_ptr, &white_x, &white_y, &red_x, |
| 833 | &red_y, &green_x, &green_y, &blue_x, &blue_y)) |
| 834 | { |
| 835 | png_set_cHRM(write_ptr, write_info_ptr, white_x, white_y, red_x, |
| 836 | red_y, green_x, green_y, blue_x, blue_y); |
| 837 | } |
| 838 | } |
| 839 | #endif |
| 840 | #if defined(PNG_gAMA_SUPPORTED) |
| 841 | { |
| 842 | double gamma; |
| 843 | |
| 844 | if (png_get_gAMA(read_ptr, read_info_ptr, &gamma)) |
| 845 | { |
| 846 | png_set_gAMA(write_ptr, write_info_ptr, gamma); |
| 847 | } |
| 848 | } |
| 849 | #endif |
| 850 | #endif /* floating point */ |
| 851 | #endif /* fixed point */ |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 852 | #if defined(PNG_iCCP_SUPPORTED) |
| 853 | { |
| 854 | png_charp name; |
| 855 | png_charp profile; |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 856 | png_uint_32 proflen; |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 857 | int compression_type; |
| 858 | |
| 859 | if (png_get_iCCP(read_ptr, read_info_ptr, &name, &compression_type, |
| 860 | &profile, &proflen)) |
| 861 | { |
| 862 | png_set_iCCP(write_ptr, write_info_ptr, name, compression_type, |
| 863 | profile, proflen); |
| 864 | } |
| 865 | } |
| 866 | #endif |
| 867 | #if defined(PNG_sRGB_SUPPORTED) |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 868 | { |
Glenn Randers-Pehrson | c4a2ae6 | 1998-01-16 22:06:18 -0600 | [diff] [blame] | 869 | int intent; |
Glenn Randers-Pehrson | b6ce43d | 1998-01-01 07:13:13 -0600 | [diff] [blame] | 870 | |
| 871 | if (png_get_sRGB(read_ptr, read_info_ptr, &intent)) |
| 872 | { |
| 873 | png_set_sRGB(write_ptr, write_info_ptr, intent); |
| 874 | } |
| 875 | } |
| 876 | #endif |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 877 | { |
| 878 | png_colorp palette; |
| 879 | int num_palette; |
| 880 | |
| 881 | if (png_get_PLTE(read_ptr, read_info_ptr, &palette, &num_palette)) |
| 882 | { |
| 883 | png_set_PLTE(write_ptr, write_info_ptr, palette, num_palette); |
| 884 | } |
| 885 | } |
| 886 | #if defined(PNG_bKGD_SUPPORTED) |
| 887 | { |
| 888 | png_color_16p background; |
| 889 | |
| 890 | if (png_get_bKGD(read_ptr, read_info_ptr, &background)) |
| 891 | { |
| 892 | png_set_bKGD(write_ptr, write_info_ptr, background); |
| 893 | } |
| 894 | } |
| 895 | #endif |
| 896 | #if defined(PNG_hIST_SUPPORTED) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 897 | { |
| 898 | png_uint_16p hist; |
| 899 | |
| 900 | if (png_get_hIST(read_ptr, read_info_ptr, &hist)) |
| 901 | { |
| 902 | png_set_hIST(write_ptr, write_info_ptr, hist); |
| 903 | } |
| 904 | } |
| 905 | #endif |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 906 | #if defined(PNG_oFFs_SUPPORTED) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 907 | { |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 908 | png_int_32 offset_x, offset_y; |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 909 | int unit_type; |
| 910 | |
| 911 | if (png_get_oFFs(read_ptr, read_info_ptr,&offset_x,&offset_y,&unit_type)) |
| 912 | { |
| 913 | png_set_oFFs(write_ptr, write_info_ptr, offset_x, offset_y, unit_type); |
| 914 | } |
| 915 | } |
| 916 | #endif |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 917 | #if defined(PNG_pCAL_SUPPORTED) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 918 | { |
| 919 | png_charp purpose, units; |
| 920 | png_charpp params; |
| 921 | png_int_32 X0, X1; |
| 922 | int type, nparams; |
| 923 | |
| 924 | if (png_get_pCAL(read_ptr, read_info_ptr, &purpose, &X0, &X1, &type, |
| 925 | &nparams, &units, ¶ms)) |
| 926 | { |
| 927 | png_set_pCAL(write_ptr, write_info_ptr, purpose, X0, X1, type, |
| 928 | nparams, units, params); |
| 929 | } |
| 930 | } |
| 931 | #endif |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 932 | #if defined(PNG_pHYs_SUPPORTED) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 933 | { |
| 934 | png_uint_32 res_x, res_y; |
| 935 | int unit_type; |
| 936 | |
| 937 | if (png_get_pHYs(read_ptr, read_info_ptr, &res_x, &res_y, &unit_type)) |
| 938 | { |
| 939 | png_set_pHYs(write_ptr, write_info_ptr, res_x, res_y, unit_type); |
| 940 | } |
| 941 | } |
| 942 | #endif |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 943 | #if defined(PNG_sBIT_SUPPORTED) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 944 | { |
| 945 | png_color_8p sig_bit; |
| 946 | |
| 947 | if (png_get_sBIT(read_ptr, read_info_ptr, &sig_bit)) |
| 948 | { |
| 949 | png_set_sBIT(write_ptr, write_info_ptr, sig_bit); |
| 950 | } |
| 951 | } |
| 952 | #endif |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 953 | #if defined(PNG_sCAL_SUPPORTED) |
| 954 | #ifdef PNG_FLOATING_POINT_SUPPORTED |
| 955 | { |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 956 | int unit; |
Glenn Randers-Pehrson | 4766a24 | 2000-07-17 06:17:09 -0500 | [diff] [blame] | 957 | double scal_width, scal_height; |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 958 | |
Glenn Randers-Pehrson | 4766a24 | 2000-07-17 06:17:09 -0500 | [diff] [blame] | 959 | if (png_get_sCAL(read_ptr, read_info_ptr, &unit, &scal_width, |
| 960 | &scal_height)) |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 961 | { |
Glenn Randers-Pehrson | 4766a24 | 2000-07-17 06:17:09 -0500 | [diff] [blame] | 962 | png_set_sCAL(write_ptr, write_info_ptr, unit, scal_width, scal_height); |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 963 | } |
| 964 | } |
| 965 | #else |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 966 | #ifdef PNG_FIXED_POINT_SUPPORTED |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 967 | { |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 968 | int unit; |
Glenn Randers-Pehrson | 4766a24 | 2000-07-17 06:17:09 -0500 | [diff] [blame] | 969 | png_charp scal_width, scal_height; |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 970 | |
Glenn Randers-Pehrson | 4766a24 | 2000-07-17 06:17:09 -0500 | [diff] [blame] | 971 | if (png_get_sCAL_s(read_ptr, read_info_ptr, &unit, &scal_width, |
| 972 | &scal_height)) |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 973 | { |
Glenn Randers-Pehrson | 4766a24 | 2000-07-17 06:17:09 -0500 | [diff] [blame] | 974 | png_set_sCAL_s(write_ptr, write_info_ptr, unit, scal_width, scal_height); |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 975 | } |
| 976 | } |
| 977 | #endif |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 978 | #endif |
| 979 | #endif |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 980 | #if defined(PNG_TEXT_SUPPORTED) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 981 | { |
| 982 | png_textp text_ptr; |
| 983 | int num_text; |
| 984 | |
| 985 | if (png_get_text(read_ptr, read_info_ptr, &text_ptr, &num_text) > 0) |
| 986 | { |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 987 | png_debug1(0, "Handling %d iTXt/tEXt/zTXt chunks\n", num_text); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 988 | png_set_text(write_ptr, write_info_ptr, text_ptr, num_text); |
| 989 | } |
| 990 | } |
| 991 | #endif |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 992 | #if defined(PNG_tIME_SUPPORTED) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 993 | { |
| 994 | png_timep mod_time; |
| 995 | |
| 996 | if (png_get_tIME(read_ptr, read_info_ptr, &mod_time)) |
| 997 | { |
| 998 | png_set_tIME(write_ptr, write_info_ptr, mod_time); |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 999 | #if defined(PNG_TIME_RFC1123_SUPPORTED) |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 1000 | /* we have to use png_strcpy instead of "=" because the string |
| 1001 | pointed to by png_convert_to_rfc1123() gets free'ed before |
| 1002 | we use it */ |
| 1003 | png_strcpy(tIME_string,png_convert_to_rfc1123(read_ptr, mod_time)); |
| 1004 | tIME_chunk_present++; |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 1005 | #endif /* PNG_TIME_RFC1123_SUPPORTED */ |
Glenn Randers-Pehrson | c944229 | 1999-01-06 21:50:16 -0600 | [diff] [blame] | 1006 | } |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1007 | } |
| 1008 | #endif |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 1009 | #if defined(PNG_tRNS_SUPPORTED) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1010 | { |
| 1011 | png_bytep trans; |
| 1012 | int num_trans; |
| 1013 | png_color_16p trans_values; |
| 1014 | |
| 1015 | if (png_get_tRNS(read_ptr, read_info_ptr, &trans, &num_trans, |
| 1016 | &trans_values)) |
| 1017 | { |
| 1018 | png_set_tRNS(write_ptr, write_info_ptr, trans, num_trans, |
| 1019 | trans_values); |
| 1020 | } |
| 1021 | } |
| 1022 | #endif |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1023 | #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED) |
| 1024 | { |
| 1025 | png_unknown_chunkp unknowns; |
| 1026 | int num_unknowns = (int)png_get_unknown_chunks(read_ptr, read_info_ptr, |
| 1027 | &unknowns); |
| 1028 | if (num_unknowns) |
| 1029 | { |
| 1030 | png_size_t i; |
| 1031 | png_set_unknown_chunks(write_ptr, write_info_ptr, unknowns, |
| 1032 | num_unknowns); |
| 1033 | /* copy the locations from the read_info_ptr. The automatically |
| 1034 | generated locations in write_info_ptr are wrong because we |
| 1035 | haven't written anything yet */ |
| 1036 | for (i = 0; i < (png_size_t)num_unknowns; i++) |
Glenn Randers-Pehrson | 228bd39 | 2000-04-23 23:14:02 -0500 | [diff] [blame] | 1037 | png_set_unknown_chunk_location(write_ptr, write_info_ptr, i, |
| 1038 | unknowns[i].location); |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1039 | } |
| 1040 | } |
| 1041 | #endif |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1042 | |
Glenn Randers-Pehrson | 3097f61 | 2001-05-07 14:52:45 -0500 | [diff] [blame] | 1043 | #ifdef PNG_WRITE_SUPPORTED |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1044 | png_debug(0, "\nWriting info struct\n"); |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 1045 | |
| 1046 | /* If we wanted, we could write info in two steps: |
| 1047 | png_write_info_before_PLTE(write_ptr, write_info_ptr); |
| 1048 | */ |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1049 | png_write_info(write_ptr, write_info_ptr); |
Glenn Randers-Pehrson | 3097f61 | 2001-05-07 14:52:45 -0500 | [diff] [blame] | 1050 | #endif |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1051 | |
Glenn Randers-Pehrson | 3097f61 | 2001-05-07 14:52:45 -0500 | [diff] [blame] | 1052 | #ifdef SINGLE_ROWBUF_ALLOC |
| 1053 | png_debug(0, "\nAllocating row buffer..."); |
Glenn Randers-Pehrson | 5c6aeb2 | 1998-12-29 11:47:59 -0600 | [diff] [blame] | 1054 | row_buf = (png_bytep)png_malloc(read_ptr, |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1055 | png_get_rowbytes(read_ptr, read_info_ptr)); |
Glenn Randers-Pehrson | 3097f61 | 2001-05-07 14:52:45 -0500 | [diff] [blame] | 1056 | png_debug1(0, "0x%08lx\n\n", (unsigned long)row_buf); |
| 1057 | #endif /* SINGLE_ROWBUF_ALLOC */ |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 1058 | png_debug(0, "Writing row data\n"); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 1059 | |
Glenn Randers-Pehrson | bcfd15d | 1999-10-01 14:22:25 -0500 | [diff] [blame] | 1060 | #if defined(PNG_READ_INTERLACING_SUPPORTED) || \ |
| 1061 | defined(PNG_WRITE_INTERLACING_SUPPORTED) |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1062 | num_pass = png_set_interlace_handling(read_ptr); |
Glenn Randers-Pehrson | 3097f61 | 2001-05-07 14:52:45 -0500 | [diff] [blame] | 1063 | # ifdef PNG_WRITE_SUPPORTED |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1064 | png_set_interlace_handling(write_ptr); |
Glenn Randers-Pehrson | 3097f61 | 2001-05-07 14:52:45 -0500 | [diff] [blame] | 1065 | # endif |
Glenn Randers-Pehrson | bcfd15d | 1999-10-01 14:22:25 -0500 | [diff] [blame] | 1066 | #else |
| 1067 | num_pass=1; |
| 1068 | #endif |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 1069 | |
Glenn Randers-Pehrson | bcfd15d | 1999-10-01 14:22:25 -0500 | [diff] [blame] | 1070 | #ifdef PNGTEST_TIMING |
| 1071 | t_stop = (float)clock(); |
| 1072 | t_misc += (t_stop - t_start); |
| 1073 | t_start = t_stop; |
| 1074 | #endif |
Guy Schalnat | 0f71645 | 1995-11-28 11:22:13 -0600 | [diff] [blame] | 1075 | for (pass = 0; pass < num_pass; pass++) |
| 1076 | { |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 1077 | png_debug1(0, "Writing row data for pass %d\n",pass); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1078 | for (y = 0; y < height; y++) |
Guy Schalnat | 0f71645 | 1995-11-28 11:22:13 -0600 | [diff] [blame] | 1079 | { |
Glenn Randers-Pehrson | 3097f61 | 2001-05-07 14:52:45 -0500 | [diff] [blame] | 1080 | #ifndef SINGLE_ROWBUF_ALLOC |
| 1081 | png_debug2(0, "\nAllocating row buffer (pass %d, y = %ld)...", pass,y); |
| 1082 | row_buf = (png_bytep)png_malloc(read_ptr, |
| 1083 | png_get_rowbytes(read_ptr, read_info_ptr)); |
| 1084 | png_debug2(0, "0x%08lx (%ld bytes)\n", (unsigned long)row_buf, |
| 1085 | png_get_rowbytes(read_ptr, read_info_ptr)); |
| 1086 | #endif /* !SINGLE_ROWBUF_ALLOC */ |
Glenn Randers-Pehrson | 3f54925 | 2001-10-27 07:35:13 -0500 | [diff] [blame] | 1087 | png_read_rows(read_ptr, (png_bytepp)&row_buf, png_bytepp_NULL, 1); |
Glenn Randers-Pehrson | 3097f61 | 2001-05-07 14:52:45 -0500 | [diff] [blame] | 1088 | |
| 1089 | #ifdef PNG_WRITE_SUPPORTED |
Glenn Randers-Pehrson | bcfd15d | 1999-10-01 14:22:25 -0500 | [diff] [blame] | 1090 | #ifdef PNGTEST_TIMING |
| 1091 | t_stop = (float)clock(); |
| 1092 | t_decode += (t_stop - t_start); |
| 1093 | t_start = t_stop; |
| 1094 | #endif |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1095 | png_write_rows(write_ptr, (png_bytepp)&row_buf, 1); |
Glenn Randers-Pehrson | bcfd15d | 1999-10-01 14:22:25 -0500 | [diff] [blame] | 1096 | #ifdef PNGTEST_TIMING |
| 1097 | t_stop = (float)clock(); |
| 1098 | t_encode += (t_stop - t_start); |
| 1099 | t_start = t_stop; |
| 1100 | #endif |
Glenn Randers-Pehrson | 3097f61 | 2001-05-07 14:52:45 -0500 | [diff] [blame] | 1101 | #endif /* PNG_WRITE_SUPPORTED */ |
| 1102 | |
| 1103 | #ifndef SINGLE_ROWBUF_ALLOC |
| 1104 | png_debug2(0, "Freeing row buffer (pass %d, y = %ld)\n\n", pass, y); |
| 1105 | png_free(read_ptr, row_buf); |
| 1106 | #endif /* !SINGLE_ROWBUF_ALLOC */ |
Guy Schalnat | 0f71645 | 1995-11-28 11:22:13 -0600 | [diff] [blame] | 1107 | } |
| 1108 | } |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 1109 | |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1110 | #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 1111 | png_free_data(read_ptr, read_info_ptr, PNG_FREE_UNKN, -1); |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1112 | #endif |
| 1113 | #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED) |
Glenn Randers-Pehrson | a77ef62 | 2000-02-18 13:48:52 -0600 | [diff] [blame] | 1114 | png_free_data(write_ptr, write_info_ptr, PNG_FREE_UNKN, -1); |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1115 | #endif |
| 1116 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1117 | png_debug(0, "Reading and writing end_info data\n"); |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1118 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1119 | png_read_end(read_ptr, end_info_ptr); |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 1120 | #if defined(PNG_TEXT_SUPPORTED) |
Glenn Randers-Pehrson | 6d8f3b0 | 1999-10-23 08:39:18 -0500 | [diff] [blame] | 1121 | { |
| 1122 | png_textp text_ptr; |
| 1123 | int num_text; |
| 1124 | |
| 1125 | if (png_get_text(read_ptr, end_info_ptr, &text_ptr, &num_text) > 0) |
| 1126 | { |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 1127 | png_debug1(0, "Handling %d iTXt/tEXt/zTXt chunks\n", num_text); |
Glenn Randers-Pehrson | 6d8f3b0 | 1999-10-23 08:39:18 -0500 | [diff] [blame] | 1128 | png_set_text(write_ptr, write_end_info_ptr, text_ptr, num_text); |
| 1129 | } |
| 1130 | } |
| 1131 | #endif |
Glenn Randers-Pehrson | 166c5a3 | 1999-12-10 09:43:02 -0600 | [diff] [blame] | 1132 | #if defined(PNG_tIME_SUPPORTED) |
Glenn Randers-Pehrson | 6d8f3b0 | 1999-10-23 08:39:18 -0500 | [diff] [blame] | 1133 | { |
| 1134 | png_timep mod_time; |
| 1135 | |
| 1136 | if (png_get_tIME(read_ptr, end_info_ptr, &mod_time)) |
| 1137 | { |
| 1138 | png_set_tIME(write_ptr, write_end_info_ptr, mod_time); |
| 1139 | #if defined(PNG_TIME_RFC1123_SUPPORTED) |
| 1140 | /* we have to use png_strcpy instead of "=" because the string |
| 1141 | pointed to by png_convert_to_rfc1123() gets free'ed before |
| 1142 | we use it */ |
| 1143 | png_strcpy(tIME_string,png_convert_to_rfc1123(read_ptr, mod_time)); |
| 1144 | tIME_chunk_present++; |
| 1145 | #endif /* PNG_TIME_RFC1123_SUPPORTED */ |
| 1146 | } |
| 1147 | } |
| 1148 | #endif |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1149 | #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED) |
| 1150 | { |
| 1151 | png_unknown_chunkp unknowns; |
| 1152 | int num_unknowns; |
| 1153 | num_unknowns = (int)png_get_unknown_chunks(read_ptr, end_info_ptr, |
| 1154 | &unknowns); |
| 1155 | if (num_unknowns) |
| 1156 | { |
| 1157 | png_size_t i; |
| 1158 | png_set_unknown_chunks(write_ptr, write_end_info_ptr, unknowns, |
| 1159 | num_unknowns); |
| 1160 | /* copy the locations from the read_info_ptr. The automatically |
| 1161 | generated locations in write_end_info_ptr are wrong because we |
| 1162 | haven't written the end_info yet */ |
| 1163 | for (i = 0; i < (png_size_t)num_unknowns; i++) |
Glenn Randers-Pehrson | 228bd39 | 2000-04-23 23:14:02 -0500 | [diff] [blame] | 1164 | png_set_unknown_chunk_location(write_ptr, write_end_info_ptr, i, |
| 1165 | unknowns[i].location); |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1166 | } |
| 1167 | } |
| 1168 | #endif |
Glenn Randers-Pehrson | 3097f61 | 2001-05-07 14:52:45 -0500 | [diff] [blame] | 1169 | #ifdef PNG_WRITE_SUPPORTED |
Glenn Randers-Pehrson | 6d8f3b0 | 1999-10-23 08:39:18 -0500 | [diff] [blame] | 1170 | png_write_end(write_ptr, write_end_info_ptr); |
Glenn Randers-Pehrson | 3097f61 | 2001-05-07 14:52:45 -0500 | [diff] [blame] | 1171 | #endif |
Glenn Randers-Pehrson | 5c6aeb2 | 1998-12-29 11:47:59 -0600 | [diff] [blame] | 1172 | |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 1173 | #ifdef PNG_EASY_ACCESS_SUPPORTED |
| 1174 | if(verbose) |
| 1175 | { |
| 1176 | png_uint_32 iwidth, iheight; |
| 1177 | iwidth = png_get_image_width(write_ptr, write_info_ptr); |
| 1178 | iheight = png_get_image_height(write_ptr, write_info_ptr); |
| 1179 | fprintf(STDERR, "Image width = %lu, height = %lu\n", |
| 1180 | iwidth, iheight); |
| 1181 | } |
| 1182 | #endif |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 1183 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1184 | png_debug(0, "Destroying data structs\n"); |
Glenn Randers-Pehrson | 3097f61 | 2001-05-07 14:52:45 -0500 | [diff] [blame] | 1185 | #ifdef SINGLE_ROWBUF_ALLOC |
| 1186 | png_debug(1, "destroying row_buf for read_ptr\n"); |
Glenn Randers-Pehrson | c4a2ae6 | 1998-01-16 22:06:18 -0600 | [diff] [blame] | 1187 | png_free(read_ptr, row_buf); |
Glenn Randers-Pehrson | 4766a24 | 2000-07-17 06:17:09 -0500 | [diff] [blame] | 1188 | row_buf=NULL; |
Glenn Randers-Pehrson | 3097f61 | 2001-05-07 14:52:45 -0500 | [diff] [blame] | 1189 | #endif /* SINGLE_ROWBUF_ALLOC */ |
| 1190 | png_debug(1, "destroying read_ptr, read_info_ptr, end_info_ptr\n"); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1191 | png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr); |
Glenn Randers-Pehrson | 3097f61 | 2001-05-07 14:52:45 -0500 | [diff] [blame] | 1192 | #ifdef PNG_WRITE_SUPPORTED |
| 1193 | png_debug(1, "destroying write_end_info_ptr\n"); |
Glenn Randers-Pehrson | 6d8f3b0 | 1999-10-23 08:39:18 -0500 | [diff] [blame] | 1194 | png_destroy_info_struct(write_ptr, &write_end_info_ptr); |
Glenn Randers-Pehrson | 3097f61 | 2001-05-07 14:52:45 -0500 | [diff] [blame] | 1195 | png_debug(1, "destroying write_ptr, write_info_ptr\n"); |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1196 | png_destroy_write_struct(&write_ptr, &write_info_ptr); |
Glenn Randers-Pehrson | 3097f61 | 2001-05-07 14:52:45 -0500 | [diff] [blame] | 1197 | #endif |
| 1198 | png_debug(0, "Destruction complete.\n"); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 1199 | |
Glenn Randers-Pehrson | ff9c947 | 2000-07-11 07:12:36 -0500 | [diff] [blame] | 1200 | FCLOSE(fpin); |
| 1201 | FCLOSE(fpout); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 1202 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1203 | png_debug(0, "Opening files for comparison\n"); |
Glenn Randers-Pehrson | ff9c947 | 2000-07-11 07:12:36 -0500 | [diff] [blame] | 1204 | #if defined(_WIN32_WCE) |
| 1205 | MultiByteToWideChar(CP_ACP, 0, inname, -1, path, MAX_PATH); |
| 1206 | if ((fpin = CreateFile(path, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL)) == INVALID_HANDLE_VALUE) |
| 1207 | #else |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1208 | if ((fpin = fopen(inname, "rb")) == NULL) |
Glenn Randers-Pehrson | ff9c947 | 2000-07-11 07:12:36 -0500 | [diff] [blame] | 1209 | #endif |
Guy Schalnat | 0f71645 | 1995-11-28 11:22:13 -0600 | [diff] [blame] | 1210 | { |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1211 | fprintf(STDERR, "Could not find file %s\n", inname); |
Glenn Randers-Pehrson | b212002 | 1998-01-31 20:07:59 -0600 | [diff] [blame] | 1212 | return (1); |
Guy Schalnat | 0f71645 | 1995-11-28 11:22:13 -0600 | [diff] [blame] | 1213 | } |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 1214 | |
Glenn Randers-Pehrson | ff9c947 | 2000-07-11 07:12:36 -0500 | [diff] [blame] | 1215 | #if defined(_WIN32_WCE) |
| 1216 | MultiByteToWideChar(CP_ACP, 0, outname, -1, path, MAX_PATH); |
| 1217 | if ((fpout = CreateFile(path, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL)) == INVALID_HANDLE_VALUE) |
| 1218 | #else |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1219 | if ((fpout = fopen(outname, "rb")) == NULL) |
Glenn Randers-Pehrson | ff9c947 | 2000-07-11 07:12:36 -0500 | [diff] [blame] | 1220 | #endif |
Guy Schalnat | 0f71645 | 1995-11-28 11:22:13 -0600 | [diff] [blame] | 1221 | { |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1222 | fprintf(STDERR, "Could not find file %s\n", outname); |
Glenn Randers-Pehrson | ff9c947 | 2000-07-11 07:12:36 -0500 | [diff] [blame] | 1223 | FCLOSE(fpin); |
Glenn Randers-Pehrson | b212002 | 1998-01-31 20:07:59 -0600 | [diff] [blame] | 1224 | return (1); |
Guy Schalnat | 0f71645 | 1995-11-28 11:22:13 -0600 | [diff] [blame] | 1225 | } |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1226 | |
Glenn Randers-Pehrson | ea3bcd7 | 1998-03-07 14:33:00 -0600 | [diff] [blame] | 1227 | for(;;) |
Guy Schalnat | 0f71645 | 1995-11-28 11:22:13 -0600 | [diff] [blame] | 1228 | { |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1229 | png_size_t num_in, num_out; |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 1230 | |
Glenn Randers-Pehrson | 316f97a | 2000-07-08 13:19:41 -0500 | [diff] [blame] | 1231 | READFILE(fpin, inbuf, 1, num_in); |
| 1232 | READFILE(fpout, outbuf, 1, num_out); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 1233 | |
Guy Schalnat | 0f71645 | 1995-11-28 11:22:13 -0600 | [diff] [blame] | 1234 | if (num_in != num_out) |
| 1235 | { |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1236 | fprintf(STDERR, "\nFiles %s and %s are of a different size\n", |
Guy Schalnat | e5a3779 | 1996-06-05 15:50:50 -0500 | [diff] [blame] | 1237 | inname, outname); |
Glenn Randers-Pehrson | cbe52d8 | 1998-02-28 07:00:24 -0600 | [diff] [blame] | 1238 | if(wrote_question == 0) |
| 1239 | { |
| 1240 | fprintf(STDERR, |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1241 | " Was %s written with the same maximum IDAT chunk size (%d bytes),", |
| 1242 | inname,PNG_ZBUF_SIZE); |
Glenn Randers-Pehrson | cbe52d8 | 1998-02-28 07:00:24 -0600 | [diff] [blame] | 1243 | fprintf(STDERR, |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1244 | "\n filtering heuristic (libpng default), compression"); |
Glenn Randers-Pehrson | cbe52d8 | 1998-02-28 07:00:24 -0600 | [diff] [blame] | 1245 | fprintf(STDERR, |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1246 | " level (zlib default),\n and zlib version (%s)?\n\n", |
Glenn Randers-Pehrson | cbe52d8 | 1998-02-28 07:00:24 -0600 | [diff] [blame] | 1247 | ZLIB_VERSION); |
| 1248 | wrote_question=1; |
| 1249 | } |
Glenn Randers-Pehrson | ff9c947 | 2000-07-11 07:12:36 -0500 | [diff] [blame] | 1250 | FCLOSE(fpin); |
| 1251 | FCLOSE(fpout); |
Glenn Randers-Pehrson | cbe52d8 | 1998-02-28 07:00:24 -0600 | [diff] [blame] | 1252 | return (0); |
Guy Schalnat | 0f71645 | 1995-11-28 11:22:13 -0600 | [diff] [blame] | 1253 | } |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 1254 | |
Guy Schalnat | 0f71645 | 1995-11-28 11:22:13 -0600 | [diff] [blame] | 1255 | if (!num_in) |
| 1256 | break; |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 1257 | |
Andreas Dilger | 47a0c42 | 1997-05-16 02:46:07 -0500 | [diff] [blame] | 1258 | if (png_memcmp(inbuf, outbuf, num_in)) |
Guy Schalnat | 0f71645 | 1995-11-28 11:22:13 -0600 | [diff] [blame] | 1259 | { |
Glenn Randers-Pehrson | 4393a9a | 1999-09-17 12:27:26 -0500 | [diff] [blame] | 1260 | fprintf(STDERR, "\nFiles %s and %s are different\n", inname, outname); |
Glenn Randers-Pehrson | cbe52d8 | 1998-02-28 07:00:24 -0600 | [diff] [blame] | 1261 | if(wrote_question == 0) |
| 1262 | { |
| 1263 | fprintf(STDERR, |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1264 | " Was %s written with the same maximum IDAT chunk size (%d bytes),", |
| 1265 | inname,PNG_ZBUF_SIZE); |
Glenn Randers-Pehrson | cbe52d8 | 1998-02-28 07:00:24 -0600 | [diff] [blame] | 1266 | fprintf(STDERR, |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1267 | "\n filtering heuristic (libpng default), compression"); |
Glenn Randers-Pehrson | cbe52d8 | 1998-02-28 07:00:24 -0600 | [diff] [blame] | 1268 | fprintf(STDERR, |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1269 | " level (zlib default),\n and zlib version (%s)?\n\n", |
Glenn Randers-Pehrson | cbe52d8 | 1998-02-28 07:00:24 -0600 | [diff] [blame] | 1270 | ZLIB_VERSION); |
| 1271 | wrote_question=1; |
| 1272 | } |
Glenn Randers-Pehrson | ff9c947 | 2000-07-11 07:12:36 -0500 | [diff] [blame] | 1273 | FCLOSE(fpin); |
| 1274 | FCLOSE(fpout); |
Glenn Randers-Pehrson | cbe52d8 | 1998-02-28 07:00:24 -0600 | [diff] [blame] | 1275 | return (0); |
Guy Schalnat | 0f71645 | 1995-11-28 11:22:13 -0600 | [diff] [blame] | 1276 | } |
| 1277 | } |
| 1278 | |
Glenn Randers-Pehrson | ff9c947 | 2000-07-11 07:12:36 -0500 | [diff] [blame] | 1279 | FCLOSE(fpin); |
| 1280 | FCLOSE(fpout); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 1281 | |
Glenn Randers-Pehrson | b212002 | 1998-01-31 20:07:59 -0600 | [diff] [blame] | 1282 | return (0); |
Guy Schalnat | 0d58058 | 1995-07-20 02:43:20 -0500 | [diff] [blame] | 1283 | } |
Guy Schalnat | 51f0eb4 | 1995-09-26 05:22:39 -0500 | [diff] [blame] | 1284 | |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 1285 | /* input and output filenames */ |
| 1286 | #ifdef RISCOS |
Glenn Randers-Pehrson | 4393a9a | 1999-09-17 12:27:26 -0500 | [diff] [blame] | 1287 | static PNG_CONST char *inname = "pngtest/png"; |
| 1288 | static PNG_CONST char *outname = "pngout/png"; |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 1289 | #else |
Glenn Randers-Pehrson | 983ec16 | 1998-03-07 11:24:03 -0600 | [diff] [blame] | 1290 | static PNG_CONST char *inname = "pngtest.png"; |
| 1291 | static PNG_CONST char *outname = "pngout.png"; |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 1292 | #endif |
| 1293 | |
| 1294 | int |
| 1295 | main(int argc, char *argv[]) |
| 1296 | { |
| 1297 | int multiple = 0; |
| 1298 | int ierror = 0; |
| 1299 | |
| 1300 | fprintf(STDERR, "Testing libpng version %s\n", PNG_LIBPNG_VER_STRING); |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 1301 | fprintf(STDERR, " with zlib version %s\n", ZLIB_VERSION); |
Glenn Randers-Pehrson | 5c6aeb2 | 1998-12-29 11:47:59 -0600 | [diff] [blame] | 1302 | fprintf(STDERR,"%s",png_get_copyright(NULL)); |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 1303 | /* Show the version of libpng used in building the library */ |
Glenn Randers-Pehrson | 1ef65b6 | 2000-05-12 06:19:53 -0500 | [diff] [blame] | 1304 | fprintf(STDERR," library (%lu):%s", png_access_version_number(), |
| 1305 | png_get_header_version(NULL)); |
Glenn Randers-Pehrson | 5379b24 | 1999-11-27 10:22:33 -0600 | [diff] [blame] | 1306 | /* Show the version of libpng used in building the application */ |
Glenn Randers-Pehrson | 1394480 | 2000-06-24 07:42:42 -0500 | [diff] [blame] | 1307 | fprintf(STDERR," pngtest (%lu):%s", (unsigned long)PNG_LIBPNG_VER, |
Glenn Randers-Pehrson | 1ef65b6 | 2000-05-12 06:19:53 -0500 | [diff] [blame] | 1308 | PNG_HEADER_VERSION_STRING); |
Glenn Randers-Pehrson | 5fea36f | 2004-07-28 08:20:44 -0500 | [diff] [blame^] | 1309 | fprintf(STDERR," png_sizeof(png_struct)=%ld, png_sizeof(png_info)=%ld\n", |
| 1310 | (long)png_sizeof(png_struct), (long)png_sizeof(png_info)); |
| 1311 | fprintf(STDERR," PNG_UINT_31_MAX=%lu, PNG_UINT_32_MAX=%lu\n", |
| 1312 | PNG_UINT_31_MAX, PNG_UINT_32_MAX); |
| 1313 | fprintf(STDERR," PNG_SIZE_MAX=%u\n",PNG_SIZE_MAX); |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 1314 | |
| 1315 | /* Do some consistency checking on the memory allocation settings, I'm |
| 1316 | not sure this matters, but it is nice to know, the first of these |
| 1317 | tests should be impossible because of the way the macros are set |
| 1318 | in pngconf.h */ |
Glenn Randers-Pehrson | ea3bcd7 | 1998-03-07 14:33:00 -0600 | [diff] [blame] | 1319 | #if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K) |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 1320 | fprintf(STDERR, " NOTE: Zlib compiled for max 64k, libpng not\n"); |
Glenn Randers-Pehrson | ea3bcd7 | 1998-03-07 14:33:00 -0600 | [diff] [blame] | 1321 | #endif |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 1322 | /* I think the following can happen. */ |
Glenn Randers-Pehrson | ea3bcd7 | 1998-03-07 14:33:00 -0600 | [diff] [blame] | 1323 | #if !defined(MAXSEG_64K) && defined(PNG_MAX_MALLOC_64K) |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 1324 | fprintf(STDERR, " NOTE: libpng compiled for max 64k, zlib not\n"); |
Glenn Randers-Pehrson | ea3bcd7 | 1998-03-07 14:33:00 -0600 | [diff] [blame] | 1325 | #endif |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 1326 | |
| 1327 | if (strcmp(png_libpng_ver, PNG_LIBPNG_VER_STRING)) |
| 1328 | { |
| 1329 | fprintf(STDERR, |
| 1330 | "Warning: versions are different between png.h and png.c\n"); |
| 1331 | fprintf(STDERR, " png.h version: %s\n", PNG_LIBPNG_VER_STRING); |
| 1332 | fprintf(STDERR, " png.c version: %s\n\n", png_libpng_ver); |
| 1333 | ++ierror; |
| 1334 | } |
| 1335 | |
| 1336 | if (argc > 1) |
| 1337 | { |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 1338 | if (strcmp(argv[1], "-m") == 0) |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 1339 | { |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 1340 | multiple = 1; |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 1341 | status_dots_requested = 0; |
| 1342 | } |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 1343 | else if (strcmp(argv[1], "-mv") == 0 || |
| 1344 | strcmp(argv[1], "-vm") == 0 ) |
| 1345 | { |
| 1346 | multiple = 1; |
| 1347 | verbose = 1; |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 1348 | status_dots_requested = 1; |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 1349 | } |
| 1350 | else if (strcmp(argv[1], "-v") == 0) |
| 1351 | { |
| 1352 | verbose = 1; |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 1353 | status_dots_requested = 1; |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 1354 | inname = argv[2]; |
| 1355 | } |
| 1356 | else |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 1357 | { |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 1358 | inname = argv[1]; |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 1359 | status_dots_requested = 0; |
| 1360 | } |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 1361 | } |
| 1362 | |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 1363 | if (!multiple && argc == 3+verbose) |
| 1364 | outname = argv[2+verbose]; |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 1365 | |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 1366 | if ((!multiple && argc > 3+verbose) || (multiple && argc < 2)) |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 1367 | { |
Glenn Randers-Pehrson | c4a2ae6 | 1998-01-16 22:06:18 -0600 | [diff] [blame] | 1368 | fprintf(STDERR, |
| 1369 | "usage: %s [infile.png] [outfile.png]\n\t%s -m {infile.png}\n", |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 1370 | argv[0], argv[0]); |
Glenn Randers-Pehrson | c4a2ae6 | 1998-01-16 22:06:18 -0600 | [diff] [blame] | 1371 | fprintf(STDERR, |
| 1372 | " reads/writes one PNG file (without -m) or multiple files (-m)\n"); |
| 1373 | fprintf(STDERR, |
| 1374 | " with -m %s is used as a temporary file\n", outname); |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 1375 | exit(1); |
| 1376 | } |
| 1377 | |
| 1378 | if (multiple) |
| 1379 | { |
| 1380 | int i; |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 1381 | #ifdef PNG_USER_MEM_SUPPORTED |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 1382 | int allocation_now = current_allocation; |
| 1383 | #endif |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 1384 | for (i=2; i<argc; ++i) |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 1385 | { |
Glenn Randers-Pehrson | 6942d53 | 2000-05-01 09:31:54 -0500 | [diff] [blame] | 1386 | #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) |
| 1387 | int k; |
| 1388 | #endif |
| 1389 | int kerror; |
Glenn Randers-Pehrson | c4a2ae6 | 1998-01-16 22:06:18 -0600 | [diff] [blame] | 1390 | fprintf(STDERR, "Testing %s:",argv[i]); |
| 1391 | kerror = test_one_file(argv[i], outname); |
Glenn Randers-Pehrson | 5c6aeb2 | 1998-12-29 11:47:59 -0600 | [diff] [blame] | 1392 | if (kerror == 0) |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 1393 | { |
Glenn Randers-Pehrson | 38d73af | 1998-03-07 21:30:44 -0600 | [diff] [blame] | 1394 | #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) |
Glenn Randers-Pehrson | 6d8f3b0 | 1999-10-23 08:39:18 -0500 | [diff] [blame] | 1395 | fprintf(STDERR, "\n PASS (%lu zero samples)\n",zero_samples); |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 1396 | #else |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 1397 | fprintf(STDERR, " PASS\n"); |
Glenn Randers-Pehrson | 5c6aeb2 | 1998-12-29 11:47:59 -0600 | [diff] [blame] | 1398 | #endif |
Glenn Randers-Pehrson | 4393a9a | 1999-09-17 12:27:26 -0500 | [diff] [blame] | 1399 | #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) |
| 1400 | for (k=0; k<256; k++) |
| 1401 | if(filters_used[k]) |
| 1402 | fprintf(STDERR, " Filter %d was used %lu times\n", |
| 1403 | k,filters_used[k]); |
| 1404 | #endif |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 1405 | #if defined(PNG_TIME_RFC1123_SUPPORTED) |
| 1406 | if(tIME_chunk_present != 0) |
| 1407 | fprintf(STDERR, " tIME = %s\n",tIME_string); |
| 1408 | tIME_chunk_present = 0; |
| 1409 | #endif /* PNG_TIME_RFC1123_SUPPORTED */ |
| 1410 | } |
| 1411 | else |
| 1412 | { |
Glenn Randers-Pehrson | c4a2ae6 | 1998-01-16 22:06:18 -0600 | [diff] [blame] | 1413 | fprintf(STDERR, " FAIL\n"); |
| 1414 | ierror += kerror; |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 1415 | } |
| 1416 | #ifdef PNG_USER_MEM_SUPPORTED |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 1417 | if (allocation_now != current_allocation) |
| 1418 | fprintf(STDERR, "MEMORY ERROR: %d bytes lost\n", |
| 1419 | current_allocation-allocation_now); |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1420 | if (current_allocation != 0) |
| 1421 | { |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 1422 | memory_infop pinfo = pinformation; |
| 1423 | |
| 1424 | fprintf(STDERR, "MEMORY ERROR: %d bytes still allocated\n", |
| 1425 | current_allocation); |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1426 | while (pinfo != NULL) |
| 1427 | { |
Glenn Randers-Pehrson | b182893 | 2001-06-23 08:03:17 -0500 | [diff] [blame] | 1428 | fprintf(STDERR, " %lu bytes at %x\n", pinfo->size, |
| 1429 | (unsigned int) pinfo->pointer); |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 1430 | pinfo = pinfo->next; |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1431 | } |
Glenn Randers-Pehrson | 2687fcc | 1998-01-07 20:54:20 -0600 | [diff] [blame] | 1432 | } |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 1433 | #endif |
| 1434 | } |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 1435 | #ifdef PNG_USER_MEM_SUPPORTED |
Glenn Randers-Pehrson | 104622b | 2000-05-29 08:58:03 -0500 | [diff] [blame] | 1436 | fprintf(STDERR, " Current memory allocation: %10d bytes\n", |
Glenn Randers-Pehrson | bcfd15d | 1999-10-01 14:22:25 -0500 | [diff] [blame] | 1437 | current_allocation); |
Glenn Randers-Pehrson | 104622b | 2000-05-29 08:58:03 -0500 | [diff] [blame] | 1438 | fprintf(STDERR, " Maximum memory allocation: %10d bytes\n", |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 1439 | maximum_allocation); |
Glenn Randers-Pehrson | 104622b | 2000-05-29 08:58:03 -0500 | [diff] [blame] | 1440 | fprintf(STDERR, " Total memory allocation: %10d bytes\n", |
| 1441 | total_allocation); |
| 1442 | fprintf(STDERR, " Number of allocations: %10d\n", |
| 1443 | num_allocations); |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 1444 | #endif |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 1445 | } |
| 1446 | else |
| 1447 | { |
Glenn Randers-Pehrson | c4a2ae6 | 1998-01-16 22:06:18 -0600 | [diff] [blame] | 1448 | int i; |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1449 | for (i=0; i<3; ++i) |
| 1450 | { |
Glenn Randers-Pehrson | c4a2ae6 | 1998-01-16 22:06:18 -0600 | [diff] [blame] | 1451 | int kerror; |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 1452 | #ifdef PNG_USER_MEM_SUPPORTED |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 1453 | int allocation_now = current_allocation; |
| 1454 | #endif |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 1455 | if (i == 1) status_dots_requested = 1; |
| 1456 | else if(verbose == 0)status_dots_requested = 0; |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 1457 | if (i == 0 || verbose == 1 || ierror != 0) |
| 1458 | fprintf(STDERR, "Testing %s:",inname); |
Glenn Randers-Pehrson | c4a2ae6 | 1998-01-16 22:06:18 -0600 | [diff] [blame] | 1459 | kerror = test_one_file(inname, outname); |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 1460 | if(kerror == 0) |
| 1461 | { |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 1462 | if(verbose == 1 || i == 2) |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 1463 | { |
Glenn Randers-Pehrson | 6942d53 | 2000-05-01 09:31:54 -0500 | [diff] [blame] | 1464 | #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) |
Glenn Randers-Pehrson | 4393a9a | 1999-09-17 12:27:26 -0500 | [diff] [blame] | 1465 | int k; |
Glenn Randers-Pehrson | 6942d53 | 2000-05-01 09:31:54 -0500 | [diff] [blame] | 1466 | #endif |
Glenn Randers-Pehrson | 38d73af | 1998-03-07 21:30:44 -0600 | [diff] [blame] | 1467 | #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) |
Glenn Randers-Pehrson | 6d8f3b0 | 1999-10-23 08:39:18 -0500 | [diff] [blame] | 1468 | fprintf(STDERR, "\n PASS (%lu zero samples)\n",zero_samples); |
Glenn Randers-Pehrson | 08a3343 | 1998-03-07 06:06:55 -0600 | [diff] [blame] | 1469 | #else |
| 1470 | fprintf(STDERR, " PASS\n"); |
| 1471 | #endif |
Glenn Randers-Pehrson | 4393a9a | 1999-09-17 12:27:26 -0500 | [diff] [blame] | 1472 | #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) |
| 1473 | for (k=0; k<256; k++) |
| 1474 | if(filters_used[k]) |
| 1475 | fprintf(STDERR, " Filter %d was used %lu times\n", |
| 1476 | k,filters_used[k]); |
| 1477 | #endif |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 1478 | #if defined(PNG_TIME_RFC1123_SUPPORTED) |
Glenn Randers-Pehrson | 4393a9a | 1999-09-17 12:27:26 -0500 | [diff] [blame] | 1479 | if(tIME_chunk_present != 0) |
| 1480 | fprintf(STDERR, " tIME = %s\n",tIME_string); |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 1481 | #endif /* PNG_TIME_RFC1123_SUPPORTED */ |
| 1482 | } |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 1483 | } |
| 1484 | else |
| 1485 | { |
| 1486 | if(verbose == 0 && i != 2) |
| 1487 | fprintf(STDERR, "Testing %s:",inname); |
Glenn Randers-Pehrson | c4a2ae6 | 1998-01-16 22:06:18 -0600 | [diff] [blame] | 1488 | fprintf(STDERR, " FAIL\n"); |
| 1489 | ierror += kerror; |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 1490 | } |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 1491 | #ifdef PNG_USER_MEM_SUPPORTED |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 1492 | if (allocation_now != current_allocation) |
| 1493 | fprintf(STDERR, "MEMORY ERROR: %d bytes lost\n", |
| 1494 | current_allocation-allocation_now); |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1495 | if (current_allocation != 0) |
| 1496 | { |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 1497 | memory_infop pinfo = pinformation; |
Glenn Randers-Pehrson | 5c6aeb2 | 1998-12-29 11:47:59 -0600 | [diff] [blame] | 1498 | |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 1499 | fprintf(STDERR, "MEMORY ERROR: %d bytes still allocated\n", |
| 1500 | current_allocation); |
Glenn Randers-Pehrson | 61c32d9 | 2000-02-04 23:40:16 -0600 | [diff] [blame] | 1501 | while (pinfo != NULL) |
| 1502 | { |
Glenn Randers-Pehrson | b182893 | 2001-06-23 08:03:17 -0500 | [diff] [blame] | 1503 | fprintf(STDERR," %lu bytes at %x\n", |
| 1504 | pinfo->size, (unsigned int)pinfo->pointer); |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 1505 | pinfo = pinfo->next; |
| 1506 | } |
| 1507 | } |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 1508 | #endif |
Glenn Randers-Pehrson | c4a2ae6 | 1998-01-16 22:06:18 -0600 | [diff] [blame] | 1509 | } |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 1510 | #ifdef PNG_USER_MEM_SUPPORTED |
Glenn Randers-Pehrson | 104622b | 2000-05-29 08:58:03 -0500 | [diff] [blame] | 1511 | fprintf(STDERR, " Current memory allocation: %10d bytes\n", |
Glenn Randers-Pehrson | bcfd15d | 1999-10-01 14:22:25 -0500 | [diff] [blame] | 1512 | current_allocation); |
Glenn Randers-Pehrson | 104622b | 2000-05-29 08:58:03 -0500 | [diff] [blame] | 1513 | fprintf(STDERR, " Maximum memory allocation: %10d bytes\n", |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 1514 | maximum_allocation); |
Glenn Randers-Pehrson | 104622b | 2000-05-29 08:58:03 -0500 | [diff] [blame] | 1515 | fprintf(STDERR, " Total memory allocation: %10d bytes\n", |
| 1516 | total_allocation); |
| 1517 | fprintf(STDERR, " Number of allocations: %10d\n", |
| 1518 | num_allocations); |
Glenn Randers-Pehrson | 46f61e2 | 1998-01-30 21:45:12 -0600 | [diff] [blame] | 1519 | #endif |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 1520 | } |
| 1521 | |
Glenn Randers-Pehrson | bcfd15d | 1999-10-01 14:22:25 -0500 | [diff] [blame] | 1522 | #ifdef PNGTEST_TIMING |
| 1523 | t_stop = (float)clock(); |
| 1524 | t_misc += (t_stop - t_start); |
| 1525 | t_start = t_stop; |
| 1526 | fprintf(STDERR," CPU time used = %.3f seconds", |
| 1527 | (t_misc+t_decode+t_encode)/(float)CLOCKS_PER_SEC); |
| 1528 | fprintf(STDERR," (decoding %.3f,\n", |
| 1529 | t_decode/(float)CLOCKS_PER_SEC); |
| 1530 | fprintf(STDERR," encoding %.3f ,", |
| 1531 | t_encode/(float)CLOCKS_PER_SEC); |
| 1532 | fprintf(STDERR," other %.3f seconds)\n\n", |
| 1533 | t_misc/(float)CLOCKS_PER_SEC); |
| 1534 | #endif |
| 1535 | |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 1536 | if (ierror == 0) |
| 1537 | fprintf(STDERR, "libpng passes test\n"); |
| 1538 | else |
| 1539 | fprintf(STDERR, "libpng FAILS test\n"); |
Glenn Randers-Pehrson | 0f881d6 | 1998-02-07 10:20:57 -0600 | [diff] [blame] | 1540 | return (int)(ierror != 0); |
Glenn Randers-Pehrson | 70e3f54 | 1998-01-03 22:40:55 -0600 | [diff] [blame] | 1541 | } |
Glenn Randers-Pehrson | f7d1a17 | 1998-06-06 15:31:35 -0500 | [diff] [blame] | 1542 | |
Glenn Randers-Pehrson | bcfd15d | 1999-10-01 14:22:25 -0500 | [diff] [blame] | 1543 | /* Generate a compiler error if there is an old png.h in the search path. */ |
Glenn Randers-Pehrson | 5fea36f | 2004-07-28 08:20:44 -0500 | [diff] [blame^] | 1544 | typedef version_1_2_6beta4 your_png_h_is_not_version_1_2_6beta4; |