OLD | NEW |
| 1 |
1 /* pngtrans.c - transforms the data in a row (used by both readers and writers) | 2 /* pngtrans.c - transforms the data in a row (used by both readers and writers) |
2 * | 3 * |
3 * Last changed in libpng 1.6.2 [April 25, 2013] | 4 * Last changed in libpng 1.6.18 [July 23, 2015] |
4 * Copyright (c) 1998-2013 Glenn Randers-Pehrson | 5 * Copyright (c) 1998-2015 Glenn Randers-Pehrson |
5 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) | 6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) |
6 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) | 7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) |
7 * | 8 * |
8 * This code is released under the libpng license. | 9 * This code is released under the libpng license. |
9 * For conditions of distribution and use, see the disclaimer | 10 * For conditions of distribution and use, see the disclaimer |
10 * and license in png.h | 11 * and license in png.h |
11 */ | 12 */ |
12 | 13 |
13 #include "pngpriv.h" | 14 #include "pngpriv.h" |
14 | 15 |
15 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) | 16 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) |
16 | 17 |
17 #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED) | 18 #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED) |
18 /* Turn on BGR-to-RGB mapping */ | 19 /* Turn on BGR-to-RGB mapping */ |
19 void PNGAPI | 20 void PNGAPI |
20 png_set_bgr(png_structrp png_ptr) | 21 png_set_bgr(png_structrp png_ptr) |
21 { | 22 { |
22 png_debug(1, "in png_set_bgr"); | 23 png_debug(1, "in png_set_bgr"); |
23 | 24 |
24 if (png_ptr == NULL) | 25 if (png_ptr == NULL) |
25 return; | 26 return; |
26 | 27 |
27 png_ptr->transformations |= PNG_BGR; | 28 png_ptr->transformations |= PNG_BGR; |
28 } | 29 } |
29 #endif | 30 #endif |
30 | 31 |
31 #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED) | 32 #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED) |
32 /* Turn on 16 bit byte swapping */ | 33 /* Turn on 16-bit byte swapping */ |
33 void PNGAPI | 34 void PNGAPI |
34 png_set_swap(png_structrp png_ptr) | 35 png_set_swap(png_structrp png_ptr) |
35 { | 36 { |
36 png_debug(1, "in png_set_swap"); | 37 png_debug(1, "in png_set_swap"); |
37 | 38 |
38 if (png_ptr == NULL) | 39 if (png_ptr == NULL) |
39 return; | 40 return; |
40 | 41 |
41 if (png_ptr->bit_depth == 16) | 42 if (png_ptr->bit_depth == 16) |
42 png_ptr->transformations |= PNG_SWAP_BYTES; | 43 png_ptr->transformations |= PNG_SWAP_BYTES; |
43 } | 44 } |
44 #endif | 45 #endif |
45 | 46 |
46 #if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED) | 47 #if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED) |
47 /* Turn on pixel packing */ | 48 /* Turn on pixel packing */ |
48 void PNGAPI | 49 void PNGAPI |
49 png_set_packing(png_structrp png_ptr) | 50 png_set_packing(png_structrp png_ptr) |
50 { | 51 { |
51 png_debug(1, "in png_set_packing"); | 52 png_debug(1, "in png_set_packing"); |
52 | 53 |
53 if (png_ptr == NULL) | 54 if (png_ptr == NULL) |
54 return; | 55 return; |
55 | 56 |
56 if (png_ptr->bit_depth < 8) | 57 if (png_ptr->bit_depth < 8) |
57 { | 58 { |
58 png_ptr->transformations |= PNG_PACK; | 59 png_ptr->transformations |= PNG_PACK; |
59 png_ptr->usr_bit_depth = 8; | 60 # ifdef PNG_WRITE_SUPPORTED |
| 61 png_ptr->usr_bit_depth = 8; |
| 62 # endif |
60 } | 63 } |
61 } | 64 } |
62 #endif | 65 #endif |
63 | 66 |
64 #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED) | 67 #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED) |
65 /* Turn on packed pixel swapping */ | 68 /* Turn on packed pixel swapping */ |
66 void PNGAPI | 69 void PNGAPI |
67 png_set_packswap(png_structrp png_ptr) | 70 png_set_packswap(png_structrp png_ptr) |
68 { | 71 { |
69 png_debug(1, "in png_set_packswap"); | 72 png_debug(1, "in png_set_packswap"); |
(...skipping 20 matching lines...) Expand all Loading... |
90 } | 93 } |
91 #endif | 94 #endif |
92 | 95 |
93 #if defined(PNG_READ_INTERLACING_SUPPORTED) || \ | 96 #if defined(PNG_READ_INTERLACING_SUPPORTED) || \ |
94 defined(PNG_WRITE_INTERLACING_SUPPORTED) | 97 defined(PNG_WRITE_INTERLACING_SUPPORTED) |
95 int PNGAPI | 98 int PNGAPI |
96 png_set_interlace_handling(png_structrp png_ptr) | 99 png_set_interlace_handling(png_structrp png_ptr) |
97 { | 100 { |
98 png_debug(1, "in png_set_interlace handling"); | 101 png_debug(1, "in png_set_interlace handling"); |
99 | 102 |
100 if (png_ptr && png_ptr->interlaced) | 103 if (png_ptr != 0 && png_ptr->interlaced != 0) |
101 { | 104 { |
102 png_ptr->transformations |= PNG_INTERLACE; | 105 png_ptr->transformations |= PNG_INTERLACE; |
103 return (7); | 106 return (7); |
104 } | 107 } |
105 | 108 |
106 return (1); | 109 return (1); |
107 } | 110 } |
108 #endif | 111 #endif |
109 | 112 |
110 #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED) | 113 #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED) |
111 /* Add a filler byte on read, or remove a filler or alpha byte on write. | 114 /* Add a filler byte on read, or remove a filler or alpha byte on write. |
112 * The filler type has changed in v0.95 to allow future 2-byte fillers | 115 * The filler type has changed in v0.95 to allow future 2-byte fillers |
113 * for 48-bit input data, as well as to avoid problems with some compilers | 116 * for 48-bit input data, as well as to avoid problems with some compilers |
114 * that don't like bytes as parameters. | 117 * that don't like bytes as parameters. |
115 */ | 118 */ |
116 void PNGAPI | 119 void PNGAPI |
117 png_set_filler(png_structrp png_ptr, png_uint_32 filler, int filler_loc) | 120 png_set_filler(png_structrp png_ptr, png_uint_32 filler, int filler_loc) |
118 { | 121 { |
119 png_debug(1, "in png_set_filler"); | 122 png_debug(1, "in png_set_filler"); |
120 | 123 |
121 if (png_ptr == NULL) | 124 if (png_ptr == NULL) |
122 return; | 125 return; |
123 | 126 |
124 /* In libpng 1.6 it is possible to determine whether this is a read or write | 127 /* In libpng 1.6 it is possible to determine whether this is a read or write |
125 * operation and therefore to do more checking here for a valid call. | 128 * operation and therefore to do more checking here for a valid call. |
126 */ | 129 */ |
127 if (png_ptr->mode & PNG_IS_READ_STRUCT) | 130 if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0) |
128 { | 131 { |
129 # ifdef PNG_READ_FILLER_SUPPORTED | 132 # ifdef PNG_READ_FILLER_SUPPORTED |
130 /* On read png_set_filler is always valid, regardless of the base PNG | 133 /* On read png_set_filler is always valid, regardless of the base PNG |
131 * format, because other transformations can give a format where the | 134 * format, because other transformations can give a format where the |
132 * filler code can execute (basically an 8 or 16-bit component RGB or G | 135 * filler code can execute (basically an 8 or 16-bit component RGB or G |
133 * format.) | 136 * format.) |
134 * | 137 * |
135 * NOTE: usr_channels is not used by the read code! (This has led to | 138 * NOTE: usr_channels is not used by the read code! (This has led to |
136 * confusion in the past.) The filler is only used in the read code. | 139 * confusion in the past.) The filler is only used in the read code. |
137 */ | 140 */ |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 void PNGAPI | 203 void PNGAPI |
201 png_set_add_alpha(png_structrp png_ptr, png_uint_32 filler, int filler_loc) | 204 png_set_add_alpha(png_structrp png_ptr, png_uint_32 filler, int filler_loc) |
202 { | 205 { |
203 png_debug(1, "in png_set_add_alpha"); | 206 png_debug(1, "in png_set_add_alpha"); |
204 | 207 |
205 if (png_ptr == NULL) | 208 if (png_ptr == NULL) |
206 return; | 209 return; |
207 | 210 |
208 png_set_filler(png_ptr, filler, filler_loc); | 211 png_set_filler(png_ptr, filler, filler_loc); |
209 /* The above may fail to do anything. */ | 212 /* The above may fail to do anything. */ |
210 if (png_ptr->transformations & PNG_FILLER) | 213 if ((png_ptr->transformations & PNG_FILLER) != 0) |
211 png_ptr->transformations |= PNG_ADD_ALPHA; | 214 png_ptr->transformations |= PNG_ADD_ALPHA; |
212 } | 215 } |
213 | 216 |
214 #endif | 217 #endif |
215 | 218 |
216 #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \ | 219 #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \ |
217 defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED) | 220 defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED) |
218 void PNGAPI | 221 void PNGAPI |
219 png_set_swap_alpha(png_structrp png_ptr) | 222 png_set_swap_alpha(png_structrp png_ptr) |
220 { | 223 { |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 *(rp + 1) = (png_byte)(~(*(rp + 1))); | 306 *(rp + 1) = (png_byte)(~(*(rp + 1))); |
304 rp += 4; | 307 rp += 4; |
305 } | 308 } |
306 } | 309 } |
307 #endif | 310 #endif |
308 } | 311 } |
309 #endif | 312 #endif |
310 | 313 |
311 #ifdef PNG_16BIT_SUPPORTED | 314 #ifdef PNG_16BIT_SUPPORTED |
312 #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED) | 315 #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED) |
313 /* Swaps byte order on 16 bit depth images */ | 316 /* Swaps byte order on 16-bit depth images */ |
314 void /* PRIVATE */ | 317 void /* PRIVATE */ |
315 png_do_swap(png_row_infop row_info, png_bytep row) | 318 png_do_swap(png_row_infop row_info, png_bytep row) |
316 { | 319 { |
317 png_debug(1, "in png_do_swap"); | 320 png_debug(1, "in png_do_swap"); |
318 | 321 |
319 if (row_info->bit_depth == 16) | 322 if (row_info->bit_depth == 16) |
320 { | 323 { |
321 png_bytep rp = row; | 324 png_bytep rp = row; |
322 png_uint_32 i; | 325 png_uint_32 i; |
323 png_uint_32 istop= row_info->width * row_info->channels; | 326 png_uint_32 istop= row_info->width * row_info->channels; |
324 | 327 |
325 for (i = 0; i < istop; i++, rp += 2) | 328 for (i = 0; i < istop; i++, rp += 2) |
326 { | 329 { |
| 330 #ifdef PNG_BUILTIN_BSWAP16_SUPPORTED |
| 331 /* Feature added to libpng-1.6.11 for testing purposes, not |
| 332 * enabled by default. |
| 333 */ |
| 334 *(png_uint_16*)rp = __builtin_bswap16(*(png_uint_16*)rp); |
| 335 #else |
327 png_byte t = *rp; | 336 png_byte t = *rp; |
328 *rp = *(rp + 1); | 337 *rp = *(rp + 1); |
329 *(rp + 1) = t; | 338 *(rp + 1) = t; |
| 339 #endif |
330 } | 340 } |
331 } | 341 } |
332 } | 342 } |
333 #endif | 343 #endif |
334 #endif | 344 #endif |
335 | 345 |
336 #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED) | 346 #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED) |
337 static PNG_CONST png_byte onebppswaptable[256] = { | 347 static PNG_CONST png_byte onebppswaptable[256] = { |
338 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, | 348 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, |
339 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0, | 349 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0, |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
461 else if (row_info->bit_depth == 4) | 471 else if (row_info->bit_depth == 4) |
462 table = fourbppswaptable; | 472 table = fourbppswaptable; |
463 | 473 |
464 else | 474 else |
465 return; | 475 return; |
466 | 476 |
467 for (rp = row; rp < end; rp++) | 477 for (rp = row; rp < end; rp++) |
468 *rp = table[*rp]; | 478 *rp = table[*rp]; |
469 } | 479 } |
470 } | 480 } |
471 #endif /* PNG_READ_PACKSWAP_SUPPORTED or PNG_WRITE_PACKSWAP_SUPPORTED */ | 481 #endif /* PACKSWAP || WRITE_PACKSWAP */ |
472 | 482 |
473 #if defined(PNG_WRITE_FILLER_SUPPORTED) || \ | 483 #if defined(PNG_WRITE_FILLER_SUPPORTED) || \ |
474 defined(PNG_READ_STRIP_ALPHA_SUPPORTED) | 484 defined(PNG_READ_STRIP_ALPHA_SUPPORTED) |
475 /* Remove a channel - this used to be 'png_do_strip_filler' but it used a | 485 /* Remove a channel - this used to be 'png_do_strip_filler' but it used a |
476 * somewhat weird combination of flags to determine what to do. All the calls | 486 * somewhat weird combination of flags to determine what to do. All the calls |
477 * to png_do_strip_filler are changed in 1.5.2 to call this instead with the | 487 * to png_do_strip_filler are changed in 1.5.2 to call this instead with the |
478 * correct arguments. | 488 * correct arguments. |
479 * | 489 * |
480 * The routine isn't general - the channel must be the channel at the start or | 490 * The routine isn't general - the channel must be the channel at the start or |
481 * end (not in the middle) of each pixel. | 491 * end (not in the middle) of each pixel. |
(...skipping 11 matching lines...) Expand all Loading... |
493 * | 503 * |
494 * at_start: 0 -- convert AG, XG, ARGB, XRGB, AAGG, XXGG, etc. | 504 * at_start: 0 -- convert AG, XG, ARGB, XRGB, AAGG, XXGG, etc. |
495 * nonzero -- convert GA, GX, RGBA, RGBX, GGAA, RRGGBBXX, etc. | 505 * nonzero -- convert GA, GX, RGBA, RGBX, GGAA, RRGGBBXX, etc. |
496 */ | 506 */ |
497 | 507 |
498 /* GA, GX, XG cases */ | 508 /* GA, GX, XG cases */ |
499 if (row_info->channels == 2) | 509 if (row_info->channels == 2) |
500 { | 510 { |
501 if (row_info->bit_depth == 8) | 511 if (row_info->bit_depth == 8) |
502 { | 512 { |
503 if (at_start) /* Skip initial filler */ | 513 if (at_start != 0) /* Skip initial filler */ |
504 ++sp; | 514 ++sp; |
505 else /* Skip initial channel and, for sp, the filler */ | 515 else /* Skip initial channel and, for sp, the filler */ |
506 sp += 2, ++dp; | 516 sp += 2, ++dp; |
507 | 517 |
508 /* For a 1 pixel wide image there is nothing to do */ | 518 /* For a 1 pixel wide image there is nothing to do */ |
509 while (sp < ep) | 519 while (sp < ep) |
510 *dp++ = *sp, sp += 2; | 520 *dp++ = *sp, sp += 2; |
511 | 521 |
512 row_info->pixel_depth = 8; | 522 row_info->pixel_depth = 8; |
513 } | 523 } |
514 | 524 |
515 else if (row_info->bit_depth == 16) | 525 else if (row_info->bit_depth == 16) |
516 { | 526 { |
517 if (at_start) /* Skip initial filler */ | 527 if (at_start != 0) /* Skip initial filler */ |
518 sp += 2; | 528 sp += 2; |
519 else /* Skip initial channel and, for sp, the filler */ | 529 else /* Skip initial channel and, for sp, the filler */ |
520 sp += 4, dp += 2; | 530 sp += 4, dp += 2; |
521 | 531 |
522 while (sp < ep) | 532 while (sp < ep) |
523 *dp++ = *sp++, *dp++ = *sp, sp += 3; | 533 *dp++ = *sp++, *dp++ = *sp, sp += 3; |
524 | 534 |
525 row_info->pixel_depth = 16; | 535 row_info->pixel_depth = 16; |
526 } | 536 } |
527 | 537 |
528 else | 538 else |
529 return; /* bad bit depth */ | 539 return; /* bad bit depth */ |
530 | 540 |
531 row_info->channels = 1; | 541 row_info->channels = 1; |
532 | 542 |
533 /* Finally fix the color type if it records an alpha channel */ | 543 /* Finally fix the color type if it records an alpha channel */ |
534 if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) | 544 if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) |
535 row_info->color_type = PNG_COLOR_TYPE_GRAY; | 545 row_info->color_type = PNG_COLOR_TYPE_GRAY; |
536 } | 546 } |
537 | 547 |
538 /* RGBA, RGBX, XRGB cases */ | 548 /* RGBA, RGBX, XRGB cases */ |
539 else if (row_info->channels == 4) | 549 else if (row_info->channels == 4) |
540 { | 550 { |
541 if (row_info->bit_depth == 8) | 551 if (row_info->bit_depth == 8) |
542 { | 552 { |
543 if (at_start) /* Skip initial filler */ | 553 if (at_start != 0) /* Skip initial filler */ |
544 ++sp; | 554 ++sp; |
545 else /* Skip initial channels and, for sp, the filler */ | 555 else /* Skip initial channels and, for sp, the filler */ |
546 sp += 4, dp += 3; | 556 sp += 4, dp += 3; |
547 | 557 |
548 /* Note that the loop adds 3 to dp and 4 to sp each time. */ | 558 /* Note that the loop adds 3 to dp and 4 to sp each time. */ |
549 while (sp < ep) | 559 while (sp < ep) |
550 *dp++ = *sp++, *dp++ = *sp++, *dp++ = *sp, sp += 2; | 560 *dp++ = *sp++, *dp++ = *sp++, *dp++ = *sp, sp += 2; |
551 | 561 |
552 row_info->pixel_depth = 24; | 562 row_info->pixel_depth = 24; |
553 } | 563 } |
554 | 564 |
555 else if (row_info->bit_depth == 16) | 565 else if (row_info->bit_depth == 16) |
556 { | 566 { |
557 if (at_start) /* Skip initial filler */ | 567 if (at_start != 0) /* Skip initial filler */ |
558 sp += 2; | 568 sp += 2; |
559 else /* Skip initial channels and, for sp, the filler */ | 569 else /* Skip initial channels and, for sp, the filler */ |
560 sp += 8, dp += 6; | 570 sp += 8, dp += 6; |
561 | 571 |
562 while (sp < ep) | 572 while (sp < ep) |
563 { | 573 { |
564 /* Copy 6 bytes, skip 2 */ | 574 /* Copy 6 bytes, skip 2 */ |
565 *dp++ = *sp++, *dp++ = *sp++; | 575 *dp++ = *sp++, *dp++ = *sp++; |
566 *dp++ = *sp++, *dp++ = *sp++; | 576 *dp++ = *sp++, *dp++ = *sp++; |
567 *dp++ = *sp++, *dp++ = *sp, sp += 3; | 577 *dp++ = *sp++, *dp++ = *sp, sp += 3; |
(...skipping 20 matching lines...) Expand all Loading... |
588 } | 598 } |
589 #endif | 599 #endif |
590 | 600 |
591 #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED) | 601 #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED) |
592 /* Swaps red and blue bytes within a pixel */ | 602 /* Swaps red and blue bytes within a pixel */ |
593 void /* PRIVATE */ | 603 void /* PRIVATE */ |
594 png_do_bgr(png_row_infop row_info, png_bytep row) | 604 png_do_bgr(png_row_infop row_info, png_bytep row) |
595 { | 605 { |
596 png_debug(1, "in png_do_bgr"); | 606 png_debug(1, "in png_do_bgr"); |
597 | 607 |
598 if ((row_info->color_type & PNG_COLOR_MASK_COLOR)) | 608 if ((row_info->color_type & PNG_COLOR_MASK_COLOR) != 0) |
599 { | 609 { |
600 png_uint_32 row_width = row_info->width; | 610 png_uint_32 row_width = row_info->width; |
601 if (row_info->bit_depth == 8) | 611 if (row_info->bit_depth == 8) |
602 { | 612 { |
603 if (row_info->color_type == PNG_COLOR_TYPE_RGB) | 613 if (row_info->color_type == PNG_COLOR_TYPE_RGB) |
604 { | 614 { |
605 png_bytep rp; | 615 png_bytep rp; |
606 png_uint_32 i; | 616 png_uint_32 i; |
607 | 617 |
608 for (i = 0, rp = row; i < row_width; i++, rp += 3) | 618 for (i = 0, rp = row; i < row_width; i++, rp += 3) |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
658 *(rp + 4) = save; | 668 *(rp + 4) = save; |
659 save = *(rp + 1); | 669 save = *(rp + 1); |
660 *(rp + 1) = *(rp + 5); | 670 *(rp + 1) = *(rp + 5); |
661 *(rp + 5) = save; | 671 *(rp + 5) = save; |
662 } | 672 } |
663 } | 673 } |
664 } | 674 } |
665 #endif | 675 #endif |
666 } | 676 } |
667 } | 677 } |
668 #endif /* PNG_READ_BGR_SUPPORTED or PNG_WRITE_BGR_SUPPORTED */ | 678 #endif /* READ_BGR || WRITE_BGR */ |
669 | 679 |
670 #if defined(PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED) || \ | 680 #if defined(PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED) || \ |
671 defined(PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED) | 681 defined(PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED) |
672 /* Added at libpng-1.5.10 */ | 682 /* Added at libpng-1.5.10 */ |
673 void /* PRIVATE */ | 683 void /* PRIVATE */ |
674 png_do_check_palette_indexes(png_structrp png_ptr, png_row_infop row_info) | 684 png_do_check_palette_indexes(png_structrp png_ptr, png_row_infop row_info) |
675 { | 685 { |
676 if (png_ptr->num_palette < (1 << row_info->bit_depth) && | 686 if (png_ptr->num_palette < (1 << row_info->bit_depth) && |
677 png_ptr->num_palette > 0) /* num_palette can be 0 in MNG files */ | 687 png_ptr->num_palette > 0) /* num_palette can be 0 in MNG files */ |
678 { | 688 { |
679 /* Calculations moved outside switch in an attempt to stop different | 689 /* Calculations moved outside switch in an attempt to stop different |
680 * compiler warnings. 'padding' is in *bits* within the last byte, it is | 690 * compiler warnings. 'padding' is in *bits* within the last byte, it is |
681 * an 'int' because pixel_depth becomes an 'int' in the expression below, | 691 * an 'int' because pixel_depth becomes an 'int' in the expression below, |
682 * and this calculation is used because it avoids warnings that other | 692 * and this calculation is used because it avoids warnings that other |
683 * forms produced on either GCC or MSVC. | 693 * forms produced on either GCC or MSVC. |
684 */ | 694 */ |
685 int padding = (-row_info->pixel_depth * row_info->width) & 7; | 695 int padding = (-row_info->pixel_depth * row_info->width) & 7; |
686 png_bytep rp = png_ptr->row_buf + row_info->rowbytes; | 696 png_bytep rp = png_ptr->row_buf + row_info->rowbytes; |
687 | 697 |
688 switch (row_info->bit_depth) | 698 switch (row_info->bit_depth) |
689 { | 699 { |
690 case 1: | 700 case 1: |
691 { | 701 { |
692 /* in this case, all bytes must be 0 so we don't need | 702 /* in this case, all bytes must be 0 so we don't need |
693 * to unpack the pixels except for the rightmost one. | 703 * to unpack the pixels except for the rightmost one. |
694 */ | 704 */ |
695 for (; rp > png_ptr->row_buf; rp--) | 705 for (; rp > png_ptr->row_buf; rp--) |
696 { | 706 { |
697 if (*rp >> padding != 0) | 707 if ((*rp >> padding) != 0) |
698 png_ptr->num_palette_max = 1; | 708 png_ptr->num_palette_max = 1; |
699 padding = 0; | 709 padding = 0; |
700 } | 710 } |
701 | 711 |
702 break; | 712 break; |
703 } | 713 } |
704 | 714 |
705 case 2: | 715 case 2: |
706 { | 716 { |
707 for (; rp > png_ptr->row_buf; rp--) | 717 for (; rp > png_ptr->row_buf; rp--) |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
761 } | 771 } |
762 | 772 |
763 break; | 773 break; |
764 } | 774 } |
765 | 775 |
766 default: | 776 default: |
767 break; | 777 break; |
768 } | 778 } |
769 } | 779 } |
770 } | 780 } |
771 #endif /* PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED */ | 781 #endif /* CHECK_FOR_INVALID_INDEX */ |
772 | 782 |
773 #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ | 783 #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ |
774 defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) | 784 defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) |
775 #ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED | 785 #ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED |
776 void PNGAPI | 786 void PNGAPI |
777 png_set_user_transform_info(png_structrp png_ptr, png_voidp | 787 png_set_user_transform_info(png_structrp png_ptr, png_voidp |
778 user_transform_ptr, int user_transform_depth, int user_transform_channels) | 788 user_transform_ptr, int user_transform_depth, int user_transform_channels) |
779 { | 789 { |
780 png_debug(1, "in png_set_user_transform_info"); | 790 png_debug(1, "in png_set_user_transform_info"); |
781 | 791 |
(...skipping 29 matching lines...) Expand all Loading... |
811 return (NULL); | 821 return (NULL); |
812 | 822 |
813 return png_ptr->user_transform_ptr; | 823 return png_ptr->user_transform_ptr; |
814 } | 824 } |
815 #endif | 825 #endif |
816 | 826 |
817 #ifdef PNG_USER_TRANSFORM_INFO_SUPPORTED | 827 #ifdef PNG_USER_TRANSFORM_INFO_SUPPORTED |
818 png_uint_32 PNGAPI | 828 png_uint_32 PNGAPI |
819 png_get_current_row_number(png_const_structrp png_ptr) | 829 png_get_current_row_number(png_const_structrp png_ptr) |
820 { | 830 { |
821 /* See the comments in png.h - this is the sub-image row when reading and | 831 /* See the comments in png.h - this is the sub-image row when reading an |
822 * interlaced image. | 832 * interlaced image. |
823 */ | 833 */ |
824 if (png_ptr != NULL) | 834 if (png_ptr != NULL) |
825 return png_ptr->row_number; | 835 return png_ptr->row_number; |
826 | 836 |
827 return PNG_UINT_32_MAX; /* help the app not to fail silently */ | 837 return PNG_UINT_32_MAX; /* help the app not to fail silently */ |
828 } | 838 } |
829 | 839 |
830 png_byte PNGAPI | 840 png_byte PNGAPI |
831 png_get_current_pass_number(png_const_structrp png_ptr) | 841 png_get_current_pass_number(png_const_structrp png_ptr) |
832 { | 842 { |
833 if (png_ptr != NULL) | 843 if (png_ptr != NULL) |
834 return png_ptr->pass; | 844 return png_ptr->pass; |
835 return 8; /* invalid */ | 845 return 8; /* invalid */ |
836 } | 846 } |
837 #endif /* PNG_USER_TRANSFORM_INFO_SUPPORTED */ | 847 #endif /* USER_TRANSFORM_INFO */ |
838 #endif /* PNG_READ_USER_TRANSFORM_SUPPORTED || | 848 #endif /* READ_USER_TRANSFORM || WRITE_USER_TRANSFORM */ |
839 PNG_WRITE_USER_TRANSFORM_SUPPORTED */ | 849 #endif /* READ || WRITE */ |
840 #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */ | |
OLD | NEW |