[libpng16] Added ANSI-C (C90) headers; eliminated the use of FAR/far.

This commit is contained in:
John Bowler 2011-11-26 18:21:02 -06:00 committed by Glenn Randers-Pehrson
parent 2ddb252d07
commit baeb6d1e92
25 changed files with 316 additions and 1021 deletions

View File

@ -1,5 +1,5 @@
Libpng 1.6.0alpha01 - November 24, 2011 Libpng 1.6.0alpha01 - November 27, 2011
This is not intended to be a public release. It will be replaced This is not intended to be a public release. It will be replaced
within a few weeks by a public version or by another test version. within a few weeks by a public version or by another test version.
@ -107,10 +107,25 @@ Version 1.5.7beta05 [(PENDING RELEASE)]
Added MINGW support to CMakeLists.txt Added MINGW support to CMakeLists.txt
Reject invalid compression flag or method when reading the iTXt chunk. Reject invalid compression flag or method when reading the iTXt chunk.
Version 1.6.0alpha01 [November 24, 2011] Version 1.6.0alpha01 [November 27, 2011]
Added example programs for the new 'simplified' API. Added example programs for the new 'simplified' API.
Moved pngvalid.c into contrib/libtests Moved pngvalid.c into contrib/libtests
Rebuilt Makefile.in, configure, etc., with autoconf-2.68 Rebuilt Makefile.in, configure, etc., with autoconf-2.68
Added ANSI-C (C90) headers and require them, and take advantage of the
change. Also fixed some of the projects/* and contrib/* files that needed
updates for libpng16 and the move of pngvalid.c.
With this change the required ANSI-C header files are assumed to exist: the
implementation must provide float.h, limits.h, stdarg.h and stddef.h and
libpng relies on limits.h and stddef.h existing and behaving as defined
(the other two required headers aren't used). Non-ANSI systems that don't
have stddef.h or limits.h will have to provide an appropriate fake
containing the relevant types and #defines.
The use of FAR/far has been eliminated and the definition of png_alloc_size_t
is now controlled by a flag so that 'small size_t' systems can select it
if necessary. Libpng 1.6 may not currently work on such systems -- it
seems likely that it will ask 'malloc' for more than 65535 bytes with any
image that has a sufficiently large row size (rather than simply failing
to read such images).
Send comments/corrections/commendations to png-mng-implement at lists.sf.net: Send comments/corrections/commendations to png-mng-implement at lists.sf.net:
(subscription required; visit (subscription required; visit

17
CHANGES
View File

@ -3752,10 +3752,25 @@ Version 1.5.7beta05 [(PENDING RELEASE)]
Added MINGW support to CMakeLists.txt Added MINGW support to CMakeLists.txt
Reject invalid compression flag or method when reading the iTXt chunk. Reject invalid compression flag or method when reading the iTXt chunk.
Version 1.6.0alpha01 [November 24, 2011] Version 1.6.0alpha01 [November 27, 2011]
Added example programs for the new 'simplified' API. Added example programs for the new 'simplified' API.
Moved pngvalid.c into contrib/libtests Moved pngvalid.c into contrib/libtests
Rebuilt Makefile.in, configure, etc., with autoconf-2.68 Rebuilt Makefile.in, configure, etc., with autoconf-2.68
Added ANSI-C (C90) headers and require them, and take advantage of the
change. Also fixed some of the projects/* and contrib/* files that needed
updates for libpng16 and the move of pngvalid.c.
With this change the required ANSI-C header files are assumed to exist: the
implementation must provide float.h, limits.h, stdarg.h and stddef.h and
libpng relies on limits.h and stddef.h existing and behaving as defined
(the other two required headers aren't used). Non-ANSI systems that don't
have stddef.h or limits.h will have to provide an appropriate fake
containing the relevant types and #defines.
The use of FAR/far has been eliminated and the definition of png_alloc_size_t
is now controlled by a flag so that 'small size_t' systems can select it
if necessary. Libpng 1.6 may not currently work on such systems -- it
seems likely that it will ask 'malloc' for more than 65535 bytes with any
image that has a sufficiently large row size (rather than simply failing
to read such images).
Send comments/corrections/commendations to png-mng-implement at lists.sf.net Send comments/corrections/commendations to png-mng-implement at lists.sf.net
(subscription required; visit (subscription required; visit

View File

@ -22,6 +22,10 @@
#include <ctype.h> #include <ctype.h>
#include <math.h> #include <math.h>
#ifdef HAVE_CONFIG_H
# include "../../config.h"
#endif
#include "../../png.h" #include "../../png.h"
#include "../sRGBtables/sRGB.h" #include "../sRGBtables/sRGB.h"

View File

@ -26,7 +26,7 @@
#include <signal.h> #include <signal.h>
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
# include "config.h" # include "../../config.h"
#endif #endif
#ifdef HAVE_FEENABLEEXCEPT #ifdef HAVE_FEENABLEEXCEPT
@ -90,7 +90,7 @@ typedef png_byte *png_const_bytep;
#endif #endif
/***************************** EXCEPTION HANDLING *****************************/ /***************************** EXCEPTION HANDLING *****************************/
#include "contrib/visupng/cexcept.h" #include "../visupng/cexcept.h"
#ifdef __cplusplus #ifdef __cplusplus
# define this not_the_cpp_this # define this not_the_cpp_this

View File

@ -19,7 +19,11 @@
#include <time.h> #include <time.h>
#include "png.h" #ifdef HAVE_CONFIG_H
# include "../../config.h"
#endif
#include "../../png.h"
static int read_png(FILE *fp) static int read_png(FILE *fp)
{ {

4
png.c
View File

@ -655,13 +655,13 @@ png_get_copyright(png_const_structp png_ptr)
#else #else
# ifdef __STDC__ # ifdef __STDC__
return PNG_STRING_NEWLINE \ return PNG_STRING_NEWLINE \
"libpng version 1.6.0alpha01 - November 24, 2011" PNG_STRING_NEWLINE \ "libpng version 1.6.0alpha01 - November 27, 2011" PNG_STRING_NEWLINE \
"Copyright (c) 1998-2011 Glenn Randers-Pehrson" PNG_STRING_NEWLINE \ "Copyright (c) 1998-2011 Glenn Randers-Pehrson" PNG_STRING_NEWLINE \
"Copyright (c) 1996-1997 Andreas Dilger" PNG_STRING_NEWLINE \ "Copyright (c) 1996-1997 Andreas Dilger" PNG_STRING_NEWLINE \
"Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc." \ "Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc." \
PNG_STRING_NEWLINE; PNG_STRING_NEWLINE;
# else # else
return "libpng version 1.6.0alpha01 - November 24, 2011\ return "libpng version 1.6.0alpha01 - November 27, 2011\
Copyright (c) 1998-2011 Glenn Randers-Pehrson\ Copyright (c) 1998-2011 Glenn Randers-Pehrson\
Copyright (c) 1996-1997 Andreas Dilger\ Copyright (c) 1996-1997 Andreas Dilger\
Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc."; Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.";

94
png.h
View File

@ -1,7 +1,7 @@
/* png.h - header file for PNG reference library /* png.h - header file for PNG reference library
* *
* libpng version 1.6.0alpha01 - November 24, 2011 * libpng version 1.6.0alpha01 - November 27, 2011
* Copyright (c) 1998-2011 Glenn Randers-Pehrson * Copyright (c) 1998-2011 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
@ -11,7 +11,7 @@
* Authors and maintainers: * Authors and maintainers:
* libpng versions 0.71, May 1995, through 0.88, January 1996: Guy Schalnat * libpng versions 0.71, May 1995, through 0.88, January 1996: Guy Schalnat
* libpng versions 0.89c, June 1996, through 0.96, May 1997: Andreas Dilger * libpng versions 0.89c, June 1996, through 0.96, May 1997: Andreas Dilger
* libpng versions 0.97, January 1998, through 1.6.0alpha01 - November 24, 2011: Glenn * libpng versions 0.97, January 1998, through 1.6.0alpha01 - November 27, 2011: Glenn
* See also "Contributing Authors", below. * See also "Contributing Authors", below.
* *
* Note about libpng version numbers: * Note about libpng version numbers:
@ -196,7 +196,7 @@
* *
* This code is released under the libpng license. * This code is released under the libpng license.
* *
* libpng versions 1.2.6, August 15, 2004, through 1.6.0alpha01, November 24, 2011, are * libpng versions 1.2.6, August 15, 2004, through 1.6.0alpha01, November 27, 2011, are
* Copyright (c) 2004, 2006-2011 Glenn Randers-Pehrson, and are * Copyright (c) 2004, 2006-2011 Glenn Randers-Pehrson, and are
* distributed according to the same disclaimer and license as libpng-1.2.5 * distributed according to the same disclaimer and license as libpng-1.2.5
* with the following individual added to the list of Contributing Authors: * with the following individual added to the list of Contributing Authors:
@ -308,7 +308,7 @@
* Y2K compliance in libpng: * Y2K compliance in libpng:
* ========================= * =========================
* *
* November 24, 2011 * November 27, 2011
* *
* Since the PNG Development group is an ad-hoc body, we can't make * Since the PNG Development group is an ad-hoc body, we can't make
* an official declaration. * an official declaration.
@ -374,7 +374,7 @@
/* Version information for png.h - this should match the version in png.c */ /* Version information for png.h - this should match the version in png.c */
#define PNG_LIBPNG_VER_STRING "1.6.0alpha01" #define PNG_LIBPNG_VER_STRING "1.6.0alpha01"
#define PNG_HEADER_VERSION_STRING \ #define PNG_HEADER_VERSION_STRING \
" libpng version 1.6.0alpha01 - November 24, 2011\n" " libpng version 1.6.0alpha01 - November 27, 2011\n"
#define PNG_LIBPNG_VER_SONUM 16 #define PNG_LIBPNG_VER_SONUM 16
#define PNG_LIBPNG_VER_DLLNUM 16 #define PNG_LIBPNG_VER_DLLNUM 16
@ -426,24 +426,6 @@
#endif #endif
#ifndef PNG_VERSION_INFO_ONLY #ifndef PNG_VERSION_INFO_ONLY
# ifndef PNG_BUILDING_SYMBOL_TABLE
/*
* Standard header files (not needed for the version info or while
* building symbol table -- see scripts/pnglibconf.dfa)
*/
# ifdef PNG_SETJMP_SUPPORTED
# include <setjmp.h>
# endif
/* Need the time information for converting tIME chunks, it
* defines struct tm:
*/
# ifdef PNG_CONVERT_tIME_SUPPORTED
/* "time.h" functions are not supported on all operating systems */
# include <time.h>
# endif
# endif
/* Machine specific configuration. */ /* Machine specific configuration. */
# include "pngconf.h" # include "pngconf.h"
#endif #endif
@ -548,9 +530,9 @@ typedef struct png_color_struct
png_byte green; png_byte green;
png_byte blue; png_byte blue;
} png_color; } png_color;
typedef png_color FAR * png_colorp; typedef png_color * png_colorp;
typedef PNG_CONST png_color FAR * png_const_colorp; typedef const png_color * png_const_colorp;
typedef png_color FAR * FAR * png_colorpp; typedef png_color * * png_colorpp;
typedef struct png_color_16_struct typedef struct png_color_16_struct
{ {
@ -560,9 +542,9 @@ typedef struct png_color_16_struct
png_uint_16 blue; png_uint_16 blue;
png_uint_16 gray; /* for use in grayscale files */ png_uint_16 gray; /* for use in grayscale files */
} png_color_16; } png_color_16;
typedef png_color_16 FAR * png_color_16p; typedef png_color_16 * png_color_16p;
typedef PNG_CONST png_color_16 FAR * png_const_color_16p; typedef const png_color_16 * png_const_color_16p;
typedef png_color_16 FAR * FAR * png_color_16pp; typedef png_color_16 * * png_color_16pp;
typedef struct png_color_8_struct typedef struct png_color_8_struct
{ {
@ -572,9 +554,9 @@ typedef struct png_color_8_struct
png_byte gray; /* for use in grayscale files */ png_byte gray; /* for use in grayscale files */
png_byte alpha; /* for alpha channel files */ png_byte alpha; /* for alpha channel files */
} png_color_8; } png_color_8;
typedef png_color_8 FAR * png_color_8p; typedef png_color_8 * png_color_8p;
typedef PNG_CONST png_color_8 FAR * png_const_color_8p; typedef const png_color_8 * png_const_color_8p;
typedef png_color_8 FAR * FAR * png_color_8pp; typedef png_color_8 * * png_color_8pp;
/* /*
* The following two structures are used for the in-core representation * The following two structures are used for the in-core representation
@ -588,9 +570,9 @@ typedef struct png_sPLT_entry_struct
png_uint_16 alpha; png_uint_16 alpha;
png_uint_16 frequency; png_uint_16 frequency;
} png_sPLT_entry; } png_sPLT_entry;
typedef png_sPLT_entry FAR * png_sPLT_entryp; typedef png_sPLT_entry * png_sPLT_entryp;
typedef PNG_CONST png_sPLT_entry FAR * png_const_sPLT_entryp; typedef const png_sPLT_entry * png_const_sPLT_entryp;
typedef png_sPLT_entry FAR * FAR * png_sPLT_entrypp; typedef png_sPLT_entry * * png_sPLT_entrypp;
/* When the depth of the sPLT palette is 8 bits, the color and alpha samples /* When the depth of the sPLT palette is 8 bits, the color and alpha samples
* occupy the LSB of their respective members, and the MSB of each member * occupy the LSB of their respective members, and the MSB of each member
@ -604,9 +586,9 @@ typedef struct png_sPLT_struct
png_sPLT_entryp entries; /* palette entries */ png_sPLT_entryp entries; /* palette entries */
png_int_32 nentries; /* number of palette entries */ png_int_32 nentries; /* number of palette entries */
} png_sPLT_t; } png_sPLT_t;
typedef png_sPLT_t FAR * png_sPLT_tp; typedef png_sPLT_t * png_sPLT_tp;
typedef PNG_CONST png_sPLT_t FAR * png_const_sPLT_tp; typedef const png_sPLT_t * png_const_sPLT_tp;
typedef png_sPLT_t FAR * FAR * png_sPLT_tpp; typedef png_sPLT_t * * png_sPLT_tpp;
#ifdef PNG_TEXT_SUPPORTED #ifdef PNG_TEXT_SUPPORTED
/* png_text holds the contents of a text/ztxt/itxt chunk in a PNG file, /* png_text holds the contents of a text/ztxt/itxt chunk in a PNG file,
@ -643,9 +625,9 @@ typedef struct png_text_struct
png_charp lang_key; /* keyword translated UTF-8 string, 0 or more png_charp lang_key; /* keyword translated UTF-8 string, 0 or more
chars or a NULL pointer */ chars or a NULL pointer */
} png_text; } png_text;
typedef png_text FAR * png_textp; typedef png_text * png_textp;
typedef PNG_CONST png_text FAR * png_const_textp; typedef const png_text * png_const_textp;
typedef png_text FAR * FAR * png_textpp; typedef png_text * * png_textpp;
#endif #endif
/* Supported compression types for text in PNG files (tEXt, and zTXt). /* Supported compression types for text in PNG files (tEXt, and zTXt).
@ -673,9 +655,9 @@ typedef struct png_time_struct
png_byte minute; /* minute of hour, 0 - 59 */ png_byte minute; /* minute of hour, 0 - 59 */
png_byte second; /* second of minute, 0 - 60 (for leap seconds) */ png_byte second; /* second of minute, 0 - 60 (for leap seconds) */
} png_time; } png_time;
typedef png_time FAR * png_timep; typedef png_time * png_timep;
typedef PNG_CONST png_time FAR * png_const_timep; typedef const png_time * png_const_timep;
typedef png_time FAR * FAR * png_timepp; typedef png_time * * png_timepp;
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) || \ #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) || \
defined(PNG_HANDLE_AS_UNKNOWN_SUPPORTED) defined(PNG_HANDLE_AS_UNKNOWN_SUPPORTED)
@ -696,9 +678,9 @@ typedef struct png_unknown_chunk_t
png_unknown_chunk; png_unknown_chunk;
typedef png_unknown_chunk FAR * png_unknown_chunkp; typedef png_unknown_chunk * png_unknown_chunkp;
typedef PNG_CONST png_unknown_chunk FAR * png_const_unknown_chunkp; typedef const png_unknown_chunk * png_const_unknown_chunkp;
typedef png_unknown_chunk FAR * FAR * png_unknown_chunkpp; typedef png_unknown_chunk * * png_unknown_chunkpp;
#endif #endif
/* Values for the unknown chunk location byte */ /* Values for the unknown chunk location byte */
@ -712,9 +694,9 @@ typedef png_unknown_chunk FAR * FAR * png_unknown_chunkpp;
* applications. Read libpng-manual.txt or libpng.3 for more info. * applications. Read libpng-manual.txt or libpng.3 for more info.
*/ */
typedef struct png_info_def png_info; typedef struct png_info_def png_info;
typedef png_info FAR * png_infop; typedef png_info * png_infop;
typedef PNG_CONST png_info FAR * png_const_infop; typedef const png_info * png_const_infop;
typedef png_info FAR * FAR * png_infopp; typedef png_info * * png_infopp;
/* Maximum positive integer used in PNG is (2^31)-1 */ /* Maximum positive integer used in PNG is (2^31)-1 */
#define PNG_UINT_31_MAX ((png_uint_32)0x7fffffffL) #define PNG_UINT_31_MAX ((png_uint_32)0x7fffffffL)
@ -831,16 +813,16 @@ typedef struct png_row_info_struct
png_byte pixel_depth; /* bits per pixel (depth * channels) */ png_byte pixel_depth; /* bits per pixel (depth * channels) */
} png_row_info; } png_row_info;
typedef png_row_info FAR * png_row_infop; typedef png_row_info * png_row_infop;
typedef png_row_info FAR * FAR * png_row_infopp; typedef png_row_info * * png_row_infopp;
/* The complete definition of png_struct has, as of libpng-1.5.0, /* The complete definition of png_struct has, as of libpng-1.5.0,
* been moved into a separate header file that is not accessible to * been moved into a separate header file that is not accessible to
* applications. Read libpng-manual.txt or libpng.3 for more info. * applications. Read libpng-manual.txt or libpng.3 for more info.
*/ */
typedef struct png_struct_def png_struct; typedef struct png_struct_def png_struct;
typedef PNG_CONST png_struct FAR * png_const_structp; typedef const png_struct * png_const_structp;
typedef png_struct FAR * png_structp; typedef png_struct * png_structp;
/* These are the function types for the I/O functions and for the functions /* These are the function types for the I/O functions and for the functions
* that allow the user to override the default I/O functions with his or her * that allow the user to override the default I/O functions with his or her
@ -943,7 +925,7 @@ typedef PNG_CALLBACK(png_voidp, *png_malloc_ptr, (png_structp,
png_alloc_size_t)); png_alloc_size_t));
typedef PNG_CALLBACK(void, *png_free_ptr, (png_structp, png_voidp)); typedef PNG_CALLBACK(void, *png_free_ptr, (png_structp, png_voidp));
typedef png_struct FAR * FAR * png_structpp; typedef png_struct * * png_structpp;
/* Section 3: exported functions /* Section 3: exported functions
* Here are the function definitions most commonly used. This is not * Here are the function definitions most commonly used. This is not
@ -1105,7 +1087,7 @@ PNG_EXPORT(23, png_const_charp, png_convert_to_rfc1123,
#ifdef PNG_CONVERT_tIME_SUPPORTED #ifdef PNG_CONVERT_tIME_SUPPORTED
/* Convert from a struct tm to png_time */ /* Convert from a struct tm to png_time */
PNG_EXPORT(24, void, png_convert_from_struct_tm, (png_timep ptime, PNG_EXPORT(24, void, png_convert_from_struct_tm, (png_timep ptime,
PNG_CONST struct tm FAR * ttime)); const struct tm * ttime));
/* Convert from time_t to png_time. Uses gmtime() */ /* Convert from time_t to png_time. Uses gmtime() */
PNG_EXPORT(25, void, png_convert_from_time_t, PNG_EXPORT(25, void, png_convert_from_time_t,

363
pngconf.h
View File

@ -1,7 +1,7 @@
/* pngconf.h - machine configurable file for libpng /* pngconf.h - machine configurable file for libpng
* *
* libpng version 1.6.0alpha01 - November 24, 2011 * libpng version 1.6.0alpha01 - November 27, 2011
* *
* Copyright (c) 1998-2011 Glenn Randers-Pehrson * Copyright (c) 1998-2011 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@ -22,33 +22,49 @@
#ifndef PNGCONF_H #ifndef PNGCONF_H
#define PNGCONF_H #define PNGCONF_H
#ifndef PNG_BUILDING_SYMBOL_TABLE #ifndef PNG_BUILDING_SYMBOL_TABLE /* else includes may cause problems */
/* PNG_NO_LIMITS_H may be used to turn off the use of the standard C
* definition file for machine specific limits, this may impact the /* From libpng 1.6.0 libpng requires an ANSI X3.159-1989 ("ISOC90") compliant C
* correctness of the definitons below (see uses of INT_MAX). * compiler for correct compilation. The following header files are required by
* the standard. If your compiler doesn't provide these header files, or they
* do not match the standard, you will need to provide/improve them.
*/ */
# ifndef PNG_NO_LIMITS_H
#include <limits.h> #include <limits.h>
# endif #include <stddef.h>
/* For the memory copy APIs (i.e. the standard definitions of these), /* Library header files. These header files are all defined by ISOC90, libpng
* because this file defines png_memcpy and so on the base APIs must * expects conformant implementations however an ISOC90 conformant system need
* be defined here. * not provide these header files if the functionality cannot be implemented.
* In this case it will be necessary to disable the relevant parts of libpng in
* the build of pnglibconf.h.
*
* Prior to 1.6.0 string.h was included here; the API changes in 1.6.0 to not
* include this unnecessary header file.
*/ */
# ifdef BSD
# include <strings.h>
# else
# include <string.h>
# endif
/* For png_FILE_p - this provides the standard definition of a
* FILE
*/
#ifdef PNG_STDIO_SUPPORTED #ifdef PNG_STDIO_SUPPORTED
/* Required for the definition of FILE: */
# include <stdio.h> # include <stdio.h>
#endif #endif
#ifdef PNG_SETJMP_SUPPORTED
/* Required for the definition of jmp_buf and the declaration of longjmp: */
# include <setjmp.h>
#endif #endif
#ifdef PNG_CONVERT_tIME_SUPPORTED
/* Required for struct tm: */
# include <time.h>
#endif
#endif /* PNG_BUILDING_SYMBOL_TABLE */
/* Prior to 1.6.0 it was possible to turn off 'const' in declarations using
* PNG_NO_CONST; this is no longer supported except for data declarations which
* apparently still cause problems in 2011 on some compilers.
*/
#define PNG_CONST const /* backward compatibility only */
/* This controls optimization of the reading of 16 and 32 bit values /* This controls optimization of the reading of 16 and 32 bit values
* from PNG files. It can be set on a per-app-file basis - it * from PNG files. It can be set on a per-app-file basis - it
* just changes whether a macro is used to the function is called. * just changes whether a macro is used to the function is called.
@ -72,28 +88,13 @@
* may be changed on a per-file basis when compiling against libpng. * may be changed on a per-file basis when compiling against libpng.
*/ */
/* The PNGARG macro protects us against machines that don't have function /* The PNGARG macro was used in versions of libpng prior to 1.6.0 to protect
* prototypes (ie K&R style headers). If your compiler does not handle * against legacy (pre ISOC90) compilers that did not understand function
* function prototypes, define this macro and use the included ansi2knr. * prototypes. It is not required for modern C compilers.
* I've always been able to use _NO_PROTO as the indicator, but you may
* need to drag the empty declaration out in front of here, or change the
* ifdef to suit your own needs.
*/ */
#ifndef PNGARG #ifndef PNGARG
# ifdef OF /* zlib prototype munger */
# define PNGARG(arglist) OF(arglist)
# else
# ifdef _NO_PROTO
# define PNGARG(arglist) ()
# else
# define PNGARG(arglist) arglist # define PNGARG(arglist) arglist
# endif /* _NO_PROTO */ #endif
# endif /* OF */
#endif /* PNGARG */
/* Function calling conventions. /* Function calling conventions.
* ============================= * =============================
@ -219,7 +220,7 @@
/* NOTE: PNGCBAPI always defaults to PNGCAPI. */ /* NOTE: PNGCBAPI always defaults to PNGCAPI. */
# if defined(PNGAPI) && !defined(PNG_USER_PRIVATEBUILD) # if defined(PNGAPI) && !defined(PNG_USER_PRIVATEBUILD)
ERROR: PNG_USER_PRIVATEBUILD must be defined if PNGAPI is changed # error "PNG_USER_PRIVATEBUILD must be defined if PNGAPI is changed"
# endif # endif
# if (defined(_MSC_VER) && _MSC_VER < 800) ||\ # if (defined(_MSC_VER) && _MSC_VER < 800) ||\
@ -414,183 +415,167 @@
# endif # endif
#endif #endif
/* The following uses const char * instead of char * for error #ifndef PNG_BUILDING_SYMBOL_TABLE
* and warning message functions, so some compilers won't complain. /* Some typedefs to get us started. These should be safe on most of the common
* If you do not want to use const, define PNG_NO_CONST here. * platforms.
* *
* This should not change how the APIs are called, so it can be done * png_uint_32 and png_int_32 may, currently, be larger than required to hold a
* on a per-file basis in the application. * 32-bit value however this is not normally advisable.
*
* png_uint_16 and png_int_16 should always be two bytes in size - this is
* verified at library build time.
*
* png_byte must always be one byte in size.
*
* The checks below use constants from limits.h, as defined by the ISOC90
* standard.
*/ */
#ifndef PNG_CONST #if CHAR_BIT == 8 && UCHAR_MAX == 255
# ifndef PNG_NO_CONST
# define PNG_CONST const
# else
# define PNG_CONST
# endif
#endif
/* Some typedefs to get us started. These should be safe on most of the
* common platforms. The typedefs should be at least as large as the
* numbers suggest (a png_uint_32 must be at least 32 bits long), but they
* don't have to be exactly that size. Some compilers dislike passing
* unsigned shorts as function parameters, so you may be better off using
* unsigned int for png_uint_16.
*/
#if defined(INT_MAX) && (INT_MAX > 0x7ffffffeL)
typedef unsigned int png_uint_32;
typedef int png_int_32;
#else
typedef unsigned long png_uint_32;
typedef long png_int_32;
#endif
typedef unsigned short png_uint_16;
typedef short png_int_16;
typedef unsigned char png_byte; typedef unsigned char png_byte;
#ifdef PNG_NO_SIZE_T
typedef unsigned int png_size_t;
#else #else
typedef size_t png_size_t; # error "libpng requires 8 bit bytes"
#endif #endif
#if INT_MIN == -32768 && INT_MAX == 32767
typedef int png_int_16;
#elif SHRT_MIN == -32768 && SHRT_MAX == 32767
typedef short png_int_16;
#else
# error "libpng requires a signed 16 bit type"
#endif
#if UINT_MAX == 65535
typedef unsigned int png_uint_16;
#elif USHRT_MAX == 65535
typedef unsigned short png_uint_16;
#else
# error "libpng requires an unsigned 16 bit type"
#endif
#if INT_MIN < -2147483646 && INT_MAX > 2147483646
typedef int png_int_32;
#elif LONG_MIN < -2147483646 && LONG_MAX > 2147483646
typedef long int png_int_32;
#else
# error "libpng requires a signed 32 bit (or more) type"
#endif
#if UINT_MAX > 4294967294
typedef unsigned int png_uint_32;
#elif ULONG_MAX > 4294967294
typedef unsigned long int png_uint_32;
#else
# error "libpng requires an unsigned 32 bit (or more) type"
#endif
/* Prior to 1.6.0 it was possible to disable the use of size_t, 1.6.0, however,
* requires an ISOC90 compiler and relies on consistent behavior of sizeof.
*/
typedef size_t png_size_t;
typedef ptrdiff_t png_ptrdiff_t;
/* libpng needs to know the maximum value of 'size_t' and this controls the
* definition of png_alloc_size_t, below. This maximum value of size_t limits
* but does not control the maximum allocations the library makes - there is
* direct application control of this through png_set_user_limits().
*/
#ifndef PNG_SMALL_SIZE_T
/* Compiler specific tests for systems where size_t is known to be less than
* 32 bits (some of these systems may no longer work because of the lack of
* 'far' support; see above.)
*/
# if (defined(__TURBOC__) && !defined(__FLAT__)) ||\
(defined(_MSC_VER) && defined(MAXSEG_64K))
# define PNG_SMALL_SIZE_T
# endif
#endif
/* png_alloc_size_t is guaranteed to be no smaller than png_size_t, and no
* smaller than png_uint_32. Casts from png_size_t or png_uint_32 to
* png_alloc_size_t are not necessary; in fact, it is recommended not to use
* them at all so that the compiler can complain when something turns out to be
* problematic.
*
* Casts in the other direction (from png_alloc_size_t to png_size_t or
* png_uint_32) should be explicitly applied; however, we do not expect to
* encounter practical situations that require such conversions.
*
* PNG_SMALL_SIZE_T must be defined if the maximum value of size_t is less than
* 4294967295 - i.e. less than the maximum value of png_uint_32.
*/
#ifdef PNG_SMALL_SIZE_T
typedef png_uint_32 png_alloc_size_t;
#else
typedef png_size_t png_alloc_size_t;
#endif
/* This macro makes the sizeof operator look and behave like a function, except
* that it can take a type without the enclosing () as an argument so long as
* the type contains no "," characters.
*/
#define png_sizeof(x) (sizeof (x)) #define png_sizeof(x) (sizeof (x))
/* The following is needed for medium model support. It cannot be in the /* Prior to 1.6.0 libpng offered limited support for Microsoft C compiler
* pngpriv.h header. Needs modification for other compilers besides * implementations of Intel CPU specific support of user-mode segmented address
* MSC. Model independent support declares all arrays and pointers to be * spaces, where 16-bit pointers address more than 65536 bytes of memory using
* large using the far keyword. The zlib version used must also support * separate 'segment' registers. The implementation requires two different
* model independent data. As of version zlib 1.0.4, the necessary changes * types of pointer (only one of which includes the segment value.)
* have been made in zlib. The USE_FAR_KEYWORD define triggers other *
* changes that are needed. (Tim Wegner) * If required this support is available in version 1.2 of libpng and may be
* available in versions through 1.5, although the correctness of the code has
* not been verified recently.
*/ */
/* Separate compiler dependencies (problem here is that zlib.h always /* Typedef for floating-point numbers that are converted to fixed-point with a
* defines FAR. (SJT) * multiple of 100,000, e.g., gamma
*/
#ifdef __BORLANDC__
# if defined(__LARGE__) || defined(__HUGE__) || defined(__COMPACT__)
# define LDATA 1
# else
# define LDATA 0
# endif
/* GRR: why is Cygwin in here? Cygwin is not Borland C... */
# if !defined(__WIN32__) && !defined(__FLAT__) && !defined(__CYGWIN__)
# define PNG_MAX_MALLOC_64K /* only used in build */
# if (LDATA != 1)
# ifndef FAR
# define FAR __far
# endif
# define USE_FAR_KEYWORD
# endif /* LDATA != 1 */
/* Possibly useful for moving data out of default segment.
* Uncomment it if you want. Could also define FARDATA as
* const if your compiler supports it. (SJT)
# define FARDATA FAR
*/
# endif /* __WIN32__, __FLAT__, __CYGWIN__ */
#endif /* __BORLANDC__ */
/* Suggest testing for specific compiler first before testing for
* FAR. The Watcom compiler defines both __MEDIUM__ and M_I86MM,
* making reliance oncertain keywords suspect. (SJT)
*/
/* MSC Medium model */
#ifdef FAR
# ifdef M_I86MM
# define USE_FAR_KEYWORD
# define FARDATA FAR
# include <dos.h>
# endif
#endif
/* SJT: default case */
#ifndef FAR
# define FAR
#endif
/* At this point FAR is always defined */
#ifndef FARDATA
# define FARDATA
#endif
/* Typedef for floating-point numbers that are converted
* to fixed-point with a multiple of 100,000, e.g., gamma
*/ */
typedef png_int_32 png_fixed_point; typedef png_int_32 png_fixed_point;
/* Add typedefs for pointers */ /* Add typedefs for pointers */
typedef void FAR * png_voidp; typedef void * png_voidp;
typedef PNG_CONST void FAR * png_const_voidp; typedef const void * png_const_voidp;
typedef png_byte FAR * png_bytep; typedef png_byte * png_bytep;
typedef PNG_CONST png_byte FAR * png_const_bytep; typedef const png_byte * png_const_bytep;
typedef png_uint_32 FAR * png_uint_32p; typedef png_uint_32 * png_uint_32p;
typedef PNG_CONST png_uint_32 FAR * png_const_uint_32p; typedef const png_uint_32 * png_const_uint_32p;
typedef png_int_32 FAR * png_int_32p; typedef png_int_32 * png_int_32p;
typedef PNG_CONST png_int_32 FAR * png_const_int_32p; typedef const png_int_32 * png_const_int_32p;
typedef png_uint_16 FAR * png_uint_16p; typedef png_uint_16 * png_uint_16p;
typedef PNG_CONST png_uint_16 FAR * png_const_uint_16p; typedef const png_uint_16 * png_const_uint_16p;
typedef png_int_16 FAR * png_int_16p; typedef png_int_16 * png_int_16p;
typedef PNG_CONST png_int_16 FAR * png_const_int_16p; typedef const png_int_16 * png_const_int_16p;
typedef char FAR * png_charp; typedef char * png_charp;
typedef PNG_CONST char FAR * png_const_charp; typedef const char * png_const_charp;
typedef png_fixed_point FAR * png_fixed_point_p; typedef png_fixed_point * png_fixed_point_p;
typedef PNG_CONST png_fixed_point FAR * png_const_fixed_point_p; typedef const png_fixed_point * png_const_fixed_point_p;
typedef png_size_t FAR * png_size_tp; typedef png_size_t * png_size_tp;
typedef PNG_CONST png_size_t FAR * png_const_size_tp; typedef const png_size_t * png_const_size_tp;
#ifdef PNG_STDIO_SUPPORTED #ifdef PNG_STDIO_SUPPORTED
typedef FILE * png_FILE_p; typedef FILE * png_FILE_p;
#endif #endif
#ifdef PNG_FLOATING_POINT_SUPPORTED #ifdef PNG_FLOATING_POINT_SUPPORTED
typedef double FAR * png_doublep; typedef double * png_doublep;
typedef PNG_CONST double FAR * png_const_doublep; typedef const double * png_const_doublep;
#endif #endif
/* Pointers to pointers; i.e. arrays */ /* Pointers to pointers; i.e. arrays */
typedef png_byte FAR * FAR * png_bytepp; typedef png_byte * * png_bytepp;
typedef png_uint_32 FAR * FAR * png_uint_32pp; typedef png_uint_32 * * png_uint_32pp;
typedef png_int_32 FAR * FAR * png_int_32pp; typedef png_int_32 * * png_int_32pp;
typedef png_uint_16 FAR * FAR * png_uint_16pp; typedef png_uint_16 * * png_uint_16pp;
typedef png_int_16 FAR * FAR * png_int_16pp; typedef png_int_16 * * png_int_16pp;
typedef PNG_CONST char FAR * FAR * png_const_charpp; typedef const char * * png_const_charpp;
typedef char FAR * FAR * png_charpp; typedef char * * png_charpp;
typedef png_fixed_point FAR * FAR * png_fixed_point_pp; typedef png_fixed_point * * png_fixed_point_pp;
#ifdef PNG_FLOATING_POINT_SUPPORTED #ifdef PNG_FLOATING_POINT_SUPPORTED
typedef double FAR * FAR * png_doublepp; typedef double * * png_doublepp;
#endif #endif
/* Pointers to pointers to pointers; i.e., pointer to array */ /* Pointers to pointers to pointers; i.e., pointer to array */
typedef char FAR * FAR * FAR * png_charppp; typedef char * * * png_charppp;
/* png_alloc_size_t is guaranteed to be no smaller than png_size_t, #endif /* PNG_BUILDING_SYMBOL_TABLE */
* and no smaller than png_uint_32. Casts from png_size_t or png_uint_32
* to png_alloc_size_t are not necessary; in fact, it is recommended
* not to use them at all so that the compiler can complain when something
* turns out to be problematic.
* Casts in the other direction (from png_alloc_size_t to png_size_t or
* png_uint_32) should be explicitly applied; however, we do not expect
* to encounter practical situations that require such conversions.
*/
#if defined(__TURBOC__) && !defined(__FLAT__)
typedef unsigned long png_alloc_size_t;
#else
# if defined(_MSC_VER) && defined(MAXSEG_64K)
typedef unsigned long png_alloc_size_t;
# else
/* This is an attempt to detect an old Windows system where (int) is
* actually 16 bits, in that case png_malloc must have an argument with a
* bigger size to accomodate the requirements of the library.
*/
# if (defined(_Windows) || defined(_WINDOWS) || defined(_WINDOWS_)) && \
(!defined(INT_MAX) || INT_MAX <= 0x7ffffffeL)
typedef DWORD png_alloc_size_t;
# else
typedef png_size_t png_alloc_size_t;
# endif
# endif
#endif
#endif /* PNGCONF_H */ #endif /* PNGCONF_H */

View File

@ -557,19 +557,9 @@ png_longjmp,(png_structp png_ptr, int val),PNG_NORETURN)
{ {
#ifdef PNG_SETJMP_SUPPORTED #ifdef PNG_SETJMP_SUPPORTED
if (png_ptr && png_ptr->longjmp_fn) if (png_ptr && png_ptr->longjmp_fn)
{
# ifdef USE_FAR_KEYWORD
{
jmp_buf tmp_jmpbuf;
png_memcpy(tmp_jmpbuf, png_ptr->longjmp_buffer, png_sizeof(jmp_buf));
png_ptr->longjmp_fn(tmp_jmpbuf, val);
}
# else
png_ptr->longjmp_fn(png_ptr->longjmp_buffer, val); png_ptr->longjmp_fn(png_ptr->longjmp_buffer, val);
#endif #endif
}
#endif
/* Here if not setjmp support or if png_ptr is null. */ /* Here if not setjmp support or if png_ptr is null. */
PNG_ABORT(); PNG_ABORT();
} }

352
pngmem.c
View File

@ -20,357 +20,6 @@
#include "pngpriv.h" #include "pngpriv.h"
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
/* Borland DOS special memory handler */
#if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
/* If you change this, be sure to change the one in png.h also */
/* Allocate memory for a png_struct. The malloc and memset can be replaced
by a single call to calloc() if this is thought to improve performance. */
PNG_FUNCTION(png_voidp /* PRIVATE */,
png_create_struct,(int type),PNG_ALLOCATED)
{
# ifdef PNG_USER_MEM_SUPPORTED
return (png_create_struct_2(type, NULL, NULL));
}
/* Alternate version of png_create_struct, for use with user-defined malloc. */
PNG_FUNCTION(png_voidp /* PRIVATE */,
png_create_struct_2,(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr),
PNG_ALLOCATED)
{
# endif /* PNG_USER_MEM_SUPPORTED */
png_size_t size;
png_voidp struct_ptr;
if (type == PNG_STRUCT_INFO)
size = png_sizeof(png_info);
else if (type == PNG_STRUCT_PNG)
size = png_sizeof(png_struct);
else
return (png_get_copyright(NULL));
# ifdef PNG_USER_MEM_SUPPORTED
if (malloc_fn != NULL)
{
png_struct dummy_struct;
memset(&dummy_struct, 0, sizeof dummy_struct);
dummy_struct.mem_ptr=mem_ptr;
struct_ptr = (*(malloc_fn))(&dummy_struct, (png_alloc_size_t)size);
}
else
# endif /* PNG_USER_MEM_SUPPORTED */
struct_ptr = (png_voidp)farmalloc(size);
if (struct_ptr != NULL)
png_memset(struct_ptr, 0, size);
return (struct_ptr);
}
/* Free memory allocated by a png_create_struct() call */
void /* PRIVATE */
png_destroy_struct(png_voidp struct_ptr)
{
# ifdef PNG_USER_MEM_SUPPORTED
png_destroy_struct_2(struct_ptr, NULL, 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_voidp mem_ptr)
{
# endif
if (struct_ptr != NULL)
{
# ifdef PNG_USER_MEM_SUPPORTED
if (free_fn != NULL)
{
png_struct dummy_struct;
memset(&dummy_struct, 0, sizeof dummy_struct);
dummy_struct.mem_ptr=mem_ptr;
(*(free_fn))(&dummy_struct, struct_ptr);
return;
}
# endif /* PNG_USER_MEM_SUPPORTED */
farfree (struct_ptr);
}
}
/* Allocate memory. For reasonable files, size should never exceed
* 64K. However, zlib may allocate more then 64K if you don't tell
* it not to. See zconf.h and png.h for more information. zlib does
* need to allocate exactly 64K, so whatever you call here must
* have the ability to do that.
*
* Borland seems to have a problem in DOS mode for exactly 64K.
* It gives you a segment with an offset of 8 (perhaps to store its
* memory stuff). zlib doesn't like this at all, so we have to
* detect and deal with it. This code should not be needed in
* Windows or OS/2 modes, and only in 16 bit mode. This code has
* been updated by Alexander Lehmann for version 0.89 to waste less
* memory.
*
* Note that we can't use png_size_t for the "size" declaration,
* since on some systems a png_size_t is a 16-bit quantity, and as a
* result, we would be truncating potentially larger memory requests
* (which should cause a fatal error) and introducing major problems.
*/
PNG_FUNCTION(png_voidp,PNGAPI
png_calloc,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED)
{
png_voidp ret;
ret = (png_malloc(png_ptr, size));
if (ret != NULL)
png_memset(ret,0,(png_size_t)size);
return (ret);
}
PNG_FUNCTION(png_voidp,PNGAPI
png_malloc,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED)
{
png_voidp ret;
if (png_ptr == NULL || size == 0)
return (NULL);
# ifdef PNG_USER_MEM_SUPPORTED
if (png_ptr->malloc_fn != NULL)
ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, size));
else
ret = (png_malloc_default(png_ptr, size));
if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
png_error(png_ptr, "Out of memory");
return (ret);
}
PNG_FUNCTION(png_voidp,PNGAPI
png_malloc_default,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED)
{
png_voidp ret;
# endif /* PNG_USER_MEM_SUPPORTED */
if (png_ptr == NULL || size == 0)
return (NULL);
# ifdef PNG_MAX_MALLOC_64K
if (size > (png_uint_32)65536L)
{
png_warning(png_ptr, "Cannot Allocate > 64K");
ret = NULL;
}
else
# endif
if (size != (size_t)size)
ret = NULL;
else if (size == (png_uint_32)65536L)
{
if (png_ptr->offset_table == NULL)
{
/* Try to see if we need to do any of this fancy stuff */
ret = farmalloc(size);
if (ret == NULL || ((png_size_t)ret & 0xffff))
{
int num_blocks;
png_uint_32 total_size;
png_bytep table;
int i, mem_level, window_bits;
png_byte huge * hptr;
int window_bits
if (ret != NULL)
{
farfree(ret);
ret = NULL;
}
window_bits =
png_ptr->zlib_window_bits >= png_ptr->zlib_text_window_bits ?
png_ptr->zlib_window_bits : png_ptr->zlib_text_window_bits;
if (window_bits > 14)
num_blocks = (int)(1 << (window_bits - 14));
else
num_blocks = 1;
mem_level =
png_ptr->zlib_mem_level >= png_ptr->zlib_text_mem_level ?
png_ptr->zlib_mem_level : png_ptr->zlib_text_mem_level;
if (mem_level >= 7)
num_blocks += (int)(1 << (mem_level - 7));
else
num_blocks++;
total_size = ((png_uint_32)65536L) * (png_uint_32)num_blocks+16;
table = farmalloc(total_size);
if (table == NULL)
{
# ifndef PNG_USER_MEM_SUPPORTED
if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
png_error(png_ptr, "Out Of Memory"); /* Note "O", "M" */
else
png_warning(png_ptr, "Out Of Memory");
# endif
return (NULL);
}
if ((png_size_t)table & 0xfff0)
{
# ifndef PNG_USER_MEM_SUPPORTED
if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
png_error(png_ptr,
"Farmalloc didn't return normalized pointer");
else
png_warning(png_ptr,
"Farmalloc didn't return normalized pointer");
# endif
return (NULL);
}
png_ptr->offset_table = table;
png_ptr->offset_table_ptr = farmalloc(num_blocks *
png_sizeof(png_bytep));
if (png_ptr->offset_table_ptr == NULL)
{
# ifndef PNG_USER_MEM_SUPPORTED
if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
png_error(png_ptr, "Out Of memory"); /* Note "O", "m" */
else
png_warning(png_ptr, "Out Of memory");
# endif
return (NULL);
}
hptr = (png_byte huge *)table;
if ((png_size_t)hptr & 0xf)
{
hptr = (png_byte huge *)((long)(hptr) & 0xfffffff0L);
hptr = hptr + 16L; /* "hptr += 16L" fails on Turbo C++ 3.0 */
}
for (i = 0; i < num_blocks; i++)
{
png_ptr->offset_table_ptr[i] = (png_bytep)hptr;
hptr = hptr + (png_uint_32)65536L; /* "+=" fails on TC++3.0 */
}
png_ptr->offset_table_number = num_blocks;
png_ptr->offset_table_count = 0;
png_ptr->offset_table_count_free = 0;
}
}
if (png_ptr->offset_table_count >= png_ptr->offset_table_number)
{
# ifndef PNG_USER_MEM_SUPPORTED
if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
png_error(png_ptr, "Out of Memory"); /* Note "O" and "M" */
else
png_warning(png_ptr, "Out of Memory");
# endif
return (NULL);
}
ret = png_ptr->offset_table_ptr[png_ptr->offset_table_count++];
}
else
ret = farmalloc(size);
# ifndef PNG_USER_MEM_SUPPORTED
if (ret == NULL)
{
if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
png_error(png_ptr, "Out of memory"); /* Note "o" and "m" */
else
png_warning(png_ptr, "Out of memory"); /* Note "o" and "m" */
}
# endif
return (ret);
}
/* Free a pointer allocated by png_malloc(). In the default
* configuration, png_ptr is not used, but is passed in case it
* is needed. If ptr is NULL, return without taking any action.
*/
void PNGAPI
png_free(png_structp png_ptr, png_voidp ptr)
{
if (png_ptr == NULL || ptr == NULL)
return;
# ifdef PNG_USER_MEM_SUPPORTED
if (png_ptr->free_fn != NULL)
{
(*(png_ptr->free_fn))(png_ptr, ptr);
return;
}
else
png_free_default(png_ptr, ptr);
}
void PNGAPI
png_free_default(png_structp png_ptr, png_voidp ptr)
{
# endif /* PNG_USER_MEM_SUPPORTED */
if (png_ptr == NULL || ptr == NULL)
return;
if (png_ptr->offset_table != NULL)
{
int i;
for (i = 0; i < png_ptr->offset_table_count; i++)
{
if (ptr == png_ptr->offset_table_ptr[i])
{
ptr = NULL;
png_ptr->offset_table_count_free++;
break;
}
}
if (png_ptr->offset_table_count_free == png_ptr->offset_table_count)
{
farfree(png_ptr->offset_table);
farfree(png_ptr->offset_table_ptr);
png_ptr->offset_table = NULL;
png_ptr->offset_table_ptr = NULL;
}
}
if (ptr != NULL)
farfree(ptr);
}
#else /* Not the Borland DOS special memory handler */
/* Allocate memory for a png_struct or a png_info. The malloc and /* 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 memset can be replaced by a single call to calloc() if this is thought
to improve performance noticably. */ to improve performance noticably. */
@ -612,7 +261,6 @@ png_free_default(png_structp png_ptr, png_voidp ptr)
# endif # endif
# endif # endif
} }
#endif /* Not Borland DOS special memory handler */
/* This function was added at libpng version 1.2.3. The png_malloc_warn() /* This function was added at libpng version 1.2.3. The png_malloc_warn()
* function will set up png_malloc() to issue a png_warning and return NULL * function will set up png_malloc() to issue a png_warning and return NULL

View File

@ -1204,20 +1204,20 @@ png_read_push_finish_row(png_structp png_ptr)
/* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */ /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
/* Start of interlace block */ /* Start of interlace block */
static PNG_CONST png_byte FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; static PNG_CONST png_byte png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
/* Offset to next interlace block */ /* Offset to next interlace block */
static PNG_CONST png_byte FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; static PNG_CONST png_byte png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
/* Start of interlace block in the y direction */ /* Start of interlace block in the y direction */
static PNG_CONST png_byte FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1}; static PNG_CONST png_byte png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
/* Offset to next interlace block in the y direction */ /* Offset to next interlace block in the y direction */
static PNG_CONST png_byte FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2}; static PNG_CONST png_byte png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
/* Height of interlace block. This is not currently used - if you need /* Height of interlace block. This is not currently used - if you need
* it, uncomment it here and in png.h * it, uncomment it here and in png.h
static PNG_CONST png_byte FARDATA png_pass_height[] = {8, 8, 4, 4, 2, 2, 1}; static PNG_CONST png_byte png_pass_height[] = {8, 8, 4, 4, 2, 2, 1};
*/ */
png_ptr->row_number++; png_ptr->row_number++;

View File

@ -39,13 +39,9 @@
*/ */
#define _POSIX_SOURCE 1 /* Just the POSIX 1003.1 and C89 APIs */ #define _POSIX_SOURCE 1 /* Just the POSIX 1003.1 and C89 APIs */
/* This is required for the definition of abort(), used as a last ditch /* Standard library headers not required by png.h: */
* error handler when all else fails.
*/
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
/* This is used to find 'offsetof', used below for alignment tests. */
#include <stddef.h>
#define PNGLIB_BUILD /*libpng is being built, not used*/ #define PNGLIB_BUILD /*libpng is being built, not used*/
@ -136,7 +132,7 @@
/* This is used for 16 bit gamma tables - only the top level pointers are const, /* This is used for 16 bit gamma tables - only the top level pointers are const,
* this could be changed: * this could be changed:
*/ */
typedef PNG_CONST png_uint_16p FAR * png_const_uint_16pp; typedef const png_uint_16p * png_const_uint_16pp;
/* Added at libpng-1.2.9 */ /* Added at libpng-1.2.9 */
/* Moved to pngpriv.h at libpng-1.5.0 */ /* Moved to pngpriv.h at libpng-1.5.0 */
@ -347,33 +343,14 @@ typedef PNG_CONST png_uint_16p FAR * png_const_uint_16pp;
# endif # endif
#endif #endif
#ifdef USE_FAR_KEYWORD /* Prior to 1.6.0 if _WINDOWS_ was defined 'lstrlenA' and 'CopyMemory' were used
/* Use this to make far-to-near assignments */ * in place of the ISOC90 functions, this is no longer done in 1.6.0, however
# define CHECK 1 * the use of png_foo as a macro defined to the C function is retained.
# define NOCHECK 0 */
# define CVT_PTR(ptr) (png_far_to_near(png_ptr,ptr,CHECK))
# define CVT_PTR_NOCHECK(ptr) (png_far_to_near(png_ptr,ptr,NOCHECK))
# define png_strlen _fstrlen
# define png_memcmp _fmemcmp /* SJT: added */
# define png_memcpy _fmemcpy
# define png_memset _fmemset
#else
# ifdef _WINDOWS_ /* Favor Windows over C runtime fns */
# define CVT_PTR(ptr) (ptr)
# define CVT_PTR_NOCHECK(ptr) (ptr)
# define png_strlen lstrlenA
# define png_memcmp memcmp
# define png_memcpy CopyMemory
# define png_memset memset
# else
# define CVT_PTR(ptr) (ptr)
# define CVT_PTR_NOCHECK(ptr) (ptr)
#define png_strlen strlen #define png_strlen strlen
# define png_memcmp memcmp /* SJT: added */ #define png_memcmp memcmp
#define png_memcpy memcpy #define png_memcpy memcpy
#define png_memset memset #define png_memset memset
# endif
#endif
/* These macros may need to be architecture dependent. */ /* These macros may need to be architecture dependent. */
#define PNG_ALIGN_NONE 0 /* do not use data alignment */ #define PNG_ALIGN_NONE 0 /* do not use data alignment */
@ -1402,11 +1379,6 @@ PNG_EXTERN void png_read_destroy PNGARG((png_structp png_ptr,
/* Free any memory used in png_ptr struct (old method - NOT DLL EXPORTED) */ /* Free any memory used in png_ptr struct (old method - NOT DLL EXPORTED) */
PNG_EXTERN void png_write_destroy PNGARG((png_structp png_ptr)); PNG_EXTERN void png_write_destroy PNGARG((png_structp png_ptr));
#ifdef USE_FAR_KEYWORD /* memory model conversion function */
PNG_EXTERN void *png_far_to_near PNGARG((png_structp png_ptr, png_voidp ptr,
int check));
#endif /* USE_FAR_KEYWORD */
#if defined(PNG_FLOATING_POINT_SUPPORTED) && defined(PNG_ERROR_TEXT_SUPPORTED) #if defined(PNG_FLOATING_POINT_SUPPORTED) && defined(PNG_ERROR_TEXT_SUPPORTED)
PNG_EXTERN PNG_FUNCTION(void, png_fixed_error, (png_structp png_ptr, PNG_EXTERN PNG_FUNCTION(void, png_fixed_error, (png_structp png_ptr,
png_const_charp name),PNG_NORETURN); png_const_charp name),PNG_NORETURN);

View File

@ -48,12 +48,6 @@ png_create_read_struct_2,(png_const_charp user_png_ver, png_voidp error_ptr,
png_structp png_ptr; png_structp png_ptr;
volatile int png_cleanup_needed = 0; volatile int png_cleanup_needed = 0;
#ifdef PNG_SETJMP_SUPPORTED
#ifdef USE_FAR_KEYWORD
jmp_buf tmp_jmpbuf;
#endif
#endif
png_debug(1, "in png_create_read_struct"); png_debug(1, "in png_create_read_struct");
#ifdef PNG_USER_MEM_SUPPORTED #ifdef PNG_USER_MEM_SUPPORTED
@ -86,15 +80,8 @@ png_create_read_struct_2,(png_const_charp user_png_ver, png_voidp error_ptr,
* encounter a png_error() will longjmp here. Since the jmpbuf is * encounter a png_error() will longjmp here. Since the jmpbuf is
* then meaningless we abort instead of returning. * then meaningless we abort instead of returning.
*/ */
#ifdef USE_FAR_KEYWORD
if (setjmp(tmp_jmpbuf))
#else
if (setjmp(png_jmpbuf(png_ptr))) /* Sets longjmp to match setjmp */ if (setjmp(png_jmpbuf(png_ptr))) /* Sets longjmp to match setjmp */
#endif
PNG_ABORT(); PNG_ABORT();
#ifdef USE_FAR_KEYWORD
png_memcpy(png_jmpbuf(png_ptr), tmp_jmpbuf, png_sizeof(jmp_buf));
#endif
#endif /* PNG_SETJMP_SUPPORTED */ #endif /* PNG_SETJMP_SUPPORTED */
#ifdef PNG_USER_MEM_SUPPORTED #ifdef PNG_USER_MEM_SUPPORTED
@ -1337,7 +1324,7 @@ png_image_read_init(png_imagep image)
if (control != NULL) if (control != NULL)
{ {
memset(control, 0, sizeof *control); png_memset(control, 0, sizeof *control);
control->png_ptr = png_ptr; control->png_ptr = png_ptr;
control->info_ptr = info_ptr; control->info_ptr = info_ptr;
@ -1520,7 +1507,7 @@ png_image_memory_read(png_structp png_ptr, png_bytep out, png_size_t need)
if (memory != NULL && size >= need) if (memory != NULL && size >= need)
{ {
memcpy(out, memory, need); png_memcpy(out, memory, need);
cp->memory = memory + need; cp->memory = memory + need;
cp->size = size - need; cp->size = size - need;
return; return;
@ -2437,7 +2424,7 @@ png_image_finish_read(png_imagep image, png_colorp background, void *buffer,
int result; int result;
png_image_read_control display; png_image_read_control display;
memset(&display, 0, sizeof display); png_memset(&display, 0, sizeof display);
display.image = image; display.image = image;
display.buffer = buffer; display.buffer = buffer;
display.row_stride = row_stride; display.row_stride = row_stride;

View File

@ -46,7 +46,6 @@ png_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
* read_data function and use it at run time with png_set_read_fn(), rather * read_data function and use it at run time with png_set_read_fn(), rather
* than changing the library. * than changing the library.
*/ */
# ifndef USE_FAR_KEYWORD
void PNGCBAPI void PNGCBAPI
png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length) png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
{ {
@ -58,68 +57,11 @@ png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
/* fread() returns 0 on error, so it is OK to store this in a png_size_t /* fread() returns 0 on error, so it is OK to store this in a png_size_t
* instead of an int, which is what fread() actually returns. * instead of an int, which is what fread() actually returns.
*/ */
check = fread(data, 1, length, (png_FILE_p)png_ptr->io_ptr); check = fread(data, 1, length, png_voidcast(png_FILE_p, png_ptr->io_ptr));
if (check != length) if (check != length)
png_error(png_ptr, "Read Error"); png_error(png_ptr, "Read Error");
} }
# else
/* This is the model-independent version. Since the standard I/O library
can't handle far buffers in the medium and small models, we have to copy
the data.
*/
#define NEAR_BUF_SIZE 1024
#define MIN(a,b) (a <= b ? a : b)
static void PNGCBAPI
png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
{
png_size_t check;
png_byte *n_data;
png_FILE_p io_ptr;
if (png_ptr == NULL)
return;
/* Check if data really is near. If so, use usual code. */
n_data = (png_byte *)CVT_PTR_NOCHECK(data);
io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
if ((png_bytep)n_data == data)
{
check = fread(n_data, 1, length, io_ptr);
}
else
{
png_byte buf[NEAR_BUF_SIZE];
png_size_t read, remaining, err;
check = 0;
remaining = length;
do
{
read = MIN(NEAR_BUF_SIZE, remaining);
err = fread(buf, 1, read, io_ptr);
png_memcpy(data, buf, read); /* copy far buffer to near buffer */
if (err != read)
break;
else
check += err;
data += read;
remaining -= read;
}
while (remaining != 0);
}
if ((png_uint_32)check != (png_uint_32)length)
png_error(png_ptr, "read Error");
}
# endif
#endif #endif
/* This function allows the application to supply a new input function /* This function allows the application to supply a new input function

View File

@ -370,12 +370,12 @@ png_set_alpha_mode(png_structp png_ptr, int mode, double output_gamma)
typedef struct png_dsort_struct typedef struct png_dsort_struct
{ {
struct png_dsort_struct FAR * next; struct png_dsort_struct * next;
png_byte left; png_byte left;
png_byte right; png_byte right;
} png_dsort; } png_dsort;
typedef png_dsort FAR * png_dsortp; typedef png_dsort * png_dsortp;
typedef png_dsort FAR * FAR * png_dsortpp; typedef png_dsort * * png_dsortpp;
void PNGAPI void PNGAPI
png_set_quantize(png_structp png_ptr, png_colorp palette, png_set_quantize(png_structp png_ptr, png_colorp palette,
@ -778,7 +778,6 @@ png_set_gamma_fixed(png_structp png_ptr, png_fixed_point scrn_gamma,
scrn_gamma = translate_gamma_flags(png_ptr, scrn_gamma, 1/*screen*/); scrn_gamma = translate_gamma_flags(png_ptr, scrn_gamma, 1/*screen*/);
file_gamma = translate_gamma_flags(png_ptr, file_gamma, 0/*file*/); file_gamma = translate_gamma_flags(png_ptr, file_gamma, 0/*file*/);
#if PNG_LIBPNG_VER >= 10600
/* Checking the gamma values for being >0 was added in 1.5.4 along with the /* Checking the gamma values for being >0 was added in 1.5.4 along with the
* premultiplied alpha support; this actually hides an undocumented feature * premultiplied alpha support; this actually hides an undocumented feature
* of the previous implementation which allowed gamma processing to be * of the previous implementation which allowed gamma processing to be
@ -787,14 +786,14 @@ png_set_gamma_fixed(png_structp png_ptr, png_fixed_point scrn_gamma,
* accept '0' for the gamma value it takes, because it isn't always used. * accept '0' for the gamma value it takes, because it isn't always used.
* *
* Since this is an API change (albeit a very minor one that removes an * Since this is an API change (albeit a very minor one that removes an
* undocumented API feature) it will not be made until libpng-1.6.0. * undocumented API feature) the following checks were only enabled in
* libpng-1.6.0.
*/ */
if (file_gamma <= 0) if (file_gamma <= 0)
png_error(png_ptr, "invalid file gamma in png_set_gamma"); png_error(png_ptr, "invalid file gamma in png_set_gamma");
if (scrn_gamma <= 0) if (scrn_gamma <= 0)
png_error(png_ptr, "invalid screen gamma in png_set_gamma"); png_error(png_ptr, "invalid screen gamma in png_set_gamma");
#endif
/* Set the gamma values unconditionally - this overrides the value in the PNG /* Set the gamma values unconditionally - this overrides the value in the PNG
* file if a gAMA chunk was present. png_set_alpha_mode provides a * file if a gAMA chunk was present. png_set_alpha_mode provides a

View File

@ -305,7 +305,7 @@ png_inflate(png_structp png_ptr, png_bytep data, png_size_t size,
* inside it is possible to chunk the input to zlib and simply rely on * inside it is possible to chunk the input to zlib and simply rely on
* zlib to advance the 'next_in' pointer. This allows arbitrary amounts o * zlib to advance the 'next_in' pointer. This allows arbitrary amounts o
* data to be passed through zlib at the unavoidable cost of requiring a * data to be passed through zlib at the unavoidable cost of requiring a
* window save (memcpy of up to 32768 output bytes) every ZLIB_IO_MAX * window save (png_memcpy of up to 32768 output bytes) every ZLIB_IO_MAX
* input bytes. * input bytes.
*/ */
if (png_ptr->zstream.avail_in == 0 && size > 0) if (png_ptr->zstream.avail_in == 0 && size > 0)

165
pngtest.c
View File

@ -67,17 +67,6 @@ typedef FILE * png_FILE_p;
# define SINGLE_ROWBUF_ALLOC /* Makes buffer overruns easier to nail */ # define SINGLE_ROWBUF_ALLOC /* Makes buffer overruns easier to nail */
#endif #endif
/* The code uses memcmp and memcpy on large objects (typically row pointers) so
* it is necessary to do soemthing special on certain architectures, note that
* the actual support for this was effectively removed in 1.4, so only the
* memory remains in this program:
*/
#define CVT_PTR(ptr) (ptr)
#define CVT_PTR_NOCHECK(ptr) (ptr)
#define png_memcmp memcmp
#define png_memcpy memcpy
#define png_memset memset
/* Turn on CPU timing /* Turn on CPU timing
#define PNGTEST_TIMING #define PNGTEST_TIMING
*/ */
@ -344,7 +333,6 @@ pngtest_check_io_state(png_structp png_ptr, png_size_t data_length,
} }
#endif #endif
#ifndef USE_FAR_KEYWORD
static void PNGCBAPI static void PNGCBAPI
pngtest_read_data(png_structp png_ptr, png_bytep data, png_size_t length) pngtest_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
{ {
@ -369,59 +357,6 @@ pngtest_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
pngtest_check_io_state(png_ptr, length, PNG_IO_READING); pngtest_check_io_state(png_ptr, length, PNG_IO_READING);
#endif #endif
} }
#else
/* This is the model-independent version. Since the standard I/O library
can't handle far buffers in the medium and small models, we have to copy
the data.
*/
#define NEAR_BUF_SIZE 1024
#define MIN(a,b) (a <= b ? a : b)
static void PNGCBAPI
pngtest_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
{
png_size_t check;
png_byte *n_data;
png_FILE_p io_ptr;
/* Check if data really is near. If so, use usual code. */
n_data = (png_byte *)CVT_PTR_NOCHECK(data);
io_ptr = (png_FILE_p)CVT_PTR(png_get_io_ptr(png_ptr));
if ((png_bytep)n_data == data)
{
check = fread(n_data, 1, length, io_ptr);
}
else
{
png_byte buf[NEAR_BUF_SIZE];
png_size_t read, remaining, err;
check = 0;
remaining = length;
do
{
read = MIN(NEAR_BUF_SIZE, remaining);
err = fread(buf, 1, 1, io_ptr);
png_memcpy(data, buf, read); /* Copy far buffer to near buffer */
if (err != read)
break;
else
check += err;
data += read;
remaining -= read;
}
while (remaining != 0);
}
if (check != length)
png_error(png_ptr, "Read Error");
#ifdef PNG_IO_STATE_SUPPORTED
pngtest_check_io_state(png_ptr, length, PNG_IO_READING);
#endif
}
#endif /* USE_FAR_KEYWORD */
#ifdef PNG_WRITE_FLUSH_SUPPORTED #ifdef PNG_WRITE_FLUSH_SUPPORTED
static void PNGCBAPI static void PNGCBAPI
@ -437,7 +372,6 @@ pngtest_flush(png_structp png_ptr)
* write_data function and use it at run time with png_set_write_fn(), rather * write_data function and use it at run time with png_set_write_fn(), rather
* than changing the library. * than changing the library.
*/ */
#ifndef USE_FAR_KEYWORD
static void PNGCBAPI static void PNGCBAPI
pngtest_write_data(png_structp png_ptr, png_bytep data, png_size_t length) pngtest_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
{ {
@ -454,63 +388,6 @@ pngtest_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
pngtest_check_io_state(png_ptr, length, PNG_IO_WRITING); pngtest_check_io_state(png_ptr, length, PNG_IO_WRITING);
#endif #endif
} }
#else
/* This is the model-independent version. Since the standard I/O library
can't handle far buffers in the medium and small models, we have to copy
the data.
*/
#define NEAR_BUF_SIZE 1024
#define MIN(a,b) (a <= b ? a : b)
static void PNGCBAPI
pngtest_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
{
png_size_t check;
png_byte *near_data; /* Needs to be "png_byte *" instead of "png_bytep" */
png_FILE_p io_ptr;
/* Check if data really is near. If so, use usual code. */
near_data = (png_byte *)CVT_PTR_NOCHECK(data);
io_ptr = (png_FILE_p)CVT_PTR(png_get_io_ptr(png_ptr));
if ((png_bytep)near_data == data)
{
check = fwrite(near_data, 1, length, io_ptr);
}
else
{
png_byte buf[NEAR_BUF_SIZE];
png_size_t written, remaining, err;
check = 0;
remaining = length;
do
{
written = MIN(NEAR_BUF_SIZE, remaining);
png_memcpy(buf, data, written); /* Copy far buffer to near buffer */
err = fwrite(buf, 1, written, io_ptr);
if (err != written)
break;
else
check += err;
data += written;
remaining -= written;
}
while (remaining != 0);
}
if (check != length)
{
png_error(png_ptr, "Write Error");
}
#ifdef PNG_IO_STATE_SUPPORTED
pngtest_check_io_state(png_ptr, length, PNG_IO_WRITING);
#endif
}
#endif /* USE_FAR_KEYWORD */
/* This function is called when there is a warning, but the library thinks /* This function is called when there is a warning, but the library thinks
* it can continue anyway. Replacement functions don't have to do anything * it can continue anyway. Replacement functions don't have to do anything
@ -563,9 +440,9 @@ typedef struct memory_information
{ {
png_alloc_size_t size; png_alloc_size_t size;
png_voidp pointer; png_voidp pointer;
struct memory_information FAR *next; struct memory_information *next;
} memory_information; } memory_information;
typedef memory_information FAR *memory_infop; typedef memory_information *memory_infop;
static memory_infop pinformation = NULL; static memory_infop pinformation = NULL;
static int current_allocation = 0; static int current_allocation = 0;
@ -621,7 +498,7 @@ PNGCBAPI png_debug_malloc(png_structp png_ptr, png_alloc_size_t size)
pinfo->next = pinformation; pinfo->next = pinformation;
pinformation = pinfo; pinformation = pinfo;
/* Make sure the caller isn't assuming zeroed memory. */ /* Make sure the caller isn't assuming zeroed memory. */
png_memset(pinfo->pointer, 0xdd, pinfo->size); memset(pinfo->pointer, 0xdd, pinfo->size);
if (verbose) if (verbose)
printf("png_malloc %lu bytes at %p\n", (unsigned long)size, printf("png_malloc %lu bytes at %p\n", (unsigned long)size,
@ -648,7 +525,7 @@ png_debug_free(png_structp png_ptr, png_voidp ptr)
/* Unlink the element from the list. */ /* Unlink the element from the list. */
{ {
memory_infop FAR *ppinfo = &pinformation; memory_infop *ppinfo = &pinformation;
for (;;) for (;;)
{ {
@ -662,7 +539,7 @@ png_debug_free(png_structp png_ptr, png_voidp ptr)
fprintf(STDERR, "Duplicate free of memory\n"); fprintf(STDERR, "Duplicate free of memory\n");
/* We must free the list element too, but first kill /* We must free the list element too, but first kill
the memory that is to be freed. */ the memory that is to be freed. */
png_memset(ptr, 0x55, pinfo->size); memset(ptr, 0x55, pinfo->size);
png_free_default(png_ptr, pinfo); png_free_default(png_ptr, pinfo);
pinfo = NULL; pinfo = NULL;
break; break;
@ -780,11 +657,6 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
png_uint_32 width, height; png_uint_32 width, height;
int num_pass, pass; int num_pass, pass;
int bit_depth, color_type; int bit_depth, color_type;
#ifdef PNG_SETJMP_SUPPORTED
#ifdef USE_FAR_KEYWORD
jmp_buf tmp_jmpbuf;
#endif
#endif
char inbuf[256], outbuf[256]; char inbuf[256], outbuf[256];
@ -850,11 +722,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
#ifdef PNG_SETJMP_SUPPORTED #ifdef PNG_SETJMP_SUPPORTED
pngtest_debug("Setting jmpbuf for read struct"); pngtest_debug("Setting jmpbuf for read struct");
#ifdef USE_FAR_KEYWORD
if (setjmp(tmp_jmpbuf))
#else
if (setjmp(png_jmpbuf(read_ptr))) if (setjmp(png_jmpbuf(read_ptr)))
#endif
{ {
fprintf(STDERR, "%s -> %s: libpng read error\n", inname, outname); fprintf(STDERR, "%s -> %s: libpng read error\n", inname, outname);
png_free(read_ptr, row_buf); png_free(read_ptr, row_buf);
@ -868,18 +736,11 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
FCLOSE(fpout); FCLOSE(fpout);
return (1); return (1);
} }
#ifdef USE_FAR_KEYWORD
png_memcpy(png_jmpbuf(read_ptr), tmp_jmpbuf, png_sizeof(jmp_buf));
#endif
#ifdef PNG_WRITE_SUPPORTED #ifdef PNG_WRITE_SUPPORTED
pngtest_debug("Setting jmpbuf for write struct"); pngtest_debug("Setting jmpbuf for write struct");
#ifdef USE_FAR_KEYWORD
if (setjmp(tmp_jmpbuf))
#else
if (setjmp(png_jmpbuf(write_ptr))) if (setjmp(png_jmpbuf(write_ptr)))
#endif
{ {
fprintf(STDERR, "%s -> %s: libpng write error\n", inname, outname); fprintf(STDERR, "%s -> %s: libpng write error\n", inname, outname);
png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr); png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr);
@ -891,10 +752,6 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
FCLOSE(fpout); FCLOSE(fpout);
return (1); return (1);
} }
#ifdef USE_FAR_KEYWORD
png_memcpy(png_jmpbuf(write_ptr), tmp_jmpbuf, png_sizeof(jmp_buf));
#endif
#endif #endif
#endif #endif
@ -1179,12 +1036,11 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
{ {
png_set_tIME(write_ptr, write_info_ptr, mod_time); png_set_tIME(write_ptr, write_info_ptr, mod_time);
#ifdef PNG_TIME_RFC1123_SUPPORTED #ifdef PNG_TIME_RFC1123_SUPPORTED
/* We have to use png_memcpy instead of "=" because the string /* We have to use memcpy instead of "=" because the string
* pointed to by png_convert_to_rfc1123() gets free'ed before * pointed to by png_convert_to_rfc1123() gets free'ed before
* we use it. * we use it.
*/ */
png_memcpy(tIME_string, memcpy(tIME_string, png_convert_to_rfc1123(read_ptr, mod_time),
png_convert_to_rfc1123(read_ptr, mod_time),
png_sizeof(tIME_string)); png_sizeof(tIME_string));
tIME_string[png_sizeof(tIME_string) - 1] = '\0'; tIME_string[png_sizeof(tIME_string) - 1] = '\0';
@ -1375,11 +1231,10 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
{ {
png_set_tIME(write_ptr, write_end_info_ptr, mod_time); png_set_tIME(write_ptr, write_end_info_ptr, mod_time);
#ifdef PNG_TIME_RFC1123_SUPPORTED #ifdef PNG_TIME_RFC1123_SUPPORTED
/* We have to use png_memcpy instead of "=" because the string /* We have to use memcpy instead of "=" because the string
pointed to by png_convert_to_rfc1123() gets free'ed before pointed to by png_convert_to_rfc1123() gets free'ed before
we use it */ we use it */
png_memcpy(tIME_string, memcpy(tIME_string, png_convert_to_rfc1123(read_ptr, mod_time),
png_convert_to_rfc1123(read_ptr, mod_time),
png_sizeof(tIME_string)); png_sizeof(tIME_string));
tIME_string[png_sizeof(tIME_string) - 1] = '\0'; tIME_string[png_sizeof(tIME_string) - 1] = '\0';
@ -1495,7 +1350,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
if (!num_in) if (!num_in)
break; break;
if (png_memcmp(inbuf, outbuf, num_in)) if (memcmp(inbuf, outbuf, num_in))
{ {
fprintf(STDERR, "\nFiles %s and %s are different\n", inname, outname); fprintf(STDERR, "\nFiles %s and %s are different\n", inname, outname);

View File

@ -46,7 +46,6 @@ png_write_data(png_structp png_ptr, png_const_bytep data, png_size_t length)
* write_data function and use it at run time with png_set_write_fn(), rather * write_data function and use it at run time with png_set_write_fn(), rather
* than changing the library. * than changing the library.
*/ */
#ifndef USE_FAR_KEYWORD
void PNGCBAPI void PNGCBAPI
png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length) png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
{ {
@ -60,64 +59,6 @@ png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
if (check != length) if (check != length)
png_error(png_ptr, "Write Error"); png_error(png_ptr, "Write Error");
} }
#else
/* This is the model-independent version. Since the standard I/O library
* can't handle far buffers in the medium and small models, we have to copy
* the data.
*/
#define NEAR_BUF_SIZE 1024
#define MIN(a,b) (a <= b ? a : b)
void PNGCBAPI
png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
{
png_uint_32 check;
png_byte *near_data; /* Needs to be "png_byte *" instead of "png_bytep" */
png_FILE_p io_ptr;
if (png_ptr == NULL)
return;
/* Check if data really is near. If so, use usual code. */
near_data = (png_byte *)CVT_PTR_NOCHECK(data);
io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
if ((png_bytep)near_data == data)
{
check = fwrite(near_data, 1, length, io_ptr);
}
else
{
png_byte buf[NEAR_BUF_SIZE];
png_size_t written, remaining, err;
check = 0;
remaining = length;
do
{
written = MIN(NEAR_BUF_SIZE, remaining);
png_memcpy(buf, data, written); /* Copy far buffer to near buffer */
err = fwrite(buf, 1, written, io_ptr);
if (err != written)
break;
else
check += err;
data += written;
remaining -= written;
}
while (remaining != 0);
}
if (check != length)
png_error(png_ptr, "Write Error");
}
#endif
#endif #endif
/* This function is called to output any data pending writing (normally /* This function is called to output any data pending writing (normally
@ -141,7 +82,7 @@ png_default_flush(png_structp png_ptr)
if (png_ptr == NULL) if (png_ptr == NULL)
return; return;
io_ptr = (png_FILE_p)CVT_PTR((png_ptr->io_ptr)); io_ptr = png_voidcast(png_FILE_p, (png_ptr->io_ptr));
fflush(io_ptr); fflush(io_ptr);
} }
# endif # endif
@ -219,36 +160,4 @@ png_set_write_fn(png_structp png_ptr, png_voidp io_ptr,
" same structure"); " same structure");
} }
} }
#ifdef USE_FAR_KEYWORD
# ifdef _MSC_VER
void *png_far_to_near(png_structp png_ptr, png_voidp ptr, int check)
{
void *near_ptr;
void FAR *far_ptr;
FP_OFF(near_ptr) = FP_OFF(ptr);
far_ptr = (void FAR *)near_ptr;
if (check != 0)
if (FP_SEG(ptr) != FP_SEG(far_ptr))
png_error(png_ptr, "segment lost in conversion");
return(near_ptr);
}
# else
void *png_far_to_near(png_structp png_ptr, png_voidp ptr, int check)
{
void *near_ptr;
void FAR *far_ptr;
near_ptr = (void FAR *)ptr;
far_ptr = (void FAR *)near_ptr;
if (check != 0)
if (far_ptr != ptr)
png_error(png_ptr, "segment lost in conversion");
return(near_ptr);
}
# endif
#endif
#endif /* PNG_WRITE_SUPPORTED */ #endif /* PNG_WRITE_SUPPORTED */

View File

@ -420,7 +420,7 @@ png_write_end(png_structp png_ptr, png_infop info_ptr)
#ifdef PNG_CONVERT_tIME_SUPPORTED #ifdef PNG_CONVERT_tIME_SUPPORTED
/* "tm" structure is not supported on WindowsCE */ /* "tm" structure is not supported on WindowsCE */
void PNGAPI void PNGAPI
png_convert_from_struct_tm(png_timep ptime, PNG_CONST struct tm FAR * ttime) png_convert_from_struct_tm(png_timep ptime, PNG_CONST struct tm * ttime)
{ {
png_debug(1, "in png_convert_from_struct_tm"); png_debug(1, "in png_convert_from_struct_tm");
@ -468,11 +468,6 @@ png_create_write_struct_2,(png_const_charp user_png_ver, png_voidp error_ptr,
volatile volatile
#endif #endif
png_structp png_ptr; png_structp png_ptr;
#ifdef PNG_SETJMP_SUPPORTED
#ifdef USE_FAR_KEYWORD
jmp_buf tmp_jmpbuf;
#endif
#endif
png_debug(1, "in png_create_write_struct"); png_debug(1, "in png_create_write_struct");
@ -496,14 +491,7 @@ png_create_write_struct_2,(png_const_charp user_png_ver, png_voidp error_ptr,
* encounter a png_error() will longjmp here. Since the jmpbuf is * encounter a png_error() will longjmp here. Since the jmpbuf is
* then meaningless we abort instead of returning. * then meaningless we abort instead of returning.
*/ */
#ifdef USE_FAR_KEYWORD
if (setjmp(tmp_jmpbuf))
#else
if (setjmp(png_jmpbuf(png_ptr))) /* sets longjmp to match setjmp */ if (setjmp(png_jmpbuf(png_ptr))) /* sets longjmp to match setjmp */
#endif
#ifdef USE_FAR_KEYWORD
png_memcpy(png_jmpbuf(png_ptr), tmp_jmpbuf, png_sizeof(jmp_buf));
#endif
PNG_ABORT(); PNG_ABORT();
#endif #endif
@ -1677,7 +1665,7 @@ png_image_write_init(png_imagep image)
if (control != NULL) if (control != NULL)
{ {
memset(control, 0, sizeof *control); png_memset(control, 0, sizeof *control);
control->png_ptr = png_ptr; control->png_ptr = png_ptr;
control->info_ptr = info_ptr; control->info_ptr = info_ptr;
@ -2127,7 +2115,7 @@ png_image_write_to_stdio(png_imagep image, FILE *file, int convert_to_8bit,
*/ */
image->opaque->png_ptr->io_ptr = file; image->opaque->png_ptr->io_ptr = file;
memset(&display, 0, sizeof display); png_memset(&display, 0, sizeof display);
display.image = image; display.image = image;
display.buffer = buffer; display.buffer = buffer;
display.row_stride = row_stride; display.row_stride = row_stride;

View File

@ -192,8 +192,8 @@ WVList
0 0
47 47
MItem MItem
16 33
..\..\pngvalid.c ..\..\contrib\libtests\pngvalid.c
48 48
WString WString
4 4

View File

@ -37,9 +37,9 @@ To use:
This project builds the libpng binaries as follows: This project builds the libpng binaries as follows:
* Win32_DLL_Release\libpng15.dll DLL build * Win32_DLL_Release\libpng16.dll DLL build
* Win32_DLL_Debug\libpng15d.dll DLL build (debug version) * Win32_DLL_Debug\libpng16d.dll DLL build (debug version)
* Win32_DLL_VB\libpng15vb.dll DLL build for Visual Basic, using stdcall * Win32_DLL_VB\libpng16vb.dll DLL build for Visual Basic, using stdcall
* Win32_LIB_Release\libpng.lib static build * Win32_LIB_Release\libpng.lib static build
* Win32_LIB_Debug\libpngd.lib static build (debug version) * Win32_LIB_Debug\libpngd.lib static build (debug version)

View File

@ -95,7 +95,7 @@
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>libpng15.lib;zlib.lib</AdditionalDependencies> <AdditionalDependencies>libpng16.lib;zlib.lib</AdditionalDependencies>
<AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories> <AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>
</Link> </Link>
<CustomBuildStep> <CustomBuildStep>
@ -128,7 +128,7 @@
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>libpng15.lib;zlib.lib</AdditionalDependencies> <AdditionalDependencies>libpng16.lib;zlib.lib</AdditionalDependencies>
<AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories> <AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>
</Link> </Link>
<CustomBuildStep> <CustomBuildStep>
@ -162,7 +162,7 @@
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding> <EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences> <OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>libpng15.lib;zlib.lib</AdditionalDependencies> <AdditionalDependencies>libpng16.lib;zlib.lib</AdditionalDependencies>
<AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories> <AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration> <LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
</Link> </Link>
@ -198,7 +198,7 @@
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding> <EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences> <OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>libpng15.lib;zlib.lib</AdditionalDependencies> <AdditionalDependencies>libpng16.lib;zlib.lib</AdditionalDependencies>
<AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories> <AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration> <LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
</Link> </Link>

View File

@ -210,7 +210,7 @@
</CustomBuildStep> </CustomBuildStep>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\..\..\pngvalid.c" /> <ClCompile Include="..\..\..\contrib\libtests\pngvalid.c" />
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">

View File

@ -1,7 +1,7 @@
VisualStudio instructions VisualStudio instructions
libpng version 1.6.0alpha01 - November 24, 2011 libpng version 1.6.0alpha01 - November 27, 2011
Copyright (c) 1998-2010 Glenn Randers-Pehrson Copyright (c) 1998-2010 Glenn Randers-Pehrson

View File

@ -2,7 +2,7 @@
<!-- <!--
* zlib.props - location of zlib source * zlib.props - location of zlib source
* *
* libpng version 1.6.0alpha01 - November 24, 2011 * libpng version 1.6.0alpha01 - November 27, 2011
* *
* Copyright (c) 1998-2011 Glenn Randers-Pehrson * Copyright (c) 1998-2011 Glenn Randers-Pehrson
* *