Imported from libpng-0.87.tar
This commit is contained in:
parent
69b1448f19
commit
4ee97b0891
74
libpng.txt
74
libpng.txt
@ -1,9 +1,9 @@
|
||||
libpng.txt - a description on how to use and modify libpng
|
||||
|
||||
libpng 1.0 beta 2 - version 0.86
|
||||
libpng 1.0 beta 2 - version 0.87
|
||||
For conditions of distribution and use, see copyright notice in png.h
|
||||
Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
January 10, 1996
|
||||
January 15, 1996
|
||||
Updated/rewritten per request in the libpng FAQ
|
||||
Copyright (c) 1995 Frank J. T. Wojcik
|
||||
December 18, 1995
|
||||
@ -13,7 +13,7 @@ I. Introduction
|
||||
This file describes how to use and modify the PNG reference library
|
||||
(known as libpng) for your own use. There are five sections to this
|
||||
file: introduction, structures, reading, writing, and modification and
|
||||
configuration notes for various special platforms. Other then this
|
||||
configuration notes for various special platforms. In addition to this
|
||||
file, example.c is a good starting point for using the library, as
|
||||
it is heavily commented and should include everything most people
|
||||
will need.
|
||||
@ -22,7 +22,7 @@ Libpng was written as a companion to the PNG specification, as a
|
||||
way to reduce the amount of time and effort it takes to support
|
||||
the PNG file format in application programs. Most users will not
|
||||
have to modify the library significantly; advanced users may want
|
||||
to modify it more. The library was coded for both kind of users.
|
||||
to modify it more. The library was coded for both kinds of users.
|
||||
All attempts were made to make it as complete as possible, while
|
||||
keeping the code easy to understand. Currently, this library
|
||||
only supports C. Support for other languages is being considered.
|
||||
@ -37,9 +37,15 @@ majority of the needs of it's users.
|
||||
|
||||
Libpng uses zlib for its compression and decompression of PNG files.
|
||||
The zlib compression utility is a general purpose utility that is
|
||||
useful for more then PNG files, and can be used without libpng.
|
||||
useful for more than PNG files, and can be used without libpng.
|
||||
See the documentation delivered with zlib for more details.
|
||||
|
||||
Libpng is thread safe provided the threads are using different
|
||||
instances of the structures. Each thread should have its own
|
||||
png_struct and png_info instances, and thus its own image.
|
||||
Libpng does not protect itself against two threads using the
|
||||
same instance of a structure.
|
||||
|
||||
|
||||
|
||||
II. Structures
|
||||
@ -287,8 +293,8 @@ PNG can have files with 16 bits per channel. If you only can handle
|
||||
if (info_ptr->bit_depth == 16)
|
||||
png_set_strip_16(png_ptr);
|
||||
|
||||
If you need to reduce an rgb file to a paletted file (perhaps because
|
||||
a paletted file has more entries then will fit on your screen)
|
||||
If you need to reduce an rgb file to a paletted file, or if a
|
||||
paletted file has more entries then will fit on your screen,
|
||||
png_set_dither() will do that. Note that this is a simple match
|
||||
dither, that merely finds the closest color available. This should
|
||||
work fairly well with optimized palettes, and fairly badly with linear
|
||||
@ -799,7 +805,7 @@ time_t routine uses gmtime(). You don't have to use either of
|
||||
these, but if you wish to fill in the png_time structure directly,
|
||||
you should provide the time in universal time (GMT) if possible
|
||||
instead of your local time. Note that the year number is the full
|
||||
year (ie 1996, rather than 96)
|
||||
year (ie 1996, rather than 96).
|
||||
|
||||
It is possible to have libpng flush any pending output, either manually,
|
||||
or automatically after a certain number of lines have been written. To
|
||||
@ -1024,8 +1030,9 @@ The replacement I/O functions should have prototypes as follows:
|
||||
png_uint_32 length);
|
||||
void user_flush_data(png_structp png_ptr);
|
||||
|
||||
Note that you can pass NULL for the flush function if you are not doing
|
||||
flushing of the output data.
|
||||
Supplying NULL for the read, write, or flush functions sets them back
|
||||
to using the default C stream functions. It is an error to read from
|
||||
a write stream, and vice versa.
|
||||
|
||||
Error handling in libpng is done through png_error() and png_warning().
|
||||
Errors handled through png_error() are fatal, meaning that png_error()
|
||||
@ -1073,13 +1080,19 @@ itself.
|
||||
|
||||
Configuring for 16 bit platforms:
|
||||
|
||||
You will probably need to change the png_large_malloc() and
|
||||
You may need to change the png_large_malloc() and
|
||||
png_large_free() routines in pngmem.c, as these are requred
|
||||
to allocate 64K. Also, you will want to look into zconf.h to tell
|
||||
zlib (and thus libpng) that it cannot allocate more then 64K at a
|
||||
time. Even if you can, the memory won't be accessable. So limit zlib
|
||||
and libpng to 64K by defining MAXSEG_64K.
|
||||
|
||||
Configuring for DOS:
|
||||
|
||||
For DOS users which only have access to the lower 640K, you will
|
||||
have to limit zlib's memory usage via a png_set_compression_mem_level()
|
||||
call. See zlib.h or zconf.h in the zlib library for more information.
|
||||
|
||||
Configuring for Medium Model:
|
||||
|
||||
Libpng's support for medium model has been tested on most of the popular
|
||||
@ -1089,7 +1102,7 @@ all set. Everything in the library (except for zlib's structure) is
|
||||
expecting far data. You must use the typedefs with the p or pp on
|
||||
the end for pointers (or at least look at them and be careful). Make
|
||||
note that the row's of data are defined as png_bytepp which is a
|
||||
unsigned char far * far *
|
||||
unsigned char far * far *.
|
||||
|
||||
Configuring for gui/windowing platforms:
|
||||
|
||||
@ -1099,14 +1112,47 @@ You may want to write a single function to do this and call it something
|
||||
like png_message(). On some compliers, you may have to change the
|
||||
memory allocators (png_malloc, etc.).
|
||||
|
||||
|
||||
Configuring for compiler xxx:
|
||||
|
||||
All includes for libpng are in pngconf.h. If you need to add/change/delete
|
||||
an include, this is the place to do it. The includes that are not
|
||||
needed outside libpng are protected by the PNG_INTERNAL definition,
|
||||
which is only defined for those routines inside libpng itself. The
|
||||
files in libpng proper only include png.h.
|
||||
files in libpng proper only include png.h, which includes pngconf.h.
|
||||
|
||||
Configuring zlib:
|
||||
|
||||
There are special functions to configure the compression. Perhaps
|
||||
the most useful one changes the compression level. The library
|
||||
normally uses the default compression level, but for maximum
|
||||
compression (9) or maximum speed (1), you may desire to change the
|
||||
level. You do this by calling:
|
||||
|
||||
png_set_compression_mem_level(png_ptr, level);
|
||||
|
||||
Another useful one is to reduce the memory level used by the library.
|
||||
The memory level defaults to 8, but it can be lowered if you are
|
||||
short on memory (running DOS, for example, where you only have 640K).
|
||||
|
||||
png_set_compression_mem_level(png_ptr, level);
|
||||
|
||||
If you want to control whether libpng uses filtering or not, you
|
||||
can call this function. I recommend not changing the default unless
|
||||
you are experimenting with compression ratios.
|
||||
|
||||
png_set_filtering(png_ptr, use_filter);
|
||||
|
||||
The other functions are for configuring zlib. They are not recommended
|
||||
for normal use and may result in writing an invalid png file. See
|
||||
zlib.h for more information on what these mean.
|
||||
|
||||
png_set_compression_strategy(png_ptr, strategy);
|
||||
png_set_compression_window_bits(png_ptr, window_bits);
|
||||
png_set_compression_method(png_ptr, method);
|
||||
|
||||
Except for png_set_filtering(), all of these are just controlling
|
||||
zlib, so see the zlib documentation (zlib.h and zconf.h) for more
|
||||
information.
|
||||
|
||||
Removing unwanted object code:
|
||||
|
||||
|
73
makefile.elf
Normal file
73
makefile.elf
Normal file
@ -0,0 +1,73 @@
|
||||
# makefile for libpng on (linux) ELF
|
||||
# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc.
|
||||
# For conditions of distribution and use, see copyright notice in png.h
|
||||
|
||||
CC=gcc
|
||||
CFLAGS=-I../zlib -O2 -Wall -fPIC
|
||||
LDFLAGS=-L. -L../zlib/ -lpng -lz -lm
|
||||
|
||||
RANLIB=ranlib
|
||||
#RANLIB=echo
|
||||
|
||||
PNGVER = 0.87
|
||||
|
||||
# where make install puts libpng.a, libpng.so*, and png.h
|
||||
prefix=/usr/local
|
||||
|
||||
OBJS = png.o pngrcb.o pngrutil.o pngtrans.o pngwutil.o \
|
||||
pngread.o pngio.o pngwrite.o pngrtran.o pngwtran.o \
|
||||
pngmem.o pngerror.o pngpread.o
|
||||
|
||||
all: libpng.so pngtest
|
||||
|
||||
libpng.a: $(OBJS)
|
||||
ar rc $@ $(OBJS)
|
||||
$(RANLIB) $@
|
||||
|
||||
libpng.so: libpng.so.1
|
||||
ln -sf libpng.so.1 libpng.so
|
||||
|
||||
libpng.so.1: libpng.so.1.$(PNGVER)
|
||||
ln -sf libpng.so.1.$(PNGVER) libpng.so.1
|
||||
|
||||
libpng.so.1.$(PNGVER): $(OBJS)
|
||||
gcc -shared -Wl,-soname,libpng.so.1 -o libpng.so.1.$(PNGVER) $(OBJS)
|
||||
|
||||
pngtest: pngtest.o libpng.so
|
||||
$(CC) -o pngtest $(CCFLAGS) pngtest.o $(LDFLAGS)
|
||||
|
||||
test: pngtest
|
||||
./pngtest
|
||||
|
||||
install: libpng.so.1.$(PNGVER)
|
||||
-@mkdir $(prefix)/include
|
||||
-@mkdir $(prefix)/lib
|
||||
cp png.h $(prefix)/include
|
||||
cp pngconf.h $(prefix)/include
|
||||
chmod 644 $(prefix)/include/png.h
|
||||
chmod 644 $(prefix)/include/pngconf.h
|
||||
cp libpng.so.1.$(PNGVER) $(prefix)/lib
|
||||
chmod 755 $(prefix)/lib/libpng.so.1.$(PNGVER)
|
||||
-@/bin/rm $(prefix)/lib/libpng.so.1 $(prefix)/lib/libpng.so
|
||||
(cd $(prefix)/lib; ln -sf libpng.so.1.$(PNGVER) libpng.so.1; \
|
||||
ln -sf libpng.so.1 libpng.so)
|
||||
|
||||
clean:
|
||||
rm -f *.o libpng.so.1.$(PNGVER) libpng.so.1 libpng.so pngtest pngout.png
|
||||
|
||||
# DO NOT DELETE THIS LINE -- make depend depends on it.
|
||||
|
||||
png.o: png.h pngconf.h
|
||||
pngerror.o: png.h pngconf.h
|
||||
pngio.o: png.h pngconf.h
|
||||
pngmem.o: png.h pngconf.h
|
||||
pngrcb.o: png.h pngconf.h
|
||||
pngread.o: png.h pngconf.h
|
||||
pngrtran.o: png.h pngconf.h
|
||||
pngrutil.o: png.h pngconf.h
|
||||
pngtest.o: png.h pngconf.h
|
||||
pngtrans.o: png.h pngconf.h
|
||||
pngwrite.o: png.h pngconf.h
|
||||
pngwtran.o: png.h pngconf.h
|
||||
pngwutil.o: png.h pngconf.h
|
||||
pngpread.o: png.h pngconf.h
|
@ -2,15 +2,15 @@
|
||||
# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc.
|
||||
# For conditions of distribution and use, see copyright notice in png.h
|
||||
|
||||
CC=cc
|
||||
CFLAGS=-I../zlib -O
|
||||
CC=gcc
|
||||
CFLAGS=-I../zlib -O2 -Wall
|
||||
LDFLAGS=-L. -L../zlib/ -lpng -lz -lm
|
||||
|
||||
#RANLIB=ranlib
|
||||
RANLIB=echo
|
||||
RANLIB=ranlib
|
||||
#RANLIB=echo
|
||||
|
||||
# where make install puts libpng.a and png.h
|
||||
prefix=/usr/local
|
||||
prefix=/home/munet-d2/sun/local
|
||||
|
||||
OBJS = png.o pngrcb.o pngrutil.o pngtrans.o pngwutil.o \
|
||||
pngread.o pngio.o pngwrite.o pngrtran.o pngwtran.o \
|
||||
@ -31,11 +31,12 @@ test: pngtest
|
||||
install: libpng.a
|
||||
-@mkdir $(prefix)/include
|
||||
-@mkdir $(prefix)/lib
|
||||
cp png.h $(prefix)/include
|
||||
cp pngconf.h $(prefix)/include
|
||||
cp png.h pngconf.h $(prefix)/include
|
||||
rcp png.h pngconf.h vlsi:bin/include
|
||||
chmod 644 $(prefix)/include/png.h
|
||||
chmod 644 $(prefix)/include/pngconf.h
|
||||
cp libpng.a $(prefix)/lib
|
||||
rcp libpng.a vlsi:bin/lib
|
||||
chmod 644 $(prefix)/lib/libpng.a
|
||||
|
||||
clean:
|
||||
@ -57,3 +58,4 @@ pngwrite.o: png.h pngconf.h
|
||||
pngwtran.o: png.h pngconf.h
|
||||
pngwutil.o: png.h pngconf.h
|
||||
pngpread.o: png.h pngconf.h
|
||||
|
27
png.c
27
png.c
@ -1,10 +1,10 @@
|
||||
|
||||
/* png.c - location for general purpose png functions
|
||||
|
||||
libpng 1.0 beta 2 - version 0.86
|
||||
libpng 1.0 beta 2 - version 0.87
|
||||
For conditions of distribution and use, see copyright notice in png.h
|
||||
Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
January 10, 1996
|
||||
January 15, 1996
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
@ -13,7 +13,7 @@
|
||||
|
||||
/* version information for c files. This better match the version
|
||||
string defined in png.h */
|
||||
char FARDATA png_libpng_ver[] = "0.86";
|
||||
char png_libpng_ver[] = "0.87";
|
||||
|
||||
/* place to hold the signiture string for a png file. */
|
||||
png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
|
||||
@ -107,11 +107,22 @@ png_check_sig(png_bytep sig, int num)
|
||||
voidpf
|
||||
png_zalloc(voidpf png_ptr, uInt items, uInt size)
|
||||
{
|
||||
voidp ptr;
|
||||
png_voidp ptr;
|
||||
png_uint_32 num_bytes;
|
||||
|
||||
ptr = ((voidp)png_large_malloc((png_structp)png_ptr,
|
||||
(png_uint_32)items * (png_uint_32)size));
|
||||
png_memset(ptr, 0, (png_uint_32)items * (png_uint_32)size);
|
||||
ptr = png_large_malloc((png_structp)png_ptr,
|
||||
(png_uint_32)items * (png_uint_32)size);
|
||||
num_bytes = (png_uint_32)items * (png_uint_32)size;
|
||||
if (num_bytes > (png_uint_32)0x7fff)
|
||||
{
|
||||
png_memset(ptr, 0, (png_size_t)0x8000L);
|
||||
png_memset((png_bytep)ptr + (png_size_t)0x8000L, 0,
|
||||
(png_size_t)(num_bytes - (png_uint_32)0x8000L));
|
||||
}
|
||||
else
|
||||
{
|
||||
png_memset(ptr, 0, (png_size_t)num_bytes);
|
||||
}
|
||||
return (voidpf)(ptr);
|
||||
}
|
||||
|
||||
@ -119,7 +130,7 @@ png_zalloc(voidpf png_ptr, uInt items, uInt size)
|
||||
void
|
||||
png_zfree(voidpf png_ptr, voidpf ptr)
|
||||
{
|
||||
png_large_free((png_structp)png_ptr, (voidp)ptr);
|
||||
png_large_free((png_structp)png_ptr, (png_voidp)ptr);
|
||||
}
|
||||
|
||||
/* reset the crc variable to 32 bits of 1's. Care must be taken
|
||||
|
@ -65,5 +65,8 @@ version 0.85
|
||||
version 0.86
|
||||
fixed bugs
|
||||
improved documentation
|
||||
|
||||
version 0.87
|
||||
fixed medium model bugs
|
||||
fixed other bugs introduced in 0.85 and 0.86
|
||||
added some minor documentation
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
|
||||
/* pngconf.c - machine configurable file for libpng
|
||||
|
||||
libpng 1.0 beta 2 - version 0.86
|
||||
libpng 1.0 beta 2 - version 0.87
|
||||
For conditions of distribution and use, see copyright notice in png.h
|
||||
Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
January 10, 1996
|
||||
January 15, 1996
|
||||
*/
|
||||
|
||||
/* Any machine specific code is near the front of this file, so if you
|
||||
@ -27,7 +27,7 @@
|
||||
Unless this gets smaller then the size of a row (compressed),
|
||||
it should not make much difference how big this is. */
|
||||
|
||||
#define PNG_ZBUF_SIZE 8192
|
||||
#define PNG_ZBUF_SIZE 32768
|
||||
|
||||
/* While libpng currently uses zlib for it's compression, it has been designed
|
||||
to stand on it's own. Towards this end, there are two defines that are
|
||||
|
@ -1,10 +1,10 @@
|
||||
|
||||
/* pngerror.c - stub functions for i/o and memory allocation
|
||||
|
||||
libpng 1.0 beta 2 - version 0.86
|
||||
libpng 1.0 beta 2 - version 0.87
|
||||
For conditions of distribution and use, see copyright notice in png.h
|
||||
Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
January 10, 1996
|
||||
January 15, 1996
|
||||
|
||||
This file provides a location for all error handling. Users which
|
||||
need special error handling are expected to write replacement functions
|
||||
@ -42,6 +42,10 @@ png_warning(png_structp png_ptr, png_const_charp message)
|
||||
png_default_warning(png_ptr, message);
|
||||
}
|
||||
|
||||
/* This is the default error handling function. Note that replacements for
|
||||
this function MUST NOT RETURN, or the program will likely crash. This
|
||||
function is used by default, or if the program supplies NULL for the
|
||||
error function pointer in png_set_message_fn(). */
|
||||
void
|
||||
png_default_error(png_structp png_ptr, png_const_charp message)
|
||||
{
|
||||
|
41
pngio.c
41
pngio.c
@ -1,10 +1,10 @@
|
||||
|
||||
/* pngio.c - stub functions for i/o and memory allocation
|
||||
|
||||
libpng 1.0 beta 2 - version 0.86
|
||||
libpng 1.0 beta 2 - version 0.87
|
||||
For conditions of distribution and use, see copyright notice in png.h
|
||||
Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
January 10, 1996
|
||||
January 15, 1996
|
||||
|
||||
This file provides a location for all input/output. Users which need
|
||||
special handling are expected to write functions which have the same
|
||||
@ -164,7 +164,7 @@ png_default_read_data(png_structp png_ptr, png_bytep data, png_uint_32 length)
|
||||
#else
|
||||
/* this works in MSC also but with lost segment warning */
|
||||
n_data = (png_byte *)data;
|
||||
if ((PNG_BYTEP )n_data == data)
|
||||
if ((png_bytep)n_data == data)
|
||||
#endif
|
||||
{
|
||||
check = fread(n_data, 1, (size_t)length, png_ptr->fp);
|
||||
@ -196,16 +196,19 @@ png_default_read_data(png_structp png_ptr, png_bytep data, png_uint_32 length)
|
||||
}
|
||||
#endif
|
||||
|
||||
/* This function is called to output any data pending writing (normally
|
||||
to disk. After png_flush is called, there should be no data pending
|
||||
writing in any buffers. */
|
||||
#if defined(PNG_WRITE_FLUSH_SUPPORTED)
|
||||
void
|
||||
png_flush(png_struct *png_ptr)
|
||||
png_flush(png_structp png_ptr)
|
||||
{
|
||||
if (png_ptr->output_flush_fn)
|
||||
(*(png_ptr->output_flush_fn))(png_ptr);
|
||||
}
|
||||
|
||||
void
|
||||
png_default_flush(png_struct *png_ptr)
|
||||
png_default_flush(png_structp png_ptr)
|
||||
{
|
||||
if (png_ptr->fp)
|
||||
fflush(png_ptr->fp);
|
||||
@ -223,19 +226,20 @@ png_default_flush(png_struct *png_ptr)
|
||||
arguments a pointer to a png_struct, a pointer to
|
||||
data to be written, and a 32-bit unsigned int which is
|
||||
the number of bytes to be written. The new write
|
||||
function should call png_error("Error msg")
|
||||
function should call png_error(png_ptr, "Error msg")
|
||||
to exit and output any fatal error messages.
|
||||
flush_data_fn - pointer to a new flush function which takes as its
|
||||
arguments a pointer to a png_struct. After a call to
|
||||
the flush function, there should be no data in any buffers
|
||||
or pending transmission. If the output method doesn't do
|
||||
any buffering of ouput, this parameter can be NULL. If
|
||||
PNG_WRITE_FLUSH_SUPPORTED is not defined at libpng
|
||||
compile time, output_flush_fn will be ignored, although
|
||||
it must be supplied for compatibility. */
|
||||
any buffering of ouput, a function prototype must still be
|
||||
supplied although it doesn't have to do anything. If
|
||||
PNG_WRITE_FLUSH_SUPPORTED is not defined at libpng compile
|
||||
time, output_flush_fn will be ignored, although it must be
|
||||
supplied for compatibility. */
|
||||
void
|
||||
png_set_write_fn(png_structp png_ptr, png_voidp io_ptr, png_rw_ptr write_data_fn,
|
||||
png_flush_ptr output_flush_fn)
|
||||
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_ptr->io_ptr = io_ptr;
|
||||
|
||||
@ -245,10 +249,10 @@ png_set_write_fn(png_structp png_ptr, png_voidp io_ptr, png_rw_ptr write_data_fn
|
||||
png_ptr->write_data_fn = png_default_write_data;
|
||||
|
||||
#if defined(PNG_WRITE_FLUSH_SUPPORTED)
|
||||
if (output_flush_fn == NULL)
|
||||
png_ptr->output_flush_fn = png_default_flush;
|
||||
else
|
||||
if (output_flush_fn)
|
||||
png_ptr->output_flush_fn = output_flush_fn;
|
||||
else
|
||||
png_ptr->output_flush_fn = png_default_flush;
|
||||
#endif /* PNG_WRITE_FLUSH_SUPPORTED */
|
||||
|
||||
/* It is an error to read while writing a png file */
|
||||
@ -270,7 +274,8 @@ png_set_write_fn(png_structp png_ptr, png_voidp io_ptr, png_rw_ptr write_data_fn
|
||||
To exit and output any fatal error messages the new write
|
||||
function should call png_error(png_ptr, "Error msg"). */
|
||||
void
|
||||
png_set_read_fn(png_struct *png_ptr, void *io_ptr, png_rw_ptr read_data_fn)
|
||||
png_set_read_fn(png_structp png_ptr, png_voidp io_ptr,
|
||||
png_rw_ptr read_data_fn)
|
||||
{
|
||||
png_ptr->io_ptr = io_ptr;
|
||||
|
||||
@ -291,8 +296,8 @@ png_set_read_fn(png_struct *png_ptr, void *io_ptr, png_rw_ptr read_data_fn)
|
||||
/* This function returns a pointer to the io_ptr associated with the user
|
||||
functions. The application should free any memory associated with this
|
||||
pointer before png_write_destroy and png_read_destroy are called. */
|
||||
void *
|
||||
png_get_io_ptr(png_struct *png_ptr)
|
||||
png_voidp
|
||||
png_get_io_ptr(png_structp png_ptr)
|
||||
{
|
||||
return png_ptr->io_ptr;
|
||||
}
|
||||
|
196
pngmem.c
196
pngmem.c
@ -1,41 +1,199 @@
|
||||
|
||||
/* pngmem.c - stub functions for memory allocation
|
||||
|
||||
libpng 1.0 beta 2 - version 0.86
|
||||
libpng 1.0 beta 2 - version 0.87
|
||||
For conditions of distribution and use, see copyright notice in png.h
|
||||
Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
January 10, 1996
|
||||
January 15, 1996
|
||||
|
||||
This file provides a location for all memory allocation. Users which
|
||||
need special memory handling are expected to modify the code in this file
|
||||
to meet their needs. See the instructions at each function. */
|
||||
to meet their needs. See the instructions at each function. */
|
||||
|
||||
#define PNG_INTERNAL
|
||||
#include "png.h"
|
||||
|
||||
/* Borland DOS special memory handler */
|
||||
#if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
|
||||
/* if you change this, be sure to change the one in png.h also */
|
||||
|
||||
/* Allocate memory. For reasonable files, size should never exceed
|
||||
64K. However, zlib may allocate more then 64K if you don't tell
|
||||
it not to. See zconf.h and png.h for more information. zlib does
|
||||
need to allocate exactly 64K, so whatever you call here must
|
||||
have the ability to do that. */
|
||||
64K. However, zlib may allocate more then 64K if you don't tell
|
||||
it not to. See zconf.h and png.h for more information. zlib does
|
||||
need to allocate exactly 64K, so whatever you call here must
|
||||
have the ability to do that. */
|
||||
|
||||
/* Borland seems to have a problem in DOS mode for exactly 64K.
|
||||
It gives you a segment with an offset of 8 (perhaps to store it's
|
||||
memory stuff). zlib doesn't like this at all, so we have to
|
||||
detect and deal with it. This code should not be needed in
|
||||
Windows or OS/2 modes, and only in 16 bit mode.
|
||||
*/
|
||||
|
||||
png_voidp
|
||||
png_large_malloc(png_structp png_ptr, png_uint_32 size)
|
||||
{
|
||||
png_voidp ret;
|
||||
if (!png_ptr || !size)
|
||||
return ((voidp)0);
|
||||
|
||||
#ifdef PNG_MAX_MALLOC_64K
|
||||
if (size > (png_uint_32)65536L)
|
||||
png_error(png_ptr, "Cannot Allocate > 64K");
|
||||
#endif
|
||||
|
||||
if (size == (png_uint_32)(65536L))
|
||||
{
|
||||
if (!png_ptr->offset_table)
|
||||
{
|
||||
/* try to see if we need to do any of this fancy stuff */
|
||||
ret = farmalloc(size);
|
||||
if (!ret || ((long)ret & 0xffff))
|
||||
{
|
||||
int num_blocks;
|
||||
png_uint_32 total_size;
|
||||
png_bytep table;
|
||||
int i;
|
||||
png_byte huge * hptr;
|
||||
|
||||
if (ret)
|
||||
farfree(ret);
|
||||
ret = 0;
|
||||
|
||||
num_blocks = (int)(1 << (png_ptr->zlib_window_bits - 14));
|
||||
if (num_blocks < 1)
|
||||
num_blocks = 1;
|
||||
if (png_ptr->zlib_mem_level >= 7)
|
||||
num_blocks += (int)(1 << (png_ptr->zlib_mem_level - 7));
|
||||
else
|
||||
num_blocks++;
|
||||
|
||||
total_size = ((png_uint_32)65536L) * (png_uint_32)num_blocks;
|
||||
|
||||
table = farmalloc(total_size);
|
||||
|
||||
if (!table)
|
||||
{
|
||||
png_error(png_ptr, "Out of Memory");
|
||||
}
|
||||
|
||||
if ((long)table & 0xffff)
|
||||
{
|
||||
farfree(table);
|
||||
total_size += (png_uint_32)65536L;
|
||||
}
|
||||
|
||||
table = farmalloc(total_size);
|
||||
|
||||
if (!table)
|
||||
{
|
||||
png_error(png_ptr, "Out of Memory");
|
||||
}
|
||||
|
||||
png_ptr->offset_table = table;
|
||||
png_ptr->offset_table_ptr = farmalloc(
|
||||
num_blocks * sizeof (png_bytep));
|
||||
hptr = (png_byte huge *)table;
|
||||
if ((long)hptr & 0xffff)
|
||||
{
|
||||
hptr = (png_byte huge *)((long)(hptr) & 0xffff0000L);
|
||||
hptr += 65536L;
|
||||
}
|
||||
for (i = 0; i < num_blocks; i++)
|
||||
{
|
||||
png_ptr->offset_table_ptr[i] = (png_bytep)hptr;
|
||||
hptr += 65536L;
|
||||
}
|
||||
|
||||
png_ptr->offset_table_number = num_blocks;
|
||||
png_ptr->offset_table_count = 0;
|
||||
png_ptr->offset_table_count_free = 0;
|
||||
}
|
||||
|
||||
if (png_ptr->offset_table_count >= png_ptr->offset_table_number)
|
||||
png_error(png_ptr, "Out of Memory");
|
||||
|
||||
ret = png_ptr->offset_table_ptr[png_ptr->offset_table_count++];
|
||||
}
|
||||
}
|
||||
else
|
||||
ret = farmalloc(size);
|
||||
|
||||
if (ret == NULL)
|
||||
{
|
||||
png_error(png_ptr, "Out of Memory");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* free a pointer allocated by png_large_malloc(). In the default
|
||||
configuration, png_ptr is not used, but is passed in case it
|
||||
is needed. If ptr is NULL, return without taking any action. */
|
||||
void
|
||||
png_large_free(png_structp png_ptr, png_voidp ptr)
|
||||
{
|
||||
if (!png_ptr)
|
||||
return;
|
||||
|
||||
if (ptr != NULL)
|
||||
{
|
||||
if (png_ptr->offset_table)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < png_ptr->offset_table_count; i++)
|
||||
{
|
||||
if (ptr == png_ptr->offset_table_ptr[i])
|
||||
{
|
||||
ptr = 0;
|
||||
png_ptr->offset_table_count_free++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (png_ptr->offset_table_count_free == png_ptr->offset_table_count)
|
||||
{
|
||||
farfree(png_ptr->offset_table);
|
||||
farfree(png_ptr->offset_table_ptr);
|
||||
png_ptr->offset_table = 0;
|
||||
png_ptr->offset_table_ptr = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (ptr)
|
||||
farfree(ptr);
|
||||
}
|
||||
}
|
||||
|
||||
#else /* Not the Borland DOS special memory handler */
|
||||
|
||||
/* Allocate memory. For reasonable files, size should never exceed
|
||||
64K. However, zlib may allocate more then 64K if you don't tell
|
||||
it not to. See zconf.h and png.h for more information. zlib does
|
||||
need to allocate exactly 64K, so whatever you call here must
|
||||
have the ability to do that. */
|
||||
|
||||
|
||||
png_voidp
|
||||
png_large_malloc(png_structp png_ptr, png_uint_32 size)
|
||||
{
|
||||
png_voidp ret;
|
||||
if (!png_ptr || !size)
|
||||
png_voidp ret;
|
||||
if (!png_ptr || !size)
|
||||
return ((voidp)0);
|
||||
|
||||
#ifdef PNG_MAX_MALLOC_64K
|
||||
if (size > (png_uint_32)65536L)
|
||||
png_error(png_ptr, "Cannot Allocate > 64K");
|
||||
if (size > (png_uint_32)65536L)
|
||||
png_error(png_ptr, "Cannot Allocate > 64K");
|
||||
#endif
|
||||
|
||||
#if defined(__TURBOC__) && !defined(__FLAT__)
|
||||
ret = farmalloc(size);
|
||||
#else
|
||||
# if defined(_MSC_VER) && defined(MAXSEG_64K)
|
||||
ret = halloc(size, 1);
|
||||
# else
|
||||
ret = malloc(size);
|
||||
# endif
|
||||
#endif
|
||||
|
||||
if (ret == NULL)
|
||||
@ -43,7 +201,7 @@ png_large_malloc(png_structp png_ptr, png_uint_32 size)
|
||||
png_error(png_ptr, "Out of Memory");
|
||||
}
|
||||
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* free a pointer allocated by png_large_malloc(). In the default
|
||||
@ -60,15 +218,22 @@ png_large_free(png_structp png_ptr, png_voidp ptr)
|
||||
#if defined(__TURBOC__) && !defined(__FLAT__)
|
||||
farfree(ptr);
|
||||
#else
|
||||
# if defined(_MSC_VER) && defined(MAXSEG_64K)
|
||||
hfree(ptr);
|
||||
# else
|
||||
free(ptr);
|
||||
# endif
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* Not Borland DOS special memory handler */
|
||||
|
||||
/* Allocate memory. This is called for smallish blocks only It
|
||||
should not get anywhere near 64K. On segmented machines, this
|
||||
must come from the local heap (for zlib). */
|
||||
must come from the local heap (for zlib). Currently, zlib is
|
||||
the only one that uses this, so you should only get one call
|
||||
to this, and that a small block. */
|
||||
void *
|
||||
png_malloc(png_structp png_ptr, png_uint_32 size)
|
||||
{
|
||||
@ -96,7 +261,8 @@ png_malloc(png_structp png_ptr, png_uint_32 size)
|
||||
}
|
||||
|
||||
/* Reallocate memory. This will not get near 64K on a
|
||||
even marginally reasonable file. */
|
||||
even marginally reasonable file. This is not used in
|
||||
the current version of the library. */
|
||||
void *
|
||||
png_realloc(png_structp png_ptr, void * ptr, png_uint_32 size,
|
||||
png_uint_32 old_size)
|
||||
|
91
pngpread.c
91
pngpread.c
@ -1,15 +1,17 @@
|
||||
|
||||
/* pngpread.c - read a png file in push mode
|
||||
|
||||
libpng 1.0 beta 2 - version 0.86
|
||||
libpng 1.0 beta 2 - version 0.87
|
||||
For conditions of distribution and use, see copyright notice in png.h
|
||||
Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
January 10, 1996
|
||||
January 15, 1996
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
#include "png.h"
|
||||
|
||||
#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
|
||||
|
||||
void
|
||||
png_process_data(png_structp png_ptr, png_infop info,
|
||||
png_bytep buffer, png_uint_32 buffer_size)
|
||||
@ -110,7 +112,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info)
|
||||
|
||||
png_push_fill_buffer(png_ptr, chunk_start, 8);
|
||||
png_ptr->push_length = png_get_uint_32(chunk_start);
|
||||
memcpy(png_ptr->push_chunk_name, chunk_start + 4, 4);
|
||||
png_memcpy(png_ptr->push_chunk_name, (png_voidp)(chunk_start + 4), 4);
|
||||
png_ptr->have_chunk_header = 1;
|
||||
png_reset_crc(png_ptr);
|
||||
png_calculate_crc(png_ptr, chunk_start + 4, 4);
|
||||
@ -142,7 +144,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info)
|
||||
else
|
||||
#else
|
||||
{
|
||||
png_push_handle_PLTE(png_ptr, info, png_ptr->push_length);
|
||||
png_push_handle_PLTE(png_ptr, png_ptr->push_length);
|
||||
}
|
||||
#endif
|
||||
png_ptr->mode = PNG_HAVE_PLTE;
|
||||
@ -316,7 +318,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info)
|
||||
png_ptr->mode == PNG_AFTER_IEND)
|
||||
png_error(png_ptr, "Out of Place tEXt");
|
||||
|
||||
png_push_handle_tEXt(png_ptr, info, png_ptr->push_length);
|
||||
png_push_handle_tEXt(png_ptr, png_ptr->push_length);
|
||||
}
|
||||
#endif
|
||||
#if defined(PNG_READ_zTXt_SUPPORTED)
|
||||
@ -326,7 +328,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info)
|
||||
png_ptr->mode == PNG_AFTER_IEND)
|
||||
png_error(png_ptr, "Out of Place zTXt");
|
||||
|
||||
png_push_handle_zTXt(png_ptr, info, png_ptr->push_length);
|
||||
png_push_handle_zTXt(png_ptr, png_ptr->push_length);
|
||||
}
|
||||
#endif
|
||||
else
|
||||
@ -376,7 +378,7 @@ png_push_skip(png_structp png_ptr)
|
||||
png_ptr->skip_length -= save_size;
|
||||
png_ptr->buffer_size -= save_size;
|
||||
png_ptr->save_buffer_size -= save_size;
|
||||
png_ptr->save_buffer_ptr += save_size;
|
||||
png_ptr->save_buffer_ptr += (png_size_t)save_size;
|
||||
}
|
||||
if (png_ptr->skip_length && png_ptr->current_buffer_size)
|
||||
{
|
||||
@ -392,7 +394,7 @@ png_push_skip(png_structp png_ptr)
|
||||
png_ptr->skip_length -= save_size;
|
||||
png_ptr->buffer_size -= save_size;
|
||||
png_ptr->current_buffer_size -= save_size;
|
||||
png_ptr->current_buffer_ptr += save_size;
|
||||
png_ptr->current_buffer_ptr += (png_size_t)save_size;
|
||||
}
|
||||
if (!png_ptr->skip_length && png_ptr->buffer_size >= 4)
|
||||
{
|
||||
@ -405,7 +407,7 @@ void
|
||||
png_push_fill_buffer(png_structp png_ptr, png_bytep buffer,
|
||||
png_uint_32 length)
|
||||
{
|
||||
png_byte * ptr;
|
||||
png_bytep ptr;
|
||||
|
||||
ptr = buffer;
|
||||
if (png_ptr->save_buffer_size)
|
||||
@ -417,12 +419,12 @@ png_push_fill_buffer(png_structp png_ptr, png_bytep buffer,
|
||||
else
|
||||
save_size = png_ptr->save_buffer_size;
|
||||
|
||||
memcpy(ptr, png_ptr->save_buffer_ptr, save_size);
|
||||
png_memcpy(ptr, png_ptr->save_buffer_ptr, (png_size_t)save_size);
|
||||
length -= save_size;
|
||||
ptr += save_size;
|
||||
ptr += (png_size_t)save_size;
|
||||
png_ptr->buffer_size -= save_size;
|
||||
png_ptr->save_buffer_size -= save_size;
|
||||
png_ptr->save_buffer_ptr += save_size;
|
||||
png_ptr->save_buffer_ptr += (png_size_t)save_size;
|
||||
}
|
||||
if (length && png_ptr->current_buffer_size)
|
||||
{
|
||||
@ -433,10 +435,10 @@ png_push_fill_buffer(png_structp png_ptr, png_bytep buffer,
|
||||
else
|
||||
save_size = png_ptr->current_buffer_size;
|
||||
|
||||
memcpy(ptr, png_ptr->current_buffer_ptr, save_size);
|
||||
png_memcpy(ptr, png_ptr->current_buffer_ptr, (png_size_t)save_size);
|
||||
png_ptr->buffer_size -= save_size;
|
||||
png_ptr->current_buffer_size -= save_size;
|
||||
png_ptr->current_buffer_ptr += save_size;
|
||||
png_ptr->current_buffer_ptr += (png_size_t)save_size;
|
||||
}
|
||||
}
|
||||
|
||||
@ -448,8 +450,8 @@ png_push_save_buffer(png_structp png_ptr)
|
||||
if (png_ptr->save_buffer_ptr != png_ptr->save_buffer)
|
||||
{
|
||||
int i;
|
||||
png_byte * sp;
|
||||
png_byte * dp;
|
||||
png_bytep sp;
|
||||
png_bytep dp;
|
||||
|
||||
for (i = 0, sp = png_ptr->save_buffer_ptr, dp = png_ptr->save_buffer;
|
||||
i < png_ptr->save_buffer_size;
|
||||
@ -463,22 +465,24 @@ png_push_save_buffer(png_structp png_ptr)
|
||||
png_ptr->save_buffer_max)
|
||||
{
|
||||
int new_max;
|
||||
png_byte * old_buffer;
|
||||
png_bytep old_buffer;
|
||||
|
||||
new_max = png_ptr->save_buffer_size +
|
||||
png_ptr->current_buffer_size + 256;
|
||||
new_max = (int)(png_ptr->save_buffer_size +
|
||||
png_ptr->current_buffer_size + 256);
|
||||
old_buffer = png_ptr->save_buffer;
|
||||
png_ptr->save_buffer = (png_byte *)
|
||||
png_ptr->save_buffer = (png_bytep)
|
||||
png_large_malloc(png_ptr, new_max);
|
||||
memcpy(png_ptr->save_buffer, old_buffer,
|
||||
png_ptr->save_buffer_size);
|
||||
png_memcpy(png_ptr->save_buffer, old_buffer,
|
||||
(png_size_t)png_ptr->save_buffer_size);
|
||||
png_large_free(png_ptr, old_buffer);
|
||||
png_ptr->save_buffer_max = new_max;
|
||||
}
|
||||
if (png_ptr->current_buffer_size)
|
||||
{
|
||||
memcpy(png_ptr->save_buffer + png_ptr->save_buffer_size,
|
||||
png_ptr->current_buffer_ptr, png_ptr->current_buffer_size);
|
||||
png_memcpy(png_ptr->save_buffer +
|
||||
(png_size_t)png_ptr->save_buffer_size,
|
||||
png_ptr->current_buffer_ptr,
|
||||
(png_size_t)png_ptr->current_buffer_size);
|
||||
png_ptr->save_buffer_size += png_ptr->current_buffer_size;
|
||||
png_ptr->current_buffer_size = 0;
|
||||
}
|
||||
@ -511,7 +515,8 @@ png_push_read_idat(png_structp png_ptr)
|
||||
|
||||
png_push_fill_buffer(png_ptr, chunk_start, 8);
|
||||
png_ptr->push_length = png_get_uint_32(chunk_start);
|
||||
memcpy(png_ptr->push_chunk_name, chunk_start + 4, 4);
|
||||
png_memcpy(png_ptr->push_chunk_name,
|
||||
(png_voidp)(chunk_start + 4), 4);
|
||||
png_ptr->have_chunk_header = 1;
|
||||
png_reset_crc(png_ptr);
|
||||
png_calculate_crc(png_ptr, chunk_start + 4, 4);
|
||||
@ -540,7 +545,7 @@ png_push_read_idat(png_structp png_ptr)
|
||||
png_ptr->idat_size -= save_size;
|
||||
png_ptr->buffer_size -= save_size;
|
||||
png_ptr->save_buffer_size -= save_size;
|
||||
png_ptr->save_buffer_ptr += save_size;
|
||||
png_ptr->save_buffer_ptr += (png_size_t)save_size;
|
||||
}
|
||||
if (png_ptr->idat_size && png_ptr->current_buffer_size)
|
||||
{
|
||||
@ -557,7 +562,7 @@ png_push_read_idat(png_structp png_ptr)
|
||||
png_ptr->idat_size -= save_size;
|
||||
png_ptr->buffer_size -= save_size;
|
||||
png_ptr->current_buffer_size -= save_size;
|
||||
png_ptr->current_buffer_ptr += save_size;
|
||||
png_ptr->current_buffer_ptr += (png_size_t)save_size;
|
||||
}
|
||||
if (!png_ptr->idat_size && png_ptr->buffer_size >= 4)
|
||||
{
|
||||
@ -785,14 +790,14 @@ png_read_push_finish_row(png_structp png_ptr)
|
||||
|
||||
|
||||
void
|
||||
png_push_handle_PLTE(png_structp png_ptr, png_infop info, png_uint_32 length)
|
||||
png_push_handle_PLTE(png_structp png_ptr, png_uint_32 length)
|
||||
{
|
||||
if (length % 3)
|
||||
png_error(png_ptr, "Invalid Palette Chunk");
|
||||
|
||||
png_ptr->num_palette = length / 3;
|
||||
png_ptr->num_palette = (png_uint_16)(length / 3);
|
||||
png_ptr->cur_palette = 0;
|
||||
png_ptr->palette = (png_colorp)png_malloc(png_ptr,
|
||||
png_ptr->palette = (png_colorp)png_large_malloc(png_ptr,
|
||||
png_ptr->num_palette * sizeof (png_color));
|
||||
png_ptr->process_mode = PNG_READ_PLTE_MODE;
|
||||
}
|
||||
@ -828,8 +833,7 @@ png_push_read_plte(png_structp png_ptr, png_infop info)
|
||||
|
||||
#if defined(PNG_READ_tEXt_SUPPORTED)
|
||||
void
|
||||
png_push_handle_tEXt(png_structp png_ptr, png_infop info,
|
||||
png_uint_32 length)
|
||||
png_push_handle_tEXt(png_structp png_ptr, png_uint_32 length)
|
||||
{
|
||||
png_ptr->current_text = (png_charp)png_large_malloc(png_ptr, length + 1);
|
||||
png_ptr->current_text[(png_size_t)length] = '\0';
|
||||
@ -855,7 +859,7 @@ png_push_read_text(png_structp png_ptr, png_infop info)
|
||||
png_calculate_crc(png_ptr, (png_bytep)png_ptr->current_text_ptr,
|
||||
text_size);
|
||||
png_ptr->current_text_left -= text_size;
|
||||
png_ptr->current_text_ptr += text_size;
|
||||
png_ptr->current_text_ptr += (png_size_t)text_size;
|
||||
}
|
||||
if (!(png_ptr->current_text_left) && png_ptr->buffer_size >= 4)
|
||||
{
|
||||
@ -882,7 +886,7 @@ png_push_read_text(png_structp png_ptr, png_infop info)
|
||||
|
||||
#if defined(PNG_READ_zTXt_SUPPORTED)
|
||||
void
|
||||
png_push_handle_zTXt(png_structp png_ptr, png_infop info,
|
||||
png_push_handle_zTXt(png_structp png_ptr,
|
||||
png_uint_32 length)
|
||||
{
|
||||
png_ptr->current_text = (png_charp)png_large_malloc(png_ptr, length + 1);
|
||||
@ -909,7 +913,7 @@ png_push_read_ztxt(png_structp png_ptr, png_infop info)
|
||||
png_calculate_crc(png_ptr, (png_bytep)png_ptr->current_text_ptr,
|
||||
text_size);
|
||||
png_ptr->current_text_left -= text_size;
|
||||
png_ptr->current_text_ptr += text_size;
|
||||
png_ptr->current_text_ptr += (png_size_t)text_size;
|
||||
}
|
||||
if (!(png_ptr->current_text_left) && png_ptr->buffer_size >= 4)
|
||||
{
|
||||
@ -923,8 +927,6 @@ png_push_read_ztxt(png_structp png_ptr, png_infop info)
|
||||
key = png_ptr->current_text;
|
||||
png_ptr->current_text = 0;
|
||||
|
||||
text = NULL;
|
||||
|
||||
for (text = key; *text; text++)
|
||||
/* empty loop */ ;
|
||||
|
||||
@ -954,7 +956,7 @@ png_push_read_ztxt(png_structp png_ptr, png_infop info)
|
||||
key_size = text - key;
|
||||
text_size = 0;
|
||||
text = NULL;
|
||||
ret = Z_STREAM_END;
|
||||
ret = Z_STREAM_END;
|
||||
|
||||
while (png_ptr->zstream->avail_in)
|
||||
{
|
||||
@ -971,7 +973,7 @@ png_push_read_ztxt(png_structp png_ptr, png_infop info)
|
||||
{
|
||||
if (!text)
|
||||
{
|
||||
text = (png_charp)png_malloc(png_ptr,
|
||||
text = (png_charp)png_large_malloc(png_ptr,
|
||||
png_ptr->zbuf_size - png_ptr->zstream->avail_out +
|
||||
key_size + 1);
|
||||
png_memcpy(text + (png_size_t)key_size, png_ptr->zbuf,
|
||||
@ -1073,7 +1075,7 @@ png_push_read_end(png_structp png_ptr, png_infop info)
|
||||
|
||||
png_push_fill_buffer(png_ptr, chunk_start, 8);
|
||||
png_ptr->push_length = png_get_uint_32(chunk_start);
|
||||
memcpy(png_ptr->push_chunk_name, chunk_start + 4, 4);
|
||||
png_memcpy(png_ptr->push_chunk_name, (png_voidp)(chunk_start + 4), 4);
|
||||
png_ptr->have_chunk_header = 1;
|
||||
png_reset_crc(png_ptr);
|
||||
png_calculate_crc(png_ptr, chunk_start + 4, 4);
|
||||
@ -1173,7 +1175,7 @@ png_push_read_end(png_structp png_ptr, png_infop info)
|
||||
png_ptr->mode == PNG_AFTER_IEND)
|
||||
png_error(png_ptr, "Out of Place tEXt");
|
||||
|
||||
png_push_handle_tEXt(png_ptr, info, png_ptr->push_length);
|
||||
png_push_handle_tEXt(png_ptr, png_ptr->push_length);
|
||||
}
|
||||
#endif
|
||||
#if defined(PNG_READ_zTXt_SUPPORTED)
|
||||
@ -1183,7 +1185,7 @@ png_push_read_end(png_structp png_ptr, png_infop info)
|
||||
png_ptr->mode == PNG_AFTER_IEND)
|
||||
png_error(png_ptr, "Out of Place zTXt");
|
||||
|
||||
png_push_handle_zTXt(png_ptr, info, png_ptr->push_length);
|
||||
png_push_handle_zTXt(png_ptr, png_ptr->push_length);
|
||||
}
|
||||
#endif
|
||||
else
|
||||
@ -1214,6 +1216,9 @@ void
|
||||
png_progressive_combine_row (png_structp png_ptr,
|
||||
png_bytep old_row, png_bytep new_row)
|
||||
{
|
||||
png_combine_row(png_ptr, old_row, png_pass_dsp_mask[png_ptr->pass]);
|
||||
if (new_row)
|
||||
png_combine_row(png_ptr, old_row, png_pass_dsp_mask[png_ptr->pass]);
|
||||
}
|
||||
|
||||
#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
|
||||
|
||||
|
42
pngrcb.c
42
pngrcb.c
@ -1,9 +1,9 @@
|
||||
/* pngrcb.c - callbacks while reading a png file
|
||||
|
||||
libpng 1.0 beta 2 - version 0.86
|
||||
libpng 1.0 beta 2 - version 0.87
|
||||
For conditions of distribution and use, see copyright notice in png.h
|
||||
Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
January 10, 1996
|
||||
January 15, 1996
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
@ -20,11 +20,11 @@ png_read_IHDR(png_structp png_ptr, png_infop info,
|
||||
|
||||
info->width = width;
|
||||
info->height = height;
|
||||
info->bit_depth = bit_depth;
|
||||
info->color_type = color_type;
|
||||
info->compression_type = compression_type;
|
||||
info->filter_type = filter_type;
|
||||
info->interlace_type = interlace_type;
|
||||
info->bit_depth = (png_byte)bit_depth;
|
||||
info->color_type =(png_byte) color_type;
|
||||
info->compression_type = (png_byte)compression_type;
|
||||
info->filter_type = (png_byte)filter_type;
|
||||
info->interlace_type = (png_byte)interlace_type;
|
||||
if (info->color_type == PNG_COLOR_TYPE_PALETTE)
|
||||
info->channels = 1;
|
||||
else if (info->color_type & PNG_COLOR_MASK_COLOR)
|
||||
@ -33,7 +33,7 @@ png_read_IHDR(png_structp png_ptr, png_infop info,
|
||||
info->channels = 1;
|
||||
if (info->color_type & PNG_COLOR_MASK_ALPHA)
|
||||
info->channels++;
|
||||
info->pixel_depth = info->channels * info->bit_depth;
|
||||
info->pixel_depth = (png_byte)(info->channels * info->bit_depth);
|
||||
info->rowbytes = ((info->width * info->pixel_depth + 7) >> 3);
|
||||
}
|
||||
|
||||
@ -45,7 +45,7 @@ png_read_PLTE(png_structp png_ptr, png_infop info,
|
||||
return;
|
||||
|
||||
info->palette = palette;
|
||||
info->num_palette = num;
|
||||
info->num_palette = (png_uint_16)num;
|
||||
info->valid |= PNG_INFO_PLTE;
|
||||
}
|
||||
|
||||
@ -112,7 +112,7 @@ png_read_tRNS(png_structp png_ptr, png_infop info,
|
||||
png_memcpy(&(info->trans_values), trans_values,
|
||||
sizeof(png_color_16));
|
||||
}
|
||||
info->num_trans = num_trans;
|
||||
info->num_trans = (png_uint_16)num_trans;
|
||||
info->valid |= PNG_INFO_tRNS;
|
||||
}
|
||||
#endif
|
||||
@ -152,7 +152,7 @@ png_read_pHYs(png_structp png_ptr, png_infop info,
|
||||
|
||||
info->x_pixels_per_unit = res_x;
|
||||
info->y_pixels_per_unit = res_y;
|
||||
info->phys_unit_type = unit_type;
|
||||
info->phys_unit_type = (png_byte)unit_type;
|
||||
info->valid |= PNG_INFO_pHYs;
|
||||
}
|
||||
#endif
|
||||
@ -167,7 +167,7 @@ png_read_oFFs(png_structp png_ptr, png_infop info,
|
||||
|
||||
info->x_offset = offset_x;
|
||||
info->y_offset = offset_y;
|
||||
info->offset_unit_type = unit_type;
|
||||
info->offset_unit_type = (png_byte)unit_type;
|
||||
info->valid |= PNG_INFO_oFFs;
|
||||
}
|
||||
#endif
|
||||
@ -200,16 +200,22 @@ png_read_zTXt(png_structp png_ptr, png_infop info,
|
||||
png_uint_32 old_max;
|
||||
|
||||
old_max = info->max_text;
|
||||
info->max_text = info->num_text + 16;
|
||||
info->text = (png_textp)png_realloc(png_ptr,
|
||||
info->text,
|
||||
info->max_text * sizeof (png_text),
|
||||
old_max * sizeof (png_text));
|
||||
info->max_text = info->num_text + 16;
|
||||
{
|
||||
png_textp old_text;
|
||||
|
||||
old_text = info->text;
|
||||
info->text = (png_textp)png_large_malloc(png_ptr,
|
||||
info->max_text * sizeof (png_text));
|
||||
png_memcpy(info->text, old_text,
|
||||
(png_size_t)(old_max * sizeof (png_text)));
|
||||
png_large_free(png_ptr, old_text);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
info->max_text = info->num_text + 16;
|
||||
info->text = (png_textp)png_malloc(png_ptr,
|
||||
info->text = (png_textp)png_large_malloc(png_ptr,
|
||||
info->max_text * sizeof (png_text));
|
||||
info->num_text = 0;
|
||||
}
|
||||
|
202
pngread.c
202
pngread.c
@ -1,10 +1,10 @@
|
||||
|
||||
/* pngread.c - read a png file
|
||||
|
||||
libpng 1.0 beta 2 - version 0.86
|
||||
libpng 1.0 beta 2 - version 0.87
|
||||
For conditions of distribution and use, see copyright notice in png.h
|
||||
Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
January 10, 1996
|
||||
Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
January 15, 1996
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
@ -14,30 +14,30 @@
|
||||
void
|
||||
png_read_init(png_structp png_ptr)
|
||||
{
|
||||
jmp_buf tmp_jmp;
|
||||
png_msg_ptr error_fn;
|
||||
png_msg_ptr warning_fn;
|
||||
png_voidp msg_ptr;
|
||||
jmp_buf tmp_jmp;
|
||||
png_msg_ptr error_fn;
|
||||
png_msg_ptr warning_fn;
|
||||
png_voidp msg_ptr;
|
||||
|
||||
png_memcpy(tmp_jmp, png_ptr->jmpbuf, sizeof (jmp_buf));
|
||||
error_fn = png_ptr->error_fn;
|
||||
warning_fn = png_ptr->warning_fn;
|
||||
msg_ptr = png_ptr->msg_ptr;
|
||||
png_memcpy(tmp_jmp, png_ptr->jmpbuf, sizeof (jmp_buf));
|
||||
error_fn = png_ptr->error_fn;
|
||||
warning_fn = png_ptr->warning_fn;
|
||||
msg_ptr = png_ptr->msg_ptr;
|
||||
|
||||
png_memset(png_ptr, 0, sizeof (png_struct));
|
||||
png_memset(png_ptr, 0, sizeof (png_struct));
|
||||
|
||||
png_memcpy(png_ptr->jmpbuf, tmp_jmp, sizeof (jmp_buf));
|
||||
png_ptr->error_fn = error_fn;
|
||||
png_ptr->warning_fn = warning_fn;
|
||||
png_ptr->msg_ptr = msg_ptr;
|
||||
png_memcpy(png_ptr->jmpbuf, tmp_jmp, sizeof (jmp_buf));
|
||||
png_ptr->error_fn = error_fn;
|
||||
png_ptr->warning_fn = warning_fn;
|
||||
png_ptr->msg_ptr = msg_ptr;
|
||||
|
||||
png_ptr->zbuf_size = PNG_ZBUF_SIZE;
|
||||
png_ptr->zbuf = png_large_malloc(png_ptr, png_ptr->zbuf_size);
|
||||
png_ptr->zstream = (z_stream *)png_malloc(png_ptr, sizeof (z_stream));
|
||||
png_ptr->zstream->zalloc = png_zalloc;
|
||||
png_ptr->zstream = (z_stream *)png_malloc(png_ptr, sizeof (z_stream));
|
||||
png_ptr->zstream->zalloc = png_zalloc;
|
||||
png_ptr->zstream->zfree = png_zfree;
|
||||
png_ptr->zstream->opaque = (voidp)png_ptr;
|
||||
inflateInit(png_ptr->zstream);
|
||||
png_ptr->zstream->opaque = (voidpf)png_ptr;
|
||||
inflateInit(png_ptr->zstream);
|
||||
png_ptr->zstream->next_out = png_ptr->zbuf;
|
||||
png_ptr->zstream->avail_out = (uInt)png_ptr->zbuf_size;
|
||||
}
|
||||
@ -63,7 +63,7 @@ png_read_info(png_structp png_ptr, png_infop info)
|
||||
png_calculate_crc(png_ptr, chunk_start + 4, 4);
|
||||
if (!png_memcmp(chunk_start + 4, png_IHDR, 4))
|
||||
{
|
||||
if (png_ptr->mode != PNG_BEFORE_IHDR)
|
||||
if (png_ptr->mode != PNG_BEFORE_IHDR)
|
||||
png_error(png_ptr, "Out of Place IHDR");
|
||||
|
||||
png_handle_IHDR(png_ptr, info, length);
|
||||
@ -81,7 +81,7 @@ png_read_info(png_structp png_ptr, png_infop info)
|
||||
#else
|
||||
{
|
||||
png_handle_PLTE(png_ptr, info, length);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
png_ptr->mode = PNG_HAVE_PLTE;
|
||||
}
|
||||
@ -99,7 +99,7 @@ png_read_info(png_structp png_ptr, png_infop info)
|
||||
else if (!png_memcmp(chunk_start + 4, png_gAMA, 4))
|
||||
{
|
||||
if (png_ptr->mode != PNG_HAVE_IHDR)
|
||||
png_error(png_ptr, "Out of Place PLTE");
|
||||
png_error(png_ptr, "Out of Place PLTE");
|
||||
|
||||
png_handle_gAMA(png_ptr, info, length);
|
||||
}
|
||||
@ -117,7 +117,7 @@ png_read_info(png_structp png_ptr, png_infop info)
|
||||
else if (!png_memcmp(chunk_start + 4, png_cHRM, 4))
|
||||
{
|
||||
if (png_ptr->mode != PNG_HAVE_IHDR)
|
||||
png_error(png_ptr, "Out of Place cHRM");
|
||||
png_error(png_ptr, "Out of Place cHRM");
|
||||
|
||||
png_handle_cHRM(png_ptr, info, length);
|
||||
}
|
||||
@ -135,7 +135,7 @@ png_read_info(png_structp png_ptr, png_infop info)
|
||||
#if defined(PNG_READ_bKGD_SUPPORTED)
|
||||
else if (!png_memcmp(chunk_start + 4, png_bKGD, 4))
|
||||
{
|
||||
if (png_ptr->mode != PNG_HAVE_IHDR &&
|
||||
if (png_ptr->mode != PNG_HAVE_IHDR &&
|
||||
png_ptr->mode != PNG_HAVE_PLTE)
|
||||
png_error(png_ptr, "Out of Place bKGD");
|
||||
|
||||
@ -153,7 +153,7 @@ png_read_info(png_structp png_ptr, png_infop info)
|
||||
#endif
|
||||
#if defined(PNG_READ_pHYs_SUPPORTED)
|
||||
else if (!png_memcmp(chunk_start + 4, png_pHYs, 4))
|
||||
{
|
||||
{
|
||||
if (png_ptr->mode != PNG_HAVE_IHDR &&
|
||||
png_ptr->mode != PNG_HAVE_PLTE)
|
||||
png_error(png_ptr, "Out of Place pHYs");
|
||||
@ -189,7 +189,7 @@ png_read_info(png_structp png_ptr, png_infop info)
|
||||
png_error(png_ptr, "Out of Place tEXt");
|
||||
|
||||
png_handle_tEXt(png_ptr, info, length);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if defined(PNG_READ_zTXt_SUPPORTED)
|
||||
else if (!png_memcmp(chunk_start + 4, png_zTXt, 4))
|
||||
@ -255,7 +255,7 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
|
||||
if (dsp_row)
|
||||
png_combine_row(png_ptr, dsp_row,
|
||||
png_pass_dsp_mask[png_ptr->pass]);
|
||||
png_read_finish_row(png_ptr);
|
||||
png_read_finish_row(png_ptr);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
@ -273,7 +273,7 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
|
||||
if ((png_ptr->row_number & 7) != 4)
|
||||
{
|
||||