author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 06 Jul 2010 15:10:48 +0300 | |
changeset 30 | 5dc02b23752f |
parent 0 | 1918ee327afb |
permissions | -rw-r--r-- |
0 | 1 |
|
2 |
/* pngread.c - read a PNG file |
|
3 |
* |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
4 |
* Last changed in libpng 1.4.0 [January 3, 2010] |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
5 |
* Copyright (c) 1998-2010 Glenn Randers-Pehrson |
0 | 6 |
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) |
7 |
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) |
|
8 |
* |
|
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 |
|
12 |
* |
|
13 |
* This file contains routines that an application calls directly to |
|
14 |
* read a PNG file or stream. |
|
15 |
*/ |
|
16 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
17 |
#define PNG_NO_PEDANTIC_WARNINGS |
0 | 18 |
#include "png.h" |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
19 |
#ifdef PNG_READ_SUPPORTED |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
20 |
#include "pngpriv.h" |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
21 |
|
0 | 22 |
|
23 |
/* Create a PNG structure for reading, and allocate any memory needed. */ |
|
24 |
png_structp PNGAPI |
|
25 |
png_create_read_struct(png_const_charp user_png_ver, png_voidp error_ptr, |
|
26 |
png_error_ptr error_fn, png_error_ptr warn_fn) |
|
27 |
{ |
|
28 |
||
29 |
#ifdef PNG_USER_MEM_SUPPORTED |
|
30 |
return (png_create_read_struct_2(user_png_ver, error_ptr, error_fn, |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
31 |
warn_fn, NULL, NULL, NULL)); |
0 | 32 |
} |
33 |
||
34 |
/* Alternate create PNG structure for reading, and allocate any memory needed. */ |
|
35 |
png_structp PNGAPI |
|
36 |
png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr, |
|
37 |
png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr, |
|
38 |
png_malloc_ptr malloc_fn, png_free_ptr free_fn) |
|
39 |
{ |
|
40 |
#endif /* PNG_USER_MEM_SUPPORTED */ |
|
41 |
||
42 |
#ifdef PNG_SETJMP_SUPPORTED |
|
43 |
volatile |
|
44 |
#endif |
|
45 |
png_structp png_ptr; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
46 |
volatile int png_cleanup_needed = 0; |
0 | 47 |
|
48 |
#ifdef PNG_SETJMP_SUPPORTED |
|
49 |
#ifdef USE_FAR_KEYWORD |
|
50 |
jmp_buf jmpbuf; |
|
51 |
#endif |
|
52 |
#endif |
|
53 |
||
54 |
int i; |
|
55 |
||
56 |
png_debug(1, "in png_create_read_struct"); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
57 |
|
0 | 58 |
#ifdef PNG_USER_MEM_SUPPORTED |
59 |
png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG, |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
60 |
malloc_fn, mem_ptr); |
0 | 61 |
#else |
62 |
png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG); |
|
63 |
#endif |
|
64 |
if (png_ptr == NULL) |
|
65 |
return (NULL); |
|
66 |
||
67 |
/* Added at libpng-1.2.6 */ |
|
68 |
#ifdef PNG_SET_USER_LIMITS_SUPPORTED |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
69 |
png_ptr->user_width_max = PNG_USER_WIDTH_MAX; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
70 |
png_ptr->user_height_max = PNG_USER_HEIGHT_MAX; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
71 |
/* Added at libpng-1.4.0 */ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
72 |
png_ptr->user_chunk_cache_max = PNG_USER_CHUNK_CACHE_MAX; |
0 | 73 |
#endif |
74 |
||
75 |
#ifdef PNG_SETJMP_SUPPORTED |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
76 |
/* Applications that neglect to set up their own setjmp() and then |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
77 |
encounter a png_error() will longjmp here. Since the jmpbuf is |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
78 |
then meaningless we abort instead of returning. */ |
0 | 79 |
#ifdef USE_FAR_KEYWORD |
80 |
if (setjmp(jmpbuf)) |
|
81 |
#else |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
82 |
if (setjmp(png_jmpbuf(png_ptr))) /* Sets longjmp to match setjmp */ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
83 |
#endif |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
84 |
PNG_ABORT(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
85 |
#ifdef USE_FAR_KEYWORD |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
86 |
png_memcpy(png_jmpbuf(png_ptr), jmpbuf, png_sizeof(jmp_buf)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
87 |
#endif |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
88 |
#endif /* PNG_SETJMP_SUPPORTED */ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
89 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
90 |
#ifdef PNG_USER_MEM_SUPPORTED |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
91 |
png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn); |
0 | 92 |
#endif |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
93 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
94 |
png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
95 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
96 |
if (user_png_ver) |
0 | 97 |
{ |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
98 |
i = 0; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
99 |
do |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
100 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
101 |
if (user_png_ver[i] != png_libpng_ver[i]) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
102 |
png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
103 |
} while (png_libpng_ver[i++]); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
104 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
105 |
else |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
106 |
png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
107 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
108 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
109 |
if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
110 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
111 |
/* Libpng 0.90 and later are binary incompatible with libpng 0.89, so |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
112 |
* we must recompile any applications that use any older library version. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
113 |
* For versions after libpng 1.0, we will be compatible, so we need |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
114 |
* only check the first digit. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
115 |
*/ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
116 |
if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] || |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
117 |
(user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) || |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
118 |
(user_png_ver[0] == '0' && user_png_ver[2] < '9')) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
119 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
120 |
#ifdef PNG_STDIO_SUPPORTED |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
121 |
char msg[80]; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
122 |
if (user_png_ver) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
123 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
124 |
png_snprintf(msg, 80, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
125 |
"Application was compiled with png.h from libpng-%.20s", |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
126 |
user_png_ver); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
127 |
png_warning(png_ptr, msg); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
128 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
129 |
png_snprintf(msg, 80, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
130 |
"Application is running with png.c from libpng-%.20s", |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
131 |
png_libpng_ver); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
132 |
png_warning(png_ptr, msg); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
133 |
#endif |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
134 |
#ifdef PNG_ERROR_NUMBERS_SUPPORTED |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
135 |
png_ptr->flags = 0; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
136 |
#endif |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
137 |
png_warning(png_ptr, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
138 |
"Incompatible libpng version in application and library"); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
139 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
140 |
png_cleanup_needed = 1; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
141 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
142 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
143 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
144 |
if (!png_cleanup_needed) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
145 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
146 |
/* Initialize zbuf - compression buffer */ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
147 |
png_ptr->zbuf_size = PNG_ZBUF_SIZE; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
148 |
png_ptr->zbuf = (png_bytep)png_malloc_warn(png_ptr, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
149 |
png_ptr->zbuf_size); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
150 |
if (png_ptr->zbuf == NULL) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
151 |
png_cleanup_needed = 1; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
152 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
153 |
png_ptr->zstream.zalloc = png_zalloc; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
154 |
png_ptr->zstream.zfree = png_zfree; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
155 |
png_ptr->zstream.opaque = (voidpf)png_ptr; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
156 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
157 |
if (!png_cleanup_needed) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
158 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
159 |
switch (inflateInit(&png_ptr->zstream)) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
160 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
161 |
case Z_OK: /* Do nothing */ break; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
162 |
case Z_MEM_ERROR: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
163 |
case Z_STREAM_ERROR: png_warning(png_ptr, "zlib memory error"); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
164 |
png_cleanup_needed = 1; break; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
165 |
case Z_VERSION_ERROR: png_warning(png_ptr, "zlib version error"); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
166 |
png_cleanup_needed = 1; break; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
167 |
default: png_warning(png_ptr, "Unknown zlib error"); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
168 |
png_cleanup_needed = 1; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
169 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
170 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
171 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
172 |
if (png_cleanup_needed) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
173 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
174 |
/* Clean up PNG structure and deallocate any memory. */ |
0 | 175 |
png_free(png_ptr, png_ptr->zbuf); |
176 |
png_ptr->zbuf = NULL; |
|
177 |
#ifdef PNG_USER_MEM_SUPPORTED |
|
178 |
png_destroy_struct_2((png_voidp)png_ptr, |
|
179 |
(png_free_ptr)free_fn, (png_voidp)mem_ptr); |
|
180 |
#else |
|
181 |
png_destroy_struct((png_voidp)png_ptr); |
|
182 |
#endif |
|
183 |
return (NULL); |
|
184 |
} |
|
185 |
||
186 |
png_ptr->zstream.next_out = png_ptr->zbuf; |
|
187 |
png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; |
|
188 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
189 |
png_set_read_fn(png_ptr, NULL, NULL); |
0 | 190 |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
191 |
|
0 | 192 |
return (png_ptr); |
193 |
} |
|
194 |
||
195 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
196 |
#ifdef PNG_SEQUENTIAL_READ_SUPPORTED |
0 | 197 |
/* Read the information before the actual image data. This has been |
198 |
* changed in v0.90 to allow reading a file that already has the magic |
|
199 |
* bytes read from the stream. You can tell libpng how many bytes have |
|
200 |
* been read from the beginning of the stream (up to the maximum of 8) |
|
201 |
* via png_set_sig_bytes(), and we will only check the remaining bytes |
|
202 |
* here. The application can then have access to the signature bytes we |
|
203 |
* read if it is determined that this isn't a valid PNG file. |
|
204 |
*/ |
|
205 |
void PNGAPI |
|
206 |
png_read_info(png_structp png_ptr, png_infop info_ptr) |
|
207 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
208 |
png_debug(1, "in png_read_info"); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
209 |
|
0 | 210 |
if (png_ptr == NULL || info_ptr == NULL) |
211 |
return; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
212 |
|
0 | 213 |
/* If we haven't checked all of the PNG signature bytes, do so now. */ |
214 |
if (png_ptr->sig_bytes < 8) |
|
215 |
{ |
|
216 |
png_size_t num_checked = png_ptr->sig_bytes, |
|
217 |
num_to_check = 8 - num_checked; |
|
218 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
219 |
#ifdef PNG_IO_STATE_SUPPORTED |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
220 |
png_ptr->io_state = PNG_IO_READING | PNG_IO_SIGNATURE; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
221 |
#endif |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
222 |
|
0 | 223 |
png_read_data(png_ptr, &(info_ptr->signature[num_checked]), num_to_check); |
224 |
png_ptr->sig_bytes = 8; |
|
225 |
||
226 |
if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check)) |
|
227 |
{ |
|
228 |
if (num_checked < 4 && |
|
229 |
png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4)) |
|
230 |
png_error(png_ptr, "Not a PNG file"); |
|
231 |
else |
|
232 |
png_error(png_ptr, "PNG file corrupted by ASCII conversion"); |
|
233 |
} |
|
234 |
if (num_checked < 3) |
|
235 |
png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE; |
|
236 |
} |
|
237 |
||
238 |
for (;;) |
|
239 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
240 |
PNG_IHDR; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
241 |
PNG_IDAT; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
242 |
PNG_IEND; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
243 |
PNG_PLTE; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
244 |
#ifdef PNG_READ_bKGD_SUPPORTED |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
245 |
PNG_bKGD; |
0 | 246 |
#endif |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
247 |
#ifdef PNG_READ_cHRM_SUPPORTED |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
248 |
PNG_cHRM; |
0 | 249 |
#endif |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
250 |
#ifdef PNG_READ_gAMA_SUPPORTED |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
251 |
PNG_gAMA; |
0 | 252 |
#endif |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
253 |
#ifdef PNG_READ_hIST_SUPPORTED |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
254 |
PNG_hIST; |
0 | 255 |
#endif |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
256 |
#ifdef PNG_READ_iCCP_SUPPORTED |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
257 |
PNG_iCCP; |
0 | 258 |
#endif |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
259 |
#ifdef PNG_READ_iTXt_SUPPORTED |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
260 |
PNG_iTXt; |
0 | 261 |
#endif |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
262 |
#ifdef PNG_READ_oFFs_SUPPORTED |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
263 |
PNG_oFFs; |
0 | 264 |
#endif |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
265 |
#ifdef PNG_READ_pCAL_SUPPORTED |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
266 |
PNG_pCAL; |
0 | 267 |
#endif |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
268 |
#ifdef PNG_READ_pHYs_SUPPORTED |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
269 |
PNG_pHYs; |
0 | 270 |
#endif |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
271 |
#ifdef PNG_READ_sBIT_SUPPORTED |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
272 |
PNG_sBIT; |
0 | 273 |
#endif |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
274 |
#ifdef PNG_READ_sCAL_SUPPORTED |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
275 |
PNG_sCAL; |
0 | 276 |
#endif |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
277 |
#ifdef PNG_READ_sPLT_SUPPORTED |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
278 |
PNG_sPLT; |
0 | 279 |
#endif |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
280 |
#ifdef PNG_READ_sRGB_SUPPORTED |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
281 |
PNG_sRGB; |
0 | 282 |
#endif |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
283 |
#ifdef PNG_READ_tEXt_SUPPORTED |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
284 |
PNG_tEXt; |
0 | 285 |
#endif |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
286 |
#ifdef PNG_READ_tIME_SUPPORTED |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
287 |
PNG_tIME; |
0 | 288 |
#endif |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
289 |
#ifdef PNG_READ_tRNS_SUPPORTED |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
290 |
PNG_tRNS; |
0 | 291 |
#endif |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
292 |
#ifdef PNG_READ_zTXt_SUPPORTED |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
293 |
PNG_zTXt; |
0 | 294 |
#endif |
295 |
png_uint_32 length = png_read_chunk_header(png_ptr); |
|
296 |
PNG_CONST png_bytep chunk_name = png_ptr->chunk_name; |
|
297 |
||
298 |
/* This should be a binary subdivision search or a hash for |
|
299 |
* matching the chunk name rather than a linear search. |
|
300 |
*/ |
|
301 |
if (!png_memcmp(chunk_name, png_IDAT, 4)) |
|
302 |
if (png_ptr->mode & PNG_AFTER_IDAT) |
|
303 |
png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT; |
|
304 |
||
305 |
if (!png_memcmp(chunk_name, png_IHDR, 4)) |
|
306 |
png_handle_IHDR(png_ptr, info_ptr, length); |
|
307 |
else if (!png_memcmp(chunk_name, png_IEND, 4)) |
|
308 |
png_handle_IEND(png_ptr, info_ptr, length); |
|
309 |
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED |
|
310 |
else if (png_handle_as_unknown(png_ptr, chunk_name)) |
|
311 |
{ |
|
312 |
if (!png_memcmp(chunk_name, png_IDAT, 4)) |
|
313 |
png_ptr->mode |= PNG_HAVE_IDAT; |
|
314 |
png_handle_unknown(png_ptr, info_ptr, length); |
|
315 |
if (!png_memcmp(chunk_name, png_PLTE, 4)) |
|
316 |
png_ptr->mode |= PNG_HAVE_PLTE; |
|
317 |
else if (!png_memcmp(chunk_name, png_IDAT, 4)) |
|
318 |
{ |
|
319 |
if (!(png_ptr->mode & PNG_HAVE_IHDR)) |
|
320 |
png_error(png_ptr, "Missing IHDR before IDAT"); |
|
321 |
else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE && |
|
322 |
!(png_ptr->mode & PNG_HAVE_PLTE)) |
|
323 |
png_error(png_ptr, "Missing PLTE before IDAT"); |
|
324 |
break; |
|
325 |
} |
|
326 |
} |
|
327 |
#endif |
|
328 |
else if (!png_memcmp(chunk_name, png_PLTE, 4)) |
|
329 |
png_handle_PLTE(png_ptr, info_ptr, length); |
|
330 |
else if (!png_memcmp(chunk_name, png_IDAT, 4)) |
|
331 |
{ |
|
332 |
if (!(png_ptr->mode & PNG_HAVE_IHDR)) |
|
333 |
png_error(png_ptr, "Missing IHDR before IDAT"); |
|
334 |
else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE && |
|
335 |
!(png_ptr->mode & PNG_HAVE_PLTE)) |
|
336 |
png_error(png_ptr, "Missing PLTE before IDAT"); |
|
337 |
||
338 |
png_ptr->idat_size = length; |
|
339 |
png_ptr->mode |= PNG_HAVE_IDAT; |
|
340 |
break; |
|
341 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
342 |
#ifdef PNG_READ_bKGD_SUPPORTED |
0 | 343 |
else if (!png_memcmp(chunk_name, png_bKGD, 4)) |
344 |
png_handle_bKGD(png_ptr, info_ptr, length); |
|
345 |
#endif |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
346 |
#ifdef PNG_READ_cHRM_SUPPORTED |
0 | 347 |
else if (!png_memcmp(chunk_name, png_cHRM, 4)) |
348 |
png_handle_cHRM(png_ptr, info_ptr, length); |
|
349 |
#endif |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
350 |
#ifdef PNG_READ_gAMA_SUPPORTED |
0 | 351 |
else if (!png_memcmp(chunk_name, png_gAMA, 4)) |
352 |
png_handle_gAMA(png_ptr, info_ptr, length); |
|
353 |
#endif |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
354 |
#ifdef PNG_READ_hIST_SUPPORTED |
0 | 355 |
else if (!png_memcmp(chunk_name, png_hIST, 4)) |
356 |
png_handle_hIST(png_ptr, info_ptr, length); |
|
357 |
#endif |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
358 |
#ifdef PNG_READ_oFFs_SUPPORTED |
0 | 359 |
else if (!png_memcmp(chunk_name, png_oFFs, 4)) |
360 |
png_handle_oFFs(png_ptr, info_ptr, length); |
|
361 |
#endif |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
362 |
#ifdef PNG_READ_pCAL_SUPPORTED |
0 | 363 |
else if (!png_memcmp(chunk_name, png_pCAL, 4)) |
364 |
png_handle_pCAL(png_ptr, info_ptr, length); |
|
365 |
#endif |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
366 |
#ifdef PNG_READ_sCAL_SUPPORTED |
0 | 367 |
else if (!png_memcmp(chunk_name, png_sCAL, 4)) |
368 |
png_handle_sCAL(png_ptr, info_ptr, length); |
|
369 |
#endif |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
370 |
#ifdef PNG_READ_pHYs_SUPPORTED |
0 | 371 |
else if (!png_memcmp(chunk_name, png_pHYs, 4)) |
372 |
png_handle_pHYs(png_ptr, info_ptr, length); |
|
373 |
#endif |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
374 |
#ifdef PNG_READ_sBIT_SUPPORTED |
0 | 375 |
else if (!png_memcmp(chunk_name, png_sBIT, 4)) |
376 |
png_handle_sBIT(png_ptr, info_ptr, length); |
|
377 |
#endif |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
378 |
#ifdef PNG_READ_sRGB_SUPPORTED |
0 | 379 |
else if (!png_memcmp(chunk_name, png_sRGB, 4)) |
380 |
png_handle_sRGB(png_ptr, info_ptr, length); |
|
381 |
#endif |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
382 |
#ifdef PNG_READ_iCCP_SUPPORTED |
0 | 383 |
else if (!png_memcmp(chunk_name, png_iCCP, 4)) |
384 |
png_handle_iCCP(png_ptr, info_ptr, length); |
|
385 |
#endif |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
386 |
#ifdef PNG_READ_sPLT_SUPPORTED |
0 | 387 |
else if (!png_memcmp(chunk_name, png_sPLT, 4)) |
388 |
png_handle_sPLT(png_ptr, info_ptr, length); |
|
389 |
#endif |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
390 |
#ifdef PNG_READ_tEXt_SUPPORTED |
0 | 391 |
else if (!png_memcmp(chunk_name, png_tEXt, 4)) |
392 |
png_handle_tEXt(png_ptr, info_ptr, length); |
|
393 |
#endif |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
394 |
#ifdef PNG_READ_tIME_SUPPORTED |
0 | 395 |
else if (!png_memcmp(chunk_name, png_tIME, 4)) |
396 |
png_handle_tIME(png_ptr, info_ptr, length); |
|
397 |
#endif |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
398 |
#ifdef PNG_READ_tRNS_SUPPORTED |
0 | 399 |
else if (!png_memcmp(chunk_name, png_tRNS, 4)) |
400 |
png_handle_tRNS(png_ptr, info_ptr, length); |
|
401 |
#endif |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
402 |
#ifdef PNG_READ_zTXt_SUPPORTED |
0 | 403 |
else if (!png_memcmp(chunk_name, png_zTXt, 4)) |
404 |
png_handle_zTXt(png_ptr, info_ptr, length); |
|
405 |
#endif |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
406 |
#ifdef PNG_READ_iTXt_SUPPORTED |
0 | 407 |
else if (!png_memcmp(chunk_name, png_iTXt, 4)) |
408 |
png_handle_iTXt(png_ptr, info_ptr, length); |
|
409 |
#endif |
|
410 |
else |
|
411 |
png_handle_unknown(png_ptr, info_ptr, length); |
|
412 |
} |
|
413 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
414 |
#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ |
0 | 415 |
|
416 |
/* Optional call to update the users info_ptr structure */ |
|
417 |
void PNGAPI |
|
418 |
png_read_update_info(png_structp png_ptr, png_infop info_ptr) |
|
419 |
{ |
|
420 |
png_debug(1, "in png_read_update_info"); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
421 |
|
0 | 422 |
if (png_ptr == NULL) |
423 |
return; |
|
424 |
if (!(png_ptr->flags & PNG_FLAG_ROW_INIT)) |
|
425 |
png_read_start_row(png_ptr); |
|
426 |
else |
|
427 |
png_warning(png_ptr, |
|
428 |
"Ignoring extra png_read_update_info() call; row buffer not reallocated"); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
429 |
|
0 | 430 |
png_read_transform_info(png_ptr, info_ptr); |
431 |
} |
|
432 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
433 |
#ifdef PNG_SEQUENTIAL_READ_SUPPORTED |
0 | 434 |
/* Initialize palette, background, etc, after transformations |
435 |
* are set, but before any reading takes place. This allows |
|
436 |
* the user to obtain a gamma-corrected palette, for example. |
|
437 |
* If the user doesn't call this, we will do it ourselves. |
|
438 |
*/ |
|
439 |
void PNGAPI |
|
440 |
png_start_read_image(png_structp png_ptr) |
|
441 |
{ |
|
442 |
png_debug(1, "in png_start_read_image"); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
443 |
|
0 | 444 |
if (png_ptr == NULL) |
445 |
return; |
|
446 |
if (!(png_ptr->flags & PNG_FLAG_ROW_INIT)) |
|
447 |
png_read_start_row(png_ptr); |
|
448 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
449 |
#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ |
0 | 450 |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
451 |
#ifdef PNG_SEQUENTIAL_READ_SUPPORTED |
0 | 452 |
void PNGAPI |
453 |
png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row) |
|
454 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
455 |
PNG_IDAT; |
0 | 456 |
PNG_CONST int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, |
457 |
0xff}; |
|
458 |
PNG_CONST int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff}; |
|
459 |
int ret; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
460 |
|
0 | 461 |
if (png_ptr == NULL) |
462 |
return; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
463 |
|
0 | 464 |
png_debug2(1, "in png_read_row (row %lu, pass %d)", |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
465 |
(unsigned long) png_ptr->row_number, png_ptr->pass); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
466 |
|
0 | 467 |
if (!(png_ptr->flags & PNG_FLAG_ROW_INIT)) |
468 |
png_read_start_row(png_ptr); |
|
469 |
if (png_ptr->row_number == 0 && png_ptr->pass == 0) |
|
470 |
{ |
|
471 |
/* Check for transforms that have been set but were defined out */ |
|
472 |
#if defined(PNG_WRITE_INVERT_SUPPORTED) && !defined(PNG_READ_INVERT_SUPPORTED) |
|
473 |
if (png_ptr->transformations & PNG_INVERT_MONO) |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
474 |
png_warning(png_ptr, "PNG_READ_INVERT_SUPPORTED is not defined"); |
0 | 475 |
#endif |
476 |
#if defined(PNG_WRITE_FILLER_SUPPORTED) && !defined(PNG_READ_FILLER_SUPPORTED) |
|
477 |
if (png_ptr->transformations & PNG_FILLER) |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
478 |
png_warning(png_ptr, "PNG_READ_FILLER_SUPPORTED is not defined"); |
0 | 479 |
#endif |
480 |
#if defined(PNG_WRITE_PACKSWAP_SUPPORTED) && !defined(PNG_READ_PACKSWAP_SUPPORTED) |
|
481 |
if (png_ptr->transformations & PNG_PACKSWAP) |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
482 |
png_warning(png_ptr, "PNG_READ_PACKSWAP_SUPPORTED is not defined"); |
0 | 483 |
#endif |
484 |
#if defined(PNG_WRITE_PACK_SUPPORTED) && !defined(PNG_READ_PACK_SUPPORTED) |
|
485 |
if (png_ptr->transformations & PNG_PACK) |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
486 |
png_warning(png_ptr, "PNG_READ_PACK_SUPPORTED is not defined"); |
0 | 487 |
#endif |
488 |
#if defined(PNG_WRITE_SHIFT_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED) |
|
489 |
if (png_ptr->transformations & PNG_SHIFT) |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
490 |
png_warning(png_ptr, "PNG_READ_SHIFT_SUPPORTED is not defined"); |
0 | 491 |
#endif |
492 |
#if defined(PNG_WRITE_BGR_SUPPORTED) && !defined(PNG_READ_BGR_SUPPORTED) |
|
493 |
if (png_ptr->transformations & PNG_BGR) |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
494 |
png_warning(png_ptr, "PNG_READ_BGR_SUPPORTED is not defined"); |
0 | 495 |
#endif |
496 |
#if defined(PNG_WRITE_SWAP_SUPPORTED) && !defined(PNG_READ_SWAP_SUPPORTED) |
|
497 |
if (png_ptr->transformations & PNG_SWAP_BYTES) |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
498 |
png_warning(png_ptr, "PNG_READ_SWAP_SUPPORTED is not defined"); |
0 | 499 |
#endif |
500 |
} |
|
501 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
502 |
#ifdef PNG_READ_INTERLACING_SUPPORTED |
0 | 503 |
/* If interlaced and we do not need a new row, combine row and return */ |
504 |
if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE)) |
|
505 |
{ |
|
506 |
switch (png_ptr->pass) |
|
507 |
{ |
|
508 |
case 0: |
|
509 |
if (png_ptr->row_number & 0x07) |
|
510 |
{ |
|
511 |
if (dsp_row != NULL) |
|
512 |
png_combine_row(png_ptr, dsp_row, |
|
513 |
png_pass_dsp_mask[png_ptr->pass]); |
|
514 |
png_read_finish_row(png_ptr); |
|
515 |
return; |
|
516 |
} |
|
517 |
break; |
|
518 |
case 1: |
|
519 |
if ((png_ptr->row_number & 0x07) || png_ptr->width < 5) |
|
520 |
{ |
|
521 |
if (dsp_row != NULL) |
|
522 |
png_combine_row(png_ptr, dsp_row, |
|
523 |
png_pass_dsp_mask[png_ptr->pass]); |
|
524 |
png_read_finish_row(png_ptr); |
|
525 |
return; |
|
526 |
} |
|
527 |
break; |
|
528 |
case 2: |
|
529 |
if ((png_ptr->row_number & 0x07) != 4) |
|
530 |
{ |
|
531 |
if (dsp_row != NULL && (png_ptr->row_number & 4)) |
|
532 |
png_combine_row(png_ptr, dsp_row, |
|
533 |
png_pass_dsp_mask[png_ptr->pass]); |
|
534 |
png_read_finish_row(png_ptr); |
|
535 |
return; |
|
536 |
} |
|
537 |
break; |
|
538 |
case 3: |
|
539 |
if ((png_ptr->row_number & 3) || png_ptr->width < 3) |
|
540 |
{ |
|
541 |
if (dsp_row != NULL) |
|
542 |
png_combine_row(png_ptr, dsp_row, |
|
543 |
png_pass_dsp_mask[png_ptr->pass]); |
|
544 |
png_read_finish_row(png_ptr); |
|
545 |
return; |
|
546 |
} |
|
547 |
break; |
|
548 |
case 4: |
|
549 |
if ((png_ptr->row_number & 3) != 2) |
|
550 |
{ |
|
551 |
if (dsp_row != NULL && (png_ptr->row_number & 2)) |
|
552 |
png_combine_row(png_ptr, dsp_row, |
|
553 |
png_pass_dsp_mask[png_ptr->pass]); |
|
554 |
png_read_finish_row(png_ptr); |
|
555 |
return; |
|
556 |
} |
|
557 |
break; |
|
558 |
case 5: |
|
559 |
if ((png_ptr->row_number & 1) || png_ptr->width < 2) |
|
560 |
{ |
|
561 |
if (dsp_row != NULL) |
|
562 |
png_combine_row(png_ptr, dsp_row, |
|
563 |
png_pass_dsp_mask[png_ptr->pass]); |
|
564 |
png_read_finish_row(png_ptr); |
|
565 |
return; |
|
566 |
} |
|
567 |
break; |
|
568 |
case 6: |
|
569 |
if (!(png_ptr->row_number & 1)) |
|
570 |
{ |
|
571 |
png_read_finish_row(png_ptr); |
|
572 |
return; |
|
573 |
} |
|
574 |
break; |
|
575 |
} |
|
576 |
} |
|
577 |
#endif |
|
578 |
||
579 |
if (!(png_ptr->mode & PNG_HAVE_IDAT)) |
|
580 |
png_error(png_ptr, "Invalid attempt to read row data"); |
|
581 |
||
582 |
png_ptr->zstream.next_out = png_ptr->row_buf; |
|
583 |
png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes; |
|
584 |
do |
|
585 |
{ |
|
586 |
if (!(png_ptr->zstream.avail_in)) |
|
587 |
{ |
|
588 |
while (!png_ptr->idat_size) |
|
589 |
{ |
|
590 |
png_crc_finish(png_ptr, 0); |
|
591 |
||
592 |
png_ptr->idat_size = png_read_chunk_header(png_ptr); |
|
593 |
if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) |
|
594 |
png_error(png_ptr, "Not enough image data"); |
|
595 |
} |
|
596 |
png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size; |
|
597 |
png_ptr->zstream.next_in = png_ptr->zbuf; |
|
598 |
if (png_ptr->zbuf_size > png_ptr->idat_size) |
|
599 |
png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size; |
|
600 |
png_crc_read(png_ptr, png_ptr->zbuf, |
|
601 |
(png_size_t)png_ptr->zstream.avail_in); |
|
602 |
png_ptr->idat_size -= png_ptr->zstream.avail_in; |
|
603 |
} |
|
604 |
ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH); |
|
605 |
if (ret == Z_STREAM_END) |
|
606 |
{ |
|
607 |
if (png_ptr->zstream.avail_out || png_ptr->zstream.avail_in || |
|
608 |
png_ptr->idat_size) |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
609 |
png_benign_error(png_ptr, "Extra compressed data"); |
0 | 610 |
png_ptr->mode |= PNG_AFTER_IDAT; |
611 |
png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED; |
|
612 |
break; |
|
613 |
} |
|
614 |
if (ret != Z_OK) |
|
615 |
png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg : |
|
616 |
"Decompression error"); |
|
617 |
||
618 |
} while (png_ptr->zstream.avail_out); |
|
619 |
||
620 |
png_ptr->row_info.color_type = png_ptr->color_type; |
|
621 |
png_ptr->row_info.width = png_ptr->iwidth; |
|
622 |
png_ptr->row_info.channels = png_ptr->channels; |
|
623 |
png_ptr->row_info.bit_depth = png_ptr->bit_depth; |
|
624 |
png_ptr->row_info.pixel_depth = png_ptr->pixel_depth; |
|
625 |
png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth, |
|
626 |
png_ptr->row_info.width); |
|
627 |
||
628 |
if (png_ptr->row_buf[0]) |
|
629 |
png_read_filter_row(png_ptr, &(png_ptr->row_info), |
|
630 |
png_ptr->row_buf + 1, png_ptr->prev_row + 1, |
|
631 |
(int)(png_ptr->row_buf[0])); |
|
632 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
633 |
png_memcpy(png_ptr->prev_row, png_ptr->row_buf, png_ptr->rowbytes + 1); |
0 | 634 |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
635 |
#ifdef PNG_MNG_FEATURES_SUPPORTED |
0 | 636 |
if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && |
637 |
(png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING)) |
|
638 |
{ |
|
639 |
/* Intrapixel differencing */ |
|
640 |
png_do_read_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1); |
|
641 |
} |
|
642 |
#endif |
|
643 |
||
644 |
||
645 |
if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA)) |
|
646 |
png_do_read_transformations(png_ptr); |
|
647 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
648 |
#ifdef PNG_READ_INTERLACING_SUPPORTED |
0 | 649 |
/* Blow up interlaced rows to full size */ |
650 |
if (png_ptr->interlaced && |
|
651 |
(png_ptr->transformations & PNG_INTERLACE)) |
|
652 |
{ |
|
653 |
if (png_ptr->pass < 6) |
|
654 |
/* Old interface (pre-1.0.9): |
|
655 |
* png_do_read_interlace(&(png_ptr->row_info), |
|
656 |
* png_ptr->row_buf + 1, png_ptr->pass, png_ptr->transformations); |
|
657 |
*/ |
|
658 |
png_do_read_interlace(png_ptr); |
|
659 |
||
660 |
if (dsp_row != NULL) |
|
661 |
png_combine_row(png_ptr, dsp_row, |
|
662 |
png_pass_dsp_mask[png_ptr->pass]); |
|
663 |
if (row != NULL) |
|
664 |
png_combine_row(png_ptr, row, |
|
665 |
png_pass_mask[png_ptr->pass]); |
|
666 |
} |
|
667 |
else |
|
668 |
#endif |
|
669 |
{ |
|
670 |
if (row != NULL) |
|
671 |
png_combine_row(png_ptr, row, 0xff); |
|
672 |
if (dsp_row != NULL) |
|
673 |
png_combine_row(png_ptr, dsp_row, 0xff); |
|
674 |
} |
|
675 |
png_read_finish_row(png_ptr); |
|
676 |
||
677 |
if (png_ptr->read_row_fn != NULL) |
|
678 |
(*(png_ptr->read_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass); |
|
679 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
680 |
#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ |
0 | 681 |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
682 |
#ifdef PNG_SEQUENTIAL_READ_SUPPORTED |
0 | 683 |
/* Read one or more rows of image data. If the image is interlaced, |
684 |
* and png_set_interlace_handling() has been called, the rows need to |
|
685 |
* contain the contents of the rows from the previous pass. If the |
|
686 |
* image has alpha or transparency, and png_handle_alpha()[*] has been |
|
687 |
* called, the rows contents must be initialized to the contents of the |
|
688 |
* screen. |
|
689 |
* |
|
690 |
* "row" holds the actual image, and pixels are placed in it |
|
691 |
* as they arrive. If the image is displayed after each pass, it will |
|
692 |
* appear to "sparkle" in. "display_row" can be used to display a |
|
693 |
* "chunky" progressive image, with finer detail added as it becomes |
|
694 |
* available. If you do not want this "chunky" display, you may pass |
|
695 |
* NULL for display_row. If you do not want the sparkle display, and |
|
696 |
* you have not called png_handle_alpha(), you may pass NULL for rows. |
|
697 |
* If you have called png_handle_alpha(), and the image has either an |
|
698 |
* alpha channel or a transparency chunk, you must provide a buffer for |
|
699 |
* rows. In this case, you do not have to provide a display_row buffer |
|
700 |
* also, but you may. If the image is not interlaced, or if you have |
|
701 |
* not called png_set_interlace_handling(), the display_row buffer will |
|
702 |
* be ignored, so pass NULL to it. |
|
703 |
* |
|
704 |
* [*] png_handle_alpha() does not exist yet, as of this version of libpng |
|
705 |
*/ |
|
706 |
||
707 |
void PNGAPI |
|
708 |
png_read_rows(png_structp png_ptr, png_bytepp row, |
|
709 |
png_bytepp display_row, png_uint_32 num_rows) |
|
710 |
{ |
|
711 |
png_uint_32 i; |
|
712 |
png_bytepp rp; |
|
713 |
png_bytepp dp; |
|
714 |
||
715 |
png_debug(1, "in png_read_rows"); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
716 |
|
0 | 717 |
if (png_ptr == NULL) |
718 |
return; |
|
719 |
rp = row; |
|
720 |
dp = display_row; |
|
721 |
if (rp != NULL && dp != NULL) |
|
722 |
for (i = 0; i < num_rows; i++) |
|
723 |
{ |
|
724 |
png_bytep rptr = *rp++; |
|
725 |
png_bytep dptr = *dp++; |
|
726 |
||
727 |
png_read_row(png_ptr, rptr, dptr); |
|
728 |
} |
|
729 |
else if (rp != NULL) |
|
730 |
for (i = 0; i < num_rows; i++) |
|
731 |
{ |
|
732 |
png_bytep rptr = *rp; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
733 |
png_read_row(png_ptr, rptr, NULL); |
0 | 734 |
rp++; |
735 |
} |
|
736 |
else if (dp != NULL) |
|
737 |
for (i = 0; i < num_rows; i++) |
|
738 |
{ |
|
739 |
png_bytep dptr = *dp; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
740 |
png_read_row(png_ptr, NULL, dptr); |
0 | 741 |
dp++; |
742 |
} |
|
743 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
744 |
#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ |
0 | 745 |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
746 |
#ifdef PNG_SEQUENTIAL_READ_SUPPORTED |
0 | 747 |
/* Read the entire image. If the image has an alpha channel or a tRNS |
748 |
* chunk, and you have called png_handle_alpha()[*], you will need to |
|
749 |
* initialize the image to the current image that PNG will be overlaying. |
|
750 |
* We set the num_rows again here, in case it was incorrectly set in |
|
751 |
* png_read_start_row() by a call to png_read_update_info() or |
|
752 |
* png_start_read_image() if png_set_interlace_handling() wasn't called |
|
753 |
* prior to either of these functions like it should have been. You can |
|
754 |
* only call this function once. If you desire to have an image for |
|
755 |
* each pass of a interlaced image, use png_read_rows() instead. |
|
756 |
* |
|
757 |
* [*] png_handle_alpha() does not exist yet, as of this version of libpng |
|
758 |
*/ |
|
759 |
void PNGAPI |
|
760 |
png_read_image(png_structp png_ptr, png_bytepp image) |
|
761 |
{ |
|
762 |
png_uint_32 i, image_height; |
|
763 |
int pass, j; |
|
764 |
png_bytepp rp; |
|
765 |
||
766 |
png_debug(1, "in png_read_image"); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
767 |
|
0 | 768 |
if (png_ptr == NULL) |
769 |
return; |
|
770 |
||
771 |
#ifdef PNG_READ_INTERLACING_SUPPORTED |
|
772 |
pass = png_set_interlace_handling(png_ptr); |
|
773 |
#else |
|
774 |
if (png_ptr->interlaced) |
|
775 |
png_error(png_ptr, |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
776 |
"Cannot read interlaced image -- interlace handler disabled"); |
0 | 777 |
pass = 1; |
778 |
#endif |
|
779 |
||
780 |
||
781 |
image_height=png_ptr->height; |
|
782 |
png_ptr->num_rows = image_height; /* Make sure this is set correctly */ |
|
783 |
||
784 |
for (j = 0; j < pass; j++) |
|
785 |
{ |
|
786 |
rp = image; |
|
787 |
for (i = 0; i < image_height; i++) |
|
788 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
789 |
png_read_row(png_ptr, *rp, NULL); |
0 | 790 |
rp++; |
791 |
} |
|
792 |
} |
|
793 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
794 |
#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ |
0 | 795 |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
796 |
#ifdef PNG_SEQUENTIAL_READ_SUPPORTED |
0 | 797 |
/* Read the end of the PNG file. Will not read past the end of the |
798 |
* file, will verify the end is accurate, and will read any comments |
|
799 |
* or time information at the end of the file, if info is not NULL. |
|
800 |
*/ |
|
801 |
void PNGAPI |
|
802 |
png_read_end(png_structp png_ptr, png_infop info_ptr) |
|
803 |
{ |
|
804 |
png_debug(1, "in png_read_end"); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
805 |
|
0 | 806 |
if (png_ptr == NULL) |
807 |
return; |
|
808 |
png_crc_finish(png_ptr, 0); /* Finish off CRC from last IDAT chunk */ |
|
809 |
||
810 |
do |
|
811 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
812 |
PNG_IHDR; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
813 |
PNG_IDAT; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
814 |
PNG_IEND; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
815 |
PNG_PLTE; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
816 |
#ifdef PNG_READ_bKGD_SUPPORTED |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
817 |
PNG_bKGD; |
0 | 818 |
#endif |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
819 |
#ifdef PNG_READ_cHRM_SUPPORTED |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
820 |
PNG_cHRM; |
0 | 821 |
#endif |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
822 |
#ifdef PNG_READ_gAMA_SUPPORTED |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
823 |
PNG_gAMA; |
0 | 824 |
#endif |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
825 |
#ifdef PNG_READ_hIST_SUPPORTED |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
826 |
PNG_hIST; |
0 | 827 |
#endif |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
828 |
#ifdef PNG_READ_iCCP_SUPPORTED |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
829 |
PNG_iCCP; |
0 | 830 |
#endif |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
831 |
#ifdef PNG_READ_iTXt_SUPPORTED |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
832 |
PNG_iTXt; |
0 | 833 |
#endif |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
834 |
#ifdef PNG_READ_oFFs_SUPPORTED |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
835 |
PNG_oFFs; |
0 | 836 |
#endif |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
837 |
#ifdef PNG_READ_pCAL_SUPPORTED |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
838 |
PNG_pCAL; |
0 | 839 |
#endif |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
840 |
#ifdef PNG_READ_pHYs_SUPPORTED |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
841 |
PNG_pHYs; |
0 | 842 |
#endif |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
843 |
#ifdef PNG_READ_sBIT_SUPPORTED |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
844 |
PNG_sBIT; |
0 | 845 |
#endif |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
846 |
#ifdef PNG_READ_sCAL_SUPPORTED |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
847 |
PNG_sCAL; |
0 | 848 |
#endif |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
849 |
#ifdef PNG_READ_sPLT_SUPPORTED |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
850 |
PNG_sPLT; |
0 | 851 |
#endif |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
852 |
#ifdef PNG_READ_sRGB_SUPPORTED |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
853 |
PNG_sRGB; |
0 | 854 |
#endif |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
855 |
#ifdef PNG_READ_tEXt_SUPPORTED |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
856 |
PNG_tEXt; |
0 | 857 |
#endif |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
858 |
#ifdef PNG_READ_tIME_SUPPORTED |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
859 |
PNG_tIME; |
0 | 860 |
#endif |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
861 |
#ifdef PNG_READ_tRNS_SUPPORTED |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
862 |
PNG_tRNS; |
0 | 863 |
#endif |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
864 |
#ifdef PNG_READ_zTXt_SUPPORTED |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
865 |
PNG_zTXt; |
0 | 866 |
#endif |
867 |
png_uint_32 length = png_read_chunk_header(png_ptr); |
|
868 |
PNG_CONST png_bytep chunk_name = png_ptr->chunk_name; |
|
869 |
||
870 |
if (!png_memcmp(chunk_name, png_IHDR, 4)) |
|
871 |
png_handle_IHDR(png_ptr, info_ptr, length); |
|
872 |
else if (!png_memcmp(chunk_name, png_IEND, 4)) |
|
873 |
png_handle_IEND(png_ptr, info_ptr, length); |
|
874 |
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED |
|
875 |
else if (png_handle_as_unknown(png_ptr, chunk_name)) |
|
876 |
{ |
|
877 |
if (!png_memcmp(chunk_name, png_IDAT, 4)) |
|
878 |
{ |
|
879 |
if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT)) |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
880 |
png_benign_error(png_ptr, "Too many IDATs found"); |
0 | 881 |
} |
882 |
png_handle_unknown(png_ptr, info_ptr, length); |
|
883 |
if (!png_memcmp(chunk_name, png_PLTE, 4)) |
|
884 |
png_ptr->mode |= PNG_HAVE_PLTE; |
|
885 |
} |
|
886 |
#endif |
|
887 |
else if (!png_memcmp(chunk_name, png_IDAT, 4)) |
|
888 |
{ |
|
889 |
/* Zero length IDATs are legal after the last IDAT has been |
|
890 |
* read, but not after other chunks have been read. |
|
891 |
*/ |
|
892 |
if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT)) |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
893 |
png_benign_error(png_ptr, "Too many IDATs found"); |
0 | 894 |
png_crc_finish(png_ptr, length); |
895 |
} |
|
896 |
else if (!png_memcmp(chunk_name, png_PLTE, 4)) |
|
897 |
png_handle_PLTE(png_ptr, info_ptr, length); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
898 |
#ifdef PNG_READ_bKGD_SUPPORTED |
0 | 899 |
else if (!png_memcmp(chunk_name, png_bKGD, 4)) |
900 |
png_handle_bKGD(png_ptr, info_ptr, length); |
|
901 |
#endif |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
902 |
#ifdef PNG_READ_cHRM_SUPPORTED |
0 | 903 |
else if (!png_memcmp(chunk_name, png_cHRM, 4)) |
904 |
png_handle_cHRM(png_ptr, info_ptr, length); |
|
905 |
#endif |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
906 |
#ifdef PNG_READ_gAMA_SUPPORTED |
0 | 907 |
else if (!png_memcmp(chunk_name, png_gAMA, 4)) |
908 |
png_handle_gAMA(png_ptr, info_ptr, length); |
|
909 |
#endif |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
910 |
#ifdef PNG_READ_hIST_SUPPORTED |
0 | 911 |
else if (!png_memcmp(chunk_name, png_hIST, 4)) |
912 |
png_handle_hIST(png_ptr, info_ptr, length); |
|
913 |
#endif |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
914 |
#ifdef PNG_READ_oFFs_SUPPORTED |
0 | 915 |
else if (!png_memcmp(chunk_name, png_oFFs, 4)) |
916 |
png_handle_oFFs(png_ptr, info_ptr, length); |
|
917 |
#endif |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
918 |
#ifdef PNG_READ_pCAL_SUPPORTED |
0 | 919 |
else if (!png_memcmp(chunk_name, png_pCAL, 4)) |
920 |
png_handle_pCAL(png_ptr, info_ptr, length); |
|
921 |
#endif |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
922 |
#ifdef PNG_READ_sCAL_SUPPORTED |
0 | 923 |
else if (!png_memcmp(chunk_name, png_sCAL, 4)) |
924 |
png_handle_sCAL(png_ptr, info_ptr, length); |
|
925 |
#endif |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
926 |
#ifdef PNG_READ_pHYs_SUPPORTED |
0 | 927 |
else if (!png_memcmp(chunk_name, png_pHYs, 4)) |
928 |
png_handle_pHYs(png_ptr, info_ptr, length); |
|
929 |
#endif |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
930 |
#ifdef PNG_READ_sBIT_SUPPORTED |
0 | 931 |
else if (!png_memcmp(chunk_name, png_sBIT, 4)) |
932 |
png_handle_sBIT(png_ptr, info_ptr, length); |
|
933 |
#endif |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
934 |
#ifdef PNG_READ_sRGB_SUPPORTED |
0 | 935 |
else if (!png_memcmp(chunk_name, png_sRGB, 4)) |
936 |
png_handle_sRGB(png_ptr, info_ptr, length); |
|
937 |
#endif |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
938 |
#ifdef PNG_READ_iCCP_SUPPORTED |
0 | 939 |
else if (!png_memcmp(chunk_name, png_iCCP, 4)) |
940 |
png_handle_iCCP(png_ptr, info_ptr, length); |
|
941 |
#endif |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
942 |
#ifdef PNG_READ_sPLT_SUPPORTED |
0 | 943 |
else if (!png_memcmp(chunk_name, png_sPLT, 4)) |
944 |
png_handle_sPLT(png_ptr, info_ptr, length); |
|
945 |
#endif |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
946 |
#ifdef PNG_READ_tEXt_SUPPORTED |
0 | 947 |
else if (!png_memcmp(chunk_name, png_tEXt, 4)) |
948 |
png_handle_tEXt(png_ptr, info_ptr, length); |
|
949 |
#endif |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
950 |
#ifdef PNG_READ_tIME_SUPPORTED |
0 | 951 |
else if (!png_memcmp(chunk_name, png_tIME, 4)) |
952 |
png_handle_tIME(png_ptr, info_ptr, length); |
|
953 |
#endif |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
954 |
#ifdef PNG_READ_tRNS_SUPPORTED |
0 | 955 |
else if (!png_memcmp(chunk_name, png_tRNS, 4)) |
956 |
png_handle_tRNS(png_ptr, info_ptr, length); |
|
957 |
#endif |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
958 |
#ifdef PNG_READ_zTXt_SUPPORTED |
0 | 959 |
else if (!png_memcmp(chunk_name, png_zTXt, 4)) |
960 |
png_handle_zTXt(png_ptr, info_ptr, length); |
|
961 |
#endif |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
962 |
#ifdef PNG_READ_iTXt_SUPPORTED |
0 | 963 |
else if (!png_memcmp(chunk_name, png_iTXt, 4)) |
964 |
png_handle_iTXt(png_ptr, info_ptr, length); |
|
965 |
#endif |
|
966 |
else |
|
967 |
png_handle_unknown(png_ptr, info_ptr, length); |
|
968 |
} while (!(png_ptr->mode & PNG_HAVE_IEND)); |
|
969 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
970 |
#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ |
0 | 971 |
|
972 |
/* Free all memory used by the read */ |
|
973 |
void PNGAPI |
|
974 |
png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr, |
|
975 |
png_infopp end_info_ptr_ptr) |
|
976 |
{ |
|
977 |
png_structp png_ptr = NULL; |
|
978 |
png_infop info_ptr = NULL, end_info_ptr = NULL; |
|
979 |
#ifdef PNG_USER_MEM_SUPPORTED |
|
980 |
png_free_ptr free_fn = NULL; |
|
981 |
png_voidp mem_ptr = NULL; |
|
982 |
#endif |
|
983 |
||
984 |
png_debug(1, "in png_destroy_read_struct"); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
985 |
|
0 | 986 |
if (png_ptr_ptr != NULL) |
987 |
png_ptr = *png_ptr_ptr; |
|
988 |
if (png_ptr == NULL) |
|
989 |
return; |
|
990 |
||
991 |
#ifdef PNG_USER_MEM_SUPPORTED |
|
992 |
free_fn = png_ptr->free_fn; |
|
993 |
mem_ptr = png_ptr->mem_ptr; |
|
994 |
#endif |
|
995 |
||
996 |
if (info_ptr_ptr != NULL) |
|
997 |
info_ptr = *info_ptr_ptr; |
|
998 |
||
999 |
if (end_info_ptr_ptr != NULL) |
|
1000 |
end_info_ptr = *end_info_ptr_ptr; |
|
1001 |
||
1002 |
png_read_destroy(png_ptr, info_ptr, end_info_ptr); |
|
1003 |
||
1004 |
if (info_ptr != NULL) |
|
1005 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1006 |
#ifdef PNG_TEXT_SUPPORTED |
0 | 1007 |
png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, -1); |
1008 |
#endif |
|
1009 |
||
1010 |
#ifdef PNG_USER_MEM_SUPPORTED |
|
1011 |
png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn, |
|
1012 |
(png_voidp)mem_ptr); |
|
1013 |
#else |
|
1014 |
png_destroy_struct((png_voidp)info_ptr); |
|
1015 |
#endif |
|
1016 |
*info_ptr_ptr = NULL; |
|
1017 |
} |
|
1018 |
||
1019 |
if (end_info_ptr != NULL) |
|
1020 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1021 |
#ifdef PNG_READ_TEXT_SUPPORTED |
0 | 1022 |
png_free_data(png_ptr, end_info_ptr, PNG_FREE_TEXT, -1); |
1023 |
#endif |
|
1024 |
#ifdef PNG_USER_MEM_SUPPORTED |
|
1025 |
png_destroy_struct_2((png_voidp)end_info_ptr, (png_free_ptr)free_fn, |
|
1026 |
(png_voidp)mem_ptr); |
|
1027 |
#else |
|
1028 |
png_destroy_struct((png_voidp)end_info_ptr); |
|
1029 |
#endif |
|
1030 |
*end_info_ptr_ptr = NULL; |
|
1031 |
} |
|
1032 |
||
1033 |
if (png_ptr != NULL) |
|
1034 |
{ |
|
1035 |
#ifdef PNG_USER_MEM_SUPPORTED |
|
1036 |
png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn, |
|
1037 |
(png_voidp)mem_ptr); |
|
1038 |
#else |
|
1039 |
png_destroy_struct((png_voidp)png_ptr); |
|
1040 |
#endif |
|
1041 |
*png_ptr_ptr = NULL; |
|
1042 |
} |
|
1043 |
} |
|
1044 |
||
1045 |
/* Free all memory used by the read (old method) */ |
|
1046 |
void /* PRIVATE */ |
|
1047 |
png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr) |
|
1048 |
{ |
|
1049 |
#ifdef PNG_SETJMP_SUPPORTED |
|
1050 |
jmp_buf tmp_jmp; |
|
1051 |
#endif |
|
1052 |
png_error_ptr error_fn; |
|
1053 |
png_error_ptr warning_fn; |
|
1054 |
png_voidp error_ptr; |
|
1055 |
#ifdef PNG_USER_MEM_SUPPORTED |
|
1056 |
png_free_ptr free_fn; |
|
1057 |
#endif |
|
1058 |
||
1059 |
png_debug(1, "in png_read_destroy"); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1060 |
|
0 | 1061 |
if (info_ptr != NULL) |
1062 |
png_info_destroy(png_ptr, info_ptr); |
|
1063 |
||
1064 |
if (end_info_ptr != NULL) |
|
1065 |
png_info_destroy(png_ptr, end_info_ptr); |
|
1066 |
||
1067 |
png_free(png_ptr, png_ptr->zbuf); |
|
1068 |
png_free(png_ptr, png_ptr->big_row_buf); |
|
1069 |
png_free(png_ptr, png_ptr->prev_row); |
|
1070 |
png_free(png_ptr, png_ptr->chunkdata); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1071 |
#ifdef PNG_READ_DITHER_SUPPORTED |
0 | 1072 |
png_free(png_ptr, png_ptr->palette_lookup); |
1073 |
png_free(png_ptr, png_ptr->dither_index); |
|
1074 |
#endif |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1075 |
#ifdef PNG_READ_GAMMA_SUPPORTED |
0 | 1076 |
png_free(png_ptr, png_ptr->gamma_table); |
1077 |
#endif |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1078 |
#ifdef PNG_READ_BACKGROUND_SUPPORTED |
0 | 1079 |
png_free(png_ptr, png_ptr->gamma_from_1); |
1080 |
png_free(png_ptr, png_ptr->gamma_to_1); |
|
1081 |
#endif |
|
1082 |
if (png_ptr->free_me & PNG_FREE_PLTE) |
|
1083 |
png_zfree(png_ptr, png_ptr->palette); |
|
1084 |
png_ptr->free_me &= ~PNG_FREE_PLTE; |
|
1085 |
#if defined(PNG_tRNS_SUPPORTED) || \ |
|
1086 |
defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) |
|
1087 |
if (png_ptr->free_me & PNG_FREE_TRNS) |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1088 |
png_free(png_ptr, png_ptr->trans_alpha); |
0 | 1089 |
png_ptr->free_me &= ~PNG_FREE_TRNS; |
1090 |
#endif |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1091 |
#ifdef PNG_READ_hIST_SUPPORTED |
0 | 1092 |
if (png_ptr->free_me & PNG_FREE_HIST) |
1093 |
png_free(png_ptr, png_ptr->hist); |
|
1094 |
png_ptr->free_me &= ~PNG_FREE_HIST; |
|
1095 |
#endif |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1096 |
#ifdef PNG_READ_GAMMA_SUPPORTED |
0 | 1097 |
if (png_ptr->gamma_16_table != NULL) |
1098 |
{ |
|
1099 |
int i; |
|
1100 |
int istop = (1 << (8 - png_ptr->gamma_shift)); |
|
1101 |
for (i = 0; i < istop; i++) |
|
1102 |
{ |
|
1103 |
png_free(png_ptr, png_ptr->gamma_16_table[i]); |
|
1104 |
} |
|
1105 |
png_free(png_ptr, png_ptr->gamma_16_table); |
|
1106 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1107 |
#ifdef PNG_READ_BACKGROUND_SUPPORTED |
0 | 1108 |
if (png_ptr->gamma_16_from_1 != NULL) |
1109 |
{ |
|
1110 |
int i; |
|
1111 |
int istop = (1 << (8 - png_ptr->gamma_shift)); |
|
1112 |
for (i = 0; i < istop; i++) |
|
1113 |
{ |
|
1114 |
png_free(png_ptr, png_ptr->gamma_16_from_1[i]); |
|
1115 |
} |
|
1116 |
png_free(png_ptr, png_ptr->gamma_16_from_1); |
|
1117 |
} |
|
1118 |
if (png_ptr->gamma_16_to_1 != NULL) |
|
1119 |
{ |
|
1120 |
int i; |
|
1121 |
int istop = (1 << (8 - png_ptr->gamma_shift)); |
|
1122 |
for (i = 0; i < istop; i++) |
|
1123 |
{ |
|
1124 |
png_free(png_ptr, png_ptr->gamma_16_to_1[i]); |
|
1125 |
} |
|
1126 |
png_free(png_ptr, png_ptr->gamma_16_to_1); |
|
1127 |
} |
|
1128 |
#endif |
|
1129 |
#endif |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1130 |
#ifdef PNG_TIME_RFC1123_SUPPORTED |
0 | 1131 |
png_free(png_ptr, png_ptr->time_buffer); |
1132 |
#endif |
|
1133 |
||
1134 |
inflateEnd(&png_ptr->zstream); |
|
1135 |
#ifdef PNG_PROGRESSIVE_READ_SUPPORTED |
|
1136 |
png_free(png_ptr, png_ptr->save_buffer); |
|
1137 |
#endif |
|
1138 |
||
1139 |
#ifdef PNG_PROGRESSIVE_READ_SUPPORTED |
|
1140 |
#ifdef PNG_TEXT_SUPPORTED |
|
1141 |
png_free(png_ptr, png_ptr->current_text); |
|
1142 |
#endif /* PNG_TEXT_SUPPORTED */ |
|
1143 |
#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */ |
|
1144 |
||
1145 |
/* Save the important info out of the png_struct, in case it is |
|
1146 |
* being used again. |
|
1147 |
*/ |
|
1148 |
#ifdef PNG_SETJMP_SUPPORTED |
|
1149 |
png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof(jmp_buf)); |
|
1150 |
#endif |
|
1151 |
||
1152 |
error_fn = png_ptr->error_fn; |
|
1153 |
warning_fn = png_ptr->warning_fn; |
|
1154 |
error_ptr = png_ptr->error_ptr; |
|
1155 |
#ifdef PNG_USER_MEM_SUPPORTED |
|
1156 |
free_fn = png_ptr->free_fn; |
|
1157 |
#endif |
|
1158 |
||
1159 |
png_memset(png_ptr, 0, png_sizeof(png_struct)); |
|
1160 |
||
1161 |
png_ptr->error_fn = error_fn; |
|
1162 |
png_ptr->warning_fn = warning_fn; |
|
1163 |
png_ptr->error_ptr = error_ptr; |
|
1164 |
#ifdef PNG_USER_MEM_SUPPORTED |
|
1165 |
png_ptr->free_fn = free_fn; |
|
1166 |
#endif |
|
1167 |
||
1168 |
#ifdef PNG_SETJMP_SUPPORTED |
|
1169 |
png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof(jmp_buf)); |
|
1170 |
#endif |
|
1171 |
||
1172 |
} |
|
1173 |
||
1174 |
void PNGAPI |
|
1175 |
png_set_read_status_fn(png_structp png_ptr, png_read_status_ptr read_row_fn) |
|
1176 |
{ |
|
1177 |
if (png_ptr == NULL) |
|
1178 |
return; |
|
1179 |
png_ptr->read_row_fn = read_row_fn; |
|
1180 |
} |
|
1181 |
||
1182 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1183 |
#ifdef PNG_SEQUENTIAL_READ_SUPPORTED |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1184 |
#ifdef PNG_INFO_IMAGE_SUPPORTED |
0 | 1185 |
void PNGAPI |
1186 |
png_read_png(png_structp png_ptr, png_infop info_ptr, |
|
1187 |
int transforms, |
|
1188 |
voidp params) |
|
1189 |
{ |
|
1190 |
int row; |
|
1191 |
||
1192 |
if (png_ptr == NULL) |
|
1193 |
return; |
|
1194 |
||
1195 |
/* png_read_info() gives us all of the information from the |
|
1196 |
* PNG file before the first IDAT (image data chunk). |
|
1197 |
*/ |
|
1198 |
png_read_info(png_ptr, info_ptr); |
|
1199 |
if (info_ptr->height > PNG_UINT_32_MAX/png_sizeof(png_bytep)) |
|
1200 |
png_error(png_ptr, "Image is too high to process with png_read_png()"); |
|
1201 |
||
1202 |
/* -------------- image transformations start here ------------------- */ |
|
1203 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1204 |
#ifdef PNG_READ_16_TO_8_SUPPORTED |
0 | 1205 |
/* Tell libpng to strip 16 bit/color files down to 8 bits per color. |
1206 |
*/ |
|
1207 |
if (transforms & PNG_TRANSFORM_STRIP_16) |
|
1208 |
png_set_strip_16(png_ptr); |
|
1209 |
#endif |
|
1210 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1211 |
#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED |
0 | 1212 |
/* Strip alpha bytes from the input data without combining with |
1213 |
* the background (not recommended). |
|
1214 |
*/ |
|
1215 |
if (transforms & PNG_TRANSFORM_STRIP_ALPHA) |
|
1216 |
png_set_strip_alpha(png_ptr); |
|
1217 |
#endif |
|
1218 |
||
1219 |
#if defined(PNG_READ_PACK_SUPPORTED) && !defined(PNG_READ_EXPAND_SUPPORTED) |
|
1220 |
/* Extract multiple pixels with bit depths of 1, 2, or 4 from a single |
|
1221 |
* byte into separate bytes (useful for paletted and grayscale images). |
|
1222 |
*/ |
|
1223 |
if (transforms & PNG_TRANSFORM_PACKING) |
|
1224 |
png_set_packing(png_ptr); |
|
1225 |
#endif |
|
1226 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1227 |
#ifdef PNG_READ_PACKSWAP_SUPPORTED |
0 | 1228 |
/* Change the order of packed pixels to least significant bit first |
1229 |
* (not useful if you are using png_set_packing). |
|
1230 |
*/ |
|
1231 |
if (transforms & PNG_TRANSFORM_PACKSWAP) |
|
1232 |
png_set_packswap(png_ptr); |
|
1233 |
#endif |
|
1234 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1235 |
#ifdef PNG_READ_EXPAND_SUPPORTED |
0 | 1236 |
/* Expand paletted colors into true RGB triplets |
1237 |
* Expand grayscale images to full 8 bits from 1, 2, or 4 bits/pixel |
|
1238 |
* Expand paletted or RGB images with transparency to full alpha |
|
1239 |
* channels so the data will be available as RGBA quartets. |
|
1240 |
*/ |
|
1241 |
if (transforms & PNG_TRANSFORM_EXPAND) |
|
1242 |
if ((png_ptr->bit_depth < 8) || |
|
1243 |
(png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) || |
|
1244 |
(png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))) |
|
1245 |
png_set_expand(png_ptr); |
|
1246 |
#endif |
|
1247 |
||
1248 |
/* We don't handle background color or gamma transformation or dithering. |
|
1249 |
*/ |
|
1250 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1251 |
#ifdef PNG_READ_INVERT_SUPPORTED |
0 | 1252 |
/* Invert monochrome files to have 0 as white and 1 as black |
1253 |
*/ |
|
1254 |
if (transforms & PNG_TRANSFORM_INVERT_MONO) |
|
1255 |
png_set_invert_mono(png_ptr); |
|
1256 |
#endif |
|
1257 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1258 |
#ifdef PNG_READ_SHIFT_SUPPORTED |
0 | 1259 |
/* If you want to shift the pixel values from the range [0,255] or |
1260 |
* [0,65535] to the original [0,7] or [0,31], or whatever range the |
|
1261 |
* colors were originally in: |
|
1262 |
*/ |
|
1263 |
if ((transforms & PNG_TRANSFORM_SHIFT) |
|
1264 |
&& png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT)) |
|
1265 |
{ |
|
1266 |
png_color_8p sig_bit; |
|
1267 |
||
1268 |
png_get_sBIT(png_ptr, info_ptr, &sig_bit); |
|
1269 |
png_set_shift(png_ptr, sig_bit); |
|
1270 |
} |
|
1271 |
#endif |
|
1272 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1273 |
#ifdef PNG_READ_BGR_SUPPORTED |
0 | 1274 |
/* Flip the RGB pixels to BGR (or RGBA to BGRA) |
1275 |
*/ |
|
1276 |
if (transforms & PNG_TRANSFORM_BGR) |
|
1277 |
png_set_bgr(png_ptr); |
|
1278 |
#endif |
|
1279 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1280 |
#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED |
0 | 1281 |
/* Swap the RGBA or GA data to ARGB or AG (or BGRA to ABGR) |
1282 |
*/ |
|
1283 |
if (transforms & PNG_TRANSFORM_SWAP_ALPHA) |
|
1284 |
png_set_swap_alpha(png_ptr); |
|
1285 |
#endif |
|
1286 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1287 |
#ifdef PNG_READ_SWAP_SUPPORTED |
0 | 1288 |
/* Swap bytes of 16 bit files to least significant byte first |
1289 |
*/ |
|
1290 |
if (transforms & PNG_TRANSFORM_SWAP_ENDIAN) |
|
1291 |
png_set_swap(png_ptr); |
|
1292 |
#endif |
|
1293 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1294 |
/* Added at libpng-1.2.41 */ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1295 |
#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1296 |
/* Invert the alpha channel from opacity to transparency |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1297 |
*/ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1298 |
if (transforms & PNG_TRANSFORM_INVERT_ALPHA) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1299 |
png_set_invert_alpha(png_ptr); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1300 |
#endif |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1301 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1302 |
/* Added at libpng-1.2.41 */ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1303 |
#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1304 |
/* Expand grayscale image to RGB |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1305 |
*/ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1306 |
if (transforms & PNG_TRANSFORM_GRAY_TO_RGB) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1307 |
png_set_gray_to_rgb(png_ptr); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1308 |
#endif |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1309 |
|
0 | 1310 |
/* We don't handle adding filler bytes */ |
1311 |
||
1312 |
/* Optional call to gamma correct and add the background to the palette |
|
1313 |
* and update info structure. REQUIRED if you are expecting libpng to |
|
1314 |
* update the palette for you (i.e., you selected such a transform above). |
|
1315 |
*/ |
|
1316 |
png_read_update_info(png_ptr, info_ptr); |
|
1317 |
||
1318 |
/* -------------- image transformations end here ------------------- */ |
|
1319 |
||
1320 |
png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0); |
|
1321 |
if (info_ptr->row_pointers == NULL) |
|
1322 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1323 |
png_uint_32 iptr; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1324 |
|
0 | 1325 |
info_ptr->row_pointers = (png_bytepp)png_malloc(png_ptr, |
1326 |
info_ptr->height * png_sizeof(png_bytep)); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1327 |
for (iptr=0; iptr<info_ptr->height; iptr++) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1328 |
info_ptr->row_pointers[iptr] = NULL; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1329 |
|
0 | 1330 |
info_ptr->free_me |= PNG_FREE_ROWS; |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1331 |
|
0 | 1332 |
for (row = 0; row < (int)info_ptr->height; row++) |
1333 |
info_ptr->row_pointers[row] = (png_bytep)png_malloc(png_ptr, |
|
1334 |
png_get_rowbytes(png_ptr, info_ptr)); |
|
1335 |
} |
|
1336 |
||
1337 |
png_read_image(png_ptr, info_ptr->row_pointers); |
|
1338 |
info_ptr->valid |= PNG_INFO_IDAT; |
|
1339 |
||
1340 |
/* Read rest of file, and get additional chunks in info_ptr - REQUIRED */ |
|
1341 |
png_read_end(png_ptr, info_ptr); |
|
1342 |
||
1343 |
transforms = transforms; /* Quiet compiler warnings */ |
|
1344 |
params = params; |
|
1345 |
||
1346 |
} |
|
1347 |
#endif /* PNG_INFO_IMAGE_SUPPORTED */ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1348 |
#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */ |
0 | 1349 |
#endif /* PNG_READ_SUPPORTED */ |