Compare commits

...

23 Commits

Author SHA1 Message Date
Glenn Randers-Pehrson
2eb0852fd6 Imported from pngcrush-1.5.8.tar 2009-04-16 10:46:56 -05:00
Glenn Randers-Pehrson
f671d863fe Imported from pngcrush-1.5.7.tar 2009-04-16 10:46:55 -05:00
Glenn Randers-Pehrson
36e234ac16 Imported from pngcrush-1.5.6.tar 2009-04-16 10:46:55 -05:00
Glenn Randers-Pehrson
0f3e444307 Imported from pngcrush-1.5.5.tar 2009-04-16 10:46:54 -05:00
Glenn Randers-Pehrson
4df0ff379f Imported from pngcrush-1.5.4.tar 2009-04-16 10:46:53 -05:00
Glenn Randers-Pehrson
4109c5d71b Imported from pngcrush-1.5.3.tar 2009-04-16 10:46:52 -05:00
Glenn Randers-Pehrson
0d46dafc86 Imported from pngcrush-1.5.2.tar 2009-04-16 10:46:51 -05:00
Glenn Randers-Pehrson
28affe866f Imported from pngcrush-1.5.1.tar 2009-04-16 10:46:50 -05:00
Glenn Randers-Pehrson
4874961d5d Imported from pngcrush-1.5.0.tar 2009-04-16 10:46:50 -05:00
Glenn Randers-Pehrson
3438f87fad Imported from pngcrush-1.4.8.tar 2009-04-16 10:46:49 -05:00
Glenn Randers-Pehrson
3c3ecc4f9e Imported from pngcrush-1.4.7.tar 2009-04-16 10:46:48 -05:00
Glenn Randers-Pehrson
4d6ce965b5 Imported from pngcrush-1.4.6.tar 2009-04-16 10:46:48 -05:00
Glenn Randers-Pehrson
55c878d8e5 Imported from pngcrush-1.4.5.tar 2009-04-16 10:46:47 -05:00
Glenn Randers-Pehrson
52ab58fb21 Imported from pngcrush-1.4.4.tar 2009-04-16 10:46:46 -05:00
Glenn Randers-Pehrson
0b5314cf35 Imported from pngcrush-1.4.3.tar 2009-04-16 10:46:45 -05:00
Glenn Randers-Pehrson
a8dc4523c7 Imported from pngcrush-1.4.2.tar 2009-04-16 10:46:44 -05:00
Glenn Randers-Pehrson
1abb7801d4 Imported from pngcrush-1.4.1.tar 2009-04-16 10:46:43 -05:00
Glenn Randers-Pehrson
d346287eaa Imported from pngcrush-1.4.0.tar 2009-04-16 10:46:42 -05:00
Glenn Randers-Pehrson
66e6b07dfd Imported from pngcrush-1.3.6.tar 2009-04-16 10:46:41 -05:00
Glenn Randers-Pehrson
601daa7a76 Imported from pngcrush-1.3.5.tar 2009-04-16 10:46:40 -05:00
Glenn Randers-Pehrson
f142567725 Imported from pngcrush-1.3.4.tar 2009-04-16 10:46:40 -05:00
Glenn Randers-Pehrson
10ecaa7a20 Imported from pngcrush-1.3.3.tar 2009-04-16 10:46:39 -05:00
Glenn Randers-Pehrson
c3e8db9e59 Imported from pngcrush-1.3.2.tar 2009-04-16 10:46:38 -05:00
34 changed files with 10643 additions and 4405 deletions

View File

@@ -1,16 +1,16 @@
There's a sample makefile.gcc for pngcrush, which you can use There are sample Makefile.gcc and Makefile.msc for pngcrush, which you can use
by typing by typing, for example
make -f makefile.gcc make -f Makefile.gcc
However, all you should need to do is enter the pngcrush-1.3.0 However, all you should need to do is enter the pngcrush-n.n.n
directory and type directory and type
cc -O -o pngcrush *.c -lm cc -O -o pngcrush *.c -lm
cp pngcrush /usr/local/bin # or wherever you want cp pngcrush /usr/local/bin # or wherever you want
You might want to create a makefile if you are planning to do You might want to create your own Makefile if you are planning to do
something more complicated, like loading with your system's shared something more complicated, like loading with your system's shared
libraries for libpng and zlib. libraries for libpng and zlib.

View File

@@ -13,7 +13,7 @@
CC = gcc CC = gcc
LD = gcc LD = gcc
RM = rm -f RM = rm -f
CFLAGS = -O -Wall CFLAGS = -I. -O -Wall
# [note that -Wall is a gcc-specific compilation flag ("all warnings on")] # [note that -Wall is a gcc-specific compilation flag ("all warnings on")]
LDFLAGS = LDFLAGS =
O = .o O = .o
@@ -27,7 +27,7 @@ OBJS = $(PNGCRUSH)$(O) adler32$(O) crc32$(O) deflate$(O) gzio$(O) \
infblock$(O) infcodes$(O) inffast$(O) inflate$(O) inftrees$(O) \ infblock$(O) infcodes$(O) inffast$(O) inflate$(O) inftrees$(O) \
infutil$(O) png$(O) pngerror$(O) pngget$(O) pngmem$(O) \ infutil$(O) png$(O) pngerror$(O) pngget$(O) pngmem$(O) \
pngpread$(O) pngread$(O) pngrio$(O) pngrtran$(O) pngrutil$(O) \ pngpread$(O) pngread$(O) pngrio$(O) pngrtran$(O) pngrutil$(O) \
pngset$(O) pngtrans$(O) pngvcrd$(O) pngwio$(O) pngwrite$(O) \ pngset$(O) pngtrans$(O) pngwio$(O) pngwrite$(O) pnggccrd$(O) \
pngwtran$(O) pngwutil$(O) trees$(O) zutil$(O) pngwtran$(O) pngwutil$(O) trees$(O) zutil$(O)
EXES = $(PNGCRUSH)$(E) EXES = $(PNGCRUSH)$(E)
@@ -35,7 +35,7 @@ EXES = $(PNGCRUSH)$(E)
# implicit make rules ------------------------------------------------------- # implicit make rules -------------------------------------------------------
.c$(O): png.h pngconf.h zlib.h pngcrush.h .c$(O): png.h pngconf.h zlib.h pngcrush.h cexcept.h
$(CC) -c $(CFLAGS) $< $(CC) -c $(CFLAGS) $<
@@ -47,7 +47,7 @@ all: $(EXES)
$(PNGCRUSH)$(E): $(OBJS) $(PNGCRUSH)$(E): $(OBJS)
$(LD) $(LDFLAGS) -o $@ $(OBJS) $(LIBS) $(LD) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
$(PNGCRUSH)$(O): $(PNGCRUSH).c png.h pngconf.h zlib.h pngcrush.h $(PNGCRUSH)$(O): $(PNGCRUSH).c png.h pngconf.h zlib.h pngcrush.h cexcept.h
# maintenance --------------------------------------------------------------- # maintenance ---------------------------------------------------------------

57
Makefile.msc Normal file
View File

@@ -0,0 +1,57 @@
# Sample makefile for pngcrush using Microsoft (Visual) C compiler.
# Author: Cosmin Truta
# Derived from Makefile.gcc by Glenn Randers-Pehrson
# Last modified: 14 January 2000
#
# Invoke this makefile from a console prompt in the usual way; for example:
#
# nmake -f Makefile.msc
#
# This makefile builds a statically linked executable.
# macros --------------------------------------------------------------------
CC = cl -nologo
LD = link -nologo setargv.obj
RM = del
CFLAGS = -I. -DPNG_ZBUF_SIZE=0x080000 -DWIN32 -O2
LDFLAGS =
O = .obj
E = .exe
PNGCRUSH = pngcrush
LIBS =
OBJS = $(PNGCRUSH)$(O) adler32$(O) crc32$(O) deflate$(O) gzio$(O) \
infblock$(O) infcodes$(O) inffast$(O) inflate$(O) inftrees$(O) \
infutil$(O) png$(O) pngerror$(O) pngget$(O) pngmem$(O) \
pngpread$(O) pngread$(O) pngrio$(O) pngrtran$(O) pngrutil$(O) \
pngset$(O) pngtrans$(O) pngvcrd$(O) pngwio$(O) pngwrite$(O) \
pngwtran$(O) pngwutil$(O) trees$(O) zutil$(O)
EXES = $(PNGCRUSH)$(E)
# implicit make rules -------------------------------------------------------
.c$(O):
$(CC) -c $(CFLAGS) $<
# dependencies --------------------------------------------------------------
all: $(EXES)
$(PNGCRUSH)$(E): $(OBJS)
$(LD) $(LDFLAGS) -out:$@ $(OBJS) $(LIBS)
$(PNGCRUSH)$(O): $(PNGCRUSH).c png.h pngconf.h zlib.h pngcrush.h cexcept.h
# maintenance ---------------------------------------------------------------
clean:
$(RM) *$(O)
$(RM) $(PNGCRUSH)$(E)

View File

@@ -1,12 +1,58 @@
Pngcrush documentation
| pngcrush 1.3.1, Copyright (C) 1998, 1999, Glenn Randers-Pehrson This is is a copy of the copyright notice, disclaimer, and license, for
| This is a free, open-source program. Permission is your convenience (the actual notice appears in the file pngcrush.c; in
| granted to everyone to use pngcrush without fee. case of any discrepancy, the copy in pngcrush.c shall prevail):
| This program was built with libpng version 1.0.5k,
| Copyright (C) 1995, Guy Eric Schalnat, Group 42 Inc., /*
* COPYRIGHT NOTICE, DISCLAIMER, AND LICENSE:
*
* If you have modified this source, you may insert additional notices
* immediately after this sentence.
*
* Copyright (C) 1998-2001 Glenn Randers-Pehrson (randeg@alum.rpi.edu)
*
* The pngcrush computer program is supplied "AS IS". The Author disclaims all
* warranties, expressed or implied, including, without limitation, the
* warranties of merchantability and of fitness for any purpose. The
* Author assumes no liability for direct, indirect, incidental, special,
* exemplary, or consequential damages, which may result from the use of
* the computer program, even if advised of the possibility of such damage.
* There is no warranty against interference with your enjoyment of the
* computer program or against infringement. There is no warranty that my
* efforts or the computer program will fulfill any of your particular purposes
* or needs. This computer program is provided with all faults, and the entire
* risk of satisfactory quality, performance, accuracy, and effort is with
* the user.
*
* Permission is hereby irrevocably granted to everyone to use, copy, modify,
* and distribute this source code, or portions hereof, for any purpose,
* without payment of any 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, disclaimer, and license may not be removed
* or altered from any source or altered source distribution.
*/
This is the output of "pngcrush" and "pngcrush -help":
| pngcrush 1.5.8, Copyright (C) 1998-2001 Glenn Randers-Pehrson
| This is a free, open-source program. Permission is irrevocably
| granted to everyone to use this version of pngcrush without
| payment of any fee.
| Executable name is pngcrush
| It was built with libpng version 1.2.1, and is
| running with libpng version 1.2.1 - December 12, 2001 (header)
| Copyright (C) 1998-2001 Glenn Randers-Pehrson,
| Copyright (C) 1996, 1997 Andreas Dilger, | Copyright (C) 1996, 1997 Andreas Dilger,
| Copyright (C) 1998, 1999, Glenn Randers-Pehrson, | Copyright (C) 1995, Guy Eric Schalnat, Group 42 Inc.,
| and zlib version 1.1.3, Copyright (c) 1998, | and zlib version 1.1.3pc, Copyright (C) 1998,
| Jean-loup Gailly and Mark Adler. | Jean-loup Gailly and Mark Adler.
@@ -14,34 +60,81 @@ usage: pngcrush [options] infile.png outfile.png
pngcrush -e ext [other options] files.png ... pngcrush -e ext [other options] files.png ...
pngcrush -d dir [other options] files.png ... pngcrush -d dir [other options] files.png ...
options: options:
-brute (Use brute-force, try 114 different methods) -already already_crushed_size [e.g., 8192]
-bit_depth depth (bit_depth to use in output file)
-brute (Use brute-force, try 114 different methods [11-124])
-c color_type of output file [0, 2, 4, or 6] -c color_type of output file [0, 2, 4, or 6]
-d directory_name (where output files will go) -d directory_name (where output files will go)
-double_gamma (used for fixing gamma in PhotoShop 5.0/5.02 files) -double_gamma (used for fixing gamma in PhotoShop 5.0/5.02 files)
-e extension (used for creating output filename) -e extension (used for creating output filename)
-f user_filter [0-5] -f user_filter [0-5]
-fix (fix otherwise fatal conditions such as bad CRCs)
-force (Write a new output file even if larger than input) -force (Write a new output file even if larger than input)
-g gamma_value (float, e.g., 0.45455) -g gamma (float or fixed*100000, e.g., 0.45455 or 45455)
-itxt b[efore_IDAT]|a[fter_IDAT] "keyword" "text" -iccp length "Profile Name" iccp_file
-itxt b[efore_IDAT]|a[fter_IDAT] "keyword" "text"
-l zlib_compression_level [0-9] -l zlib_compression_level [0-9]
-loco ("loco crush" truecolor PNGs)
-m method [0 through 200] -m method [0 through 200]
-max maximum_IDAT_size [1 through 524288] -max maximum_IDAT_size [default 8192]
-nofilecheck (do not check for infile.png == outfile.png)
-n (no save; does not do compression or write output PNG) -n (no save; does not do compression or write output PNG)
-plte_len n (truncate PLTE) -plte_len n (truncate PLTE)
-q (quiet) -q (quiet)
-reduce (do lossless color type or bit depth reduction)
-rem chunkname (or "alla" or "allb") -rem chunkname (or "alla" or "allb")
-replace_gamma gamma_value (float) even when file has a gAMA chunk. -replace_gamma gamma (float or fixed*100000) even if gAMA is present.
-res dpi -res dpi
-save (keep all copy-unsafe chunks)
-srgb [0, 1, 2, or 3] -srgb [0, 1, 2, or 3]
-text b[efore_IDAT]|a[fter_IDAT] "keyword" "text" -text b[efore_IDAT]|a[fter_IDAT] "keyword" "text"
-trns_array n trns[0] trns[1] .. trns[n-1]
-trns index red green blue gray -trns index red green blue gray
-verbose (write more detailed information) -v (display more detailed information)
-version (display the pngcrush version)
-w compression_window_size [32, 16, 8, 4, 2, 1, 512] -w compression_window_size [32, 16, 8, 4, 2, 1, 512]
-h (help) -z zlib_strategy [0, 1, or 2]
-zmem zlib_compression_mem_level [1-9, default 9]
-zitxt b[efore_IDAT]|a[fter_IDAT] "keyword" "text"
-ztxt b[efore_IDAT]|a[fter_IDAT] "keyword" "text"
-h (help and legal notices)
-p (pause) -p (pause)
options:
-brute (Use brute-force, try 114 different methods) | pngcrush 1.5.8, Copyright (C) 1998-2001 Glenn Randers-Pehrson
| This is a free, open-source program. Permission is irrevocably
| granted to everyone to use this version of pngcrush without
| payment of any fee.
| Executable name is pngcrush
| It was built with libpng version 1.2.1, and is
| running with libpng version 1.2.1 - December 12, 2001 (header)
| Copyright (C) 1998-2001 Glenn Randers-Pehrson,
| Copyright (C) 1996, 1997 Andreas Dilger,
| Copyright (C) 1995, Guy Eric Schalnat, Group 42 Inc.,
| and zlib version 1.1.3pc, Copyright (C) 1998,
| Jean-loup Gailly and Mark Adler.
usage: pngcrush [options] infile.png outfile.png
pngcrush -e ext [other options] files.png ...
pngcrush -d dir [other options] files.png ...
options (Note: any option can be spelled out for clarity, e.g.,
"pngcrush -dir New -method 7 -remove bkgd *.png"
is the same as "pngcrush -d New -m 7 -rem bkgd *.png"):
-already already_crushed_size [e.g., 8192]
If file has an IDAT greater than this size, it
will be considered to be already crushed and will
not be processed, unless you are making other changes
or the "-force" option is present.
-bit_depth depth (bit_depth to use in output file)
Default output depth is same as input depth.
-brute (Use brute-force, try 114 different methods [11-124])
Very time-consuming and generally not worthwhile. Very time-consuming and generally not worthwhile.
You can restrict this option to certain filter types, You can restrict this option to certain filter types,
@@ -55,6 +148,7 @@ options:
fewer colors present in the input file. Color types fewer colors present in the input file. Color types
4 and 6 are padded with an opaque alpha channel if 4 and 6 are padded with an opaque alpha channel if
the input file does not have alpha information. the input file does not have alpha information.
You can use 0 or 4 to convert color to grayscale.
Use 0 or 2 to delete an unwanted alpha channel. Use 0 or 2 to delete an unwanted alpha channel.
Default is to use same color type as the input file. Default is to use same color type as the input file.
@@ -82,21 +176,27 @@ options:
preceding '-m method' or '-brute_force' argument. preceding '-m method' or '-brute_force' argument.
0: none; 1-4: use specified filter; 5: adaptive. 0: none; 1-4: use specified filter; 5: adaptive.
-fix (fix otherwise fatal conditions such as bad CRCs)
-force (Write a new output file even if larger than input) -force (Write a new output file even if larger than input)
Otherwise the input file will be copied to output Otherwise the input file will be copied to output
if it is smaller than any generated file and no chunk if it is smaller than any generated file and no chunk
additions, removals, or changes were requested. additions, removals, or changes were requested.
-g gamma_value (float, e.g., 0.45455) -g gamma (float or fixed*100000, e.g., 0.45455 or 45455)
Value to insert in gAMA chunk, only if the input Value to insert in gAMA chunk, only if the input
file has no gAMA chunk. To replace an existing file has no gAMA chunk. To replace an existing
gAMA chunk, use the '-replace_gamma' option. gAMA chunk, use the '-replace_gamma' option.
-itxt b[efore_IDAT]|a[fter_IDAT] "keyword" "text" -iccp length "Profile Name" iccp_file
Compressed iTXt chunk to insert (see -text). file with ICC profile to insert in an iCCP chunk.
-itxt b[efore_IDAT]|a[fter_IDAT] "keyword" "text"
Uncompressed iTXt chunk to insert (see -text).
-l zlib_compression_level [0-9] -l zlib_compression_level [0-9]
@@ -104,29 +204,47 @@ options:
with the preceding '-m method' or '-brute_force' with the preceding '-m method' or '-brute_force'
argument. argument.
-loco ("loco crush" truecolor PNGs)
Make the file more compressible by performing a
lossless reversible color transformation.
The resulting file is a MNG, not a PNG, and should
be given the ".mng" file extension. The
"loco" option has no effect on grayscale or
indexed-color PNG files.
-m method [0 through 200] -m method [0 through 200]
pngcrush method to try (0 means try all of 1-10). pngcrush method to try (0 means try all of 1-10).
Can be repeated as in '-m 1 -m 4 -m 7'. Can be repeated as in '-m 1 -m 4 -m 7'.
This can be useful if you run out of memory when pngcrush This can be useful if pngcrush runs out of memory
tries methods 2, 3, 5, 6, 8, 9, or 10 which use when it tries methods 2, 3, 5, 6, 8, 9, or 10 which
filtering and are memory intensive. Methods use filtering and are memory intensive. Methods
1, 4, and 7 use no filtering; methods 11 and up use 1, 4, and 7 use no filtering; methods 11 and up use
specified filter, compression level, and strategy. specified filter, compression level, and strategy.
-max maximum_IDAT_size [1 through 524288] -max maximum_IDAT_size [default 8192]
-nofilecheck (do not check for infile.png == outfile.png)
To avoid false hits from MSVC-compiled code. Note
that if you use this option, you are responsible for
ensuring that the input file is not the output file.
-n (no save; does not do compression or write output PNG) -n (no save; does not do compression or write output PNG)
Useful in conjunction with -v option to get info. Useful in conjunction with -v option to get info.
-plte_len n (truncate PLTE) -plte_len n (truncate PLTE)
Truncates the PLTE. Be sure not to truncate it to Truncates the PLTE. Be sure not to truncate it to
less than the greatest index present in IDAT. less than the greatest index present in IDAT.
-q (quiet) -q (quiet)
-reduce (do lossless color type or bit depth reduction)
(if possible)
-rem chunkname (or "alla" or "allb") -rem chunkname (or "alla" or "allb")
@@ -137,19 +255,25 @@ options:
different chunks, repeat: -rem tEXt -rem pHYs. different chunks, repeat: -rem tEXt -rem pHYs.
Known chunks (those in the PNG 1.1 spec or extensions Known chunks (those in the PNG 1.1 spec or extensions
document) can be named with all lower-case letters, document) can be named with all lower-case letters,
so "-rem bkgd" is equivalent to "-rem bKGD". so "-rem bkgd" is equivalent to "-rem bKGD". But
note: "-rem text" removes all forms of text chunks;
Exact case is required to remove unknown chunks. Exact case is required to remove unknown chunks.
"-rem text" also removes zTXt. If you like to do To do surgery with a chain-saw, "-rem alla" removes
surgery with a chain-saw, "-rem alla" removes
all known ancillary chunks except for tRNS, and all known ancillary chunks except for tRNS, and
"-rem allb" removes all but tRNS and gAMA. "-rem allb" removes all but tRNS and gAMA.
-replace_gamma gamma_value (float) even when file has a gAMA chunk. -replace_gamma gamma (float or fixed*100000) even if gAMA is present.
-res dpi -res dpi
Write a pHYs chunk with the given resolution. Write a pHYs chunk with the given resolution.
-save (keep all copy-unsafe chunks)
Save otherwise unknown ancillary chunks that would
be considered copy-unsafe. This option makes
chunks 'known' to pngcrush, so they can be copied.
-srgb [0, 1, 2, or 3] -srgb [0, 1, 2, or 3]
Value of 'rendering intent' for sRGB chunk. Value of 'rendering intent' for sRGB chunk.
@@ -161,16 +285,26 @@ options:
text < 2048 chars. For now, you can only add ten text < 2048 chars. For now, you can only add ten
tEXt, iTXt, or zTXt chunks per pngcrush run. tEXt, iTXt, or zTXt chunks per pngcrush run.
-trns_array n trns[0] trns[1] .. trns[n-1]
Insert a tRNS chunk, if no tRNS chunk found in file.
Values are for the tRNS array in indexed-color PNG.
-trns index red green blue gray -trns index red green blue gray
Insert a tRNS chunk, if no tRNS chunk found in file. Insert a tRNS chunk, if no tRNS chunk found in file.
You must give all five parameters regardless of the You must give all five parameters regardless of the
color type, scaled to the output bit depth. color type, scaled to the output bit depth.
-verbose (write more detailed information) -v (display more detailed information)
Repeat the option (use "-v -v") for even more. Repeat the option (use "-v -v") for even more.
-version (display the pngcrush version)
Look for the most recent version of pngcrush at
http://pmt.sf.net
-w compression_window_size [32, 16, 8, 4, 2, 1, 512] -w compression_window_size [32, 16, 8, 4, 2, 1, 512]
Size of the sliding compression window, in kbytes Size of the sliding compression window, in kbytes
@@ -184,7 +318,9 @@ options:
zlib compression strategy to use with the preceding zlib compression strategy to use with the preceding
'-m method' argument. '-m method' argument.
-zitxt b[efore_IDAT]|a[fter_IDAT] "keyword" "text" -zmem zlib_compression_mem_level [1-9, default 9]
-zitxt b[efore_IDAT]|a[fter_IDAT] "keyword" "text"
Compressed iTXt chunk to insert (see -text). Compressed iTXt chunk to insert (see -text).
@@ -192,7 +328,7 @@ options:
zTXt chunk to insert (see -text). zTXt chunk to insert (see -text).
-h (help) -h (help and legal notices)
Display this information. Display this information.

244
cexcept.h Normal file
View File

@@ -0,0 +1,244 @@
/*===
cexcept.h 1.0.0 (2000-Jun-21-Wed)
Adam M. Costello <amc@cs.berkeley.edu>
An interface for exception-handling in ANSI C, developed jointly with
Cosmin Truta <cosmin@cs.toronto.edu>.
Copyright (c) 2000 Adam M. Costello and Cosmin Truta. Everyone
is hereby granted permission to do whatever they like with this
file, provided that if they modify it they take reasonable steps to
avoid confusing or misleading people about the authors, version,
and terms of use of the derived file. The copyright holders make
no guarantees about the correctness of this file, and are not
responsible for any damage resulting from its use.
If this interface is used by multiple .c files, they shouldn't include
this header file directly. Instead, create a wrapper header file that
includes this header file and then invokes the define_exception_type
macro (see below), and let your .c files include that header file.
The interface consists of one type, one well-known name, and six macros.
define_exception_type(type_name);
This macro is used like an external declaration. It specifies
the type of object that gets copied from the exception thrower to
the exception catcher. The type_name can be any type that can be
assigned to, that is, a non-constant arithmetic type, struct, union,
or pointer. Examples:
define_exception_type(int);
enum exception { out_of_memory, bad_arguments, disk_full };
define_exception_type(enum exception);
struct exception { int code; const char *msg; };
define_exception_type(struct exception);
struct exception_context;
This type may be used after the define_exception_type() macro has
been invoked. A struct exception_context must be known to both
the thrower and the catcher. It is expected that there be one
context for each thread that uses exceptions. It would certainly
be dangerous for multiple threads to access the same context.
One thread can use multiple contexts, but that is likely to be
confusing and not typically useful. The application can allocate
this structure in any way it pleases--automatic, static, or dynamic.
The application programmer should pretend not to know the structure
members, which are subject to change.
struct exception_context *the_exception_context;
The Try/Catch and Throw statements (described below) implicitly
refer to a context, using the name the_exception_context. It is
the application's responsibility to make sure that this name yields
the address of a mutable (non-constant) struct exception_context
wherever those statements are used. Subject to that constraint, the
application may declare a variable of this name anywhere it likes
(inside a function, in a parameter list, or externally), and may
use whatever storage class specifiers (static, extern, etc) or type
qualifiers (const, volatile) it likes. Examples:
static struct exception_context
* const the_exception_context = &foo;
{ struct exception_context *the_exception_context = bar; ... }
int blah(struct exception_context *the_exception_context, ...);
extern struct exception_context the_exception_context[1];
The last example illustrates a trick that avoids creating a pointer
object separate from the structure object.
The name could even be a macro, for example:
struct exception_context ec_array[numthreads];
#define the_exception_context (ec_array + thread_id)
Be aware that the_exception_context is used several times by the
Try/Catch/Throw macros, so it shouldn't be expensive or have side
effects. The expansion must be a drop-in replacement for an
identifier, so it's safest to put parentheses around it.
void init_exception_context(struct exception_context *ec);
For context structures allocated statically (by an external
definition or using the "static" keyword), the implicit
initialization to all zeros is sufficient, but contexts allocated
by other means must be initialized using this macro before they
are used by a Try/Catch statement. It does no harm to initialize
a context more than once (by using this macro on a statically
allocated context, or using this macro twice on the same context),
but a context must not be re-initialized after it has been used by a
Try/Catch statement.
Try statement
Catch (expression) statement
The Try/Catch/Throw macros are capitalized in order to avoid
confusion with the C++ keywords, which have subtly different
semantics.
A Try/Catch statement has a syntax similar to an if/else
statement, except that the parenthesized expression goes after
the second keyword rather than the first. As with if/else,
there are two clauses, each of which may be a simple statement
ending with a semicolon or a brace-enclosed compound statement.
But whereas the else clause is optional, the Catch clause is
required. The expression must be a modifiable lvalue (something
capable of being assigned to) of the exact same type passed to
define_exception_type().
If a Throw that uses the same exception context as the Try/Catch is
executed within the Try clause (typically within a function called
by the Try clause), and the exception is not caught by a nested
Try/Catch statement, then a copy of the exception will be assigned
to the expression, and control will jump to the Catch clause. If no
such Throw is executed, then the assignment is not performed, and
the Catch clause is not executed.
Regardless of whether an exception is caught, the expression is
always evaluated exactly once, which is significant if it has side
effects, for example:
Try foo();
Catch (p[++i].e) { ... }
IMPORTANT: Jumping into or out of a Try clause (for example via
return, break, continue, goto, longjmp) is forbidden--the compiler
will not complain, but bad things will happen at run-time. Jumping
into or out of a Catch clause is okay, and so is jumping around
inside a Try clause. In many cases where one is tempted to return
from a Try clause, it will suffice to use Throw, and then return
from the Catch clause. Another option is to set a flag variable and
use goto to jump to the end of the Try clause, then check the flag
after the Try/Catch statement.
IMPORTANT: The values of any non-volatile automatic variables
changed within the Try clause are undefined after an exception is
caught. Therefore, variables modified inside the Try block whose
values are needed later outside the Try block must either use static
storage or be declared with the "volatile" type qualifier.
Throw expression;
A Throw statement is very much like a return statement, except that
the expression is required. Whereas return jumps back to the place
where the current function was called, Throw jumps back to the Catch
clause of the innermost enclosing Try clause. The expression must
be compatible with the type passed to define_exception_type(). The
exception must be caught, otherwise the program may crash.
Slight limitation: If the expression is a comma-expression it must
be enclosed in parentheses.
Try statement
Catch_anonymous statement
When the value of the exception is not needed, a Try/Catch statement
can use Catch_anonymous instead of Catch (expression).
Everything below this point is for the benefit of the compiler. The
application programmer should pretend not to know any of it, because it
is subject to change.
===*/
#ifndef CEXCEPT_H
#define CEXCEPT_H
#include <setjmp.h>
#define define_exception_type(etype) \
struct exception__state { \
etype *exception; \
jmp_buf env; \
}
struct exception_context { \
struct exception__state *last; \
int caught; \
};
#define init_exception_context(ec) ((void)((ec)->last = 0))
#define Catch(e) exception__catch(&(e))
#define Catch_anonymous exception__catch(0)
#define Try \
{ \
struct exception__state *exception__p, exception__s; \
int exception__i; \
exception__p = the_exception_context->last; \
the_exception_context->last = &exception__s; \
for (exception__i = 0; ; exception__i = 1) \
if (exception__i) { \
if (setjmp(exception__s.env) == 0) { \
if (&exception__s)
#define exception__catch(e_addr) \
else { } \
the_exception_context->caught = 0; \
} \
else the_exception_context->caught = 1; \
the_exception_context->last = exception__p; \
break; \
} \
else exception__s.exception = e_addr; \
} \
if (!the_exception_context->caught) { } \
else
/* Try ends with if(), and Catch begins and ends with else. This */
/* ensures that the Try/Catch syntax is really the same as the */
/* if/else syntax. */
/* */
/* We use &exception__s instead of 1 to appease compilers that */
/* warn about constant expressions inside if(). Most compilers */
/* should still recognize that &exception__s is never zero and avoid */
/* generating test code. */
/* */
/* We use the variable exception__i to start the loop at the bottom, */
/* rather than jump into the loop using a switch statement, to */
/* appease compilers that warn about jumping into loops. */
#define Throw \
for (;; longjmp(the_exception_context->last->env, 1)) \
if (the_exception_context->last->exception) \
*the_exception_context->last->exception =
#endif /* CEXCEPT_H */

68
compress.c Normal file
View File

@@ -0,0 +1,68 @@
/* compress.c -- compress a memory buffer
* Copyright (C) 1995-1998 Jean-loup Gailly.
* For conditions of distribution and use, see copyright notice in zlib.h
*/
/* @(#) $Id$ */
#include "zlib.h"
/* ===========================================================================
Compresses the source buffer into the destination buffer. The level
parameter has the same meaning as in deflateInit. sourceLen is the byte
length of the source buffer. Upon entry, destLen is the total size of the
destination buffer, which must be at least 0.1% larger than sourceLen plus
12 bytes. Upon exit, destLen is the actual size of the compressed buffer.
compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
memory, Z_BUF_ERROR if there was not enough room in the output buffer,
Z_STREAM_ERROR if the level parameter is invalid.
*/
int ZEXPORT compress2 (dest, destLen, source, sourceLen, level)
Bytef *dest;
uLongf *destLen;
const Bytef *source;
uLong sourceLen;
int level;
{
z_stream stream;
int err;
stream.next_in = (Bytef*)source;
stream.avail_in = (uInt)sourceLen;
#ifdef MAXSEG_64K
/* Check for source > 64K on 16-bit machine: */
if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
#endif
stream.next_out = dest;
stream.avail_out = (uInt)*destLen;
if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
stream.zalloc = (alloc_func)0;
stream.zfree = (free_func)0;
stream.opaque = (voidpf)0;
err = deflateInit(&stream, level);
if (err != Z_OK) return err;
err = deflate(&stream, Z_FINISH);
if (err != Z_STREAM_END) {
deflateEnd(&stream);
return err == Z_OK ? Z_BUF_ERROR : err;
}
*destLen = stream.total_out;
err = deflateEnd(&stream);
return err;
}
/* ===========================================================================
*/
int ZEXPORT compress (dest, destLen, source, sourceLen)
Bytef *dest;
uLongf *destLen;
const Bytef *source;
uLong sourceLen;
{
return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
}

View File

@@ -52,7 +52,7 @@
#include "deflate.h" #include "deflate.h"
const char deflate_copyright[] = const char deflate_copyright[] =
" deflate 1.1.3 Copyright 1995-1998 Jean-loup Gailly "; " deflate 1.1.3pc Copyright 1995-1998 Jean-loup Gailly ";
/* /*
If you use the zlib library in a product, an acknowledgment is welcome If you use the zlib library in a product, an acknowledgment is welcome
in the documentation of your product. If for some reason you cannot in the documentation of your product. If for some reason you cannot
@@ -101,7 +101,7 @@ local void check_match OF((deflate_state *s, IPos start, IPos match,
/* Tail of hash chains */ /* Tail of hash chains */
#ifndef TOO_FAR #ifndef TOO_FAR
# define TOO_FAR 4096 # define TOO_FAR 32767
#endif #endif
/* Matches of length 3 are discarded if their distance exceeds TOO_FAR */ /* Matches of length 3 are discarded if their distance exceeds TOO_FAR */
@@ -232,9 +232,10 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
} }
if (strm->zfree == Z_NULL) strm->zfree = zcfree; if (strm->zfree == Z_NULL) strm->zfree = zcfree;
if (level == Z_DEFAULT_COMPRESSION) level = 6;
#ifdef FASTEST #ifdef FASTEST
level = 1; level = 1;
#else
if (level == Z_DEFAULT_COMPRESSION) level = 6;
#endif #endif
if (windowBits < 0) { /* undocumented feature: suppress zlib header */ if (windowBits < 0) { /* undocumented feature: suppress zlib header */
@@ -1279,9 +1280,12 @@ local block_state deflate_slow(s, flush)
} }
/* longest_match() sets match_start */ /* longest_match() sets match_start */
if (s->match_length <= 5 && (s->strategy == Z_FILTERED || if (s->match_length <= 5 && (s->strategy == Z_FILTERED
(s->match_length == MIN_MATCH && #if (TOO_FAR > 0 && TOO_FAR < 32767)
s->strstart - s->match_start > TOO_FAR))) { || (s->match_length == MIN_MATCH &&
s->strstart - s->match_start > TOO_FAR)
#endif
)) {
/* If prev_match is also MIN_MATCH, match_start is garbage /* If prev_match is also MIN_MATCH, match_start is garbage
* but we will ignore the current match anyway. * but we will ignore the current match anyway.

View File

@@ -160,6 +160,52 @@ int f;
r = Z_BUF_ERROR; r = Z_BUF_ERROR;
while (1) switch (z->state->mode) while (1) switch (z->state->mode)
{ {
case BLOCKS:
r = inflate_blocks(z->state->blocks, z, r);
if (r == Z_DATA_ERROR)
{
z->state->mode = BAD;
z->state->sub.marker = 0; /* can try inflateSync */
break;
}
if (r == Z_OK)
r = f;
if (r != Z_STREAM_END)
return r;
r = f;
inflate_blocks_reset(z->state->blocks, z, &z->state->sub.check.was);
if (z->state->nowrap)
{
z->state->mode = DONE;
break;
}
z->state->mode = CHECK4;
case CHECK4:
NEEDBYTE
z->state->sub.check.need = (uLong)NEXTBYTE << 24;
z->state->mode = CHECK3;
case CHECK3:
NEEDBYTE
z->state->sub.check.need += (uLong)NEXTBYTE << 16;
z->state->mode = CHECK2;
case CHECK2:
NEEDBYTE
z->state->sub.check.need += (uLong)NEXTBYTE << 8;
z->state->mode = CHECK1;
case CHECK1:
NEEDBYTE
z->state->sub.check.need += (uLong)NEXTBYTE;
if (z->state->sub.check.was != z->state->sub.check.need)
{
z->state->mode = BAD;
z->msg = (char*)"incorrect data check";
z->state->sub.marker = 5; /* can't try inflateSync */
break;
}
Tracev((stderr, "inflate: zlib check ok\n"));
z->state->mode = DONE;
case DONE:
return Z_STREAM_END;
case METHOD: case METHOD:
NEEDBYTE NEEDBYTE
if (((z->state->sub.method = NEXTBYTE) & 0xf) != Z_DEFLATED) if (((z->state->sub.method = NEXTBYTE) & 0xf) != Z_DEFLATED)
@@ -217,53 +263,6 @@ int f;
z->msg = (char*)"need dictionary"; z->msg = (char*)"need dictionary";
z->state->sub.marker = 0; /* can try inflateSync */ z->state->sub.marker = 0; /* can try inflateSync */
return Z_STREAM_ERROR; return Z_STREAM_ERROR;
case BLOCKS:
r = inflate_blocks(z->state->blocks, z, r);
if (r == Z_DATA_ERROR)
{
z->state->mode = BAD;
z->state->sub.marker = 0; /* can try inflateSync */
break;
}
if (r == Z_OK)
r = f;
if (r != Z_STREAM_END)
return r;
r = f;
inflate_blocks_reset(z->state->blocks, z, &z->state->sub.check.was);
if (z->state->nowrap)
{
z->state->mode = DONE;
break;
}
z->state->mode = CHECK4;
case CHECK4:
NEEDBYTE
z->state->sub.check.need = (uLong)NEXTBYTE << 24;
z->state->mode = CHECK3;
case CHECK3:
NEEDBYTE
z->state->sub.check.need += (uLong)NEXTBYTE << 16;
z->state->mode = CHECK2;
case CHECK2:
NEEDBYTE
z->state->sub.check.need += (uLong)NEXTBYTE << 8;
z->state->mode = CHECK1;
case CHECK1:
NEEDBYTE
z->state->sub.check.need += (uLong)NEXTBYTE;
if (z->state->sub.check.was != z->state->sub.check.need)
{
z->state->mode = BAD;
z->msg = (char*)"incorrect data check";
z->state->sub.marker = 5; /* can't try inflateSync */
break;
}
Tracev((stderr, "inflate: zlib check ok\n"));
z->state->mode = DONE;
case DONE:
return Z_STREAM_END;
case BAD: case BAD:
return Z_DATA_ERROR; return Z_DATA_ERROR;
default: default:

594
png.c
View File

@@ -1,29 +1,30 @@
/* png.c - location for general purpose libpng functions /* png.c - location for general purpose libpng functions
* *
* libpng version 1.0.5k - December 27, 1999 * libpng version 1.2.1 - December 12, 2001
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. * Copyright (c) 1998-2001 Glenn Randers-Pehrson
* Copyright (c) 1996, 1997 Andreas Dilger * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
* *
*/ */
#define PNG_INTERNAL #define PNG_INTERNAL
#define PNG_NO_EXTERN #define PNG_NO_EXTERN
#include <assert.h>
#include "png.h" #include "png.h"
/* Generate a compiler error if there is an old png.h in the search path. */
typedef version_1_2_1 Your_png_h_is_not_version_1_2_1;
/* Version information for C files. This had better match the version /* Version information for C files. This had better match the version
* string defined in png.h. * string defined in png.h. */
*/
#ifdef PNG_USE_GLOBAL_ARRAYS #ifdef PNG_USE_GLOBAL_ARRAYS
/* png_libpng_ver was changed to a function in version 1.0.5c */ /* png_libpng_ver was changed to a function in version 1.0.5c */
char png_libpng_ver[12] = "1.0.5k"; const char png_libpng_ver[18] = "1.2.1";
/* png_sig was changed to a function in version 1.0.5c */ /* png_sig was changed to a function in version 1.0.5c */
/* Place to hold the signature string for a PNG file. */ /* Place to hold the signature string for a PNG file. */
png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10}; const png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
/* Invoke global declarations for constant strings for known chunk types */ /* Invoke global declarations for constant strings for known chunk types */
PNG_IHDR; PNG_IHDR;
@@ -51,32 +52,33 @@ PNG_zTXt;
/* arrays to facilitate easy interlacing - use pass (0 - 6) as index */ /* arrays to facilitate easy interlacing - use pass (0 - 6) as index */
/* start of interlace block */ /* start of interlace block */
int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; const int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
/* offset to next interlace block */ /* offset to next interlace block */
int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; const int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
/* start of interlace block in the y direction */ /* start of interlace block in the y direction */
int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1}; const int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
/* offset to next interlace block in the y direction */ /* offset to next interlace block in the y direction */
int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2}; const int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
/* Width of interlace block. This is not currently used - if you need /* width of interlace block (used in assembler routines only) */
* it, uncomment it here and in png.h #ifdef PNG_HAVE_ASSEMBLER_COMBINE_ROW
int FARDATA png_pass_width[] = {8, 4, 4, 2, 2, 1, 1}; const int FARDATA png_pass_width[] = {8, 4, 4, 2, 2, 1, 1};
*/ #endif
/* Height of interlace block. This is not currently used - if you need /* Height of interlace block. This is not currently used - if you need
* it, uncomment it here and in png.h * it, uncomment it here and in png.h
int FARDATA png_pass_height[] = {8, 8, 4, 4, 2, 2, 1}; const 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}; const 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}; const int FARDATA png_pass_dsp_mask[]
= {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
#endif #endif
@@ -86,7 +88,7 @@ int FARDATA png_pass_dsp_mask[] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
* or write any of the magic bytes before it starts on the IHDR. * or write any of the magic bytes before it starts on the IHDR.
*/ */
void void PNGAPI
png_set_sig_bytes(png_structp png_ptr, int num_bytes) png_set_sig_bytes(png_structp png_ptr, int num_bytes)
{ {
png_debug(1, "in png_set_sig_bytes\n"); png_debug(1, "in png_set_sig_bytes\n");
@@ -104,7 +106,7 @@ png_set_sig_bytes(png_structp png_ptr, int num_bytes)
* respectively, to be less than, to match, or be greater than the correct * respectively, to be less than, to match, or be greater than the correct
* PNG signature (this is the same behaviour as strcmp, memcmp, etc). * PNG signature (this is the same behaviour as strcmp, memcmp, etc).
*/ */
int int PNGAPI
png_sig_cmp(png_bytep sig, png_size_t start, png_size_t num_to_check) png_sig_cmp(png_bytep sig, png_size_t start, png_size_t num_to_check)
{ {
png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10}; png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
@@ -126,19 +128,20 @@ png_sig_cmp(png_bytep sig, png_size_t start, png_size_t num_to_check)
* to check a partial signature. This function might be removed in the * to check a partial signature. This function might be removed in the
* future - use png_sig_cmp(). Returns true (nonzero) if the file is a PNG. * future - use png_sig_cmp(). Returns true (nonzero) if the file is a PNG.
*/ */
int int PNGAPI
png_check_sig(png_bytep sig, int num) png_check_sig(png_bytep sig, int num)
{ {
return ((int)!png_sig_cmp(sig, (png_size_t)0, (png_size_t)num)); return ((int)!png_sig_cmp(sig, (png_size_t)0, (png_size_t)num));
} }
/* Function to allocate memory for zlib. */ /* Function to allocate memory for zlib and clear it to 0. */
voidpf voidpf /* PRIVATE */
png_zalloc(voidpf png_ptr, uInt items, uInt size) png_zalloc(voidpf png_ptr, uInt items, uInt size)
{ {
png_uint_32 num_bytes = (png_uint_32)items * size; png_uint_32 num_bytes = (png_uint_32)items * size;
png_voidp ptr = (png_voidp)png_malloc((png_structp)png_ptr, num_bytes); png_voidp ptr = (png_voidp)png_malloc((png_structp)png_ptr, num_bytes);
#ifndef PNG_NO_ZALLOC_ZERO
if (num_bytes > (png_uint_32)0x8000L) if (num_bytes > (png_uint_32)0x8000L)
{ {
png_memset(ptr, 0, (png_size_t)0x8000L); png_memset(ptr, 0, (png_size_t)0x8000L);
@@ -149,11 +152,12 @@ png_zalloc(voidpf png_ptr, uInt items, uInt size)
{ {
png_memset(ptr, 0, (png_size_t)num_bytes); png_memset(ptr, 0, (png_size_t)num_bytes);
} }
#endif
return ((voidpf)ptr); return ((voidpf)ptr);
} }
/* function to free memory for zlib */ /* function to free memory for zlib */
void void /* PRIVATE */
png_zfree(voidpf png_ptr, voidpf ptr) png_zfree(voidpf png_ptr, voidpf ptr)
{ {
png_free((png_structp)png_ptr, (png_voidp)ptr); png_free((png_structp)png_ptr, (png_voidp)ptr);
@@ -162,7 +166,7 @@ png_zfree(voidpf png_ptr, voidpf ptr)
/* Reset the CRC variable to 32 bits of 1's. Care must be taken /* 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 void /* PRIVATE */
png_reset_crc(png_structp png_ptr) png_reset_crc(png_structp png_ptr)
{ {
png_ptr->crc = crc32(0, Z_NULL, 0); png_ptr->crc = crc32(0, Z_NULL, 0);
@@ -173,7 +177,7 @@ png_reset_crc(png_structp png_ptr)
* also check that this data will actually be used before going to the * also check that this data will actually be used before going to the
* trouble of calculating it. * trouble of calculating it.
*/ */
void void /* PRIVATE */
png_calculate_crc(png_structp png_ptr, png_bytep ptr, png_size_t length) png_calculate_crc(png_structp png_ptr, png_bytep ptr, png_size_t length)
{ {
int need_crc = 1; int need_crc = 1;
@@ -200,7 +204,7 @@ png_calculate_crc(png_structp png_ptr, png_bytep ptr, png_size_t length)
* and png_info_init() so that applications that want to use a shared * 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. * libpng don't have to be recompiled if png_info changes size.
*/ */
png_infop png_infop PNGAPI
png_create_info_struct(png_structp png_ptr) png_create_info_struct(png_structp png_ptr)
{ {
png_infop info_ptr; png_infop info_ptr;
@@ -208,14 +212,13 @@ png_create_info_struct(png_structp png_ptr)
png_debug(1, "in png_create_info_struct\n"); png_debug(1, "in png_create_info_struct\n");
if(png_ptr == NULL) return (NULL); if(png_ptr == NULL) return (NULL);
#ifdef PNG_USER_MEM_SUPPORTED #ifdef PNG_USER_MEM_SUPPORTED
if ((info_ptr = (png_infop)png_create_struct_2(PNG_STRUCT_INFO, info_ptr = (png_infop)png_create_struct_2(PNG_STRUCT_INFO,
png_ptr->malloc_fn)) != NULL) png_ptr->malloc_fn, png_ptr->mem_ptr);
#else #else
if ((info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO)) != NULL) info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
#endif #endif
{ if (info_ptr != NULL)
png_info_init(info_ptr); png_info_init_3(&info_ptr, sizeof(png_info));
}
return (info_ptr); return (info_ptr);
} }
@@ -225,7 +228,7 @@ png_create_info_struct(png_structp png_ptr)
* png_destroy_write_struct() to free an info struct, but this may be * png_destroy_write_struct() to free an info struct, but this may be
* useful for some applications. * useful for some applications.
*/ */
void void PNGAPI
png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr) png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr)
{ {
png_infop info_ptr = NULL; png_infop info_ptr = NULL;
@@ -239,11 +242,12 @@ png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr)
png_info_destroy(png_ptr, info_ptr); png_info_destroy(png_ptr, info_ptr);
#ifdef PNG_USER_MEM_SUPPORTED #ifdef PNG_USER_MEM_SUPPORTED
png_destroy_struct_2((png_voidp)info_ptr, png_ptr->free_fn); png_destroy_struct_2((png_voidp)info_ptr, png_ptr->free_fn,
png_ptr->mem_ptr);
#else #else
png_destroy_struct((png_voidp)info_ptr); png_destroy_struct((png_voidp)info_ptr);
#endif #endif
*info_ptr_ptr = (png_infop)NULL; *info_ptr_ptr = NULL;
} }
} }
@@ -251,244 +255,314 @@ png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr)
* and applications using it are urged to use png_create_info_struct() * and applications using it are urged to use png_create_info_struct()
* instead. * instead.
*/ */
void #undef png_info_init
void PNGAPI
png_info_init(png_infop info_ptr) png_info_init(png_infop info_ptr)
{ {
png_debug(1, "in png_info_init\n"); /* We only come here via pre-1.0.12-compiled applications */
png_info_init_3(&info_ptr, 0);
}
void PNGAPI
png_info_init_3(png_infopp ptr_ptr, png_size_t png_info_struct_size)
{
png_infop info_ptr = *ptr_ptr;
png_debug(1, "in png_info_init_3\n");
if(sizeof(png_info) > png_info_struct_size)
{
png_destroy_struct(info_ptr);
info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
*ptr_ptr = info_ptr;
}
/* set everything to 0 */ /* set everything to 0 */
png_memset(info_ptr, 0, sizeof (png_info)); png_memset(info_ptr, 0, sizeof (png_info));
} }
#if defined(PNG_TEXT_SUPPORTED) #ifdef PNG_FREE_ME_SUPPORTED
/* free text item num or (if num == -1) all text items */ void PNGAPI
void png_data_freer(png_structp png_ptr, png_infop info_ptr,
png_free_text(png_structp png_ptr, png_infop info_ptr, int num) int freer, png_uint_32 mask)
{ {
png_debug(1, "in png_data_freer\n");
if (png_ptr == NULL || info_ptr == NULL) if (png_ptr == NULL || info_ptr == NULL)
return; return;
if(freer == PNG_DESTROY_WILL_FREE_DATA)
info_ptr->free_me |= mask;
else if(freer == PNG_USER_WILL_FREE_DATA)
info_ptr->free_me &= ~mask;
else
png_warning(png_ptr,
"Unknown freer parameter in png_data_freer.");
}
#endif
void PNGAPI
png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask,
int num)
{
png_debug(1, "in png_free_data\n");
if (png_ptr == NULL || info_ptr == NULL)
return;
#if defined(PNG_TEXT_SUPPORTED)
/* free text item num or (if num == -1) all text items */
#ifdef PNG_FREE_ME_SUPPORTED
if ((mask & PNG_FREE_TEXT) & info_ptr->free_me)
#else
if (mask & PNG_FREE_TEXT)
#endif
{
if (num != -1) if (num != -1)
{ {
if (info_ptr->text[num].key) if (info_ptr->text && info_ptr->text[num].key)
{ {
png_free(png_ptr, info_ptr->text[num].key); png_free(png_ptr, info_ptr->text[num].key);
info_ptr->text[num].key = NULL; info_ptr->text[num].key = NULL;
} }
} }
else if (info_ptr->text != NULL) else
{ {
int i; int i;
if(info_ptr->text != NULL)
{
for (i = 0; i < info_ptr->num_text; i++) for (i = 0; i < info_ptr->num_text; i++)
png_free_text(png_ptr, info_ptr, i); png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, i);
png_free(png_ptr, info_ptr->text); png_free(png_ptr, info_ptr->text);
info_ptr->text = NULL; info_ptr->text = NULL;
} info_ptr->num_text=0;
info_ptr->num_text=0;
} }
} }
#endif #endif
#if defined(PNG_tRNS_SUPPORTED) #if defined(PNG_tRNS_SUPPORTED)
/* free any tRNS entry */ /* free any tRNS entry */
void #ifdef PNG_FREE_ME_SUPPORTED
png_free_tRNS(png_structp png_ptr, png_infop info_ptr) if ((mask & PNG_FREE_TRNS) & info_ptr->free_me)
#else
if ((mask & PNG_FREE_TRNS) && (png_ptr->flags & PNG_FLAG_FREE_TRNS))
#endif
{ {
if (png_ptr == NULL || info_ptr == NULL) png_free(png_ptr, info_ptr->trans);
return; info_ptr->valid &= ~PNG_INFO_tRNS;
if (info_ptr->valid & PNG_INFO_tRNS) info_ptr->trans = NULL;
{
png_free(png_ptr, info_ptr->trans);
info_ptr->valid &= ~PNG_INFO_tRNS;
}
} }
#endif #endif
#if defined(PNG_sCAL_SUPPORTED) #if defined(PNG_sCAL_SUPPORTED)
/* free any sCAL entry */ /* free any sCAL entry */
void #ifdef PNG_FREE_ME_SUPPORTED
png_free_sCAL(png_structp png_ptr, png_infop info_ptr) if ((mask & PNG_FREE_SCAL) & info_ptr->free_me)
{
if (png_ptr == NULL || info_ptr == NULL)
return;
if (info_ptr->valid & PNG_INFO_sCAL)
{
#if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
png_free(png_ptr, info_ptr->scal_s_width);
png_free(png_ptr, info_ptr->scal_s_height);
#else #else
if(png_ptr != NULL) if (mask & PNG_FREE_SCAL)
/* silence a compiler warning */ ;
#endif #endif
info_ptr->valid &= ~PNG_INFO_sCAL; {
} #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
png_free(png_ptr, info_ptr->scal_s_width);
png_free(png_ptr, info_ptr->scal_s_height);
info_ptr->scal_s_width = NULL;
info_ptr->scal_s_height = NULL;
#endif
info_ptr->valid &= ~PNG_INFO_sCAL;
} }
#endif #endif
#if defined(PNG_pCAL_SUPPORTED) #if defined(PNG_pCAL_SUPPORTED)
/* free any pCAL entry */ /* free any pCAL entry */
void #ifdef PNG_FREE_ME_SUPPORTED
png_free_pCAL(png_structp png_ptr, png_infop info_ptr) if ((mask & PNG_FREE_PCAL) & info_ptr->free_me)
#else
if (mask & PNG_FREE_PCAL)
#endif
{ {
if (png_ptr == NULL || info_ptr == NULL) png_free(png_ptr, info_ptr->pcal_purpose);
return; png_free(png_ptr, info_ptr->pcal_units);
if (info_ptr->valid & PNG_INFO_pCAL) info_ptr->pcal_purpose = NULL;
{ info_ptr->pcal_units = NULL;
png_free(png_ptr, info_ptr->pcal_purpose); if (info_ptr->pcal_params != NULL)
png_free(png_ptr, info_ptr->pcal_units); {
if (info_ptr->pcal_params != NULL) int i;
{ for (i = 0; i < (int)info_ptr->pcal_nparams; i++)
int i; {
for (i = 0; i < (int)info_ptr->pcal_nparams; i++) png_free(png_ptr, info_ptr->pcal_params[i]);
{ info_ptr->pcal_params[i]=NULL;
png_free(png_ptr, info_ptr->pcal_params[i]); }
} png_free(png_ptr, info_ptr->pcal_params);
png_free(png_ptr, info_ptr->pcal_params); info_ptr->pcal_params = NULL;
} }
info_ptr->valid &= ~PNG_INFO_pCAL; info_ptr->valid &= ~PNG_INFO_pCAL;
}
} }
#endif #endif
#if defined(PNG_iCCP_SUPPORTED) #if defined(PNG_iCCP_SUPPORTED)
/* free any iCCP entry */ /* free any iCCP entry */
void #ifdef PNG_FREE_ME_SUPPORTED
png_free_iCCP(png_structp png_ptr, png_infop info_ptr) if ((mask & PNG_FREE_ICCP) & info_ptr->free_me)
#else
if (mask & PNG_FREE_ICCP)
#endif
{ {
if (png_ptr == NULL || info_ptr == NULL) png_free(png_ptr, info_ptr->iccp_name);
return; png_free(png_ptr, info_ptr->iccp_profile);
if (info_ptr->valid & PNG_INFO_iCCP) info_ptr->iccp_name = NULL;
{ info_ptr->iccp_profile = NULL;
png_free(png_ptr, info_ptr->iccp_name); info_ptr->valid &= ~PNG_INFO_iCCP;
png_free(png_ptr, info_ptr->iccp_profile);
info_ptr->valid &= ~PNG_INFO_iCCP;
}
} }
#endif #endif
#if defined(PNG_sPLT_SUPPORTED) #if defined(PNG_sPLT_SUPPORTED)
/* free a given sPLT entry, or (if num == -1) all sPLT entries */ /* free a given sPLT entry, or (if num == -1) all sPLT entries */
void #ifdef PNG_FREE_ME_SUPPORTED
png_free_spalettes(png_structp png_ptr, png_infop info_ptr, int num) if ((mask & PNG_FREE_SPLT) & info_ptr->free_me)
#else
if (mask & PNG_FREE_SPLT)
#endif
{ {
if (png_ptr == NULL || info_ptr == NULL)
return;
if (num != -1) if (num != -1)
{ {
png_free(png_ptr, info_ptr->splt_palettes[num].name); if(info_ptr->splt_palettes)
png_free(png_ptr, info_ptr->splt_palettes[num].entries); {
info_ptr->valid &=~ PNG_INFO_sPLT; png_free(png_ptr, info_ptr->splt_palettes[num].name);
png_free(png_ptr, info_ptr->splt_palettes[num].entries);
info_ptr->splt_palettes[num].name = NULL;
info_ptr->splt_palettes[num].entries = NULL;
}
} }
else else
{ {
int i; if(info_ptr->splt_palettes_num)
{
int i;
for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
png_free_data(png_ptr, info_ptr, PNG_FREE_SPLT, i);
if(info_ptr->splt_palettes_num == 0) png_free(png_ptr, info_ptr->splt_palettes);
return; info_ptr->splt_palettes = NULL;
info_ptr->splt_palettes_num = 0;
for (i = 0; i < (int)info_ptr->splt_palettes_num; i++) }
png_free_spalettes(png_ptr, info_ptr, i); info_ptr->valid &= ~PNG_INFO_sPLT;
png_free(png_ptr, info_ptr->splt_palettes);
info_ptr->splt_palettes_num = 0;
} }
} }
#endif #endif
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
void #ifdef PNG_FREE_ME_SUPPORTED
png_free_unknown_chunks(png_structp png_ptr, png_infop info_ptr, int num) if ((mask & PNG_FREE_UNKN) & info_ptr->free_me)
#else
if (mask & PNG_FREE_UNKN)
#endif
{ {
if (png_ptr == NULL || info_ptr == NULL)
return;
if (num != -1) if (num != -1)
{ {
png_free(png_ptr, info_ptr->unknown_chunks[num].data); if(info_ptr->unknown_chunks)
info_ptr->unknown_chunks[num].data = NULL; {
png_free(png_ptr, info_ptr->unknown_chunks[num].data);
info_ptr->unknown_chunks[num].data = NULL;
}
} }
else else
{ {
int i; int i;
if(info_ptr->unknown_chunks_num == 0) if(info_ptr->unknown_chunks_num)
return; {
for (i = 0; i < (int)info_ptr->unknown_chunks_num; i++)
png_free_data(png_ptr, info_ptr, PNG_FREE_UNKN, i);
for (i = 0; i < (int)info_ptr->unknown_chunks_num; i++) png_free(png_ptr, info_ptr->unknown_chunks);
png_free_unknown_chunks(png_ptr, info_ptr, i); info_ptr->unknown_chunks = NULL;
info_ptr->unknown_chunks_num = 0;
png_free(png_ptr, info_ptr->unknown_chunks); }
info_ptr->unknown_chunks_num = 0;
}
}
void
png_free_chunk_list(png_structp png_ptr)
{
if (png_ptr == NULL)
return;
if (png_ptr->num_chunk_list)
{
png_free(png_ptr, png_ptr->chunk_list);
png_ptr->num_chunk_list=0;
} }
} }
#endif #endif
#if defined(PNG_hIST_SUPPORTED) #if defined(PNG_hIST_SUPPORTED)
/* free any hIST entry */ /* free any hIST entry */
void #ifdef PNG_FREE_ME_SUPPORTED
png_free_hIST(png_structp png_ptr, png_infop info_ptr) if ((mask & PNG_FREE_HIST) & info_ptr->free_me)
#else
if ((mask & PNG_FREE_HIST) && (png_ptr->flags & PNG_FLAG_FREE_HIST))
#endif
{ {
if (png_ptr == NULL || info_ptr == NULL) png_free(png_ptr, info_ptr->hist);
return; info_ptr->hist = NULL;
if (info_ptr->valid & PNG_INFO_hIST) info_ptr->valid &= ~PNG_INFO_hIST;
{
png_free(png_ptr, info_ptr->hist);
info_ptr->valid &= ~PNG_INFO_hIST;
}
} }
#endif #endif
/* free any PLTE entry that was internally allocated */
#ifdef PNG_FREE_ME_SUPPORTED
if ((mask & PNG_FREE_PLTE) & info_ptr->free_me)
#else
if ((mask & PNG_FREE_PLTE) && (png_ptr->flags & PNG_FLAG_FREE_PLTE))
#endif
{
png_zfree(png_ptr, info_ptr->palette);
info_ptr->palette = NULL;
info_ptr->valid &= ~PNG_INFO_PLTE;
info_ptr->num_palette = 0;
}
#if defined(PNG_INFO_IMAGE_SUPPORTED)
/* free any image bits attached to the info structure */
#ifdef PNG_FREE_ME_SUPPORTED
if ((mask & PNG_FREE_ROWS) & info_ptr->free_me)
#else
if (mask & PNG_FREE_ROWS)
#endif
{
if(info_ptr->row_pointers)
{
int row;
for (row = 0; row < (int)info_ptr->height; row++)
{
png_free(png_ptr, info_ptr->row_pointers[row]);
info_ptr->row_pointers[row]=NULL;
}
png_free(png_ptr, info_ptr->row_pointers);
info_ptr->row_pointers=NULL;
}
info_ptr->valid &= ~PNG_INFO_IDAT;
}
#endif
#ifdef PNG_FREE_ME_SUPPORTED
if(num == -1)
info_ptr->free_me &= ~mask;
else
info_ptr->free_me &= ~(mask & ~PNG_FREE_MUL);
#endif
}
/* This is an internal routine to free any memory that the info struct is /* This is an internal routine to free any memory that the info struct is
* pointing to before re-using it or freeing the struct itself. Recall * pointing to before re-using it or freeing the struct itself. Recall
* that png_free() checks for NULL pointers for us. * that png_free() checks for NULL pointers for us.
*/ */
void void /* PRIVATE */
png_info_destroy(png_structp png_ptr, png_infop info_ptr) png_info_destroy(png_structp png_ptr, png_infop info_ptr)
{ {
png_debug(1, "in png_info_destroy\n"); png_debug(1, "in png_info_destroy\n");
#if defined(PNG_READ_TEXT_SUPPORTED)
png_free_text(png_ptr, info_ptr, -1); png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
if (png_ptr->num_chunk_list)
{
png_free(png_ptr, png_ptr->chunk_list);
png_ptr->chunk_list=NULL;
png_ptr->num_chunk_list=0;
}
#endif #endif
#if defined(PNG_READ_tRNS_SUPPORTED)
png_free_tRNS(png_ptr, info_ptr); png_info_init_3(&info_ptr, sizeof(png_info));
#endif
#if defined(PNG_READ_sCAL_SUPPORTED)
png_free_sCAL(png_ptr, info_ptr);
#endif
#if defined(PNG_READ_pCAL_SUPPORTED)
png_free_pCAL(png_ptr, info_ptr);
#endif
#if defined(PNG_READ_iCCP_SUPPORTED)
png_free_iCCP(png_ptr, info_ptr);
#endif
#if defined(PNG_READ_sPLT_SUPPORTED)
png_free_spalettes(png_ptr, info_ptr, -1);
#endif
#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
png_free_unknown_chunks(png_ptr, info_ptr, -1);
png_free_chunk_list(png_ptr);
#endif
#if defined(PNG_hIST_SUPPORTED)
png_free_hIST(png_ptr, info_ptr);
#endif
png_info_init(info_ptr);
} }
/* This function returns a pointer to the io_ptr associated with the user /* This function returns a pointer to the io_ptr associated with the user
* functions. The application should free any memory associated with this * functions. The application should free any memory associated with this
* pointer before png_write_destroy() or png_read_destroy() are called. * pointer before png_write_destroy() or png_read_destroy() are called.
*/ */
png_voidp png_voidp PNGAPI
png_get_io_ptr(png_structp png_ptr) png_get_io_ptr(png_structp png_ptr)
{ {
return (png_ptr->io_ptr); return (png_ptr->io_ptr);
@@ -497,10 +571,12 @@ png_get_io_ptr(png_structp png_ptr)
#if !defined(PNG_NO_STDIO) #if !defined(PNG_NO_STDIO)
/* Initialize the default input/output functions for the PNG file. If you /* 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() * 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(). * or png_set_write_fn() instead of png_init_io(). If you have defined
* PNG_NO_STDIO, you must use a function of your own because "FILE *" isn't
* necessarily available.
*/ */
void void PNGAPI
png_init_io(png_structp png_ptr, FILE *fp) png_init_io(png_structp png_ptr, png_FILE_p fp)
{ {
png_debug(1, "in png_init_io\n"); png_debug(1, "in png_init_io\n");
png_ptr->io_ptr = (png_voidp)fp; png_ptr->io_ptr = (png_voidp)fp;
@@ -511,7 +587,7 @@ png_init_io(png_structp png_ptr, FILE *fp)
/* Convert the supplied time into an RFC 1123 string suitable for use in /* Convert the supplied time into an RFC 1123 string suitable for use in
* a "Creation Time" or other text-based time string. * a "Creation Time" or other text-based time string.
*/ */
png_charp png_charp PNGAPI
png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime) png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime)
{ {
static PNG_CONST char short_months[12][4] = static PNG_CONST char short_months[12][4] =
@@ -524,45 +600,56 @@ png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime)
sizeof(char))); sizeof(char)));
} }
#if defined(_WIN32_WCE)
{
wchar_t time_buf[29];
wsprintf(time_buf, TEXT("%d %S %d %02d:%02d:%02d +0000"),
ptime->day % 32, short_months[(ptime->month - 1) % 12],
ptime->year, ptime->hour % 24, ptime->minute % 60,
ptime->second % 61);
WideCharToMultiByte(CP_ACP, 0, time_buf, -1, png_ptr->time_buffer, 29,
NULL, NULL);
}
#else
#ifdef USE_FAR_KEYWORD #ifdef USE_FAR_KEYWORD
{ {
char near_time_buf[29]; char near_time_buf[29];
sprintf(near_time_buf, "%d %s %d %02d:%02d:%02d +0000", sprintf(near_time_buf, "%d %s %d %02d:%02d:%02d +0000",
ptime->day % 32, short_months[(ptime->month - 1) % 12], ptime->day % 32, short_months[(ptime->month - 1) % 12],
ptime->year, ptime->hour % 24, ptime->minute % 60, ptime->year, ptime->hour % 24, ptime->minute % 60,
ptime->second % 61); ptime->second % 61);
png_memcpy(png_ptr->time_buffer, near_time_buf, png_memcpy(png_ptr->time_buffer, near_time_buf,
29*sizeof(char)); 29*sizeof(char));
} }
#else #else
sprintf(png_ptr->time_buffer, "%d %s %d %02d:%02d:%02d +0000", sprintf(png_ptr->time_buffer, "%d %s %d %02d:%02d:%02d +0000",
ptime->day % 32, short_months[(ptime->month - 1) % 12], ptime->day % 32, short_months[(ptime->month - 1) % 12],
ptime->year, ptime->hour % 24, ptime->minute % 60, ptime->year, ptime->hour % 24, ptime->minute % 60,
ptime->second % 61); ptime->second % 61);
#endif #endif
#endif /* _WIN32_WCE */
return ((png_charp)png_ptr->time_buffer); return ((png_charp)png_ptr->time_buffer);
} }
#endif /* PNG_TIME_RFC1123_SUPPORTED */ #endif /* PNG_TIME_RFC1123_SUPPORTED */
#if 0
/* Signature string for a PNG file. */ /* Signature string for a PNG file. */
png_bytep png_bytep PNGAPI
png_sig_bytes(png_structp png_ptr) png_sig_bytes(void)
{ {
const png_byte png_sig_numbers[9] = {137, 80, 78, 71, 13, 10, 26, 10, 0}; return ((png_bytep)"\211\120\116\107\015\012\032\012");
if (png_ptr == NULL) /* silence compiler warning */
return ((png_bytep) strdup((png_const_charp)png_sig_numbers));
return ((png_bytep) strdup((png_const_charp)png_sig_numbers));
} }
#endif
png_charp png_charp PNGAPI
png_get_copyright(png_structp png_ptr) png_get_copyright(png_structp png_ptr)
{ {
if (png_ptr != NULL || png_ptr == NULL) /* silence compiler warning */ if (png_ptr != NULL || png_ptr == NULL) /* silence compiler warning */
return ("\n libpng version 1.0.5k - December 27, 1999\n\ return ((png_charp) "\n libpng version 1.2.1 - December 12, 2001\n\
Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.\n\ Copyright (c) 1998-2001 Glenn Randers-Pehrson\n\
Copyright (c) 1996, 1997 Andreas Dilger\n\ Copyright (c) 1996, 1997 Andreas Dilger\n\
Copyright (c) 1998, 1999 Glenn Randers-Pehrson\n"); Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.\n");
return (""); return ((png_charp) "");
} }
/* The following return the library version as a short string in the /* The following return the library version as a short string in the
@@ -571,44 +658,35 @@ png_get_copyright(png_structp png_ptr)
* in png.h. * in png.h.
*/ */
png_charp png_charp PNGAPI
png_get_libpng_ver(png_structp png_ptr) png_get_libpng_ver(png_structp png_ptr)
{ {
/* Version of *.c files used when building libpng */ /* Version of *.c files used when building libpng */
if(png_ptr != NULL) /* silence compiler warning about unused png_ptr */ if(png_ptr != NULL) /* silence compiler warning about unused png_ptr */
return("1.0.5k"); return((png_charp) "1.2.1");
return("1.0.5k"); return((png_charp) "1.2.1");
} }
png_charp png_charp PNGAPI
png_get_header_ver(png_structp png_ptr) png_get_header_ver(png_structp png_ptr)
{ {
/* Version of *.h files used when building libpng */ /* Version of *.h files used when building libpng */
if(png_ptr != NULL) /* silence compiler warning about unused png_ptr */ if(png_ptr != NULL) /* silence compiler warning about unused png_ptr */
return(PNG_LIBPNG_VER_STRING); return((png_charp) PNG_LIBPNG_VER_STRING);
return(PNG_LIBPNG_VER_STRING); return((png_charp) PNG_LIBPNG_VER_STRING);
} }
png_charp png_charp PNGAPI
png_get_header_version(png_structp png_ptr) png_get_header_version(png_structp png_ptr)
{ {
/* Returns longer string containing both version and date */ /* Returns longer string containing both version and date */
if(png_ptr != NULL) /* silence compiler warning about unused png_ptr */ if(png_ptr != NULL) /* silence compiler warning about unused png_ptr */
return(PNG_HEADER_VERSION_STRING); return((png_charp) PNG_HEADER_VERSION_STRING);
return(PNG_HEADER_VERSION_STRING); return((png_charp) PNG_HEADER_VERSION_STRING);
}
/* Generate a compiler error if there is an old png.h in the search path. */
void
png_check_version
(version_1_0_5k png_h_is_not_version_1_0_5k)
{
if(png_h_is_not_version_1_0_5k == NULL)
return;
} }
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
int int /* PRIVATE */
png_handle_as_unknown(png_structp png_ptr, png_bytep chunk_name) png_handle_as_unknown(png_structp png_ptr, png_bytep chunk_name)
{ {
/* check chunk_name and return "keep" value if it's on the list, else 0 */ /* check chunk_name and return "keep" value if it's on the list, else 0 */
@@ -623,3 +701,77 @@ png_handle_as_unknown(png_structp png_ptr, png_bytep chunk_name)
return 0; return 0;
} }
#endif #endif
/* This function, added to libpng-1.0.6g, is untested. */
int PNGAPI
png_reset_zstream(png_structp png_ptr)
{
return (inflateReset(&png_ptr->zstream));
}
/* This function was added to libpng-1.0.7 */
png_uint_32 PNGAPI
png_access_version_number(void)
{
/* Version of *.c files used when building libpng */
return((png_uint_32) 10201L);
}
#if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
/* GRR: could add this: && defined(PNG_MMX_CODE_SUPPORTED) */
/* this INTERNAL function was added to libpng 1.2.0 */
void /* PRIVATE */
png_init_mmx_flags (png_structp png_ptr)
{
png_ptr->mmx_rowbytes_threshold = 0;
png_ptr->mmx_bitdepth_threshold = 0;
# if (defined(PNG_USE_PNGVCRD) || defined(PNG_USE_PNGGCCRD))
png_ptr->asm_flags |= PNG_ASM_FLAG_MMX_SUPPORT_COMPILED;
if (png_mmx_support()) {
png_ptr->asm_flags |= PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU
# ifdef PNG_HAVE_ASSEMBLER_COMBINE_ROW
| PNG_ASM_FLAG_MMX_READ_COMBINE_ROW
# endif
# ifdef PNG_HAVE_ASSEMBLER_READ_INTERLACE
| PNG_ASM_FLAG_MMX_READ_INTERLACE
# endif
# ifndef PNG_HAVE_ASSEMBLER_READ_FILTER_ROW
;
# else
| PNG_ASM_FLAG_MMX_READ_FILTER_SUB
| PNG_ASM_FLAG_MMX_READ_FILTER_UP
| PNG_ASM_FLAG_MMX_READ_FILTER_AVG
| PNG_ASM_FLAG_MMX_READ_FILTER_PAETH ;
png_ptr->mmx_rowbytes_threshold = PNG_MMX_ROWBYTES_THRESHOLD_DEFAULT;
png_ptr->mmx_bitdepth_threshold = PNG_MMX_BITDEPTH_THRESHOLD_DEFAULT;
# endif
} else {
png_ptr->asm_flags &= ~( PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU
| PNG_MMX_READ_FLAGS
| PNG_MMX_WRITE_FLAGS );
}
# else /* !((PNGVCRD || PNGGCCRD) && PNG_ASSEMBLER_CODE_SUPPORTED)) */
/* clear all MMX flags; no support is compiled in */
png_ptr->asm_flags &= ~( PNG_MMX_FLAGS );
# endif /* ?(PNGVCRD || PNGGCCRD) */
}
#endif /* !(PNG_ASSEMBLER_CODE_SUPPORTED) */
/* this function was added to libpng 1.2.0 */
#if !defined(PNG_USE_PNGGCCRD) && \
!(defined(PNG_ASSEMBLER_CODE_SUPPORTED) && defined(PNG_USE_PNGVCRD))
int PNGAPI
png_mmx_support(void)
{
return -1;
}
#endif

1203
png.h

File diff suppressed because it is too large Load Diff

View File

@@ -1,32 +1,11 @@
/* pngasmrd.h - assembler version of utilities to read a PNG file /* pngasmrd.h - assembler version of utilities to read a PNG file
* *
* libpng 1.0.5k - December 27, 1999 * libpng 1.2.1 - December 12, 2001
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1999 Glenn Randers-Pehrson * Copyright (c) 2001 Glenn Randers-Pehrson
* *
*/ */
#ifdef PNG_ASSEMBLER_CODE_SUPPORTED /* This file is obsolete in libpng-1.0.9 and later; its contents now appear
* at the end of pngconf.h.
/* Set this in the makefile for VC++ on Pentium, not in pngconf.h */
#ifdef PNG_USE_PNGVCRD
/* Platform must be Pentium. Makefile must assemble and load pngvcrd.c .
* MMX will be detected at run time and used if present.
*/ */
#define PNG_HAVE_ASSEMBLER_COMBINE_ROW
#define PNG_HAVE_ASSEMBLER_READ_INTERLACE
#define PNG_HAVE_ASSEMBLER_READ_FILTER_ROW
#endif
/* Set this in the makefile for gcc on Pentium, not in pngconf.h */
#ifdef PNG_USE_PNGGCCRD
/* Platform must be Pentium. Makefile must assemble and load pnggccrd.c
* (not available in libpng 1.0.5k).
* MMX will be detected at run time and used if present.
*/
#define PNG_HAVE_ASSEMBLER_COMBINE_ROW
#define PNG_HAVE_ASSEMBLER_READ_INTERLACE
#define PNG_HAVE_ASSEMBLER_READ_FILTER_ROW
#endif
#endif

1020
pngconf.h

File diff suppressed because it is too large Load Diff

3370
pngcrush.c

File diff suppressed because it is too large Load Diff

View File

@@ -3,14 +3,51 @@
/* Special defines for pngcrush, mostly just to reduce the size of the /* Special defines for pngcrush, mostly just to reduce the size of the
static executable. */ static executable. */
#define PNG_NO_FLOAING_POINT_SUPPORTED /* undef this if you want to be able #ifndef PNGCRUSH_H
to reduce color to gray */ #define PNGCRUSH_H
#define PNG_NO_READ_cHRM
#define PNG_NO_WRITE_cHRM /*
#include <malloc.h>
*/
#ifdef PNG_LIBPNG_VER
#define PNGCRUSH_LIBPNG_VER PNG_LIBPNG_VER
#else
/* This must agree with PNG_LIBPNG_VER; you have to define it manually
here if you are using libpng-1.0.6h or earlier */
#define PNGCRUSH_LIBPNG_VER 10007
#endif
#if !defined(PNG_USE_PNGGCCRD) && !defined(PNG_USE_PNGVCRD) && \
!defined(PNG_NO_ASSEMBLER_CODE)
#define PNG_NO_ASSEMBLER_CODE
#endif
#ifndef PNG_NO_ZALLOC_ZERO
# define PNG_NO_ZALLOC_ZERO /* speeds it up a little */
#endif
#ifndef PNG_USER_MEM_SUPPORTED
# define PNG_USER_MEM_SUPPORTED
#endif
#define PNG_MNG_FEATURES_SUPPORTED /* extra filter type */
#ifndef PNG_NO_LEGACY_SUPPORTED
# define PNG_NO_LEGACY_SUPPORTED
#endif
#ifndef PNG_SETJMP_NOT_SUPPORTED
# define PNG_SETJMP_NOT_SUPPORTED
#endif
#if PNGCRUSH_LIBPNG_VER > 10006
#define PNG_NO_FLOATING_POINT_SUPPORTED
#define PNG_READ_GRAY_TO_RGB_SUPPORTED
#endif
#define PNG_NO_READ_hIST #define PNG_NO_READ_hIST
#define PNG_NO_WRITE_hIST #define PNG_NO_WRITE_hIST
#define PNG_NO_READ_iCCP
#define PNG_NO_WRITE_iCCP
#define PNG_NO_READ_pCAL #define PNG_NO_READ_pCAL
#define PNG_NO_WRITE_pCAL #define PNG_NO_WRITE_pCAL
#define PNG_NO_READ_sCAL #define PNG_NO_READ_sCAL
@@ -20,25 +57,60 @@
#define PNG_NO_READ_tIME #define PNG_NO_READ_tIME
#define PNG_NO_WRITE_tIME #define PNG_NO_WRITE_tIME
#define PNG_NO_EASY_ACCESS #define PNG_NO_INFO_IMAGE
#define PNG_NO_READ_USER_CHUNKS
#define PNG_EASY_ACCESS
#define PNG_NO_READ_DITHER
#define PNG_NO_READ_EMPTY_PLTE #define PNG_NO_READ_EMPTY_PLTE
#define PNG_NO_WRITE_TRANSFORMS #define PNG_NO_WRITE_TRANSFORMS
#define PNG_NO_PROGRESSIVE_READ #define PNG_NO_PROGRESSIVE_READ
#define PNG_NO_WRITE_WEIGHTED_FILTER #define PNG_NO_WRITE_WEIGHTED_FILTER
#define PNG_NO_READ_COMPOSITED_NODIV
#define PNG_READ_USER_TRANSFORM_SUPPORTED #define PNG_READ_USER_TRANSFORM_SUPPORTED
#define PNG_READ_STRIP_ALPHA_SUPPORTED #define PNG_READ_STRIP_ALPHA_SUPPORTED
#define PNG_READ_EXPAND_SUPPORTED #define PNG_READ_EXPAND_SUPPORTED
#define PNG_READ_FILLER_SUPPORTED #define PNG_READ_FILLER_SUPPORTED
#define PNG_READ_PACK_SUPPORTED
#define PNG_READ_SHIFT_SUPPORTED
#define PNG_WRITE_PACK_SUPPORTED
#define PNG_WRITE_SHIFT_SUPPORTED
#if (PNGCRUSH_LIBPNG_VER > 10002)
/* versions 0.96 through 1.0.2 have a stub png_rgb_to_gray() with the
* wrong number of parameters */
# define PNG_READ_RGB_TO_GRAY_SUPPORTED
#endif
#ifndef PNG_NO_iTXt_SUPPORTED
# define PNG_iTXt_SUPPORTED
#endif
#ifndef PNG_NO_FLOATING_POINT_SUPPORTED #ifndef PNG_NO_FLOATING_POINT_SUPPORTED
# define PNG_READ_GRAY_TO_RGB_SUPPORTED # define PNG_READ_GRAY_TO_RGB_SUPPORTED
# define PNG_READ_RGB_TO_GRAY_SUPPORTED
# define PNG_READ_BACKGROUND_SUPPORTED # define PNG_READ_BACKGROUND_SUPPORTED
# define PNG_READ_GAMMA_SUPPORTED # define PNG_READ_GAMMA_SUPPORTED
#else #else
# define PNG_NO_READ_RGB_TO_GRAY # if (PNGCRUSH_LIBPNG_VER < 10007)
# define PNG_NO_READ_RGB_TO_GRAY
# endif
#endif
/* Changed in version 0.99 */
#if PNGCRUSH_LIBPNG_VER < 99
#undef PNG_CONST
#ifndef PNG_NO_CONST
# define PNG_CONST const
#else
# define PNG_CONST
#endif
#endif
/* This allows png_default_error() to return, when it is called after our
own exception handling, which only returns after "Too many IDAT's",
or anything else that we might want to handle as a warning instead of
an error. */
#define PNG_ABORT()
#endif #endif
#define PNG_ZBUF_SIZE 524288 /* increases the IDAT size */
/*
#define PNG_NO_GLOBAL_ARRAYS
*/
#define TOO_FAR 32767 /* Improves zlib/deflate compression */

View File

@@ -1,11 +1,11 @@
/* pngerror.c - stub functions for i/o and memory allocation /* pngerror.c - stub functions for i/o and memory allocation
* *
* libpng 1.0.5k - December 27, 1999 * libpng 1.2.1 - December 12, 2001
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. * Copyright (c) 1998-2001 Glenn Randers-Pehrson
* Copyright (c) 1996, 1997 Andreas Dilger * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
* *
* This file provides a location for all error handling. Users who * This file provides a location for all error handling. Users who
* need special error handling are expected to write replacement functions * need special error handling are expected to write replacement functions
@@ -16,9 +16,11 @@
#define PNG_INTERNAL #define PNG_INTERNAL
#include "png.h" #include "png.h"
static void png_default_error PNGARG((png_structp png_ptr, static void /* PRIVATE */
png_default_error PNGARG((png_structp png_ptr,
png_const_charp message)); png_const_charp message));
static void png_default_warning PNGARG((png_structp png_ptr, static void /* PRIVATE */
png_default_warning PNGARG((png_structp png_ptr,
png_const_charp message)); png_const_charp message));
/* This function is called whenever there is a fatal error. This function /* This function is called whenever there is a fatal error. This function
@@ -26,9 +28,41 @@ static void png_default_warning PNGARG((png_structp png_ptr,
* you should supply a replacement error function and use png_set_error_fn() * you should supply a replacement error function and use png_set_error_fn()
* to replace the error function at run-time. * to replace the error function at run-time.
*/ */
void void PNGAPI
png_error(png_structp png_ptr, png_const_charp message) png_error(png_structp png_ptr, png_const_charp message)
{ {
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
char msg[16];
if (png_ptr->flags&(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
{
int offset = 0;
if (*message == '#')
{
for (offset=1; offset<15; offset++)
if (*(message+offset) == ' ')
break;
if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
{
int i;
for (i=0; i<offset-1; i++)
msg[i]=message[i+1];
msg[i]='\0';
message=msg;
}
else
message+=offset;
}
else
{
if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
{
msg[0]='0';
msg[1]='\0';
message=msg;
}
}
}
#endif
if (png_ptr->error_fn != NULL) if (png_ptr->error_fn != NULL)
(*(png_ptr->error_fn))(png_ptr, message); (*(png_ptr->error_fn))(png_ptr, message);
@@ -42,13 +76,25 @@ png_error(png_structp png_ptr, png_const_charp message)
* you should supply a replacement warning function and use * you should supply a replacement warning function and use
* png_set_error_fn() to replace the warning function at run-time. * png_set_error_fn() to replace the warning function at run-time.
*/ */
void void PNGAPI
png_warning(png_structp png_ptr, png_const_charp message) png_warning(png_structp png_ptr, png_const_charp message)
{ {
int offset = 0;
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
if (png_ptr->flags&(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
#endif
{
if (*message == '#')
{
for (offset=1; offset<15; offset++)
if (*(message+offset) == ' ')
break;
}
}
if (png_ptr->warning_fn != NULL) if (png_ptr->warning_fn != NULL)
(*(png_ptr->warning_fn))(png_ptr, message); (*(png_ptr->warning_fn))(png_ptr, (png_const_charp)(message+offset));
else else
png_default_warning(png_ptr, message); png_default_warning(png_ptr, (png_const_charp)(message+offset));
} }
/* These utilities are used internally to build an error message that relates /* These utilities are used internally to build an error message that relates
@@ -59,29 +105,35 @@ png_warning(png_structp png_ptr, png_const_charp message)
*/ */
#define isnonalpha(c) ((c) < 41 || (c) > 122 || ((c) > 90 && (c) < 97)) #define isnonalpha(c) ((c) < 41 || (c) > 122 || ((c) > 90 && (c) < 97))
static PNG_CONST char png_digit[16] = { static PNG_CONST char png_digit[16] = {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E',
}; 'F' };
static void static void /* PRIVATE */
png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp message) png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp
message)
{ {
int iout = 0, iin = 0; int iout = 0, iin = 0;
while (iin < 4) { while (iin < 4)
{
int c = png_ptr->chunk_name[iin++]; int c = png_ptr->chunk_name[iin++];
if (isnonalpha(c)) { if (isnonalpha(c))
{
buffer[iout++] = '['; buffer[iout++] = '[';
buffer[iout++] = png_digit[(c & 0xf0) >> 4]; buffer[iout++] = png_digit[(c & 0xf0) >> 4];
buffer[iout++] = png_digit[c & 0x0f]; buffer[iout++] = png_digit[c & 0x0f];
buffer[iout++] = ']'; buffer[iout++] = ']';
} else { }
else
{
buffer[iout++] = (png_byte)c; buffer[iout++] = (png_byte)c;
} }
} }
if (message == NULL) if (message == NULL)
buffer[iout] = 0; buffer[iout] = 0;
else { else
{
buffer[iout++] = ':'; buffer[iout++] = ':';
buffer[iout++] = ' '; buffer[iout++] = ' ';
png_memcpy(buffer+iout, message, 64); png_memcpy(buffer+iout, message, 64);
@@ -89,18 +141,18 @@ png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp message
} }
} }
void void PNGAPI
png_chunk_error(png_structp png_ptr, png_const_charp message) png_chunk_error(png_structp png_ptr, png_const_charp message)
{ {
char msg[16+64]; char msg[18+64];
png_format_buffer(png_ptr, msg, message); png_format_buffer(png_ptr, msg, message);
png_error(png_ptr, msg); png_error(png_ptr, msg);
} }
void void PNGAPI
png_chunk_warning(png_structp png_ptr, png_const_charp message) png_chunk_warning(png_structp png_ptr, png_const_charp message)
{ {
char msg[16+64]; char msg[18+64];
png_format_buffer(png_ptr, msg, message); png_format_buffer(png_ptr, msg, message);
png_warning(png_ptr, msg); png_warning(png_ptr, msg);
} }
@@ -110,21 +162,51 @@ png_chunk_warning(png_structp png_ptr, png_const_charp message)
* function is used by default, or if the program supplies NULL for the * function is used by default, or if the program supplies NULL for the
* error function pointer in png_set_error_fn(). * error function pointer in png_set_error_fn().
*/ */
static void static void /* PRIVATE */
png_default_error(png_structp png_ptr, png_const_charp message) png_default_error(png_structp png_ptr, png_const_charp message)
{ {
#ifndef PNG_NO_CONSOLE_IO #ifndef PNG_NO_CONSOLE_IO
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
if (*message == '#')
{
int offset;
char error_number[16];
for (offset=0; offset<15; offset++)
{
error_number[offset] = *(message+offset+1);
if (*(message+offset) == ' ')
break;
}
if((offset > 1) && (offset < 15))
{
error_number[offset-1]='\0';
fprintf(stderr, "libpng error no. %s: %s\n", error_number, message+offset);
}
else
fprintf(stderr, "libpng error: %s, offset=%d\n", message,offset);
}
else
#endif
fprintf(stderr, "libpng error: %s\n", message); fprintf(stderr, "libpng error: %s\n", message);
#else
if (message)
/* make compiler happy */ ;
#endif #endif
#ifdef USE_FAR_KEYWORD #ifdef PNG_SETJMP_SUPPORTED
# ifdef USE_FAR_KEYWORD
{ {
jmp_buf jmpbuf; jmp_buf jmpbuf;
png_memcpy(jmpbuf,png_ptr->jmpbuf,sizeof(jmp_buf)); png_memcpy(jmpbuf,png_ptr->jmpbuf,sizeof(jmp_buf));
longjmp(jmpbuf, 1); longjmp(jmpbuf, 1);
} }
#else # else
longjmp(png_ptr->jmpbuf, 1); longjmp(png_ptr->jmpbuf, 1);
# endif
#else
if (png_ptr)
/* make compiler happy */ ;
PNG_ABORT();
#endif #endif
} }
@@ -133,13 +215,38 @@ png_default_error(png_structp png_ptr, png_const_charp message)
* here if you don't want them to. In the default configuration, png_ptr is * here if you don't want them to. In the default configuration, png_ptr is
* not used, but it is passed in case it may be useful. * not used, but it is passed in case it may be useful.
*/ */
static void static void /* PRIVATE */
png_default_warning(png_structp png_ptr, png_const_charp message) png_default_warning(png_structp png_ptr, png_const_charp message)
{ {
#ifndef PNG_NO_CONSOLE_IO #ifndef PNG_NO_CONSOLE_IO
fprintf(stderr, "libpng warning: %s\n", message); # ifdef PNG_ERROR_NUMBERS_SUPPORTED
if (*message == '#')
{
int offset;
char warning_number[16];
for (offset=0; offset<15; offset++)
{
warning_number[offset]=*(message+offset+1);
if (*(message+offset) == ' ')
break;
}
if((offset > 1) && (offset < 15))
{
warning_number[offset-1]='\0';
fprintf(stderr, "libpng warning no. %s: %s\n", warning_number,
message+offset);
}
else
fprintf(stderr, "libpng warning: %s\n", message);
}
else
# endif
fprintf(stderr, "libpng warning: %s\n", message);
#else
if (message)
/* appease compiler */ ;
#endif #endif
if (png_ptr == NULL) if (png_ptr)
return; return;
} }
@@ -148,7 +255,7 @@ png_default_warning(png_structp png_ptr, png_const_charp message)
* return to the calling routine or serious problems will occur. The return * return to the calling routine or serious problems will occur. The return
* method used in the default routine calls longjmp(png_ptr->jmpbuf, 1) * method used in the default routine calls longjmp(png_ptr->jmpbuf, 1)
*/ */
void void PNGAPI
png_set_error_fn(png_structp png_ptr, png_voidp error_ptr, png_set_error_fn(png_structp png_ptr, png_voidp error_ptr,
png_error_ptr error_fn, png_error_ptr warning_fn) png_error_ptr error_fn, png_error_ptr warning_fn)
{ {
@@ -162,11 +269,21 @@ png_set_error_fn(png_structp png_ptr, png_voidp error_ptr,
* functions. The application should free any memory associated with this * functions. The application should free any memory associated with this
* pointer before png_write_destroy and png_read_destroy are called. * pointer before png_write_destroy and png_read_destroy are called.
*/ */
png_voidp png_voidp PNGAPI
png_get_error_ptr(png_structp png_ptr) png_get_error_ptr(png_structp png_ptr)
{ {
return ((png_voidp)png_ptr->error_ptr); return ((png_voidp)png_ptr->error_ptr);
} }
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
void
png_set_strip_error_numbers(png_structp png_ptr, png_uint_32 strip_mode)
{
if(png_ptr != NULL)
{
png_ptr->flags &=
((~(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))&strip_mode);
}
}
#endif

3871
pnggccrd.c

File diff suppressed because it is too large Load Diff

336
pngget.c
View File

@@ -1,17 +1,17 @@
/* pngget.c - retrieval of values from info struct /* pngget.c - retrieval of values from info struct
* *
* libpng 1.0.5k - December 27, 1999 * libpng 1.2.1 - December 12, 2001
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. * Copyright (c) 1998-2001 Glenn Randers-Pehrson
* Copyright (c) 1996, 1997 Andreas Dilger * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*/ */
#define PNG_INTERNAL #define PNG_INTERNAL
#include "png.h" #include "png.h"
png_uint_32 png_uint_32 PNGAPI
png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag) png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag)
{ {
if (png_ptr != NULL && info_ptr != NULL) if (png_ptr != NULL && info_ptr != NULL)
@@ -20,7 +20,7 @@ png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag)
return(0); return(0);
} }
png_uint_32 png_uint_32 PNGAPI
png_get_rowbytes(png_structp png_ptr, png_infop info_ptr) png_get_rowbytes(png_structp png_ptr, png_infop info_ptr)
{ {
if (png_ptr != NULL && info_ptr != NULL) if (png_ptr != NULL && info_ptr != NULL)
@@ -29,9 +29,20 @@ png_get_rowbytes(png_structp png_ptr, png_infop info_ptr)
return(0); return(0);
} }
#if defined(PNG_INFO_IMAGE_SUPPORTED)
png_bytepp PNGAPI
png_get_rows(png_structp png_ptr, png_infop info_ptr)
{
if (png_ptr != NULL && info_ptr != NULL)
return(info_ptr->row_pointers);
else
return(0);
}
#endif
#ifdef PNG_EASY_ACCESS_SUPPORTED #ifdef PNG_EASY_ACCESS_SUPPORTED
/* easy access to info, added in libpng-0.99 */ /* easy access to info, added in libpng-0.99 */
png_uint_32 png_uint_32 PNGAPI
png_get_image_width(png_structp png_ptr, png_infop info_ptr) png_get_image_width(png_structp png_ptr, png_infop info_ptr)
{ {
if (png_ptr != NULL && info_ptr != NULL) if (png_ptr != NULL && info_ptr != NULL)
@@ -41,7 +52,7 @@ png_get_image_width(png_structp png_ptr, png_infop info_ptr)
return (0); return (0);
} }
png_uint_32 png_uint_32 PNGAPI
png_get_image_height(png_structp png_ptr, png_infop info_ptr) png_get_image_height(png_structp png_ptr, png_infop info_ptr)
{ {
if (png_ptr != NULL && info_ptr != NULL) if (png_ptr != NULL && info_ptr != NULL)
@@ -51,7 +62,7 @@ png_get_image_height(png_structp png_ptr, png_infop info_ptr)
return (0); return (0);
} }
png_byte png_byte PNGAPI
png_get_bit_depth(png_structp png_ptr, png_infop info_ptr) png_get_bit_depth(png_structp png_ptr, png_infop info_ptr)
{ {
if (png_ptr != NULL && info_ptr != NULL) if (png_ptr != NULL && info_ptr != NULL)
@@ -61,7 +72,7 @@ png_get_bit_depth(png_structp png_ptr, png_infop info_ptr)
return (0); return (0);
} }
png_byte png_byte PNGAPI
png_get_color_type(png_structp png_ptr, png_infop info_ptr) png_get_color_type(png_structp png_ptr, png_infop info_ptr)
{ {
if (png_ptr != NULL && info_ptr != NULL) if (png_ptr != NULL && info_ptr != NULL)
@@ -71,7 +82,7 @@ png_get_color_type(png_structp png_ptr, png_infop info_ptr)
return (0); return (0);
} }
png_byte png_byte PNGAPI
png_get_filter_type(png_structp png_ptr, png_infop info_ptr) png_get_filter_type(png_structp png_ptr, png_infop info_ptr)
{ {
if (png_ptr != NULL && info_ptr != NULL) if (png_ptr != NULL && info_ptr != NULL)
@@ -81,7 +92,7 @@ png_get_filter_type(png_structp png_ptr, png_infop info_ptr)
return (0); return (0);
} }
png_byte png_byte PNGAPI
png_get_interlace_type(png_structp png_ptr, png_infop info_ptr) png_get_interlace_type(png_structp png_ptr, png_infop info_ptr)
{ {
if (png_ptr != NULL && info_ptr != NULL) if (png_ptr != NULL && info_ptr != NULL)
@@ -91,7 +102,7 @@ png_get_interlace_type(png_structp png_ptr, png_infop info_ptr)
return (0); return (0);
} }
png_byte png_byte PNGAPI
png_get_compression_type(png_structp png_ptr, png_infop info_ptr) png_get_compression_type(png_structp png_ptr, png_infop info_ptr)
{ {
if (png_ptr != NULL && info_ptr != NULL) if (png_ptr != NULL && info_ptr != NULL)
@@ -101,43 +112,48 @@ png_get_compression_type(png_structp png_ptr, png_infop info_ptr)
return (0); return (0);
} }
png_uint_32 png_uint_32 PNGAPI
png_get_x_pixels_per_meter(png_structp png_ptr, png_infop info_ptr) png_get_x_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
{ {
if (png_ptr != NULL && info_ptr != NULL)
#if defined(PNG_pHYs_SUPPORTED) #if defined(PNG_pHYs_SUPPORTED)
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)) if (info_ptr->valid & PNG_INFO_pHYs)
{ {
png_debug1(1, "in %s retrieval function\n", "png_get_x_pixels_per_meter"); png_debug1(1, "in %s retrieval function\n", "png_get_x_pixels_per_meter");
if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER) if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
return (0); return (0);
else return (info_ptr->x_pixels_per_unit); else return (info_ptr->x_pixels_per_unit);
} }
else #else
return (0);
#endif #endif
return (0); return (0);
} }
png_uint_32 png_uint_32 PNGAPI
png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr) png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
{ {
if (png_ptr != NULL && info_ptr != NULL)
#if defined(PNG_pHYs_SUPPORTED) #if defined(PNG_pHYs_SUPPORTED)
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)) if (info_ptr->valid & PNG_INFO_pHYs)
{ {
png_debug1(1, "in %s retrieval function\n", "png_get_y_pixels_per_meter"); png_debug1(1, "in %s retrieval function\n", "png_get_y_pixels_per_meter");
if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER) if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
return (0); return (0);
else return (info_ptr->y_pixels_per_unit); else return (info_ptr->y_pixels_per_unit);
} }
else #else
return (0);
#endif #endif
return (0); return (0);
} }
png_uint_32 png_uint_32 PNGAPI
png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr) png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
{ {
if (png_ptr != NULL && info_ptr != NULL)
#if defined(PNG_pHYs_SUPPORTED) #if defined(PNG_pHYs_SUPPORTED)
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)) if (info_ptr->valid & PNG_INFO_pHYs)
{ {
png_debug1(1, "in %s retrieval function\n", "png_get_pixels_per_meter"); png_debug1(1, "in %s retrieval function\n", "png_get_pixels_per_meter");
if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER || if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER ||
@@ -145,133 +161,144 @@ png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
return (0); return (0);
else return (info_ptr->x_pixels_per_unit); else return (info_ptr->x_pixels_per_unit);
} }
else #else
return (0);
#endif #endif
return (0); return (0);
} }
#ifdef PNG_FLOATING_POINT_SUPPORTED #ifdef PNG_FLOATING_POINT_SUPPORTED
float float PNGAPI
png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr) png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr)
{ {
if (png_ptr != NULL && info_ptr != NULL)
#if defined(PNG_pHYs_SUPPORTED) #if defined(PNG_pHYs_SUPPORTED)
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)) if (info_ptr->valid & PNG_INFO_pHYs)
{ {
png_debug1(1, "in %s retrieval function\n", "png_get_aspect_ratio"); png_debug1(1, "in %s retrieval function\n", "png_get_aspect_ratio");
if (info_ptr->x_pixels_per_unit == 0) if (info_ptr->x_pixels_per_unit == 0)
return ((float)0.0); return ((float)0.0);
else else
return ((float)info_ptr->y_pixels_per_unit return ((float)((float)info_ptr->y_pixels_per_unit
/(float)info_ptr->x_pixels_per_unit); /(float)info_ptr->x_pixels_per_unit));
} }
else #else
return (0.0);
#endif #endif
return ((float)0.0); return ((float)0.0);
} }
#endif #endif
png_uint_32 png_int_32 PNGAPI
png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr) png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr)
{ {
if (png_ptr != NULL && info_ptr != NULL)
#if defined(PNG_oFFs_SUPPORTED) #if defined(PNG_oFFs_SUPPORTED)
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)) if (info_ptr->valid & PNG_INFO_oFFs)
{ {
png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns"); png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER) if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
return (0); return (0);
else return (info_ptr->x_offset); else return (info_ptr->x_offset);
} }
else #else
return (0);
#endif #endif
return (0); return (0);
} }
png_uint_32 png_int_32 PNGAPI
png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr) png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr)
{ {
if (png_ptr != NULL && info_ptr != NULL)
#if defined(PNG_oFFs_SUPPORTED) #if defined(PNG_oFFs_SUPPORTED)
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)) if (info_ptr->valid & PNG_INFO_oFFs)
{ {
png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns"); png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER) if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
return (0); return (0);
else return (info_ptr->y_offset); else return (info_ptr->y_offset);
} }
else #else
return (0);
#endif #endif
return (0); return (0);
} }
png_uint_32 png_int_32 PNGAPI
png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr) png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr)
{ {
if (png_ptr != NULL && info_ptr != NULL)
#if defined(PNG_oFFs_SUPPORTED) #if defined(PNG_oFFs_SUPPORTED)
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)) if (info_ptr->valid & PNG_INFO_oFFs)
{ {
png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns"); png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL) if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
return (0); return (0);
else return (info_ptr->x_offset); else return (info_ptr->x_offset);
} }
else #else
return (0);
#endif #endif
return (0); return (0);
} }
png_uint_32 png_int_32 PNGAPI
png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr) png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr)
{ {
if (png_ptr != NULL && info_ptr != NULL)
#if defined(PNG_oFFs_SUPPORTED) #if defined(PNG_oFFs_SUPPORTED)
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)) if (info_ptr->valid & PNG_INFO_oFFs)
{ {
png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns"); png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL) if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
return (0); return (0);
else return (info_ptr->y_offset); else return (info_ptr->y_offset);
} }
else #else
return (0);
#endif #endif
return (0); return (0);
} }
#if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED) #if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
png_uint_32 png_uint_32 PNGAPI
png_get_pixels_per_inch(png_structp png_ptr, png_infop info_ptr) png_get_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
{ {
return ((png_uint_32)((float)png_get_pixels_per_meter(png_ptr, info_ptr) return ((png_uint_32)((float)png_get_pixels_per_meter(png_ptr, info_ptr)
*.03937 +.5) *.0254 +.5));
} }
png_uint_32 png_uint_32 PNGAPI
png_get_x_pixels_per_inch(png_structp png_ptr, png_infop info_ptr) png_get_x_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
{ {
return ((png_uint_32)((float)png_get_x_pixels_per_meter(png_ptr, info_ptr) return ((png_uint_32)((float)png_get_x_pixels_per_meter(png_ptr, info_ptr)
*.03937 +.5) *.0254 +.5));
} }
png_uint_32 png_uint_32 PNGAPI
png_get_y_pixels_per_inch(png_structp png_ptr, png_infop info_ptr) png_get_y_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
{ {
return ((png_uint_32)((float)png_get_y_pixels_per_meter(png_ptr, info_ptr) return ((png_uint_32)((float)png_get_y_pixels_per_meter(png_ptr, info_ptr)
*.03937 +.5) *.0254 +.5));
} }
float float PNGAPI
png_get_x_offset_inches(png_structp png_ptr, png_infop info_ptr) png_get_x_offset_inches(png_structp png_ptr, png_infop info_ptr)
{ {
return ((float)png_get_x_offset_microns(png_ptr, info_ptr) return ((float)png_get_x_offset_microns(png_ptr, info_ptr)
*.03937/1000000. +.5) *.00003937);
} }
float float PNGAPI
png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr) png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr)
{ {
return ((float)png_get_y_offset_microns(png_ptr, info_ptr) return ((float)png_get_y_offset_microns(png_ptr, info_ptr)
*.03937/1000000. +.5) *.00003937);
} }
#if defined(PNG_READ_pHYs_SUPPORTED) #if defined(PNG_pHYs_SUPPORTED)
png_uint_32 png_uint_32 PNGAPI
png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr, png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr,
png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type) png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
{ {
@@ -294,23 +321,23 @@ png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr,
{ {
*unit_type = (int)info_ptr->phys_unit_type; *unit_type = (int)info_ptr->phys_unit_type;
retval |= PNG_INFO_pHYs; retval |= PNG_INFO_pHYs;
if(unit_type == 1) if(*unit_type == 1)
{ {
if (res_x != NULL) *res_x = (png_uint_32)(*res_x * 39.37 + .50); if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50);
if (res_y != NULL) *res_y = (png_uint_32)(*res_y * 39.37 + .50); if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50);
} }
} }
} }
return (retval); return (retval);
} }
#endif /* PNG_READ_pHYs_SUPPORTED */ #endif /* PNG_pHYs_SUPPORTED */
#endif /* PNG_INCH_CONVERSIONS $$ PNG_FLOATING_POINT_SUPPORTED */ #endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
/* png_get_channels really belongs in here, too, but it's been around longer */ /* png_get_channels really belongs in here, too, but it's been around longer */
#endif /* PNG_EASY_ACCESS_SUPPORTED */ #endif /* PNG_EASY_ACCESS_SUPPORTED */
png_byte png_byte PNGAPI
png_get_channels(png_structp png_ptr, png_infop info_ptr) png_get_channels(png_structp png_ptr, png_infop info_ptr)
{ {
if (png_ptr != NULL && info_ptr != NULL) if (png_ptr != NULL && info_ptr != NULL)
@@ -319,7 +346,7 @@ png_get_channels(png_structp png_ptr, png_infop info_ptr)
return (0); return (0);
} }
png_bytep png_bytep PNGAPI
png_get_signature(png_structp png_ptr, png_infop info_ptr) png_get_signature(png_structp png_ptr, png_infop info_ptr)
{ {
if (png_ptr != NULL && info_ptr != NULL) if (png_ptr != NULL && info_ptr != NULL)
@@ -328,8 +355,8 @@ png_get_signature(png_structp png_ptr, png_infop info_ptr)
return (NULL); return (NULL);
} }
#if defined(PNG_READ_bKGD_SUPPORTED) #if defined(PNG_bKGD_SUPPORTED)
png_uint_32 png_uint_32 PNGAPI
png_get_bKGD(png_structp png_ptr, png_infop info_ptr, png_get_bKGD(png_structp png_ptr, png_infop info_ptr,
png_color_16p *background) png_color_16p *background)
{ {
@@ -344,9 +371,9 @@ png_get_bKGD(png_structp png_ptr, png_infop info_ptr,
} }
#endif #endif
#if defined(PNG_READ_cHRM_SUPPORTED) #if defined(PNG_cHRM_SUPPORTED)
#ifdef PNG_FLOATING_POINT_SUPPORTED #ifdef PNG_FLOATING_POINT_SUPPORTED
png_uint_32 png_uint_32 PNGAPI
png_get_cHRM(png_structp png_ptr, png_infop info_ptr, png_get_cHRM(png_structp png_ptr, png_infop info_ptr,
double *white_x, double *white_y, double *red_x, double *red_y, double *white_x, double *white_y, double *red_x, double *red_y,
double *green_x, double *green_y, double *blue_x, double *blue_y) double *green_x, double *green_y, double *blue_x, double *blue_y)
@@ -376,7 +403,7 @@ png_get_cHRM(png_structp png_ptr, png_infop info_ptr,
} }
#endif #endif
#ifdef PNG_FIXED_POINT_SUPPORTED #ifdef PNG_FIXED_POINT_SUPPORTED
png_uint_32 png_uint_32 PNGAPI
png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr, png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x, png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x,
png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y, png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y,
@@ -408,9 +435,9 @@ png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
#endif #endif
#endif #endif
#if defined(PNG_READ_gAMA_SUPPORTED) #if defined(PNG_gAMA_SUPPORTED)
#ifdef PNG_FLOATING_POINT_SUPPORTED #ifdef PNG_FLOATING_POINT_SUPPORTED
png_uint_32 png_uint_32 PNGAPI
png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma) png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma)
{ {
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA) if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
@@ -423,7 +450,8 @@ png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma)
return (0); return (0);
} }
#endif #endif
png_uint_32 #ifdef PNG_FIXED_POINT_SUPPORTED
png_uint_32 PNGAPI
png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr,
png_fixed_point *int_file_gamma) png_fixed_point *int_file_gamma)
{ {
@@ -437,9 +465,10 @@ png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr,
return (0); return (0);
} }
#endif #endif
#endif
#if defined(PNG_READ_sRGB_SUPPORTED) #if defined(PNG_sRGB_SUPPORTED)
png_uint_32 png_uint_32 PNGAPI
png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent) png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent)
{ {
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB) if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)
@@ -453,8 +482,8 @@ png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent)
} }
#endif #endif
#if defined(PNG_READ_iCCP_SUPPORTED) #if defined(PNG_iCCP_SUPPORTED)
png_uint_32 png_uint_32 PNGAPI
png_get_iCCP(png_structp png_ptr, png_infop info_ptr, png_get_iCCP(png_structp png_ptr, png_infop info_ptr,
png_charpp name, int *compression_type, png_charpp name, int *compression_type,
png_charpp profile, png_uint_32 *proflen) png_charpp profile, png_uint_32 *proflen)
@@ -475,10 +504,10 @@ png_get_iCCP(png_structp png_ptr, png_infop info_ptr,
} }
#endif #endif
#if defined(PNG_READ_sPLT_SUPPORTED) #if defined(PNG_sPLT_SUPPORTED)
png_uint_32 png_uint_32 PNGAPI
png_get_spalettes(png_structp png_ptr, png_infop info_ptr, png_get_sPLT(png_structp png_ptr, png_infop info_ptr,
png_spalette_pp spalettes) png_sPLT_tpp spalettes)
{ {
if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL) if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
*spalettes = info_ptr->splt_palettes; *spalettes = info_ptr->splt_palettes;
@@ -486,8 +515,8 @@ png_get_spalettes(png_structp png_ptr, png_infop info_ptr,
} }
#endif #endif
#if defined(PNG_READ_hIST_SUPPORTED) #if defined(PNG_hIST_SUPPORTED)
png_uint_32 png_uint_32 PNGAPI
png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist) png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist)
{ {
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST) if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)
@@ -501,7 +530,7 @@ png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist)
} }
#endif #endif
png_uint_32 png_uint_32 PNGAPI
png_get_IHDR(png_structp png_ptr, png_infop info_ptr, png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
png_uint_32 *width, png_uint_32 *height, int *bit_depth, png_uint_32 *width, png_uint_32 *height, int *bit_depth,
int *color_type, int *interlace_type, int *compression_type, int *color_type, int *interlace_type, int *compression_type,
@@ -547,8 +576,8 @@ png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
return (0); return (0);
} }
#if defined(PNG_READ_oFFs_SUPPORTED) #if defined(PNG_oFFs_SUPPORTED)
png_uint_32 png_uint_32 PNGAPI
png_get_oFFs(png_structp png_ptr, png_infop info_ptr, png_get_oFFs(png_structp png_ptr, png_infop info_ptr,
png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type) png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
{ {
@@ -565,8 +594,8 @@ png_get_oFFs(png_structp png_ptr, png_infop info_ptr,
} }
#endif #endif
#if defined(PNG_READ_pCAL_SUPPORTED) #if defined(PNG_pCAL_SUPPORTED)
png_uint_32 png_uint_32 PNGAPI
png_get_pCAL(png_structp png_ptr, png_infop info_ptr, png_get_pCAL(png_structp png_ptr, png_infop info_ptr,
png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams, png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
png_charp *units, png_charpp *params) png_charp *units, png_charpp *params)
@@ -589,9 +618,9 @@ png_get_pCAL(png_structp png_ptr, png_infop info_ptr,
} }
#endif #endif
#if defined(PNG_READ_sCAL_SUPPORTED) || defined(PNG_WRITE_sCAL_SUPPORTED) #if defined(PNG_sCAL_SUPPORTED)
#ifdef PNG_FLOATING_POINT_SUPPORTED #ifdef PNG_FLOATING_POINT_SUPPORTED
png_uint_32 png_uint_32 PNGAPI
png_get_sCAL(png_structp png_ptr, png_infop info_ptr, png_get_sCAL(png_structp png_ptr, png_infop info_ptr,
int *unit, double *width, double *height) int *unit, double *width, double *height)
{ {
@@ -607,7 +636,7 @@ png_get_sCAL(png_structp png_ptr, png_infop info_ptr,
} }
#else #else
#ifdef PNG_FIXED_POINT_SUPPORTED #ifdef PNG_FIXED_POINT_SUPPORTED
png_uint_32 png_uint_32 PNGAPI
png_get_sCAL_s(png_structp png_ptr, png_infop info_ptr, png_get_sCAL_s(png_structp png_ptr, png_infop info_ptr,
int *unit, png_charpp width, png_charpp height) int *unit, png_charpp width, png_charpp height)
{ {
@@ -625,8 +654,8 @@ png_get_sCAL_s(png_structp png_ptr, png_infop info_ptr,
#endif #endif
#endif #endif
#if defined(PNG_READ_pHYs_SUPPORTED) #if defined(PNG_pHYs_SUPPORTED)
png_uint_32 png_uint_32 PNGAPI
png_get_pHYs(png_structp png_ptr, png_infop info_ptr, png_get_pHYs(png_structp png_ptr, png_infop info_ptr,
png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type) png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
{ {
@@ -656,7 +685,7 @@ png_get_pHYs(png_structp png_ptr, png_infop info_ptr,
} }
#endif #endif
png_uint_32 png_uint_32 PNGAPI
png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette, png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette,
int *num_palette) int *num_palette)
{ {
@@ -672,8 +701,8 @@ png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette,
return (0); return (0);
} }
#if defined(PNG_READ_sBIT_SUPPORTED) #if defined(PNG_sBIT_SUPPORTED)
png_uint_32 png_uint_32 PNGAPI
png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit) png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit)
{ {
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT) if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)
@@ -687,8 +716,8 @@ png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit)
} }
#endif #endif
#if defined(PNG_READ_TEXT_SUPPORTED) #if defined(PNG_TEXT_SUPPORTED)
png_uint_32 png_uint_32 PNGAPI
png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr, png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr,
int *num_text) int *num_text)
{ {
@@ -703,12 +732,14 @@ png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr,
*num_text = info_ptr->num_text; *num_text = info_ptr->num_text;
return ((png_uint_32)info_ptr->num_text); return ((png_uint_32)info_ptr->num_text);
} }
if (num_text != NULL)
*num_text = 0;
return(0); return(0);
} }
#endif #endif
#if defined(PNG_READ_tIME_SUPPORTED) #if defined(PNG_tIME_SUPPORTED)
png_uint_32 png_uint_32 PNGAPI
png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time) png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time)
{ {
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME) if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)
@@ -722,8 +753,8 @@ png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time)
} }
#endif #endif
#if defined(PNG_READ_tRNS_SUPPORTED) #if defined(PNG_tRNS_SUPPORTED)
png_uint_32 png_uint_32 PNGAPI
png_get_tRNS(png_structp png_ptr, png_infop info_ptr, png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
png_bytep *trans, int *num_trans, png_color_16p *trans_values) png_bytep *trans, int *num_trans, png_color_16p *trans_values)
{ {
@@ -761,8 +792,8 @@ png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
} }
#endif #endif
#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
png_uint_32 png_uint_32 PNGAPI
png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr, png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr,
png_unknown_chunkpp unknowns) png_unknown_chunkpp unknowns)
{ {
@@ -773,9 +804,114 @@ png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr,
#endif #endif
#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
png_byte png_byte PNGAPI
png_get_rgb_to_gray_status (png_structp png_ptr) png_get_rgb_to_gray_status (png_structp png_ptr)
{ {
return png_ptr->rgb_to_gray_status; return (png_byte)(png_ptr? png_ptr->rgb_to_gray_status : 0);
} }
#endif #endif
#if defined(PNG_USER_CHUNKS_SUPPORTED)
png_voidp PNGAPI
png_get_user_chunk_ptr(png_structp png_ptr)
{
return (png_ptr? png_ptr->user_chunk_ptr : NULL);
}
#endif
png_uint_32 PNGAPI
png_get_compression_buffer_size(png_structp png_ptr)
{
return (png_uint_32)(png_ptr? png_ptr->zbuf_size : 0L);
}
#ifdef PNG_ASSEMBLER_CODE_SUPPORTED
/* this function was added to libpng 1.2.0 and should exist by default*/
png_uint_32 PNGAPI
png_get_asm_flags (png_structp png_ptr)
{
return (png_uint_32)(png_ptr? png_ptr->asm_flags : 0L);
}
/* this function was added to libpng 1.2.0 and should exist by default */
png_uint_32 PNGAPI
png_get_asm_flagmask (int flag_select)
{
png_uint_32 settable_asm_flags = 0;
if (flag_select & PNG_SELECT_READ)
settable_asm_flags |=
PNG_ASM_FLAG_MMX_READ_COMBINE_ROW |
PNG_ASM_FLAG_MMX_READ_INTERLACE |
PNG_ASM_FLAG_MMX_READ_FILTER_SUB |
PNG_ASM_FLAG_MMX_READ_FILTER_UP |
PNG_ASM_FLAG_MMX_READ_FILTER_AVG |
PNG_ASM_FLAG_MMX_READ_FILTER_PAETH ;
/* no non-MMX flags yet */
#if 0
/* GRR: no write-flags yet, either, but someday... */
if (flag_select & PNG_SELECT_WRITE)
settable_asm_flags |=
PNG_ASM_FLAG_MMX_WRITE_ [whatever] ;
#endif /* 0 */
return settable_asm_flags; /* _theoretically_ settable capabilities only */
}
#endif /* PNG_ASSEMBLER_CODE_SUPPORTED */
#if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
/* GRR: could add this: && defined(PNG_MMX_CODE_SUPPORTED) */
/* this function was added to libpng 1.2.0 */
png_uint_32 PNGAPI
png_get_mmx_flagmask (int flag_select, int *compilerID)
{
png_uint_32 settable_mmx_flags = 0;
if (flag_select & PNG_SELECT_READ)
settable_mmx_flags |=
PNG_ASM_FLAG_MMX_READ_COMBINE_ROW |
PNG_ASM_FLAG_MMX_READ_INTERLACE |
PNG_ASM_FLAG_MMX_READ_FILTER_SUB |
PNG_ASM_FLAG_MMX_READ_FILTER_UP |
PNG_ASM_FLAG_MMX_READ_FILTER_AVG |
PNG_ASM_FLAG_MMX_READ_FILTER_PAETH ;
#if 0
/* GRR: no MMX write support yet, but someday... */
if (flag_select & PNG_SELECT_WRITE)
settable_mmx_flags |=
PNG_ASM_FLAG_MMX_WRITE_ [whatever] ;
#endif /* 0 */
if (compilerID != NULL) {
#ifdef PNG_USE_PNGVCRD
*compilerID = 1; /* MSVC */
#else
#ifdef PNG_USE_PNGGCCRD
*compilerID = 2; /* gcc/gas */
#else
*compilerID = -1; /* unknown (i.e., no asm/MMX code compiled) */
#endif
#endif
}
return settable_mmx_flags; /* _theoretically_ settable capabilities only */
}
/* this function was added to libpng 1.2.0 */
png_byte PNGAPI
png_get_mmx_bitdepth_threshold (png_structp png_ptr)
{
return (png_byte)(png_ptr? png_ptr->mmx_bitdepth_threshold : 0);
}
/* this function was added to libpng 1.2.0 */
png_uint_32 PNGAPI
png_get_mmx_rowbytes_threshold (png_structp png_ptr)
{
return (png_uint_32)(png_ptr? png_ptr->mmx_rowbytes_threshold : 0L);
}
#endif /* PNG_ASSEMBLER_CODE_SUPPORTED */

114
pngmem.c
View File

@@ -1,11 +1,11 @@
/* pngmem.c - stub functions for memory allocation /* pngmem.c - stub functions for memory allocation
* *
* libpng 1.0.5k - December 27, 1999 * libpng 1.2.1 - December 12, 2001
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. * Copyright (c) 1998-2001 Glenn Randers-Pehrson
* Copyright (c) 1996, 1997 Andreas Dilger * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
* *
* This file provides a location for all memory allocation. Users who * This file provides a location for all memory allocation. Users who
* need special memory handling are expected to supply replacement * need special memory handling are expected to supply replacement
@@ -23,16 +23,16 @@
/* Allocate memory for a png_struct. The malloc and memset can be replaced /* Allocate memory for a png_struct. The malloc and memset can be replaced
by a single call to calloc() if this is thought to improve performance. */ by a single call to calloc() if this is thought to improve performance. */
png_voidp png_voidp /* PRIVATE */
png_create_struct(int type) png_create_struct(int type)
{ {
#ifdef PNG_USER_MEM_SUPPORTED #ifdef PNG_USER_MEM_SUPPORTED
return (png_create_struct_2(type, NULL)); return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL));
} }
/* Alternate version of png_create_struct, for use with user-defined malloc. */ /* Alternate version of png_create_struct, for use with user-defined malloc. */
png_voidp png_voidp /* PRIVATE */
png_create_struct_2(int type, png_malloc_ptr malloc_fn) png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
{ {
#endif /* PNG_USER_MEM_SUPPORTED */ #endif /* PNG_USER_MEM_SUPPORTED */
png_size_t size; png_size_t size;
@@ -43,35 +43,36 @@ png_create_struct_2(int type, png_malloc_ptr malloc_fn)
else if (type == PNG_STRUCT_PNG) else if (type == PNG_STRUCT_PNG)
size = sizeof(png_struct); size = sizeof(png_struct);
else else
return ((png_voidp)NULL); return (NULL);
#ifdef PNG_USER_MEM_SUPPORTED #ifdef PNG_USER_MEM_SUPPORTED
if(malloc_fn != NULL) if(malloc_fn != NULL)
{ {
if ((struct_ptr = (*(malloc_fn))(NULL, size)) != NULL) png_struct dummy_struct;
png_memset(struct_ptr, 0, size); png_structp png_ptr = &dummy_struct;
return (struct_ptr); png_ptr->mem_ptr=mem_ptr;
struct_ptr = (*(malloc_fn))(png_ptr, (png_uint_32)size);
} }
else
#endif /* PNG_USER_MEM_SUPPORTED */ #endif /* PNG_USER_MEM_SUPPORTED */
if ((struct_ptr = (png_voidp)farmalloc(size)) != NULL) struct_ptr = (png_voidp)farmalloc(size));
{ if (struct_ptr != NULL)
png_memset(struct_ptr, 0, size); png_memset(struct_ptr, 0, size);
}
return (struct_ptr); return (struct_ptr);
} }
/* Free memory allocated by a png_create_struct() call */ /* Free memory allocated by a png_create_struct() call */
void void /* PRIVATE */
png_destroy_struct(png_voidp struct_ptr) png_destroy_struct(png_voidp struct_ptr)
{ {
#ifdef PNG_USER_MEM_SUPPORTED #ifdef PNG_USER_MEM_SUPPORTED
png_destroy_struct_2(struct_ptr, (png_free_ptr)NULL); png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL);
} }
/* Free memory allocated by a png_create_struct() call */ /* Free memory allocated by a png_create_struct() call */
void void /* PRIVATE */
png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn) png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
png_voidp mem_ptr)
{ {
#endif #endif
if (struct_ptr != NULL) if (struct_ptr != NULL)
@@ -81,6 +82,7 @@ png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn)
{ {
png_struct dummy_struct; png_struct dummy_struct;
png_structp png_ptr = &dummy_struct; png_structp png_ptr = &dummy_struct;
png_ptr->mem_ptr=mem_ptr;
(*(free_fn))(png_ptr, struct_ptr); (*(free_fn))(png_ptr, struct_ptr);
return; return;
} }
@@ -108,23 +110,28 @@ png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn)
* result, we would be truncating potentially larger memory requests * result, we would be truncating potentially larger memory requests
* (which should cause a fatal error) and introducing major problems. * (which should cause a fatal error) and introducing major problems.
*/ */
png_voidp png_voidp PNGAPI
png_malloc(png_structp png_ptr, png_uint_32 size) png_malloc(png_structp png_ptr, png_uint_32 size)
{ {
#ifndef PNG_USER_MEM_SUPPORTED #ifndef PNG_USER_MEM_SUPPORTED
png_voidp ret; png_voidp ret;
#endif #endif
if (png_ptr == NULL || size == 0) if (png_ptr == NULL || size == 0)
return ((png_voidp)NULL); return (NULL);
#ifdef PNG_USER_MEM_SUPPORTED #ifdef PNG_USER_MEM_SUPPORTED
if(png_ptr->malloc_fn != NULL) if(png_ptr->malloc_fn != NULL)
return ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, size)); {
ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
if (ret == NULL)
png_error(png_ptr, "Out of memory!");
return (ret);
}
else else
return png_malloc_default(png_ptr, size); return png_malloc_default(png_ptr, size);
} }
png_voidp png_voidp PNGAPI
png_malloc_default(png_structp png_ptr, png_uint_32 size) png_malloc_default(png_structp png_ptr, png_uint_32 size)
{ {
png_voidp ret; png_voidp ret;
@@ -224,7 +231,7 @@ png_malloc_default(png_structp png_ptr, png_uint_32 size)
/* free a pointer allocated by png_malloc(). In the default /* free a pointer allocated by png_malloc(). In the default
configuration, png_ptr is not used, but is passed in case it configuration, png_ptr is not used, but is passed in case it
is needed. If ptr is NULL, return without taking any action. */ is needed. If ptr is NULL, return without taking any action. */
void void PNGAPI
png_free(png_structp png_ptr, png_voidp ptr) png_free(png_structp png_ptr, png_voidp ptr)
{ {
if (png_ptr == NULL || ptr == NULL) if (png_ptr == NULL || ptr == NULL)
@@ -239,7 +246,7 @@ png_free(png_structp png_ptr, png_voidp ptr)
else png_free_default(png_ptr, ptr); else png_free_default(png_ptr, ptr);
} }
void void PNGAPI
png_free_default(png_structp png_ptr, png_voidp ptr) png_free_default(png_structp png_ptr, png_voidp ptr)
{ {
#endif /* PNG_USER_MEM_SUPPORTED */ #endif /* PNG_USER_MEM_SUPPORTED */
@@ -277,18 +284,18 @@ png_free_default(png_structp png_ptr, png_voidp ptr)
/* Allocate memory for a png_struct or a png_info. The malloc and /* Allocate memory for a png_struct or a png_info. The malloc and
memset can be replaced by a single call to calloc() if this is thought memset can be replaced by a single call to calloc() if this is thought
to improve performance noticably.*/ to improve performance noticably.*/
png_voidp png_voidp /* PRIVATE */
png_create_struct(int type) png_create_struct(int type)
{ {
#ifdef PNG_USER_MEM_SUPPORTED #ifdef PNG_USER_MEM_SUPPORTED
return (png_create_struct_2(type, NULL)); return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL));
} }
/* Allocate memory for a png_struct or a png_info. The malloc and /* Allocate memory for a png_struct or a png_info. The malloc and
memset can be replaced by a single call to calloc() if this is thought memset can be replaced by a single call to calloc() if this is thought
to improve performance noticably.*/ to improve performance noticably.*/
png_voidp png_voidp /* PRIVATE */
png_create_struct_2(int type, png_malloc_ptr malloc_fn) png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
{ {
#endif /* PNG_USER_MEM_SUPPORTED */ #endif /* PNG_USER_MEM_SUPPORTED */
png_size_t size; png_size_t size;
@@ -299,12 +306,16 @@ png_create_struct_2(int type, png_malloc_ptr malloc_fn)
else if (type == PNG_STRUCT_PNG) else if (type == PNG_STRUCT_PNG)
size = sizeof(png_struct); size = sizeof(png_struct);
else else
return ((png_voidp)NULL); return (NULL);
#ifdef PNG_USER_MEM_SUPPORTED #ifdef PNG_USER_MEM_SUPPORTED
if(malloc_fn != NULL) if(malloc_fn != NULL)
{ {
if ((struct_ptr = (*(malloc_fn))(NULL, size)) != NULL) png_struct dummy_struct;
png_structp png_ptr = &dummy_struct;
png_ptr->mem_ptr=mem_ptr;
struct_ptr = (*(malloc_fn))(png_ptr, size);
if (struct_ptr != NULL)
png_memset(struct_ptr, 0, size); png_memset(struct_ptr, 0, size);
return (struct_ptr); return (struct_ptr);
} }
@@ -328,16 +339,17 @@ png_create_struct_2(int type, png_malloc_ptr malloc_fn)
/* Free memory allocated by a png_create_struct() call */ /* Free memory allocated by a png_create_struct() call */
void void /* PRIVATE */
png_destroy_struct(png_voidp struct_ptr) png_destroy_struct(png_voidp struct_ptr)
{ {
#ifdef PNG_USER_MEM_SUPPORTED #ifdef PNG_USER_MEM_SUPPORTED
png_destroy_struct_2(struct_ptr, (png_free_ptr)NULL); png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL);
} }
/* Free memory allocated by a png_create_struct() call */ /* Free memory allocated by a png_create_struct() call */
void void /* PRIVATE */
png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn) png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
png_voidp mem_ptr)
{ {
#endif /* PNG_USER_MEM_SUPPORTED */ #endif /* PNG_USER_MEM_SUPPORTED */
if (struct_ptr != NULL) if (struct_ptr != NULL)
@@ -347,6 +359,7 @@ png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn)
{ {
png_struct dummy_struct; png_struct dummy_struct;
png_structp png_ptr = &dummy_struct; png_structp png_ptr = &dummy_struct;
png_ptr->mem_ptr=mem_ptr;
(*(free_fn))(png_ptr, struct_ptr); (*(free_fn))(png_ptr, struct_ptr);
return; return;
} }
@@ -370,22 +383,25 @@ png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn)
need to allocate exactly 64K, so whatever you call here must need to allocate exactly 64K, so whatever you call here must
have the ability to do that. */ have the ability to do that. */
png_voidp png_voidp PNGAPI
png_malloc(png_structp png_ptr, png_uint_32 size) png_malloc(png_structp png_ptr, png_uint_32 size)
{ {
#ifndef PNG_USER_MEM_SUPPORTED
png_voidp ret; png_voidp ret;
#endif
if (png_ptr == NULL || size == 0) if (png_ptr == NULL || size == 0)
return ((png_voidp)NULL); return (NULL);
#ifdef PNG_USER_MEM_SUPPORTED #ifdef PNG_USER_MEM_SUPPORTED
if(png_ptr->malloc_fn != NULL) if(png_ptr->malloc_fn != NULL)
return ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, size)); {
ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, size));
if (ret == NULL)
png_error(png_ptr, "Out of Memory!");
return (ret);
}
else else
return (png_malloc_default(png_ptr, size)); return (png_malloc_default(png_ptr, size));
} }
png_voidp png_voidp /* PRIVATE */
png_malloc_default(png_structp png_ptr, png_uint_32 size) png_malloc_default(png_structp png_ptr, png_uint_32 size)
{ {
png_voidp ret; png_voidp ret;
@@ -407,16 +423,14 @@ png_malloc_default(png_structp png_ptr, png_uint_32 size)
#endif #endif
if (ret == NULL) if (ret == NULL)
{
png_error(png_ptr, "Out of Memory"); png_error(png_ptr, "Out of Memory");
}
return (ret); return (ret);
} }
/* Free a pointer allocated by png_malloc(). If ptr is NULL, return /* Free a pointer allocated by png_malloc(). If ptr is NULL, return
without taking any action. */ without taking any action. */
void void PNGAPI
png_free(png_structp png_ptr, png_voidp ptr) png_free(png_structp png_ptr, png_voidp ptr)
{ {
if (png_ptr == NULL || ptr == NULL) if (png_ptr == NULL || ptr == NULL)
@@ -430,7 +444,7 @@ png_free(png_structp png_ptr, png_voidp ptr)
} }
else png_free_default(png_ptr, ptr); else png_free_default(png_ptr, ptr);
} }
void void /* PRIVATE */
png_free_default(png_structp png_ptr, png_voidp ptr) png_free_default(png_structp png_ptr, png_voidp ptr)
{ {
if (png_ptr == NULL || ptr == NULL) if (png_ptr == NULL || ptr == NULL)
@@ -451,7 +465,7 @@ png_free_default(png_structp png_ptr, png_voidp ptr)
#endif /* Not Borland DOS special memory handler */ #endif /* Not Borland DOS special memory handler */
png_voidp png_voidp /* PRIVATE */
png_memcpy_check (png_structp png_ptr, png_voidp s1, png_voidp s2, png_memcpy_check (png_structp png_ptr, png_voidp s1, png_voidp s2,
png_uint_32 length) png_uint_32 length)
{ {
@@ -464,7 +478,7 @@ png_memcpy_check (png_structp png_ptr, png_voidp s1, png_voidp s2,
return(png_memcpy (s1, s2, size)); return(png_memcpy (s1, s2, size));
} }
png_voidp png_voidp /* PRIVATE */
png_memset_check (png_structp png_ptr, png_voidp s1, int value, png_memset_check (png_structp png_ptr, png_voidp s1, int value,
png_uint_32 length) png_uint_32 length)
{ {
@@ -482,7 +496,7 @@ png_memset_check (png_structp png_ptr, png_voidp s1, int value,
/* This function is called when the application wants to use another method /* This function is called when the application wants to use another method
* of allocating and freeing memory. * of allocating and freeing memory.
*/ */
void void PNGAPI
png_set_mem_fn(png_structp png_ptr, png_voidp mem_ptr, png_malloc_ptr png_set_mem_fn(png_structp png_ptr, png_voidp mem_ptr, png_malloc_ptr
malloc_fn, png_free_ptr free_fn) malloc_fn, png_free_ptr free_fn)
{ {
@@ -495,7 +509,7 @@ png_set_mem_fn(png_structp png_ptr, png_voidp mem_ptr, png_malloc_ptr
* functions. The application should free any memory associated with this * functions. The application should free any memory associated with this
* pointer before png_write_destroy and png_read_destroy are called. * pointer before png_write_destroy and png_read_destroy are called.
*/ */
png_voidp png_voidp PNGAPI
png_get_mem_ptr(png_structp png_ptr) png_get_mem_ptr(png_structp png_ptr)
{ {
return ((png_voidp)png_ptr->mem_ptr); return ((png_voidp)png_ptr->mem_ptr);

View File

@@ -1,11 +1,11 @@
/* pngpread.c - read a png file in push mode /* pngpread.c - read a png file in push mode
* *
* libpng 1.0.5k - December 27, 1999 * libpng 1.2.1 - December 12, 2001
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. * Copyright (c) 1998-2001 Glenn Randers-Pehrson
* Copyright (c) 1996, 1997 Andreas Dilger * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*/ */
#define PNG_INTERNAL #define PNG_INTERNAL
@@ -24,7 +24,7 @@
#define PNG_READ_iTXt_MODE 7 #define PNG_READ_iTXt_MODE 7
#define PNG_ERROR_MODE 8 #define PNG_ERROR_MODE 8
void void PNGAPI
png_process_data(png_structp png_ptr, png_infop info_ptr, png_process_data(png_structp png_ptr, png_infop info_ptr,
png_bytep buffer, png_size_t buffer_size) png_bytep buffer, png_size_t buffer_size)
{ {
@@ -39,7 +39,7 @@ png_process_data(png_structp png_ptr, png_infop info_ptr,
/* What we do with the incoming data depends on what we were previously /* What we do with the incoming data depends on what we were previously
* doing before we ran out of data... * doing before we ran out of data...
*/ */
void void /* PRIVATE */
png_process_some_data(png_structp png_ptr, png_infop info_ptr) png_process_some_data(png_structp png_ptr, png_infop info_ptr)
{ {
switch (png_ptr->process_mode) switch (png_ptr->process_mode)
@@ -99,7 +99,7 @@ png_process_some_data(png_structp png_ptr, png_infop info_ptr)
* checked by the calling application, or because of multiple calls to this * checked by the calling application, or because of multiple calls to this
* routine. * routine.
*/ */
void void /* PRIVATE */
png_push_read_sig(png_structp png_ptr, png_infop info_ptr) png_push_read_sig(png_structp png_ptr, png_infop info_ptr)
{ {
png_size_t num_checked = png_ptr->sig_bytes, png_size_t num_checked = png_ptr->sig_bytes,
@@ -131,7 +131,7 @@ png_push_read_sig(png_structp png_ptr, png_infop info_ptr)
} }
} }
void void /* PRIVATE */
png_push_read_chunk(png_structp png_ptr, png_infop info_ptr) png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
{ {
#ifdef PNG_USE_LOCAL_ARRAYS #ifdef PNG_USE_LOCAL_ARRAYS
@@ -463,14 +463,14 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER; png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
} }
void void /* PRIVATE */
png_push_crc_skip(png_structp png_ptr, png_uint_32 skip) png_push_crc_skip(png_structp png_ptr, png_uint_32 skip)
{ {
png_ptr->process_mode = PNG_SKIP_MODE; png_ptr->process_mode = PNG_SKIP_MODE;
png_ptr->skip_length = skip; png_ptr->skip_length = skip;
} }
void void /* PRIVATE */
png_push_crc_finish(png_structp png_ptr) png_push_crc_finish(png_structp png_ptr)
{ {
if (png_ptr->skip_length && png_ptr->save_buffer_size) if (png_ptr->skip_length && png_ptr->save_buffer_size)
@@ -518,7 +518,7 @@ png_push_crc_finish(png_structp png_ptr)
} }
} }
void void /* PRIVATE */
png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length) png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length)
{ {
png_bytep ptr; png_bytep ptr;
@@ -556,7 +556,7 @@ png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length)
} }
} }
void void /* PRIVATE */
png_push_save_buffer(png_structp png_ptr) png_push_save_buffer(png_structp png_ptr)
{ {
if (png_ptr->save_buffer_size) if (png_ptr->save_buffer_size)
@@ -600,7 +600,7 @@ png_push_save_buffer(png_structp png_ptr)
png_ptr->buffer_size = 0; png_ptr->buffer_size = 0;
} }
void void /* PRIVATE */
png_push_restore_buffer(png_structp png_ptr, png_bytep buffer, png_push_restore_buffer(png_structp png_ptr, png_bytep buffer,
png_size_t buffer_length) png_size_t buffer_length)
{ {
@@ -610,7 +610,7 @@ png_push_restore_buffer(png_structp png_ptr, png_bytep buffer,
png_ptr->current_buffer_ptr = png_ptr->current_buffer; png_ptr->current_buffer_ptr = png_ptr->current_buffer;
} }
void void /* PRIVATE */
png_push_read_IDAT(png_structp png_ptr) png_push_read_IDAT(png_structp png_ptr)
{ {
#ifdef PNG_USE_LOCAL_ARRAYS #ifdef PNG_USE_LOCAL_ARRAYS
@@ -700,7 +700,7 @@ png_push_read_IDAT(png_structp png_ptr)
} }
} }
void void /* PRIVATE */
png_process_IDAT_data(png_structp png_ptr, png_bytep buffer, png_process_IDAT_data(png_structp png_ptr, png_bytep buffer,
png_size_t buffer_length) png_size_t buffer_length)
{ {
@@ -714,23 +714,26 @@ png_process_IDAT_data(png_structp png_ptr, png_bytep buffer,
for(;;) for(;;)
{ {
ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH); ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
if (ret == Z_STREAM_END) if (ret != Z_OK)
{ {
if (png_ptr->zstream.avail_in) if (ret == Z_STREAM_END)
png_error(png_ptr, "Extra compressed data");
if (!(png_ptr->zstream.avail_out))
{ {
png_push_process_row(png_ptr); if (png_ptr->zstream.avail_in)
} png_error(png_ptr, "Extra compressed data");
if (!(png_ptr->zstream.avail_out))
{
png_push_process_row(png_ptr);
}
png_ptr->mode |= PNG_AFTER_IDAT; png_ptr->mode |= PNG_AFTER_IDAT;
png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED; png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
break; break;
}
else if (ret == Z_BUF_ERROR)
break;
else
png_error(png_ptr, "Decompression Error");
} }
else if (ret == Z_BUF_ERROR)
break;
else if (ret != Z_OK)
png_error(png_ptr, "Decompression Error");
if (!(png_ptr->zstream.avail_out)) if (!(png_ptr->zstream.avail_out))
{ {
png_push_process_row(png_ptr); png_push_process_row(png_ptr);
@@ -742,7 +745,7 @@ png_process_IDAT_data(png_structp png_ptr, png_bytep buffer,
} }
} }
void void /* PRIVATE */
png_push_process_row(png_structp png_ptr) png_push_process_row(png_structp png_ptr)
{ {
png_ptr->row_info.color_type = png_ptr->color_type; png_ptr->row_info.color_type = png_ptr->color_type;
@@ -769,18 +772,42 @@ png_push_process_row(png_structp png_ptr)
if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE)) if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
{ {
if (png_ptr->pass < 6) if (png_ptr->pass < 6)
/* old interface (pre-1.0.9):
png_do_read_interlace(&(png_ptr->row_info), png_do_read_interlace(&(png_ptr->row_info),
png_ptr->row_buf + 1, png_ptr->pass, png_ptr->transformations); png_ptr->row_buf + 1, png_ptr->pass, png_ptr->transformations);
*/
png_do_read_interlace(png_ptr);
switch (png_ptr->pass) switch (png_ptr->pass)
{ {
case 0: case 0:
{ {
int i; int i;
for (i = 0; i < 8 && png_ptr->pass == 0; i++) for (i = 0; i < 8 && png_ptr->pass == 0; i++)
{ {
png_push_have_row(png_ptr, png_ptr->row_buf + 1); png_push_have_row(png_ptr, png_ptr->row_buf + 1);
png_read_push_finish_row(png_ptr); png_read_push_finish_row(png_ptr); /* updates png_ptr->pass */
}
if (png_ptr->pass == 2) /* pass 1 might be empty */
{
for (i = 0; i < 4 && png_ptr->pass == 2; i++)
{
png_push_have_row(png_ptr, png_bytep_NULL);
png_read_push_finish_row(png_ptr);
}
}
if (png_ptr->pass == 4 && png_ptr->height <= 4)
{
for (i = 0; i < 2 && png_ptr->pass == 4; i++)
{
png_push_have_row(png_ptr, png_bytep_NULL);
png_read_push_finish_row(png_ptr);
}
}
if (png_ptr->pass == 6 && png_ptr->height <= 4)
{
png_push_have_row(png_ptr, png_bytep_NULL);
png_read_push_finish_row(png_ptr);
} }
break; break;
} }
@@ -792,11 +819,11 @@ png_push_process_row(png_structp png_ptr)
png_push_have_row(png_ptr, png_ptr->row_buf + 1); png_push_have_row(png_ptr, png_ptr->row_buf + 1);
png_read_push_finish_row(png_ptr); png_read_push_finish_row(png_ptr);
} }
if (png_ptr->pass == 2) if (png_ptr->pass == 2) /* skip top 4 generated rows */
{ {
for (i = 0; i < 4 && png_ptr->pass == 2; i++) for (i = 0; i < 4 && png_ptr->pass == 2; i++)
{ {
png_push_have_row(png_ptr, NULL); png_push_have_row(png_ptr, png_bytep_NULL);
png_read_push_finish_row(png_ptr); png_read_push_finish_row(png_ptr);
} }
} }
@@ -812,9 +839,17 @@ png_push_process_row(png_structp png_ptr)
} }
for (i = 0; i < 4 && png_ptr->pass == 2; i++) for (i = 0; i < 4 && png_ptr->pass == 2; i++)
{ {
png_push_have_row(png_ptr, NULL); png_push_have_row(png_ptr, png_bytep_NULL);
png_read_push_finish_row(png_ptr); png_read_push_finish_row(png_ptr);
} }
if (png_ptr->pass == 4) /* pass 3 might be empty */
{
for (i = 0; i < 2 && png_ptr->pass == 4; i++)
{
png_push_have_row(png_ptr, png_bytep_NULL);
png_read_push_finish_row(png_ptr);
}
}
break; break;
} }
case 3: case 3:
@@ -825,11 +860,11 @@ png_push_process_row(png_structp png_ptr)
png_push_have_row(png_ptr, png_ptr->row_buf + 1); png_push_have_row(png_ptr, png_ptr->row_buf + 1);
png_read_push_finish_row(png_ptr); png_read_push_finish_row(png_ptr);
} }
if (png_ptr->pass == 4) if (png_ptr->pass == 4) /* skip top two generated rows */
{ {
for (i = 0; i < 2 && png_ptr->pass == 4; i++) for (i = 0; i < 2 && png_ptr->pass == 4; i++)
{ {
png_push_have_row(png_ptr, NULL); png_push_have_row(png_ptr, png_bytep_NULL);
png_read_push_finish_row(png_ptr); png_read_push_finish_row(png_ptr);
} }
} }
@@ -845,7 +880,12 @@ png_push_process_row(png_structp png_ptr)
} }
for (i = 0; i < 2 && png_ptr->pass == 4; i++) for (i = 0; i < 2 && png_ptr->pass == 4; i++)
{ {
png_push_have_row(png_ptr, NULL); png_push_have_row(png_ptr, png_bytep_NULL);
png_read_push_finish_row(png_ptr);
}
if (png_ptr->pass == 6) /* pass 5 might be empty */
{
png_push_have_row(png_ptr, png_bytep_NULL);
png_read_push_finish_row(png_ptr); png_read_push_finish_row(png_ptr);
} }
break; break;
@@ -858,9 +898,9 @@ png_push_process_row(png_structp png_ptr)
png_push_have_row(png_ptr, png_ptr->row_buf + 1); png_push_have_row(png_ptr, png_ptr->row_buf + 1);
png_read_push_finish_row(png_ptr); png_read_push_finish_row(png_ptr);
} }
if (png_ptr->pass == 6) if (png_ptr->pass == 6) /* skip top generated row */
{ {
png_push_have_row(png_ptr, NULL); png_push_have_row(png_ptr, png_bytep_NULL);
png_read_push_finish_row(png_ptr); png_read_push_finish_row(png_ptr);
} }
break; break;
@@ -871,7 +911,7 @@ png_push_process_row(png_structp png_ptr)
png_read_push_finish_row(png_ptr); png_read_push_finish_row(png_ptr);
if (png_ptr->pass != 6) if (png_ptr->pass != 6)
break; break;
png_push_have_row(png_ptr, NULL); png_push_have_row(png_ptr, png_bytep_NULL);
png_read_push_finish_row(png_ptr); png_read_push_finish_row(png_ptr);
} }
} }
@@ -884,32 +924,32 @@ png_push_process_row(png_structp png_ptr)
} }
} }
void void /* PRIVATE */
png_read_push_finish_row(png_structp png_ptr) png_read_push_finish_row(png_structp png_ptr)
{ {
#ifdef PNG_USE_LOCAL_ARRAYS #ifdef PNG_USE_LOCAL_ARRAYS
/* arrays to facilitate easy interlacing - use pass (0 - 6) as index */ /* arrays to facilitate easy interlacing - use pass (0 - 6) as index */
/* start of interlace block */ /* start of interlace block */
const int png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; const int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
/* offset to next interlace block */ /* offset to next interlace block */
const int png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; const int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
/* start of interlace block in the y direction */ /* start of interlace block in the y direction */
const int png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1}; const int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
/* offset to next interlace block in the y direction */ /* offset to next interlace block in the y direction */
const int png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2}; const int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
/* Width of interlace block. This is not currently used - if you need /* Width of interlace block. This is not currently used - if you need
* it, uncomment it here and in png.h * it, uncomment it here and in png.h
const int png_pass_width[] = {8, 4, 4, 2, 2, 1, 1}; const int FARDATA png_pass_width[] = {8, 4, 4, 2, 2, 1, 1};
*/ */
/* Height of interlace block. This is not currently used - if you need /* Height of interlace block. This is not currently used - if you need
* it, uncomment it here and in png.h * it, uncomment it here and in png.h
const int png_pass_height[] = {8, 8, 4, 4, 2, 2, 1}; const int FARDATA png_pass_height[] = {8, 8, 4, 4, 2, 2, 1};
*/ */
#endif #endif
@@ -925,6 +965,11 @@ png_read_push_finish_row(png_structp png_ptr)
do do
{ {
png_ptr->pass++; png_ptr->pass++;
if ((png_ptr->pass == 1 && png_ptr->width < 5) ||
(png_ptr->pass == 3 && png_ptr->width < 3) ||
(png_ptr->pass == 5 && png_ptr->width < 2))
png_ptr->pass++;
if (png_ptr->pass >= 7) if (png_ptr->pass >= 7)
break; break;
@@ -949,10 +994,11 @@ png_read_push_finish_row(png_structp png_ptr)
} }
#if defined(PNG_READ_tEXt_SUPPORTED) #if defined(PNG_READ_tEXt_SUPPORTED)
void void /* PRIVATE */
png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
length)
{ {
if (png_ptr->mode == PNG_BEFORE_IHDR || png_ptr->mode & PNG_HAVE_IEND) if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
{ {
png_error(png_ptr, "Out of place tEXt"); png_error(png_ptr, "Out of place tEXt");
/* to quiet some compiler warnings */ /* to quiet some compiler warnings */
@@ -962,7 +1008,7 @@ png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length
#ifdef PNG_MAX_MALLOC_64K #ifdef PNG_MAX_MALLOC_64K
png_ptr->skip_length = 0; /* This may not be necessary */ png_ptr->skip_length = 0; /* This may not be necessary */
if (length > (png_uint_32)65535L) /* Can't hold the entire string in memory */ if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */
{ {
png_warning(png_ptr, "tEXt chunk too large to fit in memory"); png_warning(png_ptr, "tEXt chunk too large to fit in memory");
png_ptr->skip_length = length - (png_uint_32)65535L; png_ptr->skip_length = length - (png_uint_32)65535L;
@@ -979,7 +1025,7 @@ png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length
png_ptr->process_mode = PNG_READ_tEXt_MODE; png_ptr->process_mode = PNG_READ_tEXt_MODE;
} }
void void /* PRIVATE */
png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr) png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr)
{ {
if (png_ptr->buffer_size && png_ptr->current_text_left) if (png_ptr->buffer_size && png_ptr->current_text_left)
@@ -1024,23 +1070,27 @@ png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr)
text_ptr = (png_textp)png_malloc(png_ptr, (png_uint_32)sizeof(png_text)); text_ptr = (png_textp)png_malloc(png_ptr, (png_uint_32)sizeof(png_text));
text_ptr->compression = PNG_TEXT_COMPRESSION_NONE; text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
text_ptr->lang = (char *)NULL;
text_ptr->key = key; text_ptr->key = key;
text_ptr->lang_key = (char *)NULL; #ifdef PNG_iTXt_SUPPORTED
text_ptr->lang = NULL;
text_ptr->lang_key = NULL;
#endif
text_ptr->text = text; text_ptr->text = text;
png_set_text(png_ptr, info_ptr, text_ptr, 1); png_set_text(png_ptr, info_ptr, text_ptr, 1);
png_free(png_ptr, key);
png_free(png_ptr, text_ptr); png_free(png_ptr, text_ptr);
} }
} }
#endif #endif
#if defined(PNG_READ_zTXt_SUPPORTED) #if defined(PNG_READ_zTXt_SUPPORTED)
void void /* PRIVATE */
png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
length)
{ {
if (png_ptr->mode == PNG_BEFORE_IHDR || png_ptr->mode & PNG_HAVE_IEND) if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
{ {
png_error(png_ptr, "Out of place zTXt"); png_error(png_ptr, "Out of place zTXt");
/* to quiet some compiler warnings */ /* to quiet some compiler warnings */
@@ -1069,7 +1119,7 @@ png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length
png_ptr->process_mode = PNG_READ_zTXt_MODE; png_ptr->process_mode = PNG_READ_zTXt_MODE;
} }
void void /* PRIVATE */
png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr) png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
{ {
if (png_ptr->buffer_size && png_ptr->current_text_left) if (png_ptr->buffer_size && png_ptr->current_text_left)
@@ -1150,8 +1200,8 @@ png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
if (text == NULL) if (text == NULL)
{ {
text = (png_charp)png_malloc(png_ptr, text = (png_charp)png_malloc(png_ptr,
(png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out + (png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out
key_size + 1)); + key_size + 1));
png_memcpy(text + key_size, png_ptr->zbuf, png_memcpy(text + key_size, png_ptr->zbuf,
png_ptr->zbuf_size - png_ptr->zstream.avail_out); png_ptr->zbuf_size - png_ptr->zstream.avail_out);
png_memcpy(text, key, key_size); png_memcpy(text, key, key_size);
@@ -1206,22 +1256,26 @@ png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
text_ptr = (png_textp)png_malloc(png_ptr, (png_uint_32)sizeof(png_text)); text_ptr = (png_textp)png_malloc(png_ptr, (png_uint_32)sizeof(png_text));
text_ptr->compression = PNG_TEXT_COMPRESSION_zTXt; text_ptr->compression = PNG_TEXT_COMPRESSION_zTXt;
text_ptr->key = key; text_ptr->key = key;
text_ptr->lang = (char *)NULL; #ifdef PNG_iTXt_SUPPORTED
text_ptr->lang_key = (char *)NULL; text_ptr->lang = NULL;
text_ptr->lang_key = NULL;
#endif
text_ptr->text = text; text_ptr->text = text;
png_set_text(png_ptr, info_ptr, text_ptr, 1); png_set_text(png_ptr, info_ptr, text_ptr, 1);
png_free(png_ptr, key);
png_free(png_ptr, text_ptr); png_free(png_ptr, text_ptr);
} }
} }
#endif #endif
#if defined(PNG_READ_iTXt_SUPPORTED) #if defined(PNG_READ_iTXt_SUPPORTED)
void void /* PRIVATE */
png_push_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_push_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
length)
{ {
if (png_ptr->mode == PNG_BEFORE_IHDR || png_ptr->mode & PNG_HAVE_IEND) if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
{ {
png_error(png_ptr, "Out of place iTXt"); png_error(png_ptr, "Out of place iTXt");
/* to quiet some compiler warnings */ /* to quiet some compiler warnings */
@@ -1231,7 +1285,7 @@ png_push_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length
#ifdef PNG_MAX_MALLOC_64K #ifdef PNG_MAX_MALLOC_64K
png_ptr->skip_length = 0; /* This may not be necessary */ png_ptr->skip_length = 0; /* This may not be necessary */
if (length > (png_uint_32)65535L) /* Can't hold the entire string in memory */ if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */
{ {
png_warning(png_ptr, "iTXt chunk too large to fit in memory"); png_warning(png_ptr, "iTXt chunk too large to fit in memory");
png_ptr->skip_length = length - (png_uint_32)65535L; png_ptr->skip_length = length - (png_uint_32)65535L;
@@ -1248,7 +1302,7 @@ png_push_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length
png_ptr->process_mode = PNG_READ_iTXt_MODE; png_ptr->process_mode = PNG_READ_iTXt_MODE;
} }
void void /* PRIVATE */
png_push_read_iTXt(png_structp png_ptr, png_infop info_ptr) png_push_read_iTXt(png_structp png_ptr, png_infop info_ptr)
{ {
@@ -1268,7 +1322,7 @@ png_push_read_iTXt(png_structp png_ptr, png_infop info_ptr)
{ {
png_textp text_ptr; png_textp text_ptr;
png_charp key; png_charp key;
int comp_flag = 0; int comp_flag;
png_charp lang; png_charp lang;
png_charp lang_key; png_charp lang_key;
png_charp text; png_charp text;
@@ -1325,22 +1379,31 @@ png_push_read_iTXt(png_structp png_ptr, png_infop info_ptr)
#endif #endif
/* This function is called when we haven't found a handler for this /* This function is called when we haven't found a handler for this
* chunk. In the future we will have code here that can handle * chunk. If there isn't a problem with the chunk itself (ie a bad chunk
* user-defined callback functions for unknown chunks before they are * name or a critical chunk), the chunk is (currently) silently ignored.
* 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 void /* PRIVATE */
png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length) png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32
length)
{ {
png_uint_32 skip=0;
png_check_chunk_name(png_ptr, png_ptr->chunk_name); png_check_chunk_name(png_ptr, png_ptr->chunk_name);
if (!(png_ptr->chunk_name[0] & 0x20)) if (!(png_ptr->chunk_name[0] & 0x20))
{ {
png_chunk_error(png_ptr, "unknown critical chunk"); #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
/* to quiet some compiler warnings */ if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
if(info_ptr == NULL) return; HANDLE_CHUNK_ALWAYS
#if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
&& png_ptr->read_user_chunk_fn == NULL
#endif
)
#endif
png_chunk_error(png_ptr, "unknown critical chunk");
/* to quiet compiler warnings about unused info_ptr */
if (info_ptr == NULL)
return;
} }
#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
@@ -1357,34 +1420,49 @@ png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 len
} }
#endif #endif
strcpy((png_charp)chunk.name, (png_charp)png_ptr->chunk_name); png_strcpy((png_charp)chunk.name, (png_charp)png_ptr->chunk_name);
chunk.data = (png_bytep)png_malloc(png_ptr, length); chunk.data = (png_bytep)png_malloc(png_ptr, length);
png_crc_read(png_ptr, chunk.data, length); png_crc_read(png_ptr, chunk.data, length);
chunk.size = length; chunk.size = length;
png_set_unknown_chunks(png_ptr, info_ptr, &chunk, 1); #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
if(png_ptr->read_user_chunk_fn != NULL)
{
/* callback to user unknown chunk handler */
if ((*(png_ptr->read_user_chunk_fn)) (png_ptr, &chunk) <= 0)
{
if (!(png_ptr->chunk_name[0] & 0x20))
if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
HANDLE_CHUNK_ALWAYS)
png_chunk_error(png_ptr, "unknown critical chunk");
}
png_set_unknown_chunks(png_ptr, info_ptr, &chunk, 1);
}
else
#endif
png_set_unknown_chunks(png_ptr, info_ptr, &chunk, 1);
png_free(png_ptr, chunk.data); png_free(png_ptr, chunk.data);
} }
else else
#endif #endif
skip=length;
png_push_crc_skip(png_ptr, length); png_push_crc_skip(png_ptr, skip);
} }
void void /* PRIVATE */
png_push_have_info(png_structp png_ptr, png_infop info_ptr) png_push_have_info(png_structp png_ptr, png_infop info_ptr)
{ {
if (png_ptr->info_fn != NULL) if (png_ptr->info_fn != NULL)
(*(png_ptr->info_fn))(png_ptr, info_ptr); (*(png_ptr->info_fn))(png_ptr, info_ptr);
} }
void void /* PRIVATE */
png_push_have_end(png_structp png_ptr, png_infop info_ptr) png_push_have_end(png_structp png_ptr, png_infop info_ptr)
{ {
if (png_ptr->end_fn != NULL) if (png_ptr->end_fn != NULL)
(*(png_ptr->end_fn))(png_ptr, info_ptr); (*(png_ptr->end_fn))(png_ptr, info_ptr);
} }
void void /* PRIVATE */
png_push_have_row(png_structp png_ptr, png_bytep row) png_push_have_row(png_structp png_ptr, png_bytep row)
{ {
if (png_ptr->row_fn != NULL) if (png_ptr->row_fn != NULL)
@@ -1392,18 +1470,19 @@ png_push_have_row(png_structp png_ptr, png_bytep row)
(int)png_ptr->pass); (int)png_ptr->pass);
} }
void void PNGAPI
png_progressive_combine_row (png_structp png_ptr, png_progressive_combine_row (png_structp png_ptr,
png_bytep old_row, png_bytep new_row) png_bytep old_row, png_bytep new_row)
{ {
#ifdef PNG_USE_LOCAL_ARRAYS #ifdef PNG_USE_LOCAL_ARRAYS
const int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff}; const int FARDATA png_pass_dsp_mask[7] =
{0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
#endif #endif
if (new_row != NULL) /* new_row must == png_ptr->row_buf here. */ if (new_row != NULL) /* new_row must == png_ptr->row_buf here. */
png_combine_row(png_ptr, old_row, png_pass_dsp_mask[png_ptr->pass]); png_combine_row(png_ptr, old_row, png_pass_dsp_mask[png_ptr->pass]);
} }
void void PNGAPI
png_set_progressive_read_fn(png_structp png_ptr, png_voidp progressive_ptr, png_set_progressive_read_fn(png_structp png_ptr, png_voidp progressive_ptr,
png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn, png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
png_progressive_end_ptr end_fn) png_progressive_end_ptr end_fn)
@@ -1415,11 +1494,9 @@ png_set_progressive_read_fn(png_structp png_ptr, png_voidp progressive_ptr,
png_set_read_fn(png_ptr, progressive_ptr, png_push_fill_buffer); png_set_read_fn(png_ptr, progressive_ptr, png_push_fill_buffer);
} }
png_voidp png_voidp PNGAPI
png_get_progressive_ptr(png_structp png_ptr) png_get_progressive_ptr(png_structp png_ptr)
{ {
return png_ptr->io_ptr; return png_ptr->io_ptr;
} }
#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */ #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */

429
pngread.c
View File

@@ -1,11 +1,11 @@
/* pngread.c - read a PNG file /* pngread.c - read a PNG file
* *
* libpng 1.0.5k - December 27, 1999 * libpng 1.2.1 - December 12, 2001
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. * Copyright (c) 1998-2001 Glenn Randers-Pehrson
* Copyright (c) 1996, 1997 Andreas Dilger * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
* *
* This file contains routines that an application calls directly to * This file contains routines that an application calls directly to
* read a PNG file or stream. * read a PNG file or stream.
@@ -15,18 +15,18 @@
#include "png.h" #include "png.h"
/* Create a PNG structure for reading, and allocate any memory needed. */ /* Create a PNG structure for reading, and allocate any memory needed. */
png_structp png_structp PNGAPI
png_create_read_struct(png_const_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_error_ptr error_fn, png_error_ptr warn_fn)
{ {
#ifdef PNG_USER_MEM_SUPPORTED #ifdef PNG_USER_MEM_SUPPORTED
return (png_create_read_struct_2(user_png_ver, error_ptr, error_fn, return (png_create_read_struct_2(user_png_ver, error_ptr, error_fn,
warn_fn, NULL, NULL, NULL)); warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL));
} }
/* Alternate create PNG structure for reading, and allocate any memory needed. */ /* Alternate create PNG structure for reading, and allocate any memory needed. */
png_structp png_structp PNGAPI
png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr, png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr, png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
png_malloc_ptr malloc_fn, png_free_ptr free_fn) png_malloc_ptr malloc_fn, png_free_ptr free_fn)
@@ -34,19 +34,29 @@ png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
#endif /* PNG_USER_MEM_SUPPORTED */ #endif /* PNG_USER_MEM_SUPPORTED */
png_structp png_ptr; png_structp png_ptr;
#ifdef PNG_SETJMP_SUPPORTED
#ifdef USE_FAR_KEYWORD #ifdef USE_FAR_KEYWORD
jmp_buf jmpbuf; jmp_buf jmpbuf;
#endif #endif
#endif
int i;
png_debug(1, "in png_create_read_struct\n"); png_debug(1, "in png_create_read_struct\n");
#ifdef PNG_USER_MEM_SUPPORTED #ifdef PNG_USER_MEM_SUPPORTED
if ((png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG, if ((png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
(png_malloc_ptr)malloc_fn)) == NULL) (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr)) == NULL)
#else #else
if ((png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG)) == NULL) if ((png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG)) == NULL)
#endif #endif
{ return (NULL);
return (png_structp)NULL;
} #ifdef PNG_ASSEMBLER_CODE_SUPPORTED
png_init_mmx_flags(png_ptr); /* 1.2.0 addition */
#endif
#ifdef PNG_SETJMP_SUPPORTED
#ifdef USE_FAR_KEYWORD #ifdef USE_FAR_KEYWORD
if (setjmp(jmpbuf)) if (setjmp(jmpbuf))
#else #else
@@ -54,12 +64,14 @@ png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
#endif #endif
{ {
png_free(png_ptr, png_ptr->zbuf); png_free(png_ptr, png_ptr->zbuf);
png_ptr->zbuf=NULL;
png_destroy_struct(png_ptr); png_destroy_struct(png_ptr);
return (png_structp)NULL; return (NULL);
} }
#ifdef USE_FAR_KEYWORD #ifdef USE_FAR_KEYWORD
png_memcpy(png_ptr->jmpbuf,jmpbuf,sizeof(jmp_buf)); png_memcpy(png_ptr->jmpbuf,jmpbuf,sizeof(jmp_buf));
#endif #endif
#endif
#ifdef PNG_USER_MEM_SUPPORTED #ifdef PNG_USER_MEM_SUPPORTED
png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn); png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
@@ -67,16 +79,42 @@ png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn); png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
/* Libpng 0.90 and later are binary incompatible with libpng 0.89, so i=0;
* we must recompile any applications that use any older library version. do
* For versions after libpng 1.0, we will be compatible, so we need
* only check the first digit.
*/
if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
(user_png_ver[0] == '0' && user_png_ver[2] < '9'))
{ {
png_error(png_ptr, if(user_png_ver[i] != png_libpng_ver[i])
"Incompatible libpng version in application and library"); png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
} while (png_libpng_ver[i++]);
if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
{
/* Libpng 0.90 and later are binary incompatible with libpng 0.89, so
* we must recompile any applications that use any older library version.
* For versions after libpng 1.0, we will be compatible, so we need
* only check the first digit.
*/
if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
(user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
(user_png_ver[0] == '0' && user_png_ver[2] < '9'))
{
#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
char msg[80];
if (user_png_ver)
{
sprintf(msg, "Application was compiled with png.h from libpng-%.20s",
user_png_ver);
png_warning(png_ptr, msg);
}
sprintf(msg, "Application is running with png.c from libpng-%.20s",
png_libpng_ver);
png_warning(png_ptr, msg);
#endif
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
png_ptr->flags=0;
#endif
png_error(png_ptr,
"Incompatible libpng version in application and library");
}
} }
/* initialize zbuf - compression buffer */ /* initialize zbuf - compression buffer */
@@ -99,7 +137,7 @@ png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
png_ptr->zstream.next_out = png_ptr->zbuf; png_ptr->zstream.next_out = png_ptr->zbuf;
png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
png_set_read_fn(png_ptr, NULL, NULL); png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL);
return (png_ptr); return (png_ptr);
} }
@@ -107,20 +145,105 @@ png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
/* Initialize PNG structure for reading, and allocate any memory needed. /* Initialize PNG structure for reading, and allocate any memory needed.
This interface is deprecated in favour of the png_create_read_struct(), This interface is deprecated in favour of the png_create_read_struct(),
and it will eventually disappear. */ and it will eventually disappear. */
void #undef png_read_init
void PNGAPI
png_read_init(png_structp png_ptr) png_read_init(png_structp png_ptr)
{ {
jmp_buf tmp_jmp; /* to save current jump buffer */ /* We only come here via pre-1.0.7-compiled applications */
png_read_init_2(png_ptr, "1.0.6 or earlier", 0, 0);
}
png_debug(1, "in png_read_init\n"); #undef png_read_init_2
void PNGAPI
png_read_init_2(png_structp png_ptr, png_const_charp user_png_ver,
png_size_t png_struct_size, png_size_t png_info_size)
{
/* We only come here via pre-1.0.12-compiled applications */
#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
if(sizeof(png_struct) > png_struct_size || sizeof(png_info) > png_info_size)
{
char msg[80];
png_ptr->warning_fn=NULL;
if (user_png_ver)
{
sprintf(msg, "Application was compiled with png.h from libpng-%.20s",
user_png_ver);
png_warning(png_ptr, msg);
}
sprintf(msg, "Application is running with png.c from libpng-%.20s",
png_libpng_ver);
png_warning(png_ptr, msg);
}
#endif
if(sizeof(png_struct) > png_struct_size)
{
png_ptr->error_fn=NULL;
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
png_ptr->flags=0;
#endif
png_error(png_ptr,
"The png struct allocated by the application for reading is too small.");
}
if(sizeof(png_info) > png_info_size)
{
png_ptr->error_fn=NULL;
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
png_ptr->flags=0;
#endif
png_error(png_ptr,
"The info struct allocated by application for reading is too small.");
}
png_read_init_3(&png_ptr, user_png_ver, png_struct_size);
}
void PNGAPI
png_read_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
png_size_t png_struct_size)
{
#ifdef PNG_SETJMP_SUPPORTED
jmp_buf tmp_jmp; /* to save current jump buffer */
#endif
int i=0;
png_structp png_ptr=*ptr_ptr;
do
{
if(user_png_ver[i] != png_libpng_ver[i])
{
#ifdef PNG_LEGACY_SUPPORTED
png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
#else
png_ptr->warning_fn=NULL;
png_warning(png_ptr,
"Application uses deprecated png_read_init() and should be recompiled.");
break;
#endif
}
} while (png_libpng_ver[i++]);
png_debug(1, "in png_read_init_3\n");
#ifdef PNG_SETJMP_SUPPORTED
/* save jump buffer and error functions */ /* save jump buffer and error functions */
png_memcpy(tmp_jmp, png_ptr->jmpbuf, sizeof (jmp_buf)); png_memcpy(tmp_jmp, png_ptr->jmpbuf, sizeof (jmp_buf));
#endif
if(sizeof(png_struct) > png_struct_size)
{
png_destroy_struct(png_ptr);
*ptr_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
png_ptr = *ptr_ptr;
}
/* reset all variables to 0 */ /* reset all variables to 0 */
png_memset(png_ptr, 0, sizeof (png_struct)); png_memset(png_ptr, 0, sizeof (png_struct));
#ifdef PNG_SETJMP_SUPPORTED
/* restore jump buffer */ /* restore jump buffer */
png_memcpy(png_ptr->jmpbuf, tmp_jmp, sizeof (jmp_buf)); png_memcpy(png_ptr->jmpbuf, tmp_jmp, sizeof (jmp_buf));
#endif
/* initialize zbuf - compression buffer */ /* initialize zbuf - compression buffer */
png_ptr->zbuf_size = PNG_ZBUF_SIZE; png_ptr->zbuf_size = PNG_ZBUF_SIZE;
@@ -142,7 +265,7 @@ png_read_init(png_structp png_ptr)
png_ptr->zstream.next_out = png_ptr->zbuf; png_ptr->zstream.next_out = png_ptr->zbuf;
png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
png_set_read_fn(png_ptr, NULL, NULL); png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL);
} }
/* Read the information before the actual image data. This has been /* Read the information before the actual image data. This has been
@@ -153,7 +276,7 @@ png_read_init(png_structp png_ptr)
* here. The application can then have access to the signature bytes we * here. The application can then have access to the signature bytes we
* read if it is determined that this isn't a valid PNG file. * read if it is determined that this isn't a valid PNG file.
*/ */
void void PNGAPI
png_read_info(png_structp png_ptr, png_infop info_ptr) png_read_info(png_structp png_ptr, png_infop info_ptr)
{ {
png_debug(1, "in png_read_info\n"); png_debug(1, "in png_read_info\n");
@@ -175,6 +298,8 @@ png_read_info(png_structp png_ptr, png_infop info_ptr)
else else
png_error(png_ptr, "PNG file corrupted by ASCII conversion"); png_error(png_ptr, "PNG file corrupted by ASCII conversion");
} }
if (num_checked < 3)
png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
} }
for(;;) for(;;)
@@ -245,7 +370,7 @@ png_read_info(png_structp png_ptr, png_infop info_ptr)
png_reset_crc(png_ptr); png_reset_crc(png_ptr);
png_crc_read(png_ptr, png_ptr->chunk_name, 4); png_crc_read(png_ptr, png_ptr->chunk_name, 4);
png_debug2(0, "Reading %s chunk, length=%d.\n", png_ptr->chunk_name, png_debug2(0, "Reading %s chunk, length=%lu.\n", png_ptr->chunk_name,
length); length);
/* This should be a binary subdivision search or a hash for /* This should be a binary subdivision search or a hash for
@@ -362,13 +487,16 @@ png_read_info(png_structp png_ptr, png_infop info_ptr)
} }
/* optional call to update the users info_ptr structure */ /* optional call to update the users info_ptr structure */
void void PNGAPI
png_read_update_info(png_structp png_ptr, png_infop info_ptr) png_read_update_info(png_structp png_ptr, png_infop info_ptr)
{ {
png_debug(1, "in png_read_update_info\n"); png_debug(1, "in png_read_update_info\n");
/* save jump buffer and error functions */ /* save jump buffer and error functions */
if (!(png_ptr->flags & PNG_FLAG_ROW_INIT)) if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
png_read_start_row(png_ptr); png_read_start_row(png_ptr);
else
png_warning(png_ptr,
"Ignoring extra png_read_update_info() call; row buffer not reallocated");
png_read_transform_info(png_ptr, info_ptr); png_read_transform_info(png_ptr, info_ptr);
} }
@@ -377,7 +505,7 @@ png_read_update_info(png_structp png_ptr, png_infop info_ptr)
* the user to obtain a gamma-corrected palette, for example. * the user to obtain a gamma-corrected palette, for example.
* If the user doesn't call this, we will do it ourselves. * If the user doesn't call this, we will do it ourselves.
*/ */
void void PNGAPI
png_start_read_image(png_structp png_ptr) png_start_read_image(png_structp png_ptr)
{ {
png_debug(1, "in png_start_read_image\n"); png_debug(1, "in png_start_read_image\n");
@@ -386,7 +514,7 @@ png_start_read_image(png_structp png_ptr)
png_read_start_row(png_ptr); png_read_start_row(png_ptr);
} }
void void PNGAPI
png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row) png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
{ {
#ifdef PNG_USE_LOCAL_ARRAYS #ifdef PNG_USE_LOCAL_ARRAYS
@@ -395,7 +523,7 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
const int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff}; const int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
#endif #endif
int ret; int ret;
png_debug2(1, "in png_read_row (row %d, pass %d)\n", png_debug2(1, "in png_read_row (row %lu, pass %d)\n",
png_ptr->row_number, png_ptr->pass); png_ptr->row_number, png_ptr->pass);
/* save jump buffer and error functions */ /* save jump buffer and error functions */
if (!(png_ptr->flags & PNG_FLAG_ROW_INIT)) if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
@@ -572,6 +700,15 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf, png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
png_ptr->rowbytes + 1); png_ptr->rowbytes + 1);
#if defined(PNG_MNG_FEATURES_SUPPORTED)
if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
(png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
{
/* Intrapixel differencing */
png_do_read_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1);
}
#endif
if (png_ptr->transformations) if (png_ptr->transformations)
png_do_read_transformations(png_ptr); png_do_read_transformations(png_ptr);
@@ -582,8 +719,11 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
(png_ptr->transformations & PNG_INTERLACE)) (png_ptr->transformations & PNG_INTERLACE))
{ {
if (png_ptr->pass < 6) if (png_ptr->pass < 6)
/* old interface (pre-1.0.9):
png_do_read_interlace(&(png_ptr->row_info), png_do_read_interlace(&(png_ptr->row_info),
png_ptr->row_buf + 1, png_ptr->pass, png_ptr->transformations); png_ptr->row_buf + 1, png_ptr->pass, png_ptr->transformations);
*/
png_do_read_interlace(png_ptr);
if (dsp_row != NULL) if (dsp_row != NULL)
png_combine_row(png_ptr, dsp_row, png_combine_row(png_ptr, dsp_row,
@@ -627,10 +767,10 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
* not called png_set_interlace_handling(), the display_row buffer will * not called png_set_interlace_handling(), the display_row buffer will
* be ignored, so pass NULL to it. * be ignored, so pass NULL to it.
* *
* [*] png_handle_alpha() does not exist yet, as of libpng version 1.0.5k. * [*] png_handle_alpha() does not exist yet, as of libpng version 1.2.1
*/ */
void void PNGAPI
png_read_rows(png_structp png_ptr, png_bytepp row, png_read_rows(png_structp png_ptr, png_bytepp row,
png_bytepp display_row, png_uint_32 num_rows) png_bytepp display_row, png_uint_32 num_rows)
{ {
@@ -654,14 +794,14 @@ png_read_rows(png_structp png_ptr, png_bytepp row,
for (i = 0; i < num_rows; i++) for (i = 0; i < num_rows; i++)
{ {
png_bytep rptr = *rp; png_bytep rptr = *rp;
png_read_row(png_ptr, rptr, NULL); png_read_row(png_ptr, rptr, png_bytep_NULL);
rp++; rp++;
} }
else if(dp != NULL) else if(dp != NULL)
for (i = 0; i < num_rows; i++) for (i = 0; i < num_rows; i++)
{ {
png_bytep dptr = *dp; png_bytep dptr = *dp;
png_read_row(png_ptr, NULL, dptr); png_read_row(png_ptr, png_bytep_NULL, dptr);
dp++; dp++;
} }
} }
@@ -676,9 +816,9 @@ png_read_rows(png_structp png_ptr, png_bytepp row,
* only call this function once. If you desire to have an image for * only call this function once. If you desire to have an image for
* each pass of a interlaced image, use png_read_rows() instead. * each pass of a interlaced image, use png_read_rows() instead.
* *
* [*] png_handle_alpha() does not exist yet, as of libpng version 1.0.5k. * [*] png_handle_alpha() does not exist yet, as of libpng version 1.2.1
*/ */
void void PNGAPI
png_read_image(png_structp png_ptr, png_bytepp image) png_read_image(png_structp png_ptr, png_bytepp image)
{ {
png_uint_32 i,image_height; png_uint_32 i,image_height;
@@ -706,7 +846,7 @@ png_read_image(png_structp png_ptr, png_bytepp image)
rp = image; rp = image;
for (i = 0; i < image_height; i++) for (i = 0; i < image_height; i++)
{ {
png_read_row(png_ptr, *rp, NULL); png_read_row(png_ptr, *rp, png_bytep_NULL);
rp++; rp++;
} }
} }
@@ -716,7 +856,7 @@ png_read_image(png_structp png_ptr, png_bytepp image)
* file, will verify the end is accurate, and will read any comments * 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. * or time information at the end of the file, if info is not NULL.
*/ */
void void PNGAPI
png_read_end(png_structp png_ptr, png_infop info_ptr) png_read_end(png_structp png_ptr, png_infop info_ptr)
{ {
png_byte chunk_length[4]; png_byte chunk_length[4];
@@ -802,8 +942,10 @@ png_read_end(png_structp png_ptr, png_infop info_ptr)
else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name)) else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
{ {
if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
{
if (length > 0 || png_ptr->mode & PNG_AFTER_IDAT) if (length > 0 || png_ptr->mode & PNG_AFTER_IDAT)
png_error(png_ptr, "Too many IDAT's found"); png_error(png_ptr, "Too many IDAT's found");
}
else else
png_ptr->mode |= PNG_AFTER_IDAT; png_ptr->mode |= PNG_AFTER_IDAT;
png_handle_unknown(png_ptr, info_ptr, length); png_handle_unknown(png_ptr, info_ptr, length);
@@ -818,8 +960,7 @@ png_read_end(png_structp png_ptr, png_infop info_ptr)
*/ */
if (length > 0 || png_ptr->mode & PNG_AFTER_IDAT) if (length > 0 || png_ptr->mode & PNG_AFTER_IDAT)
png_error(png_ptr, "Too many IDAT's found"); png_error(png_ptr, "Too many IDAT's found");
else png_crc_finish(png_ptr, length);
png_crc_finish(png_ptr, 0);
} }
else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4)) else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
png_handle_PLTE(png_ptr, info_ptr, length); png_handle_PLTE(png_ptr, info_ptr, length);
@@ -897,7 +1038,7 @@ png_read_end(png_structp png_ptr, png_infop info_ptr)
} }
/* free all memory used by the read */ /* free all memory used by the read */
void void PNGAPI
png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr, png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
png_infopp end_info_ptr_ptr) png_infopp end_info_ptr_ptr)
{ {
@@ -905,6 +1046,7 @@ png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
png_infop info_ptr = NULL, end_info_ptr = NULL; png_infop info_ptr = NULL, end_info_ptr = NULL;
#ifdef PNG_USER_MEM_SUPPORTED #ifdef PNG_USER_MEM_SUPPORTED
png_free_ptr free_fn = NULL; png_free_ptr free_fn = NULL;
png_voidp mem_ptr = NULL;
#endif #endif
png_debug(1, "in png_destroy_read_struct\n"); png_debug(1, "in png_destroy_read_struct\n");
@@ -920,6 +1062,7 @@ png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
#ifdef PNG_USER_MEM_SUPPORTED #ifdef PNG_USER_MEM_SUPPORTED
free_fn = png_ptr->free_fn; free_fn = png_ptr->free_fn;
mem_ptr = png_ptr->mem_ptr;
#endif #endif
png_read_destroy(png_ptr, info_ptr, end_info_ptr); png_read_destroy(png_ptr, info_ptr, end_info_ptr);
@@ -927,46 +1070,51 @@ png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
if (info_ptr != NULL) if (info_ptr != NULL)
{ {
#if defined(PNG_TEXT_SUPPORTED) #if defined(PNG_TEXT_SUPPORTED)
png_free(png_ptr, info_ptr->text); png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, -1);
#endif #endif
#ifdef PNG_USER_MEM_SUPPORTED #ifdef PNG_USER_MEM_SUPPORTED
png_destroy_struct_2((png_voidp)info_ptr, free_fn); png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn,
(png_voidp)mem_ptr);
#else #else
png_destroy_struct((png_voidp)info_ptr); png_destroy_struct((png_voidp)info_ptr);
#endif #endif
*info_ptr_ptr = (png_infop)NULL; *info_ptr_ptr = NULL;
} }
if (end_info_ptr != NULL) if (end_info_ptr != NULL)
{ {
#if defined(PNG_READ_TEXT_SUPPORTED) #if defined(PNG_READ_TEXT_SUPPORTED)
png_free(png_ptr, end_info_ptr->text); png_free_data(png_ptr, end_info_ptr, PNG_FREE_TEXT, -1);
#endif #endif
#ifdef PNG_USER_MEM_SUPPORTED #ifdef PNG_USER_MEM_SUPPORTED
png_destroy_struct_2((png_voidp)end_info_ptr, free_fn); png_destroy_struct_2((png_voidp)end_info_ptr, (png_free_ptr)free_fn,
(png_voidp)mem_ptr);
#else #else
png_destroy_struct((png_voidp)end_info_ptr); png_destroy_struct((png_voidp)end_info_ptr);
#endif #endif
*end_info_ptr_ptr = (png_infop)NULL; *end_info_ptr_ptr = NULL;
} }
if (png_ptr != NULL) if (png_ptr != NULL)
{ {
#ifdef PNG_USER_MEM_SUPPORTED #ifdef PNG_USER_MEM_SUPPORTED
png_destroy_struct_2((png_voidp)png_ptr, free_fn); png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn,
(png_voidp)mem_ptr);
#else #else
png_destroy_struct((png_voidp)png_ptr); png_destroy_struct((png_voidp)png_ptr);
#endif #endif
*png_ptr_ptr = (png_structp)NULL; *png_ptr_ptr = NULL;
} }
} }
/* free all memory used by the read (old method) */ /* free all memory used by the read (old method) */
void void /* PRIVATE */
png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr) png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr)
{ {
#ifdef PNG_SETJMP_SUPPORTED
jmp_buf tmp_jmp; jmp_buf tmp_jmp;
#endif
png_error_ptr error_fn; png_error_ptr error_fn;
png_error_ptr warning_fn; png_error_ptr warning_fn;
png_voidp error_ptr; png_voidp error_ptr;
@@ -983,7 +1131,7 @@ png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr
png_info_destroy(png_ptr, end_info_ptr); png_info_destroy(png_ptr, end_info_ptr);
png_free(png_ptr, png_ptr->zbuf); png_free(png_ptr, png_ptr->zbuf);
png_free(png_ptr, png_ptr->row_buf); png_free(png_ptr, png_ptr->big_row_buf);
png_free(png_ptr, png_ptr->prev_row); png_free(png_ptr, png_ptr->prev_row);
#if defined(PNG_READ_DITHER_SUPPORTED) #if defined(PNG_READ_DITHER_SUPPORTED)
png_free(png_ptr, png_ptr->palette_lookup); png_free(png_ptr, png_ptr->palette_lookup);
@@ -996,16 +1144,37 @@ png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr
png_free(png_ptr, png_ptr->gamma_from_1); png_free(png_ptr, png_ptr->gamma_from_1);
png_free(png_ptr, png_ptr->gamma_to_1); png_free(png_ptr, png_ptr->gamma_to_1);
#endif #endif
if (png_ptr->flags & PNG_FLAG_FREE_PALETTE) #ifdef PNG_FREE_ME_SUPPORTED
if (png_ptr->free_me & PNG_FREE_PLTE)
png_zfree(png_ptr, png_ptr->palette); png_zfree(png_ptr, png_ptr->palette);
png_ptr->free_me &= ~PNG_FREE_PLTE;
#else
if (png_ptr->flags & PNG_FLAG_FREE_PLTE)
png_zfree(png_ptr, png_ptr->palette);
png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;
#endif
#if defined(PNG_tRNS_SUPPORTED) || \ #if defined(PNG_tRNS_SUPPORTED) || \
defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
if (png_ptr->flags & PNG_FLAG_FREE_TRANS) #ifdef PNG_FREE_ME_SUPPORTED
if (png_ptr->free_me & PNG_FREE_TRNS)
png_free(png_ptr, png_ptr->trans); png_free(png_ptr, png_ptr->trans);
png_ptr->free_me &= ~PNG_FREE_TRNS;
#else
if (png_ptr->flags & PNG_FLAG_FREE_TRNS)
png_free(png_ptr, png_ptr->trans);
png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
#endif
#endif #endif
#if defined(PNG_READ_hIST_SUPPORTED) #if defined(PNG_READ_hIST_SUPPORTED)
#ifdef PNG_FREE_ME_SUPPORTED
if (png_ptr->free_me & PNG_FREE_HIST)
png_free(png_ptr, png_ptr->hist);
png_ptr->free_me &= ~PNG_FREE_HIST;
#else
if (png_ptr->flags & PNG_FLAG_FREE_HIST) if (png_ptr->flags & PNG_FLAG_FREE_HIST)
png_free(png_ptr, png_ptr->hist); png_free(png_ptr, png_ptr->hist);
png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
#endif
#endif #endif
#if defined(PNG_READ_GAMMA_SUPPORTED) #if defined(PNG_READ_GAMMA_SUPPORTED)
if (png_ptr->gamma_16_table != NULL) if (png_ptr->gamma_16_table != NULL)
@@ -1053,7 +1222,9 @@ png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr
/* Save the important info out of the png_struct, in case it is /* Save the important info out of the png_struct, in case it is
* being used again. * being used again.
*/ */
#ifdef PNG_SETJMP_SUPPORTED
png_memcpy(tmp_jmp, png_ptr->jmpbuf, sizeof (jmp_buf)); png_memcpy(tmp_jmp, png_ptr->jmpbuf, sizeof (jmp_buf));
#endif
error_fn = png_ptr->error_fn; error_fn = png_ptr->error_fn;
warning_fn = png_ptr->warning_fn; warning_fn = png_ptr->warning_fn;
@@ -1071,11 +1242,157 @@ png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr
png_ptr->free_fn = free_fn; png_ptr->free_fn = free_fn;
#endif #endif
#ifdef PNG_SETJMP_SUPPORTED
png_memcpy(png_ptr->jmpbuf, tmp_jmp, sizeof (jmp_buf)); png_memcpy(png_ptr->jmpbuf, tmp_jmp, sizeof (jmp_buf));
#endif
} }
void void PNGAPI
png_set_read_status_fn(png_structp png_ptr, png_read_status_ptr read_row_fn) png_set_read_status_fn(png_structp png_ptr, png_read_status_ptr read_row_fn)
{ {
png_ptr->read_row_fn = read_row_fn; png_ptr->read_row_fn = read_row_fn;
} }
#if defined(PNG_INFO_IMAGE_SUPPORTED)
void PNGAPI
png_read_png(png_structp png_ptr, png_infop info_ptr,
int transforms,
voidp params)
{
int row;
#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
/* invert the alpha channel from opacity to transparency */
if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
png_set_invert_alpha(png_ptr);
#endif
/* The call to png_read_info() gives us all of the information from the
* PNG file before the first IDAT (image data chunk).
*/
png_read_info(png_ptr, info_ptr);
/* -------------- image transformations start here ------------------- */
#if defined(PNG_READ_16_TO_8_SUPPORTED)
/* tell libpng to strip 16 bit/color files down to 8 bits/color */
if (transforms & PNG_TRANSFORM_STRIP_16)
png_set_strip_16(png_ptr);
#endif
#if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
/* Strip alpha bytes from the input data without combining with the
* background (not recommended).
*/
if (transforms & PNG_TRANSFORM_STRIP_ALPHA)
png_set_strip_alpha(png_ptr);
#endif
#if defined(PNG_READ_PACK_SUPPORTED) && !defined(PNG_READ_EXPAND_SUPPORTED)
/* Extract multiple pixels with bit depths of 1, 2, and 4 from a single
* byte into separate bytes (useful for paletted and grayscale images).
*/
if (transforms & PNG_TRANSFORM_PACKING)
png_set_packing(png_ptr);
#endif
#if defined(PNG_READ_PACKSWAP_SUPPORTED)
/* Change the order of packed pixels to least significant bit first
* (not useful if you are using png_set_packing). */
if (transforms & PNG_TRANSFORM_PACKSWAP)
png_set_packswap(png_ptr);
#endif
#if defined(PNG_READ_EXPAND_SUPPORTED)
/* Expand paletted colors into true RGB triplets
* Expand grayscale images to full 8 bits from 1, 2, or 4 bits/pixel
* Expand paletted or RGB images with transparency to full alpha
* channels so the data will be available as RGBA quartets.
*/
if (transforms & PNG_TRANSFORM_EXPAND)
if ((png_ptr->bit_depth < 8) ||
(png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ||
(png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)))
png_set_expand(png_ptr);
#endif
/* We don't handle background color or gamma transformation or dithering. */
#if defined(PNG_READ_INVERT_SUPPORTED)
/* invert monochrome files to have 0 as white and 1 as black */
if (transforms & PNG_TRANSFORM_INVERT_MONO)
png_set_invert_mono(png_ptr);
#endif
#if defined(PNG_READ_SHIFT_SUPPORTED)
/* If you want to shift the pixel values from the range [0,255] or
* [0,65535] to the original [0,7] or [0,31], or whatever range the
* colors were originally in:
*/
if ((transforms & PNG_TRANSFORM_SHIFT)
&& png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT))
{
png_color_8p sig_bit;
png_get_sBIT(png_ptr, info_ptr, &sig_bit);
png_set_shift(png_ptr, sig_bit);
}
#endif
#if defined(PNG_READ_BGR_SUPPORTED)
/* flip the RGB pixels to BGR (or RGBA to BGRA) */
if (transforms & PNG_TRANSFORM_BGR)
png_set_bgr(png_ptr);
#endif
#if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
/* swap the RGBA or GA data to ARGB or AG (or BGRA to ABGR) */
if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
png_set_swap_alpha(png_ptr);
#endif
#if defined(PNG_READ_SWAP_SUPPORTED)
/* swap bytes of 16 bit files to least significant byte first */
if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
png_set_swap(png_ptr);
#endif
/* We don't handle adding filler bytes */
/* 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 (i.e., you selected such a transform above).
*/
png_read_update_info(png_ptr, info_ptr);
/* -------------- image transformations end here ------------------- */
#ifdef PNG_FREE_ME_SUPPORTED
png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
#endif
if(info_ptr->row_pointers == NULL)
{
info_ptr->row_pointers = (png_bytepp)png_malloc(png_ptr,
info_ptr->height * sizeof(png_bytep));
#ifdef PNG_FREE_ME_SUPPORTED
info_ptr->free_me |= PNG_FREE_ROWS;
#endif
for (row = 0; row < (int)info_ptr->height; row++)
{
info_ptr->row_pointers[row] = (png_bytep)png_malloc(png_ptr,
png_get_rowbytes(png_ptr, info_ptr));
}
}
png_read_image(png_ptr, info_ptr->row_pointers);
info_ptr->valid |= PNG_INFO_IDAT;
/* read rest of file, and get additional chunks in info_ptr - REQUIRED */
png_read_end(png_ptr, info_ptr);
if(transforms == 0 || params == NULL)
/* quiet compiler warnings */ return;
}
#endif

View File

@@ -1,11 +1,11 @@
/* pngrio.c - functions for data input /* pngrio.c - functions for data input
* *
* libpng 1.0.5k - December 27, 1999 * libpng 1.2.1 - December 12, 2001
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. * Copyright (c) 1998-2001 Glenn Randers-Pehrson
* Copyright (c) 1996, 1997 Andreas Dilger * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
* *
* This file provides a location for all input. Users who need * This file provides a location for all input. Users who need
* special handling are expected to write a function that has the same * special handling are expected to write a function that has the same
@@ -23,10 +23,10 @@
with very small lengths, so you should implement some kind of simple with very small lengths, so you should implement some kind of simple
buffering if you are using unbuffered reads. This should never be asked buffering if you are using unbuffered reads. This should never be asked
to read more then 64K on a 16 bit machine. */ to read more then 64K on a 16 bit machine. */
void void /* PRIVATE */
png_read_data(png_structp png_ptr, png_bytep data, png_size_t length) png_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
{ {
png_debug1(4,"reading %d bytes\n", length); png_debug1(4,"reading %d bytes\n", (int)length);
if (png_ptr->read_data_fn != NULL) if (png_ptr->read_data_fn != NULL)
(*(png_ptr->read_data_fn))(png_ptr, data, length); (*(png_ptr->read_data_fn))(png_ptr, data, length);
else else
@@ -39,7 +39,7 @@ png_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
read_data function and use it at run time with png_set_read_fn(), rather read_data function and use it at run time with png_set_read_fn(), rather
than changing the library. */ than changing the library. */
#ifndef USE_FAR_KEYWORD #ifndef USE_FAR_KEYWORD
static void static void /* PRIVATE */
png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length) png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
{ {
png_size_t check; png_size_t check;
@@ -47,13 +47,16 @@ png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
/* fread() returns 0 on error, so it is OK to store this in a png_size_t /* fread() returns 0 on error, so it is OK to store this in a png_size_t
* instead of an int, which is what fread() actually returns. * instead of an int, which is what fread() actually returns.
*/ */
#if defined(_WIN32_WCE)
if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
check = 0;
#else
check = (png_size_t)fread(data, (png_size_t)1, length, check = (png_size_t)fread(data, (png_size_t)1, length,
(FILE *)png_ptr->io_ptr); (png_FILE_p)png_ptr->io_ptr);
#endif
if (check != length) if (check != length)
{
png_error(png_ptr, "Read Error"); png_error(png_ptr, "Read Error");
}
} }
#else #else
/* this is the model-independent version. Since the standard I/O library /* this is the model-independent version. Since the standard I/O library
@@ -64,19 +67,24 @@ png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
#define NEAR_BUF_SIZE 1024 #define NEAR_BUF_SIZE 1024
#define MIN(a,b) (a <= b ? a : b) #define MIN(a,b) (a <= b ? a : b)
static void static void /* PRIVATE */
png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length) png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
{ {
int check; int check;
png_byte *n_data; png_byte *n_data;
FILE *io_ptr; png_FILE_p io_ptr;
/* Check if data really is near. If so, use usual code. */ /* Check if data really is near. If so, use usual code. */
n_data = (png_byte *)CVT_PTR_NOCHECK(data); n_data = (png_byte *)CVT_PTR_NOCHECK(data);
io_ptr = (FILE *)CVT_PTR(png_ptr->io_ptr); io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
if ((png_bytep)n_data == data) if ((png_bytep)n_data == data)
{ {
#if defined(_WIN32_WCE)
if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
check = 0;
#else
check = fread(n_data, 1, length, io_ptr); check = fread(n_data, 1, length, io_ptr);
#endif
} }
else else
{ {
@@ -87,7 +95,12 @@ png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
do do
{ {
read = MIN(NEAR_BUF_SIZE, remaining); read = MIN(NEAR_BUF_SIZE, remaining);
#if defined(_WIN32_WCE)
if ( !ReadFile((HANDLE)(io_ptr), buf, read, &err, NULL) )
err = 0;
#else
err = fread(buf, (png_size_t)1, read, io_ptr); err = fread(buf, (png_size_t)1, read, io_ptr);
#endif
png_memcpy(data, buf, read); /* copy far buffer to near buffer */ png_memcpy(data, buf, read); /* copy far buffer to near buffer */
if(err != read) if(err != read)
break; break;
@@ -99,9 +112,7 @@ png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
while (remaining != 0); while (remaining != 0);
} }
if ((png_uint_32)check != (png_uint_32)length) if ((png_uint_32)check != (png_uint_32)length)
{
png_error(png_ptr, "read Error"); png_error(png_ptr, "read Error");
}
} }
#endif #endif
#endif #endif
@@ -119,7 +130,7 @@ png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
unsigned int that is the number of bytes to be read. unsigned int that is the number of bytes to be read.
To exit and output any fatal error messages the new write To exit and output any fatal error messages the new write
function should call png_error(png_ptr, "Error msg"). */ function should call png_error(png_ptr, "Error msg"). */
void void PNGAPI
png_set_read_fn(png_structp png_ptr, png_voidp io_ptr, png_set_read_fn(png_structp png_ptr, png_voidp io_ptr,
png_rw_ptr read_data_fn) png_rw_ptr read_data_fn)
{ {
@@ -148,4 +159,3 @@ png_set_read_fn(png_structp png_ptr, png_voidp io_ptr,
png_ptr->output_flush_fn = NULL; png_ptr->output_flush_fn = NULL;
#endif #endif
} }

View File

@@ -1,11 +1,11 @@
/* pngrtran.c - transforms the data in a row for PNG readers /* pngrtran.c - transforms the data in a row for PNG readers
* *
* libpng 1.0.5k - December 27, 1999 * libpng 1.2.1 - December 12, 2001
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. * Copyright (c) 1998-2001 Glenn Randers-Pehrson
* Copyright (c) 1996, 1997 Andreas Dilger * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
* *
* This file contains functions optionally called by an application * This file contains functions optionally called by an application
* in order to tell libpng how to handle data when reading a PNG. * in order to tell libpng how to handle data when reading a PNG.
@@ -17,7 +17,7 @@
#include "png.h" #include "png.h"
/* Set the action on getting a CRC error for an ancillary or critical chunk. */ /* Set the action on getting a CRC error for an ancillary or critical chunk. */
void void PNGAPI
png_set_crc_action(png_structp png_ptr, int crit_action, int ancil_action) png_set_crc_action(png_structp png_ptr, int crit_action, int ancil_action)
{ {
png_debug(1, "in png_set_crc_action\n"); png_debug(1, "in png_set_crc_action\n");
@@ -72,7 +72,7 @@ png_set_crc_action(png_structp png_ptr, int crit_action, int ancil_action)
#if defined(PNG_READ_BACKGROUND_SUPPORTED) && \ #if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
defined(PNG_FLOATING_POINT_SUPPORTED) defined(PNG_FLOATING_POINT_SUPPORTED)
/* handle alpha and tRNS via a background color */ /* handle alpha and tRNS via a background color */
void void PNGAPI
png_set_background(png_structp png_ptr, png_set_background(png_structp png_ptr,
png_color_16p background_color, int background_gamma_code, png_color_16p background_color, int background_gamma_code,
int need_expand, double background_gamma) int need_expand, double background_gamma)
@@ -105,7 +105,7 @@ png_set_background(png_structp png_ptr,
#if defined(PNG_READ_16_TO_8_SUPPORTED) #if defined(PNG_READ_16_TO_8_SUPPORTED)
/* strip 16 bit depth files to 8 bit depth */ /* strip 16 bit depth files to 8 bit depth */
void void PNGAPI
png_set_strip_16(png_structp png_ptr) png_set_strip_16(png_structp png_ptr)
{ {
png_debug(1, "in png_set_strip_16\n"); png_debug(1, "in png_set_strip_16\n");
@@ -114,7 +114,7 @@ png_set_strip_16(png_structp png_ptr)
#endif #endif
#if defined(PNG_READ_STRIP_ALPHA_SUPPORTED) #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
void void PNGAPI
png_set_strip_alpha(png_structp png_ptr) png_set_strip_alpha(png_structp png_ptr)
{ {
png_debug(1, "in png_set_strip_alpha\n"); png_debug(1, "in png_set_strip_alpha\n");
@@ -141,7 +141,7 @@ typedef struct png_dsort_struct
typedef png_dsort FAR * png_dsortp; typedef png_dsort FAR * png_dsortp;
typedef png_dsort FAR * FAR * png_dsortpp; typedef png_dsort FAR * FAR * png_dsortpp;
void void PNGAPI
png_set_dither(png_structp png_ptr, png_colorp palette, png_set_dither(png_structp png_ptr, png_colorp palette,
int num_palette, int maximum_colors, png_uint_16p histogram, int num_palette, int maximum_colors, png_uint_16p histogram,
int full_dither) int full_dither)
@@ -511,7 +511,7 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
* are not close reciprocals, otherwise it slows things down slightly, and * are not close reciprocals, otherwise it slows things down slightly, and
* also needlessly introduces small errors. * also needlessly introduces small errors.
*/ */
void void PNGAPI
png_set_gamma(png_structp png_ptr, double scrn_gamma, double file_gamma) png_set_gamma(png_structp png_ptr, double scrn_gamma, double file_gamma)
{ {
png_debug(1, "in png_set_gamma\n"); png_debug(1, "in png_set_gamma\n");
@@ -527,7 +527,7 @@ png_set_gamma(png_structp png_ptr, double scrn_gamma, double file_gamma)
* less than 8-bit depth to 8-bit depth, and expand tRNS chunks * less than 8-bit depth to 8-bit depth, and expand tRNS chunks
* to alpha channels. * to alpha channels.
*/ */
void void PNGAPI
png_set_expand(png_structp png_ptr) png_set_expand(png_structp png_ptr)
{ {
png_debug(1, "in png_set_expand\n"); png_debug(1, "in png_set_expand\n");
@@ -549,7 +549,7 @@ png_set_expand(png_structp png_ptr)
*/ */
/* Expand paletted images to RGB. */ /* Expand paletted images to RGB. */
void void PNGAPI
png_set_palette_to_rgb(png_structp png_ptr) png_set_palette_to_rgb(png_structp png_ptr)
{ {
png_debug(1, "in png_set_expand\n"); png_debug(1, "in png_set_expand\n");
@@ -557,7 +557,7 @@ png_set_palette_to_rgb(png_structp png_ptr)
} }
/* Expand grayscale images of less than 8-bit depth to 8 bits. */ /* Expand grayscale images of less than 8-bit depth to 8 bits. */
void void PNGAPI
png_set_gray_1_2_4_to_8(png_structp png_ptr) png_set_gray_1_2_4_to_8(png_structp png_ptr)
{ {
png_debug(1, "in png_set_expand\n"); png_debug(1, "in png_set_expand\n");
@@ -565,7 +565,7 @@ png_set_gray_1_2_4_to_8(png_structp png_ptr)
} }
/* Expand tRNS chunks to alpha channels. */ /* Expand tRNS chunks to alpha channels. */
void void PNGAPI
png_set_tRNS_to_alpha(png_structp png_ptr) png_set_tRNS_to_alpha(png_structp png_ptr)
{ {
png_debug(1, "in png_set_expand\n"); png_debug(1, "in png_set_expand\n");
@@ -574,7 +574,7 @@ png_set_tRNS_to_alpha(png_structp png_ptr)
#endif /* defined(PNG_READ_EXPAND_SUPPORTED) */ #endif /* defined(PNG_READ_EXPAND_SUPPORTED) */
#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED) #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
void void PNGAPI
png_set_gray_to_rgb(png_structp png_ptr) png_set_gray_to_rgb(png_structp png_ptr)
{ {
png_debug(1, "in png_set_gray_to_rgb\n"); png_debug(1, "in png_set_gray_to_rgb\n");
@@ -582,14 +582,25 @@ png_set_gray_to_rgb(png_structp png_ptr)
} }
#endif #endif
#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) && \ #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
defined(PNG_FLOATING_POINT_SUPPORTED) #if defined(PNG_FLOATING_POINT_SUPPORTED)
/* Convert a RGB image to a grayscale of the same width. This allows us, /* Convert a RGB image to a grayscale of the same width. This allows us,
* for example, to convert a 24 bpp RGB image into an 8 bpp grayscale image. * for example, to convert a 24 bpp RGB image into an 8 bpp grayscale image.
*/ */
void
void PNGAPI
png_set_rgb_to_gray(png_structp png_ptr, int error_action, double red, png_set_rgb_to_gray(png_structp png_ptr, int error_action, double red,
double green) double green)
{
int red_fixed = (int)((float)red*100000.0 + 0.5);
int green_fixed = (int)((float)green*100000.0 + 0.5);
png_set_rgb_to_gray_fixed(png_ptr, error_action, red_fixed, green_fixed);
}
#endif
void PNGAPI
png_set_rgb_to_gray_fixed(png_structp png_ptr, int error_action,
png_fixed_point red, png_fixed_point green)
{ {
png_debug(1, "in png_set_rgb_to_gray\n"); png_debug(1, "in png_set_rgb_to_gray\n");
switch(error_action) switch(error_action)
@@ -610,41 +621,54 @@ png_set_rgb_to_gray(png_structp png_ptr, int error_action, double red,
} }
#endif #endif
{ {
png_byte red_byte = (png_byte)((float)red*255.0 + 0.5); png_uint_16 red_int, green_int;
png_byte green_byte = (png_byte)((float)green*255.0 + 0.5); if(red < 0 || green < 0)
if(red < 0.0 || green < 0.0)
{ {
red_byte = 54; red_int = 6968; /* .212671 * 32768 + .5 */
green_byte = 183; green_int = 23434; /* .715160 * 32768 + .5 */
} }
else if(red_byte + green_byte > 255) else if(red + green < 100000L)
{
red_int = (png_uint_16)(((png_uint_32)red*32768L)/100000L);
green_int = (png_uint_16)(((png_uint_32)green*32768L)/100000L);
}
else
{ {
png_warning(png_ptr, "ignoring out of range rgb_to_gray coefficients"); png_warning(png_ptr, "ignoring out of range rgb_to_gray coefficients");
red_byte = 54; red_int = 6968;
green_byte = 183; green_int = 23434;
} }
png_ptr->rgb_to_gray_red_coeff = red_byte; png_ptr->rgb_to_gray_red_coeff = red_int;
png_ptr->rgb_to_gray_green_coeff = green_byte; png_ptr->rgb_to_gray_green_coeff = green_int;
png_ptr->rgb_to_gray_blue_coeff = (png_byte)(255-red_byte-green_byte); png_ptr->rgb_to_gray_blue_coeff = (png_uint_16)(32768-red_int-green_int);
} }
} }
#endif #endif
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
void defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
defined(PNG_LEGACY_SUPPORTED)
void PNGAPI
png_set_read_user_transform_fn(png_structp png_ptr, png_user_transform_ptr png_set_read_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
read_user_transform_fn) read_user_transform_fn)
{ {
png_debug(1, "in png_set_read_user_transform_fn\n"); png_debug(1, "in png_set_read_user_transform_fn\n");
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
png_ptr->transformations |= PNG_USER_TRANSFORM; png_ptr->transformations |= PNG_USER_TRANSFORM;
png_ptr->read_user_transform_fn = read_user_transform_fn; png_ptr->read_user_transform_fn = read_user_transform_fn;
#endif
#ifdef PNG_LEGACY_SUPPORTED
if(read_user_transform_fn)
png_warning(png_ptr,
"This version of libpng does not support user transforms");
#endif
} }
#endif #endif
/* Initialize everything needed for the read. This includes modifying /* Initialize everything needed for the read. This includes modifying
* the palette. * the palette.
*/ */
void void /* PRIVATE */
png_init_read_transformations(png_structp png_ptr) png_init_read_transformations(png_structp png_ptr)
{ {
png_debug(1, "in png_init_read_transformations\n"); png_debug(1, "in png_init_read_transformations\n");
@@ -658,7 +682,8 @@ png_init_read_transformations(png_structp png_ptr)
#endif #endif
#if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED) #if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED)
if (png_ptr->transformations & PNG_BACKGROUND_EXPAND) if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
(png_ptr->transformations & PNG_EXPAND))
{ {
if (!(color_type & PNG_COLOR_MASK_COLOR)) /* i.e., GRAY or GRAY_ALPHA */ if (!(color_type & PNG_COLOR_MASK_COLOR)) /* i.e., GRAY or GRAY_ALPHA */
{ {
@@ -717,7 +742,7 @@ png_init_read_transformations(png_structp png_ptr)
} }
#endif #endif
#if defined(PNG_READ_BACKGROUND_SUPPORTED) #if defined(PNG_READ_BACKGROUND_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
png_ptr->background_1 = png_ptr->background; png_ptr->background_1 = png_ptr->background;
#endif #endif
#if defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED) #if defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
@@ -876,7 +901,7 @@ png_init_read_transformations(png_structp png_ptr)
} }
else else
/* transformation does not include PNG_BACKGROUND */ /* transformation does not include PNG_BACKGROUND */
#endif #endif /* PNG_READ_BACKGROUND_SUPPORTED */
if (color_type == PNG_COLOR_TYPE_PALETTE) if (color_type == PNG_COLOR_TYPE_PALETTE)
{ {
png_colorp palette = png_ptr->palette; png_colorp palette = png_ptr->palette;
@@ -894,7 +919,7 @@ png_init_read_transformations(png_structp png_ptr)
#if defined(PNG_READ_BACKGROUND_SUPPORTED) #if defined(PNG_READ_BACKGROUND_SUPPORTED)
else else
#endif #endif
#endif #endif /* PNG_READ_GAMMA_SUPPORTED && PNG_FLOATING_POINT_SUPPORTED */
#if defined(PNG_READ_BACKGROUND_SUPPORTED) #if defined(PNG_READ_BACKGROUND_SUPPORTED)
/* No GAMMA transformation */ /* No GAMMA transformation */
if ((png_ptr->transformations & PNG_BACKGROUND) && if ((png_ptr->transformations & PNG_BACKGROUND) &&
@@ -927,7 +952,7 @@ png_init_read_transformations(png_structp png_ptr)
} }
} }
} }
#endif #endif /* PNG_READ_BACKGROUND_SUPPORTED */
#if defined(PNG_READ_SHIFT_SUPPORTED) #if defined(PNG_READ_SHIFT_SUPPORTED)
if ((png_ptr->transformations & PNG_SHIFT) && if ((png_ptr->transformations & PNG_SHIFT) &&
@@ -952,15 +977,20 @@ png_init_read_transformations(png_structp png_ptr)
png_ptr->palette[i].blue >>= sb; png_ptr->palette[i].blue >>= sb;
} }
} }
#endif #endif /* PNG_READ_SHIFT_SUPPORTED */
} }
#if !defined(PNG_READ_GAMMA_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED) \
&& !defined(PNG_READ_BACKGROUND_SUPPORTED)
if(png_ptr)
return;
#endif
} }
/* Modify the info structure to reflect the transformations. The /* Modify the info structure to reflect the transformations. The
* info should be updated so a PNG file could be written with it, * info should be updated so a PNG file could be written with it,
* assuming the transformations result in valid PNG data. * assuming the transformations result in valid PNG data.
*/ */
void void /* PRIVATE */
png_read_transform_info(png_structp png_ptr, png_infop info_ptr) png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
{ {
png_debug(1, "in png_read_transform_info\n"); png_debug(1, "in png_read_transform_info\n");
@@ -1060,10 +1090,16 @@ png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
if ((png_ptr->transformations & PNG_FILLER) && if ((png_ptr->transformations & PNG_FILLER) &&
((info_ptr->color_type == PNG_COLOR_TYPE_RGB) || ((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||
(info_ptr->color_type == PNG_COLOR_TYPE_GRAY))) (info_ptr->color_type == PNG_COLOR_TYPE_GRAY)))
{
info_ptr->channels++; info_ptr->channels++;
#if 0 /* if adding a true alpha channel not just filler */
info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
#endif
}
#endif #endif
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) && \
defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
if(png_ptr->transformations & PNG_USER_TRANSFORM) if(png_ptr->transformations & PNG_USER_TRANSFORM)
{ {
if(info_ptr->bit_depth < png_ptr->user_transform_depth) if(info_ptr->bit_depth < png_ptr->user_transform_depth)
@@ -1077,20 +1113,24 @@ png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
info_ptr->bit_depth); info_ptr->bit_depth);
info_ptr->rowbytes = ((info_ptr->width * info_ptr->pixel_depth + 7) >> 3); info_ptr->rowbytes = ((info_ptr->width * info_ptr->pixel_depth + 7) >> 3);
#if !defined(PNG_READ_EXPAND_SUPPORTED)
if(png_ptr)
return;
#endif
} }
/* Transform the row. The order of transformations is significant, /* Transform the row. The order of transformations is significant,
* and is very touchy. If you add a transformation, take care to * and is very touchy. If you add a transformation, take care to
* decide how it fits in with the other transformations here. * decide how it fits in with the other transformations here.
*/ */
void void /* PRIVATE */
png_do_read_transformations(png_structp png_ptr) png_do_read_transformations(png_structp png_ptr)
{ {
png_debug(1, "in png_do_read_transformations\n"); png_debug(1, "in png_do_read_transformations\n");
#if !defined(PNG_USELESS_TESTS_SUPPORTED) #if !defined(PNG_USELESS_TESTS_SUPPORTED)
if (png_ptr->row_buf == NULL) if (png_ptr->row_buf == NULL)
{ {
#if !defined(PNG_NO_STDIO) #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
char msg[50]; char msg[50];
sprintf(msg, "NULL row buffer for row %ld, pass %d", png_ptr->row_number, sprintf(msg, "NULL row buffer for row %ld, pass %d", png_ptr->row_number,
@@ -1187,12 +1227,15 @@ From Andreas Dilger e-mail to png-implement, 26 March 1998:
((png_ptr->num_trans != 0 ) || ((png_ptr->num_trans != 0 ) ||
(png_ptr->color_type & PNG_COLOR_MASK_ALPHA))) (png_ptr->color_type & PNG_COLOR_MASK_ALPHA)))
png_do_background(&(png_ptr->row_info), png_ptr->row_buf + 1, png_do_background(&(png_ptr->row_info), png_ptr->row_buf + 1,
&(png_ptr->trans_values), &(png_ptr->background), &(png_ptr->trans_values), &(png_ptr->background)
&(png_ptr->background_1), #if defined(PNG_READ_GAMMA_SUPPORTED)
, &(png_ptr->background_1),
png_ptr->gamma_table, png_ptr->gamma_from_1, png_ptr->gamma_table, png_ptr->gamma_from_1,
png_ptr->gamma_to_1, png_ptr->gamma_16_table, png_ptr->gamma_to_1, png_ptr->gamma_16_table,
png_ptr->gamma_16_from_1, png_ptr->gamma_16_to_1, png_ptr->gamma_16_from_1, png_ptr->gamma_16_to_1,
png_ptr->gamma_shift); png_ptr->gamma_shift
#endif
);
#endif #endif
#if defined(PNG_READ_GAMMA_SUPPORTED) #if defined(PNG_READ_GAMMA_SUPPORTED)
@@ -1291,10 +1334,12 @@ From Andreas Dilger e-mail to png-implement, 26 March 1998:
/* png_byte channels; number of channels (1-4) */ /* png_byte channels; number of channels (1-4) */
/* png_byte pixel_depth; bits per pixel (depth*channels) */ /* png_byte pixel_depth; bits per pixel (depth*channels) */
png_ptr->row_buf + 1); /* start of pixel data for row */ png_ptr->row_buf + 1); /* start of pixel data for row */
#if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
if(png_ptr->user_transform_depth) if(png_ptr->user_transform_depth)
png_ptr->row_info.bit_depth = png_ptr->user_transform_depth; png_ptr->row_info.bit_depth = png_ptr->user_transform_depth;
if(png_ptr->user_transform_channels) if(png_ptr->user_transform_channels)
png_ptr->row_info.channels = png_ptr->user_transform_channels; png_ptr->row_info.channels = png_ptr->user_transform_channels;
#endif
png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth * png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth *
png_ptr->row_info.channels); png_ptr->row_info.channels);
png_ptr->row_info.rowbytes = (png_ptr->row_info.width * png_ptr->row_info.rowbytes = (png_ptr->row_info.width *
@@ -1311,7 +1356,7 @@ From Andreas Dilger e-mail to png-implement, 26 March 1998:
* the numbers 0 or 1. If you would rather they contain 0 and 255, use * the numbers 0 or 1. If you would rather they contain 0 and 255, use
* png_do_shift() after this. * png_do_shift() after this.
*/ */
void void /* PRIVATE */
png_do_unpack(png_row_infop row_info, png_bytep row) png_do_unpack(png_row_infop row_info, png_bytep row)
{ {
png_debug(1, "in png_do_unpack\n"); png_debug(1, "in png_do_unpack\n");
@@ -1401,7 +1446,7 @@ png_do_unpack(png_row_infop row_info, png_bytep row)
* a row of bit depth 8, but only 5 are significant, this will shift * a row of bit depth 8, but only 5 are significant, this will shift
* the values back to 0 through 31. * the values back to 0 through 31.
*/ */
void void /* PRIVATE */
png_do_unshift(png_row_infop row_info, png_bytep row, png_color_8p sig_bits) png_do_unshift(png_row_infop row_info, png_bytep row, png_color_8p sig_bits)
{ {
png_debug(1, "in png_do_unshift\n"); png_debug(1, "in png_do_unshift\n");
@@ -1507,7 +1552,7 @@ png_do_unshift(png_row_infop row_info, png_bytep row, png_color_8p sig_bits)
#if defined(PNG_READ_16_TO_8_SUPPORTED) #if defined(PNG_READ_16_TO_8_SUPPORTED)
/* chop rows of bit depth 16 down to 8 */ /* chop rows of bit depth 16 down to 8 */
void void /* PRIVATE */
png_do_chop(png_row_infop row_info, png_bytep row) png_do_chop(png_row_infop row_info, png_bytep row)
{ {
png_debug(1, "in png_do_chop\n"); png_debug(1, "in png_do_chop\n");
@@ -1561,7 +1606,7 @@ png_do_chop(png_row_infop row_info, png_bytep row)
#endif #endif
#if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
void void /* PRIVATE */
png_do_read_swap_alpha(png_row_infop row_info, png_bytep row) png_do_read_swap_alpha(png_row_infop row_info, png_bytep row)
{ {
png_debug(1, "in png_do_read_swap_alpha\n"); png_debug(1, "in png_do_read_swap_alpha\n");
@@ -1653,7 +1698,7 @@ png_do_read_swap_alpha(png_row_infop row_info, png_bytep row)
#endif #endif
#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
void void /* PRIVATE */
png_do_read_invert_alpha(png_row_infop row_info, png_bytep row) png_do_read_invert_alpha(png_row_infop row_info, png_bytep row)
{ {
png_debug(1, "in png_do_read_invert_alpha\n"); png_debug(1, "in png_do_read_invert_alpha\n");
@@ -1674,9 +1719,15 @@ png_do_read_invert_alpha(png_row_infop row_info, png_bytep row)
for (i = 0; i < row_width; i++) for (i = 0; i < row_width; i++)
{ {
*(--dp) = (png_byte)(255 - *(--sp)); *(--dp) = (png_byte)(255 - *(--sp));
/* This does nothing:
*(--dp) = *(--sp); *(--dp) = *(--sp);
*(--dp) = *(--sp); *(--dp) = *(--sp);
*(--dp) = *(--sp); *(--dp) = *(--sp);
We can replace it with:
*/
sp-=3;
dp=sp;
} }
} }
/* This inverts the alpha channel in RRGGBBAA */ /* This inverts the alpha channel in RRGGBBAA */
@@ -1690,12 +1741,18 @@ png_do_read_invert_alpha(png_row_infop row_info, png_bytep row)
{ {
*(--dp) = (png_byte)(255 - *(--sp)); *(--dp) = (png_byte)(255 - *(--sp));
*(--dp) = (png_byte)(255 - *(--sp)); *(--dp) = (png_byte)(255 - *(--sp));
/* This does nothing:
*(--dp) = *(--sp); *(--dp) = *(--sp);
*(--dp) = *(--sp); *(--dp) = *(--sp);
*(--dp) = *(--sp); *(--dp) = *(--sp);
*(--dp) = *(--sp); *(--dp) = *(--sp);
*(--dp) = *(--sp); *(--dp) = *(--sp);
*(--dp) = *(--sp); *(--dp) = *(--sp);
We can replace it with:
*/
sp-=6;
dp=sp;
} }
} }
} }
@@ -1725,8 +1782,12 @@ png_do_read_invert_alpha(png_row_infop row_info, png_bytep row)
{ {
*(--dp) = (png_byte)(255 - *(--sp)); *(--dp) = (png_byte)(255 - *(--sp));
*(--dp) = (png_byte)(255 - *(--sp)); *(--dp) = (png_byte)(255 - *(--sp));
/*
*(--dp) = *(--sp); *(--dp) = *(--sp);
*(--dp) = *(--sp); *(--dp) = *(--sp);
*/
sp-=2;
dp=sp;
} }
} }
} }
@@ -1736,7 +1797,7 @@ png_do_read_invert_alpha(png_row_infop row_info, png_bytep row)
#if defined(PNG_READ_FILLER_SUPPORTED) #if defined(PNG_READ_FILLER_SUPPORTED)
/* Add filler channel if we have RGB color */ /* Add filler channel if we have RGB color */
void void /* PRIVATE */
png_do_read_filler(png_row_infop row_info, png_bytep row, png_do_read_filler(png_row_infop row_info, png_bytep row,
png_uint_32 filler, png_uint_32 flags) png_uint_32 filler, png_uint_32 flags)
{ {
@@ -1912,7 +1973,7 @@ png_do_read_filler(png_row_infop row_info, png_bytep row,
#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED) #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
/* expand grayscale files to RGB, with or without alpha */ /* expand grayscale files to RGB, with or without alpha */
void void /* PRIVATE */
png_do_gray_to_rgb(png_row_infop row_info, png_bytep row) png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
{ {
png_uint_32 i; png_uint_32 i;
@@ -2004,17 +2065,17 @@ png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
* *
* We approximate this with * We approximate this with
* *
* Y = 0.211 * R + 0.715 * G + 0.074 * B * Y = 0.21268 * R + 0.7151 * G + 0.07217 * B
* *
* which can be expressed with integers as * which can be expressed with integers as
* *
* Y = (54 * R + 183 * G + 19 * B)/256 * Y = (6969 * R + 23434 * G + 2365 * B)/32768
* *
* The calculation is to be done in a linear colorspace. * The calculation is to be done in a linear colorspace.
* *
* Other integer coefficents can be used via png_set_rgb_to_gray(). * Other integer coefficents can be used via png_set_rgb_to_gray().
*/ */
int int /* PRIVATE */
png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row) png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
{ {
@@ -2030,9 +2091,9 @@ png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
#endif #endif
(row_info->color_type & PNG_COLOR_MASK_COLOR)) (row_info->color_type & PNG_COLOR_MASK_COLOR))
{ {
png_byte rc = png_ptr->rgb_to_gray_red_coeff; png_uint_32 rc = png_ptr->rgb_to_gray_red_coeff;
png_byte gc = png_ptr->rgb_to_gray_green_coeff; png_uint_32 gc = png_ptr->rgb_to_gray_green_coeff;
png_byte bc = png_ptr->rgb_to_gray_blue_coeff; png_uint_32 bc = png_ptr->rgb_to_gray_blue_coeff;
if (row_info->color_type == PNG_COLOR_TYPE_RGB) if (row_info->color_type == PNG_COLOR_TYPE_RGB)
{ {
@@ -2053,7 +2114,7 @@ png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
{ {
rgb_error |= 1; rgb_error |= 1;
*(dp++) = png_ptr->gamma_from_1[ *(dp++) = png_ptr->gamma_from_1[
(rc*red+gc*green+bc*blue)>>8]; (rc*red+gc*green+bc*blue)>>15];
} }
else else
*(dp++) = *(sp-1); *(dp++) = *(sp-1);
@@ -2072,7 +2133,7 @@ png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
if(red != green || red != blue) if(red != green || red != blue)
{ {
rgb_error |= 1; rgb_error |= 1;
*(dp++) = (png_byte)((rc*red+gc*green+bc*blue)>>8); *(dp++) = (png_byte)((rc*red+gc*green+bc*blue)>>15);
} }
else else
*(dp++) = *(sp-1); *(dp++) = *(sp-1);
@@ -2107,7 +2168,7 @@ png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >> png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >>
png_ptr->gamma_shift][blue>>8]; png_ptr->gamma_shift][blue>>8];
png_uint_16 gray16 = (png_uint_16)((rc*red_1 + gc*green_1 png_uint_16 gray16 = (png_uint_16)((rc*red_1 + gc*green_1
+ bc*blue_1)>>8); + bc*blue_1)>>15);
w = png_ptr->gamma_16_from_1[(gray16&0xff) >> w = png_ptr->gamma_16_from_1[(gray16&0xff) >>
png_ptr->gamma_shift][gray16 >> 8]; png_ptr->gamma_shift][gray16 >> 8];
rgb_error |= 1; rgb_error |= 1;
@@ -2132,7 +2193,7 @@ png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
if(red != green || red != blue) if(red != green || red != blue)
rgb_error |= 1; rgb_error |= 1;
gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>8); gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15);
*(dp++) = (png_byte)((gray16>>8) & 0xff); *(dp++) = (png_byte)((gray16>>8) & 0xff);
*(dp++) = (png_byte)(gray16 & 0xff); *(dp++) = (png_byte)(gray16 & 0xff);
} }
@@ -2156,7 +2217,7 @@ png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
if(red != green || red != blue) if(red != green || red != blue)
rgb_error |= 1; rgb_error |= 1;
*(dp++) = png_ptr->gamma_from_1 *(dp++) = png_ptr->gamma_from_1
[(rc*red + gc*green + bc*blue)>>8]; [(rc*red + gc*green + bc*blue)>>15];
*(dp++) = *(sp++); /* alpha */ *(dp++) = *(sp++); /* alpha */
} }
} }
@@ -2204,7 +2265,7 @@ png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >> png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >>
png_ptr->gamma_shift][blue>>8]; png_ptr->gamma_shift][blue>>8];
png_uint_16 gray16 = (png_uint_16)((rc * red_1 png_uint_16 gray16 = (png_uint_16)((rc * red_1
+ gc * green_1 + bc * blue_1)>>8); + gc * green_1 + bc * blue_1)>>15);
w = png_ptr->gamma_16_from_1[(gray16&0xff) >> w = png_ptr->gamma_16_from_1[(gray16&0xff) >>
png_ptr->gamma_shift][gray16 >> 8]; png_ptr->gamma_shift][gray16 >> 8];
rgb_error |= 1; rgb_error |= 1;
@@ -2229,7 +2290,7 @@ png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
blue = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2; blue = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
if(red != green || red != blue) if(red != green || red != blue)
rgb_error |= 1; rgb_error |= 1;
gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>8); gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15);
*(dp++) = (png_byte)((gray16>>8) & 0xff); *(dp++) = (png_byte)((gray16>>8) & 0xff);
*(dp++) = (png_byte)(gray16 & 0xff); *(dp++) = (png_byte)(gray16 & 0xff);
*(dp++) = *(sp++); /* alpha */ *(dp++) = *(sp++); /* alpha */
@@ -2254,7 +2315,7 @@ png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
* paletted. Most useful for gamma correction and simplification * paletted. Most useful for gamma correction and simplification
* of code. * of code.
*/ */
void void /* PRIVATE */
png_build_grayscale_palette(int bit_depth, png_colorp palette) png_build_grayscale_palette(int bit_depth, png_colorp palette)
{ {
int num_palette; int num_palette;
@@ -2300,7 +2361,7 @@ png_build_grayscale_palette(int bit_depth, png_colorp palette)
/* This function is currently unused. Do we really need it? */ /* This function is currently unused. Do we really need it? */
#if defined(PNG_READ_DITHER_SUPPORTED) && defined(PNG_CORRECT_PALETTE_SUPPORTED) #if defined(PNG_READ_DITHER_SUPPORTED) && defined(PNG_CORRECT_PALETTE_SUPPORTED)
void void /* PRIVATE */
png_correct_palette(png_structp png_ptr, png_colorp palette, png_correct_palette(png_structp png_ptr, png_colorp palette,
int num_palette) int num_palette)
{ {
@@ -2485,13 +2546,16 @@ png_correct_palette(png_structp png_ptr, png_colorp palette,
* "background" is already in the screen gamma, while "background_1" is * "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. * at a gamma of 1.0. Paletted files have already been taken care of.
*/ */
void void /* PRIVATE */
png_do_background(png_row_infop row_info, png_bytep row, png_do_background(png_row_infop row_info, png_bytep row,
png_color_16p trans_values, png_color_16p background, png_color_16p trans_values, png_color_16p background
png_color_16p background_1, #if defined(PNG_READ_GAMMA_SUPPORTED)
, png_color_16p background_1,
png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1, png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1,
png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1, png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1,
png_uint_16pp gamma_16_to_1, int gamma_shift) png_uint_16pp gamma_16_to_1, int gamma_shift
#endif
)
{ {
png_bytep sp, dp; png_bytep sp, dp;
png_uint_32 i; png_uint_32 i;
@@ -2874,6 +2938,7 @@ png_do_background(png_row_infop row_info, png_bytep row,
{ {
*dp = *sp; *dp = *sp;
} }
#if defined(PNG_READ_GAMMA_SUPPORTED)
else if (a == 0) else if (a == 0)
{ {
*dp = (png_byte)background->gray; *dp = (png_byte)background->gray;
@@ -2882,6 +2947,9 @@ png_do_background(png_row_infop row_info, png_bytep row,
{ {
png_composite(*dp, *sp, a, background_1->gray); png_composite(*dp, *sp, a, background_1->gray);
} }
#else
*dp = (png_byte)background->gray;
#endif
} }
} }
} }
@@ -2905,12 +2973,17 @@ png_do_background(png_row_infop row_info, png_bytep row,
*dp = (png_byte)((v >> 8) & 0xff); *dp = (png_byte)((v >> 8) & 0xff);
*(dp + 1) = (png_byte)(v & 0xff); *(dp + 1) = (png_byte)(v & 0xff);
} }
#if defined(PNG_READ_GAMMA_SUPPORTED)
else if (a == 0) else if (a == 0)
#else
else
#endif
{ {
/* background is already in screen gamma */ /* background is already in screen gamma */
*dp = (png_byte)((background->gray >> 8) & 0xff); *dp = (png_byte)((background->gray >> 8) & 0xff);
*(dp + 1) = (png_byte)(background->gray & 0xff); *(dp + 1) = (png_byte)(background->gray & 0xff);
} }
#if defined(PNG_READ_GAMMA_SUPPORTED)
else else
{ {
png_uint_16 g, v, w; png_uint_16 g, v, w;
@@ -2921,6 +2994,7 @@ png_do_background(png_row_infop row_info, png_bytep row,
*dp = (png_byte)((w >> 8) & 0xff); *dp = (png_byte)((w >> 8) & 0xff);
*(dp + 1) = (png_byte)(w & 0xff); *(dp + 1) = (png_byte)(w & 0xff);
} }
#endif
} }
} }
else else
@@ -2935,11 +3009,16 @@ png_do_background(png_row_infop row_info, png_bytep row,
{ {
png_memcpy(dp, sp, 2); png_memcpy(dp, sp, 2);
} }
#if defined(PNG_READ_GAMMA_SUPPORTED)
else if (a == 0) else if (a == 0)
#else
else
#endif
{ {
*dp = (png_byte)((background->gray >> 8) & 0xff); *dp = (png_byte)((background->gray >> 8) & 0xff);
*(dp + 1) = (png_byte)(background->gray & 0xff); *(dp + 1) = (png_byte)(background->gray & 0xff);
} }
#if defined(PNG_READ_GAMMA_SUPPORTED)
else else
{ {
png_uint_16 g, v; png_uint_16 g, v;
@@ -2949,6 +3028,7 @@ png_do_background(png_row_infop row_info, png_bytep row,
*dp = (png_byte)((v >> 8) & 0xff); *dp = (png_byte)((v >> 8) & 0xff);
*(dp + 1) = (png_byte)(v & 0xff); *(dp + 1) = (png_byte)(v & 0xff);
} }
#endif
} }
} }
} }
@@ -3156,7 +3236,7 @@ png_do_background(png_row_infop row_info, png_bytep row,
* is 16, use gamma_16_table and gamma_shift. Build these with * is 16, use gamma_16_table and gamma_shift. Build these with
* build_gamma_table(). * build_gamma_table().
*/ */
void void /* PRIVATE */
png_do_gamma(png_row_infop row_info, png_bytep row, png_do_gamma(png_row_infop row_info, png_bytep row,
png_bytep gamma_table, png_uint_16pp gamma_16_table, png_bytep gamma_table, png_uint_16pp gamma_16_table,
int gamma_shift) int gamma_shift)
@@ -3338,7 +3418,7 @@ png_do_gamma(png_row_infop row_info, png_bytep row,
/* Expands a palette row to an RGB or RGBA row depending /* Expands a palette row to an RGB or RGBA row depending
* upon whether you supply trans and num_trans. * upon whether you supply trans and num_trans.
*/ */
void void /* PRIVATE */
png_do_expand_palette(png_row_infop row_info, png_bytep row, png_do_expand_palette(png_row_infop row_info, png_bytep row,
png_colorp palette, png_bytep trans, int num_trans) png_colorp palette, png_bytep trans, int num_trans)
{ {
@@ -3481,7 +3561,7 @@ 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 /* If the bit depth < 8, it is expanded to 8. Also, if the
* transparency value is supplied, an alpha channel is built. * transparency value is supplied, an alpha channel is built.
*/ */
void void /* PRIVATE */
png_do_expand(png_row_infop row_info, png_bytep row, png_do_expand(png_row_infop row_info, png_bytep row,
png_color_16p trans_value) png_color_16p trans_value)
{ {
@@ -3680,7 +3760,7 @@ png_do_expand(png_row_infop row_info, png_bytep row,
#endif #endif
#if defined(PNG_READ_DITHER_SUPPORTED) #if defined(PNG_READ_DITHER_SUPPORTED)
void void /* PRIVATE */
png_do_dither(png_row_infop row_info, png_bytep row, png_do_dither(png_row_infop row_info, png_bytep row,
png_bytep palette_lookup, png_bytep dither_lookup) png_bytep palette_lookup, png_bytep dither_lookup)
{ {
@@ -3782,7 +3862,7 @@ static int png_gamma_shift[] =
* the future. Note also how the gamma_16 tables are segmented so that * 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. * we don't need to allocate > 64K chunks for a full 16-bit table.
*/ */
void void /* PRIVATE */
png_build_gamma_table(png_structp png_ptr) png_build_gamma_table(png_structp png_ptr)
{ {
png_debug(1, "in png_build_gamma_table\n"); png_debug(1, "in png_build_gamma_table\n");
@@ -3995,3 +4075,63 @@ png_build_gamma_table(png_structp png_ptr)
/* To do: install integer version of png_build_gamma_table here */ /* To do: install integer version of png_build_gamma_table here */
#endif #endif
#if defined(PNG_MNG_FEATURES_SUPPORTED)
/* undoes intrapixel differencing */
void /* PRIVATE */
png_do_read_intrapixel(png_row_infop row_info, png_bytep row)
{
png_debug(1, "in png_do_read_intrapixel\n");
if (
#if defined(PNG_USELESS_TESTS_SUPPORTED)
row != NULL && row_info != NULL &&
#endif
(row_info->color_type & PNG_COLOR_MASK_COLOR))
{
int bytes_per_pixel;
png_uint_32 row_width = row_info->width;
if (row_info->bit_depth == 8)
{
png_bytep rp;
png_uint_32 i;
if (row_info->color_type == PNG_COLOR_TYPE_RGB)
bytes_per_pixel = 3;
else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
bytes_per_pixel = 4;
else
return;
for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
{
*(rp) = (png_byte)((256 + *rp + *(rp+1))&0xff);
*(rp+2) = (png_byte)((256 + *(rp+2) + *(rp+1))&0xff);
}
}
else if (row_info->bit_depth == 16)
{
png_bytep rp;
png_uint_32 i;
if (row_info->color_type == PNG_COLOR_TYPE_RGB)
bytes_per_pixel = 6;
else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
bytes_per_pixel = 8;
else
return;
for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
{
png_uint_32 s0=*(rp )<<8 | *(rp+1);
png_uint_32 s1=*(rp+2)<<8 | *(rp+3);
png_uint_32 s2=*(rp+4)<<8 | *(rp+5);
png_uint_32 red=(65536+s0+s1)&0xffff;
png_uint_32 blue=(65536+s2+s1)&0xffff;
*(rp ) = (png_byte)((red>>8)&0xff);
*(rp+1) = (png_byte)(red&0xff);
*(rp+4) = (png_byte)((blue>>8)&0xff);
*(rp+5) = (png_byte)(blue&0xff);
}
}
}
}
#endif /* PNG_MNG_FEATURES_SUPPORTED */

File diff suppressed because it is too large Load Diff

498
pngset.c
View File

@@ -1,11 +1,11 @@
/* pngset.c - storage of image information into info struct /* pngset.c - storage of image information into info struct
* *
* libpng 1.0.5k - December 27, 1999 * libpng 1.2.1 - December 12, 2001
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. * Copyright (c) 1998-2001 Glenn Randers-Pehrson
* Copyright (c) 1996, 1997 Andreas Dilger * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
* *
* The functions here are used during reads to store data from the file * 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, and during writes to store application data
@@ -17,7 +17,7 @@
#include "png.h" #include "png.h"
#if defined(PNG_bKGD_SUPPORTED) #if defined(PNG_bKGD_SUPPORTED)
void void PNGAPI
png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background) png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background)
{ {
png_debug1(1, "in %s storage function\n", "bKGD"); png_debug1(1, "in %s storage function\n", "bKGD");
@@ -31,7 +31,7 @@ png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background)
#if defined(PNG_cHRM_SUPPORTED) #if defined(PNG_cHRM_SUPPORTED)
#ifdef PNG_FLOATING_POINT_SUPPORTED #ifdef PNG_FLOATING_POINT_SUPPORTED
void void PNGAPI
png_set_cHRM(png_structp png_ptr, png_infop info_ptr, png_set_cHRM(png_structp png_ptr, png_infop info_ptr,
double white_x, double white_y, double red_x, double red_y, double white_x, double white_y, double red_x, double red_y,
double green_x, double green_y, double blue_x, double blue_y) double green_x, double green_y, double blue_x, double blue_y)
@@ -62,7 +62,7 @@ png_set_cHRM(png_structp png_ptr, png_infop info_ptr,
} }
#endif #endif
#ifdef PNG_FIXED_POINT_SUPPORTED #ifdef PNG_FIXED_POINT_SUPPORTED
void void PNGAPI
png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr, png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x, png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x,
png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y, png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y,
@@ -81,14 +81,14 @@ png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
info_ptr->int_x_blue = blue_x; info_ptr->int_x_blue = blue_x;
info_ptr->int_y_blue = blue_y; info_ptr->int_y_blue = blue_y;
#ifdef PNG_FLOATING_POINT_SUPPORTED #ifdef PNG_FLOATING_POINT_SUPPORTED
info_ptr->x_white = (float)white_x/100000.; info_ptr->x_white = (float)(white_x/100000.);
info_ptr->y_white = (float)white_y/100000.; info_ptr->y_white = (float)(white_y/100000.);
info_ptr->x_red = (float)red_x/100000.; info_ptr->x_red = (float)(red_x/100000.);
info_ptr->y_red = (float)red_y/100000.; info_ptr->y_red = (float)(red_y/100000.);
info_ptr->x_green = (float)green_x/100000.; info_ptr->x_green = (float)(green_x/100000.);
info_ptr->y_green = (float)green_y/100000.; info_ptr->y_green = (float)(green_y/100000.);
info_ptr->x_blue = (float)blue_x/100000.; info_ptr->x_blue = (float)(blue_x/100000.);
info_ptr->y_blue = (float)blue_y/100000.; info_ptr->y_blue = (float)(blue_y/100000.);
#endif #endif
info_ptr->valid |= PNG_INFO_cHRM; info_ptr->valid |= PNG_INFO_cHRM;
} }
@@ -97,7 +97,7 @@ png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
#if defined(PNG_gAMA_SUPPORTED) #if defined(PNG_gAMA_SUPPORTED)
#ifdef PNG_FLOATING_POINT_SUPPORTED #ifdef PNG_FLOATING_POINT_SUPPORTED
void void PNGAPI
png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma) png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma)
{ {
png_debug1(1, "in %s storage function\n", "gAMA"); png_debug1(1, "in %s storage function\n", "gAMA");
@@ -109,10 +109,11 @@ png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma)
info_ptr->int_gamma = (int)(file_gamma*100000.+.5); info_ptr->int_gamma = (int)(file_gamma*100000.+.5);
#endif #endif
info_ptr->valid |= PNG_INFO_gAMA; info_ptr->valid |= PNG_INFO_gAMA;
if(file_gamma == 0.0)
png_warning(png_ptr, "Setting gamma=0");
} }
#endif #endif
#endif void PNGAPI
void
png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point
int_gamma) int_gamma)
{ {
@@ -121,28 +122,54 @@ png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point
return; return;
#ifdef PNG_FLOATING_POINT_SUPPORTED #ifdef PNG_FLOATING_POINT_SUPPORTED
info_ptr->gamma = (float)int_gamma/100000.; info_ptr->gamma = (float)(int_gamma/100000.);
#endif #endif
#ifdef PNG_FIXED_POINT_SUPPORTED
info_ptr->int_gamma = int_gamma; info_ptr->int_gamma = int_gamma;
#endif
info_ptr->valid |= PNG_INFO_gAMA; info_ptr->valid |= PNG_INFO_gAMA;
if(int_gamma == 0)
png_warning(png_ptr, "Setting gamma=0");
} }
#endif
#if defined(PNG_hIST_SUPPORTED) #if defined(PNG_hIST_SUPPORTED)
void void PNGAPI
png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist) png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist)
{ {
int i;
png_debug1(1, "in %s storage function\n", "hIST"); png_debug1(1, "in %s storage function\n", "hIST");
if (png_ptr == NULL || info_ptr == NULL) if (png_ptr == NULL || info_ptr == NULL)
return; return;
if (info_ptr->num_palette == 0)
{
png_warning(png_ptr,
"Palette size 0, hIST allocation skipped.");
return;
}
info_ptr->hist = png_malloc(png_ptr, sizeof(png_uint_16) * #ifdef PNG_FREE_ME_SUPPORTED
info_ptr->num_palette); png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0);
png_memcpy(info_ptr->hist, hist, sizeof(png_uint_16) * info_ptr->num_palette); #endif
/* Changed from info->num_palette to 256 in version 1.2.1 */
png_ptr->hist = (png_uint_16p)png_malloc(png_ptr,
(png_uint_32)(256 * sizeof (png_uint_16)));
for (i = 0; i < info_ptr->num_palette; i++)
png_ptr->hist[i] = hist[i];
info_ptr->hist = png_ptr->hist;
info_ptr->valid |= PNG_INFO_hIST; info_ptr->valid |= PNG_INFO_hIST;
#ifdef PNG_FREE_ME_SUPPORTED
info_ptr->free_me |= PNG_FREE_HIST;
#else
png_ptr->flags |= PNG_FLAG_FREE_HIST;
#endif
} }
#endif #endif
void void PNGAPI
png_set_IHDR(png_structp png_ptr, png_infop info_ptr, png_set_IHDR(png_structp png_ptr, png_infop info_ptr,
png_uint_32 width, png_uint_32 height, int bit_depth, png_uint_32 width, png_uint_32 height, int bit_depth,
int color_type, int interlace_type, int compression_type, int color_type, int interlace_type, int compression_type,
@@ -153,6 +180,61 @@ png_set_IHDR(png_structp png_ptr, png_infop info_ptr,
if (png_ptr == NULL || info_ptr == NULL) if (png_ptr == NULL || info_ptr == NULL)
return; return;
/* check for width and height valid values */
if (width == 0 || height == 0)
png_error(png_ptr, "Image width or height is zero in IHDR");
if (width > PNG_MAX_UINT || height > PNG_MAX_UINT)
png_error(png_ptr, "Invalid image size in IHDR");
/* check other values */
if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 &&
bit_depth != 8 && bit_depth != 16)
png_error(png_ptr, "Invalid bit depth in IHDR");
if (color_type < 0 || color_type == 1 ||
color_type == 5 || color_type > 6)
png_error(png_ptr, "Invalid color type in IHDR");
if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) ||
((color_type == PNG_COLOR_TYPE_RGB ||
color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
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_LAST)
png_error(png_ptr, "Unknown interlace method in IHDR");
if (compression_type != PNG_COMPRESSION_TYPE_BASE)
png_error(png_ptr, "Unknown compression method in IHDR");
#if defined(PNG_MNG_FEATURES_SUPPORTED)
/* Accept filter_method 64 (intrapixel differencing) only if
* 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and
* 2. Libpng did not read a PNG signature (this filter_method is only
* used in PNG datastreams that are embedded in MNG datastreams) and
* 3. The application called png_permit_mng_features with a mask that
* included PNG_FLAG_MNG_FILTER_64 and
* 4. The filter_method is 64 and
* 5. The color_type is RGB or RGBA
*/
if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&png_ptr->mng_features_permitted)
png_warning(png_ptr,"MNG features are not allowed in a PNG datastream\n");
if(filter_type != PNG_FILTER_TYPE_BASE)
{
if(!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
(filter_type == PNG_INTRAPIXEL_DIFFERENCING) &&
((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
(color_type == PNG_COLOR_TYPE_RGB ||
color_type == PNG_COLOR_TYPE_RGB_ALPHA)))
png_error(png_ptr, "Unknown filter method in IHDR");
if(png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)
png_warning(png_ptr, "Invalid filter method in IHDR");
}
#else
if(filter_type != PNG_FILTER_TYPE_BASE)
png_error(png_ptr, "Unknown filter method in IHDR");
#endif
info_ptr->width = width; info_ptr->width = width;
info_ptr->height = height; info_ptr->height = height;
info_ptr->bit_depth = (png_byte)bit_depth; info_ptr->bit_depth = (png_byte)bit_depth;
@@ -183,7 +265,7 @@ png_set_IHDR(png_structp png_ptr, png_infop info_ptr,
} }
#if defined(PNG_oFFs_SUPPORTED) #if defined(PNG_oFFs_SUPPORTED)
void void PNGAPI
png_set_oFFs(png_structp png_ptr, png_infop info_ptr, png_set_oFFs(png_structp png_ptr, png_infop info_ptr,
png_int_32 offset_x, png_int_32 offset_y, int unit_type) png_int_32 offset_x, png_int_32 offset_y, int unit_type)
{ {
@@ -199,7 +281,7 @@ png_set_oFFs(png_structp png_ptr, png_infop info_ptr,
#endif #endif
#if defined(PNG_pCAL_SUPPORTED) #if defined(PNG_pCAL_SUPPORTED)
void void PNGAPI
png_set_pCAL(png_structp png_ptr, png_infop info_ptr, png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams, png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams,
png_charp units, png_charpp params) png_charp units, png_charpp params)
@@ -212,7 +294,7 @@ png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
return; return;
length = png_strlen(purpose) + 1; length = png_strlen(purpose) + 1;
png_debug1(3, "allocating purpose for info (%d bytes)\n", length); png_debug1(3, "allocating purpose for info (%lu bytes)\n", length);
info_ptr->pcal_purpose = (png_charp)png_malloc(png_ptr, length); info_ptr->pcal_purpose = (png_charp)png_malloc(png_ptr, length);
png_memcpy(info_ptr->pcal_purpose, purpose, (png_size_t)length); png_memcpy(info_ptr->pcal_purpose, purpose, (png_size_t)length);
@@ -223,29 +305,33 @@ png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
info_ptr->pcal_nparams = (png_byte)nparams; info_ptr->pcal_nparams = (png_byte)nparams;
length = png_strlen(units) + 1; length = png_strlen(units) + 1;
png_debug1(3, "allocating units for info (%d bytes)\n", length); png_debug1(3, "allocating units for info (%lu bytes)\n", length);
info_ptr->pcal_units = (png_charp)png_malloc(png_ptr, length); info_ptr->pcal_units = (png_charp)png_malloc(png_ptr, length);
png_memcpy(info_ptr->pcal_units, units, (png_size_t)length); png_memcpy(info_ptr->pcal_units, units, (png_size_t)length);
info_ptr->pcal_params = (png_charpp)png_malloc(png_ptr, info_ptr->pcal_params = (png_charpp)png_malloc(png_ptr,
(png_uint_32)((nparams + 1) * sizeof(png_charp))); (png_uint_32)((nparams + 1) * sizeof(png_charp)));
info_ptr->pcal_params[nparams] = NULL; info_ptr->pcal_params[nparams] = NULL;
for (i = 0; i < nparams; i++) for (i = 0; i < nparams; i++)
{ {
length = png_strlen(params[i]) + 1; length = png_strlen(params[i]) + 1;
png_debug2(3, "allocating parameter %d for info (%d bytes)\n", i, length); png_debug2(3, "allocating parameter %d for info (%lu bytes)\n", i, length);
info_ptr->pcal_params[i] = (png_charp)png_malloc(png_ptr, length); info_ptr->pcal_params[i] = (png_charp)png_malloc(png_ptr, length);
png_memcpy(info_ptr->pcal_params[i], params[i], (png_size_t)length); png_memcpy(info_ptr->pcal_params[i], params[i], (png_size_t)length);
} }
info_ptr->valid |= PNG_INFO_pCAL; info_ptr->valid |= PNG_INFO_pCAL;
#ifdef PNG_FREE_ME_SUPPORTED
info_ptr->free_me |= PNG_FREE_PCAL;
#endif
} }
#endif #endif
#if defined(PNG_READ_sCAL_SUPPORTED) || defined(PNG_WRITE_sCAL_SUPPORTED) #if defined(PNG_READ_sCAL_SUPPORTED) || defined(PNG_WRITE_sCAL_SUPPORTED)
#ifdef PNG_FLOATING_POINT_SUPPORTED #ifdef PNG_FLOATING_POINT_SUPPORTED
void void PNGAPI
png_set_sCAL(png_structp png_ptr, png_infop info_ptr, png_set_sCAL(png_structp png_ptr, png_infop info_ptr,
int unit, double width, double height) int unit, double width, double height)
{ {
@@ -261,7 +347,7 @@ png_set_sCAL(png_structp png_ptr, png_infop info_ptr,
} }
#else #else
#ifdef PNG_FIXED_POINT_SUPPORTED #ifdef PNG_FIXED_POINT_SUPPORTED
void void PNGAPI
png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr, png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr,
int unit, png_charp swidth, png_charp sheight) int unit, png_charp swidth, png_charp sheight)
{ {
@@ -280,17 +366,20 @@ png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr,
length = png_strlen(sheight) + 1; length = png_strlen(sheight) + 1;
png_debug1(3, "allocating unit for info (%d bytes)\n", length); png_debug1(3, "allocating unit for info (%d bytes)\n", length);
info_ptr->scal_s_width = (png_charp)png_malloc(png_ptr, length); info_ptr->scal_s_height = (png_charp)png_malloc(png_ptr, length);
png_memcpy(info_ptr->scal_s_height, sheight, (png_size_t)length); png_memcpy(info_ptr->scal_s_height, sheight, (png_size_t)length);
info_ptr->valid |= PNG_INFO_sCAL; info_ptr->valid |= PNG_INFO_sCAL;
#ifdef PNG_FREE_ME_SUPPORTED
info_ptr->free_me |= PNG_FREE_SCAL;
#endif
} }
#endif #endif
#endif #endif
#endif #endif
#if defined(PNG_pHYs_SUPPORTED) #if defined(PNG_pHYs_SUPPORTED)
void void PNGAPI
png_set_pHYs(png_structp png_ptr, png_infop info_ptr, png_set_pHYs(png_structp png_ptr, png_infop info_ptr,
png_uint_32 res_x, png_uint_32 res_y, int unit_type) png_uint_32 res_x, png_uint_32 res_y, int unit_type)
{ {
@@ -305,21 +394,42 @@ png_set_pHYs(png_structp png_ptr, png_infop info_ptr,
} }
#endif #endif
void void PNGAPI
png_set_PLTE(png_structp png_ptr, png_infop info_ptr, png_set_PLTE(png_structp png_ptr, png_infop info_ptr,
png_colorp palette, int num_palette) png_colorp palette, int num_palette)
{ {
png_debug1(1, "in %s storage function\n", "PLTE"); png_debug1(1, "in %s storage function\n", "PLTE");
if (png_ptr == NULL || info_ptr == NULL) if (png_ptr == NULL || info_ptr == NULL)
return; return;
info_ptr->palette = palette; /*
info_ptr->num_palette = (png_uint_16)num_palette; * It may not actually be necessary to set png_ptr->palette here;
* we do it for backward compatibility with the way the png_handle_tRNS
* function used to do the allocation.
*/
#ifdef PNG_FREE_ME_SUPPORTED
png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0);
#endif
/* Changed in libpng-1.2.1 to allocate 256 instead of num_palette entries,
in case of an invalid PNG file that has too-large sample values. */
png_ptr->palette = (png_colorp)png_zalloc(png_ptr, (uInt)256,
sizeof (png_color));
png_memcpy(png_ptr->palette, palette, num_palette * sizeof (png_color));
info_ptr->palette = png_ptr->palette;
info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;
#ifdef PNG_FREE_ME_SUPPORTED
info_ptr->free_me |= PNG_FREE_PLTE;
#else
png_ptr->flags |= PNG_FLAG_FREE_PLTE;
#endif
info_ptr->valid |= PNG_INFO_PLTE; info_ptr->valid |= PNG_INFO_PLTE;
} }
#if defined(PNG_sBIT_SUPPORTED) #if defined(PNG_sBIT_SUPPORTED)
void void PNGAPI
png_set_sBIT(png_structp png_ptr, png_infop info_ptr, png_set_sBIT(png_structp png_ptr, png_infop info_ptr,
png_color_8p sig_bit) png_color_8p sig_bit)
{ {
@@ -333,7 +443,7 @@ png_set_sBIT(png_structp png_ptr, png_infop info_ptr,
#endif #endif
#if defined(PNG_sRGB_SUPPORTED) #if defined(PNG_sRGB_SUPPORTED)
void void PNGAPI
png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int intent) png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int intent)
{ {
png_debug1(1, "in %s storage function\n", "sRGB"); png_debug1(1, "in %s storage function\n", "sRGB");
@@ -344,7 +454,7 @@ png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int intent)
info_ptr->valid |= PNG_INFO_sRGB; info_ptr->valid |= PNG_INFO_sRGB;
} }
void void PNGAPI
png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr, png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
int intent) int intent)
{ {
@@ -416,29 +526,40 @@ png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
#if defined(PNG_iCCP_SUPPORTED) #if defined(PNG_iCCP_SUPPORTED)
void void PNGAPI
png_set_iCCP(png_structp png_ptr, png_infop info_ptr, png_set_iCCP(png_structp png_ptr, png_infop info_ptr,
png_charp name, int compression_type, png_charp name, int compression_type,
png_charp profile, png_uint_32 proflen) png_charp profile, png_uint_32 proflen)
{ {
png_charp new_iccp_name;
png_charp new_iccp_profile;
png_debug1(1, "in %s storage function\n", "iCCP"); png_debug1(1, "in %s storage function\n", "iCCP");
if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL) if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL)
return; return;
info_ptr->iccp_name = png_malloc(png_ptr, png_strlen(name)+1); new_iccp_name = (png_charp)png_malloc(png_ptr, png_strlen(name)+1);
strcpy(info_ptr->iccp_name, name); png_strcpy(new_iccp_name, name);
info_ptr->iccp_profile = png_malloc(png_ptr, proflen); new_iccp_profile = (png_charp)png_malloc(png_ptr, proflen);
png_memcpy(info_ptr->iccp_profile, profile, (png_size_t)proflen); png_memcpy(new_iccp_profile, profile, (png_size_t)proflen);
png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, 0);
info_ptr->iccp_proflen = proflen; info_ptr->iccp_proflen = proflen;
info_ptr->iccp_name = new_iccp_name;
info_ptr->iccp_profile = new_iccp_profile;
/* Compression is always zero but is here so the API and info structure /* Compression is always zero but is here so the API and info structure
* does not have to change * if we introduce multiple compression types */ * does not have to change if we introduce multiple compression types */
info_ptr->iccp_compression = (png_byte)compression_type; info_ptr->iccp_compression = (png_byte)compression_type;
#ifdef PNG_FREE_ME_SUPPORTED
info_ptr->free_me |= PNG_FREE_ICCP;
#endif
info_ptr->valid |= PNG_INFO_iCCP; info_ptr->valid |= PNG_INFO_iCCP;
} }
#endif #endif
#if defined(PNG_TEXT_SUPPORTED) #if defined(PNG_TEXT_SUPPORTED)
void void PNGAPI
png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr, png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
int num_text) int num_text)
{ {
@@ -475,39 +596,57 @@ png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
info_ptr->num_text = 0; info_ptr->num_text = 0;
info_ptr->text = (png_textp)png_malloc(png_ptr, info_ptr->text = (png_textp)png_malloc(png_ptr,
(png_uint_32)(info_ptr->max_text * sizeof (png_text))); (png_uint_32)(info_ptr->max_text * sizeof (png_text)));
#ifdef PNG_FREE_ME_SUPPORTED
info_ptr->free_me |= PNG_FREE_TEXT;
#endif
} }
png_debug1(3, "allocated %d entries for info_ptr->text\n", png_debug1(3, "allocated %d entries for info_ptr->text\n",
info_ptr->max_text); info_ptr->max_text);
} }
for (i = 0; i < num_text; i++) for (i = 0; i < num_text; i++)
{ {
png_size_t text_length,key_len,lang_len,lang_key_len; png_size_t text_length,key_len;
png_size_t lang_len,lang_key_len;
png_textp textp = &(info_ptr->text[info_ptr->num_text]); png_textp textp = &(info_ptr->text[info_ptr->num_text]);
if (text_ptr[i].key == (png_charp)NULL) if (text_ptr[i].key == NULL)
continue; continue;
key_len = png_strlen(text_ptr[i].key); key_len = png_strlen(text_ptr[i].key);
if(text_ptr[i].compression > 0) if(text_ptr[i].compression <= 0)
{
/* set iTXt data */
lang_len = png_strlen(text_ptr[i].lang);
lang_key_len = png_strlen(text_ptr[i].lang_key);
}
else
{ {
lang_len = 0; lang_len = 0;
lang_key_len = 0; lang_key_len = 0;
} }
else
#ifdef PNG_iTXt_SUPPORTED
{
/* set iTXt data */
if (text_ptr[i].key != NULL)
lang_len = png_strlen(text_ptr[i].lang);
else
lang_len = 0;
if (text_ptr[i].lang_key != NULL)
lang_key_len = png_strlen(text_ptr[i].lang_key);
else
lang_key_len = 0;
}
#else
{
png_warning(png_ptr, "iTXt chunk not supported.");
continue;
}
#endif
if (text_ptr[i].text[0] == '\0') if (text_ptr[i].text == NULL || text_ptr[i].text[0] == '\0')
{ {
text_length = 0; text_length = 0;
#ifdef PNG_iTXt_SUPPORTED
if(text_ptr[i].compression > 0) if(text_ptr[i].compression > 0)
textp->compression = PNG_ITXT_COMPRESSION_NONE; textp->compression = PNG_ITXT_COMPRESSION_NONE;
else else
#endif
textp->compression = PNG_TEXT_COMPRESSION_NONE; textp->compression = PNG_TEXT_COMPRESSION_NONE;
} }
else else
@@ -517,15 +656,15 @@ png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
} }
textp->key = (png_charp)png_malloc(png_ptr, textp->key = (png_charp)png_malloc(png_ptr,
(png_uint_32)(key_len + lang_len + lang_key_len + text_length + 4)); (png_uint_32)(key_len + text_length + lang_len + lang_key_len + 4));
/* Caution: the calling program, not libpng, is responsible for png_debug2(2, "Allocated %lu bytes at %x in png_set_text\n",
freeing this, if libpng wasn't the caller. */ (png_uint_32)(key_len + lang_len + lang_key_len + text_length + 4),
png_debug2(2, "Allocated %d bytes at %x in png_set_text\n", (int)textp->key);
key_len + lang_len + lang_key_len + text_length + 4, textp->key);
png_memcpy(textp->key, text_ptr[i].key, png_memcpy(textp->key, text_ptr[i].key,
(png_size_t)(key_len)); (png_size_t)(key_len));
*(textp->key+key_len) = '\0'; *(textp->key+key_len) = '\0';
#ifdef PNG_iTXt_SUPPORTED
if (text_ptr[i].compression > 0) if (text_ptr[i].compression > 0)
{ {
textp->lang=textp->key + key_len + 1; textp->lang=textp->key + key_len + 1;
@@ -537,32 +676,33 @@ png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
textp->text=textp->lang_key + lang_key_len + 1; textp->text=textp->lang_key + lang_key_len + 1;
} }
else else
#endif
{ {
#ifdef PNG_iTXt_SUPPORTED
textp->lang=NULL; textp->lang=NULL;
textp->lang_key=NULL; textp->lang_key=NULL;
#endif
textp->text=textp->key + key_len + 1; textp->text=textp->key + key_len + 1;
} }
if(text_length) if(text_length)
{
png_memcpy(textp->text, text_ptr[i].text, png_memcpy(textp->text, text_ptr[i].text,
(png_size_t)(text_length)); (png_size_t)(text_length));
*(textp->text+text_length) = '\0'; *(textp->text+text_length) = '\0';
}
else
textp->text--;
#ifdef PNG_iTXt_SUPPORTED
if(textp->compression > 0) if(textp->compression > 0)
{ {
textp->text_length = 0; textp->text_length = 0;
textp->itxt_length = text_length; textp->itxt_length = text_length;
} }
else else
#endif
{ {
textp->text_length = text_length; textp->text_length = text_length;
#ifdef PNG_iTXt_SUPPORTED
textp->itxt_length = 0; textp->itxt_length = 0;
#endif
} }
info_ptr->text[info_ptr->num_text]= *textp; info_ptr->text[info_ptr->num_text]= *textp;
info_ptr->num_text++; info_ptr->num_text++;
png_debug1(3, "transferred text chunk %d\n", info_ptr->num_text); png_debug1(3, "transferred text chunk %d\n", info_ptr->num_text);
@@ -571,7 +711,7 @@ png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
#endif #endif
#if defined(PNG_tIME_SUPPORTED) #if defined(PNG_tIME_SUPPORTED)
void void PNGAPI
png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time) png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time)
{ {
png_debug1(1, "in %s storage function\n", "tIME"); png_debug1(1, "in %s storage function\n", "tIME");
@@ -585,7 +725,7 @@ png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time)
#endif #endif
#if defined(PNG_tRNS_SUPPORTED) #if defined(PNG_tRNS_SUPPORTED)
void void PNGAPI
png_set_tRNS(png_structp png_ptr, png_infop info_ptr, png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
png_bytep trans, int num_trans, png_color_16p trans_values) png_bytep trans, int num_trans, png_color_16p trans_values)
{ {
@@ -595,8 +735,23 @@ png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
if (trans != NULL) if (trans != NULL)
{ {
info_ptr->trans = png_malloc(png_ptr, num_trans); /*
png_memcpy(info_ptr->trans, trans, num_trans); * It may not actually be necessary to set png_ptr->trans here;
* we do it for backward compatibility with the way the png_handle_tRNS
* function used to do the allocation.
*/
#ifdef PNG_FREE_ME_SUPPORTED
png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
#endif
/* Changed from num_trans to 256 in version 1.2.1 */
png_ptr->trans = info_ptr->trans = (png_bytep)png_malloc(png_ptr,
(png_uint_32)256);
png_memcpy(info_ptr->trans, trans, (png_size_t)num_trans);
#ifdef PNG_FREE_ME_SUPPORTED
info_ptr->free_me |= PNG_FREE_TRNS;
#else
png_ptr->flags |= PNG_FLAG_FREE_TRNS;
#endif
} }
if (trans_values != NULL) if (trans_values != NULL)
@@ -612,44 +767,48 @@ png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
#endif #endif
#if defined(PNG_sPLT_SUPPORTED) #if defined(PNG_sPLT_SUPPORTED)
void void PNGAPI
png_set_spalettes(png_structp png_ptr, png_set_sPLT(png_structp png_ptr,
png_infop info_ptr, png_spalette_p entries, int nentries) png_infop info_ptr, png_sPLT_tp entries, int nentries)
{ {
png_spalette_p np; png_sPLT_tp np;
int i; int i;
np = (png_spalette_p)png_malloc(png_ptr, np = (png_sPLT_tp)png_malloc(png_ptr,
(info_ptr->splt_palettes_num + nentries) * sizeof(png_spalette)); (info_ptr->splt_palettes_num + nentries) * sizeof(png_sPLT_t));
png_memcpy(np, info_ptr->splt_palettes, png_memcpy(np, info_ptr->splt_palettes,
info_ptr->splt_palettes_num * sizeof(png_spalette)); info_ptr->splt_palettes_num * sizeof(png_sPLT_t));
png_free(png_ptr, info_ptr->splt_palettes); png_free(png_ptr, info_ptr->splt_palettes);
info_ptr->splt_palettes=NULL;
for (i = 0; i < nentries; i++) for (i = 0; i < nentries; i++)
{ {
png_spalette_p to = np + info_ptr->splt_palettes_num + i; png_sPLT_tp to = np + info_ptr->splt_palettes_num + i;
png_spalette_p from = entries + i; png_sPLT_tp from = entries + i;
to->name = (png_charp)png_malloc(png_ptr, to->name = (png_charp)png_malloc(png_ptr,
png_strlen(from->name) + 1); png_strlen(from->name) + 1);
png_strcpy(to->name, from->name); png_strcpy(to->name, from->name);
to->entries = (png_spalette_entryp)png_malloc(png_ptr, to->entries = (png_sPLT_entryp)png_malloc(png_ptr,
from->nentries * sizeof(png_spalette)); from->nentries * sizeof(png_sPLT_t));
png_memcpy(to->entries, from->entries, png_memcpy(to->entries, from->entries,
from->nentries * sizeof(png_spalette)); from->nentries * sizeof(png_sPLT_t));
to->nentries = from->nentries; to->nentries = from->nentries;
to->depth = from->depth; to->depth = from->depth;
} }
info_ptr->splt_palettes = np; info_ptr->splt_palettes = np;
info_ptr->splt_palettes_num += nentries; info_ptr->splt_palettes_num += nentries;
info_ptr->valid |= PNG_INFO_sPLT; info_ptr->valid |= PNG_INFO_sPLT;
#ifdef PNG_FREE_ME_SUPPORTED
info_ptr->free_me |= PNG_FREE_SPLT;
#endif
} }
#endif /* PNG_sPLT_SUPPORTED */ #endif /* PNG_sPLT_SUPPORTED */
#if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED) #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
void void PNGAPI
png_set_unknown_chunks(png_structp png_ptr, png_set_unknown_chunks(png_structp png_ptr,
png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns) png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns)
{ {
@@ -666,6 +825,7 @@ png_set_unknown_chunks(png_structp png_ptr,
png_memcpy(np, info_ptr->unknown_chunks, png_memcpy(np, info_ptr->unknown_chunks,
info_ptr->unknown_chunks_num * sizeof(png_unknown_chunk)); info_ptr->unknown_chunks_num * sizeof(png_unknown_chunk));
png_free(png_ptr, info_ptr->unknown_chunks); png_free(png_ptr, info_ptr->unknown_chunks);
info_ptr->unknown_chunks=NULL;
for (i = 0; i < num_unknowns; i++) for (i = 0; i < num_unknowns; i++)
{ {
@@ -683,22 +843,51 @@ png_set_unknown_chunks(png_structp png_ptr,
info_ptr->unknown_chunks = np; info_ptr->unknown_chunks = np;
info_ptr->unknown_chunks_num += num_unknowns; info_ptr->unknown_chunks_num += num_unknowns;
#ifdef PNG_FREE_ME_SUPPORTED
info_ptr->free_me |= PNG_FREE_UNKN;
#endif
}
void PNGAPI
png_set_unknown_chunk_location(png_structp png_ptr, png_infop info_ptr,
int chunk, int location)
{
if(png_ptr != NULL && info_ptr != NULL && chunk >= 0 && chunk <
(int)info_ptr->unknown_chunks_num)
info_ptr->unknown_chunks[chunk].location = (png_byte)location;
} }
#endif #endif
#if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) #if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
void defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
void PNGAPI
png_permit_empty_plte (png_structp png_ptr, int empty_plte_permitted) png_permit_empty_plte (png_structp png_ptr, int empty_plte_permitted)
{ {
png_debug1(1, "in png_permit_empty_plte\n", ""); /* This function is deprecated in favor of png_permit_mng_features()
and will be removed from libpng-2.0.0 */
png_debug(1, "in png_permit_empty_plte, DEPRECATED.\n");
if (png_ptr == NULL) if (png_ptr == NULL)
return; return;
png_ptr->empty_plte_permitted=(png_byte)empty_plte_permitted; png_ptr->mng_features_permitted = (png_byte)
((png_ptr->mng_features_permitted & (~(PNG_FLAG_MNG_EMPTY_PLTE))) |
((empty_plte_permitted & PNG_FLAG_MNG_EMPTY_PLTE)));
}
#endif
#if defined(PNG_MNG_FEATURES_SUPPORTED)
png_uint_32 PNGAPI
png_permit_mng_features (png_structp png_ptr, png_uint_32 mng_features)
{
png_debug(1, "in png_permit_mng_features\n");
if (png_ptr == NULL)
return (png_uint_32)0;
png_ptr->mng_features_permitted =
(png_byte)(mng_features & PNG_ALL_MNG_FEATURES);
return (png_uint_32)png_ptr->mng_features_permitted;
} }
#endif #endif
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
void void PNGAPI
png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep
chunk_list, int num_chunks) chunk_list, int num_chunks)
{ {
@@ -720,16 +909,125 @@ png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep
if (chunk_list == NULL) if (chunk_list == NULL)
return; return;
old_num_chunks=png_ptr->num_chunk_list; old_num_chunks=png_ptr->num_chunk_list;
new_list=png_malloc(png_ptr,5*(num_chunks+old_num_chunks)); new_list=(png_bytep)png_malloc(png_ptr,
if(png_ptr->chunk_list != (png_bytep)NULL) (png_uint_32)(5*(num_chunks+old_num_chunks)));
if(png_ptr->chunk_list != NULL)
{ {
png_memcpy(new_list, png_ptr->chunk_list, 5*old_num_chunks); png_memcpy(new_list, png_ptr->chunk_list,
png_free_chunk_list(png_ptr); (png_size_t)(5*old_num_chunks));
png_free(png_ptr, png_ptr->chunk_list);
png_ptr->chunk_list=NULL;
} }
png_memcpy(new_list+5*old_num_chunks, chunk_list, 5*num_chunks); png_memcpy(new_list+5*old_num_chunks, chunk_list,
(png_size_t)(5*num_chunks));
for (p=new_list+5*old_num_chunks+4, i=0; i<num_chunks; i++, p+=5) for (p=new_list+5*old_num_chunks+4, i=0; i<num_chunks; i++, p+=5)
*p=(png_byte)keep; *p=(png_byte)keep;
png_ptr->num_chunk_list=old_num_chunks+num_chunks; png_ptr->num_chunk_list=old_num_chunks+num_chunks;
png_ptr->chunk_list=new_list; png_ptr->chunk_list=new_list;
#ifdef PNG_FREE_ME_SUPPORTED
png_ptr->free_me |= PNG_FREE_LIST;
#endif
} }
#endif #endif
#if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
void PNGAPI
png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp user_chunk_ptr,
png_user_chunk_ptr read_user_chunk_fn)
{
png_debug(1, "in png_set_read_user_chunk_fn\n");
png_ptr->read_user_chunk_fn = read_user_chunk_fn;
png_ptr->user_chunk_ptr = user_chunk_ptr;
}
#endif
#if defined(PNG_INFO_IMAGE_SUPPORTED)
void PNGAPI
png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers)
{
png_debug1(1, "in %s storage function\n", "rows");
if (png_ptr == NULL || info_ptr == NULL)
return;
if(info_ptr->row_pointers && (info_ptr->row_pointers != row_pointers))
png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
info_ptr->row_pointers = row_pointers;
if(row_pointers)
info_ptr->valid |= PNG_INFO_IDAT;
}
#endif
void PNGAPI
png_set_compression_buffer_size(png_structp png_ptr, png_uint_32 size)
{
if(png_ptr->zbuf)
png_free(png_ptr, png_ptr->zbuf);
png_ptr->zbuf_size = (png_size_t)size;
png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, size);
png_ptr->zstream.next_out = png_ptr->zbuf;
png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
}
void PNGAPI
png_set_invalid(png_structp png_ptr, png_infop info_ptr, int mask)
{
if (png_ptr && info_ptr)
info_ptr->valid &= ~(mask);
}
#ifdef PNG_ASSEMBLER_CODE_SUPPORTED
/* this function was added to libpng 1.2.0 and should always exist by default */
void PNGAPI
png_set_asm_flags (png_structp png_ptr, png_uint_32 asm_flags)
{
png_uint_32 settable_asm_flags;
png_uint_32 settable_mmx_flags;
settable_mmx_flags =
#ifdef PNG_HAVE_ASSEMBLER_COMBINE_ROW
PNG_ASM_FLAG_MMX_READ_COMBINE_ROW |
#endif
#ifdef PNG_HAVE_ASSEMBLER_READ_INTERLACE
PNG_ASM_FLAG_MMX_READ_INTERLACE |
#endif
#ifdef PNG_HAVE_ASSEMBLER_READ_FILTER_ROW
PNG_ASM_FLAG_MMX_READ_FILTER_SUB |
PNG_ASM_FLAG_MMX_READ_FILTER_UP |
PNG_ASM_FLAG_MMX_READ_FILTER_AVG |
PNG_ASM_FLAG_MMX_READ_FILTER_PAETH |
#endif
0;
/* could be some non-MMX ones in the future, but not currently: */
settable_asm_flags = settable_mmx_flags;
if (!(png_ptr->asm_flags & PNG_ASM_FLAG_MMX_SUPPORT_COMPILED) ||
!(png_ptr->asm_flags & PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU))
{
/* clear all MMX flags if MMX isn't supported */
settable_asm_flags &= ~settable_mmx_flags;
png_ptr->asm_flags &= ~settable_mmx_flags;
}
/* we're replacing the settable bits with those passed in by the user,
* so first zero them out of the master copy, then logical-OR in the
* allowed subset that was requested */
png_ptr->asm_flags &= ~settable_asm_flags; /* zero them */
png_ptr->asm_flags |= (asm_flags & settable_asm_flags); /* set them */
}
#endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
#ifdef PNG_ASSEMBLER_CODE_SUPPORTED
/* this function was added to libpng 1.2.0 */
void PNGAPI
png_set_mmx_thresholds (png_structp png_ptr,
png_byte mmx_bitdepth_threshold,
png_uint_32 mmx_rowbytes_threshold)
{
png_ptr->mmx_bitdepth_threshold = mmx_bitdepth_threshold;
png_ptr->mmx_rowbytes_threshold = mmx_rowbytes_threshold;
}
#endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */

View File

@@ -1,11 +1,11 @@
/* pngtrans.c - transforms the data in a row (used by both readers and writers) /* pngtrans.c - transforms the data in a row (used by both readers and writers)
* *
* libpng 1.0.5k - December 27, 1999 * libpng 1.2.1 - December 12, 2001
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. * Copyright (c) 1998-2001 Glenn Randers-Pehrson
* Copyright (c) 1996, 1997 Andreas Dilger * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*/ */
#define PNG_INTERNAL #define PNG_INTERNAL
@@ -13,7 +13,7 @@
#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED) #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
/* turn on BGR-to-RGB mapping */ /* turn on BGR-to-RGB mapping */
void void PNGAPI
png_set_bgr(png_structp png_ptr) png_set_bgr(png_structp png_ptr)
{ {
png_debug(1, "in png_set_bgr\n"); png_debug(1, "in png_set_bgr\n");
@@ -23,7 +23,7 @@ png_set_bgr(png_structp png_ptr)
#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED) #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
/* turn on 16 bit byte swapping */ /* turn on 16 bit byte swapping */
void void PNGAPI
png_set_swap(png_structp png_ptr) png_set_swap(png_structp png_ptr)
{ {
png_debug(1, "in png_set_swap\n"); png_debug(1, "in png_set_swap\n");
@@ -34,7 +34,7 @@ png_set_swap(png_structp png_ptr)
#if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED) #if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
/* turn on pixel packing */ /* turn on pixel packing */
void void PNGAPI
png_set_packing(png_structp png_ptr) png_set_packing(png_structp png_ptr)
{ {
png_debug(1, "in png_set_packing\n"); png_debug(1, "in png_set_packing\n");
@@ -48,7 +48,7 @@ png_set_packing(png_structp png_ptr)
#if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED) #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)
/* turn on packed pixel swapping */ /* turn on packed pixel swapping */
void void PNGAPI
png_set_packswap(png_structp png_ptr) png_set_packswap(png_structp png_ptr)
{ {
png_debug(1, "in png_set_packswap\n"); png_debug(1, "in png_set_packswap\n");
@@ -58,7 +58,7 @@ png_set_packswap(png_structp png_ptr)
#endif #endif
#if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED) #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
void void PNGAPI
png_set_shift(png_structp png_ptr, png_color_8p true_bits) png_set_shift(png_structp png_ptr, png_color_8p true_bits)
{ {
png_debug(1, "in png_set_shift\n"); png_debug(1, "in png_set_shift\n");
@@ -69,7 +69,7 @@ png_set_shift(png_structp png_ptr, png_color_8p true_bits)
#if defined(PNG_READ_INTERLACING_SUPPORTED) || \ #if defined(PNG_READ_INTERLACING_SUPPORTED) || \
defined(PNG_WRITE_INTERLACING_SUPPORTED) defined(PNG_WRITE_INTERLACING_SUPPORTED)
int int PNGAPI
png_set_interlace_handling(png_structp png_ptr) png_set_interlace_handling(png_structp png_ptr)
{ {
png_debug(1, "in png_set_interlace handling\n"); png_debug(1, "in png_set_interlace handling\n");
@@ -89,7 +89,7 @@ png_set_interlace_handling(png_structp png_ptr)
* for 48-bit input data, as well as to avoid problems with some compilers * for 48-bit input data, as well as to avoid problems with some compilers
* that don't like bytes as parameters. * that don't like bytes as parameters.
*/ */
void void PNGAPI
png_set_filler(png_structp png_ptr, png_uint_32 filler, int filler_loc) png_set_filler(png_structp png_ptr, png_uint_32 filler, int filler_loc)
{ {
png_debug(1, "in png_set_filler\n"); png_debug(1, "in png_set_filler\n");
@@ -122,7 +122,7 @@ png_set_filler(png_structp png_ptr, png_uint_32 filler, int filler_loc)
#if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \ #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \
defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED) defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
void void PNGAPI
png_set_swap_alpha(png_structp png_ptr) png_set_swap_alpha(png_structp png_ptr)
{ {
png_debug(1, "in png_set_swap_alpha\n"); png_debug(1, "in png_set_swap_alpha\n");
@@ -132,7 +132,7 @@ png_set_swap_alpha(png_structp png_ptr)
#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \ #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED) defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
void void PNGAPI
png_set_invert_alpha(png_structp png_ptr) png_set_invert_alpha(png_structp png_ptr)
{ {
png_debug(1, "in png_set_invert_alpha\n"); png_debug(1, "in png_set_invert_alpha\n");
@@ -141,7 +141,7 @@ png_set_invert_alpha(png_structp png_ptr)
#endif #endif
#if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED) #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
void void PNGAPI
png_set_invert_mono(png_structp png_ptr) png_set_invert_mono(png_structp png_ptr)
{ {
png_debug(1, "in png_set_invert_mono\n"); png_debug(1, "in png_set_invert_mono\n");
@@ -149,15 +149,18 @@ png_set_invert_mono(png_structp png_ptr)
} }
/* invert monochrome grayscale data */ /* invert monochrome grayscale data */
void void /* PRIVATE */
png_do_invert(png_row_infop row_info, png_bytep row) png_do_invert(png_row_infop row_info, png_bytep row)
{ {
png_debug(1, "in png_do_invert\n"); png_debug(1, "in png_do_invert\n");
if (row_info->bit_depth == 1 && /* This test removed from libpng version 1.0.13 and 1.2.0:
* if (row_info->bit_depth == 1 &&
*/
#if defined(PNG_USELESS_TESTS_SUPPORTED) #if defined(PNG_USELESS_TESTS_SUPPORTED)
row != NULL && row_info != NULL && if (row == NULL || row_info == NULL)
return;
#endif #endif
row_info->color_type == PNG_COLOR_TYPE_GRAY) if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
{ {
png_bytep rp = row; png_bytep rp = row;
png_uint_32 i; png_uint_32 i;
@@ -169,12 +172,39 @@ png_do_invert(png_row_infop row_info, png_bytep row)
rp++; rp++;
} }
} }
else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
row_info->bit_depth == 8)
{
png_bytep rp = row;
png_uint_32 i;
png_uint_32 istop = row_info->rowbytes;
for (i = 0; i < istop; i+=2)
{
*rp = (png_byte)(~(*rp));
rp+=2;
}
}
else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
row_info->bit_depth == 16)
{
png_bytep rp = row;
png_uint_32 i;
png_uint_32 istop = row_info->rowbytes;
for (i = 0; i < istop; i+=4)
{
*rp = (png_byte)(~(*rp));
*(rp+1) = (png_byte)(~(*(rp+1)));
rp+=4;
}
}
} }
#endif #endif
#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED) #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
/* swaps byte order on 16 bit depth images */ /* swaps byte order on 16 bit depth images */
void void /* PRIVATE */
png_do_swap(png_row_infop row_info, png_bytep row) png_do_swap(png_row_infop row_info, png_bytep row)
{ {
png_debug(1, "in png_do_swap\n"); png_debug(1, "in png_do_swap\n");
@@ -305,7 +335,7 @@ static png_byte fourbppswaptable[256] = {
}; };
/* swaps pixel packing order within bytes */ /* swaps pixel packing order within bytes */
void void /* PRIVATE */
png_do_packswap(png_row_infop row_info, png_bytep row) png_do_packswap(png_row_infop row_info, png_bytep row)
{ {
png_debug(1, "in png_do_packswap\n"); png_debug(1, "in png_do_packswap\n");
@@ -337,7 +367,7 @@ png_do_packswap(png_row_infop row_info, png_bytep row)
#if defined(PNG_WRITE_FILLER_SUPPORTED) || \ #if defined(PNG_WRITE_FILLER_SUPPORTED) || \
defined(PNG_READ_STRIP_ALPHA_SUPPORTED) defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
/* remove filler or alpha byte(s) */ /* remove filler or alpha byte(s) */
void void /* PRIVATE */
png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags) png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags)
{ {
png_debug(1, "in png_do_strip_filler\n"); png_debug(1, "in png_do_strip_filler\n");
@@ -392,11 +422,12 @@ png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags)
sp += 8; dp += 6; sp += 8; dp += 6;
for (i = 1; i < row_width; i++) for (i = 1; i < row_width; i++)
{ {
/* This could be (although memcpy is probably slower): /* This could be (although png_memcpy is probably slower):
png_memcpy(dp, sp, 6); png_memcpy(dp, sp, 6);
sp += 8; sp += 8;
dp += 6; dp += 6;
*/ */
*dp++ = *sp++; *dp++ = *sp++;
*dp++ = *sp++; *dp++ = *sp++;
*dp++ = *sp++; *dp++ = *sp++;
@@ -411,11 +442,12 @@ png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags)
/* This converts from XXRRGGBB or AARRGGBB to RRGGBB */ /* This converts from XXRRGGBB or AARRGGBB to RRGGBB */
for (i = 0; i < row_width; i++) for (i = 0; i < row_width; i++)
{ {
/* This could be (although memcpy is probably slower): /* This could be (although png_memcpy is probably slower):
png_memcpy(dp, sp, 6); png_memcpy(dp, sp, 6);
sp += 8; sp += 8;
dp += 6; dp += 6;
*/ */
sp+=2; sp+=2;
*dp++ = *sp++; *dp++ = *sp++;
*dp++ = *sp++; *dp++ = *sp++;
@@ -495,7 +527,7 @@ png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags)
#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED) #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
/* swaps red and blue bytes within a pixel */ /* swaps red and blue bytes within a pixel */
void void /* PRIVATE */
png_do_bgr(png_row_infop row_info, png_bytep row) png_do_bgr(png_row_infop row_info, png_bytep row)
{ {
png_debug(1, "in png_do_bgr\n"); png_debug(1, "in png_do_bgr\n");
@@ -571,25 +603,38 @@ png_do_bgr(png_row_infop row_info, png_bytep row)
#endif /* PNG_READ_BGR_SUPPORTED or PNG_WRITE_BGR_SUPPORTED */ #endif /* PNG_READ_BGR_SUPPORTED or PNG_WRITE_BGR_SUPPORTED */
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \ #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
void defined(PNG_LEGACY_SUPPORTED)
void PNGAPI
png_set_user_transform_info(png_structp png_ptr, png_voidp png_set_user_transform_info(png_structp png_ptr, png_voidp
user_transform_ptr, int user_transform_depth, int user_transform_channels) user_transform_ptr, int user_transform_depth, int user_transform_channels)
{ {
png_debug(1, "in png_set_user_transform_info\n"); png_debug(1, "in png_set_user_transform_info\n");
#if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
png_ptr->user_transform_ptr = user_transform_ptr; png_ptr->user_transform_ptr = user_transform_ptr;
png_ptr->user_transform_depth = (png_byte)user_transform_depth; png_ptr->user_transform_depth = (png_byte)user_transform_depth;
png_ptr->user_transform_channels = (png_byte)user_transform_channels; png_ptr->user_transform_channels = (png_byte)user_transform_channels;
#else
if(user_transform_ptr || user_transform_depth || user_transform_channels)
png_warning(png_ptr,
"This version of libpng does not support user transform info");
#endif
} }
#endif
/* This function returns a pointer to the user_transform_ptr associated with /* This function returns a pointer to the user_transform_ptr associated with
* the user transform functions. The application should free any memory * the user transform functions. The application should free any memory
* associated with this pointer before png_write_destroy and png_read_destroy * associated with this pointer before png_write_destroy and png_read_destroy
* are called. * are called.
*/ */
png_voidp png_voidp PNGAPI
png_get_user_transform_ptr(png_structp png_ptr) png_get_user_transform_ptr(png_structp png_ptr)
{ {
#if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
return ((png_voidp)png_ptr->user_transform_ptr); return ((png_voidp)png_ptr->user_transform_ptr);
} #else
if(png_ptr)
return (NULL);
return (NULL);
#endif #endif
}

View File

@@ -1,34 +0,0 @@
/* pngtypes.h - array of chunk-types for libpng
*
* libpng 1.0.5k - December 27, 1999
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
*/
/* Constant strings for known chunk types. If you need to add a chunk,
* define the string in png.h and invoke it here.
*/
PNG_IHDR;
PNG_IDAT;
PNG_IEND;
PNG_PLTE;
PNG_bKGD;
PNG_cHRM;
PNG_gAMA;
PNG_hIST;
PNG_iCCP;
PNG_iTXt;
PNG_oFFs;
PNG_pCAL;
PNG_pHYs;
PNG_sBIT;
PNG_sPLT;
PNG_sRGB;
PNG_tEXt;
PNG_tIME;
PNG_tRNS;
PNG_zTXt;

233
pngvcrd.c
View File

@@ -2,14 +2,25 @@
* *
* For Intel x86 CPU and Microsoft Visual C++ compiler * For Intel x86 CPU and Microsoft Visual C++ compiler
* *
* libpng 1.0.5k - December 27, 1999 * libpng version 1.2.1 - December 12, 2001
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2001 Glenn Randers-Pehrson
* Copyright (c) 1998, Intel Corporation * Copyright (c) 1998, Intel Corporation
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
* *
* Contributed by Nirav Chhatrapati, Intel Corporation, 1998 * Contributed by Nirav Chhatrapati, Intel Corporation, 1998
* Interface to libpng contributed by Gilles Vollant, 1999 * Interface to libpng contributed by Gilles Vollant, 1999
* *
*
* In png_do_read_interlace() in libpng versions 1.0.3a through 1.0.4d,
* a sign error in the post-MMX cleanup code for each pixel_depth resulted
* in bad pixels at the beginning of some rows of some images, and also
* (due to out-of-range memory reads and writes) caused heap corruption
* when compiled with MSVC 6.0. The error was fixed in version 1.0.4e.
*
* [png_read_filter_row_mmx_avg() bpp == 2 bugfix, GRR 20000916]
*
* [runtime MMX configuration, GRR 20010102]
*
*/ */
#define PNG_INTERNAL #define PNG_INTERNAL
@@ -17,22 +28,18 @@
#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) && defined(PNG_USE_PNGVCRD) #if defined(PNG_ASSEMBLER_CODE_SUPPORTED) && defined(PNG_USE_PNGVCRD)
/*
One of these might need to be defined.
#define DISABLE_PNGVCRD_COMBINE
#define DISABLE_PNGVCRD_INTERLACE
*/
static int mmx_supported=2; static int mmx_supported=2;
void
png_read_filter_row_c(png_structp png_ptr, png_row_infop row_info,
png_bytep row, png_bytep prev_row, int filter);
static int mmxsupport() int PNGAPI
png_mmx_support(void)
{ {
int mmx_supported_local = 0; int mmx_supported_local = 0;
_asm { _asm {
push ebx //CPUID will trash these
push ecx
push edx
pushfd //Save Eflag to stack pushfd //Save Eflag to stack
pop eax //Get Eflag from stack into eax pop eax //Get Eflag from stack into eax
mov ecx, eax //Make another copy of Eflag in ecx mov ecx, eax //Make another copy of Eflag in ecx
@@ -42,6 +49,8 @@ static int mmxsupport()
popfd //Restored modified value back to Eflag reg popfd //Restored modified value back to Eflag reg
pushfd //Save Eflag to stack pushfd //Save Eflag to stack
pop eax //Get Eflag from stack pop eax //Get Eflag from stack
push ecx // save original Eflag to stack
popfd // restore original Eflag
xor eax, ecx //Compare the new Eflag with the original Eflag xor eax, ecx //Compare the new Eflag with the original Eflag
jz NOT_SUPPORTED //If the same, CPUID instruction is not supported, jz NOT_SUPPORTED //If the same, CPUID instruction is not supported,
//skip following instructions and jump to //skip following instructions and jump to
@@ -70,12 +79,15 @@ static int mmxsupport()
NOT_SUPPORTED: NOT_SUPPORTED:
mov eax, mmx_supported_local //move return value to eax mov eax, mmx_supported_local //move return value to eax
pop edx //CPUID trashed these
pop ecx
pop ebx
} }
//mmx_supported_local=0; // test code for force don't support MMX //mmx_supported_local=0; // test code for force don't support MMX
//printf("MMX : %u (1=MMX supported)\n",mmx_supported_local); //printf("MMX : %u (1=MMX supported)\n",mmx_supported_local);
mmx_supported = mmx_supported_local;
return mmx_supported_local; return mmx_supported_local;
} }
@@ -93,25 +105,20 @@ NOT_SUPPORTED:
/* Use this routine for x86 platform - uses faster MMX routine if machine /* Use this routine for x86 platform - uses faster MMX routine if machine
supports MMX */ supports MMX */
void void /* PRIVATE */
png_combine_row(png_structp png_ptr, png_bytep row, int mask) png_combine_row(png_structp png_ptr, png_bytep row, int mask)
{ {
#ifdef PNG_USE_LOCAL_ARRAYS #ifdef PNG_USE_LOCAL_ARRAYS
const int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; const int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
#endif #endif
#ifdef DISABLE_PNGVCRD_COMBINE
int save_mmx_supported = mmx_supported;
#endif
png_debug(1,"in png_combine_row_asm\n"); png_debug(1,"in png_combine_row_asm\n");
#ifdef DISABLE_PNGVCRD_COMBINE if (mmx_supported == 2) {
if ((png_ptr->transformations & PNG_INTERLACE) && png_ptr->pass != 6) /* this should have happened in png_init_mmx_flags() already */
mmx_supported = 0; png_warning(png_ptr, "asm_flags may not have been initialized");
else png_mmx_support();
#endif }
if (mmx_supported == 2)
mmx_supported = mmxsupport();
if (mask == 0xff) if (mask == 0xff)
{ {
@@ -300,7 +307,8 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask)
__int64 mask0=0x0102040810204080; __int64 mask0=0x0102040810204080;
if (mmx_supported) if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)
/* && mmx_supported */ )
{ {
srcptr = png_ptr->row_buf + 1; srcptr = png_ptr->row_buf + 1;
dstptr = row; dstptr = row;
@@ -400,7 +408,8 @@ end8:
__int64 mask1=0x0101020204040808, __int64 mask1=0x0101020204040808,
mask0=0x1010202040408080; mask0=0x1010202040408080;
if (mmx_supported) if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)
/* && mmx_supported */ )
{ {
srcptr = png_ptr->row_buf + 1; srcptr = png_ptr->row_buf + 1;
dstptr = row; dstptr = row;
@@ -520,7 +529,8 @@ end16:
len = (png_ptr->width)&~7; len = (png_ptr->width)&~7;
diff = (png_ptr->width)&7; diff = (png_ptr->width)&7;
if (mmx_supported) if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)
/* && mmx_supported */ )
{ {
_asm _asm
{ {
@@ -651,7 +661,8 @@ end24:
len = (png_ptr->width)&~7; len = (png_ptr->width)&~7;
diff = (png_ptr->width)&7; diff = (png_ptr->width)&7;
if (mmx_supported) if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)
/* && mmx_supported */ )
{ {
_asm _asm
{ {
@@ -785,7 +796,8 @@ end32:
mask1=0x2020202040404040, mask1=0x2020202040404040,
mask0=0x4040808080808080; mask0=0x4040808080808080;
if (mmx_supported) if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)
/* && mmx_supported */ )
{ {
srcptr = png_ptr->row_buf + 1; srcptr = png_ptr->row_buf + 1;
dstptr = row; dstptr = row;
@@ -956,43 +968,29 @@ end48:
} /* end switch (png_ptr->row_info.pixel_depth) */ } /* end switch (png_ptr->row_info.pixel_depth) */
} /* end if (non-trivial mask) */ } /* end if (non-trivial mask) */
#ifdef DISABLE_PNGVCRD_COMBINE
mmx_supported = save_mmx_supported;
#endif
} /* end png_combine_row() */ } /* end png_combine_row() */
#if defined(PNG_READ_INTERLACING_SUPPORTED) #if defined(PNG_READ_INTERLACING_SUPPORTED)
void void /* PRIVATE */
png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass, png_do_read_interlace(png_structp png_ptr)
png_uint_32 transformations)
{ {
png_row_infop row_info = &(png_ptr->row_info);
png_bytep row = png_ptr->row_buf + 1;
int pass = png_ptr->pass;
png_uint_32 transformations = png_ptr->transformations;
#ifdef PNG_USE_LOCAL_ARRAYS #ifdef PNG_USE_LOCAL_ARRAYS
const int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; const int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
#endif #endif
#ifdef DISABLE_PNGVCRD_INTERLACE
int save_mmx_supported = mmx_supported;
#endif
png_debug(1,"in png_do_read_interlace\n"); png_debug(1,"in png_do_read_interlace\n");
#ifdef DISABLE_PNGVCRD_INTERLACE if (mmx_supported == 2) {
/* In libpng versions 1.0.3a through 1.0.4d, /* this should have happened in png_init_mmx_flags() already */
* a sign error in the post-MMX cleanup code for each pixel_depth resulted png_warning(png_ptr, "asm_flags may not have been initialized");
* in bad pixels at the beginning of some rows of some images, and also png_mmx_support();
* (due to out-of-range memory reads and writes) caused heap corruption }
* when compiled with MSVC 6.0. The error was fixed in version 1.0.4e,
* and the code appears to work completely correctly, so it is enabled
* by default.
*/
if (1) /* all passes caused a heap problem in the old code */
mmx_supported = 0;
else
#endif
if (mmx_supported == 2)
mmx_supported = mmxsupport();
if (row != NULL && row_info != NULL) if (row != NULL && row_info != NULL)
{ {
@@ -1190,7 +1188,9 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
// sign fix by GRR // sign fix by GRR
// NOTE: there is NO MMX code for 48-bit and 64-bit images // NOTE: there is NO MMX code for 48-bit and 64-bit images
if (mmx_supported) // use MMX routine if machine supports it // use MMX routine if machine supports it
if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_INTERLACE)
/* && mmx_supported */ )
{ {
if (pixel_bytes == 3) if (pixel_bytes == 3)
{ {
@@ -1878,9 +1878,6 @@ loop4_pass4:
(png_uint_32)row_info->pixel_depth + 7) >> 3); (png_uint_32)row_info->pixel_depth + 7) >> 3);
} }
#ifdef DISABLE_PNGVCRD_INTERLACE
mmx_supported = save_mmx_supported;
#endif
} }
#endif /* PNG_READ_INTERLACING_SUPPORTED */ #endif /* PNG_READ_INTERLACING_SUPPORTED */
@@ -1898,7 +1895,7 @@ union uAll {
// Optimized code for PNG Average filter decoder // Optimized code for PNG Average filter decoder
void void /* PRIVATE */
png_read_filter_row_mmx_avg(png_row_infop row_info, png_bytep row png_read_filter_row_mmx_avg(png_row_infop row_info, png_bytep row
, png_bytep prev_row) , png_bytep prev_row)
{ {
@@ -2112,8 +2109,8 @@ davg4lp:
case 2: case 2:
{ {
ActiveMask.use = 0x000000000000ffff; ActiveMask.use = 0x000000000000ffff;
ShiftBpp.use = 24; // == 3 * 8 ShiftBpp.use = 16; // == 2 * 8 [BUGFIX]
ShiftRem.use = 40; // == 64 - 24 ShiftRem.use = 48; // == 64 - 16 [BUGFIX]
_asm { _asm {
// Load ActiveMask // Load ActiveMask
movq mm7, ActiveMask movq mm7, ActiveMask
@@ -2128,7 +2125,7 @@ davg4lp:
// (we correct position in loop below) // (we correct position in loop below)
davg2lp: davg2lp:
movq mm0, [edi + ebx] movq mm0, [edi + ebx]
psllq mm2, ShiftRem // shift data to position correctly psrlq mm2, ShiftRem // shift data to position correctly [BUGFIX]
movq mm1, [esi + ebx] movq mm1, [esi + ebx]
// Add (Prev_row/2) to Average // Add (Prev_row/2) to Average
movq mm3, mm5 movq mm3, mm5
@@ -2331,7 +2328,7 @@ davgend:
} }
// Optimized code for PNG Paeth filter decoder // Optimized code for PNG Paeth filter decoder
void void /* PRIVATE */
png_read_filter_row_mmx_paeth(png_row_infop row_info, png_bytep row, png_read_filter_row_mmx_paeth(png_row_infop row_info, png_bytep row,
png_bytep prev_row) png_bytep prev_row)
{ {
@@ -3227,7 +3224,7 @@ dpthend:
} }
// Optimized code for PNG Sub filter decoder // Optimized code for PNG Sub filter decoder
void void /* PRIVATE */
png_read_filter_row_mmx_sub(png_row_infop row_info, png_bytep row) png_read_filter_row_mmx_sub(png_row_infop row_info, png_bytep row)
{ {
//int test; //int test;
@@ -3316,7 +3313,7 @@ dsub3lp:
case 1: case 1:
{ {
// Placed here just in case this is a duplicate of the // Placed here just in case this is a duplicate of the
// non-MMX code for the SUB filter in png_read_filter_row above // non-MMX code for the SUB filter in png_read_filter_row below
// //
// png_bytep rp; // png_bytep rp;
// png_bytep lp; // png_bytep lp;
@@ -3531,7 +3528,7 @@ dsubend:
} }
// Optimized code for PNG Up filter decoder // Optimized code for PNG Up filter decoder
void void /* PRIVATE */
png_read_filter_row_mmx_up(png_row_infop row_info, png_bytep row, png_read_filter_row_mmx_up(png_row_infop row_info, png_bytep row,
png_bytep prev_row) png_bytep prev_row)
{ {
@@ -3646,66 +3643,61 @@ dupend:
// Optimized png_read_filter_row routines // Optimized png_read_filter_row routines
void void /* PRIVATE */
png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep
row, png_bytep prev_row, int filter) row, png_bytep prev_row, int filter)
{ {
#ifdef PNG_DEBUG #ifdef PNG_DEBUG
char filnm[6]; char filnm[10];
#endif #endif
#define UseMMX 1
if (mmx_supported == 2) if (mmx_supported == 2) {
mmx_supported = mmxsupport(); /* this should have happened in png_init_mmx_flags() already */
png_warning(png_ptr, "asm_flags may not have been initialized");
if (!mmx_supported) png_mmx_support();
{
png_read_filter_row_c(png_ptr, row_info, row, prev_row, filter);
return ;
} }
#ifdef PNG_DEBUG #ifdef PNG_DEBUG
png_debug(1, "in png_read_filter_row\n"); png_debug(1, "in png_read_filter_row\n");
#if (UseMMX == 1)
png_debug1(0,"%s, ", "MMX");
#else
png_debug1(0,"%s, ", "x86");
#endif
switch (filter) switch (filter)
{ {
case 0: sprintf(filnm, "None "); case 0: sprintf(filnm, "none");
break; break;
case 1: sprintf(filnm, "Sub "); case 1: sprintf(filnm, "sub-%s",
(png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_SUB)? "MMX" : "x86");
break; break;
case 2: sprintf(filnm, "Up "); case 2: sprintf(filnm, "up-%s",
(png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_UP)? "MMX" : "x86");
break; break;
case 3: sprintf(filnm, "Avg "); case 3: sprintf(filnm, "avg-%s",
(png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_AVG)? "MMX" : "x86");
break; break;
case 4: sprintf(filnm, "Paeth"); case 4: sprintf(filnm, "Paeth-%s",
(png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_PAETH)? "MMX":"x86");
break; break;
default: sprintf(filnm, "Unknw"); default: sprintf(filnm, "unknw");
break; break;
} }
png_debug2(0,"row=%5d, %s, ", png_ptr->row_number, filnm); png_debug2(0,"row=%5d, %s, ", png_ptr->row_number, filnm);
png_debug2(0, "pd=%2d, b=%d, ", (int)row_info->pixel_depth, png_debug2(0, "pd=%2d, b=%d, ", (int)row_info->pixel_depth,
(int)((row_info->pixel_depth + 7) >> 3)); (int)((row_info->pixel_depth + 7) >> 3));
png_debug1(0,"len=%8d, ", row_info->rowbytes); png_debug1(0,"len=%8d, ", row_info->rowbytes);
#endif #endif /* PNG_DEBUG */
switch (filter) switch (filter)
{ {
case PNG_FILTER_VALUE_NONE: case PNG_FILTER_VALUE_NONE:
break; break;
case PNG_FILTER_VALUE_SUB: case PNG_FILTER_VALUE_SUB:
{ {
#if (UseMMX == 1) if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_SUB) &&
if ((row_info->pixel_depth > 8) && (row_info->pixel_depth >= png_ptr->mmx_bitdepth_threshold) &&
(row_info->rowbytes >= 128) ) (row_info->rowbytes >= png_ptr->mmx_rowbytes_threshold))
{ {
png_read_filter_row_mmx_sub(row_info, row); png_read_filter_row_mmx_sub(row_info, row);
} }
else else
#endif
{ {
png_uint_32 i; png_uint_32 i;
png_uint_32 istop = row_info->rowbytes; png_uint_32 istop = row_info->rowbytes;
@@ -3718,41 +3710,43 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep
*rp = (png_byte)(((int)(*rp) + (int)(*lp++)) & 0xff); *rp = (png_byte)(((int)(*rp) + (int)(*lp++)) & 0xff);
rp++; rp++;
} }
} //end !UseMMX }
break; break;
} }
case PNG_FILTER_VALUE_UP: case PNG_FILTER_VALUE_UP:
{ {
#if (UseMMX == 1) if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_UP) &&
if ((row_info->pixel_depth > 8) && (row_info->pixel_depth >= png_ptr->mmx_bitdepth_threshold) &&
(row_info->rowbytes >= 128) ) (row_info->rowbytes >= png_ptr->mmx_rowbytes_threshold))
{ {
png_read_filter_row_mmx_up(row_info, row, prev_row); png_read_filter_row_mmx_up(row_info, row, prev_row);
} //end if UseMMX }
else else
#endif
{ {
png_bytep rp;
png_bytep pp;
png_uint_32 i; png_uint_32 i;
for (i = 0, rp = row, pp = prev_row; png_uint_32 istop = row_info->rowbytes;
i < row_info->rowbytes; i++, rp++, pp++) png_bytep rp = row;
png_bytep pp = prev_row;
for (i = 0; i < istop; ++i)
{ {
*rp = (png_byte)(((int)(*rp) + (int)(*pp)) & 0xff); *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
rp++;
} }
} //end !UseMMX }
break; break;
} }
case PNG_FILTER_VALUE_AVG: case PNG_FILTER_VALUE_AVG:
{ {
#if (UseMMX == 1) if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_AVG) &&
if ((row_info->pixel_depth > 8) && (row_info->pixel_depth >= png_ptr->mmx_bitdepth_threshold) &&
(row_info->rowbytes >= 128) ) (row_info->rowbytes >= png_ptr->mmx_rowbytes_threshold))
{ {
png_read_filter_row_mmx_avg(row_info, row, prev_row); png_read_filter_row_mmx_avg(row_info, row, prev_row);
} //end if UseMMX }
else else
#endif
{ {
png_uint_32 i; png_uint_32 i;
png_bytep rp = row; png_bytep rp = row;
@@ -3774,19 +3768,19 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep
((int)(*pp++ + *lp++) >> 1)) & 0xff); ((int)(*pp++ + *lp++) >> 1)) & 0xff);
rp++; rp++;
} }
} //end !UseMMX }
break; break;
} }
case PNG_FILTER_VALUE_PAETH: case PNG_FILTER_VALUE_PAETH:
{ {
#if (UseMMX == 1) if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_PAETH) &&
if ((row_info->pixel_depth > 8) && (row_info->pixel_depth >= png_ptr->mmx_bitdepth_threshold) &&
(row_info->rowbytes >= 128) ) (row_info->rowbytes >= png_ptr->mmx_rowbytes_threshold))
{ {
png_read_filter_row_mmx_paeth(row_info, row, prev_row); png_read_filter_row_mmx_paeth(row_info, row, prev_row);
} //end if UseMMX }
else else
#endif
{ {
png_uint_32 i; png_uint_32 i;
png_bytep rp = row; png_bytep rp = row;
@@ -3837,12 +3831,15 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep
*rp = (png_byte)(((int)(*rp) + p) & 0xff); *rp = (png_byte)(((int)(*rp) + p) & 0xff);
rp++; rp++;
} }
} //end !UseMMX }
break; break;
} }
default: default:
png_error(png_ptr, "Bad adaptive filter type"); png_warning(png_ptr, "Ignoring bad row filter type");
*row=0;
break; break;
} }
} }
#endif
#endif /* PNG_ASSEMBLER_CODE_SUPPORTED && PNG_USE_PNGVCRD */

View File

@@ -1,11 +1,11 @@
/* pngwio.c - functions for data output /* pngwio.c - functions for data output
* *
* libpng 1.0.5k - December 27, 1999 * libpng 1.2.1 - December 12, 2001
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. * Copyright (c) 1998-2001 Glenn Randers-Pehrson
* Copyright (c) 1996, 1997 Andreas Dilger * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
* *
* This file provides a location for all output. Users who need * This file provides a location for all output. Users who need
* special handling are expected to write functions that have the same * special handling are expected to write functions that have the same
@@ -17,6 +17,7 @@
#define PNG_INTERNAL #define PNG_INTERNAL
#include "png.h" #include "png.h"
#ifdef PNG_WRITE_SUPPORTED
/* Write the data to whatever output you are using. The default routine /* Write the data to whatever output you are using. The default routine
writes to a file pointer. Note that this routine sometimes gets called writes to a file pointer. Note that this routine sometimes gets called
@@ -24,7 +25,7 @@
buffering if you are using unbuffered writes. This should never be asked buffering if you are using unbuffered writes. This should never be asked
to write more than 64K on a 16 bit machine. */ to write more than 64K on a 16 bit machine. */
void void /* PRIVATE */
png_write_data(png_structp png_ptr, png_bytep data, png_size_t length) png_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
{ {
if (png_ptr->write_data_fn != NULL ) if (png_ptr->write_data_fn != NULL )
@@ -39,16 +40,19 @@ png_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
write_data function and use it at run time with png_set_write_fn(), rather write_data function and use it at run time with png_set_write_fn(), rather
than changing the library. */ than changing the library. */
#ifndef USE_FAR_KEYWORD #ifndef USE_FAR_KEYWORD
static void static void /* PRIVATE */
png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length) png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
{ {
png_uint_32 check; png_uint_32 check;
check = fwrite(data, 1, length, (FILE *)(png_ptr->io_ptr)); #if defined(_WIN32_WCE)
if ( !WriteFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
check = 0;
#else
check = fwrite(data, 1, length, (png_FILE_p)(png_ptr->io_ptr));
#endif
if (check != length) if (check != length)
{
png_error(png_ptr, "Write Error"); png_error(png_ptr, "Write Error");
}
} }
#else #else
/* this is the model-independent version. Since the standard I/O library /* this is the model-independent version. Since the standard I/O library
@@ -59,19 +63,24 @@ png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
#define NEAR_BUF_SIZE 1024 #define NEAR_BUF_SIZE 1024
#define MIN(a,b) (a <= b ? a : b) #define MIN(a,b) (a <= b ? a : b)
static void static void /* PRIVATE */
png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length) png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
{ {
png_uint_32 check; png_uint_32 check;
png_byte *near_data; /* Needs to be "png_byte *" instead of "png_bytep" */ png_byte *near_data; /* Needs to be "png_byte *" instead of "png_bytep" */
FILE *io_ptr; png_FILE_p io_ptr;
/* Check if data really is near. If so, use usual code. */ /* Check if data really is near. If so, use usual code. */
near_data = (png_byte *)CVT_PTR_NOCHECK(data); near_data = (png_byte *)CVT_PTR_NOCHECK(data);
io_ptr = (FILE *)CVT_PTR(png_ptr->io_ptr); io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
if ((png_bytep)near_data == data) if ((png_bytep)near_data == data)
{ {
#if defined(_WIN32_WCE)
if ( !WriteFile(io_ptr, near_data, length, &check, NULL) )
check = 0;
#else
check = fwrite(near_data, 1, length, io_ptr); check = fwrite(near_data, 1, length, io_ptr);
#endif
} }
else else
{ {
@@ -83,7 +92,12 @@ png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
{ {
written = MIN(NEAR_BUF_SIZE, remaining); written = MIN(NEAR_BUF_SIZE, remaining);
png_memcpy(buf, data, written); /* copy far buffer to near buffer */ png_memcpy(buf, data, written); /* copy far buffer to near buffer */
#if defined(_WIN32_WCE)
if ( !WriteFile(io_ptr, buf, written, &err, NULL) )
err = 0;
#else
err = fwrite(buf, 1, written, io_ptr); err = fwrite(buf, 1, written, io_ptr);
#endif
if (err != written) if (err != written)
break; break;
else else
@@ -94,9 +108,7 @@ png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
while (remaining != 0); while (remaining != 0);
} }
if (check != length) if (check != length)
{
png_error(png_ptr, "Write Error"); png_error(png_ptr, "Write Error");
}
} }
#endif #endif
@@ -106,7 +118,7 @@ png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
to disk). After png_flush is called, there should be no data pending to disk). After png_flush is called, there should be no data pending
writing in any buffers. */ writing in any buffers. */
#if defined(PNG_WRITE_FLUSH_SUPPORTED) #if defined(PNG_WRITE_FLUSH_SUPPORTED)
void void /* PRIVATE */
png_flush(png_structp png_ptr) png_flush(png_structp png_ptr)
{ {
if (png_ptr->output_flush_fn != NULL) if (png_ptr->output_flush_fn != NULL)
@@ -114,13 +126,15 @@ png_flush(png_structp png_ptr)
} }
#if !defined(PNG_NO_STDIO) #if !defined(PNG_NO_STDIO)
static void static void /* PRIVATE */
png_default_flush(png_structp png_ptr) png_default_flush(png_structp png_ptr)
{ {
FILE *io_ptr; #if !defined(_WIN32_WCE)
io_ptr = (FILE *)CVT_PTR((png_ptr->io_ptr)); png_FILE_p io_ptr;
io_ptr = (png_FILE_p)CVT_PTR((png_ptr->io_ptr));
if (io_ptr != NULL) if (io_ptr != NULL)
fflush(io_ptr); fflush(io_ptr);
#endif
} }
#endif #endif
#endif #endif
@@ -147,7 +161,7 @@ png_default_flush(png_structp png_ptr)
PNG_WRITE_FLUSH_SUPPORTED is not defined at libpng compile PNG_WRITE_FLUSH_SUPPORTED is not defined at libpng compile
time, output_flush_fn will be ignored, although it must be time, output_flush_fn will be ignored, although it must be
supplied for compatibility. */ supplied for compatibility. */
void void PNGAPI
png_set_write_fn(png_structp png_ptr, png_voidp io_ptr, png_set_write_fn(png_structp png_ptr, png_voidp io_ptr,
png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn) png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn)
{ {
@@ -211,3 +225,4 @@ void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check)
} }
# endif # endif
# endif # endif
#endif /* PNG_WRITE_SUPPORTED */

View File

@@ -1,16 +1,17 @@
/* pngwrite.c - general routines to write a PNG file /* pngwrite.c - general routines to write a PNG file
* *
* libpng 1.0.5k - December 27, 1999 * libpng 1.2.1 - December 12, 2001
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. * Copyright (c) 1998-2001 Glenn Randers-Pehrson
* Copyright (c) 1996, 1997 Andreas Dilger * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*/ */
/* get internal access to png.h */ /* get internal access to png.h */
#define PNG_INTERNAL #define PNG_INTERNAL
#include "png.h" #include "png.h"
#ifdef PNG_WRITE_SUPPORTED
/* Writes all the PNG information. This is the suggested way to use the /* Writes all the PNG information. This is the suggested way to use the
* library. If you have a new chunk to add, make a function to write it, * library. If you have a new chunk to add, make a function to write it,
@@ -21,13 +22,20 @@
* write a plain PNG file. If you have long comments, I suggest writing * write a plain PNG file. If you have long comments, I suggest writing
* them in png_write_end(), and compressing them. * them in png_write_end(), and compressing them.
*/ */
void void PNGAPI
png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr) png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr)
{ {
png_debug(1, "in png_write_info_before_PLTE\n"); png_debug(1, "in png_write_info_before_PLTE\n");
if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE)) if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
{ {
png_write_sig(png_ptr); /* write PNG signature */ png_write_sig(png_ptr); /* write PNG signature */
#if defined(PNG_MNG_FEATURES_SUPPORTED)
if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&(png_ptr->mng_features_permitted))
{
png_warning(png_ptr,"MNG features are not allowed in a PNG datastream\n");
png_ptr->mng_features_permitted=0;
}
#endif
/* write IHDR information. */ /* write IHDR information. */
png_write_IHDR(png_ptr, info_ptr->width, info_ptr->height, png_write_IHDR(png_ptr, info_ptr->width, info_ptr->height,
info_ptr->bit_depth, info_ptr->color_type, info_ptr->compression_type, info_ptr->bit_depth, info_ptr->color_type, info_ptr->compression_type,
@@ -57,7 +65,7 @@ png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr)
#endif #endif
#if defined(PNG_WRITE_iCCP_SUPPORTED) #if defined(PNG_WRITE_iCCP_SUPPORTED)
if (info_ptr->valid & PNG_INFO_iCCP) if (info_ptr->valid & PNG_INFO_iCCP)
png_write_iCCP(png_ptr, info_ptr->iccp_name, PNG_TEXT_COMPRESSION_NONE, png_write_iCCP(png_ptr, info_ptr->iccp_name, PNG_COMPRESSION_TYPE_BASE,
info_ptr->iccp_profile, (int)info_ptr->iccp_proflen); info_ptr->iccp_profile, (int)info_ptr->iccp_proflen);
#endif #endif
#if defined(PNG_WRITE_sBIT_SUPPORTED) #if defined(PNG_WRITE_sBIT_SUPPORTED)
@@ -110,7 +118,7 @@ png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr)
} }
} }
void void PNGAPI
png_write_info(png_structp png_ptr, png_infop info_ptr) png_write_info(png_structp png_ptr, png_infop info_ptr)
{ {
#if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED) #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
@@ -165,13 +173,16 @@ png_write_info(png_structp png_ptr, png_infop info_ptr)
#endif #endif
#if defined(PNG_WRITE_sCAL_SUPPORTED) #if defined(PNG_WRITE_sCAL_SUPPORTED)
if (info_ptr->valid & PNG_INFO_sCAL) if (info_ptr->valid & PNG_INFO_sCAL)
#ifdef PNG_FLOATING_POINT_SUPPORTED #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
png_write_sCAL(png_ptr, (int)info_ptr->scal_unit, png_write_sCAL(png_ptr, (int)info_ptr->scal_unit,
info_ptr->scal_pixel_width, info_ptr->scal_pixel_height); info_ptr->scal_pixel_width, info_ptr->scal_pixel_height);
#else #else
#ifdef PNG_FIXED_POINT_SUPPORTED #ifdef PNG_FIXED_POINT_SUPPORTED
png_write_sCAL_s(png_ptr, (int)info_ptr->scal_unit, png_write_sCAL_s(png_ptr, (int)info_ptr->scal_unit,
info_ptr->scal_s_width, info_ptr->scal_s_height); info_ptr->scal_s_width, info_ptr->scal_s_height);
#else
png_warning(png_ptr,
"png_write_sCAL not supported; sCAL chunk not written.\n");
#endif #endif
#endif #endif
#endif #endif
@@ -274,7 +285,7 @@ png_write_info(png_structp png_ptr, png_infop info_ptr)
* in png_write_info(), do not write them again here. If you have long * in png_write_info(), do not write them again here. If you have long
* comments, I suggest writing them here, and compressing them. * comments, I suggest writing them here, and compressing them.
*/ */
void void PNGAPI
png_write_end(png_structp png_ptr, png_infop info_ptr) png_write_end(png_structp png_ptr, png_infop info_ptr)
{ {
png_debug(1, "in png_write_end\n"); png_debug(1, "in png_write_end\n");
@@ -372,10 +383,17 @@ png_write_end(png_structp png_ptr, png_infop info_ptr)
/* write end of PNG file */ /* write end of PNG file */
png_write_IEND(png_ptr); png_write_IEND(png_ptr);
#if 0
/* This flush, added in libpng-1.0.8, causes some applications to crash
because they do not set png_ptr->output_flush_fn */
png_flush(png_ptr);
#endif
} }
#if defined(PNG_WRITE_tIME_SUPPORTED) #if defined(PNG_WRITE_tIME_SUPPORTED)
void #if !defined(_WIN32_WCE)
/* "time.h" functions are not supported on WindowsCE */
void PNGAPI
png_convert_from_struct_tm(png_timep ptime, struct tm FAR * ttime) png_convert_from_struct_tm(png_timep ptime, struct tm FAR * ttime)
{ {
png_debug(1, "in png_convert_from_struct_tm\n"); png_debug(1, "in png_convert_from_struct_tm\n");
@@ -387,7 +405,7 @@ png_convert_from_struct_tm(png_timep ptime, struct tm FAR * ttime)
ptime->second = (png_byte)ttime->tm_sec; ptime->second = (png_byte)ttime->tm_sec;
} }
void void PNGAPI
png_convert_from_time_t(png_timep ptime, time_t ttime) png_convert_from_time_t(png_timep ptime, time_t ttime)
{ {
struct tm *tbuf; struct tm *tbuf;
@@ -397,38 +415,46 @@ png_convert_from_time_t(png_timep ptime, time_t ttime)
png_convert_from_struct_tm(ptime, tbuf); png_convert_from_struct_tm(ptime, tbuf);
} }
#endif #endif
#endif
/* Initialize png_ptr structure, and allocate any memory needed */ /* Initialize png_ptr structure, and allocate any memory needed */
png_structp png_structp PNGAPI
png_create_write_struct(png_const_charp user_png_ver, png_voidp error_ptr, png_create_write_struct(png_const_charp user_png_ver, png_voidp error_ptr,
png_error_ptr error_fn, png_error_ptr warn_fn) png_error_ptr error_fn, png_error_ptr warn_fn)
{ {
#ifdef PNG_USER_MEM_SUPPORTED #ifdef PNG_USER_MEM_SUPPORTED
return (png_create_write_struct_2(user_png_ver, error_ptr, error_fn, return (png_create_write_struct_2(user_png_ver, error_ptr, error_fn,
warn_fn, NULL, NULL, NULL)); warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL));
} }
/* Alternate initialize png_ptr structure, and allocate any memory needed */ /* Alternate initialize png_ptr structure, and allocate any memory needed */
png_structp png_structp PNGAPI
png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr, png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr, png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
png_malloc_ptr malloc_fn, png_free_ptr free_fn) png_malloc_ptr malloc_fn, png_free_ptr free_fn)
{ {
#endif /* PNG_USER_MEM_SUPPORTED */ #endif /* PNG_USER_MEM_SUPPORTED */
png_structp png_ptr; png_structp png_ptr;
#ifdef PNG_SETJMP_SUPPORTED
#ifdef USE_FAR_KEYWORD #ifdef USE_FAR_KEYWORD
jmp_buf jmpbuf; jmp_buf jmpbuf;
#endif #endif
#endif
int i;
png_debug(1, "in png_create_write_struct\n"); png_debug(1, "in png_create_write_struct\n");
#ifdef PNG_USER_MEM_SUPPORTED #ifdef PNG_USER_MEM_SUPPORTED
if ((png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG, if ((png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
(png_malloc_ptr)malloc_fn)) == NULL) (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr)) == NULL)
#else #else
if ((png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG)) == NULL) if ((png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG)) == NULL)
#endif /* PNG_USER_MEM_SUPPORTED */ #endif /* PNG_USER_MEM_SUPPORTED */
{ return (NULL);
return ((png_structp)NULL);
} #ifdef PNG_ASSEMBLER_CODE_SUPPORTED
png_init_mmx_flags(png_ptr); /* 1.2.0 addition */
#endif
#ifdef PNG_SETJMP_SUPPORTED
#ifdef USE_FAR_KEYWORD #ifdef USE_FAR_KEYWORD
if (setjmp(jmpbuf)) if (setjmp(jmpbuf))
#else #else
@@ -436,27 +462,56 @@ png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
#endif #endif
{ {
png_free(png_ptr, png_ptr->zbuf); png_free(png_ptr, png_ptr->zbuf);
png_ptr->zbuf=NULL;
png_destroy_struct(png_ptr); png_destroy_struct(png_ptr);
return ((png_structp)NULL); return (NULL);
} }
#ifdef USE_FAR_KEYWORD #ifdef USE_FAR_KEYWORD
png_memcpy(png_ptr->jmpbuf,jmpbuf,sizeof(jmp_buf)); png_memcpy(png_ptr->jmpbuf,jmpbuf,sizeof(jmp_buf));
#endif #endif
#endif
#ifdef PNG_USER_MEM_SUPPORTED #ifdef PNG_USER_MEM_SUPPORTED
png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn); png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
#endif /* PNG_USER_MEM_SUPPORTED */ #endif /* PNG_USER_MEM_SUPPORTED */
png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn); png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
/* Libpng 0.90 and later are binary incompatible with libpng 0.89, so i=0;
* we must recompile any applications that use any older library version. do
* For versions after libpng 1.0, we will be compatible, so we need
* only check the first digit.
*/
if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
(png_libpng_ver[0] == '0' && user_png_ver[2] < '9'))
{ {
png_error(png_ptr, if(user_png_ver[i] != png_libpng_ver[i])
"Incompatible libpng version in application and library"); png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
} while (png_libpng_ver[i++]);
if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
{
/* Libpng 0.90 and later are binary incompatible with libpng 0.89, so
* we must recompile any applications that use any older library version.
* For versions after libpng 1.0, we will be compatible, so we need
* only check the first digit.
*/
if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
(user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
(user_png_ver[0] == '0' && user_png_ver[2] < '9'))
{
#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
char msg[80];
if (user_png_ver)
{
sprintf(msg, "Application was compiled with png.h from libpng-%.20s",
user_png_ver);
png_warning(png_ptr, msg);
}
sprintf(msg, "Application is running with png.c from libpng-%.20s",
png_libpng_ver);
png_warning(png_ptr, msg);
#endif
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
png_ptr->flags=0;
#endif
png_error(png_ptr,
"Incompatible libpng version in application and library");
}
} }
/* initialize zbuf - compression buffer */ /* initialize zbuf - compression buffer */
@@ -464,41 +519,131 @@ png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
(png_uint_32)png_ptr->zbuf_size); (png_uint_32)png_ptr->zbuf_size);
png_set_write_fn(png_ptr, NULL, NULL, NULL); png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL,
png_flush_ptr_NULL);
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT, png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
1, NULL, NULL); 1, png_doublep_NULL, png_doublep_NULL);
#endif #endif
return ((png_structp)png_ptr); return ((png_structp)png_ptr);
} }
/* Initialize png_ptr structure, and allocate any memory needed */ /* Initialize png_ptr structure, and allocate any memory needed */
void #undef png_write_init
void PNGAPI
png_write_init(png_structp png_ptr) png_write_init(png_structp png_ptr)
{ {
jmp_buf tmp_jmp; /* to save current jump buffer */ /* We only come here via pre-1.0.7-compiled applications */
png_write_init_2(png_ptr, "1.0.6 or earlier", 0, 0);
}
png_debug(1, "in png_write_init\n"); #undef png_write_init_2
void PNGAPI
png_write_init_2(png_structp png_ptr, png_const_charp user_png_ver,
png_size_t png_struct_size, png_size_t png_info_size)
{
/* We only come here via pre-1.0.12-compiled applications */
#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
if(sizeof(png_struct) > png_struct_size || sizeof(png_info) > png_info_size)
{
char msg[80];
png_ptr->warning_fn=NULL;
if (user_png_ver)
{
sprintf(msg, "Application was compiled with png.h from libpng-%.20s",
user_png_ver);
png_warning(png_ptr, msg);
}
sprintf(msg, "Application is running with png.c from libpng-%.20s",
png_libpng_ver);
png_warning(png_ptr, msg);
}
#endif
if(sizeof(png_struct) > png_struct_size)
{
png_ptr->error_fn=NULL;
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
png_ptr->flags=0;
#endif
png_error(png_ptr,
"The png struct allocated by the application for writing is too small.");
}
if(sizeof(png_info) > png_info_size)
{
png_ptr->error_fn=NULL;
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
png_ptr->flags=0;
#endif
png_error(png_ptr,
"The info struct allocated by the application for writing is too small.");
}
png_write_init_3(&png_ptr, user_png_ver, png_struct_size);
}
void PNGAPI
png_write_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
png_size_t png_struct_size)
{
png_structp png_ptr=*ptr_ptr;
#ifdef PNG_SETJMP_SUPPORTED
jmp_buf tmp_jmp; /* to save current jump buffer */
#endif
int i = 0;
do
{
if (user_png_ver[i] != png_libpng_ver[i])
{
#ifdef PNG_LEGACY_SUPPORTED
png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
#else
png_ptr->warning_fn=NULL;
png_warning(png_ptr,
"Application uses deprecated png_write_init() and should be recompiled.");
break;
#endif
}
} while (png_libpng_ver[i++]);
png_debug(1, "in png_write_init_3\n");
#ifdef PNG_SETJMP_SUPPORTED
/* save jump buffer and error functions */ /* save jump buffer and error functions */
png_memcpy(tmp_jmp, png_ptr->jmpbuf, sizeof (jmp_buf)); png_memcpy(tmp_jmp, png_ptr->jmpbuf, sizeof (jmp_buf));
#endif
if (sizeof(png_struct) > png_struct_size)
{
png_destroy_struct(png_ptr);
png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
*ptr_ptr = png_ptr;
}
/* reset all variables to 0 */ /* reset all variables to 0 */
png_memset(png_ptr, 0, sizeof (png_struct)); png_memset(png_ptr, 0, sizeof (png_struct));
#ifdef PNG_ASSEMBLER_CODE_SUPPORTED
png_init_mmx_flags(png_ptr); /* 1.2.0 addition */
#endif
#ifdef PNG_SETJMP_SUPPORTED
/* restore jump buffer */ /* restore jump buffer */
png_memcpy(png_ptr->jmpbuf, tmp_jmp, sizeof (jmp_buf)); png_memcpy(png_ptr->jmpbuf, tmp_jmp, sizeof (jmp_buf));
#endif
png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL,
png_flush_ptr_NULL);
/* initialize zbuf - compression buffer */ /* initialize zbuf - compression buffer */
png_ptr->zbuf_size = PNG_ZBUF_SIZE; png_ptr->zbuf_size = PNG_ZBUF_SIZE;
png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
(png_uint_32)png_ptr->zbuf_size); (png_uint_32)png_ptr->zbuf_size);
png_set_write_fn(png_ptr, NULL, NULL, NULL);
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT, png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
1, NULL, NULL); 1, png_doublep_NULL, png_doublep_NULL);
#endif #endif
} }
@@ -507,7 +652,7 @@ png_write_init(png_structp png_ptr)
* have called png_set_interlace_handling(), you will have to * have called png_set_interlace_handling(), you will have to
* "write" the image seven times. * "write" the image seven times.
*/ */
void void PNGAPI
png_write_rows(png_structp png_ptr, png_bytepp row, png_write_rows(png_structp png_ptr, png_bytepp row,
png_uint_32 num_rows) png_uint_32 num_rows)
{ {
@@ -525,7 +670,7 @@ png_write_rows(png_structp png_ptr, png_bytepp row,
/* Write the image. You only need to call this function once, even /* Write the image. You only need to call this function once, even
* if you are writing an interlaced image. * if you are writing an interlaced image.
*/ */
void void PNGAPI
png_write_image(png_structp png_ptr, png_bytepp image) png_write_image(png_structp png_ptr, png_bytepp image)
{ {
png_uint_32 i; /* row index */ png_uint_32 i; /* row index */
@@ -552,7 +697,7 @@ png_write_image(png_structp png_ptr, png_bytepp image)
} }
/* called by user to write a row of image data */ /* called by user to write a row of image data */
void void PNGAPI
png_write_row(png_structp png_ptr, png_bytep row) png_write_row(png_structp png_ptr, png_bytep row)
{ {
png_debug2(1, "in png_write_row (row %ld, pass %d)\n", png_debug2(1, "in png_write_row (row %ld, pass %d)\n",
@@ -560,6 +705,11 @@ png_write_row(png_structp png_ptr, png_bytep row)
/* initialize transformations and other stuff if first time */ /* initialize transformations and other stuff if first time */
if (png_ptr->row_number == 0 && png_ptr->pass == 0) if (png_ptr->row_number == 0 && png_ptr->pass == 0)
{ {
/* make sure we wrote the header info */
if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
png_error(png_ptr,
"png_write_info was never called before png_write_row.");
/* check for transforms that have been set but were defined out */ /* check for transforms that have been set but were defined out */
#if !defined(PNG_WRITE_INVERT_SUPPORTED) && defined(PNG_READ_INVERT_SUPPORTED) #if !defined(PNG_WRITE_INVERT_SUPPORTED) && defined(PNG_READ_INVERT_SUPPORTED)
if (png_ptr->transformations & PNG_INVERT_MONO) if (png_ptr->transformations & PNG_INVERT_MONO)
@@ -664,11 +814,11 @@ png_write_row(png_structp png_ptr, png_bytep row)
(png_uint_32)png_ptr->row_info.pixel_depth + 7) >> 3); (png_uint_32)png_ptr->row_info.pixel_depth + 7) >> 3);
png_debug1(3, "row_info->color_type = %d\n", png_ptr->row_info.color_type); 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->width = %lu\n", png_ptr->row_info.width);
png_debug1(3, "row_info->channels = %d\n", png_ptr->row_info.channels); 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->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->pixel_depth = %d\n", png_ptr->row_info.pixel_depth);
png_debug1(3, "row_info->rowbytes = %d\n", png_ptr->row_info.rowbytes); png_debug1(3, "row_info->rowbytes = %lu\n", png_ptr->row_info.rowbytes);
/* Copy user's row into buffer, leaving room for filter byte. */ /* Copy user's row into buffer, leaving room for filter byte. */
png_memcpy_check(png_ptr, png_ptr->row_buf + 1, row, png_memcpy_check(png_ptr, png_ptr->row_buf + 1, row,
@@ -694,6 +844,24 @@ png_write_row(png_structp png_ptr, png_bytep row)
if (png_ptr->transformations) if (png_ptr->transformations)
png_do_write_transformations(png_ptr); png_do_write_transformations(png_ptr);
#if defined(PNG_MNG_FEATURES_SUPPORTED)
/* Write filter_method 64 (intrapixel differencing) only if
* 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and
* 2. Libpng did not write a PNG signature (this filter_method is only
* used in PNG datastreams that are embedded in MNG datastreams) and
* 3. The application called png_permit_mng_features with a mask that
* included PNG_FLAG_MNG_FILTER_64 and
* 4. The filter_method is 64 and
* 5. The color_type is RGB or RGBA
*/
if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
(png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
{
/* Intrapixel differencing */
png_do_write_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1);
}
#endif
/* Find a filter if necessary, filter the row and write it out. */ /* Find a filter if necessary, filter the row and write it out. */
png_write_find_filter(png_ptr, &(png_ptr->row_info)); png_write_find_filter(png_ptr, &(png_ptr->row_info));
@@ -703,7 +871,7 @@ png_write_row(png_structp png_ptr, png_bytep row)
#if defined(PNG_WRITE_FLUSH_SUPPORTED) #if defined(PNG_WRITE_FLUSH_SUPPORTED)
/* Set the automatic flush interval or 0 to turn flushing off */ /* Set the automatic flush interval or 0 to turn flushing off */
void void PNGAPI
png_set_flush(png_structp png_ptr, int nrows) png_set_flush(png_structp png_ptr, int nrows)
{ {
png_debug(1, "in png_set_flush\n"); png_debug(1, "in png_set_flush\n");
@@ -711,7 +879,7 @@ png_set_flush(png_structp png_ptr, int nrows)
} }
/* flush the current output buffers now */ /* flush the current output buffers now */
void void PNGAPI
png_write_flush(png_structp png_ptr) png_write_flush(png_structp png_ptr)
{ {
int wrote_IDAT; int wrote_IDAT;
@@ -764,13 +932,14 @@ png_write_flush(png_structp png_ptr)
#endif /* PNG_WRITE_FLUSH_SUPPORTED */ #endif /* PNG_WRITE_FLUSH_SUPPORTED */
/* free all memory used by the write */ /* free all memory used by the write */
void void PNGAPI
png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr) png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)
{ {
png_structp png_ptr = NULL; png_structp png_ptr = NULL;
png_infop info_ptr = NULL; png_infop info_ptr = NULL;
#ifdef PNG_USER_MEM_SUPPORTED #ifdef PNG_USER_MEM_SUPPORTED
png_free_ptr free_fn = NULL; png_free_ptr free_fn = NULL;
png_voidp mem_ptr = NULL;
#endif #endif
png_debug(1, "in png_destroy_write_struct\n"); png_debug(1, "in png_destroy_write_struct\n");
@@ -787,58 +956,47 @@ png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)
if (info_ptr != NULL) if (info_ptr != NULL)
{ {
#if defined(PNG_WRITE_TEXT_SUPPORTED) png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
png_free_text(png_ptr, info_ptr, -1);
#endif #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
#if defined(PNG_WRITE_tRNS_SUPPORTED) if (png_ptr->num_chunk_list)
png_free_tRNS(png_ptr, info_ptr); {
#endif png_free(png_ptr, png_ptr->chunk_list);
#if defined(PNG_WRITE_sCAL_SUPPORTED) png_ptr->chunk_list=NULL;
png_free_sCAL(png_ptr, info_ptr); png_ptr->num_chunk_list=0;
#endif }
#if defined(PNG_WRITE_pCAL_SUPPORTED)
png_free_pCAL(png_ptr, info_ptr);
#endif
#if defined(PNG_WRITE_iCCP_SUPPORTED)
png_free_iCCP(png_ptr, info_ptr);
#endif
#if defined(PNG_WRITE_sPLT_SUPPORTED)
png_free_spalettes(png_ptr, info_ptr, -1);
#endif
#if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
png_free_unknown_chunks(png_ptr, info_ptr, -1);
png_free_chunk_list(png_ptr);
#endif
#if defined(PNG_hIST_SUPPORTED)
png_free_hIST(png_ptr, info_ptr);
#endif #endif
#ifdef PNG_USER_MEM_SUPPORTED #ifdef PNG_USER_MEM_SUPPORTED
png_destroy_struct_2((png_voidp)info_ptr, free_fn); png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn,
(png_voidp)mem_ptr);
#else #else
png_destroy_struct((png_voidp)info_ptr); png_destroy_struct((png_voidp)info_ptr);
#endif #endif
*info_ptr_ptr = (png_infop)NULL; *info_ptr_ptr = NULL;
} }
if (png_ptr != NULL) if (png_ptr != NULL)
{ {
png_write_destroy(png_ptr); png_write_destroy(png_ptr);
#ifdef PNG_USER_MEM_SUPPORTED #ifdef PNG_USER_MEM_SUPPORTED
png_destroy_struct_2((png_voidp)png_ptr, free_fn); png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn,
(png_voidp)mem_ptr);
#else #else
png_destroy_struct((png_voidp)png_ptr); png_destroy_struct((png_voidp)png_ptr);
#endif #endif
*png_ptr_ptr = (png_structp)NULL; *png_ptr_ptr = NULL;
} }
} }
/* Free any memory used in png_ptr struct (old method) */ /* Free any memory used in png_ptr struct (old method) */
void void /* PRIVATE */
png_write_destroy(png_structp png_ptr) png_write_destroy(png_structp png_ptr)
{ {
#ifdef PNG_SETJMP_SUPPORTED
jmp_buf tmp_jmp; /* save jump buffer */ jmp_buf tmp_jmp; /* save jump buffer */
#endif
png_error_ptr error_fn; png_error_ptr error_fn;
png_error_ptr warning_fn; png_error_ptr warning_fn;
png_voidp error_ptr; png_voidp error_ptr;
@@ -871,8 +1029,10 @@ png_write_destroy(png_structp png_ptr)
png_free(png_ptr, png_ptr->inv_filter_costs); png_free(png_ptr, png_ptr->inv_filter_costs);
#endif #endif
#ifdef PNG_SETJMP_SUPPORTED
/* reset structure */ /* reset structure */
png_memcpy(tmp_jmp, png_ptr->jmpbuf, sizeof (jmp_buf)); png_memcpy(tmp_jmp, png_ptr->jmpbuf, sizeof (jmp_buf));
#endif
error_fn = png_ptr->error_fn; error_fn = png_ptr->error_fn;
warning_fn = png_ptr->warning_fn; warning_fn = png_ptr->warning_fn;
@@ -890,15 +1050,21 @@ png_write_destroy(png_structp png_ptr)
png_ptr->free_fn = free_fn; png_ptr->free_fn = free_fn;
#endif #endif
#ifdef PNG_SETJMP_SUPPORTED
png_memcpy(png_ptr->jmpbuf, tmp_jmp, sizeof (jmp_buf)); png_memcpy(png_ptr->jmpbuf, tmp_jmp, sizeof (jmp_buf));
#endif
} }
/* Allow the application to select one or more row filters to use. */ /* Allow the application to select one or more row filters to use. */
void void PNGAPI
png_set_filter(png_structp png_ptr, int method, int filters) png_set_filter(png_structp png_ptr, int method, int filters)
{ {
png_debug(1, "in png_set_filter\n"); png_debug(1, "in png_set_filter\n");
/* We allow 'method' only for future expansion of the base filter method. */ #if defined(PNG_MNG_FEATURES_SUPPORTED)
if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
(method == PNG_INTRAPIXEL_DIFFERENCING))
method = PNG_FILTER_TYPE_BASE;
#endif
if (method == PNG_FILTER_TYPE_BASE) if (method == PNG_FILTER_TYPE_BASE)
{ {
switch (filters & (PNG_ALL_FILTERS | 0x07)) switch (filters & (PNG_ALL_FILTERS | 0x07))
@@ -994,7 +1160,7 @@ png_set_filter(png_structp png_ptr, int method, int filters)
* better compression. * better compression.
*/ */
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* GRR 970116 */ #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* GRR 970116 */
void void PNGAPI
png_set_filter_heuristics(png_structp png_ptr, int heuristic_method, png_set_filter_heuristics(png_structp png_ptr, int heuristic_method,
int num_weights, png_doublep filter_weights, int num_weights, png_doublep filter_weights,
png_doublep filter_costs) png_doublep filter_costs)
@@ -1038,12 +1204,11 @@ png_set_filter_heuristics(png_structp png_ptr, int heuristic_method,
if (png_ptr->filter_weights == NULL) if (png_ptr->filter_weights == NULL)
{ {
png_ptr->filter_weights = (png_uint_16p) png_malloc(png_ptr, png_ptr->filter_weights = (png_uint_16p)png_malloc(png_ptr,
(png_uint_32)(sizeof(png_uint_16) * num_weights)); (png_uint_32)(sizeof(png_uint_16) * num_weights));
png_ptr->inv_filter_weights = (png_uint_16p) png_malloc(png_ptr, png_ptr->inv_filter_weights = (png_uint_16p)png_malloc(png_ptr,
(png_uint_32)(sizeof(png_uint_16) * num_weights)); (png_uint_32)(sizeof(png_uint_16) * num_weights));
for (i = 0; i < num_weights; i++) for (i = 0; i < num_weights; i++)
{ {
png_ptr->inv_filter_weights[i] = png_ptr->inv_filter_weights[i] =
@@ -1073,10 +1238,10 @@ png_set_filter_heuristics(png_structp png_ptr, int heuristic_method,
*/ */
if (png_ptr->filter_costs == NULL) if (png_ptr->filter_costs == NULL)
{ {
png_ptr->filter_costs = (png_uint_16p) png_malloc(png_ptr, png_ptr->filter_costs = (png_uint_16p)png_malloc(png_ptr,
(png_uint_32)(sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST)); (png_uint_32)(sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
png_ptr->inv_filter_costs = (png_uint_16p) png_malloc(png_ptr, png_ptr->inv_filter_costs = (png_uint_16p)png_malloc(png_ptr,
(png_uint_32)(sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST)); (png_uint_32)(sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
for (i = 0; i < PNG_FILTER_VALUE_LAST; i++) for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
@@ -1111,7 +1276,7 @@ png_set_filter_heuristics(png_structp png_ptr, int heuristic_method,
} }
#endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */ #endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
void void PNGAPI
png_set_compression_level(png_structp png_ptr, int level) png_set_compression_level(png_structp png_ptr, int level)
{ {
png_debug(1, "in png_set_compression_level\n"); png_debug(1, "in png_set_compression_level\n");
@@ -1119,7 +1284,7 @@ png_set_compression_level(png_structp png_ptr, int level)
png_ptr->zlib_level = level; png_ptr->zlib_level = level;
} }
void void PNGAPI
png_set_compression_mem_level(png_structp png_ptr, int mem_level) png_set_compression_mem_level(png_structp png_ptr, int mem_level)
{ {
png_debug(1, "in png_set_compression_mem_level\n"); png_debug(1, "in png_set_compression_mem_level\n");
@@ -1127,7 +1292,7 @@ png_set_compression_mem_level(png_structp png_ptr, int mem_level)
png_ptr->zlib_mem_level = mem_level; png_ptr->zlib_mem_level = mem_level;
} }
void void PNGAPI
png_set_compression_strategy(png_structp png_ptr, int strategy) png_set_compression_strategy(png_structp png_ptr, int strategy)
{ {
png_debug(1, "in png_set_compression_strategy\n"); png_debug(1, "in png_set_compression_strategy\n");
@@ -1135,7 +1300,7 @@ png_set_compression_strategy(png_structp png_ptr, int strategy)
png_ptr->zlib_strategy = strategy; png_ptr->zlib_strategy = strategy;
} }
void void PNGAPI
png_set_compression_window_bits(png_structp png_ptr, int window_bits) png_set_compression_window_bits(png_structp png_ptr, int window_bits)
{ {
if (window_bits > 15) if (window_bits > 15)
@@ -1154,7 +1319,7 @@ png_set_compression_window_bits(png_structp png_ptr, int window_bits)
png_ptr->zlib_window_bits = window_bits; png_ptr->zlib_window_bits = window_bits;
} }
void void PNGAPI
png_set_compression_method(png_structp png_ptr, int method) png_set_compression_method(png_structp png_ptr, int method)
{ {
png_debug(1, "in png_set_compression_method\n"); png_debug(1, "in png_set_compression_method\n");
@@ -1164,14 +1329,14 @@ png_set_compression_method(png_structp png_ptr, int method)
png_ptr->zlib_method = method; png_ptr->zlib_method = method;
} }
void void PNGAPI
png_set_write_status_fn(png_structp png_ptr, png_write_status_ptr write_row_fn) png_set_write_status_fn(png_structp png_ptr, png_write_status_ptr write_row_fn)
{ {
png_ptr->write_row_fn = write_row_fn; png_ptr->write_row_fn = write_row_fn;
} }
#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
void void PNGAPI
png_set_write_user_transform_fn(png_structp png_ptr, png_user_transform_ptr png_set_write_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
write_user_transform_fn) write_user_transform_fn)
{ {
@@ -1180,3 +1345,88 @@ png_set_write_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
png_ptr->write_user_transform_fn = write_user_transform_fn; png_ptr->write_user_transform_fn = write_user_transform_fn;
} }
#endif #endif
#if defined(PNG_INFO_IMAGE_SUPPORTED)
void PNGAPI
png_write_png(png_structp png_ptr, png_infop info_ptr,
int transforms, voidp params)
{
#if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
/* invert the alpha channel from opacity to transparency */
if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
png_set_invert_alpha(png_ptr);
#endif
/* Write the file header information. */
png_write_info(png_ptr, info_ptr);
/* ------ these transformations don't touch the info structure ------- */
#if defined(PNG_WRITE_INVERT_SUPPORTED)
/* invert monochrome pixels */
if (transforms & PNG_TRANSFORM_INVERT_MONO)
png_set_invert_mono(png_ptr);
#endif
#if defined(PNG_WRITE_SHIFT_SUPPORTED)
/* Shift the pixels up to a legal bit depth and fill in
* as appropriate to correctly scale the image.
*/
if ((transforms & PNG_TRANSFORM_SHIFT)
&& (info_ptr->valid & PNG_INFO_sBIT))
png_set_shift(png_ptr, &info_ptr->sig_bit);
#endif
#if defined(PNG_WRITE_PACK_SUPPORTED)
/* pack pixels into bytes */
if (transforms & PNG_TRANSFORM_PACKING)
png_set_packing(png_ptr);
#endif
#if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
/* swap location of alpha bytes from ARGB to RGBA */
if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
png_set_swap_alpha(png_ptr);
#endif
#if defined(PNG_WRITE_FILLER_SUPPORTED)
/* Get rid of filler (OR ALPHA) bytes, pack XRGB/RGBX/ARGB/RGBA into
* RGB (4 channels -> 3 channels). The second parameter is not used.
*/
if (transforms & PNG_TRANSFORM_STRIP_FILLER)
png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
#endif
#if defined(PNG_WRITE_BGR_SUPPORTED)
/* flip BGR pixels to RGB */
if (transforms & PNG_TRANSFORM_BGR)
png_set_bgr(png_ptr);
#endif
#if defined(PNG_WRITE_SWAP_SUPPORTED)
/* swap bytes of 16-bit files to most significant byte first */
if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
png_set_swap(png_ptr);
#endif
#if defined(PNG_WRITE_PACKSWAP_SUPPORTED)
/* swap bits of 1, 2, 4 bit packed pixel formats */
if (transforms & PNG_TRANSFORM_PACKSWAP)
png_set_packswap(png_ptr);
#endif
/* ----------------------- end of transformations ------------------- */
/* write the bits */
if (info_ptr->valid & PNG_INFO_IDAT)
png_write_image(png_ptr, info_ptr->row_pointers);
/* It is REQUIRED to call this to finish writing the rest of the file */
png_write_end(png_ptr, info_ptr);
if(transforms == 0 || params == NULL)
/* quiet compiler warnings */ return;
}
#endif
#endif /* PNG_WRITE_SUPPORTED */

View File

@@ -1,20 +1,21 @@
/* pngwtran.c - transforms the data in a row for PNG writers /* pngwtran.c - transforms the data in a row for PNG writers
* *
* libpng 1.0.5k - December 27, 1999 * libpng 1.2.1 - December 12, 2001
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. * Copyright (c) 1998-2001 Glenn Randers-Pehrson
* Copyright (c) 1996, 1997 Andreas Dilger * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*/ */
#define PNG_INTERNAL #define PNG_INTERNAL
#include "png.h" #include "png.h"
#ifdef PNG_WRITE_SUPPORTED
/* Transform the data according to the user's wishes. The order of /* Transform the data according to the user's wishes. The order of
* transformations is significant. * transformations is significant.
*/ */
void void /* PRIVATE */
png_do_write_transformations(png_structp png_ptr) png_do_write_transformations(png_structp png_ptr)
{ {
png_debug(1, "in png_do_write_transformations\n"); png_debug(1, "in png_do_write_transformations\n");
@@ -82,7 +83,7 @@ png_do_write_transformations(png_structp png_ptr)
* row_info bit depth should be 8 (one pixel per byte). The channels * row_info bit depth should be 8 (one pixel per byte). The channels
* should be 1 (this only happens on grayscale and paletted images). * should be 1 (this only happens on grayscale and paletted images).
*/ */
void void /* PRIVATE */
png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth) png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth)
{ {
png_debug(1, "in png_do_pack\n"); png_debug(1, "in png_do_pack\n");
@@ -208,7 +209,7 @@ png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth)
* would pass 3 as bit_depth, and this routine would translate the * would pass 3 as bit_depth, and this routine would translate the
* data to 0 to 15. * data to 0 to 15.
*/ */
void void /* PRIVATE */
png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth) png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
{ {
png_debug(1, "in png_do_shift\n"); png_debug(1, "in png_do_shift\n");
@@ -332,7 +333,7 @@ png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
#endif #endif
#if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED) #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
void void /* PRIVATE */
png_do_write_swap_alpha(png_row_infop row_info, png_bytep row) png_do_write_swap_alpha(png_row_infop row_info, png_bytep row)
{ {
png_debug(1, "in png_do_write_swap_alpha\n"); png_debug(1, "in png_do_write_swap_alpha\n");
@@ -420,7 +421,7 @@ png_do_write_swap_alpha(png_row_infop row_info, png_bytep row)
#endif #endif
#if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED) #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
void void /* PRIVATE */
png_do_write_invert_alpha(png_row_infop row_info, png_bytep row) png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
{ {
png_debug(1, "in png_do_write_invert_alpha\n"); png_debug(1, "in png_do_write_invert_alpha\n");
@@ -498,3 +499,65 @@ png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
} }
} }
#endif #endif
#if defined(PNG_MNG_FEATURES_SUPPORTED)
/* undoes intrapixel differencing */
void /* PRIVATE */
png_do_write_intrapixel(png_row_infop row_info, png_bytep row)
{
png_debug(1, "in png_do_write_intrapixel\n");
if (
#if defined(PNG_USELESS_TESTS_SUPPORTED)
row != NULL && row_info != NULL &&
#endif
(row_info->color_type & PNG_COLOR_MASK_COLOR))
{
int bytes_per_pixel;
png_uint_32 row_width = row_info->width;
if (row_info->bit_depth == 8)
{
png_bytep rp;
png_uint_32 i;
if (row_info->color_type == PNG_COLOR_TYPE_RGB)
bytes_per_pixel = 3;
else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
bytes_per_pixel = 4;
else
return;
for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
{
*(rp) = (png_byte)((*rp - *(rp+1))&0xff);
*(rp+2) = (png_byte)((*(rp+2) - *(rp+1))&0xff);
}
}
else if (row_info->bit_depth == 16)
{
png_bytep rp;
png_uint_32 i;
if (row_info->color_type == PNG_COLOR_TYPE_RGB)
bytes_per_pixel = 6;
else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
bytes_per_pixel = 8;
else
return;
for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
{
png_uint_32 s0=*(rp )<<8 | *(rp+1);
png_uint_32 s1=*(rp+2)<<8 | *(rp+3);
png_uint_32 s2=*(rp+4)<<8 | *(rp+5);
png_uint_32 red=(s0-s1)&0xffff;
png_uint_32 blue=(s2-s1)&0xffff;
*(rp ) = (png_byte)((red>>8)&0xff);
*(rp+1) = (png_byte)(red&0xff);
*(rp+4) = (png_byte)((blue>>8)&0xff);
*(rp+5) = (png_byte)(blue&0xff);
}
}
}
}
#endif /* PNG_MNG_FEATURES_SUPPORTED */
#endif /* PNG_WRITE_SUPPORTED */

File diff suppressed because it is too large Load Diff

18
zlib.h
View File

@@ -1,5 +1,5 @@
/* zlib.h -- interface of the 'zlib' general purpose compression library /* zlib.h -- interface of the 'zlib' general purpose compression library
version 1.1.3, July 9th, 1998 version 1.1.3pc, May 2000
Copyright (C) 1995-1998 Jean-loup Gailly and Mark Adler Copyright (C) 1995-1998 Jean-loup Gailly and Mark Adler
@@ -28,6 +28,20 @@
(zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format). (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
*/ */
/* Changes from version 1.1.3 to version 1.1.3pc
*
* The default value of TOO_FAR has been changed to 32767 in deflate.c
* Glenn Randers-Pehrson, February 2000.
*
* The switch statement in inflate.c was rearranged so that case BLOCKS is
* checked first. Glenn Randers-Pehrson, April 2001.
*
* Added tests for Windows platforms at line 136 in zutil.h, since some
* emulators will use MSC compiler on other platforms. Glenn Randers-Pehrson,
* May 2001. Suggested by Emmanuel Blot.
*
*/
#ifndef _ZLIB_H #ifndef _ZLIB_H
#define _ZLIB_H #define _ZLIB_H
@@ -37,7 +51,7 @@
extern "C" { extern "C" {
#endif #endif
#define ZLIB_VERSION "1.1.3" #define ZLIB_VERSION "1.1.3pc"
/* /*
The 'zlib' compression library provides in-memory compression and The 'zlib' compression library provides in-memory compression and

11
zutil.c
View File

@@ -202,6 +202,7 @@ void zcfree (voidpf opaque, voidpf ptr)
#ifndef STDC #ifndef STDC
extern voidp calloc OF((uInt items, uInt size)); extern voidp calloc OF((uInt items, uInt size));
extern voidp malloc OF((uInt items));
extern void free OF((voidpf ptr)); extern void free OF((voidpf ptr));
#endif #endif
@@ -214,6 +215,16 @@ voidpf zcalloc (opaque, items, size)
return (voidpf)calloc(items, size); return (voidpf)calloc(items, size);
} }
/* added to version 1.1.3pc -- glennrp */
voidpf zmalloc (opaque, items, size)
voidpf opaque;
unsigned items;
unsigned size;
{
if (opaque) items += size - size; /* make compiler happy */
return (voidpf)malloc(items * size);
}
void zcfree (opaque, ptr) void zcfree (opaque, ptr)
voidpf opaque; voidpf opaque;
voidpf ptr; voidpf ptr;

View File

@@ -8,6 +8,8 @@
subject to change. Applications should only use zlib.h. subject to change. Applications should only use zlib.h.
*/ */
/* Added tests for Windows platforms at line 136. glennrp, May 2001 */
/* @(#) $Id$ */ /* @(#) $Id$ */
#ifndef _Z_UTIL_H #ifndef _Z_UTIL_H
@@ -133,7 +135,9 @@ extern const char *z_errmsg[10]; /* indexed by 2-zlib_error */
# define fdopen(fd,mode) NULL /* No fdopen() */ # define fdopen(fd,mode) NULL /* No fdopen() */
#endif #endif
#if (defined(_MSC_VER) && (_MSC_VER > 600)) #if (defined(_MSC_VER) && (_MSC_VER > 600)) && (defined(WIN32) || \
defined(_Windows) || defined(_WINDOWS) || defined(_WIN32) || \
defined(__WIN32__))
# define fdopen(fd,type) _fdopen(fd,type) # define fdopen(fd,type) _fdopen(fd,type)
#endif #endif