summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ANNOUNCE36
-rw-r--r--CHANGES258
-rw-r--r--INSTALL18
-rw-r--r--KNOWNBUG2
-rw-r--r--LICENSE4
-rw-r--r--README14
-rwxr-xr-xconfigure20
-rw-r--r--configure.ac4
-rw-r--r--example.c20
-rw-r--r--libpng-1.4.0beta20.txt (renamed from libpng-1.4.0beta19.txt)6
-rw-r--r--libpng.3433
-rw-r--r--libpngpf.3510
-rw-r--r--png.52
-rw-r--r--png.c227
-rw-r--r--png.h119
-rw-r--r--pngconf.h89
-rw-r--r--pngerror.c115
-rw-r--r--pnggccrd.c5452
-rw-r--r--pngget.c130
-rw-r--r--pngmem.c115
-rw-r--r--pngpread.c228
-rw-r--r--pngpriv.h34
-rw-r--r--pngread.c216
-rw-r--r--pngrio.c17
-rw-r--r--pngrtran.c329
-rw-r--r--pngrutil.c356
-rw-r--r--pngset.c368
-rw-r--r--pngtest.c340
-rw-r--r--pngtrans.c35
-rw-r--r--pngvcrd.c3846
-rw-r--r--pngwio.c26
-rw-r--r--pngwrite.c154
-rw-r--r--pngwtran.c10
-rw-r--r--pngwutil.c304
-rw-r--r--scripts/CMakeLists.txt2
-rwxr-xr-xscripts/libpng-config-head.in2
-rw-r--r--scripts/libpng.pc.in2
-rw-r--r--scripts/makefile.32sunu2
-rw-r--r--scripts/makefile.64sunu2
-rw-r--r--scripts/makefile.aix2
-rw-r--r--scripts/makefile.beos2
-rw-r--r--scripts/makefile.cygwin2
-rw-r--r--scripts/makefile.darwin2
-rw-r--r--scripts/makefile.dec2
-rw-r--r--scripts/makefile.elf2
-rw-r--r--scripts/makefile.gcmmx2
-rw-r--r--scripts/makefile.hp642
-rw-r--r--scripts/makefile.hpgcc2
-rw-r--r--scripts/makefile.hpux2
-rw-r--r--scripts/makefile.linux2
-rw-r--r--scripts/makefile.mingw107
-rw-r--r--scripts/makefile.ne12bsd2
-rw-r--r--scripts/makefile.netbsd2
-rw-r--r--scripts/makefile.nommx2
-rw-r--r--scripts/makefile.openbsd2
-rw-r--r--scripts/makefile.sco2
-rw-r--r--scripts/makefile.sggcc2
-rw-r--r--scripts/makefile.sgi2
-rw-r--r--scripts/makefile.so92
-rw-r--r--scripts/makefile.solaris2
-rw-r--r--scripts/pngos2.def2
-rw-r--r--scripts/pngwin.def2
62 files changed, 2948 insertions, 11050 deletions
diff --git a/ANNOUNCE b/ANNOUNCE
index 3862264d5..6eae05014 100644
--- a/ANNOUNCE
+++ b/ANNOUNCE
@@ -1,5 +1,5 @@
-Libpng 1.4.0beta19 - May 15, 2007
+Libpng 1.4.0beta20 - July 10, 2008
This is not intended to be a public release. It will be replaced
within a few weeks by a public version or by another test version.
@@ -9,27 +9,27 @@ Files available for download:
Source files with LF line endings (for Unix/Linux) and with a
"configure" script
- 1.4.0beta19.tar.gz
- 1.4.0beta19.tar.bz2
+ 1.4.0beta20.tar.gz
+ 1.4.0beta20.tar.bz2
Source files with LF line endings (for Unix/Linux) without the
"configure" script
- 1.4.0beta19-no-config.tar.gz
- 1.4.0beta19-no-config.tar.bz2
+ 1.4.0beta20-no-config.tar.gz
+ 1.4.0beta20-no-config.tar.bz2
Source files with CRLF line endings (for Windows), without the
"configure" script
- lp140b19.zip
- lp140b19.tar.bz2
+ lp140b20.zip
+ lp140b20.tar.bz2
Other information:
- 1.4.0beta19-README.txt
- 1.4.0beta19-KNOWNBUGS.txt
- 1.4.0beta19-LICENSE.txt
- 1.4.0beta19-Y2K-compliance.txt
+ 1.4.0beta20-README.txt
+ 1.4.0beta20-KNOWNBUGS.txt
+ 1.4.0beta20-LICENSE.txt
+ 1.4.0beta20-Y2K-compliance.txt
Changes since the last public release (1.2.10):
@@ -235,14 +235,26 @@ version 1.4.0beta17 [December 4, 2006]
version 1.4.0beta18 [December 7, 2006]
Added scripts/CMakeLists.txt
-version 1.4.0beta19 [May 15, 2007]
+version 1.4.0beta19 [May 16, 2007]
Revised scripts/CMakeLists.txt
Rebuilt configure and Makefile.in with newer tools.
Added "png_ptr->num_trans=0" before error return in png_handle_tRNS,
to eliminate a vulnerability (CVE-2007-2554, CERT VU#684664)
+version 1.4.0beta20 [July 10, 2008]
+ Moved several PNG_HAVE_* macros from pngpriv.h to png.h because applications
+ calling set_unknown_chunk_location() need them.
+ Moved several macro definitions from pngpriv.h to pngconf.h
+ Added png_ptr->unknown_chunk to hold working unknown chunk data, so it
+ can be free'ed in case of error. Revised unknown chunk handling in
+ pngrutil.c and pngpread.c to use this structure.
+ Merge with changes to the 1.2.X branch, as of 1.2.19beta10.
+ Revised makefile.mingw
+ Prefer PNG_USE_PNGVCRD when _MSC_VER is defined in pngconf.h
+
version 1.4.0betaN [future]
Build shared libraries with -lz and sometimes -lm.
+ Revised pngvcrd.c for improved efficiency.
Send comments/corrections/commendations to png-mng-implement at lists.sf.net
(subscription required; visit
diff --git a/CHANGES b/CHANGES
index 70edb7572..1cbb35703 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1552,18 +1552,225 @@ version 1.2.10rc1 [April 19, 2006]
Ensure pngconf.h doesn't define both PNG_USE_PNGGCCRD and PNG_USE_PNGVCRD
Fixed "LN_FS" typo in makefile.sco and makefile.solaris.
-version 1.2.10rc2 [April 19, 2006]
+version 1.2.10rc2 [April 20, 2006]
Added a backslash between -DPNG_CONFIGURE_LIBPNG and -DPNG_NO_ASSEMBLER_CODE
in configure.ac and configure
Made the configure warning about versioned symbols less arrogant.
-version 1.2.10rc3 [April 20, 2006]
+version 1.2.10rc3 [April 21, 2006]
Added a note in libpng.txt that png_set_sig_bytes(8) can be used when
writing an embedded PNG without the 8-byte signature.
+ Revised makefiles and configure to avoid making links to libpng.so.*
version 1.2.10 [April 23, 2006]
Reverted configure to "rc2" state.
+version 1.2.11beta1 [May 31, 2006]
+ scripts/libpng.pc.in contained "configure" style version info and would
+ not work with makefiles.
+ The shared-library makefiles were linking to libpng.so.0 instead of
+ libpng.so.3 compatibility as the library.
+
+version 1.2.11beta2 [June 2, 2006]
+ Increased sprintf buffer from 50 to 52 chars in pngrutil.c to avoid
+ buffer overflow.
+ Fixed bug in example.c (png_set_palette_rgb -> png_set_palette_to_rgb)
+
+version 1.2.11beta3 [June 5, 2006]
+ Prepended "#! /bin/sh" to ltmail.sh and contrib/pngminus/*.sh (Cosmin).
+ Removed the accidental leftover Makefile.in~ (Cosmin).
+ Avoided potential buffer overflow and optimized buffer in
+ png_write_sCAL(), png_write_sCAL_s() (Cosmin).
+ Removed the include directories and libraries from CFLAGS and LDFLAGS
+ in scripts/makefile.gcc (Nelson A. de Oliveira, Cosmin).
+
+version 1.2.11beta4 [June 6, 2006]
+ Allow zero-length IDAT chunks after the entire zlib datastream, but not
+ after another intervening chunk type.
+
+version 1.0.19rc1, 1.2.11rc1 [June 13, 2006]
+ Deleted extraneous square brackets from [config.h] in configure.ac
+
+version 1.0.19rc2, 1.2.11rc2 [June 14, 2006]
+ Added prototypes for PNG_INCH_CONVERSIONS functions to png.h
+ Revised INSTALL and autogen.sh
+ Fixed typo in several makefiles (-W1 should be -Wl)
+ Added typedef for png_int_32 and png_uint_32 on 64-bit systems.
+
+version 1.0.19rc3, 1.2.11rc3 [June 15, 2006]
+ Removed the new typedefs for 64-bit systems (delay until version 1.4.0)
+ Added one zero element to png_gamma_shift[] array in pngrtran.c to avoid
+ reading out of bounds.
+
+version 1.0.19rc4, 1.2.11rc4 [June 15, 2006]
+ Really removed the new typedefs for 64-bit systems.
+
+version 1.0.19rc5, 1.2.11rc5 [June 22, 2006]
+ Removed png_sig_bytes entry from scripts/pngw32.def
+
+version 1.0.19, 1.2.11 [June 26, 2006]
+ None.
+
+version 1.0.20, 1.2.12 [June 27, 2006]
+ Really increased sprintf buffer from 50 to 52 chars in pngrutil.c to avoid
+ buffer overflow.
+
+version 1.2.13beta1 [October 2, 2006]
+ Removed AC_FUNC_MALLOC from configure.ac
+ Work around Intel-Mac compiler bug by setting PNG_NO_MMX_CODE in pngconf.h
+ Change "logical" to "bitwise" throughout documentation.
+ Detect and fix attempt to write wrong iCCP profile length.
+
+version 1.0.21, 1.2.13 [November 14, 2006]
+ Fix potential buffer overflow in sPLT chunk handler.
+ Fix Makefile.am to not try to link to noexistent files.
+ Check all exported functions for NULL png_ptr.
+
+version 1.2.14beta1 [November 17, 2006]
+ Relocated three misplaced tests for NULL png_ptr.
+ Built Makefile.in with automake-1.9.6 instead of 1.9.2.
+ Build configure with autoconf-2.60 instead of 2.59
+
+version 1.2.14beta2 [November 17, 2006]
+ Added some typecasts in png_zalloc().
+
+version 1.2.14rc1 [November 20, 2006]
+ Changed "strtod" to "png_strtod" in pngrutil.c
+
+version 1.0.22, 1.2.14 [November 27, 2006]
+ Added missing "$(srcdir)" in Makefile.am and Makefile.in
+
+version 1.2.15beta1 [December 3, 2006]
+ Generated configure with autoconf-2.61 instead of 2.60
+ Revised configure.ac to update libpng.pc and libpng-config.
+
+version 1.2.15beta2 [December 3, 2006]
+ Always export MMX asm functions, just stubs if not building pnggccrd.c
+
+version 1.2.15beta3 [December 4, 2006]
+ Add "png_bytep" typecast to profile while calculating length in pngwutil.c
+
+version 1.2.15beta4 [December 7, 2006]
+ Added scripts/CMakeLists.txt
+ Changed PNG_NO_ASSEMBLER_CODE to PNG_NO_MMX_CODE in scripts, like 1.4.0beta
+
+version 1.2.15beta5 [December 7, 2006]
+ Changed some instances of PNG_ASSEMBLER_* to PNG_MMX_* in pnggccrd.c
+ Revised scripts/CMakeLists.txt
+
+version 1.2.15beta6 [December 13, 2006]
+ Revised scripts/CMakeLists.txt and configure.ac
+
+version 1.2.15rc1 [December 18, 2006]
+ Revised scripts/CMakeLists.txt
+
+version 1.2.15rc2 [December 21, 2006]
+ Added conditional #undef jmpbuf in pngtest.c to undo #define in AIX headers.
+ Added scripts/makefile.nommx
+
+version 1.2.15rc3 [December 25, 2006]
+ Fixed shared library numbering error that was intruduced in 1.2.15beta6.
+
+version 1.2.15rc4 [December 27, 2006]
+ Fixed handling of rgb_to_gray when png_ptr->color.gray isn't set.
+
+version 1.2.15rc5 [December 31, 2006]
+ Revised handling of rgb_to_gray.
+
+version 1.2.15 [January 5, 2007]
+ Added some (unsigned long) typecasts in pngtest.c to avoid printing errors.
+
+version 1.2.16beta1 [January 6, 2007]
+ Fix bugs in makefile.nommx
+
+version 1.2.16beta2 [January 16, 2007]
+ Revised scripts/CMakeLists.txt
+
+version 1.2.16 [January 31, 2007]
+ No changes.
+
+version 1.2.17beta1 [March 6, 2007]
+ Revised scripts/CMakeLists.txt to install both shared and static libraries.
+ Deleted a redundant line from pngset.c.
+
+version 1.2.17beta2 [April 26, 2007]
+ Relocated misplaced test for png_ptr == NULL in pngpread.c
+ Change "==" to "&" for testing PNG_RGB_TO_GRAY_ERR & PNG_RGB_TO_GRAY_WARN
+ flags.
+ Changed remaining instances of PNG_ASSEMBLER_* to PNG_MMX_*
+ Added pngerror() when write_IHDR fails in deflateInit2().
+ Added "const" to some array declarations.
+ Mention examples of libpng usage in the libpng*.txt and libpng.3 documents.
+
+version 1.2.17rc1 [May 4, 2007]
+ No changes.
+
+version 1.2.17rc2 [May 8, 2007]
+ Moved several PNG_HAVE_* macros out of PNG_INTERNAL because applications
+ calling set_unknown_chunk_location() need them.
+ Changed transformation flag from PNG_EXPAND_tRNS to PNG_EXPAND in
+ png_set_expand_gray_1_2_4_to_8().
+ Added png_ptr->unknown_chunk to hold working unknown chunk data, so it
+ can be free'ed in case of error. Revised unknown chunk handling in
+ pngrutil.c and pngpread.c to use this structure.
+
+version 1.2.17rc3 [May 8, 2007]
+ Revised symbol-handling in configure script.
+
+version 1.2.17rc4 [May 10, 2007]
+ Revised unknown chunk handling to avoid storing unknown critical chunks.
+
+version 1.0.25 [May 15, 2007]
+version 1.2.17 [May 15, 2007]
+ Added "png_ptr->num_trans=0" before error return in png_handle_tRNS,
+ to eliminate a vulnerability (CVE-2007-2445, CERT VU#684664)
+
+version 1.0.26 [May 15, 2007]
+version 1.2.18 [May 15, 2007]
+ Reverted the libpng-1.2.17rc3 change to symbol-handling in configure script
+
+version 1.2.19beta1 [May 18, 2007]
+ Changed "const static" to "static PNG_CONST" everywhere, mostly undoing
+ change of libpng-1.2.17beta2. Changed other "const" to "PNG_CONST"
+ Changed some handling of unused parameters, to avoid compiler warnings.
+ "if (unused == NULL) return;" becomes "unused = unused".
+
+version 1.2.19beta2 [May 18, 2007]
+ Only use the valid bits of tRNS value in png_do_expand() (Brian Cartier)
+
+version 1.2.19beta3 [May 19, 2007]
+ Add some "png_byte" typecasts in png_check_keyword() and write new_key
+ instead of key in zTXt chunk (Kevin Ryde).
+
+version 1.2.19beta4 [May 21, 2007]
+ Add png_snprintf() function and use it in place of sprint() for improved
+ defense against buffer overflows.
+
+version 1.2.19beta5 [May 21, 2007]
+ Fixed png_handle_tRNS() to only use the valid bits of tRNS value.
+ Changed handling of more unused parameters, to avoid compiler warnings.
+ Removed some PNG_CONST in pngwutil.c to avoid compiler warnings.
+
+version 1.2.19beta6 [May 22, 2007]
+ Added some #ifdef PNG_MMX_CODE_SUPPORTED where needed in pngvcrd.c
+ Added a special "_MSC_VER" case that defines png_snprintf to _snprintf
+
+version 1.2.19beta7 [May 22, 2007]
+ Squelched png_squelch_warnings() in pnggccrd.c and added an
+ #ifdef PNG_MMX_CODE_SUPPORTED block around the declarations that caused
+ the warnings that png_squelch_warnings was squelching.
+
+version 1.2.19beta8 [May 22, 2007]
+ Removed __MMX__ from test in pngconf.h.
+
+version 1.2.19beta9 [May 23, 2007]
+ Made png_squelch_warnings() available via PNG_SQUELCH_WARNINGS macro.
+ Revised png_squelch_warnings() so it might work.
+ Updated makefile.sgcc and makefile.solaris; added makefile.solaris-x86.
+
+version 1.2.19beta10 [May 24, 2007]
+ Resquelched png_squelch_warnings(), use "__attribute__((used))" instead.
+
version 1.4.0beta1 [April 20, 2006]
Enabled iTXt support (changes png_struct, thus requires so-number change).
Cleaned up PNG_ASSEMBLER_CODE_SUPPORTED vs PNG_MMX_CODE_SUPPORTED
@@ -1597,47 +1804,12 @@ version 1.4.0beta5 [May 15, 2006]
Added a missing semicolon in Makefile.am and Makefile.in
Deleted extraneous square brackets from configure.ac
-version 1.2.11beta1 [May 31, 2006]
- scripts/libpng.pc.in contained "configure" style version info and would
- not work with makefiles.
- The shared-library makefiles were linking to libpng.so.0 instead of
- libpng.so.3 compatibility as the library.
-
-version 1.2.11beta2 [June 2, 2006]
- Increased sprintf buffer from 50 to 52 chars in pngrutil.c to avoid
- buffer overflow.
- Fixed bug in example.c (png_set_palette_rgb -> png_set_palette_to_rgb)
-
version 1.4.0beta6 [June 2, 2006]
Increased sprintf buffer from 50 to 52 chars in pngrutil.c to avoid
buffer overflow.
Changed sonum from 0 to 1.
Removed unused prototype for png_check_sig() from png.h
-version 1.2.11beta3 [June 5, 2006]
- Prepended "#! /bin/sh" to ltmail.sh and contrib/pngminus/*.sh (Cosmin).
- Removed the accidental leftover Makefile.in~ (Cosmin).
- Avoided potential buffer overflow and optimized buffer in
- png_write_sCAL(), png_write_sCAL_s() (Cosmin).
- Removed the include directories and libraries from CFLAGS and LDFLAGS
- in scripts/makefile.gcc (Nelson A. de Oliveira, Cosmin).
-
-version 1.2.11beta4 [June 6, 2006]
- Allow zero-length IDAT chunks after the entire zlib datastream, but not
- after another intervening chunk type.
-
-version 1.2.11rc1 [June 13, 2006]
- Deleted extraneous square brackets from [config.h] in configure.ac
-
-version 1.2.11rc2 [June 14, 2006]
- Added prototypes for PNG_INCH_CONVERSIONS functions to png.h
- Revised INSTALL and autogen.sh
- Fixed typo in several makefiles (-W1 should be -Wl)
-
-version 1.2.11rc3 [June 16, 2006]
- Added one zero element to png_gamma_shift[] array in pngrtran.c to avoid
- reading out of bounds.
-
version 1.4.0beta7 [June 16, 2006]
Exported png_write_sig (Cosmin).
Optimized buffer in png_handle_cHRM() (Cosmin).
@@ -1739,13 +1911,19 @@ version 1.4.0beta17 [December 4, 2006]
version 1.4.0beta18 [December 7, 2006]
Added scripts/CMakeLists.txt
-version 1.4.0beta19 [May 15, 2007]
+version 1.4.0beta19 [May 16, 2007]
Revised scripts/CMakeLists.txt
Rebuilt configure and Makefile.in with newer tools.
Added conditional #undef jmpbuf in pngtest.c to undo #define in AIX headers.
Added scripts/makefile.nommx
- Added "png_ptr->num_trans=0" before error return in png_handle_tRNS,
- to eliminate a vulnerability (CVE-2007-2554, CERT VU#684664)
+
+version 1.4.0beta20 [July 10, 2008]
+ Moved several PNG_HAVE_* macros from pngpriv.h to png.h because applications
+ calling set_unknown_chunk_location() need them.
+ Moved several macro definitions from pngpriv.h to pngconf.h
+ Merge with changes to the 1.2.X branch, as of 1.2.19beta10.
+ Revised makefile.mingw
+ Prefer PNG_USE_PNGVCRD when _MSC_VER is defined in pngconf.h
version 1.4.0betaN [future]
Build shared libraries with -lz and sometimes -lm.
diff --git a/INSTALL b/INSTALL
index 5af1d6f91..ad0b8b348 100644
--- a/INSTALL
+++ b/INSTALL
@@ -1,5 +1,5 @@
-Installing libpng version 1.4.0beta19 - May 15, 2007
+Installing libpng version 1.4.0beta20 - July 10, 2008
On Unix/Linux and similar systems, you can simply type
@@ -44,7 +44,7 @@ to have access to the 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.4.0beta19" or "lpng109" and "zlib-1.2.1"
+might be called "libpng-1.4.0beta20" or "lpng109" and "zlib-1.2.1"
or "zlib121") so that you have directories called "zlib" and "libpng".
Your directory structure should look like this:
@@ -95,14 +95,14 @@ include
CMakeLists.txt => "cmake" script
makefile.std => Generic UNIX makefile (cc, creates static libpng.a)
makefile.elf => Linux/ELF makefile symbol versioning,
- gcc, creates libpng14.so.1.1.4.0beta19)
+ gcc, creates libpng14.so.1.1.4.0beta20)
makefile.linux => Linux/ELF makefile
- (gcc, creates libpng14.so.1.1.4.0beta19)
+ (gcc, creates libpng14.so.1.1.4.0beta20)
makefile.gcmmx => Linux/ELF makefile
- (gcc, creates libpng14.so.1.1.4.0beta19,
+ (gcc, creates libpng14.so.1.1.4.0beta20,
uses assembler code tuned for Intel MMX platform)
makefile.nommx => Linux/ELF makefile
- (gcc, creates libpng14.so.1.1.4.0beta19
+ (gcc, creates libpng14.so.1.1.4.0beta20
does not use Intel MMX assembler code)
makefile.gcc => Generic makefile (gcc, creates static libpng.a)
makefile.knr => Archaic UNIX Makefile that converts files with
@@ -125,12 +125,12 @@ include
makefile.openbsd => OpenBSD makefile
makefile.sgi => Silicon Graphics IRIX makefile (cc, creates static lib)
makefile.sggcc => Silicon Graphics (gcc,
- creates libpng14.so.1.1.4.0beta19)
+ creates libpng14.so.1.1.4.0beta20)
makefile.sunos => Sun makefile
makefile.solaris => Solaris 2.X makefile (gcc,
- creates libpng14.so.1.1.4.0beta19)
+ creates libpng14.so.1.1.4.0beta20)
makefile.so9 => Solaris 9 makefile (gcc,
- creates libpng14.so.1.1.4.0beta19)
+ creates libpng14.so.1.1.4.0beta20)
makefile.32sunu => Sun Ultra 32-bit makefile
makefile.64sunu => Sun Ultra 64-bit makefile
makefile.sco => For SCO OSr5 ELF and Unixware 7 with Native cc
diff --git a/KNOWNBUG b/KNOWNBUG
index 8b36434dc..5fddefb61 100644
--- a/KNOWNBUG
+++ b/KNOWNBUG
@@ -1,5 +1,5 @@
-Known bugs in libpng version 1.4.0beta19
+Known bugs in libpng version 1.4.0beta20
1. April 22, 2001: pnggccrd.c has been reported to crash on NetBSD when
reading interlaced PNG files, when assembler code is enabled but running
diff --git a/LICENSE b/LICENSE
index a73a34576..c4ff63bb6 100644
--- a/LICENSE
+++ b/LICENSE
@@ -8,7 +8,7 @@ COPYRIGHT NOTICE, DISCLAIMER, and LICENSE:
If you modify libpng you may insert additional notices immediately following
this sentence.
-libpng versions 1.2.6, August 15, 2004, through 1.4.0beta19, May 15, 2007, are
+libpng versions 1.2.6, August 15, 2004, through 1.4.0beta20, July 10, 2008, are
Copyright (c) 2004, 2006-2007 Glenn Randers-Pehrson, and are
distributed according to the same disclaimer and license as libpng-1.2.5
with the following individual added to the list of Contributing Authors
@@ -106,4 +106,4 @@ certification mark of the Open Source Initiative.
Glenn Randers-Pehrson
glennrp at users.sourceforge.net
-May 15, 2007
+July 10, 2008
diff --git a/README b/README
index f607d5079..a91846163 100644
--- a/README
+++ b/README
@@ -1,4 +1,4 @@
-README for libpng version 1.4.0beta19 - May 15, 2007 (shared library 14.0)
+README for libpng version 1.4.0beta20 - July 10, 2008 (shared library 14.0)
See the note about version numbers near the top of png.h
See INSTALL for instructions on how to install libpng.
@@ -184,11 +184,11 @@ Files in this distribution:
descrip.mms => VMS makefile for MMS or MMK
makefile.std => Generic UNIX makefile (cc, creates static libpng.a)
makefile.elf => Linux/ELF makefile symbol versioning,
- gcc, creates libpng14.so.1.1.4.0beta19)
+ gcc, creates libpng14.so.1.1.4.0beta20)
makefile.linux => Linux/ELF makefile
- (gcc, creates libpng14.so.1.1.4.0beta19)
+ (gcc, creates libpng14.so.1.1.4.0beta20)
makefile.gcmmx => Linux/ELF makefile
- (gcc, creates libpng14.so.1.1.4.0beta19,
+ (gcc, creates libpng14.so.1.1.4.0beta20,
uses assembler code tuned for Intel MMX platform)
makefile.gcc => Generic makefile (gcc, creates static libpng.a)
makefile.knr => Archaic UNIX Makefile that converts files with
@@ -210,12 +210,12 @@ Files in this distribution:
makefile.openbsd => OpenBSD makefile
makefile.sgi => Silicon Graphics IRIX (cc, creates static lib)
makefile.sggcc => Silicon Graphics
- (gcc, creates libpng14.so.1.1.4.0beta19)
+ (gcc, creates libpng14.so.1.1.4.0beta20)
makefile.sunos => Sun makefile
makefile.solaris => Solaris 2.X makefile
- (gcc, creates libpng14.so.1.1.4.0beta19)
+ (gcc, creates libpng14.so.1.1.4.0beta20)
makefile.so9 => Solaris 9 makefile
- (gcc, creates libpng14.so.1.1.4.0beta19)
+ (gcc, creates libpng14.so.1.1.4.0beta20)
makefile.32sunu => Sun Ultra 32-bit makefile
makefile.64sunu => Sun Ultra 64-bit makefile
makefile.sco => For SCO OSr5 ELF and Unixware 7 with Native cc
diff --git a/configure b/configure
index 925d371bf..21056c086 100755
--- a/configure
+++ b/configure
@@ -728,8 +728,8 @@ SHELL=${CONFIG_SHELL-/bin/sh}
# Identity of this package.
PACKAGE_NAME='libpng'
PACKAGE_TARNAME='libpng'
-PACKAGE_VERSION='1.4.0beta19'
-PACKAGE_STRING='libpng 1.4.0beta19'
+PACKAGE_VERSION='1.4.0beta20'
+PACKAGE_STRING='libpng 1.4.0beta20'
PACKAGE_BUGREPORT='png-mng-implement@lists.sourceforge.net'
ac_unique_file="pngget.c"
@@ -1404,7 +1404,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
-\`configure' configures libpng 1.4.0beta19 to adapt to many kinds of systems.
+\`configure' configures libpng 1.4.0beta20 to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]...
@@ -1474,7 +1474,7 @@ fi
if test -n "$ac_init_help"; then
case $ac_init_help in
- short | recursive ) echo "Configuration of libpng 1.4.0beta19:";;
+ short | recursive ) echo "Configuration of libpng 1.4.0beta20:";;
esac
cat <<\_ACEOF
@@ -1584,7 +1584,7 @@ fi
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
-libpng configure 1.4.0beta19
+libpng configure 1.4.0beta20
generated by GNU Autoconf 2.61
Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
@@ -1598,7 +1598,7 @@ cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
-It was created by libpng $as_me 1.4.0beta19, which was
+It was created by libpng $as_me 1.4.0beta20, which was
generated by GNU Autoconf 2.61. Invocation command line was
$ $0 $@
@@ -2268,7 +2268,7 @@ fi
# Define the identity of the package.
PACKAGE='libpng'
- VERSION='1.4.0beta19'
+ VERSION='1.4.0beta20'
cat >>confdefs.h <<_ACEOF
@@ -2439,7 +2439,7 @@ fi
-PNGLIB_VERSION=1.4.0beta19
+PNGLIB_VERSION=1.4.0beta20
PNGLIB_MAJOR=14
PNGLIB_MINOR=0
@@ -21119,7 +21119,7 @@ exec 6>&1
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
-This file was extended by libpng $as_me 1.4.0beta19, which was
+This file was extended by libpng $as_me 1.4.0beta20, which was
generated by GNU Autoconf 2.61. Invocation command line was
CONFIG_FILES = $CONFIG_FILES
@@ -21172,7 +21172,7 @@ Report bugs to <bug-autoconf@gnu.org>."
_ACEOF
cat >>$CONFIG_STATUS <<_ACEOF
ac_cs_version="\\
-libpng config.status 1.4.0beta19
+libpng config.status 1.4.0beta20
configured by $0, generated by GNU Autoconf 2.61,
with options \\"`echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`\\"
diff --git a/configure.ac b/configure.ac
index 8a2fd555a..37db294a3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -18,12 +18,12 @@ AC_PREREQ(2.59)
dnl Version number stuff here:
-AC_INIT([libpng], [1.4.0beta19], [png-mng-implement@lists.sourceforge.net])
+AC_INIT([libpng], [1.4.0beta20], [png-mng-implement@lists.sourceforge.net])
AM_INIT_AUTOMAKE
dnl stop configure from automagically running automake
AM_MAINTAINER_MODE
-PNGLIB_VERSION=1.4.0beta19
+PNGLIB_VERSION=1.4.0beta20
PNGLIB_MAJOR=14
PNGLIB_MINOR=0
diff --git a/example.c b/example.c
index 4cd7148e8..b04411b66 100644
--- a/example.c
+++ b/example.c
@@ -2,9 +2,9 @@
#if 0 /* in case someone actually tries to compile this */
/* example.c - an example of using libpng
- * Last changed in libpng 1.2.1 December 7, 2001.
+ * Last changed in libpng 1.4.0 [July 10, 2008]
* This file has been placed in the public domain by the authors.
- * Maintained 1998-2001 Glenn Randers-Pehrson
+ * Maintained 1998-2008 Glenn Randers-Pehrson
* Maintained 1996, 1997 Andreas Dilger)
* Written 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*/
@@ -70,7 +70,7 @@ int check_if_png(char *file_name, FILE **fp)
/* Compare the first PNG_BYTES_TO_CHECK bytes of the signature.
Return nonzero (true) if they match */
- return(!png_sig_cmp(buf, 0, PNG_BYTES_TO_CHECK));
+ 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
@@ -367,9 +367,11 @@ void read_png(FILE *fp, unsigned int sig_read) /* file is already open */
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[y], NULL, number_of_rows);
+ png_read_rows(png_ptr, &row_pointers[y], NULL,
+ number_of_rows);
#else no_sparkle /* Read the image using the "rectangle" effect */
- png_read_rows(png_ptr, NULL, &row_pointers[y], 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 */
}
@@ -503,7 +505,7 @@ row_callback(png_structp png_ptr, png_bytep new_row,
* shown below:
*/
/* Check if row_num is in bounds. */
- if((row_num >= 0) && (row_num < height))
+ if ((row_num >= 0) && (row_num < height))
{
/* Get pointer to corresponding row in our
* PNG read buffer.
@@ -513,7 +515,7 @@ row_callback(png_structp png_ptr, png_bytep new_row,
/* If both rows are allocated then copy the new row
* data to the corresponding row data.
*/
- if((old_row != NULL) && (new_row != NULL))
+ if ((old_row != NULL) && (new_row != NULL))
png_progressive_combine_row(png_ptr, old_row, new_row);
}
/*
@@ -635,7 +637,7 @@ void write_png(char *file_name /* , ... other image information ... */)
/* set the palette if there is one. REQUIRED for indexed-color images */
palette = (png_colorp)png_malloc(png_ptr, PNG_MAX_PALETTE_LENGTH
- * sizeof (png_color));
+ * png_sizeof(png_color));
/* ... set palette colors ... */
png_set_PLTE(png_ptr, info_ptr, palette, PNG_MAX_PALETTE_LENGTH);
/* You must not free palette here, because png_set_PLTE only makes a link to
@@ -746,7 +748,7 @@ void write_png(char *file_name /* , ... other image information ... */)
png_byte image[height][width*bytes_per_pixel];
png_bytep row_pointers[height];
- if (height > PNG_UINT_32_MAX/sizeof(png_bytep))
+ if (height > PNG_UINT_32_MAX/png_sizeof(png_bytep))
png_error (png_ptr, "Image is too tall to process in memory");
for (k = 0; k < height; k++)
diff --git a/libpng-1.4.0beta19.txt b/libpng-1.4.0beta20.txt
index 8d95186a7..5dc202e06 100644
--- a/libpng-1.4.0beta19.txt
+++ b/libpng-1.4.0beta20.txt
@@ -1,6 +1,6 @@
libpng.txt - A description on how to use and modify libpng
- libpng version 1.4.0beta19 - May 15, 2007
+ libpng version 1.4.0beta20 - July 10, 2008
Updated and distributed by Glenn Randers-Pehrson
<glennrp at users.sourceforge.net>
Copyright (c) 1998-2005 Glenn Randers-Pehrson
@@ -2917,13 +2917,13 @@ application:
IX. Y2K Compliance in libpng
-May 15, 2007
+July 10, 2008
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.71 and
-upward through 1.4.0beta19 are Y2K compliant. It is my belief that earlier
+upward through 1.4.0beta20 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
diff --git a/libpng.3 b/libpng.3
index 29da2b707..b82ee11f2 100644
--- a/libpng.3
+++ b/libpng.3
@@ -1,392 +1,791 @@
-.TH LIBPNG 3 "May 15, 2007"
+.TH LIBPNG 3 "July 10, 2008"
.SH NAME
-libpng \- Portable Network Graphics (PNG) Reference Library 1.4.0beta19
+libpng \- Portable Network Graphics (PNG) Reference Library 1.4.0beta20
.SH SYNOPSIS
-\fB
-#include <png.h>\fP
+\fI\fB
+
+\fB#include <png.h>\fP
+
+\fI\fB
\fBpng_uint_32 png_access_version_number \fI(void\fP\fB);\fP
+\fI\fB
+
\fBvoid png_benign_error (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fIerror\fP\fB);\fP
+\fI\fB
+
\fBvoid png_chunk_benign_error (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fIerror\fP\fB);\fP
+\fI\fB
+
\fBint png_check_sig (png_bytep \fP\fIsig\fP\fB, int \fInum\fP\fB);\fP
+\fI\fB
+
\fBvoid png_chunk_error (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fIerror\fP\fB);\fP
+\fI\fB
+
\fBvoid png_chunk_warning (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fImessage\fP\fB);\fP
+\fI\fB
+
\fBvoid png_convert_from_struct_tm (png_timep \fP\fIptime\fP\fB, struct tm FAR * \fIttime\fP\fB);\fP
+\fI\fB
+
\fBvoid png_convert_from_time_t (png_timep \fP\fIptime\fP\fB, time_t \fIttime\fP\fB);\fP
+\fI\fB
+
\fBpng_charp png_convert_to_rfc1123 (png_structp \fP\fIpng_ptr\fP\fB, png_timep \fIptime\fP\fB);\fP
+\fI\fB
+
\fBpng_infop png_create_info_struct (png_structp \fIpng_ptr\fP\fB);\fP
+\fI\fB
+
\fBpng_structp png_create_read_struct (png_const_charp \fP\fIuser_png_ver\fP\fB, png_voidp \fP\fIerror_ptr\fP\fB, png_error_ptr \fP\fIerror_fn\fP\fB, png_error_ptr \fIwarn_fn\fP\fB);\fP
+\fI\fB
+
\fBpng_structp png_create_read_struct_2(png_const_charp \fP\fIuser_png_ver\fP\fB, png_voidp \fP\fIerror_ptr\fP\fB, png_error_ptr \fP\fIerror_fn\fP\fB, png_error_ptr \fP\fIwarn_fn\fP\fB, png_voidp \fP\fImem_ptr\fP\fB, png_malloc_ptr \fP\fImalloc_fn\fP\fB, png_free_ptr \fIfree_fn\fP\fB);\fP
+\fI\fB
+
\fBpng_structp png_create_write_struct (png_const_charp \fP\fIuser_png_ver\fP\fB, png_voidp \fP\fIerror_ptr\fP\fB, png_error_ptr \fP\fIerror_fn\fP\fB, png_error_ptr \fIwarn_fn\fP\fB);\fP
+\fI\fB
+
\fBpng_structp png_create_write_struct_2(png_const_charp \fP\fIuser_png_ver\fP\fB, png_voidp \fP\fIerror_ptr\fP\fB, png_error_ptr \fP\fIerror_fn\fP\fB, png_error_ptr \fP\fIwarn_fn\fP\fB, png_voidp \fP\fImem_ptr\fP\fB, png_malloc_ptr \fP\fImalloc_fn\fP\fB, png_free_ptr \fIfree_fn\fP\fB);\fP
+\fI\fB
+
\fBint png_debug(int \fP\fIlevel\fP\fB, png_const_charp \fImessage\fP\fB);\fP
+\fI\fB
+
\fBint png_debug1(int \fP\fIlevel\fP\fB, png_const_charp \fP\fImessage\fP\fB, \fIp1\fP\fB);\fP
+\fI\fB
+
\fBint png_debug2(int \fP\fIlevel\fP\fB, png_const_charp \fP\fImessage\fP\fB, \fP\fIp1\fP\fB, \fIp2\fP\fB);\fP
+\fI\fB
+
\fBvoid png_destroy_info_struct (png_structp \fP\fIpng_ptr\fP\fB, png_infopp \fIinfo_ptr_ptr\fP\fB);\fP
+\fI\fB
+
\fBvoid png_destroy_read_struct (png_structpp \fP\fIpng_ptr_ptr\fP\fB, png_infopp \fP\fIinfo_ptr_ptr\fP\fB, png_infopp \fIend_info_ptr_ptr\fP\fB);\fP
+\fI\fB
+
\fBvoid png_destroy_write_struct (png_structpp \fP\fIpng_ptr_ptr\fP\fB, png_infopp \fIinfo_ptr_ptr\fP\fB);\fP
+\fI\fB
+
\fBvoid png_error (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fIerror\fP\fB);\fP
+\fI\fB
+
\fBvoid png_free (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fIptr\fP\fB);\fP
+\fI\fB
+
\fBvoid png_free_chunk_list (png_structp \fIpng_ptr\fP\fB);\fP
+\fI\fB
+
\fBvoid png_free_default(png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fIptr\fP\fB);\fP
+\fI\fB
+
\fBvoid png_free_data (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fInum\fP\fB);\fP
+\fI\fB
+
\fBpng_byte png_get_bit_depth (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+\fI\fB
+
\fBpng_uint_32 png_get_bKGD (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_color_16p \fI*background\fP\fB);\fP
+\fI\fB
+
\fBpng_byte png_get_channels (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+\fI\fB
+
\fBpng_uint_32 png_get_cHRM (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, double \fP\fI*white_x\fP\fB, double \fP\fI*white_y\fP\fB, double \fP\fI*red_x\fP\fB, double \fP\fI*red_y\fP\fB, double \fP\fI*green_x\fP\fB, double \fP\fI*green_y\fP\fB, double \fP\fI*blue_x\fP\fB, double \fI*blue_y\fP\fB);\fP
+\fI\fB
+
\fBpng_uint_32 png_get_cHRM_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fI*white_x\fP\fB, png_uint_32 \fP\fI*white_y\fP\fB, png_uint_32 \fP\fI*red_x\fP\fB, png_uint_32 \fP\fI*red_y\fP\fB, png_uint_32 \fP\fI*green_x\fP\fB, png_uint_32 \fP\fI*green_y\fP\fB, png_uint_32 \fP\fI*blue_x\fP\fB, png_uint_32 \fI*blue_y\fP\fB);\fP
+\fI\fB
+
\fBpng_byte png_get_color_type (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+\fI\fB
+
\fBpng_byte png_get_compression_type (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+\fI\fB
+
\fBpng_byte png_get_copyright (png_structp \fIpng_ptr\fP\fB);\fP
+\fI\fB
+
\fBpng_voidp png_get_error_ptr (png_structp \fIpng_ptr\fP\fB);\fP
+\fI\fB
+
\fBpng_byte png_get_filter_type (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+\fI\fB
+
\fBpng_uint_32 png_get_gAMA (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, double \fI*file_gamma\fP\fB);\fP
+\fI\fB
+
\fBpng_uint_32 png_get_gAMA_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fI*int_file_gamma\fP\fB);\fP
+\fI\fB
+
\fBpng_byte png_get_header_ver (png_structp \fIpng_ptr\fP\fB);\fP
+\fI\fB
+
\fBpng_byte png_get_header_version (png_structp \fIpng_ptr\fP\fB);\fP
+\fI\fB
+
\fBpng_uint_32 png_get_hIST (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_16p \fI*hist\fP\fB);\fP
+\fI\fB
+
\fBpng_uint_32 png_get_iCCP (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_charpp \fP\fIname\fP\fB, int \fP\fI*compression_type\fP\fB, png_charpp \fP\fIprofile\fP\fB, png_uint_32 \fI*proflen\fP\fB);\fP
+\fI\fB
+
\fBpng_uint_32 png_get_IHDR (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fI*width\fP\fB, png_uint_32 \fP\fI*height\fP\fB, int \fP\fI*bit_depth\fP\fB, int \fP\fI*color_type\fP\fB, int \fP\fI*interlace_type\fP\fB, int \fP\fI*compression_type\fP\fB, int \fI*filter_type\fP\fB);\fP
+\fI\fB
+
\fBpng_uint_32 png_get_image_height (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+\fI\fB
+
\fBpng_uint_32 png_get_image_width (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
-\fB#if !defined(PNG_1_0_X) png_int_32 png_get_int_32 (png_bytep buf); \fI#endif
+\fI\fB
+
+\fB#if \fI!defined(PNG_1_0_X)
+
+\fBpng_int_32 png_get_int_32 (png_bytep \fIbuf\fP\fB);\fP
+
+\fI\fB#endif
+
+\fI\fB
\fBpng_byte png_get_interlace_type (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+\fI\fB
+
\fBpng_voidp png_get_io_ptr (png_structp \fIpng_ptr\fP\fB);\fP
+\fI\fB
+
\fBpng_byte png_get_libpng_ver (png_structp \fIpng_ptr\fP\fB);\fP
+\fI\fB
+
\fBpng_voidp png_get_mem_ptr(png_structp \fIpng_ptr\fP\fB);\fP
+\fI\fB
+
\fBpng_uint_32 png_get_oFFs (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fI*offset_x\fP\fB, png_uint_32 \fP\fI*offset_y\fP\fB, int \fI*unit_type\fP\fB);\fP
+\fI\fB
+
\fBpng_uint_32 png_get_pCAL (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_charp \fP\fI*purpose\fP\fB, png_int_32 \fP\fI*X0\fP\fB, png_int_32 \fP\fI*X1\fP\fB, int \fP\fI*type\fP\fB, int \fP\fI*nparams\fP\fB, png_charp \fP\fI*units\fP\fB, png_charpp \fI*params\fP\fB);\fP
+\fI\fB
+
\fBpng_uint_32 png_get_pHYs (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fI*res_x\fP\fB, png_uint_32 \fP\fI*res_y\fP\fB, int \fI*unit_type\fP\fB);\fP
+\fI\fB
+
\fBfloat png_get_pixel_aspect_ratio (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+\fI\fB
+
\fBpng_uint_32 png_get_pixels_per_meter (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+\fI\fB
+
\fBpng_voidp png_get_progressive_ptr (png_structp \fIpng_ptr\fP\fB);\fP
+\fI\fB
+
\fBpng_uint_32 png_get_PLTE (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_colorp \fP\fI*palette\fP\fB, int \fI*num_palette\fP\fB);\fP
-\fBpng_byte png_get_rgb_to_gray_status (png_structp png_ptr) png_uint_32 png_get_rowbytes (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+\fI\fB
+
+\fBpng_byte png_get_rgb_to_gray_status (png_structp \fIpng_ptr)
+
+\fBpng_uint_32 png_get_rowbytes (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+
+\fI\fB
\fBpng_bytepp png_get_rows (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+\fI\fB
+
\fBpng_uint_32 png_get_sBIT (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_color_8p \fI*sig_bit\fP\fB);\fP
+\fI\fB
+
\fBpng_bytep png_get_signature (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+\fI\fB
+
\fBpng_uint_32 png_get_sPLT (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_spalette_p \fI*splt_ptr\fP\fB);\fP
+\fI\fB
+
\fBpng_uint_32 png_get_sRGB (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fI*intent\fP\fB);\fP
+\fI\fB
+
\fBpng_uint_32 png_get_text (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_textp \fP\fI*text_ptr\fP\fB, int \fI*num_text\fP\fB);\fP
+\fI\fB
+
\fBpng_uint_32 png_get_tIME (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_timep \fI*mod_time\fP\fB);\fP
+\fI\fB
+
\fBpng_uint_32 png_get_tRNS (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_bytep \fP\fI*trans\fP\fB, int \fP\fI*num_trans\fP\fB, png_color_16p \fI*trans_values\fP\fB);\fP
-\fB#if !defined(PNG_1_0_X) png_uint_16 png_get_uint_16 (png_bytep \fIbuf\fP\fB);\fP
+\fI\fB
+
+\fB#if \fI!defined(PNG_1_0_X)
+
+\fBpng_uint_16 png_get_uint_16 (png_bytep \fIbuf\fP\fB);\fP
+
+\fI\fB
\fBpng_uint_32 png_get_uint_31 (png_bytep \fIbuf\fP\fB);\fP
-\fBpng_uint_32 png_get_uint_32 (png_bytep buf); \fI#endif
+\fI\fB
+
+\fBpng_uint_32 png_get_uint_32 (png_bytep \fIbuf\fP\fB);\fP
+
+\fI\fB#endif
+
+\fI\fB
\fBpng_uint_32 png_get_unknown_chunks (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_unknown_chunkpp \fIunknowns\fP\fB);\fP
+\fI\fB
+
\fBpng_voidp png_get_user_chunk_ptr (png_structp \fIpng_ptr\fP\fB);\fP
+\fI\fB
+
\fBpng_uint_32 png_get_user_height_max( png_structp \fIpng_ptr\fP\fB);\fP
+\fI\fB
+
\fBpng_voidp png_get_user_transform_ptr (png_structp \fIpng_ptr\fP\fB);\fP
+\fI\fB
+
\fBpng_uint_32 png_get_user_width_max (png_structp \fIpng_ptr\fP\fB);\fP
+\fI\fB
+
\fBpng_uint_32 png_get_valid (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIflag\fP\fB);\fP
+\fI\fB
+
\fBpng_int_32 png_get_x_offset_microns (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+\fI\fB
+
\fBpng_int_32 png_get_x_offset_pixels (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+\fI\fB
+
\fBpng_uint_32 png_get_x_pixels_per_meter (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+\fI\fB
+
\fBpng_int_32 png_get_y_offset_microns (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+\fI\fB
+
\fBpng_int_32 png_get_y_offset_pixels (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+\fI\fB
+
\fBpng_uint_32 png_get_y_pixels_per_meter (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+\fI\fB
+
\fBpng_uint_32 png_get_compression_buffer_size (png_structp \fIpng_ptr\fP\fB);\fP
+\fI\fB
+
\fBint png_handle_as_unknown (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fIchunk_name\fP\fB);\fP
+\fI\fB
+
\fBvoid png_init_io (png_structp \fP\fIpng_ptr\fP\fB, FILE \fI*fp\fP\fB);\fP
+\fI\fB
+
\fBpng_voidp png_malloc (png_structp \fP\fIpng_ptr\fP\fB, png_alloc_size_t \fIsize\fP\fB);\fP
+\fI\fB
+
\fBpng_voidp png_malloc_default(png_structp \fP\fIpng_ptr\fP\fB, png_alloc_size_t \fIsize\fP\fB);\fP
+\fI\fB
+
\fBvoidp png_memcpy (png_voidp \fP\fIs1\fP\fB, png_voidp \fP\fIs2\fP\fB, png_size_t \fIsize\fP\fB);\fP
+\fI\fB
+
\fBvoidp png_memset (png_voidp \fP\fIs1\fP\fB, int \fP\fIvalue\fP\fB, png_size_t \fIsize\fP\fB);\fP
+\fI\fB
+
\fBvoid png_process_data (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_bytep \fP\fIbuffer\fP\fB, png_size_t \fIbuffer_size\fP\fB);\fP
+\fI\fB
+
\fBvoid png_progressive_combine_row (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIold_row\fP\fB, png_bytep \fInew_row\fP\fB);\fP
+\fI\fB
+
\fBvoid png_read_destroy (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_infop \fIend_info_ptr\fP\fB);\fP
+\fI\fB
+
\fBvoid png_read_end (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+\fI\fB
+
\fBvoid png_read_image (png_structp \fP\fIpng_ptr\fP\fB, png_bytepp \fIimage\fP\fB);\fP
+\fI\fB
+
\fBvoid png_read_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+\fI\fB
+
\fBvoid png_read_png (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fP\fItransforms\fP\fB, png_voidp \fIparams\fP\fB);\fP
+\fI\fB
+
\fBvoid png_read_row (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIrow\fP\fB, png_bytep \fIdisplay_row\fP\fB);\fP
+\fI\fB
+
\fBvoid png_read_rows (png_structp \fP\fIpng_ptr\fP\fB, png_bytepp \fP\fIrow\fP\fB, png_bytepp \fP\fIdisplay_row\fP\fB, png_uint_32 \fInum_rows\fP\fB);\fP
+\fI\fB
+
\fBvoid png_read_update_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
-\fB#if !defined(PNG_1_0_X) png_save_int_32 (png_bytep \fP\fIbuf\fP\fB, png_int_32 \fIi\fP\fB);\fP
+\fI\fB
+
+\fB#if \fI!defined(PNG_1_0_X)
+
+\fBpng_save_int_32 (png_bytep \fP\fIbuf\fP\fB, png_int_32 \fIi\fP\fB);\fP
+
+\fI\fB
\fBvoid png_save_uint_16 (png_bytep \fP\fIbuf\fP\fB, unsigned int \fIi\fP\fB);\fP
+\fI\fB
+
\fBvoid png_save_uint_32 (png_bytep \fP\fIbuf\fP\fB, png_uint_32 \fIi\fP\fB);\fP
-\fBvoid png_set_add_alpha (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIfiller\fP\fB, int flags); \fI#endif
+\fI\fB
+
+\fBvoid png_set_add_alpha (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIfiller\fP\fB, int \fIflags\fP\fB);\fP
+
+\fI\fB#endif
+
+\fI\fB
\fBvoid png_set_background (png_structp \fP\fIpng_ptr\fP\fB, png_color_16p \fP\fIbackground_color\fP\fB, int \fP\fIbackground_gamma_code\fP\fB, int \fP\fIneed_expand\fP\fB, double \fIbackground_gamma\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_bgr (png_structp \fIpng_ptr\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_bKGD (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_color_16p \fIbackground\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_cHRM (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, double \fP\fIwhite_x\fP\fB, double \fP\fIwhite_y\fP\fB, double \fP\fIred_x\fP\fB, double \fP\fIred_y\fP\fB, double \fP\fIgreen_x\fP\fB, double \fP\fIgreen_y\fP\fB, double \fP\fIblue_x\fP\fB, double \fIblue_y\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_cHRM_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fIwhite_x\fP\fB, png_uint_32 \fP\fIwhite_y\fP\fB, png_uint_32 \fP\fIred_x\fP\fB, png_uint_32 \fP\fIred_y\fP\fB, png_uint_32 \fP\fIgreen_x\fP\fB, png_uint_32 \fP\fIgreen_y\fP\fB, png_uint_32 \fP\fIblue_x\fP\fB, png_uint_32 \fIblue_y\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_compression_level (png_structp \fP\fIpng_ptr\fP\fB, int \fIlevel\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_compression_mem_level (png_structp \fP\fIpng_ptr\fP\fB, int \fImem_level\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_compression_method (png_structp \fP\fIpng_ptr\fP\fB, int \fImethod\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_compression_strategy (png_structp \fP\fIpng_ptr\fP\fB, int \fIstrategy\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_compression_window_bits (png_structp \fP\fIpng_ptr\fP\fB, int \fIwindow_bits\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_crc_action (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fIcrit_action\fP\fB, int \fIancil_action\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_dither (png_structp \fP\fIpng_ptr\fP\fB, png_colorp \fP\fIpalette\fP\fB, int \fP\fInum_palette\fP\fB, int \fP\fImaximum_colors\fP\fB, png_uint_16p \fP\fIhistogram\fP\fB, int \fIfull_dither\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_error_fn (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fIerror_ptr\fP\fB, png_error_ptr \fP\fIerror_fn\fP\fB, png_error_ptr \fIwarning_fn\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_expand (png_structp \fIpng_ptr\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_expand_gray_1_2_4_to_8(png_structp \fIpng_ptr\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_filler (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIfiller\fP\fB, int \fIflags\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_filter (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fImethod\fP\fB, int \fIfilters\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_filter_heuristics (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fIheuristic_method\fP\fB, int \fP\fInum_weights\fP\fB, png_doublep \fP\fIfilter_weights\fP\fB, png_doublep \fIfilter_costs\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_flush (png_structp \fP\fIpng_ptr\fP\fB, int \fInrows\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_gamma (png_structp \fP\fIpng_ptr\fP\fB, double \fP\fIscreen_gamma\fP\fB, double \fIdefault_file_gamma\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_gAMA (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, double \fIfile_gamma\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_gAMA_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIfile_gamma\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_gray_1_2_4_to_8(png_structp \fIpng_ptr\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_gray_to_rgb (png_structp \fIpng_ptr\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_hIST (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_16p \fIhist\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_iCCP (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_charp \fP\fIname\fP\fB, int \fP\fIcompression_type\fP\fB, png_charp \fP\fIprofile\fP\fB, png_uint_32 \fIproflen\fP\fB);\fP
+\fI\fB
+
\fBint png_set_interlace_handling (png_structp \fIpng_ptr\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_invalid (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fImask\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_invert_alpha (png_structp \fIpng_ptr\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_invert_mono (png_structp \fIpng_ptr\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_IHDR (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fIwidth\fP\fB, png_uint_32 \fP\fIheight\fP\fB, int \fP\fIbit_depth\fP\fB, int \fP\fIcolor_type\fP\fB, int \fP\fIinterlace_type\fP\fB, int \fP\fIcompression_type\fP\fB, int \fIfilter_type\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_keep_unknown_chunks (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fIkeep\fP\fB, png_bytep \fP\fIchunk_list\fP\fB, int \fInum_chunks\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_mem_fn(png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fImem_ptr\fP\fB, png_malloc_ptr \fP\fImalloc_fn\fP\fB, png_free_ptr \fIfree_fn\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_oFFs (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fIoffset_x\fP\fB, png_uint_32 \fP\fIoffset_y\fP\fB, int \fIunit_type\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_packing (png_structp \fIpng_ptr\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_packswap (png_structp \fIpng_ptr\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_palette_to_rgb(png_structp \fIpng_ptr\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_pCAL (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_charp \fP\fIpurpose\fP\fB, png_int_32 \fP\fIX0\fP\fB, png_int_32 \fP\fIX1\fP\fB, int \fP\fItype\fP\fB, int \fP\fInparams\fP\fB, png_charp \fP\fIunits\fP\fB, png_charpp \fIparams\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_pHYs (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fP\fIres_x\fP\fB, png_uint_32 \fP\fIres_y\fP\fB, int \fIunit_type\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_progressive_read_fn (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fIprogressive_ptr\fP\fB, png_progressive_info_ptr \fP\fIinfo_fn\fP\fB, png_progressive_row_ptr \fP\fIrow_fn\fP\fB, png_progressive_end_ptr \fIend_fn\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_PLTE (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_colorp \fP\fIpalette\fP\fB, int \fInum_palette\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_read_fn (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fIio_ptr\fP\fB, png_rw_ptr \fIread_data_fn\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_read_status_fn (png_structp \fP\fIpng_ptr\fP\fB, png_read_status_ptr \fIread_row_fn\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_read_user_transform_fn (png_structp \fP\fIpng_ptr\fP\fB, png_user_transform_ptr \fIread_user_transform_fn\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_rgb_to_gray (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fIerror_action\fP\fB, double \fP\fIred\fP\fB, double \fIgreen\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_rgb_to_gray_fixed (png_structp \fP\fIpng_ptr\fP\fB, int error_action png_fixed_point \fP\fIred\fP\fB, png_fixed_point \fIgreen\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_rows (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_bytepp \fIrow_pointers\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_sBIT (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_color_8p \fIsig_bit\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_sCAL (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_charp \fP\fIunit\fP\fB, double \fP\fIwidth\fP\fB, double \fIheight\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_shift (png_structp \fP\fIpng_ptr\fP\fB, png_color_8p \fItrue_bits\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_sig_bytes (png_structp \fP\fIpng_ptr\fP\fB, int \fInum_bytes\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_sPLT (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_spalette_p \fP\fIsplt_ptr\fP\fB, int \fInum_spalettes\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_sRGB (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fIintent\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_sRGB_gAMA_and_cHRM (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fIintent\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_strip_16 (png_structp \fIpng_ptr\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_strip_alpha (png_structp \fIpng_ptr\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_swap (png_structp \fIpng_ptr\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_swap_alpha (png_structp \fIpng_ptr\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_text (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_textp \fP\fItext_ptr\fP\fB, int \fInum_text\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_tIME (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_timep \fImod_time\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_tRNS (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_bytep \fP\fItrans\fP\fB, int \fP\fInum_trans\fP\fB, png_color_16p \fItrans_values\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_tRNS_to_alpha(png_structp \fIpng_ptr\fP\fB);\fP
+\fI\fB
+
\fBpng_uint_32 png_set_unknown_chunks (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_unknown_chunkp \fP\fIunknowns\fP\fB, int \fP\fInum\fP\fB, int \fIlocation\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_unknown_chunk_location(png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fP\fIchunk\fP\fB, int \fIlocation\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_read_user_chunk_fn (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fIuser_chunk_ptr\fP\fB, png_user_chunk_ptr \fIread_user_chunk_fn\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_user_limits (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIuser_width_max\fP\fB, png_uint_32 \fIuser_height_max\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_user_transform_info (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fIuser_transform_ptr\fP\fB, int \fP\fIuser_transform_depth\fP\fB, int \fIuser_transform_channels\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_write_fn (png_structp \fP\fIpng_ptr\fP\fB, png_voidp \fP\fIio_ptr\fP\fB, png_rw_ptr \fP\fIwrite_data_fn\fP\fB, png_flush_ptr \fIoutput_flush_fn\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_write_status_fn (png_structp \fP\fIpng_ptr\fP\fB, png_write_status_ptr \fIwrite_row_fn\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_write_user_transform_fn (png_structp \fP\fIpng_ptr\fP\fB, png_user_transform_ptr \fIwrite_user_transform_fn\fP\fB);\fP
+\fI\fB
+
\fBvoid png_set_compression_buffer_size(png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIsize\fP\fB);\fP
+\fI\fB
+
\fBint png_sig_cmp (png_bytep \fP\fIsig\fP\fB, png_size_t \fP\fIstart\fP\fB, png_size_t \fInum_to_check\fP\fB);\fP
+\fI\fB
+
\fBvoid png_start_read_image (png_structp \fIpng_ptr\fP\fB);\fP
+\fI\fB
+
\fBvoid png_warning (png_structp \fP\fIpng_ptr\fP\fB, png_const_charp \fImessage\fP\fB);\fP
+\fI\fB
+
\fBvoid png_write_chunk (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIchunk_name\fP\fB, png_bytep \fP\fIdata\fP\fB, png_size_t \fIlength\fP\fB);\fP
+\fI\fB
+
\fBvoid png_write_chunk_data (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIdata\fP\fB, png_size_t \fIlength\fP\fB);\fP
+\fI\fB
+
\fBvoid png_write_chunk_end (png_structp \fIpng_ptr\fP\fB);\fP
+\fI\fB
+
\fBvoid png_write_chunk_start (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIchunk_name\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
+\fI\fB
+
\fBvoid png_write_destroy (png_structp \fIpng_ptr\fP\fB);\fP
+\fI\fB
+
\fBvoid png_write_end (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+\fI\fB
+
\fBvoid png_write_flush (png_structp \fIpng_ptr\fP\fB);\fP
+\fI\fB
+
\fBvoid png_write_image (png_structp \fP\fIpng_ptr\fP\fB, png_bytepp \fIimage\fP\fB);\fP
+\fI\fB
+
\fBvoid png_write_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+\fI\fB
+
\fBvoid png_write_info_before_PLTE (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+\fI\fB
+
\fBvoid png_write_png (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, int \fP\fItransforms\fP\fB, png_voidp \fIparams\fP\fB);\fP
+\fI\fB
+
\fBvoid png_write_row (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fIrow\fP\fB);\fP
+\fI\fB
+
\fBvoid png_write_rows (png_structp \fP\fIpng_ptr\fP\fB, png_bytepp \fP\fIrow\fP\fB, png_uint_32 \fInum_rows\fP\fB);\fP
+\fI\fB
+
\fBvoid png_write_sig (png_structp \fIpng_ptr\fP\fB);\fP
+\fI\fB
+
\fBvoidpf png_zalloc (voidpf \fP\fIpng_ptr\fP\fB, uInt \fP\fIitems\fP\fB, uInt \fIsize\fP\fB);\fP
+\fI\fB
+
\fBvoid png_zfree (voidpf \fP\fIpng_ptr\fP\fB, voidpf \fIptr\fP\fB);\fP
+\fI\fB
+
.SH DESCRIPTION
The
.I libpng
@@ -398,7 +797,7 @@ 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.4.0beta19 - May 15, 2007
+ libpng version 1.4.0beta20 - July 10, 2008
Updated and distributed by Glenn Randers-Pehrson
<glennrp at users.sourceforge.net>
Copyright (c) 1998-2005 Glenn Randers-Pehrson
@@ -3315,13 +3714,13 @@ application:
.SH IX. Y2K Compliance in libpng
-May 15, 2007
+July 10, 2008
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.71 and
-upward through 1.4.0beta19 are Y2K compliant. It is my belief that earlier
+upward through 1.4.0beta20 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
@@ -3488,7 +3887,7 @@ the first widely used release:
1.2.12 13 10212 12.so.0.12[.0]
1.4.0beta9-14 14 10400 14.so.0.0[.0]
1.2.13 13 10213 12.so.0.13[.0]
- 1.4.0beta15-19 14 10400 14.so.0.0[.0]
+ 1.4.0beta15-20 14 10400 14.so.0.0[.0]
Henceforth the source version will match the shared-library minor
and patch numbers; the shared-library major version number will be
@@ -3544,7 +3943,7 @@ possible without all of you.
Thanks to Frank J. T. Wojcik for helping with the documentation.
-Libpng version 1.4.0beta19 - May 15, 2007:
+Libpng version 1.4.0beta20 - July 10, 2008:
Initially created in 1995 by Guy Eric Schalnat, then of Group 42, Inc.
Currently maintained by Glenn Randers-Pehrson (glennrp at users.sourceforge.net).
@@ -3565,7 +3964,7 @@ included in the libpng distribution, the latter shall prevail.)
If you modify libpng you may insert additional notices immediately following
this sentence.
-libpng versions 1.2.6, August 15, 2004, through 1.4.0beta19, May 15, 2007, are
+libpng versions 1.2.6, August 15, 2004, through 1.4.0beta20, July 10, 2008, are
Copyright (c) 2004,2006-2007 Glenn Randers-Pehrson, and are
distributed according to the same disclaimer and license as libpng-1.2.5
with the following individual added to the list of Contributing Authors
@@ -3664,7 +4063,7 @@ certification mark of the Open Source Initiative.
Glenn Randers-Pehrson
glennrp at users.sourceforge.net
-May 15, 2007
+July 10, 2008
.\" end of man page
diff --git a/libpngpf.3 b/libpngpf.3
index 0f0f52f55..541f1028f 100644
--- a/libpngpf.3
+++ b/libpngpf.3
@@ -1,264 +1,770 @@
-.TH LIBPNGPF 3 "May 15, 2007"
+.TH LIBPNGPF 3 "July 10, 2008"
.SH NAME
-libpng \- Portable Network Graphics (PNG) Reference Library 1.4.0beta19
+libpng \- Portable Network Graphics (PNG) Reference Library 1.4.0beta20
(private functions)
.SH SYNOPSIS
\fB#include <png.h>\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_build_gamma_table (png_structp \fIpng_ptr\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_build_grayscale_palette (int \fP\fIbit_depth\fP\fB, png_colorp \fIpalette\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_calculate_crc (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIptr\fP\fB, png_size_t \fIlength\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_check_chunk_name (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fIchunk_name\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBpng_size_t png_check_keyword (png_structp \fP\fIpng_ptr\fP\fB, png_charp \fP\fIkey\fP\fB, png_charpp \fInew_key\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_combine_row (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIrow\fP\fB, int \fImask\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_correct_palette (png_structp \fP\fIpng_ptr\fP\fB, png_colorp \fP\fIpalette\fP\fB, int \fInum_palette\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBint png_crc_error (png_structp \fIpng_ptr\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBint png_crc_finish (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIskip\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_crc_read (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIbuf\fP\fB, png_size_t \fIlength\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBpng_voidp png_create_struct (int \fItype\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBpng_voidp png_create_struct_2 (int \fP\fItype\fP\fB, png_malloc_ptr \fP\fImalloc_fn\fP\fB, png_voidp \fImem_ptr\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBpng_charp png_decompress_chunk (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fIcomp_type\fP\fB, png_charp \fP\fIchunkdata\fP\fB, png_size_t \fP\fIchunklength\fP\fB, png_size_t \fP\fIprefix_length\fP\fB, png_size_t \fI*data_length\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_destroy_struct (png_voidp \fIstruct_ptr\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_destroy_struct_2 (png_voidp \fP\fIstruct_ptr\fP\fB, png_free_ptr \fP\fIfree_fn\fP\fB, png_voidp \fImem_ptr\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_do_background (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, png_color_16p \fP\fItrans_values\fP\fB, png_color_16p \fP\fIbackground\fP\fB, png_color_16p \fP\fIbackground_1\fP\fB, png_bytep \fP\fIgamma_table\fP\fB, png_bytep \fP\fIgamma_from_1\fP\fB, png_bytep \fP\fIgamma_to_1\fP\fB, png_uint_16pp \fP\fIgamma_16\fP\fB, png_uint_16pp \fP\fIgamma_16_from_1\fP\fB, png_uint_16pp \fP\fIgamma_16_to_1\fP\fB, int \fIgamma_shift\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_do_bgr (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_do_chop (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_do_dither (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, png_bytep \fP\fIpalette_lookup\fP\fB, png_bytep \fIdither_lookup\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_do_expand (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, png_color_16p \fItrans_value\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_do_expand_palette (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, png_colorp \fP\fIpalette\fP\fB, png_bytep \fP\fItrans\fP\fB, int \fInum_trans\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_do_gamma (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, png_bytep \fP\fIgamma_table\fP\fB, png_uint_16pp \fP\fIgamma_16_table\fP\fB, int \fIgamma_shift\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_do_gray_to_rgb (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_do_invert (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_do_pack (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, png_uint_32 \fIbit_depth\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_do_packswap (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_do_read_filler (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, png_uint_32 \fP\fIfiller\fP\fB, png_uint_32 \fIflags\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_do_read_interlace (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, int \fP\fIpass\fP\fB, png_uint_32 \fItransformations\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_do_read_invert_alpha (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_do_read_swap_alpha (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_do_read_transformations (png_structp \fIpng_ptr\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBint png_do_rgb_to_gray (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_do_shift (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, png_color_8p \fIbit_depth\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_do_strip_filler (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, png_uint_32 \fIflags\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_do_swap (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_do_unpack (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_do_unshift (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, png_color_8p \fIsig_bits\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_do_write_interlace (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, int \fIpass\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_do_write_invert_alpha (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_do_write_swap_alpha (png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fIrow\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_do_write_transformations (png_structp \fIpng_ptr\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid *png_far_to_near (png_structp png_ptr,png_voidp \fP\fIptr\fP\fB, int \fIcheck\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_flush (png_structp \fIpng_ptr\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_handle_bKGD (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_handle_cHRM (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_handle_gAMA (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_handle_hIST (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_handle_IEND (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_handle_IHDR (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_handle_iCCP (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_handle_iTXt (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_handle_oFFs (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_handle_pCAL (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_handle_pHYs (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_handle_PLTE (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_handle_sBIT (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_handle_sCAL (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_handle_sPLT (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_handle_sRGB (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_handle_tEXt (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_handle_tIME (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_handle_tRNS (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_handle_unknown (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_handle_zTXt (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_info_destroy (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_init_mmx_flags (png_structp \fIpng_ptr\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_init_read_transformations (png_structp \fIpng_ptr\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_process_IDAT_data (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIbuffer\fP\fB, png_size_t \fIbuffer_length\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_process_some_data (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_push_check_crc (png_structp \fIpng_ptr\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_push_crc_finish (png_structp \fIpng_ptr\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_push_crc_skip (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_push_fill_buffer (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIbuffer\fP\fB, png_size_t \fIlength\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_push_handle_tEXt (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_push_handle_unknown (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_push_handle_zTXt (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_uint_32 \fIlength\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_push_have_end (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_push_have_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_push_have_row (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fIrow\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_push_process_row (png_structp \fIpng_ptr\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_push_read_chunk (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_push_read_end (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_push_read_IDAT (png_structp \fIpng_ptr\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_push_read_sig (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_push_read_tEXt (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_push_read_zTXt (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_push_restore_buffer (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIbuffer\fP\fB, png_size_t \fIbuffer_length\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_push_save_buffer (png_structp \fIpng_ptr\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_read_data (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIdata\fP\fB, png_size_t \fIlength\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_read_filter_row (png_structp \fP\fIpng_ptr\fP\fB, png_row_infop \fP\fIrow_info\fP\fB, png_bytep \fP\fIrow\fP\fB, png_bytep \fP\fIprev_row\fP\fB, int \fIfilter\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_read_finish_row (png_structp \fIpng_ptr\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_read_push_finish_row (png_structp \fIpng_ptr\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_read_start_row (png_structp \fIpng_ptr\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_read_transform_info (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fIinfo_ptr\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_reset_crc (png_structp \fIpng_ptr\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBint png_set_text_2 (png_structp \fP\fIpng_ptr\fP\fB, png_infop \fP\fIinfo_ptr\fP\fB, png_textp \fP\fItext_ptr\fP\fB, int \fInum_text\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_write_cHRM (png_structp \fP\fIpng_ptr\fP\fB, double \fP\fIwhite_x\fP\fB, double \fP\fIwhite_y\fP\fB, double \fP\fIred_x\fP\fB, double \fP\fIred_y\fP\fB, double \fP\fIgreen_x\fP\fB, double \fP\fIgreen_y\fP\fB, double \fP\fIblue_x\fP\fB, double \fIblue_y\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_write_cHRM_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIwhite_x\fP\fB, png_uint_32 \fP\fIwhite_y\fP\fB, png_uint_32 \fP\fIred_x\fP\fB, png_uint_32 \fP\fIred_y\fP\fB, png_uint_32 \fP\fIgreen_x\fP\fB, png_uint_32 \fP\fIgreen_y\fP\fB, png_uint_32 \fP\fIblue_x\fP\fB, png_uint_32 \fIblue_y\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_write_data (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIdata\fP\fB, png_size_t \fIlength\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_write_filtered_row (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fIfiltered_row\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_write_find_filter (png_structp \fP\fIpng_ptr\fP\fB, png_row_infop \fIrow_info\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_write_finish_row (png_structp \fIpng_ptr\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_write_gAMA (png_structp \fP\fIpng_ptr\fP\fB, double \fIfile_gamma\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_write_gAMA_fixed (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fIint_file_gamma\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_write_hIST (png_structp \fP\fIpng_ptr\fP\fB, png_uint_16p \fP\fIhist\fP\fB, int \fInum_hist\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_write_iCCP (png_structp \fP\fIpng_ptr\fP\fB, png_charp \fP\fIname\fP\fB, int \fP\fIcompression_type\fP\fB, png_charp \fP\fIprofile\fP\fB, int \fIproflen\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_write_IDAT (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fIdata\fP\fB, png_size_t \fIlength\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_write_IEND (png_structp \fIpng_ptr\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_write_IHDR (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIwidth\fP\fB, png_uint_32 \fP\fIheight\fP\fB, int \fP\fIbit_depth\fP\fB, int \fP\fIcolor_type\fP\fB, int \fP\fIcompression_type\fP\fB, int \fP\fIfilter_type\fP\fB, int \fIinterlace_type\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_write_iTXt (png_structp \fP\fIpng_ptr\fP\fB, int \fP\fIcompression\fP\fB, png_charp \fP\fIkey\fP\fB, png_charp \fP\fIlang\fP\fB, png_charp \fP\fItranslated_key\fP\fB, png_charp \fItext\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_write_oFFs (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIx_offset\fP\fB, png_uint_32 \fP\fIy_offset\fP\fB, int \fIunit_type\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_write_pCAL (png_structp \fP\fIpng_ptr\fP\fB, png_charp \fP\fIpurpose\fP\fB, png_int_32 \fP\fIX0\fP\fB, png_int_32 \fP\fIX1\fP\fB, int \fP\fItype\fP\fB, int \fP\fInparams\fP\fB, png_charp \fP\fIunits\fP\fB, png_charpp \fIparams\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_write_pHYs (png_structp \fP\fIpng_ptr\fP\fB, png_uint_32 \fP\fIx_pixels_per_unit\fP\fB, png_uint_32 \fP\fIy_pixels_per_unit\fP\fB, int \fIunit_type\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_write_PLTE (png_structp \fP\fIpng_ptr\fP\fB, png_colorp \fP\fIpalette\fP\fB, png_uint_32 \fInum_pal\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_write_sBIT (png_structp \fP\fIpng_ptr\fP\fB, png_color_8p \fP\fIsbit\fP\fB, int \fIcolor_type\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_write_sCAL (png_structp \fP\fIpng_ptr\fP\fB, png_charp \fP\fIunit\fP\fB, double \fP\fIwidth\fP\fB, double \fIheight\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_write_sCAL_s (png_structp \fP\fIpng_ptr\fP\fB, png_charp \fP\fIunit\fP\fB, png_charp \fP\fIwidth\fP\fB, png_charp \fIheight\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_write_sRGB (png_structp \fP\fIpng_ptr\fP\fB, int \fIintent\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_write_sPLT (png_structp \fP\fIpng_ptr\fP\fB, png_spalette_p \fIpalette\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_write_start_row (png_structp \fIpng_ptr\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_write_tEXt (png_structp \fP\fIpng_ptr\fP\fB, png_charp \fP\fIkey\fP\fB, png_charp \fP\fItext\fP\fB, png_size_t \fItext_len\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_write_tIME (png_structp \fP\fIpng_ptr\fP\fB, png_timep \fImod_time\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_write_tRNS (png_structp \fP\fIpng_ptr\fP\fB, png_bytep \fP\fItrans\fP\fB, png_color_16p \fP\fIvalues\fP\fB, int \fP\fInumber\fP\fB, int \fIcolor_type\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_write_zTXt (png_structp \fP\fIpng_ptr\fP\fB, png_charp \fP\fIkey\fP\fB, png_charp \fP\fItext\fP\fB, png_size_t \fP\fItext_len\fP\fB, int \fIcompression\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoidpf png_zalloc (voidpf \fP\fIpng_ptr\fP\fB, uInt \fP\fIitems\fP\fB, uInt \fIsize\fP\fB);\fP
+\fI\fB
+
+\fI\fB
+
\fBvoid png_zfree (voidpf \fP\fIpng_ptr\fP\fB, voidpf \fIptr\fP\fB);\fP
\fI\fB
+\fI\fB
+
.SH DESCRIPTION
The functions listed above are used privately by libpng
and are not recommended for use by applications. They are
diff --git a/png.5 b/png.5
index bf6c6fd5b..9be03150c 100644
--- a/png.5
+++ b/png.5
@@ -1,4 +1,4 @@
-.TH PNG 5 "May 15, 2007"
+.TH PNG 5 "July 10, 2008"
.SH NAME
png \- Portable Network Graphics (PNG) format
.SH DESCRIPTION
diff --git a/png.c b/png.c
index 243558820..c21176b2a 100644
--- a/png.c
+++ b/png.c
@@ -1,9 +1,9 @@
/* png.c - location for general purpose libpng functions
*
- * Last changed in libpng 1.4.0 May 15, 2007
+ * Last changed in libpng 1.2.30 [July 10, 2008]
* For conditions of distribution and use, see copyright notice in png.h
- * Copyright (c) 1998-2007 Glenn Randers-Pehrson
+ * Copyright (c) 1998-2008 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*/
@@ -13,20 +13,20 @@
#include "pngpriv.h"
/* Generate a compiler error if there is an old png.h in the search path. */
-typedef version_1_4_0beta19 Your_png_h_is_not_version_1_4_0beta19;
+typedef version_1_4_0beta20 Your_png_h_is_not_version_1_4_0beta20;
/* Version information for C files. This had better match the version
* string defined in png.h. */
#ifdef PNG_USE_GLOBAL_ARRAYS
/* png_libpng_ver was changed to a function in version 1.0.5c */
-const char png_libpng_ver[18] = PNG_LIBPNG_VER_STRING;
+PNG_CONST char png_libpng_ver[18] = PNG_LIBPNG_VER_STRING;
#ifdef PNG_READ_SUPPORTED
/* png_sig was changed to a function in version 1.0.5c */
/* Place to hold the signature string for a PNG file. */
-const png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
+PNG_CONST png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
#endif /* PNG_READ_SUPPORTED */
/* Invoke global declarations for constant strings for known chunk types */
@@ -56,32 +56,27 @@ PNG_zTXt;
/* arrays to facilitate easy interlacing - use pass (0 - 6) as index */
/* start of interlace block */
-const int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
+PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
/* offset to next interlace block */
-const int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
+PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
/* start of interlace block in the y direction */
-const int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
+PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
/* offset to next interlace block in the y direction */
-const int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
-
-/* width of interlace block (used in assembler routines only) */
-#ifdef PNG_HAVE_MMX_COMBINE_ROW
-const int FARDATA png_pass_width[] = {8, 4, 4, 2, 2, 1, 1};
-#endif
+PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
/* Height of interlace block. This is not currently used - if you need
* it, uncomment it here and in png.h
-const int FARDATA png_pass_height[] = {8, 8, 4, 4, 2, 2, 1};
+PNG_CONST int FARDATA png_pass_height[] = {8, 8, 4, 4, 2, 2, 1};
*/
/* Mask to determine which pixels are valid in a pass */
-const int FARDATA png_pass_mask[] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
+PNG_CONST int FARDATA png_pass_mask[] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
/* Mask to determine which pixels to overwrite while displaying */
-const int FARDATA png_pass_dsp_mask[]
+PNG_CONST int FARDATA png_pass_dsp_mask[]
= {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
#endif /* PNG_READ_SUPPORTED */
@@ -97,7 +92,7 @@ const int FARDATA png_pass_dsp_mask[]
void PNGAPI
png_set_sig_bytes(png_structp png_ptr, int num_bytes)
{
- if(png_ptr == NULL) return;
+ if (png_ptr == NULL) return;
png_debug(1, "in png_set_sig_bytes\n");
if (num_bytes > 8)
png_error(png_ptr, "Too many bytes for PNG signature");
@@ -128,38 +123,37 @@ png_sig_cmp(png_bytep sig, png_size_t start, png_size_t num_to_check)
if (start + num_to_check > 8)
num_to_check = 8 - start;
- return (png_memcmp(&sig[start], &png_signature[start], num_to_check));
+ return ((int)(png_memcmp(&sig[start], &png_signature[start], num_to_check)));
}
#endif /* PNG_READ_SUPPORTED */
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
-/* Function to allocate memory for zlib.
- * Since libpng-1.2.x, this does NOT clear the allocated memory to 0.
- */
+/* Function to allocate memory for zlib and clear it to 0. */
voidpf /* private */
png_zalloc(voidpf png_ptr, uInt items, uInt size)
{
- voidpf ptr;
- png_structp p = (png_structp)png_ptr;
- png_uint_32 save_flags = p->flags;
+ png_voidp ptr;
+ png_structp p=(png_structp)png_ptr;
+ png_uint_32 save_flags=p->flags;
png_alloc_size_t num_bytes;
- if(png_ptr == NULL) return (NULL);
+ if (png_ptr == NULL) return (NULL);
if (items > PNG_UINT_32_MAX/size)
{
- png_warning(p, "Potential overflow in png_zalloc()");
- return NULL;
+ png_warning (p, "Potential overflow in png_zalloc()");
+ return (NULL);
}
num_bytes = (png_alloc_size_t)items * size;
- p->flags |= PNG_FLAG_MALLOC_NULL_MEM_OK;
- ptr = (voidpf)png_malloc(p, num_bytes);
- p->flags = save_flags;
- return ptr;
- }
+ p->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
+ ptr = (png_voidp)png_malloc((png_structp)png_ptr, num_bytes);
+ p->flags=save_flags;
-/* Function to free memory for zlib. */
+ return ((voidpf)ptr);
+}
+
+/* function to free memory for zlib */
void /* private */
png_zfree(voidpf png_ptr, voidpf ptr)
{
@@ -203,7 +197,7 @@ png_calculate_crc(png_structp png_ptr, png_bytep ptr, png_size_t length)
/* Allocate the memory for an info_struct for the application. We don't
* really need the png_ptr, but it could potentially be useful in the
- * future. This should be used in favour of malloc(sizeof(png_info))
+ * future. This should be used in favour of malloc(png_sizeof(png_info))
* and png_info_init() so that applications that want to use a shared
* libpng don't have to be recompiled if png_info changes size.
*/
@@ -213,7 +207,7 @@ png_create_info_struct(png_structp png_ptr)
png_infop info_ptr;
png_debug(1, "in png_create_info_struct\n");
- if(png_ptr == NULL) return (NULL);
+ if (png_ptr == NULL) return (NULL);
#ifdef PNG_USER_MEM_SUPPORTED
info_ptr = (png_infop)png_create_struct_2(PNG_STRUCT_INFO,
png_ptr->malloc_fn, png_ptr->mem_ptr);
@@ -221,7 +215,7 @@ png_create_info_struct(png_structp png_ptr)
info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
#endif
if (info_ptr != NULL)
- png_info_init_3(&info_ptr, sizeof(png_info));
+ png_info_init_3(&info_ptr, png_sizeof(png_info));
return (info_ptr);
}
@@ -235,7 +229,7 @@ void PNGAPI
png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr)
{
png_infop info_ptr = NULL;
- if(png_ptr == NULL) return;
+ if (png_ptr == NULL) return;
png_debug(1, "in png_destroy_info_struct\n");
if (info_ptr_ptr != NULL)
@@ -259,16 +253,17 @@ png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr)
* and applications using it are urged to use png_create_info_struct()
* instead.
*/
+
void PNGAPI
png_info_init_3(png_infopp ptr_ptr, png_size_t png_info_struct_size)
{
png_infop info_ptr = *ptr_ptr;
- if(info_ptr == NULL) return;
+ if (info_ptr == NULL) return;
png_debug(1, "in png_info_init_3\n");
- if (sizeof(png_info) > png_info_struct_size)
+ if (png_sizeof(png_info) > png_info_struct_size)
{
png_destroy_struct(info_ptr);
info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
@@ -276,7 +271,7 @@ png_info_init_3(png_infopp ptr_ptr, png_size_t png_info_struct_size)
}
/* set everything to 0 */
- png_memset(info_ptr, 0, sizeof(png_info));
+ png_memset(info_ptr, 0, png_sizeof(png_info));
}
#ifdef PNG_FREE_ME_SUPPORTED
@@ -287,9 +282,9 @@ png_data_freer(png_structp png_ptr, png_infop info_ptr,
png_debug(1, "in png_data_freer\n");
if (png_ptr == NULL || info_ptr == NULL)
return;
- if(freer == PNG_DESTROY_WILL_FREE_DATA)
+ if (freer == PNG_DESTROY_WILL_FREE_DATA)
info_ptr->free_me |= mask;
- else if(freer == PNG_USER_WILL_FREE_DATA)
+ else if (freer == PNG_USER_WILL_FREE_DATA)
info_ptr->free_me &= ~mask;
else
png_warning(png_ptr,
@@ -421,7 +416,7 @@ if (mask & PNG_FREE_SPLT)
{
if (num != -1)
{
- if(info_ptr->splt_palettes)
+ if (info_ptr->splt_palettes)
{
png_free(png_ptr, info_ptr->splt_palettes[num].name);
png_free(png_ptr, info_ptr->splt_palettes[num].entries);
@@ -431,7 +426,7 @@ if (mask & PNG_FREE_SPLT)
}
else
{
- if(info_ptr->splt_palettes_num)
+ if (info_ptr->splt_palettes_num)
{
int i;
for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
@@ -447,6 +442,11 @@ if (mask & PNG_FREE_SPLT)
#endif
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
+ if (png_ptr->unknown_chunk.data)
+ {
+ png_free(png_ptr, png_ptr->unknown_chunk.data);
+ png_ptr->unknown_chunk.data = NULL;
+ }
#ifdef PNG_FREE_ME_SUPPORTED
if ((mask & PNG_FREE_UNKN) & info_ptr->free_me)
#else
@@ -455,7 +455,7 @@ if (mask & PNG_FREE_UNKN)
{
if (num != -1)
{
- if(info_ptr->unknown_chunks)
+ if (info_ptr->unknown_chunks)
{
png_free(png_ptr, info_ptr->unknown_chunks[num].data);
info_ptr->unknown_chunks[num].data = NULL;
@@ -465,7 +465,7 @@ if (mask & PNG_FREE_UNKN)
{
int i;
- if(info_ptr->unknown_chunks_num)
+ if (info_ptr->unknown_chunks_num)
{
for (i = 0; i < (int)info_ptr->unknown_chunks_num; i++)
png_free_data(png_ptr, info_ptr, PNG_FREE_UNKN, i);
@@ -519,7 +519,7 @@ if ((mask & PNG_FREE_ROWS) & info_ptr->free_me)
if (mask & PNG_FREE_ROWS)
#endif
{
- if(info_ptr->row_pointers)
+ if (info_ptr->row_pointers)
{
int row;
for (row = 0; row < (int)info_ptr->height; row++)
@@ -535,7 +535,7 @@ if (mask & PNG_FREE_ROWS)
#endif
#ifdef PNG_FREE_ME_SUPPORTED
- if(num == -1)
+ if (num == -1)
info_ptr->free_me &= ~mask;
else
info_ptr->free_me &= ~(mask & ~PNG_FREE_MUL);
@@ -562,7 +562,7 @@ png_info_destroy(png_structp png_ptr, png_infop info_ptr)
}
#endif
- png_info_init_3(&info_ptr, sizeof(png_info));
+ png_info_init_3(&info_ptr, png_sizeof(png_info));
}
#endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
@@ -573,7 +573,7 @@ png_info_destroy(png_structp png_ptr, png_infop info_ptr)
png_voidp PNGAPI
png_get_io_ptr(png_structp png_ptr)
{
- if(png_ptr == NULL) return (NULL);
+ if (png_ptr == NULL) return (NULL);
return (png_ptr->io_ptr);
}
@@ -589,7 +589,7 @@ void PNGAPI
png_init_io(png_structp png_ptr, png_FILE_p fp)
{
png_debug(1, "in png_init_io\n");
- if(png_ptr == NULL) return;
+ if (png_ptr == NULL) return;
png_ptr->io_ptr = (png_voidp)fp;
}
#endif
@@ -605,22 +605,25 @@ png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime)
{"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
- if(png_ptr == NULL) return (NULL);
+ if (png_ptr == NULL) return (NULL);
if (png_ptr->time_buffer == NULL)
- png_ptr->time_buffer = (png_charp)png_malloc(png_ptr, 29*sizeof(char));
+ {
+ png_ptr->time_buffer = (png_charp)png_malloc(png_ptr, (png_uint_32)(29*
+ png_sizeof(char)));
+ }
#ifdef USE_FAR_KEYWORD
{
char near_time_buf[29];
- png_sprintf(near_time_buf, "%d %s %d %02d:%02d:%02d +0000",
+ png_snprintf6(near_time_buf, 29, "%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));
+ 29*png_sizeof(char));
}
#else
- png_sprintf(png_ptr->time_buffer, "%d %s %d %02d:%02d:%02d +0000",
+ png_snprintf6(png_ptr->time_buffer, 29, "%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);
@@ -629,25 +632,16 @@ png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime)
}
#endif /* PNG_TIME_RFC1123_SUPPORTED */
-#if 0
-/* Signature string for a PNG file. */
-png_bytep PNGAPI
-png_sig_bytes(void)
-{
- return ((png_bytep)"\211\120\116\107\015\012\032\012");
-}
-#endif
#endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
png_charp PNGAPI
png_get_copyright(png_structp png_ptr)
{
- if (&png_ptr != NULL) /* silence compiler warning about unused png_ptr */
- return ((png_charp) "\n libpng version 1.4.0beta19 - May 15, 2007\n\
- Copyright (c) 1998-2007 Glenn Randers-Pehrson\n\
+ png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
+ return ((png_charp) "\n libpng version 1.4.0beta20 - July 10, 2008\n\
+ Copyright (c) 1998-2008 Glenn Randers-Pehrson\n\
Copyright (c) 1996-1997 Andreas Dilger\n\
Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.\n");
- return ((png_charp) "");
}
/* The following return the library version as a short string in the
@@ -662,27 +656,28 @@ png_charp PNGAPI
png_get_libpng_ver(png_structp png_ptr)
{
/* Version of *.c files used when building libpng */
- if (&png_ptr != NULL) /* silence compiler warning about unused png_ptr */
- return ((png_charp) PNG_LIBPNG_VER_STRING);
- return ((png_charp) "");
+ png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
+ return ((png_charp) PNG_LIBPNG_VER_STRING);
}
png_charp PNGAPI
png_get_header_ver(png_structp png_ptr)
{
/* Version of *.h files used when building libpng */
- if (&png_ptr != NULL) /* silence compiler warning about unused png_ptr */
- return ((png_charp) PNG_LIBPNG_VER_STRING);
- return ((png_charp) "");
+ png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
+ return ((png_charp) PNG_LIBPNG_VER_STRING);
}
png_charp PNGAPI
png_get_header_version(png_structp png_ptr)
{
/* Returns longer string containing both version and date */
- if (&png_ptr != NULL) /* silence compiler warning about unused png_ptr */
- return ((png_charp) PNG_HEADER_VERSION_STRING);
- return ((png_charp) "");
+ png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
+ return ((png_charp) PNG_HEADER_VERSION_STRING
+#ifndef PNG_READ_SUPPORTED
+ " (NO READ SUPPORT)"
+#endif
+ "\n");
}
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
@@ -693,12 +688,12 @@ png_handle_as_unknown(png_structp png_ptr, png_bytep chunk_name)
/* check chunk_name and return "keep" value if it's on the list, else 0 */
int i;
png_bytep p;
- if((png_ptr == NULL && chunk_name == NULL) || png_ptr->num_chunk_list<=0)
+ if (png_ptr == NULL || chunk_name == NULL || png_ptr->num_chunk_list<=0)
return 0;
- p=png_ptr->chunk_list+png_ptr->num_chunk_list*5-5;
- for (i = png_ptr->num_chunk_list; i; i--, p-=5)
+ p = png_ptr->chunk_list + png_ptr->num_chunk_list*5 - 5;
+ for (i = png_ptr->num_chunk_list; i; i--, p -= 5)
if (!png_memcmp(chunk_name, p, 4))
- return ((int)*(p+4));
+ return ((int)*(p + 4));
return 0;
}
#endif
@@ -721,63 +716,17 @@ png_access_version_number(void)
}
-#if defined(PNG_READ_SUPPORTED)
-#if defined(PNG_MMX_CODE_SUPPORTED)
- /* GRR: could add this: && defined(PNG_MMX_CODE_SUPPORTED) */
-/* this INTERNAL function was added to libpng 1.2.0 */
-void /* PRIVATE */
-png_init_mmx_flags (png_structp png_ptr)
-{
- if(png_ptr == NULL) return;
- png_ptr->mmx_rowbytes_threshold = 0;
- png_ptr->mmx_bitdepth_threshold = 0;
-
-# if (defined(PNG_USE_PNGVCRD) || defined(PNG_USE_PNGGCCRD))
-
- png_ptr->asm_flags |= PNG_ASM_FLAG_MMX_SUPPORT_COMPILED;
-
- if (png_mmx_support() > 0) {
- png_ptr->asm_flags |= PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU
-# ifdef PNG_HAVE_MMX_COMBINE_ROW
- | PNG_ASM_FLAG_MMX_READ_COMBINE_ROW
-# endif
-# ifdef PNG_HAVE_MMX_READ_INTERLACE
- | PNG_ASM_FLAG_MMX_READ_INTERLACE
-# endif
-# ifndef PNG_HAVE_MMX_READ_FILTER_ROW
- ;
-# else
- | PNG_ASM_FLAG_MMX_READ_FILTER_SUB
- | PNG_ASM_FLAG_MMX_READ_FILTER_UP
- | PNG_ASM_FLAG_MMX_READ_FILTER_AVG
- | PNG_ASM_FLAG_MMX_READ_FILTER_PAETH ;
-
- png_ptr->mmx_rowbytes_threshold = PNG_MMX_ROWBYTES_THRESHOLD_DEFAULT;
- png_ptr->mmx_bitdepth_threshold = PNG_MMX_BITDEPTH_THRESHOLD_DEFAULT;
-# endif
- } else {
- png_ptr->asm_flags &= ~( PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU
- | PNG_MMX_READ_FLAGS
- | PNG_MMX_WRITE_FLAGS );
- }
-
-# else /* !((PNGVCRD || PNGGCCRD) && PNG_MMX_CODE_SUPPORTED)) */
-
- /* clear all MMX flags; no support is compiled in */
- png_ptr->asm_flags &= ~( PNG_MMX_FLAGS );
-
-# endif /* ?(PNGVCRD || PNGGCCRD) */
-}
-#endif /* !(PNG_MMX_CODE_SUPPORTED) */
-
-/* this function was added to libpng 1.2.0 */
-#if !defined(PNG_USE_PNGGCCRD) && \
- !(defined(PNG_MMX_CODE_SUPPORTED) && defined(PNG_USE_PNGVCRD))
-int PNGAPI
-png_mmx_support(void)
+#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
+#ifdef PNG_SIZE_T
+/* Added at libpng version 1.2.6 */
+ PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size));
+png_size_t PNGAPI
+png_convert_size(size_t size)
{
- return -1;
+ if (size > (png_size_t)-1)
+ PNG_ABORT(); /* We haven't got access to png_ptr, so no png_error() */
+ return ((png_size_t)size);
}
-#endif
-#endif /* PNG_READ_SUPPORTED */
+#endif /* PNG_SIZE_T */
+#endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
diff --git a/png.h b/png.h
index 90ae02acb..b3512898b 100644
--- a/png.h
+++ b/png.h
@@ -1,15 +1,15 @@
/* png.h - header file for PNG reference library
*
- * libpng version 1.4.0beta19 - May 15, 2007
- * Copyright (c) 1998-2007 Glenn Randers-Pehrson
+ * libpng version 1.4.0beta20 - July 10, 2008
+ * Copyright (c) 1998-2008 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*
* Authors and maintainers:
* libpng versions 0.71, May 1995, through 0.88, January 1996: Guy Schalnat
* libpng versions 0.89c, June 1996, through 0.96, May 1997: Andreas Dilger
- * libpng versions 0.97, January 1998, through 1.4.0beta19 - May 15, 2007: Glenn
+ * libpng versions 0.97, January 1998, through 1.4.0beta20 - July 1, 2008: Glenn
* See also "Contributing Authors", below.
*
* Note about libpng version numbers:
@@ -126,7 +126,7 @@
* 1.2.12 13 10212 12.so.0.10[.0]
* 1.4.0beta9-14 14 10400 14.so.0.0[.0]
* 1.2.13 13 10213 12.so.0.10[.0]
- * 1.4.0beta15-19 14 10400 14.so.0.0[.0]
+ * 1.4.0beta15-20 14 10400 14.so.0.0[.0]
*
* Henceforth the source version will match the shared-library major
* and minor numbers; the shared-library major version number will be
@@ -156,7 +156,7 @@
* If you modify libpng you may insert additional notices immediately following
* this sentence.
*
- * libpng versions 1.2.6, August 15, 2004, through 1.4.0beta19, May 15, 2007, are
+ * libpng versions 1.2.6, August 15, 2004, through 1.4.0beta20, July 1, 2008, are
* Copyright (c) 2004, 2006-2007 Glenn Randers-Pehrson, and are
* distributed according to the same disclaimer and license as libpng-1.2.5
* with the following individual added to the list of Contributing Authors:
@@ -268,13 +268,13 @@
* Y2K compliance in libpng:
* =========================
*
- * May 15, 2007
+ * July 1, 2008
*
* 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.71 and
- * upward through 1.4.0beta19 are Y2K compliant. It is my belief that earlier
+ * upward through 1.4.0beta20 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
@@ -330,9 +330,9 @@
*/
/* Version information for png.h - this should match the version in png.c */
-#define PNG_LIBPNG_VER_STRING "1.4.0beta19"
+#define PNG_LIBPNG_VER_STRING "1.4.0beta20"
#define PNG_HEADER_VERSION_STRING \
- " libpng version 1.4.0beta19 - May 15, 2007 (header)\n"
+ " libpng version 1.4.0beta20 - July 1, 2008 (header)\n"
#define PNG_LIBPNG_VER_SONUM 1
#define PNG_LIBPNG_VER_DLLNUM 14
@@ -344,7 +344,7 @@
/* This should match the numeric part of the final component of
* PNG_LIBPNG_VER_STRING, omitting any leading zero: */
-#define PNG_LIBPNG_VER_BUILD 19
+#define PNG_LIBPNG_VER_BUILD 21
/* Release Status */
#define PNG_LIBPNG_BUILD_ALPHA 1
@@ -1297,13 +1297,6 @@ struct png_struct_def
#endif
/* New members added in libpng-1.2.0 */
-#if defined(PNG_MMX_CODE_SUPPORTED)
- png_byte mmx_bitdepth_threshold;
- png_uint_32 mmx_rowbytes_threshold;
-#endif
-#if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
- png_uint_32 asm_flags;
-#endif
/* New members added in libpng-1.0.2 but first enabled by default in 1.2.0 */
#ifdef PNG_USER_MEM_SUPPORTED
@@ -1332,18 +1325,24 @@ struct png_struct_def
png_uint_32 user_height_max;
#endif
-/* New member added in libpng-1.4.0 */
-#if defined(PNG_IO_STATE_SUPPORTED)
+/* New members added in libpng-1.2.26 */
+ png_uint_32 old_big_row_buf_size, old_prev_row_size;
+
+/* New members added in libpng-1.4.0 */
+#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
+ /* storage for unknown chunk that the library doesn't recognize. */
+ png_unknown_chunk unknown_chunk;
+#endif
+#ifdef PNG_IO_STATE_SUPPORTED
png_uint_32 io_state;
#endif
-
};
/* This triggers a compiler error in png.c, if png.c and png.h
* do not agree upon the version number.
*/
-typedef png_structp version_1_4_0beta19;
+typedef png_structp version_1_4_0beta20;
typedef png_struct FAR * FAR * png_structpp;
@@ -2304,7 +2303,7 @@ extern PNG_EXPORT(void,png_set_sCAL_s) PNGARG((png_structp png_ptr,
handling or default unknown chunk handling is not desired. Any chunks not
listed will be handled in the default manner. The IHDR and IEND chunks
must not be listed.
- keep = 0: follow default behavour
+ keep = 0: follow default behaviour
= 1: do not keep
= 2: keep only if safe-to-copy
= 3: keep even if unsafe-to-copy
@@ -2412,71 +2411,6 @@ extern PNG_EXPORT(png_uint_32,png_permit_mng_features) PNGARG((png_structp
#define PNG_HANDLE_CHUNK_IF_SAFE 2
#define PNG_HANDLE_CHUNK_ALWAYS 3
-/* Added to version 1.2.0 */
-#if defined(PNG_MMX_CODE_SUPPORTED)
-#define PNG_ASM_FLAG_MMX_SUPPORT_COMPILED 0x01 /* not user-settable */
-#define PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU 0x02 /* not user-settable */
-#define PNG_ASM_FLAG_MMX_READ_COMBINE_ROW 0x04
-#define PNG_ASM_FLAG_MMX_READ_INTERLACE 0x08
-#define PNG_ASM_FLAG_MMX_READ_FILTER_SUB 0x10
-#define PNG_ASM_FLAG_MMX_READ_FILTER_UP 0x20
-#define PNG_ASM_FLAG_MMX_READ_FILTER_AVG 0x40
-#define PNG_ASM_FLAG_MMX_READ_FILTER_PAETH 0x80
-#define PNG_MMX_FLAGS_INITIALIZED 0x80000000 /* not user-settable */
-
-#define PNG_MMX_READ_FLAGS ( PNG_ASM_FLAG_MMX_READ_COMBINE_ROW \
- | PNG_ASM_FLAG_MMX_READ_INTERLACE \
- | PNG_ASM_FLAG_MMX_READ_FILTER_SUB \
- | PNG_ASM_FLAG_MMX_READ_FILTER_UP \
- | PNG_ASM_FLAG_MMX_READ_FILTER_AVG \
- | PNG_ASM_FLAG_MMX_READ_FILTER_PAETH )
-#define PNG_MMX_WRITE_FLAGS ( 0 )
-
-#define PNG_MMX_FLAGS ( PNG_ASM_FLAG_MMX_SUPPORT_COMPILED \
- | PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU \
- | PNG_ASM_MMX_READ_FLAGS \
- | PNG_ASM_MMX_WRITE_FLAGS )
-
-#define PNG_SELECT_READ 1
-#define PNG_SELECT_WRITE 2
-
-/* pngget.c */
-extern PNG_EXPORT(png_uint_32,png_get_mmx_flagmask)
- PNGARG((int flag_select, int *compilerID));
-
-/* pngget.c */
-extern PNG_EXPORT(png_byte,png_get_mmx_bitdepth_threshold)
- PNGARG((png_structp png_ptr));
-
-/* pngget.c */
-extern PNG_EXPORT(png_uint_32,png_get_mmx_rowbytes_threshold)
- PNGARG((png_structp png_ptr));
-
-/* pngset.c */
-extern PNG_EXPORT(void,png_set_asm_flags)
- PNGARG((png_structp png_ptr, png_uint_32 asm_flags));
-
-/* pngset.c */
-extern PNG_EXPORT(void,png_set_mmx_thresholds)
- PNGARG((png_structp png_ptr, png_byte mmx_bitdepth_threshold,
- png_uint_32 mmx_rowbytes_threshold));
-
-#endif /* PNG_MMX_CODE_SUPPORTED */
-
-#if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
-/* pngget.c */
-extern PNG_EXPORT(png_uint_32,png_get_asm_flagmask)
- PNGARG((int flag_select));
-
-/* pngget.c */
-extern PNG_EXPORT(png_uint_32,png_get_asm_flags)
- PNGARG((png_structp png_ptr));
-#endif /* PNG_ASSEMBLER_CODE_SUPPORTED */
-
-
-/* png.c, pnggccrd.c, or pngvcrd.c */
-extern PNG_EXPORT(int,png_mmx_support) PNGARG((void));
-
/* Strip the prepended error numbers ("#nnn ") from error and warning
* messages before passing them to the error or warning handler. */
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
@@ -2617,6 +2551,17 @@ extern PNG_EXPORT(void,png_save_uint_16)
/* ************************************************************************* */
+/* Various modes of operation. Note that after an init, mode is set to
+ * zero automatically when the structure is created.
+ */
+#define PNG_HAVE_IHDR 0x01
+#define PNG_HAVE_PLTE 0x02
+#define PNG_HAVE_IDAT 0x04
+#define PNG_AFTER_IDAT 0x08 /* Have complete zlib datastream */
+#define PNG_HAVE_IEND 0x10
+#define PNG_HAVE_gAMA 0x20
+#define PNG_HAVE_cHRM 0x40
+
#ifdef __cplusplus
}
#endif
diff --git a/pngconf.h b/pngconf.h
index b701a2f19..b2efdf72b 100644
--- a/pngconf.h
+++ b/pngconf.h
@@ -1,7 +1,7 @@
/* pngconf.h - machine configurable file for libpng
*
- * libpng version 1.4.0beta19 - May 15, 2007
+ * libpng version 1.4.0beta20 - May 15, 2007
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2007 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@@ -351,6 +351,38 @@
/* Other defines for things like memory and the like can go here. */
+/* This controls how fine the dithering gets. As this allocates
+ * a largish chunk of memory (32K), those who are not as concerned
+ * with dithering quality can decrease some or all of these.
+ */
+#ifndef PNG_DITHER_RED_BITS
+# define PNG_DITHER_RED_BITS 5
+#endif
+#ifndef PNG_DITHER_GREEN_BITS
+# define PNG_DITHER_GREEN_BITS 5
+#endif
+#ifndef PNG_DITHER_BLUE_BITS
+# define PNG_DITHER_BLUE_BITS 5
+#endif
+
+/* This controls how fine the gamma correction becomes when you
+ * are only interested in 8 bits anyway. Increasing this value
+ * results in more memory being used, and more pow() functions
+ * being called to fill in the gamma tables. Don't set this value
+ * less then 8, and even that may not work (I haven't tested it).
+ */
+
+#ifndef PNG_MAX_GAMMA_8
+# define PNG_MAX_GAMMA_8 11
+#endif
+
+/* This controls how much a difference in gamma we can tolerate before
+ * we actually start doing gamma conversion.
+ */
+#ifndef PNG_GAMMA_THRESHOLD
+# define PNG_GAMMA_THRESHOLD 0.05
+#endif
+
/* The following uses const char * instead of char * for error
* and warning message functions, so some compilers won't complain.
* If you do not want to use const, define PNG_NO_CONST here.
@@ -631,39 +663,6 @@
# define PNG_EASY_ACCESS_SUPPORTED
#endif
-/* PNG_ASSEMBLER_CODE was enabled by default in version 1.2.0
- * even when PNG_USE_PNGVCRD or PNG_USE_PNGGCCRD is not defined.
- *
- * PNG_NO_ASSEMBLER_CODE disables use of all assembler code and optimized C,
- * and removes or includes several functions in the API.
- *
- * PNG_NO_MMX_CODE disables the use of MMX code without changing the API.
- * When MMX code is off, then optimized C replacement functions are used.
-*/
-#if defined(PNG_READ_SUPPORTED) && !defined(PNG_NO_ASSEMBLER_CODE)
-# ifndef PNG_ASSEMBLER_CODE_SUPPORTED
-# define PNG_ASSEMBLER_CODE_SUPPORTED
-# endif
-# if defined(XP_MACOSX) && !defined(PNG_NO_MMX_CODE)
- /* work around Intel-Mac compiler bug */
-# define PNG_NO_MMX_CODE
-# endif
-# if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE) && \
- defined(__MMX__)
-# define PNG_MMX_CODE_SUPPORTED
-# endif
-# if !defined(PNG_USE_PNGGCCRD) && !defined(PNG_NO_MMX_CODE) && \
- !defined(PNG_USE_PNGVCRD) && defined(__MMX__)
-# define PNG_USE_PNGGCCRD
-# endif
-#endif
-
-/* If you are sure that you don't need thread safety and you are compiling
- with PNG_USE_PNGCCRD for an MMX application, you can define this for
- faster execution. See pnggccrd.c.
-#define PNG_THREAD_UNSAFE_OK
-*/
-
#if !defined(PNG_NO_USER_MEM) && !defined(PNG_USER_MEM_SUPPORTED)
# define PNG_USER_MEM_SUPPORTED
#endif
@@ -1020,6 +1019,7 @@ typedef unsigned char png_byte;
#else
typedef size_t png_size_t;
#endif
+#define png_sizeof(x) sizeof(x)
/* The following is needed for medium model support. It cannot be in the
* PNG_INTERNAL section. Needs modification for other compilers besides
@@ -1343,6 +1343,27 @@ typedef char FAR * FAR * FAR * png_charppp;
# define png_memcpy memcpy
# define png_memset memset
# define png_sprintf sprintf
+# ifndef PNG_NO_SNPRINTF
+# ifdef _MSC_VER
+# define png_snprintf _snprintf /* Added to v 1.2.19 */
+# define png_snprintf2 _snprintf
+# define png_snprintf6 _snprintf
+# else
+# define png_snprintf snprintf /* Added to v 1.2.19 */
+# define png_snprintf2 snprintf
+# define png_snprintf6 snprintf
+# endif
+# else
+ /* You don't have or don't want to use snprintf(). Caution: Using
+ * sprintf instead of snprintf exposes your application to accidental
+ * or malevolent buffer overflows. If you don't have snprintf()
+ * as a general rule you should provide one (you can get one from
+ * Portable OpenSSH). */
+# define png_snprintf(s1,n,fmt,x1) sprintf(s1,fmt,x1)
+# define png_snprintf2(s1,n,fmt,x1,x2) sprintf(s1,fmt,x1,x2)
+# define png_snprintf6(s1,n,fmt,x1,x2,x3,x4,x5,x6) \
+ sprintf(s1,fmt,x1,x2,x3,x4,x5,x6)
+# endif
# endif
#endif
diff --git a/pngerror.c b/pngerror.c
index 8b57a968c..97dbd66dc 100644
--- a/pngerror.c
+++ b/pngerror.c
@@ -1,9 +1,9 @@
/* pngerror.c - stub functions for i/o and memory allocation
*
- * Last changed in libpng 1.4.0 May 15, 2007
+ * Last changed in libpng 1.4.0 [July 10, 2008]
* For conditions of distribution and use, see copyright notice in png.h
- * Copyright (c) 1998-2007 Glenn Randers-Pehrson
+ * Copyright (c) 1998-2008 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*
@@ -14,21 +14,24 @@
*/
#include "png.h"
+#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
#include "pngpriv.h"
-#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
static void /* PRIVATE */
png_default_error PNGARG((png_structp png_ptr,
png_const_charp error_message));
+#ifndef PNG_NO_WARNINGS
static void /* PRIVATE */
png_default_warning PNGARG((png_structp png_ptr,
png_const_charp warning_message));
+#endif /* PNG_NO_WARNINGS */
/* This function is called whenever there is a fatal error. This function
* should not be changed. If there is a need to handle errors differently,
* you should supply a replacement error function and use png_set_error_fn()
* to replace the error function at run-time.
*/
+#ifndef PNG_NO_ERROR_TEXT
void PNGAPI
png_error(png_structp png_ptr, png_const_charp error_message)
{
@@ -42,19 +45,19 @@ png_error(png_structp png_ptr, png_const_charp error_message)
if (*error_message == '#')
{
int offset;
- for (offset=1; offset<15; offset++)
- if (*(error_message+offset) == ' ')
+ for (offset = 1; offset<15; offset++)
+ if (*(error_message + offset) == ' ')
break;
if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
{
int i;
- for (i=0; i<offset-1; i++)
+ for (i=0; i<offset - 1; i++)
msg[i]=error_message[i+1];
msg[i]='\0';
- error_message=msg;
+ error_message = msg;
}
else
- error_message+=offset;
+ error_message += offset;
}
else
{
@@ -75,7 +78,20 @@ png_error(png_structp png_ptr, png_const_charp error_message)
use the default handler, which will not return. */
png_default_error(png_ptr, error_message);
}
+#else
+void PNGAPI
+png_err(png_structp png_ptr)
+{
+ if (png_ptr != NULL && png_ptr->error_fn != NULL)
+ (*(png_ptr->error_fn))(png_ptr, '\0');
+
+ /* If the custom handler doesn't exist, or if it returns,
+ use the default handler, which will not return. */
+ png_default_error(png_ptr, '\0');
+}
+#endif /* PNG_NO_ERROR_TEXT */
+#ifndef PNG_NO_WARNINGS
/* This function is called whenever there is a non-fatal error. This function
* should not be changed. If there is a need to handle warnings differently,
* you should supply a replacement warning function and use
@@ -94,17 +110,18 @@ png_warning(png_structp png_ptr, png_const_charp warning_message)
{
if (*warning_message == '#')
{
- for (offset=1; offset<15; offset++)
- if (*(warning_message+offset) == ' ')
+ for (offset = 1; offset<15; offset++)
+ if (*(warning_message + offset) == ' ')
break;
}
}
if (png_ptr != NULL && png_ptr->warning_fn != NULL)
- (*(png_ptr->warning_fn))(png_ptr, warning_message+offset);
+ (*(png_ptr->warning_fn))(png_ptr, warning_message + offset);
}
else
- png_default_warning(png_ptr, warning_message+offset);
+ png_default_warning(png_ptr, warning_message + offset);
}
+#endif /* PNG_NO_WARNINGS */
#ifdef PNG_BENIGN_ERRORS_SUPPORTED
void PNGAPI
@@ -129,6 +146,9 @@ static PNG_CONST char png_digit[16] = {
'A', 'B', 'C', 'D', 'E', 'F'
};
+#define PNG_MAX_ERROR_TEXT 64
+
+#if !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT)
static void /* PRIVATE */
png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp
error_message)
@@ -152,36 +172,48 @@ png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp
}
if (error_message == NULL)
- buffer[iout] = 0;
+ buffer[iout] = '\0';
else
{
buffer[iout++] = ':';
buffer[iout++] = ' ';
- png_strncpy(buffer+iout, error_message, 63);
- buffer[iout+63] = 0;
+ png_memcpy(buffer + iout, error_message, PNG_MAX_ERROR_TEXT);
+ buffer[iout + PNG_MAX_ERROR_TEXT - 1] = '\0';
}
}
+#ifdef PNG_READ_SUPPORTED
void PNGAPI
png_chunk_error(png_structp png_ptr, png_const_charp error_message)
{
- char msg[18+64];
+ char msg[18+PNG_MAX_ERROR_TEXT];
if (png_ptr == NULL)
png_error(png_ptr, error_message);
- png_format_buffer(png_ptr, msg, error_message);
- png_error(png_ptr, msg);
+ else
+ {
+ png_format_buffer(png_ptr, msg, error_message);
+ png_error(png_ptr, msg);
+ }
}
+#endif /* PNG_READ_SUPPORTED */
+#endif /* !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT) */
+#ifndef PNG_NO_WARNINGS
void PNGAPI
png_chunk_warning(png_structp png_ptr, png_const_charp warning_message)
{
- char msg[18+64];
+ char msg[18+PNG_MAX_ERROR_TEXT];
if (png_ptr == NULL)
png_warning(png_ptr, warning_message);
- png_format_buffer(png_ptr, msg, warning_message);
- png_warning(png_ptr, msg);
+ else
+ {
+ png_format_buffer(png_ptr, msg, warning_message);
+ png_warning(png_ptr, msg);
+ }
}
+#endif /* PNG_NO_WARNINGS */
+#ifdef PNG_READ_SUPPORTED
#ifdef PNG_BENIGN_ERRORS_SUPPORTED
void PNGAPI
png_chunk_benign_error(png_structp png_ptr, png_const_charp error_message)
@@ -192,6 +224,7 @@ png_chunk_benign_error(png_structp png_ptr, png_const_charp error_message)
png_chunk_error(png_ptr, error_message);
}
#endif
+#endif /* PNG_READ_SUPPORTED */
/* This is the default error handling function. Note that replacements for
* this function MUST NOT RETURN, or the program will likely crash. This
@@ -209,18 +242,18 @@ png_default_error(png_structp png_ptr, png_const_charp error_message)
char error_number[16];
for (offset=0; offset<15; offset++)
{
- error_number[offset] = *(error_message+offset+1);
- if (*(error_message+offset) == ' ')
+ error_number[offset] = *(error_message + offset + 1);
+ if (*(error_message + offset) == ' ')
break;
}
- if((offset > 1) && (offset < 15))
+ if ((offset > 1) && (offset < 15))
{
- error_number[offset-1]='\0';
+ error_number[offset - 1]='\0';
fprintf(stderr, "libpng error no. %s: %s\n", error_number,
- error_message+offset);
+ error_message + offset);
}
else
- fprintf(stderr, "libpng error: %s, offset=%d\n", error_message,offset);
+ fprintf(stderr, "libpng error: %s, offset=%d\n", error_message, offset);
}
else
#endif
@@ -233,7 +266,7 @@ png_default_error(png_structp png_ptr, png_const_charp error_message)
# ifdef USE_FAR_KEYWORD
{
jmp_buf jmpbuf;
- png_memcpy(jmpbuf, png_ptr->jmpbuf, sizeof(jmp_buf));
+ png_memcpy(jmpbuf, png_ptr->jmpbuf, png_sizeof(jmp_buf));
longjmp(jmpbuf, 1);
}
# else
@@ -244,12 +277,11 @@ png_default_error(png_structp png_ptr, png_const_charp error_message)
PNG_ABORT();
#endif
#ifdef PNG_NO_CONSOLE_IO
- /* make compiler happy */ ;
- if (&error_message != NULL)
- return;
+ error_message = error_message; /* make compiler happy */
#endif
}
+#ifndef PNG_NO_WARNINGS
/* 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 them to. In the default configuration, png_ptr is
@@ -266,15 +298,15 @@ png_default_warning(png_structp png_ptr, png_const_charp warning_message)
char warning_number[16];
for (offset=0; offset<15; offset++)
{
- warning_number[offset]=*(warning_message+offset+1);
- if (*(warning_message+offset) == ' ')
+ warning_number[offset]=*(warning_message + offset + 1);
+ if (*(warning_message + offset) == ' ')
break;
}
- if((offset > 1) && (offset < 15))
+ if ((offset > 1) && (offset < 15))
{
- warning_number[offset-1]='\0';
+ warning_number[offset + 1]='\0';
fprintf(stderr, "libpng warning no. %s: %s\n", warning_number,
- warning_message+offset);
+ warning_message + offset);
}
else
fprintf(stderr, "libpng warning: %s\n", warning_message);
@@ -283,14 +315,11 @@ png_default_warning(png_structp png_ptr, png_const_charp warning_message)
# endif
fprintf(stderr, "libpng warning: %s\n", warning_message);
#else
- /* make compiler happy */ ;
- if (warning_message)
- return;
+ warning_message = warning_message; /* make compiler happy */
#endif
- /* make compiler happy */ ;
- if (png_ptr)
- return;
+ png_ptr = png_ptr; /* make compiler happy */
}
+#endif /* PNG_NO_WARNINGS */
/* This function is called when the application wants to use another method
* of handling errors and warnings. Note that the error function MUST NOT
@@ -326,7 +355,7 @@ png_get_error_ptr(png_structp png_ptr)
void PNGAPI
png_set_strip_error_numbers(png_structp png_ptr, png_uint_32 strip_mode)
{
- if(png_ptr != NULL)
+ if (png_ptr != NULL)
{
png_ptr->flags &=
((~(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))&strip_mode);
diff --git a/pnggccrd.c b/pnggccrd.c
index 1988f6485..e69de29bb 100644
--- a/pnggccrd.c
+++ b/pnggccrd.c
@@ -1,5452 +0,0 @@
-
-/* pnggccrd.c - mixed C/assembler version of utilities to read a PNG file
- *
- * For Intel x86 CPU (Pentium-MMX or later) and GNU C compiler.
- *
- * See http://www.intel.com/drg/pentiumII/appnotes/916/916.htm
- * and http://www.intel.com/drg/pentiumII/appnotes/923/923.htm
- * for Intel's performance analysis of the MMX vs. non-MMX code.
- *
- * Last changed in libpng 1.4.0 May 15, 2007
- * For conditions of distribution and use, see copyright notice in png.h
- * Copyright (c) 1998-2007 Glenn Randers-Pehrson
- * Copyright (c) 1998, Intel Corporation
- *
- * Based on MSVC code contributed by Nirav Chhatrapati, Intel Corp., 1998.
- * Interface to libpng contributed by Gilles Vollant, 1999.
- * GNU C port by Greg Roelofs, 1999-2001.
- *
- * Lines 2350-4300 converted in place with intel2gas 1.3.1:
- *
- * intel2gas -mdI pnggccrd.c.partially-msvc -o pnggccrd.c
- *
- * and then cleaned up by hand. See http://hermes.terminal.at/intel2gas/ .
- *
- * NOTE: A sufficiently recent version of GNU as (or as.exe under DOS/Windows)
- * is required to assemble the newer MMX instructions such as movq.
- * For djgpp, see
- *
- * ftp://ftp.simtel.net/pub/simtelnet/gnu/djgpp/v2gnu/bnu281b.zip
- *
- * (or a later version in the same directory). For Linux, check your
- * distribution's web site(s) or try these links:
- *
- * http://rufus.w3.org/linux/RPM/binutils.html
- * http://www.debian.org/Packages/stable/devel/binutils.html
- * ftp://ftp.slackware.com/pub/linux/slackware/slackware/slakware/d1/
- * binutils.tgz
- *
- * For other platforms, see the main GNU site:
- *
- * ftp://ftp.gnu.org/pub/gnu/binutils/
- *
- * Version 2.5.2l.15 is definitely too old...
- */
-
-/*
- * TEMPORARY PORTING NOTES AND CHANGELOG (mostly by Greg Roelofs)
- * =====================================
- *
- * 19991006:
- * - fixed sign error in post-MMX cleanup code (16- & 32-bit cases)
- *
- * 19991007:
- * - additional optimizations (possible or definite):
- * x [DONE] write MMX code for 64-bit case (pixel_bytes == 8) [not tested]
- * - write MMX code for 48-bit case (pixel_bytes == 6)
- * - figure out what's up with 24-bit case (pixel_bytes == 3):
- * why subtract 8 from width_mmx in the pass 4/5 case?
- * (only width_mmx case) (near line 1606)
- * x [DONE] replace pixel_bytes within each block with the true
- * constant value (or are compilers smart enough to do that?)
- * - rewrite all MMX interlacing code so it's aligned with
- * the *beginning* of the row buffer, not the end. This
- * would not only allow one to eliminate half of the memory
- * writes for odd passes (that is, pass == odd), it may also
- * eliminate some unaligned-data-access exceptions (assuming
- * there's a penalty for not aligning 64-bit accesses on
- * 64-bit boundaries). The only catch is that the "leftover"
- * pixel(s) at the end of the row would have to be saved,
- * but there are enough unused MMX registers in every case,
- * so this is not a problem. A further benefit is that the
- * post-MMX cleanup code (C code) in at least some of the
- * cases could be done within the assembler block.
- * x [DONE] the "v3 v2 v1 v0 v7 v6 v5 v4" comments are confusing,
- * inconsistent, and don't match the MMX Programmer's Reference
- * Manual conventions anyway. They should be changed to
- * "b7 b6 b5 b4 b3 b2 b1 b0," where b0 indicates the byte that
- * was lowest in memory (e.g., corresponding to a left pixel)
- * and b7 is the byte that was highest (e.g., a right pixel).
- *
- * 19991016:
- * - Brennan's Guide notwithstanding, gcc under Linux does *not*
- * want globals prefixed by underscores when referencing them--
- * i.e., if the variable is const4, then refer to it as const4,
- * not _const4. This seems to be a djgpp-specific requirement.
- * Also, such variables apparently *must* be declared outside
- * of functions; neither static nor automatic variables work if
- * defined within the scope of a single function, but both
- * static and truly global (multi-module) variables work fine.
- *
- * 19991023:
- * - fixed png_combine_row() non-MMX replication bug (odd passes only?)
- * - switched from string-concatenation-with-macros to cleaner method of
- * renaming global variables for djgpp--i.e., always use prefixes in
- * inlined assembler code (== strings) and conditionally rename the
- * variables, not the other way around. Hence _const4, _mask8_0, etc.
- *
- * 19991024:
- * - fixed mmxsupport()/png_do_read_interlace() first-row bug
- * This one was severely weird: even though mmxsupport() doesn't touch
- * ebx (where "row" pointer was stored), it nevertheless managed to zero
- * the register (even in static/non-fPIC code--see below), which in turn
- * caused png_do_read_interlace() to return prematurely on the first row of
- * interlaced images (i.e., without expanding the interlaced pixels).
- * Inspection of the generated assembly code didn't turn up any clues,
- * although it did point at a minor optimization (i.e., get rid of
- * mmx_supported_local variable and just use eax). Possibly the CPUID
- * instruction is more destructive than it looks? (Not yet checked.)
- * - "info gcc" was next to useless, so compared fPIC and non-fPIC assembly
- * listings... Apparently register spillage has to do with ebx, since
- * it's used to index the global offset table. Commenting it out of the
- * input-reg lists in png_combine_row() eliminated compiler barfage, so
- * ifdef'd with __PIC__ macro: if defined, use a global for unmask
- *
- * 19991107:
- * - verified CPUID clobberage: 12-char string constant ("GenuineIntel",
- * "AuthenticAMD", etc.) placed in ebx:ecx:edx. Still need to polish.
- *
- * 19991120:
- * - made "diff" variable (now "_dif") global to simplify conversion of
- * filtering routines (running out of regs, sigh). "diff" is still used
- * in interlacing routines, however.
- * - fixed up both versions of mmxsupport() (ORIG_THAT_USED_TO_CLOBBER_EBX
- * macro determines which is used); original not yet tested.
- *
- * 20000213:
- * - when compiling with gcc, be sure to use -fomit-frame-pointer
- *
- * 20000319:
- * - fixed a register-name typo in png_do_read_interlace(), default (MMX) case,
- * pass == 4 or 5, that caused visible corruption of interlaced images
- *
- * 20000623:
- * - Various problems were reported with gcc 2.95.2 in the Cygwin environment,
- * many of the form "forbidden register 0 (ax) was spilled for class AREG."
- * This is explained at http://gcc.gnu.org/fom_serv/cache/23.html, and
- * Chuck Wilson supplied a patch involving dummy output registers. See
- * http://sourceforge.net/bugs/?func=detailbug&bug_id=108741&group_id=5624
- * for the original (anonymous) SourceForge bug report.
- *
- * 20000706:
- * - Chuck Wilson passed along these remaining gcc 2.95.2 errors:
- * pnggccrd.c: In function `png_combine_row':
- * pnggccrd.c:525: more than 10 operands in `asm'
- * pnggccrd.c:669: more than 10 operands in `asm'
- * pnggccrd.c:828: more than 10 operands in `asm'
- * pnggccrd.c:994: more than 10 operands in `asm'
- * pnggccrd.c:1177: more than 10 operands in `asm'
- * They are all the same problem and can be worked around by using the
- * global _unmask variable unconditionally, not just in the -fPIC case.
- * Reportedly earlier versions of gcc also have the problem with more than
- * 10 operands; they just don't report it. Much strangeness ensues, etc.
- *
- * 20000729:
- * - enabled png_read_filter_row_mmx_up() (shortest remaining unconverted
- * MMX routine); began converting png_read_filter_row_mmx_sub()
- * - to finish remaining sections:
- * - clean up indentation and comments
- * - preload local variables
- * - add output and input regs (order of former determines numerical
- * mapping of latter)
- * - avoid all usage of ebx (including bx, bh, bl) register [20000823]
- * - remove "$" from addressing of Shift and Mask variables [20000823]
- *
- * 20000731:
- * - global union vars causing segfaults in png_read_filter_row_mmx_sub()?
- *
- * 20000822:
- * - ARGH, stupid png_read_filter_row_mmx_sub() segfault only happens with
- * shared-library (-fPIC) version! Code works just fine as part of static
- * library. Damn damn damn damn damn, should have tested that sooner.
- * ebx is getting clobbered again (explicitly this time); need to save it
- * on stack or rewrite asm code to avoid using it altogether. Blargh!
- *
- * 20000823:
- * - first section was trickiest; all remaining sections have ebx -> edx now.
- * (-fPIC works again.) Also added missing underscores to various Shift*
- * and *Mask* globals and got rid of leading "$" signs.
- *
- * 20000826:
- * - added visual separators to help navigate microscopic printed copies
- * (http://pobox.com/~newt/code/gpr-latest.zip, mode 10); started working
- * on png_read_filter_row_mmx_avg()
- *
- * 20000828:
- * - finished png_read_filter_row_mmx_avg(): only Paeth left! (930 lines...)
- * What the hell, did png_read_filter_row_mmx_paeth(), too. Comments not
- * cleaned up/shortened in either routine, but functionality is complete
- * and seems to be working fine.
- *
- * 20000829:
- * - ahhh, figured out last(?) bit of gcc/gas asm-fu: if register is listed
- * as an input reg (with dummy output variables, etc.), then it *cannot*
- * also appear in the clobber list or gcc 2.95.2 will barf. The solution
- * is simple enough...
- *
- * 20000914:
- * - bug in png_read_filter_row_mmx_avg(): 16-bit grayscale not handled
- * correctly (but 48-bit RGB just fine)
- *
- * 20000916:
- * - fixed bug in png_read_filter_row_mmx_avg(), bpp == 2 case; three errors:
- * - "_ShiftBpp.use = 24;" should have been "_ShiftBpp.use = 16;"
- * - "_ShiftRem.use = 40;" should have been "_ShiftRem.use = 48;"
- * - "psllq _ShiftRem, %%mm2" should have been "psrlq _ShiftRem, %%mm2"
- *
- * 20010101:
- * - added new png_init_mmx_flags() function (here only because it needs to
- * call mmxsupport(), which should probably become global png_mmxsupport());
- * modified other MMX routines to run conditionally (png_ptr->asm_flags)
- *
- * 20010103:
- * - renamed mmxsupport() to png_mmx_support(), with auto-set of mmx_supported,
- * and made it public; moved png_init_mmx_flags() to png.c as internal func
- *
- * 20010104:
- * - removed dependency on png_read_filter_row_c() (C code already duplicated
- * within MMX version of png_read_filter_row()) so no longer necessary to
- * compile it into pngrutil.o
- *
- * 20010310:
- * - fixed buffer-overrun bug in png_combine_row() C code (non-MMX)
- *
- * 20020304:
- * - eliminated incorrect use of width_mmx in pixel_bytes == 8 case
- *
- * 20040724:
- * - more tinkering with clobber list at lines 4529 and 5033, to get
- * it to compile on gcc-3.4.
- *
- * 20060803: patch to compile on x86_64
- *
- * STILL TO DO:
- * - test png_do_read_interlace() 64-bit case (pixel_bytes == 8)
- * - write MMX code for 48-bit case (pixel_bytes == 6)
- * - figure out what's up with 24-bit case (pixel_bytes == 3):
- * why subtract 8 from width_mmx in the pass 4/5 case?
- * (only width_mmx case) (near line 1606)
- * - rewrite all MMX interlacing code so it's aligned with beginning
- * of the row buffer, not the end (see 19991007 for details)
- * x pick one version of mmxsupport() and get rid of the other
- * - add error messages to any remaining bogus default cases
- * - enable pixel_depth == 8 cases in png_read_filter_row()? (test speed)
- * x add support for runtime enable/disable/query of various MMX routines
- */
-
-#include "png.h"
-#include "pngpriv.h"
-
-#if defined(PNG_USE_PNGGCCRD)
-
-int PNGAPI png_mmx_support(void);
-
-#ifdef PNG_USE_LOCAL_ARRAYS
-static const int FARDATA png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
-static const int FARDATA png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
-static const int FARDATA png_pass_width[7] = {8, 4, 4, 2, 2, 1, 1};
-#endif
-
-#if defined(PNG_MMX_CODE_SUPPORTED)
-/* djgpp, Win32, Cygwin, and OS2 add their own underscores to global variables,
- * so define them without: */
-#if defined(__DJGPP__) || defined(WIN32) || defined(__CYGWIN__) || \
- defined(__OS2__)
-# define _mmx_supported mmx_supported
-# define _const4 const4
-# define _const6 const6
-# define _mask8_0 mask8_0
-# define _mask16_1 mask16_1
-# define _mask16_0 mask16_0
-# define _mask24_2 mask24_2
-# define _mask24_1 mask24_1
-# define _mask24_0 mask24_0
-# define _mask32_3 mask32_3
-# define _mask32_2 mask32_2
-# define _mask32_1 mask32_1
-# define _mask32_0 mask32_0
-# define _mask48_5 mask48_5
-# define _mask48_4 mask48_4
-# define _mask48_3 mask48_3
-# define _mask48_2 mask48_2
-# define _mask48_1 mask48_1
-# define _mask48_0 mask48_0
-# define _LBCarryMask LBCarryMask
-# define _HBClearMask HBClearMask
-# define _ActiveMask ActiveMask
-# define _ActiveMask2 ActiveMask2
-# define _ActiveMaskEnd ActiveMaskEnd
-# define _ShiftBpp ShiftBpp
-# define _ShiftRem ShiftRem
-#ifdef PNG_THREAD_UNSAFE_OK
-# define _unmask unmask
-# define _FullLength FullLength
-# define _MMXLength MMXLength
-# define _dif dif
-# define _patemp patemp
-# define _pbtemp pbtemp
-# define _pctemp pctemp
-#endif
-#endif
-
-
-/* These constants are used in the inlined MMX assembly code.
- Ignore gcc's "At top level: defined but not used" warnings. */
-
-/* GRR 20000706: originally _unmask was needed only when compiling with -fPIC,
- * since that case uses the %ebx register for indexing the Global Offset Table
- * and there were no other registers available. But gcc 2.95 and later emit
- * "more than 10 operands in `asm'" errors when %ebx is used to preload unmask
- * in the non-PIC case, so we'll just use the global unconditionally now.
- */
-#ifdef PNG_THREAD_UNSAFE_OK
-static int _unmask;
-#endif
-
-static unsigned long long _mask8_0 = 0x0102040810204080LL;
-
-static unsigned long long _mask16_1 = 0x0101020204040808LL;
-static unsigned long long _mask16_0 = 0x1010202040408080LL;
-
-static unsigned long long _mask24_2 = 0x0101010202020404LL;
-static unsigned long long _mask24_1 = 0x0408080810101020LL;
-static unsigned long long _mask24_0 = 0x2020404040808080LL;
-
-static unsigned long long _mask32_3 = 0x0101010102020202LL;
-static unsigned long long _mask32_2 = 0x0404040408080808LL;
-static unsigned long long _mask32_1 = 0x1010101020202020LL;
-static unsigned long long _mask32_0 = 0x4040404080808080LL;
-
-static unsigned long long _mask48_5 = 0x0101010101010202LL;
-static unsigned long long _mask48_4 = 0x0202020204040404LL;
-static unsigned long long _mask48_3 = 0x0404080808080808LL;
-static unsigned long long _mask48_2 = 0x1010101010102020LL;
-static unsigned long long _mask48_1 = 0x2020202040404040LL;
-static unsigned long long _mask48_0 = 0x4040808080808080LL;
-
-static unsigned long long _const4 = 0x0000000000FFFFFFLL;
-//static unsigned long long _const5 = 0x000000FFFFFF0000LL; // NOT USED
-static unsigned long long _const6 = 0x00000000000000FFLL;
-
-// These are used in the row-filter routines and should/would be local
-// variables if not for gcc addressing limitations.
-// WARNING: Their presence probably defeats the thread safety of libpng.
-
-#ifdef PNG_THREAD_UNSAFE_OK
-static png_uint_32 _FullLength;
-static png_uint_32 _MMXLength;
-static int _dif;
-static int _patemp; // temp variables for Paeth routine
-static int _pbtemp;
-static int _pctemp;
-#endif
-
-void /* PRIVATE */
-png_squelch_warnings(void)
-{
-#ifdef PNG_THREAD_UNSAFE_OK
- _dif = _dif;
- _patemp = _patemp;
- _pbtemp = _pbtemp;
- _pctemp = _pctemp;
- _MMXLength = _MMXLength;
-#endif
- _const4 = _const4;
- _const6 = _const6;
- _mask8_0 = _mask8_0;
- _mask16_1 = _mask16_1;
- _mask16_0 = _mask16_0;
- _mask24_2 = _mask24_2;
- _mask24_1 = _mask24_1;
- _mask24_0 = _mask24_0;
- _mask32_3 = _mask32_3;
- _mask32_2 = _mask32_2;
- _mask32_1 = _mask32_1;
- _mask32_0 = _mask32_0;
- _mask48_5 = _mask48_5;
- _mask48_4 = _mask48_4;
- _mask48_3 = _mask48_3;
- _mask48_2 = _mask48_2;
- _mask48_1 = _mask48_1;
- _mask48_0 = _mask48_0;
-}
-#endif /* PNG_MMX_CODE_SUPPORTED */
-
-
-static int _mmx_supported = 2;
-
-/*===========================================================================*/
-/* */
-/* P N G _ C O M B I N E _ R O W */
-/* */
-/*===========================================================================*/
-
-#if defined(PNG_HAVE_MMX_COMBINE_ROW)
-
-#define BPP2 2
-#define BPP3 3 /* bytes per pixel (a.k.a. pixel_bytes) */
-#define BPP4 4
-#define BPP6 6 /* (defined only to help avoid cut-and-paste errors) */
-#define BPP8 8
-
-/* Combines the row recently read in with the previous 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 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. */
-
-/* Use this routine for the x86 platform - it uses a faster MMX routine
- if the machine supports MMX. */
-
-void /* PRIVATE */
-png_combine_row(png_structp png_ptr, png_bytep row, int mask)
-{
- png_debug(1, "in png_combine_row (pnggccrd.c)\n");
-
-#if defined(PNG_MMX_CODE_SUPPORTED)
- if (_mmx_supported == 2) {
- /* this should have happened in png_init_mmx_flags() already */
- png_warning(png_ptr, "asm_flags may not have been initialized");
- png_mmx_support();
- }
-#endif
-
- if (mask == 0xff)
- {
- png_debug(2,"mask == 0xff: doing single png_memcpy()\n");
- png_memcpy(row, png_ptr->row_buf + 1,
- PNG_ROWBYTES(png_ptr->row_info.pixel_depth,png_ptr->width));
- }
- else /* (png_combine_row() is never called with mask == 0) */
- {
- switch (png_ptr->row_info.pixel_depth)
- {
- case 1: /* png_ptr->row_info.pixel_depth */
- {
- png_bytep sp;
- png_bytep dp;
- int s_inc, s_start, s_end;
- int m;
- int shift;
- png_uint_32 i;
-
- sp = png_ptr->row_buf + 1;
- dp = row;
- m = 0x80;
-#if defined(PNG_READ_PACKSWAP_SUPPORTED)
- if (png_ptr->transformations & PNG_PACKSWAP)
- {
- s_start = 0;
- s_end = 7;
- s_inc = 1;
- }
- else
-#endif
- {
- s_start = 7;
- s_end = 0;
- s_inc = -1;
- }
-
- shift = s_start;
-
- for (i = 0; i < png_ptr->width; i++)
- {
- if (m & mask)
- {
- int value;
-
- value = (*sp >> shift) & 0x1;
- *dp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
- *dp |= (png_byte)(value << shift);
- }
-
- if (shift == s_end)
- {
- shift = s_start;
- sp++;
- dp++;
- }
- else
- shift += s_inc;
-
- if (m == 1)
- m = 0x80;
- else
- m >>= 1;
- }
- break;
- }
-
- case 2: /* png_ptr->row_info.pixel_depth */
- {
- png_bytep sp;
- png_bytep dp;
- int s_start, s_end, s_inc;
- int m;
- int shift;
- png_uint_32 i;
- int value;
-
- sp = png_ptr->row_buf + 1;
- dp = row;
- m = 0x80;
-#if defined(PNG_READ_PACKSWAP_SUPPORTED)
- if (png_ptr->transformations & PNG_PACKSWAP)
- {
- s_start = 0;
- s_end = 6;
- s_inc = 2;
- }
- else
-#endif
- {
- s_start = 6;
- s_end = 0;
- s_inc = -2;
- }
-
- shift = s_start;
-
- for (i = 0; i < png_ptr->width; i++)
- {
- if (m & mask)
- {
- value = (*sp >> shift) & 0x3;
- *dp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
- *dp |= (png_byte)(value << shift);
- }
-
- if (shift == s_end)
- {
- shift = s_start;
- sp++;
- dp++;
- }
- else
- shift += s_inc;
- if (m == 1)
- m = 0x80;
- else
- m >>= 1;
- }
- break;
- }
-
- case 4: /* png_ptr->row_info.pixel_depth */
- {
- png_bytep sp;
- png_bytep dp;
- int s_start, s_end, s_inc;
- int m;
- int shift;
- png_uint_32 i;
- int value;
-
- sp = png_ptr->row_buf + 1;
- dp = row;
- m = 0x80;
-#if defined(PNG_READ_PACKSWAP_SUPPORTED)
- if (png_ptr->transformations & PNG_PACKSWAP)
- {
- s_start = 0;
- s_end = 4;
- s_inc = 4;
- }
- else
-#endif
- {
- s_start = 4;
- s_end = 0;
- s_inc = -4;
- }
- shift = s_start;
-
- for (i = 0; i < png_ptr->width; i++)
- {
- if (m & mask)
- {
- value = (*sp >> shift) & 0xf;
- *dp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
- *dp |= (png_byte)(value << shift);
- }
-
- if (shift == s_end)
- {
- shift = s_start;
- sp++;
- dp++;
- }
- else
- shift += s_inc;
- if (m == 1)
- m = 0x80;
- else
- m >>= 1;
- }
- break;
- }
-
- case 8: /* png_ptr->row_info.pixel_depth */
- {
- png_bytep srcptr;
- png_bytep dstptr;
-
-#if defined(PNG_MMX_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK)
- if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)
- /* && _mmx_supported */ )
- {
- png_uint_32 len;
- int diff;
- int dummy_value_a; // fix 'forbidden register spilled' error
- int dummy_value_d;
- int dummy_value_c;
- int dummy_value_S;
- int dummy_value_D;
- _unmask = ~mask; // global variable for -fPIC version
- srcptr = png_ptr->row_buf + 1;
- dstptr = row;
- len = png_ptr->width &~7; // reduce to multiple of 8
- diff = (int) (png_ptr->width & 7); // amount lost
-
- __asm__ __volatile__ (
- "movd _unmask, %%mm7 \n\t" // load bit pattern
- "psubb %%mm6, %%mm6 \n\t" // zero mm6
- "punpcklbw %%mm7, %%mm7 \n\t"
- "punpcklwd %%mm7, %%mm7 \n\t"
- "punpckldq %%mm7, %%mm7 \n\t" // fill reg with 8 masks
-
- "movq _mask8_0, %%mm0 \n\t"
- "pand %%mm7, %%mm0 \n\t" // nonzero if keep byte
- "pcmpeqb %%mm6, %%mm0 \n\t" // zeros->1s, v versa
-
-// preload "movl len, %%ecx \n\t" // load length of line
-// preload "movl srcptr, %%esi \n\t" // load source
-// preload "movl dstptr, %%edi \n\t" // load dest
-
- "cmpl $0, %%ecx \n\t" // len == 0 ?
- "je mainloop8end \n\t"
-
- "mainloop8: \n\t"
- "movq (%%esi), %%mm4 \n\t" // *srcptr
- "pand %%mm0, %%mm4 \n\t"
- "movq %%mm0, %%mm6 \n\t"
- "pandn (%%edi), %%mm6 \n\t" // *dstptr
- "por %%mm6, %%mm4 \n\t"
- "movq %%mm4, (%%edi) \n\t"
- "addl $8, %%esi \n\t" // inc by 8 bytes processed
- "addl $8, %%edi \n\t"
- "subl $8, %%ecx \n\t" // dec by 8 pixels processed
- "ja mainloop8 \n\t"
-
- "mainloop8end: \n\t"
-// preload "movl diff, %%ecx \n\t" // (diff is in eax)
- "movl %%eax, %%ecx \n\t"
- "cmpl $0, %%ecx \n\t"
- "jz end8 \n\t"
-// preload "movl mask, %%edx \n\t"
- "sall $24, %%edx \n\t" // make low byte, high byte
-
- "secondloop8: \n\t"
- "sall %%edx \n\t" // move high bit to CF
- "jnc skip8 \n\t" // if CF = 0
- "movb (%%esi), %%al \n\t"
- "movb %%al, (%%edi) \n\t"
-
- "skip8: \n\t"
- "incl %%esi \n\t"
- "incl %%edi \n\t"
- "decl %%ecx \n\t"
- "jnz secondloop8 \n\t"
-
- "end8: \n\t"
- "EMMS \n\t" // DONE
-
- : "=a" (dummy_value_a), // output regs (dummy)
- "=d" (dummy_value_d),
- "=c" (dummy_value_c),
- "=S" (dummy_value_S),
- "=D" (dummy_value_D)
-
- : "3" (srcptr), // esi // input regs
- "4" (dstptr), // edi
- "0" (diff), // eax
-// was (unmask) "b" RESERVED // ebx // Global Offset Table idx
- "2" (len), // ecx
- "1" (mask) // edx
-
-#if 0 /* MMX regs (%mm0, etc.) not supported by gcc 2.7.2.3 or egcs 1.1 */
- : "%mm0", "%mm4", "%mm6", "%mm7" // clobber list
-#endif
- );
- }
- else /* mmx _not supported - Use modified C routine */
-#endif /* PNG_MMX_CODE_SUPPORTED */
- {
- register png_uint_32 i;
- png_uint_32 initial_val = png_pass_start[png_ptr->pass];
- /* png.c: png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; */
- register int stride = png_pass_inc[png_ptr->pass];
- /* png.c: png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; */
- register int rep_bytes = png_pass_width[png_ptr->pass];
- /* png.c: png_pass_width[] = {8, 4, 4, 2, 2, 1, 1}; */
- png_uint_32 len = png_ptr->width &~7; /* reduce to mult. of 8 */
- int diff = (int) (png_ptr->width & 7); /* amount lost */
- register png_uint_32 final_val = len; /* GRR bugfix */
-
- srcptr = png_ptr->row_buf + 1 + initial_val;
- dstptr = row + initial_val;
-
- for (i = initial_val; i < final_val; i += stride)
- {
- png_memcpy(dstptr, srcptr, rep_bytes);
- srcptr += stride;
- dstptr += stride;
- }
- if (diff) /* number of leftover pixels: 3 for pngtest */
- {
- final_val+=diff /* *BPP1 */ ;
- for (; i < final_val; i += stride)
- {
- if (rep_bytes > (int)(final_val-i))
- rep_bytes = (int)(final_val-i);
- png_memcpy(dstptr, srcptr, rep_bytes);
- srcptr += stride;
- dstptr += stride;
- }
- }
-
- } /* end of else (_mmx_supported) */
-
- break;
- } /* end 8 bpp */
-
- case 16: /* png_ptr->row_info.pixel_depth */
- {
- png_bytep srcptr;
- png_bytep dstptr;
-
-#if defined(PNG_MMX_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK)
- if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)
- /* && _mmx_supported */ )
- {
- png_uint_32 len;
- int diff;
- int dummy_value_a; // fix 'forbidden register spilled' error
- int dummy_value_d;
- int dummy_value_c;
- int dummy_value_S;
- int dummy_value_D;
- _unmask = ~mask; // global variable for -fPIC version
- srcptr = png_ptr->row_buf + 1;
- dstptr = row;
- len = png_ptr->width &~7; // reduce to multiple of 8
- diff = (int) (png_ptr->width & 7); // amount lost //
-
- __asm__ __volatile__ (
- "movd _unmask, %%mm7 \n\t" // load bit pattern
- "psubb %%mm6, %%mm6 \n\t" // zero mm6
- "punpcklbw %%mm7, %%mm7 \n\t"
- "punpcklwd %%mm7, %%mm7 \n\t"
- "punpckldq %%mm7, %%mm7 \n\t" // fill reg with 8 masks
-
- "movq _mask16_0, %%mm0 \n\t"
- "movq _mask16_1, %%mm1 \n\t"
-
- "pand %%mm7, %%mm0 \n\t"
- "pand %%mm7, %%mm1 \n\t"
-
- "pcmpeqb %%mm6, %%mm0 \n\t"
- "pcmpeqb %%mm6, %%mm1 \n\t"
-
-// preload "movl len, %%ecx \n\t" // load length of line
-// preload "movl srcptr, %%esi \n\t" // load source
-// preload "movl dstptr, %%edi \n\t" // load dest
-
- "cmpl $0, %%ecx \n\t"
- "jz mainloop16end \n\t"
-
- "mainloop16: \n\t"
- "movq (%%esi), %%mm4 \n\t"
- "pand %%mm0, %%mm4 \n\t"
- "movq %%mm0, %%mm6 \n\t"
- "movq (%%edi), %%mm7 \n\t"
- "pandn %%mm7, %%mm6 \n\t"
- "por %%mm6, %%mm4 \n\t"
- "movq %%mm4, (%%edi) \n\t"
-
- "movq 8(%%esi), %%mm5 \n\t"
- "pand %%mm1, %%mm5 \n\t"
- "movq %%mm1, %%mm7 \n\t"
- "movq 8(%%edi), %%mm6 \n\t"
- "pandn %%mm6, %%mm7 \n\t"
- "por %%mm7, %%mm5 \n\t"
- "movq %%mm5, 8(%%edi) \n\t"
-
- "addl $16, %%esi \n\t" // inc by 16 bytes processed
- "addl $16, %%edi \n\t"
- "subl $8, %%ecx \n\t" // dec by 8 pixels processed
- "ja mainloop16 \n\t"
-
- "mainloop16end: \n\t"
-// preload "movl diff, %%ecx \n\t" // (diff is in eax)
- "movl %%eax, %%ecx \n\t"
- "cmpl $0, %%ecx \n\t"
- "jz end16 \n\t"
-// preload "movl mask, %%edx \n\t"
- "sall $24, %%edx \n\t" // make low byte, high byte
-
- "secondloop16: \n\t"
- "sall %%edx \n\t" // move high bit to CF
- "jnc skip16 \n\t" // if CF = 0
- "movw (%%esi), %%ax \n\t"
- "movw %%ax, (%%edi) \n\t"
-
- "skip16: \n\t"
- "addl $2, %%esi \n\t"
- "addl $2, %%edi \n\t"
- "decl %%ecx \n\t"
- "jnz secondloop16 \n\t"
-
- "end16: \n\t"
- "EMMS \n\t" // DONE
-
- : "=a" (dummy_value_a), // output regs (dummy)
- "=c" (dummy_value_c),
- "=d" (dummy_value_d),
- "=S" (dummy_value_S),
- "=D" (dummy_value_D)
-
- : "0" (diff), // eax // input regs
-// was (unmask) " " RESERVED // ebx // Global Offset Table idx
- "1" (len), // ecx
- "2" (mask), // edx
- "3" (srcptr), // esi
- "4" (dstptr) // edi
-
-#if 0 /* MMX regs (%mm0, etc.) not supported by gcc 2.7.2.3 or egcs 1.1 */
- : "%mm0", "%mm1", "%mm4" // clobber list
- , "%mm5", "%mm6", "%mm7"
-#endif
- );
- }
- else /* mmx _not supported - Use modified C routine */
-#endif /* PNG_MMX_CODE_SUPPORTED */
- {
- register png_uint_32 i;
- png_uint_32 initial_val = BPP2 * png_pass_start[png_ptr->pass];
- /* png.c: png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; */
- register int stride = BPP2 * png_pass_inc[png_ptr->pass];
- /* png.c: png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; */
- register int rep_bytes = BPP2 * png_pass_width[png_ptr->pass];
- /* png.c: png_pass_width[] = {8, 4, 4, 2, 2, 1, 1}; */
- png_uint_32 len = png_ptr->width &~7; /* reduce to mult. of 8 */
- int diff = (int) (png_ptr->width & 7); /* amount lost */
- register png_uint_32 final_val = BPP2 * len; /* GRR bugfix */
-
- srcptr = png_ptr->row_buf + 1 + initial_val;
- dstptr = row + initial_val;
-
- for (i = initial_val; i < final_val; i += stride)
- {
- png_memcpy(dstptr, srcptr, rep_bytes);
- srcptr += stride;
- dstptr += stride;
- }
- if (diff) /* number of leftover pixels: 3 for pngtest */
- {
- final_val+=diff*BPP2;
- for (; i < final_val; i += stride)
- {
- if (rep_bytes > (int)(final_val-i))
- rep_bytes = (int)(final_val-i);
- png_memcpy(dstptr, srcptr, rep_bytes);
- srcptr += stride;
- dstptr += stride;
- }
- }
- } /* end of else (_mmx_supported) */
-
- break;
- } /* end 16 bpp */
-
- case 24: /* png_ptr->row_info.pixel_depth */
- {
- png_bytep srcptr;
- png_bytep dstptr;
-
-#if defined(PNG_MMX_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK)
- if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)
- /* && _mmx_supported */ )
- {
- png_uint_32 len;
- int diff;
- int dummy_value_a; // fix 'forbidden register spilled' error
- int dummy_value_d;
- int dummy_value_c;
- int dummy_value_S;
- int dummy_value_D;
- _unmask = ~mask; // global variable for -fPIC version
- srcptr = png_ptr->row_buf + 1;
- dstptr = row;
- len = png_ptr->width &~7; // reduce to multiple of 8
- diff = (int) (png_ptr->width & 7); // amount lost //
-
- __asm__ __volatile__ (
- "movd _unmask, %%mm7 \n\t" // load bit pattern
- "psubb %%mm6, %%mm6 \n\t" // zero mm6
- "punpcklbw %%mm7, %%mm7 \n\t"
- "punpcklwd %%mm7, %%mm7 \n\t"
- "punpckldq %%mm7, %%mm7 \n\t" // fill reg with 8 masks
-
- "movq _mask24_0, %%mm0 \n\t"
- "movq _mask24_1, %%mm1 \n\t"
- "movq _mask24_2, %%mm2 \n\t"
-
- "pand %%mm7, %%mm0 \n\t"
- "pand %%mm7, %%mm1 \n\t"
- "pand %%mm7, %%mm2 \n\t"
-
- "pcmpeqb %%mm6, %%mm0 \n\t"
- "pcmpeqb %%mm6, %%mm1 \n\t"
- "pcmpeqb %%mm6, %%mm2 \n\t"
-
-// preload "movl len, %%ecx \n\t" // load length of line
-// preload "movl srcptr, %%esi \n\t" // load source
-// preload "movl dstptr, %%edi \n\t" // load dest
-
- "cmpl $0, %%ecx \n\t"
- "jz mainloop24end \n\t"
-
- "mainloop24: \n\t"
- "movq (%%esi), %%mm4 \n\t"
- "pand %%mm0, %%mm4 \n\t"
- "movq %%mm0, %%mm6 \n\t"
- "movq (%%edi), %%mm7 \n\t"
- "pandn %%mm7, %%mm6 \n\t"
- "por %%mm6, %%mm4 \n\t"
- "movq %%mm4, (%%edi) \n\t"
-
- "movq 8(%%esi), %%mm5 \n\t"
- "pand %%mm1, %%mm5 \n\t"
- "movq %%mm1, %%mm7 \n\t"
- "movq 8(%%edi), %%mm6 \n\t"
- "pandn %%mm6, %%mm7 \n\t"
- "por %%mm7, %%mm5 \n\t"
- "movq %%mm5, 8(%%edi) \n\t"
-
- "movq 16(%%esi), %%mm6 \n\t"
- "pand %%mm2, %%mm6 \n\t"
- "movq %%mm2, %%mm4 \n\t"
- "movq 16(%%edi), %%mm7 \n\t"
- "pandn %%mm7, %%mm4 \n\t"
- "por %%mm4, %%mm6 \n\t"
- "movq %%mm6, 16(%%edi) \n\t"
-
- "addl $24, %%esi \n\t" // inc by 24 bytes processed
- "addl $24, %%edi \n\t"
- "subl $8, %%ecx \n\t" // dec by 8 pixels processed
-
- "ja mainloop24 \n\t"
-
- "mainloop24end: \n\t"
-// preload "movl diff, %%ecx \n\t" // (diff is in eax)
- "movl %%eax, %%ecx \n\t"
- "cmpl $0, %%ecx \n\t"
- "jz end24 \n\t"
-// preload "movl mask, %%edx \n\t"
- "sall $24, %%edx \n\t" // make low byte, high byte
-
- "secondloop24: \n\t"
- "sall %%edx \n\t" // move high bit to CF
- "jnc skip24 \n\t" // if CF = 0
- "movw (%%esi), %%ax \n\t"
- "movw %%ax, (%%edi) \n\t"
- "xorl %%eax, %%eax \n\t"
- "movb 2(%%esi), %%al \n\t"
- "movb %%al, 2(%%edi) \n\t"
-
- "skip24: \n\t"
- "addl $3, %%esi \n\t"
- "addl $3, %%edi \n\t"
- "decl %%ecx \n\t"
- "jnz secondloop24 \n\t"
-
- "end24: \n\t"
- "EMMS \n\t" // DONE
-
- : "=a" (dummy_value_a), // output regs (dummy)
- "=d" (dummy_value_d),
- "=c" (dummy_value_c),
- "=S" (dummy_value_S),
- "=D" (dummy_value_D)
-
- : "3" (srcptr), // esi // input regs
- "4" (dstptr), // edi
- "0" (diff), // eax
-// was (unmask) "b" RESERVED // ebx // Global Offset Table idx
- "2" (len), // ecx
- "1" (mask) // edx
-
-#if 0 /* MMX regs (%mm0, etc.) not supported by gcc 2.7.2.3 or egcs 1.1 */
- : "%mm0", "%mm1", "%mm2" // clobber list
- , "%mm4", "%mm5", "%mm6", "%mm7"
-#endif
- );
- }
- else /* mmx _not supported - Use modified C routine */
-#endif /* PNG_MMX_CODE_SUPPORTED */
- {
- register png_uint_32 i;
- png_uint_32 initial_val = BPP3 * png_pass_start[png_ptr->pass];
- /* png.c: png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; */
- register int stride = BPP3 * png_pass_inc[png_ptr->pass];
- /* png.c: png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; */
- register int rep_bytes = BPP3 * png_pass_width[png_ptr->pass];
- /* png.c: png_pass_width[] = {8, 4, 4, 2, 2, 1, 1}; */
- png_uint_32 len = png_ptr->width &~7; /* reduce to mult. of 8 */
- int diff = (int) (png_ptr->width & 7); /* amount lost */
- register png_uint_32 final_val = BPP3 * len; /* GRR bugfix */
-
- srcptr = png_ptr->row_buf + 1 + initial_val;
- dstptr = row + initial_val;
-
- for (i = initial_val; i < final_val; i += stride)
- {
- png_memcpy(dstptr, srcptr, rep_bytes);
- srcptr += stride;
- dstptr += stride;
- }
- if (diff) /* number of leftover pixels: 3 for pngtest */
- {
- final_val+=diff*BPP3;
- for (; i < final_val; i += stride)
- {
- if (rep_bytes > (int)(final_val-i))
- rep_bytes = (int)(final_val-i);
- png_memcpy(dstptr, srcptr, rep_bytes);
- srcptr += stride;
- dstptr += stride;
- }
- }
- } /* end of else (_mmx_supported) */
-
- break;
- } /* end 24 bpp */
-
- case 32: /* png_ptr->row_info.pixel_depth */
- {
- png_bytep srcptr;
- png_bytep dstptr;
-
-#if defined(PNG_MMX_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK)
- if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)
- /* && _mmx_supported */ )
- {
- png_uint_32 len;
- int diff;
- int dummy_value_a; // fix 'forbidden register spilled' error
- int dummy_value_d;
- int dummy_value_c;
- int dummy_value_S;
- int dummy_value_D;
- _unmask = ~mask; // global variable for -fPIC version
- srcptr = png_ptr->row_buf + 1;
- dstptr = row;
- len = png_ptr->width &~7; // reduce to multiple of 8
- diff = (int) (png_ptr->width & 7); // amount lost //
-
- __asm__ __volatile__ (
- "movd _unmask, %%mm7 \n\t" // load bit pattern
- "psubb %%mm6, %%mm6 \n\t" // zero mm6
- "punpcklbw %%mm7, %%mm7 \n\t"
- "punpcklwd %%mm7, %%mm7 \n\t"
- "punpckldq %%mm7, %%mm7 \n\t" // fill reg with 8 masks
-
- "movq _mask32_0, %%mm0 \n\t"
- "movq _mask32_1, %%mm1 \n\t"
- "movq _mask32_2, %%mm2 \n\t"
- "movq _mask32_3, %%mm3 \n\t"
-
- "pand %%mm7, %%mm0 \n\t"
- "pand %%mm7, %%mm1 \n\t"
- "pand %%mm7, %%mm2 \n\t"
- "pand %%mm7, %%mm3 \n\t"
-
- "pcmpeqb %%mm6, %%mm0 \n\t"
- "pcmpeqb %%mm6, %%mm1 \n\t"
- "pcmpeqb %%mm6, %%mm2 \n\t"
- "pcmpeqb %%mm6, %%mm3 \n\t"
-
-// preload "movl len, %%ecx \n\t" // load length of line
-// preload "movl srcptr, %%esi \n\t" // load source
-// preload "movl dstptr, %%edi \n\t" // load dest
-
- "cmpl $0, %%ecx \n\t" // lcr
- "jz mainloop32end \n\t"
-
- "mainloop32: \n\t"
- "movq (%%esi), %%mm4 \n\t"
- "pand %%mm0, %%mm4 \n\t"
- "movq %%mm0, %%mm6 \n\t"
- "movq (%%edi), %%mm7 \n\t"
- "pandn %%mm7, %%mm6 \n\t"
- "por %%mm6, %%mm4 \n\t"
- "movq %%mm4, (%%edi) \n\t"
-
- "movq 8(%%esi), %%mm5 \n\t"
- "pand %%mm1, %%mm5 \n\t"
- "movq %%mm1, %%mm7 \n\t"
- "movq 8(%%edi), %%mm6 \n\t"
- "pandn %%mm6, %%mm7 \n\t"
- "por %%mm7, %%mm5 \n\t"
- "movq %%mm5, 8(%%edi) \n\t"
-
- "movq 16(%%esi), %%mm6 \n\t"
- "pand %%mm2, %%mm6 \n\t"
- "movq %%mm2, %%mm4 \n\t"
- "movq 16(%%edi), %%mm7 \n\t"
- "pandn %%mm7, %%mm4 \n\t"
- "por %%mm4, %%mm6 \n\t"
- "movq %%mm6, 16(%%edi) \n\t"
-
- "movq 24(%%esi), %%mm7 \n\t"
- "pand %%mm3, %%mm7 \n\t"
- "movq %%mm3, %%mm5 \n\t"
- "movq 24(%%edi), %%mm4 \n\t"
- "pandn %%mm4, %%mm5 \n\t"
- "por %%mm5, %%mm7 \n\t"
- "movq %%mm7, 24(%%edi) \n\t"
-
- "addl $32, %%esi \n\t" // inc by 32 bytes processed
- "addl $32, %%edi \n\t"
- "subl $8, %%ecx \n\t" // dec by 8 pixels processed
- "ja mainloop32 \n\t"
-
- "mainloop32end: \n\t"
-// preload "movl diff, %%ecx \n\t" // (diff is in eax)
- "movl %%eax, %%ecx \n\t"
- "cmpl $0, %%ecx \n\t"
- "jz end32 \n\t"
-// preload "movl mask, %%edx \n\t"
- "sall $24, %%edx \n\t" // low byte => high byte
-
- "secondloop32: \n\t"
- "sall %%edx \n\t" // move high bit to CF
- "jnc skip32 \n\t" // if CF = 0
- "movl (%%esi), %%eax \n\t"
- "movl %%eax, (%%edi) \n\t"
-
- "skip32: \n\t"
- "addl $4, %%esi \n\t"
- "addl $4, %%edi \n\t"
- "decl %%ecx \n\t"
- "jnz secondloop32 \n\t"
-
- "end32: \n\t"
- "EMMS \n\t" // DONE
-
- : "=a" (dummy_value_a), // output regs (dummy)
- "=d" (dummy_value_d),
- "=c" (dummy_value_c),
- "=S" (dummy_value_S),
- "=D" (dummy_value_D)
-
- : "3" (srcptr), // esi // input regs
- "4" (dstptr), // edi
- "0" (diff), // eax
-// was (unmask) "b" RESERVED // ebx // Global Offset Table idx
- "2" (len), // ecx
- "1" (mask) // edx
-
-#if 0 /* MMX regs (%mm0, etc.) not supported by gcc 2.7.2.3 or egcs 1.1 */
- : "%mm0", "%mm1", "%mm2", "%mm3" // clobber list
- , "%mm4", "%mm5", "%mm6", "%mm7"
-#endif
- );
- }
- else /* mmx _not supported - Use modified C routine */
-#endif /* PNG_MMX_CODE_SUPPORTED */
- {
- register png_uint_32 i;
- png_uint_32 initial_val = BPP4 * png_pass_start[png_ptr->pass];
- /* png.c: png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; */
- register int stride = BPP4 * png_pass_inc[png_ptr->pass];
- /* png.c: png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; */
- register int rep_bytes = BPP4 * png_pass_width[png_ptr->pass];
- /* png.c: png_pass_width[] = {8, 4, 4, 2, 2, 1, 1}; */
- png_uint_32 len = png_ptr->width &~7; /* reduce to mult. of 8 */
- int diff = (int) (png_ptr->width & 7); /* amount lost */
- register png_uint_32 final_val = BPP4 * len; /* GRR bugfix */
-
- srcptr = png_ptr->row_buf + 1 + initial_val;
- dstptr = row + initial_val;
-
- for (i = initial_val; i < final_val; i += stride)
- {
- png_memcpy(dstptr, srcptr, rep_bytes);
- srcptr += stride;
- dstptr += stride;
- }
- if (diff) /* number of leftover pixels: 3 for pngtest */
- {
- final_val+=diff*BPP4;
- for (; i < final_val; i += stride)
- {
- if (rep_bytes > (int)(final_val-i))
- rep_bytes = (int)(final_val-i);
- png_memcpy(dstptr, srcptr, rep_bytes);
- srcptr += stride;
- dstptr += stride;
- }
- }
- } /* end of else (_mmx_supported) */
-
- break;
- } /* end 32 bpp */
-
- case 48: /* png_ptr->row_info.pixel_depth */
- {
- png_bytep srcptr;
- png_bytep dstptr;
-
-#if defined(PNG_MMX_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK)
- if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)
- /* && _mmx_supported */ )
- {
- png_uint_32 len;
- int diff;
- int dummy_value_a; // fix 'forbidden register spilled' error
- int dummy_value_d;
- int dummy_value_c;
- int dummy_value_S;
- int dummy_value_D;
- _unmask = ~mask; // global variable for -fPIC version
- srcptr = png_ptr->row_buf + 1;
- dstptr = row;
- len = png_ptr->width &~7; // reduce to multiple of 8
- diff = (int) (png_ptr->width & 7); // amount lost //
-
- __asm__ __volatile__ (
- "movd _unmask, %%mm7 \n\t" // load bit pattern
- "psubb %%mm6, %%mm6 \n\t" // zero mm6
- "punpcklbw %%mm7, %%mm7 \n\t"
- "punpcklwd %%mm7, %%mm7 \n\t"
- "punpckldq %%mm7, %%mm7 \n\t" // fill reg with 8 masks
-
- "movq _mask48_0, %%mm0 \n\t"
- "movq _mask48_1, %%mm1 \n\t"
- "movq _mask48_2, %%mm2 \n\t"
- "movq _mask48_3, %%mm3 \n\t"
- "movq _mask48_4, %%mm4 \n\t"
- "movq _mask48_5, %%mm5 \n\t"
-
- "pand %%mm7, %%mm0 \n\t"
- "pand %%mm7, %%mm1 \n\t"
- "pand %%mm7, %%mm2 \n\t"
- "pand %%mm7, %%mm3 \n\t"
- "pand %%mm7, %%mm4 \n\t"
- "pand %%mm7, %%mm5 \n\t"
-
- "pcmpeqb %%mm6, %%mm0 \n\t"
- "pcmpeqb %%mm6, %%mm1 \n\t"
- "pcmpeqb %%mm6, %%mm2 \n\t"
- "pcmpeqb %%mm6, %%mm3 \n\t"
- "pcmpeqb %%mm6, %%mm4 \n\t"
- "pcmpeqb %%mm6, %%mm5 \n\t"
-
-// preload "movl len, %%ecx \n\t" // load length of line
-// preload "movl srcptr, %%esi \n\t" // load source
-// preload "movl dstptr, %%edi \n\t" // load dest
-
- "cmpl $0, %%ecx \n\t"
- "jz mainloop48end \n\t"
-
- "mainloop48: \n\t"
- "movq (%%esi), %%mm7 \n\t"
- "pand %%mm0, %%mm7 \n\t"
- "movq %%mm0, %%mm6 \n\t"
- "pandn (%%edi), %%mm6 \n\t"
- "por %%mm6, %%mm7 \n\t"
- "movq %%mm7, (%%edi) \n\t"
-
- "movq 8(%%esi), %%mm6 \n\t"
- "pand %%mm1, %%mm6 \n\t"
- "movq %%mm1, %%mm7 \n\t"
- "pandn 8(%%edi), %%mm7 \n\t"
- "por %%mm7, %%mm6 \n\t"
- "movq %%mm6, 8(%%edi) \n\t"
-
- "movq 16(%%esi), %%mm6 \n\t"
- "pand %%mm2, %%mm6 \n\t"
- "movq %%mm2, %%mm7 \n\t"
- "pandn 16(%%edi), %%mm7 \n\t"
- "por %%mm7, %%mm6 \n\t"
- "movq %%mm6, 16(%%edi) \n\t"
-
- "movq 24(%%esi), %%mm7 \n\t"
- "pand %%mm3, %%mm7 \n\t"
- "movq %%mm3, %%mm6 \n\t"
- "pandn 24(%%edi), %%mm6 \n\t"
- "por %%mm6, %%mm7 \n\t"
- "movq %%mm7, 24(%%edi) \n\t"
-
- "movq 32(%%esi), %%mm6 \n\t"
- "pand %%mm4, %%mm6 \n\t"
- "movq %%mm4, %%mm7 \n\t"
- "pandn 32(%%edi), %%mm7 \n\t"
- "por %%mm7, %%mm6 \n\t"
- "movq %%mm6, 32(%%edi) \n\t"
-
- "movq 40(%%esi), %%mm7 \n\t"
- "pand %%mm5, %%mm7 \n\t"
- "movq %%mm5, %%mm6 \n\t"
- "pandn 40(%%edi), %%mm6 \n\t"
- "por %%mm6, %%mm7 \n\t"
- "movq %%mm7, 40(%%edi) \n\t"
-
- "addl $48, %%esi \n\t" // inc by 48 bytes processed
- "addl $48, %%edi \n\t"
- "subl $8, %%ecx \n\t" // dec by 8 pixels processed
-
- "ja mainloop48 \n\t"
-
- "mainloop48end: \n\t"
-// preload "movl diff, %%ecx \n\t" // (diff is in eax)
- "movl %%eax, %%ecx \n\t"
- "cmpl $0, %%ecx \n\t"
- "jz end48 \n\t"
-// preload "movl mask, %%edx \n\t"
- "sall $24, %%edx \n\t" // make low byte, high byte
-
- "secondloop48: \n\t"
- "sall %%edx \n\t" // move high bit to CF
- "jnc skip48 \n\t" // if CF = 0
- "movl (%%esi), %%eax \n\t"
- "movl %%eax, (%%edi) \n\t"
-
- "skip48: \n\t"
- "addl $4, %%esi \n\t"
- "addl $4, %%edi \n\t"
- "decl %%ecx \n\t"
- "jnz secondloop48 \n\t"
-
- "end48: \n\t"
- "EMMS \n\t" // DONE
-
- : "=a" (dummy_value_a), // output regs (dummy)
- "=d" (dummy_value_d),
- "=c" (dummy_value_c),
- "=S" (dummy_value_S),
- "=D" (dummy_value_D)
-
- : "3" (srcptr), // esi // input regs
- "4" (dstptr), // edi
- "0" (diff), // eax
-// was (unmask) "b" RESERVED // ebx // Global Offset Table idx
- "2" (len), // ecx
- "1" (mask) // edx
-
-#if 0 /* MMX regs (%mm0, etc.) not supported by gcc 2.7.2.3 or egcs 1.1 */
- : "%mm0", "%mm1", "%mm2", "%mm3" // clobber list
- , "%mm4", "%mm5", "%mm6", "%mm7"
-#endif
- );
- }
- else /* mmx _not supported - Use modified C routine */
-#endif /* PNG_MMX_CODE_SUPPORTED */
- {
- register png_uint_32 i;
- png_uint_32 initial_val = BPP6 * png_pass_start[png_ptr->pass];
- /* png.c: png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; */
- register int stride = BPP6 * png_pass_inc[png_ptr->pass];
- /* png.c: png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; */
- register int rep_bytes = BPP6 * png_pass_width[png_ptr->pass];
- /* png.c: png_pass_width[] = {8, 4, 4, 2, 2, 1, 1}; */
- png_uint_32 len = png_ptr->width &~7; /* reduce to mult. of 8 */
- int diff = (int) (png_ptr->width & 7); /* amount lost */
- register png_uint_32 final_val = BPP6 * len; /* GRR bugfix */
-
- srcptr = png_ptr->row_buf + 1 + initial_val;
- dstptr = row + initial_val;
-
- for (i = initial_val; i < final_val; i += stride)
- {
- png_memcpy(dstptr, srcptr, rep_bytes);
- srcptr += stride;
- dstptr += stride;
- }
- if (diff) /* number of leftover pixels: 3 for pngtest */
- {
- final_val+=diff*BPP6;
- for (; i < final_val; i += stride)
- {
- if (rep_bytes > (int)(final_val-i))
- rep_bytes = (int)(final_val-i);
- png_memcpy(dstptr, srcptr, rep_bytes);
- srcptr += stride;
- dstptr += stride;
- }
- }
- } /* end of else (_mmx_supported) */
-
- break;
- } /* end 48 bpp */
-
- case 64: /* png_ptr->row_info.pixel_depth */
- {
- png_bytep srcptr;
- png_bytep dstptr;
- register png_uint_32 i;
- png_uint_32 initial_val = BPP8 * png_pass_start[png_ptr->pass];
- /* png.c: png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; */
- register int stride = BPP8 * png_pass_inc[png_ptr->pass];
- /* png.c: png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; */
- register int rep_bytes = BPP8 * png_pass_width[png_ptr->pass];
- /* png.c: png_pass_width[] = {8, 4, 4, 2, 2, 1, 1}; */
- png_uint_32 len = png_ptr->width &~7; /* reduce to mult. of 8 */
- int diff = (int) (png_ptr->width & 7); /* amount lost */
- register png_uint_32 final_val = BPP8 * len; /* GRR bugfix */
-
- srcptr = png_ptr->row_buf + 1 + initial_val;
- dstptr = row + initial_val;
-
- for (i = initial_val; i < final_val; i += stride)
- {
- png_memcpy(dstptr, srcptr, rep_bytes);
- srcptr += stride;
- dstptr += stride;
- }
- if (diff) /* number of leftover pixels: 3 for pngtest */
- {
- final_val+=diff*BPP8;
- for (; i < final_val; i += stride)
- {
- if (rep_bytes > (int)(final_val-i))
- rep_bytes = (int)(final_val-i);
- png_memcpy(dstptr, srcptr, rep_bytes);
- srcptr += stride;
- dstptr += stride;
- }
- }
-
- break;
- } /* end 64 bpp */
-
- default: /* png_ptr->row_info.pixel_depth != 1,2,4,8,16,24,32,48,64 */
- {
- /* this should never happen */
- png_warning(png_ptr, "Invalid row_info.pixel_depth in pnggccrd");
- break;
- }
- } /* end switch (png_ptr->row_info.pixel_depth) */
-
- } /* end if (non-trivial mask) */
-
-} /* end png_combine_row() */
-
-#endif /* PNG_HAVE_MMX_COMBINE_ROW */
-
-
-
-
-/*===========================================================================*/
-/* */
-/* P N G _ D O _ R E A D _ I N T E R L A C E */
-/* */
-/*===========================================================================*/
-
-#if defined(PNG_READ_INTERLACING_SUPPORTED)
-#if defined(PNG_HAVE_MMX_READ_INTERLACE)
-
-/* png_do_read_interlace() is called after any 16-bit to 8-bit conversion
- * has taken place. [GRR: what other steps come before and/or after?]
- */
-
-void /* PRIVATE */
-png_do_read_interlace(png_structp png_ptr)
-{
- png_row_infop row_info = &(png_ptr->row_info);
- png_bytep row = png_ptr->row_buf + 1;
- int pass = png_ptr->pass;
-#if defined(PNG_READ_PACKSWAP_SUPPORTED)
- png_uint_32 transformations = png_ptr->transformations;
-#endif
-
- png_debug(1, "in png_do_read_interlace (pnggccrd.c)\n");
-
-#if defined(PNG_MMX_CODE_SUPPORTED)
- if (_mmx_supported == 2) {
- /* this should have happened in png_init_mmx_flags() already */
- png_warning(png_ptr, "asm_flags may not have been initialized");
- png_mmx_support();
- }
-#endif
-
- if (row != NULL && row_info != NULL)
- {
- png_uint_32 final_width;
-
- final_width = row_info->width * png_pass_inc[pass];
-
- switch (row_info->pixel_depth)
- {
- case 1:
- {
- png_bytep sp, dp;
- int sshift, dshift;
- int s_start, s_end, s_inc;
- 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)
- {
- sshift = (int)((row_info->width + 7) & 7);
- dshift = (int)((final_width + 7) & 7);
- s_start = 7;
- s_end = 0;
- s_inc = -1;
- }
- else
-#endif
- {
- sshift = 7 - (int)((row_info->width + 7) & 7);
- dshift = 7 - (int)((final_width + 7) & 7);
- s_start = 0;
- s_end = 7;
- s_inc = 1;
- }
-
- for (i = row_info->width; i; i--)
- {
- v = (png_byte)((*sp >> sshift) & 0x1);
- for (j = 0; j < png_pass_inc[pass]; j++)
- {
- *dp &= (png_byte)((0x7f7f >> (7 - dshift)) & 0xff);
- *dp |= (png_byte)(v << dshift);
- if (dshift == s_end)
- {
- dshift = s_start;
- dp--;
- }
- else
- dshift += s_inc;
- }
- if (sshift == s_end)
- {
- sshift = s_start;
- sp--;
- }
- else
- sshift += s_inc;
- }
- break;
- }
-
- case 2:
- {
- png_bytep sp, dp;
- int sshift, dshift;
- int s_start, s_end, s_inc;
- png_uint_32 i;
-
- sp = row + (png_size_t)((row_info->width - 1) >> 2);
- dp = row + (png_size_t)((final_width - 1) >> 2);
-#if defined(PNG_READ_PACKSWAP_SUPPORTED)
- if (transformations & PNG_PACKSWAP)
- {
- sshift = (png_size_t)(((row_info->width + 3) & 3) << 1);
- dshift = (png_size_t)(((final_width + 3) & 3) << 1);
- s_start = 6;
- s_end = 0;
- s_inc = -2;
- }
- else
-#endif
- {
- sshift = (png_size_t)((3 - ((row_info->width + 3) & 3)) << 1);
- dshift = (png_size_t)((3 - ((final_width + 3) & 3)) << 1);
- s_start = 0;
- s_end = 6;
- s_inc = 2;
- }
-
- for (i = row_info->width; i; i--)
- {
- png_byte v;
- int j;
-
- v = (png_byte)((*sp >> sshift) & 0x3);
- for (j = 0; j < png_pass_inc[pass]; j++)
- {
- *dp &= (png_byte)((0x3f3f >> (6 - dshift)) & 0xff);
- *dp |= (png_byte)(v << dshift);
- if (dshift == s_end)
- {
- dshift = s_start;
- dp--;
- }
- else
- dshift += s_inc;
- }
- if (sshift == s_end)
- {
- sshift = s_start;
- sp--;
- }
- else
- sshift += s_inc;
- }
- break;
- }
-
- case 4:
- {
- png_bytep sp, dp;
- int sshift, dshift;
- int s_start, s_end, s_inc;
- png_uint_32 i;
-
- 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)
- {
- sshift = (png_size_t)(((row_info->width + 1) & 1) << 2);
- dshift = (png_size_t)(((final_width + 1) & 1) << 2);
- s_start = 4;
- s_end = 0;
- s_inc = -4;
- }
- else
-#endif
- {
- sshift = (png_size_t)((1 - ((row_info->width + 1) & 1)) << 2);
- dshift = (png_size_t)((1 - ((final_width + 1) & 1)) << 2);
- s_start = 0;
- s_end = 4;
- s_inc = 4;
- }
-
- for (i = row_info->width; i; i--)
- {
- png_byte v;
- int j;
-
- v = (png_byte)((*sp >> sshift) & 0xf);
- for (j = 0; j < png_pass_inc[pass]; j++)
- {
- *dp &= (png_byte)((0xf0f >> (4 - dshift)) & 0xff);
- *dp |= (png_byte)(v << dshift);
- if (dshift == s_end)
- {
- dshift = s_start;
- dp--;
- }
- else
- dshift += s_inc;
- }
- if (sshift == s_end)
- {
- sshift = s_start;
- sp--;
- }
- else
- sshift += s_inc;
- }
- break;
- }
-
- /*====================================================================*/
-
- default: /* 8-bit or larger (this is where the routine is modified) */
- {
-#if 0
-// static unsigned long long _const4 = 0x0000000000FFFFFFLL; no good
-// static unsigned long long const4 = 0x0000000000FFFFFFLL; no good
-// unsigned long long _const4 = 0x0000000000FFFFFFLL; no good
-// unsigned long long const4 = 0x0000000000FFFFFFLL; no good
-#endif
- png_bytep sptr, dp;
- png_uint_32 i;
- png_size_t pixel_bytes;
- int width = (int)row_info->width;
-
- pixel_bytes = (row_info->pixel_depth >> 3);
-
- /* point sptr at the last pixel in the pre-expanded row: */
- sptr = row + (width - 1) * pixel_bytes;
-
- /* point dp at the last pixel position in the expanded row: */
- dp = row + (final_width - 1) * pixel_bytes;
-
- /* New code by Nirav Chhatrapati - Intel Corporation */
-
-#if defined(PNG_MMX_CODE_SUPPORTED)
- if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_INTERLACE)
- /* && _mmx_supported */ )
- {
- //--------------------------------------------------------------
- if (pixel_bytes == 3)
- {
- if (((pass == 0) || (pass == 1)) && width)
- {
- int dummy_value_c; // fix 'forbidden register spilled'
- int dummy_value_S;
- int dummy_value_D;
- long dummy_value_a;
-
- __asm__ __volatile__ (
- "subl $21, %%edi \n\t"
- // (png_pass_inc[pass] - 1)*pixel_bytes
-
- ".loop3_pass0: \n\t"
- "movd (%%esi), %%mm0 \n\t" // x x x x x 2 1 0
- "pand (%3), %%mm0 \n\t" // z z z z z 2 1 0
- "movq %%mm0, %%mm1 \n\t" // z z z z z 2 1 0
- "psllq $16, %%mm0 \n\t" // z z z 2 1 0 z z
- "movq %%mm0, %%mm2 \n\t" // z z z 2 1 0 z z
- "psllq $24, %%mm0 \n\t" // 2 1 0 z z z z z
- "psrlq $8, %%mm1 \n\t" // z z z z z z 2 1
- "por %%mm2, %%mm0 \n\t" // 2 1 0 2 1 0 z z
- "por %%mm1, %%mm0 \n\t" // 2 1 0 2 1 0 2 1
- "movq %%mm0, %%mm3 \n\t" // 2 1 0 2 1 0 2 1
- "psllq $16, %%mm0 \n\t" // 0 2 1 0 2 1 z z
- "movq %%mm3, %%mm4 \n\t" // 2 1 0 2 1 0 2 1
- "punpckhdq %%mm0, %%mm3 \n\t" // 0 2 1 0 2 1 0 2
- "movq %%mm4, 16(%%edi) \n\t"
- "psrlq $32, %%mm0 \n\t" // z z z z 0 2 1 0
- "movq %%mm3, 8(%%edi) \n\t"
- "punpckldq %%mm4, %%mm0 \n\t" // 1 0 2 1 0 2 1 0
- "subl $3, %%esi \n\t"
- "movq %%mm0, (%%edi) \n\t"
- "subl $24, %%edi \n\t"
- "decl %%ecx \n\t"
- "jnz .loop3_pass0 \n\t"
- "EMMS \n\t" // DONE
-
- : "=c" (dummy_value_c), // output regs (dummy)
- "=S" (dummy_value_S),
- "=D" (dummy_value_D),
- "=a" (dummy_value_a)
-
-
- : "1" (sptr), // esi // input regs
- "2" (dp), // edi
- "0" (width), // ecx
- "3" (&_const4) // %1(?) (0x0000000000FFFFFFLL)
-
-#if 0 /* %mm0, ..., %mm4 not supported by gcc 2.7.2.3 or egcs 1.1 */
- : "%mm0", "%mm1", "%mm2" // clobber list
- , "%mm3", "%mm4"
-#endif
- );
- }
- else if (((pass == 2) || (pass == 3)) && width)
- {
- int dummy_value_c; // fix 'forbidden register spilled'
- int dummy_value_S;
- int dummy_value_D;
- long dummy_value_a;
-
- __asm__ __volatile__ (
- "subl $9, %%edi \n\t"
- // (png_pass_inc[pass] - 1)*pixel_bytes
-
- ".loop3_pass2: \n\t"
- "movd (%%esi), %%mm0 \n\t" // x x x x x 2 1 0
- "pand (%3), %%mm0 \n\t" // z z z z z 2 1 0
- "movq %%mm0, %%mm1 \n\t" // z z z z z 2 1 0
- "psllq $16, %%mm0 \n\t" // z z z 2 1 0 z z
- "movq %%mm0, %%mm2 \n\t" // z z z 2 1 0 z z
- "psllq $24, %%mm0 \n\t" // 2 1 0 z z z z z
- "psrlq $8, %%mm1 \n\t" // z z z z z z 2 1
- "por %%mm2, %%mm0 \n\t" // 2 1 0 2 1 0 z z
- "por %%mm1, %%mm0 \n\t" // 2 1 0 2 1 0 2 1
- "movq %%mm0, 4(%%edi) \n\t"
- "psrlq $16, %%mm0 \n\t" // z z 2 1 0 2 1 0
- "subl $3, %%esi \n\t"
- "movd %%mm0, (%%edi) \n\t"
- "subl $12, %%edi \n\t"
- "decl %%ecx \n\t"
- "jnz .loop3_pass2 \n\t"
- "EMMS \n\t" // DONE
-
- : "=c" (dummy_value_c), // output regs (dummy)
- "=S" (dummy_value_S),
- "=D" (dummy_value_D),
- "=a" (dummy_value_a)
-
- : "1" (sptr), // esi // input regs
- "2" (dp), // edi
- "0" (width), // ecx
- "3" (&_const4) // (0x0000000000FFFFFFLL)
-
-#if 0 /* %mm0, ..., %mm2 not supported by gcc 2.7.2.3 or egcs 1.1 */
- : "%mm0", "%mm1", "%mm2" // clobber list
-#endif
- );
- }
- else if (width) /* && ((pass == 4) || (pass == 5)) */
- {
- int width_mmx = ((width >> 1) << 1) - 8; // GRR: huh?
- if (width_mmx < 0)
- width_mmx = 0;
- width -= width_mmx; // 8 or 9 pix, 24 or 27 bytes
- if (width_mmx)
- {
- // png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
- // sptr points at last pixel in pre-expanded row
- // dp points at last pixel position in expanded row
- int dummy_value_c; // fix 'forbidden register spilled'
- int dummy_value_S;
- int dummy_value_D;
- long dummy_value_a;
- long dummy_value_d;
-
- __asm__ __volatile__ (
- "subl $3, %%esi \n\t"
- "subl $9, %%edi \n\t"
- // (png_pass_inc[pass] + 1)*pixel_bytes
-
- ".loop3_pass4: \n\t"
- "movq (%%esi), %%mm0 \n\t" // x x 5 4 3 2 1 0
- "movq %%mm0, %%mm1 \n\t" // x x 5 4 3 2 1 0
- "movq %%mm0, %%mm2 \n\t" // x x 5 4 3 2 1 0
- "psllq $24, %%mm0 \n\t" // 4 3 2 1 0 z z z
- "pand (%3), %%mm1 \n\t" // z z z z z 2 1 0
- "psrlq $24, %%mm2 \n\t" // z z z x x 5 4 3
- "por %%mm1, %%mm0 \n\t" // 4 3 2 1 0 2 1 0
- "movq %%mm2, %%mm3 \n\t" // z z z x x 5 4 3
- "psllq $8, %%mm2 \n\t" // z z x x 5 4 3 z
- "movq %%mm0, (%%edi) \n\t"
- "psrlq $16, %%mm3 \n\t" // z z z z z x x 5
- "pand (%4), %%mm3 \n\t" // z z z z z z z 5
- "por %%mm3, %%mm2 \n\t" // z z x x 5 4 3 5
- "subl $6, %%esi \n\t"
- "movd %%mm2, 8(%%edi) \n\t"
- "subl $12, %%edi \n\t"
- "subl $2, %%ecx \n\t"
- "jnz .loop3_pass4 \n\t"
- "EMMS \n\t" // DONE
-
- : "=c" (dummy_value_c), // output regs (dummy)
- "=S" (dummy_value_S),
- "=D" (dummy_value_D),
- "=a" (dummy_value_a),
- "=d" (dummy_value_d)
-
- : "1" (sptr), // esi // input regs
- "2" (dp), // edi
- "0" (width_mmx), // ecx
- "3" (&_const4), // 0x0000000000FFFFFFLL
- "4" (&_const6) // 0x00000000000000FFLL
-
-#if 0 /* %mm0, ..., %mm3 not supported by gcc 2.7.2.3 or egcs 1.1 */
- : "%mm0", "%mm1" // clobber list
- , "%mm2", "%mm3"
-#endif
- );
- }
-
- sptr -= width_mmx*3;
- dp -= width_mmx*6;
- for (i = width; i; i--)
- {
- png_byte v[8];
- int j;
-
- png_memcpy(v, sptr, 3);
- for (j = 0; j < png_pass_inc[pass]; j++)
- {
- png_memcpy(dp, v, 3);
- dp -= 3;
- }
- sptr -= 3;
- }
- }
- } /* end of pixel_bytes == 3 */
-
- //--------------------------------------------------------------
- else if (pixel_bytes == 1)
- {
- if (((pass == 0) || (pass == 1)) && width)
- {
- int width_mmx = ((width >> 2) << 2);
- width -= width_mmx; // 0-3 pixels => 0-3 bytes
- if (width_mmx)
- {
- int dummy_value_c; // fix 'forbidden register spilled'
- int dummy_value_S;
- int dummy_value_D;
-
- __asm__ __volatile__ (
- "subl $3, %%esi \n\t"
- "subl $31, %%edi \n\t"
-
- ".loop1_pass0: \n\t"
- "movd (%%esi), %%mm0 \n\t" // x x x x 3 2 1 0
- "movq %%mm0, %%mm1 \n\t" // x x x x 3 2 1 0
- "punpcklbw %%mm0, %%mm0 \n\t" // 3 3 2 2 1 1 0 0
- "movq %%mm0, %%mm2 \n\t" // 3 3 2 2 1 1 0 0
- "punpcklwd %%mm0, %%mm0 \n\t" // 1 1 1 1 0 0 0 0
- "movq %%mm0, %%mm3 \n\t" // 1 1 1 1 0 0 0 0
- "punpckldq %%mm0, %%mm0 \n\t" // 0 0 0 0 0 0 0 0
- "punpckhdq %%mm3, %%mm3 \n\t" // 1 1 1 1 1 1 1 1
- "movq %%mm0, (%%edi) \n\t"
- "punpckhwd %%mm2, %%mm2 \n\t" // 3 3 3 3 2 2 2 2
- "movq %%mm3, 8(%%edi) \n\t"
- "movq %%mm2, %%mm4 \n\t" // 3 3 3 3 2 2 2 2
- "punpckldq %%mm2, %%mm2 \n\t" // 2 2 2 2 2 2 2 2
- "punpckhdq %%mm4, %%mm4 \n\t" // 3 3 3 3 3 3 3 3
- "movq %%mm2, 16(%%edi) \n\t"
- "subl $4, %%esi \n\t"
- "movq %%mm4, 24(%%edi) \n\t"
- "subl $32, %%edi \n\t"
- "subl $4, %%ecx \n\t"
- "jnz .loop1_pass0 \n\t"
- "EMMS \n\t" // DONE
-
- : "=c" (dummy_value_c), // output regs (dummy)
- "=S" (dummy_value_S),
- "=D" (dummy_value_D)
-
- : "1" (sptr), // esi // input regs
- "2" (dp), // edi
- "0" (width_mmx) // ecx
-
-#if 0 /* %mm0, ..., %mm4 not supported by gcc 2.7.2.3 or egcs 1.1 */
- : "%mm0", "%mm1", "%mm2" // clobber list
- , "%mm3", "%mm4"
-#endif
- );
- }
-
- sptr -= width_mmx;
- dp -= width_mmx*8;
- for (i = width; i; i--)
- {
- int j;
-
- /* I simplified this part in version 1.0.4e
- * here and in several other instances where
- * pixel_bytes == 1 -- GR-P
- *
- * Original code:
- *
- * png_byte v[8];
- * png_memcpy(v, sptr, pixel_bytes);
- * for (j = 0; j < png_pass_inc[pass]; j++)
- * {
- * png_memcpy(dp, v, pixel_bytes);
- * dp -= pixel_bytes;
- * }
- * sptr -= pixel_bytes;
- *
- * Replacement code is in the next three lines:
- */
-
- for (j = 0; j < png_pass_inc[pass]; j++)
- {
- *dp-- = *sptr;
- }
- --sptr;
- }
- }
- else if (((pass == 2) || (pass == 3)) && width)
- {
- int width_mmx = ((width >> 2) << 2);
- width -= width_mmx; // 0-3 pixels => 0-3 bytes
- if (width_mmx)
- {
- int dummy_value_c; // fix 'forbidden register spilled'
- int dummy_value_S;
- int dummy_value_D;
-
- __asm__ __volatile__ (
- "subl $3, %%esi \n\t"
- "subl $15, %%edi \n\t"
-
- ".loop1_pass2: \n\t"
- "movd (%%esi), %%mm0 \n\t" // x x x x 3 2 1 0
- "punpcklbw %%mm0, %%mm0 \n\t" // 3 3 2 2 1 1 0 0
- "movq %%mm0, %%mm1 \n\t" // 3 3 2 2 1 1 0 0
- "punpcklwd %%mm0, %%mm0 \n\t" // 1 1 1 1 0 0 0 0
- "punpckhwd %%mm1, %%mm1 \n\t" // 3 3 3 3 2 2 2 2
- "movq %%mm0, (%%edi) \n\t"
- "subl $4, %%esi \n\t"
- "movq %%mm1, 8(%%edi) \n\t"
- "subl $16, %%edi \n\t"
- "subl $4, %%ecx \n\t"
- "jnz .loop1_pass2 \n\t"
- "EMMS \n\t" // DONE
-
- : "=c" (dummy_value_c), // output regs (dummy)
- "=S" (dummy_value_S),
- "=D" (dummy_value_D)
-
- : "1" (sptr), // esi // input regs
- "2" (dp), // edi
- "0" (width_mmx) // ecx
-
-#if 0 /* %mm0, %mm1 not supported by gcc 2.7.2.3 or egcs 1.1 */
- : "%mm0", "%mm1" // clobber list
-#endif
- );
- }
-
- sptr -= width_mmx;
- dp -= width_mmx*4;
- for (i = width; i; i--)
- {
- int j;
-
- for (j = 0; j < png_pass_inc[pass]; j++)
- {
- *dp-- = *sptr;
- }
- --sptr;
- }
- }
- else if (width) /* && ((pass == 4) || (pass == 5)) */
- {
- int width_mmx = ((width >> 3) << 3);
- width -= width_mmx; // 0-3 pixels => 0-3 bytes
- if (width_mmx)
- {
- int dummy_value_c; // fix 'forbidden register spilled'
- int dummy_value_S;
- int dummy_value_D;
-
- __asm__ __volatile__ (
- "subl $7, %%esi \n\t"
- "subl $15, %%edi \n\t"
-
- ".loop1_pass4: \n\t"
- "movq (%%esi), %%mm0 \n\t" // 7 6 5 4 3 2 1 0
- "movq %%mm0, %%mm1 \n\t" // 7 6 5 4 3 2 1 0
- "punpcklbw %%mm0, %%mm0 \n\t" // 3 3 2 2 1 1 0 0
- "punpckhbw %%mm1, %%mm1 \n\t" // 7 7 6 6 5 5 4 4
- "movq %%mm1, 8(%%edi) \n\t"
- "subl $8, %%esi \n\t"
- "movq %%mm0, (%%edi) \n\t"
- "subl $16, %%edi \n\t"
- "subl $8, %%ecx \n\t"
- "jnz .loop1_pass4 \n\t"
- "EMMS \n\t" // DONE
-
- : "=c" (dummy_value_c), // output regs (none)
- "=S" (dummy_value_S),
- "=D" (dummy_value_D)
-
- : "1" (sptr), // esi // input regs
- "2" (dp), // edi
- "0" (width_mmx) // ecx
-
-#if 0 /* %mm0, %mm1 not supported by gcc 2.7.2.3 or egcs 1.1 */
- : "%mm0", "%mm1" // clobber list
-#endif
- );
- }
-
- sptr -= width_mmx;
- dp -= width_mmx*2;
- for (i = width; i; i--)
- {
- int j;
-
- for (j = 0; j < png_pass_inc[pass]; j++)
- {
- *dp-- = *sptr;
- }
- --sptr;
- }
- }
- } /* end of pixel_bytes == 1 */
-
- //--------------------------------------------------------------
- else if (pixel_bytes == 2)
- {
- if (((pass == 0) || (pass == 1)) && width)
- {
- int width_mmx = ((width >> 1) << 1);
- width -= width_mmx; // 0,1 pixels => 0,2 bytes
- if (width_mmx)
- {
- int dummy_value_c; // fix 'forbidden register spilled'
- int dummy_value_S;
- int dummy_value_D;
-
- __asm__ __volatile__ (
- "subl $2, %%esi \n\t"
- "subl $30, %%edi \n\t"
-
- ".loop2_pass0: \n\t"
- "movd (%%esi), %%mm0 \n\t" // x x x x 3 2 1 0
- "punpcklwd %%mm0, %%mm0 \n\t" // 3 2 3 2 1 0 1 0
- "movq %%mm0, %%mm1 \n\t" // 3 2 3 2 1 0 1 0
- "punpckldq %%mm0, %%mm0 \n\t" // 1 0 1 0 1 0 1 0
- "punpckhdq %%mm1, %%mm1 \n\t" // 3 2 3 2 3 2 3 2
- "movq %%mm0, (%%edi) \n\t"
- "movq %%mm0, 8(%%edi) \n\t"
- "movq %%mm1, 16(%%edi) \n\t"
- "subl $4, %%esi \n\t"
- "movq %%mm1, 24(%%edi) \n\t"
- "subl $32, %%edi \n\t"
- "subl $2, %%ecx \n\t"
- "jnz .loop2_pass0 \n\t"
- "EMMS \n\t" // DONE
-
- : "=c" (dummy_value_c), // output regs (dummy)
- "=S" (dummy_value_S),
- "=D" (dummy_value_D)
-
- : "1" (sptr), // esi // input regs
- "2" (dp), // edi
- "0" (width_mmx) // ecx
-
-#if 0 /* %mm0, %mm1 not supported by gcc 2.7.2.3 or egcs 1.1 */
- : "%mm0", "%mm1" // clobber list
-#endif
- );
- }
-
- sptr -= (width_mmx*2 - 2); // sign fixed
- dp -= (width_mmx*16 - 2); // sign fixed
- for (i = width; i; i--)
- {
- png_byte v[8];
- int j;
- sptr -= 2;
- png_memcpy(v, sptr, 2);
- for (j = 0; j < png_pass_inc[pass]; j++)
- {
- dp -= 2;
- png_memcpy(dp, v, 2);
- }
- }
- }
- else if (((pass == 2) || (pass == 3)) && width)
- {
- int width_mmx = ((width >> 1) << 1) ;
- width -= width_mmx; // 0,1 pixels => 0,2 bytes
- if (width_mmx)
- {
- int dummy_value_c; // fix 'forbidden register spilled'
- int dummy_value_S;
- int dummy_value_D;
-
- __asm__ __volatile__ (
- "subl $2, %%esi \n\t"
- "subl $14, %%edi \n\t"
-
- ".loop2_pass2: \n\t"
- "movd (%%esi), %%mm0 \n\t" // x x x x 3 2 1 0
- "punpcklwd %%mm0, %%mm0 \n\t" // 3 2 3 2 1 0 1 0
- "movq %%mm0, %%mm1 \n\t" // 3 2 3 2 1 0 1 0
- "punpckldq %%mm0, %%mm0 \n\t" // 1 0 1 0 1 0 1 0
- "punpckhdq %%mm1, %%mm1 \n\t" // 3 2 3 2 3 2 3 2
- "movq %%mm0, (%%edi) \n\t"
- "subl $4, %%esi \n\t"
- "movq %%mm1, 8(%%edi) \n\t"
- "subl $16, %%edi \n\t"
- "subl $2, %%ecx \n\t"
- "jnz .loop2_pass2 \n\t"
- "EMMS \n\t" // DONE
-
- : "=c" (dummy_value_c), // output regs (dummy)
- "=S" (dummy_value_S),
- "=D" (dummy_value_D)
-
- : "1" (sptr), // esi // input regs
- "2" (dp), // edi
- "0" (width_mmx) // ecx
-
-#if 0 /* %mm0, %mm1 not supported by gcc 2.7.2.3 or egcs 1.1 */
- : "%mm0", "%mm1" // clobber list
-#endif
- );
- }
-
- sptr -= (width_mmx*2 - 2); // sign fixed
- dp -= (width_mmx*8 - 2); // sign fixed
- for (i = width; i; i--)
- {
- png_byte v[8];
- int j;
- sptr -= 2;
- png_memcpy(v, sptr, 2);
- for (j = 0; j < png_pass_inc[pass]; j++)
- {
- dp -= 2;
- png_memcpy(dp, v, 2);
- }
- }
- }
- else if (width) // pass == 4 or 5
- {
- int width_mmx = ((width >> 1) << 1) ;
- width -= width_mmx; // 0,1 pixels => 0,2 bytes
- if (width_mmx)
- {
- int dummy_value_c; // fix 'forbidden register spilled'
- int dummy_value_S;
- int dummy_value_D;
-
- __asm__ __volatile__ (
- "subl $2, %%esi \n\t"
- "subl $6, %%edi \n\t"
-
- ".loop2_pass4: \n\t"
- "movd (%%esi), %%mm0 \n\t" // x x x x 3 2 1 0
- "punpcklwd %%mm0, %%mm0 \n\t" // 3 2 3 2 1 0 1 0
- "subl $4, %%esi \n\t"
- "movq %%mm0, (%%edi) \n\t"
- "subl $8, %%edi \n\t"
- "subl $2, %%ecx \n\t"
- "jnz .loop2_pass4 \n\t"
- "EMMS \n\t" // DONE
-
- : "=c" (dummy_value_c), // output regs (dummy)
- "=S" (dummy_value_S),
- "=D" (dummy_value_D)
-
- : "1" (sptr), // esi // input regs
- "2" (dp), // edi
- "0" (width_mmx) // ecx
-
-#if 0 /* %mm0 not supported by gcc 2.7.2.3 or egcs 1.1 */
- : "%mm0" // clobber list
-#endif
- );
- }
-
- sptr -= (width_mmx*2 - 2); // sign fixed
- dp -= (width_mmx*4 - 2); // sign fixed
- for (i = width; i; i--)
- {
- png_byte v[8];
- int j;
- sptr -= 2;
- png_memcpy(v, sptr, 2);
- for (j = 0; j < png_pass_inc[pass]; j++)
- {
- dp -= 2;
- png_memcpy(dp, v, 2);
- }
- }
- }
- } /* end of pixel_bytes == 2 */
-
- //--------------------------------------------------------------
- else if (pixel_bytes == 4)
- {
- if (((pass == 0) || (pass == 1)) && width)
- {
- int width_mmx = ((width >> 1) << 1);
- width -= width_mmx; // 0,1 pixels => 0,4 bytes
- if (width_mmx)
- {
- int dummy_value_c; // fix 'forbidden register spilled'
- int dummy_value_S;
- int dummy_value_D;
-
- __asm__ __volatile__ (
- "subl $4, %%esi \n\t"
- "subl $60, %%edi \n\t"
-
- ".loop4_pass0: \n\t"
- "movq (%%esi), %%mm0 \n\t" // 7 6 5 4 3 2 1 0
- "movq %%mm0, %%mm1 \n\t" // 7 6 5 4 3 2 1 0
- "punpckldq %%mm0, %%mm0 \n\t" // 3 2 1 0 3 2 1 0
- "punpckhdq %%mm1, %%mm1 \n\t" // 7 6 5 4 7 6 5 4
- "movq %%mm0, (%%edi) \n\t"
- "movq %%mm0, 8(%%edi) \n\t"
- "movq %%mm0, 16(%%edi) \n\t"
- "movq %%mm0, 24(%%edi) \n\t"
- "movq %%mm1, 32(%%edi) \n\t"
- "movq %%mm1, 40(%%edi) \n\t"
- "movq %%mm1, 48(%%edi) \n\t"
- "subl $8, %%esi \n\t"
- "movq %%mm1, 56(%%edi) \n\t"
- "subl $64, %%edi \n\t"
- "subl $2, %%ecx \n\t"
- "jnz .loop4_pass0 \n\t"
- "EMMS \n\t" // DONE
-
- : "=c" (dummy_value_c), // output regs (dummy)
- "=S" (dummy_value_S),
- "=D" (dummy_value_D)
-
- : "1" (sptr), // esi // input regs
- "2" (dp), // edi
- "0" (width_mmx) // ecx
-
-#if 0 /* %mm0, %mm1 not supported by gcc 2.7.2.3 or egcs 1.1 */
- : "%mm0", "%mm1" // clobber list
-#endif
- );
- }
-
- sptr -= (width_mmx*4 - 4); // sign fixed
- dp -= (width_mmx*32 - 4); // sign fixed
- for (i = width; i; i--)
- {
- png_byte v[8];
- int j;
- sptr -= 4;
- png_memcpy(v, sptr, 4);
- for (j = 0; j < png_pass_inc[pass]; j++)
- {
- dp -= 4;
- png_memcpy(dp, v, 4);
- }
- }
- }
- else if (((pass == 2) || (pass == 3)) && width)
- {
- int width_mmx = ((width >> 1) << 1);
- width -= width_mmx; // 0,1 pixels => 0,4 bytes
- if (width_mmx)
- {
- int dummy_value_c; // fix 'forbidden register spilled'
- int dummy_value_S;
- int dummy_value_D;
-
- __asm__ __volatile__ (
- "subl $4, %%esi \n\t"
- "subl $28, %%edi \n\t"
-
- ".loop4_pass2: \n\t"
- "movq (%%esi), %%mm0 \n\t" // 7 6 5 4 3 2 1 0
- "movq %%mm0, %%mm1 \n\t" // 7 6 5 4 3 2 1 0
- "punpckldq %%mm0, %%mm0 \n\t" // 3 2 1 0 3 2 1 0
- "punpckhdq %%mm1, %%mm1 \n\t" // 7 6 5 4 7 6 5 4
- "movq %%mm0, (%%edi) \n\t"
- "movq %%mm0, 8(%%edi) \n\t"
- "movq %%mm1, 16(%%edi) \n\t"
- "movq %%mm1, 24(%%edi) \n\t"
- "subl $8, %%esi \n\t"
- "subl $32, %%edi \n\t"
- "subl $2, %%ecx \n\t"
- "jnz .loop4_pass2 \n\t"
- "EMMS \n\t" // DONE
-
- : "=c" (dummy_value_c), // output regs (dummy)
- "=S" (dummy_value_S),
- "=D" (dummy_value_D)
-
- : "1" (sptr), // esi // input regs
- "2" (dp), // edi
- "0" (width_mmx) // ecx
-
-#if 0 /* %mm0, %mm1 not supported by gcc 2.7.2.3 or egcs 1.1 */
- : "%mm0", "%mm1" // clobber list
-#endif
- );
- }
-
- sptr -= (width_mmx*4 - 4); // sign fixed
- dp -= (width_mmx*16 - 4); // sign fixed
- for (i = width; i; i--)
- {
- png_byte v[8];
- int j;
- sptr -= 4;
- png_memcpy(v, sptr, 4);
- for (j = 0; j < png_pass_inc[pass]; j++)
- {
- dp -= 4;
- png_memcpy(dp, v, 4);
- }
- }
- }
- else if (width) // pass == 4 or 5
- {
- int width_mmx = ((width >> 1) << 1) ;
- width -= width_mmx; // 0,1 pixels => 0,4 bytes
- if (width_mmx)
- {
- int dummy_value_c; // fix 'forbidden register spilled'
- int dummy_value_S;
- int dummy_value_D;
-
- __asm__ __volatile__ (
- "subl $4, %%esi \n\t"
- "subl $12, %%edi \n\t"
-
- ".loop4_pass4: \n\t"
- "movq (%%esi), %%mm0 \n\t" // 7 6 5 4 3 2 1 0
- "movq %%mm0, %%mm1 \n\t" // 7 6 5 4 3 2 1 0
- "punpckldq %%mm0, %%mm0 \n\t" // 3 2 1 0 3 2 1 0
- "punpckhdq %%mm1, %%mm1 \n\t" // 7 6 5 4 7 6 5 4
- "movq %%mm0, (%%edi) \n\t"
- "subl $8, %%esi \n\t"
- "movq %%mm1, 8(%%edi) \n\t"
- "subl $16, %%edi \n\t"
- "subl $2, %%ecx \n\t"
- "jnz .loop4_pass4 \n\t"
- "EMMS \n\t" // DONE
-
- : "=c" (dummy_value_c), // output regs (dummy)
- "=S" (dummy_value_S),
- "=D" (dummy_value_D)
-
- : "1" (sptr), // esi // input regs
- "2" (dp), // edi
- "0" (width_mmx) // ecx
-
-#if 0 /* %mm0, %mm1 not supported by gcc 2.7.2.3 or egcs 1.1 */
- : "%mm0", "%mm1" // clobber list
-#endif
- );
- }
-
- sptr -= (width_mmx*4 - 4); // sign fixed
- dp -= (width_mmx*8 - 4); // sign fixed
- for (i = width; i; i--)
- {
- png_byte v[8];
- int j;
- sptr -= 4;
- png_memcpy(v, sptr, 4);
- for (j = 0; j < png_pass_inc[pass]; j++)
- {
- dp -= 4;
- png_memcpy(dp, v, 4);
- }
- }
- }
- } /* end of pixel_bytes == 4 */
-
- //--------------------------------------------------------------
- else if (pixel_bytes == 8)
- {
-// GRR TEST: should work, but needs testing (special 64-bit version of rpng2?)
- // GRR NOTE: no need to combine passes here!
- if (((pass == 0) || (pass == 1)) && width)
- {
- int dummy_value_c; // fix 'forbidden register spilled'
- int dummy_value_S;
- int dummy_value_D;
-
- // source is 8-byte RRGGBBAA
- // dest is 64-byte RRGGBBAA RRGGBBAA RRGGBBAA RRGGBBAA ...
- __asm__ __volatile__ (
- "subl $56, %%edi \n\t" // start of last block
-
- ".loop8_pass0: \n\t"
- "movq (%%esi), %%mm0 \n\t" // 7 6 5 4 3 2 1 0
- "movq %%mm0, (%%edi) \n\t"
- "movq %%mm0, 8(%%edi) \n\t"
- "movq %%mm0, 16(%%edi) \n\t"
- "movq %%mm0, 24(%%edi) \n\t"
- "movq %%mm0, 32(%%edi) \n\t"
- "movq %%mm0, 40(%%edi) \n\t"
- "movq %%mm0, 48(%%edi) \n\t"
- "subl $8, %%esi \n\t"
- "movq %%mm0, 56(%%edi) \n\t"
- "subl $64, %%edi \n\t"
- "decl %%ecx \n\t"
- "jnz .loop8_pass0 \n\t"
- "EMMS \n\t" // DONE
-
- : "=c" (dummy_value_c), // output regs (dummy)
- "=S" (dummy_value_S),
- "=D" (dummy_value_D)
-
- : "1" (sptr), // esi // input regs
- "2" (dp), // edi
- "0" (width) // ecx
-
-#if 0 /* %mm0 not supported by gcc 2.7.2.3 or egcs 1.1 */
- : "%mm0" // clobber list
-#endif
- );
- }
- else if (((pass == 2) || (pass == 3)) && width)
- {
- // source is 8-byte RRGGBBAA
- // dest is 32-byte RRGGBBAA RRGGBBAA RRGGBBAA RRGGBBAA
- // (recall that expansion is _in place_: sptr and dp
- // both point at locations within same row buffer)
- {
- int dummy_value_c; // fix 'forbidden register spilled'
- int dummy_value_S;
- int dummy_value_D;
-
- __asm__ __volatile__ (
- "subl $24, %%edi \n\t" // start of last block
-
- ".loop8_pass2: \n\t"
- "movq (%%esi), %%mm0 \n\t" // 7 6 5 4 3 2 1 0
- "movq %%mm0, (%%edi) \n\t"
- "movq %%mm0, 8(%%edi) \n\t"
- "movq %%mm0, 16(%%edi) \n\t"
- "subl $8, %%esi \n\t"
- "movq %%mm0, 24(%%edi) \n\t"
- "subl $32, %%edi \n\t"
- "decl %%ecx \n\t"
- "jnz .loop8_pass2 \n\t"
- "EMMS \n\t" // DONE
-
- : "=c" (dummy_value_c), // output regs (dummy)
- "=S" (dummy_value_S),
- "=D" (dummy_value_D)
-
- : "1" (sptr), // esi // input regs
- "2" (dp), // edi
- "0" (width) // ecx
-
-#if 0 /* %mm0 not supported by gcc 2.7.2.3 or egcs 1.1 */
- : "%mm0" // clobber list
-#endif
- );
- }
- }
- else if (width) // pass == 4 or 5
- {
- // source is 8-byte RRGGBBAA
- // dest is 16-byte RRGGBBAA RRGGBBAA
- {
- int dummy_value_c; // fix 'forbidden register spilled'
- int dummy_value_S;
- int dummy_value_D;
-
- __asm__ __volatile__ (
- "subl $8, %%edi \n\t" // start of last block
-
- ".loop8_pass4: \n\t"
- "movq (%%esi), %%mm0 \n\t" // 7 6 5 4 3 2 1 0
- "movq %%mm0, (%%edi) \n\t"
- "subl $8, %%esi \n\t"
- "movq %%mm0, 8(%%edi) \n\t"
- "subl $16, %%edi \n\t"
- "decl %%ecx \n\t"
- "jnz .loop8_pass4 \n\t"
- "EMMS \n\t" // DONE
-
- : "=c" (dummy_value_c), // output regs (dummy)
- "=S" (dummy_value_S),
- "=D" (dummy_value_D)
-
- : "1" (sptr), // esi // input regs
- "2" (dp), // edi
- "0" (width) // ecx
-
-#if 0 /* %mm0 not supported by gcc 2.7.2.3 or egcs 1.1 */
- : "%mm0" // clobber list
-#endif
- );
- }
- }
-
- } /* end of pixel_bytes == 8 */
-
- //--------------------------------------------------------------
- else if (pixel_bytes == 6)
- {
- for (i = width; i; i--)
- {
- png_byte v[8];
- int j;
- png_memcpy(v, sptr, 6);
- for (j = 0; j < png_pass_inc[pass]; j++)
- {
- png_memcpy(dp, v, 6);
- dp -= 6;
- }
- sptr -= 6;
- }
- } /* end of pixel_bytes == 6 */
-
- //--------------------------------------------------------------
- else
- {
- for (i = width; i; i--)
- {
- png_byte v[8];
- int j;
- png_memcpy(v, sptr, pixel_bytes);
- for (j = 0; j < png_pass_inc[pass]; j++)
- {
- png_memcpy(dp, v, pixel_bytes);
- dp -= pixel_bytes;
- }
- sptr-= pixel_bytes;
- }
- }
- } // end of _mmx_supported ========================================
-
- else /* MMX not supported: use modified C code - takes advantage
- * of inlining of png_memcpy for a constant */
- /* GRR 19991007: does it? or should pixel_bytes in each
- * block be replaced with immediate value (e.g., 1)? */
- /* GRR 19991017: replaced with constants in each case */
-#endif /* PNG_MMX_CODE_SUPPORTED */
- {
- if (pixel_bytes == 1)
- {
- for (i = width; i; i--)
- {
- int j;
- for (j = 0; j < png_pass_inc[pass]; j++)
- {
- *dp-- = *sptr;
- }
- --sptr;
- }
- }
- else if (pixel_bytes == 3)
- {
- for (i = width; i; i--)
- {
- png_byte v[8];
- int j;
- png_memcpy(v, sptr, 3);
- for (j = 0; j < png_pass_inc[pass]; j++)
- {
- png_memcpy(dp, v, 3);
- dp -= 3;
- }
- sptr -= 3;
- }
- }
- else if (pixel_bytes == 2)
- {
- for (i = width; i; i--)
- {
- png_byte v[8];
- int j;
- png_memcpy(v, sptr, 2);
- for (j = 0; j < png_pass_inc[pass]; j++)
- {
- png_memcpy(dp, v, 2);
- dp -= 2;
- }
- sptr -= 2;
- }
- }
- else if (pixel_bytes == 4)
- {
- for (i = width; i; i--)
- {
- png_byte v[8];
- int j;
- png_memcpy(v, sptr, 4);
- for (j = 0; j < png_pass_inc[pass]; j++)
- {
-#ifdef PNG_DEBUG
- if (dp < row || dp+3 > row+png_ptr->row_buf_size)
- {
- printf("dp out of bounds: row=%d, dp=%d, rp=%d\n",
- row, dp, row+png_ptr->row_buf_size);
- printf("row_buf=%d\n",png_ptr->row_buf_size);
- }
-#endif
- png_memcpy(dp, v, 4);
- dp -= 4;
- }
- sptr -= 4;
- }
- }
- else if (pixel_bytes == 6)
- {
- for (i = width; i; i--)
- {
- png_byte v[8];
- int j;
- png_memcpy(v, sptr, 6);
- for (j = 0; j < png_pass_inc[pass]; j++)
- {
- png_memcpy(dp, v, 6);
- dp -= 6;
- }
- sptr -= 6;
- }
- }
- else if (pixel_bytes == 8)
- {
- for (i = width; i; i--)
- {
- png_byte v[8];
- int j;
- png_memcpy(v, sptr, 8);
- for (j = 0; j < png_pass_inc[pass]; j++)
- {
- png_memcpy(dp, v, 8);
- dp -= 8;
- }
- sptr -= 8;
- }
- }
- else /* GRR: should never be reached */
- {
- for (i = width; i; i--)
- {
- png_byte v[8];
- int j;
- png_memcpy(v, sptr, pixel_bytes);
- for (j = 0; j < png_pass_inc[pass]; j++)
- {
- png_memcpy(dp, v, pixel_bytes);
- dp -= pixel_bytes;
- }
- sptr -= pixel_bytes;
- }
- }
-
- } /* end if (MMX not supported) */
- break;
- }
- } /* end switch (row_info->pixel_depth) */
-
- row_info->width = final_width;
-
- row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,final_width);
- }
-
-} /* end png_do_read_interlace() */
-
-#endif /* PNG_HAVE_MMX_READ_INTERLACE */
-#endif /* PNG_READ_INTERLACING_SUPPORTED */
-
-
-
-#if defined(PNG_HAVE_MMX_READ_FILTER_ROW)
-#if defined(PNG_MMX_CODE_SUPPORTED)
-
-// These variables are utilized in the functions below. They are declared
-// globally here to ensure alignment on 8-byte boundaries.
-
-union uAll {
- long long use;
- double align;
-} _LBCarryMask = {0x0101010101010101LL},
- _HBClearMask = {0x7f7f7f7f7f7f7f7fLL},
- _ActiveMask, _ActiveMask2, _ActiveMaskEnd, _ShiftBpp, _ShiftRem;
-
-#ifdef PNG_THREAD_UNSAFE_OK
-//===========================================================================//
-// //
-// P N G _ R E A D _ F I L T E R _ R O W _ M M X _ A V G //
-// //
-//===========================================================================//
-
-// Optimized code for PNG Average filter decoder
-
-static void /* PRIVATE */
-png_read_filter_row_mmx_avg(png_row_infop row_info, png_bytep row,
- png_bytep prev_row)
-{
- int bpp;
- int dummy_value_c; // fix 'forbidden register 2 (cx) was spilled' error
- int dummy_value_S;
- int dummy_value_D;
-
- bpp = (row_info->pixel_depth + 7) >> 3; // get # bytes per pixel
- _FullLength = row_info->rowbytes; // # of bytes to filter
-
- __asm__ __volatile__ (
- // initialize address pointers and offset
-#ifdef __PIC__
-#ifdef __x86_64__
- "pushq %%rbx \n\t" // save index to Global Offset Table
-#else
- "pushl %%ebx \n\t" // save index to Global Offset Table
-#endif
-#endif
-//pre "movl row, %%edi \n\t" // edi: Avg(x)
- "xorl %%ebx, %%ebx \n\t" // ebx: x
- "movl %%edi, %%edx \n\t"
-//pre "movl prev_row, %%esi \n\t" // esi: Prior(x)
-//pre "subl bpp, %%edx \n\t" // (bpp is preloaded into ecx)
- "subl %%ecx, %%edx \n\t" // edx: Raw(x-bpp)
-
- "xorl %%eax,%%eax \n\t"
-
- // Compute the Raw value for the first bpp bytes
- // Raw(x) = Avg(x) + (Prior(x)/2)
- "avg_rlp: \n\t"
- "movb (%%esi,%%ebx,),%%al \n\t" // load al with Prior(x)
- "incl %%ebx \n\t"
- "shrb %%al \n\t" // divide by 2
- "addb -1(%%edi,%%ebx,),%%al \n\t" // add Avg(x); -1 to offset inc ebx
-//pre "cmpl bpp, %%ebx \n\t" // (bpp is preloaded into ecx)
- "cmpl %%ecx, %%ebx \n\t"
- "movb %%al,-1(%%edi,%%ebx,) \n\t" // write Raw(x); -1 to offset inc ebx
- "jb avg_rlp \n\t" // mov does not affect flags
-
- // get # of bytes to alignment
- "movl %%edi, _dif \n\t" // take start of row
- "addl %%ebx, _dif \n\t" // add bpp
- "addl $0xf, _dif \n\t" // add 7+8 to incr past alignment bdry
- "andl $0xfffffff8, _dif \n\t" // mask to alignment boundary
- "subl %%edi, _dif \n\t" // subtract from start => value ebx at
- "jz avg_go \n\t" // alignment
-
- // fix alignment
- // Compute the Raw value for the bytes up to the alignment boundary
- // Raw(x) = Avg(x) + ((Raw(x-bpp) + Prior(x))/2)
- "xorl %%ecx, %%ecx \n\t"
-
- "avg_lp1: \n\t"
- "xorl %%eax, %%eax \n\t"
- "movb (%%esi,%%ebx,), %%cl \n\t" // load cl with Prior(x)
- "movb (%%edx,%%ebx,), %%al \n\t" // load al with Raw(x-bpp)
- "addw %%cx, %%ax \n\t"
- "incl %%ebx \n\t"
- "shrw %%ax \n\t" // divide by 2
- "addb -1(%%edi,%%ebx,), %%al \n\t" // add Avg(x); -1 to offset inc ebx
- "cmpl _dif, %%ebx \n\t" // check if at alignment boundary
- "movb %%al, -1(%%edi,%%ebx,) \n\t" // write Raw(x); -1 to offset inc ebx
- "jb avg_lp1 \n\t" // repeat until at alignment boundary
-
- "avg_go: \n\t"
- "movl _FullLength, %%eax \n\t"
- "movl %%eax, %%ecx \n\t"
- "subl %%ebx, %%eax \n\t" // subtract alignment fix
- "andl $0x00000007, %%eax \n\t" // calc bytes over mult of 8
- "subl %%eax, %%ecx \n\t" // drop over bytes from original length
- "movl %%ecx, _MMXLength \n\t"
-#ifdef __PIC__
-#ifdef __x86_64__
- "popq %%rbx \n\t" // restore index to Global Offset Table
-#else
- "popl %%ebx \n\t" // restore index to Global Offset Table
-#endif
-#endif
-
- : "=c" (dummy_value_c), // output regs (dummy)
- "=S" (dummy_value_S),
- "=D" (dummy_value_D)
-
- : "0" (bpp), // ecx // input regs
- "1" (prev_row), // esi
- "2" (row) // edi
-
- : "%eax", "%edx" // clobber list
-#ifndef __PIC__
- , "%ebx"
-#endif
- // GRR: INCLUDE "memory" as clobbered? (_dif, _MMXLength)
- // (seems to work fine without...)
- );
-
- // now do the math for the rest of the row
- switch (bpp)
- {
- case 3:
- {
- _ActiveMask.use = 0x0000000000ffffffLL;
- _ShiftBpp.use = 24; // == 3 * 8
- _ShiftRem.use = 40; // == 64 - 24
-
- __asm__ __volatile__ (
- // re-init address pointers and offset
- "movq _ActiveMask, %%mm7 \n\t"
- "movl _dif, %%ecx \n\t" // ecx: x = offset to
- "movq _LBCarryMask, %%mm5 \n\t" // alignment boundary
-// preload "movl row, %%edi \n\t" // edi: Avg(x)
- "movq _HBClearMask, %%mm4 \n\t"
-// preload "movl prev_row, %%esi \n\t" // esi: Prior(x)
-
- // prime the pump: load the first Raw(x-bpp) data set
- "movq -8(%%edi,%%ecx,), %%mm2 \n\t" // load previous aligned 8 bytes
- // (correct pos. in loop below)
- "avg_3lp: \n\t"
- "movq (%%edi,%%ecx,), %%mm0 \n\t" // load mm0 with Avg(x)
- "movq %%mm5, %%mm3 \n\t"
- "psrlq _ShiftRem, %%mm2 \n\t" // correct position Raw(x-bpp)
- // data
- "movq (%%esi,%%ecx,), %%mm1 \n\t" // load mm1 with Prior(x)
- "movq %%mm7, %%mm6 \n\t"
- "pand %%mm1, %%mm3 \n\t" // get lsb for each prev_row byte
- "psrlq $1, %%mm1 \n\t" // divide prev_row bytes by 2
- "pand %%mm4, %%mm1 \n\t" // clear invalid bit 7 of each
- // byte
- "paddb %%mm1, %%mm0 \n\t" // add (Prev_row/2) to Avg for
- // each byte
- // add 1st active group (Raw(x-bpp)/2) to average with LBCarry
- "movq %%mm3, %%mm1 \n\t" // now use mm1 for getting
- // LBCarrys
- "pand %%mm2, %%mm1 \n\t" // get LBCarrys for each byte
- // where both
- // lsb's were == 1 (only valid for active group)
- "psrlq $1, %%mm2 \n\t" // divide raw bytes by 2
- "pand %%mm4, %%mm2 \n\t" // clear invalid bit 7 of each
- // byte
- "paddb %%mm1, %%mm2 \n\t" // add LBCarrys to (Raw(x-bpp)/2)
- // for each byte
- "pand %%mm6, %%mm2 \n\t" // leave only Active Group 1
- // bytes to add to Avg
- "paddb %%mm2, %%mm0 \n\t" // add (Raw/2) + LBCarrys to
- // Avg for each Active
- // byte
- // add 2nd active group (Raw(x-bpp)/2) to average with _LBCarry
- "psllq _ShiftBpp, %%mm6 \n\t" // shift the mm6 mask to cover
- // bytes 3-5
- "movq %%mm0, %%mm2 \n\t" // mov updated Raws to mm2
- "psllq _ShiftBpp, %%mm2 \n\t" // shift data to pos. correctly
- "movq %%mm3, %%mm1 \n\t" // now use mm1 for getting
- // LBCarrys
- "pand %%mm2, %%mm1 \n\t" // get LBCarrys for each byte
- // where both
- // lsb's were == 1 (only valid for active group)
- "psrlq $1, %%mm2 \n\t" // divide raw bytes by 2
- "pand %%mm4, %%mm2 \n\t" // clear invalid bit 7 of each
- // byte
- "paddb %%mm1, %%mm2 \n\t" // add LBCarrys to (Raw(x-bpp)/2)
- // for each byte
- "pand %%mm6, %%mm2 \n\t" // leave only Active Group 2
- // bytes to add to Avg
- "paddb %%mm2, %%mm0 \n\t" // add (Raw/2) + LBCarrys to
- // Avg for each Active
- // byte
-
- // add 3rd active group (Raw(x-bpp)/2) to average with _LBCarry
- "psllq _ShiftBpp, %%mm6 \n\t" // shift mm6 mask to cover last
- // two
- // bytes
- "movq %%mm0, %%mm2 \n\t" // mov updated Raws to mm2
- "psllq _ShiftBpp, %%mm2 \n\t" // shift data to pos. correctly
- // Data only needs to be shifted once here to
- // get the correct x-bpp offset.
- "movq %%mm3, %%mm1 \n\t" // now use mm1 for getting
- // LBCarrys
- "pand %%mm2, %%mm1 \n\t" // get LBCarrys for each byte
- // where both
- // lsb's were == 1 (only valid for active group)
- "psrlq $1, %%mm2 \n\t" // divide raw bytes by 2
- "pand %%mm4, %%mm2 \n\t" // clear invalid bit 7 of each
- // byte
- "paddb %%mm1, %%mm2 \n\t" // add LBCarrys to (Raw(x-bpp)/2)
- // for each byte
- "pand %%mm6, %%mm2 \n\t" // leave only Active Group 2
- // bytes to add to Avg
- "addl $8, %%ecx \n\t"
- "paddb %%mm2, %%mm0 \n\t" // add (Raw/2) + LBCarrys to
- // Avg for each Active
- // byte
- // now ready to write back to memory
- "movq %%mm0, -8(%%edi,%%ecx,) \n\t"
- // move updated Raw(x) to use as Raw(x-bpp) for next loop
- "cmpl _MMXLength, %%ecx \n\t"
- "movq %%mm0, %%mm2 \n\t" // mov updated Raw(x) to mm2
- "jb avg_3lp \n\t"
-
- : "=S" (dummy_value_S), // output regs (dummy)
- "=D" (dummy_value_D)
-
- : "0" (prev_row), // esi // input regs
- "1" (row) // edi
-
- : "%ecx" // clobber list
-#if 0 /* %mm0, ..., %mm7 not supported by gcc 2.7.2.3 or egcs 1.1 */
- , "%mm0", "%mm1", "%mm2", "%mm3"
- , "%mm4", "%mm5", "%mm6", "%mm7"
-#endif
- );
- }
- break; // end 3 bpp
-
- case 6:
- case 4:
- //case 7: // who wrote this? PNG doesn't support 5 or 7 bytes/pixel
- //case 5: // GRR BOGUS
- {
- _ActiveMask.use = 0xffffffffffffffffLL; // use shift below to clear
- // appropriate inactive bytes
- _ShiftBpp.use = bpp << 3;
- _ShiftRem.use = 64 - _ShiftBpp.use;
-
- __asm__ __volatile__ (
- "movq _HBClearMask, %%mm4 \n\t"
-
- // re-init address pointers and offset
- "movl _dif, %%ecx \n\t" // ecx: x = offset to
- // alignment boundary
-
- // load _ActiveMask and clear all bytes except for 1st active group
- "movq _ActiveMask, %%mm7 \n\t"
-// preload "movl row, %%edi \n\t" // edi: Avg(x)
- "psrlq _ShiftRem, %%mm7 \n\t"
-// preload "movl prev_row, %%esi \n\t" // esi: Prior(x)
- "movq %%mm7, %%mm6 \n\t"
- "movq _LBCarryMask, %%mm5 \n\t"
- "psllq _ShiftBpp, %%mm6 \n\t" // create mask for 2nd active
- // group
-
- // prime the pump: load the first Raw(x-bpp) data set
- "movq -8(%%edi,%%ecx,), %%mm2 \n\t" // load previous aligned 8 bytes
- // (we correct pos. in loop below)
- "avg_4lp: \n\t"
- "movq (%%edi,%%ecx,), %%mm0 \n\t"
- "psrlq _ShiftRem, %%mm2 \n\t" // shift data to pos. correctly
- "movq (%%esi,%%ecx,), %%mm1 \n\t"
- // add (Prev_row/2) to average
- "movq %%mm5, %%mm3 \n\t"
- "pand %%mm1, %%mm3 \n\t" // get lsb for each prev_row byte
- "psrlq $1, %%mm1 \n\t" // divide prev_row bytes by 2
- "pand %%mm4, %%mm1 \n\t" // clear invalid bit 7 of each
- // byte
- "paddb %%mm1, %%mm0 \n\t" // add (Prev_row/2) to Avg for
- // each byte
- // add 1st active group (Raw(x-bpp)/2) to average with _LBCarry
- "movq %%mm3, %%mm1 \n\t" // now use mm1 for getting
- // LBCarrys
- "pand %%mm2, %%mm1 \n\t" // get LBCarrys for each byte
- // where both
- // lsb's were == 1 (only valid for active group)
- "psrlq $1, %%mm2 \n\t" // divide raw bytes by 2
- "pand %%mm4, %%mm2 \n\t" // clear invalid bit 7 of each
- // byte
- "paddb %%mm1, %%mm2 \n\t" // add LBCarrys to (Raw(x-bpp)/2)
- // for each byte
- "pand %%mm7, %%mm2 \n\t" // leave only Active Group 1
- // bytes to add to Avg
- "paddb %%mm2, %%mm0 \n\t" // add (Raw/2) + LBCarrys to Avg
- // for each Active
- // byte
- // add 2nd active group (Raw(x-bpp)/2) to average with _LBCarry
- "movq %%mm0, %%mm2 \n\t" // mov updated Raws to mm2
- "psllq _ShiftBpp, %%mm2 \n\t" // shift data to pos. correctly
- "addl $8, %%ecx \n\t"
- "movq %%mm3, %%mm1 \n\t" // now use mm1 for getting
- // LBCarrys
- "pand %%mm2, %%mm1 \n\t" // get LBCarrys for each byte
- // where both
- // lsb's were == 1 (only valid for active group)
- "psrlq $1, %%mm2 \n\t" // divide raw bytes by 2
- "pand %%mm4, %%mm2 \n\t" // clear invalid bit 7 of each
- // byte
- "paddb %%mm1, %%mm2 \n\t" // add LBCarrys to (Raw(x-bpp)/2)
- // for each byte
- "pand %%mm6, %%mm2 \n\t" // leave only Active Group 2
- // bytes to add to Avg
- "paddb %%mm2, %%mm0 \n\t" // add (Raw/2) + LBCarrys to
- // Avg for each Active
- // byte
- "cmpl _MMXLength, %%ecx \n\t"
- // now ready to write back to memory
- "movq %%mm0, -8(%%edi,%%ecx,) \n\t"
- // prep Raw(x-bpp) for next loop
- "movq %%mm0, %%mm2 \n\t" // mov updated Raws to mm2
- "jb avg_4lp \n\t"
-
- : "=S" (dummy_value_S), // output regs (dummy)
- "=D" (dummy_value_D)
-
- : "0" (prev_row), // esi // input regs
- "1" (row) // edi
-
- : "%ecx" // clobber list
-#if 0 /* %mm0, ..., %mm7 not supported by gcc 2.7.2.3 or egcs 1.1 */
- , "%mm0", "%mm1", "%mm2", "%mm3"
- , "%mm4", "%mm5", "%mm6", "%mm7"
-#endif
- );
- }
- break; // end 4,6 bpp
-
- case 2:
- {
- _ActiveMask.use = 0x000000000000ffffLL;
- _ShiftBpp.use = 16; // == 2 * 8
- _ShiftRem.use = 48; // == 64 - 16
-
- __asm__ __volatile__ (
- // load _ActiveMask
- "movq _ActiveMask, %%mm7 \n\t"
- // re-init address pointers and offset
- "movl _dif, %%ecx \n\t" // ecx: x = offset to alignment
- // boundary
- "movq _LBCarryMask, %%mm5 \n\t"
-// preload "movl row, %%edi \n\t" // edi: Avg(x)
- "movq _HBClearMask, %%mm4 \n\t"
-// preload "movl prev_row, %%esi \n\t" // esi: Prior(x)
-
- // prime the pump: load the first Raw(x-bpp) data set
- "movq -8(%%edi,%%ecx,), %%mm2 \n\t" // load previous aligned 8 bytes
- // (we correct pos. in loop below)
- "avg_2lp: \n\t"
- "movq (%%edi,%%ecx,), %%mm0 \n\t"
- "psrlq _ShiftRem, %%mm2 \n\t" // shift data to pos. correctly
- "movq (%%esi,%%ecx,), %%mm1 \n\t" // (GRR BUGFIX: was psllq)
- // add (Prev_row/2) to average
- "movq %%mm5, %%mm3 \n\t"
- "pand %%mm1, %%mm3 \n\t" // get lsb for each prev_row byte
- "psrlq $1, %%mm1 \n\t" // divide prev_row bytes by 2
- "pand %%mm4, %%mm1 \n\t" // clear invalid bit 7 of each
- // byte
- "movq %%mm7, %%mm6 \n\t"
- "paddb %%mm1, %%mm0 \n\t" // add (Prev_row/2) to Avg for
- // each byte
-
- // add 1st active group (Raw(x-bpp)/2) to average with _LBCarry
- "movq %%mm3, %%mm1 \n\t" // now use mm1 for getting
- // LBCarrys
- "pand %%mm2, %%mm1 \n\t" // get LBCarrys for each byte
- // where both
- // lsb's were == 1 (only valid
- // for active group)
- "psrlq $1, %%mm2 \n\t" // divide raw bytes by 2
- "pand %%mm4, %%mm2 \n\t" // clear invalid bit 7 of each
- // byte
- "paddb %%mm1, %%mm2 \n\t" // add LBCarrys to (Raw(x-bpp)/2)
- // for each byte
- "pand %%mm6, %%mm2 \n\t" // leave only Active Group 1
- // bytes to add to Avg
- "paddb %%mm2, %%mm0 \n\t" // add (Raw/2) + LBCarrys to Avg
- // for each Active byte
-
- // add 2nd active group (Raw(x-bpp)/2) to average with _LBCarry
- "psllq _ShiftBpp, %%mm6 \n\t" // shift the mm6 mask to cover
- // bytes 2 & 3
- "movq %%mm0, %%mm2 \n\t" // mov updated Raws to mm2
- "psllq _ShiftBpp, %%mm2 \n\t" // shift data to pos. correctly
- "movq %%mm3, %%mm1 \n\t" // now use mm1 for getting
- // LBCarrys
- "pand %%mm2, %%mm1 \n\t" // get LBCarrys for each byte
- // where both
- // lsb's were == 1 (only valid
- // for active group)
- "psrlq $1, %%mm2 \n\t" // divide raw bytes by 2
- "pand %%mm4, %%mm2 \n\t" // clear invalid bit 7 of each
- // byte
- "paddb %%mm1, %%mm2 \n\t" // add LBCarrys to (Raw(x-bpp)/2)
- // for each byte
- "pand %%mm6, %%mm2 \n\t" // leave only Active Group 2
- // bytes to add to Avg
- "paddb %%mm2, %%mm0 \n\t" // add (Raw/2) + LBCarrys to
- // Avg for each Active byte
-
- // add 3rd active group (Raw(x-bpp)/2) to average with _LBCarry
- "psllq _ShiftBpp, %%mm6 \n\t" // shift the mm6 mask to cover
- // bytes 4 & 5
- "movq %%mm0, %%mm2 \n\t" // mov updated Raws to mm2
- "psllq _ShiftBpp, %%mm2 \n\t" // shift data to pos. correctly
- "movq %%mm3, %%mm1 \n\t" // now use mm1 for getting
- // LBCarrys
- "pand %%mm2, %%mm1 \n\t" // get LBCarrys for each byte
- // where both lsb's were == 1
- // (only valid for active group)
- "psrlq $1, %%mm2 \n\t" // divide raw bytes by 2
- "pand %%mm4, %%mm2 \n\t" // clear invalid bit 7 of each
- // byte
- "paddb %%mm1, %%mm2 \n\t" // add LBCarrys to (Raw(x-bpp)/2)
- // for each byte
- "pand %%mm6, %%mm2 \n\t" // leave only Active Group 2
- // bytes to add to Avg
- "paddb %%mm2, %%mm0 \n\t" // add (Raw/2) + LBCarrys to
- // Avg for each Active byte
-
- // add 4th active group (Raw(x-bpp)/2) to average with _LBCarry
- "psllq _ShiftBpp, %%mm6 \n\t" // shift the mm6 mask to cover
- // bytes 6 & 7
- "movq %%mm0, %%mm2 \n\t" // mov updated Raws to mm2
- "psllq _ShiftBpp, %%mm2 \n\t" // shift data to pos. correctly
- "addl $8, %%ecx \n\t"
- "movq %%mm3, %%mm1 \n\t" // now use mm1 for getting
- // LBCarrys
- "pand %%mm2, %%mm1 \n\t" // get LBCarrys for each byte
- // where both
- // lsb's were == 1 (only valid
- // for active group)
- "psrlq $1, %%mm2 \n\t" // divide raw bytes by 2
- "pand %%mm4, %%mm2 \n\t" // clear invalid bit 7 of each
- // byte
- "paddb %%mm1, %%mm2 \n\t" // add LBCarrys to (Raw(x-bpp)/2)
- // for each byte
- "pand %%mm6, %%mm2 \n\t" // leave only Active Group 2
- // bytes to add to Avg
- "paddb %%mm2, %%mm0 \n\t" // add (Raw/2) + LBCarrys to
- // Avg for each Active byte
-
- "cmpl _MMXLength, %%ecx \n\t"
- // now ready to write back to memory
- "movq %%mm0, -8(%%edi,%%ecx,) \n\t"
- // prep Raw(x-bpp) for next loop
- "movq %%mm0, %%mm2 \n\t" // mov updated Raws to mm2
- "jb avg_2lp \n\t"
-
- : "=S" (dummy_value_S), // output regs (dummy)
- "=D" (dummy_value_D)
-
- : "0" (prev_row), // esi // input regs
- "1" (row) // edi
-
- : "%ecx" // clobber list
-#if 0 /* %mm0, ..., %mm7 not supported by gcc 2.7.2.3 or egcs 1.1 */
- , "%mm0", "%mm1", "%mm2", "%mm3"
- , "%mm4", "%mm5", "%mm6", "%mm7"
-#endif
- );
- }
- break; // end 2 bpp
-
- case 1:
- {
- __asm__ __volatile__ (
- // re-init address pointers and offset
-#ifdef __PIC__
-#ifdef __x86_64__
- "pushq %%rbx \n\t" // save Global Offset Table index
-#else
- "pushl %%ebx \n\t" // save Global Offset Table index
-#endif
-#endif
- "movl _dif, %%ebx \n\t" // ebx: x = offset to alignment
- // boundary
-// preload "movl row, %%edi \n\t" // edi: Avg(x)
- "cmpl _FullLength, %%ebx \n\t" // test if offset at end of array
- "jnb avg_1end \n\t"
- // do Paeth decode for remaining bytes
-// preload "movl prev_row, %%esi \n\t" // esi: Prior(x)
- "movl %%edi, %%edx \n\t"
-// preload "subl bpp, %%edx \n\t" // (bpp is preloaded into ecx)
- "subl %%ecx, %%edx \n\t" // edx: Raw(x-bpp)
- "xorl %%ecx, %%ecx \n\t" // zero ecx before using cl & cx
- // in loop below
- "avg_1lp: \n\t"
- // Raw(x) = Avg(x) + ((Raw(x-bpp) + Prior(x))/2)
- "xorl %%eax, %%eax \n\t"
- "movb (%%esi,%%ebx,), %%cl \n\t" // load cl with Prior(x)
- "movb (%%edx,%%ebx,), %%al \n\t" // load al with Raw(x-bpp)
- "addw %%cx, %%ax \n\t"
- "incl %%ebx \n\t"
- "shrw %%ax \n\t" // divide by 2
- "addb -1(%%edi,%%ebx,), %%al \n\t" // add Avg(x); -1 to offset
- // inc ebx
- "cmpl _FullLength, %%ebx \n\t" // check if at end of array
- "movb %%al, -1(%%edi,%%ebx,) \n\t" // write back Raw(x);
- // mov does not affect flags; -1 to offset inc ebx
- "jb avg_1lp \n\t"
-
- "avg_1end: \n\t"
-#ifdef __PIC__
-#ifdef __x86_64
- "popq %%rbx \n\t" // Global Offset Table index
-#else
- "popl %%ebx \n\t" // Global Offset Table index
-#endif
-#endif
-
- : "=c" (dummy_value_c), // output regs (dummy)
- "=S" (dummy_value_S),
- "=D" (dummy_value_D)
-
- : "0" (bpp), // ecx // input regs
- "1" (prev_row), // esi
- "2" (row) // edi
-
- : "%eax", "%edx" // clobber list
-#ifndef __PIC__
- , "%ebx"
-#endif
- );
- }
- return; // end 1 bpp
-
- case 8:
- {
- __asm__ __volatile__ (
- // re-init address pointers and offset
- "movl _dif, %%ecx \n\t" // ecx: x == offset to alignment
- "movq _LBCarryMask, %%mm5 \n\t" // boundary
-// preload "movl row, %%edi \n\t" // edi: Avg(x)
- "movq _HBClearMask, %%mm4 \n\t"
-// preload "movl prev_row, %%esi \n\t" // esi: Prior(x)
-
- // prime the pump: load the first Raw(x-bpp) data set
- "movq -8(%%edi,%%ecx,), %%mm2 \n\t" // load previous aligned 8 bytes
- // (NO NEED to correct pos. in loop below)
-
- "avg_8lp: \n\t"
- "movq (%%edi,%%ecx,), %%mm0 \n\t"
- "movq %%mm5, %%mm3 \n\t"
- "movq (%%esi,%%ecx,), %%mm1 \n\t"
- "addl $8, %%ecx \n\t"
- "pand %%mm1, %%mm3 \n\t" // get lsb for each prev_row byte
- "psrlq $1, %%mm1 \n\t" // divide prev_row bytes by 2
- "pand %%mm2, %%mm3 \n\t" // get LBCarrys for each byte
- // where both lsb's were == 1
- "psrlq $1, %%mm2 \n\t" // divide raw bytes by 2
- "pand %%mm4, %%mm1 \n\t" // clear invalid bit 7, each byte
- "paddb %%mm3, %%mm0 \n\t" // add LBCarrys to Avg, each byte
- "pand %%mm4, %%mm2 \n\t" // clear invalid bit 7, each byte
- "paddb %%mm1, %%mm0 \n\t" // add (Prev_row/2) to Avg, each
- "paddb %%mm2, %%mm0 \n\t" // add (Raw/2) to Avg for each
- "cmpl _MMXLength, %%ecx \n\t"
- "movq %%mm0, -8(%%edi,%%ecx,) \n\t"
- "movq %%mm0, %%mm2 \n\t" // reuse as Raw(x-bpp)
- "jb avg_8lp \n\t"
-
- : "=S" (dummy_value_S), // output regs (dummy)
- "=D" (dummy_value_D)
-
- : "0" (prev_row), // esi // input regs
- "1" (row) // edi
-
- : "%ecx" // clobber list
-#if 0 /* %mm0, ..., %mm5 not supported by gcc 2.7.2.3 or egcs 1.1 */
- , "%mm0", "%mm1", "%mm2"
- , "%mm3", "%mm4", "%mm5"
-#endif
- );
- }
- break; // end 8 bpp
-
- default: // bpp greater than 8 (!= 1,2,3,4,[5],6,[7],8)
- {
-
-#ifdef PNG_DEBUG
- // GRR: PRINT ERROR HERE: SHOULD NEVER BE REACHED
- png_debug(1,
- "Internal logic error in pnggccrd (png_read_filter_row_mmx_avg())\n");
-#endif
-
-#if 0
- __asm__ __volatile__ (
- "movq _LBCarryMask, %%mm5 \n\t"
- // re-init address pointers and offset
- "movl _dif, %%ebx \n\t" // ebx: x = offset to
- // alignment boundary
- "movl row, %%edi \n\t" // edi: Avg(x)
- "movq _HBClearMask, %%mm4 \n\t"
- "movl %%edi, %%edx \n\t"
- "movl prev_row, %%esi \n\t" // esi: Prior(x)
- "subl bpp, %%edx \n\t" // edx: Raw(x-bpp)
- "avg_Alp: \n\t"
- "movq (%%edi,%%ebx,), %%mm0 \n\t"
- "movq %%mm5, %%mm3 \n\t"
- "movq (%%esi,%%ebx,), %%mm1 \n\t"
- "pand %%mm1, %%mm3 \n\t" // get lsb for each prev_row byte
- "movq (%%edx,%%ebx,), %%mm2 \n\t"
- "psrlq $1, %%mm1 \n\t" // divide prev_row bytes by 2
- "pand %%mm2, %%mm3 \n\t" // get LBCarrys for each byte
- // where both lsb's were == 1
- "psrlq $1, %%mm2 \n\t" // divide raw bytes by 2
- "pand %%mm4, %%mm1 \n\t" // clear invalid bit 7 of each
- // byte
- "paddb %%mm3, %%mm0 \n\t" // add LBCarrys to Avg for each
- // byte
- "pand %%mm4, %%mm2 \n\t" // clear invalid bit 7 of each
- // byte
- "paddb %%mm1, %%mm0 \n\t" // add (Prev_row/2) to Avg for
- // each byte
- "addl $8, %%ebx \n\t"
- "paddb %%mm2, %%mm0 \n\t" // add (Raw/2) to Avg for each
- // byte
- "cmpl _MMXLength, %%ebx \n\t"
- "movq %%mm0, -8(%%edi,%%ebx,) \n\t"
- "jb avg_Alp \n\t"
-
- : // FIXASM: output regs/vars go here, e.g.: "=m" (memory_var)
-
- : // FIXASM: input regs, e.g.: "c" (count), "S" (src), "D" (dest)
-
- : "%ebx", "%edx", "%edi", "%esi" // CHECKASM: clobber list
- );
-#endif /* 0 - NEVER REACHED */
- }
- break;
-
- } // end switch (bpp)
-
- __asm__ __volatile__ (
- // MMX acceleration complete; now do clean-up
- // check if any remaining bytes left to decode
-#ifdef __PIC__
-#ifdef __x86_64__
- "pushq %%rbx \n\t" // save index to Global Offset Table
-#else
- "pushl %%ebx \n\t" // save index to Global Offset Table
-#endif
-#endif
- "movl _MMXLength, %%ebx \n\t" // ebx: x == offset bytes after MMX
-//pre "movl row, %%edi \n\t" // edi: Avg(x)
- "cmpl _FullLength, %%ebx \n\t" // test if offset at end of array
- "jnb avg_end \n\t"
-
- // do Avg decode for remaining bytes
-//pre "movl prev_row, %%esi \n\t" // esi: Prior(x)
- "movl %%edi, %%edx \n\t"
-//pre "subl bpp, %%edx \n\t" // (bpp is preloaded into ecx)
- "subl %%ecx, %%edx \n\t" // edx: Raw(x-bpp)
- "xorl %%ecx, %%ecx \n\t" // zero ecx before using cl & cx below
-
- "avg_lp2: \n\t"
- // Raw(x) = Avg(x) + ((Raw(x-bpp) + Prior(x))/2)
- "xorl %%eax, %%eax \n\t"
- "movb (%%esi,%%ebx,), %%cl \n\t" // load cl with Prior(x)
- "movb (%%edx,%%ebx,), %%al \n\t" // load al with Raw(x-bpp)
- "addw %%cx, %%ax \n\t"
- "incl %%ebx \n\t"
- "shrw %%ax \n\t" // divide by 2
- "addb -1(%%edi,%%ebx,), %%al \n\t" // add Avg(x); -1 to offset inc ebx
- "cmpl _FullLength, %%ebx \n\t" // check if at end of array
- "movb %%al, -1(%%edi,%%ebx,) \n\t" // write back Raw(x) [mov does not
- "jb avg_lp2 \n\t" // affect flags; -1 to offset inc ebx]
-
- "avg_end: \n\t"
- "EMMS \n\t" // end MMX; prep for poss. FP instrs.
-#ifdef __PIC__
-#ifdef __x86_64__
- "popq %%rbx \n\t" // restore index to Global Offset Table
-#else
- "popl %%ebx \n\t" // restore index to Global Offset Table
-#endif
-#endif
-
- : "=c" (dummy_value_c), // output regs (dummy)
- "=S" (dummy_value_S),
- "=D" (dummy_value_D)
-
- : "0" (bpp), // ecx // input regs
- "1" (prev_row), // esi
- "2" (row) // edi
-
- : "%eax", "%edx" // clobber list
-#ifndef __PIC__
- , "%ebx"
-#endif
- );
-
-} /* end png_read_filter_row_mmx_avg() */
-#endif
-
-
-
-#ifdef PNG_THREAD_UNSAFE_OK
-//===========================================================================//
-// //
-// P N G _ R E A D _ F I L T E R _ R O W _ M M X _ P A E T H //
-// //
-//===========================================================================//
-
-// Optimized code for PNG Paeth filter decoder
-
-static void /* PRIVATE */
-png_read_filter_row_mmx_paeth(png_row_infop row_info, png_bytep row,
- png_bytep prev_row)
-{
- int bpp;
- int dummy_value_c; // fix 'forbidden register 2 (cx) was spilled' error
- int dummy_value_S;
- int dummy_value_D;
-
- bpp = (row_info->pixel_depth + 7) >> 3; // Get # bytes per pixel
- _FullLength = row_info->rowbytes; // # of bytes to filter
-
- __asm__ __volatile__ (
-#ifdef __PIC__
-#ifdef __x86_64__
- "pushq %%rbx \n\t" // save index to Global Offset Table
-#else
- "pushl %%ebx \n\t" // save index to Global Offset Table
-#endif
-#endif
- "xorl %%ebx, %%ebx \n\t" // ebx: x offset
-//pre "movl row, %%edi \n\t"
- "xorl %%edx, %%edx \n\t" // edx: x-bpp offset
-//pre "movl prev_row, %%esi \n\t"
- "xorl %%eax, %%eax \n\t"
-
- // Compute the Raw value for the first bpp bytes
- // Note: the formula works out to be always
- // Paeth(x) = Raw(x) + Prior(x) where x < bpp
- "paeth_rlp: \n\t"
- "movb (%%edi,%%ebx,), %%al \n\t"
- "addb (%%esi,%%ebx,), %%al \n\t"
- "incl %%ebx \n\t"
-//pre "cmpl bpp, %%ebx \n\t" (bpp is preloaded into ecx)
- "cmpl %%ecx, %%ebx \n\t"
- "movb %%al, -1(%%edi,%%ebx,) \n\t"
- "jb paeth_rlp \n\t"
- // get # of bytes to alignment
- "movl %%edi, _dif \n\t" // take start of row
- "addl %%ebx, _dif \n\t" // add bpp
- "xorl %%ecx, %%ecx \n\t"
- "addl $0xf, _dif \n\t" // add 7 + 8 to incr past alignment
- // boundary
- "andl $0xfffffff8, _dif \n\t" // mask to alignment boundary
- "subl %%edi, _dif \n\t" // subtract from start ==> value ebx
- // at alignment
- "jz paeth_go \n\t"
- // fix alignment
-
- "paeth_lp1: \n\t"
- "xorl %%eax, %%eax \n\t"
- // pav = p - a = (a + b - c) - a = b - c
- "movb (%%esi,%%ebx,), %%al \n\t" // load Prior(x) into al
- "movb (%%esi,%%edx,), %%cl \n\t" // load Prior(x-bpp) into cl
- "subl %%ecx, %%eax \n\t" // subtract Prior(x-bpp)
- "movl %%eax, _patemp \n\t" // Save pav for later use
- "xorl %%eax, %%eax \n\t"
- // pbv = p - b = (a + b - c) - b = a - c
- "movb (%%edi,%%edx,), %%al \n\t" // load Raw(x-bpp) into al
- "subl %%ecx, %%eax \n\t" // subtract Prior(x-bpp)
- "movl %%eax, %%ecx \n\t"
- // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
- "addl _patemp, %%eax \n\t" // pcv = pav + pbv
- // pc = abs(pcv)
- "testl $0x80000000, %%eax \n\t"
- "jz paeth_pca \n\t"
- "negl %%eax \n\t" // reverse sign of neg values
-
- "paeth_pca: \n\t"
- "movl %%eax, _pctemp \n\t" // save pc for later use
- // pb = abs(pbv)
- "testl $0x80000000, %%ecx \n\t"
- "jz paeth_pba \n\t"
- "negl %%ecx \n\t" // reverse sign of neg values
-
- "paeth_pba: \n\t"
- "movl %%ecx, _pbtemp \n\t" // save pb for later use
- // pa = abs(pav)
- "movl _patemp, %%eax \n\t"
- "testl $0x80000000, %%eax \n\t"
- "jz paeth_paa \n\t"
- "negl %%eax \n\t" // reverse sign of neg values
-
- "paeth_paa: \n\t"
- "movl %%eax, _patemp \n\t" // save pa for later use
- // test if pa <= pb
- "cmpl %%ecx, %%eax \n\t"
- "jna paeth_abb \n\t"
- // pa > pb; now test if pb <= pc
- "cmpl _pctemp, %%ecx \n\t"
- "jna paeth_bbc \n\t"
- // pb > pc; Raw(x) = Paeth(x) + Prior(x-bpp)
- "movb (%%esi,%%edx,), %%cl \n\t" // load Prior(x-bpp) into cl
- "jmp paeth_paeth \n\t"
-
- "paeth_bbc: \n\t"
- // pb <= pc; Raw(x) = Paeth(x) + Prior(x)
- "movb (%%esi,%%ebx,), %%cl \n\t" // load Prior(x) into cl
- "jmp paeth_paeth \n\t"
-
- "paeth_abb: \n\t"
- // pa <= pb; now test if pa <= pc
- "cmpl _pctemp, %%eax \n\t"
- "jna paeth_abc \n\t"
- // pa > pc; Raw(x) = Paeth(x) + Prior(x-bpp)
- "movb (%%esi,%%edx,), %%cl \n\t" // load Prior(x-bpp) into cl
- "jmp paeth_paeth \n\t"
-
- "paeth_abc: \n\t"
- // pa <= pc; Raw(x) = Paeth(x) + Raw(x-bpp)
- "movb (%%edi,%%edx,), %%cl \n\t" // load Raw(x-bpp) into cl
-
- "paeth_paeth: \n\t"
- "incl %%ebx \n\t"
- "incl %%edx \n\t"
- // Raw(x) = (Paeth(x) + Paeth_Predictor( a, b, c )) mod 256
- "addb %%cl, -1(%%edi,%%ebx,) \n\t"
- "cmpl _dif, %%ebx \n\t"
- "jb paeth_lp1 \n\t"
-
- "paeth_go: \n\t"
- "movl _FullLength, %%ecx \n\t"
- "movl %%ecx, %%eax \n\t"
- "subl %%ebx, %%eax \n\t" // subtract alignment fix
- "andl $0x00000007, %%eax \n\t" // calc bytes over mult of 8
- "subl %%eax, %%ecx \n\t" // drop over bytes from original length
- "movl %%ecx, _MMXLength \n\t"
-#ifdef __PIC__
-#ifdef __x86_64__
- "popq %%rbx \n\t" // restore index to Global Offset Table
-#else
- "popl %%ebx \n\t" // restore index to Global Offset Table
-#endif
-#endif
-
- : "=c" (dummy_value_c), // output regs (dummy)
- "=S" (dummy_value_S),
- "=D" (dummy_value_D)
-
- : "0" (bpp), // ecx // input regs
- "1" (prev_row), // esi
- "2" (row) // edi
-
- : "%eax", "%edx" // clobber list
-#ifndef __PIC__
- , "%ebx"
-#endif
- );
-
- // now do the math for the rest of the row
- switch (bpp)
- {
- case 3:
- {
- _ActiveMask.use = 0x0000000000ffffffLL;
- _ActiveMaskEnd.use = 0xffff000000000000LL;
- _ShiftBpp.use = 24; // == bpp(3) * 8
- _ShiftRem.use = 40; // == 64 - 24
-
- __asm__ __volatile__ (
- "movl _dif, %%ecx \n\t"
-// preload "movl row, %%edi \n\t"
-// preload "movl prev_row, %%esi \n\t"
- "pxor %%mm0, %%mm0 \n\t"
- // prime the pump: load the first Raw(x-bpp) data set
- "movq -8(%%edi,%%ecx,), %%mm1 \n\t"
- "paeth_3lp: \n\t"
- "psrlq _ShiftRem, %%mm1 \n\t" // shift last 3 bytes to 1st
- // 3 bytes
- "movq (%%esi,%%ecx,), %%mm2 \n\t" // load b=Prior(x)
- "punpcklbw %%mm0, %%mm1 \n\t" // unpack High bytes of a
- "movq -8(%%esi,%%ecx,), %%mm3 \n\t" // prep c=Prior(x-bpp) bytes
- "punpcklbw %%mm0, %%mm2 \n\t" // unpack High bytes of b
- "psrlq _ShiftRem, %%mm3 \n\t" // shift last 3 bytes to 1st
- // 3 bytes
- // pav = p - a = (a + b - c) - a = b - c
- "movq %%mm2, %%mm4 \n\t"
- "punpcklbw %%mm0, %%mm3 \n\t" // unpack High bytes of c
- // pbv = p - b = (a + b - c) - b = a - c
- "movq %%mm1, %%mm5 \n\t"
- "psubw %%mm3, %%mm4 \n\t"
- "pxor %%mm7, %%mm7 \n\t"
- // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
- "movq %%mm4, %%mm6 \n\t"
- "psubw %%mm3, %%mm5 \n\t"
-
- // pa = abs(p-a) = abs(pav)
- // pb = abs(p-b) = abs(pbv)
- // pc = abs(p-c) = abs(pcv)
- "pcmpgtw %%mm4, %%mm0 \n\t" // create mask pav bytes < 0
- "paddw %%mm5, %%mm6 \n\t"
- "pand %%mm4, %%mm0 \n\t" // only pav bytes < 0 in mm7
- "pcmpgtw %%mm5, %%mm7 \n\t" // create mask pbv bytes < 0
- "psubw %%mm0, %%mm4 \n\t"
- "pand %%mm5, %%mm7 \n\t" // only pbv bytes < 0 in mm0
- "psubw %%mm0, %%mm4 \n\t"
- "psubw %%mm7, %%mm5 \n\t"
- "pxor %%mm0, %%mm0 \n\t"
- "pcmpgtw %%mm6, %%mm0 \n\t" // create mask pcv bytes < 0
- "pand %%mm6, %%mm0 \n\t" // only pav bytes < 0 in mm7
- "psubw %%mm7, %%mm5 \n\t"
- "psubw %%mm0, %%mm6 \n\t"
- // test pa <= pb
- "movq %%mm4, %%mm7 \n\t"
- "psubw %%mm0, %%mm6 \n\t"
- "pcmpgtw %%mm5, %%mm7 \n\t" // pa > pb?
- "movq %%mm7, %%mm0 \n\t"
- // use mm7 mask to merge pa & pb
- "pand %%mm7, %%mm5 \n\t"
- // use mm0 mask copy to merge a & b
- "pand %%mm0, %%mm2 \n\t"
- "pandn %%mm4, %%mm7 \n\t"
- "pandn %%mm1, %%mm0 \n\t"
- "paddw %%mm5, %%mm7 \n\t"
- "paddw %%mm2, %%mm0 \n\t"
- // test ((pa <= pb)? pa:pb) <= pc
- "pcmpgtw %%mm6, %%mm7 \n\t" // pab > pc?
- "pxor %%mm1, %%mm1 \n\t"
- "pand %%mm7, %%mm3 \n\t"
- "pandn %%mm0, %%mm7 \n\t"
- "paddw %%mm3, %%mm7 \n\t"
- "pxor %%mm0, %%mm0 \n\t"
- "packuswb %%mm1, %%mm7 \n\t"
- "movq (%%esi,%%ecx,), %%mm3 \n\t" // load c=Prior(x-bpp)
- "pand _ActiveMask, %%mm7 \n\t"
- "movq %%mm3, %%mm2 \n\t" // load b=Prior(x) step 1
- "paddb (%%edi,%%ecx,), %%mm7 \n\t" // add Paeth predictor with Raw(x)
- "punpcklbw %%mm0, %%mm3 \n\t" // unpack High bytes of c
- "movq %%mm7, (%%edi,%%ecx,) \n\t" // write back updated value
- "movq %%mm7, %%mm1 \n\t" // now mm1 will be used as
- // Raw(x-bpp)
- // now do Paeth for 2nd set of bytes (3-5)
- "psrlq _ShiftBpp, %%mm2 \n\t" // load b=Prior(x) step 2
- "punpcklbw %%mm0, %%mm1 \n\t" // unpack High bytes of a
- "pxor %%mm7, %%mm7 \n\t"
- "punpcklbw %%mm0, %%mm2 \n\t" // unpack High bytes of b
- // pbv = p - b = (a + b - c) - b = a - c
- "movq %%mm1, %%mm5 \n\t"
- // pav = p - a = (a + b - c) - a = b - c
- "movq %%mm2, %%mm4 \n\t"
- "psubw %%mm3, %%mm5 \n\t"
- "psubw %%mm3, %%mm4 \n\t"
- // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) =
- // pav + pbv = pbv + pav
- "movq %%mm5, %%mm6 \n\t"
- "paddw %%mm4, %%mm6 \n\t"
-
- // pa = abs(p-a) = abs(pav)
- // pb = abs(p-b) = abs(pbv)
- // pc = abs(p-c) = abs(pcv)
- "pcmpgtw %%mm5, %%mm0 \n\t" // create mask pbv bytes < 0
- "pcmpgtw %%mm4, %%mm7 \n\t" // create mask pav bytes < 0
- "pand %%mm5, %%mm0 \n\t" // only pbv bytes < 0 in mm0
- "pand %%mm4, %%mm7 \n\t" // only pav bytes < 0 in mm7
- "psubw %%mm0, %%mm5 \n\t"
- "psubw %%mm7, %%mm4 \n\t"
- "psubw %%mm0, %%mm5 \n\t"
- "psubw %%mm7, %%mm4 \n\t"
- "pxor %%mm0, %%mm0 \n\t"
- "pcmpgtw %%mm6, %%mm0 \n\t" // create mask pcv bytes < 0
- "pand %%mm6, %%mm0 \n\t" // only pav bytes < 0 in mm7
- "psubw %%mm0, %%mm6 \n\t"
- // test pa <= pb
- "movq %%mm4, %%mm7 \n\t"
- "psubw %%mm0, %%mm6 \n\t"
- "pcmpgtw %%mm5, %%mm7 \n\t" // pa > pb?
- "movq %%mm7, %%mm0 \n\t"
- // use mm7 mask to merge pa & pb
- "pand %%mm7, %%mm5 \n\t"
- // use mm0 mask copy to merge a & b
- "pand %%mm0, %%mm2 \n\t"
- "pandn %%mm4, %%mm7 \n\t"
- "pandn %%mm1, %%mm0 \n\t"
- "paddw %%mm5, %%mm7 \n\t"
- "paddw %%mm2, %%mm0 \n\t"
- // test ((pa <= pb)? pa:pb) <= pc
- "pcmpgtw %%mm6, %%mm7 \n\t" // pab > pc?
- "movq (%%esi,%%ecx,), %%mm2 \n\t" // load b=Prior(x)
- "pand %%mm7, %%mm3 \n\t"
- "pandn %%mm0, %%mm7 \n\t"
- "pxor %%mm1, %%mm1 \n\t"
- "paddw %%mm3, %%mm7 \n\t"
- "pxor %%mm0, %%mm0 \n\t"
- "packuswb %%mm1, %%mm7 \n\t"
- "movq %%mm2, %%mm3 \n\t" // load c=Prior(x-bpp) step 1
- "pand _ActiveMask, %%mm7 \n\t"
- "punpckhbw %%mm0, %%mm2 \n\t" // unpack High bytes of b
- "psllq _ShiftBpp, %%mm7 \n\t" // shift bytes to 2nd group of
- // 3 bytes
- // pav = p - a = (a + b - c) - a = b - c
- "movq %%mm2, %%mm4 \n\t"
- "paddb (%%edi,%%ecx,), %%mm7 \n\t" // add Paeth predictor with Raw(x)
- "psllq _ShiftBpp, %%mm3 \n\t" // load c=Prior(x-bpp) step 2
- "movq %%mm7, (%%edi,%%ecx,) \n\t" // write back updated value
- "movq %%mm7, %%mm1 \n\t"
- "punpckhbw %%mm0, %%mm3 \n\t" // unpack High bytes of c
- "psllq _ShiftBpp, %%mm1 \n\t" // shift bytes
- // now mm1 will be used as Raw(x-bpp)
- // now do Paeth for 3rd, and final, set of bytes (6-7)
- "pxor %%mm7, %%mm7 \n\t"
- "punpckhbw %%mm0, %%mm1 \n\t" // unpack High bytes of a
- "psubw %%mm3, %%mm4 \n\t"
- // pbv = p - b = (a + b - c) - b = a - c
- "movq %%mm1, %%mm5 \n\t"
- // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
- "movq %%mm4, %%mm6 \n\t"
- "psubw %%mm3, %%mm5 \n\t"
- "pxor %%mm0, %%mm0 \n\t"
- "paddw %%mm5, %%mm6 \n\t"
-
- // pa = abs(p-a) = abs(pav)
- // pb = abs(p-b) = abs(pbv)
- // pc = abs(p-c) = abs(pcv)
- "pcmpgtw %%mm4, %%mm0 \n\t" // create mask pav bytes < 0
- "pcmpgtw %%mm5, %%mm7 \n\t" // create mask pbv bytes < 0
- "pand %%mm4, %%mm0 \n\t" // only pav bytes < 0 in mm7
- "pand %%mm5, %%mm7 \n\t" // only pbv bytes < 0 in mm0
- "psubw %%mm0, %%mm4 \n\t"
- "psubw %%mm7, %%mm5 \n\t"
- "psubw %%mm0, %%mm4 \n\t"
- "psubw %%mm7, %%mm5 \n\t"
- "pxor %%mm0, %%mm0 \n\t"
- "pcmpgtw %%mm6, %%mm0 \n\t" // create mask pcv bytes < 0
- "pand %%mm6, %%mm0 \n\t" // only pav bytes < 0 in mm7
- "psubw %%mm0, %%mm6 \n\t"
- // test pa <= pb
- "movq %%mm4, %%mm7 \n\t"
- "psubw %%mm0, %%mm6 \n\t"
- "pcmpgtw %%mm5, %%mm7 \n\t" // pa > pb?
- "movq %%mm7, %%mm0 \n\t"
- // use mm0 mask copy to merge a & b
- "pand %%mm0, %%mm2 \n\t"
- // use mm7 mask to merge pa & pb
- "pand %%mm7, %%mm5 \n\t"
- "pandn %%mm1, %%mm0 \n\t"
- "pandn %%mm4, %%mm7 \n\t"
- "paddw %%mm2, %%mm0 \n\t"
- "paddw %%mm5, %%mm7 \n\t"
- // test ((pa <= pb)? pa:pb) <= pc
- "pcmpgtw %%mm6, %%mm7 \n\t" // pab > pc?
- "pand %%mm7, %%mm3 \n\t"
- "pandn %%mm0, %%mm7 \n\t"
- "paddw %%mm3, %%mm7 \n\t"
- "pxor %%mm1, %%mm1 \n\t"
- "packuswb %%mm7, %%mm1 \n\t"
- // step ecx to next set of 8 bytes and repeat loop til done
- "addl $8, %%ecx \n\t"
- "pand _ActiveMaskEnd, %%mm1 \n\t"
- "paddb -8(%%edi,%%ecx,), %%mm1 \n\t" // add Paeth predictor with
- // Raw(x)
-
- "cmpl _MMXLength, %%ecx \n\t"
- "pxor %%mm0, %%mm0 \n\t" // pxor does not affect flags
- "movq %%mm1, -8(%%edi,%%ecx,) \n\t" // write back updated value
- // mm1 will be used as Raw(x-bpp) next loop
- // mm3 ready to be used as Prior(x-bpp) next loop
- "jb paeth_3lp \n\t"
-
- : "=S" (dummy_value_S), // output regs (dummy)
- "=D" (dummy_value_D)
-
- : "0" (prev_row), // esi // input regs
- "1" (row) // edi
-
- : "%ecx" // clobber list
-#if 0 /* %mm0, ..., %mm7 not supported by gcc 2.7.2.3 or egcs 1.1 */
- , "%mm0", "%mm1", "%mm2", "%mm3"
- , "%mm4", "%mm5", "%mm6", "%mm7"
-#endif
- );
- }
- break; // end 3 bpp
-
- case 6:
- //case 7: // GRR BOGUS
- //case 5: // GRR BOGUS
- {
- _ActiveMask.use = 0x00000000ffffffffLL;
- _ActiveMask2.use = 0xffffffff00000000LL;
- _ShiftBpp.use = bpp << 3; // == bpp * 8
- _ShiftRem.use = 64 - _ShiftBpp.use;
-
- __asm__ __volatile__ (
- "movl _dif, %%ecx \n\t"
-// preload "movl row, %%edi \n\t"
-// preload "movl prev_row, %%esi \n\t"
- // prime the pump: load the first Raw(x-bpp) data set
- "movq -8(%%edi,%%ecx,), %%mm1 \n\t"
- "pxor %%mm0, %%mm0 \n\t"
-
- "paeth_6lp: \n\t"
- // must shift to position Raw(x-bpp) data
- "psrlq _ShiftRem, %%mm1 \n\t"
- // do first set of 4 bytes
- "movq -8(%%esi,%%ecx,), %%mm3 \n\t" // read c=Prior(x-bpp) bytes
- "punpcklbw %%mm0, %%mm1 \n\t" // unpack Low bytes of a
- "movq (%%esi,%%ecx,), %%mm2 \n\t" // load b=Prior(x)
- "punpcklbw %%mm0, %%mm2 \n\t" // unpack Low bytes of b
- // must shift to position Prior(x-bpp) data
- "psrlq _ShiftRem, %%mm3 \n\t"
- // pav = p - a = (a + b - c) - a = b - c
- "movq %%mm2, %%mm4 \n\t"
- "punpcklbw %%mm0, %%mm3 \n\t" // unpack Low bytes of c
- // pbv = p - b = (a + b - c) - b = a - c
- "movq %%mm1, %%mm5 \n\t"
- "psubw %%mm3, %%mm4 \n\t"
- "pxor %%mm7, %%mm7 \n\t"
- // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
- "movq %%mm4, %%mm6 \n\t"
- "psubw %%mm3, %%mm5 \n\t"
- // pa = abs(p-a) = abs(pav)
- // pb = abs(p-b) = abs(pbv)
- // pc = abs(p-c) = abs(pcv)
- "pcmpgtw %%mm4, %%mm0 \n\t" // create mask pav bytes < 0
- "paddw %%mm5, %%mm6 \n\t"
- "pand %%mm4, %%mm0 \n\t" // only pav bytes < 0 in mm7
- "pcmpgtw %%mm5, %%mm7 \n\t" // create mask pbv bytes < 0
- "psubw %%mm0, %%mm4 \n\t"
- "pand %%mm5, %%mm7 \n\t" // only pbv bytes < 0 in mm0
- "psubw %%mm0, %%mm4 \n\t"
- "psubw %%mm7, %%mm5 \n\t"
- "pxor %%mm0, %%mm0 \n\t"
- "pcmpgtw %%mm6, %%mm0 \n\t" // create mask pcv bytes < 0
- "pand %%mm6, %%mm0 \n\t" // only pav bytes < 0 in mm7
- "psubw %%mm7, %%mm5 \n\t"
- "psubw %%mm0, %%mm6 \n\t"
- // test pa <= pb
- "movq %%mm4, %%mm7 \n\t"
- "psubw %%mm0, %%mm6 \n\t"
- "pcmpgtw %%mm5, %%mm7 \n\t" // pa > pb?
- "movq %%mm7, %%mm0 \n\t"
- // use mm7 mask to merge pa & pb
- "pand %%mm7, %%mm5 \n\t"
- // use mm0 mask copy to merge a & b
- "pand %%mm0, %%mm2 \n\t"
- "pandn %%mm4, %%mm7 \n\t"
- "pandn %%mm1, %%mm0 \n\t"
- "paddw %%mm5, %%mm7 \n\t"
- "paddw %%mm2, %%mm0 \n\t"
- // test ((pa <= pb)? pa:pb) <= pc
- "pcmpgtw %%mm6, %%mm7 \n\t" // pab > pc?
- "pxor %%mm1, %%mm1 \n\t"
- "pand %%mm7, %%mm3 \n\t"
- "pandn %%mm0, %%mm7 \n\t"
- "paddw %%mm3, %%mm7 \n\t"
- "pxor %%mm0, %%mm0 \n\t"
- "packuswb %%mm1, %%mm7 \n\t"
- "movq -8(%%esi,%%ecx,), %%mm3 \n\t" // load c=Prior(x-bpp)
- "pand _ActiveMask, %%mm7 \n\t"
- "psrlq _ShiftRem, %%mm3 \n\t"
- "movq (%%esi,%%ecx,), %%mm2 \n\t" // load b=Prior(x) step 1
- "paddb (%%edi,%%ecx,), %%mm7 \n\t" // add Paeth predictor and Raw(x)
- "movq %%mm2, %%mm6 \n\t"
- "movq %%mm7, (%%edi,%%ecx,) \n\t" // write back updated value
- "movq -8(%%edi,%%ecx,), %%mm1 \n\t"
- "psllq _ShiftBpp, %%mm6 \n\t"
- "movq %%mm7, %%mm5 \n\t"
- "psrlq _ShiftRem, %%mm1 \n\t"
- "por %%mm6, %%mm3 \n\t"
- "psllq _ShiftBpp, %%mm5 \n\t"
- "punpckhbw %%mm0, %%mm3 \n\t" // unpack High bytes of c
- "por %%mm5, %%mm1 \n\t"
- // do second set of 4 bytes
- "punpckhbw %%mm0, %%mm2 \n\t" // unpack High bytes of b
- "punpckhbw %%mm0, %%mm1 \n\t" // unpack High bytes of a
- // pav = p - a = (a + b - c) - a = b - c
- "movq %%mm2, %%mm4 \n\t"
- // pbv = p - b = (a + b - c) - b = a - c
- "movq %%mm1, %%mm5 \n\t"
- "psubw %%mm3, %%mm4 \n\t"
- "pxor %%mm7, %%mm7 \n\t"
- // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
- "movq %%mm4, %%mm6 \n\t"
- "psubw %%mm3, %%mm5 \n\t"
- // pa = abs(p-a) = abs(pav)
- // pb = abs(p-b) = abs(pbv)
- // pc = abs(p-c) = abs(pcv)
- "pcmpgtw %%mm4, %%mm0 \n\t" // create mask pav bytes < 0
- "paddw %%mm5, %%mm6 \n\t"
- "pand %%mm4, %%mm0 \n\t" // only pav bytes < 0 in mm7
- "pcmpgtw %%mm5, %%mm7 \n\t" // create mask pbv bytes < 0
- "psubw %%mm0, %%mm4 \n\t"
- "pand %%mm5, %%mm7 \n\t" // only pbv bytes < 0 in mm0
- "psubw %%mm0, %%mm4 \n\t"
- "psubw %%mm7, %%mm5 \n\t"
- "pxor %%mm0, %%mm0 \n\t"
- "pcmpgtw %%mm6, %%mm0 \n\t" // create mask pcv bytes < 0
- "pand %%mm6, %%mm0 \n\t" // only pav bytes < 0 in mm7
- "psubw %%mm7, %%mm5 \n\t"
- "psubw %%mm0, %%mm6 \n\t"
- // test pa <= pb
- "movq %%mm4, %%mm7 \n\t"
- "psubw %%mm0, %%mm6 \n\t"
- "pcmpgtw %%mm5, %%mm7 \n\t" // pa > pb?
- "movq %%mm7, %%mm0 \n\t"
- // use mm7 mask to merge pa & pb
- "pand %%mm7, %%mm5 \n\t"
- // use mm0 mask copy to merge a & b
- "pand %%mm0, %%mm2 \n\t"
- "pandn %%mm4, %%mm7 \n\t"
- "pandn %%mm1, %%mm0 \n\t"
- "paddw %%mm5, %%mm7 \n\t"
- "paddw %%mm2, %%mm0 \n\t"
- // test ((pa <= pb)? pa:pb) <= pc
- "pcmpgtw %%mm6, %%mm7 \n\t" // pab > pc?
- "pxor %%mm1, %%mm1 \n\t"
- "pand %%mm7, %%mm3 \n\t"
- "pandn %%mm0, %%mm7 \n\t"
- "pxor %%mm1, %%mm1 \n\t"
- "paddw %%mm3, %%mm7 \n\t"
- "pxor %%mm0, %%mm0 \n\t"
- // step ecx to next set of 8 bytes and repeat loop til done
- "addl $8, %%ecx \n\t"
- "packuswb %%mm7, %%mm1 \n\t"
- "paddb -8(%%edi,%%ecx,), %%mm1 \n\t" // add Paeth predictor with Raw(x)
- "cmpl _MMXLength, %%ecx \n\t"
- "movq %%mm1, -8(%%edi,%%ecx,) \n\t" // write back updated value
- // mm1 will be used as Raw(x-bpp) next loop
- "jb paeth_6lp \n\t"
-
- : "=S" (dummy_value_S), // output regs (dummy)
- "=D" (dummy_value_D)
-
- : "0" (prev_row), // esi // input regs
- "1" (row) // edi
-
- : "%ecx" // clobber list
-#if 0 /* %mm0, ..., %mm7 not supported by gcc 2.7.2.3 or egcs 1.1 */
- , "%mm0", "%mm1", "%mm2", "%mm3"
- , "%mm4", "%mm5", "%mm6", "%mm7"
-#endif
- );
- }
- break; // end 6 bpp
-
- case 4:
- {
- _ActiveMask.use = 0x00000000ffffffffLL;
-
- __asm__ __volatile__ (
- "movl _dif, %%ecx \n\t"
-// preload "movl row, %%edi \n\t"
-// preload "movl prev_row, %%esi \n\t"
- "pxor %%mm0, %%mm0 \n\t"
- // prime the pump: load the first Raw(x-bpp) data set
- "movq -8(%%edi,%%ecx,), %%mm1 \n\t" // only time should need to read
- // a=Raw(x-bpp) bytes
- "paeth_4lp: \n\t"
- // do first set of 4 bytes
- "movq -8(%%esi,%%ecx,), %%mm3 \n\t" // read c=Prior(x-bpp) bytes
- "punpckhbw %%mm0, %%mm1 \n\t" // unpack Low bytes of a
- "movq (%%esi,%%ecx,), %%mm2 \n\t" // load b=Prior(x)
- "punpcklbw %%mm0, %%mm2 \n\t" // unpack High bytes of b
- // pav = p - a = (a + b - c) - a = b - c
- "movq %%mm2, %%mm4 \n\t"
- "punpckhbw %%mm0, %%mm3 \n\t" // unpack High bytes of c
- // pbv = p - b = (a + b - c) - b = a - c
- "movq %%mm1, %%mm5 \n\t"
- "psubw %%mm3, %%mm4 \n\t"
- "pxor %%mm7, %%mm7 \n\t"
- // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
- "movq %%mm4, %%mm6 \n\t"
- "psubw %%mm3, %%mm5 \n\t"
- // pa = abs(p-a) = abs(pav)
- // pb = abs(p-b) = abs(pbv)
- // pc = abs(p-c) = abs(pcv)
- "pcmpgtw %%mm4, %%mm0 \n\t" // create mask pav bytes < 0
- "paddw %%mm5, %%mm6 \n\t"
- "pand %%mm4, %%mm0 \n\t" // only pav bytes < 0 in mm7
- "pcmpgtw %%mm5, %%mm7 \n\t" // create mask pbv bytes < 0
- "psubw %%mm0, %%mm4 \n\t"
- "pand %%mm5, %%mm7 \n\t" // only pbv bytes < 0 in mm0
- "psubw %%mm0, %%mm4 \n\t"
- "psubw %%mm7, %%mm5 \n\t"
- "pxor %%mm0, %%mm0 \n\t"
- "pcmpgtw %%mm6, %%mm0 \n\t" // create mask pcv bytes < 0
- "pand %%mm6, %%mm0 \n\t" // only pav bytes < 0 in mm7
- "psubw %%mm7, %%mm5 \n\t"
- "psubw %%mm0, %%mm6 \n\t"
- // test pa <= pb
- "movq %%mm4, %%mm7 \n\t"
- "psubw %%mm0, %%mm6 \n\t"
- "pcmpgtw %%mm5, %%mm7 \n\t" // pa > pb?
- "movq %%mm7, %%mm0 \n\t"
- // use mm7 mask to merge pa & pb
- "pand %%mm7, %%mm5 \n\t"
- // use mm0 mask copy to merge a & b
- "pand %%mm0, %%mm2 \n\t"
- "pandn %%mm4, %%mm7 \n\t"
- "pandn %%mm1, %%mm0 \n\t"
- "paddw %%mm5, %%mm7 \n\t"
- "paddw %%mm2, %%mm0 \n\t"
- // test ((pa <= pb)? pa:pb) <= pc
- "pcmpgtw %%mm6, %%mm7 \n\t" // pab > pc?
- "pxor %%mm1, %%mm1 \n\t"
- "pand %%mm7, %%mm3 \n\t"
- "pandn %%mm0, %%mm7 \n\t"
- "paddw %%mm3, %%mm7 \n\t"
- "pxor %%mm0, %%mm0 \n\t"
- "packuswb %%mm1, %%mm7 \n\t"
- "movq (%%esi,%%ecx,), %%mm3 \n\t" // load c=Prior(x-bpp)
- "pand _ActiveMask, %%mm7 \n\t"
- "movq %%mm3, %%mm2 \n\t" // load b=Prior(x) step 1
- "paddb (%%edi,%%ecx,), %%mm7 \n\t" // add Paeth predictor with Raw(x)
- "punpcklbw %%mm0, %%mm3 \n\t" // unpack High bytes of c
- "movq %%mm7, (%%edi,%%ecx,) \n\t" // write back updated value
- "movq %%mm7, %%mm1 \n\t" // now mm1 will be used as Raw(x-bpp)
- // do second set of 4 bytes
- "punpckhbw %%mm0, %%mm2 \n\t" // unpack Low bytes of b
- "punpcklbw %%mm0, %%mm1 \n\t" // unpack Low bytes of a
- // pav = p - a = (a + b - c) - a = b - c
- "movq %%mm2, %%mm4 \n\t"
- // pbv = p - b = (a + b - c) - b = a - c
- "movq %%mm1, %%mm5 \n\t"
- "psubw %%mm3, %%mm4 \n\t"
- "pxor %%mm7, %%mm7 \n\t"
- // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
- "movq %%mm4, %%mm6 \n\t"
- "psubw %%mm3, %%mm5 \n\t"
- // pa = abs(p-a) = abs(pav)
- // pb = abs(p-b) = abs(pbv)
- // pc = abs(p-c) = abs(pcv)
- "pcmpgtw %%mm4, %%mm0 \n\t" // create mask pav bytes < 0
- "paddw %%mm5, %%mm6 \n\t"
- "pand %%mm4, %%mm0 \n\t" // only pav bytes < 0 in mm7
- "pcmpgtw %%mm5, %%mm7 \n\t" // create mask pbv bytes < 0
- "psubw %%mm0, %%mm4 \n\t"
- "pand %%mm5, %%mm7 \n\t" // only pbv bytes < 0 in mm0
- "psubw %%mm0, %%mm4 \n\t"
- "psubw %%mm7, %%mm5 \n\t"
- "pxor %%mm0, %%mm0 \n\t"
- "pcmpgtw %%mm6, %%mm0 \n\t" // create mask pcv bytes < 0
- "pand %%mm6, %%mm0 \n\t" // only pav bytes < 0 in mm7
- "psubw %%mm7, %%mm5 \n\t"
- "psubw %%mm0, %%mm6 \n\t"
- // test pa <= pb
- "movq %%mm4, %%mm7 \n\t"
- "psubw %%mm0, %%mm6 \n\t"
- "pcmpgtw %%mm5, %%mm7 \n\t" // pa > pb?
- "movq %%mm7, %%mm0 \n\t"
- // use mm7 mask to merge pa & pb
- "pand %%mm7, %%mm5 \n\t"
- // use mm0 mask copy to merge a & b
- "pand %%mm0, %%mm2 \n\t"
- "pandn %%mm4, %%mm7 \n\t"
- "pandn %%mm1, %%mm0 \n\t"
- "paddw %%mm5, %%mm7 \n\t"
- "paddw %%mm2, %%mm0 \n\t"
- // test ((pa <= pb)? pa:pb) <= pc
- "pcmpgtw %%mm6, %%mm7 \n\t" // pab > pc?
- "pxor %%mm1, %%mm1 \n\t"
- "pand %%mm7, %%mm3 \n\t"
- "pandn %%mm0, %%mm7 \n\t"
- "pxor %%mm1, %%mm1 \n\t"
- "paddw %%mm3, %%mm7 \n\t"
- "pxor %%mm0, %%mm0 \n\t"
- // step ecx to next set of 8 bytes and repeat loop til done
- "addl $8, %%ecx \n\t"
- "packuswb %%mm7, %%mm1 \n\t"
- "paddb -8(%%edi,%%ecx,), %%mm1 \n\t" // add predictor with Raw(x)
- "cmpl _MMXLength, %%ecx \n\t"
- "movq %%mm1, -8(%%edi,%%ecx,) \n\t" // write back updated value
- // mm1 will be used as Raw(x-bpp) next loop
- "jb paeth_4lp \n\t"
-
- : "=S" (dummy_value_S), // output regs (dummy)
- "=D" (dummy_value_D)
-
- : "0" (prev_row), // esi // input regs
- "1" (row) // edi
-
- : "%ecx" // clobber list
-#if 0 /* %mm0, ..., %mm7 not supported by gcc 2.7.2.3 or egcs 1.1 */
- , "%mm0", "%mm1", "%mm2", "%mm3"
- , "%mm4", "%mm5", "%mm6", "%mm7"
-#endif
- );
- }
- break; // end 4 bpp
-
- case 8: // bpp == 8
- {
- _ActiveMask.use = 0x00000000ffffffffLL;
-
- __asm__ __volatile__ (
- "movl _dif, %%ecx \n\t"
-// preload "movl row, %%edi \n\t"
-// preload "movl prev_row, %%esi \n\t"
- "pxor %%mm0, %%mm0 \n\t"
- // prime the pump: load the first Raw(x-bpp) data set
- "movq -8(%%edi,%%ecx,), %%mm1 \n\t" // only time should need to read
- // a=Raw(x-bpp) bytes
- "paeth_8lp: \n\t"
- // do first set of 4 bytes
- "movq -8(%%esi,%%ecx,), %%mm3 \n\t" // read c=Prior(x-bpp) bytes
- "punpcklbw %%mm0, %%mm1 \n\t" // unpack Low bytes of a
- "movq (%%esi,%%ecx,), %%mm2 \n\t" // load b=Prior(x)
- "punpcklbw %%mm0, %%mm2 \n\t" // unpack Low bytes of b
- // pav = p - a = (a + b - c) - a = b - c
- "movq %%mm2, %%mm4 \n\t"
- "punpcklbw %%mm0, %%mm3 \n\t" // unpack Low bytes of c
- // pbv = p - b = (a + b - c) - b = a - c
- "movq %%mm1, %%mm5 \n\t"
- "psubw %%mm3, %%mm4 \n\t"
- "pxor %%mm7, %%mm7 \n\t"
- // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
- "movq %%mm4, %%mm6 \n\t"
- "psubw %%mm3, %%mm5 \n\t"
- // pa = abs(p-a) = abs(pav)
- // pb = abs(p-b) = abs(pbv)
- // pc = abs(p-c) = abs(pcv)
- "pcmpgtw %%mm4, %%mm0 \n\t" // create mask pav bytes < 0
- "paddw %%mm5, %%mm6 \n\t"
- "pand %%mm4, %%mm0 \n\t" // only pav bytes < 0 in mm7
- "pcmpgtw %%mm5, %%mm7 \n\t" // create mask pbv bytes < 0
- "psubw %%mm0, %%mm4 \n\t"
- "pand %%mm5, %%mm7 \n\t" // only pbv bytes < 0 in mm0
- "psubw %%mm0, %%mm4 \n\t"
- "psubw %%mm7, %%mm5 \n\t"
- "pxor %%mm0, %%mm0 \n\t"
- "pcmpgtw %%mm6, %%mm0 \n\t" // create mask pcv bytes < 0
- "pand %%mm6, %%mm0 \n\t" // only pav bytes < 0 in mm7
- "psubw %%mm7, %%mm5 \n\t"
- "psubw %%mm0, %%mm6 \n\t"
- // test pa <= pb
- "movq %%mm4, %%mm7 \n\t"
- "psubw %%mm0, %%mm6 \n\t"
- "pcmpgtw %%mm5, %%mm7 \n\t" // pa > pb?
- "movq %%mm7, %%mm0 \n\t"
- // use mm7 mask to merge pa & pb
- "pand %%mm7, %%mm5 \n\t"
- // use mm0 mask copy to merge a & b
- "pand %%mm0, %%mm2 \n\t"
- "pandn %%mm4, %%mm7 \n\t"
- "pandn %%mm1, %%mm0 \n\t"
- "paddw %%mm5, %%mm7 \n\t"
- "paddw %%mm2, %%mm0 \n\t"
- // test ((pa <= pb)? pa:pb) <= pc
- "pcmpgtw %%mm6, %%mm7 \n\t" // pab > pc?
- "pxor %%mm1, %%mm1 \n\t"
- "pand %%mm7, %%mm3 \n\t"
- "pandn %%mm0, %%mm7 \n\t"
- "paddw %%mm3, %%mm7 \n\t"
- "pxor %%mm0, %%mm0 \n\t"
- "packuswb %%mm1, %%mm7 \n\t"
- "movq -8(%%esi,%%ecx,), %%mm3 \n\t" // read c=Prior(x-bpp) bytes
- "pand _ActiveMask, %%mm7 \n\t"
- "movq (%%esi,%%ecx,), %%mm2 \n\t" // load b=Prior(x)
- "paddb (%%edi,%%ecx,), %%mm7 \n\t" // add Paeth predictor with Raw(x)
- "punpckhbw %%mm0, %%mm3 \n\t" // unpack High bytes of c
- "movq %%mm7, (%%edi,%%ecx,) \n\t" // write back updated value
- "movq -8(%%edi,%%ecx,), %%mm1 \n\t" // read a=Raw(x-bpp) bytes
-
- // do second set of 4 bytes
- "punpckhbw %%mm0, %%mm2 \n\t" // unpack High bytes of b
- "punpckhbw %%mm0, %%mm1 \n\t" // unpack High bytes of a
- // pav = p - a = (a + b - c) - a = b - c
- "movq %%mm2, %%mm4 \n\t"
- // pbv = p - b = (a + b - c) - b = a - c
- "movq %%mm1, %%mm5 \n\t"
- "psubw %%mm3, %%mm4 \n\t"
- "pxor %%mm7, %%mm7 \n\t"
- // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
- "movq %%mm4, %%mm6 \n\t"
- "psubw %%mm3, %%mm5 \n\t"
- // pa = abs(p-a) = abs(pav)
- // pb = abs(p-b) = abs(pbv)
- // pc = abs(p-c) = abs(pcv)
- "pcmpgtw %%mm4, %%mm0 \n\t" // create mask pav bytes < 0
- "paddw %%mm5, %%mm6 \n\t"
- "pand %%mm4, %%mm0 \n\t" // only pav bytes < 0 in mm7
- "pcmpgtw %%mm5, %%mm7 \n\t" // create mask pbv bytes < 0
- "psubw %%mm0, %%mm4 \n\t"
- "pand %%mm5, %%mm7 \n\t" // only pbv bytes < 0 in mm0
- "psubw %%mm0, %%mm4 \n\t"
- "psubw %%mm7, %%mm5 \n\t"
- "pxor %%mm0, %%mm0 \n\t"
- "pcmpgtw %%mm6, %%mm0 \n\t" // create mask pcv bytes < 0
- "pand %%mm6, %%mm0 \n\t" // only pav bytes < 0 in mm7
- "psubw %%mm7, %%mm5 \n\t"
- "psubw %%mm0, %%mm6 \n\t"
- // test pa <= pb
- "movq %%mm4, %%mm7 \n\t"
- "psubw %%mm0, %%mm6 \n\t"
- "pcmpgtw %%mm5, %%mm7 \n\t" // pa > pb?
- "movq %%mm7, %%mm0 \n\t"
- // use mm7 mask to merge pa & pb
- "pand %%mm7, %%mm5 \n\t"
- // use mm0 mask copy to merge a & b
- "pand %%mm0, %%mm2 \n\t"
- "pandn %%mm4, %%mm7 \n\t"
- "pandn %%mm1, %%mm0 \n\t"
- "paddw %%mm5, %%mm7 \n\t"
- "paddw %%mm2, %%mm0 \n\t"
- // test ((pa <= pb)? pa:pb) <= pc
- "pcmpgtw %%mm6, %%mm7 \n\t" // pab > pc?
- "pxor %%mm1, %%mm1 \n\t"
- "pand %%mm7, %%mm3 \n\t"
- "pandn %%mm0, %%mm7 \n\t"
- "pxor %%mm1, %%mm1 \n\t"
- "paddw %%mm3, %%mm7 \n\t"
- "pxor %%mm0, %%mm0 \n\t"
- // step ecx to next set of 8 bytes and repeat loop til done
- "addl $8, %%ecx \n\t"
- "packuswb %%mm7, %%mm1 \n\t"
- "paddb -8(%%edi,%%ecx,), %%mm1 \n\t" // add Paeth predictor with Raw(x)
- "cmpl _MMXLength, %%ecx \n\t"
- "movq %%mm1, -8(%%edi,%%ecx,) \n\t" // write back updated value
- // mm1 will be used as Raw(x-bpp) next loop
- "jb paeth_8lp \n\t"
-
- : "=S" (dummy_value_S), // output regs (dummy)
- "=D" (dummy_value_D)
-
- : "0" (prev_row), // esi // input regs
- "1" (row) // edi
-
- : "%ecx" // clobber list
-#if 0 /* %mm0, ..., %mm7 not supported by gcc 2.7.2.3 or egcs 1.1 */
- , "%mm0", "%mm1", "%mm2", "%mm3"
- , "%mm4", "%mm5", "%mm6", "%mm7"
-#endif
- );
- }
- break; // end 8 bpp
-
- case 1: // bpp = 1
- case 2: // bpp = 2
- default: // bpp > 8
- {
- __asm__ __volatile__ (
-#ifdef __PIC__
-#ifdef __x86_64__
- "pushq %%rbx \n\t" // save Global Offset Table index
-#else
- "pushl %%ebx \n\t" // save Global Offset Table index
-#endif
-#endif
- "movl _dif, %%ebx \n\t"
- "cmpl _FullLength, %%ebx \n\t"
- "jnb paeth_dend \n\t"
-
-// preload "movl row, %%edi \n\t"
-// preload "movl prev_row, %%esi \n\t"
- // do Paeth decode for remaining bytes
- "movl %%ebx, %%edx \n\t"
-// preload "subl bpp, %%edx \n\t" // (bpp is preloaded into ecx)
- "subl %%ecx, %%edx \n\t" // edx = ebx - bpp
- "xorl %%ecx, %%ecx \n\t" // zero ecx before using cl & cx
-
- "paeth_dlp: \n\t"
- "xorl %%eax, %%eax \n\t"
- // pav = p - a = (a + b - c) - a = b - c
- "movb (%%esi,%%ebx,), %%al \n\t" // load Prior(x) into al
- "movb (%%esi,%%edx,), %%cl \n\t" // load Prior(x-bpp) into cl
- "subl %%ecx, %%eax \n\t" // subtract Prior(x-bpp)
- "movl %%eax, _patemp \n\t" // Save pav for later use
- "xorl %%eax, %%eax \n\t"
- // pbv = p - b = (a + b - c) - b = a - c
- "movb (%%edi,%%edx,), %%al \n\t" // load Raw(x-bpp) into al
- "subl %%ecx, %%eax \n\t" // subtract Prior(x-bpp)
- "movl %%eax, %%ecx \n\t"
- // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
- "addl _patemp, %%eax \n\t" // pcv = pav + pbv
- // pc = abs(pcv)
- "testl $0x80000000, %%eax \n\t"
- "jz paeth_dpca \n\t"
- "negl %%eax \n\t" // reverse sign of neg values
-
- "paeth_dpca: \n\t"
- "movl %%eax, _pctemp \n\t" // save pc for later use
- // pb = abs(pbv)
- "testl $0x80000000, %%ecx \n\t"
- "jz paeth_dpba \n\t"
- "negl %%ecx \n\t" // reverse sign of neg values
-
- "paeth_dpba: \n\t"
- "movl %%ecx, _pbtemp \n\t" // save pb for later use
- // pa = abs(pav)
- "movl _patemp, %%eax \n\t"
- "testl $0x80000000, %%eax \n\t"
- "jz paeth_dpaa \n\t"
- "negl %%eax \n\t" // reverse sign of neg values
-
- "paeth_dpaa: \n\t"
- "movl %%eax, _patemp \n\t" // save pa for later use
- // test if pa <= pb
- "cmpl %%ecx, %%eax \n\t"
- "jna paeth_dabb \n\t"
- // pa > pb; now test if pb <= pc
- "cmpl _pctemp, %%ecx \n\t"
- "jna paeth_dbbc \n\t"
- // pb > pc; Raw(x) = Paeth(x) + Prior(x-bpp)
- "movb (%%esi,%%edx,), %%cl \n\t" // load Prior(x-bpp) into cl
- "jmp paeth_dpaeth \n\t"
-
- "paeth_dbbc: \n\t"
- // pb <= pc; Raw(x) = Paeth(x) + Prior(x)
- "movb (%%esi,%%ebx,), %%cl \n\t" // load Prior(x) into cl
- "jmp paeth_dpaeth \n\t"
-
- "paeth_dabb: \n\t"
- // pa <= pb; now test if pa <= pc
- "cmpl _pctemp, %%eax \n\t"
- "jna paeth_dabc \n\t"
- // pa > pc; Raw(x) = Paeth(x) + Prior(x-bpp)
- "movb (%%esi,%%edx,), %%cl \n\t" // load Prior(x-bpp) into cl
- "jmp paeth_dpaeth \n\t"
-
- "paeth_dabc: \n\t"
- // pa <= pc; Raw(x) = Paeth(x) + Raw(x-bpp)
- "movb (%%edi,%%edx,), %%cl \n\t" // load Raw(x-bpp) into cl
-
- "paeth_dpaeth: \n\t"
- "incl %%ebx \n\t"
- "incl %%edx \n\t"
- // Raw(x) = (Paeth(x) + Paeth_Predictor( a, b, c )) mod 256
- "addb %%cl, -1(%%edi,%%ebx,) \n\t"
- "cmpl _FullLength, %%ebx \n\t"
- "jb paeth_dlp \n\t"
-
- "paeth_dend: \n\t"
-#ifdef __PIC__
-#ifdef __x86_64__
- "popq %%rbx \n\t" // index to Global Offset Table
-#else
- "popl %%ebx \n\t" // index to Global Offset Table
-#endif
-#endif
-
- : "=c" (dummy_value_c), // output regs (dummy)
- "=S" (dummy_value_S),
- "=D" (dummy_value_D)
-
- : "0" (bpp), // ecx // input regs
- "1" (prev_row), // esi
- "2" (row) // edi
-
- : "%eax", "%edx" // clobber list
-#ifndef __PIC__
- , "%ebx"
-#endif
- );
- }
- return; // No need to go further with this one
-
- } // end switch (bpp)
-
- __asm__ __volatile__ (
- // MMX acceleration complete; now do clean-up
- // check if any remaining bytes left to decode
-#ifdef __PIC__
-#ifdef __x86_64__
- "pushq %%rbx \n\t" // save index to Global Offset Table
-#else
- "pushl %%ebx \n\t" // save index to Global Offset Table
-#endif
-#endif
- "movl _MMXLength, %%ebx \n\t"
- "cmpl _FullLength, %%ebx \n\t"
- "jnb paeth_end \n\t"
-//pre "movl row, %%edi \n\t"
-//pre "movl prev_row, %%esi \n\t"
- // do Paeth decode for remaining bytes
- "movl %%ebx, %%edx \n\t"
-//pre "subl bpp, %%edx \n\t" // (bpp is preloaded into ecx)
- "subl %%ecx, %%edx \n\t" // edx = ebx - bpp
- "xorl %%ecx, %%ecx \n\t" // zero ecx before using cl & cx below
-
- "paeth_lp2: \n\t"
- "xorl %%eax, %%eax \n\t"
- // pav = p - a = (a + b - c) - a = b - c
- "movb (%%esi,%%ebx,), %%al \n\t" // load Prior(x) into al
- "movb (%%esi,%%edx,), %%cl \n\t" // load Prior(x-bpp) into cl
- "subl %%ecx, %%eax \n\t" // subtract Prior(x-bpp)
- "movl %%eax, _patemp \n\t" // Save pav for later use
- "xorl %%eax, %%eax \n\t"
- // pbv = p - b = (a + b - c) - b = a - c
- "movb (%%edi,%%edx,), %%al \n\t" // load Raw(x-bpp) into al
- "subl %%ecx, %%eax \n\t" // subtract Prior(x-bpp)
- "movl %%eax, %%ecx \n\t"
- // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
- "addl _patemp, %%eax \n\t" // pcv = pav + pbv
- // pc = abs(pcv)
- "testl $0x80000000, %%eax \n\t"
- "jz paeth_pca2 \n\t"
- "negl %%eax \n\t" // reverse sign of neg values
-
- "paeth_pca2: \n\t"
- "movl %%eax, _pctemp \n\t" // save pc for later use
- // pb = abs(pbv)
- "testl $0x80000000, %%ecx \n\t"
- "jz paeth_pba2 \n\t"
- "negl %%ecx \n\t" // reverse sign of neg values
-
- "paeth_pba2: \n\t"
- "movl %%ecx, _pbtemp \n\t" // save pb for later use
- // pa = abs(pav)
- "movl _patemp, %%eax \n\t"
- "testl $0x80000000, %%eax \n\t"
- "jz paeth_paa2 \n\t"
- "negl %%eax \n\t" // reverse sign of neg values
-
- "paeth_paa2: \n\t"
- "movl %%eax, _patemp \n\t" // save pa for later use
- // test if pa <= pb
- "cmpl %%ecx, %%eax \n\t"
- "jna paeth_abb2 \n\t"
- // pa > pb; now test if pb <= pc
- "cmpl _pctemp, %%ecx \n\t"
- "jna paeth_bbc2 \n\t"
- // pb > pc; Raw(x) = Paeth(x) + Prior(x-bpp)
- "movb (%%esi,%%edx,), %%cl \n\t" // load Prior(x-bpp) into cl
- "jmp paeth_paeth2 \n\t"
-
- "paeth_bbc2: \n\t"
- // pb <= pc; Raw(x) = Paeth(x) + Prior(x)
- "movb (%%esi,%%ebx,), %%cl \n\t" // load Prior(x) into cl
- "jmp paeth_paeth2 \n\t"
-
- "paeth_abb2: \n\t"
- // pa <= pb; now test if pa <= pc
- "cmpl _pctemp, %%eax \n\t"
- "jna paeth_abc2 \n\t"
- // pa > pc; Raw(x) = Paeth(x) + Prior(x-bpp)
- "movb (%%esi,%%edx,), %%cl \n\t" // load Prior(x-bpp) into cl
- "jmp paeth_paeth2 \n\t"
-
- "paeth_abc2: \n\t"
- // pa <= pc; Raw(x) = Paeth(x) + Raw(x-bpp)
- "movb (%%edi,%%edx,), %%cl \n\t" // load Raw(x-bpp) into cl
-
- "paeth_paeth2: \n\t"
- "incl %%ebx \n\t"
- "incl %%edx \n\t"
- // Raw(x) = (Paeth(x) + Paeth_Predictor( a, b, c )) mod 256
- "addb %%cl, -1(%%edi,%%ebx,) \n\t"
- "cmpl _FullLength, %%ebx \n\t"
- "jb paeth_lp2 \n\t"
-
- "paeth_end: \n\t"
- "EMMS \n\t" // end MMX; prep for poss. FP instrs.
-#ifdef __PIC__
-#ifdef __x86_64__
- "popq %%rbx \n\t" // restore index to Global Offset Table
-#else
- "popl %%ebx \n\t" // restore index to Global Offset Table
-#endif
-#endif
-
- : "=c" (dummy_value_c), // output regs (dummy)
- "=S" (dummy_value_S),
- "=D" (dummy_value_D)
-
- : "0" (bpp), // ecx // input regs
- "1" (prev_row), // esi
- "2" (row) // edi
-
- : "%eax", "%edx" // clobber list (no input regs!)
-#ifndef __PIC__
- , "%ebx"
-#endif
- );
-
-} /* end png_read_filter_row_mmx_paeth() */
-#endif
-
-
-
-
-#ifdef PNG_THREAD_UNSAFE_OK
-//===========================================================================//
-// //
-// P N G _ R E A D _ F I L T E R _ R O W _ M M X _ S U B //
-// //
-//===========================================================================//
-
-// Optimized code for PNG Sub filter decoder
-
-static void /* PRIVATE */
-png_read_filter_row_mmx_sub(png_row_infop row_info, png_bytep row)
-{
- int bpp;
- int dummy_value_a;
- int dummy_value_D;
-
- bpp = (row_info->pixel_depth + 7) >> 3; // calc number of bytes per pixel
- _FullLength = row_info->rowbytes - bpp; // number of bytes to filter
-
- __asm__ __volatile__ (
-//pre "movl row, %%edi \n\t"
- "movl %%edi, %%esi \n\t" // lp = row
-//pre "movl bpp, %%eax \n\t"
- "addl %%eax, %%edi \n\t" // rp = row + bpp
-//irr "xorl %%eax, %%eax \n\t"
- // get # of bytes to alignment
- "movl %%edi, _dif \n\t" // take start of row
- "addl $0xf, _dif \n\t" // add 7 + 8 to incr past
- // alignment boundary
- "xorl %%ecx, %%ecx \n\t"
- "andl $0xfffffff8, _dif \n\t" // mask to alignment boundary
- "subl %%edi, _dif \n\t" // subtract from start ==> value
- "jz sub_go \n\t" // ecx at alignment
-
- "sub_lp1: \n\t" // fix alignment
- "movb (%%esi,%%ecx,), %%al \n\t"
- "addb %%al, (%%edi,%%ecx,) \n\t"
- "incl %%ecx \n\t"
- "cmpl _dif, %%ecx \n\t"
- "jb sub_lp1 \n\t"
-
- "sub_go: \n\t"
- "movl _FullLength, %%eax \n\t"
- "movl %%eax, %%edx \n\t"
- "subl %%ecx, %%edx \n\t" // subtract alignment fix
- "andl $0x00000007, %%edx \n\t" // calc bytes over mult of 8
- "subl %%edx, %%eax \n\t" // drop over bytes from length
- "movl %%eax, _MMXLength \n\t"
-
- : "=a" (dummy_value_a), // 0 // output regs (dummy)
- "=D" (dummy_value_D) // 1
-
- : "0" (bpp), // eax // input regs
- "1" (row) // edi
-
- : "%esi", "%ecx", "%edx" // clobber list
-
-#if 0 /* MMX regs (%mm0, etc.) not supported by gcc 2.7.2.3 or egcs 1.1 */
- , "%mm0", "%mm1", "%mm2", "%mm3"
- , "%mm4", "%mm5", "%mm6", "%mm7"
-#endif
- );
-
- // now do the math for the rest of the row
- switch (bpp)
- {
- case 3:
- {
- _ActiveMask.use = 0x0000ffffff000000LL;
- _ShiftBpp.use = 24; // == 3 * 8
- _ShiftRem.use = 40; // == 64 - 24
-
- __asm__ __volatile__ (
-// preload "movl row, %%edi \n\t"
- "movq _ActiveMask, %%mm7 \n\t" // load _ActiveMask for 2nd
- // active byte group
- "movl %%edi, %%esi \n\t" // lp = row
-// preload "movl bpp, %%eax \n\t"
- "addl %%eax, %%edi \n\t" // rp = row + bpp
- "movq %%mm7, %%mm6 \n\t"
- "movl _dif, %%edx \n\t"
- "psllq _ShiftBpp, %%mm6 \n\t" // move mask in mm6 to cover
- // 3rd active byte group
- // prime the pump: load the first Raw(x-bpp) data set
- "movq -8(%%edi,%%edx,), %%mm1 \n\t"
-
- "sub_3lp: \n\t" // shift data for adding first
- "psrlq _ShiftRem, %%mm1 \n\t" // bpp bytes (no need for mask;
- // shift clears inactive bytes)
- // add 1st active group
- "movq (%%edi,%%edx,), %%mm0 \n\t"
- "paddb %%mm1, %%mm0 \n\t"
-
- // add 2nd active group
- "movq %%mm0, %%mm1 \n\t" // mov updated Raws to mm1
- "psllq _ShiftBpp, %%mm1 \n\t" // shift data to pos. correctly
- "pand %%mm7, %%mm1 \n\t" // mask to use 2nd active group
- "paddb %%mm1, %%mm0 \n\t"
-
- // add 3rd active group
- "movq %%mm0, %%mm1 \n\t" // mov updated Raws to mm1
- "psllq _ShiftBpp, %%mm1 \n\t" // shift data to pos. correctly
- "pand %%mm6, %%mm1 \n\t" // mask to use 3rd active group
- "addl $8, %%edx \n\t"
- "paddb %%mm1, %%mm0 \n\t"
-
- "cmpl _MMXLength, %%edx \n\t"
- "movq %%mm0, -8(%%edi,%%edx,) \n\t" // write updated Raws to array
- "movq %%mm0, %%mm1 \n\t" // prep 1st add at top of loop
- "jb sub_3lp \n\t"
-
- : "=a" (dummy_value_a), // 0 // output regs (dummy)
- "=D" (dummy_value_D) // 1
-
- : "0" (bpp), // eax // input regs
- "1" (row) // edi
-
- : "%edx", "%esi" // clobber list
-#if 0 /* MMX regs (%mm0, etc.) not supported by gcc 2.7.2.3 or egcs 1.1 */
- , "%mm0", "%mm1", "%mm6", "%mm7"
-#endif
- );
- }
- break;
-
- case 1:
- {
- __asm__ __volatile__ (
- "movl _dif, %%edx \n\t"
-// preload "movl row, %%edi \n\t"
- "cmpl _FullLength, %%edx \n\t"
- "jnb sub_1end \n\t"
- "movl %%edi, %%esi \n\t" // lp = row
- "xorl %%eax, %%eax \n\t"
-// preload "movl bpp, %%eax \n\t"
- "addl %%eax, %%edi \n\t" // rp = row + bpp
-
- "sub_1lp: \n\t"
- "movb (%%esi,%%edx,), %%al \n\t"
- "addb %%al, (%%edi,%%edx,) \n\t"
- "incl %%edx \n\t"
- "cmpl _FullLength, %%edx \n\t"
- "jb sub_1lp \n\t"
-
- "sub_1end: \n\t"
-
- : "=a" (dummy_value_a), // 0 // output regs (dummy)
- "=D" (dummy_value_D) // 1
-
- : "0" (bpp), // eax // input regs
- "1" (row) // edi
-
- : "%edx", "%esi" // clobber list
- );
- }
- return;
-
- case 6:
- case 4:
- //case 7: // GRR BOGUS
- //case 5: // GRR BOGUS
- {
- _ShiftBpp.use = bpp << 3;
- _ShiftRem.use = 64 - _ShiftBpp.use;
-
- __asm__ __volatile__ (
-// preload "movl row, %%edi \n\t"
- "movl _dif, %%edx \n\t"
- "movl %%edi, %%esi \n\t" // lp = row
-// preload "movl bpp, %%eax \n\t"
- "addl %%eax, %%edi \n\t" // rp = row + bpp
-
- // prime the pump: load the first Raw(x-bpp) data set
- "movq -8(%%edi,%%edx,), %%mm1 \n\t"
-
- "sub_4lp: \n\t" // shift data for adding first
- "psrlq _ShiftRem, %%mm1 \n\t" // bpp bytes (no need for mask;
- // shift clears inactive bytes)
- "movq (%%edi,%%edx,), %%mm0 \n\t"
- "paddb %%mm1, %%mm0 \n\t"
-
- // add 2nd active group
- "movq %%mm0, %%mm1 \n\t" // mov updated Raws to mm1
- "psllq _ShiftBpp, %%mm1 \n\t" // shift data to pos. correctly
- "addl $8, %%edx \n\t"
- "paddb %%mm1, %%mm0 \n\t"
-
- "cmpl _MMXLength, %%edx \n\t"
- "movq %%mm0, -8(%%edi,%%edx,) \n\t"
- "movq %%mm0, %%mm1 \n\t" // prep 1st add at top of loop
- "jb sub_4lp \n\t"
-
- : "=a" (dummy_value_a), // 0 // output regs (dummy)
- "=D" (dummy_value_D) // 1
-
- : "0" (bpp), // eax // input regs
- "1" (row) // edi
-
- : "%edx", "%esi" // clobber list
-#if 0 /* MMX regs (%mm0, etc.) not supported by gcc 2.7.2.3 or egcs 1.1 */
- , "%mm0", "%mm1"
-#endif
- );
- }
- break;
-
- case 2:
- {
- _ActiveMask.use = 0x00000000ffff0000LL;
- _ShiftBpp.use = 16; // == 2 * 8
- _ShiftRem.use = 48; // == 64 - 16
-
- __asm__ __volatile__ (
- "movq _ActiveMask, %%mm7 \n\t" // load _ActiveMask for 2nd
- // active byte group
- "movl _dif, %%edx \n\t"
- "movq %%mm7, %%mm6 \n\t"
-// preload "movl row, %%edi \n\t"
- "psllq _ShiftBpp, %%mm6 \n\t" // move mask in mm6 to cover
- // 3rd active byte group
- "movl %%edi, %%esi \n\t" // lp = row
- "movq %%mm6, %%mm5 \n\t"
-// preload "movl bpp, %%eax \n\t"
- "addl %%eax, %%edi \n\t" // rp = row + bpp
- "psllq _ShiftBpp, %%mm5 \n\t" // move mask in mm5 to cover
- // 4th active byte group
- // prime the pump: load the first Raw(x-bpp) data set
- "movq -8(%%edi,%%edx,), %%mm1 \n\t"
-
- "sub_2lp: \n\t" // shift data for adding first
- "psrlq _ShiftRem, %%mm1 \n\t" // bpp bytes (no need for mask;
- // shift clears inactive bytes)
- // add 1st active group
- "movq (%%edi,%%edx,), %%mm0 \n\t"
- "paddb %%mm1, %%mm0 \n\t"
-
- // add 2nd active group
- "movq %%mm0, %%mm1 \n\t" // mov updated Raws to mm1
- "psllq _ShiftBpp, %%mm1 \n\t" // shift data to pos. correctly
- "pand %%mm7, %%mm1 \n\t" // mask to use 2nd active group
- "paddb %%mm1, %%mm0 \n\t"
-
- // add 3rd active group
- "movq %%mm0, %%mm1 \n\t" // mov updated Raws to mm1
- "psllq _ShiftBpp, %%mm1 \n\t" // shift data to pos. correctly
- "pand %%mm6, %%mm1 \n\t" // mask to use 3rd active group
- "paddb %%mm1, %%mm0 \n\t"
-
- // add 4th active group
- "movq %%mm0, %%mm1 \n\t" // mov updated Raws to mm1
- "psllq _ShiftBpp, %%mm1 \n\t" // shift data to pos. correctly
- "pand %%mm5, %%mm1 \n\t" // mask to use 4th active group
- "addl $8, %%edx \n\t"
- "paddb %%mm1, %%mm0 \n\t"
- "cmpl _MMXLength, %%edx \n\t"
- "movq %%mm0, -8(%%edi,%%edx,) \n\t" // write updated Raws to array
- "movq %%mm0, %%mm1 \n\t" // prep 1st add at top of loop
- "jb sub_2lp \n\t"
-
- : "=a" (dummy_value_a), // 0 // output regs (dummy)
- "=D" (dummy_value_D) // 1
-
- : "0" (bpp), // eax // input regs
- "1" (row) // edi
-
- : "%edx", "%esi" // clobber list
-#if 0 /* MMX regs (%mm0, etc.) not supported by gcc 2.7.2.3 or egcs 1.1 */
- , "%mm0", "%mm1", "%mm5", "%mm6", "%mm7"
-#endif
- );
- }
- break;
-
- case 8:
- {
- __asm__ __volatile__ (
-// preload "movl row, %%edi \n\t"
- "movl _dif, %%edx \n\t"
- "movl %%edi, %%esi \n\t" // lp = row
-// preload "movl bpp, %%eax \n\t"
- "addl %%eax, %%edi \n\t" // rp = row + bpp
- "movl _MMXLength, %%ecx \n\t"
-
- // prime the pump: load the first Raw(x-bpp) data set
- "movq -8(%%edi,%%edx,), %%mm7 \n\t"
- "andl $0x0000003f, %%ecx \n\t" // calc bytes over mult of 64
-
- "sub_8lp: \n\t"
- "movq (%%edi,%%edx,), %%mm0 \n\t" // load Sub(x) for 1st 8 bytes
- "paddb %%mm7, %%mm0 \n\t"
- "movq 8(%%edi,%%edx,), %%mm1 \n\t" // load Sub(x) for 2nd 8 bytes
- "movq %%mm0, (%%edi,%%edx,) \n\t" // write Raw(x) for 1st 8 bytes
-
- // Now mm0 will be used as Raw(x-bpp) for the 2nd group of 8 bytes.
- // This will be repeated for each group of 8 bytes with the 8th
- // group being used as the Raw(x-bpp) for the 1st group of the
- // next loop.
-
- "paddb %%mm0, %%mm1 \n\t"
- "movq 16(%%edi,%%edx,), %%mm2 \n\t" // load Sub(x) for 3rd 8 bytes
- "movq %%mm1, 8(%%edi,%%edx,) \n\t" // write Raw(x) for 2nd 8 bytes
- "paddb %%mm1, %%mm2 \n\t"
- "movq 24(%%edi,%%edx,), %%mm3 \n\t" // load Sub(x) for 4th 8 bytes
- "movq %%mm2, 16(%%edi,%%edx,) \n\t" // write Raw(x) for 3rd 8 bytes
- "paddb %%mm2, %%mm3 \n\t"
- "movq 32(%%edi,%%edx,), %%mm4 \n\t" // load Sub(x) for 5th 8 bytes
- "movq %%mm3, 24(%%edi,%%edx,) \n\t" // write Raw(x) for 4th 8 bytes
- "paddb %%mm3, %%mm4 \n\t"
- "movq 40(%%edi,%%edx,), %%mm5 \n\t" // load Sub(x) for 6th 8 bytes
- "movq %%mm4, 32(%%edi,%%edx,) \n\t" // write Raw(x) for 5th 8 bytes
- "paddb %%mm4, %%mm5 \n\t"
- "movq 48(%%edi,%%edx,), %%mm6 \n\t" // load Sub(x) for 7th 8 bytes
- "movq %%mm5, 40(%%edi,%%edx,) \n\t" // write Raw(x) for 6th 8 bytes
- "paddb %%mm5, %%mm6 \n\t"
- "movq 56(%%edi,%%edx,), %%mm7 \n\t" // load Sub(x) for 8th 8 bytes
- "movq %%mm6, 48(%%edi,%%edx,) \n\t" // write Raw(x) for 7th 8 bytes
- "addl $64, %%edx \n\t"
- "paddb %%mm6, %%mm7 \n\t"
- "cmpl %%ecx, %%edx \n\t"
- "movq %%mm7, -8(%%edi,%%edx,) \n\t" // write Raw(x) for 8th 8 bytes
- "jb sub_8lp \n\t"
-
- "cmpl _MMXLength, %%edx \n\t"
- "jnb sub_8lt8 \n\t"
-
- "sub_8lpA: \n\t"
- "movq (%%edi,%%edx,), %%mm0 \n\t"
- "addl $8, %%edx \n\t"
- "paddb %%mm7, %%mm0 \n\t"
- "cmpl _MMXLength, %%edx \n\t"
- "movq %%mm0, -8(%%edi,%%edx,) \n\t" // -8 to offset early addl edx
- "movq %%mm0, %%mm7 \n\t" // move calculated Raw(x) data
- // to mm1 to be new Raw(x-bpp)
- // for next loop
- "jb sub_8lpA \n\t"
-
- "sub_8lt8: \n\t"
-
- : "=a" (dummy_value_a), // 0 // output regs (dummy)
- "=D" (dummy_value_D) // 1
-
- : "0" (bpp), // eax // input regs
- "1" (row) // edi
-
- : "%ecx", "%edx", "%esi" // clobber list
-#if 0 /* MMX regs (%mm0, etc.) not supported by gcc 2.7.2.3 or egcs 1.1 */
- , "%mm0", "%mm1", "%mm2", "%mm3", "%mm4", "%mm5", "%mm6", "%mm7"
-#endif
- );
- }
- break;
-
- default: // bpp greater than 8 bytes GRR BOGUS
- {
- __asm__ __volatile__ (
- "movl _dif, %%edx \n\t"
-// preload "movl row, %%edi \n\t"
- "movl %%edi, %%esi \n\t" // lp = row
-// preload "movl bpp, %%eax \n\t"
- "addl %%eax, %%edi \n\t" // rp = row + bpp
-
- "sub_Alp: \n\t"
- "movq (%%edi,%%edx,), %%mm0 \n\t"
- "movq (%%esi,%%edx,), %%mm1 \n\t"
- "addl $8, %%edx \n\t"
- "paddb %%mm1, %%mm0 \n\t"
- "cmpl _MMXLength, %%edx \n\t"
- "movq %%mm0, -8(%%edi,%%edx,) \n\t" // mov does not affect flags;
- // -8 to offset addl edx
- "jb sub_Alp \n\t"
-
- : "=a" (dummy_value_a), // 0 // output regs (dummy)
- "=D" (dummy_value_D) // 1
-
- : "0" (bpp), // eax // input regs
- "1" (row) // edi
-
- : "%edx", "%esi" // clobber list
-#if 0 /* MMX regs (%mm0, etc.) not supported by gcc 2.7.2.3 or egcs 1.1 */
- , "%mm0", "%mm1"
-#endif
- );
- }
- break;
-
- } // end switch (bpp)
-
- __asm__ __volatile__ (
- "movl _MMXLength, %%edx \n\t"
-//pre "movl row, %%edi \n\t"
- "cmpl _FullLength, %%edx \n\t"
- "jnb sub_end \n\t"
-
- "movl %%edi, %%esi \n\t" // lp = row
-//pre "movl bpp, %%eax \n\t"
- "addl %%eax, %%edi \n\t" // rp = row + bpp
- "xorl %%eax, %%eax \n\t"
-
- "sub_lp2: \n\t"
- "movb (%%esi,%%edx,), %%al \n\t"
- "addb %%al, (%%edi,%%edx,) \n\t"
- "incl %%edx \n\t"
- "cmpl _FullLength, %%edx \n\t"
- "jb sub_lp2 \n\t"
-
- "sub_end: \n\t"
- "EMMS \n\t" // end MMX instructions
-
- : "=a" (dummy_value_a), // 0 // output regs (dummy)
- "=D" (dummy_value_D) // 1
-
- : "0" (bpp), // eax // input regs
- "1" (row) // edi
-
- : "%edx", "%esi" // clobber list
- );
-
-} // end of png_read_filter_row_mmx_sub()
-#endif
-
-
-
-
-//===========================================================================//
-// //
-// P N G _ R E A D _ F I L T E R _ R O W _ M M X _ U P //
-// //
-//===========================================================================//
-
-// Optimized code for PNG Up filter decoder
-
-static void /* PRIVATE */
-png_read_filter_row_mmx_up(png_row_infop row_info, png_bytep row,
- png_bytep prev_row)
-{
- png_uint_32 len;
- int dummy_value_d; // fix 'forbidden register 3 (dx) was spilled' error
- int dummy_value_S;
- int dummy_value_D;
-
- len = row_info->rowbytes; // number of bytes to filter
-
- __asm__ __volatile__ (
-//pre "movl row, %%edi \n\t"
- // get # of bytes to alignment
-#ifdef __PIC__
-#ifdef __x86_64__
- "pushq %%rbx \n\t"
-#else
- "pushl %%ebx \n\t"
-#endif
-#endif
- "movl %%edi, %%ecx \n\t"
- "xorl %%ebx, %%ebx \n\t"
- "addl $0x7, %%ecx \n\t"
- "xorl %%eax, %%eax \n\t"
- "andl $0xfffffff8, %%ecx \n\t"
-//pre "movl prev_row, %%esi \n\t"
- "subl %%edi, %%ecx \n\t"
- "jz up_go \n\t"
-
- "up_lp1: \n\t" // fix alignment
- "movb (%%edi,%%ebx,), %%al \n\t"
- "addb (%%esi,%%ebx,), %%al \n\t"
- "incl %%ebx \n\t"
- "cmpl %%ecx, %%ebx \n\t"
- "movb %%al, -1(%%edi,%%ebx,) \n\t" // mov does not affect flags; -1 to
- "jb up_lp1 \n\t" // offset incl ebx
-
- "up_go: \n\t"
-//pre "movl len, %%edx \n\t"
- "movl %%edx, %%ecx \n\t"
- "subl %%ebx, %%edx \n\t" // subtract alignment fix
- "andl $0x0000003f, %%edx \n\t" // calc bytes over mult of 64
- "subl %%edx, %%ecx \n\t" // drop over bytes from length
-
- // unrolled loop - use all MMX registers and interleave to reduce
- // number of branch instructions (loops) and reduce partial stalls
- "up_loop: \n\t"
- "movq (%%esi,%%ebx,), %%mm1 \n\t"
- "movq (%%edi,%%ebx,), %%mm0 \n\t"
- "movq 8(%%esi,%%ebx,), %%mm3 \n\t"
- "paddb %%mm1, %%mm0 \n\t"
- "movq 8(%%edi,%%ebx,), %%mm2 \n\t"
- "movq %%mm0, (%%edi,%%ebx,) \n\t"
- "paddb %%mm3, %%mm2 \n\t"
- "movq 16(%%esi,%%ebx,), %%mm5 \n\t"
- "movq %%mm2, 8(%%edi,%%ebx,) \n\t"
- "movq 16(%%edi,%%ebx,), %%mm4 \n\t"
- "movq 24(%%esi,%%ebx,), %%mm7 \n\t"
- "paddb %%mm5, %%mm4 \n\t"
- "movq 24(%%edi,%%ebx,), %%mm6 \n\t"
- "movq %%mm4, 16(%%edi,%%ebx,) \n\t"
- "paddb %%mm7, %%mm6 \n\t"
- "movq 32(%%esi,%%ebx,), %%mm1 \n\t"
- "movq %%mm6, 24(%%edi,%%ebx,) \n\t"
- "movq 32(%%edi,%%ebx,), %%mm0 \n\t"
- "movq 40(%%esi,%%ebx,), %%mm3 \n\t"
- "paddb %%mm1, %%mm0 \n\t"
- "movq 40(%%edi,%%ebx,), %%mm2 \n\t"
- "movq %%mm0, 32(%%edi,%%ebx,) \n\t"
- "paddb %%mm3, %%mm2 \n\t"
- "movq 48(%%esi,%%ebx,), %%mm5 \n\t"
- "movq %%mm2, 40(%%edi,%%ebx,) \n\t"
- "movq 48(%%edi,%%ebx,), %%mm4 \n\t"
- "movq 56(%%esi,%%ebx,), %%mm7 \n\t"
- "paddb %%mm5, %%mm4 \n\t"
- "movq 56(%%edi,%%ebx,), %%mm6 \n\t"
- "movq %%mm4, 48(%%edi,%%ebx,) \n\t"
- "addl $64, %%ebx \n\t"
- "paddb %%mm7, %%mm6 \n\t"
- "cmpl %%ecx, %%ebx \n\t"
- "movq %%mm6, -8(%%edi,%%ebx,) \n\t" // (+56)movq does not affect flags;
- "jb up_loop \n\t" // -8 to offset addl ebx
-
- "cmpl $0, %%edx \n\t" // test for bytes over mult of 64
- "jz up_end \n\t"
-
- "cmpl $8, %%edx \n\t" // test for less than 8 bytes
- "jb up_lt8 \n\t" // [added by lcreeve at netins.net]
-
- "addl %%edx, %%ecx \n\t"
- "andl $0x00000007, %%edx \n\t" // calc bytes over mult of 8
- "subl %%edx, %%ecx \n\t" // drop over bytes from length
- "jz up_lt8 \n\t"
-
- "up_lpA: \n\t" // use MMX regs to update 8 bytes sim.
- "movq (%%esi,%%ebx,), %%mm1 \n\t"
- "movq (%%edi,%%ebx,), %%mm0 \n\t"
- "addl $8, %%ebx \n\t"
- "paddb %%mm1, %%mm0 \n\t"
- "cmpl %%ecx, %%ebx \n\t"
- "movq %%mm0, -8(%%edi,%%ebx,) \n\t" // movq does not affect flags; -8 to
- "jb up_lpA \n\t" // offset add ebx
- "cmpl $0, %%edx \n\t" // test for bytes over mult of 8
- "jz up_end \n\t"
-
- "up_lt8: \n\t"
- "xorl %%eax, %%eax \n\t"
- "addl %%edx, %%ecx \n\t" // move over byte count into counter
-
- "up_lp2: \n\t" // use x86 regs for remaining bytes
- "movb (%%edi,%%ebx,), %%al \n\t"
- "addb (%%esi,%%ebx,), %%al \n\t"
- "incl %%ebx \n\t"
- "cmpl %%ecx, %%ebx \n\t"
- "movb %%al, -1(%%edi,%%ebx,) \n\t" // mov does not affect flags; -1 to
- "jb up_lp2 \n\t" // offset inc ebx
-
- "up_end: \n\t"
- "EMMS \n\t" // conversion of filtered row complete
-#ifdef __PIC__
-#ifdef __x86_64__
- "popq %%rbx \n\t"
-#else
- "popl %%ebx \n\t"
-#endif
-#endif
-
- : "=d" (dummy_value_d), // 0 // output regs (dummy)
- "=S" (dummy_value_S), // 1
- "=D" (dummy_value_D) // 2
-
- : "0" (len), // edx // input regs
- "1" (prev_row), // esi
- "2" (row) // edi
-
- : "%eax", "%ecx" // clobber list (no input regs!)
-#ifndef __PIC__
- , "%ebx"
-#endif
-
-#if 0 /* MMX regs (%mm0, etc.) not supported by gcc 2.7.2.3 or egcs 1.1 */
- , "%mm0", "%mm1", "%mm2", "%mm3"
- , "%mm4", "%mm5", "%mm6", "%mm7"
-#endif
- );
-
-} // end of png_read_filter_row_mmx_up()
-
-#endif /* PNG_MMX_CODE_SUPPORTED */
-
-
-
-
-/*===========================================================================*/
-/* */
-/* P N G _ R E A D _ F I L T E R _ R O W */
-/* */
-/*===========================================================================*/
-
-
-/* Optimized png_read_filter_row routines */
-
-void /* PRIVATE */
-png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep
- row, png_bytep prev_row, int filter)
-{
-#ifdef PNG_DEBUG
- char filnm[10];
-#endif
-
-#if defined(PNG_MMX_CODE_SUPPORTED)
-/* GRR: these are superseded by png_ptr->asm_flags: */
-#define UseMMX_sub 1 // GRR: converted 20000730
-#define UseMMX_up 1 // GRR: converted 20000729
-#define UseMMX_avg 1 // GRR: converted 20000828 (+ 16-bit bugfix 20000916)
-#define UseMMX_paeth 1 // GRR: converted 20000828
-
- if (_mmx_supported == 2) {
- /* this should have happened in png_init_mmx_flags() already */
- png_warning(png_ptr, "asm_flags may not have been initialized");
- png_mmx_support();
- }
-#endif /* PNG_MMX_CODE_SUPPORTED */
-
-#ifdef PNG_DEBUG
- png_debug(1, "in png_read_filter_row (pnggccrd.c)\n");
- switch (filter)
- {
- case 0: sprintf(filnm, "none");
- break;
- case 1: sprintf(filnm, "sub-%s",
-#if defined(PNG_MMX_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK)
- (png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_SUB)? "MMX" :
-#endif
-"x86");
- break;
- case 2: sprintf(filnm, "up-%s",
-#ifdef PNG_MMX_CODE_SUPPORTED
- (png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_UP)? "MMX" :
-#endif
- "x86");
- break;
- case 3: sprintf(filnm, "avg-%s",
-#if defined(PNG_MMX_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK)
- (png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_AVG)? "MMX" :
-#endif
- "x86");
- break;
- case 4: sprintf(filnm, "Paeth-%s",
-#if defined(PNG_MMX_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK)
- (png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_PAETH)? "MMX":
-#endif
-"x86");
- break;
- default: sprintf(filnm, "unknw");
- break;
- }
- png_debug2(0, "row_number=%5ld, %5s, ", png_ptr->row_number, filnm);
- png_debug1(0, "row=0x%08lx, ", (unsigned long)row);
- png_debug2(0, "pixdepth=%2d, bytes=%d, ", (int)row_info->pixel_depth,
- (int)((row_info->pixel_depth + 7) >> 3));
- png_debug1(0,"rowbytes=%8ld\n", row_info->rowbytes);
-#endif /* PNG_DEBUG */
-
- switch (filter)
- {
- case PNG_FILTER_VALUE_NONE:
- break;
-
- case PNG_FILTER_VALUE_SUB:
-#if defined(PNG_MMX_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK)
- if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_SUB) &&
- (row_info->pixel_depth >= png_ptr->mmx_bitdepth_threshold) &&
- (row_info->rowbytes >= png_ptr->mmx_rowbytes_threshold))
- {
- png_read_filter_row_mmx_sub(row_info, row);
- }
- else
-#endif /* PNG_MMX_CODE_SUPPORTED */
- {
- png_uint_32 i;
- png_uint_32 istop = row_info->rowbytes;
- png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
- png_bytep rp = row + bpp;
- png_bytep lp = row;
-
- for (i = bpp; i < istop; i++)
- {
- *rp = (png_byte)(((int)(*rp) + (int)(*lp++)) & 0xff);
- rp++;
- }
- } /* end !UseMMX_sub */
- break;
-
- case PNG_FILTER_VALUE_UP:
-#if defined(PNG_MMX_CODE_SUPPORTED)
- if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_UP) &&
- (row_info->pixel_depth >= png_ptr->mmx_bitdepth_threshold) &&
- (row_info->rowbytes >= png_ptr->mmx_rowbytes_threshold))
- {
- png_read_filter_row_mmx_up(row_info, row, prev_row);
- }
- else
-#endif /* PNG_MMX_CODE_SUPPORTED */
- {
- png_uint_32 i;
- png_uint_32 istop = row_info->rowbytes;
- png_bytep rp = row;
- png_bytep pp = prev_row;
-
- for (i = 0; i < istop; ++i)
- {
- *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
- rp++;
- }
- } /* end !UseMMX_up */
- break;
-
- case PNG_FILTER_VALUE_AVG:
-#if defined(PNG_MMX_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK)
- if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_AVG) &&
- (row_info->pixel_depth >= png_ptr->mmx_bitdepth_threshold) &&
- (row_info->rowbytes >= png_ptr->mmx_rowbytes_threshold))
- {
- png_read_filter_row_mmx_avg(row_info, row, prev_row);
- }
- else
-#endif /* PNG_MMX_CODE_SUPPORTED */
- {
- png_uint_32 i;
- png_bytep rp = row;
- png_bytep pp = prev_row;
- png_bytep lp = row;
- png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
- png_uint_32 istop = row_info->rowbytes - bpp;
-
- for (i = 0; i < bpp; i++)
- {
- *rp = (png_byte)(((int)(*rp) +
- ((int)(*pp++) >> 1)) & 0xff);
- rp++;
- }
-
- for (i = 0; i < istop; i++)
- {
- *rp = (png_byte)(((int)(*rp) +
- ((int)(*pp++ + *lp++) >> 1)) & 0xff);
- rp++;
- }
- } /* end !UseMMX_avg */
- break;
-
- case PNG_FILTER_VALUE_PAETH:
-#if defined(PNG_MMX_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK)
- if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_PAETH) &&
- (row_info->pixel_depth >= png_ptr->mmx_bitdepth_threshold) &&
- (row_info->rowbytes >= png_ptr->mmx_rowbytes_threshold))
- {
- png_read_filter_row_mmx_paeth(row_info, row, prev_row);
- }
- else
-#endif /* PNG_MMX_CODE_SUPPORTED */
- {
- png_uint_32 i;
- 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) >> 3;
- png_uint_32 istop = row_info->rowbytes - bpp;
-
- 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;
-
- 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++;
- }
- } /* end !UseMMX_paeth */
- break;
-
- default:
- png_warning(png_ptr, "Ignoring bad row-filter type");
- *row=0;
- break;
- }
-}
-
-#endif /* PNG_HAVE_MMX_READ_FILTER_ROW */
-
-
-/*===========================================================================*/
-/* */
-/* P N G _ M M X _ S U P P O R T */
-/* */
-/*===========================================================================*/
-
-/* GRR NOTES: (1) the following code assumes 386 or better (pushfl/popfl)
- * (2) all instructions compile with gcc 2.7.2.3 and later
- * (3) the function is moved down here to prevent gcc from
- * inlining it in multiple places and then barfing be-
- * cause the ".NOT_SUPPORTED" label is multiply defined
- * [is there a way to signal that a *single* function should
- * not be inlined? is there a way to modify the label for
- * each inlined instance, e.g., by appending _1, _2, etc.?
- * maybe if don't use leading "." in label name? (nope...sigh)]
- */
-
-int PNGAPI
-png_mmx_support(void)
-{
-#if defined(PNG_MMX_CODE_SUPPORTED)
- int result;
- __asm__ __volatile__ (
-#ifdef __x86_64__
- "pushq %%rbx \n\t" // rbx gets clobbered by CPUID instruction
- "pushq %%rcx \n\t" // so does rcx...
- "pushq %%rdx \n\t" // ...and rdx (but rcx & rdx safe on Linux)
-#else
- "pushl %%ebx \n\t" // ebx gets clobbered by CPUID instruction
- "pushl %%ecx \n\t" // so does ecx...
- "pushl %%edx \n\t" // ...and edx (but ecx & edx safe on Linux)
-#endif
-// ".byte 0x66 \n\t" // convert 16-bit pushf to 32-bit pushfd
-// "pushf \n\t" // 16-bit pushf
-#ifdef __x86_64__
- "pushfq \n\t" // save Eflag to stack
- "popq %%rax \n\t" // get Eflag from stack into rax
- "movq %%rax, %%rcx \n\t" // make another copy of Eflag in rcx
- "xorl $0x200000, %%eax \n\t" // toggle ID bit in Eflag (i.e., bit 21)
- "pushq %%rax \n\t" // save modified Eflag back to stack
-#else
- "pushfl \n\t" // save Eflag to stack
- "popl %%eax \n\t" // get Eflag from stack into eax
- "movl %%eax, %%ecx \n\t" // make another copy of Eflag in ecx
- "xorl $0x200000, %%eax \n\t" // toggle ID bit in Eflag (i.e., bit 21)
- "pushl %%eax \n\t" // save modified Eflag back to stack
-#endif
-// ".byte 0x66 \n\t" // convert 16-bit popf to 32-bit popfd
-// "popf \n\t" // 16-bit popf
-#ifdef __x86_64__
- "popfq \n\t" // restore modified value to Eflag reg
- "pushfq \n\t" // save Eflag to stack
- "popq %%rax \n\t" // get Eflag from stack
- "pushq %%rcx \n\t" // save original Eflag to stack
- "popfq \n\t" // restore original Eflag
-#else
- "popfl \n\t" // restore modified value to Eflag reg
- "pushfl \n\t" // save Eflag to stack
- "popl %%eax \n\t" // get Eflag from stack
- "pushl %%ecx \n\t" // save original Eflag to stack
- "popfl \n\t" // restore original Eflag
-#endif
- "xorl %%ecx, %%eax \n\t" // compare new Eflag with original Eflag
- "jz 0f \n\t" // if same, CPUID instr. is not supported
-
- "xorl %%eax, %%eax \n\t" // set eax to zero
-// ".byte 0x0f, 0xa2 \n\t" // CPUID instruction (two-byte opcode)
- "cpuid \n\t" // get the CPU identification info
- "cmpl $1, %%eax \n\t" // make sure eax return non-zero value
- "jl 0f \n\t" // if eax is zero, MMX is not supported
-
- "xorl %%eax, %%eax \n\t" // set eax to zero and...
- "incl %%eax \n\t" // ...increment eax to 1. This pair is
- // faster than the instruction "mov eax, 1"
- "cpuid \n\t" // get the CPU identification info again
- "andl $0x800000, %%edx \n\t" // mask out all bits but MMX bit (23)
- "cmpl $0, %%edx \n\t" // 0 = MMX not supported
- "jz 0f \n\t" // non-zero = yes, MMX IS supported
-
- "movl $1, %%eax \n\t" // set return value to 1
- "jmp 1f \n\t" // DONE: have MMX support
-
- "0: \n\t" // .NOT_SUPPORTED: target label for jump instructions
- "movl $0, %%eax \n\t" // set return value to 0
- "1: \n\t" // .RETURN: target label for jump instructions
-#ifdef __x86_64__
- "popq %%rdx \n\t" // restore rdx
- "popq %%rcx \n\t" // restore rcx
- "popq %%rbx \n\t" // restore rbx
-#else
- "popl %%edx \n\t" // restore edx
- "popl %%ecx \n\t" // restore ecx
- "popl %%ebx \n\t" // restore ebx
-#endif
-
-// "ret \n\t" // DONE: no MMX support
- // (fall through to standard C "ret")
-
- : "=a" (result) // output list
-
- : // any variables used on input (none)
-
- // no clobber list
-// , "%ebx", "%ecx", "%edx" // GRR: we handle these manually
-// , "memory" // if write to a variable gcc thought was in a reg
-// , "cc" // "condition codes" (flag bits)
- );
- _mmx_supported = result;
-#else
- _mmx_supported = 0;
-#endif /* PNG_MMX_CODE_SUPPORTED */
-
- return _mmx_supported;
-}
-
-
-#endif /* PNG_USE_PNGGCCRD */
diff --git a/pngget.c b/pngget.c
index 32cdec4e8..2c2732d19 100644
--- a/pngget.c
+++ b/pngget.c
@@ -1,17 +1,16 @@
/* pngget.c - retrieval of values from info struct
*
- * Last changed in libpng 1.4.0 May 15, 2007
+ * Last changed in libpng 1.40. [July 10, 2008]
* For conditions of distribution and use, see copyright notice in png.h
- * Copyright (c) 1998-2007 Glenn Randers-Pehrson
+ * Copyright (c) 1998-2008 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*/
#include "png.h"
-#include "pngpriv.h"
-
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
+#include "pngpriv.h"
png_uint_32 PNGAPI
png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag)
@@ -122,7 +121,7 @@ png_get_x_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
if (info_ptr->valid & PNG_INFO_pHYs)
{
png_debug1(1, "in %s retrieval function\n", "png_get_x_pixels_per_meter");
- if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
+ if (info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
return (0);
else return (info_ptr->x_pixels_per_unit);
}
@@ -140,7 +139,7 @@ png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
if (info_ptr->valid & PNG_INFO_pHYs)
{
png_debug1(1, "in %s retrieval function\n", "png_get_y_pixels_per_meter");
- if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
+ if (info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
return (0);
else return (info_ptr->y_pixels_per_unit);
}
@@ -158,7 +157,7 @@ png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
if (info_ptr->valid & PNG_INFO_pHYs)
{
png_debug1(1, "in %s retrieval function\n", "png_get_pixels_per_meter");
- if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER ||
+ if (info_ptr->phys_unit_type != PNG_RESOLUTION_METER ||
info_ptr->x_pixels_per_unit != info_ptr->y_pixels_per_unit)
return (0);
else return (info_ptr->x_pixels_per_unit);
@@ -199,7 +198,7 @@ png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr)
if (info_ptr->valid & PNG_INFO_oFFs)
{
png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
- if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
+ if (info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
return (0);
else return (info_ptr->x_offset);
}
@@ -217,7 +216,7 @@ png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr)
if (info_ptr->valid & PNG_INFO_oFFs)
{
png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
- if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
+ if (info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
return (0);
else return (info_ptr->y_offset);
}
@@ -235,7 +234,7 @@ png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr)
if (info_ptr->valid & PNG_INFO_oFFs)
{
png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
- if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
+ if (info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
return (0);
else return (info_ptr->x_offset);
}
@@ -253,7 +252,7 @@ png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr)
if (info_ptr->valid & PNG_INFO_oFFs)
{
png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
- if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
+ if (info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
return (0);
else return (info_ptr->y_offset);
}
@@ -323,7 +322,7 @@ png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr,
{
*unit_type = (int)info_ptr->phys_unit_type;
retval |= PNG_INFO_pHYs;
- if(*unit_type == 1)
+ if (*unit_type == 1)
{
if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50);
if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50);
@@ -512,8 +511,11 @@ png_get_sPLT(png_structp png_ptr, png_infop info_ptr,
png_sPLT_tpp spalettes)
{
if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
+ {
*spalettes = info_ptr->splt_palettes;
- return ((png_uint_32)info_ptr->splt_palettes_num);
+ return ((png_uint_32)info_ptr->splt_palettes_num);
+ }
+ return (0);
}
#endif
@@ -781,10 +783,10 @@ png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
*trans_values = &(info_ptr->trans_values);
retval |= PNG_INFO_tRNS;
}
- if(trans != NULL)
+ if (trans != NULL)
*trans = NULL;
}
- if(num_trans != NULL)
+ if (num_trans != NULL)
{
*num_trans = info_ptr->num_trans;
retval |= PNG_INFO_tRNS;
@@ -800,8 +802,11 @@ png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr,
png_unknown_chunkpp unknowns)
{
if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)
+ {
*unknowns = info_ptr->unknown_chunks;
- return ((png_uint_32)info_ptr->unknown_chunks_num);
+ return ((png_uint_32)info_ptr->unknown_chunks_num);
+ }
+ return (0);
}
#endif
@@ -825,99 +830,10 @@ png_get_user_chunk_ptr(png_structp png_ptr)
png_size_t PNGAPI
png_get_compression_buffer_size(png_structp png_ptr)
{
- return (png_ptr ? png_ptr->zbuf_size : 0);
-}
-#endif
-
-#ifdef PNG_ASSEMBLER_CODE_SUPPORTED
-/* this function was added to libpng 1.2.0 and should exist by default */
-png_uint_32 PNGAPI
-png_get_asm_flags (png_structp png_ptr)
-{
- return (png_uint_32)(png_ptr? png_ptr->asm_flags : 0L);
+ return (png_ptr ? png_ptr->zbuf_size : 0L);
}
-
-/* this function was added to libpng 1.2.0 and should exist by default */
-png_uint_32 PNGAPI
-png_get_asm_flagmask (int flag_select)
-{
- png_uint_32 settable_asm_flags = 0;
-
-#ifdef PNG_MMX_CODE_SUPPORTED
- if (flag_select & PNG_SELECT_READ)
- settable_asm_flags |=
- PNG_ASM_FLAG_MMX_READ_COMBINE_ROW |
- PNG_ASM_FLAG_MMX_READ_INTERLACE |
- PNG_ASM_FLAG_MMX_READ_FILTER_SUB |
- PNG_ASM_FLAG_MMX_READ_FILTER_UP |
- PNG_ASM_FLAG_MMX_READ_FILTER_AVG |
- PNG_ASM_FLAG_MMX_READ_FILTER_PAETH ;
- /* no non-MMX flags yet */
#endif
-#if 0
- /* GRR: no write-flags yet, either, but someday... */
- if (flag_select & PNG_SELECT_WRITE)
- settable_asm_flags |=
- PNG_ASM_FLAG_MMX_WRITE_ [whatever] ;
-#endif /* 0 */
-
- return settable_asm_flags; /* _theoretically_ settable capabilities only */
-}
-#endif /* PNG_ASSEMBLER_CODE_SUPPORTED */
-
-
-#if defined(PNG_MMX_CODE_SUPPORTED)
-/* this function was added to libpng 1.2.0 */
-png_uint_32 PNGAPI
-png_get_mmx_flagmask (int flag_select, int *compilerID)
-{
- png_uint_32 settable_mmx_flags = 0;
-
- if (flag_select & PNG_SELECT_READ)
- settable_mmx_flags |=
- PNG_ASM_FLAG_MMX_READ_COMBINE_ROW |
- PNG_ASM_FLAG_MMX_READ_INTERLACE |
- PNG_ASM_FLAG_MMX_READ_FILTER_SUB |
- PNG_ASM_FLAG_MMX_READ_FILTER_UP |
- PNG_ASM_FLAG_MMX_READ_FILTER_AVG |
- PNG_ASM_FLAG_MMX_READ_FILTER_PAETH ;
-#if 0
- /* GRR: no MMX write support yet, but someday... */
- if (flag_select & PNG_SELECT_WRITE)
- settable_mmx_flags |=
- PNG_ASM_FLAG_MMX_WRITE_ [whatever] ;
-#endif /* 0 */
-
- if (compilerID != NULL) {
-#ifdef PNG_USE_PNGVCRD
- *compilerID = 1; /* MSVC */
-#else
-#ifdef PNG_USE_PNGGCCRD
- *compilerID = 2; /* gcc/gas */
-#else
- *compilerID = -1; /* unknown (i.e., no asm/MMX code compiled) */
-#endif
-#endif
- }
-
- return settable_mmx_flags; /* _theoretically_ settable capabilities only */
-}
-
-/* this function was added to libpng 1.2.0 */
-png_byte PNGAPI
-png_get_mmx_bitdepth_threshold (png_structp png_ptr)
-{
- return (png_byte)(png_ptr? png_ptr->mmx_bitdepth_threshold : 0);
-}
-
-/* this function was added to libpng 1.2.0 */
-png_uint_32 PNGAPI
-png_get_mmx_rowbytes_threshold (png_structp png_ptr)
-{
- return (png_uint_32)(png_ptr? png_ptr->mmx_rowbytes_threshold : 0L);
-}
-#endif /* ?PNG_MMX_CODE_SUPPORTED */
#ifdef PNG_SET_USER_LIMITS_SUPPORTED
/* these functions were added to libpng 1.2.6 */
@@ -932,7 +848,7 @@ png_get_user_height_max (png_structp png_ptr)
return (png_ptr? png_ptr->user_height_max : 0);
}
#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
-
+
#ifdef PNG_IO_STATE_SUPPORTED
png_uint_32 PNGAPI
png_get_io_state (png_structp png_ptr)
diff --git a/pngmem.c b/pngmem.c
index 959b8cab6..8fa16b5fb 100644
--- a/pngmem.c
+++ b/pngmem.c
@@ -1,9 +1,9 @@
/* pngmem.c - stub functions for memory allocation
*
- * Last changed in libpng 1.4.0 May 15, 2007
+ * Last changed in libpng 1.4.0 [July 10, 2008]
* For conditions of distribution and use, see copyright notice in png.h
- * Copyright (c) 1998-2007 Glenn Randers-Pehrson
+ * Copyright (c) 1998-2008 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*
@@ -15,9 +15,8 @@
*/
#include "png.h"
-#include "pngpriv.h"
-
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
+#include "pngpriv.h"
/* Borland DOS special memory handler */
#if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
@@ -41,19 +40,19 @@ png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
png_voidp struct_ptr;
if (type == PNG_STRUCT_INFO)
- size = sizeof(png_info);
+ size = png_sizeof(png_info);
else if (type == PNG_STRUCT_PNG)
- size = sizeof(png_struct);
+ size = png_sizeof(png_struct);
else
return (png_get_copyright(NULL));
#ifdef PNG_USER_MEM_SUPPORTED
- if(malloc_fn != NULL)
+ if (malloc_fn != NULL)
{
png_struct dummy_struct;
png_structp png_ptr = &dummy_struct;
png_ptr->mem_ptr=mem_ptr;
- struct_ptr = (*(malloc_fn))(png_ptr, size);
+ struct_ptr = (*(malloc_fn))(png_ptr, (png_uint_32)size);
}
else
#endif /* PNG_USER_MEM_SUPPORTED */
@@ -80,7 +79,7 @@ png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
if (struct_ptr != NULL)
{
#ifdef PNG_USER_MEM_SUPPORTED
- if(free_fn != NULL)
+ if (free_fn != NULL)
{
png_struct dummy_struct;
png_structp png_ptr = &dummy_struct;
@@ -122,12 +121,12 @@ png_malloc(png_structp png_ptr, png_alloc_size_t size)
return (NULL);
#ifdef PNG_USER_MEM_SUPPORTED
- if(png_ptr->malloc_fn != NULL)
- ret = (*(png_ptr->malloc_fn))(png_ptr, size);
+ if (png_ptr->malloc_fn != NULL)
+ ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
else
- ret = png_malloc_default(png_ptr, size);
+ ret = (png_malloc_default(png_ptr, size));
if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
- png_error(png_ptr, "Out of memory!");
+ png_error(png_ptr, "Out of memory");
return (ret);
}
@@ -141,7 +140,7 @@ png_malloc_default(png_structp png_ptr, png_alloc_size_t size)
return (NULL);
#ifdef PNG_MAX_MALLOC_64K
- if (size > (png_alloc_size_t)65536L)
+ if (size > (png_uint_32)65536L)
{
png_warning(png_ptr, "Cannot Allocate > 64K");
ret = NULL;
@@ -149,12 +148,9 @@ png_malloc_default(png_structp png_ptr, png_alloc_size_t size)
else
#endif
-#if !defined(INT_MAX) || (INT_MAX <= 0x7ffffffeL)
if (size != (size_t)size)
- ret = NULL;
- else
-#endif
- if (size == (png_alloc_size_t)65536L)
+ ret = NULL;
+ else if (size == (png_uint_32)65536L)
{
if (png_ptr->offset_table == NULL)
{
@@ -174,7 +170,7 @@ png_malloc_default(png_structp png_ptr, png_alloc_size_t size)
ret = NULL;
}
- if(png_ptr->zlib_window_bits > 14)
+ if (png_ptr->zlib_window_bits > 14)
num_blocks = (int)(1 << (png_ptr->zlib_window_bits - 14));
else
num_blocks = 1;
@@ -213,7 +209,7 @@ png_malloc_default(png_structp png_ptr, png_alloc_size_t size)
png_ptr->offset_table = table;
png_ptr->offset_table_ptr = farmalloc(num_blocks *
- sizeof(png_bytep));
+ png_sizeof(png_bytep));
if (png_ptr->offset_table_ptr == NULL)
{
@@ -296,7 +292,7 @@ png_free_default(png_structp png_ptr, png_voidp ptr)
{
#endif /* PNG_USER_MEM_SUPPORTED */
- if(png_ptr == NULL) return;
+ if (png_ptr == NULL || ptr == NULL) return;
if (png_ptr->offset_table != NULL)
{
@@ -349,9 +345,9 @@ png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
png_voidp struct_ptr;
if (type == PNG_STRUCT_INFO)
- size = sizeof(png_info);
+ size = png_sizeof(png_info);
else if (type == PNG_STRUCT_PNG)
- size = sizeof(png_struct);
+ size = png_sizeof(png_struct);
else
return (NULL);
@@ -368,7 +364,15 @@ png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
}
#endif /* PNG_USER_MEM_SUPPORTED */
- struct_ptr = (png_voidp)png_mem_alloc(size);
+#if defined(__TURBOC__) && !defined(__FLAT__)
+ struct_ptr = (png_voidp)farmalloc(size);
+#else
+# if defined(_MSC_VER) && defined(MAXSEG_64K)
+ struct_ptr = (png_voidp)halloc(size, 1);
+# else
+ struct_ptr = (png_voidp)malloc(size);
+# endif
+#endif
if (struct_ptr != NULL)
png_memset(struct_ptr, 0, size);
@@ -393,7 +397,7 @@ png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
if (struct_ptr != NULL)
{
#ifdef PNG_USER_MEM_SUPPORTED
- if(free_fn != NULL)
+ if (free_fn != NULL)
{
png_struct dummy_struct;
png_structp png_ptr = &dummy_struct;
@@ -402,7 +406,15 @@ png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
return;
}
#endif /* PNG_USER_MEM_SUPPORTED */
- png_mem_free(struct_ptr);
+#if defined(__TURBOC__) && !defined(__FLAT__)
+ farfree(struct_ptr);
+#else
+# if defined(_MSC_VER) && defined(MAXSEG_64K)
+ hfree(struct_ptr);
+# else
+ free(struct_ptr);
+# endif
+#endif
}
}
@@ -422,11 +434,11 @@ png_malloc(png_structp png_ptr, png_alloc_size_t size)
return (NULL);
if (png_ptr->malloc_fn != NULL)
- ret = (*(png_ptr->malloc_fn))(png_ptr, size);
+ ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
else
- ret = png_malloc_default(png_ptr, size);
+ ret = (png_malloc_default(png_ptr, size));
if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
- png_error(png_ptr, "Out of Memory!");
+ png_error(png_ptr, "Out of Memory");
return (ret);
}
@@ -440,10 +452,10 @@ png_malloc_default(png_structp png_ptr, png_alloc_size_t size)
return (NULL);
#ifdef PNG_MAX_MALLOC_64K
- if (size > (png_alloc_size_t)65536L)
+ if (size > (png_uint_32)65536L)
{
#ifndef PNG_USER_MEM_SUPPORTED
- if(png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
+ if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
png_error(png_ptr, "Cannot Allocate > 64K");
else
#endif
@@ -451,7 +463,25 @@ png_malloc_default(png_structp png_ptr, png_alloc_size_t size)
}
#endif
- ret = png_mem_alloc(size);
+ /* Check for overflow */
+#if defined(__TURBOC__) && !defined(__FLAT__)
+ if (size != (unsigned long)size)
+ ret = NULL;
+ else
+ ret = farmalloc(size);
+#else
+# if defined(_MSC_VER) && defined(MAXSEG_64K)
+ if (size != (unsigned long)size)
+ ret = NULL;
+ else
+ ret = halloc(size, 1);
+# else
+ if (size != (size_t)size)
+ ret = NULL;
+ else
+ ret = malloc((size_t)size);
+# endif
+#endif
#ifndef PNG_USER_MEM_SUPPORTED
if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
@@ -484,7 +514,16 @@ png_free_default(png_structp png_ptr, png_voidp ptr)
return;
#endif /* PNG_USER_MEM_SUPPORTED */
- png_mem_free(ptr);
+
+#if defined(__TURBOC__) && !defined(__FLAT__)
+ farfree(ptr);
+#else
+# if defined(_MSC_VER) && defined(MAXSEG_64K)
+ hfree(ptr);
+# else
+ free(ptr);
+# endif
+#endif
}
#endif /* Not Borland DOS special memory handler */
@@ -499,7 +538,7 @@ png_malloc_warn(png_structp png_ptr, png_alloc_size_t size)
{
png_voidp ptr;
png_uint_32 save_flags;
- if(png_ptr == NULL) return (NULL);
+ if (png_ptr == NULL) return (NULL);
save_flags=png_ptr->flags;
png_ptr->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
@@ -508,6 +547,7 @@ png_malloc_warn(png_structp png_ptr, png_alloc_size_t size)
return(ptr);
}
+
#ifdef PNG_USER_MEM_SUPPORTED
/* This function is called when the application wants to use another method
* of allocating and freeing memory.
@@ -516,7 +556,7 @@ void PNGAPI
png_set_mem_fn(png_structp png_ptr, png_voidp mem_ptr, png_malloc_ptr
malloc_fn, png_free_ptr free_fn)
{
- if(png_ptr != NULL) {
+ if (png_ptr != NULL) {
png_ptr->mem_ptr = mem_ptr;
png_ptr->malloc_fn = malloc_fn;
png_ptr->free_fn = free_fn;
@@ -530,9 +570,8 @@ png_set_mem_fn(png_structp png_ptr, png_voidp mem_ptr, png_malloc_ptr
png_voidp PNGAPI
png_get_mem_ptr(png_structp png_ptr)
{
- if(png_ptr == NULL) return (NULL);
+ if (png_ptr == NULL) return (NULL);
return ((png_voidp)png_ptr->mem_ptr);
}
#endif /* PNG_USER_MEM_SUPPORTED */
-
#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
diff --git a/pngpread.c b/pngpread.c
index 9e9ac63d3..8ccd71309 100644
--- a/pngpread.c
+++ b/pngpread.c
@@ -1,17 +1,16 @@
/* pngpread.c - read a png file in push mode
*
- * Last changed in libpng 1.4.0 May 15, 2007
+ * Last changed in libpng 1.4.0 [July 10, 2008]
* For conditions of distribution and use, see copyright notice in png.h
- * Copyright (c) 1998-2007 Glenn Randers-Pehrson
+ * Copyright (c) 1998-2008 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*/
#include "png.h"
-#include "pngpriv.h"
-
#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
+#include "pngpriv.h"
/* push model modes */
#define PNG_READ_SIG_MODE 0
@@ -28,7 +27,7 @@ void PNGAPI
png_process_data(png_structp png_ptr, png_infop info_ptr,
png_bytep buffer, png_size_t buffer_size)
{
- if(png_ptr == NULL) return;
+ if (png_ptr == NULL || info_ptr == NULL) return;
png_push_restore_buffer(png_ptr, buffer, buffer_size);
while (png_ptr->buffer_size)
@@ -43,7 +42,7 @@ png_process_data(png_structp png_ptr, png_infop info_ptr,
void /* PRIVATE */
png_process_some_data(png_structp png_ptr, png_infop info_ptr)
{
- if(png_ptr == NULL) return;
+ if (png_ptr == NULL) return;
switch (png_ptr->process_mode)
{
case PNG_READ_SIG_MODE:
@@ -114,7 +113,7 @@ png_push_read_sig(png_structp png_ptr, png_infop info_ptr)
png_push_fill_buffer(png_ptr, &(info_ptr->signature[num_checked]),
num_to_check);
- png_ptr->sig_bytes = (png_byte)(png_ptr->sig_bytes+num_to_check);
+ png_ptr->sig_bytes = (png_byte)(png_ptr->sig_bytes + num_to_check);
if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
{
@@ -137,60 +136,60 @@ void /* PRIVATE */
png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
{
#ifdef PNG_USE_LOCAL_ARRAYS
- PNG_IHDR;
- PNG_IDAT;
- PNG_IEND;
- PNG_PLTE;
+ PNG_CONST PNG_IHDR;
+ PNG_CONST PNG_IDAT;
+ PNG_CONST PNG_IEND;
+ PNG_CONST PNG_PLTE;
#if defined(PNG_READ_bKGD_SUPPORTED)
- PNG_bKGD;
+ PNG_CONST PNG_bKGD;
#endif
#if defined(PNG_READ_cHRM_SUPPORTED)
- PNG_cHRM;
+ PNG_CONST PNG_cHRM;
#endif
#if defined(PNG_READ_gAMA_SUPPORTED)
- PNG_gAMA;
+ PNG_CONST PNG_gAMA;
#endif
#if defined(PNG_READ_hIST_SUPPORTED)
- PNG_hIST;
+ PNG_CONST PNG_hIST;
#endif
#if defined(PNG_READ_iCCP_SUPPORTED)
- PNG_iCCP;
+ PNG_CONST PNG_iCCP;
#endif
#if defined(PNG_READ_iTXt_SUPPORTED)
- PNG_iTXt;
+ PNG_CONST PNG_iTXt;
#endif
#if defined(PNG_READ_oFFs_SUPPORTED)
- PNG_oFFs;
+ PNG_CONST PNG_oFFs;
#endif
#if defined(PNG_READ_pCAL_SUPPORTED)
- PNG_pCAL;
+ PNG_CONST PNG_pCAL;
#endif
#if defined(PNG_READ_pHYs_SUPPORTED)
- PNG_pHYs;
+ PNG_CONST PNG_pHYs;
#endif
#if defined(PNG_READ_sBIT_SUPPORTED)
- PNG_sBIT;
+ PNG_CONST PNG_sBIT;
#endif
#if defined(PNG_READ_sCAL_SUPPORTED)
- PNG_sCAL;
+ PNG_CONST PNG_sCAL;
#endif
#if defined(PNG_READ_sRGB_SUPPORTED)
- PNG_sRGB;
+ PNG_CONST PNG_sRGB;
#endif
#if defined(PNG_READ_sPLT_SUPPORTED)
- PNG_sPLT;
+ PNG_CONST PNG_sPLT;
#endif
#if defined(PNG_READ_tEXt_SUPPORTED)
- PNG_tEXt;
+ PNG_CONST PNG_tEXt;
#endif
#if defined(PNG_READ_tIME_SUPPORTED)
- PNG_tIME;
+ PNG_CONST PNG_tIME;
#endif
#if defined(PNG_READ_tRNS_SUPPORTED)
- PNG_tRNS;
+ PNG_CONST PNG_tRNS;
#endif
#if defined(PNG_READ_zTXt_SUPPORTED)
- PNG_zTXt;
+ PNG_CONST PNG_zTXt;
#endif
#endif /* PNG_USE_LOCAL_ARRAYS */
/* First we make sure we have enough data for the 4 byte chunk name
@@ -210,20 +209,22 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
}
png_push_fill_buffer(png_ptr, chunk_length, 4);
- png_ptr->push_length = png_get_uint_31(png_ptr,chunk_length);
+ png_ptr->push_length = png_get_uint_31(png_ptr, chunk_length);
png_reset_crc(png_ptr);
png_crc_read(png_ptr, png_ptr->chunk_name, 4);
png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
}
if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
- if(png_ptr->mode & PNG_AFTER_IDAT)
+ if (png_ptr->mode & PNG_AFTER_IDAT)
png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
{
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
{
+ if (png_ptr->push_length != 13)
+ png_error(png_ptr, "Invalid IHDR length");
png_push_save_buffer(png_ptr);
return;
}
@@ -292,7 +293,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
return;
if (png_ptr->mode & PNG_AFTER_IDAT)
- png_benign_error(png_ptr, "Too many IDAT's found");
+ png_benign_error(png_ptr, "Too many IDATs found");
}
png_ptr->idat_size = png_ptr->push_length;
@@ -563,7 +564,7 @@ png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length)
{
png_bytep ptr;
- if(png_ptr == NULL) return;
+ if (png_ptr == NULL) return;
ptr = buffer;
if (png_ptr->save_buffer_size)
{
@@ -604,7 +605,7 @@ png_push_save_buffer(png_structp png_ptr)
{
if (png_ptr->save_buffer_ptr != png_ptr->save_buffer)
{
- png_size_t i,istop;
+ png_size_t i, istop;
png_bytep sp;
png_bytep dp;
@@ -629,7 +630,8 @@ png_push_save_buffer(png_structp png_ptr)
}
new_max = png_ptr->save_buffer_size + png_ptr->current_buffer_size + 256;
old_buffer = png_ptr->save_buffer;
- png_ptr->save_buffer = (png_bytep)png_malloc(png_ptr, new_max);
+ png_ptr->save_buffer = (png_bytep)png_malloc(png_ptr,
+ (png_size_t)new_max);
png_memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size);
png_free(png_ptr, old_buffer);
png_ptr->save_buffer_max = new_max;
@@ -659,7 +661,7 @@ void /* PRIVATE */
png_push_read_IDAT(png_structp png_ptr)
{
#ifdef PNG_USE_LOCAL_ARRAYS
- PNG_IDAT;
+ PNG_CONST PNG_IDAT;
#endif
if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
{
@@ -672,7 +674,7 @@ png_push_read_IDAT(png_structp png_ptr)
}
png_push_fill_buffer(png_ptr, chunk_length, 4);
- png_ptr->push_length = png_get_uint_31(png_ptr,chunk_length);
+ png_ptr->push_length = png_get_uint_31(png_ptr, chunk_length);
png_reset_crc(png_ptr);
png_crc_read(png_ptr, png_ptr->chunk_name, 4);
png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
@@ -695,7 +697,7 @@ png_push_read_IDAT(png_structp png_ptr)
{
save_size = (png_size_t)png_ptr->idat_size;
/* check for overflow */
- if((png_uint_32)save_size != png_ptr->idat_size)
+ if ((png_uint_32)save_size != png_ptr->idat_size)
png_error(png_ptr, "save_size overflowed in pngpread");
}
else
@@ -717,7 +719,7 @@ png_push_read_IDAT(png_structp png_ptr)
{
save_size = (png_size_t)png_ptr->idat_size;
/* check for overflow */
- if((png_uint_32)save_size != png_ptr->idat_size)
+ if ((png_uint_32)save_size != png_ptr->idat_size)
png_error(png_ptr, "save_size overflowed in pngpread");
}
else
@@ -757,7 +759,7 @@ png_process_IDAT_data(png_structp png_ptr, png_bytep buffer,
png_ptr->zstream.next_in = buffer;
png_ptr->zstream.avail_in = (uInt)buffer_length;
- for(;;)
+ for (;;)
{
ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
if (ret != Z_OK)
@@ -988,25 +990,20 @@ png_read_push_finish_row(png_structp png_ptr)
/* arrays to facilitate easy interlacing - use pass (0 - 6) as index */
/* start of interlace block */
- const int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
+ PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
/* offset to next interlace block */
- const int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
+ PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
/* start of interlace block in the y direction */
- const int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
+ PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
/* offset to next interlace block in the y direction */
- const int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
-
- /* Width of interlace block. This is not currently used - if you need
- * it, uncomment it here and in png.h
- const int FARDATA png_pass_width[] = {8, 4, 4, 2, 2, 1, 1};
- */
+ PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
/* Height of interlace block. This is not currently used - if you need
* it, uncomment it here and in png.h
- const int FARDATA png_pass_height[] = {8, 8, 4, 4, 2, 2, 1};
+ PNG_CONST int FARDATA png_pass_height[] = {8, 8, 4, 4, 2, 2, 1};
*/
#endif
@@ -1059,8 +1056,7 @@ png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
{
png_error(png_ptr, "Out of place tEXt");
- /* to quiet some compiler warnings */
- if(info_ptr == NULL) return;
+ info_ptr = info_ptr; /* to quiet some compiler warnings */
}
#ifdef PNG_MAX_MALLOC_64K
@@ -1123,10 +1119,11 @@ png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr)
for (text = key; *text; text++)
/* empty loop */ ;
- if (text != key + png_ptr->current_text_size)
+ if (text < key + png_ptr->current_text_size)
text++;
- text_ptr = (png_textp)png_malloc(png_ptr, sizeof(png_text));
+ text_ptr = (png_textp)png_malloc(png_ptr,
+ png_sizeof(png_text));
text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
text_ptr->key = key;
#ifdef PNG_iTXt_SUPPORTED
@@ -1155,8 +1152,7 @@ png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
{
png_error(png_ptr, "Out of place zTXt");
- /* to quiet some compiler warnings */
- if(info_ptr == NULL) return;
+ info_ptr = info_ptr; /* to quiet some compiler warnings */
}
#ifdef PNG_MAX_MALLOC_64K
@@ -1173,7 +1169,7 @@ png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
#endif
png_ptr->current_text = (png_charp)png_malloc(png_ptr,
- (png_size_t)(length+1));
+ (png_size_t)(length + 1));
png_ptr->current_text[length] = '\0';
png_ptr->current_text_ptr = png_ptr->current_text;
png_ptr->current_text_size = (png_size_t)length;
@@ -1218,7 +1214,7 @@ png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
/* empty loop */ ;
/* zTXt can't have zero text */
- if (text == key + png_ptr->current_text_size)
+ if (text >= key + png_ptr->current_text_size)
{
png_ptr->current_text = NULL;
png_free(png_ptr, key);
@@ -1264,8 +1260,8 @@ png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
if (text == NULL)
{
text = (png_charp)png_malloc(png_ptr,
- png_ptr->zbuf_size - png_ptr->zstream.avail_out
- + key_size + 1);
+ (png_ptr->zbuf_size
+ - png_ptr->zstream.avail_out + key_size + 1));
png_memcpy(text + key_size, png_ptr->zbuf,
png_ptr->zbuf_size - png_ptr->zstream.avail_out);
png_memcpy(text, key, key_size);
@@ -1279,7 +1275,8 @@ png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
tmp = text;
text = (png_charp)png_malloc(png_ptr, text_size +
- png_ptr->zbuf_size - png_ptr->zstream.avail_out + 1);
+ (png_ptr->zbuf_size
+ - png_ptr->zstream.avail_out));
png_memcpy(text, tmp, text_size);
png_free(png_ptr, tmp);
png_memcpy(text + text_size, png_ptr->zbuf,
@@ -1318,7 +1315,8 @@ png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
key = text;
text += key_size;
- text_ptr = (png_textp)png_malloc(png_ptr, sizeof(png_text));
+ text_ptr = (png_textp)png_malloc(png_ptr,
+ png_sizeof(png_text));
text_ptr->compression = PNG_TEXT_COMPRESSION_zTXt;
text_ptr->key = key;
#ifdef PNG_iTXt_SUPPORTED
@@ -1346,8 +1344,7 @@ png_push_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
{
png_error(png_ptr, "Out of place iTXt");
- /* to quiet some compiler warnings */
- if(info_ptr == NULL) return;
+ info_ptr = info_ptr; /* to quiet some compiler warnings */
}
#ifdef PNG_MAX_MALLOC_64K
@@ -1362,7 +1359,7 @@ png_push_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
#endif
png_ptr->current_text = (png_charp)png_malloc(png_ptr,
- (png_size_t)(length+1));
+ (png_size_t)(length + 1));
png_ptr->current_text[length] = '\0';
png_ptr->current_text_ptr = png_ptr->current_text;
png_ptr->current_text_size = (png_size_t)length;
@@ -1414,7 +1411,7 @@ png_push_read_iTXt(png_structp png_ptr, png_infop info_ptr)
for (lang = key; *lang; lang++)
/* empty loop */ ;
- if (lang != key + png_ptr->current_text_size)
+ if (lang < key + png_ptr->current_text_size - 3)
lang++;
comp_flag = *lang++;
@@ -1424,13 +1421,18 @@ png_push_read_iTXt(png_structp png_ptr, png_infop info_ptr)
/* empty loop */ ;
lang_key++; /* skip NUL separator */
- for (text = lang_key; *text; text++)
- /* empty loop */ ;
+ text=lang_key;
+ if (lang_key < key + png_ptr->current_text_size - 1)
+ {
+ for (; *text; text++)
+ /* empty loop */ ;
+ }
- if (text != key + png_ptr->current_text_size)
+ if (text < key + png_ptr->current_text_size)
text++;
- text_ptr = (png_textp)png_malloc(png_ptr, sizeof(png_text));
+ text_ptr = (png_textp)png_malloc(png_ptr,
+ png_sizeof(png_text));
text_ptr->compression = comp_flag + 2;
text_ptr->key = key;
text_ptr->lang = lang;
@@ -1464,55 +1466,67 @@ png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32
if (!(png_ptr->chunk_name[0] & 0x20))
{
#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
- if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
- PNG_HANDLE_CHUNK_ALWAYS
+ if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
+ PNG_HANDLE_CHUNK_ALWAYS
#if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
- && png_ptr->read_user_chunk_fn == NULL
+ && png_ptr->read_user_chunk_fn == NULL
#endif
)
#endif
png_chunk_error(png_ptr, "unknown critical chunk");
- /* to quiet compiler warnings about unused info_ptr */
- if (info_ptr == NULL)
- return;
+ info_ptr = info_ptr; /* to quiet some compiler warnings */
}
#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
if (png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS)
{
- png_unknown_chunk chunk;
-
#ifdef PNG_MAX_MALLOC_64K
- if (length > (png_uint_32)65535L)
- {
- png_warning(png_ptr, "unknown chunk too large to fit in memory");
- skip = length - (png_uint_32)65535L;
- length = (png_uint_32)65535L;
- }
+ if (length > (png_uint_32)65535L)
+ {
+ png_warning(png_ptr, "unknown chunk too large to fit in memory");
+ skip = length - (png_uint_32)65535L;
+ length = (png_uint_32)65535L;
+ }
#endif
-
- png_strcpy((png_charp)chunk.name, (png_charp)png_ptr->chunk_name);
- chunk.data = (png_bytep)png_malloc(png_ptr, length);
- png_crc_read(png_ptr, chunk.data, length);
- chunk.size = length;
+ png_memcpy((png_charp)png_ptr->unknown_chunk.name,
+ (png_charp)png_ptr->chunk_name,
+ png_sizeof(png_ptr->unknown_chunk.name));
+ png_ptr->unknown_chunk.name[png_sizeof(png_ptr->unknown_chunk.name)-1]='\0';
+
+ png_ptr->unknown_chunk.size = (png_size_t)length;
+ if (length == 0)
+ png_ptr->unknown_chunk.data = NULL;
+ else
+ {
+ png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr,
+ (png_size_t)length);
+ png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
+ }
#if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
- if(png_ptr->read_user_chunk_fn != NULL)
- {
- /* callback to user unknown chunk handler */
- if ((*(png_ptr->read_user_chunk_fn)) (png_ptr, &chunk) <= 0)
- {
- if (!(png_ptr->chunk_name[0] & 0x20))
- if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
- PNG_HANDLE_CHUNK_ALWAYS)
- png_chunk_error(png_ptr, "unknown critical chunk");
- }
- png_set_unknown_chunks(png_ptr, info_ptr, &chunk, 1);
- }
- else
+ if (png_ptr->read_user_chunk_fn != NULL)
+ {
+ /* callback to user unknown chunk handler */
+ int ret;
+ ret = (*(png_ptr->read_user_chunk_fn))
+ (png_ptr, &png_ptr->unknown_chunk);
+ if (ret < 0)
+ png_chunk_error(png_ptr, "error in user chunk");
+ if (ret == 0)
+ {
+ if (!(png_ptr->chunk_name[0] & 0x20))
+ if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
+ PNG_HANDLE_CHUNK_ALWAYS)
+ png_chunk_error(png_ptr, "unknown critical chunk");
+ png_set_unknown_chunks(png_ptr, info_ptr,
+ &png_ptr->unknown_chunk, 1);
+ }
+ }
+ else
#endif
- png_set_unknown_chunks(png_ptr, info_ptr, &chunk, 1);
- png_free(png_ptr, chunk.data);
+ png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
+ png_free(png_ptr, png_ptr->unknown_chunk.data);
+ png_ptr->unknown_chunk.data = NULL;
}
else
#endif
@@ -1546,11 +1560,11 @@ void PNGAPI
png_progressive_combine_row (png_structp png_ptr,
png_bytep old_row, png_bytep new_row)
{
- if(png_ptr == NULL) return;
#ifdef PNG_USE_LOCAL_ARRAYS
- const int FARDATA png_pass_dsp_mask[7] =
+ PNG_CONST int FARDATA png_pass_dsp_mask[7] =
{0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
#endif
+ if (png_ptr == NULL) return;
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]);
}
@@ -1560,7 +1574,7 @@ png_set_progressive_read_fn(png_structp png_ptr, png_voidp progressive_ptr,
png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
png_progressive_end_ptr end_fn)
{
- if(png_ptr == NULL) return;
+ if (png_ptr == NULL) return;
png_ptr->info_fn = info_fn;
png_ptr->row_fn = row_fn;
png_ptr->end_fn = end_fn;
@@ -1571,7 +1585,7 @@ png_set_progressive_read_fn(png_structp png_ptr, png_voidp progressive_ptr,
png_voidp PNGAPI
png_get_progressive_ptr(png_structp png_ptr)
{
- if(png_ptr == NULL) return (NULL);
+ if (png_ptr == NULL) return (NULL);
return png_ptr->io_ptr;
}
#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
diff --git a/pngpriv.h b/pngpriv.h
index 9dadad5a7..1d22ff23d 100644
--- a/pngpriv.h
+++ b/pngpriv.h
@@ -1,7 +1,7 @@
/* pngpriv.h - private declarations for use inside libpng
*
- * libpng version 1.4.0beta19 - May 15, 2007
+ * libpng version 1.4.0beta20 - July 10, 2008
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2007 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@@ -77,38 +77,6 @@
# endif
#endif
-/* This controls how fine the dithering gets. As this allocates
- * a largish chunk of memory (32K), those who are not as concerned
- * with dithering quality can decrease some or all of these.
- */
-#ifndef PNG_DITHER_RED_BITS
-# define PNG_DITHER_RED_BITS 5
-#endif
-#ifndef PNG_DITHER_GREEN_BITS
-# define PNG_DITHER_GREEN_BITS 5
-#endif
-#ifndef PNG_DITHER_BLUE_BITS
-# define PNG_DITHER_BLUE_BITS 5
-#endif
-
-/* This controls how fine the gamma correction becomes when you
- * are only interested in 8 bits anyway. Increasing this value
- * results in more memory being used, and more pow() functions
- * being called to fill in the gamma tables. Don't set this value
- * less then 8, and even that may not work (I haven't tested it).
- */
-
-#ifndef PNG_MAX_GAMMA_8
-# define PNG_MAX_GAMMA_8 11
-#endif
-
-/* This controls how much a difference in gamma we can tolerate before
- * we actually start doing gamma conversion.
- */
-#ifndef PNG_GAMMA_THRESHOLD
-# define PNG_GAMMA_THRESHOLD 0.05
-#endif
-
/* Various modes of operation. Note that after an init, mode is set to
* zero automatically when the structure is created.
*/
diff --git a/pngread.c b/pngread.c
index 9b51ade33..87c2b47d0 100644
--- a/pngread.c
+++ b/pngread.c
@@ -1,9 +1,9 @@
/* pngread.c - read a PNG file
*
- * Last changed in libpng 1.4.0 May 15, 2007
+ * Last changed in libpng 1.4.0 [July 10, 2008]
* For conditions of distribution and use, see copyright notice in png.h
- * Copyright (c) 1998-2007 Glenn Randers-Pehrson
+ * Copyright (c) 1998-2008 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*
@@ -12,9 +12,8 @@
*/
#include "png.h"
-#include "pngpriv.h"
-
#if defined(PNG_READ_SUPPORTED)
+#include "pngpriv.h"
/* Create a PNG structure for reading, and allocate any memory needed. */
png_structp PNGAPI
@@ -55,10 +54,6 @@ png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
if (png_ptr == NULL)
return (NULL);
-#ifdef PNG_MMX_CODE_SUPPORTED
- png_init_mmx_flags(png_ptr); /* 1.2.0 addition */
-#endif
-
/* added at libpng-1.2.6 */
#ifdef PNG_SET_USER_LIMITS_SUPPORTED
png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
@@ -83,7 +78,7 @@ png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
return (NULL);
}
#ifdef USE_FAR_KEYWORD
- png_memcpy(png_ptr->jmpbuf, jmpbuf, sizeof(jmp_buf));
+ png_memcpy(png_ptr->jmpbuf, jmpbuf, png_sizeof(jmp_buf));
#endif
#endif
@@ -93,12 +88,18 @@ png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
- i=0;
- do
+ if (user_png_ver)
{
- if(user_png_ver[i] != png_libpng_ver[i])
+ i=0;
+ do
+ {
+ if (user_png_ver[i] != png_libpng_ver[i])
+ png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
+ } while (png_libpng_ver[i++]);
+ }
+ else
png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
- } while (png_libpng_ver[i++]);
+
if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
{
@@ -111,15 +112,17 @@ png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
(user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
(user_png_ver[0] == '0' && user_png_ver[2] < '9'))
{
-#ifndef PNG_NO_STDIO
+#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
char msg[80];
if (user_png_ver)
{
- png_sprintf(msg, "Application was compiled with png.h from libpng-%.20s",
+ png_snprintf(msg, 80,
+ "Application was compiled with png.h from libpng-%.20s",
user_png_ver);
png_warning(png_ptr, msg);
}
- png_sprintf(msg, "Application is running with png.c from libpng-%.20s",
+ png_snprintf(msg, 80,
+ "Application is running with png.c from libpng-%.20s",
png_libpng_ver);
png_warning(png_ptr, msg);
#endif
@@ -133,7 +136,8 @@ png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
/* initialize zbuf - compression buffer */
png_ptr->zbuf_size = PNG_ZBUF_SIZE;
- png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, png_ptr->zbuf_size);
+ png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
+ png_ptr->zbuf_size);
png_ptr->zstream.zalloc = png_zalloc;
png_ptr->zstream.zfree = png_zfree;
png_ptr->zstream.opaque = (voidpf)png_ptr;
@@ -159,7 +163,7 @@ png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
#ifdef USE_FAR_KEYWORD
if (setjmp(jmpbuf))
PNG_ABORT();
- png_memcpy(png_ptr->jmpbuf, jmpbuf, sizeof(jmp_buf));
+ png_memcpy(png_ptr->jmpbuf, jmpbuf, png_sizeof(jmp_buf));
#else
if (setjmp(png_ptr->jmpbuf))
PNG_ABORT();
@@ -181,7 +185,7 @@ png_read_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
png_structp png_ptr=*ptr_ptr;
- if(png_ptr == NULL) return;
+ if (png_ptr == NULL) return;
do
{
@@ -202,10 +206,10 @@ png_read_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
#ifdef PNG_SETJMP_SUPPORTED
/* save jump buffer and error functions */
- png_memcpy(tmp_jmp, png_ptr->jmpbuf, sizeof(jmp_buf));
+ png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof(jmp_buf));
#endif
- if (sizeof(png_struct) > png_struct_size)
+ if (png_sizeof(png_struct) > png_struct_size)
{
png_destroy_struct(png_ptr);
*ptr_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
@@ -213,11 +217,11 @@ png_read_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
}
/* reset all variables to 0 */
- png_memset(png_ptr, 0, sizeof(png_struct));
+ png_memset(png_ptr, 0, png_sizeof(png_struct));
#ifdef PNG_SETJMP_SUPPORTED
/* restore jump buffer */
- png_memcpy(png_ptr->jmpbuf, tmp_jmp, sizeof(jmp_buf));
+ png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof(jmp_buf));
#endif
/* added at libpng-1.2.6 */
@@ -228,7 +232,8 @@ png_read_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
/* initialize zbuf - compression buffer */
png_ptr->zbuf_size = PNG_ZBUF_SIZE;
- png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, png_ptr->zbuf_size);
+ png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
+ png_ptr->zbuf_size);
png_ptr->zstream.zalloc = png_zalloc;
png_ptr->zstream.zfree = png_zfree;
png_ptr->zstream.opaque = (voidpf)png_ptr;
@@ -260,7 +265,7 @@ png_read_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
void PNGAPI
png_read_info(png_structp png_ptr, png_infop info_ptr)
{
- if(png_ptr == NULL) return;
+ if (png_ptr == NULL || info_ptr == NULL) return;
png_debug(1, "in png_read_info\n");
/* If we haven't checked all of the PNG signature bytes, do so now. */
if (png_ptr->sig_bytes < 8)
@@ -271,6 +276,7 @@ png_read_info(png_structp png_ptr, png_infop info_ptr)
#ifdef PNG_IO_STATE_SUPPORTED
png_ptr->io_state = PNG_IO_READING | PNG_IO_SIGNATURE;
#endif
+
png_read_data(png_ptr, &(info_ptr->signature[num_checked]), num_to_check);
png_ptr->sig_bytes = 8;
@@ -286,63 +292,63 @@ png_read_info(png_structp png_ptr, png_infop info_ptr)
png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
}
- for(;;)
+ for (;;)
{
#ifdef PNG_USE_LOCAL_ARRAYS
- PNG_IHDR;
- PNG_IDAT;
- PNG_IEND;
- PNG_PLTE;
+ PNG_CONST PNG_IHDR;
+ PNG_CONST PNG_IDAT;
+ PNG_CONST PNG_IEND;
+ PNG_CONST PNG_PLTE;
#if defined(PNG_READ_bKGD_SUPPORTED)
- PNG_bKGD;
+ PNG_CONST PNG_bKGD;
#endif
#if defined(PNG_READ_cHRM_SUPPORTED)
- PNG_cHRM;
+ PNG_CONST PNG_cHRM;
#endif
#if defined(PNG_READ_gAMA_SUPPORTED)
- PNG_gAMA;
+ PNG_CONST PNG_gAMA;
#endif
#if defined(PNG_READ_hIST_SUPPORTED)
- PNG_hIST;
+ PNG_CONST PNG_hIST;
#endif
#if defined(PNG_READ_iCCP_SUPPORTED)
- PNG_iCCP;
+ PNG_CONST PNG_iCCP;
#endif
#if defined(PNG_READ_iTXt_SUPPORTED)
- PNG_iTXt;
+ PNG_CONST PNG_iTXt;
#endif
#if defined(PNG_READ_oFFs_SUPPORTED)
- PNG_oFFs;
+ PNG_CONST PNG_oFFs;
#endif
#if defined(PNG_READ_pCAL_SUPPORTED)
- PNG_pCAL;
+ PNG_CONST PNG_pCAL;
#endif
#if defined(PNG_READ_pHYs_SUPPORTED)
- PNG_pHYs;
+ PNG_CONST PNG_pHYs;
#endif
#if defined(PNG_READ_sBIT_SUPPORTED)
- PNG_sBIT;
+ PNG_CONST PNG_sBIT;
#endif
#if defined(PNG_READ_sCAL_SUPPORTED)
- PNG_sCAL;
+ PNG_CONST PNG_sCAL;
#endif
#if defined(PNG_READ_sPLT_SUPPORTED)
- PNG_sPLT;
+ PNG_CONST PNG_sPLT;
#endif
#if defined(PNG_READ_sRGB_SUPPORTED)
- PNG_sRGB;
+ PNG_CONST PNG_sRGB;
#endif
#if defined(PNG_READ_tEXt_SUPPORTED)
- PNG_tEXt;
+ PNG_CONST PNG_tEXt;
#endif
#if defined(PNG_READ_tIME_SUPPORTED)
- PNG_tIME;
+ PNG_CONST PNG_tIME;
#endif
#if defined(PNG_READ_tRNS_SUPPORTED)
- PNG_tRNS;
+ PNG_CONST PNG_tRNS;
#endif
#if defined(PNG_READ_zTXt_SUPPORTED)
- PNG_zTXt;
+ PNG_CONST PNG_zTXt;
#endif
#endif /* PNG_USE_LOCAL_ARRAYS */
png_uint_32 length = png_read_chunk_header(png_ptr);
@@ -471,7 +477,7 @@ void PNGAPI
png_read_update_info(png_structp png_ptr, png_infop info_ptr)
{
png_debug(1, "in png_read_update_info\n");
- if(png_ptr == NULL) return;
+ if (png_ptr == NULL) return;
if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
png_read_start_row(png_ptr);
else
@@ -490,7 +496,7 @@ void PNGAPI
png_start_read_image(png_structp png_ptr)
{
png_debug(1, "in png_start_read_image\n");
- if(png_ptr == NULL) return;
+ if (png_ptr == NULL) return;
if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
png_read_start_row(png_ptr);
}
@@ -501,12 +507,13 @@ void PNGAPI
png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
{
#ifdef PNG_USE_LOCAL_ARRAYS
- PNG_IDAT;
- const int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
- const int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
+ PNG_CONST PNG_IDAT;
+ PNG_CONST int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55,
+ 0xff};
+ PNG_CONST int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
#endif
int ret;
- if(png_ptr == NULL) return;
+ if (png_ptr == NULL) return;
png_debug2(1, "in png_read_row (row %lu, pass %d)\n",
(unsigned long) png_ptr->row_number, png_ptr->pass);
if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
@@ -670,7 +677,7 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
png_ptr->row_info.width);
- if(png_ptr->row_buf[0])
+ if (png_ptr->row_buf[0])
png_read_filter_row(png_ptr, &(png_ptr->row_info),
png_ptr->row_buf + 1, png_ptr->prev_row + 1,
(int)(png_ptr->row_buf[0]));
@@ -678,7 +685,7 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
png_memcpy(png_ptr->prev_row, png_ptr->row_buf, png_ptr->rowbytes + 1);
#if defined(PNG_MNG_FEATURES_SUPPORTED)
- if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
+ if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
(png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
{
/* Intrapixel differencing */
@@ -686,6 +693,7 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
}
#endif
+
if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
png_do_read_transformations(png_ptr);
@@ -757,7 +765,7 @@ png_read_rows(png_structp png_ptr, png_bytepp row,
png_bytepp dp;
png_debug(1, "in png_read_rows\n");
- if(png_ptr == NULL) return;
+ if (png_ptr == NULL) return;
rp = row;
dp = display_row;
if (rp != NULL && dp != NULL)
@@ -768,14 +776,14 @@ png_read_rows(png_structp png_ptr, png_bytepp row,
png_read_row(png_ptr, rptr, dptr);
}
- else if(rp != NULL)
+ else if (rp != NULL)
for (i = 0; i < num_rows; i++)
{
png_bytep rptr = *rp;
png_read_row(png_ptr, rptr, NULL);
rp++;
}
- else if(dp != NULL)
+ else if (dp != NULL)
for (i = 0; i < num_rows; i++)
{
png_bytep dptr = *dp;
@@ -801,12 +809,12 @@ png_read_rows(png_structp png_ptr, png_bytepp row,
void PNGAPI
png_read_image(png_structp png_ptr, png_bytepp image)
{
- png_uint_32 i,image_height;
+ png_uint_32 i, image_height;
int pass, j;
png_bytepp rp;
png_debug(1, "in png_read_image\n");
- if(png_ptr == NULL) return;
+ if (png_ptr == NULL) return;
#ifdef PNG_READ_INTERLACING_SUPPORTED
pass = png_set_interlace_handling(png_ptr);
@@ -817,6 +825,7 @@ png_read_image(png_structp png_ptr, png_bytepp image)
pass = 1;
#endif
+
image_height=png_ptr->height;
png_ptr->num_rows = image_height; /* Make sure this is set correctly */
@@ -844,69 +853,68 @@ png_read_end(png_structp png_ptr, png_infop info_ptr)
png_uint_32 length;
png_debug(1, "in png_read_end\n");
- if(png_ptr == NULL) return;
+ if (png_ptr == NULL) return;
png_crc_finish(png_ptr, 0); /* Finish off CRC from last IDAT chunk */
do
{
#ifdef PNG_USE_LOCAL_ARRAYS
- PNG_IHDR;
- PNG_IDAT;
- PNG_IEND;
- PNG_PLTE;
+ PNG_CONST PNG_IHDR;
+ PNG_CONST PNG_IDAT;
+ PNG_CONST PNG_IEND;
+ PNG_CONST PNG_PLTE;
#if defined(PNG_READ_bKGD_SUPPORTED)
- PNG_bKGD;
+ PNG_CONST PNG_bKGD;
#endif
#if defined(PNG_READ_cHRM_SUPPORTED)
- PNG_cHRM;
+ PNG_CONST PNG_cHRM;
#endif
#if defined(PNG_READ_gAMA_SUPPORTED)
- PNG_gAMA;
+ PNG_CONST PNG_gAMA;
#endif
#if defined(PNG_READ_hIST_SUPPORTED)
- PNG_hIST;
+ PNG_CONST PNG_hIST;
#endif
#if defined(PNG_READ_iCCP_SUPPORTED)
- PNG_iCCP;
+ PNG_CONST PNG_iCCP;
#endif
#if defined(PNG_READ_iTXt_SUPPORTED)
- PNG_iTXt;
+ PNG_CONST PNG_iTXt;
#endif
#if defined(PNG_READ_oFFs_SUPPORTED)
- PNG_oFFs;
+ PNG_CONST PNG_oFFs;
#endif
#if defined(PNG_READ_pCAL_SUPPORTED)
- PNG_pCAL;
+ PNG_CONST PNG_pCAL;
#endif
#if defined(PNG_READ_pHYs_SUPPORTED)
- PNG_pHYs;
+ PNG_CONST PNG_pHYs;
#endif
#if defined(PNG_READ_sBIT_SUPPORTED)
- PNG_sBIT;
+ PNG_CONST PNG_sBIT;
#endif
#if defined(PNG_READ_sCAL_SUPPORTED)
- PNG_sCAL;
+ PNG_CONST PNG_sCAL;
#endif
#if defined(PNG_READ_sPLT_SUPPORTED)
- PNG_sPLT;
+ PNG_CONST PNG_sPLT;
#endif
#if defined(PNG_READ_sRGB_SUPPORTED)
- PNG_sRGB;
+ PNG_CONST PNG_sRGB;
#endif
#if defined(PNG_READ_tEXt_SUPPORTED)
- PNG_tEXt;
+ PNG_CONST PNG_tEXt;
#endif
#if defined(PNG_READ_tIME_SUPPORTED)
- PNG_tIME;
+ PNG_CONST PNG_tIME;
#endif
#if defined(PNG_READ_tRNS_SUPPORTED)
- PNG_tRNS;
+ PNG_CONST PNG_tRNS;
#endif
#if defined(PNG_READ_zTXt_SUPPORTED)
- PNG_zTXt;
+ PNG_CONST PNG_zTXt;
#endif
#endif /* PNG_USE_LOCAL_ARRAYS */
-
length = png_read_chunk_header(png_ptr);
chunk_name = png_ptr->chunk_name;
@@ -920,7 +928,7 @@ png_read_end(png_structp png_ptr, png_infop info_ptr)
if (!png_memcmp(chunk_name, png_IDAT, 4))
{
if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
- png_benign_error(png_ptr, "Too many IDAT's found");
+ png_benign_error(png_ptr, "Too many IDATs found");
}
png_handle_unknown(png_ptr, info_ptr, length);
if (!png_memcmp(chunk_name, png_PLTE, 4))
@@ -933,7 +941,7 @@ png_read_end(png_structp png_ptr, png_infop info_ptr)
* read, but not after other chunks have been read.
*/
if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
- png_benign_error(png_ptr, "Too many IDAT's found");
+ png_benign_error(png_ptr, "Too many IDATs found");
png_crc_finish(png_ptr, length);
}
else if (!png_memcmp(chunk_name, png_PLTE, 4))
@@ -1020,13 +1028,20 @@ 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;
- png_voidp mem_ptr;
+ png_free_ptr free_fn = NULL;
+ png_voidp mem_ptr = NULL;
#endif
png_debug(1, "in png_destroy_read_struct\n");
if (png_ptr_ptr != NULL)
png_ptr = *png_ptr_ptr;
+ if (png_ptr == NULL)
+ return;
+
+#ifdef PNG_USER_MEM_SUPPORTED
+ free_fn = png_ptr->free_fn;
+ mem_ptr = png_ptr->mem_ptr;
+#endif
if (info_ptr_ptr != NULL)
info_ptr = *info_ptr_ptr;
@@ -1034,11 +1049,6 @@ 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;
- mem_ptr = png_ptr->mem_ptr;
-#endif
-
png_read_destroy(png_ptr, info_ptr, end_info_ptr);
if (info_ptr != NULL)
@@ -1202,7 +1212,7 @@ png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr
* being used again.
*/
#ifdef PNG_SETJMP_SUPPORTED
- png_memcpy(tmp_jmp, png_ptr->jmpbuf, sizeof(jmp_buf));
+ png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof(jmp_buf));
#endif
error_fn = png_ptr->error_fn;
@@ -1212,7 +1222,7 @@ png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr
free_fn = png_ptr->free_fn;
#endif
- png_memset(png_ptr, 0, sizeof(png_struct));
+ png_memset(png_ptr, 0, png_sizeof(png_struct));
png_ptr->error_fn = error_fn;
png_ptr->warning_fn = warning_fn;
@@ -1222,7 +1232,7 @@ png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr
#endif
#ifdef PNG_SETJMP_SUPPORTED
- png_memcpy(png_ptr->jmpbuf, tmp_jmp, sizeof(jmp_buf));
+ png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof(jmp_buf));
#endif
}
@@ -1230,7 +1240,7 @@ png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr
void PNGAPI
png_set_read_status_fn(png_structp png_ptr, png_read_status_ptr read_row_fn)
{
- if(png_ptr == NULL) return;
+ if (png_ptr == NULL) return;
png_ptr->read_row_fn = read_row_fn;
}
@@ -1244,7 +1254,7 @@ png_read_png(png_structp png_ptr, png_infop info_ptr,
{
int row;
- if(png_ptr == NULL) return;
+ if (png_ptr == NULL) return;
#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
/* invert the alpha channel from opacity to transparency
*/
@@ -1256,8 +1266,8 @@ png_read_png(png_structp png_ptr, png_infop info_ptr,
* PNG file before the first IDAT (image data chunk).
*/
png_read_info(png_ptr, info_ptr);
- if (info_ptr->height > PNG_UINT_32_MAX/sizeof(png_bytep))
- png_error(png_ptr,"Image is too high to process with png_read_png()");
+ if (info_ptr->height > PNG_UINT_32_MAX/png_sizeof(png_bytep))
+ png_error(png_ptr, "Image is too high to process with png_read_png()");
/* -------------- image transformations start here ------------------- */
@@ -1364,10 +1374,10 @@ png_read_png(png_structp png_ptr, png_infop info_ptr,
#ifdef PNG_FREE_ME_SUPPORTED
png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
#endif
- if(info_ptr->row_pointers == NULL)
+ if (info_ptr->row_pointers == NULL)
{
info_ptr->row_pointers = (png_bytepp)png_malloc(png_ptr,
- info_ptr->height * sizeof(png_bytep));
+ info_ptr->height * png_sizeof(png_bytep));
#ifdef PNG_FREE_ME_SUPPORTED
info_ptr->free_me |= PNG_FREE_ROWS;
#endif
@@ -1384,8 +1394,8 @@ png_read_png(png_structp png_ptr, png_infop info_ptr,
/* read rest of file, and get additional chunks in info_ptr - REQUIRED */
png_read_end(png_ptr, info_ptr);
- if(transforms == 0 || params == NULL)
- /* quiet compiler warnings */ return;
+ transforms = transforms; /* quiet compiler warnings */
+ params = params;
}
#endif /* PNG_INFO_IMAGE_SUPPORTED */
diff --git a/pngrio.c b/pngrio.c
index 4f67845e0..700382e8f 100644
--- a/pngrio.c
+++ b/pngrio.c
@@ -1,9 +1,9 @@
/* pngrio.c - functions for data input
*
- * Last changed in libpng 1.4.0 May 15, 2007
+ * Last changed in libpng 1.4.0 [July 10, 2008]
* For conditions of distribution and use, see copyright notice in png.h
- * Copyright (c) 1998-2007 Glenn Randers-Pehrson
+ * Copyright (c) 1998-2008 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*
@@ -16,9 +16,8 @@
*/
#include "png.h"
-#include "pngpriv.h"
-
#if defined(PNG_READ_SUPPORTED)
+#include "pngpriv.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
@@ -28,7 +27,7 @@
void /* PRIVATE */
png_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
{
- png_debug1(4,"reading %d bytes\n", (int)length);
+ png_debug1(4, "reading %d bytes\n", (int)length);
if (png_ptr->read_data_fn != NULL)
(*(png_ptr->read_data_fn))(png_ptr, data, length);
else
@@ -46,7 +45,7 @@ png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
{
png_size_t check;
- if(png_ptr == NULL) return;
+ if (png_ptr == NULL) return;
/* fread() returns 0 on error, so it is OK to store this in a png_size_t
* instead of an int, which is what fread() actually returns.
*/
@@ -71,7 +70,7 @@ png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
png_byte *n_data;
png_FILE_p io_ptr;
- if(png_ptr == NULL) return;
+ if (png_ptr == NULL) return;
/* Check if data really is near. If so, use usual code. */
n_data = (png_byte *)CVT_PTR_NOCHECK(data);
io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
@@ -90,7 +89,7 @@ png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
read = MIN(NEAR_BUF_SIZE, remaining);
err = fread(buf, 1, read, io_ptr);
png_memcpy(data, buf, read); /* copy far buffer to near buffer */
- if(err != read)
+ if (err != read)
break;
else
check += err;
@@ -122,7 +121,7 @@ void PNGAPI
png_set_read_fn(png_structp png_ptr, png_voidp io_ptr,
png_rw_ptr read_data_fn)
{
- if(png_ptr == NULL) return;
+ if (png_ptr == NULL) return;
png_ptr->io_ptr = io_ptr;
#if !defined(PNG_NO_STDIO)
diff --git a/pngrtran.c b/pngrtran.c
index 404394844..0792c5bfb 100644
--- a/pngrtran.c
+++ b/pngrtran.c
@@ -1,9 +1,9 @@
/* pngrtran.c - transforms the data in a row for PNG readers
*
- * Last changed in libpng 1.4.0 May 15, 2007
+ * Last changed in libpng 1.4.0 [July 10, 2008]
* For conditions of distribution and use, see copyright notice in png.h
- * Copyright (c) 1998-2007 Glenn Randers-Pehrson
+ * Copyright (c) 1998-2008 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*
@@ -14,9 +14,8 @@
*/
#include "png.h"
-#include "pngpriv.h"
-
#if defined(PNG_READ_SUPPORTED)
+#include "pngpriv.h"
/* Set the action on getting a CRC error for an ancillary or critical chunk. */
void PNGAPI
@@ -24,7 +23,7 @@ png_set_crc_action(png_structp png_ptr, int crit_action, int ancil_action)
{
png_debug(1, "in png_set_crc_action\n");
/* Tell libpng how we react to CRC errors in critical chunks */
- if(png_ptr == NULL) return;
+ if (png_ptr == NULL) return;
switch (crit_action)
{
case PNG_CRC_NO_CHANGE: /* leave setting as is */
@@ -39,7 +38,8 @@ png_set_crc_action(png_structp png_ptr, int crit_action, int ancil_action)
PNG_FLAG_CRC_CRITICAL_IGNORE;
break;
case PNG_CRC_WARN_DISCARD: /* not a valid action for critical data */
- png_warning(png_ptr, "Can't discard critical data on CRC error");
+ png_warning(png_ptr,
+ "Can't discard critical data on CRC error");
case PNG_CRC_ERROR_QUIT: /* error/quit */
case PNG_CRC_DEFAULT:
default:
@@ -81,7 +81,7 @@ png_set_background(png_structp png_ptr,
int need_expand, double background_gamma)
{
png_debug(1, "in png_set_background\n");
- if(png_ptr == NULL) return;
+ if (png_ptr == NULL) return;
if (background_gamma_code == PNG_BACKGROUND_GAMMA_UNKNOWN)
{
png_warning(png_ptr, "Application must supply a known background gamma");
@@ -89,21 +89,11 @@ png_set_background(png_structp png_ptr,
}
png_ptr->transformations |= PNG_BACKGROUND;
- png_memcpy(&(png_ptr->background), background_color, sizeof(png_color_16));
+ png_memcpy(&(png_ptr->background), background_color,
+ png_sizeof(png_color_16));
png_ptr->background_gamma = (float)background_gamma;
png_ptr->background_gamma_type = (png_byte)(background_gamma_code);
png_ptr->transformations |= (need_expand ? PNG_BACKGROUND_EXPAND : 0);
-
- /* Note: if need_expand is set and color_type is either RGB or RGB_ALPHA
- * (in which case need_expand is superfluous anyway), the background color
- * might actually be gray yet not be flagged as such. This is not a problem
- * for the current code, which uses PNG_BACKGROUND_IS_GRAY only to
- * decide when to do the png_do_gray_to_rgb() transformation.
- */
- if ((need_expand && !(png_ptr->color_type & PNG_COLOR_MASK_COLOR)) ||
- (!need_expand && background_color->red == background_color->green &&
- background_color->red == background_color->blue))
- png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
}
#endif
@@ -113,7 +103,7 @@ void PNGAPI
png_set_strip_16(png_structp png_ptr)
{
png_debug(1, "in png_set_strip_16\n");
- if(png_ptr == NULL) return;
+ if (png_ptr == NULL) return;
png_ptr->transformations |= PNG_16_TO_8;
}
#endif
@@ -123,7 +113,7 @@ void PNGAPI
png_set_strip_alpha(png_structp png_ptr)
{
png_debug(1, "in png_set_strip_alpha\n");
- if(png_ptr == NULL) return;
+ if (png_ptr == NULL) return;
png_ptr->flags |= PNG_FLAG_STRIP_ALPHA;
}
#endif
@@ -153,7 +143,7 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
int full_dither)
{
png_debug(1, "in png_set_dither\n");
- if(png_ptr == NULL) return;
+ if (png_ptr == NULL) return;
png_ptr->transformations |= PNG_DITHER;
if (!full_dither)
@@ -161,7 +151,7 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
int i;
png_ptr->dither_index = (png_bytep)png_malloc(png_ptr,
- (png_size_t)(num_palette * sizeof(png_byte)));
+ (png_uint_32)(num_palette * png_sizeof(png_byte)));
for (i = 0; i < num_palette; i++)
png_ptr->dither_index[i] = (png_byte)i;
}
@@ -177,7 +167,7 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
/* initialize an array to sort colors */
png_ptr->dither_sort = (png_bytep)png_malloc(png_ptr,
- (png_size_t)(num_palette * sizeof(png_byte)));
+ (png_uint_32)(num_palette * png_sizeof(png_byte)));
/* initialize the dither_sort array */
for (i = 0; i < num_palette; i++)
@@ -306,9 +296,9 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
/* initialize palette index arrays */
png_ptr->index_to_palette = (png_bytep)png_malloc(png_ptr,
- (png_size_t)(num_palette * sizeof(png_byte)));
+ (png_uint_32)(num_palette * png_sizeof(png_byte)));
png_ptr->palette_to_index = (png_bytep)png_malloc(png_ptr,
- (png_size_t)(num_palette * sizeof(png_byte)));
+ (png_uint_32)(num_palette * png_sizeof(png_byte)));
/* initialize the sort array */
for (i = 0; i < num_palette; i++)
@@ -317,11 +307,11 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
png_ptr->palette_to_index[i] = (png_byte)i;
}
- hash = (png_dsortpp)png_malloc(png_ptr,
- (png_size_t)(769 * sizeof(png_dsortp)));
+ hash = (png_dsortpp)png_malloc(png_ptr, (png_uint_32)(769 *
+ png_sizeof(png_dsortp)));
for (i = 0; i < 769; i++)
hash[i] = NULL;
-/* png_memset(hash, 0, 769 * sizeof(png_dsortp)); */
+/* png_memset(hash, 0, 769 * png_sizeof(png_dsortp)); */
num_new_palette = num_palette;
@@ -351,7 +341,7 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
{
t = (png_dsortp)png_malloc_warn(png_ptr,
- sizeof(png_dsort));
+ (png_uint_32)(png_sizeof(png_dsort)));
if (t == NULL)
break;
t->next = hash[d];
@@ -468,14 +458,16 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
int num_blue = (1 << PNG_DITHER_BLUE_BITS);
png_size_t num_entries = ((png_size_t)1 << total_bits);
- png_ptr->palette_lookup = (png_bytep)png_malloc(png_ptr,
- num_entries * sizeof(png_byte));
+ png_ptr->palette_lookup = (png_bytep )png_malloc(png_ptr,
+ (png_uint_32)(num_entries * png_sizeof(png_byte)));
- png_memset(png_ptr->palette_lookup, 0, num_entries * sizeof(png_byte));
+ png_memset(png_ptr->palette_lookup, 0, num_entries *
+ png_sizeof(png_byte));
- distance = (png_bytep)png_malloc(png_ptr, num_entries * sizeof(png_byte));
+ distance = (png_bytep)png_malloc(png_ptr, (png_uint_32)(num_entries *
+ png_sizeof(png_byte)));
- png_memset(distance, 0xff, num_entries * sizeof(png_byte));
+ png_memset(distance, 0xff, num_entries * png_sizeof(png_byte));
for (i = 0; i < num_palette; i++)
{
@@ -535,7 +527,7 @@ void PNGAPI
png_set_gamma(png_structp png_ptr, double scrn_gamma, double file_gamma)
{
png_debug(1, "in png_set_gamma\n");
- if(png_ptr == NULL) return;
+ if (png_ptr == NULL) return;
if ((fabs(scrn_gamma * file_gamma - 1.0) > PNG_GAMMA_THRESHOLD) ||
(png_ptr->color_type & PNG_COLOR_MASK_ALPHA) ||
(png_ptr->color_type == PNG_COLOR_TYPE_PALETTE))
@@ -554,8 +546,9 @@ void PNGAPI
png_set_expand(png_structp png_ptr)
{
png_debug(1, "in png_set_expand\n");
- if(png_ptr == NULL) return;
+ if (png_ptr == NULL) return;
png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
+ png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
}
/* GRR 19990627: the following three functions currently are identical
@@ -580,8 +573,9 @@ void PNGAPI
png_set_palette_to_rgb(png_structp png_ptr)
{
png_debug(1, "in png_set_palette_to_rgb\n");
- if(png_ptr == NULL) return;
+ if (png_ptr == NULL) return;
png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
+ png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
}
/* Expand grayscale images of less than 8-bit depth to 8 bits. */
@@ -589,16 +583,20 @@ void PNGAPI
png_set_expand_gray_1_2_4_to_8(png_structp png_ptr)
{
png_debug(1, "in png_set_expand_gray_1_2_4_to_8\n");
- if(png_ptr == NULL) return;
- png_ptr->transformations |= PNG_EXPAND_tRNS;
+ if (png_ptr == NULL) return;
+ png_ptr->transformations |= PNG_EXPAND;
+ png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
}
+
+
/* Expand tRNS chunks to alpha channels. */
void PNGAPI
png_set_tRNS_to_alpha(png_structp png_ptr)
{
- png_debug(1, "in png_set_expand\n");
+ png_debug(1, "in png_set_tRNS_to_alpha\n");
png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
+ png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
}
#endif /* defined(PNG_READ_EXPAND_SUPPORTED) */
@@ -608,6 +606,7 @@ png_set_gray_to_rgb(png_structp png_ptr)
{
png_debug(1, "in png_set_gray_to_rgb\n");
png_ptr->transformations |= PNG_GRAY_TO_RGB;
+ png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
}
#endif
@@ -623,7 +622,7 @@ png_set_rgb_to_gray(png_structp png_ptr, int error_action, double red,
{
int red_fixed = (int)((float)red*100000.0 + 0.5);
int green_fixed = (int)((float)green*100000.0 + 0.5);
- if(png_ptr == NULL) return;
+ if (png_ptr == NULL) return;
png_set_rgb_to_gray_fixed(png_ptr, error_action, red_fixed, green_fixed);
}
#endif
@@ -633,7 +632,7 @@ png_set_rgb_to_gray_fixed(png_structp png_ptr, int error_action,
png_fixed_point red, png_fixed_point green)
{
png_debug(1, "in png_set_rgb_to_gray\n");
- if(png_ptr == NULL) return;
+ if (png_ptr == NULL) return;
switch(error_action)
{
case 1: png_ptr->transformations |= PNG_RGB_TO_GRAY;
@@ -647,18 +646,19 @@ png_set_rgb_to_gray_fixed(png_structp png_ptr, int error_action,
png_ptr->transformations |= PNG_EXPAND;
#else
{
- png_warning(png_ptr, "Cannot do RGB_TO_GRAY without EXPAND_SUPPORTED");
+ png_warning(png_ptr,
+ "Cannot do RGB_TO_GRAY without EXPAND_SUPPORTED");
png_ptr->transformations &= ~PNG_RGB_TO_GRAY;
}
#endif
{
png_uint_16 red_int, green_int;
- if(red < 0 || green < 0)
+ if (red < 0 || green < 0)
{
red_int = 6968; /* .212671 * 32768 + .5 */
green_int = 23434; /* .715160 * 32768 + .5 */
}
- else if(red + green < 100000L)
+ else if (red + green < 100000L)
{
red_int = (png_uint_16)(((png_uint_32)red*32768L)/100000L);
green_int = (png_uint_16)(((png_uint_32)green*32768L)/100000L);
@@ -671,7 +671,8 @@ png_set_rgb_to_gray_fixed(png_structp png_ptr, int error_action,
}
png_ptr->rgb_to_gray_red_coeff = red_int;
png_ptr->rgb_to_gray_green_coeff = green_int;
- png_ptr->rgb_to_gray_blue_coeff = (png_uint_16)(32768-red_int-green_int);
+ png_ptr->rgb_to_gray_blue_coeff =
+ (png_uint_16)(32768 - red_int - green_int);
}
}
#endif
@@ -684,13 +685,13 @@ png_set_read_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
read_user_transform_fn)
{
png_debug(1, "in png_set_read_user_transform_fn\n");
- if(png_ptr == NULL) return;
+ if (png_ptr == NULL) return;
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
png_ptr->transformations |= PNG_USER_TRANSFORM;
png_ptr->read_user_transform_fn = read_user_transform_fn;
#endif
#ifdef PNG_LEGACY_SUPPORTED
- if(read_user_transform_fn)
+ if (read_user_transform_fn)
png_warning(png_ptr,
"This version of libpng does not support user transforms");
#endif
@@ -705,7 +706,7 @@ png_init_read_transformations(png_structp png_ptr)
{
png_debug(1, "in png_init_read_transformations\n");
#if defined(PNG_USELESS_TESTS_SUPPORTED)
- if(png_ptr != NULL)
+ if (png_ptr != NULL)
#endif
{
#if defined(PNG_READ_BACKGROUND_SUPPORTED) || defined(PNG_READ_SHIFT_SUPPORTED) \
@@ -714,6 +715,32 @@ png_init_read_transformations(png_structp png_ptr)
#endif
#if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED)
+
+#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
+ /* Detect gray background and attempt to enable optimization
+ * for gray --> RGB case */
+ /* Note: if PNG_BACKGROUND_EXPAND is set and color_type is either RGB or
+ * RGB_ALPHA (in which case need_expand is superfluous anyway), the
+ * background color might actually be gray yet not be flagged as such.
+ * This is not a problem for the current code, which uses
+ * PNG_BACKGROUND_IS_GRAY only to decide when to do the
+ * png_do_gray_to_rgb() transformation.
+ */
+ if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
+ !(color_type & PNG_COLOR_MASK_COLOR))
+ {
+ png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
+ } else if ((png_ptr->transformations & PNG_BACKGROUND) &&
+ !(png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
+ (png_ptr->transformations & PNG_GRAY_TO_RGB) &&
+ png_ptr->background.red == png_ptr->background.green &&
+ png_ptr->background.red == png_ptr->background.blue)
+ {
+ png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
+ png_ptr->background.gray = png_ptr->background.red;
+ }
+#endif
+
if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
(png_ptr->transformations & PNG_EXPAND))
{
@@ -780,7 +807,7 @@ png_init_read_transformations(png_structp png_ptr)
{
/* invert the alpha channel (in tRNS) unless the pixels are
going to be expanded, in which case leave it for later */
- int i,istop;
+ int i, istop;
istop=(int)png_ptr->num_trans;
for (i=0; i<istop; i++)
png_ptr->trans[i] = (png_byte)(255 - png_ptr->trans[i]);
@@ -801,7 +828,7 @@ png_init_read_transformations(png_structp png_ptr)
&& (fabs(png_ptr->screen_gamma * png_ptr->gamma - 1.0)
< PNG_GAMMA_THRESHOLD))
{
- int i,k;
+ int i, k;
k=0;
for (i=0; i<png_ptr->num_trans; i++)
{
@@ -809,7 +836,7 @@ png_init_read_transformations(png_structp png_ptr)
k=1; /* partial transparency is present */
}
if (k == 0)
- png_ptr->transformations &= (~PNG_GAMMA);
+ png_ptr->transformations &= ~PNG_GAMMA;
}
if ((png_ptr->transformations & (PNG_GAMMA | PNG_RGB_TO_GRAY)) &&
@@ -916,6 +943,14 @@ png_init_read_transformations(png_structp png_ptr)
palette[i].blue = png_ptr->gamma_table[palette[i].blue];
}
}
+ /* Prevent the transformations being done again, and make sure
+ * that the now spurious alpha channel is stripped - the code
+ * has just reduced background composition and gamma correction
+ * to a simple alpha channel strip.
+ */
+ png_ptr->transformations &= ~PNG_BACKGROUND;
+ png_ptr->transformations &= ~PNG_GAMMA;
+ png_ptr->transformations |= PNG_STRIP_ALPHA;
}
/* if (png_ptr->background_gamma_type!=PNG_BACKGROUND_GAMMA_UNKNOWN) */
else
@@ -990,6 +1025,9 @@ png_init_read_transformations(png_structp png_ptr)
palette[i].green = png_ptr->gamma_table[palette[i].green];
palette[i].blue = png_ptr->gamma_table[palette[i].blue];
}
+
+ /* Done the gamma correction. */
+ png_ptr->transformations &= ~PNG_GAMMA;
}
}
#if defined(PNG_READ_BACKGROUND_SUPPORTED)
@@ -1027,6 +1065,10 @@ png_init_read_transformations(png_structp png_ptr)
png_ptr->trans[i], back.blue);
}
}
+
+ /* Handled alpha, still need to strip the channel. */
+ png_ptr->transformations &= ~PNG_BACKGROUND;
+ png_ptr->transformations |= PNG_STRIP_ALPHA;
}
#endif /* PNG_READ_BACKGROUND_SUPPORTED */
@@ -1057,7 +1099,7 @@ png_init_read_transformations(png_structp png_ptr)
}
#if !defined(PNG_READ_GAMMA_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED) \
&& !defined(PNG_READ_BACKGROUND_SUPPORTED)
- if(png_ptr)
+ if (png_ptr)
return;
#endif
}
@@ -1075,7 +1117,8 @@ png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
{
if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
{
- if (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND_tRNS))
+ if (png_ptr->num_trans &&
+ (png_ptr->transformations & PNG_EXPAND_tRNS))
info_ptr->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
else
info_ptr->color_type = PNG_COLOR_TYPE_RGB;
@@ -1088,8 +1131,10 @@ png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
{
if (png_ptr->transformations & PNG_EXPAND_tRNS)
info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
+#if 0 /* Removed from libpng-1.2.27 */
else
info_ptr->color_type |= PNG_COLOR_MASK_COLOR;
+#endif
}
if (info_ptr->bit_depth < 8)
info_ptr->bit_depth = 8;
@@ -1181,11 +1226,11 @@ png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
#if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) && \
defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
- if(png_ptr->transformations & PNG_USER_TRANSFORM)
+ if (png_ptr->transformations & PNG_USER_TRANSFORM)
{
- if(info_ptr->bit_depth < png_ptr->user_transform_depth)
+ if (info_ptr->bit_depth < png_ptr->user_transform_depth)
info_ptr->bit_depth = png_ptr->user_transform_depth;
- if(info_ptr->channels < png_ptr->user_transform_channels)
+ if (info_ptr->channels < png_ptr->user_transform_channels)
info_ptr->channels = png_ptr->user_transform_channels;
}
#endif
@@ -1193,10 +1238,10 @@ defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
info_ptr->pixel_depth = (png_byte)(info_ptr->channels *
info_ptr->bit_depth);
- info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,info_ptr->width);
+ info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, info_ptr->width);
#if !defined(PNG_READ_EXPAND_SUPPORTED)
- if(png_ptr)
+ if (png_ptr)
return;
#endif
}
@@ -1209,19 +1254,29 @@ void /* PRIVATE */
png_do_read_transformations(png_structp png_ptr)
{
png_debug(1, "in png_do_read_transformations\n");
-#if !defined(PNG_USELESS_TESTS_SUPPORTED)
if (png_ptr->row_buf == NULL)
{
-#ifndef PNG_NO_STDIO
+#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
char msg[50];
- png_sprintf(msg, "NULL row buffer for row %lu, pass %d",
- (unsigned long) png_ptr->row_number, png_ptr->pass);
+ png_snprintf2(msg, 50,
+ "NULL row buffer for row %ld, pass %d", (long)png_ptr->row_number,
+ png_ptr->pass);
png_error(png_ptr, msg);
#else
png_error(png_ptr, "NULL row buffer");
#endif
}
+#ifdef PNG_WARN_UNINITIALIZED_ROW
+ if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
+ /* Application has failed to call either png_read_start_image()
+ * or png_read_update_info() after setting transforms that expand
+ * pixels. This check added to libpng-1.2.19 */
+#if (PNG_WARN_UNINITIALIZED_ROW==1)
+ png_error(png_ptr, "Uninitialized row");
+#else
+ png_warning(png_ptr, "Uninitialized row");
+#endif
#endif
#if defined(PNG_READ_EXPAND_SUPPORTED)
@@ -1234,7 +1289,8 @@ png_do_read_transformations(png_structp png_ptr)
}
else
{
- if (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND_tRNS))
+ if (png_ptr->num_trans &&
+ (png_ptr->transformations & PNG_EXPAND_tRNS))
png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1,
&(png_ptr->trans_values));
else
@@ -1255,12 +1311,14 @@ png_do_read_transformations(png_structp png_ptr)
{
int rgb_error =
png_do_rgb_to_gray(png_ptr, &(png_ptr->row_info), png_ptr->row_buf + 1);
- if(rgb_error)
+ if (rgb_error)
{
png_ptr->rgb_to_gray_status=1;
- if(png_ptr->transformations == PNG_RGB_TO_GRAY_WARN)
+ if ((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
+ PNG_RGB_TO_GRAY_WARN)
png_warning(png_ptr, "png_do_rgb_to_gray found nongray pixel");
- if(png_ptr->transformations == PNG_RGB_TO_GRAY_ERR)
+ if ((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
+ PNG_RGB_TO_GRAY_ERR)
png_error(png_ptr, "png_do_rgb_to_gray found nongray pixel");
}
}
@@ -1343,7 +1401,7 @@ From Andreas Dilger e-mail to png-implement, 26 March 1998:
{
png_do_dither((png_row_infop)&(png_ptr->row_info), png_ptr->row_buf + 1,
png_ptr->palette_lookup, png_ptr->dither_index);
- if(png_ptr->row_info.rowbytes == (png_uint_32)0)
+ if (png_ptr->row_info.rowbytes == (png_uint_32)0)
png_error(png_ptr, "png_do_dither returned rowbytes=0");
}
#endif
@@ -1405,7 +1463,7 @@ From Andreas Dilger e-mail to png-implement, 26 March 1998:
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
if (png_ptr->transformations & PNG_USER_TRANSFORM)
{
- if(png_ptr->read_user_transform_fn != NULL)
+ if (png_ptr->read_user_transform_fn != NULL)
(*(png_ptr->read_user_transform_fn)) /* user read transform function */
(png_ptr, /* png_ptr */
&(png_ptr->row_info), /* row_info: */
@@ -1417,9 +1475,9 @@ From Andreas Dilger e-mail to png-implement, 26 March 1998:
/* png_byte pixel_depth; bits per pixel (depth*channels) */
png_ptr->row_buf + 1); /* start of pixel data for row */
#if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
- if(png_ptr->user_transform_depth)
+ if (png_ptr->user_transform_depth)
png_ptr->row_info.bit_depth = png_ptr->user_transform_depth;
- if(png_ptr->user_transform_channels)
+ if (png_ptr->user_transform_channels)
png_ptr->row_info.channels = png_ptr->user_transform_channels;
#endif
png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth *
@@ -1896,7 +1954,7 @@ png_do_read_filler(png_row_infop row_info, png_bytep row,
#endif
row_info->color_type == PNG_COLOR_TYPE_GRAY)
{
- if(row_info->bit_depth == 8)
+ if (row_info->bit_depth == 8)
{
/* This changes the data from G to GX */
if (flags & PNG_FLAG_FILLER_AFTER)
@@ -1928,7 +1986,7 @@ png_do_read_filler(png_row_infop row_info, png_bytep row,
row_info->rowbytes = row_width * 2;
}
}
- else if(row_info->bit_depth == 16)
+ else if (row_info->bit_depth == 16)
{
/* This changes the data from GG to GGXX */
if (flags & PNG_FLAG_FILLER_AFTER)
@@ -1968,7 +2026,7 @@ png_do_read_filler(png_row_infop row_info, png_bytep row,
} /* COLOR_TYPE == GRAY */
else if (row_info->color_type == PNG_COLOR_TYPE_RGB)
{
- if(row_info->bit_depth == 8)
+ if (row_info->bit_depth == 8)
{
/* This changes the data from RGB to RGBX */
if (flags & PNG_FLAG_FILLER_AFTER)
@@ -2004,7 +2062,7 @@ png_do_read_filler(png_row_infop row_info, png_bytep row,
row_info->rowbytes = row_width * 4;
}
}
- else if(row_info->bit_depth == 16)
+ else if (row_info->bit_depth == 16)
{
/* This changes the data from RRGGBB to RRGGBBXX */
if (flags & PNG_FLAG_FILLER_AFTER)
@@ -2131,7 +2189,7 @@ png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
row_info->color_type |= PNG_COLOR_MASK_COLOR;
row_info->pixel_depth = (png_byte)(row_info->channels *
row_info->bit_depth);
- row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
+ row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width);
}
}
#endif
@@ -2139,8 +2197,11 @@ png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
/* reduce RGB files to grayscale, with or without alpha
* using the equation given in Poynton's ColorFAQ at
- * <http://www.inforamp.net/~poynton/>
+ * <http://www.inforamp.net/~poynton/> (THIS LINK IS DEAD June 2008)
* Copyright (c) 1998-01-04 Charles Poynton poynton at inforamp.net
+ * New links:
+ * <http://www.poynton.com/notes/colour_and_gamma/>
+ * Copyright (c) 2006-11-28 Charles Poynton poynton at poynton.com
*
* Y = 0.212671 * R + 0.715160 * G + 0.072169 * B
*
@@ -2191,14 +2252,14 @@ png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
png_byte red = png_ptr->gamma_to_1[*(sp++)];
png_byte green = png_ptr->gamma_to_1[*(sp++)];
png_byte blue = png_ptr->gamma_to_1[*(sp++)];
- if(red != green || red != blue)
+ if (red != green || red != blue)
{
rgb_error |= 1;
*(dp++) = png_ptr->gamma_from_1[
- (rc*red+gc*green+bc*blue)>>15];
+ (rc*red + gc*green + bc*blue)>>15];
}
else
- *(dp++) = *(sp-1);
+ *(dp++) = *(sp - 1);
}
}
else
@@ -2211,13 +2272,13 @@ png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
png_byte red = *(sp++);
png_byte green = *(sp++);
png_byte blue = *(sp++);
- if(red != green || red != blue)
+ if (red != green || red != blue)
{
rgb_error |= 1;
- *(dp++) = (png_byte)((rc*red+gc*green+bc*blue)>>15);
+ *(dp++) = (png_byte)((rc*red + gc*green + bc*blue)>>15);
}
else
- *(dp++) = *(sp-1);
+ *(dp++) = *(sp - 1);
}
}
}
@@ -2238,7 +2299,7 @@ png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
- if(red == green && red == blue)
+ if (red == green && red == blue)
w = red;
else
{
@@ -2272,7 +2333,7 @@ png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
- if(red != green || red != blue)
+ if (red != green || red != blue)
rgb_error |= 1;
gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15);
*(dp++) = (png_byte)((gray16>>8) & 0xff);
@@ -2295,7 +2356,7 @@ png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
png_byte red = png_ptr->gamma_to_1[*(sp++)];
png_byte green = png_ptr->gamma_to_1[*(sp++)];
png_byte blue = png_ptr->gamma_to_1[*(sp++)];
- if(red != green || red != blue)
+ if (red != green || red != blue)
rgb_error |= 1;
*(dp++) = png_ptr->gamma_from_1
[(rc*red + gc*green + bc*blue)>>15];
@@ -2312,7 +2373,7 @@ png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
png_byte red = *(sp++);
png_byte green = *(sp++);
png_byte blue = *(sp++);
- if(red != green || red != blue)
+ if (red != green || red != blue)
rgb_error |= 1;
*(dp++) = (png_byte)((rc*red + gc*green + bc*blue)>>15);
*(dp++) = *(sp++); /* alpha */
@@ -2335,7 +2396,7 @@ png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
- if(red == green && red == blue)
+ if (red == green && red == blue)
w = red;
else
{
@@ -2369,7 +2430,7 @@ png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
red = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
green = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
blue = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
- if(red != green || red != blue)
+ if (red != green || red != blue)
rgb_error |= 1;
gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15);
*(dp++) = (png_byte)((gray16>>8) & 0xff);
@@ -2384,7 +2445,7 @@ png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
row_info->color_type &= ~PNG_COLOR_MASK_COLOR;
row_info->pixel_depth = (png_byte)(row_info->channels *
row_info->bit_depth);
- row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
+ row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width);
}
return rgb_error;
}
@@ -3302,7 +3363,7 @@ png_do_background(png_row_infop row_info, png_bytep row,
row_info->channels--;
row_info->pixel_depth = (png_byte)(row_info->channels *
row_info->bit_depth);
- row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
+ row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width);
}
}
}
@@ -3664,7 +3725,7 @@ png_do_expand(png_row_infop row_info, png_bytep row,
{
case 1:
{
- gray = (png_uint_16)(gray*0xff);
+ gray = (png_uint_16)((gray&0x01)*0xff);
sp = row + (png_size_t)((row_width - 1) >> 3);
dp = row + (png_size_t)row_width - 1;
shift = 7 - (int)((row_width + 7) & 0x07);
@@ -3688,7 +3749,7 @@ png_do_expand(png_row_infop row_info, png_bytep row,
}
case 2:
{
- gray = (png_uint_16)(gray*0x55);
+ gray = (png_uint_16)((gray&0x03)*0x55);
sp = row + (png_size_t)((row_width - 1) >> 2);
dp = row + (png_size_t)row_width - 1;
shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
@@ -3711,7 +3772,7 @@ png_do_expand(png_row_infop row_info, png_bytep row,
}
case 4:
{
- gray = (png_uint_16)(gray*0x11);
+ gray = (png_uint_16)((gray&0x0f)*0x11);
sp = row + (png_size_t)((row_width - 1) >> 1);
dp = row + (png_size_t)row_width - 1;
shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
@@ -3741,6 +3802,7 @@ png_do_expand(png_row_infop row_info, png_bytep row,
{
if (row_info->bit_depth == 8)
{
+ gray = gray & 0xff;
sp = row + (png_size_t)row_width - 1;
dp = row + (png_size_t)(row_width << 1) - 1;
for (i = 0; i < row_width; i++)
@@ -3754,12 +3816,13 @@ png_do_expand(png_row_infop row_info, png_bytep row,
}
else if (row_info->bit_depth == 16)
{
+ png_byte gray_high = (gray >> 8) & 0xff;
+ png_byte gray_low = gray & 0xff;
sp = row + row_info->rowbytes - 1;
dp = row + (row_info->rowbytes << 1) - 1;
for (i = 0; i < row_width; i++)
{
- if (((png_uint_16)*(sp) |
- ((png_uint_16)*(sp - 1) << 8)) == gray)
+ if (*(sp - 1) == gray_high && *(sp) == gray_low)
{
*dp-- = 0;
*dp-- = 0;
@@ -3784,13 +3847,14 @@ png_do_expand(png_row_infop row_info, png_bytep row,
{
if (row_info->bit_depth == 8)
{
+ png_byte red = trans_value->red & 0xff;
+ png_byte green = trans_value->green & 0xff;
+ png_byte blue = trans_value->blue & 0xff;
sp = row + (png_size_t)row_info->rowbytes - 1;
dp = row + (png_size_t)(row_width << 2) - 1;
for (i = 0; i < row_width; i++)
{
- if (*(sp - 2) == trans_value->red &&
- *(sp - 1) == trans_value->green &&
- *(sp - 0) == trans_value->blue)
+ if (*(sp - 2) == red && *(sp - 1) == green && *(sp) == blue)
*dp-- = 0;
else
*dp-- = 0xff;
@@ -3801,16 +3865,22 @@ png_do_expand(png_row_infop row_info, png_bytep row,
}
else if (row_info->bit_depth == 16)
{
+ png_byte red_high = (trans_value->red >> 8) & 0xff;
+ png_byte green_high = (trans_value->green >> 8) & 0xff;
+ png_byte blue_high = (trans_value->blue >> 8) & 0xff;
+ png_byte red_low = trans_value->red & 0xff;
+ png_byte green_low = trans_value->green & 0xff;
+ png_byte blue_low = trans_value->blue & 0xff;
sp = row + row_info->rowbytes - 1;
dp = row + (png_size_t)(row_width << 3) - 1;
for (i = 0; i < row_width; i++)
{
- if ((((png_uint_16)*(sp - 4) |
- ((png_uint_16)*(sp - 5) << 8)) == trans_value->red) &&
- (((png_uint_16)*(sp - 2) |
- ((png_uint_16)*(sp - 3) << 8)) == trans_value->green) &&
- (((png_uint_16)*(sp - 0) |
- ((png_uint_16)*(sp - 1) << 8)) == trans_value->blue))
+ if (*(sp - 5) == red_high &&
+ *(sp - 4) == red_low &&
+ *(sp - 3) == green_high &&
+ *(sp - 2) == green_low &&
+ *(sp - 1) == blue_high &&
+ *(sp ) == blue_low)
{
*dp-- = 0;
*dp-- = 0;
@@ -3831,7 +3901,7 @@ png_do_expand(png_row_infop row_info, png_bytep row,
row_info->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
row_info->channels = 4;
row_info->pixel_depth = (png_byte)(row_info->bit_depth << 2);
- row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
+ row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width);
}
}
}
@@ -3884,7 +3954,7 @@ png_do_dither(png_row_infop row_info, png_bytep row,
row_info->color_type = PNG_COLOR_TYPE_PALETTE;
row_info->channels = 1;
row_info->pixel_depth = row_info->bit_depth;
- row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
+ row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width);
}
else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
palette_lookup != NULL && row_info->bit_depth == 8)
@@ -3913,7 +3983,7 @@ png_do_dither(png_row_infop row_info, png_bytep row,
row_info->color_type = PNG_COLOR_TYPE_PALETTE;
row_info->channels = 1;
row_info->pixel_depth = row_info->bit_depth;
- row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
+ row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width);
}
else if (row_info->color_type == PNG_COLOR_TYPE_PALETTE &&
dither_lookup && row_info->bit_depth == 8)
@@ -3930,8 +4000,8 @@ png_do_dither(png_row_infop row_info, png_bytep row,
#ifdef PNG_FLOATING_POINT_SUPPORTED
#if defined(PNG_READ_GAMMA_SUPPORTED)
-static int png_gamma_shift[] =
- {0x10, 0x21, 0x42, 0x84, 0x110, 0x248, 0x550, 0xff0, 0x000};
+static PNG_CONST int png_gamma_shift[] =
+ {0x10, 0x21, 0x42, 0x84, 0x110, 0x248, 0x550, 0xff0, 0x00};
/* We build the 8- or 16-bit gamma tables here. Note that for 16-bit
* tables, we don't make a full table if we are reducing to 8-bit in
@@ -3953,7 +4023,8 @@ png_build_gamma_table(png_structp png_ptr)
else
g = 1.0;
- png_ptr->gamma_table = (png_bytep)png_malloc(png_ptr, 256);
+ png_ptr->gamma_table = (png_bytep)png_malloc(png_ptr,
+ (png_uint_32)256);
for (i = 0; i < 256; i++)
{
@@ -3968,7 +4039,8 @@ png_build_gamma_table(png_structp png_ptr)
g = 1.0 / (png_ptr->gamma);
- png_ptr->gamma_to_1 = (png_bytep)png_malloc(png_ptr, 256);
+ png_ptr->gamma_to_1 = (png_bytep)png_malloc(png_ptr,
+ (png_uint_32)256);
for (i = 0; i < 256; i++)
{
@@ -3977,9 +4049,10 @@ png_build_gamma_table(png_structp png_ptr)
}
- png_ptr->gamma_from_1 = (png_bytep)png_malloc(png_ptr, 256);
+ png_ptr->gamma_from_1 = (png_bytep)png_malloc(png_ptr,
+ (png_uint_32)256);
- if(png_ptr->screen_gamma > 0.000001)
+ if (png_ptr->screen_gamma > 0.000001)
g = 1.0 / png_ptr->screen_gamma;
else
g = png_ptr->gamma; /* probably doing rgb_to_gray */
@@ -4039,7 +4112,7 @@ png_build_gamma_table(png_structp png_ptr)
g = 1.0;
png_ptr->gamma_16_table = (png_uint_16pp)png_malloc(png_ptr,
- (png_size_t)(num * sizeof(png_uint_16p)));
+ (png_uint_32)(num * png_sizeof(png_uint_16p)));
if (png_ptr->transformations & (PNG_16_TO_8 | PNG_BACKGROUND))
{
@@ -4049,7 +4122,7 @@ png_build_gamma_table(png_structp png_ptr)
for (i = 0; i < num; i++)
{
png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
- 256 * sizeof(png_uint_16));
+ (png_uint_32)(256 * png_sizeof(png_uint_16)));
}
g = 1.0 / g;
@@ -4079,7 +4152,7 @@ png_build_gamma_table(png_structp png_ptr)
for (i = 0; i < num; i++)
{
png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
- 256 * sizeof(png_uint_16));
+ (png_uint_32)(256 * png_sizeof(png_uint_16)));
ig = (((png_uint_32)i * (png_uint_32)png_gamma_shift[shift]) >> 4);
for (j = 0; j < 256; j++)
@@ -4099,12 +4172,12 @@ png_build_gamma_table(png_structp png_ptr)
g = 1.0 / (png_ptr->gamma);
png_ptr->gamma_16_to_1 = (png_uint_16pp)png_malloc(png_ptr,
- (png_size_t)(num * sizeof(png_uint_16p)));
+ (png_uint_32)(num * png_sizeof(png_uint_16p )));
for (i = 0; i < num; i++)
{
png_ptr->gamma_16_to_1[i] = (png_uint_16p)png_malloc(png_ptr,
- 256 * sizeof(png_uint_16));
+ (png_uint_32)(256 * png_sizeof(png_uint_16)));
ig = (((png_uint_32)i *
(png_uint_32)png_gamma_shift[shift]) >> 4);
@@ -4116,18 +4189,18 @@ png_build_gamma_table(png_structp png_ptr)
}
}
- if(png_ptr->screen_gamma > 0.000001)
+ if (png_ptr->screen_gamma > 0.000001)
g = 1.0 / png_ptr->screen_gamma;
else
g = png_ptr->gamma; /* probably doing rgb_to_gray */
png_ptr->gamma_16_from_1 = (png_uint_16pp)png_malloc(png_ptr,
- (png_size_t)(num * sizeof(png_uint_16p)));
+ (png_uint_32)(num * png_sizeof(png_uint_16p)));
for (i = 0; i < num; i++)
{
png_ptr->gamma_16_from_1[i] = (png_uint_16p)png_malloc(png_ptr,
- 256 * sizeof(png_uint_16));
+ (png_uint_32)(256 * png_sizeof(png_uint_16)));
ig = (((png_uint_32)i *
(png_uint_32)png_gamma_shift[shift]) >> 4);
@@ -4192,11 +4265,11 @@ png_do_read_intrapixel(png_row_infop row_info, png_bytep row)
for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
{
- png_uint_32 s0 = (*(rp ) << 8) | *(rp+1);
- png_uint_32 s1 = (*(rp+2) << 8) | *(rp+3);
- png_uint_32 s2 = (*(rp+4) << 8) | *(rp+5);
- png_uint_32 red = (png_uint_32)((s0+s1+65536L) & 0xffffL);
- png_uint_32 blue = (png_uint_32)((s2+s1+65536L) & 0xffffL);
+ png_uint_32 s0 = (*(rp ) << 8) | *(rp + 1);
+ png_uint_32 s1 = (*(rp + 2) << 8) | *(rp + 3);
+ png_uint_32 s2 = (*(rp + 4) << 8) | *(rp + 5);
+ png_uint_32 red = (png_uint_32)((s0 + s1 + 65536L) & 0xffffL);
+ png_uint_32 blue = (png_uint_32)((s2 + s1 + 65536L) & 0xffffL);
*(rp ) = (png_byte)((red >> 8) & 0xff);
*(rp+1) = (png_byte)(red & 0xff);
*(rp+4) = (png_byte)((blue >> 8) & 0xff);
diff --git a/pngrutil.c b/pngrutil.c
index 0c1b66022..36d82f323 100644
--- a/pngrutil.c
+++ b/pngrutil.c
@@ -1,9 +1,9 @@
/* pngrutil.c - utilities to read a PNG file
*
- * Last changed in libpng 1.4.0 May 15, 2007
+ * Last changed in libpng 1.4.0 [July 10, 2008]
* For conditions of distribution and use, see copyright notice in png.h
- * Copyright (c) 1998-2007 Glenn Randers-Pehrson
+ * Copyright (c) 1998-2008 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*
@@ -12,10 +12,10 @@
*/
#include "png.h"
-#include "pngpriv.h"
-
#if defined(PNG_READ_SUPPORTED)
+#include "pngpriv.h"
+# define png_strtod(p,a,b) strtod(a,b)
png_uint_32 PNGAPI
png_get_uint_31(png_structp png_ptr, png_bytep buf)
{
@@ -112,11 +112,11 @@ png_read_chunk_header(png_structp png_ptr)
return length;
}
-/* Read data and run it through the CRC. */
+/* Read data, and (optionally) run it through the CRC. */
void /* PRIVATE */
png_crc_read(png_structp png_ptr, png_bytep buf, png_size_t length)
{
- if(png_ptr == NULL) return;
+ if (png_ptr == NULL) return;
png_read_data(png_ptr, buf, length);
png_calculate_crc(png_ptr, buf, length);
}
@@ -135,16 +135,16 @@ png_crc_finish(png_structp png_ptr, png_uint_32 skip)
{
png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
}
- if (i > 0)
+ if (i)
{
png_crc_read(png_ptr, png_ptr->zbuf, i);
}
if (png_crc_error(png_ptr))
{
- if (((png_ptr->chunk_name[0] & 0x20) && /* Ancillary */
+ if (((png_ptr->chunk_name[0] & 0x20) && /* Ancillary */
!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)) ||
- (!(png_ptr->chunk_name[0] & 0x20) && /* Critical */
+ (!(png_ptr->chunk_name[0] & 0x20) && /* Critical */
(png_ptr->flags & PNG_FLAG_CRC_CRITICAL_USE)))
{
png_chunk_warning(png_ptr, "CRC error");
@@ -186,6 +186,7 @@ png_crc_error(png_structp png_ptr)
/* PNG_IO_CHUNK_CRC requires the I/O to be done at once */
png_ptr->io_state = PNG_IO_READING | PNG_IO_CHUNK_CRC;
#endif
+
png_read_data(png_ptr, crc_bytes, 4);
if (need_crc)
@@ -211,7 +212,7 @@ png_decompress_chunk(png_structp png_ptr, int comp_type,
png_charp chunkdata, png_size_t chunklength,
png_size_t prefix_size, png_size_t *newlength)
{
- static char msg[] = "Error decoding compressed text";
+ static PNG_CONST char msg[] = "Error decoding compressed text";
png_charp text;
png_size_t text_size;
@@ -240,12 +241,12 @@ png_decompress_chunk(png_structp png_ptr, int comp_type,
if (text == NULL)
{
- text_size = prefix_size + sizeof(msg) + 1;
+ text_size = prefix_size + png_sizeof(msg) + 1;
text = (png_charp)png_malloc_warn(png_ptr, text_size);
if (text == NULL)
{
- png_free(png_ptr,chunkdata);
- png_error(png_ptr,"Not enough memory to decompress chunk");
+ png_free(png_ptr, chunkdata);
+ png_error(png_ptr, "Not enough memory to decompress chunk");
}
png_memcpy(text, chunkdata, prefix_size);
}
@@ -254,9 +255,9 @@ png_decompress_chunk(png_structp png_ptr, int comp_type,
/* Copy what we can of the error message into the text chunk */
text_size = (png_size_t)(chunklength - (text - chunkdata) - 1);
- if (text_size > sizeof(msg))
- text_size = sizeof(msg);
- png_memcpy(text + prefix_size, msg, text_size + 1);
+ if (text_size > png_sizeof(msg))
+ text_size = png_sizeof(msg);
+ png_memcpy(text + prefix_size, msg, text_size);
break;
}
if (!png_ptr->zstream.avail_out || ret == Z_STREAM_END)
@@ -268,8 +269,9 @@ png_decompress_chunk(png_structp png_ptr, int comp_type,
text = (png_charp)png_malloc_warn(png_ptr, text_size + 1);
if (text == NULL)
{
- png_free(png_ptr,chunkdata);
- png_error(png_ptr, "Not enough memory to decompress chunk");
+ png_free(png_ptr, chunkdata);
+ png_error(png_ptr,
+ "Not enough memory to decompress chunk");
}
png_memcpy(text + prefix_size, png_ptr->zbuf,
text_size - prefix_size);
@@ -288,7 +290,8 @@ png_decompress_chunk(png_structp png_ptr, int comp_type,
{
png_free(png_ptr, tmp);
png_free(png_ptr, chunkdata);
- png_error(png_ptr,"Not enough memory to decompress chunk");
+ png_error(png_ptr,
+ "Not enough memory to decompress chunk");
}
png_memcpy(text, tmp, text_size);
png_free(png_ptr, tmp);
@@ -308,24 +311,27 @@ png_decompress_chunk(png_structp png_ptr, int comp_type,
}
if (ret != Z_STREAM_END)
{
-#ifndef PNG_NO_STDIO
+#if !defined(PNG_NO_STDIO)
char umsg[52];
if (ret == Z_BUF_ERROR)
- png_sprintf(umsg,"Buffer error in compressed datastream in %s chunk",
+ png_snprintf(umsg, 52,
+ "Buffer error in compressed datastream in %s chunk",
png_ptr->chunk_name);
else if (ret == Z_DATA_ERROR)
- png_sprintf(umsg,"Data error in compressed datastream in %s chunk",
+ png_snprintf(umsg, 52,
+ "Data error in compressed datastream in %s chunk",
png_ptr->chunk_name);
else
- png_sprintf(umsg,"Incomplete compressed datastream in %s chunk",
+ png_snprintf(umsg, 52,
+ "Incomplete compressed datastream in %s chunk",
png_ptr->chunk_name);
png_warning(png_ptr, umsg);
#else
png_warning(png_ptr,
"Incomplete compressed datastream in chunk other than IDAT");
#endif
- text_size=prefix_size;
+ text_size = prefix_size;
if (text == NULL)
{
text = (png_charp)png_malloc_warn(png_ptr, text_size+1);
@@ -348,17 +354,17 @@ png_decompress_chunk(png_structp png_ptr, int comp_type,
}
else /* if (comp_type != PNG_COMPRESSION_TYPE_BASE) */
{
-#ifndef PNG_NO_STDIO
+#if !defined(PNG_NO_STDIO)
char umsg[50];
- png_sprintf(umsg, "Unknown zTXt compression type %d", comp_type);
+ png_snprintf(umsg, 50, "Unknown zTXt compression type %d", comp_type);
png_warning(png_ptr, umsg);
#else
png_warning(png_ptr, "Unknown zTXt compression type");
#endif
*(chunkdata + prefix_size) = 0x00;
- *newlength=prefix_size;
+ *newlength = prefix_size;
}
return chunkdata;
@@ -428,10 +434,10 @@ png_handle_IHDR(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
/* set up other useful info */
png_ptr->pixel_depth = (png_byte)(png_ptr->bit_depth *
png_ptr->channels);
- png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->width);
- png_debug1(3,"bit_depth = %d\n", png_ptr->bit_depth);
- png_debug1(3,"channels = %d\n", png_ptr->channels);
- png_debug1(3, "rowbytes = %lu\n", (unsigned long) png_ptr->rowbytes);
+ png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, png_ptr->width);
+ png_debug1(3, "bit_depth = %d\n", png_ptr->bit_depth);
+ png_debug1(3, "channels = %d\n", png_ptr->channels);
+ png_debug1(3, "rowbytes = %lu\n", png_ptr->rowbytes);
png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth,
color_type, interlace_type, compression_type, filter_type);
}
@@ -536,7 +542,7 @@ png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
{
if (png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)
{
- png_chunk_benign_error(png_ptr, "CRC error");
+%15+% png_chunk_benign_error(png_ptr, "CRC error");
}
else
{
@@ -593,8 +599,7 @@ png_handle_IEND(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
}
png_crc_finish(png_ptr, length);
- if (&info_ptr == NULL) /* quiet compiler warnings about unused info_ptr */
- return;
+ info_ptr = info_ptr; /* quiet compiler warnings about unused info_ptr */
}
#if defined(PNG_READ_gAMA_SUPPORTED)
@@ -861,14 +866,14 @@ png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
"Ignoring incorrect cHRM value when sRGB is also present");
#ifndef PNG_NO_CONSOLE_IO
#ifdef PNG_FLOATING_POINT_SUPPORTED
- fprintf(stderr,"wx=%f, wy=%f, rx=%f, ry=%f\n",
+ 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",
+ fprintf(stderr, "gx=%f, gy=%f, bx=%f, by=%f\n",
green_x, green_y, blue_x, blue_y);
#else
- fprintf(stderr,"wx=%ld, wy=%ld, rx=%ld, ry=%ld\n",
+ fprintf(stderr, "wx=%ld, wy=%ld, rx=%ld, ry=%ld\n",
int_x_white, int_y_white, int_x_red, int_y_red);
- fprintf(stderr,"gx=%ld, gy=%ld, bx=%ld, by=%ld\n",
+ fprintf(stderr, "gx=%ld, gy=%ld, bx=%ld, by=%ld\n",
int_x_green, int_y_green, int_x_blue, int_y_blue);
#endif
#endif /* PNG_NO_CONSOLE_IO */
@@ -886,6 +891,8 @@ png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
int_x_white, int_y_white, int_x_red, int_y_red, int_x_green,
int_y_green, int_x_blue, int_y_blue);
#endif
+ if (png_crc_finish(png_ptr, 0))
+ return;
}
#endif
@@ -953,10 +960,11 @@ png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
"Ignoring incorrect gAMA value when sRGB is also present");
#ifndef PNG_NO_CONSOLE_IO
# ifdef PNG_FIXED_POINT_SUPPORTED
- fprintf(stderr,"incorrect gamma=(%d/100000)\n",(int)png_ptr->int_gamma);
+ fprintf(stderr, "incorrect gamma=(%d/100000)\n",
+ (int)png_ptr->int_gamma);
# else
# ifdef PNG_FLOATING_POINT_SUPPORTED
- fprintf(stderr,"incorrect gamma=%f\n",png_ptr->gamma);
+ fprintf(stderr, "incorrect gamma=%f\n", png_ptr->gamma);
# endif
# endif
#endif
@@ -1048,7 +1056,7 @@ png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
/* there should be at least one zero (the compression type byte)
following the separator, and we should be on it */
- if ( profile >= chunkdata + slength)
+ if ( profile >= chunkdata + slength - 1)
{
png_free(png_ptr, chunkdata);
png_warning(png_ptr, "Malformed iCCP chunk");
@@ -1060,7 +1068,7 @@ png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
if (compression_type)
{
png_warning(png_ptr, "Ignoring nonzero compression type in iCCP chunk");
- compression_type=0x00; /* Reset it to zero (libpng-1.0.6 through 1.0.8
+ compression_type = 0x00; /* Reset it to zero (libpng-1.0.6 through 1.0.8
wrote nonzero) */
}
@@ -1078,16 +1086,16 @@ png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
}
/* Check the profile_size recorded in the first 32 bits of the ICC profile */
- pC = (png_bytep)(chunkdata+prefix_length);
+ pC = (png_bytep)(chunkdata + prefix_length);
profile_size = ((*(pC ))<<24) |
- ((*(pC+1))<<16) |
- ((*(pC+2))<< 8) |
- ((*(pC+3)) );
+ ((*(pC + 1))<<16) |
+ ((*(pC + 2))<< 8) |
+ ((*(pC + 3)) );
- if(profile_size < profile_length)
+ if (profile_size < profile_length)
profile_length = profile_size;
- if(profile_size > profile_length)
+ if (profile_size > profile_length)
{
png_free(png_ptr, chunkdata);
png_warning(png_ptr, "Ignoring truncated iCCP profile");
@@ -1152,7 +1160,7 @@ png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
++entry_start;
/* a sample depth should follow the separator, and we should be on it */
- if (entry_start > chunkdata + slength)
+ if (entry_start > chunkdata + slength - 2)
{
png_free(png_ptr, chunkdata);
png_warning(png_ptr, "malformed sPLT chunk");
@@ -1173,13 +1181,13 @@ png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
new_palette.nentries = (png_int_32) ( data_length / entry_size);
if ((png_uint_32) new_palette.nentries >
- (png_uint_32) (PNG_SIZE_MAX / sizeof(png_sPLT_entry)))
+ (png_uint_32) (PNG_SIZE_MAX / png_sizeof(png_sPLT_entry)))
{
png_warning(png_ptr, "sPLT chunk too long");
return;
}
new_palette.entries = (png_sPLT_entryp)png_malloc_warn(
- png_ptr, new_palette.nentries * sizeof(png_sPLT_entry));
+ png_ptr, new_palette.nentries * png_sizeof(png_sPLT_entry));
if (new_palette.entries == NULL)
{
png_warning(png_ptr, "sPLT chunk requires too much memory");
@@ -1391,9 +1399,9 @@ png_handle_bKGD(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
{
png_ptr->background.index = buf[0];
- if(info_ptr->num_palette)
+ if (info_ptr && info_ptr->num_palette)
{
- if(buf[0] > info_ptr->num_palette)
+ if (buf[0] > info_ptr->num_palette)
{
png_warning(png_ptr, "Incorrect bKGD chunk index value");
return;
@@ -1595,7 +1603,7 @@ png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
}
png_debug1(2, "Allocating and reading pCAL chunk data (%lu bytes)\n",
- (unsigned long) (length + 1));
+ length + 1);
purpose = (png_charp)png_malloc_warn(png_ptr, length + 1);
if (purpose == NULL)
{
@@ -1657,7 +1665,7 @@ png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_debug(3, "Allocating pCAL parameters array\n");
params = (png_charpp)png_malloc_warn(png_ptr,
- (png_size_t)(nparams * sizeof(png_charp)));
+ (png_size_t)(nparams * png_sizeof(png_charp)));
if (params == NULL)
{
png_free(png_ptr, purpose);
@@ -1671,7 +1679,7 @@ png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
buf++; /* Skip the null string terminator from previous parameter. */
png_debug1(3, "Reading pCAL parameter %d\n", i);
- for (params[i] = buf; *buf != 0x00 && buf <= endptr; buf++)
+ for (params[i] = buf; buf <= endptr && *buf != 0x00; buf++)
/* Empty loop to move past each parameter string */ ;
/* Make sure we haven't run out of data yet */
@@ -1726,13 +1734,13 @@ png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
}
png_debug1(2, "Allocating and reading sCAL chunk data (%lu bytes)\n",
- (unsigned long) (length + 1));
+ length + 1);
buffer = (png_charp)png_malloc_warn(png_ptr, length + 1);
if (buffer == NULL)
- {
- png_warning(png_ptr, "Out of memory while processing sCAL chunk");
- return;
- }
+ {
+ png_warning(png_ptr, "Out of memory while processing sCAL chunk");
+ return;
+ }
slength = (png_size_t)length;
png_crc_read(png_ptr, (png_bytep)buffer, slength);
@@ -1747,11 +1755,11 @@ png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
ep = buffer + 1; /* skip unit byte */
#ifdef PNG_FLOATING_POINT_SUPPORTED
- width = strtod(ep, &vp);
+ width = png_strtod(png_ptr, ep, &vp);
if (*vp)
{
- png_warning(png_ptr, "malformed width string in sCAL chunk");
- return;
+ png_warning(png_ptr, "malformed width string in sCAL chunk");
+ return;
}
#else
#ifdef PNG_FIXED_POINT_SUPPORTED
@@ -1769,17 +1777,28 @@ png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
/* empty loop */ ;
ep++;
+ if (buffer + slength < ep)
+ {
+ png_warning(png_ptr, "Truncated sCAL chunk");
+#if defined(PNG_FIXED_POINT_SUPPORTED) && \
+ !defined(PNG_FLOATING_POINT_SUPPORTED)
+ png_free(png_ptr, swidth);
+#endif
+ png_free(png_ptr, buffer);
+ return;
+ }
+
#ifdef PNG_FLOATING_POINT_SUPPORTED
- height = strtod(ep, &vp);
+ height = png_strtod(png_ptr, ep, &vp);
if (*vp)
{
- png_warning(png_ptr, "malformed height string in sCAL chunk");
- return;
+ png_warning(png_ptr, "malformed height string in sCAL chunk");
+ return;
}
#else
#ifdef PNG_FIXED_POINT_SUPPORTED
sheight = (png_charp)png_malloc_warn(png_ptr, png_strlen(ep) + 1);
- if (swidth == NULL)
+ if (sheight == NULL)
{
png_warning(png_ptr, "Out of memory while processing sCAL chunk height");
return;
@@ -1915,7 +1934,8 @@ png_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
if (text != key + slength)
text++;
- text_ptr = (png_textp)png_malloc_warn(png_ptr, sizeof(png_text));
+ text_ptr = (png_textp)png_malloc_warn(png_ptr,
+ png_sizeof(png_text));
if (text_ptr == NULL)
{
png_warning(png_ptr, "Not enough memory to process text chunk");
@@ -1932,7 +1952,7 @@ png_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
text_ptr->text = text;
text_ptr->text_length = png_strlen(text);
- ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
+ ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
png_free(png_ptr, key);
png_free(png_ptr, text_ptr);
@@ -1965,7 +1985,7 @@ png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
there is no hard and fast rule to tell us where to stop. */
if (length > (png_uint_32)65535L)
{
- png_warning(png_ptr,"zTXt chunk too large to fit in memory");
+ png_warning(png_ptr, "zTXt chunk too large to fit in memory");
png_crc_finish(png_ptr, length);
return;
}
@@ -1974,7 +1994,7 @@ png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
if (chunkdata == NULL)
{
- png_warning(png_ptr,"Out of memory processing zTXt chunk");
+ png_warning(png_ptr, "Out of memory processing zTXt chunk");
return;
}
slength = (png_size_t)length;
@@ -1991,10 +2011,11 @@ png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
/* empty loop */ ;
/* zTXt must have some text after the chunkdataword */
- if (text == chunkdata + slength)
+ if (text >= chunkdata + slength - 2)
{
- comp_type = PNG_TEXT_COMPRESSION_NONE;
- png_warning(png_ptr, "Zero length zTXt chunk");
+ png_warning(png_ptr, "Truncated zTXt chunk");
+ png_free(png_ptr, chunkdata);
+ return;
}
else
{
@@ -2011,10 +2032,11 @@ png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
chunkdata = (png_charp)png_decompress_chunk(png_ptr, comp_type, chunkdata,
(png_size_t)length, prefix_len, &data_len);
- text_ptr = (png_textp)png_malloc_warn(png_ptr, sizeof(png_text));
+ text_ptr = (png_textp)png_malloc_warn(png_ptr,
+ png_sizeof(png_text));
if (text_ptr == NULL)
{
- png_warning(png_ptr,"Not enough memory to process zTXt chunk");
+ png_warning(png_ptr, "Not enough memory to process zTXt chunk");
png_free(png_ptr, chunkdata);
return;
}
@@ -2028,7 +2050,7 @@ png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
text_ptr->text = chunkdata + prefix_len;
text_ptr->text_length = data_len;
- ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
+ ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
png_free(png_ptr, text_ptr);
png_free(png_ptr, chunkdata);
@@ -2063,7 +2085,7 @@ png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
there is no hard and fast rule to tell us where to stop. */
if (length > (png_uint_32)65535L)
{
- png_warning(png_ptr,"iTXt chunk too large to fit in memory");
+ png_warning(png_ptr, "iTXt chunk too large to fit in memory");
png_crc_finish(png_ptr, length);
return;
}
@@ -2093,10 +2115,11 @@ png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
translated keyword (possibly empty), and possibly some text after the
keyword */
- if (lang >= chunkdata + slength)
+ if (lang >= chunkdata + slength - 3)
{
- comp_flag = PNG_TEXT_COMPRESSION_NONE;
- png_warning(png_ptr, "Zero length iTXt chunk");
+ png_warning(png_ptr, "Truncated iTXt chunk");
+ png_free(png_ptr, chunkdata);
+ return;
}
else
{
@@ -2108,9 +2131,22 @@ png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
/* empty loop */ ;
lang_key++; /* skip NUL separator */
+ if (lang_key >= chunkdata + slength)
+ {
+ png_warning(png_ptr, "Truncated iTXt chunk");
+ png_free(png_ptr, chunkdata);
+ return;
+ }
+
for (text = lang_key; *text; text++)
/* empty loop */ ;
text++; /* skip NUL separator */
+ if (text >= chunkdata + slength)
+ {
+ png_warning(png_ptr, "Malformed iTXt chunk");
+ png_free(png_ptr, chunkdata);
+ return;
+ }
prefix_len = text - chunkdata;
@@ -2119,23 +2155,24 @@ png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
chunkdata = png_decompress_chunk(png_ptr, comp_type, chunkdata,
(size_t)length, prefix_len, &data_len);
else
- data_len=png_strlen(chunkdata + prefix_len);
- text_ptr = (png_textp)png_malloc_warn(png_ptr, sizeof(png_text));
+ data_len = png_strlen(chunkdata + prefix_len);
+ text_ptr = (png_textp)png_malloc_warn(png_ptr,
+ png_sizeof(png_text));
if (text_ptr == NULL)
{
- png_warning(png_ptr,"Not enough memory to process iTXt chunk");
+ png_warning(png_ptr, "Not enough memory to process iTXt chunk");
png_free(png_ptr, chunkdata);
return;
}
text_ptr->compression = (int)comp_flag + 1;
- text_ptr->lang_key = chunkdata+(lang_key-key);
- text_ptr->lang = chunkdata+(lang-key);
+ text_ptr->lang_key = chunkdata + (lang_key - key);
+ text_ptr->lang = chunkdata + (lang - key);
text_ptr->itxt_length = data_len;
text_ptr->text_length = 0;
text_ptr->key = chunkdata;
text_ptr->text = chunkdata + prefix_len;
- ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
+ ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
png_free(png_ptr, text_ptr);
png_free(png_ptr, chunkdata);
@@ -2159,7 +2196,7 @@ png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
if (png_ptr->mode & PNG_HAVE_IDAT)
{
#ifdef PNG_USE_LOCAL_ARRAYS
- PNG_IDAT;
+ PNG_CONST PNG_IDAT;
#endif
if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) /* not an IDAT */
png_ptr->mode |= PNG_AFTER_IDAT;
@@ -2170,7 +2207,7 @@ png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
if (!(png_ptr->chunk_name[0] & 0x20))
{
#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
- if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
+ if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
PNG_HANDLE_CHUNK_ALWAYS
#if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
&& png_ptr->read_user_chunk_fn == NULL
@@ -2184,8 +2221,6 @@ png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
if ((png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS) ||
(png_ptr->read_user_chunk_fn != NULL))
{
- png_unknown_chunk chunk;
-
#ifdef PNG_MAX_MALLOC_64K
if (length > (png_uint_32)65535L)
{
@@ -2194,30 +2229,42 @@ png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
length = (png_uint_32)65535L;
}
#endif
- png_strcpy((png_charp)chunk.name, (png_charp)png_ptr->chunk_name);
- chunk.data = (png_bytep)png_malloc(png_ptr, length);
- chunk.size = (png_size_t)length;
- png_crc_read(png_ptr, (png_bytep)chunk.data, length);
+ png_memcpy((png_charp)png_ptr->unknown_chunk.name,
+ (png_charp)png_ptr->chunk_name,
+ png_sizeof(png_ptr->unknown_chunk.name));
+ png_ptr->unknown_chunk.name[png_sizeof(png_ptr->unknown_chunk.name)-1] = '\0';
+ png_ptr->unknown_chunk.size = (png_size_t)length;
+ if (length == 0)
+ png_ptr->unknown_chunk.data = NULL;
+ else
+ {
+ png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
+ png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
+ }
#if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
- if(png_ptr->read_user_chunk_fn != NULL)
+ if (png_ptr->read_user_chunk_fn != NULL)
{
/* callback to user unknown chunk handler */
- if ((*(png_ptr->read_user_chunk_fn)) (png_ptr, &chunk) <= 0)
+ int ret;
+ ret = (*(png_ptr->read_user_chunk_fn))
+ (png_ptr, &png_ptr->unknown_chunk);
+ if (ret < 0)
+ png_chunk_error(png_ptr, "error in user chunk");
+ if (ret == 0)
{
if (!(png_ptr->chunk_name[0] & 0x20))
- if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
+ if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
PNG_HANDLE_CHUNK_ALWAYS)
- {
- png_free(png_ptr, chunk.data);
png_chunk_error(png_ptr, "unknown critical chunk");
- }
- png_set_unknown_chunks(png_ptr, info_ptr, &chunk, 1);
+ png_set_unknown_chunks(png_ptr, info_ptr,
+ &png_ptr->unknown_chunk, 1);
}
}
else
#endif
- png_set_unknown_chunks(png_ptr, info_ptr, &chunk, 1);
- png_free(png_ptr, chunk.data);
+ png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
+ png_free(png_ptr, png_ptr->unknown_chunk.data);
+ png_ptr->unknown_chunk.data = NULL;
}
else
#endif
@@ -2226,8 +2273,7 @@ png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_crc_finish(png_ptr, skip);
#if !defined(PNG_READ_USER_CHUNKS_SUPPORTED)
- if (&info_ptr == NULL) /* quiet compiler warnings about unused info_ptr */
- return;
+ info_ptr = info_ptr; /* quiet compiler warnings about unused info_ptr */
#endif
}
@@ -2260,11 +2306,11 @@ png_check_chunk_name(png_structp png_ptr, png_bytep chunk_name)
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. */
-#ifndef PNG_HAVE_MMX_COMBINE_ROW
+
void /* PRIVATE */
png_combine_row(png_structp png_ptr, png_bytep row, int mask)
{
- png_debug(1,"in png_combine_row\n");
+ png_debug(1, "in png_combine_row\n");
if (mask == 0xff)
{
png_memcpy(row, png_ptr->row_buf + 1,
@@ -2461,10 +2507,8 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask)
}
}
}
-#endif /* !PNG_HAVE_MMX_COMBINE_ROW */
#ifdef PNG_READ_INTERLACING_SUPPORTED
-#ifndef PNG_HAVE_MMX_READ_INTERLACE /* else in pngvcrd.c, pnggccrd.c */
/* OLD pre-1.0.9 interface:
void png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
png_uint_32 transformations)
@@ -2479,10 +2523,10 @@ png_do_read_interlace(png_structp png_ptr)
#ifdef PNG_USE_LOCAL_ARRAYS
/* arrays to facilitate easy interlacing - use pass (0 - 6) as index */
/* offset to next interlace block */
- const int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
+ PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
#endif
- png_debug(1,"in png_do_read_interlace (stock C version)\n");
+ png_debug(1, "in png_do_read_interlace\n");
if (row != NULL && row_info != NULL)
{
png_uint_32 final_width;
@@ -2683,24 +2727,20 @@ png_do_read_interlace(png_structp png_ptr)
}
}
row_info->width = final_width;
- row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,final_width);
+ row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, final_width);
}
#if !defined(PNG_READ_PACKSWAP_SUPPORTED)
- if (&transformations == NULL) /* silence compiler warning */
- return;
+ transformations = transformations; /* silence compiler warning */
#endif
}
-#endif /* !PNG_HAVE_MMX_READ_INTERLACE */
#endif /* PNG_READ_INTERLACING_SUPPORTED */
-#ifndef PNG_HAVE_MMX_READ_FILTER_ROW
void /* PRIVATE */
png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row,
png_bytep prev_row, int filter)
{
png_debug(1, "in png_read_filter_row\n");
- png_debug2(2,"row = %lu, filter = %d\n",
- (unsigned long) png_ptr->row_number, filter);
+ png_debug2(2, "row = %lu, filter = %d\n", png_ptr->row_number, filter);
switch (filter)
{
case PNG_FILTER_VALUE_NONE:
@@ -2804,7 +2844,7 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row,
p = c;
*/
- p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
+ p = (pa <= pb && pa <= pc) ? a : (pb <= pc) ? b : c;
*rp = (png_byte)(((int)(*rp) + p) & 0xff);
rp++;
@@ -2813,29 +2853,30 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row,
}
default:
png_warning(png_ptr, "Ignoring bad adaptive filter type");
- *row=0;
+ *row = 0;
break;
}
}
-#endif /* !PNG_HAVE_MMX_READ_FILTER_ROW */
void /* PRIVATE */
png_read_finish_row(png_structp png_ptr)
{
#ifdef PNG_USE_LOCAL_ARRAYS
+#ifdef PNG_READ_INTERLACING_SUPPORTED
/* arrays to facilitate easy interlacing - use pass (0 - 6) as index */
/* start of interlace block */
- const int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
+ PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
/* offset to next interlace block */
- const int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
+ PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
/* start of interlace block in the y direction */
- const int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
+ PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
/* offset to next interlace block in the y direction */
- const int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
+ PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
+#endif /* PNG_READ_INTERLACING_SUPPORTED */
#endif
png_debug(1, "in png_read_finish_row\n");
@@ -2843,6 +2884,7 @@ png_read_finish_row(png_structp png_ptr)
if (png_ptr->row_number < png_ptr->num_rows)
return;
+#ifdef PNG_READ_INTERLACING_SUPPORTED
if (png_ptr->interlaced)
{
png_ptr->row_number = 0;
@@ -2876,18 +2918,19 @@ png_read_finish_row(png_structp png_ptr)
if (png_ptr->pass < 7)
return;
}
+#endif /* PNG_READ_INTERLACING_SUPPORTED */
if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
{
#ifdef PNG_USE_LOCAL_ARRAYS
- PNG_IDAT;
+ PNG_CONST PNG_IDAT;
#endif
char extra;
int ret;
png_ptr->zstream.next_out = (Byte *)&extra;
png_ptr->zstream.avail_out = (uInt)1;
- for(;;)
+ for (;;)
{
if (!(png_ptr->zstream.avail_in))
{
@@ -2950,19 +2993,21 @@ void /* PRIVATE */
png_read_start_row(png_structp png_ptr)
{
#ifdef PNG_USE_LOCAL_ARRAYS
+#ifdef PNG_READ_INTERLACING_SUPPORTED
/* arrays to facilitate easy interlacing - use pass (0 - 6) as index */
/* start of interlace block */
- const int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
+ PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
/* offset to next interlace block */
- const int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
+ PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
/* start of interlace block in the y direction */
- const int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
+ PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
/* offset to next interlace block in the y direction */
- const int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
+ PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
+#endif
#endif
int max_pixel_depth;
@@ -2971,6 +3016,7 @@ png_read_start_row(png_structp png_ptr)
png_debug(1, "in png_read_start_row\n");
png_ptr->zstream.avail_in = 0;
png_init_read_transformations(png_ptr);
+#ifdef PNG_READ_INTERLACING_SUPPORTED
if (png_ptr->interlaced)
{
if (!(png_ptr->transformations & PNG_INTERLACE))
@@ -2983,10 +3029,12 @@ png_read_start_row(png_structp png_ptr)
png_pass_inc[png_ptr->pass] - 1 -
png_pass_start[png_ptr->pass]) /
png_pass_inc[png_ptr->pass];
+
png_ptr->irowbytes =
PNG_ROWBYTES(png_ptr->pixel_depth, png_ptr->iwidth) + 1;
}
else
+#endif /* PNG_READ_INTERLACING_SUPPORTED */
{
png_ptr->num_rows = png_ptr->height;
png_ptr->iwidth = png_ptr->width;
@@ -3085,11 +3133,11 @@ png_read_start_row(png_structp png_ptr)
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) && \
defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
- if(png_ptr->transformations & PNG_USER_TRANSFORM)
+ if (png_ptr->transformations & PNG_USER_TRANSFORM)
{
- int user_pixel_depth=png_ptr->user_transform_depth*
+ int user_pixel_depth = png_ptr->user_transform_depth*
png_ptr->user_transform_channels;
- if(user_pixel_depth > max_pixel_depth)
+ if (user_pixel_depth > max_pixel_depth)
max_pixel_depth=user_pixel_depth;
}
#endif
@@ -3099,17 +3147,20 @@ defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
row_bytes = ((png_ptr->width + 7) & ~((png_uint_32)7));
/* calculate the maximum bytes needed, adding a byte and a pixel
for safety's sake */
- row_bytes = PNG_ROWBYTES(max_pixel_depth,row_bytes) +
+ row_bytes = PNG_ROWBYTES(max_pixel_depth, row_bytes) +
1 + ((max_pixel_depth + 7) >> 3);
#ifdef PNG_MAX_MALLOC_64K
if (row_bytes > (png_uint_32)65536L)
png_error(png_ptr, "This image requires a row greater than 64KB");
#endif
- png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes+64);
- png_ptr->row_buf = png_ptr->big_row_buf+32;
-#if defined(PNG_DEBUG) && defined(PNG_USE_PNGGCCRD)
- png_ptr->row_buf_size = row_bytes;
-#endif
+
+ if (row_bytes + 64 > png_ptr->old_big_row_buf_size)
+ {
+ png_free(png_ptr, png_ptr->big_row_buf);
+ png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes+64);
+ png_ptr->row_buf = png_ptr->big_row_buf+32;
+ png_ptr->old_big_row_buf_size = row_bytes+64;
+ }
#ifdef PNG_MAX_MALLOC_64K
if ((png_uint_32)png_ptr->rowbytes + 1 > (png_uint_32)65536L)
@@ -3117,16 +3168,23 @@ defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
#endif
if ((png_uint_32)png_ptr->rowbytes > (png_uint_32)(PNG_SIZE_MAX - 1))
png_error(png_ptr, "Row has too many bytes to allocate in memory");
- png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, png_ptr->rowbytes + 1);
+
+ if (png_ptr->rowbytes+1 > png_ptr->old_prev_row_size)
+ {
+ png_free(png_ptr, png_ptr->prev_row);
+ png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)(
+ png_ptr->rowbytes + 1));
+ png_ptr->old_prev_row_size = png_ptr->rowbytes+1;
+ }
png_memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
- png_debug1(3, "width = %lu,\n", (unsigned long) png_ptr->width);
- png_debug1(3, "height = %lu,\n", (unsigned long) png_ptr->height);
- png_debug1(3, "iwidth = %lu,\n", (unsigned long) png_ptr->iwidth);
- png_debug1(3, "num_rows = %lu\n", (unsigned long) png_ptr->num_rows);
- png_debug1(3, "rowbytes = %lu,\n", (unsigned long) png_ptr->rowbytes);
- png_debug1(3, "irowbytes = %lu,\n", (unsigned long) png_ptr->irowbytes);
+ png_debug1(3, "width = %lu,\n", png_ptr->width);
+ png_debug1(3, "height = %lu,\n", png_ptr->height);
+ png_debug1(3, "iwidth = %lu,\n", png_ptr->iwidth);
+ png_debug1(3, "num_rows = %lu\n", png_ptr->num_rows);
+ png_debug1(3, "rowbytes = %lu,\n", png_ptr->rowbytes);
+ png_debug1(3, "irowbytes = %lu,\n", png_ptr->irowbytes);
png_ptr->flags |= PNG_FLAG_ROW_INIT;
}
diff --git a/pngset.c b/pngset.c
index ea2ef0387..f9f162d44 100644
--- a/pngset.c
+++ b/pngset.c
@@ -1,9 +1,9 @@
/* pngset.c - storage of image information into info struct
*
- * Last changed in libpng 1.4.0 May 15, 2007
+ * Last changed in libpng 1.4.0 [July 10, 2008]
* For conditions of distribution and use, see copyright notice in png.h
- * Copyright (c) 1998-2007 Glenn Randers-Pehrson
+ * Copyright (c) 1998-2008 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*
@@ -14,9 +14,8 @@
*/
#include "png.h"
-#include "pngpriv.h"
-
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
+#include "pngpriv.h"
#if defined(PNG_bKGD_SUPPORTED)
void PNGAPI
@@ -26,7 +25,7 @@ png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background)
if (png_ptr == NULL || info_ptr == NULL)
return;
- png_memcpy(&(info_ptr->background), background, sizeof(png_color_16));
+ png_memcpy(&(info_ptr->background), background, png_sizeof(png_color_16));
info_ptr->valid |= PNG_INFO_bKGD;
}
#endif
@@ -41,7 +40,13 @@ png_set_cHRM(png_structp png_ptr, png_infop info_ptr,
png_debug1(1, "in %s storage function\n", "cHRM");
if (png_ptr == NULL || info_ptr == NULL)
return;
-
+ if (!(white_x || white_y || red_x || red_y || green_x || green_y ||
+ blue_x || blue_y))
+ {
+ png_warning(png_ptr,
+ "Ignoring attempt to set all-zero chromaticity values");
+ return;
+ }
if (white_x < 0.0 || white_y < 0.0 ||
red_x < 0.0 || red_y < 0.0 ||
green_x < 0.0 || green_y < 0.0 ||
@@ -93,6 +98,13 @@ png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
if (png_ptr == NULL || info_ptr == NULL)
return;
+ if (!(white_x || white_y || red_x || red_y || green_x || green_y ||
+ blue_x || blue_y))
+ {
+ png_warning(png_ptr,
+ "Ignoring attempt to set all-zero chromaticity values");
+ return;
+ }
if (white_x < 0 || white_y < 0 ||
red_x < 0 || red_y < 0 ||
green_x < 0 || green_y < 0 ||
@@ -102,25 +114,14 @@ png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
"Ignoring attempt to set negative chromaticity value");
return;
}
-#ifdef PNG_FLOATING_POINT_SUPPORTED
- if (white_x > (double) PNG_UINT_31_MAX ||
- white_y > (double) PNG_UINT_31_MAX ||
- red_x > (double) PNG_UINT_31_MAX ||
- red_y > (double) PNG_UINT_31_MAX ||
- green_x > (double) PNG_UINT_31_MAX ||
- green_y > (double) PNG_UINT_31_MAX ||
- blue_x > (double) PNG_UINT_31_MAX ||
- blue_y > (double) PNG_UINT_31_MAX)
-#else
- if (white_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
- white_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
- red_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
- red_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
- green_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
- green_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
- blue_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
- blue_y > (png_fixed_point) PNG_UINT_31_MAX/100000L)
-#endif
+ if (white_x > (png_fixed_point) PNG_UINT_31_MAX ||
+ white_y > (png_fixed_point) PNG_UINT_31_MAX ||
+ red_x > (png_fixed_point) PNG_UINT_31_MAX ||
+ red_y > (png_fixed_point) PNG_UINT_31_MAX ||
+ green_x > (png_fixed_point) PNG_UINT_31_MAX ||
+ green_y > (png_fixed_point) PNG_UINT_31_MAX ||
+ blue_x > (png_fixed_point) PNG_UINT_31_MAX ||
+ blue_y > (png_fixed_point) PNG_UINT_31_MAX )
{
png_warning(png_ptr,
"Ignoring attempt to set chromaticity value exceeding 21474.83");
@@ -172,7 +173,7 @@ png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma)
info_ptr->int_gamma = (int)(gamma*100000.+.5);
#endif
info_ptr->valid |= PNG_INFO_gAMA;
- if(gamma == 0.0)
+ if (gamma == 0.0)
png_warning(png_ptr, "Setting gamma=0");
}
#endif
@@ -196,7 +197,7 @@ png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point
if (int_gamma < 0)
{
png_warning(png_ptr, "Setting negative gamma to zero");
- gamma=0;
+ gamma = 0;
}
else
gamma=int_gamma;
@@ -208,7 +209,7 @@ png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point
info_ptr->int_gamma = gamma;
#endif
info_ptr->valid |= PNG_INFO_gAMA;
- if(gamma == 0)
+ if (gamma == 0)
png_warning(png_ptr, "Setting gamma=0");
}
#endif
@@ -222,7 +223,7 @@ png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist)
png_debug1(1, "in %s storage function\n", "hIST");
if (png_ptr == NULL || info_ptr == NULL)
return;
- if (info_ptr->num_palette <= 0 || info_ptr->num_palette
+ if (info_ptr->num_palette == 0 || info_ptr->num_palette
> PNG_MAX_PALETTE_LENGTH)
{
png_warning(png_ptr,
@@ -236,7 +237,7 @@ png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist)
/* Changed from info->num_palette to PNG_MAX_PALETTE_LENGTH in version
1.2.1 */
png_ptr->hist = (png_uint_16p)png_malloc_warn(png_ptr,
- PNG_MAX_PALETTE_LENGTH * sizeof(png_uint_16));
+ PNG_MAX_PALETTE_LENGTH * png_sizeof(png_uint_16));
if (png_ptr->hist == NULL)
{
png_warning(png_ptr, "Insufficient memory for hIST chunk data");
@@ -317,21 +318,21 @@ png_set_IHDR(png_structp png_ptr, png_infop info_ptr,
* 4. The filter_method is 64 and
* 5. The color_type is RGB or RGBA
*/
- if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&png_ptr->mng_features_permitted)
- png_warning(png_ptr,"MNG features are not allowed in a PNG datastream");
- if(filter_type != PNG_FILTER_TYPE_BASE)
+ if ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&png_ptr->mng_features_permitted)
+ png_warning(png_ptr, "MNG features are not allowed in a PNG datastream");
+ if (filter_type != PNG_FILTER_TYPE_BASE)
{
- if(!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
+ if (!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
(filter_type == PNG_INTRAPIXEL_DIFFERENCING) &&
((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
(color_type == PNG_COLOR_TYPE_RGB ||
color_type == PNG_COLOR_TYPE_RGB_ALPHA)))
png_error(png_ptr, "Unknown filter method in IHDR");
- if(png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)
+ if (png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)
png_warning(png_ptr, "Invalid filter method in IHDR");
}
#else
- if(filter_type != PNG_FILTER_TYPE_BASE)
+ if (filter_type != PNG_FILTER_TYPE_BASE)
png_error(png_ptr, "Unknown filter method in IHDR");
#endif
@@ -361,7 +362,7 @@ png_set_IHDR(png_structp png_ptr, png_infop info_ptr,
- 8) /* extra max_pixel_depth pad */
info_ptr->rowbytes = 0;
else
- info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,width);
+ info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, width);
}
#if defined(PNG_oFFs_SUPPORTED)
@@ -395,11 +396,11 @@ png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
length = png_strlen(purpose) + 1;
png_debug1(3, "allocating purpose for info (%lu bytes)\n",
- (unsigned long) length);
+ (unsigned long)length);
info_ptr->pcal_purpose = (png_charp)png_malloc_warn(png_ptr, length);
if (info_ptr->pcal_purpose == NULL)
{
- png_warning(png_ptr, "Insufficient memory for pCAL purpose");
+ png_warning(png_ptr, "Insufficient memory for pCAL purpose");
return;
}
png_memcpy(info_ptr->pcal_purpose, purpose, length);
@@ -411,21 +412,21 @@ png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
info_ptr->pcal_nparams = (png_byte)nparams;
length = png_strlen(units) + 1;
- png_debug1(3, "allocating units for info (%lu bytes)\n",
+ png_debug1(3, "allocating units for info (%lu bytes)\n",
(unsigned long)length);
info_ptr->pcal_units = (png_charp)png_malloc_warn(png_ptr, length);
if (info_ptr->pcal_units == NULL)
{
- png_warning(png_ptr, "Insufficient memory for pCAL units");
+ png_warning(png_ptr, "Insufficient memory for pCAL units");
return;
}
png_memcpy(info_ptr->pcal_units, units, length);
info_ptr->pcal_params = (png_charpp)png_malloc_warn(png_ptr,
- (png_size_t)((nparams + 1) * sizeof(png_charp)));
+ (png_size_t)((nparams + 1) * png_sizeof(png_charp)));
if (info_ptr->pcal_params == NULL)
{
- png_warning(png_ptr, "Insufficient memory for pCAL params");
+ png_warning(png_ptr, "Insufficient memory for pCAL params");
return;
}
@@ -435,12 +436,12 @@ png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
{
length = png_strlen(params[i]) + 1;
png_debug2(3, "allocating parameter %d for info (%lu bytes)\n", i,
- (unsigned long) length);
+ (unsigned long)length);
info_ptr->pcal_params[i] = (png_charp)png_malloc_warn(png_ptr, length);
if (info_ptr->pcal_params[i] == NULL)
{
- png_warning(png_ptr, "Insufficient memory for pCAL parameter");
- return;
+ png_warning(png_ptr, "Insufficient memory for pCAL parameter");
+ return;
}
png_memcpy(info_ptr->pcal_params[i], params[i], length);
}
@@ -488,7 +489,9 @@ png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr,
info_ptr->scal_s_width = (png_charp)png_malloc_warn(png_ptr, length);
if (info_ptr->scal_s_width == NULL)
{
- png_warning(png_ptr, "Memory allocation failed while processing sCAL");
+ png_warning(png_ptr,
+ "Memory allocation failed while processing sCAL");
+ return;
}
png_memcpy(info_ptr->scal_s_width, swidth, length);
@@ -499,10 +502,11 @@ png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr,
if (info_ptr->scal_s_height == NULL)
{
png_free (png_ptr, info_ptr->scal_s_width);
- png_warning(png_ptr, "Memory allocation failed while processing sCAL");
+ png_warning(png_ptr,
+ "Memory allocation failed while processing sCAL");
+ return;
}
png_memcpy(info_ptr->scal_s_height, sheight, length);
-
info_ptr->valid |= PNG_INFO_sCAL;
#ifdef PNG_FREE_ME_SUPPORTED
info_ptr->free_me |= PNG_FREE_SCAL;
@@ -561,10 +565,10 @@ png_set_PLTE(png_structp png_ptr, png_infop info_ptr,
of num_palette entries,
in case of an invalid PNG file that has too-large sample values. */
png_ptr->palette = (png_colorp)png_malloc(png_ptr,
- PNG_MAX_PALETTE_LENGTH * sizeof(png_color));
+ PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color));
png_memset(png_ptr->palette, 0, PNG_MAX_PALETTE_LENGTH *
- sizeof(png_color));
- png_memcpy(png_ptr->palette, palette, num_palette * sizeof(png_color));
+ png_sizeof(png_color));
+ png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof(png_color));
info_ptr->palette = png_ptr->palette;
info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;
@@ -586,7 +590,7 @@ png_set_sBIT(png_structp png_ptr, png_infop info_ptr,
if (png_ptr == NULL || info_ptr == NULL)
return;
- png_memcpy(&(info_ptr->sig_bit), sig_bit, sizeof(png_color_8));
+ png_memcpy(&(info_ptr->sig_bit), sig_bit, png_sizeof(png_color_8));
info_ptr->valid |= PNG_INFO_sBIT;
}
#endif
@@ -682,23 +686,26 @@ png_set_iCCP(png_structp png_ptr, png_infop info_ptr,
{
png_charp new_iccp_name;
png_charp new_iccp_profile;
+ png_uint_32 length;
png_debug1(1, "in %s storage function\n", "iCCP");
if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL)
return;
- new_iccp_name = (png_charp)png_malloc_warn(png_ptr, png_strlen(name)+1);
+ length = png_strlen(name)+1;
+ new_iccp_name = (png_charp)png_malloc_warn(png_ptr, length);
if (new_iccp_name == NULL)
{
png_warning(png_ptr, "Insufficient memory to process iCCP chunk");
return;
}
- png_strcpy(new_iccp_name, name);
+ png_memcpy(new_iccp_name, name, length);
new_iccp_profile = (png_charp)png_malloc_warn(png_ptr, proflen);
if (new_iccp_profile == NULL)
{
png_free (png_ptr, new_iccp_name);
- png_warning(png_ptr, "Insufficient memory to process iCCP profile");
+ png_warning(png_ptr,
+ "Insufficient memory to process iCCP profile");
return;
}
png_memcpy(new_iccp_profile, profile, (png_size_t)proflen);
@@ -755,14 +762,14 @@ png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
info_ptr->max_text = info_ptr->num_text + num_text + 8;
old_text = info_ptr->text;
info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
- (png_size_t)(info_ptr->max_text * sizeof(png_text)));
+ (png_size_t)(info_ptr->max_text * png_sizeof(png_text)));
if (info_ptr->text == NULL)
{
png_free(png_ptr, old_text);
return(1);
}
png_memcpy(info_ptr->text, old_text, (png_size_t)(old_max *
- sizeof(png_text)));
+ png_sizeof(png_text)));
png_free(png_ptr, old_text);
}
else
@@ -770,7 +777,7 @@ png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
info_ptr->max_text = num_text + 8;
info_ptr->num_text = 0;
info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
- (png_uint_32)(info_ptr->max_text * sizeof(png_text)));
+ (png_size_t)(info_ptr->max_text * png_sizeof(png_text)));
if (info_ptr->text == NULL)
return(1);
#ifdef PNG_FREE_ME_SUPPORTED
@@ -782,8 +789,8 @@ png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
}
for (i = 0; i < num_text; i++)
{
- png_size_t text_length,key_len;
- png_size_t lang_len,lang_key_len;
+ png_size_t text_length, key_len;
+ png_size_t lang_len, lang_key_len;
png_textp textp = &(info_ptr->text[info_ptr->num_text]);
if (text_ptr[i].key == NULL)
@@ -791,7 +798,7 @@ png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
key_len = png_strlen(text_ptr[i].key);
- if(text_ptr[i].compression <= 0)
+ if (text_ptr[i].compression <= 0)
{
lang_len = 0;
lang_key_len = 0;
@@ -820,7 +827,7 @@ png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
{
text_length = 0;
#ifdef PNG_iTXt_SUPPORTED
- if(text_ptr[i].compression > 0)
+ if (text_ptr[i].compression > 0)
textp->compression = PNG_ITXT_COMPRESSION_NONE;
else
#endif
@@ -833,26 +840,27 @@ png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
}
textp->key = (png_charp)png_malloc_warn(png_ptr,
- (png_size_t)(key_len + text_length + lang_len + lang_key_len + 4));
+ (png_size_t)
+ (key_len + text_length + lang_len + lang_key_len + 4));
if (textp->key == NULL)
return(1);
png_debug2(2, "Allocated %lu bytes at %x in png_set_text\n",
- (unsigned long)(png_uint_32)(key_len + lang_len + lang_key_len
- + text_length + 4),
+ (unsigned long)(png_uint_32)
+ (key_len + lang_len + lang_key_len + text_length + 4),
(int)textp->key);
png_memcpy(textp->key, text_ptr[i].key,
(png_size_t)(key_len));
- *(textp->key+key_len) = '\0';
+ *(textp->key + key_len) = '\0';
#ifdef PNG_iTXt_SUPPORTED
if (text_ptr[i].compression > 0)
{
textp->lang=textp->key + key_len + 1;
png_memcpy(textp->lang, text_ptr[i].lang, lang_len);
- *(textp->lang+lang_len) = '\0';
+ *(textp->lang + lang_len) = '\0';
textp->lang_key=textp->lang + lang_len + 1;
png_memcpy(textp->lang_key, text_ptr[i].lang_key, lang_key_len);
- *(textp->lang_key+lang_key_len) = '\0';
+ *(textp->lang_key + lang_key_len) = '\0';
textp->text=textp->lang_key + lang_key_len + 1;
}
else
@@ -864,13 +872,13 @@ png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
#endif
textp->text=textp->key + key_len + 1;
}
- if(text_length)
+ if (text_length)
png_memcpy(textp->text, text_ptr[i].text,
(png_size_t)(text_length));
- *(textp->text+text_length) = '\0';
+ *(textp->text + text_length) = '\0';
#ifdef PNG_iTXt_SUPPORTED
- if(textp->compression > 0)
+ if (textp->compression > 0)
{
textp->text_length = 0;
textp->itxt_length = text_length;
@@ -899,7 +907,7 @@ png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time)
(png_ptr->mode & PNG_WROTE_tIME))
return;
- png_memcpy(&(info_ptr->mod_time), mod_time, sizeof(png_time));
+ png_memcpy(&(info_ptr->mod_time), mod_time, png_sizeof(png_time));
info_ptr->valid |= PNG_INFO_tIME;
}
#endif
@@ -920,30 +928,45 @@ png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
* we do it for backward compatibility with the way the png_handle_tRNS
* function used to do the allocation.
*/
+
#ifdef PNG_FREE_ME_SUPPORTED
png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
#endif
+
/* Changed from num_trans to PNG_MAX_PALETTE_LENGTH in version 1.2.1 */
png_ptr->trans = info_ptr->trans = (png_bytep)png_malloc(png_ptr,
- PNG_MAX_PALETTE_LENGTH);
- if (num_trans <= PNG_MAX_PALETTE_LENGTH)
+ (png_size_t)PNG_MAX_PALETTE_LENGTH);
+ if (num_trans > 0 && num_trans <= PNG_MAX_PALETTE_LENGTH)
png_memcpy(info_ptr->trans, trans, (png_size_t)num_trans);
-#ifdef PNG_FREE_ME_SUPPORTED
- info_ptr->free_me |= PNG_FREE_TRNS;
-#else
- png_ptr->flags |= PNG_FLAG_FREE_TRNS;
-#endif
}
if (trans_values != NULL)
{
+ int sample_max = (1 << info_ptr->bit_depth);
+ if ((info_ptr->color_type == PNG_COLOR_TYPE_GRAY &&
+ (int)trans_values->gray > sample_max) ||
+ (info_ptr->color_type == PNG_COLOR_TYPE_RGB &&
+ ((int)trans_values->red > sample_max ||
+ (int)trans_values->green > sample_max ||
+ (int)trans_values->blue > sample_max)))
+ png_warning(png_ptr,
+ "tRNS chunk has out-of-range samples for bit_depth");
png_memcpy(&(info_ptr->trans_values), trans_values,
- sizeof(png_color_16));
+ png_sizeof(png_color_16));
if (num_trans == 0)
num_trans = 1;
}
+
info_ptr->num_trans = (png_uint_16)num_trans;
- info_ptr->valid |= PNG_INFO_tRNS;
+ if (num_trans != 0)
+ {
+ info_ptr->valid |= PNG_INFO_tRNS;
+#ifdef PNG_FREE_ME_SUPPORTED
+ info_ptr->free_me |= PNG_FREE_TRNS;
+#else
+ png_ptr->flags |= PNG_FLAG_FREE_TRNS;
+#endif
+ }
}
#endif
@@ -966,7 +989,8 @@ png_set_sPLT(png_structp png_ptr,
return;
np = (png_sPLT_tp)png_malloc_warn(png_ptr,
- (info_ptr->splt_palettes_num + nentries) * sizeof(png_sPLT_t));
+ (info_ptr->splt_palettes_num + nentries) *
+ (png_size_t)png_sizeof(png_sPLT_t));
if (np == NULL)
{
png_warning(png_ptr, "No memory for sPLT palettes");
@@ -974,7 +998,7 @@ png_set_sPLT(png_structp png_ptr,
}
png_memcpy(np, info_ptr->splt_palettes,
- info_ptr->splt_palettes_num * sizeof(png_sPLT_t));
+ info_ptr->splt_palettes_num * png_sizeof(png_sPLT_t));
png_free(png_ptr, info_ptr->splt_palettes);
info_ptr->splt_palettes=NULL;
@@ -982,15 +1006,29 @@ png_set_sPLT(png_structp png_ptr,
{
png_sPLT_tp to = np + info_ptr->splt_palettes_num + i;
png_sPLT_tp from = entries + i;
+ png_uint_32 length;
- to->name = (png_charp)png_malloc(png_ptr, png_strlen(from->name) + 1);
- /* TODO: use png_malloc_warn */
- png_strcpy(to->name, from->name);
- to->entries = (png_sPLT_entryp)png_malloc(png_ptr,
- from->nentries * sizeof(png_sPLT_entry));
- /* TODO: use png_malloc_warn */
+ length = png_strlen(from->name) + 1;
+ to->name = (png_charp)png_malloc_warn(png_ptr, (png_size_t)length);
+ if (to->name == NULL)
+ {
+ png_warning(png_ptr,
+ "Out of memory while processing sPLT chunk");
+ continue;
+ }
+ png_memcpy(to->name, from->name, length);
+ to->entries = (png_sPLT_entryp)png_malloc_warn(png_ptr,
+ (png_size_t)(from->nentries * png_sizeof(png_sPLT_entry)));
+ if (to->entries == NULL)
+ {
+ png_warning(png_ptr,
+ "Out of memory while processing sPLT chunk");
+ png_free(png_ptr, to->name);
+ to->name = NULL;
+ continue;
+ }
png_memcpy(to->entries, from->entries,
- from->nentries * sizeof(png_sPLT_entry));
+ from->nentries * png_sizeof(png_sPLT_entry));
to->nentries = from->nentries;
to->depth = from->depth;
}
@@ -1016,38 +1054,48 @@ png_set_unknown_chunks(png_structp png_ptr,
return;
np = (png_unknown_chunkp)png_malloc_warn(png_ptr,
- (info_ptr->unknown_chunks_num + num_unknowns) *
- sizeof(png_unknown_chunk));
+ (png_size_t)((info_ptr->unknown_chunks_num + num_unknowns) *
+ png_sizeof(png_unknown_chunk)));
if (np == NULL)
{
- png_warning(png_ptr, "Out of memory while processing unknown chunk");
+ png_warning(png_ptr,
+ "Out of memory while processing unknown chunk");
return;
}
png_memcpy(np, info_ptr->unknown_chunks,
- info_ptr->unknown_chunks_num * sizeof(png_unknown_chunk));
+ info_ptr->unknown_chunks_num * png_sizeof(png_unknown_chunk));
png_free(png_ptr, info_ptr->unknown_chunks);
info_ptr->unknown_chunks=NULL;
for (i = 0; i < num_unknowns; i++)
{
- png_unknown_chunkp to = np + info_ptr->unknown_chunks_num + i;
- png_unknown_chunkp from = unknowns + i;
-
- png_strncpy((png_charp)to->name, (png_charp)from->name, 5);
- to->data = (png_bytep)png_malloc_warn(png_ptr, from->size);
- if (to->data == NULL)
- {
- png_warning(png_ptr, "Out of memory processing unknown chunk");
- }
- else
- {
- png_memcpy(to->data, from->data, from->size);
- to->size = from->size;
-
- /* note our location in the read or write sequence */
- to->location = (png_byte)(png_ptr->mode & 0xff);
- }
+ png_unknown_chunkp to = np + info_ptr->unknown_chunks_num + i;
+ png_unknown_chunkp from = unknowns + i;
+
+ png_memcpy((png_charp)to->name,
+ (png_charp)from->name,
+ png_sizeof(from->name));
+ to->name[png_sizeof(to->name)-1] = '\0';
+ to->size = from->size;
+ /* note our location in the read or write sequence */
+ to->location = (png_byte)(png_ptr->mode & 0xff);
+
+ if (from->size == 0)
+ to->data=NULL;
+ else
+ {
+ to->data = (png_bytep)png_malloc_warn(png_ptr,
+ (png_size_t)from->size);
+ if (to->data == NULL)
+ {
+ png_warning(png_ptr,
+ "Out of memory while processing unknown chunk");
+ to->size = 0;
+ }
+ else
+ png_memcpy(to->data, from->data, from->size);
+ }
}
info_ptr->unknown_chunks = np;
@@ -1060,12 +1108,13 @@ void PNGAPI
png_set_unknown_chunk_location(png_structp png_ptr, png_infop info_ptr,
int chunk, int location)
{
- if(png_ptr != NULL && info_ptr != NULL && chunk >= 0 && chunk <
+ if (png_ptr != NULL && info_ptr != NULL && chunk >= 0 && chunk <
(int)info_ptr->unknown_chunks_num)
info_ptr->unknown_chunks[chunk].location = (png_byte)location;
}
#endif
+
#if defined(PNG_MNG_FEATURES_SUPPORTED)
png_uint_32 PNGAPI
png_permit_mng_features (png_structp png_ptr, png_uint_32 mng_features)
@@ -1090,12 +1139,12 @@ png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep
return;
if (num_chunks == 0)
{
- if(keep == PNG_HANDLE_CHUNK_ALWAYS || keep == PNG_HANDLE_CHUNK_IF_SAFE)
+ if (keep == PNG_HANDLE_CHUNK_ALWAYS || keep == PNG_HANDLE_CHUNK_IF_SAFE)
png_ptr->flags |= PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
else
png_ptr->flags &= ~PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
- if(keep == PNG_HANDLE_CHUNK_ALWAYS)
+ if (keep == PNG_HANDLE_CHUNK_ALWAYS)
png_ptr->flags |= PNG_FLAG_KEEP_UNSAFE_CHUNKS;
else
png_ptr->flags &= ~PNG_FLAG_KEEP_UNSAFE_CHUNKS;
@@ -1105,19 +1154,20 @@ png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep
return;
old_num_chunks=png_ptr->num_chunk_list;
new_list=(png_bytep)png_malloc(png_ptr,
- (png_size_t)(5*(num_chunks+old_num_chunks)));
- if(png_ptr->chunk_list != NULL)
+ (png_size_t)
+ (5*(num_chunks + old_num_chunks)));
+ if (png_ptr->chunk_list != NULL)
{
png_memcpy(new_list, png_ptr->chunk_list,
(png_size_t)(5*old_num_chunks));
png_free(png_ptr, png_ptr->chunk_list);
png_ptr->chunk_list=NULL;
}
- png_memcpy(new_list+5*old_num_chunks, chunk_list,
+ png_memcpy(new_list + 5*old_num_chunks, chunk_list,
(png_size_t)(5*num_chunks));
- for (p=new_list+5*old_num_chunks+4, i=0; i<num_chunks; i++, p+=5)
+ for (p=new_list + 5*old_num_chunks + 4, i = 0; i<num_chunks; i++, p += 5)
*p=(png_byte)keep;
- png_ptr->num_chunk_list=old_num_chunks+num_chunks;
+ png_ptr->num_chunk_list=old_num_chunks + num_chunks;
png_ptr->chunk_list=new_list;
#ifdef PNG_FREE_ME_SUPPORTED
png_ptr->free_me |= PNG_FREE_LIST;
@@ -1147,22 +1197,22 @@ png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers)
if (png_ptr == NULL || info_ptr == NULL)
return;
- if(info_ptr->row_pointers && (info_ptr->row_pointers != row_pointers))
+ if (info_ptr->row_pointers && (info_ptr->row_pointers != row_pointers))
png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
info_ptr->row_pointers = row_pointers;
- if(row_pointers)
+ if (row_pointers)
info_ptr->valid |= PNG_INFO_IDAT;
}
#endif
#ifdef PNG_WRITE_SUPPORTED
void PNGAPI
-png_set_compression_buffer_size(png_structp png_ptr, png_size_t size)
+png_set_compression_buffer_size(png_structp png_ptr,
+ png_size_t size)
{
if (png_ptr == NULL)
return;
- if(png_ptr->zbuf)
- png_free(png_ptr, png_ptr->zbuf);
+ png_free(png_ptr, png_ptr->zbuf);
png_ptr->zbuf_size = size;
png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, size);
png_ptr->zstream.next_out = png_ptr->zbuf;
@@ -1174,73 +1224,10 @@ void PNGAPI
png_set_invalid(png_structp png_ptr, png_infop info_ptr, int mask)
{
if (png_ptr && info_ptr)
- info_ptr->valid &= ~(mask);
+ info_ptr->valid &= ~mask;
}
-#ifdef PNG_ASSEMBLER_CODE_SUPPORTED
-/* this function was added to libpng 1.2.0 and should always exist by default */
-void PNGAPI
-png_set_asm_flags (png_structp png_ptr, png_uint_32 asm_flags)
-{
- png_uint_32 settable_asm_flags;
- png_uint_32 settable_mmx_flags;
-
- if (png_ptr == NULL)
- return;
-
- settable_mmx_flags =
-#ifdef PNG_MMX_CODE_SUPPORTED
-#ifdef PNG_HAVE_MMX_COMBINE_ROW
- PNG_ASM_FLAG_MMX_READ_COMBINE_ROW |
-#endif
-#ifdef PNG_HAVE_MMX_READ_INTERLACE
- PNG_ASM_FLAG_MMX_READ_INTERLACE |
-#endif
-#ifdef PNG_HAVE_MMX_READ_FILTER_ROW
- PNG_ASM_FLAG_MMX_READ_FILTER_SUB |
- PNG_ASM_FLAG_MMX_READ_FILTER_UP |
- PNG_ASM_FLAG_MMX_READ_FILTER_AVG |
- PNG_ASM_FLAG_MMX_READ_FILTER_PAETH |
-#endif
-#endif
- 0;
-
- /* could be some non-MMX ones in the future, but not currently: */
- settable_asm_flags = settable_mmx_flags;
-
-#ifdef PNG_MMX_CODE_SUPPORTED
- if (!(png_ptr->asm_flags & PNG_ASM_FLAG_MMX_SUPPORT_COMPILED) ||
- !(png_ptr->asm_flags & PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU))
- {
- /* clear all MMX flags if MMX isn't supported */
- settable_asm_flags &= ~settable_mmx_flags;
- png_ptr->asm_flags &= ~settable_mmx_flags;
- }
-#endif
-
- /* we're replacing the settable bits with those passed in by the user,
- * so first zero them out of the master copy, then bitwise-OR in the
- * allowed subset that was requested */
-
- png_ptr->asm_flags &= ~settable_asm_flags; /* zero them */
- png_ptr->asm_flags |= (asm_flags & settable_asm_flags); /* set them */
-}
-#endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
-
-#ifdef PNG_MMX_CODE_SUPPORTED
-/* this function was added to libpng 1.2.0 */
-void PNGAPI
-png_set_mmx_thresholds (png_structp png_ptr,
- png_byte mmx_bitdepth_threshold,
- png_uint_32 mmx_rowbytes_threshold)
-{
- if (png_ptr == NULL)
- return;
- png_ptr->mmx_bitdepth_threshold = mmx_bitdepth_threshold;
- png_ptr->mmx_rowbytes_threshold = mmx_rowbytes_threshold;
-}
-#endif /* ?PNG_MMX_CODE_SUPPORTED */
#ifdef PNG_SET_USER_LIMITS_SUPPORTED
/* this function was added to libpng 1.2.6 */
@@ -1252,7 +1239,7 @@ png_set_user_limits (png_structp png_ptr, png_uint_32 user_width_max,
* rejected by png_set_IHDR(). To accept any PNG datastream
* regardless of dimensions, set both limits to 0x7ffffffL.
*/
- if(png_ptr == NULL) return;
+ if (png_ptr == NULL) return;
png_ptr->user_width_max = user_width_max;
png_ptr->user_height_max = user_height_max;
}
@@ -1270,5 +1257,4 @@ png_set_benign_errors(png_structp png_ptr, int allowed)
png_ptr->flags &= ~PNG_FLAG_BENIGN_ERRORS_WARN;
}
#endif /* PNG_BENIGN_ERRORS_SUPPORTED */
-
#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
diff --git a/pngtest.c b/pngtest.c
index 2bb2016bb..5bad510a3 100644
--- a/pngtest.c
+++ b/pngtest.c
@@ -1,9 +1,9 @@
/* pngtest.c - a simple test program to test libpng
*
- * Last changed in libpng 1.4.0 May 15, 2007
+ * Last changed in libpng 1.4.0 [July 10, 2008]
* For conditions of distribution and use, see copyright notice in png.h
- * Copyright (c) 1998-2007 Glenn Randers-Pehrson
+ * Copyright (c) 1998-2008 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*
@@ -29,18 +29,14 @@
*/
#include "png.h"
+#include "pngpriv.h"
-#if defined(_WIN32_WCE)
-# if _WIN32_WCE < 211
- __error__ "(f|w)printf functions are not supported on old WindowsCE";
-# endif
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
+# include <stdio.h>
+# include <stdlib.h>
+# define FCLOSE(file) fclose(file)
-#ifdef PNG_NO_STDIO
- typedef FILE * png_FILE_p;
+#if defined(PNG_NO_STDIO)
+ typedef FILE * png_FILE_p;
#endif
/* Makes pngtest verbose so we can find problems (needs to be before png.h) */
@@ -52,11 +48,6 @@
# define SINGLE_ROWBUF_ALLOC /* makes buffer overruns easier to nail */
#endif
-#if defined(PNG_TIME_RFC1123_SUPPORTED)
-static int tIME_chunk_present=0;
-static char tIME_string[30] = "no tIME chunk present in file";
-#endif
-
/* Turn on CPU timing
#define PNGTEST_TIMING
*/
@@ -70,6 +61,12 @@ static float t_start, t_stop, t_decode, t_encode, t_misc;
#include <time.h>
#endif
+#if defined(PNG_TIME_RFC1123_SUPPORTED)
+#define PNG_tIME_STRING_LENGTH 30
+static int tIME_chunk_present = 0;
+static char tIME_string[PNG_tIME_STRING_LENGTH] = "no tIME chunk present in file";
+#endif
+
static int verbose = 0;
int test_one_file PNGARG((PNG_CONST char *inname, PNG_CONST char *outname));
@@ -93,24 +90,24 @@ int test_one_file PNGARG((PNG_CONST char *inname, PNG_CONST char *outname));
#endif
/* example of using row callbacks to make a simple progress meter */
-static int status_pass=1;
-static int status_dots_requested=0;
-static int status_dots=1;
+static int status_pass = 1;
+static int status_dots_requested = 0;
+static int status_dots = 1;
void
read_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass);
void
read_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass)
{
- if(png_ptr == NULL || row_number > PNG_UINT_31_MAX) return;
- if(status_pass != pass)
+ if (png_ptr == NULL || row_number > PNG_UINT_31_MAX) return;
+ if (status_pass != pass)
{
- fprintf(stdout,"\n Pass %d: ",pass);
+ fprintf(stdout, "\n Pass %d: ", pass);
status_pass = pass;
status_dots = 31;
}
status_dots--;
- if(status_dots == 0)
+ if (status_dots == 0)
{
fprintf(stdout, "\n ");
status_dots=30;
@@ -123,7 +120,7 @@ write_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass);
void
write_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass)
{
- if(png_ptr == NULL || row_number > PNG_UINT_31_MAX || pass > 7) return;
+ if (png_ptr == NULL || row_number > PNG_UINT_31_MAX || pass > 7) return;
fprintf(stdout, "w");
}
@@ -138,8 +135,8 @@ count_filters(png_structp png_ptr, png_row_infop row_info, png_bytep data);
void
count_filters(png_structp png_ptr, png_row_infop row_info, png_bytep data)
{
- if(png_ptr != NULL && row_info != NULL)
- ++filters_used[*(data-1)];
+ if (png_ptr != NULL && row_info != NULL)
+ ++filters_used[*(data - 1)];
}
#endif
@@ -155,7 +152,7 @@ void
count_zero_samples(png_structp png_ptr, png_row_infop row_info, png_bytep data)
{
png_bytep dp = data;
- if(png_ptr == NULL)return;
+ if (png_ptr == NULL)return;
/* contents of row_info:
* png_uint_32 width width of row
@@ -169,44 +166,44 @@ count_zero_samples(png_structp png_ptr, png_row_infop row_info, png_bytep data)
/* 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)
+ if (row_info->color_type == 0 || row_info->color_type == 3)
{
- int pos=0;
+ int pos = 0;
png_uint_32 n, nstop;
- for (n=0, nstop=row_info->width; n<nstop; n++)
+ for (n = 0, nstop=row_info->width; n<nstop; n++)
{
- if(row_info->bit_depth == 1)
+ if (row_info->bit_depth == 1)
{
- if(((*dp << pos++ ) & 0x80) == 0) zero_samples++;
- if(pos == 8)
+ if (((*dp << pos++ ) & 0x80) == 0) zero_samples++;
+ if (pos == 8)
{
pos = 0;
dp++;
}
}
- if(row_info->bit_depth == 2)
+ if (row_info->bit_depth == 2)
{
- if(((*dp << (pos+=2)) & 0xc0) == 0) zero_samples++;
- if(pos == 8)
+ if (((*dp << (pos+=2)) & 0xc0) == 0) zero_samples++;
+ if (pos == 8)
{
pos = 0;
dp++;
}
}
- if(row_info->bit_depth == 4)
+ if (row_info->bit_depth == 4)
{
- if(((*dp << (pos+=4)) & 0xf0) == 0) zero_samples++;
- if(pos == 8)
+ if (((*dp << (pos+=4)) & 0xf0) == 0) zero_samples++;
+ if (pos == 8)
{
pos = 0;
dp++;
}
}
- if(row_info->bit_depth == 8)
- if(*dp++ == 0) zero_samples++;
- if(row_info->bit_depth == 16)
+ if (row_info->bit_depth == 8)
+ if (*dp++ == 0) zero_samples++;
+ if (row_info->bit_depth == 16)
{
- if((*dp | *(dp+1)) == 0) zero_samples++;
+ if ((*dp | *(dp+1)) == 0) zero_samples++;
dp+=2;
}
}
@@ -216,24 +213,24 @@ count_zero_samples(png_structp png_ptr, png_row_infop row_info, png_bytep data)
png_uint_32 n, nstop;
int channel;
int color_channels = row_info->channels;
- if(row_info->color_type > 3)color_channels--;
+ if (row_info->color_type > 3)color_channels--;
- for (n=0, nstop=row_info->width; n<nstop; 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) zero_samples++;
- if(row_info->bit_depth == 16)
+ if (row_info->bit_depth == 8)
+ if (*dp++ == 0) zero_samples++;
+ if (row_info->bit_depth == 16)
{
- if((*dp | *(dp+1)) == 0) zero_samples++;
+ if ((*dp | *(dp+1)) == 0) zero_samples++;
dp+=2;
}
}
- if(row_info->color_type > 3)
+ if (row_info->color_type > 3)
{
dp++;
- if(row_info->bit_depth == 16)dp++;
+ if (row_info->bit_depth == 16)dp++;
}
}
}
@@ -261,6 +258,7 @@ pngtest_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
* instead of an int, which is what fread() actually returns.
*/
check = fread(data, 1, length, (png_FILE_p)png_ptr->io_ptr);
+
if (check != length)
{
png_error(png_ptr, "Read Error!");
@@ -300,7 +298,7 @@ pngtest_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
read = MIN(NEAR_BUF_SIZE, remaining);
err = fread(buf, 1, 1, io_ptr);
png_memcpy(data, buf, read); /* copy far buffer to near buffer */
- if(err != read)
+ if (err != read)
break;
else
check += err;
@@ -391,7 +389,6 @@ pngtest_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
png_error(png_ptr, "Write Error");
}
}
-
#endif /* USE_FAR_KEYWORD */
/* This function is called when there is a warning, but the library thinks
@@ -455,6 +452,7 @@ void png_debug_free PNGARG((png_structp png_ptr, png_voidp ptr));
png_voidp
png_debug_malloc(png_structp png_ptr, png_alloc_size_t size)
{
+
/* png_malloc has already tested for NULL; png_create_struct calls
png_debug_malloc directly, with png_ptr == NULL which is OK */
@@ -467,7 +465,8 @@ png_debug_malloc(png_structp png_ptr, png_alloc_size_t size)
/* Disable malloc_fn and free_fn */
memory_infop pinfo;
png_set_mem_fn(png_ptr, NULL, NULL, NULL);
- pinfo = (memory_infop)png_malloc(png_ptr, sizeof(*pinfo));
+ pinfo = (memory_infop)png_malloc(png_ptr,
+ png_sizeof(*pinfo));
pinfo->size = size;
current_allocation += size;
total_allocation += size;
@@ -476,7 +475,8 @@ png_debug_malloc(png_structp png_ptr, png_alloc_size_t size)
maximum_allocation = current_allocation;
pinfo->pointer = png_malloc(png_ptr, size);
/* Restore malloc_fn and free_fn */
- png_set_mem_fn(png_ptr, NULL, png_debug_malloc, png_debug_free);
+ png_set_mem_fn(png_ptr,
+ NULL, png_debug_malloc, png_debug_free);
if (size != 0 && pinfo->pointer == NULL)
{
current_allocation -= size;
@@ -538,8 +538,8 @@ png_debug_free(png_structp png_ptr, png_voidp ptr)
}
/* Finally free the data. */
- if(verbose)
- printf("Freeing %x\n",ptr);
+ if (verbose)
+ printf("Freeing %x\n", ptr);
png_free_default(png_ptr, ptr);
ptr=NULL;
}
@@ -547,8 +547,6 @@ png_debug_free(png_structp png_ptr, png_voidp ptr)
/* END of code to test memory allocation/deallocation */
-
-
/* Demonstration of user chunk support of the sTER and vpAg chunks */
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
@@ -605,8 +603,8 @@ static int read_user_chunk_callback(png_struct *png_ptr,
user_chunk_data=(png_uint_32 *) png_get_user_chunk_ptr(png_ptr);
- user_chunk_data[1]=png_get_uint_31(png_ptr,chunk->data);
- user_chunk_data[2]=png_get_uint_31(png_ptr,chunk->data + 4);
+ user_chunk_data[1]=png_get_uint_31(png_ptr, chunk->data);
+ user_chunk_data[2]=png_get_uint_31(png_ptr, chunk->data + 4);
user_chunk_data[3]=(png_uint_32)chunk->data[8];
return (1);
@@ -656,17 +654,19 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
if ((fpout = fopen(outname, "wb")) == NULL)
{
fprintf(STDERR, "Could not open output file %s\n", outname);
- fclose(fpin);
+ FCLOSE(fpin);
return (1);
}
png_debug(0, "Allocating read and write structures\n");
#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
- read_ptr = png_create_read_struct_2(PNG_LIBPNG_VER_STRING,
- NULL, NULL, NULL, NULL,
- png_debug_malloc, png_debug_free);
+ read_ptr =
+ png_create_read_struct_2(PNG_LIBPNG_VER_STRING, NULL,
+ NULL, NULL, NULL,
+ (png_malloc_ptr)png_debug_malloc, (png_free_ptr)png_debug_free);
#else
- read_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
+ read_ptr =
+ png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
#endif
#if defined(PNG_NO_STDIO)
png_set_error_fn(read_ptr, (png_voidp)inname, pngtest_error,
@@ -674,22 +674,22 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
#endif
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
- user_chunk_data[0]=0;
- user_chunk_data[1]=0;
- user_chunk_data[2]=0;
- user_chunk_data[3]=0;
+ user_chunk_data[0] = 0;
+ user_chunk_data[1] = 0;
+ user_chunk_data[2] = 0;
+ user_chunk_data[3] = 0;
png_set_read_user_chunk_fn(read_ptr, user_chunk_data,
read_user_chunk_callback);
-#endif
+#endif
#ifdef PNG_WRITE_SUPPORTED
#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
- write_ptr = png_create_write_struct_2(PNG_LIBPNG_VER_STRING,
- NULL, NULL, NULL, NULL,
- png_debug_malloc, png_debug_free);
+ write_ptr =
+ png_create_write_struct_2(PNG_LIBPNG_VER_STRING, NULL,
+ NULL, NULL, NULL, png_debug_malloc, png_debug_free);
#else
- write_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,
- NULL, NULL, NULL);
+ write_ptr =
+ png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
#endif
#if defined(PNG_NO_STDIO)
png_set_error_fn(write_ptr, (png_voidp)inname, pngtest_error,
@@ -720,12 +720,12 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
png_destroy_info_struct(write_ptr, &write_end_info_ptr);
png_destroy_write_struct(&write_ptr, &write_info_ptr);
#endif
- fclose(fpin);
- fclose(fpout);
+ FCLOSE(fpin);
+ FCLOSE(fpout);
return (1);
}
#ifdef USE_FAR_KEYWORD
- png_memcpy(png_jmpbuf(read_ptr), jmpbuf, sizeof(jmp_buf));
+ png_memcpy(png_jmpbuf(read_ptr), jmpbuf, png_sizeof(jmp_buf));
#endif
#ifdef PNG_WRITE_SUPPORTED
@@ -742,12 +742,12 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
#ifdef PNG_WRITE_SUPPORTED
png_destroy_write_struct(&write_ptr, &write_info_ptr);
#endif
- fclose(fpin);
- fclose(fpout);
+ FCLOSE(fpin);
+ FCLOSE(fpout);
return (1);
}
#ifdef USE_FAR_KEYWORD
- png_memcpy(png_jmpbuf(write_ptr), jmpbuf, sizeof(jmp_buf));
+ png_memcpy(png_jmpbuf(write_ptr), jmpbuf, png_sizeof(jmp_buf));
#endif
#endif
#endif
@@ -769,7 +769,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
# endif
# endif
#endif
- if(status_dots_requested == 1)
+ if (status_dots_requested == 1)
{
#ifdef PNG_WRITE_SUPPORTED
png_set_write_status_fn(write_ptr, write_row_callback);
@@ -787,13 +787,13 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
{
int i;
- for(i=0; i<256; i++)
- filters_used[i]=0;
+ for (i = 0; i<256; i++)
+ filters_used[i] = 0;
png_set_read_user_transform_fn(read_ptr, count_filters);
}
#endif
#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
- zero_samples=0;
+ zero_samples = 0;
png_set_write_user_transform_fn(write_ptr, count_zero_samples);
#endif
@@ -801,13 +801,15 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
# ifndef PNG_HANDLE_CHUNK_ALWAYS
# define PNG_HANDLE_CHUNK_ALWAYS 3
# endif
- png_set_keep_unknown_chunks(read_ptr, PNG_HANDLE_CHUNK_ALWAYS, NULL, 0);
+ png_set_keep_unknown_chunks(read_ptr, PNG_HANDLE_CHUNK_ALWAYS,
+ NULL, 0);
#endif
#if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
# ifndef PNG_HANDLE_CHUNK_IF_SAFE
# define PNG_HANDLE_CHUNK_IF_SAFE 2
# endif
- png_set_keep_unknown_chunks(write_ptr, PNG_HANDLE_CHUNK_IF_SAFE, NULL, 0);
+ png_set_keep_unknown_chunks(write_ptr, PNG_HANDLE_CHUNK_IF_SAFE,
+ NULL, 0);
#endif
png_debug(0, "Reading info struct\n");
@@ -936,7 +938,8 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
png_int_32 offset_x, offset_y;
int unit_type;
- if (png_get_oFFs(read_ptr, read_info_ptr,&offset_x,&offset_y,&unit_type))
+ if (png_get_oFFs(read_ptr, read_info_ptr, &offset_x, &offset_y,
+ &unit_type))
{
png_set_oFFs(write_ptr, write_info_ptr, offset_x, offset_y, unit_type);
}
@@ -1025,10 +1028,13 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
{
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
+ /* we have to use png_memcpy 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));
+ png_memcpy(tIME_string,
+ png_convert_to_rfc1123(read_ptr, mod_time),
+ png_sizeof(tIME_string));
+ tIME_string[png_sizeof(tIME_string) - 1] = '\0';
tIME_chunk_present++;
#endif /* PNG_TIME_RFC1123_SUPPORTED */
}
@@ -1043,12 +1049,19 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
if (png_get_tRNS(read_ptr, read_info_ptr, &trans, &num_trans,
&trans_values))
{
- png_set_tRNS(write_ptr, write_info_ptr, trans, num_trans,
- trans_values);
+ int sample_max = (1 << read_info_ptr->bit_depth);
+ /* libpng doesn't reject a tRNS chunk with out-of-range samples */
+ if (!((read_info_ptr->color_type == PNG_COLOR_TYPE_GRAY &&
+ (int)trans_values->gray > sample_max) ||
+ (read_info_ptr->color_type == PNG_COLOR_TYPE_RGB &&
+ ((int)trans_values->red > sample_max ||
+ (int)trans_values->green > sample_max ||
+ (int)trans_values->blue > sample_max))))
+ png_set_tRNS(write_ptr, write_info_ptr, trans, num_trans,
+ trans_values);
}
}
#endif
-
#if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
{
png_unknown_chunkp unknowns;
@@ -1085,11 +1098,11 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
unsigned char
ster_chunk_data[1];
- if(verbose)
+ if (verbose)
fprintf(STDERR, "stereo mode = %lu\n",
- (unsigned long)(user_chunk_data[0]-1));
- ster_chunk_data[0]=(unsigned char)(user_chunk_data[0]-1);
- png_write_chunk(write_ptr,png_sTER,ster_chunk_data,1);
+ (unsigned long)(user_chunk_data[0] - 1));
+ ster_chunk_data[0]=(unsigned char)(user_chunk_data[0] - 1);
+ png_write_chunk(write_ptr, png_sTER, ster_chunk_data, 1);
}
if (user_chunk_data[1] != 0 || user_chunk_data[2] != 0)
{
@@ -1098,7 +1111,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
unsigned char
vpag_chunk_data[9];
- if(verbose)
+ if (verbose)
fprintf(STDERR, "vpAg = %lu x %lu, units=%lu\n",
(unsigned long)user_chunk_data[1],
(unsigned long)user_chunk_data[2],
@@ -1127,7 +1140,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
png_set_interlace_handling(write_ptr);
# endif
#else
- num_pass=1;
+ num_pass = 1;
#endif
#ifdef PNGTEST_TIMING
@@ -1137,11 +1150,11 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
#endif
for (pass = 0; pass < num_pass; pass++)
{
- png_debug1(0, "Writing row data for pass %d\n",pass);
+ png_debug1(0, "Writing row data for pass %d\n", pass);
for (y = 0; y < height; y++)
{
#ifndef SINGLE_ROWBUF_ALLOC
- png_debug2(0, "\nAllocating row buffer (pass %d, y = %ld)...", pass,y);
+ png_debug2(0, "\nAllocating row buffer (pass %d, y = %ld)...", pass, y);
row_buf = (png_bytep)png_malloc(read_ptr,
png_get_rowbytes(read_ptr, read_info_ptr));
png_debug2(0, "0x%08lx (%ld bytes)\n", (unsigned long)row_buf,
@@ -1200,10 +1213,13 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
{
png_set_tIME(write_ptr, write_end_info_ptr, mod_time);
#if defined(PNG_TIME_RFC1123_SUPPORTED)
- /* we have to use png_strcpy instead of "=" because the string
+ /* we have to use png_memcpy 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));
+ png_memcpy(tIME_string,
+ png_convert_to_rfc1123(read_ptr, mod_time),
+ png_sizeof(tIME_string));
+ tIME_string[png_sizeof(tIME_string) - 1] = '\0';
tIME_chunk_present++;
#endif /* PNG_TIME_RFC1123_SUPPORTED */
}
@@ -1234,13 +1250,13 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
#endif
#ifdef PNG_EASY_ACCESS_SUPPORTED
- if(verbose)
+ if (verbose)
{
png_uint_32 iwidth, iheight;
iwidth = png_get_image_width(write_ptr, write_info_ptr);
iheight = png_get_image_height(write_ptr, write_info_ptr);
fprintf(STDERR, "Image width = %lu, height = %lu\n",
- (unsigned long) iwidth, (unsigned long) iheight);
+ (unsigned long)iwidth, (unsigned long)iheight);
}
#endif
@@ -1260,8 +1276,8 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
#endif
png_debug(0, "Destruction complete.\n");
- fclose(fpin);
- fclose(fpout);
+ FCLOSE(fpin);
+ FCLOSE(fpout);
png_debug(0, "Opening files for comparison\n");
if ((fpin = fopen(inname, "rb")) == NULL)
@@ -1273,7 +1289,7 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
if ((fpout = fopen(outname, "rb")) == NULL)
{
fprintf(STDERR, "Could not find file %s\n", outname);
- fclose(fpin);
+ FCLOSE(fpin);
return (1);
}
@@ -1281,8 +1297,8 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
{
png_size_t num_in, num_out;
- num_in = fread(inbuf, 1, 1, fpin);
- num_out = fread(outbuf, 1, 1, fpout);
+ num_in = fread(inbuf, 1, 1, fpin);
+ num_out = fread(outbuf, 1, 1, fpout);
if (num_in != num_out)
{
@@ -1292,16 +1308,16 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
{
fprintf(STDERR,
" Was %s written with the same maximum IDAT chunk size (%d bytes),",
- inname,PNG_ZBUF_SIZE);
+ inname, PNG_ZBUF_SIZE);
fprintf(STDERR,
"\n filtering heuristic (libpng default), compression");
fprintf(STDERR,
" level (zlib default),\n and zlib version (%s)?\n\n",
ZLIB_VERSION);
- wrote_question=1;
+ wrote_question = 1;
}
- fclose(fpin);
- fclose(fpout);
+ FCLOSE(fpin);
+ FCLOSE(fpout);
return (0);
}
@@ -1311,26 +1327,26 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
if (png_memcmp(inbuf, outbuf, num_in))
{
fprintf(STDERR, "\nFiles %s and %s are different\n", inname, outname);
- if(wrote_question == 0)
+ if (wrote_question == 0)
{
fprintf(STDERR,
" Was %s written with the same maximum IDAT chunk size (%d bytes),",
- inname,PNG_ZBUF_SIZE);
+ inname, PNG_ZBUF_SIZE);
fprintf(STDERR,
"\n filtering heuristic (libpng default), compression");
fprintf(STDERR,
" level (zlib default),\n and zlib version (%s)?\n\n",
ZLIB_VERSION);
- wrote_question=1;
+ wrote_question = 1;
}
- fclose(fpin);
- fclose(fpout);
+ FCLOSE(fpin);
+ FCLOSE(fpout);
return (0);
}
}
- fclose(fpin);
- fclose(fpout);
+ FCLOSE(fpin);
+ FCLOSE(fpout);
return (0);
}
@@ -1352,16 +1368,16 @@ 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));
+ fprintf(STDERR, "%s", png_get_copyright(NULL));
/* Show the version of libpng used in building the library */
- fprintf(STDERR," library (%lu):%s",
- (unsigned long) png_access_version_number(),
+ fprintf(STDERR, " library (%lu):%s",
+ (unsigned long)png_access_version_number(),
png_get_header_version(NULL));
/* Show the version of libpng used in building the application */
- fprintf(STDERR," pngtest (%lu):%s", (unsigned long)PNG_LIBPNG_VER,
+ fprintf(STDERR, " pngtest (%lu):%s", (unsigned long)PNG_LIBPNG_VER,
PNG_HEADER_VERSION_STRING);
- fprintf(STDERR," sizeof(png_struct)=%ld, sizeof(png_info)=%ld\n",
- (long)sizeof(png_struct), (long)sizeof(png_info));
+ fprintf(STDERR, " sizeof(png_struct)=%ld, sizeof(png_info)=%ld\n",
+ (long)png_sizeof(png_struct), (long)png_sizeof(png_info));
/* 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
@@ -1411,10 +1427,10 @@ main(int argc, char *argv[])
}
}
- if (!multiple && argc == 3+verbose)
- outname = argv[2+verbose];
+ if (!multiple && argc == 3 + verbose)
+ outname = argv[2 + verbose];
- if ((!multiple && argc > 3+verbose) || (multiple && argc < 2))
+ if ((!multiple && argc > 3 + verbose) || (multiple && argc < 2))
{
fprintf(STDERR,
"usage: %s [infile.png] [outfile.png]\n\t%s -m {infile.png}\n",
@@ -1438,25 +1454,25 @@ main(int argc, char *argv[])
int k;
#endif
int kerror;
- fprintf(STDERR, "Testing %s:",argv[i]);
+ 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, "\n PASS (%lu zero samples)\n",
- (unsigned long) zero_samples);
+ (unsigned long)zero_samples);
#else
fprintf(STDERR, " PASS\n");
#endif
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
- for (k=0; k<256; k++)
- if(filters_used[k])
+ for (k = 0; k<256; k++)
+ if (filters_used[k])
fprintf(STDERR, " Filter %d was used %lu times\n",
- k, (unsigned long) filters_used[k]);
+ k, (unsigned long)filters_used[k]);
#endif
#if defined(PNG_TIME_RFC1123_SUPPORTED)
- if(tIME_chunk_present != 0)
- fprintf(STDERR, " tIME = %s\n",tIME_string);
+ if (tIME_chunk_present != 0)
+ fprintf(STDERR, " tIME = %s\n", tIME_string);
tIME_chunk_present = 0;
#endif /* PNG_TIME_RFC1123_SUPPORTED */
}
@@ -1468,7 +1484,7 @@ main(int argc, char *argv[])
#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
if (allocation_now != current_allocation)
fprintf(STDERR, "MEMORY ERROR: %d bytes lost\n",
- current_allocation-allocation_now);
+ current_allocation - allocation_now);
if (current_allocation != 0)
{
memory_infop pinfo = pinformation;
@@ -1478,7 +1494,7 @@ main(int argc, char *argv[])
while (pinfo != NULL)
{
fprintf(STDERR, " %lu bytes at %x\n",
- (unsigned long) pinfo->size,
+ (unsigned long)pinfo->size,
(unsigned int) pinfo->pointer);
pinfo = pinfo->next;
}
@@ -1499,54 +1515,54 @@ main(int argc, char *argv[])
else
{
int i;
- for (i=0; i<3; ++i)
+ for (i = 0; i<3; ++i)
{
int kerror;
#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
int allocation_now = current_allocation;
#endif
if (i == 1) status_dots_requested = 1;
- else if(verbose == 0)status_dots_requested = 0;
+ else if (verbose == 0)status_dots_requested = 0;
if (i == 0 || verbose == 1 || ierror != 0)
- fprintf(STDERR, "Testing %s:",inname);
+ fprintf(STDERR, "Testing %s:", inname);
kerror = test_one_file(inname, outname);
- if(kerror == 0)
+ if (kerror == 0)
{
- if(verbose == 1 || i == 2)
+ if (verbose == 1 || i == 2)
{
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
int k;
#endif
#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
fprintf(STDERR, "\n PASS (%lu zero samples)\n",
- (unsigned long) zero_samples);
+ (unsigned long)zero_samples);
#else
fprintf(STDERR, " PASS\n");
#endif
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
- for (k=0; k<256; k++)
- if(filters_used[k])
+ for (k = 0; k<256; k++)
+ if (filters_used[k])
fprintf(STDERR, " Filter %d was used %lu times\n",
k,
- (unsigned long) filters_used[k]);
+ (unsigned long)filters_used[k]);
#endif
#if defined(PNG_TIME_RFC1123_SUPPORTED)
- if(tIME_chunk_present != 0)
- fprintf(STDERR, " tIME = %s\n",tIME_string);
+ if (tIME_chunk_present != 0)
+ fprintf(STDERR, " tIME = %s\n", tIME_string);
#endif /* PNG_TIME_RFC1123_SUPPORTED */
}
}
else
{
- if(verbose == 0 && i != 2)
- fprintf(STDERR, "Testing %s:",inname);
+ if (verbose == 0 && i != 2)
+ fprintf(STDERR, "Testing %s:", inname);
fprintf(STDERR, " FAIL\n");
ierror += kerror;
}
#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
if (allocation_now != current_allocation)
fprintf(STDERR, "MEMORY ERROR: %d bytes lost\n",
- current_allocation-allocation_now);
+ current_allocation - allocation_now);
if (current_allocation != 0)
{
memory_infop pinfo = pinformation;
@@ -1555,8 +1571,8 @@ main(int argc, char *argv[])
current_allocation);
while (pinfo != NULL)
{
- fprintf(STDERR," %lu bytes at %x\n",
- (unsigned long) pinfo->size, (unsigned int)pinfo->pointer);
+ fprintf(STDERR, " %lu bytes at %x\n",
+ (unsigned long)pinfo->size, (unsigned int)pinfo->pointer);
pinfo = pinfo->next;
}
}
@@ -1578,13 +1594,13 @@ main(int argc, char *argv[])
t_stop = (float)clock();
t_misc += (t_stop - t_start);
t_start = t_stop;
- fprintf(STDERR," CPU time used = %.3f seconds",
+ fprintf(STDERR, " CPU time used = %.3f seconds",
(t_misc+t_decode+t_encode)/(float)CLOCKS_PER_SEC);
- fprintf(STDERR," (decoding %.3f,\n",
+ fprintf(STDERR, " (decoding %.3f,\n",
t_decode/(float)CLOCKS_PER_SEC);
- fprintf(STDERR," encoding %.3f ,",
+ fprintf(STDERR, " encoding %.3f ,",
t_encode/(float)CLOCKS_PER_SEC);
- fprintf(STDERR," other %.3f seconds)\n\n",
+ fprintf(STDERR, " other %.3f seconds)\n\n",
t_misc/(float)CLOCKS_PER_SEC);
#endif
@@ -1596,4 +1612,4 @@ main(int argc, char *argv[])
}
/* Generate a compiler error if there is an old png.h in the search path. */
-typedef version_1_4_0beta19 your_png_h_is_not_version_1_4_0beta19;
+typedef version_1_4_0beta20 your_png_h_is_not_version_1_4_0beta20;
diff --git a/pngtrans.c b/pngtrans.c
index c1cc73a11..3c9082740 100644
--- a/pngtrans.c
+++ b/pngtrans.c
@@ -1,24 +1,24 @@
/* pngtrans.c - transforms the data in a row (used by both readers and writers)
*
- * Last changed in libpng 1.4.0 May 15, 2007
+ * Last changed in libpng 1.4.0 [July 10, 2008]
* For conditions of distribution and use, see copyright notice in png.h
- * Copyright (c) 1998-2007 Glenn Randers-Pehrson
+ * Copyright (c) 1998-2008 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*/
#include "png.h"
+#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
#include "pngpriv.h"
-#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
/* turn on BGR-to-RGB mapping */
void PNGAPI
png_set_bgr(png_structp png_ptr)
{
png_debug(1, "in png_set_bgr\n");
- if(png_ptr == NULL) return;
+ if (png_ptr == NULL) return;
png_ptr->transformations |= PNG_BGR;
}
#endif
@@ -29,7 +29,7 @@ void PNGAPI
png_set_swap(png_structp png_ptr)
{
png_debug(1, "in png_set_swap\n");
- if(png_ptr == NULL) return;
+ if (png_ptr == NULL) return;
if (png_ptr->bit_depth == 16)
png_ptr->transformations |= PNG_SWAP_BYTES;
}
@@ -41,7 +41,7 @@ void PNGAPI
png_set_packing(png_structp png_ptr)
{
png_debug(1, "in png_set_packing\n");
- if(png_ptr == NULL) return;
+ if (png_ptr == NULL) return;
if (png_ptr->bit_depth < 8)
{
png_ptr->transformations |= PNG_PACK;
@@ -56,7 +56,7 @@ void PNGAPI
png_set_packswap(png_structp png_ptr)
{
png_debug(1, "in png_set_packswap\n");
- if(png_ptr == NULL) return;
+ if (png_ptr == NULL) return;
if (png_ptr->bit_depth < 8)
png_ptr->transformations |= PNG_PACKSWAP;
}
@@ -67,7 +67,7 @@ void PNGAPI
png_set_shift(png_structp png_ptr, png_color_8p true_bits)
{
png_debug(1, "in png_set_shift\n");
- if(png_ptr == NULL) return;
+ if (png_ptr == NULL) return;
png_ptr->transformations |= PNG_SHIFT;
png_ptr->shift = *true_bits;
}
@@ -99,7 +99,7 @@ void PNGAPI
png_set_filler(png_structp png_ptr, png_uint_32 filler, int filler_loc)
{
png_debug(1, "in png_set_filler\n");
- if(png_ptr == NULL) return;
+ if (png_ptr == NULL) return;
png_ptr->transformations |= PNG_FILLER;
png_ptr->filler = (png_byte)filler;
if (filler_loc == PNG_FILLER_AFTER)
@@ -126,15 +126,17 @@ png_set_filler(png_structp png_ptr, png_uint_32 filler, int filler_loc)
}
}
+#if !defined(PNG_1_0_X)
/* Added to libpng-1.2.7 */
void PNGAPI
png_set_add_alpha(png_structp png_ptr, png_uint_32 filler, int filler_loc)
{
png_debug(1, "in png_set_add_alpha\n");
- if(png_ptr == NULL) return;
+ if (png_ptr == NULL) return;
png_set_filler(png_ptr, filler, filler_loc);
png_ptr->transformations |= PNG_ADD_ALPHA;
}
+#endif
#endif
@@ -144,7 +146,7 @@ void PNGAPI
png_set_swap_alpha(png_structp png_ptr)
{
png_debug(1, "in png_set_swap_alpha\n");
- if(png_ptr == NULL) return;
+ if (png_ptr == NULL) return;
png_ptr->transformations |= PNG_SWAP_ALPHA;
}
#endif
@@ -155,7 +157,7 @@ void PNGAPI
png_set_invert_alpha(png_structp png_ptr)
{
png_debug(1, "in png_set_invert_alpha\n");
- if(png_ptr == NULL) return;
+ if (png_ptr == NULL) return;
png_ptr->transformations |= PNG_INVERT_ALPHA;
}
#endif
@@ -165,7 +167,7 @@ void PNGAPI
png_set_invert_mono(png_structp png_ptr)
{
png_debug(1, "in png_set_invert_mono\n");
- if(png_ptr == NULL) return;
+ if (png_ptr == NULL) return;
png_ptr->transformations |= PNG_INVERT_MONO;
}
@@ -629,13 +631,13 @@ png_set_user_transform_info(png_structp png_ptr, png_voidp
user_transform_ptr, int user_transform_depth, int user_transform_channels)
{
png_debug(1, "in png_set_user_transform_info\n");
- if(png_ptr == NULL) return;
+ if (png_ptr == NULL) return;
#if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
png_ptr->user_transform_ptr = user_transform_ptr;
png_ptr->user_transform_depth = (png_byte)user_transform_depth;
png_ptr->user_transform_channels = (png_byte)user_transform_channels;
#else
- if(user_transform_ptr || user_transform_depth || user_transform_channels)
+ if (user_transform_ptr || user_transform_depth || user_transform_channels)
png_warning(png_ptr,
"This version of libpng does not support user transform info");
#endif
@@ -653,7 +655,8 @@ png_get_user_transform_ptr(png_structp png_ptr)
if (png_ptr == NULL) return (NULL);
#if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
return ((png_voidp)png_ptr->user_transform_ptr);
-#endif
+#else
return (NULL);
+#endif
}
#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
diff --git a/pngvcrd.c b/pngvcrd.c
index ee4cd71e2..e69de29bb 100644
--- a/pngvcrd.c
+++ b/pngvcrd.c
@@ -1,3846 +0,0 @@
-
-/* pngvcrd.c - mixed C/assembler version of utilities to read a PNG file
- *
- * For Intel x86 CPU and Microsoft Visual C++ compiler
- *
- * Last changed in libpng 1.4.0 May 15, 2007
- * For conditions of distribution and use, see copyright notice in png.h
- * Copyright (c) 1998-2007 Glenn Randers-Pehrson
- * Copyright (c) 1998, Intel Corporation
- *
- * Contributed by Nirav Chhatrapati, Intel Corporation, 1998
- * Interface to libpng contributed by Gilles Vollant, 1999
- *
- *
- * In png_do_read_interlace() in libpng versions 1.0.3a through 1.0.4d,
- * a sign error in the post-MMX cleanup code for each pixel_depth resulted
- * in bad pixels at the beginning of some rows of some images, and also
- * (due to out-of-range memory reads and writes) caused heap corruption
- * when compiled with MSVC 6.0. The error was fixed in version 1.0.4e.
- *
- * [png_read_filter_row_mmx_avg() bpp == 2 bugfix, GRR 20000916]
- *
- * [runtime MMX configuration, GRR 20010102]
- *
- */
-
-#include "png.h"
-#include "pngpriv.h"
-
-#if defined(PNG_MMX_CODE_SUPPORTED) && defined(PNG_USE_PNGVCRD)
-
-static int mmx_supported=2;
-
-
-int PNGAPI
-png_mmx_support(void)
-{
- int mmx_supported_local = 0;
- _asm {
- push ebx //CPUID will trash these
- push ecx
- push edx
-
- pushfd //Save Eflag to stack
- pop eax //Get Eflag from stack into eax
- mov ecx, eax //Make another copy of Eflag in ecx
- xor eax, 0x200000 //Toggle ID bit in Eflag [i.e. bit(21)]
- push eax //Save modified Eflag back to stack
-
- popfd //Restored modified value back to Eflag reg
- pushfd //Save Eflag to stack
- pop eax //Get Eflag from stack
- push ecx // save original Eflag to stack
- popfd // restore original Eflag
- xor eax, ecx //Compare the new Eflag with the original Eflag
- jz NOT_SUPPORTED //If the same, CPUID instruction is not supported,
- //skip following instructions and jump to
- //NOT_SUPPORTED label
-
- xor eax, eax //Set eax to zero
-
- _asm _emit 0x0f //CPUID instruction (two bytes opcode)
- _asm _emit 0xa2
-
- cmp eax, 1 //make sure eax return non-zero value
- jl NOT_SUPPORTED //If eax is zero, mmx not supported
-
- xor eax, eax //set eax to zero
- inc eax //Now increment eax to 1. This instruction is
- //faster than the instruction "mov eax, 1"
-
- _asm _emit 0x0f //CPUID instruction
- _asm _emit 0xa2
-
- and edx, 0x00800000 //mask out all bits but mmx bit(24)
- cmp edx, 0 // 0 = mmx not supported
- jz NOT_SUPPORTED // non-zero = Yes, mmx IS supported
-
- mov mmx_supported_local, 1 //set return value to 1
-
-NOT_SUPPORTED:
- mov eax, mmx_supported_local //move return value to eax
- pop edx //CPUID trashed these
- pop ecx
- pop ebx
- }
-
- //mmx_supported_local=0; // test code for force don't support MMX
- //printf("MMX : %u (1=MMX supported)\n",mmx_supported_local);
-
- mmx_supported = mmx_supported_local;
- return mmx_supported_local;
-}
-
-/* Combines the row recently read in with the previous 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 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. */
-
-/* Use this routine for x86 platform - uses faster MMX routine if machine
- supports MMX */
-
-void /* PRIVATE */
-png_combine_row(png_structp png_ptr, png_bytep row, int mask)
-{
-#ifdef PNG_USE_LOCAL_ARRAYS
- const int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
-#endif
-
- png_debug(1,"in png_combine_row_asm\n");
-
- if (mmx_supported == 2) {
- /* this should have happened in png_init_mmx_flags() already */
- png_warning(png_ptr, "asm_flags may not have been initialized");
- png_mmx_support();
- }
-
- if (mask == 0xff)
- {
- png_memcpy(row, png_ptr->row_buf + 1,
- PNG_ROWBYTES(png_ptr->row_info.pixel_depth, png_ptr->width));
- }
- /* GRR: add "else if (mask == 0)" case?
- * or does png_combine_row() not even get called in that case? */
- else
- {
- switch (png_ptr->row_info.pixel_depth)
- {
- case 1:
- {
- png_bytep sp;
- png_bytep dp;
- int s_inc, s_start, s_end;
- int m;
- int shift;
- png_uint_32 i;
-
- sp = png_ptr->row_buf + 1;
- dp = row;
- m = 0x80;
-#if defined(PNG_READ_PACKSWAP_SUPPORTED)
- if (png_ptr->transformations & PNG_PACKSWAP)
- {
- s_start = 0;
- s_end = 7;
- s_inc = 1;
- }
- else
-#endif
- {
- s_start = 7;
- s_end = 0;
- s_inc = -1;
- }
-
- shift = s_start;
-
- for (i = 0; i < png_ptr->width; i++)
- {
- if (m & mask)
- {
- int value;
-
- value = (*sp >> shift) & 0x1;
- *dp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
- *dp |= (png_byte)(value << shift);
- }
-
- if (shift == s_end)
- {
- shift = s_start;
- sp++;
- dp++;
- }
- else
- shift += s_inc;
-
- if (m == 1)
- m = 0x80;
- else
- m >>= 1;
- }
- break;
- }
-
- case 2:
- {
- png_bytep sp;
- png_bytep dp;
- int s_start, s_end, s_inc;
- int m;
- int shift;
- png_uint_32 i;
- int value;
-
- sp = png_ptr->row_buf + 1;
- dp = row;
- m = 0x80;
-#if defined(PNG_READ_PACKSWAP_SUPPORTED)
- if (png_ptr->transformations & PNG_PACKSWAP)
- {
- s_start = 0;
- s_end = 6;
- s_inc = 2;
- }
- else
-#endif
- {
- s_start = 6;
- s_end = 0;
- s_inc = -2;
- }
-
- shift = s_start;
-
- for (i = 0; i < png_ptr->width; i++)
- {
- if (m & mask)
- {
- value = (*sp >> shift) & 0x3;
- *dp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
- *dp |= (png_byte)(value << shift);
- }
-
- if (shift == s_end)
- {
- shift = s_start;
- sp++;
- dp++;
- }
- else
- shift += s_inc;
- if (m == 1)
- m = 0x80;
- else
- m >>= 1;
- }
- break;
- }
-
- case 4:
- {
- png_bytep sp;
- png_bytep dp;
- int s_start, s_end, s_inc;
- int m;
- int shift;
- png_uint_32 i;
- int value;
-
- sp = png_ptr->row_buf + 1;
- dp = row;
- m = 0x80;
-#if defined(PNG_READ_PACKSWAP_SUPPORTED)
- if (png_ptr->transformations & PNG_PACKSWAP)
- {
- s_start = 0;
- s_end = 4;
- s_inc = 4;
- }
- else
-#endif
- {
- s_start = 4;
- s_end = 0;
- s_inc = -4;
- }
- shift = s_start;
-
- for (i = 0; i < png_ptr->width; i++)
- {
- if (m & mask)
- {
- value = (*sp >> shift) & 0xf;
- *dp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
- *dp |= (png_byte)(value << shift);
- }
-
- if (shift == s_end)
- {
- shift = s_start;
- sp++;
- dp++;
- }
- else
- shift += s_inc;
- if (m == 1)
- m = 0x80;
- else
- m >>= 1;
- }
- break;
- }
-
- case 8:
- {
- png_bytep srcptr;
- png_bytep dstptr;
- png_uint_32 len;
- int m;
- int diff, unmask;
-
- __int64 mask0=0x0102040810204080;
-
- if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)
- /* && mmx_supported */ )
- {
- srcptr = png_ptr->row_buf + 1;
- dstptr = row;
- m = 0x80;
- unmask = ~mask;
- len = png_ptr->width &~7; //reduce to multiple of 8
- diff = png_ptr->width & 7; //amount lost
-
- _asm
- {
- movd mm7, unmask //load bit pattern
- psubb mm6,mm6 //zero mm6
- punpcklbw mm7,mm7
- punpcklwd mm7,mm7
- punpckldq mm7,mm7 //fill register with 8 masks
-
- movq mm0,mask0
-
- pand mm0,mm7 //nonzero if keep byte
- pcmpeqb mm0,mm6 //zeros->1s, v versa
-
- mov ecx,len //load length of line (pixels)
- mov esi,srcptr //load source
- mov ebx,dstptr //load dest
- cmp ecx,0 //lcr
- je mainloop8end
-
-mainloop8:
- movq mm4,[esi]
- pand mm4,mm0
- movq mm6,mm0
- pandn mm6,[ebx]
- por mm4,mm6
- movq [ebx],mm4
-
- add esi,8 //inc by 8 bytes processed
- add ebx,8
- sub ecx,8 //dec by 8 pixels processed
-
- ja mainloop8
-mainloop8end:
-
- mov ecx,diff
- cmp ecx,0
- jz end8
-
- mov edx,mask
- sal edx,24 //make low byte the high byte
-
-secondloop8:
- sal edx,1 //move high bit to CF
- jnc skip8 //if CF = 0
- mov al,[esi]
- mov [ebx],al
-skip8:
- inc esi
- inc ebx
-
- dec ecx
- jnz secondloop8
-end8:
- emms
- }
- }
- else /* mmx not supported - use modified C routine */
- {
- register unsigned int incr1, initial_val, final_val;
- png_size_t pixel_bytes;
- png_uint_32 i;
- register int disp = png_pass_inc[png_ptr->pass];
- int offset_table[7] = {0, 4, 0, 2, 0, 1, 0};
-
- pixel_bytes = (png_ptr->row_info.pixel_depth >> 3);
- srcptr = png_ptr->row_buf + 1 + offset_table[png_ptr->pass]*
- pixel_bytes;
- dstptr = row + offset_table[png_ptr->pass]*pixel_bytes;
- initial_val = offset_table[png_ptr->pass]*pixel_bytes;
- final_val = png_ptr->width*pixel_bytes;
- incr1 = (disp)*pixel_bytes;
- for (i = initial_val; i < final_val; i += incr1)
- {
- png_memcpy(dstptr, srcptr, pixel_bytes);
- srcptr += incr1;
- dstptr += incr1;
- }
- } /* end of else */
-
- break;
- } // end 8 bpp
-
- case 16:
- {
- png_bytep srcptr;
- png_bytep dstptr;
- png_uint_32 len;
- int unmask, diff;
- __int64 mask1=0x0101020204040808,
- mask0=0x1010202040408080;
-
- if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)
- /* && mmx_supported */ )
- {
- srcptr = png_ptr->row_buf + 1;
- dstptr = row;
-
- unmask = ~mask;
- len = (png_ptr->width)&~7;
- diff = (png_ptr->width)&7;
- _asm
- {
- movd mm7, unmask //load bit pattern
- psubb mm6,mm6 //zero mm6
- punpcklbw mm7,mm7
- punpcklwd mm7,mm7
- punpckldq mm7,mm7 //fill register with 8 masks
-
- movq mm0,mask0
- movq mm1,mask1
-
- pand mm0,mm7
- pand mm1,mm7
-
- pcmpeqb mm0,mm6
- pcmpeqb mm1,mm6
-
- mov ecx,len //load length of line
- mov esi,srcptr //load source
- mov ebx,dstptr //load dest
- cmp ecx,0 //lcr
- jz mainloop16end
-
-mainloop16:
- movq mm4,[esi]
- pand mm4,mm0
- movq mm6,mm0
- movq mm7,[ebx]
- pandn mm6,mm7
- por mm4,mm6
- movq [ebx],mm4
-
- movq mm5,[esi+8]
- pand mm5,mm1
- movq mm7,mm1
- movq mm6,[ebx+8]
- pandn mm7,mm6
- por mm5,mm7
- movq [ebx+8],mm5
-
- add esi,16 //inc by 16 bytes processed
- add ebx,16
- sub ecx,8 //dec by 8 pixels processed
-
- ja mainloop16
-
-mainloop16end:
- mov ecx,diff
- cmp ecx,0
- jz end16
-
- mov edx,mask
- sal edx,24 //make low byte the high byte
-secondloop16:
- sal edx,1 //move high bit to CF
- jnc skip16 //if CF = 0
- mov ax,[esi]
- mov [ebx],ax
-skip16:
- add esi,2
- add ebx,2
-
- dec ecx
- jnz secondloop16
-end16:
- emms
- }
- }
- else /* mmx not supported - use modified C routine */
- {
- register unsigned int incr1, initial_val, final_val;
- png_size_t pixel_bytes;
- png_uint_32 i;
- register int disp = png_pass_inc[png_ptr->pass];
- int offset_table[7] = {0, 4, 0, 2, 0, 1, 0};
-
- pixel_bytes = (png_ptr->row_info.pixel_depth >> 3);
- srcptr = png_ptr->row_buf + 1 + offset_table[png_ptr->pass]*
- pixel_bytes;
- dstptr = row + offset_table[png_ptr->pass]*pixel_bytes;
- initial_val = offset_table[png_ptr->pass]*pixel_bytes;
- final_val = png_ptr->width*pixel_bytes;
- incr1 = (disp)*pixel_bytes;
- for (i = initial_val; i < final_val; i += incr1)
- {
- png_memcpy(dstptr, srcptr, pixel_bytes);
- srcptr += incr1;
- dstptr += incr1;
- }
- } /* end of else */
-
- break;
- } // end 16 bpp
-
- case 24:
- {
- png_bytep srcptr;
- png_bytep dstptr;
- png_uint_32 len;
- int unmask, diff;
-
- __int64 mask2=0x0101010202020404, //24bpp
- mask1=0x0408080810101020,
- mask0=0x2020404040808080;
-
- srcptr = png_ptr->row_buf + 1;
- dstptr = row;
-
- unmask = ~mask;
- len = (png_ptr->width)&~7;
- diff = (png_ptr->width)&7;
-
- if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)
- /* && mmx_supported */ )
- {
- _asm
- {
- movd mm7, unmask //load bit pattern
- psubb mm6,mm6 //zero mm6
- punpcklbw mm7,mm7
- punpcklwd mm7,mm7
- punpckldq mm7,mm7 //fill register with 8 masks
-
- movq mm0,mask0
- movq mm1,mask1
- movq mm2,mask2
-
- pand mm0,mm7
- pand mm1,mm7
- pand mm2,mm7
-
- pcmpeqb mm0,mm6
- pcmpeqb mm1,mm6
- pcmpeqb mm2,mm6
-
- mov ecx,len //load length of line
- mov esi,srcptr //load source
- mov ebx,dstptr //load dest
- cmp ecx,0
- jz mainloop24end
-
-mainloop24:
- movq mm4,[esi]
- pand mm4,mm0
- movq mm6,mm0
- movq mm7,[ebx]
- pandn mm6,mm7
- por mm4,mm6
- movq [ebx],mm4
-
-
- movq mm5,[esi+8]
- pand mm5,mm1
- movq mm7,mm1
- movq mm6,[ebx+8]
- pandn mm7,mm6
- por mm5,mm7
- movq [ebx+8],mm5
-
- movq mm6,[esi+16]
- pand mm6,mm2
- movq mm4,mm2
- movq mm7,[ebx+16]
- pandn mm4,mm7
- por mm6,mm4
- movq [ebx+16],mm6
-
- add esi,24 //inc by 24 bytes processed
- add ebx,24
- sub ecx,8 //dec by 8 pixels processed
-
- ja mainloop24
-
-mainloop24end:
- mov ecx,diff
- cmp ecx,0
- jz end24
-
- mov edx,mask
- sal edx,24 //make low byte the high byte
-secondloop24:
- sal edx,1 //move high bit to CF
- jnc skip24 //if CF = 0
- mov ax,[esi]
- mov [ebx],ax
- xor eax,eax
- mov al,[esi+2]
- mov [ebx+2],al
-skip24:
- add esi,3
- add ebx,3
-
- dec ecx
- jnz secondloop24
-
-end24:
- emms
- }
- }
- else /* mmx not supported - use modified C routine */
- {
- register unsigned int incr1, initial_val, final_val;
- png_size_t pixel_bytes;
- png_uint_32 i;
- register int disp = png_pass_inc[png_ptr->pass];
- int offset_table[7] = {0, 4, 0, 2, 0, 1, 0};
-
- pixel_bytes = (png_ptr->row_info.pixel_depth >> 3);
- srcptr = png_ptr->row_buf + 1 + offset_table[png_ptr->pass]*
- pixel_bytes;
- dstptr = row + offset_table[png_ptr->pass]*pixel_bytes;
- initial_val = offset_table[png_ptr->pass]*pixel_bytes;
- final_val = png_ptr->width*pixel_bytes;
- incr1 = (disp)*pixel_bytes;
- for (i = initial_val; i < final_val; i += incr1)
- {
- png_memcpy(dstptr, srcptr, pixel_bytes);
- srcptr += incr1;
- dstptr += incr1;
- }
- } /* end of else */
-
- break;
- } // end 24 bpp
-
- case 32:
- {
- png_bytep srcptr;
- png_bytep dstptr;
- png_uint_32 len;
- int unmask, diff;
-
- __int64 mask3=0x0101010102020202, //32bpp
- mask2=0x0404040408080808,
- mask1=0x1010101020202020,
- mask0=0x4040404080808080;
-
- srcptr = png_ptr->row_buf + 1;
- dstptr = row;
-
- unmask = ~mask;
- len = (png_ptr->width)&~7;
- diff = (png_ptr->width)&7;
-
- if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)
- /* && mmx_supported */ )
- {
- _asm
- {
- movd mm7, unmask //load bit pattern
- psubb mm6,mm6 //zero mm6
- punpcklbw mm7,mm7
- punpcklwd mm7,mm7
- punpckldq mm7,mm7 //fill register with 8 masks
-
- movq mm0,mask0
- movq mm1,mask1
- movq mm2,mask2
- movq mm3,mask3
-
- pand mm0,mm7
- pand mm1,mm7
- pand mm2,mm7
- pand mm3,mm7
-
- pcmpeqb mm0,mm6
- pcmpeqb mm1,mm6
- pcmpeqb mm2,mm6
- pcmpeqb mm3,mm6
-
- mov ecx,len //load length of line
- mov esi,srcptr //load source
- mov ebx,dstptr //load dest
-
- cmp ecx,0 //lcr
- jz mainloop32end
-
-mainloop32:
- movq mm4,[esi]
- pand mm4,mm0
- movq mm6,mm0
- movq mm7,[ebx]
- pandn mm6,mm7
- por mm4,mm6
- movq [ebx],mm4
-
- movq mm5,[esi+8]
- pand mm5,mm1
- movq mm7,mm1
- movq mm6,[ebx+8]
- pandn mm7,mm6
- por mm5,mm7
- movq [ebx+8],mm5
-
- movq mm6,[esi+16]
- pand mm6,mm2
- movq mm4,mm2
- movq mm7,[ebx+16]
- pandn mm4,mm7
- por mm6,mm4
- movq [ebx+16],mm6
-
- movq mm7,[esi+24]
- pand mm7,mm3
- movq mm5,mm3
- movq mm4,[ebx+24]
- pandn mm5,mm4
- por mm7,mm5
- movq [ebx+24],mm7
-
- add esi,32 //inc by 32 bytes processed
- add ebx,32
- sub ecx,8 //dec by 8 pixels processed
-
- ja mainloop32
-
-mainloop32end:
- mov ecx,diff
- cmp ecx,0
- jz end32
-
- mov edx,mask
- sal edx,24 //make low byte the high byte
-secondloop32:
- sal edx,1 //move high bit to CF
- jnc skip32 //if CF = 0
- mov eax,[esi]
- mov [ebx],eax
-skip32:
- add esi,4
- add ebx,4
-
- dec ecx
- jnz secondloop32
-
-end32:
- emms
- }
- }
- else /* mmx _not supported - Use modified C routine */
- {
- register unsigned int incr1, initial_val, final_val;
- png_size_t pixel_bytes;
- png_uint_32 i;
- register int disp = png_pass_inc[png_ptr->pass];
- int offset_table[7] = {0, 4, 0, 2, 0, 1, 0};
-
- pixel_bytes = (png_ptr->row_info.pixel_depth >> 3);
- srcptr = png_ptr->row_buf + 1 + offset_table[png_ptr->pass]*
- pixel_bytes;
- dstptr = row + offset_table[png_ptr->pass]*pixel_bytes;
- initial_val = offset_table[png_ptr->pass]*pixel_bytes;
- final_val = png_ptr->width*pixel_bytes;
- incr1 = (disp)*pixel_bytes;
- for (i = initial_val; i < final_val; i += incr1)
- {
- png_memcpy(dstptr, srcptr, pixel_bytes);
- srcptr += incr1;
- dstptr += incr1;
- }
- } /* end of else */
-
- break;
- } // end 32 bpp
-
- case 48:
- {
- png_bytep srcptr;
- png_bytep dstptr;
- png_uint_32 len;
- int unmask, diff;
-
- __int64 mask5=0x0101010101010202,
- mask4=0x0202020204040404,
- mask3=0x0404080808080808,
- mask2=0x1010101010102020,
- mask1=0x2020202040404040,
- mask0=0x4040808080808080;
-
- if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)
- /* && mmx_supported */ )
- {
- srcptr = png_ptr->row_buf + 1;
- dstptr = row;
-
- unmask = ~mask;
- len = (png_ptr->width)&~7;
- diff = (png_ptr->width)&7;
- _asm
- {
- movd mm7, unmask //load bit pattern
- psubb mm6,mm6 //zero mm6
- punpcklbw mm7,mm7
- punpcklwd mm7,mm7
- punpckldq mm7,mm7 //fill register with 8 masks
-
- movq mm0,mask0
- movq mm1,mask1
- movq mm2,mask2
- movq mm3,mask3
- movq mm4,mask4
- movq mm5,mask5
-
- pand mm0,mm7
- pand mm1,mm7
- pand mm2,mm7
- pand mm3,mm7
- pand mm4,mm7
- pand mm5,mm7
-
- pcmpeqb mm0,mm6
- pcmpeqb mm1,mm6
- pcmpeqb mm2,mm6
- pcmpeqb mm3,mm6
- pcmpeqb mm4,mm6
- pcmpeqb mm5,mm6
-
- mov ecx,len //load length of line
- mov esi,srcptr //load source
- mov ebx,dstptr //load dest
-
- cmp ecx,0
- jz mainloop48end
-
-mainloop48:
- movq mm7,[esi]
- pand mm7,mm0
- movq mm6,mm0
- pandn mm6,[ebx]
- por mm7,mm6
- movq [ebx],mm7
-
- movq mm6,[esi+8]
- pand mm6,mm1
- movq mm7,mm1
- pandn mm7,[ebx+8]
- por mm6,mm7
- movq [ebx+8],mm6
-
- movq mm6,[esi+16]
- pand mm6,mm2
- movq mm7,mm2
- pandn mm7,[ebx+16]
- por mm6,mm7
- movq [ebx+16],mm6
-
- movq mm7,[esi+24]
- pand mm7,mm3
- movq mm6,mm3
- pandn mm6,[ebx+24]
- por mm7,mm6
- movq [ebx+24],mm7
-
- movq mm6,[esi+32]
- pand mm6,mm4
- movq mm7,mm4
- pandn mm7,[ebx+32]
- por mm6,mm7
- movq [ebx+32],mm6
-
- movq mm7,[esi+40]
- pand mm7,mm5
- movq mm6,mm5
- pandn mm6,[ebx+40]
- por mm7,mm6
- movq [ebx+40],mm7
-
- add esi,48 //inc by 32 bytes processed
- add ebx,48
- sub ecx,8 //dec by 8 pixels processed
-
- ja mainloop48
-mainloop48end:
-
- mov ecx,diff
- cmp ecx,0
- jz end48
-
- mov edx,mask
- sal edx,24 //make low byte the high byte
-
-secondloop48:
- sal edx,1 //move high bit to CF
- jnc skip48 //if CF = 0
- mov eax,[esi]
- mov [ebx],eax
-skip48:
- add esi,4
- add ebx,4
-
- dec ecx
- jnz secondloop48
-
-end48:
- emms
- }
- }
- else /* mmx _not supported - Use modified C routine */
- {
- register unsigned int incr1, initial_val, final_val;
- png_size_t pixel_bytes;
- png_uint_32 i;
- register int disp = png_pass_inc[png_ptr->pass];
- int offset_table[7] = {0, 4, 0, 2, 0, 1, 0};
-
- pixel_bytes = (png_ptr->row_info.pixel_depth >> 3);
- srcptr = png_ptr->row_buf + 1 + offset_table[png_ptr->pass]*
- pixel_bytes;
- dstptr = row + offset_table[png_ptr->pass]*pixel_bytes;
- initial_val = offset_table[png_ptr->pass]*pixel_bytes;
- final_val = png_ptr->width*pixel_bytes;
- incr1 = (disp)*pixel_bytes;
- for (i = initial_val; i < final_val; i += incr1)
- {
- png_memcpy(dstptr, srcptr, pixel_bytes);
- srcptr += incr1;
- dstptr += incr1;
- }
- } /* end of else */
-
- break;
- } // end 48 bpp
-
- default:
- {
- png_bytep sptr;
- png_bytep dp;
- png_size_t pixel_bytes;
- int offset_table[7] = {0, 4, 0, 2, 0, 1, 0};
- unsigned int i;
- register int disp = png_pass_inc[png_ptr->pass]; // get the offset
- register unsigned int incr1, initial_val, final_val;
-
- pixel_bytes = (png_ptr->row_info.pixel_depth >> 3);
- sptr = png_ptr->row_buf + 1 + offset_table[png_ptr->pass]*
- pixel_bytes;
- dp = row + offset_table[png_ptr->pass]*pixel_bytes;
- initial_val = offset_table[png_ptr->pass]*pixel_bytes;
- final_val = png_ptr->width*pixel_bytes;
- incr1 = (disp)*pixel_bytes;
- for (i = initial_val; i < final_val; i += incr1)
- {
- png_memcpy(dp, sptr, pixel_bytes);
- sptr += incr1;
- dp += incr1;
- }
- break;
- }
- } /* end switch (png_ptr->row_info.pixel_depth) */
- } /* end if (non-trivial mask) */
-
-} /* end png_combine_row() */
-
-
-#if defined(PNG_READ_INTERLACING_SUPPORTED)
-
-void /* PRIVATE */
-png_do_read_interlace(png_structp png_ptr)
-{
- png_row_infop row_info = &(png_ptr->row_info);
- png_bytep row = png_ptr->row_buf + 1;
- int pass = png_ptr->pass;
- png_uint_32 transformations = png_ptr->transformations;
-#ifdef PNG_USE_LOCAL_ARRAYS
- const int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
-#endif
-
- png_debug(1,"in png_do_read_interlace\n");
-
- if (mmx_supported == 2) {
- /* this should have happened in png_init_mmx_flags() already */
- png_warning(png_ptr, "asm_flags may not have been initialized");
- png_mmx_support();
- }
-
- if (row != NULL && row_info != NULL)
- {
- png_uint_32 final_width;
-
- final_width = row_info->width * png_pass_inc[pass];
-
- switch (row_info->pixel_depth)
- {
- case 1:
- {
- png_bytep sp, dp;
- int sshift, dshift;
- int s_start, s_end, s_inc;
- 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)
- {
- sshift = (int)((row_info->width + 7) & 7);
- dshift = (int)((final_width + 7) & 7);
- s_start = 7;
- s_end = 0;
- s_inc = -1;
- }
- else
-#endif
- {
- sshift = 7 - (int)((row_info->width + 7) & 7);
- dshift = 7 - (int)((final_width + 7) & 7);
- s_start = 0;
- s_end = 7;
- s_inc = 1;
- }
-
- for (i = row_info->width; i; i--)
- {
- v = (png_byte)((*sp >> sshift) & 0x1);
- for (j = 0; j < png_pass_inc[pass]; j++)
- {
- *dp &= (png_byte)((0x7f7f >> (7 - dshift)) & 0xff);
- *dp |= (png_byte)(v << dshift);
- if (dshift == s_end)
- {
- dshift = s_start;
- dp--;
- }
- else
- dshift += s_inc;
- }
- if (sshift == s_end)
- {
- sshift = s_start;
- sp--;
- }
- else
- sshift += s_inc;
- }
- break;
- }
-
- case 2:
- {
- png_bytep sp, dp;
- int sshift, dshift;
- int s_start, s_end, s_inc;
- png_uint_32 i;
-
- sp = row + (png_size_t)((row_info->width - 1) >> 2);
- dp = row + (png_size_t)((final_width - 1) >> 2);
-#if defined(PNG_READ_PACKSWAP_SUPPORTED)
- if (transformations & PNG_PACKSWAP)
- {
- sshift = (png_size_t)(((row_info->width + 3) & 3) << 1);
- dshift = (png_size_t)(((final_width + 3) & 3) << 1);
- s_start = 6;
- s_end = 0;
- s_inc = -2;
- }
- else
-#endif
- {
- sshift = (png_size_t)((3 - ((row_info->width + 3) & 3)) << 1);
- dshift = (png_size_t)((3 - ((final_width + 3) & 3)) << 1);
- s_start = 0;
- s_end = 6;
- s_inc = 2;
- }
-
- for (i = row_info->width; i; i--)
- {
- png_byte v;
- int j;
-
- v = (png_byte)((*sp >> sshift) & 0x3);
- for (j = 0; j < png_pass_inc[pass]; j++)
- {
- *dp &= (png_byte)((0x3f3f >> (6 - dshift)) & 0xff);
- *dp |= (png_byte)(v << dshift);
- if (dshift == s_end)
- {
- dshift = s_start;
- dp--;
- }
- else
- dshift += s_inc;
- }
- if (sshift == s_end)
- {
- sshift = s_start;
- sp--;
- }
- else
- sshift += s_inc;
- }
- break;
- }
-
- case 4:
- {
- png_bytep sp, dp;
- int sshift, dshift;
- int s_start, s_end, s_inc;
- png_uint_32 i;
-
- 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)
- {
- sshift = (png_size_t)(((row_info->width + 1) & 1) << 2);
- dshift = (png_size_t)(((final_width + 1) & 1) << 2);
- s_start = 4;
- s_end = 0;
- s_inc = -4;
- }
- else
-#endif
- {
- sshift = (png_size_t)((1 - ((row_info->width + 1) & 1)) << 2);
- dshift = (png_size_t)((1 - ((final_width + 1) & 1)) << 2);
- s_start = 0;
- s_end = 4;
- s_inc = 4;
- }
-
- for (i = row_info->width; i; i--)
- {
- png_byte v;
- int j;
-
- v = (png_byte)((*sp >> sshift) & 0xf);
- for (j = 0; j < png_pass_inc[pass]; j++)
- {
- *dp &= (png_byte)((0xf0f >> (4 - dshift)) & 0xff);
- *dp |= (png_byte)(v << dshift);
- if (dshift == s_end)
- {
- dshift = s_start;
- dp--;
- }
- else
- dshift += s_inc;
- }
- if (sshift == s_end)
- {
- sshift = s_start;
- sp--;
- }
- else
- sshift += s_inc;
- }
- break;
- }
-
- default: // This is the place where the routine is modified
- {
- __int64 const4 = 0x0000000000FFFFFF;
- // __int64 const5 = 0x000000FFFFFF0000; // unused...
- __int64 const6 = 0x00000000000000FF;
- png_bytep sptr, dp;
- png_uint_32 i;
- png_size_t pixel_bytes;
- int width = row_info->width;
-
- pixel_bytes = (row_info->pixel_depth >> 3);
-
- sptr = row + (width - 1) * pixel_bytes;
- dp = row + (final_width - 1) * pixel_bytes;
- // New code by Nirav Chhatrapati - Intel Corporation
- // sign fix by GRR
- // NOTE: there is NO MMX code for 48-bit and 64-bit images
-
- // use MMX routine if machine supports it
- if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_INTERLACE)
- /* && mmx_supported */ )
- {
- if (pixel_bytes == 3)
- {
- if (((pass == 0) || (pass == 1)) && width)
- {
- _asm
- {
- mov esi, sptr
- mov edi, dp
- mov ecx, width
- sub edi, 21 // (png_pass_inc[pass] - 1)*pixel_bytes
-loop_pass0:
- movd mm0, [esi] ; X X X X X v2 v1 v0
- pand mm0, const4 ; 0 0 0 0 0 v2 v1 v0
- movq mm1, mm0 ; 0 0 0 0 0 v2 v1 v0
- psllq mm0, 16 ; 0 0 0 v2 v1 v0 0 0
- movq mm2, mm0 ; 0 0 0 v2 v1 v0 0 0
- psllq mm0, 24 ; v2 v1 v0 0 0 0 0 0
- psrlq mm1, 8 ; 0 0 0 0 0 0 v2 v1
- por mm0, mm2 ; v2 v1 v0 v2 v1 v0 0 0
- por mm0, mm1 ; v2 v1 v0 v2 v1 v0 v2 v1
- movq mm3, mm0 ; v2 v1 v0 v2 v1 v0 v2 v1
- psllq mm0, 16 ; v0 v2 v1 v0 v2 v1 0 0
- movq mm4, mm3 ; v2 v1 v0 v2 v1 v0 v2 v1
- punpckhdq mm3, mm0 ; v0 v2 v1 v0 v2 v1 v0 v2
- movq [edi+16] , mm4
- psrlq mm0, 32 ; 0 0 0 0 v0 v2 v1 v0
- movq [edi+8] , mm3
- punpckldq mm0, mm4 ; v1 v0 v2 v1 v0 v2 v1 v0
- sub esi, 3
- movq [edi], mm0
- sub edi, 24
- //sub esi, 3
- dec ecx
- jnz loop_pass0
- EMMS
- }
- }
- else if (((pass == 2) || (pass == 3)) && width)
- {
- _asm
- {
- mov esi, sptr
- mov edi, dp
- mov ecx, width
- sub edi, 9 // (png_pass_inc[pass] - 1)*pixel_bytes
-loop_pass2:
- movd mm0, [esi] ; X X X X X v2 v1 v0
- pand mm0, const4 ; 0 0 0 0 0 v2 v1 v0
- movq mm1, mm0 ; 0 0 0 0 0 v2 v1 v0
- psllq mm0, 16 ; 0 0 0 v2 v1 v0 0 0
- movq mm2, mm0 ; 0 0 0 v2 v1 v0 0 0
- psllq mm0, 24 ; v2 v1 v0 0 0 0 0 0
- psrlq mm1, 8 ; 0 0 0 0 0 0 v2 v1
- por mm0, mm2 ; v2 v1 v0 v2 v1 v0 0 0
- por mm0, mm1 ; v2 v1 v0 v2 v1 v0 v2 v1
- movq [edi+4], mm0 ; move to memory
- psrlq mm0, 16 ; 0 0 v2 v1 v0 v2 v1 v0
- movd [edi], mm0 ; move to memory
- sub esi, 3
- sub edi, 12
- dec ecx
- jnz loop_pass2
- EMMS
- }
- }
- else if (width) /* && ((pass == 4) || (pass == 5)) */
- {
- int width_mmx = ((width >> 1) << 1) - 8;
- if (width_mmx < 0)
- width_mmx = 0;
- width -= width_mmx; // 8 or 9 pix, 24 or 27 bytes
- if (width_mmx)
- {
- _asm
- {
- mov esi, sptr
- mov edi, dp
- mov ecx, width_mmx
- sub esi, 3
- sub edi, 9
-loop_pass4:
- movq mm0, [esi] ; X X v2 v1 v0 v5 v4 v3
- movq mm7, mm0 ; X X v2 v1 v0 v5 v4 v3
- movq mm6, mm0 ; X X v2 v1 v0 v5 v4 v3
- psllq mm0, 24 ; v1 v0 v5 v4 v3 0 0 0
- pand mm7, const4 ; 0 0 0 0 0 v5 v4 v3
- psrlq mm6, 24 ; 0 0 0 X X v2 v1 v0
- por mm0, mm7 ; v1 v0 v5 v4 v3 v5 v4 v3
- movq mm5, mm6 ; 0 0 0 X X v2 v1 v0
- psllq mm6, 8 ; 0 0 X X v2 v1 v0 0
- movq [edi], mm0 ; move quad to memory
- psrlq mm5, 16 ; 0 0 0 0 0 X X v2
- pand mm5, const6 ; 0 0 0 0 0 0 0 v2
- por mm6, mm5 ; 0 0 X X v2 v1 v0 v2
- movd [edi+8], mm6 ; move double to memory
- sub esi, 6
- sub edi, 12
- sub ecx, 2
- jnz loop_pass4
- EMMS
- }
- }
-
- sptr -= width_mmx*3;
- dp -= width_mmx*6;
- for (i = width; i; i--)
- {
- png_byte v[8];
- int j;
-
- png_memcpy(v, sptr, 3);
- for (j = 0; j < png_pass_inc[pass]; j++)
- {
- png_memcpy(dp, v, 3);
- dp -= 3;
- }
- sptr -= 3;
- }
- }
- } /* end of pixel_bytes == 3 */
-
- else if (pixel_bytes == 1)
- {
- if (((pass == 0) || (pass == 1)) && width)
- {
- int width_mmx = ((width >> 2) << 2);
- width -= width_mmx;
- if (width_mmx)
- {
- _asm
- {
- mov esi, sptr
- mov edi, dp
- mov ecx, width_mmx
- sub edi, 31
- sub esi, 3
-loop1_pass0:
- movd mm0, [esi] ; X X X X v0 v1 v2 v3
- movq mm1, mm0 ; X X X X v0 v1 v2 v3
- punpcklbw mm0, mm0 ; v0 v0 v1 v1 v2 v2 v3 v3
- movq mm2, mm0 ; v0 v0 v1 v1 v2 v2 v3 v3
- punpcklwd mm0, mm0 ; v2 v2 v2 v2 v3 v3 v3 v3
- movq mm3, mm0 ; v2 v2 v2 v2 v3 v3 v3 v3
- punpckldq mm0, mm0 ; v3 v3 v3 v3 v3 v3 v3 v3
- punpckhdq mm3, mm3 ; v2 v2 v2 v2 v2 v2 v2 v2
- movq [edi], mm0 ; move to memory v3
- punpckhwd mm2, mm2 ; v0 v0 v0 v0 v1 v1 v1 v1
- movq [edi+8], mm3 ; move to memory v2
- movq mm4, mm2 ; v0 v0 v0 v0 v1 v1 v1 v1
- punpckldq mm2, mm2 ; v1 v1 v1 v1 v1 v1 v1 v1
- punpckhdq mm4, mm4 ; v0 v0 v0 v0 v0 v0 v0 v0
- movq [edi+16], mm2 ; move to memory v1
- movq [edi+24], mm4 ; move to memory v0
- sub esi, 4
- sub edi, 32
- sub ecx, 4
- jnz loop1_pass0
- EMMS
- }
- }
-
- sptr -= width_mmx;
- dp -= width_mmx*8;
- for (i = width; i; i--)
- {
- int j;
-
- /* I simplified this part in version 1.0.4e
- * here and in several other instances where
- * pixel_bytes == 1 -- GR-P
- *
- * Original code:
- *
- * png_byte v[8];
- * png_memcpy(v, sptr, pixel_bytes);
- * for (j = 0; j < png_pass_inc[pass]; j++)
- * {
- * png_memcpy(dp, v, pixel_bytes);
- * dp -= pixel_bytes;
- * }
- * sptr -= pixel_bytes;
- *
- * Replacement code is in the next three lines:
- */
-
- for (j = 0; j < png_pass_inc[pass]; j++)
- *dp-- = *sptr;
- sptr--;
- }
- }
- else if (((pass == 2) || (pass == 3)) && width)
- {
- int width_mmx = ((width >> 2) << 2);
- width -= width_mmx;
- if (width_mmx)
- {
- _asm
- {
- mov esi, sptr
- mov edi, dp
- mov ecx, width_mmx
- sub edi, 15
- sub esi, 3
-loop1_pass2:
- movd mm0, [esi] ; X X X X v0 v1 v2 v3
- punpcklbw mm0, mm0 ; v0 v0 v1 v1 v2 v2 v3 v3
- movq mm1, mm0 ; v0 v0 v1 v1 v2 v2 v3 v3
- punpcklwd mm0, mm0 ; v2 v2 v2 v2 v3 v3 v3 v3
- punpckhwd mm1, mm1 ; v0 v0 v0 v0 v1 v1 v1 v1
- movq [edi], mm0 ; move to memory v2 and v3
- sub esi, 4
- movq [edi+8], mm1 ; move to memory v1 and v0
- sub edi, 16
- sub ecx, 4
- jnz loop1_pass2
- EMMS
- }
- }
-
- sptr -= width_mmx;
- dp -= width_mmx*4;
- for (i = width; i; i--)
- {
- int j;
-
- for (j = 0; j < png_pass_inc[pass]; j++)
- {
- *dp-- = *sptr;
- }
- sptr --;
- }
- }
- else if (width) /* && ((pass == 4) || (pass == 5))) */
- {
- int width_mmx = ((width >> 3) << 3);
- width -= width_mmx;
- if (width_mmx)
- {
- _asm
- {
- mov esi, sptr
- mov edi, dp
- mov ecx, width_mmx
- sub edi, 15
- sub esi, 7
-loop1_pass4:
- movq mm0, [esi] ; v0 v1 v2 v3 v4 v5 v6 v7
- movq mm1, mm0 ; v0 v1 v2 v3 v4 v5 v6 v7
- punpcklbw mm0, mm0 ; v4 v4 v5 v5 v6 v6 v7 v7
- //movq mm1, mm0 ; v0 v0 v1 v1 v2 v2 v3 v3
- punpckhbw mm1, mm1 ;v0 v0 v1 v1 v2 v2 v3 v3
- movq [edi+8], mm1 ; move to memory v0 v1 v2 and v3
- sub esi, 8
- movq [edi], mm0 ; move to memory v4 v5 v6 and v7
- //sub esi, 4
- sub edi, 16
- sub ecx, 8
- jnz loop1_pass4
- EMMS
- }
- }
-
- sptr -= width_mmx;
- dp -= width_mmx*2;
- for (i = width; i; i--)
- {
- int j;
-
- for (j = 0; j < png_pass_inc[pass]; j++)
- {
- *dp-- = *sptr;
- }
- sptr --;
- }
- }
- } /* end of pixel_bytes == 1 */
-
- else if (pixel_bytes == 2)
- {
- if (((pass == 0) || (pass == 1)) && width)
- {
- int width_mmx = ((width >> 1) << 1);
- width -= width_mmx;
- if (width_mmx)
- {
- _asm
- {
- mov esi, sptr
- mov edi, dp
- mov ecx, width_mmx
- sub esi, 2
- sub edi, 30
-loop2_pass0:
- movd mm0, [esi] ; X X X X v1 v0 v3 v2
- punpcklwd mm0, mm0 ; v1 v0 v1 v0 v3 v2 v3 v2
- movq mm1, mm0 ; v1 v0 v1 v0 v3 v2 v3 v2
- punpckldq mm0, mm0 ; v3 v2 v3 v2 v3 v2 v3 v2
- punpckhdq mm1, mm1 ; v1 v0 v1 v0 v1 v0 v1 v0
- movq [edi], mm0
- movq [edi + 8], mm0
- movq [edi + 16], mm1
- movq [edi + 24], mm1
- sub esi, 4
- sub edi, 32
- sub ecx, 2
- jnz loop2_pass0
- EMMS
- }
- }
-
- sptr -= (width_mmx*2 - 2); // sign fixed
- dp -= (width_mmx*16 - 2); // sign fixed
- for (i = width; i; i--)
- {
- png_byte v[8];
- int j;
- sptr -= 2;
- png_memcpy(v, sptr, 2);
- for (j = 0; j < png_pass_inc[pass]; j++)
- {
- dp -= 2;
- png_memcpy(dp, v, 2);
- }
- }
- }
- else if (((pass == 2) || (pass == 3)) && width)
- {
- int width_mmx = ((width >> 1) << 1) ;
- width -= width_mmx;
- if (width_mmx)
- {
- _asm
- {
- mov esi, sptr
- mov edi, dp
- mov ecx, width_mmx
- sub esi, 2
- sub edi, 14
-loop2_pass2:
- movd mm0, [esi] ; X X X X v1 v0 v3 v2
- punpcklwd mm0, mm0 ; v1 v0 v1 v0 v3 v2 v3 v2
- movq mm1, mm0 ; v1 v0 v1 v0 v3 v2 v3 v2
- punpckldq mm0, mm0 ; v3 v2 v3 v2 v3 v2 v3 v2
- punpckhdq mm1, mm1 ; v1 v0 v1 v0 v1 v0 v1 v0
- movq [edi], mm0
- sub esi, 4
- movq [edi + 8], mm1
- //sub esi, 4
- sub edi, 16
- sub ecx, 2
- jnz loop2_pass2
- EMMS
- }
- }
-
- sptr -= (width_mmx*2 - 2); // sign fixed
- dp -= (width_mmx*8 - 2); // sign fixed
- for (i = width; i; i--)
- {
- png_byte v[8];
- int j;
- sptr -= 2;
- png_memcpy(v, sptr, 2);
- for (j = 0; j < png_pass_inc[pass]; j++)
- {
- dp -= 2;
- png_memcpy(dp, v, 2);
- }
- }
- }
- else if (width) // pass == 4 or 5
- {
- int width_mmx = ((width >> 1) << 1) ;
- width -= width_mmx;
- if (width_mmx)
- {
- _asm
- {
- mov esi, sptr
- mov edi, dp
- mov ecx, width_mmx
- sub esi, 2
- sub edi, 6
-loop2_pass4:
- movd mm0, [esi] ; X X X X v1 v0 v3 v2
- punpcklwd mm0, mm0 ; v1 v0 v1 v0 v3 v2 v3 v2
- sub esi, 4
- movq [edi], mm0
- sub edi, 8
- sub ecx, 2
- jnz loop2_pass4
- EMMS
- }
- }
-
- sptr -= (width_mmx*2 - 2); // sign fixed
- dp -= (width_mmx*4 - 2); // sign fixed
- for (i = width; i; i--)
- {
- png_byte v[8];
- int j;
- sptr -= 2;
- png_memcpy(v, sptr, 2);
- for (j = 0; j < png_pass_inc[pass]; j++)
- {
- dp -= 2;
- png_memcpy(dp, v, 2);
- }
- }
- }
- } /* end of pixel_bytes == 2 */
-
- else if (pixel_bytes == 4)
- {
- if (((pass == 0) || (pass == 1)) && width)
- {
- int width_mmx = ((width >> 1) << 1) ;
- width -= width_mmx;
- if (width_mmx)
- {
- _asm
- {
- mov esi, sptr
- mov edi, dp
- mov ecx, width_mmx
- sub esi, 4
- sub edi, 60
-loop4_pass0:
- movq mm0, [esi] ; v3 v2 v1 v0 v7 v6 v5 v4
- movq mm1, mm0 ; v3 v2 v1 v0 v7 v6 v5 v4
- punpckldq mm0, mm0 ; v7 v6 v5 v4 v7 v6 v5 v4
- punpckhdq mm1, mm1 ; v3 v2 v1 v0 v3 v2 v1 v0
- movq [edi], mm0
- movq [edi + 8], mm0
- movq [edi + 16], mm0
- movq [edi + 24], mm0
- movq [edi+32], mm1
- movq [edi + 40], mm1
- movq [edi+ 48], mm1
- sub esi, 8
- movq [edi + 56], mm1
- sub edi, 64
- sub ecx, 2
- jnz loop4_pass0
- EMMS
- }
- }
-
- sptr -= (width_mmx*4 - 4); // sign fixed
- dp -= (width_mmx*32 - 4); // sign fixed
- for (i = width; i; i--)
- {
- png_byte v[8];
- int j;
- sptr -= 4;
- png_memcpy(v, sptr, 4);
- for (j = 0; j < png_pass_inc[pass]; j++)
- {
- dp -= 4;
- png_memcpy(dp, v, 4);
- }
- }
- }
- else if (((pass == 2) || (pass == 3)) && width)
- {
- int width_mmx = ((width >> 1) << 1) ;
- width -= width_mmx;
- if (width_mmx)
- {
- _asm
- {
- mov esi, sptr
- mov edi, dp
- mov ecx, width_mmx
- sub esi, 4
- sub edi, 28
-loop4_pass2:
- movq mm0, [esi] ; v3 v2 v1 v0 v7 v6 v5 v4
- movq mm1, mm0 ; v3 v2 v1 v0 v7 v6 v5 v4
- punpckldq mm0, mm0 ; v7 v6 v5 v4 v7 v6 v5 v4
- punpckhdq mm1, mm1 ; v3 v2 v1 v0 v3 v2 v1 v0
- movq [edi], mm0
- movq [edi + 8], mm0
- movq [edi+16], mm1
- movq [edi + 24], mm1
- sub esi, 8
- sub edi, 32
- sub ecx, 2
- jnz loop4_pass2
- EMMS
- }
- }
-
- sptr -= (width_mmx*4 - 4); // sign fixed
- dp -= (width_mmx*16 - 4); // sign fixed
- for (i = width; i; i--)
- {
- png_byte v[8];
- int j;
- sptr -= 4;
- png_memcpy(v, sptr, 4);
- for (j = 0; j < png_pass_inc[pass]; j++)
- {
- dp -= 4;
- png_memcpy(dp, v, 4);
- }
- }
- }
- else if (width) // pass == 4 or 5
- {
- int width_mmx = ((width >> 1) << 1) ;
- width -= width_mmx;
- if (width_mmx)
- {
- _asm
- {
- mov esi, sptr
- mov edi, dp
- mov ecx, width_mmx
- sub esi, 4
- sub edi, 12
-loop4_pass4:
- movq mm0, [esi] ; v3 v2 v1 v0 v7 v6 v5 v4
- movq mm1, mm0 ; v3 v2 v1 v0 v7 v6 v5 v4
- punpckldq mm0, mm0 ; v7 v6 v5 v4 v7 v6 v5 v4
- punpckhdq mm1, mm1 ; v3 v2 v1 v0 v3 v2 v1 v0
- movq [edi], mm0
- sub esi, 8
- movq [edi + 8], mm1
- sub edi, 16
- sub ecx, 2
- jnz loop4_pass4
- EMMS
- }
- }
-
- sptr -= (width_mmx*4 - 4); // sign fixed
- dp -= (width_mmx*8 - 4); // sign fixed
- for (i = width; i; i--)
- {
- png_byte v[8];
- int j;
- sptr -= 4;
- png_memcpy(v, sptr, 4);
- for (j = 0; j < png_pass_inc[pass]; j++)
- {
- dp -= 4;
- png_memcpy(dp, v, 4);
- }
- }
- }
-
- } /* end of pixel_bytes == 4 */
-
- else if (pixel_bytes == 6)
- {
- for (i = width; i; i--)
- {
- png_byte v[8];
- int j;
- png_memcpy(v, sptr, 6);
- for (j = 0; j < png_pass_inc[pass]; j++)
- {
- png_memcpy(dp, v, 6);
- dp -= 6;
- }
- sptr -= 6;
- }
- } /* end of pixel_bytes == 6 */
-
- else
- {
- for (i = width; i; i--)
- {
- png_byte v[8];
- int j;
- png_memcpy(v, sptr, pixel_bytes);
- for (j = 0; j < png_pass_inc[pass]; j++)
- {
- png_memcpy(dp, v, pixel_bytes);
- dp -= pixel_bytes;
- }
- sptr-= pixel_bytes;
- }
- }
- } /* end of mmx_supported */
-
- else /* MMX not supported: use modified C code - takes advantage
- * of inlining of memcpy for a constant */
- {
- if (pixel_bytes == 1)
- {
- for (i = width; i; i--)
- {
- int j;
- for (j = 0; j < png_pass_inc[pass]; j++)
- *dp-- = *sptr;
- sptr--;
- }
- }
- else if (pixel_bytes == 3)
- {
- for (i = width; i; i--)
- {
- png_byte v[8];
- int j;
- png_memcpy(v, sptr, pixel_bytes);
- for (j = 0; j < png_pass_inc[pass]; j++)
- {
- png_memcpy(dp, v, pixel_bytes);
- dp -= pixel_bytes;
- }
- sptr -= pixel_bytes;
- }
- }
- else if (pixel_bytes == 2)
- {
- for (i = width; i; i--)
- {
- png_byte v[8];
- int j;
- png_memcpy(v, sptr, pixel_bytes);
- for (j = 0; j < png_pass_inc[pass]; j++)
- {
- png_memcpy(dp, v, pixel_bytes);
- dp -= pixel_bytes;
- }
- sptr -= pixel_bytes;
- }
- }
- else if (pixel_bytes == 4)
- {
- for (i = width; i; i--)
- {
- png_byte v[8];
- int j;
- png_memcpy(v, sptr, pixel_bytes);
- for (j = 0; j < png_pass_inc[pass]; j++)
- {
- png_memcpy(dp, v, pixel_bytes);
- dp -= pixel_bytes;
- }
- sptr -= pixel_bytes;
- }
- }
- else if (pixel_bytes == 6)
- {
- for (i = width; i; i--)
- {
- png_byte v[8];
- int j;
- png_memcpy(v, sptr, pixel_bytes);
- for (j = 0; j < png_pass_inc[pass]; j++)
- {
- png_memcpy(dp, v, pixel_bytes);
- dp -= pixel_bytes;
- }
- sptr -= pixel_bytes;
- }
- }
- else
- {
- for (i = width; i; i--)
- {
- png_byte v[8];
- int j;
- png_memcpy(v, sptr, pixel_bytes);
- for (j = 0; j < png_pass_inc[pass]; j++)
- {
- png_memcpy(dp, v, pixel_bytes);
- dp -= pixel_bytes;
- }
- sptr -= pixel_bytes;
- }
- }
-
- } /* end of MMX not supported */
- break;
- }
- } /* end switch (row_info->pixel_depth) */
-
- row_info->width = final_width;
-
- row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,final_width);
- }
-
-}
-
-#endif /* PNG_READ_INTERLACING_SUPPORTED */
-
-
-// These variables are utilized in the functions below. They are declared
-// globally here to ensure alignment on 8-byte boundaries.
-
-union uAll {
- __int64 use;
- double align;
-} LBCarryMask = {0x0101010101010101},
- HBClearMask = {0x7f7f7f7f7f7f7f7f},
- ActiveMask, ActiveMask2, ActiveMaskEnd, ShiftBpp, ShiftRem;
-
-
-// Optimized code for PNG Average filter decoder
-void /* PRIVATE */
-png_read_filter_row_mmx_avg(png_row_infop row_info, png_bytep row
- , png_bytep prev_row)
-{
- int bpp;
- png_uint_32 FullLength;
- png_uint_32 MMXLength;
- //png_uint_32 len;
- int diff;
-
- bpp = (row_info->pixel_depth + 7) >> 3; // Get # bytes per pixel
- FullLength = row_info->rowbytes; // # of bytes to filter
- _asm {
- // Init address pointers and offset
- mov edi, row // edi ==> Avg(x)
- xor ebx, ebx // ebx ==> x
- mov edx, edi
- mov esi, prev_row // esi ==> Prior(x)
- sub edx, bpp // edx ==> Raw(x-bpp)
-
- xor eax, eax
- // Compute the Raw value for the first bpp bytes
- // Raw(x) = Avg(x) + (Prior(x)/2)
-davgrlp:
- mov al, [esi + ebx] // Load al with Prior(x)
- inc ebx
- shr al, 1 // divide by 2
- add al, [edi+ebx-1] // Add Avg(x); -1 to offset inc ebx
- cmp ebx, bpp
- mov [edi+ebx-1], al // Write back Raw(x);
- // mov does not affect flags; -1 to offset inc ebx
- jb davgrlp
- // get # of bytes to alignment
- mov diff, edi // take start of row
- add diff, ebx // add bpp
- add diff, 0xf // add 7 + 8 to incr past alignment boundary
- and diff, 0xfffffff8 // mask to alignment boundary
- sub diff, edi // subtract from start ==> value ebx at alignment
- jz davggo
- // fix alignment
- // Compute the Raw value for the bytes upto the alignment boundary
- // Raw(x) = Avg(x) + ((Raw(x-bpp) + Prior(x))/2)
- xor ecx, ecx
-davglp1:
- xor eax, eax
- mov cl, [esi + ebx] // load cl with Prior(x)
- mov al, [edx + ebx] // load al with Raw(x-bpp)
- add ax, cx
- inc ebx
- shr ax, 1 // divide by 2
- add al, [edi+ebx-1] // Add Avg(x); -1 to offset inc ebx
- cmp ebx, diff // Check if at alignment boundary
- mov [edi+ebx-1], al // Write back Raw(x);
- // mov does not affect flags; -1 to offset inc ebx
- jb davglp1 // Repeat until at alignment boundary
-davggo:
- mov eax, FullLength
- mov ecx, eax
- sub eax, ebx // subtract alignment fix
- and eax, 0x00000007 // calc bytes over mult of 8
- sub ecx, eax // drop over bytes from original length
- mov MMXLength, ecx
- } // end _asm block
- // Now do the math for the rest of the row
- switch ( bpp )
- {
- case 3:
- {
- ActiveMask.use = 0x0000000000ffffff;
- ShiftBpp.use = 24; // == 3 * 8
- ShiftRem.use = 40; // == 64 - 24
- _asm {
- // Re-init address pointers and offset
- movq mm7, ActiveMask
- mov ebx, diff // ebx ==> x = offset to alignment boundary
- movq mm5, LBCarryMask
- mov edi, row // edi ==> Avg(x)
- movq mm4, HBClearMask
- mov esi, prev_row // esi ==> Prior(x)
- // PRIME the pump (load the first Raw(x-bpp) data set
- movq mm2, [edi + ebx - 8] // Load previous aligned 8 bytes
- // (we correct position in loop below)
-davg3lp:
- movq mm0, [edi + ebx] // Load mm0 with Avg(x)
- // Add (Prev_row/2) to Average
- movq mm3, mm5
- psrlq mm2, ShiftRem // Correct position Raw(x-bpp) data
- movq mm1, [esi + ebx] // Load mm1 with Prior(x)
- movq mm6, mm7
- pand mm3, mm1 // get lsb for each prev_row byte
- psrlq mm1, 1 // divide prev_row bytes by 2
- pand mm1, mm4 // clear invalid bit 7 of each byte
- paddb mm0, mm1 // add (Prev_row/2) to Avg for each byte
- // Add 1st active group (Raw(x-bpp)/2) to Average with LBCarry
- movq mm1, mm3 // now use mm1 for getting LBCarrys
- pand mm1, mm2 // get LBCarrys for each byte where both
- // lsb's were == 1 (Only valid for active group)
- psrlq mm2, 1 // divide raw bytes by 2
- pand mm2, mm4 // clear invalid bit 7 of each byte
- paddb mm2, mm1 // add LBCarrys to (Raw(x-bpp)/2) for each byte
- pand mm2, mm6 // Leave only Active Group 1 bytes to add to Avg
- paddb mm0, mm2 // add (Raw/2) + LBCarrys to Avg for each Active
- // byte
- // Add 2nd active group (Raw(x-bpp)/2) to Average with LBCarry
- psllq mm6, ShiftBpp // shift the mm6 mask to cover bytes 3-5
- movq mm2, mm0 // mov updated Raws to mm2
- psllq mm2, ShiftBpp // shift data to position correctly
- movq mm1, mm3 // now use mm1 for getting LBCarrys
- pand mm1, mm2 // get LBCarrys for each byte where both
- // lsb's were == 1 (Only valid for active group)
- psrlq mm2, 1 // divide raw bytes by 2
- pand mm2, mm4 // clear invalid bit 7 of each byte
- paddb mm2, mm1 // add LBCarrys to (Raw(x-bpp)/2) for each byte
- pand mm2, mm6 // Leave only Active Group 2 bytes to add to Avg
- paddb mm0, mm2 // add (Raw/2) + LBCarrys to Avg for each Active
- // byte
-
- // Add 3rd active group (Raw(x-bpp)/2) to Average with LBCarry
- psllq mm6, ShiftBpp // shift the mm6 mask to cover the last two
- // bytes
- movq mm2, mm0 // mov updated Raws to mm2
- psllq mm2, ShiftBpp // shift data to position correctly
- // Data only needs to be shifted once here to
- // get the correct x-bpp offset.
- movq mm1, mm3 // now use mm1 for getting LBCarrys
- pand mm1, mm2 // get LBCarrys for each byte where both
- // lsb's were == 1 (Only valid for active group)
- psrlq mm2, 1 // divide raw bytes by 2
- pand mm2, mm4 // clear invalid bit 7 of each byte
- paddb mm2, mm1 // add LBCarrys to (Raw(x-bpp)/2) for each byte
- pand mm2, mm6 // Leave only Active Group 2 bytes to add to Avg
- add ebx, 8
- paddb mm0, mm2 // add (Raw/2) + LBCarrys to Avg for each Active
- // byte
-
- // Now ready to write back to memory
- movq [edi + ebx - 8], mm0
- // Move updated Raw(x) to use as Raw(x-bpp) for next loop
- cmp ebx, MMXLength
- movq mm2, mm0 // mov updated Raw(x) to mm2
- jb davg3lp
- } // end _asm block
- }
- break;
-
- case 6:
- case 4:
- case 7:
- case 5:
- {
- ActiveMask.use = 0xffffffffffffffff; // use shift below to clear
- // appropriate inactive bytes
- ShiftBpp.use = bpp << 3;
- ShiftRem.use = 64 - ShiftBpp.use;
- _asm {
- movq mm4, HBClearMask
- // Re-init address pointers and offset
- mov ebx, diff // ebx ==> x = offset to alignment boundary
- // Load ActiveMask and clear all bytes except for 1st active group
- movq mm7, ActiveMask
- mov edi, row // edi ==> Avg(x)
- psrlq mm7, ShiftRem
- mov esi, prev_row // esi ==> Prior(x)
- movq mm6, mm7
- movq mm5, LBCarryMask
- psllq mm6, ShiftBpp // Create mask for 2nd active group
- // PRIME the pump (load the first Raw(x-bpp) data set
- movq mm2, [edi + ebx - 8] // Load previous aligned 8 bytes
- // (we correct position in loop below)
-davg4lp:
- movq mm0, [edi + ebx]
- psrlq mm2, ShiftRem // shift data to position correctly
- movq mm1, [esi + ebx]
- // Add (Prev_row/2) to Average
- movq mm3, mm5
- pand mm3, mm1 // get lsb for each prev_row byte
- psrlq mm1, 1 // divide prev_row bytes by 2
- pand mm1, mm4 // clear invalid bit 7 of each byte
- paddb mm0, mm1 // add (Prev_row/2) to Avg for each byte
- // Add 1st active group (Raw(x-bpp)/2) to Average with LBCarry
- movq mm1, mm3 // now use mm1 for getting LBCarrys
- pand mm1, mm2 // get LBCarrys for each byte where both
- // lsb's were == 1 (Only valid for active group)
- psrlq mm2, 1 // divide raw bytes by 2
- pand mm2, mm4 // clear invalid bit 7 of each byte
- paddb mm2, mm1 // add LBCarrys to (Raw(x-bpp)/2) for each byte
- pand mm2, mm7 // Leave only Active Group 1 bytes to add to Avg
- paddb mm0, mm2 // add (Raw/2) + LBCarrys to Avg for each Active
- // byte
- // Add 2nd active group (Raw(x-bpp)/2) to Average with LBCarry
- movq mm2, mm0 // mov updated Raws to mm2
- psllq mm2, ShiftBpp // shift data to position correctly
- add ebx, 8
- movq mm1, mm3 // now use mm1 for getting LBCarrys
- pand mm1, mm2 // get LBCarrys for each byte where both
- // lsb's were == 1 (Only valid for active group)
- psrlq mm2, 1 // divide raw bytes by 2
- pand mm2, mm4 // clear invalid bit 7 of each byte
- paddb mm2, mm1 // add LBCarrys to (Raw(x-bpp)/2) for each byte
- pand mm2, mm6 // Leave only Active Group 2 bytes to add to Avg
- paddb mm0, mm2 // add (Raw/2) + LBCarrys to Avg for each Active
- // byte
- cmp ebx, MMXLength
- // Now ready to write back to memory
- movq [edi + ebx - 8], mm0
- // Prep Raw(x-bpp) for next loop
- movq mm2, mm0 // mov updated Raws to mm2
- jb davg4lp
- } // end _asm block
- }
- break;
- case 2:
- {
- ActiveMask.use = 0x000000000000ffff;
- ShiftBpp.use = 16; // == 2 * 8 [BUGFIX]
- ShiftRem.use = 48; // == 64 - 16 [BUGFIX]
- _asm {
- // Load ActiveMask
- movq mm7, ActiveMask
- // Re-init address pointers and offset
- mov ebx, diff // ebx ==> x = offset to alignment boundary
- movq mm5, LBCarryMask
- mov edi, row // edi ==> Avg(x)
- movq mm4, HBClearMask
- mov esi, prev_row // esi ==> Prior(x)
- // PRIME the pump (load the first Raw(x-bpp) data set
- movq mm2, [edi + ebx - 8] // Load previous aligned 8 bytes
- // (we correct position in loop below)
-davg2lp:
- movq mm0, [edi + ebx]
- psrlq mm2, ShiftRem // shift data to position correctly [BUGFIX]
- movq mm1, [esi + ebx]
- // Add (Prev_row/2) to Average
- movq mm3, mm5
- pand mm3, mm1 // get lsb for each prev_row byte
- psrlq mm1, 1 // divide prev_row bytes by 2
- pand mm1, mm4 // clear invalid bit 7 of each byte
- movq mm6, mm7
- paddb mm0, mm1 // add (Prev_row/2) to Avg for each byte
- // Add 1st active group (Raw(x-bpp)/2) to Average with LBCarry
- movq mm1, mm3 // now use mm1 for getting LBCarrys
- pand mm1, mm2 // get LBCarrys for each byte where both
- // lsb's were == 1 (Only valid for active group)
- psrlq mm2, 1 // divide raw bytes by 2
- pand mm2, mm4 // clear invalid bit 7 of each byte
- paddb mm2, mm1 // add LBCarrys to (Raw(x-bpp)/2) for each byte
- pand mm2, mm6 // Leave only Active Group 1 bytes to add to Avg
- paddb mm0, mm2 // add (Raw/2) + LBCarrys to Avg for each Active byte
- // Add 2nd active group (Raw(x-bpp)/2) to Average with LBCarry
- psllq mm6, ShiftBpp // shift the mm6 mask to cover bytes 2 & 3
- movq mm2, mm0 // mov updated Raws to mm2
- psllq mm2, ShiftBpp // shift data to position correctly
- movq mm1, mm3 // now use mm1 for getting LBCarrys
- pand mm1, mm2 // get LBCarrys for each byte where both
- // lsb's were == 1 (Only valid for active group)
- psrlq mm2, 1 // divide raw bytes by 2
- pand mm2, mm4 // clear invalid bit 7 of each byte
- paddb mm2, mm1 // add LBCarrys to (Raw(x-bpp)/2) for each byte
- pand mm2, mm6 // Leave only Active Group 2 bytes to add to Avg
- paddb mm0, mm2 // add (Raw/2) + LBCarrys to Avg for each Active byte
-
- // Add rdd active group (Raw(x-bpp)/2) to Average with LBCarry
- psllq mm6, ShiftBpp // shift the mm6 mask to cover bytes 4 & 5
- movq mm2, mm0 // mov updated Raws to mm2
- psllq mm2, ShiftBpp // shift data to position correctly
- // Data only needs to be shifted once here to
- // get the correct x-bpp offset.
- movq mm1, mm3 // now use mm1 for getting LBCarrys
- pand mm1, mm2 // get LBCarrys for each byte where both
- // lsb's were == 1 (Only valid for active group)
- psrlq mm2, 1 // divide raw bytes by 2
- pand mm2, mm4 // clear invalid bit 7 of each byte
- paddb mm2, mm1 // add LBCarrys to (Raw(x-bpp)/2) for each byte
- pand mm2, mm6 // Leave only Active Group 2 bytes to add to Avg
- paddb mm0, mm2 // add (Raw/2) + LBCarrys to Avg for each Active byte
-
- // Add 4th active group (Raw(x-bpp)/2) to Average with LBCarry
- psllq mm6, ShiftBpp // shift the mm6 mask to cover bytes 6 & 7
- movq mm2, mm0 // mov updated Raws to mm2
- psllq mm2, ShiftBpp // shift data to position correctly
- // Data only needs to be shifted once here to
- // get the correct x-bpp offset.
- add ebx, 8
- movq mm1, mm3 // now use mm1 for getting LBCarrys
- pand mm1, mm2 // get LBCarrys for each byte where both
- // lsb's were == 1 (Only valid for active group)
- psrlq mm2, 1 // divide raw bytes by 2
- pand mm2, mm4 // clear invalid bit 7 of each byte
- paddb mm2, mm1 // add LBCarrys to (Raw(x-bpp)/2) for each byte
- pand mm2, mm6 // Leave only Active Group 2 bytes to add to Avg
- paddb mm0, mm2 // add (Raw/2) + LBCarrys to Avg for each Active byte
-
- cmp ebx, MMXLength
- // Now ready to write back to memory
- movq [edi + ebx - 8], mm0
- // Prep Raw(x-bpp) for next loop
- movq mm2, mm0 // mov updated Raws to mm2
- jb davg2lp
- } // end _asm block
- }
- break;
-
- case 1: // bpp == 1
- {
- _asm {
- // Re-init address pointers and offset
- mov ebx, diff // ebx ==> x = offset to alignment boundary
- mov edi, row // edi ==> Avg(x)
- cmp ebx, FullLength // Test if offset at end of array
- jnb davg1end
- // Do Paeth decode for remaining bytes
- mov esi, prev_row // esi ==> Prior(x)
- mov edx, edi
- xor ecx, ecx // zero ecx before using cl & cx in loop below
- sub edx, bpp // edx ==> Raw(x-bpp)
-davg1lp:
- // Raw(x) = Avg(x) + ((Raw(x-bpp) + Prior(x))/2)
- xor eax, eax
- mov cl, [esi + ebx] // load cl with Prior(x)
- mov al, [edx + ebx] // load al with Raw(x-bpp)
- add ax, cx
- inc ebx
- shr ax, 1 // divide by 2
- add al, [edi+ebx-1] // Add Avg(x); -1 to offset inc ebx
- cmp ebx, FullLength // Check if at end of array
- mov [edi+ebx-1], al // Write back Raw(x);
- // mov does not affect flags; -1 to offset inc ebx
- jb davg1lp
-davg1end:
- } // end _asm block
- }
- return;
-
- case 8: // bpp == 8
- {
- _asm {
- // Re-init address pointers and offset
- mov ebx, diff // ebx ==> x = offset to alignment boundary
- movq mm5, LBCarryMask
- mov edi, row // edi ==> Avg(x)
- movq mm4, HBClearMask
- mov esi, prev_row // esi ==> Prior(x)
- // PRIME the pump (load the first Raw(x-bpp) data set
- movq mm2, [edi + ebx - 8] // Load previous aligned 8 bytes
- // (NO NEED to correct position in loop below)
-davg8lp:
- movq mm0, [edi + ebx]
- movq mm3, mm5
- movq mm1, [esi + ebx]
- add ebx, 8
- pand mm3, mm1 // get lsb for each prev_row byte
- psrlq mm1, 1 // divide prev_row bytes by 2
- pand mm3, mm2 // get LBCarrys for each byte where both
- // lsb's were == 1
- psrlq mm2, 1 // divide raw bytes by 2
- pand mm1, mm4 // clear invalid bit 7 of each byte
- paddb mm0, mm3 // add LBCarrys to Avg for each byte
- pand mm2, mm4 // clear invalid bit 7 of each byte
- paddb mm0, mm1 // add (Prev_row/2) to Avg for each byte
- paddb mm0, mm2 // add (Raw/2) to Avg for each byte
- cmp ebx, MMXLength
- movq [edi + ebx - 8], mm0
- movq mm2, mm0 // reuse as Raw(x-bpp)
- jb davg8lp
- } // end _asm block
- }
- break;
- default: // bpp greater than 8
- {
- _asm {
- movq mm5, LBCarryMask
- // Re-init address pointers and offset
- mov ebx, diff // ebx ==> x = offset to alignment boundary
- mov edi, row // edi ==> Avg(x)
- movq mm4, HBClearMask
- mov edx, edi
- mov esi, prev_row // esi ==> Prior(x)
- sub edx, bpp // edx ==> Raw(x-bpp)
-davgAlp:
- movq mm0, [edi + ebx]
- movq mm3, mm5
- movq mm1, [esi + ebx]
- pand mm3, mm1 // get lsb for each prev_row byte
- movq mm2, [edx + ebx]
- psrlq mm1, 1 // divide prev_row bytes by 2
- pand mm3, mm2 // get LBCarrys for each byte where both
- // lsb's were == 1
- psrlq mm2, 1 // divide raw bytes by 2
- pand mm1, mm4 // clear invalid bit 7 of each byte
- paddb mm0, mm3 // add LBCarrys to Avg for each byte
- pand mm2, mm4 // clear invalid bit 7 of each byte
- paddb mm0, mm1 // add (Prev_row/2) to Avg for each byte
- add ebx, 8
- paddb mm0, mm2 // add (Raw/2) to Avg for each byte
- cmp ebx, MMXLength
- movq [edi + ebx - 8], mm0
- jb davgAlp
- } // end _asm block
- }
- break;
- } // end switch ( bpp )
-
- _asm {
- // MMX acceleration complete now do clean-up
- // Check if any remaining bytes left to decode
- mov ebx, MMXLength // ebx ==> x = offset bytes remaining after MMX
- mov edi, row // edi ==> Avg(x)
- cmp ebx, FullLength // Test if offset at end of array
- jnb davgend
- // Do Paeth decode for remaining bytes
- mov esi, prev_row // esi ==> Prior(x)
- mov edx, edi
- xor ecx, ecx // zero ecx before using cl & cx in loop below
- sub edx, bpp // edx ==> Raw(x-bpp)
-davglp2:
- // Raw(x) = Avg(x) + ((Raw(x-bpp) + Prior(x))/2)
- xor eax, eax
- mov cl, [esi + ebx] // load cl with Prior(x)
- mov al, [edx + ebx] // load al with Raw(x-bpp)
- add ax, cx
- inc ebx
- shr ax, 1 // divide by 2
- add al, [edi+ebx-1] // Add Avg(x); -1 to offset inc ebx
- cmp ebx, FullLength // Check if at end of array
- mov [edi+ebx-1], al // Write back Raw(x);
- // mov does not affect flags; -1 to offset inc ebx
- jb davglp2
-davgend:
- emms // End MMX instructions; prep for possible FP instrs.
- } // end _asm block
-}
-
-// Optimized code for PNG Paeth filter decoder
-void /* PRIVATE */
-png_read_filter_row_mmx_paeth(png_row_infop row_info, png_bytep row,
- png_bytep prev_row)
-{
- png_uint_32 FullLength;
- png_uint_32 MMXLength;
- //png_uint_32 len;
- int bpp;
- int diff;
- //int ptemp;
- int patemp, pbtemp, pctemp;
-
- bpp = (row_info->pixel_depth + 7) >> 3; // Get # bytes per pixel
- FullLength = row_info->rowbytes; // # of bytes to filter
- _asm
- {
- xor ebx, ebx // ebx ==> x offset
- mov edi, row
- xor edx, edx // edx ==> x-bpp offset
- mov esi, prev_row
- xor eax, eax
-
- // Compute the Raw value for the first bpp bytes
- // Note: the formula works out to be always
- // Paeth(x) = Raw(x) + Prior(x) where x < bpp
-dpthrlp:
- mov al, [edi + ebx]
- add al, [esi + ebx]
- inc ebx
- cmp ebx, bpp
- mov [edi + ebx - 1], al
- jb dpthrlp
- // get # of bytes to alignment
- mov diff, edi // take start of row
- add diff, ebx // add bpp
- xor ecx, ecx
- add diff, 0xf // add 7 + 8 to incr past alignment boundary
- and diff, 0xfffffff8 // mask to alignment boundary
- sub diff, edi // subtract from start ==> value ebx at alignment
- jz dpthgo
- // fix alignment
-dpthlp1:
- xor eax, eax
- // pav = p - a = (a + b - c) - a = b - c
- mov al, [esi + ebx] // load Prior(x) into al
- mov cl, [esi + edx] // load Prior(x-bpp) into cl
- sub eax, ecx // subtract Prior(x-bpp)
- mov patemp, eax // Save pav for later use
- xor eax, eax
- // pbv = p - b = (a + b - c) - b = a - c
- mov al, [edi + edx] // load Raw(x-bpp) into al
- sub eax, ecx // subtract Prior(x-bpp)
- mov ecx, eax
- // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
- add eax, patemp // pcv = pav + pbv
- // pc = abs(pcv)
- test eax, 0x80000000
- jz dpthpca
- neg eax // reverse sign of neg values
-dpthpca:
- mov pctemp, eax // save pc for later use
- // pb = abs(pbv)
- test ecx, 0x80000000
- jz dpthpba
- neg ecx // reverse sign of neg values
-dpthpba:
- mov pbtemp, ecx // save pb for later use
- // pa = abs(pav)
- mov eax, patemp
- test eax, 0x80000000
- jz dpthpaa
- neg eax // reverse sign of neg values
-dpthpaa:
- mov patemp, eax // save pa for later use
- // test if pa <= pb
- cmp eax, ecx
- jna dpthabb
- // pa > pb; now test if pb <= pc
- cmp ecx, pctemp
- jna dpthbbc
- // pb > pc; Raw(x) = Paeth(x) + Prior(x-bpp)
- mov cl, [esi + edx] // load Prior(x-bpp) into cl
- jmp dpthpaeth
-dpthbbc:
- // pb <= pc; Raw(x) = Paeth(x) + Prior(x)
- mov cl, [esi + ebx] // load Prior(x) into cl
- jmp dpthpaeth
-dpthabb:
- // pa <= pb; now test if pa <= pc
- cmp eax, pctemp
- jna dpthabc
- // pa > pc; Raw(x) = Paeth(x) + Prior(x-bpp)
- mov cl, [esi + edx] // load Prior(x-bpp) into cl
- jmp dpthpaeth
-dpthabc:
- // pa <= pc; Raw(x) = Paeth(x) + Raw(x-bpp)
- mov cl, [edi + edx] // load Raw(x-bpp) into cl
-dpthpaeth:
- inc ebx
- inc edx
- // Raw(x) = (Paeth(x) + Paeth_Predictor( a, b, c )) mod 256
- add [edi + ebx - 1], cl
- cmp ebx, diff
- jb dpthlp1
-dpthgo:
- mov ecx, FullLength
- mov eax, ecx
- sub eax, ebx // subtract alignment fix
- and eax, 0x00000007 // calc bytes over mult of 8
- sub ecx, eax // drop over bytes from original length
- mov MMXLength, ecx
- } // end _asm block
- // Now do the math for the rest of the row
- switch ( bpp )
- {
- case 3:
- {
- ActiveMask.use = 0x0000000000ffffff;
- ActiveMaskEnd.use = 0xffff000000000000;
- ShiftBpp.use = 24; // == bpp(3) * 8
- ShiftRem.use = 40; // == 64 - 24
- _asm
- {
- mov ebx, diff
- mov edi, row
- mov esi, prev_row
- pxor mm0, mm0
- // PRIME the pump (load the first Raw(x-bpp) data set
- movq mm1, [edi+ebx-8]
-dpth3lp:
- psrlq mm1, ShiftRem // shift last 3 bytes to 1st 3 bytes
- movq mm2, [esi + ebx] // load b=Prior(x)
- punpcklbw mm1, mm0 // Unpack High bytes of a
- movq mm3, [esi+ebx-8] // Prep c=Prior(x-bpp) bytes
- punpcklbw mm2, mm0 // Unpack High bytes of b
- psrlq mm3, ShiftRem // shift last 3 bytes to 1st 3 bytes
- // pav = p - a = (a + b - c) - a = b - c
- movq mm4, mm2
- punpcklbw mm3, mm0 // Unpack High bytes of c
- // pbv = p - b = (a + b - c) - b = a - c
- movq mm5, mm1
- psubw mm4, mm3
- pxor mm7, mm7
- // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
- movq mm6, mm4
- psubw mm5, mm3
-
- // pa = abs(p-a) = abs(pav)
- // pb = abs(p-b) = abs(pbv)
- // pc = abs(p-c) = abs(pcv)
- pcmpgtw mm0, mm4 // Create mask pav bytes < 0
- paddw mm6, mm5
- pand mm0, mm4 // Only pav bytes < 0 in mm7
- pcmpgtw mm7, mm5 // Create mask pbv bytes < 0
- psubw mm4, mm0
- pand mm7, mm5 // Only pbv bytes < 0 in mm0
- psubw mm4, mm0
- psubw mm5, mm7
- pxor mm0, mm0
- pcmpgtw mm0, mm6 // Create mask pcv bytes < 0
- pand mm0, mm6 // Only pav bytes < 0 in mm7
- psubw mm5, mm7
- psubw mm6, mm0
- // test pa <= pb
- movq mm7, mm4
- psubw mm6, mm0
- pcmpgtw mm7, mm5 // pa > pb?
- movq mm0, mm7
- // use mm7 mask to merge pa & pb
- pand mm5, mm7
- // use mm0 mask copy to merge a & b
- pand mm2, mm0
- pandn mm7, mm4
- pandn mm0, mm1
- paddw mm7, mm5
- paddw mm0, mm2
- // test ((pa <= pb)? pa:pb) <= pc
- pcmpgtw mm7, mm6 // pab > pc?
- pxor mm1, mm1
- pand mm3, mm7
- pandn mm7, mm0
- paddw mm7, mm3
- pxor mm0, mm0
- packuswb mm7, mm1
- movq mm3, [esi + ebx] // load c=Prior(x-bpp)
- pand mm7, ActiveMask
- movq mm2, mm3 // load b=Prior(x) step 1
- paddb mm7, [edi + ebx] // add Paeth predictor with Raw(x)
- punpcklbw mm3, mm0 // Unpack High bytes of c
- movq [edi + ebx], mm7 // write back updated value
- movq mm1, mm7 // Now mm1 will be used as Raw(x-bpp)
- // Now do Paeth for 2nd set of bytes (3-5)
- psrlq mm2, ShiftBpp // load b=Prior(x) step 2
- punpcklbw mm1, mm0 // Unpack High bytes of a
- pxor mm7, mm7
- punpcklbw mm2, mm0 // Unpack High bytes of b
- // pbv = p - b = (a + b - c) - b = a - c
- movq mm5, mm1
- // pav = p - a = (a + b - c) - a = b - c
- movq mm4, mm2
- psubw mm5, mm3
- psubw mm4, mm3
- // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) =
- // pav + pbv = pbv + pav
- movq mm6, mm5
- paddw mm6, mm4
-
- // pa = abs(p-a) = abs(pav)
- // pb = abs(p-b) = abs(pbv)
- // pc = abs(p-c) = abs(pcv)
- pcmpgtw mm0, mm5 // Create mask pbv bytes < 0
- pcmpgtw mm7, mm4 // Create mask pav bytes < 0
- pand mm0, mm5 // Only pbv bytes < 0 in mm0
- pand mm7, mm4 // Only pav bytes < 0 in mm7
- psubw mm5, mm0
- psubw mm4, mm7
- psubw mm5, mm0
- psubw mm4, mm7
- pxor mm0, mm0
- pcmpgtw mm0, mm6 // Create mask pcv bytes < 0
- pand mm0, mm6 // Only pav bytes < 0 in mm7
- psubw mm6, mm0
- // test pa <= pb
- movq mm7, mm4
- psubw mm6, mm0
- pcmpgtw mm7, mm5 // pa > pb?
- movq mm0, mm7
- // use mm7 mask to merge pa & pb
- pand mm5, mm7
- // use mm0 mask copy to merge a & b
- pand mm2, mm0
- pandn mm7, mm4
- pandn mm0, mm1
- paddw mm7, mm5
- paddw mm0, mm2
- // test ((pa <= pb)? pa:pb) <= pc
- pcmpgtw mm7, mm6 // pab > pc?
- movq mm2, [esi + ebx] // load b=Prior(x)
- pand mm3, mm7
- pandn mm7, mm0
- pxor mm1, mm1
- paddw mm7, mm3
- pxor mm0, mm0
- packuswb mm7, mm1
- movq mm3, mm2 // load c=Prior(x-bpp) step 1
- pand mm7, ActiveMask
- punpckhbw mm2, mm0 // Unpack High bytes of b
- psllq mm7, ShiftBpp // Shift bytes to 2nd group of 3 bytes
- // pav = p - a = (a + b - c) - a = b - c
- movq mm4, mm2
- paddb mm7, [edi + ebx] // add Paeth predictor with Raw(x)
- psllq mm3, ShiftBpp // load c=Prior(x-bpp) step 2
- movq [edi + ebx], mm7 // write back updated value
- movq mm1, mm7
- punpckhbw mm3, mm0 // Unpack High bytes of c
- psllq mm1, ShiftBpp // Shift bytes
- // Now mm1 will be used as Raw(x-bpp)
- // Now do Paeth for 3rd, and final, set of bytes (6-7)
- pxor mm7, mm7
- punpckhbw mm1, mm0 // Unpack High bytes of a
- psubw mm4, mm3
- // pbv = p - b = (a + b - c) - b = a - c
- movq mm5, mm1
- // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
- movq mm6, mm4
- psubw mm5, mm3
- pxor mm0, mm0
- paddw mm6, mm5
-
- // pa = abs(p-a) = abs(pav)
- // pb = abs(p-b) = abs(pbv)
- // pc = abs(p-c) = abs(pcv)
- pcmpgtw mm0, mm4 // Create mask pav bytes < 0
- pcmpgtw mm7, mm5 // Create mask pbv bytes < 0
- pand mm0, mm4 // Only pav bytes < 0 in mm7
- pand mm7, mm5 // Only pbv bytes < 0 in mm0
- psubw mm4, mm0
- psubw mm5, mm7
- psubw mm4, mm0
- psubw mm5, mm7
- pxor mm0, mm0
- pcmpgtw mm0, mm6 // Create mask pcv bytes < 0
- pand mm0, mm6 // Only pav bytes < 0 in mm7
- psubw mm6, mm0
- // test pa <= pb
- movq mm7, mm4
- psubw mm6, mm0
- pcmpgtw mm7, mm5 // pa > pb?
- movq mm0, mm7
- // use mm0 mask copy to merge a & b
- pand mm2, mm0
- // use mm7 mask to merge pa & pb
- pand mm5, mm7
- pandn mm0, mm1
- pandn mm7, mm4
- paddw mm0, mm2
- paddw mm7, mm5
- // test ((pa <= pb)? pa:pb) <= pc
- pcmpgtw mm7, mm6 // pab > pc?
- pand mm3, mm7
- pandn mm7, mm0
- paddw mm7, mm3
- pxor mm1, mm1
- packuswb mm1, mm7
- // Step ebx to next set of 8 bytes and repeat loop til done
- add ebx, 8
- pand mm1, ActiveMaskEnd
- paddb mm1, [edi + ebx - 8] // add Paeth predictor with Raw(x)
-
- cmp ebx, MMXLength
- pxor mm0, mm0 // pxor does not affect flags
- movq [edi + ebx - 8], mm1 // write back updated value
- // mm1 will be used as Raw(x-bpp) next loop
- // mm3 ready to be used as Prior(x-bpp) next loop
- jb dpth3lp
- } // end _asm block
- }
- break;
-
- case 6:
- case 7:
- case 5:
- {
- ActiveMask.use = 0x00000000ffffffff;
- ActiveMask2.use = 0xffffffff00000000;
- ShiftBpp.use = bpp << 3; // == bpp * 8
- ShiftRem.use = 64 - ShiftBpp.use;
- _asm
- {
- mov ebx, diff
- mov edi, row
- mov esi, prev_row
- // PRIME the pump (load the first Raw(x-bpp) data set
- movq mm1, [edi+ebx-8]
- pxor mm0, mm0
-dpth6lp:
- // Must shift to position Raw(x-bpp) data
- psrlq mm1, ShiftRem
- // Do first set of 4 bytes
- movq mm3, [esi+ebx-8] // read c=Prior(x-bpp) bytes
- punpcklbw mm1, mm0 // Unpack Low bytes of a
- movq mm2, [esi + ebx] // load b=Prior(x)
- punpcklbw mm2, mm0 // Unpack Low bytes of b
- // Must shift to position Prior(x-bpp) data
- psrlq mm3, ShiftRem
- // pav = p - a = (a + b - c) - a = b - c
- movq mm4, mm2
- punpcklbw mm3, mm0 // Unpack Low bytes of c
- // pbv = p - b = (a + b - c) - b = a - c
- movq mm5, mm1
- psubw mm4, mm3
- pxor mm7, mm7
- // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
- movq mm6, mm4
- psubw mm5, mm3
- // pa = abs(p-a) = abs(pav)
- // pb = abs(p-b) = abs(pbv)
- // pc = abs(p-c) = abs(pcv)
- pcmpgtw mm0, mm4 // Create mask pav bytes < 0
- paddw mm6, mm5
- pand mm0, mm4 // Only pav bytes < 0 in mm7
- pcmpgtw mm7, mm5 // Create mask pbv bytes < 0
- psubw mm4, mm0
- pand mm7, mm5 // Only pbv bytes < 0 in mm0
- psubw mm4, mm0
- psubw mm5, mm7
- pxor mm0, mm0
- pcmpgtw mm0, mm6 // Create mask pcv bytes < 0
- pand mm0, mm6 // Only pav bytes < 0 in mm7
- psubw mm5, mm7
- psubw mm6, mm0
- // test pa <= pb
- movq mm7, mm4
- psubw mm6, mm0
- pcmpgtw mm7, mm5 // pa > pb?
- movq mm0, mm7
- // use mm7 mask to merge pa & pb
- pand mm5, mm7
- // use mm0 mask copy to merge a & b
- pand mm2, mm0
- pandn mm7, mm4
- pandn mm0, mm1
- paddw mm7, mm5
- paddw mm0, mm2
- // test ((pa <= pb)? pa:pb) <= pc
- pcmpgtw mm7, mm6 // pab > pc?
- pxor mm1, mm1
- pand mm3, mm7
- pandn mm7, mm0
- paddw mm7, mm3
- pxor mm0, mm0
- packuswb mm7, mm1
- movq mm3, [esi + ebx - 8] // load c=Prior(x-bpp)
- pand mm7, ActiveMask
- psrlq mm3, ShiftRem
- movq mm2, [esi + ebx] // load b=Prior(x) step 1
- paddb mm7, [edi + ebx] // add Paeth predictor with Raw(x)
- movq mm6, mm2
- movq [edi + ebx], mm7 // write back updated value
- movq mm1, [edi+ebx-8]
- psllq mm6, ShiftBpp
- movq mm5, mm7
- psrlq mm1, ShiftRem
- por mm3, mm6
- psllq mm5, ShiftBpp
- punpckhbw mm3, mm0 // Unpack High bytes of c
- por mm1, mm5
- // Do second set of 4 bytes
- punpckhbw mm2, mm0 // Unpack High bytes of b
- punpckhbw mm1, mm0 // Unpack High bytes of a
- // pav = p - a = (a + b - c) - a = b - c
- movq mm4, mm2
- // pbv = p - b = (a + b - c) - b = a - c
- movq mm5, mm1
- psubw mm4, mm3
- pxor mm7, mm7
- // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
- movq mm6, mm4
- psubw mm5, mm3
- // pa = abs(p-a) = abs(pav)
- // pb = abs(p-b) = abs(pbv)
- // pc = abs(p-c) = abs(pcv)
- pcmpgtw mm0, mm4 // Create mask pav bytes < 0
- paddw mm6, mm5
- pand mm0, mm4 // Only pav bytes < 0 in mm7
- pcmpgtw mm7, mm5 // Create mask pbv bytes < 0
- psubw mm4, mm0
- pand mm7, mm5 // Only pbv bytes < 0 in mm0
- psubw mm4, mm0
- psubw mm5, mm7
- pxor mm0, mm0
- pcmpgtw mm0, mm6 // Create mask pcv bytes < 0
- pand mm0, mm6 // Only pav bytes < 0 in mm7
- psubw mm5, mm7
- psubw mm6, mm0
- // test pa <= pb
- movq mm7, mm4
- psubw mm6, mm0
- pcmpgtw mm7, mm5 // pa > pb?
- movq mm0, mm7
- // use mm7 mask to merge pa & pb
- pand mm5, mm7
- // use mm0 mask copy to merge a & b
- pand mm2, mm0
- pandn mm7, mm4
- pandn mm0, mm1
- paddw mm7, mm5
- paddw mm0, mm2
- // test ((pa <= pb)? pa:pb) <= pc
- pcmpgtw mm7, mm6 // pab > pc?
- pxor mm1, mm1
- pand mm3, mm7
- pandn mm7, mm0
- pxor mm1, mm1
- paddw mm7, mm3
- pxor mm0, mm0
- // Step ex to next set of 8 bytes and repeat loop til done
- add ebx, 8
- packuswb mm1, mm7
- paddb mm1, [edi + ebx - 8] // add Paeth predictor with Raw(x)
- cmp ebx, MMXLength
- movq [edi + ebx - 8], mm1 // write back updated value
- // mm1 will be used as Raw(x-bpp) next loop
- jb dpth6lp
- } // end _asm block
- }
- break;
-
- case 4:
- {
- ActiveMask.use = 0x00000000ffffffff;
- _asm {
- mov ebx, diff
- mov edi, row
- mov esi, prev_row
- pxor mm0, mm0
- // PRIME the pump (load the first Raw(x-bpp) data set
- movq mm1, [edi+ebx-8] // Only time should need to read
- // a=Raw(x-bpp) bytes
-dpth4lp:
- // Do first set of 4 bytes
- movq mm3, [esi+ebx-8] // read c=Prior(x-bpp) bytes
- punpckhbw mm1, mm0 // Unpack Low bytes of a
- movq mm2, [esi + ebx] // load b=Prior(x)
- punpcklbw mm2, mm0 // Unpack High bytes of b
- // pav = p - a = (a + b - c) - a = b - c
- movq mm4, mm2
- punpckhbw mm3, mm0 // Unpack High bytes of c
- // pbv = p - b = (a + b - c) - b = a - c
- movq mm5, mm1
- psubw mm4, mm3
- pxor mm7, mm7
- // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
- movq mm6, mm4
- psubw mm5, mm3
- // pa = abs(p-a) = abs(pav)
- // pb = abs(p-b) = abs(pbv)
- // pc = abs(p-c) = abs(pcv)
- pcmpgtw mm0, mm4 // Create mask pav bytes < 0
- paddw mm6, mm5
- pand mm0, mm4 // Only pav bytes < 0 in mm7
- pcmpgtw mm7, mm5 // Create mask pbv bytes < 0
- psubw mm4, mm0
- pand mm7, mm5 // Only pbv bytes < 0 in mm0
- psubw mm4, mm0
- psubw mm5, mm7
- pxor mm0, mm0
- pcmpgtw mm0, mm6 // Create mask pcv bytes < 0
- pand mm0, mm6 // Only pav bytes < 0 in mm7
- psubw mm5, mm7
- psubw mm6, mm0
- // test pa <= pb
- movq mm7, mm4
- psubw mm6, mm0
- pcmpgtw mm7, mm5 // pa > pb?
- movq mm0, mm7
- // use mm7 mask to merge pa & pb
- pand mm5, mm7
- // use mm0 mask copy to merge a & b
- pand mm2, mm0
- pandn mm7, mm4
- pandn mm0, mm1
- paddw mm7, mm5
- paddw mm0, mm2
- // test ((pa <= pb)? pa:pb) <= pc
- pcmpgtw mm7, mm6 // pab > pc?
- pxor mm1, mm1
- pand mm3, mm7
- pandn mm7, mm0
- paddw mm7, mm3
- pxor mm0, mm0
- packuswb mm7, mm1
- movq mm3, [esi + ebx] // load c=Prior(x-bpp)
- pand mm7, ActiveMask
- movq mm2, mm3 // load b=Prior(x) step 1
- paddb mm7, [edi + ebx] // add Paeth predictor with Raw(x)
- punpcklbw mm3, mm0 // Unpack High bytes of c
- movq [edi + ebx], mm7 // write back updated value
- movq mm1, mm7 // Now mm1 will be used as Raw(x-bpp)
- // Do second set of 4 bytes
- punpckhbw mm2, mm0 // Unpack Low bytes of b
- punpcklbw mm1, mm0 // Unpack Low bytes of a
- // pav = p - a = (a + b - c) - a = b - c
- movq mm4, mm2
- // pbv = p - b = (a + b - c) - b = a - c
- movq mm5, mm1
- psubw mm4, mm3
- pxor mm7, mm7
- // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
- movq mm6, mm4
- psubw mm5, mm3
- // pa = abs(p-a) = abs(pav)
- // pb = abs(p-b) = abs(pbv)
- // pc = abs(p-c) = abs(pcv)
- pcmpgtw mm0, mm4 // Create mask pav bytes < 0
- paddw mm6, mm5
- pand mm0, mm4 // Only pav bytes < 0 in mm7
- pcmpgtw mm7, mm5 // Create mask pbv bytes < 0
- psubw mm4, mm0
- pand mm7, mm5 // Only pbv bytes < 0 in mm0
- psubw mm4, mm0
- psubw mm5, mm7
- pxor mm0, mm0
- pcmpgtw mm0, mm6 // Create mask pcv bytes < 0
- pand mm0, mm6 // Only pav bytes < 0 in mm7
- psubw mm5, mm7
- psubw mm6, mm0
- // test pa <= pb
- movq mm7, mm4
- psubw mm6, mm0
- pcmpgtw mm7, mm5 // pa > pb?
- movq mm0, mm7
- // use mm7 mask to merge pa & pb
- pand mm5, mm7
- // use mm0 mask copy to merge a & b
- pand mm2, mm0
- pandn mm7, mm4
- pandn mm0, mm1
- paddw mm7, mm5
- paddw mm0, mm2
- // test ((pa <= pb)? pa:pb) <= pc
- pcmpgtw mm7, mm6 // pab > pc?
- pxor mm1, mm1
- pand mm3, mm7
- pandn mm7, mm0
- pxor mm1, mm1
- paddw mm7, mm3
- pxor mm0, mm0
- // Step ex to next set of 8 bytes and repeat loop til done
- add ebx, 8
- packuswb mm1, mm7
- paddb mm1, [edi + ebx - 8] // add Paeth predictor with Raw(x)
- cmp ebx, MMXLength
- movq [edi + ebx - 8], mm1 // write back updated value
- // mm1 will be used as Raw(x-bpp) next loop
- jb dpth4lp
- } // end _asm block
- }
- break;
- case 8: // bpp == 8
- {
- ActiveMask.use = 0x00000000ffffffff;
- _asm {
- mov ebx, diff
- mov edi, row
- mov esi, prev_row
- pxor mm0, mm0
- // PRIME the pump (load the first Raw(x-bpp) data set
- movq mm1, [edi+ebx-8] // Only time should need to read
- // a=Raw(x-bpp) bytes
-dpth8lp:
- // Do first set of 4 bytes
- movq mm3, [esi+ebx-8] // read c=Prior(x-bpp) bytes
- punpcklbw mm1, mm0 // Unpack Low bytes of a
- movq mm2, [esi + ebx] // load b=Prior(x)
- punpcklbw mm2, mm0 // Unpack Low bytes of b
- // pav = p - a = (a + b - c) - a = b - c
- movq mm4, mm2
- punpcklbw mm3, mm0 // Unpack Low bytes of c
- // pbv = p - b = (a + b - c) - b = a - c
- movq mm5, mm1
- psubw mm4, mm3
- pxor mm7, mm7
- // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
- movq mm6, mm4
- psubw mm5, mm3
- // pa = abs(p-a) = abs(pav)
- // pb = abs(p-b) = abs(pbv)
- // pc = abs(p-c) = abs(pcv)
- pcmpgtw mm0, mm4 // Create mask pav bytes < 0
- paddw mm6, mm5
- pand mm0, mm4 // Only pav bytes < 0 in mm7
- pcmpgtw mm7, mm5 // Create mask pbv bytes < 0
- psubw mm4, mm0
- pand mm7, mm5 // Only pbv bytes < 0 in mm0
- psubw mm4, mm0
- psubw mm5, mm7
- pxor mm0, mm0
- pcmpgtw mm0, mm6 // Create mask pcv bytes < 0
- pand mm0, mm6 // Only pav bytes < 0 in mm7
- psubw mm5, mm7
- psubw mm6, mm0
- // test pa <= pb
- movq mm7, mm4
- psubw mm6, mm0
- pcmpgtw mm7, mm5 // pa > pb?
- movq mm0, mm7
- // use mm7 mask to merge pa & pb
- pand mm5, mm7
- // use mm0 mask copy to merge a & b
- pand mm2, mm0
- pandn mm7, mm4
- pandn mm0, mm1
- paddw mm7, mm5
- paddw mm0, mm2
- // test ((pa <= pb)? pa:pb) <= pc
- pcmpgtw mm7, mm6 // pab > pc?
- pxor mm1, mm1
- pand mm3, mm7
- pandn mm7, mm0
- paddw mm7, mm3
- pxor mm0, mm0
- packuswb mm7, mm1
- movq mm3, [esi+ebx-8] // read c=Prior(x-bpp) bytes
- pand mm7, ActiveMask
- movq mm2, [esi + ebx] // load b=Prior(x)
- paddb mm7, [edi + ebx] // add Paeth predictor with Raw(x)
- punpckhbw mm3, mm0 // Unpack High bytes of c
- movq [edi + ebx], mm7 // write back updated value
- movq mm1, [edi+ebx-8] // read a=Raw(x-bpp) bytes
-
- // Do second set of 4 bytes
- punpckhbw mm2, mm0 // Unpack High bytes of b
- punpckhbw mm1, mm0 // Unpack High bytes of a
- // pav = p - a = (a + b - c) - a = b - c
- movq mm4, mm2
- // pbv = p - b = (a + b - c) - b = a - c
- movq mm5, mm1
- psubw mm4, mm3
- pxor mm7, mm7
- // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
- movq mm6, mm4
- psubw mm5, mm3
- // pa = abs(p-a) = abs(pav)
- // pb = abs(p-b) = abs(pbv)
- // pc = abs(p-c) = abs(pcv)
- pcmpgtw mm0, mm4 // Create mask pav bytes < 0
- paddw mm6, mm5
- pand mm0, mm4 // Only pav bytes < 0 in mm7
- pcmpgtw mm7, mm5 // Create mask pbv bytes < 0
- psubw mm4, mm0
- pand mm7, mm5 // Only pbv bytes < 0 in mm0
- psubw mm4, mm0
- psubw mm5, mm7
- pxor mm0, mm0
- pcmpgtw mm0, mm6 // Create mask pcv bytes < 0
- pand mm0, mm6 // Only pav bytes < 0 in mm7
- psubw mm5, mm7
- psubw mm6, mm0
- // test pa <= pb
- movq mm7, mm4
- psubw mm6, mm0
- pcmpgtw mm7, mm5 // pa > pb?
- movq mm0, mm7
- // use mm7 mask to merge pa & pb
- pand mm5, mm7
- // use mm0 mask copy to merge a & b
- pand mm2, mm0
- pandn mm7, mm4
- pandn mm0, mm1
- paddw mm7, mm5
- paddw mm0, mm2
- // test ((pa <= pb)? pa:pb) <= pc
- pcmpgtw mm7, mm6 // pab > pc?
- pxor mm1, mm1
- pand mm3, mm7
- pandn mm7, mm0
- pxor mm1, mm1
- paddw mm7, mm3
- pxor mm0, mm0
- // Step ex to next set of 8 bytes and repeat loop til done
- add ebx, 8
- packuswb mm1, mm7
- paddb mm1, [edi + ebx - 8] // add Paeth predictor with Raw(x)
- cmp ebx, MMXLength
- movq [edi + ebx - 8], mm1 // write back updated value
- // mm1 will be used as Raw(x-bpp) next loop
- jb dpth8lp
- } // end _asm block
- }
- break;
-
- case 1: // bpp = 1
- case 2: // bpp = 2
- default: // bpp > 8
- {
- _asm {
- mov ebx, diff
- cmp ebx, FullLength
- jnb dpthdend
- mov edi, row
- mov esi, prev_row
- // Do Paeth decode for remaining bytes
- mov edx, ebx
- xor ecx, ecx // zero ecx before using cl & cx in loop below
- sub edx, bpp // Set edx = ebx - bpp
-dpthdlp:
- xor eax, eax
- // pav = p - a = (a + b - c) - a = b - c
- mov al, [esi + ebx] // load Prior(x) into al
- mov cl, [esi + edx] // load Prior(x-bpp) into cl
- sub eax, ecx // subtract Prior(x-bpp)
- mov patemp, eax // Save pav for later use
- xor eax, eax
- // pbv = p - b = (a + b - c) - b = a - c
- mov al, [edi + edx] // load Raw(x-bpp) into al
- sub eax, ecx // subtract Prior(x-bpp)
- mov ecx, eax
- // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
- add eax, patemp // pcv = pav + pbv
- // pc = abs(pcv)
- test eax, 0x80000000
- jz dpthdpca
- neg eax // reverse sign of neg values
-dpthdpca:
- mov pctemp, eax // save pc for later use
- // pb = abs(pbv)
- test ecx, 0x80000000
- jz dpthdpba
- neg ecx // reverse sign of neg values
-dpthdpba:
- mov pbtemp, ecx // save pb for later use
- // pa = abs(pav)
- mov eax, patemp
- test eax, 0x80000000
- jz dpthdpaa
- neg eax // reverse sign of neg values
-dpthdpaa:
- mov patemp, eax // save pa for later use
- // test if pa <= pb
- cmp eax, ecx
- jna dpthdabb
- // pa > pb; now test if pb <= pc
- cmp ecx, pctemp
- jna dpthdbbc
- // pb > pc; Raw(x) = Paeth(x) + Prior(x-bpp)
- mov cl, [esi + edx] // load Prior(x-bpp) into cl
- jmp dpthdpaeth
-dpthdbbc:
- // pb <= pc; Raw(x) = Paeth(x) + Prior(x)
- mov cl, [esi + ebx] // load Prior(x) into cl
- jmp dpthdpaeth
-dpthdabb:
- // pa <= pb; now test if pa <= pc
- cmp eax, pctemp
- jna dpthdabc
- // pa > pc; Raw(x) = Paeth(x) + Prior(x-bpp)
- mov cl, [esi + edx] // load Prior(x-bpp) into cl
- jmp dpthdpaeth
-dpthdabc:
- // pa <= pc; Raw(x) = Paeth(x) + Raw(x-bpp)
- mov cl, [edi + edx] // load Raw(x-bpp) into cl
-dpthdpaeth:
- inc ebx
- inc edx
- // Raw(x) = (Paeth(x) + Paeth_Predictor( a, b, c )) mod 256
- add [edi + ebx - 1], cl
- cmp ebx, FullLength
- jb dpthdlp
-dpthdend:
- } // end _asm block
- }
- return; // No need to go further with this one
- } // end switch ( bpp )
- _asm
- {
- // MMX acceleration complete now do clean-up
- // Check if any remaining bytes left to decode
- mov ebx, MMXLength
- cmp ebx, FullLength
- jnb dpthend
- mov edi, row
- mov esi, prev_row
- // Do Paeth decode for remaining bytes
- mov edx, ebx
- xor ecx, ecx // zero ecx before using cl & cx in loop below
- sub edx, bpp // Set edx = ebx - bpp
-dpthlp2:
- xor eax, eax
- // pav = p - a = (a + b - c) - a = b - c
- mov al, [esi + ebx] // load Prior(x) into al
- mov cl, [esi + edx] // load Prior(x-bpp) into cl
- sub eax, ecx // subtract Prior(x-bpp)
- mov patemp, eax // Save pav for later use
- xor eax, eax
- // pbv = p - b = (a + b - c) - b = a - c
- mov al, [edi + edx] // load Raw(x-bpp) into al
- sub eax, ecx // subtract Prior(x-bpp)
- mov ecx, eax
- // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
- add eax, patemp // pcv = pav + pbv
- // pc = abs(pcv)
- test eax, 0x80000000
- jz dpthpca2
- neg eax // reverse sign of neg values
-dpthpca2:
- mov pctemp, eax // save pc for later use
- // pb = abs(pbv)
- test ecx, 0x80000000
- jz dpthpba2
- neg ecx // reverse sign of neg values
-dpthpba2:
- mov pbtemp, ecx // save pb for later use
- // pa = abs(pav)
- mov eax, patemp
- test eax, 0x80000000
- jz dpthpaa2
- neg eax // reverse sign of neg values
-dpthpaa2:
- mov patemp, eax // save pa for later use
- // test if pa <= pb
- cmp eax, ecx
- jna dpthabb2
- // pa > pb; now test if pb <= pc
- cmp ecx, pctemp
- jna dpthbbc2
- // pb > pc; Raw(x) = Paeth(x) + Prior(x-bpp)
- mov cl, [esi + edx] // load Prior(x-bpp) into cl
- jmp dpthpaeth2
-dpthbbc2:
- // pb <= pc; Raw(x) = Paeth(x) + Prior(x)
- mov cl, [esi + ebx] // load Prior(x) into cl
- jmp dpthpaeth2
-dpthabb2:
- // pa <= pb; now test if pa <= pc
- cmp eax, pctemp
- jna dpthabc2
- // pa > pc; Raw(x) = Paeth(x) + Prior(x-bpp)
- mov cl, [esi + edx] // load Prior(x-bpp) into cl
- jmp dpthpaeth2
-dpthabc2:
- // pa <= pc; Raw(x) = Paeth(x) + Raw(x-bpp)
- mov cl, [edi + edx] // load Raw(x-bpp) into cl
-dpthpaeth2:
- inc ebx
- inc edx
- // Raw(x) = (Paeth(x) + Paeth_Predictor( a, b, c )) mod 256
- add [edi + ebx - 1], cl
- cmp ebx, FullLength
- jb dpthlp2
-dpthend:
- emms // End MMX instructions; prep for possible FP instrs.
- } // end _asm block
-}
-
-// Optimized code for PNG Sub filter decoder
-void /* PRIVATE */
-png_read_filter_row_mmx_sub(png_row_infop row_info, png_bytep row)
-{
- //int test;
- int bpp;
- png_uint_32 FullLength;
- png_uint_32 MMXLength;
- int diff;
-
- bpp = (row_info->pixel_depth + 7) >> 3; // Get # bytes per pixel
- FullLength = row_info->rowbytes - bpp; // # of bytes to filter
- _asm {
- mov edi, row
- mov esi, edi // lp = row
- add edi, bpp // rp = row + bpp
- xor eax, eax
- // get # of bytes to alignment
- mov diff, edi // take start of row
- add diff, 0xf // add 7 + 8 to incr past
- // alignment boundary
- xor ebx, ebx
- and diff, 0xfffffff8 // mask to alignment boundary
- sub diff, edi // subtract from start ==> value
- // ebx at alignment
- jz dsubgo
- // fix alignment
-dsublp1:
- mov al, [esi+ebx]
- add [edi+ebx], al
- inc ebx
- cmp ebx, diff
- jb dsublp1
-dsubgo:
- mov ecx, FullLength
- mov edx, ecx
- sub edx, ebx // subtract alignment fix
- and edx, 0x00000007 // calc bytes over mult of 8
- sub ecx, edx // drop over bytes from length
- mov MMXLength, ecx
- } // end _asm block
-
- // Now do the math for the rest of the row
- switch ( bpp )
- {
- case 3:
- {
- ActiveMask.use = 0x0000ffffff000000;
- ShiftBpp.use = 24; // == 3 * 8
- ShiftRem.use = 40; // == 64 - 24
- _asm {
- mov edi, row
- movq mm7, ActiveMask // Load ActiveMask for 2nd active byte group
- mov esi, edi // lp = row
- add edi, bpp // rp = row + bpp
- movq mm6, mm7
- mov ebx, diff
- psllq mm6, ShiftBpp // Move mask in mm6 to cover 3rd active
- // byte group
- // PRIME the pump (load the first Raw(x-bpp) data set
- movq mm1, [edi+ebx-8]
-dsub3lp:
- psrlq mm1, ShiftRem // Shift data for adding 1st bpp bytes
- // no need for mask; shift clears inactive bytes
- // Add 1st active group
- movq mm0, [edi+ebx]
- paddb mm0, mm1
- // Add 2nd active group
- movq mm1, mm0 // mov updated Raws to mm1
- psllq mm1, ShiftBpp // shift data to position correctly
- pand mm1, mm7 // mask to use only 2nd active group
- paddb mm0, mm1
- // Add 3rd active group
- movq mm1, mm0 // mov updated Raws to mm1
- psllq mm1, ShiftBpp // shift data to position correctly
- pand mm1, mm6 // mask to use only 3rd active group
- add ebx, 8
- paddb mm0, mm1
- cmp ebx, MMXLength
- movq [edi+ebx-8], mm0 // Write updated Raws back to array
- // Prep for doing 1st add at top of loop
- movq mm1, mm0
- jb dsub3lp
- } // end _asm block
- }
- break;
-
- case 1:
- {
- // Placed here just in case this is a duplicate of the
- // non-MMX code for the SUB filter in png_read_filter_row below
- //
- // png_bytep rp;
- // png_bytep lp;
- // png_uint_32 i;
- // bpp = (row_info->pixel_depth + 7) >> 3;
- // for (i = (png_uint_32)bpp, rp = row + bpp, lp = row;
- // i < row_info->rowbytes; i++, rp++, lp++)
- // {
- // *rp = (png_byte)(((int)(*rp) + (int)(*lp)) & 0xff);
- // }
- _asm {
- mov ebx, diff
- mov edi, row
- cmp ebx, FullLength
- jnb dsub1end
- mov esi, edi // lp = row
- xor eax, eax
- add edi, bpp // rp = row + bpp
-dsub1lp:
- mov al, [esi+ebx]
- add [edi+ebx], al
- inc ebx
- cmp ebx, FullLength
- jb dsub1lp
-dsub1end:
- } // end _asm block
- }
- return;
-
- case 6:
- case 7:
- case 4:
- case 5:
- {
- ShiftBpp.use = bpp << 3;
- ShiftRem.use = 64 - ShiftBpp.use;
- _asm {
- mov edi, row
- mov ebx, diff
- mov esi, edi // lp = row
- add edi, bpp // rp = row + bpp
- // PRIME the pump (load the first Raw(x-bpp) data set
- movq mm1, [edi+ebx-8]
-dsub4lp:
- psrlq mm1, ShiftRem // Shift data for adding 1st bpp bytes
- // no need for mask; shift clears inactive bytes
- movq mm0, [edi+ebx]
- paddb mm0, mm1
- // Add 2nd active group
- movq mm1, mm0 // mov updated Raws to mm1
- psllq mm1, ShiftBpp // shift data to position correctly
- // there is no need for any mask
- // since shift clears inactive bits/bytes
- add ebx, 8
- paddb mm0, mm1
- cmp ebx, MMXLength
- movq [edi+ebx-8], mm0
- movq mm1, mm0 // Prep for doing 1st add at top of loop
- jb dsub4lp
- } // end _asm block
- }
- break;
-
- case 2:
- {
- ActiveMask.use = 0x00000000ffff0000;
- ShiftBpp.use = 16; // == 2 * 8
- ShiftRem.use = 48; // == 64 - 16
- _asm {
- movq mm7, ActiveMask // Load ActiveMask for 2nd active byte group
- mov ebx, diff
- movq mm6, mm7
- mov edi, row
- psllq mm6, ShiftBpp // Move mask in mm6 to cover 3rd active
- // byte group
- mov esi, edi // lp = row
- movq mm5, mm6
- add edi, bpp // rp = row + bpp
- psllq mm5, ShiftBpp // Move mask in mm5 to cover 4th active
- // byte group
- // PRIME the pump (load the first Raw(x-bpp) data set
- movq mm1, [edi+ebx-8]
-dsub2lp:
- // Add 1st active group
- psrlq mm1, ShiftRem // Shift data for adding 1st bpp bytes
- // no need for mask; shift clears inactive
- // bytes
- movq mm0, [edi+ebx]
- paddb mm0, mm1
- // Add 2nd active group
- movq mm1, mm0 // mov updated Raws to mm1
- psllq mm1, ShiftBpp // shift data to position correctly
- pand mm1, mm7 // mask to use only 2nd active group
- paddb mm0, mm1
- // Add 3rd active group
- movq mm1, mm0 // mov updated Raws to mm1
- psllq mm1, ShiftBpp // shift data to position correctly
- pand mm1, mm6 // mask to use only 3rd active group
- paddb mm0, mm1
- // Add 4th active group
- movq mm1, mm0 // mov updated Raws to mm1
- psllq mm1, ShiftBpp // shift data to position correctly
- pand mm1, mm5 // mask to use only 4th active group
- add ebx, 8
- paddb mm0, mm1
- cmp ebx, MMXLength
- movq [edi+ebx-8], mm0 // Write updated Raws back to array
- movq mm1, mm0 // Prep for doing 1st add at top of loop
- jb dsub2lp
- } // end _asm block
- }
- break;
- case 8:
- {
- _asm {
- mov edi, row
- mov ebx, diff
- mov esi, edi // lp = row
- add edi, bpp // rp = row + bpp
- mov ecx, MMXLength
- movq mm7, [edi+ebx-8] // PRIME the pump (load the first
- // Raw(x-bpp) data set
- and ecx, 0x0000003f // calc bytes over mult of 64
-dsub8lp:
- movq mm0, [edi+ebx] // Load Sub(x) for 1st 8 bytes
- paddb mm0, mm7
- movq mm1, [edi+ebx+8] // Load Sub(x) for 2nd 8 bytes
- movq [edi+ebx], mm0 // Write Raw(x) for 1st 8 bytes
- // Now mm0 will be used as Raw(x-bpp) for
- // the 2nd group of 8 bytes. This will be
- // repeated for each group of 8 bytes with
- // the 8th group being used as the Raw(x-bpp)
- // for the 1st group of the next loop.
- paddb mm1, mm0
- movq mm2, [edi+ebx+16] // Load Sub(x) for 3rd 8 bytes
- movq [edi+ebx+8], mm1 // Write Raw(x) for 2nd 8 bytes
- paddb mm2, mm1
- movq mm3, [edi+ebx+24] // Load Sub(x) for 4th 8 bytes
- movq [edi+ebx+16], mm2 // Write Raw(x) for 3rd 8 bytes
- paddb mm3, mm2
- movq mm4, [edi+ebx+32] // Load Sub(x) for 5th 8 bytes
- movq [edi+ebx+24], mm3 // Write Raw(x) for 4th 8 bytes
- paddb mm4, mm3
- movq mm5, [edi+ebx+40] // Load Sub(x) for 6th 8 bytes
- movq [edi+ebx+32], mm4 // Write Raw(x) for 5th 8 bytes
- paddb mm5, mm4
- movq mm6, [edi+ebx+48] // Load Sub(x) for 7th 8 bytes
- movq [edi+ebx+40], mm5 // Write Raw(x) for 6th 8 bytes
- paddb mm6, mm5
- movq mm7, [edi+ebx+56] // Load Sub(x) for 8th 8 bytes
- movq [edi+ebx+48], mm6 // Write Raw(x) for 7th 8 bytes
- add ebx, 64
- paddb mm7, mm6
- cmp ebx, ecx
- movq [edi+ebx-8], mm7 // Write Raw(x) for 8th 8 bytes
- jb dsub8lp
- cmp ebx, MMXLength
- jnb dsub8lt8
-dsub8lpA:
- movq mm0, [edi+ebx]
- add ebx, 8
- paddb mm0, mm7
- cmp ebx, MMXLength
- movq [edi+ebx-8], mm0 // use -8 to offset early add to ebx
- movq mm7, mm0 // Move calculated Raw(x) data to mm1 to
- // be the new Raw(x-bpp) for the next loop
- jb dsub8lpA
-dsub8lt8:
- } // end _asm block
- }
- break;
-
- default: // bpp greater than 8 bytes
- {
- _asm {
- mov ebx, diff
- mov edi, row
- mov esi, edi // lp = row
- add edi, bpp // rp = row + bpp
-dsubAlp:
- movq mm0, [edi+ebx]
- movq mm1, [esi+ebx]
- add ebx, 8
- paddb mm0, mm1
- cmp ebx, MMXLength
- movq [edi+ebx-8], mm0 // mov does not affect flags; -8 to offset
- // add ebx
- jb dsubAlp
- } // end _asm block
- }
- break;
-
- } // end switch ( bpp )
-
- _asm {
- mov ebx, MMXLength
- mov edi, row
- cmp ebx, FullLength
- jnb dsubend
- mov esi, edi // lp = row
- xor eax, eax
- add edi, bpp // rp = row + bpp
-dsublp2:
- mov al, [esi+ebx]
- add [edi+ebx], al
- inc ebx
- cmp ebx, FullLength
- jb dsublp2
-dsubend:
- emms // End MMX instructions; prep for possible FP instrs.
- } // end _asm block
-}
-
-// Optimized code for PNG Up filter decoder
-void /* PRIVATE */
-png_read_filter_row_mmx_up(png_row_infop row_info, png_bytep row,
- png_bytep prev_row)
-{
- png_uint_32 len;
- len = row_info->rowbytes; // # of bytes to filter
- _asm {
- mov edi, row
- // get # of bytes to alignment
- mov ecx, edi
- xor ebx, ebx
- add ecx, 0x7
- xor eax, eax
- and ecx, 0xfffffff8
- mov esi, prev_row
- sub ecx, edi
- jz dupgo
- // fix alignment
-duplp1:
- mov al, [edi+ebx]
- add al, [esi+ebx]
- inc ebx
- cmp ebx, ecx
- mov [edi + ebx-1], al // mov does not affect flags; -1 to offset inc ebx
- jb duplp1
-dupgo:
- mov ecx, len
- mov edx, ecx
- sub edx, ebx // subtract alignment fix
- and edx, 0x0000003f // calc bytes over mult of 64
- sub ecx, edx // drop over bytes from length
- // Unrolled loop - use all MMX registers and interleave to reduce
- // number of branch instructions (loops) and reduce partial stalls
-duploop:
- movq mm1, [esi+ebx]
- movq mm0, [edi+ebx]
- movq mm3, [esi+ebx+8]
- paddb mm0, mm1
- movq mm2, [edi+ebx+8]
- movq [edi+ebx], mm0
- paddb mm2, mm3
- movq mm5, [esi+ebx+16]
- movq [edi+ebx+8], mm2
- movq mm4, [edi+ebx+16]
- movq mm7, [esi+ebx+24]
- paddb mm4, mm5
- movq mm6, [edi+ebx+24]
- movq [edi+ebx+16], mm4
- paddb mm6, mm7
- movq mm1, [esi+ebx+32]
- movq [edi+ebx+24], mm6
- movq mm0, [edi+ebx+32]
- movq mm3, [esi+ebx+40]
- paddb mm0, mm1
- movq mm2, [edi+ebx+40]
- movq [edi+ebx+32], mm0
- paddb mm2, mm3
- movq mm5, [esi+ebx+48]
- movq [edi+ebx+40], mm2
- movq mm4, [edi+ebx+48]
- movq mm7, [esi+ebx+56]
- paddb mm4, mm5
- movq mm6, [edi+ebx+56]
- movq [edi+ebx+48], mm4
- add ebx, 64
- paddb mm6, mm7
- cmp ebx, ecx
- movq [edi+ebx-8], mm6 // (+56)movq does not affect flags;
- // -8 to offset add ebx
- jb duploop
-
- cmp edx, 0 // Test for bytes over mult of 64
- jz dupend
-
-
- // 2 lines added by lcreeve at netins.net
- // (mail 11 Jul 98 in png-implement list)
- cmp edx, 8 //test for less than 8 bytes
- jb duplt8
-
-
- add ecx, edx
- and edx, 0x00000007 // calc bytes over mult of 8
- sub ecx, edx // drop over bytes from length
- jz duplt8
- // Loop using MMX registers mm0 & mm1 to update 8 bytes simultaneously
-duplpA:
- movq mm1, [esi+ebx]
- movq mm0, [edi+ebx]
- add ebx, 8
- paddb mm0, mm1
- cmp ebx, ecx
- movq [edi+ebx-8], mm0 // movq does not affect flags; -8 to offset add ebx
- jb duplpA
- cmp edx, 0 // Test for bytes over mult of 8
- jz dupend
-duplt8:
- xor eax, eax
- add ecx, edx // move over byte count into counter
- // Loop using x86 registers to update remaining bytes
-duplp2:
- mov al, [edi + ebx]
- add al, [esi + ebx]
- inc ebx
- cmp ebx, ecx
- mov [edi + ebx-1], al // mov does not affect flags; -1 to offset inc ebx
- jb duplp2
-dupend:
- // Conversion of filtered row completed
- emms // End MMX instructions; prep for possible FP instrs.
- } // end _asm block
-}
-
-
-// Optimized png_read_filter_row routines
-void /* PRIVATE */
-png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep
- row, png_bytep prev_row, int filter)
-{
-#ifdef PNG_DEBUG
- char filnm[10];
-#endif
-
- if (mmx_supported == 2) {
- /* this should have happened in png_init_mmx_flags() already */
- png_warning(png_ptr, "asm_flags may not have been initialized");
- png_mmx_support();
- }
-
-#ifdef PNG_DEBUG
- png_debug(1, "in png_read_filter_row\n");
- switch (filter)
- {
- case 0: png_sprintf(filnm, "none");
- break;
- case 1: png_sprintf(filnm, "sub-%s",
- (png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_SUB)? "MMX" : "x86");
- break;
- case 2: png_sprintf(filnm, "up-%s",
- (png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_UP)? "MMX" : "x86");
- break;
- case 3: png_sprintf(filnm, "avg-%s",
- (png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_AVG)? "MMX" : "x86");
- break;
- case 4: png_sprintf(filnm, "Paeth-%s",
- (png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_PAETH)? "MMX":"x86");
- break;
- default: png_sprintf(filnm, "unknw");
- break;
- }
- png_debug2(0,"row=%5d, %s, ", png_ptr->row_number, filnm);
- png_debug2(0, "pd=%2d, b=%d, ", (int)row_info->pixel_depth,
- (int)((row_info->pixel_depth + 7) >> 3));
- png_debug1(0,"len=%8d, ", row_info->rowbytes);
-#endif /* PNG_DEBUG */
-
- switch (filter)
- {
- case PNG_FILTER_VALUE_NONE:
- break;
-
- case PNG_FILTER_VALUE_SUB:
- {
- if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_SUB) &&
- (row_info->pixel_depth >= png_ptr->mmx_bitdepth_threshold) &&
- (row_info->rowbytes >= png_ptr->mmx_rowbytes_threshold))
- {
- png_read_filter_row_mmx_sub(row_info, row);
- }
- else
- {
- png_uint_32 i;
- png_uint_32 istop = row_info->rowbytes;
- png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
- png_bytep rp = row + bpp;
- png_bytep lp = row;
-
- for (i = bpp; i < istop; i++)
- {
- *rp = (png_byte)(((int)(*rp) + (int)(*lp++)) & 0xff);
- rp++;
- }
- }
- break;
- }
-
- case PNG_FILTER_VALUE_UP:
- {
- if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_UP) &&
- (row_info->pixel_depth >= png_ptr->mmx_bitdepth_threshold) &&
- (row_info->rowbytes >= png_ptr->mmx_rowbytes_threshold))
- {
- png_read_filter_row_mmx_up(row_info, row, prev_row);
- }
- else
- {
- png_uint_32 i;
- png_uint_32 istop = row_info->rowbytes;
- png_bytep rp = row;
- png_bytep pp = prev_row;
-
- for (i = 0; i < istop; ++i)
- {
- *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
- rp++;
- }
- }
- break;
- }
-
- case PNG_FILTER_VALUE_AVG:
- {
- if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_AVG) &&
- (row_info->pixel_depth >= png_ptr->mmx_bitdepth_threshold) &&
- (row_info->rowbytes >= png_ptr->mmx_rowbytes_threshold))
- {
- png_read_filter_row_mmx_avg(row_info, row, prev_row);
- }
- else
- {
- png_uint_32 i;
- png_bytep rp = row;
- png_bytep pp = prev_row;
- png_bytep lp = row;
- png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
- png_uint_32 istop = row_info->rowbytes - bpp;
-
- for (i = 0; i < bpp; i++)
- {
- *rp = (png_byte)(((int)(*rp) +
- ((int)(*pp++) >> 1)) & 0xff);
- rp++;
- }
-
- for (i = 0; i < istop; i++)
- {
- *rp = (png_byte)(((int)(*rp) +
- ((int)(*pp++ + *lp++) >> 1)) & 0xff);
- rp++;
- }
- }
- break;
- }
-
- case PNG_FILTER_VALUE_PAETH:
- {
- if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_PAETH) &&
- (row_info->pixel_depth >= png_ptr->mmx_bitdepth_threshold) &&
- (row_info->rowbytes >= png_ptr->mmx_rowbytes_threshold))
- {
- png_read_filter_row_mmx_paeth(row_info, row, prev_row);
- }
- else
- {
- png_uint_32 i;
- 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) >> 3;
- png_uint_32 istop=row_info->rowbytes - bpp;
-
- 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;
-
- 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_warning(png_ptr, "Ignoring bad row filter type");
- *row=0;
- break;
- }
-}
-
-#endif /* PNG_MMX_CODE_SUPPORTED && PNG_USE_PNGVCRD */
diff --git a/pngwio.c b/pngwio.c
index 4d6ddc973..d61dea1c3 100644
--- a/pngwio.c
+++ b/pngwio.c
@@ -1,9 +1,9 @@
/* pngwio.c - functions for data output
*
- * Last changed in libpng 1.4.0 May 15, 2007
+ * Last changed in libpng 1.4.0 [July 10, 2008]
* For conditions of distribution and use, see copyright notice in png.h
- * Copyright (c) 1998-2007 Glenn Randers-Pehrson
+ * Copyright (c) 1998-2008 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*
@@ -45,6 +45,7 @@ png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
{
png_uint_32 check;
+ if (png_ptr == NULL) return;
check = fwrite(data, 1, length, (png_FILE_p)(png_ptr->io_ptr));
if (check != length)
png_error(png_ptr, "Write Error");
@@ -65,7 +66,7 @@ png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
png_byte *near_data; /* Needs to be "png_byte *" instead of "png_bytep" */
png_FILE_p io_ptr;
- if(png_ptr == NULL) return;
+ if (png_ptr == NULL) return;
/* Check if data really is near. If so, use usual code. */
near_data = (png_byte *)CVT_PTR_NOCHECK(data);
io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
@@ -116,6 +117,7 @@ void PNGAPI
png_default_flush(png_structp png_ptr)
{
png_FILE_p io_ptr;
+ if (png_ptr == NULL) return;
io_ptr = (png_FILE_p)CVT_PTR((png_ptr->io_ptr));
if (io_ptr != NULL)
fflush(io_ptr);
@@ -149,7 +151,7 @@ void PNGAPI
png_set_write_fn(png_structp png_ptr, png_voidp io_ptr,
png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn)
{
- if(png_ptr == NULL) return;
+ if (png_ptr == NULL) return;
png_ptr->io_ptr = io_ptr;
#if !defined(PNG_NO_STDIO)
@@ -185,27 +187,27 @@ png_set_write_fn(png_structp png_ptr, png_voidp io_ptr,
#if defined(USE_FAR_KEYWORD)
#if defined(_MSC_VER)
-void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check)
+void *png_far_to_near(png_structp png_ptr, png_voidp ptr, int check)
{
void *near_ptr;
void FAR *far_ptr;
FP_OFF(near_ptr) = FP_OFF(ptr);
far_ptr = (void FAR *)near_ptr;
- if(check != 0)
- if(FP_SEG(ptr) != FP_SEG(far_ptr))
- png_error(png_ptr,"segment lost in conversion");
+ if (check != 0)
+ if (FP_SEG(ptr) != FP_SEG(far_ptr))
+ png_error(png_ptr, "segment lost in conversion");
return(near_ptr);
}
# else
-void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check)
+void *png_far_to_near(png_structp png_ptr, png_voidp ptr, int check)
{
void *near_ptr;
void FAR *far_ptr;
near_ptr = (void FAR *)ptr;
far_ptr = (void FAR *)near_ptr;
- if(check != 0)
- if(far_ptr != ptr)
- png_error(png_ptr,"segment lost in conversion");
+ if (check != 0)
+ if (far_ptr != ptr)
+ png_error(png_ptr, "segment lost in conversion");
return(near_ptr);
}
# endif
diff --git a/pngwrite.c b/pngwrite.c
index fc5eb4064..4bfa06636 100644
--- a/pngwrite.c
+++ b/pngwrite.c
@@ -1,9 +1,9 @@
/* pngwrite.c - general routines to write a PNG file
*
- * Last changed in libpng 1.4.0 May 15, 2007
+ * Last changed in libpng 1.4.0 [July 10, 2008]
* For conditions of distribution and use, see copyright notice in png.h
- * Copyright (c) 1998-2007 Glenn Randers-Pehrson
+ * Copyright (c) 1998-2008 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*/
@@ -32,9 +32,9 @@ png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr)
{
png_write_sig(png_ptr); /* write PNG signature */
#if defined(PNG_MNG_FEATURES_SUPPORTED)
- if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&(png_ptr->mng_features_permitted))
+ if ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&(png_ptr->mng_features_permitted))
{
- png_warning(png_ptr,"MNG features are not allowed in a PNG datastream");
+ png_warning(png_ptr, "MNG features are not allowed in a PNG datastream");
png_ptr->mng_features_permitted=0;
}
#endif
@@ -112,6 +112,8 @@ png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr)
((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
(png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
{
+ if (up->size == 0)
+ png_warning(png_ptr, "Writing zero-length unknown chunk");
png_write_chunk(png_ptr, up->name, up->data, up->size);
}
}
@@ -391,11 +393,13 @@ png_write_end(png_structp png_ptr, png_infop info_ptr)
/* write end of PNG file */
png_write_IEND(png_ptr);
-#if 0
-/* This flush, added in libpng-1.0.8, causes some applications to crash
- because they do not set png_ptr->output_flush_fn */
+ /* This flush, added in libpng-1.0.8, removed from libpng-1.0.9beta03,
+ * and restored again in libpng-1.2.30, may cause some applications that
+ * do not set png_ptr->output_flush_fn to crash. If your application
+ * experiences this problem, please report the event to
+ * png-mng-implement at lists.sf.net .
+ */
png_flush(png_ptr);
-#endif
}
#if defined(PNG_WRITE_tIME_SUPPORTED)
@@ -450,17 +454,13 @@ png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
png_debug(1, "in png_create_write_struct\n");
#ifdef PNG_USER_MEM_SUPPORTED
png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
- malloc_fn, mem_ptr);
+ (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
#else
png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
#endif /* PNG_USER_MEM_SUPPORTED */
if (png_ptr == NULL)
return (NULL);
-#ifdef PNG_MMX_CODE_SUPPORTED
- png_init_mmx_flags(png_ptr); /* 1.2.0 addition */
-#endif
-
/* added at libpng-1.2.6 */
#ifdef PNG_SET_USER_LIMITS_SUPPORTED
png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
@@ -480,7 +480,7 @@ png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
return (NULL);
}
#ifdef USE_FAR_KEYWORD
- png_memcpy(png_ptr->jmpbuf, jmpbuf, sizeof(jmp_buf));
+ png_memcpy(png_ptr->jmpbuf, jmpbuf, png_sizeof(jmp_buf));
#endif
#endif
@@ -489,12 +489,15 @@ png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
#endif /* PNG_USER_MEM_SUPPORTED */
png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
- i=0;
- do
+ if (user_png_ver)
{
- if(user_png_ver[i] != png_libpng_ver[i])
- png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
- } while (png_libpng_ver[i++]);
+ i=0;
+ do
+ {
+ if (user_png_ver[i] != png_libpng_ver[i])
+ png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
+ } while (png_libpng_ver[i++]);
+ }
if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
{
@@ -507,15 +510,17 @@ png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
(user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
(user_png_ver[0] == '0' && user_png_ver[2] < '9'))
{
-#ifndef PNG_NO_STDIO
+#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
char msg[80];
if (user_png_ver)
{
- png_sprintf(msg, "Application was compiled with png.h from libpng-%.20s",
+ png_snprintf(msg, 80,
+ "Application was compiled with png.h from libpng-%.20s",
user_png_ver);
png_warning(png_ptr, msg);
}
- png_sprintf(msg, "Application is running with png.c from libpng-%.20s",
+ png_snprintf(msg, 80,
+ "Application is running with png.c from libpng-%.20s",
png_libpng_ver);
png_warning(png_ptr, msg);
#endif
@@ -529,7 +534,8 @@ png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
/* initialize zbuf - compression buffer */
png_ptr->zbuf_size = PNG_ZBUF_SIZE;
- png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, png_ptr->zbuf_size);
+ png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
+ (png_uint_32)png_ptr->zbuf_size);
png_set_write_fn(png_ptr, NULL, NULL, NULL);
@@ -545,7 +551,7 @@ png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
#ifdef USE_FAR_KEYWORD
if (setjmp(jmpbuf))
PNG_ABORT();
- png_memcpy(png_ptr->jmpbuf, jmpbuf, sizeof(jmp_buf));
+ png_memcpy(png_ptr->jmpbuf, jmpbuf, png_sizeof(jmp_buf));
#else
if (setjmp(png_ptr->jmpbuf))
PNG_ABORT();
@@ -554,6 +560,9 @@ png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
return (png_ptr);
}
+/* Initialize png_ptr structure, and allocate any memory needed */
+
+
void PNGAPI
png_write_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
png_size_t png_struct_size)
@@ -577,7 +586,7 @@ png_write_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
#else
png_ptr->warning_fn=NULL;
png_warning(png_ptr,
- "Application uses deprecated png_write_init() and should be recompiled");
+ "Application uses deprecated png_write_init() and should be recompiled.");
break;
#endif
}
@@ -587,10 +596,10 @@ png_write_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
#ifdef PNG_SETJMP_SUPPORTED
/* save jump buffer and error functions */
- png_memcpy(tmp_jmp, png_ptr->jmpbuf, sizeof(jmp_buf));
+ png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof(jmp_buf));
#endif
- if (sizeof(png_struct) > png_struct_size)
+ if (png_sizeof(png_struct) > png_struct_size)
{
png_destroy_struct(png_ptr);
png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
@@ -598,7 +607,7 @@ png_write_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
}
/* reset all variables to 0 */
- png_memset(png_ptr, 0, sizeof(png_struct));
+ png_memset(png_ptr, 0, png_sizeof(png_struct));
/* added at libpng-1.2.6 */
#ifdef PNG_SET_USER_LIMITS_SUPPORTED
@@ -606,20 +615,17 @@ png_write_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
#endif
-#ifdef PNG_MMX_CODE_SUPPORTED
- png_init_mmx_flags(png_ptr); /* 1.2.0 addition */
-#endif
-
#ifdef PNG_SETJMP_SUPPORTED
/* restore jump buffer */
- png_memcpy(png_ptr->jmpbuf, tmp_jmp, sizeof(jmp_buf));
+ png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof(jmp_buf));
#endif
png_set_write_fn(png_ptr, NULL, NULL, NULL);
/* initialize zbuf - compression buffer */
png_ptr->zbuf_size = PNG_ZBUF_SIZE;
- png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, png_ptr->zbuf_size);
+ png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
+ (png_uint_32)png_ptr->zbuf_size);
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
@@ -804,13 +810,11 @@ png_write_row(png_structp png_ptr, png_bytep row)
png_ptr->row_info.width);
png_debug1(3, "row_info->color_type = %d\n", png_ptr->row_info.color_type);
- png_debug1(3, "row_info->width = %lu\n",
- (unsigned long) png_ptr->row_info.width);
+ png_debug1(3, "row_info->width = %lu\n", png_ptr->row_info.width);
png_debug1(3, "row_info->channels = %d\n", png_ptr->row_info.channels);
png_debug1(3, "row_info->bit_depth = %d\n", png_ptr->row_info.bit_depth);
png_debug1(3, "row_info->pixel_depth = %d\n", png_ptr->row_info.pixel_depth);
- png_debug1(3, "row_info->rowbytes = %lu\n",
- (unsigned long) png_ptr->row_info.rowbytes);
+ png_debug1(3, "row_info->rowbytes = %lu\n", png_ptr->row_info.rowbytes);
/* Copy user's row into buffer, leaving room for filter byte. */
png_memcpy(png_ptr->row_buf + 1, row, png_ptr->row_info.rowbytes);
@@ -845,7 +849,7 @@ png_write_row(png_structp png_ptr, png_bytep row)
* 4. The filter_method is 64 and
* 5. The color_type is RGB or RGBA
*/
- if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
+ if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
(png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
{
/* Intrapixel differencing */
@@ -947,21 +951,32 @@ png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)
#endif
}
+#ifdef PNG_USER_MEM_SUPPORTED
+ if (png_ptr != NULL)
+ {
+ free_fn = png_ptr->free_fn;
+ mem_ptr = png_ptr->mem_ptr;
+ }
+#endif
+
if (info_ptr_ptr != NULL)
info_ptr = *info_ptr_ptr;
if (info_ptr != NULL)
{
- png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
+ if (png_ptr != NULL)
+ {
+ png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
- if (png_ptr->num_chunk_list)
- {
- png_free(png_ptr, png_ptr->chunk_list);
- png_ptr->chunk_list=NULL;
- png_ptr->num_chunk_list=0;
- }
+ if (png_ptr->num_chunk_list)
+ {
+ png_free(png_ptr, png_ptr->chunk_list);
+ png_ptr->chunk_list=NULL;
+ png_ptr->num_chunk_list=0;
+ }
#endif
+ }
#ifdef PNG_USER_MEM_SUPPORTED
png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn,
@@ -1007,11 +1022,13 @@ png_write_destroy(png_structp png_ptr)
/* free our memory. png_free checks NULL for us. */
png_free(png_ptr, png_ptr->zbuf);
png_free(png_ptr, png_ptr->row_buf);
+#ifndef PNG_NO_WRITE_FILTER
png_free(png_ptr, png_ptr->prev_row);
png_free(png_ptr, png_ptr->sub_row);
png_free(png_ptr, png_ptr->up_row);
png_free(png_ptr, png_ptr->avg_row);
png_free(png_ptr, png_ptr->paeth_row);
+#endif
#if defined(PNG_TIME_RFC1123_SUPPORTED)
png_free(png_ptr, png_ptr->time_buffer);
@@ -1027,7 +1044,7 @@ png_write_destroy(png_structp png_ptr)
#ifdef PNG_SETJMP_SUPPORTED
/* reset structure */
- png_memcpy(tmp_jmp, png_ptr->jmpbuf, sizeof(jmp_buf));
+ png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof(jmp_buf));
#endif
error_fn = png_ptr->error_fn;
@@ -1037,7 +1054,7 @@ png_write_destroy(png_structp png_ptr)
free_fn = png_ptr->free_fn;
#endif
- png_memset(png_ptr, 0, sizeof(png_struct));
+ png_memset(png_ptr, 0, png_sizeof(png_struct));
png_ptr->error_fn = error_fn;
png_ptr->warning_fn = warning_fn;
@@ -1047,7 +1064,7 @@ png_write_destroy(png_structp png_ptr)
#endif
#ifdef PNG_SETJMP_SUPPORTED
- png_memcpy(png_ptr->jmpbuf, tmp_jmp, sizeof(jmp_buf));
+ png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof(jmp_buf));
#endif
}
@@ -1059,7 +1076,7 @@ png_set_filter(png_structp png_ptr, int method, int filters)
if (png_ptr == NULL)
return;
#if defined(PNG_MNG_FEATURES_SUPPORTED)
- if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
+ if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
(method == PNG_INTRAPIXEL_DIFFERENCING))
method = PNG_FILTER_TYPE_BASE;
#endif
@@ -1067,15 +1084,26 @@ png_set_filter(png_structp png_ptr, int method, int filters)
{
switch (filters & (PNG_ALL_FILTERS | 0x07))
{
+#ifndef PNG_NO_WRITE_FILTER
case 5:
case 6:
case 7: png_warning(png_ptr, "Unknown row filter for method 0");
- case PNG_FILTER_VALUE_NONE: png_ptr->do_filter=PNG_FILTER_NONE; break;
- case PNG_FILTER_VALUE_SUB: png_ptr->do_filter=PNG_FILTER_SUB; break;
- case PNG_FILTER_VALUE_UP: png_ptr->do_filter=PNG_FILTER_UP; break;
- case PNG_FILTER_VALUE_AVG: png_ptr->do_filter=PNG_FILTER_AVG; break;
- case PNG_FILTER_VALUE_PAETH: png_ptr->do_filter=PNG_FILTER_PAETH;break;
+#endif /* PNG_NO_WRITE_FILTER */
+ case PNG_FILTER_VALUE_NONE:
+ png_ptr->do_filter=PNG_FILTER_NONE; break;
+#ifndef PNG_NO_WRITE_FILTER
+ case PNG_FILTER_VALUE_SUB:
+ png_ptr->do_filter=PNG_FILTER_SUB; break;
+ case PNG_FILTER_VALUE_UP:
+ png_ptr->do_filter=PNG_FILTER_UP; break;
+ case PNG_FILTER_VALUE_AVG:
+ png_ptr->do_filter=PNG_FILTER_AVG; break;
+ case PNG_FILTER_VALUE_PAETH:
+ png_ptr->do_filter=PNG_FILTER_PAETH; break;
default: png_ptr->do_filter = (png_byte)filters; break;
+#else
+ default: png_warning(png_ptr, "Unknown row filter for method 0");
+#endif /* PNG_NO_WRITE_FILTER */
}
/* If we have allocated the row_buf, this means we have already started
@@ -1089,6 +1117,7 @@ png_set_filter(png_structp png_ptr, int method, int filters)
*/
if (png_ptr->row_buf != NULL)
{
+#ifndef PNG_NO_WRITE_FILTER
if ((png_ptr->do_filter & PNG_FILTER_SUB) && png_ptr->sub_row == NULL)
{
png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
@@ -1143,6 +1172,7 @@ png_set_filter(png_structp png_ptr, int method, int filters)
}
if (png_ptr->do_filter == PNG_NO_FILTERS)
+#endif /* PNG_NO_WRITE_FILTER */
png_ptr->do_filter = PNG_FILTER_NONE;
}
}
@@ -1193,7 +1223,7 @@ png_set_filter_heuristics(png_structp png_ptr, int heuristic_method,
if (png_ptr->prev_filters == NULL)
{
png_ptr->prev_filters = (png_bytep)png_malloc(png_ptr,
- (png_size_t)(sizeof(png_byte) * num_weights));
+ (png_uint_32)(png_sizeof(png_byte) * num_weights));
/* To make sure that the weighting starts out fairly */
for (i = 0; i < num_weights; i++)
@@ -1205,10 +1235,10 @@ png_set_filter_heuristics(png_structp png_ptr, int heuristic_method,
if (png_ptr->filter_weights == NULL)
{
png_ptr->filter_weights = (png_uint_16p)png_malloc(png_ptr,
- (png_size_t)(sizeof(png_uint_16) * num_weights));
+ (png_uint_32)(png_sizeof(png_uint_16) * num_weights));
png_ptr->inv_filter_weights = (png_uint_16p)png_malloc(png_ptr,
- (png_size_t)(sizeof(png_uint_16) * num_weights));
+ (png_uint_32)(png_sizeof(png_uint_16) * num_weights));
for (i = 0; i < num_weights; i++)
{
png_ptr->inv_filter_weights[i] =
@@ -1239,10 +1269,10 @@ png_set_filter_heuristics(png_structp png_ptr, int heuristic_method,
if (png_ptr->filter_costs == NULL)
{
png_ptr->filter_costs = (png_uint_16p)png_malloc(png_ptr,
- (sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
+ (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
png_ptr->inv_filter_costs = (png_uint_16p)png_malloc(png_ptr,
- (sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
+ (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
{
@@ -1441,8 +1471,8 @@ png_write_png(png_structp png_ptr, png_infop info_ptr,
/* It is REQUIRED to call this to finish writing the rest of the file */
png_write_end(png_ptr, info_ptr);
- if(transforms == 0 || params == NULL)
- /* quiet compiler warnings */ return;
+ transforms = transforms; /* quiet compiler warnings */
+ params = params;
}
#endif
#endif /* PNG_WRITE_SUPPORTED */
diff --git a/pngwtran.c b/pngwtran.c
index 3f5f67544..27f54695c 100644
--- a/pngwtran.c
+++ b/pngwtran.c
@@ -1,9 +1,9 @@
/* pngwtran.c - transforms the data in a row for PNG writers
*
- * Last changed in libpng 1.2.9 April 14, 2006
+ * Last changed in libpng 1.4.0 [July 10, 2008]
* For conditions of distribution and use, see copyright notice in png.h
- * Copyright (c) 1998-2006 Glenn Randers-Pehrson
+ * Copyright (c) 1998-2008 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*/
@@ -25,7 +25,7 @@ png_do_write_transformations(png_structp png_ptr)
#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
if (png_ptr->transformations & PNG_USER_TRANSFORM)
- if(png_ptr->write_user_transform_fn != NULL)
+ if (png_ptr->write_user_transform_fn != NULL)
(*(png_ptr->write_user_transform_fn)) /* user write transform function */
(png_ptr, /* png_ptr */
&(png_ptr->row_info), /* row_info: */
@@ -558,8 +558,8 @@ png_do_write_intrapixel(png_row_infop row_info, png_bytep row)
png_uint_32 s0 = (*(rp ) << 8) | *(rp+1);
png_uint_32 s1 = (*(rp+2) << 8) | *(rp+3);
png_uint_32 s2 = (*(rp+4) << 8) | *(rp+5);
- png_uint_32 red = (png_uint_32)((s0-s1) & 0xffffL);
- png_uint_32 blue = (png_uint_32)((s2-s1) & 0xffffL);
+ png_uint_32 red = (png_uint_32)((s0 - s1) & 0xffffL);
+ png_uint_32 blue = (png_uint_32)((s2 - s1) & 0xffffL);
*(rp ) = (png_byte)((red >> 8) & 0xff);
*(rp+1) = (png_byte)(red & 0xff);
*(rp+4) = (png_byte)((blue >> 8) & 0xff);
diff --git a/pngwutil.c b/pngwutil.c
index 507cf41a4..7bb2590c3 100644
--- a/pngwutil.c
+++ b/pngwutil.c
@@ -1,9 +1,9 @@
/* pngwutil.c - utilities to write a PNG file
*
- * Last changed in libpng 1.4.0 May 15, 2007
+ * Last changed in libpng 1.4.0 [July 10, 2008]
* For conditions of distribution and use, see copyright notice in png.h
- * Copyright (c) 1998-2007 Glenn Randers-Pehrson
+ * Copyright (c) 1998-2008 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*/
@@ -70,7 +70,7 @@ png_write_sig(png_structp png_ptr)
/* write the rest of the 8 byte signature */
png_write_data(png_ptr, &png_signature[png_ptr->sig_bytes],
(png_size_t)(8 - png_ptr->sig_bytes));
- if(png_ptr->sig_bytes < 3)
+ if (png_ptr->sig_bytes < 3)
png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
}
@@ -87,9 +87,9 @@ void PNGAPI
png_write_chunk(png_structp png_ptr, png_bytep chunk_name,
png_bytep data, png_size_t length)
{
- if(png_ptr == NULL) return;
+ if (png_ptr == NULL) return;
png_write_chunk_start(png_ptr, chunk_name, (png_uint_32)length);
- png_write_chunk_data(png_ptr, data, length);
+ png_write_chunk_data(png_ptr, data, (png_size_t)length);
png_write_chunk_end(png_ptr);
}
@@ -102,8 +102,6 @@ png_write_chunk_start(png_structp png_ptr, png_bytep chunk_name,
png_uint_32 length)
{
png_byte buf[8];
- png_debug2(0, "Writing %s chunk, length = %lu\n", chunk_name,
- (unsigned long)length);
#ifdef PNG_IO_STATE_SUPPORTED
/* Inform the I/O callback that the chunk header is being written.
@@ -112,14 +110,16 @@ png_write_chunk_start(png_structp png_ptr, png_bytep chunk_name,
png_ptr->io_state = PNG_IO_WRITING | PNG_IO_CHUNK_HDR;
#endif
+ png_debug2(0, "Writing %s chunk, length = %lu\n", chunk_name,
+ (unsigned long)length);
+ if (png_ptr == NULL) return;
+
/* write the length and the chunk name */
png_save_uint_32(buf, length);
png_memcpy(buf + 4, chunk_name, 4);
- png_write_data(png_ptr, buf, 8);
-
+ png_write_data(png_ptr, buf, (png_size_t)8);
/* put the chunk name into png_ptr->chunk_name */
png_memcpy(png_ptr->chunk_name, chunk_name, 4);
-
/* reset the crc and run it over the chunk name */
png_reset_crc(png_ptr);
png_calculate_crc(png_ptr, chunk_name, 4);
@@ -141,7 +141,7 @@ void PNGAPI
png_write_chunk_data(png_structp png_ptr, png_bytep data, png_size_t length)
{
/* write the data, and run the CRC over it */
- if(png_ptr == NULL) return;
+ if (png_ptr == NULL) return;
if (data != NULL && length > 0)
{
png_write_data(png_ptr, data, length);
@@ -158,6 +158,8 @@ png_write_chunk_end(png_structp png_ptr)
{
png_byte buf[4];
+ if (png_ptr == NULL) return;
+
#ifdef PNG_IO_STATE_SUPPORTED
/* Inform the I/O callback that the chunk CRC is being written.
* PNG_IO_CHUNK_CRC requires a single I/O function call.
@@ -168,7 +170,7 @@ png_write_chunk_end(png_structp png_ptr)
/* write the crc in a single operation */
png_save_uint_32(buf, png_ptr->crc);
- png_write_data(png_ptr, buf, 4);
+ png_write_data(png_ptr, buf, (png_size_t)4);
}
#if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_iCCP_SUPPORTED)
@@ -212,9 +214,9 @@ png_text_compress(png_structp png_ptr,
if (compression >= PNG_TEXT_COMPRESSION_LAST)
{
-#ifndef PNG_NO_STDIO
+#if !defined(PNG_NO_STDIO)
char msg[50];
- png_sprintf(msg, "Unknown compression type %d", compression);
+ png_snprintf(msg, 50, "Unknown compression type %d", compression);
png_warning(png_ptr, msg);
#else
png_warning(png_ptr, "Unknown compression type");
@@ -271,19 +273,22 @@ png_text_compress(png_structp png_ptr,
old_ptr = comp->output_ptr;
comp->output_ptr = (png_charpp)png_malloc(png_ptr,
- (png_size_t)(comp->max_output_ptr * sizeof(png_charpp)));
+ (png_size_t)
+ (comp->max_output_ptr * png_sizeof(png_charpp)));
png_memcpy(comp->output_ptr, old_ptr, old_max
- * sizeof(png_charp));
+ * png_sizeof(png_charp));
png_free(png_ptr, old_ptr);
}
else
comp->output_ptr = (png_charpp)png_malloc(png_ptr,
- (png_size_t)(comp->max_output_ptr * sizeof(png_charp)));
+ (png_size_t)
+ (comp->max_output_ptr * png_sizeof(png_charp)));
}
/* save the data */
comp->output_ptr[comp->num_output_ptr] =
- (png_charp)png_malloc(png_ptr, png_ptr->zbuf_size);
+ (png_charp)png_malloc(png_ptr,
+ png_ptr->zbuf_size);
png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
png_ptr->zbuf_size);
comp->num_output_ptr++;
@@ -320,19 +325,22 @@ png_text_compress(png_structp png_ptr,
old_ptr = comp->output_ptr;
/* This could be optimized to realloc() */
comp->output_ptr = (png_charpp)png_malloc(png_ptr,
- (png_size_t)(comp->max_output_ptr * sizeof(png_charpp)));
+ (png_size_t)(comp->max_output_ptr *
+ png_sizeof(png_charp)));
png_memcpy(comp->output_ptr, old_ptr,
- old_max * sizeof(png_charp));
+ old_max * png_sizeof(png_charp));
png_free(png_ptr, old_ptr);
}
else
comp->output_ptr = (png_charpp)png_malloc(png_ptr,
- (png_size_t)(comp->max_output_ptr * sizeof(png_charp)));
+ (png_size_t)(comp->max_output_ptr *
+ png_sizeof(png_charp)));
}
/* save off the data */
comp->output_ptr[comp->num_output_ptr] =
- (png_charp)png_malloc(png_ptr, png_ptr->zbuf_size);
+ (png_charp)png_malloc(png_ptr,
+ (png_size_t)png_ptr->zbuf_size);
png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
png_ptr->zbuf_size);
comp->num_output_ptr++;
@@ -377,8 +385,8 @@ png_write_compressed_data_out(png_structp png_ptr, compression_state *comp)
/* write saved output buffers, if any */
for (i = 0; i < comp->num_output_ptr; i++)
{
- png_write_chunk_data(png_ptr,(png_bytep)comp->output_ptr[i],
- png_ptr->zbuf_size);
+ png_write_chunk_data(png_ptr, (png_bytep)comp->output_ptr[i],
+ (png_size_t)png_ptr->zbuf_size);
png_free(png_ptr, comp->output_ptr[i]);
comp->output_ptr[i]=NULL;
}
@@ -388,7 +396,7 @@ png_write_compressed_data_out(png_structp png_ptr, compression_state *comp)
/* write anything left in zbuf */
if (png_ptr->zstream.avail_out < (png_uint_32)png_ptr->zbuf_size)
png_write_chunk_data(png_ptr, png_ptr->zbuf,
- png_ptr->zbuf_size - png_ptr->zstream.avail_out);
+ (png_size_t)(png_ptr->zbuf_size - png_ptr->zstream.avail_out));
/* reset zlib for another zTXt/iTXt or image data */
deflateReset(&png_ptr->zstream);
@@ -408,6 +416,8 @@ png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height,
#ifdef PNG_USE_LOCAL_ARRAYS
PNG_IHDR;
#endif
+ int ret;
+
png_byte buf[13]; /* buffer to store the IHDR info */
png_debug(1, "in png_write_IHDR\n");
@@ -422,7 +432,7 @@ png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height,
case 4:
case 8:
case 16: png_ptr->channels = 1; break;
- default: png_error(png_ptr,"Invalid bit depth for grayscale image");
+ default: png_error(png_ptr, "Invalid bit depth for grayscale image");
}
break;
case PNG_COLOR_TYPE_RGB:
@@ -522,7 +532,7 @@ png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height,
buf[12] = (png_byte)interlace_type;
/* write the chunk */
- png_write_chunk(png_ptr, (png_bytep)png_IHDR, buf, 13);
+ png_write_chunk(png_ptr, (png_bytep)png_IHDR, buf, (png_size_t)13);
/* initialize zlib with PNG info */
png_ptr->zstream.zalloc = png_zalloc;
@@ -551,9 +561,19 @@ png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height,
png_ptr->zlib_window_bits = 15;
if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_METHOD))
png_ptr->zlib_method = 8;
- deflateInit2(&png_ptr->zstream, png_ptr->zlib_level,
- png_ptr->zlib_method, png_ptr->zlib_window_bits,
- png_ptr->zlib_mem_level, png_ptr->zlib_strategy);
+ ret = deflateInit2(&png_ptr->zstream, png_ptr->zlib_level,
+ png_ptr->zlib_method, png_ptr->zlib_window_bits,
+ png_ptr->zlib_mem_level, png_ptr->zlib_strategy);
+ if (ret != Z_OK)
+ {
+ if (ret == Z_VERSION_ERROR) png_error(png_ptr,
+ "zlib failed to initialize compressor -- version error");
+ if (ret == Z_STREAM_ERROR) png_error(png_ptr,
+ "zlib failed to initialize compressor -- stream error");
+ if (ret == Z_MEM_ERROR) png_error(png_ptr,
+ "zlib failed to initialize compressor -- mem error");
+ png_error(png_ptr, "zlib failed to initialize compressor");
+ }
png_ptr->zstream.next_out = png_ptr->zbuf;
png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
/* libpng is not interested in zstream.data_type */
@@ -605,14 +625,15 @@ png_write_PLTE(png_structp png_ptr, png_colorp palette, png_uint_32 num_pal)
png_ptr->num_palette = (png_uint_16)num_pal;
png_debug1(3, "num_palette = %d\n", png_ptr->num_palette);
- png_write_chunk_start(png_ptr, (png_bytep)png_PLTE, num_pal * 3);
+ png_write_chunk_start(png_ptr, (png_bytep)png_PLTE,
+ (png_uint_32)(num_pal * 3));
#ifndef PNG_NO_POINTER_INDEXING
for (i = 0, pal_ptr = palette; i < num_pal; i++, pal_ptr++)
{
buf[0] = pal_ptr->red;
buf[1] = pal_ptr->green;
buf[2] = pal_ptr->blue;
- png_write_chunk_data(png_ptr, buf, 3);
+ png_write_chunk_data(png_ptr, buf, (png_size_t)3);
}
#else
/* This is a little slower but some buggy compilers need to do this instead */
@@ -622,7 +643,7 @@ png_write_PLTE(png_structp png_ptr, png_colorp palette, png_uint_32 num_pal)
buf[0] = pal_ptr[i].red;
buf[1] = pal_ptr[i].green;
buf[2] = pal_ptr[i].blue;
- png_write_chunk_data(png_ptr, buf, 3);
+ png_write_chunk_data(png_ptr, buf, (png_size_t)3);
}
#endif
png_write_chunk_end(png_ptr);
@@ -689,7 +710,8 @@ png_write_IEND(png_structp png_ptr)
PNG_IEND;
#endif
png_debug(1, "in png_write_IEND\n");
- png_write_chunk(png_ptr, (png_bytep)png_IEND, NULL, 0);
+ png_write_chunk(png_ptr, (png_bytep)png_IEND, NULL,
+ (png_size_t)0);
png_ptr->mode |= PNG_HAVE_IEND;
}
@@ -709,7 +731,7 @@ png_write_gAMA(png_structp png_ptr, double file_gamma)
/* file_gamma is saved in 1/100,000ths */
igamma = (png_uint_32)(file_gamma * 100000.0 + 0.5);
png_save_uint_32(buf, igamma);
- png_write_chunk(png_ptr, (png_bytep)png_gAMA, buf, 4);
+ png_write_chunk(png_ptr, (png_bytep)png_gAMA, buf, (png_size_t)4);
}
#endif
#ifdef PNG_FIXED_POINT_SUPPORTED
@@ -724,7 +746,7 @@ png_write_gAMA_fixed(png_structp png_ptr, png_fixed_point file_gamma)
png_debug(1, "in png_write_gAMA\n");
/* file_gamma is saved in 1/100,000ths */
png_save_uint_32(buf, (png_uint_32)file_gamma);
- png_write_chunk(png_ptr, (png_bytep)png_gAMA, buf, 4);
+ png_write_chunk(png_ptr, (png_bytep)png_gAMA, buf, (png_size_t)4);
}
#endif
#endif
@@ -740,11 +762,11 @@ png_write_sRGB(png_structp png_ptr, int srgb_intent)
png_byte buf[1];
png_debug(1, "in png_write_sRGB\n");
- if(srgb_intent >= PNG_sRGB_INTENT_LAST)
+ if (srgb_intent >= PNG_sRGB_INTENT_LAST)
png_warning(png_ptr,
"Invalid sRGB rendering intent specified");
buf[0]=(png_byte)srgb_intent;
- png_write_chunk(png_ptr, (png_bytep)png_sRGB, buf, 1);
+ png_write_chunk(png_ptr, (png_bytep)png_sRGB, buf, (png_size_t)1);
}
#endif
@@ -785,34 +807,35 @@ png_write_iCCP(png_structp png_ptr, png_charp name, int compression_type,
if (profile_len > 3)
embedded_profile_len =
- ((*( (png_bytep)profile ))<<24) |
- ((*( (png_bytep)profile+1))<<16) |
- ((*( (png_bytep)profile+2))<< 8) |
- ((*( (png_bytep)profile+3)) );
+ ((*( (png_bytep)profile ))<<24) |
+ ((*( (png_bytep)profile + 1))<<16) |
+ ((*( (png_bytep)profile + 2))<< 8) |
+ ((*( (png_bytep)profile + 3)) );
if (profile_len < embedded_profile_len)
- {
- png_warning(png_ptr,
- "Embedded profile length too large in iCCP chunk");
- return;
- }
+ {
+ png_warning(png_ptr,
+ "Embedded profile length too large in iCCP chunk");
+ return;
+ }
if (profile_len > embedded_profile_len)
- {
- png_warning(png_ptr,
- "Truncating profile to actual length in iCCP chunk");
- profile_len = embedded_profile_len;
- }
+ {
+ png_warning(png_ptr,
+ "Truncating profile to actual length in iCCP chunk");
+ profile_len = embedded_profile_len;
+ }
if (profile_len)
- profile_len = png_text_compress(png_ptr, profile,
- (png_size_t)profile_len, PNG_COMPRESSION_TYPE_BASE, &comp);
+ profile_len = png_text_compress(png_ptr, profile,
+ (png_size_t)profile_len, PNG_COMPRESSION_TYPE_BASE, &comp);
/* make sure we include the NULL after the name and the compression type */
png_write_chunk_start(png_ptr, (png_bytep)png_iCCP,
- (png_uint_32)name_len+profile_len+2);
- new_name[name_len+1]=0x00;
- png_write_chunk_data(png_ptr, (png_bytep)new_name, name_len + 2);
+ (png_uint_32)(name_len + profile_len + 2));
+ new_name[name_len + 1] = 0x00;
+ png_write_chunk_data(png_ptr, (png_bytep)new_name,
+ (png_size_t)(name_len + 2));
if (profile_len)
png_write_compressed_data_out(png_ptr, &comp);
@@ -850,13 +873,14 @@ png_write_sPLT(png_structp png_ptr, png_sPLT_tp spalette)
/* make sure we include the NULL after the name */
png_write_chunk_start(png_ptr, (png_bytep)png_sPLT,
- (png_uint_32)(name_len + 2 + palette_size));
- png_write_chunk_data(png_ptr, (png_bytep)new_name, name_len + 1);
- png_write_chunk_data(png_ptr, (png_bytep)&spalette->depth, 1);
+ (png_uint_32)(name_len + 2 + palette_size));
+ png_write_chunk_data(png_ptr, (png_bytep)new_name,
+ (png_size_t)(name_len + 1));
+ png_write_chunk_data(png_ptr, (png_bytep)&spalette->depth, (png_size_t)1);
/* loop through each palette entry, writing appropriately */
#ifndef PNG_NO_POINTER_INDEXING
- for (ep = spalette->entries; ep<spalette->entries+spalette->nentries; ep++)
+ for (ep = spalette->entries; ep<spalette->entries + spalette->nentries; ep++)
{
if (spalette->depth == 8)
{
@@ -874,7 +898,7 @@ png_write_sPLT(png_structp png_ptr, png_sPLT_tp spalette)
png_save_uint_16(entrybuf + 6, ep->alpha);
png_save_uint_16(entrybuf + 8, ep->frequency);
}
- png_write_chunk_data(png_ptr, entrybuf, entry_size);
+ png_write_chunk_data(png_ptr, entrybuf, (png_size_t)entry_size);
}
#else
ep=spalette->entries;
@@ -896,7 +920,7 @@ png_write_sPLT(png_structp png_ptr, png_sPLT_tp spalette)
png_save_uint_16(entrybuf + 6, ep[i].alpha);
png_save_uint_16(entrybuf + 8, ep[i].frequency);
}
- png_write_chunk_data(png_ptr, entrybuf, entry_size);
+ png_write_chunk_data(png_ptr, entrybuf, (png_size_t)entry_size);
}
#endif
@@ -982,7 +1006,7 @@ png_write_cHRM(png_structp png_ptr, double white_x, double white_y,
{
png_warning(png_ptr, "Invalid cHRM white point specified");
#if !defined(PNG_NO_CONSOLE_IO)
- fprintf(stderr,"white_x=%f, white_y=%f\n",white_x, white_y);
+ fprintf(stderr, "white_x=%f, white_y=%f\n", white_x, white_y);
#endif
return;
}
@@ -1021,7 +1045,7 @@ png_write_cHRM(png_structp png_ptr, double white_x, double white_y,
itemp = (png_uint_32)(blue_y * 100000.0 + 0.5);
png_save_uint_32(buf + 28, itemp);
- png_write_chunk(png_ptr, (png_bytep)png_cHRM, buf, 32);
+ png_write_chunk(png_ptr, (png_bytep)png_cHRM, buf, (png_size_t)32);
}
#endif
#ifdef PNG_FIXED_POINT_SUPPORTED
@@ -1042,7 +1066,7 @@ png_write_cHRM_fixed(png_structp png_ptr, png_fixed_point white_x,
{
png_warning(png_ptr, "Invalid fixed cHRM white point specified");
#if !defined(PNG_NO_CONSOLE_IO)
- fprintf(stderr,"white_x=%ld, white_y=%ld\n",(unsigned long)white_x,
+ fprintf(stderr, "white_x=%ld, white_y=%ld\n", (unsigned long)white_x,
(unsigned long)white_y);
#endif
return;
@@ -1074,7 +1098,7 @@ png_write_cHRM_fixed(png_structp png_ptr, png_fixed_point white_x,
png_save_uint_32(buf + 24, (png_uint_32)blue_x);
png_save_uint_32(buf + 28, (png_uint_32)blue_y);
- png_write_chunk(png_ptr, (png_bytep)png_cHRM, buf, 32);
+ png_write_chunk(png_ptr, (png_bytep)png_cHRM, buf, (png_size_t)32);
}
#endif
#endif
@@ -1095,24 +1119,24 @@ png_write_tRNS(png_structp png_ptr, png_bytep trans, png_color_16p tran,
{
if (num_trans <= 0 || num_trans > (int)png_ptr->num_palette)
{
- png_warning(png_ptr,"Invalid number of transparent colors specified");
+ png_warning(png_ptr, "Invalid number of transparent colors specified");
return;
}
/* write the chunk out as it is */
- png_write_chunk(png_ptr, (png_bytep)png_tRNS,
- trans, (png_size_t)num_trans);
+ png_write_chunk(png_ptr, (png_bytep)png_tRNS, trans,
+ (png_size_t)num_trans);
}
else if (color_type == PNG_COLOR_TYPE_GRAY)
{
/* one 16 bit value */
- if(tran->gray >= (1 << png_ptr->bit_depth))
+ if (tran->gray >= (1 << png_ptr->bit_depth))
{
png_warning(png_ptr,
"Ignoring attempt to write tRNS chunk out-of-range for bit_depth");
return;
}
png_save_uint_16(buf, tran->gray);
- png_write_chunk(png_ptr, (png_bytep)png_tRNS, buf, 2);
+ png_write_chunk(png_ptr, (png_bytep)png_tRNS, buf, (png_size_t)2);
}
else if (color_type == PNG_COLOR_TYPE_RGB)
{
@@ -1120,13 +1144,13 @@ png_write_tRNS(png_structp png_ptr, png_bytep trans, png_color_16p tran,
png_save_uint_16(buf, tran->red);
png_save_uint_16(buf + 2, tran->green);
png_save_uint_16(buf + 4, tran->blue);
- if(png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
+ if (png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
{
png_warning(png_ptr,
- "Ignoring attempt to write 16-bit tRNS chunk when bit_depth is 8");
+ "Ignoring attempt to write 16-bit tRNS chunk when bit_depth is 8");
return;
}
- png_write_chunk(png_ptr, (png_bytep)png_tRNS, buf, 6);
+ png_write_chunk(png_ptr, (png_bytep)png_tRNS, buf, (png_size_t)6);
}
else
{
@@ -1159,31 +1183,31 @@ png_write_bKGD(png_structp png_ptr, png_color_16p back, int color_type)
return;
}
buf[0] = back->index;
- png_write_chunk(png_ptr, (png_bytep)png_bKGD, buf, 1);
+ png_write_chunk(png_ptr, (png_bytep)png_bKGD, buf, (png_size_t)1);
}
else if (color_type & PNG_COLOR_MASK_COLOR)
{
png_save_uint_16(buf, back->red);
png_save_uint_16(buf + 2, back->green);
png_save_uint_16(buf + 4, back->blue);
- if(png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
+ if (png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
{
png_warning(png_ptr,
"Ignoring attempt to write 16-bit bKGD chunk when bit_depth is 8");
return;
}
- png_write_chunk(png_ptr, (png_bytep)png_bKGD, buf, 6);
+ png_write_chunk(png_ptr, (png_bytep)png_bKGD, buf, (png_size_t)6);
}
else
{
- if(back->gray >= (1 << png_ptr->bit_depth))
+ if (back->gray >= (1 << png_ptr->bit_depth))
{
png_warning(png_ptr,
"Ignoring attempt to write bKGD chunk out-of-range for bit_depth");
return;
}
png_save_uint_16(buf, back->gray);
- png_write_chunk(png_ptr, (png_bytep)png_bKGD, buf, 2);
+ png_write_chunk(png_ptr, (png_bytep)png_bKGD, buf, (png_size_t)2);
}
}
#endif
@@ -1209,11 +1233,11 @@ png_write_hIST(png_structp png_ptr, png_uint_16p hist, int num_hist)
}
png_write_chunk_start(png_ptr, (png_bytep)png_hIST,
- (png_uint_32)(num_hist * 2));
+ (png_uint_32)(num_hist * 2));
for (i = 0; i < num_hist; i++)
{
png_save_uint_16(buf, hist[i]);
- png_write_chunk_data(png_ptr, buf, 2);
+ png_write_chunk_data(png_ptr, buf, (png_size_t)2);
}
png_write_chunk_end(png_ptr);
}
@@ -1245,27 +1269,29 @@ png_check_keyword(png_structp png_ptr, png_charp key, png_charpp new_key)
if (key == NULL || (key_len = png_strlen(key)) == 0)
{
png_warning(png_ptr, "zero length keyword");
- return 0;
+ return ((png_size_t)0);
}
png_debug1(2, "Keyword to be checked is '%s'\n", key);
- *new_key = (png_charp)png_malloc_warn(png_ptr, key_len + 2);
+ *new_key = (png_charp)png_malloc_warn(png_ptr, (png_uint_32)(key_len + 2));
if (*new_key == NULL)
{
png_warning(png_ptr, "Out of memory while procesing keyword");
- return 0;
+ return ((png_size_t)0);
}
/* Replace non-printing characters with a blank and print a warning */
for (kp = key, dp = *new_key; *kp != '\0'; kp++, dp++)
{
- if (*kp < 0x20 || (*kp > 0x7E && (png_byte)*kp < 0xA1))
+ if ((png_byte)*kp < 0x20 ||
+ ((png_byte)*kp > 0x7E && (png_byte)*kp < 0xA1))
{
-#ifndef PNG_NO_STDIO
+#if !defined(PNG_NO_STDIO)
char msg[40];
- png_sprintf(msg, "invalid keyword character 0x%02X", *kp);
+ png_snprintf(msg, 40,
+ "invalid keyword character 0x%02X", (png_byte)*kp);
png_warning(png_ptr, msg);
#else
png_warning(png_ptr, "invalid character in keyword");
@@ -1327,7 +1353,7 @@ png_check_keyword(png_structp png_ptr, png_charp key, png_charpp new_key)
}
}
*dp = '\0';
- if(kwarn)
+ if (kwarn)
png_warning(png_ptr, "extra interior spaces removed from keyword");
if (key_len == 0)
@@ -1340,7 +1366,7 @@ png_check_keyword(png_structp png_ptr, png_charp key, png_charpp new_key)
if (key_len > 79)
{
png_warning(png_ptr, "keyword length must be 1 - 79 characters");
- (*new_key)[79] = '\0';
+ new_key[79] = '\0';
key_len = 79;
}
@@ -1374,16 +1400,17 @@ png_write_tEXt(png_structp png_ptr, png_charp key, png_charp text,
/* make sure we include the 0 after the key */
png_write_chunk_start(png_ptr, (png_bytep)png_tEXt,
- (png_uint_32)key_len+text_len+1);
+ (png_uint_32)(key_len + text_len + 1));
/*
* We leave it to the application to meet PNG-1.0 requirements on the
* contents of the text. PNG-1.0 through PNG-1.2 discourage the use of
* any non-Latin-1 characters except for NEWLINE. ISO PNG will forbid them.
* The NUL character is forbidden by PNG-1.0 through PNG-1.2 and ISO PNG.
*/
- png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
+ png_write_chunk_data(png_ptr, (png_bytep)new_key,
+ (png_size_t)(key_len + 1));
if (text_len)
- png_write_chunk_data(png_ptr, (png_bytep)text, text_len);
+ png_write_chunk_data(png_ptr, (png_bytep)text, (png_size_t)text_len);
png_write_chunk_end(png_ptr);
png_free(png_ptr, new_key);
@@ -1415,32 +1442,34 @@ png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,
if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
{
png_warning(png_ptr, "Empty keyword in zTXt chunk");
+ png_free(png_ptr, new_key);
return;
}
if (text == NULL || *text == '\0' || compression==PNG_TEXT_COMPRESSION_NONE)
{
- png_write_tEXt(png_ptr, new_key, text, 0);
+ png_write_tEXt(png_ptr, new_key, text, (png_size_t)0);
png_free(png_ptr, new_key);
return;
}
text_len = png_strlen(text);
- png_free(png_ptr, new_key);
-
/* compute the compressed data; do it now for the length */
text_len = png_text_compress(png_ptr, text, text_len, compression,
&comp);
/* write start of chunk */
- png_write_chunk_start(png_ptr, (png_bytep)png_zTXt, (png_uint_32)
- (key_len+text_len+2));
+ png_write_chunk_start(png_ptr, (png_bytep)png_zTXt,
+ (png_uint_32)(key_len+text_len + 2));
/* write key */
- png_write_chunk_data(png_ptr, (png_bytep)key, key_len + 1);
+ png_write_chunk_data(png_ptr, (png_bytep)new_key,
+ (png_size_t)(key_len + 1));
+ png_free(png_ptr, new_key);
+
buf[0] = (png_byte)compression;
/* write compression */
- png_write_chunk_data(png_ptr, (png_bytep)buf, 1);
+ png_write_chunk_data(png_ptr, (png_bytep)buf, (png_size_t)1);
/* write the compressed data */
png_write_compressed_data_out(png_ptr, &comp);
@@ -1514,7 +1543,8 @@ png_write_iTXt(png_structp png_ptr, int compression, png_charp key,
* any non-Latin-1 characters except for NEWLINE. ISO PNG will forbid them.
* The NUL character is forbidden by PNG-1.0 through PNG-1.2 and ISO PNG.
*/
- png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
+ png_write_chunk_data(png_ptr, (png_bytep)new_key,
+ (png_size_t)(key_len + 1));
/* set the compression flag */
if (compression == PNG_ITXT_COMPRESSION_NONE || \
@@ -1524,17 +1554,18 @@ png_write_iTXt(png_structp png_ptr, int compression, png_charp key,
cbuf[0] = 1;
/* set the compression method */
cbuf[1] = 0;
- png_write_chunk_data(png_ptr, cbuf, 2);
+ png_write_chunk_data(png_ptr, cbuf, (png_size_t)2);
cbuf[0] = 0;
- png_write_chunk_data(png_ptr, (new_lang ? (png_bytep)new_lang : cbuf), lang_len + 1);
- png_write_chunk_data(png_ptr, (lang_key ? (png_bytep)lang_key : cbuf), lang_key_len + 1);
+ png_write_chunk_data(png_ptr, (new_lang ? (png_bytep)new_lang : cbuf),
+ (png_size_t)(lang_len + 1));
+ png_write_chunk_data(png_ptr, (lang_key ? (png_bytep)lang_key : cbuf),
+ (png_size_t)(lang_key_len + 1));
png_write_compressed_data_out(png_ptr, &comp);
png_write_chunk_end(png_ptr);
png_free(png_ptr, new_key);
- if (new_lang)
- png_free(png_ptr, new_lang);
+ png_free(png_ptr, new_lang);
}
#endif
@@ -1557,10 +1588,9 @@ png_write_oFFs(png_structp png_ptr, png_int_32 x_offset, png_int_32 y_offset,
png_save_int_32(buf + 4, y_offset);
buf[8] = (png_byte)unit_type;
- png_write_chunk(png_ptr, (png_bytep)png_oFFs, buf, 9);
+ png_write_chunk(png_ptr, (png_bytep)png_oFFs, buf, (png_size_t)9);
}
#endif
-
#if defined(PNG_WRITE_pCAL_SUPPORTED)
/* write the pCAL chunk (described in the PNG extensions document) */
void /* PRIVATE */
@@ -1587,7 +1617,7 @@ png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0,
total_len = purpose_len + units_len + 10;
params_len = (png_uint_32p)png_malloc(png_ptr,
- (png_size_t)(nparams * sizeof(png_uint_32)));
+ (png_size_t)(nparams * png_sizeof(png_uint_32)));
/* Find the length of each parameter, making sure we don't count the
null terminator for the last parameter. */
@@ -1601,13 +1631,14 @@ png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0,
png_debug1(3, "pCAL total length = %d\n", (int)total_len);
png_write_chunk_start(png_ptr, (png_bytep)png_pCAL, (png_uint_32)total_len);
- png_write_chunk_data(png_ptr, (png_bytep)new_purpose, purpose_len);
+ png_write_chunk_data(png_ptr, (png_bytep)new_purpose,
+ (png_size_t)purpose_len);
png_save_int_32(buf, X0);
png_save_int_32(buf + 4, X1);
buf[8] = (png_byte)type;
buf[9] = (png_byte)nparams;
- png_write_chunk_data(png_ptr, buf, 10);
- png_write_chunk_data(png_ptr, (png_bytep)units, units_len);
+ png_write_chunk_data(png_ptr, buf, (png_size_t)10);
+ png_write_chunk_data(png_ptr, (png_bytep)units, (png_size_t)units_len);
png_free(png_ptr, new_purpose);
@@ -1631,17 +1662,17 @@ png_write_sCAL(png_structp png_ptr, int unit, double width, double height)
#ifdef PNG_USE_LOCAL_ARRAYS
PNG_sCAL;
#endif
- png_size_t total_len;
char buf[64];
+ png_size_t total_len;
png_debug(1, "in png_write_sCAL\n");
buf[0] = (char)unit;
-
- png_sprintf(buf + 1, "%12.12e", width);
+ png_snprintf(buf + 1, 63, "%12.12e", width);
total_len = 1 + png_strlen(buf + 1) + 1;
- png_sprintf(buf + total_len, "%12.12e", height);
+ png_snprintf(buf + total_len, 64-total_len, "%12.12e", height);
total_len += png_strlen(buf + total_len);
+
png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len);
png_write_chunk(png_ptr, (png_bytep)png_sCAL, (png_bytep)buf, total_len);
}
@@ -1699,7 +1730,7 @@ png_write_pHYs(png_structp png_ptr, png_uint_32 x_pixels_per_unit,
png_save_uint_32(buf + 4, y_pixels_per_unit);
buf[8] = (png_byte)unit_type;
- png_write_chunk(png_ptr, (png_bytep)png_pHYs, buf, 9);
+ png_write_chunk(png_ptr, (png_bytep)png_pHYs, buf, (png_size_t)9);
}
#endif
@@ -1731,7 +1762,7 @@ png_write_tIME(png_structp png_ptr, png_timep mod_time)
buf[5] = mod_time->minute;
buf[6] = mod_time->second;
- png_write_chunk(png_ptr, (png_bytep)png_tIME, buf, 7);
+ png_write_chunk(png_ptr, (png_bytep)png_tIME, buf, (png_size_t)7);
}
#endif
@@ -1739,6 +1770,7 @@ png_write_tIME(png_structp png_ptr, png_timep mod_time)
void /* PRIVATE */
png_write_start_row(png_structp png_ptr)
{
+#ifdef PNG_WRITE_INTERLACING_SUPPORTED
#ifdef PNG_USE_LOCAL_ARRAYS
/* arrays to facilitate easy interlacing - use pass (0 - 6) as index */
@@ -1754,22 +1786,25 @@ png_write_start_row(png_structp png_ptr)
/* offset to next interlace block in the y direction */
int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
#endif
+#endif
png_size_t buf_size;
png_debug(1, "in png_write_start_row\n");
- buf_size = (PNG_ROWBYTES(
+ buf_size = (png_size_t)(PNG_ROWBYTES(
png_ptr->usr_channels*png_ptr->usr_bit_depth, png_ptr->width) + 1);
/* set up row buffer */
- png_ptr->row_buf = (png_bytep)png_malloc(png_ptr, buf_size);
+ png_ptr->row_buf = (png_bytep)png_malloc(png_ptr,
+ (png_size_t)buf_size);
png_ptr->row_buf[0] = PNG_FILTER_VALUE_NONE;
+#ifndef PNG_NO_WRITE_FILTER
/* set up filtering buffer, if using this filter */
if (png_ptr->do_filter & PNG_FILTER_SUB)
{
png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
- (png_ptr->rowbytes + 1));
+ (png_size_t)(png_ptr->rowbytes + 1));
png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
}
@@ -1777,29 +1812,31 @@ png_write_start_row(png_structp png_ptr)
if (png_ptr->do_filter & (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH))
{
/* set up previous row buffer */
- png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, buf_size);
+ png_ptr->prev_row = (png_bytep)png_malloc(png_ptr,
+ (png_size_t)buf_size);
png_memset(png_ptr->prev_row, 0, buf_size);
if (png_ptr->do_filter & PNG_FILTER_UP)
{
png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
- (png_ptr->rowbytes + 1));
+ (png_size_t)(png_ptr->rowbytes + 1));
png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
}
if (png_ptr->do_filter & PNG_FILTER_AVG)
{
png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
- (png_ptr->rowbytes + 1));
+ (png_size_t)(png_ptr->rowbytes + 1));
png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
}
if (png_ptr->do_filter & PNG_FILTER_PAETH)
{
png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
- (png_ptr->rowbytes + 1));
+ (png_size_t)(png_ptr->rowbytes + 1));
png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
}
+#endif /* PNG_NO_WRITE_FILTER */
}
#ifdef PNG_WRITE_INTERLACING_SUPPORTED
@@ -1833,6 +1870,7 @@ png_write_start_row(png_structp png_ptr)
void /* PRIVATE */
png_write_finish_row(png_structp png_ptr)
{
+#ifdef PNG_WRITE_INTERLACING_SUPPORTED
#ifdef PNG_USE_LOCAL_ARRAYS
/* arrays to facilitate easy interlacing - use pass (0 - 6) as index */
@@ -1848,6 +1886,7 @@ png_write_finish_row(png_structp png_ptr)
/* offset to next interlace block in the y direction */
int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
#endif
+#endif
int ret;
@@ -1895,7 +1934,7 @@ png_write_finish_row(png_structp png_ptr)
{
if (png_ptr->prev_row != NULL)
png_memset(png_ptr->prev_row, 0,
- (PNG_ROWBYTES(png_ptr->usr_channels*
+ (png_size_t)(PNG_ROWBYTES(png_ptr->usr_channels*
png_ptr->usr_bit_depth, png_ptr->width)) + 1);
return;
}
@@ -2121,7 +2160,9 @@ png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
void /* PRIVATE */
png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
{
- png_bytep prev_row, best_row, row_buf;
+ png_bytep best_row;
+#ifndef PNG_NO_WRITE_FILTER
+ png_bytep prev_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;
@@ -2134,7 +2175,10 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
bpp = (row_info->pixel_depth + 7) >> 3;
prev_row = png_ptr->prev_row;
- best_row = row_buf = png_ptr->row_buf;
+#endif
+ best_row = png_ptr->row_buf;
+#ifndef PNG_NO_WRITE_FILTER
+ row_buf = best_row;
mins = PNG_MAXSUM;
/* The prediction method we use is to find which method provides the
@@ -2709,11 +2753,12 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
best_row = png_ptr->paeth_row;
}
}
-
+#endif /* PNG_NO_WRITE_FILTER */
/* Do the actual writing of the filtered row data from the chosen filter. */
png_write_filtered_row(png_ptr, best_row);
+#ifndef PNG_NO_WRITE_FILTER
#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)
@@ -2726,6 +2771,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
png_ptr->prev_filters[j] = best_row[0];
}
#endif
+#endif /* PNG_NO_WRITE_FILTER */
}
diff --git a/scripts/CMakeLists.txt b/scripts/CMakeLists.txt
index fd26f8060..b8ff0141a 100644
--- a/scripts/CMakeLists.txt
+++ b/scripts/CMakeLists.txt
@@ -178,7 +178,7 @@ configure_file(${PNG_SOURCE_DIR}/scripts/libpng-config.in
# SET UP LINKS
set_target_properties(${PNG_LIB_NAME} PROPERTIES
-# VERSION 0.${PNGLIB_RELEASE}.1.4.0beta19
+# VERSION 0.${PNGLIB_RELEASE}.1.4.0beta20
VERSION 0.${PNGLIB_RELEASE}.0
SOVERSION 0
CLEAN_DIRECT_OUTPUT 1)
diff --git a/scripts/libpng-config-head.in b/scripts/libpng-config-head.in
index 881cb8204..f1f404573 100755
--- a/scripts/libpng-config-head.in
+++ b/scripts/libpng-config-head.in
@@ -8,7 +8,7 @@
# Modeled after libxml-config.
-version=1.4.0beta19
+version=1.4.0beta20
prefix=""
libdir=""
libs=""
diff --git a/scripts/libpng.pc.in b/scripts/libpng.pc.in
index 282c4baf7..ff066f427 100644
--- a/scripts/libpng.pc.in
+++ b/scripts/libpng.pc.in
@@ -5,6 +5,6 @@ includedir=@includedir@/libpng14
Name: libpng
Description: Loads and saves PNG files
-Version: 1.4.0beta19
+Version: 1.4.0beta20
Libs: -L${libdir} -lpng14
Cflags: -I${includedir}
diff --git a/scripts/makefile.32sunu b/scripts/makefile.32sunu
index d5db638a1..e36fe3a17 100644
--- a/scripts/makefile.32sunu
+++ b/scripts/makefile.32sunu
@@ -8,7 +8,7 @@
# Library name:
LIBNAME=libpng14
PNGMAJ = 1
-PNGMIN = 1.4.0beta19
+PNGMIN = 1.4.0beta20
PNGVER = $(PNGMAJ).$(PNGMIN)
# Shared library names:
diff --git a/scripts/makefile.64sunu b/scripts/makefile.64sunu
index 49692dba9..8bf744416 100644
--- a/scripts/makefile.64sunu
+++ b/scripts/makefile.64sunu
@@ -8,7 +8,7 @@
# Library name:
LIBNAME=libpng14
PNGMAJ = 1
-PNGMIN = 1.4.0beta19
+PNGMIN = 1.4.0beta20
PNGVER = $(PNGMAJ).$(PNGMIN)
# Shared library names:
diff --git a/scripts/makefile.aix b/scripts/makefile.aix
index edfeb73e2..7361b1904 100644
--- a/scripts/makefile.aix
+++ b/scripts/makefile.aix
@@ -20,7 +20,7 @@ LN_SF = ln -f -s
LIBNAME=libpng14
PNGMAJ = 1
-PNGMIN = 1.4.0beta19
+PNGMIN = 1.4.0beta20
PNGVER = $(PNGMAJ).$(PNGMIN)
prefix=/usr/local
diff --git a/scripts/makefile.beos b/scripts/makefile.beos
index 176152675..350f83790 100644
--- a/scripts/makefile.beos
+++ b/scripts/makefile.beos
@@ -8,7 +8,7 @@
# Library name:
LIBNAME=libpng14
PNGMAJ = 1
-PNGMIN = 1.4.0beta19
+PNGMIN = 1.4.0beta20
PNGVER = $(PNGMAJ).$(PNGMIN)
# Shared library names:
diff --git a/scripts/makefile.cygwin b/scripts/makefile.cygwin
index 56fd7c139..f174741a2 100644
--- a/scripts/makefile.cygwin
+++ b/scripts/makefile.cygwin
@@ -65,7 +65,7 @@ CFLAGS= $(strip $(MINGW_CCFLAGS) $(addprefix -I,$(ZLIBINC)) \
LIBNAME = libpng14
PNGMAJ = 1
CYGDLL = 14
-PNGMIN = 1.4.0beta19
+PNGMIN = 1.4.0beta20
PNGVER = $(PNGMAJ).$(PNGMIN)
SHAREDLIB=cygpng$(CYGDLL).dll
diff --git a/scripts/makefile.darwin b/scripts/makefile.darwin
index 8d312483f..45a501fc0 100644
--- a/scripts/makefile.darwin
+++ b/scripts/makefile.darwin
@@ -19,7 +19,7 @@ ZLIBINC=../zlib
# Library name:
LIBNAME = libpng14
PNGMAJ = 1
-PNGMIN = 1.4.0beta19
+PNGMIN = 1.4.0beta20
PNGVER = $(PNGMAJ).$(PNGMIN)
# Shared library names:
diff --git a/scripts/makefile.dec b/scripts/makefile.dec
index 287e843b4..509fe92ee 100644
--- a/scripts/makefile.dec
+++ b/scripts/makefile.dec
@@ -5,7 +5,7 @@
# Library name:
PNGMAJ = 1
-PNGMIN = 1.4.0beta19
+PNGMIN = 1.4.0beta20
PNGVER = $(PNGMAJ).$(PNGMIN)
LIBNAME = libpng14
diff --git a/scripts/makefile.elf b/scripts/makefile.elf
index e36a71f5d..1f5b634f8 100644
--- a/scripts/makefile.elf
+++ b/scripts/makefile.elf
@@ -12,7 +12,7 @@
# Library name:
LIBNAME = libpng14
PNGMAJ = 1
-PNGMIN = 1.4.0beta19
+PNGMIN = 1.4.0beta20
PNGVER = $(PNGMAJ).$(PNGMIN)
# Shared library names:
diff --git a/scripts/makefile.gcmmx b/scripts/makefile.gcmmx
index 6689ad219..2092e9df2 100644
--- a/scripts/makefile.gcmmx
+++ b/scripts/makefile.gcmmx
@@ -16,7 +16,7 @@
# Library name:
LIBNAME = libpng14
PNGMAJ = 1
-PNGMIN = 1.4.0beta19
+PNGMIN = 1.4.0beta20
PNGVER = $(PNGMAJ).$(PNGMIN)
# Shared library names:
diff --git a/scripts/makefile.hp64 b/scripts/makefile.hp64
index 464cf7cb3..a328c83b6 100644
--- a/scripts/makefile.hp64
+++ b/scripts/makefile.hp64
@@ -18,7 +18,7 @@ ZLIBINC=/opt/zlib/include
# Library name:
LIBNAME = libpng14
PNGMAJ = 1
-PNGMIN = 1.4.0beta19
+PNGMIN = 1.4.0beta20
PNGVER = $(PNGMAJ).$(PNGMIN)
# Shared library names:
diff --git a/scripts/makefile.hpgcc b/scripts/makefile.hpgcc
index f5b78f332..762036575 100644
--- a/scripts/makefile.hpgcc
+++ b/scripts/makefile.hpgcc
@@ -8,7 +8,7 @@
# Library name:
LIBNAME = libpng14
PNGMAJ = 1
-PNGMIN = 1.4.0beta19
+PNGMIN = 1.4.0beta20
PNGVER = $(PNGMAJ).$(PNGMIN)
# Shared library names:
diff --git a/scripts/makefile.hpux b/scripts/makefile.hpux
index 577f9c5e4..f7bde8a36 100644
--- a/scripts/makefile.hpux
+++ b/scripts/makefile.hpux
@@ -18,7 +18,7 @@ ZLIBINC=/opt/zlib/include
# Library name:
LIBNAME = libpng14
PNGMAJ = 1
-PNGMIN = 1.4.0beta19
+PNGMIN = 1.4.0beta20
PNGVER = $(PNGMAJ).$(PNGMIN)
# Shared library names:
diff --git a/scripts/makefile.linux b/scripts/makefile.linux
index da853fc43..36fe45e2c 100644
--- a/scripts/makefile.linux
+++ b/scripts/makefile.linux
@@ -6,7 +6,7 @@
# Library name:
LIBNAME = libpng14
PNGMAJ = 1
-PNGMIN = 1.4.0beta19
+PNGMIN = 1.4.0beta20
PNGVER = $(PNGMAJ).$(PNGMIN)
# Shared library names:
diff --git a/scripts/makefile.mingw b/scripts/makefile.mingw
index bdcc44524..ac36ee13d 100644
--- a/scripts/makefile.mingw
+++ b/scripts/makefile.mingw
@@ -6,15 +6,15 @@
# Built from makefile.cygwin
# Copyright (C) 2002, 2006 Soren Anderson, Charles Wilson,
# and Glenn Randers-Pehrson, based on makefile for linux-elf w/mmx by:
-# Copyright (C) 1998-2000 Greg Roelofs
+# Copyright (C) 1998-2000, 2007 Greg Roelofs
# Copyright (C) 1996, 1997 Andreas Dilger
# For conditions of distribution and use, see copyright notice in png.h
+
# This makefile intends to support building outside the src directory
# if desired. When invoking it, specify an argument to SRCDIR on the
# command line that points to the top of the directory where your source
# is located.
-
ifdef SRCDIR
VPATH = $(SRCDIR)
else
@@ -29,16 +29,25 @@ endif
# If you're going to install into a temporary location
# via DESTDIR, $(DESTDIR)$(prefix) must already exist before
# you execute make install.
-
DESTDIR=
+# If you're using a cross-compiler, add the appropriate prefix (e.g.,
+# "i386-mingw32msvc-") to the following three commands:
CC=gcc
+AR=ar
+RANLIB=ranlib
+
+MKDIR_P=/bin/mkdir -pv
+
+
+# To enable assembler optimizations, add '-DPNG_USE_PNGGCCRD' to
+# $CFLAGS, and include pnggccrd.o in $OBJS, below.
# Where "make install" puts libpng*.a, *png*.dll, png.h, and pngconf.h
ifndef prefix
prefix=/usr
-$(warning You haven't specified a 'prefix=' location. Defaulting to "/usr")
+$(warning "You haven't specified a 'prefix=' location. Defaulting to '/usr'")
endif
exec_prefix=$(prefix)
@@ -54,15 +63,25 @@ WARNMORE=-Wwrite-strings -Wpointer-arith -Wshadow \
-Wmissing-declarations -Wtraditional -Wcast-align \
-Wstrict-prototypes -Wmissing-prototypes #-Wconversion
-### Normal compilation
+### if you use the asm, add pnggccrd.o to the OBJS list
+###
+### if you don't need thread safety, but want the asm accel
+#CFLAGS= $(strip $(MINGW_CCFLAGS) -DPNG_THREAD_UNSAFE_OK -DPNG_USE_PNGGCCRD \
+# $(addprefix -I,$(ZLIBINC)) -Wall -O3 $(ALIGN) -funroll-loops \
+# -fomit-frame-pointer) # $(WARNMORE) -g -DPNG_DEBUG=5
+### if you need thread safety and want (minimal) asm accel
+#CFLAGS= $(strip $(MINGW_CCFLAGS) -DPNG_USE_PNGGCCRD $(addprefix -I,$(ZLIBINC)) \
+# -Wall -O3 $(ALIGN) -funroll-loops \
+# -fomit-frame-pointer) # $(WARNMORE) -g -DPNG_DEBUG=5
+### Normal (non-asm) compilation
CFLAGS= $(strip $(MINGW_CCFLAGS) $(addprefix -I,$(ZLIBINC)) \
-Wall -O3 $(ALIGN) -funroll-loops \
-fomit-frame-pointer) # $(WARNMORE) -g -DPNG_DEBUG=5
LIBNAME = libpng14
-PNGMAJ = 1
+PNGMAJ = 1
MINGDLL = 14
-PNGMIN = 1.4.0beta19
+PNGMIN = 1.4.0beta20
PNGVER = $(PNGMAJ).$(PNGMIN)
SHAREDLIB=libpng$(MINGDLL).dll
@@ -76,10 +95,6 @@ LDFLAGS=$(strip -L. $(MINGW_LDFLAGS) -lpng $(addprefix -L,$(ZLIBLIB)) -lz)
LDSFLAGS=$(strip -shared -L. $(MINGW_LDFLAGS))
LDEXTRA=-Wl,--out-implib=$(IMPLIB) $(addprefix -L,$(ZLIBLIB)) -lz
-MKDIR_P=/bin/mkdir -pv
-RANLIB=ranlib
-#RANLIB=echo
-
INCPATH=$(prefix)/include
LIBPATH=$(exec_prefix)/lib
@@ -97,7 +112,7 @@ DL =$(D)$(LIBPATH)
OBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \
pngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \
- pngwtran.o pngmem.o pngerror.o pngpread.o pnggccrd.o
+ pngwtran.o pngmem.o pngerror.o pngpread.o # pnggccrd.o
OBJSDLL = $(OBJS:.o=.pic.o)
@@ -149,22 +164,8 @@ shared: all-shared
all-static: $(STATLIB) pngtest-stat$(EXE)
all-shared: $(SHAREDLIB) pngtest$(EXE)
-pnggccrd.o: pnggccrd.c png.h pngconf.h pngdefs.h pngpriv.h
- @echo ""
- @echo ' You can ignore the "control reaches end of non-void function"'
- @echo ' warning and "<variable> defined but not used" warnings:'
- @echo ""
- $(CC) -c $(CFLAGS) -o $@ $<
-
-pnggccrd.pic.o: pnggccrd.c png.h pngconf.h pngdefs.h pngpriv.h
- @echo ""
- @echo ' You can ignore the "control reaches end of non-void function"'
- @echo ' warning and "<variable> defined but not used" warnings:'
- @echo ""
- $(CC) -c $(CFLAGS) -DPNG_BUILD_DLL -o $@ $<
-
$(STATLIB): $(OBJS)
- ar rc $@ $(OBJS)
+ $(AR) rc $@ $(OBJS)
$(RANLIB) $@
$(SHAREDDEF): scripts/pngwin.def
@@ -180,12 +181,6 @@ pngtest$(EXE): pngtest.pic.o $(SHAREDLIB)
pngtest-stat$(EXE): pngtest.o $(STATLIB)
$(CC) -static $(CFLAGS) $< $(LDFLAGS) -o $@
-pngtest.pic.o: pngtest.c
- $(CC) $(CFLAGS) -c $< -o $@
-
-pngtest.o: pngtest.c
- $(CC) $(CFLAGS) -c $< -o $@
-
test: test-static test-shared
test-static: pngtest-stat$(EXE)
@@ -218,8 +213,7 @@ install-headers:
-@if [ ! -d $(DI)/$(LIBNAME) ]; then $(MKDIR_P) $(DI)/$(LIBNAME); fi
-@rm -f $(DI)/png.h
-@rm -f $(DI)/pngconf.h
- -@rm -f $(DI)/pngdefs.h
- install -m 644 $(S)/png.h $(S)/pngconf.h $(S)/pngdefs.h $(DI)/$(LIBNAME)
+ install -m 644 $(S)/png.h $(S)/pngconf.h $(DI)/$(LIBNAME)
-@rm -f $(DI)/libpng
(cd $(DI); ln -sf $(LIBNAME) libpng; ln -sf $(LIBNAME)/* .)
@@ -273,8 +267,8 @@ test-installed:
clean:
/bin/rm -f *.pic.o *.o $(STATLIB) $(IMPLIB) $(SHAREDLIB) \
- pngtest-stat$(EXE) pngtest$(EXE) pngout.png $(SHAREDDEF) \
- libpng-config libpng.pc pngtesti$(EXE) pngdefs.h
+ pngtest-stat$(EXE) pngtest$(EXE) pngout.png $(SHAREDDEF) \
+ libpng-config libpng.pc pngtesti$(EXE)
DOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO
writelock:
@@ -284,23 +278,24 @@ writelock:
# DO NOT DELETE THIS LINE -- make depend depends on it.
-png.o png.pic.o: png.h pngconf.h pngdefs.h pngpriv.h png.c
-pngerror.o pngerror.pic.o: png.h pngconf.h pngdefs.h pngpriv.h pngerror.c
-pngrio.o pngrio.pic.o: png.h pngconf.h pngdefs.h pngpriv.h pngrio.c
-pngwio.o pngwio.pic.o: png.h pngconf.h pngdefs.h pngpriv.h pngwio.c
-pngmem.o pngmem.pic.o: png.h pngconf.h pngdefs.h pngpriv.h pngmem.c
-pngset.o pngset.pic.o: png.h pngconf.h pngdefs.h pngpriv.h pngset.c
-pnggcrd.o pnggcrd.pic.o: png.h pngconf.h pngdefs.h pngpriv.h pngget.c
-pngget.o pngget.pic.o: png.h pngconf.h pngdefs.h pngpriv.h pngget.c
-pngread.o pngread.pic.o: png.h pngconf.h pngdefs.h pngpriv.h pngread.c
-pngrtran.o pngrtran.pic.o: png.h pngconf.h pngdefs.h pngpriv.h pngrtran.c
-pngrutil.o pngrutil.pic.o: png.h pngconf.h pngdefs.h pngpriv.h pngrutil.c
-pngtrans.o pngtrans.pic.o: png.h pngconf.h pngdefs.h pngpriv.h pngtrans.c
-pngwrite.o pngwrite.pic.o: png.h pngconf.h pngdefs.h pngpriv.h pngwrite.c
-pngwtran.o pngwtran.pic.o: png.h pngconf.h pngdefs.h pngpriv.h pngwtran.c
-pngwutil.o pngwutil.pic.o: png.h pngconf.h pngdefs.h pngpriv.h pngwutil.c
-pngpread.o pngpread.pic.o: png.h pngconf.h pngdefs.h pngpriv.h pngpread.c
-
-pngtest.o: png.h pngconf.h pngdefs.h pngtest.c
-pngtest-stat.o: png.h pngconf.h pngdefs.h pngtest.c
+png.o png.pic.o: png.h pngconf.h pngpriv.h pngdefs.h png.c
+pngerror.o pngerror.pic.o: png.h pngconf.h pngpriv.h pngdefs.h pngerror.c
+pngrio.o pngrio.pic.o: png.h pngconf.h pngpriv.h pngdefs.h pngrio.c
+pngwio.o pngwio.pic.o: png.h pngconf.h pngpriv.h pngdefs.h pngwio.c
+pngmem.o pngmem.pic.o: png.h pngconf.h pngpriv.h pngdefs.h pngmem.c
+pngset.o pngset.pic.o: png.h pngconf.h pngpriv.h pngdefs.h pngset.c
+pngget.o pngget.pic.o: png.h pngconf.h pngpriv.h pngdefs.h pngget.c
+pngread.o pngread.pic.o: png.h pngconf.h pngpriv.h pngdefs.h pngread.c
+pngrtran.o pngrtran.pic.o: png.h pngconf.h pngpriv.h pngdefs.h pngrtran.c
+pngrutil.o pngrutil.pic.o: png.h pngconf.h pngpriv.h pngdefs.h pngrutil.c
+pngtrans.o pngtrans.pic.o: png.h pngconf.h pngpriv.h pngdefs.h pngtrans.c
+pngwrite.o pngwrite.pic.o: png.h pngconf.h pngpriv.h pngdefs.h pngwrite.c
+pngwtran.o pngwtran.pic.o: png.h pngconf.h pngpriv.h pngdefs.h pngwtran.c
+pngwutil.o pngwutil.pic.o: png.h pngconf.h pngpriv.h pngdefs.h pngwutil.c
+pngpread.o pngpread.pic.o: png.h pngconf.h pngpriv.h pngdefs.h pngpread.c
+pnggccrd.o pnggccrd.pic.o: png.h pngconf.h pngpriv.h pngdefs.h pnggccrd.c
+
+pngtest.o pngtest.pic.o: png.h pngconf.h pngpriv.h pngdefs.h pngtest.c
+
+
diff --git a/scripts/makefile.ne12bsd b/scripts/makefile.ne12bsd
index 58c902c37..1baaf5aa8 100644
--- a/scripts/makefile.ne12bsd
+++ b/scripts/makefile.ne12bsd
@@ -14,7 +14,7 @@ INCSDIR=${LOCALBASE}/include/libpng14
LIB= png14
SHLIB_MAJOR= 0
-SHLIB_MINOR= 1.4.0beta19
+SHLIB_MINOR= 1.4.0beta20
SRCS= pnggccrd.c png.c pngset.c pngget.c pngrutil.c pngtrans.c pngwutil.c \
pngread.c pngrio.c pngwio.c pngwrite.c pngrtran.c \
pngwtran.c pngmem.c pngerror.c pngpread.c
diff --git a/scripts/makefile.netbsd b/scripts/makefile.netbsd
index bfae9be05..d9d60a663 100644
--- a/scripts/makefile.netbsd
+++ b/scripts/makefile.netbsd
@@ -13,7 +13,7 @@ INCSDIR=${LOCALBASE}/include/libpng
LIB= png
SHLIB_MAJOR= 3
-SHLIB_MINOR= 1.4.0beta19
+SHLIB_MINOR= 1.4.0beta20
SRCS= pnggccrd.c png.c pngset.c pngget.c pngrutil.c pngtrans.c pngwutil.c \
pngread.c pngrio.c pngwio.c pngwrite.c pngrtran.c \
pngwtran.c pngmem.c pngerror.c pngpread.c
diff --git a/scripts/makefile.nommx b/scripts/makefile.nommx
index 70c724986..8125252c8 100644
--- a/scripts/makefile.nommx
+++ b/scripts/makefile.nommx
@@ -16,7 +16,7 @@
# Library name:
LIBNAME = libpng14
PNGMAJ = 1
-PNGMIN = 1.4.0beta19
+PNGMIN = 1.4.0beta20
PNGVER = $(PNGMAJ).$(PNGMIN)
# Shared library names:
diff --git a/scripts/makefile.openbsd b/scripts/makefile.openbsd
index 5444f36f8..8517bf230 100644
--- a/scripts/makefile.openbsd
+++ b/scripts/makefile.openbsd
@@ -8,7 +8,7 @@ LIBDIR= ${PREFIX}/lib
MANDIR= ${PREFIX}/man/cat
SHLIB_MAJOR= 0
-SHLIB_MINOR= 1.4.0beta19
+SHLIB_MINOR= 1.4.0beta20
LIB= png
SRCS= png.c pngerror.c pnggccrd.c pngget.c pngmem.c pngpread.c \
diff --git a/scripts/makefile.sco b/scripts/makefile.sco
index 3ea8f17b0..cb2fa29ce 100644
--- a/scripts/makefile.sco
+++ b/scripts/makefile.sco
@@ -9,7 +9,7 @@
# Library name:
LIBNAME = libpng14
PNGMAJ = 1
-PNGMIN = 1.4.0beta19
+PNGMIN = 1.4.0beta20
PNGVER = $(PNGMAJ).$(PNGMIN)
# Shared library names:
diff --git a/scripts/makefile.sggcc b/scripts/makefile.sggcc
index 12dd0dab7..fad7514cb 100644
--- a/scripts/makefile.sggcc
+++ b/scripts/makefile.sggcc
@@ -6,7 +6,7 @@
# Library name:
LIBNAME=libpng14
PNGMAJ = 1
-PNGMIN = 1.4.0beta19
+PNGMIN = 1.4.0beta20
PNGVER = $(PNGMAJ).$(PNGMIN)
# Shared library names:
diff --git a/scripts/makefile.sgi b/scripts/makefile.sgi
index 257ab5970..763d65bbf 100644
--- a/scripts/makefile.sgi
+++ b/scripts/makefile.sgi
@@ -6,7 +6,7 @@
# Library name:
LIBNAME=libpng14
PNGMAJ = 1
-PNGMIN = 1.4.0beta19
+PNGMIN = 1.4.0beta20
PNGVER = $(PNGMAJ).$(PNGMIN)
# Shared library names:
diff --git a/scripts/makefile.so9 b/scripts/makefile.so9
index f1b7d7d06..2ec18f85e 100644
--- a/scripts/makefile.so9
+++ b/scripts/makefile.so9
@@ -8,7 +8,7 @@
# Library name:
PNGMAJ = 1
-PNGMIN = 1.4.0beta19
+PNGMIN = 1.4.0beta20
PNGVER = $(PNGMAJ).$(PNGMIN)
LIBNAME = libpng14
diff --git a/scripts/makefile.solaris b/scripts/makefile.solaris
index d15fc245c..6c5fe31e4 100644
--- a/scripts/makefile.solaris
+++ b/scripts/makefile.solaris
@@ -8,7 +8,7 @@
# Library name:
LIBNAME = libpng14
PNGMAJ = 1
-PNGMIN = 1.4.0beta19
+PNGMIN = 1.4.0beta20
PNGVER = $(PNGMAJ).$(PNGMIN)
# Shared library names:
diff --git a/scripts/pngos2.def b/scripts/pngos2.def
index 2f384ae46..ec880adc7 100644
--- a/scripts/pngos2.def
+++ b/scripts/pngos2.def
@@ -2,7 +2,7 @@
; PNG.LIB module definition file for OS/2
;----------------------------------------
-; Version 1.4.0beta19
+; Version 1.4.0beta20
LIBRARY PNG
DESCRIPTION "PNG image compression library for OS/2"
diff --git a/scripts/pngwin.def b/scripts/pngwin.def
index e21405c9a..eb9ddc1ce 100644
--- a/scripts/pngwin.def
+++ b/scripts/pngwin.def
@@ -5,7 +5,7 @@
LIBRARY
EXPORTS
-;Version 1.4.0beta19
+;Version 1.4.0beta20
png_build_grayscale_palette
png_chunk_error
png_chunk_warning