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