| OLD | NEW |
| 1 | 1 |
| 2 /* pngset.c - storage of image information into info struct | 2 /* pngset.c - storage of image information into info struct |
| 3 * | 3 * |
| 4 * Last changed in libpng 1.2.37 [June 4, 2009] | 4 * Last changed in libpng 1.2.43 [February 25, 2010] |
| 5 * For conditions of distribution and use, see copyright notice in png.h | 5 * Copyright (c) 1998-2010 Glenn Randers-Pehrson |
| 6 * Copyright (c) 1998-2009 Glenn Randers-Pehrson | |
| 7 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) | 6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) |
| 8 * (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.) |
| 9 * | 8 * |
| 9 * This code is released under the libpng license. |
| 10 * For conditions of distribution and use, see the disclaimer |
| 11 * and license in png.h |
| 12 * |
| 10 * The functions here are used during reads to store data from the file | 13 * The functions here are used during reads to store data from the file |
| 11 * into the info struct, and during writes to store application data | 14 * into the info struct, and during writes to store application data |
| 12 * into the info struct for writing into the file. This abstracts the | 15 * into the info struct for writing into the file. This abstracts the |
| 13 * info struct and allows us to change the structure in the future. | 16 * info struct and allows us to change the structure in the future. |
| 14 */ | 17 */ |
| 15 | 18 |
| 16 #define PNG_INTERNAL | 19 #define PNG_INTERNAL |
| 20 #define PNG_NO_PEDANTIC_WARNINGS |
| 17 #include "png.h" | 21 #include "png.h" |
| 18 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) | 22 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) |
| 19 | 23 |
| 20 #if defined(PNG_bKGD_SUPPORTED) | 24 #ifdef PNG_bKGD_SUPPORTED |
| 21 void PNGAPI | 25 void PNGAPI |
| 22 png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background) | 26 png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background) |
| 23 { | 27 { |
| 24 png_debug1(1, "in %s storage function", "bKGD"); | 28 png_debug1(1, "in %s storage function", "bKGD"); |
| 29 |
| 25 if (png_ptr == NULL || info_ptr == NULL) | 30 if (png_ptr == NULL || info_ptr == NULL) |
| 26 return; | 31 return; |
| 27 | 32 |
| 28 png_memcpy(&(info_ptr->background), background, png_sizeof(png_color_16)); | 33 png_memcpy(&(info_ptr->background), background, png_sizeof(png_color_16)); |
| 29 info_ptr->valid |= PNG_INFO_bKGD; | 34 info_ptr->valid |= PNG_INFO_bKGD; |
| 30 } | 35 } |
| 31 #endif | 36 #endif |
| 32 | 37 |
| 33 #if defined(PNG_cHRM_SUPPORTED) | 38 #ifdef PNG_cHRM_SUPPORTED |
| 34 #ifdef PNG_FLOATING_POINT_SUPPORTED | 39 #ifdef PNG_FLOATING_POINT_SUPPORTED |
| 35 void PNGAPI | 40 void PNGAPI |
| 36 png_set_cHRM(png_structp png_ptr, png_infop info_ptr, | 41 png_set_cHRM(png_structp png_ptr, png_infop info_ptr, |
| 37 double white_x, double white_y, double red_x, double red_y, | 42 double white_x, double white_y, double red_x, double red_y, |
| 38 double green_x, double green_y, double blue_x, double blue_y) | 43 double green_x, double green_y, double blue_x, double blue_y) |
| 39 { | 44 { |
| 40 png_debug1(1, "in %s storage function", "cHRM"); | 45 png_debug1(1, "in %s storage function", "cHRM"); |
| 46 |
| 41 if (png_ptr == NULL || info_ptr == NULL) | 47 if (png_ptr == NULL || info_ptr == NULL) |
| 42 return; | 48 return; |
| 43 | 49 |
| 44 info_ptr->x_white = (float)white_x; | 50 info_ptr->x_white = (float)white_x; |
| 45 info_ptr->y_white = (float)white_y; | 51 info_ptr->y_white = (float)white_y; |
| 46 info_ptr->x_red = (float)red_x; | 52 info_ptr->x_red = (float)red_x; |
| 47 info_ptr->y_red = (float)red_y; | 53 info_ptr->y_red = (float)red_y; |
| 48 info_ptr->x_green = (float)green_x; | 54 info_ptr->x_green = (float)green_x; |
| 49 info_ptr->y_green = (float)green_y; | 55 info_ptr->y_green = (float)green_y; |
| 50 info_ptr->x_blue = (float)blue_x; | 56 info_ptr->x_blue = (float)blue_x; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 64 #endif /* PNG_FLOATING_POINT_SUPPORTED */ | 70 #endif /* PNG_FLOATING_POINT_SUPPORTED */ |
| 65 | 71 |
| 66 #ifdef PNG_FIXED_POINT_SUPPORTED | 72 #ifdef PNG_FIXED_POINT_SUPPORTED |
| 67 void PNGAPI | 73 void PNGAPI |
| 68 png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr, | 74 png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr, |
| 69 png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x, | 75 png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x, |
| 70 png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y, | 76 png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y, |
| 71 png_fixed_point blue_x, png_fixed_point blue_y) | 77 png_fixed_point blue_x, png_fixed_point blue_y) |
| 72 { | 78 { |
| 73 png_debug1(1, "in %s storage function", "cHRM fixed"); | 79 png_debug1(1, "in %s storage function", "cHRM fixed"); |
| 80 |
| 74 if (png_ptr == NULL || info_ptr == NULL) | 81 if (png_ptr == NULL || info_ptr == NULL) |
| 75 return; | 82 return; |
| 76 | 83 |
| 77 #if !defined(PNG_NO_CHECK_cHRM) | 84 #ifdef PNG_CHECK_cHRM_SUPPORTED |
| 78 if (png_check_cHRM_fixed(png_ptr, | 85 if (png_check_cHRM_fixed(png_ptr, |
| 79 white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y)) | 86 white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y)) |
| 80 #endif | 87 #endif |
| 81 { | 88 { |
| 82 info_ptr->int_x_white = white_x; | 89 info_ptr->int_x_white = white_x; |
| 83 info_ptr->int_y_white = white_y; | 90 info_ptr->int_y_white = white_y; |
| 84 info_ptr->int_x_red = red_x; | 91 info_ptr->int_x_red = red_x; |
| 85 info_ptr->int_y_red = red_y; | 92 info_ptr->int_y_red = red_y; |
| 86 info_ptr->int_x_green = green_x; | 93 info_ptr->int_x_green = green_x; |
| 87 info_ptr->int_y_green = green_y; | 94 info_ptr->int_y_green = green_y; |
| 88 info_ptr->int_x_blue = blue_x; | 95 info_ptr->int_x_blue = blue_x; |
| 89 info_ptr->int_y_blue = blue_y; | 96 info_ptr->int_y_blue = blue_y; |
| 90 #ifdef PNG_FLOATING_POINT_SUPPORTED | 97 #ifdef PNG_FLOATING_POINT_SUPPORTED |
| 91 info_ptr->x_white = (float)(white_x/100000.); | 98 info_ptr->x_white = (float)(white_x/100000.); |
| 92 info_ptr->y_white = (float)(white_y/100000.); | 99 info_ptr->y_white = (float)(white_y/100000.); |
| 93 info_ptr->x_red = (float)( red_x/100000.); | 100 info_ptr->x_red = (float)( red_x/100000.); |
| 94 info_ptr->y_red = (float)( red_y/100000.); | 101 info_ptr->y_red = (float)( red_y/100000.); |
| 95 info_ptr->x_green = (float)(green_x/100000.); | 102 info_ptr->x_green = (float)(green_x/100000.); |
| 96 info_ptr->y_green = (float)(green_y/100000.); | 103 info_ptr->y_green = (float)(green_y/100000.); |
| 97 info_ptr->x_blue = (float)( blue_x/100000.); | 104 info_ptr->x_blue = (float)( blue_x/100000.); |
| 98 info_ptr->y_blue = (float)( blue_y/100000.); | 105 info_ptr->y_blue = (float)( blue_y/100000.); |
| 99 #endif | 106 #endif |
| 100 info_ptr->valid |= PNG_INFO_cHRM; | 107 info_ptr->valid |= PNG_INFO_cHRM; |
| 101 } | 108 } |
| 102 } | 109 } |
| 103 #endif /* PNG_FIXED_POINT_SUPPORTED */ | 110 #endif /* PNG_FIXED_POINT_SUPPORTED */ |
| 104 #endif /* PNG_cHRM_SUPPORTED */ | 111 #endif /* PNG_cHRM_SUPPORTED */ |
| 105 | 112 |
| 106 #if defined(PNG_gAMA_SUPPORTED) | 113 #ifdef PNG_gAMA_SUPPORTED |
| 107 #ifdef PNG_FLOATING_POINT_SUPPORTED | 114 #ifdef PNG_FLOATING_POINT_SUPPORTED |
| 108 void PNGAPI | 115 void PNGAPI |
| 109 png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma) | 116 png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma) |
| 110 { | 117 { |
| 111 double png_gamma; | 118 double png_gamma; |
| 119 |
| 112 png_debug1(1, "in %s storage function", "gAMA"); | 120 png_debug1(1, "in %s storage function", "gAMA"); |
| 121 |
| 113 if (png_ptr == NULL || info_ptr == NULL) | 122 if (png_ptr == NULL || info_ptr == NULL) |
| 114 return; | 123 return; |
| 115 | 124 |
| 116 /* Check for overflow */ | 125 /* Check for overflow */ |
| 117 if (file_gamma > 21474.83) | 126 if (file_gamma > 21474.83) |
| 118 { | 127 { |
| 119 png_warning(png_ptr, "Limiting gamma to 21474.83"); | 128 png_warning(png_ptr, "Limiting gamma to 21474.83"); |
| 120 png_gamma=21474.83; | 129 png_gamma=21474.83; |
| 121 } | 130 } |
| 122 else | 131 else |
| 123 png_gamma = file_gamma; | 132 png_gamma = file_gamma; |
| 124 info_ptr->gamma = (float)png_gamma; | 133 info_ptr->gamma = (float)png_gamma; |
| 125 #ifdef PNG_FIXED_POINT_SUPPORTED | 134 #ifdef PNG_FIXED_POINT_SUPPORTED |
| 126 info_ptr->int_gamma = (int)(png_gamma*100000.+.5); | 135 info_ptr->int_gamma = (int)(png_gamma*100000.+.5); |
| 127 #endif | 136 #endif |
| 128 info_ptr->valid |= PNG_INFO_gAMA; | 137 info_ptr->valid |= PNG_INFO_gAMA; |
| 129 if (png_gamma == 0.0) | 138 if (png_gamma == 0.0) |
| 130 png_warning(png_ptr, "Setting gamma=0"); | 139 png_warning(png_ptr, "Setting gamma=0"); |
| 131 } | 140 } |
| 132 #endif | 141 #endif |
| 133 void PNGAPI | 142 void PNGAPI |
| 134 png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point | 143 png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point |
| 135 int_gamma) | 144 int_gamma) |
| 136 { | 145 { |
| 137 png_fixed_point png_gamma; | 146 png_fixed_point png_gamma; |
| 138 | 147 |
| 139 png_debug1(1, "in %s storage function", "gAMA"); | 148 png_debug1(1, "in %s storage function", "gAMA"); |
| 149 |
| 140 if (png_ptr == NULL || info_ptr == NULL) | 150 if (png_ptr == NULL || info_ptr == NULL) |
| 141 return; | 151 return; |
| 142 | 152 |
| 143 if (int_gamma > (png_fixed_point)PNG_UINT_31_MAX) | 153 if (int_gamma > (png_fixed_point)PNG_UINT_31_MAX) |
| 144 { | 154 { |
| 145 png_warning(png_ptr, "Limiting gamma to 21474.83"); | 155 png_warning(png_ptr, "Limiting gamma to 21474.83"); |
| 146 png_gamma=PNG_UINT_31_MAX; | 156 png_gamma=PNG_UINT_31_MAX; |
| 147 } | 157 } |
| 148 else | 158 else |
| 149 { | 159 { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 160 #endif | 170 #endif |
| 161 #ifdef PNG_FIXED_POINT_SUPPORTED | 171 #ifdef PNG_FIXED_POINT_SUPPORTED |
| 162 info_ptr->int_gamma = png_gamma; | 172 info_ptr->int_gamma = png_gamma; |
| 163 #endif | 173 #endif |
| 164 info_ptr->valid |= PNG_INFO_gAMA; | 174 info_ptr->valid |= PNG_INFO_gAMA; |
| 165 if (png_gamma == 0) | 175 if (png_gamma == 0) |
| 166 png_warning(png_ptr, "Setting gamma=0"); | 176 png_warning(png_ptr, "Setting gamma=0"); |
| 167 } | 177 } |
| 168 #endif | 178 #endif |
| 169 | 179 |
| 170 #if defined(PNG_hIST_SUPPORTED) | 180 #ifdef PNG_hIST_SUPPORTED |
| 171 void PNGAPI | 181 void PNGAPI |
| 172 png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist) | 182 png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist) |
| 173 { | 183 { |
| 174 int i; | 184 int i; |
| 175 | 185 |
| 176 png_debug1(1, "in %s storage function", "hIST"); | 186 png_debug1(1, "in %s storage function", "hIST"); |
| 187 |
| 177 if (png_ptr == NULL || info_ptr == NULL) | 188 if (png_ptr == NULL || info_ptr == NULL) |
| 178 return; | 189 return; |
| 190 |
| 179 if (info_ptr->num_palette == 0 || info_ptr->num_palette | 191 if (info_ptr->num_palette == 0 || info_ptr->num_palette |
| 180 > PNG_MAX_PALETTE_LENGTH) | 192 > PNG_MAX_PALETTE_LENGTH) |
| 181 { | 193 { |
| 182 png_warning(png_ptr, | 194 png_warning(png_ptr, |
| 183 "Invalid palette size, hIST allocation skipped."); | 195 "Invalid palette size, hIST allocation skipped."); |
| 184 return; | 196 return; |
| 185 } | 197 } |
| 186 | 198 |
| 187 #ifdef PNG_FREE_ME_SUPPORTED | 199 #ifdef PNG_FREE_ME_SUPPORTED |
| 188 png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0); | 200 png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 211 } | 223 } |
| 212 #endif | 224 #endif |
| 213 | 225 |
| 214 void PNGAPI | 226 void PNGAPI |
| 215 png_set_IHDR(png_structp png_ptr, png_infop info_ptr, | 227 png_set_IHDR(png_structp png_ptr, png_infop info_ptr, |
| 216 png_uint_32 width, png_uint_32 height, int bit_depth, | 228 png_uint_32 width, png_uint_32 height, int bit_depth, |
| 217 int color_type, int interlace_type, int compression_type, | 229 int color_type, int interlace_type, int compression_type, |
| 218 int filter_type) | 230 int filter_type) |
| 219 { | 231 { |
| 220 png_debug1(1, "in %s storage function", "IHDR"); | 232 png_debug1(1, "in %s storage function", "IHDR"); |
| 233 |
| 221 if (png_ptr == NULL || info_ptr == NULL) | 234 if (png_ptr == NULL || info_ptr == NULL) |
| 222 return; | 235 return; |
| 223 | 236 |
| 224 /* Check for width and height valid values */ | |
| 225 if (width == 0 || height == 0) | |
| 226 png_error(png_ptr, "Image width or height is zero in IHDR"); | |
| 227 #ifdef PNG_SET_USER_LIMITS_SUPPORTED | |
| 228 if (width > png_ptr->user_width_max || height > png_ptr->user_height_max) | |
| 229 png_error(png_ptr, "image size exceeds user limits in IHDR"); | |
| 230 #else | |
| 231 if (width > PNG_USER_WIDTH_MAX || height > PNG_USER_HEIGHT_MAX) | |
| 232 png_error(png_ptr, "image size exceeds user limits in IHDR"); | |
| 233 #endif | |
| 234 if (width > PNG_UINT_31_MAX || height > PNG_UINT_31_MAX) | |
| 235 png_error(png_ptr, "Invalid image size in IHDR"); | |
| 236 if ( width > (PNG_UINT_32_MAX | |
| 237 >> 3) /* 8-byte RGBA pixels */ | |
| 238 - 64 /* bigrowbuf hack */ | |
| 239 - 1 /* filter byte */ | |
| 240 - 7*8 /* rounding of width to multiple of 8 pixels */ | |
| 241 - 8) /* extra max_pixel_depth pad */ | |
| 242 png_warning(png_ptr, "Width is too large for libpng to process pixels"); | |
| 243 | |
| 244 /* Check other values */ | |
| 245 if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 && | |
| 246 bit_depth != 8 && bit_depth != 16) | |
| 247 png_error(png_ptr, "Invalid bit depth in IHDR"); | |
| 248 | |
| 249 if (color_type < 0 || color_type == 1 || | |
| 250 color_type == 5 || color_type > 6) | |
| 251 png_error(png_ptr, "Invalid color type in IHDR"); | |
| 252 | |
| 253 if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) || | |
| 254 ((color_type == PNG_COLOR_TYPE_RGB || | |
| 255 color_type == PNG_COLOR_TYPE_GRAY_ALPHA || | |
| 256 color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8)) | |
| 257 png_error(png_ptr, "Invalid color type/bit depth combination in IHDR"); | |
| 258 | |
| 259 if (interlace_type >= PNG_INTERLACE_LAST) | |
| 260 png_error(png_ptr, "Unknown interlace method in IHDR"); | |
| 261 | |
| 262 if (compression_type != PNG_COMPRESSION_TYPE_BASE) | |
| 263 png_error(png_ptr, "Unknown compression method in IHDR"); | |
| 264 | |
| 265 #if defined(PNG_MNG_FEATURES_SUPPORTED) | |
| 266 /* Accept filter_method 64 (intrapixel differencing) only if | |
| 267 * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and | |
| 268 * 2. Libpng did not read a PNG signature (this filter_method is only | |
| 269 * used in PNG datastreams that are embedded in MNG datastreams) and | |
| 270 * 3. The application called png_permit_mng_features with a mask that | |
| 271 * included PNG_FLAG_MNG_FILTER_64 and | |
| 272 * 4. The filter_method is 64 and | |
| 273 * 5. The color_type is RGB or RGBA | |
| 274 */ | |
| 275 if ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&png_ptr->mng_features_permitted) | |
| 276 png_warning(png_ptr, "MNG features are not allowed in a PNG datastream"); | |
| 277 if (filter_type != PNG_FILTER_TYPE_BASE) | |
| 278 { | |
| 279 if (!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && | |
| 280 (filter_type == PNG_INTRAPIXEL_DIFFERENCING) && | |
| 281 ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) && | |
| 282 (color_type == PNG_COLOR_TYPE_RGB || | |
| 283 color_type == PNG_COLOR_TYPE_RGB_ALPHA))) | |
| 284 png_error(png_ptr, "Unknown filter method in IHDR"); | |
| 285 if (png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) | |
| 286 png_warning(png_ptr, "Invalid filter method in IHDR"); | |
| 287 } | |
| 288 #else | |
| 289 if (filter_type != PNG_FILTER_TYPE_BASE) | |
| 290 png_error(png_ptr, "Unknown filter method in IHDR"); | |
| 291 #endif | |
| 292 | |
| 293 info_ptr->width = width; | 237 info_ptr->width = width; |
| 294 info_ptr->height = height; | 238 info_ptr->height = height; |
| 295 info_ptr->bit_depth = (png_byte)bit_depth; | 239 info_ptr->bit_depth = (png_byte)bit_depth; |
| 296 info_ptr->color_type =(png_byte) color_type; | 240 info_ptr->color_type = (png_byte)color_type; |
| 297 info_ptr->compression_type = (png_byte)compression_type; | 241 info_ptr->compression_type = (png_byte)compression_type; |
| 298 info_ptr->filter_type = (png_byte)filter_type; | 242 info_ptr->filter_type = (png_byte)filter_type; |
| 299 info_ptr->interlace_type = (png_byte)interlace_type; | 243 info_ptr->interlace_type = (png_byte)interlace_type; |
| 244 |
| 245 png_check_IHDR (png_ptr, info_ptr->width, info_ptr->height, |
| 246 info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type, |
| 247 info_ptr->compression_type, info_ptr->filter_type); |
| 248 |
| 300 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) | 249 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) |
| 301 info_ptr->channels = 1; | 250 info_ptr->channels = 1; |
| 302 else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR) | 251 else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR) |
| 303 info_ptr->channels = 3; | 252 info_ptr->channels = 3; |
| 304 else | 253 else |
| 305 info_ptr->channels = 1; | 254 info_ptr->channels = 1; |
| 306 if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA) | 255 if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA) |
| 307 info_ptr->channels++; | 256 info_ptr->channels++; |
| 308 info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth); | 257 info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth); |
| 309 | 258 |
| 310 /* Check for potential overflow */ | 259 /* Check for potential overflow */ |
| 311 if (width > (PNG_UINT_32_MAX | 260 if (width > (PNG_UINT_32_MAX |
| 312 >> 3) /* 8-byte RGBA pixels */ | 261 >> 3) /* 8-byte RGBA pixels */ |
| 313 - 64 /* bigrowbuf hack */ | 262 - 64 /* bigrowbuf hack */ |
| 314 - 1 /* filter byte */ | 263 - 1 /* filter byte */ |
| 315 - 7*8 /* rounding of width to multiple of 8 pixels */ | 264 - 7*8 /* rounding of width to multiple of 8 pixels */ |
| 316 - 8) /* extra max_pixel_depth pad */ | 265 - 8) /* extra max_pixel_depth pad */ |
| 317 info_ptr->rowbytes = (png_size_t)0; | 266 info_ptr->rowbytes = (png_size_t)0; |
| 318 else | 267 else |
| 319 info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, width); | 268 info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, width); |
| 320 } | 269 } |
| 321 | 270 |
| 322 #if defined(PNG_oFFs_SUPPORTED) | 271 #ifdef PNG_oFFs_SUPPORTED |
| 323 void PNGAPI | 272 void PNGAPI |
| 324 png_set_oFFs(png_structp png_ptr, png_infop info_ptr, | 273 png_set_oFFs(png_structp png_ptr, png_infop info_ptr, |
| 325 png_int_32 offset_x, png_int_32 offset_y, int unit_type) | 274 png_int_32 offset_x, png_int_32 offset_y, int unit_type) |
| 326 { | 275 { |
| 327 png_debug1(1, "in %s storage function", "oFFs"); | 276 png_debug1(1, "in %s storage function", "oFFs"); |
| 277 |
| 328 if (png_ptr == NULL || info_ptr == NULL) | 278 if (png_ptr == NULL || info_ptr == NULL) |
| 329 return; | 279 return; |
| 330 | 280 |
| 331 info_ptr->x_offset = offset_x; | 281 info_ptr->x_offset = offset_x; |
| 332 info_ptr->y_offset = offset_y; | 282 info_ptr->y_offset = offset_y; |
| 333 info_ptr->offset_unit_type = (png_byte)unit_type; | 283 info_ptr->offset_unit_type = (png_byte)unit_type; |
| 334 info_ptr->valid |= PNG_INFO_oFFs; | 284 info_ptr->valid |= PNG_INFO_oFFs; |
| 335 } | 285 } |
| 336 #endif | 286 #endif |
| 337 | 287 |
| 338 #if defined(PNG_pCAL_SUPPORTED) | 288 #ifdef PNG_pCAL_SUPPORTED |
| 339 void PNGAPI | 289 void PNGAPI |
| 340 png_set_pCAL(png_structp png_ptr, png_infop info_ptr, | 290 png_set_pCAL(png_structp png_ptr, png_infop info_ptr, |
| 341 png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams, | 291 png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams, |
| 342 png_charp units, png_charpp params) | 292 png_charp units, png_charpp params) |
| 343 { | 293 { |
| 344 png_uint_32 length; | 294 png_uint_32 length; |
| 345 int i; | 295 int i; |
| 346 | 296 |
| 347 png_debug1(1, "in %s storage function", "pCAL"); | 297 png_debug1(1, "in %s storage function", "pCAL"); |
| 298 |
| 348 if (png_ptr == NULL || info_ptr == NULL) | 299 if (png_ptr == NULL || info_ptr == NULL) |
| 349 return; | 300 return; |
| 350 | 301 |
| 351 length = png_strlen(purpose) + 1; | 302 length = png_strlen(purpose) + 1; |
| 352 png_debug1(3, "allocating purpose for info (%lu bytes)", | 303 png_debug1(3, "allocating purpose for info (%lu bytes)", |
| 353 (unsigned long)length); | 304 (unsigned long)length); |
| 354 info_ptr->pcal_purpose = (png_charp)png_malloc_warn(png_ptr, length); | 305 info_ptr->pcal_purpose = (png_charp)png_malloc_warn(png_ptr, length); |
| 355 if (info_ptr->pcal_purpose == NULL) | 306 if (info_ptr->pcal_purpose == NULL) |
| 356 { | 307 { |
| 357 png_warning(png_ptr, "Insufficient memory for pCAL purpose."); | 308 png_warning(png_ptr, "Insufficient memory for pCAL purpose."); |
| 358 return; | 309 return; |
| 359 } | 310 } |
| 360 png_memcpy(info_ptr->pcal_purpose, purpose, (png_size_t)length); | 311 png_memcpy(info_ptr->pcal_purpose, purpose, (png_size_t)length); |
| 361 | 312 |
| 362 png_debug(3, "storing X0, X1, type, and nparams in info"); | 313 png_debug(3, "storing X0, X1, type, and nparams in info"); |
| 363 info_ptr->pcal_X0 = X0; | 314 info_ptr->pcal_X0 = X0; |
| 364 info_ptr->pcal_X1 = X1; | 315 info_ptr->pcal_X1 = X1; |
| 365 info_ptr->pcal_type = (png_byte)type; | 316 info_ptr->pcal_type = (png_byte)type; |
| 366 info_ptr->pcal_nparams = (png_byte)nparams; | 317 info_ptr->pcal_nparams = (png_byte)nparams; |
| 367 | 318 |
| 368 length = png_strlen(units) + 1; | 319 length = png_strlen(units) + 1; |
| 369 png_debug1(3, "allocating units for info (%lu bytes)", | 320 png_debug1(3, "allocating units for info (%lu bytes)", |
| 370 (unsigned long)length); | 321 (unsigned long)length); |
| 371 info_ptr->pcal_units = (png_charp)png_malloc_warn(png_ptr, length); | 322 info_ptr->pcal_units = (png_charp)png_malloc_warn(png_ptr, length); |
| 372 if (info_ptr->pcal_units == NULL) | 323 if (info_ptr->pcal_units == NULL) |
| 373 { | 324 { |
| 374 png_warning(png_ptr, "Insufficient memory for pCAL units."); | 325 png_warning(png_ptr, "Insufficient memory for pCAL units."); |
| 375 return; | 326 return; |
| 376 } | 327 } |
| 377 png_memcpy(info_ptr->pcal_units, units, (png_size_t)length); | 328 png_memcpy(info_ptr->pcal_units, units, (png_size_t)length); |
| 378 | 329 |
| 379 info_ptr->pcal_params = (png_charpp)png_malloc_warn(png_ptr, | 330 info_ptr->pcal_params = (png_charpp)png_malloc_warn(png_ptr, |
| 380 (png_uint_32)((nparams + 1) * png_sizeof(png_charp))); | 331 (png_uint_32)((nparams + 1) * png_sizeof(png_charp))); |
| 381 if (info_ptr->pcal_params == NULL) | 332 if (info_ptr->pcal_params == NULL) |
| 382 { | 333 { |
| 383 png_warning(png_ptr, "Insufficient memory for pCAL params."); | 334 png_warning(png_ptr, "Insufficient memory for pCAL params."); |
| 384 return; | 335 return; |
| 385 } | 336 } |
| 386 | 337 |
| 387 png_memset(info_ptr->pcal_params, 0, (nparams + 1) * png_sizeof(png_charp)); | 338 png_memset(info_ptr->pcal_params, 0, (nparams + 1) * png_sizeof(png_charp)); |
| 388 | 339 |
| 389 for (i = 0; i < nparams; i++) | 340 for (i = 0; i < nparams; i++) |
| 390 { | 341 { |
| 391 length = png_strlen(params[i]) + 1; | 342 length = png_strlen(params[i]) + 1; |
| 392 png_debug2(3, "allocating parameter %d for info (%lu bytes)", i, | 343 png_debug2(3, "allocating parameter %d for info (%lu bytes)", i, |
| 393 (unsigned long)length); | 344 (unsigned long)length); |
| 394 info_ptr->pcal_params[i] = (png_charp)png_malloc_warn(png_ptr, length); | 345 info_ptr->pcal_params[i] = (png_charp)png_malloc_warn(png_ptr, length); |
| 395 if (info_ptr->pcal_params[i] == NULL) | 346 if (info_ptr->pcal_params[i] == NULL) |
| 396 { | 347 { |
| 397 png_warning(png_ptr, "Insufficient memory for pCAL parameter."); | 348 png_warning(png_ptr, "Insufficient memory for pCAL parameter."); |
| 398 return; | 349 return; |
| 399 } | 350 } |
| 400 png_memcpy(info_ptr->pcal_params[i], params[i], (png_size_t)length); | 351 png_memcpy(info_ptr->pcal_params[i], params[i], (png_size_t)length); |
| 401 } | 352 } |
| 402 | 353 |
| 403 info_ptr->valid |= PNG_INFO_pCAL; | 354 info_ptr->valid |= PNG_INFO_pCAL; |
| 404 #ifdef PNG_FREE_ME_SUPPORTED | 355 #ifdef PNG_FREE_ME_SUPPORTED |
| 405 info_ptr->free_me |= PNG_FREE_PCAL; | 356 info_ptr->free_me |= PNG_FREE_PCAL; |
| 406 #endif | 357 #endif |
| 407 } | 358 } |
| 408 #endif | 359 #endif |
| 409 | 360 |
| 410 #if defined(PNG_READ_sCAL_SUPPORTED) || defined(PNG_WRITE_sCAL_SUPPORTED) | 361 #if defined(PNG_READ_sCAL_SUPPORTED) || defined(PNG_WRITE_sCAL_SUPPORTED) |
| 411 #ifdef PNG_FLOATING_POINT_SUPPORTED | 362 #ifdef PNG_FLOATING_POINT_SUPPORTED |
| 412 void PNGAPI | 363 void PNGAPI |
| 413 png_set_sCAL(png_structp png_ptr, png_infop info_ptr, | 364 png_set_sCAL(png_structp png_ptr, png_infop info_ptr, |
| 414 int unit, double width, double height) | 365 int unit, double width, double height) |
| 415 { | 366 { |
| 416 png_debug1(1, "in %s storage function", "sCAL"); | 367 png_debug1(1, "in %s storage function", "sCAL"); |
| 368 |
| 417 if (png_ptr == NULL || info_ptr == NULL) | 369 if (png_ptr == NULL || info_ptr == NULL) |
| 418 return; | 370 return; |
| 419 | 371 |
| 420 info_ptr->scal_unit = (png_byte)unit; | 372 info_ptr->scal_unit = (png_byte)unit; |
| 421 info_ptr->scal_pixel_width = width; | 373 info_ptr->scal_pixel_width = width; |
| 422 info_ptr->scal_pixel_height = height; | 374 info_ptr->scal_pixel_height = height; |
| 423 | 375 |
| 424 info_ptr->valid |= PNG_INFO_sCAL; | 376 info_ptr->valid |= PNG_INFO_sCAL; |
| 425 } | 377 } |
| 426 #else | 378 #else |
| 427 #ifdef PNG_FIXED_POINT_SUPPORTED | 379 #ifdef PNG_FIXED_POINT_SUPPORTED |
| 428 void PNGAPI | 380 void PNGAPI |
| 429 png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr, | 381 png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr, |
| 430 int unit, png_charp swidth, png_charp sheight) | 382 int unit, png_charp swidth, png_charp sheight) |
| 431 { | 383 { |
| 432 png_uint_32 length; | 384 png_uint_32 length; |
| 433 | 385 |
| 434 png_debug1(1, "in %s storage function", "sCAL"); | 386 png_debug1(1, "in %s storage function", "sCAL"); |
| 387 |
| 435 if (png_ptr == NULL || info_ptr == NULL) | 388 if (png_ptr == NULL || info_ptr == NULL) |
| 436 return; | 389 return; |
| 437 | 390 |
| 438 info_ptr->scal_unit = (png_byte)unit; | 391 info_ptr->scal_unit = (png_byte)unit; |
| 439 | 392 |
| 440 length = png_strlen(swidth) + 1; | 393 length = png_strlen(swidth) + 1; |
| 441 png_debug1(3, "allocating unit for info (%u bytes)", | 394 png_debug1(3, "allocating unit for info (%u bytes)", |
| 442 (unsigned int)length); | 395 (unsigned int)length); |
| 443 info_ptr->scal_s_width = (png_charp)png_malloc_warn(png_ptr, length); | 396 info_ptr->scal_s_width = (png_charp)png_malloc_warn(png_ptr, length); |
| 444 if (info_ptr->scal_s_width == NULL) | 397 if (info_ptr->scal_s_width == NULL) |
| 445 { | 398 { |
| 446 png_warning(png_ptr, | 399 png_warning(png_ptr, |
| 447 "Memory allocation failed while processing sCAL."); | 400 "Memory allocation failed while processing sCAL."); |
| 448 return; | 401 return; |
| 449 } | 402 } |
| 450 png_memcpy(info_ptr->scal_s_width, swidth, (png_size_t)length); | 403 png_memcpy(info_ptr->scal_s_width, swidth, (png_size_t)length); |
| 451 | 404 |
| 452 length = png_strlen(sheight) + 1; | 405 length = png_strlen(sheight) + 1; |
| 453 png_debug1(3, "allocating unit for info (%u bytes)", | 406 png_debug1(3, "allocating unit for info (%u bytes)", |
| 454 (unsigned int)length); | 407 (unsigned int)length); |
| 455 info_ptr->scal_s_height = (png_charp)png_malloc_warn(png_ptr, length); | 408 info_ptr->scal_s_height = (png_charp)png_malloc_warn(png_ptr, length); |
| 456 if (info_ptr->scal_s_height == NULL) | 409 if (info_ptr->scal_s_height == NULL) |
| 457 { | 410 { |
| 458 png_free (png_ptr, info_ptr->scal_s_width); | 411 png_free (png_ptr, info_ptr->scal_s_width); |
| 459 info_ptr->scal_s_width = NULL; | 412 info_ptr->scal_s_width = NULL; |
| 460 png_warning(png_ptr, | 413 png_warning(png_ptr, |
| 461 "Memory allocation failed while processing sCAL."); | 414 "Memory allocation failed while processing sCAL."); |
| 462 return; | 415 return; |
| 463 } | 416 } |
| 464 png_memcpy(info_ptr->scal_s_height, sheight, (png_size_t)length); | 417 png_memcpy(info_ptr->scal_s_height, sheight, (png_size_t)length); |
| 465 info_ptr->valid |= PNG_INFO_sCAL; | 418 info_ptr->valid |= PNG_INFO_sCAL; |
| 466 #ifdef PNG_FREE_ME_SUPPORTED | 419 #ifdef PNG_FREE_ME_SUPPORTED |
| 467 info_ptr->free_me |= PNG_FREE_SCAL; | 420 info_ptr->free_me |= PNG_FREE_SCAL; |
| 468 #endif | 421 #endif |
| 469 } | 422 } |
| 470 #endif | 423 #endif |
| 471 #endif | 424 #endif |
| 472 #endif | 425 #endif |
| 473 | 426 |
| 474 #if defined(PNG_pHYs_SUPPORTED) | 427 #ifdef PNG_pHYs_SUPPORTED |
| 475 void PNGAPI | 428 void PNGAPI |
| 476 png_set_pHYs(png_structp png_ptr, png_infop info_ptr, | 429 png_set_pHYs(png_structp png_ptr, png_infop info_ptr, |
| 477 png_uint_32 res_x, png_uint_32 res_y, int unit_type) | 430 png_uint_32 res_x, png_uint_32 res_y, int unit_type) |
| 478 { | 431 { |
| 479 png_debug1(1, "in %s storage function", "pHYs"); | 432 png_debug1(1, "in %s storage function", "pHYs"); |
| 433 |
| 480 if (png_ptr == NULL || info_ptr == NULL) | 434 if (png_ptr == NULL || info_ptr == NULL) |
| 481 return; | 435 return; |
| 482 | 436 |
| 483 info_ptr->x_pixels_per_unit = res_x; | 437 info_ptr->x_pixels_per_unit = res_x; |
| 484 info_ptr->y_pixels_per_unit = res_y; | 438 info_ptr->y_pixels_per_unit = res_y; |
| 485 info_ptr->phys_unit_type = (png_byte)unit_type; | 439 info_ptr->phys_unit_type = (png_byte)unit_type; |
| 486 info_ptr->valid |= PNG_INFO_pHYs; | 440 info_ptr->valid |= PNG_INFO_pHYs; |
| 487 } | 441 } |
| 488 #endif | 442 #endif |
| 489 | 443 |
| 490 void PNGAPI | 444 void PNGAPI |
| 491 png_set_PLTE(png_structp png_ptr, png_infop info_ptr, | 445 png_set_PLTE(png_structp png_ptr, png_infop info_ptr, |
| 492 png_colorp palette, int num_palette) | 446 png_colorp palette, int num_palette) |
| 493 { | 447 { |
| 494 | 448 |
| 495 png_debug1(1, "in %s storage function", "PLTE"); | 449 png_debug1(1, "in %s storage function", "PLTE"); |
| 450 |
| 496 if (png_ptr == NULL || info_ptr == NULL) | 451 if (png_ptr == NULL || info_ptr == NULL) |
| 497 return; | 452 return; |
| 498 | 453 |
| 499 if (num_palette < 0 || num_palette > PNG_MAX_PALETTE_LENGTH) | 454 if (num_palette < 0 || num_palette > PNG_MAX_PALETTE_LENGTH) |
| 500 { | 455 { |
| 501 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) | 456 if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) |
| 502 png_error(png_ptr, "Invalid palette length"); | 457 png_error(png_ptr, "Invalid palette length"); |
| 503 else | 458 else |
| 504 { | 459 { |
| 505 png_warning(png_ptr, "Invalid palette length"); | 460 png_warning(png_ptr, "Invalid palette length"); |
| 506 return; | 461 return; |
| 507 } | 462 } |
| 508 } | 463 } |
| 509 | 464 |
| 510 /* | 465 /* It may not actually be necessary to set png_ptr->palette here; |
| 511 * It may not actually be necessary to set png_ptr->palette here; | |
| 512 * we do it for backward compatibility with the way the png_handle_tRNS | 466 * we do it for backward compatibility with the way the png_handle_tRNS |
| 513 * function used to do the allocation. | 467 * function used to do the allocation. |
| 514 */ | 468 */ |
| 515 #ifdef PNG_FREE_ME_SUPPORTED | 469 #ifdef PNG_FREE_ME_SUPPORTED |
| 516 png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0); | 470 png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0); |
| 517 #endif | 471 #endif |
| 518 | 472 |
| 519 /* Changed in libpng-1.2.1 to allocate PNG_MAX_PALETTE_LENGTH instead | 473 /* Changed in libpng-1.2.1 to allocate PNG_MAX_PALETTE_LENGTH instead |
| 520 * of num_palette entries, in case of an invalid PNG file that has | 474 * of num_palette entries, in case of an invalid PNG file that has |
| 521 * too-large sample values. | 475 * too-large sample values. |
| 522 */ | 476 */ |
| 523 png_ptr->palette = (png_colorp)png_malloc(png_ptr, | 477 png_ptr->palette = (png_colorp)png_calloc(png_ptr, |
| 524 PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color)); | 478 PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color)); |
| 525 png_memset(png_ptr->palette, 0, PNG_MAX_PALETTE_LENGTH * | |
| 526 png_sizeof(png_color)); | |
| 527 png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof(png_color)); | 479 png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof(png_color)); |
| 528 info_ptr->palette = png_ptr->palette; | 480 info_ptr->palette = png_ptr->palette; |
| 529 info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette; | 481 info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette; |
| 530 | 482 |
| 531 #ifdef PNG_FREE_ME_SUPPORTED | 483 #ifdef PNG_FREE_ME_SUPPORTED |
| 532 info_ptr->free_me |= PNG_FREE_PLTE; | 484 info_ptr->free_me |= PNG_FREE_PLTE; |
| 533 #else | 485 #else |
| 534 png_ptr->flags |= PNG_FLAG_FREE_PLTE; | 486 png_ptr->flags |= PNG_FLAG_FREE_PLTE; |
| 535 #endif | 487 #endif |
| 536 | 488 |
| 537 info_ptr->valid |= PNG_INFO_PLTE; | 489 info_ptr->valid |= PNG_INFO_PLTE; |
| 538 } | 490 } |
| 539 | 491 |
| 540 #if defined(PNG_sBIT_SUPPORTED) | 492 #ifdef PNG_sBIT_SUPPORTED |
| 541 void PNGAPI | 493 void PNGAPI |
| 542 png_set_sBIT(png_structp png_ptr, png_infop info_ptr, | 494 png_set_sBIT(png_structp png_ptr, png_infop info_ptr, |
| 543 png_color_8p sig_bit) | 495 png_color_8p sig_bit) |
| 544 { | 496 { |
| 545 png_debug1(1, "in %s storage function", "sBIT"); | 497 png_debug1(1, "in %s storage function", "sBIT"); |
| 498 |
| 546 if (png_ptr == NULL || info_ptr == NULL) | 499 if (png_ptr == NULL || info_ptr == NULL) |
| 547 return; | 500 return; |
| 548 | 501 |
| 549 png_memcpy(&(info_ptr->sig_bit), sig_bit, png_sizeof(png_color_8)); | 502 png_memcpy(&(info_ptr->sig_bit), sig_bit, png_sizeof(png_color_8)); |
| 550 info_ptr->valid |= PNG_INFO_sBIT; | 503 info_ptr->valid |= PNG_INFO_sBIT; |
| 551 } | 504 } |
| 552 #endif | 505 #endif |
| 553 | 506 |
| 554 #if defined(PNG_sRGB_SUPPORTED) | 507 #ifdef PNG_sRGB_SUPPORTED |
| 555 void PNGAPI | 508 void PNGAPI |
| 556 png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int intent) | 509 png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int intent) |
| 557 { | 510 { |
| 558 png_debug1(1, "in %s storage function", "sRGB"); | 511 png_debug1(1, "in %s storage function", "sRGB"); |
| 512 |
| 559 if (png_ptr == NULL || info_ptr == NULL) | 513 if (png_ptr == NULL || info_ptr == NULL) |
| 560 return; | 514 return; |
| 561 | 515 |
| 562 info_ptr->srgb_intent = (png_byte)intent; | 516 info_ptr->srgb_intent = (png_byte)intent; |
| 563 info_ptr->valid |= PNG_INFO_sRGB; | 517 info_ptr->valid |= PNG_INFO_sRGB; |
| 564 } | 518 } |
| 565 | 519 |
| 566 void PNGAPI | 520 void PNGAPI |
| 567 png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr, | 521 png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr, |
| 568 int intent) | 522 int intent) |
| 569 { | 523 { |
| 570 #if defined(PNG_gAMA_SUPPORTED) | 524 #ifdef PNG_gAMA_SUPPORTED |
| 571 #ifdef PNG_FLOATING_POINT_SUPPORTED | 525 #ifdef PNG_FLOATING_POINT_SUPPORTED |
| 572 float file_gamma; | 526 float file_gamma; |
| 573 #endif | 527 #endif |
| 574 #ifdef PNG_FIXED_POINT_SUPPORTED | 528 #ifdef PNG_FIXED_POINT_SUPPORTED |
| 575 png_fixed_point int_file_gamma; | 529 png_fixed_point int_file_gamma; |
| 576 #endif | 530 #endif |
| 577 #endif | 531 #endif |
| 578 #if defined(PNG_cHRM_SUPPORTED) | 532 #ifdef PNG_cHRM_SUPPORTED |
| 579 #ifdef PNG_FLOATING_POINT_SUPPORTED | 533 #ifdef PNG_FLOATING_POINT_SUPPORTED |
| 580 float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y; | 534 float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y; |
| 581 #endif | 535 #endif |
| 582 png_fixed_point int_white_x, int_white_y, int_red_x, int_red_y, int_green_x, | 536 png_fixed_point int_white_x, int_white_y, int_red_x, int_red_y, int_green_x, |
| 583 int_green_y, int_blue_x, int_blue_y; | 537 int_green_y, int_blue_x, int_blue_y; |
| 584 #endif | 538 #endif |
| 585 png_debug1(1, "in %s storage function", "sRGB_gAMA_and_cHRM"); | 539 png_debug1(1, "in %s storage function", "sRGB_gAMA_and_cHRM"); |
| 540 |
| 586 if (png_ptr == NULL || info_ptr == NULL) | 541 if (png_ptr == NULL || info_ptr == NULL) |
| 587 return; | 542 return; |
| 588 | 543 |
| 589 png_set_sRGB(png_ptr, info_ptr, intent); | 544 png_set_sRGB(png_ptr, info_ptr, intent); |
| 590 | 545 |
| 591 #if defined(PNG_gAMA_SUPPORTED) | 546 #ifdef PNG_gAMA_SUPPORTED |
| 592 #ifdef PNG_FLOATING_POINT_SUPPORTED | 547 #ifdef PNG_FLOATING_POINT_SUPPORTED |
| 593 file_gamma = (float).45455; | 548 file_gamma = (float).45455; |
| 594 png_set_gAMA(png_ptr, info_ptr, file_gamma); | 549 png_set_gAMA(png_ptr, info_ptr, file_gamma); |
| 595 #endif | 550 #endif |
| 596 #ifdef PNG_FIXED_POINT_SUPPORTED | 551 #ifdef PNG_FIXED_POINT_SUPPORTED |
| 597 int_file_gamma = 45455L; | 552 int_file_gamma = 45455L; |
| 598 png_set_gAMA_fixed(png_ptr, info_ptr, int_file_gamma); | 553 png_set_gAMA_fixed(png_ptr, info_ptr, int_file_gamma); |
| 599 #endif | 554 #endif |
| 600 #endif | 555 #endif |
| 601 | 556 |
| 602 #if defined(PNG_cHRM_SUPPORTED) | 557 #ifdef PNG_cHRM_SUPPORTED |
| 603 int_white_x = 31270L; | 558 int_white_x = 31270L; |
| 604 int_white_y = 32900L; | 559 int_white_y = 32900L; |
| 605 int_red_x = 64000L; | 560 int_red_x = 64000L; |
| 606 int_red_y = 33000L; | 561 int_red_y = 33000L; |
| 607 int_green_x = 30000L; | 562 int_green_x = 30000L; |
| 608 int_green_y = 60000L; | 563 int_green_y = 60000L; |
| 609 int_blue_x = 15000L; | 564 int_blue_x = 15000L; |
| 610 int_blue_y = 6000L; | 565 int_blue_y = 6000L; |
| 611 | 566 |
| 612 #ifdef PNG_FLOATING_POINT_SUPPORTED | 567 #ifdef PNG_FLOATING_POINT_SUPPORTED |
| 613 white_x = (float).3127; | 568 white_x = (float).3127; |
| 614 white_y = (float).3290; | 569 white_y = (float).3290; |
| 615 red_x = (float).64; | 570 red_x = (float).64; |
| 616 red_y = (float).33; | 571 red_y = (float).33; |
| 617 green_x = (float).30; | 572 green_x = (float).30; |
| 618 green_y = (float).60; | 573 green_y = (float).60; |
| 619 blue_x = (float).15; | 574 blue_x = (float).15; |
| 620 blue_y = (float).06; | 575 blue_y = (float).06; |
| 621 #endif | 576 #endif |
| 622 | 577 |
| 623 #if !defined(PNG_NO_CHECK_cHRM) | 578 #ifdef PNG_FIXED_POINT_SUPPORTED |
| 624 if (png_check_cHRM_fixed(png_ptr, | 579 png_set_cHRM_fixed(png_ptr, info_ptr, |
| 625 int_white_x, int_white_y, int_red_x, int_red_y, int_green_x, | 580 int_white_x, int_white_y, int_red_x, int_red_y, int_green_x, |
| 626 int_green_y, int_blue_x, int_blue_y)) | 581 int_green_y, int_blue_x, int_blue_y); |
| 627 #endif | |
| 628 { | |
| 629 #ifdef PNG_FIXED_POINT_SUPPORTED | |
| 630 png_set_cHRM_fixed(png_ptr, info_ptr, | |
| 631 int_white_x, int_white_y, int_red_x, int_red_y, int_green_x, | |
| 632 int_green_y, int_blue_x, int_blue_y); | |
| 633 #endif | 582 #endif |
| 634 #ifdef PNG_FLOATING_POINT_SUPPORTED | 583 #ifdef PNG_FLOATING_POINT_SUPPORTED |
| 635 png_set_cHRM(png_ptr, info_ptr, | 584 png_set_cHRM(png_ptr, info_ptr, |
| 636 white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y); | 585 white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y); |
| 637 #endif | 586 #endif |
| 638 } | |
| 639 #endif /* cHRM */ | 587 #endif /* cHRM */ |
| 640 } | 588 } |
| 641 #endif /* sRGB */ | 589 #endif /* sRGB */ |
| 642 | 590 |
| 643 | 591 |
| 644 #if defined(PNG_iCCP_SUPPORTED) | 592 #ifdef PNG_iCCP_SUPPORTED |
| 645 void PNGAPI | 593 void PNGAPI |
| 646 png_set_iCCP(png_structp png_ptr, png_infop info_ptr, | 594 png_set_iCCP(png_structp png_ptr, png_infop info_ptr, |
| 647 png_charp name, int compression_type, | 595 png_charp name, int compression_type, |
| 648 png_charp profile, png_uint_32 proflen) | 596 png_charp profile, png_uint_32 proflen) |
| 649 { | 597 { |
| 650 png_charp new_iccp_name; | 598 png_charp new_iccp_name; |
| 651 png_charp new_iccp_profile; | 599 png_charp new_iccp_profile; |
| 652 png_uint_32 length; | 600 png_uint_32 length; |
| 653 | 601 |
| 654 png_debug1(1, "in %s storage function", "iCCP"); | 602 png_debug1(1, "in %s storage function", "iCCP"); |
| 603 |
| 655 if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL) | 604 if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL) |
| 656 return; | 605 return; |
| 657 | 606 |
| 658 length = png_strlen(name)+1; | 607 length = png_strlen(name)+1; |
| 659 new_iccp_name = (png_charp)png_malloc_warn(png_ptr, length); | 608 new_iccp_name = (png_charp)png_malloc_warn(png_ptr, length); |
| 660 if (new_iccp_name == NULL) | 609 if (new_iccp_name == NULL) |
| 661 { | 610 { |
| 662 png_warning(png_ptr, "Insufficient memory to process iCCP chunk."); | 611 png_warning(png_ptr, "Insufficient memory to process iCCP chunk."); |
| 663 return; | 612 return; |
| 664 } | 613 } |
| 665 png_memcpy(new_iccp_name, name, length); | 614 png_memcpy(new_iccp_name, name, length); |
| 666 new_iccp_profile = (png_charp)png_malloc_warn(png_ptr, proflen); | 615 new_iccp_profile = (png_charp)png_malloc_warn(png_ptr, proflen); |
| 667 if (new_iccp_profile == NULL) | 616 if (new_iccp_profile == NULL) |
| 668 { | 617 { |
| 669 png_free (png_ptr, new_iccp_name); | 618 png_free (png_ptr, new_iccp_name); |
| 670 png_warning(png_ptr, | 619 png_warning(png_ptr, |
| 671 "Insufficient memory to process iCCP profile."); | 620 "Insufficient memory to process iCCP profile."); |
| 672 return; | 621 return; |
| 673 } | 622 } |
| 674 png_memcpy(new_iccp_profile, profile, (png_size_t)proflen); | 623 png_memcpy(new_iccp_profile, profile, (png_size_t)proflen); |
| 675 | 624 |
| 676 png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, 0); | 625 png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, 0); |
| 677 | 626 |
| 678 info_ptr->iccp_proflen = proflen; | 627 info_ptr->iccp_proflen = proflen; |
| 679 info_ptr->iccp_name = new_iccp_name; | 628 info_ptr->iccp_name = new_iccp_name; |
| 680 info_ptr->iccp_profile = new_iccp_profile; | 629 info_ptr->iccp_profile = new_iccp_profile; |
| 681 /* Compression is always zero but is here so the API and info structure | 630 /* Compression is always zero but is here so the API and info structure |
| 682 * does not have to change if we introduce multiple compression types */ | 631 * does not have to change if we introduce multiple compression types |
| 632 */ |
| 683 info_ptr->iccp_compression = (png_byte)compression_type; | 633 info_ptr->iccp_compression = (png_byte)compression_type; |
| 684 #ifdef PNG_FREE_ME_SUPPORTED | 634 #ifdef PNG_FREE_ME_SUPPORTED |
| 685 info_ptr->free_me |= PNG_FREE_ICCP; | 635 info_ptr->free_me |= PNG_FREE_ICCP; |
| 686 #endif | 636 #endif |
| 687 info_ptr->valid |= PNG_INFO_iCCP; | 637 info_ptr->valid |= PNG_INFO_iCCP; |
| 688 } | 638 } |
| 689 #endif | 639 #endif |
| 690 | 640 |
| 691 #if defined(PNG_TEXT_SUPPORTED) | 641 #ifdef PNG_TEXT_SUPPORTED |
| 692 void PNGAPI | 642 void PNGAPI |
| 693 png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr, | 643 png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr, |
| 694 int num_text) | 644 int num_text) |
| 695 { | 645 { |
| 696 int ret; | 646 int ret; |
| 697 ret = png_set_text_2(png_ptr, info_ptr, text_ptr, num_text); | 647 ret = png_set_text_2(png_ptr, info_ptr, text_ptr, num_text); |
| 698 if (ret) | 648 if (ret) |
| 699 png_error(png_ptr, "Insufficient memory to store text"); | 649 png_error(png_ptr, "Insufficient memory to store text"); |
| 700 } | 650 } |
| 701 | 651 |
| 702 int /* PRIVATE */ | 652 int /* PRIVATE */ |
| 703 png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr, | 653 png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr, |
| 704 int num_text) | 654 int num_text) |
| 705 { | 655 { |
| 706 int i; | 656 int i; |
| 707 | 657 |
| 708 png_debug1(1, "in %s storage function", (png_ptr->chunk_name[0] == '\0' ? | 658 png_debug1(1, "in %s storage function", ((png_ptr == NULL || |
| 659 png_ptr->chunk_name[0] == '\0') ? |
| 709 "text" : (png_const_charp)png_ptr->chunk_name)); | 660 "text" : (png_const_charp)png_ptr->chunk_name)); |
| 710 | 661 |
| 711 if (png_ptr == NULL || info_ptr == NULL || num_text == 0) | 662 if (png_ptr == NULL || info_ptr == NULL || num_text == 0) |
| 712 return(0); | 663 return(0); |
| 713 | 664 |
| 714 /* Make sure we have enough space in the "text" array in info_struct | 665 /* Make sure we have enough space in the "text" array in info_struct |
| 715 * to hold all of the incoming text_ptr objects. | 666 * to hold all of the incoming text_ptr objects. |
| 716 */ | 667 */ |
| 717 if (info_ptr->num_text + num_text > info_ptr->max_text) | 668 if (info_ptr->num_text + num_text > info_ptr->max_text) |
| 718 { | 669 { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 759 if (text_ptr[i].key == NULL) | 710 if (text_ptr[i].key == NULL) |
| 760 continue; | 711 continue; |
| 761 | 712 |
| 762 key_len = png_strlen(text_ptr[i].key); | 713 key_len = png_strlen(text_ptr[i].key); |
| 763 | 714 |
| 764 if (text_ptr[i].compression <= 0) | 715 if (text_ptr[i].compression <= 0) |
| 765 { | 716 { |
| 766 lang_len = 0; | 717 lang_len = 0; |
| 767 lang_key_len = 0; | 718 lang_key_len = 0; |
| 768 } | 719 } |
| 720 |
| 769 else | 721 else |
| 770 #ifdef PNG_iTXt_SUPPORTED | 722 #ifdef PNG_iTXt_SUPPORTED |
| 771 { | 723 { |
| 772 /* Set iTXt data */ | 724 /* Set iTXt data */ |
| 725 |
| 773 if (text_ptr[i].lang != NULL) | 726 if (text_ptr[i].lang != NULL) |
| 774 lang_len = png_strlen(text_ptr[i].lang); | 727 lang_len = png_strlen(text_ptr[i].lang); |
| 775 else | 728 else |
| 776 lang_len = 0; | 729 lang_len = 0; |
| 777 if (text_ptr[i].lang_key != NULL) | 730 if (text_ptr[i].lang_key != NULL) |
| 778 lang_key_len = png_strlen(text_ptr[i].lang_key); | 731 lang_key_len = png_strlen(text_ptr[i].lang_key); |
| 779 else | 732 else |
| 780 lang_key_len = 0; | 733 lang_key_len = 0; |
| 781 } | 734 } |
| 782 #else | 735 #else /* PNG_iTXt_SUPPORTED */ |
| 783 { | 736 { |
| 784 png_warning(png_ptr, "iTXt chunk not supported."); | 737 png_warning(png_ptr, "iTXt chunk not supported."); |
| 785 continue; | 738 continue; |
| 786 } | 739 } |
| 787 #endif | 740 #endif |
| 788 | 741 |
| 789 if (text_ptr[i].text == NULL || text_ptr[i].text[0] == '\0') | 742 if (text_ptr[i].text == NULL || text_ptr[i].text[0] == '\0') |
| 790 { | 743 { |
| 791 text_length = 0; | 744 text_length = 0; |
| 792 #ifdef PNG_iTXt_SUPPORTED | 745 #ifdef PNG_iTXt_SUPPORTED |
| 793 if (text_ptr[i].compression > 0) | 746 if (text_ptr[i].compression > 0) |
| 794 textp->compression = PNG_ITXT_COMPRESSION_NONE; | 747 textp->compression = PNG_ITXT_COMPRESSION_NONE; |
| 795 else | 748 else |
| 796 #endif | 749 #endif |
| 797 textp->compression = PNG_TEXT_COMPRESSION_NONE; | 750 textp->compression = PNG_TEXT_COMPRESSION_NONE; |
| 798 } | 751 } |
| 752 |
| 799 else | 753 else |
| 800 { | 754 { |
| 801 text_length = png_strlen(text_ptr[i].text); | 755 text_length = png_strlen(text_ptr[i].text); |
| 802 textp->compression = text_ptr[i].compression; | 756 textp->compression = text_ptr[i].compression; |
| 803 } | 757 } |
| 804 | 758 |
| 805 textp->key = (png_charp)png_malloc_warn(png_ptr, | 759 textp->key = (png_charp)png_malloc_warn(png_ptr, |
| 806 (png_uint_32) | 760 (png_uint_32) |
| 807 (key_len + text_length + lang_len + lang_key_len + 4)); | 761 (key_len + text_length + lang_len + lang_key_len + 4)); |
| 808 if (textp->key == NULL) | 762 if (textp->key == NULL) |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 840 *(textp->text + text_length) = '\0'; | 794 *(textp->text + text_length) = '\0'; |
| 841 | 795 |
| 842 #ifdef PNG_iTXt_SUPPORTED | 796 #ifdef PNG_iTXt_SUPPORTED |
| 843 if (textp->compression > 0) | 797 if (textp->compression > 0) |
| 844 { | 798 { |
| 845 textp->text_length = 0; | 799 textp->text_length = 0; |
| 846 textp->itxt_length = text_length; | 800 textp->itxt_length = text_length; |
| 847 } | 801 } |
| 848 else | 802 else |
| 849 #endif | 803 #endif |
| 804 |
| 850 { | 805 { |
| 851 textp->text_length = text_length; | 806 textp->text_length = text_length; |
| 852 #ifdef PNG_iTXt_SUPPORTED | 807 #ifdef PNG_iTXt_SUPPORTED |
| 853 textp->itxt_length = 0; | 808 textp->itxt_length = 0; |
| 854 #endif | 809 #endif |
| 855 } | 810 } |
| 856 info_ptr->num_text++; | 811 info_ptr->num_text++; |
| 857 png_debug1(3, "transferred text chunk %d", info_ptr->num_text); | 812 png_debug1(3, "transferred text chunk %d", info_ptr->num_text); |
| 858 } | 813 } |
| 859 return(0); | 814 return(0); |
| 860 } | 815 } |
| 861 #endif | 816 #endif |
| 862 | 817 |
| 863 #if defined(PNG_tIME_SUPPORTED) | 818 #ifdef PNG_tIME_SUPPORTED |
| 864 void PNGAPI | 819 void PNGAPI |
| 865 png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time) | 820 png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time) |
| 866 { | 821 { |
| 867 png_debug1(1, "in %s storage function", "tIME"); | 822 png_debug1(1, "in %s storage function", "tIME"); |
| 823 |
| 868 if (png_ptr == NULL || info_ptr == NULL || | 824 if (png_ptr == NULL || info_ptr == NULL || |
| 869 (png_ptr->mode & PNG_WROTE_tIME)) | 825 (png_ptr->mode & PNG_WROTE_tIME)) |
| 870 return; | 826 return; |
| 871 | 827 |
| 872 png_memcpy(&(info_ptr->mod_time), mod_time, png_sizeof(png_time)); | 828 png_memcpy(&(info_ptr->mod_time), mod_time, png_sizeof(png_time)); |
| 873 info_ptr->valid |= PNG_INFO_tIME; | 829 info_ptr->valid |= PNG_INFO_tIME; |
| 874 } | 830 } |
| 875 #endif | 831 #endif |
| 876 | 832 |
| 877 #if defined(PNG_tRNS_SUPPORTED) | 833 #ifdef PNG_tRNS_SUPPORTED |
| 878 void PNGAPI | 834 void PNGAPI |
| 879 png_set_tRNS(png_structp png_ptr, png_infop info_ptr, | 835 png_set_tRNS(png_structp png_ptr, png_infop info_ptr, |
| 880 png_bytep trans, int num_trans, png_color_16p trans_values) | 836 png_bytep trans, int num_trans, png_color_16p trans_values) |
| 881 { | 837 { |
| 882 png_debug1(1, "in %s storage function", "tRNS"); | 838 png_debug1(1, "in %s storage function", "tRNS"); |
| 839 |
| 883 if (png_ptr == NULL || info_ptr == NULL) | 840 if (png_ptr == NULL || info_ptr == NULL) |
| 884 return; | 841 return; |
| 885 | 842 |
| 886 if (trans != NULL) | 843 if (trans != NULL) |
| 887 { | 844 { |
| 888 /* | 845 /* It may not actually be necessary to set png_ptr->trans here; |
| 889 * It may not actually be necessary to set png_ptr->trans here; | |
| 890 * we do it for backward compatibility with the way the png_handle_tRNS | 846 * we do it for backward compatibility with the way the png_handle_tRNS |
| 891 * function used to do the allocation. | 847 * function used to do the allocation. |
| 892 */ | 848 */ |
| 893 | 849 |
| 894 #ifdef PNG_FREE_ME_SUPPORTED | 850 #ifdef PNG_FREE_ME_SUPPORTED |
| 895 png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0); | 851 png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0); |
| 896 #endif | 852 #endif |
| 897 | 853 |
| 898 /* Changed from num_trans to PNG_MAX_PALETTE_LENGTH in version 1.2.1 */ | 854 /* Changed from num_trans to PNG_MAX_PALETTE_LENGTH in version 1.2.1 */ |
| 899 png_ptr->trans = info_ptr->trans = (png_bytep)png_malloc(png_ptr, | 855 png_ptr->trans = info_ptr->trans = (png_bytep)png_malloc(png_ptr, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 925 info_ptr->valid |= PNG_INFO_tRNS; | 881 info_ptr->valid |= PNG_INFO_tRNS; |
| 926 #ifdef PNG_FREE_ME_SUPPORTED | 882 #ifdef PNG_FREE_ME_SUPPORTED |
| 927 info_ptr->free_me |= PNG_FREE_TRNS; | 883 info_ptr->free_me |= PNG_FREE_TRNS; |
| 928 #else | 884 #else |
| 929 png_ptr->flags |= PNG_FLAG_FREE_TRNS; | 885 png_ptr->flags |= PNG_FLAG_FREE_TRNS; |
| 930 #endif | 886 #endif |
| 931 } | 887 } |
| 932 } | 888 } |
| 933 #endif | 889 #endif |
| 934 | 890 |
| 935 #if defined(PNG_sPLT_SUPPORTED) | 891 #ifdef PNG_sPLT_SUPPORTED |
| 936 void PNGAPI | 892 void PNGAPI |
| 937 png_set_sPLT(png_structp png_ptr, | 893 png_set_sPLT(png_structp png_ptr, |
| 938 png_infop info_ptr, png_sPLT_tp entries, int nentries) | 894 png_infop info_ptr, png_sPLT_tp entries, int nentries) |
| 939 /* | 895 /* |
| 940 * entries - array of png_sPLT_t structures | 896 * entries - array of png_sPLT_t structures |
| 941 * to be added to the list of palettes | 897 * to be added to the list of palettes |
| 942 * in the info structure. | 898 * in the info structure. |
| 943 * nentries - number of palette structures to be | 899 * nentries - number of palette structures to be |
| 944 * added. | 900 * added. |
| 945 */ | 901 */ |
| 946 { | 902 { |
| 947 png_sPLT_tp np; | 903 png_sPLT_tp np; |
| 948 int i; | 904 int i; |
| 949 | 905 |
| 950 if (png_ptr == NULL || info_ptr == NULL) | 906 if (png_ptr == NULL || info_ptr == NULL) |
| 951 return; | 907 return; |
| 952 | 908 |
| 953 np = (png_sPLT_tp)png_malloc_warn(png_ptr, | 909 np = (png_sPLT_tp)png_malloc_warn(png_ptr, |
| 954 (info_ptr->splt_palettes_num + nentries) * | 910 (info_ptr->splt_palettes_num + nentries) * |
| 955 (png_uint_32)png_sizeof(png_sPLT_t)); | 911 (png_uint_32)png_sizeof(png_sPLT_t)); |
| 956 if (np == NULL) | 912 if (np == NULL) |
| 957 { | 913 { |
| 958 png_warning(png_ptr, "No memory for sPLT palettes."); | 914 png_warning(png_ptr, "No memory for sPLT palettes."); |
| 959 return; | 915 return; |
| 960 } | 916 } |
| 961 | 917 |
| 962 png_memcpy(np, info_ptr->splt_palettes, | 918 png_memcpy(np, info_ptr->splt_palettes, |
| 963 info_ptr->splt_palettes_num * png_sizeof(png_sPLT_t)); | 919 info_ptr->splt_palettes_num * png_sizeof(png_sPLT_t)); |
| 964 png_free(png_ptr, info_ptr->splt_palettes); | 920 png_free(png_ptr, info_ptr->splt_palettes); |
| 965 info_ptr->splt_palettes=NULL; | 921 info_ptr->splt_palettes=NULL; |
| 966 | 922 |
| 967 for (i = 0; i < nentries; i++) | 923 for (i = 0; i < nentries; i++) |
| 968 { | 924 { |
| 969 png_sPLT_tp to = np + info_ptr->splt_palettes_num + i; | 925 png_sPLT_tp to = np + info_ptr->splt_palettes_num + i; |
| 970 png_sPLT_tp from = entries + i; | 926 png_sPLT_tp from = entries + i; |
| 971 png_uint_32 length; | 927 png_uint_32 length; |
| 972 | 928 |
| 973 length = png_strlen(from->name) + 1; | 929 length = png_strlen(from->name) + 1; |
| 974 to->name = (png_charp)png_malloc_warn(png_ptr, length); | 930 to->name = (png_charp)png_malloc_warn(png_ptr, length); |
| 975 if (to->name == NULL) | 931 if (to->name == NULL) |
| 976 { | 932 { |
| 977 png_warning(png_ptr, | 933 png_warning(png_ptr, |
| 978 "Out of memory while processing sPLT chunk"); | 934 "Out of memory while processing sPLT chunk"); |
| 979 continue; | 935 continue; |
| 980 } | 936 } |
| 981 png_memcpy(to->name, from->name, length); | 937 png_memcpy(to->name, from->name, length); |
| 982 to->entries = (png_sPLT_entryp)png_malloc_warn(png_ptr, | 938 to->entries = (png_sPLT_entryp)png_malloc_warn(png_ptr, |
| 983 (png_uint_32)(from->nentries * png_sizeof(png_sPLT_entry))); | 939 (png_uint_32)(from->nentries * png_sizeof(png_sPLT_entry))); |
| 984 if (to->entries == NULL) | 940 if (to->entries == NULL) |
| 985 { | 941 { |
| 986 png_warning(png_ptr, | 942 png_warning(png_ptr, |
| 987 "Out of memory while processing sPLT chunk"); | 943 "Out of memory while processing sPLT chunk"); |
| 988 png_free(png_ptr, to->name); | 944 png_free(png_ptr, to->name); |
| 989 to->name = NULL; | 945 to->name = NULL; |
| 990 continue; | 946 continue; |
| 991 } | 947 } |
| 992 png_memcpy(to->entries, from->entries, | 948 png_memcpy(to->entries, from->entries, |
| 993 from->nentries * png_sizeof(png_sPLT_entry)); | 949 from->nentries * png_sizeof(png_sPLT_entry)); |
| 994 to->nentries = from->nentries; | 950 to->nentries = from->nentries; |
| 995 to->depth = from->depth; | 951 to->depth = from->depth; |
| 996 } | 952 } |
| 997 | 953 |
| 998 info_ptr->splt_palettes = np; | 954 info_ptr->splt_palettes = np; |
| 999 info_ptr->splt_palettes_num += nentries; | 955 info_ptr->splt_palettes_num += nentries; |
| 1000 info_ptr->valid |= PNG_INFO_sPLT; | 956 info_ptr->valid |= PNG_INFO_sPLT; |
| 1001 #ifdef PNG_FREE_ME_SUPPORTED | 957 #ifdef PNG_FREE_ME_SUPPORTED |
| 1002 info_ptr->free_me |= PNG_FREE_SPLT; | 958 info_ptr->free_me |= PNG_FREE_SPLT; |
| 1003 #endif | 959 #endif |
| 1004 } | 960 } |
| 1005 #endif /* PNG_sPLT_SUPPORTED */ | 961 #endif /* PNG_sPLT_SUPPORTED */ |
| 1006 | 962 |
| 1007 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) | 963 #ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED |
| 1008 void PNGAPI | 964 void PNGAPI |
| 1009 png_set_unknown_chunks(png_structp png_ptr, | 965 png_set_unknown_chunks(png_structp png_ptr, |
| 1010 png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns) | 966 png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns) |
| 1011 { | 967 { |
| 1012 png_unknown_chunkp np; | 968 png_unknown_chunkp np; |
| 1013 int i; | 969 int i; |
| 1014 | 970 |
| 1015 if (png_ptr == NULL || info_ptr == NULL || num_unknowns == 0) | 971 if (png_ptr == NULL || info_ptr == NULL || num_unknowns == 0) |
| 1016 return; | 972 return; |
| 1017 | 973 |
| 1018 np = (png_unknown_chunkp)png_malloc_warn(png_ptr, | 974 np = (png_unknown_chunkp)png_malloc_warn(png_ptr, |
| 1019 (png_uint_32)((info_ptr->unknown_chunks_num + num_unknowns) * | 975 (png_uint_32)((info_ptr->unknown_chunks_num + num_unknowns) * |
| 1020 png_sizeof(png_unknown_chunk))); | 976 png_sizeof(png_unknown_chunk))); |
| 1021 if (np == NULL) | 977 if (np == NULL) |
| 1022 { | 978 { |
| 1023 png_warning(png_ptr, | 979 png_warning(png_ptr, |
| 1024 "Out of memory while processing unknown chunk."); | 980 "Out of memory while processing unknown chunk."); |
| 1025 return; | 981 return; |
| 1026 } | 982 } |
| 1027 | 983 |
| 1028 png_memcpy(np, info_ptr->unknown_chunks, | 984 png_memcpy(np, info_ptr->unknown_chunks, |
| 1029 info_ptr->unknown_chunks_num * png_sizeof(png_unknown_chunk)); | 985 info_ptr->unknown_chunks_num * png_sizeof(png_unknown_chunk)); |
| 1030 png_free(png_ptr, info_ptr->unknown_chunks); | 986 png_free(png_ptr, info_ptr->unknown_chunks); |
| 1031 info_ptr->unknown_chunks=NULL; | 987 info_ptr->unknown_chunks = NULL; |
| 1032 | 988 |
| 1033 for (i = 0; i < num_unknowns; i++) | 989 for (i = 0; i < num_unknowns; i++) |
| 1034 { | 990 { |
| 1035 png_unknown_chunkp to = np + info_ptr->unknown_chunks_num + i; | 991 png_unknown_chunkp to = np + info_ptr->unknown_chunks_num + i; |
| 1036 png_unknown_chunkp from = unknowns + i; | 992 png_unknown_chunkp from = unknowns + i; |
| 1037 | 993 |
| 1038 png_memcpy((png_charp)to->name, | 994 png_memcpy((png_charp)to->name, (png_charp)from->name, |
| 1039 (png_charp)from->name, | 995 png_sizeof(from->name)); |
| 1040 png_sizeof(from->name)); | |
| 1041 to->name[png_sizeof(to->name)-1] = '\0'; | 996 to->name[png_sizeof(to->name)-1] = '\0'; |
| 1042 to->size = from->size; | 997 to->size = from->size; |
| 1043 /* Note our location in the read or write sequence */ | 998 /* Note our location in the read or write sequence */ |
| 1044 to->location = (png_byte)(png_ptr->mode & 0xff); | 999 to->location = (png_byte)(png_ptr->mode & 0xff); |
| 1045 | 1000 |
| 1046 if (from->size == 0) | 1001 if (from->size == 0) |
| 1047 to->data=NULL; | 1002 to->data=NULL; |
| 1048 else | 1003 else |
| 1049 { | 1004 { |
| 1050 to->data = (png_bytep)png_malloc_warn(png_ptr, | 1005 to->data = (png_bytep)png_malloc_warn(png_ptr, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1064 info_ptr->unknown_chunks_num += num_unknowns; | 1019 info_ptr->unknown_chunks_num += num_unknowns; |
| 1065 #ifdef PNG_FREE_ME_SUPPORTED | 1020 #ifdef PNG_FREE_ME_SUPPORTED |
| 1066 info_ptr->free_me |= PNG_FREE_UNKN; | 1021 info_ptr->free_me |= PNG_FREE_UNKN; |
| 1067 #endif | 1022 #endif |
| 1068 } | 1023 } |
| 1069 void PNGAPI | 1024 void PNGAPI |
| 1070 png_set_unknown_chunk_location(png_structp png_ptr, png_infop info_ptr, | 1025 png_set_unknown_chunk_location(png_structp png_ptr, png_infop info_ptr, |
| 1071 int chunk, int location) | 1026 int chunk, int location) |
| 1072 { | 1027 { |
| 1073 if (png_ptr != NULL && info_ptr != NULL && chunk >= 0 && chunk < | 1028 if (png_ptr != NULL && info_ptr != NULL && chunk >= 0 && chunk < |
| 1074 (int)info_ptr->unknown_chunks_num) | 1029 (int)info_ptr->unknown_chunks_num) |
| 1075 info_ptr->unknown_chunks[chunk].location = (png_byte)location; | 1030 info_ptr->unknown_chunks[chunk].location = (png_byte)location; |
| 1076 } | 1031 } |
| 1077 #endif | 1032 #endif |
| 1078 | 1033 |
| 1079 #if defined(PNG_1_0_X) || defined(PNG_1_2_X) | 1034 #if defined(PNG_1_0_X) || defined(PNG_1_2_X) |
| 1080 #if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \ | 1035 #if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \ |
| 1081 defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED) | 1036 defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED) |
| 1082 void PNGAPI | 1037 void PNGAPI |
| 1083 png_permit_empty_plte (png_structp png_ptr, int empty_plte_permitted) | 1038 png_permit_empty_plte (png_structp png_ptr, int empty_plte_permitted) |
| 1084 { | 1039 { |
| 1085 /* This function is deprecated in favor of png_permit_mng_features() | 1040 /* This function is deprecated in favor of png_permit_mng_features() |
| 1086 and will be removed from libpng-1.3.0 */ | 1041 and will be removed from libpng-1.3.0 */ |
| 1042 |
| 1087 png_debug(1, "in png_permit_empty_plte, DEPRECATED."); | 1043 png_debug(1, "in png_permit_empty_plte, DEPRECATED."); |
| 1044 |
| 1088 if (png_ptr == NULL) | 1045 if (png_ptr == NULL) |
| 1089 return; | 1046 return; |
| 1090 png_ptr->mng_features_permitted = (png_byte) | 1047 png_ptr->mng_features_permitted = (png_byte) |
| 1091 ((png_ptr->mng_features_permitted & (~PNG_FLAG_MNG_EMPTY_PLTE)) | | 1048 ((png_ptr->mng_features_permitted & (~PNG_FLAG_MNG_EMPTY_PLTE)) | |
| 1092 ((empty_plte_permitted & PNG_FLAG_MNG_EMPTY_PLTE))); | 1049 ((empty_plte_permitted & PNG_FLAG_MNG_EMPTY_PLTE))); |
| 1093 } | 1050 } |
| 1094 #endif | 1051 #endif |
| 1095 #endif | 1052 #endif |
| 1096 | 1053 |
| 1097 #if defined(PNG_MNG_FEATURES_SUPPORTED) | 1054 #ifdef PNG_MNG_FEATURES_SUPPORTED |
| 1098 png_uint_32 PNGAPI | 1055 png_uint_32 PNGAPI |
| 1099 png_permit_mng_features (png_structp png_ptr, png_uint_32 mng_features) | 1056 png_permit_mng_features (png_structp png_ptr, png_uint_32 mng_features) |
| 1100 { | 1057 { |
| 1101 png_debug(1, "in png_permit_mng_features"); | 1058 png_debug(1, "in png_permit_mng_features"); |
| 1059 |
| 1102 if (png_ptr == NULL) | 1060 if (png_ptr == NULL) |
| 1103 return (png_uint_32)0; | 1061 return (png_uint_32)0; |
| 1104 png_ptr->mng_features_permitted = | 1062 png_ptr->mng_features_permitted = |
| 1105 (png_byte)(mng_features & PNG_ALL_MNG_FEATURES); | 1063 (png_byte)(mng_features & PNG_ALL_MNG_FEATURES); |
| 1106 return (png_uint_32)png_ptr->mng_features_permitted; | 1064 return (png_uint_32)png_ptr->mng_features_permitted; |
| 1107 } | 1065 } |
| 1108 #endif | 1066 #endif |
| 1109 | 1067 |
| 1110 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) | 1068 #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED |
| 1111 void PNGAPI | 1069 void PNGAPI |
| 1112 png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep | 1070 png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep |
| 1113 chunk_list, int num_chunks) | 1071 chunk_list, int num_chunks) |
| 1114 { | 1072 { |
| 1115 png_bytep new_list, p; | 1073 png_bytep new_list, p; |
| 1116 int i, old_num_chunks; | 1074 int i, old_num_chunks; |
| 1117 if (png_ptr == NULL) | 1075 if (png_ptr == NULL) |
| 1118 return; | 1076 return; |
| 1119 if (num_chunks == 0) | 1077 if (num_chunks == 0) |
| 1120 { | 1078 { |
| 1121 if (keep == PNG_HANDLE_CHUNK_ALWAYS || keep == PNG_HANDLE_CHUNK_IF_SAFE) | 1079 if (keep == PNG_HANDLE_CHUNK_ALWAYS || keep == PNG_HANDLE_CHUNK_IF_SAFE) |
| 1122 png_ptr->flags |= PNG_FLAG_KEEP_UNKNOWN_CHUNKS; | 1080 png_ptr->flags |= PNG_FLAG_KEEP_UNKNOWN_CHUNKS; |
| 1123 else | 1081 else |
| 1124 png_ptr->flags &= ~PNG_FLAG_KEEP_UNKNOWN_CHUNKS; | 1082 png_ptr->flags &= ~PNG_FLAG_KEEP_UNKNOWN_CHUNKS; |
| 1125 | 1083 |
| 1126 if (keep == PNG_HANDLE_CHUNK_ALWAYS) | 1084 if (keep == PNG_HANDLE_CHUNK_ALWAYS) |
| 1127 png_ptr->flags |= PNG_FLAG_KEEP_UNSAFE_CHUNKS; | 1085 png_ptr->flags |= PNG_FLAG_KEEP_UNSAFE_CHUNKS; |
| 1128 else | 1086 else |
| 1129 png_ptr->flags &= ~PNG_FLAG_KEEP_UNSAFE_CHUNKS; | 1087 png_ptr->flags &= ~PNG_FLAG_KEEP_UNSAFE_CHUNKS; |
| 1130 return; | 1088 return; |
| 1131 } | 1089 } |
| 1132 if (chunk_list == NULL) | 1090 if (chunk_list == NULL) |
| 1133 return; | 1091 return; |
| 1134 old_num_chunks = png_ptr->num_chunk_list; | 1092 old_num_chunks = png_ptr->num_chunk_list; |
| 1135 new_list=(png_bytep)png_malloc(png_ptr, | 1093 new_list=(png_bytep)png_malloc(png_ptr, |
| 1136 (png_uint_32) | 1094 (png_uint_32) |
| 1137 (5*(num_chunks + old_num_chunks))); | 1095 (5*(num_chunks + old_num_chunks))); |
| 1138 if (png_ptr->chunk_list != NULL) | 1096 if (png_ptr->chunk_list != NULL) |
| 1139 { | 1097 { |
| 1140 png_memcpy(new_list, png_ptr->chunk_list, | 1098 png_memcpy(new_list, png_ptr->chunk_list, |
| 1141 (png_size_t)(5*old_num_chunks)); | 1099 (png_size_t)(5*old_num_chunks)); |
| 1142 png_free(png_ptr, png_ptr->chunk_list); | 1100 png_free(png_ptr, png_ptr->chunk_list); |
| 1143 png_ptr->chunk_list=NULL; | 1101 png_ptr->chunk_list=NULL; |
| 1144 } | 1102 } |
| 1145 png_memcpy(new_list + 5*old_num_chunks, chunk_list, | 1103 png_memcpy(new_list + 5*old_num_chunks, chunk_list, |
| 1146 (png_size_t)(5*num_chunks)); | 1104 (png_size_t)(5*num_chunks)); |
| 1147 for (p = new_list + 5*old_num_chunks + 4, i = 0; i<num_chunks; i++, p += 5) | 1105 for (p = new_list + 5*old_num_chunks + 4, i = 0; i<num_chunks; i++, p += 5) |
| 1148 *p=(png_byte)keep; | 1106 *p=(png_byte)keep; |
| 1149 png_ptr->num_chunk_list = old_num_chunks + num_chunks; | 1107 png_ptr->num_chunk_list = old_num_chunks + num_chunks; |
| 1150 png_ptr->chunk_list = new_list; | 1108 png_ptr->chunk_list = new_list; |
| 1151 #ifdef PNG_FREE_ME_SUPPORTED | 1109 #ifdef PNG_FREE_ME_SUPPORTED |
| 1152 png_ptr->free_me |= PNG_FREE_LIST; | 1110 png_ptr->free_me |= PNG_FREE_LIST; |
| 1153 #endif | 1111 #endif |
| 1154 } | 1112 } |
| 1155 #endif | 1113 #endif |
| 1156 | 1114 |
| 1157 #if defined(PNG_READ_USER_CHUNKS_SUPPORTED) | 1115 #ifdef PNG_READ_USER_CHUNKS_SUPPORTED |
| 1158 void PNGAPI | 1116 void PNGAPI |
| 1159 png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp user_chunk_ptr, | 1117 png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp user_chunk_ptr, |
| 1160 png_user_chunk_ptr read_user_chunk_fn) | 1118 png_user_chunk_ptr read_user_chunk_fn) |
| 1161 { | 1119 { |
| 1162 png_debug(1, "in png_set_read_user_chunk_fn"); | 1120 png_debug(1, "in png_set_read_user_chunk_fn"); |
| 1121 |
| 1163 if (png_ptr == NULL) | 1122 if (png_ptr == NULL) |
| 1164 return; | 1123 return; |
| 1124 |
| 1165 png_ptr->read_user_chunk_fn = read_user_chunk_fn; | 1125 png_ptr->read_user_chunk_fn = read_user_chunk_fn; |
| 1166 png_ptr->user_chunk_ptr = user_chunk_ptr; | 1126 png_ptr->user_chunk_ptr = user_chunk_ptr; |
| 1167 } | 1127 } |
| 1168 #endif | 1128 #endif |
| 1169 | 1129 |
| 1170 #if defined(PNG_INFO_IMAGE_SUPPORTED) | 1130 #ifdef PNG_INFO_IMAGE_SUPPORTED |
| 1171 void PNGAPI | 1131 void PNGAPI |
| 1172 png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers) | 1132 png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers) |
| 1173 { | 1133 { |
| 1174 png_debug1(1, "in %s storage function", "rows"); | 1134 png_debug1(1, "in %s storage function", "rows"); |
| 1175 | 1135 |
| 1176 if (png_ptr == NULL || info_ptr == NULL) | 1136 if (png_ptr == NULL || info_ptr == NULL) |
| 1177 return; | 1137 return; |
| 1178 | 1138 |
| 1179 if (info_ptr->row_pointers && (info_ptr->row_pointers != row_pointers)) | 1139 if (info_ptr->row_pointers && (info_ptr->row_pointers != row_pointers)) |
| 1180 png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0); | 1140 png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0); |
| 1181 info_ptr->row_pointers = row_pointers; | 1141 info_ptr->row_pointers = row_pointers; |
| 1182 if (row_pointers) | 1142 if (row_pointers) |
| 1183 info_ptr->valid |= PNG_INFO_IDAT; | 1143 info_ptr->valid |= PNG_INFO_IDAT; |
| 1184 } | 1144 } |
| 1185 #endif | 1145 #endif |
| 1186 | 1146 |
| 1187 #ifdef PNG_WRITE_SUPPORTED | |
| 1188 void PNGAPI | 1147 void PNGAPI |
| 1189 png_set_compression_buffer_size(png_structp png_ptr, | 1148 png_set_compression_buffer_size(png_structp png_ptr, |
| 1190 png_uint_32 size) | 1149 png_uint_32 size) |
| 1191 { | 1150 { |
| 1192 if (png_ptr == NULL) | 1151 if (png_ptr == NULL) |
| 1193 return; | 1152 return; |
| 1194 png_free(png_ptr, png_ptr->zbuf); | 1153 png_free(png_ptr, png_ptr->zbuf); |
| 1195 png_ptr->zbuf_size = (png_size_t)size; | 1154 png_ptr->zbuf_size = (png_size_t)size; |
| 1196 png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, size); | 1155 png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, size); |
| 1197 png_ptr->zstream.next_out = png_ptr->zbuf; | 1156 png_ptr->zstream.next_out = png_ptr->zbuf; |
| 1198 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; | 1157 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; |
| 1199 } | 1158 } |
| 1200 #endif | |
| 1201 | 1159 |
| 1202 void PNGAPI | 1160 void PNGAPI |
| 1203 png_set_invalid(png_structp png_ptr, png_infop info_ptr, int mask) | 1161 png_set_invalid(png_structp png_ptr, png_infop info_ptr, int mask) |
| 1204 { | 1162 { |
| 1205 if (png_ptr && info_ptr) | 1163 if (png_ptr && info_ptr) |
| 1206 info_ptr->valid &= ~mask; | 1164 info_ptr->valid &= ~mask; |
| 1207 } | 1165 } |
| 1208 | 1166 |
| 1209 | 1167 |
| 1210 #ifndef PNG_1_0_X | 1168 #ifndef PNG_1_0_X |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1244 * rejected by png_set_IHDR(). To accept any PNG datastream | 1202 * rejected by png_set_IHDR(). To accept any PNG datastream |
| 1245 * regardless of dimensions, set both limits to 0x7ffffffL. | 1203 * regardless of dimensions, set both limits to 0x7ffffffL. |
| 1246 */ | 1204 */ |
| 1247 if (png_ptr == NULL) | 1205 if (png_ptr == NULL) |
| 1248 return; | 1206 return; |
| 1249 png_ptr->user_width_max = user_width_max; | 1207 png_ptr->user_width_max = user_width_max; |
| 1250 png_ptr->user_height_max = user_height_max; | 1208 png_ptr->user_height_max = user_height_max; |
| 1251 } | 1209 } |
| 1252 #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */ | 1210 #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */ |
| 1253 | 1211 |
| 1212 |
| 1213 #ifdef PNG_BENIGN_ERRORS_SUPPORTED |
| 1214 void PNGAPI |
| 1215 png_set_benign_errors(png_structp png_ptr, int allowed) |
| 1216 { |
| 1217 png_debug(1, "in png_set_benign_errors"); |
| 1218 |
| 1219 if (allowed) |
| 1220 png_ptr->flags |= PNG_FLAG_BENIGN_ERRORS_WARN; |
| 1221 else |
| 1222 png_ptr->flags &= ~PNG_FLAG_BENIGN_ERRORS_WARN; |
| 1223 } |
| 1224 #endif /* PNG_BENIGN_ERRORS_SUPPORTED */ |
| 1254 #endif /* ?PNG_1_0_X */ | 1225 #endif /* ?PNG_1_0_X */ |
| 1255 #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */ | 1226 #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */ |
| OLD | NEW |