author | prr |
Sat, 09 Dec 2017 11:40:40 -0800 | |
changeset 48280 | 791d551bcdb8 |
parent 47216 | 71c04702a3d5 |
child 51304 | 66d9993dd4ad |
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 |
* |
|
48280 | 32 |
* Last changed in libpng 1.6.32 [August 24, 2017] |
33 |
* Copyright (c) 1998-2002,2004,2006-2017 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); |
48280 | 220 |
png_check_chunk_length(png_ptr, png_ptr->push_length); |
2 | 221 |
png_ptr->mode |= PNG_HAVE_CHUNK_HEADER; |
222 |
} |
|
223 |
||
29913 | 224 |
chunk_name = png_ptr->chunk_name; |
225 |
||
226 |
if (chunk_name == png_IDAT) |
|
227 |
{ |
|
228 |
if ((png_ptr->mode & PNG_AFTER_IDAT) != 0) |
|
10576 | 229 |
png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT; |
2 | 230 |
|
29913 | 231 |
/* If we reach an IDAT chunk, this means we have read all of the |
232 |
* header chunks, and we can start reading the image (or if this |
|
233 |
* is called after the image has been read - we have an error). |
|
234 |
*/ |
|
235 |
if ((png_ptr->mode & PNG_HAVE_IHDR) == 0) |
|
236 |
png_error(png_ptr, "Missing IHDR before IDAT"); |
|
237 |
||
238 |
else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE && |
|
239 |
(png_ptr->mode & PNG_HAVE_PLTE) == 0) |
|
240 |
png_error(png_ptr, "Missing PLTE before IDAT"); |
|
241 |
||
242 |
png_ptr->process_mode = PNG_READ_IDAT_MODE; |
|
243 |
||
40436
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
244 |
if ((png_ptr->mode & PNG_HAVE_IDAT) != 0) |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
245 |
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
|
246 |
if (png_ptr->push_length == 0) |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
247 |
return; |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
248 |
|
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
249 |
png_ptr->mode |= PNG_HAVE_IDAT; |
29913 | 250 |
|
251 |
if ((png_ptr->mode & PNG_AFTER_IDAT) != 0) |
|
252 |
png_benign_error(png_ptr, "Too many IDATs found"); |
|
253 |
} |
|
254 |
||
255 |
if (chunk_name == png_IHDR) |
|
2 | 256 |
{ |
10576 | 257 |
if (png_ptr->push_length != 13) |
258 |
png_error(png_ptr, "Invalid IHDR length"); |
|
259 |
||
29913 | 260 |
PNG_PUSH_SAVE_BUFFER_IF_FULL |
2 | 261 |
png_handle_IHDR(png_ptr, info_ptr, png_ptr->push_length); |
262 |
} |
|
10576 | 263 |
|
29913 | 264 |
else if (chunk_name == png_IEND) |
2 | 265 |
{ |
29913 | 266 |
PNG_PUSH_SAVE_BUFFER_IF_FULL |
2 | 267 |
png_handle_IEND(png_ptr, info_ptr, png_ptr->push_length); |
268 |
||
269 |
png_ptr->process_mode = PNG_READ_DONE_MODE; |
|
270 |
png_push_have_end(png_ptr, info_ptr); |
|
271 |
} |
|
10576 | 272 |
|
2 | 273 |
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED |
29913 | 274 |
else if ((keep = png_chunk_unknown_handling(png_ptr, chunk_name)) != 0) |
2 | 275 |
{ |
29913 | 276 |
PNG_PUSH_SAVE_BUFFER_IF_FULL |
277 |
png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length, keep); |
|
10576 | 278 |
|
29913 | 279 |
if (chunk_name == png_PLTE) |
280 |
png_ptr->mode |= PNG_HAVE_PLTE; |
|
2 | 281 |
} |
29913 | 282 |
#endif |
10576 | 283 |
|
29913 | 284 |
else if (chunk_name == png_PLTE) |
2 | 285 |
{ |
29913 | 286 |
PNG_PUSH_SAVE_BUFFER_IF_FULL |
2 | 287 |
png_handle_PLTE(png_ptr, info_ptr, png_ptr->push_length); |
288 |
} |
|
10576 | 289 |
|
29913 | 290 |
else if (chunk_name == png_IDAT) |
2 | 291 |
{ |
292 |
png_ptr->idat_size = png_ptr->push_length; |
|
293 |
png_ptr->process_mode = PNG_READ_IDAT_MODE; |
|
294 |
png_push_have_info(png_ptr, info_ptr); |
|
10576 | 295 |
png_ptr->zstream.avail_out = |
296 |
(uInt) PNG_ROWBYTES(png_ptr->pixel_depth, |
|
297 |
png_ptr->iwidth) + 1; |
|
2 | 298 |
png_ptr->zstream.next_out = png_ptr->row_buf; |
299 |
return; |
|
300 |
} |
|
10576 | 301 |
|
302 |
#ifdef PNG_READ_gAMA_SUPPORTED |
|
29913 | 303 |
else if (png_ptr->chunk_name == png_gAMA) |
2 | 304 |
{ |
29913 | 305 |
PNG_PUSH_SAVE_BUFFER_IF_FULL |
2 | 306 |
png_handle_gAMA(png_ptr, info_ptr, png_ptr->push_length); |
307 |
} |
|
10576 | 308 |
|
2 | 309 |
#endif |
10576 | 310 |
#ifdef PNG_READ_sBIT_SUPPORTED |
29913 | 311 |
else if (png_ptr->chunk_name == png_sBIT) |
2 | 312 |
{ |
29913 | 313 |
PNG_PUSH_SAVE_BUFFER_IF_FULL |
2 | 314 |
png_handle_sBIT(png_ptr, info_ptr, png_ptr->push_length); |
315 |
} |
|
10576 | 316 |
|
2 | 317 |
#endif |
10576 | 318 |
#ifdef PNG_READ_cHRM_SUPPORTED |
29913 | 319 |
else if (png_ptr->chunk_name == png_cHRM) |
2 | 320 |
{ |
29913 | 321 |
PNG_PUSH_SAVE_BUFFER_IF_FULL |
2 | 322 |
png_handle_cHRM(png_ptr, info_ptr, png_ptr->push_length); |
323 |
} |
|
10576 | 324 |
|
2 | 325 |
#endif |
10576 | 326 |
#ifdef PNG_READ_sRGB_SUPPORTED |
29913 | 327 |
else if (chunk_name == png_sRGB) |
2 | 328 |
{ |
29913 | 329 |
PNG_PUSH_SAVE_BUFFER_IF_FULL |
2 | 330 |
png_handle_sRGB(png_ptr, info_ptr, png_ptr->push_length); |
331 |
} |
|
10576 | 332 |
|
2 | 333 |
#endif |
10576 | 334 |
#ifdef PNG_READ_iCCP_SUPPORTED |
29913 | 335 |
else if (png_ptr->chunk_name == png_iCCP) |
2 | 336 |
{ |
29913 | 337 |
PNG_PUSH_SAVE_BUFFER_IF_FULL |
2 | 338 |
png_handle_iCCP(png_ptr, info_ptr, png_ptr->push_length); |
339 |
} |
|
10576 | 340 |
|
2 | 341 |
#endif |
10576 | 342 |
#ifdef PNG_READ_sPLT_SUPPORTED |
29913 | 343 |
else if (chunk_name == png_sPLT) |
2 | 344 |
{ |
29913 | 345 |
PNG_PUSH_SAVE_BUFFER_IF_FULL |
2 | 346 |
png_handle_sPLT(png_ptr, info_ptr, png_ptr->push_length); |
347 |
} |
|
10576 | 348 |
|
2 | 349 |
#endif |
10576 | 350 |
#ifdef PNG_READ_tRNS_SUPPORTED |
29913 | 351 |
else if (chunk_name == png_tRNS) |
2 | 352 |
{ |
29913 | 353 |
PNG_PUSH_SAVE_BUFFER_IF_FULL |
2 | 354 |
png_handle_tRNS(png_ptr, info_ptr, png_ptr->push_length); |
355 |
} |
|
10576 | 356 |
|
2 | 357 |
#endif |
10576 | 358 |
#ifdef PNG_READ_bKGD_SUPPORTED |
29913 | 359 |
else if (chunk_name == png_bKGD) |
2 | 360 |
{ |
29913 | 361 |
PNG_PUSH_SAVE_BUFFER_IF_FULL |
2 | 362 |
png_handle_bKGD(png_ptr, info_ptr, png_ptr->push_length); |
363 |
} |
|
10576 | 364 |
|
2 | 365 |
#endif |
10576 | 366 |
#ifdef PNG_READ_hIST_SUPPORTED |
29913 | 367 |
else if (chunk_name == png_hIST) |
2 | 368 |
{ |
29913 | 369 |
PNG_PUSH_SAVE_BUFFER_IF_FULL |
2 | 370 |
png_handle_hIST(png_ptr, info_ptr, png_ptr->push_length); |
371 |
} |
|
10576 | 372 |
|
2 | 373 |
#endif |
10576 | 374 |
#ifdef PNG_READ_pHYs_SUPPORTED |
29913 | 375 |
else if (chunk_name == png_pHYs) |
2 | 376 |
{ |
29913 | 377 |
PNG_PUSH_SAVE_BUFFER_IF_FULL |
2 | 378 |
png_handle_pHYs(png_ptr, info_ptr, png_ptr->push_length); |
379 |
} |
|
10576 | 380 |
|
2 | 381 |
#endif |
10576 | 382 |
#ifdef PNG_READ_oFFs_SUPPORTED |
29913 | 383 |
else if (chunk_name == png_oFFs) |
2 | 384 |
{ |
29913 | 385 |
PNG_PUSH_SAVE_BUFFER_IF_FULL |
2 | 386 |
png_handle_oFFs(png_ptr, info_ptr, png_ptr->push_length); |
387 |
} |
|
388 |
#endif |
|
10576 | 389 |
|
390 |
#ifdef PNG_READ_pCAL_SUPPORTED |
|
29913 | 391 |
else if (chunk_name == png_pCAL) |
2 | 392 |
{ |
29913 | 393 |
PNG_PUSH_SAVE_BUFFER_IF_FULL |
2 | 394 |
png_handle_pCAL(png_ptr, info_ptr, png_ptr->push_length); |
395 |
} |
|
10576 | 396 |
|
2 | 397 |
#endif |
10576 | 398 |
#ifdef PNG_READ_sCAL_SUPPORTED |
29913 | 399 |
else if (chunk_name == png_sCAL) |
2 | 400 |
{ |
29913 | 401 |
PNG_PUSH_SAVE_BUFFER_IF_FULL |
2 | 402 |
png_handle_sCAL(png_ptr, info_ptr, png_ptr->push_length); |
403 |
} |
|
10576 | 404 |
|
2 | 405 |
#endif |
10576 | 406 |
#ifdef PNG_READ_tIME_SUPPORTED |
29913 | 407 |
else if (chunk_name == png_tIME) |
2 | 408 |
{ |
29913 | 409 |
PNG_PUSH_SAVE_BUFFER_IF_FULL |
2 | 410 |
png_handle_tIME(png_ptr, info_ptr, png_ptr->push_length); |
411 |
} |
|
10576 | 412 |
|
2 | 413 |
#endif |
10576 | 414 |
#ifdef PNG_READ_tEXt_SUPPORTED |
29913 | 415 |
else if (chunk_name == png_tEXt) |
2 | 416 |
{ |
29913 | 417 |
PNG_PUSH_SAVE_BUFFER_IF_FULL |
418 |
png_handle_tEXt(png_ptr, info_ptr, png_ptr->push_length); |
|
2 | 419 |
} |
10576 | 420 |
|
2 | 421 |
#endif |
10576 | 422 |
#ifdef PNG_READ_zTXt_SUPPORTED |
29913 | 423 |
else if (chunk_name == png_zTXt) |
2 | 424 |
{ |
29913 | 425 |
PNG_PUSH_SAVE_BUFFER_IF_FULL |
426 |
png_handle_zTXt(png_ptr, info_ptr, png_ptr->push_length); |
|
2 | 427 |
} |
10576 | 428 |
|
2 | 429 |
#endif |
10576 | 430 |
#ifdef PNG_READ_iTXt_SUPPORTED |
29913 | 431 |
else if (chunk_name == png_iTXt) |
2 | 432 |
{ |
29913 | 433 |
PNG_PUSH_SAVE_BUFFER_IF_FULL |
434 |
png_handle_iTXt(png_ptr, info_ptr, png_ptr->push_length); |
|
435 |
} |
|
436 |
#endif |
|
10576 | 437 |
|
2 | 438 |
else |
439 |
{ |
|
29913 | 440 |
PNG_PUSH_SAVE_BUFFER_IF_FULL |
441 |
png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length, |
|
43321 | 442 |
PNG_HANDLE_CHUNK_AS_DEFAULT); |
2 | 443 |
} |
444 |
||
445 |
png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER; |
|
446 |
} |
|
447 |
||
10576 | 448 |
void PNGCBAPI |
2 | 449 |
png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length) |
450 |
{ |
|
451 |
png_bytep ptr; |
|
452 |
||
10576 | 453 |
if (png_ptr == NULL) |
454 |
return; |
|
455 |
||
2 | 456 |
ptr = buffer; |
29913 | 457 |
if (png_ptr->save_buffer_size != 0) |
2 | 458 |
{ |
459 |
png_size_t save_size; |
|
460 |
||
461 |
if (length < png_ptr->save_buffer_size) |
|
462 |
save_size = length; |
|
10576 | 463 |
|
2 | 464 |
else |
465 |
save_size = png_ptr->save_buffer_size; |
|
466 |
||
29913 | 467 |
memcpy(ptr, png_ptr->save_buffer_ptr, save_size); |
2 | 468 |
length -= save_size; |
469 |
ptr += save_size; |
|
470 |
png_ptr->buffer_size -= save_size; |
|
471 |
png_ptr->save_buffer_size -= save_size; |
|
472 |
png_ptr->save_buffer_ptr += save_size; |
|
473 |
} |
|
29913 | 474 |
if (length != 0 && png_ptr->current_buffer_size != 0) |
2 | 475 |
{ |
476 |
png_size_t save_size; |
|
477 |
||
478 |
if (length < png_ptr->current_buffer_size) |
|
479 |
save_size = length; |
|
10576 | 480 |
|
2 | 481 |
else |
482 |
save_size = png_ptr->current_buffer_size; |
|
483 |
||
29913 | 484 |
memcpy(ptr, png_ptr->current_buffer_ptr, save_size); |
2 | 485 |
png_ptr->buffer_size -= save_size; |
486 |
png_ptr->current_buffer_size -= save_size; |
|
487 |
png_ptr->current_buffer_ptr += save_size; |
|
488 |
} |
|
489 |
} |
|
490 |
||
491 |
void /* PRIVATE */ |
|
29913 | 492 |
png_push_save_buffer(png_structrp png_ptr) |
2 | 493 |
{ |
29913 | 494 |
if (png_ptr->save_buffer_size != 0) |
2 | 495 |
{ |
496 |
if (png_ptr->save_buffer_ptr != png_ptr->save_buffer) |
|
497 |
{ |
|
10576 | 498 |
png_size_t i, istop; |
2 | 499 |
png_bytep sp; |
500 |
png_bytep dp; |
|
501 |
||
502 |
istop = png_ptr->save_buffer_size; |
|
503 |
for (i = 0, sp = png_ptr->save_buffer_ptr, dp = png_ptr->save_buffer; |
|
10576 | 504 |
i < istop; i++, sp++, dp++) |
2 | 505 |
{ |
506 |
*dp = *sp; |
|
507 |
} |
|
508 |
} |
|
509 |
} |
|
510 |
if (png_ptr->save_buffer_size + png_ptr->current_buffer_size > |
|
10576 | 511 |
png_ptr->save_buffer_max) |
2 | 512 |
{ |
513 |
png_size_t new_max; |
|
514 |
png_bytep old_buffer; |
|
515 |
||
516 |
if (png_ptr->save_buffer_size > PNG_SIZE_MAX - |
|
10576 | 517 |
(png_ptr->current_buffer_size + 256)) |
2 | 518 |
{ |
10576 | 519 |
png_error(png_ptr, "Potential overflow of save_buffer"); |
2 | 520 |
} |
10576 | 521 |
|
2 | 522 |
new_max = png_ptr->save_buffer_size + png_ptr->current_buffer_size + 256; |
523 |
old_buffer = png_ptr->save_buffer; |
|
10576 | 524 |
png_ptr->save_buffer = (png_bytep)png_malloc_warn(png_ptr, |
525 |
(png_size_t)new_max); |
|
526 |
||
527 |
if (png_ptr->save_buffer == NULL) |
|
528 |
{ |
|
529 |
png_free(png_ptr, old_buffer); |
|
530 |
png_error(png_ptr, "Insufficient memory for save_buffer"); |
|
531 |
} |
|
532 |
||
40436
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
533 |
if (old_buffer) |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
534 |
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
|
535 |
else if (png_ptr->save_buffer_size) |
94ae0ede53a5
8155690: Update libPNG library to the latest up-to-date
azvegint
parents:
35296
diff
changeset
|
536 |
png_error(png_ptr, "save_buffer error"); |
2 | 537 |
png_free(png_ptr, old_buffer); |
538 |
png_ptr->save_buffer_max = new_max; |
|
539 |
} |
|
540 |
if (png_ptr->current_buffer_size) |
|
541 |
{ |
|
29913 | 542 |
memcpy(png_ptr->save_buffer + png_ptr->save_buffer_size, |
2 | 543 |
png_ptr->current_buffer_ptr, png_ptr->current_buffer_size); |
544 |
png_ptr->save_buffer_size += png_ptr->current_buffer_size; |
|
545 |
png_ptr->current_buffer_size = 0; |
|
546 |
} |
|
547 |
png_ptr->save_buffer_ptr = png_ptr->save_buffer; |
|
548 |
png_ptr->buffer_size = 0; |
|
549 |
} |
|
550 |
||
551 |
void /* PRIVATE */ |
|
29913 | 552 |
png_push_restore_buffer(png_structrp png_ptr, png_bytep buffer, |
43321 | 553 |
png_size_t buffer_length) |
2 | 554 |
{ |
555 |
png_ptr->current_buffer = buffer; |
|
556 |
png_ptr->current_buffer_size = buffer_length; |
|
557 |
png_ptr->buffer_size = buffer_length + png_ptr->save_buffer_size; |
|
558 |
png_ptr->current_buffer_ptr = png_ptr->current_buffer; |
|
559 |
} |
|
560 |
||
561 |
void /* PRIVATE */ |
|
29913 | 562 |
png_push_read_IDAT(png_structrp png_ptr) |
2 | 563 |
{ |
29913 | 564 |
if ((png_ptr->mode & PNG_HAVE_CHUNK_HEADER) == 0) |
2 | 565 |
{ |
566 |
png_byte chunk_length[4]; |
|
29913 | 567 |
png_byte chunk_tag[4]; |
2 | 568 |
|
29913 | 569 |
/* TODO: this code can be commoned up with the same code in push_read */ |
570 |
PNG_PUSH_SAVE_BUFFER_IF_LT(8) |
|
2 | 571 |
png_push_fill_buffer(png_ptr, chunk_length, 4); |
10576 | 572 |
png_ptr->push_length = png_get_uint_31(png_ptr, chunk_length); |
2 | 573 |
png_reset_crc(png_ptr); |
29913 | 574 |
png_crc_read(png_ptr, chunk_tag, 4); |
575 |
png_ptr->chunk_name = PNG_CHUNK_FROM_STRING(chunk_tag); |
|
2 | 576 |
png_ptr->mode |= PNG_HAVE_CHUNK_HEADER; |
577 |
||
29913 | 578 |
if (png_ptr->chunk_name != png_IDAT) |
2 | 579 |
{ |
580 |
png_ptr->process_mode = PNG_READ_CHUNK_MODE; |
|
10576 | 581 |
|
29913 | 582 |
if ((png_ptr->flags & PNG_FLAG_ZSTREAM_ENDED) == 0) |
2 | 583 |
png_error(png_ptr, "Not enough compressed data"); |
10576 | 584 |
|
2 | 585 |
return; |
586 |
} |
|
587 |
||
588 |
png_ptr->idat_size = png_ptr->push_length; |
|
589 |
} |
|
29913 | 590 |
|
591 |
if (png_ptr->idat_size != 0 && png_ptr->save_buffer_size != 0) |
|
2 | 592 |
{ |
10576 | 593 |
png_size_t save_size = png_ptr->save_buffer_size; |
594 |
png_uint_32 idat_size = png_ptr->idat_size; |
|
2 | 595 |
|
10576 | 596 |
/* We want the smaller of 'idat_size' and 'current_buffer_size', but they |
597 |
* are of different types and we don't know which variable has the fewest |
|
598 |
* bits. Carefully select the smaller and cast it to the type of the |
|
599 |
* larger - this cannot overflow. Do not cast in the following test - it |
|
35296 | 600 |
* will break on either 16-bit or 64-bit platforms. |
10576 | 601 |
*/ |
602 |
if (idat_size < save_size) |
|
603 |
save_size = (png_size_t)idat_size; |
|
604 |
||
2 | 605 |
else |
10576 | 606 |
idat_size = (png_uint_32)save_size; |
2 | 607 |
|
608 |
png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size); |
|
10576 | 609 |
|
610 |
png_process_IDAT_data(png_ptr, png_ptr->save_buffer_ptr, save_size); |
|
611 |
||
612 |
png_ptr->idat_size -= idat_size; |
|
2 | 613 |
png_ptr->buffer_size -= save_size; |
614 |
png_ptr->save_buffer_size -= save_size; |
|
615 |
png_ptr->save_buffer_ptr += save_size; |
|
616 |
} |
|
10576 | 617 |
|
29913 | 618 |
if (png_ptr->idat_size != 0 && png_ptr->current_buffer_size != 0) |
2 | 619 |
{ |
10576 | 620 |
png_size_t save_size = png_ptr->current_buffer_size; |
621 |
png_uint_32 idat_size = png_ptr->idat_size; |
|
2 | 622 |
|
10576 | 623 |
/* We want the smaller of 'idat_size' and 'current_buffer_size', but they |
624 |
* are of different types and we don't know which variable has the fewest |
|
625 |
* bits. Carefully select the smaller and cast it to the type of the |
|
626 |
* larger - this cannot overflow. |
|
627 |
*/ |
|
628 |
if (idat_size < save_size) |
|
629 |
save_size = (png_size_t)idat_size; |
|
630 |
||
2 | 631 |
else |
10576 | 632 |
idat_size = (png_uint_32)save_size; |
2 | 633 |
|
634 |
png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size); |
|
635 |
||
10576 | 636 |
png_process_IDAT_data(png_ptr, png_ptr->current_buffer_ptr, save_size); |
637 |
||
638 |
png_ptr->idat_size -= idat_size; |
|
2 | 639 |
png_ptr->buffer_size -= save_size; |
640 |
png_ptr->current_buffer_size -= save_size; |
|
641 |
png_ptr->current_buffer_ptr += save_size; |
|
642 |
} |
|
35296 | 643 |
|
29913 | 644 |
if (png_ptr->idat_size == 0) |
2 | 645 |
{ |
29913 | 646 |
PNG_PUSH_SAVE_BUFFER_IF_LT(4) |
2 | 647 |
png_crc_finish(png_ptr, 0); |
648 |
png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER; |
|
649 |
png_ptr->mode |= PNG_AFTER_IDAT; |
|
29913 | 650 |
png_ptr->zowner = 0; |
2 | 651 |
} |
652 |
} |
|
653 |
||
654 |
void /* PRIVATE */ |
|
29913 | 655 |
png_process_IDAT_data(png_structrp png_ptr, png_bytep buffer, |
43321 | 656 |
png_size_t buffer_length) |
2 | 657 |
{ |
10576 | 658 |
/* The caller checks for a non-zero buffer length. */ |
659 |
if (!(buffer_length > 0) || buffer == NULL) |
|
660 |
png_error(png_ptr, "No IDAT data (internal error)"); |
|
2 | 661 |
|
10576 | 662 |
/* This routine must process all the data it has been given |
663 |
* before returning, calling the row callback as required to |
|
664 |
* handle the uncompressed results. |
|
665 |
*/ |
|
2 | 666 |
png_ptr->zstream.next_in = buffer; |
29913 | 667 |
/* TODO: WARNING: TRUNCATION ERROR: DANGER WILL ROBINSON: */ |
2 | 668 |
png_ptr->zstream.avail_in = (uInt)buffer_length; |
10576 | 669 |
|
670 |
/* Keep going until the decompressed data is all processed |
|
671 |
* or the stream marked as finished. |
|
672 |
*/ |
|
673 |
while (png_ptr->zstream.avail_in > 0 && |
|
35296 | 674 |
(png_ptr->flags & PNG_FLAG_ZSTREAM_ENDED) == 0) |
2 | 675 |
{ |
10576 | 676 |
int ret; |
2 | 677 |
|
10576 | 678 |
/* We have data for zlib, but we must check that zlib |
679 |
* has someplace to put the results. It doesn't matter |
|
680 |
* if we don't expect any results -- it may be the input |
|
681 |
* data is just the LZ end code. |
|
682 |
*/ |
|
683 |
if (!(png_ptr->zstream.avail_out > 0)) |
|
2 | 684 |
{ |
29913 | 685 |
/* TODO: WARNING: TRUNCATION ERROR: DANGER WILL ROBINSON: */ |
686 |
png_ptr->zstream.avail_out = (uInt)(PNG_ROWBYTES(png_ptr->pixel_depth, |
|
687 |
png_ptr->iwidth) + 1); |
|
10576 | 688 |
|
2 | 689 |
png_ptr->zstream.next_out = png_ptr->row_buf; |
690 |
} |
|
10576 | 691 |
|
692 |
/* Using Z_SYNC_FLUSH here means that an unterminated |
|
693 |
* LZ stream (a stream with a missing end code) can still |
|
694 |
* be handled, otherwise (Z_NO_FLUSH) a future zlib |
|
695 |
* implementation might defer output and therefore |
|
696 |
* change the current behavior (see comments in inflate.c |
|
697 |
* for why this doesn't happen at present with zlib 1.2.5). |
|
698 |
*/ |
|
35296 | 699 |
ret = PNG_INFLATE(png_ptr, Z_SYNC_FLUSH); |
10576 | 700 |
|
701 |
/* Check for any failure before proceeding. */ |
|
702 |
if (ret != Z_OK && ret != Z_STREAM_END) |
|
703 |
{ |
|
704 |
/* Terminate the decompression. */ |
|
29913 | 705 |
png_ptr->flags |= PNG_FLAG_ZSTREAM_ENDED; |
706 |
png_ptr->zowner = 0; |
|
10576 | 707 |
|
708 |
/* This may be a truncated stream (missing or |
|
709 |
* damaged end code). Treat that as a warning. |
|
710 |
*/ |
|
711 |
if (png_ptr->row_number >= png_ptr->num_rows || |
|
712 |
png_ptr->pass > 6) |
|
713 |
png_warning(png_ptr, "Truncated compressed data in IDAT"); |
|
714 |
||
715 |
else |
|
43321 | 716 |
{ |
717 |
if (ret == Z_DATA_ERROR) |
|
718 |
png_benign_error(png_ptr, "IDAT: ADLER32 checksum mismatch"); |
|
719 |
else |
|
720 |
png_error(png_ptr, "Decompression error in IDAT"); |
|
721 |
} |
|
10576 | 722 |
|
723 |
/* Skip the check on unprocessed input */ |
|
724 |
return; |
|
725 |
} |
|
726 |
||
727 |
/* Did inflate output any data? */ |
|
728 |
if (png_ptr->zstream.next_out != png_ptr->row_buf) |
|
729 |
{ |
|
730 |
/* Is this unexpected data after the last row? |
|
731 |
* If it is, artificially terminate the LZ output |
|
732 |
* here. |
|
733 |
*/ |
|
734 |
if (png_ptr->row_number >= png_ptr->num_rows || |
|
735 |
png_ptr->pass > 6) |
|
736 |
{ |
|
737 |
/* Extra data. */ |
|
738 |
png_warning(png_ptr, "Extra compressed data in IDAT"); |
|
29913 | 739 |
png_ptr->flags |= PNG_FLAG_ZSTREAM_ENDED; |
740 |
png_ptr->zowner = 0; |
|
10576 | 741 |
|
742 |
/* Do no more processing; skip the unprocessed |
|
743 |
* input check below. |
|
744 |
*/ |
|
745 |
return; |
|
746 |
} |
|
747 |
||
748 |
/* Do we have a complete row? */ |
|
749 |
if (png_ptr->zstream.avail_out == 0) |
|
750 |
png_push_process_row(png_ptr); |
|
751 |
} |
|
752 |
||
753 |
/* And check for the end of the stream. */ |
|
754 |
if (ret == Z_STREAM_END) |
|
29913 | 755 |
png_ptr->flags |= PNG_FLAG_ZSTREAM_ENDED; |
2 | 756 |
} |
10576 | 757 |
|
758 |
/* All the data should have been processed, if anything |
|
759 |
* is left at this point we have bytes of IDAT data |
|
760 |
* after the zlib end code. |
|
761 |
*/ |
|
762 |
if (png_ptr->zstream.avail_in > 0) |
|
763 |
png_warning(png_ptr, "Extra compression data in IDAT"); |
|
2 | 764 |
} |
765 |
||
766 |
void /* PRIVATE */ |
|
29913 | 767 |
png_push_process_row(png_structrp png_ptr) |
2 | 768 |
{ |
29913 | 769 |
/* 1.5.6: row_info moved out of png_struct to a local here. */ |
770 |
png_row_info row_info; |
|
771 |
||
772 |
row_info.width = png_ptr->iwidth; /* NOTE: width of current interlaced row */ |
|
773 |
row_info.color_type = png_ptr->color_type; |
|
774 |
row_info.bit_depth = png_ptr->bit_depth; |
|
775 |
row_info.channels = png_ptr->channels; |
|
776 |
row_info.pixel_depth = png_ptr->pixel_depth; |
|
777 |
row_info.rowbytes = PNG_ROWBYTES(row_info.pixel_depth, row_info.width); |
|
2 | 778 |
|
29913 | 779 |
if (png_ptr->row_buf[0] > PNG_FILTER_VALUE_NONE) |
780 |
{ |
|
781 |
if (png_ptr->row_buf[0] < PNG_FILTER_VALUE_LAST) |
|
782 |
png_read_filter_row(png_ptr, &row_info, png_ptr->row_buf + 1, |
|
783 |
png_ptr->prev_row + 1, png_ptr->row_buf[0]); |
|
784 |
else |
|
785 |
png_error(png_ptr, "bad adaptive filter value"); |
|
786 |
} |
|
2 | 787 |
|
29913 | 788 |
/* libpng 1.5.6: the following line was copying png_ptr->rowbytes before |
789 |
* 1.5.6, while the buffer really is this big in current versions of libpng |
|
790 |
* it may not be in the future, so this was changed just to copy the |
|
791 |
* interlaced row count: |
|
792 |
*/ |
|
793 |
memcpy(png_ptr->prev_row, png_ptr->row_buf, row_info.rowbytes + 1); |
|
2 | 794 |
|
10576 | 795 |
#ifdef PNG_READ_TRANSFORMS_SUPPORTED |
29913 | 796 |
if (png_ptr->transformations != 0) |
797 |
png_do_read_transformations(png_ptr, &row_info); |
|
10576 | 798 |
#endif |
2 | 799 |
|
29913 | 800 |
/* The transformed pixel depth should match the depth now in row_info. */ |
801 |
if (png_ptr->transformed_pixel_depth == 0) |
|
802 |
{ |
|
803 |
png_ptr->transformed_pixel_depth = row_info.pixel_depth; |
|
804 |
if (row_info.pixel_depth > png_ptr->maximum_pixel_depth) |
|
805 |
png_error(png_ptr, "progressive row overflow"); |
|
806 |
} |
|
807 |
||
808 |
else if (png_ptr->transformed_pixel_depth != row_info.pixel_depth) |
|
809 |
png_error(png_ptr, "internal progressive row size calculation error"); |
|
810 |
||
811 |
||
10576 | 812 |
#ifdef PNG_READ_INTERLACING_SUPPORTED |
29913 | 813 |
/* Expand interlaced rows to full size */ |
814 |
if (png_ptr->interlaced != 0 && |
|
815 |
(png_ptr->transformations & PNG_INTERLACE) != 0) |
|
2 | 816 |
{ |
817 |
if (png_ptr->pass < 6) |
|
29913 | 818 |
png_do_read_interlace(&row_info, png_ptr->row_buf + 1, png_ptr->pass, |
43321 | 819 |
png_ptr->transformations); |
2 | 820 |
|
29913 | 821 |
switch (png_ptr->pass) |
822 |
{ |
|
2 | 823 |
case 0: |
824 |
{ |
|
825 |
int i; |
|
826 |
for (i = 0; i < 8 && png_ptr->pass == 0; i++) |
|
827 |
{ |
|
828 |
png_push_have_row(png_ptr, png_ptr->row_buf + 1); |
|
10576 | 829 |
png_read_push_finish_row(png_ptr); /* Updates png_ptr->pass */ |
2 | 830 |
} |
10576 | 831 |
|
832 |
if (png_ptr->pass == 2) /* Pass 1 might be empty */ |
|
2 | 833 |
{ |
834 |
for (i = 0; i < 4 && png_ptr->pass == 2; i++) |
|
835 |
{ |
|
10576 | 836 |
png_push_have_row(png_ptr, NULL); |
2 | 837 |
png_read_push_finish_row(png_ptr); |
838 |
} |
|
839 |
} |
|
10576 | 840 |
|
2 | 841 |
if (png_ptr->pass == 4 && png_ptr->height <= 4) |
842 |
{ |
|
843 |
for (i = 0; i < 2 && png_ptr->pass == 4; i++) |
|
844 |
{ |
|
10576 | 845 |
png_push_have_row(png_ptr, NULL); |
2 | 846 |
png_read_push_finish_row(png_ptr); |
847 |
} |
|
848 |
} |
|
10576 | 849 |
|
2 | 850 |
if (png_ptr->pass == 6 && png_ptr->height <= 4) |
851 |
{ |
|
10576 | 852 |
png_push_have_row(png_ptr, NULL); |
2 | 853 |
png_read_push_finish_row(png_ptr); |
854 |
} |
|
10576 | 855 |
|
2 | 856 |
break; |
857 |
} |
|
10576 | 858 |
|
2 | 859 |
case 1: |
860 |
{ |
|
861 |
int i; |
|
862 |
for (i = 0; i < 8 && png_ptr->pass == 1; i++) |
|
863 |
{ |
|
864 |
png_push_have_row(png_ptr, png_ptr->row_buf + 1); |
|
865 |
png_read_push_finish_row(png_ptr); |
|
866 |
} |
|
10576 | 867 |
|
868 |
if (png_ptr->pass == 2) /* Skip top 4 generated rows */ |
|
2 | 869 |
{ |
870 |
for (i = 0; i < 4 && png_ptr->pass == 2; i++) |
|
871 |
{ |
|
10576 | 872 |
png_push_have_row(png_ptr, NULL); |
2 | 873 |
png_read_push_finish_row(png_ptr); |
874 |
} |
|
875 |
} |
|
10576 | 876 |
|
2 | 877 |
break; |
878 |
} |
|
10576 | 879 |
|
2 | 880 |
case 2: |
881 |
{ |
|
882 |
int i; |
|
10576 | 883 |
|
2 | 884 |
for (i = 0; i < 4 && png_ptr->pass == 2; i++) |
885 |
{ |
|
886 |
png_push_have_row(png_ptr, png_ptr->row_buf + 1); |
|
887 |
png_read_push_finish_row(png_ptr); |
|
888 |
} |
|
10576 | 889 |
|
2 | 890 |
for (i = 0; i < 4 && png_ptr->pass == 2; i++) |
891 |
{ |
|
10576 | 892 |
png_push_have_row(png_ptr, NULL); |
2 | 893 |
png_read_push_finish_row(png_ptr); |
894 |
} |
|
10576 | 895 |
|
896 |
if (png_ptr->pass == 4) /* Pass 3 might be empty */ |
|
2 | 897 |
{ |
898 |
for (i = 0; i < 2 && png_ptr->pass == 4; i++) |
|
899 |
{ |
|
10576 | 900 |
png_push_have_row(png_ptr, NULL); |
2 | 901 |
png_read_push_finish_row(png_ptr); |
902 |
} |
|
903 |
} |
|
10576 | 904 |
|
2 | 905 |
break; |
906 |
} |
|
10576 | 907 |
|
2 | 908 |
case 3: |
909 |
{ |
|
910 |
int i; |
|
10576 | 911 |
|
2 | 912 |
for (i = 0; i < 4 && png_ptr->pass == 3; i++) |
913 |
{ |
|
914 |
png_push_have_row(png_ptr, png_ptr->row_buf + 1); |
|
915 |
png_read_push_finish_row(png_ptr); |
|
916 |
} |
|
10576 | 917 |
|
918 |
if (png_ptr->pass == 4) /* Skip top two generated rows */ |
|
2 | 919 |
{ |
920 |
for (i = 0; i < 2 && png_ptr->pass == 4; i++) |
|
921 |
{ |
|
10576 | 922 |
png_push_have_row(png_ptr, NULL); |
2 | 923 |
png_read_push_finish_row(png_ptr); |
924 |
} |
|
925 |
} |
|
10576 | 926 |
|
2 | 927 |
break; |
928 |
} |
|
10576 | 929 |
|
2 | 930 |
case 4: |
931 |
{ |
|
932 |
int i; |
|
10576 | 933 |
|
2 | 934 |
for (i = 0; i < 2 && png_ptr->pass == 4; i++) |
935 |
{ |
|
936 |
png_push_have_row(png_ptr, png_ptr->row_buf + 1); |
|
937 |
png_read_push_finish_row(png_ptr); |
|
938 |
} |
|
10576 | 939 |
|
2 | 940 |
for (i = 0; i < 2 && png_ptr->pass == 4; i++) |
941 |
{ |
|
10576 | 942 |
png_push_have_row(png_ptr, NULL); |
2 | 943 |
png_read_push_finish_row(png_ptr); |
944 |
} |
|
10576 | 945 |
|
946 |
if (png_ptr->pass == 6) /* Pass 5 might be empty */ |
|
2 | 947 |
{ |
10576 | 948 |
png_push_have_row(png_ptr, NULL); |
2 | 949 |
png_read_push_finish_row(png_ptr); |
950 |
} |
|
10576 | 951 |
|
2 | 952 |
break; |
953 |
} |
|
10576 | 954 |
|
2 | 955 |
case 5: |
956 |
{ |
|
957 |
int i; |
|
10576 | 958 |
|
2 | 959 |
for (i = 0; i < 2 && png_ptr->pass == 5; i++) |
960 |
{ |
|
961 |
png_push_have_row(png_ptr, png_ptr->row_buf + 1); |
|
962 |
png_read_push_finish_row(png_ptr); |
|
963 |
} |
|
10576 | 964 |
|
965 |
if (png_ptr->pass == 6) /* Skip top generated row */ |
|
2 | 966 |
{ |
10576 | 967 |
png_push_have_row(png_ptr, NULL); |
2 | 968 |
png_read_push_finish_row(png_ptr); |
969 |
} |
|
10576 | 970 |
|
2 | 971 |
break; |
972 |
} |
|
10576 | 973 |
|
974 |
default: |
|
2 | 975 |
case 6: |
976 |
{ |
|
977 |
png_push_have_row(png_ptr, png_ptr->row_buf + 1); |
|
978 |
png_read_push_finish_row(png_ptr); |
|
10576 | 979 |
|
2 | 980 |
if (png_ptr->pass != 6) |
981 |
break; |
|
10576 | 982 |
|
983 |
png_push_have_row(png_ptr, NULL); |
|
2 | 984 |
png_read_push_finish_row(png_ptr); |
985 |
} |
|
986 |
} |
|
987 |
} |
|
988 |
else |
|
35296 | 989 |
#endif |
2 | 990 |
{ |
991 |
png_push_have_row(png_ptr, png_ptr->row_buf + 1); |
|
992 |
png_read_push_finish_row(png_ptr); |
|
993 |
} |
|
994 |
} |
|
995 |
||
996 |
void /* PRIVATE */ |
|
29913 | 997 |
png_read_push_finish_row(png_structrp png_ptr) |
2 | 998 |
{ |
35296 | 999 |
#ifdef PNG_READ_INTERLACING_SUPPORTED |
10576 | 1000 |
/* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ |
2 | 1001 |
|
10576 | 1002 |
/* Start of interlace block */ |
29913 | 1003 |
static PNG_CONST png_byte png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; |
2 | 1004 |
|
10576 | 1005 |
/* Offset to next interlace block */ |
29913 | 1006 |
static PNG_CONST png_byte png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; |
2 | 1007 |
|
10576 | 1008 |
/* Start of interlace block in the y direction */ |
29913 | 1009 |
static PNG_CONST png_byte png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1}; |
2 | 1010 |
|
10576 | 1011 |
/* Offset to next interlace block in the y direction */ |
29913 | 1012 |
static PNG_CONST png_byte png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2}; |
2 | 1013 |
|
1014 |
/* Height of interlace block. This is not currently used - if you need |
|
1015 |
* it, uncomment it here and in png.h |
|
29913 | 1016 |
static PNG_CONST png_byte png_pass_height[] = {8, 8, 4, 4, 2, 2, 1}; |
2 | 1017 |
*/ |
29913 | 1018 |
#endif |
2 | 1019 |
|
1020 |
png_ptr->row_number++; |
|
1021 |
if (png_ptr->row_number < png_ptr->num_rows) |
|
1022 |
return; |
|
1023 |
||
35296 | 1024 |
#ifdef PNG_READ_INTERLACING_SUPPORTED |
29913 | 1025 |
if (png_ptr->interlaced != 0) |
2 | 1026 |
{ |
1027 |
png_ptr->row_number = 0; |
|
29913 | 1028 |
memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1); |
10576 | 1029 |
|
2 | 1030 |
do |
1031 |
{ |
|
1032 |
png_ptr->pass++; |
|
1033 |
if ((png_ptr->pass == 1 && png_ptr->width < 5) || |
|
1034 |
(png_ptr->pass == 3 && png_ptr->width < 3) || |
|
1035 |
(png_ptr->pass == 5 && png_ptr->width < 2)) |
|
10576 | 1036 |
png_ptr->pass++; |
2 | 1037 |
|
1038 |
if (png_ptr->pass > 7) |
|
1039 |
png_ptr->pass--; |
|
10576 | 1040 |
|
2 | 1041 |
if (png_ptr->pass >= 7) |
1042 |
break; |
|
1043 |
||
1044 |
png_ptr->iwidth = (png_ptr->width + |
|
10576 | 1045 |
png_pass_inc[png_ptr->pass] - 1 - |
1046 |
png_pass_start[png_ptr->pass]) / |
|
1047 |
png_pass_inc[png_ptr->pass]; |
|
2 | 1048 |
|
29913 | 1049 |
if ((png_ptr->transformations & PNG_INTERLACE) != 0) |
2 | 1050 |
break; |
1051 |
||
1052 |
png_ptr->num_rows = (png_ptr->height + |
|
10576 | 1053 |
png_pass_yinc[png_ptr->pass] - 1 - |
1054 |
png_pass_ystart[png_ptr->pass]) / |
|
1055 |
png_pass_yinc[png_ptr->pass]; |
|
2 | 1056 |
|
1057 |
} while (png_ptr->iwidth == 0 || png_ptr->num_rows == 0); |
|
1058 |
} |
|
35296 | 1059 |
#endif /* READ_INTERLACING */ |
2 | 1060 |
} |
1061 |
||
1062 |
void /* PRIVATE */ |
|
29913 | 1063 |
png_push_have_info(png_structrp png_ptr, png_inforp info_ptr) |
2 | 1064 |
{ |
1065 |
if (png_ptr->info_fn != NULL) |
|
1066 |
(*(png_ptr->info_fn))(png_ptr, info_ptr); |
|
1067 |
} |
|
1068 |
||
1069 |
void /* PRIVATE */ |
|
29913 | 1070 |
png_push_have_end(png_structrp png_ptr, png_inforp info_ptr) |
2 | 1071 |
{ |
1072 |
if (png_ptr->end_fn != NULL) |
|
1073 |
(*(png_ptr->end_fn))(png_ptr, info_ptr); |
|
1074 |
} |
|
1075 |
||
1076 |
void /* PRIVATE */ |
|
29913 | 1077 |
png_push_have_row(png_structrp png_ptr, png_bytep row) |
2 | 1078 |
{ |
1079 |
if (png_ptr->row_fn != NULL) |
|
1080 |
(*(png_ptr->row_fn))(png_ptr, row, png_ptr->row_number, |
|
43321 | 1081 |
(int)png_ptr->pass); |
2 | 1082 |
} |
1083 |
||
35296 | 1084 |
#ifdef PNG_READ_INTERLACING_SUPPORTED |
2 | 1085 |
void PNGAPI |
29913 | 1086 |
png_progressive_combine_row(png_const_structrp png_ptr, png_bytep old_row, |
10576 | 1087 |
png_const_bytep new_row) |
2 | 1088 |
{ |
10576 | 1089 |
if (png_ptr == NULL) |
1090 |
return; |
|
1091 |
||
29913 | 1092 |
/* new_row is a flag here - if it is NULL then the app callback was called |
1093 |
* from an empty row (see the calls to png_struct::row_fn below), otherwise |
|
1094 |
* it must be png_ptr->row_buf+1 |
|
1095 |
*/ |
|
1096 |
if (new_row != NULL) |
|
1097 |
png_combine_row(png_ptr, old_row, 1/*blocky display*/); |
|
2 | 1098 |
} |
35296 | 1099 |
#endif /* READ_INTERLACING */ |
2 | 1100 |
|
1101 |
void PNGAPI |
|
29913 | 1102 |
png_set_progressive_read_fn(png_structrp png_ptr, png_voidp progressive_ptr, |
10576 | 1103 |
png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn, |
1104 |
png_progressive_end_ptr end_fn) |
|
2 | 1105 |
{ |
10576 | 1106 |
if (png_ptr == NULL) |
1107 |
return; |
|
1108 |
||
2 | 1109 |
png_ptr->info_fn = info_fn; |
1110 |
png_ptr->row_fn = row_fn; |
|
1111 |
png_ptr->end_fn = end_fn; |
|
1112 |
||
1113 |
png_set_read_fn(png_ptr, progressive_ptr, png_push_fill_buffer); |
|
1114 |
} |
|
1115 |
||
1116 |
png_voidp PNGAPI |
|
29913 | 1117 |
png_get_progressive_ptr(png_const_structrp png_ptr) |
2 | 1118 |
{ |
10576 | 1119 |
if (png_ptr == NULL) |
1120 |
return (NULL); |
|
1121 |
||
2 | 1122 |
return png_ptr->io_ptr; |
1123 |
} |
|
29913 | 1124 |
#endif /* PROGRESSIVE_READ */ |