Imported from libpng-1.4.0beta54.tar

This commit is contained in:
Glenn Randers-Pehrson
2009-04-13 11:41:33 -05:00
parent a6cc627446
commit a93c942070
66 changed files with 276 additions and 365 deletions

165
pngread.c
View File

@@ -1,7 +1,7 @@
/* pngread.c - read a PNG file
*
* Last changed in libpng 1.4.0 [April 1, 2009]
* Last changed in libpng 1.4.0 [April 13, 2009]
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2009 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@@ -15,6 +15,26 @@
#if defined(PNG_READ_SUPPORTED)
#include "pngpriv.h"
/* Clean up PNG structure and deallocate any memory. */
#ifdef PNG_USER_MEM_SUPPORTED
void /* PRIVATE */
png_cleanup_read_struct(png_structp png_ptr,
png_free_ptr free_fn, png_voidp mem_ptr)
#else
void /* PRIVATE */
png_cleanup_read_struct(png_structp png_ptr)
#endif
{
png_free(png_ptr, png_ptr->zbuf);
png_ptr->zbuf = NULL;
#ifdef PNG_USER_MEM_SUPPORTED
png_destroy_struct_2((png_voidp)png_ptr,
(png_free_ptr)free_fn, (png_voidp)mem_ptr);
#else
png_destroy_struct((png_voidp)png_ptr);
#endif
}
/* Create a PNG structure for reading, and allocate any memory needed. */
png_structp PNGAPI
png_create_read_struct(png_const_charp user_png_ver, png_voidp error_ptr,
@@ -34,6 +54,7 @@ png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
{
#endif /* PNG_USER_MEM_SUPPORTED */
int png_cleanup_needed = 0;
#ifdef PNG_SETJMP_SUPPORTED
volatile
#endif
@@ -63,28 +84,6 @@ png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
#endif
#ifdef PNG_SETJMP_SUPPORTED
#ifdef USE_FAR_KEYWORD
if (setjmp(jmpbuf))
#else
if (setjmp(png_ptr->jmpbuf))
#endif
{
png_free(png_ptr, png_ptr->zbuf);
png_ptr->zbuf = NULL;
#ifdef PNG_USER_MEM_SUPPORTED
png_destroy_struct_2((png_voidp)png_ptr,
(png_free_ptr)free_fn, (png_voidp)mem_ptr);
#else
png_destroy_struct((png_voidp)png_ptr);
#endif
return (NULL);
}
#ifdef USE_FAR_KEYWORD
png_memcpy(png_ptr->jmpbuf, jmpbuf, png_sizeof(jmp_buf));
#endif
#endif
#ifdef PNG_USER_MEM_SUPPORTED
png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
#endif
@@ -132,26 +131,56 @@ png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
png_ptr->flags = 0;
#endif
png_error(png_ptr,
png_warning(png_ptr,
"Incompatible libpng version in application and library");
png_cleanup_needed = 1;
}
}
if (!png_cleanup_needed)
{
/* initialize zbuf - compression buffer */
png_ptr->zbuf_size = PNG_ZBUF_SIZE;
png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
png_ptr->zbuf = (png_bytep)png_malloc_warn(png_ptr,
png_ptr->zbuf_size);
if (png_ptr->zbuf == NULL)
{
#ifdef PNG_USER_MEM_SUPPORTED
png_cleanup_read_struct(png_ptr, free_fn, mem_ptr);
#else
png_cleanup_read_struct(png_ptr);
#endif
return NULL;
}
}
png_ptr->zstream.zalloc = png_zalloc;
png_ptr->zstream.zfree = png_zfree;
png_ptr->zstream.opaque = (voidpf)png_ptr;
if (!png_cleanup_needed)
{
switch (inflateInit(&png_ptr->zstream))
{
case Z_OK: /* Do nothing */ break;
case Z_MEM_ERROR:
case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory error"); break;
case Z_VERSION_ERROR: png_error(png_ptr, "zlib version error"); break;
default: png_error(png_ptr, "Unknown zlib error");
case Z_STREAM_ERROR: png_warning(png_ptr, "zlib memory error");
png_cleanup_needed = 1;
case Z_VERSION_ERROR: png_warning(png_ptr, "zlib version error");
png_cleanup_needed = 1;
default: png_warning(png_ptr, "Unknown zlib error");
png_cleanup_needed = 1;
}
}
if (png_cleanup_needed)
{
#ifdef PNG_USER_MEM_SUPPORTED
png_cleanup_read_struct(png_ptr, free_fn, mem_ptr);
#else
png_cleanup_read_struct(png_ptr);
#endif
return (NULL);
}
png_ptr->zstream.next_out = png_ptr->zbuf;
@@ -176,86 +205,6 @@ png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
}
void PNGAPI
png_read_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
png_size_t png_struct_size)
{
#ifdef PNG_SETJMP_SUPPORTED
jmp_buf tmp_jmp; /* to save current jump buffer */
#endif
int i = 0;
png_structp png_ptr=*ptr_ptr;
if (png_ptr == NULL) return;
do
{
if (user_png_ver[i] != png_libpng_ver[i])
{
#ifdef PNG_LEGACY_SUPPORTED
png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
#else
png_ptr->warning_fn = NULL;
png_warning(png_ptr,
"Application uses deprecated png_read_init() and should be recompiled");
break;
#endif
}
} while (png_libpng_ver[i++]);
png_debug(1, "in png_read_init_3");
#ifdef PNG_SETJMP_SUPPORTED
/* save jump buffer and error functions */
png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof(jmp_buf));
#endif
if (png_sizeof(png_struct) > png_struct_size)
{
png_destroy_struct(png_ptr);
*ptr_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
png_ptr = *ptr_ptr;
}
/* reset all variables to 0 */
png_memset(png_ptr, 0, png_sizeof(png_struct));
#ifdef PNG_SETJMP_SUPPORTED
/* restore jump buffer */
png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof(jmp_buf));
#endif
/* added at libpng-1.2.6 */
#ifdef PNG_SET_USER_LIMITS_SUPPORTED
png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
#endif
/* initialize zbuf - compression buffer */
png_ptr->zbuf_size = PNG_ZBUF_SIZE;
png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
png_ptr->zbuf_size);
png_ptr->zstream.zalloc = png_zalloc;
png_ptr->zstream.zfree = png_zfree;
png_ptr->zstream.opaque = (voidpf)png_ptr;
switch (inflateInit(&png_ptr->zstream))
{
case Z_OK: /* Do nothing */ break;
case Z_MEM_ERROR:
case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory"); break;
case Z_VERSION_ERROR: png_error(png_ptr, "zlib version"); break;
default: png_error(png_ptr, "Unknown zlib error");
}
png_ptr->zstream.next_out = png_ptr->zbuf;
png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
png_set_read_fn(png_ptr, NULL, NULL);
}
#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
/* Read the information before the actual image data. This has been
* changed in v0.90 to allow reading a file that already has the magic