| 1 | /* |
|---|
| 2 | * $Id: //suprahd/releases/suprahd_163/suprahd_ztvapp640_163/drivers/graphics/PNG/lpng102/pngset.c#1 $ |
|---|
| 3 | * $Revision: #1 $ |
|---|
| 4 | * $DateTime: 2006/02/24 17:51:46 $ |
|---|
| 5 | * $Change: 42566 $ |
|---|
| 6 | * $Author: pryush.sharma $ |
|---|
| 7 | */ |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | /* pngset.c - storage of image information into info struct |
|---|
| 11 | * |
|---|
| 12 | * libpng 1.0.2 - June 14, 1998 |
|---|
| 13 | * For conditions of distribution and use, see copyright notice in png.h |
|---|
| 14 | * Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. |
|---|
| 15 | * Copyright (c) 1996, 1997 Andreas Dilger |
|---|
| 16 | * Copyright (c) 1998, Glenn Randers-Pehrson |
|---|
| 17 | * |
|---|
| 18 | * The functions here are used during reads to store data from the file |
|---|
| 19 | * into the info struct, and during writes to store application data |
|---|
| 20 | * into the info struct for writing into the file. This abstracts the |
|---|
| 21 | * info struct and allows us to change the structure in the future. |
|---|
| 22 | */ |
|---|
| 23 | |
|---|
| 24 | #define PNG_INTERNAL |
|---|
| 25 | #include "png.h" |
|---|
| 26 | |
|---|
| 27 | #if defined(PNG_READ_bKGD_SUPPORTED) || defined(PNG_WRITE_bKGD_SUPPORTED) |
|---|
| 28 | void |
|---|
| 29 | png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background) |
|---|
| 30 | { |
|---|
| 31 | png_debug1(1, "in %s storage function\n", "bKGD"); |
|---|
| 32 | if (png_ptr == NULL || info_ptr == NULL) |
|---|
| 33 | return; |
|---|
| 34 | |
|---|
| 35 | png_memcpy(&(info_ptr->background), background, sizeof(png_color_16)); |
|---|
| 36 | info_ptr->valid |= PNG_INFO_bKGD; |
|---|
| 37 | } |
|---|
| 38 | #endif |
|---|
| 39 | |
|---|
| 40 | #if defined(PNG_READ_cHRM_SUPPORTED) || defined(PNG_WRITE_cHRM_SUPPORTED) |
|---|
| 41 | void |
|---|
| 42 | png_set_cHRM(png_structp png_ptr, png_infop info_ptr, |
|---|
| 43 | double white_x, double white_y, double red_x, double red_y, |
|---|
| 44 | double green_x, double green_y, double blue_x, double blue_y) |
|---|
| 45 | { |
|---|
| 46 | png_debug1(1, "in %s storage function\n", "cHRM"); |
|---|
| 47 | if (png_ptr == NULL || info_ptr == NULL) |
|---|
| 48 | return; |
|---|
| 49 | |
|---|
| 50 | info_ptr->x_white = (float)white_x; |
|---|
| 51 | info_ptr->y_white = (float)white_y; |
|---|
| 52 | info_ptr->x_red = (float)red_x; |
|---|
| 53 | info_ptr->y_red = (float)red_y; |
|---|
| 54 | info_ptr->x_green = (float)green_x; |
|---|
| 55 | info_ptr->y_green = (float)green_y; |
|---|
| 56 | info_ptr->x_blue = (float)blue_x; |
|---|
| 57 | info_ptr->y_blue = (float)blue_y; |
|---|
| 58 | info_ptr->valid |= PNG_INFO_cHRM; |
|---|
| 59 | } |
|---|
| 60 | #endif |
|---|
| 61 | |
|---|
| 62 | #if defined(PNG_READ_gAMA_SUPPORTED) || defined(PNG_WRITE_gAMA_SUPPORTED) |
|---|
| 63 | void |
|---|
| 64 | png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma) |
|---|
| 65 | { |
|---|
| 66 | png_debug1(1, "in %s storage function\n", "gAMA"); |
|---|
| 67 | if (png_ptr == NULL || info_ptr == NULL) |
|---|
| 68 | return; |
|---|
| 69 | |
|---|
| 70 | info_ptr->gamma = (float)file_gamma; |
|---|
| 71 | info_ptr->valid |= PNG_INFO_gAMA; |
|---|
| 72 | } |
|---|
| 73 | #endif |
|---|
| 74 | |
|---|
| 75 | #if defined(PNG_READ_hIST_SUPPORTED) || defined(PNG_WRITE_hIST_SUPPORTED) |
|---|
| 76 | void |
|---|
| 77 | png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist) |
|---|
| 78 | { |
|---|
| 79 | png_debug1(1, "in %s storage function\n", "hIST"); |
|---|
| 80 | if (png_ptr == NULL || info_ptr == NULL) |
|---|
| 81 | return; |
|---|
| 82 | |
|---|
| 83 | info_ptr->hist = hist; |
|---|
| 84 | info_ptr->valid |= PNG_INFO_hIST; |
|---|
| 85 | } |
|---|
| 86 | #endif |
|---|
| 87 | |
|---|
| 88 | void |
|---|
| 89 | png_set_IHDR(png_structp png_ptr, png_infop info_ptr, |
|---|
| 90 | png_uint_32 width, png_uint_32 height, int bit_depth, |
|---|
| 91 | int color_type, int interlace_type, int compression_type, |
|---|
| 92 | int filter_type) |
|---|
| 93 | { |
|---|
| 94 | int rowbytes_per_pixel; |
|---|
| 95 | png_debug1(1, "in %s storage function\n", "IHDR"); |
|---|
| 96 | if (png_ptr == NULL || info_ptr == NULL) |
|---|
| 97 | return; |
|---|
| 98 | |
|---|
| 99 | info_ptr->width = width; |
|---|
| 100 | info_ptr->height = height; |
|---|
| 101 | info_ptr->bit_depth = (png_byte)bit_depth; |
|---|
| 102 | info_ptr->color_type =(png_byte) color_type; |
|---|
| 103 | info_ptr->compression_type = (png_byte)compression_type; |
|---|
| 104 | info_ptr->filter_type = (png_byte)filter_type; |
|---|
| 105 | info_ptr->interlace_type = (png_byte)interlace_type; |
|---|
| 106 | if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) |
|---|
| 107 | info_ptr->channels = 1; |
|---|
| 108 | else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR) |
|---|
| 109 | info_ptr->channels = 3; |
|---|
| 110 | else |
|---|
| 111 | info_ptr->channels = 1; |
|---|
| 112 | if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA) |
|---|
| 113 | info_ptr->channels++; |
|---|
| 114 | info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth); |
|---|
| 115 | |
|---|
| 116 | /* check for overflow */ |
|---|
| 117 | rowbytes_per_pixel = (info_ptr->pixel_depth + 7) >> 3; |
|---|
| 118 | if (( width > (png_uint_32)2147483647L/rowbytes_per_pixel)) |
|---|
| 119 | { |
|---|
| 120 | png_warning(png_ptr, |
|---|
| 121 | "Width too large to process image data; rowbytes will overflow."); |
|---|
| 122 | info_ptr->rowbytes = (png_size_t)0; |
|---|
| 123 | } |
|---|
| 124 | else |
|---|
| 125 | info_ptr->rowbytes = (info_ptr->width * info_ptr->pixel_depth + 7) >> 3; |
|---|
| 126 | } |
|---|
| 127 | |
|---|
| 128 | #if defined(PNG_READ_oFFs_SUPPORTED) || defined(PNG_WRITE_oFFs_SUPPORTED) |
|---|
| 129 | void |
|---|
| 130 | png_set_oFFs(png_structp png_ptr, png_infop info_ptr, |
|---|
| 131 | png_uint_32 offset_x, png_uint_32 offset_y, int unit_type) |
|---|
| 132 | { |
|---|
| 133 | png_debug1(1, "in %s storage function\n", "oFFs"); |
|---|
| 134 | if (png_ptr == NULL || info_ptr == NULL) |
|---|
| 135 | return; |
|---|
| 136 | |
|---|
| 137 | info_ptr->x_offset = offset_x; |
|---|
| 138 | info_ptr->y_offset = offset_y; |
|---|
| 139 | info_ptr->offset_unit_type = (png_byte)unit_type; |
|---|
| 140 | info_ptr->valid |= PNG_INFO_oFFs; |
|---|
| 141 | } |
|---|
| 142 | #endif |
|---|
| 143 | |
|---|
| 144 | #if defined(PNG_READ_pCAL_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) |
|---|
| 145 | void |
|---|
| 146 | png_set_pCAL(png_structp png_ptr, png_infop info_ptr, |
|---|
| 147 | png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams, |
|---|
| 148 | png_charp units, png_charpp params) |
|---|
| 149 | { |
|---|
| 150 | png_uint_32 length; |
|---|
| 151 | int i; |
|---|
| 152 | |
|---|
| 153 | png_debug1(1, "in %s storage function\n", "pCAL"); |
|---|
| 154 | if (png_ptr == NULL || info_ptr == NULL) |
|---|
| 155 | return; |
|---|
| 156 | |
|---|
| 157 | length = png_strlen(purpose) + 1; |
|---|
| 158 | png_debug1(3, "allocating purpose for info (%d bytes)\n", length); |
|---|
| 159 | info_ptr->pcal_purpose = (png_charp)png_malloc(png_ptr, length); |
|---|
| 160 | png_memcpy(info_ptr->pcal_purpose, purpose, (png_size_t)length); |
|---|
| 161 | |
|---|
| 162 | png_debug(3, "storing X0, X1, type, and nparams in info\n"); |
|---|
| 163 | info_ptr->pcal_X0 = X0; |
|---|
| 164 | info_ptr->pcal_X1 = X1; |
|---|
| 165 | info_ptr->pcal_type = (png_byte)type; |
|---|
| 166 | info_ptr->pcal_nparams = (png_byte)nparams; |
|---|
| 167 | |
|---|
| 168 | length = png_strlen(units) + 1; |
|---|
| 169 | png_debug1(3, "allocating units for info (%d bytes)\n", length); |
|---|
| 170 | info_ptr->pcal_units = (png_charp)png_malloc(png_ptr, length); |
|---|
| 171 | png_memcpy(info_ptr->pcal_units, units, (png_size_t)length); |
|---|
| 172 | |
|---|
| 173 | info_ptr->pcal_params = (png_charpp)png_malloc(png_ptr, |
|---|
| 174 | (png_uint_32)((nparams + 1) * sizeof(png_charp))); |
|---|
| 175 | info_ptr->pcal_params[nparams] = NULL; |
|---|
| 176 | |
|---|
| 177 | for (i = 0; i < nparams; i++) |
|---|
| 178 | { |
|---|
| 179 | length = png_strlen(params[i]) + 1; |
|---|
| 180 | png_debug2(3, "allocating parameter %d for info (%d bytes)\n", i, length); |
|---|
| 181 | info_ptr->pcal_params[i] = (png_charp)png_malloc(png_ptr, length); |
|---|
| 182 | png_memcpy(info_ptr->pcal_params[i], params[i], (png_size_t)length); |
|---|
| 183 | } |
|---|
| 184 | |
|---|
| 185 | info_ptr->valid |= PNG_INFO_pCAL; |
|---|
| 186 | } |
|---|
| 187 | #endif |
|---|
| 188 | |
|---|
| 189 | #if defined(PNG_READ_pHYs_SUPPORTED) || defined(PNG_WRITE_pHYs_SUPPORTED) |
|---|
| 190 | void |
|---|
| 191 | png_set_pHYs(png_structp png_ptr, png_infop info_ptr, |
|---|
| 192 | png_uint_32 res_x, png_uint_32 res_y, int unit_type) |
|---|
| 193 | { |
|---|
| 194 | png_debug1(1, "in %s storage function\n", "pHYs"); |
|---|
| 195 | if (png_ptr == NULL || info_ptr == NULL) |
|---|
| 196 | return; |
|---|
| 197 | |
|---|
| 198 | info_ptr->x_pixels_per_unit = res_x; |
|---|
| 199 | info_ptr->y_pixels_per_unit = res_y; |
|---|
| 200 | info_ptr->phys_unit_type = (png_byte)unit_type; |
|---|
| 201 | info_ptr->valid |= PNG_INFO_pHYs; |
|---|
| 202 | } |
|---|
| 203 | #endif |
|---|
| 204 | |
|---|
| 205 | void |
|---|
| 206 | png_set_PLTE(png_structp png_ptr, png_infop info_ptr, |
|---|
| 207 | png_colorp palette, int num_palette) |
|---|
| 208 | { |
|---|
| 209 | png_debug1(1, "in %s storage function\n", "PLTE"); |
|---|
| 210 | if (png_ptr == NULL || info_ptr == NULL) |
|---|
| 211 | return; |
|---|
| 212 | |
|---|
| 213 | info_ptr->palette = palette; |
|---|
| 214 | info_ptr->num_palette = (png_uint_16)num_palette; |
|---|
| 215 | info_ptr->valid |= PNG_INFO_PLTE; |
|---|
| 216 | } |
|---|
| 217 | |
|---|
| 218 | #if defined(PNG_READ_sBIT_SUPPORTED) || defined(PNG_WRITE_sBIT_SUPPORTED) |
|---|
| 219 | void |
|---|
| 220 | png_set_sBIT(png_structp png_ptr, png_infop info_ptr, |
|---|
| 221 | png_color_8p sig_bit) |
|---|
| 222 | { |
|---|
| 223 | png_debug1(1, "in %s storage function\n", "sBIT"); |
|---|
| 224 | if (png_ptr == NULL || info_ptr == NULL) |
|---|
| 225 | return; |
|---|
| 226 | |
|---|
| 227 | png_memcpy(&(info_ptr->sig_bit), sig_bit, sizeof (png_color_8)); |
|---|
| 228 | info_ptr->valid |= PNG_INFO_sBIT; |
|---|
| 229 | } |
|---|
| 230 | #endif |
|---|
| 231 | |
|---|
| 232 | #if defined(PNG_READ_sRGB_SUPPORTED) || defined(PNG_WRITE_sRGB_SUPPORTED) |
|---|
| 233 | void |
|---|
| 234 | png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int intent) |
|---|
| 235 | { |
|---|
| 236 | png_debug1(1, "in %s storage function\n", "sRGB"); |
|---|
| 237 | if (png_ptr == NULL || info_ptr == NULL) |
|---|
| 238 | return; |
|---|
| 239 | |
|---|
| 240 | info_ptr->srgb_intent = (png_byte)intent; |
|---|
| 241 | info_ptr->valid |= PNG_INFO_sRGB; |
|---|
| 242 | } |
|---|
| 243 | void |
|---|
| 244 | png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr, |
|---|
| 245 | int intent) |
|---|
| 246 | { |
|---|
| 247 | #if defined(PNG_READ_gAMA_SUPPORTED) || defined(PNG_WRITE_gAMA_SUPPORTED) |
|---|
| 248 | float file_gamma; |
|---|
| 249 | #endif |
|---|
| 250 | #if defined(PNG_READ_cHRM_SUPPORTED) || defined(PNG_WRITE_cHRM_SUPPORTED) |
|---|
| 251 | float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y; |
|---|
| 252 | #endif |
|---|
| 253 | png_debug1(1, "in %s storage function\n", "sRGB_gAMA_and_cHRM"); |
|---|
| 254 | if (png_ptr == NULL || info_ptr == NULL) |
|---|
| 255 | return; |
|---|
| 256 | |
|---|
| 257 | png_set_sRGB(png_ptr, info_ptr, intent); |
|---|
| 258 | |
|---|
| 259 | #if defined(PNG_READ_gAMA_SUPPORTED) || defined(PNG_WRITE_gAMA_SUPPORTED) |
|---|
| 260 | file_gamma = (float).45; |
|---|
| 261 | png_set_gAMA(png_ptr, info_ptr, file_gamma); |
|---|
| 262 | #endif |
|---|
| 263 | |
|---|
| 264 | #if defined(PNG_READ_cHRM_SUPPORTED) || defined(PNG_WRITE_cHRM_SUPPORTED) |
|---|
| 265 | white_x = (float).3127; |
|---|
| 266 | white_y = (float).3290; |
|---|
| 267 | red_x = (float).64; |
|---|
| 268 | red_y = (float).33; |
|---|
| 269 | green_x = (float).30; |
|---|
| 270 | green_y = (float).60; |
|---|
| 271 | blue_x = (float).15; |
|---|
| 272 | blue_y = (float).06; |
|---|
| 273 | |
|---|
| 274 | png_set_cHRM(png_ptr, info_ptr, |
|---|
| 275 | white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y); |
|---|
| 276 | |
|---|
| 277 | #endif |
|---|
| 278 | } |
|---|
| 279 | #endif |
|---|
| 280 | |
|---|
| 281 | #if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_WRITE_tEXt_SUPPORTED) || \ |
|---|
| 282 | defined(PNG_READ_zTXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED) |
|---|
| 283 | void |
|---|
| 284 | png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr, |
|---|
| 285 | int num_text) |
|---|
| 286 | { |
|---|
| 287 | int i; |
|---|
| 288 | |
|---|
| 289 | png_debug1(1, "in %s storage function\n", (png_ptr->chunk_name[0] == '\0' ? |
|---|
| 290 | "text" : (png_const_charp)png_ptr->chunk_name)); |
|---|
| 291 | |
|---|
| 292 | if (png_ptr == NULL || info_ptr == NULL || num_text == 0) |
|---|
| 293 | return; |
|---|
| 294 | |
|---|
| 295 | /* Make sure we have enough space in the "text" array in info_struct |
|---|
| 296 | * to hold all of the incoming text_ptr objects. |
|---|
| 297 | */ |
|---|
| 298 | if (info_ptr->num_text + num_text > info_ptr->max_text) |
|---|
| 299 | { |
|---|
| 300 | if (info_ptr->text != NULL) |
|---|
| 301 | { |
|---|
| 302 | png_textp old_text; |
|---|
| 303 | int old_max; |
|---|
| 304 | |
|---|
| 305 | old_max = info_ptr->max_text; |
|---|
| 306 | info_ptr->max_text = info_ptr->num_text + num_text + 8; |
|---|
| 307 | old_text = info_ptr->text; |
|---|
| 308 | info_ptr->text = (png_textp)png_malloc(png_ptr, |
|---|
| 309 | (png_uint_32)(info_ptr->max_text * sizeof (png_text))); |
|---|
| 310 | png_memcpy(info_ptr->text, old_text, (png_size_t)(old_max * |
|---|
| 311 | sizeof(png_text))); |
|---|
| 312 | png_free(png_ptr, old_text); |
|---|
| 313 | } |
|---|
| 314 | else |
|---|
| 315 | { |
|---|
| 316 | info_ptr->max_text = num_text + 8; |
|---|
| 317 | info_ptr->num_text = 0; |
|---|
| 318 | info_ptr->text = (png_textp)png_malloc(png_ptr, |
|---|
| 319 | (png_uint_32)(info_ptr->max_text * sizeof (png_text))); |
|---|
| 320 | } |
|---|
| 321 | png_debug1(3, "allocated %d entries for info_ptr->text\n", |
|---|
| 322 | info_ptr->max_text); |
|---|
| 323 | } |
|---|
| 324 | |
|---|
| 325 | for (i = 0; i < num_text; i++) |
|---|
| 326 | { |
|---|
| 327 | png_textp textp = &(info_ptr->text[info_ptr->num_text]); |
|---|
| 328 | |
|---|
| 329 | if (text_ptr[i].text == NULL) |
|---|
| 330 | text_ptr[i].text = (png_charp)""; |
|---|
| 331 | |
|---|
| 332 | if (text_ptr[i].text[0] == '\0') |
|---|
| 333 | { |
|---|
| 334 | textp->text_length = 0; |
|---|
| 335 | textp->compression = PNG_TEXT_COMPRESSION_NONE; |
|---|
| 336 | } |
|---|
| 337 | else |
|---|
| 338 | { |
|---|
| 339 | textp->text_length = png_strlen(text_ptr[i].text); |
|---|
| 340 | textp->compression = text_ptr[i].compression; |
|---|
| 341 | } |
|---|
| 342 | textp->text = text_ptr[i].text; |
|---|
| 343 | textp->key = text_ptr[i].key; |
|---|
| 344 | info_ptr->num_text++; |
|---|
| 345 | png_debug1(3, "transferred text chunk %d\n", info_ptr->num_text); |
|---|
| 346 | } |
|---|
| 347 | } |
|---|
| 348 | #endif |
|---|
| 349 | |
|---|
| 350 | #if defined(PNG_READ_tIME_SUPPORTED) || defined(PNG_WRITE_tIME_SUPPORTED) |
|---|
| 351 | void |
|---|
| 352 | png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time) |
|---|
| 353 | { |
|---|
| 354 | png_debug1(1, "in %s storage function\n", "tIME"); |
|---|
| 355 | if (png_ptr == NULL || info_ptr == NULL) |
|---|
| 356 | return; |
|---|
| 357 | |
|---|
| 358 | png_memcpy(&(info_ptr->mod_time), mod_time, sizeof (png_time)); |
|---|
| 359 | info_ptr->valid |= PNG_INFO_tIME; |
|---|
| 360 | } |
|---|
| 361 | #endif |
|---|
| 362 | |
|---|
| 363 | #if defined(PNG_READ_tRNS_SUPPORTED) || defined(PNG_WRITE_tRNS_SUPPORTED) |
|---|
| 364 | void |
|---|
| 365 | png_set_tRNS(png_structp png_ptr, png_infop info_ptr, |
|---|
| 366 | png_bytep trans, int num_trans, png_color_16p trans_values) |
|---|
| 367 | { |
|---|
| 368 | png_debug1(1, "in %s storage function\n", "tRNS"); |
|---|
| 369 | if (png_ptr == NULL || info_ptr == NULL) |
|---|
| 370 | return; |
|---|
| 371 | |
|---|
| 372 | if (trans != NULL) |
|---|
| 373 | { |
|---|
| 374 | info_ptr->trans = trans; |
|---|
| 375 | } |
|---|
| 376 | |
|---|
| 377 | if (trans_values != NULL) |
|---|
| 378 | { |
|---|
| 379 | png_memcpy(&(info_ptr->trans_values), trans_values, |
|---|
| 380 | sizeof(png_color_16)); |
|---|
| 381 | if (num_trans == 0) |
|---|
| 382 | num_trans = 1; |
|---|
| 383 | } |
|---|
| 384 | info_ptr->num_trans = (png_uint_16)num_trans; |
|---|
| 385 | info_ptr->valid |= PNG_INFO_tRNS; |
|---|
| 386 | } |
|---|
| 387 | #endif |
|---|
| 388 | |
|---|