提交 02ad0efb 编写于 作者: A Andreas Dilger 提交者: Glenn Randers-Pehrson

Imported from libpng-0.90.tar

上级 c21f90c3
......@@ -93,11 +93,30 @@ version 0.89
fixed gamma and background correction for paletted images, so
png_correct_palette is not needed unless you are correcting an
external palette (you will need to #define PNG_CORRECT_PALETTE_SUPPORTED
in pngconf.h)
in pngconf.h) - if nobody uses this, it may disappear in the future.
fixed bug with Borland 64K memory allocation (Alexander Lehmann)
fixed bug in interlace handling (Smaraderagd, I think)
fixed bug in interlace handling (Smarasderagd, I think)
added more error checking for writing and image to reduce invalid files
separated read and write functions so that they won't both be linked
into a binary when only reading or writing functionality is used
new pngtest image also has interlacing and zTXt
updated dcumentation to reflect new API
updated documentation to reflect new API
version 0.90
made CRC errors/warnings on critical and ancillary chunks configurable
libpng will use the zlib CRC routines by (compile-time) default
changed DOS small/medium model memory support - needs zlib 1.04 (Tim Wegner)
added external C++ wrapper statements to png.h (Gilles Dauphin)
allow PNG file to be read when some or all of file signature has already
been read from the beginning of the stream (this affects the size of
info_struct and invalidates all programs that use a shared libpng)
fixed png_filler() declarations
fixed? background color conversions
fixed order of error function pointers to match documentation
current chunk name is now available in png_struct to reduce the number
of nearly identical error messages (will simplify multi-lingual
support when available)
try to get ready for unknown-chunk callback functions:
- previously read critical chunks are flagged, so the chunk handling
routines can determine if the chunk is in the right place
- all chunk handling routines have the same prototypes, so we will
be able to handle all chunks via a callback mechanism
readme.txt - for libpng 0.89
This is a bug fix for the third beta version of libpng 1.0. The
changes from libpng-0.88 are bug fixes and some changes to the
API itself to increase robustness with shared libraries. This
release is based on libpng-0.88, but has been modified from that
version by Andreas Dilger <adilger@enel.ucalgary.ca> because the
original author, Guy Schalnat, has not been able to keep up with
the time demands of maintaining this library.
readme.txt - for libpng 0.90
This is the fourth beta version of libpng 1.0. The changes from
libpng-0.89 include bug fixes, a C++ wrapper for png.h, some
additions to the API, as well as internal changes to the library.
**
Note that some of the changes to the png_info structure render
this version of the library binary incompatible with libpng-0.89
if you are using a shared library. Re-compiling the application
should be enough to remove this problem.
**
The additions to 0.89 include the ability to read from a PNG stream
which has had some (or all) of the signature bytes read by the
calling application. This also allows the reading of embedded PNG
streams that do not have the PNG file signature. As well, it is
now possible to set the library action on the detection of chunk
CRC errors. It is possible to set different actions based on
whether the error occurred in a critical or an ancillary chunk.
The callback functions for the error/warning messages have changed
since the last release because their implementation was broken,
since the 0.88 release because their implementation was broken,
and it was thought best to change the API itself (which was only
introduced in libpng-0.88 itself) to alert the user to the change,
rather than mislead the user into thinking their application was
......@@ -40,19 +51,23 @@ used by libpng) and zlib's restrictions, see zlib.h
I have included a general makefile, as well as several machine and compiler
specific ones, but you may have to modify one for your own needs.
You will need zlib 0.95 or later to run this. zlib is a compression
library that is useful for more things then just png files. If
you need a compression library, check out zlib.h. There was a bug in
zlib <= 0.99 which caused it to generate invalid compression streams
on some occasions. Later versions of zlib do not have this problem.
You should use zlib 1.0.4 or later to run this, but it MAY work with
versions as old as zlib 0.95. Even so, there are bugs in older zlib
versions which can cause the output of invalid compression streams for
some images. You will definitely need zlib 1.0.4 or later if you are
taking advantage of the MS-DOS "far" structure allocation for the small
and medium memory models. You should also note that zlib is a
compression library that is useful for more things than just PNG files.
You can use zlib as a drop-in replacement for fread() and fwrite() if
you are so inclined.
zlib should be available at the same place that libpng is.
If not, it should be at ftp.uu.net in /graphics/png
Eventually, it will be at ftp.uu.net in /pub/archiving/zip/zlib
You may also want a copy of the PNG specification. It should
be available at the same place you picked up libpng. If it is
not there, try ftp.uu.net in the /graphics/png directory.
You may also want a copy of the PNG specification. It is available
as an Internet Draft, and RFC, and a W3C Recommendation. Failing
these resources you can try ftp.uu.net in the /graphics/png directory.
This code is currently being archived at ftp.uu.net in the
/graphics/png directory, and on CompuServe, Lib 20 (PNG SUPPORT)
......@@ -70,8 +85,8 @@ Finally, if you get any warning messages when compiling libpng
(note: not zlib), and they are easy to fix, I'd appreciate the
fix. Please mention "libpng" somewhere in the subject line. Thanks.
This release was created and will be supported by myself, and the
PNG group.
This release was created and will be supported by myself (of course
based in a large way on Guy's earlier work), and the PNG group.
adilger@enel.ucalgary.ca
png-implement@dworkin.wustl.edu
......@@ -91,13 +106,60 @@ 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 over a year now, and it is official and
been discussing PNG for a couple years 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.
Files in this distribution:
CHANGES.txt => Description of changes between libpng versions
README => This file
TODO => Things not implemented in the current library
ansi2knr.c => Converts files to K&R style function declarations
build.bat => MS-DOS batch file for Borland compiler
descrip.mms => VMS project file
example.c => Example code for using libpng functions
libpng.txt => Description of libpng and its functions
makefile => Defualt makefile
makefile.aco => ACORN makefile
makefile.ama => Amiga makefile
makefile.atr => Atari makefile
makefile.bor => Borland makefile
makefile.dj2 => DJGPP 2 makefile
makefile.elf => Unix ELF makefile
makefile.knr => Makefile which calls ansi2knr to convert files
makefile.mip => MIPS makefile
makefile.msc => Microsoft C makefile
makefile.std => Standard Unix makefile
makefile.tc => Turbo C makefile
makevms.com => VMS make program
png.c => Basic interface functions common to library
png.h => Library function and interface declarations
pngconf.h => System specific library configuration
pngerror.c => Error/warning message I/O functions
pngmem.c => Memory handling functions
pngpread.c => Progressive reading functions
pngrcb.c => Read callback (data handling) low-level functions
pngread.c => Read data/helper high-level functions
pngrio.c => Lowest-level data read I/O functions
pngrtran.c => Read data transformation functions
pngrutil.c => Read data utility functions
pngtest.c => Library test program
pngtest.png => Library test sample image
pngtrans.c => Common data transformation functions
pngwio.c => Lowest-level write I/O functions
pngwrite.c => High-level write functions
pngwtran.c => Write data transformations
pngwutil.c => Write utility functions
Good luck, and happy coding.
-Andreas Eric Dilger
University of Calgary
Internet: adilger@enel.ucalgary.ca
Web: www-mddsp.enel.ucalgary.ca/People/adilger/
-Guy Eric Schalnat
Group 42, Inc.
Internet: schalnat@group42.com
......
......@@ -5,21 +5,19 @@ for 0.9
final bug fixes
cHRM transformation
better documentation
multi-lingual message support
after 1.0
overlaying one image on top of another
optional palette creation
histogram creation
text conversion between different code types
support for other chunks being defined (sCAl, the gIF series,
and others that people come up with).
support for application-defined chunk handlers
support for embedded PNG usage (MNG)
pull writer
better dithering
keep up with public chunks
other compression libraries
more exotic interlace handling
better filtering (counting huffman bits? filter type inertia?)
better filter selection (counting huffman bits? filter type inertia?)
C++ wrapper
other languages (pascal, for one)
comments of > 64K
comments of > 64K for DOS
......@@ -14,45 +14,61 @@
#include <png.h>
/* check to see if a file is a png file using png_check_sig() */
int check_png(char * file_name)
/* Check to see if a file is a png file using png_check_sig().
If this call is successful, and you are going to keep the file
open, you should call png_set_sig_bytes_read(png_ptr, 8);
once you have created the png_ptr, so that libpng knows it
doesn't have to read the signature again. Make sure you don't
call png_set_sig_bytes_read() with more than 8 bytes read or
give it an incorrect number of bytes read, or you will either
have read too many bytes (your fault), or you are telling libpng
to read the wrong number of magic bytes (also your fault). */
int check_png(char *file_name, FILE **fp)
{
FILE *fp;
char buf[8];
int ret;
fp = fopen(file_name, "rb");
*fp = fopen(file_name, "rb");
if (!fp)
return 0;
ret = fread(buf, 1, 8, fp);
fclose(fp);
ret = fread(buf, 1, 8, *fp);
if (ret != 8)
return 0;
ret = png_check_sig(buf, 8);
/* Check the signature starting at byte 0, and check all 8 bytes */
ret = png_check_sig(buf, 0, 8);
return (ret);
}
/* read a png file. You may want to return an error code if the read
fails (depending upon the failure). */
void read_png(char *file_name)
fails (depending upon the failure). There are two "prototypes" given
here - one where we are given the filename, and we need to open the
file, and the other where we are given an open file (possibly with
some or all of the magic bytes read - see above) and an opened file
for reading. */
------- prototype 1 ----------
void read_png(char *file_name) /* We need to open the file */
{
FILE *fp;
png_structp png_ptr;
png_infop info_ptr;
FILE *fp;
/* open the file */
fp = fopen(file_name, "rb");
if (!fp)
if ((fp = fopen(file_name, "rb")) == NULL)
return;
------- prototype 2 ----------
void read_png(FILE *fp, unsigned int sig_read) /* file is already open */
{
png_structp png_ptr;
png_infop info_ptr;
------- only use one! --------
/* Create and initialize the png_struct with the desired error handler
functions. If you want to use the default stderr and longjump method,
you can supply NULL for the last three parameters. We also check that
the header file is compatible with the library version.
*/
the header file is compatible with the library version. */
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,
(void *)user_error_ptr, user_error_fn, user_warning_fn);
......@@ -88,7 +104,11 @@ void read_png(char *file_name)
png_set_read_fn(png_ptr, (void *)user_io_ptr, user_read_fn);
/* where user_io_ptr is a structure you want available to the callbacks */
/* read the file information */
/* if we have already read some of the signature from the beginning call */
png_set_sig_bytes_read(png_ptr, sig_read);
/* The call to png_read_info() gives us all of the information
from the PNG file before the first IDAT (image data chunk). */
png_read_info(png_ptr, info_ptr);
/* set up the transformations you want. Note that these are
......@@ -120,7 +140,10 @@ void read_png(char *file_name)
png_set_background(png_ptr, &my_background,
PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0);
/* tell libpng to handle the gamma conversion for you */
/* tell libpng to handle the gamma conversion for you. We only
need the second call if the screen_gamma isn't the usual 2.2
or if it is controllable by the user. It may also be a good
idea to allow the user to set the file gamma if it is unknown. */
if (info_ptr->valid & PNG_INFO_gAMA)
png_set_gamma(png_ptr, screen_gamma, info_ptr->gamma);
else
......@@ -398,10 +421,6 @@ void write_png(char *file_name, ... other image information ...)
/* set up the output control if you are using standard C streams */
png_init_io(png_ptr, fp);
/* if you are using replacement message functions, here you would call */
png_set_message_fn(png_ptr, (void *)msg_ptr, user_error_fn, user_warning_fn);
/* where msg_ptr is a structure you want available to the callbacks */
/* set the file information here */
info_ptr->width = ;
info_ptr->height = ;
......
......@@ -56,14 +56,14 @@ II. Structures
There are two main structures that are important to libpng, png_struct
and png_info. The first, png_struct, is an internal structure that
will not, for the most part, be used by a user except as the first
variable passed to every png function call.
variable passed to every libpng function call.
The png_info structure is designed to provide information about the
png file. All of its fields are intended to be examined or modified
by the user. See png.h for a good description of the png_info fields.
png.h is also an invaluable reference for programming with libpng.
And while I'm on the topic, make sure you include the png header file:
And while I'm on the topic, make sure you include the libpng header file:
#include <png.h>
......@@ -86,11 +86,13 @@ file. Libpng provides a simple check to see if a file is a PNG file.
To use it, pass in the first 1 to 8 bytes of the file, and it will
return true or false (1 or 0) depending on whether the bytes could be
part of a PNG file. Of course, the more bytes you pass in, the
greater the accuracy of the prediction. If you pass in more then
eight bytes, libpng will only look at the first eight bytes. However,
because libpng automatically checks the file header, this is not often
necessary, and you should pass a newly opened file pointer to libpng
when reading a file.
greater the accuracy of the prediction.
If you are intending to keep the file pointer open for use in libpng,
you must ensure you don't read more than 8 bytes from the beginning
of the file, and you also have to make a call to png_set_sig_bytes_read()
with the number of bytes you read from the beginning. Libpng will
then only check the bytes (if any) that your program didn't read.
(*): If you are not using the standard I/O functions, you will need
to replace them with custom functions. See the discussion under
......@@ -102,12 +104,11 @@ Customizing libpng.
return;
}
fread(header, 1, number, fp);
is_png = png_check_sig(header, number);
is_png = png_check_sig(header, 0, number);
if (!is_png)
{
return;
}
fclose(fp);
Next, png_struct and png_info need to be allocated and initialized.
In order to ensure that the size of these structures is correct even
......@@ -134,20 +135,20 @@ Changes to Libpng below regarding the old initialization functions.
return;
}
The error handling routines passed to png_create_read_struct()
are only necessary if you are not using the libpng supplied
error handling functions. When libpng encounters an error,
it expects to longjmp back to your routine. Therefore, you
will need to call setjmp and pass the jmpbuf field of your
png_struct. If you read the file from different routines, you
will need to update the jmpbuf field every time you enter a new
routine that will call a png_ function. See your documentation
of setjmp/longjmp for your compiler for more information on
setjmp/longjmp. See the discussion on libpng error handling
in the Customizing Libpng section below for more information on
the libpng error handling. If an error occurs, and libpng
longjmp's back to your setjmp, you will want to call
png_destroy_read_struct() to free any memory.
The error handling routines passed to png_create_read_struct() are only
necessary if you are not using the libpng supplied error handling
functions. When libpng encounters an error, it expects to longjmp back
to your routine. Therefore, you will need to call setjmp and pass the
jmpbuf field of your png_struct. If you read the file from different
routines, you will need to update the jmpbuf field every time you enter
a new routine that will call a png_ function.
See your documentation of setjmp/longjmp for your compiler for more
information on setjmp/longjmp. See the discussion on libpng error
handling in the Customizing Libpng section below for more information on
the libpng error handling. If an error occurs, and libpng longjmp's
back to your setjmp, you will want to call png_destroy_read_struct() to
free any memory.
if (setjmp(png_ptr->jmpbuf))
{
......@@ -165,10 +166,16 @@ Libpng section below.
png_init_io(png_ptr, fp);
If you had previously opened the file and read any of the signature from
the beginning in order to see if this was a PNG file, you need to let
libpng know that there are some bytes missing from the start of the file.
png_set_sig_bytes(png_ptr, number);
You are now ready to read all the file information up to the actual
image data. You do this with a call to png_read_info().
png_read_info(png_ptr, info_ptr);
png_read_info(png_ptr, info_ptr);
The png_info structure is now filled in with all the data necessary
to read the file. Some of the more important parts of the info_ptr are:
......@@ -183,8 +190,13 @@ to read the file. Some of the more important parts of the info_ptr are:
bit_depth times the channels
rowbytes - number of bytes needed to hold a row
interlace_type - currently 0 for none, 1 for interlaced
signature - holds the signature read from the file (if any). The
data is kept in the same offset it would be if the
whole signature were read (ie if you had already read
in 4 bytes of signature, the remaining 4 bytes would
be in signature[4] through signature[7]).
valid - this details which optional chunks were found in the
file to see if a chunk was present, AND '&' valid with
file. To see if a chunk was present, AND '&' valid with
the appropriate PNG_INFO_<chunk name> define.
These are also important, but their validity depends on whether a
......@@ -217,7 +229,7 @@ keyword/text pairs, one pair per chunk. While there are suggested
keywords, there is no requirement to restrict the use to these
strings. There is a requirement to have at least one character for a
keyword. It is strongly suggested that keywords be sensible to humans
(that's the point), so don't use abbreviations. See the png
(that's the point), so don't use abbreviations. See the PNG
specification for more details. There is also no requirement to have
text after the keyword.
......@@ -243,6 +255,13 @@ checks to see if it has data that it can do somthing with, you should
make sure to only enable a transformation if it will be valid for the
data. For example, don't swap red and blue on grayscale data.
The colors used for the background and transparency values should be
supplied in the same format/depth as the current image data. They
are stored in the same format/depth as the image data in a bKGD or tRNS
chunk, so this is what libpng expects for this data. The colors are
transformed to keep in sync with the image data when an application
calls the png_update_info() routine (see below).
Data will be decoded into the supplied row buffers packed into bytes
unless the library has been told to transform it into another format.
For example, 4 bit/pixel paletted or grayscale data will be returned
......@@ -747,7 +766,7 @@ Libpng section below.
You now have the option of modifying how the compression library will
run. The following functions are mainly for testing, but may be useful
in some cases, like if you need to write png files extremely fast and
in some cases, like if you need to write PNG files extremely fast and
are willing to give up some compression, or if you want to get the
maximum possible compression at the expense of slower writing. If you
have no special needs in this area, let the library do what it wants by
......
# makefile for libpng on Acorn RISCOS
# Project: libpng
......@@ -8,108 +7,43 @@ C++flags = -c -depend !Depend -IC: -throwback
Linkflags = -aif -c++ -o $@
ObjAsmflags = -throwback -NoCache -depend !Depend
CMHGflags =
LibFileflags = -c -o $@
LibFileflags = -c -l -o $@
Squeezeflags = -o $@
# Final targets:
@.libpng-lib: @.o.png @.o.pngerror @.o.pngrio @.o.pngwio @.o.pngmem \
@.o.pngpread @.o.pngrcb @.o.pngread @.o.pngrtran @.o.pngrutil \
@.o.pngtrans @.o.pngwrite @.o.pngwtran @.o.pngwutil
@.o.pngpread @.o.pngrcb @.o.pngread @.o.pngrtran @.o.pngrutil @.o.pngtrans @.o.pngwrite \
@.o.pngwtran @.o.pngwutil
LibFile $(LibFileflags) @.o.png @.o.pngerror @.o.pngrio @.o.pngwio \
@.o.pngmem @.o.pngpread @.o.pngrcb @.o.pngread @.o.pngrtran \
@.o.pngrutil @.o.pngtrans @.o.pngwrite @.o.pngwtran @.o.pngwutil
@.test: @.tests.pngtest
echo Please run "Test" in directory tests
@.tests.pngtest: @.o.pngtest @.libpng-lib C:o.Stubs Zlib:zlib_lib
Link $(Linkflags) @.o.pngtest @.libpng-lib C:o.Stubs Zlib:zlib_lib
@.o.pngmem @.o.pngpread @.o.pngrcb @.o.pngread @.o.pngrtran @.o.pngrutil @.o.pngtrans \
@.o.pngwrite @.o.pngwtran @.o.pngwutil
@.mm-libpng-lib: @.mm.png @.mm.pngerror @.mm.pngrio @.mm.pngwio @.mm.pngmem \
@.mm.pngpread @.mm.pngrcb @.mm.pngread @.mm.pngrtran @.mm.pngrutil @.mm.pngtrans \
@.mm.pngwrite @.mm.pngwtran @.mm.pngwutil
LibFile $(LibFileflags) @.mm.png @.mm.pngerror @.mm.pngrio @.mm.pngwio \
@.mm.pngmem @.mm.pngpread @.mm.pngrcb @.mm.pngread @.mm.pngrtran @.mm.pngrutil \
@.mm.pngtrans @.mm.pngwrite @.mm.pngwtran @.mm.pngwutil
# User-editable dependencies:
Test: @.pngtest
<Prefix$Dir>.PngTest
@remove <Prefix$Dir>.pngout_png
#It would be nice if you could stop "make" listing from here on!
@.pngtest: @.o.pngtest @.libpng-lib C:o.Stubs Zlib:zlib_lib
Link $(Linkflags) @.o.pngtest @.libpng-lib C:o.Stubs Zlib:zlib_lib
.SUFFIXES: .o .mm .c
.c.mm:
MemCheck.CC cc $(ccflags) -o $@ LibPng:$<
.c.o:
cc $(ccflags) -o $@ $<
# Static dependencies:
@.o.example: @.tests.c.example
cc $(ccflags) -o @.o.example @.tests.c.example
@.o.pngtest: @.tests.c.pngtest
cc $(ccflags) -o @.o.pngtest @.tests.c.pngtest
# Dynamic dependencies:
o.png: c.png
o.png: h.png
o.png: Zlib:h.zlib
o.png: Zlib:h.zconf
o.png: h.pngconf
o.pngerror: c.pngerror
o.pngerror: h.png
o.pngerror: Zlib:h.zlib
o.pngerror: Zlib:h.zconf
o.pngerror: h.pngconf
o.pngrio: c.pngrio
o.pngrio: h.png
o.pngrio: Zlib:h.zlib
o.pngrio: Zlib:h.zconf
o.pngrio: h.pngconf
o.pngwio: c.pngwio
o.pngwio: h.png
o.pngwio: Zlib:h.zlib
o.pngwio: Zlib:h.zconf
o.pngwio: h.pngconf
o.pngmem: c.pngmem
o.pngmem: h.png
o.pngmem: Zlib:h.zlib
o.pngmem: Zlib:h.zconf
o.pngmem: h.pngconf
o.pngpread: c.pngpread
o.pngpread: h.png
o.pngpread: Zlib:h.zlib
o.pngpread: Zlib:h.zconf
o.pngpread: h.pngconf
o.pngrcb: c.pngrcb
o.pngrcb: h.png
o.pngrcb: Zlib:h.zlib
o.pngrcb: Zlib:h.zconf
o.pngrcb: h.pngconf
o.pngread: c.pngread
o.pngread: h.png
o.pngread: Zlib:h.zlib
o.pngread: Zlib:h.zconf
o.pngread: h.pngconf
o.pngrtran: c.pngrtran
o.pngrtran: h.png
o.pngrtran: Zlib:h.zlib
o.pngrtran: Zlib:h.zconf
o.pngrtran: h.pngconf
o.pngrutil: c.pngrutil
o.pngrutil: h.png
o.pngrutil: Zlib:h.zlib
o.pngrutil: Zlib:h.zconf
o.pngrutil: h.pngconf
o.pngtrans: c.pngtrans
o.pngtrans: h.png
o.pngtrans: Zlib:h.zlib
o.pngtrans: Zlib:h.zconf
o.pngtrans: h.pngconf
o.pngwrite: c.pngwrite
o.pngwrite: h.png
o.pngwrite: Zlib:h.zlib
o.pngwrite: Zlib:h.zconf
o.pngwrite: h.pngconf
o.pngwtran: c.pngwtran
o.pngwtran: h.png
o.pngwtran: Zlib:h.zlib
o.pngwtran: Zlib:h.zconf
o.pngwtran: h.pngconf
o.pngwutil: c.pngwutil
o.pngwutil: h.png
o.pngwutil: Zlib:h.zlib
o.pngwutil: Zlib:h.zconf
o.pngwutil: h.pngconf
o.pngtest: tests.c.pngtest
o.pngtest: h.png
o.pngtest: Zlib:h.zlib
o.pngtest: Zlib:h.zconf
o.pngtest: h.pngconf
# makefile for libpng on (linux) ELF
# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc.
# Copyright (C) 1996, 1997 Andreas Dilger
# For conditions of distribution and use, see copyright notice in png.h
CC=gcc
CFLAGS=-I../zlib -O2 -Wall -fPIC
CFLAGS=-I../zlib -Wall -Wwrite-strings -Wpointer-arith \
-Wstrict-prototypes -Wmissing-prototypes -O2 -fPIC
LDFLAGS=-L. -Wl,-rpath,. -L../zlib/ -Wl,-rpath,../zlib/ -lpng -lz -lm
RANLIB=ranlib
#RANLIB=echo
PNGVER = 0.89
PNGMAJ = 0
PNGMIN = 90
PNGVER = $(PNGMAJ).$(PNGMIN)
# where make install puts libpng.a, libpng.so*, and png.h
prefix=/usr/local
......@@ -24,14 +27,14 @@ libpng.a: $(OBJS)
ar rc $@ $(OBJS)
$(RANLIB) $@
libpng.so: libpng.so.1
ln -sf libpng.so.1 libpng.so
libpng.so: libpng.so.$(PNGMAJ)
ln -sf libpng.so.$(PNGMAJ) libpng.so
libpng.so.1: libpng.so.1.$(PNGVER)
ln -sf libpng.so.1.$(PNGVER) libpng.so.1
libpng.so.$(PNGMAJ): libpng.so.$(PNGVER)
ln -sf libpng.so.$(PNGVER) libpng.so.$(PNGMAJ)
libpng.so.1.$(PNGVER): $(OBJS)
gcc -shared -Wl,-soname,libpng.so.1 -o libpng.so.1.$(PNGVER) $(OBJS)
libpng.so.$(PNGVER): $(OBJS)
gcc -shared -Wl,-soname,libpng.so.$(PNGMAJ) -o libpng.so.$(PNGVER) $(OBJS)
pngtest: pngtest.o libpng.so
$(CC) -o pngtest $(CCFLAGS) pngtest.o $(LDFLAGS)
......@@ -39,21 +42,21 @@ pngtest: pngtest.o libpng.so
test: pngtest
./pngtest
install: libpng.so.1.$(PNGVER)
install: libpng.so.$(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)
cp libpng.so.$(PNGVER) $(prefix)/lib
chmod 755 $(prefix)/lib/libpng.so.$(PNGVER)
-@/bin/rm $(prefix)/lib/libpng.so.$(PNGMAJ) $(prefix)/lib/libpng.so
(cd $(prefix)/lib; ln -sf libpng.so.$(PNGVER) libpng.so.$(PNGMAJ); \
ln -sf libpng.so.$(PNGMAJ) libpng.so)
clean:
rm -f *.o libpng.so.1.$(PNGVER) libpng.so.1 libpng.so pngtest pngout.png
rm -f *.o libpng.a libpng.so* pngtest pngout.png
# DO NOT DELETE THIS LINE -- make depend depends on it.
......
/* png.c - location for general purpose png functions
libpng 1.0 beta 3 - version 0.89
libpng 1.0 beta 4 - version 0.90
For conditions of distribution and use, see copyright notice in png.h
Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
May 25, 1996
January 10, 1997
*/
#define PNG_INTERNAL
......@@ -13,7 +13,7 @@
/* version information for c files. This better match the version
string defined in png.h */
char png_libpng_ver[] = "0.89";
char png_libpng_ver[] = "0.90";
/* place to hold the signiture string for a png file. */
png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
......@@ -70,15 +70,52 @@ int FARDATA png_pass_mask[] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
int FARDATA png_pass_dsp_mask[] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
/* Tells libpng that we have already handled the first "num_bytes" bytes
* of the PNG file signature. If the PNG data is embedded into another
* stream we can set num_bytes = 8 so that libpng will not attempt to read
* or write any of the magic bytes before it starts on the IHDR.
*/
void
png_set_sig_bytes(png_structp png_ptr, int num_bytes)
{
if (num_bytes > 8)
png_error(png_ptr, "Too many bytes for PNG signature.");
png_ptr->sig_bytes = num_bytes < 0 ? 0 : num_bytes;
}
/* Checks whether the supplied bytes match the PNG signature. We allow
* checking less than the full 8-byte signature so that those apps that
* already read the first few bytes of a file to determine the file type
* can simply check the remaining bytes for extra assurance. Returns
* an integer less than, equal to, or greater than zero if sig is found,
* respectively, to be less than, to match, or be greater than the correct
* PNG signature (this is the same behaviour as strcmp, memcmp, etc).
*/
int
png_check_sig(png_bytep sig, int num)
png_sig_cmp(png_bytep sig, int start, int num_to_check)
{
if (num > 8)
num = 8;
if (num < 1)
if (num_to_check > 8)
num_to_check = 8;
else if (num_to_check < 1)
return 0;
if (start > 7 || start < 0)
return 0;
return (!png_memcmp(sig, png_sig, num));
if (start + num_to_check > 8)
num_to_check = 8 - start;
return (png_memcmp(sig, &png_sig[start], (unsigned int)num_to_check));
}
/* (Obsolete) function to check signature bytes. It does not allow one
to check a partial signature. This function will be removed in the
future - use png_sig_cmp(). */
int
png_check_sig(png_bytep sig, int num)
{
return !png_sig_cmp(sig, 0, num);
}
/* Function to allocate memory for zlib. */
......@@ -88,7 +125,7 @@ png_zalloc(voidpf png_ptr, uInt items, uInt size)
png_voidp ptr;
png_uint_32 num_bytes;
ptr = png_large_malloc((png_structp)png_ptr,
ptr = png_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)
......@@ -108,26 +145,27 @@ png_zalloc(voidpf png_ptr, uInt items, uInt size)
void
png_zfree(voidpf png_ptr, voidpf ptr)
{
png_large_free((png_structp)png_ptr, (png_voidp)ptr);
png_free((png_structp)png_ptr, (png_voidp)ptr);
}
/* reset the crc variable to 32 bits of 1's. Care must be taken
in case crc is > 32 bits to leave the top bits 0 */
/* Reset the CRC variable to 32 bits of 1's. Care must be taken
in case CRC is > 32 bits to leave the top bits 0. */
void
png_reset_crc(png_structp png_ptr)
{
/* set crc to all 1's */
#ifdef PNG_USE_OWN_CRC
png_ptr->crc = 0xffffffffL;
#else
png_ptr->crc = crc32(0, Z_NULL, 0);
#endif
}
/* Note: the crc code below was copied from the sample code in the
PNG spec, with appropriate modifications made to ensure the
variables are large enough */
/* table of crc's of all 8-bit messages. If you wish to png_malloc this
table, turn this into a pointer, and png_malloc it in make_crc_table().
#ifdef PNG_USE_OWN_CRC
/* Table of CRC's of all 8-bit messages. If you wish to png_malloc this
table, turn this into a pointer, and png_malloc() it in make_crc_table().
You may then want to hook it into png_struct and free it with the
destroy functions. */
destroy functions. Another alternative is to pre-fill the table. */
static png_uint_32 crc_table[256];
/* Flag: has the table been computed? Initially false. */
......@@ -150,9 +188,9 @@ make_crc_table(void)
crc_table_computed = 1;
}
/* update a running crc with the bytes buf[0..len-1]--the crc should be
/* Update a running CRC with the bytes buf[0..len-1]--the crc should be
initialized to all 1's, and the transmitted value is the 1's complement
of the final running crc. */
of the final running CRC. */
static png_uint_32
update_crc(png_uint_32 crc, png_bytep buf, png_uint_32 len)
{
......@@ -176,8 +214,9 @@ update_crc(png_uint_32 crc, png_bytep buf, png_uint_32 len)
return c;
}
#endif /* PNG_USE_OWN_CRC */
/* calculate the crc over a section of data. Note that while we
/* Calculate the crc over a section of data. Note that while we
are passing in a 32 bit value for length, on 16 bit machines, you
would need to use huge pointers to access all that data. If you
need this, put huge here and above. */
......@@ -185,9 +224,18 @@ void
png_calculate_crc(png_structp png_ptr, png_bytep ptr,
png_uint_32 length)
{
#ifdef PNG_USE_OWN_CRC
png_ptr->crc = update_crc(png_ptr->crc, ptr, length);
#else
png_ptr->crc = crc32(png_ptr->crc, ptr, length);
#endif
}
/* Allocate the memory for an info_struct for the application. We don't
really need the png_ptr, but it could potentially be useful in the
future. This should be used in favour of malloc(sizeof(png_info))
and png_info_init() so that applications that want to use a shared
libpng don't have to be recompiled if png_info changes size. */
png_infop
png_create_info_struct(png_structp png_ptr)
{
......@@ -195,23 +243,65 @@ png_create_info_struct(png_structp png_ptr)
if ((info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO)) != NULL)
{
png_memset(info_ptr, 0, sizeof(png_info));
png_ptr->do_free |= PNG_FREE_INFO;
png_info_init(info_ptr);
}
return info_ptr;
}
/* This function frees the memory associated with a single info struct.
Normally, one would use either png_destroy_read_struct() or
png_destroy_write_struct() to free an info struct, but this may be
useful for some applications. */
void
png_info_init(png_infop info)
png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr)
{
png_infop info_ptr = NULL;
if (info_ptr_ptr)
info_ptr = *info_ptr_ptr;
if (info_ptr)
{
png_info_destroy(png_ptr, info_ptr);
png_destroy_struct((png_voidp)info_ptr);
*info_ptr_ptr = (png_infop)NULL;
}
}
/* Initialize the info structure. This is now an internal function (0.89)
and applications using it are urged to use png_create_info_struct()
instead. */
void
png_info_init(png_infop info_ptr)
{
/* set everything to 0 */
png_memset(info, 0, sizeof (png_info));
png_memset(info_ptr, 0, sizeof (png_info));
}
/* This is an internal routine to free any memory that the info struct is
pointing to before re-using it or freeing the struct itself. */
void
png_info_destroy(png_structp png_ptr, png_infop info_ptr)
{
#if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_READ_zTXt_SUPPORTED)
int i;
for (i = 0; i < info_ptr->num_text; i++)
{
png_free(png_ptr, info_ptr->text[i].key);
}
png_free(png_ptr, info_ptr->text);
#endif
png_info_init(info_ptr);
}
/* This function returns a pointer to the io_ptr associated with the user
functions. The application should free any memory associated with this
pointer before png_write_destroy and png_read_destroy are called. */
pointer before png_write_destroy() or png_read_destroy() are called. */
png_voidp
png_get_io_ptr(png_structp png_ptr)
{
......
此差异已折叠。
/* pngconf.c - machine configurable file for libpng
libpng 1.0 beta 3 - version 0.89
libpng 1.0 beta 4 - version 0.90
For conditions of distribution and use, see copyright notice in png.h
Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
May 25, 1996
December 3, 1996
*/
/* Any machine specific code is near the front of this file, so if you
......@@ -15,7 +15,7 @@
#ifndef PNGCONF_H
#define PNGCONF_H
/* this is the size of the compression buffer, and thus the size of
/* This is the size of the compression buffer, and thus the size of
an IDAT chunk. Make this whatever size you feel is best for your
machine. One of these will be allocated per png_struct. When this
is full, it writes the data to the disk, and does some other
......@@ -29,14 +29,7 @@
#define PNG_ZBUF_SIZE 8192
/* 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
used to help portability between machines. To make it simpler to
setup libpng on a machine, this currently uses zlib's definitions, so
any changes should be made in zlib. Libpng will check zlib's settings
and adjust it's own accordingly. */
/* if you are running on a machine where you cannot allocate more then
/* If you are running on a machine where you cannot allocate more then
64K of memory, uncomment this. While libpng will not normally need
that much memory in a chunk (unless you load up a very large file),
zlib needs to know how big of a chunk it can use, and libpng thus
......@@ -48,7 +41,7 @@
#define PNG_MAX_ALLOC_64K
#endif
/* this protects us against compilers which run on a windowing system
/* This protects us against compilers which run on a windowing system
and thus don't have or would rather us not use the stdio types:
stdin, stdout, and stderr. The only one currently used is stderr
in png_error() and png_warning(). #defining PNG_NO_STDIO will
......@@ -56,14 +49,19 @@
/* #define PNG_NO_STDIO */
/* this macro protects us against machines that don't have function
prototypes. If your compiler does not handle function prototypes,
define this macro. I've always been able to use _NO_PROTO as the
indicator, but you may need to drag the empty declaration out in
front of here, or change the ifdef to suit your own needs. */
/* for FILE. If you are not using standard io, you don't need this */
#ifndef PNG_NO_STDIO
#include <stdio.h>
#endif
/* This macro protects us against machines that don't have function
prototypes (ie K&R style headers). If your compiler does not handle
function prototypes, define this macro. I've always been able to use
_NO_PROTO as the indicator, but you may need to drag the empty declaration
out in front of here, or change the ifdef to suit your own needs. */
#ifndef PNGARG
#ifdef OF
#ifdef OF /* Zlib prototype munger */
#define PNGARG(arglist) OF(arglist)
#else
......@@ -77,39 +75,65 @@
#endif /* PNGARG */
/* Try to determine if we are compiling on a Mac */
#if defined(__MWERKS__) ||defined(applec) ||defined(THINK_C) ||defined(__SC__)
#define MACOS
#endif
/* enough people need this for various reasons to include it here */
#if !defined(MACOS) && !defined(RISCOS)
#include <sys/types.h>
#endif
/* need the time information for reading tIME chunks */
#include <time.h>
/* for FILE. If you are not using standard io, you don't need this */
#include <stdio.h>
/* This is an attempt to force a single setjmp behaviour on Linux */
#ifdef linux
#ifdef _BSD_SOURCE
#define _PNG_SAVE_BSD_SOURCE
#undef _BSD_SOURCE
#endif
#ifdef _SETJMP_H
error: png.h already includes setjmp.h
#endif
#endif /* linux */
/* include setjmp.h for error handling */
#include <setjmp.h>
#ifdef linux
#ifdef _PNG_SAVE_BSD_SOURCE
#define _BSD_SOURCE
#undef _PNG_SAVE_BSD_SOURCE
#endif
#endif /* linux */
#ifdef BSD
#include <strings.h>
#else
#include <string.h>
#endif
/* other defines for things like memory and the like can go here. These
/* Other defines for things like memory and the like can go here. These
are the only files included in libpng, so if you need to change them,
change them here. They are only included if PNG_INTERNAL is defined. */
#ifdef PNG_INTERNAL
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
/* other defines specific to compilers can go here. Try to keep
/* Other defines specific to compilers can go here. Try to keep
them inside an appropriate ifdef/endif pair for portability */
/* for some reason, Borland C++ defines memcmp, etc. in mem.h, not
#ifdef MACOS
#include <fp.h>
#else
#include <math.h>
#endif
/* For some reason, Borland C++ defines memcmp, etc. in mem.h, not
stdlib.h like it should (I think). Or perhaps this is a C++
feature */
feature? */
#ifdef __TURBOC__
#include <mem.h>
#include "alloc.h"
......@@ -119,17 +143,17 @@
#include <malloc.h>
#endif
/* this controls how fine the dithering gets. As this allocates
/* This controls how fine the dithering gets. As this allocates
a largish chunk of memory (32K), those who are not as concerned
with dithering quality can decrease some or all of these */
with dithering quality can decrease some or all of these. */
#define PNG_DITHER_RED_BITS 5
#define PNG_DITHER_GREEN_BITS 5
#define PNG_DITHER_BLUE_BITS 5
/* this controls how fine the gamma correction becomes when you
/* This controls how fine the gamma correction becomes when you
are only interested in 8 bits anyway. Increasing this value
results in more memory being used, and more pow() functions
being called to fill in the gamma tables. Don't get this
being called to fill in the gamma tables. Don't set this
value less then 8, and even that may not work (I haven't tested
it). */
......@@ -137,32 +161,33 @@
#endif /* PNG_INTERNAL */
/* the following uses const char * instead of char * for error
/* The following uses const char * instead of char * for error
and warning message functions, so some compilers won't complain.
If you want to use const, define PNG_USE_CONST here. It is not
normally defined to make configuration easier, as it is not a
critical part of the code.
*/
#define PNG_USE_CONST
#ifdef PNG_USE_CONST
# define PNG_CONST const
#else
# define PNG_CONST
#endif
/* The following defines give you the ability to remove code
from the library that you will not be using. I wish I
could figure out how to automate this, but I can't do
that without making it seriously hard on the users. So
if you are not using an ability, change the #define to
and #undef, and that part of the library will not be
compiled. If your linker can't find a function, you
may want to make sure the ability is defined here.
Some of these depend upon some others being defined.
I haven't figured out all the interactions here, so
you may have to experiment awhile to get everything
to compile.
*/
/* The following defines give you the ability to remove code from the
library that you will not be using. I wish I could figure out how to
automate this, but I can't do that without making it seriously hard
on the users. So if you are not using an ability, change the #define
to and #undef, and that part of the library will not be compiled. If
your linker can't find a function, you may want to make sure the
ability is defined here. Some of these depend upon some others being
defined. I haven't figured out all the interactions here, so you may
have to experiment awhile to get everything to compile. If you are
creating or using a shared library, you probably shouldn't touch this,
as it will affect the size of the structures, and this will cause bad
things to happen if the library and/or application ever change. */
/* Any transformations you will not be using can be undef'ed here */
#define PNG_PROGRESSIVE_READ_SUPPORTED
......@@ -179,7 +204,6 @@
#define PNG_READ_FILLER_SUPPORTED
#define PNG_READ_GAMMA_SUPPORTED
#define PNG_READ_GRAY_TO_RGB_SUPPORTED
#undef PNG_CORRECT_PALETTE_SUPPORTED
#define PNG_WRITE_INTERLACING_SUPPORTED
#define PNG_WRITE_SHIFT_SUPPORTED
......@@ -190,6 +214,10 @@
#define PNG_WRITE_FILLER_SUPPORTED
#define PNG_WRITE_FLUSH_SUPPORTED
/* These functions are turned off by default, as they will be phased out. */
#undef PNG_USE_OWN_CRC
#undef PNG_CORRECT_PALETTE_SUPPORTED
/* any chunks you are not interested in, you can undef here. The
ones that allocate memory may be expecially important (hIST,
tEXt, zTXt, tRNS) Others will just save time and make png_info
......@@ -221,10 +249,10 @@
#define PNG_WRITE_tEXt_SUPPORTED
#define PNG_WRITE_zTXt_SUPPORTED
/* some typedefs to get us started. These should be safe on most of the
common platforms. The typedefs should be at least as large
as the numbers suggest (a png_uint_32 must be at least 32 bits long),
but they don't have to be exactly that size. */
/* Some typedefs to get us started. These should be safe on most of the
common platforms. The typedefs should be at least as large as the
numbers suggest (a png_uint_32 must be at least 32 bits long), but they
don't have to be exactly that size. */
typedef unsigned long png_uint_32;
typedef long png_int_32;
......@@ -232,7 +260,7 @@ typedef unsigned short png_uint_16;
typedef short png_int_16;
typedef unsigned char png_byte;
/* this is usually size_t. it is typedef'ed just in case you need it to
/* This is usually size_t. It is typedef'ed just in case you need it to
change (I'm not sure if you will or not, so I thought I'd be safe) */
typedef size_t png_size_t;
......@@ -243,10 +271,10 @@ typedef size_t png_size_t;
model independent data. As of version Zlib .95, the necessary changes
have been made in Zlib. The USE_FAR_KEYWORD define triggers other
changes that are needed. Most of the far keyword changes are hidden
inside typedefs with suffix "f". Tim Wegner */
inside typedefs with suffix "f". (Tim Wegner) */
/* SJT: Separate compiler dependencies */
/* SJT: problem here is that zlib.h always defines FAR */
/* Separate compiler dependencies (problem here is that zlib.h always
defines FAR. (SJT) */
#ifdef __BORLANDC__
#if defined(__LARGE__) || defined(__HUGE__) || defined(__COMPACT__)
#define LDATA 1
......@@ -263,9 +291,9 @@ typedef size_t png_size_t;
#define USE_FAR_KEYWORD
#endif /* LDATA != 1 */
/* SJT: Possibly useful for moving data out of default segment.
Uncomment it if you want. Could also define FARDATA as const
if your compiler supports it.
/* Possibly useful for moving data out of default segment.
Uncomment it if you want. Could also define FARDATA as
const if your compiler supports it. (SJT)
# define FARDATA FAR
*/
#endif /* __WIN32__, __FLAT__ */
......@@ -273,16 +301,16 @@ typedef size_t png_size_t;
#endif /* __BORLANDC__ */
/* SJT: Suggest testing for specific compiler first before
testing for FAR. The Watcom compiler defines both __MEDIUM__
and M_I86MM, making reliance oncertain keywords suspect
*/
/* Suggest testing for specific compiler first before testing for
FAR. The Watcom compiler defines both __MEDIUM__ and M_I86MM,
making reliance oncertain keywords suspect. (SJT) */
/* MSC Medium model */
#if defined(FAR)
# if defined(M_I86MM)
# define USE_FAR_KEYWORD
# define FARDATA FAR /* SJT: added */
# define FARDATA FAR
# include <dos.h>
# endif
#endif
......@@ -293,21 +321,16 @@ typedef size_t png_size_t;
/* SJT: At this point FAR is always defined */
/* not used anymore, but kept for compatability */
typedef unsigned char FAR png_bytef;
/* SJT: */
#ifndef FARDATA
#define FARDATA
#endif
/* End medium model changes to be in zconf.h */
/* SJT: More typedefs */
typedef void FAR * png_voidp;
/* Not used anymore (as of 0.88), but kept for compatability (for now). */
typedef unsigned char FAR png_bytef;
/* SJT: Add typedefs for pointers */
typedef void FAR * png_voidp;
typedef png_byte FAR * png_bytep;
typedef png_uint_32 FAR * png_uint_32p;
typedef png_int_32 FAR * png_int_32p;
......@@ -332,12 +355,17 @@ typedef char FAR * FAR * png_charpp;
*/
typedef charf * png_zcharp;
typedef charf * FAR * png_zcharpp;
typedef z_stream * png_zstreamp; /* zlib won't accept far z_stream */
typedef z_stream FAR * png_zstreamp;
/* User may want to use these so not in PNG_INTERNAL. Any library functions
that are passed far data must be model independent. */
#if defined(USE_FAR_KEYWORD) /* memory model independent fns */
/* use this to make far-to-near assignments */
# define CHECK 1
# define NOCHECK 0
# define CVT_PTR(ptr) (far_to_near(png_ptr,ptr,CHECK))
# define CVT_PTR_NOCHECK(ptr) (far_to_near(png_ptr,ptr,NOCHECK))
# define png_strcpy _fstrcpy
# define png_strcat _fstrcat
# define png_strlen _fstrlen
......@@ -346,6 +374,8 @@ typedef z_stream * png_zstreamp; /* zlib won't accept far z_stream */
# define png_memcpy _fmemcpy
# define png_memset _fmemset
#else /* use the usual functions */
# define CVT_PTR(ptr) (ptr)
# define CVT_PTR_NOCHECK(ptr) (ptr)
# define png_strcpy strcpy
# define png_strcat strcat
# define png_strlen strlen
......
/* pngerror.c - stub functions for i/o and memory allocation
libpng 1.0 beta 3 - version 0.89
libpng 1.0 beta 4 - version 0.90
For conditions of distribution and use, see copyright notice in png.h
Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
May 25, 1996
January 10, 1997
This file provides a location for all error handling. Users which
need special error handling are expected to write replacement functions
......
/* pngmem.c - stub functions for memory allocation
libpng 1.0 beta 3 - version 0.89
libpng 1.0 beta 4 - version 0.90
For conditions of distribution and use, see copyright notice in png.h
Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
May 25, 1996
January 10, 1997
This file provides a location for all memory allocation. Users which
need special memory handling are expected to modify the code in this file
......@@ -18,12 +18,11 @@
/* if you change this, be sure to change the one in png.h also */
/* Allocate memory for a png_struct. The malloc and memset can be replaced
* by a single call to calloc() if this is thought to improve performance.
*/
by a single call to calloc() if this is thought to improve performance. */
png_voidp
png_create_struct(uInt type)
png_create_struct(int type)
{
png_size_t type;
png_size_t size;
png_voidp struct_ptr;
if (type == PNG_STRUCT_INFO)
......@@ -66,7 +65,7 @@ png_destroy_struct(png_voidp struct_ptr)
*/
png_voidp
png_large_malloc(png_structp png_ptr, png_uint_32 size)
png_malloc(png_structp png_ptr, png_uint_32 size)
{
png_voidp ret;
if (!png_ptr || !size)
......@@ -160,11 +159,11 @@ png_large_malloc(png_structp png_ptr, png_uint_32 size)
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. */
/* free a pointer allocated by png_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)
png_free(png_structp png_ptr, png_voidp ptr)
{
if (!png_ptr)
return;
......@@ -201,11 +200,10 @@ png_large_free(png_structp png_ptr, png_voidp ptr)
#else /* Not the Borland DOS special memory handler */
/* Allocate memory for a png_struct or a png_info. The malloc and
* memset can be replaced by a single call to calloc() if this is thought
* to improve performance noticably.
*/
memset can be replaced by a single call to calloc() if this is thought
to improve performance noticably.*/
png_voidp
png_create_struct(uInt type)
png_create_struct(int type)
{
size_t size;
png_voidp struct_ptr;
......@@ -257,8 +255,9 @@ png_destroy_struct(png_voidp struct_ptr)
need to allocate exactly 64K, so whatever you call here must
have the ability to do that. */
#ifndef FORTIFY
png_voidp
png_large_malloc(png_structp png_ptr, png_uint_32 size)
png_malloc(png_structp png_ptr, png_uint_32 size)
{
png_voidp ret;
if (!png_ptr || !size)
......@@ -287,11 +286,11 @@ png_large_malloc(png_structp png_ptr, png_uint_32 size)
return ret;
}
/* free a pointer allocated by png_large_malloc(). In the default
/* free a pointer allocated by png_malloc(). In the default
configuration, png_ptr is not used, but is passed in case it
is needed. If ptr is NULL, return without taking any action. */
void
png_large_free(png_structp png_ptr, png_voidp ptr)
png_free(png_structp png_ptr, png_voidp ptr)
{
if (!png_ptr)
return;
......@@ -310,76 +309,6 @@ png_large_free(png_structp png_ptr, png_voidp ptr)
}
}
#endif /* FORTIFY */
#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). 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)
{
void *ret;
if (!png_ptr || !size)
{
return ((void *)0);
}
#ifdef PNG_MAX_MALLOC_64K
if (size > (png_uint_32)65536L)
png_error(png_ptr, "Cannot Allocate > 64K");
#endif
ret = malloc((png_size_t)size);
if (!ret)
{
png_error(png_ptr, "Out of Memory");
}
return ret;
}
/* Reallocate memory. This will not get near 64K on a
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)
{
void *ret;
if (!png_ptr || !old_size || !ptr || !size)
return ((void *)0);
#ifdef PNG_MAX_MALLOC_64K
if (size > (png_uint_32)65536L)
png_error(png_ptr, "Cannot Allocate > 64K");
#endif
ret = realloc(ptr, (png_size_t)size);
if (!ret)
{
png_error(png_ptr, "Out of Memory 7");
}
return ret;
}
/* free a pointer allocated by png_malloc(). In the default
configuration, png_ptr is not used, but is passed incase it
is needed. If ptr is NULL, return without taking any action. */
void
png_free(png_structp png_ptr, void * ptr)
{
if (!png_ptr)
return;
if (ptr != (void *)0)
free(ptr);
}
此差异已折叠。
/* pngrcb.c - callbacks while reading a png file
libpng 1.0 beta 3 - version 0.89
libpng 1.0 beta 4 - version 0.90
For conditions of distribution and use, see copyright notice in png.h
Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
May 25, 1996
January 10, 1997
*/
#define PNG_INTERNAL
......@@ -15,7 +15,7 @@ png_read_IHDR(png_structp png_ptr, png_infop info,
int color_type, int compression_type, int filter_type,
int interlace_type)
{
if (!png_ptr || !info)
if (!info)
return;
info->width = width;
......@@ -41,7 +41,7 @@ void
png_read_PLTE(png_structp png_ptr, png_infop info,
png_colorp palette, int num)
{
if (!png_ptr || !info)
if (!info)
return;
info->palette = palette;
......@@ -53,10 +53,10 @@ png_read_PLTE(png_structp png_ptr, png_infop info,
void
png_read_gAMA(png_structp png_ptr, png_infop info, double gamma)
{
if (!png_ptr || !info)
if (!info)
return;
info->gamma = gamma;
info->gamma = (float)gamma;
info->valid |= PNG_INFO_gAMA;
}
#endif
......@@ -66,7 +66,7 @@ void
png_read_sBIT(png_structp png_ptr, png_infop info,
png_color_8p sig_bit)
{
if (!png_ptr || !info)
if (!info)
return;
png_memcpy(&(info->sig_bit), sig_bit, sizeof (png_color_8));
......@@ -80,17 +80,17 @@ png_read_cHRM(png_structp png_ptr, png_infop info,
double white_x, double white_y, double red_x, double red_y,
double green_x, double green_y, double blue_x, double blue_y)
{
if (!png_ptr || !info)
if (!info)
return;
info->x_white = white_x;
info->y_white = white_y;
info->x_red = red_x;
info->y_red = red_y;
info->x_green = green_x;
info->y_green = green_y;
info->x_blue = blue_x;
info->y_blue = blue_y;
info->x_white = (float)white_x;
info->y_white = (float)white_y;
info->x_red = (float)red_x;
info->y_red = (float)red_y;
info->x_green = (float)green_x;
info->y_green = (float)green_y;
info->x_blue = (float)blue_x;
info->y_blue = (float)blue_y;
info->valid |= PNG_INFO_cHRM;
}
#endif
......@@ -100,7 +100,7 @@ void
png_read_tRNS(png_structp png_ptr, png_infop info,
png_bytep trans, int num_trans, png_color_16p trans_values)
{
if (!png_ptr || !info)
if (!info)
return;
if (trans)
......@@ -122,7 +122,7 @@ void
png_read_bKGD(png_structp png_ptr, png_infop info,
png_color_16p background)
{
if (!png_ptr || !info)
if (!info)
return;
png_memcpy(&(info->background), background, sizeof(png_color_16));
......@@ -134,7 +134,7 @@ png_read_bKGD(png_structp png_ptr, png_infop info,
void
png_read_hIST(png_structp png_ptr, png_infop info, png_uint_16p hist)
{
if (!png_ptr || !info)
if (!info)
return;
info->hist = hist;
......@@ -147,7 +147,7 @@ void
png_read_pHYs(png_structp png_ptr, png_infop info,
png_uint_32 res_x, png_uint_32 res_y, int unit_type)
{
if (!png_ptr || !info)
if (!info)
return;
info->x_pixels_per_unit = res_x;
......@@ -162,7 +162,7 @@ void
png_read_oFFs(png_structp png_ptr, png_infop info,
png_uint_32 offset_x, png_uint_32 offset_y, int unit_type)
{
if (!png_ptr || !info)
if (!info)
return;
info->x_offset = offset_x;
......@@ -177,7 +177,7 @@ void
png_read_tIME(png_structp png_ptr, png_infop info,
png_timep mod_time)
{
if (!png_ptr || !info)
if (!info)
return;
png_memcpy(&(info->mod_time), mod_time, sizeof (png_time));
......@@ -190,7 +190,7 @@ void
png_read_zTXt(png_structp png_ptr, png_infop info,
png_charp key, png_charp text, png_uint_32 text_len, int compression)
{
if (!png_ptr || !info)
if (!info)
return;
if (info->max_text <= info->num_text)
......@@ -205,18 +205,18 @@ png_read_zTXt(png_structp png_ptr, png_infop info,
png_textp old_text;
old_text = info->text;
info->text = (png_textp)png_large_malloc(png_ptr,
info->text = (png_textp)png_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);
png_free(png_ptr, old_text);
}
}
else
{
info->max_text = 16;
info->num_text = 0;
info->text = (png_textp)png_large_malloc(png_ptr,
info->text = (png_textp)png_malloc(png_ptr,
info->max_text * sizeof (png_text));
}
}
......@@ -234,7 +234,7 @@ void
png_read_tEXt(png_structp png_ptr, png_infop info,
png_charp key, png_charp text, png_uint_32 text_len)
{
if (!png_ptr || !info)
if (!info)
return;
png_read_zTXt(png_ptr, info, key, text, text_len, -1);
......
此差异已折叠。
/* pngrio.c - functions for data input
libpng 1.0 beta 3 - version 0.89
libpng 1.0 beta 4 - version 0.90
For conditions of distribution and use, see copyright notice in png.h
Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
May 25, 1996
January 10, 1997
This file provides a location for all input. Users which need
special handling are expected to write a function which has the same
......@@ -56,29 +56,19 @@ png_default_read_data(png_structp png_ptr, png_bytep data, png_uint_32 length)
#define NEAR_BUF_SIZE 1024
#define MIN(a,b) (a <= b ? a : b)
#ifdef _MSC_VER
/* for FP_OFF */
#include <dos.h>
#endif
static void
png_default_read_data(png_structp png_ptr, png_bytep data, png_uint_32 length)
{
png_uint_32 check;
png_byte *n_data;
FILE *io_ptr;
/* Check if data really is near. If so, use usual code. */
#ifdef _MSC_VER
/* do it this way just to quiet warning */
FP_OFF(n_data) = FP_OFF(data);
if (FP_SEG(n_data) == FP_SEG(data))
#else
/* this works in MSC also but with lost segment warning */
n_data = (png_byte *)data;
n_data = (png_byte *)CVT_PTR_NOCHECK(data);
io_ptr = (FILE *)CVT_PTR(png_ptr->io_ptr);
if ((png_bytep)n_data == data)
#endif
{
check = fread(n_data, 1, (size_t)length, (FILE *)png_ptr->io_ptr);
check = fread(n_data, 1, (size_t)length, io_ptr);
}
else
{
......@@ -89,7 +79,7 @@ png_default_read_data(png_structp png_ptr, png_bytep data, png_uint_32 length)
do
{
read = MIN(NEAR_BUF_SIZE, remaining);
err = fread(buf, 1, read, (FILE *)png_ptr->io_ptr);
err = fread(buf, 1, read, io_ptr);
png_memcpy(data, buf, read); /* copy far buffer to near buffer */
if(err != read)
break;
......
/* pngrtran.c - transforms the data in a row for png readers
libpng 1.0 beta 3 - version 0.89
libpng 1.0 beta 4 - version 0.90
For conditions of distribution and use, see copyright notice in png.h
Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
May 25, 1996
January 10, 1997
*/
#define PNG_INTERNAL
......@@ -17,6 +17,12 @@ png_set_background(png_structp png_ptr,
png_color_16p background_color, int background_gamma_code,
int need_expand, double background_gamma)
{
if (background_gamma_code == PNG_BACKGROUND_GAMMA_UNKNOWN)
{
png_warning(png_ptr, "Application must supply a known background gamma");
return;
}
png_ptr->transformations |= PNG_BACKGROUND;
png_memcpy(&(png_ptr->background), background_color,
sizeof(png_color_16));
......@@ -63,7 +69,7 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
{
int i;
png_ptr->dither_index = (png_bytep)png_large_malloc(png_ptr,
png_ptr->dither_index = (png_bytep)png_malloc(png_ptr,
num_palette * sizeof (png_byte));
for (i = 0; i < num_palette; i++)
png_ptr->dither_index[i] = (png_byte)i;
......@@ -80,7 +86,7 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
png_bytep sort;
/* initialize an array to sort colors */
sort = (png_bytep)png_large_malloc(png_ptr, num_palette * sizeof (png_byte));
sort = (png_bytep)png_malloc(png_ptr, num_palette * sizeof (png_byte));
/* initialize the sort array */
for (i = 0; i < num_palette; i++)
......@@ -190,7 +196,7 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
}
}
}
png_large_free(png_ptr, sort);
png_free(png_ptr, sort);
}
else
{
......@@ -210,9 +216,9 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
/* which original index points to this palette color */
/* initialize palette index arrays */
index_to_palette = (png_bytep)png_large_malloc(png_ptr,
index_to_palette = (png_bytep)png_malloc(png_ptr,
num_palette * sizeof (png_byte));
palette_to_index = (png_bytep)png_large_malloc(png_ptr,
palette_to_index = (png_bytep)png_malloc(png_ptr,
num_palette * sizeof (png_byte));
/* initialize the sort array */
......@@ -222,7 +228,7 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
palette_to_index[i] = (png_byte)i;
}
hash = (png_dsortpp)png_large_malloc(png_ptr, 769 * sizeof (png_dsortp));
hash = (png_dsortpp)png_malloc(png_ptr, 769 * sizeof (png_dsortp));
for (i = 0; i < 769; i++)
hash[i] = (png_dsortp)0;
/* png_memset(hash, 0, 769 * sizeof (png_dsortp)); */
......@@ -255,7 +261,7 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
{
png_dsortp t;
t = png_large_malloc(png_ptr, sizeof (png_dsort));
t = png_malloc(png_ptr, sizeof (png_dsort));
t->next = hash[d];
t->left = (png_byte)i;
t->right = (png_byte)j;
......@@ -336,7 +342,7 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
png_dsortp t;
t = p->next;
png_large_free(png_ptr, p);
png_free(png_ptr, p);
p = t;
}
}
......@@ -344,9 +350,9 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
}
max_d += 96;
}
png_large_free(png_ptr, hash);
png_large_free(png_ptr, palette_to_index);
png_large_free(png_ptr, index_to_palette);
png_free(png_ptr, hash);
png_free(png_ptr, palette_to_index);
png_free(png_ptr, index_to_palette);
}
num_palette = maximum_colors;
}
......@@ -371,12 +377,12 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
num_blue = (1 << PNG_DITHER_BLUE_BITS);
num_entries = ((png_uint_32)1 << total_bits);
png_ptr->palette_lookup = (png_bytep )png_large_malloc(png_ptr,
png_ptr->palette_lookup = (png_bytep )png_malloc(png_ptr,
(png_size_t)num_entries * sizeof (png_byte));
png_memset(png_ptr->palette_lookup, 0, (png_size_t)num_entries * sizeof (png_byte));
distance = (png_bytep )png_large_malloc(png_ptr,
distance = (png_bytep )png_malloc(png_ptr,
(png_size_t)num_entries * sizeof (png_byte));
png_memset(distance, 0xff, (png_size_t)num_entries * sizeof (png_byte));
......@@ -422,27 +428,30 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
}
}
png_large_free(png_ptr, distance);
png_free(png_ptr, distance);
}
}
#endif
#if defined(PNG_READ_GAMMA_SUPPORTED)
/* transform the image from the file_gamma to the screen_gamma */
/* Transform the image from the file_gamma to the screen_gamma. We
only do transformations on images where the file_gamma and screen_gamma
are not close reciprocals, otherwise it slows things down slightly, and
also introduces small errors. */
void
png_set_gamma(png_structp png_ptr, double screen_gamma,
double file_gamma)
png_set_gamma(png_structp png_ptr, double screen_gamma, double file_gamma)
{
png_ptr->transformations |= PNG_GAMMA;
if (fabs(screen_gamma * file_gamma - 1.0) > 0.05)
png_ptr->transformations |= PNG_GAMMA;
png_ptr->gamma = (float)file_gamma;
png_ptr->display_gamma = (float)screen_gamma;
}
#endif
#if defined(PNG_READ_EXPAND_SUPPORTED)
/* expand paletted images to rgb, expand grayscale images of
/* Expand paletted images to rgb, expand grayscale images of
less then 8 bit depth to 8 bit depth, and expand tRNS chunks
to alpha channels */
to alpha channels. */
void
png_set_expand(png_structp png_ptr)
{
......@@ -458,6 +467,18 @@ png_set_gray_to_rgb(png_structp png_ptr)
}
#endif
#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
/* Convert a RGB image to a grayscale of the given width. This would
allow us, for example, to convert a 24 bpp RGB image into an 8 or
16 bpp grayscale image. (Not yet implemented.) */
void
png_set_rgb_to_gray(png_structp png_ptr, int gray_bits)
{
png_ptr->transformations |= PNG_RGB_TO_GRAY;
/* Need to do something with gray_bits here. */
}
#endif
/* initialize everything needed for the read. This includes modifying
the palette */
void
......@@ -804,6 +825,7 @@ png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
void
png_do_read_transformations(png_structp png_ptr)
{
#if defined(PNG_READ_EXPAND_SUPPORTED)
if ((png_ptr->transformations & PNG_EXPAND) &&
png_ptr->row_info.color_type == PNG_COLOR_TYPE_PALETTE)
......@@ -835,12 +857,18 @@ png_do_read_transformations(png_structp png_ptr)
#if defined(PNG_READ_GAMMA_SUPPORTED)
if ((png_ptr->transformations & PNG_GAMMA) &&
!(png_ptr->transformations & PNG_BACKGROUND))
!(png_ptr->transformations & PNG_BACKGROUND) &&
(png_ptr->color_type != PNG_COLOR_TYPE_PALETTE))
png_do_gamma(&(png_ptr->row_info), png_ptr->row_buf + 1,
png_ptr->gamma_table, png_ptr->gamma_16_table,
png_ptr->gamma_shift);
#endif
#if defined(PNG_RGB_TO_GRAY_SUPPORTED)
if (png_ptr->transformations & PNG_RGB_TO_GRAY)
png_do_rgb_to_gray(&(png_ptr->row_info), png_ptr->row_buf + 1);
#endif
#if defined(PNG_READ_16_TO_8_SUPPORTED)
if (png_ptr->transformations & PNG_16_TO_8)
png_do_chop(&(png_ptr->row_info), png_ptr->row_buf + 1);
......@@ -1097,6 +1125,7 @@ png_do_chop(png_row_infop row_info, png_bytep row)
{
png_bytep sp, dp;
png_uint_32 i;
if (row && row_info && row_info->bit_depth == 16)
{
sp = row;
......@@ -1123,7 +1152,7 @@ png_do_chop(png_row_infop row_info, png_bytep row)
/* add filler byte */
void
png_do_read_filler(png_row_infop row_info, png_bytep row,
png_byte filler, png_byte flags)
png_byte filler, png_uint_32 flags)
{
png_bytep sp, dp;
png_uint_32 i;
......@@ -1304,8 +1333,8 @@ png_build_grayscale_palette(int bit_depth, png_colorp palette)
}
}
/* This function is currently unused? */
#if defined(PNG_READ_DITHER_SUPPORTED) || defined(PNG_CORRECT_PALETTE_SUPPORTED)
/* This function is currently unused. Do we really need it? */
#if defined(PNG_READ_DITHER_SUPPORTED) && defined(PNG_CORRECT_PALETTE_SUPPORTED)
void
png_correct_palette(png_structp png_ptr, png_colorp palette,
int num_palette)
......@@ -2137,6 +2166,7 @@ png_do_background(png_row_infop row_info, png_bytep row,
break;
}
}
if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
{
row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
......@@ -2463,123 +2493,131 @@ png_do_expand(png_row_infop row_info, png_bytep row,
if (row && row_info)
{
if (row_info->color_type == PNG_COLOR_TYPE_GRAY &&
row_info->bit_depth < 8)
if (row_info->color_type == PNG_COLOR_TYPE_GRAY )
{
switch (row_info->bit_depth)
png_uint_16 gray = trans_value ? trans_value->gray : 0;
if (row_info->bit_depth < 8)
{
case 1:
switch (row_info->bit_depth)
{
sp = row + (png_size_t)((row_info->width - 1) >> 3);
dp = row + (png_size_t)row_info->width - 1;
shift = 7 - (int)((row_info->width + 7) & 7);
for (i = 0; i < row_info->width; i++)
case 1:
{
if ((*sp >> shift) & 0x1)
*dp = 0xff;
else
*dp = 0;
if (shift == 7)
gray *= 0xff;
sp = row + (png_size_t)((row_info->width - 1) >> 3);
dp = row + (png_size_t)row_info->width - 1;
shift = 7 - (int)((row_info->width + 7) & 7);
for (i = 0; i < row_info->width; i++)
{
shift = 0;
sp--;
}
else
shift++;
if ((*sp >> shift) & 0x1)
*dp = 0xff;
else
*dp = 0;
if (shift == 7)
{
shift = 0;
sp--;
}
else
shift++;
dp--;
dp--;
}
break;
}
break;
}
case 2:
{
sp = row + (png_size_t)((row_info->width - 1) >> 2);
dp = row + (png_size_t)row_info->width - 1;
shift = (int)((3 - ((row_info->width + 3) & 3)) << 1);
for (i = 0; i < row_info->width; i++)
case 2:
{
value = (*sp >> shift) & 0x3;
*dp = (png_byte)(value | (value << 2) | (value << 4) |
(value << 6));
if (shift == 6)
gray *= 0x55;
sp = row + (png_size_t)((row_info->width - 1) >> 2);
dp = row + (png_size_t)row_info->width - 1;
shift = (int)((3 - ((row_info->width + 3) & 3)) << 1);
for (i = 0; i < row_info->width; i++)
{
shift = 0;
sp--;
}
else
shift += 2;
value = (*sp >> shift) & 0x3;
*dp = (png_byte)(value | (value << 2) | (value << 4) |
(value << 6));
if (shift == 6)
{
shift = 0;
sp--;
}
else
shift += 2;
dp--;
dp--;
}
break;
}
break;
}
case 4:
{
sp = row + (png_size_t)((row_info->width - 1) >> 1);
dp = row + (png_size_t)row_info->width - 1;
shift = (int)((1 - ((row_info->width + 1) & 1)) << 2);
for (i = 0; i < row_info->width; i++)
case 4:
{
value = (*sp >> shift) & 0xf;
*dp = (png_byte)(value | (value << 4));
if (shift == 4)
gray *= 0x11;
sp = row + (png_size_t)((row_info->width - 1) >> 1);
dp = row + (png_size_t)row_info->width - 1;
shift = (int)((1 - ((row_info->width + 1) & 1)) << 2);
for (i = 0; i < row_info->width; i++)
{
shift = 0;
sp--;
}
else
shift = 4;
value = (*sp >> shift) & 0xf;
*dp = (png_byte)(value | (value << 4));
if (shift == 4)
{
shift = 0;
sp--;
}
else
shift = 4;
dp--;
dp--;
}
break;
}
break;
}
row_info->bit_depth = 8;
row_info->pixel_depth = 8;
row_info->rowbytes = row_info->width;
}
row_info->bit_depth = 8;
row_info->pixel_depth = 8;
row_info->rowbytes = row_info->width;
}
if (row_info->color_type == PNG_COLOR_TYPE_GRAY && trans_value)
{
if (row_info->bit_depth == 8)
{
sp = row + (png_size_t)row_info->width - 1;
dp = row + (png_size_t)(row_info->width << 1) - 1;
for (i = 0; i < row_info->width; i++)
{
if (*sp == trans_value->gray)
*dp-- = 0;
else
*dp-- = 0xff;
*dp-- = *sp--;
}
}
else if (row_info->bit_depth == 16)
if (trans_value)
{
sp = row + (png_size_t)row_info->rowbytes - 1;
dp = row + (png_size_t)(row_info->rowbytes << 1) - 1;
for (i = 0; i < row_info->width; i++)
if (row_info->bit_depth == 8)
{
if (((png_uint_16)*(sp) |
((png_uint_16)*(sp - 1) << 8)) == trans_value->gray)
sp = row + (png_size_t)row_info->width - 1;
dp = row + (png_size_t)(row_info->width << 1) - 1;
for (i = 0; i < row_info->width; i++)
{
*dp-- = 0;
*dp-- = 0;
if (*sp == gray)
*dp-- = 0;
else
*dp-- = 0xff;
*dp-- = *sp--;
}
else
}
else if (row_info->bit_depth == 16)
{
sp = row + (png_size_t)row_info->rowbytes - 1;
dp = row + (png_size_t)(row_info->rowbytes << 1) - 1;
for (i = 0; i < row_info->width; i++)
{
*dp-- = 0xff;
*dp-- = 0xff;
if (((png_uint_16)*(sp) |
((png_uint_16)*(sp - 1) << 8)) == gray)
{
*dp-- = 0;
*dp-- = 0;
}
else
{
*dp-- = 0xff;
*dp-- = 0xff;
}
*dp-- = *sp--;
*dp-- = *sp--;
}
*dp-- = *sp--;
*dp-- = *sp--;
}
row_info->color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
row_info->channels = 2;
row_info->pixel_depth = (png_byte)(row_info->bit_depth << 1);
row_info->rowbytes =
((row_info->width * row_info->pixel_depth) >> 3);
}
row_info->color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
row_info->channels = 2;
row_info->pixel_depth = (png_byte)(row_info->bit_depth << 1);
row_info->rowbytes =
((row_info->width * row_info->pixel_depth) >> 3);
}
else if (row_info->color_type == PNG_COLOR_TYPE_RGB && trans_value)
{
......@@ -2742,7 +2780,7 @@ png_build_gamma_table(png_structp png_ptr)
g = 1.0 / (png_ptr->gamma * png_ptr->display_gamma);
png_ptr->gamma_table = (png_bytep)png_large_malloc(png_ptr,
png_ptr->gamma_table = (png_bytep)png_malloc(png_ptr,
(png_uint_32)256);
for (i = 0; i < 256; i++)
......@@ -2755,7 +2793,7 @@ png_build_gamma_table(png_structp png_ptr)
{
g = 1.0 / (png_ptr->gamma);
png_ptr->gamma_to_1 = (png_bytep)png_large_malloc(png_ptr,
png_ptr->gamma_to_1 = (png_bytep)png_malloc(png_ptr,
(png_uint_32)256);
for (i = 0; i < 256; i++)
......@@ -2766,7 +2804,7 @@ png_build_gamma_table(png_structp png_ptr)
g = 1.0 / (png_ptr->display_gamma);
png_ptr->gamma_from_1 = (png_bytep)png_large_malloc(png_ptr,
png_ptr->gamma_from_1 = (png_bytep)png_malloc(png_ptr,
(png_uint_32)256);
for (i = 0; i < 256; i++)
......@@ -2818,7 +2856,7 @@ png_build_gamma_table(png_structp png_ptr)
g = 1.0 / (png_ptr->gamma * png_ptr->display_gamma);
png_ptr->gamma_16_table = (png_uint_16pp)png_large_malloc(png_ptr,
png_ptr->gamma_16_table = (png_uint_16pp)png_malloc(png_ptr,
num * sizeof (png_uint_16p ));
if ((png_ptr->transformations & PNG_16_TO_8) &&
......@@ -2829,7 +2867,7 @@ png_build_gamma_table(png_structp png_ptr)
for (i = 0; i < num; i++)
{
png_ptr->gamma_16_table[i] = (png_uint_16p)png_large_malloc(png_ptr,
png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
256 * sizeof (png_uint_16));
}
......@@ -2860,7 +2898,7 @@ png_build_gamma_table(png_structp png_ptr)
{
for (i = 0; i < num; i++)
{
png_ptr->gamma_16_table[i] = (png_uint_16p)png_large_malloc(png_ptr,
png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
256 * sizeof (png_uint_16));
ig = (((png_uint_32)i *
......@@ -2878,12 +2916,12 @@ png_build_gamma_table(png_structp png_ptr)
{
g = 1.0 / (png_ptr->gamma);
png_ptr->gamma_16_to_1 = (png_uint_16pp)png_large_malloc(png_ptr,
png_ptr->gamma_16_to_1 = (png_uint_16pp)png_malloc(png_ptr,
num * sizeof (png_uint_16p ));
for (i = 0; i < num; i++)
{
png_ptr->gamma_16_to_1[i] = (png_uint_16p)png_large_malloc(png_ptr,
png_ptr->gamma_16_to_1[i] = (png_uint_16p)png_malloc(png_ptr,
256 * sizeof (png_uint_16));
ig = (((png_uint_32)i *
......@@ -2897,12 +2935,12 @@ png_build_gamma_table(png_structp png_ptr)
}
g = 1.0 / (png_ptr->display_gamma);
png_ptr->gamma_16_from_1 = (png_uint_16pp)png_large_malloc(png_ptr,
png_ptr->gamma_16_from_1 = (png_uint_16pp)png_malloc(png_ptr,
num * sizeof (png_uint_16p));
for (i = 0; i < num; i++)
{
png_ptr->gamma_16_from_1[i] = (png_uint_16p)png_large_malloc(png_ptr,
png_ptr->gamma_16_from_1[i] = (png_uint_16p)png_malloc(png_ptr,
256 * sizeof (png_uint_16));
ig = (((png_uint_32)i *
......
此差异已折叠。
/* pngtest.c - a simple test program to test libpng
libpng 1.0 beta 3 - version 0.89
libpng 1.0 beta 4 - version 0.90
For conditions of distribution and use, see copyright notice in png.h
Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
May 25, 1996
January 10, 1997
*/
#include <stdio.h>
......@@ -20,7 +21,7 @@
/* input and output filenames */
#ifdef RISCOS
char *inname = "pngtest_pn";
char *inname = "pngtest_png";
char *outname = "pngout_png";
#else
char *inname = "pngtest.png";
......@@ -41,7 +42,9 @@ int main(int argc, char *argv[])
png_uint_32 rowbytes;
png_uint_32 y;
int channels, num_pass, pass;
#ifdef USE_FAR_KEYWORD
jmp_buf jmpbuf;
#endif
row_buf = (png_bytep)NULL;
near_row_buf = (png_byte *)NULL;
......@@ -82,14 +85,18 @@ int main(int argc, char *argv[])
return 1;
}
read_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, (void *)NULL,
read_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, (png_voidp)NULL,
(png_error_ptr)NULL, (png_error_ptr)NULL);
write_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, (void *)NULL,
write_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, (png_voidp)NULL,
(png_error_ptr)NULL, (png_error_ptr)NULL);
info_ptr = png_create_info_struct(read_ptr);
end_info = png_create_info_struct(read_ptr);
#ifdef USE_FAR_KEYWORD
if (setjmp(jmpbuf))
#else
if (setjmp(read_ptr->jmpbuf))
#endif
{
fprintf(STDERR, "libpng read error\n");
png_destroy_read_struct(&read_ptr, &info_ptr, &end_info);
......@@ -98,8 +105,12 @@ int main(int argc, char *argv[])
fclose(fpout);
return 1;
}
#ifdef USE_FAR_KEYWORD
png_memcpy(read_ptr->jmpbuf,jmpbuf,sizeof(jmp_buf));
if (setjmp(jmpbuf))
#else
if (setjmp(write_ptr->jmpbuf))
#endif
{
fprintf(STDERR, "libpng write error\n");
png_destroy_read_struct(&read_ptr, &info_ptr, &end_info);
......@@ -108,7 +119,9 @@ int main(int argc, char *argv[])
fclose(fpout);
return 1;
}
#ifdef USE_FAR_KEYWORD
png_memcpy(write_ptr->jmpbuf,jmpbuf,sizeof(jmp_buf));
#endif
png_init_io(read_ptr, fpin);
png_init_io(write_ptr, fpout);
......@@ -166,7 +179,7 @@ int main(int argc, char *argv[])
fclose(fpin);
fclose(fpout);
free((void *)near_row_buf);
free((png_byte *)near_row_buf);
fpin = fopen(inname, "rb");
......@@ -183,13 +196,12 @@ int main(int argc, char *argv[])
fclose(fpin);
return 1;
}
while (1)
{
int num_in, num_out;
num_in = fread(inbuf, 1, 256, fpin);
num_out = fread(outbuf, 1, 256, fpout);
num_in = fread(inbuf, 1, 1, fpin);
num_out = fread(outbuf, 1, 1, fpout);
if (num_in != num_out)
{
......
......@@ -2,10 +2,10 @@
/* pngtrans.c - transforms the data in a row
routines used by both readers and writers
libpng 1.0 beta 3 - version 0.89
libpng 1.0 beta 4 - version 0.90
For conditions of distribution and use, see copyright notice in png.h
Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
May 25, 1996
January 10, 1997
*/
#define PNG_INTERNAL
......@@ -68,10 +68,10 @@ png_set_interlace_handling(png_structp png_ptr)
#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
void
png_set_filler(png_structp png_ptr, int filler, int filler_loc)
png_set_filler(png_structp png_ptr, png_byte filler, int filler_loc)
{
png_ptr->transformations |= PNG_FILLER;
png_ptr->filler = (png_byte)filler;
png_ptr->filler = filler;
if (filler_loc == PNG_FILLER_AFTER)
png_ptr->flags |= PNG_FLAG_FILLER_AFTER;
else
......@@ -82,17 +82,20 @@ png_set_filler(png_structp png_ptr, int filler, int filler_loc)
png_ptr->usr_channels = 4;
}
/* old functions kept around for compatability purposes */
/* Old functions kept around for compatability purposes. They will be
* removed at some time in the future, so don't use them. You should
* use png_set_filler() above instead. We set filler bytes to 0xff in
* case they are mistakenly used as PNG alpha (0xff is fully opaque). */
void
png_set_rgbx(png_structp png_ptr)
{
png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER);
png_set_filler(png_ptr, (png_byte)0xff, PNG_FILLER_AFTER);
}
void
png_set_xrgb(png_structp png_ptr)
{
png_set_filler(png_ptr, 0xff, PNG_FILLER_BEFORE);
png_set_filler(png_ptr, (png_byte)0xff, PNG_FILLER_BEFORE);
}
#endif
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册