2 /* pngtest.c - a simple test program to test libpng
4 * Last changed in libpng 1.4.1 [February 25, 2010]
5 * Copyright (c) 1998-2010 Glenn Randers-Pehrson
6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
9 * This code is released under the libpng license.
10 * For conditions of distribution and use, see the disclaimer
11 * and license in png.h
13 * This program reads in a PNG image, writes it out again, and then
14 * compares the two files. If the files are identical, this shows that
15 * the basic chunk handling, filtering, and (de)compression code is working
16 * properly. It does not currently test all of the transforms, although
19 * The program will report "FAIL" in certain legitimate cases:
20 * 1) when the compression level or filter selection method is changed.
21 * 2) when the maximum IDAT size (PNG_ZBUF_SIZE in pngconf.h) is not 8192.
22 * 3) unknown unsafe-to-copy ancillary chunks or unknown critical chunks
23 * exist in the input file.
24 * 4) others not listed here...
25 * In these cases, it is best to check with another tool such as "pngcheck"
26 * to see what the differences between the two files are.
28 * If a filename is given on the command-line, then this file is used
29 * for the input, rather than the default "pngtest.png". This allows
30 * testing a wide variety of files easily. You can also test a number
31 * of files at once by typing "pngtest -m file1.png file2.png ..."
39 # define FCLOSE(file) fclose(file)
41 #ifndef PNG_STDIO_SUPPORTED
42 typedef FILE * png_FILE_p
;
45 /* Makes pngtest verbose so we can find problems (needs to be before png.h) */
51 # define SINGLE_ROWBUF_ALLOC /* Makes buffer overruns easier to nail */
55 #define PNGTEST_TIMING
58 #ifndef PNG_FLOATING_POINT_SUPPORTED
63 static float t_start
, t_stop
, t_decode
, t_encode
, t_misc
;
67 #ifdef PNG_TIME_RFC1123_SUPPORTED
68 #define PNG_tIME_STRING_LENGTH 29
69 static int tIME_chunk_present
= 0;
70 static char tIME_string
[PNG_tIME_STRING_LENGTH
] = "tIME chunk is not present";
73 static int verbose
= 0;
75 int test_one_file
PNGARG((PNG_CONST
char *inname
, PNG_CONST
char *outname
));
81 /* Defined so I can write to a file on gui/windowing platforms */
82 /* #define STDERR stderr */
83 #define STDERR stdout /* For DOS */
85 /* In case a system header (e.g., on AIX) defined jmpbuf */
90 /* Define png_jmpbuf() in case we are using a pre-1.0.6 version of libpng */
92 # define png_jmpbuf(png_ptr) png_ptr->jmpbuf
95 /* Example of using row callbacks to make a simple progress meter */
96 static int status_pass
= 1;
97 static int status_dots_requested
= 0;
98 static int status_dots
= 1;
101 read_row_callback(png_structp png_ptr
, png_uint_32 row_number
, int pass
);
103 read_row_callback(png_structp png_ptr
, png_uint_32 row_number
, int pass
)
105 if (png_ptr
== NULL
|| row_number
> PNG_UINT_31_MAX
)
107 if (status_pass
!= pass
)
109 fprintf(stdout
, "\n Pass %d: ", pass
);
114 if (status_dots
== 0)
116 fprintf(stdout
, "\n ");
119 fprintf(stdout
, "r");
123 write_row_callback(png_structp png_ptr
, png_uint_32 row_number
, int pass
);
125 write_row_callback(png_structp png_ptr
, png_uint_32 row_number
, int pass
)
127 if (png_ptr
== NULL
|| row_number
> PNG_UINT_31_MAX
|| pass
> 7)
129 fprintf(stdout
, "w");
133 #ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
134 /* Example of using user transform callback (we don't transform anything,
135 * but merely examine the row filters. We set this to 256 rather than
136 * 5 in case illegal filter values are present.)
138 static png_uint_32 filters_used
[256];
140 count_filters(png_structp png_ptr
, png_row_infop row_info
, png_bytep data
);
142 count_filters(png_structp png_ptr
, png_row_infop row_info
, png_bytep data
)
144 if (png_ptr
!= NULL
&& row_info
!= NULL
)
145 ++filters_used
[*(data
- 1)];
149 #ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
150 /* Example of using user transform callback (we don't transform anything,
151 * but merely count the zero samples)
154 static png_uint_32 zero_samples
;
157 count_zero_samples(png_structp png_ptr
, png_row_infop row_info
, png_bytep data
);
159 count_zero_samples(png_structp png_ptr
, png_row_infop row_info
, png_bytep data
)
162 if (png_ptr
== NULL
)return;
164 /* Contents of row_info:
165 * png_uint_32 width width of row
166 * png_uint_32 rowbytes number of bytes in row
167 * png_byte color_type color type of pixels
168 * png_byte bit_depth bit depth of samples
169 * png_byte channels number of channels (1-4)
170 * png_byte pixel_depth bits per pixel (depth*channels)
173 /* Counts the number of zero samples (or zero pixels if color_type is 3 */
175 if (row_info
->color_type
== 0 || row_info
->color_type
== 3)
178 png_uint_32 n
, nstop
;
179 for (n
= 0, nstop
=row_info
->width
; n
<nstop
; n
++)
181 if (row_info
->bit_depth
== 1)
183 if (((*dp
<< pos
++ ) & 0x80) == 0)
191 if (row_info
->bit_depth
== 2)
193 if (((*dp
<< (pos
+=2)) & 0xc0) == 0)
201 if (row_info
->bit_depth
== 4)
203 if (((*dp
<< (pos
+=4)) & 0xf0) == 0)
211 if (row_info
->bit_depth
== 8)
214 if (row_info
->bit_depth
== 16)
216 if ((*dp
| *(dp
+1)) == 0)
222 else /* Other color types */
224 png_uint_32 n
, nstop
;
226 int color_channels
= row_info
->channels
;
227 if (row_info
->color_type
> 3)color_channels
--;
229 for (n
= 0, nstop
=row_info
->width
; n
<nstop
; n
++)
231 for (channel
= 0; channel
< color_channels
; channel
++)
233 if (row_info
->bit_depth
== 8)
236 if (row_info
->bit_depth
== 16)
238 if ((*dp
| *(dp
+1)) == 0)
243 if (row_info
->color_type
> 3)
246 if (row_info
->bit_depth
== 16)
252 #endif /* PNG_WRITE_USER_TRANSFORM_SUPPORTED */
254 static int wrote_question
= 0;
256 #ifndef PNG_STDIO_SUPPORTED
257 /* START of code to validate stdio-free compilation */
258 /* These copies of the default read/write functions come from pngrio.c and
259 * pngwio.c. They allow "don't include stdio" testing of the library.
260 * This is the function that does the actual reading of data. If you are
261 * not reading from a standard C stream, you should create a replacement
262 * read_data function and use it at run time with png_set_read_fn(), rather
263 * than changing the library.
266 #ifndef USE_FAR_KEYWORD
268 pngtest_read_data(png_structp png_ptr
, png_bytep data
, png_size_t length
)
270 png_size_t check
= 0;
273 /* fread() returns 0 on error, so it is OK to store this in a png_size_t
274 * instead of an int, which is what fread() actually returns.
276 io_ptr
= png_get_io_ptr(png_ptr
);
279 check
= fread(data
, 1, length
, (png_FILE_p
)io_ptr
);
284 png_error(png_ptr
, "Read Error!");
288 /* This is the model-independent version. Since the standard I/O library
289 can't handle far buffers in the medium and small models, we have to copy
293 #define NEAR_BUF_SIZE 1024
294 #define MIN(a,b) (a <= b ? a : b)
297 pngtest_read_data(png_structp png_ptr
, png_bytep data
, png_size_t length
)
303 /* Check if data really is near. If so, use usual code. */
304 n_data
= (png_byte
*)CVT_PTR_NOCHECK(data
);
305 io_ptr
= (png_FILE_p
)CVT_PTR(png_get_io_ptr(png_ptr
));
306 if ((png_bytep
)n_data
== data
)
308 check
= fread(n_data
, 1, length
, io_ptr
);
312 png_byte buf
[NEAR_BUF_SIZE
];
313 png_size_t read
, remaining
, err
;
318 read
= MIN(NEAR_BUF_SIZE
, remaining
);
319 err
= fread(buf
, 1, 1, io_ptr
);
320 png_memcpy(data
, buf
, read
); /* Copy far buffer to near buffer */
328 while (remaining
!= 0);
331 png_error(png_ptr
, "read Error");
333 #endif /* USE_FAR_KEYWORD */
335 #ifdef PNG_WRITE_FLUSH_SUPPORTED
337 pngtest_flush(png_structp png_ptr
)
339 /* Do nothing; fflush() is said to be just a waste of energy. */
340 png_ptr
= png_ptr
; /* Stifle compiler warning */
344 /* This is the function that does the actual writing of data. If you are
345 * not writing to a standard C stream, you should create a replacement
346 * write_data function and use it at run time with png_set_write_fn(), rather
347 * than changing the library.
349 #ifndef USE_FAR_KEYWORD
351 pngtest_write_data(png_structp png_ptr
, png_bytep data
, png_size_t length
)
355 io_ptr
= (png_FILE_p
)CVT_PTR(png_get_io_ptr(png_ptr
));
357 check
= fwrite(data
, 1, length
, io_ptr
);
360 png_error(png_ptr
, "Write Error");
364 /* This is the model-independent version. Since the standard I/O library
365 can't handle far buffers in the medium and small models, we have to copy
369 #define NEAR_BUF_SIZE 1024
370 #define MIN(a,b) (a <= b ? a : b)
373 pngtest_write_data(png_structp png_ptr
, png_bytep data
, png_size_t length
)
376 png_byte
*near_data
; /* Needs to be "png_byte *" instead of "png_bytep" */
379 /* Check if data really is near. If so, use usual code. */
380 near_data
= (png_byte
*)CVT_PTR_NOCHECK(data
);
381 io_ptr
= (png_FILE_p
)CVT_PTR(png_ptr
->io_ptr
);
382 if ((png_bytep
)near_data
== data
)
384 check
= fwrite(near_data
, 1, length
, io_ptr
);
388 png_byte buf
[NEAR_BUF_SIZE
];
389 png_size_t written
, remaining
, err
;
394 written
= MIN(NEAR_BUF_SIZE
, remaining
);
395 png_memcpy(buf
, data
, written
); /* Copy far buffer to near buffer */
396 err
= fwrite(buf
, 1, written
, io_ptr
);
402 remaining
-= written
;
404 while (remaining
!= 0);
408 png_error(png_ptr
, "Write Error");
411 #endif /* USE_FAR_KEYWORD */
413 /* This function is called when there is a warning, but the library thinks
414 * it can continue anyway. Replacement functions don't have to do anything
415 * here if you don't want to. In the default configuration, png_ptr is
416 * not used, but it is passed in case it may be useful.
419 pngtest_warning(png_structp png_ptr
, png_const_charp message
)
421 PNG_CONST
char *name
= "UNKNOWN (ERROR!)";
423 test
= png_get_error_ptr(png_ptr
);
425 fprintf(STDERR
, "%s: libpng warning: %s\n", name
, message
);
427 fprintf(STDERR
, "%s: libpng warning: %s\n", test
, message
);
430 /* This is the default error handling function. Note that replacements for
431 * this function MUST NOT RETURN, or the program will likely crash. This
432 * function is used by default, or if the program supplies NULL for the
433 * error function pointer in png_set_error_fn().
436 pngtest_error(png_structp png_ptr
, png_const_charp message
)
438 pngtest_warning(png_ptr
, message
);
439 /* We can return because png_error calls the default handler, which is
440 * actually OK in this case.
443 #endif /* !PNG_STDIO_SUPPORTED */
444 /* END of code to validate stdio-free compilation */
446 /* START of code to validate memory allocation and deallocation */
447 #if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
449 /* Allocate memory. For reasonable files, size should never exceed
450 * 64K. However, zlib may allocate more then 64K if you don't tell
451 * it not to. See zconf.h and png.h for more information. zlib does
452 * need to allocate exactly 64K, so whatever you call here must
453 * have the ability to do that.
455 * This piece of code can be compiled to validate max 64K allocations
456 * by setting MAXSEG_64K in zlib zconf.h *or* PNG_MAX_MALLOC_64K.
458 typedef struct memory_information
460 png_alloc_size_t size
;
462 struct memory_information FAR
*next
;
463 } memory_information
;
464 typedef memory_information FAR
*memory_infop
;
466 static memory_infop pinformation
= NULL
;
467 static int current_allocation
= 0;
468 static int maximum_allocation
= 0;
469 static int total_allocation
= 0;
470 static int num_allocations
= 0;
472 png_voidp png_debug_malloc
473 PNGARG((png_structp png_ptr
, png_alloc_size_t size
));
474 void png_debug_free
PNGARG((png_structp png_ptr
, png_voidp ptr
));
477 png_debug_malloc(png_structp png_ptr
, png_alloc_size_t size
)
480 /* png_malloc has already tested for NULL; png_create_struct calls
481 * png_debug_malloc directly, with png_ptr == NULL which is OK
487 /* This calls the library allocator twice, once to get the requested
488 buffer and once to get a new free list entry. */
490 /* Disable malloc_fn and free_fn */
492 png_set_mem_fn(png_ptr
, NULL
, NULL
, NULL
);
493 pinfo
= (memory_infop
)png_malloc(png_ptr
,
496 current_allocation
+= size
;
497 total_allocation
+= size
;
499 if (current_allocation
> maximum_allocation
)
500 maximum_allocation
= current_allocation
;
501 pinfo
->pointer
= png_malloc(png_ptr
, size
);
502 /* Restore malloc_fn and free_fn */
503 png_set_mem_fn(png_ptr
,
504 NULL
, png_debug_malloc
, png_debug_free
);
505 if (size
!= 0 && pinfo
->pointer
== NULL
)
507 current_allocation
-= size
;
508 total_allocation
-= size
;
510 "out of memory in pngtest->png_debug_malloc");
512 pinfo
->next
= pinformation
;
513 pinformation
= pinfo
;
514 /* Make sure the caller isn't assuming zeroed memory. */
515 png_memset(pinfo
->pointer
, 0xdd, pinfo
->size
);
517 printf("png_malloc %lu bytes at %x\n", (unsigned long)size
,
519 return (png_voidp
)(pinfo
->pointer
);
523 /* Free a pointer. It is removed from the list at the same time. */
525 png_debug_free(png_structp png_ptr
, png_voidp ptr
)
528 fprintf(STDERR
, "NULL pointer to png_debug_free.\n");
531 #if 0 /* This happens all the time. */
532 fprintf(STDERR
, "WARNING: freeing NULL pointer\n");
537 /* Unlink the element from the list. */
539 memory_infop FAR
*ppinfo
= &pinformation
;
542 memory_infop pinfo
= *ppinfo
;
543 if (pinfo
->pointer
== ptr
)
545 *ppinfo
= pinfo
->next
;
546 current_allocation
-= pinfo
->size
;
547 if (current_allocation
< 0)
548 fprintf(STDERR
, "Duplicate free of memory\n");
549 /* We must free the list element too, but first kill
550 the memory that is to be freed. */
551 png_memset(ptr
, 0x55, pinfo
->size
);
552 png_free_default(png_ptr
, pinfo
);
556 if (pinfo
->next
== NULL
)
558 fprintf(STDERR
, "Pointer %x not found\n", (unsigned int)ptr
);
561 ppinfo
= &pinfo
->next
;
565 /* Finally free the data. */
567 printf("Freeing %x\n", ptr
);
568 png_free_default(png_ptr
, ptr
);
571 #endif /* PNG_USER_MEM_SUPPORTED && PNG_DEBUG */
572 /* END of code to test memory allocation/deallocation */
575 /* Demonstration of user chunk support of the sTER and vpAg chunks */
576 #ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
578 /* (sTER is a public chunk not yet known by libpng. vpAg is a private
579 chunk used in ImageMagick to store "virtual page" size). */
581 static png_uint_32 user_chunk_data
[4];
589 static int read_user_chunk_callback(png_struct
*png_ptr
,
590 png_unknown_chunkp chunk
)
595 /* Return one of the following:
596 * return (-n); chunk had an error
597 * return (0); did not recognize
598 * return (n); success
600 * The unknown chunk structure contains the chunk data:
605 * Note that libpng has already taken care of the CRC handling.
608 if (chunk
->name
[0] == 115 && chunk
->name
[1] == 84 && /* s T */
609 chunk
->name
[2] == 69 && chunk
->name
[3] == 82) /* E R */
611 /* Found sTER chunk */
612 if (chunk
->size
!= 1)
613 return (-1); /* Error return */
614 if (chunk
->data
[0] != 0 && chunk
->data
[0] != 1)
615 return (-1); /* Invalid mode */
616 my_user_chunk_data
=(png_uint_32
*) png_get_user_chunk_ptr(png_ptr
);
617 my_user_chunk_data
[0]=chunk
->data
[0]+1;
621 if (chunk
->name
[0] != 118 || chunk
->name
[1] != 112 || /* v p */
622 chunk
->name
[2] != 65 || chunk
->name
[3] != 103) /* A g */
623 return (0); /* Did not recognize */
625 /* Found ImageMagick vpAg chunk */
627 if (chunk
->size
!= 9)
628 return (-1); /* Error return */
630 my_user_chunk_data
=(png_uint_32
*) png_get_user_chunk_ptr(png_ptr
);
632 my_user_chunk_data
[1]=png_get_uint_31(png_ptr
, chunk
->data
);
633 my_user_chunk_data
[2]=png_get_uint_31(png_ptr
, chunk
->data
+ 4);
634 my_user_chunk_data
[3]=(png_uint_32
)chunk
->data
[8];
640 /* END of code to demonstrate user chunk support */
644 test_one_file(PNG_CONST
char *inname
, PNG_CONST
char *outname
)
646 static png_FILE_p fpin
;
647 static png_FILE_p fpout
; /* "static" prevents setjmp corruption */
648 png_structp read_ptr
;
649 png_infop read_info_ptr
, end_info_ptr
;
650 #ifdef PNG_WRITE_SUPPORTED
651 png_structp write_ptr
;
652 png_infop write_info_ptr
;
653 png_infop write_end_info_ptr
;
655 png_structp write_ptr
= NULL
;
656 png_infop write_info_ptr
= NULL
;
657 png_infop write_end_info_ptr
= NULL
;
661 png_uint_32 width
, height
;
663 int bit_depth
, color_type
;
664 #ifdef PNG_SETJMP_SUPPORTED
665 #ifdef USE_FAR_KEYWORD
670 char inbuf
[256], outbuf
[256];
674 if ((fpin
= fopen(inname
, "rb")) == NULL
)
676 fprintf(STDERR
, "Could not find input file %s\n", inname
);
680 if ((fpout
= fopen(outname
, "wb")) == NULL
)
682 fprintf(STDERR
, "Could not open output file %s\n", outname
);
687 png_debug(0, "Allocating read and write structures");
688 #if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
690 png_create_read_struct_2(PNG_LIBPNG_VER_STRING
, NULL
,
692 (png_malloc_ptr
)png_debug_malloc
, (png_free_ptr
)png_debug_free
);
695 png_create_read_struct(PNG_LIBPNG_VER_STRING
, NULL
, NULL
, NULL
);
697 #ifndef PNG_STDIO_SUPPORTED
698 png_set_error_fn(read_ptr
, (png_voidp
)inname
, pngtest_error
,
702 #ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
703 user_chunk_data
[0] = 0;
704 user_chunk_data
[1] = 0;
705 user_chunk_data
[2] = 0;
706 user_chunk_data
[3] = 0;
707 png_set_read_user_chunk_fn(read_ptr
, user_chunk_data
,
708 read_user_chunk_callback
);
711 #ifdef PNG_WRITE_SUPPORTED
712 #if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
714 png_create_write_struct_2(PNG_LIBPNG_VER_STRING
, NULL
,
715 NULL
, NULL
, NULL
, png_debug_malloc
, png_debug_free
);
718 png_create_write_struct(PNG_LIBPNG_VER_STRING
, NULL
, NULL
, NULL
);
720 #ifndef PNG_STDIO_SUPPORTED
721 png_set_error_fn(write_ptr
, (png_voidp
)inname
, pngtest_error
,
725 png_debug(0, "Allocating read_info, write_info and end_info structures");
726 read_info_ptr
= png_create_info_struct(read_ptr
);
727 end_info_ptr
= png_create_info_struct(read_ptr
);
728 #ifdef PNG_WRITE_SUPPORTED
729 write_info_ptr
= png_create_info_struct(write_ptr
);
730 write_end_info_ptr
= png_create_info_struct(write_ptr
);
733 #ifdef PNG_SETJMP_SUPPORTED
734 png_debug(0, "Setting jmpbuf for read struct");
735 #ifdef USE_FAR_KEYWORD
738 if (setjmp(png_jmpbuf(read_ptr
)))
741 fprintf(STDERR
, "%s -> %s: libpng read error\n", inname
, outname
);
742 png_free(read_ptr
, row_buf
);
744 png_destroy_read_struct(&read_ptr
, &read_info_ptr
, &end_info_ptr
);
745 #ifdef PNG_WRITE_SUPPORTED
746 png_destroy_info_struct(write_ptr
, &write_end_info_ptr
);
747 png_destroy_write_struct(&write_ptr
, &write_info_ptr
);
753 #ifdef USE_FAR_KEYWORD
754 png_memcpy(png_jmpbuf(read_ptr
), jmpbuf
, png_sizeof(jmp_buf));
757 #ifdef PNG_WRITE_SUPPORTED
758 png_debug(0, "Setting jmpbuf for write struct");
759 #ifdef USE_FAR_KEYWORD
762 if (setjmp(png_jmpbuf(write_ptr
)))
765 fprintf(STDERR
, "%s -> %s: libpng write error\n", inname
, outname
);
766 png_destroy_read_struct(&read_ptr
, &read_info_ptr
, &end_info_ptr
);
767 png_destroy_info_struct(write_ptr
, &write_end_info_ptr
);
768 #ifdef PNG_WRITE_SUPPORTED
769 png_destroy_write_struct(&write_ptr
, &write_info_ptr
);
775 #ifdef USE_FAR_KEYWORD
776 png_memcpy(png_jmpbuf(write_ptr
), jmpbuf
, png_sizeof(jmp_buf));
781 png_debug(0, "Initializing input and output streams");
782 #ifdef PNG_STDIO_SUPPORTED
783 png_init_io(read_ptr
, fpin
);
784 # ifdef PNG_WRITE_SUPPORTED
785 png_init_io(write_ptr
, fpout
);
788 png_set_read_fn(read_ptr
, (png_voidp
)fpin
, pngtest_read_data
);
789 # ifdef PNG_WRITE_SUPPORTED
790 png_set_write_fn(write_ptr
, (png_voidp
)fpout
, pngtest_write_data
,
791 # ifdef PNG_WRITE_FLUSH_SUPPORTED
798 if (status_dots_requested
== 1)
800 #ifdef PNG_WRITE_SUPPORTED
801 png_set_write_status_fn(write_ptr
, write_row_callback
);
803 png_set_read_status_fn(read_ptr
, read_row_callback
);
807 #ifdef PNG_WRITE_SUPPORTED
808 png_set_write_status_fn(write_ptr
, NULL
);
810 png_set_read_status_fn(read_ptr
, NULL
);
813 #ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
816 for (i
= 0; i
<256; i
++)
818 png_set_read_user_transform_fn(read_ptr
, count_filters
);
821 #ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
823 png_set_write_user_transform_fn(write_ptr
, count_zero_samples
);
826 #ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
827 # ifndef PNG_HANDLE_CHUNK_ALWAYS
828 # define PNG_HANDLE_CHUNK_ALWAYS 3
830 png_set_keep_unknown_chunks(read_ptr
, PNG_HANDLE_CHUNK_ALWAYS
,
833 #ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
834 # ifndef PNG_HANDLE_CHUNK_IF_SAFE
835 # define PNG_HANDLE_CHUNK_IF_SAFE 2
837 png_set_keep_unknown_chunks(write_ptr
, PNG_HANDLE_CHUNK_IF_SAFE
,
841 png_debug(0, "Reading info struct");
842 png_read_info(read_ptr
, read_info_ptr
);
844 png_debug(0, "Transferring info struct");
846 int interlace_type
, compression_type
, filter_type
;
848 if (png_get_IHDR(read_ptr
, read_info_ptr
, &width
, &height
, &bit_depth
,
849 &color_type
, &interlace_type
, &compression_type
, &filter_type
))
851 png_set_IHDR(write_ptr
, write_info_ptr
, width
, height
, bit_depth
,
852 #ifdef PNG_WRITE_INTERLACING_SUPPORTED
853 color_type
, interlace_type
, compression_type
, filter_type
);
855 color_type
, PNG_INTERLACE_NONE
, compression_type
, filter_type
);
859 #ifdef PNG_FIXED_POINT_SUPPORTED
860 #ifdef PNG_cHRM_SUPPORTED
862 png_fixed_point white_x
, white_y
, red_x
, red_y
, green_x
, green_y
, blue_x
,
864 if (png_get_cHRM_fixed(read_ptr
, read_info_ptr
, &white_x
, &white_y
,
865 &red_x
, &red_y
, &green_x
, &green_y
, &blue_x
, &blue_y
))
867 png_set_cHRM_fixed(write_ptr
, write_info_ptr
, white_x
, white_y
, red_x
,
868 red_y
, green_x
, green_y
, blue_x
, blue_y
);
872 #ifdef PNG_gAMA_SUPPORTED
874 png_fixed_point gamma
;
876 if (png_get_gAMA_fixed(read_ptr
, read_info_ptr
, &gamma
))
877 png_set_gAMA_fixed(write_ptr
, write_info_ptr
, gamma
);
880 #else /* Use floating point versions */
881 #ifdef PNG_FLOATING_POINT_SUPPORTED
882 #ifdef PNG_cHRM_SUPPORTED
884 double white_x
, white_y
, red_x
, red_y
, green_x
, green_y
, blue_x
,
886 if (png_get_cHRM(read_ptr
, read_info_ptr
, &white_x
, &white_y
, &red_x
,
887 &red_y
, &green_x
, &green_y
, &blue_x
, &blue_y
))
889 png_set_cHRM(write_ptr
, write_info_ptr
, white_x
, white_y
, red_x
,
890 red_y
, green_x
, green_y
, blue_x
, blue_y
);
894 #ifdef PNG_gAMA_SUPPORTED
898 if (png_get_gAMA(read_ptr
, read_info_ptr
, &gamma
))
899 png_set_gAMA(write_ptr
, write_info_ptr
, gamma
);
902 #endif /* Floating point */
903 #endif /* Fixed point */
904 #ifdef PNG_iCCP_SUPPORTED
909 int compression_type
;
911 if (png_get_iCCP(read_ptr
, read_info_ptr
, &name
, &compression_type
,
914 png_set_iCCP(write_ptr
, write_info_ptr
, name
, compression_type
,
919 #ifdef PNG_sRGB_SUPPORTED
923 if (png_get_sRGB(read_ptr
, read_info_ptr
, &intent
))
924 png_set_sRGB(write_ptr
, write_info_ptr
, intent
);
931 if (png_get_PLTE(read_ptr
, read_info_ptr
, &palette
, &num_palette
))
932 png_set_PLTE(write_ptr
, write_info_ptr
, palette
, num_palette
);
934 #ifdef PNG_bKGD_SUPPORTED
936 png_color_16p background
;
938 if (png_get_bKGD(read_ptr
, read_info_ptr
, &background
))
940 png_set_bKGD(write_ptr
, write_info_ptr
, background
);
944 #ifdef PNG_hIST_SUPPORTED
948 if (png_get_hIST(read_ptr
, read_info_ptr
, &hist
))
949 png_set_hIST(write_ptr
, write_info_ptr
, hist
);
952 #ifdef PNG_oFFs_SUPPORTED
954 png_int_32 offset_x
, offset_y
;
957 if (png_get_oFFs(read_ptr
, read_info_ptr
, &offset_x
, &offset_y
,
960 png_set_oFFs(write_ptr
, write_info_ptr
, offset_x
, offset_y
, unit_type
);
964 #ifdef PNG_pCAL_SUPPORTED
966 png_charp purpose
, units
;
971 if (png_get_pCAL(read_ptr
, read_info_ptr
, &purpose
, &X0
, &X1
, &type
,
972 &nparams
, &units
, ¶ms
))
974 png_set_pCAL(write_ptr
, write_info_ptr
, purpose
, X0
, X1
, type
,
975 nparams
, units
, params
);
979 #ifdef PNG_pHYs_SUPPORTED
981 png_uint_32 res_x
, res_y
;
984 if (png_get_pHYs(read_ptr
, read_info_ptr
, &res_x
, &res_y
, &unit_type
))
985 png_set_pHYs(write_ptr
, write_info_ptr
, res_x
, res_y
, unit_type
);
988 #ifdef PNG_sBIT_SUPPORTED
990 png_color_8p sig_bit
;
992 if (png_get_sBIT(read_ptr
, read_info_ptr
, &sig_bit
))
993 png_set_sBIT(write_ptr
, write_info_ptr
, sig_bit
);
996 #ifdef PNG_sCAL_SUPPORTED
997 #ifdef PNG_FLOATING_POINT_SUPPORTED
1000 double scal_width
, scal_height
;
1002 if (png_get_sCAL(read_ptr
, read_info_ptr
, &unit
, &scal_width
,
1005 png_set_sCAL(write_ptr
, write_info_ptr
, unit
, scal_width
, scal_height
);
1009 #ifdef PNG_FIXED_POINT_SUPPORTED
1012 png_charp scal_width
, scal_height
;
1014 if (png_get_sCAL_s(read_ptr
, read_info_ptr
, &unit
, &scal_width
,
1017 png_set_sCAL_s(write_ptr
, write_info_ptr
, unit
, scal_width
,
1024 #ifdef PNG_TEXT_SUPPORTED
1029 if (png_get_text(read_ptr
, read_info_ptr
, &text_ptr
, &num_text
) > 0)
1031 png_debug1(0, "Handling %d iTXt/tEXt/zTXt chunks", num_text
);
1032 png_set_text(write_ptr
, write_info_ptr
, text_ptr
, num_text
);
1036 #ifdef PNG_tIME_SUPPORTED
1040 if (png_get_tIME(read_ptr
, read_info_ptr
, &mod_time
))
1042 png_set_tIME(write_ptr
, write_info_ptr
, mod_time
);
1043 #ifdef PNG_TIME_RFC1123_SUPPORTED
1044 /* We have to use png_memcpy instead of "=" because the string
1045 * pointed to by png_convert_to_rfc1123() gets free'ed before
1048 png_memcpy(tIME_string
,
1049 png_convert_to_rfc1123(read_ptr
, mod_time
),
1050 png_sizeof(tIME_string
));
1051 tIME_string
[png_sizeof(tIME_string
) - 1] = '\0';
1052 tIME_chunk_present
++;
1053 #endif /* PNG_TIME_RFC1123_SUPPORTED */
1057 #ifdef PNG_tRNS_SUPPORTED
1059 png_bytep trans_alpha
;
1061 png_color_16p trans_color
;
1063 if (png_get_tRNS(read_ptr
, read_info_ptr
, &trans_alpha
, &num_trans
,
1066 int sample_max
= (1 << bit_depth
);
1067 /* libpng doesn't reject a tRNS chunk with out-of-range samples */
1068 if (!((color_type
== PNG_COLOR_TYPE_GRAY
&&
1069 (int)trans_color
->gray
> sample_max
) ||
1070 (color_type
== PNG_COLOR_TYPE_RGB
&&
1071 ((int)trans_color
->red
> sample_max
||
1072 (int)trans_color
->green
> sample_max
||
1073 (int)trans_color
->blue
> sample_max
))))
1074 png_set_tRNS(write_ptr
, write_info_ptr
, trans_alpha
, num_trans
,
1079 #ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
1081 png_unknown_chunkp unknowns
;
1082 int num_unknowns
= (int)png_get_unknown_chunks(read_ptr
, read_info_ptr
,
1087 png_set_unknown_chunks(write_ptr
, write_info_ptr
, unknowns
,
1089 /* Copy the locations from the read_info_ptr. The automatically
1090 * generated locations in write_info_ptr are wrong because we
1091 * haven't written anything yet.
1093 for (i
= 0; i
< (png_size_t
)num_unknowns
; i
++)
1094 png_set_unknown_chunk_location(write_ptr
, write_info_ptr
, i
,
1095 unknowns
[i
].location
);
1100 #ifdef PNG_WRITE_SUPPORTED
1101 png_debug(0, "Writing info struct");
1103 /* If we wanted, we could write info in two steps:
1104 * png_write_info_before_PLTE(write_ptr, write_info_ptr);
1106 png_write_info(write_ptr
, write_info_ptr
);
1108 #ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
1109 if (user_chunk_data
[0] != 0)
1111 png_byte png_sTER
[5] = {115, 84, 69, 82, '\0'};
1117 fprintf(STDERR
, "\n stereo mode = %lu\n",
1118 (unsigned long)(user_chunk_data
[0] - 1));
1119 ster_chunk_data
[0]=(unsigned char)(user_chunk_data
[0] - 1);
1120 png_write_chunk(write_ptr
, png_sTER
, ster_chunk_data
, 1);
1122 if (user_chunk_data
[1] != 0 || user_chunk_data
[2] != 0)
1124 png_byte png_vpAg
[5] = {118, 112, 65, 103, '\0'};
1130 fprintf(STDERR
, " vpAg = %lu x %lu, units = %lu\n",
1131 (unsigned long)user_chunk_data
[1],
1132 (unsigned long)user_chunk_data
[2],
1133 (unsigned long)user_chunk_data
[3]);
1134 png_save_uint_32(vpag_chunk_data
, user_chunk_data
[1]);
1135 png_save_uint_32(vpag_chunk_data
+ 4, user_chunk_data
[2]);
1136 vpag_chunk_data
[8] = (unsigned char)(user_chunk_data
[3] & 0xff);
1137 png_write_chunk(write_ptr
, png_vpAg
, vpag_chunk_data
, 9);
1143 #ifdef SINGLE_ROWBUF_ALLOC
1144 png_debug(0, "Allocating row buffer...");
1145 row_buf
= (png_bytep
)png_malloc(read_ptr
,
1146 png_get_rowbytes(read_ptr
, read_info_ptr
));
1147 png_debug1(0, "0x%08lx", (unsigned long)row_buf
);
1148 #endif /* SINGLE_ROWBUF_ALLOC */
1149 png_debug(0, "Writing row data");
1151 #if defined(PNG_READ_INTERLACING_SUPPORTED) || \
1152 defined(PNG_WRITE_INTERLACING_SUPPORTED)
1153 num_pass
= png_set_interlace_handling(read_ptr
);
1154 # ifdef PNG_WRITE_SUPPORTED
1155 png_set_interlace_handling(write_ptr
);
1161 #ifdef PNGTEST_TIMING
1162 t_stop
= (float)clock();
1163 t_misc
+= (t_stop
- t_start
);
1166 for (pass
= 0; pass
< num_pass
; pass
++)
1168 png_debug1(0, "Writing row data for pass %d", pass
);
1169 for (y
= 0; y
< height
; y
++)
1171 #ifndef SINGLE_ROWBUF_ALLOC
1172 png_debug2(0, "Allocating row buffer (pass %d, y = %ld)...", pass
, y
);
1173 row_buf
= (png_bytep
)png_malloc(read_ptr
,
1174 png_get_rowbytes(read_ptr
, read_info_ptr
));
1175 png_debug2(0, "0x%08lx (%ld bytes)", (unsigned long)row_buf
,
1176 png_get_rowbytes(read_ptr
, read_info_ptr
));
1177 #endif /* !SINGLE_ROWBUF_ALLOC */
1178 png_read_rows(read_ptr
, (png_bytepp
)&row_buf
, NULL
, 1);
1180 #ifdef PNG_WRITE_SUPPORTED
1181 #ifdef PNGTEST_TIMING
1182 t_stop
= (float)clock();
1183 t_decode
+= (t_stop
- t_start
);
1186 png_write_rows(write_ptr
, (png_bytepp
)&row_buf
, 1);
1187 #ifdef PNGTEST_TIMING
1188 t_stop
= (float)clock();
1189 t_encode
+= (t_stop
- t_start
);
1192 #endif /* PNG_WRITE_SUPPORTED */
1194 #ifndef SINGLE_ROWBUF_ALLOC
1195 png_debug2(0, "Freeing row buffer (pass %d, y = %ld)", pass
, y
);
1196 png_free(read_ptr
, row_buf
);
1198 #endif /* !SINGLE_ROWBUF_ALLOC */
1202 #ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
1203 png_free_data(read_ptr
, read_info_ptr
, PNG_FREE_UNKN
, -1);
1205 #ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
1206 png_free_data(write_ptr
, write_info_ptr
, PNG_FREE_UNKN
, -1);
1209 png_debug(0, "Reading and writing end_info data");
1211 png_read_end(read_ptr
, end_info_ptr
);
1212 #ifdef PNG_TEXT_SUPPORTED
1217 if (png_get_text(read_ptr
, end_info_ptr
, &text_ptr
, &num_text
) > 0)
1219 png_debug1(0, "Handling %d iTXt/tEXt/zTXt chunks", num_text
);
1220 png_set_text(write_ptr
, write_end_info_ptr
, text_ptr
, num_text
);
1224 #ifdef PNG_tIME_SUPPORTED
1228 if (png_get_tIME(read_ptr
, end_info_ptr
, &mod_time
))
1230 png_set_tIME(write_ptr
, write_end_info_ptr
, mod_time
);
1231 #ifdef PNG_TIME_RFC1123_SUPPORTED
1232 /* We have to use png_memcpy instead of "=" because the string
1233 pointed to by png_convert_to_rfc1123() gets free'ed before
1235 png_memcpy(tIME_string
,
1236 png_convert_to_rfc1123(read_ptr
, mod_time
),
1237 png_sizeof(tIME_string
));
1238 tIME_string
[png_sizeof(tIME_string
) - 1] = '\0';
1239 tIME_chunk_present
++;
1240 #endif /* PNG_TIME_RFC1123_SUPPORTED */
1244 #ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
1246 png_unknown_chunkp unknowns
;
1248 num_unknowns
= (int)png_get_unknown_chunks(read_ptr
, end_info_ptr
,
1253 png_set_unknown_chunks(write_ptr
, write_end_info_ptr
, unknowns
,
1255 /* Copy the locations from the read_info_ptr. The automatically
1256 * generated locations in write_end_info_ptr are wrong because we
1257 * haven't written the end_info yet.
1259 for (i
= 0; i
< (png_size_t
)num_unknowns
; i
++)
1260 png_set_unknown_chunk_location(write_ptr
, write_end_info_ptr
, i
,
1261 unknowns
[i
].location
);
1265 #ifdef PNG_WRITE_SUPPORTED
1266 png_write_end(write_ptr
, write_end_info_ptr
);
1269 #ifdef PNG_EASY_ACCESS_SUPPORTED
1272 png_uint_32 iwidth
, iheight
;
1273 iwidth
= png_get_image_width(write_ptr
, write_info_ptr
);
1274 iheight
= png_get_image_height(write_ptr
, write_info_ptr
);
1275 fprintf(STDERR
, "\n Image width = %lu, height = %lu\n",
1276 (unsigned long)iwidth
, (unsigned long)iheight
);
1280 png_debug(0, "Destroying data structs");
1281 #ifdef SINGLE_ROWBUF_ALLOC
1282 png_debug(1, "destroying row_buf for read_ptr");
1283 png_free(read_ptr
, row_buf
);
1285 #endif /* SINGLE_ROWBUF_ALLOC */
1286 png_debug(1, "destroying read_ptr, read_info_ptr, end_info_ptr");
1287 png_destroy_read_struct(&read_ptr
, &read_info_ptr
, &end_info_ptr
);
1288 #ifdef PNG_WRITE_SUPPORTED
1289 png_debug(1, "destroying write_end_info_ptr");
1290 png_destroy_info_struct(write_ptr
, &write_end_info_ptr
);
1291 png_debug(1, "destroying write_ptr, write_info_ptr");
1292 png_destroy_write_struct(&write_ptr
, &write_info_ptr
);
1294 png_debug(0, "Destruction complete.");
1299 png_debug(0, "Opening files for comparison");
1300 if ((fpin
= fopen(inname
, "rb")) == NULL
)
1302 fprintf(STDERR
, "Could not find file %s\n", inname
);
1306 if ((fpout
= fopen(outname
, "rb")) == NULL
)
1308 fprintf(STDERR
, "Could not find file %s\n", outname
);
1315 png_size_t num_in
, num_out
;
1317 num_in
= fread(inbuf
, 1, 1, fpin
);
1318 num_out
= fread(outbuf
, 1, 1, fpout
);
1320 if (num_in
!= num_out
)
1322 fprintf(STDERR
, "\nFiles %s and %s are of a different size\n",
1324 if (wrote_question
== 0)
1327 " Was %s written with the same maximum IDAT chunk size (%d bytes),",
1328 inname
, PNG_ZBUF_SIZE
);
1330 "\n filtering heuristic (libpng default), compression");
1332 " level (zlib default),\n and zlib version (%s)?\n\n",
1344 if (png_memcmp(inbuf
, outbuf
, num_in
))
1346 fprintf(STDERR
, "\nFiles %s and %s are different\n", inname
, outname
);
1347 if (wrote_question
== 0)
1350 " Was %s written with the same maximum IDAT chunk size (%d bytes),",
1351 inname
, PNG_ZBUF_SIZE
);
1353 "\n filtering heuristic (libpng default), compression");
1355 " level (zlib default),\n and zlib version (%s)?\n\n",
1371 /* Input and output filenames */
1373 static PNG_CONST
char *inname
= "pngtest/png";
1374 static PNG_CONST
char *outname
= "pngout/png";
1376 static PNG_CONST
char *inname
= "pngtest.png";
1377 static PNG_CONST
char *outname
= "pngout.png";
1381 main(int argc
, char *argv
[])
1386 fprintf(STDERR
, "\n Testing libpng version %s\n", PNG_LIBPNG_VER_STRING
);
1387 fprintf(STDERR
, " with zlib version %s\n", ZLIB_VERSION
);
1388 fprintf(STDERR
, "%s", png_get_copyright(NULL
));
1389 /* Show the version of libpng used in building the library */
1390 fprintf(STDERR
, " library (%lu):%s",
1391 (unsigned long)png_access_version_number(),
1392 png_get_header_version(NULL
));
1393 /* Show the version of libpng used in building the application */
1394 fprintf(STDERR
, " pngtest (%lu):%s", (unsigned long)PNG_LIBPNG_VER
,
1395 PNG_HEADER_VERSION_STRING
);
1396 fprintf(STDERR
, " sizeof(png_struct)=%ld, sizeof(png_info)=%ld\n",
1397 (long)png_sizeof(png_struct
), (long)png_sizeof(png_info
));
1399 /* Do some consistency checking on the memory allocation settings, I'm
1400 * not sure this matters, but it is nice to know, the first of these
1401 * tests should be impossible because of the way the macros are set
1404 #if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K)
1405 fprintf(STDERR
, " NOTE: Zlib compiled for max 64k, libpng not\n");
1407 /* I think the following can happen. */
1408 #if !defined(MAXSEG_64K) && defined(PNG_MAX_MALLOC_64K)
1409 fprintf(STDERR
, " NOTE: libpng compiled for max 64k, zlib not\n");
1412 if (strcmp(png_libpng_ver
, PNG_LIBPNG_VER_STRING
))
1415 "Warning: versions are different between png.h and png.c\n");
1416 fprintf(STDERR
, " png.h version: %s\n", PNG_LIBPNG_VER_STRING
);
1417 fprintf(STDERR
, " png.c version: %s\n\n", png_libpng_ver
);
1423 if (strcmp(argv
[1], "-m") == 0)
1426 status_dots_requested
= 0;
1428 else if (strcmp(argv
[1], "-mv") == 0 ||
1429 strcmp(argv
[1], "-vm") == 0 )
1433 status_dots_requested
= 1;
1435 else if (strcmp(argv
[1], "-v") == 0)
1438 status_dots_requested
= 1;
1444 status_dots_requested
= 0;
1448 if (!multiple
&& argc
== 3 + verbose
)
1449 outname
= argv
[2 + verbose
];
1451 if ((!multiple
&& argc
> 3 + verbose
) || (multiple
&& argc
< 2))
1454 "usage: %s [infile.png] [outfile.png]\n\t%s -m {infile.png}\n",
1457 " reads/writes one PNG file (without -m) or multiple files (-m)\n");
1459 " with -m %s is used as a temporary file\n", outname
);
1466 #if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
1467 int allocation_now
= current_allocation
;
1469 for (i
=2; i
<argc
; ++i
)
1472 fprintf(STDERR
, "\n Testing %s:", argv
[i
]);
1473 kerror
= test_one_file(argv
[i
], outname
);
1476 #ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
1479 #ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
1480 fprintf(STDERR
, "\n PASS (%lu zero samples)\n",
1481 (unsigned long)zero_samples
);
1483 fprintf(STDERR
, " PASS\n");
1485 #ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
1486 for (k
= 0; k
<256; k
++)
1487 if (filters_used
[k
])
1488 fprintf(STDERR
, " Filter %d was used %lu times\n",
1489 k
, (unsigned long)filters_used
[k
]);
1491 #ifdef PNG_TIME_RFC1123_SUPPORTED
1492 if (tIME_chunk_present
!= 0)
1493 fprintf(STDERR
, " tIME = %s\n", tIME_string
);
1494 tIME_chunk_present
= 0;
1495 #endif /* PNG_TIME_RFC1123_SUPPORTED */
1499 fprintf(STDERR
, " FAIL\n");
1502 #if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
1503 if (allocation_now
!= current_allocation
)
1504 fprintf(STDERR
, "MEMORY ERROR: %d bytes lost\n",
1505 current_allocation
- allocation_now
);
1506 if (current_allocation
!= 0)
1508 memory_infop pinfo
= pinformation
;
1510 fprintf(STDERR
, "MEMORY ERROR: %d bytes still allocated\n",
1511 current_allocation
);
1512 while (pinfo
!= NULL
)
1514 fprintf(STDERR
, " %lu bytes at %x\n",
1515 (unsigned long)pinfo
->size
,
1516 (unsigned int) pinfo
->pointer
);
1517 pinfo
= pinfo
->next
;
1522 #if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
1523 fprintf(STDERR
, " Current memory allocation: %10d bytes\n",
1524 current_allocation
);
1525 fprintf(STDERR
, " Maximum memory allocation: %10d bytes\n",
1526 maximum_allocation
);
1527 fprintf(STDERR
, " Total memory allocation: %10d bytes\n",
1529 fprintf(STDERR
, " Number of allocations: %10d\n",
1536 for (i
= 0; i
<3; ++i
)
1539 #if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
1540 int allocation_now
= current_allocation
;
1542 if (i
== 1) status_dots_requested
= 1;
1543 else if (verbose
== 0)status_dots_requested
= 0;
1544 if (i
== 0 || verbose
== 1 || ierror
!= 0)
1545 fprintf(STDERR
, "\n Testing %s:", inname
);
1546 kerror
= test_one_file(inname
, outname
);
1549 if (verbose
== 1 || i
== 2)
1551 #ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
1554 #ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
1555 fprintf(STDERR
, "\n PASS (%lu zero samples)\n",
1556 (unsigned long)zero_samples
);
1558 fprintf(STDERR
, " PASS\n");
1560 #ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
1561 for (k
= 0; k
<256; k
++)
1562 if (filters_used
[k
])
1563 fprintf(STDERR
, " Filter %d was used %lu times\n",
1564 k
, (unsigned long)filters_used
[k
]);
1566 #ifdef PNG_TIME_RFC1123_SUPPORTED
1567 if (tIME_chunk_present
!= 0)
1568 fprintf(STDERR
, " tIME = %s\n", tIME_string
);
1569 #endif /* PNG_TIME_RFC1123_SUPPORTED */
1574 if (verbose
== 0 && i
!= 2)
1575 fprintf(STDERR
, "\n Testing %s:", inname
);
1576 fprintf(STDERR
, " FAIL\n");
1579 #if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
1580 if (allocation_now
!= current_allocation
)
1581 fprintf(STDERR
, "MEMORY ERROR: %d bytes lost\n",
1582 current_allocation
- allocation_now
);
1583 if (current_allocation
!= 0)
1585 memory_infop pinfo
= pinformation
;
1587 fprintf(STDERR
, "MEMORY ERROR: %d bytes still allocated\n",
1588 current_allocation
);
1589 while (pinfo
!= NULL
)
1591 fprintf(STDERR
, " %lu bytes at %x\n",
1592 (unsigned long)pinfo
->size
, (unsigned int)pinfo
->pointer
);
1593 pinfo
= pinfo
->next
;
1598 #if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
1599 fprintf(STDERR
, " Current memory allocation: %10d bytes\n",
1600 current_allocation
);
1601 fprintf(STDERR
, " Maximum memory allocation: %10d bytes\n",
1602 maximum_allocation
);
1603 fprintf(STDERR
, " Total memory allocation: %10d bytes\n",
1605 fprintf(STDERR
, " Number of allocations: %10d\n",
1610 #ifdef PNGTEST_TIMING
1611 t_stop
= (float)clock();
1612 t_misc
+= (t_stop
- t_start
);
1614 fprintf(STDERR
, " CPU time used = %.3f seconds",
1615 (t_misc
+t_decode
+t_encode
)/(float)CLOCKS_PER_SEC
);
1616 fprintf(STDERR
, " (decoding %.3f,\n",
1617 t_decode
/(float)CLOCKS_PER_SEC
);
1618 fprintf(STDERR
, " encoding %.3f ,",
1619 t_encode
/(float)CLOCKS_PER_SEC
);
1620 fprintf(STDERR
, " other %.3f seconds)\n\n",
1621 t_misc
/(float)CLOCKS_PER_SEC
);
1625 fprintf(STDERR
, " libpng passes test\n");
1627 fprintf(STDERR
, " libpng FAILS test\n");
1628 return (int)(ierror
!= 0);
1631 /* Generate a compiler error if there is an old png.h in the search path. */
1632 typedef version_1_4_4 your_png_h_is_not_version_1_4_4
;