istereo2

annotate libs/libpng/png.c @ 20:2b85d05df3f2

animation controls for easier screenshot grabbing
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 02 Oct 2015 04:54:55 +0300
parents
children
rev   line source
nuclear@2 1
nuclear@2 2 /* png.c - location for general purpose libpng functions
nuclear@2 3 *
nuclear@2 4 * Last changed in libpng 1.2.30 [August 15, 2008]
nuclear@2 5 * For conditions of distribution and use, see copyright notice in png.h
nuclear@2 6 * Copyright (c) 1998-2008 Glenn Randers-Pehrson
nuclear@2 7 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
nuclear@2 8 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
nuclear@2 9 */
nuclear@2 10
nuclear@2 11 #define PNG_INTERNAL
nuclear@2 12 #define PNG_NO_EXTERN
nuclear@2 13 #include "png.h"
nuclear@2 14
nuclear@2 15 /* Generate a compiler error if there is an old png.h in the search path. */
nuclear@2 16 typedef version_1_2_33 Your_png_h_is_not_version_1_2_33;
nuclear@2 17
nuclear@2 18 /* Version information for C files. This had better match the version
nuclear@2 19 * string defined in png.h. */
nuclear@2 20
nuclear@2 21 #ifdef PNG_USE_GLOBAL_ARRAYS
nuclear@2 22 /* png_libpng_ver was changed to a function in version 1.0.5c */
nuclear@2 23 PNG_CONST char png_libpng_ver[18] = PNG_LIBPNG_VER_STRING;
nuclear@2 24
nuclear@2 25 #ifdef PNG_READ_SUPPORTED
nuclear@2 26
nuclear@2 27 /* png_sig was changed to a function in version 1.0.5c */
nuclear@2 28 /* Place to hold the signature string for a PNG file. */
nuclear@2 29 PNG_CONST png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
nuclear@2 30 #endif /* PNG_READ_SUPPORTED */
nuclear@2 31
nuclear@2 32 /* Invoke global declarations for constant strings for known chunk types */
nuclear@2 33 PNG_IHDR;
nuclear@2 34 PNG_IDAT;
nuclear@2 35 PNG_IEND;
nuclear@2 36 PNG_PLTE;
nuclear@2 37 PNG_bKGD;
nuclear@2 38 PNG_cHRM;
nuclear@2 39 PNG_gAMA;
nuclear@2 40 PNG_hIST;
nuclear@2 41 PNG_iCCP;
nuclear@2 42 PNG_iTXt;
nuclear@2 43 PNG_oFFs;
nuclear@2 44 PNG_pCAL;
nuclear@2 45 PNG_sCAL;
nuclear@2 46 PNG_pHYs;
nuclear@2 47 PNG_sBIT;
nuclear@2 48 PNG_sPLT;
nuclear@2 49 PNG_sRGB;
nuclear@2 50 PNG_tEXt;
nuclear@2 51 PNG_tIME;
nuclear@2 52 PNG_tRNS;
nuclear@2 53 PNG_zTXt;
nuclear@2 54
nuclear@2 55 #ifdef PNG_READ_SUPPORTED
nuclear@2 56 /* arrays to facilitate easy interlacing - use pass (0 - 6) as index */
nuclear@2 57
nuclear@2 58 /* start of interlace block */
nuclear@2 59 PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
nuclear@2 60
nuclear@2 61 /* offset to next interlace block */
nuclear@2 62 PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
nuclear@2 63
nuclear@2 64 /* start of interlace block in the y direction */
nuclear@2 65 PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
nuclear@2 66
nuclear@2 67 /* offset to next interlace block in the y direction */
nuclear@2 68 PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
nuclear@2 69
nuclear@2 70 /* Height of interlace block. This is not currently used - if you need
nuclear@2 71 * it, uncomment it here and in png.h
nuclear@2 72 PNG_CONST int FARDATA png_pass_height[] = {8, 8, 4, 4, 2, 2, 1};
nuclear@2 73 */
nuclear@2 74
nuclear@2 75 /* Mask to determine which pixels are valid in a pass */
nuclear@2 76 PNG_CONST int FARDATA png_pass_mask[] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
nuclear@2 77
nuclear@2 78 /* Mask to determine which pixels to overwrite while displaying */
nuclear@2 79 PNG_CONST int FARDATA png_pass_dsp_mask[]
nuclear@2 80 = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
nuclear@2 81
nuclear@2 82 #endif /* PNG_READ_SUPPORTED */
nuclear@2 83 #endif /* PNG_USE_GLOBAL_ARRAYS */
nuclear@2 84
nuclear@2 85 /* Tells libpng that we have already handled the first "num_bytes" bytes
nuclear@2 86 * of the PNG file signature. If the PNG data is embedded into another
nuclear@2 87 * stream we can set num_bytes = 8 so that libpng will not attempt to read
nuclear@2 88 * or write any of the magic bytes before it starts on the IHDR.
nuclear@2 89 */
nuclear@2 90
nuclear@2 91 #ifdef PNG_READ_SUPPORTED
nuclear@2 92 void PNGAPI
nuclear@2 93 png_set_sig_bytes(png_structp png_ptr, int num_bytes)
nuclear@2 94 {
nuclear@2 95 if (png_ptr == NULL) return;
nuclear@2 96 png_debug(1, "in png_set_sig_bytes\n");
nuclear@2 97 if (num_bytes > 8)
nuclear@2 98 png_error(png_ptr, "Too many bytes for PNG signature.");
nuclear@2 99
nuclear@2 100 png_ptr->sig_bytes = (png_byte)(num_bytes < 0 ? 0 : num_bytes);
nuclear@2 101 }
nuclear@2 102
nuclear@2 103 /* Checks whether the supplied bytes match the PNG signature. We allow
nuclear@2 104 * checking less than the full 8-byte signature so that those apps that
nuclear@2 105 * already read the first few bytes of a file to determine the file type
nuclear@2 106 * can simply check the remaining bytes for extra assurance. Returns
nuclear@2 107 * an integer less than, equal to, or greater than zero if sig is found,
nuclear@2 108 * respectively, to be less than, to match, or be greater than the correct
nuclear@2 109 * PNG signature (this is the same behaviour as strcmp, memcmp, etc).
nuclear@2 110 */
nuclear@2 111 int PNGAPI
nuclear@2 112 png_sig_cmp(png_bytep sig, png_size_t start, png_size_t num_to_check)
nuclear@2 113 {
nuclear@2 114 png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
nuclear@2 115 if (num_to_check > 8)
nuclear@2 116 num_to_check = 8;
nuclear@2 117 else if (num_to_check < 1)
nuclear@2 118 return (-1);
nuclear@2 119
nuclear@2 120 if (start > 7)
nuclear@2 121 return (-1);
nuclear@2 122
nuclear@2 123 if (start + num_to_check > 8)
nuclear@2 124 num_to_check = 8 - start;
nuclear@2 125
nuclear@2 126 return ((int)(png_memcmp(&sig[start], &png_signature[start], num_to_check)));
nuclear@2 127 }
nuclear@2 128
nuclear@2 129 #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
nuclear@2 130 /* (Obsolete) function to check signature bytes. It does not allow one
nuclear@2 131 * to check a partial signature. This function might be removed in the
nuclear@2 132 * future - use png_sig_cmp(). Returns true (nonzero) if the file is PNG.
nuclear@2 133 */
nuclear@2 134 int PNGAPI
nuclear@2 135 png_check_sig(png_bytep sig, int num)
nuclear@2 136 {
nuclear@2 137 return ((int)!png_sig_cmp(sig, (png_size_t)0, (png_size_t)num));
nuclear@2 138 }
nuclear@2 139 #endif
nuclear@2 140 #endif /* PNG_READ_SUPPORTED */
nuclear@2 141
nuclear@2 142 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
nuclear@2 143 /* Function to allocate memory for zlib and clear it to 0. */
nuclear@2 144 #ifdef PNG_1_0_X
nuclear@2 145 voidpf PNGAPI
nuclear@2 146 #else
nuclear@2 147 voidpf /* private */
nuclear@2 148 #endif
nuclear@2 149 png_zalloc(voidpf png_ptr, uInt items, uInt size)
nuclear@2 150 {
nuclear@2 151 png_voidp ptr;
nuclear@2 152 png_structp p=(png_structp)png_ptr;
nuclear@2 153 png_uint_32 save_flags=p->flags;
nuclear@2 154 png_uint_32 num_bytes;
nuclear@2 155
nuclear@2 156 if (png_ptr == NULL) return (NULL);
nuclear@2 157 if (items > PNG_UINT_32_MAX/size)
nuclear@2 158 {
nuclear@2 159 png_warning (p, "Potential overflow in png_zalloc()");
nuclear@2 160 return (NULL);
nuclear@2 161 }
nuclear@2 162 num_bytes = (png_uint_32)items * size;
nuclear@2 163
nuclear@2 164 p->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
nuclear@2 165 ptr = (png_voidp)png_malloc((png_structp)png_ptr, num_bytes);
nuclear@2 166 p->flags=save_flags;
nuclear@2 167
nuclear@2 168 #if defined(PNG_1_0_X) && !defined(PNG_NO_ZALLOC_ZERO)
nuclear@2 169 if (ptr == NULL)
nuclear@2 170 return ((voidpf)ptr);
nuclear@2 171
nuclear@2 172 if (num_bytes > (png_uint_32)0x8000L)
nuclear@2 173 {
nuclear@2 174 png_memset(ptr, 0, (png_size_t)0x8000L);
nuclear@2 175 png_memset((png_bytep)ptr + (png_size_t)0x8000L, 0,
nuclear@2 176 (png_size_t)(num_bytes - (png_uint_32)0x8000L));
nuclear@2 177 }
nuclear@2 178 else
nuclear@2 179 {
nuclear@2 180 png_memset(ptr, 0, (png_size_t)num_bytes);
nuclear@2 181 }
nuclear@2 182 #endif
nuclear@2 183 return ((voidpf)ptr);
nuclear@2 184 }
nuclear@2 185
nuclear@2 186 /* function to free memory for zlib */
nuclear@2 187 #ifdef PNG_1_0_X
nuclear@2 188 void PNGAPI
nuclear@2 189 #else
nuclear@2 190 void /* private */
nuclear@2 191 #endif
nuclear@2 192 png_zfree(voidpf png_ptr, voidpf ptr)
nuclear@2 193 {
nuclear@2 194 png_free((png_structp)png_ptr, (png_voidp)ptr);
nuclear@2 195 }
nuclear@2 196
nuclear@2 197 /* Reset the CRC variable to 32 bits of 1's. Care must be taken
nuclear@2 198 * in case CRC is > 32 bits to leave the top bits 0.
nuclear@2 199 */
nuclear@2 200 void /* PRIVATE */
nuclear@2 201 png_reset_crc(png_structp png_ptr)
nuclear@2 202 {
nuclear@2 203 png_ptr->crc = crc32(0, Z_NULL, 0);
nuclear@2 204 }
nuclear@2 205
nuclear@2 206 /* Calculate the CRC over a section of data. We can only pass as
nuclear@2 207 * much data to this routine as the largest single buffer size. We
nuclear@2 208 * also check that this data will actually be used before going to the
nuclear@2 209 * trouble of calculating it.
nuclear@2 210 */
nuclear@2 211 void /* PRIVATE */
nuclear@2 212 png_calculate_crc(png_structp png_ptr, png_bytep ptr, png_size_t length)
nuclear@2 213 {
nuclear@2 214 int need_crc = 1;
nuclear@2 215
nuclear@2 216 if (png_ptr->chunk_name[0] & 0x20) /* ancillary */
nuclear@2 217 {
nuclear@2 218 if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
nuclear@2 219 (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
nuclear@2 220 need_crc = 0;
nuclear@2 221 }
nuclear@2 222 else /* critical */
nuclear@2 223 {
nuclear@2 224 if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
nuclear@2 225 need_crc = 0;
nuclear@2 226 }
nuclear@2 227
nuclear@2 228 if (need_crc)
nuclear@2 229 png_ptr->crc = crc32(png_ptr->crc, ptr, (uInt)length);
nuclear@2 230 }
nuclear@2 231
nuclear@2 232 /* Allocate the memory for an info_struct for the application. We don't
nuclear@2 233 * really need the png_ptr, but it could potentially be useful in the
nuclear@2 234 * future. This should be used in favour of malloc(png_sizeof(png_info))
nuclear@2 235 * and png_info_init() so that applications that want to use a shared
nuclear@2 236 * libpng don't have to be recompiled if png_info changes size.
nuclear@2 237 */
nuclear@2 238 png_infop PNGAPI
nuclear@2 239 png_create_info_struct(png_structp png_ptr)
nuclear@2 240 {
nuclear@2 241 png_infop info_ptr;
nuclear@2 242
nuclear@2 243 png_debug(1, "in png_create_info_struct\n");
nuclear@2 244 if (png_ptr == NULL) return (NULL);
nuclear@2 245 #ifdef PNG_USER_MEM_SUPPORTED
nuclear@2 246 info_ptr = (png_infop)png_create_struct_2(PNG_STRUCT_INFO,
nuclear@2 247 png_ptr->malloc_fn, png_ptr->mem_ptr);
nuclear@2 248 #else
nuclear@2 249 info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
nuclear@2 250 #endif
nuclear@2 251 if (info_ptr != NULL)
nuclear@2 252 png_info_init_3(&info_ptr, png_sizeof(png_info));
nuclear@2 253
nuclear@2 254 return (info_ptr);
nuclear@2 255 }
nuclear@2 256
nuclear@2 257 /* This function frees the memory associated with a single info struct.
nuclear@2 258 * Normally, one would use either png_destroy_read_struct() or
nuclear@2 259 * png_destroy_write_struct() to free an info struct, but this may be
nuclear@2 260 * useful for some applications.
nuclear@2 261 */
nuclear@2 262 void PNGAPI
nuclear@2 263 png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr)
nuclear@2 264 {
nuclear@2 265 png_infop info_ptr = NULL;
nuclear@2 266 if (png_ptr == NULL) return;
nuclear@2 267
nuclear@2 268 png_debug(1, "in png_destroy_info_struct\n");
nuclear@2 269 if (info_ptr_ptr != NULL)
nuclear@2 270 info_ptr = *info_ptr_ptr;
nuclear@2 271
nuclear@2 272 if (info_ptr != NULL)
nuclear@2 273 {
nuclear@2 274 png_info_destroy(png_ptr, info_ptr);
nuclear@2 275
nuclear@2 276 #ifdef PNG_USER_MEM_SUPPORTED
nuclear@2 277 png_destroy_struct_2((png_voidp)info_ptr, png_ptr->free_fn,
nuclear@2 278 png_ptr->mem_ptr);
nuclear@2 279 #else
nuclear@2 280 png_destroy_struct((png_voidp)info_ptr);
nuclear@2 281 #endif
nuclear@2 282 *info_ptr_ptr = NULL;
nuclear@2 283 }
nuclear@2 284 }
nuclear@2 285
nuclear@2 286 /* Initialize the info structure. This is now an internal function (0.89)
nuclear@2 287 * and applications using it are urged to use png_create_info_struct()
nuclear@2 288 * instead.
nuclear@2 289 */
nuclear@2 290 #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
nuclear@2 291 #undef png_info_init
nuclear@2 292 void PNGAPI
nuclear@2 293 png_info_init(png_infop info_ptr)
nuclear@2 294 {
nuclear@2 295 /* We only come here via pre-1.0.12-compiled applications */
nuclear@2 296 png_info_init_3(&info_ptr, 0);
nuclear@2 297 }
nuclear@2 298 #endif
nuclear@2 299
nuclear@2 300 void PNGAPI
nuclear@2 301 png_info_init_3(png_infopp ptr_ptr, png_size_t png_info_struct_size)
nuclear@2 302 {
nuclear@2 303 png_infop info_ptr = *ptr_ptr;
nuclear@2 304
nuclear@2 305 if (info_ptr == NULL) return;
nuclear@2 306
nuclear@2 307 png_debug(1, "in png_info_init_3\n");
nuclear@2 308
nuclear@2 309 if (png_sizeof(png_info) > png_info_struct_size)
nuclear@2 310 {
nuclear@2 311 png_destroy_struct(info_ptr);
nuclear@2 312 info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
nuclear@2 313 *ptr_ptr = info_ptr;
nuclear@2 314 }
nuclear@2 315
nuclear@2 316 /* set everything to 0 */
nuclear@2 317 png_memset(info_ptr, 0, png_sizeof(png_info));
nuclear@2 318 }
nuclear@2 319
nuclear@2 320 #ifdef PNG_FREE_ME_SUPPORTED
nuclear@2 321 void PNGAPI
nuclear@2 322 png_data_freer(png_structp png_ptr, png_infop info_ptr,
nuclear@2 323 int freer, png_uint_32 mask)
nuclear@2 324 {
nuclear@2 325 png_debug(1, "in png_data_freer\n");
nuclear@2 326 if (png_ptr == NULL || info_ptr == NULL)
nuclear@2 327 return;
nuclear@2 328 if (freer == PNG_DESTROY_WILL_FREE_DATA)
nuclear@2 329 info_ptr->free_me |= mask;
nuclear@2 330 else if (freer == PNG_USER_WILL_FREE_DATA)
nuclear@2 331 info_ptr->free_me &= ~mask;
nuclear@2 332 else
nuclear@2 333 png_warning(png_ptr,
nuclear@2 334 "Unknown freer parameter in png_data_freer.");
nuclear@2 335 }
nuclear@2 336 #endif
nuclear@2 337
nuclear@2 338 void PNGAPI
nuclear@2 339 png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask,
nuclear@2 340 int num)
nuclear@2 341 {
nuclear@2 342 png_debug(1, "in png_free_data\n");
nuclear@2 343 if (png_ptr == NULL || info_ptr == NULL)
nuclear@2 344 return;
nuclear@2 345
nuclear@2 346 #if defined(PNG_TEXT_SUPPORTED)
nuclear@2 347 /* free text item num or (if num == -1) all text items */
nuclear@2 348 #ifdef PNG_FREE_ME_SUPPORTED
nuclear@2 349 if ((mask & PNG_FREE_TEXT) & info_ptr->free_me)
nuclear@2 350 #else
nuclear@2 351 if (mask & PNG_FREE_TEXT)
nuclear@2 352 #endif
nuclear@2 353 {
nuclear@2 354 if (num != -1)
nuclear@2 355 {
nuclear@2 356 if (info_ptr->text && info_ptr->text[num].key)
nuclear@2 357 {
nuclear@2 358 png_free(png_ptr, info_ptr->text[num].key);
nuclear@2 359 info_ptr->text[num].key = NULL;
nuclear@2 360 }
nuclear@2 361 }
nuclear@2 362 else
nuclear@2 363 {
nuclear@2 364 int i;
nuclear@2 365 for (i = 0; i < info_ptr->num_text; i++)
nuclear@2 366 png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, i);
nuclear@2 367 png_free(png_ptr, info_ptr->text);
nuclear@2 368 info_ptr->text = NULL;
nuclear@2 369 info_ptr->num_text=0;
nuclear@2 370 }
nuclear@2 371 }
nuclear@2 372 #endif
nuclear@2 373
nuclear@2 374 #if defined(PNG_tRNS_SUPPORTED)
nuclear@2 375 /* free any tRNS entry */
nuclear@2 376 #ifdef PNG_FREE_ME_SUPPORTED
nuclear@2 377 if ((mask & PNG_FREE_TRNS) & info_ptr->free_me)
nuclear@2 378 #else
nuclear@2 379 if ((mask & PNG_FREE_TRNS) && (png_ptr->flags & PNG_FLAG_FREE_TRNS))
nuclear@2 380 #endif
nuclear@2 381 {
nuclear@2 382 png_free(png_ptr, info_ptr->trans);
nuclear@2 383 info_ptr->trans = NULL;
nuclear@2 384 info_ptr->valid &= ~PNG_INFO_tRNS;
nuclear@2 385 #ifndef PNG_FREE_ME_SUPPORTED
nuclear@2 386 png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
nuclear@2 387 #endif
nuclear@2 388 }
nuclear@2 389 #endif
nuclear@2 390
nuclear@2 391 #if defined(PNG_sCAL_SUPPORTED)
nuclear@2 392 /* free any sCAL entry */
nuclear@2 393 #ifdef PNG_FREE_ME_SUPPORTED
nuclear@2 394 if ((mask & PNG_FREE_SCAL) & info_ptr->free_me)
nuclear@2 395 #else
nuclear@2 396 if (mask & PNG_FREE_SCAL)
nuclear@2 397 #endif
nuclear@2 398 {
nuclear@2 399 #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
nuclear@2 400 png_free(png_ptr, info_ptr->scal_s_width);
nuclear@2 401 png_free(png_ptr, info_ptr->scal_s_height);
nuclear@2 402 info_ptr->scal_s_width = NULL;
nuclear@2 403 info_ptr->scal_s_height = NULL;
nuclear@2 404 #endif
nuclear@2 405 info_ptr->valid &= ~PNG_INFO_sCAL;
nuclear@2 406 }
nuclear@2 407 #endif
nuclear@2 408
nuclear@2 409 #if defined(PNG_pCAL_SUPPORTED)
nuclear@2 410 /* free any pCAL entry */
nuclear@2 411 #ifdef PNG_FREE_ME_SUPPORTED
nuclear@2 412 if ((mask & PNG_FREE_PCAL) & info_ptr->free_me)
nuclear@2 413 #else
nuclear@2 414 if (mask & PNG_FREE_PCAL)
nuclear@2 415 #endif
nuclear@2 416 {
nuclear@2 417 png_free(png_ptr, info_ptr->pcal_purpose);
nuclear@2 418 png_free(png_ptr, info_ptr->pcal_units);
nuclear@2 419 info_ptr->pcal_purpose = NULL;
nuclear@2 420 info_ptr->pcal_units = NULL;
nuclear@2 421 if (info_ptr->pcal_params != NULL)
nuclear@2 422 {
nuclear@2 423 int i;
nuclear@2 424 for (i = 0; i < (int)info_ptr->pcal_nparams; i++)
nuclear@2 425 {
nuclear@2 426 png_free(png_ptr, info_ptr->pcal_params[i]);
nuclear@2 427 info_ptr->pcal_params[i]=NULL;
nuclear@2 428 }
nuclear@2 429 png_free(png_ptr, info_ptr->pcal_params);
nuclear@2 430 info_ptr->pcal_params = NULL;
nuclear@2 431 }
nuclear@2 432 info_ptr->valid &= ~PNG_INFO_pCAL;
nuclear@2 433 }
nuclear@2 434 #endif
nuclear@2 435
nuclear@2 436 #if defined(PNG_iCCP_SUPPORTED)
nuclear@2 437 /* free any iCCP entry */
nuclear@2 438 #ifdef PNG_FREE_ME_SUPPORTED
nuclear@2 439 if ((mask & PNG_FREE_ICCP) & info_ptr->free_me)
nuclear@2 440 #else
nuclear@2 441 if (mask & PNG_FREE_ICCP)
nuclear@2 442 #endif
nuclear@2 443 {
nuclear@2 444 png_free(png_ptr, info_ptr->iccp_name);
nuclear@2 445 png_free(png_ptr, info_ptr->iccp_profile);
nuclear@2 446 info_ptr->iccp_name = NULL;
nuclear@2 447 info_ptr->iccp_profile = NULL;
nuclear@2 448 info_ptr->valid &= ~PNG_INFO_iCCP;
nuclear@2 449 }
nuclear@2 450 #endif
nuclear@2 451
nuclear@2 452 #if defined(PNG_sPLT_SUPPORTED)
nuclear@2 453 /* free a given sPLT entry, or (if num == -1) all sPLT entries */
nuclear@2 454 #ifdef PNG_FREE_ME_SUPPORTED
nuclear@2 455 if ((mask & PNG_FREE_SPLT) & info_ptr->free_me)
nuclear@2 456 #else
nuclear@2 457 if (mask & PNG_FREE_SPLT)
nuclear@2 458 #endif
nuclear@2 459 {
nuclear@2 460 if (num != -1)
nuclear@2 461 {
nuclear@2 462 if (info_ptr->splt_palettes)
nuclear@2 463 {
nuclear@2 464 png_free(png_ptr, info_ptr->splt_palettes[num].name);
nuclear@2 465 png_free(png_ptr, info_ptr->splt_palettes[num].entries);
nuclear@2 466 info_ptr->splt_palettes[num].name = NULL;
nuclear@2 467 info_ptr->splt_palettes[num].entries = NULL;
nuclear@2 468 }
nuclear@2 469 }
nuclear@2 470 else
nuclear@2 471 {
nuclear@2 472 if (info_ptr->splt_palettes_num)
nuclear@2 473 {
nuclear@2 474 int i;
nuclear@2 475 for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
nuclear@2 476 png_free_data(png_ptr, info_ptr, PNG_FREE_SPLT, i);
nuclear@2 477
nuclear@2 478 png_free(png_ptr, info_ptr->splt_palettes);
nuclear@2 479 info_ptr->splt_palettes = NULL;
nuclear@2 480 info_ptr->splt_palettes_num = 0;
nuclear@2 481 }
nuclear@2 482 info_ptr->valid &= ~PNG_INFO_sPLT;
nuclear@2 483 }
nuclear@2 484 }
nuclear@2 485 #endif
nuclear@2 486
nuclear@2 487 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
nuclear@2 488 if (png_ptr->unknown_chunk.data)
nuclear@2 489 {
nuclear@2 490 png_free(png_ptr, png_ptr->unknown_chunk.data);
nuclear@2 491 png_ptr->unknown_chunk.data = NULL;
nuclear@2 492 }
nuclear@2 493
nuclear@2 494 #ifdef PNG_FREE_ME_SUPPORTED
nuclear@2 495 if ((mask & PNG_FREE_UNKN) & info_ptr->free_me)
nuclear@2 496 #else
nuclear@2 497 if (mask & PNG_FREE_UNKN)
nuclear@2 498 #endif
nuclear@2 499 {
nuclear@2 500 if (num != -1)
nuclear@2 501 {
nuclear@2 502 if (info_ptr->unknown_chunks)
nuclear@2 503 {
nuclear@2 504 png_free(png_ptr, info_ptr->unknown_chunks[num].data);
nuclear@2 505 info_ptr->unknown_chunks[num].data = NULL;
nuclear@2 506 }
nuclear@2 507 }
nuclear@2 508 else
nuclear@2 509 {
nuclear@2 510 int i;
nuclear@2 511
nuclear@2 512 if (info_ptr->unknown_chunks_num)
nuclear@2 513 {
nuclear@2 514 for (i = 0; i < (int)info_ptr->unknown_chunks_num; i++)
nuclear@2 515 png_free_data(png_ptr, info_ptr, PNG_FREE_UNKN, i);
nuclear@2 516
nuclear@2 517 png_free(png_ptr, info_ptr->unknown_chunks);
nuclear@2 518 info_ptr->unknown_chunks = NULL;
nuclear@2 519 info_ptr->unknown_chunks_num = 0;
nuclear@2 520 }
nuclear@2 521 }
nuclear@2 522 }
nuclear@2 523 #endif
nuclear@2 524
nuclear@2 525 #if defined(PNG_hIST_SUPPORTED)
nuclear@2 526 /* free any hIST entry */
nuclear@2 527 #ifdef PNG_FREE_ME_SUPPORTED
nuclear@2 528 if ((mask & PNG_FREE_HIST) & info_ptr->free_me)
nuclear@2 529 #else
nuclear@2 530 if ((mask & PNG_FREE_HIST) && (png_ptr->flags & PNG_FLAG_FREE_HIST))
nuclear@2 531 #endif
nuclear@2 532 {
nuclear@2 533 png_free(png_ptr, info_ptr->hist);
nuclear@2 534 info_ptr->hist = NULL;
nuclear@2 535 info_ptr->valid &= ~PNG_INFO_hIST;
nuclear@2 536 #ifndef PNG_FREE_ME_SUPPORTED
nuclear@2 537 png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
nuclear@2 538 #endif
nuclear@2 539 }
nuclear@2 540 #endif
nuclear@2 541
nuclear@2 542 /* free any PLTE entry that was internally allocated */
nuclear@2 543 #ifdef PNG_FREE_ME_SUPPORTED
nuclear@2 544 if ((mask & PNG_FREE_PLTE) & info_ptr->free_me)
nuclear@2 545 #else
nuclear@2 546 if ((mask & PNG_FREE_PLTE) && (png_ptr->flags & PNG_FLAG_FREE_PLTE))
nuclear@2 547 #endif
nuclear@2 548 {
nuclear@2 549 png_zfree(png_ptr, info_ptr->palette);
nuclear@2 550 info_ptr->palette = NULL;
nuclear@2 551 info_ptr->valid &= ~PNG_INFO_PLTE;
nuclear@2 552 #ifndef PNG_FREE_ME_SUPPORTED
nuclear@2 553 png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;
nuclear@2 554 #endif
nuclear@2 555 info_ptr->num_palette = 0;
nuclear@2 556 }
nuclear@2 557
nuclear@2 558 #if defined(PNG_INFO_IMAGE_SUPPORTED)
nuclear@2 559 /* free any image bits attached to the info structure */
nuclear@2 560 #ifdef PNG_FREE_ME_SUPPORTED
nuclear@2 561 if ((mask & PNG_FREE_ROWS) & info_ptr->free_me)
nuclear@2 562 #else
nuclear@2 563 if (mask & PNG_FREE_ROWS)
nuclear@2 564 #endif
nuclear@2 565 {
nuclear@2 566 if (info_ptr->row_pointers)
nuclear@2 567 {
nuclear@2 568 int row;
nuclear@2 569 for (row = 0; row < (int)info_ptr->height; row++)
nuclear@2 570 {
nuclear@2 571 png_free(png_ptr, info_ptr->row_pointers[row]);
nuclear@2 572 info_ptr->row_pointers[row]=NULL;
nuclear@2 573 }
nuclear@2 574 png_free(png_ptr, info_ptr->row_pointers);
nuclear@2 575 info_ptr->row_pointers=NULL;
nuclear@2 576 }
nuclear@2 577 info_ptr->valid &= ~PNG_INFO_IDAT;
nuclear@2 578 }
nuclear@2 579 #endif
nuclear@2 580
nuclear@2 581 #ifdef PNG_FREE_ME_SUPPORTED
nuclear@2 582 if (num == -1)
nuclear@2 583 info_ptr->free_me &= ~mask;
nuclear@2 584 else
nuclear@2 585 info_ptr->free_me &= ~(mask & ~PNG_FREE_MUL);
nuclear@2 586 #endif
nuclear@2 587 }
nuclear@2 588
nuclear@2 589 /* This is an internal routine to free any memory that the info struct is
nuclear@2 590 * pointing to before re-using it or freeing the struct itself. Recall
nuclear@2 591 * that png_free() checks for NULL pointers for us.
nuclear@2 592 */
nuclear@2 593 void /* PRIVATE */
nuclear@2 594 png_info_destroy(png_structp png_ptr, png_infop info_ptr)
nuclear@2 595 {
nuclear@2 596 png_debug(1, "in png_info_destroy\n");
nuclear@2 597
nuclear@2 598 png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
nuclear@2 599
nuclear@2 600 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
nuclear@2 601 if (png_ptr->num_chunk_list)
nuclear@2 602 {
nuclear@2 603 png_free(png_ptr, png_ptr->chunk_list);
nuclear@2 604 png_ptr->chunk_list=NULL;
nuclear@2 605 png_ptr->num_chunk_list = 0;
nuclear@2 606 }
nuclear@2 607 #endif
nuclear@2 608
nuclear@2 609 png_info_init_3(&info_ptr, png_sizeof(png_info));
nuclear@2 610 }
nuclear@2 611 #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
nuclear@2 612
nuclear@2 613 /* This function returns a pointer to the io_ptr associated with the user
nuclear@2 614 * functions. The application should free any memory associated with this
nuclear@2 615 * pointer before png_write_destroy() or png_read_destroy() are called.
nuclear@2 616 */
nuclear@2 617 png_voidp PNGAPI
nuclear@2 618 png_get_io_ptr(png_structp png_ptr)
nuclear@2 619 {
nuclear@2 620 if (png_ptr == NULL) return (NULL);
nuclear@2 621 return (png_ptr->io_ptr);
nuclear@2 622 }
nuclear@2 623
nuclear@2 624 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
nuclear@2 625 #if !defined(PNG_NO_STDIO)
nuclear@2 626 /* Initialize the default input/output functions for the PNG file. If you
nuclear@2 627 * use your own read or write routines, you can call either png_set_read_fn()
nuclear@2 628 * or png_set_write_fn() instead of png_init_io(). If you have defined
nuclear@2 629 * PNG_NO_STDIO, you must use a function of your own because "FILE *" isn't
nuclear@2 630 * necessarily available.
nuclear@2 631 */
nuclear@2 632 void PNGAPI
nuclear@2 633 png_init_io(png_structp png_ptr, png_FILE_p fp)
nuclear@2 634 {
nuclear@2 635 png_debug(1, "in png_init_io\n");
nuclear@2 636 if (png_ptr == NULL) return;
nuclear@2 637 png_ptr->io_ptr = (png_voidp)fp;
nuclear@2 638 }
nuclear@2 639 #endif
nuclear@2 640
nuclear@2 641 #if defined(PNG_TIME_RFC1123_SUPPORTED)
nuclear@2 642 /* Convert the supplied time into an RFC 1123 string suitable for use in
nuclear@2 643 * a "Creation Time" or other text-based time string.
nuclear@2 644 */
nuclear@2 645 png_charp PNGAPI
nuclear@2 646 png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime)
nuclear@2 647 {
nuclear@2 648 static PNG_CONST char short_months[12][4] =
nuclear@2 649 {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
nuclear@2 650 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
nuclear@2 651
nuclear@2 652 if (png_ptr == NULL) return (NULL);
nuclear@2 653 if (png_ptr->time_buffer == NULL)
nuclear@2 654 {
nuclear@2 655 png_ptr->time_buffer = (png_charp)png_malloc(png_ptr, (png_uint_32)(29*
nuclear@2 656 png_sizeof(char)));
nuclear@2 657 }
nuclear@2 658
nuclear@2 659 #if defined(_WIN32_WCE)
nuclear@2 660 {
nuclear@2 661 wchar_t time_buf[29];
nuclear@2 662 wsprintf(time_buf, TEXT("%d %S %d %02d:%02d:%02d +0000"),
nuclear@2 663 ptime->day % 32, short_months[(ptime->month - 1) % 12],
nuclear@2 664 ptime->year, ptime->hour % 24, ptime->minute % 60,
nuclear@2 665 ptime->second % 61);
nuclear@2 666 WideCharToMultiByte(CP_ACP, 0, time_buf, -1, png_ptr->time_buffer, 29,
nuclear@2 667 NULL, NULL);
nuclear@2 668 }
nuclear@2 669 #else
nuclear@2 670 #ifdef USE_FAR_KEYWORD
nuclear@2 671 {
nuclear@2 672 char near_time_buf[29];
nuclear@2 673 png_snprintf6(near_time_buf, 29, "%d %s %d %02d:%02d:%02d +0000",
nuclear@2 674 ptime->day % 32, short_months[(ptime->month - 1) % 12],
nuclear@2 675 ptime->year, ptime->hour % 24, ptime->minute % 60,
nuclear@2 676 ptime->second % 61);
nuclear@2 677 png_memcpy(png_ptr->time_buffer, near_time_buf,
nuclear@2 678 29*png_sizeof(char));
nuclear@2 679 }
nuclear@2 680 #else
nuclear@2 681 png_snprintf6(png_ptr->time_buffer, 29, "%d %s %d %02d:%02d:%02d +0000",
nuclear@2 682 ptime->day % 32, short_months[(ptime->month - 1) % 12],
nuclear@2 683 ptime->year, ptime->hour % 24, ptime->minute % 60,
nuclear@2 684 ptime->second % 61);
nuclear@2 685 #endif
nuclear@2 686 #endif /* _WIN32_WCE */
nuclear@2 687 return ((png_charp)png_ptr->time_buffer);
nuclear@2 688 }
nuclear@2 689 #endif /* PNG_TIME_RFC1123_SUPPORTED */
nuclear@2 690
nuclear@2 691 #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
nuclear@2 692
nuclear@2 693 png_charp PNGAPI
nuclear@2 694 png_get_copyright(png_structp png_ptr)
nuclear@2 695 {
nuclear@2 696 png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
nuclear@2 697 return ((png_charp) "\n libpng version 1.2.33 - October 31, 2008\n\
nuclear@2 698 Copyright (c) 1998-2008 Glenn Randers-Pehrson\n\
nuclear@2 699 Copyright (c) 1996-1997 Andreas Dilger\n\
nuclear@2 700 Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.\n");
nuclear@2 701 }
nuclear@2 702
nuclear@2 703 /* The following return the library version as a short string in the
nuclear@2 704 * format 1.0.0 through 99.99.99zz. To get the version of *.h files
nuclear@2 705 * used with your application, print out PNG_LIBPNG_VER_STRING, which
nuclear@2 706 * is defined in png.h.
nuclear@2 707 * Note: now there is no difference between png_get_libpng_ver() and
nuclear@2 708 * png_get_header_ver(). Due to the version_nn_nn_nn typedef guard,
nuclear@2 709 * it is guaranteed that png.c uses the correct version of png.h.
nuclear@2 710 */
nuclear@2 711 png_charp PNGAPI
nuclear@2 712 png_get_libpng_ver(png_structp png_ptr)
nuclear@2 713 {
nuclear@2 714 /* Version of *.c files used when building libpng */
nuclear@2 715 png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
nuclear@2 716 return ((png_charp) PNG_LIBPNG_VER_STRING);
nuclear@2 717 }
nuclear@2 718
nuclear@2 719 png_charp PNGAPI
nuclear@2 720 png_get_header_ver(png_structp png_ptr)
nuclear@2 721 {
nuclear@2 722 /* Version of *.h files used when building libpng */
nuclear@2 723 png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
nuclear@2 724 return ((png_charp) PNG_LIBPNG_VER_STRING);
nuclear@2 725 }
nuclear@2 726
nuclear@2 727 png_charp PNGAPI
nuclear@2 728 png_get_header_version(png_structp png_ptr)
nuclear@2 729 {
nuclear@2 730 /* Returns longer string containing both version and date */
nuclear@2 731 png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
nuclear@2 732 return ((png_charp) PNG_HEADER_VERSION_STRING
nuclear@2 733 #ifndef PNG_READ_SUPPORTED
nuclear@2 734 " (NO READ SUPPORT)"
nuclear@2 735 #endif
nuclear@2 736 "\n");
nuclear@2 737 }
nuclear@2 738
nuclear@2 739 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
nuclear@2 740 #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
nuclear@2 741 int PNGAPI
nuclear@2 742 png_handle_as_unknown(png_structp png_ptr, png_bytep chunk_name)
nuclear@2 743 {
nuclear@2 744 /* check chunk_name and return "keep" value if it's on the list, else 0 */
nuclear@2 745 int i;
nuclear@2 746 png_bytep p;
nuclear@2 747 if (png_ptr == NULL || chunk_name == NULL || png_ptr->num_chunk_list<=0)
nuclear@2 748 return 0;
nuclear@2 749 p = png_ptr->chunk_list + png_ptr->num_chunk_list*5 - 5;
nuclear@2 750 for (i = png_ptr->num_chunk_list; i; i--, p -= 5)
nuclear@2 751 if (!png_memcmp(chunk_name, p, 4))
nuclear@2 752 return ((int)*(p + 4));
nuclear@2 753 return 0;
nuclear@2 754 }
nuclear@2 755 #endif
nuclear@2 756
nuclear@2 757 /* This function, added to libpng-1.0.6g, is untested. */
nuclear@2 758 int PNGAPI
nuclear@2 759 png_reset_zstream(png_structp png_ptr)
nuclear@2 760 {
nuclear@2 761 if (png_ptr == NULL) return Z_STREAM_ERROR;
nuclear@2 762 return (inflateReset(&png_ptr->zstream));
nuclear@2 763 }
nuclear@2 764 #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
nuclear@2 765
nuclear@2 766 /* This function was added to libpng-1.0.7 */
nuclear@2 767 png_uint_32 PNGAPI
nuclear@2 768 png_access_version_number(void)
nuclear@2 769 {
nuclear@2 770 /* Version of *.c files used when building libpng */
nuclear@2 771 return((png_uint_32) PNG_LIBPNG_VER);
nuclear@2 772 }
nuclear@2 773
nuclear@2 774
nuclear@2 775 #if defined(PNG_READ_SUPPORTED) && defined(PNG_ASSEMBLER_CODE_SUPPORTED)
nuclear@2 776 #if !defined(PNG_1_0_X)
nuclear@2 777 /* this function was added to libpng 1.2.0 */
nuclear@2 778 int PNGAPI
nuclear@2 779 png_mmx_support(void)
nuclear@2 780 {
nuclear@2 781 /* obsolete, to be removed from libpng-1.4.0 */
nuclear@2 782 return -1;
nuclear@2 783 }
nuclear@2 784 #endif /* PNG_1_0_X */
nuclear@2 785 #endif /* PNG_READ_SUPPORTED && PNG_ASSEMBLER_CODE_SUPPORTED */
nuclear@2 786
nuclear@2 787 #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
nuclear@2 788 #ifdef PNG_SIZE_T
nuclear@2 789 /* Added at libpng version 1.2.6 */
nuclear@2 790 PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size));
nuclear@2 791 png_size_t PNGAPI
nuclear@2 792 png_convert_size(size_t size)
nuclear@2 793 {
nuclear@2 794 if (size > (png_size_t)-1)
nuclear@2 795 PNG_ABORT(); /* We haven't got access to png_ptr, so no png_error() */
nuclear@2 796 return ((png_size_t)size);
nuclear@2 797 }
nuclear@2 798 #endif /* PNG_SIZE_T */
nuclear@2 799 #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */