3 * Copyright (c) 2013 John Cunningham Bowler
5 * Last changed in libpng 1.6.1 [March 28, 2013]
7 * This code is released under the libpng license.
8 * For conditions of distribution and use, see the disclaimer
11 * Load an arbitrary number of PNG files (from the command line, or, if there
12 * are no arguments on the command line, from stdin) then run a time test by
13 * reading each file by row. The test does nothing with the read result and
14 * does no transforms. The only output is a time as a floating point number of
15 * seconds with 9 decimal digits.
21 #if defined(HAVE_CONFIG_H) && !defined(PNG_NO_CONFIG_H)
25 /* Define the following to use this test against your installed libpng, rather
26 * than the one being built here:
28 #ifdef PNG_FREESTANDING_TESTS
31 # include "../../png.h"
37 png_structp png_ptr
= png_create_read_struct(PNG_LIBPNG_VER_STRING
,0,0,0);
38 png_infop info_ptr
= NULL
;
39 png_bytep row
= NULL
, display
= NULL
;
44 if (setjmp(png_jmpbuf(png_ptr
)))
46 png_destroy_read_struct(&png_ptr
, &info_ptr
, NULL
);
47 if (row
!= NULL
) free(row
);
48 if (display
!= NULL
) free(display
);
52 png_init_io(png_ptr
, fp
);
54 info_ptr
= png_create_info_struct(png_ptr
);
56 png_error(png_ptr
, "OOM allocating info structure");
58 png_set_keep_unknown_chunks(png_ptr
, PNG_HANDLE_CHUNK_ALWAYS
, NULL
, 0);
60 png_read_info(png_ptr
, info_ptr
);
63 png_size_t rowbytes
= png_get_rowbytes(png_ptr
, info_ptr
);
65 row
= malloc(rowbytes
);
66 display
= malloc(rowbytes
);
68 if (row
== NULL
|| display
== NULL
)
69 png_error(png_ptr
, "OOM allocating row buffers");
72 png_uint_32 height
= png_get_image_height(png_ptr
, info_ptr
);
73 int passes
= png_set_interlace_handling(png_ptr
);
76 png_start_read_image(png_ptr
);
78 for (pass
= 0; pass
< passes
; ++pass
)
80 png_uint_32 y
= height
;
82 /* NOTE: this trashes the row each time; interlace handling won't
83 * work, but this avoids memory thrashing for speed testing.
86 png_read_row(png_ptr
, row
, display
);
91 /* Make sure to read to the end of the file: */
92 png_read_end(png_ptr
, info_ptr
);
93 png_destroy_read_struct(&png_ptr
, &info_ptr
, NULL
);
102 /* Exit code 0 on success. */
103 return !read_png(stdin
);