Imported from libpng-1.2.0beta1.tar

This commit is contained in:
Glenn Randers-Pehrson
2001-05-06 05:34:26 -05:00
parent e68f5a361b
commit 1fd5fb33c2
56 changed files with 1093 additions and 826 deletions

104
pngread.c
View File

@@ -1,7 +1,7 @@
/* pngread.c - read a PNG file
*
* libpng 1.0.12beta1 - May 14, 2001
* libpng 1.2.0beta1 - May 6, 2001
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2001 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@@ -46,7 +46,7 @@ png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
png_debug(1, "in png_create_read_struct\n");
#ifdef PNG_USER_MEM_SUPPORTED
if ((png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
(png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr)) == NULL)
(png_malloc_ptr)malloc_fn)) == NULL)
#else
if ((png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG)) == NULL)
#endif
@@ -54,6 +54,10 @@ png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
return (png_structp)NULL;
}
#ifdef PNG_ASSEMBLER_CODE_SUPPORTED
png_init_mmx_flags(png_ptr); /* 1.2.0 addition */
#endif
#ifdef PNG_SETJMP_SUPPORTED
#ifdef USE_FAR_KEYWORD
if (setjmp(jmpbuf))
@@ -92,7 +96,6 @@ png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
* only check the first digit.
*/
if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
(user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
(user_png_ver[0] == '0' && user_png_ver[2] < '9'))
{
png_error(png_ptr,
@@ -100,17 +103,15 @@ png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
}
/* Libpng 1.0.6 was not binary compatible, due to insertion of the
info_ptr->free_me member. Libpng-1.0.1 and earlier were not
compatible due to insertion of the user transform function. Note
to maintainer: this test can be removed from version 1.2.0 and
beyond because the previous test would have already rejected it. */
info_ptr->free_me member. Note to maintainer: this test can be
removed from version 2.0.0 and beyond because the previous test
would have already rejected it. */
if (user_png_ver[0] == '1' && user_png_ver[2] == '0' &&
(user_png_ver[4] < '2' || user_png_ver[4] == '6') &&
user_png_ver[5] == '\0')
if (user_png_ver[4] == '6' && user_png_ver[2] == '0' &&
user_png_ver[0] == '1' && user_png_ver[5] == '\0')
{
png_error(png_ptr,
"Application must be recompiled; versions <= 1.0.6 were incompatible");
"Application must be recompiled; version 1.0.6 was incompatible");
}
}
@@ -147,42 +148,18 @@ void PNGAPI
png_read_init(png_structp png_ptr)
{
/* We only come here via pre-1.0.7-compiled applications */
png_read_init_2(png_ptr, "1.0.0", 0, 0);
png_read_init_2(png_ptr, "1.0.0", 10000, 10000);
}
#undef png_read_init_2
void PNGAPI
png_read_init_2(png_structp png_ptr, png_const_charp user_png_ver,
png_size_t png_struct_size, png_size_t png_info_size)
{
/* We only come here via pre-1.0.12-compiled applications */
if(sizeof(png_struct) > png_struct_size)
{
png_ptr->error_fn=(png_error_ptr)NULL;
png_error(png_ptr,
"The png struct allocated by the application for reading is too small.");
}
if(sizeof(png_info) > png_info_size)
{
png_ptr->error_fn=(png_error_ptr)NULL;
png_error(png_ptr,
"The info struct allocated by application for reading is too small.");
}
png_read_init_3(&png_ptr, user_png_ver, png_struct_size);
}
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;
do
{
if(user_png_ver[i] != png_libpng_ver[i])
@@ -190,31 +167,35 @@ png_read_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
#ifdef PNG_LEGACY_SUPPORTED
png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
#else
png_ptr->warning_fn=(png_error_ptr)NULL;
png_warning(png_ptr,
"Application uses deprecated png_read_init() and should be recompiled.");
break;
png_ptr->error_fn=(png_error_ptr)NULL;
png_error(png_ptr,
"Application uses deprecated png_read_init() and must be recompiled.");
#endif
}
} while (png_libpng_ver[i++]);
png_debug(1, "in png_read_init_3\n");
if(sizeof(png_struct) > png_struct_size ||
sizeof(png_info) > png_info_size)
{
png_ptr->error_fn=(png_error_ptr)NULL;
png_error(png_ptr,
"Application and library have different sized structs. Please recompile.");
}
png_debug(1, "in png_read_init_2\n");
#ifdef PNG_SETJMP_SUPPORTED
/* save jump buffer and error functions */
png_memcpy(tmp_jmp, png_ptr->jmpbuf, sizeof (jmp_buf));
#endif
if(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, sizeof (png_struct));
#ifdef PNG_ASSEMBLER_CODE_SUPPORTED
png_init_mmx_flags(png_ptr); /* 1.2.0 addition */
#endif
#ifdef PNG_SETJMP_SUPPORTED
/* restore jump buffer */
png_memcpy(png_ptr->jmpbuf, tmp_jmp, sizeof (jmp_buf));
@@ -742,7 +723,7 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
* not called png_set_interlace_handling(), the display_row buffer will
* be ignored, so pass NULL to it.
*
* [*] png_handle_alpha() does not exist yet, as of libpng version 1.0.12beta1
* [*] png_handle_alpha() does not exist yet, as of libpng version 1.2.0beta1
*/
void PNGAPI
@@ -791,7 +772,7 @@ png_read_rows(png_structp png_ptr, png_bytepp row,
* only call this function once. If you desire to have an image for
* each pass of a interlaced image, use png_read_rows() instead.
*
* [*] png_handle_alpha() does not exist yet, as of libpng version 1.0.12beta1
* [*] png_handle_alpha() does not exist yet, as of libpng version 1.2.0beta1
*/
void PNGAPI
png_read_image(png_structp png_ptr, png_bytepp image)
@@ -1021,7 +1002,6 @@ png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
png_infop info_ptr = NULL, end_info_ptr = NULL;
#ifdef PNG_USER_MEM_SUPPORTED
png_free_ptr free_fn = NULL;
png_voidp mem_ptr = NULL;
#endif
png_debug(1, "in png_destroy_read_struct\n");
@@ -1037,7 +1017,6 @@ png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
#ifdef PNG_USER_MEM_SUPPORTED
free_fn = png_ptr->free_fn;
mem_ptr = png_ptr->mem_ptr;
#endif
png_read_destroy(png_ptr, info_ptr, end_info_ptr);
@@ -1049,8 +1028,7 @@ png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
#endif
#ifdef PNG_USER_MEM_SUPPORTED
png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn,
(png_voidp)mem_ptr);
png_destroy_struct_2((png_voidp)info_ptr, free_fn);
#else
png_destroy_struct((png_voidp)info_ptr);
#endif
@@ -1063,8 +1041,7 @@ png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
png_free_data(png_ptr, end_info_ptr, PNG_FREE_TEXT, -1);
#endif
#ifdef PNG_USER_MEM_SUPPORTED
png_destroy_struct_2((png_voidp)end_info_ptr, (png_free_ptr)free_fn,
(png_voidp)mem_ptr);
png_destroy_struct_2((png_voidp)end_info_ptr, free_fn);
#else
png_destroy_struct((png_voidp)end_info_ptr);
#endif
@@ -1074,8 +1051,7 @@ png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
if (png_ptr != NULL)
{
#ifdef PNG_USER_MEM_SUPPORTED
png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn,
(png_voidp)mem_ptr);
png_destroy_struct_2((png_voidp)png_ptr, free_fn);
#else
png_destroy_struct((png_voidp)png_ptr);
#endif
@@ -1084,7 +1060,7 @@ png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
}
/* free all memory used by the read (old method) */
void /* PRIVATE */
void PNGAPI
png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr)
{
#ifdef PNG_SETJMP_SUPPORTED
@@ -1337,7 +1313,7 @@ png_read_png(png_structp png_ptr, png_infop info_ptr,
/* Optional call to gamma correct and add the background to the palette
* and update info structure. REQUIRED if you are expecting libpng to
* update the palette for you (i.e., you selected such a transform above).
* update the palette for you (ie you selected such a transform above).
*/
png_read_update_info(png_ptr, info_ptr);
@@ -1349,15 +1325,13 @@ png_read_png(png_structp png_ptr, png_infop info_ptr,
if(info_ptr->row_pointers == NULL)
{
info_ptr->row_pointers = (png_bytepp)png_malloc(png_ptr,
info_ptr->height * sizeof(png_bytep));
info_ptr->height * sizeof(png_bytep));
#ifdef PNG_FREE_ME_SUPPORTED
info_ptr->free_me |= PNG_FREE_ROWS;
#endif
for (row = 0; row < (int)info_ptr->height; row++)
{
info_ptr->row_pointers[row] = (png_bytep)png_malloc(png_ptr,
info_ptr->row_pointers[row] = png_malloc(png_ptr,
png_get_rowbytes(png_ptr, info_ptr));
}
}
png_read_image(png_ptr, info_ptr->row_pointers);
@@ -1366,7 +1340,7 @@ png_read_png(png_structp png_ptr, png_infop info_ptr,
/* read rest of file, and get additional chunks in info_ptr - REQUIRED */
png_read_end(png_ptr, info_ptr);
if(transforms == 0 || params == NULL)
if(transforms == 0 || params == (voidp)NULL)
/* quiet compiler warnings */ return;
}