mirror of
https://git.code.sf.net/p/libpng/code.git
synced 2025-07-10 18:04:09 +02:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2687fcc7b5 | ||
|
|
70e3f543f1 | ||
|
|
b6ce43d6ff | ||
|
|
47a0c422ca | ||
|
|
02ad0efbc8 | ||
|
|
c21f90c334 |
189
CHANGES
Normal file
189
CHANGES
Normal file
@@ -0,0 +1,189 @@
|
||||
pngchange.txt - changes for libpng
|
||||
|
||||
version 0.2
|
||||
added reader into png.h
|
||||
fixed small problems in stub file
|
||||
version 0.3
|
||||
added pull reader
|
||||
split up pngwrite.c to several files
|
||||
added pnglib.txt
|
||||
added example.c
|
||||
cleaned up writer, adding a few new tranformations
|
||||
fixed some bugs in writer
|
||||
interfaced with zlib 0.5
|
||||
added K&R support
|
||||
added check for 64 KB blocks for 16 bit machines
|
||||
version 0.4
|
||||
cleaned up code and commented code
|
||||
simplified time handling into png_time
|
||||
created png_color_16 and png_color_8 to handle color needs
|
||||
cleaned up color type defines
|
||||
fixed various bugs
|
||||
made various names more consistant
|
||||
interfaced with zlib 0.71
|
||||
cleaned up zTXt reader and writer (using zlib's Reset functions)
|
||||
split transformations into pngrtran.c and pngwtran.c
|
||||
version 0.5
|
||||
interfaced with zlib 0.8
|
||||
fixed many reading and writing bugs
|
||||
saved using 3 spaces instead of tabs
|
||||
version 0.6
|
||||
added png_large_malloc() and png_large_free()
|
||||
added png_size_t
|
||||
cleaned up some compiler warnings
|
||||
added png_start_read_image()
|
||||
version 0.7
|
||||
cleaned up lots of bugs
|
||||
finished dithering and other stuff
|
||||
added test program
|
||||
changed name from pnglib to libpng
|
||||
version 0.71 [June, 1995]
|
||||
changed pngtest.png for zlib 0.93
|
||||
fixed error in libpng.txt and example.c
|
||||
version 0.8
|
||||
cleaned up some bugs
|
||||
added png_set_filler()
|
||||
split up pngstub.c into pngmem.c, pngio.c, and pngerror.c
|
||||
added #define's to remove unwanted code
|
||||
moved png_info_init() to png.c
|
||||
added old_size into png_realloc()
|
||||
added functions to manually set filtering and compression info
|
||||
changed compression parameters based on image type
|
||||
optimized filter selection code
|
||||
added version info
|
||||
changed external functions passing floats to doubles (k&r problems?)
|
||||
put all the configurable stuff in pngconf.h
|
||||
enabled png_set_shift to work with paletted images on read
|
||||
added png_read_update_info() - updates info structure with
|
||||
transformations
|
||||
version 0.81 [August, 1995]
|
||||
incorporated Tim Wegner's medium model code (thanks, Tim)
|
||||
version 0.82 [September, 1995]
|
||||
[unspecified changes]
|
||||
version 0.85 [December, 1995]
|
||||
added more medium model code (almost everything's a far)
|
||||
added i/o, error, and memory callback functions
|
||||
fixed some bugs (16 bit, 4 bit interlaced, etc.)
|
||||
added first run progressive reader (barely tested)
|
||||
version 0.86 [January, 1996]
|
||||
fixed bugs
|
||||
improved documentation
|
||||
version 0.87 [January, 1996]
|
||||
fixed medium model bugs
|
||||
fixed other bugs introduced in 0.85 and 0.86
|
||||
added some minor documentation
|
||||
version 0.88 [January, 1996]
|
||||
fixed progressive bugs
|
||||
replaced tabs with spaces
|
||||
cleaned up documentation
|
||||
added callbacks for read/write and warning/error functions
|
||||
version 0.89 [July, 1996]
|
||||
added new initialization API to make libpng work better with shared libs
|
||||
we now have png_create_read_struct(), png_create_write_struct(),
|
||||
png_create_info_struct(), png_destroy_read_struct(), and
|
||||
png_destroy_write_struct() instead of the separate calls to
|
||||
malloc and png_read_init(), png_info_init(), and png_write_init()
|
||||
changed warning/error callback functions to fix bug - this means you
|
||||
should use the new initialization API if you were using the old
|
||||
png_set_message_fn() calls, and that the old API no longer exists
|
||||
so that people are aware that they need to change their code
|
||||
changed filter selection API to allow selection of multiple filters
|
||||
since it didn't work in previous versions of libpng anyways
|
||||
optimized filter selection code
|
||||
fixed png_set_background() to allow using an arbitrary RGB color for
|
||||
paletted images
|
||||
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) - if nobody uses this, it may disappear in the future.
|
||||
fixed bug with Borland 64K memory allocation (Alexander Lehmann)
|
||||
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 documentation to reflect new API
|
||||
version 0.90 [January, 1997]
|
||||
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
|
||||
try to fix Linux "setjmp" buffer size problems
|
||||
version 0.95 [March, 1997]
|
||||
fixed bug in pngwutil.c allocating "up_row" twice and "avg_row" never
|
||||
fixed bug in PNG file signature compares when start != 0
|
||||
changed parameter type of png_set_filler(...filler...) from png_byte
|
||||
to png_uint_32
|
||||
added test for MACOS to ensure that both math.h and fp.h are not #included
|
||||
added macros for libpng to be compiled as a Windows DLL (Andreas Kupries)
|
||||
added "packswap" transformation, which changes the endianness of
|
||||
packed-pixel bytes (Kevin Bracey)
|
||||
added "strip_alpha" transformation, which removes the alpha channel of
|
||||
input images without using it (not neccesarily a good idea)
|
||||
added "swap_alpha" transformation, which puts the alpha channel in front
|
||||
of the color bytes instead of after
|
||||
removed all implicit variable tests which assume NULL == 0 (I think)
|
||||
changed several variables to "png_size_t" to show 16/32-bit limitations
|
||||
added new pCAL chunk read/write support
|
||||
added experimental filter selection weighting (Greg Roelofs)
|
||||
removed old png_set_rgbx() and png_set_xrgb() functions that have been
|
||||
obsolete for about 2 years now (use png_set_filler() instead)
|
||||
added macros to read 16- and 32-bit ints directly from buffer, to be
|
||||
used only on those systems that support it (namely PowerPC and 680x0)
|
||||
With some testing, this may become the default for MACOS/PPC systems.
|
||||
only calculate CRC on data if we are going to use it
|
||||
added macros for zTXt compression type PNG_zTXt_COMPRESSION_???
|
||||
added macros for simple libpng debugging output selectable at compile time
|
||||
removed PNG_READ_END_MODE in progressive reader (Smarasderagd)
|
||||
more description of info_struct in libpng.txt and png.h
|
||||
more instructions in example.c
|
||||
more chunk types tested in pngtest.c
|
||||
renamed pngrcb.c to pngset.c, and all png_read_<chunk> functions to be
|
||||
png_set_<chunk>. We now have corresponding png_get_<chunk>
|
||||
functions in pngget.c to get infomation in info_ptr. This isolates
|
||||
the application from the internal organization of png_info_struct
|
||||
(good for shared library implementations).
|
||||
version 0.96 [May, 1997]
|
||||
fixed serious bug with < 8bpp images introduced in 0.95
|
||||
fixed 256-color transparency bug (Greg Roelofs)
|
||||
fixed up documentation (Greg Roelofs, Laszlo Nyul)
|
||||
fixed "error" in pngconf.h for Linux setjmp() behaviour
|
||||
fixed DOS medium model support (Tim Wegner)
|
||||
fixed png_check_keyword() for case with error in static string text
|
||||
added read of CRC after IEND chunk for embedded PNGs (Laszlo Nyul)
|
||||
added typecasts to quiet compiler errors
|
||||
added more debugging info
|
||||
version 0.97 [January, 1998]
|
||||
removed PNG_USE_OWN_CRC capability
|
||||
relocated png_set_crc_action from pngrutil.c to pngrtran.c
|
||||
fixed typecasts of "new_key", etc.
|
||||
added RFC 1152 date support
|
||||
fixed bug in gamma handling of 4-bit grayscale
|
||||
added more typecasts. 65536L becomes (png_uint_32)65536L, etc.
|
||||
minor corrections in libpng.txt
|
||||
added simple sRGB support
|
||||
make it simpler to do conditional compiling: PNG_READ_NOT_FULLY_SUPPORTED
|
||||
fixed memory leak in pngwrite.c (free info_ptr->text)
|
||||
added more conditions for png_do_background, to avoid changing
|
||||
black pixels to background when a background is supplied and
|
||||
no pixels are transparent
|
||||
repaired PNG_NO_STDIO behaviour
|
||||
tested NODIV support and made it default behaviour
|
||||
added "-m" option to pngtest
|
||||
[anything else? 2-bit grayscale gamma bug?]
|
||||
regularized version numbering scheme and bumped shared-library major
|
||||
version number to 2 to avoid potential problems with libpng 0.89 apps
|
||||
178
README
Normal file
178
README
Normal file
@@ -0,0 +1,178 @@
|
||||
[NOTE: this is still beta version 0.97c; the text below has already
|
||||
been updated in anticipation of the imminent 1.0 release.]
|
||||
|
||||
|
||||
README for libpng 1.0
|
||||
|
||||
This is the first official release of libpng. Don't let the fact that
|
||||
it's the first release fool you. The libpng library has been in
|
||||
extensive use and testing for about two years. However, it's
|
||||
finally gotten to the stage where there haven't been significant
|
||||
changes to the API in some time, and people have a bad feeling about
|
||||
libraries with versions < 1.0.
|
||||
|
||||
****
|
||||
Note that some of the changes to the png_info structure render this
|
||||
version of the library binary incompatible with libpng-0.89 or
|
||||
earlier versions if you are using a shared library. The type of the
|
||||
"filler" parameter for png_set_filler() has changed from png_byte to
|
||||
png_uint_32, which will affect shared-library applications that use
|
||||
this function.
|
||||
|
||||
To avoid problems with changes to the internals of png_info_struct,
|
||||
new APIs have been made available in 0.95 to avoid direct application
|
||||
access to info_ptr. These functions are the png_set_<chunk> and
|
||||
png_get_<chunk> functions. These functions should be used when
|
||||
accessing/storing the info_struct data, rather than manipulating it
|
||||
directly, to avoid such problems in the future.
|
||||
|
||||
It is important to note that the APIs do not make current programs
|
||||
that access the info struct directly incompatible with the new
|
||||
library. However, it is strongly suggested that new programs use
|
||||
the new APIs (as shown in example.c), and older programs be converted
|
||||
to the new format, to facilitate upgrades in the future.
|
||||
****
|
||||
|
||||
Additions since 0.90 include the ability to compile libpng as a
|
||||
Windows DLL, and new APIs for accessing data in the info struct.
|
||||
Experimental functions include the ability to set weighting and cost
|
||||
factors for row filter selection, direct reads of integers from buffers
|
||||
on big-endian processors that support misaligned data access, faster
|
||||
methods of doing alpha composition, and more accurate 16->8 bit color
|
||||
conversion.
|
||||
|
||||
The additions since 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 CRC error occurred in a
|
||||
critical or an ancillary chunk.
|
||||
|
||||
The changes made to the library, and bugs fixed are based on discussions
|
||||
on the PNG implementation mailing list <png-implement@dworking.wustl.edu>
|
||||
and not on material submitted to Guy.
|
||||
|
||||
For a detailed description on using libpng, read libpng.txt. For
|
||||
examples of libpng in a program, see example.c and pngtest.c. For usage
|
||||
information and restrictions (what little they are) on libpng, see
|
||||
png.h. For a description on using zlib (the compression library 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 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 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)
|
||||
at GO GRAPHSUP. If you can't find it in any of those places,
|
||||
e-mail me, and I'll help you find it.
|
||||
|
||||
If you have any code changes, requests, problems, etc., please e-mail
|
||||
them to me. Also, I'd appreciate any make files or project files,
|
||||
and any modifications you needed to make to get libpng to compile,
|
||||
along with a #define variable to tell what compiler/system you are on.
|
||||
If you needed to add transformations to libpng, or wish libpng would
|
||||
provide the image in a different way, drop me a note (and code, if
|
||||
possible), so I can consider supporting the transformation.
|
||||
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 (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
|
||||
|
||||
You can reach Guy, the original libpng author, at (internet preferred):
|
||||
|
||||
internet: schalnat@group42.com
|
||||
CompuServe: 75501,1625
|
||||
|
||||
Please do not send 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
|
||||
get them in the end anyway. If you have a question about something
|
||||
in the PNG specification that is related to using libpng, send it
|
||||
to me. Send me any questions that start with "I was using libpng,
|
||||
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 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 => 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 => Default Unixish 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
|
||||
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
|
||||
pngset.c => Functions for storing data into the info_struct
|
||||
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
|
||||
Internet: adilger@enel.ucalgary.ca
|
||||
Web: http://www-mddsp.enel.ucalgary.ca/People/adilger/
|
||||
|
||||
-Guy Eric Schalnat
|
||||
Group 42, Inc.
|
||||
Internet: schalnat@group42.com
|
||||
CompuServe: 75501,1625
|
||||
Web: http://www.group42.com/
|
||||
|
||||
20
TODO
Normal file
20
TODO
Normal file
@@ -0,0 +1,20 @@
|
||||
pngtodo.txt - list of things to do for libpng
|
||||
|
||||
add "grayscale->palette" transformation and "palette->grayscale" detection
|
||||
improved dithering
|
||||
multi-lingual error and warning message support
|
||||
sPLT chunk handling
|
||||
cHRM transformation
|
||||
complete sRGB transformation (presently it simply uses gamma=0.5)
|
||||
man pages for function calls
|
||||
high-level API for reading images
|
||||
final bug fixes
|
||||
better documentation
|
||||
better filter selection
|
||||
(counting huffman bits/precompression? filter inertia? filter costs?)
|
||||
optional palette creation
|
||||
histogram creation
|
||||
support for application-defined chunk handlers
|
||||
keep up with public chunks
|
||||
better C++ wrapper/full C++ implementation?
|
||||
text conversion between different code pages (Latin-1 -> Mac and DOS)
|
||||
@@ -8,9 +8,9 @@ pref = /prefix=all
|
||||
|
||||
|
||||
|
||||
OBJS = png.obj, pngrcb.obj, pngrutil.obj, pngtrans.obj, pngwutil.obj,\
|
||||
pngread.obj, pngmem.obj, pngwrite.obj, pngrtran.obj, pngwtran.obj,\
|
||||
pngrio.obj, pngwio.obj, pngerror.obj, pngpread.obj
|
||||
OBJS = png.obj, pngset.obj, pngget.obj, pngrutil.obj, pngtrans.obj,\
|
||||
pngwutil.obj, pngread.obj, pngmem.obj, pngwrite.obj, pngrtran.obj,\
|
||||
pngwtran.obj, pngrio.obj, pngwio.obj, pngerror.obj, pngpread.obj
|
||||
|
||||
|
||||
CFLAGS= $(C_DEB) $(CC_DEFS) $(PREF)
|
||||
@@ -35,7 +35,8 @@ clean :
|
||||
# Other dependencies.
|
||||
png.obj : png.h, pngconf.h
|
||||
pngpread.obj : png.h, pngconf.h
|
||||
pngrcb.obj : png.h, pngconf.h
|
||||
pngset.obj : png.h, pngconf.h
|
||||
pngget.obj : png.h, pngconf.h
|
||||
pngread.obj : png.h, pngconf.h
|
||||
pngrtran.obj : png.h, pngconf.h
|
||||
pngrutil.obj : png.h, pngconf.h
|
||||
|
||||
606
example.c
606
example.c
@@ -1,76 +1,108 @@
|
||||
/* example.c - an example of using libpng */
|
||||
|
||||
/* this is an example of how to use libpng to read and write
|
||||
png files. The file libpng.txt is much more verbose then
|
||||
this. If you have not read it, do so first. This was
|
||||
designed to be a starting point of an implementation.
|
||||
This is not officially part of libpng, and therefore
|
||||
does not require a copyright notice.
|
||||
|
||||
This file does not currently compile, because it is missing
|
||||
certain parts, like allocating memory to hold an image.
|
||||
You will have to supply these parts to get it to compile.
|
||||
*/
|
||||
/* This is an example of how to use libpng to read and write PNG files.
|
||||
* The file libpng.txt is much more verbose then this. If you have not
|
||||
* read it, do so first. This was designed to be a starting point of an
|
||||
* implementation. This is not officially part of libpng, and therefore
|
||||
* does not require a copyright notice.
|
||||
*
|
||||
* This file does not currently compile, because it is missing certain
|
||||
* parts, like allocating memory to hold an image. You will have to
|
||||
* supply these parts to get it to compile. For an example of a minimal
|
||||
* working PNG reader/writer, see pngtest.c, included in this distribution.
|
||||
*/
|
||||
|
||||
#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(). Returns
|
||||
* non-zero if the image is a PNG, and 0 if it isn't a PNG.
|
||||
*
|
||||
* If this call is successful, and you are going to keep the file open,
|
||||
* you should call png_set_sig_bytes(png_ptr, PNG_BYTES_TO_CHECK); once
|
||||
* you have created the png_ptr, so that libpng knows your application
|
||||
* has read that many bytes from the start of the file. Make sure you
|
||||
* don't call png_set_sig_bytes() with more than 8 bytes read or give it
|
||||
* an incorrect number of bytes read, or you will either have read too
|
||||
* many bytes (your fault), or you are telling libpng to read the wrong
|
||||
* number of magic bytes (also your fault).
|
||||
*
|
||||
* Many applications already read the first 2 or 4 bytes from the start
|
||||
* of the image to determine the file type, so it would be easiest just
|
||||
* to pass the bytes to png_check_sig() or even skip that if you know
|
||||
* you have a PNG file, and call png_set_sig_bytes().
|
||||
*/
|
||||
#define PNG_BYTES_TO_CHECK 4
|
||||
int check_if_png(char *file_name, FILE **fp)
|
||||
{
|
||||
FILE *fp;
|
||||
char buf[8];
|
||||
int ret;
|
||||
char buf[PNG_BYTES_TO_CHECK];
|
||||
|
||||
fp = fopen(file_name, "rb");
|
||||
if (!fp)
|
||||
return 0;
|
||||
ret = fread(buf, 1, 8, fp);
|
||||
fclose(fp);
|
||||
|
||||
if (ret != 8)
|
||||
/* Open the prospective PNG file. */
|
||||
if ((*fp = fopen(file_name, "rb")) != NULL);
|
||||
return 0;
|
||||
|
||||
ret = png_check_sig(buf, 8);
|
||||
/* Read in the signature bytes */
|
||||
if (fread(buf, 1, PNG_BYTES_TO_CHECK, *fp) != PNG_BYTES_TO_CHECK)
|
||||
return 0;
|
||||
|
||||
return (ret);
|
||||
/* Compare the first PNG_BYTES_TO_CHECK bytes of the signature. */
|
||||
return(png_check_sig(buf, PNG_BYTES_TO_CHECK));
|
||||
}
|
||||
|
||||
/* 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)
|
||||
/* Read a PNG file. You may want to return an error code if the read
|
||||
* fails (depending upon the failure). There are two "prototypes" given
|
||||
* here - one where we are given the filename, and we need to open the
|
||||
* file, and the other where we are given an open file (possibly with
|
||||
* some or all of the magic bytes read - see comments above).
|
||||
*/
|
||||
**** prototype 1 ****
|
||||
void read_png(char *file_name) /* We need to open the file */
|
||||
{
|
||||
FILE *fp;
|
||||
png_structp png_ptr;
|
||||
png_infop info_ptr;
|
||||
unsigned int sig_read = 0;
|
||||
png_uint_32 width, height;
|
||||
int bit_depth, color_type, interlace_type;
|
||||
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;
|
||||
png_uint_32 width, height;
|
||||
int bit_depth, color_type, interlace_type;
|
||||
**** only use one prototype! ****
|
||||
|
||||
/* 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.
|
||||
* functions. If you want to use the default stderr and longjump method,
|
||||
* you can supply NULL for the last three parameters. We also supply the
|
||||
* the compiler header file version, so that we know if the application
|
||||
* was compiled with a compatible version of the library. REQUIRED
|
||||
*/
|
||||
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,
|
||||
(void *)user_error_ptr, user_error_fn, user_warning_fn);
|
||||
|
||||
if (!png_ptr)
|
||||
if (png_ptr == NULL)
|
||||
{
|
||||
fclose(fp);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Allocate/initialize the memory for image information. REQUIRED. */
|
||||
info_ptr = png_create_info_struct();
|
||||
if (!info_ptr)
|
||||
if (info_ptr == NULL)
|
||||
{
|
||||
fclose(fp);
|
||||
png_destroy_read_struct(&png_ptr, (png_infopp)NULL, (png_infopp)NULL);
|
||||
png_destroy_read_struct(&png_ptr, (png_infopp)NULL, (png_infopp)NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
/* set error handling if you are using the setjmp/longjmp method */
|
||||
/* Set error handling if you are using the setjmp/longjmp method (this is
|
||||
* the normal method of doing things with libpng). REQUIRED unless you
|
||||
* set up your own error handlers in the png_create_read_struct() earlier.
|
||||
*/
|
||||
if (setjmp(png_ptr->jmpbuf))
|
||||
{
|
||||
/* Free all of the memory associated with the png_ptr and info_ptr */
|
||||
@@ -80,145 +112,228 @@ void read_png(char *file_name)
|
||||
return;
|
||||
}
|
||||
|
||||
/* set up the input control if you are using standard C streams */
|
||||
/* One of the following I/O initialization methods is REQUIRED */
|
||||
**** PNG file I/O method 1 ****
|
||||
/* Set up the input control if you are using standard C streams */
|
||||
png_init_io(png_ptr, fp);
|
||||
|
||||
/* if you are using replacement read functions, instead of calling
|
||||
png_init_io() here you would call */
|
||||
**** PNG file I/O method 2 ****
|
||||
/* If you are using replacement read functions, instead of calling
|
||||
* png_init_io() here you would call:
|
||||
*/
|
||||
png_set_read_fn(png_ptr, (void *)user_io_ptr, user_read_fn);
|
||||
/* where user_io_ptr is a structure you want available to the callbacks */
|
||||
**** Use only one I/O method! ****
|
||||
|
||||
/* read the file information */
|
||||
/* If we have already read some of the signature */
|
||||
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). REQUIRED
|
||||
*/
|
||||
png_read_info(png_ptr, info_ptr);
|
||||
|
||||
/* set up the transformations you want. Note that these are
|
||||
all optional. Only call them if you want them */
|
||||
png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,
|
||||
&interlace_type, NULL, NULL);
|
||||
|
||||
/* expand paletted colors into true RGB triplets */
|
||||
if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
|
||||
/**** Set up the data transformations you want. Note that these are all
|
||||
**** optional. Only call them if you want/need them. Many of the
|
||||
**** transformations only work on specific types of images, and many
|
||||
**** are mutually exclusive.
|
||||
****/
|
||||
|
||||
/* tell libpng to strip 16 bit/color files down to 8 bits/color */
|
||||
png_set_strip_16(png_ptr);
|
||||
|
||||
/* Strip alpha bytes from the input data without combining with th
|
||||
* background (not recommended).
|
||||
*/
|
||||
png_set_strip_alpha(png_ptr);
|
||||
|
||||
/* Extract multiple pixels with bit depths of 1, 2, and 4 from a single
|
||||
* byte into separate bytes (useful for paletted and grayscale images).
|
||||
*/
|
||||
png_set_packing(png_ptr);
|
||||
|
||||
/* Change the order of packed pixels to least significant bit first
|
||||
* (not useful if you are using png_set_packing). */
|
||||
png_set_packswap(png_ptr);
|
||||
|
||||
/* Expand paletted colors into true RGB triplets */
|
||||
if (color_type == PNG_COLOR_TYPE_PALETTE)
|
||||
png_set_expand(png_ptr);
|
||||
|
||||
/* expand grayscale images to the full 8 bits */
|
||||
if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY && info_ptr->bit_depth < 8)
|
||||
/* Expand grayscale images to the full 8 bits from 1, 2, or 4 bits/pixel */
|
||||
if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
|
||||
png_set_expand(png_ptr);
|
||||
|
||||
/* expand paletted or RGB images with transparency to full alpha channels
|
||||
* so the data will be available as RGBA quartets */
|
||||
if (info_ptr->valid & PNG_INFO_tRNS)
|
||||
/* Expand paletted or RGB images with transparency to full alpha channels
|
||||
* so the data will be available as RGBA quartets.
|
||||
*/
|
||||
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
|
||||
png_set_expand(png_ptr);
|
||||
|
||||
/* Set the background color to draw transparent and alpha
|
||||
images over. It is possible to set the red, green, and blue
|
||||
components directly for paletted images. */
|
||||
/* Set the background color to draw transparent and alpha images over.
|
||||
* It is possible to set the red, green, and blue components directly
|
||||
* for paletted images instead of supplying a palette index. Note that
|
||||
* even if the PNG file supplies a background, you are not required to
|
||||
* use it - you should use the (solid) application background if it has one.
|
||||
*/
|
||||
|
||||
png_color_16 my_background;
|
||||
png_color_16 my_background, *image_background);
|
||||
|
||||
if (info_ptr->valid & PNG_INFO_bKGD)
|
||||
png_set_background(png_ptr, &(info_ptr->background),
|
||||
if (png_get_bKGD(png_ptr, info_ptr, &image_background);
|
||||
png_set_background(png_ptr, image_background),
|
||||
PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);
|
||||
else
|
||||
png_set_background(png_ptr, &my_background,
|
||||
PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0);
|
||||
|
||||
/* tell libpng to handle the gamma conversion for you */
|
||||
if (info_ptr->valid & PNG_INFO_gAMA)
|
||||
png_set_gamma(png_ptr, screen_gamma, info_ptr->gamma);
|
||||
else
|
||||
png_set_gamma(png_ptr, screen_gamma, 0.45);
|
||||
|
||||
/* tell libpng to strip 16 bit/color files down to 8 bits/color */
|
||||
if (info_ptr->bit_depth == 16)
|
||||
png_set_strip_16(png_ptr);
|
||||
|
||||
/* dither rgb files down to 8 bit palette & reduce palettes
|
||||
to the number of colors available on your screen */
|
||||
if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
|
||||
/* Some suggestions as to how to get a screen gamma value */
|
||||
if (/* We have a user-defined screen gamma value */)
|
||||
{
|
||||
if (info_ptr->valid & PNG_INFO_PLTE)
|
||||
png_set_dither(png_ptr, info_ptr->palette, info_ptr->num_palette,
|
||||
max_screen_colors, info_ptr->histogram);
|
||||
screen_gamma = user-defined screen_gamma;
|
||||
}
|
||||
/* This is one way that applications share the same screen gamma value */
|
||||
else if ((gamma_str = getenv("DISPLAY_GAMMA")) != NULL)
|
||||
{
|
||||
screen_gamma = atof(gamma_str);
|
||||
}
|
||||
/* If we don't have another value */
|
||||
else
|
||||
{
|
||||
screen_gamma = 2.2; /* A good guess for PC monitors */
|
||||
screen_gamma = 1.7 or 1.0; /* A good guess for Mac systems */
|
||||
}
|
||||
|
||||
/* Tell libpng to handle the gamma conversion for you. The second call
|
||||
* is a good guess for PC generated images, but it should be configurable
|
||||
* by the user at run time by the user. It is strongly suggested that
|
||||
* your application support gamma correction.
|
||||
*/
|
||||
if (png_get_sRGB(png_ptr, info_ptr, &srgb_intent)
|
||||
png_set_sRGB(png_ptr, srgb_intent, 0);
|
||||
else
|
||||
if (png_get_gAMA(png_ptr, info_ptr, &image_gamma)
|
||||
png_set_gamma(png_ptr, screen_gamma, image_gamma);
|
||||
else
|
||||
png_set_gamma(png_ptr, screen_gamma, 0.45);
|
||||
|
||||
/* Dither RGB files down to 8 bit palette or reduce palettes
|
||||
* to the number of colors available on your screen.
|
||||
*/
|
||||
if (color_type & PNG_COLOR_MASK_COLOR)
|
||||
{
|
||||
png_uint_32 num_palette;
|
||||
png_colorp palette;
|
||||
|
||||
/* This reduces the image to the application supplied palette */
|
||||
if (we have our own palette)
|
||||
{
|
||||
png_color std_color_cube[MAX_SCREEN_COLORS] =
|
||||
{/* ... colors ... */};
|
||||
/* An array of colors to which the image should be dithered */
|
||||
png_color std_color_cube[MAX_SCREEN_COLORS];
|
||||
|
||||
png_set_dither(png_ptr, std_color_cube, MAX_SCREEN_COLORS,
|
||||
MAX_SCREEN_COLORS, NULL);
|
||||
MAX_SCREEN_COLORS, NULL, 0);
|
||||
}
|
||||
/* This reduces the image to the palette supplied in the file */
|
||||
else if (png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette)))
|
||||
{
|
||||
png_color16p histogram;
|
||||
|
||||
png_get_hIST(png_ptr, info_ptr, &histogram);
|
||||
|
||||
png_set_dither(png_ptr, palette, num_palette,
|
||||
max_screen_colors, histogram, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/* invert monocrome files to have 0 as white and 1 as black */
|
||||
if (info_ptr->bit_depth == 1 && info_ptr->color_type == PNG_COLOR_GRAY)
|
||||
png_set_invert(png_ptr);
|
||||
png_set_invert(png_ptr);
|
||||
|
||||
/* shift the pixels down to their true bit depth */
|
||||
if (info_ptr->valid & PNG_INFO_sBIT &&
|
||||
info_ptr->bit_depth > info_ptr->sig_bit)
|
||||
png_set_shift(png_ptr, &(info_ptr->sig_bit));
|
||||
/* If you want to shift the pixel values from the range [0,255] or
|
||||
* [0,65535] to the original [0,7] or [0,31], or whatever range the
|
||||
* colors were originally in:
|
||||
*/
|
||||
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT))
|
||||
{
|
||||
png_color8p sig_bit;
|
||||
|
||||
/* pack multiple pixels with bit depths of 1, 2, and 4 into bytes
|
||||
(useful only for paletted and grayscale images) */
|
||||
if (info_ptr->bit_depth < 8)
|
||||
png_set_packing(png_ptr);
|
||||
png_get_sBIT(png_ptr, info_ptr, &sig_bit);
|
||||
png_set_shift(png_ptr, sig_bit);
|
||||
}
|
||||
|
||||
/* flip the rgb pixels to bgr */
|
||||
if (info_ptr->color_type == PNG_COLOR_TYPE_RGB ||
|
||||
info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
|
||||
png_set_bgr(png_ptr);
|
||||
/* flip the RGB pixels to BGR (or RGBA to BGRA) */
|
||||
png_set_bgr(png_ptr);
|
||||
|
||||
/* swap bytes of 16 bit files to least significant bit first */
|
||||
if (info_ptr->bit_depth == 16)
|
||||
png_set_swap(png_ptr);
|
||||
/* swap the RGBA or GA data to ARGB or AG (or BGRA to ABGR) */
|
||||
png_set_swap_alpha(png_ptr);
|
||||
|
||||
/* add a filler byte to RGB files (before or after each RGB triplet) */
|
||||
if (info_ptr->bit_depth == 8 && info_ptr->color_type == PNG_COLOR_TYPE_RGB)
|
||||
png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER);
|
||||
/* swap bytes of 16 bit files to least significant byte first */
|
||||
png_set_swap(png_ptr);
|
||||
|
||||
/* turn on interlace handling if you are not using png_read_image() */
|
||||
/* Add filler (or alpha) byte (before/after each RGB triplet) */
|
||||
png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER);
|
||||
|
||||
/* Turn on interlace handling. REQUIRED if you are not using
|
||||
* png_read_image(). To see how to handle interlacing passes,
|
||||
* see the png_read_row() method below:
|
||||
*/
|
||||
number_passes = png_set_interlace_handling(png_ptr);
|
||||
|
||||
/* optional call to gamma correct and add the background to the palette
|
||||
and update info structure. */
|
||||
/* Optional call to gamma correct and add the background to the palette
|
||||
* and update info structure. REQUIRED if you are expecting libpng to
|
||||
* update the palette for you (ie you selected such a transform above).
|
||||
*/
|
||||
png_read_update_info(png_ptr, info_ptr);
|
||||
|
||||
/* allocate the memory to hold the image using the fields
|
||||
of png_info. */
|
||||
/* Allocate the memory to hold the image using the fields of info_ptr. */
|
||||
|
||||
/* the easiest way to read the image */
|
||||
/* The easiest way to read the image: */
|
||||
png_bytep row_pointers[height];
|
||||
|
||||
for (row = 0; row < height; row++)
|
||||
{
|
||||
row_pointers[row] = malloc(info_ptr->rowbytes);
|
||||
row_pointers[row] = malloc(png_get_rowbytes(png_ptr, info_ptr));
|
||||
}
|
||||
|
||||
/* Now it's time to read the image. One of these methods is REQUIRED */
|
||||
**** Read the entire image in one go ****
|
||||
png_read_image(png_ptr, row_pointers);
|
||||
|
||||
/* the other way to read images - deal with interlacing */
|
||||
**** Read the image one or more scanlines at a time ****
|
||||
/* The other way to read images - deal with interlacing: */
|
||||
|
||||
for (pass = 0; pass < number_passes; pass++)
|
||||
{
|
||||
/* Read the image using the "sparkle" effect. */
|
||||
png_read_rows(png_ptr, row_pointers, NULL, number_of_rows);
|
||||
|
||||
/* If you are only reading on row at a time, this works */
|
||||
[[[[[[[ Read the image a single row at a time ]]]]]]]
|
||||
for (y = 0; y < height; y++)
|
||||
{
|
||||
png_bytep row_pointers = row[y];
|
||||
png_read_rows(png_ptr, &row_pointers, NULL, 1);
|
||||
}
|
||||
|
||||
/* to get the rectangle effect, use the third parameter */
|
||||
png_read_rows(png_ptr, NULL, row_pointers, number_of_rows);
|
||||
|
||||
[[[[[[[ Read the image several rows at a time ]]]]]]]
|
||||
for (y = 0; y < height; y += number_of_rows)
|
||||
{
|
||||
<<<<<<<<<< Read the image using the "sparkle" effect. >>>>>>>>>>
|
||||
png_read_rows(png_ptr, row_pointers, NULL, number_of_rows);
|
||||
|
||||
<<<<<<<<<< Read the image using the "rectangle" effect >>>>>>>>>>
|
||||
png_read_rows(png_ptr, NULL, row_pointers, number_of_rows);
|
||||
<<<<<<<<<< use only one of these two methods >>>>>>>>>>
|
||||
}
|
||||
|
||||
/* if you want to display the image after every pass, do
|
||||
so here */
|
||||
[[[[[[[ use only one of these two methods ]]]]]]]
|
||||
}
|
||||
**** use only one of these two methods ****
|
||||
|
||||
/* read the rest of the file, getting any additional chunks in info_ptr */
|
||||
/* read rest of file, and get additional chunks in info_ptr - REQUIRED */
|
||||
png_read_end(png_ptr, info_ptr);
|
||||
|
||||
/* clean up after the read, and free any memory allocated */
|
||||
/* clean up after the read, and free any memory allocated - REQUIRED */
|
||||
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
|
||||
|
||||
/* close the file */
|
||||
@@ -234,15 +349,15 @@ int
|
||||
initialize_png_reader(png_structp *png_ptr, png_infop *info_ptr)
|
||||
{
|
||||
/* 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 library version is compatible in case we are using dynamically
|
||||
linked libraries.
|
||||
* 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 library version is compatible in case we are using dynamically
|
||||
* linked libraries.
|
||||
*/
|
||||
*png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,
|
||||
(void *)user_error_ptr, user_error_fn, user_warning_fn);
|
||||
|
||||
if (! *png_ptr)
|
||||
if (*png_ptr == NULL)
|
||||
{
|
||||
*info_ptr = NULL;
|
||||
return ERROR;
|
||||
@@ -250,7 +365,7 @@ initialize_png_reader(png_structp *png_ptr, png_infop *info_ptr)
|
||||
|
||||
*info_ptr = png_create_info_struct(png_ptr);
|
||||
|
||||
if (! *info_ptr)
|
||||
if (*info_ptr == NULL)
|
||||
{
|
||||
png_destroy_read_struct(png_ptr, info_ptr, (png_infopp)NULL);
|
||||
return ERROR;
|
||||
@@ -263,13 +378,14 @@ initialize_png_reader(png_structp *png_ptr, png_infop *info_ptr)
|
||||
}
|
||||
|
||||
/* this one's new. You will need to provide all three
|
||||
function callbacks, even if you aren't using them all.
|
||||
These functions shouldn't be dependent on global or
|
||||
static variables if you are decoding several images
|
||||
simultaneously. You should store stream specific data
|
||||
in a separate struct, given as the second parameter,
|
||||
and retrieve the pointer from inside the callbacks using
|
||||
the function png_get_progressive_ptr(png_ptr). */
|
||||
* function callbacks, even if you aren't using them all.
|
||||
* These functions shouldn't be dependent on global or
|
||||
* static variables if you are decoding several images
|
||||
* simultaneously. You should store stream specific data
|
||||
* in a separate struct, given as the second parameter,
|
||||
* and retrieve the pointer from inside the callbacks using
|
||||
* the function png_get_progressive_ptr(png_ptr).
|
||||
*/
|
||||
png_set_progressive_read_fn(*png_ptr, (void *)stream_data,
|
||||
info_callback, row_callback, end_callback);
|
||||
|
||||
@@ -287,15 +403,16 @@ process_data(png_structp *png_ptr, png_infop *info_ptr,
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
/* this one's new also. Simply give it chunks of data as
|
||||
they arrive from the data stream (in order, of course).
|
||||
On Segmented machines, don't give it any more than 64K.
|
||||
The library seems to run fine with sizes of 4K, although
|
||||
you can give it much less if necessary (I assume you can
|
||||
give it chunks of 1 byte, but I haven't tried with less
|
||||
than 256 bytes yet). When this function returns, you may
|
||||
want to display any rows that were generated in the row
|
||||
callback, if you aren't already displaying them there. */
|
||||
/* This one's new also. Simply give it chunks of data as
|
||||
* they arrive from the data stream (in order, of course).
|
||||
* On Segmented machines, don't give it any more than 64K.
|
||||
* The library seems to run fine with sizes of 4K, although
|
||||
* you can give it much less if necessary (I assume you can
|
||||
* give it chunks of 1 byte, but I haven't tried with less
|
||||
* than 256 bytes yet). When this function returns, you may
|
||||
* want to display any rows that were generated in the row
|
||||
* callback, if you aren't already displaying them there.
|
||||
*/
|
||||
png_process_data(*png_ptr, *info_ptr, buffer, length);
|
||||
return OK;
|
||||
}
|
||||
@@ -303,52 +420,56 @@ process_data(png_structp *png_ptr, png_infop *info_ptr,
|
||||
info_callback(png_structp png_ptr, png_infop info)
|
||||
{
|
||||
/* do any setup here, including setting any of the transformations
|
||||
mentioned in the Reading PNG files section. For now, you _must_
|
||||
call either png_start_read_image() or png_read_update_info()
|
||||
after all the transformations are set (even if you don't set
|
||||
any). You may start getting rows before png_process_data()
|
||||
returns, so this is your last chance to prepare for that. */
|
||||
* mentioned in the Reading PNG files section. For now, you _must_
|
||||
* call either png_start_read_image() or png_read_update_info()
|
||||
* after all the transformations are set (even if you don't set
|
||||
* any). You may start getting rows before png_process_data()
|
||||
* returns, so this is your last chance to prepare for that.
|
||||
*/
|
||||
}
|
||||
|
||||
row_callback(png_structp png_ptr, png_bytep new_row,
|
||||
png_uint_32 row_num, int pass)
|
||||
{
|
||||
/* this function is called for every row in the image. If the
|
||||
image is interlacing, and you turned on the interlace handler,
|
||||
this function will be called for every row in every pass.
|
||||
Some of these rows will not be changed from the previous pass.
|
||||
When the row is not changed, the new_row variable will be NULL.
|
||||
The rows and passes are called in order, so you don't really
|
||||
need the row_num and pass, but I'm supplying them because it
|
||||
may make your life easier.
|
||||
|
||||
For the non-NULL rows of interlaced images, you must call
|
||||
png_progressive_combine_row() passing in the row and the
|
||||
old row. You can call this function for NULL rows (it will
|
||||
just return) and for non-interlaced images (it just does the
|
||||
memcpy for you) if it will make the code easier. Thus, you
|
||||
can just do this for all cases: */
|
||||
* image is interlacing, and you turned on the interlace handler,
|
||||
* this function will be called for every row in every pass.
|
||||
* Some of these rows will not be changed from the previous pass.
|
||||
* When the row is not changed, the new_row variable will be NULL.
|
||||
* The rows and passes are called in order, so you don't really
|
||||
* need the row_num and pass, but I'm supplying them because it
|
||||
* may make your life easier.
|
||||
*
|
||||
* For the non-NULL rows of interlaced images, you must call
|
||||
* png_progressive_combine_row() passing in the row and the
|
||||
* old row. You can call this function for NULL rows (it will
|
||||
* just return) and for non-interlaced images (it just does the
|
||||
* memcpy for you) if it will make the code easier. Thus, you
|
||||
* can just do this for all cases:
|
||||
*/
|
||||
|
||||
png_progressive_combine_row(png_ptr, old_row, new_row);
|
||||
|
||||
/* where old_row is what was displayed for previous rows. Note
|
||||
that the first pass (pass == 0 really) will completely cover
|
||||
the old row, so the rows do not have to be initialized. After
|
||||
the first pass (and only for interlaced images), you will have
|
||||
to pass the current row, and the function will combine the
|
||||
old row and the new row. */
|
||||
* that the first pass (pass == 0 really) will completely cover
|
||||
* the old row, so the rows do not have to be initialized. After
|
||||
* the first pass (and only for interlaced images), you will have
|
||||
* to pass the current row, and the function will combine the
|
||||
* old row and the new row.
|
||||
*/
|
||||
}
|
||||
|
||||
end_callback(png_structp png_ptr, png_infop info)
|
||||
{
|
||||
/* this function is called when the whole image has been read,
|
||||
including any chunks after the image (up to and including
|
||||
the IEND). You will usually have the same info chunk as you
|
||||
had in the header, although some data may have been added
|
||||
to the comments and time fields.
|
||||
|
||||
Most people won't do much here, perhaps setting a flag that
|
||||
marks the image as finished. */
|
||||
* including any chunks after the image (up to and including
|
||||
* the IEND). You will usually have the same info chunk as you
|
||||
* had in the header, although some data may have been added
|
||||
* to the comments and time fields.
|
||||
*
|
||||
* Most people won't do much here, perhaps setting a flag that
|
||||
* marks the image as finished.
|
||||
*/
|
||||
}
|
||||
|
||||
/* write a png file */
|
||||
@@ -360,33 +481,36 @@ void write_png(char *file_name, ... other image information ...)
|
||||
|
||||
/* open the file */
|
||||
fp = fopen(file_name, "wb");
|
||||
if (!fp)
|
||||
if (fp == NULL)
|
||||
return;
|
||||
|
||||
/* 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 library version is compatible in case we are using dynamically
|
||||
linked libraries.
|
||||
* 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 library version is compatible with the one used at compile time,
|
||||
* in case we are using dynamically linked libraries. REQUIRED.
|
||||
*/
|
||||
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,
|
||||
(void *)user_error_ptr, user_error_fn, user_warning_fn);
|
||||
|
||||
if (!png_ptr)
|
||||
if (png_ptr == NULL)
|
||||
{
|
||||
fclose(fp);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Allocate/initialize the image information data. REQUIRED */
|
||||
info_ptr = png_create_info_struct(png_ptr);
|
||||
if (!info_ptr)
|
||||
if (info_ptr == NULL)
|
||||
{
|
||||
fclose(fp);
|
||||
png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
/* set error handling */
|
||||
/* Set error handling. REQUIRED if you aren't supplying your own
|
||||
* error hadnling functions in the png_create_write_struct() call.
|
||||
*/
|
||||
if (setjmp(png_ptr->jmpbuf))
|
||||
{
|
||||
/* If we get here, we had a problem reading the file */
|
||||
@@ -395,67 +519,107 @@ void write_png(char *file_name, ... other image information ...)
|
||||
return;
|
||||
}
|
||||
|
||||
/* One of the following I/O initialization functions is REQUIRED */
|
||||
**** I/O initialization method 1 ****
|
||||
/* set up the output control if you are using standard C streams */
|
||||
png_init_io(png_ptr, fp);
|
||||
**** I/O initialization method 2 ****
|
||||
/* If you are using replacement read functions, instead of calling
|
||||
* png_init_io() here you would call */
|
||||
png_set_write_fn(png_ptr, (void *)user_io_ptr, user_write_fn,
|
||||
user_IO_flush_function);
|
||||
/* where user_io_ptr is a structure you want available to the callbacks */
|
||||
**** only use 1 initialization method ****
|
||||
|
||||
/* 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 image information here. Width and height are up to 2^31,
|
||||
* bit_depth is one of 1, 2, 4, 8, or 16, but valid values also depend on
|
||||
* the color_type selected. color_type is one of PNG_COLOR_TYPE_GRAY,
|
||||
* PNG_COLOR_TYPE_GRAY_ALPHA, PNG_COLOR_TYPE_PALETTE, PNG_COLOR_TYPE_RGB,
|
||||
* or PNG_COLOR_TYPE_RGB_ALPHA. interlace is either PNG_INTERLACE_NONE or
|
||||
* PNG_INTERLACE_ADAM7, and the compression_type and filter_type MUST
|
||||
* currently be PNG_COMPRESSION_TYPE_BASE and PNG_FILTER_TYPE_BASE. REQUIRED
|
||||
*/
|
||||
png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth, PNG_COLOR_TYPE_???,
|
||||
PNG_INTERLACE_????, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
|
||||
|
||||
/* set the file information here */
|
||||
info_ptr->width = ;
|
||||
info_ptr->height = ;
|
||||
etc.
|
||||
|
||||
/* set the palette if there is one */
|
||||
info_ptr->valid |= PNG_INFO_PLTE;
|
||||
info_ptr->palette = malloc(256 * sizeof (png_color));
|
||||
info_ptr->num_palette = 256;
|
||||
/* set the palette if there is one. REQUIRED for indexed-color images */
|
||||
palette = png_malloc(png_ptr, 256 * sizeof (png_color));
|
||||
... set palette colors ...
|
||||
png_set_PLTE(png_ptr, info_ptr, palette, 256);
|
||||
|
||||
/* optional significant bit chunk */
|
||||
info_ptr->valid |= PNG_INFO_sBIT;
|
||||
/* if we are dealing with a grayscale image then */
|
||||
info_ptr->sig_bit.gray = true_bit_depth;
|
||||
sig_bit.gray = true_bit_depth;
|
||||
/* otherwise, if we are dealing with a color image then */
|
||||
info_ptr->sig_bit.red = true_red_bit_depth;
|
||||
info_ptr->sig_bit.green = true_green_bit_depth;
|
||||
info_ptr->sig_bit.blue = true_blue_bit_depth;
|
||||
sig_bit.red = true_red_bit_depth;
|
||||
sig_bit.green = true_green_bit_depth;
|
||||
sig_bit.blue = true_blue_bit_depth;
|
||||
/* if the image has an alpha channel then */
|
||||
info_ptr->sig_bit.alpha = true_alpha_bit_depth;
|
||||
sig_bit.alpha = true_alpha_bit_depth;
|
||||
png_set_sBIT(png_ptr, info_ptr, sig_bit);
|
||||
|
||||
|
||||
/* optional gamma chunk is strongly suggested if you have any guess
|
||||
as to the correct gamma of the image */
|
||||
info_ptr->valid |= PNG_INFO_gAMA;
|
||||
info_ptr->gamma = gamma;
|
||||
/* Optional gamma chunk is strongly suggested if you have any guess
|
||||
* as to the correct gamma of the image.
|
||||
*/
|
||||
png_set_gAMA(png_ptr, info_ptr, gamma);
|
||||
|
||||
/* other optional chunks like cHRM, bKGD, tRNS, tEXt, tIME, oFFs, pHYs, */
|
||||
/* Optionally write comments into the image */
|
||||
text_ptr[0].key = "Title";
|
||||
text_ptr[0].text = "Mona Lisa";
|
||||
text_ptr[0].compression = PNG_TEXT_COMPRESSION_NONE;
|
||||
text_ptr[1].key = "Author";
|
||||
text_ptr[1].text = "Leonardo DaVinci";
|
||||
text_ptr[1].compression = PNG_TEXT_COMPRESSION_NONE;
|
||||
text_ptr[2].key = "Description";
|
||||
text_ptr[2].text = "<long text>";
|
||||
text_ptr[2].compression = PNG_TEXT_COMPRESSION_zTXt;
|
||||
png_set_text(png_ptr, info_ptr, text_ptr, 2);
|
||||
|
||||
/* write the file header information */
|
||||
/* other optional chunks like cHRM, bKGD, tRNS, tIME, oFFs, pHYs, */
|
||||
/* note that if sRGB is present the cHRM chunk must be ignored
|
||||
* on read and must be written in accordance with the sRGB profile */
|
||||
|
||||
/* Write the file header information. REQUIRED */
|
||||
png_write_info(png_ptr, info_ptr);
|
||||
|
||||
/* Once we write out the header, the compression type on the text
|
||||
* chunks gets changed to PNG_TEXT_COMPRESSION_NONE_WR or
|
||||
* PNG_TEXT_COMPRESSION_zTXt_WR, so it doesn't get written out again
|
||||
* at the end.
|
||||
*/
|
||||
|
||||
/* set up the transformations you want. Note that these are
|
||||
all optional. Only call them if you want them */
|
||||
* all optional. Only call them if you want them.
|
||||
*/
|
||||
|
||||
/* invert monocrome pixels */
|
||||
png_set_invert(png_ptr);
|
||||
|
||||
/* shift the pixels up to a legal bit depth and fill in
|
||||
as appropriate to correctly scale the image */
|
||||
png_set_shift(png_ptr, &(info_ptr->sig_bit));
|
||||
/* Shift the pixels up to a legal bit depth and fill in
|
||||
* as appropriate to correctly scale the image.
|
||||
*/
|
||||
png_set_shift(png_ptr, &sig_bit);
|
||||
|
||||
/* pack pixels into bytes */
|
||||
png_set_packing(png_ptr);
|
||||
|
||||
/* flip bgr pixels to rgb */
|
||||
/* swap location of alpha bytes from ARGB to RGBA */
|
||||
png_set_swap_alpha(png_ptr);
|
||||
|
||||
/* Get rid of filler (OR ALPHA) bytes, pack XRGB/RGBX/ARGB/RGBA into
|
||||
* RGB (4 channels -> 3 channels). The second parameter is not used.
|
||||
*/
|
||||
png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
|
||||
|
||||
/* flip BGR pixels to RGB */
|
||||
png_set_bgr(png_ptr);
|
||||
|
||||
/* swap bytes of 16 bit files to most significant bit first */
|
||||
/* swap bytes of 16-bit files to most significant byte first */
|
||||
png_set_swap(png_ptr);
|
||||
|
||||
/* get rid of filler bytes, pack rgb into 3 bytes. The
|
||||
filler number is not used. */
|
||||
png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
|
||||
/* swap bits of 1, 2, 4 bit packed pixel formats */
|
||||
png_set_packswap(png_ptr);
|
||||
|
||||
/* turn on interlace handling if you are not using png_write_image() */
|
||||
if (interlacing)
|
||||
@@ -463,14 +627,22 @@ void write_png(char *file_name, ... other image information ...)
|
||||
else
|
||||
number_passes = 1;
|
||||
|
||||
/* the easiest way to write the image (you may choose to allocate the
|
||||
memory differently, however) */
|
||||
/* The easiest way to write the image (you may have a different memory
|
||||
* layout, however, so choose what fits your needs best). You need to
|
||||
* use the first method if you aren't handling interlacing yourself.
|
||||
*/
|
||||
png_byte row_pointers[height][width];
|
||||
|
||||
/* One of the following output methods is REQUIRED */
|
||||
**** write out the entire image data in one call ***
|
||||
png_write_image(png_ptr, row_pointers);
|
||||
|
||||
/* the other way to write the image - deal with interlacing */
|
||||
|
||||
**** write out the image data by one or more scanlines ****
|
||||
/* The number of passes is either 1 for non-interlaced images,
|
||||
* or 7 for interlaced images.
|
||||
*/
|
||||
for (pass = 0; pass < number_passes; pass++)
|
||||
{
|
||||
/* Write a few rows at a time. */
|
||||
@@ -483,24 +655,22 @@ void write_png(char *file_name, ... other image information ...)
|
||||
png_write_rows(png_ptr, &row_pointers, 1);
|
||||
}
|
||||
}
|
||||
**** use only one output method ****
|
||||
|
||||
/* You can write optional chunks like tEXt, tIME at the end as well.
|
||||
* Note that if you wrote tEXt or zTXt chunks before the image, and
|
||||
* you aren't writing out more at the end, you have to set
|
||||
* info_ptr->num_text = 0 or they will be written out again.
|
||||
/* You can write optional chunks like tEXt, zTXt, and tIME at the end
|
||||
* as well.
|
||||
*/
|
||||
|
||||
/* write the rest of the file */
|
||||
/* It is REQUIRED to call this to finish writing the rest of the file */
|
||||
png_write_end(png_ptr, info_ptr);
|
||||
|
||||
/* if you malloced the palette, free it here */
|
||||
if (info_ptr->palette)
|
||||
free(info_ptr->palette);
|
||||
free(info_ptr->palette);
|
||||
|
||||
/* if you allocated any text comments, free them here */
|
||||
|
||||
/* clean up after the write, and free any memory allocated */
|
||||
png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
|
||||
png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
|
||||
|
||||
/* close the file */
|
||||
fclose(fp);
|
||||
|
||||
797
libpng.txt
797
libpng.txt
File diff suppressed because it is too large
Load Diff
163
makefile.aco
163
makefile.aco
@@ -7,41 +7,148 @@ 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
|
||||
LibFile $(LibFileflags) @.o.png @.o.pngerror @.o.pngrio @.o.pngwio \
|
||||
@.o.pngmem @.o.pngpread @.o.pngrcb @.o.pngread @.o.pngrtran \
|
||||
@.o.pngpread @.o.pngset @.o.pngget @.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
|
||||
LibFile $(LibFileflags) @.o.png @.o.pngerror @.o.pngrio @.o.pngrtran \
|
||||
@.o.pngmem @.o.pngpread @.o.pngset @.o.pngget @.o.pngread @.o.pngwio \
|
||||
@.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.pngset @.mm.pngget @.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.pngset @.mm.pngget \
|
||||
@.mm.pngread @.mm.pngrtran @.mm.pngrutil @.mm.pngtrans @.mm.pngwrite \
|
||||
@.mm.pngwtran @.mm.pngwutil
|
||||
|
||||
|
||||
# User-editable dependencies:
|
||||
# (C) Copyright 1997 Tom Tanner
|
||||
Test: @.pngtest
|
||||
<Prefix$Dir>.pngtest
|
||||
@remove <Prefix$Dir>.pngtest
|
||||
|
||||
#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.pngtest: c.pngtest
|
||||
o.pngtest: h.png
|
||||
o.pngtest: Zlib:h.zlib
|
||||
o.pngtest: Zlib:h.zconf
|
||||
o.pngtest: h.pngconf
|
||||
mm.png: LibPng:c.png
|
||||
mm.png: LibPng:h.png
|
||||
mm.png: Zlib:h.zlib
|
||||
mm.png: Zlib:h.zconf
|
||||
mm.png: LibPng:h.pngconf
|
||||
mm.png: MemCheck:ANSI.h.stdio
|
||||
mm.pngerror: LibPng:c.pngerror
|
||||
mm.pngerror: LibPng:h.png
|
||||
mm.pngerror: Zlib:h.zlib
|
||||
mm.pngerror: Zlib:h.zconf
|
||||
mm.pngerror: LibPng:h.pngconf
|
||||
mm.pngerror: MemCheck:ANSI.h.stdio
|
||||
mm.pngrio: LibPng:c.pngrio
|
||||
mm.pngrio: LibPng:h.png
|
||||
mm.pngrio: Zlib:h.zlib
|
||||
mm.pngrio: Zlib:h.zconf
|
||||
mm.pngrio: LibPng:h.pngconf
|
||||
mm.pngrio: MemCheck:ANSI.h.stdio
|
||||
mm.pngwio: LibPng:c.pngwio
|
||||
mm.pngwio: LibPng:h.png
|
||||
mm.pngwio: Zlib:h.zlib
|
||||
mm.pngwio: Zlib:h.zconf
|
||||
mm.pngwio: LibPng:h.pngconf
|
||||
mm.pngwio: MemCheck:ANSI.h.stdio
|
||||
mm.pngmem: LibPng:c.pngmem
|
||||
mm.pngmem: LibPng:h.png
|
||||
mm.pngmem: Zlib:h.zlib
|
||||
mm.pngmem: Zlib:h.zconf
|
||||
mm.pngmem: LibPng:h.pngconf
|
||||
mm.pngmem: MemCheck:ANSI.h.stdio
|
||||
mm.pngpread: LibPng:c.pngpread
|
||||
mm.pngpread: LibPng:h.png
|
||||
mm.pngpread: Zlib:h.zlib
|
||||
mm.pngpread: Zlib:h.zconf
|
||||
mm.pngpread: LibPng:h.pngconf
|
||||
mm.pngpread: MemCheck:ANSI.h.stdio
|
||||
mm.pngset: LibPng:c.pngset
|
||||
mm.pngset: LibPng:h.png
|
||||
mm.pngset: Zlib:h.zlib
|
||||
mm.pngset: Zlib:h.zconf
|
||||
mm.pngset: LibPng:h.pngconf
|
||||
mm.pngset: MemCheck:ANSI.h.stdio
|
||||
mm.pngget: LibPng:c.pngget
|
||||
mm.pngget: LibPng:h.png
|
||||
mm.pngget: Zlib:h.zlib
|
||||
mm.pngget: Zlib:h.zconf
|
||||
mm.pngget: LibPng:h.pngconf
|
||||
mm.pngget: MemCheck:ANSI.h.stdio
|
||||
mm.pngread: LibPng:c.pngread
|
||||
mm.pngread: LibPng:h.png
|
||||
mm.pngread: Zlib:h.zlib
|
||||
mm.pngread: Zlib:h.zconf
|
||||
mm.pngread: LibPng:h.pngconf
|
||||
mm.pngread: MemCheck:ANSI.h.stdio
|
||||
mm.pngrtran: LibPng:c.pngrtran
|
||||
mm.pngrtran: LibPng:h.png
|
||||
mm.pngrtran: Zlib:h.zlib
|
||||
mm.pngrtran: Zlib:h.zconf
|
||||
mm.pngrtran: LibPng:h.pngconf
|
||||
mm.pngrtran: MemCheck:ANSI.h.stdio
|
||||
mm.pngrutil: LibPng:c.pngrutil
|
||||
mm.pngrutil: LibPng:h.png
|
||||
mm.pngrutil: Zlib:h.zlib
|
||||
mm.pngrutil: Zlib:h.zconf
|
||||
mm.pngrutil: LibPng:h.pngconf
|
||||
mm.pngrutil: MemCheck:ANSI.h.stdio
|
||||
mm.pngtrans: LibPng:c.pngtrans
|
||||
mm.pngtrans: LibPng:h.png
|
||||
mm.pngtrans: Zlib:h.zlib
|
||||
mm.pngtrans: Zlib:h.zconf
|
||||
mm.pngtrans: LibPng:h.pngconf
|
||||
mm.pngtrans: MemCheck:ANSI.h.stdio
|
||||
mm.pngwrite: LibPng:c.pngwrite
|
||||
mm.pngwrite: LibPng:h.png
|
||||
mm.pngwrite: Zlib:h.zlib
|
||||
mm.pngwrite: Zlib:h.zconf
|
||||
mm.pngwrite: LibPng:h.pngconf
|
||||
mm.pngwrite: MemCheck:ANSI.h.stdio
|
||||
mm.pngwtran: LibPng:c.pngwtran
|
||||
mm.pngwtran: LibPng:h.png
|
||||
mm.pngwtran: Zlib:h.zlib
|
||||
mm.pngwtran: Zlib:h.zconf
|
||||
mm.pngwtran: LibPng:h.pngconf
|
||||
mm.pngwtran: MemCheck:ANSI.h.stdio
|
||||
mm.pngwutil: LibPng:c.pngwutil
|
||||
mm.pngwutil: LibPng:h.png
|
||||
mm.pngwutil: Zlib:h.zlib
|
||||
mm.pngwutil: Zlib:h.zconf
|
||||
mm.pngwutil: LibPng:h.pngconf
|
||||
mm.pngwutil: MemCheck:ANSI.h.stdio
|
||||
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
|
||||
@@ -67,11 +174,16 @@ 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.pngset: c.pngset
|
||||
o.pngset: h.png
|
||||
o.pngset: Zlib:h.zlib
|
||||
o.pngset: Zlib:h.zconf
|
||||
o.pngset: h.pngconf
|
||||
o.pngget: c.pngget
|
||||
o.pngget: h.png
|
||||
o.pngget: Zlib:h.zlib
|
||||
o.pngget: Zlib:h.zconf
|
||||
o.pngget: h.pngconf
|
||||
o.pngread: c.pngread
|
||||
o.pngread: h.png
|
||||
o.pngread: Zlib:h.zlib
|
||||
@@ -107,8 +219,3 @@ 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
|
||||
|
||||
@@ -22,7 +22,7 @@ AR= oml
|
||||
# make directory command
|
||||
MKDIR= makedir
|
||||
|
||||
OBJS = png.o pngrcb.o pngrutil.o pngtrans.o pngwutil.o pngpread.o \
|
||||
OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o pngpread.o \
|
||||
pngread.o pngerror.o pngwrite.o pngrtran.o pngwtran.o pngrio.o pngwio.o pngmem.o
|
||||
|
||||
all: libpng.lib pngtest
|
||||
|
||||
@@ -10,7 +10,7 @@ LDFLAGS=-lpng -lz -lm
|
||||
|
||||
# where make install puts libpng.a and png.h
|
||||
|
||||
OBJS = $(LBR)(png.o) $(LBR)(pngrcb.o) $(LBR)(pngrutil.o)\
|
||||
OBJS = $(LBR)(png.o) $(LBR)(pngset.o) $(LBR)(pngget.o) $(LBR)(pngrutil.o)\
|
||||
$(LBR)(pngtrans.o) $(LBR)(pngwutil.o)\
|
||||
$(LBR)(pngread.o) $(LBR)(pngerror.o) $(LBR)(pngwrite.o)\
|
||||
$(LBR)(pngrtran.o) $(LBR)(pngwtran.o)\
|
||||
|
||||
@@ -74,7 +74,8 @@ OBJS = \
|
||||
pngerror.$(O) \
|
||||
pngmem.$(O) \
|
||||
pngpread.$(O) \
|
||||
pngrcb.$(O) \
|
||||
pngset.$(O) \
|
||||
pngget.$(O) \
|
||||
pngread.$(O) \
|
||||
pngrio.$(O) \
|
||||
pngrtran.$(O) \
|
||||
@@ -91,7 +92,8 @@ LIBOBJS = \
|
||||
+pngmem.$(O) \
|
||||
+pngpread.$(O) \
|
||||
+pngread.$(O) \
|
||||
+pngrcb.$(O) \
|
||||
+pngset.$(O) \
|
||||
+pngget.$(O) \
|
||||
+pngrio.$(O) \
|
||||
+pngrtran.$(O) \
|
||||
+pngrutil.$(O) \
|
||||
@@ -126,7 +128,8 @@ test:
|
||||
## Minor Targets
|
||||
|
||||
png.obj: png.c
|
||||
pngrcb.obj: pngrcb.c
|
||||
pngset.obj: pngset.c
|
||||
pngget.obj: pngget.c
|
||||
pngread.obj: pngread.c
|
||||
pngpread.obj: pngpread.c
|
||||
pngrtran.obj: pngrtran.c
|
||||
|
||||
@@ -1,19 +1,25 @@
|
||||
# makefile for libpng
|
||||
# makefile for libpng on DEC Alpha Unix
|
||||
# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc.
|
||||
# For conditions of distribution and use, see copyright notice in png.h
|
||||
|
||||
CC=cc
|
||||
CFLAGS=-I../zlib -O
|
||||
LDFLAGS=-L. -L../zlib/ -lpng -lz -lm
|
||||
# Where the zlib library and include files are located
|
||||
#ZLIBLIB=/usr/local/lib
|
||||
#ZLIBINC=/usr/local/include
|
||||
ZLIBLIB=../zlib
|
||||
ZLIBINC=../zlib
|
||||
|
||||
#RANLIB=ranlib
|
||||
RANLIB=echo
|
||||
CC=cc
|
||||
CFLAGS=-std -w1 -I$(ZLIBINC) -O # -g -DPNG_DEBUG=1
|
||||
LDFLAGS=-L. -L$(ZLIBLIB) -lpng -lz -lm
|
||||
|
||||
#RANLIB=echo
|
||||
RANLIB=ranlib
|
||||
|
||||
# where make install puts libpng.a and png.h
|
||||
prefix=/usr/local
|
||||
|
||||
OBJS = png.o pngrcb.o pngrutil.o pngtrans.o pngwutil.o \
|
||||
pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o
|
||||
OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \
|
||||
pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \
|
||||
pngwtran.o pngmem.o pngerror.o pngpread.o
|
||||
|
||||
all: libpng.a pngtest
|
||||
@@ -48,7 +54,8 @@ pngerror.o: png.h pngconf.h
|
||||
pngrio.o: png.h pngconf.h
|
||||
pngwio.o: png.h pngconf.h
|
||||
pngmem.o: png.h pngconf.h
|
||||
pngrcb.o: png.h pngconf.h
|
||||
pngset.o: png.h pngconf.h
|
||||
pngget.o: png.h pngconf.h
|
||||
pngread.o: png.h pngconf.h
|
||||
pngrtran.o: png.h pngconf.h
|
||||
pngrutil.o: png.h pngconf.h
|
||||
@@ -1,4 +1,4 @@
|
||||
# gcc/DOS makefile for libpng
|
||||
# DJGPP (DOS gcc) makefile for libpng
|
||||
# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc.
|
||||
# For conditions of distribution and use, see copyright notice in png.h
|
||||
|
||||
@@ -12,7 +12,7 @@ RANLIB=ranlib
|
||||
#prefix=/usr/local
|
||||
prefix=.
|
||||
|
||||
OBJS = png.o pngrcb.o pngrutil.o pngtrans.o pngwutil.o \
|
||||
OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \
|
||||
pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o pngwtran.o \
|
||||
pngmem.o pngerror.o pngpread.o
|
||||
|
||||
@@ -38,7 +38,8 @@ pngerror.o: png.h pngconf.h
|
||||
pngrio.o: png.h pngconf.h
|
||||
pngwio.o: png.h pngconf.h
|
||||
pngmem.o: png.h pngconf.h
|
||||
pngrcb.o: png.h pngconf.h
|
||||
pngset.o: png.h pngconf.h
|
||||
pngget.o: png.h pngconf.h
|
||||
pngread.o: png.h pngconf.h
|
||||
pngpread.o: png.h pngconf.h
|
||||
pngrtran.o: png.h pngconf.h
|
||||
107
makefile.elf
107
makefile.elf
@@ -1,74 +1,97 @@
|
||||
# makefile for libpng on (linux) ELF
|
||||
# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc.
|
||||
# makefile for libpng on Linux ELF with gcc
|
||||
# Copyright (C) 1996, 1997 Andreas Dilger
|
||||
# Copyright (C) 1998 Glenn Randers-Pehrson
|
||||
# For conditions of distribution and use, see copyright notice in png.h
|
||||
|
||||
CC=gcc
|
||||
CFLAGS=-I../zlib -O2 -Wall -fPIC
|
||||
LDFLAGS=-L. -Wl,-rpath,. -L../zlib/ -Wl,-rpath,../zlib/ -lpng -lz -lm
|
||||
|
||||
# Where the zlib library and include files are located
|
||||
#ZLIBLIB=/usr/local/lib
|
||||
#ZLIBINC=/usr/local/include
|
||||
ZLIBLIB=../zlib
|
||||
ZLIBINC=../zlib
|
||||
|
||||
WARNMORE=-Wwrite-strings -Wpointer-arith -Wshadow \
|
||||
-Wmissing-declarations -Wtraditional -Wcast-align \
|
||||
-Wstrict-prototypes -Wmissing-prototypes #-Wconversion
|
||||
CFLAGS=-I$(ZLIBINC) -Wall -O3 -funroll-loops -malign-loops=2 \
|
||||
-malign-functions=2 #$(WARNMORE) -g -DPNG_DEBUG=5
|
||||
LDFLAGS=-L. -Wl,-rpath,. -L$(ZLIBLIB) -Wl,-rpath,$(ZLIBLIB) -lpng -lz -lm
|
||||
|
||||
RANLIB=ranlib
|
||||
#RANLIB=echo
|
||||
|
||||
PNGVER = 0.89
|
||||
PNGMAJ = 2
|
||||
PNGMIN = 0.97
|
||||
PNGVER = $(PNGMAJ).$(PNGMIN)
|
||||
|
||||
# where make install puts libpng.a, libpng.so*, and png.h
|
||||
prefix=/usr/local
|
||||
INCPATH=$(prefix)/include
|
||||
LIBPATH=$(prefix)/lib
|
||||
|
||||
OBJS = png.o pngrcb.o pngrutil.o pngtrans.o pngwutil.o \
|
||||
OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \
|
||||
pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \
|
||||
pngwtran.o pngmem.o pngerror.o pngpread.o
|
||||
|
||||
all: libpng.so pngtest
|
||||
OBJSDLL = $(OBJS:.o=.pic.o)
|
||||
|
||||
.SUFFIXES: .c .o .pic.o
|
||||
|
||||
.c.pic.o:
|
||||
$(CC) -c $(CFLAGS) -fPIC -o $@ $*.c
|
||||
|
||||
all: libpng.a libpng.so pngtest
|
||||
|
||||
libpng.a: $(OBJS)
|
||||
ar rc $@ $(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): $(OBJSDLL)
|
||||
gcc -shared -Wl,-soname,libpng.so.$(PNGMAJ) -o libpng.so.$(PNGVER) \
|
||||
$(OBJSDLL)
|
||||
|
||||
pngtest: pngtest.o libpng.so
|
||||
$(CC) -o pngtest $(CCFLAGS) pngtest.o $(LDFLAGS)
|
||||
$(CC) -o pngtest $(CFLAGS) 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)
|
||||
install: libpng.a libpng.so.$(PNGVER)
|
||||
-@mkdir $(INCPATH) $(LIBPATH)
|
||||
cp png.h pngconf.h $(INCPATH)
|
||||
chmod 644 $(INCPATH)/png.h $(INCPATH)/pngconf.h
|
||||
cp libpng.a libpng.so.$(PNGVER) $(LIBPATH)
|
||||
chmod 755 $(LIBPATH)/libpng.so.$(PNGVER)
|
||||
-@/bin/rm -f $(LIBPATH)/libpng.so.$(PNGMAJ) $(LIBPATH)/libpng.so
|
||||
(cd $(LIBPATH); 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
|
||||
/bin/rm -f *.o libpng.a 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
|
||||
pngrio.o: png.h pngconf.h
|
||||
pngwio.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
|
||||
png.o png.pic.o: png.h pngconf.h
|
||||
pngerror.o pngerror.pic.o: png.h pngconf.h
|
||||
pngrio.o pngrio.pic.o: png.h pngconf.h
|
||||
pngwio.o pngwio.pic.o: png.h pngconf.h
|
||||
pngmem.o pngmem.pic.o: png.h pngconf.h
|
||||
pngset.o pngset.pic.o: png.h pngconf.h
|
||||
pngget.o pngget.pic.o: png.h pngconf.h
|
||||
pngread.o pngread.pic.o: png.h pngconf.h
|
||||
pngrtran.o pngrtran.pic.o: png.h pngconf.h
|
||||
pngrutil.o pngrutil.pic.o: png.h pngconf.h
|
||||
pngtrans.o pngtrans.pic.o: png.h pngconf.h
|
||||
pngwrite.o pngwrite.pic.o: png.h pngconf.h
|
||||
pngwtran.o pngwtran.pic.o: png.h pngconf.h
|
||||
pngwutil.o pngwutil.pic.o: png.h pngconf.h
|
||||
pngpread.o pngpread.pic.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
|
||||
|
||||
@@ -14,7 +14,7 @@ RANLIB=ranlib
|
||||
# where make install puts libpng.a and png.h
|
||||
prefix=/usr/local
|
||||
|
||||
OBJS = png.o pngrcb.o pngrutil.o pngtrans.o pngwutil.o \
|
||||
OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \
|
||||
pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \
|
||||
pngwtran.o pngmem.o pngerror.o pngpread.o
|
||||
|
||||
@@ -60,7 +60,8 @@ pngerror.o: png.h pngconf.h
|
||||
pngrio.o: png.h pngconf.h
|
||||
pngwio.o: png.h pngconf.h
|
||||
pngmem.o: png.h pngconf.h
|
||||
pngrcb.o: png.h pngconf.h
|
||||
pngset.o: png.h pngconf.h
|
||||
pngget.o: png.h pngconf.h
|
||||
pngread.o: png.h pngconf.h
|
||||
pngpread.o: png.h pngconf.h
|
||||
pngrtran.o: png.h pngconf.h
|
||||
|
||||
@@ -13,7 +13,7 @@ RANLIB=echo
|
||||
# where make install puts libpng.a and png.h
|
||||
prefix=/usr/local
|
||||
|
||||
OBJS = png.o pngrcb.o pngrutil.o pngtrans.o pngwutil.o \
|
||||
OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \
|
||||
pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \
|
||||
pngwtran.o pngmem.o pngerror.o pngpread.o
|
||||
|
||||
@@ -49,7 +49,8 @@ pngerror.o: png.h pngconf.h
|
||||
pngrio.o: png.h pngconf.h
|
||||
pngwio.o: png.h pngconf.h
|
||||
pngmem.o: png.h pngconf.h
|
||||
pngrcb.o: png.h pngconf.h
|
||||
pngset.o: png.h pngconf.h
|
||||
pngget.o: png.h pngconf.h
|
||||
pngread.o: png.h pngconf.h
|
||||
pngpread.o: png.h pngconf.h
|
||||
pngrtran.o: png.h pngconf.h
|
||||
|
||||
13
makefile.msc
13
makefile.msc
@@ -16,15 +16,19 @@ O=.obj
|
||||
ERRFILE= >> pngerrs
|
||||
|
||||
# variables
|
||||
OBJS1 = png$(O) pngrcb$(O) pngrutil$(O) pngtrans$(O) pngwutil$(O) pngmem$(O) pngpread$(O)
|
||||
OBJS2 = pngread$(O) pngerror$(O) pngwrite$(O) pngrtran$(O) pngwtran$(O) pngrio$(O) pngwio$(O)
|
||||
OBJS1 = png$(O) pngset$(O) pngget$(O) pngrutil$(O) pngtrans$(O) pngwutil$(O)
|
||||
OBJS2 = pngmem$(O) pngpread$(O) pngread$(O) pngerror$(O) pngwrite$(O)
|
||||
OBJS3 = pngrtran$(O) pngwtran$(O) pngrio$(O) pngwio$(O)
|
||||
|
||||
all: libpng.lib
|
||||
|
||||
png$(O): png.h pngconf.h
|
||||
$(CC) -c $(CFLAGS) $*.c $(ERRFILE)
|
||||
|
||||
pngrcb$(O): png.h pngconf.h
|
||||
pngset$(O): png.h pngconf.h
|
||||
$(CC) -c $(CFLAGS) $*.c $(ERRFILE)
|
||||
|
||||
pngget$(O): png.h pngconf.h
|
||||
$(CC) -c $(CFLAGS) $*.c $(ERRFILE)
|
||||
|
||||
pngread$(O): png.h pngconf.h
|
||||
@@ -66,10 +70,11 @@ pngwtran$(O): png.h pngconf.h
|
||||
pngwutil$(O): png.h pngconf.h
|
||||
$(CC) -c $(CFLAGS) $*.c $(ERRFILE)
|
||||
|
||||
libpng.lib: $(OBJS1) $(OBJS2)
|
||||
libpng.lib: $(OBJS1) $(OBJS2) $(OBJS3)
|
||||
del libpng.lib
|
||||
lib libpng $(OBJS1);
|
||||
lib libpng $(OBJS2);
|
||||
lib libpng $(OBJS3);
|
||||
|
||||
pngtest.exe: pngtest.obj libpng.lib
|
||||
$(LD) $(LDFLAGS) pngtest.obj,,,libpng.lib ..\zlib\zlib.lib ;
|
||||
|
||||
21
makefile.std
21
makefile.std
@@ -2,17 +2,23 @@
|
||||
# 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
|
||||
LDFLAGS=-L. -L../zlib/ -lpng -lz -lm
|
||||
# Where the zlib library and include files are located
|
||||
#ZLIBLIB=/usr/local/lib
|
||||
#ZLIBINC=/usr/local/include
|
||||
ZLIBLIB=../zlib
|
||||
ZLIBINC=../zlib
|
||||
|
||||
#RANLIB=ranlib
|
||||
RANLIB=echo
|
||||
CC=cc
|
||||
CFLAGS=-I$(ZLIBINC) -O # -g -DPNG_DEBUG=1
|
||||
LDFLAGS=-L. -L$(ZLIBLIB) -lpng -lz -lm
|
||||
|
||||
#RANLIB=echo
|
||||
RANLIB=ranlib
|
||||
|
||||
# where make install puts libpng.a and png.h
|
||||
prefix=/usr/local
|
||||
|
||||
OBJS = png.o pngrcb.o pngrutil.o pngtrans.o pngwutil.o \
|
||||
OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \
|
||||
pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \
|
||||
pngwtran.o pngmem.o pngerror.o pngpread.o
|
||||
|
||||
@@ -48,7 +54,8 @@ pngerror.o: png.h pngconf.h
|
||||
pngrio.o: png.h pngconf.h
|
||||
pngwio.o: png.h pngconf.h
|
||||
pngmem.o: png.h pngconf.h
|
||||
pngrcb.o: png.h pngconf.h
|
||||
pngset.o: png.h pngconf.h
|
||||
pngget.o: png.h pngconf.h
|
||||
pngread.o: png.h pngconf.h
|
||||
pngrtran.o: png.h pngconf.h
|
||||
pngrutil.o: png.h pngconf.h
|
||||
|
||||
72
makefile.sun
Normal file
72
makefile.sun
Normal file
@@ -0,0 +1,72 @@
|
||||
# makefile for libpng
|
||||
# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc.
|
||||
# For conditions of distribution and use, see copyright notice in png.h
|
||||
|
||||
# Where the zlib library and include files are located
|
||||
#ZLIBLIB=/usr/local/lib
|
||||
#ZLIBINC=/usr/local/include
|
||||
ZLIBLIB=../zlib
|
||||
ZLIBINC=../zlib
|
||||
|
||||
|
||||
WARNMORE=-Wwrite-strings -Wpointer-arith -Wshadow -Wconversion \
|
||||
-Wmissing-declarations -Wtraditional -Wcast-align \
|
||||
-Wstrict-prototypes -Wmissing-prototypes
|
||||
CC=gcc
|
||||
CFLAGS=-I$(ZLIBINC) -O $(WARNMORE) -DPNG_DEBUG=4
|
||||
LDFLAGS=-L. -L$(ZLIBLIB) -lpng -lz -lm
|
||||
|
||||
RANLIB=ranlib
|
||||
#RANLIB=echo
|
||||
|
||||
# where make install puts libpng.a and png.h
|
||||
prefix=/usr/local
|
||||
|
||||
OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \
|
||||
pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \
|
||||
pngwtran.o pngmem.o pngerror.o pngpread.o
|
||||
|
||||
all: libpng.a pngtest
|
||||
|
||||
libpng.a: $(OBJS)
|
||||
ar rc $@ $(OBJS)
|
||||
$(RANLIB) $@
|
||||
|
||||
pngtest: pngtest.o libpng.a
|
||||
$(CC) -o pngtest $(CCFLAGS) pngtest.o $(LDFLAGS)
|
||||
|
||||
test: pngtest
|
||||
./pngtest
|
||||
|
||||
install: libpng.a
|
||||
-@mkdir $(prefix)/include
|
||||
-@mkdir $(prefix)/lib
|
||||
cp png.h $(prefix)/include
|
||||
cp pngconf.h $(prefix)/include
|
||||
chmod 644 $(prefix)/include/png.h
|
||||
chmod 644 $(prefix)/include/pngconf.h
|
||||
cp libpng.a $(prefix)/lib
|
||||
chmod 644 $(prefix)/lib/libpng.a
|
||||
|
||||
clean:
|
||||
rm -f *.o libpng.a pngtest pngout.png
|
||||
|
||||
# DO NOT DELETE THIS LINE -- make depend depends on it.
|
||||
|
||||
png.o: png.h pngconf.h
|
||||
pngerror.o: png.h pngconf.h
|
||||
pngrio.o: png.h pngconf.h
|
||||
pngwio.o: png.h pngconf.h
|
||||
pngmem.o: png.h pngconf.h
|
||||
pngset.o: png.h pngconf.h
|
||||
pngget.o: png.h pngconf.h
|
||||
pngread.o: png.h pngconf.h
|
||||
pngrtran.o: png.h pngconf.h
|
||||
pngrutil.o: png.h pngconf.h
|
||||
pngtest.o: png.h pngconf.h
|
||||
pngtrans.o: png.h pngconf.h
|
||||
pngwrite.o: png.h pngconf.h
|
||||
pngwtran.o: png.h pngconf.h
|
||||
pngwutil.o: png.h pngconf.h
|
||||
pngpread.o: png.h pngconf.h
|
||||
|
||||
18
makefile.tc
18
makefile.tc
@@ -13,17 +13,22 @@ LDFLAGS=$(MODEL)
|
||||
O=.obj
|
||||
|
||||
# variables
|
||||
OBJS1 = png$(O) pngrcb$(O) pngrutil$(O) pngtrans$(O) pngwutil$(O) pngmem$(O) pngpread$(O)
|
||||
OBJS2 = pngread$(O) pngerror$(O) pngwrite$(O) pngrtran$(O) pngwtran$(O) pngrio$(O) pngwio$(O)
|
||||
OBJSL1 = +png$(O) +pngrcb$(O) +pngrutil$(O) +pngtrans$(O) +pngwutil$(O) +pngmem$(O) +pngpread$(O)
|
||||
OBJSL2 = +pngread$(O) +pngerror$(O) +pngwrite$(O) +pngrtran$(O) +pngwtran$(O) +pngrio$(O) +pngwio$(O)
|
||||
OBJS1 = png$(O) pngset$(O) pngget$(O) pngrutil$(O) pngtrans$(O) pngwutil$(O)
|
||||
OBJS2 = pngmem$(O) pngpread$(O) pngread$(O) pngerror$(O) pngwrite$(O)
|
||||
OBJS3 = pngrtran$(O) pngwtran$(O) pngrio$(O) pngwio$(O)
|
||||
OBJSL1 = +png$(O) +pngset$(O) +pngget$(O) +pngrutil$(O) +pngtrans$(O)
|
||||
OBJSL2 = +pngwutil$(O) +pngmem$(O) +pngpread$(O) +pngread$(O) +pngerror$(O)
|
||||
OBJSL3 = +pngwrite$(O) +pngrtran$(O) +pngwtran$(O) +pngrio$(O) +pngwio$(O)
|
||||
|
||||
all: libpng.lib
|
||||
|
||||
png$(O): png.h pngconf.h
|
||||
$(CC) -c $(CFLAGS) $*.c
|
||||
|
||||
pngrcb$(O): png.h pngconf.h
|
||||
pngset$(O): png.h pngconf.h
|
||||
$(CC) -c $(CFLAGS) $*.c
|
||||
|
||||
pngget$(O): png.h pngconf.h
|
||||
$(CC) -c $(CFLAGS) $*.c
|
||||
|
||||
pngread$(O): png.h pngconf.h
|
||||
@@ -65,8 +70,9 @@ pngwtran$(O): png.h pngconf.h
|
||||
pngwutil$(O): png.h pngconf.h
|
||||
$(CC) -c $(CFLAGS) $*.c
|
||||
|
||||
libpng.lib: $(OBJS1) $(OBJS2)
|
||||
libpng.lib: $(OBJS1) $(OBJS2) $(OBJS3)
|
||||
$(LIB) libpng +$(OBJSL1)
|
||||
$(LIB) libpng +$(OBJSL2)
|
||||
$(LIB) libpng +$(OBJSL3)
|
||||
|
||||
# End of makefile for libpng
|
||||
|
||||
@@ -38,8 +38,10 @@ $ CALL MAKE png.OBJ "cc ''CCOPT' png" -
|
||||
png.c png.h pngconf.h
|
||||
$ CALL MAKE pngpread.OBJ "cc ''CCOPT' pngpread" -
|
||||
pngpread.c png.h pngconf.h
|
||||
$ CALL MAKE pngrcb.OBJ "cc ''CCOPT' pngrcb" -
|
||||
pngrcb.c png.h pngconf.h
|
||||
$ CALL MAKE pngset.OBJ "cc ''CCOPT' pngset" -
|
||||
pngset.c png.h pngconf.h
|
||||
$ CALL MAKE pngget.OBJ "cc ''CCOPT' pngget" -
|
||||
pngget.c png.h pngconf.h
|
||||
$ CALL MAKE pngread.OBJ "cc ''CCOPT' pngread" -
|
||||
pngread.c png.h pngconf.h
|
||||
$ CALL MAKE pngpread.OBJ "cc ''CCOPT' pngpread" -
|
||||
|
||||
327
png.c
327
png.c
@@ -1,41 +1,47 @@
|
||||
|
||||
/* png.c - location for general purpose png functions
|
||||
|
||||
libpng 1.0 beta 3 - version 0.89
|
||||
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
|
||||
*/
|
||||
/* png.c - location for general purpose libpng functions
|
||||
*
|
||||
* libpng 0.97
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* January 7, 1998
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
#define PNG_NO_EXTERN
|
||||
#include "png.h"
|
||||
|
||||
/* version information for c files. This better match the version
|
||||
string defined in png.h */
|
||||
char png_libpng_ver[] = "0.89";
|
||||
/* Version information for C files. This had better match the version
|
||||
* string defined in png.h.
|
||||
*/
|
||||
char png_libpng_ver[] = "0.97";
|
||||
|
||||
/* place to hold the signiture string for a png file. */
|
||||
/* Place to hold the signiture string for a PNG file. */
|
||||
png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
|
||||
|
||||
/* constant strings for known chunk types. If you need to add a chunk,
|
||||
add a string holding the name here. If you want to make the code
|
||||
portable to EBCDIC machines, use ASCII numbers, not characters. */
|
||||
png_byte FARDATA png_IHDR[4] = { 73, 72, 68, 82};
|
||||
png_byte FARDATA png_IDAT[4] = { 73, 68, 65, 84};
|
||||
png_byte FARDATA png_IEND[4] = { 73, 69, 78, 68};
|
||||
png_byte FARDATA png_PLTE[4] = { 80, 76, 84, 69};
|
||||
png_byte FARDATA png_gAMA[4] = {103, 65, 77, 65};
|
||||
png_byte FARDATA png_sBIT[4] = {115, 66, 73, 84};
|
||||
png_byte FARDATA png_cHRM[4] = { 99, 72, 82, 77};
|
||||
png_byte FARDATA png_tRNS[4] = {116, 82, 78, 83};
|
||||
png_byte FARDATA png_bKGD[4] = { 98, 75, 71, 68};
|
||||
png_byte FARDATA png_hIST[4] = {104, 73, 83, 84};
|
||||
png_byte FARDATA png_tEXt[4] = {116, 69, 88, 116};
|
||||
png_byte FARDATA png_zTXt[4] = {122, 84, 88, 116};
|
||||
png_byte FARDATA png_pHYs[4] = {112, 72, 89, 115};
|
||||
png_byte FARDATA png_oFFs[4] = {111, 70, 70, 115};
|
||||
png_byte FARDATA png_tIME[4] = {116, 73, 77, 69};
|
||||
/* Constant strings for known chunk types. If you need to add a chunk,
|
||||
* add a string holding the name here. If you want to make the code
|
||||
* portable to EBCDIC machines, use ASCII numbers, not characters.
|
||||
*/
|
||||
png_byte FARDATA png_IHDR[5] = { 73, 72, 68, 82, '\0'};
|
||||
png_byte FARDATA png_IDAT[5] = { 73, 68, 65, 84, '\0'};
|
||||
png_byte FARDATA png_IEND[5] = { 73, 69, 78, 68, '\0'};
|
||||
png_byte FARDATA png_PLTE[5] = { 80, 76, 84, 69, '\0'};
|
||||
png_byte FARDATA png_bKGD[5] = { 98, 75, 71, 68, '\0'};
|
||||
png_byte FARDATA png_cHRM[5] = { 99, 72, 82, 77, '\0'};
|
||||
png_byte FARDATA png_gAMA[5] = {103, 65, 77, 65, '\0'};
|
||||
png_byte FARDATA png_hIST[5] = {104, 73, 83, 84, '\0'};
|
||||
png_byte FARDATA png_oFFs[5] = {111, 70, 70, 115, '\0'};
|
||||
png_byte FARDATA png_pCAL[5] = {112, 67, 65, 76, '\0'};
|
||||
png_byte FARDATA png_pHYs[5] = {112, 72, 89, 115, '\0'};
|
||||
png_byte FARDATA png_sBIT[5] = {115, 66, 73, 84, '\0'};
|
||||
png_byte FARDATA png_sRGB[5] = {115, 82, 71, 66, '\0'};
|
||||
png_byte FARDATA png_tEXt[5] = {116, 69, 88, 116, '\0'};
|
||||
png_byte FARDATA png_tIME[5] = {116, 73, 77, 69, '\0'};
|
||||
png_byte FARDATA png_tRNS[5] = {116, 82, 78, 83, '\0'};
|
||||
png_byte FARDATA png_zTXt[5] = {122, 84, 88, 116, '\0'};
|
||||
|
||||
/* arrays to facilitate easy interlacing - use pass (0 - 6) as index */
|
||||
|
||||
@@ -51,34 +57,71 @@ int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
|
||||
/* offset to next interlace block in the y direction */
|
||||
int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
|
||||
|
||||
/* width of interlace block */
|
||||
/* this is not currently used - if you need it, uncomment it here and
|
||||
in png.h
|
||||
/* Width of interlace block. This is not currently used - if you need
|
||||
* it, uncomment it here and in png.h
|
||||
int FARDATA png_pass_width[] = {8, 4, 4, 2, 2, 1, 1};
|
||||
*/
|
||||
|
||||
/* height of interlace block */
|
||||
/* this is not currently used - if you need it, uncomment it here and
|
||||
in png.h
|
||||
/* Height of interlace block. This is not currently used - if you need
|
||||
* it, uncomment it here and in png.h
|
||||
int FARDATA png_pass_height[] = {8, 8, 4, 4, 2, 2, 1};
|
||||
*/
|
||||
|
||||
/* mask to determine which pixels are valid in a pass */
|
||||
/* Mask to determine which pixels are valid in a pass */
|
||||
int FARDATA png_pass_mask[] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
|
||||
|
||||
/* mask to determine which pixels to overwrite while displaying */
|
||||
/* Mask to determine which pixels to overwrite while displaying */
|
||||
int FARDATA png_pass_dsp_mask[] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
|
||||
|
||||
|
||||
/* 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)
|
||||
{
|
||||
png_debug(1, "in png_set_sig_bytes\n");
|
||||
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_sig_cmp(png_bytep sig, png_size_t start, png_size_t num_to_check)
|
||||
{
|
||||
if (num_to_check > 8)
|
||||
num_to_check = 8;
|
||||
else if (num_to_check < 1)
|
||||
return 0;
|
||||
|
||||
if (start > 7)
|
||||
return 0;
|
||||
|
||||
if (start + num_to_check > 8)
|
||||
num_to_check = 8 - start;
|
||||
|
||||
return (png_memcmp(&sig[start], &png_sig[start], 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)
|
||||
{
|
||||
if (num > 8)
|
||||
num = 8;
|
||||
if (num < 1)
|
||||
return 0;
|
||||
|
||||
return (!png_memcmp(sig, png_sig, num));
|
||||
return !png_sig_cmp(sig, (png_size_t)0, (png_size_t)num);
|
||||
}
|
||||
|
||||
/* Function to allocate memory for zlib. */
|
||||
@@ -88,10 +131,9 @@ 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,
|
||||
(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)
|
||||
num_bytes = (png_uint_32)items * size;
|
||||
ptr = png_malloc((png_structp)png_ptr, num_bytes);
|
||||
if (num_bytes > (png_uint_32)0x8000)
|
||||
{
|
||||
png_memset(ptr, 0, (png_size_t)0x8000L);
|
||||
png_memset((png_bytep)ptr + (png_size_t)0x8000L, 0,
|
||||
@@ -108,121 +150,154 @@ 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 */
|
||||
png_ptr->crc = 0xffffffffL;
|
||||
png_ptr->crc = crc32(0, Z_NULL, 0);
|
||||
}
|
||||
|
||||
/* 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().
|
||||
You may then want to hook it into png_struct and free it with the
|
||||
destroy functions. */
|
||||
static png_uint_32 crc_table[256];
|
||||
|
||||
/* Flag: has the table been computed? Initially false. */
|
||||
static int crc_table_computed = 0;
|
||||
|
||||
/* make the table for a fast crc */
|
||||
static void
|
||||
make_crc_table(void)
|
||||
{
|
||||
png_uint_32 c;
|
||||
int n, k;
|
||||
|
||||
for (n = 0; n < 256; n++)
|
||||
{
|
||||
c = (png_uint_32)n;
|
||||
for (k = 0; k < 8; k++)
|
||||
c = c & 1 ? 0xedb88320L ^ (c >> 1) : c >> 1;
|
||||
crc_table[n] = c;
|
||||
}
|
||||
crc_table_computed = 1;
|
||||
}
|
||||
|
||||
/* update a running crc with the bytes buf[0..len-1]--the crc should be
|
||||
initialized to all 1's, and the transmitted value is the 1's complement
|
||||
of the final running crc. */
|
||||
static png_uint_32
|
||||
update_crc(png_uint_32 crc, png_bytep buf, png_uint_32 len)
|
||||
{
|
||||
png_uint_32 c;
|
||||
png_bytep p;
|
||||
png_uint_32 n;
|
||||
|
||||
c = crc;
|
||||
p = buf;
|
||||
n = len;
|
||||
|
||||
if (!crc_table_computed)
|
||||
{
|
||||
make_crc_table();
|
||||
}
|
||||
|
||||
if (n > 0) do
|
||||
{
|
||||
c = crc_table[(png_byte)((c ^ (*p++)) & 0xff)] ^ (c >> 8);
|
||||
} while (--n);
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
/* 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. */
|
||||
/* Calculate the CRC over a section of data. We can only pass as
|
||||
* much data to this routine as the largest single buffer size. We
|
||||
* also check that this data will actually be used before going to the
|
||||
* trouble of calculating it.
|
||||
*/
|
||||
void
|
||||
png_calculate_crc(png_structp png_ptr, png_bytep ptr,
|
||||
png_uint_32 length)
|
||||
png_calculate_crc(png_structp png_ptr, png_bytep ptr, png_size_t length)
|
||||
{
|
||||
png_ptr->crc = update_crc(png_ptr->crc, ptr, length);
|
||||
int need_crc = 1;
|
||||
|
||||
if (png_ptr->chunk_name[0] & 0x20) /* ancillary */
|
||||
{
|
||||
if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
|
||||
(PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
|
||||
need_crc = 0;
|
||||
}
|
||||
else /* critical */
|
||||
{
|
||||
if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
|
||||
need_crc = 0;
|
||||
}
|
||||
|
||||
if (need_crc)
|
||||
png_ptr->crc = crc32(png_ptr->crc, ptr, length);
|
||||
}
|
||||
|
||||
/* 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)
|
||||
{
|
||||
png_infop info_ptr;
|
||||
|
||||
png_debug(1, "in png_create_info_struct\n");
|
||||
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;
|
||||
|
||||
png_debug(1, "in png_destroy_info_struct\n");
|
||||
if (info_ptr_ptr != NULL)
|
||||
info_ptr = *info_ptr_ptr;
|
||||
|
||||
if (info_ptr != NULL)
|
||||
{
|
||||
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)
|
||||
{
|
||||
png_debug(1, "in png_info_init\n");
|
||||
/* 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. Recall
|
||||
* that png_free() checks for NULL pointers for us.
|
||||
*/
|
||||
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;
|
||||
|
||||
png_debug(1, "in png_info_destroy\n");
|
||||
if (info_ptr->text != NULL)
|
||||
{
|
||||
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
|
||||
#if defined(PNG_READ_pCAL_SUPPORTED)
|
||||
png_free(png_ptr, info_ptr->pcal_purpose);
|
||||
png_free(png_ptr, info_ptr->pcal_units);
|
||||
if (info_ptr->pcal_params != NULL)
|
||||
{
|
||||
for (i = 0; i < info_ptr->pcal_nparams; i++)
|
||||
{
|
||||
png_free(png_ptr, info_ptr->pcal_params[i]);
|
||||
}
|
||||
png_free(png_ptr, info_ptr->pcal_params);
|
||||
}
|
||||
#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. */
|
||||
* functions. The application should free any memory associated with this
|
||||
* pointer before png_write_destroy() or png_read_destroy() are called.
|
||||
*/
|
||||
png_voidp
|
||||
png_get_io_ptr(png_structp png_ptr)
|
||||
{
|
||||
return png_ptr->io_ptr;
|
||||
}
|
||||
|
||||
/* Initialize the default input/output functions for the png file. If you
|
||||
change the read, or write routines, you can call either png_set_read_fn()
|
||||
or png_set_write_fn() instead of png_init_io(). */
|
||||
|
||||
#if !defined(PNG_NO_STDIO)
|
||||
/* Initialize the default input/output functions for the PNG file. If you
|
||||
* use your own read or write routines, you can call either png_set_read_fn()
|
||||
* or png_set_write_fn() instead of png_init_io().
|
||||
*/
|
||||
void
|
||||
png_init_io(png_structp png_ptr, FILE *fp)
|
||||
{
|
||||
png_debug(1, "in png_init_io\n");
|
||||
png_ptr->io_ptr = (png_voidp)fp;
|
||||
}
|
||||
#endif
|
||||
|
||||
103
pngchang.txt
103
pngchang.txt
@@ -1,103 +0,0 @@
|
||||
pngchange.txt - changes for libpng
|
||||
|
||||
version 0.2
|
||||
added reader into png.h
|
||||
fixed small problems in stub file
|
||||
version 0.3
|
||||
added pull reader
|
||||
split up pngwrite.c to several files
|
||||
added pnglib.txt
|
||||
added example.c
|
||||
cleaned up writer, adding a few new tranformations
|
||||
fixed some bugs in writer
|
||||
interfaced with zlib 0.5
|
||||
added K&R support
|
||||
added check for 64 KB blocks for 16 bit machines
|
||||
version 0.4
|
||||
cleaned up code and commented code
|
||||
simplified time handling into png_time
|
||||
created png_color_16 and png_color_8 to handle color needs
|
||||
cleaned up color type defines
|
||||
fixed various bugs
|
||||
made various names more consistant
|
||||
interfaced with zlib 0.71
|
||||
cleaned up zTXt reader and writer (using zlib's Reset functions)
|
||||
split transformations into pngrtran.c and pngwtran.c
|
||||
version 0.5
|
||||
interfaced with zlib 0.8
|
||||
fixed many reading and writing bugs
|
||||
saved using 3 spaces instead of tabs
|
||||
version 0.6
|
||||
added png_large_malloc() and png_large_free()
|
||||
added png_size_t
|
||||
cleaned up some compiler warnings
|
||||
added png_start_read_image()
|
||||
version 0.7
|
||||
cleaned up lots of bugs
|
||||
finished dithering and other stuff
|
||||
added test program
|
||||
changed name from pnglib to libpng
|
||||
version 0.71
|
||||
changed pngtest.png for zlib 0.93
|
||||
fixed error in libpng.txt and example.c
|
||||
version 0.8
|
||||
cleaned up some bugs
|
||||
added png_set_filler()
|
||||
split up pngstub.c into pngmem.c, pngio.c, and pngerror.c
|
||||
added #define's to remove unwanted code
|
||||
moved png_info_init() to png.c
|
||||
added old_size into png_realloc()
|
||||
added functions to manually set filtering and compression info
|
||||
changed compression parameters based on image type
|
||||
optimized filter selection code
|
||||
added version info
|
||||
changed external functions passing floats to doubles (k&r problems?)
|
||||
put all the configurable stuff in pngconf.h
|
||||
enabled png_set_shift to work with paletted images on read
|
||||
added png_read_update_info() - updates info structure with
|
||||
transformations
|
||||
version 0.81
|
||||
incorporated Tim Wegner's medium model code (thanks, Tim)
|
||||
version 0.85
|
||||
added more medium model code (almost everythings a far)
|
||||
added i/o, error, and memory callback functions
|
||||
fixed some bugs (16 bit, 4 bit interlaced, etc.)
|
||||
added first run progressive reader (barely tested)
|
||||
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
|
||||
version 0.88
|
||||
fixed progressive bugs
|
||||
replaced tabs with spaces
|
||||
cleaned up documentation
|
||||
added callbacks for read/write and warning/error functions
|
||||
version 0.89
|
||||
added new initialization API to make libpng work better with shared libs
|
||||
we now have png_create_read_struct(), png_create_write_struct(),
|
||||
png_create_info_struct(), png_destroy_read_struct(), and
|
||||
png_destroy_write_struct() instead of the separate calls to
|
||||
malloc and png_read_init(), png_info_init(), and png_write_init()
|
||||
changed warning/error callback functions to fix bug - this means you
|
||||
should use the new initialization API if you were using the old
|
||||
png_set_message_fn() calls, and that the old API no longer exists
|
||||
so that people are aware that they need to change their code
|
||||
changed filter selection API to allow selection of multiple filters
|
||||
since it didn't work in previous versions of libpng anyways
|
||||
optimized filter selection code
|
||||
fixed png_set_background() to allow using an arbitrary RGB color for
|
||||
paletted images
|
||||
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)
|
||||
fixed bug with Borland 64K memory allocation (Alexander Lehmann)
|
||||
fixed bug in interlace handling (Smaraderagd, 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
|
||||
470
pngconf.h
470
pngconf.h
@@ -1,69 +1,76 @@
|
||||
|
||||
/* pngconf.c - machine configurable file for libpng
|
||||
|
||||
libpng 1.0 beta 3 - version 0.89
|
||||
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
|
||||
*/
|
||||
*
|
||||
* libpng 0.97
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* January 7, 1998
|
||||
*/
|
||||
|
||||
/* Any machine specific code is near the front of this file, so if you
|
||||
are configuring libpng for a machine, you may want to read the section
|
||||
starting here down to where it starts to typedef png_color, png_text,
|
||||
and png_info */
|
||||
* are configuring libpng for a machine, you may want to read the section
|
||||
* starting here down to where it starts to typedef png_color, png_text,
|
||||
* and png_info.
|
||||
*/
|
||||
|
||||
#ifndef PNGCONF_H
|
||||
#define PNGCONF_H
|
||||
|
||||
/* this is the size of the compression buffer, and thus the size of
|
||||
an IDAT chunk. Make this whatever size you feel is best for your
|
||||
machine. One of these will be allocated per png_struct. When this
|
||||
is full, it writes the data to the disk, and does some other
|
||||
calculations. Making this an extreamly small size will slow
|
||||
the library down, but you may want to experiment to determine
|
||||
where it becomes significant, if you are concerned with memory
|
||||
usage. Note that zlib allocates at least 32Kb also. For readers,
|
||||
this describes the size of the buffer available to read the data in.
|
||||
Unless this gets smaller then the size of a row (compressed),
|
||||
it should not make much difference how big this is. */
|
||||
/* This is the size of the compression buffer, and thus the size of
|
||||
* an IDAT chunk. Make this whatever size you feel is best for your
|
||||
* machine. One of these will be allocated per png_struct. When this
|
||||
* is full, it writes the data to the disk, and does some other
|
||||
* calculations. Making this an extremely small size will slow
|
||||
* the library down, but you may want to experiment to determine
|
||||
* where it becomes significant, if you are concerned with memory
|
||||
* usage. Note that zlib allocates at least 32Kb also. For readers,
|
||||
* this describes the size of the buffer available to read the data in.
|
||||
* Unless this gets smaller then the size of a row (compressed),
|
||||
* it should not make much difference how big this is.
|
||||
*/
|
||||
|
||||
#ifndef PNG_ZBUF_SIZE
|
||||
#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
|
||||
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
|
||||
makes sure to check any memory allocation to verify it will fit
|
||||
into memory.
|
||||
#define PNG_MAX_ALLOC_64K
|
||||
*/
|
||||
#ifdef MAXSEG_64K
|
||||
#define PNG_MAX_ALLOC_64K
|
||||
#endif
|
||||
|
||||
/* this protects us against compilers which run on a windowing system
|
||||
and thus don't have or would rather us not use the stdio types:
|
||||
stdin, stdout, and stderr. The only one currently used is stderr
|
||||
in png_error() and png_warning(). #defining PNG_NO_STDIO will
|
||||
prevent these from being compiled and used. */
|
||||
/* If you are running on a machine where you cannot allocate more
|
||||
* than 64K of memory at once, uncomment this. While libpng will not
|
||||
* normally need that much memory in a chunk (unless you load up a very
|
||||
* large file), zlib needs to know how big of a chunk it can use, and
|
||||
* libpng thus makes sure to check any memory allocation to verify it
|
||||
* will fit into memory.
|
||||
#define PNG_MAX_MALLOC_64K
|
||||
*/
|
||||
#if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K)
|
||||
#define PNG_MAX_MALLOC_64K
|
||||
#endif
|
||||
|
||||
/* #define PNG_NO_STDIO */
|
||||
/* This protects us against compilers which run on a windowing system
|
||||
* and thus don't have or would rather us not use the stdio types:
|
||||
* stdin, stdout, and stderr. The only one currently used is stderr
|
||||
* in png_error() and png_warning(). #defining PNG_NO_STDIO will
|
||||
* prevent these from being compiled and used.
|
||||
* #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. */
|
||||
/* We still need stdio.h for FILE even when PNG_NO_STDIO is defined.
|
||||
*/
|
||||
#ifndef PNG_NO_STDIO
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
/* This macro protects us against machines that don't have function
|
||||
* prototypes (ie K&R style headers). If your compiler does not handle
|
||||
* function prototypes, define this macro and use the included ansi2knr.
|
||||
* I've always been able to use _NO_PROTO as the indicator, but you may
|
||||
* need to drag the empty declaration out in front of here, or change the
|
||||
* ifdef to suit your own needs.
|
||||
*/
|
||||
#ifndef PNGARG
|
||||
|
||||
#ifdef OF
|
||||
#ifdef OF /* zlib prototype munger */
|
||||
#define PNGARG(arglist) OF(arglist)
|
||||
#else
|
||||
|
||||
@@ -77,39 +84,83 @@
|
||||
|
||||
#endif /* PNGARG */
|
||||
|
||||
/* Try to determine if we are compiling on a Mac. Note that testing for
|
||||
* just __MWERKS__ is not good enough, because the Codewarrior is now used
|
||||
* on non-Mac platforms.
|
||||
*/
|
||||
#if (defined(__MWERKS__) && defined(macintosh)) || defined(applec) || \
|
||||
defined(THINK_C) || defined(__SC__)
|
||||
#define MACOS
|
||||
#endif
|
||||
|
||||
/* 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. If
|
||||
* the X config stuff didn't define _BSD_SOURCE we wouldn't need this.
|
||||
*/
|
||||
#ifdef __linux__
|
||||
#ifdef _BSD_SOURCE
|
||||
#define _PNG_SAVE_BSD_SOURCE
|
||||
#undef _BSD_SOURCE
|
||||
#endif
|
||||
#ifdef _SETJMP_H
|
||||
__png.h__ already includes setjmp.h
|
||||
__dont__ include it again
|
||||
#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
|
||||
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. */
|
||||
/* Other defines for things like memory and the like can go here. */
|
||||
#ifdef PNG_INTERNAL
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
|
||||
/* The functions exported by PNG_EXTERN are PNG_INTERNAL functions, which
|
||||
* aren't usually used outside the library (as far as I know), so it is
|
||||
* debatable if they should be exported at all. In the future, when it is
|
||||
* possible to have run-time registry of chunk-handling functions, some of
|
||||
* these will be made available again.
|
||||
#define PNG_EXTERN extern
|
||||
*/
|
||||
#define PNG_EXTERN
|
||||
|
||||
/* Other defines specific to compilers can go here. Try to keep
|
||||
* them inside an appropriate ifdef/endif pair for portability.
|
||||
*/
|
||||
|
||||
#if defined(MACOS)
|
||||
/* We need to check that <math.h> hasn't already been included earlier
|
||||
* as it seems it doesn't agree with <fp.h>, yet we should really use
|
||||
* <fp.h> if possible.
|
||||
*/
|
||||
#if !defined(__MATH_H__) && !defined(__MATH_H) && !defined(__cmath__)
|
||||
#include <fp.h>
|
||||
#endif
|
||||
#else
|
||||
#include <math.h>
|
||||
#endif
|
||||
|
||||
/* 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
|
||||
stdlib.h like it should (I think). Or perhaps this is a C++
|
||||
feature */
|
||||
/* 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"?
|
||||
*/
|
||||
#ifdef __TURBOC__
|
||||
#include <mem.h>
|
||||
#include "alloc.h"
|
||||
@@ -119,30 +170,43 @@
|
||||
#include <malloc.h>
|
||||
#endif
|
||||
|
||||
/* this controls how fine the dithering gets. As this allocates
|
||||
a largish chunk of memory (32K), those who are not as concerned
|
||||
with dithering quality can decrease some or all of these */
|
||||
/* 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.
|
||||
*/
|
||||
#ifndef PNG_DITHER_RED_BITS
|
||||
#define PNG_DITHER_RED_BITS 5
|
||||
#endif
|
||||
#ifndef PNG_DITHER_GREEN_BITS
|
||||
#define PNG_DITHER_GREEN_BITS 5
|
||||
#endif
|
||||
#ifndef PNG_DITHER_BLUE_BITS
|
||||
#define PNG_DITHER_BLUE_BITS 5
|
||||
#endif
|
||||
|
||||
/* 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
|
||||
value less then 8, and even that may not work (I haven't tested
|
||||
it). */
|
||||
/* This controls how fine the gamma correction becomes when you
|
||||
* are only interested in 8 bits anyway. Increasing this value
|
||||
* results in more memory being used, and more pow() functions
|
||||
* being called to fill in the gamma tables. Don't set this value
|
||||
* less then 8, and even that may not work (I haven't tested it).
|
||||
*/
|
||||
|
||||
#define PNG_MAX_GAMMA_8 11
|
||||
|
||||
/* This controls how much a difference in gamma we can tolerate before
|
||||
* we actually start doing gamma conversion.
|
||||
*/
|
||||
#define PNG_GAMMA_THRESHOLD 0.05
|
||||
|
||||
#endif /* PNG_INTERNAL */
|
||||
|
||||
/* the following uses const char * instead of char * for error
|
||||
and warning message functions, so some compilers won't complain.
|
||||
If you want to use const, define PNG_USE_CONST here. It is not
|
||||
normally defined to make configuration easier, as it is not a
|
||||
critical part of the code.
|
||||
*/
|
||||
/* 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
|
||||
@@ -150,28 +214,43 @@
|
||||
# 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 */
|
||||
|
||||
/* GR-P, 0.96a: Set "*FULLY_SUPPORTED as default but allow user
|
||||
to turn it off with "*NOT_FULLY_SUPPORTED" on the compile line,
|
||||
then pick and choose which ones to define without having to edit
|
||||
this file */
|
||||
|
||||
#ifndef PNG_READ_NOT_FULLY_SUPPORTED
|
||||
#define PNG_READ_FULLY_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_WRITE_NOT_FULLY_SUPPORTED
|
||||
#define PNG_WRITE_FULLY_SUPPORTED
|
||||
#endif
|
||||
|
||||
#ifdef PNG_READ_FULLY_SUPPORTED
|
||||
#define PNG_PROGRESSIVE_READ_SUPPORTED
|
||||
#define PNG_READ_INTERLACING_SUPPORTED
|
||||
#define PNG_READ_OPT_PLTE_SUPPORTED
|
||||
#define PNG_READ_EXPAND_SUPPORTED
|
||||
#define PNG_READ_SHIFT_SUPPORTED
|
||||
#define PNG_READ_PACK_SUPPORTED
|
||||
#define PNG_READ_BGR_SUPPORTED
|
||||
#define PNG_READ_SWAP_SUPPORTED
|
||||
#define PNG_READ_PACKSWAP_SUPPORTED
|
||||
#define PNG_READ_INVERT_SUPPORTED
|
||||
#define PNG_READ_DITHER_SUPPORTED
|
||||
#define PNG_READ_BACKGROUND_SUPPORTED
|
||||
@@ -179,52 +258,92 @@
|
||||
#define PNG_READ_FILLER_SUPPORTED
|
||||
#define PNG_READ_GAMMA_SUPPORTED
|
||||
#define PNG_READ_GRAY_TO_RGB_SUPPORTED
|
||||
#undef PNG_CORRECT_PALETTE_SUPPORTED
|
||||
#define PNG_READ_SWAP_ALPHA_SUPPORTED
|
||||
#define PNG_READ_STRIP_ALPHA_SUPPORTED
|
||||
#define PNG_READ_COMPOSITE_NODIV_SUPPORTED /* well tested on Intel */
|
||||
#endif /* PNG_READ_FULLY_SUPPORTED */
|
||||
#define PNG_READ_INTERLACING_SUPPORTED
|
||||
|
||||
#ifdef PNG_WRITE_FULLY_SUPPORTED
|
||||
#define PNG_WRITE_INTERLACING_SUPPORTED
|
||||
#define PNG_WRITE_SHIFT_SUPPORTED
|
||||
#define PNG_WRITE_PACK_SUPPORTED
|
||||
#define PNG_WRITE_BGR_SUPPORTED
|
||||
#define PNG_WRITE_SWAP_SUPPORTED
|
||||
#define PNG_WRITE_PACKSWAP_SUPPORTED
|
||||
#define PNG_WRITE_INVERT_SUPPORTED
|
||||
#define PNG_WRITE_FILLER_SUPPORTED
|
||||
#define PNG_WRITE_FILLER_SUPPORTED /* This is the same as WRITE_STRIP_ALPHA */
|
||||
#define PNG_WRITE_FLUSH_SUPPORTED
|
||||
#define PNG_WRITE_SWAP_ALPHA_SUPPORTED
|
||||
#define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
|
||||
#endif /* PNG_WRITE_FULLY_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
|
||||
smaller. OPT_PLTE only disables the optional palette in RGB
|
||||
and RGB Alpha images. */
|
||||
#if !defined(PNG_NO_STDIO)
|
||||
#define PNG_TIME_RFC1152_SUPPORTED
|
||||
#endif
|
||||
|
||||
#define PNG_READ_gAMA_SUPPORTED
|
||||
#define PNG_READ_sBIT_SUPPORTED
|
||||
#define PNG_READ_cHRM_SUPPORTED
|
||||
#define PNG_READ_tRNS_SUPPORTED
|
||||
/* These are currently experimental features */
|
||||
#undef PNG_READ_16_TO_8_ACCURATE_SHIFT_SUPPORTED /* very little testing */
|
||||
|
||||
/* This is only for PowerPC big-endian and 680x0 systems */
|
||||
#undef PNG_READ_BIG_ENDIAN_SUPPORTED /* some testing */
|
||||
|
||||
/* These functions are turned off by default, as they will be phased out. */
|
||||
#undef PNG_USELESS_TESTS_SUPPORTED
|
||||
#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, pCAL). Others will just save time and make png_info
|
||||
* a bit smaller. OPT_PLTE only disables the optional palette in RGB
|
||||
* and RGBA images.
|
||||
*/
|
||||
|
||||
#ifdef PNG_READ_FULLY_SUPPORTED
|
||||
#define PNG_READ_bKGD_SUPPORTED
|
||||
#define PNG_READ_cHRM_SUPPORTED
|
||||
#define PNG_READ_gAMA_SUPPORTED
|
||||
#define PNG_READ_hIST_SUPPORTED
|
||||
#define PNG_READ_pHYs_SUPPORTED
|
||||
#define PNG_READ_oFFs_SUPPORTED
|
||||
#define PNG_READ_tIME_SUPPORTED
|
||||
#define PNG_READ_pCAL_SUPPORTED
|
||||
#define PNG_READ_pHYs_SUPPORTED
|
||||
#define PNG_READ_sBIT_SUPPORTED
|
||||
#define PNG_READ_sRGB_SUPPORTED
|
||||
#define PNG_READ_tEXt_SUPPORTED
|
||||
#define PNG_READ_tIME_SUPPORTED
|
||||
#define PNG_READ_tRNS_SUPPORTED
|
||||
#define PNG_READ_zTXt_SUPPORTED
|
||||
#define PNG_READ_OPT_PLTE_SUPPORTED
|
||||
#endif /* PNG_READ_FULLY_SUPPORTED */
|
||||
|
||||
#define PNG_WRITE_gAMA_SUPPORTED
|
||||
#define PNG_WRITE_sBIT_SUPPORTED
|
||||
#define PNG_WRITE_cHRM_SUPPORTED
|
||||
#define PNG_WRITE_tRNS_SUPPORTED
|
||||
#ifdef PNG_WRITE_FULLY_SUPPORTED
|
||||
#define PNG_WRITE_bKGD_SUPPORTED
|
||||
#define PNG_WRITE_cHRM_SUPPORTED
|
||||
#define PNG_WRITE_gAMA_SUPPORTED
|
||||
#define PNG_WRITE_hIST_SUPPORTED
|
||||
#define PNG_WRITE_pHYs_SUPPORTED
|
||||
#define PNG_WRITE_oFFs_SUPPORTED
|
||||
#define PNG_WRITE_tIME_SUPPORTED
|
||||
#define PNG_WRITE_pCAL_SUPPORTED
|
||||
#define PNG_WRITE_pHYs_SUPPORTED
|
||||
#define PNG_WRITE_sBIT_SUPPORTED
|
||||
#define PNG_WRITE_sRGB_SUPPORTED
|
||||
#define PNG_WRITE_tEXt_SUPPORTED
|
||||
#define PNG_WRITE_tIME_SUPPORTED
|
||||
#define PNG_WRITE_tRNS_SUPPORTED
|
||||
#define PNG_WRITE_zTXt_SUPPORTED
|
||||
#endif /* PNG_WRITE_FULLY_SUPPORTED */
|
||||
|
||||
/* 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. */
|
||||
/* need the time information for reading tIME chunks */
|
||||
#if defined(PNG_READ_tIME_SUPPORTED) || defined(PNG_WRITE_tIME_SUPPORTED)
|
||||
#include <time.h>
|
||||
#endif
|
||||
|
||||
/* 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 compilers dislike passing
|
||||
* unsigned shorts as function parameters, so you may be better off using
|
||||
* unsigned int for png_uint_16. Likewise, for 64-bit systems, you may
|
||||
* want to have unsigned int for png_uint_32 instead of unsigned long.
|
||||
*/
|
||||
|
||||
typedef unsigned long png_uint_32;
|
||||
typedef long png_int_32;
|
||||
@@ -232,21 +351,21 @@ 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;
|
||||
|
||||
/* The following is needed for medium model support. It cannot be in the
|
||||
PNG_INTERNAL section. Needs modification for other compilers besides
|
||||
MSC. Model independent support declares all arrays that might be very
|
||||
large using the far keyword. The Zlib version used must also support
|
||||
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 */
|
||||
/* The following is needed for medium model support. It cannot be in the
|
||||
* PNG_INTERNAL section. Needs modification for other compilers besides
|
||||
* MSC. Model independent support declares all arrays and pointers to be
|
||||
* large using the far keyword. The zlib version used must also support
|
||||
* model independent data. As of version zlib 1.0.4, the necessary changes
|
||||
* have been made in zlib. The USE_FAR_KEYWORD define triggers other
|
||||
* changes that are needed. (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,26 +382,27 @@ 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__ */
|
||||
|
||||
#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
|
||||
|
||||
@@ -291,23 +411,13 @@ typedef size_t png_size_t;
|
||||
# define FAR
|
||||
#endif
|
||||
|
||||
/* SJT: At this point FAR is always defined */
|
||||
|
||||
/* not used anymore, but kept for compatability */
|
||||
typedef unsigned char FAR png_bytef;
|
||||
|
||||
/* SJT: */
|
||||
/* At this point FAR is always defined */
|
||||
#ifndef FARDATA
|
||||
#define FARDATA
|
||||
#endif
|
||||
|
||||
/* End medium model changes to be in zconf.h */
|
||||
|
||||
/* SJT: More typedefs */
|
||||
typedef void FAR * png_voidp;
|
||||
|
||||
|
||||
/* SJT: Add typedefs for pointers */
|
||||
/* 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;
|
||||
@@ -315,8 +425,9 @@ typedef png_uint_16 FAR * png_uint_16p;
|
||||
typedef png_int_16 FAR * png_int_16p;
|
||||
typedef PNG_CONST char FAR * png_const_charp;
|
||||
typedef char FAR * png_charp;
|
||||
typedef double FAR * png_doublep;
|
||||
|
||||
/* SJT: Pointers to pointers; i.e. arrays */
|
||||
/* Pointers to pointers; i.e. arrays */
|
||||
typedef png_byte FAR * FAR * png_bytepp;
|
||||
typedef png_uint_32 FAR * FAR * png_uint_32pp;
|
||||
typedef png_int_32 FAR * FAR * png_int_32pp;
|
||||
@@ -324,37 +435,70 @@ typedef png_uint_16 FAR * FAR * png_uint_16pp;
|
||||
typedef png_int_16 FAR * FAR * png_int_16pp;
|
||||
typedef PNG_CONST char FAR * FAR * png_const_charpp;
|
||||
typedef char FAR * FAR * png_charpp;
|
||||
typedef double FAR * FAR * png_doublepp;
|
||||
|
||||
/* Pointers to pointers to pointers; i.e. pointer to array */
|
||||
typedef char FAR * FAR * FAR * png_charppp;
|
||||
|
||||
/* SJT: libpng typedefs for types in zlib. If Zlib changes
|
||||
or another compression library is used, then change these.
|
||||
Eliminates need to change all the source files.
|
||||
*/
|
||||
/* libpng typedefs for types in zlib. If zlib changes
|
||||
* or another compression library is used, then change these.
|
||||
* Eliminates need to change all the source files.
|
||||
*/
|
||||
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;
|
||||
|
||||
/* allow for compilation as dll under MS Windows */
|
||||
#ifdef __WIN32DLL__
|
||||
#define PNG_EXPORT(type,symbol) __declspec(dllexport) type symbol
|
||||
#endif
|
||||
|
||||
/* allow for compilation as dll with BORLAND C++ 5.0 */
|
||||
#if defined(__BORLANDC__) && defined(_Windows) && defined(__DLL__)
|
||||
# define PNG_EXPORT(t,s) t _export s
|
||||
#endif
|
||||
|
||||
/* allow for compilation as shared lib under BeOS */
|
||||
#ifdef __BEOSDLL__
|
||||
#define PNG_EXPORT(type,symbol) __declspec(export) type symbol
|
||||
#endif
|
||||
|
||||
#ifndef PNG_EXPORT
|
||||
#define PNG_EXPORT(t,s) t s
|
||||
#endif
|
||||
|
||||
|
||||
/* User may want to use these so not in PNG_INTERNAL. Any library functions
|
||||
that are passed far data must be model independent. */
|
||||
* that are passed far data must be model independent.
|
||||
*/
|
||||
|
||||
#if defined(USE_FAR_KEYWORD) /* memory model independent fns */
|
||||
# define png_strcpy _fstrcpy
|
||||
# define png_strcat _fstrcat
|
||||
/* 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_strlen _fstrlen
|
||||
# define png_strcmp _fstrcmp
|
||||
# define png_memcmp _fmemcmp /* SJT: added */
|
||||
# define png_memcpy _fmemcpy
|
||||
# define png_memset _fmemset
|
||||
#else /* use the usual functions */
|
||||
# define png_strcpy strcpy
|
||||
# define png_strcat strcat
|
||||
# define CVT_PTR(ptr) (ptr)
|
||||
# define CVT_PTR_NOCHECK(ptr) (ptr)
|
||||
# define png_strlen strlen
|
||||
# define png_strcmp strcmp
|
||||
# define png_memcmp memcmp /* SJT: added */
|
||||
# define png_memcpy memcpy
|
||||
# define png_memset memset
|
||||
#endif
|
||||
/* End of memory model independent support */
|
||||
|
||||
/* Just a double check that someone hasn't tried to define something
|
||||
* contradictory.
|
||||
*/
|
||||
#if (PNG_ZBUF_SIZE > 65536) && defined(PNG_MAX_MALLOC_64K)
|
||||
#undef PNG_ZBUF_SIZE
|
||||
#define PNG_ZBUF_SIZE 65536
|
||||
#endif
|
||||
|
||||
#endif /* PNGCONF_H */
|
||||
|
||||
|
||||
123
pngerror.c
123
pngerror.c
@@ -1,15 +1,18 @@
|
||||
|
||||
/* pngerror.c - stub functions for i/o and memory allocation
|
||||
|
||||
libpng 1.0 beta 3 - version 0.89
|
||||
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
|
||||
|
||||
This file provides a location for all error handling. Users which
|
||||
need special error handling are expected to write replacement functions
|
||||
and use png_set_error_fn() to use those functions. See the instructions
|
||||
at each function. */
|
||||
*
|
||||
* libpng 0.97
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* January 7, 1998
|
||||
*
|
||||
* This file provides a location for all error handling. Users which
|
||||
* need special error handling are expected to write replacement functions
|
||||
* and use png_set_error_fn() to use those functions. See the instructions
|
||||
* at each function.
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
#include "png.h"
|
||||
@@ -20,13 +23,14 @@ static void png_default_warning PNGARG((png_structp png_ptr,
|
||||
png_const_charp message));
|
||||
|
||||
/* This function is called whenever there is a fatal error. This function
|
||||
should not be changed. If there is a need to handle errors differently,
|
||||
you should supply a replacement error function and use png_set_error_fn()
|
||||
to replace the error function at run-time. */
|
||||
* should not be changed. If there is a need to handle errors differently,
|
||||
* you should supply a replacement error function and use png_set_error_fn()
|
||||
* to replace the error function at run-time.
|
||||
*/
|
||||
void
|
||||
png_error(png_structp png_ptr, png_const_charp message)
|
||||
{
|
||||
if (png_ptr->error_fn)
|
||||
if (png_ptr->error_fn != NULL)
|
||||
(*(png_ptr->error_fn))(png_ptr, message);
|
||||
|
||||
/* if the following returns or doesn't exist, use the default function,
|
||||
@@ -35,22 +39,78 @@ png_error(png_structp png_ptr, png_const_charp message)
|
||||
}
|
||||
|
||||
/* This function is called whenever there is a non-fatal error. This function
|
||||
should not be changed. If there is a need to handle warnings differently,
|
||||
you should supply a replacement warning function and use
|
||||
png_set_error_fn() to replace the warning function at run-time. */
|
||||
* should not be changed. If there is a need to handle warnings differently,
|
||||
* you should supply a replacement warning function and use
|
||||
* png_set_error_fn() to replace the warning function at run-time.
|
||||
*/
|
||||
void
|
||||
png_warning(png_structp png_ptr, png_const_charp message)
|
||||
{
|
||||
if (png_ptr->warning_fn)
|
||||
if (png_ptr->warning_fn != NULL)
|
||||
(*(png_ptr->warning_fn))(png_ptr, message);
|
||||
else
|
||||
png_default_warning(png_ptr, message);
|
||||
}
|
||||
|
||||
/* These utilities are used internally to build an error message which relates
|
||||
* to the current chunk. The chunk name comes from png_ptr->chunk_name,
|
||||
* this is used to prefix the message. The message is limited in length
|
||||
* to 63 bytes, the name characters are output as hex digits wrapped in []
|
||||
* if the character is invalid.
|
||||
*/
|
||||
#define isnonalpha(c) ((c) < 41 || (c) > 122 || ((c) > 90 && (c) < 97))
|
||||
static const char png_digit[16] = {
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
|
||||
};
|
||||
|
||||
static void
|
||||
png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp message)
|
||||
{
|
||||
int iout = 0, iin = 0;
|
||||
|
||||
while (iin < 4) {
|
||||
int c = png_ptr->chunk_name[iin++];
|
||||
if (isnonalpha(c)) {
|
||||
buffer[iout++] = '[';
|
||||
buffer[iout++] = png_digit[(c & 0xf0) >> 4];
|
||||
buffer[iout++] = png_digit[c & 0xf];
|
||||
buffer[iout++] = ']';
|
||||
} else {
|
||||
buffer[iout++] = c;
|
||||
}
|
||||
}
|
||||
|
||||
if (message == NULL)
|
||||
buffer[iout++] = 0;
|
||||
else {
|
||||
buffer[iout++] = ':';
|
||||
buffer[iout++] = ' ';
|
||||
png_memcpy(buffer+iout, message, 64);
|
||||
buffer[iout+63] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
png_chunk_error(png_structp png_ptr, png_const_charp message)
|
||||
{
|
||||
char msg[16+64];
|
||||
png_format_buffer(png_ptr, msg, message);
|
||||
png_error(png_ptr, msg);
|
||||
}
|
||||
|
||||
void
|
||||
png_chunk_warning(png_structp png_ptr, png_const_charp message)
|
||||
{
|
||||
char msg[16+64];
|
||||
png_format_buffer(png_ptr, msg, message);
|
||||
png_warning(png_ptr, msg);
|
||||
}
|
||||
|
||||
/* This is the default error handling function. Note that replacements for
|
||||
this function MUST NOT RETURN, or the program will likely crash. This
|
||||
function is used by default, or if the program supplies NULL for the
|
||||
error function pointer in png_set_error_fn(). */
|
||||
* this function MUST NOT RETURN, or the program will likely crash. This
|
||||
* function is used by default, or if the program supplies NULL for the
|
||||
* error function pointer in png_set_error_fn().
|
||||
*/
|
||||
static void
|
||||
png_default_error(png_structp png_ptr, png_const_charp message)
|
||||
{
|
||||
@@ -70,13 +130,14 @@ png_default_error(png_structp png_ptr, png_const_charp message)
|
||||
}
|
||||
|
||||
/* This function is called when there is a warning, but the library thinks
|
||||
it can continue anyway. Replacement functions don't have to do anything
|
||||
here if you don't want to. In the default configuration, png_ptr is
|
||||
not used, but it is passed in case it may be useful. */
|
||||
* it can continue anyway. Replacement functions don't have to do anything
|
||||
* here if you don't want to. In the default configuration, png_ptr is
|
||||
* not used, but it is passed in case it may be useful.
|
||||
*/
|
||||
static void
|
||||
png_default_warning(png_structp png_ptr, png_const_charp message)
|
||||
{
|
||||
if (!png_ptr)
|
||||
if (png_ptr == NULL)
|
||||
return;
|
||||
|
||||
#ifndef PNG_NO_STDIO
|
||||
@@ -85,9 +146,10 @@ png_default_warning(png_structp png_ptr, png_const_charp message)
|
||||
}
|
||||
|
||||
/* This function is called when the application wants to use another method
|
||||
of handling errors and warnings. Note that the error function MUST NOT
|
||||
return to the calling routine or serious problems will occur. The return
|
||||
method used in the default routine calls longjmp(png_ptr->jmpbuf, 1) */
|
||||
* of handling errors and warnings. Note that the error function MUST NOT
|
||||
* return to the calling routine or serious problems will occur. The return
|
||||
* method used in the default routine calls longjmp(png_ptr->jmpbuf, 1)
|
||||
*/
|
||||
void
|
||||
png_set_error_fn(png_structp png_ptr, png_voidp error_ptr,
|
||||
png_error_ptr error_fn, png_error_ptr warning_fn)
|
||||
@@ -99,8 +161,9 @@ png_set_error_fn(png_structp png_ptr, png_voidp error_ptr,
|
||||
|
||||
|
||||
/* This function returns a pointer to the error_ptr associated with the user
|
||||
functions. The application should free any memory associated with this
|
||||
pointer before png_write_destroy and png_read_destroy are called. */
|
||||
* functions. The application should free any memory associated with this
|
||||
* pointer before png_write_destroy and png_read_destroy are called.
|
||||
*/
|
||||
png_voidp
|
||||
png_get_error_ptr(png_structp png_ptr)
|
||||
{
|
||||
|
||||
326
pngget.c
Normal file
326
pngget.c
Normal file
@@ -0,0 +1,326 @@
|
||||
|
||||
/* pngget.c - retrieval of values from info struct
|
||||
*
|
||||
* libpng 0.97
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* January 7, 1998
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
#include "png.h"
|
||||
|
||||
png_uint_32
|
||||
png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag)
|
||||
{
|
||||
if (info_ptr != NULL)
|
||||
return(info_ptr->valid & flag);
|
||||
else
|
||||
return(0);
|
||||
}
|
||||
|
||||
png_uint_32
|
||||
png_get_rowbytes(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
if (info_ptr != NULL)
|
||||
return(info_ptr->rowbytes);
|
||||
else
|
||||
return(0);
|
||||
}
|
||||
|
||||
png_byte
|
||||
png_get_channels(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
if (info_ptr != NULL)
|
||||
return(info_ptr->channels);
|
||||
else
|
||||
return(0);
|
||||
}
|
||||
|
||||
png_bytep
|
||||
png_get_signature(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
if (info_ptr != NULL)
|
||||
return(info_ptr->signature);
|
||||
else
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
#if defined(PNG_READ_bKGD_SUPPORTED)
|
||||
png_uint_32
|
||||
png_get_bKGD(png_structp png_ptr, png_infop info_ptr,
|
||||
png_color_16p *background)
|
||||
{
|
||||
if (info_ptr != NULL && info_ptr->valid & PNG_INFO_bKGD &&
|
||||
background != NULL)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n", "bKGD");
|
||||
*background = &(info_ptr->background);
|
||||
return (PNG_INFO_bKGD);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_cHRM_SUPPORTED)
|
||||
png_uint_32
|
||||
png_get_cHRM(png_structp png_ptr, png_infop info_ptr,
|
||||
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 (info_ptr != NULL && info_ptr->valid & PNG_INFO_cHRM)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n", "cHRM");
|
||||
if (white_x != NULL)
|
||||
*white_x = (double)info_ptr->x_white;
|
||||
if (white_y != NULL)
|
||||
*white_y = (double)info_ptr->y_white;
|
||||
if (red_x != NULL)
|
||||
*red_x = (double)info_ptr->x_red;
|
||||
if (red_y != NULL)
|
||||
*red_y = (double)info_ptr->y_red;
|
||||
if (green_x != NULL)
|
||||
*green_x = (double)info_ptr->x_green;
|
||||
if (green_y != NULL)
|
||||
*green_y = (double)info_ptr->y_green;
|
||||
if (blue_x != NULL)
|
||||
*blue_x = (double)info_ptr->x_blue;
|
||||
if (blue_y != NULL)
|
||||
*blue_y = (double)info_ptr->y_blue;
|
||||
return (PNG_INFO_cHRM);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_gAMA_SUPPORTED)
|
||||
png_uint_32
|
||||
png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma)
|
||||
{
|
||||
if (info_ptr != NULL && info_ptr->valid & PNG_INFO_gAMA &&
|
||||
file_gamma != NULL)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n", "gAMA");
|
||||
*file_gamma = (double)info_ptr->gamma;
|
||||
return (PNG_INFO_gAMA);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_sRGB_SUPPORTED)
|
||||
png_uint_32
|
||||
png_get_sRGB(png_structp png_ptr, png_infop info_ptr, png_bytep
|
||||
file_srgb_intent)
|
||||
{
|
||||
if (info_ptr != NULL && info_ptr->valid & PNG_INFO_sRGB &&
|
||||
file_srgb_intent != NULL)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n", "sRGB");
|
||||
*file_srgb_intent = info_ptr->srgb_intent;
|
||||
return (PNG_INFO_sRGB);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_hIST_SUPPORTED)
|
||||
png_uint_32
|
||||
png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist)
|
||||
{
|
||||
if (info_ptr != NULL && info_ptr->valid & PNG_INFO_hIST && hist != NULL)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n", "hIST");
|
||||
*hist = info_ptr->hist;
|
||||
return (PNG_INFO_hIST);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
#endif
|
||||
|
||||
png_uint_32
|
||||
png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
|
||||
png_uint_32 *width, png_uint_32 *height, int *bit_depth,
|
||||
int *color_type, int *interlace_type, int *compression_type,
|
||||
int *filter_type)
|
||||
|
||||
{
|
||||
if (info_ptr != NULL && width != NULL && height != NULL &&
|
||||
bit_depth != NULL && color_type != NULL)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n", "IHDR");
|
||||
*width = info_ptr->width;
|
||||
*height = info_ptr->height;
|
||||
*bit_depth = info_ptr->bit_depth;
|
||||
*color_type = info_ptr->color_type;
|
||||
if (compression_type != NULL)
|
||||
*compression_type = info_ptr->compression_type;
|
||||
if (filter_type != NULL)
|
||||
*filter_type = info_ptr->filter_type;
|
||||
if (interlace_type != NULL)
|
||||
*interlace_type = info_ptr->interlace_type;
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
#if defined(PNG_READ_oFFs_SUPPORTED)
|
||||
png_uint_32
|
||||
png_get_oFFs(png_structp png_ptr, png_infop info_ptr,
|
||||
png_uint_32 *offset_x, png_uint_32 *offset_y, int *unit_type)
|
||||
{
|
||||
if (info_ptr != NULL && info_ptr->valid & PNG_INFO_oFFs &&
|
||||
offset_x != NULL && offset_y != NULL && unit_type != NULL)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n", "oFFs");
|
||||
*offset_x = info_ptr->x_offset;
|
||||
*offset_y = info_ptr->y_offset;
|
||||
*unit_type = (int)info_ptr->offset_unit_type;
|
||||
return (PNG_INFO_oFFs);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_pCAL_SUPPORTED)
|
||||
png_uint_32
|
||||
png_get_pCAL(png_structp png_ptr, png_infop info_ptr,
|
||||
png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
|
||||
png_charp *units, png_charpp *params)
|
||||
{
|
||||
if (info_ptr != NULL && info_ptr->valid & PNG_INFO_pCAL &&
|
||||
purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
|
||||
nparams != NULL && units != NULL && params != NULL)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n", "pCAL");
|
||||
*purpose = info_ptr->pcal_purpose;
|
||||
*X0 = info_ptr->pcal_X0;
|
||||
*X1 = info_ptr->pcal_X1;
|
||||
*type = (int)info_ptr->pcal_type;
|
||||
*nparams = (int)info_ptr->pcal_nparams;
|
||||
*units = info_ptr->pcal_units;
|
||||
*params = info_ptr->pcal_params;
|
||||
return (PNG_INFO_pCAL);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_pHYs_SUPPORTED)
|
||||
png_uint_32
|
||||
png_get_pHYs(png_structp png_ptr, png_infop info_ptr,
|
||||
png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
|
||||
{
|
||||
png_uint_32 retval = 0;
|
||||
|
||||
if (info_ptr != NULL && info_ptr->valid & PNG_INFO_pHYs)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n", "pHYs");
|
||||
if (res_x != NULL && res_y != NULL)
|
||||
{
|
||||
*res_x = info_ptr->x_pixels_per_unit;
|
||||
*res_y = info_ptr->y_pixels_per_unit;
|
||||
retval |= PNG_INFO_pHYs;
|
||||
}
|
||||
if (unit_type != NULL)
|
||||
{
|
||||
*unit_type = (int)info_ptr->phys_unit_type;
|
||||
retval |= PNG_INFO_pHYs;
|
||||
}
|
||||
return (retval);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
#endif
|
||||
|
||||
png_uint_32
|
||||
png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette,
|
||||
int *num_palette)
|
||||
{
|
||||
if (info_ptr != NULL && info_ptr->valid & PNG_INFO_PLTE && palette != NULL)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n", "PLTE");
|
||||
*palette = info_ptr->palette;
|
||||
*num_palette = info_ptr->num_palette;
|
||||
png_debug1(3, "num_palette = %d\n", *num_palette);
|
||||
return (PNG_INFO_PLTE);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
#if defined(PNG_READ_sBIT_SUPPORTED)
|
||||
png_uint_32
|
||||
png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit)
|
||||
{
|
||||
if (info_ptr != NULL && info_ptr->valid & PNG_INFO_sBIT && sig_bit != NULL)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n", "sBIT");
|
||||
*sig_bit = &(info_ptr->sig_bit);
|
||||
return (PNG_INFO_sBIT);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_READ_zTXt_SUPPORTED)
|
||||
png_uint_32
|
||||
png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr,
|
||||
int *num_text)
|
||||
{
|
||||
if ((info_ptr != NULL) || (info_ptr->num_text > 0))
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n",
|
||||
(png_ptr->chunk_name[0] == '\0' ? "text" : png_ptr->chunk_name));
|
||||
if (text_ptr != NULL)
|
||||
*text_ptr = info_ptr->text;
|
||||
if (num_text != NULL)
|
||||
*num_text = info_ptr->num_text;
|
||||
return ((png_uint_32)info_ptr->num_text);
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_tIME_SUPPORTED)
|
||||
png_uint_32
|
||||
png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time)
|
||||
{
|
||||
if (info_ptr != NULL && info_ptr->valid & PNG_INFO_tIME && mod_time != NULL)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n", "tIME");
|
||||
*mod_time = &(info_ptr->mod_time);
|
||||
return (PNG_INFO_tIME);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_tRNS_SUPPORTED)
|
||||
png_uint_32
|
||||
png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
|
||||
png_bytep *trans, int *num_trans, png_color_16p *trans_values)
|
||||
{
|
||||
if (info_ptr != NULL && info_ptr->valid & PNG_INFO_tRNS)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function\n", "tRNS");
|
||||
if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE && trans != NULL)
|
||||
{
|
||||
*trans = info_ptr->trans;
|
||||
}
|
||||
else if (trans_values != NULL)
|
||||
{
|
||||
*trans_values = &(info_ptr->trans_values);
|
||||
}
|
||||
else
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
*num_trans = info_ptr->num_trans;
|
||||
return (PNG_INFO_tRNS);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
#endif
|
||||
|
||||
252
pngmem.c
252
pngmem.c
@@ -1,14 +1,17 @@
|
||||
|
||||
/* pngmem.c - stub functions for memory allocation
|
||||
|
||||
libpng 1.0 beta 3 - version 0.89
|
||||
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
|
||||
|
||||
This file provides a location for all memory allocation. Users which
|
||||
need special memory handling are expected to modify the code in this file
|
||||
to meet their needs. See the instructions at each function. */
|
||||
*
|
||||
* libpng 0.97
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* January 7, 1998
|
||||
*
|
||||
* This file provides a location for all memory allocation. Users which
|
||||
* need special memory handling are expected to modify the code in this file
|
||||
* to meet their needs. See the instructions at each function.
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
#include "png.h"
|
||||
@@ -18,12 +21,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)
|
||||
@@ -46,30 +48,34 @@ png_create_struct(uInt type)
|
||||
void
|
||||
png_destroy_struct(png_voidp struct_ptr)
|
||||
{
|
||||
if (struct_ptr)
|
||||
if (struct_ptr != NULL)
|
||||
farfree (struct_ptr);
|
||||
}
|
||||
|
||||
/* 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. */
|
||||
|
||||
/* 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. This code has
|
||||
been updated by Alexander Lehmann for version 0.89 to waste less
|
||||
memory.
|
||||
*/
|
||||
|
||||
* 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. This code has
|
||||
* been updated by Alexander Lehmann for version 0.89 to waste less
|
||||
* memory.
|
||||
*
|
||||
* Note that we can't use png_size_t for the "size" declaration,
|
||||
* since on some systems a png_size_t is a 16-bit quantity, and as a
|
||||
* result, we would be truncating potentially larger memory requests
|
||||
* (which should cause a fatal error) and introducing major problems.
|
||||
*/
|
||||
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)
|
||||
if (png_ptr == NULL || size == 0)
|
||||
return ((voidp)NULL);
|
||||
|
||||
#ifdef PNG_MAX_MALLOC_64K
|
||||
@@ -77,13 +83,13 @@ png_large_malloc(png_structp png_ptr, png_uint_32 size)
|
||||
png_error(png_ptr, "Cannot Allocate > 64K");
|
||||
#endif
|
||||
|
||||
if (size == (png_uint_32)(65536L))
|
||||
if (size == (png_uint_32)65536L)
|
||||
{
|
||||
if (!png_ptr->offset_table)
|
||||
if (png_ptr->offset_table == NULL)
|
||||
{
|
||||
/* try to see if we need to do any of this fancy stuff */
|
||||
ret = farmalloc(size);
|
||||
if (!ret || ((long)ret & 0xffff))
|
||||
if (ret == NULL || ((png_size_t)ret & 0xffff))
|
||||
{
|
||||
int num_blocks;
|
||||
png_uint_32 total_size;
|
||||
@@ -91,7 +97,7 @@ png_large_malloc(png_structp png_ptr, png_uint_32 size)
|
||||
int i;
|
||||
png_byte huge * hptr;
|
||||
|
||||
if (ret)
|
||||
if (ret != NULL)
|
||||
farfree(ret);
|
||||
ret = NULL;
|
||||
|
||||
@@ -107,27 +113,27 @@ png_large_malloc(png_structp png_ptr, png_uint_32 size)
|
||||
|
||||
table = farmalloc(total_size);
|
||||
|
||||
if (!table)
|
||||
if (table == NULL)
|
||||
{
|
||||
png_error(png_ptr, "Out of Memory");
|
||||
}
|
||||
|
||||
if ((long)table & 0xfff0)
|
||||
if ((png_size_t)table & 0xfff0)
|
||||
{
|
||||
png_error(png_ptr, "Farmalloc didn't return normalized pointer");
|
||||
}
|
||||
|
||||
png_ptr->offset_table = table;
|
||||
png_ptr->offset_table_ptr = farmalloc(
|
||||
num_blocks * sizeof (png_bytep));
|
||||
png_ptr->offset_table_ptr = farmalloc(num_blocks *
|
||||
sizeof (png_bytep));
|
||||
|
||||
if (!png_ptr->offset_table_ptr)
|
||||
if (png_ptr->offset_table_ptr == NULL)
|
||||
{
|
||||
png_error(png_ptr, "Out of memory");
|
||||
}
|
||||
|
||||
hptr = (png_byte huge *)table;
|
||||
if ((long)hptr & 0xf)
|
||||
if ((png_size_t)hptr & 0xf)
|
||||
{
|
||||
hptr = (png_byte huge *)((long)(hptr) & 0xfffffff0L);
|
||||
hptr += 16L;
|
||||
@@ -135,7 +141,7 @@ png_large_malloc(png_structp png_ptr, png_uint_32 size)
|
||||
for (i = 0; i < num_blocks; i++)
|
||||
{
|
||||
png_ptr->offset_table_ptr[i] = (png_bytep)hptr;
|
||||
hptr += 65536L;
|
||||
hptr += (png_uint_32)65536L;
|
||||
}
|
||||
|
||||
png_ptr->offset_table_number = num_blocks;
|
||||
@@ -160,68 +166,64 @@ 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)
|
||||
if (png_ptr == NULL || ptr == NULL)
|
||||
return;
|
||||
|
||||
if (ptr != NULL)
|
||||
if (png_ptr->offset_table != NULL)
|
||||
{
|
||||
if (png_ptr->offset_table)
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < png_ptr->offset_table_count; i++)
|
||||
for (i = 0; i < png_ptr->offset_table_count; i++)
|
||||
{
|
||||
if (ptr == png_ptr->offset_table_ptr[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;
|
||||
ptr = NULL;
|
||||
png_ptr->offset_table_count_free++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ptr)
|
||||
farfree(ptr);
|
||||
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 = NULL;
|
||||
png_ptr->offset_table_ptr = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (ptr != NULL)
|
||||
farfree(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_size_t size;
|
||||
png_voidp struct_ptr;
|
||||
|
||||
if (type == PNG_STRUCT_INFO)
|
||||
size = sizeof(png_info);
|
||||
size = sizeof(png_info);
|
||||
else if (type == PNG_STRUCT_PNG)
|
||||
size = sizeof(png_struct);
|
||||
size = sizeof(png_struct);
|
||||
else
|
||||
return (png_voidp)NULL;
|
||||
return (png_voidp)NULL;
|
||||
|
||||
#if defined(__TURBOC__) && !defined(__FLAT__)
|
||||
if ((struct_ptr = (png_voidp)farmalloc(size)) != NULL)
|
||||
#else
|
||||
# if defined(_MSC_VER) && defined(MAXSEG_64K)
|
||||
if ((struct_ptr = (png_voidp)halloc(size)) != NULL)
|
||||
if ((struct_ptr = (png_voidp)halloc(size,1)) != NULL)
|
||||
# else
|
||||
if ((struct_ptr = (png_voidp)malloc(size)) != NULL)
|
||||
# endif
|
||||
@@ -238,7 +240,7 @@ png_create_struct(uInt type)
|
||||
void
|
||||
png_destroy_struct(png_voidp struct_ptr)
|
||||
{
|
||||
if (struct_ptr)
|
||||
if (struct_ptr != NULL)
|
||||
#if defined(__TURBOC__) && !defined(__FLAT__)
|
||||
farfree(struct_ptr);
|
||||
#else
|
||||
@@ -253,16 +255,16 @@ png_destroy_struct(png_voidp struct_ptr)
|
||||
|
||||
/* 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
|
||||
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_malloc(png_structp png_ptr, png_uint_32 size)
|
||||
{
|
||||
png_voidp ret;
|
||||
if (!png_ptr || !size)
|
||||
return ((voidp)0);
|
||||
if (png_ptr == NULL || size == 0)
|
||||
return (NULL);
|
||||
|
||||
#ifdef PNG_MAX_MALLOC_64K
|
||||
if (size > (png_uint_32)65536L)
|
||||
@@ -270,7 +272,7 @@ png_large_malloc(png_structp png_ptr, png_uint_32 size)
|
||||
#endif
|
||||
|
||||
#if defined(__TURBOC__) && !defined(__FLAT__)
|
||||
ret = farmalloc(size);
|
||||
ret = farmalloc((png_size_t)size);
|
||||
#else
|
||||
# if defined(_MSC_VER) && defined(MAXSEG_64K)
|
||||
ret = halloc(size, 1);
|
||||
@@ -287,99 +289,25 @@ 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)
|
||||
if (png_ptr == NULL || ptr == NULL)
|
||||
return;
|
||||
|
||||
if (ptr != NULL)
|
||||
{
|
||||
#if defined(__TURBOC__) && !defined(__FLAT__)
|
||||
farfree(ptr);
|
||||
farfree(ptr);
|
||||
#else
|
||||
# if defined(_MSC_VER) && defined(MAXSEG_64K)
|
||||
hfree(ptr);
|
||||
hfree(ptr);
|
||||
# else
|
||||
free(ptr);
|
||||
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). 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);
|
||||
}
|
||||
|
||||
|
||||
915
pngpread.c
915
pngpread.c
File diff suppressed because it is too large
Load Diff
243
pngrcb.c
243
pngrcb.c
@@ -1,243 +0,0 @@
|
||||
/* pngrcb.c - callbacks while reading a png file
|
||||
|
||||
libpng 1.0 beta 3 - version 0.89
|
||||
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
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
#include "png.h"
|
||||
|
||||
void
|
||||
png_read_IHDR(png_structp png_ptr, png_infop info,
|
||||
png_uint_32 width, png_uint_32 height, int bit_depth,
|
||||
int color_type, int compression_type, int filter_type,
|
||||
int interlace_type)
|
||||
{
|
||||
if (!png_ptr || !info)
|
||||
return;
|
||||
|
||||
info->width = width;
|
||||
info->height = height;
|
||||
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)
|
||||
info->channels = 3;
|
||||
else
|
||||
info->channels = 1;
|
||||
if (info->color_type & PNG_COLOR_MASK_ALPHA)
|
||||
info->channels++;
|
||||
info->pixel_depth = (png_byte)(info->channels * info->bit_depth);
|
||||
info->rowbytes = ((info->width * info->pixel_depth + 7) >> 3);
|
||||
}
|
||||
|
||||
void
|
||||
png_read_PLTE(png_structp png_ptr, png_infop info,
|
||||
png_colorp palette, int num)
|
||||
{
|
||||
if (!png_ptr || !info)
|
||||
return;
|
||||
|
||||
info->palette = palette;
|
||||
info->num_palette = (png_uint_16)num;
|
||||
info->valid |= PNG_INFO_PLTE;
|
||||
}
|
||||
|
||||
#if defined(PNG_READ_gAMA_SUPPORTED)
|
||||
void
|
||||
png_read_gAMA(png_structp png_ptr, png_infop info, double gamma)
|
||||
{
|
||||
if (!png_ptr || !info)
|
||||
return;
|
||||
|
||||
info->gamma = gamma;
|
||||
info->valid |= PNG_INFO_gAMA;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_sBIT_SUPPORTED)
|
||||
void
|
||||
png_read_sBIT(png_structp png_ptr, png_infop info,
|
||||
png_color_8p sig_bit)
|
||||
{
|
||||
if (!png_ptr || !info)
|
||||
return;
|
||||
|
||||
png_memcpy(&(info->sig_bit), sig_bit, sizeof (png_color_8));
|
||||
info->valid |= PNG_INFO_sBIT;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_cHRM_SUPPORTED)
|
||||
void
|
||||
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)
|
||||
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->valid |= PNG_INFO_cHRM;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_tRNS_SUPPORTED)
|
||||
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)
|
||||
return;
|
||||
|
||||
if (trans)
|
||||
{
|
||||
info->trans = trans;
|
||||
}
|
||||
else
|
||||
{
|
||||
png_memcpy(&(info->trans_values), trans_values,
|
||||
sizeof(png_color_16));
|
||||
}
|
||||
info->num_trans = (png_uint_16)num_trans;
|
||||
info->valid |= PNG_INFO_tRNS;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_bKGD_SUPPORTED)
|
||||
void
|
||||
png_read_bKGD(png_structp png_ptr, png_infop info,
|
||||
png_color_16p background)
|
||||
{
|
||||
if (!png_ptr || !info)
|
||||
return;
|
||||
|
||||
png_memcpy(&(info->background), background, sizeof(png_color_16));
|
||||
info->valid |= PNG_INFO_bKGD;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_hIST_SUPPORTED)
|
||||
void
|
||||
png_read_hIST(png_structp png_ptr, png_infop info, png_uint_16p hist)
|
||||
{
|
||||
if (!png_ptr || !info)
|
||||
return;
|
||||
|
||||
info->hist = hist;
|
||||
info->valid |= PNG_INFO_hIST;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_pHYs_SUPPORTED)
|
||||
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)
|
||||
return;
|
||||
|
||||
info->x_pixels_per_unit = res_x;
|
||||
info->y_pixels_per_unit = res_y;
|
||||
info->phys_unit_type = (png_byte)unit_type;
|
||||
info->valid |= PNG_INFO_pHYs;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_oFFs_SUPPORTED)
|
||||
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)
|
||||
return;
|
||||
|
||||
info->x_offset = offset_x;
|
||||
info->y_offset = offset_y;
|
||||
info->offset_unit_type = (png_byte)unit_type;
|
||||
info->valid |= PNG_INFO_oFFs;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_tIME_SUPPORTED)
|
||||
void
|
||||
png_read_tIME(png_structp png_ptr, png_infop info,
|
||||
png_timep mod_time)
|
||||
{
|
||||
if (!png_ptr || !info)
|
||||
return;
|
||||
|
||||
png_memcpy(&(info->mod_time), mod_time, sizeof (png_time));
|
||||
info->valid |= PNG_INFO_tIME;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_READ_zTXt_SUPPORTED)
|
||||
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)
|
||||
return;
|
||||
|
||||
if (info->max_text <= info->num_text)
|
||||
{
|
||||
if (info->text)
|
||||
{
|
||||
png_uint_32 old_max;
|
||||
|
||||
old_max = info->max_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 = 16;
|
||||
info->num_text = 0;
|
||||
info->text = (png_textp)png_large_malloc(png_ptr,
|
||||
info->max_text * sizeof (png_text));
|
||||
}
|
||||
}
|
||||
|
||||
info->text[info->num_text].key = key;
|
||||
info->text[info->num_text].text = text;
|
||||
info->text[info->num_text].text_length = text_len;
|
||||
info->text[info->num_text].compression = compression;
|
||||
info->num_text++;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_tEXt_SUPPORTED)
|
||||
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)
|
||||
return;
|
||||
|
||||
png_read_zTXt(png_ptr, info, key, text, text_len, -1);
|
||||
}
|
||||
#endif
|
||||
|
||||
80
pngrio.c
80
pngrio.c
@@ -1,17 +1,20 @@
|
||||
|
||||
/* pngrio.c - functions for data input
|
||||
|
||||
libpng 1.0 beta 3 - version 0.89
|
||||
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
|
||||
|
||||
This file provides a location for all input. Users which need
|
||||
special handling are expected to write a function which has the same
|
||||
arguments as this, and perform a similar function, but possibly has
|
||||
a different input method. Note that you shouldn't change this
|
||||
function, but rather write a replacement function and then make
|
||||
libpng use it at run time with png_set_read_fn(...) */
|
||||
*
|
||||
* libpng 0.97
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* January 7, 1998
|
||||
*
|
||||
* This file provides a location for all input. Users which need
|
||||
* special handling are expected to write a function which has the same
|
||||
* arguments as this, and perform a similar function, but possibly has
|
||||
* a different input method. Note that you shouldn't change this
|
||||
* function, but rather write a replacement function and then make
|
||||
* libpng use it at run time with png_set_read_fn(...).
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
#include "png.h"
|
||||
@@ -20,28 +23,34 @@
|
||||
reads from a file pointer. Note that this routine sometimes gets called
|
||||
with very small lengths, so you should implement some kind of simple
|
||||
buffering if you are using unbuffered reads. This should never be asked
|
||||
to read more then 64K on a 16 bit machine. The cast to png_size_t is
|
||||
there to quiet some compilers */
|
||||
to read more then 64K on a 16 bit machine. */
|
||||
void
|
||||
png_read_data(png_structp png_ptr, png_bytep data, png_uint_32 length)
|
||||
png_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
{
|
||||
if (png_ptr->read_data_fn)
|
||||
png_debug1(4,"reading %d bytes\n", length);
|
||||
if (png_ptr->read_data_fn != NULL)
|
||||
(*(png_ptr->read_data_fn))(png_ptr, data, length);
|
||||
else
|
||||
png_error(png_ptr, "Call to NULL read function");
|
||||
}
|
||||
|
||||
#if !defined(PNG_NO_STDIO)
|
||||
/* This is the function which does the actual reading of data. If you are
|
||||
not reading from a standard C stream, you should create a replacement
|
||||
read_data function and use it at run time with png_set_read_fn(), rather
|
||||
than changing the library. */
|
||||
#ifndef USE_FAR_KEYWORD
|
||||
static void
|
||||
png_default_read_data(png_structp png_ptr, png_bytep data, png_uint_32 length)
|
||||
png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
{
|
||||
png_uint_32 check;
|
||||
png_size_t check;
|
||||
|
||||
/* fread() returns 0 on error, so it is OK to store this in a png_size_t
|
||||
* instead of an int, which is what fread() actually returns.
|
||||
*/
|
||||
check = (png_size_t)fread(data, (png_size_t)1, length,
|
||||
(FILE *)png_ptr->io_ptr);
|
||||
|
||||
check = fread(data, 1, (size_t)length, (FILE *)png_ptr->io_ptr);
|
||||
if (check != length)
|
||||
{
|
||||
png_error(png_ptr, "Read Error");
|
||||
@@ -56,40 +65,30 @@ 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_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
{
|
||||
png_uint_32 check;
|
||||
int 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, length, io_ptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
png_byte buf[NEAR_BUF_SIZE];
|
||||
png_size_t read, remaining, err;
|
||||
check = 0;
|
||||
remaining = (png_size_t)length;
|
||||
remaining = length;
|
||||
do
|
||||
{
|
||||
read = MIN(NEAR_BUF_SIZE, remaining);
|
||||
err = fread(buf, 1, read, (FILE *)png_ptr->io_ptr);
|
||||
err = fread(buf, (png_size_t)1, read, io_ptr);
|
||||
png_memcpy(data, buf, read); /* copy far buffer to near buffer */
|
||||
if(err != read)
|
||||
break;
|
||||
@@ -106,6 +105,7 @@ png_default_read_data(png_structp png_ptr, png_bytep data, png_uint_32 length)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* This function allows the application to supply a new input function
|
||||
for libpng if standard C streams aren't being used.
|
||||
@@ -126,10 +126,14 @@ png_set_read_fn(png_structp png_ptr, png_voidp io_ptr,
|
||||
{
|
||||
png_ptr->io_ptr = io_ptr;
|
||||
|
||||
if (read_data_fn)
|
||||
#if !defined(PNG_NO_STDIO)
|
||||
if (read_data_fn != NULL)
|
||||
png_ptr->read_data_fn = read_data_fn;
|
||||
else
|
||||
png_ptr->read_data_fn = png_default_read_data;
|
||||
#else
|
||||
png_ptr->read_data_fn = read_data_fn;
|
||||
#endif
|
||||
|
||||
/* It is an error to write to a read device */
|
||||
png_ptr->write_data_fn = NULL;
|
||||
|
||||
1864
pngrtran.c
1864
pngrtran.c
File diff suppressed because it is too large
Load Diff
1389
pngrutil.c
1389
pngrutil.c
File diff suppressed because it is too large
Load Diff
369
pngset.c
Normal file
369
pngset.c
Normal file
@@ -0,0 +1,369 @@
|
||||
|
||||
/* pngset.c - storage of image information into info struct
|
||||
*
|
||||
* libpng 0.97
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* January 7, 1998
|
||||
*
|
||||
* The functions here are used during reads to store data from the file
|
||||
* into the info struct, and during writes to store application data
|
||||
* into the info struct for writing into the file. This abstracts the
|
||||
* info struct and allows us to change the structure in the future.
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
#include "png.h"
|
||||
|
||||
#if defined(PNG_READ_bKGD_SUPPORTED) || defined(PNG_WRITE_bKGD_SUPPORTED)
|
||||
void
|
||||
png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background)
|
||||
{
|
||||
png_debug1(1, "in %s storage function\n", "bKGD");
|
||||
if (info_ptr == NULL)
|
||||
return;
|
||||
|
||||
png_memcpy(&(info_ptr->background), background, sizeof(png_color_16));
|
||||
info_ptr->valid |= PNG_INFO_bKGD;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_cHRM_SUPPORTED) || defined(PNG_WRITE_cHRM_SUPPORTED)
|
||||
void
|
||||
png_set_cHRM(png_structp png_ptr, png_infop info_ptr,
|
||||
double white_x, double white_y, double red_x, double red_y,
|
||||
double green_x, double green_y, double blue_x, double blue_y)
|
||||
{
|
||||
png_debug1(1, "in %s storage function\n", "cHRM");
|
||||
if (info_ptr == NULL)
|
||||
return;
|
||||
|
||||
info_ptr->x_white = (float)white_x;
|
||||
info_ptr->y_white = (float)white_y;
|
||||
info_ptr->x_red = (float)red_x;
|
||||
info_ptr->y_red = (float)red_y;
|
||||
info_ptr->x_green = (float)green_x;
|
||||
info_ptr->y_green = (float)green_y;
|
||||
info_ptr->x_blue = (float)blue_x;
|
||||
info_ptr->y_blue = (float)blue_y;
|
||||
info_ptr->valid |= PNG_INFO_cHRM;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_gAMA_SUPPORTED) || defined(PNG_WRITE_gAMA_SUPPORTED)
|
||||
void
|
||||
png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma)
|
||||
{
|
||||
png_debug1(1, "in %s storage function\n", "gAMA");
|
||||
if (info_ptr == NULL)
|
||||
return;
|
||||
|
||||
info_ptr->gamma = (float)file_gamma;
|
||||
info_ptr->valid |= PNG_INFO_gAMA;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_hIST_SUPPORTED) || defined(PNG_WRITE_hIST_SUPPORTED)
|
||||
void
|
||||
png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist)
|
||||
{
|
||||
png_debug1(1, "in %s storage function\n", "hIST");
|
||||
if (info_ptr == NULL)
|
||||
return;
|
||||
|
||||
info_ptr->hist = hist;
|
||||
info_ptr->valid |= PNG_INFO_hIST;
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
png_set_IHDR(png_structp png_ptr, png_infop info_ptr,
|
||||
png_uint_32 width, png_uint_32 height, int bit_depth,
|
||||
int color_type, int interlace_type, int compression_type,
|
||||
int filter_type)
|
||||
{
|
||||
png_debug1(1, "in %s storage function\n", "IHDR");
|
||||
if (info_ptr == NULL)
|
||||
return;
|
||||
|
||||
info_ptr->width = width;
|
||||
info_ptr->height = height;
|
||||
info_ptr->bit_depth = (png_byte)bit_depth;
|
||||
info_ptr->color_type =(png_byte) color_type;
|
||||
info_ptr->compression_type = (png_byte)compression_type;
|
||||
info_ptr->filter_type = (png_byte)filter_type;
|
||||
info_ptr->interlace_type = (png_byte)interlace_type;
|
||||
if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
|
||||
info_ptr->channels = 1;
|
||||
else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
|
||||
info_ptr->channels = 3;
|
||||
else
|
||||
info_ptr->channels = 1;
|
||||
if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
|
||||
info_ptr->channels++;
|
||||
info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth);
|
||||
info_ptr->rowbytes = ((info_ptr->width * info_ptr->pixel_depth + 7) >> 3);
|
||||
}
|
||||
|
||||
#if defined(PNG_READ_oFFs_SUPPORTED) || defined(PNG_WRITE_oFFs_SUPPORTED)
|
||||
void
|
||||
png_set_oFFs(png_structp png_ptr, png_infop info_ptr,
|
||||
png_uint_32 offset_x, png_uint_32 offset_y, int unit_type)
|
||||
{
|
||||
png_debug1(1, "in %s storage function\n", "oFFs");
|
||||
if (info_ptr == NULL)
|
||||
return;
|
||||
|
||||
info_ptr->x_offset = offset_x;
|
||||
info_ptr->y_offset = offset_y;
|
||||
info_ptr->offset_unit_type = (png_byte)unit_type;
|
||||
info_ptr->valid |= PNG_INFO_oFFs;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_pCAL_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED)
|
||||
void
|
||||
png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
|
||||
png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams,
|
||||
png_charp units, png_charpp params)
|
||||
{
|
||||
png_size_t length;
|
||||
int i;
|
||||
|
||||
png_debug1(1, "in %s storage function\n", "pCAL");
|
||||
if (info_ptr == NULL)
|
||||
return;
|
||||
|
||||
length = png_strlen(purpose) + 1;
|
||||
png_debug1(3, "allocating purpose for info (%d bytes)\n", length);
|
||||
info_ptr->pcal_purpose = (png_charp)png_malloc(png_ptr, length);
|
||||
png_memcpy(info_ptr->pcal_purpose, purpose, length);
|
||||
|
||||
png_debug(3, "storing X0, X1, type, and nparams in info\n");
|
||||
info_ptr->pcal_X0 = X0;
|
||||
info_ptr->pcal_X1 = X1;
|
||||
info_ptr->pcal_type = (png_byte)type;
|
||||
info_ptr->pcal_nparams = (png_byte)nparams;
|
||||
|
||||
length = png_strlen(units) + 1;
|
||||
png_debug1(3, "allocating units for info (%d bytes)\n", length);
|
||||
info_ptr->pcal_units = (png_charp)png_malloc(png_ptr, length);
|
||||
png_memcpy(info_ptr->pcal_units, units, length);
|
||||
|
||||
info_ptr->pcal_params = (png_charpp)png_malloc(png_ptr,
|
||||
(nparams + 1) * sizeof(png_charp));
|
||||
info_ptr->pcal_params[nparams] = NULL;
|
||||
|
||||
for (i = 0; i < nparams; i++)
|
||||
{
|
||||
length = png_strlen(params[i]) + 1;
|
||||
png_debug2(3, "allocating parameter %d for info (%d bytes)\n", i, length);
|
||||
info_ptr->pcal_params[i] = (png_charp)png_malloc(png_ptr, length);
|
||||
png_memcpy(info_ptr->pcal_params[i], params[i], length);
|
||||
}
|
||||
|
||||
info_ptr->valid |= PNG_INFO_pCAL;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_pHYs_SUPPORTED) || defined(PNG_WRITE_pHYs_SUPPORTED)
|
||||
void
|
||||
png_set_pHYs(png_structp png_ptr, png_infop info_ptr,
|
||||
png_uint_32 res_x, png_uint_32 res_y, int unit_type)
|
||||
{
|
||||
png_debug1(1, "in %s storage function\n", "pHYs");
|
||||
if (info_ptr == NULL)
|
||||
return;
|
||||
|
||||
info_ptr->x_pixels_per_unit = res_x;
|
||||
info_ptr->y_pixels_per_unit = res_y;
|
||||
info_ptr->phys_unit_type = (png_byte)unit_type;
|
||||
info_ptr->valid |= PNG_INFO_pHYs;
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
png_set_PLTE(png_structp png_ptr, png_infop info_ptr,
|
||||
png_colorp palette, int num_palette)
|
||||
{
|
||||
png_debug1(1, "in %s storage function\n", "PLTE");
|
||||
if (info_ptr == NULL)
|
||||
return;
|
||||
|
||||
info_ptr->palette = palette;
|
||||
info_ptr->num_palette = (png_uint_16)num_palette;
|
||||
info_ptr->valid |= PNG_INFO_PLTE;
|
||||
}
|
||||
|
||||
#if defined(PNG_READ_sBIT_SUPPORTED) || defined(PNG_WRITE_sBIT_SUPPORTED)
|
||||
void
|
||||
png_set_sBIT(png_structp png_ptr, png_infop info_ptr,
|
||||
png_color_8p sig_bit)
|
||||
{
|
||||
png_debug1(1, "in %s storage function\n", "sBIT");
|
||||
if (info_ptr == NULL)
|
||||
return;
|
||||
|
||||
png_memcpy(&(info_ptr->sig_bit), sig_bit, sizeof (png_color_8));
|
||||
info_ptr->valid |= PNG_INFO_sBIT;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_sRGB_SUPPORTED) || defined(PNG_WRITE_sRGB_SUPPORTED)
|
||||
void
|
||||
png_set_sRGB(png_structp png_ptr, png_infop info_ptr, png_byte intent)
|
||||
{
|
||||
png_debug1(1, "in %s storage function\n", "sRGB");
|
||||
if (info_ptr == NULL)
|
||||
return;
|
||||
|
||||
info_ptr->srgb_intent = intent;
|
||||
info_ptr->valid |= PNG_INFO_sRGB;
|
||||
}
|
||||
void
|
||||
png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
|
||||
png_byte intent)
|
||||
{
|
||||
#if defined(PNG_READ_gAMA_SUPPORTED) || defined(PNG_WRITE_gAMA_SUPPORTED)
|
||||
float file_gamma;
|
||||
#endif
|
||||
#if defined(PNG_READ_cHRM_SUPPORTED) || defined(PNG_WRITE_cHRM_SUPPORTED)
|
||||
float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
|
||||
#endif
|
||||
png_debug1(1, "in %s storage function\n", "sRGB_gAMA_and_cHRM");
|
||||
if (info_ptr == NULL)
|
||||
return;
|
||||
|
||||
png_set_sRGB(png_ptr, info_ptr, intent);
|
||||
|
||||
#if defined(PNG_READ_gAMA_SUPPORTED) || defined(PNG_WRITE_gAMA_SUPPORTED)
|
||||
file_gamma = (float).45;
|
||||
png_set_gAMA(png_ptr, info_ptr, file_gamma);
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_cHRM_SUPPORTED) || defined(PNG_WRITE_cHRM_SUPPORTED)
|
||||
white_x = (float).3127;
|
||||
white_y = (float).3290;
|
||||
red_x = (float).64;
|
||||
red_y = (float).33;
|
||||
green_x = (float).30;
|
||||
green_y = (float).60;
|
||||
blue_x = (float).15;
|
||||
blue_y = (float).06;
|
||||
|
||||
png_set_cHRM(png_ptr, info_ptr,
|
||||
white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
|
||||
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_WRITE_tEXt_SUPPORTED) || \
|
||||
defined(PNG_READ_zTXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED)
|
||||
void
|
||||
png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
|
||||
int num_text)
|
||||
{
|
||||
int i;
|
||||
|
||||
png_debug1(1, "in %s storage function\n", (png_ptr->chunk_name[0] == '\0' ?
|
||||
"text" : png_ptr->chunk_name));
|
||||
|
||||
if (info_ptr == NULL || num_text == 0)
|
||||
return;
|
||||
|
||||
/* Make sure we have enough space in the "text" array in info_struct
|
||||
* to hold all of the incoming text_ptr objects.
|
||||
*/
|
||||
if (info_ptr->num_text + num_text > info_ptr->max_text)
|
||||
{
|
||||
if (info_ptr->text != NULL)
|
||||
{
|
||||
png_textp old_text;
|
||||
int old_max;
|
||||
|
||||
old_max = info_ptr->max_text;
|
||||
info_ptr->max_text = info_ptr->num_text + num_text + 8;
|
||||
old_text = info_ptr->text;
|
||||
info_ptr->text = (png_textp)png_malloc(png_ptr,
|
||||
info_ptr->max_text * sizeof (png_text));
|
||||
png_memcpy(info_ptr->text, old_text, old_max * sizeof(png_text));
|
||||
png_free(png_ptr, old_text);
|
||||
}
|
||||
else
|
||||
{
|
||||
info_ptr->max_text = num_text + 8;
|
||||
info_ptr->num_text = 0;
|
||||
info_ptr->text = (png_textp)png_malloc(png_ptr,
|
||||
info_ptr->max_text * sizeof (png_text));
|
||||
}
|
||||
png_debug1(3, "allocated %d entries for info_ptr->text\n",
|
||||
info_ptr->max_text);
|
||||
}
|
||||
|
||||
for (i = 0; i < num_text; i++)
|
||||
{
|
||||
png_textp textp = &(info_ptr->text[info_ptr->num_text]);
|
||||
|
||||
if (text_ptr[i].text == NULL)
|
||||
text_ptr[i].text = "";
|
||||
|
||||
if (text_ptr[i].text[0] == '\0')
|
||||
{
|
||||
textp->text_length = 0;
|
||||
textp->compression = PNG_TEXT_COMPRESSION_NONE;
|
||||
}
|
||||
else
|
||||
{
|
||||
textp->text_length = png_strlen(text_ptr[i].text);
|
||||
textp->compression = text_ptr[i].compression;
|
||||
}
|
||||
textp->text = text_ptr[i].text;
|
||||
textp->key = text_ptr[i].key;
|
||||
info_ptr->num_text++;
|
||||
png_debug1(3, "transferred text chunk %d\n", info_ptr->num_text);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_tIME_SUPPORTED) || defined(PNG_WRITE_tIME_SUPPORTED)
|
||||
void
|
||||
png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time)
|
||||
{
|
||||
png_debug1(1, "in %s storage function\n", "tIME");
|
||||
if (info_ptr == NULL)
|
||||
return;
|
||||
|
||||
png_memcpy(&(info_ptr->mod_time), mod_time, sizeof (png_time));
|
||||
info_ptr->valid |= PNG_INFO_tIME;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_tRNS_SUPPORTED) || defined(PNG_WRITE_tRNS_SUPPORTED)
|
||||
void
|
||||
png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
|
||||
png_bytep trans, int num_trans, png_color_16p trans_values)
|
||||
{
|
||||
png_debug1(1, "in %s storage function\n", "tRNS");
|
||||
if (info_ptr == NULL)
|
||||
return;
|
||||
|
||||
if (trans != NULL)
|
||||
{
|
||||
info_ptr->trans = trans;
|
||||
}
|
||||
|
||||
if (trans_values != NULL)
|
||||
{
|
||||
png_memcpy(&(info_ptr->trans_values), trans_values,
|
||||
sizeof(png_color_16));
|
||||
if (num_trans == 0)
|
||||
num_trans = 1;
|
||||
}
|
||||
info_ptr->num_trans = (png_uint_16)num_trans;
|
||||
info_ptr->valid |= PNG_INFO_tRNS;
|
||||
}
|
||||
#endif
|
||||
|
||||
622
pngtest.c
622
pngtest.c
@@ -1,13 +1,40 @@
|
||||
/* pngtest.c - a simple test program to test libpng
|
||||
|
||||
libpng 1.0 beta 3 - version 0.89
|
||||
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
|
||||
*/
|
||||
/* pngtest.c - a simple test program to test libpng
|
||||
*
|
||||
* libpng 0.97
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* January 7, 1998
|
||||
*
|
||||
* This program reads in a PNG image, writes it out again, and then
|
||||
* compares the two files. If the files are identical, this shows that
|
||||
* the basic chunk handling, filtering, and (de)compression code is working
|
||||
* properly. It does not currently test all of the transforms, although
|
||||
* it probably should.
|
||||
*
|
||||
* The program will fail in certain legitimate cases:
|
||||
* 1) when the compression level or filter selection method is changed.
|
||||
* 2) when the chunk size is smaller than 8K.
|
||||
* 3) unknown ancillary chunks exist in the input file.
|
||||
* 4) others not listed here...
|
||||
* In these cases, it is best to check with another tool such as "pngcheck"
|
||||
* to see what the differences between the two images are.
|
||||
*
|
||||
* If a filename is given on the command-line, then this file is used
|
||||
* for the input, rather than the default "pngtest.png". This allows
|
||||
* testing a wide variety of files easily.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/* Makes pngtest verbose so we can find problems (needs to be before png.h) */
|
||||
#ifndef PNG_DEBUG
|
||||
#define PNG_DEBUG 0
|
||||
#endif
|
||||
|
||||
#include "png.h"
|
||||
|
||||
#ifdef __TURBOC__
|
||||
@@ -18,166 +45,492 @@
|
||||
/* #define STDERR stderr */
|
||||
#define STDERR stdout /* for DOS */
|
||||
|
||||
/* input and output filenames */
|
||||
#ifdef RISCOS
|
||||
char *inname = "pngtest_pn";
|
||||
char *outname = "pngout_png";
|
||||
/* START of code to validate stdio-free compilation */
|
||||
/* These copies of the default read/write functions come from pngrio.c and */
|
||||
/* pngwio.c. They allow "don't include stdio" testing of the library. */
|
||||
#if defined(PNG_NO_STDIO)
|
||||
/* This is the function which does the actual reading of data. If you are
|
||||
not reading from a standard C stream, you should create a replacement
|
||||
read_data function and use it at run time with png_set_read_fn(), rather
|
||||
than changing the library. */
|
||||
#ifndef USE_FAR_KEYWORD
|
||||
static void
|
||||
png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
{
|
||||
png_size_t check;
|
||||
|
||||
/* fread() returns 0 on error, so it is OK to store this in a png_size_t
|
||||
* instead of an int, which is what fread() actually returns.
|
||||
*/
|
||||
check = (png_size_t)fread(data, (png_size_t)1, length,
|
||||
(FILE *)png_ptr->io_ptr);
|
||||
|
||||
if (check != length)
|
||||
{
|
||||
png_error(png_ptr, "Read Error");
|
||||
}
|
||||
}
|
||||
#else
|
||||
char *inname = "pngtest.png";
|
||||
char *outname = "pngout.png";
|
||||
/* this is the model-independent version. Since the standard I/O library
|
||||
can't handle far buffers in the medium and small models, we have to copy
|
||||
the data.
|
||||
*/
|
||||
|
||||
#define NEAR_BUF_SIZE 1024
|
||||
#define MIN(a,b) (a <= b ? a : b)
|
||||
|
||||
static void
|
||||
png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
{
|
||||
int check;
|
||||
png_byte *n_data;
|
||||
FILE *io_ptr;
|
||||
|
||||
/* Check if data really is near. If so, use usual code. */
|
||||
n_data = (png_byte *)CVT_PTR_NOCHECK(data);
|
||||
io_ptr = (FILE *)CVT_PTR(png_ptr->io_ptr);
|
||||
if ((png_bytep)n_data == data)
|
||||
{
|
||||
check = fread(n_data, 1, length, io_ptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
png_byte buf[NEAR_BUF_SIZE];
|
||||
png_size_t read, remaining, err;
|
||||
check = 0;
|
||||
remaining = length;
|
||||
do
|
||||
{
|
||||
read = MIN(NEAR_BUF_SIZE, remaining);
|
||||
err = fread(buf, (png_size_t)1, read, io_ptr);
|
||||
png_memcpy(data, buf, read); /* copy far buffer to near buffer */
|
||||
if(err != read)
|
||||
break;
|
||||
else
|
||||
check += err;
|
||||
data += read;
|
||||
remaining -= read;
|
||||
}
|
||||
while (remaining != 0);
|
||||
}
|
||||
if (check != length)
|
||||
{
|
||||
png_error(png_ptr, "read Error");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
char inbuf[256], outbuf[256];
|
||||
#if defined(PNG_WRITE_FLUSH_SUPPORTED)
|
||||
static void
|
||||
png_default_flush(png_structp png_ptr)
|
||||
{
|
||||
FILE *io_ptr;
|
||||
io_ptr = (FILE *)CVT_PTR((png_ptr->io_ptr));
|
||||
if (io_ptr != NULL)
|
||||
fflush(io_ptr);
|
||||
}
|
||||
#endif
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
/* This is the function which does the actual writing of data. If you are
|
||||
not writing to a standard C stream, you should create a replacement
|
||||
write_data function and use it at run time with png_set_write_fn(), rather
|
||||
than changing the library. */
|
||||
#ifndef USE_FAR_KEYWORD
|
||||
static void
|
||||
png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
{
|
||||
png_uint_32 check;
|
||||
|
||||
check = fwrite(data, 1, length, (FILE *)(png_ptr->io_ptr));
|
||||
if (check != length)
|
||||
{
|
||||
png_error(png_ptr, "Write Error");
|
||||
}
|
||||
}
|
||||
#else
|
||||
/* this is the model-independent version. Since the standard I/O library
|
||||
can't handle far buffers in the medium and small models, we have to copy
|
||||
the data.
|
||||
*/
|
||||
|
||||
#define NEAR_BUF_SIZE 1024
|
||||
#define MIN(a,b) (a <= b ? a : b)
|
||||
|
||||
static void
|
||||
png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
{
|
||||
png_uint_32 check;
|
||||
png_byte *near_data; /* Needs to be "png_byte *" instead of "png_bytep" */
|
||||
FILE *io_ptr;
|
||||
|
||||
/* Check if data really is near. If so, use usual code. */
|
||||
near_data = (png_byte *)CVT_PTR_NOCHECK(data);
|
||||
io_ptr = (FILE *)CVT_PTR(png_ptr->io_ptr);
|
||||
if ((png_bytep)near_data == data)
|
||||
{
|
||||
check = fwrite(near_data, 1, length, io_ptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
png_byte buf[NEAR_BUF_SIZE];
|
||||
png_size_t written, remaining, err;
|
||||
check = 0;
|
||||
remaining = length;
|
||||
do
|
||||
{
|
||||
written = MIN(NEAR_BUF_SIZE, remaining);
|
||||
png_memcpy(buf, data, written); /* copy far buffer to near buffer */
|
||||
err = fwrite(buf, 1, written, io_ptr);
|
||||
if (err != written)
|
||||
break;
|
||||
else
|
||||
check += err;
|
||||
data += written;
|
||||
remaining -= written;
|
||||
}
|
||||
while (remaining != 0);
|
||||
}
|
||||
if (check != length)
|
||||
{
|
||||
png_error(png_ptr, "Write Error");
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* This function is called when there is a warning, but the library thinks
|
||||
* it can continue anyway. Replacement functions don't have to do anything
|
||||
* here if you don't want to. In the default configuration, png_ptr is
|
||||
* not used, but it is passed in case it may be useful.
|
||||
*/
|
||||
static void
|
||||
png_default_warning(png_structp png_ptr, png_const_charp message)
|
||||
{
|
||||
PNG_CONST char *name = "UNKNOWN (ERROR!)";
|
||||
if (png_ptr != NULL && png_ptr->error_ptr != NULL)
|
||||
name = png_ptr->error_ptr;
|
||||
fprintf(STDERR, "%s: libpng warning: %s\n", name, message);
|
||||
}
|
||||
|
||||
/* This is the default error handling function. Note that replacements for
|
||||
* this function MUST NOT RETURN, or the program will likely crash. This
|
||||
* function is used by default, or if the program supplies NULL for the
|
||||
* error function pointer in png_set_error_fn().
|
||||
*/
|
||||
static void
|
||||
png_default_error(png_structp png_ptr, png_const_charp message)
|
||||
{
|
||||
png_default_warning(png_ptr, message);
|
||||
/* We can return because png_error calls the default handler which is
|
||||
* actually ok in this case. */
|
||||
}
|
||||
#endif
|
||||
/* END of code to validate stdio-free compilation */
|
||||
|
||||
/* Test one file */
|
||||
int test(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
{
|
||||
FILE *fpin, *fpout;
|
||||
png_structp read_ptr;
|
||||
png_structp write_ptr;
|
||||
png_infop info_ptr;
|
||||
png_infop end_info;
|
||||
png_structp read_ptr, write_ptr;
|
||||
png_infop read_info_ptr, write_info_ptr, end_info_ptr;
|
||||
png_bytep row_buf;
|
||||
png_byte *near_row_buf;
|
||||
png_uint_32 rowbytes;
|
||||
png_uint_32 y;
|
||||
int channels, num_pass, pass;
|
||||
png_uint_32 width, height;
|
||||
int num_pass, pass;
|
||||
int bit_depth, color_type;
|
||||
#ifdef USE_FAR_KEYWORD
|
||||
jmp_buf jmpbuf;
|
||||
#endif
|
||||
|
||||
char inbuf[256], outbuf[256];
|
||||
|
||||
row_buf = (png_bytep)NULL;
|
||||
near_row_buf = (png_byte *)NULL;
|
||||
|
||||
fprintf(STDERR, "Testing libpng version %s\n", PNG_LIBPNG_VER_STRING);
|
||||
|
||||
if (strcmp(png_libpng_ver, PNG_LIBPNG_VER_STRING))
|
||||
{
|
||||
fprintf(STDERR,
|
||||
"Warning: versions are different between png.h and png.c\n");
|
||||
fprintf(STDERR, " png.h version: %s\n", PNG_LIBPNG_VER_STRING);
|
||||
fprintf(STDERR, " png.c version: %s\n\n", png_libpng_ver);
|
||||
}
|
||||
|
||||
if (argc > 1)
|
||||
inname = argv[1];
|
||||
|
||||
if (argc > 2)
|
||||
outname = argv[2];
|
||||
|
||||
if (argc > 3)
|
||||
{
|
||||
fprintf(stderr, "usage: %s [infile.png] [outfile.png]\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
fpin = fopen(inname, "rb");
|
||||
if (!fpin)
|
||||
if ((fpin = fopen(inname, "rb")) == NULL)
|
||||
{
|
||||
fprintf(STDERR, "Could not find input file %s\n", inname);
|
||||
return 1;
|
||||
}
|
||||
|
||||
fpout = fopen(outname, "wb");
|
||||
if (!fpout)
|
||||
if ((fpout = fopen(outname, "wb")) == NULL)
|
||||
{
|
||||
fprintf(STDERR, "Could not open output file %s\n", outname);
|
||||
fclose(fpin);
|
||||
return 1;
|
||||
}
|
||||
|
||||
read_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, (void *)NULL,
|
||||
(png_error_ptr)NULL, (png_error_ptr)NULL);
|
||||
write_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, (void *)NULL,
|
||||
png_debug(0, "Allocating read and write structures\n");
|
||||
read_ptr = png_create_read_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);
|
||||
#if defined(PNG_NO_STDIO)
|
||||
png_set_error_fn(read_ptr, (png_voidp)inname, png_default_error, png_default_warning);
|
||||
#endif
|
||||
write_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, (png_voidp)NULL,
|
||||
(png_error_ptr)NULL, (png_error_ptr)NULL);
|
||||
#if defined(PNG_NO_STDIO)
|
||||
png_set_error_fn(write_ptr, (png_voidp)inname, png_default_error, png_default_warning);
|
||||
#endif
|
||||
png_debug(0, "Allocating read_info, write_info and end_info structures\n");
|
||||
read_info_ptr = png_create_info_struct(read_ptr);
|
||||
write_info_ptr = png_create_info_struct(read_ptr);
|
||||
end_info_ptr = png_create_info_struct(read_ptr);
|
||||
|
||||
png_debug(0, "Setting jmpbuf for read struct\n");
|
||||
#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);
|
||||
png_destroy_write_struct(&write_ptr, (png_infopp)NULL);
|
||||
fprintf(STDERR, "%s -> %s: libpng read error\n", inname, outname);
|
||||
png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr);
|
||||
png_destroy_write_struct(&write_ptr, &write_info_ptr);
|
||||
fclose(fpin);
|
||||
fclose(fpout);
|
||||
return 1;
|
||||
}
|
||||
|
||||
png_debug(0, "Setting jmpbuf for write struct\n");
|
||||
#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);
|
||||
png_destroy_write_struct(&write_ptr, (png_infopp)NULL);
|
||||
fprintf(STDERR, "%s -> %s: libpng write error\n", inname, outname);
|
||||
png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr);
|
||||
png_destroy_write_struct(&write_ptr, &write_info_ptr);
|
||||
fclose(fpin);
|
||||
fclose(fpout);
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifdef USE_FAR_KEYWORD
|
||||
png_memcpy(write_ptr->jmpbuf,jmpbuf,sizeof(jmp_buf));
|
||||
#endif
|
||||
png_debug(0, "Initializing input and output streams\n");
|
||||
#if !defined(PNG_NO_STDIO)
|
||||
png_init_io(read_ptr, fpin);
|
||||
png_init_io(write_ptr, fpout);
|
||||
#else
|
||||
png_set_read_fn(read_ptr, (png_voidp)fpin, png_default_read_data);
|
||||
png_set_write_fn(write_ptr, (png_voidp)fpout, png_default_write_data,
|
||||
#if defined(PNG_WRITE_FLUSH_SUPPORTED)
|
||||
png_default_flush);
|
||||
#else
|
||||
NULL);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
png_read_info(read_ptr, info_ptr);
|
||||
png_write_info(write_ptr, info_ptr);
|
||||
png_debug(0, "Reading info struct\n");
|
||||
png_read_info(read_ptr, read_info_ptr);
|
||||
|
||||
if ((info_ptr->color_type & PNG_COLOR_TYPE_PALETTE)==PNG_COLOR_TYPE_PALETTE)
|
||||
channels = 1;
|
||||
else
|
||||
channels = 3;
|
||||
if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
|
||||
channels++;
|
||||
png_debug(0, "Transferring info struct\n");
|
||||
{
|
||||
int interlace_type, compression_type, filter_type;
|
||||
|
||||
rowbytes = ((info_ptr->width * info_ptr->bit_depth * channels + 7) >> 3);
|
||||
near_row_buf = (png_byte *)malloc((size_t)rowbytes);
|
||||
row_buf = (png_bytep)near_row_buf;
|
||||
if (!row_buf)
|
||||
if (png_get_IHDR(read_ptr, read_info_ptr, &width, &height, &bit_depth,
|
||||
&color_type, &interlace_type, &compression_type, &filter_type))
|
||||
{
|
||||
png_set_IHDR(write_ptr, write_info_ptr, width, height, bit_depth,
|
||||
color_type, interlace_type, compression_type, filter_type);
|
||||
}
|
||||
}
|
||||
#if defined(PNG_READ_bKGD_SUPPORTED) && defined(PNG_WRITE_bKGD_SUPPORTED)
|
||||
{
|
||||
png_color_16p background;
|
||||
|
||||
if (png_get_bKGD(read_ptr, read_info_ptr, &background))
|
||||
{
|
||||
png_set_bKGD(write_ptr, write_info_ptr, background);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if defined(PNG_READ_cHRM_SUPPORTED) && defined(PNG_WRITE_cHRM_SUPPORTED)
|
||||
{
|
||||
double white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
|
||||
|
||||
if (png_get_cHRM(read_ptr, read_info_ptr, &white_x, &white_y, &red_x,
|
||||
&red_y, &green_x, &green_y, &blue_x, &blue_y))
|
||||
{
|
||||
png_set_cHRM(write_ptr, write_info_ptr, white_x, white_y, red_x,
|
||||
red_y, green_x, green_y, blue_x, blue_y);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if defined(PNG_READ_gAMA_SUPPORTED) && defined(PNG_WRITE_gAMA_SUPPORTED)
|
||||
{
|
||||
double gamma;
|
||||
|
||||
if (png_get_gAMA(read_ptr, read_info_ptr, &gamma))
|
||||
{
|
||||
png_set_gAMA(write_ptr, write_info_ptr, gamma);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if defined(PNG_READ_sRGB_SUPPORTED) && defined(PNG_WRITE_sRGB_SUPPORTED)
|
||||
{
|
||||
png_byte intent;
|
||||
|
||||
if (png_get_sRGB(read_ptr, read_info_ptr, &intent))
|
||||
{
|
||||
png_set_sRGB(write_ptr, write_info_ptr, intent);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if defined(PNG_READ_hIST_SUPPORTED) && defined(PNG_WRITE_hIST_SUPPORTED)
|
||||
{
|
||||
png_uint_16p hist;
|
||||
|
||||
if (png_get_hIST(read_ptr, read_info_ptr, &hist))
|
||||
{
|
||||
png_set_hIST(write_ptr, write_info_ptr, hist);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if defined(PNG_READ_oFFs_SUPPORTED) && defined(PNG_WRITE_oFFs_SUPPORTED)
|
||||
{
|
||||
png_uint_32 offset_x, offset_y;
|
||||
int unit_type;
|
||||
|
||||
if (png_get_oFFs(read_ptr, read_info_ptr,&offset_x,&offset_y,&unit_type))
|
||||
{
|
||||
png_set_oFFs(write_ptr, write_info_ptr, offset_x, offset_y, unit_type);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if defined(PNG_READ_pCAL_SUPPORTED) && defined(PNG_WRITE_pCAL_SUPPORTED)
|
||||
{
|
||||
png_charp purpose, units;
|
||||
png_charpp params;
|
||||
png_int_32 X0, X1;
|
||||
int type, nparams;
|
||||
|
||||
if (png_get_pCAL(read_ptr, read_info_ptr, &purpose, &X0, &X1, &type,
|
||||
&nparams, &units, ¶ms))
|
||||
{
|
||||
png_set_pCAL(write_ptr, write_info_ptr, purpose, X0, X1, type,
|
||||
nparams, units, params);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if defined(PNG_READ_pHYs_SUPPORTED) && defined(PNG_WRITE_pHYs_SUPPORTED)
|
||||
{
|
||||
png_uint_32 res_x, res_y;
|
||||
int unit_type;
|
||||
|
||||
if (png_get_pHYs(read_ptr, read_info_ptr, &res_x, &res_y, &unit_type))
|
||||
{
|
||||
png_set_pHYs(write_ptr, write_info_ptr, res_x, res_y, unit_type);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
{
|
||||
png_colorp palette;
|
||||
int num_palette;
|
||||
|
||||
if (png_get_PLTE(read_ptr, read_info_ptr, &palette, &num_palette))
|
||||
{
|
||||
png_set_PLTE(write_ptr, write_info_ptr, palette, num_palette);
|
||||
}
|
||||
}
|
||||
#if defined(PNG_READ_sBIT_SUPPORTED) && defined(PNG_WRITE_sBIT_SUPPORTED)
|
||||
{
|
||||
png_color_8p sig_bit;
|
||||
|
||||
if (png_get_sBIT(read_ptr, read_info_ptr, &sig_bit))
|
||||
{
|
||||
png_set_sBIT(write_ptr, write_info_ptr, sig_bit);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if (defined(PNG_READ_tEXt_SUPPORTED) && defined(PNG_WRITE_tEXt_SUPPORTED)) || \
|
||||
(defined(PNG_READ_zTXt_SUPPORTED) && defined(PNG_WRITE_zTXt_SUPPORTED))
|
||||
{
|
||||
png_textp text_ptr;
|
||||
int num_text;
|
||||
|
||||
if (png_get_text(read_ptr, read_info_ptr, &text_ptr, &num_text) > 0)
|
||||
{
|
||||
png_debug1(0, "Handling %d tEXt/zTXt chunks\n", num_text);
|
||||
png_set_text(write_ptr, write_info_ptr, text_ptr, num_text);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if defined(PNG_READ_tIME_SUPPORTED) && defined(PNG_WRITE_tIME_SUPPORTED)
|
||||
{
|
||||
png_timep mod_time;
|
||||
|
||||
if (png_get_tIME(read_ptr, read_info_ptr, &mod_time))
|
||||
{
|
||||
png_set_tIME(write_ptr, write_info_ptr, mod_time);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if defined(PNG_READ_tRNS_SUPPORTED) && defined(PNG_WRITE_tRNS_SUPPORTED)
|
||||
{
|
||||
png_bytep trans;
|
||||
int num_trans;
|
||||
png_color_16p trans_values;
|
||||
|
||||
if (png_get_tRNS(read_ptr, read_info_ptr, &trans, &num_trans,
|
||||
&trans_values))
|
||||
{
|
||||
png_set_tRNS(write_ptr, write_info_ptr, trans, num_trans,
|
||||
trans_values);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
png_debug(0, "\nWriting info struct\n");
|
||||
png_write_info(write_ptr, write_info_ptr);
|
||||
|
||||
row_buf = (png_bytep)png_malloc(read_ptr,
|
||||
png_get_rowbytes(read_ptr, read_info_ptr));
|
||||
if (row_buf == NULL)
|
||||
{
|
||||
fprintf(STDERR, "No memory to allocate row buffer\n");
|
||||
png_destroy_read_struct(&read_ptr, &info_ptr, &end_info);
|
||||
png_destroy_write_struct(&write_ptr, (png_infopp)NULL);
|
||||
png_destroy_read_struct(&read_ptr, &read_info_ptr, (png_infopp)NULL);
|
||||
png_destroy_write_struct(&write_ptr, &write_info_ptr);
|
||||
fclose(fpin);
|
||||
fclose(fpout);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (info_ptr->interlace_type)
|
||||
{
|
||||
num_pass = png_set_interlace_handling(read_ptr);
|
||||
num_pass = png_set_interlace_handling(write_ptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
num_pass = 1;
|
||||
}
|
||||
num_pass = png_set_interlace_handling(read_ptr);
|
||||
png_set_interlace_handling(write_ptr);
|
||||
|
||||
for (pass = 0; pass < num_pass; pass++)
|
||||
{
|
||||
for (y = 0; y < info_ptr->height; y++)
|
||||
for (y = 0; y < height; y++)
|
||||
{
|
||||
#ifdef TESTING
|
||||
fprintf(STDERR, "Processing line #%ld\n", y);
|
||||
#endif
|
||||
png_read_rows(read_ptr, (png_bytepp)&row_buf, (png_bytepp)0, 1);
|
||||
png_read_rows(read_ptr, (png_bytepp)&row_buf, (png_bytepp)NULL, 1);
|
||||
png_write_rows(write_ptr, (png_bytepp)&row_buf, 1);
|
||||
}
|
||||
}
|
||||
|
||||
png_read_end(read_ptr, end_info);
|
||||
png_write_end(write_ptr, end_info);
|
||||
png_debug(0, "Reading and writing end_info data\n");
|
||||
png_read_end(read_ptr, end_info_ptr);
|
||||
png_write_end(write_ptr, end_info_ptr);
|
||||
|
||||
png_destroy_read_struct(&read_ptr, &info_ptr, &end_info);
|
||||
png_destroy_write_struct(&write_ptr, (png_infopp)NULL);
|
||||
png_debug(0, "Destroying data structs\n");
|
||||
png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr);
|
||||
png_destroy_write_struct(&write_ptr, &write_info_ptr);
|
||||
|
||||
fclose(fpin);
|
||||
fclose(fpout);
|
||||
|
||||
free((void *)near_row_buf);
|
||||
png_free(read_ptr, row_buf);
|
||||
|
||||
fpin = fopen(inname, "rb");
|
||||
|
||||
if (!fpin)
|
||||
png_debug(0, "Opening files for comparison\n");
|
||||
if ((fpin = fopen(inname, "rb")) == NULL)
|
||||
{
|
||||
fprintf(STDERR, "Could not find file %s\n", inname);
|
||||
return 1;
|
||||
}
|
||||
|
||||
fpout = fopen(outname, "rb");
|
||||
if (!fpout)
|
||||
if ((fpout = fopen(outname, "rb")) == NULL)
|
||||
{
|
||||
fprintf(STDERR, "Could not find file %s\n", outname);
|
||||
fclose(fpin);
|
||||
@@ -186,10 +539,10 @@ int main(int argc, char *argv[])
|
||||
|
||||
while (1)
|
||||
{
|
||||
int num_in, num_out;
|
||||
png_size_t 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)
|
||||
{
|
||||
@@ -203,7 +556,7 @@ int main(int argc, char *argv[])
|
||||
if (!num_in)
|
||||
break;
|
||||
|
||||
if (memcmp(inbuf, outbuf, num_in))
|
||||
if (png_memcmp(inbuf, outbuf, num_in))
|
||||
{
|
||||
fprintf(STDERR, "Files %s and %s are different\n", inname, outname);
|
||||
fclose(fpin);
|
||||
@@ -214,8 +567,73 @@ int main(int argc, char *argv[])
|
||||
|
||||
fclose(fpin);
|
||||
fclose(fpout);
|
||||
fprintf(STDERR, "libpng passes test\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* input and output filenames */
|
||||
#ifdef RISCOS
|
||||
PNG_CONST char *inname = "pngtest_png";
|
||||
PNG_CONST char *outname = "pngout_png";
|
||||
#else
|
||||
PNG_CONST char *inname = "pngtest.png";
|
||||
PNG_CONST char *outname = "pngout.png";
|
||||
#endif
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int multiple = 0;
|
||||
int ierror = 0;
|
||||
|
||||
fprintf(STDERR, "Testing libpng version %s\n", PNG_LIBPNG_VER_STRING);
|
||||
|
||||
if (strcmp(png_libpng_ver, PNG_LIBPNG_VER_STRING))
|
||||
{
|
||||
fprintf(STDERR,
|
||||
"Warning: versions are different between png.h and png.c\n");
|
||||
fprintf(STDERR, " png.h version: %s\n", PNG_LIBPNG_VER_STRING);
|
||||
fprintf(STDERR, " png.c version: %s\n\n", png_libpng_ver);
|
||||
++ierror;
|
||||
}
|
||||
|
||||
if (argc > 1)
|
||||
{
|
||||
if (strcmp(argv[1], "-m") == 0)
|
||||
multiple = 1;
|
||||
else
|
||||
inname = argv[1];
|
||||
}
|
||||
|
||||
if (!multiple && argc == 3)
|
||||
outname = argv[2];
|
||||
|
||||
if (!multiple && argc > 3 || multiple && argc < 2)
|
||||
{
|
||||
fprintf(STDERR, "usage: %s [infile.png] [outfile.png]\n\t%s -m {infile.png}\n",
|
||||
argv[0], argv[0]);
|
||||
fprintf(STDERR, " reads/writes one PNG file (without -m) or multiple files (-m)\n");
|
||||
fprintf(STDERR, " with -m %s is used as a temporary file\n", outname);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (multiple)
|
||||
{
|
||||
int i;
|
||||
for (i=2; i<argc; ++i)
|
||||
{
|
||||
fprintf(STDERR, "Testing %s:\n",argv[i]);
|
||||
ierror += test(argv[i], outname);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ierror += test(inname, outname);
|
||||
}
|
||||
|
||||
if (ierror == 0)
|
||||
fprintf(STDERR, "libpng passes test\n");
|
||||
else
|
||||
fprintf(STDERR, "libpng FAILS test\n");
|
||||
return ierror != 0;
|
||||
}
|
||||
|
||||
BIN
pngtest.png
BIN
pngtest.png
Binary file not shown.
|
Before Width: | Height: | Size: 8.7 KiB After Width: | Height: | Size: 8.4 KiB |
27
pngtodo.txt
27
pngtodo.txt
@@ -1,27 +0,0 @@
|
||||
pngtodo.txt - list of things to do for libpng
|
||||
|
||||
for 0.9
|
||||
improved dithering
|
||||
final bug fixes
|
||||
cHRM transformation
|
||||
better documentation
|
||||
|
||||
after 1.0
|
||||
overlaying one image on top of another
|
||||
make pull reader use push reader internally to reduce code, and
|
||||
increase amount of image read in an error situation
|
||||
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).
|
||||
pull writer
|
||||
better dithering
|
||||
keep up with public chunks
|
||||
other compression libraries
|
||||
more exotic interlace handling
|
||||
better filtering (counting huffman bits? filter type inertia?)
|
||||
C++ wrapper
|
||||
other languages (pascal, for one)
|
||||
comments of > 64K
|
||||
|
||||
513
pngtrans.c
513
pngtrans.c
@@ -1,12 +1,13 @@
|
||||
|
||||
/* pngtrans.c - transforms the data in a row
|
||||
routines used by both readers and writers
|
||||
|
||||
libpng 1.0 beta 3 - version 0.89
|
||||
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
|
||||
*/
|
||||
/* pngtrans.c - transforms the data in a row (used by both readers and writers)
|
||||
*
|
||||
* libpng 0.97
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* January 7, 1998
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
#include "png.h"
|
||||
@@ -16,6 +17,7 @@
|
||||
void
|
||||
png_set_bgr(png_structp png_ptr)
|
||||
{
|
||||
png_debug(1, "in png_set_bgr\n");
|
||||
png_ptr->transformations |= PNG_BGR;
|
||||
}
|
||||
#endif
|
||||
@@ -25,6 +27,7 @@ png_set_bgr(png_structp png_ptr)
|
||||
void
|
||||
png_set_swap(png_structp png_ptr)
|
||||
{
|
||||
png_debug(1, "in png_set_swap\n");
|
||||
if (png_ptr->bit_depth == 16)
|
||||
png_ptr->transformations |= PNG_SWAP_BYTES;
|
||||
}
|
||||
@@ -35,6 +38,7 @@ png_set_swap(png_structp png_ptr)
|
||||
void
|
||||
png_set_packing(png_structp png_ptr)
|
||||
{
|
||||
png_debug(1, "in png_set_packing\n");
|
||||
if (png_ptr->bit_depth < 8)
|
||||
{
|
||||
png_ptr->transformations |= PNG_PACK;
|
||||
@@ -43,10 +47,22 @@ png_set_packing(png_structp png_ptr)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)
|
||||
/* turn on packed pixel swapping */
|
||||
void
|
||||
png_set_packswap(png_structp png_ptr)
|
||||
{
|
||||
png_debug(1, "in png_set_packswap\n");
|
||||
if (png_ptr->bit_depth < 8)
|
||||
png_ptr->transformations |= PNG_PACKSWAP;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
|
||||
void
|
||||
png_set_shift(png_structp png_ptr, png_color_8p true_bits)
|
||||
{
|
||||
png_debug(1, "in png_set_shift\n");
|
||||
png_ptr->transformations |= PNG_SHIFT;
|
||||
png_ptr->shift = *true_bits;
|
||||
}
|
||||
@@ -56,6 +72,7 @@ png_set_shift(png_structp png_ptr, png_color_8p true_bits)
|
||||
int
|
||||
png_set_interlace_handling(png_structp png_ptr)
|
||||
{
|
||||
png_debug(1, "in png_set_interlace handling\n");
|
||||
if (png_ptr->interlaced)
|
||||
{
|
||||
png_ptr->transformations |= PNG_INTERLACE;
|
||||
@@ -67,9 +84,15 @@ png_set_interlace_handling(png_structp png_ptr)
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
|
||||
/* Add a filler byte on read, or remove a filler or alpha byte on write.
|
||||
* The filler type has changed in v0.95 to allow future 2-byte fillers
|
||||
* for 48-bit input data, as well as avoiding problems with some compilers
|
||||
* which don't like bytes as parameters.
|
||||
*/
|
||||
void
|
||||
png_set_filler(png_structp png_ptr, int filler, int filler_loc)
|
||||
png_set_filler(png_structp png_ptr, png_uint_32 filler, int filler_loc)
|
||||
{
|
||||
png_debug(1, "in png_set_filler\n");
|
||||
png_ptr->transformations |= PNG_FILLER;
|
||||
png_ptr->filler = (png_byte)filler;
|
||||
if (filler_loc == PNG_FILLER_AFTER)
|
||||
@@ -77,22 +100,21 @@ png_set_filler(png_structp png_ptr, int filler, int filler_loc)
|
||||
else
|
||||
png_ptr->flags &= ~PNG_FLAG_FILLER_AFTER;
|
||||
|
||||
if (png_ptr->color_type == PNG_COLOR_TYPE_RGB &&
|
||||
png_ptr->bit_depth == 8)
|
||||
/* This should probably go in the "do_filler" routine */
|
||||
if (png_ptr->color_type == PNG_COLOR_TYPE_RGB && png_ptr->bit_depth == 8)
|
||||
{
|
||||
png_ptr->usr_channels = 4;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* old functions kept around for compatability purposes */
|
||||
#if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \
|
||||
defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
|
||||
void
|
||||
png_set_rgbx(png_structp png_ptr)
|
||||
png_set_swap_alpha(png_structp png_ptr)
|
||||
{
|
||||
png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER);
|
||||
}
|
||||
|
||||
void
|
||||
png_set_xrgb(png_structp png_ptr)
|
||||
{
|
||||
png_set_filler(png_ptr, 0xff, PNG_FILLER_BEFORE);
|
||||
png_debug(1, "in png_set_swap_alpha\n");
|
||||
png_ptr->transformations |= PNG_SWAP_ALPHA;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -100,6 +122,7 @@ png_set_xrgb(png_structp png_ptr)
|
||||
void
|
||||
png_set_invert_mono(png_structp png_ptr)
|
||||
{
|
||||
png_debug(1, "in png_set_invert_mono\n");
|
||||
png_ptr->transformations |= PNG_INVERT_MONO;
|
||||
}
|
||||
|
||||
@@ -107,15 +130,17 @@ png_set_invert_mono(png_structp png_ptr)
|
||||
void
|
||||
png_do_invert(png_row_infop row_info, png_bytep row)
|
||||
{
|
||||
if (row && row_info && row_info->bit_depth == 1 &&
|
||||
row_info->color_type == PNG_COLOR_TYPE_GRAY)
|
||||
png_debug(1, "in png_do_invert\n");
|
||||
if (row_info->bit_depth == 1 &&
|
||||
#if defined(PNG_USELESS_TESTS_SUPPORTED)
|
||||
row != NULL && row_info != NULL &&
|
||||
#endif
|
||||
row_info->color_type == PNG_COLOR_TYPE_GRAY)
|
||||
{
|
||||
png_bytep rp;
|
||||
png_uint_32 i;
|
||||
|
||||
for (i = 0, rp = row;
|
||||
i < row_info->rowbytes;
|
||||
i++, rp++)
|
||||
for (i = 0, rp = row; i < row_info->rowbytes; i++, rp++)
|
||||
{
|
||||
*rp = (png_byte)(~(*rp));
|
||||
}
|
||||
@@ -128,7 +153,12 @@ png_do_invert(png_row_infop row_info, png_bytep row)
|
||||
void
|
||||
png_do_swap(png_row_infop row_info, png_bytep row)
|
||||
{
|
||||
if (row && row_info && row_info->bit_depth == 16)
|
||||
png_debug(1, "in png_do_swap\n");
|
||||
if (
|
||||
#if defined(PNG_USELESS_TESTS_SUPPORTED)
|
||||
row != NULL && row_info != NULL &&
|
||||
#endif
|
||||
row_info->bit_depth == 16)
|
||||
{
|
||||
png_bytep rp;
|
||||
png_byte t;
|
||||
@@ -146,80 +176,391 @@ png_do_swap(png_row_infop row_info, png_bytep row)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
|
||||
/* swaps red and blue */
|
||||
#if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)
|
||||
static png_byte onebppswaptable[256] = {
|
||||
0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0,
|
||||
0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
|
||||
0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8,
|
||||
0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8,
|
||||
0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4,
|
||||
0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,
|
||||
0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC,
|
||||
0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC,
|
||||
0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2,
|
||||
0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2,
|
||||
0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA,
|
||||
0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,
|
||||
0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6,
|
||||
0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6,
|
||||
0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE,
|
||||
0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE,
|
||||
0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1,
|
||||
0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,
|
||||
0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9,
|
||||
0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9,
|
||||
0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5,
|
||||
0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5,
|
||||
0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED,
|
||||
0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,
|
||||
0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3,
|
||||
0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3,
|
||||
0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB,
|
||||
0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB,
|
||||
0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7,
|
||||
0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
|
||||
0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF,
|
||||
0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
|
||||
};
|
||||
|
||||
static png_byte twobppswaptable[256] = {
|
||||
0x00, 0x40, 0x80, 0xC0, 0x10, 0x50, 0x90, 0xD0,
|
||||
0x20, 0x60, 0xA0, 0xE0, 0x30, 0x70, 0xB0, 0xF0,
|
||||
0x04, 0x44, 0x84, 0xC4, 0x14, 0x54, 0x94, 0xD4,
|
||||
0x24, 0x64, 0xA4, 0xE4, 0x34, 0x74, 0xB4, 0xF4,
|
||||
0x08, 0x48, 0x88, 0xC8, 0x18, 0x58, 0x98, 0xD8,
|
||||
0x28, 0x68, 0xA8, 0xE8, 0x38, 0x78, 0xB8, 0xF8,
|
||||
0x0C, 0x4C, 0x8C, 0xCC, 0x1C, 0x5C, 0x9C, 0xDC,
|
||||
0x2C, 0x6C, 0xAC, 0xEC, 0x3C, 0x7C, 0xBC, 0xFC,
|
||||
0x01, 0x41, 0x81, 0xC1, 0x11, 0x51, 0x91, 0xD1,
|
||||
0x21, 0x61, 0xA1, 0xE1, 0x31, 0x71, 0xB1, 0xF1,
|
||||
0x05, 0x45, 0x85, 0xC5, 0x15, 0x55, 0x95, 0xD5,
|
||||
0x25, 0x65, 0xA5, 0xE5, 0x35, 0x75, 0xB5, 0xF5,
|
||||
0x09, 0x49, 0x89, 0xC9, 0x19, 0x59, 0x99, 0xD9,
|
||||
0x29, 0x69, 0xA9, 0xE9, 0x39, 0x79, 0xB9, 0xF9,
|
||||
0x0D, 0x4D, 0x8D, 0xCD, 0x1D, 0x5D, 0x9D, 0xDD,
|
||||
0x2D, 0x6D, 0xAD, 0xED, 0x3D, 0x7D, 0xBD, 0xFD,
|
||||
0x02, 0x42, 0x82, 0xC2, 0x12, 0x52, 0x92, 0xD2,
|
||||
0x22, 0x62, 0xA2, 0xE2, 0x32, 0x72, 0xB2, 0xF2,
|
||||
0x06, 0x46, 0x86, 0xC6, 0x16, 0x56, 0x96, 0xD6,
|
||||
0x26, 0x66, 0xA6, 0xE6, 0x36, 0x76, 0xB6, 0xF6,
|
||||
0x0A, 0x4A, 0x8A, 0xCA, 0x1A, 0x5A, 0x9A, 0xDA,
|
||||
0x2A, 0x6A, 0xAA, 0xEA, 0x3A, 0x7A, 0xBA, 0xFA,
|
||||
0x0E, 0x4E, 0x8E, 0xCE, 0x1E, 0x5E, 0x9E, 0xDE,
|
||||
0x2E, 0x6E, 0xAE, 0xEE, 0x3E, 0x7E, 0xBE, 0xFE,
|
||||
0x03, 0x43, 0x83, 0xC3, 0x13, 0x53, 0x93, 0xD3,
|
||||
0x23, 0x63, 0xA3, 0xE3, 0x33, 0x73, 0xB3, 0xF3,
|
||||
0x07, 0x47, 0x87, 0xC7, 0x17, 0x57, 0x97, 0xD7,
|
||||
0x27, 0x67, 0xA7, 0xE7, 0x37, 0x77, 0xB7, 0xF7,
|
||||
0x0B, 0x4B, 0x8B, 0xCB, 0x1B, 0x5B, 0x9B, 0xDB,
|
||||
0x2B, 0x6B, 0xAB, 0xEB, 0x3B, 0x7B, 0xBB, 0xFB,
|
||||
0x0F, 0x4F, 0x8F, 0xCF, 0x1F, 0x5F, 0x9F, 0xDF,
|
||||
0x2F, 0x6F, 0xAF, 0xEF, 0x3F, 0x7F, 0xBF, 0xFF
|
||||
};
|
||||
|
||||
static png_byte fourbppswaptable[256] = {
|
||||
0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70,
|
||||
0x80, 0x90, 0xA0, 0xB0, 0xC0, 0xD0, 0xE0, 0xF0,
|
||||
0x01, 0x11, 0x21, 0x31, 0x41, 0x51, 0x61, 0x71,
|
||||
0x81, 0x91, 0xA1, 0xB1, 0xC1, 0xD1, 0xE1, 0xF1,
|
||||
0x02, 0x12, 0x22, 0x32, 0x42, 0x52, 0x62, 0x72,
|
||||
0x82, 0x92, 0xA2, 0xB2, 0xC2, 0xD2, 0xE2, 0xF2,
|
||||
0x03, 0x13, 0x23, 0x33, 0x43, 0x53, 0x63, 0x73,
|
||||
0x83, 0x93, 0xA3, 0xB3, 0xC3, 0xD3, 0xE3, 0xF3,
|
||||
0x04, 0x14, 0x24, 0x34, 0x44, 0x54, 0x64, 0x74,
|
||||
0x84, 0x94, 0xA4, 0xB4, 0xC4, 0xD4, 0xE4, 0xF4,
|
||||
0x05, 0x15, 0x25, 0x35, 0x45, 0x55, 0x65, 0x75,
|
||||
0x85, 0x95, 0xA5, 0xB5, 0xC5, 0xD5, 0xE5, 0xF5,
|
||||
0x06, 0x16, 0x26, 0x36, 0x46, 0x56, 0x66, 0x76,
|
||||
0x86, 0x96, 0xA6, 0xB6, 0xC6, 0xD6, 0xE6, 0xF6,
|
||||
0x07, 0x17, 0x27, 0x37, 0x47, 0x57, 0x67, 0x77,
|
||||
0x87, 0x97, 0xA7, 0xB7, 0xC7, 0xD7, 0xE7, 0xF7,
|
||||
0x08, 0x18, 0x28, 0x38, 0x48, 0x58, 0x68, 0x78,
|
||||
0x88, 0x98, 0xA8, 0xB8, 0xC8, 0xD8, 0xE8, 0xF8,
|
||||
0x09, 0x19, 0x29, 0x39, 0x49, 0x59, 0x69, 0x79,
|
||||
0x89, 0x99, 0xA9, 0xB9, 0xC9, 0xD9, 0xE9, 0xF9,
|
||||
0x0A, 0x1A, 0x2A, 0x3A, 0x4A, 0x5A, 0x6A, 0x7A,
|
||||
0x8A, 0x9A, 0xAA, 0xBA, 0xCA, 0xDA, 0xEA, 0xFA,
|
||||
0x0B, 0x1B, 0x2B, 0x3B, 0x4B, 0x5B, 0x6B, 0x7B,
|
||||
0x8B, 0x9B, 0xAB, 0xBB, 0xCB, 0xDB, 0xEB, 0xFB,
|
||||
0x0C, 0x1C, 0x2C, 0x3C, 0x4C, 0x5C, 0x6C, 0x7C,
|
||||
0x8C, 0x9C, 0xAC, 0xBC, 0xCC, 0xDC, 0xEC, 0xFC,
|
||||
0x0D, 0x1D, 0x2D, 0x3D, 0x4D, 0x5D, 0x6D, 0x7D,
|
||||
0x8D, 0x9D, 0xAD, 0xBD, 0xCD, 0xDD, 0xED, 0xFD,
|
||||
0x0E, 0x1E, 0x2E, 0x3E, 0x4E, 0x5E, 0x6E, 0x7E,
|
||||
0x8E, 0x9E, 0xAE, 0xBE, 0xCE, 0xDE, 0xEE, 0xFE,
|
||||
0x0F, 0x1F, 0x2F, 0x3F, 0x4F, 0x5F, 0x6F, 0x7F,
|
||||
0x8F, 0x9F, 0xAF, 0xBF, 0xCF, 0xDF, 0xEF, 0xFF
|
||||
};
|
||||
|
||||
/* swaps pixel packing order within bytes */
|
||||
void
|
||||
png_do_bgr(png_row_infop row_info, png_bytep row)
|
||||
png_do_packswap(png_row_infop row_info, png_bytep row)
|
||||
{
|
||||
if (row && row_info && (row_info->color_type & 2))
|
||||
png_debug(1, "in png_do_packswap\n");
|
||||
if (
|
||||
#if defined(PNG_USELESS_TESTS_SUPPORTED)
|
||||
row != NULL && row_info != NULL
|
||||
#endif
|
||||
row_info->bit_depth < 8)
|
||||
{
|
||||
if (row_info->color_type == 2 && row_info->bit_depth == 8)
|
||||
{
|
||||
png_bytep rp;
|
||||
png_byte t;
|
||||
png_uint_32 i;
|
||||
png_bytep rp, end, table;
|
||||
|
||||
for (i = 0, rp = row;
|
||||
i < row_info->width;
|
||||
i++, rp += 3)
|
||||
end = row + row_info->rowbytes;
|
||||
|
||||
if (row_info->bit_depth == 1)
|
||||
table = onebppswaptable;
|
||||
else if (row_info->bit_depth == 2)
|
||||
table = twobppswaptable;
|
||||
else if (row_info->bit_depth == 4)
|
||||
table = fourbppswaptable;
|
||||
else
|
||||
return;
|
||||
|
||||
for (rp = row; rp < end; rp++)
|
||||
*rp = table[*rp];
|
||||
}
|
||||
}
|
||||
#endif /* PNG_READ_PACKSWAP_SUPPORTED or PNG_WRITE_PACKSWAP_SUPPORTED */
|
||||
|
||||
#if defined(PNG_WRITE_FILLER_SUPPORTED) || \
|
||||
defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
|
||||
/* remove filler or alpha byte(s) */
|
||||
void
|
||||
png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags)
|
||||
{
|
||||
png_debug(1, "in png_do_strip_filler\n");
|
||||
#if defined(PNG_USELESS_TESTS_SUPPORTED)
|
||||
if (row != NULL && row_info != NULL)
|
||||
#endif
|
||||
{
|
||||
/*
|
||||
if (row_info->color_type == PNG_COLOR_TYPE_RGB ||
|
||||
row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
|
||||
*/
|
||||
if (row_info->channels == 4)
|
||||
{
|
||||
if (row_info->bit_depth == 8)
|
||||
{
|
||||
t = *rp;
|
||||
*rp = *(rp + 2);
|
||||
*(rp + 2) = t;
|
||||
/* This converts from RGBX or RGBA to RGB */
|
||||
if (flags & PNG_FLAG_FILLER_AFTER)
|
||||
{
|
||||
png_bytep sp, dp;
|
||||
png_uint_32 i;
|
||||
|
||||
for (i = 1, sp = row + 4, dp = row + 3; i < row_info->width; i++)
|
||||
{
|
||||
*dp++ = *sp++;
|
||||
*dp++ = *sp++;
|
||||
*dp++ = *sp++;
|
||||
sp++;
|
||||
}
|
||||
}
|
||||
/* This converts from XRGB or ARGB to RGB */
|
||||
else
|
||||
{
|
||||
png_bytep sp, dp;
|
||||
png_uint_32 i;
|
||||
|
||||
for (i = 0, sp = row, dp = row; i < row_info->width; i++)
|
||||
{
|
||||
sp++;
|
||||
*dp++ = *sp++;
|
||||
*dp++ = *sp++;
|
||||
*dp++ = *sp++;
|
||||
}
|
||||
}
|
||||
row_info->pixel_depth = 24;
|
||||
row_info->rowbytes = row_info->width * 3;
|
||||
}
|
||||
else /* if (row_info->bit_depth == 16) */
|
||||
{
|
||||
if (flags & PNG_FLAG_FILLER_AFTER)
|
||||
{
|
||||
png_bytep sp, dp;
|
||||
png_uint_32 i;
|
||||
|
||||
/* This converts from RRGGBBXX or RRGGBBAA to RRGGBB */
|
||||
for (i = 1, sp = row + 8, dp = row + 6; i < row_info->width; i++)
|
||||
{
|
||||
/* This could be (although memcpy is probably slower):
|
||||
png_memcpy(dp, sp, 6);
|
||||
sp += 8;
|
||||
dp += 6;
|
||||
*/
|
||||
*dp++ = *sp++;
|
||||
*dp++ = *sp++;
|
||||
*dp++ = *sp++;
|
||||
*dp++ = *sp++;
|
||||
*dp++ = *sp++;
|
||||
*dp++ = *sp++;
|
||||
sp += 2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
png_bytep sp, dp;
|
||||
png_uint_32 i;
|
||||
|
||||
/* This converts from XXRRGGBB or AARRGGBB to RRGGBB */
|
||||
for (i = 0, sp = row + 2, dp = row; i < row_info->width; i++)
|
||||
{
|
||||
/* This could be (although memcpy is probably slower):
|
||||
png_memcpy(dp, sp, 6);
|
||||
sp += 8;
|
||||
dp += 6;
|
||||
*/
|
||||
*dp++ = *sp++;
|
||||
*dp++ = *sp++;
|
||||
*dp++ = *sp++;
|
||||
*dp++ = *sp++;
|
||||
*dp++ = *sp++;
|
||||
*dp++ = *sp++;
|
||||
}
|
||||
}
|
||||
row_info->pixel_depth = 48;
|
||||
row_info->rowbytes = row_info->width * 6;
|
||||
}
|
||||
row_info->channels = 3;
|
||||
}
|
||||
else if (row_info->color_type == 6 && row_info->bit_depth == 8)
|
||||
/*
|
||||
else if (row_info->color_type == PNG_COLOR_TYPE_GRAY ||
|
||||
row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
|
||||
*/
|
||||
else if (row_info->channels == 2)
|
||||
{
|
||||
png_bytep rp;
|
||||
png_byte t;
|
||||
png_uint_32 i;
|
||||
|
||||
for (i = 0, rp = row;
|
||||
i < row_info->width;
|
||||
i++, rp += 4)
|
||||
if (row_info->bit_depth == 8)
|
||||
{
|
||||
t = *rp;
|
||||
*rp = *(rp + 2);
|
||||
*(rp + 2) = t;
|
||||
}
|
||||
}
|
||||
else if (row_info->color_type == 2 && row_info->bit_depth == 16)
|
||||
{
|
||||
png_bytep rp;
|
||||
png_byte t[2];
|
||||
png_uint_32 i;
|
||||
/* This converts from GX or GA to G */
|
||||
if (flags & PNG_FLAG_FILLER_AFTER)
|
||||
{
|
||||
png_bytep sp, dp;
|
||||
png_uint_32 i;
|
||||
|
||||
for (i = 0, rp = row;
|
||||
i < row_info->width;
|
||||
i++, rp += 6)
|
||||
{
|
||||
t[0] = *rp;
|
||||
t[1] = *(rp + 1);
|
||||
*rp = *(rp + 4);
|
||||
*(rp + 1) = *(rp + 5);
|
||||
*(rp + 4) = t[0];
|
||||
*(rp + 5) = t[1];
|
||||
}
|
||||
}
|
||||
else if (row_info->color_type == 6 && row_info->bit_depth == 16)
|
||||
{
|
||||
png_bytep rp;
|
||||
png_byte t[2];
|
||||
png_uint_32 i;
|
||||
for (i = 1, sp = row + 2, dp = row + 1; i < row_info->width; i++)
|
||||
{
|
||||
*dp++ = *sp++;
|
||||
sp++;
|
||||
}
|
||||
}
|
||||
/* This converts from XG or AG to G */
|
||||
else
|
||||
{
|
||||
png_bytep sp, dp;
|
||||
png_uint_32 i;
|
||||
|
||||
for (i = 0, rp = row;
|
||||
i < row_info->width;
|
||||
i++, rp += 8)
|
||||
{
|
||||
t[0] = *rp;
|
||||
t[1] = *(rp + 1);
|
||||
*rp = *(rp + 4);
|
||||
*(rp + 1) = *(rp + 5);
|
||||
*(rp + 4) = t[0];
|
||||
*(rp + 5) = t[1];
|
||||
for (i = 0, sp = row, dp = row; i < row_info->width; i++)
|
||||
{
|
||||
sp++;
|
||||
*dp++ = *sp++;
|
||||
}
|
||||
}
|
||||
row_info->pixel_depth = 8;
|
||||
row_info->rowbytes = row_info->width;
|
||||
}
|
||||
else /* if (row_info->bit_depth == 16) */
|
||||
{
|
||||
if (flags & PNG_FLAG_FILLER_AFTER)
|
||||
{
|
||||
png_bytep sp, dp;
|
||||
png_uint_32 i;
|
||||
|
||||
/* This converts from GGXX or GGAA to GG */
|
||||
for (i = 1, sp = row + 4, dp = row + 2; i < row_info->width; i++)
|
||||
{
|
||||
*dp++ = *sp++;
|
||||
*dp++ = *sp++;
|
||||
sp += 2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
png_bytep sp, dp;
|
||||
png_uint_32 i;
|
||||
|
||||
/* This converts from XXGG or AAGG to GG */
|
||||
for (i = 0, sp = row, dp = row; i < row_info->width; i++)
|
||||
{
|
||||
sp += 2;
|
||||
*dp++ = *sp++;
|
||||
*dp++ = *sp++;
|
||||
}
|
||||
}
|
||||
row_info->pixel_depth = 16;
|
||||
row_info->rowbytes = row_info->width * 2;
|
||||
}
|
||||
row_info->channels = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
|
||||
/* swaps red and blue bytes within a pixel */
|
||||
void
|
||||
png_do_bgr(png_row_infop row_info, png_bytep row)
|
||||
{
|
||||
png_debug(1, "in png_do_bgr\n");
|
||||
if (
|
||||
#if defined(PNG_USELESS_TESTS_SUPPORTED)
|
||||
row != NULL && row_info != NULL &&
|
||||
#endif
|
||||
(row_info->color_type & PNG_COLOR_MASK_COLOR))
|
||||
{
|
||||
if (row_info->bit_depth == 8)
|
||||
{
|
||||
if (row_info->color_type == PNG_COLOR_TYPE_RGB)
|
||||
{
|
||||
png_bytep rp;
|
||||
png_byte save;
|
||||
png_uint_32 i;
|
||||
|
||||
for (i = 0, rp = row; i < row_info->width; i++, rp += 3)
|
||||
{
|
||||
save = *rp;
|
||||
*rp = *(rp + 2);
|
||||
*(rp + 2) = save;
|
||||
}
|
||||
}
|
||||
else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
|
||||
{
|
||||
png_bytep rp;
|
||||
png_byte save;
|
||||
png_uint_32 i;
|
||||
|
||||
for (i = 0, rp = row; i < row_info->width; i++, rp += 4)
|
||||
{
|
||||
save = *rp;
|
||||
*rp = *(rp + 2);
|
||||
*(rp + 2) = save;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (row_info->bit_depth == 16)
|
||||
{
|
||||
if (row_info->color_type == PNG_COLOR_TYPE_RGB)
|
||||
{
|
||||
png_bytep rp;
|
||||
png_byte save[2];
|
||||
png_uint_32 i;
|
||||
|
||||
for (i = 0, rp = row; i < row_info->width; i++, rp += 6)
|
||||
{
|
||||
save[0] = *rp;
|
||||
save[1] = *(rp + 1);
|
||||
*rp = *(rp + 4);
|
||||
*(rp + 1) = *(rp + 5);
|
||||
*(rp + 4) = save[0];
|
||||
*(rp + 5) = save[1];
|
||||
}
|
||||
}
|
||||
else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
|
||||
{
|
||||
png_bytep rp;
|
||||
png_byte save[2];
|
||||
png_uint_32 i;
|
||||
|
||||
for (i = 0, rp = row; i < row_info->width; i++, rp += 8)
|
||||
{
|
||||
save[0] = *rp;
|
||||
save[1] = *(rp + 1);
|
||||
*rp = *(rp + 4);
|
||||
*(rp + 1) = *(rp + 5);
|
||||
*(rp + 4) = save[0];
|
||||
*(rp + 5) = save[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* PNG_READ_BGR_SUPPORTED or PNG_WRITE_BGR_SUPPORTED */
|
||||
|
||||
|
||||
117
pngwio.c
117
pngwio.c
@@ -1,17 +1,20 @@
|
||||
|
||||
/* pngwio.c - functions for data output
|
||||
|
||||
libpng 1.0 beta 3 - version 0.89
|
||||
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
|
||||
|
||||
This file provides a location for all output. Users which need
|
||||
special handling are expected to write functions which have the same
|
||||
arguments as these, and perform similar functions, but possibly use
|
||||
different output methods. Note that you shouldn't change these
|
||||
functions, but rather write replacement functions and then change
|
||||
them at run time with png_set_write_fn(...) */
|
||||
*
|
||||
* libpng 0.97
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* January 7, 1998
|
||||
*
|
||||
* This file provides a location for all output. Users which need
|
||||
* special handling are expected to write functions which have the same
|
||||
* arguments as these, and perform similar functions, but possibly use
|
||||
* different output methods. Note that you shouldn't change these
|
||||
* functions, but rather write replacement functions and then change
|
||||
* them at run time with png_set_write_fn(...).
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
#include "png.h"
|
||||
@@ -20,29 +23,29 @@
|
||||
writes to a file pointer. Note that this routine sometimes gets called
|
||||
with very small lengths, so you should implement some kind of simple
|
||||
buffering if you are using unbuffered writes. This should never be asked
|
||||
to write more then 64K on a 16 bit machine. The cast to png_size_t is
|
||||
there to quiet warnings of certain compilers. */
|
||||
to write more then 64K on a 16 bit machine. */
|
||||
|
||||
void
|
||||
png_write_data(png_structp png_ptr, png_bytep data, png_uint_32 length)
|
||||
png_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
{
|
||||
if (png_ptr->write_data_fn)
|
||||
if (png_ptr->write_data_fn != NULL )
|
||||
(*(png_ptr->write_data_fn))(png_ptr, data, length);
|
||||
else
|
||||
png_error(png_ptr, "Call to NULL write function");
|
||||
}
|
||||
|
||||
#if !defined(PNG_NO_STDIO)
|
||||
/* This is the function which does the actual writing of data. If you are
|
||||
not writing to a standard C stream, you should create a replacement
|
||||
write_data function and use it at run time with png_set_write_fn(), rather
|
||||
than changing the library. */
|
||||
#ifndef USE_FAR_KEYWORD
|
||||
static void
|
||||
png_default_write_data(png_structp png_ptr, png_bytep data, png_uint_32 length)
|
||||
png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
{
|
||||
png_uint_32 check;
|
||||
|
||||
check = fwrite(data, 1, (png_size_t)length, (FILE *)(png_ptr->io_ptr));
|
||||
check = fwrite(data, 1, length, (FILE *)(png_ptr->io_ptr));
|
||||
if (check != length)
|
||||
{
|
||||
png_error(png_ptr, "Write Error");
|
||||
@@ -57,41 +60,31 @@ png_default_write_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_write_data(png_structp png_ptr, png_bytep data, png_uint_32 length)
|
||||
png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
{
|
||||
png_uint_32 check;
|
||||
png_byte *n_data;
|
||||
png_byte *near_data; /* Needs to be "png_byte *" instead of "png_bytep" */
|
||||
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;
|
||||
if ((png_bytep)n_data == data)
|
||||
#endif
|
||||
near_data = (png_byte *)CVT_PTR_NOCHECK(data);
|
||||
io_ptr = (FILE *)CVT_PTR(png_ptr->io_ptr);
|
||||
if ((png_bytep)near_data == data)
|
||||
{
|
||||
check = fwrite(n_data, 1, (png_size_t)length, (FILE *)(png_ptr->io_ptr));
|
||||
check = fwrite(near_data, 1, length, io_ptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
png_byte buf[NEAR_BUF_SIZE];
|
||||
png_size_t written, remaining, err;
|
||||
check = 0;
|
||||
remaining = (png_size_t)length;
|
||||
remaining = length;
|
||||
do
|
||||
{
|
||||
written = MIN(NEAR_BUF_SIZE, remaining);
|
||||
png_memcpy(buf, data, written); /* copy far buffer to near buffer */
|
||||
err = fwrite(buf, 1, written, (FILE *)(png_ptr->io_ptr));
|
||||
err = fwrite(buf, 1, written, io_ptr);
|
||||
if (err != written)
|
||||
break;
|
||||
else
|
||||
@@ -107,6 +100,7 @@ png_default_write_data(png_structp png_ptr, png_bytep data, png_uint_32 length)
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* This function is called to output any data pending writing (normally
|
||||
@@ -116,17 +110,21 @@ png_default_write_data(png_structp png_ptr, png_bytep data, png_uint_32 length)
|
||||
void
|
||||
png_flush(png_structp png_ptr)
|
||||
{
|
||||
if (png_ptr->output_flush_fn)
|
||||
if (png_ptr->output_flush_fn != NULL)
|
||||
(*(png_ptr->output_flush_fn))(png_ptr);
|
||||
}
|
||||
|
||||
#if !defined(PNG_NO_STDIO)
|
||||
static void
|
||||
png_default_flush(png_structp png_ptr)
|
||||
{
|
||||
if ((FILE *)(png_ptr->io_ptr))
|
||||
fflush((FILE *)(png_ptr->io_ptr));
|
||||
FILE *io_ptr;
|
||||
io_ptr = (FILE *)CVT_PTR((png_ptr->io_ptr));
|
||||
if (io_ptr != NULL)
|
||||
fflush(io_ptr);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* This function allows the application to supply new output functions for
|
||||
libpng if standard C streams aren't being used.
|
||||
@@ -156,19 +154,54 @@ png_set_write_fn(png_structp png_ptr, png_voidp io_ptr,
|
||||
{
|
||||
png_ptr->io_ptr = io_ptr;
|
||||
|
||||
if (write_data_fn)
|
||||
#if !defined(PNG_NO_STDIO)
|
||||
if (write_data_fn != NULL)
|
||||
png_ptr->write_data_fn = write_data_fn;
|
||||
else
|
||||
png_ptr->write_data_fn = png_default_write_data;
|
||||
#else
|
||||
png_ptr->write_data_fn = write_data_fn;
|
||||
#endif
|
||||
|
||||
#if defined(PNG_WRITE_FLUSH_SUPPORTED)
|
||||
if (output_flush_fn)
|
||||
#if !defined(PNG_NO_STDIO)
|
||||
if (output_flush_fn != NULL)
|
||||
png_ptr->output_flush_fn = output_flush_fn;
|
||||
else
|
||||
png_ptr->output_flush_fn = png_default_flush;
|
||||
#else
|
||||
png_ptr->output_flush_fn = output_flush_fn;
|
||||
#endif
|
||||
#endif /* PNG_WRITE_FLUSH_SUPPORTED */
|
||||
|
||||
/* It is an error to read while writing a png file */
|
||||
png_ptr->read_data_fn = NULL;
|
||||
}
|
||||
|
||||
#if defined(USE_FAR_KEYWORD)
|
||||
#if defined(_MSC_VER)
|
||||
void *far_to_near(png_structp png_ptr,png_voidp ptr, int check)
|
||||
{
|
||||
void *near_ptr;
|
||||
void FAR *far_ptr;
|
||||
FP_OFF(near_ptr) = FP_OFF(ptr);
|
||||
far_ptr = (void FAR *)near_ptr;
|
||||
if(check != 0)
|
||||
if(FP_SEG(ptr) != FP_SEG(far_ptr))
|
||||
png_error(png_ptr,"segment lost in conversion");
|
||||
return(near_ptr);
|
||||
}
|
||||
# else
|
||||
void *far_to_near(png_structp png_ptr,png_voidp ptr, int check)
|
||||
{
|
||||
void *near_ptr;
|
||||
void FAR *far_ptr;
|
||||
near_ptr = (void FAR *)ptr;
|
||||
far_ptr = (void FAR *)near_ptr;
|
||||
if(check != 0)
|
||||
if(far_ptr != ptr)
|
||||
png_error(png_ptr,"segment lost in conversion");
|
||||
return(near_ptr);
|
||||
}
|
||||
# endif
|
||||
# endif
|
||||
|
||||
647
pngwrite.c
647
pngwrite.c
@@ -1,169 +1,194 @@
|
||||
|
||||
/* pngwrite.c - general routines to write a png file
|
||||
|
||||
libpng 1.0 beta 3 - version 0.89
|
||||
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
|
||||
*/
|
||||
|
||||
/* pngwrite.c - general routines to write a PNG file
|
||||
*
|
||||
* libpng 0.97
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* January 7, 1998
|
||||
*/
|
||||
|
||||
/* get internal access to png.h */
|
||||
#define PNG_INTERNAL
|
||||
#include "png.h"
|
||||
|
||||
/* Writes all the png information. This is the suggested way to use
|
||||
the library. If you have a new chunk to add, make a function to
|
||||
write it, and put it in the correct location here. If you want
|
||||
the chunk written after the image data, put it in png_write_end().
|
||||
I strongly encurage you to supply a PNG_INFO_ flag, and check
|
||||
info->valid before writing the chunk, as that will keep the code
|
||||
from breaking if you want to just write a plain png file.
|
||||
If you have long comments, I suggest writing them in png_write_end(),
|
||||
and compressing them. */
|
||||
/* Writes all the PNG information. This is the suggested way to use the
|
||||
* library. If you have a new chunk to add, make a function to write it,
|
||||
* and put it in the correct location here. If you want the chunk written
|
||||
* after the image data, put it in png_write_end(). I strongly encurage
|
||||
* you to supply a PNG_INFO_ flag, and check info_ptr->valid before writing
|
||||
* the chunk, as that will keep the code from breaking if you want to just
|
||||
* write a plain PNG file. If you have long comments, I suggest writing
|
||||
* them in png_write_end(), and compressing them.
|
||||
*/
|
||||
void
|
||||
png_write_info(png_structp png_ptr, png_infop info)
|
||||
png_write_info(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
#if defined(PNG_WRITE_tEXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED)
|
||||
int i;
|
||||
#endif
|
||||
|
||||
png_debug(1, "in png_write_info\n");
|
||||
png_write_sig(png_ptr); /* write PNG signature */
|
||||
/* write IHDR information. */
|
||||
png_write_IHDR(png_ptr, info->width, info->height, info->bit_depth,
|
||||
info->color_type, info->compression_type, info->filter_type,
|
||||
info->interlace_type);
|
||||
png_write_IHDR(png_ptr, info_ptr->width, info_ptr->height,
|
||||
info_ptr->bit_depth, info_ptr->color_type, info_ptr->compression_type,
|
||||
info_ptr->filter_type, info_ptr->interlace_type);
|
||||
/* the rest of these check to see if the valid field has the appropriate
|
||||
flag set, and if it does, writes the chunk. */
|
||||
#if defined(PNG_WRITE_gAMA_SUPPORTED)
|
||||
if (info->valid & PNG_INFO_gAMA)
|
||||
png_write_gAMA(png_ptr, info->gamma);
|
||||
if (info_ptr->valid & PNG_INFO_gAMA)
|
||||
png_write_gAMA(png_ptr, info_ptr->gamma);
|
||||
#endif
|
||||
#if defined(PNG_WRITE_sRGB_SUPPORTED)
|
||||
if (info_ptr->valid & PNG_INFO_sRGB)
|
||||
png_write_sRGB(png_ptr, info_ptr->srgb_intent);
|
||||
#endif
|
||||
#if defined(PNG_WRITE_sBIT_SUPPORTED)
|
||||
if (info->valid & PNG_INFO_sBIT)
|
||||
png_write_sBIT(png_ptr, &(info->sig_bit), info->color_type);
|
||||
if (info_ptr->valid & PNG_INFO_sBIT)
|
||||
png_write_sBIT(png_ptr, &(info_ptr->sig_bit), info_ptr->color_type);
|
||||
#endif
|
||||
#if defined(PNG_WRITE_cHRM_SUPPORTED)
|
||||
if (info->valid & PNG_INFO_cHRM)
|
||||
if (info_ptr->valid & PNG_INFO_cHRM)
|
||||
png_write_cHRM(png_ptr,
|
||||
info->x_white, info->y_white,
|
||||
info->x_red, info->y_red,
|
||||
info->x_green, info->y_green,
|
||||
info->x_blue, info->y_blue);
|
||||
info_ptr->x_white, info_ptr->y_white,
|
||||
info_ptr->x_red, info_ptr->y_red,
|
||||
info_ptr->x_green, info_ptr->y_green,
|
||||
info_ptr->x_blue, info_ptr->y_blue);
|
||||
#endif
|
||||
if (info->valid & PNG_INFO_PLTE)
|
||||
png_write_PLTE(png_ptr, info->palette, info->num_palette);
|
||||
else if (info->color_type == PNG_COLOR_TYPE_PALETTE)
|
||||
if (info_ptr->valid & PNG_INFO_PLTE)
|
||||
png_write_PLTE(png_ptr, info_ptr->palette,
|
||||
(png_uint_32)info_ptr->num_palette);
|
||||
else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
|
||||
png_error(png_ptr, "Valid palette required for paletted images\n");
|
||||
#if defined(PNG_WRITE_tRNS_SUPPORTED)
|
||||
if (info->valid & PNG_INFO_tRNS)
|
||||
png_write_tRNS(png_ptr, info->trans, &(info->trans_values),
|
||||
info->num_trans, info->color_type);
|
||||
if (info_ptr->valid & PNG_INFO_tRNS)
|
||||
png_write_tRNS(png_ptr, info_ptr->trans, &(info_ptr->trans_values),
|
||||
info_ptr->num_trans, info_ptr->color_type);
|
||||
#endif
|
||||
#if defined(PNG_WRITE_bKGD_SUPPORTED)
|
||||
if (info->valid & PNG_INFO_bKGD)
|
||||
png_write_bKGD(png_ptr, &(info->background), info->color_type);
|
||||
if (info_ptr->valid & PNG_INFO_bKGD)
|
||||
png_write_bKGD(png_ptr, &(info_ptr->background), info_ptr->color_type);
|
||||
#endif
|
||||
#if defined(PNG_WRITE_hIST_SUPPORTED)
|
||||
if (info->valid & PNG_INFO_hIST)
|
||||
png_write_hIST(png_ptr, info->hist, info->num_palette);
|
||||
#endif
|
||||
#if defined(PNG_WRITE_pHYs_SUPPORTED)
|
||||
if (info->valid & PNG_INFO_pHYs)
|
||||
png_write_pHYs(png_ptr, info->x_pixels_per_unit,
|
||||
info->y_pixels_per_unit, info->phys_unit_type);
|
||||
if (info_ptr->valid & PNG_INFO_hIST)
|
||||
png_write_hIST(png_ptr, info_ptr->hist, info_ptr->num_palette);
|
||||
#endif
|
||||
#if defined(PNG_WRITE_oFFs_SUPPORTED)
|
||||
if (info->valid & PNG_INFO_oFFs)
|
||||
png_write_oFFs(png_ptr, info->x_offset, info->y_offset,
|
||||
info->offset_unit_type);
|
||||
if (info_ptr->valid & PNG_INFO_oFFs)
|
||||
png_write_oFFs(png_ptr, info_ptr->x_offset, info_ptr->y_offset,
|
||||
info_ptr->offset_unit_type);
|
||||
#endif
|
||||
#if defined(PNG_WRITE_pCAL_SUPPORTED)
|
||||
if (info_ptr->valid & PNG_INFO_pCAL)
|
||||
png_write_pCAL(png_ptr, info_ptr->pcal_purpose, info_ptr->pcal_X0,
|
||||
info_ptr->pcal_X1, info_ptr->pcal_type, info_ptr->pcal_nparams,
|
||||
info_ptr->pcal_units, info_ptr->pcal_params);
|
||||
#endif
|
||||
#if defined(PNG_WRITE_pHYs_SUPPORTED)
|
||||
if (info_ptr->valid & PNG_INFO_pHYs)
|
||||
png_write_pHYs(png_ptr, info_ptr->x_pixels_per_unit,
|
||||
info_ptr->y_pixels_per_unit, info_ptr->phys_unit_type);
|
||||
#endif
|
||||
#if defined(PNG_WRITE_tIME_SUPPORTED)
|
||||
if (info->valid & PNG_INFO_tIME)
|
||||
if (info_ptr->valid & PNG_INFO_tIME)
|
||||
{
|
||||
png_write_tIME(png_ptr, &(info->mod_time));
|
||||
png_write_tIME(png_ptr, &(info_ptr->mod_time));
|
||||
png_ptr->flags |= PNG_FLAG_WROTE_tIME;
|
||||
}
|
||||
#endif
|
||||
#if defined(PNG_WRITE_tEXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED)
|
||||
/* Check to see if we need to write text chunks */
|
||||
if (info->num_text)
|
||||
for (i = 0; i < info_ptr->num_text; i++)
|
||||
{
|
||||
int i; /* local counter */
|
||||
|
||||
/* loop through the text chunks */
|
||||
for (i = 0; i < info->num_text; i++)
|
||||
png_debug2(2, "Writing header text chunk %d, type %d\n", i,
|
||||
info_ptr->text[i].compression);
|
||||
/* If we want a compressed text chunk */
|
||||
if (info_ptr->text[i].compression >= PNG_TEXT_COMPRESSION_zTXt)
|
||||
{
|
||||
/* if chunk is compressed */
|
||||
if (info->text[i].compression >= 0)
|
||||
{
|
||||
#if defined(PNG_WRITE_zTXt_SUPPORTED)
|
||||
/* write compressed chunk */
|
||||
png_write_zTXt(png_ptr, info->text[i].key,
|
||||
info->text[i].text, info->text[i].text_length,
|
||||
info->text[i].compression);
|
||||
/* write compressed chunk */
|
||||
png_write_zTXt(png_ptr, info_ptr->text[i].key,
|
||||
info_ptr->text[i].text, info_ptr->text[i].text_length,
|
||||
info_ptr->text[i].compression);
|
||||
#else
|
||||
png_warning(png_ptr, "Unable to write compressed text\n");
|
||||
png_warning(png_ptr, "Unable to write compressed text\n");
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Mark this chunk as written */
|
||||
info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
|
||||
}
|
||||
else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
|
||||
{
|
||||
#if defined(PNG_WRITE_tEXt_SUPPORTED)
|
||||
/* write uncompressed chunk */
|
||||
png_write_tEXt(png_ptr, info->text[i].key,
|
||||
info->text[i].text, info->text[i].text_length);
|
||||
/* write uncompressed chunk */
|
||||
png_write_tEXt(png_ptr, info_ptr->text[i].key,
|
||||
info_ptr->text[i].text, info_ptr->text[i].text_length);
|
||||
#else
|
||||
png_warning(png_ptr, "Unable to write uncompressed text\n");
|
||||
png_warning(png_ptr, "Unable to write uncompressed text\n");
|
||||
#endif
|
||||
}
|
||||
/* Mark this chunk as written */
|
||||
info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/* writes the end of the png file. If you don't want to write comments or
|
||||
time information, you can pass NULL for info. If you already wrote these
|
||||
in png_write_info(), do not write them again here. If you have long
|
||||
comments, I suggest writing them here, and compressing them. */
|
||||
/* Writes the end of the PNG file. If you don't want to write comments or
|
||||
* time information, you can pass NULL for info. If you already wrote these
|
||||
* in png_write_info(), do not write them again here. If you have long
|
||||
* comments, I suggest writing them here, and compressing them.
|
||||
*/
|
||||
void
|
||||
png_write_end(png_structp png_ptr, png_infop info)
|
||||
png_write_end(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
png_debug(1, "in png_write_end\n");
|
||||
if (!(png_ptr->mode & PNG_HAVE_IDAT))
|
||||
png_error(png_ptr, "No IDATs written into file");
|
||||
|
||||
/* see if user wants us to write information chunks */
|
||||
if (info)
|
||||
if (info_ptr != NULL)
|
||||
{
|
||||
#if defined(PNG_WRITE_tEXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED)
|
||||
int i; /* local index variable */
|
||||
#endif
|
||||
#if defined(PNG_WRITE_tIME_SUPPORTED)
|
||||
/* check to see if user has supplied a time chunk */
|
||||
if (info->valid & PNG_INFO_tIME &&
|
||||
if (info_ptr->valid & PNG_INFO_tIME &&
|
||||
!(png_ptr->flags & PNG_FLAG_WROTE_tIME))
|
||||
png_write_tIME(png_ptr, &(info->mod_time));
|
||||
png_write_tIME(png_ptr, &(info_ptr->mod_time));
|
||||
#endif
|
||||
#if defined(PNG_WRITE_tEXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED)
|
||||
/* check to see if we need to write comment chunks */
|
||||
if (info->num_text)
|
||||
/* loop through comment chunks */
|
||||
for (i = 0; i < info_ptr->num_text; i++)
|
||||
{
|
||||
int i; /* local index variable */
|
||||
|
||||
/* loop through comment chunks */
|
||||
for (i = 0; i < info->num_text; i++)
|
||||
png_debug2(2, "Writing trailer text chunk %d, type %d\n", i,
|
||||
info_ptr->text[i].compression);
|
||||
if (info_ptr->text[i].compression >= PNG_TEXT_COMPRESSION_zTXt)
|
||||
{
|
||||
#if defined(PNG_WRITE_zTXt_SUPPORTED)
|
||||
/* check to see if comment is to be compressed */
|
||||
if (info->text[i].compression >= 0)
|
||||
{
|
||||
/* write compressed chunk */
|
||||
png_write_zTXt(png_ptr, info->text[i].key,
|
||||
info->text[i].text, info->text[i].text_length,
|
||||
info->text[i].compression);
|
||||
}
|
||||
/* write compressed chunk */
|
||||
png_write_zTXt(png_ptr, info_ptr->text[i].key,
|
||||
info_ptr->text[i].text, info_ptr->text[i].text_length,
|
||||
info_ptr->text[i].compression);
|
||||
#else
|
||||
png_warning(png_ptr, "Unable to write compressed text\n");
|
||||
#endif
|
||||
/* Mark this chunk as written */
|
||||
info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
|
||||
}
|
||||
else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
|
||||
{
|
||||
#if defined(PNG_WRITE_tEXt_SUPPORTED)
|
||||
else
|
||||
#endif
|
||||
#endif
|
||||
#if defined(PNG_WRITE_tEXt_SUPPORTED)
|
||||
{
|
||||
/* write uncompressed chunk */
|
||||
png_write_tEXt(png_ptr, info->text[i].key,
|
||||
info->text[i].text, info->text[i].text_length);
|
||||
}
|
||||
/* write uncompressed chunk */
|
||||
png_write_tEXt(png_ptr, info_ptr->text[i].key,
|
||||
info_ptr->text[i].text, info_ptr->text[i].text_length);
|
||||
#else
|
||||
png_warning(png_ptr, "Unable to write uncompressed text\n");
|
||||
#endif
|
||||
|
||||
/* Mark this chunk as written */
|
||||
info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -171,14 +196,50 @@ png_write_end(png_structp png_ptr, png_infop info)
|
||||
|
||||
png_ptr->mode |= PNG_AFTER_IDAT;
|
||||
|
||||
/* write end of png file */
|
||||
/* write end of PNG file */
|
||||
png_write_IEND(png_ptr);
|
||||
}
|
||||
|
||||
#if defined(PNG_TIME_RFC1152_SUPPORTED)
|
||||
/* Convert the supplied time into an RFC 1152 string suitable for use in
|
||||
* a "Creation Time" or other text-based time string.
|
||||
*/
|
||||
png_charp
|
||||
png_convert_to_rfc1152(png_structp png_ptr, png_timep ptime)
|
||||
{
|
||||
const char *short_months[12] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
||||
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
|
||||
|
||||
if (png_ptr->time_buffer == NULL)
|
||||
{
|
||||
png_ptr->time_buffer = (png_charp)png_malloc(png_ptr, 29*sizeof(char));
|
||||
}
|
||||
|
||||
#ifdef USE_FAR_KEYWORD
|
||||
{
|
||||
char near_time_buf[29];
|
||||
sprintf(near_time_buf, "%d %s %d %02d:%02d:%02d +0000",
|
||||
ptime->day % 31, short_months[ptime->month],
|
||||
ptime->year, ptime->hour % 24, ptime->minute % 60,
|
||||
ptime->second % 61);
|
||||
png_memcpy(png_ptr->time_buffer, near_time_buf,
|
||||
29*sizeof(char));
|
||||
}
|
||||
#else
|
||||
sprintf(png_ptr->time_buffer, "%d %s %d %02d:%02d:%02d +0000",
|
||||
ptime->day % 31, short_months[ptime->month],
|
||||
ptime->year, ptime->hour % 24, ptime->minute % 60,
|
||||
ptime->second % 61);
|
||||
#endif
|
||||
return png_ptr->time_buffer;
|
||||
}
|
||||
#endif /* PNG_TIME_RFC1152_SUPPORTED */
|
||||
|
||||
#if defined(PNG_WRITE_tIME_SUPPORTED)
|
||||
void
|
||||
png_convert_from_struct_tm(png_timep ptime, struct tm FAR * ttime)
|
||||
{
|
||||
png_debug(1, "in png_convert_from_struct_tm\n");
|
||||
ptime->year = (png_uint_16)(1900 + ttime->tm_year);
|
||||
ptime->month = (png_byte)(ttime->tm_mon + 1);
|
||||
ptime->day = (png_byte)ttime->tm_mday;
|
||||
@@ -192,63 +253,75 @@ png_convert_from_time_t(png_timep ptime, time_t ttime)
|
||||
{
|
||||
struct tm *tbuf;
|
||||
|
||||
png_debug(1, "in png_convert_from_time_t\n");
|
||||
tbuf = gmtime(&ttime);
|
||||
png_convert_from_struct_tm(ptime, tbuf);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* initialize png structure, and allocate any memory needed */
|
||||
/* Initialize png_ptr structure, and allocate any memory needed */
|
||||
png_structp
|
||||
png_create_write_struct(png_const_charp user_png_ver, voidp error_ptr,
|
||||
png_error_ptr warn_fn, png_error_ptr error_fn)
|
||||
png_error_ptr error_fn, png_error_ptr warn_fn)
|
||||
{
|
||||
png_structp png_ptr;
|
||||
|
||||
#ifdef USE_FAR_KEYWORD
|
||||
jmp_buf jmpbuf;
|
||||
#endif
|
||||
png_debug(1, "in png_create_write_struct\n");
|
||||
if ((png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG)) == NULL)
|
||||
{
|
||||
return (png_structp)NULL;
|
||||
}
|
||||
|
||||
#ifdef USE_FAR_KEYWORD
|
||||
if (setjmp(jmpbuf))
|
||||
#else
|
||||
if (setjmp(png_ptr->jmpbuf))
|
||||
#endif
|
||||
{
|
||||
png_large_free(png_ptr, png_ptr->zbuf);
|
||||
png_free(png_ptr, png_ptr->zstream);
|
||||
png_free(png_ptr, png_ptr->zbuf);
|
||||
png_destroy_struct(png_ptr);
|
||||
return (png_structp)NULL;
|
||||
}
|
||||
#ifdef USE_FAR_KEYWORD
|
||||
png_memcpy(png_ptr->jmpbuf,jmpbuf,sizeof(jmp_buf));
|
||||
#endif
|
||||
png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
|
||||
|
||||
png_set_error_fn(png_ptr, error_ptr, warn_fn, error_fn);
|
||||
|
||||
if (user_png_ver == NULL || strcmp(user_png_ver, png_libpng_ver))
|
||||
/* Libpng 0.90 and later are binary incompatible with libpng 0.89, so
|
||||
* we must recompile any applications that use any older library version.
|
||||
* For versions after libpng 1.0, we will be compatible, so we need
|
||||
* only check the first digit.
|
||||
*/
|
||||
if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
|
||||
(png_libpng_ver[0] == '0' && user_png_ver[2] < '9'))
|
||||
{
|
||||
if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0])
|
||||
{
|
||||
png_error(png_ptr, "Incompatible libpng versions");
|
||||
}
|
||||
else
|
||||
{
|
||||
png_warning(png_ptr, "Different libpng versions");
|
||||
}
|
||||
png_error(png_ptr,
|
||||
"Incompatible libpng version in application and library");
|
||||
}
|
||||
|
||||
/* initialize zbuf - compression buffer */
|
||||
png_ptr->zbuf_size = PNG_ZBUF_SIZE;
|
||||
png_ptr->zbuf = png_large_malloc(png_ptr, png_ptr->zbuf_size);
|
||||
png_ptr->zbuf = png_malloc(png_ptr, png_ptr->zbuf_size);
|
||||
|
||||
png_set_write_fn(png_ptr, NULL, NULL, NULL);
|
||||
|
||||
png_ptr->do_free |= PNG_FREE_STRUCT;
|
||||
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
|
||||
png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
|
||||
1, NULL, NULL);
|
||||
#endif
|
||||
|
||||
return (png_ptr);
|
||||
}
|
||||
|
||||
|
||||
/* initialize png structure, and allocate any memory needed */
|
||||
/* Initialize png_ptr structure, and allocate any memory needed */
|
||||
void
|
||||
png_write_init(png_structp png_ptr)
|
||||
{
|
||||
jmp_buf tmp_jmp; /* to save current jump buffer */
|
||||
|
||||
png_debug(1, "in png_write_init\n");
|
||||
/* save jump buffer and error functions */
|
||||
png_memcpy(tmp_jmp, png_ptr->jmpbuf, sizeof (jmp_buf));
|
||||
|
||||
@@ -260,14 +333,20 @@ png_write_init(png_structp png_ptr)
|
||||
|
||||
/* initialize zbuf - compression buffer */
|
||||
png_ptr->zbuf_size = PNG_ZBUF_SIZE;
|
||||
png_ptr->zbuf = png_large_malloc(png_ptr, png_ptr->zbuf_size);
|
||||
png_ptr->zbuf = png_malloc(png_ptr, png_ptr->zbuf_size);
|
||||
png_set_write_fn(png_ptr, NULL, NULL, NULL);
|
||||
|
||||
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
|
||||
png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
|
||||
1, NULL, NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* write a few rows of image data. If the image is interlaced,
|
||||
either you will have to write the 7 sub images, or, if you
|
||||
have called png_set_interlace_handling(), you will have to
|
||||
"write" the image seven times */
|
||||
/* Write a few rows of image data. If the image is interlaced,
|
||||
* either you will have to write the 7 sub images, or, if you
|
||||
* have called png_set_interlace_handling(), you will have to
|
||||
* "write" the image seven times.
|
||||
*/
|
||||
void
|
||||
png_write_rows(png_structp png_ptr, png_bytepp row,
|
||||
png_uint_32 num_rows)
|
||||
@@ -275,6 +354,7 @@ png_write_rows(png_structp png_ptr, png_bytepp row,
|
||||
png_uint_32 i; /* row counter */
|
||||
png_bytepp rp; /* row pointer */
|
||||
|
||||
png_debug(1, "in png_write_rows\n");
|
||||
/* loop through the rows */
|
||||
for (i = 0, rp = row; i < num_rows; i++, rp++)
|
||||
{
|
||||
@@ -282,8 +362,9 @@ png_write_rows(png_structp png_ptr, png_bytepp row,
|
||||
}
|
||||
}
|
||||
|
||||
/* write the image. You only need to call this function once, even
|
||||
if you are writing an interlaced image. */
|
||||
/* Write the image. You only need to call this function once, even
|
||||
* if you are writing an interlaced image.
|
||||
*/
|
||||
void
|
||||
png_write_image(png_structp png_ptr, png_bytepp image)
|
||||
{
|
||||
@@ -291,6 +372,7 @@ png_write_image(png_structp png_ptr, png_bytepp image)
|
||||
int pass, num_pass; /* pass variables */
|
||||
png_bytepp rp; /* points to current row */
|
||||
|
||||
png_debug(1, "in png_write_image\n");
|
||||
/* intialize interlace handling. If image is not interlaced,
|
||||
this will set pass to 1 */
|
||||
num_pass = png_set_interlace_handling(png_ptr);
|
||||
@@ -309,6 +391,8 @@ png_write_image(png_structp png_ptr, png_bytepp image)
|
||||
void
|
||||
png_write_row(png_structp png_ptr, png_bytep row)
|
||||
{
|
||||
png_debug2(1, "in png_write_row (row %ld, pass %d)\n",
|
||||
png_ptr->row_number, png_ptr->pass);
|
||||
/* initialize transformations and other stuff if first time */
|
||||
if (png_ptr->row_number == 0 && png_ptr->pass == 0)
|
||||
{
|
||||
@@ -384,8 +468,15 @@ png_write_row(png_structp png_ptr, png_bytep row)
|
||||
png_ptr->row_info.rowbytes = ((png_ptr->row_info.width *
|
||||
(png_uint_32)png_ptr->row_info.pixel_depth + 7) >> 3);
|
||||
|
||||
/* copy users row into buffer, leaving room for filter byte */
|
||||
png_memcpy(png_ptr->row_buf + 1, row, (png_size_t)png_ptr->row_info.rowbytes);
|
||||
png_debug1(3, "row_info->color_type = %d\n", png_ptr->row_info.color_type);
|
||||
png_debug1(3, "row_info->width = %d\n", png_ptr->row_info.width);
|
||||
png_debug1(3, "row_info->channels = %d\n", png_ptr->row_info.channels);
|
||||
png_debug1(3, "row_info->bit_depth = %d\n", png_ptr->row_info.bit_depth);
|
||||
png_debug1(3, "row_info->pixel_depth = %d\n", png_ptr->row_info.pixel_depth);
|
||||
png_debug1(3, "row_info->rowbytes = %d\n", png_ptr->row_info.rowbytes);
|
||||
|
||||
/* Copy user's row into buffer, leaving room for filter byte. */
|
||||
png_memcpy(png_ptr->row_buf + 1, row, png_ptr->row_info.rowbytes);
|
||||
|
||||
#if defined(PNG_WRITE_INTERLACING_SUPPORTED)
|
||||
/* handle interlacing */
|
||||
@@ -407,18 +498,8 @@ png_write_row(png_structp png_ptr, png_bytep row)
|
||||
if (png_ptr->transformations)
|
||||
png_do_write_transformations(png_ptr);
|
||||
|
||||
/* find a filter if necessary, filter the row and write it out */
|
||||
/* Find a filter if necessary, filter the row and write it out. */
|
||||
png_write_find_filter(png_ptr, &(png_ptr->row_info));
|
||||
|
||||
/* trade current and prev rows so next filter references are correct */
|
||||
if (png_ptr->prev_row)
|
||||
{
|
||||
png_bytep tptr;
|
||||
|
||||
tptr = png_ptr->prev_row;
|
||||
png_ptr->prev_row = png_ptr->row_buf;
|
||||
png_ptr->row_buf = tptr;
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(PNG_WRITE_FLUSH_SUPPORTED)
|
||||
@@ -426,6 +507,7 @@ png_write_row(png_structp png_ptr, png_bytep row)
|
||||
void
|
||||
png_set_flush(png_structp png_ptr, int nrows)
|
||||
{
|
||||
png_debug(1, "in png_set_flush\n");
|
||||
png_ptr->flush_dist = (nrows < 0 ? 0 : nrows);
|
||||
}
|
||||
|
||||
@@ -435,6 +517,7 @@ png_write_flush(png_structp png_ptr)
|
||||
{
|
||||
int wrote_IDAT;
|
||||
|
||||
png_debug(1, "in png_write_flush\n");
|
||||
/* We have already written out all of the data */
|
||||
if (png_ptr->row_number >= png_ptr->num_rows)
|
||||
return;
|
||||
@@ -444,37 +527,37 @@ png_write_flush(png_structp png_ptr)
|
||||
int ret;
|
||||
|
||||
/* compress the data */
|
||||
ret = deflate(png_ptr->zstream, Z_SYNC_FLUSH);
|
||||
ret = deflate(&png_ptr->zstream, Z_SYNC_FLUSH);
|
||||
wrote_IDAT = 0;
|
||||
|
||||
/* check for compression errors */
|
||||
if (ret != Z_OK)
|
||||
{
|
||||
if (png_ptr->zstream->msg)
|
||||
png_error(png_ptr, png_ptr->zstream->msg);
|
||||
if (png_ptr->zstream.msg != NULL)
|
||||
png_error(png_ptr, png_ptr->zstream.msg);
|
||||
else
|
||||
png_error(png_ptr, "zlib error");
|
||||
}
|
||||
|
||||
if (!png_ptr->zstream->avail_out)
|
||||
if (!(png_ptr->zstream.avail_out))
|
||||
{
|
||||
/* write the IDAT and reset the zlib output buffer */
|
||||
png_write_IDAT(png_ptr, png_ptr->zbuf,
|
||||
png_ptr->zbuf_size);
|
||||
png_ptr->zstream->next_out = png_ptr->zbuf;
|
||||
png_ptr->zstream->avail_out = (uInt)png_ptr->zbuf_size;
|
||||
png_ptr->zstream.next_out = png_ptr->zbuf;
|
||||
png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
|
||||
wrote_IDAT = 1;
|
||||
}
|
||||
} while(wrote_IDAT == 1);
|
||||
|
||||
/* If there is any data left to be output, write it into a new IDAT */
|
||||
if (png_ptr->zbuf_size != png_ptr->zstream->avail_out)
|
||||
if (png_ptr->zbuf_size != png_ptr->zstream.avail_out)
|
||||
{
|
||||
/* write the IDAT and reset the zlib output buffer */
|
||||
png_write_IDAT(png_ptr, png_ptr->zbuf,
|
||||
png_ptr->zbuf_size - png_ptr->zstream->avail_out);
|
||||
png_ptr->zstream->next_out = png_ptr->zbuf;
|
||||
png_ptr->zstream->avail_out = (uInt)png_ptr->zbuf_size;
|
||||
png_ptr->zbuf_size - png_ptr->zstream.avail_out);
|
||||
png_ptr->zstream.next_out = png_ptr->zbuf;
|
||||
png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
|
||||
}
|
||||
png_ptr->flush_rows = 0;
|
||||
png_flush(png_ptr);
|
||||
@@ -483,24 +566,37 @@ png_write_flush(png_structp png_ptr)
|
||||
|
||||
/* free all memory used by the write */
|
||||
void
|
||||
png_destroy_write_struct(png_structpp png_ptr, png_infopp info_ptr)
|
||||
png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)
|
||||
{
|
||||
if (info_ptr && *info_ptr)
|
||||
png_structp png_ptr = NULL;
|
||||
png_infop info_ptr = NULL;
|
||||
|
||||
png_debug(1, "in png_destroy_write_struct\n");
|
||||
if (png_ptr_ptr != NULL)
|
||||
png_ptr = *png_ptr_ptr;
|
||||
|
||||
if (info_ptr_ptr != NULL)
|
||||
info_ptr = *info_ptr_ptr;
|
||||
|
||||
if (info_ptr != NULL)
|
||||
{
|
||||
png_destroy_struct((voidp)*info_ptr);
|
||||
*info_ptr = (png_infop)NULL;
|
||||
#ifdef PNG_WRITE_tEXt_SUPPORTED
|
||||
png_free(png_ptr, info_ptr->text);
|
||||
#endif
|
||||
png_destroy_struct((png_voidp)info_ptr);
|
||||
*info_ptr_ptr = (png_infop)NULL;
|
||||
}
|
||||
|
||||
if (png_ptr && *png_ptr)
|
||||
if (png_ptr != NULL)
|
||||
{
|
||||
png_write_destroy(*png_ptr);
|
||||
png_destroy_struct((voidp)*png_ptr);
|
||||
*png_ptr = (png_structp)NULL;
|
||||
png_write_destroy(png_ptr);
|
||||
png_destroy_struct((png_voidp)png_ptr);
|
||||
*png_ptr_ptr = (png_structp)NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* free any memory used in png struct (old) */
|
||||
/* Free any memory used in png_ptr struct (old method) */
|
||||
void
|
||||
png_write_destroy(png_structp png_ptr)
|
||||
{
|
||||
@@ -509,18 +605,28 @@ png_write_destroy(png_structp png_ptr)
|
||||
png_error_ptr warning_fn;
|
||||
png_voidp error_ptr;
|
||||
|
||||
png_debug(1, "in png_write_destroy\n");
|
||||
/* free any memory zlib uses */
|
||||
deflateEnd(png_ptr->zstream);
|
||||
png_free(png_ptr, png_ptr->zstream);
|
||||
deflateEnd(&png_ptr->zstream);
|
||||
|
||||
/* free our memory. png_free checks NULL for us. */
|
||||
png_large_free(png_ptr, png_ptr->zbuf);
|
||||
png_large_free(png_ptr, png_ptr->row_buf);
|
||||
png_large_free(png_ptr, png_ptr->prev_row);
|
||||
png_large_free(png_ptr, png_ptr->sub_row);
|
||||
png_large_free(png_ptr, png_ptr->up_row);
|
||||
png_large_free(png_ptr, png_ptr->avg_row);
|
||||
png_large_free(png_ptr, png_ptr->paeth_row);
|
||||
png_free(png_ptr, png_ptr->zbuf);
|
||||
png_free(png_ptr, png_ptr->row_buf);
|
||||
png_free(png_ptr, png_ptr->prev_row);
|
||||
png_free(png_ptr, png_ptr->sub_row);
|
||||
png_free(png_ptr, png_ptr->up_row);
|
||||
png_free(png_ptr, png_ptr->avg_row);
|
||||
png_free(png_ptr, png_ptr->paeth_row);
|
||||
#if defined(PNG_TIME_RFC1152_SUPPORTED)
|
||||
png_free(png_ptr, png_ptr->time_buffer);
|
||||
#endif /* PNG_TIME_RFC1152_SUPPORTED */
|
||||
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
|
||||
png_free(png_ptr, png_ptr->prev_filters);
|
||||
png_free(png_ptr, png_ptr->filter_weights);
|
||||
png_free(png_ptr, png_ptr->inv_filter_weights);
|
||||
png_free(png_ptr, png_ptr->filter_costs);
|
||||
png_free(png_ptr, png_ptr->inv_filter_costs);
|
||||
#endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
|
||||
|
||||
/* reset structure */
|
||||
png_memcpy(tmp_jmp, png_ptr->jmpbuf, sizeof (jmp_buf));
|
||||
@@ -538,80 +644,88 @@ png_write_destroy(png_structp png_ptr)
|
||||
png_memcpy(png_ptr->jmpbuf, tmp_jmp, sizeof (jmp_buf));
|
||||
}
|
||||
|
||||
/* Allow the application to select one or more filters to use */
|
||||
/* Allow the application to select one or more row filters to use. */
|
||||
void
|
||||
png_set_filter(png_structp png_ptr, int method, int filters)
|
||||
{
|
||||
/* We allow 'method' only for future expansion of the base filter method */
|
||||
if (method == 0)
|
||||
png_debug(1, "in png_set_filter\n");
|
||||
/* We allow 'method' only for future expansion of the base filter method. */
|
||||
if (method == PNG_FILTER_TYPE_BASE)
|
||||
{
|
||||
switch (filters & (PNG_ALL_FILTERS | 0x07))
|
||||
{
|
||||
case 5:
|
||||
case 6:
|
||||
case 7: png_warning(png_ptr, "Unknown custom row filter for method 0");
|
||||
case 0: png_ptr->do_filter = PNG_FILTER_NONE; break;
|
||||
case 1: png_ptr->do_filter = PNG_FILTER_SUB; break;
|
||||
case 2: png_ptr->do_filter = PNG_FILTER_UP; break;
|
||||
case 3: png_ptr->do_filter = PNG_FILTER_AVG; break;
|
||||
case 4: png_ptr->do_filter = PNG_FILTER_PAETH; break;
|
||||
case 7: png_warning(png_ptr, "Unknown row filter for method 0");
|
||||
case PNG_FILTER_VALUE_NONE: png_ptr->do_filter=PNG_FILTER_NONE; break;
|
||||
case PNG_FILTER_VALUE_SUB: png_ptr->do_filter=PNG_FILTER_SUB; break;
|
||||
case PNG_FILTER_VALUE_UP: png_ptr->do_filter=PNG_FILTER_UP; break;
|
||||
case PNG_FILTER_VALUE_AVG: png_ptr->do_filter=PNG_FILTER_AVG; break;
|
||||
case PNG_FILTER_VALUE_PAETH: png_ptr->do_filter=PNG_FILTER_PAETH;break;
|
||||
default: png_ptr->do_filter = (png_byte)filters; break;
|
||||
}
|
||||
|
||||
/* If we have allocated the row_buf, then we should have also allocated
|
||||
* all of the filter buffers that have been selected.
|
||||
/* If we have allocated the row_buf, this means we have already started
|
||||
* with the image and we should have allocated all of the filter buffers
|
||||
* that have been selected. If prev_row isn't already allocated, then
|
||||
* it is too late to start using the filters that need it, since we
|
||||
* will be missing the data in the previous row. If an application
|
||||
* wants to start and stop using particular filters during compression,
|
||||
* it should start out with all of the filters, and then add and
|
||||
* remove them after the start of compression.
|
||||
*/
|
||||
if (png_ptr->row_buf)
|
||||
if (png_ptr->row_buf != NULL)
|
||||
{
|
||||
if (png_ptr->do_filter & PNG_FILTER_SUB && !(png_ptr->sub_row))
|
||||
if (png_ptr->do_filter & PNG_FILTER_SUB && png_ptr->sub_row == NULL)
|
||||
{
|
||||
png_ptr->sub_row = (png_bytep )png_large_malloc(png_ptr,
|
||||
png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
|
||||
png_ptr->rowbytes + 1);
|
||||
png_ptr->sub_row[0] = 1; /* Set the row filter type */
|
||||
png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
|
||||
}
|
||||
|
||||
if (png_ptr->do_filter & PNG_FILTER_UP && !(png_ptr->up_row))
|
||||
if (png_ptr->do_filter & PNG_FILTER_UP && png_ptr->up_row == NULL)
|
||||
{
|
||||
if (!(png_ptr->prev_row))
|
||||
if (png_ptr->prev_row == NULL)
|
||||
{
|
||||
png_warning(png_ptr, "Can't to add up filter after starting");
|
||||
png_warning(png_ptr, "Can't add Up filter after starting");
|
||||
png_ptr->do_filter &= ~PNG_FILTER_UP;
|
||||
}
|
||||
else
|
||||
{
|
||||
png_ptr->up_row = (png_bytep )png_large_malloc(png_ptr,
|
||||
png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
|
||||
png_ptr->rowbytes + 1);
|
||||
png_ptr->up_row[0] = 2; /* Set the row filter type */
|
||||
png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
|
||||
}
|
||||
}
|
||||
|
||||
if (png_ptr->do_filter & PNG_FILTER_AVG && !(png_ptr->avg_row))
|
||||
if (png_ptr->do_filter & PNG_FILTER_AVG && png_ptr->avg_row == NULL)
|
||||
{
|
||||
if (!(png_ptr->prev_row))
|
||||
if (png_ptr->prev_row == NULL)
|
||||
{
|
||||
png_warning(png_ptr, "Can't add average filter after starting");
|
||||
png_warning(png_ptr, "Can't add Average filter after starting");
|
||||
png_ptr->do_filter &= ~PNG_FILTER_AVG;
|
||||
}
|
||||
else
|
||||
{
|
||||
png_ptr->up_row = (png_bytep )png_large_malloc(png_ptr,
|
||||
png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
|
||||
png_ptr->rowbytes + 1);
|
||||
png_ptr->up_row[0] = 3; /* Set the row filter type */
|
||||
png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
|
||||
}
|
||||
}
|
||||
|
||||
if (png_ptr->do_filter & PNG_FILTER_PAETH && !(png_ptr->paeth_row))
|
||||
if (png_ptr->do_filter & PNG_FILTER_PAETH &&
|
||||
png_ptr->paeth_row == NULL)
|
||||
{
|
||||
if (!(png_ptr->prev_row))
|
||||
if (png_ptr->prev_row == NULL)
|
||||
{
|
||||
png_warning(png_ptr, "Can't add Paeth filter after starting");
|
||||
png_ptr->do_filter &= ~PNG_FILTER_PAETH;
|
||||
}
|
||||
else
|
||||
{
|
||||
png_ptr->paeth_row = (png_bytep )png_large_malloc(png_ptr,
|
||||
png_ptr->paeth_row = (png_bytep )png_malloc(png_ptr,
|
||||
png_ptr->rowbytes + 1);
|
||||
png_ptr->paeth_row[0] = 4; /* Set the row filter type */
|
||||
png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -620,12 +734,140 @@ png_set_filter(png_structp png_ptr, int method, int filters)
|
||||
}
|
||||
}
|
||||
else
|
||||
png_error(png_ptr, "Unknown custom filter method");
|
||||
png_error(png_ptr, "Unknown custom filter method");
|
||||
}
|
||||
|
||||
/* This allows us to influence the way in which libpng chooses the "best"
|
||||
* filter for the current scanline. While the "minimum-sum-of-absolute-
|
||||
* differences metric is relatively fast and effective, there is some
|
||||
* question as to whether it can be improved upon by trying to keep the
|
||||
* filtered data going to zlib more consistent, hopefully resulting in
|
||||
* better compression.
|
||||
*/
|
||||
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* GRR 970116 */
|
||||
void
|
||||
png_set_filter_heuristics(png_structp png_ptr, int heuristic_method,
|
||||
int num_weights, png_doublep filter_weights,
|
||||
png_doublep filter_costs)
|
||||
{
|
||||
#if defined(PNG_WRITE_tEXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED)
|
||||
int i;
|
||||
#endif
|
||||
|
||||
png_debug(1, "in png_set_filter_heuristics\n");
|
||||
if (heuristic_method >= PNG_FILTER_HEURISTIC_LAST)
|
||||
{
|
||||
png_warning(png_ptr, "Unknown filter heuristic method");
|
||||
return;
|
||||
}
|
||||
|
||||
if (heuristic_method == PNG_FILTER_HEURISTIC_DEFAULT)
|
||||
{
|
||||
heuristic_method = PNG_FILTER_HEURISTIC_UNWEIGHTED;
|
||||
}
|
||||
|
||||
if (num_weights < 0 || filter_weights == NULL ||
|
||||
heuristic_method == PNG_FILTER_HEURISTIC_UNWEIGHTED)
|
||||
{
|
||||
num_weights = 0;
|
||||
}
|
||||
|
||||
png_ptr->num_prev_filters = num_weights;
|
||||
png_ptr->heuristic_method = heuristic_method;
|
||||
|
||||
if (num_weights > 0)
|
||||
{
|
||||
if (png_ptr->prev_filters == NULL)
|
||||
{
|
||||
png_ptr->prev_filters = (png_bytep)png_malloc(png_ptr,
|
||||
sizeof(png_byte) * num_weights);
|
||||
|
||||
/* To make sure that the weighting starts out fairly */
|
||||
for (i = 0; i < num_weights; i++)
|
||||
{
|
||||
png_ptr->prev_filters[i] = 255;
|
||||
}
|
||||
}
|
||||
|
||||
if (png_ptr->filter_weights == NULL)
|
||||
{
|
||||
png_ptr->filter_weights = (png_uint_16p)png_malloc(png_ptr,
|
||||
sizeof(png_uint_16) * num_weights);
|
||||
|
||||
png_ptr->inv_filter_weights = (png_uint_16p)png_malloc(png_ptr,
|
||||
sizeof(png_uint_16) * num_weights);
|
||||
|
||||
for (i = 0; i < num_weights; i++)
|
||||
{
|
||||
png_ptr->inv_filter_weights[i] =
|
||||
png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < num_weights; i++)
|
||||
{
|
||||
if (filter_weights[i] < 0.0)
|
||||
{
|
||||
png_ptr->inv_filter_weights[i] =
|
||||
png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
|
||||
}
|
||||
else
|
||||
{
|
||||
png_ptr->inv_filter_weights[i] =
|
||||
(png_uint_16)((double)PNG_WEIGHT_FACTOR*filter_weights[i]+0.5);
|
||||
png_ptr->filter_weights[i] =
|
||||
(png_uint_16)((double)PNG_WEIGHT_FACTOR/filter_weights[i]+0.5);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* If, in the future, there are other filter methods, this would
|
||||
* need to be based on png_ptr->filter.
|
||||
*/
|
||||
if (png_ptr->filter_costs == NULL)
|
||||
{
|
||||
png_ptr->filter_costs = (png_uint_16p)png_malloc(png_ptr,
|
||||
sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST);
|
||||
|
||||
png_ptr->inv_filter_costs = (png_uint_16p)png_malloc(png_ptr,
|
||||
sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST);
|
||||
|
||||
for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
|
||||
{
|
||||
png_ptr->inv_filter_costs[i] =
|
||||
png_ptr->filter_costs[i] = PNG_COST_FACTOR;
|
||||
}
|
||||
}
|
||||
|
||||
/* Here is where we set the relative costs of the different filters. We
|
||||
* should take the desired compression level into account when setting
|
||||
* the costs, so that Paeth, for instance, has a high relative cost at low
|
||||
* compression levels, while it has a lower relative cost at higher
|
||||
* compression settings. The filter types are in order of increasing
|
||||
* relative cost, so it would be possible to do this with an algorithm.
|
||||
*/
|
||||
for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
|
||||
{
|
||||
if (filter_costs == NULL || filter_costs[i] < 0.0)
|
||||
{
|
||||
png_ptr->inv_filter_costs[i] =
|
||||
png_ptr->filter_costs[i] = PNG_COST_FACTOR;
|
||||
}
|
||||
else if (filter_costs[i] >= 1.0)
|
||||
{
|
||||
png_ptr->inv_filter_costs[i] =
|
||||
(png_uint_16)((double)PNG_COST_FACTOR / filter_costs[i] + 0.5);
|
||||
png_ptr->filter_costs[i] =
|
||||
(png_uint_16)((double)PNG_COST_FACTOR * filter_costs[i] + 0.5);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
|
||||
|
||||
void
|
||||
png_set_compression_level(png_structp png_ptr, int level)
|
||||
{
|
||||
png_debug(1, "in png_set_compression_level\n");
|
||||
png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_LEVEL;
|
||||
png_ptr->zlib_level = level;
|
||||
}
|
||||
@@ -633,6 +875,7 @@ png_set_compression_level(png_structp png_ptr, int level)
|
||||
void
|
||||
png_set_compression_mem_level(png_structp png_ptr, int mem_level)
|
||||
{
|
||||
png_debug(1, "in png_set_compression_mem_level\n");
|
||||
png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL;
|
||||
png_ptr->zlib_mem_level = mem_level;
|
||||
}
|
||||
@@ -640,6 +883,7 @@ png_set_compression_mem_level(png_structp png_ptr, int mem_level)
|
||||
void
|
||||
png_set_compression_strategy(png_structp png_ptr, int strategy)
|
||||
{
|
||||
png_debug(1, "in png_set_compression_strategy\n");
|
||||
png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_STRATEGY;
|
||||
png_ptr->zlib_strategy = strategy;
|
||||
}
|
||||
@@ -656,6 +900,7 @@ png_set_compression_window_bits(png_structp png_ptr, int window_bits)
|
||||
void
|
||||
png_set_compression_method(png_structp png_ptr, int method)
|
||||
{
|
||||
png_debug(1, "in png_set_compression_method\n");
|
||||
if (method != 8)
|
||||
png_warning(png_ptr, "Only compression method 8 is supported by PNG");
|
||||
png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_METHOD;
|
||||
|
||||
233
pngwtran.c
233
pngwtran.c
@@ -1,29 +1,33 @@
|
||||
|
||||
/* pngwtran.c - transforms the data in a row for png writers
|
||||
|
||||
libpng 1.0 beta 3 - version 0.89
|
||||
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
|
||||
*/
|
||||
/* pngwtran.c - transforms the data in a row for PNG writers
|
||||
*
|
||||
* libpng 0.97
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* January 7, 1998
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
#include "png.h"
|
||||
|
||||
/* transform the data according to the users wishes. The order of
|
||||
transformations is significant. */
|
||||
/* Transform the data according to the users wishes. The order of
|
||||
* transformations is significant.
|
||||
*/
|
||||
void
|
||||
png_do_write_transformations(png_structp png_ptr)
|
||||
{
|
||||
png_debug(1, "in png_do_write_transformations\n");
|
||||
#if defined(PNG_WRITE_FILLER_SUPPORTED)
|
||||
if (png_ptr->transformations & PNG_FILLER)
|
||||
png_do_write_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
|
||||
png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
|
||||
png_ptr->flags);
|
||||
#endif
|
||||
#if defined(PNG_WRITE_PACK_SUPPORTED)
|
||||
if (png_ptr->transformations & PNG_PACK)
|
||||
png_do_pack(&(png_ptr->row_info), png_ptr->row_buf + 1,
|
||||
png_ptr->bit_depth);
|
||||
(png_uint_32)png_ptr->bit_depth);
|
||||
#endif
|
||||
#if defined(PNG_WRITE_SHIFT_SUPPORTED)
|
||||
if (png_ptr->transformations & PNG_SHIFT)
|
||||
@@ -34,6 +38,10 @@ png_do_write_transformations(png_structp png_ptr)
|
||||
if (png_ptr->transformations & PNG_SWAP_BYTES)
|
||||
png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
|
||||
#endif
|
||||
#if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
|
||||
if (png_ptr->transformations & PNG_SWAP_ALPHA)
|
||||
png_do_write_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
|
||||
#endif
|
||||
#if defined(PNG_WRITE_BGR_SUPPORTED)
|
||||
if (png_ptr->transformations & PNG_BGR)
|
||||
png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
|
||||
@@ -45,24 +53,27 @@ png_do_write_transformations(png_structp png_ptr)
|
||||
}
|
||||
|
||||
#if defined(PNG_WRITE_PACK_SUPPORTED)
|
||||
/* pack pixels into bytes. Pass the true bit depth in bit_depth. The
|
||||
row_info bit depth should be 8 (one pixel per byte). The channels
|
||||
should be 1 (this only happens on grayscale and paletted images) */
|
||||
/* Pack pixels into bytes. Pass the true bit depth in bit_depth. The
|
||||
* row_info bit depth should be 8 (one pixel per byte). The channels
|
||||
* should be 1 (this only happens on grayscale and paletted images).
|
||||
*/
|
||||
void
|
||||
png_do_pack(png_row_infop row_info, png_bytep row, png_byte bit_depth)
|
||||
png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth)
|
||||
{
|
||||
if (row_info && row && row_info->bit_depth == 8 &&
|
||||
png_debug(1, "in png_do_pack\n");
|
||||
if (row_info->bit_depth == 8 &&
|
||||
#if defined(PNG_USELESS_TESTS_SUPPORTED)
|
||||
row != NULL && row_info != NULL &&
|
||||
#endif
|
||||
row_info->channels == 1)
|
||||
{
|
||||
switch (bit_depth)
|
||||
switch ((int)bit_depth)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
png_bytep sp;
|
||||
png_bytep dp;
|
||||
int mask;
|
||||
png_int_32 i;
|
||||
int v;
|
||||
png_bytep sp, dp;
|
||||
int mask, v;
|
||||
png_uint_32 i;
|
||||
|
||||
sp = row;
|
||||
dp = row;
|
||||
@@ -70,7 +81,7 @@ 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++)
|
||||
{
|
||||
if (*sp)
|
||||
if (*sp != 0)
|
||||
v |= mask;
|
||||
sp++;
|
||||
if (mask > 1)
|
||||
@@ -89,12 +100,9 @@ png_do_pack(png_row_infop row_info, png_bytep row, png_byte bit_depth)
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
png_bytep sp;
|
||||
png_bytep dp;
|
||||
int shift;
|
||||
png_int_32 i;
|
||||
int v;
|
||||
png_byte value;
|
||||
png_bytep sp, dp;
|
||||
int shift, v;
|
||||
png_uint_32 i;
|
||||
|
||||
sp = row;
|
||||
dp = row;
|
||||
@@ -102,6 +110,8 @@ 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++)
|
||||
{
|
||||
png_byte value;
|
||||
|
||||
value = (png_byte)(*sp & 0x3);
|
||||
v |= (value << shift);
|
||||
if (shift == 0)
|
||||
@@ -121,12 +131,9 @@ png_do_pack(png_row_infop row_info, png_bytep row, png_byte bit_depth)
|
||||
}
|
||||
case 4:
|
||||
{
|
||||
png_bytep sp;
|
||||
png_bytep dp;
|
||||
int shift;
|
||||
png_int_32 i;
|
||||
int v;
|
||||
png_byte value;
|
||||
png_bytep sp, dp;
|
||||
int shift, v;
|
||||
png_uint_32 i;
|
||||
|
||||
sp = row;
|
||||
dp = row;
|
||||
@@ -134,6 +141,8 @@ 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++)
|
||||
{
|
||||
png_byte value;
|
||||
|
||||
value = (png_byte)(*sp & 0xf);
|
||||
v |= (value << shift);
|
||||
|
||||
@@ -154,8 +163,8 @@ png_do_pack(png_row_infop row_info, png_bytep row, png_byte bit_depth)
|
||||
break;
|
||||
}
|
||||
}
|
||||
row_info->bit_depth = bit_depth;
|
||||
row_info->pixel_depth = (png_uint_16)(bit_depth * row_info->channels);
|
||||
row_info->bit_depth = (png_byte)bit_depth;
|
||||
row_info->pixel_depth = (png_byte)(bit_depth * row_info->channels);
|
||||
row_info->rowbytes =
|
||||
((row_info->width * row_info->pixel_depth + 7) >> 3);
|
||||
}
|
||||
@@ -163,20 +172,26 @@ png_do_pack(png_row_infop row_info, png_bytep row, png_byte bit_depth)
|
||||
#endif
|
||||
|
||||
#if defined(PNG_WRITE_SHIFT_SUPPORTED)
|
||||
/* shift pixel values to take advantage of whole range. Pass the
|
||||
true number of bits in bit_depth. The row should be packed
|
||||
according to row_info->bit_depth. Thus, if you had a row of
|
||||
bit depth 4, but the pixels only had values from 0 to 7, you
|
||||
would pass 3 as bit_depth, and this routine would translate the
|
||||
data to 0 to 15. */
|
||||
/* Shift pixel values to take advantage of whole range. Pass the
|
||||
* true number of bits in bit_depth. The row should be packed
|
||||
* according to row_info->bit_depth. Thus, if you had a row of
|
||||
* bit depth 4, but the pixels only had values from 0 to 7, you
|
||||
* would pass 3 as bit_depth, and this routine would translate the
|
||||
* data to 0 to 15.
|
||||
*/
|
||||
void
|
||||
png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
|
||||
{
|
||||
if (row && row_info &&
|
||||
png_debug(1, "in png_do_shift\n");
|
||||
#if defined(PNG_USELESS_TESTS_SUPPORTED)
|
||||
if (row != NULL && row_info != NULL &&
|
||||
#else
|
||||
if (
|
||||
#endif
|
||||
row_info->color_type != PNG_COLOR_TYPE_PALETTE)
|
||||
{
|
||||
int shift_start[4], shift_dec[4];
|
||||
int channels;
|
||||
png_uint_32 channels;
|
||||
|
||||
channels = 0;
|
||||
if (row_info->color_type & PNG_COLOR_MASK_COLOR)
|
||||
@@ -209,7 +224,6 @@ png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
|
||||
{
|
||||
png_bytep bp;
|
||||
png_uint_32 i;
|
||||
int j;
|
||||
png_byte mask;
|
||||
|
||||
if (bit_depth->gray == 1 && row_info->bit_depth == 2)
|
||||
@@ -221,7 +235,8 @@ png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
|
||||
|
||||
for (bp = row, i = 0; i < row_info->rowbytes; i++, bp++)
|
||||
{
|
||||
int v;
|
||||
png_uint_16 v;
|
||||
int j;
|
||||
|
||||
v = *bp;
|
||||
*bp = 0;
|
||||
@@ -238,15 +253,15 @@ png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
|
||||
{
|
||||
png_bytep bp;
|
||||
png_uint_32 i;
|
||||
int j;
|
||||
|
||||
for (bp = row, i = 0; i < row_info->width; i++)
|
||||
{
|
||||
int c;
|
||||
png_uint_32 c;
|
||||
|
||||
for (c = 0; c < channels; c++, bp++)
|
||||
{
|
||||
int v;
|
||||
png_uint_16 v;
|
||||
int j;
|
||||
|
||||
v = *bp;
|
||||
*bp = 0;
|
||||
@@ -264,20 +279,17 @@ png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
|
||||
{
|
||||
png_bytep bp;
|
||||
png_uint_32 i;
|
||||
int j;
|
||||
|
||||
for (bp = row, i = 0;
|
||||
i < row_info->width * row_info->channels;
|
||||
i++)
|
||||
for (bp = row, i = 0; i < row_info->width * row_info->channels; i++)
|
||||
{
|
||||
int c;
|
||||
png_uint_32 c;
|
||||
|
||||
for (c = 0; c < channels; c++, bp += 2)
|
||||
{
|
||||
png_uint_16 value, v;
|
||||
int j;
|
||||
|
||||
v = (png_uint_16)(((png_uint_16)(*bp) << 8) +
|
||||
(png_uint_16)(*(bp + 1)));
|
||||
v = ((png_uint_16)(*bp) << 8) + *(bp + 1);
|
||||
value = 0;
|
||||
for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
|
||||
{
|
||||
@@ -295,51 +307,88 @@ png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PNG_WRITE_FILLER_SUPPORTED
|
||||
/* remove filler byte */
|
||||
#if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
|
||||
void
|
||||
png_do_write_filler(png_row_infop row_info, png_bytep row,
|
||||
png_byte flags)
|
||||
png_do_write_swap_alpha(png_row_infop row_info, png_bytep row)
|
||||
{
|
||||
if (row && row_info && row_info->color_type == PNG_COLOR_TYPE_RGB &&
|
||||
row_info->bit_depth == 8)
|
||||
png_debug(1, "in png_do_write_swap_alpha\n");
|
||||
#if defined(PNG_USELESS_TESTS_SUPPORTED)
|
||||
if (row != NULL && row_info != NULL)
|
||||
#endif
|
||||
{
|
||||
if (flags & PNG_FLAG_FILLER_AFTER)
|
||||
if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
|
||||
{
|
||||
png_bytep sp, dp;
|
||||
|
||||
png_uint_32 i;
|
||||
|
||||
for (i = 1, sp = row + 4, dp = row + 3;
|
||||
i < row_info->width;
|
||||
i++)
|
||||
/* This converts from ARGB to RGBA */
|
||||
if (row_info->bit_depth == 8)
|
||||
{
|
||||
*dp++ = *sp++;
|
||||
*dp++ = *sp++;
|
||||
*dp++ = *sp++;
|
||||
sp++;
|
||||
png_bytep sp, dp;
|
||||
png_byte save;
|
||||
png_uint_32 i;
|
||||
|
||||
for (i = 0, sp = dp = row; i < row_info->width; i++)
|
||||
{
|
||||
save = *(sp++);
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = save;
|
||||
}
|
||||
}
|
||||
/* This converts from AARRGGBB to RRGGBBAA */
|
||||
else
|
||||
{
|
||||
png_bytep sp, dp;
|
||||
png_byte save[2];
|
||||
png_uint_32 i;
|
||||
|
||||
for (i = 0, sp = dp = row; i < row_info->width; i++)
|
||||
{
|
||||
save[0] = *(sp++);
|
||||
save[1] = *(sp++);
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = save[0];
|
||||
*(dp++) = save[1];
|
||||
}
|
||||
}
|
||||
row_info->channels = 3;
|
||||
row_info->pixel_depth = 24;
|
||||
row_info->rowbytes = row_info->width * 3;
|
||||
}
|
||||
else
|
||||
else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
|
||||
{
|
||||
png_bytep sp, dp;
|
||||
png_uint_32 i;
|
||||
|
||||
for (i = 0, sp = row, dp = row;
|
||||
i < row_info->width;
|
||||
i++)
|
||||
/* This converts from AG to GA */
|
||||
if (row_info->bit_depth == 8)
|
||||
{
|
||||
sp++;
|
||||
*dp++ = *sp++;
|
||||
*dp++ = *sp++;
|
||||
*dp++ = *sp++;
|
||||
png_bytep sp, dp;
|
||||
png_byte save;
|
||||
png_uint_32 i;
|
||||
|
||||
for (i = 0, sp = dp = row; i < row_info->width; i++)
|
||||
{
|
||||
save = *(sp++);
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = save;
|
||||
}
|
||||
}
|
||||
/* This converts from AAGG to GGAA */
|
||||
else
|
||||
{
|
||||
png_bytep sp, dp;
|
||||
png_byte save[2];
|
||||
png_uint_32 i;
|
||||
|
||||
for (i = 0, sp = dp = row; i < row_info->width; i++)
|
||||
{
|
||||
save[0] = *(sp++);
|
||||
save[1] = *(sp++);
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = save[0];
|
||||
*(dp++) = save[1];
|
||||
}
|
||||
}
|
||||
row_info->channels = 3;
|
||||
row_info->pixel_depth = 24;
|
||||
row_info->rowbytes = row_info->width * 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
1236
pngwutil.c
1236
pngwutil.c
File diff suppressed because it is too large
Load Diff
106
readme.txt
106
readme.txt
@@ -1,106 +0,0 @@
|
||||
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.
|
||||
|
||||
The callback functions for the error/warning messages have changed
|
||||
since the last 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
|
||||
OK after re-compiling. This means that calls to png_set_message_fn()
|
||||
no longer exist, because the previously suggested method of calling
|
||||
them before png_read_init() or png_write_init() is now ineffective.
|
||||
|
||||
The preferred method of setting the error and warning callbacks
|
||||
has been incorporated into the allocation of the png_struct and
|
||||
info_struct itself, which allow them to be safely used during the
|
||||
initialization of the structure, as well as to keep the size of
|
||||
the png_struct internal to the library, rather than at compile time
|
||||
of the application. This will hopefully remove any problems with
|
||||
dynamically linked libraries, and should be considered the preferred
|
||||
method of creating these structures, although the previous
|
||||
initialization API is still available for compatibility. See libpng.txt
|
||||
for more information on the new API.
|
||||
|
||||
The changes made to the library, and bugs fixed are based on discussions
|
||||
on the PNG implementation mailing list <png-implement@dworking.wustl.edu>
|
||||
and not on material submitted to Guy.
|
||||
|
||||
For a detailed description on using libpng, read libpng.txt. For
|
||||
usage information and restrictions (what little they are) on libpng,
|
||||
see png.h. For a description on using zlib (the compression library
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
This code is currently being archived at ftp.uu.net in the
|
||||
/graphics/png directory, and on CompuServe, Lib 20 (PNG SUPPORT)
|
||||
at GO GRAPHSUP. If you can't find it in any of those places,
|
||||
e-mail me, and I'll help you find it.
|
||||
|
||||
If you have any code changes, requests, problems, etc., please e-mail
|
||||
them to me. Also, I'd appreciate any make files or project files,
|
||||
and any modifications you needed to make to get libpng to compile,
|
||||
along with a #define variable to tell what compiler/system you are on.
|
||||
If you needed to add transformations to libpng, or wish libpng would
|
||||
provide the image in a different way, drop me a note (and code, if
|
||||
possible), so I can consider supporting the transformation.
|
||||
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.
|
||||
|
||||
adilger@enel.ucalgary.ca
|
||||
png-implement@dworkin.wustl.edu
|
||||
|
||||
You can reach Guy, the original libpng author, at (internet preferred):
|
||||
|
||||
internet: schalnat@group42.com
|
||||
CompuServe: 75501,1625
|
||||
|
||||
Please do not send 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
|
||||
get them in the end anyway. If you have a question about something
|
||||
in the PNG specification that is related to using libpng, send it
|
||||
to me. Send me any questions that start with "I was using libpng,
|
||||
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
|
||||
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.
|
||||
|
||||
Good luck, and happy coding.
|
||||
|
||||
-Guy Eric Schalnat
|
||||
Group 42, Inc.
|
||||
Internet: schalnat@group42.com
|
||||
CompuServe: 75501,1625
|
||||
Web: www.group42.com
|
||||
|
||||
Reference in New Issue
Block a user