libPNG 1.0.3
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2216 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
103
src/png/CHANGES
103
src/png/CHANGES
@@ -283,6 +283,107 @@ version 1.0.0b [March 13, 1998]
|
||||
Minor changes to makefile.s2x
|
||||
Removed #ifdef/#endif around a png_free() in pngread.c
|
||||
version 1.0.1 [March 14, 1998]
|
||||
Changes makefile.s2x to reduce security risk of using a relative pathname
|
||||
Changed makefile.s2x to reduce security risk of using a relative pathname
|
||||
Fixed some typos in the documentation (Greg).
|
||||
Fixed a problem with value of "channels" returned by png_read_update_info()
|
||||
version 1.0.1a [April 21, 1998]
|
||||
Optimized Paeth calculations by replacing abs() function calls with intrinsics
|
||||
plus other loop optimizations. Improves avg decoding speed by about 20%.
|
||||
Commented out i386istic "align" compiler flags in makefile.lnx.
|
||||
Reduced the default warning level in some makefiles, to make them consistent.
|
||||
Removed references to IJG and JPEG in the ansi2knr.c copyright statement.
|
||||
Fixed a bug in png_do_strip_filler with XXRRGGBB => RRGGBB transformation.
|
||||
Added grayscale and 16-bit capability to png_do_read_filler().
|
||||
Fixed a bug in pngset.c, introduced in version 0.99c, that sets rowbytes
|
||||
too large when writing an image with bit_depth < 8 (Bob Dellaca).
|
||||
Corrected some bugs in the experimental weighted filtering heuristics.
|
||||
Moved a misplaced pngrutil code block that truncates tRNS if it has more
|
||||
than num_palette entries -- test was done before num_palette was defined.
|
||||
Fixed a png_convert_to_rfc1123() bug that converts day 31 to 0 (Steve Eddins).
|
||||
Changed compiler flags in makefile.wat for better optimization (Pawel Mrochen).
|
||||
version 1.0.1b [May 2, 1998]
|
||||
Relocated png_do_gray_to_rgb() within png_do_read_transformations() (Greg).
|
||||
Relocated the png_composite macros from pngrtran.c to png.h (Greg).
|
||||
Added makefile.sco (contributed by Mike Hopkirk).
|
||||
Fixed two bugs (missing definitions of "istop") introduced in libpng-1.0.1a.
|
||||
Fixed a bug in pngrtran.c that would set channels=5 under some circumstances.
|
||||
More work on the Paeth-filtering, achieving imperceptible speedup (A Kleinert).
|
||||
More work on loop optimization which may help when compiled with C++ compilers.
|
||||
Added warnings when people try to use transforms they've defined out.
|
||||
Collapsed 4 "i" and "c" loops into single "i" loops in pngrtran and pngwtran.
|
||||
Revised paragraph about png_set_expand() in libpng.txt and libpng.3 (Greg)
|
||||
version 1.0.1c [May 11, 1998]
|
||||
Fixed a bug in pngrtran.c (introduced in libpng-1.0.1a) where the masks for
|
||||
filler bytes should have been 0xff instead of 0xf.
|
||||
Added max_pixel_depth=32 in pngrutil.c when using FILLER with palette images.
|
||||
Moved PNG_WRITE_WEIGHTED_FILTER_SUPPORTED and PNG_WRITE_FLUSH_SUPPORTED
|
||||
out of the PNG_WRITE_TRANSFORMS_NOT_SUPPORTED block of pngconf.h
|
||||
Added "PNG_NO_WRITE_TRANSFORMS" etc., as alternatives for *_NOT_SUPPORTED,
|
||||
for consistency, in pngconf.h
|
||||
Added individual "ifndef PNG_NO_[CAPABILITY]" in pngconf.h to make it easier
|
||||
to remove unwanted capabilities via the compile line
|
||||
Made some corrections to grammar (which, it's) in documentation (Greg).
|
||||
Corrected example.c, use of row_pointers in png_write_image().
|
||||
version 1.0.1d [May 24, 1998]
|
||||
Corrected several statements that used side effects illegally in pngrutil.c
|
||||
and pngtrans.c, that were introduced in version 1.0.1b
|
||||
Revised png_read_rows() to avoid repeated if-testing for NULL (A Kleinert)
|
||||
More corrections to example.c, use of row_pointers in png_write_image()
|
||||
and png_read_rows().
|
||||
Added pngdll.mak and pngdef.pas to scripts directory, contributed by
|
||||
Bob Dellaca, to make a png32bd.dll with Borland C++ 4.5
|
||||
Fixed error in example.c with png_set_text: num_text is 3, not 2 (Guido V.)
|
||||
Changed several loops from count-down to count-up, for consistency.
|
||||
version 1.0.1e [June 6, 1998]
|
||||
Revised libpng.txt and libpng.3 description of png_set_read|write_fn(), and
|
||||
added warnings when people try to set png_read_fn and png_write_fn in
|
||||
the same structure.
|
||||
Added a test such that png_do_gamma will be done when num_trans==0
|
||||
for truecolor images that have defined a background. This corrects an
|
||||
error that was introduced in libpng-0.90 that can cause gamma processing
|
||||
to be skipped.
|
||||
Added tests in png.h to include "trans" and "trans_values" in structures
|
||||
when PNG_READ_BACKGROUND_SUPPORTED or PNG_READ_EXPAND_SUPPORTED is defined.
|
||||
Add png_free(png_ptr->time_buffer) in png_destroy_read_struct()
|
||||
Moved png_convert_to_rfc_1123() from pngwrite.c to png.c
|
||||
Added capability for user-provided malloc_fn() and free_fn() functions,
|
||||
and revised pngtest.c to demonstrate their use, replacing the
|
||||
PNGTEST_DEBUG_MEM feature.
|
||||
Added makefile.w32, for Microsoft C++ 4.0 and later (Tim Wegner).
|
||||
version 1.0.2 [June 14, 1998]
|
||||
Fixed two bugs in makefile.bor .
|
||||
version 1.0.2a [December 30, 1998]
|
||||
Replaced and extended code that was removed from png_set_filler() in 1.0.1a.
|
||||
Fixed a bug in png_do_filler() that made it fail to write filler bytes in
|
||||
the left-most pixel of each row (Kevin Bracey).
|
||||
Changed "static pngcharp tIME_string" to "static char tIME_string[30]"
|
||||
in pngtest.c (Duncan Simpson).
|
||||
Fixed a bug in pngtest.c that caused pngtest to try to write a tIME chunk
|
||||
even when no tIME chunk was present in the source file.
|
||||
Fixed a problem in pngrutil.c: gray_to_rgb didn't always work with 16-bit.
|
||||
Fixed a problem in png_read_push_finish_row(), which would not skip some
|
||||
passes that it should skip, for images that are less than 3 pixels high.
|
||||
Interchanged the order of calls to png_do_swap() and png_do_shift()
|
||||
in pngwtran.c (John Cromer).
|
||||
Added #ifdef PNG_DEBUG/#endif surrounding use of PNG_DEBUG in png.h .
|
||||
Changed "bad adaptive filter type" from error to warning in pngrutil.c .
|
||||
Fixed a documentation error about default filtering with 8-bit indexed-color.
|
||||
Separated the PNG_NO_STDIO macro into PNG_NO_STDIO and PNG_NO_CONSOLE_IO
|
||||
(L. Peter Deutsch).
|
||||
Added png_set_rgb_to_gray() and png_get_rgb_to_gray_status() functions.
|
||||
Added png_get_copyright() and png_get_header_version() functions.
|
||||
Revised comments on png_set_progressive_read_fn() in libpng.txt and example.c
|
||||
Added information about debugging in libpng.txt and libpng.3 .
|
||||
Changed "ln -sf" to "ln -s -f" in makefile.s2x, makefile.lnx, and makefile.sco.
|
||||
Removed lines after Dynamic Dependencies" in makefile.aco .
|
||||
Revised makefile.dec to make a shared library (Jeremie Petit).
|
||||
Removed trailing blanks from all files.
|
||||
version 1.0.2a [January 6, 1999]
|
||||
Removed misplaced #endif and #ifdef PNG_NO_EXTERN near the end of png.h
|
||||
Added "if" tests to silence complaints about unused png_ptr in png.h and png.c
|
||||
Changed "check_if_png" function in example.c to return true (nonzero) if PNG.
|
||||
Changed libpng.txt to demonstrate png_sig_cmp() instead of png_check_sig()
|
||||
which is obsolete.
|
||||
version 1.0.3 [January 14, 1999]
|
||||
Added makefile.hux, for Hewlett Packard HPUX 10.20 and 11.00 (Jim Rice)
|
||||
Added a statement of Y2K compliance in png.h, libpng.1, and Y2KINFO.
|
||||
|
@@ -1,5 +1,5 @@
|
||||
|
||||
Installing libpng version 1.0.1 March 15, 1998
|
||||
Installing libpng version 1.0.3 - January 14, 1999
|
||||
|
||||
Before installing libpng, you must first install zlib. zlib
|
||||
can usually be found wherever you got libpng. zlib can be
|
||||
@@ -10,8 +10,8 @@ zlib.h and zconf.h include files that correspond to the
|
||||
version of zlib that's installed.
|
||||
|
||||
You can rename the directories that you downloaded (they
|
||||
might be called "libpng-1.0.1 or "lpng100" and "zlib-1.1.1"
|
||||
or "zlib111") so that you have directories called "zlib" and "libpng".
|
||||
might be called "libpng-1.0.3" or "lpng103" and "zlib-1.1.3"
|
||||
or "zlib113") so that you have directories called "zlib" and "libpng".
|
||||
|
||||
Your directory structure should look like this:
|
||||
|
||||
@@ -42,6 +42,7 @@ include
|
||||
makefile.std => Generic UNIX makefile
|
||||
makefile.knr => Archaic UNIX Makefile that converts files with ansi2knr
|
||||
makefile.dec => DEC Alpha UNIX makefile
|
||||
makefile.hux => HPUX (10.20 and 11.00) makefile
|
||||
makefile.sgi => Silicon Graphics IRIX makefile
|
||||
makefile.sun => Sun makefile
|
||||
makefile.s2x => Solaris 2.X makefile (gcc, creates libpng.so.2.1.0)
|
||||
@@ -56,11 +57,14 @@ include
|
||||
build.bat => MS-DOS batch file for Borland compiler
|
||||
makefile.dj2 => DJGPP 2 makefile
|
||||
makefile.msc => Microsoft C makefile
|
||||
makefile.w32 => makefile for Microsoft Visual C++ 4.0 and later
|
||||
makefile.tc3 => Turbo C 3.0 makefile
|
||||
makefile.os2 => OS/2 Makefile (gcc and emx, requires pngos2.def)
|
||||
pngos2.def => OS/2 module definition file used by makefile.os2
|
||||
makefile.wat => Watcom 10a+ Makefile, 32-bit flat memory model
|
||||
makevms.com => VMS build script
|
||||
pngdll.mak => To make a png32bd.dll with Borland C++ 4.5
|
||||
pngdef.pas => Defines for a png32bd.dll with Borland C++ 4.5
|
||||
|
||||
Copy the file (or files) that you need from the
|
||||
scripts directory into this directory, for example
|
||||
|
@@ -1,4 +1,4 @@
|
||||
README for libpng 1.0.1 (shared library 2.1)
|
||||
README for libpng 1.0.3 - January 14, 1999 (shared library 2.1)
|
||||
See the note about version numbers near the top of png.h
|
||||
|
||||
See INSTALL for instructions on how to install libpng.
|
||||
@@ -159,6 +159,7 @@ Files in this distribution:
|
||||
makefile.std => Generic UNIX makefile
|
||||
makefile.knr => Archaic UNIX Makefile that converts files with ansi2knr
|
||||
makefile.dec => DEC Alpha UNIX makefile
|
||||
makefile.hux => HPUX (10.20 and 11.00) makefile
|
||||
makefile.sgi => Silicon Graphics IRIX makefile
|
||||
makefile.sun => Sun makefile
|
||||
makefile.s2x => Solaris 2.X makefile (gcc, creates libpng.so.2.1.0)
|
||||
@@ -173,11 +174,14 @@ Files in this distribution:
|
||||
build.bat => MS-DOS batch file for Borland compiler
|
||||
makefile.dj2 => DJGPP 2 makefile
|
||||
makefile.msc => Microsoft C makefile
|
||||
makefile.w32 => makefile for Microsoft Visual C++ 4.0 and later
|
||||
makefile.tc3 => Turbo C 3.0 makefile
|
||||
makefile.os2 => OS/2 Makefile (gcc and emx, requires pngos2.def)
|
||||
makefile.wat => Watcom 10a+ Makefile, 32-bit flat memory model
|
||||
pngos2.def => OS/2 module definition file used by makefile.os2
|
||||
makevms.com => VMS build script
|
||||
pngdll.mak => To make a png32bd.dll with Borland C++ 4.5
|
||||
pngdef.pas => Defines for a png32bd.dll with Borland C++ 4.5
|
||||
|
||||
Good luck, and happy coding.
|
||||
|
||||
|
44
src/png/TODO
44
src/png/TODO
@@ -1,22 +1,24 @@
|
||||
TODO - list of things to do for libpng
|
||||
TODO - list of things to do for libpng:
|
||||
|
||||
fix problem with C++ and EXTERN "C"
|
||||
add "grayscale->palette" transformation and "palette->grayscale" detection
|
||||
add "grayscale" -> "grayscale+alpha" and "grayscale+FILLER" transformations
|
||||
improved dithering
|
||||
multi-lingual error and warning message support
|
||||
sPLT chunk handling
|
||||
cHRM transformation
|
||||
complete sRGB transformation (presently it simply uses gamma=0.45)
|
||||
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)
|
||||
Final bug fixes.
|
||||
Fix problem with C++ and EXTERN "C".
|
||||
Better C++ wrapper/full C++ implementation?
|
||||
Keep up with public chunks.
|
||||
sPLT chunk handling.
|
||||
cHRM transformation.
|
||||
Support for application-defined chunk handlers.
|
||||
Improve setjmp/longjmp usage or remove it in favor of returning error codes.
|
||||
High-level API for reading images.
|
||||
Add "grayscale->palette" transformation and "palette->grayscale" detection.
|
||||
Color to gray transformation.
|
||||
Improved dithering.
|
||||
Multi-lingual error and warning message support.
|
||||
Complete sRGB transformation (presently it simply uses gamma=0.45455).
|
||||
Man pages for function calls.
|
||||
Better documentation.
|
||||
Better filter selection
|
||||
(counting huffman bits/precompression? filter inertia? filter costs?).
|
||||
Optional palette (sPLT) creation.
|
||||
Histogram creation.
|
||||
Text conversion between different code pages (Latin-1 -> Mac and DOS).
|
||||
Improve API by hiding the info_ptr.
|
||||
|
@@ -1,7 +1,9 @@
|
||||
/* ansi2knr.c */
|
||||
/* Convert ANSI C function definitions to K&R ("traditional C") syntax */
|
||||
|
||||
/*
|
||||
/* Convert ANSI C function definitions to K&R ("traditional C") syntax
|
||||
Copyright (C) 1989 Aladdin Enterprises. All rights reserved.
|
||||
Copyright (C) 1988 Richard M. Stallman
|
||||
|
||||
ansi2knr is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY. No author or distributor accepts responsibility to anyone for the
|
||||
consequences of using it or for whether it serves any particular purpose or
|
||||
@@ -12,12 +14,12 @@ Everyone is granted permission to copy, modify and redistribute ansi2knr,
|
||||
but only under the conditions described in the GPL. A copy of this license
|
||||
is supposed to have been given to you along with ansi2knr so you can know
|
||||
your rights and responsibilities. It should be in a file named COPYLEFT.
|
||||
[In the IJG distribution, the GPL appears below, not in a separate file.]
|
||||
[In the LIBPNG distribution, the GPL appears below, not in a separate file.]
|
||||
Among other things, the copyright notice and this notice must be preserved
|
||||
on all copies.
|
||||
|
||||
We explicitly state here what we believe is already implied by the GPL: if
|
||||
the ansi2knr program is distributed as a separate set of sources and a
|
||||
the ansi2knr program is distributed as a separate source file and a
|
||||
separate executable file which are aggregated on a storage medium together
|
||||
with another program, this in itself does not bring the other program under
|
||||
the GPL, nor does the mere fact that such a program or the procedures for
|
||||
@@ -27,7 +29,7 @@ program under the GPL.
|
||||
|
||||
/*
|
||||
---------- Here is the GNU GPL file COPYLEFT, referred to above ----------
|
||||
----- These terms do NOT apply to the JPEG software itself; see README ------
|
||||
----- These terms do NOT apply to the LIBPNG software itself; see README ------
|
||||
|
||||
GHOSTSCRIPT GENERAL PUBLIC LICENSE
|
||||
(Clarified 11 Feb 1988)
|
||||
|
@@ -13,10 +13,13 @@
|
||||
* working PNG reader/writer, see pngtest.c, included in this distribution.
|
||||
*/
|
||||
|
||||
#include "../png/png.h"
|
||||
#include "png.h"
|
||||
|
||||
/* Check to see if a file is a PNG file using png_sig_cmp(). Returns
|
||||
* non-zero if the image is a PNG, and 0 if it isn't a PNG.
|
||||
/* Check to see if a file is a PNG file using png_sig_cmp(). png_sig_cmp()
|
||||
* returns zero if the image is a PNG and nonzero if it isn't a PNG.
|
||||
*
|
||||
* The function check_if_png() shown here, but not used, returns nonzero (true)
|
||||
* if the file can be opened and is a PNG, 0 (false) otherwise.
|
||||
*
|
||||
* 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
|
||||
@@ -41,12 +44,14 @@ int check_if_png(char *file_name, FILE **fp)
|
||||
if ((*fp = fopen(file_name, "rb")) != NULL);
|
||||
return 0;
|
||||
|
||||
/* Read in the signature bytes */
|
||||
/* Read in some of the signature bytes */
|
||||
if (fread(buf, 1, PNG_BYTES_TO_CHECK, *fp) != PNG_BYTES_TO_CHECK)
|
||||
return 0;
|
||||
|
||||
/* Compare the first PNG_BYTES_TO_CHECK bytes of the signature. */
|
||||
return(png_sig_cmp(buf, (png_size_t)0, PNG_BYTES_TO_CHECK));
|
||||
/* Compare the first PNG_BYTES_TO_CHECK bytes of the signature.
|
||||
Return nonzero (true) if they match */
|
||||
|
||||
return(!png_sig_cmp(buf, (png_size_t)0, PNG_BYTES_TO_CHECK));
|
||||
}
|
||||
|
||||
/* Read a PNG file. You may want to return an error code if the read
|
||||
@@ -83,7 +88,7 @@ void read_png(FILE *fp, unsigned int sig_read) /* file is already open */
|
||||
* 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);
|
||||
png_voidp user_error_ptr, user_error_fn, user_warning_fn);
|
||||
|
||||
if (png_ptr == NULL)
|
||||
{
|
||||
@@ -221,10 +226,13 @@ void read_png(FILE *fp, unsigned int sig_read) /* file is already open */
|
||||
if (png_get_sRGB(png_ptr, info_ptr, &intent))
|
||||
png_set_sRGB(png_ptr, intent, 0);
|
||||
else
|
||||
{
|
||||
double image_gamma;
|
||||
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.50);
|
||||
png_set_gamma(png_ptr, screen_gamma, 0.45455);
|
||||
}
|
||||
|
||||
/* Dither RGB files down to 8 bit palette or reduce palettes
|
||||
* to the number of colors available on your screen.
|
||||
@@ -316,18 +324,18 @@ void read_png(FILE *fp, unsigned int sig_read) /* file is already open */
|
||||
#ifdef single /* 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);
|
||||
png_read_rows(png_ptr, &row_pointers[y], NULL, 1);
|
||||
}
|
||||
|
||||
#else no_single /* Read the image several rows at a time */
|
||||
for (y = 0; y < height; y += number_of_rows)
|
||||
{
|
||||
#ifdef sparkle /* Read the image using the "sparkle" effect. */
|
||||
png_read_rows(png_ptr, row_pointers, NULL, number_of_rows);
|
||||
png_read_rows(png_ptr, &row_pointers[y], NULL, number_of_rows);
|
||||
|
||||
png_read_rows(png_ptr, NULL, row_pointers[y], number_of_rows);
|
||||
#else no_sparkle /* Read the image using the "rectangle" effect */
|
||||
png_read_rows(png_ptr, NULL, row_pointers, number_of_rows);
|
||||
png_read_rows(png_ptr, NULL, &row_pointers[y], number_of_rows);
|
||||
#endif no_sparkle /* use only one of these two methods */
|
||||
}
|
||||
|
||||
@@ -362,7 +370,7 @@ initialize_png_reader(png_structp *png_ptr, png_infop *info_ptr)
|
||||
* linked libraries.
|
||||
*/
|
||||
*png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,
|
||||
(void *)user_error_ptr, user_error_fn, user_warning_fn);
|
||||
png_voidp user_error_ptr, user_error_fn, user_warning_fn);
|
||||
|
||||
if (*png_ptr == NULL)
|
||||
{
|
||||
@@ -384,8 +392,11 @@ initialize_png_reader(png_structp *png_ptr, png_infop *info_ptr)
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
/* this one's new. You will need to provide all three
|
||||
/* This one's new. You will need to provide all three
|
||||
* function callbacks, even if you aren't using them all.
|
||||
* If you aren't using all functions, you can specify NULL
|
||||
* parameters. Even when all three functions are NULL,
|
||||
* you need to call png_set_progressive_read_fn().
|
||||
* These functions shouldn't be dependent on global or
|
||||
* static variables if you are decoding several images
|
||||
* simultaneously. You should store stream specific data
|
||||
@@ -498,7 +509,7 @@ void write_png(char *file_name /* , ... other image information ... */)
|
||||
* 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);
|
||||
png_voidp user_error_ptr, user_error_fn, user_warning_fn);
|
||||
|
||||
if (png_ptr == NULL)
|
||||
{
|
||||
@@ -581,7 +592,7 @@ void write_png(char *file_name /* , ... other image information ... */)
|
||||
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);
|
||||
png_set_text(png_ptr, info_ptr, text_ptr, 3);
|
||||
|
||||
/* other optional chunks like cHRM, bKGD, tRNS, tIME, oFFs, pHYs, */
|
||||
/* note that if sRGB is present the cHRM chunk must be ignored
|
||||
@@ -638,7 +649,11 @@ void write_png(char *file_name /* , ... other image information ... */)
|
||||
* 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];
|
||||
png_uint_32 k, height, width;
|
||||
png_byte image[height][width];
|
||||
png_bytep row_pointers[height];
|
||||
for (k = 0; k < height; k++)
|
||||
row_pointers[k] = image + k*width;
|
||||
|
||||
/* One of the following output methods is REQUIRED */
|
||||
#ifdef entire /* write out the entire image data in one call */
|
||||
@@ -653,13 +668,12 @@ void write_png(char *file_name /* , ... other image information ... */)
|
||||
for (pass = 0; pass < number_passes; pass++)
|
||||
{
|
||||
/* Write a few rows at a time. */
|
||||
png_write_rows(png_ptr, row_pointers, number_of_rows);
|
||||
png_write_rows(png_ptr, &row_pointers[first_row], number_of_rows);
|
||||
|
||||
/* If you are only writing one row at a time, this works */
|
||||
for (y = 0; y < height; y++)
|
||||
{
|
||||
png_bytep row_pointers = row[y];
|
||||
png_write_rows(png_ptr, &row_pointers, 1);
|
||||
png_write_rows(png_ptr, &row_pointers[y], 1);
|
||||
}
|
||||
}
|
||||
#endif no_entire /* use only one output method */
|
||||
|
364
src/png/libpng.3
364
src/png/libpng.3
@@ -1,6 +1,6 @@
|
||||
.TH LIBPNG 3 "March 15, 1998"
|
||||
.TH LIBPNG 3 "January 14, 1999"
|
||||
.SH NAME
|
||||
libpng \- Portable Network Graphics (PNG) Reference Library
|
||||
libpng \- Portable Network Graphics (PNG) Reference Library 1.0.3 - January 14, 1999
|
||||
.SH SYNOPSIS
|
||||
|
||||
#include <png.h>
|
||||
@@ -27,14 +27,25 @@ png_structp png_create_read_struct (png_const_charp
|
||||
user_png_ver, voidp error_ptr, png_error_ptr error_fn,
|
||||
png_error_ptr warn_fn);
|
||||
|
||||
png_structp png_create_read_struct_2(png_const_charp user_png_ver,
|
||||
png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr
|
||||
warn_fn, png_voidp mem_ptr, png_malloc_ptr malloc_fn,
|
||||
png_free_ptr free_fn)
|
||||
|
||||
png_structp png_create_write_struct (png_const_charp
|
||||
user_png_ver, voidp error_ptr, png_error_ptr error_fn,
|
||||
png_error_ptr warn_fn);
|
||||
|
||||
void png_debug_free (png_structp png_ptr, png_voidp ptr);
|
||||
png_structp png_create_write_struct_2(png_const_charp
|
||||
user_png_ver, png_voidp error_ptr, png_error_ptr error_fn,
|
||||
png_error_ptr warn_fn, png_voidp mem_ptr,
|
||||
png_malloc_ptr malloc_fn, png_free_ptr free_fn)
|
||||
|
||||
png_voidp png_debug_malloc (png_structp png_ptr, png_uint_32
|
||||
size);
|
||||
int png_debug(int level, png_const_charp message)
|
||||
|
||||
int png_debug1(int level, png_const_charp message, p1)
|
||||
|
||||
int png_debug2(int level, png_const_charp message, p1, p2)
|
||||
|
||||
void png_destroy_info_struct (png_structp png_ptr, png_infopp
|
||||
info_ptr_ptr);
|
||||
@@ -49,6 +60,8 @@ void png_error (png_structp png_ptr, png_const_charp error);
|
||||
|
||||
void png_free (png_structp png_ptr, png_voidp ptr);
|
||||
|
||||
void png_free_default(png_structp png_ptr, png_voidp ptr)
|
||||
|
||||
png_byte png_get_bit_depth (png_structp png_ptr, png_infop
|
||||
info_ptr);
|
||||
|
||||
@@ -69,6 +82,8 @@ info_ptr);
|
||||
png_byte png_get_compression_type (png_structp png_ptr,
|
||||
png_infop info_ptr);
|
||||
|
||||
png_byte png_get_copyright (png_structp png_ptr);
|
||||
|
||||
png_voidp png_get_error_ptr (png_structp png_ptr);
|
||||
|
||||
png_byte png_get_filter_type (png_structp png_ptr, png_infop
|
||||
@@ -77,9 +92,16 @@ info_ptr);
|
||||
png_uint_32 png_get_gAMA (png_structp png_ptr, png_infop
|
||||
info_ptr, double *file_gamma);
|
||||
|
||||
png_byte png_get_header_version (png_structp png_ptr);
|
||||
|
||||
png_uint_32 png_get_hIST (png_structp png_ptr, png_infop
|
||||
info_ptr, png_uint_16p *hist);
|
||||
|
||||
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);
|
||||
|
||||
png_uint_32 png_get_image_height (png_structp png_ptr,
|
||||
png_infop info_ptr);
|
||||
|
||||
@@ -91,10 +113,7 @@ info_ptr);
|
||||
|
||||
png_voidp png_get_io_ptr (png_structp png_ptr);
|
||||
|
||||
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);
|
||||
png_voidp png_get_mem_ptr(png_structp png_ptr)
|
||||
|
||||
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
|
||||
@@ -119,6 +138,8 @@ png_voidp png_get_progressive_ptr (png_structp png_ptr);
|
||||
png_uint_32 png_get_PLTE (png_structp png_ptr, png_infop
|
||||
info_ptr, png_colorp *palette, int *num_palette);
|
||||
|
||||
png_byte png_get_rgb_to_gray_status (png_structp png_ptr)
|
||||
|
||||
png_uint_32 png_get_rowbytes (png_structp png_ptr, png_infop
|
||||
info_ptr);
|
||||
|
||||
@@ -168,6 +189,9 @@ void png_init_io (png_structp png_ptr, FILE *fp);
|
||||
|
||||
png_voidp png_malloc (png_structp png_ptr, png_uint_32 size);
|
||||
|
||||
png_voidp png_malloc_default(png_structp png_ptr,
|
||||
png_uint_32 size)
|
||||
|
||||
voidp png_memcpy (png_voidp s1, png_voidp s2, png_size_t size);
|
||||
|
||||
png_voidp png_memcpy_check (png_structp png_ptr, png_voidp s1,
|
||||
@@ -276,6 +300,9 @@ png_uint_32 width, png_uint_32 height, int bit_depth, int
|
||||
color_type, int interlace_type, int compression_type, int
|
||||
filter_type);
|
||||
|
||||
void png_set_mem_fn(png_structp png_ptr, png_voidp mem_ptr,
|
||||
png_malloc_ptr malloc_fn, png_free_ptr free_fn)
|
||||
|
||||
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);
|
||||
|
||||
@@ -307,7 +334,7 @@ void png_set_read_status_fn (png_structp png_ptr, png_read_status_ptr
|
||||
void png_set_read_user_transform_fn (png_structp png_ptr,
|
||||
png_user_transform_ptr read_user_transform_fn);
|
||||
|
||||
void png_set_rgb_to_gray (png_structp png_ptr);
|
||||
void png_set_rgb_to_gray (png_structp png_ptr, int error_action);
|
||||
|
||||
void png_set_sBIT (png_structp png_ptr, png_infop info_ptr,
|
||||
png_color_8p sig_bit);
|
||||
@@ -396,10 +423,10 @@ Following is a copy of the libpng.txt file that accompanies libpng.
|
||||
.SH LIBPNG.TXT
|
||||
libpng.txt - A description on how to use and modify libpng
|
||||
|
||||
libpng version 1.0.1 March 15, 1998
|
||||
libpng version 1.0.3 - January 14, 1999
|
||||
Updated and distributed by Glenn Randers-Pehrson
|
||||
<randeg@alumni.rpi.edu>
|
||||
Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
||||
For conditions of distribution and use, see copyright
|
||||
notice in png.h.
|
||||
|
||||
@@ -436,7 +463,8 @@ as RFC 2083 <ftp://ftp.uu.net/graphics/png/documents/> and as a
|
||||
W3C Recommendation <http://www.w3.org/TR/REC.png.html>. Some
|
||||
additional chunks are described in the special-purpose public chunks
|
||||
documents at <ftp://ftp.uu.net/graphics/png/documents/>. Other information
|
||||
about PNG can be found at the PNG home page, <http://www.cdrom.com/pub/png/>.
|
||||
about PNG, and the latest version of libpng, can be found at the PNG home
|
||||
page, <http://www.cdrom.com/pub/png/>.
|
||||
|
||||
Most users will not have to modify the library significantly; advanced
|
||||
users may want to modify it more. All attempts were made to make it as
|
||||
@@ -453,6 +481,8 @@ work to be done (see the TODO file), libpng should cover the
|
||||
majority of the needs of its users.
|
||||
|
||||
Libpng uses zlib for its compression and decompression of PNG files.
|
||||
Further information about zlib, and the latest version of zlib, can
|
||||
be found at the zlib home page, <http://www.cdrom.com/pub/infozip/zlib/>.
|
||||
The zlib compression utility is a general purpose utility that is
|
||||
useful for more than PNG files, and can be used without libpng.
|
||||
See the documentation delivered with zlib for more details.
|
||||
@@ -522,7 +552,7 @@ Customizing libpng.
|
||||
return;
|
||||
}
|
||||
fread(header, 1, number, fp);
|
||||
is_png = png_check_sig(header, 0, number);
|
||||
is_png = !png_sig_cmp(header, 0, number);
|
||||
if (!is_png)
|
||||
{
|
||||
return;
|
||||
@@ -539,7 +569,7 @@ be NULL if the default error handlers are to be used). See the section
|
||||
on Changes to Libpng below regarding the old initialization functions.
|
||||
|
||||
png_structp png_ptr = png_create_read_struct
|
||||
(PNG_LIBPNG_VER_STRING, (void *)user_error_ptr,
|
||||
(PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
|
||||
user_error_fn, user_warning_fn);
|
||||
if (!png_ptr)
|
||||
return;
|
||||
@@ -560,12 +590,23 @@ on Changes to Libpng below regarding the old initialization functions.
|
||||
return;
|
||||
}
|
||||
|
||||
If you want to use your own memory allocation routines,
|
||||
define PNG_USER_MEM_SUPPORTED and use
|
||||
png_create_read_struct_2() instead of png_create_read_struct():
|
||||
|
||||
The error handling routines passed to png_create_read_struct() are only
|
||||
necessary if you are not using the libpng supplied error handling
|
||||
functions. When libpng encounters an error, it expects to longjmp back
|
||||
to your routine. Therefore, you will need to call setjmp and pass the
|
||||
jmpbuf field of your png_struct. If you read the file from different
|
||||
png_structp png_ptr = png_create_read_struct_2
|
||||
(PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
|
||||
user_error_fn, user_warning_fn, (png_voidp)
|
||||
user_mem_ptr, user_malloc_fn, user_free_fn);
|
||||
|
||||
The error handling routines passed to png_create_read_struct()
|
||||
and the memory alloc/free routines passed to png_create_struct_2()
|
||||
are only necessary if you are not using the libpng supplied error
|
||||
handling and memory alloc/free functions.
|
||||
|
||||
When libpng encounters an error, it expects to longjmp back
|
||||
to your routine. Therefore, you will need to call setjmp and pass
|
||||
your png_ptr->jmpbuf. If you read the file from different
|
||||
routines, you will need to update the jmpbuf field every time you enter
|
||||
a new routine that will call a png_ function.
|
||||
|
||||
@@ -876,7 +917,10 @@ in RGBRGBRGB format unless png_set_filler() is called to insert filler
|
||||
bytes, either before or after each RGB triplet. 16-bit RGB data will
|
||||
be returned RRGGBB RRGGBB, with the most significant byte of the color
|
||||
value first, unless png_set_strip_16() is called to transform it to
|
||||
regular RGBRGB triplets.
|
||||
regular RGB RGB triplets, or png_set_filler() is called to insert
|
||||
filler bytes, either before or after each RRGGBB triplet. Similarly,
|
||||
8-bit or 16-bit grayscale data can be modified with png_set_filler()
|
||||
or png_set_strip_16().
|
||||
|
||||
The following code transforms grayscale images of less than 8 to 8 bits,
|
||||
changes paletted images to RGB, and adds a full alpha channel if there is
|
||||
@@ -952,7 +996,7 @@ into 4 bytes for windowing systems that need them in this format:
|
||||
PNG_COLOR_TYPE_RGB) png_set_filler(png_ptr,
|
||||
filler, PNG_FILLER_BEFORE);
|
||||
|
||||
where "filler" is the number to fill with, and the location is
|
||||
where "filler" is the 8 or 16-bit number to fill with, and the location is
|
||||
either PNG_FILLER_BEFORE or PNG_FILLER_AFTER, depending upon whether
|
||||
you want the filler before the RGB or after. This transformation
|
||||
does not affect images that already have full alpha channels.
|
||||
@@ -970,21 +1014,76 @@ RGB. This code will do that conversion:
|
||||
color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
|
||||
png_set_gray_to_rgb(png_ptr);
|
||||
|
||||
Conversely, you can convert an RGB or RGBA image to grayscale or grayscale
|
||||
with alpha. This is intended for conversion of images that really are
|
||||
gray (red == green == blue), so the function simply strips out the red
|
||||
and blue channels, leaving the green channel in the gray position.
|
||||
|
||||
if (color_type == PNG_COLOR_TYPE_RGB ||
|
||||
color_type == PNG_COLOR_TYPE_RGB_ALPHA)
|
||||
png_set_rgb_to_gray(png_ptr, error_action,
|
||||
float red_weight, float green_weight);
|
||||
|
||||
error_action = 1: silently do the conversion
|
||||
error_action = 2: issue a warning if the original
|
||||
image has any pixel where
|
||||
red != green or red != blue
|
||||
error_action = 3: issue an error and abort the
|
||||
conversion if the original
|
||||
image has any pixel where
|
||||
red != green or red != blue
|
||||
|
||||
red_weight: weight of red component
|
||||
(NULL -> default 54/256)
|
||||
green_weight: weight of green component
|
||||
(NULL -> default 183/256)
|
||||
|
||||
If you have set error_action = 1 or 2, you can
|
||||
later check whether the image really was gray, after processing
|
||||
the image rows, with the png_get_rgb_to_gray_status(png_ptr) function.
|
||||
It will return a png_byte that is zero if the image was gray or
|
||||
1 if there were any non-gray pixels. bKGD and sBIT data
|
||||
will be silently converted to grayscale, using the green channel
|
||||
data, regardless of the error_action setting.
|
||||
|
||||
With 0.0<=red_weight+green_weight<=1.0,
|
||||
the normalized graylevel is computed:
|
||||
|
||||
int rw = red_weight * 256;
|
||||
int gw = green_weight * 256;
|
||||
int bw = 256 - (rw + gw);
|
||||
gray = (rw*red + gw*green + bw*blue)/256;
|
||||
|
||||
The default values approximate those recommended in the Charles
|
||||
Poynton's Color FAQ, <http://www.inforamp.net/~poynton/>
|
||||
Copyright (c) 1998-01-04 Charles Poynton poynton@inforamp.net
|
||||
|
||||
Y = 0.212671 * R + 0.715160 * G + 0.072169 * B
|
||||
|
||||
Libpng approximates this with
|
||||
|
||||
Y = 0.211 * R + 0.715 * G + 0.074 * B
|
||||
|
||||
which can be expressed with integers as
|
||||
|
||||
Y = (54 * R + 183 * G + 19 * B)/256
|
||||
|
||||
The calculation is done in a linear colorspace, if the image gamma
|
||||
is known.
|
||||
|
||||
If you have a grayscale and you are using png_set_expand() to change to
|
||||
a higher bit-depth you must indicate if the supplied background gray
|
||||
is supplied in the original file bit depth (need_expand = 1) or in the
|
||||
expanded bit depth (need_expand = 0). Similarly, if you are reading
|
||||
a paletted image, you must indicate if you have supplied the background
|
||||
as a palette index that needs to be expanded (need_expand = 1). You can
|
||||
also specify an RGB triplet that isn't in the palette when setting your
|
||||
background for a paletted image.
|
||||
a higher bit-depth, you must either supply the background color as a gray
|
||||
value at the original file bit-depth (need_expand = 1) or else supply the
|
||||
background color as an RGB triplet at the final, expanded bit depth
|
||||
(need_expand = 0). Similarly, if you are reading a paletted image, you
|
||||
must either supply the background color as a palette index (need_expand = 1)
|
||||
or as an RGB triplet that may or may not be in the palette (need_expand = 0).
|
||||
|
||||
png_color_16 my_background;
|
||||
png_color_16p image_background;
|
||||
|
||||
if (png_get_bKGD(png_ptr, info_ptr,
|
||||
&image_background))
|
||||
png_set_background(png_ptr, image_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,
|
||||
@@ -1031,7 +1130,7 @@ compensation other than the display_gamma is needed (viewing_gamma=1.0).
|
||||
The png_set_gamma() function handles gamma transformations of the data.
|
||||
Pass both the file gamma and the current screen_gamma. If the file does
|
||||
not have a gamma value, you can pass one anyway if you have an idea what
|
||||
it is (usually 0.50 is a good guess for GIF images on PCs). Note
|
||||
it is (usually 0.45455 is a good guess for GIF images on PCs). Note
|
||||
that file gammas are inverted from screen gammas. See the discussions
|
||||
on gamma in the PNG specification for an excellent description of what
|
||||
gamma is, and why all applications should support it. It is strongly
|
||||
@@ -1040,7 +1139,7 @@ recommended that PNG viewers support gamma correction.
|
||||
if (png_get_gAMA(png_ptr, info_ptr, &gamma))
|
||||
png_set_gamma(png_ptr, screen_gamma, gamma);
|
||||
else
|
||||
png_set_gamma(png_ptr, screen_gamma, 0.50);
|
||||
png_set_gamma(png_ptr, screen_gamma, 0.45455);
|
||||
|
||||
If you need to reduce an RGB file to a paletted file, or if a paletted
|
||||
file has more entries then will fit on your screen, png_set_dither()
|
||||
@@ -1268,7 +1367,7 @@ png_infop info_ptr;
|
||||
initialize_png_reader()
|
||||
{
|
||||
png_ptr = png_create_read_struct
|
||||
(PNG_LIBPNG_VER_STRING, (void *)user_error_ptr,
|
||||
(PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
|
||||
user_error_fn, user_warning_fn);
|
||||
if (!png_ptr)
|
||||
return -1;
|
||||
@@ -1291,7 +1390,9 @@ png_infop info_ptr;
|
||||
to be called when the header info is valid,
|
||||
when each row is completed, and when the image
|
||||
is finished. If you aren't using all functions,
|
||||
you can specify a NULL parameter. You can use
|
||||
you can specify NULL parameters. Even when all
|
||||
three functions are NULL, you need to call
|
||||
png_set_progressive_read_fn(). You can use
|
||||
any struct as the user_ptr (cast to a void pointer
|
||||
for the function call), and retrieve the pointer
|
||||
from inside the callbacks using the function
|
||||
@@ -1337,7 +1438,7 @@ png_infop info_ptr;
|
||||
}
|
||||
|
||||
/* This function is called (as set by
|
||||
png_set_progressive_fn() above) when enough data
|
||||
png_set_progressive_read_fn() above) when enough data
|
||||
has been supplied so all of the header has been
|
||||
read.
|
||||
*/
|
||||
@@ -1387,8 +1488,8 @@ png_infop info_ptr;
|
||||
new_row);
|
||||
|
||||
/* where old_row is what was displayed for
|
||||
previous rows. Note that the first pass
|
||||
(pass == 0, really) will completely cover
|
||||
previously for the row. 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
|
||||
@@ -1412,6 +1513,8 @@ png_infop info_ptr;
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
.SH IV. Writing
|
||||
|
||||
Much of this is very similar to reading. However, everything of
|
||||
@@ -1438,7 +1541,7 @@ both "png_ptr"; you can call them anything you like, such as
|
||||
"read_ptr" and "write_ptr". Look at pngtest.c, for example.
|
||||
|
||||
png_structp png_ptr = png_create_write_struct
|
||||
(PNG_LIBPNG_VER_STRING, (void *)user_error_ptr,
|
||||
(PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
|
||||
user_error_fn, user_warning_fn);
|
||||
if (!png_ptr)
|
||||
return;
|
||||
@@ -1451,10 +1554,19 @@ both "png_ptr"; you can call them anything you like, such as
|
||||
return;
|
||||
}
|
||||
|
||||
If you want to use your own memory allocation routines,
|
||||
define PNG_USER_MEM_SUPPORTED and use
|
||||
png_create_write_struct_2() instead of png_create_read_struct():
|
||||
|
||||
png_structp png_ptr = png_create_write_struct_2
|
||||
(PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,
|
||||
user_error_fn, user_warning_fn, (png_voidp)
|
||||
user_mem_ptr, user_malloc_fn, user_free_fn);
|
||||
|
||||
After you have these structures, you will need to set up the
|
||||
error handling. When libpng encounters an error, it expects to
|
||||
longjmp() back to your routine. Therefore, you will need to call
|
||||
setjmp and pass the jmpbuf field of your png_struct. If you
|
||||
setjmp() and pass the png_ptr->jmpbuf. If you
|
||||
write the file from different routines, you will need to update
|
||||
the jmpbuf field every time you enter a new routine that will
|
||||
call a png_ function. See your documentation of setjmp/longjmp
|
||||
@@ -1468,6 +1580,8 @@ section below for more information on the libpng error handling.
|
||||
fclose(fp);
|
||||
return;
|
||||
}
|
||||
...
|
||||
return;
|
||||
|
||||
Now you need to set up the output code. The default for libpng is to
|
||||
use the C function fwrite(). If you use this, you will need to pass a
|
||||
@@ -1504,9 +1618,9 @@ not calling this function at all, as it has been tuned to deliver a good
|
||||
speed/compression ratio. The second parameter to png_set_filter() is
|
||||
the filter method, for which the only valid value is '0' (as of the
|
||||
October 1996 PNG specification, version 1.0). The third parameter is a
|
||||
flag that indicates
|
||||
which filter type(s) are to be tested for each scanline. See the
|
||||
Compression Library for details on the specific filter types.
|
||||
flag that indicates which filter type(s) are to be tested for each
|
||||
scanline. See the Compression Library for details on the specific filter
|
||||
types.
|
||||
|
||||
|
||||
/* turn on or off filtering, and/or choose
|
||||
@@ -1698,7 +1812,7 @@ png_text structure holds a keyword-text value, and a compression type.
|
||||
The compression types have the same valid numbers as the compression
|
||||
types of the image data. Currently, the only valid number is zero.
|
||||
However, you can store text either compressed or uncompressed, unlike
|
||||
images which always have to be compressed. So if you don't want the
|
||||
images, which always have to be compressed. So if you don't want the
|
||||
text compressed, set the compression type to PNG_TEXT_COMPRESSION_NONE.
|
||||
Until text gets around 1000 bytes, it is not worth compressing it.
|
||||
After the text has been written out to the file, the compression type
|
||||
@@ -1758,7 +1872,7 @@ depending on whether you mean the PNG file, the time the image was
|
||||
created in a non-PNG format, a still photo from which the image was
|
||||
scanned, or possibly the subject matter itself. In order to facilitate
|
||||
machine-readable dates, it is recommended that the "Creation Time"
|
||||
tEXt chunk use RFC 1123 format dates (e.g. 22 May 1997 18:07:10 GMT"),
|
||||
tEXt chunk use RFC 1123 format dates (e.g. "22 May 1997 18:07:10 GMT"),
|
||||
although this isn't a requirement. Unlike the tIME chunk, the
|
||||
"Creation Time" tEXt chunk is not expected to be automatically changed
|
||||
by the software. To facilitate the use of RFC 1123 dates, a function
|
||||
@@ -1780,8 +1894,9 @@ checks to see if it has data that it can do something with, you should
|
||||
make sure to only enable a transformation if it will be valid for the
|
||||
data. For example, don't swap red and blue on grayscale data.
|
||||
|
||||
PNG files store RGB pixels packed into 3 bytes. This code tells
|
||||
the library to expect input data with 4 bytes per pixel
|
||||
PNG files store RGB pixels packed into 3 or 6 bytes. This code tells
|
||||
the library to expand the input data to 4 or 8 bytes per pixel
|
||||
(or expand 1 or 2-byte grayscale data to 2 or 4 bytes per pixel).
|
||||
|
||||
png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
|
||||
|
||||
@@ -1899,11 +2014,11 @@ times, or any of that other stuff necessary with png_write_rows().
|
||||
|
||||
where row_pointers is:
|
||||
|
||||
png_bytef *row_pointers[height];
|
||||
png_byte *row_pointers[height];
|
||||
|
||||
You can point to void or char or whatever you use for pixels.
|
||||
|
||||
If you can't want to write the whole image at once, you can
|
||||
If you don't want to write the whole image at once, you can
|
||||
use png_write_rows() instead. If the file is not interlaced,
|
||||
this is simple:
|
||||
|
||||
@@ -1975,7 +2090,7 @@ The second deals with more complicated things like adding new chunks,
|
||||
adding new transformations, and generally changing how libpng works.
|
||||
|
||||
All of the memory allocation, input/output, and error handling in libpng
|
||||
goes through callbacks which are user settable. The default routines are
|
||||
goes through callbacks that are user settable. The default routines are
|
||||
in pngmem.c, pngrio.c, pngwio.c, and pngerror.c respectively. To change
|
||||
these functions, call the appropriate png_set_???_fn() function.
|
||||
|
||||
@@ -1997,14 +2112,15 @@ time, instead of calling the png_init_io() function. These functions
|
||||
also provide a void pointer that can be retrieved via the function
|
||||
png_get_io_ptr(). For example:
|
||||
|
||||
png_set_read_fn(png_structp png_ptr,
|
||||
voidp io_ptr, png_rw_ptr read_data_fn)
|
||||
png_set_read_fn(png_structp read_ptr,
|
||||
voidp read_io_ptr, png_rw_ptr read_data_fn)
|
||||
|
||||
png_set_write_fn(png_structp png_ptr,
|
||||
voidp io_ptr, png_rw_ptr write_data_fn,
|
||||
png_set_write_fn(png_structp write_ptr,
|
||||
voidp write_io_ptr, png_rw_ptr write_data_fn,
|
||||
png_flush_ptr output_flush_fn);
|
||||
|
||||
voidp io_ptr = png_get_io_ptr(png_ptr);
|
||||
voidp read_io_ptr = png_get_io_ptr(read_ptr);
|
||||
voidp write_io_ptr = png_get_io_ptr(write_ptr);
|
||||
|
||||
The replacement I/O functions should have prototypes as follows:
|
||||
|
||||
@@ -2083,7 +2199,7 @@ won't be accessible. So limit zlib and libpng to 64K by defining MAXSEG_64K.
|
||||
|
||||
Configuring for DOS:
|
||||
|
||||
For DOS users which only have access to the lower 640K, you will
|
||||
For DOS users who only have access to the lower 640K, you will
|
||||
have to limit zlib's memory usage via a png_set_compression_mem_level()
|
||||
call. See zlib.h or zconf.h in the zlib library for more information.
|
||||
|
||||
@@ -2095,7 +2211,7 @@ defined, and FAR gets defined to far in pngconf.h, and you should be
|
||||
all set. Everything in the library (except for zlib's structure) is
|
||||
expecting far data. You must use the typedefs with the p or pp on
|
||||
the end for pointers (or at least look at them and be careful). Make
|
||||
note that the row's of data are defined as png_bytepp which is a
|
||||
note that the row's of data are defined as png_bytepp, which is an
|
||||
unsigned char far * far *.
|
||||
|
||||
Configuring for gui/windowing platforms:
|
||||
@@ -2155,8 +2271,8 @@ can call one of these functions. The selection and configuration
|
||||
of row filters can have a significant impact on the size and
|
||||
encoding speed and a somewhat lesser impact on the decoding speed
|
||||
of an image. Filtering is enabled by default for RGB and grayscale
|
||||
images (with and without alpha), and for 8-bit paletted images, but
|
||||
not for paletted images with bit depths less than 8 bits/pixel.
|
||||
images (with and without alpha), but not for paletted images nor
|
||||
for any images with bit depths less than 8 bits/pixel.
|
||||
|
||||
The 'method' parameter sets the main filtering method, which is
|
||||
currently only '0' in the PNG 1.0 specification. The 'filters'
|
||||
@@ -2191,10 +2307,10 @@ by telling it the relative computational costs of the filters.
|
||||
PNG_FILTER_SELECTION_WEIGHTED, 3,
|
||||
weights, costs);
|
||||
|
||||
The weights are multiplying factors which indicate to libpng that row
|
||||
should be the same for successive rows unless another row filter is that
|
||||
many times better than the previous filter. In the above example, if
|
||||
the previous 3 filters were SUB, SUB, NONE, the SUB filter could have a
|
||||
The weights are multiplying factors that indicate to libpng that the
|
||||
row filter should be the same for successive rows unless another row filter
|
||||
is that many times better than the previous filter. In the above example,
|
||||
if the previous 3 filters were SUB, SUB, NONE, the SUB filter could have a
|
||||
"sum of absolute differences" 1.5 x 1.3 times higher than other filters
|
||||
and still be chosen, while the NONE filter could have a sum 1.1 times
|
||||
higher than other filters and still be chosen. Unspecified weights are
|
||||
@@ -2217,19 +2333,23 @@ Removing unwanted object code:
|
||||
|
||||
There are a bunch of #define's in pngconf.h that control what parts of
|
||||
libpng are compiled. All the defines end in _SUPPORTED. If you are
|
||||
never going to use an ability, you can change the #define to #undef
|
||||
before recompiling libpng and save yourself code and data space.
|
||||
You can also turn a number of them off en masse with a compiler directive
|
||||
that defines PNG_READ[or WRITE]_TRANSFORMS_NOT_SUPPORTED, or
|
||||
PNG_READ[or WRITE]_ANCILLARY_CHUNKS_NOT_SUPPORTED, or all four,
|
||||
never going to use a capability, you can change the #define to #undef
|
||||
before recompiling libpng and save yourself code and data space, or
|
||||
you can turn off individual capabilities with defines that begin with
|
||||
PNG_NO_.
|
||||
|
||||
You can also turn all of the transforms and ancillary chunk capabilities
|
||||
off en masse with compiler directives that define
|
||||
PNG_NO_READ[or WRITE]_TRANSFORMS, or PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS,
|
||||
or all four,
|
||||
along with directives to turn on any of the capabilities that you do
|
||||
want. The PNG_READ[or WRITE]_TRANSFORMS_NOT_SUPPORTED directives disable
|
||||
want. The PNG_NO_READ[or WRITE]_TRANSFORMS directives disable
|
||||
the extra transformations but still leave the library fully capable of reading
|
||||
and writing PNG files with all known public chunks [except for sPLT].
|
||||
Use of the PNG_READ[or WRITE]_ANCILLARY_CHUNKS_NOT_SUPPORTED directive
|
||||
Use of the PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS directive
|
||||
produces a library that is incapable of reading or writing ancillary chunks.
|
||||
If you are not using the progressive reading capability, you can
|
||||
turn that off with PNG_PROGRESSIVE_READ_NOT_SUPPORTED (don't confuse
|
||||
turn that off with PNG_NO_PROGRESSIVE_READ (don't confuse
|
||||
this with the INTERLACING capability, which you'll still have).
|
||||
|
||||
All the reading and writing specific code are in separate files, so the
|
||||
@@ -2245,10 +2365,46 @@ or DLL file), you should not remove or disable any parts of the library,
|
||||
as this will cause applications linked with different versions of the
|
||||
library to fail if they call functions not available in your library.
|
||||
The size of the library itself should not be an issue, because only
|
||||
those sections which are actually used will be loaded into memory.
|
||||
those sections that are actually used will be loaded into memory.
|
||||
|
||||
Requesting debug printout:
|
||||
|
||||
Changes to Libpng from version 0.88
|
||||
The macro definition PNG_DEBUG can be used to request debugging
|
||||
printout. Set it to an integer value in the range 0 to 3. Higher
|
||||
numbers result in increasing amounts of debugging information. The
|
||||
information is printed to the "stderr" file, unless another file
|
||||
name is specified in the PNG_DEBUG_FILE macro definition.
|
||||
|
||||
When PNG_DEBUG > 0, the following functions (macros) become available:
|
||||
|
||||
png_debug(level, message)
|
||||
png_debug1(level, message, p1)
|
||||
png_debug2(level, message, p1, p2)
|
||||
|
||||
in which "level" is compared to PNG_DEBUG to decide whether to print
|
||||
the message, "message" is the formatted string to be printed,
|
||||
and p1 and p2 are parameters that are to be embedded in the string
|
||||
according to printf-style formatting directives. For example,
|
||||
|
||||
png_debug1(2, "foo=%d\n", foo);
|
||||
|
||||
is expanded to
|
||||
|
||||
if(PNG_DEBUG > 2)
|
||||
fprintf(PNG_DEBUG_FILE, "foo=%d\n", foo);
|
||||
|
||||
When PNG_DEBUG is defined but is zero, the macros aren't defined, but you
|
||||
can still use PNG_DEBUG to control your own debugging:
|
||||
|
||||
#ifdef PNG_DEBUG
|
||||
fprintf(stderr, ...
|
||||
#endif
|
||||
|
||||
When PNG_DEBUG = 1, the macros are defined, but only png_debug statements
|
||||
having level = 0 will be printed. There aren't any such statements in
|
||||
this version of libpng, but if you insert some they will be printed.
|
||||
|
||||
.SH VI. Changes to Libpng from version 0.88
|
||||
|
||||
It should be noted that versions of libpng later than 0.96 are not
|
||||
distributed by the original libpng author, Guy Schalnat, nor by
|
||||
@@ -2274,13 +2430,65 @@ allocating and freeing the png_struct for each image read.
|
||||
|
||||
Setting the error callbacks via png_set_message_fn() before
|
||||
png_read_init() as was suggested in libpng-0.88 is no longer supported
|
||||
because this caused applications which do not use custom error functions
|
||||
because this caused applications that do not use custom error functions
|
||||
to fail if the png_ptr was not initialized to zero. It is still possible
|
||||
to set the error callbacks AFTER png_read_init(), or to change them with
|
||||
png_set_error_fn(), which is essentially the same function, but with a
|
||||
new name to force compilation errors with applications that try to use
|
||||
the old method.
|
||||
|
||||
.SH VII. Y2K Compliance in libpng
|
||||
|
||||
January 13, 1999
|
||||
|
||||
Since the PNG Development group is an ad-hoc body, we can't make
|
||||
an official declaration.
|
||||
|
||||
This is your unofficial assurance that libpng from version 0.81 and
|
||||
upward are Y2K compliant. It is my belief that earlier versions were
|
||||
also Y2K compliant.
|
||||
|
||||
Libpng only has three year fields. One is a 2-byte unsigned integer that
|
||||
will hold years up to 65535. The other two hold the date in text
|
||||
format, and will hold years up to 9999.
|
||||
|
||||
The integer is
|
||||
"png_uint_16 year" in png_time_struct.
|
||||
|
||||
The strings are
|
||||
"png_charp time_buffer" in png_struct and
|
||||
"near_time_buffer", which is a local character string in png.c.
|
||||
|
||||
There are seven time-related functions:
|
||||
|
||||
png_convert_to_rfc_1123() in png.c
|
||||
(formerly png_convert_to_rfc_1152() in error)
|
||||
png_convert_from_struct_tm() in pngwrite.c, called in pngwrite.c
|
||||
png_convert_from_time_t() in pngwrite.c
|
||||
png_get_tIME() in pngget.c
|
||||
png_handle_tIME() in pngrutil.c, called in pngread.c
|
||||
png_set_tIME() in pngset.c
|
||||
png_write_tIME() in pngwutil.c, called in pngwrite.c
|
||||
|
||||
All appear to handle dates properly in a Y2K environment. The
|
||||
png_convert_from_time_t() function calls gmtime() to convert from system
|
||||
clock time, which returns (year - 1900), which we properly convert to
|
||||
the full 4-digit year. There is a possibility that applications using
|
||||
libpng are not passing 4-digit years into the png_convert_to_rfc_1123()
|
||||
function, or incorrectly passing only a 2-digit year instead of
|
||||
"year - 1900" into the png_convert_from_struct_tm() function, but this
|
||||
is not under our control. The libpng documentation has always stated
|
||||
that it works with 4-digit years, and the APIs have been documented as
|
||||
such.
|
||||
|
||||
The tIME chunk itself is also Y2K compliant. It uses a 2-byte unsigned
|
||||
integer to hold the year, and can hold years as large as 65535.
|
||||
|
||||
|
||||
Glenn Randers-Pehrson
|
||||
libpng maintainer
|
||||
PNG Development Group
|
||||
|
||||
.SH NOTE
|
||||
|
||||
Note about libpng version numbers:
|
||||
@@ -2366,7 +2574,7 @@ possible without all of you.
|
||||
|
||||
Thanks to Frank J. T. Wojcik for helping with the documentation.
|
||||
|
||||
Libpng version 1.0.1 March 15, 1998:
|
||||
Libpng version 1.0.3 - January 14, 1999:
|
||||
Initially created in 1995 by Guy Eric Schalnat, then of Group 42, Inc.
|
||||
Currently maintained by Glenn Randers-Pehrson (randeg@alumni.rpi.edu).
|
||||
|
||||
@@ -2376,6 +2584,10 @@ Supported by the PNG development group
|
||||
|
||||
.SH COPYRIGHT NOTICE:
|
||||
|
||||
Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
Copyright (c) 1996, 1997 Andreas Dilger
|
||||
Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
||||
|
||||
The PNG Reference Library (libpng) is supplied "AS IS". The Contributing
|
||||
Authors and Group 42, Inc. disclaim all warranties, expressed or implied,
|
||||
including, without limitation, the warranties of merchantability and of
|
||||
|
@@ -1,6 +1,6 @@
|
||||
.TH LIBPNGPF 3 "March 15, 1998"
|
||||
.TH LIBPNGPF 3 "January 14, 1999"
|
||||
.SH NAME
|
||||
libpng \- Portable Network Graphics (PNG) Reference Library
|
||||
libpng \- Portable Network Graphics (PNG) Reference Library 1.0.3 - January 14, 1999
|
||||
(private functions)
|
||||
.SH SYNOPSIS
|
||||
#include <png.h>
|
||||
@@ -31,10 +31,15 @@ int png_crc_finish (png_structp png_ptr, png_uint_32 skip);
|
||||
void png_crc_read (png_structp png_ptr, png_bytep buf,
|
||||
png_size_t length);
|
||||
|
||||
png_voidp png_create_struct (int type);
|
||||
png_voidp png_create_struct (int type, png_malloc_ptr malloc_fn);
|
||||
|
||||
png_voidp png_create_struct_2 (int type);
|
||||
|
||||
void png_destroy_struct (png_voidp struct_ptr);
|
||||
|
||||
void png_destroy_struct_2 (png_voidp struct_ptr, png_free_ptr
|
||||
free_fn);
|
||||
|
||||
void png_do_background (png_row_infop row_info, png_bytep row,
|
||||
png_color_16p trans_values, png_color_16p background,
|
||||
png_color_16p background_1, png_bytep gamma_table, png_bytep
|
||||
@@ -83,7 +88,7 @@ row);
|
||||
|
||||
void png_do_read_transformations (png_structp png_ptr);
|
||||
|
||||
void png_do_rgb_to_gray (png_row_infop row_info, png_bytep
|
||||
int png_do_rgb_to_gray (png_row_infop row_info, png_bytep
|
||||
row);
|
||||
|
||||
void png_do_shift (png_row_infop row_info, png_bytep row,
|
||||
|
@@ -1,4 +1,4 @@
|
||||
.TH PNG 5 "March 15, 1998"
|
||||
.TH PNG 5 "January 14, 1999"
|
||||
.SH NAME
|
||||
png \- Portable Network Graphics (PNG) format
|
||||
.SH DESCRIPTION
|
||||
|
@@ -1,22 +1,22 @@
|
||||
|
||||
/* png.c - location for general purpose libpng functions
|
||||
*
|
||||
* libpng 1.0.1
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* libpng version 1.0.3 - January 14, 1999
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* March 15, 1998
|
||||
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
||||
*
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
#define PNG_NO_EXTERN
|
||||
#include "../png/png.h"
|
||||
#include "png.h"
|
||||
|
||||
/* Version information for C files. This had better match the version
|
||||
* string defined in png.h.
|
||||
*/
|
||||
char png_libpng_ver[12] = "1.0.1";
|
||||
|
||||
char png_libpng_ver[12] = "1.0.3";
|
||||
|
||||
/* Place to hold the signature string for a PNG file. */
|
||||
png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
|
||||
@@ -115,8 +115,8 @@ png_sig_cmp(png_bytep sig, png_size_t start, png_size_t 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().
|
||||
* to check a partial signature. This function might be removed in the
|
||||
* future - use png_sig_cmp(). Returns true (nonzero) if the file is a PNG.
|
||||
*/
|
||||
int
|
||||
png_check_sig(png_bytep sig, int num)
|
||||
@@ -128,12 +128,10 @@ png_check_sig(png_bytep sig, int num)
|
||||
voidpf
|
||||
png_zalloc(voidpf png_ptr, uInt items, uInt size)
|
||||
{
|
||||
png_voidp ptr;
|
||||
png_uint_32 num_bytes;
|
||||
png_uint_32 num_bytes = (png_uint_32)items * size;
|
||||
png_voidp ptr = (png_voidp)png_malloc((png_structp)png_ptr, num_bytes);
|
||||
|
||||
num_bytes = (png_uint_32)items * size;
|
||||
ptr = (png_voidp)png_malloc((png_structp)png_ptr, num_bytes);
|
||||
if (num_bytes > (png_uint_32)0x8000)
|
||||
if (num_bytes > (png_uint_32)0x8000L)
|
||||
{
|
||||
png_memset(ptr, 0, (png_size_t)0x8000L);
|
||||
png_memset((png_bytep)ptr + (png_size_t)0x8000L, 0,
|
||||
@@ -201,7 +199,12 @@ png_create_info_struct(png_structp png_ptr)
|
||||
|
||||
png_debug(1, "in png_create_info_struct\n");
|
||||
if(png_ptr == NULL) return (NULL);
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
if ((info_ptr = (png_infop)png_create_struct_2(PNG_STRUCT_INFO,
|
||||
png_ptr->malloc_fn)) != NULL)
|
||||
#else
|
||||
if ((info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO)) != NULL)
|
||||
#endif
|
||||
{
|
||||
png_info_init(info_ptr);
|
||||
}
|
||||
@@ -227,7 +230,11 @@ png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr)
|
||||
{
|
||||
png_info_destroy(png_ptr, info_ptr);
|
||||
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
png_destroy_struct_2((png_voidp)info_ptr, png_ptr->free_fn);
|
||||
#else
|
||||
png_destroy_struct((png_voidp)info_ptr);
|
||||
#endif
|
||||
*info_ptr_ptr = (png_infop)NULL;
|
||||
}
|
||||
}
|
||||
@@ -252,11 +259,10 @@ 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)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < info_ptr->num_text; i++)
|
||||
{
|
||||
png_free(png_ptr, info_ptr->text[i].key);
|
||||
@@ -269,6 +275,7 @@ png_info_destroy(png_structp png_ptr, png_infop info_ptr)
|
||||
png_free(png_ptr, info_ptr->pcal_units);
|
||||
if (info_ptr->pcal_params != NULL)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < (int)info_ptr->pcal_nparams; i++)
|
||||
{
|
||||
png_free(png_ptr, info_ptr->pcal_params[i]);
|
||||
@@ -302,3 +309,51 @@ png_init_io(png_structp png_ptr, FILE *fp)
|
||||
png_ptr->io_ptr = (png_voidp)fp;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_TIME_RFC1123_SUPPORTED)
|
||||
/* Convert the supplied time into an RFC 1123 string suitable for use in
|
||||
* a "Creation Time" or other text-based time string.
|
||||
*/
|
||||
png_charp
|
||||
png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime)
|
||||
{
|
||||
static PNG_CONST char short_months[12][4] =
|
||||
{"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, (png_uint_32)(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 % 32, short_months[(ptime->month - 1) % 12],
|
||||
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 % 32, short_months[(ptime->month - 1) % 12],
|
||||
ptime->year, ptime->hour % 24, ptime->minute % 60,
|
||||
ptime->second % 61);
|
||||
#endif
|
||||
return ((png_charp)png_ptr->time_buffer);
|
||||
}
|
||||
#endif /* PNG_TIME_RFC1123_SUPPORTED */
|
||||
|
||||
png_charp
|
||||
png_get_copyright(png_structp png_ptr)
|
||||
{
|
||||
if(png_ptr == NULL)
|
||||
/* silence compiler warning about unused png_ptr */ ;
|
||||
return("\n libpng version 1.0.3 - January 14, 1999\n\
|
||||
Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.\n\
|
||||
Copyright (c) 1996, 1997 Andreas Dilger\n\
|
||||
Copyright (c) 1998, 1999, Glenn Randers-Pehrson\n");
|
||||
}
|
||||
|
286
src/png/png.h
286
src/png/png.h
@@ -1,12 +1,62 @@
|
||||
|
||||
/* png.h - header file for PNG reference library
|
||||
*
|
||||
* libpng 1.0.1
|
||||
* For conditions of distribution and use, see the COPYRIGHT NOTICE below.
|
||||
* libpng version 1.0.3 - January 14, 1999
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998 Glenn Randers-Pehrson
|
||||
* March 15, 1998
|
||||
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
||||
*
|
||||
* Y2K compliance in libpng:
|
||||
* =========================
|
||||
*
|
||||
* January 13, 1999
|
||||
*
|
||||
* Since the PNG Development group is an ad-hoc body, we can't make
|
||||
* an official declaration.
|
||||
*
|
||||
* This is your unofficial assurance that libpng from version 0.81 and
|
||||
* upward are Y2K compliant. It is my belief that earlier versions were
|
||||
* also Y2K compliant.
|
||||
*
|
||||
* Libpng only has three year fields. One is a 2-byte unsigned integer
|
||||
* that will hold years up to 65535. The other two hold the date in text
|
||||
* format, and will hold years up to 9999.
|
||||
*
|
||||
* The integer is
|
||||
* "png_uint_16 year" in png_time_struct.
|
||||
*
|
||||
* The strings are
|
||||
* "png_charp time_buffer" in png_struct and
|
||||
* "near_time_buffer", which is a local character string in png.c.
|
||||
*
|
||||
* There are seven time-related functions:
|
||||
* png.c: png_convert_to_rfc_1123() in png.c
|
||||
* (formerly png_convert_to_rfc_1152() in error)
|
||||
* png_convert_from_struct_tm() in pngwrite.c, called in pngwrite.c
|
||||
* png_convert_from_time_t() in pngwrite.c
|
||||
* png_get_tIME() in pngget.c
|
||||
* png_handle_tIME() in pngrutil.c, called in pngread.c
|
||||
* png_set_tIME() in pngset.c
|
||||
* png_write_tIME() in pngwutil.c, called in pngwrite.c
|
||||
*
|
||||
* All handle dates properly in a Y2K environment. The
|
||||
* png_convert_from_time_t() function calls gmtime() to convert from system
|
||||
* clock time, which returns (year - 1900), which we properly convert to
|
||||
* the full 4-digit year. There is a possibility that applications using
|
||||
* libpng are not passing 4-digit years into the png_convert_to_rfc_1123()
|
||||
* function, or incorrectly passing only a 2-digit year instead of
|
||||
* "year - 1900" into the png_convert_from_struct_tm() function, but this
|
||||
* is not under our control. The libpng documentation has always stated
|
||||
* that it works with 4-digit years, and the APIs have been documented as
|
||||
* such.
|
||||
*
|
||||
* The tIME chunk itself is also Y2K compliant. It uses a 2-byte unsigned
|
||||
* integer to hold the year, and can hold years as large as 65535.
|
||||
*
|
||||
*
|
||||
* Glenn Randers-Pehrson
|
||||
* libpng maintainer
|
||||
* PNG Development Group
|
||||
*
|
||||
* Note about libpng version numbers:
|
||||
*
|
||||
@@ -18,7 +68,7 @@
|
||||
*
|
||||
* source png.h png.h shared-lib
|
||||
* version string int version
|
||||
* ------- ------ ------ ----------
|
||||
* ------- ------ ----- ----------
|
||||
* 0.89c ("1.0 beta 3") 0.89 89 1.0.89
|
||||
* 0.90 ("1.0 beta 4") 0.90 90 0.90 [should have been 2.0.90]
|
||||
* 0.95 ("1.0 beta 5") 0.95 95 0.95 [should have been 2.0.95]
|
||||
@@ -31,17 +81,20 @@
|
||||
* 1.00 1.00 100 2.1.0 [int should be 10000]
|
||||
* 1.0.0 1.0.0 100 2.1.0 [int should be 10000]
|
||||
* 1.0.1 1.0.1 10001 2.1.0
|
||||
* 1.0.1a-e 1.0.1a-e 10002 2.1.0.1a-e
|
||||
* 1.0.2 1.0.2 10002 2.1.0.2
|
||||
* 1.0.2a-c 1.0.2a 10003 2.1.0.2a-c
|
||||
* 1.0.3 1.0.3 10003 2.1.0.3
|
||||
*
|
||||
* Henceforth the source version will match the shared-library minor
|
||||
* and patch numbers; the shared-library major version number will be
|
||||
* used for changes in backward compatibility, as it is intended.
|
||||
* The PNG_PNGLIB_VER macro, which is not used within libpng but
|
||||
* is available for applications, is an unsigned integer of the form
|
||||
* xyyzz corresponding to the source version x.y.z (leading zeros in y and z).
|
||||
* used for changes in backward compatibility, as it is intended. The
|
||||
* PNG_PNGLIB_VER macro, which is not used within libpng but is available
|
||||
* for applications, is an unsigned integer of the form xyyzz corresponding
|
||||
* to the source version x.y.z (leading zeros in y and z).
|
||||
*
|
||||
*
|
||||
* See libpng.txt for more information. The PNG specification is available
|
||||
* as RFC 2083 <ftp://ftp.uu.net/graphics/png/documents/>
|
||||
* See libpng.txt or libpng.3 for more information. The PNG specification
|
||||
* is available as RFC 2083 <ftp://ftp.uu.net/graphics/png/documents/>
|
||||
* and as a W3C Recommendation <http://www.w3.org/TR/REC.png.html>
|
||||
*
|
||||
* Contributing Authors:
|
||||
@@ -92,6 +145,7 @@
|
||||
* appreciated.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _PNG_H
|
||||
#define _PNG_H
|
||||
|
||||
@@ -106,10 +160,10 @@ extern "C" {
|
||||
*/
|
||||
|
||||
/* include the compression library's header */
|
||||
#include "../zlib/zlib.h"
|
||||
#include "zlib.h"
|
||||
|
||||
/* include all user configurable info */
|
||||
#include "../png/pngconf.h"
|
||||
#include "pngconf.h"
|
||||
|
||||
/* This file is arranged in several sections. The first section contains
|
||||
* structure and type definitions. The second section contains the external
|
||||
@@ -118,14 +172,14 @@ extern "C" {
|
||||
*/
|
||||
|
||||
/* Version information for png.h - this should match the version in png.c */
|
||||
#define PNG_LIBPNG_VER_STRING "1.0.1"
|
||||
#define PNG_LIBPNG_VER_STRING "1.0.3"
|
||||
|
||||
/* Careful here. At one time, Guy wanted to use 082, but that would be octal.
|
||||
* We must not include leading zeros.
|
||||
* Versions 0.7 through 1.0.0 were in the range 0 to 100 here (only
|
||||
* version 1.0.0 was mis-numbered 100 instead of 10000). From
|
||||
* version 1.0.1 it's xxyyzz, where x=major, y=minor, z=bugfix */
|
||||
#define PNG_LIBPNG_VER 10001 /* 1.0.1 */
|
||||
#define PNG_LIBPNG_VER 10003 /* 1.0.3 */
|
||||
|
||||
/* variables declared in png.c - only it needs to define PNG_NO_EXTERN */
|
||||
#if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
|
||||
@@ -145,6 +199,7 @@ extern int FARDATA png_pass_dsp_mask[7];
|
||||
extern int FARDATA png_pass_width[7];
|
||||
extern int FARDATA png_pass_height[7];
|
||||
*/
|
||||
|
||||
#endif /* PNG_NO_EXTERN */
|
||||
|
||||
/* Three color definitions. The order of the red, green, and blue, (and the
|
||||
@@ -231,7 +286,7 @@ typedef png_time FAR * FAR * png_timepp;
|
||||
* With libpng < 0.95, it was only possible to directly set and read the
|
||||
* the values in the png_info_struct, which meant that the contents and
|
||||
* order of the values had to remain fixed. With libpng 0.95 and later,
|
||||
* however, * there are now functions which abstract the contents of
|
||||
* however, there are now functions that abstract the contents of
|
||||
* png_info_struct from the application, so this makes it easier to use
|
||||
* libpng with dynamic libraries, and even makes it possible to use
|
||||
* libraries that don't have all of the libpng ancillary chunk-handing
|
||||
@@ -289,14 +344,14 @@ typedef struct png_info_struct
|
||||
/* The tEXt and zTXt chunks contain human-readable textual data in
|
||||
* uncompressed and compressed forms, respectively. The data in "text"
|
||||
* is an array of pointers to uncompressed, null-terminated C strings.
|
||||
* Each chunk has a keyword which describes the textual data contained
|
||||
* Each chunk has a keyword that describes the textual data contained
|
||||
* in that chunk. Keywords are not required to be unique, and the text
|
||||
* string may be empty. Any number of text chunks may be in an image.
|
||||
*/
|
||||
int num_text; /* number of comments read/to write */
|
||||
int max_text; /* current size of text array */
|
||||
png_textp text; /* array of comments read/to write */
|
||||
#endif /* PNG_READ_tEXt/zTXt_SUPPORTED || PNG_WRITE_tEXt/zTXt_SUPPORTED */
|
||||
#endif /* PNG_READ_OR_WRITE_tEXt_OR_zTXt_SUPPORTED */
|
||||
#if defined(PNG_READ_tIME_SUPPORTED) || defined(PNG_WRITE_tIME_SUPPORTED)
|
||||
/* The tIME chunk holds the last time the displayed image data was
|
||||
* modified. See the png_time struct for the contents of this struct.
|
||||
@@ -312,14 +367,15 @@ typedef struct png_info_struct
|
||||
*/
|
||||
png_color_8 sig_bit; /* significant bits in color channels */
|
||||
#endif /* PNG_READ_sBIT_SUPPORTED || PNG_WRITE_sBIT_SUPPORTED */
|
||||
#if defined(PNG_READ_tRNS_SUPPORTED) || defined(PNG_WRITE_tRNS_SUPPORTED)
|
||||
#if defined(PNG_READ_tRNS_SUPPORTED) || defined(PNG_WRITE_tRNS_SUPPORTED) || \
|
||||
defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
|
||||
/* The tRNS chunk supplies transparency data for paletted images and
|
||||
* other image types that don't need a full alpha channel. There are
|
||||
* "num_trans" transparency values for a paletted image, stored in the
|
||||
* same order as the palette colors, starting from index 0. Values
|
||||
* for the data are in the range [0, 255], ranging from fully transparent
|
||||
* to fully opaque, respectively. For non-paletted images, there is a
|
||||
* single color specified which should be treated as fully transparent.
|
||||
* single color specified that should be treated as fully transparent.
|
||||
* Data is valid if (valid & PNG_INFO_tRNS) is non-zero.
|
||||
*/
|
||||
png_bytep trans; /* transparent values for paletted image */
|
||||
@@ -491,10 +547,11 @@ typedef struct png_row_info_struct
|
||||
typedef png_row_info FAR * png_row_infop;
|
||||
typedef png_row_info FAR * FAR * png_row_infopp;
|
||||
|
||||
/* These are the function types for the I/O functions, and the functions which
|
||||
* modify the default I/O functions to user I/O functions. The png_error_ptr
|
||||
* type should match that of user supplied warning and error functions, while
|
||||
* the png_rw_ptr type should match that of the user read/write data functions.
|
||||
/* These are the function types for the I/O functions and for the functions
|
||||
* that allow the user to override the default I/O functions with his or her
|
||||
* own. The png_error_ptr type should match that of user-supplied warning
|
||||
* and error functions, while the png_rw_ptr type should match that of the
|
||||
* user read/write data functions.
|
||||
*/
|
||||
typedef struct png_struct_def png_struct;
|
||||
typedef png_struct FAR * png_structp;
|
||||
@@ -517,6 +574,9 @@ typedef void (*png_user_transform_ptr) PNGARG((png_structp,
|
||||
png_row_infop, png_bytep));
|
||||
#endif /* PNG_READ|WRITE_USER_TRANSFORM_SUPPORTED */
|
||||
|
||||
typedef png_voidp (*png_malloc_ptr) PNGARG((png_structp, png_size_t));
|
||||
typedef void (*png_free_ptr) PNGARG((png_structp, png_structp));
|
||||
|
||||
/* The structure that holds the information to read and write PNG files.
|
||||
* The only people who need to care about what is inside of this are the
|
||||
* people who will be modifying the library for their own special needs.
|
||||
@@ -589,7 +649,7 @@ struct png_struct_def
|
||||
png_byte sig_bytes; /* magic bytes read/written from start of file */
|
||||
|
||||
#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
|
||||
png_byte filler; /* filler byte for 24->32-bit pixel expansion */
|
||||
png_uint_16 filler; /* filler bytes for pixel expansion */
|
||||
#endif /* PNG_READ_FILLER_SUPPORTED */
|
||||
#if defined(PNG_READ_bKGD_SUPPORTED)
|
||||
png_byte background_gamma_type;
|
||||
@@ -604,7 +664,7 @@ struct png_struct_def
|
||||
png_uint_32 flush_dist; /* how many rows apart to flush, 0 - no flush */
|
||||
png_uint_32 flush_rows; /* number of rows written since last flush */
|
||||
#endif /* PNG_WRITE_FLUSH_SUPPORTED */
|
||||
#if defined(PNG_READ_GAMMA_SUPPORTED)
|
||||
#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
|
||||
int gamma_shift; /* number of "insignificant" bits 16-bit gamma */
|
||||
float gamma; /* file gamma value */
|
||||
float screen_gamma; /* screen gamma value (display_gamma/viewing_gamma */
|
||||
@@ -623,10 +683,11 @@ struct png_struct_def
|
||||
#if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
|
||||
png_color_8 shift; /* shift for significant bit tranformation */
|
||||
#endif /* PNG_READ_SHIFT_SUPPORTED || PNG_WRITE_SHIFT_SUPPORTED */
|
||||
#if defined(PNG_READ_tRNS_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
|
||||
#if defined(PNG_READ_tRNS_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) \
|
||||
|| defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
|
||||
png_bytep trans; /* transparency values for paletted files */
|
||||
png_color_16 trans_values; /* transparency values for non-paletted files */
|
||||
#endif /* PNG_READ_tRNS_SUPPORTED || PNG_READ_BACKGROUND_SUPPORTED */
|
||||
#endif /* PNG_READ|WRITE_tRNS_SUPPORTED||PNG_READ_EXPAND|BACKGROUND_SUPPORTED */
|
||||
png_read_status_ptr read_row_fn; /* called after each row is decoded */
|
||||
png_write_status_ptr write_row_fn; /* called after each row is encoded */
|
||||
#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
|
||||
@@ -679,6 +740,17 @@ struct png_struct_def
|
||||
#if defined(PNG_TIME_RFC1123_SUPPORTED)
|
||||
png_charp time_buffer; /* String to hold RFC 1123 time text */
|
||||
#endif /* PNG_TIME_RFC1123_SUPPORTED */
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
png_voidp mem_ptr; /* user supplied struct for mem functions */
|
||||
png_malloc_ptr malloc_fn; /* function for allocating memory */
|
||||
png_free_ptr free_fn; /* function for freeing memory */
|
||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||
#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
|
||||
png_byte rgb_to_gray_status;
|
||||
png_byte rgb_to_gray_red_coeff;
|
||||
png_byte rgb_to_gray_green_coeff;
|
||||
png_byte rgb_to_gray_blue_coeff;
|
||||
#endif
|
||||
};
|
||||
|
||||
typedef png_struct FAR * FAR * png_structpp;
|
||||
@@ -710,14 +782,25 @@ extern PNG_EXPORT(int,png_check_sig) PNGARG((png_bytep sig, int num));
|
||||
|
||||
/* Allocate and initialize png_ptr struct for reading, and any other memory. */
|
||||
extern PNG_EXPORT(png_structp,png_create_read_struct)
|
||||
PNGARG((png_const_charp user_png_ver, voidp error_ptr,
|
||||
PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
|
||||
png_error_ptr error_fn, png_error_ptr warn_fn));
|
||||
|
||||
/* Allocate and initialize png_ptr struct for reading, and any other memory */
|
||||
/* Allocate and initialize png_ptr struct for writing, and any other memory */
|
||||
extern PNG_EXPORT(png_structp,png_create_write_struct)
|
||||
PNGARG((png_const_charp user_png_ver, voidp error_ptr,
|
||||
PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
|
||||
png_error_ptr error_fn, png_error_ptr warn_fn));
|
||||
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
extern PNG_EXPORT(png_structp,png_create_read_struct_2)
|
||||
PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
|
||||
png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
|
||||
png_malloc_ptr malloc_fn, png_free_ptr free_fn));
|
||||
extern PNG_EXPORT(png_structp,png_create_write_struct_2)
|
||||
PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
|
||||
png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
|
||||
png_malloc_ptr malloc_fn, png_free_ptr free_fn));
|
||||
#endif
|
||||
|
||||
/* Write a PNG chunk - size, type, (optional) data, CRC. */
|
||||
extern PNG_EXPORT(void,png_write_chunk) PNGARG((png_structp png_ptr,
|
||||
png_bytep chunk_name, png_bytep data, png_size_t length));
|
||||
@@ -779,8 +862,11 @@ extern PNG_EXPORT(void,png_set_gray_to_rgb) PNGARG((png_structp png_ptr));
|
||||
#endif /* PNG_READ_GRAY_TO_RGB_SUPPORTED */
|
||||
|
||||
#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
|
||||
/* Reduce RGB to grayscale. (Not yet implemented) */
|
||||
extern PNG_EXPORT(void,png_set_rgb_to_gray) PNGARG((png_structp png_ptr));
|
||||
/* Reduce RGB to grayscale. */
|
||||
extern PNG_EXPORT(void,png_set_rgb_to_gray) PNGARG((png_structp png_ptr,
|
||||
int error_action, float red, float green ));
|
||||
extern PNG_EXPORT(png_byte,png_get_rgb_to_gray_status) PNGARG((png_structp
|
||||
png_ptr));
|
||||
#endif /* PNG_READ_RGB_TO_GRAY_SUPPORTED */
|
||||
|
||||
extern PNG_EXPORT(void,png_build_grayscale_palette) PNGARG((int bit_depth,
|
||||
@@ -1084,6 +1170,7 @@ extern PNG_EXPORT(void,png_init_io) PNGARG((png_structp png_ptr, FILE *fp));
|
||||
* method of error handling. If error_fn or warning_fn is NULL, the
|
||||
* default function will be used.
|
||||
*/
|
||||
|
||||
extern PNG_EXPORT(void,png_set_error_fn) PNGARG((png_structp png_ptr,
|
||||
png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warning_fn));
|
||||
|
||||
@@ -1111,6 +1198,15 @@ extern PNG_EXPORT(void,png_set_read_status_fn) PNGARG((png_structp png_ptr,
|
||||
extern PNG_EXPORT(void,png_set_write_status_fn) PNGARG((png_structp png_ptr,
|
||||
png_write_status_ptr write_row_fn));
|
||||
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
/* Replace the default memory allocation functions with user supplied one(s). */
|
||||
extern PNG_EXPORT(void,png_set_mem_fn) PNGARG((png_structp png_ptr,
|
||||
png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn));
|
||||
|
||||
/* Return the user pointer associated with the memory functions */
|
||||
extern PNG_EXPORT(png_voidp,png_get_mem_ptr) PNGARG((png_structp png_ptr));
|
||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||
|
||||
#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
|
||||
extern PNG_EXPORT(void,png_set_read_user_transform_fn) PNGARG((png_structp
|
||||
png_ptr, png_user_transform_ptr read_user_transform_fn));
|
||||
@@ -1138,7 +1234,7 @@ extern PNG_EXPORT(png_voidp,png_get_progressive_ptr)
|
||||
extern PNG_EXPORT(void,png_process_data) PNGARG((png_structp png_ptr,
|
||||
png_infop info_ptr, png_bytep buffer, png_size_t buffer_size));
|
||||
|
||||
/* function which combines rows. Not very much different than the
|
||||
/* function that combines rows. Not very much different than the
|
||||
* png_combine_row() call. Is this even used?????
|
||||
*/
|
||||
extern PNG_EXPORT(void,png_progressive_combine_row) PNGARG((png_structp png_ptr,
|
||||
@@ -1151,19 +1247,19 @@ extern PNG_EXPORT(png_voidp,png_malloc) PNGARG((png_structp png_ptr,
|
||||
/* frees a pointer allocated by png_malloc() */
|
||||
extern PNG_EXPORT(void,png_free) PNGARG((png_structp png_ptr, png_voidp ptr));
|
||||
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
extern PNG_EXPORT(png_voidp,png_malloc_default) PNGARG((png_structp png_ptr,
|
||||
png_uint_32 size));
|
||||
extern PNG_EXPORT(void,png_free_default) PNGARG((png_structp png_ptr,
|
||||
png_voidp ptr));
|
||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||
|
||||
extern PNG_EXPORT(png_voidp,png_memcpy_check) PNGARG((png_structp png_ptr,
|
||||
png_voidp s1, png_voidp s2, png_uint_32 size));
|
||||
|
||||
extern PNG_EXPORT(png_voidp,png_memset_check) PNGARG((png_structp png_ptr,
|
||||
png_voidp s1, int value, png_uint_32 size));
|
||||
|
||||
#ifdef PNGTEST_MEMORY_DEBUG
|
||||
/* debugging versions of png_malloc() and png_free() */
|
||||
extern PNG_EXPORT(png_voidp,png_debug_malloc) PNGARG((png_structp png_ptr,
|
||||
png_uint_32 size));
|
||||
extern PNG_EXPORT(void,png_debug_free) PNGARG((png_structp png_ptr,
|
||||
png_voidp ptr));
|
||||
#endif
|
||||
#if defined(USE_FAR_KEYWORD) /* memory model conversion function */
|
||||
extern void *png_far_to_near PNGARG((png_structp png_ptr,png_voidp ptr,
|
||||
int check));
|
||||
@@ -1390,8 +1486,7 @@ extern PNG_EXPORT(png_uint_32,png_get_text) PNGARG((png_structp png_ptr,
|
||||
defined(PNG_READ_zTXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED)
|
||||
extern PNG_EXPORT(void,png_set_text) PNGARG((png_structp png_ptr,
|
||||
png_infop info_ptr, png_textp text_ptr, int num_text));
|
||||
#endif /* PNG_READ_tEXt_SUPPORTED || PNG_WRITE_tEXt_SUPPORTED ||
|
||||
PNG_READ_zTXt_SUPPORTED || PNG_WRITE_zTXt_SUPPORTED */
|
||||
#endif /* PNG_READ_OR_WRITE_tEXt_OR_zTXt_SUPPORTED */
|
||||
|
||||
#if defined(PNG_READ_tIME_SUPPORTED)
|
||||
extern PNG_EXPORT(png_uint_32,png_get_tIME) PNGARG((png_structp png_ptr,
|
||||
@@ -1420,28 +1515,87 @@ extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr,
|
||||
* only been added since version 0.95 so it is not implemented throughout
|
||||
* libpng yet, but more support will be added as needed.
|
||||
*/
|
||||
#ifdef PNG_DEBUG
|
||||
#if (PNG_DEBUG > 0)
|
||||
#ifdef PNG_NO_STDIO
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
#ifndef PNG_DEBUG_FILE
|
||||
#define PNG_DEBUG_FILE stderr
|
||||
#endif /* PNG_DEBUG_FILE */
|
||||
|
||||
#define png_debug(l,m) if (PNG_DEBUG > l) \
|
||||
fprintf(PNG_DEBUG_FILE,"%s"m,(l==1 ? "\t" : \
|
||||
(l==2 ? "\t\t":(l==3 ? "\t\t\t":""))))
|
||||
(l==2 ? "\t\t":(l>2 ? "\t\t\t":""))))
|
||||
#define png_debug1(l,m,p1) if (PNG_DEBUG > l) \
|
||||
fprintf(PNG_DEBUG_FILE,"%s"m,(l==1 ? "\t" : \
|
||||
(l==2 ? "\t\t":(l==3 ? "\t\t\t":""))),p1)
|
||||
(l==2 ? "\t\t":(l>2 ? "\t\t\t":""))),p1)
|
||||
#define png_debug2(l,m,p1,p2) if (PNG_DEBUG > l) \
|
||||
fprintf(PNG_DEBUG_FILE,"%s"m,(l==1 ? "\t" : \
|
||||
(l==2 ? "\t\t":(l==3 ? "\t\t\t":""))),p1,p2)
|
||||
#else
|
||||
#define png_debug(l, m)
|
||||
#define png_debug1(l, m, p1)
|
||||
#define png_debug2(l, m, p1, p2)
|
||||
(l==2 ? "\t\t":(l>2 ? "\t\t\t":""))),p1,p2)
|
||||
#endif /* (PNG_DEBUG > 0) */
|
||||
#endif /* PNG_DEBUG */
|
||||
#ifndef png_debug
|
||||
#define png_debug(l, m)
|
||||
#endif
|
||||
#ifndef png_debug1
|
||||
#define png_debug1(l, m, p1)
|
||||
#endif
|
||||
#ifndef png_debug2
|
||||
#define png_debug2(l, m, p1, p2)
|
||||
#endif
|
||||
|
||||
extern PNG_EXPORT(png_charp,png_get_copyright) PNGARG((png_structp png_ptr));
|
||||
extern PNG_EXPORT(png_charp,png_get_header_version) PNGARG((png_structp png_ptr));
|
||||
|
||||
#ifdef PNG_NO_EXTERN
|
||||
/* this only gets included in png.c */
|
||||
png_charp
|
||||
png_get_header_version(png_structp png_ptr)
|
||||
{
|
||||
if(png_ptr == NULL)
|
||||
/* silence compiler warning about unused png_ptr */ ;
|
||||
return("\n libpng version 1.0.3 - January 14, 1999 (header)\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED
|
||||
/* With these routines we avoid an integer divide, which will be slower on
|
||||
* most machines. However, it does take more operations than the corresponding
|
||||
* divide method, so it may be slower on a few RISC systems. There are two
|
||||
* shifts (by 8 or 16 bits) and an addition, versus a single integer divide.
|
||||
*
|
||||
* Note that the rounding factors are NOT supposed to be the same! 128 and
|
||||
* 32768 are correct for the NODIV code; 127 and 32767 are correct for the
|
||||
* standard method.
|
||||
*
|
||||
* [Optimized code by Greg Roelofs and Mark Adler...blame us for bugs. :-) ]
|
||||
*/
|
||||
|
||||
/* fg and bg should be in `gamma 1.0' space; alpha is the opacity */
|
||||
|
||||
# define png_composite(composite, fg, alpha, bg) \
|
||||
{ png_uint_16 temp = ((png_uint_16)(fg) * (png_uint_16)(alpha) + \
|
||||
(png_uint_16)(bg)*(png_uint_16)(255 - \
|
||||
(png_uint_16)(alpha)) + (png_uint_16)128); \
|
||||
(composite) = (png_byte)((temp + (temp >> 8)) >> 8); }
|
||||
|
||||
# define png_composite_16(composite, fg, alpha, bg) \
|
||||
{ png_uint_32 temp = ((png_uint_32)(fg) * (png_uint_32)(alpha) + \
|
||||
(png_uint_32)(bg)*(png_uint_32)(65535L - \
|
||||
(png_uint_32)(alpha)) + (png_uint_32)32768L); \
|
||||
(composite) = (png_uint_16)((temp + (temp >> 16)) >> 16); }
|
||||
|
||||
#else /* standard method using integer division */
|
||||
|
||||
# define png_composite(composite, fg, alpha, bg) \
|
||||
(composite) = (png_byte)(((png_uint_16)(fg) * (png_uint_16)(alpha) + \
|
||||
(png_uint_16)(bg) * (png_uint_16)(255 - (png_uint_16)(alpha)) + \
|
||||
(png_uint_16)127) / 255)
|
||||
|
||||
# define png_composite_16(composite, fg, alpha, bg) \
|
||||
(composite) = (png_uint_16)(((png_uint_32)(fg) * (png_uint_32)(alpha) + \
|
||||
(png_uint_32)(bg)*(png_uint_32)(65535L - (png_uint_32)(alpha)) + \
|
||||
(png_uint_32)32767) / (png_uint_32)65535L)
|
||||
|
||||
#endif /* PNG_READ_COMPOSITE_NODIV_SUPPORTED */
|
||||
|
||||
/* These next functions are used internally in the code. They generally
|
||||
* shouldn't be used unless you are writing code to add or replace some
|
||||
@@ -1484,7 +1638,7 @@ extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr,
|
||||
#define PNG_DITHER 0x0040
|
||||
#define PNG_BACKGROUND 0x0080
|
||||
#define PNG_BACKGROUND_EXPAND 0x0100
|
||||
#define PNG_RGB_TO_GRAY 0x0200 /* Not currently implemented */
|
||||
/* 0x0200 unused */
|
||||
#define PNG_16_TO_8 0x0400
|
||||
#define PNG_RGBA 0x0800
|
||||
#define PNG_EXPAND 0x1000
|
||||
@@ -1496,6 +1650,9 @@ extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr,
|
||||
#define PNG_STRIP_ALPHA 0x40000L
|
||||
#define PNG_INVERT_ALPHA 0x80000L
|
||||
#define PNG_USER_TRANSFORM 0x100000L
|
||||
#define PNG_RGB_TO_GRAY_ERR 0x200000L
|
||||
#define PNG_RGB_TO_GRAY_WARN 0x400000L
|
||||
#define PNG_RGB_TO_GRAY 0x600000L /* two bits, RGB_TO_GRAY_ERR|WARN */
|
||||
|
||||
/* flags for png_create_struct */
|
||||
#define PNG_STRUCT_PNG 0x0001
|
||||
@@ -1525,6 +1682,7 @@ extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr,
|
||||
#define PNG_FLAG_FREE_HIST 0x4000
|
||||
#define PNG_FLAG_HAVE_CHUNK_HEADER 0x8000L
|
||||
#define PNG_FLAG_WROTE_tIME 0x10000L
|
||||
#define PNG_FLAG_BACKGROUND_IS_GRAY 0x20000L
|
||||
|
||||
#define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \
|
||||
PNG_FLAG_CRC_ANCILLARY_NOWARN)
|
||||
@@ -1590,7 +1748,7 @@ PNG_EXTERN png_int_32 png_get_int_32 PNGARG((png_bytep buf));
|
||||
#endif /* PNG_READ_pCAL_SUPPORTED */
|
||||
PNG_EXTERN png_uint_32 png_get_uint_32 PNGARG((png_bytep buf));
|
||||
PNG_EXTERN png_uint_16 png_get_uint_16 PNGARG((png_bytep buf));
|
||||
#endif /* PNG_BIG_ENDIAN_GET_SUPPORTED */
|
||||
#endif /* PNG_READ_BIG_ENDIAN_SUPPORTED */
|
||||
|
||||
/* Initialize png_ptr struct for reading, and allocate any other memory.
|
||||
* (old interface - NOT DLL EXPORTED).
|
||||
@@ -1608,6 +1766,11 @@ PNG_EXTERN png_voidp png_create_struct PNGARG((int type));
|
||||
/* free memory from internal libpng struct */
|
||||
PNG_EXTERN void png_destroy_struct PNGARG((png_voidp struct_ptr));
|
||||
|
||||
PNG_EXTERN png_voidp png_create_struct_2 PNGARG((int type, png_malloc_ptr
|
||||
malloc_fn));
|
||||
PNG_EXTERN void png_destroy_struct_2 PNGARG((png_voidp struct_ptr,
|
||||
png_free_ptr free_fn));
|
||||
|
||||
/* free any memory that info_ptr points to and reset struct. */
|
||||
PNG_EXTERN void png_info_destroy PNGARG((png_structp png_ptr,
|
||||
png_infop info_ptr));
|
||||
@@ -1651,8 +1814,8 @@ PNG_EXTERN void png_flush PNGARG((png_structp png_ptr));
|
||||
#endif
|
||||
|
||||
/* Place a 32-bit number into a buffer in PNG byte order (big-endian).
|
||||
* The only currently known PNG chunk that uses signed numbers is
|
||||
* the ancillary extension chunk, pCAL.
|
||||
* The only currently known PNG chunks that use signed numbers are
|
||||
* the ancillary extension chunks, oFFs and pCAL.
|
||||
*/
|
||||
PNG_EXTERN void png_save_uint_32 PNGARG((png_bytep buf, png_uint_32 i));
|
||||
|
||||
@@ -1723,7 +1886,8 @@ PNG_EXTERN void png_write_hIST PNGARG((png_structp png_ptr, png_uint_16p hist,
|
||||
int num_hist));
|
||||
#endif
|
||||
|
||||
#if defined(PNG_WRITE_tEXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED)
|
||||
#if defined(PNG_WRITE_tEXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED) || \
|
||||
defined(PNG_WRITE_pCAL_SUPPORTED)
|
||||
PNG_EXTERN png_size_t png_check_keyword PNGARG((png_structp png_ptr,
|
||||
png_charp key, png_charpp new_key));
|
||||
#endif
|
||||
@@ -1847,8 +2011,8 @@ PNG_EXTERN void png_do_packswap PNGARG((png_row_infop row_info, png_bytep row));
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
|
||||
PNG_EXTERN void png_do_rgb_to_gray PNGARG((png_row_infop row_info,
|
||||
png_bytep row));
|
||||
PNG_EXTERN int png_do_rgb_to_gray PNGARG((png_structp png_ptr, png_row_infop
|
||||
row_info, png_bytep row));
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
|
||||
|
@@ -1,12 +1,11 @@
|
||||
|
||||
/* pngconf.h - machine configurable file for libpng
|
||||
*
|
||||
* libpng 1.0.1
|
||||
* libpng 1.0.3 - January 14, 1999
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* March 15, 1998
|
||||
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
||||
*/
|
||||
|
||||
/* Any machine specific code is near the front of this file, so if you
|
||||
@@ -18,6 +17,7 @@
|
||||
#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
|
||||
@@ -47,17 +47,32 @@
|
||||
#define PNG_MAX_MALLOC_64K
|
||||
#endif
|
||||
|
||||
/* This protects us against compilers which run on a windowing system
|
||||
/* This protects us against compilers that 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.
|
||||
* in png_error() and png_warning(). #defining PNG_NO_CONSOLE_IO will
|
||||
* prevent these from being compiled and used. #defining PNG_NO_STDIO
|
||||
* will also prevent these, plus will prevent the entire set of stdio
|
||||
* macros and functions (FILE *, printf, etc.) from being compiled and used,
|
||||
* unless PNG_DEBUG has been #defined.
|
||||
*
|
||||
* #define PNG_NO_CONSOLE_IO
|
||||
* #define PNG_NO_STDIO
|
||||
*/
|
||||
|
||||
#ifndef PNG_NO_STDIO
|
||||
#ifdef PNG_DEBUG
|
||||
# if (PNG_DEBUG > 0)
|
||||
# include <stdio.h>
|
||||
# endif
|
||||
#else
|
||||
# ifdef PNG_NO_STDIO
|
||||
# ifndef PNG_NO_CONSOLE_IO
|
||||
# define PNG_NO_CONSOLE_IO
|
||||
# endif
|
||||
# else
|
||||
# include <stdio.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* This macro protects us against machines that don't have function
|
||||
* prototypes (ie K&R style headers). If your compiler does not handle
|
||||
@@ -237,72 +252,139 @@ __dont__ include it again
|
||||
/* Any transformations you will not be using can be undef'ed here */
|
||||
|
||||
/* GR-P, 0.96a: Set "*TRANSFORMS_SUPPORTED as default but allow user
|
||||
to turn it off with "*TRANSFORMS_NOT_SUPPORTED" on the compile line,
|
||||
then pick and choose which ones to define without having to edit
|
||||
this file. It is safe to use the *TRANSFORMS_NOT_SUPPORTED if you
|
||||
only want to have a png-compliant reader/writer but don't need
|
||||
to turn it off with "*TRANSFORMS_NOT_SUPPORTED" or *PNG_NO_*_TRANSFORMS
|
||||
on the compile line, then pick and choose which ones to define without
|
||||
having to edit this file. It is safe to use the *TRANSFORMS_NOT_SUPPORTED
|
||||
if you only want to have a png-compliant reader/writer but don't need
|
||||
any of the extra transformations. This saves about 80 kbytes in a
|
||||
typical installation of the library.
|
||||
typical installation of the library. (PNG_NO_* form added in version
|
||||
1.0.1c, for consistency)
|
||||
*/
|
||||
|
||||
|
||||
#ifndef PNG_READ_TRANSFORMS_NOT_SUPPORTED
|
||||
#if !defined(PNG_READ_TRANSFORMS_NOT_SUPPORTED) && \
|
||||
!defined(PNG_NO_READ_TRANSFORMS)
|
||||
#define PNG_READ_TRANSFORMS_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_WRITE_TRANSFORMS_NOT_SUPPORTED
|
||||
#if !defined(PNG_WRITE_TRANSFORMS_NOT_SUPPORTED) && \
|
||||
!defined(PNG_NO_WRITE_TRANSFORMS)
|
||||
#define PNG_WRITE_TRANSFORMS_SUPPORTED
|
||||
#endif
|
||||
|
||||
#ifdef PNG_READ_TRANSFORMS_SUPPORTED
|
||||
#ifndef PNG_NO_READ_EXPAND
|
||||
#define PNG_READ_EXPAND_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_READ_SHIFT
|
||||
#define PNG_READ_SHIFT_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_READ_PACK
|
||||
#define PNG_READ_PACK_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_READ_BGR
|
||||
#define PNG_READ_BGR_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_READ_SWAP
|
||||
#define PNG_READ_SWAP_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_READ_PACKSWAP
|
||||
#define PNG_READ_PACKSWAP_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_READ_INVERT
|
||||
#define PNG_READ_INVERT_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_READ_DITHER
|
||||
#define PNG_READ_DITHER_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_READ_BACKGROUND
|
||||
#define PNG_READ_BACKGROUND_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_READ_16_TO_8
|
||||
#define PNG_READ_16_TO_8_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_READ_FILLER
|
||||
#define PNG_READ_FILLER_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_READ_GAMMA
|
||||
#define PNG_READ_GAMMA_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_READ_GRAY_TO_RGB
|
||||
#define PNG_READ_GRAY_TO_RGB_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_READ_SWAP_ALPHA
|
||||
#define PNG_READ_SWAP_ALPHA_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_READ_INVERT_ALPHA
|
||||
#define PNG_READ_INVERT_ALPHA_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_READ_STRIP_ALPHA
|
||||
#define PNG_READ_STRIP_ALPHA_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_READ_USER_TRANSFORM
|
||||
#define PNG_READ_USER_TRANSFORM_SUPPORTED
|
||||
/* the following aren't implemented yet
|
||||
#endif
|
||||
#ifndef PNG_NO_READ_RGB_TO_GRAY
|
||||
#define PNG_READ_RGB_TO_GRAY_SUPPORTED
|
||||
*/
|
||||
#endif
|
||||
#endif /* PNG_READ_TRANSFORMS_SUPPORTED */
|
||||
|
||||
#ifndef PNG_PROGRESSIVE_READ_NOT_SUPPORTED /* if you don't do progressive */
|
||||
#if !defined(PNG_NO_PROGRESSIVE_READ) && \
|
||||
!defined(PNG_PROGRESSIVE_READ_NOT_SUPPORTED) /* if you don't do progressive */
|
||||
#define PNG_PROGRESSIVE_READ_SUPPORTED /* reading. This is not talking */
|
||||
#endif /* about interlacing capability! You'll */
|
||||
/* still have interlacing unless you change the following line: */
|
||||
#define PNG_READ_INTERLACING_SUPPORTED /* required for PNG-compliant decoders */
|
||||
|
||||
#ifndef PNG_NO_READ_COMPOSITED_NODIV
|
||||
#define PNG_READ_COMPOSITE_NODIV_SUPPORTED /* well tested on Intel and SGI */
|
||||
#endif
|
||||
|
||||
#ifdef PNG_WRITE_TRANSFORMS_SUPPORTED
|
||||
#ifndef PNG_NO_WRITE_SHIFT
|
||||
#define PNG_WRITE_SHIFT_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_WRITE_PACK
|
||||
#define PNG_WRITE_PACK_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_WRITE_BGR
|
||||
#define PNG_WRITE_BGR_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_WRITE_SWAP
|
||||
#define PNG_WRITE_SWAP_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_WRITE_PACKSWAP
|
||||
#define PNG_WRITE_PACKSWAP_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_WRITE_INVERT
|
||||
#define PNG_WRITE_INVERT_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_WRITE_FILLER
|
||||
#define PNG_WRITE_FILLER_SUPPORTED /* This is the same as WRITE_STRIP_ALPHA */
|
||||
#define PNG_WRITE_FLUSH_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_WRITE_SWAP_ALPHA
|
||||
#define PNG_WRITE_SWAP_ALPHA_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_WRITE_INVERT_ALPHA
|
||||
#define PNG_WRITE_INVERT_ALPHA_SUPPORTED
|
||||
#define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_WRITE_USER_TRANSFORM
|
||||
#define PNG_WRITE_USER_TRANSFORM_SUPPORTED
|
||||
#endif
|
||||
#endif /* PNG_WRITE_TRANSFORMS_SUPPORTED */
|
||||
|
||||
#define PNG_WRITE_INTERLACING_SUPPORTED /* not required for PNG-compliant
|
||||
encoders, but can cause trouble
|
||||
if left undefined */
|
||||
|
||||
#if !defined(PNG_NO_STDIO)
|
||||
#ifndef PNG_NO_WRITE_WEIGHTED_FILTER
|
||||
#define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
|
||||
#endif
|
||||
|
||||
#ifndef PNG_NO_WRITE_FLUSH
|
||||
#define PNG_WRITE_FLUSH_SUPPORTED
|
||||
#endif
|
||||
|
||||
#ifndef PNG_NO_STDIO
|
||||
#define PNG_TIME_RFC1123_SUPPORTED
|
||||
#endif
|
||||
|
||||
@@ -322,7 +404,7 @@ __dont__ include it again
|
||||
* png_get_x_offset_microns()
|
||||
* png_get_y_offset_microns()
|
||||
*/
|
||||
#if !defined(PNG_NO_EASY_ACCESS)
|
||||
#ifndef PNG_NO_EASY_ACCESS
|
||||
#define PNG_EASY_ACCESS_SUPPORTED
|
||||
#endif
|
||||
|
||||
@@ -331,6 +413,7 @@ __dont__ include it again
|
||||
/* very little testing */
|
||||
/*
|
||||
#define PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED
|
||||
#define PNG_USER_MEM_SUPPORTED
|
||||
*/
|
||||
|
||||
/* This is only for PowerPC big-endian and 680x0 systems */
|
||||
@@ -351,45 +434,100 @@ __dont__ include it again
|
||||
* a bit smaller.
|
||||
*/
|
||||
|
||||
#ifndef PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED
|
||||
#if !defined(PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \
|
||||
!defined(PNG_NO_READ_ANCILLARY_CHUNKS)
|
||||
#define PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED
|
||||
#if !defined(PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \
|
||||
!defined(PNG_NO_WRITE_ANCILLARY_CHUNKS)
|
||||
#define PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
|
||||
#endif
|
||||
|
||||
#ifdef PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
|
||||
#ifndef PNG_NO_READ_bKGD
|
||||
#define PNG_READ_bKGD_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_READ_cHRM
|
||||
#define PNG_READ_cHRM_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_READ_gAMA
|
||||
#define PNG_READ_gAMA_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_READ_hIST
|
||||
#define PNG_READ_hIST_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_READ_oFFs
|
||||
#define PNG_READ_oFFs_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_READ_pCAL
|
||||
#define PNG_READ_pCAL_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_READ_pHYs
|
||||
#define PNG_READ_pHYs_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_READ_sBIT
|
||||
#define PNG_READ_sBIT_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_READ_sRGB
|
||||
#define PNG_READ_sRGB_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_READ_tEXt
|
||||
#define PNG_READ_tEXt_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_READ_tIME
|
||||
#define PNG_READ_tIME_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_READ_tRNS
|
||||
#define PNG_READ_tRNS_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_READ_zTXt
|
||||
#define PNG_READ_zTXt_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_READ_OPT_PLTE
|
||||
#define PNG_READ_OPT_PLTE_SUPPORTED /* only affects support of the optional */
|
||||
/* PLTE chunk in RGB and RGBA images */
|
||||
#endif /* PLTE chunk in RGB and RGBA images */
|
||||
#endif /* PNG_READ_ANCILLARY_CHUNKS_SUPPORTED */
|
||||
|
||||
#ifdef PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
|
||||
#ifndef PNG_NO_WRITE_bKGD
|
||||
#define PNG_WRITE_bKGD_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_WRITE_cHRM
|
||||
#define PNG_WRITE_cHRM_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_WRITE_gAMA
|
||||
#define PNG_WRITE_gAMA_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_WRITE_hIST
|
||||
#define PNG_WRITE_hIST_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_WRITE_oFFs
|
||||
#define PNG_WRITE_oFFs_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_WRITE_pCAL
|
||||
#define PNG_WRITE_pCAL_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_WRITE_pHYs
|
||||
#define PNG_WRITE_pHYs_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_WRITE_sBIT
|
||||
#define PNG_WRITE_sBIT_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_WRITE_sRGB
|
||||
#define PNG_WRITE_sRGB_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_WRITE_tEXt
|
||||
#define PNG_WRITE_tEXt_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_WRITE_tIME
|
||||
#define PNG_WRITE_tIME_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_WRITE_tRNS
|
||||
#define PNG_WRITE_tRNS_SUPPORTED
|
||||
#endif
|
||||
#ifndef PNG_NO_WRITE_zTXt
|
||||
#define PNG_WRITE_zTXt_SUPPORTED
|
||||
#endif
|
||||
#endif /* PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED */
|
||||
|
||||
/* need the time information for reading tIME chunks */
|
||||
@@ -539,6 +677,7 @@ typedef z_stream FAR * png_zstreamp;
|
||||
# define NOCHECK 0
|
||||
# define CVT_PTR(ptr) (png_far_to_near(png_ptr,ptr,CHECK))
|
||||
# define CVT_PTR_NOCHECK(ptr) (png_far_to_near(png_ptr,ptr,NOCHECK))
|
||||
# define png_strcpy _fstrcpy
|
||||
# define png_strlen _fstrlen
|
||||
# define png_memcmp _fmemcmp /* SJT: added */
|
||||
# define png_memcpy _fmemcpy
|
||||
@@ -546,6 +685,7 @@ typedef z_stream FAR * png_zstreamp;
|
||||
#else /* use the usual functions */
|
||||
# define CVT_PTR(ptr) (ptr)
|
||||
# define CVT_PTR_NOCHECK(ptr) (ptr)
|
||||
# define png_strcpy strcpy
|
||||
# define png_strlen strlen
|
||||
# define png_memcmp memcmp /* SJT: added */
|
||||
# define png_memcpy memcpy
|
||||
|
@@ -1,21 +1,20 @@
|
||||
|
||||
/* pngerror.c - stub functions for i/o and memory allocation
|
||||
*
|
||||
* libpng 1.0.1
|
||||
* libpng 1.0.3 - January 14, 1999
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* March 15, 1998
|
||||
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
||||
*
|
||||
* This file provides a location for all error handling. Users which
|
||||
* This file provides a location for all error handling. Users who
|
||||
* 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/png.h"
|
||||
#include "png.h"
|
||||
|
||||
static void png_default_error PNGARG((png_structp png_ptr,
|
||||
png_const_charp message));
|
||||
@@ -52,7 +51,7 @@ png_warning(png_structp png_ptr, png_const_charp message)
|
||||
png_default_warning(png_ptr, message);
|
||||
}
|
||||
|
||||
/* These utilities are used internally to build an error message which relates
|
||||
/* These utilities are used internally to build an error message that 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 []
|
||||
@@ -114,7 +113,7 @@ png_chunk_warning(png_structp png_ptr, png_const_charp message)
|
||||
static void
|
||||
png_default_error(png_structp png_ptr, png_const_charp message)
|
||||
{
|
||||
#ifndef PNG_NO_STDIO
|
||||
#ifndef PNG_NO_CONSOLE_IO
|
||||
fprintf(stderr, "libpng error: %s\n", message);
|
||||
#endif
|
||||
|
||||
@@ -131,18 +130,17 @@ 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
|
||||
* here if you don't want them to. In the default configuration, png_ptr is
|
||||
* not used, but it is passed in case it may be useful.
|
||||
*/
|
||||
static void
|
||||
png_default_warning(png_structp png_ptr, png_const_charp message)
|
||||
{
|
||||
if (png_ptr == NULL)
|
||||
return;
|
||||
|
||||
#ifndef PNG_NO_STDIO
|
||||
#ifndef PNG_NO_CONSOLE_IO
|
||||
fprintf(stderr, "libpng warning: %s\n", message);
|
||||
#endif
|
||||
if (png_ptr == NULL)
|
||||
return;
|
||||
}
|
||||
|
||||
/* This function is called when the application wants to use another method
|
||||
|
@@ -1,16 +1,15 @@
|
||||
|
||||
/* pngget.c - retrieval of values from info struct
|
||||
*
|
||||
* libpng 1.0.1
|
||||
* libpng 1.0.3 - January 14, 1999
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* March 15, 1998
|
||||
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
#include "../png/png.h"
|
||||
#include "png.h"
|
||||
|
||||
png_uint_32
|
||||
png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag)
|
||||
@@ -302,11 +301,11 @@ png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr,
|
||||
}
|
||||
return (retval);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* PNG_READ_pHYs_SUPPORTED */
|
||||
#endif /* PNG_INCH_CONVERSIONS */
|
||||
|
||||
/* png_get_channels really belongs in here, too, but it's been around longer */
|
||||
|
||||
#endif /* PNG_EASY_ACCESS_SUPPORTED */
|
||||
|
||||
png_byte
|
||||
@@ -642,3 +641,10 @@ png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
|
||||
png_byte
|
||||
png_get_rgb_to_gray_status (png_structp png_ptr)
|
||||
{
|
||||
return png_ptr->rgb_to_gray_status;
|
||||
}
|
||||
#endif
|
||||
|
207
src/png/pngmem.c
207
src/png/pngmem.c
@@ -1,30 +1,21 @@
|
||||
|
||||
/* pngmem.c - stub functions for memory allocation
|
||||
*
|
||||
* libpng 1.0.1
|
||||
* libpng 1.0.3 - January 14, 1999
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* March 15, 1998
|
||||
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
||||
*
|
||||
* 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.
|
||||
* This file provides a location for all memory allocation. Users who
|
||||
* need special memory handling are expected to supply replacement
|
||||
* functions for png_malloc() and png_free(), and to use
|
||||
* png_create_read_struct_2() and png_create_write_struct_2() to
|
||||
* identify the replacement functions.
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
#include "../png/png.h"
|
||||
|
||||
/* The following "hides" PNG_MALLOC and PNG_FREE thus allowing the pngtest
|
||||
application to put a wrapper on top of them. */
|
||||
#ifdef PNGTEST_MEMORY_DEBUG
|
||||
#define PNG_MALLOC png_debug_malloc
|
||||
#define PNG_FREE png_debug_free
|
||||
#else
|
||||
#define PNG_MALLOC png_malloc
|
||||
#define PNG_FREE png_free
|
||||
#endif
|
||||
#include "png.h"
|
||||
|
||||
/* Borland DOS special memory handler */
|
||||
#if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
|
||||
@@ -35,6 +26,15 @@
|
||||
png_voidp
|
||||
png_create_struct(int type)
|
||||
{
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
return (png_create_struct_2(type, NULL));
|
||||
}
|
||||
|
||||
/* Alternate version of png_create_struct, for use with user-defined malloc. */
|
||||
png_voidp
|
||||
png_create_struct_2(int type, png_malloc_ptr malloc_fn)
|
||||
{
|
||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||
png_size_t size;
|
||||
png_voidp struct_ptr;
|
||||
|
||||
@@ -45,11 +45,18 @@ png_create_struct(int type)
|
||||
else
|
||||
return ((png_voidp)NULL);
|
||||
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
if(malloc_fn != NULL)
|
||||
{
|
||||
if ((struct_ptr = (*(malloc_fn))(NULL, size)) != NULL)
|
||||
png_memset(struct_ptr, 0, size);
|
||||
return (struct_ptr);
|
||||
}
|
||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||
if ((struct_ptr = (png_voidp)farmalloc(size)) != NULL)
|
||||
{
|
||||
png_memset(struct_ptr, 0, size);
|
||||
}
|
||||
|
||||
return (struct_ptr);
|
||||
}
|
||||
|
||||
@@ -58,8 +65,27 @@ png_create_struct(int type)
|
||||
void
|
||||
png_destroy_struct(png_voidp struct_ptr)
|
||||
{
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
png_destroy_struct_2(struct_ptr, (png_free_ptr)NULL);
|
||||
}
|
||||
|
||||
/* Free memory allocated by a png_create_struct() call */
|
||||
void
|
||||
png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn)
|
||||
{
|
||||
#endif
|
||||
if (struct_ptr != NULL)
|
||||
{
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
if(free_fn != NULL)
|
||||
{
|
||||
png_struct dummy_struct;
|
||||
png_structp png_ptr = &dummy_struct;
|
||||
(*(free_fn))(png_ptr, struct_ptr);
|
||||
struct_ptr = NULL;
|
||||
return;
|
||||
}
|
||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||
farfree (struct_ptr);
|
||||
struct_ptr = NULL;
|
||||
}
|
||||
@@ -72,7 +98,7 @@ png_destroy_struct(png_voidp struct_ptr)
|
||||
* 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
|
||||
* It gives you a segment with an offset of 8 (perhaps to store its
|
||||
* 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
|
||||
@@ -85,12 +111,27 @@ png_destroy_struct(png_voidp struct_ptr)
|
||||
* (which should cause a fatal error) and introducing major problems.
|
||||
*/
|
||||
png_voidp
|
||||
PNG_MALLOC(png_structp png_ptr, png_uint_32 size)
|
||||
png_malloc(png_structp png_ptr, png_uint_32 size)
|
||||
{
|
||||
#ifndef PNG_USER_MEM_SUPPORTED
|
||||
png_voidp ret;
|
||||
#endif
|
||||
if (png_ptr == NULL || size == 0)
|
||||
return ((png_voidp)NULL);
|
||||
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
if(png_ptr->malloc_fn != NULL)
|
||||
return ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, size));
|
||||
else
|
||||
return png_malloc_default(png_ptr, size);
|
||||
}
|
||||
|
||||
png_voidp
|
||||
png_malloc_default(png_structp png_ptr, png_uint_32 size)
|
||||
{
|
||||
png_voidp ret;
|
||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||
|
||||
#ifdef PNG_MAX_MALLOC_64K
|
||||
if (size > (png_uint_32)65536L)
|
||||
png_error(png_ptr, "Cannot Allocate > 64K");
|
||||
@@ -181,15 +222,30 @@ PNG_MALLOC(png_structp png_ptr, png_uint_32 size)
|
||||
return (ret);
|
||||
}
|
||||
|
||||
/* free a pointer allocated by PNG_MALLOC(). In the default
|
||||
/* free a pointer allocated by png_malloc(). In the default
|
||||
configuration, png_ptr is not used, but is passed in case it
|
||||
is needed. If ptr is NULL, return without taking any action. */
|
||||
void
|
||||
PNG_FREE(png_structp png_ptr, png_voidp ptr)
|
||||
png_free(png_structp png_ptr, png_voidp ptr)
|
||||
{
|
||||
if (png_ptr == NULL || ptr == NULL)
|
||||
return;
|
||||
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
if (png_ptr->free_fn != NULL)
|
||||
{
|
||||
(*(png_ptr->free_fn))(png_ptr, ptr);
|
||||
ptr = NULL;
|
||||
return;
|
||||
}
|
||||
else png_free_default(png_ptr, ptr);
|
||||
}
|
||||
|
||||
void
|
||||
png_free_default(png_structp png_ptr, png_voidp ptr)
|
||||
{
|
||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||
|
||||
if (png_ptr->offset_table != NULL)
|
||||
{
|
||||
int i;
|
||||
@@ -227,6 +283,17 @@ PNG_FREE(png_structp png_ptr, png_voidp ptr)
|
||||
png_voidp
|
||||
png_create_struct(int type)
|
||||
{
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
return (png_create_struct_2(type, NULL));
|
||||
}
|
||||
|
||||
/* 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.*/
|
||||
png_voidp
|
||||
png_create_struct_2(int type, png_malloc_ptr malloc_fn)
|
||||
{
|
||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||
png_size_t size;
|
||||
png_voidp struct_ptr;
|
||||
|
||||
@@ -237,6 +304,15 @@ png_create_struct(int type)
|
||||
else
|
||||
return ((png_voidp)NULL);
|
||||
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
if(malloc_fn != NULL)
|
||||
{
|
||||
if ((struct_ptr = (*(malloc_fn))(NULL, size)) != NULL)
|
||||
png_memset(struct_ptr, 0, size);
|
||||
return (struct_ptr);
|
||||
}
|
||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||
|
||||
#if defined(__TURBOC__) && !defined(__FLAT__)
|
||||
if ((struct_ptr = (png_voidp)farmalloc(size)) != NULL)
|
||||
#else
|
||||
@@ -258,15 +334,37 @@ png_create_struct(int type)
|
||||
void
|
||||
png_destroy_struct(png_voidp struct_ptr)
|
||||
{
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
png_destroy_struct_2(struct_ptr, (png_free_ptr)NULL);
|
||||
}
|
||||
|
||||
/* Free memory allocated by a png_create_struct() call */
|
||||
void
|
||||
png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn)
|
||||
{
|
||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||
if (struct_ptr != NULL)
|
||||
{
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
if(free_fn != NULL)
|
||||
{
|
||||
png_struct dummy_struct;
|
||||
png_structp png_ptr = &dummy_struct;
|
||||
(*(free_fn))(png_ptr, struct_ptr);
|
||||
struct_ptr = NULL;
|
||||
return;
|
||||
}
|
||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||
#if defined(__TURBOC__) && !defined(__FLAT__)
|
||||
farfree(struct_ptr);
|
||||
struct_ptr = NULL;
|
||||
#else
|
||||
# if defined(_MSC_VER) && defined(MAXSEG_64K)
|
||||
hfree(struct_ptr);
|
||||
struct_ptr = NULL;
|
||||
# else
|
||||
free(struct_ptr);
|
||||
struct_ptr = NULL;
|
||||
# endif
|
||||
#endif
|
||||
}
|
||||
@@ -280,13 +378,26 @@ png_destroy_struct(png_voidp struct_ptr)
|
||||
have the ability to do that. */
|
||||
|
||||
png_voidp
|
||||
PNG_MALLOC(png_structp png_ptr, png_uint_32 size)
|
||||
png_malloc(png_structp png_ptr, png_uint_32 size)
|
||||
{
|
||||
#ifndef PNG_USER_MEM_SUPPORTED
|
||||
png_voidp ret;
|
||||
|
||||
#endif
|
||||
if (png_ptr == NULL || size == 0)
|
||||
return ((png_voidp)NULL);
|
||||
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
if(png_ptr->malloc_fn != NULL)
|
||||
return ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, size));
|
||||
else
|
||||
return (png_malloc_default(png_ptr, size));
|
||||
}
|
||||
png_voidp
|
||||
png_malloc_default(png_structp png_ptr, png_uint_32 size)
|
||||
{
|
||||
png_voidp ret;
|
||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||
|
||||
#ifdef PNG_MAX_MALLOC_64K
|
||||
if (size > (png_uint_32)65536L)
|
||||
png_error(png_ptr, "Cannot Allocate > 64K");
|
||||
@@ -310,22 +421,38 @@ PNG_MALLOC(png_structp png_ptr, png_uint_32 size)
|
||||
return (ret);
|
||||
}
|
||||
|
||||
/* 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. */
|
||||
/* Free a pointer allocated by png_malloc(). If ptr is NULL, return
|
||||
without taking any action. */
|
||||
void
|
||||
PNG_FREE(png_structp png_ptr, png_voidp ptr)
|
||||
png_free(png_structp png_ptr, png_voidp ptr)
|
||||
{
|
||||
if (png_ptr == NULL || ptr == NULL)
|
||||
return;
|
||||
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
if (png_ptr->free_fn != NULL)
|
||||
{
|
||||
(*(png_ptr->free_fn))(png_ptr, ptr);
|
||||
ptr = NULL;
|
||||
return;
|
||||
}
|
||||
else png_free_default(png_ptr, ptr);
|
||||
}
|
||||
void
|
||||
png_free_default(png_structp png_ptr, png_voidp ptr)
|
||||
{
|
||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||
|
||||
#if defined(__TURBOC__) && !defined(__FLAT__)
|
||||
farfree(ptr);
|
||||
ptr = NULL;
|
||||
#else
|
||||
# if defined(_MSC_VER) && defined(MAXSEG_64K)
|
||||
hfree(ptr);
|
||||
ptr = NULL;
|
||||
# else
|
||||
free(ptr);
|
||||
ptr = NULL;
|
||||
# endif
|
||||
#endif
|
||||
}
|
||||
@@ -358,3 +485,27 @@ png_memset_check (png_structp png_ptr, png_voidp s1, int value,
|
||||
return (png_memset (s1, value, size));
|
||||
|
||||
}
|
||||
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
/* This function is called when the application wants to use another method
|
||||
* of allocating and freeing memory.
|
||||
*/
|
||||
void
|
||||
png_set_mem_fn(png_structp png_ptr, png_voidp mem_ptr, png_malloc_ptr
|
||||
malloc_fn, png_free_ptr free_fn)
|
||||
{
|
||||
png_ptr->mem_ptr = mem_ptr;
|
||||
png_ptr->malloc_fn = malloc_fn;
|
||||
png_ptr->free_fn = free_fn;
|
||||
}
|
||||
|
||||
/* This function returns a pointer to the mem_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.
|
||||
*/
|
||||
png_voidp
|
||||
png_get_mem_ptr(png_structp png_ptr)
|
||||
{
|
||||
return ((png_voidp)png_ptr->mem_ptr);
|
||||
}
|
||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||
|
@@ -1,16 +1,15 @@
|
||||
|
||||
/* pngpread.c - read a png file in push mode
|
||||
*
|
||||
* libpng 1.0.1
|
||||
* libpng 1.0.3 - January 14, 1999
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* March 15, 1998
|
||||
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
#include "../png/png.h"
|
||||
#include "png.h"
|
||||
|
||||
#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
|
||||
|
||||
@@ -78,8 +77,9 @@ png_process_some_data(png_structp png_ptr, png_infop info_ptr)
|
||||
|
||||
/* Read any remaining signature bytes from the stream and compare them with
|
||||
* the correct PNG signature. It is possible that this routine is called
|
||||
* with bytes already read from the signature, whether because they have been
|
||||
* checked by the calling application, or from multiple calls to this routine.
|
||||
* with bytes already read from the signature, either because they have been
|
||||
* checked by the calling application, or because of multiple calls to this
|
||||
* routine.
|
||||
*/
|
||||
void
|
||||
png_push_read_sig(png_structp png_ptr, png_infop info_ptr)
|
||||
@@ -446,13 +446,13 @@ png_push_save_buffer(png_structp png_ptr)
|
||||
{
|
||||
if (png_ptr->save_buffer_ptr != png_ptr->save_buffer)
|
||||
{
|
||||
png_size_t i;
|
||||
png_size_t i,istop;
|
||||
png_bytep sp;
|
||||
png_bytep dp;
|
||||
|
||||
istop = png_ptr->save_buffer_size;
|
||||
for (i = 0, sp = png_ptr->save_buffer_ptr, dp = png_ptr->save_buffer;
|
||||
i < png_ptr->save_buffer_size;
|
||||
i++, sp++, dp++)
|
||||
i < istop; i++, sp++, dp++)
|
||||
{
|
||||
*dp = *sp;
|
||||
}
|
||||
@@ -781,6 +781,7 @@ png_read_push_finish_row(png_structp png_ptr)
|
||||
png_ptr->pass++;
|
||||
if (png_ptr->pass >= 7)
|
||||
break;
|
||||
|
||||
png_ptr->iwidth = (png_ptr->width +
|
||||
png_pass_inc[png_ptr->pass] - 1 -
|
||||
png_pass_start[png_ptr->pass]) /
|
||||
@@ -789,18 +790,15 @@ png_read_push_finish_row(png_structp png_ptr)
|
||||
png_ptr->irowbytes = ((png_ptr->iwidth *
|
||||
png_ptr->pixel_depth + 7) >> 3) + 1;
|
||||
|
||||
if (!(png_ptr->transformations & PNG_INTERLACE))
|
||||
{
|
||||
if (png_ptr->transformations & PNG_INTERLACE)
|
||||
break;
|
||||
|
||||
png_ptr->num_rows = (png_ptr->height +
|
||||
png_pass_yinc[png_ptr->pass] - 1 -
|
||||
png_pass_ystart[png_ptr->pass]) /
|
||||
png_pass_yinc[png_ptr->pass];
|
||||
if (!(png_ptr->num_rows))
|
||||
continue;
|
||||
}
|
||||
if (png_ptr->transformations & PNG_INTERLACE)
|
||||
break;
|
||||
} while (png_ptr->iwidth == 0);
|
||||
|
||||
} while (png_ptr->iwidth == 0 || png_ptr->num_rows == 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1070,7 +1068,7 @@ png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
|
||||
#endif
|
||||
|
||||
/* This function is called when we haven't found a handler for this
|
||||
* chunk. In the future we will have code here which can handle
|
||||
* chunk. In the future we will have code here that can handle
|
||||
* user-defined callback functions for unknown chunks before they are
|
||||
* ignored or cause an error. If there isn't a problem with the
|
||||
* chunk itself (ie a bad chunk name or a critical chunk), the chunk
|
||||
@@ -1117,7 +1115,7 @@ void
|
||||
png_progressive_combine_row (png_structp png_ptr,
|
||||
png_bytep old_row, png_bytep new_row)
|
||||
{
|
||||
if (new_row != NULL)
|
||||
if (new_row != NULL) /* new_row must == png_ptr->row_buf here. */
|
||||
png_combine_row(png_ptr, old_row, png_pass_dsp_mask[png_ptr->pass]);
|
||||
}
|
||||
|
||||
|
@@ -1,31 +1,49 @@
|
||||
|
||||
/* pngread.c - read a PNG file
|
||||
*
|
||||
* libpng 1.0.1
|
||||
* libpng 1.0.3 - January 14, 1999
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* March 15, 1998
|
||||
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
||||
*
|
||||
* This file contains routines that an application calls directly to
|
||||
* read a PNG file or stream.
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
#include "../png/png.h"
|
||||
#include "png.h"
|
||||
|
||||
/* Create a PNG structure for reading, and allocate any memory needed. */
|
||||
png_structp
|
||||
png_create_read_struct(png_const_charp user_png_ver, voidp error_ptr,
|
||||
png_create_read_struct(png_const_charp user_png_ver, png_voidp error_ptr,
|
||||
png_error_ptr error_fn, png_error_ptr warn_fn)
|
||||
{
|
||||
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
return (png_create_read_struct_2(user_png_ver, error_ptr, error_fn,
|
||||
warn_fn, NULL, NULL, NULL));
|
||||
}
|
||||
|
||||
/* Alternate create PNG structure for reading, and allocate any memory needed. */
|
||||
png_structp
|
||||
png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
|
||||
png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
|
||||
png_malloc_ptr malloc_fn, png_free_ptr free_fn)
|
||||
{
|
||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||
|
||||
png_structp png_ptr;
|
||||
#ifdef USE_FAR_KEYWORD
|
||||
jmp_buf jmpbuf;
|
||||
#endif
|
||||
png_debug(1, "in png_create_read_struct\n");
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
if ((png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
|
||||
(png_malloc_ptr)malloc_fn)) == NULL)
|
||||
#else
|
||||
if ((png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG)) == NULL)
|
||||
#endif
|
||||
{
|
||||
return (png_structp)NULL;
|
||||
}
|
||||
@@ -42,6 +60,11 @@ png_create_read_struct(png_const_charp user_png_ver, voidp error_ptr,
|
||||
#ifdef USE_FAR_KEYWORD
|
||||
png_memcpy(png_ptr->jmpbuf,jmpbuf,sizeof(jmp_buf));
|
||||
#endif
|
||||
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
|
||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||
|
||||
png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
|
||||
|
||||
/* Libpng 0.90 and later are binary incompatible with libpng 0.89, so
|
||||
@@ -82,7 +105,7 @@ png_create_read_struct(png_const_charp user_png_ver, voidp error_ptr,
|
||||
}
|
||||
|
||||
/* Initialize PNG structure for reading, and allocate any memory needed.
|
||||
This interface is depreciated in favour of the png_create_read_struct(),
|
||||
This interface is deprecated in favour of the png_create_read_struct(),
|
||||
and it will eventually disappear. */
|
||||
void
|
||||
png_read_init(png_structp png_ptr)
|
||||
@@ -125,7 +148,7 @@ png_read_init(png_structp png_ptr)
|
||||
/* Read the information before the actual image data. This has been
|
||||
* changed in v0.90 to allow reading a file that already has the magic
|
||||
* bytes read from the stream. You can tell libpng how many bytes have
|
||||
* been read from the beginning of the stream (up to the maxumum of 8)
|
||||
* been read from the beginning of the stream (up to the maximum of 8)
|
||||
* via png_set_sig_bytes(), and we will only check the remaining bytes
|
||||
* here. The application can then have access to the signature bytes we
|
||||
* read if it is determined that this isn't a valid PNG file.
|
||||
@@ -258,7 +281,7 @@ png_read_update_info(png_structp png_ptr, png_infop info_ptr)
|
||||
|
||||
/* Initialize palette, background, etc, after transformations
|
||||
* are set, but before any reading takes place. This allows
|
||||
* the user to obtail a gamma corrected palette, for example.
|
||||
* the user to obtain a gamma-corrected palette, for example.
|
||||
* If the user doesn't call this, we will do it ourselves.
|
||||
*/
|
||||
void
|
||||
@@ -279,6 +302,38 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
|
||||
/* save jump buffer and error functions */
|
||||
if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
|
||||
png_read_start_row(png_ptr);
|
||||
if (png_ptr->row_number == 0 && png_ptr->pass == 0)
|
||||
{
|
||||
/* check for transforms that have been set but were defined out */
|
||||
#if defined(PNG_WRITE_INVERT_SUPPORTED) && !defined(PNG_READ_INVERT_SUPPORTED)
|
||||
if (png_ptr->transformations & PNG_INVERT_MONO)
|
||||
png_warning(png_ptr, "PNG_READ_INVERT_SUPPORTED is not defined.");
|
||||
#endif
|
||||
#if defined(PNG_WRITE_FILLER_SUPPORTED) && !defined(PNG_READ_FILLER_SUPPORTED)
|
||||
if (png_ptr->transformations & PNG_FILLER)
|
||||
png_warning(png_ptr, "PNG_READ_FILLER_SUPPORTED is not defined.");
|
||||
#endif
|
||||
#if defined(PNG_WRITE_PACKSWAP_SUPPORTED) && !defined(PNG_READ_PACKSWAP_SUPPORTED)
|
||||
if (png_ptr->transformations & PNG_PACKSWAP)
|
||||
png_warning(png_ptr, "PNG_READ_PACKSWAP_SUPPORTED is not defined.");
|
||||
#endif
|
||||
#if defined(PNG_WRITE_PACK_SUPPORTED) && !defined(PNG_READ_PACK_SUPPORTED)
|
||||
if (png_ptr->transformations & PNG_PACK)
|
||||
png_warning(png_ptr, "PNG_READ_PACK_SUPPORTED is not defined.");
|
||||
#endif
|
||||
#if defined(PNG_WRITE_SHIFT_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED)
|
||||
if (png_ptr->transformations & PNG_SHIFT)
|
||||
png_warning(png_ptr, "PNG_READ_SHIFT_SUPPORTED is not defined.");
|
||||
#endif
|
||||
#if defined(PNG_WRITE_BGR_SUPPORTED) && !defined(PNG_READ_BGR_SUPPORTED)
|
||||
if (png_ptr->transformations & PNG_BGR)
|
||||
png_warning(png_ptr, "PNG_READ_BGR_SUPPORTED is not defined.");
|
||||
#endif
|
||||
#if defined(PNG_WRITE_SWAP_SUPPORTED) && !defined(PNG_READ_SWAP_SUPPORTED)
|
||||
if (png_ptr->transformations & PNG_SWAP_BYTES)
|
||||
png_warning(png_ptr, "PNG_READ_SWAP_SUPPORTED is not defined.");
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(PNG_READ_INTERLACING_SUPPORTED)
|
||||
/* if interlaced and we do not need a new row, combine row and return */
|
||||
@@ -457,7 +512,7 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
|
||||
/* Read one or more rows of image data. If the image is interlaced,
|
||||
* and png_set_interlace_handling() has been called, the rows need to
|
||||
* contain the contents of the rows from the previous pass. If the
|
||||
* image has alpha or transparency, and png_handle_alpha() has been
|
||||
* image has alpha or transparency, and png_handle_alpha()[*] has been
|
||||
* called, the rows contents must be initialized to the contents of the
|
||||
* screen.
|
||||
*
|
||||
@@ -474,6 +529,8 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
|
||||
* also, but you may. If the image is not interlaced, or if you have
|
||||
* not called png_set_interlace_handling(), the display_row buffer will
|
||||
* be ignored, so pass NULL to it.
|
||||
*
|
||||
* [*] png_handle_alpha() does not exist yet, as of libpng version 1.0.3.
|
||||
*/
|
||||
|
||||
void
|
||||
@@ -488,29 +545,32 @@ png_read_rows(png_structp png_ptr, png_bytepp row,
|
||||
/* save jump buffer and error functions */
|
||||
rp = row;
|
||||
dp = display_row;
|
||||
if (rp != NULL && dp != NULL)
|
||||
for (i = 0; i < num_rows; i++)
|
||||
{
|
||||
png_bytep rptr;
|
||||
png_bytep dptr;
|
||||
png_bytep rptr = *rp++;
|
||||
png_bytep dptr = *dp++;
|
||||
|
||||
if (rp != NULL)
|
||||
rptr = *rp;
|
||||
else
|
||||
rptr = NULL;
|
||||
if (dp != NULL)
|
||||
dptr = *dp;
|
||||
else
|
||||
dptr = NULL;
|
||||
png_read_row(png_ptr, rptr, dptr);
|
||||
if (row != NULL)
|
||||
}
|
||||
else if(rp != NULL)
|
||||
for (i = 0; i < num_rows; i++)
|
||||
{
|
||||
png_bytep rptr = *rp;
|
||||
png_read_row(png_ptr, rptr, NULL);
|
||||
rp++;
|
||||
if (display_row != NULL)
|
||||
}
|
||||
else if(dp != NULL)
|
||||
for (i = 0; i < num_rows; i++)
|
||||
{
|
||||
png_bytep dptr = *dp;
|
||||
png_read_row(png_ptr, NULL, dptr);
|
||||
dp++;
|
||||
}
|
||||
}
|
||||
|
||||
/* Read the entire image. If the image has an alpha channel or a tRNS
|
||||
* chunk, and you have called png_handle_alpha(), you will need to
|
||||
* chunk, and you have called png_handle_alpha()[*], you will need to
|
||||
* initialize the image to the current image that PNG will be overlaying.
|
||||
* We set the num_rows again here, in case it was incorrectly set in
|
||||
* png_read_start_row() by a call to png_read_update_info() or
|
||||
@@ -518,11 +578,13 @@ png_read_rows(png_structp png_ptr, png_bytepp row,
|
||||
* prior to either of these functions like it should have been. You can
|
||||
* only call this function once. If you desire to have an image for
|
||||
* each pass of a interlaced image, use png_read_rows() instead.
|
||||
*
|
||||
* [*] png_handle_alpha() does not exist yet, as of libpng version 1.0.3.
|
||||
*/
|
||||
void
|
||||
png_read_image(png_structp png_ptr, png_bytepp image)
|
||||
{
|
||||
png_uint_32 i;
|
||||
png_uint_32 i,image_height;
|
||||
int pass, j;
|
||||
png_bytepp rp;
|
||||
|
||||
@@ -530,12 +592,13 @@ png_read_image(png_structp png_ptr, png_bytepp image)
|
||||
/* save jump buffer and error functions */
|
||||
pass = png_set_interlace_handling(png_ptr);
|
||||
|
||||
png_ptr->num_rows = png_ptr->height; /* Make sure this is set correctly */
|
||||
image_height=png_ptr->height;
|
||||
png_ptr->num_rows = image_height; /* Make sure this is set correctly */
|
||||
|
||||
for (j = 0; j < pass; j++)
|
||||
{
|
||||
rp = image;
|
||||
for (i = 0; i < png_ptr->height; i++)
|
||||
for (i = 0; i < image_height; i++)
|
||||
{
|
||||
png_read_row(png_ptr, *rp, NULL);
|
||||
rp++;
|
||||
@@ -647,6 +710,9 @@ png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
|
||||
{
|
||||
png_structp png_ptr = NULL;
|
||||
png_infop info_ptr = NULL, end_info_ptr = NULL;
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
png_free_ptr free_fn = NULL;
|
||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||
|
||||
png_debug(1, "in png_destroy_read_struct\n");
|
||||
/* save jump buffer and error functions */
|
||||
@@ -659,6 +725,10 @@ png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
|
||||
if (end_info_ptr_ptr != NULL)
|
||||
end_info_ptr = *end_info_ptr_ptr;
|
||||
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
free_fn = png_ptr->free_fn;
|
||||
#endif
|
||||
|
||||
png_read_destroy(png_ptr, info_ptr, end_info_ptr);
|
||||
|
||||
if (info_ptr != NULL)
|
||||
@@ -666,7 +736,12 @@ png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
|
||||
#if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_READ_zTXt_SUPPORTED)
|
||||
png_free(png_ptr, info_ptr->text);
|
||||
#endif
|
||||
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
png_destroy_struct_2((png_voidp)info_ptr, free_fn);
|
||||
#else
|
||||
png_destroy_struct((png_voidp)info_ptr);
|
||||
#endif
|
||||
*info_ptr_ptr = (png_infop)NULL;
|
||||
}
|
||||
|
||||
@@ -675,13 +750,21 @@ png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
|
||||
#if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_READ_zTXt_SUPPORTED)
|
||||
png_free(png_ptr, end_info_ptr->text);
|
||||
#endif
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
png_destroy_struct_2((png_voidp)end_info_ptr, free_fn);
|
||||
#else
|
||||
png_destroy_struct((png_voidp)end_info_ptr);
|
||||
#endif
|
||||
*end_info_ptr_ptr = (png_infop)NULL;
|
||||
}
|
||||
|
||||
if (png_ptr != NULL)
|
||||
{
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
png_destroy_struct_2((png_voidp)png_ptr, free_fn);
|
||||
#else
|
||||
png_destroy_struct((png_voidp)png_ptr);
|
||||
#endif
|
||||
*png_ptr_ptr = (png_structp)NULL;
|
||||
}
|
||||
}
|
||||
@@ -694,6 +777,9 @@ png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr
|
||||
png_error_ptr error_fn;
|
||||
png_error_ptr warning_fn;
|
||||
png_voidp error_ptr;
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
png_free_ptr free_fn;
|
||||
#endif
|
||||
|
||||
png_debug(1, "in png_read_destroy\n");
|
||||
/* save jump buffer and error functions */
|
||||
@@ -729,33 +815,39 @@ png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr
|
||||
if (png_ptr->gamma_16_table != NULL)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < (1 << (8 - png_ptr->gamma_shift)); i++)
|
||||
int istop = (1 << (8 - png_ptr->gamma_shift));
|
||||
for (i = 0; i < istop; i++)
|
||||
{
|
||||
png_free(png_ptr, png_ptr->gamma_16_table[i]);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if defined(PNG_READ_BACKGROUND_SUPPORTED)
|
||||
png_free(png_ptr, png_ptr->gamma_16_table);
|
||||
}
|
||||
#if defined(PNG_READ_BACKGROUND_SUPPORTED)
|
||||
if (png_ptr->gamma_16_from_1 != NULL)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < (1 << (8 - png_ptr->gamma_shift)); i++)
|
||||
int istop = (1 << (8 - png_ptr->gamma_shift));
|
||||
for (i = 0; i < istop; i++)
|
||||
{
|
||||
png_free(png_ptr, png_ptr->gamma_16_from_1[i]);
|
||||
}
|
||||
}
|
||||
png_free(png_ptr, png_ptr->gamma_16_from_1);
|
||||
}
|
||||
if (png_ptr->gamma_16_to_1 != NULL)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < (1 << (8 - png_ptr->gamma_shift)); i++)
|
||||
int istop = (1 << (8 - png_ptr->gamma_shift));
|
||||
for (i = 0; i < istop; i++)
|
||||
{
|
||||
png_free(png_ptr, png_ptr->gamma_16_to_1[i]);
|
||||
}
|
||||
}
|
||||
png_free(png_ptr, png_ptr->gamma_16_to_1);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
#if defined(PNG_TIME_RFC1123_SUPPORTED)
|
||||
png_free(png_ptr, png_ptr->time_buffer);
|
||||
#endif /* PNG_TIME_RFC1123_SUPPORTED */
|
||||
|
||||
inflateEnd(&png_ptr->zstream);
|
||||
#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
|
||||
@@ -770,12 +862,18 @@ png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr
|
||||
error_fn = png_ptr->error_fn;
|
||||
warning_fn = png_ptr->warning_fn;
|
||||
error_ptr = png_ptr->error_ptr;
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
free_fn = png_ptr->free_fn;
|
||||
#endif
|
||||
|
||||
png_memset(png_ptr, 0, sizeof (png_struct));
|
||||
|
||||
png_ptr->error_fn = error_fn;
|
||||
png_ptr->warning_fn = warning_fn;
|
||||
png_ptr->error_ptr = error_ptr;
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
png_ptr->free_fn = free_fn;
|
||||
#endif
|
||||
|
||||
png_memcpy(png_ptr->jmpbuf, tmp_jmp, sizeof (jmp_buf));
|
||||
}
|
||||
|
@@ -1,23 +1,22 @@
|
||||
|
||||
/* pngrio.c - functions for data input
|
||||
*
|
||||
* libpng 1.0.1
|
||||
* libpng 1.0.3 - January 14, 1999
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* March 15, 1998
|
||||
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
||||
*
|
||||
* 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
|
||||
* This file provides a location for all input. Users who need
|
||||
* special handling are expected to write a function that has the same
|
||||
* arguments as this and performs a similar function, but that 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/png.h"
|
||||
#include "png.h"
|
||||
|
||||
/* Read the data from whatever input you are using. The default routine
|
||||
reads from a file pointer. Note that this routine sometimes gets called
|
||||
@@ -35,7 +34,7 @@ png_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
}
|
||||
|
||||
#if !defined(PNG_NO_STDIO)
|
||||
/* This is the function which does the actual reading of data. If you are
|
||||
/* This is the function that 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. */
|
||||
@@ -114,10 +113,10 @@ png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
png_ptr - pointer to a png input data structure
|
||||
io_ptr - pointer to user supplied structure containing info about
|
||||
the input functions. May be NULL.
|
||||
read_data_fn - pointer to a new input function which takes as it's
|
||||
read_data_fn - pointer to a new input function that takes as its
|
||||
arguments a pointer to a png_struct, a pointer to
|
||||
a location where input data can be stored, and a 32-bit
|
||||
unsigned int which is the number of bytes to be read.
|
||||
unsigned int that is the number of bytes to be read.
|
||||
To exit and output any fatal error messages the new write
|
||||
function should call png_error(png_ptr, "Error msg"). */
|
||||
void
|
||||
@@ -136,7 +135,14 @@ png_set_read_fn(png_structp png_ptr, png_voidp io_ptr,
|
||||
#endif
|
||||
|
||||
/* It is an error to write to a read device */
|
||||
if (png_ptr->write_data_fn != NULL)
|
||||
{
|
||||
png_ptr->write_data_fn = NULL;
|
||||
png_warning(png_ptr,
|
||||
"It's an error to set both read_data_fn and write_data_fn in the ");
|
||||
png_warning(png_ptr,
|
||||
"same structure. Resetting write_data_fn to NULL.");
|
||||
}
|
||||
|
||||
#if defined(PNG_WRITE_FLUSH_SUPPORTED)
|
||||
png_ptr->output_flush_fn = NULL;
|
||||
|
1336
src/png/pngrtran.c
1336
src/png/pngrtran.c
File diff suppressed because it is too large
Load Diff
@@ -1,28 +1,25 @@
|
||||
|
||||
/* pngrutil.c - utilities to read a PNG file
|
||||
*
|
||||
* libpng 1.0.1
|
||||
* libpng 1.0.3 - January 14, 1999
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* March 15, 1998
|
||||
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
||||
*
|
||||
* This file contains routines which are only called from within
|
||||
* This file contains routines that are only called from within
|
||||
* libpng itself during the course of reading an image.
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
#include "../png/png.h"
|
||||
#include "png.h"
|
||||
|
||||
#ifndef PNG_READ_BIG_ENDIAN_SUPPORTED
|
||||
/* Grab an unsigned 32-bit integer from a buffer in big endian format. */
|
||||
/* Grab an unsigned 32-bit integer from a buffer in big-endian format. */
|
||||
png_uint_32
|
||||
png_get_uint_32(png_bytep buf)
|
||||
{
|
||||
png_uint_32 i;
|
||||
|
||||
i = ((png_uint_32)(*buf) << 24) +
|
||||
png_uint_32 i = ((png_uint_32)(*buf) << 24) +
|
||||
((png_uint_32)(*(buf + 1)) << 16) +
|
||||
((png_uint_32)(*(buf + 2)) << 8) +
|
||||
(png_uint_32)(*(buf + 3));
|
||||
@@ -31,15 +28,13 @@ png_get_uint_32(png_bytep buf)
|
||||
}
|
||||
|
||||
#if defined(PNG_READ_pCAL_SUPPORTED)
|
||||
/* Grab a signed 32-bit integer from a buffer in big endian format. The
|
||||
/* Grab a signed 32-bit integer from a buffer in big-endian format. The
|
||||
* data is stored in the PNG file in two's complement format, and it is
|
||||
* assumed that the machine format for signed integers is the same. */
|
||||
png_int_32
|
||||
png_get_int_32(png_bytep buf)
|
||||
{
|
||||
png_int_32 i;
|
||||
|
||||
i = ((png_int_32)(*buf) << 24) +
|
||||
png_int_32 i = ((png_int_32)(*buf) << 24) +
|
||||
((png_int_32)(*(buf + 1)) << 16) +
|
||||
((png_int_32)(*(buf + 2)) << 8) +
|
||||
(png_int_32)(*(buf + 3));
|
||||
@@ -48,13 +43,11 @@ png_get_int_32(png_bytep buf)
|
||||
}
|
||||
#endif /* PNG_READ_pCAL_SUPPORTED */
|
||||
|
||||
/* Grab an unsigned 16-bit integer from a buffer in big endian format. */
|
||||
/* Grab an unsigned 16-bit integer from a buffer in big-endian format. */
|
||||
png_uint_16
|
||||
png_get_uint_16(png_bytep buf)
|
||||
{
|
||||
png_uint_16 i;
|
||||
|
||||
i = (png_uint_16)(((png_uint_16)(*buf) << 8) +
|
||||
png_uint_16 i = (png_uint_16)(((png_uint_16)(*buf) << 8) +
|
||||
(png_uint_16)(*(buf + 1)));
|
||||
|
||||
return (i);
|
||||
@@ -76,15 +69,16 @@ png_crc_read(png_structp png_ptr, png_bytep buf, png_size_t length)
|
||||
int
|
||||
png_crc_finish(png_structp png_ptr, png_uint_32 skip)
|
||||
{
|
||||
png_uint_32 i;
|
||||
png_size_t i;
|
||||
png_size_t istop = png_ptr->zbuf_size;
|
||||
|
||||
for (i = skip; i > (png_uint_32)png_ptr->zbuf_size; i -= png_ptr->zbuf_size)
|
||||
for (i = (png_size_t)skip; i > istop; i -= istop)
|
||||
{
|
||||
png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
|
||||
}
|
||||
if (i)
|
||||
{
|
||||
png_crc_read(png_ptr, png_ptr->zbuf, (png_size_t)i);
|
||||
png_crc_read(png_ptr, png_ptr->zbuf, i);
|
||||
}
|
||||
|
||||
if (png_crc_error(png_ptr))
|
||||
@@ -258,20 +252,6 @@ png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
|
||||
png_ptr->mode |= PNG_HAVE_PLTE;
|
||||
|
||||
#if defined (PNG_READ_tRNS_SUPPORTED)
|
||||
if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
|
||||
{
|
||||
if (info_ptr != NULL && info_ptr->valid & PNG_INFO_tRNS)
|
||||
{
|
||||
if (png_ptr->num_trans > png_ptr->num_palette)
|
||||
{
|
||||
png_warning(png_ptr, "Truncating incorrect tRNS chunk length");
|
||||
png_ptr->num_trans = png_ptr->num_palette;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
|
||||
if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
|
||||
{
|
||||
@@ -349,6 +329,21 @@ png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
png_ptr->palette = palette;
|
||||
png_ptr->num_palette = (png_uint_16)num;
|
||||
png_set_PLTE(png_ptr, info_ptr, palette, num);
|
||||
|
||||
#if defined (PNG_READ_tRNS_SUPPORTED)
|
||||
if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
|
||||
{
|
||||
if (info_ptr != NULL && info_ptr->valid & PNG_INFO_tRNS)
|
||||
{
|
||||
if (png_ptr->num_trans > png_ptr->num_palette)
|
||||
{
|
||||
png_warning(png_ptr, "Truncating incorrect tRNS chunk length");
|
||||
png_ptr->num_trans = png_ptr->num_palette;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
@@ -429,7 +424,7 @@ png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
{
|
||||
png_warning(png_ptr,
|
||||
"Ignoring incorrect gAMA value when sRGB is also present");
|
||||
#ifndef PNG_NO_STDIO
|
||||
#ifndef PNG_NO_CONSOLE_IO
|
||||
fprintf(stderr, "igamma = %lu\n", igamma);
|
||||
#endif
|
||||
return;
|
||||
@@ -501,6 +496,9 @@ png_handle_sBIT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
else
|
||||
{
|
||||
png_ptr->sig_bit.gray = buf[0];
|
||||
png_ptr->sig_bit.red = buf[0];
|
||||
png_ptr->sig_bit.green = buf[0];
|
||||
png_ptr->sig_bit.blue = buf[0];
|
||||
png_ptr->sig_bit.alpha = buf[1];
|
||||
}
|
||||
png_set_sBIT(png_ptr, info_ptr, &(png_ptr->sig_bit));
|
||||
@@ -629,7 +627,7 @@ png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
|
||||
png_warning(png_ptr,
|
||||
"Ignoring incorrect cHRM value when sRGB is also present");
|
||||
#ifndef PNG_NO_STDIO
|
||||
#ifndef PNG_NO_CONSOLE_IO
|
||||
fprintf(stderr,"wx=%f, wy=%f, rx=%f, ry=%f\n",
|
||||
white_x, white_y, red_x, red_y);
|
||||
fprintf(stderr,"gx=%f, gy=%f, bx=%f, by=%f\n",
|
||||
@@ -698,7 +696,7 @@ png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
{
|
||||
png_warning(png_ptr,
|
||||
"Ignoring incorrect gAMA value when sRGB is also present");
|
||||
#ifndef PNG_NO_STDIO
|
||||
#ifndef PNG_NO_CONSOLE_IO
|
||||
fprintf(stderr,"gamma=%f\n",png_ptr->gamma);
|
||||
#endif
|
||||
}
|
||||
@@ -758,6 +756,12 @@ png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
png_crc_finish(png_ptr, length);
|
||||
return;
|
||||
}
|
||||
if (length == 0)
|
||||
{
|
||||
png_warning(png_ptr, "Zero length tRNS chunk");
|
||||
png_crc_finish(png_ptr, length);
|
||||
return;
|
||||
}
|
||||
|
||||
png_ptr->trans = (png_bytep)png_malloc(png_ptr, length);
|
||||
png_ptr->flags |= PNG_FLAG_FREE_TRANS;
|
||||
@@ -1075,7 +1079,7 @@ png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
purpose[slength] = 0x00; /* null terminate the last string */
|
||||
|
||||
png_debug(3, "Finding end of pCAL purpose string\n");
|
||||
for (buf = purpose; *buf != '\0'; buf++)
|
||||
for (buf = purpose; *buf; buf++)
|
||||
/* empty loop */ ;
|
||||
|
||||
endptr = purpose + slength;
|
||||
@@ -1113,7 +1117,7 @@ png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
png_warning(png_ptr, "Unrecognized equation type for pCAL chunk");
|
||||
}
|
||||
|
||||
for (buf = units; *buf != 0x00; buf++)
|
||||
for (buf = units; *buf; buf++)
|
||||
/* Empty loop to move past the units string. */ ;
|
||||
|
||||
png_debug(3, "Allocating pCAL parameters array\n");
|
||||
@@ -1465,13 +1469,13 @@ png_check_chunk_name(png_structp png_ptr, png_bytep chunk_name)
|
||||
}
|
||||
}
|
||||
|
||||
/* Combines the row recently read in with the previous row.
|
||||
This routine takes care of alpha and transparency if requested.
|
||||
/* Combines the row recently read in with the existing pixels in the
|
||||
row. This routine takes care of alpha and transparency if requested.
|
||||
This routine also handles the two methods of progressive display
|
||||
of interlaced images, depending on the mask value.
|
||||
The mask value describes which pixels are to be combined with
|
||||
the row. The pattern always repeats every 8 pixels, so just 8
|
||||
bits are needed. A one indicates the pixels is to be combined,
|
||||
bits are needed. A one indicates the pixel is to be combined,
|
||||
a zero indicates the pixel is to be skipped. This is in addition
|
||||
to any alpha or transparency value associated with the pixel. If
|
||||
you want all pixels to be combined, pass 0xff (255) in mask. */
|
||||
@@ -1492,16 +1496,14 @@ png_combine_row(png_structp png_ptr, png_bytep row,
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
png_bytep sp;
|
||||
png_bytep dp;
|
||||
png_bytep sp = png_ptr->row_buf + 1;
|
||||
png_bytep dp = row;
|
||||
int s_inc, s_start, s_end;
|
||||
int m;
|
||||
int m = 0x80;
|
||||
int shift;
|
||||
png_uint_32 i;
|
||||
png_uint_32 row_width = png_ptr->width;
|
||||
|
||||
sp = png_ptr->row_buf + 1;
|
||||
dp = row;
|
||||
m = 0x80;
|
||||
#if defined(PNG_READ_PACKSWAP_SUPPORTED)
|
||||
if (png_ptr->transformations & PNG_PACKSWAP)
|
||||
{
|
||||
@@ -1519,7 +1521,7 @@ png_combine_row(png_structp png_ptr, png_bytep row,
|
||||
|
||||
shift = s_start;
|
||||
|
||||
for (i = 0; i < png_ptr->width; i++)
|
||||
for (i = 0; i < row_width; i++)
|
||||
{
|
||||
if (m & mask)
|
||||
{
|
||||
@@ -1548,17 +1550,15 @@ png_combine_row(png_structp png_ptr, png_bytep row,
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
png_bytep sp;
|
||||
png_bytep dp;
|
||||
png_bytep sp = png_ptr->row_buf + 1;
|
||||
png_bytep dp = row;
|
||||
int s_start, s_end, s_inc;
|
||||
int m;
|
||||
int m = 0x80;
|
||||
int shift;
|
||||
png_uint_32 i;
|
||||
png_uint_32 row_width = png_ptr->width;
|
||||
int value;
|
||||
|
||||
sp = png_ptr->row_buf + 1;
|
||||
dp = row;
|
||||
m = 0x80;
|
||||
#if defined(PNG_READ_PACKSWAP_SUPPORTED)
|
||||
if (png_ptr->transformations & PNG_PACKSWAP)
|
||||
{
|
||||
@@ -1576,7 +1576,7 @@ png_combine_row(png_structp png_ptr, png_bytep row,
|
||||
|
||||
shift = s_start;
|
||||
|
||||
for (i = 0; i < png_ptr->width; i++)
|
||||
for (i = 0; i < row_width; i++)
|
||||
{
|
||||
if (m & mask)
|
||||
{
|
||||
@@ -1602,17 +1602,15 @@ png_combine_row(png_structp png_ptr, png_bytep row,
|
||||
}
|
||||
case 4:
|
||||
{
|
||||
png_bytep sp;
|
||||
png_bytep dp;
|
||||
png_bytep sp = png_ptr->row_buf + 1;
|
||||
png_bytep dp = row;
|
||||
int s_start, s_end, s_inc;
|
||||
int m;
|
||||
int m = 0x80;
|
||||
int shift;
|
||||
png_uint_32 i;
|
||||
png_uint_32 row_width = png_ptr->width;
|
||||
int value;
|
||||
|
||||
sp = png_ptr->row_buf + 1;
|
||||
dp = row;
|
||||
m = 0x80;
|
||||
#if defined(PNG_READ_PACKSWAP_SUPPORTED)
|
||||
if (png_ptr->transformations & PNG_PACKSWAP)
|
||||
{
|
||||
@@ -1629,7 +1627,7 @@ png_combine_row(png_structp png_ptr, png_bytep row,
|
||||
}
|
||||
shift = s_start;
|
||||
|
||||
for (i = 0; i < png_ptr->width; i++)
|
||||
for (i = 0; i < row_width; i++)
|
||||
{
|
||||
if (m & mask)
|
||||
{
|
||||
@@ -1655,18 +1653,15 @@ png_combine_row(png_structp png_ptr, png_bytep row,
|
||||
}
|
||||
default:
|
||||
{
|
||||
png_bytep sp;
|
||||
png_bytep dp;
|
||||
png_size_t pixel_bytes;
|
||||
png_bytep sp = png_ptr->row_buf + 1;
|
||||
png_bytep dp = row;
|
||||
png_size_t pixel_bytes = (png_ptr->row_info.pixel_depth >> 3);
|
||||
png_uint_32 i;
|
||||
png_byte m;
|
||||
png_uint_32 row_width = png_ptr->width;
|
||||
png_byte m = 0x80;
|
||||
|
||||
pixel_bytes = (png_ptr->row_info.pixel_depth >> 3);
|
||||
|
||||
sp = png_ptr->row_buf + 1;
|
||||
dp = row;
|
||||
m = 0x80;
|
||||
for (i = 0; i < png_ptr->width; i++)
|
||||
for (i = 0; i < row_width; i++)
|
||||
{
|
||||
if (m & mask)
|
||||
{
|
||||
@@ -1703,15 +1698,15 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
png_bytep sp, dp;
|
||||
png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 3);
|
||||
png_bytep dp = row + (png_size_t)((final_width - 1) >> 3);
|
||||
int sshift, dshift;
|
||||
int s_start, s_end, s_inc;
|
||||
int jstop = png_pass_inc[pass];
|
||||
png_byte v;
|
||||
png_uint_32 i;
|
||||
int j;
|
||||
|
||||
sp = row + (png_size_t)((row_info->width - 1) >> 3);
|
||||
dp = row + (png_size_t)((final_width - 1) >> 3);
|
||||
#if defined(PNG_READ_PACKSWAP_SUPPORTED)
|
||||
if (transformations & PNG_PACKSWAP)
|
||||
{
|
||||
@@ -1731,10 +1726,10 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
|
||||
s_inc = 1;
|
||||
}
|
||||
|
||||
for (i = row_info->width; i; i--)
|
||||
for (i = 0; i < row_info->width; i++)
|
||||
{
|
||||
v = (png_byte)((*sp >> sshift) & 0x1);
|
||||
for (j = 0; j < png_pass_inc[pass]; j++)
|
||||
for (j = 0; j < jstop; j++)
|
||||
{
|
||||
*dp &= (png_byte)((0x7f7f >> (7 - dshift)) & 0xff);
|
||||
*dp |= (png_byte)(v << dshift);
|
||||
@@ -1758,13 +1753,13 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
png_bytep sp, dp;
|
||||
png_bytep sp = row + (png_uint_32)((row_info->width - 1) >> 2);
|
||||
png_bytep dp = row + (png_uint_32)((final_width - 1) >> 2);
|
||||
int sshift, dshift;
|
||||
int s_start, s_end, s_inc;
|
||||
int jstop = png_pass_inc[pass];
|
||||
png_uint_32 i;
|
||||
|
||||
sp = row + (png_uint_32)((row_info->width - 1) >> 2);
|
||||
dp = row + (png_uint_32)((final_width - 1) >> 2);
|
||||
#if defined(PNG_READ_PACKSWAP_SUPPORTED)
|
||||
if (transformations & PNG_PACKSWAP)
|
||||
{
|
||||
@@ -1784,13 +1779,13 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
|
||||
s_inc = 2;
|
||||
}
|
||||
|
||||
for (i = row_info->width; i; i--)
|
||||
for (i = 0; i < row_info->width; i++)
|
||||
{
|
||||
png_byte v;
|
||||
int j;
|
||||
|
||||
v = (png_byte)((*sp >> sshift) & 0x3);
|
||||
for (j = 0; j < png_pass_inc[pass]; j++)
|
||||
for (j = 0; j < jstop; j++)
|
||||
{
|
||||
*dp &= (png_byte)((0x3f3f >> (6 - dshift)) & 0xff);
|
||||
*dp |= (png_byte)(v << dshift);
|
||||
@@ -1814,13 +1809,13 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
|
||||
}
|
||||
case 4:
|
||||
{
|
||||
png_bytep sp, dp;
|
||||
png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 1);
|
||||
png_bytep dp = row + (png_size_t)((final_width - 1) >> 1);
|
||||
int sshift, dshift;
|
||||
int s_start, s_end, s_inc;
|
||||
png_uint_32 i;
|
||||
int jstop = png_pass_inc[pass];
|
||||
|
||||
sp = row + (png_size_t)((row_info->width - 1) >> 1);
|
||||
dp = row + (png_size_t)((final_width - 1) >> 1);
|
||||
#if defined(PNG_READ_PACKSWAP_SUPPORTED)
|
||||
if (transformations & PNG_PACKSWAP)
|
||||
{
|
||||
@@ -1840,13 +1835,12 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
|
||||
s_inc = 4;
|
||||
}
|
||||
|
||||
for (i = row_info->width; i; i--)
|
||||
for (i = 0; i < row_info->width; i++)
|
||||
{
|
||||
png_byte v;
|
||||
png_byte v = (png_byte)((*sp >> sshift) & 0xf);
|
||||
int j;
|
||||
|
||||
v = (png_byte)((*sp >> sshift) & 0xf);
|
||||
for (j = 0; j < png_pass_inc[pass]; j++)
|
||||
for (j = 0; j < jstop; j++)
|
||||
{
|
||||
*dp &= (png_byte)((0xf0f >> (4 - dshift)) & 0xff);
|
||||
*dp |= (png_byte)(v << dshift);
|
||||
@@ -1870,21 +1864,19 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
|
||||
}
|
||||
default:
|
||||
{
|
||||
png_bytep sp, dp;
|
||||
png_size_t pixel_bytes = (row_info->pixel_depth >> 3);
|
||||
png_bytep sp = row + (png_size_t)(row_info->width - 1) * pixel_bytes;
|
||||
png_bytep dp = row + (png_size_t)(final_width - 1) * pixel_bytes;
|
||||
int jstop = png_pass_inc[pass];
|
||||
png_uint_32 i;
|
||||
png_size_t pixel_bytes;
|
||||
|
||||
pixel_bytes = (row_info->pixel_depth >> 3);
|
||||
|
||||
sp = row + (png_size_t)(row_info->width - 1) * pixel_bytes;
|
||||
dp = row + (png_size_t)(final_width - 1) * pixel_bytes;
|
||||
for (i = row_info->width; i; i--)
|
||||
for (i = 0; i < row_info->width; i++)
|
||||
{
|
||||
png_byte v[8];
|
||||
int j;
|
||||
|
||||
png_memcpy(v, sp, pixel_bytes);
|
||||
for (j = 0; j < png_pass_inc[pass]; j++)
|
||||
for (j = 0; j < jstop; j++)
|
||||
{
|
||||
png_memcpy(dp, v, pixel_bytes);
|
||||
dp -= pixel_bytes;
|
||||
@@ -1916,97 +1908,112 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row,
|
||||
case PNG_FILTER_VALUE_SUB:
|
||||
{
|
||||
png_uint_32 i;
|
||||
int bpp;
|
||||
png_bytep rp;
|
||||
png_bytep lp;
|
||||
png_uint_32 istop = row_info->rowbytes;
|
||||
png_uint_32 bpp = (row_info->pixel_depth + 7) / 8;
|
||||
png_bytep rp = row + bpp;
|
||||
png_bytep lp = row;
|
||||
|
||||
bpp = (row_info->pixel_depth + 7) / 8;
|
||||
for (i = (png_uint_32)bpp, rp = row + bpp, lp = row;
|
||||
i < row_info->rowbytes; i++, rp++, lp++)
|
||||
for (i = bpp; i < istop; i++)
|
||||
{
|
||||
*rp = (png_byte)(((int)(*rp) + (int)(*lp)) & 0xff);
|
||||
*rp = (png_byte)(((int)(*rp) + (int)(*lp++)) & 0xff);
|
||||
rp++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PNG_FILTER_VALUE_UP:
|
||||
{
|
||||
png_uint_32 i;
|
||||
png_bytep rp;
|
||||
png_bytep pp;
|
||||
png_uint_32 istop = row_info->rowbytes;
|
||||
png_bytep rp = row;
|
||||
png_bytep pp = prev_row;
|
||||
|
||||
for (i = 0, rp = row, pp = prev_row;
|
||||
i < row_info->rowbytes; i++, rp++, pp++)
|
||||
for (i = 0; i < istop; i++)
|
||||
{
|
||||
*rp = (png_byte)(((int)(*rp) + (int)(*pp)) & 0xff);
|
||||
*rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
|
||||
rp++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PNG_FILTER_VALUE_AVG:
|
||||
{
|
||||
png_uint_32 i;
|
||||
int bpp;
|
||||
png_bytep rp;
|
||||
png_bytep pp;
|
||||
png_bytep lp;
|
||||
png_bytep rp = row;
|
||||
png_bytep pp = prev_row;
|
||||
png_bytep lp = row;
|
||||
png_uint_32 bpp = (row_info->pixel_depth + 7) / 8;
|
||||
png_uint_32 istop = row_info->rowbytes - bpp;
|
||||
|
||||
bpp = (row_info->pixel_depth + 7) / 8;
|
||||
for (i = 0, rp = row, pp = prev_row;
|
||||
i < (png_uint_32)bpp; i++, rp++, pp++)
|
||||
for (i = 0; i < bpp; i++)
|
||||
{
|
||||
*rp = (png_byte)(((int)(*rp) +
|
||||
((int)(*pp) / 2)) & 0xff);
|
||||
((int)(*pp++) / 2)) & 0xff);
|
||||
rp++;
|
||||
}
|
||||
for (lp = row; i < row_info->rowbytes; i++, rp++, lp++, pp++)
|
||||
|
||||
for (i = 0; i < istop; i++)
|
||||
{
|
||||
*rp = (png_byte)(((int)(*rp) +
|
||||
(int)(*pp + *lp) / 2) & 0xff);
|
||||
(int)(*pp++ + *lp++) / 2) & 0xff);
|
||||
rp++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PNG_FILTER_VALUE_PAETH:
|
||||
{
|
||||
int bpp;
|
||||
png_uint_32 i;
|
||||
png_bytep rp;
|
||||
png_bytep pp;
|
||||
png_bytep lp;
|
||||
png_bytep cp;
|
||||
png_bytep rp = row;
|
||||
png_bytep pp = prev_row;
|
||||
png_bytep lp = row;
|
||||
png_bytep cp = prev_row;
|
||||
png_uint_32 bpp = (row_info->pixel_depth + 7) / 8;
|
||||
png_uint_32 istop=row_info->rowbytes - bpp;
|
||||
|
||||
bpp = (row_info->pixel_depth + 7) / 8;
|
||||
for (i = 0, rp = row, pp = prev_row,
|
||||
lp = row - bpp, cp = prev_row - bpp;
|
||||
i < row_info->rowbytes; i++, rp++, pp++, lp++, cp++)
|
||||
for (i = 0; i < bpp; i++)
|
||||
{
|
||||
*rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
|
||||
rp++;
|
||||
}
|
||||
|
||||
for (i = 0; i < istop; i++) /* use leftover rp,pp */
|
||||
{
|
||||
int a, b, c, pa, pb, pc, p;
|
||||
|
||||
b = *pp;
|
||||
if (i >= (png_uint_32)bpp)
|
||||
{
|
||||
c = *cp;
|
||||
a = *lp;
|
||||
}
|
||||
else
|
||||
{
|
||||
a = c = 0;
|
||||
}
|
||||
p = a + b - c;
|
||||
pa = abs(p - a);
|
||||
pb = abs(p - b);
|
||||
pc = abs(p - c);
|
||||
a = *lp++;
|
||||
b = *pp++;
|
||||
c = *cp++;
|
||||
|
||||
p = b - c;
|
||||
pc = a - c;
|
||||
|
||||
#ifdef PNG_USE_ABS
|
||||
pa = abs(p);
|
||||
pb = abs(pc);
|
||||
pc = abs(p + pc);
|
||||
#else
|
||||
pa = p < 0 ? -p : p;
|
||||
pb = pc < 0 ? -pc : pc;
|
||||
pc = (p + pc) < 0 ? -(p + pc) : p + pc;
|
||||
#endif
|
||||
|
||||
/*
|
||||
if (pa <= pb && pa <= pc)
|
||||
p = a;
|
||||
else if (pb <= pc)
|
||||
p = b;
|
||||
else
|
||||
p = c;
|
||||
*/
|
||||
|
||||
p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
|
||||
|
||||
*rp = (png_byte)(((int)(*rp) + p) & 0xff);
|
||||
rp++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
png_error(png_ptr, "Bad adaptive filter type");
|
||||
png_warning(png_ptr, "Ignoring bad adaptive filter type");
|
||||
*row=0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -2044,7 +2051,7 @@ png_read_finish_row(png_structp png_ptr)
|
||||
if (!(png_ptr->num_rows))
|
||||
continue;
|
||||
}
|
||||
if (png_ptr->transformations & PNG_INTERLACE)
|
||||
else /* if (png_ptr->transformations & PNG_INTERLACE) */
|
||||
break;
|
||||
} while (png_ptr->iwidth == 0);
|
||||
|
||||
@@ -2118,7 +2125,7 @@ void
|
||||
png_read_start_row(png_structp png_ptr)
|
||||
{
|
||||
int max_pixel_depth;
|
||||
png_uint_32 rowbytes;
|
||||
png_uint_32 row_bytes;
|
||||
|
||||
png_debug(1, "in png_read_start_row\n");
|
||||
png_ptr->zstream.avail_in = 0;
|
||||
@@ -2136,10 +2143,10 @@ png_read_start_row(png_structp png_ptr)
|
||||
png_pass_start[png_ptr->pass]) /
|
||||
png_pass_inc[png_ptr->pass];
|
||||
|
||||
rowbytes = ((png_ptr->iwidth *
|
||||
row_bytes = ((png_ptr->iwidth *
|
||||
(png_uint_32)png_ptr->pixel_depth + 7) >> 3) +1;
|
||||
png_ptr->irowbytes = (png_size_t)rowbytes;
|
||||
if((png_uint_32)png_ptr->irowbytes != rowbytes)
|
||||
png_ptr->irowbytes = (png_size_t)row_bytes;
|
||||
if((png_uint_32)png_ptr->irowbytes != row_bytes)
|
||||
png_error(png_ptr, "Rowbytes overflow in png_read_start_row");
|
||||
}
|
||||
else
|
||||
@@ -2186,27 +2193,47 @@ png_read_start_row(png_structp png_ptr)
|
||||
#if defined(PNG_READ_FILLER_SUPPORTED)
|
||||
if (png_ptr->transformations & (PNG_FILLER))
|
||||
{
|
||||
if (max_pixel_depth < 32)
|
||||
if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
|
||||
max_pixel_depth = 32;
|
||||
else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
|
||||
{
|
||||
if (max_pixel_depth <= 8)
|
||||
max_pixel_depth = 16;
|
||||
else
|
||||
max_pixel_depth = 32;
|
||||
}
|
||||
else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
|
||||
{
|
||||
if (max_pixel_depth <= 32)
|
||||
max_pixel_depth = 32;
|
||||
else
|
||||
max_pixel_depth = 64;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
|
||||
if (png_ptr->transformations & PNG_GRAY_TO_RGB)
|
||||
{
|
||||
if ((png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND)) ||
|
||||
if (
|
||||
#if defined(PNG_READ_EXPAND_SUPPORTED)
|
||||
(png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND)) ||
|
||||
#endif
|
||||
#if defined(PNG_READ_FILLER_SUPPORTED)
|
||||
(png_ptr->transformations & (PNG_FILLER)) ||
|
||||
#endif
|
||||
png_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
|
||||
{
|
||||
if (max_pixel_depth <= 16)
|
||||
max_pixel_depth = 32;
|
||||
else if (max_pixel_depth <= 32)
|
||||
else
|
||||
max_pixel_depth = 64;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (max_pixel_depth <= 8)
|
||||
max_pixel_depth = 24;
|
||||
else if (max_pixel_depth <= 16)
|
||||
else
|
||||
max_pixel_depth = 48;
|
||||
}
|
||||
}
|
||||
@@ -2214,16 +2241,16 @@ png_read_start_row(png_structp png_ptr)
|
||||
|
||||
/* align the width on the next larger 8 pixels. Mainly used
|
||||
for interlacing */
|
||||
rowbytes = ((png_ptr->width + 7) & ~((png_uint_32)7));
|
||||
row_bytes = ((png_ptr->width + 7) & ~((png_uint_32)7));
|
||||
/* calculate the maximum bytes needed, adding a byte and a pixel
|
||||
for safety sake */
|
||||
rowbytes = ((rowbytes * (png_uint_32)max_pixel_depth + 7) >> 3) +
|
||||
for safety's sake */
|
||||
row_bytes = ((row_bytes * (png_uint_32)max_pixel_depth + 7) >> 3) +
|
||||
1 + ((max_pixel_depth + 7) >> 3);
|
||||
#ifdef PNG_MAX_MALLOC_64K
|
||||
if (rowbytes > (png_uint_32)65536L)
|
||||
if (row_bytes > (png_uint_32)65536L)
|
||||
png_error(png_ptr, "This image requires a row greater than 64KB");
|
||||
#endif
|
||||
png_ptr->row_buf = (png_bytep)png_malloc(png_ptr, rowbytes);
|
||||
png_ptr->row_buf = (png_bytep)png_malloc(png_ptr, row_bytes);
|
||||
|
||||
#ifdef PNG_MAX_MALLOC_64K
|
||||
if ((png_uint_32)png_ptr->rowbytes + 1 > (png_uint_32)65536L)
|
||||
|
@@ -1,12 +1,11 @@
|
||||
|
||||
/* pngset.c - storage of image information into info struct
|
||||
*
|
||||
* libpng 1.0.1
|
||||
* libpng 1.0.3 - January 14, 1999
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* March 15, 1998
|
||||
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
||||
*
|
||||
* The functions here are used during reads to store data from the file
|
||||
* into the info struct, and during writes to store application data
|
||||
@@ -15,7 +14,7 @@
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
#include "../png/png.h"
|
||||
#include "png.h"
|
||||
|
||||
#if defined(PNG_READ_bKGD_SUPPORTED) || defined(PNG_WRITE_bKGD_SUPPORTED)
|
||||
void
|
||||
@@ -108,13 +107,14 @@ png_set_IHDR(png_structp png_ptr, png_infop info_ptr,
|
||||
|
||||
/* check for overflow */
|
||||
rowbytes_per_pixel = (info_ptr->pixel_depth + 7) >> 3;
|
||||
info_ptr->rowbytes = info_ptr->width * rowbytes_per_pixel;
|
||||
if (( width > (png_uint_32)2147483647L/rowbytes_per_pixel))
|
||||
{
|
||||
png_warning(png_ptr,
|
||||
"Width too large to process image data; rowbytes will overflow.");
|
||||
info_ptr->rowbytes = (png_size_t)0;
|
||||
}
|
||||
else
|
||||
info_ptr->rowbytes = (info_ptr->width * info_ptr->pixel_depth + 7) >> 3;
|
||||
}
|
||||
|
||||
#if defined(PNG_READ_oFFs_SUPPORTED) || defined(PNG_WRITE_oFFs_SUPPORTED)
|
||||
|
@@ -1,12 +1,11 @@
|
||||
|
||||
/* pngtest.c - a simple test program to test libpng
|
||||
*
|
||||
* libpng 1.0.1
|
||||
* libpng 1.0.3 -January 14, 1999
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* March 15, 1998
|
||||
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
||||
*
|
||||
* 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
|
||||
@@ -14,9 +13,9 @@
|
||||
* properly. It does not currently test all of the transforms, although
|
||||
* it probably should.
|
||||
*
|
||||
* The program will fail in certain legitimate cases:
|
||||
* The program will report "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.
|
||||
* 2) when the chunk size is not 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"
|
||||
@@ -24,7 +23,8 @@
|
||||
*
|
||||
* 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.
|
||||
* testing a wide variety of files easily. You can also test a number
|
||||
* of files at once by typing "pngtest -m file1.png file2.png ..."
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
@@ -35,7 +35,12 @@
|
||||
#define PNG_DEBUG 0
|
||||
#endif
|
||||
|
||||
#include "../png/png.h"
|
||||
#include "png.h"
|
||||
|
||||
#if defined(PNG_TIME_RFC1123_SUPPORTED)
|
||||
static int tIME_chunk_present=0;
|
||||
static char tIME_string[30] = "no tIME chunk present in file";
|
||||
#endif /* PNG_TIME_RFC1123_SUPPORTED */
|
||||
|
||||
int test_one_file PNGARG((PNG_CONST char *inname, PNG_CONST char *outname));
|
||||
|
||||
@@ -81,12 +86,12 @@ write_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass)
|
||||
|
||||
#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
|
||||
/* example of using user transform callback (we don't transform anything,
|
||||
but merely count the black pixels) */
|
||||
but merely count the zero samples) */
|
||||
|
||||
static png_uint_32 black_pixels;
|
||||
static png_uint_32 zero_samples;
|
||||
|
||||
void
|
||||
count_black_pixels(png_structp png_ptr, png_row_infop row_info, png_bytep data)
|
||||
count_zero_samples(png_structp png_ptr, png_row_infop row_info, png_bytep data)
|
||||
{
|
||||
png_bytep dp = data;
|
||||
if(png_ptr == NULL)return;
|
||||
@@ -100,60 +105,66 @@ count_black_pixels(png_structp png_ptr, png_row_infop row_info, png_bytep data)
|
||||
* png_byte pixel_depth bits per pixel (depth*channels)
|
||||
*/
|
||||
|
||||
/* counts the number of black pixels (or zero pixels if color_type is 3 */
|
||||
/* counts the number of zero samples (or zero pixels if color_type is 3 */
|
||||
|
||||
if(row_info->color_type == 0 || row_info->color_type == 3)
|
||||
{
|
||||
int pos=0;
|
||||
png_uint_32 n;
|
||||
for (n=0; n<row_info->width; n++)
|
||||
png_uint_32 n, nstop;
|
||||
for (n=0, nstop=row_info->width; n<nstop; n++)
|
||||
{
|
||||
if(row_info->bit_depth == 1)
|
||||
if(((*dp << pos++ )& 0x80) == 0) black_pixels++;
|
||||
{
|
||||
if(((*dp << pos++ )& 0x80) == 0) zero_samples++;
|
||||
if(pos == 8)
|
||||
{
|
||||
pos = 0;
|
||||
dp++;
|
||||
}
|
||||
}
|
||||
if(row_info->bit_depth == 2)
|
||||
if(((*dp << (pos+=2))& 0xc0) == 0) black_pixels++;
|
||||
{
|
||||
if(((*dp << (pos+=2))& 0xc0) == 0) zero_samples++;
|
||||
if(pos == 8)
|
||||
{
|
||||
pos = 0;
|
||||
dp++;
|
||||
}
|
||||
}
|
||||
if(row_info->bit_depth == 4)
|
||||
if(((*dp << (pos+=4))& 0xf0) == 0) black_pixels++;
|
||||
{
|
||||
if(((*dp << (pos+=4))& 0xf0) == 0) zero_samples++;
|
||||
if(pos == 8)
|
||||
{
|
||||
pos = 0;
|
||||
dp++;
|
||||
}
|
||||
}
|
||||
if(row_info->bit_depth == 8)
|
||||
if(*dp++ == 0) black_pixels++;
|
||||
if(*dp++ == 0) zero_samples++;
|
||||
if(row_info->bit_depth == 16)
|
||||
{
|
||||
if((*dp | *(dp+1)) == 0) black_pixels++;
|
||||
if((*dp | *(dp+1)) == 0) zero_samples++;
|
||||
dp+=2;
|
||||
}
|
||||
}
|
||||
}
|
||||
else /* other color types */
|
||||
{
|
||||
png_uint_32 n;
|
||||
png_uint_32 n, nstop;
|
||||
int channel;
|
||||
int color_channels = row_info->channels;
|
||||
if(row_info->color_type > 3)color_channels--;
|
||||
|
||||
for (n=0; n<row_info->width; n++)
|
||||
for (n=0, nstop=row_info->width; n<nstop; n++)
|
||||
{
|
||||
for (channel = 0; channel < color_channels; channel++)
|
||||
{
|
||||
if(row_info->bit_depth == 8)
|
||||
if(*dp++ == 0) black_pixels++;
|
||||
if(*dp++ == 0) zero_samples++;
|
||||
if(row_info->bit_depth == 16)
|
||||
{
|
||||
if((*dp | *(dp+1)) == 0) black_pixels++;
|
||||
if((*dp | *(dp+1)) == 0) zero_samples++;
|
||||
dp+=2;
|
||||
}
|
||||
}
|
||||
@@ -174,7 +185,7 @@ static int wrote_question = 0;
|
||||
/* 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. */
|
||||
/* This is the function which does the actual reading of data. If you are
|
||||
/* This is the function that 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. */
|
||||
@@ -256,7 +267,7 @@ png_default_flush(png_structp png_ptr)
|
||||
}
|
||||
#endif
|
||||
|
||||
/* This is the function which does the actual writing of data. If you are
|
||||
/* This is the function that 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. */
|
||||
@@ -346,18 +357,14 @@ 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. */
|
||||
/* We can return because png_error calls the default handler, which is
|
||||
* actually OK in this case. */
|
||||
}
|
||||
#endif /* PNG_NO_STDIO */
|
||||
/* END of code to validate stdio-free compilation */
|
||||
|
||||
/* START of code to validate memory allocation and deallocation */
|
||||
#ifdef PNGTEST_MEMORY_DEBUG
|
||||
/* Borland DOS special memory handler */
|
||||
#if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
|
||||
ERROR - memory debugging is not supported on this platform
|
||||
#else
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
|
||||
/* Allocate memory. For reasonable files, size should never exceed
|
||||
64K. However, zlib may allocate more then 64K if you don't tell
|
||||
@@ -384,23 +391,23 @@ extern PNG_EXPORT(void,png_debug_free) PNGARG((png_structp png_ptr,
|
||||
png_voidp ptr));
|
||||
|
||||
png_voidp
|
||||
png_malloc(png_structp png_ptr, png_uint_32 size) {
|
||||
if (png_ptr == NULL) {
|
||||
fprintf(STDERR, "NULL pointer to memory allocator\n");
|
||||
return (NULL);
|
||||
}
|
||||
png_debug_malloc(png_structp png_ptr, png_uint_32 size) {
|
||||
|
||||
/* png_malloc has already tested for NULL; png_create_struct calls
|
||||
png_debug_malloc directly, with png_ptr == NULL which is OK */
|
||||
|
||||
if (size == 0)
|
||||
return (png_voidp)(NULL);
|
||||
|
||||
/* This calls the library allocator twice, once to get the requested
|
||||
buffer and once to get a new free list entry. */
|
||||
{
|
||||
memory_infop pinfo = png_debug_malloc(png_ptr, sizeof *pinfo);
|
||||
memory_infop pinfo = png_malloc_default(png_ptr, sizeof *pinfo);
|
||||
pinfo->size = size;
|
||||
current_allocation += size;
|
||||
if (current_allocation > maximum_allocation)
|
||||
maximum_allocation = current_allocation;
|
||||
pinfo->pointer = png_debug_malloc(png_ptr, size);
|
||||
pinfo->pointer = png_malloc_default(png_ptr, size);
|
||||
pinfo->next = pinformation;
|
||||
pinformation = pinfo;
|
||||
/* Make sure the caller isn't assuming zeroed memory. */
|
||||
@@ -411,10 +418,10 @@ png_malloc(png_structp png_ptr, png_uint_32 size) {
|
||||
|
||||
/* Free a pointer. It is removed from the list at the same time. */
|
||||
void
|
||||
png_free(png_structp png_ptr, png_voidp ptr)
|
||||
png_debug_free(png_structp png_ptr, png_voidp ptr)
|
||||
{
|
||||
if (png_ptr == NULL)
|
||||
fprintf(STDERR, "NULL pointer to memory allocator\n");
|
||||
fprintf(STDERR, "NULL pointer to png_debug_free.\n");
|
||||
if (ptr == 0) {
|
||||
#if 0 /* This happens all the time. */
|
||||
fprintf(STDERR, "WARNING: freeing NULL pointer\n");
|
||||
@@ -433,9 +440,9 @@ png_free(png_structp png_ptr, png_voidp ptr)
|
||||
if (current_allocation < 0)
|
||||
fprintf(STDERR, "Duplicate free of memory\n");
|
||||
/* We must free the list element too, but first kill
|
||||
the memory which is to be freed. */
|
||||
the memory that is to be freed. */
|
||||
memset(ptr, 0x55, pinfo->size);
|
||||
png_debug_free(png_ptr, pinfo);
|
||||
png_free_default(png_ptr, pinfo);
|
||||
break;
|
||||
}
|
||||
if (pinfo->next == NULL) {
|
||||
@@ -447,10 +454,9 @@ png_free(png_structp png_ptr, png_voidp ptr)
|
||||
}
|
||||
|
||||
/* Finally free the data. */
|
||||
png_debug_free(png_ptr, ptr);
|
||||
png_free_default(png_ptr, ptr);
|
||||
}
|
||||
#endif /* Not Borland DOS special memory handler */
|
||||
#endif
|
||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||
/* END of code to test memory allocation/deallocation */
|
||||
|
||||
/* Test one file */
|
||||
@@ -487,14 +493,26 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
}
|
||||
|
||||
png_debug(0, "Allocating read and write structures\n");
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
read_ptr = png_create_read_struct_2(PNG_LIBPNG_VER_STRING, (png_voidp)NULL,
|
||||
(png_error_ptr)NULL, (png_error_ptr)NULL, (png_voidp)NULL,
|
||||
(png_malloc_ptr)png_debug_malloc, (png_free_ptr)png_debug_free);
|
||||
#else
|
||||
read_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, (png_voidp)NULL,
|
||||
(png_error_ptr)NULL, (png_error_ptr)NULL);
|
||||
#endif
|
||||
#if defined(PNG_NO_STDIO)
|
||||
png_set_error_fn(read_ptr, (png_voidp)inname, png_default_error,
|
||||
png_default_warning);
|
||||
#endif
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
write_ptr = png_create_write_struct_2(PNG_LIBPNG_VER_STRING, (png_voidp)NULL,
|
||||
(png_error_ptr)NULL, (png_error_ptr)NULL, (png_voidp)NULL,
|
||||
(png_malloc_ptr)png_debug_malloc, (png_free_ptr)png_debug_free);
|
||||
#else
|
||||
write_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, (png_voidp)NULL,
|
||||
(png_error_ptr)NULL, (png_error_ptr)NULL);
|
||||
#endif
|
||||
#if defined(PNG_NO_STDIO)
|
||||
png_set_error_fn(write_ptr, (png_voidp)inname, png_default_error,
|
||||
png_default_warning);
|
||||
@@ -503,6 +521,8 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
read_info_ptr = png_create_info_struct(read_ptr);
|
||||
write_info_ptr = png_create_info_struct(write_ptr);
|
||||
end_info_ptr = png_create_info_struct(read_ptr);
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
#endif
|
||||
|
||||
png_debug(0, "Setting jmpbuf for read struct\n");
|
||||
#ifdef USE_FAR_KEYWORD
|
||||
@@ -518,10 +538,12 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
fclose(fpout);
|
||||
return (1);
|
||||
}
|
||||
#ifdef USE_FAR_KEYWORD
|
||||
png_memcpy(read_ptr->jmpbuf,jmpbuf,sizeof(jmp_buf));
|
||||
#endif
|
||||
|
||||
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))
|
||||
@@ -534,10 +556,10 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
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);
|
||||
@@ -563,8 +585,8 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
}
|
||||
|
||||
# if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
|
||||
black_pixels=0;
|
||||
png_set_write_user_transform_fn(write_ptr, count_black_pixels);
|
||||
zero_samples=0;
|
||||
png_set_write_user_transform_fn(write_ptr, count_zero_samples);
|
||||
# endif
|
||||
|
||||
png_debug(0, "Reading info struct\n");
|
||||
@@ -713,6 +735,13 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
|
||||
if (png_get_tIME(read_ptr, read_info_ptr, &mod_time))
|
||||
{
|
||||
png_set_tIME(write_ptr, write_info_ptr, mod_time);
|
||||
#if defined(PNG_TIME_RFC1123_SUPPORTED)
|
||||
/* we have to use png_strcpy instead of "=" because the string
|
||||
pointed to by png_convert_to_rfc1123() gets free'ed before
|
||||
we use it */
|
||||
png_strcpy(tIME_string,png_convert_to_rfc1123(read_ptr, mod_time));
|
||||
tIME_chunk_present++;
|
||||
#endif /* PNG_TIME_RFC1123_SUPPORTED */
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -871,6 +900,7 @@ main(int argc, char *argv[])
|
||||
|
||||
fprintf(STDERR, "Testing libpng version %s\n", PNG_LIBPNG_VER_STRING);
|
||||
fprintf(STDERR, " with zlib version %s\n", ZLIB_VERSION);
|
||||
fprintf(STDERR,"%s",png_get_copyright(NULL));
|
||||
|
||||
/* Do some consistency checking on the memory allocation settings, I'm
|
||||
not sure this matters, but it is nice to know, the first of these
|
||||
@@ -938,7 +968,7 @@ main(int argc, char *argv[])
|
||||
if (multiple)
|
||||
{
|
||||
int i;
|
||||
#ifdef PNGTEST_MEMORY_DEBUG
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
int allocation_now = current_allocation;
|
||||
#endif
|
||||
for (i=2; i<argc; ++i)
|
||||
@@ -947,16 +977,24 @@ main(int argc, char *argv[])
|
||||
fprintf(STDERR, "Testing %s:",argv[i]);
|
||||
kerror = test_one_file(argv[i], outname);
|
||||
if (kerror == 0)
|
||||
{
|
||||
#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
|
||||
fprintf(STDERR, " PASS (%lu black pixels)\n",black_pixels);
|
||||
fprintf(STDERR, " PASS (%lu zero samples)\n",zero_samples);
|
||||
#else
|
||||
fprintf(STDERR, " PASS\n");
|
||||
#endif
|
||||
else {
|
||||
#if defined(PNG_TIME_RFC1123_SUPPORTED)
|
||||
if(tIME_chunk_present != 0)
|
||||
fprintf(STDERR, " tIME = %s\n",tIME_string);
|
||||
tIME_chunk_present = 0;
|
||||
#endif /* PNG_TIME_RFC1123_SUPPORTED */
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(STDERR, " FAIL\n");
|
||||
ierror += kerror;
|
||||
}
|
||||
#ifdef PNGTEST_MEMORY_DEBUG
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
if (allocation_now != current_allocation)
|
||||
fprintf(STDERR, "MEMORY ERROR: %d bytes lost\n",
|
||||
current_allocation-allocation_now);
|
||||
@@ -972,7 +1010,7 @@ main(int argc, char *argv[])
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#ifdef PNGTEST_MEMORY_DEBUG
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
fprintf(STDERR, "Maximum memory allocation: %d bytes\n",
|
||||
maximum_allocation);
|
||||
#endif
|
||||
@@ -982,7 +1020,7 @@ main(int argc, char *argv[])
|
||||
int i;
|
||||
for (i=0; i<3; ++i) {
|
||||
int kerror;
|
||||
#ifdef PNGTEST_MEMORY_DEBUG
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
int allocation_now = current_allocation;
|
||||
#endif
|
||||
if (i == 1) status_dots_requested = 1;
|
||||
@@ -993,11 +1031,17 @@ main(int argc, char *argv[])
|
||||
if(kerror == 0)
|
||||
{
|
||||
if(verbose == 1 || i == 2)
|
||||
{
|
||||
#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
|
||||
fprintf(STDERR, " PASS (%lu black pixels)\n",black_pixels);
|
||||
fprintf(STDERR, " PASS (%lu zero samples)\n",zero_samples);
|
||||
#else
|
||||
fprintf(STDERR, " PASS\n");
|
||||
#endif
|
||||
#if defined(PNG_TIME_RFC1123_SUPPORTED)
|
||||
if(tIME_chunk_present != 0)
|
||||
fprintf(STDERR, " tIME = %s\n",tIME_string);
|
||||
#endif /* PNG_TIME_RFC1123_SUPPORTED */
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1006,7 +1050,7 @@ main(int argc, char *argv[])
|
||||
fprintf(STDERR, " FAIL\n");
|
||||
ierror += kerror;
|
||||
}
|
||||
#ifdef PNGTEST_MEMORY_DEBUG
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
if (allocation_now != current_allocation)
|
||||
fprintf(STDERR, "MEMORY ERROR: %d bytes lost\n",
|
||||
current_allocation-allocation_now);
|
||||
@@ -1022,7 +1066,7 @@ main(int argc, char *argv[])
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#ifdef PNGTEST_MEMORY_DEBUG
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
fprintf(STDERR, "Maximum memory allocation: %d bytes\n",
|
||||
maximum_allocation);
|
||||
#endif
|
||||
@@ -1034,3 +1078,4 @@ main(int argc, char *argv[])
|
||||
fprintf(STDERR, "libpng FAILS test\n");
|
||||
return (int)(ierror != 0);
|
||||
}
|
||||
|
||||
|
@@ -1,16 +1,15 @@
|
||||
|
||||
/* pngtrans.c - transforms the data in a row (used by both readers and writers)
|
||||
*
|
||||
* libpng 1.0.1
|
||||
* libpng 1.0.3 - January 14, 1999
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* March 15, 1998
|
||||
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
#include "../png/png.h"
|
||||
#include "png.h"
|
||||
|
||||
#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
|
||||
/* turn on bgr to rgb mapping */
|
||||
@@ -87,8 +86,8 @@ png_set_interlace_handling(png_structp png_ptr)
|
||||
#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.
|
||||
* for 48-bit input data, as well as to avoid problems with some compilers
|
||||
* that don't like bytes as parameters.
|
||||
*/
|
||||
void
|
||||
png_set_filler(png_structp png_ptr, png_uint_32 filler, int filler_loc)
|
||||
@@ -101,11 +100,23 @@ png_set_filler(png_structp png_ptr, png_uint_32 filler, int filler_loc)
|
||||
else
|
||||
png_ptr->flags &= ~PNG_FLAG_FILLER_AFTER;
|
||||
|
||||
/* This should probably go in the "do_filler" routine */
|
||||
if (png_ptr->color_type == PNG_COLOR_TYPE_RGB && png_ptr->bit_depth == 8)
|
||||
/* This should probably go in the "do_filler" routine.
|
||||
* I attempted to do that in libpng-1.0.1a but that caused problems
|
||||
* so I restored it in libpng-1.0.2a
|
||||
*/
|
||||
|
||||
if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
|
||||
{
|
||||
png_ptr->usr_channels = 4;
|
||||
}
|
||||
|
||||
/* Also I added this in libpng-1.0.2a (what happens when we expand
|
||||
* a less-than-8-bit grayscale to GA? */
|
||||
|
||||
if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY && png_ptr->bit_depth >= 8)
|
||||
{
|
||||
png_ptr->usr_channels = 2;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -137,7 +148,7 @@ png_set_invert_mono(png_structp png_ptr)
|
||||
png_ptr->transformations |= PNG_INVERT_MONO;
|
||||
}
|
||||
|
||||
/* invert monocrome grayscale data */
|
||||
/* invert monochrome grayscale data */
|
||||
void
|
||||
png_do_invert(png_row_infop row_info, png_bytep row)
|
||||
{
|
||||
@@ -148,12 +159,14 @@ png_do_invert(png_row_infop row_info, png_bytep row)
|
||||
#endif
|
||||
row_info->color_type == PNG_COLOR_TYPE_GRAY)
|
||||
{
|
||||
png_bytep rp;
|
||||
png_bytep rp = row;
|
||||
png_uint_32 i;
|
||||
png_uint_32 istop = row_info->rowbytes;
|
||||
|
||||
for (i = 0, rp = row; i < row_info->rowbytes; i++, rp++)
|
||||
for (i = 0; i < istop; i++)
|
||||
{
|
||||
*rp = (png_byte)(~(*rp));
|
||||
rp++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -171,15 +184,13 @@ png_do_swap(png_row_infop row_info, png_bytep row)
|
||||
#endif
|
||||
row_info->bit_depth == 16)
|
||||
{
|
||||
png_bytep rp;
|
||||
png_byte t;
|
||||
png_bytep rp = row;
|
||||
png_uint_32 i;
|
||||
png_uint_32 istop= row_info->width * row_info->channels;
|
||||
|
||||
for (i = 0, rp = row;
|
||||
i < row_info->width * row_info->channels;
|
||||
i++, rp += 2)
|
||||
for (i = 0; i < istop; i++, rp += 2)
|
||||
{
|
||||
t = *rp;
|
||||
png_byte t = *rp;
|
||||
*rp = *(rp + 1);
|
||||
*(rp + 1) = t;
|
||||
}
|
||||
@@ -338,6 +349,11 @@ png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags)
|
||||
if (row_info->color_type == PNG_COLOR_TYPE_RGB ||
|
||||
row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
|
||||
*/
|
||||
png_bytep sp=row;
|
||||
png_bytep dp=row;
|
||||
png_uint_32 row_width=row_info->width;
|
||||
png_uint_32 i;
|
||||
|
||||
if (row_info->channels == 4)
|
||||
{
|
||||
if (row_info->bit_depth == 8)
|
||||
@@ -345,10 +361,8 @@ png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags)
|
||||
/* 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+=3; sp+=4;
|
||||
for (i = 1; i < row_width; i++)
|
||||
{
|
||||
*dp++ = *sp++;
|
||||
*dp++ = *sp++;
|
||||
@@ -359,10 +373,7 @@ png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags)
|
||||
/* 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++)
|
||||
for (i = 0; i < row_width; i++)
|
||||
{
|
||||
sp++;
|
||||
*dp++ = *sp++;
|
||||
@@ -371,17 +382,15 @@ png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags)
|
||||
}
|
||||
}
|
||||
row_info->pixel_depth = 24;
|
||||
row_info->rowbytes = row_info->width * 3;
|
||||
row_info->rowbytes = row_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++)
|
||||
sp += 8; dp += 6;
|
||||
for (i = 1; i < row_width; i++)
|
||||
{
|
||||
/* This could be (although memcpy is probably slower):
|
||||
png_memcpy(dp, sp, 6);
|
||||
@@ -399,17 +408,15 @@ png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags)
|
||||
}
|
||||
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++)
|
||||
for (i = 0; i < row_width; i++)
|
||||
{
|
||||
/* This could be (although memcpy is probably slower):
|
||||
png_memcpy(dp, sp, 6);
|
||||
sp += 8;
|
||||
dp += 6;
|
||||
*/
|
||||
sp+=2;
|
||||
*dp++ = *sp++;
|
||||
*dp++ = *sp++;
|
||||
*dp++ = *sp++;
|
||||
@@ -419,9 +426,10 @@ png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags)
|
||||
}
|
||||
}
|
||||
row_info->pixel_depth = 48;
|
||||
row_info->rowbytes = row_info->width * 6;
|
||||
row_info->rowbytes = row_width * 6;
|
||||
}
|
||||
row_info->channels = 3;
|
||||
row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
|
||||
}
|
||||
/*
|
||||
else if (row_info->color_type == PNG_COLOR_TYPE_GRAY ||
|
||||
@@ -434,10 +442,7 @@ png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags)
|
||||
/* This converts from GX or GA to G */
|
||||
if (flags & PNG_FLAG_FILLER_AFTER)
|
||||
{
|
||||
png_bytep sp, dp;
|
||||
png_uint_32 i;
|
||||
|
||||
for (i = 1, sp = row + 2, dp = row + 1; i < row_info->width; i++)
|
||||
for (i = 0; i < row_width; i++)
|
||||
{
|
||||
*dp++ = *sp++;
|
||||
sp++;
|
||||
@@ -446,27 +451,22 @@ png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags)
|
||||
/* This converts from XG or AG to G */
|
||||
else
|
||||
{
|
||||
png_bytep sp, dp;
|
||||
png_uint_32 i;
|
||||
|
||||
for (i = 0, sp = row, dp = row; i < row_info->width; i++)
|
||||
for (i = 0; i < row_width; i++)
|
||||
{
|
||||
sp++;
|
||||
*dp++ = *sp++;
|
||||
}
|
||||
}
|
||||
row_info->pixel_depth = 8;
|
||||
row_info->rowbytes = row_info->width;
|
||||
row_info->rowbytes = row_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++)
|
||||
sp += 4; dp += 2;
|
||||
for (i = 1; i < row_width; i++)
|
||||
{
|
||||
*dp++ = *sp++;
|
||||
*dp++ = *sp++;
|
||||
@@ -475,11 +475,8 @@ png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags)
|
||||
}
|
||||
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++)
|
||||
for (i = 0; i < row_width; i++)
|
||||
{
|
||||
sp += 2;
|
||||
*dp++ = *sp++;
|
||||
@@ -487,9 +484,10 @@ png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags)
|
||||
}
|
||||
}
|
||||
row_info->pixel_depth = 16;
|
||||
row_info->rowbytes = row_info->width * 2;
|
||||
row_info->rowbytes = row_width * 2;
|
||||
}
|
||||
row_info->channels = 1;
|
||||
row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -507,17 +505,17 @@ png_do_bgr(png_row_infop row_info, png_bytep row)
|
||||
#endif
|
||||
(row_info->color_type & PNG_COLOR_MASK_COLOR))
|
||||
{
|
||||
png_uint_32 row_width = row_info->width;
|
||||
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)
|
||||
for (i = 0, rp = row; i < row_width; i++, rp += 3)
|
||||
{
|
||||
save = *rp;
|
||||
png_byte save = *rp;
|
||||
*rp = *(rp + 2);
|
||||
*(rp + 2) = save;
|
||||
}
|
||||
@@ -525,12 +523,11 @@ png_do_bgr(png_row_infop row_info, png_bytep row)
|
||||
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)
|
||||
for (i = 0, rp = row; i < row_width; i++, rp += 4)
|
||||
{
|
||||
save = *rp;
|
||||
png_byte save = *rp;
|
||||
*rp = *(rp + 2);
|
||||
*(rp + 2) = save;
|
||||
}
|
||||
@@ -541,33 +538,31 @@ png_do_bgr(png_row_infop row_info, png_bytep row)
|
||||
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)
|
||||
for (i = 0, rp = row; i < row_width; i++, rp += 6)
|
||||
{
|
||||
save[0] = *rp;
|
||||
save[1] = *(rp + 1);
|
||||
png_byte save = *rp;
|
||||
*rp = *(rp + 4);
|
||||
*(rp + 4) = save;
|
||||
save = *(rp + 1);
|
||||
*(rp + 1) = *(rp + 5);
|
||||
*(rp + 4) = save[0];
|
||||
*(rp + 5) = save[1];
|
||||
*(rp + 5) = save;
|
||||
}
|
||||
}
|
||||
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)
|
||||
for (i = 0, rp = row; i < row_width; i++, rp += 8)
|
||||
{
|
||||
save[0] = *rp;
|
||||
save[1] = *(rp + 1);
|
||||
png_byte save = *rp;
|
||||
*rp = *(rp + 4);
|
||||
*(rp + 4) = save;
|
||||
save = *(rp + 1);
|
||||
*(rp + 1) = *(rp + 5);
|
||||
*(rp + 4) = save[0];
|
||||
*(rp + 5) = save[1];
|
||||
*(rp + 5) = save;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,29 +1,28 @@
|
||||
|
||||
/* pngwio.c - functions for data output
|
||||
*
|
||||
* libpng 1.0.1
|
||||
* libpng 1.0.3 - January 14, 1999
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* March 15, 1998
|
||||
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
||||
*
|
||||
* 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
|
||||
* This file provides a location for all output. Users who need
|
||||
* special handling are expected to write functions that have the same
|
||||
* arguments as these and perform similar functions, but that 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/png.h"
|
||||
#include "png.h"
|
||||
|
||||
/* Write the data to whatever output you are using. The default routine
|
||||
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. */
|
||||
to write more than 64K on a 16 bit machine. */
|
||||
|
||||
void
|
||||
png_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
@@ -35,7 +34,7 @@ png_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
}
|
||||
|
||||
#if !defined(PNG_NO_STDIO)
|
||||
/* This is the function which does the actual writing of data. If you are
|
||||
/* This is the function that 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. */
|
||||
@@ -133,13 +132,13 @@ png_default_flush(png_structp png_ptr)
|
||||
png_ptr - pointer to a png output data structure
|
||||
io_ptr - pointer to user supplied structure containing info about
|
||||
the output functions. May be NULL.
|
||||
write_data_fn - pointer to a new output function which takes as its
|
||||
write_data_fn - pointer to a new output function that takes as its
|
||||
arguments a pointer to a png_struct, a pointer to
|
||||
data to be written, and a 32-bit unsigned int which is
|
||||
data to be written, and a 32-bit unsigned int that is
|
||||
the number of bytes to be written. The new write
|
||||
function should call png_error(png_ptr, "Error msg")
|
||||
to exit and output any fatal error messages.
|
||||
flush_data_fn - pointer to a new flush function which takes as its
|
||||
flush_data_fn - pointer to a new flush function that takes as its
|
||||
arguments a pointer to a png_struct. After a call to
|
||||
the flush function, there should be no data in any buffers
|
||||
or pending transmission. If the output method doesn't do
|
||||
@@ -175,7 +174,14 @@ png_set_write_fn(png_structp png_ptr, png_voidp io_ptr,
|
||||
#endif /* PNG_WRITE_FLUSH_SUPPORTED */
|
||||
|
||||
/* It is an error to read while writing a png file */
|
||||
if (png_ptr->read_data_fn != NULL)
|
||||
{
|
||||
png_ptr->read_data_fn = NULL;
|
||||
png_warning(png_ptr,
|
||||
"Attempted to set both read_data_fn and write_data_fn in");
|
||||
png_warning(png_ptr,
|
||||
"the same structure. Resetting read_data_fn to NULL.");
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(USE_FAR_KEYWORD)
|
||||
|
@@ -1,22 +1,21 @@
|
||||
|
||||
/* pngwrite.c - general routines to write a PNG file
|
||||
*
|
||||
* libpng 1.0.1
|
||||
* libpng 1.0.3 - January 14, 1999
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* March 15, 1998
|
||||
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
||||
*/
|
||||
|
||||
/* get internal access to png.h */
|
||||
#define PNG_INTERNAL
|
||||
#include "../png/png.h"
|
||||
#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
|
||||
* after the image data, put it in png_write_end(). I strongly encourage
|
||||
* 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
|
||||
@@ -218,43 +217,6 @@ png_write_end(png_structp png_ptr, png_infop info_ptr)
|
||||
png_write_IEND(png_ptr);
|
||||
}
|
||||
|
||||
#if defined(PNG_TIME_RFC1123_SUPPORTED)
|
||||
/* Convert the supplied time into an RFC 1123 string suitable for use in
|
||||
* a "Creation Time" or other text-based time string.
|
||||
*/
|
||||
png_charp
|
||||
png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime)
|
||||
{
|
||||
static PNG_CONST char short_months[12][4] =
|
||||
{"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, (png_uint_32)(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 - 1],
|
||||
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 - 1],
|
||||
ptime->year, ptime->hour % 24, ptime->minute % 60,
|
||||
ptime->second % 61);
|
||||
#endif
|
||||
return ((png_charp)png_ptr->time_buffer);
|
||||
}
|
||||
#endif /* PNG_TIME_RFC1123_SUPPORTED */
|
||||
|
||||
#if defined(PNG_WRITE_tIME_SUPPORTED)
|
||||
void
|
||||
png_convert_from_struct_tm(png_timep ptime, struct tm FAR * ttime)
|
||||
@@ -281,15 +243,32 @@ png_convert_from_time_t(png_timep ptime, time_t ttime)
|
||||
|
||||
/* 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_create_write_struct(png_const_charp user_png_ver, png_voidp error_ptr,
|
||||
png_error_ptr error_fn, png_error_ptr warn_fn)
|
||||
{
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
return (png_create_write_struct_2(user_png_ver, error_ptr, error_fn,
|
||||
warn_fn, NULL, NULL, NULL));
|
||||
}
|
||||
|
||||
/* Alternate initialize png_ptr structure, and allocate any memory needed */
|
||||
png_structp
|
||||
png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
|
||||
png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
|
||||
png_malloc_ptr malloc_fn, png_free_ptr free_fn)
|
||||
{
|
||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||
png_structp png_ptr;
|
||||
#ifdef USE_FAR_KEYWORD
|
||||
jmp_buf jmpbuf;
|
||||
#endif
|
||||
png_debug(1, "in png_create_write_struct\n");
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
if ((png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
|
||||
(png_malloc_ptr)malloc_fn)) == NULL)
|
||||
#else
|
||||
if ((png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG)) == NULL)
|
||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||
{
|
||||
return ((png_structp)NULL);
|
||||
}
|
||||
@@ -306,6 +285,9 @@ png_create_write_struct(png_const_charp user_png_ver, voidp error_ptr,
|
||||
#ifdef USE_FAR_KEYWORD
|
||||
png_memcpy(png_ptr->jmpbuf,jmpbuf,sizeof(jmp_buf));
|
||||
#endif
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
|
||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||
png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
|
||||
|
||||
/* Libpng 0.90 and later are binary incompatible with libpng 0.89, so
|
||||
@@ -335,7 +317,6 @@ png_create_write_struct(png_const_charp user_png_ver, voidp error_ptr,
|
||||
return ((png_structp)png_ptr);
|
||||
}
|
||||
|
||||
|
||||
/* Initialize png_ptr structure, and allocate any memory needed */
|
||||
void
|
||||
png_write_init(png_structp png_ptr)
|
||||
@@ -422,6 +403,36 @@ png_write_row(png_structp png_ptr, png_bytep row)
|
||||
/* initialize transformations and other stuff if first time */
|
||||
if (png_ptr->row_number == 0 && png_ptr->pass == 0)
|
||||
{
|
||||
/* check for transforms that have been set but were defined out */
|
||||
#if !defined(PNG_WRITE_INVERT_SUPPORTED) && defined(PNG_READ_INVERT_SUPPORTED)
|
||||
if (png_ptr->transformations & PNG_INVERT_MONO)
|
||||
png_warning(png_ptr, "PNG_WRITE_INVERT_SUPPORTED is not defined.");
|
||||
#endif
|
||||
#if !defined(PNG_WRITE_FILLER_SUPPORTED) && defined(PNG_READ_FILLER_SUPPORTED)
|
||||
if (png_ptr->transformations & PNG_FILLER)
|
||||
png_warning(png_ptr, "PNG_WRITE_FILLER_SUPPORTED is not defined.");
|
||||
#endif
|
||||
#if !defined(PNG_WRITE_PACKSWAP_SUPPORTED) && defined(PNG_READ_PACKSWAP_SUPPORTED)
|
||||
if (png_ptr->transformations & PNG_PACKSWAP)
|
||||
png_warning(png_ptr, "PNG_WRITE_PACKSWAP_SUPPORTED is not defined.");
|
||||
#endif
|
||||
#if !defined(PNG_WRITE_PACK_SUPPORTED) && defined(PNG_READ_PACK_SUPPORTED)
|
||||
if (png_ptr->transformations & PNG_PACK)
|
||||
png_warning(png_ptr, "PNG_WRITE_PACK_SUPPORTED is not defined.");
|
||||
#endif
|
||||
#if !defined(PNG_WRITE_SHIFT_SUPPORTED) && defined(PNG_READ_SHIFT_SUPPORTED)
|
||||
if (png_ptr->transformations & PNG_SHIFT)
|
||||
png_warning(png_ptr, "PNG_WRITE_SHIFT_SUPPORTED is not defined.");
|
||||
#endif
|
||||
#if !defined(PNG_WRITE_BGR_SUPPORTED) && defined(PNG_READ_BGR_SUPPORTED)
|
||||
if (png_ptr->transformations & PNG_BGR)
|
||||
png_warning(png_ptr, "PNG_WRITE_BGR_SUPPORTED is not defined.");
|
||||
#endif
|
||||
#if !defined(PNG_WRITE_SWAP_SUPPORTED) && defined(PNG_READ_SWAP_SUPPORTED)
|
||||
if (png_ptr->transformations & PNG_SWAP_BYTES)
|
||||
png_warning(png_ptr, "PNG_WRITE_SWAP_SUPPORTED is not defined.");
|
||||
#endif
|
||||
|
||||
png_write_start_row(png_ptr);
|
||||
}
|
||||
|
||||
@@ -601,10 +612,18 @@ png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)
|
||||
{
|
||||
png_structp png_ptr = NULL;
|
||||
png_infop info_ptr = NULL;
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
png_free_ptr free_fn = NULL;
|
||||
#endif
|
||||
|
||||
png_debug(1, "in png_destroy_write_struct\n");
|
||||
if (png_ptr_ptr != NULL)
|
||||
{
|
||||
png_ptr = *png_ptr_ptr;
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
free_fn = png_ptr->free_fn;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (info_ptr_ptr != NULL)
|
||||
info_ptr = *info_ptr_ptr;
|
||||
@@ -627,14 +646,22 @@ png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)
|
||||
png_free(png_ptr, info_ptr->pcal_params);
|
||||
}
|
||||
#endif
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
png_destroy_struct_2((png_voidp)info_ptr, free_fn);
|
||||
#else
|
||||
png_destroy_struct((png_voidp)info_ptr);
|
||||
#endif
|
||||
*info_ptr_ptr = (png_infop)NULL;
|
||||
}
|
||||
|
||||
if (png_ptr != NULL)
|
||||
{
|
||||
png_write_destroy(png_ptr);
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
png_destroy_struct_2((png_voidp)png_ptr, free_fn);
|
||||
#else
|
||||
png_destroy_struct((png_voidp)png_ptr);
|
||||
#endif
|
||||
*png_ptr_ptr = (png_structp)NULL;
|
||||
}
|
||||
}
|
||||
@@ -648,6 +675,9 @@ png_write_destroy(png_structp png_ptr)
|
||||
png_error_ptr error_fn;
|
||||
png_error_ptr warning_fn;
|
||||
png_voidp error_ptr;
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
png_free_ptr free_fn;
|
||||
#endif
|
||||
|
||||
png_debug(1, "in png_write_destroy\n");
|
||||
/* free any memory zlib uses */
|
||||
@@ -678,12 +708,18 @@ png_write_destroy(png_structp png_ptr)
|
||||
error_fn = png_ptr->error_fn;
|
||||
warning_fn = png_ptr->warning_fn;
|
||||
error_ptr = png_ptr->error_ptr;
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
free_fn = png_ptr->free_fn;
|
||||
#endif
|
||||
|
||||
png_memset(png_ptr, 0, sizeof (png_struct));
|
||||
|
||||
png_ptr->error_fn = error_fn;
|
||||
png_ptr->warning_fn = warning_fn;
|
||||
png_ptr->error_ptr = error_ptr;
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
png_ptr->free_fn = free_fn;
|
||||
#endif
|
||||
|
||||
png_memcpy(png_ptr->jmpbuf, tmp_jmp, sizeof (jmp_buf));
|
||||
}
|
||||
@@ -794,9 +830,7 @@ 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)
|
||||
|
@@ -1,18 +1,17 @@
|
||||
|
||||
/* pngwtran.c - transforms the data in a row for PNG writers
|
||||
*
|
||||
* libpng 1.0.1
|
||||
* libpng 1.0.3 - January 14, 1999
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* March 15, 1998
|
||||
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
#include "../png/png.h"
|
||||
#include "png.h"
|
||||
|
||||
/* Transform the data according to the users wishes. The order of
|
||||
/* Transform the data according to the user's wishes. The order of
|
||||
* transformations is significant.
|
||||
*/
|
||||
void
|
||||
@@ -48,15 +47,15 @@ png_do_write_transformations(png_structp png_ptr)
|
||||
png_do_pack(&(png_ptr->row_info), png_ptr->row_buf + 1,
|
||||
(png_uint_32)png_ptr->bit_depth);
|
||||
#endif
|
||||
#if defined(PNG_WRITE_SWAP_SUPPORTED)
|
||||
if (png_ptr->transformations & PNG_SWAP_BYTES)
|
||||
png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
|
||||
#endif
|
||||
#if defined(PNG_WRITE_SHIFT_SUPPORTED)
|
||||
if (png_ptr->transformations & PNG_SHIFT)
|
||||
png_do_shift(&(png_ptr->row_info), png_ptr->row_buf + 1,
|
||||
&(png_ptr->shift));
|
||||
#endif
|
||||
#if defined(PNG_WRITE_SWAP_SUPPORTED)
|
||||
if (png_ptr->transformations & PNG_SWAP_BYTES)
|
||||
png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
|
||||
#endif
|
||||
#if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
|
||||
if (png_ptr->transformations & PNG_INVERT_ALPHA)
|
||||
png_do_write_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
|
||||
@@ -97,12 +96,14 @@ png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth)
|
||||
png_bytep sp, dp;
|
||||
int mask, v;
|
||||
png_uint_32 i;
|
||||
png_uint_32 row_width = row_info->width;
|
||||
|
||||
sp = row;
|
||||
dp = row;
|
||||
mask = 0x80;
|
||||
v = 0;
|
||||
for (i = 0; i < row_info->width; i++)
|
||||
|
||||
for (i = 0; i < row_width; i++)
|
||||
{
|
||||
if (*sp != 0)
|
||||
v |= mask;
|
||||
@@ -126,12 +127,13 @@ png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth)
|
||||
png_bytep sp, dp;
|
||||
int shift, v;
|
||||
png_uint_32 i;
|
||||
png_uint_32 row_width = row_info->width;
|
||||
|
||||
sp = row;
|
||||
dp = row;
|
||||
shift = 6;
|
||||
v = 0;
|
||||
for (i = 0; i < row_info->width; i++)
|
||||
for (i = 0; i < row_width; i++)
|
||||
{
|
||||
png_byte value;
|
||||
|
||||
@@ -157,12 +159,13 @@ png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth)
|
||||
png_bytep sp, dp;
|
||||
int shift, v;
|
||||
png_uint_32 i;
|
||||
png_uint_32 row_width = row_info->width;
|
||||
|
||||
sp = row;
|
||||
dp = row;
|
||||
shift = 4;
|
||||
v = 0;
|
||||
for (i = 0; i < row_info->width; i++)
|
||||
for (i = 0; i < row_width; i++)
|
||||
{
|
||||
png_byte value;
|
||||
|
||||
@@ -214,9 +217,8 @@ png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
|
||||
row_info->color_type != PNG_COLOR_TYPE_PALETTE)
|
||||
{
|
||||
int shift_start[4], shift_dec[4];
|
||||
png_uint_32 channels;
|
||||
int channels = 0;
|
||||
|
||||
channels = 0;
|
||||
if (row_info->color_type & PNG_COLOR_MASK_COLOR)
|
||||
{
|
||||
shift_start[channels] = row_info->bit_depth - bit_depth->red;
|
||||
@@ -245,9 +247,10 @@ png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
|
||||
/* with low row depths, could only be grayscale, so one channel */
|
||||
if (row_info->bit_depth < 8)
|
||||
{
|
||||
png_bytep bp;
|
||||
png_bytep bp = row;
|
||||
png_uint_32 i;
|
||||
png_byte mask;
|
||||
png_uint_32 row_bytes = row_info->rowbytes;
|
||||
|
||||
if (bit_depth->gray == 1 && row_info->bit_depth == 2)
|
||||
mask = 0x55;
|
||||
@@ -256,7 +259,7 @@ png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
|
||||
else
|
||||
mask = 0xff;
|
||||
|
||||
for (bp = row, i = 0; i < row_info->rowbytes; i++, bp++)
|
||||
for (i = 0; i < row_bytes; i++, bp++)
|
||||
{
|
||||
png_uint_16 v;
|
||||
int j;
|
||||
@@ -274,17 +277,16 @@ png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
|
||||
}
|
||||
else if (row_info->bit_depth == 8)
|
||||
{
|
||||
png_bytep bp;
|
||||
png_bytep bp = row;
|
||||
png_uint_32 i;
|
||||
png_uint_32 istop = channels * row_info->width;
|
||||
|
||||
for (bp = row, i = 0; i < row_info->width; i++)
|
||||
for (i = 0; i < istop; i++, bp++)
|
||||
{
|
||||
png_uint_32 c;
|
||||
|
||||
for (c = 0; c < channels; c++, bp++)
|
||||
{
|
||||
png_uint_16 v;
|
||||
int j;
|
||||
int c = (int)(i%channels);
|
||||
|
||||
v = *bp;
|
||||
*bp = 0;
|
||||
@@ -297,18 +299,15 @@ png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
png_bytep bp;
|
||||
png_uint_32 i;
|
||||
png_uint_32 istop = channels * row_info->width;
|
||||
|
||||
for (bp = row, i = 0; i < row_info->width * row_info->channels; i++)
|
||||
{
|
||||
png_uint_32 c;
|
||||
|
||||
for (c = 0; c < channels; c++, bp += 2)
|
||||
for (bp = row, i = 0; i < istop; i++)
|
||||
{
|
||||
int c = (int)(i%channels);
|
||||
png_uint_16 value, v;
|
||||
int j;
|
||||
|
||||
@@ -321,9 +320,8 @@ png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
|
||||
else
|
||||
value |= (png_uint_16)((v >> (-j)) & (png_uint_16)0xffff);
|
||||
}
|
||||
*bp = (png_byte)(value >> 8);
|
||||
*(bp + 1) = (png_byte)(value & 0xff);
|
||||
}
|
||||
*bp++ = (png_byte)(value >> 8);
|
||||
*bp++ = (png_byte)(value & 0xff);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -345,12 +343,11 @@ png_do_write_swap_alpha(png_row_infop row_info, png_bytep row)
|
||||
if (row_info->bit_depth == 8)
|
||||
{
|
||||
png_bytep sp, dp;
|
||||
png_byte save;
|
||||
png_uint_32 i;
|
||||
|
||||
for (i = 0, sp = dp = row; i < row_info->width; i++)
|
||||
png_uint_32 row_width = row_info->width;
|
||||
for (i = 0, sp = dp = row; i < row_width; i++)
|
||||
{
|
||||
save = *(sp++);
|
||||
png_byte save = *(sp++);
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = *(sp++);
|
||||
@@ -361,11 +358,12 @@ png_do_write_swap_alpha(png_row_infop row_info, png_bytep row)
|
||||
else
|
||||
{
|
||||
png_bytep sp, dp;
|
||||
png_byte save[2];
|
||||
png_uint_32 i;
|
||||
png_uint_32 row_width = row_info->width;
|
||||
|
||||
for (i = 0, sp = dp = row; i < row_info->width; i++)
|
||||
for (i = 0, sp = dp = row; i < row_width; i++)
|
||||
{
|
||||
png_byte save[2];
|
||||
save[0] = *(sp++);
|
||||
save[1] = *(sp++);
|
||||
*(dp++) = *(sp++);
|
||||
@@ -385,12 +383,12 @@ png_do_write_swap_alpha(png_row_infop row_info, png_bytep row)
|
||||
if (row_info->bit_depth == 8)
|
||||
{
|
||||
png_bytep sp, dp;
|
||||
png_byte save;
|
||||
png_uint_32 i;
|
||||
png_uint_32 row_width = row_info->width;
|
||||
|
||||
for (i = 0, sp = dp = row; i < row_info->width; i++)
|
||||
for (i = 0, sp = dp = row; i < row_width; i++)
|
||||
{
|
||||
save = *(sp++);
|
||||
png_byte save = *(sp++);
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = save;
|
||||
}
|
||||
@@ -399,11 +397,12 @@ png_do_write_swap_alpha(png_row_infop row_info, png_bytep row)
|
||||
else
|
||||
{
|
||||
png_bytep sp, dp;
|
||||
png_byte save[2];
|
||||
png_uint_32 i;
|
||||
png_uint_32 row_width = row_info->width;
|
||||
|
||||
for (i = 0, sp = dp = row; i < row_info->width; i++)
|
||||
for (i = 0, sp = dp = row; i < row_width; i++)
|
||||
{
|
||||
png_byte save[2];
|
||||
save[0] = *(sp++);
|
||||
save[1] = *(sp++);
|
||||
*(dp++) = *(sp++);
|
||||
@@ -433,8 +432,8 @@ png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
|
||||
{
|
||||
png_bytep sp, dp;
|
||||
png_uint_32 i;
|
||||
|
||||
for (i = 0, sp = dp = row; i < row_info->width; i++)
|
||||
png_uint_32 row_width = row_info->width;
|
||||
for (i = 0, sp = dp = row; i < row_width; i++)
|
||||
{
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = *(sp++);
|
||||
@@ -447,8 +446,9 @@ png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
|
||||
{
|
||||
png_bytep sp, dp;
|
||||
png_uint_32 i;
|
||||
png_uint_32 row_width = row_info->width;
|
||||
|
||||
for (i = 0, sp = dp = row; i < row_info->width; i++)
|
||||
for (i = 0, sp = dp = row; i < row_width; i++)
|
||||
{
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = *(sp++);
|
||||
@@ -468,8 +468,9 @@ png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
|
||||
{
|
||||
png_bytep sp, dp;
|
||||
png_uint_32 i;
|
||||
png_uint_32 row_width = row_info->width;
|
||||
|
||||
for (i = 0, sp = dp = row; i < row_info->width; i++)
|
||||
for (i = 0, sp = dp = row; i < row_width; i++)
|
||||
{
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = 255 - *(sp++);
|
||||
@@ -480,8 +481,9 @@ png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
|
||||
{
|
||||
png_bytep sp, dp;
|
||||
png_uint_32 i;
|
||||
png_uint_32 row_width = row_info->width;
|
||||
|
||||
for (i = 0, sp = dp = row; i < row_info->width; i++)
|
||||
for (i = 0, sp = dp = row; i < row_width; i++)
|
||||
{
|
||||
*(dp++) = *(sp++);
|
||||
*(dp++) = *(sp++);
|
||||
|
@@ -1,16 +1,15 @@
|
||||
|
||||
/* pngwutil.c - utilities to write a PNG file
|
||||
*
|
||||
* libpng 1.0.1
|
||||
* libpng 1.0.3 - January 14, 1999
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
* Copyright (c) 1998, Glenn Randers-Pehrson
|
||||
* March 15, 1998
|
||||
* Copyright (c) 1998, 1999 Glenn Randers-Pehrson
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
#include "../png/png.h"
|
||||
#include "png.h"
|
||||
|
||||
/* Place a 32-bit number into a buffer in PNG byte order. We work
|
||||
* with unsigned numbers for convenience, although one supported
|
||||
@@ -274,7 +273,7 @@ png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height,
|
||||
}
|
||||
|
||||
/* write the palette. We are careful not to trust png_color to be in the
|
||||
* correct order for PNG, so people can redefine it to any convient
|
||||
* correct order for PNG, so people can redefine it to any convenient
|
||||
* structure.
|
||||
*/
|
||||
void
|
||||
@@ -575,7 +574,8 @@ png_write_hIST(png_structp png_ptr, png_uint_16p hist, int num_hist)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_WRITE_tEXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED)
|
||||
#if defined(PNG_WRITE_tEXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED) || \
|
||||
defined(PNG_WRITE_pCAL_SUPPORTED)
|
||||
/* Check that the tEXt or zTXt keyword is valid per PNG 1.0 specification,
|
||||
* and if invalid, correct the keyword rather than discarding the entire
|
||||
* chunk. The PNG 1.0 specification requires keywords 1-79 characters in
|
||||
@@ -766,7 +766,7 @@ png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,
|
||||
}
|
||||
|
||||
/* We can't write the chunk until we find out how much data we have,
|
||||
* which means we need to run the compressor first, and save the
|
||||
* which means we need to run the compressor first and save the
|
||||
* output. This shouldn't be a problem, as the vast majority of
|
||||
* comments should be reasonable, but we will set up an array of
|
||||
* malloc'd pointers to be sure.
|
||||
@@ -1241,7 +1241,7 @@ png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
|
||||
if (pass < 6)
|
||||
#endif
|
||||
{
|
||||
/* each pixel depth is handled seperately */
|
||||
/* each pixel depth is handled separately */
|
||||
switch (row_info->pixel_depth)
|
||||
{
|
||||
case 1:
|
||||
@@ -1252,11 +1252,12 @@ png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
|
||||
int d;
|
||||
int value;
|
||||
png_uint_32 i;
|
||||
png_uint_32 row_width = row_info->width;
|
||||
|
||||
dp = row;
|
||||
d = 0;
|
||||
shift = 7;
|
||||
for (i = png_pass_start[pass]; i < row_info->width;
|
||||
for (i = png_pass_start[pass]; i < row_width;
|
||||
i += png_pass_inc[pass])
|
||||
{
|
||||
sp = row + (png_size_t)(i >> 3);
|
||||
@@ -1285,11 +1286,12 @@ png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
|
||||
int d;
|
||||
int value;
|
||||
png_uint_32 i;
|
||||
png_uint_32 row_width = row_info->width;
|
||||
|
||||
dp = row;
|
||||
shift = 6;
|
||||
d = 0;
|
||||
for (i = png_pass_start[pass]; i < row_info->width;
|
||||
for (i = png_pass_start[pass]; i < row_width;
|
||||
i += png_pass_inc[pass])
|
||||
{
|
||||
sp = row + (png_size_t)(i >> 2);
|
||||
@@ -1317,11 +1319,12 @@ png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
|
||||
int d;
|
||||
int value;
|
||||
png_uint_32 i;
|
||||
png_uint_32 row_width = row_info->width;
|
||||
|
||||
dp = row;
|
||||
shift = 4;
|
||||
d = 0;
|
||||
for (i = png_pass_start[pass]; i < row_info->width;
|
||||
for (i = png_pass_start[pass]; i < row_width;
|
||||
i += png_pass_inc[pass])
|
||||
{
|
||||
sp = row + (png_size_t)(i >> 1);
|
||||
@@ -1346,6 +1349,7 @@ png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
|
||||
png_bytep sp;
|
||||
png_bytep dp;
|
||||
png_uint_32 i;
|
||||
png_uint_32 row_width = row_info->width;
|
||||
png_size_t pixel_bytes;
|
||||
|
||||
/* start at the beginning */
|
||||
@@ -1354,7 +1358,7 @@ png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
|
||||
pixel_bytes = (row_info->pixel_depth >> 3);
|
||||
/* loop through the row, only looking at the pixels that
|
||||
matter */
|
||||
for (i = png_pass_start[pass]; i < row_info->width;
|
||||
for (i = png_pass_start[pass]; i < row_width;
|
||||
i += png_pass_inc[pass])
|
||||
{
|
||||
/* find out where the original pixel is */
|
||||
@@ -1392,6 +1396,11 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
|
||||
{
|
||||
png_bytep prev_row, best_row, row_buf;
|
||||
png_uint_32 mins, bpp;
|
||||
png_byte filter_to_do = png_ptr->do_filter;
|
||||
png_uint_32 row_bytes = row_info->rowbytes;
|
||||
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
|
||||
int num_p_filters = (int)png_ptr->num_prev_filters;
|
||||
#endif
|
||||
|
||||
png_debug(1, "in png_write_find_filter\n");
|
||||
/* find out how many bytes offset each pixel is */
|
||||
@@ -1403,28 +1412,38 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
|
||||
|
||||
/* The prediction method we use is to find which method provides the
|
||||
* smallest value when summing the absolute values of the distances
|
||||
* from zero using anything >= 128 as negative numbers. This is known
|
||||
* from zero, using anything >= 128 as negative numbers. This is known
|
||||
* as the "minimum sum of absolute differences" heuristic. Other
|
||||
* heuristics are the "weighted minumum sum of absolute differences"
|
||||
* heuristics are the "weighted minimum sum of absolute differences"
|
||||
* (experimental and can in theory improve compression), and the "zlib
|
||||
* predictive" method (not implemented in libpng 0.95), which does test
|
||||
* compressions of lines using different filter methods, and then chooses
|
||||
* the (series of) filter(s) which give minimum compressed data size (VERY
|
||||
* predictive" method (not implemented yet), which does test compressions
|
||||
* of lines using different filter methods, and then chooses the
|
||||
* (series of) filter(s) that give minimum compressed data size (VERY
|
||||
* computationally expensive).
|
||||
*
|
||||
* GRR 980525: consider also
|
||||
* (1) minimum sum of absolute differences from running average (i.e.,
|
||||
* keep running sum of non-absolute differences & count of bytes)
|
||||
* [track dispersion, too? restart average if dispersion too large?]
|
||||
* (1b) minimum sum of absolute differences from sliding average, probably
|
||||
* with window size <= deflate window (usually 32K)
|
||||
* (2) minimum sum of squared differences from zero or running average
|
||||
* (i.e., ~ root-mean-square approach)
|
||||
*/
|
||||
|
||||
|
||||
/* We don't need to test the 'no filter' case if this is the only filter
|
||||
* that has been chosen, as it doesn't actually do anything to the data.
|
||||
*/
|
||||
if (png_ptr->do_filter & PNG_FILTER_NONE &&
|
||||
png_ptr->do_filter != PNG_FILTER_NONE)
|
||||
if (filter_to_do & PNG_FILTER_NONE &&
|
||||
filter_to_do != PNG_FILTER_NONE)
|
||||
{
|
||||
png_bytep rp;
|
||||
png_uint_32 sum = 0;
|
||||
png_uint_32 i;
|
||||
int v;
|
||||
|
||||
for (i = 0, rp = row_buf + 1; i < row_info->rowbytes; i++, rp++)
|
||||
for (i = 0, rp = row_buf + 1; i < row_bytes; i++, rp++)
|
||||
{
|
||||
v = *rp;
|
||||
sum += (v < 128) ? v : 256 - v;
|
||||
@@ -1434,17 +1453,18 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
|
||||
if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
|
||||
{
|
||||
png_uint_32 sumhi, sumlo;
|
||||
int j;
|
||||
sumlo = sum & PNG_LOMASK;
|
||||
sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; /* Gives us some footroom */
|
||||
|
||||
/* Reduce the sum if we match any of the previous rows */
|
||||
for (i = 0; i < (png_uint_32)png_ptr->num_prev_filters; i++)
|
||||
for (j = 0; j < num_p_filters; j++)
|
||||
{
|
||||
if (png_ptr->prev_filters[i] == PNG_FILTER_NONE)
|
||||
if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
|
||||
{
|
||||
sumlo = (sumlo * png_ptr->filter_weights[i]) >>
|
||||
sumlo = (sumlo * png_ptr->filter_weights[j]) >>
|
||||
PNG_WEIGHT_SHIFT;
|
||||
sumhi = (sumhi * png_ptr->filter_weights[i]) >>
|
||||
sumhi = (sumhi * png_ptr->filter_weights[j]) >>
|
||||
PNG_WEIGHT_SHIFT;
|
||||
}
|
||||
}
|
||||
@@ -1468,7 +1488,25 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
|
||||
}
|
||||
|
||||
/* sub filter */
|
||||
if (png_ptr->do_filter & PNG_FILTER_SUB)
|
||||
if (filter_to_do == PNG_FILTER_SUB)
|
||||
/* it's the only filter so no testing is needed */
|
||||
{
|
||||
png_bytep rp, lp, dp;
|
||||
png_uint_32 i;
|
||||
for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
|
||||
i++, rp++, dp++)
|
||||
{
|
||||
*dp = *rp;
|
||||
}
|
||||
for (lp = row_buf + 1; i < row_bytes;
|
||||
i++, rp++, lp++, dp++)
|
||||
{
|
||||
*dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
|
||||
}
|
||||
best_row = png_ptr->sub_row;
|
||||
}
|
||||
|
||||
else if (filter_to_do & PNG_FILTER_SUB)
|
||||
{
|
||||
png_bytep rp, dp, lp;
|
||||
png_uint_32 sum = 0, lmins = mins;
|
||||
@@ -1476,23 +1514,24 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
|
||||
int v;
|
||||
|
||||
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
|
||||
/* We temporarily increase the "minumum sum" by the factor we
|
||||
/* We temporarily increase the "minimum sum" by the factor we
|
||||
* would reduce the sum of this filter, so that we can do the
|
||||
* early exit comparison without scaling the sum each time.
|
||||
*/
|
||||
if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
|
||||
{
|
||||
int j;
|
||||
png_uint_32 lmhi, lmlo;
|
||||
lmlo = lmins & PNG_LOMASK;
|
||||
lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
|
||||
|
||||
for (i = 0; i < (png_uint_32)png_ptr->num_prev_filters; i++)
|
||||
for (j = 0; j < num_p_filters; j++)
|
||||
{
|
||||
if (png_ptr->prev_filters[i] == PNG_FILTER_VALUE_SUB)
|
||||
if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB)
|
||||
{
|
||||
lmlo = (lmlo * png_ptr->inv_filter_weights[i]) >>
|
||||
lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
|
||||
PNG_WEIGHT_SHIFT;
|
||||
lmhi = (lmhi * png_ptr->inv_filter_weights[i]) >>
|
||||
lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
|
||||
PNG_WEIGHT_SHIFT;
|
||||
}
|
||||
}
|
||||
@@ -1530,17 +1569,18 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
|
||||
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
|
||||
if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
|
||||
{
|
||||
int j;
|
||||
png_uint_32 sumhi, sumlo;
|
||||
sumlo = sum & PNG_LOMASK;
|
||||
sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
|
||||
|
||||
for (i = 0; i < (png_uint_32)png_ptr->num_prev_filters; i++)
|
||||
for (j = 0; j < num_p_filters; j++)
|
||||
{
|
||||
if (png_ptr->prev_filters[i] == PNG_FILTER_VALUE_SUB)
|
||||
if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB)
|
||||
{
|
||||
sumlo = (sumlo * png_ptr->inv_filter_weights[i]) >>
|
||||
sumlo = (sumlo * png_ptr->inv_filter_weights[j]) >>
|
||||
PNG_WEIGHT_SHIFT;
|
||||
sumhi = (sumhi * png_ptr->inv_filter_weights[i]) >>
|
||||
sumhi = (sumhi * png_ptr->inv_filter_weights[j]) >>
|
||||
PNG_WEIGHT_SHIFT;
|
||||
}
|
||||
}
|
||||
@@ -1565,27 +1605,43 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
|
||||
}
|
||||
|
||||
/* up filter */
|
||||
if (png_ptr->do_filter & PNG_FILTER_UP)
|
||||
if (filter_to_do == PNG_FILTER_UP)
|
||||
{
|
||||
png_bytep rp, dp, pp;
|
||||
png_uint_32 i;
|
||||
|
||||
for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
|
||||
pp = prev_row + 1; i < row_bytes;
|
||||
i++, rp++, pp++, dp++)
|
||||
{
|
||||
*dp = (png_byte)(((int)*rp - (int)*pp) & 0xff);
|
||||
}
|
||||
best_row = png_ptr->up_row;
|
||||
}
|
||||
|
||||
else if (filter_to_do & PNG_FILTER_UP)
|
||||
{
|
||||
png_bytep rp, dp, pp;
|
||||
png_uint_32 sum = 0, lmins = mins;
|
||||
png_uint_32 i;
|
||||
int v;
|
||||
|
||||
|
||||
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
|
||||
if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
|
||||
{
|
||||
int j;
|
||||
png_uint_32 lmhi, lmlo;
|
||||
lmlo = lmins & PNG_LOMASK;
|
||||
lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
|
||||
|
||||
for (i = 0; i < (png_uint_32)png_ptr->num_prev_filters; i++)
|
||||
for (j = 0; j < num_p_filters; j++)
|
||||
{
|
||||
if (png_ptr->prev_filters[i] == PNG_FILTER_VALUE_UP)
|
||||
if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP)
|
||||
{
|
||||
lmlo = (lmlo * png_ptr->inv_filter_weights[i]) >>
|
||||
lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
|
||||
PNG_WEIGHT_SHIFT;
|
||||
lmhi = (lmhi * png_ptr->inv_filter_weights[i]) >>
|
||||
lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
|
||||
PNG_WEIGHT_SHIFT;
|
||||
}
|
||||
}
|
||||
@@ -1603,10 +1659,9 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
|
||||
#endif
|
||||
|
||||
for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
|
||||
pp = prev_row + 1; i < row_info->rowbytes;
|
||||
i++, rp++, pp++, dp++)
|
||||
pp = prev_row + 1; i < row_bytes; i++)
|
||||
{
|
||||
v = *dp = (png_byte)(((int)*rp - (int)*pp) & 0xff);
|
||||
v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
|
||||
|
||||
sum += (v < 128) ? v : 256 - v;
|
||||
|
||||
@@ -1617,17 +1672,18 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
|
||||
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
|
||||
if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
|
||||
{
|
||||
int j;
|
||||
png_uint_32 sumhi, sumlo;
|
||||
sumlo = sum & PNG_LOMASK;
|
||||
sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
|
||||
|
||||
for (i = 0; i < (png_uint_32)png_ptr->num_prev_filters; i++)
|
||||
for (j = 0; j < num_p_filters; j++)
|
||||
{
|
||||
if (png_ptr->prev_filters[i] == PNG_FILTER_UP)
|
||||
if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP)
|
||||
{
|
||||
sumlo = (sumlo * png_ptr->filter_weights[i]) >>
|
||||
sumlo = (sumlo * png_ptr->filter_weights[j]) >>
|
||||
PNG_WEIGHT_SHIFT;
|
||||
sumhi = (sumhi * png_ptr->filter_weights[i]) >>
|
||||
sumhi = (sumhi * png_ptr->filter_weights[j]) >>
|
||||
PNG_WEIGHT_SHIFT;
|
||||
}
|
||||
}
|
||||
@@ -1652,7 +1708,24 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
|
||||
}
|
||||
|
||||
/* avg filter */
|
||||
if (png_ptr->do_filter & PNG_FILTER_AVG)
|
||||
if (filter_to_do == PNG_FILTER_AVG)
|
||||
{
|
||||
png_bytep rp, dp, pp, lp;
|
||||
png_uint_32 i;
|
||||
for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
|
||||
pp = prev_row + 1; i < bpp; i++)
|
||||
{
|
||||
*dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
|
||||
}
|
||||
for (lp = row_buf + 1; i < row_bytes; i++)
|
||||
{
|
||||
*dp++ = (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2))
|
||||
& 0xff);
|
||||
}
|
||||
best_row = png_ptr->avg_row;
|
||||
}
|
||||
|
||||
else if (filter_to_do & PNG_FILTER_AVG)
|
||||
{
|
||||
png_bytep rp, dp, pp, lp;
|
||||
png_uint_32 sum = 0, lmins = mins;
|
||||
@@ -1662,17 +1735,18 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
|
||||
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
|
||||
if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
|
||||
{
|
||||
int j;
|
||||
png_uint_32 lmhi, lmlo;
|
||||
lmlo = lmins & PNG_LOMASK;
|
||||
lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
|
||||
|
||||
for (i = 0; i < (png_uint_32)png_ptr->num_prev_filters; i++)
|
||||
for (j = 0; j < num_p_filters; j++)
|
||||
{
|
||||
if (png_ptr->prev_filters[i] == PNG_FILTER_VALUE_AVG)
|
||||
if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_AVG)
|
||||
{
|
||||
lmlo = (lmlo * png_ptr->inv_filter_weights[i]) >>
|
||||
lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
|
||||
PNG_WEIGHT_SHIFT;
|
||||
lmhi = (lmhi * png_ptr->inv_filter_weights[i]) >>
|
||||
lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
|
||||
PNG_WEIGHT_SHIFT;
|
||||
}
|
||||
}
|
||||
@@ -1690,16 +1764,16 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
|
||||
#endif
|
||||
|
||||
for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
|
||||
pp = prev_row + 1; i < bpp; i++, rp++, pp++, dp++)
|
||||
pp = prev_row + 1; i < bpp; i++)
|
||||
{
|
||||
v = *dp = (png_byte)(((int)*rp - ((int)*pp / 2)) & 0xff);
|
||||
v = *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
|
||||
|
||||
sum += (v < 128) ? v : 256 - v;
|
||||
}
|
||||
for (lp = row_buf + 1; i < row_info->rowbytes;
|
||||
i++, rp++, pp++, lp++, dp++)
|
||||
for (lp = row_buf + 1; i < row_bytes; i++)
|
||||
{
|
||||
v = *dp = (png_byte)(((int)*rp - (((int)*pp + (int)*lp) / 2)) & 0xff);
|
||||
v = *dp++ =
|
||||
(png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2)) & 0xff);
|
||||
|
||||
sum += (v < 128) ? v : 256 - v;
|
||||
|
||||
@@ -1710,17 +1784,18 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
|
||||
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
|
||||
if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
|
||||
{
|
||||
int j;
|
||||
png_uint_32 sumhi, sumlo;
|
||||
sumlo = sum & PNG_LOMASK;
|
||||
sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
|
||||
|
||||
for (i = 0; i < png_ptr->num_prev_filters; i++)
|
||||
for (j = 0; j < num_p_filters; j++)
|
||||
{
|
||||
if (png_ptr->prev_filters[i] == PNG_FILTER_NONE)
|
||||
if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
|
||||
{
|
||||
sumlo = (sumlo * png_ptr->filter_weights[i]) >>
|
||||
sumlo = (sumlo * png_ptr->filter_weights[j]) >>
|
||||
PNG_WEIGHT_SHIFT;
|
||||
sumhi = (sumhi * png_ptr->filter_weights[i]) >>
|
||||
sumhi = (sumhi * png_ptr->filter_weights[j]) >>
|
||||
PNG_WEIGHT_SHIFT;
|
||||
}
|
||||
}
|
||||
@@ -1745,7 +1820,45 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
|
||||
}
|
||||
|
||||
/* Paeth filter */
|
||||
if (png_ptr->do_filter & PNG_FILTER_PAETH)
|
||||
if (filter_to_do == PNG_FILTER_PAETH)
|
||||
{
|
||||
png_bytep rp, dp, pp, cp, lp;
|
||||
png_uint_32 i;
|
||||
for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
|
||||
pp = prev_row + 1; i < bpp; i++)
|
||||
{
|
||||
*dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
|
||||
}
|
||||
|
||||
for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
|
||||
{
|
||||
int a, b, c, pa, pb, pc, p;
|
||||
|
||||
b = *pp++;
|
||||
c = *cp++;
|
||||
a = *lp++;
|
||||
|
||||
p = b - c;
|
||||
pc = a - c;
|
||||
|
||||
#ifdef PNG_USE_ABS
|
||||
pa = abs(p);
|
||||
pb = abs(pc);
|
||||
pc = abs(p + pc);
|
||||
#else
|
||||
pa = p < 0 ? -p : p;
|
||||
pb = pc < 0 ? -pc : pc;
|
||||
pc = (p + pc) < 0 ? -(p + pc) : p + pc;
|
||||
#endif
|
||||
|
||||
p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
|
||||
|
||||
*dp++ = (png_byte)(((int)*rp++ - p) & 0xff);
|
||||
}
|
||||
best_row = png_ptr->paeth_row;
|
||||
}
|
||||
|
||||
else if (filter_to_do & PNG_FILTER_PAETH)
|
||||
{
|
||||
png_bytep rp, dp, pp, cp, lp;
|
||||
png_uint_32 sum = 0, lmins = mins;
|
||||
@@ -1755,17 +1868,18 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
|
||||
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
|
||||
if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
|
||||
{
|
||||
int j;
|
||||
png_uint_32 lmhi, lmlo;
|
||||
lmlo = lmins & PNG_LOMASK;
|
||||
lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
|
||||
|
||||
for (i = 0; i < png_ptr->num_prev_filters; i++)
|
||||
for (j = 0; j < num_p_filters; j++)
|
||||
{
|
||||
if (png_ptr->prev_filters[i] == PNG_FILTER_VALUE_PAETH)
|
||||
if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH)
|
||||
{
|
||||
lmlo = (lmlo * png_ptr->inv_filter_weights[i]) >>
|
||||
lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
|
||||
PNG_WEIGHT_SHIFT;
|
||||
lmhi = (lmhi * png_ptr->inv_filter_weights[i]) >>
|
||||
lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
|
||||
PNG_WEIGHT_SHIFT;
|
||||
}
|
||||
}
|
||||
@@ -1783,34 +1897,48 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
|
||||
#endif
|
||||
|
||||
for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
|
||||
pp = prev_row + 1; (unsigned)i < bpp; i++, rp++, pp++, dp++)
|
||||
pp = prev_row + 1; i < bpp; i++)
|
||||
{
|
||||
v = *dp = (png_byte)(((int)*rp - (int)*pp) & 0xff);
|
||||
v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
|
||||
|
||||
sum += (v < 128) ? v : 256 - v;
|
||||
}
|
||||
for (lp = row_buf + 1, cp = prev_row + 1; i < row_info->rowbytes;
|
||||
i++, rp++, pp++, lp++, dp++, cp++)
|
||||
|
||||
for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
|
||||
{
|
||||
int a, b, c, pa, pb, pc, p;
|
||||
|
||||
b = *pp;
|
||||
c = *cp;
|
||||
a = *lp;
|
||||
b = *pp++;
|
||||
c = *cp++;
|
||||
a = *lp++;
|
||||
|
||||
#ifndef PNG_SLOW_PAETH
|
||||
p = b - c;
|
||||
pc = a - c;
|
||||
#ifdef PNG_USE_ABS
|
||||
pa = abs(p);
|
||||
pb = abs(pc);
|
||||
pc = abs(p + pc);
|
||||
#else
|
||||
pa = p < 0 ? -p : p;
|
||||
pb = pc < 0 ? -pc : pc;
|
||||
pc = (p + pc) < 0 ? -(p + pc) : p + pc;
|
||||
#endif
|
||||
p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
|
||||
#else /* PNG_SLOW_PAETH */
|
||||
p = a + b - c;
|
||||
pa = abs(p - a);
|
||||
pb = abs(p - b);
|
||||
pc = abs(p - c);
|
||||
|
||||
if (pa <= pb && pa <= pc)
|
||||
p = a;
|
||||
else if (pb <= pc)
|
||||
p = b;
|
||||
else
|
||||
p = c;
|
||||
#endif /* PNG_SLOW_PAETH */
|
||||
|
||||
v = *dp = (png_byte)(((int)*rp - p) & 0xff);
|
||||
v = *dp++ = (png_byte)(((int)*rp++ - p) & 0xff);
|
||||
|
||||
sum += (v < 128) ? v : 256 - v;
|
||||
|
||||
@@ -1821,17 +1949,18 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
|
||||
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
|
||||
if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
|
||||
{
|
||||
int j;
|
||||
png_uint_32 sumhi, sumlo;
|
||||
sumlo = sum & PNG_LOMASK;
|
||||
sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
|
||||
|
||||
for (i = 0; i < png_ptr->num_prev_filters; i++)
|
||||
for (j = 0; j < num_p_filters; j++)
|
||||
{
|
||||
if (png_ptr->prev_filters[i] == PNG_FILTER_PAETH)
|
||||
if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH)
|
||||
{
|
||||
sumlo = (sumlo * png_ptr->filter_weights[i]) >>
|
||||
sumlo = (sumlo * png_ptr->filter_weights[j]) >>
|
||||
PNG_WEIGHT_SHIFT;
|
||||
sumhi = (sumhi * png_ptr->filter_weights[i]) >>
|
||||
sumhi = (sumhi * png_ptr->filter_weights[j]) >>
|
||||
PNG_WEIGHT_SHIFT;
|
||||
}
|
||||
}
|
||||
@@ -1855,19 +1984,19 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
|
||||
}
|
||||
|
||||
/* Do the actual writing of the filtered row data from the chosen filter. */
|
||||
|
||||
png_write_filtered_row(png_ptr, best_row);
|
||||
|
||||
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
|
||||
/* Save the type of filter we picked this time for future calculations */
|
||||
if (png_ptr->num_prev_filters > 0)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 1; i < (int)png_ptr->num_prev_filters; i++)
|
||||
int j;
|
||||
for (j = 1; j < num_p_filters; j++)
|
||||
{
|
||||
png_ptr->prev_filters[i] = png_ptr->prev_filters[i - 1];
|
||||
png_ptr->prev_filters[j] = png_ptr->prev_filters[j - 1];
|
||||
}
|
||||
png_ptr->prev_filters[i] = best_row[0];
|
||||
png_ptr->prev_filters[j] = best_row[0];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
Reference in New Issue
Block a user