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