Imported from libpng-0.87.tar

This commit is contained in:
Guy Schalnat 1996-01-16 01:51:56 -06:00 committed by Glenn Randers-Pehrson
parent 69b1448f19
commit 4ee97b0891
22 changed files with 1210 additions and 863 deletions

View File

@ -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
View 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

View File

@ -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
View File

@ -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

544
png.h

File diff suppressed because it is too large Load Diff

View File

@ -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

View File

@ -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

View File

@ -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
View File

@ -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
View File

@ -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)

View File

@ -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 */

View File

@ -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
View File

@ -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)
{
if (dsp_row && (png_ptr->row_number & 4))
png_combine_row(png_ptr, dsp_row,
png_combine_row(png_ptr, dsp_row,
png_pass_dsp_mask[png_ptr->pass]);
png_read_finish_row(png_ptr);
return;
@ -291,7 +291,7 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
break;
case 4:
if ((png_ptr->row_number & 3) != 2)
{
{
if (dsp_row && (png_ptr->row_number & 2))
png_combine_row(png_ptr, dsp_row,
png_pass_dsp_mask[png_ptr->pass]);
@ -309,7 +309,7 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
return;
}
break;
case 6:
case 6:
if (!(png_ptr->row_number & 1))
{
png_read_finish_row(png_ptr);
@ -327,7 +327,7 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
png_ptr->zstream->avail_out = (uInt)png_ptr->irowbytes;
do
{
if (!(png_ptr->zstream->avail_in))
if (!(png_ptr->zstream->avail_in))
{
while (!png_ptr->idat_size)
{
@ -345,7 +345,7 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
png_reset_crc(png_ptr);
png_crc_read(png_ptr, buf, 4);
if (png_memcmp(buf, png_IDAT, 4))
if (png_memcmp(buf, png_IDAT, 4))
png_error(png_ptr, "Not enough image data");
}
@ -356,14 +356,14 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zstream->avail_in);
png_ptr->idat_size -= png_ptr->zstream->avail_in;
}
ret = inflate(png_ptr->zstream, Z_PARTIAL_FLUSH);
ret = inflate(png_ptr->zstream, Z_PARTIAL_FLUSH);
if (ret == Z_STREAM_END)
{
if (png_ptr->zstream->avail_out || png_ptr->zstream->avail_in ||
png_ptr->idat_size)
png_error(png_ptr, "Extra compressed data");
png_ptr->mode = PNG_AT_LAST_IDAT;
break;
break;
}
if (ret != Z_OK)
png_error(png_ptr, "Compression Error");
@ -381,7 +381,7 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
png_ptr->row_info.rowbytes = ((png_ptr->row_info.width *
(png_uint_32)png_ptr->row_info.pixel_depth + 7) >> 3);
if (png_ptr->row_buf[0])
if (png_ptr->row_buf[0])
png_read_filter_row(&(png_ptr->row_info),
png_ptr->row_buf + 1, png_ptr->prev_row + 1,
(int)(png_ptr->row_buf[0]));
@ -421,7 +421,7 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
/* read a one or more rows of image data. If the image is interlaced,
and png_set_interlace_handling() has been called, the rows need to
to contain the contents of the rows from the previous pass. If
the image has alpha or transparency, and png_handle_alpha() has been
the image has alpha or transparency, and png_handle_alpha() has been
called, the rows contents must be initialized to the contents of the
screen. row holds the actual image, and pixels are placed in it
as they arrive. If the image is displayed after each pass, it will
@ -435,22 +435,22 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
rows. In this case, you do not have to provide a display_rows buffer
also, but you may. If the image is not interlaced, or if you have
not called png_set_interlace_handling(), the display_row buffer will
be ignored, so pass NULL to it. */
be ignored, so pass NULL to it. */
void
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)
{
png_uint_32 i;
png_bytepp rp;
png_bytepp dp;
png_uint_32 i;
png_bytepp rp;
png_bytepp dp;
rp = row;
dp = display_row;
for (i = 0; i < num_rows; i++)
{
png_bytep rptr;
png_bytep dptr;
png_bytep rptr;
png_bytep dptr;
if (rp)
rptr = *rp;
@ -461,7 +461,7 @@ png_read_rows(png_structp png_ptr, png_bytepp row,
else
dptr = NULL;
png_read_row(png_ptr, rptr, dptr);
if (row)
if (row)
rp++;
if (display_row)
dp++;
@ -479,7 +479,7 @@ png_read_image(png_structp png_ptr, png_bytepp image)
{
png_uint_32 i;
int pass, j;
png_bytepp rp;
png_bytepp rp;
pass = png_set_interlace_handling(png_ptr);
for (j = 0; j < pass; j++)
@ -533,7 +533,7 @@ png_read_end(png_structp png_ptr, png_infop info)
png_error(png_ptr, "invalid chunk after IDAT");
}
else if (!png_memcmp(chunk_start + 4, png_cHRM, 4))
{
{
png_error(png_ptr, "invalid chunk after IDAT");
}
else if (!png_memcmp(chunk_start + 4, png_tRNS, 4))
@ -551,7 +551,7 @@ png_read_end(png_structp png_ptr, png_infop info)
else if (!png_memcmp(chunk_start + 4, png_IDAT, 4))
{
if (length > 0 || png_ptr->mode != PNG_AT_LAST_IDAT)
png_error(png_ptr, "too many IDAT's found");
png_error(png_ptr, "too many IDAT's found");
}
else if (!png_memcmp(chunk_start + 4, png_pHYs, 4))
{
@ -569,7 +569,7 @@ png_read_end(png_structp png_ptr, png_infop info)
png_error(png_ptr, "Out of Place tIME");
if (info)
png_handle_tIME(png_ptr, info, length);
png_handle_tIME(png_ptr, info, length);
else
png_crc_skip(png_ptr, length);
}
@ -605,7 +605,7 @@ png_read_end(png_structp png_ptr, png_infop info)
png_ptr->mode = PNG_AFTER_IEND;
}
else
{
{
if ((chunk_start[4] & 0x20) == 0)
png_error(png_ptr, "Unknown Critical Chunk");
@ -616,7 +616,7 @@ png_read_end(png_structp png_ptr, png_infop info)
if (((crc ^ 0xffffffffL) & 0xffffffffL) !=
(png_ptr->crc & 0xffffffffL))
png_error(png_ptr, "Bad CRC value");
if (png_ptr->mode == PNG_AT_LAST_IDAT)
if (png_ptr->mode == PNG_AT_LAST_IDAT)
png_ptr->mode = PNG_AFTER_IDAT;
} while (png_ptr->mode != PNG_AFTER_IEND);
}
@ -629,37 +629,27 @@ png_read_destroy(png_structp png_ptr, png_infop info, png_infop end_info)
jmp_buf tmp_jmp;
if (info)
{
if (png_ptr->do_free & PNG_FREE_PALETTE)
png_free(png_ptr, info->palette);
#if defined(PNG_READ_BACKGROUND_SUPPORTED) && defined(PNG_READ_bKGD_SUPPORTED)
if (png_ptr->do_free & PNG_FREE_TRANS)
png_free(png_ptr, info->trans);
#endif
#if defined(PNG_READ_hIST_SUPPORTED)
if (png_ptr->do_free & PNG_FREE_HIST)
png_free(png_ptr, info->hist);
#endif
{
#if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_READ_zTXt_SUPPORTED)
for (i = 0; i < info->num_text; i++)
{
png_large_free(png_ptr, info->text[i].key);
}
for (i = 0; i < info->num_text; i++)
{
png_large_free(png_ptr, info->text[i].key);
}
png_free(png_ptr, info->text);
png_large_free(png_ptr, info->text);
#endif
png_memset(info, 0, sizeof(png_info));
}
png_memset(info, 0, sizeof(png_info));
}
if (end_info)
{
#if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_READ_zTXt_SUPPORTED)
for (i = 0; i < end_info->num_text; i++)
for (i = 0; i < end_info->num_text; i++)
{
png_large_free(png_ptr, end_info->text[i].key);
png_large_free(png_ptr, end_info->text[i].key);
}
png_free(png_ptr, end_info->text);
png_large_free(png_ptr, end_info->text);
#endif
png_memset(end_info, 0, sizeof(png_info));
}
@ -669,59 +659,61 @@ png_read_destroy(png_structp png_ptr, png_infop info, png_infop end_info)
png_large_free(png_ptr, png_ptr->prev_row);
#if defined(PNG_READ_DITHER_SUPPORTED)
png_large_free(png_ptr, png_ptr->palette_lookup);
png_free(png_ptr, png_ptr->dither_index);
png_large_free(png_ptr, png_ptr->dither_index);
#endif
#if defined(PNG_READ_GAMMA_SUPPORTED)
png_free(png_ptr, png_ptr->gamma_table);
png_large_free(png_ptr, png_ptr->gamma_table);
#endif
#if defined(PNG_READ_BACKGROUND_SUPPORTED)
png_free(png_ptr, png_ptr->gamma_from_1);
png_free(png_ptr, png_ptr->gamma_to_1);
png_large_free(png_ptr, png_ptr->gamma_from_1);
png_large_free(png_ptr, png_ptr->gamma_to_1);
#endif
if (png_ptr->do_free & PNG_FREE_PALETTE)
png_large_free(png_ptr, png_ptr->palette);
#if defined(PNG_READ_BACKGROUND_SUPPORTED) && defined(PNG_READ_bKGD_SUPPORTED)
if (png_ptr->do_free & PNG_FREE_TRANS)
png_large_free(png_ptr, png_ptr->trans);
#endif
#if defined(PNG_READ_hIST_SUPPORTED)
if (png_ptr->do_free & PNG_FREE_HIST)
png_large_free(png_ptr, png_ptr->hist);
#endif
#if defined(PNG_READ_GAMMA_SUPPORTED)
if (png_ptr->gamma_16_table)
{
for (i = 0; i < (1 << (8 - png_ptr->gamma_shift)); i++)
{
png_free(png_ptr, png_ptr->gamma_16_table[i]);
}
}
#endif
#if defined(PNG_READ_BACKGROUND_SUPPORTED)
png_free(png_ptr, png_ptr->gamma_16_table);
if (png_ptr->gamma_16_from_1)
{
for (i = 0; i < (1 << (8 - png_ptr->gamma_shift)); i++)
{
png_free(png_ptr, png_ptr->gamma_16_from_1[i]);
png_large_free(png_ptr, png_ptr->gamma_16_table[i]);
}
}
png_free(png_ptr, png_ptr->gamma_16_from_1);
#endif
#if defined(PNG_READ_BACKGROUND_SUPPORTED)
png_large_free(png_ptr, png_ptr->gamma_16_table);
if (png_ptr->gamma_16_from_1)
{
for (i = 0; i < (1 << (8 - png_ptr->gamma_shift)); i++)
{
png_large_free(png_ptr, png_ptr->gamma_16_from_1[i]);
}
}
png_large_free(png_ptr, png_ptr->gamma_16_from_1);
if (png_ptr->gamma_16_to_1)
{
for (i = 0; i < (1 << (8 - png_ptr->gamma_shift)); i++)
{
png_free(png_ptr, png_ptr->gamma_16_to_1[i]);
png_large_free(png_ptr, png_ptr->gamma_16_to_1[i]);
}
}
png_free(png_ptr, png_ptr->gamma_16_to_1);
}
png_large_free(png_ptr, png_ptr->gamma_16_to_1);
#endif
#if defined(PNG_READ_BACKGROUND_SUPPORTED)
png_free(png_ptr, png_ptr->trans);
#endif
#if defined(PNG_READ_DITHER_SUPPORTED)
png_free(png_ptr, png_ptr->hist);
#endif
if (!png_ptr->user_palette)
png_free(png_ptr, png_ptr->palette);
inflateEnd(png_ptr->zstream);
png_free(png_ptr, png_ptr->zstream);
inflateEnd(png_ptr->zstream);
png_free(png_ptr, png_ptr->zstream);
#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
png_free(png_ptr, png_ptr->save_buffer);
png_large_free(png_ptr, png_ptr->save_buffer);
#endif
png_memcpy(tmp_jmp, png_ptr->jmpbuf, sizeof (jmp_buf));
png_memset(png_ptr, 0, sizeof (png_struct));
png_memcpy(png_ptr->jmpbuf, tmp_jmp, sizeof (jmp_buf));
png_memcpy(tmp_jmp, png_ptr->jmpbuf, sizeof (jmp_buf));
png_memset(png_ptr, 0, sizeof (png_struct));
png_memcpy(png_ptr->jmpbuf, tmp_jmp, sizeof (jmp_buf));
}

File diff suppressed because it is too large Load Diff

View File

@ -1,10 +1,10 @@
/* pngrutil.c - utilities to 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
January 15, 1996
*/
#define PNG_INTERNAL
@ -30,8 +30,8 @@ png_get_uint_16(png_bytep buf)
{
png_uint_16 i;
i = ((png_uint_16)(*buf) << 8) +
(png_uint_16)(*(buf + 1));
i = (png_uint_16)(((png_uint_16)(*buf) << 8) +
(png_uint_16)(*(buf + 1)));
return i;
}
@ -121,9 +121,9 @@ png_handle_IHDR(png_structp png_ptr, png_infop info, png_uint_32 length)
/* set internal variables */
png_ptr->width = width;
png_ptr->height = height;
png_ptr->bit_depth = bit_depth;
png_ptr->interlaced = interlace_type;
png_ptr->color_type = color_type;
png_ptr->bit_depth = (png_byte)bit_depth;
png_ptr->interlaced = (png_byte)interlace_type;
png_ptr->color_type = (png_byte)color_type;
/* find number of channels */
switch (png_ptr->color_type)
@ -143,8 +143,8 @@ png_handle_IHDR(png_structp png_ptr, png_infop info, png_uint_32 length)
break;
}
/* set up other useful info */
png_ptr->pixel_depth = png_ptr->bit_depth *
png_ptr->channels;
png_ptr->pixel_depth = (png_byte)(png_ptr->bit_depth *
png_ptr->channels);
png_ptr->rowbytes = ((png_ptr->width *
(png_uint_32)png_ptr->pixel_depth + 7) >> 3);
/* call the IHDR callback (which should just set up info) */
@ -163,7 +163,7 @@ png_handle_PLTE(png_structp png_ptr, png_infop info, png_uint_32 length)
png_error(png_ptr, "Invalid Palette Chunk");
num = (int)length / 3;
palette = (png_colorp)png_malloc(png_ptr, num * sizeof (png_color));
palette = (png_colorp)png_large_malloc(png_ptr, num * sizeof (png_color));
png_ptr->do_free |= PNG_FREE_PALETTE;
for (i = 0; i < num; i++)
{
@ -176,7 +176,7 @@ png_handle_PLTE(png_structp png_ptr, png_infop info, png_uint_32 length)
palette[i].blue = buf[2];
}
png_ptr->palette = palette;
png_ptr->num_palette = num;
png_ptr->num_palette = (png_uint_16)num;
png_read_PLTE(png_ptr, info, palette, num);
}
@ -310,10 +310,10 @@ png_handle_tRNS(png_structp png_ptr, png_infop info, png_uint_32 length)
return;
}
png_ptr->trans = (png_bytep)png_malloc(png_ptr, length);
png_ptr->trans = (png_bytep)png_large_malloc(png_ptr, length);
png_ptr->do_free |= PNG_FREE_TRANS;
png_crc_read(png_ptr, png_ptr->trans, length);
png_ptr->num_trans = (int)length;
png_ptr->num_trans = (png_uint_16)length;
}
else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
{
@ -406,7 +406,7 @@ png_handle_hIST(png_structp png_ptr, png_infop info, png_uint_32 length)
}
num = (int)length / 2;
png_ptr->hist = (png_uint_16p)png_malloc(png_ptr,
png_ptr->hist = (png_uint_16p)png_large_malloc(png_ptr,
num * sizeof (png_uint_16));
png_ptr->do_free |= PNG_FREE_HIST;
for (i = 0; i < num; i++)
@ -503,9 +503,7 @@ png_handle_tEXt(png_structp png_ptr, png_infop info, png_uint_32 length)
png_charp key;
png_charp text;
text = NULL;
key = (png_charp )png_large_malloc(png_ptr, length + 1);
key = (png_charp )png_large_malloc(png_ptr, length + 1);
png_crc_read(png_ptr, (png_bytep )key, length);
key[(png_size_t)length] = '\0';
@ -529,10 +527,8 @@ png_handle_zTXt(png_structp png_ptr, png_infop info, png_uint_32 length)
int ret;
png_uint_32 text_size, key_size;
text = NULL;
key = png_large_malloc(png_ptr, length + 1);
png_crc_read(png_ptr, (png_bytep )key, length);
key = png_large_malloc(png_ptr, length + 1);
png_crc_read(png_ptr, (png_bytep )key, length);
key[(png_size_t)length] = '\0';
for (text = key; *text; text++)
@ -585,7 +581,7 @@ png_handle_zTXt(png_structp png_ptr, png_infop info, png_uint_32 length)
{
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,
@ -687,7 +683,7 @@ png_combine_row(png_structp png_ptr, png_bytep row,
{
value = (*sp >> shift) & 0x1;
*dp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
*dp |= (value << shift);
*dp |= (png_byte)(value << shift);
}
if (shift == 0)
@ -725,7 +721,7 @@ png_combine_row(png_structp png_ptr, png_bytep row,
{
value = (*sp >> shift) & 0x3;
*dp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
*dp |= (value << shift);
*dp |= (png_byte)(value << shift);
}
if (shift == 0)
@ -762,7 +758,7 @@ png_combine_row(png_structp png_ptr, png_bytep row,
{
value = (*sp >> shift) & 0xf;
*dp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
*dp |= (value << shift);
*dp |= (png_byte)(value << shift);
}
if (shift == 0)
@ -839,7 +835,7 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass)
dshift = 7 - (int)((final_width + 7) & 7);
for (i = row_info->width; i; i--)
{
v = (*sp >> sshift) & 0x1;
v = (png_byte)((*sp >> sshift) & 0x1);
for (j = 0; j < png_pass_inc[pass]; j++)
{
*dp &= (png_byte)((0x7f7f >> (7 - dshift)) & 0xff);
@ -875,11 +871,11 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass)
dshift = (png_size_t)((3 - ((final_width + 3) & 3)) << 1);
for (i = row_info->width; i; i--)
{
v = (*sp >> sshift) & 0x3;
v = (png_byte)((*sp >> sshift) & 0x3);
for (j = 0; j < png_pass_inc[pass]; j++)
{
*dp &= (png_byte)((0x3f3f >> (6 - dshift)) & 0xff);
*dp |= (v << dshift);
*dp |= (png_byte)(v << dshift);
if (dshift == 6)
{
dshift = 0;
@ -912,11 +908,11 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass)
dshift = (png_size_t)((1 - ((final_width + 1) & 1)) << 2);
for (i = row_info->width; i; i--)
{
v = (*sp >> sshift) & 0xf;
v = (png_byte)((*sp >> sshift) & 0xf);
for (j = 0; j < png_pass_inc[pass]; j++)
{
*dp &= (png_byte)((0xf0f >> (4 - dshift)) & 0xff);
*dp |= (v << dshift);
*dp |= (png_byte)(v << dshift);
if (dshift == 4)
{
dshift = 0;

View File

@ -1,10 +1,10 @@
/* pngtest.c - a simple test program to test libpng
/* pngtest.c - a simple test program to test 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
*/
Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
January 15, 1996
*/
#include <stdio.h>
#include <stdlib.h>
@ -32,12 +32,14 @@ char inbuf[256], outbuf[256];
int main()
{
FILE *fpin, *fpout;
png_bytep row_buf;
png_bytep row_buf;
png_byte * near_row_buf;
png_uint_32 rowbytes;
png_uint_32 y;
int channels, num_pass, pass;
row_buf = (png_bytep )0;
row_buf = (png_bytep)0;
near_row_buf = (png_byte *)0;
fprintf(STDERR, "Testing libpng version %s\n", PNG_LIBPNG_VER_STRING);
@ -73,7 +75,7 @@ int main()
}
if (setjmp(write_ptr.jmpbuf))
{
{
fprintf(STDERR, "libpng write error\n");
fclose(fpin);
fclose(fpout);
@ -91,7 +93,7 @@ int main()
png_read_info(&read_ptr, &info_ptr);
png_write_info(&write_ptr, &info_ptr);
if ((info_ptr.color_type & 3) == 2)
if ((info_ptr.color_type & 3) == 2)
channels = 3;
else
channels = 1;
@ -99,7 +101,8 @@ int main()
channels++;
rowbytes = ((info_ptr.width * info_ptr.bit_depth * channels + 7) >> 3);
row_buf = (png_bytep )malloc((size_t)rowbytes);
near_row_buf = (png_byte *)malloc((size_t)rowbytes);
row_buf = (png_bytep)near_row_buf;
if (!row_buf)
{
fprintf(STDERR, "no memory to allocate row buffer\n");
@ -124,8 +127,11 @@ int main()
{
for (y = 0; y < info_ptr.height; y++)
{
png_read_rows(&read_ptr, (png_bytepp )&row_buf, (png_bytepp )0, 1);
png_write_rows(&write_ptr, (png_bytepp )&row_buf, 1);
#ifdef TESTING
fprintf(STDERR, "Processing line #%ld\n", y);
#endif
png_read_rows(&read_ptr, (png_bytepp)&row_buf, (png_bytepp)0, 1);
png_write_rows(&write_ptr, (png_bytepp)&row_buf, 1);
}
}
@ -138,7 +144,7 @@ int main()
fclose(fpin);
fclose(fpout);
free((void *)row_buf);
free((void *)near_row_buf);
fpin = fopen(inname, "rb");

View File

@ -3,7 +3,8 @@ pngtodo.txt - list of things to do for libpng
for 0.9
improved dithering
final bug fixes
cHRM transformation
cHRM transformation
better documentation
after 1.0
overlaying one image on top of another

View File

@ -2,10 +2,10 @@
/* pngtrans.c - transforms the data in a row
routines used by both readers and writers
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
@ -113,7 +113,7 @@ png_do_invert(png_row_infop row_info, png_bytep row)
i < row_info->rowbytes;
i++, rp++)
{
*rp = ~(*rp);
*rp = (png_byte)(~(*rp));
}
}
}

View File

@ -1,10 +1,10 @@
/* pngwrite.c - general routines to write 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
*/
/* get internal access to png.h */
@ -161,12 +161,12 @@ png_write_end(png_structp png_ptr, png_infop info)
void
png_convert_from_struct_tm(png_timep ptime, struct tm FAR * ttime)
{
ptime->year = 1900 + ttime->tm_year;
ptime->month = ttime->tm_mon + 1;
ptime->day = ttime->tm_mday;
ptime->hour = ttime->tm_hour;
ptime->minute = ttime->tm_min;
ptime->second = ttime->tm_sec;
ptime->year = (png_uint_16)(1900 + ttime->tm_year);
ptime->month = (png_byte)(ttime->tm_mon + 1);
ptime->day = (png_byte)ttime->tm_mday;
ptime->hour = (png_byte)ttime->tm_hour;
ptime->minute = (png_byte)ttime->tm_min;
ptime->second = (png_byte)ttime->tm_sec;
}
void
@ -322,8 +322,8 @@ png_write_row(png_structp png_ptr, png_bytep row)
png_ptr->row_info.width = png_ptr->usr_width;
png_ptr->row_info.channels = png_ptr->usr_channels;
png_ptr->row_info.bit_depth = png_ptr->usr_bit_depth;
png_ptr->row_info.pixel_depth = png_ptr->row_info.bit_depth *
png_ptr->row_info.channels;
png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth *
png_ptr->row_info.channels);
png_ptr->row_info.rowbytes = ((png_ptr->row_info.width *
(png_uint_32)png_ptr->row_info.pixel_depth + 7) >> 3);
@ -421,14 +421,14 @@ png_write_row(png_structp png_ptr, png_bytep row)
#if defined(PNG_WRITE_FLUSH_SUPPORTED)
/* Set the automatic flush interval or 0 to turn flushing off */
void
png_set_flush(png_struct *png_ptr, int nrows)
png_set_flush(png_structp png_ptr, int nrows)
{
png_ptr->flush_dist = (nrows < 0 ? 0 : nrows);
}
/* flush the current output buffers now */
void
png_write_flush(png_struct *png_ptr)
png_write_flush(png_structp png_ptr)
{
int wrote_IDAT;
@ -501,7 +501,7 @@ void
png_set_filtering(png_structp png_ptr, int filter)
{
png_ptr->do_custom_filter = 1;
png_ptr->do_filter = filter;
png_ptr->do_filter = (png_byte)filter;
}
void

View File

@ -1,10 +1,10 @@
/* pngwtran.c - transforms the data in a row for png writers
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
@ -78,13 +78,13 @@ png_do_pack(png_row_infop row_info, png_bytep row, png_byte bit_depth)
else
{
mask = 0x80;
*dp = v;
*dp = (png_byte)v;
dp++;
v = 0;
}
}
if (mask != 0x80)
*dp = v;
*dp = (png_byte)v;
break;
}
case 2:
@ -94,7 +94,7 @@ png_do_pack(png_row_infop row_info, png_bytep row, png_byte bit_depth)
int shift;
png_int_32 i;
int v;
png_byte value;
png_byte value;
sp = row;
dp = row;
@ -102,12 +102,12 @@ png_do_pack(png_row_infop row_info, png_bytep row, png_byte bit_depth)
v = 0;
for (i = 0; i < row_info->width; i++)
{
value = *sp & 0x3;
value = (png_byte)(*sp & 0x3);
v |= (value << shift);
if (shift == 0)
{
shift = 6;
*dp = v;
*dp = (png_byte)v;
dp++;
v = 0;
}
@ -116,7 +116,7 @@ png_do_pack(png_row_infop row_info, png_bytep row, png_byte bit_depth)
sp++;
}
if (shift != 6)
*dp = v;
*dp = (png_byte)v;
break;
}
case 4:
@ -134,13 +134,13 @@ png_do_pack(png_row_infop row_info, png_bytep row, png_byte bit_depth)
v = 0;
for (i = 0; i < row_info->width; i++)
{
value = *sp & 0xf;
value = (png_byte)(*sp & 0xf);
v |= (value << shift);
if (shift == 0)
{
shift = 4;
*dp = v;
*dp = (png_byte)v;
dp++;
v = 0;
}
@ -150,12 +150,12 @@ png_do_pack(png_row_infop row_info, png_bytep row, png_byte bit_depth)
sp++;
}
if (shift != 4)
*dp = v;
*dp = (png_byte)v;
break;
}
}
row_info->bit_depth = bit_depth;
row_info->pixel_depth = bit_depth * row_info->channels;
row_info->pixel_depth = (png_uint_16)(bit_depth * row_info->channels);
row_info->rowbytes =
((row_info->width * row_info->pixel_depth + 7) >> 3);
}
@ -276,7 +276,8 @@ png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
{
png_uint_16 value, v;
v = ((png_uint_16)(*bp) << 8) + (png_uint_16)(*(bp + 1));
v = (png_uint_16)(((png_uint_16)(*bp) << 8) +
(png_uint_16)(*(bp + 1)));
value = 0;
for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
{
@ -285,8 +286,8 @@ png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
else
value |= (png_uint_16)((v >> (-j)) & (png_uint_16)0xffff);
}
*bp = value >> 8;
*(bp + 1) = value & 0xff;
*bp = (png_byte)(value >> 8);
*(bp + 1) = (png_byte)(value & 0xff);
}
}
}

View File

@ -1,10 +1,10 @@
/* pngwutil.c - utilities to write 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
#include "png.h"
@ -142,15 +142,15 @@ png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height,
/* pack the header information into the buffer */
png_save_uint_32(buf, width);
png_save_uint_32(buf + 4, height);
buf[8] = bit_depth;
buf[9] = color_type;
buf[10] = compression_type;
buf[11] = filter_type;
buf[12] = interlace_type;
/* save off the relevent information */
png_ptr->bit_depth = bit_depth;
png_ptr->color_type = color_type;
png_ptr->interlaced = interlace_type;
buf[8] = (png_byte)bit_depth;
buf[9] = (png_byte)color_type;
buf[10] = (png_byte)compression_type;
buf[11] = (png_byte)filter_type;
buf[12] = (png_byte)interlace_type;
/* save off the relevent information */
png_ptr->bit_depth = (png_byte)bit_depth;
png_ptr->color_type = (png_byte)color_type;
png_ptr->interlaced = (png_byte)interlace_type;
png_ptr->width = width;
png_ptr->height = height;
@ -170,7 +170,7 @@ png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height,
png_ptr->channels = 4;
break;
}
png_ptr->pixel_depth = bit_depth * png_ptr->channels;
png_ptr->pixel_depth = (png_byte)(bit_depth * png_ptr->channels);
png_ptr->rowbytes = ((width * (png_uint_32)png_ptr->pixel_depth + 7) >> 3);
/* set the usr info, so any transformations can modify it */
png_ptr->usr_width = png_ptr->width;
@ -184,7 +184,7 @@ png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height,
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;
png_ptr->zstream->opaque = (voidpf)png_ptr;
if (!png_ptr->do_custom_filter)
{
if (png_ptr->color_type == 3 || png_ptr->bit_depth < 8)
@ -476,12 +476,19 @@ png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,
old_max = max_output_ptr;
max_output_ptr = num_output_ptr + 4;
if (output_ptr)
output_ptr = (png_charpp)png_realloc(png_ptr, output_ptr,
max_output_ptr * sizeof (png_charpp),
old_max * sizeof (png_charp));
else
output_ptr = (png_charpp)png_malloc(png_ptr,
if (output_ptr)
{
png_charpp old_ptr;
old_ptr = output_ptr;
output_ptr = (png_charpp)png_large_malloc(png_ptr,
max_output_ptr * sizeof (png_charpp));
png_memcpy(output_ptr, old_ptr,
(png_size_t)(old_max * sizeof (png_charp)));
png_large_free(png_ptr, old_ptr);
}
else
output_ptr = (png_charpp)png_large_malloc(png_ptr,
max_output_ptr * sizeof (png_charp));
}
@ -516,7 +523,7 @@ png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,
/* check to see if we need more room */
if (!png_ptr->zstream->avail_out && ret == Z_OK)
{
/* check to make sure our output array has room */
/* check to make sure our output array has room */
if (num_output_ptr >= max_output_ptr)
{
png_uint_32 old_max;
@ -524,17 +531,24 @@ png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,
old_max = max_output_ptr;
max_output_ptr = num_output_ptr + 4;
if (output_ptr)
output_ptr = (png_charpp)png_realloc(png_ptr, output_ptr,
max_output_ptr * sizeof (png_charp),
old_max * sizeof (png_charp));
else
output_ptr = (png_charpp)png_malloc(png_ptr,
max_output_ptr * sizeof (png_charp));
}
{
png_charpp old_ptr;
/* save off the data */
output_ptr[num_output_ptr] = png_large_malloc(png_ptr,
png_ptr->zbuf_size);
old_ptr = output_ptr;
output_ptr = (png_charpp)png_large_malloc(png_ptr,
max_output_ptr * sizeof (png_charpp));
png_memcpy(output_ptr, old_ptr,
(png_size_t)(old_max * sizeof (png_charp)));
png_large_free(png_ptr, old_ptr);
}
else
output_ptr = (png_charpp)png_large_malloc(png_ptr,
max_output_ptr * sizeof (png_charp));
}
/* save off the data */
output_ptr[num_output_ptr] = png_large_malloc(png_ptr,
png_ptr->zbuf_size);
png_memcpy(output_ptr[num_output_ptr], png_ptr->zbuf,
(png_size_t)png_ptr->zbuf_size);
num_output_ptr++;
@ -556,7 +570,7 @@ png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,
(png_uint_32)(key_len + text_len + 2));
/* write key */
png_write_chunk_data(png_ptr, (png_bytep )key, (png_uint_32)(key_len + 1));
buf[0] = compression;
buf[0] = (png_byte)compression;
/* write compression */
png_write_chunk_data(png_ptr, (png_bytep )buf, (png_uint_32)1);
@ -567,7 +581,7 @@ png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,
png_large_free(png_ptr, output_ptr[i]);
}
if (max_output_ptr)
png_free(png_ptr, output_ptr);
png_large_free(png_ptr, output_ptr);
/* write anything left in zbuf */
if (png_ptr->zstream->avail_out < png_ptr->zbuf_size)
png_write_chunk_data(png_ptr, png_ptr->zbuf,
@ -591,7 +605,7 @@ png_write_pHYs(png_structp png_ptr, png_uint_32 x_pixels_per_unit,
png_save_uint_32(buf, x_pixels_per_unit);
png_save_uint_32(buf + 4, y_pixels_per_unit);
buf[8] = unit_type;
buf[8] = (png_byte)unit_type;
png_write_chunk(png_ptr, png_pHYs, buf, (png_uint_32)9);
}
@ -608,7 +622,7 @@ png_write_oFFs(png_structp png_ptr, png_uint_32 x_offset,
png_save_uint_32(buf, x_offset);
png_save_uint_32(buf + 4, y_offset);
buf[8] = unit_type;
buf[8] = (png_byte)unit_type;
png_write_chunk(png_ptr, png_oFFs, buf, (png_uint_32)9);
}
@ -804,7 +818,7 @@ png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
if (shift == 0)
{
shift = 7;
*dp++ = d;
*dp++ = (png_byte)d;
d = 0;
}
else
@ -812,7 +826,7 @@ png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
}
if (shift != 7)
*dp = d;
*dp = (png_byte)d;
break;
}
case 2:
@ -838,14 +852,14 @@ png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
if (shift == 0)
{
shift = 6;
*dp++ = d;
*dp++ = (png_byte)d;
d = 0;
}
else
shift -= 2;
}
if (shift != 6)
*dp = d;
*dp = (png_byte)d;
break;
}
case 4:
@ -871,14 +885,14 @@ png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
if (shift == 0)
{
shift = 4;
*dp++ = d;
*dp++ = (png_byte)d;
d = 0;
}
else
shift -= 4;
}
if (shift != 4)
*dp = d;
*dp = (png_byte)d;
break;
}
default:
@ -1038,7 +1052,7 @@ png_write_filter_row(png_row_infop row_info, png_bytep row,
if (s1 < mins)
{
mins = s1;
mins = s1;
minf = 1;
}
@ -1056,12 +1070,11 @@ png_write_filter_row(png_row_infop row_info, png_bytep row,
if (s4 < mins)
{
mins = s4;
minf = 4;
}
/* set filter byte */
row[0] = minf;
row[0] = (png_byte)minf;
/* do filter */
switch (minf)
@ -1074,7 +1087,7 @@ png_write_filter_row(png_row_infop row_info, png_bytep row,
{
*rp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
}
break;
break;
/* up filter */
case 2:
for (i = 0, rp = row + (png_size_t)row_info->rowbytes,

View File

@ -1,4 +1,4 @@
readme.txt - for libpng 0.86
readme.txt - for libpng 0.87
This is a bug fix for the second beta version of libpng 1.0, and
a first try at a progressive (push) reader. It hasn't been
@ -60,6 +60,11 @@ You can reach me at:
internet: schalnat@group42.com
CompuServe: 75501,1625
I tend to check my CompuServe account very infrequently, so you may
want to use the internet account. If I don't answer your email
immediately, please be patient. If you don't receive a reply within
a week, you may want to write and ask if I got the first email.
Please do not send me general questions about PNG. Send them to
the address in the specification. At the same time, please do
not send libpng questions to that address, send them to me. I'll
@ -70,7 +75,7 @@ and ...". If in doubt, send questions to me. I'll bounce them
to others, if necessary.
Please do not send suggestions on how to change PNG. We have
been discussing PNG for 9 months now, and it is official and
been discussing PNG for over a year now, and it is official and
finished. If you have suggestions for libpng, however, I'll
gladly listen. Even if your suggestion is not used for version
1.0, it may be used later.