/* png.c - location for general purpose libpng functions
*
- * libpng version 1.2.4 - July 8, 2002
- * Copyright (c) 1998-2002 Glenn Randers-Pehrson
+ * libpng version 1.2.7 - September 12, 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
#include "png.h"
/* Generate a compiler error if there is an old png.h in the search path. */
-typedef version_1_2_4 Your_png_h_is_not_version_1_2_4;
+typedef version_1_2_7 Your_png_h_is_not_version_1_2_7;
/* 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 */
-const char png_libpng_ver[18] = "1.2.4";
+const char png_libpng_ver[18] = PNG_LIBPNG_VER_STRING;
/* png_sig was changed to a function in version 1.0.5c */
/* Place to hold the signature string for a PNG file. */
#endif
-#ifdef __VISAGECPP__
-const char png_libpng_ver[18] = "1.2.4";
-#endif
-
/* 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
/* Function to allocate memory for zlib and clear it to 0. */
#ifdef PNG_1_0_X
-void PNGAPI
+voidpf PNGAPI
#else
voidpf /* private */
#endif
png_zalloc(voidpf png_ptr, uInt items, uInt size)
{
- png_uint_32 num_bytes = (png_uint_32)items * size;
png_voidp ptr;
- png_structp p=(png_structp)png_ptr;
+ png_structp p=(png_struct*)png_ptr;
png_uint_32 save_flags=p->flags;
+ png_uint_32 num_bytes;
+
+ if (items > PNG_UINT_32_MAX/size)
+ {
+ png_warning (png_ptr, "Potential overflow in png_zalloc()");
+ return (NULL);
+ }
+ num_bytes = (png_uint_32)items * size;
p->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
ptr = (png_voidp)png_malloc((png_structp)png_ptr, num_bytes);
p->flags=save_flags;
-#ifndef PNG_NO_ZALLOC_ZERO
+#if defined(PNG_1_0_X) && !defined(PNG_NO_ZALLOC_ZERO)
if (ptr == NULL)
return ((voidpf)ptr);
/* 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(sizeof(png_info))
+ * 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.
*/
info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
#endif
if (info_ptr != NULL)
- png_info_init_3(&info_ptr, sizeof(png_info));
+ png_info_init_3(&info_ptr, png_sizeof(png_info));
return (info_ptr);
}
png_debug(1, "in png_info_init_3\n");
- if(sizeof(png_info) > png_info_struct_size)
+ if(png_sizeof(png_info) > png_info_struct_size)
{
png_destroy_struct(info_ptr);
info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
}
/* set everything to 0 */
- png_memset(info_ptr, 0, sizeof (png_info));
+ png_memset(info_ptr, 0, png_sizeof (png_info));
}
#ifdef PNG_FREE_ME_SUPPORTED
}
#endif
- png_info_init_3(&info_ptr, sizeof(png_info));
+ png_info_init_3(&info_ptr, png_sizeof(png_info));
}
/* This function returns a pointer to the io_ptr associated with the user
if (png_ptr->time_buffer == NULL)
{
png_ptr->time_buffer = (png_charp)png_malloc(png_ptr, (png_uint_32)(29*
- sizeof(char)));
+ png_sizeof(char)));
}
#if defined(_WIN32_WCE)
ptime->year, ptime->hour % 24, ptime->minute % 60,
ptime->second % 61);
png_memcpy(png_ptr->time_buffer, near_time_buf,
- 29*sizeof(char));
+ 29*png_sizeof(char));
}
#else
sprintf(png_ptr->time_buffer, "%d %s %d %02d:%02d:%02d +0000",
png_charp PNGAPI
png_get_copyright(png_structp png_ptr)
{
- if (png_ptr != NULL || png_ptr == NULL) /* silence compiler warning */
- return ((png_charp) "\n libpng version 1.2.4 - July 8, 2002\n\
- Copyright (c) 1998-2002 Glenn Randers-Pehrson\n\
+ if (&png_ptr != NULL) /* silence compiler warning about unused png_ptr */
+ return ((png_charp) "\n libpng version 1.2.7 - September 12, 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.
+ * 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,
+ * it is guaranteed that png.c uses the correct version of png.h.
*/
-
png_charp PNGAPI
png_get_libpng_ver(png_structp png_ptr)
{
/* Version of *.c files used when building libpng */
- if(png_ptr != NULL) /* silence compiler warning about unused png_ptr */
- return((png_charp) "1.2.4");
- return((png_charp) "1.2.4");
+ if (&png_ptr != NULL) /* silence compiler warning about unused png_ptr */
+ return ((png_charp) PNG_LIBPNG_VER_STRING);
+ return ((png_charp) "");
}
png_charp PNGAPI
png_get_header_ver(png_structp png_ptr)
{
/* Version of *.h files used when building libpng */
- if(png_ptr != NULL) /* silence compiler warning about unused png_ptr */
- return((png_charp) PNG_LIBPNG_VER_STRING);
- return((png_charp) PNG_LIBPNG_VER_STRING);
+ if (&png_ptr != NULL) /* silence compiler warning about unused png_ptr */
+ return ((png_charp) PNG_LIBPNG_VER_STRING);
+ return ((png_charp) "");
}
png_charp PNGAPI
png_get_header_version(png_structp png_ptr)
{
/* Returns longer string containing both version and date */
- if(png_ptr != NULL) /* silence compiler warning about unused png_ptr */
- return((png_charp) PNG_HEADER_VERSION_STRING);
- return((png_charp) PNG_HEADER_VERSION_STRING);
+ if (&png_ptr != NULL) /* silence compiler warning about unused png_ptr */
+ return ((png_charp) PNG_HEADER_VERSION_STRING);
+ return ((png_charp) "");
}
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
png_access_version_number(void)
{
/* Version of *.c files used when building libpng */
- return((png_uint_32) 10204L);
+ return((png_uint_32) PNG_LIBPNG_VER);
}
png_ptr->asm_flags |= PNG_ASM_FLAG_MMX_SUPPORT_COMPILED;
- if (png_mmx_support()) {
+ if (png_mmx_support() > 0) {
png_ptr->asm_flags |= PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU
# ifdef PNG_HAVE_ASSEMBLER_COMBINE_ROW
| PNG_ASM_FLAG_MMX_READ_COMBINE_ROW
}
#endif
#endif /* PNG_1_0_X */
+
+#ifdef PNG_SIZE_T
+/* Added at libpng version 1.2.6 */
+ PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size));
+png_size_t PNGAPI
+png_convert_size(size_t size)
+{
+ if (size > (png_size_t)-1)
+ PNG_ABORT(); /* We haven't got access to png_ptr, so no png_error() */
+ return ((png_size_t)size);
+}
+#endif /* PNG_SIZE_T */