VirtualBox

source: vbox/trunk/src/libs/libpng-1.6.45/contrib/libtests/readpng.c@ 107813

Last change on this file since 107813 was 107813, checked in by vboxsync, 3 weeks ago

libpng-1.6.45: Applied and adjusted our libpng changes to 1.6.45. bugref:8515

  • Property svn:eol-style set to native
File size: 3.1 KB
Line 
1/* readpng.c
2 *
3 * Copyright (c) 2013 John Cunningham Bowler
4 *
5 * This code is released under the libpng license.
6 * For conditions of distribution and use, see the disclaimer
7 * and license in png.h
8 *
9 * Load an arbitrary number of PNG files (from the command line, or, if there
10 * are no arguments on the command line, from stdin) then run a time test by
11 * reading each file by row. The test does nothing with the read result and
12 * does no transforms. The only output is a time as a floating point number of
13 * seconds with 9 decimal digits.
14 */
15#include <stdlib.h>
16#include <stdio.h>
17#include <string.h>
18
19#if defined(HAVE_CONFIG_H) && !defined(PNG_NO_CONFIG_H)
20# include <config.h>
21#endif
22
23/* Define the following to use this test against your installed libpng, rather
24 * than the one being built here:
25 */
26#ifdef PNG_FREESTANDING_TESTS
27# include <png.h>
28#else
29# include "../../png.h"
30#endif
31
32static int
33read_png(FILE *fp)
34{
35 png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,0,0,0);
36 png_infop info_ptr = NULL;
37 png_bytep row = NULL, display = NULL;
38
39 if (png_ptr == NULL)
40 return 0;
41
42 if (setjmp(png_jmpbuf(png_ptr)))
43 {
44 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
45 if (row != NULL) free(row);
46 if (display != NULL) free(display);
47 return 0;
48 }
49
50 png_init_io(png_ptr, fp);
51
52 info_ptr = png_create_info_struct(png_ptr);
53 if (info_ptr == NULL)
54 png_error(png_ptr, "OOM allocating info structure");
55
56 png_set_keep_unknown_chunks(png_ptr, PNG_HANDLE_CHUNK_ALWAYS, NULL, 0);
57
58 png_read_info(png_ptr, info_ptr);
59
60 {
61 size_t rowbytes = png_get_rowbytes(png_ptr, info_ptr);
62
63 /* Failure to initialize these is harmless */
64 row = malloc(rowbytes);
65 display = malloc(rowbytes);
66
67 if (row == NULL || display == NULL)
68 png_error(png_ptr, "OOM allocating row buffers");
69
70 {
71 png_uint_32 height = png_get_image_height(png_ptr, info_ptr);
72# ifdef PNG_READ_INTERLACING_SUPPORTED
73 int passes = png_set_interlace_handling(png_ptr);
74# else /* !READ_INTERLACING */
75 int passes = png_get_interlace_type(png_ptr, info_ptr) ==
76 PNG_INTERLACE_ADAM7 ? PNG_INTERLACE_ADAM7_PASSES : 1;
77# endif /* !READ_INTERLACING */
78 int pass;
79
80 png_start_read_image(png_ptr);
81
82 for (pass = 0; pass < passes; ++pass)
83 {
84 png_uint_32 y = height;
85
86# ifndef PNG_READ_INTERLACING_SUPPORTED
87 if (passes == PNG_INTERLACE_ADAM7_PASSES)
88 y = PNG_PASS_ROWS(y, pass);
89# endif /* READ_INTERLACING */
90
91 /* NOTE: this trashes the row each time; interlace handling won't
92 * work, but this avoids memory thrashing for speed testing.
93 */
94 while (y-- > 0)
95 png_read_row(png_ptr, row, display);
96 }
97 }
98 }
99
100 /* Make sure to read to the end of the file: */
101 png_read_end(png_ptr, info_ptr);
102 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
103 free(row);
104 free(display);
105 return 1;
106}
107
108int
109main(void)
110{
111 /* Exit code 0 on success. */
112 return !read_png(stdin);
113}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette