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