Compare commits

...

4 Commits

Author SHA1 Message Date
Glenn Randers-Pehrson
0f881d62b3 Imported from libpng-0.99c.tar 2009-04-06 16:04:13 -05:00
Glenn Randers-Pehrson
b212002101 Imported from libpng-0.99a.tar 2009-04-06 16:04:12 -05:00
Glenn Randers-Pehrson
46f61e2398 Imported from libpng-0.99.tar 2009-04-06 16:04:12 -05:00
Glenn Randers-Pehrson
c4a2ae6cac Imported from libpng-0.98.tar 2009-04-06 16:04:11 -05:00
31 changed files with 2650 additions and 572 deletions

58
CHANGES
View File

@@ -170,20 +170,58 @@ version 0.96 [May, 1997]
version 0.97 [January, 1998]
removed PNG_USE_OWN_CRC capability
relocated png_set_crc_action from pngrutil.c to pngrtran.c
fixed typecasts of "new_key", etc.
added RFC 1152 date support
fixed typecasts of "new_key", etc. (Andreas Dilger)
added RFC 1152 [sic] date support
fixed bug in gamma handling of 4-bit grayscale
added more typecasts. 65536L becomes (png_uint_32)65536L, etc.
added 2-bit grayscale gamma handling (Glenn R-P)
added more typecasts. 65536L becomes (png_uint_32)65536L, etc. (Glenn R-P)
minor corrections in libpng.txt
added simple sRGB support
make it simpler to do conditional compiling: PNG_READ_NOT_FULLY_SUPPORTED
fixed memory leak in pngwrite.c (free info_ptr->text)
added simple sRGB support (Glenn R-P)
easier conditional compiling, e.g. define PNG_READ/WRITE_NOT_FULLY_SUPPORTED;
all configurable options can be selected from command-line instead
of having to edit pngconf.h (Glenn R-P)
fixed memory leak in pngwrite.c (free info_ptr->text) (Glenn R-P)
added more conditions for png_do_background, to avoid changing
black pixels to background when a background is supplied and
no pixels are transparent
repaired PNG_NO_STDIO behaviour
tested NODIV support and made it default behaviour
added "-m" option to pngtest
[anything else? 2-bit grayscale gamma bug?]
tested NODIV support and made it default behaviour (Greg Roelofs)
added "-m" option and PNGTEST_DEBUG_MEMORY to pngtest (John Bowler)
regularized version numbering scheme and bumped shared-library major
version number to 2 to avoid potential problems with libpng 0.89 apps
version number to 2 to avoid problems with libpng 0.89 apps (Greg Roelofs)
version 0.98 [January, 1998]
cleaned up some typos in libpng.txt and in code documentation
fixed memory leaks in pCAL chunk processing (Glenn R-P and John Bowler)
cosmetic change "display_gamma" to "screen_gamma" in pngrtran.c
changed recommendation about file_gamma for PC images to .51 from .45,
in example.c and libpng.txt, added comments to distinguish between
screen_gamma, viewing_gamma, and display_gamma.
changed all references to RFC1152 to read RFC1123 and changed the
PNG_TIME_RFC1152_SUPPORTED macro to PNG_TIME_RFC1123_SUPPORTED
added png_invert_alpha capability (Glenn R-P -- suggestion by Jon Vincent)
changed srgb_intent from png_byte to int to avoid compiler bugs
version 0.99 [January 30, 1998]
free info_ptr->text instead of end_info_ptr->text in pngread.c (John Bowler)
fixed a longstanding "packswap" bug in pngtrans.c
fixed some inconsistencies in pngconf.h that prevented compiling with
PNG_READ_GAMMA_SUPPORTED and PNG_READ_hIST_SUPPORTED undefined
fixed some typos and made other minor rearrangement of libpng.txt (Andreas)
changed recommendation about file_gamma for PC images to .50 from .51 in
example.c and libpng.txt, and changed file_gamma for sRGB images to .45
added a number of functions to access information from the png structure
png_get_image_height(), etc. (Glenn R-P, suggestion by Brad Pettit)
added TARGET_MACOS similar to zlib-1.0.8
define PNG_ALWAYS_EXTERN when __MWERKS__ && WIN32 are defined
added type casting to all png_malloc() function calls
version 0.99a [January 31, 1998]
Added type casts and parentheses to all returns that return a value.(Tim W.)
version 0.99b [February 4, 1998]
Added type cast png_uint_32 on malloc function calls where needed.
Changed type of num_hist from png_uint_32 to int (same as num_palette).
Added checks for rowbytes overflow, in case png_size_t is less than 32 bits.
Renamed makefile.elf to makefile.lnx.
version 0.99c [February 7, 1998]
More type casting. Removed erroneous overflow test in pngmem.c.
Added png_buffered_memcpy() and png_buffered_memset(), apply them to rowbytes.
Added UNIX manual pages libpng.3, initially created by R. P. C. Rodgers,
U.S. National Library of Medicine (rodgers@nlm.nih.gov), and png.5.

36
README
View File

@@ -1,4 +1,4 @@
[NOTE: this is still beta version 0.97c; the text below has already
[NOTE: this is still beta version 0.99c; the text below has already
been updated in anticipation of the imminent 1.0 release.]
@@ -6,7 +6,7 @@ README for libpng 1.0
This is the first official release of libpng. Don't let the fact that
it's the first release fool you. The libpng library has been in
extensive use and testing for about two years. However, it's
extensive use and testing for about two and a half years. However, it's
finally gotten to the stage where there haven't been significant
changes to the API in some time, and people have a bad feeling about
libraries with versions < 1.0.
@@ -77,7 +77,7 @@ If not, it should be at ftp.uu.net in /graphics/png
Eventually, it will be at ftp.uu.net in /pub/archiving/zip/zlib
You may also want a copy of the PNG specification. It is available
as an Internet Draft, and RFC, and a W3C Recommendation. Failing
as an RFC and a W3C Recommendation. Failing
these resources you can try ftp.uu.net in the /graphics/png directory.
This code is currently being archived at ftp.uu.net in the
@@ -97,19 +97,19 @@ Finally, if you get any warning messages when compiling libpng
fix. Please mention "libpng" somewhere in the subject line. Thanks.
This release was created and will be supported by myself (of course
based in a large way on Guy's earlier work), and the PNG group.
based in a large way on Guy's and Andreas' earlier work), and the PNG group.
adilger@enel.ucalgary.ca
randeg@alumni.rpi.edu
png-implement@dworkin.wustl.edu
You can reach Guy, the original libpng author, at (internet preferred):
internet: schalnat@group42.com
CompuServe: 75501,1625
You can't reach Guy, the original libpng author, at the addresses
given in previous versions of this document. He and Andreas will read mail
addressed to the png-implement list, however.
Please do not send general questions about PNG. Send them to
the address in the specification. At the same time, please do
not send libpng questions to that address, send them to me. I'll
the address in the specification (png-group@w3.org). At the same
time, please do not send libpng questions to that address, send them to me
or to png-implement@dworkin.wustl.edu. I'll
get them in the end anyway. If you have a question about something
in the PNG specification that is related to using libpng, send it
to me. Send me any questions that start with "I was using libpng,
@@ -132,18 +132,20 @@ Files in this distribution:
descrip.mms => VMS project file
example.c => Example code for using libpng functions
libpng.txt => Description of libpng and its functions
makefile => Default Unixish makefile
makefile.aco => ACORN makefile
makefile.ama => Amiga makefile
makefile.atr => Atari makefile
makefile.bor => Borland makefile
makefile.dec => DEC makefile
makefile.dj2 => DJGPP 2 makefile
makefile.elf => Unix ELF makefile
makefile.knr => Makefile which calls ansi2knr to convert files
makefile.mip => MIPS makefile
makefile.msc => Microsoft C makefile
makefile.sgi => Silicon Graphics Irix makefile
makefile.std => Standard Unix makefile
makefile.tc => Turbo C makefile
makefile.sun => SUN makefile
makefile.tc3 => Turbo C 3.0 makefile
makevms.com => VMS make program
png.c => Basic interface functions common to library
png.h => Library function and interface declarations
@@ -166,13 +168,15 @@ Files in this distribution:
Good luck, and happy coding.
-Glenn Randers-Pehrson
Internet: randeg@alumni.rpi.edu
Web: http://www.rpi.edu/~randeg/index.html
-Andreas Eric Dilger
Internet: adilger@enel.ucalgary.ca
Web: http://www-mddsp.enel.ucalgary.ca/People/adilger/
-Guy Eric Schalnat
Group 42, Inc.
Internet: schalnat@group42.com
CompuServe: 75501,1625
(formerly of Group 42, Inc)
Web: http://www.group42.com/

2
TODO
View File

@@ -5,7 +5,7 @@ improved dithering
multi-lingual error and warning message support
sPLT chunk handling
cHRM transformation
complete sRGB transformation (presently it simply uses gamma=0.5)
complete sRGB transformation (presently it simply uses gamma=0.45)
man pages for function calls
high-level API for reading images
final bug fixes

View File

@@ -190,19 +190,22 @@ void read_png(FILE *fp, unsigned int sig_read) /* file is already open */
PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0);
/* Some suggestions as to how to get a screen gamma value */
/* Note that screen gamma is (display_gamma/viewing_gamma)
if (/* We have a user-defined screen gamma value */)
{
screen_gamma = user-defined screen_gamma;
}
/* This is one way that applications share the same screen gamma value */
else if ((gamma_str = getenv("DISPLAY_GAMMA")) != NULL)
else if ((gamma_str = getenv("SCREEN_GAMMA")) != NULL)
{
screen_gamma = atof(gamma_str);
}
/* If we don't have another value */
else
{
screen_gamma = 2.2; /* A good guess for PC monitors */
screen_gamma = 2.2; /* A good guess for a PC monitors in a dimly
lit room */
screen_gamma = 1.7 or 1.0; /* A good guess for Mac systems */
}
@@ -211,13 +214,16 @@ void read_png(FILE *fp, unsigned int sig_read) /* file is already open */
* by the user at run time by the user. It is strongly suggested that
* your application support gamma correction.
*/
if (png_get_sRGB(png_ptr, info_ptr, &srgb_intent)
png_set_sRGB(png_ptr, srgb_intent, 0);
int intent;
if (png_get_sRGB(png_ptr, info_ptr, &intent)
png_set_sRGB(png_ptr, intent, 0);
else
if (png_get_gAMA(png_ptr, info_ptr, &image_gamma)
png_set_gamma(png_ptr, screen_gamma, image_gamma);
else
png_set_gamma(png_ptr, screen_gamma, 0.45);
png_set_gamma(png_ptr, screen_gamma, 0.50);
/* Dither RGB files down to 8 bit palette or reduce palettes
* to the number of colors available on your screen.
@@ -249,7 +255,7 @@ void read_png(FILE *fp, unsigned int sig_read) /* file is already open */
}
/* invert monocrome files to have 0 as white and 1 as black */
png_set_invert(png_ptr);
png_set_invert_mono(png_ptr);
/* If you want to shift the pixel values from the range [0,255] or
* [0,65535] to the original [0,7] or [0,31], or whatever range the
@@ -543,7 +549,7 @@ void write_png(char *file_name, ... other image information ...)
PNG_INTERLACE_????, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
/* set the palette if there is one. REQUIRED for indexed-color images */
palette = png_malloc(png_ptr, 256 * sizeof (png_color));
palette = (png_colorp)png_malloc(png_ptr, 256 * sizeof (png_color));
... set palette colors ...
png_set_PLTE(png_ptr, info_ptr, palette, 256);
@@ -594,7 +600,7 @@ void write_png(char *file_name, ... other image information ...)
*/
/* invert monocrome pixels */
png_set_invert(png_ptr);
png_set_invert_mono(png_ptr);
/* Shift the pixels up to a legal bit depth and fill in
* as appropriate to correctly scale the image.

102
libpng.3 Normal file
View File

@@ -0,0 +1,102 @@
.TH PNG 5 "February 7, 1998"
.SH NAME
libpng \- Portable Network Graphics (PNG) format
.SH SYNOPSIS
[see
.I png.h
for full description]
.SH DESCRIPTION
The
.I libpng
library supports encoding, decoding, and various manipulations of
the Portable Network Graphics (PNG) format image files. It uses the
.IR zlib(3)
compression library.
.SH "SEE ALSO"
.IR libpng :
.IP
ftp://ftp.uu.net/graphics/png
http://www.cdrom.com/pub/png
.LP
.IR zlib :
.IP
(generally) at the same location as
.I libpng
or at
.br
ftp://ftp.uu.net/pub/archiving/zip/zlib
.br
http://www.cdrom.com/pub/infozip/zlib
.LP
PNG specification:
RFC 2083
.IP
(generally) at the same location as
.I libpng
or at
.br
ftp://ds.internic.net/rfc/rfc2083.txt
.br
or (as a W3C Recommendation) at
.br
http://www.w3.org/TR/REC-png.html
.SH AUTHORS
This man page: R. P. C. Rodgers and Glenn Randers-Pehrson
.LP
Libpng version 0.99c (February 7, 1998):
Initially created in 1995 by Guy Eric Schalnat, then of Group 42, Inc.
Currently maintained by Glenn Randers-Pehrson (randeg@alumni.rpi.edu).
.LP
Supported by the PNG development group
.br
(png-implement@dworkin.wustl.edu).
.LP
.SH COPYRIGHT NOTICE
Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
.br
Copyright (c) 1996, 1997 Andreas Dilger
.br
Copyright (c) 1998 Glenn Randers-Pehrson
.br
.LP
The PNG Reference Library is supplied "AS IS". The Contributing Authors
and Group 42, Inc. disclaim all warranties, expressed or implied,
including, without limitation, the warranties of merchantability and of
fitness for any purpose. The Contributing Authors and Group 42, Inc.
assume no liability for direct, indirect, incidental, special, exemplary,
or consequential damages, which may result from the use of the PNG
Reference Library, even if advised of the possibility of such damage.
.LP
Permission is hereby granted to use, copy, modify, and distribute this
source code, or portions hereof, for any purpose, without fee, subject
to the following restrictions:
.br
1. The origin of this source code must not be misrepresented.
.br
2. Altered versions must be plainly marked as such and must not be
misrepresented as being the original source.
.br
3. This Copyright notice may not be removed or altered from any source or
altered source distribution.
.br
.LP
The Contributing Authors and Group 42, Inc. specifically permit, without
fee, and encourage the use of this source code as a component to
supporting the PNG file format in commercial products. If you use this
source code in a product, acknowledgment is not required but would be
appreciated.
.LP
The
.IR zlib (3)
library, version 1.0.8,
is copyright (C) 1995-1998 by Jean-loup Gailly and Mark Adler.
.LP
.\" end of man page

View File

@@ -1,11 +1,14 @@
libpng.txt - a description on how to use and modify libpng
libpng version 1.00 version 0.97
libpng version 0.99c
Updated and distributed by Glenn Randers-Pehrson <randeg@alumni.rpi.edu>
Copyright (c) 1998, Glenn Randers-Pehrson
February 7, 1998
based on:
libpng version 1.00 version 0.96
Updated and distributed by Andreas Dilger <adilger@enel.ucalgary.ca>,
libpng 1.0 beta 6 version 0.96
Updated and distributed by Andreas Dilger
Copyright (c) 1996, 1997 Andreas Dilger
May 28, 1997
@@ -29,10 +32,10 @@ it is heavily commented and should include everything most people
will need.
Libpng was written as a companion to the PNG specification, as a way
to reduce the amount of time and effort it takes to support the PNG
of reducing the amount of time and effort it takes to support the PNG
file format in application programs. The PNG specification is available
as RFC 2083 <ftp://ftp.uu.net/graphics/png/documents/> and as a
W3C Recommendation <http://www.w3.org/pub/WWW/TR/REC.png.html>. Some
W3C Recommendation <http://www.w3.org/TR/REC.png.html>. Some
additional chunks are described in the special-purpose public chunks
documents at <ftp://ftp.uu.net/graphics/png/documents/>. Other information
about PNG can be found at the PNG home page, <http://www.cdrom.com/pub/png/>.
@@ -49,12 +52,14 @@ machines (ANSI, K&R, 16-, 32-, and 64-bit) available, and to be easy
to use. The ultimate goal of libpng is to promote the acceptance of
the PNG file format in whatever way possible. While there is still
work to be done (see the TODO file), libpng should cover the
majority of the needs of it's users.
majority of the needs of its users.
Libpng uses zlib for its compression and decompression of PNG files.
The zlib compression utility is a general purpose utility that is
useful for more than PNG files, and can be used without libpng.
See the documentation delivered with zlib for more details.
You can usually find the source files for the zlib utility wherever you
find the libpng source files.
Libpng is thread safe, provided the threads are using different
instances of the structures. Each thread should have its own
@@ -69,13 +74,15 @@ II. Structures
There are two main structures that are important to libpng, png_struct
and png_info. The first, png_struct, is an internal structure that
will not, for the most part, be used by a user except as the first
variable passed to every libpng function call.
variable passed to every libpng function call. It is not actually
used in many of the functions; do not be alarmed about compiler
warnings that say something to the effect that "png_ptr is not used."
The png_info structure is designed to provide information about the
PNG file. At one time, the fields of png_info were intended to be
directly accessible to the user. However, this tended to cause problems
with applications using dynamically loaded libraries, and as a result
a set of interface functions for png_info were delevoped. The fields
a set of interface functions for png_info was developed. The fields
of png_info are still available for older applications, but it is
suggested that applications use the new interfaces if at all possible.
@@ -193,6 +200,19 @@ libpng know that there are some bytes missing from the start of the file.
png_set_sig_bytes(png_ptr, number);
In PNG files, the alpha channel in an image is the level of opacity.
If you need the alpha channel in an image to be the level of transparency
instead of opacity, you can invert the alpha channel (or the tRNS chunk
data) after it's read, so that 0 is fully opaque and 255 (in 8-bit or
paletted images) or 65535 (in 16-bit images) is fully transparent, with
png_set_invert_alpha(png_ptr);
This has to appear here rather than later with the other transformations
because the tRNS chunk data must be modified in the case of paletted images.
If your image is not a paletted image, the tRNS data (which in such cases
represents a single color to be rendered as transparent) won't be changed.
You are now ready to read all the file information up to the actual
image data. You do this with a call to png_read_info().
@@ -219,9 +239,11 @@ Functions are used to get the information from the info_ptr:
PNG_COLOR_MASK_COLOR
PNG_COLOR_MASK_ALPHA
interlace_type - PNG_INTERLACE_TYPE_NONE or PNG_INTERLACE_TYPE_ADAM7
compression_type - (must be PNG_COMPRESSION_TYPE_BASE for PNG 1.0)
filter_type - (must be PNG_FILTER_TYPE_BASE for PNG 1.0)
compression_type - (must be PNG_COMPRESSION_TYPE_BASE for PNG 1.0)
interlace_type - (PNG_INTERLACE_TYPE_NONE or PNG_INTERLACE_TYPE_ADAM7)
Any or all of interlace_type, compression_type, of filter_type can be
NULL if you are not interested in their values.
channels = png_get_channels(png_ptr, info_ptr);
channels - number of channels of info for the color type
@@ -237,6 +259,17 @@ Functions are used to get the information from the info_ptr:
already read in 4 bytes of signature before staring
libpng, the remaining 4 bytes would be in signature[4]
through signature[7] (see png_set_sig_bytes())).
Information from each if the IHDR fields can be retrieve separately as well:
width = png_get_image_width(png_ptr, info_ptr);
height = png_get_image_height(png_ptr, info_ptr);
bit_depth = png_get_bit_depth(png_ptr, info_ptr);
color_type = png_get_color_type(png_ptr, info_ptr);
filter_type = png_get_filter_type(png_ptr, info_ptr);
compression_type = png_get_compression_type(png_ptr, info_ptr);
interlace_type = png_get_interlace_type(png_ptr, info_ptr);
These are also important, but their validity depends on whether the chunk
has been read. The png_get_valid(png_ptr, info_ptr, PNG_INFO_<chunk>) and
@@ -252,6 +285,12 @@ into the info_ptr is returned for any complex types.
png_get_gAMA(png_ptr, info_ptr, &gamma);
gamma - the gamma the file is written at (PNG_INFO_gAMA)
png_get_sRGB(png_ptr, info_ptr, &srgb_intent);
srgb_intent - the rendering intent (PNG_INFO_sRGB)
The presence of the sRGB chunk means that the pixel
data is in the sRGB color space. This chunk also
implies specific values of gAMA and cHRM.
png_get_sBIT(png_ptr, info_ptr, &sig_bit);
sig_bit - the number of significant bits for (PNG_INFO_sBIT)
the gray, red, green, and blue channels, whichever
@@ -290,6 +329,15 @@ into the info_ptr is returned for any complex types.
res_y - pixels/unit physical resolution in x direction
unit_type - PNG_RESOLUTION_UNKOWN, PNG_RESOLUTION_METER
The data from the pHYs chunk can be retrieved in several convenient
forms:
res_x_and_y = png_get_pixels_per_meter(png_ptr, info_ptr)
aspect_ratio = png_get_pixel_aspect_ratio(png_ptr, info_ptr)
(Each of these returns 0 [signifying "unknown"] if the data is not
present or if res_x is 0; res_x_and_y is 0 if res_x != res_y)
For more information, see the png_info definition in png.h and the
PNG specification for chunk contents. Be careful with trusting
rowbytes, as some of the transformations could increase the space
@@ -301,9 +349,9 @@ keyword/text pairs, one pair per chunk, with no limit on the number
of text chunks, and a 2^31 byte limit on their size. While there are
suggested keywords, there is no requirement to restrict the use to these
strings. It is strongly suggested that keywords and text be sensible
to humans (that's the point), so don't use abbreviations or non-printing
symbols. See the PNG specification for more details. There is also
no requirement to have text after the keyword.
to humans (that's the point), so don't use abbreviations. Non-printing
symbols are not allowed. See the PNG specification for more details.
There is also no requirement to have text after the keyword.
Keywords should be limited to 79 Latin-1 characters without leading or
trailing spaces, but non-consecutive spaces are allowed within the
@@ -366,8 +414,21 @@ PNG can have files with 16 bits per channel. If you only can handle
if (bit_depth == 16)
png_set_strip_16(png_ptr);
The png_set_background() function tells libpng to composite images
with alpha or simple transparency against the supplied background
color. If the PNG file contains a bKGD chunk (PNG_INFO_bKGD valid),
you may use this color, or supply another color more suitable for
the current display (e.g., the background color from a web page). You
need to tell libpng whether the color is in the gamma space of the
display (PNG_BACKGROUND_GAMMA_SCREEN for colors you supply), the file
(PNG_BACKGROUND_GAMMA_FILE for colors from the bKGD chunk), or one
that is neither of these gammas (PNG_BACKGROUND_GAMMA_UNIQUE - I don't
know why anyone would use this, but it's here).
If, for some reason, you don't need the alpha channel on an image,
and you want to remove it rather than combining it with the background:
and you want to remove it rather than combining it with the background
(but the image author certainly had in mind that you *would* combine
it with the background, so that's what you should probably do):
if (color_type & PNG_COLOR_MASK_ALPHA)
png_set_strip_alpha(png_ptr);
@@ -381,7 +442,7 @@ values of the pixels:
png_set_packing(png_ptr);
PNG files have possible bit depths of 1, 2, 4, 8, and 16. All pixels
stored in a PNG image whave been "scaled" or "shifted" up to the next
stored in a PNG image have been "scaled" or "shifted" up to the next
higher possible bit depth (eg from 5 bits/sample in the range [0,31] to
8 bits/sample in the range [0, 255]). However, it is also possible to
convert the PNG pixel data back to the original bit depth of the image.
@@ -423,17 +484,6 @@ RGB. This code will do that conversion:
color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
png_set_gray_to_rgb(png_ptr);
The png_set_background() function tells libpng to composite images
with alpha or simple transparency against the supplied background
color. If the PNG file contains a bKGD chunk (PNG_INFO_bKGD valid),
you may use this color, or supply another color more suitable for
the current display (e.g., the background color from a web page). You
need to tell libpng whether the color is in the gamma space of the
dispay (PNG_BACKGROUND_GAMMA_SCREEN for colors you supply), the file
(PNG_BACKGROUND_GAMMA_FILE for colors from the bKGD chunk), or one
that is neither of these gammas (PNG_BACKGROUND_GAMMA_UNIQUE - I don't
know why anyone would use this, but it's here).
If you have a grayscale and you are using png_set_expand() to change to
a higher bit-depth you must indicate if the supplied background gray
is supplied in the original file bit depth (need_expand = 1) or in the
@@ -457,28 +507,40 @@ To properly display PNG images on any kind of system, the application needs
to know what the display gamma is. Ideally, the user will know this, and
the application will allow them to set it. One method of allowing the user
to set the display gamma separately for each system is to check for the
DISPLAY_GAMMA environment variable, which will hopefully be correctly set.
DISPLAY_GAMMA and VIEWING_GAMMA environment variables or for a SCREEN_GAMMA
environment variable, which will hopefully be correctly set.
Note that display_gamma is the gamma of your display, while screen_gamma is
the overall gamma correction required to produce pleasing results,
which depends on the lighting conditions in the surrounding environment.
Screen_gamma is display_gamma/viewing_gamma, where viewing_gamma is
the amount of additional gamma correction needed to compensate for
a dim (viewing_gamma=1.125) or dark (viewing_gamma=1.25) environment.
In a brightly lit room, no compensation other than the display_gamma
is needed (viewing_gamma=1.0).
if (/* We have a user-defined screen gamma value */)
{
screen_gamma = user_defined_screen_gamma;
}
/* One way that applications can share the same screen gamma value */
else if ((gamma_str = getenv("DISPLAY_GAMMA")) != NULL)
else if ((gamma_str = getenv("SCREEN_GAMMA")) != NULL)
{
screen_gamma = atof(gamma_str);
}
/* If we don't have another value */
else
{
screen_gamma = 2.2; /* A good guess for PC monitors */
screen_gamma = 2.5; /* A good guess for a PC monitor in a bright office */
screen_gamma = 2.2; /* A good guess for a PC monitor in a dim room */
screen_gamma = 2.0; /* A good guess for a PC monitor in a dark room */
screen_gamma = 1.7 or 1.0; /* A good guess for Mac systems */
}
The png_set_gamma() function handles gamma transformations of the data.
Pass both the file gamma and the current screen_gamma. If the file does
not have a gamma value, you can pass one anyway if you have an idea what
it is (usually 0.45 is a good guess for GIF images on PCs). Note
it is (usually 0.50 is a good guess for GIF images on PCs). Note
that file gammas are inverted from screen gammas. See the discussions
on gamma in the PNG specification for an excellent description of what
gamma is, and why all applications should support it. It is strongly
@@ -487,7 +549,7 @@ recommended that PNG viewers support gamma correction.
if (png_get_gAMA(png_ptr, info_ptr, &gamma))
png_set_gamma(png_ptr, screen_gamma, gamma);
else
png_set_gamma(png_ptr, screen_gamma, 0.45);
png_set_gamma(png_ptr, screen_gamma, 0.50);
If you need to reduce an RGB file to a paletted file, or if a paletted
file has more entries then will fit on your screen, png_set_dither()
@@ -542,15 +604,16 @@ need to change the order the pixels are packed into bytes, you can use:
png_set_packswap(png_ptr);
The last thing to handle is interlacing; this is covered in detail below,
but you must call the function here.
but you must call the function here if you want libpng to handle expansion
of the interlaced image.
number_passes = png_set_interlace_handling(png_ptr);
number_of_passes = png_set_interlace_handling(png_ptr);
After setting the transformations, libpng can update your png_info
structure to reflect any transformations you've requested with this
call. This is most useful to update the info structure's rowbytes
field so you can use it to allocate your image memory. This function
will also update your palette with the correct display gamma and
will also update your palette with the correct screen_gamma and
background if these have been given with the calls above.
png_read_update_info(png_ptr, info_ptr);
@@ -582,7 +645,7 @@ where row_pointers is:
You can point to void or char or whatever you use for pixels.
If you don't want to read int the whole image at once, you can
If you don't want to read in the whole image at once, you can
use png_read_rows() instead. If there is no interlacing (check
interlace_type == PNG_INTERLACE_TYPE_NONE), this is simple:
@@ -599,24 +662,24 @@ row_pointers:
If the file is interlaced (info_ptr->interlace_type != 0), things get
somewhat harder. The only current (PNG Specification version 1.0)
interlacing type for PNG is (interlace_type == PNG_INTERLACE_TYPE_ADAM7)
is a someewhat complicated 2D interlace scheme, known as Adam7, that
is a somewhat complicated 2D interlace scheme, known as Adam7, that
breaks down an image into seven smaller images of varying size, based
on an 8x8 grid.
libpng can fill out those images or it can give them to you "as is".
If you want them filled out, there are two ways to do that. The one
mentioned in the PNG specification is to expand each pixel to cover
those pixels that have not been read yet. This results in a blocky
image for the first pass, which gradually smoothes out as more pixels
are read. The other method is the "sparkle" method, where pixels are
draw only in their final locations, with the rest of the image remaining
whatever colors they were initialized to before the start of the read.
The first method usually looks better, but tends to be slower, as there
are more pixels to put in the rows.
those pixels that have not been read yet (the "rectangle" method).
This results in a blocky image for the first pass, which gradually
smooths out as more pixels are read. The other method is the "sparkle"
method, where pixels are drawn only in their final locations, with the
rest of the image remaining whatever colors they were initialized to
before the start of the read. The first method usually looks better,
but tends to be slower, as there are more pixels to put in the rows.
If you don't want libpng to handle the interlacing details, just call
png_read_rows() seven times to read in all seven images. Each of the
images are valid images by themselves, or they can be combined on an
images is a valid image by itself, or they can all be combined on an
8x8 grid to form a single image (although if you intend to combine them
you would be far better off using the libpng interlace handling).
@@ -638,7 +701,7 @@ If you want libpng to expand the images, call this before calling
png_start_read_image() or png_read_update_info():
if (interlace_type == PNG_INTERLACE_TYPE_ADAM7)
number_passes = png_set_interlace_handling(png_ptr);
number_of_passes = png_set_interlace_handling(png_ptr);
This will return the number of passes needed. Currently, this
is seven, but may change if another interlace type is added.
@@ -649,12 +712,12 @@ If you are not going to display the image after each pass, but are
going to wait until the entire image is read in, use the sparkle
effect. This effect is faster and the end result of either method
is exactly the same. If you are planning on displaying the image
after each pass, the rectangle effect is generally considered the
after each pass, the "rectangle" effect is generally considered the
better looking one.
If you only want the "sparkle" effect, just call png_read_rows() as
normal, with the third parameter NULL. Make sure you make pass over
the image number_passes times, and you don't change the data in the
the image number_of_passes times, and you don't change the data in the
rows between calls. You can change the locations of the data, just
not the data. Each pass only writes the pixels appropriate for that
pass, and assumes the data from previous passes is still valid.
@@ -933,7 +996,7 @@ contain, see the PNG specification.
Some of the more important parts of the png_info are:
png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth, color_type,
interlace_type,
interlace_type, compression_type, filter_type)
width - holds the width of the image in pixels (up to 2^31).
height - holds the height of the image in pixels (up to 2^31).
bit_depth - holds the bit depth of one of the image channels.
@@ -950,11 +1013,9 @@ Some of the more important parts of the png_info are:
PNG_COLOR_MASK_COLOR
PNG_COLOR_MASK_ALPHA
interlace_type - PNG_INTERLACE_TYPE_NONE or PNG_INTER_LACE_TYPE_ADAM7
interlace_type - PNG_INTERLACE_TYPE_NONE or PNG_INTERLACE_TYPE_ADAM7
compression_type - (must be PNG_COMPRESSION_TYPE_DEFAULT for PNG 1.0)
filter_type - (must be PNG_FILTER_TYPE_DEFAULT for PNG 1.0)
Any or all of interlace_type, compression_type, of filter_type can be
NULL if you are not interested in their values.
png_set_PLTE(png_ptr, info_ptr, palette, num_palette);
palette - the palette for the file (array of png_color)
@@ -963,6 +1024,25 @@ Some of the more important parts of the png_info are:
png_set_gAMA(png_ptr, info_ptr, gamma);
gamma - the gamma the image was created at (PNG_INFO_gAMA)
png_set_sRGB(png_ptr, info_ptr, srgb_intent);
srgb_intent - the rendering intent (PNG_INFO_sRGB)
The presence of the sRGB chunk means that the pixel
data is in the sRGB color space. This chunk also
implies specific values of gAMA and cHRM.
Rendering intent is the CSS-1 property that has been
defined by the International Color Consortium
(http://www.color.org). It can be one of
PNG_SRGB_INTENT_SATURATION, PNG_SRGB_INTENT_PERCEPTUAL,
PNG_SRGB_INTENT_ABSOLUTE, or PNG_SRGB_INTENT_RELATIVE.
png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr, srgb_intent);
srgb_intent - the rendering intent (PNG_INFO_sRGB)
The presence of the sRGB chunk means that the pixel
data is in the sRGB color space. This chunk also
causes gAMA and cHRM chunks with the specific values
that are consistent with sRGB to be written.
png_set_sBIT(png_ptr, info_ptr, sig_bit);
sig_bit - the number of significant bits for (PNG_INFO_sBIT)
the gray, red, green, and blue channels, whichever
@@ -996,11 +1076,25 @@ Some of the more important parts of the png_info are:
offset_y - positive offset from the top edge of the screen
unit_type - PNG_OFFSET_PIXEL, PNG_OFFSET_MICROMETER
png_get_pHYs(png_ptr, info_ptr, res_x, res_y, unit_type);
png_set_pHYs(png_ptr, info_ptr, res_x, res_y, unit_type);
res_x - pixels/unit physical resolution in x direction
res_y - pixels/unit physical resolution in x direction
unit_type - PNG_RESOLUTION_UNKOWN, PNG_RESOLUTION_METER
In PNG files, the alpha channel in an image is the level of opacity.
If your data is supplied as a level of transparency, you can invert the
alpha channel before you write it, so that 0 is fully transparent and 255
(in 8-bit or paletted images) or 65535 (in 16-bit images) is fully opaque,
with
png_set_invert_alpha(png_ptr);
This must appear here instead of later with the other transformations
because in the case of paletted images the tRNS chunk data has to
be inverted before the tRNS chunk is written. If your image is not a
paletted image, the tRNS data (which in such cases represents a single
color to be rendered as transparent) won't be changed.
A quick word about text and num_text. text is an array of png_text
structures. num_text is the number of valid structures in the array.
If you want, you can use max_text to hold the size of the array, but
@@ -1072,8 +1166,8 @@ tEXt chunk use RFC 1123 format dates (eg 22 May 1997 18:07:10 GMT"),
although this isn't a requirement. Unlike the tIME chunk, the
"Creation Time" tEXt chunk is not expected to be automatically changed
by the software. To facilitate the use of RFC 1123 dates, a function
png_convert_to_rfc1152(png_timep) is provided to convert from PNG
time to an RFC 1152 format string.
png_convert_to_rfc1123(png_timep) is provided to convert from PNG
time to an RFC 1123 format string.
You are now ready to write all the file information up to the actual
image data. You do this with a call to png_write_info().
@@ -1158,7 +1252,7 @@ PNG files describe monochrome as black being zero and white being
one. This code would be used if the pixels are supplied with this reversed
(black being one and white being zero):
png_set_invert(png_ptr);
png_set_invert_mono(png_ptr);
It is possible to have libpng flush any pending output, either manually,
or automatically after a certain number of lines have been written. To
@@ -1229,12 +1323,12 @@ correct number of times to write all seven sub-images.
If you want libpng to build the sub-images, call this before you start
writing any rows:
number_passes = png_set_interlace_handling(png_ptr);
number_of_passes = png_set_interlace_handling(png_ptr);
This will return the number of passes needed. Currently, this
is seven, but may change if another interlace type is added.
Then write the complete image number_passes times.
Then write the complete image number_of_passes times.
png_write_rows(png_ptr, row_pointers, number_of_rows);
@@ -1244,8 +1338,8 @@ and only update the rows that are actually used.
After you are finished writing the image, you should finish writing
the file. If you are interested in writing comments or time, you should
pass the an appropriately filled png_info pointer. If you
are not interested, you can pass NULL.
pass an appropriately filled png_info pointer. If you are not interested,
you can pass NULL.
png_write_end(png_ptr, info_ptr);
@@ -1280,7 +1374,7 @@ MAXSEG_64K in zlib.h. Since it is unlikely that the method of handling
memory allocation on a platform will change between applications, these
functions must be modified in the library at compile time.
Input/Output in libpng is done throught png_read() and png_write(),
Input/Output in libpng is done through png_read() and png_write(),
which currently just call fread() and fwrite(). The FILE * is stored in
png_struct and is initialized via png_init_io(). If you wish to change
the method of I/O, the library supplies callbacks that you can set
@@ -1378,7 +1472,7 @@ call. See zlib.h or zconf.h in the zlib library for more information.
Configuring for Medium Model:
Libpng's support for medium model has been tested on most of the popular
complers. Make sure MAXSEG_64K gets defined, USE_FAR_KEYWORD gets
compilers. Make sure MAXSEG_64K gets defined, USE_FAR_KEYWORD gets
defined, and FAR gets defined to far in pngconf.h, and you should be
all set. Everything in the library (except for zlib's structure) is
expecting far data. You must use the typedefs with the p or pp on
@@ -1410,8 +1504,8 @@ most useful one changes the compression level, which currently uses
input compression values in the range 0 - 9. The library normally
uses the default compression level (Z_DEFAULT_COMPRESSION = 6). Tests
have shown that for a large majority of images, compression values in
the range 3-6 compress as well as higher levels, and do so much faster.
For online applications it may be desirable to have maximum speed
the range 3-6 compress nearly as well as higher levels, and do so much
faster. For online applications it may be desirable to have maximum speed
(Z_BEST_SPEED = 1). With versions of zlib after v0.99, you can also
specify no compression (Z_NO_COMPRESSION = 0), but this would create
files larger than just storing the raw bitmap. You can specify the
@@ -1437,14 +1531,19 @@ Controlling row filtering:
If you want to control whether libpng uses filtering or not, which
filters are used, and how it goes about picking row filters, you
can call one of these functions. Filtering is enabled by default for
RGB and grayscale images (with and without alpha), and for 8-bit
paletted images, but not for paletted images with bit depths less
than 8 bits/pixel. The 'method' parameter sets the main filtering
method, which is currently only '0' in the PNG 1.0 specification.
The 'filters' parameter sets which filter(s), if any, should be
used for each scanline. Possible values are PNG_ALL_FILTERS and
PNG_NO_FILTERS to turn filtering on and off, respectively.
can call one of these functions. The selection and configuration
of row filters can have a significant impact on the size and
encoding speed and a somewhat lesser impact on the decoding speed
of an image. Filtering is enabled by default for RGB and grayscale
images (with and without alpha), and for 8-bit paletted images, but
not for paletted images with bit depths less than 8 bits/pixel.
The 'method' parameter sets the main filtering method, which is
currently only '0' in the PNG 1.0 specification. The 'filters'
parameter sets which filter(s), if any, should be used for each
scanline. Possible values are PNG_ALL_FILTERS and PNG_NO_FILTERS
to turn filtering on and off, respectively.
Individual filter types are PNG_FILTER_NONE, PNG_FILTER_SUB,
PNG_FILTER_UP, PNG_FILTER_AVG, PNG_FILTER_PAETH, which can be bitwise
ORed together '|' to specify one or more filters to use. These
@@ -1495,8 +1594,18 @@ Removing unwanted object code:
There are a bunch of #define's in pngconf.h that control what parts of
libpng are compiled. All the defines end in _SUPPORTED. If you are
never going to use an ability, you can change the #define to #undef
before recompiling libpng and save yourself code and data space. All
the reading and writing specific code are in seperate files, so the
before recompiling libpng and save yourself code and data space.
You can also turn them off en masse with a compiler directive that
defines PNG_READ[or WRITE]_NOT_FULLY_SUPPORTED, or
PNG_READ[or WRITE]_ANCILLARY_CHUNKS_NOT_SUPPORTED, or all four,
along with directives to turn on any of the capabilities that you do
want. The NOT_FULLY_SUPPORTED directives disable the extra
transformations but still leave the library fully capable of reading
and writing PNG files with all known public chunks [except for sPLT].
Use of the PNG_READ[or WRITE]_ANCILLARY_CHUNKS_NOT_SUPPORTED directive
produces a library that is incapable of reading or writing ancillary chunks.
All the reading and writing specific code are in separate files, so the
linker should only grab the files it needs. However, if you want to
make sure, or if you are building a stand alone library, all the
reading files start with pngr and all the writing files start with
@@ -1514,10 +1623,12 @@ those sections which are actually used will be loaded into memory.
Changes to Libpng from version 0.88
It should be noted that versions of libpng later than 0.88 are not
distributed by the original libpng author, Guy Schalnat, but rather
another member of the original PNG Group, Andreas Dilger. Guy is still
alive and well, but he has moved on to other things.
It should be noted that versions of libpng later than 0.96 are not
distributed by the original libpng author, Guy Schalnat, nor by
Andreas Dilger, who had taken over from Guy during 1996 and 1997, and
distributed versions 0.89 through 0.96, but rather by another member
of the original PNG Group, Glenn Randers-Pehrson. Guy and Andreas are
still alive and well, but they have moved on to other things.
The old libpng functions png_read_init(), png_write_init(),
png_info_init(), png_read_destroy(), and png_write_destory() have been

View File

@@ -1,6 +1,6 @@
# makefile for libpng on Linux ELF with gcc
# Copyright (C) 1996, 1997 Andreas Dilger
# Copyright (C) 1998 Glenn Randers-Pehrson
# Copyright (C) 1998 Greg Roelofs
# For conditions of distribution and use, see copyright notice in png.h
CC=gcc
@@ -22,7 +22,7 @@ RANLIB=ranlib
#RANLIB=echo
PNGMAJ = 2
PNGMIN = 0.97
PNGMIN = 0.99
PNGVER = $(PNGMAJ).$(PNGMIN)
# where make install puts libpng.a, libpng.so*, and png.h

80
makefile.min Normal file
View File

@@ -0,0 +1,80 @@
# makefile for libpng
# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc.
# For conditions of distribution and use, see copyright notice in png.h
# Where the zlib library and include files are located
#ZLIBLIB=/usr/local/lib
#ZLIBINC=/usr/local/include
ZLIBLIB=../zlib
ZLIBINC=../zlib
CC=cc
# CFLAGS=-I$(ZLIBINC) -O -fullwarn \
# -DPNG_NO_EASY_ACCESS
CFLAGS=-I$(ZLIBINC) -O -fullwarn \
-DPNG_READ_NOT_FULLY_SUPPORTED -DPNG_WRITE_NOT_FULLY_SUPPORTED
#CFLAGS=-I$(ZLIBINC) -O -fullwarn -DPNGTEST_MEMORY_DEBUG \
# -DPNG_READ_NOT_FULLY_SUPPORTED -DPNG_WRITE_NOT_FULLY_SUPPORTED \
# -DPNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED \
# -DPNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED \
# -DPNG_NO_STDIO
LDFLAGS=-L. -L$(ZLIBLIB) -lpng -lz -lm
RANLIB=echo
#RANLIB=ranlib
# where make install puts libpng.a and png.h
prefix=/usr/local
OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \
pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \
pngwtran.o pngmem.o pngerror.o pngpread.o
all: libpng.a pngtest
libpng.a: $(OBJS)
ar rc $@ $(OBJS)
$(RANLIB) $@
pngtest: pngtest.o libpng.a
$(CC) -o pngtest $(CCFLAGS) pngtest.o $(LDFLAGS)
test: pngtest
./pngtest
install: libpng.a
-@mkdir $(prefix)/include
-@mkdir $(prefix)/lib
cp png.h $(prefix)/include
cp pngconf.h $(prefix)/include
chmod 644 $(prefix)/include/png.h
chmod 644 $(prefix)/include/pngconf.h
cp libpng.a $(prefix)/lib
chmod 644 $(prefix)/lib/libpng.a
clean:
rm -f *.o libpng.a pngtest pngout.png
# DO NOT DELETE THIS LINE -- make depend depends on it.
png.o: png.h pngconf.h
pngerror.o: png.h pngconf.h
pngrio.o: png.h pngconf.h
pngwio.o: png.h pngconf.h
pngmem.o: png.h pngconf.h
pngset.o: png.h pngconf.h
pngget.o: png.h pngconf.h
pngread.o: png.h pngconf.h
pngrtran.o: png.h pngconf.h
pngrutil.o: png.h pngconf.h
pngtest.o: png.h pngconf.h
pngtrans.o: png.h pngconf.h
pngwrite.o: png.h pngconf.h
pngwtran.o: png.h pngconf.h
pngwutil.o: png.h pngconf.h
pngpread.o: png.h pngconf.h

View File

@@ -5,7 +5,7 @@
# ------------- Microsoft C 5.1 and later -------------
MODEL=-AL
CFLAGS=-Oait -Gs -nologo -W2 $(MODEL) -I..\zlib
CFLAGS=-Oait -Gs -nologo -W3 $(MODEL) -I..\zlib
#-Ox generates bad code with MSC 5.1
CC=cl
LD=link

69
makefile.sgi Normal file
View File

@@ -0,0 +1,69 @@
# makefile for libpng
# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc.
# For conditions of distribution and use, see copyright notice in png.h
# Where the zlib library and include files are located
#ZLIBLIB=/usr/local/lib
#ZLIBINC=/usr/local/include
ZLIBLIB=../zlib
ZLIBINC=../zlib
CC=cc
CFLAGS=-I$(ZLIBINC) -O -fullwarn # -g -DPNG_DEBUG=1
LDFLAGS=-L. -L$(ZLIBLIB) -lpng -lz -lm
RANLIB=echo
#RANLIB=ranlib
# where make install puts libpng.a and png.h
prefix=/usr/local
OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \
pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \
pngwtran.o pngmem.o pngerror.o pngpread.o
all: libpng.a pngtest
libpng.a: $(OBJS)
ar rc $@ $(OBJS)
$(RANLIB) $@
pngtest: pngtest.o libpng.a
$(CC) -o pngtest $(CCFLAGS) pngtest.o $(LDFLAGS)
test: pngtest
./pngtest
install: libpng.a
-@mkdir $(prefix)/include
-@mkdir $(prefix)/lib
cp png.h $(prefix)/include
cp pngconf.h $(prefix)/include
chmod 644 $(prefix)/include/png.h
chmod 644 $(prefix)/include/pngconf.h
cp libpng.a $(prefix)/lib
chmod 644 $(prefix)/lib/libpng.a
clean:
rm -f *.o libpng.a pngtest pngout.png
# DO NOT DELETE THIS LINE -- make depend depends on it.
png.o: png.h pngconf.h
pngerror.o: png.h pngconf.h
pngrio.o: png.h pngconf.h
pngwio.o: png.h pngconf.h
pngmem.o: png.h pngconf.h
pngset.o: png.h pngconf.h
pngget.o: png.h pngconf.h
pngread.o: png.h pngconf.h
pngrtran.o: png.h pngconf.h
pngrutil.o: png.h pngconf.h
pngtest.o: png.h pngconf.h
pngtrans.o: png.h pngconf.h
pngwrite.o: png.h pngconf.h
pngwtran.o: png.h pngconf.h
pngwutil.o: png.h pngconf.h
pngpread.o: png.h pngconf.h

View File

@@ -1,7 +1,7 @@
# Makefile for libpng
# TurboC++ 3.0 (Note: All modules are compiled in C mode)
# To use, do "make -fmakefile.tc"
# To use, do "make -fmakefile.tc3"
# ------------- Turbo C++ 3.0 -------------
MODEL=-ml

44
png.5 Normal file
View File

@@ -0,0 +1,44 @@
.TH PNG 5 "February 7, 1998"
.SH NAME
png \- Portable Network Graphics (PNG) format
.SH DESCRIPTION
PNG (Portable Network Graphics) is an extensible file format for the
lossless, portable, well-compressed storage of raster images. PNG provides
a patent-free replacement for GIF and can also replace many
common uses of TIFF. Indexed-color, grayscale, and truecolor images are
supported, plus an optional alpha channel. Sample depths range from
1 to 16 bits.
.br
PNG is designed to work well in online viewing applications, such as the
World Wide Web, so it is fully streamable with a progressive display
option. PNG is robust, providing both full file integrity checking and
fast, simple detection of common transmission errors. Also, PNG can store
gamma and chromaticity data for improved color matching on heterogeneous
platforms.
.SH "SEE ALSO"
.IR libpng(3), zlib(3), deflate(5), and zlib(5)
.LP
PNG specification:
RFC 2083
.IP
.br
ftp://ds.internic.net/rfc/rfc2083.txt
.br
or (as a W3C Recommendation) at
.br
http://www.w3.org/TR/REC-png.html
.SH AUTHORS
This man page: Glenn Randers-Pehrson
.LP
Portable Network Graphics (PNG) Specification Version 1.0 (October 1, 1996):
Thomas Boutell and others (png-list@dworkin.wustl.edu).
.LP
.SH COPYRIGHT NOTICE
The PNG specification is copyright (c) 1996 Massachussets Institute of
Technology. See the specification for conditions of use and distribution.
.LP
.\" end of man page

26
png.c
View File

@@ -1,12 +1,12 @@
/* png.c - location for general purpose libpng functions
*
* libpng 0.97
* libpng 0.99c
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson
* January 7, 1998
* February 7, 1998
*/
#define PNG_INTERNAL
@@ -16,9 +16,9 @@
/* Version information for C files. This had better match the version
* string defined in png.h.
*/
char png_libpng_ver[] = "0.97";
char png_libpng_ver[5] = "0.99";
/* Place to hold the signiture string for a PNG file. */
/* Place to hold the signature string for a PNG file. */
png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
/* Constant strings for known chunk types. If you need to add a chunk,
@@ -103,15 +103,15 @@ png_sig_cmp(png_bytep sig, png_size_t start, png_size_t num_to_check)
if (num_to_check > 8)
num_to_check = 8;
else if (num_to_check < 1)
return 0;
return (0);
if (start > 7)
return 0;
return (0);
if (start + num_to_check > 8)
num_to_check = 8 - start;
return (png_memcmp(&sig[start], &png_sig[start], num_to_check));
return ((int)(png_memcmp(&sig[start], &png_sig[start], num_to_check)));
}
/* (Obsolete) function to check signature bytes. It does not allow one
@@ -121,7 +121,7 @@ png_sig_cmp(png_bytep sig, png_size_t start, png_size_t num_to_check)
int
png_check_sig(png_bytep sig, int num)
{
return !png_sig_cmp(sig, (png_size_t)0, (png_size_t)num);
return ((int)!png_sig_cmp(sig, (png_size_t)0, (png_size_t)num));
}
/* Function to allocate memory for zlib. */
@@ -132,7 +132,7 @@ png_zalloc(voidpf png_ptr, uInt items, uInt size)
png_uint_32 num_bytes;
num_bytes = (png_uint_32)items * size;
ptr = png_malloc((png_structp)png_ptr, num_bytes);
ptr = (png_voidp)png_malloc((png_structp)png_ptr, num_bytes);
if (num_bytes > (png_uint_32)0x8000)
{
png_memset(ptr, 0, (png_size_t)0x8000L);
@@ -143,7 +143,7 @@ png_zalloc(voidpf png_ptr, uInt items, uInt size)
{
png_memset(ptr, 0, (png_size_t)num_bytes);
}
return (voidpf)(ptr);
return ((voidpf)ptr);
}
/* function to free memory for zlib */
@@ -205,7 +205,7 @@ png_create_info_struct(png_structp png_ptr)
png_info_init(info_ptr);
}
return info_ptr;
return (info_ptr);
}
/* This function frees the memory associated with a single info struct.
@@ -268,7 +268,7 @@ png_info_destroy(png_structp png_ptr, png_infop info_ptr)
png_free(png_ptr, info_ptr->pcal_units);
if (info_ptr->pcal_params != NULL)
{
for (i = 0; i < info_ptr->pcal_nparams; i++)
for (i = 0; i < (int)info_ptr->pcal_nparams; i++)
{
png_free(png_ptr, info_ptr->pcal_params[i]);
}
@@ -286,7 +286,7 @@ png_info_destroy(png_structp png_ptr, png_infop info_ptr)
png_voidp
png_get_io_ptr(png_structp png_ptr)
{
return png_ptr->io_ptr;
return (png_ptr->io_ptr);
}
#if !defined(PNG_NO_STDIO)

287
png.h
View File

@@ -1,12 +1,40 @@
/* png.h - header file for PNG reference library
*
* libpng 0.97 beta
* For conditions of distribution and use, see copyright notice in png.h
* libpng 0.99c beta
* For conditions of distribution and use, see the COPYRIGHT NOTICE below.
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998 Glenn Randers-Pehrson
* January 7, 1998
* February 7, 1998
*
* Note about libpng version numbers:
*
* Due to various miscommunications, unforeseen code incompatibilities
* and occasional factors outside the authors' control, version numbering
* on the library has not always been consistent and straightforward.
* The following table summarizes matters since version 0.89c, which was
* the first widely used release:
*
* source png.h shared-lib
* version string version
* ------- ------ ----------
* 0.89c ("1.0 beta 3") 0.89 1.0.89
* 0.90 ("1.0 beta 4") 0.90 0.90 [should have been 2.0.90]
* 0.95 ("1.0 beta 5") 0.95 0.95 [should have been 2.0.95]
* 0.96 ("1.0 beta 6") 0.96 0.96 [should have been 2.0.96]
* 0.97b ("1.00.97 beta 7") 1.00.97 1.0.0 [should have been 2.0.97]
* 0.97c 0.97 2.0.97
* 0.98 0.98 2.0.98
* 0.99 0.99 2.0.99
* 0.99a 0.99 2.0.99
* 0.99b 0.99 2.0.99
* 0.99c 0.99 2.0.99
* 1.0 1.00 2.1.0
*
* Henceforth the source version will match the shared-library minor
* and patch numbers; the shared-library major version number will be
* used for changes in backward compatibility, as it is intended.
*
* BETA NOTICE:
* This is a beta version. It reads and writes valid files on the
@@ -21,12 +49,12 @@
*
* See libpng.txt for more information. The PNG specification is available
* as RFC 2083 <ftp://ftp.uu.net/graphics/png/documents/>
* and as a W3C Recommendation <http://www.w3.org/pub/WWW/TR/REC.png.html>
* and as a W3C Recommendation <http://www.w3.org/TR/REC.png.html>
*
* Contributing Authors:
* John Bowler
* Sam Bushell
* Kevin Bracey
* Sam Bushell
* Andreas Dilger
* Magnus Holmgren
* Tom Lane
@@ -44,6 +72,8 @@
*
* Thanks to Frank J. T. Wojcik for helping with the documentation.
*
* COPYRIGHT NOTICE:
*
* The PNG Reference Library is supplied "AS IS". The Contributing Authors
* and Group 42, Inc. disclaim all warranties, expressed or implied,
* including, without limitation, the warranties of merchantability and of
@@ -94,57 +124,30 @@ extern "C" {
*/
/* Version information for png.h - this should match the version in png.c */
#define PNG_LIBPNG_VER_STRING "0.97"
#define PNG_LIBPNG_VER_STRING "0.99"
/* careful here. At one time, I wanted to use 082, but that would be octal.
* Version 1.0 will be 100 here, etc.
*/
#define PNG_LIBPNG_VER 97
#define PNG_LIBPNG_VER 99
/* variables declared in png.c - only it needs to define PNG_NO_EXTERN */
#ifndef PNG_NO_EXTERN
#if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
/* Version information for C files, stored in png.c. This had better match
* the version above.
*/
extern char png_libpng_ver[];
extern char png_libpng_ver[5];
/*
* Note about libpng version numbers:
*
* Due to various miscommunications, unforeseen code incompatibilities
* and occasional factors outside the authors' control, version numbering
* on the library has not always been consistent and straightforward.
* The following table summarizes matters since version 0.89c, which was
* the first widely used release:
*
* source png.h shared-lib
* version string version
* ------- ------ ----------
* 0.89c ("1.0 beta 3") 0.89 1.0.89
* 0.90 ("1.0 beta 4") 0.90 0.90 [should have been 2.0.90]
* 0.95 ("1.0 beta 5") 0.95 0.95 [should have been 2.0.95]
* 0.96 ("1.0 beta 6") 0.96 0.96 [should have been 2.0.96]
* 0.97b ("1.00.97 beta 7") 1.00.97 1.0.0 [should have been 2.0.97]
* 0.97c 0.97 2.0.97
* 0.98 0.98 2.0.98
* 0.99 0.99 2.0.99
* 1.0 1.00 2.1.0
*
* Henceforth the source version will match the shared-library minor
* and patch numbers; the shared-library major version number will be
* used for changes in backward compatibility, as it is intended.
*/
/* Structures to facilitate easy interlacing. See png.c for more details */
extern int FARDATA png_pass_start[];
extern int FARDATA png_pass_inc[];
extern int FARDATA png_pass_ystart[];
extern int FARDATA png_pass_yinc[];
extern int FARDATA png_pass_mask[];
extern int FARDATA png_pass_dsp_mask[];
extern int FARDATA png_pass_start[7];
extern int FARDATA png_pass_inc[7];
extern int FARDATA png_pass_ystart[7];
extern int FARDATA png_pass_yinc[7];
extern int FARDATA png_pass_mask[7];
extern int FARDATA png_pass_dsp_mask[7];
/* These aren't currently used. If you need them, see png.c for more details
extern int FARDATA png_pass_width[];
extern int FARDATA png_pass_height[];
extern int FARDATA png_pass_width[7];
extern int FARDATA png_pass_height[7];
*/
#endif /* PNG_NO_EXTERN */
@@ -248,7 +251,7 @@ typedef struct png_info_struct
png_uint_32 width; /* width of image in pixels (from IHDR) */
png_uint_32 height; /* height of image in pixels (from IHDR) */
png_uint_32 valid; /* valid chunk data (see PNG_INFO_ below) */
png_size_t rowbytes; /* bytes needed to hold an untransformed row */
png_uint_32 rowbytes; /* bytes needed to hold an untransformed row */
png_colorp palette; /* array of color values (valid & PNG_INFO_PLTE) */
png_uint_16 num_palette; /* number of color entries in "palette" (PLTE) */
png_uint_16 num_trans; /* number of transparent palette color (tRNS) */
@@ -270,7 +273,8 @@ typedef struct png_info_struct
* and initialize the appropriate fields below.
*/
#if defined(PNG_READ_gAMA_SUPPORTED) || defined(PNG_WRITE_gAMA_SUPPORTED)
#if defined(PNG_READ_gAMA_SUPPORTED) || defined(PNG_WRITE_gAMA_SUPPORTED) || \
defined(PNG_READ_GAMMA_SUPPORTED)
/* The gAMA chunk describes the gamma characteristics of the system
* on which the image was created, normally in the range [1.0, 2.5].
* Data is valid if (valid & PNG_INFO_gAMA) is non-zero.
@@ -325,7 +329,8 @@ typedef struct png_info_struct
png_bytep trans; /* transparent values for paletted image */
png_color_16 trans_values; /* transparent color for non-palette image */
#endif /* PNG_READ_tRNS_SUPPORTED || PNG_WRITE_tRNS_SUPPORTED */
#if defined(PNG_READ_bKGD_SUPPORTED) || defined(PNG_WRITE_bKGD_SUPPORTED)
#if defined(PNG_READ_bKGD_SUPPORTED) || defined(PNG_WRITE_bKGD_SUPPORTED) || \
defined(PNG_READ_BACKGROUND_SUPPORTED)
/* The bKGD chunk gives the suggested image background color if the
* display program does not have its own background color and the image
* is needs to composited onto a background before display. The colors
@@ -446,6 +451,15 @@ typedef png_info FAR * FAR * png_infopp;
#define PNG_RESOLUTION_METER 1 /* pixels/meter */
#define PNG_RESOLUTION_LAST 2 /* Not a valid value */
/* These are for the sRGB chunk. These values should NOT be changed. */
#define PNG_sRGB_INTENT_SATURATION 0
#define PNG_sRGB_INTENT_PERCEPTUAL 1
#define PNG_sRGB_INTENT_ABSOLUTE 2
#define PNG_sRGB_INTENT_RELATIVE 3
#define PNG_sRGB_INTENT_LAST 4 /* Not a valid value */
/* These determine if an ancillary chunk's data has been successfully read
* from the PNG header, or if the application has filled in the corresponding
* data in the info_struct to be written into the output file. The values
@@ -471,7 +485,7 @@ typedef png_info FAR * FAR * png_infopp;
typedef struct png_row_info_struct
{
png_uint_32 width; /* width of row */
png_size_t rowbytes; /* number of bytes in row */
png_uint_32 rowbytes; /* number of bytes in row */
png_byte color_type; /* color type of row */
png_byte bit_depth; /* bit depth of row */
png_byte channels; /* number of channels (1, 2, 3, or 4) */
@@ -534,8 +548,8 @@ struct png_struct_def
png_uint_32 height; /* height of image in pixels */
png_uint_32 num_rows; /* number of rows in current pass */
png_uint_32 usr_width; /* width of row at start of write */
png_size_t rowbytes; /* size of row in bytes */
png_size_t irowbytes; /* size of current interlaced row in bytes */
png_uint_32 rowbytes; /* size of row in bytes */
png_uint_32 irowbytes; /* size of current interlaced row in bytes */
png_uint_32 iwidth; /* width of current interlaced row in pixels */
png_uint_32 row_number; /* current row in interlace pass */
png_bytep prev_row; /* buffer to save previous (unfiltered) row */
@@ -582,9 +596,9 @@ struct png_struct_def
png_uint_32 flush_rows; /* number of rows written since last flush */
#endif /* PNG_WRITE_FLUSH_SUPPORTED */
#if defined(PNG_READ_GAMMA_SUPPORTED)
int gamma_shift; /* number of "insignificant" bits 16-bit gamma */
float gamma; /* file gamma value */
float display_gamma; /* display gamma value */
int gamma_shift; /* number of "insignificant" bits 16-bit gamma */
float gamma; /* file gamma value */
float screen_gamma; /* screen gamma value (display_gamma/viewing_gamma */
#endif /* PNG_READ_GAMMA_SUPPORTED */
#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
png_bytep gamma_table; /* gamma table for 8 bit depth files */
@@ -626,6 +640,7 @@ struct png_struct_def
png_charp current_text; /* current text chunk buffer */
png_charp current_text_ptr; /* current location in current_text */
#endif /* PNG_PROGRESSIVE_READ_SUPPORTED && PNG_READ_tEXt/zTXt_SUPPORTED */
#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
#if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
/* for the Borland special 64K segment handler */
png_bytepp offset_table_ptr;
@@ -633,13 +648,14 @@ struct png_struct_def
png_uint_16 offset_table_number;
png_uint_16 offset_table_count;
png_uint_16 offset_table_count_free;
#endif /* PNG_PROGRESSIVE_READ_SUPPORTED&&__TURBOC__&&!_Windows&&!__FLAT__ */
#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
#endif /* __TURBOC__&&!_Windows&&!__FLAT__ */
#if defined(PNG_READ_DITHER_SUPPORTED)
png_bytep palette_lookup; /* lookup table for dithering */
png_bytep dither_index; /* index translation for palette files */
png_uint_16p hist; /* histogram */
#endif /* PNG_READ_DITHER_SUPPORTED */
#if defined(PNG_READ_DITHER_SUPPORTED) || defined(PNG_READ_hIST_SUPPORTED)
png_uint_16p hist; /* histogram */
#endif
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
png_byte heuristic_method; /* heuristic for row filter selection */
png_byte num_prev_filters; /* number of weights for previous rows */
@@ -649,9 +665,9 @@ struct png_struct_def
png_uint_16p filter_costs; /* relative filter calculation cost */
png_uint_16p inv_filter_costs; /* 1/relative filter calculation cost */
#endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
#if defined(PNG_TIME_RFC1152_SUPPORTED)
png_charp time_buffer; /* String to hold RFC 1152 time text */
#endif /* PNG_TIME_RFC1152_SUPPORTED */
#if defined(PNG_TIME_RFC1123_SUPPORTED)
png_charp time_buffer; /* String to hold RFC 1123 time text */
#endif /* PNG_TIME_RFC1123_SUPPORTED */
};
typedef png_struct FAR * FAR * png_structpp;
@@ -706,10 +722,10 @@ extern PNG_EXPORT(void,png_write_info) PNGARG((png_structp png_ptr,
extern PNG_EXPORT(void,png_read_info) PNGARG((png_structp png_ptr,
png_infop info_ptr));
#if defined(PNG_TIME_RFC1152_SUPPORTED)
extern PNG_EXPORT(png_charp,png_convert_to_rfc1152)
#if defined(PNG_TIME_RFC1123_SUPPORTED)
extern PNG_EXPORT(png_charp,png_convert_to_rfc1123)
PNGARG((png_structp png_ptr, png_timep ptime));
#endif /* PNG_TIME_RFC1152_SUPPORTED */
#endif /* PNG_TIME_RFC1123_SUPPORTED */
#if defined(PNG_WRITE_tIME_SUPPORTED)
/* convert from a struct tm to png_time */
@@ -753,6 +769,11 @@ extern PNG_EXPORT(void,png_set_strip_alpha) PNGARG((png_structp png_ptr));
extern PNG_EXPORT(void,png_set_swap_alpha) PNGARG((png_structp png_ptr));
#endif /* PNG_READ_SWAP_ALPHA_SUPPORTED || PNG_WRITE_SWAP_ALPHA_SUPPORTED */
#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
extern PNG_EXPORT(void,png_set_invert_alpha) PNGARG((png_structp png_ptr));
#endif /* PNG_READ_INVERT_ALPHA_SUPPORTED || PNG_WRITE_INVERT_ALPHA_SUPPORTED */
#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
/* Add a filler byte to 24-bit RGB images. */
extern PNG_EXPORT(void,png_set_filler) PNGARG((png_structp png_ptr,
@@ -819,7 +840,7 @@ extern PNG_EXPORT(void,png_set_dither) PNGARG((png_structp png_ptr,
#endif /* PNG_READ_DITHER_SUPPORTED */
#if defined(PNG_READ_GAMMA_SUPPORTED)
/* Handle gamma correction. */
/* Handle gamma correction. Screen_gamma=(display_gamma/viewing_gamma) */
extern PNG_EXPORT(void,png_set_gamma) PNGARG((png_structp png_ptr,
double screen_gamma, double default_file_gamma));
#endif /* PNG_READ_GAMMA_SUPPORTED */
@@ -1088,6 +1109,19 @@ extern PNG_EXPORT(png_voidp,png_malloc) PNGARG((png_structp png_ptr,
/* frees a pointer allocated by png_malloc() */
extern PNG_EXPORT(void,png_free) PNGARG((png_structp png_ptr, png_voidp ptr));
extern PNG_EXPORT(void,png_buffered_memcpy) PNGARG((png_structp png_ptr,
png_voidp s1, png_voidp s2, png_uint_32 size));
extern PNG_EXPORT(void,png_buffered_memset) PNGARG((png_structp png_ptr,
png_voidp s1, int value, png_uint_32 size));
#ifdef PNGTEST_MEMORY_DEBUG
/* debugging versions of png_malloc() and png_free() */
extern PNG_EXPORT(png_voidp,png_debug_malloc) PNGARG((png_structp png_ptr,
png_uint_32 size));
extern PNG_EXPORT(void,png_debug_free) PNGARG((png_structp png_ptr,
png_voidp ptr));
#endif
#if defined(USE_FAR_KEYWORD) /* memory model conversion function */
extern void *far_to_near PNGARG((png_structp png_ptr,png_voidp ptr,int check));
#endif /* USE_FAR_KEYWORD */
@@ -1120,18 +1154,67 @@ extern PNG_EXPORT(void,png_chunk_warning) PNGARG((png_structp png_ptr,
* to avoid problems with future changes in the size and internal layout of
* png_info_struct.
*/
/* Returns "flag" if chunk data is valid in info_ptr */
/* Returns "flag" if chunk data is valid in info_ptr. */
extern PNG_EXPORT(png_uint_32,png_get_valid) PNGARG((png_structp png_ptr,
png_infop info_ptr, png_uint_32 flag));
/* Returns number of bytes needed to hold a transformed row */
/* Returns number of bytes needed to hold a transformed row. */
extern PNG_EXPORT(png_uint_32,png_get_rowbytes) PNGARG((png_structp png_ptr,
png_infop info_ptr));
/* Returns number of color channels in image */
/* Returns number of color channels in image. */
extern PNG_EXPORT(png_byte,png_get_channels) PNGARG((png_structp png_ptr,
png_infop info_ptr));
#ifdef PNG_EASY_ACCESS_SUPPORTED
/* Returns image width in pixels. */
extern PNG_EXPORT(png_uint_32, png_get_image_width) PNGARG((png_structp
png_ptr, png_infop info_ptr));
/* Returns image height in pixels. */
extern PNG_EXPORT(png_uint_32, png_get_image_height) PNGARG((png_structp
png_ptr, png_infop info_ptr));
/* Returns image bit_depth. */
extern PNG_EXPORT(png_byte, png_get_bit_depth) PNGARG((png_structp
png_ptr, png_infop info_ptr));
/* Returns image color_type. */
extern PNG_EXPORT(png_byte, png_get_color_type) PNGARG((png_structp
png_ptr, png_infop info_ptr));
/* Returns image filter_type. */
extern PNG_EXPORT(png_byte, png_get_filter_type) PNGARG((png_structp
png_ptr, png_infop info_ptr));
/* Returns image interlace_type. */
extern PNG_EXPORT(png_byte, png_get_interlace_type) PNGARG((png_structp
png_ptr, png_infop info_ptr));
/* Returns image compression_type. */
extern PNG_EXPORT(png_byte, png_get_compression_type) PNGARG((png_structp
png_ptr, png_infop info_ptr));
/* Returns image resolution in pixels per meter, from pHYs chunk data. */
extern PNG_EXPORT(png_uint_32, png_get_pixels_per_meter) PNGARG((png_structp
png_ptr, png_infop info_ptr));
/* Returns pixel aspect ratio, computed from pHYs chunk data. */
extern PNG_EXPORT(float, png_get_pixel_aspect_ratio) PNGARG((png_structp
png_ptr, png_infop info_ptr));
/* Returns image x, y offset in pixels or microns, from oFFs chunk data. */
extern PNG_EXPORT(png_uint_32, png_get_x_offset_pixels) PNGARG((png_structp
png_ptr, png_infop info_ptr));
extern PNG_EXPORT(png_uint_32, png_get_y_offset_pixels) PNGARG((png_structp
png_ptr, png_infop info_ptr));
extern PNG_EXPORT(png_uint_32, png_get_x_offset_microns) PNGARG((png_structp
png_ptr, png_infop info_ptr));
extern PNG_EXPORT(png_uint_32, png_get_y_offset_microns) PNGARG((png_structp
png_ptr, png_infop info_ptr));
#endif /* PNG_EASY_ACCESS_SUPPORTED */
/* Returns pointer to signature string read from PNG header */
extern PNG_EXPORT(png_bytep,png_get_signature) PNGARG((png_structp png_ptr,
png_infop info_ptr));
@@ -1240,14 +1323,14 @@ extern PNG_EXPORT(void,png_set_sBIT) PNGARG((png_structp png_ptr,
#if defined(PNG_READ_sRGB_SUPPORTED)
extern PNG_EXPORT(png_uint_32,png_get_sRGB) PNGARG((png_structp png_ptr,
png_infop info_ptr, png_bytep srgb_intent));
png_infop info_ptr, int *intent));
#endif /* PNG_READ_sRGB_SUPPORTED */
#if defined(PNG_READ_sRGB_SUPPORTED) || defined(PNG_WRITE_sRGB_SUPPORTED)
extern PNG_EXPORT(void,png_set_sRGB) PNGARG((png_structp png_ptr,
png_infop info_ptr, png_byte srgb_intent));
png_infop info_ptr, int intent));
extern PNG_EXPORT(void,png_set_sRGB_gAMA_and_cHRM) PNGARG((png_structp png_ptr,
png_infop info_ptr, png_byte srgb_intent));
png_infop info_ptr, int intent));
#endif /* PNG_READ_sRGB_SUPPORTED || PNG_WRITE_sRGB_SUPPORTED */
#if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_READ_zTXt_SUPPORTED)
@@ -1291,6 +1374,9 @@ extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr,
* libpng yet, but more support will be added as needed.
*/
#if (PNG_DEBUG > 0)
#ifdef PNG_NO_STDIO
#include <stdio.h>
#endif
#ifndef PNG_DEBUG_FILE
#define PNG_DEBUG_FILE stderr
#endif /* PNG_DEBUG_FILE */
@@ -1358,9 +1444,10 @@ extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr,
#define PNG_GAMMA 0x2000
#define PNG_GRAY_TO_RGB 0x4000
#define PNG_FILLER 0x8000
#define PNG_PACKSWAP 0x10000
#define PNG_SWAP_ALPHA 0x20000
#define PNG_STRIP_ALPHA 0x40000
#define PNG_PACKSWAP 0x10000L
#define PNG_SWAP_ALPHA 0x20000L
#define PNG_STRIP_ALPHA 0x40000L
#define PNG_INVERT_ALPHA 0x80000L
/* flags for png_create_struct */
#define PNG_STRUCT_PNG 0x0001
@@ -1406,32 +1493,32 @@ extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr,
abs((int)((c1).blue) - (int)((c2).blue)))
/* variables declared in png.c - only it needs to define PNG_NO_EXTERN */
#ifndef PNG_NO_EXTERN
/* place to hold the signiture string for a PNG file. */
extern png_byte FARDATA png_sig[];
#if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
/* place to hold the signature string for a PNG file. */
extern png_byte FARDATA png_sig[8];
/* Constant strings for known chunk types. If you need to add a chunk,
* add a string holding the name here. See png.c for more details. We
* can't selectively include these, since we still check for chunk in the
* wrong locations with these labels.
*/
extern png_byte FARDATA png_IHDR[];
extern png_byte FARDATA png_IDAT[];
extern png_byte FARDATA png_IEND[];
extern png_byte FARDATA png_PLTE[];
extern png_byte FARDATA png_bKGD[];
extern png_byte FARDATA png_cHRM[];
extern png_byte FARDATA png_gAMA[];
extern png_byte FARDATA png_hIST[];
extern png_byte FARDATA png_oFFs[];
extern png_byte FARDATA png_pCAL[];
extern png_byte FARDATA png_pHYs[];
extern png_byte FARDATA png_sBIT[];
extern png_byte FARDATA png_sRGB[];
extern png_byte FARDATA png_tEXt[];
extern png_byte FARDATA png_tIME[];
extern png_byte FARDATA png_tRNS[];
extern png_byte FARDATA png_zTXt[];
extern png_byte FARDATA png_IHDR[5];
extern png_byte FARDATA png_IDAT[5];
extern png_byte FARDATA png_IEND[5];
extern png_byte FARDATA png_PLTE[5];
extern png_byte FARDATA png_bKGD[5];
extern png_byte FARDATA png_cHRM[5];
extern png_byte FARDATA png_gAMA[5];
extern png_byte FARDATA png_hIST[5];
extern png_byte FARDATA png_oFFs[5];
extern png_byte FARDATA png_pCAL[5];
extern png_byte FARDATA png_pHYs[5];
extern png_byte FARDATA png_sBIT[5];
extern png_byte FARDATA png_sRGB[5];
extern png_byte FARDATA png_tEXt[5];
extern png_byte FARDATA png_tIME[5];
extern png_byte FARDATA png_tRNS[5];
extern png_byte FARDATA png_zTXt[5];
#endif /* PNG_NO_EXTERN */
@@ -1546,7 +1633,7 @@ PNG_EXTERN void png_write_chunk_data PNGARG((png_structp png_ptr,
/* Finish a chunk started with png_write_chunk_start() (includes CRC). */
PNG_EXTERN void png_write_chunk_end PNGARG((png_structp png_ptr));
/* simple function to write the signiture */
/* simple function to write the signature */
PNG_EXTERN void png_write_sig PNGARG((png_structp png_ptr));
/* write various chunks */
@@ -1585,7 +1672,7 @@ PNG_EXTERN void png_write_cHRM PNGARG((png_structp png_ptr,
#if defined(PNG_WRITE_sRGB_SUPPORTED)
PNG_EXTERN void png_write_sRGB PNGARG((png_structp png_ptr,
png_byte srgb_intent));
int intent));
#endif
#if defined(PNG_WRITE_tRNS_SUPPORTED)
@@ -1600,7 +1687,7 @@ PNG_EXTERN void png_write_bKGD PNGARG((png_structp png_ptr,
#if defined(PNG_WRITE_hIST_SUPPORTED)
PNG_EXTERN void png_write_hIST PNGARG((png_structp png_ptr, png_uint_16p hist,
png_uint_32 num_hist));
int num_hist));
#endif
#if defined(PNG_WRITE_tEXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED)
@@ -1702,6 +1789,16 @@ PNG_EXTERN void png_do_write_swap_alpha PNGARG((png_row_infop row_info,
png_bytep row));
#endif
#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
PNG_EXTERN void png_do_read_invert_alpha PNGARG((png_row_infop row_info,
png_bytep row));
#endif
#if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
PNG_EXTERN void png_do_write_invert_alpha PNGARG((png_row_infop row_info,
png_bytep row));
#endif
#if defined(PNG_WRITE_FILLER_SUPPORTED) || \
defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
PNG_EXTERN void png_do_strip_filler PNGARG((png_row_infop row_info,

109
pngconf.h
View File

@@ -1,12 +1,12 @@
/* pngconf.c - machine configurable file for libpng
/* pngconf.h - machine configurable file for libpng
*
* libpng 0.97
* libpng 0.99c
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson
* January 7, 1998
* February 7, 1998
*/
/* Any machine specific code is near the front of this file, so if you
@@ -27,7 +27,7 @@
* where it becomes significant, if you are concerned with memory
* usage. Note that zlib allocates at least 32Kb also. For readers,
* this describes the size of the buffer available to read the data in.
* Unless this gets smaller then the size of a row (compressed),
* Unless this gets smaller than the size of a row (compressed),
* it should not make much difference how big this is.
*/
@@ -55,8 +55,6 @@
* #define PNG_NO_STDIO
*/
/* We still need stdio.h for FILE even when PNG_NO_STDIO is defined.
*/
#ifndef PNG_NO_STDIO
#include <stdio.h>
#endif
@@ -88,10 +86,12 @@
* just __MWERKS__ is not good enough, because the Codewarrior is now used
* on non-Mac platforms.
*/
#ifndef MACOS
#if (defined(__MWERKS__) && defined(macintosh)) || defined(applec) || \
defined(THINK_C) || defined(__SC__)
defined(THINK_C) || defined(__SC__) || defined(TARGET_OS_MAC)
#define MACOS
#endif
#endif
/* enough people need this for various reasons to include it here */
#if !defined(MACOS) && !defined(RISCOS)
@@ -157,6 +157,11 @@ __dont__ include it again
#include <math.h>
#endif
/* Codewarrior on NT has linking problems without this. */
#if defined(__MWERKS__) && defined(WIN32)
#define PNG_ALWAYS_EXTERN
#endif
/* For some reason, Borland C++ defines memcmp, etc. in mem.h, not
* stdlib.h like it should (I think). Or perhaps this is a C++
* "feature"?
@@ -191,24 +196,25 @@ __dont__ include it again
* less then 8, and even that may not work (I haven't tested it).
*/
#ifndef PNG_MAX_GAMMA_8
#define PNG_MAX_GAMMA_8 11
#endif
/* This controls how much a difference in gamma we can tolerate before
* we actually start doing gamma conversion.
*/
#ifndef PNG_GAMMA_THRESHOLD
#define PNG_GAMMA_THRESHOLD 0.05
#endif
#endif /* PNG_INTERNAL */
/* The following uses const char * instead of char * for error
* and warning message functions, so some compilers won't complain.
* If you want to use const, define PNG_USE_CONST here. It is not
* normally defined to make configuration easier, as it is not a
* critical part of the code.
* If you do not want to use const, define PNG_NO_CONST here.
*/
#define PNG_USE_CONST
#ifdef PNG_USE_CONST
#ifndef PNG_NO_CONST
# define PNG_CONST const
#else
# define PNG_CONST
@@ -233,7 +239,8 @@ __dont__ include it again
/* GR-P, 0.96a: Set "*FULLY_SUPPORTED as default but allow user
to turn it off with "*NOT_FULLY_SUPPORTED" on the compile line,
then pick and choose which ones to define without having to edit
this file */
this file.
*/
#ifndef PNG_READ_NOT_FULLY_SUPPORTED
#define PNG_READ_FULLY_SUPPORTED
@@ -244,7 +251,6 @@ __dont__ include it again
#ifdef PNG_READ_FULLY_SUPPORTED
#define PNG_PROGRESSIVE_READ_SUPPORTED
#define PNG_READ_OPT_PLTE_SUPPORTED
#define PNG_READ_EXPAND_SUPPORTED
#define PNG_READ_SHIFT_SUPPORTED
#define PNG_READ_PACK_SUPPORTED
@@ -259,13 +265,14 @@ __dont__ include it again
#define PNG_READ_GAMMA_SUPPORTED
#define PNG_READ_GRAY_TO_RGB_SUPPORTED
#define PNG_READ_SWAP_ALPHA_SUPPORTED
#define PNG_READ_INVERT_ALPHA_SUPPORTED
#define PNG_READ_STRIP_ALPHA_SUPPORTED
#define PNG_READ_COMPOSITE_NODIV_SUPPORTED /* well tested on Intel */
#endif /* PNG_READ_FULLY_SUPPORTED */
#define PNG_READ_INTERLACING_SUPPORTED
#define PNG_READ_INTERLACING_SUPPORTED /* required for PNG-compliant decoders */
#ifdef PNG_WRITE_FULLY_SUPPORTED
#define PNG_WRITE_INTERLACING_SUPPORTED
#define PNG_WRITE_SHIFT_SUPPORTED
#define PNG_WRITE_PACK_SUPPORTED
#define PNG_WRITE_BGR_SUPPORTED
@@ -275,31 +282,71 @@ __dont__ include it again
#define PNG_WRITE_FILLER_SUPPORTED /* This is the same as WRITE_STRIP_ALPHA */
#define PNG_WRITE_FLUSH_SUPPORTED
#define PNG_WRITE_SWAP_ALPHA_SUPPORTED
#define PNG_WRITE_INVERT_ALPHA_SUPPORTED
#define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
#endif /* PNG_WRITE_FULLY_SUPPORTED */
#define PNG_WRITE_INTERLACING_SUPPORTED /* not required for PNG-compliant */
/* encoders, but can cause trouble
if left undefined */
#if !defined(PNG_NO_STDIO)
#define PNG_TIME_RFC1152_SUPPORTED
#define PNG_TIME_RFC1123_SUPPORTED
#endif
/* These are currently experimental features */
#undef PNG_READ_16_TO_8_ACCURATE_SHIFT_SUPPORTED /* very little testing */
/* This adds extra functions in pngget.c for accessing data from the
* info pointer (added in version 0.99)
* png_get_image_width()
* png_get_image_height()
* png_get_bit_depth()
* png_get_color_type()
* png_get_compression_type()
* png_get_filter_type()
* png_get_interlace_type()
* png_get_pixel_aspect_ratio()
* png_get_pixels_per_meter()
* png_get_x_offset_pixels()
* png_get_y_offset_pixels()
* png_get_x_offset_microns()
* png_get_y_offset_microns()
*/
#if !defined(PNG_NO_EASY_ACCESS)
#define PNG_EASY_ACCESS_SUPPORTED
#endif
/* These are currently experimental features, define them if you want */
/* very little testing */
/*
#define PNG_READ_16_TO_8_ACCURATE_SHIFT_SUPPORTED
*/
/* This is only for PowerPC big-endian and 680x0 systems */
#undef PNG_READ_BIG_ENDIAN_SUPPORTED /* some testing */
/* some testing */
/*
#define PNG_READ_BIG_ENDIAN_SUPPORTED
*/
/* These functions are turned off by default, as they will be phased out. */
#undef PNG_USELESS_TESTS_SUPPORTED
#undef PNG_CORRECT_PALETTE_SUPPORTED
/*
#define PNG_USELESS_TESTS_SUPPORTED
#define PNG_CORRECT_PALETTE_SUPPORTED
*/
/* Any chunks you are not interested in, you can undef here. The
* ones that allocate memory may be expecially important (hIST,
* tEXt, zTXt, tRNS, pCAL). Others will just save time and make png_info
* a bit smaller. OPT_PLTE only disables the optional palette in RGB
* and RGBA images.
* a bit smaller.
*/
#ifdef PNG_READ_FULLY_SUPPORTED
#ifndef PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED
#define PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
#endif
#ifndef PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED
#define PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
#endif
#ifdef PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
#define PNG_READ_bKGD_SUPPORTED
#define PNG_READ_cHRM_SUPPORTED
#define PNG_READ_gAMA_SUPPORTED
@@ -313,9 +360,11 @@ __dont__ include it again
#define PNG_READ_tIME_SUPPORTED
#define PNG_READ_tRNS_SUPPORTED
#define PNG_READ_zTXt_SUPPORTED
#endif /* PNG_READ_FULLY_SUPPORTED */
#define PNG_READ_OPT_PLTE_SUPPORTED /* only affects support of the optional */
/* PLTE chunk in RGB and RGBA images */
#endif /* PNG_READ_ANCILLARY_CHUNKS_SUPPORTED */
#ifdef PNG_WRITE_FULLY_SUPPORTED
#ifdef PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
#define PNG_WRITE_bKGD_SUPPORTED
#define PNG_WRITE_cHRM_SUPPORTED
#define PNG_WRITE_gAMA_SUPPORTED
@@ -329,7 +378,7 @@ __dont__ include it again
#define PNG_WRITE_tIME_SUPPORTED
#define PNG_WRITE_tRNS_SUPPORTED
#define PNG_WRITE_zTXt_SUPPORTED
#endif /* PNG_WRITE_FULLY_SUPPORTED */
#endif /* PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED */
/* need the time information for reading tIME chunks */
#if defined(PNG_READ_tIME_SUPPORTED) || defined(PNG_WRITE_tIME_SUPPORTED)
@@ -455,7 +504,7 @@ typedef z_stream FAR * png_zstreamp;
/* allow for compilation as dll with BORLAND C++ 5.0 */
#if defined(__BORLANDC__) && defined(_Windows) && defined(__DLL__)
# define PNG_EXPORT(t,s) t _export s
# define PNG_EXPORT(type,symbol) type _export symbol
#endif
/* allow for compilation as shared lib under BeOS */
@@ -464,7 +513,7 @@ typedef z_stream FAR * png_zstreamp;
#endif
#ifndef PNG_EXPORT
#define PNG_EXPORT(t,s) t s
#define PNG_EXPORT(type,symbol) type symbol
#endif

View File

@@ -1,12 +1,12 @@
/* pngerror.c - stub functions for i/o and memory allocation
*
* libpng 0.97
* libpng 0.99c
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson
* January 7, 1998
* February 7, 1998
*
* This file provides a location for all error handling. Users which
* need special error handling are expected to write replacement functions
@@ -81,7 +81,7 @@ png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp message
}
if (message == NULL)
buffer[iout++] = 0;
buffer[iout] = 0;
else {
buffer[iout++] = ':';
buffer[iout++] = ' ';
@@ -167,7 +167,7 @@ png_set_error_fn(png_structp png_ptr, png_voidp error_ptr,
png_voidp
png_get_error_ptr(png_structp png_ptr)
{
return png_ptr->error_ptr;
return ((png_voidp)png_ptr->error_ptr);
}

211
pngget.c
View File

@@ -1,12 +1,12 @@
/* pngget.c - retrieval of values from info struct
*
* libpng 0.97
* libpng 0.99c
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson
* January 7, 1998
* February 7, 1998
*/
#define PNG_INTERNAL
@@ -30,13 +30,186 @@ png_get_rowbytes(png_structp png_ptr, png_infop info_ptr)
return(0);
}
#ifdef PNG_EASY_ACCESS_SUPPORTED
/* easy access to info, added in libpng-0.99 */
png_uint_32
png_get_image_width(png_structp png_ptr, png_infop info_ptr)
{
if (info_ptr != NULL)
{
return info_ptr->width;
}
return (0);
}
png_uint_32
png_get_image_height(png_structp png_ptr, png_infop info_ptr)
{
if (info_ptr != NULL)
{
return info_ptr->height;
}
return (0);
}
png_byte
png_get_bit_depth(png_structp png_ptr, png_infop info_ptr)
{
if (info_ptr != NULL)
{
return info_ptr->bit_depth;
}
return (0);
}
png_byte
png_get_color_type(png_structp png_ptr, png_infop info_ptr)
{
if (info_ptr != NULL)
{
return info_ptr->color_type;
}
return (0);
}
png_byte
png_get_filter_type(png_structp png_ptr, png_infop info_ptr)
{
if (info_ptr != NULL)
{
return info_ptr->filter_type;
}
return (0);
}
png_byte
png_get_interlace_type(png_structp png_ptr, png_infop info_ptr)
{
if (info_ptr != NULL)
{
return info_ptr->interlace_type;
}
return (0);
}
png_byte
png_get_compression_type(png_structp png_ptr, png_infop info_ptr)
{
if (info_ptr != NULL)
{
return info_ptr->compression_type;
}
return (0);
}
png_uint_32
png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
{
#if defined(PNG_READ_pHYs_SUPPORTED) || defined(PNG_WRITE_pHYs_SUPPORTED)
if (info_ptr != NULL && info_ptr->valid & PNG_INFO_pHYs)
{
png_debug1(1, "in %s retrieval function\n", "png_get_pixels_per_meter");
if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
return (0);
else return (info_ptr->x_pixels_per_unit);
}
else
#endif
return (0);
}
float
png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr)
{
#if defined(PNG_READ_pHYs_SUPPORTED) || defined(PNG_WRITE_pHYs_SUPPORTED)
if (info_ptr != NULL && info_ptr->valid & PNG_INFO_pHYs)
{
png_debug1(1, "in %s retrieval function\n", "png_get_aspect_ratio");
if (info_ptr->x_pixels_per_unit == 0)
return ((float)0.0);
else
return ((float)info_ptr->y_pixels_per_unit
/(float)info_ptr->x_pixels_per_unit);
}
else
#endif
return ((float)0.0);
}
png_uint_32
png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr)
{
#if defined(PNG_READ_oFFs_SUPPORTED) || defined(PNG_WRITE_oFFs_SUPPORTED)
if (info_ptr != NULL && info_ptr->valid & PNG_INFO_oFFs)
{
png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
return (0);
else return (info_ptr->x_offset);
}
else
#endif
return (0);
}
png_uint_32
png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr)
{
#if defined(PNG_READ_oFFs_SUPPORTED) || defined(PNG_WRITE_oFFs_SUPPORTED)
if (info_ptr != NULL && info_ptr->valid & PNG_INFO_oFFs)
{
png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
return (0);
else return (info_ptr->y_offset);
}
else
#endif
return (0);
}
png_uint_32
png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr)
{
#if defined(PNG_READ_oFFs_SUPPORTED) || defined(PNG_WRITE_oFFs_SUPPORTED)
if (info_ptr != NULL && info_ptr->valid & PNG_INFO_oFFs)
{
png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
return (0);
else return (info_ptr->x_offset);
}
else
#endif
return (0);
}
png_uint_32
png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr)
{
#if defined(PNG_READ_oFFs_SUPPORTED) || defined(PNG_WRITE_oFFs_SUPPORTED)
if (info_ptr != NULL && info_ptr->valid & PNG_INFO_oFFs)
{
png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
return (0);
else return (info_ptr->y_offset);
}
else
#endif
return (0);
}
/* png_get_channels really belongs in here, too, but it's been around longer */
#endif
png_byte
png_get_channels(png_structp png_ptr, png_infop info_ptr)
{
if (info_ptr != NULL)
return(info_ptr->channels);
else
return(0);
return (0);
}
png_bytep
@@ -45,7 +218,7 @@ png_get_signature(png_structp png_ptr, png_infop info_ptr)
if (info_ptr != NULL)
return(info_ptr->signature);
else
return(NULL);
return (NULL);
}
#if defined(PNG_READ_bKGD_SUPPORTED)
@@ -112,14 +285,13 @@ png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma)
#if defined(PNG_READ_sRGB_SUPPORTED)
png_uint_32
png_get_sRGB(png_structp png_ptr, png_infop info_ptr, png_bytep
file_srgb_intent)
png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent)
{
if (info_ptr != NULL && info_ptr->valid & PNG_INFO_sRGB &&
file_srgb_intent != NULL)
{
png_debug1(1, "in %s retrieval function\n", "sRGB");
*file_srgb_intent = info_ptr->srgb_intent;
*file_srgb_intent = (int)info_ptr->srgb_intent;
return (PNG_INFO_sRGB);
}
return (0);
@@ -150,6 +322,10 @@ png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
if (info_ptr != NULL && width != NULL && height != NULL &&
bit_depth != NULL && color_type != NULL)
{
png_uint_32 rowbytes;
int pixel_depth, channels;
png_uint_32 rowbytes_per_pixel;
png_debug1(1, "in %s retrieval function\n", "IHDR");
*width = info_ptr->width;
*height = info_ptr->height;
@@ -161,6 +337,24 @@ png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
*filter_type = info_ptr->filter_type;
if (interlace_type != NULL)
*interlace_type = info_ptr->interlace_type;
/* check for potential overflow of rowbytes */
if (*color_type == PNG_COLOR_TYPE_PALETTE)
channels = 1;
else if (*color_type & PNG_COLOR_MASK_COLOR)
channels = 3;
else
channels = 1;
if (*color_type & PNG_COLOR_MASK_ALPHA)
channels++;
pixel_depth = *bit_depth * channels;
rowbytes_per_pixel = (pixel_depth + 7) >> 3;
rowbytes = *width * rowbytes_per_pixel;
if ((*width > (png_uint_32)2147483647L/rowbytes_per_pixel))
{
png_warning(png_ptr,
"Width too large for libpng to process image data.");
}
return (1);
}
return (0);
@@ -272,7 +466,8 @@ png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr,
if ((info_ptr != NULL) || (info_ptr->num_text > 0))
{
png_debug1(1, "in %s retrieval function\n",
(png_ptr->chunk_name[0] == '\0' ? "text" : png_ptr->chunk_name));
(png_ptr->chunk_name[0] == '\0' ? "text"
: (png_const_charp)png_ptr->chunk_name));
if (text_ptr != NULL)
*text_ptr = info_ptr->text;
if (num_text != NULL)

102
pngmem.c
View File

@@ -1,12 +1,11 @@
/* pngmem.c - stub functions for memory allocation
*
* libpng 0.97
* libpng 0.99c
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson
* January 7, 1998
* February 7, 1998
*
* This file provides a location for all memory allocation. Users which
* need special memory handling are expected to modify the code in this file
@@ -16,6 +15,16 @@
#define PNG_INTERNAL
#include "png.h"
/* The following "hides" PNG_MALLOC and PNG_FREE thus allowing the pngtest
application to put a wrapper on top of them. */
#ifdef PNGTEST_MEMORY_DEBUG
#define PNG_MALLOC png_debug_malloc
#define PNG_FREE png_debug_free
#else
#define PNG_MALLOC png_malloc
#define PNG_FREE png_free
#endif
/* 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 */
@@ -33,7 +42,7 @@ png_create_struct(int type)
else if (type == PNG_STRUCT_PNG)
size = sizeof(png_struct);
else
return (png_voidp)NULL;
return ((png_voidp)NULL);
if ((struct_ptr = (png_voidp)farmalloc(size)) != NULL)
{
@@ -49,7 +58,10 @@ void
png_destroy_struct(png_voidp struct_ptr)
{
if (struct_ptr != NULL)
{
farfree (struct_ptr);
struct_ptr = NULL;
}
}
/* Allocate memory. For reasonable files, size should never exceed
@@ -72,11 +84,11 @@ png_destroy_struct(png_voidp struct_ptr)
* (which should cause a fatal error) and introducing major problems.
*/
png_voidp
png_malloc(png_structp png_ptr, png_uint_32 size)
PNG_MALLOC(png_structp png_ptr, png_uint_32 size)
{
png_voidp ret;
if (png_ptr == NULL || size == 0)
return ((voidp)NULL);
return ((png_voidp)NULL);
#ifdef PNG_MAX_MALLOC_64K
if (size > (png_uint_32)65536L)
@@ -98,8 +110,10 @@ png_malloc(png_structp png_ptr, png_uint_32 size)
png_byte huge * hptr;
if (ret != NULL)
{
farfree(ret);
ret = NULL;
ret = NULL;
}
num_blocks = (int)(1 << (png_ptr->zlib_window_bits - 14));
if (num_blocks < 1)
@@ -115,7 +129,7 @@ png_malloc(png_structp png_ptr, png_uint_32 size)
if (table == NULL)
{
png_error(png_ptr, "Out of Memory");
png_error(png_ptr, "Out Of Memory."); /* Note "O" and "M" */
}
if ((png_size_t)table & 0xfff0)
@@ -129,7 +143,7 @@ png_malloc(png_structp png_ptr, png_uint_32 size)
if (png_ptr->offset_table_ptr == NULL)
{
png_error(png_ptr, "Out of memory");
png_error(png_ptr, "Out Of memory.");
}
hptr = (png_byte huge *)table;
@@ -151,7 +165,7 @@ png_malloc(png_structp png_ptr, png_uint_32 size)
}
if (png_ptr->offset_table_count >= png_ptr->offset_table_number)
png_error(png_ptr, "Out of Memory");
png_error(png_ptr, "Out of Memory.");
ret = png_ptr->offset_table_ptr[png_ptr->offset_table_count++];
}
@@ -160,17 +174,17 @@ png_malloc(png_structp png_ptr, png_uint_32 size)
if (ret == NULL)
{
png_error(png_ptr, "Out of Memory");
png_error(png_ptr, "Out of memory."); /* Note "o" and "m" */
}
return ret;
return (ret);
}
/* free a pointer allocated by png_malloc(). In the default
/* 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
png_free(png_structp png_ptr, png_voidp ptr)
PNG_FREE(png_structp png_ptr, png_voidp ptr)
{
if (png_ptr == NULL || ptr == NULL)
return;
@@ -198,7 +212,10 @@ png_free(png_structp png_ptr, png_voidp ptr)
}
if (ptr != NULL)
{
farfree(ptr);
ptr = NULL;
}
}
#else /* Not the Borland DOS special memory handler */
@@ -217,7 +234,7 @@ png_create_struct(int type)
else if (type == PNG_STRUCT_PNG)
size = sizeof(png_struct);
else
return (png_voidp)NULL;
return ((png_voidp)NULL);
#if defined(__TURBOC__) && !defined(__FLAT__)
if ((struct_ptr = (png_voidp)farmalloc(size)) != NULL)
@@ -241,6 +258,7 @@ void
png_destroy_struct(png_voidp struct_ptr)
{
if (struct_ptr != NULL)
{
#if defined(__TURBOC__) && !defined(__FLAT__)
farfree(struct_ptr);
#else
@@ -250,6 +268,7 @@ png_destroy_struct(png_voidp struct_ptr)
free(struct_ptr);
# endif
#endif
}
}
@@ -260,24 +279,30 @@ png_destroy_struct(png_voidp struct_ptr)
have the ability to do that. */
png_voidp
png_malloc(png_structp png_ptr, png_uint_32 size)
PNG_MALLOC(png_structp png_ptr, png_uint_32 size)
{
png_voidp ret;
png_size_t length;
if (png_ptr == NULL || size == 0)
return (NULL);
return ((png_voidp)NULL);
#ifdef PNG_MAX_MALLOC_64K
if (size > (png_uint_32)65536L)
if (png_size > (png_uint_32)65536L)
png_error(png_ptr, "Cannot Allocate > 64K");
#endif
length = (png_size_t)size;
if ((png_uint_32)length != size)
png_error(png_ptr, "Cannot Allocate > size_t");
#if defined(__TURBOC__) && !defined(__FLAT__)
ret = farmalloc((png_size_t)size);
ret = farmalloc(length);
#else
# if defined(_MSC_VER) && defined(MAXSEG_64K)
ret = halloc(size, 1);
ret = halloc(length, 1);
# else
ret = malloc(size);
ret = malloc(length);
# endif
#endif
@@ -286,14 +311,14 @@ png_malloc(png_structp png_ptr, png_uint_32 size)
png_error(png_ptr, "Out of Memory");
}
return ret;
return (ret);
}
/* Free a pointer allocated by png_malloc(). In the default
/* 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
png_free(png_structp png_ptr, png_voidp ptr)
PNG_FREE(png_structp png_ptr, png_voidp ptr)
{
if (png_ptr == NULL || ptr == NULL)
return;
@@ -311,3 +336,32 @@ png_free(png_structp png_ptr, png_voidp ptr)
#endif /* Not Borland DOS special memory handler */
void
png_buffered_memcpy (png_structp png_ptr, png_voidp s1, png_voidp s2,
png_uint_32 length)
{
png_size_t size;
png_uint_32 i;
for (i=0; i<length; i+=65530)
{
size = (png_size_t)(length - i);
if (size > (png_size_t)65530L)
size=(png_size_t)65530L;
png_memcpy (s1, s2, size);
}
}
void
png_buffered_memset (png_structp png_ptr, png_voidp s1, int value,
png_uint_32 length)
{
png_size_t size;
png_uint_32 i;
for (i=0; i<length; i+=65530)
{
size = length - i;
if (size > 65530)
size=65530;
png_memset (s1, value, size);
}
}

View File

@@ -1,12 +1,12 @@
/* pngpread.c - read a png file in push mode
*
* libpng 0.97
* libpng 0.99c
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson
* January 7, 1998
* February 7, 1998
*/
#define PNG_INTERNAL
@@ -466,7 +466,8 @@ png_push_save_buffer(png_structp png_ptr)
new_max = png_ptr->save_buffer_size + png_ptr->current_buffer_size + 256;
old_buffer = png_ptr->save_buffer;
png_ptr->save_buffer = (png_bytep)png_malloc(png_ptr, new_max);
png_ptr->save_buffer = (png_bytep)png_malloc(png_ptr,
(png_uint_32)new_max);
png_memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size);
png_free(png_ptr, old_buffer);
png_ptr->save_buffer_max = new_max;
@@ -527,7 +528,12 @@ png_push_read_IDAT(png_structp png_ptr)
png_size_t save_size;
if (png_ptr->idat_size < (png_uint_32)png_ptr->save_buffer_size)
save_size = png_ptr->idat_size;
{
save_size = (png_size_t)png_ptr->idat_size;
/* check for overflow */
if((png_uint_32)save_size != png_ptr->idat_size)
png_error(png_ptr, "save_size overflowed in pngpread");
}
else
save_size = png_ptr->save_buffer_size;
@@ -544,7 +550,12 @@ png_push_read_IDAT(png_structp png_ptr)
png_size_t save_size;
if (png_ptr->idat_size < (png_uint_32)png_ptr->current_buffer_size)
save_size = png_ptr->idat_size;
{
save_size = (png_size_t)png_ptr->idat_size;
/* check for overflow */
if((png_uint_32)save_size != png_ptr->idat_size)
png_error(png_ptr, "save_size overflowed in pngpread");
}
else
save_size = png_ptr->current_buffer_size;
@@ -619,6 +630,7 @@ png_push_process_row(png_structp png_ptr)
png_ptr->row_info.channels = png_ptr->channels;
png_ptr->row_info.bit_depth = png_ptr->bit_depth;
png_ptr->row_info.pixel_depth = png_ptr->pixel_depth;
png_ptr->row_info.rowbytes = ((png_ptr->row_info.width *
(png_uint_32)png_ptr->row_info.pixel_depth + 7) >> 3);
@@ -626,7 +638,8 @@ png_push_process_row(png_structp png_ptr)
png_ptr->row_buf + 1, png_ptr->prev_row + 1,
(int)(png_ptr->row_buf[0]));
png_memcpy(png_ptr->prev_row, png_ptr->row_buf, png_ptr->rowbytes + 1);
png_buffered_memcpy(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
png_ptr->rowbytes + 1);
if (png_ptr->transformations)
png_do_read_transformations(png_ptr);
@@ -761,7 +774,8 @@ png_read_push_finish_row(png_structp png_ptr)
if (png_ptr->interlaced)
{
png_ptr->row_number = 0;
png_memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
png_buffered_memset(png_ptr, png_ptr->prev_row, 0,
(png_size_t)png_ptr->rowbytes + 1);
do
{
png_ptr->pass++;
@@ -771,8 +785,7 @@ png_read_push_finish_row(png_structp png_ptr)
png_pass_inc[png_ptr->pass] - 1 -
png_pass_start[png_ptr->pass]) /
png_pass_inc[png_ptr->pass];
png_ptr->irowbytes = ((png_ptr->iwidth *
png_ptr->pixel_depth + 7) >> 3) + 1;
png_ptr->irowbytes = ((png_ptr->pixel_depth + 7) >> 3) + 1;
if (!(png_ptr->transformations & PNG_INTERLACE))
{
png_ptr->num_rows = (png_ptr->height +
@@ -806,11 +819,12 @@ png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length
}
#endif
png_ptr->current_text = (png_charp)png_malloc(png_ptr, length+1);
png_ptr->current_text = (png_charp)png_malloc(png_ptr,
(png_uint_32)(length+1));
png_ptr->current_text[length] = '\0';
png_ptr->current_text_ptr = png_ptr->current_text;
png_ptr->current_text_size = length;
png_ptr->current_text_left = length;
png_ptr->current_text_size = (png_size_t)length;
png_ptr->current_text_left = (png_size_t)length;
png_ptr->process_mode = PNG_READ_tEXt_MODE;
}
@@ -857,7 +871,7 @@ png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr)
if (text != key + png_ptr->current_text_size)
text++;
text_ptr = (png_textp)png_malloc(png_ptr, sizeof(png_text));
text_ptr = (png_textp)png_malloc(png_ptr, (png_uint_32)sizeof(png_text));
text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
text_ptr->key = key;
text_ptr->text = text;
@@ -889,11 +903,12 @@ png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length
}
#endif
png_ptr->current_text = (png_charp)png_malloc(png_ptr, length+1);
png_ptr->current_text = (png_charp)png_malloc(png_ptr,
(png_uint_32)(length+1));
png_ptr->current_text[length] = '\0';
png_ptr->current_text_ptr = png_ptr->current_text;
png_ptr->current_text_size = length;
png_ptr->current_text_left = length;
png_ptr->current_text_size = (png_size_t)length;
png_ptr->current_text_left = (png_size_t)length;
png_ptr->process_mode = PNG_READ_zTXt_MODE;
}
@@ -978,8 +993,8 @@ png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
if (text == NULL)
{
text = (png_charp)png_malloc(png_ptr,
png_ptr->zbuf_size - png_ptr->zstream.avail_out +
key_size + 1);
(png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out +
key_size + 1));
png_memcpy(text + key_size, png_ptr->zbuf,
png_ptr->zbuf_size - png_ptr->zstream.avail_out);
png_memcpy(text, key, key_size);
@@ -992,8 +1007,9 @@ png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
png_charp tmp;
tmp = text;
text = png_malloc(png_ptr, text_size +
png_ptr->zbuf_size - png_ptr->zstream.avail_out + 1);
text = (png_charp)png_malloc(png_ptr, text_size +
(png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out
+ 1));
png_memcpy(text, tmp, text_size);
png_free(png_ptr, tmp);
png_memcpy(text + text_size, png_ptr->zbuf,
@@ -1029,9 +1045,8 @@ png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
png_free(png_ptr, key);
key = text;
text += key_size;
text_size -= key_size;
text_ptr = (png_textp)png_malloc(png_ptr, sizeof(png_text));
text_ptr = (png_textp)png_malloc(png_ptr, (png_uint_32)sizeof(png_text));
text_ptr->compression = PNG_TEXT_COMPRESSION_zTXt;
text_ptr->key = key;
text_ptr->text = text;

View File

@@ -1,12 +1,12 @@
/* pngread.c - read a PNG file
*
* libpng 0.97
* libpng 0.99c
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson
* January 7, 1998
* February 7, 1998
*
* This file contains routines that an application calls directly to
* read a PNG file or stream.
@@ -17,7 +17,7 @@
/* Create a PNG structure for reading, and allocate any memory needed. */
png_structp
png_create_read_struct(png_const_charp user_png_ver, png_voidp error_ptr,
png_create_read_struct(png_const_charp user_png_ver, voidp error_ptr,
png_error_ptr error_fn, png_error_ptr warn_fn)
{
png_structp png_ptr;
@@ -58,7 +58,8 @@ png_create_read_struct(png_const_charp user_png_ver, png_voidp error_ptr,
/* initialize zbuf - compression buffer */
png_ptr->zbuf_size = PNG_ZBUF_SIZE;
png_ptr->zbuf = png_malloc(png_ptr, png_ptr->zbuf_size);
png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
(png_uint_32)png_ptr->zbuf_size);
png_ptr->zstream.zalloc = png_zalloc;
png_ptr->zstream.zfree = png_zfree;
png_ptr->zstream.opaque = (voidpf)png_ptr;
@@ -100,7 +101,8 @@ png_read_init(png_structp png_ptr)
/* initialize zbuf - compression buffer */
png_ptr->zbuf_size = PNG_ZBUF_SIZE;
png_ptr->zbuf = png_malloc(png_ptr, png_ptr->zbuf_size);
png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
(png_uint_32)png_ptr->zbuf_size);
png_ptr->zstream.zalloc = png_zalloc;
png_ptr->zstream.zfree = png_zfree;
png_ptr->zstream.opaque = (voidpf)png_ptr;
@@ -407,14 +409,17 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
png_ptr->row_info.channels = png_ptr->channels;
png_ptr->row_info.bit_depth = png_ptr->bit_depth;
png_ptr->row_info.pixel_depth = png_ptr->pixel_depth;
png_ptr->row_info.rowbytes = ((png_ptr->row_info.width *
(png_uint_32)png_ptr->row_info.pixel_depth + 7) >> 3);
{
png_ptr->row_info.rowbytes = ((png_ptr->row_info.width *
(png_uint_32)png_ptr->row_info.pixel_depth + 7) >> 3);
}
png_read_filter_row(png_ptr, &(png_ptr->row_info),
png_ptr->row_buf + 1, png_ptr->prev_row + 1,
(int)(png_ptr->row_buf[0]));
png_memcpy(png_ptr->prev_row, png_ptr->row_buf, png_ptr->rowbytes + 1);
png_buffered_memcpy(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
png_ptr->rowbytes + 1);
if (png_ptr->transformations)
png_do_read_transformations(png_ptr);
@@ -655,12 +660,18 @@ png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
if (info_ptr != NULL)
{
#if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_READ_zTXt_SUPPORTED)
png_free(png_ptr, info_ptr->text);
#endif
png_destroy_struct((png_voidp)info_ptr);
*info_ptr_ptr = (png_infop)NULL;
}
if (end_info_ptr != NULL)
{
#if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_READ_zTXt_SUPPORTED)
png_free(png_ptr, end_info_ptr->text);
#endif
png_destroy_struct((png_voidp)end_info_ptr);
*end_info_ptr_ptr = (png_infop)NULL;
}
@@ -704,7 +715,7 @@ png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr
png_free(png_ptr, png_ptr->gamma_to_1);
#endif
if (png_ptr->flags & PNG_FLAG_FREE_PALETTE)
png_free(png_ptr, png_ptr->palette);
png_zfree(png_ptr, png_ptr->palette);
#if defined(PNG_READ_BACKGROUND_SUPPORTED) && defined(PNG_READ_bKGD_SUPPORTED)
if (png_ptr->flags & PNG_FLAG_FREE_TRANS)
png_free(png_ptr, png_ptr->trans);

View File

@@ -1,12 +1,12 @@
/* pngrio.c - functions for data input
*
* libpng 0.97
* libpng 0.99c
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson
* January 7, 1998
* February 7, 1998
*
* This file provides a location for all input. Users which need
* special handling are expected to write a function which has the same
@@ -99,7 +99,7 @@ png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
}
while (remaining != 0);
}
if (check != length)
if ((png_uint_32)check != (png_uint_32)length)
{
png_error(png_ptr, "read Error");
}

View File

@@ -1,12 +1,12 @@
/* pngrtran.c - transforms the data in a row for PNG readers
*
* libpng 0.97
* libpng 0.99c
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson
* January 7, 1998
* February 7, 1998
*
* This file contains functions optionally called by an application
* in order to tell libpng how to handle data when reading a PNG.
@@ -184,7 +184,7 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
int i;
png_ptr->dither_index = (png_bytep)png_malloc(png_ptr,
num_palette * sizeof (png_byte));
(png_uint_32)(num_palette * sizeof (png_byte)));
for (i = 0; i < num_palette; i++)
png_ptr->dither_index[i] = (png_byte)i;
}
@@ -200,7 +200,8 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
png_bytep sort;
/* initialize an array to sort colors */
sort = (png_bytep)png_malloc(png_ptr, num_palette * sizeof (png_byte));
sort = (png_bytep)png_malloc(png_ptr, (png_uint_32)(num_palette
* sizeof (png_byte)));
/* initialize the sort array */
for (i = 0; i < num_palette; i++)
@@ -243,11 +244,11 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
move the others */
for (i = 0, j = num_palette; i < maximum_colors; i++)
{
if (sort[i] >= maximum_colors)
if ((int)sort[i] >= maximum_colors)
{
do
j--;
while (sort[j] >= maximum_colors);
while ((int)sort[j] >= maximum_colors);
palette[i] = palette[j];
}
}
@@ -261,13 +262,13 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
for (i = 0, j = num_palette; i < maximum_colors; i++)
{
/* only move the colors we need to */
if (sort[i] >= maximum_colors)
if ((int)sort[i] >= maximum_colors)
{
png_color tmp_color;
do
j--;
while (sort[j] >= maximum_colors);
while ((int)sort[j] >= maximum_colors);
tmp_color = palette[j];
palette[j] = palette[i];
@@ -281,7 +282,7 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
/* find closest color for those colors we are not using */
for (i = 0; i < num_palette; i++)
{
if (png_ptr->dither_index[i] >= maximum_colors)
if ((int)png_ptr->dither_index[i] >= maximum_colors)
{
int min_d, k, min_k, d_index;
@@ -328,9 +329,9 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
/* initialize palette index arrays */
index_to_palette = (png_bytep)png_malloc(png_ptr,
num_palette * sizeof (png_byte));
(png_uint_32)(num_palette * sizeof (png_byte)));
palette_to_index = (png_bytep)png_malloc(png_ptr,
num_palette * sizeof (png_byte));
(png_uint_32)(num_palette * sizeof (png_byte)));
/* initialize the sort array */
for (i = 0; i < num_palette; i++)
@@ -339,7 +340,8 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
palette_to_index[i] = (png_byte)i;
}
hash = (png_dsortpp)png_malloc(png_ptr, 769 * sizeof (png_dsortp));
hash = (png_dsortpp)png_malloc(png_ptr, (png_uint_32)(769 *
sizeof (png_dsortp)));
for (i = 0; i < 769; i++)
hash[i] = NULL;
/* png_memset(hash, 0, 769 * sizeof (png_dsortp)); */
@@ -372,7 +374,8 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
{
png_dsortp t;
t = png_malloc(png_ptr, sizeof (png_dsort));
t = (png_dsortp)png_malloc(png_ptr, (png_uint_32)(sizeof
(png_dsort)));
t->next = hash[d];
t->left = (png_byte)i;
t->right = (png_byte)j;
@@ -389,8 +392,8 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
for (p = hash[i]; p; p = p->next)
{
if (index_to_palette[p->left] < num_new_palette &&
index_to_palette[p->right] < num_new_palette)
if ((int)index_to_palette[p->left] < num_new_palette &&
(int)index_to_palette[p->right] < num_new_palette)
{
int j, next_j;
@@ -417,7 +420,7 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
index_to_palette[j])
png_ptr->dither_index[k] =
index_to_palette[next_j];
if (png_ptr->dither_index[k] ==
if ((int)png_ptr->dither_index[k] ==
num_new_palette)
png_ptr->dither_index[k] =
index_to_palette[j];
@@ -488,11 +491,12 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
num_entries = ((png_size_t)1 << total_bits);
png_ptr->palette_lookup = (png_bytep )png_malloc(png_ptr,
num_entries * sizeof (png_byte));
(png_uint_32)(num_entries * sizeof (png_byte)));
png_memset(png_ptr->palette_lookup, 0, num_entries * sizeof (png_byte));
distance = (png_bytep)png_malloc(png_ptr, num_entries * sizeof(png_byte));
distance = (png_bytep)png_malloc(png_ptr, (png_uint_32)(num_entries *
sizeof(png_byte)));
png_memset(distance, 0xff, num_entries * sizeof(png_byte));
@@ -527,7 +531,7 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
dmax = ((dm > db) ? dm : db);
d = dmax + dt + db;
if (d < distance[d_index])
if (d < (int)distance[d_index])
{
distance[d_index] = (png_byte)d;
png_ptr->palette_lookup[d_index] = (png_byte)i;
@@ -549,13 +553,13 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
* also needlessly introduces small errors.
*/
void
png_set_gamma(png_structp png_ptr, double screen_gamma, double file_gamma)
png_set_gamma(png_structp png_ptr, double scrn_gamma, double file_gamma)
{
png_debug(1, "in png_set_gamma\n");
if (fabs(screen_gamma * file_gamma - 1.0) > PNG_GAMMA_THRESHOLD)
if (fabs(scrn_gamma * file_gamma - 1.0) > PNG_GAMMA_THRESHOLD)
png_ptr->transformations |= PNG_GAMMA;
png_ptr->gamma = (float)file_gamma;
png_ptr->display_gamma = (float)screen_gamma;
png_ptr->screen_gamma = (float)scrn_gamma;
}
#endif
@@ -592,6 +596,7 @@ png_set_rgb_to_gray(png_structp png_ptr, int gray_bits)
png_debug(1, "in png_set_rgb_to_gray\n");
png_ptr->transformations |= PNG_RGB_TO_GRAY;
/* Need to do something with gray_bits here. */
png_warning(png_ptr, "RGB to GRAY transformation is not yet implemented.");
}
#endif
@@ -644,6 +649,23 @@ png_init_read_transformations(png_structp png_ptr)
png_ptr->palette[png_ptr->background.index].green;
png_ptr->background.blue =
png_ptr->palette[png_ptr->background.index].blue;
#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
if (png_ptr->transformations & PNG_INVERT_ALPHA)
{
#if defined(PNG_READ_EXPAND_SUPPORTED)
if (png_ptr->transformations & !PNG_EXPAND)
#endif
{
/* invert the alpha channel (in tRNS) unless the pixels are
going to be expanded, in which case leave it for later */
int i;
for (i=0; i<(int)png_ptr->num_trans; i++)
png_ptr->trans[i] = 255 - png_ptr->trans[i];
}
}
#endif
}
}
#endif
@@ -681,7 +703,7 @@ png_init_read_transformations(png_structp png_ptr)
{
double g;
g = 1.0 / (png_ptr->background_gamma * png_ptr->display_gamma);
g = 1.0 / (png_ptr->background_gamma * png_ptr->screen_gamma);
if (png_ptr->background_gamma_type==PNG_BACKGROUND_GAMMA_SCREEN||
fabs(g - 1.0) < PNG_GAMMA_THRESHOLD)
@@ -761,17 +783,17 @@ png_init_read_transformations(png_structp png_ptr)
switch (png_ptr->background_gamma_type)
{
case PNG_BACKGROUND_GAMMA_SCREEN:
g = (png_ptr->display_gamma);
g = (png_ptr->screen_gamma);
gs = 1.0;
break;
case PNG_BACKGROUND_GAMMA_FILE:
g = 1.0 / (png_ptr->gamma);
gs = 1.0 / (png_ptr->gamma * png_ptr->display_gamma);
gs = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
break;
case PNG_BACKGROUND_GAMMA_UNIQUE:
g = 1.0 / (png_ptr->background_gamma);
gs = 1.0 / (png_ptr->background_gamma *
png_ptr->display_gamma);
png_ptr->screen_gamma);
break;
}
@@ -834,7 +856,7 @@ png_init_read_transformations(png_structp png_ptr)
back.green = (png_byte)png_ptr->background.green;
back.blue = (png_byte)png_ptr->background.blue;
for (i = 0; i < png_ptr->num_trans; i++)
for (i = 0; i < (int)png_ptr->num_trans; i++)
{
if (png_ptr->trans[i] == 0)
{
@@ -954,7 +976,7 @@ png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
else
info_ptr->channels = 1;
#if defined(PNG_STRIP_ALPHA_SUPPORTED)
#if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
if ((png_ptr->transformations & PNG_STRIP_ALPHA) &&
info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
{
@@ -977,8 +999,7 @@ png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
info_ptr->pixel_depth = (png_byte)(info_ptr->channels *
info_ptr->bit_depth);
info_ptr->rowbytes =
(png_size_t)((info_ptr->width * info_ptr->pixel_depth + 7) >> 3);
info_ptr->rowbytes = ((info_ptr->width * info_ptr->pixel_depth + 7) >> 3);
}
/* Transform the row. The order of transformations is significant,
@@ -1067,6 +1088,8 @@ png_do_read_transformations(png_structp png_ptr)
{
png_do_dither((png_row_infop)&(png_ptr->row_info), png_ptr->row_buf + 1,
png_ptr->palette_lookup, png_ptr->dither_index);
if(png_ptr->row_info.rowbytes == (png_uint_32)0)
png_error(png_ptr, "png_do_dither returned rowbytes=0");
}
#endif
@@ -1112,6 +1135,11 @@ png_do_read_transformations(png_structp png_ptr)
png_do_read_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
#endif
#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
if (png_ptr->transformations & PNG_INVERT_ALPHA)
png_do_read_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
#endif
#if defined(PNG_READ_SWAP_SUPPORTED)
if (png_ptr->transformations & PNG_SWAP_BYTES)
png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
@@ -1204,7 +1232,7 @@ png_do_unpack(png_row_infop row_info, png_bytep row)
}
row_info->bit_depth = 8;
row_info->pixel_depth = (png_byte)(8 * row_info->channels);
row_info->rowbytes = (png_size_t)row_info->width * row_info->channels;
row_info->rowbytes = row_info->width * row_info->channels;
}
}
#endif
@@ -1263,7 +1291,7 @@ png_do_unshift(png_row_infop row_info, png_bytep row, png_color_8p sig_bits)
case 2:
{
png_bytep bp;
png_size_t i;
png_uint_32 i;
for (bp = row, i = 0; i < row_info->rowbytes; i++, bp++)
{
@@ -1276,7 +1304,7 @@ png_do_unshift(png_row_infop row_info, png_bytep row, png_color_8p sig_bits)
{
png_bytep bp;
png_byte mask;
png_size_t i;
png_uint_32 i;
mask = (png_byte)(((int)0xf0 >> shift[0]) & (int)0xf0) |
(png_byte)((int)0xf >> shift[0]);
@@ -1290,11 +1318,11 @@ png_do_unshift(png_row_infop row_info, png_bytep row, png_color_8p sig_bits)
case 8:
{
png_bytep bp;
png_size_t i;
png_uint_32 i;
for (bp = row, i = 0; i < row_info->width; i++)
{
for (c = 0; c < row_info->channels; c++, bp++)
for (c = 0; c < (int)row_info->channels; c++, bp++)
{
*bp >>= shift[c];
}
@@ -1308,7 +1336,7 @@ png_do_unshift(png_row_infop row_info, png_bytep row, png_color_8p sig_bits)
for (bp = row, i = 0; i < row_info->width; i++)
{
for (c = 0; c < row_info->channels; c++, bp += 2)
for (c = 0; c < (int)row_info->channels; c++, bp += 2)
{
value = (png_uint_16)((*bp << 8) + *(bp + 1));
value >>= shift[c];
@@ -1372,7 +1400,7 @@ png_do_chop(png_row_infop row_info, png_bytep row)
}
row_info->bit_depth = 8;
row_info->pixel_depth = (png_byte)(8 * row_info->channels);
row_info->rowbytes = (png_size_t)row_info->width * row_info->channels;
row_info->rowbytes = row_info->width * row_info->channels;
}
}
#endif
@@ -1468,6 +1496,87 @@ png_do_read_swap_alpha(png_row_infop row_info, png_bytep row)
}
#endif
#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
void
png_do_read_invert_alpha(png_row_infop row_info, png_bytep row)
{
png_debug(1, "in png_do_read_invert_alpha\n");
#if defined(PNG_USELESS_TESTS_SUPPORTED)
if (row != NULL && row_info != NULL)
#endif
{
if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
{
/* This inverts the alpha channel in RGBA */
if (row_info->bit_depth == 8)
{
png_bytep sp, dp;
png_uint_32 i;
for (i = 0, sp = dp = row + row_info->rowbytes;
i < row_info->width; i++)
{
*(--dp) = *(--sp);
*(--dp) = *(--sp);
*(--dp) = *(--sp);
*(--dp) = 255 - *(--sp);
}
}
/* This inverts the alpha channel in RRGGBBAA */
else
{
png_bytep sp, dp;
png_uint_32 i;
for (i = 0, sp = dp = row + row_info->rowbytes;
i < row_info->width; i++)
{
*(--dp) = *(--sp);
*(--dp) = *(--sp);
*(--dp) = *(--sp);
*(--dp) = *(--sp);
*(--dp) = *(--sp);
*(--dp) = *(--sp);
*(--dp) = 255 - *(--sp);
*(--dp) = 255 - *(--sp);
}
}
}
else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
{
/* This inverts the alpha channel in AG */
if (row_info->bit_depth == 8)
{
png_bytep sp, dp;
png_uint_32 i;
for (i = 0, sp = dp = row + row_info->rowbytes;
i < row_info->width; i++)
{
*(--dp) = *(--sp);
*(--dp) = 255 - *(--sp);
}
}
/* This inverts the alpha channel in AAGG */
else
{
png_bytep sp, dp;
png_uint_32 i;
for (i = 0, sp = dp = row + row_info->rowbytes;
i < row_info->width; i++)
{
*(--dp) = *(--sp);
*(--dp) = *(--sp);
*(--dp) = 255 - *(--sp);
*(--dp) = 255 - *(--sp);
}
}
}
}
}
#endif
#if defined(PNG_READ_FILLER_SUPPORTED)
/* Add filler channel if we have RGB color */
void
@@ -1500,7 +1609,7 @@ png_do_read_filler(png_row_infop row_info, png_bytep row,
*(--dp) = (png_byte)filler;
row_info->channels = 4;
row_info->pixel_depth = 32;
row_info->rowbytes = (png_size_t)row_info->width * 4;
row_info->rowbytes = row_info->width * 4;
}
/* This changes the data from RGB to XRGB */
else
@@ -1517,7 +1626,7 @@ png_do_read_filler(png_row_infop row_info, png_bytep row,
}
row_info->channels = 4;
row_info->pixel_depth = 32;
row_info->rowbytes = (png_size_t)row_info->width * 4;
row_info->rowbytes = row_info->width * 4;
}
}
}
@@ -1611,7 +1720,7 @@ png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
row_info->color_type |= PNG_COLOR_MASK_COLOR;
row_info->pixel_depth = (png_byte)(row_info->channels *
row_info->bit_depth);
row_info->rowbytes = (png_size_t)((row_info->width *
row_info->rowbytes = ((row_info->width *
row_info->pixel_depth + 7) >> 3);
}
}
@@ -1693,7 +1802,7 @@ png_correct_palette(png_structp png_ptr, png_colorp palette,
{
double g;
g = 1.0 / (png_ptr->background_gamma * png_ptr->display_gamma);
g = 1.0 / (png_ptr->background_gamma * png_ptr->screen_gamma);
if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_SCREEN ||
fabs(g - 1.0) < PNG_GAMMA_THRESHOLD)
@@ -1889,7 +1998,8 @@ png_do_background(png_row_infop row_info, png_bytep row,
shift = 7;
for (i = 0; i < row_info->width; i++)
{
if (((*sp >> shift) & 0x1) == trans_values->gray)
if ((png_uint_16)((*sp >> shift) & 0x1)
== trans_values->gray)
{
*sp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
*sp |= (png_byte)(background->gray << shift);
@@ -1910,7 +2020,8 @@ png_do_background(png_row_infop row_info, png_bytep row,
shift = 6;
for (i = 0; i < row_info->width; i++)
{
if (((*sp >> shift) & 0x3) == trans_values->gray)
if ((png_uint_16)((*sp >> shift) & 0x3)
== trans_values->gray)
{
*sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
*sp |= (png_byte)(background->gray << shift);
@@ -1931,7 +2042,8 @@ png_do_background(png_row_infop row_info, png_bytep row,
shift = 4;
for (i = 0; i < row_info->width; i++)
{
if (((*sp >> shift) & 0xf) == trans_values->gray)
if ((png_uint_16)((*sp >> shift) & 0xf)
== trans_values->gray)
{
*sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
*sp |= (png_byte)(background->gray << shift);
@@ -2439,7 +2551,7 @@ png_do_background(png_row_infop row_info, png_bytep row,
row_info->channels--;
row_info->pixel_depth = (png_byte)(row_info->channels *
row_info->bit_depth);
row_info->rowbytes = (png_size_t)((row_info->width *
row_info->rowbytes = ((row_info->width *
row_info->pixel_depth + 7) >> 3);
}
}
@@ -2720,7 +2832,7 @@ png_do_expand_palette(png_row_infop row_info, png_bytep row,
}
row_info->bit_depth = 8;
row_info->pixel_depth = 8;
row_info->rowbytes = (png_size_t)row_info->width;
row_info->rowbytes = row_info->width;
}
switch (row_info->bit_depth)
{
@@ -2744,7 +2856,7 @@ png_do_expand_palette(png_row_infop row_info, png_bytep row,
}
row_info->bit_depth = 8;
row_info->pixel_depth = 32;
row_info->rowbytes = (png_size_t)row_info->width * 4;
row_info->rowbytes = row_info->width * 4;
row_info->color_type = 6;
row_info->channels = 4;
}
@@ -2762,7 +2874,7 @@ png_do_expand_palette(png_row_infop row_info, png_bytep row,
}
row_info->bit_depth = 8;
row_info->pixel_depth = 24;
row_info->rowbytes = (png_size_t)row_info->width * 3;
row_info->rowbytes = row_info->width * 3;
row_info->color_type = 2;
row_info->channels = 3;
}
@@ -2868,7 +2980,7 @@ png_do_expand(png_row_infop row_info, png_bytep row,
}
row_info->bit_depth = 8;
row_info->pixel_depth = 8;
row_info->rowbytes = (png_size_t)row_info->width;
row_info->rowbytes = row_info->width;
}
if (trans_value != NULL)
@@ -2911,7 +3023,7 @@ png_do_expand(png_row_infop row_info, png_bytep row,
row_info->channels = 2;
row_info->pixel_depth = (png_byte)(row_info->bit_depth << 1);
row_info->rowbytes =
(png_size_t)((row_info->width * row_info->pixel_depth) >> 3);
((row_info->width * row_info->pixel_depth) >> 3);
}
}
else if (row_info->color_type == PNG_COLOR_TYPE_RGB && trans_value)
@@ -2966,7 +3078,7 @@ png_do_expand(png_row_infop row_info, png_bytep row,
row_info->channels = 4;
row_info->pixel_depth = (png_byte)(row_info->bit_depth << 2);
row_info->rowbytes =
(png_size_t)((row_info->width * row_info->pixel_depth) >> 3);
((row_info->width * row_info->pixel_depth) >> 3);
}
}
}
@@ -3019,7 +3131,7 @@ png_do_dither(png_row_infop row_info, png_bytep row,
row_info->channels = 1;
row_info->pixel_depth = row_info->bit_depth;
row_info->rowbytes =
((row_info->width * row_info->pixel_depth + 7) >> 3);
((row_info->width * row_info->pixel_depth + 7) >> 3);
}
else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
palette_lookup != NULL && row_info->bit_depth == 8)
@@ -3049,7 +3161,7 @@ png_do_dither(png_row_infop row_info, png_bytep row,
row_info->channels = 1;
row_info->pixel_depth = row_info->bit_depth;
row_info->rowbytes =
(png_size_t)((row_info->width * row_info->pixel_depth + 7) >> 3);
((row_info->width * row_info->pixel_depth + 7) >> 3);
}
else if (row_info->color_type == PNG_COLOR_TYPE_PALETTE &&
dither_lookup && row_info->bit_depth == 8)
@@ -3082,7 +3194,7 @@ png_build_gamma_table(png_structp png_ptr)
int i;
double g;
g = 1.0 / (png_ptr->gamma * png_ptr->display_gamma);
g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
png_ptr->gamma_table = (png_bytep)png_malloc(png_ptr,
(png_uint_32)256);
@@ -3107,7 +3219,7 @@ png_build_gamma_table(png_structp png_ptr)
g) * 255.0 + .5);
}
g = 1.0 / (png_ptr->display_gamma);
g = 1.0 / (png_ptr->screen_gamma);
png_ptr->gamma_from_1 = (png_bytep)png_malloc(png_ptr,
(png_uint_32)256);
@@ -3160,10 +3272,10 @@ png_build_gamma_table(png_structp png_ptr)
num = (1 << (8 - shift));
g = 1.0 / (png_ptr->gamma * png_ptr->display_gamma);
g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
png_ptr->gamma_16_table = (png_uint_16pp)png_malloc(png_ptr,
num * sizeof (png_uint_16p));
(png_uint_32)(num * sizeof (png_uint_16p)));
if ((png_ptr->transformations & PNG_16_TO_8) &&
!(png_ptr->transformations & PNG_BACKGROUND))
@@ -3174,7 +3286,7 @@ png_build_gamma_table(png_structp png_ptr)
for (i = 0; i < num; i++)
{
png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
256 * sizeof (png_uint_16));
(png_uint_32)(256 * sizeof (png_uint_16)));
}
g = 1.0 / g;
@@ -3204,7 +3316,7 @@ png_build_gamma_table(png_structp png_ptr)
for (i = 0; i < num; i++)
{
png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
256 * sizeof (png_uint_16));
(png_uint_32)(256 * sizeof (png_uint_16)));
ig = (((png_uint_32)i * (png_uint_32)png_gamma_shift[shift]) >> 4);
for (j = 0; j < 256; j++)
@@ -3222,12 +3334,12 @@ png_build_gamma_table(png_structp png_ptr)
g = 1.0 / (png_ptr->gamma);
png_ptr->gamma_16_to_1 = (png_uint_16pp)png_malloc(png_ptr,
num * sizeof (png_uint_16p ));
(png_uint_32)(num * sizeof (png_uint_16p )));
for (i = 0; i < num; i++)
{
png_ptr->gamma_16_to_1[i] = (png_uint_16p)png_malloc(png_ptr,
256 * sizeof (png_uint_16));
(png_uint_32)(256 * sizeof (png_uint_16)));
ig = (((png_uint_32)i *
(png_uint_32)png_gamma_shift[shift]) >> 4);
@@ -3238,15 +3350,15 @@ png_build_gamma_table(png_structp png_ptr)
65535.0, g) * 65535.0 + .5);
}
}
g = 1.0 / (png_ptr->display_gamma);
g = 1.0 / (png_ptr->screen_gamma);
png_ptr->gamma_16_from_1 = (png_uint_16pp)png_malloc(png_ptr,
num * sizeof (png_uint_16p));
(png_uint_32)(num * sizeof (png_uint_16p)));
for (i = 0; i < num; i++)
{
png_ptr->gamma_16_from_1[i] = (png_uint_16p)png_malloc(png_ptr,
256 * sizeof (png_uint_16));
(png_uint_32)(256 * sizeof (png_uint_16)));
ig = (((png_uint_32)i *
(png_uint_32)png_gamma_shift[shift]) >> 4);

View File

@@ -1,12 +1,12 @@
/* pngrutil.c - utilities to read a PNG file
*
* libpng 0.97
* libpng 0.99
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson
* January 7, 1998
* February 7, 1998
*
* This file contains routines which are only called from within
* libpng itself during the course of reading an image.
@@ -27,7 +27,7 @@ png_get_uint_32(png_bytep buf)
((png_uint_32)(*(buf + 2)) << 8) +
(png_uint_32)(*(buf + 3));
return i;
return (i);
}
#if defined(PNG_READ_pCAL_SUPPORTED)
@@ -44,7 +44,7 @@ png_get_int_32(png_bytep buf)
((png_int_32)(*(buf + 2)) << 8) +
(png_int_32)(*(buf + 3));
return i;
return (i);
}
#endif /* PNG_READ_pCAL_SUPPORTED */
@@ -57,7 +57,7 @@ png_get_uint_16(png_bytep buf)
i = (png_uint_16)(((png_uint_16)(*buf) << 8) +
(png_uint_16)(*(buf + 1)));
return i;
return (i);
}
#endif /* PNG_READ_BIG_ENDIAN_SUPPORTED */
@@ -100,13 +100,13 @@ png_crc_finish(png_structp png_ptr, png_uint_32 skip)
{
png_chunk_error(png_ptr, "CRC error");
}
return 1;
return (1);
}
return 0;
return (0);
}
/* Compare the CRC stored in the PNG file with that calulated by libpng from
/* Compare the CRC stored in the PNG file with that calculated by libpng from
the data it has read thus far. */
int
png_crc_error(png_structp png_ptr)
@@ -132,10 +132,10 @@ png_crc_error(png_structp png_ptr)
if (need_crc)
{
crc = png_get_uint_32(crc_bytes);
return (crc != png_ptr->crc);
return ((int)(crc != png_ptr->crc));
}
else
return 0;
return (0);
}
@@ -226,7 +226,7 @@ png_handle_IHDR(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
/* set up other useful info */
png_ptr->pixel_depth = (png_byte)(png_ptr->bit_depth *
png_ptr->channels);
png_ptr->channels);
png_ptr->rowbytes = ((png_ptr->width *
(png_uint_32)png_ptr->pixel_depth + 7) >> 3);
png_debug1(3,"bit_depth = %d\n", png_ptr->bit_depth);
@@ -281,7 +281,7 @@ png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
}
num = (int)length / 3;
palette = (png_colorp)png_zalloc(png_ptr, num, sizeof (png_color));
palette = (png_colorp)png_zalloc(png_ptr, (uInt)num, sizeof (png_color));
png_ptr->flags |= PNG_FLAG_FREE_PALETTE;
for (i = 0; i < num; i++)
{
@@ -298,10 +298,13 @@ png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
whatever the normal CRC configuration tells us. However, if we
have an RGB image, the PLTE can be considered ancillary, so
we will act as though it is. */
#if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
#endif
{
png_crc_finish(png_ptr, 0);
}
#if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
else if (png_crc_error(png_ptr)) /* Only if we have a CRC error */
{
/* If we don't want to use the data from an ancillary chunk,
@@ -318,7 +321,7 @@ png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
{
png_chunk_warning(png_ptr, "CRC error");
png_ptr->flags &= ~PNG_FLAG_FREE_PALETTE;
png_free(png_ptr, palette);
png_zfree(png_ptr, palette);
return;
}
}
@@ -328,7 +331,7 @@ png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_chunk_warning(png_ptr, "CRC error");
}
}
#endif
png_ptr->palette = palette;
png_ptr->num_palette = (png_uint_16)num;
png_set_PLTE(png_ptr, info_ptr, palette, num);
@@ -416,7 +419,9 @@ png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
#endif /* PNG_READ_sRGB_SUPPORTED */
file_gamma = (float)igamma / (float)100000.0;
#ifdef PNG_READ_GAMMA_SUPPORTED
png_ptr->gamma = file_gamma;
#endif
png_set_gAMA(png_ptr, info_ptr, file_gamma);
}
#endif
@@ -626,7 +631,7 @@ png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
void
png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
{
png_byte intent;
int intent;
png_byte buf[1];
png_debug(1, "in png_handle_sRGB\n");
@@ -663,13 +668,13 @@ png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
intent = buf[0];
/* check for bad intent */
if (intent > 3)
if (intent >= PNG_sRGB_INTENT_LAST)
{
png_warning(png_ptr, "Unknown sRGB intent");
return;
}
#ifdef PNG_READ_gAMA_SUPPORTED
#if defined(PNG_READ_gAMA_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
if ((info_ptr->valid & PNG_INFO_gAMA))
if((png_uint_32)(png_ptr->gamma*(float)100000.+.5) != (png_uint_32)45000L)
{
@@ -904,7 +909,7 @@ png_handle_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
num = (int)length / 2;
png_ptr->hist = (png_uint_16p)png_malloc(png_ptr,
num * sizeof (png_uint_16));
(png_uint_32)(num * sizeof (png_uint_16)));
png_ptr->flags |= PNG_FLAG_FREE_HIST;
for (i = 0; i < num; i++)
{
@@ -1092,10 +1097,11 @@ png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
for (buf = units; *buf != '\0'; buf++);
png_debug(3, "Allocating pCAL parameters array\n");
params = (png_charpp)png_malloc(png_ptr, nparams*sizeof(png_charp)) ;
params = (png_charpp)png_malloc(png_ptr, (png_uint_32)(nparams
*sizeof(png_charp))) ;
/* Get pointers to the start of each parameter string. */
for (i = 0; i < nparams; i++)
for (i = 0; i < (int)nparams; i++)
{
buf++; /* Skip the null string terminator from previous parameter. */
@@ -1208,7 +1214,7 @@ png_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
if (text != key + (png_size_t)length)
text++;
text_ptr = (png_textp)png_malloc(png_ptr, sizeof(png_text));
text_ptr = (png_textp)png_malloc(png_ptr, (png_uint_32)sizeof(png_text));
text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
text_ptr->key = key;
text_ptr->text = text;
@@ -1298,14 +1304,14 @@ png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
if (text == NULL)
{
text_size = key_size + sizeof(msg) + 1;
text = (png_charp)png_malloc(png_ptr, text_size);
text = (png_charp)png_malloc(png_ptr, (png_uint_32)text_size);
png_memcpy(text, key, key_size);
}
text[text_size - 1] = '\0';
/* Copy what we can of the error message into the text chunk */
text_size = length - (text - key) - 1;
text_size = (png_size_t)length - (text - key) - 1;
text_size = sizeof(msg) > text_size ? text_size : sizeof(msg);
png_memcpy(text + key_size, msg, text_size + 1);
break;
@@ -1315,8 +1321,8 @@ png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
if (text == NULL)
{
text = (png_charp)png_malloc(png_ptr,
png_ptr->zbuf_size - png_ptr->zstream.avail_out +
key_size + 1);
(png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out
+ key_size + 1));
png_memcpy(text + key_size, png_ptr->zbuf,
png_ptr->zbuf_size - png_ptr->zstream.avail_out);
png_memcpy(text, key, key_size);
@@ -1329,8 +1335,8 @@ png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_charp tmp;
tmp = text;
text = png_malloc(png_ptr, text_size +
png_ptr->zbuf_size - png_ptr->zstream.avail_out + 1);
text = (png_charp)png_malloc(png_ptr, (png_uint_32)(text_size +
png_ptr->zbuf_size - png_ptr->zstream.avail_out + 1));
png_memcpy(text, tmp, text_size);
png_free(png_ptr, tmp);
png_memcpy(text + text_size, png_ptr->zbuf,
@@ -1356,7 +1362,6 @@ png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_free(png_ptr, key);
key = text;
text += key_size;
text_size -= key_size;
}
else /* if (comp_type >= PNG_TEXT_COMPRESSION_LAST) */
{
@@ -1376,7 +1381,7 @@ png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_memcpy(text, msg, text_size + 1);
}
text_ptr = (png_textp)png_malloc(png_ptr, sizeof(png_text));
text_ptr = (png_textp)png_malloc(png_ptr, (png_uint_32)sizeof(png_text));
text_ptr->compression = comp_type;
text_ptr->key = key;
text_ptr->text = text;
@@ -1874,6 +1879,7 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row,
png_debug(1, "in png_read_filter_row\n");
png_debug2(2,"row = %d, filter = %d\n", png_ptr->row_number, filter);
switch (filter)
{
case PNG_FILTER_VALUE_NONE:
@@ -1987,7 +1993,7 @@ png_read_finish_row(png_structp png_ptr)
if (png_ptr->interlaced)
{
png_ptr->row_number = 0;
png_memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
png_buffered_memset(png_ptr, png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
do
{
png_ptr->pass++;
@@ -1997,8 +2003,9 @@ png_read_finish_row(png_structp png_ptr)
png_pass_inc[png_ptr->pass] - 1 -
png_pass_start[png_ptr->pass]) /
png_pass_inc[png_ptr->pass];
png_ptr->irowbytes = ((png_ptr->iwidth *
png_ptr->pixel_depth + 7) >> 3) + 1;
png_ptr->irowbytes = ((png_ptr->iwidth *
(png_uint_32)png_ptr->pixel_depth + 7) >> 3) +1;
if (!(png_ptr->transformations & PNG_INTERLACE))
{
png_ptr->num_rows = (png_ptr->height +
@@ -2099,8 +2106,12 @@ png_read_start_row(png_structp png_ptr)
png_pass_inc[png_ptr->pass] - 1 -
png_pass_start[png_ptr->pass]) /
png_pass_inc[png_ptr->pass];
png_ptr->irowbytes = ((png_ptr->iwidth *
png_ptr->pixel_depth + 7) >> 3) + 1;
rowbytes = ((png_ptr->iwidth *
(png_uint_32)png_ptr->pixel_depth + 7) >> 3) +1;
png_ptr->irowbytes = (png_size_t)rowbytes;
if((png_uint_32)png_ptr->irowbytes != rowbytes)
png_error(png_ptr, "Rowbytes overflow in png_read_start_row");
}
else
{
@@ -2189,9 +2200,10 @@ png_read_start_row(png_structp png_ptr)
if ((png_uint_32)png_ptr->rowbytes + 1 > (png_uint_32)65536L)
png_error(png_ptr, "This image requires a row greater than 64KB");
#endif
png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, png_ptr->rowbytes + 1);
png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)(
png_ptr->rowbytes + 1));
png_memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
png_buffered_memset(png_ptr, png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
png_debug1(3, "width = %d,\n", png_ptr->width);
png_debug1(3, "height = %d,\n", png_ptr->height);

View File

@@ -1,12 +1,12 @@
/* pngset.c - storage of image information into info struct
*
* libpng 0.97
* libpng 0.99c
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson
* January 7, 1998
* February 7, 1998
*
* The functions here are used during reads to store data from the file
* into the info struct, and during writes to store application data
@@ -84,6 +84,7 @@ png_set_IHDR(png_structp png_ptr, png_infop info_ptr,
int color_type, int interlace_type, int compression_type,
int filter_type)
{
int rowbytes_per_pixel;
png_debug1(1, "in %s storage function\n", "IHDR");
if (info_ptr == NULL)
return;
@@ -104,7 +105,16 @@ png_set_IHDR(png_structp png_ptr, png_infop info_ptr,
if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
info_ptr->channels++;
info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth);
info_ptr->rowbytes = ((info_ptr->width * info_ptr->pixel_depth + 7) >> 3);
/* check for overflow */
rowbytes_per_pixel = (info_ptr->pixel_depth + 7) >> 3;
info_ptr->rowbytes = info_ptr->width * rowbytes_per_pixel;
if (( width > (png_uint_32)2147483647L/rowbytes_per_pixel))
{
png_warning(png_ptr,
"Width too large to process image data; rowbytes will overflow.");
info_ptr->rowbytes = (png_size_t)0;
}
}
#if defined(PNG_READ_oFFs_SUPPORTED) || defined(PNG_WRITE_oFFs_SUPPORTED)
@@ -129,8 +139,8 @@ png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams,
png_charp units, png_charpp params)
{
png_size_t length;
int i;
png_uint_32 length;
png_uint_32 i;
png_debug1(1, "in %s storage function\n", "pCAL");
if (info_ptr == NULL)
@@ -139,7 +149,7 @@ png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
length = png_strlen(purpose) + 1;
png_debug1(3, "allocating purpose for info (%d bytes)\n", length);
info_ptr->pcal_purpose = (png_charp)png_malloc(png_ptr, length);
png_memcpy(info_ptr->pcal_purpose, purpose, length);
png_memcpy(info_ptr->pcal_purpose, purpose, (png_size_t)length);
png_debug(3, "storing X0, X1, type, and nparams in info\n");
info_ptr->pcal_X0 = X0;
@@ -150,10 +160,10 @@ png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
length = png_strlen(units) + 1;
png_debug1(3, "allocating units for info (%d bytes)\n", length);
info_ptr->pcal_units = (png_charp)png_malloc(png_ptr, length);
png_memcpy(info_ptr->pcal_units, units, length);
png_memcpy(info_ptr->pcal_units, units, (png_size_t)length);
info_ptr->pcal_params = (png_charpp)png_malloc(png_ptr,
(nparams + 1) * sizeof(png_charp));
(png_uint_32)((nparams + 1) * sizeof(png_charp)));
info_ptr->pcal_params[nparams] = NULL;
for (i = 0; i < nparams; i++)
@@ -161,7 +171,7 @@ png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
length = png_strlen(params[i]) + 1;
png_debug2(3, "allocating parameter %d for info (%d bytes)\n", i, length);
info_ptr->pcal_params[i] = (png_charp)png_malloc(png_ptr, length);
png_memcpy(info_ptr->pcal_params[i], params[i], length);
png_memcpy(info_ptr->pcal_params[i], params[i], (png_size_t)length);
}
info_ptr->valid |= PNG_INFO_pCAL;
@@ -213,18 +223,18 @@ png_set_sBIT(png_structp png_ptr, png_infop info_ptr,
#if defined(PNG_READ_sRGB_SUPPORTED) || defined(PNG_WRITE_sRGB_SUPPORTED)
void
png_set_sRGB(png_structp png_ptr, png_infop info_ptr, png_byte intent)
png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int intent)
{
png_debug1(1, "in %s storage function\n", "sRGB");
if (info_ptr == NULL)
return;
info_ptr->srgb_intent = intent;
info_ptr->srgb_intent = (png_byte)intent;
info_ptr->valid |= PNG_INFO_sRGB;
}
void
png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
png_byte intent)
int intent)
{
#if defined(PNG_READ_gAMA_SUPPORTED) || defined(PNG_WRITE_gAMA_SUPPORTED)
float file_gamma;
@@ -269,7 +279,7 @@ png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
int i;
png_debug1(1, "in %s storage function\n", (png_ptr->chunk_name[0] == '\0' ?
"text" : png_ptr->chunk_name));
"text" : (png_const_charp)png_ptr->chunk_name));
if (info_ptr == NULL || num_text == 0)
return;
@@ -289,7 +299,8 @@ png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
old_text = info_ptr->text;
info_ptr->text = (png_textp)png_malloc(png_ptr,
info_ptr->max_text * sizeof (png_text));
png_memcpy(info_ptr->text, old_text, old_max * sizeof(png_text));
png_memcpy(info_ptr->text, old_text, (png_size_t)(old_max *
sizeof(png_text)));
png_free(png_ptr, old_text);
}
else
@@ -297,7 +308,7 @@ png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
info_ptr->max_text = num_text + 8;
info_ptr->num_text = 0;
info_ptr->text = (png_textp)png_malloc(png_ptr,
info_ptr->max_text * sizeof (png_text));
(png_uint_32)(info_ptr->max_text * sizeof (png_text)));
}
png_debug1(3, "allocated %d entries for info_ptr->text\n",
info_ptr->max_text);
@@ -308,7 +319,7 @@ png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
png_textp textp = &(info_ptr->text[info_ptr->num_text]);
if (text_ptr[i].text == NULL)
text_ptr[i].text = "";
text_ptr[i].text = (png_charp)"";
if (text_ptr[i].text[0] == '\0')
{

319
pngtest.c
View File

@@ -1,12 +1,12 @@
/* pngtest.c - a simple test program to test libpng
*
* libpng 0.97
* libpng 0.99c
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson
* January 7, 1998
* February 7, 1998
*
* This program reads in a PNG image, writes it out again, and then
* compares the two files. If the files are identical, this shows that
@@ -37,6 +37,13 @@
#include "png.h"
#ifdef PNGTEST_MEMORY_DEBUG
#include <unistd.h>
void *sbrk (ssize_t incr);
#endif
int test_one_file(PNG_CONST char *inname, PNG_CONST char *outname);
#ifdef __TURBOC__
#include <mem.h>
#endif
@@ -45,16 +52,20 @@
/* #define STDERR stderr */
#define STDERR stdout /* for DOS */
static int verbose = 0;
#if defined(PNG_NO_STDIO)
/* START of code to validate stdio-free compilation */
/* These copies of the default read/write functions come from pngrio.c and */
/* pngwio.c. They allow "don't include stdio" testing of the library. */
#if defined(PNG_NO_STDIO)
/* This is the function which does the actual reading of data. If you are
not reading from a standard C stream, you should create a replacement
read_data function and use it at run time with png_set_read_fn(), rather
than changing the library. */
#ifndef USE_FAR_KEYWORD
static void
png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length);
static void
png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
{
png_size_t check;
@@ -79,6 +90,8 @@ png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
#define NEAR_BUF_SIZE 1024
#define MIN(a,b) (a <= b ? a : b)
static void
png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length);
static void
png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
{
@@ -118,10 +131,12 @@ png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
png_error(png_ptr, "read Error");
}
}
#endif
#endif /* USE_FAR_KEYWORD */
#if defined(PNG_WRITE_FLUSH_SUPPORTED)
static void
png_default_flush(png_structp png_ptr);
static void
png_default_flush(png_structp png_ptr)
{
FILE *io_ptr;
@@ -137,6 +152,8 @@ png_default_flush(png_structp png_ptr)
than changing the library. */
#ifndef USE_FAR_KEYWORD
static void
png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length);
static void
png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
{
png_uint_32 check;
@@ -156,6 +173,8 @@ png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
#define NEAR_BUF_SIZE 1024
#define MIN(a,b) (a <= b ? a : b)
static void
png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length);
static void
png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
{
@@ -196,7 +215,7 @@ png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
}
}
#endif
#endif /* USE_FAR_KEYWORD */
/* 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
@@ -224,13 +243,114 @@ png_default_error(png_structp png_ptr, png_const_charp message)
/* We can return because png_error calls the default handler which is
* actually ok in this case. */
}
#endif
#endif /* PNG_NO_STDIO */
/* END of code to validate stdio-free compilation */
/* Test one file */
int test(PNG_CONST char *inname, PNG_CONST char *outname)
/* START of code to validate memory allocation and deallocation */
#ifdef PNGTEST_MEMORY_DEBUG
/* Borland DOS special memory handler */
#if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
ERROR - memory debugging is not supported on this platform
#else
/* 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.
This piece of code can be compiled to validate max 64K allocations
by setting MAXSEG_64K in zlib zconf.h *or* PNG_MAX_MALLOC_64K. */
typedef struct memory_information {
png_uint_32 size;
png_voidp pointer;
struct memory_information FAR *next;
} memory_information;
typedef memory_information FAR *memory_infop;
static memory_infop pinformation = NULL;
static int current_allocation = 0;
static int maximum_allocation = 0;
extern PNG_EXPORT(png_voidp,png_debug_malloc) PNGARG((png_structp png_ptr,
png_uint_32 size));
extern PNG_EXPORT(void,png_debug_free) PNGARG((png_structp png_ptr,
png_voidp ptr));
png_voidp
png_malloc(png_structp png_ptr, png_uint_32 size) {
if (png_ptr == NULL) {
fprintf(STDERR, "NULL pointer to memory allocator\n");
return (NULL);
}
if (size == 0)
return (png_voidp)(NULL);
/* This calls the library allocator twice, once to get the requested
buffer and once to get a new free list entry. */
{
memory_infop pinfo = png_debug_malloc(png_ptr, sizeof *pinfo);
pinfo->size = size;
current_allocation += size;
if (current_allocation > maximum_allocation)
maximum_allocation = current_allocation;
pinfo->pointer = png_debug_malloc(png_ptr, size);
pinfo->next = pinformation;
pinformation = pinfo;
/* Make sure the caller isn't assuming zeroed memory. */
png_memset(pinfo->pointer, 0xdd, pinfo->size);
return (png_voidp)(pinfo->pointer);
}
}
/* Free a pointer. It is removed from the list at the same time. */
void
png_free(png_structp png_ptr, png_voidp ptr)
{
FILE *fpin, *fpout;
if (png_ptr == NULL)
fprintf(STDERR, "NULL pointer to memory allocator\n");
if (ptr == 0) {
#if 0 /* This happens all the time. */
fprintf(STDERR, "WARNING: freeing NULL pointer\n");
#endif
return;
}
/* Unlink the element from the list. */
{
memory_infop FAR *ppinfo = &pinformation;
for (;;) {
memory_infop pinfo = *ppinfo;
if (pinfo->pointer == ptr) {
*ppinfo = pinfo->next;
current_allocation -= pinfo->size;
if (current_allocation < 0)
fprintf(STDERR, "Duplicate free of memory\n");
/* We must free the list element too, but first kill
the memory which is to be freed. */
memset(ptr, 0x55, pinfo->size);
png_debug_free(png_ptr, pinfo);
break;
}
if (pinfo->next == NULL) {
fprintf(STDERR, "Pointer %x not found\n", ptr);
break;
}
ppinfo = &pinfo->next;
}
}
/* Finally free the data. */
png_debug_free(png_ptr, ptr);
}
#endif /* Not Borland DOS special memory handler */
#endif
/* END of code to test memory allocation/deallocation */
/* Test one file */
int test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
{
static FILE *fpin, *fpout; /* "static" prevents setjmp corruption */
png_structp read_ptr, write_ptr;
png_infop read_info_ptr, write_info_ptr, end_info_ptr;
png_bytep row_buf;
@@ -249,30 +369,32 @@ int test(PNG_CONST char *inname, PNG_CONST char *outname)
if ((fpin = fopen(inname, "rb")) == NULL)
{
fprintf(STDERR, "Could not find input file %s\n", inname);
return 1;
return (1);
}
if ((fpout = fopen(outname, "wb")) == NULL)
{
fprintf(STDERR, "Could not open output file %s\n", outname);
fclose(fpin);
return 1;
return (1);
}
png_debug(0, "Allocating read and write structures\n");
read_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, (png_voidp)NULL,
(png_error_ptr)NULL, (png_error_ptr)NULL);
#if defined(PNG_NO_STDIO)
png_set_error_fn(read_ptr, (png_voidp)inname, png_default_error, png_default_warning);
png_set_error_fn(read_ptr, (png_voidp)inname, png_default_error,
png_default_warning);
#endif
write_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, (png_voidp)NULL,
(png_error_ptr)NULL, (png_error_ptr)NULL);
#if defined(PNG_NO_STDIO)
png_set_error_fn(write_ptr, (png_voidp)inname, png_default_error, png_default_warning);
png_set_error_fn(write_ptr, (png_voidp)inname, png_default_error,
png_default_warning);
#endif
png_debug(0, "Allocating read_info, write_info and end_info structures\n");
read_info_ptr = png_create_info_struct(read_ptr);
write_info_ptr = png_create_info_struct(read_ptr);
write_info_ptr = png_create_info_struct(write_ptr);
end_info_ptr = png_create_info_struct(read_ptr);
png_debug(0, "Setting jmpbuf for read struct\n");
@@ -287,7 +409,7 @@ int test(PNG_CONST char *inname, PNG_CONST char *outname)
png_destroy_write_struct(&write_ptr, &write_info_ptr);
fclose(fpin);
fclose(fpout);
return 1;
return (1);
}
png_debug(0, "Setting jmpbuf for write struct\n");
@@ -303,7 +425,7 @@ int test(PNG_CONST char *inname, PNG_CONST char *outname)
png_destroy_write_struct(&write_ptr, &write_info_ptr);
fclose(fpin);
fclose(fpout);
return 1;
return (1);
}
#ifdef USE_FAR_KEYWORD
@@ -334,7 +456,11 @@ int test(PNG_CONST char *inname, PNG_CONST char *outname)
&color_type, &interlace_type, &compression_type, &filter_type))
{
png_set_IHDR(write_ptr, write_info_ptr, width, height, bit_depth,
#if defined(PNG_WRITE_INTERLACING_SUPPORTED)
color_type, interlace_type, compression_type, filter_type);
#else
color_type, PNG_INTERLACE_NONE, compression_type, filter_type);
#endif
}
}
#if defined(PNG_READ_bKGD_SUPPORTED) && defined(PNG_WRITE_bKGD_SUPPORTED)
@@ -371,7 +497,7 @@ int test(PNG_CONST char *inname, PNG_CONST char *outname)
#endif
#if defined(PNG_READ_sRGB_SUPPORTED) && defined(PNG_WRITE_sRGB_SUPPORTED)
{
png_byte intent;
int intent;
if (png_get_sRGB(read_ptr, read_info_ptr, &intent))
{
@@ -486,6 +612,7 @@ int test(PNG_CONST char *inname, PNG_CONST char *outname)
png_debug(0, "\nWriting info struct\n");
png_write_info(write_ptr, write_info_ptr);
png_debug(0, "\nAllocating row buffer \n");
row_buf = (png_bytep)png_malloc(read_ptr,
png_get_rowbytes(read_ptr, read_info_ptr));
if (row_buf == NULL)
@@ -495,14 +622,16 @@ int test(PNG_CONST char *inname, PNG_CONST char *outname)
png_destroy_write_struct(&write_ptr, &write_info_ptr);
fclose(fpin);
fclose(fpout);
return 1;
return (1);
}
png_debug(0, "Writing row data\n");
num_pass = png_set_interlace_handling(read_ptr);
png_set_interlace_handling(write_ptr);
for (pass = 0; pass < num_pass; pass++)
{
png_debug1(0, "Writing row data for pass %d\n",pass);
for (y = 0; y < height; y++)
{
png_read_rows(read_ptr, (png_bytepp)&row_buf, (png_bytepp)NULL, 1);
@@ -513,28 +642,38 @@ int test(PNG_CONST char *inname, PNG_CONST char *outname)
png_debug(0, "Reading and writing end_info data\n");
png_read_end(read_ptr, end_info_ptr);
png_write_end(write_ptr, end_info_ptr);
#ifdef PNG_EASY_ACCESS_SUPPORTED
if(verbose)
{
png_uint_32 iwidth, iheight;
iwidth = png_get_image_width(write_ptr, write_info_ptr);
iheight = png_get_image_height(write_ptr, write_info_ptr);
fprintf(STDERR, "Image width = %lu, height = %lu\n",
iwidth, iheight);
}
#endif
png_debug(0, "Destroying data structs\n");
png_free(read_ptr, row_buf);
png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr);
png_destroy_write_struct(&write_ptr, &write_info_ptr);
fclose(fpin);
fclose(fpout);
png_free(read_ptr, row_buf);
png_debug(0, "Opening files for comparison\n");
if ((fpin = fopen(inname, "rb")) == NULL)
{
fprintf(STDERR, "Could not find file %s\n", inname);
return 1;
return (1);
}
if ((fpout = fopen(outname, "rb")) == NULL)
{
fprintf(STDERR, "Could not find file %s\n", outname);
fclose(fpin);
return 1;
return (1);
}
while (1)
@@ -550,7 +689,7 @@ int test(PNG_CONST char *inname, PNG_CONST char *outname)
inname, outname);
fclose(fpin);
fclose(fpout);
return 1;
return (1);
}
if (!num_in)
@@ -561,14 +700,14 @@ int test(PNG_CONST char *inname, PNG_CONST char *outname)
fprintf(STDERR, "Files %s and %s are different\n", inname, outname);
fclose(fpin);
fclose(fpout);
return 1;
return (1);
}
}
fclose(fpin);
fclose(fpout);
return 0;
return (0);
}
/* input and output filenames */
@@ -576,8 +715,8 @@ int test(PNG_CONST char *inname, PNG_CONST char *outname)
PNG_CONST char *inname = "pngtest_png";
PNG_CONST char *outname = "pngout_png";
#else
PNG_CONST char *inname = "pngtest.png";
PNG_CONST char *outname = "pngout.png";
static char *inname = "pngtest.png";
static char *outname = "pngout.png";
#endif
int
@@ -587,6 +726,19 @@ main(int argc, char *argv[])
int ierror = 0;
fprintf(STDERR, "Testing libpng version %s\n", PNG_LIBPNG_VER_STRING);
fprintf(STDERR, " with zlib version %s\n", ZLIB_VERSION);
/* Do some consistency checking on the memory allocation settings, I'm
not sure this matters, but it is nice to know, the first of these
tests should be impossible because of the way the macros are set
in pngconf.h */
#if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K)
fprintf(STDERR, " NOTE: Zlib compiled for max 64k, libpng not\n");
#endif
/* I think the following can happen. */
#if !defined(MAXSEG_64K) && defined(PNG_MAX_MALLOC_64K)
fprintf(STDERR, " NOTE: libpng compiled for max 64k, zlib not\n");
#endif
if (strcmp(png_libpng_ver, PNG_LIBPNG_VER_STRING))
{
@@ -599,41 +751,124 @@ main(int argc, char *argv[])
if (argc > 1)
{
if (strcmp(argv[1], "-m") == 0)
multiple = 1;
else
inname = argv[1];
if (strcmp(argv[1], "-m") == 0)
multiple = 1;
else if (strcmp(argv[1], "-mv") == 0 ||
strcmp(argv[1], "-vm") == 0 )
{
multiple = 1;
verbose = 1;
}
else if (strcmp(argv[1], "-v") == 0)
{
verbose = 1;
inname = argv[2];
}
else
inname = argv[1];
}
if (!multiple && argc == 3)
outname = argv[2];
if (!multiple && argc == 3+verbose)
outname = argv[2+verbose];
if (!multiple && argc > 3 || multiple && argc < 2)
if ((!multiple && argc > 3+verbose) || (multiple && argc < 2))
{
fprintf(STDERR, "usage: %s [infile.png] [outfile.png]\n\t%s -m {infile.png}\n",
fprintf(STDERR,
"usage: %s [infile.png] [outfile.png]\n\t%s -m {infile.png}\n",
argv[0], argv[0]);
fprintf(STDERR, " reads/writes one PNG file (without -m) or multiple files (-m)\n");
fprintf(STDERR, " with -m %s is used as a temporary file\n", outname);
fprintf(STDERR,
" reads/writes one PNG file (without -m) or multiple files (-m)\n");
fprintf(STDERR,
" with -m %s is used as a temporary file\n", outname);
exit(1);
}
if (multiple)
{
int i;
#ifdef PNGTEST_MEMORY_DEBUG
int allocation_now = current_allocation;
#endif
for (i=2; i<argc; ++i)
{
fprintf(STDERR, "Testing %s:\n",argv[i]);
ierror += test(argv[i], outname);
{
int kerror;
fprintf(STDERR, "Testing %s:",argv[i]);
kerror = test_one_file(argv[i], outname);
if (kerror == 0)
fprintf(STDERR, " PASS\n");
else {
fprintf(STDERR, " FAIL\n");
ierror += kerror;
}
#ifdef PNGTEST_MEMORY_DEBUG
if (allocation_now != current_allocation)
fprintf(STDERR, "MEMORY ERROR: %d bytes lost\n",
current_allocation-allocation_now);
if (current_allocation != 0) {
memory_infop pinfo = pinformation;
fprintf(STDERR, "MEMORY ERROR: %d bytes still allocated\n",
current_allocation);
while (pinfo != NULL) {
fprintf(STDERR, " %d bytes at %x\n", pinfo->size, pinfo->pointer);
pinfo = pinfo->next;
}
}
#endif
}
#ifdef PNGTEST_MEMORY_DEBUG
fprintf(STDERR, "Maximum memory allocation: %d bytes\n",
maximum_allocation);
#endif
}
else
{
ierror += test(inname, outname);
int i;
for (i=0; i<3; ++i) {
int kerror;
#ifdef PNGTEST_MEMORY_DEBUG
int allocation_now = current_allocation;
#endif
if (i == 0 || verbose == 1 || ierror != 0)
fprintf(STDERR, "Testing %s:",inname);
kerror = test_one_file(inname, outname);
if(kerror == 0)
{
if(verbose == 1 || i == 2) fprintf(STDERR, " PASS\n");
}
else
{
if(verbose == 0 && i != 2)
fprintf(STDERR, "Testing %s:",inname);
fprintf(STDERR, " FAIL\n");
ierror += kerror;
}
#ifdef PNGTEST_MEMORY_DEBUG
if (allocation_now != current_allocation)
fprintf(STDERR, "MEMORY ERROR: %d bytes lost\n",
current_allocation-allocation_now);
if (current_allocation != 0) {
memory_infop pinfo = pinformation;
fprintf(STDERR, "MEMORY ERROR: %d bytes still allocated\n",
current_allocation);
while (pinfo != NULL) {
fprintf(STDERR, " %d bytes at %x\n", pinfo->size, pinfo->pointer);
pinfo = pinfo->next;
}
}
fprintf(STDERR, "sbrk(0)=%d\n",sbrk(0));
#endif
}
#ifdef PNGTEST_MEMORY_DEBUG
fprintf(STDERR, "Maximum memory allocation: %d bytes\n",
maximum_allocation);
#endif
}
if (ierror == 0)
fprintf(STDERR, "libpng passes test\n");
else
fprintf(STDERR, "libpng FAILS test\n");
return ierror != 0;
return (int)(ierror != 0);
}

View File

@@ -1,12 +1,12 @@
/* pngtrans.c - transforms the data in a row (used by both readers and writers)
*
* libpng 0.97
* libpng 0.99c
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson
* January 7, 1998
* February 7, 1998
*/
#define PNG_INTERNAL
@@ -68,7 +68,8 @@ png_set_shift(png_structp png_ptr, png_color_8p true_bits)
}
#endif
#if defined(PNG_READ_INTERLACING_SUPPORTED) || defined(PNG_WRITE_INTERLACING_SUPPORTED)
#if defined(PNG_READ_INTERLACING_SUPPORTED) || \
defined(PNG_WRITE_INTERLACING_SUPPORTED)
int
png_set_interlace_handling(png_structp png_ptr)
{
@@ -76,10 +77,10 @@ png_set_interlace_handling(png_structp png_ptr)
if (png_ptr->interlaced)
{
png_ptr->transformations |= PNG_INTERLACE;
return 7;
return (7);
}
return 1;
return (1);
}
#endif
@@ -118,6 +119,16 @@ png_set_swap_alpha(png_structp png_ptr)
}
#endif
#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
void
png_set_invert_alpha(png_structp png_ptr)
{
png_debug(1, "in png_set_invert_alpha\n");
png_ptr->transformations |= PNG_INVERT_ALPHA;
}
#endif
#if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
void
png_set_invert_mono(png_structp png_ptr)
@@ -289,7 +300,7 @@ png_do_packswap(png_row_infop row_info, png_bytep row)
png_debug(1, "in png_do_packswap\n");
if (
#if defined(PNG_USELESS_TESTS_SUPPORTED)
row != NULL && row_info != NULL
row != NULL && row_info != NULL &&
#endif
row_info->bit_depth < 8)
{

View File

@@ -1,12 +1,12 @@
/* pngwio.c - functions for data output
*
* libpng 0.97
* libpng 0.99c
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson
* January 7, 1998
* February 7, 1998
*
* This file provides a location for all output. Users which need
* special handling are expected to write functions which have the same

View File

@@ -1,12 +1,12 @@
/* pngwrite.c - general routines to write a PNG file
*
* libpng 0.97
* libpng 0.99c
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson
* January 7, 1998
* February 7, 1998
*/
/* get internal access to png.h */
@@ -34,7 +34,12 @@ png_write_info(png_structp png_ptr, png_infop info_ptr)
/* write IHDR information. */
png_write_IHDR(png_ptr, info_ptr->width, info_ptr->height,
info_ptr->bit_depth, info_ptr->color_type, info_ptr->compression_type,
info_ptr->filter_type, info_ptr->interlace_type);
info_ptr->filter_type,
#if defined(PNG_WRITE_INTERLACING_SUPPORTED)
info_ptr->interlace_type);
#else
0);
#endif
/* the rest of these check to see if the valid field has the appropriate
flag set, and if it does, writes the chunk. */
#if defined(PNG_WRITE_gAMA_SUPPORTED)
@@ -43,7 +48,7 @@ png_write_info(png_structp png_ptr, png_infop info_ptr)
#endif
#if defined(PNG_WRITE_sRGB_SUPPORTED)
if (info_ptr->valid & PNG_INFO_sRGB)
png_write_sRGB(png_ptr, info_ptr->srgb_intent);
png_write_sRGB(png_ptr, (int)info_ptr->srgb_intent);
#endif
#if defined(PNG_WRITE_sBIT_SUPPORTED)
if (info_ptr->valid & PNG_INFO_sBIT)
@@ -62,10 +67,23 @@ png_write_info(png_structp png_ptr, png_infop info_ptr)
(png_uint_32)info_ptr->num_palette);
else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
png_error(png_ptr, "Valid palette required for paletted images\n");
#if defined(PNG_WRITE_tRNS_SUPPORTED)
if (info_ptr->valid & PNG_INFO_tRNS)
{
#if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
/* invert the alpha channel (in tRNS) */
if (png_ptr->transformations & PNG_INVERT_ALPHA &&
info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
{
int j;
for (j=0; j<(int)info_ptr->num_trans; j++)
info_ptr->trans[j] = 255 - info_ptr->trans[j];
}
#endif
png_write_tRNS(png_ptr, info_ptr->trans, &(info_ptr->trans_values),
info_ptr->num_trans, info_ptr->color_type);
}
#endif
#if defined(PNG_WRITE_bKGD_SUPPORTED)
if (info_ptr->valid & PNG_INFO_bKGD)
@@ -200,19 +218,20 @@ png_write_end(png_structp png_ptr, png_infop info_ptr)
png_write_IEND(png_ptr);
}
#if defined(PNG_TIME_RFC1152_SUPPORTED)
/* Convert the supplied time into an RFC 1152 string suitable for use in
#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.
*/
png_charp
png_convert_to_rfc1152(png_structp png_ptr, png_timep ptime)
png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime)
{
const char *short_months[12] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
if (png_ptr->time_buffer == NULL)
{
png_ptr->time_buffer = (png_charp)png_malloc(png_ptr, 29*sizeof(char));
png_ptr->time_buffer = (png_charp)png_malloc(png_ptr, (png_uint_32)(29*
sizeof(char)));
}
#ifdef USE_FAR_KEYWORD
@@ -231,9 +250,9 @@ png_convert_to_rfc1152(png_structp png_ptr, png_timep ptime)
ptime->year, ptime->hour % 24, ptime->minute % 60,
ptime->second % 61);
#endif
return png_ptr->time_buffer;
return ((png_charp)png_ptr->time_buffer);
}
#endif /* PNG_TIME_RFC1152_SUPPORTED */
#endif /* PNG_TIME_RFC1123_SUPPORTED */
#if defined(PNG_WRITE_tIME_SUPPORTED)
void
@@ -271,7 +290,7 @@ png_create_write_struct(png_const_charp user_png_ver, voidp error_ptr,
png_debug(1, "in png_create_write_struct\n");
if ((png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG)) == NULL)
{
return (png_structp)NULL;
return ((png_structp)NULL);
}
#ifdef USE_FAR_KEYWORD
if (setjmp(jmpbuf))
@@ -281,7 +300,7 @@ png_create_write_struct(png_const_charp user_png_ver, voidp error_ptr,
{
png_free(png_ptr, png_ptr->zbuf);
png_destroy_struct(png_ptr);
return (png_structp)NULL;
return ((png_structp)NULL);
}
#ifdef USE_FAR_KEYWORD
png_memcpy(png_ptr->jmpbuf,jmpbuf,sizeof(jmp_buf));
@@ -302,7 +321,8 @@ png_create_write_struct(png_const_charp user_png_ver, voidp error_ptr,
/* initialize zbuf - compression buffer */
png_ptr->zbuf_size = PNG_ZBUF_SIZE;
png_ptr->zbuf = png_malloc(png_ptr, png_ptr->zbuf_size);
png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
(png_uint_32)png_ptr->zbuf_size);
png_set_write_fn(png_ptr, NULL, NULL, NULL);
@@ -311,7 +331,7 @@ png_create_write_struct(png_const_charp user_png_ver, voidp error_ptr,
1, NULL, NULL);
#endif
return (png_ptr);
return ((png_structp)png_ptr);
}
@@ -333,7 +353,8 @@ png_write_init(png_structp png_ptr)
/* initialize zbuf - compression buffer */
png_ptr->zbuf_size = PNG_ZBUF_SIZE;
png_ptr->zbuf = png_malloc(png_ptr, png_ptr->zbuf_size);
png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
(png_uint_32)png_ptr->zbuf_size);
png_set_write_fn(png_ptr, NULL, NULL, NULL);
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
@@ -373,9 +394,13 @@ png_write_image(png_structp png_ptr, png_bytepp image)
png_bytepp rp; /* points to current row */
png_debug(1, "in png_write_image\n");
#if defined(PNG_WRITE_INTERLACING_SUPPORTED)
/* intialize interlace handling. If image is not interlaced,
this will set pass to 1 */
num_pass = png_set_interlace_handling(png_ptr);
#else
num_pass = 1;
#endif
/* loop through passes */
for (pass = 0; pass < num_pass; pass++)
{
@@ -465,6 +490,7 @@ png_write_row(png_structp png_ptr, png_bytep row)
png_ptr->row_info.bit_depth = png_ptr->usr_bit_depth;
png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth *
png_ptr->row_info.channels);
png_ptr->row_info.rowbytes = ((png_ptr->row_info.width *
(png_uint_32)png_ptr->row_info.pixel_depth + 7) >> 3);
@@ -476,7 +502,8 @@ png_write_row(png_structp png_ptr, png_bytep row)
png_debug1(3, "row_info->rowbytes = %d\n", png_ptr->row_info.rowbytes);
/* Copy user's row into buffer, leaving room for filter byte. */
png_memcpy(png_ptr->row_buf + 1, row, png_ptr->row_info.rowbytes);
png_buffered_memcpy(png_ptr, png_ptr->row_buf + 1, row,
png_ptr->row_info.rowbytes);
#if defined(PNG_WRITE_INTERLACING_SUPPORTED)
/* handle interlacing */
@@ -582,6 +609,19 @@ png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)
{
#ifdef PNG_WRITE_tEXt_SUPPORTED
png_free(png_ptr, info_ptr->text);
#endif
#if defined(PNG_READ_pCAL_SUPPORTED)
png_free(png_ptr, info_ptr->pcal_purpose);
png_free(png_ptr, info_ptr->pcal_units);
if (info_ptr->pcal_params != NULL)
{
int i;
for (i = 0; i < (int)info_ptr->pcal_nparams; i++)
{
png_free(png_ptr, info_ptr->pcal_params[i]);
}
png_free(png_ptr, info_ptr->pcal_params);
}
#endif
png_destroy_struct((png_voidp)info_ptr);
*info_ptr_ptr = (png_infop)NULL;
@@ -617,9 +657,9 @@ png_write_destroy(png_structp png_ptr)
png_free(png_ptr, png_ptr->up_row);
png_free(png_ptr, png_ptr->avg_row);
png_free(png_ptr, png_ptr->paeth_row);
#if defined(PNG_TIME_RFC1152_SUPPORTED)
#if defined(PNG_TIME_RFC1123_SUPPORTED)
png_free(png_ptr, png_ptr->time_buffer);
#endif /* PNG_TIME_RFC1152_SUPPORTED */
#endif /* PNG_TIME_RFC1123_SUPPORTED */
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
png_free(png_ptr, png_ptr->prev_filters);
png_free(png_ptr, png_ptr->filter_weights);
@@ -679,7 +719,7 @@ png_set_filter(png_structp png_ptr, int method, int filters)
if (png_ptr->do_filter & PNG_FILTER_SUB && png_ptr->sub_row == NULL)
{
png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
png_ptr->rowbytes + 1);
(png_ptr->rowbytes + 1));
png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
}
@@ -693,7 +733,7 @@ png_set_filter(png_structp png_ptr, int method, int filters)
else
{
png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
png_ptr->rowbytes + 1);
(png_ptr->rowbytes + 1));
png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
}
}
@@ -708,7 +748,7 @@ png_set_filter(png_structp png_ptr, int method, int filters)
else
{
png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
png_ptr->rowbytes + 1);
(png_ptr->rowbytes + 1));
png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
}
}
@@ -723,8 +763,8 @@ png_set_filter(png_structp png_ptr, int method, int filters)
}
else
{
png_ptr->paeth_row = (png_bytep )png_malloc(png_ptr,
png_ptr->rowbytes + 1);
png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
(png_ptr->rowbytes + 1));
png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
}
}
@@ -780,7 +820,7 @@ png_set_filter_heuristics(png_structp png_ptr, int heuristic_method,
if (png_ptr->prev_filters == NULL)
{
png_ptr->prev_filters = (png_bytep)png_malloc(png_ptr,
sizeof(png_byte) * num_weights);
(png_uint_32)(sizeof(png_byte) * num_weights));
/* To make sure that the weighting starts out fairly */
for (i = 0; i < num_weights; i++)
@@ -792,10 +832,10 @@ png_set_filter_heuristics(png_structp png_ptr, int heuristic_method,
if (png_ptr->filter_weights == NULL)
{
png_ptr->filter_weights = (png_uint_16p)png_malloc(png_ptr,
sizeof(png_uint_16) * num_weights);
(png_uint_32)(sizeof(png_uint_16) * num_weights));
png_ptr->inv_filter_weights = (png_uint_16p)png_malloc(png_ptr,
sizeof(png_uint_16) * num_weights);
(png_uint_32)(sizeof(png_uint_16) * num_weights));
for (i = 0; i < num_weights; i++)
{
@@ -827,10 +867,10 @@ png_set_filter_heuristics(png_structp png_ptr, int heuristic_method,
if (png_ptr->filter_costs == NULL)
{
png_ptr->filter_costs = (png_uint_16p)png_malloc(png_ptr,
sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST);
(png_uint_32)(sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
png_ptr->inv_filter_costs = (png_uint_16p)png_malloc(png_ptr,
sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST);
(png_uint_32)(sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
{

View File

@@ -1,12 +1,12 @@
/* pngwtran.c - transforms the data in a row for PNG writers
*
* libpng 0.97
* libpng 0.99c
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson
* January 7, 1998
* February 7, 1998
*/
#define PNG_INTERNAL
@@ -24,6 +24,10 @@ png_do_write_transformations(png_structp png_ptr)
png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
png_ptr->flags);
#endif
#if defined(PNG_WRITE_PACKSWAP_SUPPORTED)
if (png_ptr->transformations & PNG_PACKSWAP)
png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1);
#endif
#if defined(PNG_WRITE_PACK_SUPPORTED)
if (png_ptr->transformations & PNG_PACK)
png_do_pack(&(png_ptr->row_info), png_ptr->row_buf + 1,
@@ -42,6 +46,10 @@ png_do_write_transformations(png_structp png_ptr)
if (png_ptr->transformations & PNG_SWAP_ALPHA)
png_do_write_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
#endif
#if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
if (png_ptr->transformations & PNG_INVERT_ALPHA)
png_do_write_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
#endif
#if defined(PNG_WRITE_BGR_SUPPORTED)
if (png_ptr->transformations & PNG_BGR)
png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
@@ -394,3 +402,79 @@ png_do_write_swap_alpha(png_row_infop row_info, png_bytep row)
}
#endif
#if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
void
png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
{
png_debug(1, "in png_do_write_invert_alpha\n");
#if defined(PNG_USELESS_TESTS_SUPPORTED)
if (row != NULL && row_info != NULL)
#endif
{
if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
{
/* This inverts the alpha channel in RGBA */
if (row_info->bit_depth == 8)
{
png_bytep sp, dp;
png_uint_32 i;
for (i = 0, sp = dp = row; i < row_info->width; i++)
{
*(dp++) = *(sp++);
*(dp++) = *(sp++);
*(dp++) = *(sp++);
*(dp++) = 255 - *(sp++);
}
}
/* This inverts the alpha channel in RRGGBBAA */
else
{
png_bytep sp, dp;
png_uint_32 i;
for (i = 0, sp = dp = row; i < row_info->width; i++)
{
*(dp++) = *(sp++);
*(dp++) = *(sp++);
*(dp++) = *(sp++);
*(dp++) = *(sp++);
*(dp++) = *(sp++);
*(dp++) = *(sp++);
*(dp++) = 255 - *(sp++);
*(dp++) = 255 - *(sp++);
}
}
}
else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
{
/* This inverts the alpha channel in GA */
if (row_info->bit_depth == 8)
{
png_bytep sp, dp;
png_uint_32 i;
for (i = 0, sp = dp = row; i < row_info->width; i++)
{
*(dp++) = *(sp++);
*(dp++) = 255 - *(sp++);
}
}
/* This inverts the alpha channel in GGAA */
else
{
png_bytep sp, dp;
png_uint_32 i;
for (i = 0, sp = dp = row; i < row_info->width; i++)
{
*(dp++) = *(sp++);
*(dp++) = *(sp++);
*(dp++) = 255 - *(sp++);
*(dp++) = 255 - *(sp++);
}
}
}
}
}
#endif

View File

@@ -1,12 +1,12 @@
/* pngwutil.c - utilities to write a PNG file
*
* libpng 0.97
* libpng 0.99c
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson
* January 7, 1998
* February 7, 1998
*/
#define PNG_INTERNAL
@@ -200,12 +200,16 @@ png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height,
filter_type = PNG_FILTER_TYPE_BASE;
}
#ifdef PNG_WRITE_INTERLACING_SUPPORTED
if (interlace_type != PNG_INTERLACE_NONE &&
interlace_type != PNG_INTERLACE_ADAM7)
{
png_warning(png_ptr, "Invalid interlace type specified");
interlace_type = PNG_INTERLACE_ADAM7;
}
#else
interlace_type=PNG_INTERLACE_NONE;
#endif
/* save off the relevent information */
png_ptr->bit_depth = (png_byte)bit_depth;
@@ -346,15 +350,15 @@ png_write_gAMA(png_structp png_ptr, double file_gamma)
#if defined(PNG_WRITE_sRGB_SUPPORTED)
/* write a sRGB chunk */
void
png_write_sRGB(png_structp png_ptr, png_byte srgb_intent)
png_write_sRGB(png_structp png_ptr, int srgb_intent)
{
png_byte buf[1];
png_debug(1, "in png_write_sRGB\n");
if(srgb_intent > 3)
if(srgb_intent >= PNG_sRGB_INTENT_LAST)
png_warning(png_ptr,
"Invalid sRGB rendering intent specified");
buf[0]=srgb_intent;
buf[0]=(png_byte)srgb_intent;
png_write_chunk(png_ptr, png_sRGB, buf, (png_size_t)1);
}
#endif
@@ -371,7 +375,7 @@ png_write_sBIT(png_structp png_ptr, png_color_8p sbit, int color_type)
/* make sure we don't depend upon the order of PNG_COLOR_8 */
if (color_type & PNG_COLOR_MASK_COLOR)
{
int maxbits;
png_byte maxbits;
maxbits = color_type==PNG_COLOR_TYPE_PALETTE ? 8:png_ptr->usr_bit_depth;
if (sbit->red == 0 || sbit->red > maxbits ||
@@ -482,7 +486,7 @@ png_write_tRNS(png_structp png_ptr, png_bytep trans, png_color_16p tran,
png_debug(1, "in png_write_tRNS\n");
if (color_type == PNG_COLOR_TYPE_PALETTE)
{
if (num_trans <= 0 || num_trans > png_ptr->num_palette)
if (num_trans <= 0 || num_trans > (int)png_ptr->num_palette)
{
png_warning(png_ptr,"Invalid number of transparent colors specified");
return;
@@ -506,7 +510,7 @@ png_write_tRNS(png_structp png_ptr, png_bytep trans, png_color_16p tran,
}
else
{
png_warning(png_ptr, "Can't write tRNS with and alpha channel");
png_warning(png_ptr, "Can't write tRNS with an alpha channel");
}
}
#endif
@@ -547,13 +551,13 @@ png_write_bKGD(png_structp png_ptr, png_color_16p back, int color_type)
#if defined(PNG_WRITE_hIST_SUPPORTED)
/* write the histogram */
void
png_write_hIST(png_structp png_ptr, png_uint_16p hist, png_uint_32 num_hist)
png_write_hIST(png_structp png_ptr, png_uint_16p hist, int num_hist)
{
png_uint_32 i;
int i;
png_byte buf[3];
png_debug(1, "in png_write_hIST\n");
if (num_hist > png_ptr->num_palette)
if (num_hist > (int)png_ptr->num_palette)
{
png_debug2(3, "num_hist = %d, num_palette = %d\n", num_hist,
png_ptr->num_palette);
@@ -561,7 +565,7 @@ png_write_hIST(png_structp png_ptr, png_uint_16p hist, png_uint_32 num_hist)
return;
}
png_write_chunk_start(png_ptr, png_hIST, num_hist * 2);
png_write_chunk_start(png_ptr, png_hIST, (png_uint_32)(num_hist * 2));
for (i = 0; i < num_hist; i++)
{
png_save_uint_16(buf, hist[i]);
@@ -595,12 +599,12 @@ png_check_keyword(png_structp png_ptr, png_charp key, png_charpp new_key)
if (key == NULL || (key_len = png_strlen(key)) == 0)
{
png_chunk_warning(png_ptr, "zero length keyword");
return 0;
return ((png_size_t)0);
}
png_debug1(2, "Keyword to be checked is '%s'\n", key);
*new_key = (png_charp)png_malloc(png_ptr, key_len + 1);
*new_key = (png_charp)png_malloc(png_ptr, (png_uint_32)(key_len + 1));
/* Replace non-printing characters with a blank and print a warning */
for (kp = key, dp = *new_key; *kp != '\0'; kp++, dp++)
@@ -684,7 +688,7 @@ png_check_keyword(png_structp png_ptr, png_charp key, png_charpp new_key)
key_len = 79;
}
return key_len;
return (key_len);
}
#endif
@@ -811,17 +815,18 @@ png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,
old_ptr = output_ptr;
output_ptr = (png_charpp)png_malloc(png_ptr,
max_output_ptr * sizeof (png_charpp));
(png_uint_32)(max_output_ptr * sizeof (png_charpp)));
png_memcpy(output_ptr, old_ptr, old_max * sizeof (png_charp));
png_free(png_ptr, old_ptr);
}
else
output_ptr = (png_charpp)png_malloc(png_ptr,
max_output_ptr * sizeof (png_charp));
(png_uint_32)(max_output_ptr * sizeof (png_charp)));
}
/* save the data */
output_ptr[num_output_ptr] = png_malloc(png_ptr, png_ptr->zbuf_size);
output_ptr[num_output_ptr] = (png_charp)png_malloc(png_ptr,
(png_uint_32)png_ptr->zbuf_size);
png_memcpy(output_ptr[num_output_ptr], png_ptr->zbuf,
png_ptr->zbuf_size);
num_output_ptr++;
@@ -864,18 +869,18 @@ png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,
old_ptr = output_ptr;
/* This could be optimized to realloc() */
output_ptr = (png_charpp)png_malloc(png_ptr,
max_output_ptr * sizeof (png_charpp));
(png_uint_32)(max_output_ptr * sizeof (png_charpp)));
png_memcpy(output_ptr, old_ptr, old_max * sizeof (png_charp));
png_free(png_ptr, old_ptr);
}
else
output_ptr = (png_charpp)png_malloc(png_ptr,
max_output_ptr * sizeof (png_charp));
(png_uint_32)(max_output_ptr * sizeof (png_charp)));
}
/* save off the data */
output_ptr[num_output_ptr] = png_malloc(png_ptr,
png_ptr->zbuf_size);
output_ptr[num_output_ptr] = (png_charp)png_malloc(png_ptr,
(png_uint_32)png_ptr->zbuf_size);
png_memcpy(output_ptr[num_output_ptr], png_ptr->zbuf,
png_ptr->zbuf_size);
num_output_ptr++;
@@ -963,7 +968,8 @@ png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0,
png_debug1(3, "pCAL units length = %d\n", units_len);
total_len = purpose_len + units_len + 10;
params_len = (png_uint_32p)png_malloc(png_ptr, nparams*sizeof(png_uint_32));
params_len = (png_uint_32p)png_malloc(png_ptr, (png_uint_32)(nparams
*sizeof(png_uint_32)));
/* Find the length of each parameter, making sure we don't count the
null terminator for the last parameter. */
@@ -975,7 +981,7 @@ png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0,
}
png_debug1(3, "pCAL total length = %d\n", total_len);
png_write_chunk_start(png_ptr, png_pCAL, total_len);
png_write_chunk_start(png_ptr, png_pCAL, (png_uint_32)total_len);
png_write_chunk_data(png_ptr, (png_bytep)new_purpose, purpose_len);
png_save_int_32(buf, X0);
png_save_int_32(buf + 4, X1);
@@ -992,6 +998,7 @@ png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0,
(png_size_t)params_len[i]);
}
png_free(png_ptr, params_len);
png_write_chunk_end(png_ptr);
}
#endif
@@ -1057,14 +1064,14 @@ png_write_start_row(png_structp png_ptr)
png_ptr->usr_bit_depth + 7) >> 3) + 1);
/* set up row buffer */
png_ptr->row_buf = (png_bytep)png_malloc(png_ptr, buf_size);
png_ptr->row_buf = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size);
png_ptr->row_buf[0] = PNG_FILTER_VALUE_NONE;
/* set up filtering buffer, if using this filter */
if (png_ptr->do_filter & PNG_FILTER_SUB)
{
png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
png_ptr->rowbytes + 1);
(png_ptr->rowbytes + 1));
png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
}
@@ -1072,31 +1079,32 @@ png_write_start_row(png_structp png_ptr)
if (png_ptr->do_filter & (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH))
{
/* set up previous row buffer */
png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, buf_size);
png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size);
png_memset(png_ptr->prev_row, 0, buf_size);
if (png_ptr->do_filter & PNG_FILTER_UP)
{
png_ptr->up_row = (png_bytep )png_malloc(png_ptr,
png_ptr->rowbytes + 1);
(png_ptr->rowbytes + 1));
png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
}
if (png_ptr->do_filter & PNG_FILTER_AVG)
{
png_ptr->avg_row = (png_bytep )png_malloc(png_ptr,
png_ptr->rowbytes + 1);
png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
(png_ptr->rowbytes + 1));
png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
}
if (png_ptr->do_filter & PNG_FILTER_PAETH)
{
png_ptr->paeth_row = (png_bytep )png_malloc(png_ptr,
png_ptr->rowbytes + 1);
(png_ptr->rowbytes + 1));
png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
}
}
#ifdef PNG_WRITE_INTERLACING_SUPPORTED
/* if interlaced, we need to set up width and height of pass */
if (png_ptr->interlaced)
{
@@ -1114,6 +1122,7 @@ png_write_start_row(png_structp png_ptr)
}
}
else
#endif
{
png_ptr->num_rows = png_ptr->height;
png_ptr->usr_width = png_ptr->width;
@@ -1136,6 +1145,7 @@ png_write_finish_row(png_structp png_ptr)
if (png_ptr->row_number < png_ptr->num_rows)
return;
#ifdef PNG_WRITE_INTERLACING_SUPPORTED
/* if interlaced, go to next pass */
if (png_ptr->interlaced)
{
@@ -1177,6 +1187,7 @@ png_write_finish_row(png_structp png_ptr)
return;
}
}
#endif
/* if we get here, we've just written the last row, so we need
to flush the compressor */
@@ -1362,9 +1373,8 @@ png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
png_pass_inc[pass] - 1 -
png_pass_start[pass]) /
png_pass_inc[pass];
row_info->rowbytes = ((row_info->width *
row_info->pixel_depth + 7) >> 3);
row_info->rowbytes = ((row_info->width *
row_info->pixel_depth + 7) >> 3);
}
}
#endif
@@ -1395,7 +1405,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
* smallest value when summing the absolute values of the distances
* from zero using anything >= 128 as negative numbers. This is known
* as the "minimum sum of absolute differences" heuristic. Other
* heruistics are the "weighted minumum sum of absolute differences"
* heuristics are the "weighted minumum sum of absolute differences"
* (experimental and can in theory improve compression), and the "zlib
* predictive" method (not implemented in libpng 0.95), which does test
* compressions of lines using different filter methods, and then chooses
@@ -1411,7 +1421,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
{
png_bytep rp;
png_uint_32 sum = 0;
png_size_t i;
png_uint_32 i;
int v;
for (i = 0, rp = row_buf + 1; i < row_info->rowbytes; i++, rp++)
@@ -1428,7 +1438,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; /* Gives us some footroom */
/* Reduce the sum if we match any of the previous rows */
for (i = 0; i < png_ptr->num_prev_filters; i++)
for (i = 0; i < (png_uint_32)png_ptr->num_prev_filters; i++)
{
if (png_ptr->prev_filters[i] == PNG_FILTER_NONE)
{
@@ -1462,7 +1472,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
{
png_bytep rp, dp, lp;
png_uint_32 sum = 0, lmins = mins;
png_size_t i;
png_uint_32 i;
int v;
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
@@ -1476,7 +1486,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
lmlo = lmins & PNG_LOMASK;
lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
for (i = 0; i < png_ptr->num_prev_filters; i++)
for (i = 0; i < (png_uint_32)png_ptr->num_prev_filters; i++)
{
if (png_ptr->prev_filters[i] == PNG_FILTER_VALUE_SUB)
{
@@ -1506,7 +1516,8 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
sum += (v < 128) ? v : 256 - v;
}
for (lp = row_buf + 1; i < row_info->rowbytes; i++, rp++, lp++, dp++)
for (lp = row_buf + 1; i < row_info->rowbytes;
i++, rp++, lp++, dp++)
{
v = *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
@@ -1523,7 +1534,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
sumlo = sum & PNG_LOMASK;
sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
for (i = 0; i < png_ptr->num_prev_filters; i++)
for (i = 0; i < (png_uint_32)png_ptr->num_prev_filters; i++)
{
if (png_ptr->prev_filters[i] == PNG_FILTER_VALUE_SUB)
{
@@ -1558,7 +1569,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
{
png_bytep rp, dp, pp;
png_uint_32 sum = 0, lmins = mins;
png_size_t i;
png_uint_32 i;
int v;
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
@@ -1568,7 +1579,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
lmlo = lmins & PNG_LOMASK;
lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
for (i = 0; i < png_ptr->num_prev_filters; i++)
for (i = 0; i < (png_uint_32)png_ptr->num_prev_filters; i++)
{
if (png_ptr->prev_filters[i] == PNG_FILTER_VALUE_UP)
{
@@ -1592,7 +1603,8 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
#endif
for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
pp = prev_row + 1; i < row_info->rowbytes; i++, rp++, pp++, dp++)
pp = prev_row + 1; i < row_info->rowbytes;
i++, rp++, pp++, dp++)
{
v = *dp = (png_byte)(((int)*rp - (int)*pp) & 0xff);
@@ -1609,7 +1621,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
sumlo = sum & PNG_LOMASK;
sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
for (i = 0; i < png_ptr->num_prev_filters; i++)
for (i = 0; i < (png_uint_32)png_ptr->num_prev_filters; i++)
{
if (png_ptr->prev_filters[i] == PNG_FILTER_UP)
{
@@ -1644,7 +1656,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
{
png_bytep rp, dp, pp, lp;
png_uint_32 sum = 0, lmins = mins;
png_size_t i;
png_uint_32 i;
int v;
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
@@ -1654,7 +1666,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
lmlo = lmins & PNG_LOMASK;
lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
for (i = 0; i < png_ptr->num_prev_filters; i++)
for (i = 0; i < (png_uint_32)png_ptr->num_prev_filters; i++)
{
if (png_ptr->prev_filters[i] == PNG_FILTER_VALUE_AVG)
{
@@ -1737,7 +1749,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
{
png_bytep rp, dp, pp, cp, lp;
png_uint_32 sum = 0, lmins = mins;
png_size_t i;
png_uint_32 i;
int v;
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
@@ -1771,7 +1783,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
#endif
for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
pp = prev_row + 1; i < bpp; i++, rp++, pp++, dp++)
pp = prev_row + 1; (unsigned)i < bpp; i++, rp++, pp++, dp++)
{
v = *dp = (png_byte)(((int)*rp - (int)*pp) & 0xff);
@@ -1849,9 +1861,9 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
/* Save the type of filter we picked this time for future calculations */
if (png_ptr->num_prev_filters > 0)
{
png_byte i;
int i;
for (i = 1; i < png_ptr->num_prev_filters; i++)
for (i = 1; i < (int)png_ptr->num_prev_filters; i++)
{
png_ptr->prev_filters[i] = png_ptr->prev_filters[i - 1];
}
@@ -1920,4 +1932,3 @@ png_write_filtered_row(png_structp png_ptr, png_bytep filtered_row)
}
#endif /* PNG_WRITE_FLUSH_SUPPORTED */
}

687
synopsis.txt Normal file
View File

@@ -0,0 +1,687 @@
Synopsis, for man pages:
void *far_to_near (png_structp png_ptr,png_voidp ptr,int
check);
png_voidp png_buffered_memcpy (png_structp png_ptr, png_voidp
s1, png_voidp s2, png_uint_32 size);
png_voidp png_buffered_memset (png_structp png_ptr, png_voidp
s1, int value, png_uint_32 size);
void png_build_gamma_table (png_structp png_ptr);
void png_build_grayscale_palette (int bit_depth, png_colorp
palette);
void png_calculate_crc (png_structp png_ptr, png_bytep ptr,
png_size_t length);
void png_check_chunk_name (png_structp png_ptr, png_bytep
chunk_name);
png_size_t png_check_keyword (png_structp png_ptr, png_charp
key, png_charpp new_key);
int png_check_sig (png_bytep sig, int num);
void png_chunk_error (png_structp png_ptr, png_const_charp
error);
void png_chunk_warning (png_structp png_ptr, png_const_charp
message);
void png_combine_row (png_structp png_ptr, png_bytep row, int
mask);
void png_convert_from_struct_tm (png_timep ptime, struct tm FAR
* ttime);
void png_convert_from_time_t (png_timep ptime, time_t ttime);
png_charp png_convert_to_rfc1123) (png_structp png_ptr,
png_timep ptime);
void png_correct_palette (png_structp png_ptr, png_colorp
palette, int num_palette);
int png_crc_error (png_structp png_ptr);
int png_crc_finish (png_structp png_ptr, png_uint_32 skip);
void png_crc_read (png_structp png_ptr, png_bytep buf,
png_size_t length);
png_infop png_create_info_struct) (png_structp png_ptr);
png_structp png_create_read_struct) (png_const_charp
user_png_ver, voidp error_ptr, png_error_ptr error_fn,
png_error_ptr warn_fn);
png_voidp png_create_struct (int type);
png_structp png_create_write_struct) (png_const_charp
user_png_ver, voidp error_ptr, png_error_ptr error_fn,
png_error_ptr warn_fn);
void png_debug_free (png_structp png_ptr, png_voidp ptr);
png_voidp png_debug_malloc (png_structp png_ptr, png_uint_32
size);
void png_destroy_info_struct (png_structp png_ptr, png_infopp
info_ptr_ptr);
void png_destroy_read_struct (png_structpp png_ptr_ptr,
png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr);
void png_destroy_struct (png_voidp struct_ptr);
void png_destroy_write_struct (png_structpp png_ptr_ptr,
png_infopp info_ptr_ptr);
void png_do_background (png_row_infop row_info, png_bytep row,
png_color_16p trans_values, png_color_16p background,
png_color_16p background_1, png_bytep gamma_table, png_bytep
gamma_from_1, png_bytep gamma_to_1, png_uint_16pp gamma_16,
png_uint_16pp gamma_16_from_1, png_uint_16pp gamma_16_to_1, int
gamma_shift);
void png_do_bgr (png_row_infop row_info, png_bytep row);
void png_do_chop (png_row_infop row_info, png_bytep row);
void png_do_dither (png_row_infop row_info, png_bytep row,
png_bytep palette_lookup, png_bytep dither_lookup);
void png_do_expand (png_row_infop row_info, png_bytep row,
png_color_16p trans_value);
void png_do_expand_palette (png_row_infop row_info, png_bytep
row, png_colorp palette, png_bytep trans, int num_trans);
void png_do_gamma (png_row_infop row_info, png_bytep row,
png_bytep gamma_table, png_uint_16pp gamma_16_table, int
gamma_shift);
void png_do_gray_to_rgb (png_row_infop row_info, png_bytep
row);
void png_do_invert (png_row_infop row_info, png_bytep row);
void png_do_pack (png_row_infop row_info, png_bytep row,
png_uint_32 bit_depth);
void png_do_packswap (png_row_infop row_info, png_bytep row);
void png_do_read_filler (png_row_infop row_info, png_bytep row,
png_uint_32 filler, png_uint_32 flags);
void png_do_read_interlace (png_row_infop row_info, png_bytep
row, int pass, png_uint_32 transformations);
void png_do_read_invert_alpha (png_row_infop row_info,
png_bytep row);
void png_do_read_swap_alpha (png_row_infop row_info, png_bytep
row);
void png_do_read_transformations (png_structp png_ptr);
void png_do_rgb_to_gray (png_row_infop row_info, png_bytep
row);
void png_do_shift (png_row_infop row_info, png_bytep row,
png_color_8p bit_depth);
void png_do_strip_filler (png_row_infop row_info, png_bytep
row, png_uint_32 flags);
void png_do_swap (png_row_infop row_info, png_bytep row);
void png_do_unpack (png_row_infop row_info, png_bytep row);
void png_do_unshift (png_row_infop row_info, png_bytep row,
png_color_8p sig_bits);
void png_do_write_interlace (png_row_infop row_info, png_bytep
row, int pass);
void png_do_write_invert_alpha (png_row_infop row_info,
png_bytep row);
void png_do_write_swap_alpha (png_row_infop row_info, png_bytep
row);
void png_do_write_transformations (png_structp png_ptr);
void png_error (png_structp png_ptr, png_const_charp error);
void png_flush (png_structp png_ptr);
void png_free (png_structp png_ptr, png_voidp ptr);
png_byte png_get_bit_depth (png_structp png_ptr, png_infop
info_ptr);
png_uint_32 png_get_bKGD (png_structp png_ptr, png_infop
info_ptr, png_color_16p *background);
png_byte png_get_channels (png_structp png_ptr, png_infop
info_ptr);
png_uint_32 png_get_cHRM (png_structp png_ptr, png_infop
info_ptr, double *white_x, double *white_y, double *red_x,
double *red_y, double *green_x, double *green_y, double
*blue_x, double *blue_y);
png_byte png_get_color_type (png_structp png_ptr, png_infop
info_ptr);
png_byte png_get_compression_type (png_structp png_ptr,
png_infop info_ptr);
png_voidp png_get_error_ptr (png_structp png_ptr);
png_byte png_get_filter_type (png_structp png_ptr, png_infop
info_ptr);
png_uint_32 png_get_gAMA (png_structp png_ptr, png_infop
info_ptr, double *file_gamma);
png_uint_32 png_get_hIST (png_structp png_ptr, png_infop
info_ptr, png_uint_16p *hist);
png_uint_32 png_get_image_height (png_structp png_ptr,
png_infop info_ptr);
png_uint_32 png_get_image_width (png_structp png_ptr, png_infop
info_ptr);
png_int_32 png_get_int_32 (png_bytep buf);
png_byte png_get_interlace_type (png_structp png_ptr, png_infop
info_ptr);
png_voidp png_get_io_ptr (png_structp png_ptr);
png_uint_32 png_get_IHDR (png_structp png_ptr, png_infop
info_ptr, png_uint_32 *width, png_uint_32 *height, int
*bit_depth, int *color_type, int *interlace_type, int
*compression_type, int *filter_type);
png_uint_32 png_get_oFFs (png_structp png_ptr, png_infop
info_ptr, png_uint_32 *offset_x, png_uint_32 *offset_y, int
*unit_type);
png_uint_32 png_get_pCAL (png_structp png_ptr, png_infop
info_ptr, png_charp *purpose, png_int_32 *X0, png_int_32 *X1,
int *type, int *nparams, png_charp *units, png_charpp *params);
png_uint_32 png_get_pHYs (png_structp png_ptr, png_infop
info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int
*unit_type);
float png_get_pixel_aspect_ratio (png_structp png_ptr,
png_infop info_ptr);
png_uint_32 png_get_pixels_per_meter (png_structp png_ptr,
png_infop info_ptr);
png_voidp png_get_progressive_ptr (png_structp png_ptr);
png_uint_32 png_get_PLTE (png_structp png_ptr, png_infop
info_ptr, png_colorp *palette, int *num_palette);
png_uint_32 png_get_rowbytes (png_structp png_ptr, png_infop
info_ptr);
png_uint_32 png_get_sBIT (png_structp png_ptr, png_infop
info_ptr, png_color_8p *sig_bit);
png_bytep png_get_signature (png_structp png_ptr, png_infop
info_ptr);
png_uint_32 png_get_sRGB (png_structp png_ptr, png_infop
info_ptr, int *intent);
png_uint_32 png_get_text (png_structp png_ptr, png_infop
info_ptr, png_textp *text_ptr, int *num_text);
png_uint_32 png_get_tIME (png_structp png_ptr, png_infop
info_ptr, png_timep *mod_time);
png_uint_32 png_get_tRNS (png_structp png_ptr, png_infop
info_ptr, png_bytep *trans, int *num_trans, png_color_16p
*trans_values);
png_uint_16 png_get_uint_16 (png_bytep buf);
png_uint_32 png_get_uint_32 (png_bytep buf);
png_uint_32 png_get_valid (png_structp png_ptr, png_infop
info_ptr, png_uint_32 flag);
png_uint_32 png_get_x_offset_microns (png_structp png_ptr,
png_infop info_ptr);
png_uint_32 png_get_x_offset_pixels (png_structp png_ptr,
png_infop info_ptr);
png_uint_32 png_get_y_offset_microns (png_structp png_ptr,
png_infop info_ptr);
png_uint_32 png_get_y_offset_pixels (png_structp png_ptr,
png_infop info_ptr);
void png_handle_bKGD (png_structp png_ptr, png_infop info_ptr,
png_uint_32 length);
void png_handle_cHRM (png_structp png_ptr, png_infop info_ptr,
png_uint_32 length);
void png_handle_gAMA (png_structp png_ptr, png_infop info_ptr,
png_uint_32 length);
void png_handle_hIST (png_structp png_ptr, png_infop info_ptr,
png_uint_32 length);
void png_handle_IEND (png_structp png_ptr, png_infop info_ptr,
png_uint_32 length);
void png_handle_IHDR (png_structp png_ptr, png_infop info_ptr,
png_uint_32 length);
void png_handle_oFFs (png_structp png_ptr, png_infop info_ptr,
png_uint_32 length);
void png_handle_pCAL (png_structp png_ptr, png_infop info_ptr,
png_uint_32 length);
void png_handle_pHYs (png_structp png_ptr, png_infop info_ptr,
png_uint_32 length);
void png_handle_PLTE (png_structp png_ptr, png_infop info_ptr,
png_uint_32 length);
void png_handle_sBIT (png_structp png_ptr, png_infop info_ptr,
png_uint_32 length);
void png_handle_sRGB (png_structp png_ptr, png_infop info_ptr,
png_uint_32 length);
void png_handle_tEXt (png_structp png_ptr, png_infop info_ptr,
png_uint_32 length);
void png_handle_tIME (png_structp png_ptr, png_infop info_ptr,
png_uint_32 length);
void png_handle_tRNS (png_structp png_ptr, png_infop info_ptr,
png_uint_32 length);
void png_handle_unknown (png_structp png_ptr, png_infop
info_ptr, png_uint_32 length);
void png_handle_zTXt (png_structp png_ptr, png_infop info_ptr,
png_uint_32 length);
void png_info_destroy (png_structp png_ptr, png_infop
info_ptr);
void png_info_init (png_infop info_ptr);
void png_init_io (png_structp png_ptr, FILE *fp);
void png_init_read_transformations (png_structp png_ptr);
png_voidp png_malloc (png_structp png_ptr, png_uint_32 size);
void png_process_data (png_structp png_ptr, png_infop info_ptr,
png_bytep buffer, png_size_t buffer_size);
void png_process_IDAT_data (png_structp png_ptr, png_bytep
buffer, png_size_t buffer_length);
void png_process_some_data (png_structp png_ptr, png_infop
info_ptr);
void png_progressive_combine_row (png_structp png_ptr,
png_bytep old_row, png_bytep new_row);
void png_push_check_crc (png_structp png_ptr);
void png_push_crc_finish (png_structp png_ptr);
void png_push_crc_skip (png_structp png_ptr, png_uint_32
length);
void png_push_fill_buffer (png_structp png_ptr, png_bytep
buffer, png_size_t length);
void png_push_handle_tEXt (png_structp png_ptr, png_infop
info_ptr, png_uint_32 length);
void png_push_handle_unknown (png_structp png_ptr, png_infop
info_ptr, png_uint_32 length);
void png_push_handle_zTXt (png_structp png_ptr, png_infop
info_ptr, png_uint_32 length);
void png_push_have_end (png_structp png_ptr, png_infop
info_ptr);
void png_push_have_info (png_structp png_ptr, png_infop
info_ptr);
void png_push_have_row (png_structp png_ptr, png_bytep row);
void png_push_process_row (png_structp png_ptr);
void png_push_read_chunk (png_structp png_ptr, png_infop
info_ptr);
void png_push_read_end (png_structp png_ptr, png_infop
info_ptr);
void png_push_read_IDAT (png_structp png_ptr);
void png_push_read_sig (png_structp png_ptr, png_infop
info_ptr);
void png_push_read_tEXt (png_structp png_ptr, png_infop
info_ptr);
void png_push_read_zTXt (png_structp png_ptr, png_infop
info_ptr);
void png_push_restore_buffer (png_structp png_ptr, png_bytep
buffer, png_size_t buffer_length);
void png_push_save_buffer (png_structp png_ptr);
void png_read_data (png_structp png_ptr, png_bytep data,
png_size_t length);
void png_read_destroy (png_structp png_ptr, png_infop info_ptr,
png_infop end_info_ptr);
void png_read_end (png_structp png_ptr, png_infop info_ptr);
void png_read_filter_row (png_structp png_ptr, png_row_infop
row_info, png_bytep row, png_bytep prev_row, int filter);
void png_read_finish_row (png_structp png_ptr);
void png_read_image (png_structp png_ptr, png_bytepp image);
void png_read_info (png_structp png_ptr, png_infop info_ptr);
void png_read_init (png_structp png_ptr);
void png_read_push_finish_row (png_structp png_ptr);
void png_read_row (png_structp png_ptr, png_bytep row,
png_bytep display_row);
void png_read_rows (png_structp png_ptr, png_bytepp row,
png_bytepp display_row, png_uint_32 num_rows);
void png_read_start_row (png_structp png_ptr);
void png_read_transform_info (png_structp png_ptr, png_infop
info_ptr);
void png_read_update_info (png_structp png_ptr, png_infop
info_ptr);
void png_reset_crc (png_structp png_ptr);
void png_save_int_32 (png_bytep buf, png_int_32 i);
void png_save_uint_16 (png_bytep buf, unsigned int i);
void png_save_uint_32 (png_bytep buf, png_uint_32 i);
void png_set_background (png_structp png_ptr, png_color_16p
background_color, int background_gamma_code, int need_expand,
double background_gamma);
void png_set_bgr (png_structp png_ptr);
void png_set_bKGD (png_structp png_ptr, png_infop info_ptr,
png_color_16p background);
void png_set_cHRM (png_structp png_ptr, png_infop info_ptr,
double white_x, double white_y, double red_x, double red_y,
double green_x, double green_y, double blue_x, double blue_y);
void png_set_compression_level (png_structp png_ptr, int
level);
void png_set_compression_mem_level) (png_structp png_ptr, int
mem_level);
void png_set_compression_method (png_structp png_ptr, int
method);
void png_set_compression_strategy) (png_structp png_ptr, int
strategy);
void png_set_compression_window_bits) (png_structp png_ptr, int
window_bits);
void png_set_crc_action (png_structp png_ptr, int crit_action,
int ancil_action);
void png_set_dither (png_structp png_ptr, png_colorp palette,
int num_palette, int maximum_colors, png_uint_16p histogram,
int full_dither);
void png_set_error_fn (png_structp png_ptr, png_voidp
error_ptr, png_error_ptr error_fn, png_error_ptr warning_fn);
void png_set_expand (png_structp png_ptr);
void png_set_filler (png_structp png_ptr, png_uint_32 filler,
int flags);
void png_set_filter (png_structp png_ptr, int method, int
filters);
void png_set_filter_heuristics (png_structp png_ptr, int
heuristic_method, int num_weights, png_doublep filter_weights,
png_doublep filter_costs);
void png_set_flush (png_structp png_ptr, int nrows);
void png_set_gamma (png_structp png_ptr, double screen_gamma,
double default_file_gamma);
void png_set_gAMA (png_structp png_ptr, png_infop info_ptr,
double file_gamma);
void png_set_gray_to_rgb (png_structp png_ptr);
void png_set_hIST (png_structp png_ptr, png_infop info_ptr,
png_uint_16p hist);
int png_set_interlace_handling (png_structp png_ptr);
void png_set_invert_alpha (png_structp png_ptr);
void png_set_invert_mono (png_structp png_ptr);
void png_set_IHDR (png_structp png_ptr, png_infop info_ptr,
png_uint_32 width, png_uint_32 height, int bit_depth, int
color_type, int interlace_type, int compression_type, int
filter_type);
void png_set_oFFs (png_structp png_ptr, png_infop info_ptr,
png_uint_32 offset_x, png_uint_32 offset_y, int unit_type);
void png_set_packing (png_structp png_ptr);
void png_set_packswap (png_structp png_ptr);
void png_set_pCAL (png_structp png_ptr, png_infop info_ptr,
png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int
nparams, png_charp units, png_charpp params);
void png_set_pHYs (png_structp png_ptr, png_infop info_ptr,
png_uint_32 res_x, png_uint_32 res_y, int unit_type);
void png_set_progressive_read_fn (png_structp png_ptr,
png_voidp progressive_ptr, png_progressive_info_ptr info_fn,
png_progressive_row_ptr row_fn, png_progressive_end_ptr
end_fn);
void png_set_PLTE (png_structp png_ptr, png_infop info_ptr,
png_colorp palette, int num_palette);
void png_set_read_fn (png_structp png_ptr, png_voidp io_ptr,
png_rw_ptr read_data_fn);
void png_set_rgb_to_gray (png_structp png_ptr);
void png_set_sBIT (png_structp png_ptr, png_infop info_ptr,
png_color_8p sig_bit);
void png_set_shift (png_structp png_ptr, png_color_8p
true_bits);
void png_set_sig_bytes (png_structp png_ptr, int num_bytes);
void png_set_sRGB (png_structp png_ptr, png_infop info_ptr, int
intent);
void png_set_sRGB_gAMA_and_cHRM (png_structp png_ptr, png_infop
info_ptr, int intent);
void png_set_strip_16 (png_structp png_ptr);
void png_set_strip_alpha (png_structp png_ptr);
void png_set_swap (png_structp png_ptr);
void png_set_swap_alpha (png_structp png_ptr);
void png_set_text (png_structp png_ptr, png_infop info_ptr,
png_textp text_ptr, int num_text);
void png_set_tIME (png_structp png_ptr, png_infop info_ptr,
png_timep mod_time);
void png_set_tRNS (png_structp png_ptr, png_infop info_ptr,
png_bytep trans, int num_trans, png_color_16p trans_values);
void png_set_write_fn (png_structp png_ptr, png_voidp io_ptr,
png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn);
int png_sig_cmp (png_bytep sig, png_size_t start, png_size_t
num_to_check);
void png_start_read_image (png_structp png_ptr);
void png_warning (png_structp png_ptr, png_const_charp
message);
void png_write_bKGD (png_structp png_ptr, png_color_16p values,
int color_type);
void png_write_chunk (png_structp png_ptr, png_bytep
chunk_name, png_bytep data, png_size_t length);
void png_write_chunk_data (png_structp png_ptr, png_bytep data,
png_size_t length);
void png_write_chunk_end (png_structp png_ptr);
void png_write_chunk_start (png_structp png_ptr, png_bytep
chunk_name, png_uint_32 length);
void png_write_cHRM (png_structp png_ptr, double white_x,
double white_y, double red_x, double red_y, double green_x,
double green_y, double blue_x, double blue_y);
void png_write_data (png_structp png_ptr, png_bytep data,
png_size_t length);
void png_write_destroy (png_structp png_ptr);
void png_write_destroy_info (png_infop info_ptr);
void png_write_end (png_structp png_ptr, png_infop info_ptr);
void png_write_filtered_row (png_structp png_ptr, png_bytep
filtered_row);
void png_write_find_filter (png_structp png_ptr, png_row_infop
row_info);
void png_write_finish_row (png_structp png_ptr);
void png_write_flush (png_structp png_ptr);
void png_write_gAMA (png_structp png_ptr, double file_gamma);
void png_write_hIST (png_structp png_ptr, png_uint_16p hist,
int num_hist);
void png_write_image (png_structp png_ptr, png_bytepp image);
void png_write_info (png_structp png_ptr, png_infop info_ptr);
void png_write_init (png_structp png_ptr);
void png_write_IDAT (png_structp png_ptr, png_bytep data,
png_size_t length);
void png_write_IEND (png_structp png_ptr);
void png_write_IHDR (png_structp png_ptr, png_uint_32 width,
png_uint_32 height, int bit_depth, int color_type, int
compression_type, int filter_type, int interlace_type);
void png_write_oFFs (png_structp png_ptr, png_uint_32 x_offset,
png_uint_32 y_offset, int unit_type);
void png_write_pCAL (png_structp png_ptr, png_charp purpose,
png_int_32 X0, png_int_32 X1, int type, int nparams, png_charp
units, png_charpp params);
void png_write_pHYs (png_structp png_ptr, png_uint_32
x_pixels_per_unit, png_uint_32 y_pixels_per_unit, int
unit_type);
void png_write_PLTE (png_structp png_ptr, png_colorp palette,
png_uint_32 num_pal);
void png_write_row (png_structp png_ptr, png_bytep row);
void png_write_rows (png_structp png_ptr, png_bytepp row,
png_uint_32 num_rows);
void png_write_sBIT (png_structp png_ptr, png_color_8p sbit,
int color_type);
void png_write_sig (png_structp png_ptr);
void png_write_sRGB (png_structp png_ptr, int intent);
void png_write_start_row (png_structp png_ptr);
void png_write_tEXt (png_structp png_ptr, png_charp key,
png_charp text, png_size_t text_len);
void png_write_tIME (png_structp png_ptr, png_timep mod_time);
void png_write_tRNS (png_structp png_ptr, png_bytep trans,
png_color_16p values, int number, int color_type);
void png_write_zTXt (png_structp png_ptr, png_charp key,
png_charp text, png_size_t text_len, int compression);
voidpf png_zalloc (voidpf png_ptr, uInt items, uInt size);
void png_zfree (voidpf png_ptr, voidpf ptr);