png.c revision f9a51917495bc8ba8b60632219652a7b122c1190
/* png.c - location for general purpose libpng functions
*
* libpng version 1.2.8 - December 3, 2004
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2004 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*/
#define PNG_INTERNAL
#define PNG_NO_EXTERN
#include "png.h"
/* Generate a compiler error if there is an old png.h in the search path. */
/* Version information for C files. This had better match the version
* string defined in png.h. */
#ifdef PNG_USE_GLOBAL_ARRAYS
/* png_libpng_ver was changed to a function in version 1.0.5c */
/* png_sig was changed to a function in version 1.0.5c */
/* Place to hold the signature string for a PNG file. */
/* Invoke global declarations for constant strings for known chunk types */
/* arrays to facilitate easy interlacing - use pass (0 - 6) as index */
/* start of interlace block */
/* offset to next interlace block */
/* start of interlace block in the y direction */
/* offset to next interlace block in the y direction */
/* width of interlace block (used in assembler routines only) */
#endif
/* Height of interlace block. This is not currently used - if you need
* it, uncomment it here and in png.h
const int FARDATA png_pass_height[] = {8, 8, 4, 4, 2, 2, 1};
*/
/* Mask to determine which pixels are valid in a pass */
/* Mask to determine which pixels to overwrite while displaying */
const int FARDATA png_pass_dsp_mask[]
= {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
#endif /* PNG_USE_GLOBAL_ARRAYS */
/* Tells libpng that we have already handled the first "num_bytes" bytes
* of the PNG file signature. If the PNG data is embedded into another
* stream we can set num_bytes = 8 so that libpng will not attempt to read
* or write any of the magic bytes before it starts on the IHDR.
*/
void PNGAPI
{
if (num_bytes > 8)
}
/* Checks whether the supplied bytes match the PNG signature. We allow
* checking less than the full 8-byte signature so that those apps that
* already read the first few bytes of a file to determine the file type
* can simply check the remaining bytes for extra assurance. Returns
* an integer less than, equal to, or greater than zero if sig is found,
* respectively, to be less than, to match, or be greater than the correct
* PNG signature (this is the same behaviour as strcmp, memcmp, etc).
*/
int PNGAPI
{
if (num_to_check > 8)
num_to_check = 8;
else if (num_to_check < 1)
return (0);
if (start > 7)
return (0);
}
/* (Obsolete) function to check signature bytes. It does not allow one
* to check a partial signature. This function might be removed in the
* future - use png_sig_cmp(). Returns true (nonzero) if the file is a PNG.
*/
int PNGAPI
{
}
/* Function to allocate memory for zlib and clear it to 0. */
#ifdef PNG_1_0_X
#else
voidpf /* private */
#endif
{
{
return (NULL);
}
p->flags=save_flags;
#if defined(PNG_1_0_X) && !defined(PNG_NO_ZALLOC_ZERO)
{
}
else
{
}
#endif
}
/* function to free memory for zlib */
#ifdef PNG_1_0_X
void PNGAPI
#else
void /* private */
#endif
{
}
/* Reset the CRC variable to 32 bits of 1's. Care must be taken
* in case CRC is > 32 bits to leave the top bits 0.
*/
void /* PRIVATE */
{
}
/* Calculate the CRC over a section of data. We can only pass as
* much data to this routine as the largest single buffer size. We
* also check that this data will actually be used before going to the
* trouble of calculating it.
*/
void /* PRIVATE */
{
int need_crc = 1;
{
need_crc = 0;
}
else /* critical */
{
need_crc = 0;
}
if (need_crc)
}
/* Allocate the memory for an info_struct for the application. We don't
* really need the png_ptr, but it could potentially be useful in the
* future. This should be used in favour of malloc(png_sizeof(png_info))
* and png_info_init() so that applications that want to use a shared
* libpng don't have to be recompiled if png_info changes size.
*/
{
#ifdef PNG_USER_MEM_SUPPORTED
#else
#endif
return (info_ptr);
}
/* This function frees the memory associated with a single info struct.
* Normally, one would use either png_destroy_read_struct() or
* png_destroy_write_struct() to free an info struct, but this may be
* useful for some applications.
*/
void PNGAPI
{
if (info_ptr_ptr != NULL)
info_ptr = *info_ptr_ptr;
{
#ifdef PNG_USER_MEM_SUPPORTED
#else
#endif
*info_ptr_ptr = NULL;
}
}
/* Initialize the info structure. This is now an internal function (0.89)
* and applications using it are urged to use png_create_info_struct()
* instead.
*/
void PNGAPI
{
/* We only come here via pre-1.0.12-compiled applications */
png_info_init_3(&info_ptr, 0);
}
#endif
void PNGAPI
{
{
}
/* set everything to 0 */
}
#ifdef PNG_FREE_ME_SUPPORTED
void PNGAPI
{
return;
if(freer == PNG_DESTROY_WILL_FREE_DATA)
else if(freer == PNG_USER_WILL_FREE_DATA)
else
"Unknown freer parameter in png_data_freer.");
}
#endif
void PNGAPI
int num)
{
return;
#if defined(PNG_TEXT_SUPPORTED)
/* free text item num or (if num == -1) all text items */
#ifdef PNG_FREE_ME_SUPPORTED
#else
if (mask & PNG_FREE_TEXT)
#endif
{
if (num != -1)
{
{
}
}
else
{
int i;
}
}
#endif
#if defined(PNG_tRNS_SUPPORTED)
/* free any tRNS entry */
#ifdef PNG_FREE_ME_SUPPORTED
#else
#endif
{
#ifndef PNG_FREE_ME_SUPPORTED
#endif
}
#endif
#if defined(PNG_sCAL_SUPPORTED)
/* free any sCAL entry */
#ifdef PNG_FREE_ME_SUPPORTED
#else
if (mask & PNG_FREE_SCAL)
#endif
{
#if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
#endif
}
#endif
#if defined(PNG_pCAL_SUPPORTED)
/* free any pCAL entry */
#ifdef PNG_FREE_ME_SUPPORTED
#else
if (mask & PNG_FREE_PCAL)
#endif
{
{
int i;
for (i = 0; i < (int)info_ptr->pcal_nparams; i++)
{
}
}
}
#endif
#if defined(PNG_iCCP_SUPPORTED)
/* free any iCCP entry */
#ifdef PNG_FREE_ME_SUPPORTED
#else
if (mask & PNG_FREE_ICCP)
#endif
{
}
#endif
#if defined(PNG_sPLT_SUPPORTED)
/* free a given sPLT entry, or (if num == -1) all sPLT entries */
#ifdef PNG_FREE_ME_SUPPORTED
#else
if (mask & PNG_FREE_SPLT)
#endif
{
if (num != -1)
{
if(info_ptr->splt_palettes)
{
}
}
else
{
{
int i;
for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
info_ptr->splt_palettes_num = 0;
}
}
}
#endif
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
#ifdef PNG_FREE_ME_SUPPORTED
#else
if (mask & PNG_FREE_UNKN)
#endif
{
if (num != -1)
{
if(info_ptr->unknown_chunks)
{
}
}
else
{
int i;
{
for (i = 0; i < (int)info_ptr->unknown_chunks_num; i++)
info_ptr->unknown_chunks_num = 0;
}
}
}
#endif
#if defined(PNG_hIST_SUPPORTED)
/* free any hIST entry */
#ifdef PNG_FREE_ME_SUPPORTED
#else
#endif
{
#ifndef PNG_FREE_ME_SUPPORTED
#endif
}
#endif
/* free any PLTE entry that was internally allocated */
#ifdef PNG_FREE_ME_SUPPORTED
#else
#endif
{
#ifndef PNG_FREE_ME_SUPPORTED
#endif
info_ptr->num_palette = 0;
}
#if defined(PNG_INFO_IMAGE_SUPPORTED)
/* free any image bits attached to the info structure */
#ifdef PNG_FREE_ME_SUPPORTED
#else
if (mask & PNG_FREE_ROWS)
#endif
{
if(info_ptr->row_pointers)
{
int row;
{
}
}
}
#endif
#ifdef PNG_FREE_ME_SUPPORTED
if(num == -1)
else
#endif
}
/* This is an internal routine to free any memory that the info struct is
* pointing to before re-using it or freeing the struct itself. Recall
* that png_free() checks for NULL pointers for us.
*/
void /* PRIVATE */
{
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
if (png_ptr->num_chunk_list)
{
}
#endif
}
/* This function returns a pointer to the io_ptr associated with the user
* functions. The application should free any memory associated with this
* pointer before png_write_destroy() or png_read_destroy() are called.
*/
{
}
#if !defined(PNG_NO_STDIO)
* use your own read or write routines, you can call either png_set_read_fn()
* or png_set_write_fn() instead of png_init_io(). If you have defined
* PNG_NO_STDIO, you must use a function of your own because "FILE *" isn't
* necessarily available.
*/
void PNGAPI
{
}
#endif
#if defined(PNG_TIME_RFC1123_SUPPORTED)
/* Convert the supplied time into an RFC 1123 string suitable for use in
* a "Creation Time" or other text-based time string.
*/
{
{"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
{
png_sizeof(char)));
}
#if defined(_WIN32_WCE)
{
}
#else
#ifdef USE_FAR_KEYWORD
{
char near_time_buf[29];
29*png_sizeof(char));
}
#else
#endif
#endif /* _WIN32_WCE */
}
#endif /* PNG_TIME_RFC1123_SUPPORTED */
#if 0
/* Signature string for a PNG file. */
png_sig_bytes(void)
{
return ((png_bytep)"\211\120\116\107\015\012\032\012");
}
#endif
{
return ((png_charp) "\n libpng version 1.2.8 - December 3, 2004\n\
Copyright (c) 1998-2004 Glenn Randers-Pehrson\n\
Copyright (c) 1996-1997 Andreas Dilger\n\
Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.\n");
return ((png_charp) "");
}
/* The following return the library version as a short string in the
* format 1.0.0 through 99.99.99zz. To get the version of *.h files
* used with your application, print out PNG_LIBPNG_VER_STRING, which
* is defined in png.h.
* Note: now there is no difference between png_get_libpng_ver() and
* png_get_header_ver(). Due to the version_nn_nn_nn typedef guard,
*/
{
/* Version of *.c files used when building libpng */
return ((png_charp) PNG_LIBPNG_VER_STRING);
return ((png_charp) "");
}
{
/* Version of *.h files used when building libpng */
return ((png_charp) PNG_LIBPNG_VER_STRING);
return ((png_charp) "");
}
{
/* Returns longer string containing both version and date */
return ((png_charp) PNG_HEADER_VERSION_STRING);
return ((png_charp) "");
}
int PNGAPI
{
/* check chunk_name and return "keep" value if it's on the list, else 0 */
int i;
png_bytep p;
return 0;
return ((int)*(p+4));
return 0;
}
#endif
/* This function, added to libpng-1.0.6g, is untested. */
int PNGAPI
{
}
/* This function was added to libpng-1.0.7 */
{
/* Version of *.c files used when building libpng */
return((png_uint_32) PNG_LIBPNG_VER);
}
#if !defined(PNG_1_0_X)
#if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
/* GRR: could add this: && defined(PNG_MMX_CODE_SUPPORTED) */
/* this INTERNAL function was added to libpng 1.2.0 */
void /* PRIVATE */
{
# if (defined(PNG_USE_PNGVCRD) || defined(PNG_USE_PNGGCCRD))
if (png_mmx_support() > 0) {
# ifdef PNG_HAVE_ASSEMBLER_COMBINE_ROW
# endif
# endif
# ifndef PNG_HAVE_ASSEMBLER_READ_FILTER_ROW
;
# else
# endif
} else {
| PNG_MMX_WRITE_FLAGS );
}
# else /* !((PNGVCRD || PNGGCCRD) && PNG_ASSEMBLER_CODE_SUPPORTED)) */
/* clear all MMX flags; no support is compiled in */
# endif /* ?(PNGVCRD || PNGGCCRD) */
}
#endif /* !(PNG_ASSEMBLER_CODE_SUPPORTED) */
/* this function was added to libpng 1.2.0 */
#if !defined(PNG_USE_PNGGCCRD) && \
!(defined(PNG_ASSEMBLER_CODE_SUPPORTED) && defined(PNG_USE_PNGVCRD))
int PNGAPI
png_mmx_support(void)
{
return -1;
}
#endif
#endif /* PNG_1_0_X */
#ifdef PNG_SIZE_T
/* Added at libpng version 1.2.6 */
{
PNG_ABORT(); /* We haven't got access to png_ptr, so no png_error() */
return ((png_size_t)size);
}
#endif /* PNG_SIZE_T */