istereo2

diff libs/libpng/png.c @ 2:81d35769f546

added the tunnel effect source
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 19 Sep 2015 05:51:51 +0300
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/libs/libpng/png.c	Sat Sep 19 05:51:51 2015 +0300
     1.3 @@ -0,0 +1,799 @@
     1.4 +
     1.5 +/* png.c - location for general purpose libpng functions
     1.6 + *
     1.7 + * Last changed in libpng 1.2.30 [August 15, 2008]
     1.8 + * For conditions of distribution and use, see copyright notice in png.h
     1.9 + * Copyright (c) 1998-2008 Glenn Randers-Pehrson
    1.10 + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
    1.11 + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
    1.12 + */
    1.13 +
    1.14 +#define PNG_INTERNAL
    1.15 +#define PNG_NO_EXTERN
    1.16 +#include "png.h"
    1.17 +
    1.18 +/* Generate a compiler error if there is an old png.h in the search path. */
    1.19 +typedef version_1_2_33 Your_png_h_is_not_version_1_2_33;
    1.20 +
    1.21 +/* Version information for C files.  This had better match the version
    1.22 + * string defined in png.h.  */
    1.23 +
    1.24 +#ifdef PNG_USE_GLOBAL_ARRAYS
    1.25 +/* png_libpng_ver was changed to a function in version 1.0.5c */
    1.26 +PNG_CONST char png_libpng_ver[18] = PNG_LIBPNG_VER_STRING;
    1.27 +
    1.28 +#ifdef PNG_READ_SUPPORTED
    1.29 +
    1.30 +/* png_sig was changed to a function in version 1.0.5c */
    1.31 +/* Place to hold the signature string for a PNG file. */
    1.32 +PNG_CONST png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
    1.33 +#endif /* PNG_READ_SUPPORTED */
    1.34 +
    1.35 +/* Invoke global declarations for constant strings for known chunk types */
    1.36 +PNG_IHDR;
    1.37 +PNG_IDAT;
    1.38 +PNG_IEND;
    1.39 +PNG_PLTE;
    1.40 +PNG_bKGD;
    1.41 +PNG_cHRM;
    1.42 +PNG_gAMA;
    1.43 +PNG_hIST;
    1.44 +PNG_iCCP;
    1.45 +PNG_iTXt;
    1.46 +PNG_oFFs;
    1.47 +PNG_pCAL;
    1.48 +PNG_sCAL;
    1.49 +PNG_pHYs;
    1.50 +PNG_sBIT;
    1.51 +PNG_sPLT;
    1.52 +PNG_sRGB;
    1.53 +PNG_tEXt;
    1.54 +PNG_tIME;
    1.55 +PNG_tRNS;
    1.56 +PNG_zTXt;
    1.57 +
    1.58 +#ifdef PNG_READ_SUPPORTED
    1.59 +/* arrays to facilitate easy interlacing - use pass (0 - 6) as index */
    1.60 +
    1.61 +/* start of interlace block */
    1.62 +PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
    1.63 +
    1.64 +/* offset to next interlace block */
    1.65 +PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
    1.66 +
    1.67 +/* start of interlace block in the y direction */
    1.68 +PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
    1.69 +
    1.70 +/* offset to next interlace block in the y direction */
    1.71 +PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
    1.72 +
    1.73 +/* Height of interlace block.  This is not currently used - if you need
    1.74 + * it, uncomment it here and in png.h
    1.75 +PNG_CONST int FARDATA png_pass_height[] = {8, 8, 4, 4, 2, 2, 1};
    1.76 +*/
    1.77 +
    1.78 +/* Mask to determine which pixels are valid in a pass */
    1.79 +PNG_CONST int FARDATA png_pass_mask[] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
    1.80 +
    1.81 +/* Mask to determine which pixels to overwrite while displaying */
    1.82 +PNG_CONST int FARDATA png_pass_dsp_mask[]
    1.83 +   = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
    1.84 +
    1.85 +#endif /* PNG_READ_SUPPORTED */
    1.86 +#endif /* PNG_USE_GLOBAL_ARRAYS */
    1.87 +
    1.88 +/* Tells libpng that we have already handled the first "num_bytes" bytes
    1.89 + * of the PNG file signature.  If the PNG data is embedded into another
    1.90 + * stream we can set num_bytes = 8 so that libpng will not attempt to read
    1.91 + * or write any of the magic bytes before it starts on the IHDR.
    1.92 + */
    1.93 +
    1.94 +#ifdef PNG_READ_SUPPORTED
    1.95 +void PNGAPI
    1.96 +png_set_sig_bytes(png_structp png_ptr, int num_bytes)
    1.97 +{
    1.98 +   if (png_ptr == NULL) return;
    1.99 +   png_debug(1, "in png_set_sig_bytes\n");
   1.100 +   if (num_bytes > 8)
   1.101 +      png_error(png_ptr, "Too many bytes for PNG signature.");
   1.102 +
   1.103 +   png_ptr->sig_bytes = (png_byte)(num_bytes < 0 ? 0 : num_bytes);
   1.104 +}
   1.105 +
   1.106 +/* Checks whether the supplied bytes match the PNG signature.  We allow
   1.107 + * checking less than the full 8-byte signature so that those apps that
   1.108 + * already read the first few bytes of a file to determine the file type
   1.109 + * can simply check the remaining bytes for extra assurance.  Returns
   1.110 + * an integer less than, equal to, or greater than zero if sig is found,
   1.111 + * respectively, to be less than, to match, or be greater than the correct
   1.112 + * PNG signature (this is the same behaviour as strcmp, memcmp, etc).
   1.113 + */
   1.114 +int PNGAPI
   1.115 +png_sig_cmp(png_bytep sig, png_size_t start, png_size_t num_to_check)
   1.116 +{
   1.117 +   png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
   1.118 +   if (num_to_check > 8)
   1.119 +      num_to_check = 8;
   1.120 +   else if (num_to_check < 1)
   1.121 +      return (-1);
   1.122 +
   1.123 +   if (start > 7)
   1.124 +      return (-1);
   1.125 +
   1.126 +   if (start + num_to_check > 8)
   1.127 +      num_to_check = 8 - start;
   1.128 +
   1.129 +   return ((int)(png_memcmp(&sig[start], &png_signature[start], num_to_check)));
   1.130 +}
   1.131 +
   1.132 +#if defined(PNG_1_0_X) || defined(PNG_1_2_X)
   1.133 +/* (Obsolete) function to check signature bytes.  It does not allow one
   1.134 + * to check a partial signature.  This function might be removed in the
   1.135 + * future - use png_sig_cmp().  Returns true (nonzero) if the file is PNG.
   1.136 + */
   1.137 +int PNGAPI
   1.138 +png_check_sig(png_bytep sig, int num)
   1.139 +{
   1.140 +  return ((int)!png_sig_cmp(sig, (png_size_t)0, (png_size_t)num));
   1.141 +}
   1.142 +#endif
   1.143 +#endif /* PNG_READ_SUPPORTED */
   1.144 +
   1.145 +#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
   1.146 +/* Function to allocate memory for zlib and clear it to 0. */
   1.147 +#ifdef PNG_1_0_X
   1.148 +voidpf PNGAPI
   1.149 +#else
   1.150 +voidpf /* private */
   1.151 +#endif
   1.152 +png_zalloc(voidpf png_ptr, uInt items, uInt size)
   1.153 +{
   1.154 +   png_voidp ptr;
   1.155 +   png_structp p=(png_structp)png_ptr;
   1.156 +   png_uint_32 save_flags=p->flags;
   1.157 +   png_uint_32 num_bytes;
   1.158 +
   1.159 +   if (png_ptr == NULL) return (NULL);
   1.160 +   if (items > PNG_UINT_32_MAX/size)
   1.161 +   {
   1.162 +     png_warning (p, "Potential overflow in png_zalloc()");
   1.163 +     return (NULL);
   1.164 +   }
   1.165 +   num_bytes = (png_uint_32)items * size;
   1.166 +
   1.167 +   p->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
   1.168 +   ptr = (png_voidp)png_malloc((png_structp)png_ptr, num_bytes);
   1.169 +   p->flags=save_flags;
   1.170 +
   1.171 +#if defined(PNG_1_0_X) && !defined(PNG_NO_ZALLOC_ZERO)
   1.172 +   if (ptr == NULL)
   1.173 +       return ((voidpf)ptr);
   1.174 +
   1.175 +   if (num_bytes > (png_uint_32)0x8000L)
   1.176 +   {
   1.177 +      png_memset(ptr, 0, (png_size_t)0x8000L);
   1.178 +      png_memset((png_bytep)ptr + (png_size_t)0x8000L, 0,
   1.179 +         (png_size_t)(num_bytes - (png_uint_32)0x8000L));
   1.180 +   }
   1.181 +   else
   1.182 +   {
   1.183 +      png_memset(ptr, 0, (png_size_t)num_bytes);
   1.184 +   }
   1.185 +#endif
   1.186 +   return ((voidpf)ptr);
   1.187 +}
   1.188 +
   1.189 +/* function to free memory for zlib */
   1.190 +#ifdef PNG_1_0_X
   1.191 +void PNGAPI
   1.192 +#else
   1.193 +void /* private */
   1.194 +#endif
   1.195 +png_zfree(voidpf png_ptr, voidpf ptr)
   1.196 +{
   1.197 +   png_free((png_structp)png_ptr, (png_voidp)ptr);
   1.198 +}
   1.199 +
   1.200 +/* Reset the CRC variable to 32 bits of 1's.  Care must be taken
   1.201 + * in case CRC is > 32 bits to leave the top bits 0.
   1.202 + */
   1.203 +void /* PRIVATE */
   1.204 +png_reset_crc(png_structp png_ptr)
   1.205 +{
   1.206 +   png_ptr->crc = crc32(0, Z_NULL, 0);
   1.207 +}
   1.208 +
   1.209 +/* Calculate the CRC over a section of data.  We can only pass as
   1.210 + * much data to this routine as the largest single buffer size.  We
   1.211 + * also check that this data will actually be used before going to the
   1.212 + * trouble of calculating it.
   1.213 + */
   1.214 +void /* PRIVATE */
   1.215 +png_calculate_crc(png_structp png_ptr, png_bytep ptr, png_size_t length)
   1.216 +{
   1.217 +   int need_crc = 1;
   1.218 +
   1.219 +   if (png_ptr->chunk_name[0] & 0x20)                     /* ancillary */
   1.220 +   {
   1.221 +      if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
   1.222 +          (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
   1.223 +         need_crc = 0;
   1.224 +   }
   1.225 +   else                                                    /* critical */
   1.226 +   {
   1.227 +      if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
   1.228 +         need_crc = 0;
   1.229 +   }
   1.230 +
   1.231 +   if (need_crc)
   1.232 +      png_ptr->crc = crc32(png_ptr->crc, ptr, (uInt)length);
   1.233 +}
   1.234 +
   1.235 +/* Allocate the memory for an info_struct for the application.  We don't
   1.236 + * really need the png_ptr, but it could potentially be useful in the
   1.237 + * future.  This should be used in favour of malloc(png_sizeof(png_info))
   1.238 + * and png_info_init() so that applications that want to use a shared
   1.239 + * libpng don't have to be recompiled if png_info changes size.
   1.240 + */
   1.241 +png_infop PNGAPI
   1.242 +png_create_info_struct(png_structp png_ptr)
   1.243 +{
   1.244 +   png_infop info_ptr;
   1.245 +
   1.246 +   png_debug(1, "in png_create_info_struct\n");
   1.247 +   if (png_ptr == NULL) return (NULL);
   1.248 +#ifdef PNG_USER_MEM_SUPPORTED
   1.249 +   info_ptr = (png_infop)png_create_struct_2(PNG_STRUCT_INFO,
   1.250 +      png_ptr->malloc_fn, png_ptr->mem_ptr);
   1.251 +#else
   1.252 +   info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
   1.253 +#endif
   1.254 +   if (info_ptr != NULL)
   1.255 +      png_info_init_3(&info_ptr, png_sizeof(png_info));
   1.256 +
   1.257 +   return (info_ptr);
   1.258 +}
   1.259 +
   1.260 +/* This function frees the memory associated with a single info struct.
   1.261 + * Normally, one would use either png_destroy_read_struct() or
   1.262 + * png_destroy_write_struct() to free an info struct, but this may be
   1.263 + * useful for some applications.
   1.264 + */
   1.265 +void PNGAPI
   1.266 +png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr)
   1.267 +{
   1.268 +   png_infop info_ptr = NULL;
   1.269 +   if (png_ptr == NULL) return;
   1.270 +
   1.271 +   png_debug(1, "in png_destroy_info_struct\n");
   1.272 +   if (info_ptr_ptr != NULL)
   1.273 +      info_ptr = *info_ptr_ptr;
   1.274 +
   1.275 +   if (info_ptr != NULL)
   1.276 +   {
   1.277 +      png_info_destroy(png_ptr, info_ptr);
   1.278 +
   1.279 +#ifdef PNG_USER_MEM_SUPPORTED
   1.280 +      png_destroy_struct_2((png_voidp)info_ptr, png_ptr->free_fn,
   1.281 +          png_ptr->mem_ptr);
   1.282 +#else
   1.283 +      png_destroy_struct((png_voidp)info_ptr);
   1.284 +#endif
   1.285 +      *info_ptr_ptr = NULL;
   1.286 +   }
   1.287 +}
   1.288 +
   1.289 +/* Initialize the info structure.  This is now an internal function (0.89)
   1.290 + * and applications using it are urged to use png_create_info_struct()
   1.291 + * instead.
   1.292 + */
   1.293 +#if defined(PNG_1_0_X) || defined(PNG_1_2_X)
   1.294 +#undef png_info_init
   1.295 +void PNGAPI
   1.296 +png_info_init(png_infop info_ptr)
   1.297 +{
   1.298 +   /* We only come here via pre-1.0.12-compiled applications */
   1.299 +   png_info_init_3(&info_ptr, 0);
   1.300 +}
   1.301 +#endif
   1.302 +
   1.303 +void PNGAPI
   1.304 +png_info_init_3(png_infopp ptr_ptr, png_size_t png_info_struct_size)
   1.305 +{
   1.306 +   png_infop info_ptr = *ptr_ptr;
   1.307 +
   1.308 +   if (info_ptr == NULL) return;
   1.309 +
   1.310 +   png_debug(1, "in png_info_init_3\n");
   1.311 +
   1.312 +   if (png_sizeof(png_info) > png_info_struct_size)
   1.313 +     {
   1.314 +       png_destroy_struct(info_ptr);
   1.315 +       info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
   1.316 +       *ptr_ptr = info_ptr;
   1.317 +     }
   1.318 +
   1.319 +   /* set everything to 0 */
   1.320 +   png_memset(info_ptr, 0, png_sizeof(png_info));
   1.321 +}
   1.322 +
   1.323 +#ifdef PNG_FREE_ME_SUPPORTED
   1.324 +void PNGAPI
   1.325 +png_data_freer(png_structp png_ptr, png_infop info_ptr,
   1.326 +   int freer, png_uint_32 mask)
   1.327 +{
   1.328 +   png_debug(1, "in png_data_freer\n");
   1.329 +   if (png_ptr == NULL || info_ptr == NULL)
   1.330 +      return;
   1.331 +   if (freer == PNG_DESTROY_WILL_FREE_DATA)
   1.332 +      info_ptr->free_me |= mask;
   1.333 +   else if (freer == PNG_USER_WILL_FREE_DATA)
   1.334 +      info_ptr->free_me &= ~mask;
   1.335 +   else
   1.336 +      png_warning(png_ptr,
   1.337 +         "Unknown freer parameter in png_data_freer.");
   1.338 +}
   1.339 +#endif
   1.340 +
   1.341 +void PNGAPI
   1.342 +png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask,
   1.343 +   int num)
   1.344 +{
   1.345 +   png_debug(1, "in png_free_data\n");
   1.346 +   if (png_ptr == NULL || info_ptr == NULL)
   1.347 +      return;
   1.348 +
   1.349 +#if defined(PNG_TEXT_SUPPORTED)
   1.350 +/* free text item num or (if num == -1) all text items */
   1.351 +#ifdef PNG_FREE_ME_SUPPORTED
   1.352 +if ((mask & PNG_FREE_TEXT) & info_ptr->free_me)
   1.353 +#else
   1.354 +if (mask & PNG_FREE_TEXT)
   1.355 +#endif
   1.356 +{
   1.357 +   if (num != -1)
   1.358 +   {
   1.359 +     if (info_ptr->text && info_ptr->text[num].key)
   1.360 +     {
   1.361 +         png_free(png_ptr, info_ptr->text[num].key);
   1.362 +         info_ptr->text[num].key = NULL;
   1.363 +     }
   1.364 +   }
   1.365 +   else
   1.366 +   {
   1.367 +       int i;
   1.368 +       for (i = 0; i < info_ptr->num_text; i++)
   1.369 +           png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, i);
   1.370 +       png_free(png_ptr, info_ptr->text);
   1.371 +       info_ptr->text = NULL;
   1.372 +       info_ptr->num_text=0;
   1.373 +   }
   1.374 +}
   1.375 +#endif
   1.376 +
   1.377 +#if defined(PNG_tRNS_SUPPORTED)
   1.378 +/* free any tRNS entry */
   1.379 +#ifdef PNG_FREE_ME_SUPPORTED
   1.380 +if ((mask & PNG_FREE_TRNS) & info_ptr->free_me)
   1.381 +#else
   1.382 +if ((mask & PNG_FREE_TRNS) && (png_ptr->flags & PNG_FLAG_FREE_TRNS))
   1.383 +#endif
   1.384 +{
   1.385 +    png_free(png_ptr, info_ptr->trans);
   1.386 +    info_ptr->trans = NULL;
   1.387 +    info_ptr->valid &= ~PNG_INFO_tRNS;
   1.388 +#ifndef PNG_FREE_ME_SUPPORTED
   1.389 +    png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
   1.390 +#endif
   1.391 +}
   1.392 +#endif
   1.393 +
   1.394 +#if defined(PNG_sCAL_SUPPORTED)
   1.395 +/* free any sCAL entry */
   1.396 +#ifdef PNG_FREE_ME_SUPPORTED
   1.397 +if ((mask & PNG_FREE_SCAL) & info_ptr->free_me)
   1.398 +#else
   1.399 +if (mask & PNG_FREE_SCAL)
   1.400 +#endif
   1.401 +{
   1.402 +#if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
   1.403 +    png_free(png_ptr, info_ptr->scal_s_width);
   1.404 +    png_free(png_ptr, info_ptr->scal_s_height);
   1.405 +    info_ptr->scal_s_width = NULL;
   1.406 +    info_ptr->scal_s_height = NULL;
   1.407 +#endif
   1.408 +    info_ptr->valid &= ~PNG_INFO_sCAL;
   1.409 +}
   1.410 +#endif
   1.411 +
   1.412 +#if defined(PNG_pCAL_SUPPORTED)
   1.413 +/* free any pCAL entry */
   1.414 +#ifdef PNG_FREE_ME_SUPPORTED
   1.415 +if ((mask & PNG_FREE_PCAL) & info_ptr->free_me)
   1.416 +#else
   1.417 +if (mask & PNG_FREE_PCAL)
   1.418 +#endif
   1.419 +{
   1.420 +    png_free(png_ptr, info_ptr->pcal_purpose);
   1.421 +    png_free(png_ptr, info_ptr->pcal_units);
   1.422 +    info_ptr->pcal_purpose = NULL;
   1.423 +    info_ptr->pcal_units = NULL;
   1.424 +    if (info_ptr->pcal_params != NULL)
   1.425 +    {
   1.426 +        int i;
   1.427 +        for (i = 0; i < (int)info_ptr->pcal_nparams; i++)
   1.428 +        {
   1.429 +          png_free(png_ptr, info_ptr->pcal_params[i]);
   1.430 +          info_ptr->pcal_params[i]=NULL;
   1.431 +        }
   1.432 +        png_free(png_ptr, info_ptr->pcal_params);
   1.433 +        info_ptr->pcal_params = NULL;
   1.434 +    }
   1.435 +    info_ptr->valid &= ~PNG_INFO_pCAL;
   1.436 +}
   1.437 +#endif
   1.438 +
   1.439 +#if defined(PNG_iCCP_SUPPORTED)
   1.440 +/* free any iCCP entry */
   1.441 +#ifdef PNG_FREE_ME_SUPPORTED
   1.442 +if ((mask & PNG_FREE_ICCP) & info_ptr->free_me)
   1.443 +#else
   1.444 +if (mask & PNG_FREE_ICCP)
   1.445 +#endif
   1.446 +{
   1.447 +    png_free(png_ptr, info_ptr->iccp_name);
   1.448 +    png_free(png_ptr, info_ptr->iccp_profile);
   1.449 +    info_ptr->iccp_name = NULL;
   1.450 +    info_ptr->iccp_profile = NULL;
   1.451 +    info_ptr->valid &= ~PNG_INFO_iCCP;
   1.452 +}
   1.453 +#endif
   1.454 +
   1.455 +#if defined(PNG_sPLT_SUPPORTED)
   1.456 +/* free a given sPLT entry, or (if num == -1) all sPLT entries */
   1.457 +#ifdef PNG_FREE_ME_SUPPORTED
   1.458 +if ((mask & PNG_FREE_SPLT) & info_ptr->free_me)
   1.459 +#else
   1.460 +if (mask & PNG_FREE_SPLT)
   1.461 +#endif
   1.462 +{
   1.463 +   if (num != -1)
   1.464 +   {
   1.465 +      if (info_ptr->splt_palettes)
   1.466 +      {
   1.467 +          png_free(png_ptr, info_ptr->splt_palettes[num].name);
   1.468 +          png_free(png_ptr, info_ptr->splt_palettes[num].entries);
   1.469 +          info_ptr->splt_palettes[num].name = NULL;
   1.470 +          info_ptr->splt_palettes[num].entries = NULL;
   1.471 +      }
   1.472 +   }
   1.473 +   else
   1.474 +   {
   1.475 +       if (info_ptr->splt_palettes_num)
   1.476 +       {
   1.477 +         int i;
   1.478 +         for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
   1.479 +            png_free_data(png_ptr, info_ptr, PNG_FREE_SPLT, i);
   1.480 +
   1.481 +         png_free(png_ptr, info_ptr->splt_palettes);
   1.482 +         info_ptr->splt_palettes = NULL;
   1.483 +         info_ptr->splt_palettes_num = 0;
   1.484 +       }
   1.485 +       info_ptr->valid &= ~PNG_INFO_sPLT;
   1.486 +   }
   1.487 +}
   1.488 +#endif
   1.489 +
   1.490 +#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
   1.491 +  if (png_ptr->unknown_chunk.data)
   1.492 +  {
   1.493 +    png_free(png_ptr, png_ptr->unknown_chunk.data);
   1.494 +    png_ptr->unknown_chunk.data = NULL;
   1.495 +  }
   1.496 +
   1.497 +#ifdef PNG_FREE_ME_SUPPORTED
   1.498 +if ((mask & PNG_FREE_UNKN) & info_ptr->free_me)
   1.499 +#else
   1.500 +if (mask & PNG_FREE_UNKN)
   1.501 +#endif
   1.502 +{
   1.503 +   if (num != -1)
   1.504 +   {
   1.505 +       if (info_ptr->unknown_chunks)
   1.506 +       {
   1.507 +          png_free(png_ptr, info_ptr->unknown_chunks[num].data);
   1.508 +          info_ptr->unknown_chunks[num].data = NULL;
   1.509 +       }
   1.510 +   }
   1.511 +   else
   1.512 +   {
   1.513 +       int i;
   1.514 +
   1.515 +       if (info_ptr->unknown_chunks_num)
   1.516 +       {
   1.517 +         for (i = 0; i < (int)info_ptr->unknown_chunks_num; i++)
   1.518 +            png_free_data(png_ptr, info_ptr, PNG_FREE_UNKN, i);
   1.519 +
   1.520 +         png_free(png_ptr, info_ptr->unknown_chunks);
   1.521 +         info_ptr->unknown_chunks = NULL;
   1.522 +         info_ptr->unknown_chunks_num = 0;
   1.523 +       }
   1.524 +   }
   1.525 +}
   1.526 +#endif
   1.527 +
   1.528 +#if defined(PNG_hIST_SUPPORTED)
   1.529 +/* free any hIST entry */
   1.530 +#ifdef PNG_FREE_ME_SUPPORTED
   1.531 +if ((mask & PNG_FREE_HIST)  & info_ptr->free_me)
   1.532 +#else
   1.533 +if ((mask & PNG_FREE_HIST) && (png_ptr->flags & PNG_FLAG_FREE_HIST))
   1.534 +#endif
   1.535 +{
   1.536 +    png_free(png_ptr, info_ptr->hist);
   1.537 +    info_ptr->hist = NULL;
   1.538 +    info_ptr->valid &= ~PNG_INFO_hIST;
   1.539 +#ifndef PNG_FREE_ME_SUPPORTED
   1.540 +    png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
   1.541 +#endif
   1.542 +}
   1.543 +#endif
   1.544 +
   1.545 +/* free any PLTE entry that was internally allocated */
   1.546 +#ifdef PNG_FREE_ME_SUPPORTED
   1.547 +if ((mask & PNG_FREE_PLTE) & info_ptr->free_me)
   1.548 +#else
   1.549 +if ((mask & PNG_FREE_PLTE) && (png_ptr->flags & PNG_FLAG_FREE_PLTE))
   1.550 +#endif
   1.551 +{
   1.552 +    png_zfree(png_ptr, info_ptr->palette);
   1.553 +    info_ptr->palette = NULL;
   1.554 +    info_ptr->valid &= ~PNG_INFO_PLTE;
   1.555 +#ifndef PNG_FREE_ME_SUPPORTED
   1.556 +    png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;
   1.557 +#endif
   1.558 +    info_ptr->num_palette = 0;
   1.559 +}
   1.560 +
   1.561 +#if defined(PNG_INFO_IMAGE_SUPPORTED)
   1.562 +/* free any image bits attached to the info structure */
   1.563 +#ifdef PNG_FREE_ME_SUPPORTED
   1.564 +if ((mask & PNG_FREE_ROWS) & info_ptr->free_me)
   1.565 +#else
   1.566 +if (mask & PNG_FREE_ROWS)
   1.567 +#endif
   1.568 +{
   1.569 +    if (info_ptr->row_pointers)
   1.570 +    {
   1.571 +       int row;
   1.572 +       for (row = 0; row < (int)info_ptr->height; row++)
   1.573 +       {
   1.574 +          png_free(png_ptr, info_ptr->row_pointers[row]);
   1.575 +          info_ptr->row_pointers[row]=NULL;
   1.576 +       }
   1.577 +       png_free(png_ptr, info_ptr->row_pointers);
   1.578 +       info_ptr->row_pointers=NULL;
   1.579 +    }
   1.580 +    info_ptr->valid &= ~PNG_INFO_IDAT;
   1.581 +}
   1.582 +#endif
   1.583 +
   1.584 +#ifdef PNG_FREE_ME_SUPPORTED
   1.585 +   if (num == -1)
   1.586 +     info_ptr->free_me &= ~mask;
   1.587 +   else
   1.588 +     info_ptr->free_me &= ~(mask & ~PNG_FREE_MUL);
   1.589 +#endif
   1.590 +}
   1.591 +
   1.592 +/* This is an internal routine to free any memory that the info struct is
   1.593 + * pointing to before re-using it or freeing the struct itself.  Recall
   1.594 + * that png_free() checks for NULL pointers for us.
   1.595 + */
   1.596 +void /* PRIVATE */
   1.597 +png_info_destroy(png_structp png_ptr, png_infop info_ptr)
   1.598 +{
   1.599 +   png_debug(1, "in png_info_destroy\n");
   1.600 +
   1.601 +   png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
   1.602 +
   1.603 +#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
   1.604 +   if (png_ptr->num_chunk_list)
   1.605 +   {
   1.606 +       png_free(png_ptr, png_ptr->chunk_list);
   1.607 +       png_ptr->chunk_list=NULL;
   1.608 +       png_ptr->num_chunk_list = 0;
   1.609 +   }
   1.610 +#endif
   1.611 +
   1.612 +   png_info_init_3(&info_ptr, png_sizeof(png_info));
   1.613 +}
   1.614 +#endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
   1.615 +
   1.616 +/* This function returns a pointer to the io_ptr associated with the user
   1.617 + * functions.  The application should free any memory associated with this
   1.618 + * pointer before png_write_destroy() or png_read_destroy() are called.
   1.619 + */
   1.620 +png_voidp PNGAPI
   1.621 +png_get_io_ptr(png_structp png_ptr)
   1.622 +{
   1.623 +   if (png_ptr == NULL) return (NULL);
   1.624 +   return (png_ptr->io_ptr);
   1.625 +}
   1.626 +
   1.627 +#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
   1.628 +#if !defined(PNG_NO_STDIO)
   1.629 +/* Initialize the default input/output functions for the PNG file.  If you
   1.630 + * use your own read or write routines, you can call either png_set_read_fn()
   1.631 + * or png_set_write_fn() instead of png_init_io().  If you have defined
   1.632 + * PNG_NO_STDIO, you must use a function of your own because "FILE *" isn't
   1.633 + * necessarily available.
   1.634 + */
   1.635 +void PNGAPI
   1.636 +png_init_io(png_structp png_ptr, png_FILE_p fp)
   1.637 +{
   1.638 +   png_debug(1, "in png_init_io\n");
   1.639 +   if (png_ptr == NULL) return;
   1.640 +   png_ptr->io_ptr = (png_voidp)fp;
   1.641 +}
   1.642 +#endif
   1.643 +
   1.644 +#if defined(PNG_TIME_RFC1123_SUPPORTED)
   1.645 +/* Convert the supplied time into an RFC 1123 string suitable for use in
   1.646 + * a "Creation Time" or other text-based time string.
   1.647 + */
   1.648 +png_charp PNGAPI
   1.649 +png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime)
   1.650 +{
   1.651 +   static PNG_CONST char short_months[12][4] =
   1.652 +        {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
   1.653 +         "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
   1.654 +
   1.655 +   if (png_ptr == NULL) return (NULL);
   1.656 +   if (png_ptr->time_buffer == NULL)
   1.657 +   {
   1.658 +      png_ptr->time_buffer = (png_charp)png_malloc(png_ptr, (png_uint_32)(29*
   1.659 +         png_sizeof(char)));
   1.660 +   }
   1.661 +
   1.662 +#if defined(_WIN32_WCE)
   1.663 +   {
   1.664 +      wchar_t time_buf[29];
   1.665 +      wsprintf(time_buf, TEXT("%d %S %d %02d:%02d:%02d +0000"),
   1.666 +          ptime->day % 32, short_months[(ptime->month - 1) % 12],
   1.667 +        ptime->year, ptime->hour % 24, ptime->minute % 60,
   1.668 +          ptime->second % 61);
   1.669 +      WideCharToMultiByte(CP_ACP, 0, time_buf, -1, png_ptr->time_buffer, 29,
   1.670 +          NULL, NULL);
   1.671 +   }
   1.672 +#else
   1.673 +#ifdef USE_FAR_KEYWORD
   1.674 +   {
   1.675 +      char near_time_buf[29];
   1.676 +      png_snprintf6(near_time_buf, 29, "%d %s %d %02d:%02d:%02d +0000",
   1.677 +          ptime->day % 32, short_months[(ptime->month - 1) % 12],
   1.678 +          ptime->year, ptime->hour % 24, ptime->minute % 60,
   1.679 +          ptime->second % 61);
   1.680 +      png_memcpy(png_ptr->time_buffer, near_time_buf,
   1.681 +          29*png_sizeof(char));
   1.682 +   }
   1.683 +#else
   1.684 +   png_snprintf6(png_ptr->time_buffer, 29, "%d %s %d %02d:%02d:%02d +0000",
   1.685 +       ptime->day % 32, short_months[(ptime->month - 1) % 12],
   1.686 +       ptime->year, ptime->hour % 24, ptime->minute % 60,
   1.687 +       ptime->second % 61);
   1.688 +#endif
   1.689 +#endif /* _WIN32_WCE */
   1.690 +   return ((png_charp)png_ptr->time_buffer);
   1.691 +}
   1.692 +#endif /* PNG_TIME_RFC1123_SUPPORTED */
   1.693 +
   1.694 +#endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
   1.695 +
   1.696 +png_charp PNGAPI
   1.697 +png_get_copyright(png_structp png_ptr)
   1.698 +{
   1.699 +   png_ptr = png_ptr;  /* silence compiler warning about unused png_ptr */
   1.700 +   return ((png_charp) "\n libpng version 1.2.33 - October 31, 2008\n\
   1.701 +   Copyright (c) 1998-2008 Glenn Randers-Pehrson\n\
   1.702 +   Copyright (c) 1996-1997 Andreas Dilger\n\
   1.703 +   Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.\n");
   1.704 +}
   1.705 +
   1.706 +/* The following return the library version as a short string in the
   1.707 + * format 1.0.0 through 99.99.99zz.  To get the version of *.h files
   1.708 + * used with your application, print out PNG_LIBPNG_VER_STRING, which
   1.709 + * is defined in png.h.
   1.710 + * Note: now there is no difference between png_get_libpng_ver() and
   1.711 + * png_get_header_ver().  Due to the version_nn_nn_nn typedef guard,
   1.712 + * it is guaranteed that png.c uses the correct version of png.h.
   1.713 + */
   1.714 +png_charp PNGAPI
   1.715 +png_get_libpng_ver(png_structp png_ptr)
   1.716 +{
   1.717 +   /* Version of *.c files used when building libpng */
   1.718 +   png_ptr = png_ptr;  /* silence compiler warning about unused png_ptr */
   1.719 +   return ((png_charp) PNG_LIBPNG_VER_STRING);
   1.720 +}
   1.721 +
   1.722 +png_charp PNGAPI
   1.723 +png_get_header_ver(png_structp png_ptr)
   1.724 +{
   1.725 +   /* Version of *.h files used when building libpng */
   1.726 +   png_ptr = png_ptr;  /* silence compiler warning about unused png_ptr */
   1.727 +   return ((png_charp) PNG_LIBPNG_VER_STRING);
   1.728 +}
   1.729 +
   1.730 +png_charp PNGAPI
   1.731 +png_get_header_version(png_structp png_ptr)
   1.732 +{
   1.733 +   /* Returns longer string containing both version and date */
   1.734 +   png_ptr = png_ptr;  /* silence compiler warning about unused png_ptr */
   1.735 +   return ((png_charp) PNG_HEADER_VERSION_STRING
   1.736 +#ifndef PNG_READ_SUPPORTED
   1.737 +   "     (NO READ SUPPORT)"
   1.738 +#endif
   1.739 +   "\n");
   1.740 +}
   1.741 +
   1.742 +#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
   1.743 +#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
   1.744 +int PNGAPI
   1.745 +png_handle_as_unknown(png_structp png_ptr, png_bytep chunk_name)
   1.746 +{
   1.747 +   /* check chunk_name and return "keep" value if it's on the list, else 0 */
   1.748 +   int i;
   1.749 +   png_bytep p;
   1.750 +   if (png_ptr == NULL || chunk_name == NULL || png_ptr->num_chunk_list<=0)
   1.751 +      return 0;
   1.752 +   p = png_ptr->chunk_list + png_ptr->num_chunk_list*5 - 5;
   1.753 +   for (i = png_ptr->num_chunk_list; i; i--, p -= 5)
   1.754 +      if (!png_memcmp(chunk_name, p, 4))
   1.755 +        return ((int)*(p + 4));
   1.756 +   return 0;
   1.757 +}
   1.758 +#endif
   1.759 +
   1.760 +/* This function, added to libpng-1.0.6g, is untested. */
   1.761 +int PNGAPI
   1.762 +png_reset_zstream(png_structp png_ptr)
   1.763 +{
   1.764 +   if (png_ptr == NULL) return Z_STREAM_ERROR;
   1.765 +   return (inflateReset(&png_ptr->zstream));
   1.766 +}
   1.767 +#endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
   1.768 +
   1.769 +/* This function was added to libpng-1.0.7 */
   1.770 +png_uint_32 PNGAPI
   1.771 +png_access_version_number(void)
   1.772 +{
   1.773 +   /* Version of *.c files used when building libpng */
   1.774 +   return((png_uint_32) PNG_LIBPNG_VER);
   1.775 +}
   1.776 +
   1.777 +
   1.778 +#if defined(PNG_READ_SUPPORTED) && defined(PNG_ASSEMBLER_CODE_SUPPORTED)
   1.779 +#if !defined(PNG_1_0_X)
   1.780 +/* this function was added to libpng 1.2.0 */
   1.781 +int PNGAPI
   1.782 +png_mmx_support(void)
   1.783 +{
   1.784 +   /* obsolete, to be removed from libpng-1.4.0 */
   1.785 +    return -1;
   1.786 +}
   1.787 +#endif /* PNG_1_0_X */
   1.788 +#endif /* PNG_READ_SUPPORTED && PNG_ASSEMBLER_CODE_SUPPORTED */
   1.789 +
   1.790 +#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
   1.791 +#ifdef PNG_SIZE_T
   1.792 +/* Added at libpng version 1.2.6 */
   1.793 +   PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size));
   1.794 +png_size_t PNGAPI
   1.795 +png_convert_size(size_t size)
   1.796 +{
   1.797 +  if (size > (png_size_t)-1)
   1.798 +     PNG_ABORT();  /* We haven't got access to png_ptr, so no png_error() */
   1.799 +  return ((png_size_t)size);
   1.800 +}
   1.801 +#endif /* PNG_SIZE_T */
   1.802 +#endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */