| 1 | /* |
|---|
| 2 | * $Id: //suprahd/releases/suprahd_163/suprahd_ztvapp640_163/drivers/graphics/PNG/lpng102/pngtest.c#1 $ |
|---|
| 3 | * $Revision: #1 $ |
|---|
| 4 | * $DateTime: 2006/02/24 17:51:46 $ |
|---|
| 5 | * $Change: 42566 $ |
|---|
| 6 | * $Author: pryush.sharma $ |
|---|
| 7 | */ |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | /* pngtest.c - a simple test program to test libpng |
|---|
| 11 | * |
|---|
| 12 | * libpng 1.0.2 -June 14, 1998 |
|---|
| 13 | * For conditions of distribution and use, see copyright notice in png.h |
|---|
| 14 | * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. |
|---|
| 15 | * Copyright (c) 1996, 1997 Andreas Dilger |
|---|
| 16 | * Copyright (c) 1998, Glenn Randers-Pehrson |
|---|
| 17 | * |
|---|
| 18 | * This program reads in a PNG image, writes it out again, and then |
|---|
| 19 | * compares the two files. If the files are identical, this shows that |
|---|
| 20 | * the basic chunk handling, filtering, and (de)compression code is working |
|---|
| 21 | * properly. It does not currently test all of the transforms, although |
|---|
| 22 | * it probably should. |
|---|
| 23 | * |
|---|
| 24 | * The program will report "FAIL" in certain legitimate cases: |
|---|
| 25 | * 1) when the compression level or filter selection method is changed. |
|---|
| 26 | * 2) when the chunk size is not 8K. |
|---|
| 27 | * 3) unknown ancillary chunks exist in the input file. |
|---|
| 28 | * 4) others not listed here... |
|---|
| 29 | * In these cases, it is best to check with another tool such as "pngcheck" |
|---|
| 30 | * to see what the differences between the two images are. |
|---|
| 31 | * |
|---|
| 32 | * If a filename is given on the command-line, then this file is used |
|---|
| 33 | * for the input, rather than the default "pngtest.png". This allows |
|---|
| 34 | * testing a wide variety of files easily. You can also test a number |
|---|
| 35 | * of files at once by typing "pngtest -m file1.png file2.png ..." |
|---|
| 36 | */ |
|---|
| 37 | |
|---|
| 38 | #include <stdio.h> |
|---|
| 39 | //#include <string.h> |
|---|
| 40 | |
|---|
| 41 | /* Makes pngtest verbose so we can find problems (needs to be before png.h) */ |
|---|
| 42 | #ifndef PNG_DEBUG |
|---|
| 43 | #define PNG_DEBUG 0 |
|---|
| 44 | #endif |
|---|
| 45 | |
|---|
| 46 | #include "png.h" |
|---|
| 47 | |
|---|
| 48 | #if defined(PNG_TIME_RFC1123_SUPPORTED) |
|---|
| 49 | static int tIME_chunk_present=0; |
|---|
| 50 | static char tIME_string[30] = "no tIME chunk present in file"; |
|---|
| 51 | #endif /* PNG_TIME_RFC1123_SUPPORTED */ |
|---|
| 52 | |
|---|
| 53 | int test_one_file PNGARG((PNG_CONST char *inname, PNG_CONST char *outname)); |
|---|
| 54 | |
|---|
| 55 | #ifdef __TURBOC__ |
|---|
| 56 | #include <mem.h> |
|---|
| 57 | #endif |
|---|
| 58 | |
|---|
| 59 | /* defined so I can write to a file on gui/windowing platforms */ |
|---|
| 60 | /* #define STDERR stderr */ |
|---|
| 61 | #define STDERR stdout /* for DOS */ |
|---|
| 62 | |
|---|
| 63 | /* example of using row callbacks to make a simple progress meter */ |
|---|
| 64 | static int status_pass=1; |
|---|
| 65 | static int status_dots_requested=0; |
|---|
| 66 | static int status_dots=1; |
|---|
| 67 | |
|---|
| 68 | void |
|---|
| 69 | read_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass) |
|---|
| 70 | { |
|---|
| 71 | if(png_ptr == NULL || row_number > 0x3fffffffL) return; |
|---|
| 72 | if(status_pass != pass) |
|---|
| 73 | { |
|---|
| 74 | fprintf(stdout,"\n Pass %d: ",pass); |
|---|
| 75 | status_pass = pass; |
|---|
| 76 | status_dots = 30; |
|---|
| 77 | } |
|---|
| 78 | status_dots--; |
|---|
| 79 | if(status_dots == 0) |
|---|
| 80 | { |
|---|
| 81 | fprintf(stdout, "\n "); |
|---|
| 82 | status_dots=30; |
|---|
| 83 | } |
|---|
| 84 | fprintf(stdout, "r"); |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | void |
|---|
| 88 | write_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass) |
|---|
| 89 | { |
|---|
| 90 | if(png_ptr == NULL || row_number > 0x3fffffffL || pass > 7) return; |
|---|
| 91 | fprintf(stdout, "w"); |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | |
|---|
| 95 | #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) |
|---|
| 96 | /* example of using user transform callback (we don't transform anything, |
|---|
| 97 | but merely count the zero samples) */ |
|---|
| 98 | |
|---|
| 99 | static png_uint_32 zero_samples; |
|---|
| 100 | |
|---|
| 101 | void |
|---|
| 102 | count_zero_samples(png_structp png_ptr, png_row_infop row_info, png_bytep data) |
|---|
| 103 | { |
|---|
| 104 | png_bytep dp = data; |
|---|
| 105 | if(png_ptr == NULL)return; |
|---|
| 106 | |
|---|
| 107 | /* contents of row_info: |
|---|
| 108 | * png_uint_32 width width of row |
|---|
| 109 | * png_uint_32 rowbytes number of bytes in row |
|---|
| 110 | * png_byte color_type color type of pixels |
|---|
| 111 | * png_byte bit_depth bit depth of samples |
|---|
| 112 | * png_byte channels number of channels (1-4) |
|---|
| 113 | * png_byte pixel_depth bits per pixel (depth*channels) |
|---|
| 114 | */ |
|---|
| 115 | |
|---|
| 116 | /* counts the number of zero samples (or zero pixels if color_type is 3 */ |
|---|
| 117 | |
|---|
| 118 | if(row_info->color_type == 0 || row_info->color_type == 3) |
|---|
| 119 | { |
|---|
| 120 | int pos=0; |
|---|
| 121 | png_uint_32 n, nstop; |
|---|
| 122 | for (n=0, nstop=row_info->width; n<nstop; n++) |
|---|
| 123 | { |
|---|
| 124 | if(row_info->bit_depth == 1) |
|---|
| 125 | { |
|---|
| 126 | if(((*dp << pos++ )& 0x80) == 0) zero_samples++; |
|---|
| 127 | if(pos == 8) |
|---|
| 128 | { |
|---|
| 129 | pos = 0; |
|---|
| 130 | dp++; |
|---|
| 131 | } |
|---|
| 132 | } |
|---|
| 133 | if(row_info->bit_depth == 2) |
|---|
| 134 | { |
|---|
| 135 | if(((*dp << (pos+=2))& 0xc0) == 0) zero_samples++; |
|---|
| 136 | if(pos == 8) |
|---|
| 137 | { |
|---|
| 138 | pos = 0; |
|---|
| 139 | dp++; |
|---|
| 140 | } |
|---|
| 141 | } |
|---|
| 142 | if(row_info->bit_depth == 4) |
|---|
| 143 | { |
|---|
| 144 | if(((*dp << (pos+=4))& 0xf0) == 0) zero_samples++; |
|---|
| 145 | if(pos == 8) |
|---|
| 146 | { |
|---|
| 147 | pos = 0; |
|---|
| 148 | dp++; |
|---|
| 149 | } |
|---|
| 150 | } |
|---|
| 151 | if(row_info->bit_depth == 8) |
|---|
| 152 | if(*dp++ == 0) zero_samples++; |
|---|
| 153 | if(row_info->bit_depth == 16) |
|---|
| 154 | { |
|---|
| 155 | if((*dp | *(dp+1)) == 0) zero_samples++; |
|---|
| 156 | dp+=2; |
|---|
| 157 | } |
|---|
| 158 | } |
|---|
| 159 | } |
|---|
| 160 | else /* other color types */ |
|---|
| 161 | { |
|---|
| 162 | png_uint_32 n, nstop; |
|---|
| 163 | int channel; |
|---|
| 164 | int color_channels = row_info->channels; |
|---|
| 165 | if(row_info->color_type > 3)color_channels--; |
|---|
| 166 | |
|---|
| 167 | for (n=0, nstop=row_info->width; n<nstop; n++) |
|---|
| 168 | { |
|---|
| 169 | for (channel = 0; channel < color_channels; channel++) |
|---|
| 170 | { |
|---|
| 171 | if(row_info->bit_depth == 8) |
|---|
| 172 | if(*dp++ == 0) zero_samples++; |
|---|
| 173 | if(row_info->bit_depth == 16) |
|---|
| 174 | { |
|---|
| 175 | if((*dp | *(dp+1)) == 0) zero_samples++; |
|---|
| 176 | dp+=2; |
|---|
| 177 | } |
|---|
| 178 | } |
|---|
| 179 | if(row_info->color_type > 3) |
|---|
| 180 | { |
|---|
| 181 | dp++; |
|---|
| 182 | if(row_info->bit_depth == 16)dp++; |
|---|
| 183 | } |
|---|
| 184 | } |
|---|
| 185 | } |
|---|
| 186 | } |
|---|
| 187 | #endif /* PNG_WRITE_USER_TRANSFORM_SUPPORTED */ |
|---|
| 188 | |
|---|
| 189 | static int verbose = 0; |
|---|
| 190 | static int wrote_question = 0; |
|---|
| 191 | |
|---|
| 192 | #if defined(PNG_NO_STDIO) |
|---|
| 193 | /* START of code to validate stdio-free compilation */ |
|---|
| 194 | /* These copies of the default read/write functions come from pngrio.c and */ |
|---|
| 195 | /* pngwio.c. They allow "don't include stdio" testing of the library. */ |
|---|
| 196 | /* This is the function that does the actual reading of data. If you are |
|---|
| 197 | not reading from a standard C stream, you should create a replacement |
|---|
| 198 | read_data function and use it at run time with png_set_read_fn(), rather |
|---|
| 199 | than changing the library. */ |
|---|
| 200 | #ifndef USE_FAR_KEYWORD |
|---|
| 201 | static void |
|---|
| 202 | png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length) |
|---|
| 203 | { |
|---|
| 204 | png_size_t check; |
|---|
| 205 | |
|---|
| 206 | /* fread() returns 0 on error, so it is OK to store this in a png_size_t |
|---|
| 207 | * instead of an int, which is what fread() actually returns. |
|---|
| 208 | */ |
|---|
| 209 | check = (png_size_t)fread(data, (png_size_t)1, length, |
|---|
| 210 | (FILE *)png_ptr->io_ptr); |
|---|
| 211 | |
|---|
| 212 | if (check != length) |
|---|
| 213 | { |
|---|
| 214 | png_error(png_ptr, "Read Error"); |
|---|
| 215 | } |
|---|
| 216 | } |
|---|
| 217 | #else |
|---|
| 218 | /* this is the model-independent version. Since the standard I/O library |
|---|
| 219 | can't handle far buffers in the medium and small models, we have to copy |
|---|
| 220 | the data. |
|---|
| 221 | */ |
|---|
| 222 | |
|---|
| 223 | #define NEAR_BUF_SIZE 1024 |
|---|
| 224 | #define MIN(a,b) (a <= b ? a : b) |
|---|
| 225 | |
|---|
| 226 | static void |
|---|
| 227 | png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length) |
|---|
| 228 | { |
|---|
| 229 | int check; |
|---|
| 230 | png_byte *n_data; |
|---|
| 231 | FILE *io_ptr; |
|---|
| 232 | |
|---|
| 233 | /* Check if data really is near. If so, use usual code. */ |
|---|
| 234 | n_data = (png_byte *)CVT_PTR_NOCHECK(data); |
|---|
| 235 | io_ptr = (FILE *)CVT_PTR(png_ptr->io_ptr); |
|---|
| 236 | if ((png_bytep)n_data == data) |
|---|
| 237 | { |
|---|
| 238 | check = fread(n_data, 1, length, io_ptr); |
|---|
| 239 | } |
|---|
| 240 | else |
|---|
| 241 | { |
|---|
| 242 | png_byte buf[NEAR_BUF_SIZE]; |
|---|
| 243 | png_size_t read, remaining, err; |
|---|
| 244 | check = 0; |
|---|
| 245 | remaining = length; |
|---|
| 246 | do |
|---|
| 247 | { |
|---|
| 248 | read = MIN(NEAR_BUF_SIZE, remaining); |
|---|
| 249 | err = fread(buf, (png_size_t)1, read, io_ptr); |
|---|
| 250 | png_memcpy(data, buf, read); /* copy far buffer to near buffer */ |
|---|
| 251 | if(err != read) |
|---|
| 252 | break; |
|---|
| 253 | else |
|---|
| 254 | check += err; |
|---|
| 255 | data += read; |
|---|
| 256 | remaining -= read; |
|---|
| 257 | } |
|---|
| 258 | while (remaining != 0); |
|---|
| 259 | } |
|---|
| 260 | if (check != length) |
|---|
| 261 | { |
|---|
| 262 | png_error(png_ptr, "read Error"); |
|---|
| 263 | } |
|---|
| 264 | } |
|---|
| 265 | #endif /* USE_FAR_KEYWORD */ |
|---|
| 266 | |
|---|
| 267 | #if defined(PNG_WRITE_FLUSH_SUPPORTED) |
|---|
| 268 | static void |
|---|
| 269 | png_default_flush(png_structp png_ptr) |
|---|
| 270 | { |
|---|
| 271 | FILE *io_ptr; |
|---|
| 272 | io_ptr = (FILE *)CVT_PTR((png_ptr->io_ptr)); |
|---|
| 273 | if (io_ptr != NULL) |
|---|
| 274 | fflush(io_ptr); |
|---|
| 275 | } |
|---|
| 276 | #endif |
|---|
| 277 | |
|---|
| 278 | /* This is the function that does the actual writing of data. If you are |
|---|
| 279 | not writing to a standard C stream, you should create a replacement |
|---|
| 280 | write_data function and use it at run time with png_set_write_fn(), rather |
|---|
| 281 | than changing the library. */ |
|---|
| 282 | #ifndef USE_FAR_KEYWORD |
|---|
| 283 | static void |
|---|
| 284 | png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length) |
|---|
| 285 | { |
|---|
| 286 | png_uint_32 check; |
|---|
| 287 | |
|---|
| 288 | check = fwrite(data, 1, length, (FILE *)(png_ptr->io_ptr)); |
|---|
| 289 | if (check != length) |
|---|
| 290 | { |
|---|
| 291 | png_error(png_ptr, "Write Error"); |
|---|
| 292 | } |
|---|
| 293 | } |
|---|
| 294 | #else |
|---|
| 295 | /* this is the model-independent version. Since the standard I/O library |
|---|
| 296 | can't handle far buffers in the medium and small models, we have to copy |
|---|
| 297 | the data. |
|---|
| 298 | */ |
|---|
| 299 | |
|---|
| 300 | #define NEAR_BUF_SIZE 1024 |
|---|
| 301 | #define MIN(a,b) (a <= b ? a : b) |
|---|
| 302 | |
|---|
| 303 | static void |
|---|
| 304 | png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length) |
|---|
| 305 | { |
|---|
| 306 | png_uint_32 check; |
|---|
| 307 | png_byte *near_data; /* Needs to be "png_byte *" instead of "png_bytep" */ |
|---|
| 308 | FILE *io_ptr; |
|---|
| 309 | |
|---|
| 310 | /* Check if data really is near. If so, use usual code. */ |
|---|
| 311 | near_data = (png_byte *)CVT_PTR_NOCHECK(data); |
|---|
| 312 | io_ptr = (FILE *)CVT_PTR(png_ptr->io_ptr); |
|---|
| 313 | if ((png_bytep)near_data == data) |
|---|
| 314 | { |
|---|
| 315 | check = fwrite(near_data, 1, length, io_ptr); |
|---|
| 316 | } |
|---|
| 317 | else |
|---|
| 318 | { |
|---|
| 319 | png_byte buf[NEAR_BUF_SIZE]; |
|---|
| 320 | png_size_t written, remaining, err; |
|---|
| 321 | check = 0; |
|---|
| 322 | remaining = length; |
|---|
| 323 | do |
|---|
| 324 | { |
|---|
| 325 | written = MIN(NEAR_BUF_SIZE, remaining); |
|---|
| 326 | png_memcpy(buf, data, written); /* copy far buffer to near buffer */ |
|---|
| 327 | err = fwrite(buf, 1, written, io_ptr); |
|---|
| 328 | if (err != written) |
|---|
| 329 | break; |
|---|
| 330 | else |
|---|
| 331 | check += err; |
|---|
| 332 | data += written; |
|---|
| 333 | remaining -= written; |
|---|
| 334 | } |
|---|
| 335 | while (remaining != 0); |
|---|
| 336 | } |
|---|
| 337 | if (check != length) |
|---|
| 338 | { |
|---|
| 339 | png_error(png_ptr, "Write Error"); |
|---|
| 340 | } |
|---|
| 341 | } |
|---|
| 342 | |
|---|
| 343 | #endif /* USE_FAR_KEYWORD */ |
|---|
| 344 | |
|---|
| 345 | /* This function is called when there is a warning, but the library thinks |
|---|
| 346 | * it can continue anyway. Replacement functions don't have to do anything |
|---|
| 347 | * here if you don't want to. In the default configuration, png_ptr is |
|---|
| 348 | * not used, but it is passed in case it may be useful. |
|---|
| 349 | */ |
|---|
| 350 | static void |
|---|
| 351 | png_default_warning(png_structp png_ptr, png_const_charp message) |
|---|
| 352 | { |
|---|
| 353 | PNG_CONST char *name = "UNKNOWN (ERROR!)"; |
|---|
| 354 | if (png_ptr != NULL && png_ptr->error_ptr != NULL) |
|---|
| 355 | name = png_ptr->error_ptr; |
|---|
| 356 | fprintf(STDERR, "%s: libpng warning: %s\n", name, message); |
|---|
| 357 | } |
|---|
| 358 | |
|---|
| 359 | /* This is the default error handling function. Note that replacements for |
|---|
| 360 | * this function MUST NOT RETURN, or the program will likely crash. This |
|---|
| 361 | * function is used by default, or if the program supplies NULL for the |
|---|
| 362 | * error function pointer in png_set_error_fn(). |
|---|
| 363 | */ |
|---|
| 364 | static void |
|---|
| 365 | png_default_error(png_structp png_ptr, png_const_charp message) |
|---|
| 366 | { |
|---|
| 367 | png_default_warning(png_ptr, message); |
|---|
| 368 | /* We can return because png_error calls the default handler, which is |
|---|
| 369 | * actually OK in this case. */ |
|---|
| 370 | } |
|---|
| 371 | #endif /* PNG_NO_STDIO */ |
|---|
| 372 | /* END of code to validate stdio-free compilation */ |
|---|
| 373 | |
|---|
| 374 | /* START of code to validate memory allocation and deallocation */ |
|---|
| 375 | #ifdef PNG_USER_MEM_SUPPORTED |
|---|
| 376 | |
|---|
| 377 | /* Allocate memory. For reasonable files, size should never exceed |
|---|
| 378 | 64K. However, zlib may allocate more then 64K if you don't tell |
|---|
| 379 | it not to. See zconf.h and png.h for more information. zlib does |
|---|
| 380 | need to allocate exactly 64K, so whatever you call here must |
|---|
| 381 | have the ability to do that. |
|---|
| 382 | |
|---|
| 383 | This piece of code can be compiled to validate max 64K allocations |
|---|
| 384 | by setting MAXSEG_64K in zlib zconf.h *or* PNG_MAX_MALLOC_64K. */ |
|---|
| 385 | typedef struct memory_information { |
|---|
| 386 | png_uint_32 size; |
|---|
| 387 | png_voidp pointer; |
|---|
| 388 | struct memory_information FAR *next; |
|---|
| 389 | } memory_information; |
|---|
| 390 | typedef memory_information FAR *memory_infop; |
|---|
| 391 | |
|---|
| 392 | static memory_infop pinformation = NULL; |
|---|
| 393 | static int current_allocation = 0; |
|---|
| 394 | static int maximum_allocation = 0; |
|---|
| 395 | |
|---|
| 396 | extern PNG_EXPORT(png_voidp,png_debug_malloc) PNGARG((png_structp png_ptr, |
|---|
| 397 | png_uint_32 size)); |
|---|
| 398 | extern PNG_EXPORT(void,png_debug_free) PNGARG((png_structp png_ptr, |
|---|
| 399 | png_voidp ptr)); |
|---|
| 400 | |
|---|
| 401 | png_voidp |
|---|
| 402 | png_debug_malloc(png_structp png_ptr, png_uint_32 size) { |
|---|
| 403 | |
|---|
| 404 | /* png_malloc has already tested for NULL; png_create_struct calls |
|---|
| 405 | png_debug_malloc directly, with png_ptr == NULL which is OK */ |
|---|
| 406 | |
|---|
| 407 | if (size == 0) |
|---|
| 408 | return (png_voidp)(NULL); |
|---|
| 409 | |
|---|
| 410 | /* This calls the library allocator twice, once to get the requested |
|---|
| 411 | buffer and once to get a new free list entry. */ |
|---|
| 412 | { |
|---|
| 413 | memory_infop pinfo = png_malloc_default(png_ptr, sizeof *pinfo); |
|---|
| 414 | pinfo->size = size; |
|---|
| 415 | current_allocation += size; |
|---|
| 416 | if (current_allocation > maximum_allocation) |
|---|
| 417 | maximum_allocation = current_allocation; |
|---|
| 418 | pinfo->pointer = png_malloc_default(png_ptr, size); |
|---|
| 419 | pinfo->next = pinformation; |
|---|
| 420 | pinformation = pinfo; |
|---|
| 421 | /* Make sure the caller isn't assuming zeroed memory. */ |
|---|
| 422 | png_memset(pinfo->pointer, 0xdd, pinfo->size); |
|---|
| 423 | return (png_voidp)(pinfo->pointer); |
|---|
| 424 | } |
|---|
| 425 | } |
|---|
| 426 | |
|---|
| 427 | /* Free a pointer. It is removed from the list at the same time. */ |
|---|
| 428 | void |
|---|
| 429 | png_debug_free(png_structp png_ptr, png_voidp ptr) |
|---|
| 430 | { |
|---|
| 431 | if (png_ptr == NULL) |
|---|
| 432 | fprintf(STDERR, "NULL pointer to png_debug_free.\n"); |
|---|
| 433 | if (ptr == 0) { |
|---|
| 434 | #if 0 /* This happens all the time. */ |
|---|
| 435 | fprintf(STDERR, "WARNING: freeing NULL pointer\n"); |
|---|
| 436 | #endif |
|---|
| 437 | return; |
|---|
| 438 | } |
|---|
| 439 | |
|---|
| 440 | /* Unlink the element from the list. */ |
|---|
| 441 | { |
|---|
| 442 | memory_infop FAR *ppinfo = &pinformation; |
|---|
| 443 | for (;;) { |
|---|
| 444 | memory_infop pinfo = *ppinfo; |
|---|
| 445 | if (pinfo->pointer == ptr) { |
|---|
| 446 | *ppinfo = pinfo->next; |
|---|
| 447 | current_allocation -= pinfo->size; |
|---|
| 448 | if (current_allocation < 0) |
|---|
| 449 | fprintf(STDERR, "Duplicate free of memory\n"); |
|---|
| 450 | /* We must free the list element too, but first kill |
|---|
| 451 | the memory that is to be freed. */ |
|---|
| 452 | memset(ptr, 0x55, pinfo->size); |
|---|
| 453 | png_free_default(png_ptr, pinfo); |
|---|
| 454 | break; |
|---|
| 455 | } |
|---|
| 456 | if (pinfo->next == NULL) { |
|---|
| 457 | fprintf(STDERR, "Pointer %x not found\n", ptr); |
|---|
| 458 | break; |
|---|
| 459 | } |
|---|
| 460 | ppinfo = &pinfo->next; |
|---|
| 461 | } |
|---|
| 462 | } |
|---|
| 463 | |
|---|
| 464 | /* Finally free the data. */ |
|---|
| 465 | png_free_default(png_ptr, ptr); |
|---|
| 466 | } |
|---|
| 467 | #endif /* PNG_USER_MEM_SUPPORTED */ |
|---|
| 468 | /* END of code to test memory allocation/deallocation */ |
|---|
| 469 | |
|---|
| 470 | /* Test one file */ |
|---|
| 471 | int |
|---|
| 472 | test_one_file(PNG_CONST char *inname, PNG_CONST char *outname) |
|---|
| 473 | { |
|---|
| 474 | static FILE *fpin, *fpout; /* "static" prevents setjmp corruption */ |
|---|
| 475 | png_structp read_ptr, write_ptr; |
|---|
| 476 | png_infop read_info_ptr, write_info_ptr, end_info_ptr; |
|---|
| 477 | png_bytep row_buf; |
|---|
| 478 | png_uint_32 y; |
|---|
| 479 | png_uint_32 width, height; |
|---|
| 480 | int num_pass, pass; |
|---|
| 481 | int bit_depth, color_type; |
|---|
| 482 | #ifdef USE_FAR_KEYWORD |
|---|
| 483 | jmp_buf jmpbuf; |
|---|
| 484 | #endif |
|---|
| 485 | |
|---|
| 486 | char inbuf[256], outbuf[256]; |
|---|
| 487 | |
|---|
| 488 | row_buf = (png_bytep)NULL; |
|---|
| 489 | |
|---|
| 490 | if ((fpin = fopen(inname, "rb")) == NULL) |
|---|
| 491 | { |
|---|
| 492 | fprintf(STDERR, "Could not find input file %s\n", inname); |
|---|
| 493 | return (1); |
|---|
| 494 | } |
|---|
| 495 | |
|---|
| 496 | if ((fpout = fopen(outname, "wb")) == NULL) |
|---|
| 497 | { |
|---|
| 498 | fprintf(STDERR, "Could not open output file %s\n", outname); |
|---|
| 499 | fclose(fpin); |
|---|
| 500 | return (1); |
|---|
| 501 | } |
|---|
| 502 | |
|---|
| 503 | png_debug(0, "Allocating read and write structures\n"); |
|---|
| 504 | #ifdef PNG_USER_MEM_SUPPORTED |
|---|
| 505 | read_ptr = png_create_read_struct_2(PNG_LIBPNG_VER_STRING, (png_voidp)NULL, |
|---|
| 506 | (png_error_ptr)NULL, (png_error_ptr)NULL, (png_voidp)NULL, |
|---|
| 507 | (png_malloc_ptr)png_debug_malloc, (png_free_ptr)png_debug_free); |
|---|
| 508 | #else |
|---|
| 509 | read_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, (png_voidp)NULL, |
|---|
| 510 | (png_error_ptr)NULL, (png_error_ptr)NULL); |
|---|
| 511 | #endif |
|---|
| 512 | #if defined(PNG_NO_STDIO) |
|---|
| 513 | png_set_error_fn(read_ptr, (png_voidp)inname, png_default_error, |
|---|
| 514 | png_default_warning); |
|---|
| 515 | #endif |
|---|
| 516 | #ifdef PNG_USER_MEM_SUPPORTED |
|---|
| 517 | write_ptr = png_create_write_struct_2(PNG_LIBPNG_VER_STRING, (png_voidp)NULL, |
|---|
| 518 | (png_error_ptr)NULL, (png_error_ptr)NULL, (png_voidp)NULL, |
|---|
| 519 | (png_malloc_ptr)png_debug_malloc, (png_free_ptr)png_debug_free); |
|---|
| 520 | #else |
|---|
| 521 | write_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, (png_voidp)NULL, |
|---|
| 522 | (png_error_ptr)NULL, (png_error_ptr)NULL); |
|---|
| 523 | #endif |
|---|
| 524 | #if defined(PNG_NO_STDIO) |
|---|
| 525 | png_set_error_fn(write_ptr, (png_voidp)inname, png_default_error, |
|---|
| 526 | png_default_warning); |
|---|
| 527 | #endif |
|---|
| 528 | png_debug(0, "Allocating read_info, write_info and end_info structures\n"); |
|---|
| 529 | read_info_ptr = png_create_info_struct(read_ptr); |
|---|
| 530 | write_info_ptr = png_create_info_struct(write_ptr); |
|---|
| 531 | end_info_ptr = png_create_info_struct(read_ptr); |
|---|
| 532 | #ifdef PNG_USER_MEM_SUPPORTED |
|---|
| 533 | #endif |
|---|
| 534 | |
|---|
| 535 | png_debug(0, "Setting jmpbuf for read struct\n"); |
|---|
| 536 | #ifdef USE_FAR_KEYWORD |
|---|
| 537 | if (setjmp(jmpbuf)) |
|---|
| 538 | #else |
|---|
| 539 | if (setjmp(read_ptr->jmpbuf)) |
|---|
| 540 | #endif |
|---|
| 541 | { |
|---|
| 542 | fprintf(STDERR, "%s -> %s: libpng read error\n", inname, outname); |
|---|
| 543 | png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr); |
|---|
| 544 | png_destroy_write_struct(&write_ptr, &write_info_ptr); |
|---|
| 545 | fclose(fpin); |
|---|
| 546 | fclose(fpout); |
|---|
| 547 | return (1); |
|---|
| 548 | } |
|---|
| 549 | |
|---|
| 550 | png_debug(0, "Setting jmpbuf for write struct\n"); |
|---|
| 551 | #ifdef USE_FAR_KEYWORD |
|---|
| 552 | png_memcpy(read_ptr->jmpbuf,jmpbuf,sizeof(jmp_buf)); |
|---|
| 553 | if (setjmp(jmpbuf)) |
|---|
| 554 | #else |
|---|
| 555 | if (setjmp(write_ptr->jmpbuf)) |
|---|
| 556 | #endif |
|---|
| 557 | { |
|---|
| 558 | fprintf(STDERR, "%s -> %s: libpng write error\n", inname, outname); |
|---|
| 559 | png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr); |
|---|
| 560 | png_destroy_write_struct(&write_ptr, &write_info_ptr); |
|---|
| 561 | fclose(fpin); |
|---|
| 562 | fclose(fpout); |
|---|
| 563 | return (1); |
|---|
| 564 | } |
|---|
| 565 | |
|---|
| 566 | #ifdef USE_FAR_KEYWORD |
|---|
| 567 | png_memcpy(write_ptr->jmpbuf,jmpbuf,sizeof(jmp_buf)); |
|---|
| 568 | #endif |
|---|
| 569 | png_debug(0, "Initializing input and output streams\n"); |
|---|
| 570 | #if !defined(PNG_NO_STDIO) |
|---|
| 571 | png_init_io(read_ptr, fpin); |
|---|
| 572 | png_init_io(write_ptr, fpout); |
|---|
| 573 | #else |
|---|
| 574 | png_set_read_fn(read_ptr, (png_voidp)fpin, png_default_read_data); |
|---|
| 575 | png_set_write_fn(write_ptr, (png_voidp)fpout, png_default_write_data, |
|---|
| 576 | #if defined(PNG_WRITE_FLUSH_SUPPORTED) |
|---|
| 577 | png_default_flush); |
|---|
| 578 | #else |
|---|
| 579 | NULL); |
|---|
| 580 | #endif |
|---|
| 581 | #endif |
|---|
| 582 | if(status_dots_requested == 1) |
|---|
| 583 | { |
|---|
| 584 | png_set_write_status_fn(write_ptr, write_row_callback); |
|---|
| 585 | png_set_read_status_fn(read_ptr, read_row_callback); |
|---|
| 586 | } |
|---|
| 587 | else |
|---|
| 588 | { |
|---|
| 589 | png_set_write_status_fn(write_ptr, NULL); |
|---|
| 590 | png_set_read_status_fn(read_ptr, NULL); |
|---|
| 591 | } |
|---|
| 592 | |
|---|
| 593 | # if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) |
|---|
| 594 | zero_samples=0; |
|---|
| 595 | png_set_write_user_transform_fn(write_ptr, count_zero_samples); |
|---|
| 596 | # endif |
|---|
| 597 | |
|---|
| 598 | png_debug(0, "Reading info struct\n"); |
|---|
| 599 | png_read_info(read_ptr, read_info_ptr); |
|---|
| 600 | |
|---|
| 601 | png_debug(0, "Transferring info struct\n"); |
|---|
| 602 | { |
|---|
| 603 | int interlace_type, compression_type, filter_type; |
|---|
| 604 | |
|---|
| 605 | if (png_get_IHDR(read_ptr, read_info_ptr, &width, &height, &bit_depth, |
|---|
| 606 | &color_type, &interlace_type, &compression_type, &filter_type)) |
|---|
| 607 | { |
|---|
| 608 | png_set_IHDR(write_ptr, write_info_ptr, width, height, bit_depth, |
|---|
| 609 | #if defined(PNG_WRITE_INTERLACING_SUPPORTED) |
|---|
| 610 | color_type, interlace_type, compression_type, filter_type); |
|---|
| 611 | #else |
|---|
| 612 | color_type, PNG_INTERLACE_NONE, compression_type, filter_type); |
|---|
| 613 | #endif |
|---|
| 614 | } |
|---|
| 615 | } |
|---|
| 616 | #if defined(PNG_READ_bKGD_SUPPORTED) && defined(PNG_WRITE_bKGD_SUPPORTED) |
|---|
| 617 | { |
|---|
| 618 | png_color_16p background; |
|---|
| 619 | |
|---|
| 620 | if (png_get_bKGD(read_ptr, read_info_ptr, &background)) |
|---|
| 621 | { |
|---|
| 622 | png_set_bKGD(write_ptr, write_info_ptr, background); |
|---|
| 623 | } |
|---|
| 624 | } |
|---|
| 625 | #endif |
|---|
| 626 | #if defined(PNG_READ_cHRM_SUPPORTED) && defined(PNG_WRITE_cHRM_SUPPORTED) |
|---|
| 627 | { |
|---|
| 628 | double white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y; |
|---|
| 629 | |
|---|
| 630 | if (png_get_cHRM(read_ptr, read_info_ptr, &white_x, &white_y, &red_x, |
|---|
| 631 | &red_y, &green_x, &green_y, &blue_x, &blue_y)) |
|---|
| 632 | { |
|---|
| 633 | png_set_cHRM(write_ptr, write_info_ptr, white_x, white_y, red_x, |
|---|
| 634 | red_y, green_x, green_y, blue_x, blue_y); |
|---|
| 635 | } |
|---|
| 636 | } |
|---|
| 637 | #endif |
|---|
| 638 | #if defined(PNG_READ_gAMA_SUPPORTED) && defined(PNG_WRITE_gAMA_SUPPORTED) |
|---|
| 639 | { |
|---|
| 640 | double gamma; |
|---|
| 641 | |
|---|
| 642 | if (png_get_gAMA(read_ptr, read_info_ptr, &gamma)) |
|---|
| 643 | { |
|---|
| 644 | png_set_gAMA(write_ptr, write_info_ptr, gamma); |
|---|
| 645 | } |
|---|
| 646 | } |
|---|
| 647 | #endif |
|---|
| 648 | #if defined(PNG_READ_sRGB_SUPPORTED) && defined(PNG_WRITE_sRGB_SUPPORTED) |
|---|
| 649 | { |
|---|
| 650 | int intent; |
|---|
| 651 | |
|---|
| 652 | if (png_get_sRGB(read_ptr, read_info_ptr, &intent)) |
|---|
| 653 | { |
|---|
| 654 | png_set_sRGB(write_ptr, write_info_ptr, intent); |
|---|
| 655 | } |
|---|
| 656 | } |
|---|
| 657 | #endif |
|---|
| 658 | #if defined(PNG_READ_hIST_SUPPORTED) && defined(PNG_WRITE_hIST_SUPPORTED) |
|---|
| 659 | { |
|---|
| 660 | png_uint_16p hist; |
|---|
| 661 | |
|---|
| 662 | if (png_get_hIST(read_ptr, read_info_ptr, &hist)) |
|---|
| 663 | { |
|---|
| 664 | png_set_hIST(write_ptr, write_info_ptr, hist); |
|---|
| 665 | } |
|---|
| 666 | } |
|---|
| 667 | #endif |
|---|
| 668 | #if defined(PNG_READ_oFFs_SUPPORTED) && defined(PNG_WRITE_oFFs_SUPPORTED) |
|---|
| 669 | { |
|---|
| 670 | png_uint_32 offset_x, offset_y; |
|---|
| 671 | int unit_type; |
|---|
| 672 | |
|---|
| 673 | if (png_get_oFFs(read_ptr, read_info_ptr,&offset_x,&offset_y,&unit_type)) |
|---|
| 674 | { |
|---|
| 675 | png_set_oFFs(write_ptr, write_info_ptr, offset_x, offset_y, unit_type); |
|---|
| 676 | } |
|---|
| 677 | } |
|---|
| 678 | #endif |
|---|
| 679 | #if defined(PNG_READ_pCAL_SUPPORTED) && defined(PNG_WRITE_pCAL_SUPPORTED) |
|---|
| 680 | { |
|---|
| 681 | png_charp purpose, units; |
|---|
| 682 | png_charpp params; |
|---|
| 683 | png_int_32 X0, X1; |
|---|
| 684 | int type, nparams; |
|---|
| 685 | |
|---|
| 686 | if (png_get_pCAL(read_ptr, read_info_ptr, &purpose, &X0, &X1, &type, |
|---|
| 687 | &nparams, &units, ¶ms)) |
|---|
| 688 | { |
|---|
| 689 | png_set_pCAL(write_ptr, write_info_ptr, purpose, X0, X1, type, |
|---|
| 690 | nparams, units, params); |
|---|
| 691 | } |
|---|
| 692 | } |
|---|
| 693 | #endif |
|---|
| 694 | #if defined(PNG_READ_pHYs_SUPPORTED) && defined(PNG_WRITE_pHYs_SUPPORTED) |
|---|
| 695 | { |
|---|
| 696 | png_uint_32 res_x, res_y; |
|---|
| 697 | int unit_type; |
|---|
| 698 | |
|---|
| 699 | if (png_get_pHYs(read_ptr, read_info_ptr, &res_x, &res_y, &unit_type)) |
|---|
| 700 | { |
|---|
| 701 | png_set_pHYs(write_ptr, write_info_ptr, res_x, res_y, unit_type); |
|---|
| 702 | } |
|---|
| 703 | } |
|---|
| 704 | #endif |
|---|
| 705 | { |
|---|
| 706 | png_colorp palette; |
|---|
| 707 | int num_palette; |
|---|
| 708 | |
|---|
| 709 | if (png_get_PLTE(read_ptr, read_info_ptr, &palette, &num_palette)) |
|---|
| 710 | { |
|---|
| 711 | png_set_PLTE(write_ptr, write_info_ptr, palette, num_palette); |
|---|
| 712 | } |
|---|
| 713 | } |
|---|
| 714 | #if defined(PNG_READ_sBIT_SUPPORTED) && defined(PNG_WRITE_sBIT_SUPPORTED) |
|---|
| 715 | { |
|---|
| 716 | png_color_8p sig_bit; |
|---|
| 717 | |
|---|
| 718 | if (png_get_sBIT(read_ptr, read_info_ptr, &sig_bit)) |
|---|
| 719 | { |
|---|
| 720 | png_set_sBIT(write_ptr, write_info_ptr, sig_bit); |
|---|
| 721 | } |
|---|
| 722 | } |
|---|
| 723 | #endif |
|---|
| 724 | #if (defined(PNG_READ_tEXt_SUPPORTED) && defined(PNG_WRITE_tEXt_SUPPORTED)) || \ |
|---|
| 725 | (defined(PNG_READ_zTXt_SUPPORTED) && defined(PNG_WRITE_zTXt_SUPPORTED)) |
|---|
| 726 | { |
|---|
| 727 | png_textp text_ptr; |
|---|
| 728 | int num_text; |
|---|
| 729 | |
|---|
| 730 | if (png_get_text(read_ptr, read_info_ptr, &text_ptr, &num_text) > 0) |
|---|
| 731 | { |
|---|
| 732 | png_debug1(0, "Handling %d tEXt/zTXt chunks\n", num_text); |
|---|
| 733 | png_set_text(write_ptr, write_info_ptr, text_ptr, num_text); |
|---|
| 734 | } |
|---|
| 735 | } |
|---|
| 736 | #endif |
|---|
| 737 | #if defined(PNG_READ_tIME_SUPPORTED) && defined(PNG_WRITE_tIME_SUPPORTED) |
|---|
| 738 | { |
|---|
| 739 | png_timep mod_time; |
|---|
| 740 | |
|---|
| 741 | if (png_get_tIME(read_ptr, read_info_ptr, &mod_time)) |
|---|
| 742 | { |
|---|
| 743 | png_set_tIME(write_ptr, write_info_ptr, mod_time); |
|---|
| 744 | } |
|---|
| 745 | #if defined(PNG_TIME_RFC1123_SUPPORTED) |
|---|
| 746 | { |
|---|
| 747 | /* we have to use png_strcpy instead of "=" because the string |
|---|
| 748 | pointed to by png_convert_to_rfc1123() gets free'ed before |
|---|
| 749 | we use it */ |
|---|
| 750 | png_strcpy(tIME_string,png_convert_to_rfc1123(read_ptr, mod_time)); |
|---|
| 751 | tIME_chunk_present++; |
|---|
| 752 | } |
|---|
| 753 | #endif /* PNG_TIME_RFC1123_SUPPORTED */ |
|---|
| 754 | } |
|---|
| 755 | #endif |
|---|
| 756 | #if defined(PNG_READ_tRNS_SUPPORTED) && defined(PNG_WRITE_tRNS_SUPPORTED) |
|---|
| 757 | { |
|---|
| 758 | png_bytep trans; |
|---|
| 759 | int num_trans; |
|---|
| 760 | png_color_16p trans_values; |
|---|
| 761 | |
|---|
| 762 | if (png_get_tRNS(read_ptr, read_info_ptr, &trans, &num_trans, |
|---|
| 763 | &trans_values)) |
|---|
| 764 | { |
|---|
| 765 | png_set_tRNS(write_ptr, write_info_ptr, trans, num_trans, |
|---|
| 766 | trans_values); |
|---|
| 767 | } |
|---|
| 768 | } |
|---|
| 769 | #endif |
|---|
| 770 | |
|---|
| 771 | png_debug(0, "\nWriting info struct\n"); |
|---|
| 772 | png_write_info(write_ptr, write_info_ptr); |
|---|
| 773 | |
|---|
| 774 | png_debug(0, "\nAllocating row buffer \n"); |
|---|
| 775 | row_buf = (png_bytep)png_malloc(read_ptr, |
|---|
| 776 | png_get_rowbytes(read_ptr, read_info_ptr)); |
|---|
| 777 | if (row_buf == NULL) |
|---|
| 778 | { |
|---|
| 779 | fprintf(STDERR, "No memory to allocate row buffer\n"); |
|---|
| 780 | png_destroy_read_struct(&read_ptr, &read_info_ptr, (png_infopp)NULL); |
|---|
| 781 | png_destroy_write_struct(&write_ptr, &write_info_ptr); |
|---|
| 782 | fclose(fpin); |
|---|
| 783 | fclose(fpout); |
|---|
| 784 | return (1); |
|---|
| 785 | } |
|---|
| 786 | png_debug(0, "Writing row data\n"); |
|---|
| 787 | |
|---|
| 788 | num_pass = png_set_interlace_handling(read_ptr); |
|---|
| 789 | png_set_interlace_handling(write_ptr); |
|---|
| 790 | |
|---|
| 791 | for (pass = 0; pass < num_pass; pass++) |
|---|
| 792 | { |
|---|
| 793 | png_debug1(0, "Writing row data for pass %d\n",pass); |
|---|
| 794 | for (y = 0; y < height; y++) |
|---|
| 795 | { |
|---|
| 796 | png_read_rows(read_ptr, (png_bytepp)&row_buf, (png_bytepp)NULL, 1); |
|---|
| 797 | png_write_rows(write_ptr, (png_bytepp)&row_buf, 1); |
|---|
| 798 | } |
|---|
| 799 | } |
|---|
| 800 | |
|---|
| 801 | png_debug(0, "Reading and writing end_info data\n"); |
|---|
| 802 | png_read_end(read_ptr, end_info_ptr); |
|---|
| 803 | png_write_end(write_ptr, end_info_ptr); |
|---|
| 804 | |
|---|
| 805 | #ifdef PNG_EASY_ACCESS_SUPPORTED |
|---|
| 806 | if(verbose) |
|---|
| 807 | { |
|---|
| 808 | png_uint_32 iwidth, iheight; |
|---|
| 809 | iwidth = png_get_image_width(write_ptr, write_info_ptr); |
|---|
| 810 | iheight = png_get_image_height(write_ptr, write_info_ptr); |
|---|
| 811 | fprintf(STDERR, "Image width = %lu, height = %lu\n", |
|---|
| 812 | iwidth, iheight); |
|---|
| 813 | } |
|---|
| 814 | #endif |
|---|
| 815 | |
|---|
| 816 | png_debug(0, "Destroying data structs\n"); |
|---|
| 817 | png_free(read_ptr, row_buf); |
|---|
| 818 | png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr); |
|---|
| 819 | png_destroy_write_struct(&write_ptr, &write_info_ptr); |
|---|
| 820 | |
|---|
| 821 | fclose(fpin); |
|---|
| 822 | fclose(fpout); |
|---|
| 823 | |
|---|
| 824 | png_debug(0, "Opening files for comparison\n"); |
|---|
| 825 | if ((fpin = fopen(inname, "rb")) == NULL) |
|---|
| 826 | { |
|---|
| 827 | fprintf(STDERR, "Could not find file %s\n", inname); |
|---|
| 828 | return (1); |
|---|
| 829 | } |
|---|
| 830 | |
|---|
| 831 | if ((fpout = fopen(outname, "rb")) == NULL) |
|---|
| 832 | { |
|---|
| 833 | fprintf(STDERR, "Could not find file %s\n", outname); |
|---|
| 834 | fclose(fpin); |
|---|
| 835 | return (1); |
|---|
| 836 | } |
|---|
| 837 | |
|---|
| 838 | for(;;) |
|---|
| 839 | { |
|---|
| 840 | png_size_t num_in, num_out; |
|---|
| 841 | |
|---|
| 842 | num_in = fread(inbuf, 1, 1, fpin); |
|---|
| 843 | num_out = fread(outbuf, 1, 1, fpout); |
|---|
| 844 | |
|---|
| 845 | if (num_in != num_out) |
|---|
| 846 | { |
|---|
| 847 | fprintf(STDERR, "Files %s and %s are of a different size\n", |
|---|
| 848 | inname, outname); |
|---|
| 849 | if(wrote_question == 0) |
|---|
| 850 | { |
|---|
| 851 | fprintf(STDERR, |
|---|
| 852 | " Was %s written with the same chunk size (8k),",inname); |
|---|
| 853 | fprintf(STDERR, |
|---|
| 854 | " filtering\n heuristic (libpng default), compression"); |
|---|
| 855 | fprintf(STDERR, |
|---|
| 856 | " level (zlib default)\n and zlib version (%s)?\n\n", |
|---|
| 857 | ZLIB_VERSION); |
|---|
| 858 | wrote_question=1; |
|---|
| 859 | } |
|---|
| 860 | fclose(fpin); |
|---|
| 861 | fclose(fpout); |
|---|
| 862 | return (0); |
|---|
| 863 | } |
|---|
| 864 | |
|---|
| 865 | if (!num_in) |
|---|
| 866 | break; |
|---|
| 867 | |
|---|
| 868 | if (png_memcmp(inbuf, outbuf, num_in)) |
|---|
| 869 | { |
|---|
| 870 | fprintf(STDERR, "Files %s and %s are different\n", inname, outname); |
|---|
| 871 | if(wrote_question == 0) |
|---|
| 872 | { |
|---|
| 873 | fprintf(STDERR, |
|---|
| 874 | " Was %s written with the same chunk size (8k),",inname); |
|---|
| 875 | fprintf(STDERR, |
|---|
| 876 | " filtering\n heuristic (libpng default), compression"); |
|---|
| 877 | fprintf(STDERR, |
|---|
| 878 | " level (zlib default)\n and zlib version (%s)?\n\n", |
|---|
| 879 | ZLIB_VERSION); |
|---|
| 880 | wrote_question=1; |
|---|
| 881 | } |
|---|
| 882 | fclose(fpin); |
|---|
| 883 | fclose(fpout); |
|---|
| 884 | return (0); |
|---|
| 885 | } |
|---|
| 886 | } |
|---|
| 887 | |
|---|
| 888 | fclose(fpin); |
|---|
| 889 | fclose(fpout); |
|---|
| 890 | |
|---|
| 891 | return (0); |
|---|
| 892 | } |
|---|
| 893 | |
|---|
| 894 | /* input and output filenames */ |
|---|
| 895 | #ifdef RISCOS |
|---|
| 896 | PNG_CONST char *inname = "pngtest/png"; |
|---|
| 897 | PNG_CONST char *outname = "pngout/png"; |
|---|
| 898 | #else |
|---|
| 899 | static PNG_CONST char *inname = "pngtest.png"; |
|---|
| 900 | static PNG_CONST char *outname = "pngout.png"; |
|---|
| 901 | #endif |
|---|
| 902 | |
|---|
| 903 | int |
|---|
| 904 | main(int argc, char *argv[]) |
|---|
| 905 | { |
|---|
| 906 | int multiple = 0; |
|---|
| 907 | int ierror = 0; |
|---|
| 908 | |
|---|
| 909 | fprintf(STDERR, "Testing libpng version %s\n", PNG_LIBPNG_VER_STRING); |
|---|
| 910 | fprintf(STDERR, " with zlib version %s\n", ZLIB_VERSION); |
|---|
| 911 | |
|---|
| 912 | /* Do some consistency checking on the memory allocation settings, I'm |
|---|
| 913 | not sure this matters, but it is nice to know, the first of these |
|---|
| 914 | tests should be impossible because of the way the macros are set |
|---|
| 915 | in pngconf.h */ |
|---|
| 916 | #if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K) |
|---|
| 917 | fprintf(STDERR, " NOTE: Zlib compiled for max 64k, libpng not\n"); |
|---|
| 918 | #endif |
|---|
| 919 | /* I think the following can happen. */ |
|---|
| 920 | #if !defined(MAXSEG_64K) && defined(PNG_MAX_MALLOC_64K) |
|---|
| 921 | fprintf(STDERR, " NOTE: libpng compiled for max 64k, zlib not\n"); |
|---|
| 922 | #endif |
|---|
| 923 | |
|---|
| 924 | if (strcmp(png_libpng_ver, PNG_LIBPNG_VER_STRING)) |
|---|
| 925 | { |
|---|
| 926 | fprintf(STDERR, |
|---|
| 927 | "Warning: versions are different between png.h and png.c\n"); |
|---|
| 928 | fprintf(STDERR, " png.h version: %s\n", PNG_LIBPNG_VER_STRING); |
|---|
| 929 | fprintf(STDERR, " png.c version: %s\n\n", png_libpng_ver); |
|---|
| 930 | ++ierror; |
|---|
| 931 | } |
|---|
| 932 | |
|---|
| 933 | if (argc > 1) |
|---|
| 934 | { |
|---|
| 935 | if (strcmp(argv[1], "-m") == 0) |
|---|
| 936 | { |
|---|
| 937 | multiple = 1; |
|---|
| 938 | status_dots_requested = 0; |
|---|
| 939 | } |
|---|
| 940 | else if (strcmp(argv[1], "-mv") == 0 || |
|---|
| 941 | strcmp(argv[1], "-vm") == 0 ) |
|---|
| 942 | { |
|---|
| 943 | multiple = 1; |
|---|
| 944 | verbose = 1; |
|---|
| 945 | status_dots_requested = 1; |
|---|
| 946 | } |
|---|
| 947 | else if (strcmp(argv[1], "-v") == 0) |
|---|
| 948 | { |
|---|
| 949 | verbose = 1; |
|---|
| 950 | status_dots_requested = 1; |
|---|
| 951 | inname = argv[2]; |
|---|
| 952 | } |
|---|
| 953 | else |
|---|
| 954 | { |
|---|
| 955 | inname = argv[1]; |
|---|
| 956 | status_dots_requested = 0; |
|---|
| 957 | } |
|---|
| 958 | } |
|---|
| 959 | |
|---|
| 960 | if (!multiple && argc == 3+verbose) |
|---|
| 961 | outname = argv[2+verbose]; |
|---|
| 962 | |
|---|
| 963 | if ((!multiple && argc > 3+verbose) || (multiple && argc < 2)) |
|---|
| 964 | { |
|---|
| 965 | fprintf(STDERR, |
|---|
| 966 | "usage: %s [infile.png] [outfile.png]\n\t%s -m {infile.png}\n", |
|---|
| 967 | argv[0], argv[0]); |
|---|
| 968 | fprintf(STDERR, |
|---|
| 969 | " reads/writes one PNG file (without -m) or multiple files (-m)\n"); |
|---|
| 970 | fprintf(STDERR, |
|---|
| 971 | " with -m %s is used as a temporary file\n", outname); |
|---|
| 972 | exit(1); |
|---|
| 973 | } |
|---|
| 974 | |
|---|
| 975 | if (multiple) |
|---|
| 976 | { |
|---|
| 977 | int i; |
|---|
| 978 | #ifdef PNG_USER_MEM_SUPPORTED |
|---|
| 979 | int allocation_now = current_allocation; |
|---|
| 980 | #endif |
|---|
| 981 | for (i=2; i<argc; ++i) |
|---|
| 982 | { |
|---|
| 983 | int kerror; |
|---|
| 984 | fprintf(STDERR, "Testing %s:",argv[i]); |
|---|
| 985 | kerror = test_one_file(argv[i], outname); |
|---|
| 986 | if (kerror == 0) |
|---|
| 987 | { |
|---|
| 988 | #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) |
|---|
| 989 | fprintf(STDERR, " PASS (%lu zero samples)\n",zero_samples); |
|---|
| 990 | #else |
|---|
| 991 | fprintf(STDERR, " PASS\n"); |
|---|
| 992 | #endif |
|---|
| 993 | #if defined(PNG_TIME_RFC1123_SUPPORTED) |
|---|
| 994 | if(tIME_chunk_present != 0) |
|---|
| 995 | fprintf(STDERR, " tIME = %s\n",tIME_string); |
|---|
| 996 | tIME_chunk_present = 0; |
|---|
| 997 | #endif /* PNG_TIME_RFC1123_SUPPORTED */ |
|---|
| 998 | } |
|---|
| 999 | else |
|---|
| 1000 | { |
|---|
| 1001 | fprintf(STDERR, " FAIL\n"); |
|---|
| 1002 | ierror += kerror; |
|---|
| 1003 | } |
|---|
| 1004 | #ifdef PNG_USER_MEM_SUPPORTED |
|---|
| 1005 | if (allocation_now != current_allocation) |
|---|
| 1006 | fprintf(STDERR, "MEMORY ERROR: %d bytes lost\n", |
|---|
| 1007 | current_allocation-allocation_now); |
|---|
| 1008 | if (current_allocation != 0) { |
|---|
| 1009 | memory_infop pinfo = pinformation; |
|---|
| 1010 | |
|---|
| 1011 | fprintf(STDERR, "MEMORY ERROR: %d bytes still allocated\n", |
|---|
| 1012 | current_allocation); |
|---|
| 1013 | while (pinfo != NULL) { |
|---|
| 1014 | fprintf(STDERR, " %d bytes at %x\n", pinfo->size, pinfo->pointer); |
|---|
| 1015 | pinfo = pinfo->next; |
|---|
| 1016 | } |
|---|
| 1017 | } |
|---|
| 1018 | #endif |
|---|
| 1019 | } |
|---|
| 1020 | #ifdef PNG_USER_MEM_SUPPORTED |
|---|
| 1021 | fprintf(STDERR, "Maximum memory allocation: %d bytes\n", |
|---|
| 1022 | maximum_allocation); |
|---|
| 1023 | #endif |
|---|
| 1024 | } |
|---|
| 1025 | else |
|---|
| 1026 | { |
|---|
| 1027 | int i; |
|---|
| 1028 | for (i=0; i<3; ++i) { |
|---|
| 1029 | int kerror; |
|---|
| 1030 | #ifdef PNG_USER_MEM_SUPPORTED |
|---|
| 1031 | int allocation_now = current_allocation; |
|---|
| 1032 | #endif |
|---|
| 1033 | if (i == 1) status_dots_requested = 1; |
|---|
| 1034 | else if(verbose == 0)status_dots_requested = 0; |
|---|
| 1035 | if (i == 0 || verbose == 1 || ierror != 0) |
|---|
| 1036 | fprintf(STDERR, "Testing %s:",inname); |
|---|
| 1037 | kerror = test_one_file(inname, outname); |
|---|
| 1038 | if(kerror == 0) |
|---|
| 1039 | { |
|---|
| 1040 | if(verbose == 1 || i == 2) |
|---|
| 1041 | { |
|---|
| 1042 | #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) |
|---|
| 1043 | fprintf(STDERR, " PASS (%lu zero samples)\n",zero_samples); |
|---|
| 1044 | #else |
|---|
| 1045 | fprintf(STDERR, " PASS\n"); |
|---|
| 1046 | #endif |
|---|
| 1047 | #if defined(PNG_TIME_RFC1123_SUPPORTED) |
|---|
| 1048 | if(tIME_chunk_present != 0) |
|---|
| 1049 | fprintf(STDERR, " tIME = %s\n",tIME_string); |
|---|
| 1050 | #endif /* PNG_TIME_RFC1123_SUPPORTED */ |
|---|
| 1051 | } |
|---|
| 1052 | } |
|---|
| 1053 | else |
|---|
| 1054 | { |
|---|
| 1055 | if(verbose == 0 && i != 2) |
|---|
| 1056 | fprintf(STDERR, "Testing %s:",inname); |
|---|
| 1057 | fprintf(STDERR, " FAIL\n"); |
|---|
| 1058 | ierror += kerror; |
|---|
| 1059 | } |
|---|
| 1060 | #ifdef PNG_USER_MEM_SUPPORTED |
|---|
| 1061 | if (allocation_now != current_allocation) |
|---|
| 1062 | fprintf(STDERR, "MEMORY ERROR: %d bytes lost\n", |
|---|
| 1063 | current_allocation-allocation_now); |
|---|
| 1064 | if (current_allocation != 0) { |
|---|
| 1065 | memory_infop pinfo = pinformation; |
|---|
| 1066 | |
|---|
| 1067 | fprintf(STDERR, "MEMORY ERROR: %d bytes still allocated\n", |
|---|
| 1068 | current_allocation); |
|---|
| 1069 | while (pinfo != NULL) { |
|---|
| 1070 | fprintf(STDERR, " %d bytes at %x\n", pinfo->size, pinfo->pointer); |
|---|
| 1071 | pinfo = pinfo->next; |
|---|
| 1072 | } |
|---|
| 1073 | } |
|---|
| 1074 | #endif |
|---|
| 1075 | } |
|---|
| 1076 | #ifdef PNG_USER_MEM_SUPPORTED |
|---|
| 1077 | fprintf(STDERR, "Maximum memory allocation: %d bytes\n", |
|---|
| 1078 | maximum_allocation); |
|---|
| 1079 | #endif |
|---|
| 1080 | } |
|---|
| 1081 | |
|---|
| 1082 | if (ierror == 0) |
|---|
| 1083 | fprintf(STDERR, "libpng passes test\n"); |
|---|
| 1084 | else |
|---|
| 1085 | fprintf(STDERR, "libpng FAILS test\n"); |
|---|
| 1086 | return (int)(ierror != 0); |
|---|
| 1087 | } |
|---|
| 1088 | |
|---|