mirror of
https://git.code.sf.net/p/libpng/code.git
synced 2025-07-10 18:04:09 +02:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b212002101 | ||
|
|
46f61e2398 | ||
|
|
c4a2ae6cac | ||
|
|
2687fcc7b5 | ||
|
|
70e3f543f1 | ||
|
|
b6ce43d6ff |
49
CHANGES
49
CHANGES
@@ -167,3 +167,52 @@ version 0.96 [May, 1997]
|
||||
added read of CRC after IEND chunk for embedded PNGs (Laszlo Nyul)
|
||||
added typecasts to quiet compiler errors
|
||||
added more debugging info
|
||||
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. (Andreas Dilger)
|
||||
added RFC 1152 [sic] date support
|
||||
fixed bug in gamma handling of 4-bit grayscale
|
||||
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 (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 (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 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.)
|
||||
|
||||
|
||||
56
README
56
README
@@ -1,16 +1,22 @@
|
||||
README for libpng 0.96
|
||||
[NOTE: this is still beta version 0.99a; the text below has already
|
||||
been updated in anticipation of the imminent 1.0 release.]
|
||||
|
||||
This is the sixth (and hopefully last) beta release of libpng 1.0.
|
||||
The changes from libpng-0.90 include bug fixes, a C++ wrapper for
|
||||
png.h, some additions to the API, as well as internal changes to
|
||||
the library. See "CHANGES" for a detailed list of differences.
|
||||
|
||||
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 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.
|
||||
|
||||
****
|
||||
Note that some of the changes to the png_info structure render this
|
||||
version of the library binary incompatible with libpng-0.89 or
|
||||
earlier versions if you are using a shared library. The type of the
|
||||
"filler" parameter for png_set_filler() has changed from png_byte to
|
||||
png_uint_32, which will affect shared-library applications which use
|
||||
png_uint_32, which will affect shared-library applications that use
|
||||
this function.
|
||||
|
||||
To avoid problems with changes to the internals of png_info_struct,
|
||||
@@ -19,6 +25,12 @@ access to info_ptr. These functions are the png_set_<chunk> and
|
||||
png_get_<chunk> functions. These functions should be used when
|
||||
accessing/storing the info_struct data, rather than manipulating it
|
||||
directly, to avoid such problems in the future.
|
||||
|
||||
It is important to note that the APIs do not make current programs
|
||||
that access the info struct directly incompatible with the new
|
||||
library. However, it is strongly suggested that new programs use
|
||||
the new APIs (as shown in example.c), and older programs be converted
|
||||
to the new format, to facilitate upgrades in the future.
|
||||
****
|
||||
|
||||
Additions since 0.90 include the ability to compile libpng as a
|
||||
@@ -65,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
|
||||
@@ -85,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,
|
||||
@@ -120,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
|
||||
@@ -154,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/
|
||||
|
||||
|
||||
3
TODO
3
TODO
@@ -3,8 +3,9 @@ pngtodo.txt - list of things to do for libpng
|
||||
add "grayscale->palette" transformation and "palette->grayscale" detection
|
||||
improved dithering
|
||||
multi-lingual error and warning message support
|
||||
sPLT chunk handling
|
||||
cHRM transformation
|
||||
sRGB chunk handling
|
||||
complete sRGB transformation (presently it simply uses gamma=0.45)
|
||||
man pages for function calls
|
||||
high-level API for reading images
|
||||
final bug fixes
|
||||
|
||||
136
example.c
136
example.c
@@ -1,36 +1,36 @@
|
||||
/* example.c - an example of using libpng */
|
||||
|
||||
/* This is an example of how to use libpng to read and write PNG files.
|
||||
The file libpng.txt is much more verbose then this. If you have not
|
||||
read it, do so first. This was designed to be a starting point of an
|
||||
implementation. This is not officially part of libpng, and therefore
|
||||
does not require a copyright notice.
|
||||
|
||||
This file does not currently compile, because it is missing certain
|
||||
parts, like allocating memory to hold an image. You will have to
|
||||
supply these parts to get it to compile. For an example of a minimal
|
||||
working PNG reader/writer, see pngtest.c, included in this distribution.
|
||||
*/
|
||||
* The file libpng.txt is much more verbose then this. If you have not
|
||||
* read it, do so first. This was designed to be a starting point of an
|
||||
* implementation. This is not officially part of libpng, and therefore
|
||||
* does not require a copyright notice.
|
||||
*
|
||||
* This file does not currently compile, because it is missing certain
|
||||
* parts, like allocating memory to hold an image. You will have to
|
||||
* supply these parts to get it to compile. For an example of a minimal
|
||||
* working PNG reader/writer, see pngtest.c, included in this distribution.
|
||||
*/
|
||||
|
||||
#include <png.h>
|
||||
|
||||
/* Check to see if a file is a PNG file using png_check_sig(). Returns
|
||||
non-zero if the image is a PNG, and 0 if it isn't a PNG.
|
||||
|
||||
If this call is successful, and you are going to keep the file open,
|
||||
you should call png_set_sig_bytes(png_ptr, PNG_BYTES_TO_CHECK); once
|
||||
you have created the png_ptr, so that libpng knows your application
|
||||
has read that many bytes from the start of the file. Make sure you
|
||||
don't call png_set_sig_bytes() with more than 8 bytes read or give it
|
||||
an incorrect number of bytes read, or you will either have read too
|
||||
many bytes (your fault), or you are telling libpng to read the wrong
|
||||
number of magic bytes (also your fault).
|
||||
|
||||
Many applications already read the first 2 or 4 bytes from the start
|
||||
of the image to determine the file type, so it would be easiest just
|
||||
to pass the bytes to png_check_sig() or even skip that if you know
|
||||
you have a PNG file, and call png_set_sig_bytes().
|
||||
*/
|
||||
* non-zero if the image is a PNG, and 0 if it isn't a PNG.
|
||||
*
|
||||
* If this call is successful, and you are going to keep the file open,
|
||||
* you should call png_set_sig_bytes(png_ptr, PNG_BYTES_TO_CHECK); once
|
||||
* you have created the png_ptr, so that libpng knows your application
|
||||
* has read that many bytes from the start of the file. Make sure you
|
||||
* don't call png_set_sig_bytes() with more than 8 bytes read or give it
|
||||
* an incorrect number of bytes read, or you will either have read too
|
||||
* many bytes (your fault), or you are telling libpng to read the wrong
|
||||
* number of magic bytes (also your fault).
|
||||
*
|
||||
* Many applications already read the first 2 or 4 bytes from the start
|
||||
* of the image to determine the file type, so it would be easiest just
|
||||
* to pass the bytes to png_check_sig() or even skip that if you know
|
||||
* you have a PNG file, and call png_set_sig_bytes().
|
||||
*/
|
||||
#define PNG_BYTES_TO_CHECK 4
|
||||
int check_if_png(char *file_name, FILE **fp)
|
||||
{
|
||||
@@ -49,10 +49,11 @@ int check_if_png(char *file_name, FILE **fp)
|
||||
}
|
||||
|
||||
/* Read a PNG file. You may want to return an error code if the read
|
||||
fails (depending upon the failure). There are two "prototypes" given
|
||||
here - one where we are given the filename, and we need to open the
|
||||
file, and the other where we are given an open file (possibly with
|
||||
some or all of the magic bytes read - see comments above). */
|
||||
* fails (depending upon the failure). There are two "prototypes" given
|
||||
* here - one where we are given the filename, and we need to open the
|
||||
* file, and the other where we are given an open file (possibly with
|
||||
* some or all of the magic bytes read - see comments above).
|
||||
*/
|
||||
**** prototype 1 ****
|
||||
void read_png(char *file_name) /* We need to open the file */
|
||||
{
|
||||
@@ -118,7 +119,8 @@ void read_png(FILE *fp, unsigned int sig_read) /* file is already open */
|
||||
|
||||
**** PNG file I/O method 2 ****
|
||||
/* If you are using replacement read functions, instead of calling
|
||||
* png_init_io() here you would call */
|
||||
* png_init_io() here you would call:
|
||||
*/
|
||||
png_set_read_fn(png_ptr, (void *)user_io_ptr, user_read_fn);
|
||||
/* where user_io_ptr is a structure you want available to the callbacks */
|
||||
**** Use only one I/O method! ****
|
||||
@@ -143,29 +145,31 @@ void read_png(FILE *fp, unsigned int sig_read) /* file is already open */
|
||||
/* tell libpng to strip 16 bit/color files down to 8 bits/color */
|
||||
png_set_strip_16(png_ptr);
|
||||
|
||||
/* strip alpha bytes from the input data without combining with th
|
||||
* background (not recommended) */
|
||||
/* Strip alpha bytes from the input data without combining with th
|
||||
* background (not recommended).
|
||||
*/
|
||||
png_set_strip_alpha(png_ptr);
|
||||
|
||||
/* extract multiple pixels with bit depths of 1, 2, and 4 from a single
|
||||
/* Extract multiple pixels with bit depths of 1, 2, and 4 from a single
|
||||
* byte into separate bytes (useful for paletted and grayscale images).
|
||||
*/
|
||||
png_set_packing(png_ptr);
|
||||
|
||||
/* change the order of packed pixels to least significant bit first
|
||||
/* Change the order of packed pixels to least significant bit first
|
||||
* (not useful if you are using png_set_packing). */
|
||||
png_set_packswap(png_ptr);
|
||||
|
||||
/* expand paletted colors into true RGB triplets */
|
||||
/* Expand paletted colors into true RGB triplets */
|
||||
if (color_type == PNG_COLOR_TYPE_PALETTE)
|
||||
png_set_expand(png_ptr);
|
||||
|
||||
/* expand grayscale images to the full 8 bits from 1, 2, or 4 bits/pixel */
|
||||
/* Expand grayscale images to the full 8 bits from 1, 2, or 4 bits/pixel */
|
||||
if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
|
||||
png_set_expand(png_ptr);
|
||||
|
||||
/* expand paletted or RGB images with transparency to full alpha channels
|
||||
* so the data will be available as RGBA quartets */
|
||||
/* Expand paletted or RGB images with transparency to full alpha channels
|
||||
* so the data will be available as RGBA quartets.
|
||||
*/
|
||||
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
|
||||
png_set_expand(png_ptr);
|
||||
|
||||
@@ -186,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 */
|
||||
}
|
||||
|
||||
@@ -207,13 +214,20 @@ 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_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);
|
||||
|
||||
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.50);
|
||||
|
||||
/* Dither RGB files down to 8 bit palette or reduce palettes
|
||||
to the number of colors available on your screen */
|
||||
* to the number of colors available on your screen.
|
||||
*/
|
||||
if (color_type & PNG_COLOR_MASK_COLOR)
|
||||
{
|
||||
png_uint_32 num_palette;
|
||||
@@ -241,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
|
||||
@@ -269,19 +283,19 @@ void read_png(FILE *fp, unsigned int sig_read) /* file is already open */
|
||||
|
||||
/* Turn on interlace handling. REQUIRED if you are not using
|
||||
* png_read_image(). To see how to handle interlacing passes,
|
||||
* see the png_read_row() method below.
|
||||
* see the png_read_row() method below:
|
||||
*/
|
||||
number_passes = png_set_interlace_handling(png_ptr);
|
||||
|
||||
/* optional call to gamma correct and add the background to the palette
|
||||
/* Optional call to gamma correct and add the background to the palette
|
||||
* and update info structure. REQUIRED if you are expecting libpng to
|
||||
* update the palette for you (ie you selected such a transform above).
|
||||
*/
|
||||
png_read_update_info(png_ptr, info_ptr);
|
||||
|
||||
/* allocate the memory to hold the image using the fields of info_ptr. */
|
||||
/* Allocate the memory to hold the image using the fields of info_ptr. */
|
||||
|
||||
/* the easiest way to read the image */
|
||||
/* The easiest way to read the image: */
|
||||
png_bytep row_pointers[height];
|
||||
|
||||
for (row = 0; row < height; row++)
|
||||
@@ -294,7 +308,7 @@ void read_png(FILE *fp, unsigned int sig_read) /* file is already open */
|
||||
png_read_image(png_ptr, row_pointers);
|
||||
|
||||
**** Read the image one or more scanlines at a time ****
|
||||
/* the other way to read images - deal with interlacing */
|
||||
/* The other way to read images - deal with interlacing: */
|
||||
|
||||
for (pass = 0; pass < number_passes; pass++)
|
||||
{
|
||||
@@ -535,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);
|
||||
|
||||
@@ -552,7 +566,8 @@ void write_png(char *file_name, ... other image information ...)
|
||||
|
||||
|
||||
/* Optional gamma chunk is strongly suggested if you have any guess
|
||||
* as to the correct gamma of the image. */
|
||||
* as to the correct gamma of the image.
|
||||
*/
|
||||
png_set_gAMA(png_ptr, info_ptr, gamma);
|
||||
|
||||
/* Optionally write comments into the image */
|
||||
@@ -568,6 +583,8 @@ void write_png(char *file_name, ... other image information ...)
|
||||
png_set_text(png_ptr, info_ptr, text_ptr, 2);
|
||||
|
||||
/* other optional chunks like cHRM, bKGD, tRNS, tIME, oFFs, pHYs, */
|
||||
/* note that if sRGB is present the cHRM chunk must be ignored
|
||||
* on read and must be written in accordance with the sRGB profile */
|
||||
|
||||
/* Write the file header information. REQUIRED */
|
||||
png_write_info(png_ptr, info_ptr);
|
||||
@@ -579,13 +596,15 @@ void write_png(char *file_name, ... other image information ...)
|
||||
*/
|
||||
|
||||
/* set up the transformations you want. Note that these are
|
||||
* all optional. Only call them if you want them. */
|
||||
* all optional. Only call them if you want them.
|
||||
*/
|
||||
|
||||
/* 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 */
|
||||
* as appropriate to correctly scale the image.
|
||||
*/
|
||||
png_set_shift(png_ptr, &sig_bit);
|
||||
|
||||
/* pack pixels into bytes */
|
||||
@@ -595,7 +614,8 @@ void write_png(char *file_name, ... other image information ...)
|
||||
png_set_swap_alpha(png_ptr);
|
||||
|
||||
/* Get rid of filler (OR ALPHA) bytes, pack XRGB/RGBX/ARGB/RGBA into
|
||||
* RGB (4 channels -> 3 channels). The second parameter is not used. */
|
||||
* RGB (4 channels -> 3 channels). The second parameter is not used.
|
||||
*/
|
||||
png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
|
||||
|
||||
/* flip BGR pixels to RGB */
|
||||
|
||||
306
libpng.txt
306
libpng.txt
@@ -1,11 +1,17 @@
|
||||
libpng.txt - a description on how to use and modify libpng
|
||||
|
||||
libpng 1.0 beta 5 - version 0.95
|
||||
Updated and distributed by Andreas Dilger <adilger@enel.ucalgary.ca>,
|
||||
Copyright (c) 1996, 1997 Andreas Dilger
|
||||
March 15, 1997
|
||||
libpng version 0.99a
|
||||
Updated and distributed by Glenn Randers-Pehrson <randeg@alumni.rpi.edu>
|
||||
Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
January 31, 1998
|
||||
|
||||
based on:
|
||||
|
||||
libpng 1.0 beta 6 version 0.96
|
||||
Updated and distributed by Andreas Dilger
|
||||
Copyright (c) 1996, 1997 Andreas Dilger
|
||||
May 28, 1997
|
||||
|
||||
libpng 1.0 beta 2 - version 0.88
|
||||
For conditions of distribution and use, see copyright notice in png.h
|
||||
Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
@@ -26,12 +32,19 @@ 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
|
||||
file format in application programs. Most users will not have to
|
||||
modify the library significantly; advanced users may want to modify it
|
||||
more. All attempts were made to make it as complete as possible,
|
||||
while keeping the code easy to understand. Currently, this library
|
||||
only supports C. Support for other languages is being considered.
|
||||
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
|
||||
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/>.
|
||||
|
||||
Most users will not have to modify the library significantly; advanced
|
||||
users may want to modify it more. All attempts were made to make it as
|
||||
complete as possible, while keeping the code easy to understand.
|
||||
Currently, this library only supports C. Support for other languages
|
||||
is being considered.
|
||||
|
||||
Libpng has been designed to handle multiple sessions at one time,
|
||||
to be easily modifiable, to be portable to the vast majority of
|
||||
@@ -39,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
|
||||
@@ -59,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.
|
||||
|
||||
@@ -183,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().
|
||||
|
||||
@@ -209,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
|
||||
@@ -227,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
|
||||
@@ -242,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
|
||||
@@ -280,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
|
||||
@@ -291,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
|
||||
@@ -341,7 +399,7 @@ transparency information in a tRNS chunk. This is most useful on
|
||||
grayscale images with bit depths of 2 or 4 or if there is a multiple-image
|
||||
viewing application that wishes to treat all images in the same way.
|
||||
|
||||
if (color_type == PNG_COLOR_TYPE_PALETTE && bit_depth < 8)
|
||||
if (color_type == PNG_COLOR_TYPE_PALETTE && bit_depth <= 8)
|
||||
png_set_expand(png_ptr);
|
||||
|
||||
if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
|
||||
@@ -356,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);
|
||||
@@ -371,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.
|
||||
@@ -413,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
|
||||
@@ -447,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
|
||||
@@ -477,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()
|
||||
@@ -532,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);
|
||||
@@ -572,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:
|
||||
|
||||
@@ -589,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).
|
||||
|
||||
@@ -614,7 +687,7 @@ The first pass will return an image 1/8 as wide as the entire image
|
||||
(every 8th column starting in column 0) and 1/8 as high as the original
|
||||
(every 8th row starting in row 0), the second will be 1/8 as wide
|
||||
(starting in column 4) and 1/8 as high (also starting in row 0). The
|
||||
third pass will be 1/4 as wide (every 4th pixel starting in row 0) and
|
||||
third pass will be 1/4 as wide (every 4th pixel starting in column 0) and
|
||||
1/8 as high (every 8th row starting in row 4), and the fourth pass will
|
||||
be 1/4 as wide and 1/4 as high (every 4th column starting in column 2,
|
||||
and every 4th row starting in row 0). The fifth pass will return an
|
||||
@@ -628,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.
|
||||
@@ -639,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.
|
||||
@@ -923,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.
|
||||
@@ -940,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)
|
||||
@@ -953,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
|
||||
@@ -986,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
|
||||
@@ -1013,7 +1117,8 @@ The keywords that are given in the PNG Specification are:
|
||||
Author Name of image's creator
|
||||
Description Description of image (possibly long)
|
||||
Copyright Copyright notice
|
||||
Creation Time Time of original image creation
|
||||
Creation Time Time of original image creation (usually
|
||||
RFC 1123 format, see below)
|
||||
Software Software used to create the image
|
||||
Disclaimer Legal disclaimer
|
||||
Warning Warning of nature of content
|
||||
@@ -1050,6 +1155,20 @@ instead of your local time. Note that the year number is the full
|
||||
year (ie 1996, rather than 96 - PNG is year 2000 compliant!), and
|
||||
that months start with 1.
|
||||
|
||||
If you want to store the time of the original image creation, you should
|
||||
use a plain tEXt chunk with the "Creation Time" keyword. This is
|
||||
necessary because the "creation time" of a PNG image is somewhat vague,
|
||||
depending on whether you mean the PNG file, the time the image was
|
||||
created in a non-PNG format, a still photo from which the image was
|
||||
scanned, or possibly the subject matter itself. In order to facilitate
|
||||
machine-readable dates, it is recommended that the "Creation Time"
|
||||
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_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().
|
||||
|
||||
@@ -1133,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
|
||||
@@ -1204,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);
|
||||
|
||||
@@ -1219,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);
|
||||
|
||||
@@ -1255,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
|
||||
@@ -1307,8 +1426,8 @@ default function will be used, calling fprintf() and/or longjmp() if a
|
||||
problem is encountered. The replacement error functions should have
|
||||
parameters as follows:
|
||||
|
||||
void user_error_fn(png_struct png_ptr, png_const_charp error_msg);
|
||||
void user_warning_fn(png_struct png_ptr, png_const_charp warning_msg);
|
||||
void user_error_fn(png_structp png_ptr, png_const_charp error_msg);
|
||||
void user_warning_fn(png_structp png_ptr, png_const_charp warning_msg);
|
||||
|
||||
The motivation behind using setjmp() and longjmp() is the C++ throw and
|
||||
catch exception handling methods. This makes the code much easier to write,
|
||||
@@ -1353,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
|
||||
@@ -1385,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
|
||||
@@ -1412,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
|
||||
@@ -1470,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
|
||||
@@ -1489,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
|
||||
|
||||
68
makefile.dec
Normal file
68
makefile.dec
Normal file
@@ -0,0 +1,68 @@
|
||||
# makefile for libpng on DEC Alpha Unix
|
||||
# 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=-std -w1 -I$(ZLIBINC) -O # -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
|
||||
|
||||
67
makefile.elf
67
makefile.elf
@@ -1,5 +1,6 @@
|
||||
# makefile for libpng on (linux) ELF
|
||||
# makefile for libpng on Linux ELF with gcc
|
||||
# Copyright (C) 1996, 1997 Andreas Dilger
|
||||
# Copyright (C) 1998 Greg Roelofs
|
||||
# For conditions of distribution and use, see copyright notice in png.h
|
||||
|
||||
CC=gcc
|
||||
@@ -13,14 +14,15 @@ ZLIBINC=../zlib
|
||||
WARNMORE=-Wwrite-strings -Wpointer-arith -Wshadow \
|
||||
-Wmissing-declarations -Wtraditional -Wcast-align \
|
||||
-Wstrict-prototypes -Wmissing-prototypes #-Wconversion
|
||||
CFLAGS=-I$(ZLIBINC) -Wall -O2 -fPIC # $(WARNMORE) # -g -DPNG_DEBUG=3
|
||||
CFLAGS=-I$(ZLIBINC) -Wall -O3 -funroll-loops -malign-loops=2 \
|
||||
-malign-functions=2 #$(WARNMORE) -g -DPNG_DEBUG=5
|
||||
LDFLAGS=-L. -Wl,-rpath,. -L$(ZLIBLIB) -Wl,-rpath,$(ZLIBLIB) -lpng -lz -lm
|
||||
|
||||
RANLIB=ranlib
|
||||
#RANLIB=echo
|
||||
|
||||
PNGMAJ = 0
|
||||
PNGMIN = 96
|
||||
PNGMAJ = 2
|
||||
PNGMIN = 0.99
|
||||
PNGVER = $(PNGMAJ).$(PNGMIN)
|
||||
|
||||
# where make install puts libpng.a, libpng.so*, and png.h
|
||||
@@ -32,10 +34,17 @@ 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.so pngtest
|
||||
OBJSDLL = $(OBJS:.o=.pic.o)
|
||||
|
||||
.SUFFIXES: .c .o .pic.o
|
||||
|
||||
.c.pic.o:
|
||||
$(CC) -c $(CFLAGS) -fPIC -o $@ $*.c
|
||||
|
||||
all: libpng.a libpng.so pngtest
|
||||
|
||||
libpng.a: $(OBJS)
|
||||
ar rc $@ $(OBJS)
|
||||
ar rc $@ $(OBJS)
|
||||
$(RANLIB) $@
|
||||
|
||||
libpng.so: libpng.so.$(PNGMAJ)
|
||||
@@ -44,43 +53,45 @@ libpng.so: libpng.so.$(PNGMAJ)
|
||||
libpng.so.$(PNGMAJ): libpng.so.$(PNGVER)
|
||||
ln -sf libpng.so.$(PNGVER) libpng.so.$(PNGMAJ)
|
||||
|
||||
libpng.so.$(PNGVER): $(OBJS)
|
||||
gcc -shared -Wl,-soname,libpng.so.$(PNGMAJ) -o libpng.so.$(PNGVER) $(OBJS)
|
||||
libpng.so.$(PNGVER): $(OBJSDLL)
|
||||
gcc -shared -Wl,-soname,libpng.so.$(PNGMAJ) -o libpng.so.$(PNGVER) \
|
||||
$(OBJSDLL)
|
||||
|
||||
pngtest: pngtest.o libpng.so
|
||||
$(CC) -o pngtest pngtest.o $(LDFLAGS)
|
||||
$(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS)
|
||||
|
||||
test: pngtest
|
||||
./pngtest
|
||||
|
||||
install: libpng.so.$(PNGVER)
|
||||
install: libpng.a libpng.so.$(PNGVER)
|
||||
-@mkdir $(INCPATH) $(LIBPATH)
|
||||
cp png.h pngconf.h $(INCPATH)
|
||||
chmod 644 $(INCPATH)/png.h $(INCPATH)/pngconf.h
|
||||
cp libpng.so.$(PNGVER) $(LIBPATH)
|
||||
cp libpng.a libpng.so.$(PNGVER) $(LIBPATH)
|
||||
chmod 755 $(LIBPATH)/libpng.so.$(PNGVER)
|
||||
-@/bin/rm $(LIBPATH)/libpng.so.$(PNGMAJ) $(LIBPATH)/libpng.so
|
||||
-@/bin/rm -f $(LIBPATH)/libpng.so.$(PNGMAJ) $(LIBPATH)/libpng.so
|
||||
(cd $(LIBPATH); ln -sf libpng.so.$(PNGVER) libpng.so.$(PNGMAJ); \
|
||||
ln -sf libpng.so.$(PNGMAJ) libpng.so)
|
||||
|
||||
clean:
|
||||
rm -f *.o libpng.a libpng.so* pngtest pngout.png
|
||||
/bin/rm -f *.o libpng.a libpng.so* 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
|
||||
png.o png.pic.o: png.h pngconf.h
|
||||
pngerror.o pngerror.pic.o: png.h pngconf.h
|
||||
pngrio.o pngrio.pic.o: png.h pngconf.h
|
||||
pngwio.o pngwio.pic.o: png.h pngconf.h
|
||||
pngmem.o pngmem.pic.o: png.h pngconf.h
|
||||
pngset.o pngset.pic.o: png.h pngconf.h
|
||||
pngget.o pngget.pic.o: png.h pngconf.h
|
||||
pngread.o pngread.pic.o: png.h pngconf.h
|
||||
pngrtran.o pngrtran.pic.o: png.h pngconf.h
|
||||
pngrutil.o pngrutil.pic.o: png.h pngconf.h
|
||||
pngtrans.o pngtrans.pic.o: png.h pngconf.h
|
||||
pngwrite.o pngwrite.pic.o: png.h pngconf.h
|
||||
pngwtran.o pngwtran.pic.o: png.h pngconf.h
|
||||
pngwutil.o pngwutil.pic.o: png.h pngconf.h
|
||||
pngpread.o pngpread.pic.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
|
||||
|
||||
80
makefile.min
Normal file
80
makefile.min
Normal 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
|
||||
|
||||
@@ -9,11 +9,12 @@ ZLIBLIB=../zlib
|
||||
ZLIBINC=../zlib
|
||||
|
||||
CC=cc
|
||||
CFLAGS=-I$(ZLIBINC) -O # -g -DPNG_DEBUG=1
|
||||
|
||||
CFLAGS=-I$(ZLIBINC) -O -fullwarn # -g -DPNG_DEBUG=1
|
||||
LDFLAGS=-L. -L$(ZLIBLIB) -lpng -lz -lm
|
||||
|
||||
#RANLIB=echo
|
||||
RANLIB=ranlib
|
||||
RANLIB=echo
|
||||
#RANLIB=ranlib
|
||||
|
||||
# where make install puts libpng.a and png.h
|
||||
prefix=/usr/local
|
||||
@@ -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
|
||||
173
png.c
173
png.c
@@ -1,27 +1,30 @@
|
||||
|
||||
/* png.c - location for general purpose png functions
|
||||
|
||||
libpng 1.0 beta 6 - version 0.96
|
||||
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
|
||||
May 12, 1997
|
||||
*/
|
||||
/* png.c - location for general purpose libpng functions
|
||||
*
|
||||
* libpng 0.99a
|
||||
* 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 31, 1998
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
#define PNG_NO_EXTERN
|
||||
#include "png.h"
|
||||
|
||||
/* Version information for C files. This had better match the version
|
||||
string defined in png.h */
|
||||
char png_libpng_ver[] = "0.95";
|
||||
* string defined in png.h.
|
||||
*/
|
||||
char png_libpng_ver[6] = "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,
|
||||
add a string holding the name here. If you want to make the code
|
||||
portable to EBCDIC machines, use ASCII numbers, not characters. */
|
||||
/* Constant strings for known chunk types. If you need to add a chunk,
|
||||
* add a string holding the name here. If you want to make the code
|
||||
* portable to EBCDIC machines, use ASCII numbers, not characters.
|
||||
*/
|
||||
png_byte FARDATA png_IHDR[5] = { 73, 72, 68, 82, '\0'};
|
||||
png_byte FARDATA png_IDAT[5] = { 73, 68, 65, 84, '\0'};
|
||||
png_byte FARDATA png_IEND[5] = { 73, 69, 78, 68, '\0'};
|
||||
@@ -34,6 +37,7 @@ png_byte FARDATA png_oFFs[5] = {111, 70, 70, 115, '\0'};
|
||||
png_byte FARDATA png_pCAL[5] = {112, 67, 65, 76, '\0'};
|
||||
png_byte FARDATA png_pHYs[5] = {112, 72, 89, 115, '\0'};
|
||||
png_byte FARDATA png_sBIT[5] = {115, 66, 73, 84, '\0'};
|
||||
png_byte FARDATA png_sRGB[5] = {115, 82, 71, 66, '\0'};
|
||||
png_byte FARDATA png_tEXt[5] = {116, 69, 88, 116, '\0'};
|
||||
png_byte FARDATA png_tIME[5] = {116, 73, 77, 69, '\0'};
|
||||
png_byte FARDATA png_tRNS[5] = {116, 82, 78, 83, '\0'};
|
||||
@@ -53,22 +57,20 @@ int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
|
||||
/* offset to next interlace block in the y direction */
|
||||
int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
|
||||
|
||||
/* width of interlace block */
|
||||
/* this is not currently used - if you need it, uncomment it here and
|
||||
in png.h
|
||||
/* Width of interlace block. This is not currently used - if you need
|
||||
* it, uncomment it here and in png.h
|
||||
int FARDATA png_pass_width[] = {8, 4, 4, 2, 2, 1, 1};
|
||||
*/
|
||||
|
||||
/* height of interlace block */
|
||||
/* this is not currently used - if you need it, uncomment it here and
|
||||
in png.h
|
||||
/* Height of interlace block. This is not currently used - if you need
|
||||
* it, uncomment it here and in png.h
|
||||
int FARDATA png_pass_height[] = {8, 8, 4, 4, 2, 2, 1};
|
||||
*/
|
||||
|
||||
/* mask to determine which pixels are valid in a pass */
|
||||
/* Mask to determine which pixels are valid in a pass */
|
||||
int FARDATA png_pass_mask[] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
|
||||
|
||||
/* mask to determine which pixels to overwrite while displaying */
|
||||
/* Mask to determine which pixels to overwrite while displaying */
|
||||
int FARDATA png_pass_dsp_mask[] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
|
||||
|
||||
|
||||
@@ -101,24 +103,25 @@ 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
|
||||
to check a partial signature. This function will be removed in the
|
||||
future - use png_sig_cmp(). */
|
||||
* to check a partial signature. This function will be removed in the
|
||||
* future - use png_sig_cmp().
|
||||
*/
|
||||
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. */
|
||||
@@ -129,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);
|
||||
@@ -140,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 */
|
||||
@@ -151,78 +154,19 @@ png_zfree(voidpf png_ptr, voidpf ptr)
|
||||
}
|
||||
|
||||
/* Reset the CRC variable to 32 bits of 1's. Care must be taken
|
||||
in case CRC is > 32 bits to leave the top bits 0. */
|
||||
* in case CRC is > 32 bits to leave the top bits 0.
|
||||
*/
|
||||
void
|
||||
png_reset_crc(png_structp png_ptr)
|
||||
{
|
||||
/* set CRC to all 1's */
|
||||
#ifdef PNG_USE_OWN_CRC
|
||||
png_ptr->crc = 0xffffffffL;
|
||||
#else
|
||||
png_ptr->crc = crc32(0, Z_NULL, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef PNG_USE_OWN_CRC
|
||||
/* Table of CRCs of all 8-bit messages. By default, we use the tables made
|
||||
by zlib, to save some memory. If you wish to png_malloc() this
|
||||
table, turn this into a pointer, and png_malloc() it in make_crc_table().
|
||||
You may then want to hook it into png_struct and free it with the
|
||||
destroy functions. Another alternative is to pre-fill the table. */
|
||||
static png_uint_32 crc_table[256];
|
||||
|
||||
/* Flag: has the table been computed? Initially false. */
|
||||
static int crc_table_computed = 0;
|
||||
|
||||
/* make the table for a fast crc */
|
||||
static void
|
||||
make_crc_table(void)
|
||||
{
|
||||
png_uint_32 c;
|
||||
int n, k;
|
||||
|
||||
for (n = 0; n < 256; n++)
|
||||
{
|
||||
c = (png_uint_32)n;
|
||||
for (k = 0; k < 8; k++)
|
||||
c = c & 1 ? 0xedb88320L ^ (c >> 1) : c >> 1;
|
||||
crc_table[n] = c;
|
||||
}
|
||||
crc_table_computed = 1;
|
||||
}
|
||||
|
||||
/* Update a running CRC with the bytes buf[0..len-1] - the CRC should be
|
||||
initialized to all 1's, and the transmitted value is the 1's complement
|
||||
of the final running CRC. */
|
||||
static png_uint_32
|
||||
update_crc(png_uint_32 crc, png_bytep buf, png_size_t len)
|
||||
{
|
||||
png_uint_32 c;
|
||||
png_bytep p;
|
||||
png_uint_32 n;
|
||||
|
||||
c = crc;
|
||||
p = buf;
|
||||
n = len;
|
||||
|
||||
if (!crc_table_computed)
|
||||
{
|
||||
make_crc_table();
|
||||
}
|
||||
|
||||
if (n > 0) do
|
||||
{
|
||||
c = crc_table[(png_byte)((c ^ (*p++)) & 0xff)] ^ (c >> 8);
|
||||
} while (--n);
|
||||
|
||||
return c;
|
||||
}
|
||||
#endif /* PNG_USE_OWN_CRC */
|
||||
|
||||
/* Calculate the CRC over a section of data. We can only pass as
|
||||
much data to this routine as the largest single buffer size. We
|
||||
also check that this data will actually be used before going to the
|
||||
trouble of calculating it. */
|
||||
* much data to this routine as the largest single buffer size. We
|
||||
* also check that this data will actually be used before going to the
|
||||
* trouble of calculating it.
|
||||
*/
|
||||
void
|
||||
png_calculate_crc(png_structp png_ptr, png_bytep ptr, png_size_t length)
|
||||
{
|
||||
@@ -241,18 +185,15 @@ png_calculate_crc(png_structp png_ptr, png_bytep ptr, png_size_t length)
|
||||
}
|
||||
|
||||
if (need_crc)
|
||||
#ifdef PNG_USE_OWN_CRC
|
||||
png_ptr->crc = update_crc(png_ptr->crc, ptr, length);
|
||||
#else
|
||||
png_ptr->crc = crc32(png_ptr->crc, ptr, length);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Allocate the memory for an info_struct for the application. We don't
|
||||
really need the png_ptr, but it could potentially be useful in the
|
||||
future. This should be used in favour of malloc(sizeof(png_info))
|
||||
and png_info_init() so that applications that want to use a shared
|
||||
libpng don't have to be recompiled if png_info changes size. */
|
||||
* really need the png_ptr, but it could potentially be useful in the
|
||||
* future. This should be used in favour of malloc(sizeof(png_info))
|
||||
* and png_info_init() so that applications that want to use a shared
|
||||
* libpng don't have to be recompiled if png_info changes size.
|
||||
*/
|
||||
png_infop
|
||||
png_create_info_struct(png_structp png_ptr)
|
||||
{
|
||||
@@ -264,13 +205,14 @@ 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.
|
||||
Normally, one would use either png_destroy_read_struct() or
|
||||
png_destroy_write_struct() to free an info struct, but this may be
|
||||
useful for some applications. */
|
||||
* Normally, one would use either png_destroy_read_struct() or
|
||||
* png_destroy_write_struct() to free an info struct, but this may be
|
||||
* useful for some applications.
|
||||
*/
|
||||
void
|
||||
png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr)
|
||||
{
|
||||
@@ -290,8 +232,9 @@ png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr)
|
||||
}
|
||||
|
||||
/* Initialize the info structure. This is now an internal function (0.89)
|
||||
and applications using it are urged to use png_create_info_struct()
|
||||
instead. */
|
||||
* and applications using it are urged to use png_create_info_struct()
|
||||
* instead.
|
||||
*/
|
||||
void
|
||||
png_info_init(png_infop info_ptr)
|
||||
{
|
||||
@@ -337,18 +280,20 @@ png_info_destroy(png_structp png_ptr, png_infop info_ptr)
|
||||
}
|
||||
|
||||
/* This function returns a pointer to the io_ptr associated with the user
|
||||
functions. The application should free any memory associated with this
|
||||
pointer before png_write_destroy() or png_read_destroy() are called. */
|
||||
* functions. The application should free any memory associated with this
|
||||
* pointer before png_write_destroy() or png_read_destroy() are called.
|
||||
*/
|
||||
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)
|
||||
/* Initialize the default input/output functions for the PNG file. If you
|
||||
use your own read or write routines, you can call either png_set_read_fn()
|
||||
or png_set_write_fn() instead of png_init_io(). */
|
||||
* use your own read or write routines, you can call either png_set_read_fn()
|
||||
* or png_set_write_fn() instead of png_init_io().
|
||||
*/
|
||||
void
|
||||
png_init_io(png_structp png_ptr, FILE *fp)
|
||||
{
|
||||
|
||||
445
png.h
445
png.h
@@ -1,67 +1,98 @@
|
||||
|
||||
/* png.h - header file for PNG reference library
|
||||
|
||||
libpng 1.0 beta 6 - version 0.96
|
||||
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
|
||||
May 12, 1997
|
||||
|
||||
BETA NOTICE:
|
||||
This is a beta version. It reads and writes valid files on the
|
||||
platforms I have, and has had a wide testing program. You may
|
||||
have to modify the includes below to get it to work on your
|
||||
system, and you may have to supply the correct compiler flags in
|
||||
the makefile if you can't find a makefile suitable for your
|
||||
operating system/compiler combination. Read libpng.txt for more
|
||||
information, including how to contact the authors if you have any
|
||||
problems, or if you want your compiler/platform to be supported in
|
||||
the next official libpng release.
|
||||
|
||||
See libpng.txt for more information.
|
||||
|
||||
Contributing Authors:
|
||||
John Bowler
|
||||
Sam Bushell
|
||||
Kevin Bracey
|
||||
Andreas Dilger
|
||||
Magnus Holmgren
|
||||
Dave Martindale
|
||||
Greg Roelofs
|
||||
Guy Eric Schalnat
|
||||
Paul Schmidt
|
||||
Tom Tanner
|
||||
Tim Wegner
|
||||
|
||||
The contributing authors would like to thank all those who helped
|
||||
with testing, bug fixes, and patience. This wouldn't have been
|
||||
possible without all of you.
|
||||
|
||||
Thanks to Frank J. T. Wojcik for helping with the documentation.
|
||||
|
||||
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.
|
||||
|
||||
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:
|
||||
1. The origin of this source code must not be misrepresented.
|
||||
2. Altered versions must be plainly marked as such and must not be
|
||||
misrepresented as being the original source.
|
||||
3. This Copyright notice may not be removed or altered from any source or
|
||||
altered source distribution.
|
||||
|
||||
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.
|
||||
*/
|
||||
*
|
||||
* libpng 0.99a beta
|
||||
* 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 31, 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
|
||||
* 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
|
||||
* platforms I have, and has had a wide testing program. You may
|
||||
* have to modify the includes below to get it to work on your
|
||||
* system, and you may have to supply the correct compiler flags in
|
||||
* the makefile if you can't find a makefile suitable for your
|
||||
* operating system/compiler combination. Read libpng.txt for more
|
||||
* information, including how to contact the authors if you have any
|
||||
* problems, or if you want your compiler/platform to be supported in
|
||||
* the next official libpng release.
|
||||
*
|
||||
* 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>
|
||||
*
|
||||
* Contributing Authors:
|
||||
* John Bowler
|
||||
* Sam Bushell
|
||||
* Kevin Bracey
|
||||
* Andreas Dilger
|
||||
* Magnus Holmgren
|
||||
* Tom Lane
|
||||
* Dave Martindale
|
||||
* Glenn Randers-Pehrson
|
||||
* Greg Roelofs
|
||||
* Guy Eric Schalnat
|
||||
* Paul Schmidt
|
||||
* Tom Tanner
|
||||
* Tim Wegner
|
||||
*
|
||||
* The contributing authors would like to thank all those who helped
|
||||
* with testing, bug fixes, and patience. This wouldn't have been
|
||||
* possible without all of you.
|
||||
*
|
||||
* Thanks to Frank J. T. Wojcik for helping with the documentation.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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:
|
||||
* 1. The origin of this source code must not be misrepresented.
|
||||
* 2. Altered versions must be plainly marked as such and must not be
|
||||
* misrepresented as being the original source.
|
||||
* 3. This Copyright notice may not be removed or altered from any source or
|
||||
* altered source distribution.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef _PNG_H
|
||||
#define _PNG_H
|
||||
@@ -89,30 +120,30 @@ extern "C" {
|
||||
*/
|
||||
|
||||
/* Version information for png.h - this should match the version in png.c */
|
||||
#define PNG_LIBPNG_VER_STRING "0.96"
|
||||
#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 96
|
||||
#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];
|
||||
|
||||
/* 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 */
|
||||
|
||||
@@ -172,10 +203,11 @@ typedef png_text FAR * FAR * png_textpp;
|
||||
#define PNG_TEXT_COMPRESSION_LAST 1 /* Not a valid value */
|
||||
|
||||
/* png_time is a way to hold the time in an machine independent way.
|
||||
Two conversions are provided, both from time_t and struct tm. There
|
||||
is no portable way to convert to either of these structures, as far
|
||||
as I know. If you know of a portable way, send it to me. As a side
|
||||
note - PNG is Year 2000 compliant! */
|
||||
* Two conversions are provided, both from time_t and struct tm. There
|
||||
* is no portable way to convert to either of these structures, as far
|
||||
* as I know. If you know of a portable way, send it to me. As a side
|
||||
* note - PNG is Year 2000 compliant!
|
||||
*/
|
||||
typedef struct png_time_struct
|
||||
{
|
||||
png_uint_16 year; /* full year, as in, 1995 */
|
||||
@@ -237,13 +269,21 @@ 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.
|
||||
*/
|
||||
float gamma; /* gamma value of image, if (valid & PNG_INFO_gAMA) */
|
||||
#endif /* PNG_READ_gAMA_SUPPORTED || PNG_WRITE_gAMA_SUPPORTED */
|
||||
|
||||
#if defined(PNG_READ_sRGB_SUPPORTED) || defined(PNG_WRITE_sRGB_SUPPORTED)
|
||||
/* GR-P, 0.96a */
|
||||
/* Data valid if (valid & PNG_INFO_sRGB) non-zero. */
|
||||
png_byte srgb_intent; /* sRGB rendering intent [0, 1, 2, or 3] */
|
||||
#endif /* PNG_READ_sRGB_SUPPORTED || PNG_WRITE_sRGB_SUPPORTED */
|
||||
|
||||
#if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_WRITE_tEXt_SUPPORTED) || \
|
||||
defined(PNG_READ_zTXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED)
|
||||
/* The tEXt and zTXt chunks contain human-readable textual data in
|
||||
@@ -285,7 +325,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
|
||||
@@ -406,6 +447,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
|
||||
@@ -422,6 +472,7 @@ typedef png_info FAR * FAR * png_infopp;
|
||||
#define PNG_INFO_oFFs 0x0100
|
||||
#define PNG_INFO_tIME 0x0200
|
||||
#define PNG_INFO_pCAL 0x0400
|
||||
#define PNG_INFO_sRGB 0x0800 /* GR-P, 0.96a */
|
||||
|
||||
/* This is used for the transformation routines, as some of them
|
||||
* change these values for the row. It also should enable using
|
||||
@@ -524,7 +575,6 @@ struct png_struct_def
|
||||
png_byte usr_channels; /* channels at start of write */
|
||||
png_byte sig_bytes; /* magic bytes read/written from start of file */
|
||||
|
||||
|
||||
#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
|
||||
png_byte filler; /* filler byte for 24->32-bit pixel expansion */
|
||||
#endif /* PNG_READ_FILLER_SUPPORTED */
|
||||
@@ -542,9 +592,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 */
|
||||
@@ -586,6 +636,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;
|
||||
@@ -593,13 +644,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 */
|
||||
@@ -609,6 +661,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_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;
|
||||
@@ -640,8 +695,8 @@ extern PNG_EXPORT(int,png_check_sig) PNGARG((png_bytep sig, int num));
|
||||
|
||||
/* Allocate and initialize png_ptr struct for reading, and any other memory. */
|
||||
extern PNG_EXPORT(png_structp,png_create_read_struct)
|
||||
PNGARG((png_charp user_png_ver, voidp error_ptr, png_error_ptr error_fn,
|
||||
png_error_ptr warn_fn));
|
||||
PNGARG((png_const_charp user_png_ver, voidp error_ptr,
|
||||
png_error_ptr error_fn, png_error_ptr warn_fn));
|
||||
|
||||
/* Allocate and initialize png_ptr struct for reading, and any other memory */
|
||||
extern PNG_EXPORT(png_structp,png_create_write_struct)
|
||||
@@ -663,6 +718,11 @@ 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_RFC1123_SUPPORTED)
|
||||
extern PNG_EXPORT(png_charp,png_convert_to_rfc1123)
|
||||
PNGARG((png_structp png_ptr, png_timep ptime));
|
||||
#endif /* PNG_TIME_RFC1123_SUPPORTED */
|
||||
|
||||
#if defined(PNG_WRITE_tIME_SUPPORTED)
|
||||
/* convert from a struct tm to png_time */
|
||||
extern PNG_EXPORT(void,png_convert_from_struct_tm) PNGARG((png_timep ptime,
|
||||
@@ -705,6 +765,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,
|
||||
@@ -771,7 +836,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 */
|
||||
@@ -840,6 +905,9 @@ extern void png_read_destroy PNGARG((png_structp png_ptr, png_infop info_ptr,
|
||||
extern PNG_EXPORT(void,png_destroy_write_struct)
|
||||
PNGARG((png_structpp png_ptr_ptr, png_infopp info_ptr_ptr));
|
||||
|
||||
/* free any memory used in info_ptr struct (old method - NOT DLL EXPORTED) */
|
||||
extern void png_write_destroy_info PNGARG((png_infop info_ptr));
|
||||
|
||||
/* free any memory used in png_ptr struct (old method - NOT DLL EXPORTED) */
|
||||
extern void png_write_destroy PNGARG((png_structp png_ptr));
|
||||
|
||||
@@ -868,10 +936,12 @@ extern PNG_EXPORT(void,png_set_crc_action) PNGARG((png_structp png_ptr,
|
||||
* mainly useful for testing, as the defaults should work with most users.
|
||||
* Those users who are tight on memory or want faster performance at the
|
||||
* expense of compression can modify them. See the compression library
|
||||
* header file (zlib.h) for an explination of the compression functions. */
|
||||
* header file (zlib.h) for an explination of the compression functions.
|
||||
*/
|
||||
|
||||
/* set the filtering method(s) used by libpng. Currently, the only valid
|
||||
* value for "method" is 0 */
|
||||
* value for "method" is 0.
|
||||
*/
|
||||
extern PNG_EXPORT(void,png_set_filter) PNGARG((png_structp png_ptr, int method,
|
||||
int filters));
|
||||
|
||||
@@ -972,8 +1042,10 @@ extern PNG_EXPORT(void,png_set_compression_method) PNGARG((png_structp png_ptr,
|
||||
* more information.
|
||||
*/
|
||||
|
||||
#if !defined(PNG_NO_STDIO)
|
||||
/* Initialize the input/output for the PNG file to the default functions. */
|
||||
extern PNG_EXPORT(void,png_init_io) PNGARG((png_structp png_ptr, FILE *fp));
|
||||
#endif
|
||||
|
||||
/* Replace the (error and abort), and warning functions with user
|
||||
* supplied functions. If no messages are to be printed you must still
|
||||
@@ -1030,9 +1102,16 @@ extern PNG_EXPORT(void,png_progressive_combine_row) PNGARG((png_structp png_ptr,
|
||||
extern PNG_EXPORT(png_voidp,png_malloc) PNGARG((png_structp png_ptr,
|
||||
png_uint_32 size));
|
||||
|
||||
/* free's a pointer allocated by png_malloc() */
|
||||
/* frees a pointer allocated by png_malloc() */
|
||||
extern PNG_EXPORT(void,png_free) PNGARG((png_structp png_ptr, png_voidp ptr));
|
||||
|
||||
#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 */
|
||||
@@ -1041,10 +1120,18 @@ extern void *far_to_near PNGARG((png_structp png_ptr,png_voidp ptr,int check));
|
||||
extern PNG_EXPORT(void,png_error) PNGARG((png_structp png_ptr,
|
||||
png_const_charp error));
|
||||
|
||||
/* The same, but the chunk name is prepended to the error string. */
|
||||
extern PNG_EXPORT(void,png_chunk_error) PNGARG((png_structp png_ptr,
|
||||
png_const_charp error));
|
||||
|
||||
/* Non-fatal error in libpng. Can continue, but may have a problem. */
|
||||
extern PNG_EXPORT(void,png_warning) PNGARG((png_structp png_ptr,
|
||||
png_const_charp message));
|
||||
|
||||
/* Non-fatal error in libpng, chunk name is prepended to message. */
|
||||
extern PNG_EXPORT(void,png_chunk_warning) PNGARG((png_structp png_ptr,
|
||||
png_const_charp message));
|
||||
|
||||
/* The png_set_<chunk> functions are for storing values in the png_info_struct.
|
||||
* Similarly, the png_get_<chunk> calls are used to read values from the
|
||||
* png_info_struct, either storing the parameters in the passed variables, or
|
||||
@@ -1057,18 +1144,67 @@ extern PNG_EXPORT(void,png_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));
|
||||
@@ -1175,6 +1311,18 @@ extern PNG_EXPORT(void,png_set_sBIT) PNGARG((png_structp png_ptr,
|
||||
png_infop info_ptr, png_color_8p sig_bit));
|
||||
#endif /* PNG_READ_sBIT_SUPPORTED || PNG_WRITE_sBIT_SUPPORTED */
|
||||
|
||||
#if defined(PNG_READ_sRGB_SUPPORTED)
|
||||
extern PNG_EXPORT(png_uint_32,png_get_sRGB) PNGARG((png_structp png_ptr,
|
||||
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, int intent));
|
||||
extern PNG_EXPORT(void,png_set_sRGB_gAMA_and_cHRM) PNGARG((png_structp png_ptr,
|
||||
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)
|
||||
/* png_get_text also returns the number of text chunks in text_ptr */
|
||||
extern PNG_EXPORT(png_uint_32,png_get_text) PNGARG((png_structp png_ptr,
|
||||
@@ -1216,6 +1364,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 */
|
||||
@@ -1244,13 +1395,17 @@ extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr,
|
||||
#if defined(PNG_INTERNAL)
|
||||
|
||||
/* Various modes of operation. Note that after an init, mode is set to
|
||||
zero automatically when the structure is created. */
|
||||
* zero automatically when the structure is created.
|
||||
*/
|
||||
#define PNG_BEFORE_IHDR 0x00
|
||||
#define PNG_HAVE_IHDR 0x01
|
||||
#define PNG_HAVE_PLTE 0x02
|
||||
#define PNG_HAVE_IDAT 0x04
|
||||
#define PNG_AFTER_IDAT 0x08
|
||||
#define PNG_HAVE_IEND 0x10
|
||||
#define PNG_HAVE_gAMA 0x20
|
||||
#define PNG_HAVE_cHRM 0x40
|
||||
#define PNG_HAVE_sRGB 0x80
|
||||
|
||||
/* push model modes */
|
||||
#define PNG_READ_SIG_MODE 0
|
||||
@@ -1282,6 +1437,7 @@ extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr,
|
||||
#define PNG_PACKSWAP 0x10000
|
||||
#define PNG_SWAP_ALPHA 0x20000
|
||||
#define PNG_STRIP_ALPHA 0x40000
|
||||
#define PNG_INVERT_ALPHA 0x80000
|
||||
|
||||
/* flags for png_create_struct */
|
||||
#define PNG_STRUCT_PNG 0x0001
|
||||
@@ -1328,29 +1484,31 @@ extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr,
|
||||
|
||||
/* 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[];
|
||||
/* 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_tEXt[];
|
||||
extern png_byte FARDATA png_tIME[];
|
||||
extern png_byte FARDATA png_tRNS[];
|
||||
extern png_byte FARDATA png_zTXt[];
|
||||
/* 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[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 */
|
||||
|
||||
@@ -1376,12 +1534,14 @@ PNG_EXTERN png_uint_32 png_get_uint_32 PNGARG((png_bytep buf));
|
||||
PNG_EXTERN png_uint_16 png_get_uint_16 PNGARG((png_bytep buf));
|
||||
#endif /* PNG_BIG_ENDIAN_GET_SUPPORTED */
|
||||
|
||||
/* Initialize png_ptr struct for reading, and allocate any other memory
|
||||
* (old interface - NOT DLL EXPORTED) */
|
||||
/* Initialize png_ptr struct for reading, and allocate any other memory.
|
||||
* (old interface - NOT DLL EXPORTED).
|
||||
*/
|
||||
extern void png_read_init PNGARG((png_structp png_ptr));
|
||||
|
||||
/* Initialize png_ptr struct for writing, and allocate any other memory
|
||||
* (old interface - NOT DLL EXPORTED) */
|
||||
/* Initialize png_ptr struct for writing, and allocate any other memory.
|
||||
* (old interface - NOT DLL EXPORTED).
|
||||
*/
|
||||
extern void png_write_init PNGARG((png_structp png_ptr));
|
||||
|
||||
/* allocate memory for an internal libpng struct */
|
||||
@@ -1433,7 +1593,7 @@ PNG_EXTERN void png_flush PNGARG((png_structp png_ptr));
|
||||
#endif
|
||||
|
||||
/* Place a 32-bit number into a buffer in PNG byte order (big-endian).
|
||||
* The only currently known PNG chunk that uses unsigned numbers is
|
||||
* The only currently known PNG chunk that uses signed numbers is
|
||||
* the ancillary extension chunk, pCAL.
|
||||
*/
|
||||
PNG_EXTERN void png_save_uint_32 PNGARG((png_bytep buf, png_uint_32 i));
|
||||
@@ -1442,8 +1602,11 @@ PNG_EXTERN void png_save_uint_32 PNGARG((png_bytep buf, png_uint_32 i));
|
||||
PNG_EXTERN void png_save_int_32 PNGARG((png_bytep buf, png_int_32 i));
|
||||
#endif
|
||||
|
||||
/* place a 16 bit number into a buffer in PNG byte order */
|
||||
PNG_EXTERN void png_save_uint_16 PNGARG((png_bytep buf, png_uint_16 i));
|
||||
/* Place a 16 bit number into a buffer in PNG byte order.
|
||||
* The parameter is declared unsigned int, not png_uint_16,
|
||||
* just to avoid potential problems on pre-ANSI C compilers.
|
||||
*/
|
||||
PNG_EXTERN void png_save_uint_16 PNGARG((png_bytep buf, unsigned int i));
|
||||
|
||||
/* Write a PNG chunk - size, type, (optional) data, CRC. */
|
||||
PNG_EXTERN void png_write_chunk PNGARG((png_structp png_ptr,
|
||||
@@ -1460,13 +1623,14 @@ 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 */
|
||||
|
||||
/* Write the IHDR chunk, and update the png_struct with the necessary
|
||||
information. */
|
||||
* information.
|
||||
*/
|
||||
PNG_EXTERN void png_write_IHDR PNGARG((png_structp png_ptr, png_uint_32 width,
|
||||
png_uint_32 height,
|
||||
int bit_depth, int color_type, int compression_type, int filter_type,
|
||||
@@ -1496,6 +1660,11 @@ PNG_EXTERN void png_write_cHRM PNGARG((png_structp png_ptr,
|
||||
double blue_x, double blue_y));
|
||||
#endif
|
||||
|
||||
#if defined(PNG_WRITE_sRGB_SUPPORTED)
|
||||
PNG_EXTERN void png_write_sRGB PNGARG((png_structp png_ptr,
|
||||
int intent));
|
||||
#endif
|
||||
|
||||
#if defined(PNG_WRITE_tRNS_SUPPORTED)
|
||||
PNG_EXTERN void png_write_tRNS PNGARG((png_structp png_ptr, png_bytep trans,
|
||||
png_color_16p values, int number, int color_type));
|
||||
@@ -1513,7 +1682,7 @@ PNG_EXTERN void png_write_hIST PNGARG((png_structp png_ptr, png_uint_16p hist,
|
||||
|
||||
#if defined(PNG_WRITE_tEXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED)
|
||||
PNG_EXTERN png_size_t png_check_keyword PNGARG((png_structp png_ptr,
|
||||
png_charp key, png_bytepp new_key));
|
||||
png_charp key, png_charpp new_key));
|
||||
#endif
|
||||
|
||||
#if defined(PNG_WRITE_tEXt_SUPPORTED)
|
||||
@@ -1610,6 +1779,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,
|
||||
@@ -1698,7 +1877,8 @@ PNG_EXTERN void png_do_expand PNGARG((png_row_infop row_info,
|
||||
#endif
|
||||
|
||||
/* The following decodes the appropriate chunks, and does error correction,
|
||||
* then calls the appropriate callback for the chunk if it is valid */
|
||||
* then calls the appropriate callback for the chunk if it is valid.
|
||||
*/
|
||||
|
||||
/* decode the IHDR chunk */
|
||||
PNG_EXTERN void png_handle_IHDR PNGARG((png_structp png_ptr, png_infop info_ptr,
|
||||
@@ -1723,6 +1903,11 @@ PNG_EXTERN void png_handle_cHRM PNGARG((png_structp png_ptr, png_infop info_ptr,
|
||||
png_uint_32 length));
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_sRGB_SUPPORTED)
|
||||
PNG_EXTERN void png_handle_sRGB PNGARG((png_structp png_ptr, png_infop info_ptr,
|
||||
png_uint_32 length));
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_tRNS_SUPPORTED)
|
||||
PNG_EXTERN void png_handle_tRNS PNGARG((png_structp png_ptr, png_infop info_ptr,
|
||||
png_uint_32 length));
|
||||
|
||||
312
pngconf.h
312
pngconf.h
@@ -1,66 +1,71 @@
|
||||
|
||||
/* pngconf.c - machine configurable file for libpng
|
||||
|
||||
libpng 1.0 beta 6 - version 0.96
|
||||
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
|
||||
May 12, 1997
|
||||
*/
|
||||
*
|
||||
* libpng 0.99a
|
||||
* 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 31, 1998
|
||||
*/
|
||||
|
||||
/* Any machine specific code is near the front of this file, so if you
|
||||
are configuring libpng for a machine, you may want to read the section
|
||||
starting here down to where it starts to typedef png_color, png_text,
|
||||
and png_info */
|
||||
* are configuring libpng for a machine, you may want to read the section
|
||||
* starting here down to where it starts to typedef png_color, png_text,
|
||||
* and png_info.
|
||||
*/
|
||||
|
||||
#ifndef PNGCONF_H
|
||||
#define PNGCONF_H
|
||||
|
||||
/* This is the size of the compression buffer, and thus the size of
|
||||
an IDAT chunk. Make this whatever size you feel is best for your
|
||||
machine. One of these will be allocated per png_struct. When this
|
||||
is full, it writes the data to the disk, and does some other
|
||||
calculations. Making this an extreamly small size will slow
|
||||
the library down, but you may want to experiment to determine
|
||||
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),
|
||||
it should not make much difference how big this is. */
|
||||
* an IDAT chunk. Make this whatever size you feel is best for your
|
||||
* machine. One of these will be allocated per png_struct. When this
|
||||
* is full, it writes the data to the disk, and does some other
|
||||
* calculations. Making this an extremely small size will slow
|
||||
* the library down, but you may want to experiment to determine
|
||||
* 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 than the size of a row (compressed),
|
||||
* it should not make much difference how big this is.
|
||||
*/
|
||||
|
||||
#ifndef PNG_ZBUF_SIZE
|
||||
#define PNG_ZBUF_SIZE 8192
|
||||
#endif
|
||||
|
||||
/* If you are running on a machine where you cannot allocate more
|
||||
than 64K of memory at once, uncomment this. While libpng will not
|
||||
normally need that much memory in a chunk (unless you load up a very
|
||||
large file), zlib needs to know how big of a chunk it can use, and
|
||||
libpng thus makes sure to check any memory allocation to verify it
|
||||
will fit into memory.
|
||||
* than 64K of memory at once, uncomment this. While libpng will not
|
||||
* normally need that much memory in a chunk (unless you load up a very
|
||||
* large file), zlib needs to know how big of a chunk it can use, and
|
||||
* libpng thus makes sure to check any memory allocation to verify it
|
||||
* will fit into memory.
|
||||
#define PNG_MAX_MALLOC_64K
|
||||
*/
|
||||
*/
|
||||
#if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K)
|
||||
#define PNG_MAX_MALLOC_64K
|
||||
#endif
|
||||
|
||||
/* This protects us against compilers which run on a windowing system
|
||||
and thus don't have or would rather us not use the stdio types:
|
||||
stdin, stdout, and stderr. The only one currently used is stderr
|
||||
in png_error() and png_warning(). #defining PNG_NO_STDIO will
|
||||
prevent these from being compiled and used. */
|
||||
* and thus don't have or would rather us not use the stdio types:
|
||||
* stdin, stdout, and stderr. The only one currently used is stderr
|
||||
* in png_error() and png_warning(). #defining PNG_NO_STDIO will
|
||||
* prevent these from being compiled and used.
|
||||
* #define PNG_NO_STDIO
|
||||
*/
|
||||
|
||||
/* #define PNG_NO_STDIO */
|
||||
|
||||
/* for FILE. If you are not using standard io, you don't need this */
|
||||
#ifndef PNG_NO_STDIO
|
||||
#ifndef PNG_NO_STDIO
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
/* This macro protects us against machines that don't have function
|
||||
prototypes (ie K&R style headers). If your compiler does not handle
|
||||
function prototypes, define this macro and use the included ansi2knr.
|
||||
I've always been able to use _NO_PROTO as the indicator, but you may
|
||||
need to drag the empty declaration out in front of here, or change the
|
||||
ifdef to suit your own needs. */
|
||||
* prototypes (ie K&R style headers). If your compiler does not handle
|
||||
* function prototypes, define this macro and use the included ansi2knr.
|
||||
* I've always been able to use _NO_PROTO as the indicator, but you may
|
||||
* need to drag the empty declaration out in front of here, or change the
|
||||
* ifdef to suit your own needs.
|
||||
*/
|
||||
#ifndef PNGARG
|
||||
|
||||
#ifdef OF /* zlib prototype munger */
|
||||
@@ -77,10 +82,16 @@
|
||||
|
||||
#endif /* PNGARG */
|
||||
|
||||
/* Try to determine if we are compiling on a Mac */
|
||||
#if defined(__MWERKS__) ||defined(applec) ||defined(THINK_C) ||defined(__SC__)
|
||||
/* Try to determine if we are compiling on a Mac. Note that testing for
|
||||
* 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(TARGET_OS_MAC)
|
||||
#define MACOS
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* enough people need this for various reasons to include it here */
|
||||
#if !defined(MACOS) && !defined(RISCOS)
|
||||
@@ -88,27 +99,28 @@
|
||||
#endif
|
||||
|
||||
/* This is an attempt to force a single setjmp behaviour on Linux. If
|
||||
the X config stuff didn't define _BSD_SOURCE we wouldn't need this. */
|
||||
#ifdef linux
|
||||
* the X config stuff didn't define _BSD_SOURCE we wouldn't need this.
|
||||
*/
|
||||
#ifdef __linux__
|
||||
#ifdef _BSD_SOURCE
|
||||
#define _PNG_SAVE_BSD_SOURCE
|
||||
#undef _BSD_SOURCE
|
||||
#endif
|
||||
#ifdef _SETJMP_H
|
||||
#error __png_h_already_includes_setjmp_h__
|
||||
#error __dont_include_it_again__
|
||||
__png.h__ already includes setjmp.h
|
||||
__dont__ include it again
|
||||
#endif
|
||||
#endif /* linux */
|
||||
#endif /* __linux__ */
|
||||
|
||||
/* include setjmp.h for error handling */
|
||||
#include <setjmp.h>
|
||||
|
||||
#ifdef linux
|
||||
#ifdef __linux__
|
||||
#ifdef _PNG_SAVE_BSD_SOURCE
|
||||
#define _BSD_SOURCE
|
||||
#undef _PNG_SAVE_BSD_SOURCE
|
||||
#endif
|
||||
#endif /* linux */
|
||||
#endif /* __linux__ */
|
||||
|
||||
#ifdef BSD
|
||||
#include <strings.h>
|
||||
@@ -119,9 +131,6 @@
|
||||
/* Other defines for things like memory and the like can go here. */
|
||||
#ifdef PNG_INTERNAL
|
||||
#include <stdlib.h>
|
||||
/* Where do we need this???
|
||||
#include <ctype.h>
|
||||
*/
|
||||
|
||||
/* The functions exported by PNG_EXTERN are PNG_INTERNAL functions, which
|
||||
* aren't usually used outside the library (as far as I know), so it is
|
||||
@@ -133,12 +142,14 @@
|
||||
#define PNG_EXTERN
|
||||
|
||||
/* Other defines specific to compilers can go here. Try to keep
|
||||
them inside an appropriate ifdef/endif pair for portability */
|
||||
* them inside an appropriate ifdef/endif pair for portability.
|
||||
*/
|
||||
|
||||
#if defined(MACOS)
|
||||
/* We need to check that <math.h> hasn't already been included earlier
|
||||
as it seems it doesn't agree with <fp.h>, yet we should really use
|
||||
<fp.h> if possible. */
|
||||
* as it seems it doesn't agree with <fp.h>, yet we should really use
|
||||
* <fp.h> if possible.
|
||||
*/
|
||||
#if !defined(__MATH_H__) && !defined(__MATH_H) && !defined(__cmath__)
|
||||
#include <fp.h>
|
||||
#endif
|
||||
@@ -146,9 +157,15 @@
|
||||
#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"? */
|
||||
* stdlib.h like it should (I think). Or perhaps this is a C++
|
||||
* "feature"?
|
||||
*/
|
||||
#ifdef __TURBOC__
|
||||
#include <mem.h>
|
||||
#include "alloc.h"
|
||||
@@ -159,58 +176,81 @@
|
||||
#endif
|
||||
|
||||
/* This controls how fine the dithering gets. As this allocates
|
||||
a largish chunk of memory (32K), those who are not as concerned
|
||||
with dithering quality can decrease some or all of these. */
|
||||
* a largish chunk of memory (32K), those who are not as concerned
|
||||
* with dithering quality can decrease some or all of these.
|
||||
*/
|
||||
#ifndef PNG_DITHER_RED_BITS
|
||||
#define PNG_DITHER_RED_BITS 5
|
||||
#endif
|
||||
#ifndef PNG_DITHER_GREEN_BITS
|
||||
#define PNG_DITHER_GREEN_BITS 5
|
||||
#endif
|
||||
#ifndef PNG_DITHER_BLUE_BITS
|
||||
#define PNG_DITHER_BLUE_BITS 5
|
||||
#endif
|
||||
|
||||
/* This controls how fine the gamma correction becomes when you
|
||||
are only interested in 8 bits anyway. Increasing this value
|
||||
results in more memory being used, and more pow() functions
|
||||
being called to fill in the gamma tables. Don't set this
|
||||
value less then 8, and even that may not work (I haven't tested
|
||||
it). */
|
||||
* are only interested in 8 bits anyway. Increasing this value
|
||||
* results in more memory being used, and more pow() functions
|
||||
* being called to fill in the gamma tables. Don't set this value
|
||||
* 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. */
|
||||
* 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.
|
||||
*/
|
||||
#undef PNG_USE_CONST
|
||||
* and warning message functions, so some compilers won't complain.
|
||||
* If you do not want to use const, define PNG_NO_CONST here.
|
||||
*/
|
||||
|
||||
#ifdef PNG_USE_CONST
|
||||
#ifndef PNG_NO_CONST
|
||||
# define PNG_CONST const
|
||||
#else
|
||||
# define PNG_CONST
|
||||
#endif
|
||||
|
||||
/* The following defines give you the ability to remove code from the
|
||||
library that you will not be using. I wish I could figure out how to
|
||||
automate this, but I can't do that without making it seriously hard
|
||||
on the users. So if you are not using an ability, change the #define
|
||||
to and #undef, and that part of the library will not be compiled. If
|
||||
your linker can't find a function, you may want to make sure the
|
||||
ability is defined here. Some of these depend upon some others being
|
||||
defined. I haven't figured out all the interactions here, so you may
|
||||
have to experiment awhile to get everything to compile. If you are
|
||||
creating or using a shared library, you probably shouldn't touch this,
|
||||
as it will affect the size of the structures, and this will cause bad
|
||||
things to happen if the library and/or application ever change. */
|
||||
* library that you will not be using. I wish I could figure out how to
|
||||
* automate this, but I can't do that without making it seriously hard
|
||||
* on the users. So if you are not using an ability, change the #define
|
||||
* to and #undef, and that part of the library will not be compiled. If
|
||||
* your linker can't find a function, you may want to make sure the
|
||||
* ability is defined here. Some of these depend upon some others being
|
||||
* defined. I haven't figured out all the interactions here, so you may
|
||||
* have to experiment awhile to get everything to compile. If you are
|
||||
* creating or using a shared library, you probably shouldn't touch this,
|
||||
* as it will affect the size of the structures, and this will cause bad
|
||||
* things to happen if the library and/or application ever change.
|
||||
*/
|
||||
|
||||
/* Any transformations you will not be using can be undef'ed here */
|
||||
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
#ifndef PNG_READ_NOT_FULLY_SUPPORTED
|
||||
#define PNG_READ_FULLY_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_WRITE_NOT_FULLY_SUPPORTED
|
||||
#define PNG_WRITE_FULLY_SUPPORTED
|
||||
#endif
|
||||
|
||||
#ifdef PNG_READ_FULLY_SUPPORTED
|
||||
#define PNG_PROGRESSIVE_READ_SUPPORTED
|
||||
#define PNG_READ_OPT_PLTE_SUPPORTED
|
||||
#define PNG_READ_INTERLACING_SUPPORTED
|
||||
#define PNG_READ_EXPAND_SUPPORTED
|
||||
#define PNG_READ_SHIFT_SUPPORTED
|
||||
#define PNG_READ_PACK_SUPPORTED
|
||||
@@ -225,9 +265,14 @@
|
||||
#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_WRITE_INTERLACING_SUPPORTED
|
||||
#define PNG_READ_INTERLACING_SUPPORTED /* required for PNG-compliant decoders */
|
||||
|
||||
#ifdef PNG_WRITE_FULLY_SUPPORTED
|
||||
#define PNG_WRITE_SHIFT_SUPPORTED
|
||||
#define PNG_WRITE_PACK_SUPPORTED
|
||||
#define PNG_WRITE_BGR_SUPPORTED
|
||||
@@ -237,27 +282,71 @@
|
||||
#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 */
|
||||
|
||||
/* These are currently experimental features */
|
||||
#undef PNG_READ_16_TO_8_ACCURATE_SHIFT_SUPPORTED /* very little testing */
|
||||
#undef PNG_READ_COMPOSITE_NODIV_SUPPORTED /* very little testing */
|
||||
#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_RFC1123_SUPPORTED
|
||||
#endif
|
||||
|
||||
/* 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_USE_OWN_CRC
|
||||
#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.
|
||||
*/
|
||||
|
||||
#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
|
||||
@@ -266,11 +355,16 @@
|
||||
#define PNG_READ_pCAL_SUPPORTED
|
||||
#define PNG_READ_pHYs_SUPPORTED
|
||||
#define PNG_READ_sBIT_SUPPORTED
|
||||
#define PNG_READ_sRGB_SUPPORTED
|
||||
#define PNG_READ_tEXt_SUPPORTED
|
||||
#define PNG_READ_tIME_SUPPORTED
|
||||
#define PNG_READ_tRNS_SUPPORTED
|
||||
#define PNG_READ_zTXt_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_ANCILLARY_CHUNKS_SUPPORTED
|
||||
#define PNG_WRITE_bKGD_SUPPORTED
|
||||
#define PNG_WRITE_cHRM_SUPPORTED
|
||||
#define PNG_WRITE_gAMA_SUPPORTED
|
||||
@@ -279,10 +373,12 @@
|
||||
#define PNG_WRITE_pCAL_SUPPORTED
|
||||
#define PNG_WRITE_pHYs_SUPPORTED
|
||||
#define PNG_WRITE_sBIT_SUPPORTED
|
||||
#define PNG_WRITE_sRGB_SUPPORTED
|
||||
#define PNG_WRITE_tEXt_SUPPORTED
|
||||
#define PNG_WRITE_tIME_SUPPORTED
|
||||
#define PNG_WRITE_tRNS_SUPPORTED
|
||||
#define PNG_WRITE_zTXt_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)
|
||||
@@ -336,18 +432,19 @@ typedef size_t png_size_t;
|
||||
#endif /* LDATA != 1 */
|
||||
|
||||
/* Possibly useful for moving data out of default segment.
|
||||
Uncomment it if you want. Could also define FARDATA as
|
||||
const if your compiler supports it. (SJT)
|
||||
* Uncomment it if you want. Could also define FARDATA as
|
||||
* const if your compiler supports it. (SJT)
|
||||
# define FARDATA FAR
|
||||
*/
|
||||
*/
|
||||
#endif /* __WIN32__, __FLAT__ */
|
||||
|
||||
#endif /* __BORLANDC__ */
|
||||
|
||||
|
||||
/* Suggest testing for specific compiler first before testing for
|
||||
FAR. The Watcom compiler defines both __MEDIUM__ and M_I86MM,
|
||||
making reliance oncertain keywords suspect. (SJT) */
|
||||
* FAR. The Watcom compiler defines both __MEDIUM__ and M_I86MM,
|
||||
* making reliance oncertain keywords suspect. (SJT)
|
||||
*/
|
||||
|
||||
/* MSC Medium model */
|
||||
#if defined(FAR)
|
||||
@@ -400,18 +497,29 @@ typedef charf * png_zcharp;
|
||||
typedef charf * FAR * png_zcharpp;
|
||||
typedef z_stream FAR * png_zstreamp;
|
||||
|
||||
/* allow for compilation as dll under windows */
|
||||
/* allow for compilation as dll under MS Windows */
|
||||
#ifdef __WIN32DLL__
|
||||
#define PNG_EXPORT(type,symbol) __declspec(dllexport) type symbol
|
||||
#endif
|
||||
|
||||
/* allow for compilation as dll with BORLAND C++ 5.0 */
|
||||
#if defined(__BORLANDC__) && defined(_Windows) && defined(__DLL__)
|
||||
# define PNG_EXPORT(type,symbol) type _export symbol
|
||||
#endif
|
||||
|
||||
/* allow for compilation as shared lib under BeOS */
|
||||
#ifdef __BEOSDLL__
|
||||
#define PNG_EXPORT(type,symbol) __declspec(export) type symbol
|
||||
#endif
|
||||
|
||||
#ifndef PNG_EXPORT
|
||||
#define PNG_EXPORT(t,s) t s
|
||||
#define PNG_EXPORT(type,symbol) type symbol
|
||||
#endif
|
||||
|
||||
|
||||
/* User may want to use these so not in PNG_INTERNAL. Any library functions
|
||||
that are passed far data must be model independent. */
|
||||
* that are passed far data must be model independent.
|
||||
*/
|
||||
|
||||
#if defined(USE_FAR_KEYWORD) /* memory model independent fns */
|
||||
/* use this to make far-to-near assignments */
|
||||
|
||||
120
pngerror.c
120
pngerror.c
@@ -1,16 +1,18 @@
|
||||
|
||||
/* pngerror.c - stub functions for i/o and memory allocation
|
||||
|
||||
libpng 1.0 beta 6 - version 0.96
|
||||
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
|
||||
May 12, 1997
|
||||
|
||||
This file provides a location for all error handling. Users which
|
||||
need special error handling are expected to write replacement functions
|
||||
and use png_set_error_fn() to use those functions. See the instructions
|
||||
at each function. */
|
||||
*
|
||||
* libpng 0.99a
|
||||
* 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 31, 1998
|
||||
*
|
||||
* This file provides a location for all error handling. Users which
|
||||
* need special error handling are expected to write replacement functions
|
||||
* and use png_set_error_fn() to use those functions. See the instructions
|
||||
* at each function.
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
#include "png.h"
|
||||
@@ -21,9 +23,10 @@ static void png_default_warning PNGARG((png_structp png_ptr,
|
||||
png_const_charp message));
|
||||
|
||||
/* This function is called whenever there is a fatal error. This function
|
||||
should not be changed. If there is a need to handle errors differently,
|
||||
you should supply a replacement error function and use png_set_error_fn()
|
||||
to replace the error function at run-time. */
|
||||
* should not be changed. If there is a need to handle errors differently,
|
||||
* you should supply a replacement error function and use png_set_error_fn()
|
||||
* to replace the error function at run-time.
|
||||
*/
|
||||
void
|
||||
png_error(png_structp png_ptr, png_const_charp message)
|
||||
{
|
||||
@@ -36,9 +39,10 @@ png_error(png_structp png_ptr, png_const_charp message)
|
||||
}
|
||||
|
||||
/* This function is called whenever there is a non-fatal error. This function
|
||||
should not be changed. If there is a need to handle warnings differently,
|
||||
you should supply a replacement warning function and use
|
||||
png_set_error_fn() to replace the warning function at run-time. */
|
||||
* should not be changed. If there is a need to handle warnings differently,
|
||||
* you should supply a replacement warning function and use
|
||||
* png_set_error_fn() to replace the warning function at run-time.
|
||||
*/
|
||||
void
|
||||
png_warning(png_structp png_ptr, png_const_charp message)
|
||||
{
|
||||
@@ -48,10 +52,65 @@ png_warning(png_structp png_ptr, png_const_charp message)
|
||||
png_default_warning(png_ptr, message);
|
||||
}
|
||||
|
||||
/* These utilities are used internally to build an error message which relates
|
||||
* to the current chunk. The chunk name comes from png_ptr->chunk_name,
|
||||
* this is used to prefix the message. The message is limited in length
|
||||
* to 63 bytes, the name characters are output as hex digits wrapped in []
|
||||
* if the character is invalid.
|
||||
*/
|
||||
#define isnonalpha(c) ((c) < 41 || (c) > 122 || ((c) > 90 && (c) < 97))
|
||||
static const char png_digit[16] = {
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
|
||||
};
|
||||
|
||||
static void
|
||||
png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp message)
|
||||
{
|
||||
int iout = 0, iin = 0;
|
||||
|
||||
while (iin < 4) {
|
||||
int c = png_ptr->chunk_name[iin++];
|
||||
if (isnonalpha(c)) {
|
||||
buffer[iout++] = '[';
|
||||
buffer[iout++] = png_digit[(c & 0xf0) >> 4];
|
||||
buffer[iout++] = png_digit[c & 0xf];
|
||||
buffer[iout++] = ']';
|
||||
} else {
|
||||
buffer[iout++] = c;
|
||||
}
|
||||
}
|
||||
|
||||
if (message == NULL)
|
||||
buffer[iout++] = 0;
|
||||
else {
|
||||
buffer[iout++] = ':';
|
||||
buffer[iout++] = ' ';
|
||||
png_memcpy(buffer+iout, message, 64);
|
||||
buffer[iout+63] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
png_chunk_error(png_structp png_ptr, png_const_charp message)
|
||||
{
|
||||
char msg[16+64];
|
||||
png_format_buffer(png_ptr, msg, message);
|
||||
png_error(png_ptr, msg);
|
||||
}
|
||||
|
||||
void
|
||||
png_chunk_warning(png_structp png_ptr, png_const_charp message)
|
||||
{
|
||||
char msg[16+64];
|
||||
png_format_buffer(png_ptr, msg, message);
|
||||
png_warning(png_ptr, msg);
|
||||
}
|
||||
|
||||
/* This is the default error handling function. Note that replacements for
|
||||
this function MUST NOT RETURN, or the program will likely crash. This
|
||||
function is used by default, or if the program supplies NULL for the
|
||||
error function pointer in png_set_error_fn(). */
|
||||
* this function MUST NOT RETURN, or the program will likely crash. This
|
||||
* function is used by default, or if the program supplies NULL for the
|
||||
* error function pointer in png_set_error_fn().
|
||||
*/
|
||||
static void
|
||||
png_default_error(png_structp png_ptr, png_const_charp message)
|
||||
{
|
||||
@@ -71,9 +130,10 @@ png_default_error(png_structp png_ptr, png_const_charp message)
|
||||
}
|
||||
|
||||
/* 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
|
||||
here if you don't want to. In the default configuration, png_ptr is
|
||||
not used, but it is passed in case it may be useful. */
|
||||
* it can continue anyway. Replacement functions don't have to do anything
|
||||
* here if you don't want to. In the default configuration, png_ptr is
|
||||
* not used, but it is passed in case it may be useful.
|
||||
*/
|
||||
static void
|
||||
png_default_warning(png_structp png_ptr, png_const_charp message)
|
||||
{
|
||||
@@ -86,9 +146,10 @@ png_default_warning(png_structp png_ptr, png_const_charp message)
|
||||
}
|
||||
|
||||
/* This function is called when the application wants to use another method
|
||||
of handling errors and warnings. Note that the error function MUST NOT
|
||||
return to the calling routine or serious problems will occur. The return
|
||||
method used in the default routine calls longjmp(png_ptr->jmpbuf, 1) */
|
||||
* of handling errors and warnings. Note that the error function MUST NOT
|
||||
* return to the calling routine or serious problems will occur. The return
|
||||
* method used in the default routine calls longjmp(png_ptr->jmpbuf, 1)
|
||||
*/
|
||||
void
|
||||
png_set_error_fn(png_structp png_ptr, png_voidp error_ptr,
|
||||
png_error_ptr error_fn, png_error_ptr warning_fn)
|
||||
@@ -100,12 +161,13 @@ png_set_error_fn(png_structp png_ptr, png_voidp error_ptr,
|
||||
|
||||
|
||||
/* This function returns a pointer to the error_ptr associated with the user
|
||||
functions. The application should free any memory associated with this
|
||||
pointer before png_write_destroy and png_read_destroy are called. */
|
||||
* functions. The application should free any memory associated with this
|
||||
* pointer before png_write_destroy and png_read_destroy are called.
|
||||
*/
|
||||
png_voidp
|
||||
png_get_error_ptr(png_structp png_ptr)
|
||||
{
|
||||
return png_ptr->error_ptr;
|
||||
return ((png_voidp)png_ptr->error_ptr);
|
||||
}
|
||||
|
||||
|
||||
|
||||
229
pngget.c
229
pngget.c
@@ -1,12 +1,13 @@
|
||||
|
||||
/* pngget.c - retrieval of values from info struct
|
||||
|
||||
libpng 1.0 beta 6 - version 0.96
|
||||
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
|
||||
May 12, 1997
|
||||
*/
|
||||
*
|
||||
* libpng 0.99a
|
||||
* 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 31, 1998
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
#include "png.h"
|
||||
@@ -29,6 +30,179 @@ 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 (0.0);
|
||||
else
|
||||
return ((float)info_ptr->y_pixels_per_unit
|
||||
/(float)info_ptr->x_pixels_per_unit);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
return (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)
|
||||
{
|
||||
@@ -109,6 +283,21 @@ png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_sRGB_SUPPORTED)
|
||||
png_uint_32
|
||||
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 = (int)info_ptr->srgb_intent;
|
||||
return (PNG_INFO_sRGB);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_hIST_SUPPORTED)
|
||||
png_uint_32
|
||||
png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist)
|
||||
@@ -196,14 +385,23 @@ 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)
|
||||
{
|
||||
if (info_ptr != NULL && info_ptr->valid & PNG_INFO_pHYs &&
|
||||
res_x != NULL && res_y != NULL && unit_type != NULL)
|
||||
png_uint_32 retval = 0;
|
||||
|
||||
if (info_ptr != NULL && info_ptr->valid & PNG_INFO_pHYs)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n", "pHYs");
|
||||
*res_x = info_ptr->x_pixels_per_unit;
|
||||
*res_y = info_ptr->y_pixels_per_unit;
|
||||
*unit_type = (int)info_ptr->phys_unit_type;
|
||||
return (PNG_INFO_pHYs);
|
||||
if (res_x != NULL && res_y != NULL)
|
||||
{
|
||||
*res_x = info_ptr->x_pixels_per_unit;
|
||||
*res_y = info_ptr->y_pixels_per_unit;
|
||||
retval |= PNG_INFO_pHYs;
|
||||
}
|
||||
if (unit_type != NULL)
|
||||
{
|
||||
*unit_type = (int)info_ptr->phys_unit_type;
|
||||
retval |= PNG_INFO_pHYs;
|
||||
}
|
||||
return (retval);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
@@ -246,12 +444,13 @@ 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)
|
||||
*num_text = info_ptr->num_text;
|
||||
return (info_ptr->num_text);
|
||||
return ((png_uint_32)info_ptr->num_text);
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
87
pngmem.c
87
pngmem.c
@@ -1,19 +1,30 @@
|
||||
|
||||
/* pngmem.c - stub functions for memory allocation
|
||||
|
||||
libpng 1.0 beta 6 - version 0.96
|
||||
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
|
||||
May 12, 1997
|
||||
|
||||
This file provides a location for all memory allocation. Users which
|
||||
need special memory handling are expected to modify the code in this file
|
||||
to meet their needs. See the instructions at each function. */
|
||||
*
|
||||
* libpng 0.99a
|
||||
* 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 31, 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
|
||||
* to meet their needs. See the instructions at each function.
|
||||
*/
|
||||
|
||||
#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 */
|
||||
@@ -31,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)
|
||||
{
|
||||
@@ -47,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
|
||||
@@ -70,18 +84,18 @@ 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)
|
||||
png_error(png_ptr, "Cannot Allocate > 64K");
|
||||
#endif
|
||||
|
||||
if (size == (png_uint_32)(65536L))
|
||||
if (size == (png_uint_32)65536L)
|
||||
{
|
||||
if (png_ptr->offset_table == NULL)
|
||||
{
|
||||
@@ -96,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)
|
||||
@@ -113,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)
|
||||
@@ -127,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;
|
||||
@@ -139,7 +155,7 @@ png_malloc(png_structp png_ptr, png_uint_32 size)
|
||||
for (i = 0; i < num_blocks; i++)
|
||||
{
|
||||
png_ptr->offset_table_ptr[i] = (png_bytep)hptr;
|
||||
hptr += 65536L;
|
||||
hptr += (png_uint_32)65536L;
|
||||
}
|
||||
|
||||
png_ptr->offset_table_number = num_blocks;
|
||||
@@ -149,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++];
|
||||
}
|
||||
@@ -158,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;
|
||||
@@ -196,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 */
|
||||
@@ -215,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)
|
||||
@@ -239,15 +258,20 @@ void
|
||||
png_destroy_struct(png_voidp struct_ptr)
|
||||
{
|
||||
if (struct_ptr != NULL)
|
||||
{
|
||||
#if defined(__TURBOC__) && !defined(__FLAT__)
|
||||
farfree(struct_ptr);
|
||||
struct_ptr = NULL;
|
||||
#else
|
||||
# if defined(_MSC_VER) && defined(MAXSEG_64K)
|
||||
hfree(struct_ptr);
|
||||
struct_ptr = NULL;
|
||||
# else
|
||||
free(struct_ptr);
|
||||
struct_ptr = NULL;
|
||||
# endif
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -258,11 +282,11 @@ 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;
|
||||
if (png_ptr == NULL || size == 0)
|
||||
return (NULL);
|
||||
return ((png_voidp)NULL);
|
||||
|
||||
#ifdef PNG_MAX_MALLOC_64K
|
||||
if (size > (png_uint_32)65536L)
|
||||
@@ -284,25 +308,28 @@ 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;
|
||||
|
||||
#if defined(__TURBOC__) && !defined(__FLAT__)
|
||||
farfree(ptr);
|
||||
ptr = NULL;
|
||||
#else
|
||||
# if defined(_MSC_VER) && defined(MAXSEG_64K)
|
||||
hfree(ptr);
|
||||
ptr = NULL;
|
||||
# else
|
||||
free(ptr);
|
||||
ptr = NULL;
|
||||
# endif
|
||||
#endif
|
||||
}
|
||||
|
||||
67
pngpread.c
67
pngpread.c
@@ -1,12 +1,13 @@
|
||||
|
||||
/* pngpread.c - read a png file in push mode
|
||||
|
||||
libpng 1.0 beta 6 - version 0.96
|
||||
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
|
||||
May 12, 1997
|
||||
*/
|
||||
*
|
||||
* libpng 0.99a
|
||||
* 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 31, 1998
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
#include "png.h"
|
||||
@@ -116,10 +117,11 @@ void
|
||||
png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
/* First we make sure we have enough data for the 4 byte chunk name
|
||||
and the 4 byte chunk length before proceeding with decoding the
|
||||
chunk data. To fully decode each of these chunks, we also make
|
||||
sure we have enough data in the buffer for the 4 byte CRC at the
|
||||
end of every chunk (except IDAT, which is handled separately). */
|
||||
* and the 4 byte chunk length before proceeding with decoding the
|
||||
* chunk data. To fully decode each of these chunks, we also make
|
||||
* sure we have enough data in the buffer for the 4 byte CRC at the
|
||||
* end of every chunk (except IDAT, which is handled separately).
|
||||
*/
|
||||
if (!(png_ptr->flags & PNG_FLAG_HAVE_CHUNK_HEADER))
|
||||
{
|
||||
png_byte chunk_length[4];
|
||||
@@ -160,8 +162,9 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
|
||||
{
|
||||
/* If we reach an IDAT chunk, this means we have read all of the
|
||||
header chunks, and we can start reading the image (or if this
|
||||
is called after the image has been read - we have an error). */
|
||||
* header chunks, and we can start reading the image (or if this
|
||||
* is called after the image has been read - we have an error).
|
||||
*/
|
||||
if (png_ptr->mode & PNG_HAVE_IDAT)
|
||||
{
|
||||
if (png_ptr->push_length == 0)
|
||||
@@ -227,6 +230,18 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
|
||||
png_handle_cHRM(png_ptr, info_ptr, png_ptr->push_length);
|
||||
}
|
||||
#endif
|
||||
#if defined(PNG_READ_sRGB_SUPPORTED)
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
{
|
||||
png_push_save_buffer(png_ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
png_handle_sRGB(png_ptr, info_ptr, png_ptr->push_length);
|
||||
}
|
||||
#endif
|
||||
#if defined(PNG_READ_tRNS_SUPPORTED)
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
|
||||
{
|
||||
@@ -783,11 +798,11 @@ png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length
|
||||
#ifdef PNG_MAX_MALLOC_64K
|
||||
png_ptr->skip_length = 0; /* This may not be necessary */
|
||||
|
||||
if (length > 65535L) /* We can't hold the entire string in memory */
|
||||
if (length > (png_uint_32)65535L) /* Can't hold the entire string in memory */
|
||||
{
|
||||
png_warning(png_ptr, "tEXt chunk too large to fit in memory");
|
||||
png_ptr->skip_length = length - 65535L;
|
||||
length = 65535L;
|
||||
png_ptr->skip_length = length - (png_uint_32)65535L;
|
||||
length = (png_uint_32)65535L;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -866,7 +881,7 @@ png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length
|
||||
* to be able to store the uncompressed data. Actually, the threshold
|
||||
* is probably around 32K, but it isn't as definite as 64K is.
|
||||
*/
|
||||
if (length > 65535L)
|
||||
if (length > (png_uint_32)65535L)
|
||||
{
|
||||
png_warning(png_ptr, "zTXt chunk too large to fit in memory");
|
||||
png_push_crc_skip(png_ptr, length);
|
||||
@@ -977,7 +992,7 @@ png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
|
||||
png_charp tmp;
|
||||
|
||||
tmp = text;
|
||||
text = png_malloc(png_ptr, text_size +
|
||||
text = (png_charp)png_malloc(png_ptr, text_size +
|
||||
png_ptr->zbuf_size - png_ptr->zstream.avail_out + 1);
|
||||
png_memcpy(text, tmp, text_size);
|
||||
png_free(png_ptr, tmp);
|
||||
@@ -1029,11 +1044,12 @@ png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
|
||||
#endif
|
||||
|
||||
/* This function is called when we haven't found a handler for this
|
||||
chunk. In the future we will have code here which can handle
|
||||
user-defined callback functions for unknown chunks before they are
|
||||
ignored or cause an error. If there isn't a problem with the
|
||||
chunk itself (ie a bad chunk name or a critical chunk), the chunk
|
||||
is (currently) silently ignored. */
|
||||
* chunk. In the future we will have code here which can handle
|
||||
* user-defined callback functions for unknown chunks before they are
|
||||
* ignored or cause an error. If there isn't a problem with the
|
||||
* chunk itself (ie a bad chunk name or a critical chunk), the chunk
|
||||
* is (currently) silently ignored.
|
||||
*/
|
||||
void
|
||||
png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
{
|
||||
@@ -1041,10 +1057,7 @@ png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 len
|
||||
|
||||
if (!(png_ptr->chunk_name[0] & 0x20))
|
||||
{
|
||||
char msg[40];
|
||||
|
||||
sprintf(msg, "Unknown critical chunk %s", png_ptr->chunk_name);
|
||||
png_error(png_ptr, msg);
|
||||
png_chunk_error(png_ptr, "unknown critical chunk");
|
||||
}
|
||||
|
||||
png_push_crc_skip(png_ptr, length);
|
||||
|
||||
113
pngread.c
113
pngread.c
@@ -1,19 +1,23 @@
|
||||
|
||||
/* pngread.c - read a PNG file
|
||||
|
||||
libpng 1.0 beta 6 - version 0.96
|
||||
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
|
||||
May 12, 1997
|
||||
*/
|
||||
*
|
||||
* libpng 0.99a
|
||||
* 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 31, 1998
|
||||
*
|
||||
* This file contains routines that an application calls directly to
|
||||
* read a PNG file or stream.
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
#include "png.h"
|
||||
|
||||
/* Create a PNG structure for reading, and allocate any memory needed. */
|
||||
png_structp
|
||||
png_create_read_struct(png_charp user_png_ver, png_voidp error_ptr,
|
||||
png_create_read_struct(png_const_charp user_png_ver, png_voidp error_ptr,
|
||||
png_error_ptr error_fn, png_error_ptr warn_fn)
|
||||
{
|
||||
png_structp png_ptr;
|
||||
@@ -54,7 +58,7 @@ png_create_read_struct(png_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_ptr->zbuf_size);
|
||||
png_ptr->zstream.zalloc = png_zalloc;
|
||||
png_ptr->zstream.zfree = png_zfree;
|
||||
png_ptr->zstream.opaque = (voidpf)png_ptr;
|
||||
@@ -76,7 +80,6 @@ png_create_read_struct(png_charp user_png_ver, png_voidp error_ptr,
|
||||
return (png_ptr);
|
||||
}
|
||||
|
||||
|
||||
/* Initialize PNG structure for reading, and allocate any memory needed.
|
||||
This interface is depreciated in favour of the png_create_read_struct(),
|
||||
and it will eventually disappear. */
|
||||
@@ -97,7 +100,7 @@ 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_ptr->zbuf_size);
|
||||
png_ptr->zstream.zalloc = png_zalloc;
|
||||
png_ptr->zstream.zfree = png_zfree;
|
||||
png_ptr->zstream.opaque = (voidpf)png_ptr;
|
||||
@@ -215,6 +218,10 @@ png_read_info(png_structp png_ptr, png_infop info_ptr)
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
|
||||
png_handle_sBIT(png_ptr, info_ptr, length);
|
||||
#endif
|
||||
#if defined(PNG_READ_sRGB_SUPPORTED)
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
|
||||
png_handle_sRGB(png_ptr, info_ptr, length);
|
||||
#endif
|
||||
#if defined(PNG_READ_tEXt_SUPPORTED)
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
|
||||
png_handle_tEXt(png_ptr, info_ptr, length);
|
||||
@@ -247,10 +254,11 @@ png_read_update_info(png_structp png_ptr, png_infop info_ptr)
|
||||
png_read_transform_info(png_ptr, info_ptr);
|
||||
}
|
||||
|
||||
/* initialize palette, background, etc, after transformations
|
||||
are set, but before any reading takes place. This allows
|
||||
the user to obtail a gamma corrected palette, for example.
|
||||
If the user doesn't call this, we will do it ourselves. */
|
||||
/* Initialize palette, background, etc, after transformations
|
||||
* are set, but before any reading takes place. This allows
|
||||
* the user to obtail a gamma corrected palette, for example.
|
||||
* If the user doesn't call this, we will do it ourselves.
|
||||
*/
|
||||
void
|
||||
png_start_read_image(png_structp png_ptr)
|
||||
{
|
||||
@@ -439,23 +447,26 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
|
||||
}
|
||||
|
||||
/* Read one or more rows of image data. If the image is interlaced,
|
||||
and png_set_interlace_handling() has been called, the rows need to
|
||||
to contain the contents of the rows from the previous pass. If
|
||||
the image has alpha or transparency, and png_handle_alpha() has been
|
||||
called, the rows contents must be initialized to the contents of the
|
||||
screen. "row" holds the actual image, and pixels are placed in it
|
||||
as they arrive. If the image is displayed after each pass, it will
|
||||
appear to "sparkle" in. "display_row" can be used to display a
|
||||
"chunky" progressive image, with finer detail added as it becomes
|
||||
available. If you do not want this "chunky" display, you may pass
|
||||
NULL for display_row. If you do not want the sparkle display, and
|
||||
you have not called png_handle_alpha(), you may pass NULL for rows.
|
||||
If you have called png_handle_alpha(), and the image has either an
|
||||
alpha channel or a transparency chunk, you must provide a buffer for
|
||||
rows. In this case, you do not have to provide a display_row buffer
|
||||
also, but you may. If the image is not interlaced, or if you have
|
||||
not called png_set_interlace_handling(), the display_row buffer will
|
||||
be ignored, so pass NULL to it. */
|
||||
* and png_set_interlace_handling() has been called, the rows need to
|
||||
* contain the contents of the rows from the previous pass. If the
|
||||
* image has alpha or transparency, and png_handle_alpha() has been
|
||||
* called, the rows contents must be initialized to the contents of the
|
||||
* screen.
|
||||
*
|
||||
* "row" holds the actual image, and pixels are placed in it
|
||||
* as they arrive. If the image is displayed after each pass, it will
|
||||
* appear to "sparkle" in. "display_row" can be used to display a
|
||||
* "chunky" progressive image, with finer detail added as it becomes
|
||||
* available. If you do not want this "chunky" display, you may pass
|
||||
* NULL for display_row. If you do not want the sparkle display, and
|
||||
* you have not called png_handle_alpha(), you may pass NULL for rows.
|
||||
* If you have called png_handle_alpha(), and the image has either an
|
||||
* alpha channel or a transparency chunk, you must provide a buffer for
|
||||
* rows. In this case, you do not have to provide a display_row buffer
|
||||
* also, but you may. If the image is not interlaced, or if you have
|
||||
* not called png_set_interlace_handling(), the display_row buffer will
|
||||
* be ignored, so pass NULL to it.
|
||||
*/
|
||||
|
||||
void
|
||||
png_read_rows(png_structp png_ptr, png_bytepp row,
|
||||
@@ -491,14 +502,15 @@ png_read_rows(png_structp png_ptr, png_bytepp row,
|
||||
}
|
||||
|
||||
/* Read the entire image. If the image has an alpha channel or a tRNS
|
||||
chunk, and you have called png_handle_alpha(), you will need to
|
||||
initialize the image to the current image that PNG will be overlaying.
|
||||
We set the num_rows again here, in case it was incorrectly set in
|
||||
png_read_start_row() by a call to png_read_update_info() or
|
||||
png_start_read_image() if png_set_interlace_handling() wasn't called
|
||||
prior to either of these functions like it should have been. You can
|
||||
only call this function once. If you desire to have an image for
|
||||
each pass of a interlaced image, use png_read_rows() instead */
|
||||
* chunk, and you have called png_handle_alpha(), you will need to
|
||||
* initialize the image to the current image that PNG will be overlaying.
|
||||
* We set the num_rows again here, in case it was incorrectly set in
|
||||
* png_read_start_row() by a call to png_read_update_info() or
|
||||
* png_start_read_image() if png_set_interlace_handling() wasn't called
|
||||
* prior to either of these functions like it should have been. You can
|
||||
* only call this function once. If you desire to have an image for
|
||||
* each pass of a interlaced image, use png_read_rows() instead.
|
||||
*/
|
||||
void
|
||||
png_read_image(png_structp png_ptr, png_bytepp image)
|
||||
{
|
||||
@@ -524,8 +536,9 @@ png_read_image(png_structp png_ptr, png_bytepp image)
|
||||
}
|
||||
|
||||
/* Read the end of the PNG file. Will not read past the end of the
|
||||
file, will verify the end is accurate, and will read any comments
|
||||
or time information at the end of the file, if info is not NULL. */
|
||||
* file, will verify the end is accurate, and will read any comments
|
||||
* or time information at the end of the file, if info is not NULL.
|
||||
*/
|
||||
void
|
||||
png_read_end(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
@@ -594,6 +607,10 @@ png_read_end(png_structp png_ptr, png_infop info_ptr)
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
|
||||
png_handle_sBIT(png_ptr, info_ptr, length);
|
||||
#endif
|
||||
#if defined(PNG_READ_sRGB_SUPPORTED)
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
|
||||
png_handle_sRGB(png_ptr, info_ptr, length);
|
||||
#endif
|
||||
#if defined(PNG_READ_tEXt_SUPPORTED)
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
|
||||
png_handle_tEXt(png_ptr, info_ptr, length);
|
||||
@@ -638,12 +655,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;
|
||||
}
|
||||
@@ -659,7 +682,6 @@ png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
|
||||
void
|
||||
png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr)
|
||||
{
|
||||
int i;
|
||||
jmp_buf tmp_jmp;
|
||||
png_error_ptr error_fn;
|
||||
png_error_ptr warning_fn;
|
||||
@@ -688,7 +710,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);
|
||||
@@ -700,6 +722,7 @@ png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr
|
||||
#if defined(PNG_READ_GAMMA_SUPPORTED)
|
||||
if (png_ptr->gamma_16_table != NULL)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < (1 << (8 - png_ptr->gamma_shift)); i++)
|
||||
{
|
||||
png_free(png_ptr, png_ptr->gamma_16_table[i]);
|
||||
@@ -710,6 +733,7 @@ png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr
|
||||
png_free(png_ptr, png_ptr->gamma_16_table);
|
||||
if (png_ptr->gamma_16_from_1 != NULL)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < (1 << (8 - png_ptr->gamma_shift)); i++)
|
||||
{
|
||||
png_free(png_ptr, png_ptr->gamma_16_from_1[i]);
|
||||
@@ -718,6 +742,7 @@ png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr
|
||||
png_free(png_ptr, png_ptr->gamma_16_from_1);
|
||||
if (png_ptr->gamma_16_to_1 != NULL)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < (1 << (8 - png_ptr->gamma_shift)); i++)
|
||||
{
|
||||
png_free(png_ptr, png_ptr->gamma_16_to_1[i]);
|
||||
|
||||
34
pngrio.c
34
pngrio.c
@@ -1,18 +1,20 @@
|
||||
|
||||
/* pngrio.c - functions for data input
|
||||
|
||||
libpng 1.0 beta 6 - version 0.96
|
||||
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
|
||||
May 12, 1997
|
||||
|
||||
This file provides a location for all input. Users which need
|
||||
special handling are expected to write a function which has the same
|
||||
arguments as this, and perform a similar function, but possibly has
|
||||
a different input method. Note that you shouldn't change this
|
||||
function, but rather write a replacement function and then make
|
||||
libpng use it at run time with png_set_read_fn(...) */
|
||||
*
|
||||
* libpng 0.99a
|
||||
* 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 31, 1998
|
||||
*
|
||||
* This file provides a location for all input. Users which need
|
||||
* special handling are expected to write a function which has the same
|
||||
* arguments as this, and perform a similar function, but possibly has
|
||||
* a different input method. Note that you shouldn't change this
|
||||
* function, but rather write a replacement function and then make
|
||||
* libpng use it at run time with png_set_read_fn(...).
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
#include "png.h"
|
||||
@@ -32,6 +34,7 @@ png_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
png_error(png_ptr, "Call to NULL read function");
|
||||
}
|
||||
|
||||
#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
|
||||
@@ -102,6 +105,7 @@ png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* This function allows the application to supply a new input function
|
||||
for libpng if standard C streams aren't being used.
|
||||
@@ -122,10 +126,14 @@ png_set_read_fn(png_structp png_ptr, png_voidp io_ptr,
|
||||
{
|
||||
png_ptr->io_ptr = io_ptr;
|
||||
|
||||
#if !defined(PNG_NO_STDIO)
|
||||
if (read_data_fn != NULL)
|
||||
png_ptr->read_data_fn = read_data_fn;
|
||||
else
|
||||
png_ptr->read_data_fn = png_default_read_data;
|
||||
#else
|
||||
png_ptr->read_data_fn = read_data_fn;
|
||||
#endif
|
||||
|
||||
/* It is an error to write to a read device */
|
||||
png_ptr->write_data_fn = NULL;
|
||||
|
||||
416
pngrtran.c
416
pngrtran.c
@@ -1,49 +1,114 @@
|
||||
|
||||
/* pngrtran.c - transforms the data in a row for PNG readers
|
||||
|
||||
libpng 1.0 beta 6 - version 0.96
|
||||
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
|
||||
May 12, 1997
|
||||
*/
|
||||
*
|
||||
* libpng 0.99a
|
||||
* 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 31, 1998
|
||||
*
|
||||
* This file contains functions optionally called by an application
|
||||
* in order to tell libpng how to handle data when reading a PNG.
|
||||
* Transformations which are used in both reading and writing are
|
||||
* in pngtrans.c.
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
#include "png.h"
|
||||
|
||||
#ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED
|
||||
/* With these routines, we avoid an integer divide, which will be slower on
|
||||
many machines. However, it does take more operations than the corresponding
|
||||
divide method, so it may be slower on some RISC systems. There are two
|
||||
shifts (by 8 or 16 bits) and an addition, versus a single integer divide.
|
||||
The results may also be off by one for certain values. */
|
||||
* many machines. However, it does take more operations than the corresponding
|
||||
* divide method, so it may be slower on some RISC systems. There are two
|
||||
* shifts (by 8 or 16 bits) and an addition, versus a single integer divide.
|
||||
*
|
||||
* Note that the rounding factors are NOT supposed to be the same! 128 and
|
||||
* 32768 are correct for the NODIV code; 127 and 32767 are correct for the
|
||||
* standard method.
|
||||
*
|
||||
* [Optimized code by Greg Roelofs and Mark Adler...blame us for bugs. :-) ]
|
||||
*/
|
||||
|
||||
/* pixel and background should be in gamma 1.0 space */
|
||||
#define png_composite(composite, pixel, trans, background) \
|
||||
{ png_uint_16 temp = ((png_uint_16)(pixel) * (png_uint_16)(trans) + \
|
||||
(png_uint_16)(background)*(png_uint_16)(255 - \
|
||||
(png_uint_16)(trans)) + (png_uint_16)127); \
|
||||
(composite) = (png_byte)(((temp >> 8) + temp) >> 8); }
|
||||
/* fg and bg should be in `gamma 1.0' space; alpha is the opacity */
|
||||
# define png_composite(composite, fg, alpha, bg) \
|
||||
{ png_uint_16 temp = ((png_uint_16)(fg) * (png_uint_16)(alpha) + \
|
||||
(png_uint_16)(bg)*(png_uint_16)(255 - \
|
||||
(png_uint_16)(alpha)) + (png_uint_16)128); \
|
||||
(composite) = (png_byte)((temp + (temp >> 8)) >> 8); }
|
||||
# define png_composite_16(composite, fg, alpha, bg) \
|
||||
{ png_uint_32 temp = ((png_uint_32)(fg) * (png_uint_32)(alpha) + \
|
||||
(png_uint_32)(bg)*(png_uint_32)(65535L - \
|
||||
(png_uint_32)(alpha)) + (png_uint_32)32768L); \
|
||||
(composite) = (png_uint_16)((temp + (temp >> 16)) >> 16); }
|
||||
|
||||
/* pixel and background should be in gamma 1.0 space */
|
||||
#define png_composite_16(composite, pixel, trans, background) \
|
||||
{ png_uint_32 temp = ((png_uint_32)(pixel) * (png_uint_32)(trans) + \
|
||||
(png_uint_32)(background)*(png_uint_32)(65535L - \
|
||||
(png_uint_32)(trans)) + (png_uint_32)32767); \
|
||||
(composite) = (png_uint_16)(((temp >> 16) + temp) >> 16); }
|
||||
#else
|
||||
/* pixel and background should be in gamma 1.0 space */
|
||||
#define png_composite(composite, pixel, trans, background) \
|
||||
(composite) = (png_byte)(((png_uint_16)(pixel) * (png_uint_16)(trans) + \
|
||||
(png_uint_16)(background) * (png_uint_16)(255 - (png_uint_16)(trans)) + \
|
||||
(png_uint_16)127) / 255)
|
||||
|
||||
/* pixel and background should be in gamma 1.0 space */
|
||||
#define png_composite_16(composite, pixel, trans, background) \
|
||||
(composite) = (png_uint_16)(((png_uint_32)(pixel) * (png_uint_32)(trans) + \
|
||||
(png_uint_32)(background)*(png_uint_32)(65535L - (png_uint_32)(trans)) + \
|
||||
(png_uint_32)32767) / 65535L)
|
||||
#endif
|
||||
#else /* standard method using integer division */
|
||||
|
||||
/* fg and bg should be in `gamma 1.0' space; alpha is the opacity */
|
||||
# define png_composite(composite, fg, alpha, bg) \
|
||||
(composite) = (png_byte)(((png_uint_16)(fg) * (png_uint_16)(alpha) + \
|
||||
(png_uint_16)(bg) * (png_uint_16)(255 - (png_uint_16)(alpha)) + \
|
||||
(png_uint_16)127) / 255)
|
||||
# define png_composite_16(composite, fg, alpha, bg) \
|
||||
(composite) = (png_uint_16)(((png_uint_32)(fg) * (png_uint_32)(alpha) + \
|
||||
(png_uint_32)(bg)*(png_uint_32)(65535L - (png_uint_32)(alpha)) + \
|
||||
(png_uint_32)32767) / (png_uint_32)65535L)
|
||||
|
||||
#endif /* ?PNG_READ_COMPOSITE_NODIV_SUPPORTED */
|
||||
|
||||
|
||||
/* Set the action on getting a CRC error for an ancillary or critical chunk. */
|
||||
void
|
||||
png_set_crc_action(png_structp png_ptr, int crit_action, int ancil_action)
|
||||
{
|
||||
png_debug(1, "in png_set_crc_action\n");
|
||||
/* Tell libpng how we react to CRC errors in critical chunks */
|
||||
switch (crit_action)
|
||||
{
|
||||
case PNG_CRC_NO_CHANGE: /* leave setting as is */
|
||||
break;
|
||||
case PNG_CRC_WARN_USE: /* warn/use data */
|
||||
png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
|
||||
png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE;
|
||||
break;
|
||||
case PNG_CRC_QUIET_USE: /* quiet/use data */
|
||||
png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
|
||||
png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE |
|
||||
PNG_FLAG_CRC_CRITICAL_IGNORE;
|
||||
break;
|
||||
case PNG_CRC_WARN_DISCARD: /* not a valid action for critical data */
|
||||
png_warning(png_ptr, "Can't discard critical data on CRC error.");
|
||||
case PNG_CRC_ERROR_QUIT: /* error/quit */
|
||||
case PNG_CRC_DEFAULT:
|
||||
default:
|
||||
png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (ancil_action)
|
||||
{
|
||||
case PNG_CRC_NO_CHANGE: /* leave setting as is */
|
||||
break;
|
||||
case PNG_CRC_WARN_USE: /* warn/use data */
|
||||
png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
|
||||
png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE;
|
||||
break;
|
||||
case PNG_CRC_QUIET_USE: /* quiet/use data */
|
||||
png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
|
||||
png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE |
|
||||
PNG_FLAG_CRC_ANCILLARY_NOWARN;
|
||||
break;
|
||||
case PNG_CRC_ERROR_QUIT: /* error/quit */
|
||||
png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
|
||||
png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_NOWARN;
|
||||
break;
|
||||
case PNG_CRC_WARN_DISCARD: /* warn/discard data */
|
||||
case PNG_CRC_DEFAULT:
|
||||
default:
|
||||
png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(PNG_READ_BACKGROUND_SUPPORTED)
|
||||
/* handle alpha and tRNS via a background color */
|
||||
@@ -89,12 +154,13 @@ png_set_strip_alpha(png_structp png_ptr)
|
||||
|
||||
#if defined(PNG_READ_DITHER_SUPPORTED)
|
||||
/* Dither file to 8 bit. Supply a palette, the current number
|
||||
of elements in the palette, the maximum number of elements
|
||||
allowed, and a histogram if possible. If the current number
|
||||
of colors is greater then the maximum number, the palette will be
|
||||
modified to fit in the maximum number. "full_dither" indicates
|
||||
whether we need a dithering cube set up for RGB images, or if we
|
||||
simply are reducing the number of colors in a paletted image. */
|
||||
* of elements in the palette, the maximum number of elements
|
||||
* allowed, and a histogram if possible. If the current number
|
||||
* of colors is greater then the maximum number, the palette will be
|
||||
* modified to fit in the maximum number. "full_dither" indicates
|
||||
* whether we need a dithering cube set up for RGB images, or if we
|
||||
* simply are reducing the number of colors in a paletted image.
|
||||
*/
|
||||
|
||||
typedef struct png_dsort_struct
|
||||
{
|
||||
@@ -306,7 +372,7 @@ 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, sizeof (png_dsort));
|
||||
t->next = hash[d];
|
||||
t->left = (png_byte)i;
|
||||
t->right = (png_byte)j;
|
||||
@@ -478,24 +544,26 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
|
||||
|
||||
#if defined(PNG_READ_GAMMA_SUPPORTED)
|
||||
/* Transform the image from the file_gamma to the screen_gamma. We
|
||||
only do transformations on images where the file_gamma and screen_gamma
|
||||
are not close reciprocals, otherwise it slows things down slightly, and
|
||||
also needlessly introduces small errors. */
|
||||
* only do transformations on images where the file_gamma and screen_gamma
|
||||
* are not close reciprocals, otherwise it slows things down slightly, and
|
||||
* 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
|
||||
|
||||
#if defined(PNG_READ_EXPAND_SUPPORTED)
|
||||
/* Expand paletted images to rgb, expand grayscale images of
|
||||
less then 8 bit depth to 8 bit depth, and expand tRNS chunks
|
||||
to alpha channels. */
|
||||
* less then 8 bit depth to 8 bit depth, and expand tRNS chunks
|
||||
* to alpha channels.
|
||||
*/
|
||||
void
|
||||
png_set_expand(png_structp png_ptr)
|
||||
{
|
||||
@@ -515,19 +583,22 @@ png_set_gray_to_rgb(png_structp png_ptr)
|
||||
|
||||
#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
|
||||
/* Convert a RGB image to a grayscale of the given width. This would
|
||||
allow us, for example, to convert a 24 bpp RGB image into an 8 or
|
||||
16 bpp grayscale image. (Not yet implemented.) */
|
||||
* allow us, for example, to convert a 24 bpp RGB image into an 8 or
|
||||
* 16 bpp grayscale image. (Not yet implemented.)
|
||||
*/
|
||||
void
|
||||
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
|
||||
|
||||
/* Initialize everything needed for the read. This includes modifying
|
||||
the palette */
|
||||
* the palette.
|
||||
*/
|
||||
void
|
||||
png_init_read_transformations(png_structp png_ptr)
|
||||
{
|
||||
@@ -574,6 +645,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<png_ptr->num_trans; i++)
|
||||
png_ptr->trans[i] = 255 - png_ptr->trans[i];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -611,7 +699,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)
|
||||
@@ -691,17 +779,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;
|
||||
}
|
||||
|
||||
@@ -810,8 +898,9 @@ png_init_read_transformations(png_structp png_ptr)
|
||||
}
|
||||
|
||||
/* Modify the info structure to reflect the transformations. The
|
||||
info should be updated so a PNG file could be written with it,
|
||||
assuming the transformations result in valid PNG data. */
|
||||
* info should be updated so a PNG file could be written with it,
|
||||
* assuming the transformations result in valid PNG data.
|
||||
*/
|
||||
void
|
||||
png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
@@ -883,7 +972,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)
|
||||
{
|
||||
@@ -910,9 +999,10 @@ png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
|
||||
(png_size_t)((info_ptr->width * info_ptr->pixel_depth + 7) >> 3);
|
||||
}
|
||||
|
||||
/* transform the row. The order of transformations is significant,
|
||||
and is very touchy. If you add a transformation, take care to
|
||||
decide how it fits in with the other transformations here. */
|
||||
/* Transform the row. The order of transformations is significant,
|
||||
* and is very touchy. If you add a transformation, take care to
|
||||
* decide how it fits in with the other transformations here.
|
||||
*/
|
||||
void
|
||||
png_do_read_transformations(png_structp png_ptr)
|
||||
{
|
||||
@@ -920,11 +1010,15 @@ png_do_read_transformations(png_structp png_ptr)
|
||||
#if !defined(PNG_USELESS_TESTS_SUPPORTED)
|
||||
if (png_ptr->row_buf == NULL)
|
||||
{
|
||||
#if !defined(PNG_NO_STDIO)
|
||||
char msg[50];
|
||||
|
||||
sprintf(msg, "NULL row buffer for row %ld, pass %d", png_ptr->row_number,
|
||||
png_ptr->pass);
|
||||
png_error(png_ptr, msg);
|
||||
#else
|
||||
png_error(png_ptr, "NULL row buffer");
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -955,7 +1049,9 @@ png_do_read_transformations(png_structp png_ptr)
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_BACKGROUND_SUPPORTED)
|
||||
if (png_ptr->transformations & PNG_BACKGROUND)
|
||||
if ((png_ptr->transformations & PNG_BACKGROUND) &&
|
||||
((png_ptr->num_trans != 0 ) ||
|
||||
(png_ptr->color_type & PNG_COLOR_MASK_ALPHA)))
|
||||
png_do_background(&(png_ptr->row_info), png_ptr->row_buf + 1,
|
||||
&(png_ptr->trans_values), &(png_ptr->background),
|
||||
&(png_ptr->background_1),
|
||||
@@ -1034,6 +1130,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);
|
||||
@@ -1041,11 +1142,12 @@ png_do_read_transformations(png_structp png_ptr)
|
||||
}
|
||||
|
||||
#if defined(PNG_READ_PACK_SUPPORTED)
|
||||
/* unpack pixels of 1, 2, or 4 bits per pixel into 1 byte per pixel,
|
||||
without changing the actual values. Thus, if you had a row with
|
||||
a bit depth of 1, you would end up with bytes that only contained
|
||||
the numbers 0 or 1. If you would rather they contain 0 and 255, use
|
||||
png_do_shift() after this. */
|
||||
/* Unpack pixels of 1, 2, or 4 bits per pixel into 1 byte per pixel,
|
||||
* without changing the actual values. Thus, if you had a row with
|
||||
* a bit depth of 1, you would end up with bytes that only contained
|
||||
* the numbers 0 or 1. If you would rather they contain 0 and 255, use
|
||||
* png_do_shift() after this.
|
||||
*/
|
||||
void
|
||||
png_do_unpack(png_row_infop row_info, png_bytep row)
|
||||
{
|
||||
@@ -1131,10 +1233,11 @@ png_do_unpack(png_row_infop row_info, png_bytep row)
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_SHIFT_SUPPORTED)
|
||||
/* reverse the effects of png_do_shift. This routine merely shifts the
|
||||
pixels back to their significant bits values. Thus, if you have
|
||||
a row of bit depth 8, but only 5 are significant, this will shift
|
||||
the values back to 0 through 31 */
|
||||
/* Reverse the effects of png_do_shift. This routine merely shifts the
|
||||
* pixels back to their significant bits values. Thus, if you have
|
||||
* a row of bit depth 8, but only 5 are significant, this will shift
|
||||
* the values back to 0 through 31.
|
||||
*/
|
||||
void
|
||||
png_do_unshift(png_row_infop row_info, png_bytep row, png_color_8p sig_bits)
|
||||
{
|
||||
@@ -1268,7 +1371,17 @@ png_do_chop(png_row_infop row_info, png_bytep row)
|
||||
*
|
||||
* What the ideal calculation should be:
|
||||
*dp = (((((png_uint_32)(*sp) << 8) |
|
||||
(png_uint_32)(*(sp + 1))) * 255 + 127) / 65535;
|
||||
(png_uint_32)(*(sp + 1))) * 255 + 127) / (png_uint_32)65535L;
|
||||
|
||||
|
||||
* GRR: no, I think this is what it really should be:
|
||||
*dp = (((((png_uint_32)(*sp) << 8) |
|
||||
(png_uint_32)(*(sp + 1))) + 128L) / (png_uint_32)257L;
|
||||
|
||||
* GRR: here's the exact calculation with shifts:
|
||||
temp = (((png_uint_32)(*sp) << 8) | (png_uint_32)(*(sp + 1))) + 128L;
|
||||
*dp = (temp - (temp >> 8)) >> 8;
|
||||
|
||||
|
||||
* Approximate calculation with shift/add instead of multiply/divide:
|
||||
*dp = ((((png_uint_32)(*sp) << 8) |
|
||||
@@ -1378,6 +1491,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
|
||||
@@ -1527,10 +1721,11 @@ png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
|
||||
}
|
||||
#endif
|
||||
|
||||
/* build a grayscale palette. Palette is assumed to be 1 << bit_depth
|
||||
large of png_color. This lets grayscale images be treated as
|
||||
paletted. Most useful for gamma correction and simplification
|
||||
of code. */
|
||||
/* Build a grayscale palette. Palette is assumed to be 1 << bit_depth
|
||||
* large of png_color. This lets grayscale images be treated as
|
||||
* paletted. Most useful for gamma correction and simplification
|
||||
* of code.
|
||||
*/
|
||||
void
|
||||
png_build_grayscale_palette(int bit_depth, png_colorp palette)
|
||||
{
|
||||
@@ -1602,7 +1797,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)
|
||||
@@ -1762,8 +1957,9 @@ png_correct_palette(png_structp png_ptr, png_colorp palette,
|
||||
|
||||
#if defined(PNG_READ_BACKGROUND_SUPPORTED)
|
||||
/* Replace any alpha or transparency with the supplied background color.
|
||||
"background" is already in the screen gamma, while "background_1" is
|
||||
at a gamma of 1.0. Paletted files have already been taken care of. */
|
||||
* "background" is already in the screen gamma, while "background_1" is
|
||||
* at a gamma of 1.0. Paletted files have already been taken care of.
|
||||
*/
|
||||
void
|
||||
png_do_background(png_row_infop row_info, png_bytep row,
|
||||
png_color_16p trans_values, png_color_16p background,
|
||||
@@ -2330,7 +2526,7 @@ png_do_background(png_row_infop row_info, png_bytep row,
|
||||
png_composite_16(v, g, a, background->green);
|
||||
*(dp + 2) = (png_byte)((v >> 8) & 0xff);
|
||||
*(dp + 3) = (png_byte)(v & 0xff);
|
||||
png_composite_16(v, g, a, background->green);
|
||||
png_composite_16(v, b, a, background->blue);
|
||||
*(dp + 4) = (png_byte)((v >> 8) & 0xff);
|
||||
*(dp + 5) = (png_byte)(v & 0xff);
|
||||
}
|
||||
@@ -2356,10 +2552,11 @@ png_do_background(png_row_infop row_info, png_bytep row,
|
||||
|
||||
#if defined(PNG_READ_GAMMA_SUPPORTED)
|
||||
/* Gamma correct the image, avoiding the alpha channel. Make sure
|
||||
you do this after you deal with the trasparency issue on grayscale
|
||||
or rgb images. If your bit depth is 8, use gamma_table, if it
|
||||
is 16, use gamma_16_table and gamma_shift. Build these with
|
||||
build_gamma_table(). */
|
||||
* you do this after you deal with the trasparency issue on grayscale
|
||||
* or rgb images. If your bit depth is 8, use gamma_table, if it
|
||||
* is 16, use gamma_16_table and gamma_shift. Build these with
|
||||
* build_gamma_table().
|
||||
*/
|
||||
void
|
||||
png_do_gamma(png_row_infop row_info, png_bytep row,
|
||||
png_bytep gamma_table, png_uint_16pp gamma_16_table,
|
||||
@@ -2481,6 +2678,22 @@ png_do_gamma(png_row_infop row_info, png_bytep row,
|
||||
}
|
||||
case PNG_COLOR_TYPE_GRAY:
|
||||
{
|
||||
if (row_info->bit_depth == 2)
|
||||
{
|
||||
for (i = 0, sp = row; i < row_info->width; i += 4)
|
||||
{
|
||||
int a = *sp & 0xc0;
|
||||
int b = *sp & 0x30;
|
||||
int c = *sp & 0x0c;
|
||||
int d = *sp & 0x03;
|
||||
|
||||
*sp = ((((int)gamma_table[a|(a>>2)|(a>>4)|(a>>6)]) ) & 0xc0)|
|
||||
((((int)gamma_table[(b<<2)|b|(b>>2)|(b>>4)])>>2) & 0x30)|
|
||||
((((int)gamma_table[(c<<4)|(c<<2)|c|(c>>2)])>>4) & 0x0c)|
|
||||
((((int)gamma_table[(d<<6)|(d<<4)|(d<<2)|d])>>6) );
|
||||
sp++;
|
||||
}
|
||||
}
|
||||
if (row_info->bit_depth == 4)
|
||||
{
|
||||
for (i = 0, sp = row; i < row_info->width; i += 2)
|
||||
@@ -2488,8 +2701,8 @@ png_do_gamma(png_row_infop row_info, png_bytep row,
|
||||
int msb = *sp & 0xf0;
|
||||
int lsb = *sp & 0x0f;
|
||||
|
||||
*sp = (((int)gamma_table[msb | msb >> 4] + 8) & 0xf0) |
|
||||
(((int)gamma_table[lsb << 4 | lsb] + 8) >> 4);
|
||||
*sp = (((int)gamma_table[msb | (msb >> 4)]) & 0xf0) |
|
||||
(((int)gamma_table[(lsb << 4) | lsb]) >> 4);
|
||||
sp++;
|
||||
}
|
||||
}
|
||||
@@ -2521,8 +2734,9 @@ png_do_gamma(png_row_infop row_info, png_bytep row,
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_EXPAND_SUPPORTED)
|
||||
/* expands a palette row to an rgb or rgba row depending
|
||||
upon whether you supply trans and num_trans */
|
||||
/* Expands a palette row to an rgb or rgba row depending
|
||||
* upon whether you supply trans and num_trans.
|
||||
*/
|
||||
void
|
||||
png_do_expand_palette(png_row_infop row_info, png_bytep row,
|
||||
png_colorp palette, png_bytep trans, int num_trans)
|
||||
@@ -2662,8 +2876,9 @@ png_do_expand_palette(png_row_infop row_info, png_bytep row,
|
||||
}
|
||||
}
|
||||
|
||||
/* if the bit depth < 8, it is expanded to 8. Also, if the
|
||||
transparency value is supplied, an alpha channel is built. */
|
||||
/* If the bit depth < 8, it is expanded to 8. Also, if the
|
||||
* transparency value is supplied, an alpha channel is built.
|
||||
*/
|
||||
void
|
||||
png_do_expand(png_row_infop row_info, png_bytep row,
|
||||
png_color_16p trans_value)
|
||||
@@ -2958,9 +3173,10 @@ static int png_gamma_shift[] =
|
||||
{0x10, 0x21, 0x42, 0x84, 0x110, 0x248, 0x550, 0xff0};
|
||||
|
||||
/* We build the 8- or 16-bit gamma tables here. Note that for 16-bit
|
||||
tables, we don't make a full table if we are reducing to 8-bit in
|
||||
the future. Note also how the gamma_16 tables are segmented so that
|
||||
we don't need to allocate > 64K chunks for a full 16-bit table. */
|
||||
* tables, we don't make a full table if we are reducing to 8-bit in
|
||||
* the future. Note also how the gamma_16 tables are segmented so that
|
||||
* we don't need to allocate > 64K chunks for a full 16-bit table.
|
||||
*/
|
||||
void
|
||||
png_build_gamma_table(png_structp png_ptr)
|
||||
{
|
||||
@@ -2970,7 +3186,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);
|
||||
@@ -2995,7 +3211,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);
|
||||
@@ -3048,7 +3264,7 @@ 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));
|
||||
@@ -3126,7 +3342,7 @@ 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));
|
||||
|
||||
294
pngrutil.c
294
pngrutil.c
@@ -1,12 +1,16 @@
|
||||
|
||||
/* pngrutil.c - utilities to read a PNG file
|
||||
|
||||
libpng 1.0 beta 6 - version 0.96
|
||||
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
|
||||
May 12, 1997
|
||||
*/
|
||||
*
|
||||
* libpng 0.99a
|
||||
* 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 31, 1998
|
||||
*
|
||||
* This file contains routines which are only called from within
|
||||
* libpng itself during the course of reading an image.
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
#include "png.h"
|
||||
@@ -23,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)
|
||||
@@ -40,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 */
|
||||
|
||||
@@ -53,63 +57,10 @@ 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 */
|
||||
|
||||
/* Set the action on getting a CRC error for an ancillary or critical chunk. */
|
||||
void
|
||||
png_set_crc_action(png_structp png_ptr, int crit_action, int ancil_action)
|
||||
{
|
||||
png_debug(1, "in png_set_crc_action\n");
|
||||
/* Tell libpng how we react to CRC errors in critical chunks */
|
||||
switch (crit_action)
|
||||
{
|
||||
case PNG_CRC_NO_CHANGE: /* leave setting as is */
|
||||
break;
|
||||
case PNG_CRC_WARN_USE: /* warn/use data */
|
||||
png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
|
||||
png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE;
|
||||
break;
|
||||
case PNG_CRC_QUIET_USE: /* quiet/use data */
|
||||
png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
|
||||
png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE |
|
||||
PNG_FLAG_CRC_CRITICAL_IGNORE;
|
||||
break;
|
||||
case PNG_CRC_WARN_DISCARD: /* not a valid action for critical data */
|
||||
png_warning(png_ptr, "Can't discard critical data on CRC error.");
|
||||
case PNG_CRC_ERROR_QUIT: /* error/quit */
|
||||
case PNG_CRC_DEFAULT:
|
||||
default:
|
||||
png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (ancil_action)
|
||||
{
|
||||
case PNG_CRC_NO_CHANGE: /* leave setting as is */
|
||||
break;
|
||||
case PNG_CRC_WARN_USE: /* warn/use data */
|
||||
png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
|
||||
png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE;
|
||||
break;
|
||||
case PNG_CRC_QUIET_USE: /* quiet/use data */
|
||||
png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
|
||||
png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE |
|
||||
PNG_FLAG_CRC_ANCILLARY_NOWARN;
|
||||
break;
|
||||
case PNG_CRC_ERROR_QUIT: /* error/quit */
|
||||
png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
|
||||
png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_NOWARN;
|
||||
break;
|
||||
case PNG_CRC_WARN_DISCARD: /* warn/discard data */
|
||||
case PNG_CRC_DEFAULT:
|
||||
default:
|
||||
png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Read data, and (optionally) run it through the CRC. */
|
||||
void
|
||||
png_crc_read(png_structp png_ptr, png_bytep buf, png_size_t length)
|
||||
@@ -138,28 +89,24 @@ png_crc_finish(png_structp png_ptr, png_uint_32 skip)
|
||||
|
||||
if (png_crc_error(png_ptr))
|
||||
{
|
||||
char msg[80];
|
||||
|
||||
sprintf(msg,"CRC error in %s", png_ptr->chunk_name);
|
||||
|
||||
if ((png_ptr->chunk_name[0] & 0x20 && /* Ancillary */
|
||||
!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)) ||
|
||||
(!(png_ptr->chunk_name[0] & 0x20) && /* Critical */
|
||||
png_ptr->flags & PNG_FLAG_CRC_CRITICAL_USE))
|
||||
{
|
||||
png_warning(png_ptr, msg);
|
||||
png_chunk_warning(png_ptr, "CRC error");
|
||||
}
|
||||
else
|
||||
{
|
||||
png_error(png_ptr, msg);
|
||||
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)
|
||||
@@ -185,14 +132,10 @@ png_crc_error(png_structp png_ptr)
|
||||
if (need_crc)
|
||||
{
|
||||
crc = png_get_uint_32(crc_bytes);
|
||||
#ifdef PNG_USE_OWN_CRC
|
||||
return (((crc^0xffffffffL)&0xffffffffL) != (png_ptr->crc&0xffffffffL));
|
||||
#else
|
||||
return (crc != png_ptr->crc);
|
||||
#endif
|
||||
return ((int)(crc != png_ptr->crc));
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
@@ -228,7 +171,8 @@ png_handle_IHDR(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
interlace_type = buf[12];
|
||||
|
||||
/* check for width and height valid values */
|
||||
if (width == 0 || width > 2147483647 || height == 0 || height > 2147483647)
|
||||
if (width == 0 || width > (png_uint_32)2147483647L || height == 0 ||
|
||||
height > (png_uint_32)2147483647L)
|
||||
png_error(png_ptr, "Invalid image size in IHDR");
|
||||
|
||||
/* check other values */
|
||||
@@ -246,7 +190,7 @@ png_handle_IHDR(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8))
|
||||
png_error(png_ptr, "Invalid color type/bit depth combination in IHDR");
|
||||
|
||||
if (interlace_type > PNG_INTERLACE_ADAM7)
|
||||
if (interlace_type >= PNG_INTERLACE_LAST)
|
||||
png_error(png_ptr, "Unknown interlace method in IHDR");
|
||||
|
||||
if (compression_type != PNG_COMPRESSION_TYPE_BASE)
|
||||
@@ -337,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_malloc(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++)
|
||||
{
|
||||
@@ -354,16 +298,15 @@ 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 */
|
||||
{
|
||||
char msg[80];
|
||||
|
||||
sprintf(msg,"CRC error in %s", png_ptr->chunk_name);
|
||||
|
||||
/* If we don't want to use the data from an ancillary chunk,
|
||||
we have two options: an error abort, or a warning and we
|
||||
ignore the data in this chunk (which should be OK, since
|
||||
@@ -372,23 +315,23 @@ png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
{
|
||||
if (png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)
|
||||
{
|
||||
png_error(png_ptr, msg);
|
||||
png_chunk_error(png_ptr, "CRC error");
|
||||
}
|
||||
else
|
||||
{
|
||||
png_warning(png_ptr, msg);
|
||||
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;
|
||||
}
|
||||
}
|
||||
/* Otherwise, we (optionally) emit a warning and use the chunk. */
|
||||
else if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN))
|
||||
{
|
||||
png_warning(png_ptr, msg);
|
||||
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);
|
||||
@@ -434,7 +377,12 @@ png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
else if (png_ptr->mode & PNG_HAVE_PLTE)
|
||||
/* Should be an error, but we can cope with it */
|
||||
png_warning(png_ptr, "Out of place gAMA chunk");
|
||||
else if (info_ptr != NULL && info_ptr->valid & PNG_INFO_gAMA)
|
||||
|
||||
else if (info_ptr != NULL && info_ptr->valid & PNG_INFO_gAMA
|
||||
#if defined(PNG_READ_sRGB_SUPPORTED)
|
||||
&& !(info_ptr->valid & PNG_INFO_sRGB)
|
||||
#endif
|
||||
)
|
||||
{
|
||||
png_warning(png_ptr, "Duplicate gAMA chunk");
|
||||
png_crc_finish(png_ptr, length);
|
||||
@@ -457,8 +405,23 @@ png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
if (igamma == 0)
|
||||
return;
|
||||
|
||||
#if defined(PNG_READ_sRGB_SUPPORTED)
|
||||
if (info_ptr->valid & PNG_INFO_sRGB)
|
||||
if(igamma != (png_uint_32)45000L)
|
||||
{
|
||||
png_warning(png_ptr,
|
||||
"Ignoring incorrect gAMA value when sRGB is also present");
|
||||
#ifndef PNG_NO_STDIO
|
||||
fprintf(stderr, "igamma = %lu\n", igamma);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
#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
|
||||
@@ -483,8 +446,10 @@ png_handle_sBIT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
return;
|
||||
}
|
||||
else if (png_ptr->mode & PNG_HAVE_PLTE)
|
||||
{
|
||||
/* Should be an error, but we can cope with it */
|
||||
png_warning(png_ptr, "Out of place sBIT chunk");
|
||||
}
|
||||
else if (info_ptr != NULL && info_ptr->valid & PNG_INFO_sBIT)
|
||||
{
|
||||
png_warning(png_ptr, "Duplicate sBIT chunk");
|
||||
@@ -545,7 +510,12 @@ png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
else if (png_ptr->mode & PNG_HAVE_PLTE)
|
||||
/* Should be an error, but we can cope with it */
|
||||
png_warning(png_ptr, "Missing PLTE before cHRM");
|
||||
else if (info_ptr != NULL && info_ptr->valid & PNG_INFO_cHRM)
|
||||
|
||||
else if (info_ptr != NULL && info_ptr->valid & PNG_INFO_cHRM
|
||||
#if defined(PNG_READ_sRGB_SUPPORTED)
|
||||
&& !(info_ptr->valid & PNG_INFO_sRGB)
|
||||
#endif
|
||||
)
|
||||
{
|
||||
png_warning(png_ptr, "Duplicate cHRM chunk");
|
||||
png_crc_finish(png_ptr, length);
|
||||
@@ -615,8 +585,8 @@ png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
val = png_get_uint_32(buf);
|
||||
blue_y = (float)val / (float)100000.0;
|
||||
|
||||
if (blue_x < 0 || blue_x > 0.8 || blue_y < 0 || blue_y > 0.8 ||
|
||||
blue_x + blue_y > 1.0)
|
||||
if (blue_x < (float)0 || blue_x > (float)0.8 || blue_y < (float)0 ||
|
||||
blue_y > (float)0.8 || blue_x + blue_y > (float)1.0)
|
||||
{
|
||||
png_warning(png_ptr, "Invalid cHRM blue point");
|
||||
png_crc_finish(png_ptr, 0);
|
||||
@@ -626,11 +596,116 @@ png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
if (png_crc_finish(png_ptr, 0))
|
||||
return;
|
||||
|
||||
#if defined(PNG_READ_sRGB_SUPPORTED)
|
||||
if (info_ptr->valid & PNG_INFO_sRGB)
|
||||
{
|
||||
if (fabs(white_x - (float).3127) > (float).001 ||
|
||||
fabs(white_y - (float).3290) > (float).001 ||
|
||||
fabs( red_x - (float).6400) > (float).001 ||
|
||||
fabs( red_y - (float).3300) > (float).001 ||
|
||||
fabs(green_x - (float).3000) > (float).001 ||
|
||||
fabs(green_y - (float).6000) > (float).001 ||
|
||||
fabs( blue_x - (float).1500) > (float).001 ||
|
||||
fabs( blue_y - (float).0600) > (float).001)
|
||||
{
|
||||
|
||||
png_warning(png_ptr,
|
||||
"Ignoring incorrect cHRM value when sRGB is also present");
|
||||
#ifndef PNG_NO_STDIO
|
||||
fprintf(stderr,"wx=%f, wy=%f, rx=%f, ry=%f\n",
|
||||
white_x, white_y, red_x, red_y);
|
||||
fprintf(stderr,"gx=%f, gy=%f, bx=%f, by=%f\n",
|
||||
green_x, green_y, blue_x, blue_y);
|
||||
#endif
|
||||
}
|
||||
return;
|
||||
}
|
||||
#endif /* PNG_READ_sRGB_SUPPORTED */
|
||||
|
||||
png_set_cHRM(png_ptr, info_ptr,
|
||||
white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_sRGB_SUPPORTED)
|
||||
void
|
||||
png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
{
|
||||
int intent;
|
||||
png_byte buf[1];
|
||||
|
||||
png_debug(1, "in png_handle_sRGB\n");
|
||||
|
||||
if (!(png_ptr->mode & PNG_HAVE_IHDR))
|
||||
png_error(png_ptr, "Missing IHDR before sRGB");
|
||||
else if (png_ptr->mode & PNG_HAVE_IDAT)
|
||||
{
|
||||
png_warning(png_ptr, "Invalid sRGB after IDAT");
|
||||
png_crc_finish(png_ptr, length);
|
||||
return;
|
||||
}
|
||||
else if (png_ptr->mode & PNG_HAVE_PLTE)
|
||||
/* Should be an error, but we can cope with it */
|
||||
png_warning(png_ptr, "Out of place sRGB chunk");
|
||||
|
||||
else if (info_ptr != NULL && info_ptr->valid & PNG_INFO_sRGB)
|
||||
{
|
||||
png_warning(png_ptr, "Duplicate sRGB chunk");
|
||||
png_crc_finish(png_ptr, length);
|
||||
return;
|
||||
}
|
||||
|
||||
if (length != 1)
|
||||
{
|
||||
png_warning(png_ptr, "Incorrect sRGB chunk length");
|
||||
png_crc_finish(png_ptr, length);
|
||||
return;
|
||||
}
|
||||
|
||||
png_crc_read(png_ptr, buf, 1);
|
||||
if (png_crc_finish(png_ptr, 0))
|
||||
return;
|
||||
|
||||
intent = buf[0];
|
||||
/* check for bad intent */
|
||||
if (intent >= PNG_sRGB_INTENT_LAST)
|
||||
{
|
||||
png_warning(png_ptr, "Unknown sRGB intent");
|
||||
return;
|
||||
}
|
||||
|
||||
#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)
|
||||
{
|
||||
png_warning(png_ptr,
|
||||
"Ignoring incorrect gAMA value when sRGB is also present");
|
||||
#ifndef PNG_NO_STDIO
|
||||
fprintf(stderr,"gamma=%f\n",png_ptr->gamma);
|
||||
#endif
|
||||
}
|
||||
#endif /* PNG_READ_gAMA_SUPPORTED */
|
||||
|
||||
#ifdef PNG_READ_cHRM_SUPPORTED
|
||||
if (info_ptr->valid & PNG_INFO_cHRM)
|
||||
if (fabs(info_ptr->x_white - (float).3127) > (float).001 ||
|
||||
fabs(info_ptr->y_white - (float).3290) > (float).001 ||
|
||||
fabs( info_ptr->x_red - (float).6400) > (float).001 ||
|
||||
fabs( info_ptr->y_red - (float).3300) > (float).001 ||
|
||||
fabs(info_ptr->x_green - (float).3000) > (float).001 ||
|
||||
fabs(info_ptr->y_green - (float).6000) > (float).001 ||
|
||||
fabs( info_ptr->x_blue - (float).1500) > (float).001 ||
|
||||
fabs( info_ptr->y_blue - (float).0600) > (float).001)
|
||||
{
|
||||
png_warning(png_ptr,
|
||||
"Ignoring incorrect cHRM value when sRGB is also present");
|
||||
}
|
||||
#endif /* PNG_READ_cHRM_SUPPORTED */
|
||||
|
||||
png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr, intent);
|
||||
}
|
||||
#endif /* PNG_READ_sRGB_SUPPORTED */
|
||||
|
||||
#if defined(PNG_READ_tRNS_SUPPORTED)
|
||||
void
|
||||
png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
@@ -683,7 +758,7 @@ png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
}
|
||||
|
||||
png_crc_read(png_ptr, buf, (png_size_t)length);
|
||||
png_ptr->num_trans = 3;
|
||||
png_ptr->num_trans = 1;
|
||||
png_ptr->trans_values.red = png_get_uint_16(buf);
|
||||
png_ptr->trans_values.green = png_get_uint_16(buf + 2);
|
||||
png_ptr->trans_values.blue = png_get_uint_16(buf + 4);
|
||||
@@ -1113,11 +1188,11 @@ png_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
png_ptr->mode |= PNG_AFTER_IDAT;
|
||||
|
||||
#ifdef PNG_MAX_MALLOC_64K
|
||||
if (length > 65535L)
|
||||
if (length > (png_uint_32)65535L)
|
||||
{
|
||||
png_warning(png_ptr, "tEXt chunk too large to fit in memory");
|
||||
skip = length - 65535L;
|
||||
length = 65535L;
|
||||
skip = length - (png_uint_32)65535L;
|
||||
length = (png_uint_32)65535L;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1171,7 +1246,7 @@ png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
#ifdef PNG_MAX_MALLOC_64K
|
||||
/* We will no doubt have problems with chunks even half this size, but
|
||||
there is no hard and fast rule to tell us where to stop. */
|
||||
if (length > 65535L)
|
||||
if (length > (png_uint_32)65535L)
|
||||
{
|
||||
png_warning(png_ptr,"zTXt chunk too large to fit in memory");
|
||||
png_crc_finish(png_ptr, length);
|
||||
@@ -1259,7 +1334,7 @@ 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 +
|
||||
text = (png_charp)png_malloc(png_ptr, text_size +
|
||||
png_ptr->zbuf_size - png_ptr->zstream.avail_out + 1);
|
||||
png_memcpy(text, tmp, text_size);
|
||||
png_free(png_ptr, tmp);
|
||||
@@ -1291,10 +1366,14 @@ png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
else /* if (comp_type >= PNG_TEXT_COMPRESSION_LAST) */
|
||||
{
|
||||
png_size_t text_size;
|
||||
#if !defined(PNG_NO_STDIO)
|
||||
char umsg[50];
|
||||
|
||||
sprintf(umsg, "Unknown zTXt compression type %d", comp_type);
|
||||
png_warning(png_ptr, umsg);
|
||||
#else
|
||||
png_warning(png_ptr, "Unknown zTXt compression type");
|
||||
#endif
|
||||
|
||||
/* Copy what we can of the error message into the text chunk */
|
||||
text_size = (png_size_t)length - (text - key) - 1;
|
||||
@@ -1329,10 +1408,7 @@ png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
|
||||
if (!(png_ptr->chunk_name[0] & 0x20))
|
||||
{
|
||||
char msg[40];
|
||||
|
||||
sprintf(msg, "Unknown critical chunk %s", png_ptr->chunk_name);
|
||||
png_error(png_ptr, msg);
|
||||
png_chunk_error(png_ptr, "unknown critical chunk");
|
||||
}
|
||||
|
||||
if (png_ptr->mode & PNG_HAVE_IDAT)
|
||||
@@ -1356,11 +1432,7 @@ png_check_chunk_name(png_structp png_ptr, png_bytep chunk_name)
|
||||
if (isnonalpha(chunk_name[0]) || isnonalpha(chunk_name[1]) ||
|
||||
isnonalpha(chunk_name[2]) || isnonalpha(chunk_name[3]))
|
||||
{
|
||||
char msg[45];
|
||||
|
||||
sprintf(msg, "Invalid chunk type 0x%02X 0x%02X 0x%02X 0x%02X",
|
||||
chunk_name[0], chunk_name[1], chunk_name[2], chunk_name[3]);
|
||||
png_error(png_ptr, msg);
|
||||
png_chunk_error(png_ptr, "invalid chunk type");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2113,13 +2185,13 @@ png_read_start_row(png_structp png_ptr)
|
||||
rowbytes = ((rowbytes * (png_uint_32)max_pixel_depth + 7) >> 3) +
|
||||
1 + ((max_pixel_depth + 7) >> 3);
|
||||
#ifdef PNG_MAX_MALLOC_64K
|
||||
if (rowbytes > 65536L)
|
||||
if (rowbytes > (png_uint_32)65536L)
|
||||
png_error(png_ptr, "This image requires a row greater than 64KB");
|
||||
#endif
|
||||
png_ptr->row_buf = (png_bytep)png_malloc(png_ptr, rowbytes);
|
||||
|
||||
#ifdef PNG_MAX_MALLOC_64K
|
||||
if (png_ptr->rowbytes + 1 > 65536L)
|
||||
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);
|
||||
|
||||
79
pngset.c
79
pngset.c
@@ -1,12 +1,18 @@
|
||||
|
||||
/* pngset.c - storage of image information into info struct
|
||||
|
||||
libpng 1.0 beta 6 - version 0.96
|
||||
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
|
||||
May 12, 1997
|
||||
*/
|
||||
*
|
||||
* libpng 0.99a
|
||||
* 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 31, 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
|
||||
* into the info struct for writing into the file. This abstracts the
|
||||
* info struct and allows us to change the structure in the future.
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
#include "png.h"
|
||||
@@ -205,8 +211,57 @@ png_set_sBIT(png_structp png_ptr, png_infop info_ptr,
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED) || \
|
||||
defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED)
|
||||
#if defined(PNG_READ_sRGB_SUPPORTED) || defined(PNG_WRITE_sRGB_SUPPORTED)
|
||||
void
|
||||
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 = (png_byte)intent;
|
||||
info_ptr->valid |= PNG_INFO_sRGB;
|
||||
}
|
||||
void
|
||||
png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
|
||||
int intent)
|
||||
{
|
||||
#if defined(PNG_READ_gAMA_SUPPORTED) || defined(PNG_WRITE_gAMA_SUPPORTED)
|
||||
float file_gamma;
|
||||
#endif
|
||||
#if defined(PNG_READ_cHRM_SUPPORTED) || defined(PNG_WRITE_cHRM_SUPPORTED)
|
||||
float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
|
||||
#endif
|
||||
png_debug1(1, "in %s storage function\n", "sRGB_gAMA_and_cHRM");
|
||||
if (info_ptr == NULL)
|
||||
return;
|
||||
|
||||
png_set_sRGB(png_ptr, info_ptr, intent);
|
||||
|
||||
#if defined(PNG_READ_gAMA_SUPPORTED) || defined(PNG_WRITE_gAMA_SUPPORTED)
|
||||
file_gamma = (float).45;
|
||||
png_set_gAMA(png_ptr, info_ptr, file_gamma);
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_cHRM_SUPPORTED) || defined(PNG_WRITE_cHRM_SUPPORTED)
|
||||
white_x = (float).3127;
|
||||
white_y = (float).3290;
|
||||
red_x = (float).64;
|
||||
red_y = (float).33;
|
||||
green_x = (float).30;
|
||||
green_y = (float).60;
|
||||
blue_x = (float).15;
|
||||
blue_y = (float).06;
|
||||
|
||||
png_set_cHRM(png_ptr, info_ptr,
|
||||
white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
|
||||
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_WRITE_tEXt_SUPPORTED) || \
|
||||
defined(PNG_READ_zTXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED)
|
||||
void
|
||||
png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
|
||||
int num_text)
|
||||
@@ -214,7 +269,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;
|
||||
@@ -253,7 +308,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')
|
||||
{
|
||||
@@ -304,6 +359,8 @@ png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
|
||||
{
|
||||
png_memcpy(&(info_ptr->trans_values), trans_values,
|
||||
sizeof(png_color_16));
|
||||
if (num_trans == 0)
|
||||
num_trans = 1;
|
||||
}
|
||||
info_ptr->num_trans = (png_uint_16)num_trans;
|
||||
info_ptr->valid |= PNG_INFO_tRNS;
|
||||
|
||||
606
pngtest.c
606
pngtest.c
@@ -1,12 +1,31 @@
|
||||
|
||||
/* pngtest.c - a simple test program to test libpng
|
||||
|
||||
libpng 1.0 beta 6 - version 0.96
|
||||
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
|
||||
May 12, 1997
|
||||
*/
|
||||
*
|
||||
* libpng 0.99a
|
||||
* 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 31, 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
|
||||
* the basic chunk handling, filtering, and (de)compression code is working
|
||||
* properly. It does not currently test all of the transforms, although
|
||||
* it probably should.
|
||||
*
|
||||
* The program will fail in certain legitimate cases:
|
||||
* 1) when the compression level or filter selection method is changed.
|
||||
* 2) when the chunk size is smaller than 8K.
|
||||
* 3) unknown ancillary chunks exist in the input file.
|
||||
* 4) others not listed here...
|
||||
* In these cases, it is best to check with another tool such as "pngcheck"
|
||||
* to see what the differences between the two images are.
|
||||
*
|
||||
* If a filename is given on the command-line, then this file is used
|
||||
* for the input, rather than the default "pngtest.png". This allows
|
||||
* testing a wide variety of files easily.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -18,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
|
||||
@@ -26,21 +52,305 @@
|
||||
/* #define STDERR stderr */
|
||||
#define STDERR stdout /* for DOS */
|
||||
|
||||
/* input and output filenames */
|
||||
#ifdef RISCOS
|
||||
char *inname = "pngtest_png";
|
||||
char *outname = "pngout_png";
|
||||
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. */
|
||||
/* 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;
|
||||
|
||||
/* fread() returns 0 on error, so it is OK to store this in a png_size_t
|
||||
* instead of an int, which is what fread() actually returns.
|
||||
*/
|
||||
check = (png_size_t)fread(data, (png_size_t)1, length,
|
||||
(FILE *)png_ptr->io_ptr);
|
||||
|
||||
if (check != length)
|
||||
{
|
||||
png_error(png_ptr, "Read Error");
|
||||
}
|
||||
}
|
||||
#else
|
||||
char *inname = "pngtest.png";
|
||||
char *outname = "pngout.png";
|
||||
/* this is the model-independent version. Since the standard I/O library
|
||||
can't handle far buffers in the medium and small models, we have to copy
|
||||
the data.
|
||||
*/
|
||||
|
||||
#define NEAR_BUF_SIZE 1024
|
||||
#define MIN(a,b) (a <= b ? a : b)
|
||||
|
||||
static void
|
||||
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)
|
||||
{
|
||||
int check;
|
||||
png_byte *n_data;
|
||||
FILE *io_ptr;
|
||||
|
||||
/* Check if data really is near. If so, use usual code. */
|
||||
n_data = (png_byte *)CVT_PTR_NOCHECK(data);
|
||||
io_ptr = (FILE *)CVT_PTR(png_ptr->io_ptr);
|
||||
if ((png_bytep)n_data == data)
|
||||
{
|
||||
check = fread(n_data, 1, length, io_ptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
png_byte buf[NEAR_BUF_SIZE];
|
||||
png_size_t read, remaining, err;
|
||||
check = 0;
|
||||
remaining = length;
|
||||
do
|
||||
{
|
||||
read = MIN(NEAR_BUF_SIZE, remaining);
|
||||
err = fread(buf, (png_size_t)1, read, io_ptr);
|
||||
png_memcpy(data, buf, read); /* copy far buffer to near buffer */
|
||||
if(err != read)
|
||||
break;
|
||||
else
|
||||
check += err;
|
||||
data += read;
|
||||
remaining -= read;
|
||||
}
|
||||
while (remaining != 0);
|
||||
}
|
||||
if (check != length)
|
||||
{
|
||||
png_error(png_ptr, "read Error");
|
||||
}
|
||||
}
|
||||
#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;
|
||||
io_ptr = (FILE *)CVT_PTR((png_ptr->io_ptr));
|
||||
if (io_ptr != NULL)
|
||||
fflush(io_ptr);
|
||||
}
|
||||
#endif
|
||||
|
||||
char inbuf[256], outbuf[256];
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
/* This is the function which does the actual writing of data. If you are
|
||||
not writing to a standard C stream, you should create a replacement
|
||||
write_data function and use it at run time with png_set_write_fn(), rather
|
||||
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)
|
||||
{
|
||||
FILE *fpin, *fpout;
|
||||
png_uint_32 check;
|
||||
|
||||
check = fwrite(data, 1, length, (FILE *)(png_ptr->io_ptr));
|
||||
if (check != length)
|
||||
{
|
||||
png_error(png_ptr, "Write Error");
|
||||
}
|
||||
}
|
||||
#else
|
||||
/* this is the model-independent version. Since the standard I/O library
|
||||
can't handle far buffers in the medium and small models, we have to copy
|
||||
the data.
|
||||
*/
|
||||
|
||||
#define NEAR_BUF_SIZE 1024
|
||||
#define MIN(a,b) (a <= b ? a : b)
|
||||
|
||||
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;
|
||||
png_byte *near_data; /* Needs to be "png_byte *" instead of "png_bytep" */
|
||||
FILE *io_ptr;
|
||||
|
||||
/* Check if data really is near. If so, use usual code. */
|
||||
near_data = (png_byte *)CVT_PTR_NOCHECK(data);
|
||||
io_ptr = (FILE *)CVT_PTR(png_ptr->io_ptr);
|
||||
if ((png_bytep)near_data == data)
|
||||
{
|
||||
check = fwrite(near_data, 1, length, io_ptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
png_byte buf[NEAR_BUF_SIZE];
|
||||
png_size_t written, remaining, err;
|
||||
check = 0;
|
||||
remaining = length;
|
||||
do
|
||||
{
|
||||
written = MIN(NEAR_BUF_SIZE, remaining);
|
||||
png_memcpy(buf, data, written); /* copy far buffer to near buffer */
|
||||
err = fwrite(buf, 1, written, io_ptr);
|
||||
if (err != written)
|
||||
break;
|
||||
else
|
||||
check += err;
|
||||
data += written;
|
||||
remaining -= written;
|
||||
}
|
||||
while (remaining != 0);
|
||||
}
|
||||
if (check != length)
|
||||
{
|
||||
png_error(png_ptr, "Write Error");
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* 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
|
||||
* here if you don't want to. In the default configuration, png_ptr is
|
||||
* not used, but it is passed in case it may be useful.
|
||||
*/
|
||||
static void
|
||||
png_default_warning(png_structp png_ptr, png_const_charp message)
|
||||
{
|
||||
PNG_CONST char *name = "UNKNOWN (ERROR!)";
|
||||
if (png_ptr != NULL && png_ptr->error_ptr != NULL)
|
||||
name = png_ptr->error_ptr;
|
||||
fprintf(STDERR, "%s: libpng warning: %s\n", name, message);
|
||||
}
|
||||
|
||||
/* This is the default error handling function. Note that replacements for
|
||||
* this function MUST NOT RETURN, or the program will likely crash. This
|
||||
* function is used by default, or if the program supplies NULL for the
|
||||
* error function pointer in png_set_error_fn().
|
||||
*/
|
||||
static void
|
||||
png_default_error(png_structp png_ptr, png_const_charp message)
|
||||
{
|
||||
png_default_warning(png_ptr, message);
|
||||
/* We can return because png_error calls the default handler which is
|
||||
* actually ok in this case. */
|
||||
}
|
||||
#endif /* PNG_NO_STDIO */
|
||||
/* END of code to validate stdio-free compilation */
|
||||
|
||||
/* 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 (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)
|
||||
{
|
||||
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;
|
||||
@@ -51,51 +361,40 @@ main(int argc, char *argv[])
|
||||
#ifdef USE_FAR_KEYWORD
|
||||
jmp_buf jmpbuf;
|
||||
#endif
|
||||
|
||||
char inbuf[256], outbuf[256];
|
||||
|
||||
row_buf = (png_bytep)NULL;
|
||||
|
||||
fprintf(STDERR, "Testing libpng version %s\n", PNG_LIBPNG_VER_STRING);
|
||||
|
||||
if (strcmp(png_libpng_ver, PNG_LIBPNG_VER_STRING))
|
||||
{
|
||||
fprintf(STDERR,
|
||||
"Warning: versions are different between png.h and png.c\n");
|
||||
fprintf(STDERR, " png.h version: %s\n", PNG_LIBPNG_VER_STRING);
|
||||
fprintf(STDERR, " png.c version: %s\n\n", png_libpng_ver);
|
||||
}
|
||||
|
||||
if (argc > 1)
|
||||
inname = argv[1];
|
||||
|
||||
if (argc > 2)
|
||||
outname = argv[2];
|
||||
|
||||
if (argc > 3)
|
||||
{
|
||||
fprintf(stderr, "usage: %s [infile.png] [outfile.png]\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
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);
|
||||
#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);
|
||||
#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");
|
||||
@@ -105,12 +404,12 @@ main(int argc, char *argv[])
|
||||
if (setjmp(read_ptr->jmpbuf))
|
||||
#endif
|
||||
{
|
||||
fprintf(STDERR, "libpng read error\n");
|
||||
fprintf(STDERR, "%s -> %s: libpng read error\n", inname, outname);
|
||||
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);
|
||||
return 1;
|
||||
return (1);
|
||||
}
|
||||
|
||||
png_debug(0, "Setting jmpbuf for write struct\n");
|
||||
@@ -121,20 +420,30 @@ main(int argc, char *argv[])
|
||||
if (setjmp(write_ptr->jmpbuf))
|
||||
#endif
|
||||
{
|
||||
fprintf(STDERR, "libpng write error\n");
|
||||
fprintf(STDERR, "%s -> %s: libpng write error\n", inname, outname);
|
||||
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);
|
||||
return 1;
|
||||
return (1);
|
||||
}
|
||||
|
||||
#ifdef USE_FAR_KEYWORD
|
||||
png_memcpy(write_ptr->jmpbuf,jmpbuf,sizeof(jmp_buf));
|
||||
#endif
|
||||
png_debug(0, "Initializing input and output streams\n");
|
||||
#if !defined(PNG_NO_STDIO)
|
||||
png_init_io(read_ptr, fpin);
|
||||
png_init_io(write_ptr, fpout);
|
||||
#else
|
||||
png_set_read_fn(read_ptr, (png_voidp)fpin, png_default_read_data);
|
||||
png_set_write_fn(write_ptr, (png_voidp)fpout, png_default_write_data,
|
||||
#if defined(PNG_WRITE_FLUSH_SUPPORTED)
|
||||
png_default_flush);
|
||||
#else
|
||||
NULL);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
png_debug(0, "Reading info struct\n");
|
||||
png_read_info(read_ptr, read_info_ptr);
|
||||
@@ -147,7 +456,11 @@ main(int argc, char *argv[])
|
||||
&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)
|
||||
@@ -182,6 +495,16 @@ main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if defined(PNG_READ_sRGB_SUPPORTED) && defined(PNG_WRITE_sRGB_SUPPORTED)
|
||||
{
|
||||
int intent;
|
||||
|
||||
if (png_get_sRGB(read_ptr, read_info_ptr, &intent))
|
||||
{
|
||||
png_set_sRGB(write_ptr, write_info_ptr, intent);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if defined(PNG_READ_hIST_SUPPORTED) && defined(PNG_WRITE_hIST_SUPPORTED)
|
||||
{
|
||||
png_uint_16p hist;
|
||||
@@ -298,7 +621,7 @@ main(int argc, char *argv[])
|
||||
png_destroy_write_struct(&write_ptr, &write_info_ptr);
|
||||
fclose(fpin);
|
||||
fclose(fpout);
|
||||
return 1;
|
||||
return (1);
|
||||
}
|
||||
|
||||
num_pass = png_set_interlace_handling(read_ptr);
|
||||
@@ -316,28 +639,38 @@ main(int argc, char *argv[])
|
||||
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)
|
||||
@@ -353,7 +686,7 @@ main(int argc, char *argv[])
|
||||
inname, outname);
|
||||
fclose(fpin);
|
||||
fclose(fpout);
|
||||
return 1;
|
||||
return (1);
|
||||
}
|
||||
|
||||
if (!num_in)
|
||||
@@ -364,14 +697,175 @@ main(int argc, char *argv[])
|
||||
fprintf(STDERR, "Files %s and %s are different\n", inname, outname);
|
||||
fclose(fpin);
|
||||
fclose(fpout);
|
||||
return 1;
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
|
||||
fclose(fpin);
|
||||
fclose(fpout);
|
||||
fprintf(STDERR, "libpng passes test\n");
|
||||
|
||||
return 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* input and output filenames */
|
||||
#ifdef RISCOS
|
||||
PNG_CONST char *inname = "pngtest_png";
|
||||
PNG_CONST char *outname = "pngout_png";
|
||||
#else
|
||||
static char *inname = "pngtest.png";
|
||||
static char *outname = "pngout.png";
|
||||
#endif
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int multiple = 0;
|
||||
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))
|
||||
{
|
||||
fprintf(STDERR,
|
||||
"Warning: versions are different between png.h and png.c\n");
|
||||
fprintf(STDERR, " png.h version: %s\n", PNG_LIBPNG_VER_STRING);
|
||||
fprintf(STDERR, " png.c version: %s\n\n", png_libpng_ver);
|
||||
++ierror;
|
||||
}
|
||||
|
||||
if (argc > 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+verbose)
|
||||
outname = argv[2+verbose];
|
||||
|
||||
if ((!multiple && argc > 3+verbose) || (multiple && argc < 2))
|
||||
{
|
||||
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);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (multiple)
|
||||
{
|
||||
int i;
|
||||
#ifdef PNGTEST_MEMORY_DEBUG
|
||||
int allocation_now = current_allocation;
|
||||
#endif
|
||||
for (i=2; i<argc; ++i)
|
||||
{
|
||||
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
|
||||
{
|
||||
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 ((int)(ierror != 0));
|
||||
}
|
||||
|
||||
34
pngtrans.c
34
pngtrans.c
@@ -1,12 +1,13 @@
|
||||
|
||||
/* pngtrans.c - transforms the data in a row (used by both readers and writers)
|
||||
|
||||
libpng 1.0 beta 6 - version 0.96
|
||||
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
|
||||
May 12, 1997
|
||||
*/
|
||||
*
|
||||
* libpng 0.99a
|
||||
* 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 31, 1998
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
#include "png.h"
|
||||
@@ -67,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)
|
||||
{
|
||||
@@ -75,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
|
||||
|
||||
@@ -117,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)
|
||||
@@ -288,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)
|
||||
{
|
||||
|
||||
40
pngwio.c
40
pngwio.c
@@ -1,18 +1,20 @@
|
||||
|
||||
/* pngwio.c - functions for data output
|
||||
|
||||
libpng 1.0 beta 6 - version 0.96
|
||||
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
|
||||
May 12, 1997
|
||||
|
||||
This file provides a location for all output. Users which need
|
||||
special handling are expected to write functions which have the same
|
||||
arguments as these, and perform similar functions, but possibly use
|
||||
different output methods. Note that you shouldn't change these
|
||||
functions, but rather write replacement functions and then change
|
||||
them at run time with png_set_write_fn(...) */
|
||||
*
|
||||
* libpng 0.99a
|
||||
* 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 31, 1998
|
||||
*
|
||||
* This file provides a location for all output. Users which need
|
||||
* special handling are expected to write functions which have the same
|
||||
* arguments as these, and perform similar functions, but possibly use
|
||||
* different output methods. Note that you shouldn't change these
|
||||
* functions, but rather write replacement functions and then change
|
||||
* them at run time with png_set_write_fn(...).
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
#include "png.h"
|
||||
@@ -32,6 +34,7 @@ png_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
png_error(png_ptr, "Call to NULL write function");
|
||||
}
|
||||
|
||||
#if !defined(PNG_NO_STDIO)
|
||||
/* This is the function which does the actual writing of data. If you are
|
||||
not writing to a standard C stream, you should create a replacement
|
||||
write_data function and use it at run time with png_set_write_fn(), rather
|
||||
@@ -97,6 +100,7 @@ png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* This function is called to output any data pending writing (normally
|
||||
@@ -110,6 +114,7 @@ png_flush(png_structp png_ptr)
|
||||
(*(png_ptr->output_flush_fn))(png_ptr);
|
||||
}
|
||||
|
||||
#if !defined(PNG_NO_STDIO)
|
||||
static void
|
||||
png_default_flush(png_structp png_ptr)
|
||||
{
|
||||
@@ -119,6 +124,7 @@ png_default_flush(png_structp png_ptr)
|
||||
fflush(io_ptr);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* This function allows the application to supply new output functions for
|
||||
libpng if standard C streams aren't being used.
|
||||
@@ -148,16 +154,24 @@ png_set_write_fn(png_structp png_ptr, png_voidp io_ptr,
|
||||
{
|
||||
png_ptr->io_ptr = io_ptr;
|
||||
|
||||
#if !defined(PNG_NO_STDIO)
|
||||
if (write_data_fn != NULL)
|
||||
png_ptr->write_data_fn = write_data_fn;
|
||||
else
|
||||
png_ptr->write_data_fn = png_default_write_data;
|
||||
#else
|
||||
png_ptr->write_data_fn = write_data_fn;
|
||||
#endif
|
||||
|
||||
#if defined(PNG_WRITE_FLUSH_SUPPORTED)
|
||||
#if !defined(PNG_NO_STDIO)
|
||||
if (output_flush_fn != NULL)
|
||||
png_ptr->output_flush_fn = output_flush_fn;
|
||||
else
|
||||
png_ptr->output_flush_fn = png_default_flush;
|
||||
#else
|
||||
png_ptr->output_flush_fn = output_flush_fn;
|
||||
#endif
|
||||
#endif /* PNG_WRITE_FLUSH_SUPPORTED */
|
||||
|
||||
/* It is an error to read while writing a png file */
|
||||
|
||||
159
pngwrite.c
159
pngwrite.c
@@ -1,12 +1,13 @@
|
||||
|
||||
/* pngwrite.c - general routines to write a PNG file
|
||||
|
||||
libpng 1.0 beta 6 - version 0.96
|
||||
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
|
||||
May 12, 1997
|
||||
*/
|
||||
*
|
||||
* libpng 0.99a
|
||||
* 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 31, 1998
|
||||
*/
|
||||
|
||||
/* get internal access to png.h */
|
||||
#define PNG_INTERNAL
|
||||
@@ -24,20 +25,31 @@
|
||||
void
|
||||
png_write_info(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
#if defined(PNG_WRITE_tEXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED)
|
||||
int i;
|
||||
#endif
|
||||
|
||||
png_debug(1, "in png_write_info\n");
|
||||
png_write_sig(png_ptr); /* write PNG signature */
|
||||
/* 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)
|
||||
if (info_ptr->valid & PNG_INFO_gAMA)
|
||||
png_write_gAMA(png_ptr, info_ptr->gamma);
|
||||
#endif
|
||||
#if defined(PNG_WRITE_sRGB_SUPPORTED)
|
||||
if (info_ptr->valid & PNG_INFO_sRGB)
|
||||
png_write_sRGB(png_ptr, (int)info_ptr->srgb_intent);
|
||||
#endif
|
||||
#if defined(PNG_WRITE_sBIT_SUPPORTED)
|
||||
if (info_ptr->valid & PNG_INFO_sBIT)
|
||||
png_write_sBIT(png_ptr, &(info_ptr->sig_bit), info_ptr->color_type);
|
||||
@@ -55,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<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)
|
||||
@@ -128,9 +153,10 @@ png_write_info(png_structp png_ptr, png_infop info_ptr)
|
||||
}
|
||||
|
||||
/* Writes the end of the PNG file. If you don't want to write comments or
|
||||
time information, you can pass NULL for info. If you already wrote these
|
||||
in png_write_info(), do not write them again here. If you have long
|
||||
comments, I suggest writing them here, and compressing them. */
|
||||
* time information, you can pass NULL for info. If you already wrote these
|
||||
* in png_write_info(), do not write them again here. If you have long
|
||||
* comments, I suggest writing them here, and compressing them.
|
||||
*/
|
||||
void
|
||||
png_write_end(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
@@ -141,7 +167,9 @@ png_write_end(png_structp png_ptr, png_infop info_ptr)
|
||||
/* see if user wants us to write information chunks */
|
||||
if (info_ptr != NULL)
|
||||
{
|
||||
#if defined(PNG_WRITE_tEXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED)
|
||||
int i; /* local index variable */
|
||||
#endif
|
||||
#if defined(PNG_WRITE_tIME_SUPPORTED)
|
||||
/* check to see if user has supplied a time chunk */
|
||||
if (info_ptr->valid & PNG_INFO_tIME &&
|
||||
@@ -190,6 +218,41 @@ png_write_end(png_structp png_ptr, png_infop info_ptr)
|
||||
png_write_IEND(png_ptr);
|
||||
}
|
||||
|
||||
#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_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));
|
||||
}
|
||||
|
||||
#ifdef USE_FAR_KEYWORD
|
||||
{
|
||||
char near_time_buf[29];
|
||||
sprintf(near_time_buf, "%d %s %d %02d:%02d:%02d +0000",
|
||||
ptime->day % 31, short_months[ptime->month],
|
||||
ptime->year, ptime->hour % 24, ptime->minute % 60,
|
||||
ptime->second % 61);
|
||||
png_memcpy(png_ptr->time_buffer, near_time_buf,
|
||||
29*sizeof(char));
|
||||
}
|
||||
#else
|
||||
sprintf(png_ptr->time_buffer, "%d %s %d %02d:%02d:%02d +0000",
|
||||
ptime->day % 31, short_months[ptime->month],
|
||||
ptime->year, ptime->hour % 24, ptime->minute % 60,
|
||||
ptime->second % 61);
|
||||
#endif
|
||||
return ((png_charp)png_ptr->time_buffer);
|
||||
}
|
||||
#endif /* PNG_TIME_RFC1123_SUPPORTED */
|
||||
|
||||
#if defined(PNG_WRITE_tIME_SUPPORTED)
|
||||
void
|
||||
png_convert_from_struct_tm(png_timep ptime, struct tm FAR * ttime)
|
||||
@@ -226,7 +289,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))
|
||||
@@ -236,7 +299,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));
|
||||
@@ -257,11 +320,16 @@ 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_ptr->zbuf_size);
|
||||
|
||||
png_set_write_fn(png_ptr, NULL, NULL, NULL);
|
||||
|
||||
return (png_ptr);
|
||||
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
|
||||
png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
|
||||
1, NULL, NULL);
|
||||
#endif
|
||||
|
||||
return ((png_structp)png_ptr);
|
||||
}
|
||||
|
||||
|
||||
@@ -283,7 +351,7 @@ 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_ptr->zbuf_size);
|
||||
png_set_write_fn(png_ptr, NULL, NULL, NULL);
|
||||
|
||||
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
|
||||
@@ -292,10 +360,11 @@ png_write_init(png_structp png_ptr)
|
||||
#endif
|
||||
}
|
||||
|
||||
/* write a few rows of image data. If the image is interlaced,
|
||||
either you will have to write the 7 sub images, or, if you
|
||||
have called png_set_interlace_handling(), you will have to
|
||||
"write" the image seven times */
|
||||
/* Write a few rows of image data. If the image is interlaced,
|
||||
* either you will have to write the 7 sub images, or, if you
|
||||
* have called png_set_interlace_handling(), you will have to
|
||||
* "write" the image seven times.
|
||||
*/
|
||||
void
|
||||
png_write_rows(png_structp png_ptr, png_bytepp row,
|
||||
png_uint_32 num_rows)
|
||||
@@ -311,8 +380,9 @@ png_write_rows(png_structp png_ptr, png_bytepp row,
|
||||
}
|
||||
}
|
||||
|
||||
/* write the image. You only need to call this function once, even
|
||||
if you are writing an interlaced image. */
|
||||
/* Write the image. You only need to call this function once, even
|
||||
* if you are writing an interlaced image.
|
||||
*/
|
||||
void
|
||||
png_write_image(png_structp png_ptr, png_bytepp image)
|
||||
{
|
||||
@@ -321,9 +391,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++)
|
||||
{
|
||||
@@ -339,7 +413,8 @@ png_write_image(png_structp png_ptr, png_bytepp image)
|
||||
void
|
||||
png_write_row(png_structp png_ptr, png_bytep row)
|
||||
{
|
||||
png_debug(1, "in png_write_row\n");
|
||||
png_debug2(1, "in png_write_row (row %ld, pass %d)\n",
|
||||
png_ptr->row_number, png_ptr->pass);
|
||||
/* initialize transformations and other stuff if first time */
|
||||
if (png_ptr->row_number == 0 && png_ptr->pass == 0)
|
||||
{
|
||||
@@ -415,12 +490,12 @@ png_write_row(png_structp png_ptr, png_bytep row)
|
||||
png_ptr->row_info.rowbytes = ((png_ptr->row_info.width *
|
||||
(png_uint_32)png_ptr->row_info.pixel_depth + 7) >> 3);
|
||||
|
||||
png_debug1(4, "row_info->color_type = %d\n", png_ptr->row_info.color_type);
|
||||
png_debug1(4, "row_info->width = %d\n", png_ptr->row_info.width);
|
||||
png_debug1(4, "row_info->channels = %d\n", png_ptr->row_info.channels);
|
||||
png_debug1(4, "row_info->bit_depth = %d\n", png_ptr->row_info.bit_depth);
|
||||
png_debug1(4, "row_info->pixel_depth = %d\n", png_ptr->row_info.pixel_depth);
|
||||
png_debug1(4, "row_info->rowbytes = %d\n", png_ptr->row_info.rowbytes);
|
||||
png_debug1(3, "row_info->color_type = %d\n", png_ptr->row_info.color_type);
|
||||
png_debug1(3, "row_info->width = %d\n", png_ptr->row_info.width);
|
||||
png_debug1(3, "row_info->channels = %d\n", png_ptr->row_info.channels);
|
||||
png_debug1(3, "row_info->bit_depth = %d\n", png_ptr->row_info.bit_depth);
|
||||
png_debug1(3, "row_info->pixel_depth = %d\n", png_ptr->row_info.pixel_depth);
|
||||
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);
|
||||
@@ -527,6 +602,22 @@ png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)
|
||||
|
||||
if (info_ptr != NULL)
|
||||
{
|
||||
#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 < 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;
|
||||
}
|
||||
@@ -561,6 +652,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_RFC1123_SUPPORTED)
|
||||
png_free(png_ptr, png_ptr->time_buffer);
|
||||
#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);
|
||||
@@ -664,7 +758,7 @@ png_set_filter(png_structp png_ptr, int method, int filters)
|
||||
}
|
||||
else
|
||||
{
|
||||
png_ptr->paeth_row = (png_bytep )png_malloc(png_ptr,
|
||||
png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
|
||||
png_ptr->rowbytes + 1);
|
||||
png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
|
||||
}
|
||||
@@ -683,14 +777,17 @@ png_set_filter(png_structp png_ptr, int method, int filters)
|
||||
* differences metric is relatively fast and effective, there is some
|
||||
* question as to whether it can be improved upon by trying to keep the
|
||||
* filtered data going to zlib more consistent, hopefully resulting in
|
||||
* better compression. */
|
||||
* better compression.
|
||||
*/
|
||||
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* GRR 970116 */
|
||||
void
|
||||
png_set_filter_heuristics(png_structp png_ptr, int heuristic_method,
|
||||
int num_weights, png_doublep filter_weights,
|
||||
png_doublep filter_costs)
|
||||
{
|
||||
#if defined(PNG_WRITE_tEXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED)
|
||||
int i;
|
||||
#endif
|
||||
|
||||
png_debug(1, "in png_set_filter_heuristics\n");
|
||||
if (heuristic_method >= PNG_FILTER_HEURISTIC_LAST)
|
||||
|
||||
128
pngwtran.c
128
pngwtran.c
@@ -1,18 +1,20 @@
|
||||
|
||||
/* pngwtran.c - transforms the data in a row for PNG writers
|
||||
|
||||
libpng 1.0 beta 6 - version 0.96
|
||||
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
|
||||
May 12, 1997
|
||||
*/
|
||||
*
|
||||
* libpng 0.99a
|
||||
* 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 31, 1998
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
#include "png.h"
|
||||
|
||||
/* transform the data according to the users wishes. The order of
|
||||
transformations is significant. */
|
||||
/* Transform the data according to the users wishes. The order of
|
||||
* transformations is significant.
|
||||
*/
|
||||
void
|
||||
png_do_write_transformations(png_structp png_ptr)
|
||||
{
|
||||
@@ -22,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,
|
||||
@@ -40,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);
|
||||
@@ -51,9 +61,10 @@ png_do_write_transformations(png_structp png_ptr)
|
||||
}
|
||||
|
||||
#if defined(PNG_WRITE_PACK_SUPPORTED)
|
||||
/* pack pixels into bytes. Pass the true bit depth in bit_depth. The
|
||||
row_info bit depth should be 8 (one pixel per byte). The channels
|
||||
should be 1 (this only happens on grayscale and paletted images) */
|
||||
/* Pack pixels into bytes. Pass the true bit depth in bit_depth. The
|
||||
* row_info bit depth should be 8 (one pixel per byte). The channels
|
||||
* should be 1 (this only happens on grayscale and paletted images).
|
||||
*/
|
||||
void
|
||||
png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth)
|
||||
{
|
||||
@@ -169,12 +180,13 @@ png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth)
|
||||
#endif
|
||||
|
||||
#if defined(PNG_WRITE_SHIFT_SUPPORTED)
|
||||
/* shift pixel values to take advantage of whole range. Pass the
|
||||
true number of bits in bit_depth. The row should be packed
|
||||
according to row_info->bit_depth. Thus, if you had a row of
|
||||
bit depth 4, but the pixels only had values from 0 to 7, you
|
||||
would pass 3 as bit_depth, and this routine would translate the
|
||||
data to 0 to 15. */
|
||||
/* Shift pixel values to take advantage of whole range. Pass the
|
||||
* true number of bits in bit_depth. The row should be packed
|
||||
* according to row_info->bit_depth. Thus, if you had a row of
|
||||
* bit depth 4, but the pixels only had values from 0 to 7, you
|
||||
* would pass 3 as bit_depth, and this routine would translate the
|
||||
* data to 0 to 15.
|
||||
*/
|
||||
void
|
||||
png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
|
||||
{
|
||||
@@ -252,7 +264,7 @@ png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
|
||||
|
||||
for (bp = row, i = 0; i < row_info->width; i++)
|
||||
{
|
||||
int c;
|
||||
png_uint_32 c;
|
||||
|
||||
for (c = 0; c < channels; c++, bp++)
|
||||
{
|
||||
@@ -278,7 +290,7 @@ png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
|
||||
|
||||
for (bp = row, i = 0; i < row_info->width * row_info->channels; i++)
|
||||
{
|
||||
int c;
|
||||
png_uint_32 c;
|
||||
|
||||
for (c = 0; c < channels; c++, bp += 2)
|
||||
{
|
||||
@@ -390,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
|
||||
|
||||
208
pngwutil.c
208
pngwutil.c
@@ -1,12 +1,13 @@
|
||||
|
||||
/* pngwutil.c - utilities to write a PNG file
|
||||
|
||||
libpng 1.0 beta 6 - version 0.96
|
||||
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
|
||||
May 12, 1997
|
||||
*/
|
||||
*
|
||||
* libpng 0.99a
|
||||
* 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 31, 1998
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
#include "png.h"
|
||||
@@ -26,8 +27,9 @@ png_save_uint_32(png_bytep buf, png_uint_32 i)
|
||||
|
||||
#if defined(PNG_WRITE_pCAL_SUPPORTED)
|
||||
/* The png_save_int_32 function assumes integers are stored in two's
|
||||
complement format. If this isn't the case, then this routine needs to
|
||||
be modified to write data in two's complement format. */
|
||||
* complement format. If this isn't the case, then this routine needs to
|
||||
* be modified to write data in two's complement format.
|
||||
*/
|
||||
void
|
||||
png_save_int_32(png_bytep buf, png_int_32 i)
|
||||
{
|
||||
@@ -38,22 +40,26 @@ png_save_int_32(png_bytep buf, png_int_32 i)
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Place a 16-bit number into a buffer in PNG byte order. */
|
||||
/* Place a 16-bit number into a buffer in PNG byte order.
|
||||
* The parameter is declared unsigned int, not png_uint_16,
|
||||
* just to avoid potential problems on pre-ANSI C compilers.
|
||||
*/
|
||||
void
|
||||
png_save_uint_16(png_bytep buf, png_uint_16 i)
|
||||
png_save_uint_16(png_bytep buf, unsigned int i)
|
||||
{
|
||||
buf[0] = (png_byte)((i >> 8) & 0xff);
|
||||
buf[1] = (png_byte)(i & 0xff);
|
||||
}
|
||||
|
||||
/* Write a PNG chunk all at once. The type is an array of ASCII characters
|
||||
representing the chunk name. The array must be at least 4 bytes in
|
||||
length, and does not need to be null terminated. To be safe, pass the
|
||||
pre-defined chunk names here, and if you need a new one, define it
|
||||
where the others are defined. The length is the length of the data.
|
||||
All the data must be present. If that is not possible, use the
|
||||
png_write_chunk_start(), png_write_chunk_data(), and png_write_chunk_end()
|
||||
functions instead. */
|
||||
* representing the chunk name. The array must be at least 4 bytes in
|
||||
* length, and does not need to be null terminated. To be safe, pass the
|
||||
* pre-defined chunk names here, and if you need a new one, define it
|
||||
* where the others are defined. The length is the length of the data.
|
||||
* All the data must be present. If that is not possible, use the
|
||||
* png_write_chunk_start(), png_write_chunk_data(), and png_write_chunk_end()
|
||||
* functions instead.
|
||||
*/
|
||||
void
|
||||
png_write_chunk(png_structp png_ptr, png_bytep chunk_name,
|
||||
png_bytep data, png_size_t length)
|
||||
@@ -64,8 +70,9 @@ png_write_chunk(png_structp png_ptr, png_bytep chunk_name,
|
||||
}
|
||||
|
||||
/* Write the start of a PNG chunk. The type is the chunk type.
|
||||
The total_length is the sum of the lengths of all the data you will be
|
||||
passing in png_write_chunk_data() */
|
||||
* The total_length is the sum of the lengths of all the data you will be
|
||||
* passing in png_write_chunk_data().
|
||||
*/
|
||||
void
|
||||
png_write_chunk_start(png_structp png_ptr, png_bytep chunk_name,
|
||||
png_uint_32 length)
|
||||
@@ -85,9 +92,10 @@ png_write_chunk_start(png_structp png_ptr, png_bytep chunk_name,
|
||||
}
|
||||
|
||||
/* Write the data of a PNG chunk started with png_write_chunk_start().
|
||||
Note that multiple calls to this function are allowed, and that the
|
||||
sum of the lengths from these calls *must* add up to the total_length
|
||||
given to png_write_chunk_start(). */
|
||||
* Note that multiple calls to this function are allowed, and that the
|
||||
* sum of the lengths from these calls *must* add up to the total_length
|
||||
* given to png_write_chunk_start().
|
||||
*/
|
||||
void
|
||||
png_write_chunk_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
{
|
||||
@@ -106,11 +114,7 @@ png_write_chunk_end(png_structp png_ptr)
|
||||
png_byte buf[4];
|
||||
|
||||
/* write the crc */
|
||||
#ifdef PNG_USE_OWN_CRC
|
||||
png_save_uint_32(buf, ~png_ptr->crc);
|
||||
#else
|
||||
png_save_uint_32(buf, png_ptr->crc);
|
||||
#endif
|
||||
|
||||
png_write_data(png_ptr, buf, (png_size_t)4);
|
||||
}
|
||||
@@ -119,7 +123,8 @@ png_write_chunk_end(png_structp png_ptr)
|
||||
* the magic bytes of the signature, or more likely, the PNG stream is
|
||||
* being embedded into another stream and doesn't need its own signature,
|
||||
* we should call png_set_sig_bytes() to tell libpng how many of the
|
||||
* bytes have already been written. */
|
||||
* bytes have already been written.
|
||||
*/
|
||||
void
|
||||
png_write_sig(png_structp png_ptr)
|
||||
{
|
||||
@@ -129,8 +134,9 @@ png_write_sig(png_structp png_ptr)
|
||||
}
|
||||
|
||||
/* Write the IHDR chunk, and update the png_struct with the necessary
|
||||
information. Note that the rest of this code depends upon this
|
||||
information being correct. */
|
||||
* information. Note that the rest of this code depends upon this
|
||||
* information being correct.
|
||||
*/
|
||||
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,
|
||||
@@ -194,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;
|
||||
@@ -264,8 +274,9 @@ png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height,
|
||||
}
|
||||
|
||||
/* write the palette. We are careful not to trust png_color to be in the
|
||||
correct order for PNG, so people can redefine it to any convient
|
||||
structure. */
|
||||
* correct order for PNG, so people can redefine it to any convient
|
||||
* structure.
|
||||
*/
|
||||
void
|
||||
png_write_PLTE(png_structp png_ptr, png_colorp palette, png_uint_32 num_pal)
|
||||
{
|
||||
@@ -336,6 +347,22 @@ png_write_gAMA(png_structp png_ptr, double file_gamma)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_WRITE_sRGB_SUPPORTED)
|
||||
/* write a sRGB chunk */
|
||||
void
|
||||
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 >= PNG_sRGB_INTENT_LAST)
|
||||
png_warning(png_ptr,
|
||||
"Invalid sRGB rendering intent specified");
|
||||
buf[0]=(png_byte)srgb_intent;
|
||||
png_write_chunk(png_ptr, png_sRGB, buf, (png_size_t)1);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_WRITE_sBIT_SUPPORTED)
|
||||
/* write the sBIT chunk */
|
||||
void
|
||||
@@ -483,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
|
||||
@@ -560,11 +587,10 @@ png_write_hIST(png_structp png_ptr, png_uint_16p hist, png_uint_32 num_hist)
|
||||
* static keywords without having to have duplicate copies of the strings.
|
||||
*/
|
||||
png_size_t
|
||||
png_check_keyword(png_structp png_ptr, png_charp key, png_bytepp new_key)
|
||||
png_check_keyword(png_structp png_ptr, png_charp key, png_charpp new_key)
|
||||
{
|
||||
png_size_t key_len;
|
||||
png_charp kp;
|
||||
png_bytep dp;
|
||||
png_charp kp, dp;
|
||||
int kflag;
|
||||
|
||||
png_debug(1, "in png_check_keyword\n");
|
||||
@@ -572,27 +598,27 @@ png_check_keyword(png_structp png_ptr, png_charp key, png_bytepp new_key)
|
||||
|
||||
if (key == NULL || (key_len = png_strlen(key)) == 0)
|
||||
{
|
||||
char msg[40];
|
||||
|
||||
sprintf(msg, "Zero length %s keyword", png_ptr->chunk_name);
|
||||
png_warning(png_ptr, msg);
|
||||
return 0;
|
||||
png_chunk_warning(png_ptr, "zero length keyword");
|
||||
return ((png_size_t)0);
|
||||
}
|
||||
|
||||
png_debug1(2, "Keyword to be checked is '%s'\n", key);
|
||||
|
||||
*new_key = (png_bytep)png_malloc(png_ptr, key_len + 1);
|
||||
*new_key = (png_charp)png_malloc(png_ptr, key_len + 1);
|
||||
|
||||
/* Replace non-printing characters with a blank and print a warning */
|
||||
for (kp = key, dp = *new_key; *kp != '\0'; kp++, dp++)
|
||||
{
|
||||
if (*kp < 0x20 || ((png_byte)*kp > 0x7E && (png_byte)*kp < 0xA1))
|
||||
if (*kp < 0x20 || (*kp > 0x7E && (png_byte)*kp < 0xA1))
|
||||
{
|
||||
#if !defined(PNG_NO_STDIO)
|
||||
char msg[40];
|
||||
|
||||
sprintf(msg, "Invalid %s keyword character 0x%02X",
|
||||
png_ptr->chunk_name, *kp);
|
||||
png_warning(png_ptr, msg);
|
||||
sprintf(msg, "invalid keyword character 0x%02X", *kp);
|
||||
png_chunk_warning(png_ptr, msg);
|
||||
#else
|
||||
png_chunk_warning(png_ptr, "invalid character in keyword");
|
||||
#endif
|
||||
*dp = ' ';
|
||||
}
|
||||
else
|
||||
@@ -606,11 +632,7 @@ png_check_keyword(png_structp png_ptr, png_charp key, png_bytepp new_key)
|
||||
kp = *new_key + key_len - 1;
|
||||
if (*kp == ' ')
|
||||
{
|
||||
char msg[50];
|
||||
sprintf(msg, "Trailing spaces removed from %s keyword",
|
||||
png_ptr->chunk_name);
|
||||
|
||||
png_warning(png_ptr, msg);
|
||||
png_chunk_warning(png_ptr, "trailing spaces removed from keyword");
|
||||
|
||||
while (*kp == ' ')
|
||||
{
|
||||
@@ -623,11 +645,7 @@ png_check_keyword(png_structp png_ptr, png_charp key, png_bytepp new_key)
|
||||
kp = *new_key;
|
||||
if (*kp == ' ')
|
||||
{
|
||||
char msg[50];
|
||||
sprintf(msg, "Leading spaces removed from %s keyword",
|
||||
png_ptr->chunk_name);
|
||||
|
||||
png_warning(png_ptr, msg);
|
||||
png_chunk_warning(png_ptr, "leading spaces removed from keyword");
|
||||
|
||||
while (*kp == ' ')
|
||||
{
|
||||
@@ -660,24 +678,17 @@ png_check_keyword(png_structp png_ptr, png_charp key, png_bytepp new_key)
|
||||
|
||||
if (key_len == 0)
|
||||
{
|
||||
char msg[40];
|
||||
|
||||
sprintf(msg, "Zero length %s keyword", png_ptr->chunk_name);
|
||||
png_warning(png_ptr, msg);
|
||||
png_chunk_warning(png_ptr, "zero length keyword");
|
||||
}
|
||||
|
||||
if (key_len > 79)
|
||||
{
|
||||
char msg[50];
|
||||
|
||||
sprintf(msg, "%s keyword length must be 1 - 79 characters",
|
||||
png_ptr->chunk_name);
|
||||
png_warning(png_ptr, msg);
|
||||
png_chunk_warning(png_ptr, "keyword length must be 1 - 79 characters");
|
||||
new_key[79] = '\0';
|
||||
key_len = 79;
|
||||
}
|
||||
|
||||
return key_len;
|
||||
return (key_len);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -688,15 +699,12 @@ png_write_tEXt(png_structp png_ptr, png_charp key, png_charp text,
|
||||
png_size_t text_len)
|
||||
{
|
||||
png_size_t key_len;
|
||||
png_bytep new_key;
|
||||
png_charp new_key;
|
||||
|
||||
png_debug(1, "in png_write_tEXt\n");
|
||||
if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
|
||||
{
|
||||
char msg[40];
|
||||
|
||||
sprintf(msg, "Empty keyword in %s chunk", "tEXt");
|
||||
png_warning(png_ptr, msg);
|
||||
png_warning(png_ptr, "Empty keyword in tEXt chunk");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -705,7 +713,7 @@ png_write_tEXt(png_structp png_ptr, png_charp key, png_charp text,
|
||||
|
||||
/* make sure we include the 0 after the key */
|
||||
png_write_chunk_start(png_ptr, png_tEXt, (png_uint_32)key_len+text_len+1);
|
||||
png_write_chunk_data(png_ptr, new_key, key_len + 1);
|
||||
png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
|
||||
if (text_len)
|
||||
png_write_chunk_data(png_ptr, (png_bytep)text, text_len);
|
||||
|
||||
@@ -722,7 +730,7 @@ png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,
|
||||
{
|
||||
png_size_t key_len;
|
||||
char buf[1];
|
||||
png_bytep new_key;
|
||||
png_charp new_key;
|
||||
int i, ret;
|
||||
png_charpp output_ptr = NULL; /* array of pointers to output */
|
||||
int num_output_ptr = 0; /* number of output pointers used */
|
||||
@@ -732,10 +740,7 @@ png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,
|
||||
|
||||
if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
|
||||
{
|
||||
char msg[40];
|
||||
|
||||
sprintf(msg, "Empty keyword in %s chunk", "zTXt");
|
||||
png_warning(png_ptr, msg);
|
||||
png_warning(png_ptr, "Empty keyword in zTXt chunk");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -750,9 +755,13 @@ png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,
|
||||
|
||||
if (compression >= PNG_TEXT_COMPRESSION_LAST)
|
||||
{
|
||||
#if !defined(PNG_NO_STDIO)
|
||||
char msg[50];
|
||||
sprintf(msg, "Unknown zTXt compression type %d", compression);
|
||||
png_warning(png_ptr, msg);
|
||||
#else
|
||||
png_warning(png_ptr, "Unknown zTXt compression type");
|
||||
#endif
|
||||
compression = PNG_TEXT_COMPRESSION_zTXt;
|
||||
}
|
||||
|
||||
@@ -816,7 +825,8 @@ png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,
|
||||
}
|
||||
|
||||
/* 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_ptr->zbuf_size);
|
||||
png_memcpy(output_ptr[num_output_ptr], png_ptr->zbuf,
|
||||
png_ptr->zbuf_size);
|
||||
num_output_ptr++;
|
||||
@@ -869,7 +879,7 @@ png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,
|
||||
}
|
||||
|
||||
/* save off the data */
|
||||
output_ptr[num_output_ptr] = png_malloc(png_ptr,
|
||||
output_ptr[num_output_ptr] = (png_charp)png_malloc(png_ptr,
|
||||
png_ptr->zbuf_size);
|
||||
png_memcpy(output_ptr[num_output_ptr], png_ptr->zbuf,
|
||||
png_ptr->zbuf_size);
|
||||
@@ -945,7 +955,7 @@ png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0,
|
||||
png_size_t purpose_len, units_len, total_len;
|
||||
png_uint_32p params_len;
|
||||
png_byte buf[10];
|
||||
png_bytep new_purpose;
|
||||
png_charp new_purpose;
|
||||
int i;
|
||||
|
||||
png_debug1(1, "in png_write_pCAL (%d parameters)\n", nparams);
|
||||
@@ -971,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_data(png_ptr, new_purpose, purpose_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);
|
||||
buf[8] = (png_byte)type;
|
||||
@@ -987,6 +997,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
|
||||
@@ -1013,8 +1024,9 @@ png_write_pHYs(png_structp png_ptr, png_uint_32 x_pixels_per_unit,
|
||||
#endif
|
||||
|
||||
#if defined(PNG_WRITE_tIME_SUPPORTED)
|
||||
/* write the tIME chunk. Use either png_convert_from_struct_tm()
|
||||
or png_convert_from_time_t(), or fill in the structure yourself */
|
||||
/* Write the tIME chunk. Use either png_convert_from_struct_tm()
|
||||
* or png_convert_from_time_t(), or fill in the structure yourself.
|
||||
*/
|
||||
void
|
||||
png_write_tIME(png_structp png_ptr, png_timep mod_time)
|
||||
{
|
||||
@@ -1091,6 +1103,7 @@ png_write_start_row(png_structp png_ptr)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef PNG_WRITE_INTERLACING_SUPPORTED
|
||||
/* if interlaced, we need to set up width and height of pass */
|
||||
if (png_ptr->interlaced)
|
||||
{
|
||||
@@ -1108,6 +1121,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;
|
||||
@@ -1130,6 +1144,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)
|
||||
{
|
||||
@@ -1171,6 +1186,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 */
|
||||
@@ -1206,14 +1222,13 @@ png_write_finish_row(png_structp png_ptr)
|
||||
}
|
||||
|
||||
#if defined(PNG_WRITE_INTERLACING_SUPPORTED)
|
||||
/* pick out the correct pixels for the interlace pass.
|
||||
|
||||
The basic idea here is to go through the row with a source
|
||||
pointer and a destination pointer (sp and dp), and copy the
|
||||
correct pixels for the pass. As the row gets compacted,
|
||||
sp will always be >= dp, so we should never overwrite anything.
|
||||
See the default: case for the easiest code to understand.
|
||||
*/
|
||||
/* Pick out the correct pixels for the interlace pass.
|
||||
* The basic idea here is to go through the row with a source
|
||||
* pointer and a destination pointer (sp and dp), and copy the
|
||||
* correct pixels for the pass. As the row gets compacted,
|
||||
* sp will always be >= dp, so we should never overwrite anything.
|
||||
* See the default: case for the easiest code to understand.
|
||||
*/
|
||||
void
|
||||
png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
|
||||
{
|
||||
@@ -1366,11 +1381,12 @@ png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
|
||||
|
||||
/* This filters the row, chooses which filter to use, if it has not already
|
||||
* been specified by the application, and then writes the row out with the
|
||||
* chosen filter. */
|
||||
#define PNG_MAXSUM (~0x0UL >> 1)
|
||||
* chosen filter.
|
||||
*/
|
||||
#define PNG_MAXSUM (png_uint_32)(~0x0UL >> 1)
|
||||
#define PNG_HISHIFT 10
|
||||
#define PNG_LOMASK 0xffffL
|
||||
#define PNG_HIMASK (~PNG_LOMASK >> PNG_HISHIFT)
|
||||
#define PNG_LOMASK (png_uint_32)0xffffL
|
||||
#define PNG_HIMASK (png_uint_32)(~PNG_LOMASK >> PNG_HISHIFT)
|
||||
void
|
||||
png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
|
||||
{
|
||||
@@ -1389,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
|
||||
|
||||
Reference in New Issue
Block a user