Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(79)

Side by Side Diff: third_party/libpng/pngrutil.c

Issue 140074: Updates the PNG library to 1.2.37, enables some functionality for O3D (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « third_party/libpng/pngrtran.c ('k') | third_party/libpng/pngset.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* pngrutil.c - utilities to read a PNG file 2 /* pngrutil.c - utilities to read a PNG file
3 * 3 *
4 * Last changed in libpng 1.2.36 [May 7, 2009] 4 * Last changed in libpng 1.2.37 [June 4, 2009]
5 * For conditions of distribution and use, see copyright notice in png.h 5 * For conditions of distribution and use, see copyright notice in png.h
6 * Copyright (c) 1998-2009 Glenn Randers-Pehrson 6 * Copyright (c) 1998-2009 Glenn Randers-Pehrson
7 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) 7 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
8 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) 8 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
9 * 9 *
10 * This file contains routines that are only called from within 10 * This file contains routines that are only called from within
11 * libpng itself during the course of reading an image. 11 * libpng itself during the course of reading an image.
12 */ 12 */
13 13
14 #define PNG_INTERNAL 14 #define PNG_INTERNAL
15 #include "png.h" 15 #include "png.h"
16 #if defined(PNG_READ_SUPPORTED) 16 #if defined(PNG_READ_SUPPORTED)
17 17
18 #if defined(_WIN32_WCE) && (_WIN32_WCE<0x500) 18 #if defined(_WIN32_WCE) && (_WIN32_WCE<0x500)
19 # define WIN32_WCE_OLD 19 # define WIN32_WCE_OLD
20 #endif 20 #endif
21 21
22 #ifdef PNG_FLOATING_POINT_SUPPORTED 22 #ifdef PNG_FLOATING_POINT_SUPPORTED
23 # if defined(WIN32_WCE_OLD) 23 # if defined(WIN32_WCE_OLD)
24 /* strtod() function is not supported on WindowsCE */ 24 /* The strtod() function is not supported on WindowsCE */
25 __inline double png_strtod(png_structp png_ptr, PNG_CONST char *nptr, char **end ptr) 25 __inline double png_strtod(png_structp png_ptr, PNG_CONST char *nptr, char **end ptr)
26 { 26 {
27 double result = 0; 27 double result = 0;
28 int len; 28 int len;
29 wchar_t *str, *end; 29 wchar_t *str, *end;
30 30
31 len = MultiByteToWideChar(CP_ACP, 0, nptr, -1, NULL, 0); 31 len = MultiByteToWideChar(CP_ACP, 0, nptr, -1, NULL, 0);
32 str = (wchar_t *)png_malloc(png_ptr, len * png_sizeof(wchar_t)); 32 str = (wchar_t *)png_malloc(png_ptr, len * png_sizeof(wchar_t));
33 if ( NULL != str ) 33 if ( NULL != str )
34 { 34 {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 png_uint_32 i = ((png_uint_32)(*buf) << 24) + 69 png_uint_32 i = ((png_uint_32)(*buf) << 24) +
70 ((png_uint_32)(*(buf + 1)) << 16) + 70 ((png_uint_32)(*(buf + 1)) << 16) +
71 ((png_uint_32)(*(buf + 2)) << 8) + 71 ((png_uint_32)(*(buf + 2)) << 8) +
72 (png_uint_32)(*(buf + 3)); 72 (png_uint_32)(*(buf + 3));
73 73
74 return (i); 74 return (i);
75 } 75 }
76 76
77 /* Grab a signed 32-bit integer from a buffer in big-endian format. The 77 /* Grab a signed 32-bit integer from a buffer in big-endian format. The
78 * data is stored in the PNG file in two's complement format, and it is 78 * data is stored in the PNG file in two's complement format, and it is
79 * assumed that the machine format for signed integers is the same. */ 79 * assumed that the machine format for signed integers is the same.
80 */
80 png_int_32 PNGAPI 81 png_int_32 PNGAPI
81 png_get_int_32(png_bytep buf) 82 png_get_int_32(png_bytep buf)
82 { 83 {
83 png_int_32 i = ((png_int_32)(*buf) << 24) + 84 png_int_32 i = ((png_int_32)(*buf) << 24) +
84 ((png_int_32)(*(buf + 1)) << 16) + 85 ((png_int_32)(*(buf + 1)) << 16) +
85 ((png_int_32)(*(buf + 2)) << 8) + 86 ((png_int_32)(*(buf + 2)) << 8) +
86 (png_int_32)(*(buf + 3)); 87 (png_int_32)(*(buf + 3));
87 88
88 return (i); 89 return (i);
89 } 90 }
(...skipping 11 matching lines...) Expand all
101 102
102 /* Read the chunk header (length + type name). 103 /* Read the chunk header (length + type name).
103 * Put the type name into png_ptr->chunk_name, and return the length. 104 * Put the type name into png_ptr->chunk_name, and return the length.
104 */ 105 */
105 png_uint_32 /* PRIVATE */ 106 png_uint_32 /* PRIVATE */
106 png_read_chunk_header(png_structp png_ptr) 107 png_read_chunk_header(png_structp png_ptr)
107 { 108 {
108 png_byte buf[8]; 109 png_byte buf[8];
109 png_uint_32 length; 110 png_uint_32 length;
110 111
111 /* read the length and the chunk name */ 112 /* Read the length and the chunk name */
112 png_read_data(png_ptr, buf, 8); 113 png_read_data(png_ptr, buf, 8);
113 length = png_get_uint_31(png_ptr, buf); 114 length = png_get_uint_31(png_ptr, buf);
114 115
115 /* put the chunk name into png_ptr->chunk_name */ 116 /* Put the chunk name into png_ptr->chunk_name */
116 png_memcpy(png_ptr->chunk_name, buf + 4, 4); 117 png_memcpy(png_ptr->chunk_name, buf + 4, 4);
117 118
118 png_debug2(0, "Reading %s chunk, length = %lu", 119 png_debug2(0, "Reading %s chunk, length = %lu",
119 png_ptr->chunk_name, length); 120 png_ptr->chunk_name, length);
120 121
121 /* reset the crc and run it over the chunk name */ 122 /* Reset the crc and run it over the chunk name */
122 png_reset_crc(png_ptr); 123 png_reset_crc(png_ptr);
123 png_calculate_crc(png_ptr, png_ptr->chunk_name, 4); 124 png_calculate_crc(png_ptr, png_ptr->chunk_name, 4);
124 125
125 /* check to see if chunk name is valid */ 126 /* Check to see if chunk name is valid */
126 png_check_chunk_name(png_ptr, png_ptr->chunk_name); 127 png_check_chunk_name(png_ptr, png_ptr->chunk_name);
127 128
128 return length; 129 return length;
129 } 130 }
130 131
131 /* Read data, and (optionally) run it through the CRC. */ 132 /* Read data, and (optionally) run it through the CRC. */
132 void /* PRIVATE */ 133 void /* PRIVATE */
133 png_crc_read(png_structp png_ptr, png_bytep buf, png_size_t length) 134 png_crc_read(png_structp png_ptr, png_bytep buf, png_size_t length)
134 { 135 {
135 if (png_ptr == NULL) return; 136 if (png_ptr == NULL)
137 return;
136 png_read_data(png_ptr, buf, length); 138 png_read_data(png_ptr, buf, length);
137 png_calculate_crc(png_ptr, buf, length); 139 png_calculate_crc(png_ptr, buf, length);
138 } 140 }
139 141
140 /* Optionally skip data and then check the CRC. Depending on whether we 142 /* Optionally skip data and then check the CRC. Depending on whether we
141 are reading a ancillary or critical chunk, and how the program has set 143 * are reading a ancillary or critical chunk, and how the program has set
142 things up, we may calculate the CRC on the data and print a message. 144 * things up, we may calculate the CRC on the data and print a message.
143 Returns '1' if there was a CRC error, '0' otherwise. */ 145 * Returns '1' if there was a CRC error, '0' otherwise.
146 */
144 int /* PRIVATE */ 147 int /* PRIVATE */
145 png_crc_finish(png_structp png_ptr, png_uint_32 skip) 148 png_crc_finish(png_structp png_ptr, png_uint_32 skip)
146 { 149 {
147 png_size_t i; 150 png_size_t i;
148 png_size_t istop = png_ptr->zbuf_size; 151 png_size_t istop = png_ptr->zbuf_size;
149 152
150 for (i = (png_size_t)skip; i > istop; i -= istop) 153 for (i = (png_size_t)skip; i > istop; i -= istop)
151 { 154 {
152 png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size); 155 png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
153 } 156 }
154 if (i) 157 if (i)
155 { 158 {
156 png_crc_read(png_ptr, png_ptr->zbuf, i); 159 png_crc_read(png_ptr, png_ptr->zbuf, i);
157 } 160 }
158 161
159 if (png_crc_error(png_ptr)) 162 if (png_crc_error(png_ptr))
160 { 163 {
161 if (((png_ptr->chunk_name[0] & 0x20) && /* Ancillary */ 164 if (((png_ptr->chunk_name[0] & 0x20) && /* Ancillary */
162 !(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)) || 165 !(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)) ||
163 (!(png_ptr->chunk_name[0] & 0x20) && /* Critical */ 166 (!(png_ptr->chunk_name[0] & 0x20) && /* Critical */
164 (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_USE))) 167 (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_USE)))
165 { 168 {
166 png_chunk_warning(png_ptr, "CRC error"); 169 png_chunk_warning(png_ptr, "CRC error");
167 } 170 }
168 else 171 else
169 { 172 {
170 png_chunk_error(png_ptr, "CRC error"); 173 png_chunk_error(png_ptr, "CRC error");
171 } 174 }
172 return (1); 175 return (1);
173 } 176 }
174 177
175 return (0); 178 return (0);
176 } 179 }
177 180
178 /* Compare the CRC stored in the PNG file with that calculated by libpng from 181 /* Compare the CRC stored in the PNG file with that calculated by libpng from
179 the data it has read thus far. */ 182 * the data it has read thus far.
183 */
180 int /* PRIVATE */ 184 int /* PRIVATE */
181 png_crc_error(png_structp png_ptr) 185 png_crc_error(png_structp png_ptr)
182 { 186 {
183 png_byte crc_bytes[4]; 187 png_byte crc_bytes[4];
184 png_uint_32 crc; 188 png_uint_32 crc;
185 int need_crc = 1; 189 int need_crc = 1;
186 190
187 if (png_ptr->chunk_name[0] & 0x20) /* ancillary */ 191 if (png_ptr->chunk_name[0] & 0x20) /* ancillary */
188 { 192 {
189 if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) == 193 if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 } 328 }
325 if (ret != Z_STREAM_END) 329 if (ret != Z_STREAM_END)
326 { 330 {
327 #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE) 331 #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
328 char umsg[52]; 332 char umsg[52];
329 333
330 if (ret == Z_BUF_ERROR) 334 if (ret == Z_BUF_ERROR)
331 png_snprintf(umsg, 52, 335 png_snprintf(umsg, 52,
332 "Buffer error in compressed datastream in %s chunk", 336 "Buffer error in compressed datastream in %s chunk",
333 png_ptr->chunk_name); 337 png_ptr->chunk_name);
338
334 else if (ret == Z_DATA_ERROR) 339 else if (ret == Z_DATA_ERROR)
335 png_snprintf(umsg, 52, 340 png_snprintf(umsg, 52,
336 "Data error in compressed datastream in %s chunk", 341 "Data error in compressed datastream in %s chunk",
337 png_ptr->chunk_name); 342 png_ptr->chunk_name);
343
338 else 344 else
339 png_snprintf(umsg, 52, 345 png_snprintf(umsg, 52,
340 "Incomplete compressed datastream in %s chunk", 346 "Incomplete compressed datastream in %s chunk",
341 png_ptr->chunk_name); 347 png_ptr->chunk_name);
348
342 png_warning(png_ptr, umsg); 349 png_warning(png_ptr, umsg);
343 #else 350 #else
344 png_warning(png_ptr, 351 png_warning(png_ptr,
345 "Incomplete compressed datastream in chunk other than IDAT"); 352 "Incomplete compressed datastream in chunk other than IDAT");
346 #endif 353 #endif
347 text_size = prefix_size; 354 text_size = prefix_size;
348 if (text == NULL) 355 if (text == NULL)
349 { 356 {
350 text = (png_charp)png_malloc_warn(png_ptr, text_size+1); 357 text = (png_charp)png_malloc_warn(png_ptr, text_size+1);
351 if (text == NULL) 358 if (text == NULL)
(...skipping 24 matching lines...) Expand all
376 #else 383 #else
377 png_warning(png_ptr, "Unknown zTXt compression type"); 384 png_warning(png_ptr, "Unknown zTXt compression type");
378 #endif 385 #endif
379 386
380 *(png_ptr->chunkdata + prefix_size) = 0x00; 387 *(png_ptr->chunkdata + prefix_size) = 0x00;
381 *newlength = prefix_size; 388 *newlength = prefix_size;
382 } 389 }
383 } 390 }
384 #endif 391 #endif
385 392
386 /* read and check the IDHR chunk */ 393 /* Read and check the IDHR chunk */
387 void /* PRIVATE */ 394 void /* PRIVATE */
388 png_handle_IHDR(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) 395 png_handle_IHDR(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
389 { 396 {
390 png_byte buf[13]; 397 png_byte buf[13];
391 png_uint_32 width, height; 398 png_uint_32 width, height;
392 int bit_depth, color_type, compression_type, filter_type; 399 int bit_depth, color_type, compression_type, filter_type;
393 int interlace_type; 400 int interlace_type;
394 401
395 png_debug(1, "in png_handle_IHDR"); 402 png_debug(1, "in png_handle_IHDR");
396 403
397 if (png_ptr->mode & PNG_HAVE_IHDR) 404 if (png_ptr->mode & PNG_HAVE_IHDR)
398 png_error(png_ptr, "Out of place IHDR"); 405 png_error(png_ptr, "Out of place IHDR");
399 406
400 /* check the length */ 407 /* Check the length */
401 if (length != 13) 408 if (length != 13)
402 png_error(png_ptr, "Invalid IHDR chunk"); 409 png_error(png_ptr, "Invalid IHDR chunk");
403 410
404 png_ptr->mode |= PNG_HAVE_IHDR; 411 png_ptr->mode |= PNG_HAVE_IHDR;
405 412
406 png_crc_read(png_ptr, buf, 13); 413 png_crc_read(png_ptr, buf, 13);
407 png_crc_finish(png_ptr, 0); 414 png_crc_finish(png_ptr, 0);
408 415
409 width = png_get_uint_31(png_ptr, buf); 416 width = png_get_uint_31(png_ptr, buf);
410 height = png_get_uint_31(png_ptr, buf + 4); 417 height = png_get_uint_31(png_ptr, buf + 4);
411 bit_depth = buf[8]; 418 bit_depth = buf[8];
412 color_type = buf[9]; 419 color_type = buf[9];
413 compression_type = buf[10]; 420 compression_type = buf[10];
414 filter_type = buf[11]; 421 filter_type = buf[11];
415 interlace_type = buf[12]; 422 interlace_type = buf[12];
416 423
417 /* set internal variables */ 424 /* Set internal variables */
418 png_ptr->width = width; 425 png_ptr->width = width;
419 png_ptr->height = height; 426 png_ptr->height = height;
420 png_ptr->bit_depth = (png_byte)bit_depth; 427 png_ptr->bit_depth = (png_byte)bit_depth;
421 png_ptr->interlaced = (png_byte)interlace_type; 428 png_ptr->interlaced = (png_byte)interlace_type;
422 png_ptr->color_type = (png_byte)color_type; 429 png_ptr->color_type = (png_byte)color_type;
423 #if defined(PNG_MNG_FEATURES_SUPPORTED) 430 #if defined(PNG_MNG_FEATURES_SUPPORTED)
424 png_ptr->filter_type = (png_byte)filter_type; 431 png_ptr->filter_type = (png_byte)filter_type;
425 #endif 432 #endif
426 png_ptr->compression_type = (png_byte)compression_type; 433 png_ptr->compression_type = (png_byte)compression_type;
427 434
428 /* find number of channels */ 435 /* Find number of channels */
429 switch (png_ptr->color_type) 436 switch (png_ptr->color_type)
430 { 437 {
431 case PNG_COLOR_TYPE_GRAY: 438 case PNG_COLOR_TYPE_GRAY:
432 case PNG_COLOR_TYPE_PALETTE: 439 case PNG_COLOR_TYPE_PALETTE:
433 png_ptr->channels = 1; 440 png_ptr->channels = 1;
434 break; 441 break;
442
435 case PNG_COLOR_TYPE_RGB: 443 case PNG_COLOR_TYPE_RGB:
436 png_ptr->channels = 3; 444 png_ptr->channels = 3;
437 break; 445 break;
446
438 case PNG_COLOR_TYPE_GRAY_ALPHA: 447 case PNG_COLOR_TYPE_GRAY_ALPHA:
439 png_ptr->channels = 2; 448 png_ptr->channels = 2;
440 break; 449 break;
450
441 case PNG_COLOR_TYPE_RGB_ALPHA: 451 case PNG_COLOR_TYPE_RGB_ALPHA:
442 png_ptr->channels = 4; 452 png_ptr->channels = 4;
443 break; 453 break;
444 } 454 }
445 455
446 /* set up other useful info */ 456 /* Set up other useful info */
447 png_ptr->pixel_depth = (png_byte)(png_ptr->bit_depth * 457 png_ptr->pixel_depth = (png_byte)(png_ptr->bit_depth *
448 png_ptr->channels); 458 png_ptr->channels);
449 png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, png_ptr->width); 459 png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, png_ptr->width);
450 png_debug1(3, "bit_depth = %d", png_ptr->bit_depth); 460 png_debug1(3, "bit_depth = %d", png_ptr->bit_depth);
451 png_debug1(3, "channels = %d", png_ptr->channels); 461 png_debug1(3, "channels = %d", png_ptr->channels);
452 png_debug1(3, "rowbytes = %lu", png_ptr->rowbytes); 462 png_debug1(3, "rowbytes = %lu", png_ptr->rowbytes);
453 png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth, 463 png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth,
454 color_type, interlace_type, compression_type, filter_type); 464 color_type, interlace_type, compression_type, filter_type);
455 } 465 }
456 466
457 /* read and check the palette */ 467 /* Read and check the palette */
458 void /* PRIVATE */ 468 void /* PRIVATE */
459 png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) 469 png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
460 { 470 {
461 png_color palette[PNG_MAX_PALETTE_LENGTH]; 471 png_color palette[PNG_MAX_PALETTE_LENGTH];
462 int num, i; 472 int num, i;
463 #ifndef PNG_NO_POINTER_INDEXING 473 #ifndef PNG_NO_POINTER_INDEXING
464 png_colorp pal_ptr; 474 png_colorp pal_ptr;
465 #endif 475 #endif
466 476
467 png_debug(1, "in png_handle_PLTE"); 477 png_debug(1, "in png_handle_PLTE");
468 478
469 if (!(png_ptr->mode & PNG_HAVE_IHDR)) 479 if (!(png_ptr->mode & PNG_HAVE_IHDR))
470 png_error(png_ptr, "Missing IHDR before PLTE"); 480 png_error(png_ptr, "Missing IHDR before PLTE");
481
471 else if (png_ptr->mode & PNG_HAVE_IDAT) 482 else if (png_ptr->mode & PNG_HAVE_IDAT)
472 { 483 {
473 png_warning(png_ptr, "Invalid PLTE after IDAT"); 484 png_warning(png_ptr, "Invalid PLTE after IDAT");
474 png_crc_finish(png_ptr, length); 485 png_crc_finish(png_ptr, length);
475 return; 486 return;
476 } 487 }
488
477 else if (png_ptr->mode & PNG_HAVE_PLTE) 489 else if (png_ptr->mode & PNG_HAVE_PLTE)
478 png_error(png_ptr, "Duplicate PLTE chunk"); 490 png_error(png_ptr, "Duplicate PLTE chunk");
479 491
480 png_ptr->mode |= PNG_HAVE_PLTE; 492 png_ptr->mode |= PNG_HAVE_PLTE;
481 493
482 if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR)) 494 if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR))
483 { 495 {
484 png_warning(png_ptr, 496 png_warning(png_ptr,
485 "Ignoring PLTE chunk in grayscale PNG"); 497 "Ignoring PLTE chunk in grayscale PNG");
486 png_crc_finish(png_ptr, length); 498 png_crc_finish(png_ptr, length);
487 return; 499 return;
488 } 500 }
489 #if !defined(PNG_READ_OPT_PLTE_SUPPORTED) 501 #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
490 if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE) 502 if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
491 { 503 {
492 png_crc_finish(png_ptr, length); 504 png_crc_finish(png_ptr, length);
493 return; 505 return;
494 } 506 }
495 #endif 507 #endif
496 508
497 if (length > 3*PNG_MAX_PALETTE_LENGTH || length % 3) 509 if (length > 3*PNG_MAX_PALETTE_LENGTH || length % 3)
498 { 510 {
499 if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE) 511 if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
500 { 512 {
501 png_warning(png_ptr, "Invalid palette chunk"); 513 png_warning(png_ptr, "Invalid palette chunk");
502 png_crc_finish(png_ptr, length); 514 png_crc_finish(png_ptr, length);
503 return; 515 return;
504 } 516 }
517
505 else 518 else
506 { 519 {
507 png_error(png_ptr, "Invalid palette chunk"); 520 png_error(png_ptr, "Invalid palette chunk");
508 } 521 }
509 } 522 }
510 523
511 num = (int)length / 3; 524 num = (int)length / 3;
512 525
513 #ifndef PNG_NO_POINTER_INDEXING 526 #ifndef PNG_NO_POINTER_INDEXING
514 for (i = 0, pal_ptr = palette; i < num; i++, pal_ptr++) 527 for (i = 0, pal_ptr = palette; i < num; i++, pal_ptr++)
515 { 528 {
516 png_byte buf[3]; 529 png_byte buf[3];
517 530
518 png_crc_read(png_ptr, buf, 3); 531 png_crc_read(png_ptr, buf, 3);
519 pal_ptr->red = buf[0]; 532 pal_ptr->red = buf[0];
520 pal_ptr->green = buf[1]; 533 pal_ptr->green = buf[1];
521 pal_ptr->blue = buf[2]; 534 pal_ptr->blue = buf[2];
522 } 535 }
523 #else 536 #else
524 for (i = 0; i < num; i++) 537 for (i = 0; i < num; i++)
525 { 538 {
526 png_byte buf[3]; 539 png_byte buf[3];
527 540
528 png_crc_read(png_ptr, buf, 3); 541 png_crc_read(png_ptr, buf, 3);
529 /* don't depend upon png_color being any order */ 542 /* Don't depend upon png_color being any order */
530 palette[i].red = buf[0]; 543 palette[i].red = buf[0];
531 palette[i].green = buf[1]; 544 palette[i].green = buf[1];
532 palette[i].blue = buf[2]; 545 palette[i].blue = buf[2];
533 } 546 }
534 #endif 547 #endif
535 548
536 /* If we actually NEED the PLTE chunk (ie for a paletted image), we do 549 /* If we actually NEED the PLTE chunk (ie for a paletted image), we do
537 whatever the normal CRC configuration tells us. However, if we 550 * whatever the normal CRC configuration tells us. However, if we
538 have an RGB image, the PLTE can be considered ancillary, so 551 * have an RGB image, the PLTE can be considered ancillary, so
539 we will act as though it is. */ 552 * we will act as though it is.
553 */
540 #if !defined(PNG_READ_OPT_PLTE_SUPPORTED) 554 #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
541 if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) 555 if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
542 #endif 556 #endif
543 { 557 {
544 png_crc_finish(png_ptr, 0); 558 png_crc_finish(png_ptr, 0);
545 } 559 }
546 #if !defined(PNG_READ_OPT_PLTE_SUPPORTED) 560 #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
547 else if (png_crc_error(png_ptr)) /* Only if we have a CRC error */ 561 else if (png_crc_error(png_ptr)) /* Only if we have a CRC error */
548 { 562 {
549 /* If we don't want to use the data from an ancillary chunk, 563 /* If we don't want to use the data from an ancillary chunk,
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 } 618 }
605 619
606 png_ptr->mode |= (PNG_AFTER_IDAT | PNG_HAVE_IEND); 620 png_ptr->mode |= (PNG_AFTER_IDAT | PNG_HAVE_IEND);
607 621
608 if (length != 0) 622 if (length != 0)
609 { 623 {
610 png_warning(png_ptr, "Incorrect IEND chunk length"); 624 png_warning(png_ptr, "Incorrect IEND chunk length");
611 } 625 }
612 png_crc_finish(png_ptr, length); 626 png_crc_finish(png_ptr, length);
613 627
614 info_ptr = info_ptr; /* quiet compiler warnings about unused info_ptr */ 628 info_ptr = info_ptr; /* Quiet compiler warnings about unused info_ptr */
615 } 629 }
616 630
617 #if defined(PNG_READ_gAMA_SUPPORTED) 631 #if defined(PNG_READ_gAMA_SUPPORTED)
618 void /* PRIVATE */ 632 void /* PRIVATE */
619 png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) 633 png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
620 { 634 {
621 png_fixed_point igamma; 635 png_fixed_point igamma;
622 #ifdef PNG_FLOATING_POINT_SUPPORTED 636 #ifdef PNG_FLOATING_POINT_SUPPORTED
623 float file_gamma; 637 float file_gamma;
624 #endif 638 #endif
(...skipping 29 matching lines...) Expand all
654 png_warning(png_ptr, "Incorrect gAMA chunk length"); 668 png_warning(png_ptr, "Incorrect gAMA chunk length");
655 png_crc_finish(png_ptr, length); 669 png_crc_finish(png_ptr, length);
656 return; 670 return;
657 } 671 }
658 672
659 png_crc_read(png_ptr, buf, 4); 673 png_crc_read(png_ptr, buf, 4);
660 if (png_crc_finish(png_ptr, 0)) 674 if (png_crc_finish(png_ptr, 0))
661 return; 675 return;
662 676
663 igamma = (png_fixed_point)png_get_uint_32(buf); 677 igamma = (png_fixed_point)png_get_uint_32(buf);
664 /* check for zero gamma */ 678 /* Check for zero gamma */
665 if (igamma == 0) 679 if (igamma == 0)
666 { 680 {
667 png_warning(png_ptr, 681 png_warning(png_ptr,
668 "Ignoring gAMA chunk with gamma=0"); 682 "Ignoring gAMA chunk with gamma=0");
669 return; 683 return;
670 } 684 }
671 685
672 #if defined(PNG_READ_sRGB_SUPPORTED) 686 #if defined(PNG_READ_sRGB_SUPPORTED)
673 if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)) 687 if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB))
674 if (PNG_OUT_OF_RANGE(igamma, 45500L, 500)) 688 if (PNG_OUT_OF_RANGE(igamma, 45500L, 500))
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
918 png_warning(png_ptr, "Incorrect sRGB chunk length"); 932 png_warning(png_ptr, "Incorrect sRGB chunk length");
919 png_crc_finish(png_ptr, length); 933 png_crc_finish(png_ptr, length);
920 return; 934 return;
921 } 935 }
922 936
923 png_crc_read(png_ptr, buf, 1); 937 png_crc_read(png_ptr, buf, 1);
924 if (png_crc_finish(png_ptr, 0)) 938 if (png_crc_finish(png_ptr, 0))
925 return; 939 return;
926 940
927 intent = buf[0]; 941 intent = buf[0];
928 /* check for bad intent */ 942 /* Check for bad intent */
929 if (intent >= PNG_sRGB_INTENT_LAST) 943 if (intent >= PNG_sRGB_INTENT_LAST)
930 { 944 {
931 png_warning(png_ptr, "Unknown sRGB intent"); 945 png_warning(png_ptr, "Unknown sRGB intent");
932 return; 946 return;
933 } 947 }
934 948
935 #if defined(PNG_READ_gAMA_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED) 949 #if defined(PNG_READ_gAMA_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
936 if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)) 950 if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA))
937 { 951 {
938 png_fixed_point igamma; 952 png_fixed_point igamma;
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1033 if (png_crc_finish(png_ptr, skip)) 1047 if (png_crc_finish(png_ptr, skip))
1034 { 1048 {
1035 png_free(png_ptr, png_ptr->chunkdata); 1049 png_free(png_ptr, png_ptr->chunkdata);
1036 png_ptr->chunkdata = NULL; 1050 png_ptr->chunkdata = NULL;
1037 return; 1051 return;
1038 } 1052 }
1039 1053
1040 png_ptr->chunkdata[slength] = 0x00; 1054 png_ptr->chunkdata[slength] = 0x00;
1041 1055
1042 for (profile = png_ptr->chunkdata; *profile; profile++) 1056 for (profile = png_ptr->chunkdata; *profile; profile++)
1043 /* empty loop to find end of name */ ; 1057 /* Empty loop to find end of name */ ;
1044 1058
1045 ++profile; 1059 ++profile;
1046 1060
1047 /* there should be at least one zero (the compression type byte) 1061 /* There should be at least one zero (the compression type byte)
1048 following the separator, and we should be on it */ 1062 * following the separator, and we should be on it
1063 */
1049 if ( profile >= png_ptr->chunkdata + slength - 1) 1064 if ( profile >= png_ptr->chunkdata + slength - 1)
1050 { 1065 {
1051 png_free(png_ptr, png_ptr->chunkdata); 1066 png_free(png_ptr, png_ptr->chunkdata);
1052 png_ptr->chunkdata = NULL; 1067 png_ptr->chunkdata = NULL;
1053 png_warning(png_ptr, "Malformed iCCP chunk"); 1068 png_warning(png_ptr, "Malformed iCCP chunk");
1054 return; 1069 return;
1055 } 1070 }
1056 1071
1057 /* compression_type should always be zero */ 1072 /* Compression_type should always be zero */
1058 compression_type = *profile++; 1073 compression_type = *profile++;
1059 if (compression_type) 1074 if (compression_type)
1060 { 1075 {
1061 png_warning(png_ptr, "Ignoring nonzero compression type in iCCP chunk"); 1076 png_warning(png_ptr, "Ignoring nonzero compression type in iCCP chunk");
1062 compression_type = 0x00; /* Reset it to zero (libpng-1.0.6 through 1.0.8 1077 compression_type = 0x00; /* Reset it to zero (libpng-1.0.6 through 1.0.8
1063 wrote nonzero) */ 1078 wrote nonzero) */
1064 } 1079 }
1065 1080
1066 prefix_length = profile - png_ptr->chunkdata; 1081 prefix_length = profile - png_ptr->chunkdata;
1067 png_decompress_chunk(png_ptr, compression_type, 1082 png_decompress_chunk(png_ptr, compression_type,
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1145 if (png_crc_finish(png_ptr, skip)) 1160 if (png_crc_finish(png_ptr, skip))
1146 { 1161 {
1147 png_free(png_ptr, png_ptr->chunkdata); 1162 png_free(png_ptr, png_ptr->chunkdata);
1148 png_ptr->chunkdata = NULL; 1163 png_ptr->chunkdata = NULL;
1149 return; 1164 return;
1150 } 1165 }
1151 1166
1152 png_ptr->chunkdata[slength] = 0x00; 1167 png_ptr->chunkdata[slength] = 0x00;
1153 1168
1154 for (entry_start = (png_bytep)png_ptr->chunkdata; *entry_start; entry_start++ ) 1169 for (entry_start = (png_bytep)png_ptr->chunkdata; *entry_start; entry_start++ )
1155 /* empty loop to find end of name */ ; 1170 /* Empty loop to find end of name */ ;
1156 ++entry_start; 1171 ++entry_start;
1157 1172
1158 /* a sample depth should follow the separator, and we should be on it */ 1173 /* A sample depth should follow the separator, and we should be on it */
1159 if (entry_start > (png_bytep)png_ptr->chunkdata + slength - 2) 1174 if (entry_start > (png_bytep)png_ptr->chunkdata + slength - 2)
1160 { 1175 {
1161 png_free(png_ptr, png_ptr->chunkdata); 1176 png_free(png_ptr, png_ptr->chunkdata);
1162 png_ptr->chunkdata = NULL; 1177 png_ptr->chunkdata = NULL;
1163 png_warning(png_ptr, "malformed sPLT chunk"); 1178 png_warning(png_ptr, "malformed sPLT chunk");
1164 return; 1179 return;
1165 } 1180 }
1166 1181
1167 new_palette.depth = *entry_start++; 1182 new_palette.depth = *entry_start++;
1168 entry_size = (new_palette.depth == 8 ? 6 : 10); 1183 entry_size = (new_palette.depth == 8 ? 6 : 10);
1169 data_length = (slength - (entry_start - (png_bytep)png_ptr->chunkdata)); 1184 data_length = (slength - (entry_start - (png_bytep)png_ptr->chunkdata));
1170 1185
1171 /* integrity-check the data length */ 1186 /* Integrity-check the data length */
1172 if (data_length % entry_size) 1187 if (data_length % entry_size)
1173 { 1188 {
1174 png_free(png_ptr, png_ptr->chunkdata); 1189 png_free(png_ptr, png_ptr->chunkdata);
1175 png_ptr->chunkdata = NULL; 1190 png_ptr->chunkdata = NULL;
1176 png_warning(png_ptr, "sPLT chunk has bad length"); 1191 png_warning(png_ptr, "sPLT chunk has bad length");
1177 return; 1192 return;
1178 } 1193 }
1179 1194
1180 new_palette.nentries = (png_int_32) ( data_length / entry_size); 1195 new_palette.nentries = (png_int_32) ( data_length / entry_size);
1181 if ((png_uint_32) new_palette.nentries > 1196 if ((png_uint_32) new_palette.nentries >
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1229 { 1244 {
1230 pp[i].red = png_get_uint_16(entry_start); entry_start += 2; 1245 pp[i].red = png_get_uint_16(entry_start); entry_start += 2;
1231 pp[i].green = png_get_uint_16(entry_start); entry_start += 2; 1246 pp[i].green = png_get_uint_16(entry_start); entry_start += 2;
1232 pp[i].blue = png_get_uint_16(entry_start); entry_start += 2; 1247 pp[i].blue = png_get_uint_16(entry_start); entry_start += 2;
1233 pp[i].alpha = png_get_uint_16(entry_start); entry_start += 2; 1248 pp[i].alpha = png_get_uint_16(entry_start); entry_start += 2;
1234 } 1249 }
1235 pp->frequency = png_get_uint_16(entry_start); entry_start += 2; 1250 pp->frequency = png_get_uint_16(entry_start); entry_start += 2;
1236 } 1251 }
1237 #endif 1252 #endif
1238 1253
1239 /* discard all chunk data except the name and stash that */ 1254 /* Discard all chunk data except the name and stash that */
1240 new_palette.name = png_ptr->chunkdata; 1255 new_palette.name = png_ptr->chunkdata;
1241 1256
1242 png_set_sPLT(png_ptr, info_ptr, &new_palette, 1); 1257 png_set_sPLT(png_ptr, info_ptr, &new_palette, 1);
1243 1258
1244 png_free(png_ptr, png_ptr->chunkdata); 1259 png_free(png_ptr, png_ptr->chunkdata);
1245 png_ptr->chunkdata = NULL; 1260 png_ptr->chunkdata = NULL;
1246 png_free(png_ptr, new_palette.entries); 1261 png_free(png_ptr, new_palette.entries);
1247 } 1262 }
1248 #endif /* PNG_READ_sPLT_SUPPORTED */ 1263 #endif /* PNG_READ_sPLT_SUPPORTED */
1249 1264
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
1565 return; 1580 return;
1566 1581
1567 offset_x = png_get_int_32(buf); 1582 offset_x = png_get_int_32(buf);
1568 offset_y = png_get_int_32(buf + 4); 1583 offset_y = png_get_int_32(buf + 4);
1569 unit_type = buf[8]; 1584 unit_type = buf[8];
1570 png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y, unit_type); 1585 png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y, unit_type);
1571 } 1586 }
1572 #endif 1587 #endif
1573 1588
1574 #if defined(PNG_READ_pCAL_SUPPORTED) 1589 #if defined(PNG_READ_pCAL_SUPPORTED)
1575 /* read the pCAL chunk (described in the PNG Extensions document) */ 1590 /* Read the pCAL chunk (described in the PNG Extensions document) */
1576 void /* PRIVATE */ 1591 void /* PRIVATE */
1577 png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) 1592 png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
1578 { 1593 {
1579 png_int_32 X0, X1; 1594 png_int_32 X0, X1;
1580 png_byte type, nparams; 1595 png_byte type, nparams;
1581 png_charp buf, units, endptr; 1596 png_charp buf, units, endptr;
1582 png_charpp params; 1597 png_charpp params;
1583 png_size_t slength; 1598 png_size_t slength;
1584 int i; 1599 int i;
1585 1600
(...skipping 26 matching lines...) Expand all
1612 slength = (png_size_t)length; 1627 slength = (png_size_t)length;
1613 png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength); 1628 png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength);
1614 1629
1615 if (png_crc_finish(png_ptr, 0)) 1630 if (png_crc_finish(png_ptr, 0))
1616 { 1631 {
1617 png_free(png_ptr, png_ptr->chunkdata); 1632 png_free(png_ptr, png_ptr->chunkdata);
1618 png_ptr->chunkdata = NULL; 1633 png_ptr->chunkdata = NULL;
1619 return; 1634 return;
1620 } 1635 }
1621 1636
1622 png_ptr->chunkdata[slength] = 0x00; /* null terminate the last string */ 1637 png_ptr->chunkdata[slength] = 0x00; /* Null terminate the last string */
1623 1638
1624 png_debug(3, "Finding end of pCAL purpose string"); 1639 png_debug(3, "Finding end of pCAL purpose string");
1625 for (buf = png_ptr->chunkdata; *buf; buf++) 1640 for (buf = png_ptr->chunkdata; *buf; buf++)
1626 /* empty loop */ ; 1641 /* Empty loop */ ;
1627 1642
1628 endptr = png_ptr->chunkdata + slength; 1643 endptr = png_ptr->chunkdata + slength;
1629 1644
1630 /* We need to have at least 12 bytes after the purpose string 1645 /* We need to have at least 12 bytes after the purpose string
1631 in order to get the parameter information. */ 1646 in order to get the parameter information. */
1632 if (endptr <= buf + 12) 1647 if (endptr <= buf + 12)
1633 { 1648 {
1634 png_warning(png_ptr, "Invalid pCAL data"); 1649 png_warning(png_ptr, "Invalid pCAL data");
1635 png_free(png_ptr, png_ptr->chunkdata); 1650 png_free(png_ptr, png_ptr->chunkdata);
1636 png_ptr->chunkdata = NULL; 1651 png_ptr->chunkdata = NULL;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1699 png_set_pCAL(png_ptr, info_ptr, png_ptr->chunkdata, X0, X1, type, nparams, 1714 png_set_pCAL(png_ptr, info_ptr, png_ptr->chunkdata, X0, X1, type, nparams,
1700 units, params); 1715 units, params);
1701 1716
1702 png_free(png_ptr, png_ptr->chunkdata); 1717 png_free(png_ptr, png_ptr->chunkdata);
1703 png_ptr->chunkdata = NULL; 1718 png_ptr->chunkdata = NULL;
1704 png_free(png_ptr, params); 1719 png_free(png_ptr, params);
1705 } 1720 }
1706 #endif 1721 #endif
1707 1722
1708 #if defined(PNG_READ_sCAL_SUPPORTED) 1723 #if defined(PNG_READ_sCAL_SUPPORTED)
1709 /* read the sCAL chunk */ 1724 /* Read the sCAL chunk */
1710 void /* PRIVATE */ 1725 void /* PRIVATE */
1711 png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) 1726 png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
1712 { 1727 {
1713 png_charp ep; 1728 png_charp ep;
1714 #ifdef PNG_FLOATING_POINT_SUPPORTED 1729 #ifdef PNG_FLOATING_POINT_SUPPORTED
1715 double width, height; 1730 double width, height;
1716 png_charp vp; 1731 png_charp vp;
1717 #else 1732 #else
1718 #ifdef PNG_FIXED_POINT_SUPPORTED 1733 #ifdef PNG_FIXED_POINT_SUPPORTED
1719 png_charp swidth, sheight; 1734 png_charp swidth, sheight;
(...skipping 29 matching lines...) Expand all
1749 slength = (png_size_t)length; 1764 slength = (png_size_t)length;
1750 png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength); 1765 png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength);
1751 1766
1752 if (png_crc_finish(png_ptr, 0)) 1767 if (png_crc_finish(png_ptr, 0))
1753 { 1768 {
1754 png_free(png_ptr, png_ptr->chunkdata); 1769 png_free(png_ptr, png_ptr->chunkdata);
1755 png_ptr->chunkdata = NULL; 1770 png_ptr->chunkdata = NULL;
1756 return; 1771 return;
1757 } 1772 }
1758 1773
1759 png_ptr->chunkdata[slength] = 0x00; /* null terminate the last string */ 1774 png_ptr->chunkdata[slength] = 0x00; /* Null terminate the last string */
1760 1775
1761 ep = png_ptr->chunkdata + 1; /* skip unit byte */ 1776 ep = png_ptr->chunkdata + 1; /* Skip unit byte */
1762 1777
1763 #ifdef PNG_FLOATING_POINT_SUPPORTED 1778 #ifdef PNG_FLOATING_POINT_SUPPORTED
1764 width = png_strtod(png_ptr, ep, &vp); 1779 width = png_strtod(png_ptr, ep, &vp);
1765 if (*vp) 1780 if (*vp)
1766 { 1781 {
1767 png_warning(png_ptr, "malformed width string in sCAL chunk"); 1782 png_warning(png_ptr, "malformed width string in sCAL chunk");
1768 return; 1783 return;
1769 } 1784 }
1770 #else 1785 #else
1771 #ifdef PNG_FIXED_POINT_SUPPORTED 1786 #ifdef PNG_FIXED_POINT_SUPPORTED
1772 swidth = (png_charp)png_malloc_warn(png_ptr, png_strlen(ep) + 1); 1787 swidth = (png_charp)png_malloc_warn(png_ptr, png_strlen(ep) + 1);
1773 if (swidth == NULL) 1788 if (swidth == NULL)
1774 { 1789 {
1775 png_warning(png_ptr, "Out of memory while processing sCAL chunk width"); 1790 png_warning(png_ptr, "Out of memory while processing sCAL chunk width");
1776 return; 1791 return;
1777 } 1792 }
1778 png_memcpy(swidth, ep, (png_size_t)png_strlen(ep)); 1793 png_memcpy(swidth, ep, (png_size_t)png_strlen(ep));
1779 #endif 1794 #endif
1780 #endif 1795 #endif
1781 1796
1782 for (ep = png_ptr->chunkdata; *ep; ep++) 1797 for (ep = png_ptr->chunkdata; *ep; ep++)
1783 /* empty loop */ ; 1798 /* Empty loop */ ;
1784 ep++; 1799 ep++;
1785 1800
1786 if (png_ptr->chunkdata + slength < ep) 1801 if (png_ptr->chunkdata + slength < ep)
1787 { 1802 {
1788 png_warning(png_ptr, "Truncated sCAL chunk"); 1803 png_warning(png_ptr, "Truncated sCAL chunk");
1789 #if defined(PNG_FIXED_POINT_SUPPORTED) && \ 1804 #if defined(PNG_FIXED_POINT_SUPPORTED) && \
1790 !defined(PNG_FLOATING_POINT_SUPPORTED) 1805 !defined(PNG_FLOATING_POINT_SUPPORTED)
1791 png_free(png_ptr, swidth); 1806 png_free(png_ptr, swidth);
1792 #endif 1807 #endif
1793 png_free(png_ptr, png_ptr->chunkdata); 1808 png_free(png_ptr, png_ptr->chunkdata);
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1937 png_free(png_ptr, png_ptr->chunkdata); 1952 png_free(png_ptr, png_ptr->chunkdata);
1938 png_ptr->chunkdata = NULL; 1953 png_ptr->chunkdata = NULL;
1939 return; 1954 return;
1940 } 1955 }
1941 1956
1942 key = png_ptr->chunkdata; 1957 key = png_ptr->chunkdata;
1943 1958
1944 key[slength] = 0x00; 1959 key[slength] = 0x00;
1945 1960
1946 for (text = key; *text; text++) 1961 for (text = key; *text; text++)
1947 /* empty loop to find end of key */ ; 1962 /* Empty loop to find end of key */ ;
1948 1963
1949 if (text != key + slength) 1964 if (text != key + slength)
1950 text++; 1965 text++;
1951 1966
1952 text_ptr = (png_textp)png_malloc_warn(png_ptr, 1967 text_ptr = (png_textp)png_malloc_warn(png_ptr,
1953 (png_uint_32)png_sizeof(png_text)); 1968 (png_uint_32)png_sizeof(png_text));
1954 if (text_ptr == NULL) 1969 if (text_ptr == NULL)
1955 { 1970 {
1956 png_warning(png_ptr, "Not enough memory to process text chunk."); 1971 png_warning(png_ptr, "Not enough memory to process text chunk.");
1957 png_free(png_ptr, png_ptr->chunkdata); 1972 png_free(png_ptr, png_ptr->chunkdata);
(...skipping 14 matching lines...) Expand all
1972 1987
1973 png_free(png_ptr, png_ptr->chunkdata); 1988 png_free(png_ptr, png_ptr->chunkdata);
1974 png_ptr->chunkdata = NULL; 1989 png_ptr->chunkdata = NULL;
1975 png_free(png_ptr, text_ptr); 1990 png_free(png_ptr, text_ptr);
1976 if (ret) 1991 if (ret)
1977 png_warning(png_ptr, "Insufficient memory to process text chunk."); 1992 png_warning(png_ptr, "Insufficient memory to process text chunk.");
1978 } 1993 }
1979 #endif 1994 #endif
1980 1995
1981 #if defined(PNG_READ_zTXt_SUPPORTED) 1996 #if defined(PNG_READ_zTXt_SUPPORTED)
1982 /* note: this does not correctly handle chunks that are > 64K under DOS */ 1997 /* Note: this does not correctly handle chunks that are > 64K under DOS */
1983 void /* PRIVATE */ 1998 void /* PRIVATE */
1984 png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) 1999 png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
1985 { 2000 {
1986 png_textp text_ptr; 2001 png_textp text_ptr;
1987 png_charp text; 2002 png_charp text;
1988 int comp_type; 2003 int comp_type;
1989 int ret; 2004 int ret;
1990 png_size_t slength, prefix_len, data_len; 2005 png_size_t slength, prefix_len, data_len;
1991 2006
1992 png_debug(1, "in png_handle_zTXt"); 2007 png_debug(1, "in png_handle_zTXt");
(...skipping 28 matching lines...) Expand all
2021 if (png_crc_finish(png_ptr, 0)) 2036 if (png_crc_finish(png_ptr, 0))
2022 { 2037 {
2023 png_free(png_ptr, png_ptr->chunkdata); 2038 png_free(png_ptr, png_ptr->chunkdata);
2024 png_ptr->chunkdata = NULL; 2039 png_ptr->chunkdata = NULL;
2025 return; 2040 return;
2026 } 2041 }
2027 2042
2028 png_ptr->chunkdata[slength] = 0x00; 2043 png_ptr->chunkdata[slength] = 0x00;
2029 2044
2030 for (text = png_ptr->chunkdata; *text; text++) 2045 for (text = png_ptr->chunkdata; *text; text++)
2031 /* empty loop */ ; 2046 /* Empty loop */ ;
2032 2047
2033 /* zTXt must have some text after the chunkdataword */ 2048 /* zTXt must have some text after the chunkdataword */
2034 if (text >= png_ptr->chunkdata + slength - 2) 2049 if (text >= png_ptr->chunkdata + slength - 2)
2035 { 2050 {
2036 png_warning(png_ptr, "Truncated zTXt chunk"); 2051 png_warning(png_ptr, "Truncated zTXt chunk");
2037 png_free(png_ptr, png_ptr->chunkdata); 2052 png_free(png_ptr, png_ptr->chunkdata);
2038 png_ptr->chunkdata = NULL; 2053 png_ptr->chunkdata = NULL;
2039 return; 2054 return;
2040 } 2055 }
2041 else 2056 else
2042 { 2057 {
2043 comp_type = *(++text); 2058 comp_type = *(++text);
2044 if (comp_type != PNG_TEXT_COMPRESSION_zTXt) 2059 if (comp_type != PNG_TEXT_COMPRESSION_zTXt)
2045 { 2060 {
2046 png_warning(png_ptr, "Unknown compression type in zTXt chunk"); 2061 png_warning(png_ptr, "Unknown compression type in zTXt chunk");
2047 comp_type = PNG_TEXT_COMPRESSION_zTXt; 2062 comp_type = PNG_TEXT_COMPRESSION_zTXt;
2048 } 2063 }
2049 text++; /* skip the compression_method byte */ 2064 text++; /* Skip the compression_method byte */
2050 } 2065 }
2051 prefix_len = text - png_ptr->chunkdata; 2066 prefix_len = text - png_ptr->chunkdata;
2052 2067
2053 png_decompress_chunk(png_ptr, comp_type, 2068 png_decompress_chunk(png_ptr, comp_type,
2054 (png_size_t)length, prefix_len, &data_len); 2069 (png_size_t)length, prefix_len, &data_len);
2055 2070
2056 text_ptr = (png_textp)png_malloc_warn(png_ptr, 2071 text_ptr = (png_textp)png_malloc_warn(png_ptr,
2057 (png_uint_32)png_sizeof(png_text)); 2072 (png_uint_32)png_sizeof(png_text));
2058 if (text_ptr == NULL) 2073 if (text_ptr == NULL)
2059 { 2074 {
(...skipping 16 matching lines...) Expand all
2076 2091
2077 png_free(png_ptr, text_ptr); 2092 png_free(png_ptr, text_ptr);
2078 png_free(png_ptr, png_ptr->chunkdata); 2093 png_free(png_ptr, png_ptr->chunkdata);
2079 png_ptr->chunkdata = NULL; 2094 png_ptr->chunkdata = NULL;
2080 if (ret) 2095 if (ret)
2081 png_error(png_ptr, "Insufficient memory to store zTXt chunk."); 2096 png_error(png_ptr, "Insufficient memory to store zTXt chunk.");
2082 } 2097 }
2083 #endif 2098 #endif
2084 2099
2085 #if defined(PNG_READ_iTXt_SUPPORTED) 2100 #if defined(PNG_READ_iTXt_SUPPORTED)
2086 /* note: this does not correctly handle chunks that are > 64K under DOS */ 2101 /* Note: this does not correctly handle chunks that are > 64K under DOS */
2087 void /* PRIVATE */ 2102 void /* PRIVATE */
2088 png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) 2103 png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
2089 { 2104 {
2090 png_textp text_ptr; 2105 png_textp text_ptr;
2091 png_charp key, lang, text, lang_key; 2106 png_charp key, lang, text, lang_key;
2092 int comp_flag; 2107 int comp_flag;
2093 int comp_type = 0; 2108 int comp_type = 0;
2094 int ret; 2109 int ret;
2095 png_size_t slength, prefix_len, data_len; 2110 png_size_t slength, prefix_len, data_len;
2096 2111
(...skipping 29 matching lines...) Expand all
2126 if (png_crc_finish(png_ptr, 0)) 2141 if (png_crc_finish(png_ptr, 0))
2127 { 2142 {
2128 png_free(png_ptr, png_ptr->chunkdata); 2143 png_free(png_ptr, png_ptr->chunkdata);
2129 png_ptr->chunkdata = NULL; 2144 png_ptr->chunkdata = NULL;
2130 return; 2145 return;
2131 } 2146 }
2132 2147
2133 png_ptr->chunkdata[slength] = 0x00; 2148 png_ptr->chunkdata[slength] = 0x00;
2134 2149
2135 for (lang = png_ptr->chunkdata; *lang; lang++) 2150 for (lang = png_ptr->chunkdata; *lang; lang++)
2136 /* empty loop */ ; 2151 /* Empty loop */ ;
2137 lang++; /* skip NUL separator */ 2152 lang++; /* Skip NUL separator */
2138 2153
2139 /* iTXt must have a language tag (possibly empty), two compression bytes, 2154 /* iTXt must have a language tag (possibly empty), two compression bytes,
2140 translated keyword (possibly empty), and possibly some text after the 2155 * translated keyword (possibly empty), and possibly some text after the
2141 keyword */ 2156 * keyword
2157 */
2142 2158
2143 if (lang >= png_ptr->chunkdata + slength - 3) 2159 if (lang >= png_ptr->chunkdata + slength - 3)
2144 { 2160 {
2145 png_warning(png_ptr, "Truncated iTXt chunk"); 2161 png_warning(png_ptr, "Truncated iTXt chunk");
2146 png_free(png_ptr, png_ptr->chunkdata); 2162 png_free(png_ptr, png_ptr->chunkdata);
2147 png_ptr->chunkdata = NULL; 2163 png_ptr->chunkdata = NULL;
2148 return; 2164 return;
2149 } 2165 }
2150 else 2166 else
2151 { 2167 {
2152 comp_flag = *lang++; 2168 comp_flag = *lang++;
2153 comp_type = *lang++; 2169 comp_type = *lang++;
2154 } 2170 }
2155 2171
2156 for (lang_key = lang; *lang_key; lang_key++) 2172 for (lang_key = lang; *lang_key; lang_key++)
2157 /* empty loop */ ; 2173 /* Empty loop */ ;
2158 lang_key++; /* skip NUL separator */ 2174 lang_key++; /* Skip NUL separator */
2159 2175
2160 if (lang_key >= png_ptr->chunkdata + slength) 2176 if (lang_key >= png_ptr->chunkdata + slength)
2161 { 2177 {
2162 png_warning(png_ptr, "Truncated iTXt chunk"); 2178 png_warning(png_ptr, "Truncated iTXt chunk");
2163 png_free(png_ptr, png_ptr->chunkdata); 2179 png_free(png_ptr, png_ptr->chunkdata);
2164 png_ptr->chunkdata = NULL; 2180 png_ptr->chunkdata = NULL;
2165 return; 2181 return;
2166 } 2182 }
2167 2183
2168 for (text = lang_key; *text; text++) 2184 for (text = lang_key; *text; text++)
2169 /* empty loop */ ; 2185 /* Empty loop */ ;
2170 text++; /* skip NUL separator */ 2186 text++; /* Skip NUL separator */
2171 if (text >= png_ptr->chunkdata + slength) 2187 if (text >= png_ptr->chunkdata + slength)
2172 { 2188 {
2173 png_warning(png_ptr, "Malformed iTXt chunk"); 2189 png_warning(png_ptr, "Malformed iTXt chunk");
2174 png_free(png_ptr, png_ptr->chunkdata); 2190 png_free(png_ptr, png_ptr->chunkdata);
2175 png_ptr->chunkdata = NULL; 2191 png_ptr->chunkdata = NULL;
2176 return; 2192 return;
2177 } 2193 }
2178 2194
2179 prefix_len = text - png_ptr->chunkdata; 2195 prefix_len = text - png_ptr->chunkdata;
2180 2196
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
2222 png_uint_32 skip = 0; 2238 png_uint_32 skip = 0;
2223 2239
2224 png_debug(1, "in png_handle_unknown"); 2240 png_debug(1, "in png_handle_unknown");
2225 2241
2226 2242
2227 if (png_ptr->mode & PNG_HAVE_IDAT) 2243 if (png_ptr->mode & PNG_HAVE_IDAT)
2228 { 2244 {
2229 #ifdef PNG_USE_LOCAL_ARRAYS 2245 #ifdef PNG_USE_LOCAL_ARRAYS
2230 PNG_CONST PNG_IDAT; 2246 PNG_CONST PNG_IDAT;
2231 #endif 2247 #endif
2232 if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) /* not an IDAT */ 2248 if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) /* Not an IDAT */
2233 png_ptr->mode |= PNG_AFTER_IDAT; 2249 png_ptr->mode |= PNG_AFTER_IDAT;
2234 } 2250 }
2235 2251
2236 if (!(png_ptr->chunk_name[0] & 0x20)) 2252 if (!(png_ptr->chunk_name[0] & 0x20))
2237 { 2253 {
2238 #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) 2254 #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
2239 if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name) != 2255 if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
2240 PNG_HANDLE_CHUNK_ALWAYS 2256 PNG_HANDLE_CHUNK_ALWAYS
2241 #if defined(PNG_READ_USER_CHUNKS_SUPPORTED) 2257 #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
2242 && png_ptr->read_user_chunk_fn == NULL 2258 && png_ptr->read_user_chunk_fn == NULL
(...skipping 23 matching lines...) Expand all
2266 if (length == 0) 2282 if (length == 0)
2267 png_ptr->unknown_chunk.data = NULL; 2283 png_ptr->unknown_chunk.data = NULL;
2268 else 2284 else
2269 { 2285 {
2270 png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length); 2286 png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
2271 png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length); 2287 png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
2272 } 2288 }
2273 #if defined(PNG_READ_USER_CHUNKS_SUPPORTED) 2289 #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
2274 if (png_ptr->read_user_chunk_fn != NULL) 2290 if (png_ptr->read_user_chunk_fn != NULL)
2275 { 2291 {
2276 /* callback to user unknown chunk handler */ 2292 /* Callback to user unknown chunk handler */
2277 int ret; 2293 int ret;
2278 ret = (*(png_ptr->read_user_chunk_fn)) 2294 ret = (*(png_ptr->read_user_chunk_fn))
2279 (png_ptr, &png_ptr->unknown_chunk); 2295 (png_ptr, &png_ptr->unknown_chunk);
2280 if (ret < 0) 2296 if (ret < 0)
2281 png_chunk_error(png_ptr, "error in user chunk"); 2297 png_chunk_error(png_ptr, "error in user chunk");
2282 if (ret == 0) 2298 if (ret == 0)
2283 { 2299 {
2284 if (!(png_ptr->chunk_name[0] & 0x20)) 2300 if (!(png_ptr->chunk_name[0] & 0x20))
2285 if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name) != 2301 if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
2286 PNG_HANDLE_CHUNK_ALWAYS) 2302 PNG_HANDLE_CHUNK_ALWAYS)
2287 png_chunk_error(png_ptr, "unknown critical chunk"); 2303 png_chunk_error(png_ptr, "unknown critical chunk");
2288 png_set_unknown_chunks(png_ptr, info_ptr, 2304 png_set_unknown_chunks(png_ptr, info_ptr,
2289 &png_ptr->unknown_chunk, 1); 2305 &png_ptr->unknown_chunk, 1);
2290 } 2306 }
2291 } 2307 }
2292 else 2308 else
2293 #endif 2309 #endif
2294 png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1); 2310 png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
2295 png_free(png_ptr, png_ptr->unknown_chunk.data); 2311 png_free(png_ptr, png_ptr->unknown_chunk.data);
2296 png_ptr->unknown_chunk.data = NULL; 2312 png_ptr->unknown_chunk.data = NULL;
2297 } 2313 }
2298 else 2314 else
2299 #endif 2315 #endif
2300 skip = length; 2316 skip = length;
2301 2317
2302 png_crc_finish(png_ptr, skip); 2318 png_crc_finish(png_ptr, skip);
2303 2319
2304 #if !defined(PNG_READ_USER_CHUNKS_SUPPORTED) 2320 #if !defined(PNG_READ_USER_CHUNKS_SUPPORTED)
2305 info_ptr = info_ptr; /* quiet compiler warnings about unused info_ptr */ 2321 info_ptr = info_ptr; /* Quiet compiler warnings about unused info_ptr */
2306 #endif 2322 #endif
2307 } 2323 }
2308 2324
2309 /* This function is called to verify that a chunk name is valid. 2325 /* This function is called to verify that a chunk name is valid.
2310 This function can't have the "critical chunk check" incorporated 2326 This function can't have the "critical chunk check" incorporated
2311 into it, since in the future we will need to be able to call user 2327 into it, since in the future we will need to be able to call user
2312 functions to handle unknown critical chunks after we check that 2328 functions to handle unknown critical chunks after we check that
2313 the chunk name itself is valid. */ 2329 the chunk name itself is valid. */
2314 2330
2315 #define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97)) 2331 #define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
2543 png_uint_32 transformations) 2559 png_uint_32 transformations)
2544 */ 2560 */
2545 void /* PRIVATE */ 2561 void /* PRIVATE */
2546 png_do_read_interlace(png_structp png_ptr) 2562 png_do_read_interlace(png_structp png_ptr)
2547 { 2563 {
2548 png_row_infop row_info = &(png_ptr->row_info); 2564 png_row_infop row_info = &(png_ptr->row_info);
2549 png_bytep row = png_ptr->row_buf + 1; 2565 png_bytep row = png_ptr->row_buf + 1;
2550 int pass = png_ptr->pass; 2566 int pass = png_ptr->pass;
2551 png_uint_32 transformations = png_ptr->transformations; 2567 png_uint_32 transformations = png_ptr->transformations;
2552 #ifdef PNG_USE_LOCAL_ARRAYS 2568 #ifdef PNG_USE_LOCAL_ARRAYS
2553 /* arrays to facilitate easy interlacing - use pass (0 - 6) as index */ 2569 /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
2554 /* offset to next interlace block */ 2570 /* Offset to next interlace block */
2555 PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; 2571 PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
2556 #endif 2572 #endif
2557 2573
2558 png_debug(1, "in png_do_read_interlace"); 2574 png_debug(1, "in png_do_read_interlace");
2559 if (row != NULL && row_info != NULL) 2575 if (row != NULL && row_info != NULL)
2560 { 2576 {
2561 png_uint_32 final_width; 2577 png_uint_32 final_width;
2562 2578
2563 final_width = row_info->width * png_pass_inc[pass]; 2579 final_width = row_info->width * png_pass_inc[pass];
2564 2580
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
2752 } 2768 }
2753 sp -= pixel_bytes; 2769 sp -= pixel_bytes;
2754 } 2770 }
2755 break; 2771 break;
2756 } 2772 }
2757 } 2773 }
2758 row_info->width = final_width; 2774 row_info->width = final_width;
2759 row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, final_width); 2775 row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, final_width);
2760 } 2776 }
2761 #if !defined(PNG_READ_PACKSWAP_SUPPORTED) 2777 #if !defined(PNG_READ_PACKSWAP_SUPPORTED)
2762 transformations = transformations; /* silence compiler warning */ 2778 transformations = transformations; /* Silence compiler warning */
2763 #endif 2779 #endif
2764 } 2780 }
2765 #endif /* PNG_READ_INTERLACING_SUPPORTED */ 2781 #endif /* PNG_READ_INTERLACING_SUPPORTED */
2766 2782
2767 void /* PRIVATE */ 2783 void /* PRIVATE */
2768 png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row, 2784 png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row,
2769 png_bytep prev_row, int filter) 2785 png_bytep prev_row, int filter)
2770 { 2786 {
2771 png_debug(1, "in png_read_filter_row"); 2787 png_debug(1, "in png_read_filter_row");
2772 png_debug2(2, "row = %lu, filter = %d", png_ptr->row_number, filter); 2788 png_debug2(2, "row = %lu, filter = %d", png_ptr->row_number, filter);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
2836 png_bytep cp = prev_row; 2852 png_bytep cp = prev_row;
2837 png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3; 2853 png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
2838 png_uint_32 istop=row_info->rowbytes - bpp; 2854 png_uint_32 istop=row_info->rowbytes - bpp;
2839 2855
2840 for (i = 0; i < bpp; i++) 2856 for (i = 0; i < bpp; i++)
2841 { 2857 {
2842 *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff); 2858 *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
2843 rp++; 2859 rp++;
2844 } 2860 }
2845 2861
2846 for (i = 0; i < istop; i++) /* use leftover rp,pp */ 2862 for (i = 0; i < istop; i++) /* Use leftover rp,pp */
2847 { 2863 {
2848 int a, b, c, pa, pb, pc, p; 2864 int a, b, c, pa, pb, pc, p;
2849 2865
2850 a = *lp++; 2866 a = *lp++;
2851 b = *pp++; 2867 b = *pp++;
2852 c = *cp++; 2868 c = *cp++;
2853 2869
2854 p = b - c; 2870 p = b - c;
2855 pc = a - c; 2871 pc = a - c;
2856 2872
(...skipping 23 matching lines...) Expand all
2880 } 2896 }
2881 break; 2897 break;
2882 } 2898 }
2883 default: 2899 default:
2884 png_warning(png_ptr, "Ignoring bad adaptive filter type"); 2900 png_warning(png_ptr, "Ignoring bad adaptive filter type");
2885 *row = 0; 2901 *row = 0;
2886 break; 2902 break;
2887 } 2903 }
2888 } 2904 }
2889 2905
2906 #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
2890 void /* PRIVATE */ 2907 void /* PRIVATE */
2891 png_read_finish_row(png_structp png_ptr) 2908 png_read_finish_row(png_structp png_ptr)
2892 { 2909 {
2893 #ifdef PNG_USE_LOCAL_ARRAYS 2910 #ifdef PNG_USE_LOCAL_ARRAYS
2894 #ifdef PNG_READ_INTERLACING_SUPPORTED 2911 #ifdef PNG_READ_INTERLACING_SUPPORTED
2895 /* arrays to facilitate easy interlacing - use pass (0 - 6) as index */ 2912 /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
2896 2913
2897 /* start of interlace block */ 2914 /* Start of interlace block */
2898 PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0}; 2915 PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
2899 2916
2900 /* offset to next interlace block */ 2917 /* Offset to next interlace block */
2901 PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; 2918 PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
2902 2919
2903 /* start of interlace block in the y direction */ 2920 /* Start of interlace block in the y direction */
2904 PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1}; 2921 PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
2905 2922
2906 /* offset to next interlace block in the y direction */ 2923 /* Offset to next interlace block in the y direction */
2907 PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; 2924 PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
2908 #endif /* PNG_READ_INTERLACING_SUPPORTED */ 2925 #endif /* PNG_READ_INTERLACING_SUPPORTED */
2909 #endif 2926 #endif
2910 2927
2911 png_debug(1, "in png_read_finish_row"); 2928 png_debug(1, "in png_read_finish_row");
2912 png_ptr->row_number++; 2929 png_ptr->row_number++;
2913 if (png_ptr->row_number < png_ptr->num_rows) 2930 if (png_ptr->row_number < png_ptr->num_rows)
2914 return; 2931 return;
2915 2932
2916 #ifdef PNG_READ_INTERLACING_SUPPORTED 2933 #ifdef PNG_READ_INTERLACING_SUPPORTED
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
3011 png_ptr->zstream.avail_out = 0; 3028 png_ptr->zstream.avail_out = 0;
3012 } 3029 }
3013 3030
3014 if (png_ptr->idat_size || png_ptr->zstream.avail_in) 3031 if (png_ptr->idat_size || png_ptr->zstream.avail_in)
3015 png_warning(png_ptr, "Extra compression data"); 3032 png_warning(png_ptr, "Extra compression data");
3016 3033
3017 inflateReset(&png_ptr->zstream); 3034 inflateReset(&png_ptr->zstream);
3018 3035
3019 png_ptr->mode |= PNG_AFTER_IDAT; 3036 png_ptr->mode |= PNG_AFTER_IDAT;
3020 } 3037 }
3038 #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
3021 3039
3022 void /* PRIVATE */ 3040 void /* PRIVATE */
3023 png_read_start_row(png_structp png_ptr) 3041 png_read_start_row(png_structp png_ptr)
3024 { 3042 {
3025 #ifdef PNG_USE_LOCAL_ARRAYS 3043 #ifdef PNG_USE_LOCAL_ARRAYS
3026 #ifdef PNG_READ_INTERLACING_SUPPORTED 3044 #ifdef PNG_READ_INTERLACING_SUPPORTED
3027 /* arrays to facilitate easy interlacing - use pass (0 - 6) as index */ 3045 /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
3028 3046
3029 /* start of interlace block */ 3047 /* Start of interlace block */
3030 PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0}; 3048 PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
3031 3049
3032 /* offset to next interlace block */ 3050 /* Offset to next interlace block */
3033 PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; 3051 PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
3034 3052
3035 /* start of interlace block in the y direction */ 3053 /* Start of interlace block in the y direction */
3036 PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1}; 3054 PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
3037 3055
3038 /* offset to next interlace block in the y direction */ 3056 /* Offset to next interlace block in the y direction */
3039 PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; 3057 PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
3040 #endif 3058 #endif
3041 #endif 3059 #endif
3042 3060
3043 int max_pixel_depth; 3061 int max_pixel_depth;
3044 png_size_t row_bytes; 3062 png_size_t row_bytes;
3045 3063
3046 png_debug(1, "in png_read_start_row"); 3064 png_debug(1, "in png_read_start_row");
3047 png_ptr->zstream.avail_in = 0; 3065 png_ptr->zstream.avail_in = 0;
3048 png_init_read_transformations(png_ptr); 3066 png_init_read_transformations(png_ptr);
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
3165 defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) 3183 defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
3166 if (png_ptr->transformations & PNG_USER_TRANSFORM) 3184 if (png_ptr->transformations & PNG_USER_TRANSFORM)
3167 { 3185 {
3168 int user_pixel_depth = png_ptr->user_transform_depth* 3186 int user_pixel_depth = png_ptr->user_transform_depth*
3169 png_ptr->user_transform_channels; 3187 png_ptr->user_transform_channels;
3170 if (user_pixel_depth > max_pixel_depth) 3188 if (user_pixel_depth > max_pixel_depth)
3171 max_pixel_depth=user_pixel_depth; 3189 max_pixel_depth=user_pixel_depth;
3172 } 3190 }
3173 #endif 3191 #endif
3174 3192
3175 /* align the width on the next larger 8 pixels. Mainly used 3193 /* Align the width on the next larger 8 pixels. Mainly used
3176 for interlacing */ 3194 * for interlacing
3195 */
3177 row_bytes = ((png_ptr->width + 7) & ~((png_uint_32)7)); 3196 row_bytes = ((png_ptr->width + 7) & ~((png_uint_32)7));
3178 /* calculate the maximum bytes needed, adding a byte and a pixel 3197 /* Calculate the maximum bytes needed, adding a byte and a pixel
3179 for safety's sake */ 3198 * for safety's sake
3199 */
3180 row_bytes = PNG_ROWBYTES(max_pixel_depth, row_bytes) + 3200 row_bytes = PNG_ROWBYTES(max_pixel_depth, row_bytes) +
3181 1 + ((max_pixel_depth + 7) >> 3); 3201 1 + ((max_pixel_depth + 7) >> 3);
3182 #ifdef PNG_MAX_MALLOC_64K 3202 #ifdef PNG_MAX_MALLOC_64K
3183 if (row_bytes > (png_uint_32)65536L) 3203 if (row_bytes > (png_uint_32)65536L)
3184 png_error(png_ptr, "This image requires a row greater than 64KB"); 3204 png_error(png_ptr, "This image requires a row greater than 64KB");
3185 #endif 3205 #endif
3186 3206
3187 if (row_bytes + 64 > png_ptr->old_big_row_buf_size) 3207 if (row_bytes + 64 > png_ptr->old_big_row_buf_size)
3188 { 3208 {
3189 png_free(png_ptr, png_ptr->big_row_buf); 3209 png_free(png_ptr, png_ptr->big_row_buf);
3190 png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes + 64); 3210 png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes + 64);
3191 if (png_ptr->interlaced) 3211 if (png_ptr->interlaced)
3192 png_memset(png_ptr->big_row_buf, 0, png_ptr->rowbytes + 64); 3212 png_memset(png_ptr->big_row_buf, 0, row_bytes + 64);
3193 png_ptr->row_buf = png_ptr->big_row_buf + 32; 3213 png_ptr->row_buf = png_ptr->big_row_buf + 32;
3194 png_ptr->old_big_row_buf_size = row_bytes + 64; 3214 png_ptr->old_big_row_buf_size = row_bytes + 64;
3195 } 3215 }
3196 3216
3197 #ifdef PNG_MAX_MALLOC_64K 3217 #ifdef PNG_MAX_MALLOC_64K
3198 if ((png_uint_32)png_ptr->rowbytes + 1 > (png_uint_32)65536L) 3218 if ((png_uint_32)row_bytes + 1 > (png_uint_32)65536L)
3199 png_error(png_ptr, "This image requires a row greater than 64KB"); 3219 png_error(png_ptr, "This image requires a row greater than 64KB");
3200 #endif 3220 #endif
3201 if ((png_uint_32)png_ptr->rowbytes > (png_uint_32)(PNG_SIZE_MAX - 1)) 3221 if ((png_uint_32)row_bytes > (png_uint_32)(PNG_SIZE_MAX - 1))
3202 png_error(png_ptr, "Row has too many bytes to allocate in memory."); 3222 png_error(png_ptr, "Row has too many bytes to allocate in memory.");
3203 3223
3204 if (png_ptr->rowbytes+1 > png_ptr->old_prev_row_size) 3224 if (row_bytes + 1 > png_ptr->old_prev_row_size)
3205 { 3225 {
3206 png_free(png_ptr, png_ptr->prev_row); 3226 png_free(png_ptr, png_ptr->prev_row);
3207 png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)( 3227 png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)(
3208 png_ptr->rowbytes + 1)); 3228 row_bytes + 1));
3209 png_ptr->old_prev_row_size = png_ptr->rowbytes+1; 3229 png_memset_check(png_ptr, png_ptr->prev_row, 0, row_bytes + 1);
3230 png_ptr->old_prev_row_size = row_bytes + 1;
3210 } 3231 }
3211 3232
3212 png_memset_check(png_ptr, png_ptr->prev_row, 0, png_ptr->rowbytes + 1); 3233 png_ptr->rowbytes = row_bytes;
3213 3234
3214 png_debug1(3, "width = %lu,", png_ptr->width); 3235 png_debug1(3, "width = %lu,", png_ptr->width);
3215 png_debug1(3, "height = %lu,", png_ptr->height); 3236 png_debug1(3, "height = %lu,", png_ptr->height);
3216 png_debug1(3, "iwidth = %lu,", png_ptr->iwidth); 3237 png_debug1(3, "iwidth = %lu,", png_ptr->iwidth);
3217 png_debug1(3, "num_rows = %lu,", png_ptr->num_rows); 3238 png_debug1(3, "num_rows = %lu,", png_ptr->num_rows);
3218 png_debug1(3, "rowbytes = %lu,", png_ptr->rowbytes); 3239 png_debug1(3, "rowbytes = %lu,", png_ptr->rowbytes);
3219 png_debug1(3, "irowbytes = %lu", png_ptr->irowbytes); 3240 png_debug1(3, "irowbytes = %lu", png_ptr->irowbytes);
3220 3241
3221 png_ptr->flags |= PNG_FLAG_ROW_INIT; 3242 png_ptr->flags |= PNG_FLAG_ROW_INIT;
3222 } 3243 }
3223 #endif /* PNG_READ_SUPPORTED */ 3244 #endif /* PNG_READ_SUPPORTED */
OLDNEW
« no previous file with comments | « third_party/libpng/pngrtran.c ('k') | third_party/libpng/pngset.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698