2 /* pngtest.c - a simple test program to test libpng
4 * Last changed in libpng 1.2.37 [June 4, 2009]
5 * For conditions of distribution and use, see copyright notice in png.h
6 * Copyright (c) 1998-2009 Glenn Randers-Pehrson
7 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
8 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
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
16 * The program will report "FAIL" in certain legitimate cases:
17 * 1) when the compression level or filter selection method is changed.
18 * 2) when the maximum IDAT size (PNG_ZBUF_SIZE in pngconf.h) is not 8192.
19 * 3) unknown unsafe-to-copy ancillary chunks or unknown critical chunks
20 * exist in the input file.
21 * 4) others not listed here...
22 * In these cases, it is best to check with another tool such as "pngcheck"
23 * to see what the differences between the two files are.
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
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 ..."
33 #if defined(_WIN32_WCE)
35 __error__ (f
|w
)printf functions are
not supported on old WindowsCE
.;
39 # define READFILE(file, data, length, check) \
40 if (ReadFile(file, data, length, &check, NULL)) check = 0
41 # define WRITEFILE(file, data, length, check)) \
42 if (WriteFile(file, data, length, &check, NULL)) check = 0
43 # define FCLOSE(file) CloseHandle(file)
47 # define READFILE(file, data, length, check) \
48 check=(png_size_t)fread(data, (png_size_t)1, length, file)
49 # define WRITEFILE(file, data, length, check) \
50 check=(png_size_t)fwrite(data, (png_size_t)1, length, file)
51 # define FCLOSE(file) fclose(file)
54 #if defined(PNG_NO_STDIO)
55 # if defined(_WIN32_WCE)
56 typedef HANDLE png_FILE_p
;
58 typedef FILE * png_FILE_p
;
62 /* Makes pngtest verbose so we can find problems (needs to be before png.h) */
68 # define SINGLE_ROWBUF_ALLOC /* Makes buffer overruns easier to nail */
72 #define PNGTEST_TIMING
75 #ifdef PNG_NO_FLOATING_POINT_SUPPORTED
80 static float t_start
, t_stop
, t_decode
, t_encode
, t_misc
;
84 #if defined(PNG_TIME_RFC1123_SUPPORTED)
85 #define PNG_tIME_STRING_LENGTH 29
86 static int tIME_chunk_present
= 0;
87 static char tIME_string
[PNG_tIME_STRING_LENGTH
] = "tIME chunk is not present";
90 static int verbose
= 0;
92 int test_one_file
PNGARG((PNG_CONST
char *inname
, PNG_CONST
char *outname
));
98 /* Defined so I can write to a file on gui/windowing platforms */
99 /* #define STDERR stderr */
100 #define STDERR stdout /* For DOS */
102 /* In case a system header (e.g., on AIX) defined jmpbuf */
107 /* Define png_jmpbuf() in case we are using a pre-1.0.6 version of libpng */
109 # define png_jmpbuf(png_ptr) png_ptr->jmpbuf
112 /* Example of using row callbacks to make a simple progress meter */
113 static int status_pass
= 1;
114 static int status_dots_requested
= 0;
115 static int status_dots
= 1;
121 read_row_callback(png_structp png_ptr
, png_uint_32 row_number
, int pass
);
126 read_row_callback(png_structp png_ptr
, png_uint_32 row_number
, int pass
)
128 if (png_ptr
== NULL
|| row_number
> PNG_UINT_31_MAX
)
130 if (status_pass
!= pass
)
132 fprintf(stdout
, "\n Pass %d: ", pass
);
137 if (status_dots
== 0)
139 fprintf(stdout
, "\n ");
142 fprintf(stdout
, "r");
149 write_row_callback(png_structp png_ptr
, png_uint_32 row_number
, int pass
);
154 write_row_callback(png_structp png_ptr
, png_uint_32 row_number
, int pass
)
156 if (png_ptr
== NULL
|| row_number
> PNG_UINT_31_MAX
|| pass
> 7)
158 fprintf(stdout
, "w");
162 #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
163 /* Example of using user transform callback (we don't transform anything,
164 * but merely examine the row filters. We set this to 256 rather than
165 * 5 in case illegal filter values are present.)
167 static png_uint_32 filters_used
[256];
172 count_filters(png_structp png_ptr
, png_row_infop row_info
, png_bytep data
);
177 count_filters(png_structp png_ptr
, png_row_infop row_info
, png_bytep data
)
179 if (png_ptr
!= NULL
&& row_info
!= NULL
)
180 ++filters_used
[*(data
- 1)];
184 #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
185 /* Example of using user transform callback (we don't transform anything,
186 * but merely count the zero samples)
189 static png_uint_32 zero_samples
;
195 count_zero_samples(png_structp png_ptr
, png_row_infop row_info
, png_bytep data
);
200 count_zero_samples(png_structp png_ptr
, png_row_infop row_info
, png_bytep data
)
203 if (png_ptr
== NULL
)return;
205 /* Contents of row_info:
206 * png_uint_32 width width of row
207 * png_uint_32 rowbytes number of bytes in row
208 * png_byte color_type color type of pixels
209 * png_byte bit_depth bit depth of samples
210 * png_byte channels number of channels (1-4)
211 * png_byte pixel_depth bits per pixel (depth*channels)
214 /* Counts the number of zero samples (or zero pixels if color_type is 3 */
216 if (row_info
->color_type
== 0 || row_info
->color_type
== 3)
219 png_uint_32 n
, nstop
;
220 for (n
= 0, nstop
=row_info
->width
; n
<nstop
; n
++)
222 if (row_info
->bit_depth
== 1)
224 if (((*dp
<< pos
++ ) & 0x80) == 0)
232 if (row_info
->bit_depth
== 2)
234 if (((*dp
<< (pos
+=2)) & 0xc0) == 0)
242 if (row_info
->bit_depth
== 4)
244 if (((*dp
<< (pos
+=4)) & 0xf0) == 0)
252 if (row_info
->bit_depth
== 8)
255 if (row_info
->bit_depth
== 16)
257 if ((*dp
| *(dp
+1)) == 0)
263 else /* Other color types */
265 png_uint_32 n
, nstop
;
267 int color_channels
= row_info
->channels
;
268 if (row_info
->color_type
> 3)color_channels
--;
270 for (n
= 0, nstop
=row_info
->width
; n
<nstop
; n
++)
272 for (channel
= 0; channel
< color_channels
; channel
++)
274 if (row_info
->bit_depth
== 8)
277 if (row_info
->bit_depth
== 16)
279 if ((*dp
| *(dp
+1)) == 0)
284 if (row_info
->color_type
> 3)
287 if (row_info
->bit_depth
== 16)
293 #endif /* PNG_WRITE_USER_TRANSFORM_SUPPORTED */
295 static int wrote_question
= 0;
297 #if defined(PNG_NO_STDIO)
298 /* START of code to validate stdio-free compilation */
299 /* These copies of the default read/write functions come from pngrio.c and
300 * pngwio.c. They allow "don't include stdio" testing of the library.
301 * This is the function that does the actual reading of data. If you are
302 * not reading from a standard C stream, you should create a replacement
303 * read_data function and use it at run time with png_set_read_fn(), rather
304 * than changing the library.
307 #ifndef USE_FAR_KEYWORD
309 pngtest_read_data(png_structp png_ptr
, png_bytep data
, png_size_t length
)
313 /* fread() returns 0 on error, so it is OK to store this in a png_size_t
314 * instead of an int, which is what fread() actually returns.
316 READFILE((png_FILE_p
)png_ptr
->io_ptr
, data
, length
, check
);
320 png_error(png_ptr
, "Read Error!");
324 /* This is the model-independent version. Since the standard I/O library
325 can't handle far buffers in the medium and small models, we have to copy
329 #define NEAR_BUF_SIZE 1024
330 #define MIN(a,b) (a <= b ? a : b)
333 pngtest_read_data(png_structp png_ptr
, png_bytep data
, png_size_t length
)
339 /* Check if data really is near. If so, use usual code. */
340 n_data
= (png_byte
*)CVT_PTR_NOCHECK(data
);
341 io_ptr
= (png_FILE_p
)CVT_PTR(png_ptr
->io_ptr
);
342 if ((png_bytep
)n_data
== data
)
344 READFILE(io_ptr
, n_data
, length
, check
);
348 png_byte buf
[NEAR_BUF_SIZE
];
349 png_size_t read
, remaining
, err
;
354 read
= MIN(NEAR_BUF_SIZE
, remaining
);
355 READFILE(io_ptr
, buf
, 1, err
);
356 png_memcpy(data
, buf
, read
); /* Copy far buffer to near buffer */
364 while (remaining
!= 0);
367 png_error(png_ptr
, "read Error");
369 #endif /* USE_FAR_KEYWORD */
371 #if defined(PNG_WRITE_FLUSH_SUPPORTED)
373 pngtest_flush(png_structp png_ptr
)
375 /* Do nothing; fflush() is said to be just a waste of energy. */
376 png_ptr
= png_ptr
; /* Stifle compiler warning */
380 /* This is the function that does the actual writing of data. If you are
381 * not writing to a standard C stream, you should create a replacement
382 * write_data function and use it at run time with png_set_write_fn(), rather
383 * than changing the library.
385 #ifndef USE_FAR_KEYWORD
387 pngtest_write_data(png_structp png_ptr
, png_bytep data
, png_size_t length
)
391 WRITEFILE((png_FILE_p
)png_ptr
->io_ptr
, data
, length
, check
);
394 png_error(png_ptr
, "Write Error");
398 /* This is the model-independent version. Since the standard I/O library
399 can't handle far buffers in the medium and small models, we have to copy
403 #define NEAR_BUF_SIZE 1024
404 #define MIN(a,b) (a <= b ? a : b)
407 pngtest_write_data(png_structp png_ptr
, png_bytep data
, png_size_t length
)
410 png_byte
*near_data
; /* Needs to be "png_byte *" instead of "png_bytep" */
413 /* Check if data really is near. If so, use usual code. */
414 near_data
= (png_byte
*)CVT_PTR_NOCHECK(data
);
415 io_ptr
= (png_FILE_p
)CVT_PTR(png_ptr
->io_ptr
);
416 if ((png_bytep
)near_data
== data
)
418 WRITEFILE(io_ptr
, near_data
, length
, check
);
422 png_byte buf
[NEAR_BUF_SIZE
];
423 png_size_t written
, remaining
, err
;
428 written
= MIN(NEAR_BUF_SIZE
, remaining
);
429 png_memcpy(buf
, data
, written
); /* Copy far buffer to near buffer */
430 WRITEFILE(io_ptr
, buf
, written
, err
);
436 remaining
-= written
;
438 while (remaining
!= 0);
442 png_error(png_ptr
, "Write Error");
445 #endif /* USE_FAR_KEYWORD */
447 /* This function is called when there is a warning, but the library thinks
448 * it can continue anyway. Replacement functions don't have to do anything
449 * here if you don't want to. In the default configuration, png_ptr is
450 * not used, but it is passed in case it may be useful.
453 pngtest_warning(png_structp png_ptr
, png_const_charp message
)
455 PNG_CONST
char *name
= "UNKNOWN (ERROR!)";
456 if (png_ptr
!= NULL
&& png_ptr
->error_ptr
!= NULL
)
457 name
= png_ptr
->error_ptr
;
458 fprintf(STDERR
, "%s: libpng warning: %s\n", name
, message
);
461 /* This is the default error handling function. Note that replacements for
462 * this function MUST NOT RETURN, or the program will likely crash. This
463 * function is used by default, or if the program supplies NULL for the
464 * error function pointer in png_set_error_fn().
467 pngtest_error(png_structp png_ptr
, png_const_charp message
)
469 pngtest_warning(png_ptr
, message
);
470 /* We can return because png_error calls the default handler, which is
471 * actually OK in this case.
474 #endif /* PNG_NO_STDIO */
475 /* END of code to validate stdio-free compilation */
477 /* START of code to validate memory allocation and deallocation */
478 #if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
480 /* Allocate memory. For reasonable files, size should never exceed
481 * 64K. However, zlib may allocate more then 64K if you don't tell
482 * it not to. See zconf.h and png.h for more information. zlib does
483 * need to allocate exactly 64K, so whatever you call here must
484 * have the ability to do that.
486 * This piece of code can be compiled to validate max 64K allocations
487 * by setting MAXSEG_64K in zlib zconf.h *or* PNG_MAX_MALLOC_64K.
489 typedef struct memory_information
493 struct memory_information FAR
*next
;
494 } memory_information
;
495 typedef memory_information FAR
*memory_infop
;
497 static memory_infop pinformation
= NULL
;
498 static int current_allocation
= 0;
499 static int maximum_allocation
= 0;
500 static int total_allocation
= 0;
501 static int num_allocations
= 0;
503 png_voidp png_debug_malloc
PNGARG((png_structp png_ptr
, png_uint_32 size
));
504 void png_debug_free
PNGARG((png_structp png_ptr
, png_voidp ptr
));
507 png_debug_malloc(png_structp png_ptr
, png_uint_32 size
)
510 /* png_malloc has already tested for NULL; png_create_struct calls
511 * png_debug_malloc directly, with png_ptr == NULL which is OK
517 /* This calls the library allocator twice, once to get the requested
518 buffer and once to get a new free list entry. */
520 /* Disable malloc_fn and free_fn */
522 png_set_mem_fn(png_ptr
, NULL
, NULL
, NULL
);
523 pinfo
= (memory_infop
)png_malloc(png_ptr
,
524 (png_uint_32
)png_sizeof(*pinfo
));
526 current_allocation
+= size
;
527 total_allocation
+= size
;
529 if (current_allocation
> maximum_allocation
)
530 maximum_allocation
= current_allocation
;
531 pinfo
->pointer
= (png_voidp
)png_malloc(png_ptr
, size
);
532 /* Restore malloc_fn and free_fn */
533 png_set_mem_fn(png_ptr
,
534 png_voidp_NULL
, (png_malloc_ptr
)png_debug_malloc
,
535 (png_free_ptr
)png_debug_free
);
536 if (size
!= 0 && pinfo
->pointer
== NULL
)
538 current_allocation
-= size
;
539 total_allocation
-= size
;
541 "out of memory in pngtest->png_debug_malloc.");
543 pinfo
->next
= pinformation
;
544 pinformation
= pinfo
;
545 /* Make sure the caller isn't assuming zeroed memory. */
546 png_memset(pinfo
->pointer
, 0xdd, pinfo
->size
);
548 printf("png_malloc %lu bytes at %x\n", (unsigned long)size
,
550 return (png_voidp
)(pinfo
->pointer
);
554 /* Free a pointer. It is removed from the list at the same time. */
556 png_debug_free(png_structp png_ptr
, png_voidp ptr
)
559 fprintf(STDERR
, "NULL pointer to png_debug_free.\n");
562 #if 0 /* This happens all the time. */
563 fprintf(STDERR
, "WARNING: freeing NULL pointer\n");
568 /* Unlink the element from the list. */
570 memory_infop FAR
*ppinfo
= &pinformation
;
573 memory_infop pinfo
= *ppinfo
;
574 if (pinfo
->pointer
== ptr
)
576 *ppinfo
= pinfo
->next
;
577 current_allocation
-= pinfo
->size
;
578 if (current_allocation
< 0)
579 fprintf(STDERR
, "Duplicate free of memory\n");
580 /* We must free the list element too, but first kill
581 the memory that is to be freed. */
582 png_memset(ptr
, 0x55, pinfo
->size
);
583 png_free_default(png_ptr
, pinfo
);
587 if (pinfo
->next
== NULL
)
589 fprintf(STDERR
, "Pointer %x not found\n", (unsigned int)ptr
);
592 ppinfo
= &pinfo
->next
;
596 /* Finally free the data. */
598 printf("Freeing %x\n", ptr
);
599 png_free_default(png_ptr
, ptr
);
602 #endif /* PNG_USER_MEM_SUPPORTED && PNG_DEBUG */
603 /* END of code to test memory allocation/deallocation */
606 /* Demonstration of user chunk support of the sTER and vpAg chunks */
607 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
609 /* (sTER is a public chunk not yet known by libpng. vpAg is a private
610 chunk used in ImageMagick to store "virtual page" size). */
612 static png_uint_32 user_chunk_data
[4];
620 static int read_user_chunk_callback(png_struct
*png_ptr
,
621 png_unknown_chunkp chunk
)
626 /* Return one of the following:
627 * return (-n); chunk had an error
628 * return (0); did not recognize
629 * return (n); success
631 * The unknown chunk structure contains the chunk data:
636 * Note that libpng has already taken care of the CRC handling.
639 if (chunk
->name
[0] == 115 && chunk
->name
[1] == 84 && /* s T */
640 chunk
->name
[2] == 69 && chunk
->name
[3] == 82) /* E R */
642 /* Found sTER chunk */
643 if (chunk
->size
!= 1)
644 return (-1); /* Error return */
645 if (chunk
->data
[0] != 0 && chunk
->data
[0] != 1)
646 return (-1); /* Invalid mode */
647 my_user_chunk_data
=(png_uint_32
*) png_get_user_chunk_ptr(png_ptr
);
648 my_user_chunk_data
[0]=chunk
->data
[0]+1;
652 if (chunk
->name
[0] != 118 || chunk
->name
[1] != 112 || /* v p */
653 chunk
->name
[2] != 65 || chunk
->name
[3] != 103) /* A g */
654 return (0); /* Did not recognize */
656 /* Found ImageMagick vpAg chunk */
658 if (chunk
->size
!= 9)
659 return (-1); /* Error return */
661 my_user_chunk_data
=(png_uint_32
*) png_get_user_chunk_ptr(png_ptr
);
663 my_user_chunk_data
[1]=png_get_uint_31(png_ptr
, chunk
->data
);
664 my_user_chunk_data
[2]=png_get_uint_31(png_ptr
, chunk
->data
+ 4);
665 my_user_chunk_data
[3]=(png_uint_32
)chunk
->data
[8];
671 /* END of code to demonstrate user chunk support */
675 test_one_file(PNG_CONST
char *inname
, PNG_CONST
char *outname
)
677 static png_FILE_p fpin
;
678 static png_FILE_p fpout
; /* "static" prevents setjmp corruption */
679 png_structp read_ptr
;
680 png_infop read_info_ptr
, end_info_ptr
;
681 #ifdef PNG_WRITE_SUPPORTED
682 png_structp write_ptr
;
683 png_infop write_info_ptr
;
684 png_infop write_end_info_ptr
;
686 png_structp write_ptr
= NULL
;
687 png_infop write_info_ptr
= NULL
;
688 png_infop write_end_info_ptr
= NULL
;
692 png_uint_32 width
, height
;
694 int bit_depth
, color_type
;
695 #ifdef PNG_SETJMP_SUPPORTED
696 #ifdef USE_FAR_KEYWORD
701 #if defined(_WIN32_WCE)
702 TCHAR path
[MAX_PATH
];
704 char inbuf
[256], outbuf
[256];
708 #if defined(_WIN32_WCE)
709 MultiByteToWideChar(CP_ACP
, 0, inname
, -1, path
, MAX_PATH
);
710 if ((fpin
= CreateFile(path
, GENERIC_READ
, 0, NULL
, OPEN_EXISTING
, 0, NULL
)) == INVALID_HANDLE_VALUE
)
712 if ((fpin
= fopen(inname
, "rb")) == NULL
)
715 fprintf(STDERR
, "Could not find input file %s\n", inname
);
719 #if defined(_WIN32_WCE)
720 MultiByteToWideChar(CP_ACP
, 0, outname
, -1, path
, MAX_PATH
);
721 if ((fpout
= CreateFile(path
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, NULL
)) == INVALID_HANDLE_VALUE
)
723 if ((fpout
= fopen(outname
, "wb")) == NULL
)
726 fprintf(STDERR
, "Could not open output file %s\n", outname
);
731 png_debug(0, "Allocating read and write structures");
732 #if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
734 png_create_read_struct_2(PNG_LIBPNG_VER_STRING
, png_voidp_NULL
,
735 png_error_ptr_NULL
, png_error_ptr_NULL
, png_voidp_NULL
,
736 (png_malloc_ptr
)png_debug_malloc
, (png_free_ptr
)png_debug_free
);
739 png_create_read_struct(PNG_LIBPNG_VER_STRING
, png_voidp_NULL
,
740 png_error_ptr_NULL
, png_error_ptr_NULL
);
742 #if defined(PNG_NO_STDIO)
743 png_set_error_fn(read_ptr
, (png_voidp
)inname
, pngtest_error
,
747 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
748 user_chunk_data
[0] = 0;
749 user_chunk_data
[1] = 0;
750 user_chunk_data
[2] = 0;
751 user_chunk_data
[3] = 0;
752 png_set_read_user_chunk_fn(read_ptr
, user_chunk_data
,
753 read_user_chunk_callback
);
756 #ifdef PNG_WRITE_SUPPORTED
757 #if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
759 png_create_write_struct_2(PNG_LIBPNG_VER_STRING
, png_voidp_NULL
,
760 png_error_ptr_NULL
, png_error_ptr_NULL
, png_voidp_NULL
,
761 (png_malloc_ptr
)png_debug_malloc
, (png_free_ptr
)png_debug_free
);
764 png_create_write_struct(PNG_LIBPNG_VER_STRING
, png_voidp_NULL
,
765 png_error_ptr_NULL
, png_error_ptr_NULL
);
767 #if defined(PNG_NO_STDIO)
768 png_set_error_fn(write_ptr
, (png_voidp
)inname
, pngtest_error
,
772 png_debug(0, "Allocating read_info, write_info and end_info structures");
773 read_info_ptr
= png_create_info_struct(read_ptr
);
774 end_info_ptr
= png_create_info_struct(read_ptr
);
775 #ifdef PNG_WRITE_SUPPORTED
776 write_info_ptr
= png_create_info_struct(write_ptr
);
777 write_end_info_ptr
= png_create_info_struct(write_ptr
);
780 #ifdef PNG_SETJMP_SUPPORTED
781 png_debug(0, "Setting jmpbuf for read struct");
782 #ifdef USE_FAR_KEYWORD
785 if (setjmp(png_jmpbuf(read_ptr
)))
788 fprintf(STDERR
, "%s -> %s: libpng read error\n", inname
, outname
);
789 png_free(read_ptr
, row_buf
);
791 png_destroy_read_struct(&read_ptr
, &read_info_ptr
, &end_info_ptr
);
792 #ifdef PNG_WRITE_SUPPORTED
793 png_destroy_info_struct(write_ptr
, &write_end_info_ptr
);
794 png_destroy_write_struct(&write_ptr
, &write_info_ptr
);
800 #ifdef USE_FAR_KEYWORD
801 png_memcpy(png_jmpbuf(read_ptr
), jmpbuf
, png_sizeof(jmp_buf));
804 #ifdef PNG_WRITE_SUPPORTED
805 png_debug(0, "Setting jmpbuf for write struct");
806 #ifdef USE_FAR_KEYWORD
809 if (setjmp(png_jmpbuf(write_ptr
)))
812 fprintf(STDERR
, "%s -> %s: libpng write error\n", inname
, outname
);
813 png_destroy_read_struct(&read_ptr
, &read_info_ptr
, &end_info_ptr
);
814 png_destroy_info_struct(write_ptr
, &write_end_info_ptr
);
815 #ifdef PNG_WRITE_SUPPORTED
816 png_destroy_write_struct(&write_ptr
, &write_info_ptr
);
822 #ifdef USE_FAR_KEYWORD
823 png_memcpy(png_jmpbuf(write_ptr
), jmpbuf
, png_sizeof(jmp_buf));
828 png_debug(0, "Initializing input and output streams");
829 #if !defined(PNG_NO_STDIO)
830 png_init_io(read_ptr
, fpin
);
831 # ifdef PNG_WRITE_SUPPORTED
832 png_init_io(write_ptr
, fpout
);
835 png_set_read_fn(read_ptr
, (png_voidp
)fpin
, pngtest_read_data
);
836 # ifdef PNG_WRITE_SUPPORTED
837 png_set_write_fn(write_ptr
, (png_voidp
)fpout
, pngtest_write_data
,
838 # if defined(PNG_WRITE_FLUSH_SUPPORTED)
845 if (status_dots_requested
== 1)
847 #ifdef PNG_WRITE_SUPPORTED
848 png_set_write_status_fn(write_ptr
, write_row_callback
);
850 png_set_read_status_fn(read_ptr
, read_row_callback
);
854 #ifdef PNG_WRITE_SUPPORTED
855 png_set_write_status_fn(write_ptr
, png_write_status_ptr_NULL
);
857 png_set_read_status_fn(read_ptr
, png_read_status_ptr_NULL
);
860 #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
863 for (i
= 0; i
<256; i
++)
865 png_set_read_user_transform_fn(read_ptr
, count_filters
);
868 #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
870 png_set_write_user_transform_fn(write_ptr
, count_zero_samples
);
873 #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
874 # ifndef PNG_HANDLE_CHUNK_ALWAYS
875 # define PNG_HANDLE_CHUNK_ALWAYS 3
877 png_set_keep_unknown_chunks(read_ptr
, PNG_HANDLE_CHUNK_ALWAYS
,
880 #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
881 # ifndef PNG_HANDLE_CHUNK_IF_SAFE
882 # define PNG_HANDLE_CHUNK_IF_SAFE 2
884 png_set_keep_unknown_chunks(write_ptr
, PNG_HANDLE_CHUNK_IF_SAFE
,
888 png_debug(0, "Reading info struct");
889 png_read_info(read_ptr
, read_info_ptr
);
891 png_debug(0, "Transferring info struct");
893 int interlace_type
, compression_type
, filter_type
;
895 if (png_get_IHDR(read_ptr
, read_info_ptr
, &width
, &height
, &bit_depth
,
896 &color_type
, &interlace_type
, &compression_type
, &filter_type
))
898 png_set_IHDR(write_ptr
, write_info_ptr
, width
, height
, bit_depth
,
899 #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
900 color_type
, interlace_type
, compression_type
, filter_type
);
902 color_type
, PNG_INTERLACE_NONE
, compression_type
, filter_type
);
906 #if defined(PNG_FIXED_POINT_SUPPORTED)
907 #if defined(PNG_cHRM_SUPPORTED)
909 png_fixed_point white_x
, white_y
, red_x
, red_y
, green_x
, green_y
, blue_x
,
911 if (png_get_cHRM_fixed(read_ptr
, read_info_ptr
, &white_x
, &white_y
, &red_x
,
912 &red_y
, &green_x
, &green_y
, &blue_x
, &blue_y
))
914 png_set_cHRM_fixed(write_ptr
, write_info_ptr
, white_x
, white_y
, red_x
,
915 red_y
, green_x
, green_y
, blue_x
, blue_y
);
919 #if defined(PNG_gAMA_SUPPORTED)
921 png_fixed_point gamma
;
923 if (png_get_gAMA_fixed(read_ptr
, read_info_ptr
, &gamma
))
924 png_set_gAMA_fixed(write_ptr
, write_info_ptr
, gamma
);
927 #else /* Use floating point versions */
928 #if defined(PNG_FLOATING_POINT_SUPPORTED)
929 #if defined(PNG_cHRM_SUPPORTED)
931 double white_x
, white_y
, red_x
, red_y
, green_x
, green_y
, blue_x
,
933 if (png_get_cHRM(read_ptr
, read_info_ptr
, &white_x
, &white_y
, &red_x
,
934 &red_y
, &green_x
, &green_y
, &blue_x
, &blue_y
))
936 png_set_cHRM(write_ptr
, write_info_ptr
, white_x
, white_y
, red_x
,
937 red_y
, green_x
, green_y
, blue_x
, blue_y
);
941 #if defined(PNG_gAMA_SUPPORTED)
945 if (png_get_gAMA(read_ptr
, read_info_ptr
, &gamma
))
946 png_set_gAMA(write_ptr
, write_info_ptr
, gamma
);
949 #endif /* Floating point */
950 #endif /* Fixed point */
951 #if defined(PNG_iCCP_SUPPORTED)
956 int compression_type
;
958 if (png_get_iCCP(read_ptr
, read_info_ptr
, &name
, &compression_type
,
961 png_set_iCCP(write_ptr
, write_info_ptr
, name
, compression_type
,
966 #if defined(PNG_sRGB_SUPPORTED)
970 if (png_get_sRGB(read_ptr
, read_info_ptr
, &intent
))
971 png_set_sRGB(write_ptr
, write_info_ptr
, intent
);
978 if (png_get_PLTE(read_ptr
, read_info_ptr
, &palette
, &num_palette
))
979 png_set_PLTE(write_ptr
, write_info_ptr
, palette
, num_palette
);
981 #if defined(PNG_bKGD_SUPPORTED)
983 png_color_16p background
;
985 if (png_get_bKGD(read_ptr
, read_info_ptr
, &background
))
987 png_set_bKGD(write_ptr
, write_info_ptr
, background
);
991 #if defined(PNG_hIST_SUPPORTED)
995 if (png_get_hIST(read_ptr
, read_info_ptr
, &hist
))
996 png_set_hIST(write_ptr
, write_info_ptr
, hist
);
999 #if defined(PNG_oFFs_SUPPORTED)
1001 png_int_32 offset_x
, offset_y
;
1004 if (png_get_oFFs(read_ptr
, read_info_ptr
, &offset_x
, &offset_y
,
1007 png_set_oFFs(write_ptr
, write_info_ptr
, offset_x
, offset_y
, unit_type
);
1011 #if defined(PNG_pCAL_SUPPORTED)
1013 png_charp purpose
, units
;
1018 if (png_get_pCAL(read_ptr
, read_info_ptr
, &purpose
, &X0
, &X1
, &type
,
1019 &nparams
, &units
, ¶ms
))
1021 png_set_pCAL(write_ptr
, write_info_ptr
, purpose
, X0
, X1
, type
,
1022 nparams
, units
, params
);
1026 #if defined(PNG_pHYs_SUPPORTED)
1028 png_uint_32 res_x
, res_y
;
1031 if (png_get_pHYs(read_ptr
, read_info_ptr
, &res_x
, &res_y
, &unit_type
))
1032 png_set_pHYs(write_ptr
, write_info_ptr
, res_x
, res_y
, unit_type
);
1035 #if defined(PNG_sBIT_SUPPORTED)
1037 png_color_8p sig_bit
;
1039 if (png_get_sBIT(read_ptr
, read_info_ptr
, &sig_bit
))
1040 png_set_sBIT(write_ptr
, write_info_ptr
, sig_bit
);
1043 #if defined(PNG_sCAL_SUPPORTED)
1044 #ifdef PNG_FLOATING_POINT_SUPPORTED
1047 double scal_width
, scal_height
;
1049 if (png_get_sCAL(read_ptr
, read_info_ptr
, &unit
, &scal_width
,
1052 png_set_sCAL(write_ptr
, write_info_ptr
, unit
, scal_width
, scal_height
);
1056 #ifdef PNG_FIXED_POINT_SUPPORTED
1059 png_charp scal_width
, scal_height
;
1061 if (png_get_sCAL_s(read_ptr
, read_info_ptr
, &unit
, &scal_width
,
1064 png_set_sCAL_s(write_ptr
, write_info_ptr
, unit
, scal_width
, scal_height
);
1070 #if defined(PNG_TEXT_SUPPORTED)
1075 if (png_get_text(read_ptr
, read_info_ptr
, &text_ptr
, &num_text
) > 0)
1077 png_debug1(0, "Handling %d iTXt/tEXt/zTXt chunks", num_text
);
1078 png_set_text(write_ptr
, write_info_ptr
, text_ptr
, num_text
);
1082 #if defined(PNG_tIME_SUPPORTED)
1086 if (png_get_tIME(read_ptr
, read_info_ptr
, &mod_time
))
1088 png_set_tIME(write_ptr
, write_info_ptr
, mod_time
);
1089 #if defined(PNG_TIME_RFC1123_SUPPORTED)
1090 /* We have to use png_memcpy instead of "=" because the string
1091 * pointed to by png_convert_to_rfc1123() gets free'ed before
1094 png_memcpy(tIME_string
,
1095 png_convert_to_rfc1123(read_ptr
, mod_time
),
1096 png_sizeof(tIME_string
));
1097 tIME_string
[png_sizeof(tIME_string
) - 1] = '\0';
1098 tIME_chunk_present
++;
1099 #endif /* PNG_TIME_RFC1123_SUPPORTED */
1103 #if defined(PNG_tRNS_SUPPORTED)
1107 png_color_16p trans_values
;
1109 if (png_get_tRNS(read_ptr
, read_info_ptr
, &trans
, &num_trans
,
1112 int sample_max
= (1 << read_info_ptr
->bit_depth
);
1113 /* libpng doesn't reject a tRNS chunk with out-of-range samples */
1114 if (!((read_info_ptr
->color_type
== PNG_COLOR_TYPE_GRAY
&&
1115 (int)trans_values
->gray
> sample_max
) ||
1116 (read_info_ptr
->color_type
== PNG_COLOR_TYPE_RGB
&&
1117 ((int)trans_values
->red
> sample_max
||
1118 (int)trans_values
->green
> sample_max
||
1119 (int)trans_values
->blue
> sample_max
))))
1120 png_set_tRNS(write_ptr
, write_info_ptr
, trans
, num_trans
,
1125 #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
1127 png_unknown_chunkp unknowns
;
1128 int num_unknowns
= (int)png_get_unknown_chunks(read_ptr
, read_info_ptr
,
1133 png_set_unknown_chunks(write_ptr
, write_info_ptr
, unknowns
,
1135 /* Copy the locations from the read_info_ptr. The automatically
1136 * generated locations in write_info_ptr are wrong because we
1137 * haven't written anything yet.
1139 for (i
= 0; i
< (png_size_t
)num_unknowns
; i
++)
1140 png_set_unknown_chunk_location(write_ptr
, write_info_ptr
, i
,
1141 unknowns
[i
].location
);
1146 #ifdef PNG_WRITE_SUPPORTED
1147 png_debug(0, "Writing info struct");
1149 /* If we wanted, we could write info in two steps:
1150 * png_write_info_before_PLTE(write_ptr, write_info_ptr);
1152 png_write_info(write_ptr
, write_info_ptr
);
1154 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
1155 if (user_chunk_data
[0] != 0)
1157 png_byte png_sTER
[5] = {115, 84, 69, 82, '\0'};
1163 fprintf(STDERR
, "\n stereo mode = %lu\n",
1164 (unsigned long)(user_chunk_data
[0] - 1));
1165 ster_chunk_data
[0]=(unsigned char)(user_chunk_data
[0] - 1);
1166 png_write_chunk(write_ptr
, png_sTER
, ster_chunk_data
, 1);
1168 if (user_chunk_data
[1] != 0 || user_chunk_data
[2] != 0)
1170 png_byte png_vpAg
[5] = {118, 112, 65, 103, '\0'};
1176 fprintf(STDERR
, " vpAg = %lu x %lu, units = %lu\n",
1177 (unsigned long)user_chunk_data
[1],
1178 (unsigned long)user_chunk_data
[2],
1179 (unsigned long)user_chunk_data
[3]);
1180 png_save_uint_32(vpag_chunk_data
, user_chunk_data
[1]);
1181 png_save_uint_32(vpag_chunk_data
+ 4, user_chunk_data
[2]);
1182 vpag_chunk_data
[8] = (unsigned char)(user_chunk_data
[3] & 0xff);
1183 png_write_chunk(write_ptr
, png_vpAg
, vpag_chunk_data
, 9);
1189 #ifdef SINGLE_ROWBUF_ALLOC
1190 png_debug(0, "Allocating row buffer...");
1191 row_buf
= (png_bytep
)png_malloc(read_ptr
,
1192 png_get_rowbytes(read_ptr
, read_info_ptr
));
1193 png_debug1(0, "0x%08lx", (unsigned long)row_buf
);
1194 #endif /* SINGLE_ROWBUF_ALLOC */
1195 png_debug(0, "Writing row data");
1197 #if defined(PNG_READ_INTERLACING_SUPPORTED) || \
1198 defined(PNG_WRITE_INTERLACING_SUPPORTED)
1199 num_pass
= png_set_interlace_handling(read_ptr
);
1200 # ifdef PNG_WRITE_SUPPORTED
1201 png_set_interlace_handling(write_ptr
);
1207 #ifdef PNGTEST_TIMING
1208 t_stop
= (float)clock();
1209 t_misc
+= (t_stop
- t_start
);
1212 for (pass
= 0; pass
< num_pass
; pass
++)
1214 png_debug1(0, "Writing row data for pass %d", pass
);
1215 for (y
= 0; y
< height
; y
++)
1217 #ifndef SINGLE_ROWBUF_ALLOC
1218 png_debug2(0, "Allocating row buffer (pass %d, y = %ld)...", pass
, y
);
1219 row_buf
= (png_bytep
)png_malloc(read_ptr
,
1220 png_get_rowbytes(read_ptr
, read_info_ptr
));
1221 png_debug2(0, "0x%08lx (%ld bytes)", (unsigned long)row_buf
,
1222 png_get_rowbytes(read_ptr
, read_info_ptr
));
1223 #endif /* !SINGLE_ROWBUF_ALLOC */
1224 png_read_rows(read_ptr
, (png_bytepp
)&row_buf
, png_bytepp_NULL
, 1);
1226 #ifdef PNG_WRITE_SUPPORTED
1227 #ifdef PNGTEST_TIMING
1228 t_stop
= (float)clock();
1229 t_decode
+= (t_stop
- t_start
);
1232 png_write_rows(write_ptr
, (png_bytepp
)&row_buf
, 1);
1233 #ifdef PNGTEST_TIMING
1234 t_stop
= (float)clock();
1235 t_encode
+= (t_stop
- t_start
);
1238 #endif /* PNG_WRITE_SUPPORTED */
1240 #ifndef SINGLE_ROWBUF_ALLOC
1241 png_debug2(0, "Freeing row buffer (pass %d, y = %ld)", pass
, y
);
1242 png_free(read_ptr
, row_buf
);
1244 #endif /* !SINGLE_ROWBUF_ALLOC */
1248 #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
1249 png_free_data(read_ptr
, read_info_ptr
, PNG_FREE_UNKN
, -1);
1251 #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
1252 png_free_data(write_ptr
, write_info_ptr
, PNG_FREE_UNKN
, -1);
1255 png_debug(0, "Reading and writing end_info data");
1257 png_read_end(read_ptr
, end_info_ptr
);
1258 #if defined(PNG_TEXT_SUPPORTED)
1263 if (png_get_text(read_ptr
, end_info_ptr
, &text_ptr
, &num_text
) > 0)
1265 png_debug1(0, "Handling %d iTXt/tEXt/zTXt chunks", num_text
);
1266 png_set_text(write_ptr
, write_end_info_ptr
, text_ptr
, num_text
);
1270 #if defined(PNG_tIME_SUPPORTED)
1274 if (png_get_tIME(read_ptr
, end_info_ptr
, &mod_time
))
1276 png_set_tIME(write_ptr
, write_end_info_ptr
, mod_time
);
1277 #if defined(PNG_TIME_RFC1123_SUPPORTED)
1278 /* We have to use png_memcpy instead of "=" because the string
1279 pointed to by png_convert_to_rfc1123() gets free'ed before
1281 png_memcpy(tIME_string
,
1282 png_convert_to_rfc1123(read_ptr
, mod_time
),
1283 png_sizeof(tIME_string
));
1284 tIME_string
[png_sizeof(tIME_string
) - 1] = '\0';
1285 tIME_chunk_present
++;
1286 #endif /* PNG_TIME_RFC1123_SUPPORTED */
1290 #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
1292 png_unknown_chunkp unknowns
;
1294 num_unknowns
= (int)png_get_unknown_chunks(read_ptr
, end_info_ptr
,
1299 png_set_unknown_chunks(write_ptr
, write_end_info_ptr
, unknowns
,
1301 /* Copy the locations from the read_info_ptr. The automatically
1302 * generated locations in write_end_info_ptr are wrong because we
1303 * haven't written the end_info yet.
1305 for (i
= 0; i
< (png_size_t
)num_unknowns
; i
++)
1306 png_set_unknown_chunk_location(write_ptr
, write_end_info_ptr
, i
,
1307 unknowns
[i
].location
);
1311 #ifdef PNG_WRITE_SUPPORTED
1312 png_write_end(write_ptr
, write_end_info_ptr
);
1315 #ifdef PNG_EASY_ACCESS_SUPPORTED
1318 png_uint_32 iwidth
, iheight
;
1319 iwidth
= png_get_image_width(write_ptr
, write_info_ptr
);
1320 iheight
= png_get_image_height(write_ptr
, write_info_ptr
);
1321 fprintf(STDERR
, "\n Image width = %lu, height = %lu\n",
1322 (unsigned long)iwidth
, (unsigned long)iheight
);
1326 png_debug(0, "Destroying data structs");
1327 #ifdef SINGLE_ROWBUF_ALLOC
1328 png_debug(1, "destroying row_buf for read_ptr");
1329 png_free(read_ptr
, row_buf
);
1331 #endif /* SINGLE_ROWBUF_ALLOC */
1332 png_debug(1, "destroying read_ptr, read_info_ptr, end_info_ptr");
1333 png_destroy_read_struct(&read_ptr
, &read_info_ptr
, &end_info_ptr
);
1334 #ifdef PNG_WRITE_SUPPORTED
1335 png_debug(1, "destroying write_end_info_ptr");
1336 png_destroy_info_struct(write_ptr
, &write_end_info_ptr
);
1337 png_debug(1, "destroying write_ptr, write_info_ptr");
1338 png_destroy_write_struct(&write_ptr
, &write_info_ptr
);
1340 png_debug(0, "Destruction complete.");
1345 png_debug(0, "Opening files for comparison");
1346 #if defined(_WIN32_WCE)
1347 MultiByteToWideChar(CP_ACP
, 0, inname
, -1, path
, MAX_PATH
);
1348 if ((fpin
= CreateFile(path
, GENERIC_READ
, 0, NULL
, OPEN_EXISTING
, 0, NULL
)) == INVALID_HANDLE_VALUE
)
1350 if ((fpin
= fopen(inname
, "rb")) == NULL
)
1353 fprintf(STDERR
, "Could not find file %s\n", inname
);
1357 #if defined(_WIN32_WCE)
1358 MultiByteToWideChar(CP_ACP
, 0, outname
, -1, path
, MAX_PATH
);
1359 if ((fpout
= CreateFile(path
, GENERIC_READ
, 0, NULL
, OPEN_EXISTING
, 0, NULL
)) == INVALID_HANDLE_VALUE
)
1361 if ((fpout
= fopen(outname
, "rb")) == NULL
)
1364 fprintf(STDERR
, "Could not find file %s\n", outname
);
1371 png_size_t num_in
, num_out
;
1373 READFILE(fpin
, inbuf
, 1, num_in
);
1374 READFILE(fpout
, outbuf
, 1, num_out
);
1376 if (num_in
!= num_out
)
1378 fprintf(STDERR
, "\nFiles %s and %s are of a different size\n",
1380 if (wrote_question
== 0)
1383 " Was %s written with the same maximum IDAT chunk size (%d bytes),",
1384 inname
, PNG_ZBUF_SIZE
);
1386 "\n filtering heuristic (libpng default), compression");
1388 " level (zlib default),\n and zlib version (%s)?\n\n",
1400 if (png_memcmp(inbuf
, outbuf
, num_in
))
1402 fprintf(STDERR
, "\nFiles %s and %s are different\n", inname
, outname
);
1403 if (wrote_question
== 0)
1406 " Was %s written with the same maximum IDAT chunk size (%d bytes),",
1407 inname
, PNG_ZBUF_SIZE
);
1409 "\n filtering heuristic (libpng default), compression");
1411 " level (zlib default),\n and zlib version (%s)?\n\n",
1427 /* Input and output filenames */
1429 static PNG_CONST
char *inname
= "pngtest/png";
1430 static PNG_CONST
char *outname
= "pngout/png";
1432 static PNG_CONST
char *inname
= "pngtest.png";
1433 static PNG_CONST
char *outname
= "pngout.png";
1437 main(int argc
, char *argv
[])
1442 fprintf(STDERR
, "\n Testing libpng version %s\n", PNG_LIBPNG_VER_STRING
);
1443 fprintf(STDERR
, " with zlib version %s\n", ZLIB_VERSION
);
1444 fprintf(STDERR
, "%s", png_get_copyright(NULL
));
1445 /* Show the version of libpng used in building the library */
1446 fprintf(STDERR
, " library (%lu):%s",
1447 (unsigned long)png_access_version_number(),
1448 png_get_header_version(NULL
));
1449 /* Show the version of libpng used in building the application */
1450 fprintf(STDERR
, " pngtest (%lu):%s", (unsigned long)PNG_LIBPNG_VER
,
1451 PNG_HEADER_VERSION_STRING
);
1452 fprintf(STDERR
, " sizeof(png_struct)=%ld, sizeof(png_info)=%ld\n",
1453 (long)png_sizeof(png_struct
), (long)png_sizeof(png_info
));
1455 /* Do some consistency checking on the memory allocation settings, I'm
1456 * not sure this matters, but it is nice to know, the first of these
1457 * tests should be impossible because of the way the macros are set
1460 #if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K)
1461 fprintf(STDERR
, " NOTE: Zlib compiled for max 64k, libpng not\n");
1463 /* I think the following can happen. */
1464 #if !defined(MAXSEG_64K) && defined(PNG_MAX_MALLOC_64K)
1465 fprintf(STDERR
, " NOTE: libpng compiled for max 64k, zlib not\n");
1468 if (strcmp(png_libpng_ver
, PNG_LIBPNG_VER_STRING
))
1471 "Warning: versions are different between png.h and png.c\n");
1472 fprintf(STDERR
, " png.h version: %s\n", PNG_LIBPNG_VER_STRING
);
1473 fprintf(STDERR
, " png.c version: %s\n\n", png_libpng_ver
);
1479 if (strcmp(argv
[1], "-m") == 0)
1482 status_dots_requested
= 0;
1484 else if (strcmp(argv
[1], "-mv") == 0 ||
1485 strcmp(argv
[1], "-vm") == 0 )
1489 status_dots_requested
= 1;
1491 else if (strcmp(argv
[1], "-v") == 0)
1494 status_dots_requested
= 1;
1500 status_dots_requested
= 0;
1504 if (!multiple
&& argc
== 3 + verbose
)
1505 outname
= argv
[2 + verbose
];
1507 if ((!multiple
&& argc
> 3 + verbose
) || (multiple
&& argc
< 2))
1510 "usage: %s [infile.png] [outfile.png]\n\t%s -m {infile.png}\n",
1513 " reads/writes one PNG file (without -m) or multiple files (-m)\n");
1515 " with -m %s is used as a temporary file\n", outname
);
1522 #if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
1523 int allocation_now
= current_allocation
;
1525 for (i
=2; i
<argc
; ++i
)
1527 #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
1531 fprintf(STDERR
, "\n Testing %s:", argv
[i
]);
1532 kerror
= test_one_file(argv
[i
], outname
);
1535 #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
1536 fprintf(STDERR
, "\n PASS (%lu zero samples)\n",
1537 (unsigned long)zero_samples
);
1539 fprintf(STDERR
, " PASS\n");
1541 #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
1542 for (k
= 0; k
<256; k
++)
1543 if (filters_used
[k
])
1544 fprintf(STDERR
, " Filter %d was used %lu times\n",
1545 k
, (unsigned long)filters_used
[k
]);
1547 #if defined(PNG_TIME_RFC1123_SUPPORTED)
1548 if (tIME_chunk_present
!= 0)
1549 fprintf(STDERR
, " tIME = %s\n", tIME_string
);
1550 tIME_chunk_present
= 0;
1551 #endif /* PNG_TIME_RFC1123_SUPPORTED */
1555 fprintf(STDERR
, " FAIL\n");
1558 #if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
1559 if (allocation_now
!= current_allocation
)
1560 fprintf(STDERR
, "MEMORY ERROR: %d bytes lost\n",
1561 current_allocation
- allocation_now
);
1562 if (current_allocation
!= 0)
1564 memory_infop pinfo
= pinformation
;
1566 fprintf(STDERR
, "MEMORY ERROR: %d bytes still allocated\n",
1567 current_allocation
);
1568 while (pinfo
!= NULL
)
1570 fprintf(STDERR
, " %lu bytes at %x\n",
1571 (unsigned long)pinfo
->size
,
1572 (unsigned int) pinfo
->pointer
);
1573 pinfo
= pinfo
->next
;
1578 #if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
1579 fprintf(STDERR
, " Current memory allocation: %10d bytes\n",
1580 current_allocation
);
1581 fprintf(STDERR
, " Maximum memory allocation: %10d bytes\n",
1582 maximum_allocation
);
1583 fprintf(STDERR
, " Total memory allocation: %10d bytes\n",
1585 fprintf(STDERR
, " Number of allocations: %10d\n",
1592 for (i
= 0; i
<3; ++i
)
1595 #if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
1596 int allocation_now
= current_allocation
;
1598 if (i
== 1) status_dots_requested
= 1;
1599 else if (verbose
== 0)status_dots_requested
= 0;
1600 if (i
== 0 || verbose
== 1 || ierror
!= 0)
1601 fprintf(STDERR
, "\n Testing %s:", inname
);
1602 kerror
= test_one_file(inname
, outname
);
1605 if (verbose
== 1 || i
== 2)
1607 #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
1610 #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
1611 fprintf(STDERR
, "\n PASS (%lu zero samples)\n",
1612 (unsigned long)zero_samples
);
1614 fprintf(STDERR
, " PASS\n");
1616 #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
1617 for (k
= 0; k
<256; k
++)
1618 if (filters_used
[k
])
1619 fprintf(STDERR
, " Filter %d was used %lu times\n",
1621 (unsigned long)filters_used
[k
]);
1623 #if defined(PNG_TIME_RFC1123_SUPPORTED)
1624 if (tIME_chunk_present
!= 0)
1625 fprintf(STDERR
, " tIME = %s\n", tIME_string
);
1626 #endif /* PNG_TIME_RFC1123_SUPPORTED */
1631 if (verbose
== 0 && i
!= 2)
1632 fprintf(STDERR
, "\n Testing %s:", inname
);
1633 fprintf(STDERR
, " FAIL\n");
1636 #if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
1637 if (allocation_now
!= current_allocation
)
1638 fprintf(STDERR
, "MEMORY ERROR: %d bytes lost\n",
1639 current_allocation
- allocation_now
);
1640 if (current_allocation
!= 0)
1642 memory_infop pinfo
= pinformation
;
1644 fprintf(STDERR
, "MEMORY ERROR: %d bytes still allocated\n",
1645 current_allocation
);
1646 while (pinfo
!= NULL
)
1648 fprintf(STDERR
, " %lu bytes at %x\n",
1649 (unsigned long)pinfo
->size
, (unsigned int)pinfo
->pointer
);
1650 pinfo
= pinfo
->next
;
1655 #if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
1656 fprintf(STDERR
, " Current memory allocation: %10d bytes\n",
1657 current_allocation
);
1658 fprintf(STDERR
, " Maximum memory allocation: %10d bytes\n",
1659 maximum_allocation
);
1660 fprintf(STDERR
, " Total memory allocation: %10d bytes\n",
1662 fprintf(STDERR
, " Number of allocations: %10d\n",
1667 #ifdef PNGTEST_TIMING
1668 t_stop
= (float)clock();
1669 t_misc
+= (t_stop
- t_start
);
1671 fprintf(STDERR
, " CPU time used = %.3f seconds",
1672 (t_misc
+t_decode
+t_encode
)/(float)CLOCKS_PER_SEC
);
1673 fprintf(STDERR
, " (decoding %.3f,\n",
1674 t_decode
/(float)CLOCKS_PER_SEC
);
1675 fprintf(STDERR
, " encoding %.3f ,",
1676 t_encode
/(float)CLOCKS_PER_SEC
);
1677 fprintf(STDERR
, " other %.3f seconds)\n\n",
1678 t_misc
/(float)CLOCKS_PER_SEC
);
1682 fprintf(STDERR
, " libpng passes test\n");
1684 fprintf(STDERR
, " libpng FAILS test\n");
1685 return (int)(ierror
!= 0);
1688 /* Generate a compiler error if there is an old png.h in the search path. */
1689 typedef version_1_2_37 your_png_h_is_not_version_1_2_37
;