annotate lib/libpng/pngpread.c @ 2575:a76d408c5132 tip

DrawTranslucent -> DrawTextureGrayShade Removed old texture drawing stuff
author a.parshin
date Wed, 09 Mar 2016 01:39:52 +0200
parents 6e178010fc29
children
rev   line source
2296
Ritor1
parents:
diff changeset
1
Ritor1
parents:
diff changeset
2 /* pngpread.c - read a png file in push mode
Ritor1
parents:
diff changeset
3 *
Ritor1
parents:
diff changeset
4 * Last changed in libpng 1.6.10 [March 6, 2014]
Ritor1
parents:
diff changeset
5 * Copyright (c) 1998-2014 Glenn Randers-Pehrson
Ritor1
parents:
diff changeset
6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
Ritor1
parents:
diff changeset
7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
Ritor1
parents:
diff changeset
8 *
Ritor1
parents:
diff changeset
9 * This code is released under the libpng license.
Ritor1
parents:
diff changeset
10 * For conditions of distribution and use, see the disclaimer
Ritor1
parents:
diff changeset
11 * and license in png.h
Ritor1
parents:
diff changeset
12 */
Ritor1
parents:
diff changeset
13
Ritor1
parents:
diff changeset
14 #include "pngpriv.h"
Ritor1
parents:
diff changeset
15
Ritor1
parents:
diff changeset
16 #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
Ritor1
parents:
diff changeset
17
Ritor1
parents:
diff changeset
18 /* Push model modes */
Ritor1
parents:
diff changeset
19 #define PNG_READ_SIG_MODE 0
Ritor1
parents:
diff changeset
20 #define PNG_READ_CHUNK_MODE 1
Ritor1
parents:
diff changeset
21 #define PNG_READ_IDAT_MODE 2
Ritor1
parents:
diff changeset
22 #define PNG_SKIP_MODE 3
Ritor1
parents:
diff changeset
23 #define PNG_READ_tEXt_MODE 4
Ritor1
parents:
diff changeset
24 #define PNG_READ_zTXt_MODE 5
Ritor1
parents:
diff changeset
25 #define PNG_READ_DONE_MODE 6
Ritor1
parents:
diff changeset
26 #define PNG_READ_iTXt_MODE 7
Ritor1
parents:
diff changeset
27 #define PNG_ERROR_MODE 8
Ritor1
parents:
diff changeset
28
Ritor1
parents:
diff changeset
29 void PNGAPI
Ritor1
parents:
diff changeset
30 png_process_data(png_structrp png_ptr, png_inforp info_ptr,
Ritor1
parents:
diff changeset
31 png_bytep buffer, png_size_t buffer_size)
Ritor1
parents:
diff changeset
32 {
Ritor1
parents:
diff changeset
33 if (png_ptr == NULL || info_ptr == NULL)
Ritor1
parents:
diff changeset
34 return;
Ritor1
parents:
diff changeset
35
Ritor1
parents:
diff changeset
36 png_push_restore_buffer(png_ptr, buffer, buffer_size);
Ritor1
parents:
diff changeset
37
Ritor1
parents:
diff changeset
38 while (png_ptr->buffer_size)
Ritor1
parents:
diff changeset
39 {
Ritor1
parents:
diff changeset
40 png_process_some_data(png_ptr, info_ptr);
Ritor1
parents:
diff changeset
41 }
Ritor1
parents:
diff changeset
42 }
Ritor1
parents:
diff changeset
43
Ritor1
parents:
diff changeset
44 png_size_t PNGAPI
Ritor1
parents:
diff changeset
45 png_process_data_pause(png_structrp png_ptr, int save)
Ritor1
parents:
diff changeset
46 {
Ritor1
parents:
diff changeset
47 if (png_ptr != NULL)
Ritor1
parents:
diff changeset
48 {
Ritor1
parents:
diff changeset
49 /* It's easiest for the caller if we do the save, then the caller doesn't
Ritor1
parents:
diff changeset
50 * have to supply the same data again:
Ritor1
parents:
diff changeset
51 */
Ritor1
parents:
diff changeset
52 if (save)
Ritor1
parents:
diff changeset
53 png_push_save_buffer(png_ptr);
Ritor1
parents:
diff changeset
54 else
Ritor1
parents:
diff changeset
55 {
Ritor1
parents:
diff changeset
56 /* This includes any pending saved bytes: */
Ritor1
parents:
diff changeset
57 png_size_t remaining = png_ptr->buffer_size;
Ritor1
parents:
diff changeset
58 png_ptr->buffer_size = 0;
Ritor1
parents:
diff changeset
59
Ritor1
parents:
diff changeset
60 /* So subtract the saved buffer size, unless all the data
Ritor1
parents:
diff changeset
61 * is actually 'saved', in which case we just return 0
Ritor1
parents:
diff changeset
62 */
Ritor1
parents:
diff changeset
63 if (png_ptr->save_buffer_size < remaining)
Ritor1
parents:
diff changeset
64 return remaining - png_ptr->save_buffer_size;
Ritor1
parents:
diff changeset
65 }
Ritor1
parents:
diff changeset
66 }
Ritor1
parents:
diff changeset
67
Ritor1
parents:
diff changeset
68 return 0;
Ritor1
parents:
diff changeset
69 }
Ritor1
parents:
diff changeset
70
Ritor1
parents:
diff changeset
71 png_uint_32 PNGAPI
Ritor1
parents:
diff changeset
72 png_process_data_skip(png_structrp png_ptr)
Ritor1
parents:
diff changeset
73 {
Ritor1
parents:
diff changeset
74 png_uint_32 remaining = 0;
Ritor1
parents:
diff changeset
75
Ritor1
parents:
diff changeset
76 if (png_ptr != NULL && png_ptr->process_mode == PNG_SKIP_MODE &&
Ritor1
parents:
diff changeset
77 png_ptr->skip_length > 0)
Ritor1
parents:
diff changeset
78 {
Ritor1
parents:
diff changeset
79 /* At the end of png_process_data the buffer size must be 0 (see the loop
Ritor1
parents:
diff changeset
80 * above) so we can detect a broken call here:
Ritor1
parents:
diff changeset
81 */
Ritor1
parents:
diff changeset
82 if (png_ptr->buffer_size != 0)
Ritor1
parents:
diff changeset
83 png_error(png_ptr,
Ritor1
parents:
diff changeset
84 "png_process_data_skip called inside png_process_data");
Ritor1
parents:
diff changeset
85
Ritor1
parents:
diff changeset
86 /* If is impossible for there to be a saved buffer at this point -
Ritor1
parents:
diff changeset
87 * otherwise we could not be in SKIP mode. This will also happen if
Ritor1
parents:
diff changeset
88 * png_process_skip is called inside png_process_data (but only very
Ritor1
parents:
diff changeset
89 * rarely.)
Ritor1
parents:
diff changeset
90 */
Ritor1
parents:
diff changeset
91 if (png_ptr->save_buffer_size != 0)
Ritor1
parents:
diff changeset
92 png_error(png_ptr, "png_process_data_skip called with saved data");
Ritor1
parents:
diff changeset
93
Ritor1
parents:
diff changeset
94 remaining = png_ptr->skip_length;
Ritor1
parents:
diff changeset
95 png_ptr->skip_length = 0;
Ritor1
parents:
diff changeset
96 png_ptr->process_mode = PNG_READ_CHUNK_MODE;
Ritor1
parents:
diff changeset
97 }
Ritor1
parents:
diff changeset
98
Ritor1
parents:
diff changeset
99 return remaining;
Ritor1
parents:
diff changeset
100 }
Ritor1
parents:
diff changeset
101
Ritor1
parents:
diff changeset
102 /* What we do with the incoming data depends on what we were previously
Ritor1
parents:
diff changeset
103 * doing before we ran out of data...
Ritor1
parents:
diff changeset
104 */
Ritor1
parents:
diff changeset
105 void /* PRIVATE */
Ritor1
parents:
diff changeset
106 png_process_some_data(png_structrp png_ptr, png_inforp info_ptr)
Ritor1
parents:
diff changeset
107 {
Ritor1
parents:
diff changeset
108 if (png_ptr == NULL)
Ritor1
parents:
diff changeset
109 return;
Ritor1
parents:
diff changeset
110
Ritor1
parents:
diff changeset
111 switch (png_ptr->process_mode)
Ritor1
parents:
diff changeset
112 {
Ritor1
parents:
diff changeset
113 case PNG_READ_SIG_MODE:
Ritor1
parents:
diff changeset
114 {
Ritor1
parents:
diff changeset
115 png_push_read_sig(png_ptr, info_ptr);
Ritor1
parents:
diff changeset
116 break;
Ritor1
parents:
diff changeset
117 }
Ritor1
parents:
diff changeset
118
Ritor1
parents:
diff changeset
119 case PNG_READ_CHUNK_MODE:
Ritor1
parents:
diff changeset
120 {
Ritor1
parents:
diff changeset
121 png_push_read_chunk(png_ptr, info_ptr);
Ritor1
parents:
diff changeset
122 break;
Ritor1
parents:
diff changeset
123 }
Ritor1
parents:
diff changeset
124
Ritor1
parents:
diff changeset
125 case PNG_READ_IDAT_MODE:
Ritor1
parents:
diff changeset
126 {
Ritor1
parents:
diff changeset
127 png_push_read_IDAT(png_ptr);
Ritor1
parents:
diff changeset
128 break;
Ritor1
parents:
diff changeset
129 }
Ritor1
parents:
diff changeset
130
Ritor1
parents:
diff changeset
131 case PNG_SKIP_MODE:
Ritor1
parents:
diff changeset
132 {
Ritor1
parents:
diff changeset
133 png_push_crc_finish(png_ptr);
Ritor1
parents:
diff changeset
134 break;
Ritor1
parents:
diff changeset
135 }
Ritor1
parents:
diff changeset
136
Ritor1
parents:
diff changeset
137 default:
Ritor1
parents:
diff changeset
138 {
Ritor1
parents:
diff changeset
139 png_ptr->buffer_size = 0;
Ritor1
parents:
diff changeset
140 break;
Ritor1
parents:
diff changeset
141 }
Ritor1
parents:
diff changeset
142 }
Ritor1
parents:
diff changeset
143 }
Ritor1
parents:
diff changeset
144
Ritor1
parents:
diff changeset
145 /* Read any remaining signature bytes from the stream and compare them with
Ritor1
parents:
diff changeset
146 * the correct PNG signature. It is possible that this routine is called
Ritor1
parents:
diff changeset
147 * with bytes already read from the signature, either because they have been
Ritor1
parents:
diff changeset
148 * checked by the calling application, or because of multiple calls to this
Ritor1
parents:
diff changeset
149 * routine.
Ritor1
parents:
diff changeset
150 */
Ritor1
parents:
diff changeset
151 void /* PRIVATE */
Ritor1
parents:
diff changeset
152 png_push_read_sig(png_structrp png_ptr, png_inforp info_ptr)
Ritor1
parents:
diff changeset
153 {
Ritor1
parents:
diff changeset
154 png_size_t num_checked = png_ptr->sig_bytes, /* SAFE, does not exceed 8 */
Ritor1
parents:
diff changeset
155 num_to_check = 8 - num_checked;
Ritor1
parents:
diff changeset
156
Ritor1
parents:
diff changeset
157 if (png_ptr->buffer_size < num_to_check)
Ritor1
parents:
diff changeset
158 {
Ritor1
parents:
diff changeset
159 num_to_check = png_ptr->buffer_size;
Ritor1
parents:
diff changeset
160 }
Ritor1
parents:
diff changeset
161
Ritor1
parents:
diff changeset
162 png_push_fill_buffer(png_ptr, &(info_ptr->signature[num_checked]),
Ritor1
parents:
diff changeset
163 num_to_check);
Ritor1
parents:
diff changeset
164 png_ptr->sig_bytes = (png_byte)(png_ptr->sig_bytes + num_to_check);
Ritor1
parents:
diff changeset
165
Ritor1
parents:
diff changeset
166 if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
Ritor1
parents:
diff changeset
167 {
Ritor1
parents:
diff changeset
168 if (num_checked < 4 &&
Ritor1
parents:
diff changeset
169 png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
Ritor1
parents:
diff changeset
170 png_error(png_ptr, "Not a PNG file");
Ritor1
parents:
diff changeset
171
Ritor1
parents:
diff changeset
172 else
Ritor1
parents:
diff changeset
173 png_error(png_ptr, "PNG file corrupted by ASCII conversion");
Ritor1
parents:
diff changeset
174 }
Ritor1
parents:
diff changeset
175 else
Ritor1
parents:
diff changeset
176 {
Ritor1
parents:
diff changeset
177 if (png_ptr->sig_bytes >= 8)
Ritor1
parents:
diff changeset
178 {
Ritor1
parents:
diff changeset
179 png_ptr->process_mode = PNG_READ_CHUNK_MODE;
Ritor1
parents:
diff changeset
180 }
Ritor1
parents:
diff changeset
181 }
Ritor1
parents:
diff changeset
182 }
Ritor1
parents:
diff changeset
183
Ritor1
parents:
diff changeset
184 void /* PRIVATE */
Ritor1
parents:
diff changeset
185 png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
Ritor1
parents:
diff changeset
186 {
Ritor1
parents:
diff changeset
187 png_uint_32 chunk_name;
Ritor1
parents:
diff changeset
188 #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
Ritor1
parents:
diff changeset
189 int keep; /* unknown handling method */
Ritor1
parents:
diff changeset
190 #endif
Ritor1
parents:
diff changeset
191
Ritor1
parents:
diff changeset
192 /* First we make sure we have enough data for the 4 byte chunk name
Ritor1
parents:
diff changeset
193 * and the 4 byte chunk length before proceeding with decoding the
Ritor1
parents:
diff changeset
194 * chunk data. To fully decode each of these chunks, we also make
Ritor1
parents:
diff changeset
195 * sure we have enough data in the buffer for the 4 byte CRC at the
Ritor1
parents:
diff changeset
196 * end of every chunk (except IDAT, which is handled separately).
Ritor1
parents:
diff changeset
197 */
Ritor1
parents:
diff changeset
198 if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
Ritor1
parents:
diff changeset
199 {
Ritor1
parents:
diff changeset
200 png_byte chunk_length[4];
Ritor1
parents:
diff changeset
201 png_byte chunk_tag[4];
Ritor1
parents:
diff changeset
202
Ritor1
parents:
diff changeset
203 if (png_ptr->buffer_size < 8)
Ritor1
parents:
diff changeset
204 {
Ritor1
parents:
diff changeset
205 png_push_save_buffer(png_ptr);
Ritor1
parents:
diff changeset
206 return;
Ritor1
parents:
diff changeset
207 }
Ritor1
parents:
diff changeset
208
Ritor1
parents:
diff changeset
209 png_push_fill_buffer(png_ptr, chunk_length, 4);
Ritor1
parents:
diff changeset
210 png_ptr->push_length = png_get_uint_31(png_ptr, chunk_length);
Ritor1
parents:
diff changeset
211 png_reset_crc(png_ptr);
Ritor1
parents:
diff changeset
212 png_crc_read(png_ptr, chunk_tag, 4);
Ritor1
parents:
diff changeset
213 png_ptr->chunk_name = PNG_CHUNK_FROM_STRING(chunk_tag);
Ritor1
parents:
diff changeset
214 png_check_chunk_name(png_ptr, png_ptr->chunk_name);
Ritor1
parents:
diff changeset
215 png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
Ritor1
parents:
diff changeset
216 }
Ritor1
parents:
diff changeset
217
Ritor1
parents:
diff changeset
218 chunk_name = png_ptr->chunk_name;
Ritor1
parents:
diff changeset
219
Ritor1
parents:
diff changeset
220 if (chunk_name == png_IDAT)
Ritor1
parents:
diff changeset
221 {
Ritor1
parents:
diff changeset
222 if (png_ptr->mode & PNG_AFTER_IDAT)
Ritor1
parents:
diff changeset
223 png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
Ritor1
parents:
diff changeset
224
Ritor1
parents:
diff changeset
225 /* If we reach an IDAT chunk, this means we have read all of the
Ritor1
parents:
diff changeset
226 * header chunks, and we can start reading the image (or if this
Ritor1
parents:
diff changeset
227 * is called after the image has been read - we have an error).
Ritor1
parents:
diff changeset
228 */
Ritor1
parents:
diff changeset
229 if (!(png_ptr->mode & PNG_HAVE_IHDR))
Ritor1
parents:
diff changeset
230 png_error(png_ptr, "Missing IHDR before IDAT");
Ritor1
parents:
diff changeset
231
Ritor1
parents:
diff changeset
232 else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
Ritor1
parents:
diff changeset
233 !(png_ptr->mode & PNG_HAVE_PLTE))
Ritor1
parents:
diff changeset
234 png_error(png_ptr, "Missing PLTE before IDAT");
Ritor1
parents:
diff changeset
235
Ritor1
parents:
diff changeset
236 png_ptr->mode |= PNG_HAVE_IDAT;
Ritor1
parents:
diff changeset
237 png_ptr->process_mode = PNG_READ_IDAT_MODE;
Ritor1
parents:
diff changeset
238
Ritor1
parents:
diff changeset
239 if (!(png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
Ritor1
parents:
diff changeset
240 if (png_ptr->push_length == 0)
Ritor1
parents:
diff changeset
241 return;
Ritor1
parents:
diff changeset
242
Ritor1
parents:
diff changeset
243 if (png_ptr->mode & PNG_AFTER_IDAT)
Ritor1
parents:
diff changeset
244 png_benign_error(png_ptr, "Too many IDATs found");
Ritor1
parents:
diff changeset
245 }
Ritor1
parents:
diff changeset
246
Ritor1
parents:
diff changeset
247 if (chunk_name == png_IHDR)
Ritor1
parents:
diff changeset
248 {
Ritor1
parents:
diff changeset
249 if (png_ptr->push_length != 13)
Ritor1
parents:
diff changeset
250 png_error(png_ptr, "Invalid IHDR length");
Ritor1
parents:
diff changeset
251
Ritor1
parents:
diff changeset
252 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
Ritor1
parents:
diff changeset
253 {
Ritor1
parents:
diff changeset
254 png_push_save_buffer(png_ptr);
Ritor1
parents:
diff changeset
255 return;
Ritor1
parents:
diff changeset
256 }
Ritor1
parents:
diff changeset
257
Ritor1
parents:
diff changeset
258 png_handle_IHDR(png_ptr, info_ptr, png_ptr->push_length);
Ritor1
parents:
diff changeset
259 }
Ritor1
parents:
diff changeset
260
Ritor1
parents:
diff changeset
261 else if (chunk_name == png_IEND)
Ritor1
parents:
diff changeset
262 {
Ritor1
parents:
diff changeset
263 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
Ritor1
parents:
diff changeset
264 {
Ritor1
parents:
diff changeset
265 png_push_save_buffer(png_ptr);
Ritor1
parents:
diff changeset
266 return;
Ritor1
parents:
diff changeset
267 }
Ritor1
parents:
diff changeset
268
Ritor1
parents:
diff changeset
269 png_handle_IEND(png_ptr, info_ptr, png_ptr->push_length);
Ritor1
parents:
diff changeset
270
Ritor1
parents:
diff changeset
271 png_ptr->process_mode = PNG_READ_DONE_MODE;
Ritor1
parents:
diff changeset
272 png_push_have_end(png_ptr, info_ptr);
Ritor1
parents:
diff changeset
273 }
Ritor1
parents:
diff changeset
274
Ritor1
parents:
diff changeset
275 #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
Ritor1
parents:
diff changeset
276 else if ((keep = png_chunk_unknown_handling(png_ptr, chunk_name)) != 0)
Ritor1
parents:
diff changeset
277 {
Ritor1
parents:
diff changeset
278 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
Ritor1
parents:
diff changeset
279 {
Ritor1
parents:
diff changeset
280 png_push_save_buffer(png_ptr);
Ritor1
parents:
diff changeset
281 return;
Ritor1
parents:
diff changeset
282 }
Ritor1
parents:
diff changeset
283
Ritor1
parents:
diff changeset
284 png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length, keep);
Ritor1
parents:
diff changeset
285
Ritor1
parents:
diff changeset
286 if (chunk_name == png_PLTE)
Ritor1
parents:
diff changeset
287 png_ptr->mode |= PNG_HAVE_PLTE;
Ritor1
parents:
diff changeset
288 }
Ritor1
parents:
diff changeset
289 #endif
Ritor1
parents:
diff changeset
290
Ritor1
parents:
diff changeset
291 else if (chunk_name == png_PLTE)
Ritor1
parents:
diff changeset
292 {
Ritor1
parents:
diff changeset
293 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
Ritor1
parents:
diff changeset
294 {
Ritor1
parents:
diff changeset
295 png_push_save_buffer(png_ptr);
Ritor1
parents:
diff changeset
296 return;
Ritor1
parents:
diff changeset
297 }
Ritor1
parents:
diff changeset
298 png_handle_PLTE(png_ptr, info_ptr, png_ptr->push_length);
Ritor1
parents:
diff changeset
299 }
Ritor1
parents:
diff changeset
300
Ritor1
parents:
diff changeset
301 else if (chunk_name == png_IDAT)
Ritor1
parents:
diff changeset
302 {
Ritor1
parents:
diff changeset
303 png_ptr->idat_size = png_ptr->push_length;
Ritor1
parents:
diff changeset
304 png_ptr->process_mode = PNG_READ_IDAT_MODE;
Ritor1
parents:
diff changeset
305 png_push_have_info(png_ptr, info_ptr);
Ritor1
parents:
diff changeset
306 png_ptr->zstream.avail_out =
Ritor1
parents:
diff changeset
307 (uInt) PNG_ROWBYTES(png_ptr->pixel_depth,
Ritor1
parents:
diff changeset
308 png_ptr->iwidth) + 1;
Ritor1
parents:
diff changeset
309 png_ptr->zstream.next_out = png_ptr->row_buf;
Ritor1
parents:
diff changeset
310 return;
Ritor1
parents:
diff changeset
311 }
Ritor1
parents:
diff changeset
312
Ritor1
parents:
diff changeset
313 #ifdef PNG_READ_gAMA_SUPPORTED
Ritor1
parents:
diff changeset
314 else if (png_ptr->chunk_name == png_gAMA)
Ritor1
parents:
diff changeset
315 {
Ritor1
parents:
diff changeset
316 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
Ritor1
parents:
diff changeset
317 {
Ritor1
parents:
diff changeset
318 png_push_save_buffer(png_ptr);
Ritor1
parents:
diff changeset
319 return;
Ritor1
parents:
diff changeset
320 }
Ritor1
parents:
diff changeset
321
Ritor1
parents:
diff changeset
322 png_handle_gAMA(png_ptr, info_ptr, png_ptr->push_length);
Ritor1
parents:
diff changeset
323 }
Ritor1
parents:
diff changeset
324
Ritor1
parents:
diff changeset
325 #endif
Ritor1
parents:
diff changeset
326 #ifdef PNG_READ_sBIT_SUPPORTED
Ritor1
parents:
diff changeset
327 else if (png_ptr->chunk_name == png_sBIT)
Ritor1
parents:
diff changeset
328 {
Ritor1
parents:
diff changeset
329 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
Ritor1
parents:
diff changeset
330 {
Ritor1
parents:
diff changeset
331 png_push_save_buffer(png_ptr);
Ritor1
parents:
diff changeset
332 return;
Ritor1
parents:
diff changeset
333 }
Ritor1
parents:
diff changeset
334
Ritor1
parents:
diff changeset
335 png_handle_sBIT(png_ptr, info_ptr, png_ptr->push_length);
Ritor1
parents:
diff changeset
336 }
Ritor1
parents:
diff changeset
337
Ritor1
parents:
diff changeset
338 #endif
Ritor1
parents:
diff changeset
339 #ifdef PNG_READ_cHRM_SUPPORTED
Ritor1
parents:
diff changeset
340 else if (png_ptr->chunk_name == png_cHRM)
Ritor1
parents:
diff changeset
341 {
Ritor1
parents:
diff changeset
342 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
Ritor1
parents:
diff changeset
343 {
Ritor1
parents:
diff changeset
344 png_push_save_buffer(png_ptr);
Ritor1
parents:
diff changeset
345 return;
Ritor1
parents:
diff changeset
346 }
Ritor1
parents:
diff changeset
347
Ritor1
parents:
diff changeset
348 png_handle_cHRM(png_ptr, info_ptr, png_ptr->push_length);
Ritor1
parents:
diff changeset
349 }
Ritor1
parents:
diff changeset
350
Ritor1
parents:
diff changeset
351 #endif
Ritor1
parents:
diff changeset
352 #ifdef PNG_READ_sRGB_SUPPORTED
Ritor1
parents:
diff changeset
353 else if (chunk_name == png_sRGB)
Ritor1
parents:
diff changeset
354 {
Ritor1
parents:
diff changeset
355 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
Ritor1
parents:
diff changeset
356 {
Ritor1
parents:
diff changeset
357 png_push_save_buffer(png_ptr);
Ritor1
parents:
diff changeset
358 return;
Ritor1
parents:
diff changeset
359 }
Ritor1
parents:
diff changeset
360
Ritor1
parents:
diff changeset
361 png_handle_sRGB(png_ptr, info_ptr, png_ptr->push_length);
Ritor1
parents:
diff changeset
362 }
Ritor1
parents:
diff changeset
363
Ritor1
parents:
diff changeset
364 #endif
Ritor1
parents:
diff changeset
365 #ifdef PNG_READ_iCCP_SUPPORTED
Ritor1
parents:
diff changeset
366 else if (png_ptr->chunk_name == png_iCCP)
Ritor1
parents:
diff changeset
367 {
Ritor1
parents:
diff changeset
368 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
Ritor1
parents:
diff changeset
369 {
Ritor1
parents:
diff changeset
370 png_push_save_buffer(png_ptr);
Ritor1
parents:
diff changeset
371 return;
Ritor1
parents:
diff changeset
372 }
Ritor1
parents:
diff changeset
373
Ritor1
parents:
diff changeset
374 png_handle_iCCP(png_ptr, info_ptr, png_ptr->push_length);
Ritor1
parents:
diff changeset
375 }
Ritor1
parents:
diff changeset
376
Ritor1
parents:
diff changeset
377 #endif
Ritor1
parents:
diff changeset
378 #ifdef PNG_READ_sPLT_SUPPORTED
Ritor1
parents:
diff changeset
379 else if (chunk_name == png_sPLT)
Ritor1
parents:
diff changeset
380 {
Ritor1
parents:
diff changeset
381 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
Ritor1
parents:
diff changeset
382 {
Ritor1
parents:
diff changeset
383 png_push_save_buffer(png_ptr);
Ritor1
parents:
diff changeset
384 return;
Ritor1
parents:
diff changeset
385 }
Ritor1
parents:
diff changeset
386
Ritor1
parents:
diff changeset
387 png_handle_sPLT(png_ptr, info_ptr, png_ptr->push_length);
Ritor1
parents:
diff changeset
388 }
Ritor1
parents:
diff changeset
389
Ritor1
parents:
diff changeset
390 #endif
Ritor1
parents:
diff changeset
391 #ifdef PNG_READ_tRNS_SUPPORTED
Ritor1
parents:
diff changeset
392 else if (chunk_name == png_tRNS)
Ritor1
parents:
diff changeset
393 {
Ritor1
parents:
diff changeset
394 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
Ritor1
parents:
diff changeset
395 {
Ritor1
parents:
diff changeset
396 png_push_save_buffer(png_ptr);
Ritor1
parents:
diff changeset
397 return;
Ritor1
parents:
diff changeset
398 }
Ritor1
parents:
diff changeset
399
Ritor1
parents:
diff changeset
400 png_handle_tRNS(png_ptr, info_ptr, png_ptr->push_length);
Ritor1
parents:
diff changeset
401 }
Ritor1
parents:
diff changeset
402
Ritor1
parents:
diff changeset
403 #endif
Ritor1
parents:
diff changeset
404 #ifdef PNG_READ_bKGD_SUPPORTED
Ritor1
parents:
diff changeset
405 else if (chunk_name == png_bKGD)
Ritor1
parents:
diff changeset
406 {
Ritor1
parents:
diff changeset
407 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
Ritor1
parents:
diff changeset
408 {
Ritor1
parents:
diff changeset
409 png_push_save_buffer(png_ptr);
Ritor1
parents:
diff changeset
410 return;
Ritor1
parents:
diff changeset
411 }
Ritor1
parents:
diff changeset
412
Ritor1
parents:
diff changeset
413 png_handle_bKGD(png_ptr, info_ptr, png_ptr->push_length);
Ritor1
parents:
diff changeset
414 }
Ritor1
parents:
diff changeset
415
Ritor1
parents:
diff changeset
416 #endif
Ritor1
parents:
diff changeset
417 #ifdef PNG_READ_hIST_SUPPORTED
Ritor1
parents:
diff changeset
418 else if (chunk_name == png_hIST)
Ritor1
parents:
diff changeset
419 {
Ritor1
parents:
diff changeset
420 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
Ritor1
parents:
diff changeset
421 {
Ritor1
parents:
diff changeset
422 png_push_save_buffer(png_ptr);
Ritor1
parents:
diff changeset
423 return;
Ritor1
parents:
diff changeset
424 }
Ritor1
parents:
diff changeset
425
Ritor1
parents:
diff changeset
426 png_handle_hIST(png_ptr, info_ptr, png_ptr->push_length);
Ritor1
parents:
diff changeset
427 }
Ritor1
parents:
diff changeset
428
Ritor1
parents:
diff changeset
429 #endif
Ritor1
parents:
diff changeset
430 #ifdef PNG_READ_pHYs_SUPPORTED
Ritor1
parents:
diff changeset
431 else if (chunk_name == png_pHYs)
Ritor1
parents:
diff changeset
432 {
Ritor1
parents:
diff changeset
433 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
Ritor1
parents:
diff changeset
434 {
Ritor1
parents:
diff changeset
435 png_push_save_buffer(png_ptr);
Ritor1
parents:
diff changeset
436 return;
Ritor1
parents:
diff changeset
437 }
Ritor1
parents:
diff changeset
438
Ritor1
parents:
diff changeset
439 png_handle_pHYs(png_ptr, info_ptr, png_ptr->push_length);
Ritor1
parents:
diff changeset
440 }
Ritor1
parents:
diff changeset
441
Ritor1
parents:
diff changeset
442 #endif
Ritor1
parents:
diff changeset
443 #ifdef PNG_READ_oFFs_SUPPORTED
Ritor1
parents:
diff changeset
444 else if (chunk_name == png_oFFs)
Ritor1
parents:
diff changeset
445 {
Ritor1
parents:
diff changeset
446 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
Ritor1
parents:
diff changeset
447 {
Ritor1
parents:
diff changeset
448 png_push_save_buffer(png_ptr);
Ritor1
parents:
diff changeset
449 return;
Ritor1
parents:
diff changeset
450 }
Ritor1
parents:
diff changeset
451
Ritor1
parents:
diff changeset
452 png_handle_oFFs(png_ptr, info_ptr, png_ptr->push_length);
Ritor1
parents:
diff changeset
453 }
Ritor1
parents:
diff changeset
454 #endif
Ritor1
parents:
diff changeset
455
Ritor1
parents:
diff changeset
456 #ifdef PNG_READ_pCAL_SUPPORTED
Ritor1
parents:
diff changeset
457 else if (chunk_name == png_pCAL)
Ritor1
parents:
diff changeset
458 {
Ritor1
parents:
diff changeset
459 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
Ritor1
parents:
diff changeset
460 {
Ritor1
parents:
diff changeset
461 png_push_save_buffer(png_ptr);
Ritor1
parents:
diff changeset
462 return;
Ritor1
parents:
diff changeset
463 }
Ritor1
parents:
diff changeset
464
Ritor1
parents:
diff changeset
465 png_handle_pCAL(png_ptr, info_ptr, png_ptr->push_length);
Ritor1
parents:
diff changeset
466 }
Ritor1
parents:
diff changeset
467
Ritor1
parents:
diff changeset
468 #endif
Ritor1
parents:
diff changeset
469 #ifdef PNG_READ_sCAL_SUPPORTED
Ritor1
parents:
diff changeset
470 else if (chunk_name == png_sCAL)
Ritor1
parents:
diff changeset
471 {
Ritor1
parents:
diff changeset
472 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
Ritor1
parents:
diff changeset
473 {
Ritor1
parents:
diff changeset
474 png_push_save_buffer(png_ptr);
Ritor1
parents:
diff changeset
475 return;
Ritor1
parents:
diff changeset
476 }
Ritor1
parents:
diff changeset
477
Ritor1
parents:
diff changeset
478 png_handle_sCAL(png_ptr, info_ptr, png_ptr->push_length);
Ritor1
parents:
diff changeset
479 }
Ritor1
parents:
diff changeset
480
Ritor1
parents:
diff changeset
481 #endif
Ritor1
parents:
diff changeset
482 #ifdef PNG_READ_tIME_SUPPORTED
Ritor1
parents:
diff changeset
483 else if (chunk_name == png_tIME)
Ritor1
parents:
diff changeset
484 {
Ritor1
parents:
diff changeset
485 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
Ritor1
parents:
diff changeset
486 {
Ritor1
parents:
diff changeset
487 png_push_save_buffer(png_ptr);
Ritor1
parents:
diff changeset
488 return;
Ritor1
parents:
diff changeset
489 }
Ritor1
parents:
diff changeset
490
Ritor1
parents:
diff changeset
491 png_handle_tIME(png_ptr, info_ptr, png_ptr->push_length);
Ritor1
parents:
diff changeset
492 }
Ritor1
parents:
diff changeset
493
Ritor1
parents:
diff changeset
494 #endif
Ritor1
parents:
diff changeset
495 #ifdef PNG_READ_tEXt_SUPPORTED
Ritor1
parents:
diff changeset
496 else if (chunk_name == png_tEXt)
Ritor1
parents:
diff changeset
497 {
Ritor1
parents:
diff changeset
498 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
Ritor1
parents:
diff changeset
499 {
Ritor1
parents:
diff changeset
500 png_push_save_buffer(png_ptr);
Ritor1
parents:
diff changeset
501 return;
Ritor1
parents:
diff changeset
502 }
Ritor1
parents:
diff changeset
503
Ritor1
parents:
diff changeset
504 png_handle_tEXt(png_ptr, info_ptr, png_ptr->push_length);
Ritor1
parents:
diff changeset
505 }
Ritor1
parents:
diff changeset
506
Ritor1
parents:
diff changeset
507 #endif
Ritor1
parents:
diff changeset
508 #ifdef PNG_READ_zTXt_SUPPORTED
Ritor1
parents:
diff changeset
509 else if (chunk_name == png_zTXt)
Ritor1
parents:
diff changeset
510 {
Ritor1
parents:
diff changeset
511 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
Ritor1
parents:
diff changeset
512 {
Ritor1
parents:
diff changeset
513 png_push_save_buffer(png_ptr);
Ritor1
parents:
diff changeset
514 return;
Ritor1
parents:
diff changeset
515 }
Ritor1
parents:
diff changeset
516
Ritor1
parents:
diff changeset
517 png_handle_zTXt(png_ptr, info_ptr, png_ptr->push_length);
Ritor1
parents:
diff changeset
518 }
Ritor1
parents:
diff changeset
519
Ritor1
parents:
diff changeset
520 #endif
Ritor1
parents:
diff changeset
521 #ifdef PNG_READ_iTXt_SUPPORTED
Ritor1
parents:
diff changeset
522 else if (chunk_name == png_iTXt)
Ritor1
parents:
diff changeset
523 {
Ritor1
parents:
diff changeset
524 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
Ritor1
parents:
diff changeset
525 {
Ritor1
parents:
diff changeset
526 png_push_save_buffer(png_ptr);
Ritor1
parents:
diff changeset
527 return;
Ritor1
parents:
diff changeset
528 }
Ritor1
parents:
diff changeset
529
Ritor1
parents:
diff changeset
530 png_handle_iTXt(png_ptr, info_ptr, png_ptr->push_length);
Ritor1
parents:
diff changeset
531 }
Ritor1
parents:
diff changeset
532 #endif
Ritor1
parents:
diff changeset
533
Ritor1
parents:
diff changeset
534 else
Ritor1
parents:
diff changeset
535 {
Ritor1
parents:
diff changeset
536 if (png_ptr->push_length + 4 > png_ptr->buffer_size)
Ritor1
parents:
diff changeset
537 {
Ritor1
parents:
diff changeset
538 png_push_save_buffer(png_ptr);
Ritor1
parents:
diff changeset
539 return;
Ritor1
parents:
diff changeset
540 }
Ritor1
parents:
diff changeset
541 png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length,
Ritor1
parents:
diff changeset
542 PNG_HANDLE_CHUNK_AS_DEFAULT);
Ritor1
parents:
diff changeset
543 }
Ritor1
parents:
diff changeset
544
Ritor1
parents:
diff changeset
545 png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
Ritor1
parents:
diff changeset
546 }
Ritor1
parents:
diff changeset
547
Ritor1
parents:
diff changeset
548 void /* PRIVATE */
Ritor1
parents:
diff changeset
549 png_push_crc_skip(png_structrp png_ptr, png_uint_32 skip)
Ritor1
parents:
diff changeset
550 {
Ritor1
parents:
diff changeset
551 png_ptr->process_mode = PNG_SKIP_MODE;
Ritor1
parents:
diff changeset
552 png_ptr->skip_length = skip;
Ritor1
parents:
diff changeset
553 }
Ritor1
parents:
diff changeset
554
Ritor1
parents:
diff changeset
555 void /* PRIVATE */
Ritor1
parents:
diff changeset
556 png_push_crc_finish(png_structrp png_ptr)
Ritor1
parents:
diff changeset
557 {
Ritor1
parents:
diff changeset
558 if (png_ptr->skip_length && png_ptr->save_buffer_size)
Ritor1
parents:
diff changeset
559 {
Ritor1
parents:
diff changeset
560 png_size_t save_size = png_ptr->save_buffer_size;
Ritor1
parents:
diff changeset
561 png_uint_32 skip_length = png_ptr->skip_length;
Ritor1
parents:
diff changeset
562
Ritor1
parents:
diff changeset
563 /* We want the smaller of 'skip_length' and 'save_buffer_size', but
Ritor1
parents:
diff changeset
564 * they are of different types and we don't know which variable has the
Ritor1
parents:
diff changeset
565 * fewest bits. Carefully select the smaller and cast it to the type of
Ritor1
parents:
diff changeset
566 * the larger - this cannot overflow. Do not cast in the following test
Ritor1
parents:
diff changeset
567 * - it will break on either 16 or 64 bit platforms.
Ritor1
parents:
diff changeset
568 */
Ritor1
parents:
diff changeset
569 if (skip_length < save_size)
Ritor1
parents:
diff changeset
570 save_size = (png_size_t)skip_length;
Ritor1
parents:
diff changeset
571
Ritor1
parents:
diff changeset
572 else
Ritor1
parents:
diff changeset
573 skip_length = (png_uint_32)save_size;
Ritor1
parents:
diff changeset
574
Ritor1
parents:
diff changeset
575 png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
Ritor1
parents:
diff changeset
576
Ritor1
parents:
diff changeset
577 png_ptr->skip_length -= skip_length;
Ritor1
parents:
diff changeset
578 png_ptr->buffer_size -= save_size;
Ritor1
parents:
diff changeset
579 png_ptr->save_buffer_size -= save_size;
Ritor1
parents:
diff changeset
580 png_ptr->save_buffer_ptr += save_size;
Ritor1
parents:
diff changeset
581 }
Ritor1
parents:
diff changeset
582 if (png_ptr->skip_length && png_ptr->current_buffer_size)
Ritor1
parents:
diff changeset
583 {
Ritor1
parents:
diff changeset
584 png_size_t save_size = png_ptr->current_buffer_size;
Ritor1
parents:
diff changeset
585 png_uint_32 skip_length = png_ptr->skip_length;
Ritor1
parents:
diff changeset
586
Ritor1
parents:
diff changeset
587 /* We want the smaller of 'skip_length' and 'current_buffer_size', here,
Ritor1
parents:
diff changeset
588 * the same problem exists as above and the same solution.
Ritor1
parents:
diff changeset
589 */
Ritor1
parents:
diff changeset
590 if (skip_length < save_size)
Ritor1
parents:
diff changeset
591 save_size = (png_size_t)skip_length;
Ritor1
parents:
diff changeset
592
Ritor1
parents:
diff changeset
593 else
Ritor1
parents:
diff changeset
594 skip_length = (png_uint_32)save_size;
Ritor1
parents:
diff changeset
595
Ritor1
parents:
diff changeset
596 png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
Ritor1
parents:
diff changeset
597
Ritor1
parents:
diff changeset
598 png_ptr->skip_length -= skip_length;
Ritor1
parents:
diff changeset
599 png_ptr->buffer_size -= save_size;
Ritor1
parents:
diff changeset
600 png_ptr->current_buffer_size -= save_size;
Ritor1
parents:
diff changeset
601 png_ptr->current_buffer_ptr += save_size;
Ritor1
parents:
diff changeset
602 }
Ritor1
parents:
diff changeset
603 if (!png_ptr->skip_length)
Ritor1
parents:
diff changeset
604 {
Ritor1
parents:
diff changeset
605 if (png_ptr->buffer_size < 4)
Ritor1
parents:
diff changeset
606 {
Ritor1
parents:
diff changeset
607 png_push_save_buffer(png_ptr);
Ritor1
parents:
diff changeset
608 return;
Ritor1
parents:
diff changeset
609 }
Ritor1
parents:
diff changeset
610
Ritor1
parents:
diff changeset
611 png_crc_finish(png_ptr, 0);
Ritor1
parents:
diff changeset
612 png_ptr->process_mode = PNG_READ_CHUNK_MODE;
Ritor1
parents:
diff changeset
613 }
Ritor1
parents:
diff changeset
614 }
Ritor1
parents:
diff changeset
615
Ritor1
parents:
diff changeset
616 void PNGCBAPI
Ritor1
parents:
diff changeset
617 png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length)
Ritor1
parents:
diff changeset
618 {
Ritor1
parents:
diff changeset
619 png_bytep ptr;
Ritor1
parents:
diff changeset
620
Ritor1
parents:
diff changeset
621 if (png_ptr == NULL)
Ritor1
parents:
diff changeset
622 return;
Ritor1
parents:
diff changeset
623
Ritor1
parents:
diff changeset
624 ptr = buffer;
Ritor1
parents:
diff changeset
625 if (png_ptr->save_buffer_size)
Ritor1
parents:
diff changeset
626 {
Ritor1
parents:
diff changeset
627 png_size_t save_size;
Ritor1
parents:
diff changeset
628
Ritor1
parents:
diff changeset
629 if (length < png_ptr->save_buffer_size)
Ritor1
parents:
diff changeset
630 save_size = length;
Ritor1
parents:
diff changeset
631
Ritor1
parents:
diff changeset
632 else
Ritor1
parents:
diff changeset
633 save_size = png_ptr->save_buffer_size;
Ritor1
parents:
diff changeset
634
Ritor1
parents:
diff changeset
635 memcpy(ptr, png_ptr->save_buffer_ptr, save_size);
Ritor1
parents:
diff changeset
636 length -= save_size;
Ritor1
parents:
diff changeset
637 ptr += save_size;
Ritor1
parents:
diff changeset
638 png_ptr->buffer_size -= save_size;
Ritor1
parents:
diff changeset
639 png_ptr->save_buffer_size -= save_size;
Ritor1
parents:
diff changeset
640 png_ptr->save_buffer_ptr += save_size;
Ritor1
parents:
diff changeset
641 }
Ritor1
parents:
diff changeset
642 if (length && png_ptr->current_buffer_size)
Ritor1
parents:
diff changeset
643 {
Ritor1
parents:
diff changeset
644 png_size_t save_size;
Ritor1
parents:
diff changeset
645
Ritor1
parents:
diff changeset
646 if (length < png_ptr->current_buffer_size)
Ritor1
parents:
diff changeset
647 save_size = length;
Ritor1
parents:
diff changeset
648
Ritor1
parents:
diff changeset
649 else
Ritor1
parents:
diff changeset
650 save_size = png_ptr->current_buffer_size;
Ritor1
parents:
diff changeset
651
Ritor1
parents:
diff changeset
652 memcpy(ptr, png_ptr->current_buffer_ptr, save_size);
Ritor1
parents:
diff changeset
653 png_ptr->buffer_size -= save_size;
Ritor1
parents:
diff changeset
654 png_ptr->current_buffer_size -= save_size;
Ritor1
parents:
diff changeset
655 png_ptr->current_buffer_ptr += save_size;
Ritor1
parents:
diff changeset
656 }
Ritor1
parents:
diff changeset
657 }
Ritor1
parents:
diff changeset
658
Ritor1
parents:
diff changeset
659 void /* PRIVATE */
Ritor1
parents:
diff changeset
660 png_push_save_buffer(png_structrp png_ptr)
Ritor1
parents:
diff changeset
661 {
Ritor1
parents:
diff changeset
662 if (png_ptr->save_buffer_size)
Ritor1
parents:
diff changeset
663 {
Ritor1
parents:
diff changeset
664 if (png_ptr->save_buffer_ptr != png_ptr->save_buffer)
Ritor1
parents:
diff changeset
665 {
Ritor1
parents:
diff changeset
666 png_size_t i, istop;
Ritor1
parents:
diff changeset
667 png_bytep sp;
Ritor1
parents:
diff changeset
668 png_bytep dp;
Ritor1
parents:
diff changeset
669
Ritor1
parents:
diff changeset
670 istop = png_ptr->save_buffer_size;
Ritor1
parents:
diff changeset
671 for (i = 0, sp = png_ptr->save_buffer_ptr, dp = png_ptr->save_buffer;
Ritor1
parents:
diff changeset
672 i < istop; i++, sp++, dp++)
Ritor1
parents:
diff changeset
673 {
Ritor1
parents:
diff changeset
674 *dp = *sp;
Ritor1
parents:
diff changeset
675 }
Ritor1
parents:
diff changeset
676 }
Ritor1
parents:
diff changeset
677 }
Ritor1
parents:
diff changeset
678 if (png_ptr->save_buffer_size + png_ptr->current_buffer_size >
Ritor1
parents:
diff changeset
679 png_ptr->save_buffer_max)
Ritor1
parents:
diff changeset
680 {
Ritor1
parents:
diff changeset
681 png_size_t new_max;
Ritor1
parents:
diff changeset
682 png_bytep old_buffer;
Ritor1
parents:
diff changeset
683
Ritor1
parents:
diff changeset
684 if (png_ptr->save_buffer_size > PNG_SIZE_MAX -
Ritor1
parents:
diff changeset
685 (png_ptr->current_buffer_size + 256))
Ritor1
parents:
diff changeset
686 {
Ritor1
parents:
diff changeset
687 png_error(png_ptr, "Potential overflow of save_buffer");
Ritor1
parents:
diff changeset
688 }
Ritor1
parents:
diff changeset
689
Ritor1
parents:
diff changeset
690 new_max = png_ptr->save_buffer_size + png_ptr->current_buffer_size + 256;
Ritor1
parents:
diff changeset
691 old_buffer = png_ptr->save_buffer;
Ritor1
parents:
diff changeset
692 png_ptr->save_buffer = (png_bytep)png_malloc_warn(png_ptr,
Ritor1
parents:
diff changeset
693 (png_size_t)new_max);
Ritor1
parents:
diff changeset
694
Ritor1
parents:
diff changeset
695 if (png_ptr->save_buffer == NULL)
Ritor1
parents:
diff changeset
696 {
Ritor1
parents:
diff changeset
697 png_free(png_ptr, old_buffer);
Ritor1
parents:
diff changeset
698 png_error(png_ptr, "Insufficient memory for save_buffer");
Ritor1
parents:
diff changeset
699 }
Ritor1
parents:
diff changeset
700
Ritor1
parents:
diff changeset
701 memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size);
Ritor1
parents:
diff changeset
702 png_free(png_ptr, old_buffer);
Ritor1
parents:
diff changeset
703 png_ptr->save_buffer_max = new_max;
Ritor1
parents:
diff changeset
704 }
Ritor1
parents:
diff changeset
705 if (png_ptr->current_buffer_size)
Ritor1
parents:
diff changeset
706 {
Ritor1
parents:
diff changeset
707 memcpy(png_ptr->save_buffer + png_ptr->save_buffer_size,
Ritor1
parents:
diff changeset
708 png_ptr->current_buffer_ptr, png_ptr->current_buffer_size);
Ritor1
parents:
diff changeset
709 png_ptr->save_buffer_size += png_ptr->current_buffer_size;
Ritor1
parents:
diff changeset
710 png_ptr->current_buffer_size = 0;
Ritor1
parents:
diff changeset
711 }
Ritor1
parents:
diff changeset
712 png_ptr->save_buffer_ptr = png_ptr->save_buffer;
Ritor1
parents:
diff changeset
713 png_ptr->buffer_size = 0;
Ritor1
parents:
diff changeset
714 }
Ritor1
parents:
diff changeset
715
Ritor1
parents:
diff changeset
716 void /* PRIVATE */
Ritor1
parents:
diff changeset
717 png_push_restore_buffer(png_structrp png_ptr, png_bytep buffer,
Ritor1
parents:
diff changeset
718 png_size_t buffer_length)
Ritor1
parents:
diff changeset
719 {
Ritor1
parents:
diff changeset
720 png_ptr->current_buffer = buffer;
Ritor1
parents:
diff changeset
721 png_ptr->current_buffer_size = buffer_length;
Ritor1
parents:
diff changeset
722 png_ptr->buffer_size = buffer_length + png_ptr->save_buffer_size;
Ritor1
parents:
diff changeset
723 png_ptr->current_buffer_ptr = png_ptr->current_buffer;
Ritor1
parents:
diff changeset
724 }
Ritor1
parents:
diff changeset
725
Ritor1
parents:
diff changeset
726 void /* PRIVATE */
Ritor1
parents:
diff changeset
727 png_push_read_IDAT(png_structrp png_ptr)
Ritor1
parents:
diff changeset
728 {
Ritor1
parents:
diff changeset
729 if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
Ritor1
parents:
diff changeset
730 {
Ritor1
parents:
diff changeset
731 png_byte chunk_length[4];
Ritor1
parents:
diff changeset
732 png_byte chunk_tag[4];
Ritor1
parents:
diff changeset
733
Ritor1
parents:
diff changeset
734 /* TODO: this code can be commoned up with the same code in push_read */
Ritor1
parents:
diff changeset
735 if (png_ptr->buffer_size < 8)
Ritor1
parents:
diff changeset
736 {
Ritor1
parents:
diff changeset
737 png_push_save_buffer(png_ptr);
Ritor1
parents:
diff changeset
738 return;
Ritor1
parents:
diff changeset
739 }
Ritor1
parents:
diff changeset
740
Ritor1
parents:
diff changeset
741 png_push_fill_buffer(png_ptr, chunk_length, 4);
Ritor1
parents:
diff changeset
742 png_ptr->push_length = png_get_uint_31(png_ptr, chunk_length);
Ritor1
parents:
diff changeset
743 png_reset_crc(png_ptr);
Ritor1
parents:
diff changeset
744 png_crc_read(png_ptr, chunk_tag, 4);
Ritor1
parents:
diff changeset
745 png_ptr->chunk_name = PNG_CHUNK_FROM_STRING(chunk_tag);
Ritor1
parents:
diff changeset
746 png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
Ritor1
parents:
diff changeset
747
Ritor1
parents:
diff changeset
748 if (png_ptr->chunk_name != png_IDAT)
Ritor1
parents:
diff changeset
749 {
Ritor1
parents:
diff changeset
750 png_ptr->process_mode = PNG_READ_CHUNK_MODE;
Ritor1
parents:
diff changeset
751
Ritor1
parents:
diff changeset
752 if (!(png_ptr->flags & PNG_FLAG_ZSTREAM_ENDED))
Ritor1
parents:
diff changeset
753 png_error(png_ptr, "Not enough compressed data");
Ritor1
parents:
diff changeset
754
Ritor1
parents:
diff changeset
755 return;
Ritor1
parents:
diff changeset
756 }
Ritor1
parents:
diff changeset
757
Ritor1
parents:
diff changeset
758 png_ptr->idat_size = png_ptr->push_length;
Ritor1
parents:
diff changeset
759 }
Ritor1
parents:
diff changeset
760
Ritor1
parents:
diff changeset
761 if (png_ptr->idat_size && png_ptr->save_buffer_size)
Ritor1
parents:
diff changeset
762 {
Ritor1
parents:
diff changeset
763 png_size_t save_size = png_ptr->save_buffer_size;
Ritor1
parents:
diff changeset
764 png_uint_32 idat_size = png_ptr->idat_size;
Ritor1
parents:
diff changeset
765
Ritor1
parents:
diff changeset
766 /* We want the smaller of 'idat_size' and 'current_buffer_size', but they
Ritor1
parents:
diff changeset
767 * are of different types and we don't know which variable has the fewest
Ritor1
parents:
diff changeset
768 * bits. Carefully select the smaller and cast it to the type of the
Ritor1
parents:
diff changeset
769 * larger - this cannot overflow. Do not cast in the following test - it
Ritor1
parents:
diff changeset
770 * will break on either 16 or 64 bit platforms.
Ritor1
parents:
diff changeset
771 */
Ritor1
parents:
diff changeset
772 if (idat_size < save_size)
Ritor1
parents:
diff changeset
773 save_size = (png_size_t)idat_size;
Ritor1
parents:
diff changeset
774
Ritor1
parents:
diff changeset
775 else
Ritor1
parents:
diff changeset
776 idat_size = (png_uint_32)save_size;
Ritor1
parents:
diff changeset
777
Ritor1
parents:
diff changeset
778 png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
Ritor1
parents:
diff changeset
779
Ritor1
parents:
diff changeset
780 png_process_IDAT_data(png_ptr, png_ptr->save_buffer_ptr, save_size);
Ritor1
parents:
diff changeset
781
Ritor1
parents:
diff changeset
782 png_ptr->idat_size -= idat_size;
Ritor1
parents:
diff changeset
783 png_ptr->buffer_size -= save_size;
Ritor1
parents:
diff changeset
784 png_ptr->save_buffer_size -= save_size;
Ritor1
parents:
diff changeset
785 png_ptr->save_buffer_ptr += save_size;
Ritor1
parents:
diff changeset
786 }
Ritor1
parents:
diff changeset
787
Ritor1
parents:
diff changeset
788 if (png_ptr->idat_size && png_ptr->current_buffer_size)
Ritor1
parents:
diff changeset
789 {
Ritor1
parents:
diff changeset
790 png_size_t save_size = png_ptr->current_buffer_size;
Ritor1
parents:
diff changeset
791 png_uint_32 idat_size = png_ptr->idat_size;
Ritor1
parents:
diff changeset
792
Ritor1
parents:
diff changeset
793 /* We want the smaller of 'idat_size' and 'current_buffer_size', but they
Ritor1
parents:
diff changeset
794 * are of different types and we don't know which variable has the fewest
Ritor1
parents:
diff changeset
795 * bits. Carefully select the smaller and cast it to the type of the
Ritor1
parents:
diff changeset
796 * larger - this cannot overflow.
Ritor1
parents:
diff changeset
797 */
Ritor1
parents:
diff changeset
798 if (idat_size < save_size)
Ritor1
parents:
diff changeset
799 save_size = (png_size_t)idat_size;
Ritor1
parents:
diff changeset
800
Ritor1
parents:
diff changeset
801 else
Ritor1
parents:
diff changeset
802 idat_size = (png_uint_32)save_size;
Ritor1
parents:
diff changeset
803
Ritor1
parents:
diff changeset
804 png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
Ritor1
parents:
diff changeset
805
Ritor1
parents:
diff changeset
806 png_process_IDAT_data(png_ptr, png_ptr->current_buffer_ptr, save_size);
Ritor1
parents:
diff changeset
807
Ritor1
parents:
diff changeset
808 png_ptr->idat_size -= idat_size;
Ritor1
parents:
diff changeset
809 png_ptr->buffer_size -= save_size;
Ritor1
parents:
diff changeset
810 png_ptr->current_buffer_size -= save_size;
Ritor1
parents:
diff changeset
811 png_ptr->current_buffer_ptr += save_size;
Ritor1
parents:
diff changeset
812 }
Ritor1
parents:
diff changeset
813 if (!png_ptr->idat_size)
Ritor1
parents:
diff changeset
814 {
Ritor1
parents:
diff changeset
815 if (png_ptr->buffer_size < 4)
Ritor1
parents:
diff changeset
816 {
Ritor1
parents:
diff changeset
817 png_push_save_buffer(png_ptr);
Ritor1
parents:
diff changeset
818 return;
Ritor1
parents:
diff changeset
819 }
Ritor1
parents:
diff changeset
820
Ritor1
parents:
diff changeset
821 png_crc_finish(png_ptr, 0);
Ritor1
parents:
diff changeset
822 png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
Ritor1
parents:
diff changeset
823 png_ptr->mode |= PNG_AFTER_IDAT;
Ritor1
parents:
diff changeset
824 png_ptr->zowner = 0;
Ritor1
parents:
diff changeset
825 }
Ritor1
parents:
diff changeset
826 }
Ritor1
parents:
diff changeset
827
Ritor1
parents:
diff changeset
828 void /* PRIVATE */
Ritor1
parents:
diff changeset
829 png_process_IDAT_data(png_structrp png_ptr, png_bytep buffer,
Ritor1
parents:
diff changeset
830 png_size_t buffer_length)
Ritor1
parents:
diff changeset
831 {
Ritor1
parents:
diff changeset
832 /* The caller checks for a non-zero buffer length. */
Ritor1
parents:
diff changeset
833 if (!(buffer_length > 0) || buffer == NULL)
Ritor1
parents:
diff changeset
834 png_error(png_ptr, "No IDAT data (internal error)");
Ritor1
parents:
diff changeset
835
Ritor1
parents:
diff changeset
836 /* This routine must process all the data it has been given
Ritor1
parents:
diff changeset
837 * before returning, calling the row callback as required to
Ritor1
parents:
diff changeset
838 * handle the uncompressed results.
Ritor1
parents:
diff changeset
839 */
Ritor1
parents:
diff changeset
840 png_ptr->zstream.next_in = buffer;
Ritor1
parents:
diff changeset
841 /* TODO: WARNING: TRUNCATION ERROR: DANGER WILL ROBINSON: */
Ritor1
parents:
diff changeset
842 png_ptr->zstream.avail_in = (uInt)buffer_length;
Ritor1
parents:
diff changeset
843
Ritor1
parents:
diff changeset
844 /* Keep going until the decompressed data is all processed
Ritor1
parents:
diff changeset
845 * or the stream marked as finished.
Ritor1
parents:
diff changeset
846 */
Ritor1
parents:
diff changeset
847 while (png_ptr->zstream.avail_in > 0 &&
Ritor1
parents:
diff changeset
848 !(png_ptr->flags & PNG_FLAG_ZSTREAM_ENDED))
Ritor1
parents:
diff changeset
849 {
Ritor1
parents:
diff changeset
850 int ret;
Ritor1
parents:
diff changeset
851
Ritor1
parents:
diff changeset
852 /* We have data for zlib, but we must check that zlib
Ritor1
parents:
diff changeset
853 * has someplace to put the results. It doesn't matter
Ritor1
parents:
diff changeset
854 * if we don't expect any results -- it may be the input
Ritor1
parents:
diff changeset
855 * data is just the LZ end code.
Ritor1
parents:
diff changeset
856 */
Ritor1
parents:
diff changeset
857 if (!(png_ptr->zstream.avail_out > 0))
Ritor1
parents:
diff changeset
858 {
Ritor1
parents:
diff changeset
859 /* TODO: WARNING: TRUNCATION ERROR: DANGER WILL ROBINSON: */
Ritor1
parents:
diff changeset
860 png_ptr->zstream.avail_out = (uInt)(PNG_ROWBYTES(png_ptr->pixel_depth,
Ritor1
parents:
diff changeset
861 png_ptr->iwidth) + 1);
Ritor1
parents:
diff changeset
862
Ritor1
parents:
diff changeset
863 png_ptr->zstream.next_out = png_ptr->row_buf;
Ritor1
parents:
diff changeset
864 }
Ritor1
parents:
diff changeset
865
Ritor1
parents:
diff changeset
866 /* Using Z_SYNC_FLUSH here means that an unterminated
Ritor1
parents:
diff changeset
867 * LZ stream (a stream with a missing end code) can still
Ritor1
parents:
diff changeset
868 * be handled, otherwise (Z_NO_FLUSH) a future zlib
Ritor1
parents:
diff changeset
869 * implementation might defer output and therefore
Ritor1
parents:
diff changeset
870 * change the current behavior (see comments in inflate.c
Ritor1
parents:
diff changeset
871 * for why this doesn't happen at present with zlib 1.2.5).
Ritor1
parents:
diff changeset
872 */
Ritor1
parents:
diff changeset
873 ret = inflate(&png_ptr->zstream, Z_SYNC_FLUSH);
Ritor1
parents:
diff changeset
874
Ritor1
parents:
diff changeset
875 /* Check for any failure before proceeding. */
Ritor1
parents:
diff changeset
876 if (ret != Z_OK && ret != Z_STREAM_END)
Ritor1
parents:
diff changeset
877 {
Ritor1
parents:
diff changeset
878 /* Terminate the decompression. */
Ritor1
parents:
diff changeset
879 png_ptr->flags |= PNG_FLAG_ZSTREAM_ENDED;
Ritor1
parents:
diff changeset
880 png_ptr->zowner = 0;
Ritor1
parents:
diff changeset
881
Ritor1
parents:
diff changeset
882 /* This may be a truncated stream (missing or
Ritor1
parents:
diff changeset
883 * damaged end code). Treat that as a warning.
Ritor1
parents:
diff changeset
884 */
Ritor1
parents:
diff changeset
885 if (png_ptr->row_number >= png_ptr->num_rows ||
Ritor1
parents:
diff changeset
886 png_ptr->pass > 6)
Ritor1
parents:
diff changeset
887 png_warning(png_ptr, "Truncated compressed data in IDAT");
Ritor1
parents:
diff changeset
888
Ritor1
parents:
diff changeset
889 else
Ritor1
parents:
diff changeset
890 png_error(png_ptr, "Decompression error in IDAT");
Ritor1
parents:
diff changeset
891
Ritor1
parents:
diff changeset
892 /* Skip the check on unprocessed input */
Ritor1
parents:
diff changeset
893 return;
Ritor1
parents:
diff changeset
894 }
Ritor1
parents:
diff changeset
895
Ritor1
parents:
diff changeset
896 /* Did inflate output any data? */
Ritor1
parents:
diff changeset
897 if (png_ptr->zstream.next_out != png_ptr->row_buf)
Ritor1
parents:
diff changeset
898 {
Ritor1
parents:
diff changeset
899 /* Is this unexpected data after the last row?
Ritor1
parents:
diff changeset
900 * If it is, artificially terminate the LZ output
Ritor1
parents:
diff changeset
901 * here.
Ritor1
parents:
diff changeset
902 */
Ritor1
parents:
diff changeset
903 if (png_ptr->row_number >= png_ptr->num_rows ||
Ritor1
parents:
diff changeset
904 png_ptr->pass > 6)
Ritor1
parents:
diff changeset
905 {
Ritor1
parents:
diff changeset
906 /* Extra data. */
Ritor1
parents:
diff changeset
907 png_warning(png_ptr, "Extra compressed data in IDAT");
Ritor1
parents:
diff changeset
908 png_ptr->flags |= PNG_FLAG_ZSTREAM_ENDED;
Ritor1
parents:
diff changeset
909 png_ptr->zowner = 0;
Ritor1
parents:
diff changeset
910
Ritor1
parents:
diff changeset
911 /* Do no more processing; skip the unprocessed
Ritor1
parents:
diff changeset
912 * input check below.
Ritor1
parents:
diff changeset
913 */
Ritor1
parents:
diff changeset
914 return;
Ritor1
parents:
diff changeset
915 }
Ritor1
parents:
diff changeset
916
Ritor1
parents:
diff changeset
917 /* Do we have a complete row? */
Ritor1
parents:
diff changeset
918 if (png_ptr->zstream.avail_out == 0)
Ritor1
parents:
diff changeset
919 png_push_process_row(png_ptr);
Ritor1
parents:
diff changeset
920 }
Ritor1
parents:
diff changeset
921
Ritor1
parents:
diff changeset
922 /* And check for the end of the stream. */
Ritor1
parents:
diff changeset
923 if (ret == Z_STREAM_END)
Ritor1
parents:
diff changeset
924 png_ptr->flags |= PNG_FLAG_ZSTREAM_ENDED;
Ritor1
parents:
diff changeset
925 }
Ritor1
parents:
diff changeset
926
Ritor1
parents:
diff changeset
927 /* All the data should have been processed, if anything
Ritor1
parents:
diff changeset
928 * is left at this point we have bytes of IDAT data
Ritor1
parents:
diff changeset
929 * after the zlib end code.
Ritor1
parents:
diff changeset
930 */
Ritor1
parents:
diff changeset
931 if (png_ptr->zstream.avail_in > 0)
Ritor1
parents:
diff changeset
932 png_warning(png_ptr, "Extra compression data in IDAT");
Ritor1
parents:
diff changeset
933 }
Ritor1
parents:
diff changeset
934
Ritor1
parents:
diff changeset
935 void /* PRIVATE */
Ritor1
parents:
diff changeset
936 png_push_process_row(png_structrp png_ptr)
Ritor1
parents:
diff changeset
937 {
Ritor1
parents:
diff changeset
938 /* 1.5.6: row_info moved out of png_struct to a local here. */
Ritor1
parents:
diff changeset
939 png_row_info row_info;
Ritor1
parents:
diff changeset
940
Ritor1
parents:
diff changeset
941 row_info.width = png_ptr->iwidth; /* NOTE: width of current interlaced row */
Ritor1
parents:
diff changeset
942 row_info.color_type = png_ptr->color_type;
Ritor1
parents:
diff changeset
943 row_info.bit_depth = png_ptr->bit_depth;
Ritor1
parents:
diff changeset
944 row_info.channels = png_ptr->channels;
Ritor1
parents:
diff changeset
945 row_info.pixel_depth = png_ptr->pixel_depth;
Ritor1
parents:
diff changeset
946 row_info.rowbytes = PNG_ROWBYTES(row_info.pixel_depth, row_info.width);
Ritor1
parents:
diff changeset
947
Ritor1
parents:
diff changeset
948 if (png_ptr->row_buf[0] > PNG_FILTER_VALUE_NONE)
Ritor1
parents:
diff changeset
949 {
Ritor1
parents:
diff changeset
950 if (png_ptr->row_buf[0] < PNG_FILTER_VALUE_LAST)
Ritor1
parents:
diff changeset
951 png_read_filter_row(png_ptr, &row_info, png_ptr->row_buf + 1,
Ritor1
parents:
diff changeset
952 png_ptr->prev_row + 1, png_ptr->row_buf[0]);
Ritor1
parents:
diff changeset
953 else
Ritor1
parents:
diff changeset
954 png_error(png_ptr, "bad adaptive filter value");
Ritor1
parents:
diff changeset
955 }
Ritor1
parents:
diff changeset
956
Ritor1
parents:
diff changeset
957 /* libpng 1.5.6: the following line was copying png_ptr->rowbytes before
Ritor1
parents:
diff changeset
958 * 1.5.6, while the buffer really is this big in current versions of libpng
Ritor1
parents:
diff changeset
959 * it may not be in the future, so this was changed just to copy the
Ritor1
parents:
diff changeset
960 * interlaced row count:
Ritor1
parents:
diff changeset
961 */
Ritor1
parents:
diff changeset
962 memcpy(png_ptr->prev_row, png_ptr->row_buf, row_info.rowbytes + 1);
Ritor1
parents:
diff changeset
963
Ritor1
parents:
diff changeset
964 #ifdef PNG_READ_TRANSFORMS_SUPPORTED
Ritor1
parents:
diff changeset
965 if (png_ptr->transformations)
Ritor1
parents:
diff changeset
966 png_do_read_transformations(png_ptr, &row_info);
Ritor1
parents:
diff changeset
967 #endif
Ritor1
parents:
diff changeset
968
Ritor1
parents:
diff changeset
969 /* The transformed pixel depth should match the depth now in row_info. */
Ritor1
parents:
diff changeset
970 if (png_ptr->transformed_pixel_depth == 0)
Ritor1
parents:
diff changeset
971 {
Ritor1
parents:
diff changeset
972 png_ptr->transformed_pixel_depth = row_info.pixel_depth;
Ritor1
parents:
diff changeset
973 if (row_info.pixel_depth > png_ptr->maximum_pixel_depth)
Ritor1
parents:
diff changeset
974 png_error(png_ptr, "progressive row overflow");
Ritor1
parents:
diff changeset
975 }
Ritor1
parents:
diff changeset
976
Ritor1
parents:
diff changeset
977 else if (png_ptr->transformed_pixel_depth != row_info.pixel_depth)
Ritor1
parents:
diff changeset
978 png_error(png_ptr, "internal progressive row size calculation error");
Ritor1
parents:
diff changeset
979
Ritor1
parents:
diff changeset
980
Ritor1
parents:
diff changeset
981 #ifdef PNG_READ_INTERLACING_SUPPORTED
Ritor1
parents:
diff changeset
982 /* Blow up interlaced rows to full size */
Ritor1
parents:
diff changeset
983 if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
Ritor1
parents:
diff changeset
984 {
Ritor1
parents:
diff changeset
985 if (png_ptr->pass < 6)
Ritor1
parents:
diff changeset
986 png_do_read_interlace(&row_info, png_ptr->row_buf + 1, png_ptr->pass,
Ritor1
parents:
diff changeset
987 png_ptr->transformations);
Ritor1
parents:
diff changeset
988
Ritor1
parents:
diff changeset
989 switch (png_ptr->pass)
Ritor1
parents:
diff changeset
990 {
Ritor1
parents:
diff changeset
991 case 0:
Ritor1
parents:
diff changeset
992 {
Ritor1
parents:
diff changeset
993 int i;
Ritor1
parents:
diff changeset
994 for (i = 0; i < 8 && png_ptr->pass == 0; i++)
Ritor1
parents:
diff changeset
995 {
Ritor1
parents:
diff changeset
996 png_push_have_row(png_ptr, png_ptr->row_buf + 1);
Ritor1
parents:
diff changeset
997 png_read_push_finish_row(png_ptr); /* Updates png_ptr->pass */
Ritor1
parents:
diff changeset
998 }
Ritor1
parents:
diff changeset
999
Ritor1
parents:
diff changeset
1000 if (png_ptr->pass == 2) /* Pass 1 might be empty */
Ritor1
parents:
diff changeset
1001 {
Ritor1
parents:
diff changeset
1002 for (i = 0; i < 4 && png_ptr->pass == 2; i++)
Ritor1
parents:
diff changeset
1003 {
Ritor1
parents:
diff changeset
1004 png_push_have_row(png_ptr, NULL);
Ritor1
parents:
diff changeset
1005 png_read_push_finish_row(png_ptr);
Ritor1
parents:
diff changeset
1006 }
Ritor1
parents:
diff changeset
1007 }
Ritor1
parents:
diff changeset
1008
Ritor1
parents:
diff changeset
1009 if (png_ptr->pass == 4 && png_ptr->height <= 4)
Ritor1
parents:
diff changeset
1010 {
Ritor1
parents:
diff changeset
1011 for (i = 0; i < 2 && png_ptr->pass == 4; i++)
Ritor1
parents:
diff changeset
1012 {
Ritor1
parents:
diff changeset
1013 png_push_have_row(png_ptr, NULL);
Ritor1
parents:
diff changeset
1014 png_read_push_finish_row(png_ptr);
Ritor1
parents:
diff changeset
1015 }
Ritor1
parents:
diff changeset
1016 }
Ritor1
parents:
diff changeset
1017
Ritor1
parents:
diff changeset
1018 if (png_ptr->pass == 6 && png_ptr->height <= 4)
Ritor1
parents:
diff changeset
1019 {
Ritor1
parents:
diff changeset
1020 png_push_have_row(png_ptr, NULL);
Ritor1
parents:
diff changeset
1021 png_read_push_finish_row(png_ptr);
Ritor1
parents:
diff changeset
1022 }
Ritor1
parents:
diff changeset
1023
Ritor1
parents:
diff changeset
1024 break;
Ritor1
parents:
diff changeset
1025 }
Ritor1
parents:
diff changeset
1026
Ritor1
parents:
diff changeset
1027 case 1:
Ritor1
parents:
diff changeset
1028 {
Ritor1
parents:
diff changeset
1029 int i;
Ritor1
parents:
diff changeset
1030 for (i = 0; i < 8 && png_ptr->pass == 1; i++)
Ritor1
parents:
diff changeset
1031 {
Ritor1
parents:
diff changeset
1032 png_push_have_row(png_ptr, png_ptr->row_buf + 1);
Ritor1
parents:
diff changeset
1033 png_read_push_finish_row(png_ptr);
Ritor1
parents:
diff changeset
1034 }
Ritor1
parents:
diff changeset
1035
Ritor1
parents:
diff changeset
1036 if (png_ptr->pass == 2) /* Skip top 4 generated rows */
Ritor1
parents:
diff changeset
1037 {
Ritor1
parents:
diff changeset
1038 for (i = 0; i < 4 && png_ptr->pass == 2; i++)
Ritor1
parents:
diff changeset
1039 {
Ritor1
parents:
diff changeset
1040 png_push_have_row(png_ptr, NULL);
Ritor1
parents:
diff changeset
1041 png_read_push_finish_row(png_ptr);
Ritor1
parents:
diff changeset
1042 }
Ritor1
parents:
diff changeset
1043 }
Ritor1
parents:
diff changeset
1044
Ritor1
parents:
diff changeset
1045 break;
Ritor1
parents:
diff changeset
1046 }
Ritor1
parents:
diff changeset
1047
Ritor1
parents:
diff changeset
1048 case 2:
Ritor1
parents:
diff changeset
1049 {
Ritor1
parents:
diff changeset
1050 int i;
Ritor1
parents:
diff changeset
1051
Ritor1
parents:
diff changeset
1052 for (i = 0; i < 4 && png_ptr->pass == 2; i++)
Ritor1
parents:
diff changeset
1053 {
Ritor1
parents:
diff changeset
1054 png_push_have_row(png_ptr, png_ptr->row_buf + 1);
Ritor1
parents:
diff changeset
1055 png_read_push_finish_row(png_ptr);
Ritor1
parents:
diff changeset
1056 }
Ritor1
parents:
diff changeset
1057
Ritor1
parents:
diff changeset
1058 for (i = 0; i < 4 && png_ptr->pass == 2; i++)
Ritor1
parents:
diff changeset
1059 {
Ritor1
parents:
diff changeset
1060 png_push_have_row(png_ptr, NULL);
Ritor1
parents:
diff changeset
1061 png_read_push_finish_row(png_ptr);
Ritor1
parents:
diff changeset
1062 }
Ritor1
parents:
diff changeset
1063
Ritor1
parents:
diff changeset
1064 if (png_ptr->pass == 4) /* Pass 3 might be empty */
Ritor1
parents:
diff changeset
1065 {
Ritor1
parents:
diff changeset
1066 for (i = 0; i < 2 && png_ptr->pass == 4; i++)
Ritor1
parents:
diff changeset
1067 {
Ritor1
parents:
diff changeset
1068 png_push_have_row(png_ptr, NULL);
Ritor1
parents:
diff changeset
1069 png_read_push_finish_row(png_ptr);
Ritor1
parents:
diff changeset
1070 }
Ritor1
parents:
diff changeset
1071 }
Ritor1
parents:
diff changeset
1072
Ritor1
parents:
diff changeset
1073 break;
Ritor1
parents:
diff changeset
1074 }
Ritor1
parents:
diff changeset
1075
Ritor1
parents:
diff changeset
1076 case 3:
Ritor1
parents:
diff changeset
1077 {
Ritor1
parents:
diff changeset
1078 int i;
Ritor1
parents:
diff changeset
1079
Ritor1
parents:
diff changeset
1080 for (i = 0; i < 4 && png_ptr->pass == 3; i++)
Ritor1
parents:
diff changeset
1081 {
Ritor1
parents:
diff changeset
1082 png_push_have_row(png_ptr, png_ptr->row_buf + 1);
Ritor1
parents:
diff changeset
1083 png_read_push_finish_row(png_ptr);
Ritor1
parents:
diff changeset
1084 }
Ritor1
parents:
diff changeset
1085
Ritor1
parents:
diff changeset
1086 if (png_ptr->pass == 4) /* Skip top two generated rows */
Ritor1
parents:
diff changeset
1087 {
Ritor1
parents:
diff changeset
1088 for (i = 0; i < 2 && png_ptr->pass == 4; i++)
Ritor1
parents:
diff changeset
1089 {
Ritor1
parents:
diff changeset
1090 png_push_have_row(png_ptr, NULL);
Ritor1
parents:
diff changeset
1091 png_read_push_finish_row(png_ptr);
Ritor1
parents:
diff changeset
1092 }
Ritor1
parents:
diff changeset
1093 }
Ritor1
parents:
diff changeset
1094
Ritor1
parents:
diff changeset
1095 break;
Ritor1
parents:
diff changeset
1096 }
Ritor1
parents:
diff changeset
1097
Ritor1
parents:
diff changeset
1098 case 4:
Ritor1
parents:
diff changeset
1099 {
Ritor1
parents:
diff changeset
1100 int i;
Ritor1
parents:
diff changeset
1101
Ritor1
parents:
diff changeset
1102 for (i = 0; i < 2 && png_ptr->pass == 4; i++)
Ritor1
parents:
diff changeset
1103 {
Ritor1
parents:
diff changeset
1104 png_push_have_row(png_ptr, png_ptr->row_buf + 1);
Ritor1
parents:
diff changeset
1105 png_read_push_finish_row(png_ptr);
Ritor1
parents:
diff changeset
1106 }
Ritor1
parents:
diff changeset
1107
Ritor1
parents:
diff changeset
1108 for (i = 0; i < 2 && png_ptr->pass == 4; i++)
Ritor1
parents:
diff changeset
1109 {
Ritor1
parents:
diff changeset
1110 png_push_have_row(png_ptr, NULL);
Ritor1
parents:
diff changeset
1111 png_read_push_finish_row(png_ptr);
Ritor1
parents:
diff changeset
1112 }
Ritor1
parents:
diff changeset
1113
Ritor1
parents:
diff changeset
1114 if (png_ptr->pass == 6) /* Pass 5 might be empty */
Ritor1
parents:
diff changeset
1115 {
Ritor1
parents:
diff changeset
1116 png_push_have_row(png_ptr, NULL);
Ritor1
parents:
diff changeset
1117 png_read_push_finish_row(png_ptr);
Ritor1
parents:
diff changeset
1118 }
Ritor1
parents:
diff changeset
1119
Ritor1
parents:
diff changeset
1120 break;
Ritor1
parents:
diff changeset
1121 }
Ritor1
parents:
diff changeset
1122
Ritor1
parents:
diff changeset
1123 case 5:
Ritor1
parents:
diff changeset
1124 {
Ritor1
parents:
diff changeset
1125 int i;
Ritor1
parents:
diff changeset
1126
Ritor1
parents:
diff changeset
1127 for (i = 0; i < 2 && png_ptr->pass == 5; i++)
Ritor1
parents:
diff changeset
1128 {
Ritor1
parents:
diff changeset
1129 png_push_have_row(png_ptr, png_ptr->row_buf + 1);
Ritor1
parents:
diff changeset
1130 png_read_push_finish_row(png_ptr);
Ritor1
parents:
diff changeset
1131 }
Ritor1
parents:
diff changeset
1132
Ritor1
parents:
diff changeset
1133 if (png_ptr->pass == 6) /* Skip top generated row */
Ritor1
parents:
diff changeset
1134 {
Ritor1
parents:
diff changeset
1135 png_push_have_row(png_ptr, NULL);
Ritor1
parents:
diff changeset
1136 png_read_push_finish_row(png_ptr);
Ritor1
parents:
diff changeset
1137 }
Ritor1
parents:
diff changeset
1138
Ritor1
parents:
diff changeset
1139 break;
Ritor1
parents:
diff changeset
1140 }
Ritor1
parents:
diff changeset
1141
Ritor1
parents:
diff changeset
1142 default:
Ritor1
parents:
diff changeset
1143 case 6:
Ritor1
parents:
diff changeset
1144 {
Ritor1
parents:
diff changeset
1145 png_push_have_row(png_ptr, png_ptr->row_buf + 1);
Ritor1
parents:
diff changeset
1146 png_read_push_finish_row(png_ptr);
Ritor1
parents:
diff changeset
1147
Ritor1
parents:
diff changeset
1148 if (png_ptr->pass != 6)
Ritor1
parents:
diff changeset
1149 break;
Ritor1
parents:
diff changeset
1150
Ritor1
parents:
diff changeset
1151 png_push_have_row(png_ptr, NULL);
Ritor1
parents:
diff changeset
1152 png_read_push_finish_row(png_ptr);
Ritor1
parents:
diff changeset
1153 }
Ritor1
parents:
diff changeset
1154 }
Ritor1
parents:
diff changeset
1155 }
Ritor1
parents:
diff changeset
1156 else
Ritor1
parents:
diff changeset
1157 #endif
Ritor1
parents:
diff changeset
1158 {
Ritor1
parents:
diff changeset
1159 png_push_have_row(png_ptr, png_ptr->row_buf + 1);
Ritor1
parents:
diff changeset
1160 png_read_push_finish_row(png_ptr);
Ritor1
parents:
diff changeset
1161 }
Ritor1
parents:
diff changeset
1162 }
Ritor1
parents:
diff changeset
1163
Ritor1
parents:
diff changeset
1164 void /* PRIVATE */
Ritor1
parents:
diff changeset
1165 png_read_push_finish_row(png_structrp png_ptr)
Ritor1
parents:
diff changeset
1166 {
Ritor1
parents:
diff changeset
1167 #ifdef PNG_READ_INTERLACING_SUPPORTED
Ritor1
parents:
diff changeset
1168 /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
Ritor1
parents:
diff changeset
1169
Ritor1
parents:
diff changeset
1170 /* Start of interlace block */
Ritor1
parents:
diff changeset
1171 static PNG_CONST png_byte png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
Ritor1
parents:
diff changeset
1172
Ritor1
parents:
diff changeset
1173 /* Offset to next interlace block */
Ritor1
parents:
diff changeset
1174 static PNG_CONST png_byte png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
Ritor1
parents:
diff changeset
1175
Ritor1
parents:
diff changeset
1176 /* Start of interlace block in the y direction */
Ritor1
parents:
diff changeset
1177 static PNG_CONST png_byte png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
Ritor1
parents:
diff changeset
1178
Ritor1
parents:
diff changeset
1179 /* Offset to next interlace block in the y direction */
Ritor1
parents:
diff changeset
1180 static PNG_CONST png_byte png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
Ritor1
parents:
diff changeset
1181
Ritor1
parents:
diff changeset
1182 /* Height of interlace block. This is not currently used - if you need
Ritor1
parents:
diff changeset
1183 * it, uncomment it here and in png.h
Ritor1
parents:
diff changeset
1184 static PNG_CONST png_byte png_pass_height[] = {8, 8, 4, 4, 2, 2, 1};
Ritor1
parents:
diff changeset
1185 */
Ritor1
parents:
diff changeset
1186 #endif
Ritor1
parents:
diff changeset
1187
Ritor1
parents:
diff changeset
1188 png_ptr->row_number++;
Ritor1
parents:
diff changeset
1189 if (png_ptr->row_number < png_ptr->num_rows)
Ritor1
parents:
diff changeset
1190 return;
Ritor1
parents:
diff changeset
1191
Ritor1
parents:
diff changeset
1192 #ifdef PNG_READ_INTERLACING_SUPPORTED
Ritor1
parents:
diff changeset
1193 if (png_ptr->interlaced)
Ritor1
parents:
diff changeset
1194 {
Ritor1
parents:
diff changeset
1195 png_ptr->row_number = 0;
Ritor1
parents:
diff changeset
1196 memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
Ritor1
parents:
diff changeset
1197
Ritor1
parents:
diff changeset
1198 do
Ritor1
parents:
diff changeset
1199 {
Ritor1
parents:
diff changeset
1200 png_ptr->pass++;
Ritor1
parents:
diff changeset
1201 if ((png_ptr->pass == 1 && png_ptr->width < 5) ||
Ritor1
parents:
diff changeset
1202 (png_ptr->pass == 3 && png_ptr->width < 3) ||
Ritor1
parents:
diff changeset
1203 (png_ptr->pass == 5 && png_ptr->width < 2))
Ritor1
parents:
diff changeset
1204 png_ptr->pass++;
Ritor1
parents:
diff changeset
1205
Ritor1
parents:
diff changeset
1206 if (png_ptr->pass > 7)
Ritor1
parents:
diff changeset
1207 png_ptr->pass--;
Ritor1
parents:
diff changeset
1208
Ritor1
parents:
diff changeset
1209 if (png_ptr->pass >= 7)
Ritor1
parents:
diff changeset
1210 break;
Ritor1
parents:
diff changeset
1211
Ritor1
parents:
diff changeset
1212 png_ptr->iwidth = (png_ptr->width +
Ritor1
parents:
diff changeset
1213 png_pass_inc[png_ptr->pass] - 1 -
Ritor1
parents:
diff changeset
1214 png_pass_start[png_ptr->pass]) /
Ritor1
parents:
diff changeset
1215 png_pass_inc[png_ptr->pass];
Ritor1
parents:
diff changeset
1216
Ritor1
parents:
diff changeset
1217 if (png_ptr->transformations & PNG_INTERLACE)
Ritor1
parents:
diff changeset
1218 break;
Ritor1
parents:
diff changeset
1219
Ritor1
parents:
diff changeset
1220 png_ptr->num_rows = (png_ptr->height +
Ritor1
parents:
diff changeset
1221 png_pass_yinc[png_ptr->pass] - 1 -
Ritor1
parents:
diff changeset
1222 png_pass_ystart[png_ptr->pass]) /
Ritor1
parents:
diff changeset
1223 png_pass_yinc[png_ptr->pass];
Ritor1
parents:
diff changeset
1224
Ritor1
parents:
diff changeset
1225 } while (png_ptr->iwidth == 0 || png_ptr->num_rows == 0);
Ritor1
parents:
diff changeset
1226 }
Ritor1
parents:
diff changeset
1227 #endif /* PNG_READ_INTERLACING_SUPPORTED */
Ritor1
parents:
diff changeset
1228 }
Ritor1
parents:
diff changeset
1229
Ritor1
parents:
diff changeset
1230 void /* PRIVATE */
Ritor1
parents:
diff changeset
1231 png_push_have_info(png_structrp png_ptr, png_inforp info_ptr)
Ritor1
parents:
diff changeset
1232 {
Ritor1
parents:
diff changeset
1233 if (png_ptr->info_fn != NULL)
Ritor1
parents:
diff changeset
1234 (*(png_ptr->info_fn))(png_ptr, info_ptr);
Ritor1
parents:
diff changeset
1235 }
Ritor1
parents:
diff changeset
1236
Ritor1
parents:
diff changeset
1237 void /* PRIVATE */
Ritor1
parents:
diff changeset
1238 png_push_have_end(png_structrp png_ptr, png_inforp info_ptr)
Ritor1
parents:
diff changeset
1239 {
Ritor1
parents:
diff changeset
1240 if (png_ptr->end_fn != NULL)
Ritor1
parents:
diff changeset
1241 (*(png_ptr->end_fn))(png_ptr, info_ptr);
Ritor1
parents:
diff changeset
1242 }
Ritor1
parents:
diff changeset
1243
Ritor1
parents:
diff changeset
1244 void /* PRIVATE */
Ritor1
parents:
diff changeset
1245 png_push_have_row(png_structrp png_ptr, png_bytep row)
Ritor1
parents:
diff changeset
1246 {
Ritor1
parents:
diff changeset
1247 if (png_ptr->row_fn != NULL)
Ritor1
parents:
diff changeset
1248 (*(png_ptr->row_fn))(png_ptr, row, png_ptr->row_number,
Ritor1
parents:
diff changeset
1249 (int)png_ptr->pass);
Ritor1
parents:
diff changeset
1250 }
Ritor1
parents:
diff changeset
1251
Ritor1
parents:
diff changeset
1252 #ifdef PNG_READ_INTERLACING_SUPPORTED
Ritor1
parents:
diff changeset
1253 void PNGAPI
Ritor1
parents:
diff changeset
1254 png_progressive_combine_row(png_const_structrp png_ptr, png_bytep old_row,
Ritor1
parents:
diff changeset
1255 png_const_bytep new_row)
Ritor1
parents:
diff changeset
1256 {
Ritor1
parents:
diff changeset
1257 if (png_ptr == NULL)
Ritor1
parents:
diff changeset
1258 return;
Ritor1
parents:
diff changeset
1259
Ritor1
parents:
diff changeset
1260 /* new_row is a flag here - if it is NULL then the app callback was called
Ritor1
parents:
diff changeset
1261 * from an empty row (see the calls to png_struct::row_fn below), otherwise
Ritor1
parents:
diff changeset
1262 * it must be png_ptr->row_buf+1
Ritor1
parents:
diff changeset
1263 */
Ritor1
parents:
diff changeset
1264 if (new_row != NULL)
Ritor1
parents:
diff changeset
1265 png_combine_row(png_ptr, old_row, 1/*display*/);
Ritor1
parents:
diff changeset
1266 }
Ritor1
parents:
diff changeset
1267 #endif /* PNG_READ_INTERLACING_SUPPORTED */
Ritor1
parents:
diff changeset
1268
Ritor1
parents:
diff changeset
1269 void PNGAPI
Ritor1
parents:
diff changeset
1270 png_set_progressive_read_fn(png_structrp png_ptr, png_voidp progressive_ptr,
Ritor1
parents:
diff changeset
1271 png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
Ritor1
parents:
diff changeset
1272 png_progressive_end_ptr end_fn)
Ritor1
parents:
diff changeset
1273 {
Ritor1
parents:
diff changeset
1274 if (png_ptr == NULL)
Ritor1
parents:
diff changeset
1275 return;
Ritor1
parents:
diff changeset
1276
Ritor1
parents:
diff changeset
1277 png_ptr->info_fn = info_fn;
Ritor1
parents:
diff changeset
1278 png_ptr->row_fn = row_fn;
Ritor1
parents:
diff changeset
1279 png_ptr->end_fn = end_fn;
Ritor1
parents:
diff changeset
1280
Ritor1
parents:
diff changeset
1281 png_set_read_fn(png_ptr, progressive_ptr, png_push_fill_buffer);
Ritor1
parents:
diff changeset
1282 }
Ritor1
parents:
diff changeset
1283
Ritor1
parents:
diff changeset
1284 png_voidp PNGAPI
Ritor1
parents:
diff changeset
1285 png_get_progressive_ptr(png_const_structrp png_ptr)
Ritor1
parents:
diff changeset
1286 {
Ritor1
parents:
diff changeset
1287 if (png_ptr == NULL)
Ritor1
parents:
diff changeset
1288 return (NULL);
Ritor1
parents:
diff changeset
1289
Ritor1
parents:
diff changeset
1290 return png_ptr->io_ptr;
Ritor1
parents:
diff changeset
1291 }
Ritor1
parents:
diff changeset
1292 #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */