src/3rdparty/libpng/pngread.c
changeset 30 5dc02b23752f
parent 0 1918ee327afb
equal deleted inserted replaced
29:b72c6db6890b 30:5dc02b23752f
     1 
     1 
     2 /* pngread.c - read a PNG file
     2 /* pngread.c - read a PNG file
     3  *
     3  *
     4  * Last changed in libpng 1.2.37 [June 4, 2009]
     4  * Last changed in libpng 1.4.0 [January 3, 2010]
     5  * Copyright (c) 1998-2009 Glenn Randers-Pehrson
     5  * Copyright (c) 1998-2010 Glenn Randers-Pehrson
     6  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
     6  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
     7  * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
     7  * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
     8  *
     8  *
     9  * This code is released under the libpng license.
     9  * This code is released under the libpng license.
    10  * For conditions of distribution and use, see the disclaimer
    10  * For conditions of distribution and use, see the disclaimer
    12  *
    12  *
    13  * This file contains routines that an application calls directly to
    13  * This file contains routines that an application calls directly to
    14  * read a PNG file or stream.
    14  * read a PNG file or stream.
    15  */
    15  */
    16 
    16 
    17 #define PNG_INTERNAL
    17 #define PNG_NO_PEDANTIC_WARNINGS
    18 #include "png.h"
    18 #include "png.h"
    19 #if defined(PNG_READ_SUPPORTED)
    19 #ifdef PNG_READ_SUPPORTED
       
    20 #include "pngpriv.h"
       
    21 
    20 
    22 
    21 /* Create a PNG structure for reading, and allocate any memory needed. */
    23 /* Create a PNG structure for reading, and allocate any memory needed. */
    22 png_structp PNGAPI
    24 png_structp PNGAPI
    23 png_create_read_struct(png_const_charp user_png_ver, png_voidp error_ptr,
    25 png_create_read_struct(png_const_charp user_png_ver, png_voidp error_ptr,
    24    png_error_ptr error_fn, png_error_ptr warn_fn)
    26    png_error_ptr error_fn, png_error_ptr warn_fn)
    25 {
    27 {
    26 
    28 
    27 #ifdef PNG_USER_MEM_SUPPORTED
    29 #ifdef PNG_USER_MEM_SUPPORTED
    28    return (png_create_read_struct_2(user_png_ver, error_ptr, error_fn,
    30    return (png_create_read_struct_2(user_png_ver, error_ptr, error_fn,
    29       warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL));
    31       warn_fn, NULL, NULL, NULL));
    30 }
    32 }
    31 
    33 
    32 /* Alternate create PNG structure for reading, and allocate any memory needed. */
    34 /* Alternate create PNG structure for reading, and allocate any memory needed. */
    33 png_structp PNGAPI
    35 png_structp PNGAPI
    34 png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
    36 png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
    39 
    41 
    40 #ifdef PNG_SETJMP_SUPPORTED
    42 #ifdef PNG_SETJMP_SUPPORTED
    41    volatile
    43    volatile
    42 #endif
    44 #endif
    43    png_structp png_ptr;
    45    png_structp png_ptr;
       
    46    volatile int png_cleanup_needed = 0;
    44 
    47 
    45 #ifdef PNG_SETJMP_SUPPORTED
    48 #ifdef PNG_SETJMP_SUPPORTED
    46 #ifdef USE_FAR_KEYWORD
    49 #ifdef USE_FAR_KEYWORD
    47    jmp_buf jmpbuf;
    50    jmp_buf jmpbuf;
    48 #endif
    51 #endif
    49 #endif
    52 #endif
    50 
    53 
    51    int i;
    54    int i;
    52 
    55 
    53    png_debug(1, "in png_create_read_struct");
    56    png_debug(1, "in png_create_read_struct");
       
    57 
    54 #ifdef PNG_USER_MEM_SUPPORTED
    58 #ifdef PNG_USER_MEM_SUPPORTED
    55    png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
    59    png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
    56       (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
    60       malloc_fn, mem_ptr);
    57 #else
    61 #else
    58    png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
    62    png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
    59 #endif
    63 #endif
    60    if (png_ptr == NULL)
    64    if (png_ptr == NULL)
    61       return (NULL);
    65       return (NULL);
    62 
    66 
    63    /* Added at libpng-1.2.6 */
    67    /* Added at libpng-1.2.6 */
    64 #ifdef PNG_SET_USER_LIMITS_SUPPORTED
    68 #ifdef PNG_SET_USER_LIMITS_SUPPORTED
    65    png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
    69    png_ptr->user_width_max = PNG_USER_WIDTH_MAX;
    66    png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
    70    png_ptr->user_height_max = PNG_USER_HEIGHT_MAX;
       
    71    /* Added at libpng-1.4.0 */
       
    72    png_ptr->user_chunk_cache_max = PNG_USER_CHUNK_CACHE_MAX;
    67 #endif
    73 #endif
    68 
    74 
    69 #ifdef PNG_SETJMP_SUPPORTED
    75 #ifdef PNG_SETJMP_SUPPORTED
       
    76 /* Applications that neglect to set up their own setjmp() and then
       
    77    encounter a png_error() will longjmp here.  Since the jmpbuf is
       
    78    then meaningless we abort instead of returning. */
    70 #ifdef USE_FAR_KEYWORD
    79 #ifdef USE_FAR_KEYWORD
    71    if (setjmp(jmpbuf))
    80    if (setjmp(jmpbuf))
    72 #else
    81 #else
    73    if (setjmp(png_ptr->jmpbuf))
    82    if (setjmp(png_jmpbuf(png_ptr))) /* Sets longjmp to match setjmp */
    74 #endif
    83 #endif
    75    {
    84       PNG_ABORT();
       
    85 #ifdef USE_FAR_KEYWORD
       
    86    png_memcpy(png_jmpbuf(png_ptr), jmpbuf, png_sizeof(jmp_buf));
       
    87 #endif
       
    88 #endif /* PNG_SETJMP_SUPPORTED */
       
    89 
       
    90 #ifdef PNG_USER_MEM_SUPPORTED
       
    91    png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
       
    92 #endif
       
    93 
       
    94    png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
       
    95 
       
    96    if (user_png_ver)
       
    97    {
       
    98       i = 0;
       
    99       do
       
   100       {
       
   101          if (user_png_ver[i] != png_libpng_ver[i])
       
   102             png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
       
   103       } while (png_libpng_ver[i++]);
       
   104     }
       
   105     else
       
   106          png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
       
   107 
       
   108 
       
   109     if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
       
   110     {
       
   111        /* Libpng 0.90 and later are binary incompatible with libpng 0.89, so
       
   112        * we must recompile any applications that use any older library version.
       
   113        * For versions after libpng 1.0, we will be compatible, so we need
       
   114        * only check the first digit.
       
   115        */
       
   116       if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
       
   117           (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
       
   118           (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
       
   119       {
       
   120 #ifdef PNG_STDIO_SUPPORTED
       
   121          char msg[80];
       
   122          if (user_png_ver)
       
   123          {
       
   124            png_snprintf(msg, 80,
       
   125               "Application was compiled with png.h from libpng-%.20s",
       
   126               user_png_ver);
       
   127            png_warning(png_ptr, msg);
       
   128          }
       
   129          png_snprintf(msg, 80,
       
   130              "Application  is  running with png.c from libpng-%.20s",
       
   131              png_libpng_ver);
       
   132          png_warning(png_ptr, msg);
       
   133 #endif
       
   134 #ifdef PNG_ERROR_NUMBERS_SUPPORTED
       
   135          png_ptr->flags = 0;
       
   136 #endif
       
   137          png_warning(png_ptr,
       
   138             "Incompatible libpng version in application and library");
       
   139 
       
   140          png_cleanup_needed = 1;
       
   141       }
       
   142    }
       
   143 
       
   144    if (!png_cleanup_needed)
       
   145    {
       
   146    /* Initialize zbuf - compression buffer */
       
   147    png_ptr->zbuf_size = PNG_ZBUF_SIZE;
       
   148    png_ptr->zbuf = (png_bytep)png_malloc_warn(png_ptr,
       
   149      png_ptr->zbuf_size);
       
   150    if (png_ptr->zbuf == NULL)
       
   151         png_cleanup_needed = 1;
       
   152    }
       
   153    png_ptr->zstream.zalloc = png_zalloc;
       
   154    png_ptr->zstream.zfree = png_zfree;
       
   155    png_ptr->zstream.opaque = (voidpf)png_ptr;
       
   156 
       
   157    if (!png_cleanup_needed)
       
   158    {
       
   159       switch (inflateInit(&png_ptr->zstream))
       
   160       {
       
   161          case Z_OK: /* Do nothing */ break;
       
   162          case Z_MEM_ERROR:
       
   163          case Z_STREAM_ERROR: png_warning(png_ptr, "zlib memory error");
       
   164             png_cleanup_needed = 1; break;
       
   165          case Z_VERSION_ERROR: png_warning(png_ptr, "zlib version error");
       
   166             png_cleanup_needed = 1; break;
       
   167          default: png_warning(png_ptr, "Unknown zlib error");
       
   168             png_cleanup_needed = 1;
       
   169       }
       
   170    }
       
   171 
       
   172    if (png_cleanup_needed)
       
   173    {
       
   174       /* Clean up PNG structure and deallocate any memory. */
    76       png_free(png_ptr, png_ptr->zbuf);
   175       png_free(png_ptr, png_ptr->zbuf);
    77       png_ptr->zbuf = NULL;
   176       png_ptr->zbuf = NULL;
    78 #ifdef PNG_USER_MEM_SUPPORTED
   177 #ifdef PNG_USER_MEM_SUPPORTED
    79       png_destroy_struct_2((png_voidp)png_ptr,
   178       png_destroy_struct_2((png_voidp)png_ptr,
    80          (png_free_ptr)free_fn, (png_voidp)mem_ptr);
   179          (png_free_ptr)free_fn, (png_voidp)mem_ptr);
    81 #else
   180 #else
    82       png_destroy_struct((png_voidp)png_ptr);
   181       png_destroy_struct((png_voidp)png_ptr);
    83 #endif
   182 #endif
    84       return (NULL);
   183       return (NULL);
    85    }
   184    }
    86 #ifdef USE_FAR_KEYWORD
       
    87    png_memcpy(png_ptr->jmpbuf, jmpbuf, png_sizeof(jmp_buf));
       
    88 #endif
       
    89 #endif
       
    90 
       
    91 #ifdef PNG_USER_MEM_SUPPORTED
       
    92    png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
       
    93 #endif
       
    94 
       
    95    png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
       
    96 
       
    97    if (user_png_ver)
       
    98    {
       
    99      i = 0;
       
   100      do
       
   101      {
       
   102        if (user_png_ver[i] != png_libpng_ver[i])
       
   103           png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
       
   104      } while (png_libpng_ver[i++]);
       
   105    }
       
   106    else
       
   107         png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
       
   108 
       
   109 
       
   110    if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
       
   111    {
       
   112      /* Libpng 0.90 and later are binary incompatible with libpng 0.89, so
       
   113       * we must recompile any applications that use any older library version.
       
   114       * For versions after libpng 1.0, we will be compatible, so we need
       
   115       * only check the first digit.
       
   116       */
       
   117      if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
       
   118          (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
       
   119          (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
       
   120      {
       
   121 #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
       
   122         char msg[80];
       
   123         if (user_png_ver)
       
   124         {
       
   125           png_snprintf(msg, 80,
       
   126              "Application was compiled with png.h from libpng-%.20s",
       
   127              user_png_ver);
       
   128           png_warning(png_ptr, msg);
       
   129         }
       
   130         png_snprintf(msg, 80,
       
   131              "Application  is  running with png.c from libpng-%.20s",
       
   132            png_libpng_ver);
       
   133         png_warning(png_ptr, msg);
       
   134 #endif
       
   135 #ifdef PNG_ERROR_NUMBERS_SUPPORTED
       
   136         png_ptr->flags = 0;
       
   137 #endif
       
   138         png_error(png_ptr,
       
   139            "Incompatible libpng version in application and library");
       
   140      }
       
   141    }
       
   142 
       
   143    /* Initialize zbuf - compression buffer */
       
   144    png_ptr->zbuf_size = PNG_ZBUF_SIZE;
       
   145    png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
       
   146      (png_uint_32)png_ptr->zbuf_size);
       
   147    png_ptr->zstream.zalloc = png_zalloc;
       
   148    png_ptr->zstream.zfree = png_zfree;
       
   149    png_ptr->zstream.opaque = (voidpf)png_ptr;
       
   150 
       
   151    switch (inflateInit(&png_ptr->zstream))
       
   152    {
       
   153      case Z_OK: /* Do nothing */ break;
       
   154      case Z_MEM_ERROR:
       
   155      case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory error"); break;
       
   156      case Z_VERSION_ERROR: png_error(png_ptr, "zlib version error"); break;
       
   157      default: png_error(png_ptr, "Unknown zlib error");
       
   158    }
       
   159 
   185 
   160    png_ptr->zstream.next_out = png_ptr->zbuf;
   186    png_ptr->zstream.next_out = png_ptr->zbuf;
   161    png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
   187    png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
   162 
   188 
   163    png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL);
   189    png_set_read_fn(png_ptr, NULL, NULL);
   164 
   190 
   165 #ifdef PNG_SETJMP_SUPPORTED
   191 
   166 /* Applications that neglect to set up their own setjmp() and then encounter
       
   167    a png_error() will longjmp here.  Since the jmpbuf is then meaningless we
       
   168    abort instead of returning. */
       
   169 #ifdef USE_FAR_KEYWORD
       
   170    if (setjmp(jmpbuf))
       
   171       PNG_ABORT();
       
   172    png_memcpy(png_ptr->jmpbuf, jmpbuf, png_sizeof(jmp_buf));
       
   173 #else
       
   174    if (setjmp(png_ptr->jmpbuf))
       
   175       PNG_ABORT();
       
   176 #endif
       
   177 #endif
       
   178    return (png_ptr);
   192    return (png_ptr);
   179 }
   193 }
   180 
   194 
   181 #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
   195 
   182 /* Initialize PNG structure for reading, and allocate any memory needed.
   196 #ifdef PNG_SEQUENTIAL_READ_SUPPORTED
   183    This interface is deprecated in favour of the png_create_read_struct(),
       
   184    and it will disappear as of libpng-1.3.0. */
       
   185 #undef png_read_init
       
   186 void PNGAPI
       
   187 png_read_init(png_structp png_ptr)
       
   188 {
       
   189    /* We only come here via pre-1.0.7-compiled applications */
       
   190    png_read_init_2(png_ptr, "1.0.6 or earlier", 0, 0);
       
   191 }
       
   192 
       
   193 void PNGAPI
       
   194 png_read_init_2(png_structp png_ptr, png_const_charp user_png_ver,
       
   195    png_size_t png_struct_size, png_size_t png_info_size)
       
   196 {
       
   197    /* We only come here via pre-1.0.12-compiled applications */
       
   198    if (png_ptr == NULL)
       
   199       return;
       
   200 #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
       
   201    if (png_sizeof(png_struct) > png_struct_size ||
       
   202       png_sizeof(png_info) > png_info_size)
       
   203    {
       
   204       char msg[80];
       
   205       png_ptr->warning_fn = NULL;
       
   206       if (user_png_ver)
       
   207       {
       
   208         png_snprintf(msg, 80,
       
   209            "Application was compiled with png.h from libpng-%.20s",
       
   210            user_png_ver);
       
   211         png_warning(png_ptr, msg);
       
   212       }
       
   213       png_snprintf(msg, 80,
       
   214          "Application  is  running with png.c from libpng-%.20s",
       
   215          png_libpng_ver);
       
   216       png_warning(png_ptr, msg);
       
   217    }
       
   218 #endif
       
   219    if (png_sizeof(png_struct) > png_struct_size)
       
   220      {
       
   221        png_ptr->error_fn = NULL;
       
   222 #ifdef PNG_ERROR_NUMBERS_SUPPORTED
       
   223        png_ptr->flags = 0;
       
   224 #endif
       
   225        png_error(png_ptr,
       
   226        "The png struct allocated by the application for reading is too small.");
       
   227      }
       
   228    if (png_sizeof(png_info) > png_info_size)
       
   229      {
       
   230        png_ptr->error_fn = NULL;
       
   231 #ifdef PNG_ERROR_NUMBERS_SUPPORTED
       
   232        png_ptr->flags = 0;
       
   233 #endif
       
   234        png_error(png_ptr,
       
   235          "The info struct allocated by application for reading is too small.");
       
   236      }
       
   237    png_read_init_3(&png_ptr, user_png_ver, png_struct_size);
       
   238 }
       
   239 #endif /* PNG_1_0_X || PNG_1_2_X */
       
   240 
       
   241 void PNGAPI
       
   242 png_read_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
       
   243    png_size_t png_struct_size)
       
   244 {
       
   245 #ifdef PNG_SETJMP_SUPPORTED
       
   246    jmp_buf tmp_jmp;  /* to save current jump buffer */
       
   247 #endif
       
   248 
       
   249    int i = 0;
       
   250 
       
   251    png_structp png_ptr=*ptr_ptr;
       
   252 
       
   253    if (png_ptr == NULL)
       
   254       return;
       
   255 
       
   256    do
       
   257    {
       
   258      if (user_png_ver[i] != png_libpng_ver[i])
       
   259      {
       
   260 #ifdef PNG_LEGACY_SUPPORTED
       
   261        png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
       
   262 #else
       
   263        png_ptr->warning_fn = NULL;
       
   264        png_warning(png_ptr,
       
   265         "Application uses deprecated png_read_init() and should be recompiled.");
       
   266        break;
       
   267 #endif
       
   268      }
       
   269    } while (png_libpng_ver[i++]);
       
   270 
       
   271    png_debug(1, "in png_read_init_3");
       
   272 
       
   273 #ifdef PNG_SETJMP_SUPPORTED
       
   274    /* Save jump buffer and error functions */
       
   275    png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof(jmp_buf));
       
   276 #endif
       
   277 
       
   278    if (png_sizeof(png_struct) > png_struct_size)
       
   279    {
       
   280       png_destroy_struct(png_ptr);
       
   281       *ptr_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
       
   282       png_ptr = *ptr_ptr;
       
   283    }
       
   284 
       
   285    /* Reset all variables to 0 */
       
   286    png_memset(png_ptr, 0, png_sizeof(png_struct));
       
   287 
       
   288 #ifdef PNG_SETJMP_SUPPORTED
       
   289    /* Restore jump buffer */
       
   290    png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof(jmp_buf));
       
   291 #endif
       
   292 
       
   293    /* Added at libpng-1.2.6 */
       
   294 #ifdef PNG_SET_USER_LIMITS_SUPPORTED
       
   295    png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
       
   296    png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
       
   297 #endif
       
   298 
       
   299    /* Initialize zbuf - compression buffer */
       
   300    png_ptr->zbuf_size = PNG_ZBUF_SIZE;
       
   301    png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
       
   302      (png_uint_32)png_ptr->zbuf_size);
       
   303    png_ptr->zstream.zalloc = png_zalloc;
       
   304    png_ptr->zstream.zfree = png_zfree;
       
   305    png_ptr->zstream.opaque = (voidpf)png_ptr;
       
   306 
       
   307    switch (inflateInit(&png_ptr->zstream))
       
   308    {
       
   309      case Z_OK: /* Do nothing */ break;
       
   310      case Z_MEM_ERROR:
       
   311      case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory"); break;
       
   312      case Z_VERSION_ERROR: png_error(png_ptr, "zlib version"); break;
       
   313      default: png_error(png_ptr, "Unknown zlib error");
       
   314    }
       
   315 
       
   316    png_ptr->zstream.next_out = png_ptr->zbuf;
       
   317    png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
       
   318 
       
   319    png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL);
       
   320 }
       
   321 
       
   322 #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
       
   323 /* Read the information before the actual image data.  This has been
   197 /* Read the information before the actual image data.  This has been
   324  * changed in v0.90 to allow reading a file that already has the magic
   198  * changed in v0.90 to allow reading a file that already has the magic
   325  * bytes read from the stream.  You can tell libpng how many bytes have
   199  * bytes read from the stream.  You can tell libpng how many bytes have
   326  * been read from the beginning of the stream (up to the maximum of 8)
   200  * been read from the beginning of the stream (up to the maximum of 8)
   327  * via png_set_sig_bytes(), and we will only check the remaining bytes
   201  * via png_set_sig_bytes(), and we will only check the remaining bytes
   329  * read if it is determined that this isn't a valid PNG file.
   203  * read if it is determined that this isn't a valid PNG file.
   330  */
   204  */
   331 void PNGAPI
   205 void PNGAPI
   332 png_read_info(png_structp png_ptr, png_infop info_ptr)
   206 png_read_info(png_structp png_ptr, png_infop info_ptr)
   333 {
   207 {
       
   208    png_debug(1, "in png_read_info");
       
   209  
   334    if (png_ptr == NULL || info_ptr == NULL)
   210    if (png_ptr == NULL || info_ptr == NULL)
   335       return;
   211       return;
   336    png_debug(1, "in png_read_info");
   212  
   337    /* If we haven't checked all of the PNG signature bytes, do so now. */
   213    /* If we haven't checked all of the PNG signature bytes, do so now. */
   338    if (png_ptr->sig_bytes < 8)
   214    if (png_ptr->sig_bytes < 8)
   339    {
   215    {
   340       png_size_t num_checked = png_ptr->sig_bytes,
   216       png_size_t num_checked = png_ptr->sig_bytes,
   341                  num_to_check = 8 - num_checked;
   217                  num_to_check = 8 - num_checked;
       
   218 
       
   219 #ifdef PNG_IO_STATE_SUPPORTED
       
   220       png_ptr->io_state = PNG_IO_READING | PNG_IO_SIGNATURE;
       
   221 #endif
   342 
   222 
   343       png_read_data(png_ptr, &(info_ptr->signature[num_checked]), num_to_check);
   223       png_read_data(png_ptr, &(info_ptr->signature[num_checked]), num_to_check);
   344       png_ptr->sig_bytes = 8;
   224       png_ptr->sig_bytes = 8;
   345 
   225 
   346       if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
   226       if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
   355          png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
   235          png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
   356    }
   236    }
   357 
   237 
   358    for (;;)
   238    for (;;)
   359    {
   239    {
   360 #ifdef PNG_USE_LOCAL_ARRAYS
   240       PNG_IHDR;
   361       PNG_CONST PNG_IHDR;
   241       PNG_IDAT;
   362       PNG_CONST PNG_IDAT;
   242       PNG_IEND;
   363       PNG_CONST PNG_IEND;
   243       PNG_PLTE;
   364       PNG_CONST PNG_PLTE;
   244 #ifdef PNG_READ_bKGD_SUPPORTED
   365 #if defined(PNG_READ_bKGD_SUPPORTED)
   245       PNG_bKGD;
   366       PNG_CONST PNG_bKGD;
   246 #endif
   367 #endif
   247 #ifdef PNG_READ_cHRM_SUPPORTED
   368 #if defined(PNG_READ_cHRM_SUPPORTED)
   248       PNG_cHRM;
   369       PNG_CONST PNG_cHRM;
   249 #endif
   370 #endif
   250 #ifdef PNG_READ_gAMA_SUPPORTED
   371 #if defined(PNG_READ_gAMA_SUPPORTED)
   251       PNG_gAMA;
   372       PNG_CONST PNG_gAMA;
   252 #endif
   373 #endif
   253 #ifdef PNG_READ_hIST_SUPPORTED
   374 #if defined(PNG_READ_hIST_SUPPORTED)
   254       PNG_hIST;
   375       PNG_CONST PNG_hIST;
   255 #endif
   376 #endif
   256 #ifdef PNG_READ_iCCP_SUPPORTED
   377 #if defined(PNG_READ_iCCP_SUPPORTED)
   257       PNG_iCCP;
   378       PNG_CONST PNG_iCCP;
   258 #endif
   379 #endif
   259 #ifdef PNG_READ_iTXt_SUPPORTED
   380 #if defined(PNG_READ_iTXt_SUPPORTED)
   260       PNG_iTXt;
   381       PNG_CONST PNG_iTXt;
   261 #endif
   382 #endif
   262 #ifdef PNG_READ_oFFs_SUPPORTED
   383 #if defined(PNG_READ_oFFs_SUPPORTED)
   263       PNG_oFFs;
   384       PNG_CONST PNG_oFFs;
   264 #endif
   385 #endif
   265 #ifdef PNG_READ_pCAL_SUPPORTED
   386 #if defined(PNG_READ_pCAL_SUPPORTED)
   266       PNG_pCAL;
   387       PNG_CONST PNG_pCAL;
   267 #endif
   388 #endif
   268 #ifdef PNG_READ_pHYs_SUPPORTED
   389 #if defined(PNG_READ_pHYs_SUPPORTED)
   269       PNG_pHYs;
   390       PNG_CONST PNG_pHYs;
   270 #endif
   391 #endif
   271 #ifdef PNG_READ_sBIT_SUPPORTED
   392 #if defined(PNG_READ_sBIT_SUPPORTED)
   272       PNG_sBIT;
   393       PNG_CONST PNG_sBIT;
   273 #endif
   394 #endif
   274 #ifdef PNG_READ_sCAL_SUPPORTED
   395 #if defined(PNG_READ_sCAL_SUPPORTED)
   275       PNG_sCAL;
   396       PNG_CONST PNG_sCAL;
   276 #endif
   397 #endif
   277 #ifdef PNG_READ_sPLT_SUPPORTED
   398 #if defined(PNG_READ_sPLT_SUPPORTED)
   278       PNG_sPLT;
   399       PNG_CONST PNG_sPLT;
   279 #endif
   400 #endif
   280 #ifdef PNG_READ_sRGB_SUPPORTED
   401 #if defined(PNG_READ_sRGB_SUPPORTED)
   281       PNG_sRGB;
   402       PNG_CONST PNG_sRGB;
   282 #endif
   403 #endif
   283 #ifdef PNG_READ_tEXt_SUPPORTED
   404 #if defined(PNG_READ_tEXt_SUPPORTED)
   284       PNG_tEXt;
   405       PNG_CONST PNG_tEXt;
   285 #endif
   406 #endif
   286 #ifdef PNG_READ_tIME_SUPPORTED
   407 #if defined(PNG_READ_tIME_SUPPORTED)
   287       PNG_tIME;
   408       PNG_CONST PNG_tIME;
   288 #endif
   409 #endif
   289 #ifdef PNG_READ_tRNS_SUPPORTED
   410 #if defined(PNG_READ_tRNS_SUPPORTED)
   290       PNG_tRNS;
   411       PNG_CONST PNG_tRNS;
   291 #endif
   412 #endif
   292 #ifdef PNG_READ_zTXt_SUPPORTED
   413 #if defined(PNG_READ_zTXt_SUPPORTED)
   293       PNG_zTXt;
   414       PNG_CONST PNG_zTXt;
   294 #endif
   415 #endif
       
   416 #endif /* PNG_USE_LOCAL_ARRAYS */
       
   417       png_uint_32 length = png_read_chunk_header(png_ptr);
   295       png_uint_32 length = png_read_chunk_header(png_ptr);
   418       PNG_CONST png_bytep chunk_name = png_ptr->chunk_name;
   296       PNG_CONST png_bytep chunk_name = png_ptr->chunk_name;
   419 
   297 
   420       /* This should be a binary subdivision search or a hash for
   298       /* This should be a binary subdivision search or a hash for
   421        * matching the chunk name rather than a linear search.
   299        * matching the chunk name rather than a linear search.
   459 
   337 
   460          png_ptr->idat_size = length;
   338          png_ptr->idat_size = length;
   461          png_ptr->mode |= PNG_HAVE_IDAT;
   339          png_ptr->mode |= PNG_HAVE_IDAT;
   462          break;
   340          break;
   463       }
   341       }
   464 #if defined(PNG_READ_bKGD_SUPPORTED)
   342 #ifdef PNG_READ_bKGD_SUPPORTED
   465       else if (!png_memcmp(chunk_name, png_bKGD, 4))
   343       else if (!png_memcmp(chunk_name, png_bKGD, 4))
   466          png_handle_bKGD(png_ptr, info_ptr, length);
   344          png_handle_bKGD(png_ptr, info_ptr, length);
   467 #endif
   345 #endif
   468 #if defined(PNG_READ_cHRM_SUPPORTED)
   346 #ifdef PNG_READ_cHRM_SUPPORTED
   469       else if (!png_memcmp(chunk_name, png_cHRM, 4))
   347       else if (!png_memcmp(chunk_name, png_cHRM, 4))
   470          png_handle_cHRM(png_ptr, info_ptr, length);
   348          png_handle_cHRM(png_ptr, info_ptr, length);
   471 #endif
   349 #endif
   472 #if defined(PNG_READ_gAMA_SUPPORTED)
   350 #ifdef PNG_READ_gAMA_SUPPORTED
   473       else if (!png_memcmp(chunk_name, png_gAMA, 4))
   351       else if (!png_memcmp(chunk_name, png_gAMA, 4))
   474          png_handle_gAMA(png_ptr, info_ptr, length);
   352          png_handle_gAMA(png_ptr, info_ptr, length);
   475 #endif
   353 #endif
   476 #if defined(PNG_READ_hIST_SUPPORTED)
   354 #ifdef PNG_READ_hIST_SUPPORTED
   477       else if (!png_memcmp(chunk_name, png_hIST, 4))
   355       else if (!png_memcmp(chunk_name, png_hIST, 4))
   478          png_handle_hIST(png_ptr, info_ptr, length);
   356          png_handle_hIST(png_ptr, info_ptr, length);
   479 #endif
   357 #endif
   480 #if defined(PNG_READ_oFFs_SUPPORTED)
   358 #ifdef PNG_READ_oFFs_SUPPORTED
   481       else if (!png_memcmp(chunk_name, png_oFFs, 4))
   359       else if (!png_memcmp(chunk_name, png_oFFs, 4))
   482          png_handle_oFFs(png_ptr, info_ptr, length);
   360          png_handle_oFFs(png_ptr, info_ptr, length);
   483 #endif
   361 #endif
   484 #if defined(PNG_READ_pCAL_SUPPORTED)
   362 #ifdef PNG_READ_pCAL_SUPPORTED
   485       else if (!png_memcmp(chunk_name, png_pCAL, 4))
   363       else if (!png_memcmp(chunk_name, png_pCAL, 4))
   486          png_handle_pCAL(png_ptr, info_ptr, length);
   364          png_handle_pCAL(png_ptr, info_ptr, length);
   487 #endif
   365 #endif
   488 #if defined(PNG_READ_sCAL_SUPPORTED)
   366 #ifdef PNG_READ_sCAL_SUPPORTED
   489       else if (!png_memcmp(chunk_name, png_sCAL, 4))
   367       else if (!png_memcmp(chunk_name, png_sCAL, 4))
   490          png_handle_sCAL(png_ptr, info_ptr, length);
   368          png_handle_sCAL(png_ptr, info_ptr, length);
   491 #endif
   369 #endif
   492 #if defined(PNG_READ_pHYs_SUPPORTED)
   370 #ifdef PNG_READ_pHYs_SUPPORTED
   493       else if (!png_memcmp(chunk_name, png_pHYs, 4))
   371       else if (!png_memcmp(chunk_name, png_pHYs, 4))
   494          png_handle_pHYs(png_ptr, info_ptr, length);
   372          png_handle_pHYs(png_ptr, info_ptr, length);
   495 #endif
   373 #endif
   496 #if defined(PNG_READ_sBIT_SUPPORTED)
   374 #ifdef PNG_READ_sBIT_SUPPORTED
   497       else if (!png_memcmp(chunk_name, png_sBIT, 4))
   375       else if (!png_memcmp(chunk_name, png_sBIT, 4))
   498          png_handle_sBIT(png_ptr, info_ptr, length);
   376          png_handle_sBIT(png_ptr, info_ptr, length);
   499 #endif
   377 #endif
   500 #if defined(PNG_READ_sRGB_SUPPORTED)
   378 #ifdef PNG_READ_sRGB_SUPPORTED
   501       else if (!png_memcmp(chunk_name, png_sRGB, 4))
   379       else if (!png_memcmp(chunk_name, png_sRGB, 4))
   502          png_handle_sRGB(png_ptr, info_ptr, length);
   380          png_handle_sRGB(png_ptr, info_ptr, length);
   503 #endif
   381 #endif
   504 #if defined(PNG_READ_iCCP_SUPPORTED)
   382 #ifdef PNG_READ_iCCP_SUPPORTED
   505       else if (!png_memcmp(chunk_name, png_iCCP, 4))
   383       else if (!png_memcmp(chunk_name, png_iCCP, 4))
   506          png_handle_iCCP(png_ptr, info_ptr, length);
   384          png_handle_iCCP(png_ptr, info_ptr, length);
   507 #endif
   385 #endif
   508 #if defined(PNG_READ_sPLT_SUPPORTED)
   386 #ifdef PNG_READ_sPLT_SUPPORTED
   509       else if (!png_memcmp(chunk_name, png_sPLT, 4))
   387       else if (!png_memcmp(chunk_name, png_sPLT, 4))
   510          png_handle_sPLT(png_ptr, info_ptr, length);
   388          png_handle_sPLT(png_ptr, info_ptr, length);
   511 #endif
   389 #endif
   512 #if defined(PNG_READ_tEXt_SUPPORTED)
   390 #ifdef PNG_READ_tEXt_SUPPORTED
   513       else if (!png_memcmp(chunk_name, png_tEXt, 4))
   391       else if (!png_memcmp(chunk_name, png_tEXt, 4))
   514          png_handle_tEXt(png_ptr, info_ptr, length);
   392          png_handle_tEXt(png_ptr, info_ptr, length);
   515 #endif
   393 #endif
   516 #if defined(PNG_READ_tIME_SUPPORTED)
   394 #ifdef PNG_READ_tIME_SUPPORTED
   517       else if (!png_memcmp(chunk_name, png_tIME, 4))
   395       else if (!png_memcmp(chunk_name, png_tIME, 4))
   518          png_handle_tIME(png_ptr, info_ptr, length);
   396          png_handle_tIME(png_ptr, info_ptr, length);
   519 #endif
   397 #endif
   520 #if defined(PNG_READ_tRNS_SUPPORTED)
   398 #ifdef PNG_READ_tRNS_SUPPORTED
   521       else if (!png_memcmp(chunk_name, png_tRNS, 4))
   399       else if (!png_memcmp(chunk_name, png_tRNS, 4))
   522          png_handle_tRNS(png_ptr, info_ptr, length);
   400          png_handle_tRNS(png_ptr, info_ptr, length);
   523 #endif
   401 #endif
   524 #if defined(PNG_READ_zTXt_SUPPORTED)
   402 #ifdef PNG_READ_zTXt_SUPPORTED
   525       else if (!png_memcmp(chunk_name, png_zTXt, 4))
   403       else if (!png_memcmp(chunk_name, png_zTXt, 4))
   526          png_handle_zTXt(png_ptr, info_ptr, length);
   404          png_handle_zTXt(png_ptr, info_ptr, length);
   527 #endif
   405 #endif
   528 #if defined(PNG_READ_iTXt_SUPPORTED)
   406 #ifdef PNG_READ_iTXt_SUPPORTED
   529       else if (!png_memcmp(chunk_name, png_iTXt, 4))
   407       else if (!png_memcmp(chunk_name, png_iTXt, 4))
   530          png_handle_iTXt(png_ptr, info_ptr, length);
   408          png_handle_iTXt(png_ptr, info_ptr, length);
   531 #endif
   409 #endif
   532       else
   410       else
   533          png_handle_unknown(png_ptr, info_ptr, length);
   411          png_handle_unknown(png_ptr, info_ptr, length);
   534    }
   412    }
   535 }
   413 }
   536 #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
   414 #endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
   537 
   415 
   538 /* Optional call to update the users info_ptr structure */
   416 /* Optional call to update the users info_ptr structure */
   539 void PNGAPI
   417 void PNGAPI
   540 png_read_update_info(png_structp png_ptr, png_infop info_ptr)
   418 png_read_update_info(png_structp png_ptr, png_infop info_ptr)
   541 {
   419 {
   542    png_debug(1, "in png_read_update_info");
   420    png_debug(1, "in png_read_update_info");
       
   421  
   543    if (png_ptr == NULL)
   422    if (png_ptr == NULL)
   544       return;
   423       return;
   545    if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
   424    if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
   546       png_read_start_row(png_ptr);
   425       png_read_start_row(png_ptr);
   547    else
   426    else
   548       png_warning(png_ptr,
   427       png_warning(png_ptr,
   549       "Ignoring extra png_read_update_info() call; row buffer not reallocated");
   428       "Ignoring extra png_read_update_info() call; row buffer not reallocated");
       
   429 
   550    png_read_transform_info(png_ptr, info_ptr);
   430    png_read_transform_info(png_ptr, info_ptr);
   551 }
   431 }
   552 
   432 
   553 #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
   433 #ifdef PNG_SEQUENTIAL_READ_SUPPORTED
   554 /* Initialize palette, background, etc, after transformations
   434 /* Initialize palette, background, etc, after transformations
   555  * are set, but before any reading takes place.  This allows
   435  * are set, but before any reading takes place.  This allows
   556  * the user to obtain a gamma-corrected palette, for example.
   436  * the user to obtain a gamma-corrected palette, for example.
   557  * If the user doesn't call this, we will do it ourselves.
   437  * If the user doesn't call this, we will do it ourselves.
   558  */
   438  */
   559 void PNGAPI
   439 void PNGAPI
   560 png_start_read_image(png_structp png_ptr)
   440 png_start_read_image(png_structp png_ptr)
   561 {
   441 {
   562    png_debug(1, "in png_start_read_image");
   442    png_debug(1, "in png_start_read_image");
       
   443  
   563    if (png_ptr == NULL)
   444    if (png_ptr == NULL)
   564       return;
   445       return;
   565    if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
   446    if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
   566       png_read_start_row(png_ptr);
   447       png_read_start_row(png_ptr);
   567 }
   448 }
   568 #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
   449 #endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
   569 
   450 
   570 #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
   451 #ifdef PNG_SEQUENTIAL_READ_SUPPORTED
   571 void PNGAPI
   452 void PNGAPI
   572 png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
   453 png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
   573 {
   454 {
   574 #ifdef PNG_USE_LOCAL_ARRAYS
   455    PNG_IDAT;
   575    PNG_CONST PNG_IDAT;
       
   576    PNG_CONST int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55,
   456    PNG_CONST int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55,
   577       0xff};
   457       0xff};
   578    PNG_CONST int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
   458    PNG_CONST int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
   579 #endif
       
   580    int ret;
   459    int ret;
       
   460  
   581    if (png_ptr == NULL)
   461    if (png_ptr == NULL)
   582       return;
   462       return;
       
   463  
   583    png_debug2(1, "in png_read_row (row %lu, pass %d)",
   464    png_debug2(1, "in png_read_row (row %lu, pass %d)",
   584       png_ptr->row_number, png_ptr->pass);
   465       (unsigned long) png_ptr->row_number, png_ptr->pass);
       
   466 
   585    if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
   467    if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
   586       png_read_start_row(png_ptr);
   468       png_read_start_row(png_ptr);
   587    if (png_ptr->row_number == 0 && png_ptr->pass == 0)
   469    if (png_ptr->row_number == 0 && png_ptr->pass == 0)
   588    {
   470    {
   589    /* Check for transforms that have been set but were defined out */
   471    /* Check for transforms that have been set but were defined out */
   590 #if defined(PNG_WRITE_INVERT_SUPPORTED) && !defined(PNG_READ_INVERT_SUPPORTED)
   472 #if defined(PNG_WRITE_INVERT_SUPPORTED) && !defined(PNG_READ_INVERT_SUPPORTED)
   591    if (png_ptr->transformations & PNG_INVERT_MONO)
   473    if (png_ptr->transformations & PNG_INVERT_MONO)
   592       png_warning(png_ptr, "PNG_READ_INVERT_SUPPORTED is not defined.");
   474       png_warning(png_ptr, "PNG_READ_INVERT_SUPPORTED is not defined");
   593 #endif
   475 #endif
   594 #if defined(PNG_WRITE_FILLER_SUPPORTED) && !defined(PNG_READ_FILLER_SUPPORTED)
   476 #if defined(PNG_WRITE_FILLER_SUPPORTED) && !defined(PNG_READ_FILLER_SUPPORTED)
   595    if (png_ptr->transformations & PNG_FILLER)
   477    if (png_ptr->transformations & PNG_FILLER)
   596       png_warning(png_ptr, "PNG_READ_FILLER_SUPPORTED is not defined.");
   478       png_warning(png_ptr, "PNG_READ_FILLER_SUPPORTED is not defined");
   597 #endif
   479 #endif
   598 #if defined(PNG_WRITE_PACKSWAP_SUPPORTED) && !defined(PNG_READ_PACKSWAP_SUPPORTED)
   480 #if defined(PNG_WRITE_PACKSWAP_SUPPORTED) && !defined(PNG_READ_PACKSWAP_SUPPORTED)
   599    if (png_ptr->transformations & PNG_PACKSWAP)
   481    if (png_ptr->transformations & PNG_PACKSWAP)
   600       png_warning(png_ptr, "PNG_READ_PACKSWAP_SUPPORTED is not defined.");
   482       png_warning(png_ptr, "PNG_READ_PACKSWAP_SUPPORTED is not defined");
   601 #endif
   483 #endif
   602 #if defined(PNG_WRITE_PACK_SUPPORTED) && !defined(PNG_READ_PACK_SUPPORTED)
   484 #if defined(PNG_WRITE_PACK_SUPPORTED) && !defined(PNG_READ_PACK_SUPPORTED)
   603    if (png_ptr->transformations & PNG_PACK)
   485    if (png_ptr->transformations & PNG_PACK)
   604       png_warning(png_ptr, "PNG_READ_PACK_SUPPORTED is not defined.");
   486       png_warning(png_ptr, "PNG_READ_PACK_SUPPORTED is not defined");
   605 #endif
   487 #endif
   606 #if defined(PNG_WRITE_SHIFT_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED)
   488 #if defined(PNG_WRITE_SHIFT_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED)
   607    if (png_ptr->transformations & PNG_SHIFT)
   489    if (png_ptr->transformations & PNG_SHIFT)
   608       png_warning(png_ptr, "PNG_READ_SHIFT_SUPPORTED is not defined.");
   490       png_warning(png_ptr, "PNG_READ_SHIFT_SUPPORTED is not defined");
   609 #endif
   491 #endif
   610 #if defined(PNG_WRITE_BGR_SUPPORTED) && !defined(PNG_READ_BGR_SUPPORTED)
   492 #if defined(PNG_WRITE_BGR_SUPPORTED) && !defined(PNG_READ_BGR_SUPPORTED)
   611    if (png_ptr->transformations & PNG_BGR)
   493    if (png_ptr->transformations & PNG_BGR)
   612       png_warning(png_ptr, "PNG_READ_BGR_SUPPORTED is not defined.");
   494       png_warning(png_ptr, "PNG_READ_BGR_SUPPORTED is not defined");
   613 #endif
   495 #endif
   614 #if defined(PNG_WRITE_SWAP_SUPPORTED) && !defined(PNG_READ_SWAP_SUPPORTED)
   496 #if defined(PNG_WRITE_SWAP_SUPPORTED) && !defined(PNG_READ_SWAP_SUPPORTED)
   615    if (png_ptr->transformations & PNG_SWAP_BYTES)
   497    if (png_ptr->transformations & PNG_SWAP_BYTES)
   616       png_warning(png_ptr, "PNG_READ_SWAP_SUPPORTED is not defined.");
   498       png_warning(png_ptr, "PNG_READ_SWAP_SUPPORTED is not defined");
   617 #endif
   499 #endif
   618    }
   500    }
   619 
   501 
   620 #if defined(PNG_READ_INTERLACING_SUPPORTED)
   502 #ifdef PNG_READ_INTERLACING_SUPPORTED
   621    /* If interlaced and we do not need a new row, combine row and return */
   503    /* If interlaced and we do not need a new row, combine row and return */
   622    if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
   504    if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
   623    {
   505    {
   624       switch (png_ptr->pass)
   506       switch (png_ptr->pass)
   625       {
   507       {
   722       ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
   604       ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
   723       if (ret == Z_STREAM_END)
   605       if (ret == Z_STREAM_END)
   724       {
   606       {
   725          if (png_ptr->zstream.avail_out || png_ptr->zstream.avail_in ||
   607          if (png_ptr->zstream.avail_out || png_ptr->zstream.avail_in ||
   726             png_ptr->idat_size)
   608             png_ptr->idat_size)
   727             png_error(png_ptr, "Extra compressed data");
   609             png_benign_error(png_ptr, "Extra compressed data");
   728          png_ptr->mode |= PNG_AFTER_IDAT;
   610          png_ptr->mode |= PNG_AFTER_IDAT;
   729          png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
   611          png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
   730          break;
   612          break;
   731       }
   613       }
   732       if (ret != Z_OK)
   614       if (ret != Z_OK)
   746    if (png_ptr->row_buf[0])
   628    if (png_ptr->row_buf[0])
   747    png_read_filter_row(png_ptr, &(png_ptr->row_info),
   629    png_read_filter_row(png_ptr, &(png_ptr->row_info),
   748       png_ptr->row_buf + 1, png_ptr->prev_row + 1,
   630       png_ptr->row_buf + 1, png_ptr->prev_row + 1,
   749       (int)(png_ptr->row_buf[0]));
   631       (int)(png_ptr->row_buf[0]));
   750 
   632 
   751    png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
   633    png_memcpy(png_ptr->prev_row, png_ptr->row_buf, png_ptr->rowbytes + 1);
   752       png_ptr->rowbytes + 1);
   634 
   753 
   635 #ifdef PNG_MNG_FEATURES_SUPPORTED
   754 #if defined(PNG_MNG_FEATURES_SUPPORTED)
       
   755    if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
   636    if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
   756       (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
   637       (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
   757    {
   638    {
   758       /* Intrapixel differencing */
   639       /* Intrapixel differencing */
   759       png_do_read_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1);
   640       png_do_read_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1);
   762 
   643 
   763 
   644 
   764    if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
   645    if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
   765       png_do_read_transformations(png_ptr);
   646       png_do_read_transformations(png_ptr);
   766 
   647 
   767 #if defined(PNG_READ_INTERLACING_SUPPORTED)
   648 #ifdef PNG_READ_INTERLACING_SUPPORTED
   768    /* Blow up interlaced rows to full size */
   649    /* Blow up interlaced rows to full size */
   769    if (png_ptr->interlaced &&
   650    if (png_ptr->interlaced &&
   770       (png_ptr->transformations & PNG_INTERLACE))
   651       (png_ptr->transformations & PNG_INTERLACE))
   771    {
   652    {
   772       if (png_ptr->pass < 6)
   653       if (png_ptr->pass < 6)
   794    png_read_finish_row(png_ptr);
   675    png_read_finish_row(png_ptr);
   795 
   676 
   796    if (png_ptr->read_row_fn != NULL)
   677    if (png_ptr->read_row_fn != NULL)
   797       (*(png_ptr->read_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
   678       (*(png_ptr->read_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
   798 }
   679 }
   799 #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
   680 #endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
   800 
   681 
   801 #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
   682 #ifdef PNG_SEQUENTIAL_READ_SUPPORTED
   802 /* Read one or more rows of image data.  If the image is interlaced,
   683 /* Read one or more rows of image data.  If the image is interlaced,
   803  * and png_set_interlace_handling() has been called, the rows need to
   684  * and png_set_interlace_handling() has been called, the rows need to
   804  * contain the contents of the rows from the previous pass.  If the
   685  * contain the contents of the rows from the previous pass.  If the
   805  * image has alpha or transparency, and png_handle_alpha()[*] has been
   686  * image has alpha or transparency, and png_handle_alpha()[*] has been
   806  * called, the rows contents must be initialized to the contents of the
   687  * called, the rows contents must be initialized to the contents of the
   830    png_uint_32 i;
   711    png_uint_32 i;
   831    png_bytepp rp;
   712    png_bytepp rp;
   832    png_bytepp dp;
   713    png_bytepp dp;
   833 
   714 
   834    png_debug(1, "in png_read_rows");
   715    png_debug(1, "in png_read_rows");
       
   716  
   835    if (png_ptr == NULL)
   717    if (png_ptr == NULL)
   836       return;
   718       return;
   837    rp = row;
   719    rp = row;
   838    dp = display_row;
   720    dp = display_row;
   839    if (rp != NULL && dp != NULL)
   721    if (rp != NULL && dp != NULL)
   846       }
   728       }
   847    else if (rp != NULL)
   729    else if (rp != NULL)
   848       for (i = 0; i < num_rows; i++)
   730       for (i = 0; i < num_rows; i++)
   849       {
   731       {
   850          png_bytep rptr = *rp;
   732          png_bytep rptr = *rp;
   851          png_read_row(png_ptr, rptr, png_bytep_NULL);
   733          png_read_row(png_ptr, rptr, NULL);
   852          rp++;
   734          rp++;
   853       }
   735       }
   854    else if (dp != NULL)
   736    else if (dp != NULL)
   855       for (i = 0; i < num_rows; i++)
   737       for (i = 0; i < num_rows; i++)
   856       {
   738       {
   857          png_bytep dptr = *dp;
   739          png_bytep dptr = *dp;
   858          png_read_row(png_ptr, png_bytep_NULL, dptr);
   740          png_read_row(png_ptr, NULL, dptr);
   859          dp++;
   741          dp++;
   860       }
   742       }
   861 }
   743 }
   862 #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
   744 #endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
   863 
   745 
   864 #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
   746 #ifdef PNG_SEQUENTIAL_READ_SUPPORTED
   865 /* Read the entire image.  If the image has an alpha channel or a tRNS
   747 /* Read the entire image.  If the image has an alpha channel or a tRNS
   866  * chunk, and you have called png_handle_alpha()[*], you will need to
   748  * chunk, and you have called png_handle_alpha()[*], you will need to
   867  * initialize the image to the current image that PNG will be overlaying.
   749  * initialize the image to the current image that PNG will be overlaying.
   868  * We set the num_rows again here, in case it was incorrectly set in
   750  * We set the num_rows again here, in case it was incorrectly set in
   869  * png_read_start_row() by a call to png_read_update_info() or
   751  * png_read_start_row() by a call to png_read_update_info() or
   880    png_uint_32 i, image_height;
   762    png_uint_32 i, image_height;
   881    int pass, j;
   763    int pass, j;
   882    png_bytepp rp;
   764    png_bytepp rp;
   883 
   765 
   884    png_debug(1, "in png_read_image");
   766    png_debug(1, "in png_read_image");
       
   767  
   885    if (png_ptr == NULL)
   768    if (png_ptr == NULL)
   886       return;
   769       return;
   887 
   770 
   888 #ifdef PNG_READ_INTERLACING_SUPPORTED
   771 #ifdef PNG_READ_INTERLACING_SUPPORTED
   889    pass = png_set_interlace_handling(png_ptr);
   772    pass = png_set_interlace_handling(png_ptr);
   890 #else
   773 #else
   891    if (png_ptr->interlaced)
   774    if (png_ptr->interlaced)
   892       png_error(png_ptr,
   775       png_error(png_ptr,
   893         "Cannot read interlaced image -- interlace handler disabled.");
   776         "Cannot read interlaced image -- interlace handler disabled");
   894    pass = 1;
   777    pass = 1;
   895 #endif
   778 #endif
   896 
   779 
   897 
   780 
   898    image_height=png_ptr->height;
   781    image_height=png_ptr->height;
   901    for (j = 0; j < pass; j++)
   784    for (j = 0; j < pass; j++)
   902    {
   785    {
   903       rp = image;
   786       rp = image;
   904       for (i = 0; i < image_height; i++)
   787       for (i = 0; i < image_height; i++)
   905       {
   788       {
   906          png_read_row(png_ptr, *rp, png_bytep_NULL);
   789          png_read_row(png_ptr, *rp, NULL);
   907          rp++;
   790          rp++;
   908       }
   791       }
   909    }
   792    }
   910 }
   793 }
   911 #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
   794 #endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
   912 
   795 
   913 #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
   796 #ifdef PNG_SEQUENTIAL_READ_SUPPORTED
   914 /* Read the end of the PNG file.  Will not read past the end of the
   797 /* Read the end of the PNG file.  Will not read past the end of the
   915  * file, will verify the end is accurate, and will read any comments
   798  * file, will verify the end is accurate, and will read any comments
   916  * or time information at the end of the file, if info is not NULL.
   799  * or time information at the end of the file, if info is not NULL.
   917  */
   800  */
   918 void PNGAPI
   801 void PNGAPI
   919 png_read_end(png_structp png_ptr, png_infop info_ptr)
   802 png_read_end(png_structp png_ptr, png_infop info_ptr)
   920 {
   803 {
   921    png_debug(1, "in png_read_end");
   804    png_debug(1, "in png_read_end");
       
   805  
   922    if (png_ptr == NULL)
   806    if (png_ptr == NULL)
   923       return;
   807       return;
   924    png_crc_finish(png_ptr, 0); /* Finish off CRC from last IDAT chunk */
   808    png_crc_finish(png_ptr, 0); /* Finish off CRC from last IDAT chunk */
   925 
   809 
   926    do
   810    do
   927    {
   811    {
   928 #ifdef PNG_USE_LOCAL_ARRAYS
   812       PNG_IHDR;
   929       PNG_CONST PNG_IHDR;
   813       PNG_IDAT;
   930       PNG_CONST PNG_IDAT;
   814       PNG_IEND;
   931       PNG_CONST PNG_IEND;
   815       PNG_PLTE;
   932       PNG_CONST PNG_PLTE;
   816 #ifdef PNG_READ_bKGD_SUPPORTED
   933 #if defined(PNG_READ_bKGD_SUPPORTED)
   817       PNG_bKGD;
   934       PNG_CONST PNG_bKGD;
   818 #endif
   935 #endif
   819 #ifdef PNG_READ_cHRM_SUPPORTED
   936 #if defined(PNG_READ_cHRM_SUPPORTED)
   820       PNG_cHRM;
   937       PNG_CONST PNG_cHRM;
   821 #endif
   938 #endif
   822 #ifdef PNG_READ_gAMA_SUPPORTED
   939 #if defined(PNG_READ_gAMA_SUPPORTED)
   823       PNG_gAMA;
   940       PNG_CONST PNG_gAMA;
   824 #endif
   941 #endif
   825 #ifdef PNG_READ_hIST_SUPPORTED
   942 #if defined(PNG_READ_hIST_SUPPORTED)
   826       PNG_hIST;
   943       PNG_CONST PNG_hIST;
   827 #endif
   944 #endif
   828 #ifdef PNG_READ_iCCP_SUPPORTED
   945 #if defined(PNG_READ_iCCP_SUPPORTED)
   829       PNG_iCCP;
   946       PNG_CONST PNG_iCCP;
   830 #endif
   947 #endif
   831 #ifdef PNG_READ_iTXt_SUPPORTED
   948 #if defined(PNG_READ_iTXt_SUPPORTED)
   832       PNG_iTXt;
   949       PNG_CONST PNG_iTXt;
   833 #endif
   950 #endif
   834 #ifdef PNG_READ_oFFs_SUPPORTED
   951 #if defined(PNG_READ_oFFs_SUPPORTED)
   835       PNG_oFFs;
   952       PNG_CONST PNG_oFFs;
   836 #endif
   953 #endif
   837 #ifdef PNG_READ_pCAL_SUPPORTED
   954 #if defined(PNG_READ_pCAL_SUPPORTED)
   838       PNG_pCAL;
   955       PNG_CONST PNG_pCAL;
   839 #endif
   956 #endif
   840 #ifdef PNG_READ_pHYs_SUPPORTED
   957 #if defined(PNG_READ_pHYs_SUPPORTED)
   841       PNG_pHYs;
   958       PNG_CONST PNG_pHYs;
   842 #endif
   959 #endif
   843 #ifdef PNG_READ_sBIT_SUPPORTED
   960 #if defined(PNG_READ_sBIT_SUPPORTED)
   844       PNG_sBIT;
   961       PNG_CONST PNG_sBIT;
   845 #endif
   962 #endif
   846 #ifdef PNG_READ_sCAL_SUPPORTED
   963 #if defined(PNG_READ_sCAL_SUPPORTED)
   847       PNG_sCAL;
   964       PNG_CONST PNG_sCAL;
   848 #endif
   965 #endif
   849 #ifdef PNG_READ_sPLT_SUPPORTED
   966 #if defined(PNG_READ_sPLT_SUPPORTED)
   850       PNG_sPLT;
   967       PNG_CONST PNG_sPLT;
   851 #endif
   968 #endif
   852 #ifdef PNG_READ_sRGB_SUPPORTED
   969 #if defined(PNG_READ_sRGB_SUPPORTED)
   853       PNG_sRGB;
   970       PNG_CONST PNG_sRGB;
   854 #endif
   971 #endif
   855 #ifdef PNG_READ_tEXt_SUPPORTED
   972 #if defined(PNG_READ_tEXt_SUPPORTED)
   856       PNG_tEXt;
   973       PNG_CONST PNG_tEXt;
   857 #endif
   974 #endif
   858 #ifdef PNG_READ_tIME_SUPPORTED
   975 #if defined(PNG_READ_tIME_SUPPORTED)
   859       PNG_tIME;
   976       PNG_CONST PNG_tIME;
   860 #endif
   977 #endif
   861 #ifdef PNG_READ_tRNS_SUPPORTED
   978 #if defined(PNG_READ_tRNS_SUPPORTED)
   862       PNG_tRNS;
   979       PNG_CONST PNG_tRNS;
   863 #endif
   980 #endif
   864 #ifdef PNG_READ_zTXt_SUPPORTED
   981 #if defined(PNG_READ_zTXt_SUPPORTED)
   865       PNG_zTXt;
   982       PNG_CONST PNG_zTXt;
   866 #endif
   983 #endif
       
   984 #endif /* PNG_USE_LOCAL_ARRAYS */
       
   985       png_uint_32 length = png_read_chunk_header(png_ptr);
   867       png_uint_32 length = png_read_chunk_header(png_ptr);
   986       PNG_CONST png_bytep chunk_name = png_ptr->chunk_name;
   868       PNG_CONST png_bytep chunk_name = png_ptr->chunk_name;
   987 
   869 
   988       if (!png_memcmp(chunk_name, png_IHDR, 4))
   870       if (!png_memcmp(chunk_name, png_IHDR, 4))
   989          png_handle_IHDR(png_ptr, info_ptr, length);
   871          png_handle_IHDR(png_ptr, info_ptr, length);
   993       else if (png_handle_as_unknown(png_ptr, chunk_name))
   875       else if (png_handle_as_unknown(png_ptr, chunk_name))
   994       {
   876       {
   995          if (!png_memcmp(chunk_name, png_IDAT, 4))
   877          if (!png_memcmp(chunk_name, png_IDAT, 4))
   996          {
   878          {
   997             if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
   879             if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
   998                png_error(png_ptr, "Too many IDAT's found");
   880                png_benign_error(png_ptr, "Too many IDATs found");
   999          }
   881          }
  1000          png_handle_unknown(png_ptr, info_ptr, length);
   882          png_handle_unknown(png_ptr, info_ptr, length);
  1001          if (!png_memcmp(chunk_name, png_PLTE, 4))
   883          if (!png_memcmp(chunk_name, png_PLTE, 4))
  1002             png_ptr->mode |= PNG_HAVE_PLTE;
   884             png_ptr->mode |= PNG_HAVE_PLTE;
  1003       }
   885       }
  1006       {
   888       {
  1007          /* Zero length IDATs are legal after the last IDAT has been
   889          /* Zero length IDATs are legal after the last IDAT has been
  1008           * read, but not after other chunks have been read.
   890           * read, but not after other chunks have been read.
  1009           */
   891           */
  1010          if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
   892          if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  1011             png_error(png_ptr, "Too many IDAT's found");
   893             png_benign_error(png_ptr, "Too many IDATs found");
  1012          png_crc_finish(png_ptr, length);
   894          png_crc_finish(png_ptr, length);
  1013       }
   895       }
  1014       else if (!png_memcmp(chunk_name, png_PLTE, 4))
   896       else if (!png_memcmp(chunk_name, png_PLTE, 4))
  1015          png_handle_PLTE(png_ptr, info_ptr, length);
   897          png_handle_PLTE(png_ptr, info_ptr, length);
  1016 #if defined(PNG_READ_bKGD_SUPPORTED)
   898 #ifdef PNG_READ_bKGD_SUPPORTED
  1017       else if (!png_memcmp(chunk_name, png_bKGD, 4))
   899       else if (!png_memcmp(chunk_name, png_bKGD, 4))
  1018          png_handle_bKGD(png_ptr, info_ptr, length);
   900          png_handle_bKGD(png_ptr, info_ptr, length);
  1019 #endif
   901 #endif
  1020 #if defined(PNG_READ_cHRM_SUPPORTED)
   902 #ifdef PNG_READ_cHRM_SUPPORTED
  1021       else if (!png_memcmp(chunk_name, png_cHRM, 4))
   903       else if (!png_memcmp(chunk_name, png_cHRM, 4))
  1022          png_handle_cHRM(png_ptr, info_ptr, length);
   904          png_handle_cHRM(png_ptr, info_ptr, length);
  1023 #endif
   905 #endif
  1024 #if defined(PNG_READ_gAMA_SUPPORTED)
   906 #ifdef PNG_READ_gAMA_SUPPORTED
  1025       else if (!png_memcmp(chunk_name, png_gAMA, 4))
   907       else if (!png_memcmp(chunk_name, png_gAMA, 4))
  1026          png_handle_gAMA(png_ptr, info_ptr, length);
   908          png_handle_gAMA(png_ptr, info_ptr, length);
  1027 #endif
   909 #endif
  1028 #if defined(PNG_READ_hIST_SUPPORTED)
   910 #ifdef PNG_READ_hIST_SUPPORTED
  1029       else if (!png_memcmp(chunk_name, png_hIST, 4))
   911       else if (!png_memcmp(chunk_name, png_hIST, 4))
  1030          png_handle_hIST(png_ptr, info_ptr, length);
   912          png_handle_hIST(png_ptr, info_ptr, length);
  1031 #endif
   913 #endif
  1032 #if defined(PNG_READ_oFFs_SUPPORTED)
   914 #ifdef PNG_READ_oFFs_SUPPORTED
  1033       else if (!png_memcmp(chunk_name, png_oFFs, 4))
   915       else if (!png_memcmp(chunk_name, png_oFFs, 4))
  1034          png_handle_oFFs(png_ptr, info_ptr, length);
   916          png_handle_oFFs(png_ptr, info_ptr, length);
  1035 #endif
   917 #endif
  1036 #if defined(PNG_READ_pCAL_SUPPORTED)
   918 #ifdef PNG_READ_pCAL_SUPPORTED
  1037       else if (!png_memcmp(chunk_name, png_pCAL, 4))
   919       else if (!png_memcmp(chunk_name, png_pCAL, 4))
  1038          png_handle_pCAL(png_ptr, info_ptr, length);
   920          png_handle_pCAL(png_ptr, info_ptr, length);
  1039 #endif
   921 #endif
  1040 #if defined(PNG_READ_sCAL_SUPPORTED)
   922 #ifdef PNG_READ_sCAL_SUPPORTED
  1041       else if (!png_memcmp(chunk_name, png_sCAL, 4))
   923       else if (!png_memcmp(chunk_name, png_sCAL, 4))
  1042          png_handle_sCAL(png_ptr, info_ptr, length);
   924          png_handle_sCAL(png_ptr, info_ptr, length);
  1043 #endif
   925 #endif
  1044 #if defined(PNG_READ_pHYs_SUPPORTED)
   926 #ifdef PNG_READ_pHYs_SUPPORTED
  1045       else if (!png_memcmp(chunk_name, png_pHYs, 4))
   927       else if (!png_memcmp(chunk_name, png_pHYs, 4))
  1046          png_handle_pHYs(png_ptr, info_ptr, length);
   928          png_handle_pHYs(png_ptr, info_ptr, length);
  1047 #endif
   929 #endif
  1048 #if defined(PNG_READ_sBIT_SUPPORTED)
   930 #ifdef PNG_READ_sBIT_SUPPORTED
  1049       else if (!png_memcmp(chunk_name, png_sBIT, 4))
   931       else if (!png_memcmp(chunk_name, png_sBIT, 4))
  1050          png_handle_sBIT(png_ptr, info_ptr, length);
   932          png_handle_sBIT(png_ptr, info_ptr, length);
  1051 #endif
   933 #endif
  1052 #if defined(PNG_READ_sRGB_SUPPORTED)
   934 #ifdef PNG_READ_sRGB_SUPPORTED
  1053       else if (!png_memcmp(chunk_name, png_sRGB, 4))
   935       else if (!png_memcmp(chunk_name, png_sRGB, 4))
  1054          png_handle_sRGB(png_ptr, info_ptr, length);
   936          png_handle_sRGB(png_ptr, info_ptr, length);
  1055 #endif
   937 #endif
  1056 #if defined(PNG_READ_iCCP_SUPPORTED)
   938 #ifdef PNG_READ_iCCP_SUPPORTED
  1057       else if (!png_memcmp(chunk_name, png_iCCP, 4))
   939       else if (!png_memcmp(chunk_name, png_iCCP, 4))
  1058          png_handle_iCCP(png_ptr, info_ptr, length);
   940          png_handle_iCCP(png_ptr, info_ptr, length);
  1059 #endif
   941 #endif
  1060 #if defined(PNG_READ_sPLT_SUPPORTED)
   942 #ifdef PNG_READ_sPLT_SUPPORTED
  1061       else if (!png_memcmp(chunk_name, png_sPLT, 4))
   943       else if (!png_memcmp(chunk_name, png_sPLT, 4))
  1062          png_handle_sPLT(png_ptr, info_ptr, length);
   944          png_handle_sPLT(png_ptr, info_ptr, length);
  1063 #endif
   945 #endif
  1064 #if defined(PNG_READ_tEXt_SUPPORTED)
   946 #ifdef PNG_READ_tEXt_SUPPORTED
  1065       else if (!png_memcmp(chunk_name, png_tEXt, 4))
   947       else if (!png_memcmp(chunk_name, png_tEXt, 4))
  1066          png_handle_tEXt(png_ptr, info_ptr, length);
   948          png_handle_tEXt(png_ptr, info_ptr, length);
  1067 #endif
   949 #endif
  1068 #if defined(PNG_READ_tIME_SUPPORTED)
   950 #ifdef PNG_READ_tIME_SUPPORTED
  1069       else if (!png_memcmp(chunk_name, png_tIME, 4))
   951       else if (!png_memcmp(chunk_name, png_tIME, 4))
  1070          png_handle_tIME(png_ptr, info_ptr, length);
   952          png_handle_tIME(png_ptr, info_ptr, length);
  1071 #endif
   953 #endif
  1072 #if defined(PNG_READ_tRNS_SUPPORTED)
   954 #ifdef PNG_READ_tRNS_SUPPORTED
  1073       else if (!png_memcmp(chunk_name, png_tRNS, 4))
   955       else if (!png_memcmp(chunk_name, png_tRNS, 4))
  1074          png_handle_tRNS(png_ptr, info_ptr, length);
   956          png_handle_tRNS(png_ptr, info_ptr, length);
  1075 #endif
   957 #endif
  1076 #if defined(PNG_READ_zTXt_SUPPORTED)
   958 #ifdef PNG_READ_zTXt_SUPPORTED
  1077       else if (!png_memcmp(chunk_name, png_zTXt, 4))
   959       else if (!png_memcmp(chunk_name, png_zTXt, 4))
  1078          png_handle_zTXt(png_ptr, info_ptr, length);
   960          png_handle_zTXt(png_ptr, info_ptr, length);
  1079 #endif
   961 #endif
  1080 #if defined(PNG_READ_iTXt_SUPPORTED)
   962 #ifdef PNG_READ_iTXt_SUPPORTED
  1081       else if (!png_memcmp(chunk_name, png_iTXt, 4))
   963       else if (!png_memcmp(chunk_name, png_iTXt, 4))
  1082          png_handle_iTXt(png_ptr, info_ptr, length);
   964          png_handle_iTXt(png_ptr, info_ptr, length);
  1083 #endif
   965 #endif
  1084       else
   966       else
  1085          png_handle_unknown(png_ptr, info_ptr, length);
   967          png_handle_unknown(png_ptr, info_ptr, length);
  1086    } while (!(png_ptr->mode & PNG_HAVE_IEND));
   968    } while (!(png_ptr->mode & PNG_HAVE_IEND));
  1087 }
   969 }
  1088 #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
   970 #endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
  1089 
   971 
  1090 /* Free all memory used by the read */
   972 /* Free all memory used by the read */
  1091 void PNGAPI
   973 void PNGAPI
  1092 png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
   974 png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
  1093    png_infopp end_info_ptr_ptr)
   975    png_infopp end_info_ptr_ptr)
  1098    png_free_ptr free_fn = NULL;
   980    png_free_ptr free_fn = NULL;
  1099    png_voidp mem_ptr = NULL;
   981    png_voidp mem_ptr = NULL;
  1100 #endif
   982 #endif
  1101 
   983 
  1102    png_debug(1, "in png_destroy_read_struct");
   984    png_debug(1, "in png_destroy_read_struct");
       
   985  
  1103    if (png_ptr_ptr != NULL)
   986    if (png_ptr_ptr != NULL)
  1104       png_ptr = *png_ptr_ptr;
   987       png_ptr = *png_ptr_ptr;
  1105    if (png_ptr == NULL)
   988    if (png_ptr == NULL)
  1106       return;
   989       return;
  1107 
   990 
  1118 
  1001 
  1119    png_read_destroy(png_ptr, info_ptr, end_info_ptr);
  1002    png_read_destroy(png_ptr, info_ptr, end_info_ptr);
  1120 
  1003 
  1121    if (info_ptr != NULL)
  1004    if (info_ptr != NULL)
  1122    {
  1005    {
  1123 #if defined(PNG_TEXT_SUPPORTED)
  1006 #ifdef PNG_TEXT_SUPPORTED
  1124       png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, -1);
  1007       png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, -1);
  1125 #endif
  1008 #endif
  1126 
  1009 
  1127 #ifdef PNG_USER_MEM_SUPPORTED
  1010 #ifdef PNG_USER_MEM_SUPPORTED
  1128       png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn,
  1011       png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn,
  1133       *info_ptr_ptr = NULL;
  1016       *info_ptr_ptr = NULL;
  1134    }
  1017    }
  1135 
  1018 
  1136    if (end_info_ptr != NULL)
  1019    if (end_info_ptr != NULL)
  1137    {
  1020    {
  1138 #if defined(PNG_READ_TEXT_SUPPORTED)
  1021 #ifdef PNG_READ_TEXT_SUPPORTED
  1139       png_free_data(png_ptr, end_info_ptr, PNG_FREE_TEXT, -1);
  1022       png_free_data(png_ptr, end_info_ptr, PNG_FREE_TEXT, -1);
  1140 #endif
  1023 #endif
  1141 #ifdef PNG_USER_MEM_SUPPORTED
  1024 #ifdef PNG_USER_MEM_SUPPORTED
  1142       png_destroy_struct_2((png_voidp)end_info_ptr, (png_free_ptr)free_fn,
  1025       png_destroy_struct_2((png_voidp)end_info_ptr, (png_free_ptr)free_fn,
  1143          (png_voidp)mem_ptr);
  1026          (png_voidp)mem_ptr);
  1172 #ifdef PNG_USER_MEM_SUPPORTED
  1055 #ifdef PNG_USER_MEM_SUPPORTED
  1173    png_free_ptr free_fn;
  1056    png_free_ptr free_fn;
  1174 #endif
  1057 #endif
  1175 
  1058 
  1176    png_debug(1, "in png_read_destroy");
  1059    png_debug(1, "in png_read_destroy");
       
  1060  
  1177    if (info_ptr != NULL)
  1061    if (info_ptr != NULL)
  1178       png_info_destroy(png_ptr, info_ptr);
  1062       png_info_destroy(png_ptr, info_ptr);
  1179 
  1063 
  1180    if (end_info_ptr != NULL)
  1064    if (end_info_ptr != NULL)
  1181       png_info_destroy(png_ptr, end_info_ptr);
  1065       png_info_destroy(png_ptr, end_info_ptr);
  1182 
  1066 
  1183    png_free(png_ptr, png_ptr->zbuf);
  1067    png_free(png_ptr, png_ptr->zbuf);
  1184    png_free(png_ptr, png_ptr->big_row_buf);
  1068    png_free(png_ptr, png_ptr->big_row_buf);
  1185    png_free(png_ptr, png_ptr->prev_row);
  1069    png_free(png_ptr, png_ptr->prev_row);
  1186    png_free(png_ptr, png_ptr->chunkdata);
  1070    png_free(png_ptr, png_ptr->chunkdata);
  1187 #if defined(PNG_READ_DITHER_SUPPORTED)
  1071 #ifdef PNG_READ_DITHER_SUPPORTED
  1188    png_free(png_ptr, png_ptr->palette_lookup);
  1072    png_free(png_ptr, png_ptr->palette_lookup);
  1189    png_free(png_ptr, png_ptr->dither_index);
  1073    png_free(png_ptr, png_ptr->dither_index);
  1190 #endif
  1074 #endif
  1191 #if defined(PNG_READ_GAMMA_SUPPORTED)
  1075 #ifdef PNG_READ_GAMMA_SUPPORTED
  1192    png_free(png_ptr, png_ptr->gamma_table);
  1076    png_free(png_ptr, png_ptr->gamma_table);
  1193 #endif
  1077 #endif
  1194 #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  1078 #ifdef PNG_READ_BACKGROUND_SUPPORTED
  1195    png_free(png_ptr, png_ptr->gamma_from_1);
  1079    png_free(png_ptr, png_ptr->gamma_from_1);
  1196    png_free(png_ptr, png_ptr->gamma_to_1);
  1080    png_free(png_ptr, png_ptr->gamma_to_1);
  1197 #endif
  1081 #endif
  1198 #ifdef PNG_FREE_ME_SUPPORTED
       
  1199    if (png_ptr->free_me & PNG_FREE_PLTE)
  1082    if (png_ptr->free_me & PNG_FREE_PLTE)
  1200       png_zfree(png_ptr, png_ptr->palette);
  1083       png_zfree(png_ptr, png_ptr->palette);
  1201    png_ptr->free_me &= ~PNG_FREE_PLTE;
  1084    png_ptr->free_me &= ~PNG_FREE_PLTE;
  1202 #else
       
  1203    if (png_ptr->flags & PNG_FLAG_FREE_PLTE)
       
  1204       png_zfree(png_ptr, png_ptr->palette);
       
  1205    png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;
       
  1206 #endif
       
  1207 #if defined(PNG_tRNS_SUPPORTED) || \
  1085 #if defined(PNG_tRNS_SUPPORTED) || \
  1208     defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  1086     defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  1209 #ifdef PNG_FREE_ME_SUPPORTED
       
  1210    if (png_ptr->free_me & PNG_FREE_TRNS)
  1087    if (png_ptr->free_me & PNG_FREE_TRNS)
  1211       png_free(png_ptr, png_ptr->trans);
  1088       png_free(png_ptr, png_ptr->trans_alpha);
  1212    png_ptr->free_me &= ~PNG_FREE_TRNS;
  1089    png_ptr->free_me &= ~PNG_FREE_TRNS;
  1213 #else
  1090 #endif
  1214    if (png_ptr->flags & PNG_FLAG_FREE_TRNS)
  1091 #ifdef PNG_READ_hIST_SUPPORTED
  1215       png_free(png_ptr, png_ptr->trans);
       
  1216    png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
       
  1217 #endif
       
  1218 #endif
       
  1219 #if defined(PNG_READ_hIST_SUPPORTED)
       
  1220 #ifdef PNG_FREE_ME_SUPPORTED
       
  1221    if (png_ptr->free_me & PNG_FREE_HIST)
  1092    if (png_ptr->free_me & PNG_FREE_HIST)
  1222       png_free(png_ptr, png_ptr->hist);
  1093       png_free(png_ptr, png_ptr->hist);
  1223    png_ptr->free_me &= ~PNG_FREE_HIST;
  1094    png_ptr->free_me &= ~PNG_FREE_HIST;
  1224 #else
  1095 #endif
  1225    if (png_ptr->flags & PNG_FLAG_FREE_HIST)
  1096 #ifdef PNG_READ_GAMMA_SUPPORTED
  1226       png_free(png_ptr, png_ptr->hist);
       
  1227    png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
       
  1228 #endif
       
  1229 #endif
       
  1230 #if defined(PNG_READ_GAMMA_SUPPORTED)
       
  1231    if (png_ptr->gamma_16_table != NULL)
  1097    if (png_ptr->gamma_16_table != NULL)
  1232    {
  1098    {
  1233       int i;
  1099       int i;
  1234       int istop = (1 << (8 - png_ptr->gamma_shift));
  1100       int istop = (1 << (8 - png_ptr->gamma_shift));
  1235       for (i = 0; i < istop; i++)
  1101       for (i = 0; i < istop; i++)
  1236       {
  1102       {
  1237          png_free(png_ptr, png_ptr->gamma_16_table[i]);
  1103          png_free(png_ptr, png_ptr->gamma_16_table[i]);
  1238       }
  1104       }
  1239    png_free(png_ptr, png_ptr->gamma_16_table);
  1105    png_free(png_ptr, png_ptr->gamma_16_table);
  1240    }
  1106    }
  1241 #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  1107 #ifdef PNG_READ_BACKGROUND_SUPPORTED
  1242    if (png_ptr->gamma_16_from_1 != NULL)
  1108    if (png_ptr->gamma_16_from_1 != NULL)
  1243    {
  1109    {
  1244       int i;
  1110       int i;
  1245       int istop = (1 << (8 - png_ptr->gamma_shift));
  1111       int istop = (1 << (8 - png_ptr->gamma_shift));
  1246       for (i = 0; i < istop; i++)
  1112       for (i = 0; i < istop; i++)
  1259       }
  1125       }
  1260    png_free(png_ptr, png_ptr->gamma_16_to_1);
  1126    png_free(png_ptr, png_ptr->gamma_16_to_1);
  1261    }
  1127    }
  1262 #endif
  1128 #endif
  1263 #endif
  1129 #endif
  1264 #if defined(PNG_TIME_RFC1123_SUPPORTED)
  1130 #ifdef PNG_TIME_RFC1123_SUPPORTED
  1265    png_free(png_ptr, png_ptr->time_buffer);
  1131    png_free(png_ptr, png_ptr->time_buffer);
  1266 #endif
  1132 #endif
  1267 
  1133 
  1268    inflateEnd(&png_ptr->zstream);
  1134    inflateEnd(&png_ptr->zstream);
  1269 #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  1135 #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  1312       return;
  1178       return;
  1313    png_ptr->read_row_fn = read_row_fn;
  1179    png_ptr->read_row_fn = read_row_fn;
  1314 }
  1180 }
  1315 
  1181 
  1316 
  1182 
  1317 #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  1183 #ifdef PNG_SEQUENTIAL_READ_SUPPORTED
  1318 #if defined(PNG_INFO_IMAGE_SUPPORTED)
  1184 #ifdef PNG_INFO_IMAGE_SUPPORTED
  1319 void PNGAPI
  1185 void PNGAPI
  1320 png_read_png(png_structp png_ptr, png_infop info_ptr,
  1186 png_read_png(png_structp png_ptr, png_infop info_ptr,
  1321                            int transforms,
  1187                            int transforms,
  1322                            voidp params)
  1188                            voidp params)
  1323 {
  1189 {
  1324    int row;
  1190    int row;
  1325 
  1191 
  1326    if (png_ptr == NULL)
  1192    if (png_ptr == NULL)
  1327       return;
  1193       return;
  1328 #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
       
  1329    /* Invert the alpha channel from opacity to transparency
       
  1330     */
       
  1331    if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
       
  1332        png_set_invert_alpha(png_ptr);
       
  1333 #endif
       
  1334 
  1194 
  1335    /* png_read_info() gives us all of the information from the
  1195    /* png_read_info() gives us all of the information from the
  1336     * PNG file before the first IDAT (image data chunk).
  1196     * PNG file before the first IDAT (image data chunk).
  1337     */
  1197     */
  1338    png_read_info(png_ptr, info_ptr);
  1198    png_read_info(png_ptr, info_ptr);
  1339    if (info_ptr->height > PNG_UINT_32_MAX/png_sizeof(png_bytep))
  1199    if (info_ptr->height > PNG_UINT_32_MAX/png_sizeof(png_bytep))
  1340       png_error(png_ptr, "Image is too high to process with png_read_png()");
  1200       png_error(png_ptr, "Image is too high to process with png_read_png()");
  1341 
  1201 
  1342    /* -------------- image transformations start here ------------------- */
  1202    /* -------------- image transformations start here ------------------- */
  1343 
  1203 
  1344 #if defined(PNG_READ_16_TO_8_SUPPORTED)
  1204 #ifdef PNG_READ_16_TO_8_SUPPORTED
  1345    /* Tell libpng to strip 16 bit/color files down to 8 bits per color.
  1205    /* Tell libpng to strip 16 bit/color files down to 8 bits per color.
  1346     */
  1206     */
  1347    if (transforms & PNG_TRANSFORM_STRIP_16)
  1207    if (transforms & PNG_TRANSFORM_STRIP_16)
  1348       png_set_strip_16(png_ptr);
  1208       png_set_strip_16(png_ptr);
  1349 #endif
  1209 #endif
  1350 
  1210 
  1351 #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  1211 #ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
  1352    /* Strip alpha bytes from the input data without combining with
  1212    /* Strip alpha bytes from the input data without combining with
  1353     * the background (not recommended).
  1213     * the background (not recommended).
  1354     */
  1214     */
  1355    if (transforms & PNG_TRANSFORM_STRIP_ALPHA)
  1215    if (transforms & PNG_TRANSFORM_STRIP_ALPHA)
  1356       png_set_strip_alpha(png_ptr);
  1216       png_set_strip_alpha(png_ptr);
  1362     */
  1222     */
  1363    if (transforms & PNG_TRANSFORM_PACKING)
  1223    if (transforms & PNG_TRANSFORM_PACKING)
  1364       png_set_packing(png_ptr);
  1224       png_set_packing(png_ptr);
  1365 #endif
  1225 #endif
  1366 
  1226 
  1367 #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  1227 #ifdef PNG_READ_PACKSWAP_SUPPORTED
  1368    /* Change the order of packed pixels to least significant bit first
  1228    /* Change the order of packed pixels to least significant bit first
  1369     * (not useful if you are using png_set_packing).
  1229     * (not useful if you are using png_set_packing).
  1370     */
  1230     */
  1371    if (transforms & PNG_TRANSFORM_PACKSWAP)
  1231    if (transforms & PNG_TRANSFORM_PACKSWAP)
  1372       png_set_packswap(png_ptr);
  1232       png_set_packswap(png_ptr);
  1373 #endif
  1233 #endif
  1374 
  1234 
  1375 #if defined(PNG_READ_EXPAND_SUPPORTED)
  1235 #ifdef PNG_READ_EXPAND_SUPPORTED
  1376    /* Expand paletted colors into true RGB triplets
  1236    /* Expand paletted colors into true RGB triplets
  1377     * Expand grayscale images to full 8 bits from 1, 2, or 4 bits/pixel
  1237     * Expand grayscale images to full 8 bits from 1, 2, or 4 bits/pixel
  1378     * Expand paletted or RGB images with transparency to full alpha
  1238     * Expand paletted or RGB images with transparency to full alpha
  1379     * channels so the data will be available as RGBA quartets.
  1239     * channels so the data will be available as RGBA quartets.
  1380     */
  1240     */
  1386 #endif
  1246 #endif
  1387 
  1247 
  1388    /* We don't handle background color or gamma transformation or dithering.
  1248    /* We don't handle background color or gamma transformation or dithering.
  1389     */
  1249     */
  1390 
  1250 
  1391 #if defined(PNG_READ_INVERT_SUPPORTED)
  1251 #ifdef PNG_READ_INVERT_SUPPORTED
  1392    /* Invert monochrome files to have 0 as white and 1 as black
  1252    /* Invert monochrome files to have 0 as white and 1 as black
  1393     */
  1253     */
  1394    if (transforms & PNG_TRANSFORM_INVERT_MONO)
  1254    if (transforms & PNG_TRANSFORM_INVERT_MONO)
  1395       png_set_invert_mono(png_ptr);
  1255       png_set_invert_mono(png_ptr);
  1396 #endif
  1256 #endif
  1397 
  1257 
  1398 #if defined(PNG_READ_SHIFT_SUPPORTED)
  1258 #ifdef PNG_READ_SHIFT_SUPPORTED
  1399    /* If you want to shift the pixel values from the range [0,255] or
  1259    /* If you want to shift the pixel values from the range [0,255] or
  1400     * [0,65535] to the original [0,7] or [0,31], or whatever range the
  1260     * [0,65535] to the original [0,7] or [0,31], or whatever range the
  1401     * colors were originally in:
  1261     * colors were originally in:
  1402     */
  1262     */
  1403    if ((transforms & PNG_TRANSFORM_SHIFT)
  1263    if ((transforms & PNG_TRANSFORM_SHIFT)
  1408       png_get_sBIT(png_ptr, info_ptr, &sig_bit);
  1268       png_get_sBIT(png_ptr, info_ptr, &sig_bit);
  1409       png_set_shift(png_ptr, sig_bit);
  1269       png_set_shift(png_ptr, sig_bit);
  1410    }
  1270    }
  1411 #endif
  1271 #endif
  1412 
  1272 
  1413 #if defined(PNG_READ_BGR_SUPPORTED)
  1273 #ifdef PNG_READ_BGR_SUPPORTED
  1414    /* Flip the RGB pixels to BGR (or RGBA to BGRA)
  1274    /* Flip the RGB pixels to BGR (or RGBA to BGRA)
  1415     */
  1275     */
  1416    if (transforms & PNG_TRANSFORM_BGR)
  1276    if (transforms & PNG_TRANSFORM_BGR)
  1417       png_set_bgr(png_ptr);
  1277       png_set_bgr(png_ptr);
  1418 #endif
  1278 #endif
  1419 
  1279 
  1420 #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  1280 #ifdef PNG_READ_SWAP_ALPHA_SUPPORTED
  1421    /* Swap the RGBA or GA data to ARGB or AG (or BGRA to ABGR)
  1281    /* Swap the RGBA or GA data to ARGB or AG (or BGRA to ABGR)
  1422     */
  1282     */
  1423    if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
  1283    if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
  1424        png_set_swap_alpha(png_ptr);
  1284        png_set_swap_alpha(png_ptr);
  1425 #endif
  1285 #endif
  1426 
  1286 
  1427 #if defined(PNG_READ_SWAP_SUPPORTED)
  1287 #ifdef PNG_READ_SWAP_SUPPORTED
  1428    /* Swap bytes of 16 bit files to least significant byte first
  1288    /* Swap bytes of 16 bit files to least significant byte first
  1429     */
  1289     */
  1430    if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
  1290    if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
  1431       png_set_swap(png_ptr);
  1291       png_set_swap(png_ptr);
       
  1292 #endif
       
  1293 
       
  1294 /* Added at libpng-1.2.41 */
       
  1295 #ifdef PNG_READ_INVERT_ALPHA_SUPPORTED
       
  1296    /* Invert the alpha channel from opacity to transparency
       
  1297     */
       
  1298    if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
       
  1299        png_set_invert_alpha(png_ptr);
       
  1300 #endif
       
  1301 
       
  1302 /* Added at libpng-1.2.41 */
       
  1303 #ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
       
  1304    /* Expand grayscale image to RGB
       
  1305     */
       
  1306    if (transforms & PNG_TRANSFORM_GRAY_TO_RGB)
       
  1307        png_set_gray_to_rgb(png_ptr);
  1432 #endif
  1308 #endif
  1433 
  1309 
  1434    /* We don't handle adding filler bytes */
  1310    /* We don't handle adding filler bytes */
  1435 
  1311 
  1436    /* Optional call to gamma correct and add the background to the palette
  1312    /* Optional call to gamma correct and add the background to the palette
  1439     */
  1315     */
  1440    png_read_update_info(png_ptr, info_ptr);
  1316    png_read_update_info(png_ptr, info_ptr);
  1441 
  1317 
  1442    /* -------------- image transformations end here ------------------- */
  1318    /* -------------- image transformations end here ------------------- */
  1443 
  1319 
  1444 #ifdef PNG_FREE_ME_SUPPORTED
       
  1445    png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
  1320    png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
  1446 #endif
       
  1447    if (info_ptr->row_pointers == NULL)
  1321    if (info_ptr->row_pointers == NULL)
  1448    {
  1322    {
       
  1323     png_uint_32 iptr;
       
  1324 
  1449       info_ptr->row_pointers = (png_bytepp)png_malloc(png_ptr,
  1325       info_ptr->row_pointers = (png_bytepp)png_malloc(png_ptr,
  1450          info_ptr->height * png_sizeof(png_bytep));
  1326          info_ptr->height * png_sizeof(png_bytep));
  1451       png_memset(info_ptr->row_pointers, 0, info_ptr->height
  1327       for (iptr=0; iptr<info_ptr->height; iptr++)
  1452          * png_sizeof(png_bytep));
  1328          info_ptr->row_pointers[iptr] = NULL;
  1453 #ifdef PNG_FREE_ME_SUPPORTED
  1329 
  1454       info_ptr->free_me |= PNG_FREE_ROWS;
  1330       info_ptr->free_me |= PNG_FREE_ROWS;
  1455 #endif
  1331 
  1456       for (row = 0; row < (int)info_ptr->height; row++)
  1332       for (row = 0; row < (int)info_ptr->height; row++)
  1457          info_ptr->row_pointers[row] = (png_bytep)png_malloc(png_ptr,
  1333          info_ptr->row_pointers[row] = (png_bytep)png_malloc(png_ptr,
  1458             png_get_rowbytes(png_ptr, info_ptr));
  1334             png_get_rowbytes(png_ptr, info_ptr));
  1459    }
  1335    }
  1460 
  1336 
  1467    transforms = transforms; /* Quiet compiler warnings */
  1343    transforms = transforms; /* Quiet compiler warnings */
  1468    params = params;
  1344    params = params;
  1469 
  1345 
  1470 }
  1346 }
  1471 #endif /* PNG_INFO_IMAGE_SUPPORTED */
  1347 #endif /* PNG_INFO_IMAGE_SUPPORTED */
  1472 #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  1348 #endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
  1473 #endif /* PNG_READ_SUPPORTED */
  1349 #endif /* PNG_READ_SUPPORTED */