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