| OLD | NEW |
| 1 | 1 |
| 2 /* 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) |
| 3 * | 3 * |
| 4 * Last changed in libpng 1.2.17 May 15, 2007 | 4 * Last changed in libpng 1.2.30 [August 15, 2008] |
| 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-2007 Glenn Randers-Pehrson | 6 * Copyright (c) 1998-2008 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 | 10 |
| 11 #define PNG_INTERNAL | 11 #define PNG_INTERNAL |
| 12 #include "png.h" | 12 #include "png.h" |
| 13 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) |
| 13 | 14 |
| 14 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) | |
| 15 #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED) | 15 #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED) |
| 16 /* turn on BGR-to-RGB mapping */ | 16 /* turn on BGR-to-RGB mapping */ |
| 17 void PNGAPI | 17 void PNGAPI |
| 18 png_set_bgr(png_structp png_ptr) | 18 png_set_bgr(png_structp png_ptr) |
| 19 { | 19 { |
| 20 png_debug(1, "in png_set_bgr\n"); | 20 png_debug(1, "in png_set_bgr\n"); |
| 21 if(png_ptr == NULL) return; | 21 if (png_ptr == NULL) return; |
| 22 png_ptr->transformations |= PNG_BGR; | 22 png_ptr->transformations |= PNG_BGR; |
| 23 } | 23 } |
| 24 #endif | 24 #endif |
| 25 | 25 |
| 26 #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED) | 26 #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED) |
| 27 /* turn on 16 bit byte swapping */ | 27 /* turn on 16 bit byte swapping */ |
| 28 void PNGAPI | 28 void PNGAPI |
| 29 png_set_swap(png_structp png_ptr) | 29 png_set_swap(png_structp png_ptr) |
| 30 { | 30 { |
| 31 png_debug(1, "in png_set_swap\n"); | 31 png_debug(1, "in png_set_swap\n"); |
| 32 if(png_ptr == NULL) return; | 32 if (png_ptr == NULL) return; |
| 33 if (png_ptr->bit_depth == 16) | 33 if (png_ptr->bit_depth == 16) |
| 34 png_ptr->transformations |= PNG_SWAP_BYTES; | 34 png_ptr->transformations |= PNG_SWAP_BYTES; |
| 35 } | 35 } |
| 36 #endif | 36 #endif |
| 37 | 37 |
| 38 #if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED) | 38 #if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED) |
| 39 /* turn on pixel packing */ | 39 /* turn on pixel packing */ |
| 40 void PNGAPI | 40 void PNGAPI |
| 41 png_set_packing(png_structp png_ptr) | 41 png_set_packing(png_structp png_ptr) |
| 42 { | 42 { |
| 43 png_debug(1, "in png_set_packing\n"); | 43 png_debug(1, "in png_set_packing\n"); |
| 44 if(png_ptr == NULL) return; | 44 if (png_ptr == NULL) return; |
| 45 if (png_ptr->bit_depth < 8) | 45 if (png_ptr->bit_depth < 8) |
| 46 { | 46 { |
| 47 png_ptr->transformations |= PNG_PACK; | 47 png_ptr->transformations |= PNG_PACK; |
| 48 png_ptr->usr_bit_depth = 8; | 48 png_ptr->usr_bit_depth = 8; |
| 49 } | 49 } |
| 50 } | 50 } |
| 51 #endif | 51 #endif |
| 52 | 52 |
| 53 #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED) | 53 #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED) |
| 54 /* turn on packed pixel swapping */ | 54 /* turn on packed pixel swapping */ |
| 55 void PNGAPI | 55 void PNGAPI |
| 56 png_set_packswap(png_structp png_ptr) | 56 png_set_packswap(png_structp png_ptr) |
| 57 { | 57 { |
| 58 png_debug(1, "in png_set_packswap\n"); | 58 png_debug(1, "in png_set_packswap\n"); |
| 59 if(png_ptr == NULL) return; | 59 if (png_ptr == NULL) return; |
| 60 if (png_ptr->bit_depth < 8) | 60 if (png_ptr->bit_depth < 8) |
| 61 png_ptr->transformations |= PNG_PACKSWAP; | 61 png_ptr->transformations |= PNG_PACKSWAP; |
| 62 } | 62 } |
| 63 #endif | 63 #endif |
| 64 | 64 |
| 65 #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED) | 65 #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED) |
| 66 void PNGAPI | 66 void PNGAPI |
| 67 png_set_shift(png_structp png_ptr, png_color_8p true_bits) | 67 png_set_shift(png_structp png_ptr, png_color_8p true_bits) |
| 68 { | 68 { |
| 69 png_debug(1, "in png_set_shift\n"); | 69 png_debug(1, "in png_set_shift\n"); |
| 70 if(png_ptr == NULL) return; | 70 if (png_ptr == NULL) return; |
| 71 png_ptr->transformations |= PNG_SHIFT; | 71 png_ptr->transformations |= PNG_SHIFT; |
| 72 png_ptr->shift = *true_bits; | 72 png_ptr->shift = *true_bits; |
| 73 } | 73 } |
| 74 #endif | 74 #endif |
| 75 | 75 |
| 76 #if defined(PNG_READ_INTERLACING_SUPPORTED) || \ | 76 #if defined(PNG_READ_INTERLACING_SUPPORTED) || \ |
| 77 defined(PNG_WRITE_INTERLACING_SUPPORTED) | 77 defined(PNG_WRITE_INTERLACING_SUPPORTED) |
| 78 int PNGAPI | 78 int PNGAPI |
| 79 png_set_interlace_handling(png_structp png_ptr) | 79 png_set_interlace_handling(png_structp png_ptr) |
| 80 { | 80 { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 92 #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED) | 92 #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED) |
| 93 /* Add a filler byte on read, or remove a filler or alpha byte on write. | 93 /* Add a filler byte on read, or remove a filler or alpha byte on write. |
| 94 * The filler type has changed in v0.95 to allow future 2-byte fillers | 94 * The filler type has changed in v0.95 to allow future 2-byte fillers |
| 95 * for 48-bit input data, as well as to avoid problems with some compilers | 95 * for 48-bit input data, as well as to avoid problems with some compilers |
| 96 * that don't like bytes as parameters. | 96 * that don't like bytes as parameters. |
| 97 */ | 97 */ |
| 98 void PNGAPI | 98 void PNGAPI |
| 99 png_set_filler(png_structp png_ptr, png_uint_32 filler, int filler_loc) | 99 png_set_filler(png_structp png_ptr, png_uint_32 filler, int filler_loc) |
| 100 { | 100 { |
| 101 png_debug(1, "in png_set_filler\n"); | 101 png_debug(1, "in png_set_filler\n"); |
| 102 if(png_ptr == NULL) return; | 102 if (png_ptr == NULL) return; |
| 103 png_ptr->transformations |= PNG_FILLER; | 103 png_ptr->transformations |= PNG_FILLER; |
| 104 png_ptr->filler = (png_byte)filler; | 104 png_ptr->filler = (png_byte)filler; |
| 105 if (filler_loc == PNG_FILLER_AFTER) | 105 if (filler_loc == PNG_FILLER_AFTER) |
| 106 png_ptr->flags |= PNG_FLAG_FILLER_AFTER; | 106 png_ptr->flags |= PNG_FLAG_FILLER_AFTER; |
| 107 else | 107 else |
| 108 png_ptr->flags &= ~PNG_FLAG_FILLER_AFTER; | 108 png_ptr->flags &= ~PNG_FLAG_FILLER_AFTER; |
| 109 | 109 |
| 110 /* This should probably go in the "do_read_filler" routine. | 110 /* This should probably go in the "do_read_filler" routine. |
| 111 * I attempted to do that in libpng-1.0.1a but that caused problems | 111 * I attempted to do that in libpng-1.0.1a but that caused problems |
| 112 * so I restored it in libpng-1.0.2a | 112 * so I restored it in libpng-1.0.2a |
| (...skipping 12 matching lines...) Expand all Loading... |
| 125 png_ptr->usr_channels = 2; | 125 png_ptr->usr_channels = 2; |
| 126 } | 126 } |
| 127 } | 127 } |
| 128 | 128 |
| 129 #if !defined(PNG_1_0_X) | 129 #if !defined(PNG_1_0_X) |
| 130 /* Added to libpng-1.2.7 */ | 130 /* Added to libpng-1.2.7 */ |
| 131 void PNGAPI | 131 void PNGAPI |
| 132 png_set_add_alpha(png_structp png_ptr, png_uint_32 filler, int filler_loc) | 132 png_set_add_alpha(png_structp png_ptr, png_uint_32 filler, int filler_loc) |
| 133 { | 133 { |
| 134 png_debug(1, "in png_set_add_alpha\n"); | 134 png_debug(1, "in png_set_add_alpha\n"); |
| 135 if(png_ptr == NULL) return; | 135 if (png_ptr == NULL) return; |
| 136 png_set_filler(png_ptr, filler, filler_loc); | 136 png_set_filler(png_ptr, filler, filler_loc); |
| 137 png_ptr->transformations |= PNG_ADD_ALPHA; | 137 png_ptr->transformations |= PNG_ADD_ALPHA; |
| 138 } | 138 } |
| 139 #endif | 139 #endif |
| 140 | 140 |
| 141 #endif | 141 #endif |
| 142 | 142 |
| 143 #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \ | 143 #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \ |
| 144 defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED) | 144 defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED) |
| 145 void PNGAPI | 145 void PNGAPI |
| 146 png_set_swap_alpha(png_structp png_ptr) | 146 png_set_swap_alpha(png_structp png_ptr) |
| 147 { | 147 { |
| 148 png_debug(1, "in png_set_swap_alpha\n"); | 148 png_debug(1, "in png_set_swap_alpha\n"); |
| 149 if(png_ptr == NULL) return; | 149 if (png_ptr == NULL) return; |
| 150 png_ptr->transformations |= PNG_SWAP_ALPHA; | 150 png_ptr->transformations |= PNG_SWAP_ALPHA; |
| 151 } | 151 } |
| 152 #endif | 152 #endif |
| 153 | 153 |
| 154 #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \ | 154 #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \ |
| 155 defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED) | 155 defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED) |
| 156 void PNGAPI | 156 void PNGAPI |
| 157 png_set_invert_alpha(png_structp png_ptr) | 157 png_set_invert_alpha(png_structp png_ptr) |
| 158 { | 158 { |
| 159 png_debug(1, "in png_set_invert_alpha\n"); | 159 png_debug(1, "in png_set_invert_alpha\n"); |
| 160 if(png_ptr == NULL) return; | 160 if (png_ptr == NULL) return; |
| 161 png_ptr->transformations |= PNG_INVERT_ALPHA; | 161 png_ptr->transformations |= PNG_INVERT_ALPHA; |
| 162 } | 162 } |
| 163 #endif | 163 #endif |
| 164 | 164 |
| 165 #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED) | 165 #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED) |
| 166 void PNGAPI | 166 void PNGAPI |
| 167 png_set_invert_mono(png_structp png_ptr) | 167 png_set_invert_mono(png_structp png_ptr) |
| 168 { | 168 { |
| 169 png_debug(1, "in png_set_invert_mono\n"); | 169 png_debug(1, "in png_set_invert_mono\n"); |
| 170 if(png_ptr == NULL) return; | 170 if (png_ptr == NULL) return; |
| 171 png_ptr->transformations |= PNG_INVERT_MONO; | 171 png_ptr->transformations |= PNG_INVERT_MONO; |
| 172 } | 172 } |
| 173 | 173 |
| 174 /* invert monochrome grayscale data */ | 174 /* invert monochrome grayscale data */ |
| 175 void /* PRIVATE */ | 175 void /* PRIVATE */ |
| 176 png_do_invert(png_row_infop row_info, png_bytep row) | 176 png_do_invert(png_row_infop row_info, png_bytep row) |
| 177 { | 177 { |
| 178 png_debug(1, "in png_do_invert\n"); | 178 png_debug(1, "in png_do_invert\n"); |
| 179 /* This test removed from libpng version 1.0.13 and 1.2.0: | 179 /* This test removed from libpng version 1.0.13 and 1.2.0: |
| 180 * if (row_info->bit_depth == 1 && | 180 * if (row_info->bit_depth == 1 && |
| (...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 624 #endif /* PNG_READ_BGR_SUPPORTED or PNG_WRITE_BGR_SUPPORTED */ | 624 #endif /* PNG_READ_BGR_SUPPORTED or PNG_WRITE_BGR_SUPPORTED */ |
| 625 | 625 |
| 626 #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ | 626 #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ |
| 627 defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \ | 627 defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \ |
| 628 defined(PNG_LEGACY_SUPPORTED) | 628 defined(PNG_LEGACY_SUPPORTED) |
| 629 void PNGAPI | 629 void PNGAPI |
| 630 png_set_user_transform_info(png_structp png_ptr, png_voidp | 630 png_set_user_transform_info(png_structp png_ptr, png_voidp |
| 631 user_transform_ptr, int user_transform_depth, int user_transform_channels) | 631 user_transform_ptr, int user_transform_depth, int user_transform_channels) |
| 632 { | 632 { |
| 633 png_debug(1, "in png_set_user_transform_info\n"); | 633 png_debug(1, "in png_set_user_transform_info\n"); |
| 634 if(png_ptr == NULL) return; | 634 if (png_ptr == NULL) return; |
| 635 #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) | 635 #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) |
| 636 png_ptr->user_transform_ptr = user_transform_ptr; | 636 png_ptr->user_transform_ptr = user_transform_ptr; |
| 637 png_ptr->user_transform_depth = (png_byte)user_transform_depth; | 637 png_ptr->user_transform_depth = (png_byte)user_transform_depth; |
| 638 png_ptr->user_transform_channels = (png_byte)user_transform_channels; | 638 png_ptr->user_transform_channels = (png_byte)user_transform_channels; |
| 639 #else | 639 #else |
| 640 if(user_transform_ptr || user_transform_depth || user_transform_channels) | 640 if (user_transform_ptr || user_transform_depth || user_transform_channels) |
| 641 png_warning(png_ptr, | 641 png_warning(png_ptr, |
| 642 "This version of libpng does not support user transform info"); | 642 "This version of libpng does not support user transform info"); |
| 643 #endif | 643 #endif |
| 644 } | 644 } |
| 645 #endif | 645 #endif |
| 646 | 646 |
| 647 /* This function returns a pointer to the user_transform_ptr associated with | 647 /* This function returns a pointer to the user_transform_ptr associated with |
| 648 * the user transform functions. The application should free any memory | 648 * the user transform functions. The application should free any memory |
| 649 * associated with this pointer before png_write_destroy and png_read_destroy | 649 * associated with this pointer before png_write_destroy and png_read_destroy |
| 650 * are called. | 650 * are called. |
| 651 */ | 651 */ |
| 652 png_voidp PNGAPI | 652 png_voidp PNGAPI |
| 653 png_get_user_transform_ptr(png_structp png_ptr) | 653 png_get_user_transform_ptr(png_structp png_ptr) |
| 654 { | 654 { |
| 655 if (png_ptr == NULL) return (NULL); |
| 655 #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) | 656 #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) |
| 656 if (png_ptr == NULL) return (NULL); | |
| 657 return ((png_voidp)png_ptr->user_transform_ptr); | 657 return ((png_voidp)png_ptr->user_transform_ptr); |
| 658 #else | 658 #else |
| 659 return (NULL); | 659 return (NULL); |
| 660 #endif | 660 #endif |
| 661 } | 661 } |
| 662 #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */ | 662 #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */ |
| OLD | NEW |