Imported from libpng-0.97.tar

This commit is contained in:
Glenn Randers-Pehrson 1998-01-01 07:13:13 -06:00
parent 47a0c422ca
commit b6ce43d6ff
24 changed files with 1297 additions and 763 deletions

18
CHANGES
View File

@ -167,3 +167,21 @@ 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 1.00 [not distributed, but Andreas handed off to G&G]
skipped version 1.00 to avoid potential problems with shared libraries
created with version 0.89
removed PNG_USE_OWN_CRC capability
relocated png_set_crc_action from pngrutil.c to pngrtran.c
fixed typecasts of "new_key" etc.
added RFC 1152 date support
version 1.00.97 [Dec 1997]
fixed bug in gamma handling of 4-bit grayscale
added more typecasts. 65536L becomes (png_uint_32)65536L, etc.
minor corrections in libpng.txt
added simple sRGB support
make it simpler to do conditional compiling
fixed memory leak in pngwrite.c (free info_ptr->text)
added more conditions for png_do_background, to avoid changing
black pixels to background when a background is supplied and
no pixels are transparent
include stdio.h in pngconf.h even when PNG_NO_STDIO is defined.

23
README
View File

@ -1,9 +1,16 @@
README for libpng 0.96
README for libpng 1.10
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.
This first official release of libpng. Don't let the fact that
it's the first release fool you. The libpng library has been in
extensive use and testing for about two years. However, it's
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 the version number is 1.10 to avoid potential problems
with shared libraries created for Linux ELF under version 0.89,
which mistakenly used 1.0.89 as the library version number in
false anticipation of an imminent 1.0 release.
****
Note that some of the changes to the png_info structure render this
@ -19,6 +26,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
which 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

120
example.c
View File

@ -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);
@ -207,13 +211,17 @@ 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);
if (png_get_sRGB(png_ptr, info_ptr, &srgb_intent)
png_set_sRGB(png_ptr, srgb_intent, 0);
else
if (png_get_gAMA(png_ptr, info_ptr, &image_gamma)
png_set_gamma(png_ptr, screen_gamma, image_gamma);
else
png_set_gamma(png_ptr, screen_gamma, 0.45);
/* 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;
@ -269,19 +277,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 +302,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++)
{
@ -552,7 +560,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 +577,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 +590,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);
/* 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 +608,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 */

View File

@ -1,10 +1,13 @@
libpng.txt - a description on how to use and modify libpng
libpng 1.0 beta 5 - version 0.95
libpng version 1.00 version 0.97
based on:
libpng version 1.00 version 0.96
Updated and distributed by Andreas Dilger <adilger@enel.ucalgary.ca>,
Copyright (c) 1996, 1997 Andreas Dilger
March 15, 1997
based on:
May 28, 1997
libpng 1.0 beta 2 - version 0.88
For conditions of distribution and use, see copyright notice in png.h
@ -27,11 +30,18 @@ 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.
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
@ -341,7 +351,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)
@ -614,7 +624,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
@ -1013,7 +1023,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 +1061,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_rfc1152(png_timep) is provided to convert from PNG
time to an RFC 1152 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().
@ -1307,8 +1332,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,

68
makefile.dec Normal file
View 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

View File

@ -13,14 +13,14 @@ 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 -fPIC #$(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 = 1
PNGMIN = 1.0
PNGVER = $(PNGMAJ).$(PNGMIN)
# where make install puts libpng.a, libpng.so*, and png.h
@ -45,10 +45,10 @@ 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)
gcc -shared -Wl,-soname,libpng.so.$(PNGMAJ) $(OBJS) -o libpng.so.$(PNGVER)
pngtest: pngtest.o libpng.so
$(CC) -o pngtest pngtest.o $(LDFLAGS)
$(CC) -o pngtest $(CCFLAGS) pngtest.o $(LDFLAGS)
test: pngtest
./pngtest

154
png.c
View File

@ -1,27 +1,29 @@
/* 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 1.00.97
* 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 28, 1997
*/
#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[] = "1.00.97";
/* Place to hold the signiture 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 +36,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 +56,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};
@ -113,8 +114,9 @@ png_sig_cmp(png_bytep sig, png_size_t start, png_size_t 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)
{
@ -151,78 +153,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 +184,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)
{
@ -268,9 +208,10 @@ png_create_info_struct(png_structp png_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 +231,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,8 +279,9 @@ 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)
{
@ -347,8 +290,9 @@ png_get_io_ptr(png_structp png_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)
{

238
png.h
View File

@ -1,67 +1,71 @@
/* 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 1.00.97 beta 7
* 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
* Dec 31, 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. 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,12 +93,12 @@ 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 "1.00.97"
/* 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 97
/* variables declared in png.c - only it needs to define PNG_NO_EXTERN */
#ifndef PNG_NO_EXTERN
@ -172,10 +176,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 */
@ -244,6 +249,13 @@ typedef struct png_info_struct
*/
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
@ -422,6 +434,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 +537,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 */
@ -609,6 +621,9 @@ struct png_struct_def
png_uint_16p filter_costs; /* relative filter calculation cost */
png_uint_16p inv_filter_costs; /* 1/relative filter calculation cost */
#endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
#if defined(PNG_TIME_RFC1152_SUPPORTED)
png_charp time_buffer; /* String to hold RFC 1152 time text */
#endif /* PNG_TIME_RFC1152_SUPPORTED */
};
typedef png_struct FAR * FAR * png_structpp;
@ -640,8 +655,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 +678,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_RFC1152_SUPPORTED)
extern PNG_EXPORT(png_charp,png_convert_to_rfc1152)
PNGARG((png_structp png_ptr, png_timep ptime));
#endif /* PNG_TIME_RFC1152_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,
@ -840,6 +860,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 +891,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));
@ -1030,7 +1055,7 @@ 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));
#if defined(USE_FAR_KEYWORD) /* memory model conversion function */
@ -1175,6 +1200,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, png_byte *srgb_intent));
#endif /* PNG_READ_sRGB_SUPPORTED */
#if defined(PNG_READ_sRGB_SUPPORTED) || defined(PNG_WRITE_sRGB_SUPPORTED)
extern PNG_EXPORT(void,png_set_sRGB) PNGARG((png_structp png_ptr,
png_infop info_ptr, png_byte srgb_intent));
extern PNG_EXPORT(void,png_set_sRGB_gAMA_and_cHRM) PNGARG((png_structp png_ptr,
png_infop info_ptr, png_byte srgb_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,
@ -1244,13 +1281,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
@ -1331,10 +1372,11 @@ extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr,
/* place to hold the signiture string for a PNG file. */
extern png_byte FARDATA png_sig[];
/* 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. */
/* 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[];
@ -1347,6 +1389,7 @@ extern png_byte FARDATA png_oFFs[];
extern png_byte FARDATA png_pCAL[];
extern png_byte FARDATA png_pHYs[];
extern png_byte FARDATA png_sBIT[];
extern png_byte FARDATA png_sRGB[];
extern png_byte FARDATA png_tEXt[];
extern png_byte FARDATA png_tIME[];
extern png_byte FARDATA png_tRNS[];
@ -1376,12 +1419,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 +1478,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 +1487,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,
@ -1466,7 +1514,8 @@ 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 +1545,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,
png_byte srgb_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 +1567,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)
@ -1698,7 +1752,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 +1778,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));

225
pngconf.h
View File

@ -1,66 +1,69 @@
/* 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 1.00.97
* 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 28, 1997
*/
/* 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 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.
*/
#define PNG_ZBUF_SIZE 8192
/* 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 */
/* We still need stdio.h for FILE even when PNG_NO_STDIO is defined.
*/
/* for FILE. If you are not using standard io, you don't need this */
#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,8 +80,12 @@
#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.
*/
#if (defined(__MWERKS__) && defined(macintosh)) || defined(applec) || \
defined(THINK_C) || defined(__SC__)
#define MACOS
#endif
@ -88,27 +95,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