Imported from libpng-1.2.0beta3.tar

This commit is contained in:
Glenn Randers-Pehrson
2001-05-18 04:54:50 -05:00
parent 3097f618f2
commit 8b6a889881
55 changed files with 495 additions and 296 deletions

View File

@@ -1,7 +1,7 @@
/* pngmem.c - stub functions for memory allocation
*
* libpng 1.2.0beta2 - May 7, 2001
* libpng 1.2.0beta3 - May 18, 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)
@@ -27,12 +27,12 @@ png_voidp /* PRIVATE */
png_create_struct(int type)
{
#ifdef PNG_USER_MEM_SUPPORTED
return (png_create_struct_2(type, NULL));
return (png_create_struct_2(type, NULL, NULL));
}
/* Alternate version of png_create_struct, for use with user-defined malloc. */
png_voidp /* PRIVATE */
png_create_struct_2(int type, png_malloc_ptr malloc_fn)
png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
{
#endif /* PNG_USER_MEM_SUPPORTED */
png_size_t size;
@@ -48,9 +48,18 @@ png_create_struct_2(int type, png_malloc_ptr malloc_fn)
#ifdef PNG_USER_MEM_SUPPORTED
if(malloc_fn != NULL)
{
if ((struct_ptr = (*(malloc_fn))(NULL, size)) != NULL)
if (mem_ptr != NULL)
{
png_struct dummy_struct;
png_structp png_ptr = &dummy_struct;
png_ptr->mem_ptr=mem_ptr;
struct_ptr = (*(malloc_fn))(png_ptr, size);
}
else
struct_ptr = (*(malloc_fn))(NULL, size);
if (struct_ptr != NULL)
png_memset(struct_ptr, 0, size);
return (struct_ptr);
return (struct_ptr);
}
#endif /* PNG_USER_MEM_SUPPORTED */
if ((struct_ptr = (png_voidp)farmalloc(size)) != NULL)
@@ -66,12 +75,13 @@ void /* PRIVATE */
png_destroy_struct(png_voidp struct_ptr)
{
#ifdef PNG_USER_MEM_SUPPORTED
png_destroy_struct_2(struct_ptr, (png_free_ptr)NULL);
png_destroy_struct_2(struct_ptr, (png_free_ptr)NULL, (png_voidp)NULL);
}
/* Free memory allocated by a png_create_struct() call */
void /* PRIVATE */
png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn)
png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
png_voidp mem_ptr)
{
#endif
if (struct_ptr != NULL)
@@ -81,6 +91,7 @@ png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn)
{
png_struct dummy_struct;
png_structp png_ptr = &dummy_struct;
png_ptr->mem_ptr=mem_ptr;
(*(free_fn))(png_ptr, struct_ptr);
return;
}
@@ -286,14 +297,14 @@ png_voidp /* PRIVATE */
png_create_struct(int type)
{
#ifdef PNG_USER_MEM_SUPPORTED
return (png_create_struct_2(type, NULL));
return (png_create_struct_2(type, NULL, NULL));
}
/* Allocate memory for a png_struct or a png_info. The malloc and
memset can be replaced by a single call to calloc() if this is thought
to improve performance noticably.*/
png_voidp /* PRIVATE */
png_create_struct_2(int type, png_malloc_ptr malloc_fn)
png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
{
#endif /* PNG_USER_MEM_SUPPORTED */
png_size_t size;
@@ -309,7 +320,16 @@ png_create_struct_2(int type, png_malloc_ptr malloc_fn)
#ifdef PNG_USER_MEM_SUPPORTED
if(malloc_fn != NULL)
{
if ((struct_ptr = (*(malloc_fn))(NULL, size)) != NULL)
if (mem_ptr != NULL)
{
png_struct dummy_struct;
png_structp png_ptr = &dummy_struct;
png_ptr->mem_ptr=mem_ptr;
struct_ptr = (*(malloc_fn))(png_ptr, size);
}
else
struct_ptr = (*(malloc_fn))(NULL, size);
if (struct_ptr != NULL)
png_memset(struct_ptr, 0, size);
return (struct_ptr);
}
@@ -337,12 +357,13 @@ void /* PRIVATE */
png_destroy_struct(png_voidp struct_ptr)
{
#ifdef PNG_USER_MEM_SUPPORTED
png_destroy_struct_2(struct_ptr, (png_free_ptr)NULL);
png_destroy_struct_2(struct_ptr, (png_free_ptr)NULL, (png_voidp)NULL);
}
/* Free memory allocated by a png_create_struct() call */
void /* PRIVATE */
png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn)
png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
png_voidp mem_ptr)
{
#endif /* PNG_USER_MEM_SUPPORTED */
if (struct_ptr != NULL)
@@ -352,6 +373,7 @@ png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn)
{
png_struct dummy_struct;
png_structp png_ptr = &dummy_struct;
png_ptr->mem_ptr=mem_ptr;
(*(free_fn))(png_ptr, struct_ptr);
return;
}