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
#endif
#endif /* linux */
#endif /* __linux__ */
#ifdef BSD
#include <strings.h>
@ -119,9 +127,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 +138,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
@ -147,8 +154,9 @@
#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,34 +167,36 @@
#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.
*/
#define PNG_DITHER_RED_BITS 5
#define PNG_DITHER_GREEN_BITS 5
#define PNG_DITHER_BLUE_BITS 5
/* 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).
*/
#define PNG_MAX_GAMMA_8 11
/* This controls how much a difference in gamma we can tolerate before
we actually start doing gamma conversion. */
* we actually start doing gamma conversion.
*/
#define PNG_GAMMA_THRESHOLD 0.05
#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 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.
*/
#define PNG_USE_CONST
#ifdef PNG_USE_CONST
# define PNG_CONST const
@ -195,19 +205,34 @@
#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
@ -226,7 +251,9 @@
#define PNG_READ_GRAY_TO_RGB_SUPPORTED
#define PNG_READ_SWAP_ALPHA_SUPPORTED
#define PNG_READ_STRIP_ALPHA_SUPPORTED
#endif /* PNG_READ_FULLY_SUPPORTED */
#ifdef PNG_WRITE_FULLY_SUPPORTED
#define PNG_WRITE_INTERLACING_SUPPORTED
#define PNG_WRITE_SHIFT_SUPPORTED
#define PNG_WRITE_PACK_SUPPORTED
@ -238,6 +265,9 @@
#define PNG_WRITE_FLUSH_SUPPORTED
#define PNG_WRITE_SWAP_ALPHA_SUPPORTED
#define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
#endif /*PNG_WRITE_FULLY_SUPPORTED */
#define PNG_TIME_RFC1152_SUPPORTED
/* These are currently experimental features */
#undef PNG_READ_16_TO_8_ACCURATE_SHIFT_SUPPORTED /* very little testing */
@ -247,7 +277,6 @@
#undef PNG_READ_BIG_ENDIAN_SUPPORTED /* some testing */
/* 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
@ -258,6 +287,7 @@
* and RGBA images.
*/
#ifdef PNG_READ_FULLY_SUPPORTED
#define PNG_READ_bKGD_SUPPORTED
#define PNG_READ_cHRM_SUPPORTED
#define PNG_READ_gAMA_SUPPORTED
@ -266,11 +296,14 @@
#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
#endif /* PNG_READ_FULLY_SUPPORTED */
#ifdef PNG_WRITE_FULLY_SUPPORTED
#define PNG_WRITE_bKGD_SUPPORTED
#define PNG_WRITE_cHRM_SUPPORTED
#define PNG_WRITE_gAMA_SUPPORTED
@ -279,10 +312,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_FULLY_SUPPORTED */
/* need the time information for reading tIME chunks */
#if defined(PNG_READ_tIME_SUPPORTED) || defined(PNG_WRITE_tIME_SUPPORTED)
@ -336,18 +371,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 +436,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(t,s) t _export s
#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
#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 */

View File

@ -1,16 +1,17 @@
/* 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 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
*
* 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 +22,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 +38,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)
{
@ -49,9 +52,10 @@ png_warning(png_structp png_ptr, png_const_charp 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(). */
* 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 +75,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 +91,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,8 +106,9 @@ 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)
{

View File

@ -1,12 +1,12 @@
/* 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 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
#include "png.h"
@ -109,6 +109,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, png_byte *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 = (png_byte)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 +211,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);
}
@ -251,7 +275,7 @@ png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr,
*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);
}

View File

@ -1,15 +1,16 @@
/* 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 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
*
* 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"
@ -81,7 +82,7 @@ png_malloc(png_structp png_ptr, png_uint_32 size)
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)
{
@ -139,7 +140,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;

View File

@ -1,12 +1,12 @@
/* 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 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
#include "png.h"
@ -116,10 +116,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 +161,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 +229,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 +797,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 +880,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);
@ -1029,11 +1043,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)
{

100
pngread.c
View File

@ -1,19 +1,22 @@
/* 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 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
*
* 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;
@ -76,7 +79,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. */
@ -215,6 +217,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 +253,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 +446,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 +501,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 +535,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 +606,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);
@ -659,7 +675,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;
@ -700,6 +715,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 +726,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 +735,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]);

View File

@ -1,18 +1,19 @@
/* 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 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
*
* 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"

View File

@ -1,22 +1,28 @@
/* 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 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
*
* 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.
* The results may also be off by one for certain values.
*/
/* pixel and background should be in gamma 1.0 space */
#define png_composite(composite, pixel, trans, background) \
@ -42,9 +48,62 @@
#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)
(png_uint_32)32767) / (png_uint_32)65535L)
#endif
/* 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 */
void
@ -89,12 +148,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
{
@ -478,9 +538,10 @@ 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)
{
@ -494,8 +555,9 @@ png_set_gamma(png_structp png_ptr, double screen_gamma, double file_gamma)
#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,8 +577,9 @@ 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)
{
@ -527,7 +590,8 @@ png_set_rgb_to_gray(png_structp png_ptr, int gray_bits)
#endif
/* Initialize everything needed for the read. This includes modifying
the palette */
* the palette.
*/
void
png_init_read_transformations(png_structp png_ptr)
{
@ -810,8 +874,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)
{
@ -910,9 +975,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)
{
@ -955,7 +1021,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),
@ -1041,11 +1109,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 +1200,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 +1338,7 @@ 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;
* Approximate calculation with shift/add instead of multiply/divide:
*dp = ((((png_uint_32)(*sp) << 8) |
@ -1527,10 +1597,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)
{
@ -1762,8 +1833,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 +2402,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 +2428,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,
@ -2488,8 +2561,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 +2594,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 +2736,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 +3033,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)
{

View File

@ -1,12 +1,15 @@
/* 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 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
*
* 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"
@ -57,59 +60,6 @@ png_get_uint_16(png_bytep buf)
}
#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)
@ -185,11 +135,7 @@ 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
}
else
return 0;
@ -228,7 +174,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 +193,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 +284,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, num, sizeof (png_color));
png_ptr->flags |= PNG_FLAG_FREE_PALETTE;
for (i = 0; i < num; i++)
{
@ -457,6 +404,26 @@ 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 ((png_ptr->mode & PNG_HAVE_sRGB))
if(igamma != 50000)
{
png_warning(png_ptr,
"Ignoring incorrect gAMA value when sRGB is also present");
return;
}
#endif /* PNG_READ_sRGB_SUPPORTED */
#if defined(PNG_READ_sRGB_SUPPORTED)
if (png_ptr->mode & PNG_HAVE_sRGB)
if(igamma != 50000)
{
png_warning(png_ptr,
"Ignoring incorrect gAMA value when sRGB is also present");
return;
}
#endif /* PNG_READ_sRGB_SUPPORTED */
file_gamma = (float)igamma / (float)100000.0;
png_ptr->gamma = file_gamma;
png_set_gAMA(png_ptr, info_ptr, file_gamma);
@ -483,8 +450,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 +514,8 @@ 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
&& !(info_ptr->valid & PNG_INFO_sRGB))
{
png_warning(png_ptr, "Duplicate cHRM chunk");
png_crc_finish(png_ptr, length);
@ -626,11 +596,92 @@ 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 ((png_ptr->mode & PNG_HAVE_sRGB))
if(white_x != .3127 || white_y != .329 || red_x != .64 || red_y != .33 ||
green_x != .3 || green_y != .6 || blue_x != .15 || blue_y != .06)
{
png_warning(png_ptr,
"Ignoring incorrect cHRM value when sRGB is also present");
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)
{
png_byte intent;
png_byte buf[1];
float file_gamma;
float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
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 > 3)
{
png_warning(png_ptr, "Unknown sRGB intent");
return;
}
/* if we really want to be paranoid we could check for
already defined gamma and chrm with values that are
inconsistent with sRGB -- for now, just ignore them */
file_gamma = 0.45;
png_set_gAMA(png_ptr, info_ptr, file_gamma);
white_x = 0.3127;
white_y = 0.3290;
red_x = 0.6400;
red_y = 0.3300;
green_x = 0.3000;
green_y = 0.6000;
blue_x = 0.1500;
blue_y = 0.0600;
png_set_cHRM(png_ptr, info_ptr,
white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
png_set_sRGB(png_ptr, info_ptr, intent);
}
#endif
#if defined(PNG_READ_tRNS_SUPPORTED)
void
png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
@ -683,7 +734,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 +1164,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 +1222,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);
@ -2113,13 +2164,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);

View File

@ -1,12 +1,17 @@
/* 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 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
*
* 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 +210,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, png_byte intent)
{
png_debug1(1, "in %s storage function\n", "sRGB");
if (info_ptr == NULL)
return;
info_ptr->srgb_intent = intent;
info_ptr->valid |= PNG_INFO_sRGB;
}
void
png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
png_byte intent)
{
#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 = 0.45;
png_set_gAMA(png_ptr, info_ptr, file_gamma);
#endif
#if defined(PNG_READ_cHRM_SUPPORTED) || defined(PNG_WRITE_cHRM_SUPPORTED)
white_x = 0.3127;
white_y = 0.3290;
red_x = 0.6400;
red_y = 0.3300;
green_x = 0.3000;
green_y = 0.6000;
blue_x = 0.1500;
blue_y = 0.0600;
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)
@ -304,6 +358,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;

View File

@ -1,12 +1,30 @@
/* 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 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
*
* 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>
@ -28,11 +46,11 @@
/* input and output filenames */
#ifdef RISCOS
char *inname = "pngtest_png";
char *outname = "pngout_png";
PNG_CONST char *inname = "pngtest_png";
PNG_CONST char *outname = "pngout_png";
#else
char *inname = "pngtest.png";
char *outname = "pngout.png";
PNG_CONST char *inname = "pngtest.png";
PNG_CONST char *outname = "pngout.png";
#endif
char inbuf[256], outbuf[256];
@ -182,6 +200,16 @@ main(int argc, char *argv[])
}
}
#endif
#if defined(PNG_READ_sRGB_SUPPORTED) && defined(PNG_WRITE_sRGB_SUPPORTED)
{
png_byte 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;

View File

@ -1,12 +1,12 @@
/* 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 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
#include "png.h"

View File

@ -1,18 +1,19 @@
/* 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 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
*
* 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"

View File

@ -1,12 +1,12 @@
/* 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 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
*/
/* get internal access to png.h */
#define PNG_INTERNAL
@ -38,6 +38,10 @@ png_write_info(png_structp png_ptr, png_infop info_ptr)
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, 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);
@ -128,9 +132,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)
{
@ -190,6 +195,28 @@ png_write_end(png_structp png_ptr, png_infop info_ptr)
png_write_IEND(png_ptr);
}
#if defined(PNG_TIME_RFC1152_SUPPORTED)
/* Convert the supplied time into an RFC 1152 string suitable for use in
* a "Creation Time" or other text-based time string.
*/
png_charp
png_convert_to_rfc1152(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));
}
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);
return png_ptr->time_buffer;
}
#endif /* PNG_TIME_RFC1152_SUPPORTED */
#if defined(PNG_WRITE_tIME_SUPPORTED)
void
png_convert_from_struct_tm(png_timep ptime, struct tm FAR * ttime)
@ -261,6 +288,11 @@ png_create_write_struct(png_const_charp user_png_ver, voidp error_ptr,
png_set_write_fn(png_ptr, NULL, NULL, NULL);
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
1, NULL, NULL);
#endif
return (png_ptr);
}
@ -292,10 +324,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 +344,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)
{
@ -339,7 +373,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 +450,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 +562,9 @@ 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
png_destroy_struct((png_voidp)info_ptr);
*info_ptr_ptr = (png_infop)NULL;
}
@ -561,6 +599,9 @@ png_write_destroy(png_structp png_ptr)
png_free(png_ptr, png_ptr->up_row);
png_free(png_ptr, png_ptr->avg_row);
png_free(png_ptr, png_ptr->paeth_row);
#if defined(PNG_TIME_RFC1152_SUPPORTED)
png_free(png_ptr, png_ptr->time_buffer);
#endif /* PNG_TIME_RFC1152_SUPPORTED */
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
png_free(png_ptr, png_ptr->prev_filters);
png_free(png_ptr, png_ptr->filter_weights);
@ -683,7 +724,8 @@ 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,

View File

@ -1,18 +1,19 @@
/* 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 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
#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)
{
@ -51,9 +52,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 +171,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 +255,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 +281,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)
{

View File

@ -1,12 +1,12 @@
/* 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 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
#include "png.h"
@ -26,8 +26,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 +39,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 +69,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 +91,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 +113,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 +122,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 +133,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,
@ -264,8 +269,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 +342,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, png_byte srgb_intent)
{
png_byte buf[1];
png_debug(1, "in png_write_sRGB\n");
if(srgb_intent > 3)
png_warning(png_ptr,
"Invalid sRGB rendering intent specified");
buf[0]=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
@ -560,11 +582,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");
@ -581,12 +602,12 @@ png_check_keyword(png_structp png_ptr, png_charp key, png_bytepp new_key)
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 && *kp < 0xA1))
{
char msg[40];
@ -688,7 +709,7 @@ 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)
@ -705,7 +726,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 +743,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 */
@ -945,7 +966,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 +992,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;
@ -1013,8 +1034,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)
{
@ -1206,14 +1228,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,7 +1387,8 @@ 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. */
* chosen filter.
*/
#define PNG_MAXSUM (~0x0UL >> 1)
#define PNG_HISHIFT 10
#define PNG_LOMASK 0xffffL