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