Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mpc-hc/mpc-hc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralexwild <alexwild@users.sourceforge.net>2007-08-29 00:27:02 +0400
committeralexwild <alexwild@users.sourceforge.net>2007-08-29 00:27:02 +0400
commit1bdc52d312142e9c9f31438f27d5376e64ddf30f (patch)
tree92fdc1e4e481d7553c56f7cc3e3308dd2f316daf /src/libpng
parentd9466c2e38f00caf8182198c54de45f8f8802045 (diff)
libpng update to v1.2.19
git-svn-id: https://mpc-hc.svn.sourceforge.net/svnroot/mpc-hc/trunk@176 10f7b99b-c216-0410-bff0-8a66a9350fd8
Diffstat (limited to 'src/libpng')
-rw-r--r--src/libpng/LICENSE109
-rw-r--r--src/libpng/README263
-rw-r--r--src/libpng/png.c112
-rw-r--r--src/libpng/png.h146
-rw-r--r--src/libpng/pngconf.h168
-rw-r--r--src/libpng/pngerror.c32
-rw-r--r--src/libpng/pnggccrd.c5559
-rw-r--r--src/libpng/pngget.c11
-rw-r--r--src/libpng/pngpread.c78
-rw-r--r--src/libpng/pngread.c109
-rw-r--r--src/libpng/pngrtran.c81
-rw-r--r--src/libpng/pngrutil.c1159
-rw-r--r--src/libpng/pngset.c39
-rw-r--r--src/libpng/pngtest.c21
-rw-r--r--src/libpng/pngtrans.c10
-rw-r--r--src/libpng/pngvcrd.c1162
-rw-r--r--src/libpng/pngwio.c2
-rw-r--r--src/libpng/pngwrite.c44
-rw-r--r--src/libpng/pngwutil.c50
19 files changed, 5694 insertions, 3461 deletions
diff --git a/src/libpng/LICENSE b/src/libpng/LICENSE
new file mode 100644
index 000000000..09f543f2a
--- /dev/null
+++ b/src/libpng/LICENSE
@@ -0,0 +1,109 @@
+
+This copy of the libpng notices is provided for your convenience. In case of
+any discrepancy between this copy and the notices in the file png.h that is
+included in the libpng distribution, the latter shall prevail.
+
+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.2.19, August 18, 2007, 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
+
+ Cosmin Truta
+
+libpng versions 1.0.7, July 1, 2000, through 1.2.5 - October 3, 2002, are
+Copyright (c) 2000-2002 Glenn Randers-Pehrson, and are
+distributed according to the same disclaimer and license as libpng-1.0.6
+with the following individuals added to the list of Contributing Authors
+
+ Simon-Pierre Cadieux
+ Eric S. Raymond
+ Gilles Vollant
+
+and with the following additions to the disclaimer:
+
+ There is no warranty against interference with your enjoyment of the
+ library or against infringement. There is no warranty that our
+ efforts or the library will fulfill any of your particular purposes
+ or needs. This library is provided with all faults, and the entire
+ risk of satisfactory quality, performance, accuracy, and effort is with
+ the user.
+
+libpng versions 0.97, January 1998, through 1.0.6, March 20, 2000, are
+Copyright (c) 1998, 1999 Glenn Randers-Pehrson, and are
+distributed according to the same disclaimer and license as libpng-0.96,
+with the following individuals added to the list of Contributing Authors:
+
+ Tom Lane
+ Glenn Randers-Pehrson
+ Willem van Schaik
+
+libpng versions 0.89, June 1996, through 0.96, May 1997, are
+Copyright (c) 1996, 1997 Andreas Dilger
+Distributed according to the same disclaimer and license as libpng-0.88,
+with the following individuals added to the list of Contributing Authors:
+
+ John Bowler
+ Kevin Bracey
+ Sam Bushell
+ Magnus Holmgren
+ Greg Roelofs
+ Tom Tanner
+
+libpng versions 0.5, May 1995, through 0.88, January 1996, are
+Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
+
+For the purposes of this copyright and license, "Contributing Authors"
+is defined as the following set of individuals:
+
+ Andreas Dilger
+ Dave Martindale
+ Guy Eric Schalnat
+ Paul Schmidt
+ Tim Wegner
+
+The PNG Reference Library is supplied "AS IS". The Contributing Authors
+and Group 42, Inc. disclaim all warranties, expressed or implied,
+including, without limitation, the warranties of merchantability and of
+fitness for any purpose. The Contributing Authors and Group 42, Inc.
+assume no liability for direct, indirect, incidental, special, exemplary,
+or consequential damages, which may result from the use of the PNG
+Reference Library, even if advised of the possibility of such damage.
+
+Permission is hereby granted to use, copy, modify, and distribute this
+source code, or portions hereof, for any purpose, without fee, subject
+to the following restrictions:
+
+1. The origin of this source code must not be misrepresented.
+
+2. Altered versions must be plainly marked as such and must not
+ be misrepresented as being the original source.
+
+3. This Copyright notice may not be removed or altered from any
+ source or altered source distribution.
+
+The Contributing Authors and Group 42, Inc. specifically permit, without
+fee, and encourage the use of this source code as a component to
+supporting the PNG file format in commercial products. If you use this
+source code in a product, acknowledgment is not required but would be
+appreciated.
+
+
+A "png_get_copyright" function is available, for convenient use in "about"
+boxes and the like:
+
+ printf("%s",png_get_copyright(NULL));
+
+Also, the PNG logo (in PNG format, of course) is supplied in the
+files "pngbar.png" and "pngbar.jpg (88x31) and "pngnow.png" (98x31).
+
+Libpng is OSI Certified Open Source Software. OSI Certified Open Source is a
+certification mark of the Open Source Initiative.
+
+Glenn Randers-Pehrson
+glennrp at users.sourceforge.net
+August 18, 2007
diff --git a/src/libpng/README b/src/libpng/README
new file mode 100644
index 000000000..b60484075
--- /dev/null
+++ b/src/libpng/README
@@ -0,0 +1,263 @@
+README for libpng version 1.2.19 - August 18, 2007 (shared library 12.0)
+See the note about version numbers near the top of png.h
+
+See INSTALL for instructions on how to install libpng.
+
+Libpng comes in several distribution formats. Get libpng-*.tar.gz
+or libpng-*.tar.bz2 if you want UNIX-style line endings in the text
+files, or lpng*.zip if you want DOS-style line endings.
+
+Version 0.89 was the first official release of libpng. Don't let the
+fact that it's the first release fool you. The libpng library has been in
+extensive use and testing since mid-1995. By late 1997 it had
+finally gotten to the stage where there hadn't been significant
+changes to the API in some time, and people have a bad feeling about
+libraries with versions < 1.0. Version 1.0.0 was released in
+March 1998.
+
+****
+Note that some of the changes to the png_info structure render this
+version of the library binary incompatible with libpng-0.89 or
+earlier versions if you are using a shared library. The type of the
+"filler" parameter for png_set_filler() has changed from png_byte to
+png_uint_32, which will affect shared-library applications that use
+this function.
+
+To avoid problems with changes to the internals of png_info_struct,
+new APIs have been made available in 0.95 to avoid direct application
+access to info_ptr. These functions are the png_set_<chunk> and
+png_get_<chunk> functions. These functions should be used when
+accessing/storing the info_struct data, rather than manipulating it
+directly, to avoid such problems in the future.
+
+It is important to note that the APIs do not make current programs
+that access the info struct directly incompatible with the new
+library. However, it is strongly suggested that new programs use
+the new APIs (as shown in example.c and pngtest.c), and older programs
+be converted to the new format, to facilitate upgrades in the future.
+****
+
+Additions since 0.90 include the ability to compile libpng as a
+Windows DLL, and new APIs for accessing data in the info struct.
+Experimental functions include the ability to set weighting and cost
+factors for row filter selection, direct reads of integers from buffers
+on big-endian processors that support misaligned data access, faster
+methods of doing alpha composition, and more accurate 16->8 bit color
+conversion.
+
+The additions since 0.89 include the ability to read from a PNG stream
+which has had some (or all) of the signature bytes read by the calling
+application. This also allows the reading of embedded PNG streams that
+do not have the PNG file signature. As well, it is now possible to set
+the library action on the detection of chunk CRC errors. It is possible
+to set different actions based on whether the CRC error occurred in a
+critical or an ancillary chunk.
+
+The changes made to the library, and bugs fixed are based on discussions
+on the PNG-implement mailing list
+and not on material submitted privately to Guy, Andreas, or Glenn. They will
+forward any good suggestions to the list.
+
+For a detailed description on using libpng, read libpng.txt. For
+examples of libpng in a program, see example.c and pngtest.c. For usage
+information and restrictions (what little they are) on libpng, see
+png.h. For a description on using zlib (the compression library used by
+libpng) and zlib's restrictions, see zlib.h
+
+I have included a general makefile, as well as several machine and
+compiler specific ones, but you may have to modify one for your own needs.
+
+You should use zlib 1.0.4 or later to run this, but it MAY work with
+versions as old as zlib 0.95. Even so, there are bugs in older zlib
+versions which can cause the output of invalid compression streams for
+some images. You will definitely need zlib 1.0.4 or later if you are
+taking advantage of the MS-DOS "far" structure allocation for the small
+and medium memory models. You should also note that zlib is a
+compression library that is useful for more things than just PNG files.
+You can use zlib as a drop-in replacement for fread() and fwrite() if
+you are so inclined.
+
+zlib should be available at the same place that libpng is, or at.
+ftp://ftp.info-zip.org/pub/infozip/zlib
+
+You may also want a copy of the PNG specification. It is available
+as an RFC, a W3C Recommendation, and an ISO/IEC Standard. You can find
+these at http://www.libpng.org/pub/png/documents/
+
+This code is currently being archived at libpng.sf.net in the
+[DOWNLOAD] area, and on CompuServe, Lib 20 (PNG SUPPORT)
+at GO GRAPHSUP. If you can't find it in any of those places,
+e-mail me, and I'll help you find it.
+
+If you have any code changes, requests, problems, etc., please e-mail
+them to me. Also, I'd appreciate any make files or project files,
+and any modifications you needed to make to get libpng to compile,
+along with a #define variable to tell what compiler/system you are on.
+If you needed to add transformations to libpng, or wish libpng would
+provide the image in a different way, drop me a note (and code, if
+possible), so I can consider supporting the transformation.
+Finally, if you get any warning messages when compiling libpng
+(note: not zlib), and they are easy to fix, I'd appreciate the
+fix. Please mention "libpng" somewhere in the subject line. Thanks.
+
+This release was created and will be supported by myself (of course
+based in a large way on Guy's and Andreas' earlier work), and the PNG group.
+
+Send comments/corrections/commendations to png-mng-implement at lists.sf.net
+(subscription required; visit
+https://lists.sourceforge.net/lists/listinfo/png-mng-implement
+to subscribe) or to glennrp at users.sourceforge.net
+
+You can't reach Guy, the original libpng author, at the addresses
+given in previous versions of this document. He and Andreas will read mail
+addressed to the png-implement list, however.
+
+Please do not send general questions about PNG. Send them to
+the (png-list at ccrc.wustl.edu, subscription required, write to
+majordomo at ccrc.wustl.edu with "subscribe png-list" in your message).
+On the other hand,
+please do not send libpng questions to that address, send them to me
+or to the png-implement list. I'll
+get them in the end anyway. If you have a question about something
+in the PNG specification that is related to using libpng, send it
+to me. Send me any questions that start with "I was using libpng,
+and ...". If in doubt, send questions to me. I'll bounce them
+to others, if necessary.
+
+Please do not send suggestions on how to change PNG. We have
+been discussing PNG for nine years now, and it is official and
+finished. If you have suggestions for libpng, however, I'll
+gladly listen. Even if your suggestion is not used immediately,
+it may be used later.
+
+Files in this distribution:
+
+ ANNOUNCE => Announcement of this version, with recent changes
+ CHANGES => Description of changes between libpng versions
+ KNOWNBUG => List of known bugs and deficiencies
+ LICENSE => License to use and redistribute libpng
+ README => This file
+ TODO => Things not implemented in the current library
+ Y2KINFO => Statement of Y2K compliance
+ example.c => Example code for using libpng functions
+ libpng.3 => manual page for libpng (includes libpng.txt)
+ libpng.txt => Description of libpng and its functions
+ libpngpf.3 => manual page for libpng's private functions
+ png.5 => manual page for the PNG format
+ png.c => Basic interface functions common to library
+ png.h => Library function and interface declarations
+ pngconf.h => System specific library configuration
+ pngasmrd.h => Header file for assembler-coded functions
+ pngerror.c => Error/warning message I/O functions
+ pngget.c => Functions for retrieving info from struct
+ pngmem.c => Memory handling functions
+ pngbar.png => PNG logo, 88x31
+ pngnow.png => PNG logo, 98x31
+ pngpread.c => Progressive reading functions
+ pngread.c => Read data/helper high-level functions
+ pngrio.c => Lowest-level data read I/O functions
+ pngrtran.c => Read data transformation functions
+ pngrutil.c => Read data utility functions
+ pngset.c => Functions for storing data into the info_struct
+ pngtest.c => Library test program
+ pngtest.png => Library test sample image
+ pngtrans.c => Common data transformation functions
+ pngwio.c => Lowest-level write I/O functions
+ pngwrite.c => High-level write functions
+ pngwtran.c => Write data transformations
+ pngwutil.c => Write utility functions
+ contrib => Contributions
+ gregbook => source code for PNG reading and writing, from
+ Greg Roelofs' "PNG: The Definitive Guide",
+ O'Reilly, 1999
+ msvctest => Builds and runs pngtest using a MSVC workspace
+ pngminus => Simple pnm2png and png2pnm programs
+ pngsuite => Test images
+ visupng => Contains a MSVC workspace for VisualPng
+ projects => Contains project files and workspaces for building DLL
+ beos => Contains a Beos workspace for building libpng
+ c5builder => Contains a Borland workspace for building libpng
+ and zlib
+ visualc6 => Contains a Microsoft Visual C++ (MSVC) workspace
+ for building libpng and zlib
+ netware.txt => Contains instructions for downloading a set of
+ project files for building libpng and zlib on
+ Netware.
+ wince.txt => Contains instructions for downloading a Microsoft
+ Visual C++ (Windows CD Toolkit) workspace for
+ building libpng and zlib on WindowsCE
+ scripts => Directory containing scripts for building libpng:
+ 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 libpng12.so.0.1.2.19)
+ makefile.linux => Linux/ELF makefile
+ (gcc, creates libpng12.so.0.1.2.19)
+ makefile.gcmmx => Linux/ELF makefile
+ (gcc, creates libpng12.so.0.1.2.19,
+ 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
+ ansi2knr (Requires ansi2knr.c from
+ ftp://ftp.cs.wisc.edu/ghost)
+ makefile.aix => AIX makefile
+ makefile.cygwin => Cygwin/gcc makefile
+ makefile.darwin => Darwin makefile
+ makefile.dec => DEC Alpha UNIX makefile
+ makefile.freebsd => FreeBSD makefile
+ makefile.hpgcc => HPUX makefile using gcc
+ makefile.hpux => HPUX (10.20 and 11.00) makefile
+ makefile.hp64 => HPUX (10.20 and 11.00) makefile, 64 bit
+ makefile.ibmc => IBM C/C++ version 3.x for Win32 and OS/2 (static)
+ makefile.intel => Intel C/C++ version 4.0 and later
+ libpng.icc => Project file, IBM VisualAge/C++ 4.0 or later
+ makefile.netbsd => NetBSD/cc makefile, PNGGCCRD, makes libpng.so.
+ makefile.ne12bsd => NetBSD/cc makefile, PNGGCCRD, makes libpng12.so
+ makefile.openbsd => OpenBSD makefile
+ makefile.sgi => Silicon Graphics IRIX (cc, creates static lib)
+ makefile.sggcc => Silicon Graphics
+ (gcc, creates libpng12.so.0.1.2.19)
+ makefile.sunos => Sun makefile
+ makefile.solaris => Solaris 2.X makefile
+ (gcc, creates libpng12.so.0.1.2.19)
+ makefile.so9 => Solaris 9 makefile
+ (gcc, creates libpng12.so.0.1.2.19)
+ 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
+ makefile.mips => MIPS makefile
+ makefile.acorn => Acorn makefile
+ makefile.amiga => Amiga makefile
+ smakefile.ppc => AMIGA smakefile for SAS C V6.58/7.00 PPC
+ compiler (Requires SCOPTIONS, copied from
+ scripts/SCOPTIONS.ppc)
+ makefile.atari => Atari makefile
+ makefile.beos => BEOS makefile for X86
+ makefile.bor => Borland makefile (uses bcc)
+ makefile.bc32 => 32-bit Borland C++ (all modules compiled in C mode)
+ makefile.tc3 => Turbo C 3.0 makefile
+ makefile.dj2 => DJGPP 2 makefile
+ makefile.msc => Microsoft C makefile
+ makefile.vcawin32=> makefile for Microsoft Visual C++ 5.0 and
+ later (uses assembler code tuned for Intel MMX
+ platform)
+ makefile.vcwin32 => makefile for Microsoft Visual C++ 4.0 and
+ later (does not use assembler code)
+ makefile.os2 => OS/2 Makefile (gcc and emx, requires pngos2.def)
+ pngos2.def => OS/2 module definition file used by makefile.os2
+ makefile.watcom => Watcom 10a+ Makefile, 32-bit flat memory model
+ makevms.com => VMS build script
+ SCOPTIONS.ppc => Used with smakefile.ppc
+
+Good luck, and happy coding.
+
+-Glenn Randers-Pehrson (current maintainer)
+ Internet: glennrp at users.sourceforge.net
+
+-Andreas Eric Dilger (former maintainer, 1996-1997)
+ Internet: adilger at enel.ucalgary.ca
+ Web: http://www-mddsp.enel.ucalgary.ca/People/adilger/
+
+-Guy Eric Schalnat (original author and former maintainer, 1995-1996)
+ (formerly of Group 42, Inc)
+ Internet: gschal at infinet.com
diff --git a/src/libpng/png.c b/src/libpng/png.c
index 9665c2c1c..8aa4131ab 100644
--- a/src/libpng/png.c
+++ b/src/libpng/png.c
@@ -1,7 +1,7 @@
/* png.c - location for general purpose libpng functions
*
- * Last changed in libpng 1.2.17 May 15, 2007
+ * Last changed in libpng 1.2.19 August 18, 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)
@@ -13,20 +13,20 @@
#include "png.h"
/* Generate a compiler error if there is an old png.h in the search path. */
-typedef version_1_2_18 Your_png_h_is_not_version_1_2_18;
+typedef version_1_2_19 Your_png_h_is_not_version_1_2_19;
/* 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,32 @@ 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};
+PNG_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};
+#if defined(PNG_HAVE_MMX_COMBINE_ROW) || defined(PNG_OPTIMIZED_CODE_SUPPORTED)
+PNG_CONST int FARDATA png_pass_width[] = {8, 4, 4, 2, 2, 1, 1};
#endif
/* 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 */
@@ -134,7 +134,7 @@ png_sig_cmp(png_bytep sig, png_size_t start, png_size_t num_to_check)
#if defined(PNG_1_0_X) || defined(PNG_1_2_X)
/* (Obsolete) function to check signature bytes. It does not allow one
* to check a partial signature. This function might be removed in the
- * future - use png_sig_cmp(). Returns true (nonzero) if the file is a PNG.
+ * future - use png_sig_cmp(). Returns true (nonzero) if the file is PNG.
*/
int PNGAPI
png_check_sig(png_bytep sig, int num)
@@ -674,7 +674,7 @@ png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime)
#ifdef USE_FAR_KEYWORD
{
char near_time_buf[29];
- 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);
@@ -682,7 +682,7 @@ png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime)
29*png_sizeof(char));
}
#else
- 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);
@@ -692,25 +692,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.2.18 - May 15, 2007\n\
+ png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
+ return ((png_charp) "\n libpng version 1.2.19 - August 18, 2007\n\
Copyright (c) 1998-2007 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
@@ -725,27 +716,70 @@ 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
+#ifdef PNG_READ_SUPPORTED
+# ifdef PNG_USE_PNGGCCRD
+# ifdef __x86_64__
+# ifdef __PIC__
+ " (PNGGCRD x86_64, PIC)\n"
+# else
+# ifdef PNG_THREAD_UNSAFE_OK
+ " (PNGGCRD x86_64, Thread unsafe)\n"
+# else
+ " (PNGGCRD x86_64, Thread safe)\n"
+# endif
+# endif
+# else
+# ifdef PNG_THREAD_UNSAFE_OK
+ " (PNGGCRD, Thread unsafe)\n"
+# else
+ " (PNGGCRD, Thread safe)\n"
+# endif
+# endif
+# else
+# ifdef PNG_USE_PNGVCRD
+# ifdef __x86_64__
+ " (x86_64 PNGVCRD)\n"
+# else
+ " (PNGVCRD)\n"
+# endif
+# else
+# ifdef __x86_64__
+# ifdef PNG_OPTIMIZED_CODE_SUPPORTED
+ " (x86_64 OPTIMIZED)\n"
+# else
+ " (x86_64 NOT OPTIMIZED)\n"
+# endif
+# else
+# ifdef PNG_OPTIMIZED_CODE_SUPPORTED
+ " (OPTIMIZED)\n"
+# else
+ " (NOT OPTIMIZED)\n"
+# endif
+# endif
+# endif
+# endif
+#else
+ " (NO READ SUPPORT)\n"
+#endif
+ );
}
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
@@ -756,7 +790,7 @@ 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)
@@ -843,8 +877,8 @@ png_mmx_support(void)
return -1;
}
#endif
-#endif /* PNG_1_0_X && PNG_ASSEMBLER_CODE_SUPPORTED */
-#endif /* PNG_READ_SUPPORTED */
+#endif /* PNG_1_0_X */
+#endif /* PNG_READ_SUPPORTED && PNG_ASSEMBLER_CODE_SUPPORTED */
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
#ifdef PNG_SIZE_T
diff --git a/src/libpng/png.h b/src/libpng/png.h
index 1c4f56fad..04f786d45 100644
--- a/src/libpng/png.h
+++ b/src/libpng/png.h
@@ -1,7 +1,7 @@
/* png.h - header file for PNG reference library
*
- * libpng version 1.2.18 - May 15, 2007
+ * libpng version 1.2.19 - August 18, 2007
* Copyright (c) 1998-2007 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.)
@@ -9,7 +9,7 @@
* 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.2.18 - May 15, 2007: Glenn
+ * libpng versions 0.97, January 1998, through 1.2.19 - August 18, 2007: Glenn
* See also "Contributing Authors", below.
*
* Note about libpng version numbers:
@@ -150,6 +150,11 @@
* 1.2.17 13 10217 12.so.0.17[.0]
* 1.0.26 10 10026 10.so.0.26[.0]
* 1.2.18 13 10218 12.so.0.18[.0]
+ * 1.2.19beta1-31 13 10219 12.so.0.19[.0]
+ * 1.0.27rc1-6 10 10027 10.so.0.27[.0]
+ * 1.2.19rc1-6 13 10219 12.so.0.19[.0]
+ * 1.0.27 10 10027 10.so.0.27[.0]
+ * 1.2.19 13 10219 12.so.0.19[.0]
*
* Henceforth the source version will match the shared-library major
* and minor numbers; the shared-library major version number will be
@@ -179,7 +184,7 @@
* If you modify libpng you may insert additional notices immediately following
* this sentence.
*
- * libpng versions 1.2.6, August 15, 2004, through 1.2.18, May 15, 2007, are
+ * libpng versions 1.2.6, August 15, 2004, through 1.2.19, August 18, 2007, 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:
@@ -291,13 +296,13 @@
* Y2K compliance in libpng:
* =========================
*
- * May 15, 2007
+ * August 18, 2007
*
* 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.2.18 are Y2K compliant. It is my belief that earlier
+ * upward through 1.2.19 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
@@ -353,9 +358,9 @@
*/
/* Version information for png.h - this should match the version in png.c */
-#define PNG_LIBPNG_VER_STRING "1.2.18"
+#define PNG_LIBPNG_VER_STRING "1.2.19"
#define PNG_HEADER_VERSION_STRING \
- " libpng version 1.2.18 - May 15, 2007 (header)\n"
+ " libpng version 1.2.19 - August 18, 2007\n"
#define PNG_LIBPNG_VER_SONUM 0
#define PNG_LIBPNG_VER_DLLNUM 13
@@ -363,7 +368,7 @@
/* These should match the first 3 components of PNG_LIBPNG_VER_STRING: */
#define PNG_LIBPNG_VER_MAJOR 1
#define PNG_LIBPNG_VER_MINOR 2
-#define PNG_LIBPNG_VER_RELEASE 18
+#define PNG_LIBPNG_VER_RELEASE 19
/* This should match the numeric part of the final component of
* PNG_LIBPNG_VER_STRING, omitting any leading zero: */
@@ -391,11 +396,11 @@
* Versions 0.7 through 1.0.0 were in the range 0 to 100 here (only
* version 1.0.0 was mis-numbered 100 instead of 10000). From
* version 1.0.1 it's xxyyzz, where x=major, y=minor, z=release */
-#define PNG_LIBPNG_VER 10218 /* 1.2.18 */
+#define PNG_LIBPNG_VER 10219 /* 1.2.19 */
#ifndef PNG_VERSION_INFO_ONLY
/* include the compression library's header */
-#include "..\zlib\zlib.h"
+#include "zlib.h"
#endif
/* include all user configurable info, including optional assembler routines */
@@ -479,7 +484,7 @@ extern "C" {
* the version above.
*/
#ifdef PNG_USE_GLOBAL_ARRAYS
-PNG_EXPORT_VAR (const char) png_libpng_ver[18];
+PNG_EXPORT_VAR (PNG_CONST char) png_libpng_ver[18];
/* need room for 99.99.99beta99z */
#else
#define png_libpng_ver png_get_header_ver(NULL)
@@ -488,17 +493,17 @@ PNG_EXPORT_VAR (const char) png_libpng_ver[18];
#ifdef PNG_USE_GLOBAL_ARRAYS
/* This was removed in version 1.0.5c */
/* Structures to facilitate easy interlacing. See png.c for more details */
-PNG_EXPORT_VAR (const int FARDATA) png_pass_start[7];
-PNG_EXPORT_VAR (const int FARDATA) png_pass_inc[7];
-PNG_EXPORT_VAR (const int FARDATA) png_pass_ystart[7];
-PNG_EXPORT_VAR (const int FARDATA) png_pass_yinc[7];
-PNG_EXPORT_VAR (const int FARDATA) png_pass_mask[7];
-PNG_EXPORT_VAR (const int FARDATA) png_pass_dsp_mask[7];
-#ifdef PNG_USE_PNGGCCRD
-PNG_EXPORT_VAR (const int FARDATA) png_pass_width[7];
+PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_start[7];
+PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_inc[7];
+PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_ystart[7];
+PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_yinc[7];
+PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_mask[7];
+PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_dsp_mask[7];
+#if defined(PNG_HAVE_MMX_COMBINE_ROW) || defined(PNG_OPTIMIZED_CODE_SUPPORTED)
+PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_width[7];
#endif
/* This isn't currently used. If you need it, see png.c for more details.
-PNG_EXPORT_VAR (const int FARDATA) png_pass_height[7];
+PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_height[7];
*/
#endif
@@ -1352,7 +1357,7 @@ struct png_struct_def
png_byte filter_type;
#endif
-#if defined(PNG_1_0_X) || (defined(PNG_DEBUG) && defined(PNG_USE_PNGGCCRD))
+#if defined(PNG_1_0_X)
/* New member added in libpng-1.0.10, ifdef'ed out in 1.2.0 */
png_uint_32 row_buf_size;
#endif
@@ -1406,7 +1411,7 @@ struct png_struct_def
/* 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_2_18;
+typedef png_structp version_1_2_19;
typedef png_struct FAR * FAR * png_structpp;
@@ -2062,13 +2067,17 @@ extern PNG_EXPORT(void,png_error) PNGARG((png_structp png_ptr,
extern PNG_EXPORT(void,png_chunk_error) PNGARG((png_structp png_ptr,
png_const_charp error_message));
+#ifndef PNG_NO_WARNINGS
/* Non-fatal error in libpng. Can continue, but may have a problem. */
extern PNG_EXPORT(void,png_warning) PNGARG((png_structp png_ptr,
png_const_charp warning_message));
+#ifdef PNG_READ_SUPPORTED
/* Non-fatal error in libpng, chunk name is prepended to message. */
extern PNG_EXPORT(void,png_chunk_warning) PNGARG((png_structp png_ptr,
png_const_charp warning_message));
+#endif /* PNG_READ_SUPPORTED */
+#endif /* PNG_NO_WARNINGS */
/* The png_set_<chunk> functions are for storing values in the png_info_struct.
* Similarly, the png_get_<chunk> calls are used to read values from the
@@ -2490,10 +2499,6 @@ extern PNG_EXPORT(void, png_write_png) PNGARG((png_structp png_ptr,
#define png_debug2(l, m, p1, p2)
#endif
-#if 0
-extern PNG_EXPORT(png_bytep,png_sig_bytes) PNGARG((void));
-#endif
-
extern PNG_EXPORT(png_charp,png_get_copyright) PNGARG((png_structp png_ptr));
extern PNG_EXPORT(png_charp,png_get_header_ver) PNGARG((png_structp png_ptr));
extern PNG_EXPORT(png_charp,png_get_header_version) PNGARG((png_structp png_ptr));
@@ -2817,11 +2822,8 @@ extern PNG_EXPORT(void,png_save_uint_16)
#if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
/* place to hold the signature string for a PNG file. */
#ifdef PNG_USE_GLOBAL_ARRAYS
- PNG_EXPORT_VAR (const png_byte FARDATA) png_sig[8];
+ PNG_EXPORT_VAR (PNG_CONST png_byte FARDATA) png_sig[8];
#else
-#if 0
-#define png_sig png_sig_bytes(NULL)
-#endif
#endif
#endif /* PNG_NO_EXTERN */
@@ -2829,50 +2831,50 @@ extern PNG_EXPORT(void,png_save_uint_16)
* define the name here, and add an invocation of the macro in png.c and
* wherever it's needed.
*/
-#define PNG_IHDR const png_byte png_IHDR[5] = { 73, 72, 68, 82, '\0'}
-#define PNG_IDAT const png_byte png_IDAT[5] = { 73, 68, 65, 84, '\0'}
-#define PNG_IEND const png_byte png_IEND[5] = { 73, 69, 78, 68, '\0'}
-#define PNG_PLTE const png_byte png_PLTE[5] = { 80, 76, 84, 69, '\0'}
-#define PNG_bKGD const png_byte png_bKGD[5] = { 98, 75, 71, 68, '\0'}
-#define PNG_cHRM const png_byte png_cHRM[5] = { 99, 72, 82, 77, '\0'}
-#define PNG_gAMA const png_byte png_gAMA[5] = {103, 65, 77, 65, '\0'}
-#define PNG_hIST const png_byte png_hIST[5] = {104, 73, 83, 84, '\0'}
-#define PNG_iCCP const png_byte png_iCCP[5] = {105, 67, 67, 80, '\0'}
-#define PNG_iTXt const png_byte png_iTXt[5] = {105, 84, 88, 116, '\0'}
-#define PNG_oFFs const png_byte png_oFFs[5] = {111, 70, 70, 115, '\0'}
-#define PNG_pCAL const png_byte png_pCAL[5] = {112, 67, 65, 76, '\0'}
-#define PNG_sCAL const png_byte png_sCAL[5] = {115, 67, 65, 76, '\0'}
-#define PNG_pHYs const png_byte png_pHYs[5] = {112, 72, 89, 115, '\0'}
-#define PNG_sBIT const png_byte png_sBIT[5] = {115, 66, 73, 84, '\0'}
-#define PNG_sPLT const png_byte png_sPLT[5] = {115, 80, 76, 84, '\0'}
-#define PNG_sRGB const png_byte png_sRGB[5] = {115, 82, 71, 66, '\0'}
-#define PNG_tEXt const png_byte png_tEXt[5] = {116, 69, 88, 116, '\0'}
-#define PNG_tIME const png_byte png_tIME[5] = {116, 73, 77, 69, '\0'}
-#define PNG_tRNS const png_byte png_tRNS[5] = {116, 82, 78, 83, '\0'}
-#define PNG_zTXt const png_byte png_zTXt[5] = {122, 84, 88, 116, '\0'}
+#define PNG_IHDR png_byte png_IHDR[5] = { 73, 72, 68, 82, '\0'}
+#define PNG_IDAT png_byte png_IDAT[5] = { 73, 68, 65, 84, '\0'}
+#define PNG_IEND png_byte png_IEND[5] = { 73, 69, 78, 68, '\0'}
+#define PNG_PLTE png_byte png_PLTE[5] = { 80, 76, 84, 69, '\0'}
+#define PNG_bKGD png_byte png_bKGD[5] = { 98, 75, 71, 68, '\0'}
+#define PNG_cHRM png_byte png_cHRM[5] = { 99, 72, 82, 77, '\0'}
+#define PNG_gAMA png_byte png_gAMA[5] = {103, 65, 77, 65, '\0'}
+#define PNG_hIST png_byte png_hIST[5] = {104, 73, 83, 84, '\0'}
+#define PNG_iCCP png_byte png_iCCP[5] = {105, 67, 67, 80, '\0'}
+#define PNG_iTXt png_byte png_iTXt[5] = {105, 84, 88, 116, '\0'}
+#define PNG_oFFs png_byte png_oFFs[5] = {111, 70, 70, 115, '\0'}
+#define PNG_pCAL png_byte png_pCAL[5] = {112, 67, 65, 76, '\0'}
+#define PNG_sCAL png_byte png_sCAL[5] = {115, 67, 65, 76, '\0'}
+#define PNG_pHYs png_byte png_pHYs[5] = {112, 72, 89, 115, '\0'}
+#define PNG_sBIT png_byte png_sBIT[5] = {115, 66, 73, 84, '\0'}
+#define PNG_sPLT png_byte png_sPLT[5] = {115, 80, 76, 84, '\0'}
+#define PNG_sRGB png_byte png_sRGB[5] = {115, 82, 71, 66, '\0'}
+#define PNG_tEXt png_byte png_tEXt[5] = {116, 69, 88, 116, '\0'}
+#define PNG_tIME png_byte png_tIME[5] = {116, 73, 77, 69, '\0'}
+#define PNG_tRNS png_byte png_tRNS[5] = {116, 82, 78, 83, '\0'}
+#define PNG_zTXt png_byte png_zTXt[5] = {122, 84, 88, 116, '\0'}
#ifdef PNG_USE_GLOBAL_ARRAYS
-PNG_EXPORT_VAR (const png_byte FARDATA) png_IHDR[5];
-PNG_EXPORT_VAR (const png_byte FARDATA) png_IDAT[5];
-PNG_EXPORT_VAR (const png_byte FARDATA) png_IEND[5];
-PNG_EXPORT_VAR (const png_byte FARDATA) png_PLTE[5];
-PNG_EXPORT_VAR (const png_byte FARDATA) png_bKGD[5];
-PNG_EXPORT_VAR (const png_byte FARDATA) png_cHRM[5];
-PNG_EXPORT_VAR (const png_byte FARDATA) png_gAMA[5];
-PNG_EXPORT_VAR (const png_byte FARDATA) png_hIST[5];
-PNG_EXPORT_VAR (const png_byte FARDATA) png_iCCP[5];
-PNG_EXPORT_VAR (const png_byte FARDATA) png_iTXt[5];
-PNG_EXPORT_VAR (const png_byte FARDATA) png_oFFs[5];
-PNG_EXPORT_VAR (const png_byte FARDATA) png_pCAL[5];
-PNG_EXPORT_VAR (const png_byte FARDATA) png_sCAL[5];
-PNG_EXPORT_VAR (const png_byte FARDATA) png_pHYs[5];
-PNG_EXPORT_VAR (const png_byte FARDATA) png_sBIT[5];
-PNG_EXPORT_VAR (const png_byte FARDATA) png_sPLT[5];
-PNG_EXPORT_VAR (const png_byte FARDATA) png_sRGB[5];
-PNG_EXPORT_VAR (const png_byte FARDATA) png_tEXt[5];
-PNG_EXPORT_VAR (const png_byte FARDATA) png_tIME[5];
-PNG_EXPORT_VAR (const png_byte FARDATA) png_tRNS[5];
-PNG_EXPORT_VAR (const png_byte FARDATA) png_zTXt[5];
+PNG_EXPORT_VAR (png_byte FARDATA) png_IHDR[5];
+PNG_EXPORT_VAR (png_byte FARDATA) png_IDAT[5];
+PNG_EXPORT_VAR (png_byte FARDATA) png_IEND[5];
+PNG_EXPORT_VAR (png_byte FARDATA) png_PLTE[5];
+PNG_EXPORT_VAR (png_byte FARDATA) png_bKGD[5];
+PNG_EXPORT_VAR (png_byte FARDATA) png_cHRM[5];
+PNG_EXPORT_VAR (png_byte FARDATA) png_gAMA[5];
+PNG_EXPORT_VAR (png_byte FARDATA) png_hIST[5];
+PNG_EXPORT_VAR (png_byte FARDATA) png_iCCP[5];
+PNG_EXPORT_VAR (png_byte FARDATA) png_iTXt[5];
+PNG_EXPORT_VAR (png_byte FARDATA) png_oFFs[5];
+PNG_EXPORT_VAR (png_byte FARDATA) png_pCAL[5];
+PNG_EXPORT_VAR (png_byte FARDATA) png_sCAL[5];
+PNG_EXPORT_VAR (png_byte FARDATA) png_pHYs[5];
+PNG_EXPORT_VAR (png_byte FARDATA) png_sBIT[5];
+PNG_EXPORT_VAR (png_byte FARDATA) png_sPLT[5];
+PNG_EXPORT_VAR (png_byte FARDATA) png_sRGB[5];
+PNG_EXPORT_VAR (png_byte FARDATA) png_tEXt[5];
+PNG_EXPORT_VAR (png_byte FARDATA) png_tIME[5];
+PNG_EXPORT_VAR (png_byte FARDATA) png_tRNS[5];
+PNG_EXPORT_VAR (png_byte FARDATA) png_zTXt[5];
#endif /* PNG_USE_GLOBAL_ARRAYS */
#if defined(PNG_1_0_X) || defined (PNG_1_2_X)
diff --git a/src/libpng/pngconf.h b/src/libpng/pngconf.h
index a5047325f..43dfe04c4 100644
--- a/src/libpng/pngconf.h
+++ b/src/libpng/pngconf.h
@@ -1,7 +1,7 @@
/* pngconf.h - machine configurable file for libpng
*
- * libpng version 1.2.18 - May 15, 2007
+ * libpng version 1.2.19 - August 18, 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)
@@ -75,6 +75,14 @@
/* End of material added to libpng-1.2.8 */
+/* Added at libpng-1.2.19 */
+#ifndef PNG_NO_WARN_UNINITIALIZED_ROW
+# ifndef PNG_WARN_UNINITIALIZED_ROW
+# define PNG_WARN_UNINITIALIZED_ROW 1 /* 0: warning; 1: error */
+# endif
+#endif
+/* End of material added at libpng-1.2.19 */
+
/* This is the size of the compression buffer, and thus the size of
* an IDAT chunk. Make this whatever size you feel is best for your
* machine. One of these will be allocated per png_struct. When this
@@ -276,6 +284,7 @@
# define PNGARG(arglist) arglist
#endif /* _NO_PROTO */
+
#endif /* OF */
#endif /* PNGARG */
@@ -594,16 +603,16 @@
#endif /* PNG_READ_TRANSFORMS_SUPPORTED */
#if !defined(PNG_NO_PROGRESSIVE_READ) && \
- !defined(PNG_PROGRESSIVE_READ_NOT_SUPPORTED) /* if you don't do progressive */
-# define PNG_PROGRESSIVE_READ_SUPPORTED /* reading. This is not talking */
-#endif /* about interlacing capability! You'll */
- /* still have interlacing unless you change the following line: */
+ !defined(PNG_PROGRESSIVE_READ_NOT_SUPPORTED) /* if you don't do progressive */
+# define PNG_PROGRESSIVE_READ_SUPPORTED /* reading. This is not talking */
+#endif /* about interlacing capability! You'll */
+ /* still have interlacing unless you change the following line: */
-#define PNG_READ_INTERLACING_SUPPORTED /* required for PNG-compliant decoders */
+#define PNG_READ_INTERLACING_SUPPORTED /* required in PNG-compliant decoders */
#ifndef PNG_NO_READ_COMPOSITE_NODIV
# ifndef PNG_NO_READ_COMPOSITED_NODIV /* libpng-1.0.x misspelling */
-# define PNG_READ_COMPOSITE_NODIV_SUPPORTED /* well tested on Intel, SGI */
+# define PNG_READ_COMPOSITE_NODIV_SUPPORTED /* well tested on Intel, SGI */
# endif
#endif
@@ -723,35 +732,46 @@
/* 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_ASSEMBLER_CODE disables use of all assembler code,
+ * and removes several functions from 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.
+ * When MMX code is off, then optimized C replacement functions are used,
+ * if PNG_NO_OPTIMIZED_CODE is not enabled. This was added in version
+ * 1.2.19.
*/
+
+#if defined(PNG_READ_SUPPORTED) && !defined(PNG_NO_OPTIMIZED_CODE)
+# ifndef PNG_OPTIMIZED_CODE_SUPPORTED
+# define PNG_OPTIMIZED_CODE_SUPPORTED
+# endif
+#endif
+
#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__)
+
+# if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
# define PNG_MMX_CODE_SUPPORTED
# endif
-# if !defined(PNG_USE_PNGGCCRD) && !defined(PNG_NO_MMX_CODE) && \
- !defined(PNG_USE_PNGVCRD) && defined(__MMX__)
+
+# if !defined(PNG_USE_PNGVCRD) && defined(PNG_MMX_CODE_SUPPORTED) && \
+ defined(_MSC_VER)
+# define PNG_USE_PNGVCRD
+# endif
+
+# if !defined(PNG_USE_PNGGCCRD) && defined(PNG_MMX_CODE_SUPPORTED) && \
+ !defined(PNG_USE_PNGVCRD)
# define PNG_USE_PNGGCCRD
+ /* 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
+ */
# 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
-*/
+#endif
#if !defined(PNG_1_0_X)
#if !defined(PNG_NO_USER_MEM) && !defined(PNG_USER_MEM_SUPPORTED)
@@ -1273,7 +1293,8 @@ typedef z_stream FAR * png_zstreamp;
* but might be required for some pre-1.0.5c applications.
*/
#if !defined(PNG_USE_LOCAL_ARRAYS) && !defined(PNG_USE_GLOBAL_ARRAYS)
-# if defined(PNG_NO_GLOBAL_ARRAYS) || (defined(__GNUC__) && defined(PNG_DLL))
+# if defined(PNG_NO_GLOBAL_ARRAYS) || \
+ (defined(__GNUC__) && defined(PNG_DLL)) || defined(_MSC_VER)
# define PNG_USE_LOCAL_ARRAYS
# else
# define PNG_USE_GLOBAL_ARRAYS
@@ -1410,6 +1431,7 @@ typedef z_stream FAR * png_zstreamp;
# define NOCHECK 0
# define CVT_PTR(ptr) (png_far_to_near(png_ptr,ptr,CHECK))
# define CVT_PTR_NOCHECK(ptr) (png_far_to_near(png_ptr,ptr,NOCHECK))
+# define png_snprintf _fsnprintf /* Added to v 1.2.19 */
# define png_strcpy _fstrcpy
# define png_strncpy _fstrncpy /* Added to v 1.2.6 */
# define png_strlen _fstrlen
@@ -1419,6 +1441,27 @@ typedef z_stream FAR * png_zstreamp;
#else /* use the usual functions */
# define CVT_PTR(ptr) (ptr)
# define CVT_PTR_NOCHECK(ptr) (ptr)
+# 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
# define png_strcpy strcpy
# define png_strncpy strncpy /* Added to v 1.2.6 */
# define png_strlen strlen
@@ -1440,39 +1483,48 @@ typedef z_stream FAR * png_zstreamp;
/* Prior to libpng-1.0.9, this block was in pngasmrd.h */
#if defined(PNG_INTERNAL)
-/* These are the default thresholds before the MMX code kicks in; if either
- * rowbytes or bitdepth is below the threshold, plain C code is used. These
- * can be overridden at runtime via the png_set_mmx_thresholds() call in
- * libpng 1.2.0 and later. The values below were chosen by Intel.
- */
-
-#ifndef PNG_MMX_ROWBYTES_THRESHOLD_DEFAULT
-# define PNG_MMX_ROWBYTES_THRESHOLD_DEFAULT 128 /* >= */
-#endif
-#ifndef PNG_MMX_BITDEPTH_THRESHOLD_DEFAULT
-# define PNG_MMX_BITDEPTH_THRESHOLD_DEFAULT 9 /* >= */
-#endif
-
-/* Set this in the makefile for VC++ on Pentium, not here. */
-/* Platform must be Pentium. Makefile must assemble and load pngvcrd.c .
- * MMX will be detected at run time and used if present.
- */
-#ifdef PNG_USE_PNGVCRD
-# define PNG_HAVE_MMX_COMBINE_ROW
-# define PNG_HAVE_MMX_READ_INTERLACE
-# define PNG_HAVE_MMX_READ_FILTER_ROW
-#endif
-
-/* Set this in the makefile for gcc/as on Pentium, not here. */
-/* Platform must be Pentium. Makefile must assemble and load pnggccrd.c .
- * MMX will be detected at run time and used if present.
- */
-#ifdef PNG_USE_PNGGCCRD
-# define PNG_HAVE_MMX_COMBINE_ROW
-# define PNG_HAVE_MMX_READ_INTERLACE
-# define PNG_HAVE_MMX_READ_FILTER_ROW
-#endif
-/* - see pnggccrd.c for info about what is currently enabled */
+#if defined(PNG_USE_PNGGCCRD) || defined(PNG_USE_PNGVCRD)
+ /* Platform must be Pentium. Makefile must assemble and load
+ * pnggccrd.c or pngvcrd.c. MMX will be detected at run time and
+ * used if present.
+ */
+# ifndef PNG_NO_MMX_COMBINE_ROW
+# define PNG_HAVE_MMX_COMBINE_ROW
+# endif
+# ifndef PNG_NO_MMX_READ_INTERLACE
+# define PNG_HAVE_MMX_READ_INTERLACE
+# endif
+# ifndef PNG_NO_MMX_READ_FILTER_ROW
+# define PNG_HAVE_MMX_READ_FILTER_ROW
+# ifndef PNG_NO_MMX_FILTER_SUB
+# define PNG_MMX_READ_FILTER_SUB_SUPPORTED
+# endif
+# if !(defined(__GNUC__) && defined(__x86_64__) && (__GNUC__ < 4))
+ /* work around 64-bit gcc compiler bugs in gcc-3.x */
+# ifndef PNG_NO_MMX_FILTER_UP
+# define PNG_MMX_READ_FILTER_UP_SUPPORTED
+# endif
+# ifndef PNG_NO_MMX_FILTER_AVG
+# define PNG_MMX_READ_FILTER_AVG_SUPPORTED
+# endif
+# ifndef PNG_NO_MMX_FILTER_PAETH
+# define PNG_MMX_READ_FILTER_PAETH_SUPPORTED
+# endif
+# endif /* !((__x86_64__) && (GNUC < 4)) */
+# endif
+ /* These are the default thresholds before the MMX code kicks in; if either
+ * rowbytes or bitdepth is below the threshold, plain C code is used. These
+ * can be overridden at runtime via the png_set_mmx_thresholds() call in
+ * libpng 1.2.0 and later. The values below were chosen by Intel.
+ */
+# ifndef PNG_MMX_ROWBYTES_THRESHOLD_DEFAULT
+# define PNG_MMX_ROWBYTES_THRESHOLD_DEFAULT 128 /* >= */
+# endif
+# ifndef PNG_MMX_BITDEPTH_THRESHOLD_DEFAULT
+# define PNG_MMX_BITDEPTH_THRESHOLD_DEFAULT 9 /* >= */
+# endif
+#endif /* PNG_USE_PNGGCCRD || PNG_USE_PNGVCRD */
+/* - see pngvcrd.c or pnggccrd.c for info about what is currently enabled */
#endif /* PNG_INTERNAL */
#endif /* PNG_READ_SUPPORTED */
diff --git a/src/libpng/pngerror.c b/src/libpng/pngerror.c
index f50f65344..b1d5fbe78 100644
--- a/src/libpng/pngerror.c
+++ b/src/libpng/pngerror.c
@@ -1,9 +1,9 @@
/* pngerror.c - stub functions for i/o and memory allocation
*
- * Last changed in libpng 1.2.13 November 13, 2006
+ * Last changed in libpng 1.2.19 August 18, 2007
* For conditions of distribution and use, see copyright notice in png.h
- * Copyright (c) 1998-2006 Glenn Randers-Pehrson
+ * Copyright (c) 1998-2007 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.)
*
@@ -20,9 +20,11 @@
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,
@@ -76,6 +78,7 @@ png_error(png_structp png_ptr, png_const_charp error_message)
png_default_error(png_ptr, error_message);
}
+#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
@@ -105,6 +108,8 @@ png_warning(png_structp png_ptr, png_const_charp warning_message)
else
png_default_warning(png_ptr, warning_message+offset);
}
+#endif /* PNG_NO_WARNINGS */
+
/* These utilities are used internally to build an error message that relates
* to the current chunk. The chunk name comes from png_ptr->chunk_name,
@@ -113,7 +118,7 @@ png_warning(png_structp png_ptr, png_const_charp warning_message)
* if the character is invalid.
*/
#define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
-const static PNG_CONST char png_digit[16] = {
+static PNG_CONST char png_digit[16] = {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'A', 'B', 'C', 'D', 'E', 'F'
};
@@ -151,6 +156,7 @@ png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp
}
}
+#ifdef PNG_READ_SUPPORTED
void PNGAPI
png_chunk_error(png_structp png_ptr, png_const_charp error_message)
{
@@ -164,6 +170,7 @@ png_chunk_error(png_structp png_ptr, png_const_charp error_message)
}
}
+#ifndef PNG_NO_WARNINGS
void PNGAPI
png_chunk_warning(png_structp png_ptr, png_const_charp warning_message)
{
@@ -176,6 +183,9 @@ png_chunk_warning(png_structp png_ptr, png_const_charp warning_message)
png_warning(png_ptr, msg);
}
}
+#endif /* PNG_NO_WARNINGS */
+
+#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
@@ -217,7 +227,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,png_sizeof(jmp_buf));
+ png_memcpy(jmpbuf, png_ptr->jmpbuf, png_sizeof(jmp_buf));
longjmp(jmpbuf, 1);
}
# else
@@ -228,12 +238,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
@@ -267,14 +276,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
diff --git a/src/libpng/pnggccrd.c b/src/libpng/pnggccrd.c
index fab523c0b..f63867cd2 100644
--- a/src/libpng/pnggccrd.c
+++ b/src/libpng/pnggccrd.c
@@ -1,51 +1,50 @@
/* 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.
+ * For Intel/AMD x86 or x86-64 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.2.15 January 5, 2007
+ * Last changed in libpng 1.2.19 August 18, 2007
* For conditions of distribution and use, see copyright notice in png.h
+ * Copyright (c) 1998 Intel Corporation
+ * Copyright (c) 1999-2002,2007 Greg Roelofs
* 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
+ * References:
*
- * ftp://ftp.simtel.net/pub/simtelnet/gnu/djgpp/v2gnu/bnu281b.zip
+ * http://www.intel.com/drg/pentiumII/appnotes/916/916.htm
+ * http://www.intel.com/drg/pentiumII/appnotes/923/923.htm
+ * [Intel's performance analysis of the MMX vs. non-MMX code;
+ * moved/deleted as of 2006, but text and some graphs still
+ * available via WayBack Machine at archive.org]
*
- * (or a later version in the same directory). For Linux, check your
- * distribution's web site(s) or try these links:
+ * http://www.ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html
+ * http://sam.zoy.org/blog/2007-04-13-shlib-with-non-pic-code-have-inline-assembly-and-pic-mix-well
+ * http://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html
+ * http://gcc.gnu.org/onlinedocs/gcc/Variable-Attributes.html
+ * http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html
+ * AMD64 Architecture Programmer's Manual, volumes 1 and 5
+ * [http://www.amd.com/us-en/Processors/TechnicalResources/0,,30_182_739_7044,00.html]
+ * Intel 64 and IA-32 Software Developer's Manuals
+ * [http://developer.intel.com/products/processor/manuals/]
*
- * 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
+ * png_read_filter_row_mmx_*() were converted in place with intel2gas 1.3.1:
*
- * For other platforms, see the main GNU site:
+ * intel2gas -mdI pnggccrd.c.partially-msvc -o pnggccrd.c
*
- * ftp://ftp.gnu.org/pub/gnu/binutils/
+ * and then cleaned up by hand. See http://hermes.terminal.at/intel2gas/ .
*
- * Version 2.5.2l.15 is definitely too old...
+ * NOTE: A sufficiently recent version of GNU as (or as.exe under DOS/Windows)
+ * is required to assemble the newer asm instructions such as movq. (Version
+ * 2.5.2l.15 is definitely too old.) See ftp://ftp.gnu.org/pub/gnu/binutils/ .
*/
/*
- * TEMPORARY PORTING NOTES AND CHANGELOG (mostly by Greg Roelofs)
- * =====================================
+ * PORTING NOTES AND CHANGELOG (mostly by Greg Roelofs)
+ * ===========================
*
* 19991006:
* - fixed sign error in post-MMX cleanup code (16- & 32-bit cases)
@@ -56,7 +55,7 @@
* - 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)
+ * (only width_mmx case) (near line 2335)
* 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
@@ -75,8 +74,8 @@
* 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).
+ * was lowest in memory (i.e., corresponding to a left pixel)
+ * and b7 is the byte that was highest (i.e., a right pixel).
*
* 19991016:
* - Brennan's Guide notwithstanding, gcc under Linux does *not*
@@ -88,6 +87,10 @@
* defined within the scope of a single function, but both
* static and truly global (multi-module) variables work fine.
*
+ * 19991017:
+ * - replaced pixel_bytes in each png_memcpy() call with constant value for
+ * inlining (png_do_read_interlace() "non-MMX/modified C code" block)
+ *
* 19991023:
* - fixed png_combine_row() non-MMX replication bug (odd passes only?)
* - switched from string-concatenation-with-macros to cleaner method of
@@ -168,7 +171,7 @@
* 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.
+ * library. 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!
*
@@ -221,48 +224,249 @@
* 20010310:
* - fixed buffer-overrun bug in png_combine_row() C code (non-MMX)
*
+ * 20010808:
+ * - added PNG_THREAD_UNSAFE_OK around code using global variables [GR-P]
+ *
+ * 20011124:
+ * - fixed missing save of Eflag in png_mmx_support() [Maxim Sobolev]
+ *
* 20020304:
* - eliminated incorrect use of width_mmx in pixel_bytes == 8 case
*
+ * 20020407:
+ * - fixed insufficient preservation of ebx register [Sami Farin]
+ *
* 20040724:
- * - more tinkering with clobber list at lines 4529 and 5033, to get
- * it to compile on gcc-3.4.
+ * - more tinkering with clobber list at lines 4529 and 5033 to get it to
+ * compile with gcc 3.4 [GR-P]
+ *
+ * 20040809:
+ * - added "rim" definitions for CONST4 and CONST6 [GR-P]
+ *
+ * 20060303:
+ * - added "OS2" to list of systems that don't need leading underscores [GR-P]
+ *
+ * 20060320:
+ * - made PIC-compliant [Christian Aichinger]
+ *
+ * 20070313:
+ * - finally applied Giuseppe Ghibò's 64-bit patch of 20060803 (completely
+ * overlooked Dylan Alex Simon's similar patch of 20060414, oops...)
+ *
+ * 20070524:
+ * - fixed link failure caused by asm-only variables being optimized out
+ * (identified by Dimitri of Trolltech) with __attribute__((used)), which
+ * also gets rid of warnings => nuked ugly png_squelch_warnings() hack
+ * - dropped redundant ifdef
+ * - moved png_mmx_support() back up where originally intended (as in
+ * pngvcrd.c), using __attribute__((noinline)) in extra prototype
+ *
+ * 20070527:
+ * - revised png_combine_row() to reuse mask in lieu of external _unmask
+ * - moved 32-bit (RGBA) case to top of png_combine_row(): most common
+ * - just about ready to give up on x86-64 -fPIC mode; can't even access 16
+ * _mask*_* constants without triggering link error on shared library:
+ * /usr/bin/ld: pnggccrd.pic.o: relocation R_X86_64_32S against `a local
+ * symbol' can not be used when making a shared object; recompile with
+ * -fPIC
+ * pnggccrd.pic.o: could not read symbols: Bad value
+ * ("objdump -x pnggccrd.pic.o | grep rodata" to verify)
+ * [might be able to work around by doing within assembly code whatever
+ * -fPIC does, but given problems to date, seems like long shot...]
+ * [relevant ifdefs: __x86_64__ && __PIC__ => C code only]
+ * - changed #if 0 to #ifdef PNG_CLOBBER_MMX_REGS_SUPPORTED in case gcc ever
+ * supports MMX regs (%mm0, etc.) in clobber list (not supported by gcc
+ * 2.7.2.3, 2.91.66 (egcs 1.1.2), 3.x, or 4.1.2)
+ *
+ * 20070603:
+ * - revised png_combine_row() to use @GOTPCREL(%%rip) addressing on _c64
+ * struct of _mask*_* constants for x86-64 -fPIC; see sam.zoy.org link
+ * above for details
+ * - moved _const4 and _const6 into _c64 struct, renamed to _amask5_3_0 and
+ * _amask7_1_0, respectively
+ * - can't figure out how to use _c64._mask*_* vars within asm code, so still
+ * need single variables for non-x86-64/-fPIC half :-(
+ * - replaced various __PIC__ ifdefs with *_GOT_ebx macros
+ * - moved _LBCarryMask and _HBClearMask into _c64 struct
+ * - conditionally replaced _p*temp variables with %r11d-%r13d (via p*_TEMP
+ * and CLOBBER_r1*d macros)
+ *
+ * 20070604:
+ * - replaced all _ActiveMask and _ActiveMaskEnd with new _amask*_*_* consts
+ * (_amask naming convention: numbers of 00-bytes, ff-bytes, 00-bytes)
+ * - _ActiveMask // (10) // avg/paeth/sub; read-only; consts; movq/pand
+ * 0x0000000000ffffffLL (bpp 3, avg) _amask5_3_0
+ * 0xffffffffffffffffLL (bpp 4, 6, avg) _amask0_8_0
+ * 0x000000000000ffffLL (bpp 2, avg) _amask6_2_0
+ * 0x0000000000ffffffLL (bpp 3, paeth) _amask5_3_0
+ * 0x00000000ffffffffLL (bpp 6, paeth) _amask4_4_0
+ * 0x00000000ffffffffLL (bpp 4, paeth) _amask4_4_0
+ * 0x00000000ffffffffLL (bpp 8, paeth) _amask4_4_0
+ * 0x0000ffffff000000LL (bpp 3, sub) _amask2_3_3
+ * 0x00000000ffff0000LL (bpp 2, sub) _amask4_2_2
+ * - _ActiveMaskEnd // (1) // paeth only; read-only; const; pand
+ * 0xffff000000000000LL (bpp 3, paeth) _amask0_2_6
+ * - changed all "#if defined(__x86_64__) // later // && defined(__PIC__)"
+ * lines to "#ifdef PNG_x86_64_USE_GOTPCREL" for easier/safer testing
+ *
+ * 20070605:
+ * - merged PNG_x86_64_USE_GOTPCREL, non-PNG_x86_64_USE_GOTPCREL code via
+ * *MASK* and LOAD/RESTORE macros
+ *
+ * 20070607:
+ * - replaced all constant instances of _ShiftBpp, _ShiftRem with immediates
+ * (still have two shared cases in avg, sub routines)
+ *
+ * 20070609:
+ * - replaced remaining instances of _ShiftBpp, _ShiftRem with immediates
+ * (split sub and avg 4/6-bpp cases into separate blocks)
+ * - fixed paeth bug due to clobbered r11/r12/r13 regs
+ *
+ * 20070610:
+ * - made global "_dif" variable (avg/paeth/sub routines) local again (now
+ * "diff"--see 19991120 entry above), using register constraints
+ * - note that %ebp in clobber list doesn't actually work, at least for 32-bit
+ * version and gcc 4.1.2; must save and restore manually. (Seems to work
+ * OK for 64-bit version and gcc 3.4.3, but gcc may not be using ebp/rbp
+ * in that case.)
+ * - started replacing direct _MMXLength accesses with register constraints
+ *
+ * 20070612:
+ * - continued replacing direct _MMXLength accesses with register constraints
+ *
+ * 20070613:
+ * - finished replacing direct _MMXLength accesses with register constraints;
+ * switched to local variable (and renamed back to MMXLength)
+ *
+ * 20070614:
+ * - fixed sub bpp = 1 bug
+ * - started replacing direct _FullLength accesses with register constraints
+ *
+ * 20070615:
+ * - fixed 64-bit paeth bpp 3 crash bug (misplaced LOAD_GOT_rbp)
+ * - fixed 64-bit paeth bpp 1/2 and cleanup-block crash bugs (misplaced
+ * RESTORE_r11_r12_r13)
+ * - slightly optimized avg/paeth cleanup blocks and paeth bpp 1/2 block
+ * (save/restore ebx only if needed)
+ * - continued replacing direct _FullLength accesses with register constraints
+ *
+ * 20070616:
+ * - finished replacing direct _FullLength accesses with register constraints
+ * (*ugly* conditional clobber-separator macros for avg and paeth, sigh)
+ *
+ * 20070618:
+ * - fixed misplaced PNG_THREAD_UNSAFE_OK endif (was missing LOAD_GOT_rbp/
+ * RESTORE_rbp in 32-bit thread-safe case)
+ * - changed all "ifdef *" to "if defined(*)" [GR-P]
+ *
+ * 20070619:
+ * - rearranged most bitdepth-related case statements to put most frequent
+ * cases at top (24-bit, 32-bit, 8-bit, rest)
+ *
+ * 20070623:
+ * - cleaned up png_debug() warnings/formatting
+ * - removed PNG_MMX_CODE_SUPPORTED ifdefs and added outer __GNUC__ ifdef
+ * (module no longer used by non-x86/non-GCC builds as of libpng 1.2.19)
+ * - removed single libpng-1.2.x PNG_DEBUG dependency on 1.0.x png_struct
+ * member (row_buf_size)
+ * - rearranged pass-related if-blocks in png_do_read_interlace() to put most
+ * frequent cases (4, 5) at top [GR-P suggestion]
+ *
+ * 20070624-29:
+ * - fixed 64-bit crash bug: pointers -> rsi/rdi, not esi/edi (switched to
+ * %0/%1/%2/%3/%4 notation; eliminated size suffixes from relevant add/
+ * inc/sub/mov instructions; changed dummy vars to pointers)
+ * - png_combine_row()
+ * - png_do_read_interlace()
+ * - png_read_filter_row_mmx_avg()
+ * - png_read_filter_row_mmx_paeth()
+ * - png_read_filter_row_mmx_sub()
+ * - png_read_filter_row_mmx_up()
+ * - NOTE: this fix makes use of the fact that modifying a 32-bit reg (e.g.,
+ * %%ebx) clears the top half of its corresponding 64-bit reg (%%rbx), so
+ * it's safe to mix 32-bit operations with 64-bit base/index addressing
+ * (see new PSI/PAX/PBX/PDX/PBP/etc. "pointer-register" macros); applies
+ * also to clobber lists
+ *
+ * 20070630:
+ * - cleaned up formatting, macros, minor png_read_filter_row_mmx_sub() 8-bpp
+ * register-usage inefficiency
+ * - fixed 32-bit png_do_read_interlace() bug (was using pointer size for
+ * 64-bit dummy values)
+ *
+ * 20070703:
+ * - added check for (manual) PIC macro to fix OpenBSD crash bug
+ *
+ * 20070717:
+ * - fixed 48-bit png_combine_row() bug (was acting like 32-bit): copy 6
+ * bytes per pixel, not 4, and use stride of 6, not 4, in the second loop
+ * of interlace processing of 48-bit pixels [GR-P]
+ *
+ * 20070722:
+ * - fixed 64-bit png_uint_32 bug with MMXLength/FullLength temp vars
+ *
+ * [still broken: tops of all row-filter blocks (input/output constraints);
+ * shows up on 64-bit dynamic (-fPIC) version with -O2, especially if debug-
+ * printfs enabled, but at right edge of odd-width images even if disabled]
+ *
*
* 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
+ * - fix final thread-unsafe code using stack vars and pointer? (paeth top,
+ * default, bottom only: default, bottom already 5 reg constraints; could
+ * replace bpp with pointer and group bpp/patemp/pbtemp/pctemp in array)
+ * - fix ebp/no-reg-constraint inefficiency (avg/paeth/sub top)
+ * - 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? due to
+ * odd number of bytes? (only width_mmx case) (near line 2335)
+ * - rewrite all MMX interlacing code so it's aligned with beginning
+ * of the row buffer, not the end (see 19991007 for details)
+ * - add error messages to any remaining bogus default cases
+ * - enable pixel_depth == 8 cases in png_read_filter_row()? (test speed)
+ * - try =r, etc., as reg constraints? (would gcc use 64-bit ones on x86-64?)
+ * - need full, non-graphical, CRC-based test suite... maybe autogenerate
+ * random data of various height/width/depth, compute CRCs, write (C
+ * funcs), read (asm/MMX), recompute CRCs, and compare?
+ * - write true x86-64 version using 128-bit "media instructions", %xmm0-15,
+ * and extra general-purpose registers
*/
+#if defined(__GNUC__)
+
#define PNG_INTERNAL
#include "png.h"
+
+/* for some inexplicable reason, gcc 3.3.5 on OpenBSD (and elsewhere?) does
+ * *not* define __PIC__ when the -fPIC option is used, so we have to rely on
+ * makefiles and whatnot to define the PIC macro explicitly */
+#if defined(PIC) && !defined(__PIC__) // (this can/should move to pngconf.h)
+# define __PIC__
+#endif
+
#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) && defined(PNG_USE_PNGGCCRD)
+/* if you want/need full thread-safety on x86-64 even when linking statically,
+ * comment out the "&& defined(__PIC__)" part here: */
+#if defined(__x86_64__) && defined(__PIC__)
+# define PNG_x86_64_USE_GOTPCREL // GOTPCREL => full thread-safety
+# define PNG_CLOBBER_x86_64_REGS_SUPPORTED // works as of gcc 3.4.3 ...
+#endif
+
int PNGAPI png_mmx_support(void);
-#ifdef PNG_USE_LOCAL_ARRAYS
-const static int FARDATA png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
-const static int FARDATA png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
-const static int FARDATA png_pass_width[7] = {8, 4, 4, 2, 2, 1, 1};
+#if defined(PNG_USE_LOCAL_ARRAYS)
+static PNG_CONST int FARDATA png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
+static PNG_CONST int FARDATA png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
+static PNG_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
@@ -279,109 +483,466 @@ const static int FARDATA png_pass_width[7] = {8, 4, 4, 2, 2, 1, 1};
# define _mask48_2 mask48_2
# define _mask48_1 mask48_1
# define _mask48_0 mask48_0
+# define _amask5_3_0 amask5_3_0
+# define _amask7_1_0 amask7_1_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
+# define _amask0_8_0 amask0_8_0
+# define _amask6_2_0 amask6_2_0
+# define _amask4_4_0 amask4_4_0
+# define _amask0_2_6 amask0_2_6
+# define _amask2_3_3 amask2_3_3
+# define _amask4_2_2 amask4_2_2
+# if defined(PNG_THREAD_UNSAFE_OK)
+# define _patemp patemp
+# define _pbtemp pbtemp
+# define _pctemp pctemp
+# endif
+#endif // djgpp, Win32, Cygwin, OS2
+
+
+/* These constants are used in the inlined MMX assembly code. */
+
+typedef unsigned long long ull;
+
+#if defined(PNG_x86_64_USE_GOTPCREL)
+static PNG_CONST struct {
+ //ull _mask_array[26];
+
+ // png_combine_row() constants:
+ ull _mask8_0;
+ ull _mask16_0, _mask16_1;
+ ull _mask24_0, _mask24_1, _mask24_2;
+ ull _mask32_0, _mask32_1, _mask32_2, _mask32_3;
+ ull _mask48_0, _mask48_1, _mask48_2, _mask48_3, _mask48_4, _mask48_5;
+
+ // png_do_read_interlace() constants:
+ ull _amask5_3_0, _amask7_1_0; // was _const4 and _const6, respectively
+
+ // png_read_filter_row_mmx_avg() constants (also uses _amask5_3_0):
+ ull _LBCarryMask, _HBClearMask;
+ ull _amask0_8_0, _amask6_2_0; // was ActiveMask for bpp 4/6 and 2 cases
+
+ // png_read_filter_row_mmx_paeth() constants (also uses _amask5_3_0):
+ ull _amask4_4_0, _amask0_2_6; // was ActiveMask{,End} for bpp 6/4/8 and 3
+
+ // png_read_filter_row_mmx_sub() constants:
+ ull _amask2_3_3, _amask4_2_2; // was ActiveMask for bpp 3 and 2 cases
+
+} _c64 __attribute__((used, aligned(8))) = {
+
+ // png_combine_row() constants:
+ 0x0102040810204080LL, // _mask8_0 offset 0
+
+ 0x1010202040408080LL, // _mask16_0 offset 8
+ 0x0101020204040808LL, // _mask16_1 offset 16
+
+ 0x2020404040808080LL, // _mask24_0 offset 24
+ 0x0408080810101020LL, // _mask24_1 offset 32
+ 0x0101010202020404LL, // _mask24_2 offset 40
+
+ 0x4040404080808080LL, // _mask32_0 offset 48
+ 0x1010101020202020LL, // _mask32_1 offset 56
+ 0x0404040408080808LL, // _mask32_2 offset 64
+ 0x0101010102020202LL, // _mask32_3 offset 72
+
+ 0x4040808080808080LL, // _mask48_0 offset 80
+ 0x2020202040404040LL, // _mask48_1 offset 88
+ 0x1010101010102020LL, // _mask48_2 offset 96
+ 0x0404080808080808LL, // _mask48_3 offset 104
+ 0x0202020204040404LL, // _mask48_4 offset 112
+ 0x0101010101010202LL, // _mask48_5 offset 120
+
+ // png_do_read_interlace() constants:
+ 0x0000000000FFFFFFLL, // _amask5_3_0 offset 128 (bpp 3, avg/paeth) const4
+ 0x00000000000000FFLL, // _amask7_1_0 offset 136 const6
+
+ // png_read_filter_row_mmx_avg() constants:
+ 0x0101010101010101LL, // _LBCarryMask offset 144
+ 0x7F7F7F7F7F7F7F7FLL, // _HBClearMask offset 152
+ 0xFFFFFFFFFFFFFFFFLL, // _amask0_8_0 offset 160 (bpp 4/6, avg)
+ 0x000000000000FFFFLL, // _amask6_2_0 offset 168 (bpp 2, avg)
+
+ // png_read_filter_row_mmx_paeth() constants:
+ 0x00000000FFFFFFFFLL, // _amask4_4_0 offset 176 (bpp 6/4/8, paeth)
+ 0xFFFF000000000000LL, // _amask0_2_6 offset 184 (bpp 3, paeth) A.M.End
+
+ // png_read_filter_row_mmx_sub() constants:
+ 0x0000FFFFFF000000LL, // _amask2_3_3 offset 192 (bpp 3, sub)
+ 0x00000000FFFF0000LL, // _amask4_2_2 offset 200 (bpp 2, sub)
+
+};
+
+#define MASK8_0 "(%%rbp)"
+#define MASK16_0 "8(%%rbp)"
+#define MASK16_1 "16(%%rbp)"
+#define MASK24_0 "24(%%rbp)"
+#define MASK24_1 "32(%%rbp)"
+#define MASK24_2 "40(%%rbp)"
+#define MASK32_0 "48(%%rbp)"
+#define MASK32_1 "56(%%rbp)"
+#define MASK32_2 "64(%%rbp)"
+#define MASK32_3 "72(%%rbp)"
+#define MASK48_0 "80(%%rbp)"
+#define MASK48_1 "88(%%rbp)"
+#define MASK48_2 "96(%%rbp)"
+#define MASK48_3 "104(%%rbp)"
+#define MASK48_4 "112(%%rbp)"
+#define MASK48_5 "120(%%rbp)"
+#define AMASK5_3_0 "128(%%rbp)"
+#define AMASK7_1_0 "136(%%rbp)"
+#define LB_CARRY_MASK "144(%%rbp)"
+#define HB_CLEAR_MASK "152(%%rbp)"
+#define AMASK0_8_0 "160(%%rbp)"
+#define AMASK6_2_0 "168(%%rbp)"
+#define AMASK4_4_0 "176(%%rbp)"
+#define AMASK0_2_6 "184(%%rbp)"
+#define AMASK2_3_3 "192(%%rbp)"
+#define AMASK4_2_2 "200(%%rbp)"
+
+#else // !PNG_x86_64_USE_GOTPCREL
+
+static PNG_CONST ull _mask8_0 __attribute__((used, aligned(8))) = 0x0102040810204080LL;
+
+static PNG_CONST ull _mask16_1 __attribute__((used, aligned(8))) = 0x0101020204040808LL;
+static PNG_CONST ull _mask16_0 __attribute__((used, aligned(8))) = 0x1010202040408080LL;
+
+static PNG_CONST ull _mask24_2 __attribute__((used, aligned(8))) = 0x0101010202020404LL;
+static PNG_CONST ull _mask24_1 __attribute__((used, aligned(8))) = 0x0408080810101020LL;
+static PNG_CONST ull _mask24_0 __attribute__((used, aligned(8))) = 0x2020404040808080LL;
+
+static PNG_CONST ull _mask32_3 __attribute__((used, aligned(8))) = 0x0101010102020202LL;
+static PNG_CONST ull _mask32_2 __attribute__((used, aligned(8))) = 0x0404040408080808LL;
+static PNG_CONST ull _mask32_1 __attribute__((used, aligned(8))) = 0x1010101020202020LL;
+static PNG_CONST ull _mask32_0 __attribute__((used, aligned(8))) = 0x4040404080808080LL;
+
+static PNG_CONST ull _mask48_5 __attribute__((used, aligned(8))) = 0x0101010101010202LL;
+static PNG_CONST ull _mask48_4 __attribute__((used, aligned(8))) = 0x0202020204040404LL;
+static PNG_CONST ull _mask48_3 __attribute__((used, aligned(8))) = 0x0404080808080808LL;
+static PNG_CONST ull _mask48_2 __attribute__((used, aligned(8))) = 0x1010101010102020LL;
+static PNG_CONST ull _mask48_1 __attribute__((used, aligned(8))) = 0x2020202040404040LL;
+static PNG_CONST ull _mask48_0 __attribute__((used, aligned(8))) = 0x4040808080808080LL;
+
+// png_do_read_interlace() constants:
+static PNG_CONST ull _amask5_3_0 __attribute__((aligned(8))) = 0x0000000000FFFFFFLL; // was _const4
+static PNG_CONST ull _amask7_1_0 __attribute__((aligned(8))) = 0x00000000000000FFLL; // was _const6
+
+// png_read_filter_row_mmx_avg() constants:
+static PNG_CONST ull _LBCarryMask __attribute__((used, aligned(8))) = 0x0101010101010101LL;
+static PNG_CONST ull _HBClearMask __attribute__((used, aligned(8))) = 0x7f7f7f7f7f7f7f7fLL;
+static PNG_CONST ull _amask0_8_0 __attribute__((used, aligned(8))) = 0xFFFFFFFFFFFFFFFFLL;
+static PNG_CONST ull _amask6_2_0 __attribute__((used, aligned(8))) = 0x000000000000FFFFLL;
+
+// png_read_filter_row_mmx_paeth() constants:
+static PNG_CONST ull _amask4_4_0 __attribute__((used, aligned(8))) = 0x00000000FFFFFFFFLL;
+static PNG_CONST ull _amask0_2_6 __attribute__((used, aligned(8))) = 0xFFFF000000000000LL;
+
+// png_read_filter_row_mmx_sub() constants:
+static PNG_CONST ull _amask2_3_3 __attribute__((used, aligned(8))) = 0x0000FFFFFF000000LL;
+static PNG_CONST ull _amask4_2_2 __attribute__((used, aligned(8))) = 0x00000000FFFF0000LL;
+
+#define MASK8_0 "_mask8_0"
+#define MASK16_0 "_mask16_0"
+#define MASK16_1 "_mask16_1"
+#define MASK24_0 "_mask24_0"
+#define MASK24_1 "_mask24_1"
+#define MASK24_2 "_mask24_2"
+#define MASK32_0 "_mask32_0"
+#define MASK32_1 "_mask32_1"
+#define MASK32_2 "_mask32_2"
+#define MASK32_3 "_mask32_3"
+#define MASK48_0 "_mask48_0"
+#define MASK48_1 "_mask48_1"
+#define MASK48_2 "_mask48_2"
+#define MASK48_3 "_mask48_3"
+#define MASK48_4 "_mask48_4"
+#define MASK48_5 "_mask48_5"
+#define AMASK5_3_0 "_amask5_3_0"
+#define AMASK7_1_0 "_amask7_1_0"
+#define LB_CARRY_MASK "_LBCarryMask"
+#define HB_CLEAR_MASK "_HBClearMask"
+#define AMASK0_8_0 "_amask0_8_0"
+#define AMASK6_2_0 "_amask6_2_0"
+#define AMASK4_4_0 "_amask4_4_0"
+#define AMASK0_2_6 "_amask0_2_6"
+#define AMASK2_3_3 "_amask2_3_3"
+#define AMASK4_2_2 "_amask4_2_2"
+
+#endif // ?PNG_x86_64_USE_GOTPCREL
+
+
+#if defined(PNG_HAVE_MMX_READ_FILTER_ROW) || defined(PNG_HAVE_MMX_COMBINE_ROW)
+
+// this block is specific to png_read_filter_row_mmx_paeth() except for
+// LOAD_GOT_rbp and RESTORE_rbp, which are also used in png_combine_row()
+#if defined(PNG_x86_64_USE_GOTPCREL)
+# define pa_TEMP "%%r11d"
+# define pb_TEMP "%%r12d"
+# define pc_TEMP "%%r13d"
+# if defined(PNG_CLOBBER_x86_64_REGS_SUPPORTED) // works as of gcc 3.4.3 ...
+# define SAVE_r11_r12_r13
+# define RESTORE_r11_r12_r13
+# define _CLOBBER_r11_r12_r13 ,"%r11", "%r12", "%r13"
+# define CLOBBER_r11_r12_r13 "%r11", "%r12", "%r13"
+# else // !PNG_CLOBBER_x86_64_REGS_SUPPORTED
+# define SAVE_r11_r12_r13 "pushq %%r11 \n\t" \
+ "pushq %%r12 \n\t" \
+ "pushq %%r13 \n\t" // "normally 0-extended"
+# define RESTORE_r11_r12_r13 "popq %%r13 \n\t" \
+ "popq %%r12 \n\t" \
+ "popq %%r11 \n\t"
+# define _CLOBBER_r11_r12_r13
+# define CLOBBER_r11_r12_r13
+# endif
+# define LOAD_GOT_rbp "pushq %%rbp \n\t" \
+ "movq _c64@GOTPCREL(%%rip), %%rbp \n\t"
+# define RESTORE_rbp "popq %%rbp \n\t"
+#else // 32-bit and/or non-PIC
+# if defined(PNG_THREAD_UNSAFE_OK)
+ // These variables are used in png_read_filter_row_mmx_paeth() and would be
+ // local variables if not for gcc-inline-assembly addressing limitations
+ // (some apparently related to ELF format, others to CPU type).
+ //
+ // WARNING: Their presence defeats the thread-safety of libpng.
+ static int _patemp __attribute__((used));
+ static int _pbtemp __attribute__((used));
+ static int _pctemp __attribute__((used));
+# define pa_TEMP "_patemp"
+# define pb_TEMP "_pbtemp" // temp variables for
+# define pc_TEMP "_pctemp" // Paeth routine
+# define SAVE_r11_r12_r13
+# define RESTORE_r11_r12_r13
+# define _CLOBBER_r11_r12_r13 // not using regs => not clobbering
+# define CLOBBER_r11_r12_r13
+# endif // PNG_THREAD_UNSAFE_OK
+# define LOAD_GOT_rbp
+# define RESTORE_rbp
#endif
+
+#if defined(__x86_64__)
+# define SAVE_ebp
+# define RESTORE_ebp
+# define _CLOBBER_ebp ,"%ebp"
+# define CLOBBER_ebp "%ebp"
+# define SAVE_FullLength "movl %%eax, %%r15d \n\t"
+# define RESTORE_FullLength "movl %%r15d, " // may go into eax or ecx
+# if defined(PNG_CLOBBER_x86_64_REGS_SUPPORTED) // works as of gcc 3.4.3 ...
+# define SAVE_r15
+# define RESTORE_r15
+# define _CLOBBER_r15 ,"%r15"
+# else
+# define SAVE_r15 "pushq %%r15 \n\t"
+# define RESTORE_r15 "popq %%r15 \n\t"
+# define _CLOBBER_r15
+# endif
+# define PBP "%%rbp" // regs used for 64-bit
+# define PAX "%%rax" // pointers or in
+# define PBX "%%rbx" // combination with
+# define PCX "%%rcx" // 64-bit pointer-regs
+# define PDX "%%rdx" // (base/index pairs,
+# define PSI "%%rsi" // add/sub/mov pairs)
+# define CLEAR_BOTTOM_3_BITS "and $0xfffffffffffffff8, "
+#else
+# define SAVE_ebp "pushl %%ebp \n\t" // clobber list doesn't work
+# define RESTORE_ebp "popl %%ebp \n\t" // for %ebp on 32-bit; not
+# define _CLOBBER_ebp // clear why not
+# define CLOBBER_ebp
+# define SAVE_FullLength "pushl %%eax \n\t"
+# define RESTORE_FullLength "popl " // eax (avg) or ecx (paeth)
+# define SAVE_r15
+# define RESTORE_r15
+# define _CLOBBER_r15
+# define PBP "%%ebp" // regs used for or in
+# define PAX "%%eax" // combination with
+# define PBX "%%ebx" // "normal," 32-bit
+# define PCX "%%ecx" // pointers
+# define PDX "%%edx"
+# define PSI "%%esi"
+# define CLEAR_BOTTOM_3_BITS "and $0xfffffff8, "
#endif
+// CLOB_COMMA_ebx_ebp: need comma ONLY if both CLOBBER_ebp and CLOBBER_GOT_ebx
+// have values, i.e., only if __x86_64__ AND !__PIC__
+#if defined(__x86_64__) && !defined(__PIC__)
+# define CLOB_COMMA_ebx_ebp , // clobbering both ebp and ebx => need comma
+#else
+# define CLOB_COMMA_ebx_ebp
+#endif
-/* These constants are used in the inlined MMX assembly code.
- Ignore gcc's "At top level: defined but not used" warnings. */
+// CLOB_COMMA_ebX_r1X: need comma UNLESS both CLOBBER_ebp and CLOBBER_GOT_ebx
+// are empty OR CLOBBER_r11_r12_r13 is empty--i.e., NO comma
+// if (!__x86_64__ AND __PIC__) OR !(PNG_x86_64_USE_GOTPCREL
+// AND PNG_CLOBBER_x86_64_REGS_SUPPORTED) (double sigh...)
+#if (!defined(__x86_64__) && defined(__PIC__)) || \
+ !defined(PNG_x86_64_USE_GOTPCREL) || \
+ !defined(PNG_CLOBBER_x86_64_REGS_SUPPORTED)
+# define CLOB_COMMA_ebX_r1X
+#else
+# define CLOB_COMMA_ebX_r1X , // clobbering (ebp OR ebx) AND r11_r12_r13
+#endif
-/* 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;
+// CLOB_COLON_ebx_ebp: need colon unless CLOBBER_ebp and CLOBBER_GOT_ebx are
+// BOTH empty--i.e., NO colon if (!__x86_64__ AND __PIC__)
+// CLOB_COLON_ebx_ebp_r1X: if, in addition, CLOBBER_r11_r12_r13 is empty, then
+// no colon for Paeth blocks, either--i.e., NO colon
+// if !(PNG_x86_64_USE_GOTPCREL AND
+// PNG_CLOBBER_x86_64_REGS_SUPPORTED)
+#if (!defined(__x86_64__) && defined(__PIC__))
+# define CLOB_COLON_ebx_ebp
+# if !(defined(PNG_x86_64_USE_GOTPCREL) && \
+ defined(PNG_CLOBBER_x86_64_REGS_SUPPORTED))
+# define CLOB_COLON_ebx_ebp_r1X
+# else
+# define CLOB_COLON_ebx_ebp_r1X : // clobbering ebp OR ebx OR r11_r12_r13
+# endif
+#else
+# define CLOB_COLON_ebx_ebp : // clobbering ebp OR ebx
+# define CLOB_COLON_ebx_ebp_r1X : // clobbering ebp OR ebx OR r11_r12_r13
+#endif
+
+#endif // PNG_HAVE_MMX_READ_FILTER_ROW
+
+#if defined(__PIC__) // macros to save, restore index to Global Offset Table
+# if defined(__x86_64__)
+# define SAVE_GOT_ebx "pushq %%rbx \n\t"
+# define RESTORE_GOT_ebx "popq %%rbx \n\t"
+# else
+# define SAVE_GOT_ebx "pushl %%ebx \n\t"
+# define RESTORE_GOT_ebx "popl %%ebx \n\t"
+# endif
+# define _CLOBBER_GOT_ebx // explicitly saved, restored => not clobbered
+# define CLOBBER_GOT_ebx
+#else
+# define SAVE_GOT_ebx
+# define RESTORE_GOT_ebx
+# define _CLOBBER_GOT_ebx ,"%ebx"
+# define CLOBBER_GOT_ebx "%ebx"
#endif
-const static unsigned long long _mask8_0 = 0x0102040810204080LL;
-
-const static unsigned long long _mask16_1 = 0x0101020204040808LL;
-const static unsigned long long _mask16_0 = 0x1010202040408080LL;
-
-const static unsigned long long _mask24_2 = 0x0101010202020404LL;
-const static unsigned long long _mask24_1 = 0x0408080810101020LL;
-const static unsigned long long _mask24_0 = 0x2020404040808080LL;
-
-const static unsigned long long _mask32_3 = 0x0101010102020202LL;
-const static unsigned long long _mask32_2 = 0x0404040408080808LL;
-const static unsigned long long _mask32_1 = 0x1010101020202020LL;
-const static unsigned long long _mask32_0 = 0x4040404080808080LL;
-
-const static unsigned long long _mask48_5 = 0x0101010101010202LL;
-const static unsigned long long _mask48_4 = 0x0202020204040404LL;
-const static unsigned long long _mask48_3 = 0x0404080808080808LL;
-const static unsigned long long _mask48_2 = 0x1010101010102020LL;
-const static unsigned long long _mask48_1 = 0x2020202040404040LL;
-const static unsigned long long _mask48_0 = 0x4040808080808080LL;
-
-const static unsigned long long _const4 = 0x0000000000FFFFFFLL;
-//const static unsigned long long _const5 = 0x000000FFFFFF0000LL; // NOT USED
-const 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;
+#if defined(PNG_HAVE_MMX_COMBINE_ROW) || defined(PNG_HAVE_MMX_READ_INTERLACE)
+# define BPP2 2
+# define BPP3 3 // bytes per pixel (a.k.a. pixel_bytes)
+# define BPP4 4 // (defined only to help avoid cut-and-paste errors)
+# define BPP6 6
+# define BPP8 8
#endif
-void /* PRIVATE */
-png_squelch_warnings(void)
+
+
+static int _mmx_supported = 2; // 0: no MMX; 1: MMX supported; 2: not tested
+
+/*===========================================================================*/
+/* */
+/* 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
+// x (3) the function is moved down here to prevent gcc from
+// x inlining it in multiple places and then barfing be-
+// x cause the ".NOT_SUPPORTED" label is multiply defined
+// [need to retest with gcc 2.7.2.3]
+
+// GRR 20070524: This declaration apparently is compatible with but supersedes
+// the one in png.h; in any case, the generated object file is slightly
+// smaller. It is unnecessary with gcc 4.1.2, but gcc 2.x apparently
+// replicated the ".NOT_SUPPORTED" label in each location the function was
+// inlined, leading to compilation errors due to the "multiply defined"
+// label. Old workaround was to leave the function at the end of this
+// file; new one (still testing) is to use a gcc-specific function attribute
+// to prevent local inlining.
+int PNGAPI
+png_mmx_support(void) __attribute__((noinline));
+
+int PNGAPI
+png_mmx_support(void)
{
-#ifdef PNG_THREAD_UNSAFE_OK
- _dif = _dif;
- _patemp = _patemp;
- _pbtemp = _pbtemp;
- _pctemp = _pctemp;
- _MMXLength = _MMXLength;
+#if defined(PNG_MMX_CODE_SUPPORTED) // superfluous, but what the heck
+ int result;
+ __asm__ __volatile__ (
+#if defined(__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)
+ "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
+ "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
+ "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)
+ "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
+ "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
- _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;
-}
+ "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
+#if defined(__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;
+}
-static int _mmx_supported = 2;
/*===========================================================================*/
/* */
@@ -391,12 +952,6 @@ static int _mmx_supported = 2;
#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
@@ -414,9 +969,14 @@ static int _mmx_supported = 2;
void /* PRIVATE */
png_combine_row(png_structp png_ptr, png_bytep row, int mask)
{
+ int dummy_value_a; // fix 'forbidden register spilled' error
+ int dummy_value_c;
+ int dummy_value_d;
+ png_bytep dummy_value_S;
+ png_bytep dummy_value_D;
+
png_debug(1, "in png_combine_row (pnggccrd.c)\n");
-#if defined(PNG_MMX_CODE_SUPPORTED)
if (_mmx_supported == 2) {
#if !defined(PNG_1_0_X)
/* this should have happened in png_init_mmx_flags() already */
@@ -424,7 +984,6 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask)
#endif
png_mmx_support();
}
-#endif
if (mask == 0xff)
{
@@ -436,250 +995,111 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask)
{
switch (png_ptr->row_info.pixel_depth)
{
- case 1: /* png_ptr->row_info.pixel_depth */
+ case 24: /* 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;
+ png_bytep srcptr;
+ png_bytep dstptr;
- 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
+#if !defined(PNG_1_0_X)
+ if (png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)
+#else
+ if (_mmx_supported)
#endif
{
- s_start = 7;
- s_end = 0;
- s_inc = -1;
- }
-
- shift = s_start;
+ png_uint_32 len;
+ int diff;
- for (i = 0; i < png_ptr->width; i++)
- {
- if (m & mask)
- {
- int value;
+ 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
- value = (*sp >> shift) & 0x1;
- *dp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
- *dp |= (png_byte)(value << shift);
- }
+ __asm__ __volatile__ (
+ "not %%edx \n\t" // mask => unmask
+ "movd %%edx, %%mm7 \n\t" // load bit pattern
+ "not %%edx \n\t" // unmask => mask for later
+ "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
- if (shift == s_end)
- {
- shift = s_start;
- sp++;
- dp++;
- }
- else
- shift += s_inc;
+ LOAD_GOT_rbp
+ "movq " MASK24_0 ", %%mm0 \n\t" // _mask24_0 -> mm0
+ "movq " MASK24_1 ", %%mm1 \n\t" // _mask24_1 -> mm1
+ "movq " MASK24_2 ", %%mm2 \n\t" // _mask24_2 -> mm2
+ RESTORE_rbp
- if (m == 1)
- m = 0x80;
- else
- m >>= 1;
- }
- break;
- }
+ "pand %%mm7, %%mm0 \n\t"
+ "pand %%mm7, %%mm1 \n\t"
+ "pand %%mm7, %%mm2 \n\t"
- 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;
+ "pcmpeqb %%mm6, %%mm0 \n\t"
+ "pcmpeqb %%mm6, %%mm1 \n\t"
+ "pcmpeqb %%mm6, %%mm2 \n\t"
- 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;
- }
+// preload "movl len, %%ecx \n\t" // load length of line
+// preload "movl srcptr, %3 \n\t" // load source
+// preload "movl dstptr, %4 \n\t" // load dest
- shift = s_start;
+ "cmpl $0, %%ecx \n\t"
+ "jz mainloop24end \n\t"
- 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);
- }
+ "mainloop24: \n\t"
+ "movq (%3), %%mm4 \n\t"
+ "pand %%mm0, %%mm4 \n\t"
+ "movq %%mm0, %%mm6 \n\t"
+ "movq (%4), %%mm7 \n\t"
+ "pandn %%mm7, %%mm6 \n\t"
+ "por %%mm6, %%mm4 \n\t"
+ "movq %%mm4, (%4) \n\t"
- if (shift == s_end)
- {
- shift = s_start;
- sp++;
- dp++;
- }
- else
- shift += s_inc;
- if (m == 1)
- m = 0x80;
- else
- m >>= 1;
- }
- break;
- }
+ "movq 8(%3), %%mm5 \n\t"
+ "pand %%mm1, %%mm5 \n\t"
+ "movq %%mm1, %%mm7 \n\t"
+ "movq 8(%4), %%mm6 \n\t"
+ "pandn %%mm6, %%mm7 \n\t"
+ "por %%mm7, %%mm5 \n\t"
+ "movq %%mm5, 8(%4) \n\t"
- 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;
+ "movq 16(%3), %%mm6 \n\t"
+ "pand %%mm2, %%mm6 \n\t"
+ "movq %%mm2, %%mm4 \n\t"
+ "movq 16(%4), %%mm7 \n\t"
+ "pandn %%mm7, %%mm4 \n\t"
+ "por %%mm4, %%mm6 \n\t"
+ "movq %%mm6, 16(%4) \n\t"
- 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;
+ "add $24, %3 \n\t" // inc by 24 bytes processed
+ "add $24, %4 \n\t"
+ "subl $8, %%ecx \n\t" // dec by 8 pixels processed
- 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);
- }
+ "ja mainloop24 \n\t"
- if (shift == s_end)
- {
- shift = s_start;
- sp++;
- dp++;
- }
- else
- shift += s_inc;
- if (m == 1)
- m = 0x80;
- else
- m >>= 1;
- }
- break;
- }
+ "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
- case 8: /* png_ptr->row_info.pixel_depth */
- {
- png_bytep srcptr;
- png_bytep dstptr;
+ "secondloop24: \n\t"
+ "sall %%edx \n\t" // move high bit to CF
+ "jnc skip24 \n\t" // if CF = 0
+ "movw (%3), %%ax \n\t"
+ "movw %%ax, (%4) \n\t"
+ "xorl %%eax, %%eax \n\t"
+ "movb 2(%3), %%al \n\t"
+ "movb %%al, 2(%4) \n\t"
-#if defined(PNG_MMX_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK)
-#if !defined(PNG_1_0_X)
- if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)
- /* && _mmx_supported */ )
-#else
- if (_mmx_supported)
-#endif
- {
- 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
+ "skip24: \n\t"
+ "add $3, %3 \n\t"
+ "add $3, %4 \n\t"
+ "decl %%ecx \n\t"
+ "jnz secondloop24 \n\t"
- __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
+ "end24: \n\t"
+ "EMMS \n\t" // DONE
: "=a" (dummy_value_a), // output regs (dummy)
"=d" (dummy_value_d),
@@ -687,31 +1107,31 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask)
"=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
+ : "0" (diff), // eax // input regs
+ "1" (mask), // edx
"2" (len), // ecx
- "1" (mask) // edx
+// was (unmask) "b" RESERVED // ebx // Global Offset Table idx
+ "3" (srcptr), // esi/rsi
+ "4" (dstptr) // edi/rdi
-#if 0 /* MMX regs (%mm0, etc.) not supported by gcc 2.7.2.3 or egcs 1.1 */
- : "%mm0", "%mm4", "%mm6", "%mm7" // clobber list
+#if defined(PNG_CLOBBER_MMX_REGS_SUPPORTED)
+ : "%mm0", "%mm1", "%mm2" // clobber list
+ , "%mm4", "%mm5", "%mm6", "%mm7"
#endif
);
}
- else /* mmx _not supported - Use modified C routine */
-#endif /* PNG_MMX_CODE_SUPPORTED */
+ else /* not _mmx_supported - use modified C routine */
{
register png_uint_32 i;
- png_uint_32 initial_val = png_pass_start[png_ptr->pass];
+ 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 = png_pass_inc[png_ptr->pass];
+ 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 = png_pass_width[png_ptr->pass];
+ 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 = len; /* GRR bugfix */
+ register png_uint_32 final_val = BPP3 * len; /* GRR bugfix */
srcptr = png_ptr->row_buf + 1 + initial_val;
dstptr = row + initial_val;
@@ -724,7 +1144,7 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask)
}
if (diff) /* number of leftover pixels: 3 for pngtest */
{
- final_val+=diff /* *BPP1 */ ;
+ final_val += diff*BPP3;
for (; i < final_val; i += stride)
{
if (rep_bytes > (int)(final_val-i))
@@ -734,138 +1154,157 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask)
dstptr += stride;
}
}
-
} /* end of else (_mmx_supported) */
break;
- } /* end 8 bpp */
+ } /* end 24 bpp */
- case 16: /* png_ptr->row_info.pixel_depth */
+ // formerly claimed to be most common case (combining 32-bit RGBA),
+ // but almost certainly less common than 24-bit RGB case
+ 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 !defined(PNG_1_0_X)
- if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)
- /* && _mmx_supported */ )
+ if (png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)
#else
if (_mmx_supported)
#endif
{
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 //
+ 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
+ "not %%edx \n\t" // mask => unmask
+ "movd %%edx, %%mm7 \n\t" // load bit pattern
+ "not %%edx \n\t" // unmask => mask for later
"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"
+ LOAD_GOT_rbp
+ "movq " MASK32_0 ", %%mm0 \n\t" // _mask32_0
+ "movq " MASK32_1 ", %%mm1 \n\t" // _mask32_1
+ "movq " MASK32_2 ", %%mm2 \n\t" // _mask32_2
+ "movq " MASK32_3 ", %%mm3 \n\t" // _mask32_3
+ RESTORE_rbp
"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
+// preload "movl srcptr, %3 \n\t" // load source
+// preload "movl dstptr, %4 \n\t" // load dest
- "cmpl $0, %%ecx \n\t"
- "jz mainloop16end \n\t"
+ "cmpl $0, %%ecx \n\t" // lcr
+ "jz mainloop32end \n\t"
- "mainloop16: \n\t"
- "movq (%%esi), %%mm4 \n\t"
+ "mainloop32: \n\t"
+ "movq (%3), %%mm4 \n\t"
"pand %%mm0, %%mm4 \n\t"
"movq %%mm0, %%mm6 \n\t"
- "movq (%%edi), %%mm7 \n\t"
+ "movq (%4), %%mm7 \n\t"
"pandn %%mm7, %%mm6 \n\t"
"por %%mm6, %%mm4 \n\t"
- "movq %%mm4, (%%edi) \n\t"
+ "movq %%mm4, (%4) \n\t"
- "movq 8(%%esi), %%mm5 \n\t"
+ "movq 8(%3), %%mm5 \n\t"
"pand %%mm1, %%mm5 \n\t"
"movq %%mm1, %%mm7 \n\t"
- "movq 8(%%edi), %%mm6 \n\t"
+ "movq 8(%4), %%mm6 \n\t"
"pandn %%mm6, %%mm7 \n\t"
"por %%mm7, %%mm5 \n\t"
- "movq %%mm5, 8(%%edi) \n\t"
+ "movq %%mm5, 8(%4) \n\t"
+
+ "movq 16(%3), %%mm6 \n\t"
+ "pand %%mm2, %%mm6 \n\t"
+ "movq %%mm2, %%mm4 \n\t"
+ "movq 16(%4), %%mm7 \n\t"
+ "pandn %%mm7, %%mm4 \n\t"
+ "por %%mm4, %%mm6 \n\t"
+ "movq %%mm6, 16(%4) \n\t"
+
+ "movq 24(%3), %%mm7 \n\t"
+ "pand %%mm3, %%mm7 \n\t"
+ "movq %%mm3, %%mm5 \n\t"
+ "movq 24(%4), %%mm4 \n\t"
+ "pandn %%mm4, %%mm5 \n\t"
+ "por %%mm5, %%mm7 \n\t"
+ "movq %%mm7, 24(%4) \n\t"
- "addl $16, %%esi \n\t" // inc by 16 bytes processed
- "addl $16, %%edi \n\t"
+ "add $32, %3 \n\t" // inc by 32 bytes processed
+ "add $32, %4 \n\t"
"subl $8, %%ecx \n\t" // dec by 8 pixels processed
- "ja mainloop16 \n\t"
+ "ja mainloop32 \n\t"
- "mainloop16end: \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 end16 \n\t"
+ "jz end32 \n\t"
// preload "movl mask, %%edx \n\t"
- "sall $24, %%edx \n\t" // make low byte, high byte
+ "sall $24, %%edx \n\t" // low byte => high byte
- "secondloop16: \n\t"
+ "secondloop32: \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"
+ "jnc skip32 \n\t" // if CF = 0
+ "movl (%3), %%eax \n\t"
+ "movl %%eax, (%4) \n\t"
- "skip16: \n\t"
- "addl $2, %%esi \n\t"
- "addl $2, %%edi \n\t"
+ "skip32: \n\t"
+ "add $4, %3 \n\t"
+ "add $4, %4 \n\t"
"decl %%ecx \n\t"
- "jnz secondloop16 \n\t"
+ "jnz secondloop32 \n\t"
- "end16: \n\t"
+ "end32: \n\t"
"EMMS \n\t" // DONE
: "=a" (dummy_value_a), // output regs (dummy)
- "=c" (dummy_value_c),
"=d" (dummy_value_d),
+ "=c" (dummy_value_c),
"=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
+ "1" (mask), // edx
+ "2" (len), // ecx
+// was (unmask) "b" RESERVED // ebx // Global Offset Table idx
+ "3" (srcptr), // esi/rsi
+ "4" (dstptr) // edi/rdi
-#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"
+#if defined(PNG_CLOBBER_MMX_REGS_SUPPORTED)
+ : "%mm0", "%mm1", "%mm2", "%mm3" // clobber list
+ , "%mm4", "%mm5", "%mm6", "%mm7"
#endif
);
}
- else /* mmx _not supported - Use modified C routine */
-#endif /* PNG_MMX_CODE_SUPPORTED */
+ else /* not _mmx_supported - use modified C routine */
{
register png_uint_32 i;
- png_uint_32 initial_val = BPP2 * png_pass_start[png_ptr->pass];
+ 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 = BPP2 * png_pass_inc[png_ptr->pass];
+ 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 = BPP2 * png_pass_width[png_ptr->pass];
+ 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 = BPP2 * len; /* GRR bugfix */
+ register png_uint_32 final_val = BPP4 * len; /* GRR bugfix */
srcptr = png_ptr->row_buf + 1 + initial_val;
dstptr = row + initial_val;
@@ -878,7 +1317,7 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask)
}
if (diff) /* number of leftover pixels: 3 for pngtest */
{
- final_val+=diff*BPP2;
+ final_val += diff*BPP4;
for (; i < final_val; i += stride)
{
if (rep_bytes > (int)(final_val-i))
@@ -891,115 +1330,83 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask)
} /* end of else (_mmx_supported) */
break;
- } /* end 16 bpp */
+ } /* end 32 bpp */
- case 24: /* png_ptr->row_info.pixel_depth */
+ 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 !defined(PNG_1_0_X)
- if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)
- /* && _mmx_supported */ )
+ if (png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)
#else
if (_mmx_supported)
#endif
{
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 //
+ 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
+ "not %%edx \n\t" // mask => unmask
+ "movd %%edx, %%mm7 \n\t" // load bit pattern
+ "not %%edx \n\t" // unmask => mask for later
"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"
+ LOAD_GOT_rbp
+ "movq " MASK8_0 ", %%mm0 \n\t" // _mask8_0 -> mm0
+ RESTORE_rbp
- "pcmpeqb %%mm6, %%mm0 \n\t"
- "pcmpeqb %%mm6, %%mm1 \n\t"
- "pcmpeqb %%mm6, %%mm2 \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
+// preload "movl srcptr, %3 \n\t" // load source
+// preload "movl dstptr, %4 \n\t" // load dest
- "cmpl $0, %%ecx \n\t"
- "jz mainloop24end \n\t"
+ "cmpl $0, %%ecx \n\t" // len == 0 ?
+ "je mainloop8end \n\t"
- "mainloop24: \n\t"
- "movq (%%esi), %%mm4 \n\t"
+ "mainloop8: \n\t"
+ "movq (%3), %%mm4 \n\t" // *srcptr
"pand %%mm0, %%mm4 \n\t"
"movq %%mm0, %%mm6 \n\t"
- "movq (%%edi), %%mm7 \n\t"
- "pandn %%mm7, %%mm6 \n\t"
+ "pandn (%4), %%mm6 \n\t" // *dstptr
"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"
+ "movq %%mm4, (%4) \n\t"
+ "add $8, %3 \n\t" // inc by 8 bytes processed
+ "add $8, %4 \n\t"
"subl $8, %%ecx \n\t" // dec by 8 pixels processed
+ "ja mainloop8 \n\t"
- "ja mainloop24 \n\t"
-
- "mainloop24end: \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 end24 \n\t"
+ "jz end8 \n\t"
// preload "movl mask, %%edx \n\t"
"sall $24, %%edx \n\t" // make low byte, high byte
- "secondloop24: \n\t"
+ "secondloop8: \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"
+ "jnc skip8 \n\t" // if CF = 0
+ "movb (%3), %%al \n\t"
+ "movb %%al, (%4) \n\t"
- "skip24: \n\t"
- "addl $3, %%esi \n\t"
- "addl $3, %%edi \n\t"
+ "skip8: \n\t"
+ "inc %3 \n\t"
+ "inc %4 \n\t"
"decl %%ecx \n\t"
- "jnz secondloop24 \n\t"
+ "jnz secondloop8 \n\t"
- "end24: \n\t"
+ "end8: \n\t"
"EMMS \n\t" // DONE
: "=a" (dummy_value_a), // output regs (dummy)
@@ -1008,32 +1415,30 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask)
"=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
+ : "0" (diff), // eax // input regs
+ "1" (mask), // edx
"2" (len), // ecx
- "1" (mask) // edx
+// was (unmask) "b" RESERVED // ebx // Global Offset Table idx
+ "3" (srcptr), // esi/rsi
+ "4" (dstptr) // edi/rdi
-#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"
+#if defined(PNG_CLOBBER_MMX_REGS_SUPPORTED)
+ : "%mm0", "%mm4", "%mm6", "%mm7" // clobber list
#endif
);
}
- else /* mmx _not supported - Use modified C routine */
-#endif /* PNG_MMX_CODE_SUPPORTED */
+ else /* not _mmx_supported - use modified C routine */
{
register png_uint_32 i;
- png_uint_32 initial_val = BPP3 * png_pass_start[png_ptr->pass];
+ 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 = BPP3 * png_pass_inc[png_ptr->pass];
+ 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 = BPP3 * png_pass_width[png_ptr->pass];
+ 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 = BPP3 * len; /* GRR bugfix */
+ register png_uint_32 final_val = len; /* GRR bugfix */
srcptr = png_ptr->row_buf + 1 + initial_val;
dstptr = row + initial_val;
@@ -1046,7 +1451,7 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask)
}
if (diff) /* number of leftover pixels: 3 for pngtest */
{
- final_val+=diff*BPP3;
+ final_val += diff /* *BPP1 */ ;
for (; i < final_val; i += stride)
{
if (rep_bytes > (int)(final_val-i))
@@ -1056,125 +1461,268 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask)
dstptr += stride;
}
}
+
} /* end of else (_mmx_supported) */
break;
- } /* end 24 bpp */
+ } /* end 8 bpp */
- case 32: /* 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;
+ } /* end 1 bpp */
+
+ 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;
+ } /* end 2 bpp */
+
+ 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;
+ } /* end 4 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 !defined(PNG_1_0_X)
- if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)
- /* && _mmx_supported */ )
+ if (png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)
#else
if (_mmx_supported)
#endif
{
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 //
+ 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
+ "not %%edx \n\t" // mask => unmask
+ "movd %%edx, %%mm7 \n\t" // load bit pattern
+ "not %%edx \n\t" // unmask => mask for later
"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"
+ LOAD_GOT_rbp
+ "movq " MASK16_0 ", %%mm0 \n\t" // _mask16_0 -> mm0
+ "movq " MASK16_1 ", %%mm1 \n\t" // _mask16_1 -> mm1
+ RESTORE_rbp
"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
+// preload "movl srcptr, %3 \n\t" // load source
+// preload "movl dstptr, %4 \n\t" // load dest
- "cmpl $0, %%ecx \n\t" // lcr
- "jz mainloop32end \n\t"
+ "cmpl $0, %%ecx \n\t"
+ "jz mainloop16end \n\t"
- "mainloop32: \n\t"
- "movq (%%esi), %%mm4 \n\t"
+ "mainloop16: \n\t"
+ "movq (%3), %%mm4 \n\t"
"pand %%mm0, %%mm4 \n\t"
"movq %%mm0, %%mm6 \n\t"
- "movq (%%edi), %%mm7 \n\t"
+ "movq (%4), %%mm7 \n\t"
"pandn %%mm7, %%mm6 \n\t"
"por %%mm6, %%mm4 \n\t"
- "movq %%mm4, (%%edi) \n\t"
+ "movq %%mm4, (%4) \n\t"
- "movq 8(%%esi), %%mm5 \n\t"
+ "movq 8(%3), %%mm5 \n\t"
"pand %%mm1, %%mm5 \n\t"
"movq %%mm1, %%mm7 \n\t"
- "movq 8(%%edi), %%mm6 \n\t"
+ "movq 8(%4), %%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"
+ "movq %%mm5, 8(%4) \n\t"
- "addl $32, %%esi \n\t" // inc by 32 bytes processed
- "addl $32, %%edi \n\t"
+ "add $16, %3 \n\t" // inc by 16 bytes processed
+ "add $16, %4 \n\t"
"subl $8, %%ecx \n\t" // dec by 8 pixels processed
- "ja mainloop32 \n\t"
+ "ja mainloop16 \n\t"
- "mainloop32end: \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 end32 \n\t"
+ "jz end16 \n\t"
// preload "movl mask, %%edx \n\t"
- "sall $24, %%edx \n\t" // low byte => high byte
+ "sall $24, %%edx \n\t" // make low byte, high byte
- "secondloop32: \n\t"
+ "secondloop16: \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"
+ "jnc skip16 \n\t" // if CF = 0
+ "movw (%3), %%ax \n\t"
+ "movw %%ax, (%4) \n\t"
- "skip32: \n\t"
- "addl $4, %%esi \n\t"
- "addl $4, %%edi \n\t"
+ "skip16: \n\t"
+ "add $2, %3 \n\t"
+ "add $2, %4 \n\t"
"decl %%ecx \n\t"
- "jnz secondloop32 \n\t"
+ "jnz secondloop16 \n\t"
- "end32: \n\t"
+ "end16: \n\t"
"EMMS \n\t" // DONE
: "=a" (dummy_value_a), // output regs (dummy)
@@ -1183,32 +1731,31 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask)
"=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
+ : "0" (diff), // eax // input regs
+ "1" (mask), // edx
"2" (len), // ecx
- "1" (mask) // edx
+// was (unmask) "b" RESERVED // ebx // Global Offset Table idx
+ "3" (srcptr), // esi/rsi
+ "4" (dstptr) // edi/rdi
-#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"
+#if defined(PNG_CLOBBER_MMX_REGS_SUPPORTED)
+ : "%mm0", "%mm1", "%mm4" // clobber list
+ , "%mm5", "%mm6", "%mm7"
#endif
);
}
- else /* mmx _not supported - Use modified C routine */
-#endif /* PNG_MMX_CODE_SUPPORTED */
+ else /* not _mmx_supported - use modified C routine */
{
register png_uint_32 i;
- png_uint_32 initial_val = BPP4 * png_pass_start[png_ptr->pass];
+ 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 = BPP4 * png_pass_inc[png_ptr->pass];
+ 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 = BPP4 * png_pass_width[png_ptr->pass];
+ 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 = BPP4 * len; /* GRR bugfix */
+ register png_uint_32 final_val = BPP2 * len; /* GRR bugfix */
srcptr = png_ptr->row_buf + 1 + initial_val;
dstptr = row + initial_val;
@@ -1221,7 +1768,7 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask)
}
if (diff) /* number of leftover pixels: 3 for pngtest */
{
- final_val+=diff*BPP4;
+ final_val += diff*BPP2;
for (; i < final_val; i += stride)
{
if (rep_bytes > (int)(final_val-i))
@@ -1234,47 +1781,44 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask)
} /* end of else (_mmx_supported) */
break;
- } /* end 32 bpp */
+ } /* end 16 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 !defined(PNG_1_0_X)
- if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)
- /* && _mmx_supported */ )
+ if (png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)
#else
if (_mmx_supported)
#endif
{
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 //
+ 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
+ "not %%edx \n\t" // mask => unmask
+ "movd %%edx, %%mm7 \n\t" // load bit pattern
+ "not %%edx \n\t" // unmask => mask for later
"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"
+ LOAD_GOT_rbp
+ "movq " MASK48_0 ", %%mm0 \n\t" // _mask48_0 -> mm0
+ "movq " MASK48_1 ", %%mm1 \n\t" // _mask48_1 -> mm1
+ "movq " MASK48_2 ", %%mm2 \n\t" // _mask48_2 -> mm2
+ "movq " MASK48_3 ", %%mm3 \n\t" // _mask48_3 -> mm3
+ "movq " MASK48_4 ", %%mm4 \n\t" // _mask48_4 -> mm4
+ "movq " MASK48_5 ", %%mm5 \n\t" // _mask48_5 -> mm5
+ RESTORE_rbp
"pand %%mm7, %%mm0 \n\t"
"pand %%mm7, %%mm1 \n\t"
@@ -1291,57 +1835,57 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask)
"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
+// preload "movl srcptr, %3 \n\t" // load source
+// preload "movl dstptr, %4 \n\t" // load dest
"cmpl $0, %%ecx \n\t"
"jz mainloop48end \n\t"
"mainloop48: \n\t"
- "movq (%%esi), %%mm7 \n\t"
+ "movq (%3), %%mm7 \n\t"
"pand %%mm0, %%mm7 \n\t"
"movq %%mm0, %%mm6 \n\t"
- "pandn (%%edi), %%mm6 \n\t"
+ "pandn (%4), %%mm6 \n\t"
"por %%mm6, %%mm7 \n\t"
- "movq %%mm7, (%%edi) \n\t"
+ "movq %%mm7, (%4) \n\t"
- "movq 8(%%esi), %%mm6 \n\t"
+ "movq 8(%3), %%mm6 \n\t"
"pand %%mm1, %%mm6 \n\t"
"movq %%mm1, %%mm7 \n\t"
- "pandn 8(%%edi), %%mm7 \n\t"
+ "pandn 8(%4), %%mm7 \n\t"
"por %%mm7, %%mm6 \n\t"
- "movq %%mm6, 8(%%edi) \n\t"
+ "movq %%mm6, 8(%4) \n\t"
- "movq 16(%%esi), %%mm6 \n\t"
+ "movq 16(%3), %%mm6 \n\t"
"pand %%mm2, %%mm6 \n\t"
"movq %%mm2, %%mm7 \n\t"
- "pandn 16(%%edi), %%mm7 \n\t"
+ "pandn 16(%4), %%mm7 \n\t"
"por %%mm7, %%mm6 \n\t"
- "movq %%mm6, 16(%%edi) \n\t"
+ "movq %%mm6, 16(%4) \n\t"
- "movq 24(%%esi), %%mm7 \n\t"
+ "movq 24(%3), %%mm7 \n\t"
"pand %%mm3, %%mm7 \n\t"
"movq %%mm3, %%mm6 \n\t"
- "pandn 24(%%edi), %%mm6 \n\t"
+ "pandn 24(%4), %%mm6 \n\t"
"por %%mm6, %%mm7 \n\t"
- "movq %%mm7, 24(%%edi) \n\t"
+ "movq %%mm7, 24(%4) \n\t"
- "movq 32(%%esi), %%mm6 \n\t"
+ "movq 32(%3), %%mm6 \n\t"
"pand %%mm4, %%mm6 \n\t"
"movq %%mm4, %%mm7 \n\t"
- "pandn 32(%%edi), %%mm7 \n\t"
+ "pandn 32(%4), %%mm7 \n\t"
"por %%mm7, %%mm6 \n\t"
- "movq %%mm6, 32(%%edi) \n\t"
+ "movq %%mm6, 32(%4) \n\t"
- "movq 40(%%esi), %%mm7 \n\t"
+ "movq 40(%3), %%mm7 \n\t"
"pand %%mm5, %%mm7 \n\t"
"movq %%mm5, %%mm6 \n\t"
- "pandn 40(%%edi), %%mm6 \n\t"
+ "pandn 40(%4), %%mm6 \n\t"
"por %%mm6, %%mm7 \n\t"
- "movq %%mm7, 40(%%edi) \n\t"
+ "movq %%mm7, 40(%4) \n\t"
- "addl $48, %%esi \n\t" // inc by 48 bytes processed
- "addl $48, %%edi \n\t"
+ "add $48, %3 \n\t" // inc by 48 bytes processed
+ "add $48, %4 \n\t"
"subl $8, %%ecx \n\t" // dec by 8 pixels processed
"ja mainloop48 \n\t"
@@ -1357,12 +1901,14 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask)
"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"
+ "movl (%3), %%eax \n\t"
+ "movl %%eax, (%4) \n\t"
+ "movw 4(%3), %%ax \n\t" // GR-P bugfix 20070717
+ "movw %%ax, 4(%4) \n\t" // GR-P bugfix 20070717
"skip48: \n\t"
- "addl $4, %%esi \n\t"
- "addl $4, %%edi \n\t"
+ "add $6, %3 \n\t" // GR-P bugfix 20070717
+ "add $6, %4 \n\t" // GR-P bugfix 20070717
"decl %%ecx \n\t"
"jnz secondloop48 \n\t"
@@ -1375,21 +1921,20 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask)
"=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
+ : "0" (diff), // eax // input regs
+ "1" (mask), // edx
"2" (len), // ecx
- "1" (mask) // edx
+// was (unmask) "b" RESERVED // ebx // Global Offset Table idx
+ "3" (srcptr), // esi/rsi
+ "4" (dstptr) // edi/rdi
-#if 0 /* MMX regs (%mm0, etc.) not supported by gcc 2.7.2.3 or egcs 1.1 */
+#if defined(PNG_CLOBBER_MMX_REGS_SUPPORTED)
: "%mm0", "%mm1", "%mm2", "%mm3" // clobber list
, "%mm4", "%mm5", "%mm6", "%mm7"
#endif
);
}
- else /* mmx _not supported - Use modified C routine */
-#endif /* PNG_MMX_CODE_SUPPORTED */
+ else /* not _mmx_supported - use modified C routine */
{
register png_uint_32 i;
png_uint_32 initial_val = BPP6 * png_pass_start[png_ptr->pass];
@@ -1413,7 +1958,7 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask)
}
if (diff) /* number of leftover pixels: 3 for pngtest */
{
- final_val+=diff*BPP6;
+ final_val += diff*BPP6;
for (; i < final_val; i += stride)
{
if (rep_bytes > (int)(final_val-i))
@@ -1454,7 +1999,7 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask)
}
if (diff) /* number of leftover pixels: 3 for pngtest */
{
- final_val+=diff*BPP8;
+ final_val += diff*BPP8;
for (; i < final_val; i += stride)
{
if (rep_bytes > (int)(final_val-i))
@@ -1470,8 +2015,11 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask)
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");
+ // ERROR: SHOULD NEVER BE REACHED
+#if defined(PNG_DEBUG)
+ png_debug(1, "Internal libpng logic error (GCC "
+ "png_combine_row() pixel_depth)\n");
+#endif
break;
}
} /* end switch (png_ptr->row_info.pixel_depth) */
@@ -1510,7 +2058,6 @@ png_do_read_interlace(png_structp png_ptr)
png_debug(1, "in png_do_read_interlace (pnggccrd.c)\n");
-#if defined(PNG_MMX_CODE_SUPPORTED)
if (_mmx_supported == 2) {
#if !defined(PNG_1_0_X)
/* this should have happened in png_init_mmx_flags() already */
@@ -1518,7 +2065,6 @@ png_do_read_interlace(png_structp png_ptr)
#endif
png_mmx_support();
}
-#endif
if (row != NULL && row_info != NULL)
{
@@ -1702,12 +2248,6 @@ png_do_read_interlace(png_structp png_ptr)
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;
@@ -1723,30 +2263,106 @@ png_do_read_interlace(png_structp png_ptr)
/* New code by Nirav Chhatrapati - Intel Corporation */
-#if defined(PNG_MMX_CODE_SUPPORTED)
#if !defined(PNG_1_0_X)
- if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_INTERLACE)
- /* && _mmx_supported */ )
+ if (png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_INTERLACE)
#else
if (_mmx_supported)
#endif
{
+ int dummy_value_c; // fix 'forbidden register spilled'
+ png_bytep dummy_value_S;
+ png_bytep dummy_value_D;
+ png_bytep dummy_value_a;
+ png_bytep dummy_value_d;
+
//--------------------------------------------------------------
- if (pixel_bytes == 3)
+ if (pixel_bytes == BPP3)
{
- if (((pass == 0) || (pass == 1)) && width)
+ if (((pass == 4) || (pass == 5)) && width)
{
- int dummy_value_c; // fix 'forbidden register spilled'
- int dummy_value_S;
- int dummy_value_D;
- int dummy_value_a;
+ 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
+ __asm__ __volatile__ (
+ "sub $3, %1 \n\t"
+ "sub $9, %2 \n\t"
+ // (png_pass_inc[pass] + 1)*pixel_bytes
+
+ ".loop3_pass4: \n\t"
+ "movq (%1), %%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, (%2) \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
+ "sub $6, %1 \n\t"
+ "movd %%mm2, 8(%2) \n\t"
+ "sub $12, %2 \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)
+
+ : "0" (width_mmx), // ecx // input regs
+ "1" (sptr), // esi/rsi
+ "2" (dp), // edi/rdi
+#if defined(PNG_x86_64_USE_GOTPCREL) // formerly _const4 and _const6:
+ "3" (&_c64._amask5_3_0), // (0x0000000000FFFFFFLL)
+ "4" (&_c64._amask7_1_0) // (0x00000000000000FFLL)
+#else
+ "3" (&_amask5_3_0), // eax (0x0000000000FFFFFFLL)
+ "4" (&_amask7_1_0) // edx (0x00000000000000FFLL)
+#endif
+
+#if defined(PNG_CLOBBER_MMX_REGS_SUPPORTED)
+ : "%mm0", "%mm1" // clobber list
+ , "%mm2", "%mm3"
+#endif
+ );
+ }
+
+ sptr -= width_mmx*BPP3;
+ dp -= width_mmx*2*BPP3;
+ for (i = width; i; i--)
+ {
+ png_byte v[8];
+ int j;
+
+ png_memcpy(v, sptr, BPP3);
+ for (j = 0; j < png_pass_inc[pass]; j++)
+ {
+ png_memcpy(dp, v, BPP3);
+ dp -= BPP3;
+ }
+ sptr -= BPP3;
+ }
+ }
+ else if (((pass == 2) || (pass == 3)) && width)
+ {
__asm__ __volatile__ (
- "subl $21, %%edi \n\t"
+ "sub $9, %2 \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
+ ".loop3_pass2: \n\t"
+ "movd (%1), %%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
@@ -1755,19 +2371,13 @@ png_do_read_interlace(png_structp png_ptr)
"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"
+ "movq %%mm0, 4(%2) \n\t"
+ "psrlq $16, %%mm0 \n\t" // z z 2 1 0 2 1 0
+ "sub $3, %1 \n\t"
+ "movd %%mm0, (%2) \n\t"
+ "sub $12, %2 \n\t"
"decl %%ecx \n\t"
- "jnz .loop3_pass0 \n\t"
+ "jnz .loop3_pass2 \n\t"
"EMMS \n\t" // DONE
: "=c" (dummy_value_c), // output regs (dummy)
@@ -1775,32 +2385,29 @@ png_do_read_interlace(png_structp png_ptr)
"=D" (dummy_value_D),
"=a" (dummy_value_a)
+ : "0" (width), // ecx // input regs
+ "1" (sptr), // esi/rsi
+ "2" (dp), // edi/rdi
+#if defined(PNG_x86_64_USE_GOTPCREL) // formerly _const4:
+ "3" (&_c64._amask5_3_0) // (0x0000000000FFFFFFLL)
+#else
+ "3" (&_amask5_3_0) // eax (0x0000000000FFFFFFLL)
+#endif
- : "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 */
+#if defined(CLOBBER_MMX_REGS_SUPPORTED)
: "%mm0", "%mm1", "%mm2" // clobber list
- , "%mm3", "%mm4"
#endif
);
}
- else if (((pass == 2) || (pass == 3)) && width)
+ else if (width) // && ((pass == 0) || (pass == 1))
{
- int dummy_value_c; // fix 'forbidden register spilled'
- int dummy_value_S;
- int dummy_value_D;
- int dummy_value_a;
-
__asm__ __volatile__ (
- "subl $9, %%edi \n\t"
+ "sub $21, %2 \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
+ ".loop3_pass0: \n\t"
+ "movd (%1), %%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
@@ -1808,13 +2415,19 @@ png_do_read_interlace(png_structp png_ptr)
"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"
+ "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(%2) \n\t"
+ "psrlq $32, %%mm0 \n\t" // z z z z 0 2 1 0
+ "movq %%mm3, 8(%2) \n\t"
+ "punpckldq %%mm4, %%mm0 \n\t" // 1 0 2 1 0 2 1 0
+ "sub $3, %1 \n\t"
+ "movq %%mm0, (%2) \n\t"
+ "sub $24, %2 \n\t"
"decl %%ecx \n\t"
- "jnz .loop3_pass2 \n\t"
+ "jnz .loop3_pass0 \n\t"
"EMMS \n\t" // DONE
: "=c" (dummy_value_c), // output regs (dummy)
@@ -1822,273 +2435,227 @@ png_do_read_interlace(png_structp png_ptr)
"=D" (dummy_value_D),
"=a" (dummy_value_a)
- : "1" (sptr), // esi // input regs
- "2" (dp), // edi
- "0" (width), // ecx
- "3" (&_const4) // (0x0000000000FFFFFFLL)
+ : "0" (width), // ecx // input regs
+ "1" (sptr), // esi/rsi
+ "2" (dp), // edi/rdi
+#if defined(PNG_x86_64_USE_GOTPCREL) // formerly _const4:
+ "3" (&_c64._amask5_3_0) // (0x0000000000FFFFFFLL)
+#else
+ "3" (&_amask5_3_0) // eax (0x0000000000FFFFFFLL)
+#endif
-#if 0 /* %mm0, ..., %mm2 not supported by gcc 2.7.2.3 or egcs 1.1 */
+#if defined(PNG_CLOBBER_MMX_REGS_SUPPORTED)
: "%mm0", "%mm1", "%mm2" // clobber list
+ , "%mm3", "%mm4"
#endif
);
}
- else if (width) /* && ((pass == 4) || (pass == 5)) */
+ } /* end of pixel_bytes == 3 */
+
+ //--------------------------------------------------------------
+ else if (pixel_bytes == BPP4)
+ {
+ if (((pass == 4) || (pass == 5)) && width)
{
- 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
+ int width_mmx = ((width >> 1) << 1) ;
+ width -= width_mmx; // 0,1 pixels => 0,4 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;
- int dummy_value_a;
- int dummy_value_d;
-
__asm__ __volatile__ (
- "subl $3, %%esi \n\t"
- "subl $9, %%edi \n\t"
- // (png_pass_inc[pass] + 1)*pixel_bytes
+ "sub $4, %1 \n\t"
+ "sub $12, %2 \n\t"
- ".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"
+ ".loop4_pass4: \n\t"
+ "movq (%1), %%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, (%2) \n\t"
+ "sub $8, %1 \n\t"
+ "movq %%mm1, 8(%2) \n\t"
+ "sub $16, %2 \n\t"
"subl $2, %%ecx \n\t"
- "jnz .loop3_pass4 \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),
- "=a" (dummy_value_a),
- "=d" (dummy_value_d)
+ "=D" (dummy_value_D)
- : "1" (sptr), // esi // input regs
- "2" (dp), // edi
- "0" (width_mmx), // ecx
- "3" (&_const4), // 0x0000000000FFFFFFLL
- "4" (&_const6) // 0x00000000000000FFLL
+ : "0" (width_mmx), // ecx // input regs
+ "1" (sptr), // esi/rsi
+ "2" (dp) // edi/rdi
-#if 0 /* %mm0, ..., %mm3 not supported by gcc 2.7.2.3 or egcs 1.1 */
+#if defined(CLOBBER_MMX_REGS_SUPPORTED)
: "%mm0", "%mm1" // clobber list
- , "%mm2", "%mm3"
#endif
);
}
- sptr -= width_mmx*3;
- dp -= width_mmx*6;
+ sptr -= (width_mmx*BPP4 - BPP4); // sign fixed
+ dp -= (width_mmx*2*BPP4 - BPP4); // sign fixed
for (i = width; i; i--)
{
png_byte v[8];
int j;
-
- png_memcpy(v, sptr, 3);
+ sptr -= BPP4;
+ png_memcpy(v, sptr, BPP4);
for (j = 0; j < png_pass_inc[pass]; j++)
{
- png_memcpy(dp, v, 3);
- dp -= 3;
+ dp -= BPP4;
+ png_memcpy(dp, v, BPP4);
}
- sptr -= 3;
}
}
- } /* end of pixel_bytes == 3 */
-
- //--------------------------------------------------------------
- else if (pixel_bytes == 1)
- {
- if (((pass == 0) || (pass == 1)) && width)
+ else if (((pass == 2) || (pass == 3)) && width)
{
- int width_mmx = ((width >> 2) << 2);
- width -= width_mmx; // 0-3 pixels => 0-3 bytes
+ 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 $3, %%esi \n\t"
- "subl $31, %%edi \n\t"
+ "sub $4, %1 \n\t"
+ "sub $28, %2 \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"
+ ".loop4_pass2: \n\t"
+ "movq (%1), %%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, (%2) \n\t"
+ "movq %%mm0, 8(%2) \n\t"
+ "movq %%mm1, 16(%2) \n\t"
+ "movq %%mm1, 24(%2) \n\t"
+ "sub $8, %1 \n\t"
+ "sub $32, %2 \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
+ : "0" (width_mmx), // ecx // input regs
+ "1" (sptr), // esi/rsi
+ "2" (dp) // edi/rdi
-#if 0 /* %mm0, ..., %mm4 not supported by gcc 2.7.2.3 or egcs 1.1 */
- : "%mm0", "%mm1", "%mm2" // clobber list
- , "%mm3", "%mm4"
+#if defined(CLOBBER_MMX_REGS_SUPPORTED)
+ : "%mm0", "%mm1" // clobber list
#endif
);
}
- sptr -= width_mmx;
- dp -= width_mmx*8;
+ 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;
-
- /* 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:
- */
-
+ sptr -= 4;
+ png_memcpy(v, sptr, 4);
for (j = 0; j < png_pass_inc[pass]; j++)
{
- *dp-- = *sptr;
+ dp -= 4;
+ png_memcpy(dp, v, 4);
}
- --sptr;
}
}
- else if (((pass == 2) || (pass == 3)) && width)
+ else if (width) // && ((pass == 0) || (pass == 1))
{
- int width_mmx = ((width >> 2) << 2);
- width -= width_mmx; // 0-3 pixels => 0-3 bytes
+ 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 $3, %%esi \n\t"
- "subl $15, %%edi \n\t"
+ "sub $4, %1 \n\t"
+ "sub $60, %2 \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"
+ ".loop4_pass0: \n\t"
+ "movq (%1), %%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, (%2) \n\t"
+ "movq %%mm0, 8(%2) \n\t"
+ "movq %%mm0, 16(%2) \n\t"
+ "movq %%mm0, 24(%2) \n\t"
+ "movq %%mm1, 32(%2) \n\t"
+ "movq %%mm1, 40(%2) \n\t"
+ "movq %%mm1, 48(%2) \n\t"
+ "sub $8, %1 \n\t"
+ "movq %%mm1, 56(%2) \n\t"
+ "sub $64, %2 \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
+ : "0" (width_mmx), // ecx // input regs
+ "1" (sptr), // esi/rsi
+ "2" (dp) // edi/rdi
-#if 0 /* %mm0, %mm1 not supported by gcc 2.7.2.3 or egcs 1.1 */
+#if defined(PNG_CLOBBER_MMX_REGS_SUPPORTED)
: "%mm0", "%mm1" // clobber list
#endif
);
}
- sptr -= width_mmx;
- dp -= width_mmx*4;
+ 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-- = *sptr;
+ dp -= 4;
+ png_memcpy(dp, v, 4);
}
- --sptr;
}
}
- else if (width) /* && ((pass == 4) || (pass == 5)) */
+ } /* end of pixel_bytes == 4 */
+
+ //--------------------------------------------------------------
+ else if (pixel_bytes == 1)
+ {
+ if (((pass == 4) || (pass == 5)) && width)
{
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"
+ "sub $7, %1 \n\t"
+ "sub $15, %2 \n\t"
".loop1_pass4: \n\t"
- "movq (%%esi), %%mm0 \n\t" // 7 6 5 4 3 2 1 0
+ "movq (%1), %%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"
+ "movq %%mm1, 8(%2) \n\t"
+ "sub $8, %1 \n\t"
+ "movq %%mm0, (%2) \n\t"
+ "sub $16, %2 \n\t"
"subl $8, %%ecx \n\t"
"jnz .loop1_pass4 \n\t"
"EMMS \n\t" // DONE
- : "=c" (dummy_value_c), // output regs (none)
+ : "=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
+ : "0" (width_mmx), // ecx // input regs
+ "1" (sptr), // esi/rsi
+ "2" (dp) // edi/rdi
-#if 0 /* %mm0, %mm1 not supported by gcc 2.7.2.3 or egcs 1.1 */
+#if defined(PNG_CLOBBER_MMX_REGS_SUPPORTED)
: "%mm0", "%mm1" // clobber list
#endif
);
@@ -2107,147 +2674,157 @@ png_do_read_interlace(png_structp png_ptr)
--sptr;
}
}
- } /* end of pixel_bytes == 1 */
-
- //--------------------------------------------------------------
- else if (pixel_bytes == 2)
- {
- if (((pass == 0) || (pass == 1)) && width)
+ else if (((pass == 2) || (pass == 3)) && width)
{
- int width_mmx = ((width >> 1) << 1);
- width -= width_mmx; // 0,1 pixels => 0,2 bytes
+ 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 $2, %%esi \n\t"
- "subl $30, %%edi \n\t"
+ "sub $3, %1 \n\t"
+ "sub $15, %2 \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"
+ ".loop1_pass2: \n\t"
+ "movd (%1), %%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, (%2) \n\t"
+ "sub $4, %1 \n\t"
+ "movq %%mm1, 8(%2) \n\t"
+ "sub $16, %2 \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
+ : "0" (width_mmx), // ecx // input regs
+ "1" (sptr), // esi/rsi
+ "2" (dp) // edi/rdi
-#if 0 /* %mm0, %mm1 not supported by gcc 2.7.2.3 or egcs 1.1 */
+#if defined(PNG_CLOBBER_MMX_REGS_SUPPORTED)
: "%mm0", "%mm1" // clobber list
#endif
);
}
- sptr -= (width_mmx*2 - 2); // sign fixed
- dp -= (width_mmx*16 - 2); // sign fixed
+ sptr -= width_mmx;
+ dp -= width_mmx*4;
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);
+ *dp-- = *sptr;
}
+ --sptr;
}
}
- else if (((pass == 2) || (pass == 3)) && width)
+ else if (width) // && ((pass == 0) || (pass == 1))
{
- int width_mmx = ((width >> 1) << 1) ;
- width -= width_mmx; // 0,1 pixels => 0,2 bytes
+ 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 $2, %%esi \n\t"
- "subl $14, %%edi \n\t"
+ "sub $3, %1 \n\t"
+ "sub $31, %2 \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"
+ ".loop1_pass0: \n\t"
+ "movd (%1), %%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, (%2) \n\t"
+ "punpckhwd %%mm2, %%mm2 \n\t" // 3 3 3 3 2 2 2 2
+ "movq %%mm3, 8(%2) \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(%2) \n\t"
+ "sub $4, %1 \n\t"
+ "movq %%mm4, 24(%2) \n\t"
+ "sub $32, %2 \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
+ : "0" (width_mmx), // ecx // input regs
+ "1" (sptr), // esi/rsi
+ "2" (dp) // edi/rdi
-#if 0 /* %mm0, %mm1 not supported by gcc 2.7.2.3 or egcs 1.1 */
- : "%mm0", "%mm1" // clobber list
+#if defined(PNG_CLOBBER_MMX_REGS_SUPPORTED)
+ : "%mm0", "%mm1", "%mm2" // clobber list
+ , "%mm3", "%mm4"
#endif
);
}
- sptr -= (width_mmx*2 - 2); // sign fixed
- dp -= (width_mmx*8 - 2); // sign fixed
+ sptr -= width_mmx;
+ dp -= width_mmx*8;
for (i = width; i; i--)
{
- png_byte v[8];
int j;
- sptr -= 2;
- png_memcpy(v, sptr, 2);
+
+ /* 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 -= 2;
- png_memcpy(dp, v, 2);
+ *dp-- = *sptr;
}
+ --sptr;
}
}
- else if (width) // pass == 4 or 5
+ } /* end of pixel_bytes == 1 */
+
+ //--------------------------------------------------------------
+ else if (pixel_bytes == BPP2)
+ {
+ if (((pass == 4) || (pass == 5)) && 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 $6, %%edi \n\t"
+ "sub $2, %1 \n\t"
+ "sub $6, %2 \n\t"
".loop2_pass4: \n\t"
- "movd (%%esi), %%mm0 \n\t" // x x x x 3 2 1 0
+ "movd (%1), %%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"
+ "sub $4, %1 \n\t"
+ "movq %%mm0, (%2) \n\t"
+ "sub $8, %2 \n\t"
"subl $2, %%ecx \n\t"
"jnz .loop2_pass4 \n\t"
"EMMS \n\t" // DONE
@@ -2256,255 +2833,172 @@ png_do_read_interlace(png_structp png_ptr)
"=S" (dummy_value_S),
"=D" (dummy_value_D)
- : "1" (sptr), // esi // input regs
- "2" (dp), // edi
- "0" (width_mmx) // ecx
+ : "0" (width_mmx), // ecx // input regs
+ "1" (sptr), // esi/rsi
+ "2" (dp) // edi/rdi
-#if 0 /* %mm0 not supported by gcc 2.7.2.3 or egcs 1.1 */
+#if defined(PNG_CLOBBER_MMX_REGS_SUPPORTED)
: "%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
+ sptr -= (width_mmx*BPP2 - BPP2); // sign fixed
+ dp -= (width_mmx*2*BPP2 - BPP2); // sign fixed
for (i = width; i; i--)
{
png_byte v[8];
int j;
- sptr -= 4;
- png_memcpy(v, sptr, 4);
+ sptr -= BPP2;
+ png_memcpy(v, sptr, BPP2);
for (j = 0; j < png_pass_inc[pass]; j++)
{
- dp -= 4;
- png_memcpy(dp, v, 4);
+ dp -= BPP2;
+ png_memcpy(dp, v, BPP2);
}
}
}
else if (((pass == 2) || (pass == 3)) && width)
{
- int width_mmx = ((width >> 1) << 1);
- width -= width_mmx; // 0,1 pixels => 0,4 bytes
+ 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 $4, %%esi \n\t"
- "subl $28, %%edi \n\t"
+ "sub $2, %1 \n\t"
+ "sub $14, %2 \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"
+ ".loop2_pass2: \n\t"
+ "movd (%1), %%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, (%2) \n\t"
+ "sub $4, %1 \n\t"
+ "movq %%mm1, 8(%2) \n\t"
+ "sub $16, %2 \n\t"
"subl $2, %%ecx \n\t"
- "jnz .loop4_pass2 \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
+ : "0" (width_mmx), // ecx // input regs
+ "1" (sptr), // esi/rsi
+ "2" (dp) // edi/rdi
-#if 0 /* %mm0, %mm1 not supported by gcc 2.7.2.3 or egcs 1.1 */
+#if defined(CLOBBER_MMX_REGS_SUPPORTED)
: "%mm0", "%mm1" // clobber list
#endif
);
}
- sptr -= (width_mmx*4 - 4); // sign fixed
- dp -= (width_mmx*16 - 4); // sign fixed
+ 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 -= 4;
- png_memcpy(v, sptr, 4);
+ sptr -= 2;
+ png_memcpy(v, sptr, 2);
for (j = 0; j < png_pass_inc[pass]; j++)
{
- dp -= 4;
- png_memcpy(dp, v, 4);
+ dp -= 2;
+ png_memcpy(dp, v, 2);
}
}
}
- else if (width) // pass == 4 or 5
+ else if (width) // && ((pass == 0) || (pass == 1))
{
- int width_mmx = ((width >> 1) << 1) ;
- width -= width_mmx; // 0,1 pixels => 0,4 bytes
+ 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 $4, %%esi \n\t"
- "subl $12, %%edi \n\t"
+ "sub $2, %1 \n\t"
+ "sub $30, %2 \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"
+ ".loop2_pass0: \n\t"
+ "movd (%1), %%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, (%2) \n\t"
+ "movq %%mm0, 8(%2) \n\t"
+ "movq %%mm1, 16(%2) \n\t"
+ "sub $4, %1 \n\t"
+ "movq %%mm1, 24(%2) \n\t"
+ "sub $32, %2 \n\t"
"subl $2, %%ecx \n\t"
- "jnz .loop4_pass4 \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
+ : "0" (width_mmx), // ecx // input regs
+ "1" (sptr), // esi/rsi
+ "2" (dp) // edi/rdi
-#if 0 /* %mm0, %mm1 not supported by gcc 2.7.2.3 or egcs 1.1 */
+#if defined(CLOBBER_MMX_REGS_SUPPORTED)
: "%mm0", "%mm1" // clobber list
#endif
);
}
- sptr -= (width_mmx*4 - 4); // sign fixed
- dp -= (width_mmx*8 - 4); // sign fixed
+ 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 -= 4;
- png_memcpy(v, sptr, 4);
+ sptr -= 2;
+ png_memcpy(v, sptr, 2);
for (j = 0; j < png_pass_inc[pass]; j++)
{
- dp -= 4;
- png_memcpy(dp, v, 4);
+ dp -= 2;
+ png_memcpy(dp, v, 2);
}
}
}
- } /* end of pixel_bytes == 4 */
+ } /* end of pixel_bytes == 2 */
//--------------------------------------------------------------
- else if (pixel_bytes == 8)
+ else if (pixel_bytes == BPP8)
{
// 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)
+ if (((pass == 4) || (pass == 5)) && 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 ...
+ // dest is 16-byte 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"
+ "sub $8, %2 \n\t" // start of last block
+
+ ".loop8_pass4: \n\t"
+ "movq (%1), %%mm0 \n\t" // 7 6 5 4 3 2 1 0
+ "movq %%mm0, (%2) \n\t"
+ "sub $8, %1 \n\t"
+ "movq %%mm0, 8(%2) \n\t"
+ "sub $16, %2 \n\t"
"decl %%ecx \n\t"
- "jnz .loop8_pass0 \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
+ : "0" (width), // ecx // input regs
+ "1" (sptr), // esi/rsi
+ "2" (dp) // edi/rdi
-#if 0 /* %mm0 not supported by gcc 2.7.2.3 or egcs 1.1 */
+#if defined(CLOBBER_MMX_REGS_SUPPORTED)
: "%mm0" // clobber list
#endif
);
@@ -2515,235 +3009,211 @@ png_do_read_interlace(png_structp png_ptr)
// 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
+ __asm__ __volatile__ (
+ "sub $24, %2 \n\t" // start of last block
+
+ ".loop8_pass2: \n\t"
+ "movq (%1), %%mm0 \n\t" // 7 6 5 4 3 2 1 0
+ "movq %%mm0, (%2) \n\t"
+ "movq %%mm0, 8(%2) \n\t"
+ "movq %%mm0, 16(%2) \n\t"
+ "sub $8, %1 \n\t"
+ "movq %%mm0, 24(%2) \n\t"
+ "sub $32, %2 \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)
+ : "=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
+ : "0" (width), // ecx // input regs
+ "1" (sptr), // esi/rsi
+ "2" (dp) // edi/rdi
-#if 0 /* %mm0 not supported by gcc 2.7.2.3 or egcs 1.1 */
- : "%mm0" // clobber list
+#if defined(PNG_CLOBBER_MMX_REGS_SUPPORTED)
+ : "%mm0" // clobber list
#endif
- );
- }
+ );
}
- else if (width) // pass == 4 or 5
+ else if (width) // && ((pass == 0) || (pass == 1))
{
// 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;
+ // dest is 64-byte RRGGBBAA RRGGBBAA RRGGBBAA RRGGBBAA ...
+ __asm__ __volatile__ (
+ "sub $56, %2 \n\t" // start of last block
- __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
+ ".loop8_pass0: \n\t"
+ "movq (%1), %%mm0 \n\t" // 7 6 5 4 3 2 1 0
+ "movq %%mm0, (%2) \n\t"
+ "movq %%mm0, 8(%2) \n\t"
+ "movq %%mm0, 16(%2) \n\t"
+ "movq %%mm0, 24(%2) \n\t"
+ "movq %%mm0, 32(%2) \n\t"
+ "movq %%mm0, 40(%2) \n\t"
+ "movq %%mm0, 48(%2) \n\t"
+ "sub $8, %1 \n\t"
+ "movq %%mm0, 56(%2) \n\t"
+ "sub $64, %2 \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)
+ : "=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
+ : "0" (width), // ecx // input regs
+ "1" (sptr), // esi/rsi
+ "2" (dp) // edi/rdi
-#if 0 /* %mm0 not supported by gcc 2.7.2.3 or egcs 1.1 */
- : "%mm0" // clobber list
+#if defined(PNG_CLOBBER_MMX_REGS_SUPPORTED)
+ : "%mm0" // clobber list
#endif
- );
- }
+ );
}
-
} /* end of pixel_bytes == 8 */
//--------------------------------------------------------------
- else if (pixel_bytes == 6)
+ else if (pixel_bytes == BPP6) // why no MMX for this case?
{
for (i = width; i; i--)
{
png_byte v[8];
int j;
- png_memcpy(v, sptr, 6);
+ png_memcpy(v, sptr, BPP6);
for (j = 0; j < png_pass_inc[pass]; j++)
{
- png_memcpy(dp, v, 6);
- dp -= 6;
+ png_memcpy(dp, v, BPP6);
+ dp -= BPP6;
}
- sptr -= 6;
+ sptr -= BPP6;
}
} /* 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;
- }
+ // ERROR: SHOULD NEVER BE REACHED
+#if defined(PNG_DEBUG)
+ png_debug(1, "Internal libpng logic error (GCC "
+ "png_do_read_interlace() _mmx_supported)\n");
+#endif
}
+
} // 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)
+ if (pixel_bytes == BPP3)
{
for (i = width; i; i--)
{
+ png_byte v[8];
int j;
+ png_memcpy(v, sptr, BPP3);
for (j = 0; j < png_pass_inc[pass]; j++)
{
- *dp-- = *sptr;
+ png_memcpy(dp, v, BPP3);
+ dp -= BPP3;
}
- --sptr;
+ sptr -= BPP3;
}
}
- else if (pixel_bytes == 3)
+ else if (pixel_bytes == BPP4)
{
for (i = width; i; i--)
{
png_byte v[8];
int j;
- png_memcpy(v, sptr, 3);
+ png_memcpy(v, sptr, BPP4);
for (j = 0; j < png_pass_inc[pass]; j++)
{
- png_memcpy(dp, v, 3);
- dp -= 3;
+#if defined(PNG_DEBUG) && defined(PNG_1_0_X) // row_buf_size gone in 1.2.x
+ if (dp < row || dp+3 > row+png_ptr->row_buf_size)
+ {
+ printf("dp out of bounds: row=%10p, dp=%10p, "
+ "rp=%10p\n", row, dp, row+png_ptr->row_buf_size);
+ printf("row_buf_size=%lu\n", png_ptr->row_buf_size);
+ }
+#endif
+ png_memcpy(dp, v, BPP4);
+ dp -= BPP4;
}
- sptr -= 3;
+ sptr -= BPP4;
}
}
- else if (pixel_bytes == 2)
+ else if (pixel_bytes == 1)
{
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;
+ *dp-- = *sptr;
}
- sptr -= 2;
+ --sptr;
}
}
- else if (pixel_bytes == 4)
+ else if (pixel_bytes == BPP2)
{
for (i = width; i; i--)
{
png_byte v[8];
int j;
- png_memcpy(v, sptr, 4);
+ png_memcpy(v, sptr, BPP2);
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;
+ png_memcpy(dp, v, BPP2);
+ dp -= BPP2;
}
- sptr -= 4;
+ sptr -= BPP2;
}
}
- else if (pixel_bytes == 6)
+ else if (pixel_bytes == BPP6)
{
for (i = width; i; i--)
{
png_byte v[8];
int j;
- png_memcpy(v, sptr, 6);
+ png_memcpy(v, sptr, BPP6);
for (j = 0; j < png_pass_inc[pass]; j++)
{
- png_memcpy(dp, v, 6);
- dp -= 6;
+ png_memcpy(dp, v, BPP6);
+ dp -= BPP6;
}
- sptr -= 6;
+ sptr -= BPP6;
}
}
- else if (pixel_bytes == 8)
+ else if (pixel_bytes == BPP8)
{
for (i = width; i; i--)
{
png_byte v[8];
int j;
- png_memcpy(v, sptr, 8);
+ png_memcpy(v, sptr, BPP8);
for (j = 0; j < png_pass_inc[pass]; j++)
{
- png_memcpy(dp, v, 8);
- dp -= 8;
+ png_memcpy(dp, v, BPP8);
+ dp -= BPP8;
}
- sptr -= 8;
+ sptr -= BPP8;
}
}
- else /* GRR: should never be reached */
+ 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;
- }
+ // ERROR: SHOULD NEVER BE REACHED
+#if defined(PNG_DEBUG)
+ png_debug(1, "Internal libpng logic error (GCC "
+ "png_do_read_interlace() !_mmx_supported)\n");
+#endif
}
} /* end if (MMX not supported) */
break;
- }
+ } /* end default (8-bit or larger) */
} /* end switch (row_info->pixel_depth) */
row_info->width = final_width;
@@ -2759,19 +3229,8 @@ png_do_read_interlace(png_structp png_ptr)
#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;
+#if defined(PNG_MMX_READ_FILTER_AVG_SUPPORTED)
-#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 //
@@ -2784,90 +3243,117 @@ static void /* PRIVATE */
png_read_filter_row_mmx_avg(png_row_infop row_info, png_bytep row,
png_bytep prev_row)
{
+ unsigned FullLength, MMXLength; // png_uint_32 is actually 64-bit on x86-64
int bpp;
+ int dummy_value_a;
int dummy_value_c; // fix 'forbidden register 2 (cx) was spilled' error
- int dummy_value_S;
- int dummy_value_D;
+ int dummy_value_d;
+ png_bytep dummy_value_S;
+ png_bytep dummy_value_D;
+ int diff; // __attribute__((used));
- bpp = (row_info->pixel_depth + 7) >> 3; // get # bytes per pixel
- _FullLength = row_info->rowbytes; // # of bytes to filter
+ bpp = (row_info->pixel_depth + 7) >> 3; // calc number of bytes per pixel
+ FullLength = row_info->rowbytes; // number of bytes to filter
__asm__ __volatile__ (
+ "avg_top: \n\t"
+ SAVE_GOT_ebx
+ SAVE_r15
+ SAVE_ebp
// initialize address pointers and offset
-#ifdef __PIC__
- "pushl %%ebx \n\t" // save index to Global Offset Table
-#endif
-//pre "movl row, %%edi \n\t" // edi: Avg(x)
+//pre "movl row, %5 \n\t" // edi/rdi: ptr to 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"
+//pre "movl prev_row, %4 \n\t" // esi/rsi: ptr to Prior(x)
+ "mov %5, " PDX " \n\t" // copy of row ptr...
+//pre "subl bpp, " PDX " \n\t" // (bpp is preloaded into ecx)
+ "sub " PCX "," PDX " \n\t" // edx/rdx: ptr to Raw(x-bpp)
+//pre "movl FullLength, %%eax \n\t" // bring in via eax...
+ SAVE_FullLength // ...but store for later use
+ "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)
+ "movb (%4," PBX ",), %%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
+ "addb -1(%5," PBX ",), %%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
+ "movb %%al, -1(%5," PBX ",) \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
+ // get # of bytes to alignment (32-bit mask _would_ be good enough
+ // [computing delta], but 32-bit ops are zero-extended on 64-bit, argh)
+ // (if swapped edx and ebp, could do 8-bit or 16-bit mask...FIXME?)
+ "mov %5, " PBP " \n\t" // take start of row
+ "add " PBX "," PBP " \n\t" // add bpp
+ "add $0xf, " PBP " \n\t" // add 7+8 to incr past alignment bdry
+// "andl $0xfffffff8, %%ebp \n\t" // mask to alignment boundary (32-bit!)
+ CLEAR_BOTTOM_3_BITS PBP "\n\t" // mask to alignment boundary
+ "sub %5, " PBP " \n\t" // subtract row ptr again => ebp =
+ "jz avg_go \n\t" // target value of ebx at alignment
+
+ "xorl %%ecx, %%ecx \n\t"
// 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)
+ "movb (%4," PBX ",), %%cl \n\t" // load cl with Prior(x)
+ "movb (" PDX "," PBX ",), %%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
+ "addb -1(%5," PBX ",), %%al \n\t" // add Avg(x); -1 to offset inc ebx
+ "cmpl %%ebp, %%ebx \n\t" // check if at alignment boundary
+ "movb %%al, -1(%5," PBX ",) \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"
+ RESTORE_FullLength "%%eax \n\t" // FullLength -> eax
+ "movl %%eax, %%ecx \n\t" // copy -> ecx
"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__
- "popl %%ebx \n\t" // restore index to Global Offset Table
-#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...)
+ "subl %%eax, %%ecx \n\t" // sub over-bytes from original length
+//out "movl %%ecx, MMXLength \n\t"
+ "movl %%ebp, %%eax \n\t" // ebp = diff, but no reg constraint(?)
+ RESTORE_ebp // (could swap ebp and edx functions)
+ RESTORE_r15
+ RESTORE_GOT_ebx
+
+// "There is no way for you to specify that an input operand is modified
+// without also specifying it as an output operand." [makes sense]
+
+// "Unless an output operand has the `&' constraint modifier, GCC may
+// allocate it in the same register as an unrelated input operand, on the
+// assumption the inputs are consumed before the outputs are produced."
+// [trying to _force_ this]
+
+// "`=' Means that this operand is write-only for this instruction:
+// the previous value is discarded and replaced by output data."
+// [operand == variable name, presumably]
+
+ // output regs
+ // these are operands 0-1 (originally 0-3):
+ : "=c" (MMXLength), // %0 -> %0
+ "=a" (diff) // %3 -> %1
+// "=S" (dummy_value_S), // %1 -> GONE
+// "=D" (dummy_value_D), // %2 -> GONE
+
+ // input regs
+ // these are operands 2-5 (originally 4-7); two of their constraints say
+ // they must go in same places as operands 0-1 (originally 0-3) above:
+ : "0" (bpp), // %4 -> %2 ecx
+ "1" (FullLength), // %7 -> %3 eax
+ "S" (prev_row), // %5 -> %4 esi/rsi
+ "D" (row) // %6 -> %5 edi/rdi
+
+ : "%edx" // clobber list
+ _CLOBBER_r15
+ _CLOBBER_ebp
+ _CLOBBER_GOT_ebx
);
// now do the math for the rest of the row
@@ -2875,152 +3361,149 @@ png_read_filter_row_mmx_avg(png_row_infop row_info, png_bytep row,
{
case 3:
{
- _ActiveMask.use = 0x0000000000ffffffLL;
- _ShiftBpp.use = 24; // == 3 * 8
- _ShiftRem.use = 40; // == 64 - 24
+// _ShiftBpp = 24; // == 3 * 8
+// _ShiftRem = 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)
+ LOAD_GOT_rbp
+ "movq " AMASK5_3_0 ", %%mm7 \n\t" // _amask5_3_0 -> mm7
+// preload "movl diff, %%ecx \n\t" // ecx: x = offset to
+ // alignment boundary
+ "movq " LB_CARRY_MASK ", %%mm5 \n\t" // [interleave for parallel.?]
+// preload "movl row, %1 \n\t" // edi: Avg(x)
+ "movq " HB_CLEAR_MASK ", %%mm4 \n\t" // _HBClearMask -> mm4
+// preload "movl prev_row, %0 \n\t" // esi: Prior(x)
+ RESTORE_rbp
// 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)
+ "movq -8(%1," PCX ",), %%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)
+ "movq (%1," PCX ",), %%mm0 \n\t" // load mm0 with Avg(x)
+ "movq %%mm5, %%mm3 \n\t"
+ "psrlq $40, %%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
+ "movq (%0," PCX ",), %%mm1 \n\t" // load mm1 with Prior(x)
+ "movq %%mm7, %%mm6 \n\t"
+ "pand %%mm1, %%mm3 \n\t" // get lsb for each prevrow 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
+ "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)
+ "pand %%mm2, %%mm1 \n\t" // get LBCarrys for each byte
+ // where both lsb's were == 1
+ // (valid only 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)
+ "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
+ "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
+ // 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
+ "psllq $24, %%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
+ "movq %%mm0, %%mm2 \n\t" // mov updated Raws to mm2
+ "psllq $24, %%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)
+ "pand %%mm2, %%mm1 \n\t" // get LBCarrys for each byte
+ // where both lsb's were == 1
+ // (valid only 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)
+ "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
+ "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
+ // 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
+ "psllq $24, %%mm6 \n\t" // shift mm6 mask to cover last
+ // two bytes
+ "movq %%mm0, %%mm2 \n\t" // mov updated Raws to mm2
+ "psllq $24, %%mm2 \n\t" // shift data to pos. correctly
+ // Data need be shifted only once here to
// get the correct x-bpp offset.
- "movq %%mm3, %%mm1 \n\t" // now use mm1 for getting
+ "movq %%mm3, %%mm1 \n\t" // now use mm1 for getting
// LBCarrys
- "pand %%mm2, %%mm1 \n\t" // get LBCarrys for each byte
+ "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)
+ "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
+ "pand %%mm6, %%mm2 \n\t" // leave only Active Group 2
// bytes to add to Avg
- "addl $8, %%ecx \n\t"
+ "addl $8, %%ecx \n\t"
"paddb %%mm2, %%mm0 \n\t" // add (Raw/2) + LBCarrys to
- // Avg for each Active
- // byte
+ // Avg for each Active byte
// now ready to write back to memory
- "movq %%mm0, -8(%%edi,%%ecx,) \n\t"
+ "movq %%mm0, -8(%1," PCX ",) \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
+ "cmpl %%eax, %%ecx \n\t" // MMXLength
+ "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)
+ : "=S" (dummy_value_S), // output regs (dummy)
+ "=D" (dummy_value_D),
+ "=c" (dummy_value_c),
+ "=a" (dummy_value_a)
- : "0" (prev_row), // esi // input regs
- "1" (row) // edi
+ : "0" (prev_row), // esi/rsi // input regs
+ "1" (row), // edi/rdi
+ "2" (diff), // ecx
+ "3" (MMXLength) // eax
- : "%ecx" // clobber list
-#if 0 /* %mm0, ..., %mm7 not supported by gcc 2.7.2.3 or egcs 1.1 */
- , "%mm0", "%mm1", "%mm2", "%mm3"
+#if defined(CLOBBER_MMX_REGS_SUPPORTED)
+ : "%mm0", "%mm1", "%mm2", "%mm3" // clobber list
, "%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;
+ case 4: // formerly shared with 6 bpp case via _ShiftBpp and _ShiftRem,
+ { // but loop uses all 8 MMX regs, and psrlq/psllq require 64-bit
+ // mem (PIC/.so problems), MMX reg (none left), or immediate
+// _ShiftBpp = bpp << 3; // 32 (psllq)
+// _ShiftRem = 64 - _ShiftBpp; // 32 (psrlq)
__asm__ __volatile__ (
- "movq _HBClearMask, %%mm4 \n\t"
-
+ LOAD_GOT_rbp
+ "movq " HB_CLEAR_MASK ", %%mm4 \n\t" // _HBClearMask -> mm4
+ "movq " LB_CARRY_MASK ", %%mm5 \n\t" // _LBCarryMask -> mm5
// 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
+// preload "movl diff, %%ecx \n\t" // ecx: x = offset to
+ // alignment boundary
+ "movq " AMASK0_8_0 ", %%mm7 \n\t" // _amask0_8_0 -> mm7
+ RESTORE_rbp
+
+ // ... and clear all bytes except for 1st active group
+// preload "movl row, %1 \n\t" // edi: Avg(x)
+ "psrlq $32, %%mm7 \n\t" // was _ShiftRem
+// preload "movl prev_row, %0 \n\t" // esi: Prior(x)
+ "movq %%mm7, %%mm6 \n\t"
+ "psllq $32, %%mm6 \n\t" // 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)
+ "movq -8(%1," PCX ",), %%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"
+ "movq (%1," PCX ",), %%mm0 \n\t"
+ "psrlq $32, %%mm2 \n\t" // shift data to pos. correctly
+ "movq (%0," PCX ",), %%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
@@ -3047,7 +3530,7 @@ png_read_filter_row_mmx_avg(png_row_infop row_info, png_bytep row,
// 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
+ "psllq $32, %%mm2 \n\t" // shift data to pos. correctly
"addl $8, %%ecx \n\t"
"movq %%mm3, %%mm1 \n\t" // now use mm1 for getting
// LBCarrys
@@ -3062,54 +3545,114 @@ png_read_filter_row_mmx_avg(png_row_infop row_info, png_bytep row,
"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"
+ // Avg for each Active byte
+ "cmpl %%eax, %%ecx \n\t" // MMXLength
// now ready to write back to memory
- "movq %%mm0, -8(%%edi,%%ecx,) \n\t"
+ "movq %%mm0, -8(%1," PCX ",) \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)
+ "=D" (dummy_value_D),
+ "=c" (dummy_value_c),
+ "=a" (dummy_value_a)
- : "0" (prev_row), // esi // input regs
- "1" (row) // edi
+ : "0" (prev_row), // esi/rsi // input regs
+ "1" (row), // edi/rdi
+ "2" (diff), // ecx
+ "3" (MMXLength) // eax
- : "%ecx" // clobber list
-#if 0 /* %mm0, ..., %mm7 not supported by gcc 2.7.2.3 or egcs 1.1 */
- , "%mm0", "%mm1", "%mm2", "%mm3"
+#if defined(CLOBBER_MMX_REGS_SUPPORTED)
+ : "%mm0", "%mm1", "%mm2", "%mm3" // clobber list
, "%mm4", "%mm5", "%mm6", "%mm7"
#endif
);
}
- break; // end 4,6 bpp
+ break; // end 4 bpp
+
+ case 1:
+ {
+ __asm__ __volatile__ (
+ // re-init address pointers and offset
+// preload "movl diff, %%ecx \n\t" // ecx: x = offset to align. bdry
+// preload "movl row, %1 \n\t" // edi/rdi: Avg(x)
+// preload "movl FullLength, %%eax \n\t"
+ "cmpl %%eax, %%ecx \n\t" // test if offset at end of array
+ "jnb avg_1end \n\t"
+
+ SAVE_ebp
+
+ // do Avg decode for remaining bytes
+// preload "movl prev_row, %0 \n\t" // esi/rsi: Prior(x)
+ "mov %1, " PBP " \n\t" // copy of row pointer...
+ "dec " PBP " \n\t" // ebp/rbp: Raw(x-bpp)
+ "xorl %%edx, %%edx \n\t" // zero edx before using dl & dx
+ // in loop below
+ SAVE_GOT_ebx
+
+ "avg_1lp: \n\t"
+ // Raw(x) = Avg(x) + ((Raw(x-bpp) + Prior(x))/2)
+ "xorl %%ebx, %%ebx \n\t"
+ "movb (%0," PCX ",), %%dl \n\t" // load dl with Prior(x)
+ "movb (" PBP "," PCX ",), %%bl \n\t" // load bl with Raw(x-bpp)
+ "addw %%dx, %%bx \n\t"
+ "incl %%ecx \n\t"
+ "shrw %%bx \n\t" // divide by 2
+ "addb -1(%1," PCX ",), %%bl \n\t" // add Avg(x); -1 to offset
+ // inc ecx
+ "cmpl %%eax, %%ecx \n\t" // check if at end of array
+ "movb %%bl, -1(%1," PCX ",) \n\t" // write back Raw(x);
+ // mov does not affect flags; -1 to offset inc ecx
+ "jb avg_1lp \n\t"
+
+ RESTORE_GOT_ebx
+ RESTORE_ebp
+
+ "avg_1end: \n\t"
+
+ : "=S" (dummy_value_S), // output regs (dummy)
+ "=D" (dummy_value_D),
+ "=c" (dummy_value_c),
+ "=a" (dummy_value_a)
+
+ : "0" (prev_row), // esi/rsi // input regs
+ "1" (row), // edi/rdi
+ "2" (diff), // ecx
+ "3" (FullLength) // eax
+
+ : "%edx" // clobber list
+ _CLOBBER_GOT_ebx
+ _CLOBBER_ebp
+ );
+ }
+ return; // end 1 bpp
case 2:
{
- _ActiveMask.use = 0x000000000000ffffLL;
- _ShiftBpp.use = 16; // == 2 * 8
- _ShiftRem.use = 48; // == 64 - 16
+// _ShiftBpp = 16; // == 2 * 8
+// _ShiftRem = 48; // == 64 - _ShiftBpp
__asm__ __volatile__ (
- // load _ActiveMask
- "movq _ActiveMask, %%mm7 \n\t"
+ LOAD_GOT_rbp
+ // load (former) _ActiveMask
+ "movq " AMASK6_2_0 ", %%mm7 \n\t" // _amask6_2_0 -> mm7
// 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)
+// preload "movl diff, %%ecx \n\t" // ecx: x = offset to
+ // alignment boundary
+ "movq " LB_CARRY_MASK ", %%mm5 \n\t" // _LBCarryMask -> mm5
+// preload "movl row, %1 \n\t" // edi: Avg(x)
+ "movq " HB_CLEAR_MASK ", %%mm4 \n\t" // _HBClearMask -> mm4
+// preload "movl prev_row, %0 \n\t" // esi: Prior(x)
+ RESTORE_rbp
// 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)
+ "movq -8(%1," PCX ",), %%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)
+ "movq (%1," PCX ",), %%mm0 \n\t"
+ "psrlq $48, %%mm2 \n\t" // shift data to pos. correctly
+ "movq (%0," PCX ",), %%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
@@ -3138,10 +3681,10 @@ png_read_filter_row_mmx_avg(png_row_infop row_info, png_bytep row,
// 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
+ "psllq $16, %%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
+ "psllq $16, %%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
@@ -3159,10 +3702,10 @@ png_read_filter_row_mmx_avg(png_row_infop row_info, png_bytep row,
// 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
+ "psllq $16, %%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
+ "psllq $16, %%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
@@ -3179,10 +3722,10 @@ png_read_filter_row_mmx_avg(png_row_infop row_info, png_bytep row,
// 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
+ "psllq $16, %%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
+ "psllq $16, %%mm2 \n\t" // shift data to pos. correctly
"addl $8, %%ecx \n\t"
"movq %%mm3, %%mm1 \n\t" // now use mm1 for getting
// LBCarrys
@@ -3199,102 +3742,148 @@ png_read_filter_row_mmx_avg(png_row_infop row_info, png_bytep row,
// 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"
+ "cmpl %%eax, %%ecx \n\t" // MMXLength
// now ready to write back to memory
- "movq %%mm0, -8(%%edi,%%ecx,) \n\t"
+ "movq %%mm0, -8(%1," PCX ",) \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)
+ "=D" (dummy_value_D),
+ "=c" (dummy_value_c),
+ "=a" (dummy_value_a)
- : "0" (prev_row), // esi // input regs
- "1" (row) // edi
+ : "0" (prev_row), // esi/rsi // input regs
+ "1" (row), // edi/rdi
+ "2" (diff), // ecx
+ "3" (MMXLength) // eax
- : "%ecx" // clobber list
-#if 0 /* %mm0, ..., %mm7 not supported by gcc 2.7.2.3 or egcs 1.1 */
- , "%mm0", "%mm1", "%mm2", "%mm3"
+#if defined(CLOBBER_MMX_REGS_SUPPORTED)
+ : "%mm0", "%mm1", "%mm2", "%mm3" // clobber list
, "%mm4", "%mm5", "%mm6", "%mm7"
#endif
);
}
break; // end 2 bpp
- case 1:
+ case 6: // formerly shared with 4 bpp case (see comments there)
{
+// _ShiftBpp = bpp << 3; // 48 (psllq)
+// _ShiftRem = 64 - _ShiftBpp; // 16 (psrlq)
+
__asm__ __volatile__ (
+ LOAD_GOT_rbp
+ "movq " HB_CLEAR_MASK ", %%mm4 \n\t" // _HBClearMask -> mm4
+ "movq " LB_CARRY_MASK ", %%mm5 \n\t" // _LBCarryMask -> mm5
// re-init address pointers and offset
-#ifdef __PIC__
- "pushl %%ebx \n\t" // save Global Offset Table index
-#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"
+// preload "movl diff, %%ecx \n\t" // ecx: x = offset to
+ // alignment boundary
+ "movq " AMASK0_8_0 ", %%mm7 \n\t" // _amask0_8_0 -> mm7
+ RESTORE_rbp
+
+ // ... and clear all bytes except for 1st active group
+// preload "movl row, %1 \n\t" // edi: Avg(x)
+ "psrlq $16, %%mm7 \n\t"
+// preload "movl prev_row, %0 \n\t" // esi: Prior(x)
+ "movq %%mm7, %%mm6 \n\t"
+ "psllq $48, %%mm6 \n\t" // mask for 2nd active group
- "avg_1end: \n\t"
-#ifdef __PIC__
- "popl %%ebx \n\t" // Global Offset Table index
-#endif
+ // prime the pump: load the first Raw(x-bpp) data set
+ "movq -8(%1," PCX ",), %%mm2 \n\t" // load previous aligned 8 bytes
+ // (we correct pos. in loop below)
+ "avg_6lp: \n\t"
+ "movq (%1," PCX ",), %%mm0 \n\t"
+ "psrlq $16, %%mm2 \n\t" // shift data to pos. correctly
+ "movq (%0," PCX ",), %%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 $48, %%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 %%eax, %%ecx \n\t" // MMXLength
+ // now ready to write back to memory
+ "movq %%mm0, -8(%1," PCX ",) \n\t"
+ // prep Raw(x-bpp) for next loop
+ "movq %%mm0, %%mm2 \n\t" // mov updated Raws to mm2
+ "jb avg_6lp \n\t"
- : "=c" (dummy_value_c), // output regs (dummy)
- "=S" (dummy_value_S),
- "=D" (dummy_value_D)
+ : "=S" (dummy_value_S), // output regs (dummy)
+ "=D" (dummy_value_D),
+ "=c" (dummy_value_c),
+ "=a" (dummy_value_a)
- : "0" (bpp), // ecx // input regs
- "1" (prev_row), // esi
- "2" (row) // edi
+ : "0" (prev_row), // esi/rsi // input regs
+ "1" (row), // edi/rdi
+ "2" (diff), // ecx
+ "3" (MMXLength) // eax
- : "%eax", "%edx" // clobber list
-#ifndef __PIC__
- , "%ebx"
+#if defined(CLOBBER_MMX_REGS_SUPPORTED)
+ : "%mm0", "%mm1", "%mm2", "%mm3" // clobber list
+ , "%mm4", "%mm5", "%mm6", "%mm7"
#endif
);
}
- return; // end 1 bpp
+ break; // end 6 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)
+// preload "movl diff, %%ecx \n\t" // ecx: x = offset to
+ // alignment boundary
+ LOAD_GOT_rbp
+ "movq " LB_CARRY_MASK ", %%mm5 \n\t" // [interleave for parallel.?]
+// preload "movl row, %1 \n\t" // edi: Avg(x)
+ "movq " HB_CLEAR_MASK ", %%mm4 \n\t" // _HBClearMask -> mm4
+// preload "movl prev_row, %0 \n\t" // esi: Prior(x)
+ RESTORE_rbp
// prime the pump: load the first Raw(x-bpp) data set
- "movq -8(%%edi,%%ecx,), %%mm2 \n\t" // load previous aligned 8 bytes
+ "movq -8(%1," PCX ",), %%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 (%1," PCX ",), %%mm0 \n\t"
"movq %%mm5, %%mm3 \n\t"
- "movq (%%esi,%%ecx,), %%mm1 \n\t"
+ "movq (%0," PCX ",), %%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
@@ -3306,78 +3895,36 @@ png_read_filter_row_mmx_avg(png_row_infop row_info, png_bytep row,
"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"
+ "cmpl %%eax, %%ecx \n\t" // MMXLength
+ "movq %%mm0, -8(%1," PCX ",) \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)
+ "=D" (dummy_value_D),
+ "=c" (dummy_value_c),
+ "=a" (dummy_value_a)
- : "0" (prev_row), // esi // input regs
- "1" (row) // edi
+ : "0" (prev_row), // esi/rsi // input regs
+ "1" (row), // edi/rdi
+ "2" (diff), // ecx
+ "3" (MMXLength) // eax
- : "%ecx" // clobber list
-#if 0 /* %mm0, ..., %mm5 not supported by gcc 2.7.2.3 or egcs 1.1 */
- , "%mm0", "%mm1", "%mm2"
+#if defined(CLOBBER_MMX_REGS_SUPPORTED)
+ : "%mm0", "%mm1", "%mm2" // clobber list
, "%mm3", "%mm4", "%mm5"
#endif
);
}
break; // end 8 bpp
- default: // bpp greater than 8 (!= 1,2,3,4,[5],6,[7],8)
+ default: // bpp != 1,2,3,4,6,8: doesn't exist
{
-
-#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");
+ // ERROR: SHOULD NEVER BE REACHED
+#if defined(PNG_DEBUG)
+ png_debug(1, "Internal libpng logic error (GCC "
+ "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;
@@ -3386,60 +3933,69 @@ png_read_filter_row_mmx_avg(png_row_infop row_info, png_bytep row,
__asm__ __volatile__ (
// MMX acceleration complete; now do clean-up
// check if any remaining bytes left to decode
-#ifdef __PIC__
- "pushl %%ebx \n\t" // save index to Global Offset Table
-#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
+//pre "movl FullLength, %%edx \n\t"
+//pre "movl MMXLength, %%eax \n\t" // eax: x == offset bytes after MMX
+//pre "movl row, %2 \n\t" // edi: Avg(x)
+ "cmpl %%edx, %%eax \n\t" // test if offset at end of array
"jnb avg_end \n\t"
+ SAVE_ebp
+
// 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)
+//pre "movl prev_row, %1 \n\t" // esi: Prior(x)
+ "mov %2, " PBP " \n\t" // copy of row pointer...
+//pre "subl bpp, " PBP " \n\t" // (bpp is preloaded into ecx)
+ "sub " PCX "," PBP " \n\t" // ebp: Raw(x-bpp)
"xorl %%ecx, %%ecx \n\t" // zero ecx before using cl & cx below
+ SAVE_GOT_ebx
+
"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]
+ "xorl %%ebx, %%ebx \n\t"
+ "movb (%1," PAX ",), %%cl \n\t" // load cl with Prior(x)
+ "movb (" PBP "," PAX ",), %%bl \n\t" // load bl with Raw(x-bpp)
+ "addw %%cx, %%bx \n\t"
+ "incl %%eax \n\t"
+ "shrw %%bx \n\t" // divide by 2
+ "addb -1(%2," PAX ",), %%bl \n\t" // add Avg(x); -1 to offset inc eax
+ "cmpl %%edx, %%eax \n\t" // check if at end of array
+ "movb %%bl, -1(%2," PAX ",) \n\t" // write back Raw(x) [mov does not
+ "jb avg_lp2 \n\t" // affect flags; -1 to offset inc eax]
+
+ RESTORE_GOT_ebx
+ RESTORE_ebp
"avg_end: \n\t"
"EMMS \n\t" // end MMX; prep for poss. FP instrs.
-#ifdef __PIC__
- "popl %%ebx \n\t" // restore index to Global Offset Table
-#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
+ "=D" (dummy_value_D),
+ "=a" (dummy_value_a),
+ "=d" (dummy_value_d)
+
+ : "0" (bpp), // ecx // input regs
+ "1" (prev_row), // esi/rsi
+ "2" (row), // edi/rdi
+ "3" (MMXLength), // eax
+ "4" (FullLength) // edx
+
+ CLOB_COLON_ebx_ebp // clobber list
+ CLOBBER_GOT_ebx
+ CLOB_COMMA_ebx_ebp
+ CLOBBER_ebp
);
} /* end png_read_filter_row_mmx_avg() */
-#endif
+
+#endif /* PNG_MMX_READ_FILTER_AVG_SUPPORTED */
-#ifdef PNG_THREAD_UNSAFE_OK
+#if defined(PNG_MMX_READ_FILTER_PAETH_SUPPORTED)
+#if defined(PNG_x86_64_USE_GOTPCREL) || defined(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 //
@@ -3452,141 +4008,157 @@ static void /* PRIVATE */
png_read_filter_row_mmx_paeth(png_row_infop row_info, png_bytep row,
png_bytep prev_row)
{
+ unsigned FullLength, MMXLength; // png_uint_32 is actually 64-bit on x86-64
int bpp;
+ int dummy_value_a;
int dummy_value_c; // fix 'forbidden register 2 (cx) was spilled' error
- int dummy_value_S;
- int dummy_value_D;
+ int dummy_value_d;
+ png_charp dummy_value_S;
+ png_charp dummy_value_D;
+ int diff; // __attribute__((used));
- bpp = (row_info->pixel_depth + 7) >> 3; // Get # bytes per pixel
- _FullLength = row_info->rowbytes; // # of bytes to filter
+ bpp = (row_info->pixel_depth + 7) >> 3; // calc number of bytes per pixel
+ FullLength = row_info->rowbytes; // number of bytes to filter
__asm__ __volatile__ (
-#ifdef __PIC__
- "pushl %%ebx \n\t" // save index to Global Offset Table
-#endif
+ SAVE_GOT_ebx
+ SAVE_r15
+ SAVE_ebp
+//pre "movl row, %2 \n\t" // edi/rdi
"xorl %%ebx, %%ebx \n\t" // ebx: x offset
-//pre "movl row, %%edi \n\t"
+//pre "movl prev_row, %1 \n\t" // esi/rsi
"xorl %%edx, %%edx \n\t" // edx: x-bpp offset
-//pre "movl prev_row, %%esi \n\t"
+//pre "movl FullLength, %%eax \n\t" // bring in via eax...
+ SAVE_FullLength // ...but store for later use
"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"
+ "movb (%2," PBX ",), %%al \n\t"
+ "addb (%1," PBX ",), %%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"
+ "movb %%al, -1(%2," PBX ",) \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
+
+ // get # of bytes to alignment (note: computing _delta_ of two pointers,
+ // so hereafter %%ebp is sufficient even on 64-bit)
+ "mov %2, " PBP " \n\t" // take start of row
+ "add " PBX "," PBP " \n\t" // add bpp
+ "add $0xf, " PBP " \n\t" // add 7+8 to incr past alignment bdry
+// "andl $0xfffffff8, %%ebp \n\t" // mask to alignment boundary (32-bit!)
+ CLEAR_BOTTOM_3_BITS PBP "\n\t" // mask to alignment boundary
+ "sub %2, " PBP " \n\t" // subtract row ptr again => ebp =
+ "jz paeth_go \n\t" // target value of ebx at alignment
+
"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
+ SAVE_r11_r12_r13
+
+ // 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
+ "movb (%1," PBX ",), %%al \n\t" // load Prior(x) into al
+ "movb (%1," PDX ",), %%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
+ "movl %%eax, " pa_TEMP " \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
+ "movb (%2," PDX ",), %%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
+ // pcv = p - c = (a + b - c) - c = (a - c) + (b - c) = pav + pbv
+ "addl " pa_TEMP ", %%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
+ "movl %%eax, " pc_TEMP " \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
+ "movl %%ecx, " pb_TEMP " \n\t" // save pb for later use
// pa = abs(pav)
- "movl _patemp, %%eax \n\t"
+ "movl " pa_TEMP ", %%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
+ "movl %%eax, " pa_TEMP " \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"
+ "cmpl " pc_TEMP ", %%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
+ "movb (%1," PDX ",), %%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
+ "movb (%1," PBX ",), %%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"
+ "cmpl " pc_TEMP ", %%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
+ "movb (%1," PDX ",), %%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
+ "movb (%2," PDX ",), %%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"
+ "addb %%cl, -1(%2," PBX ",) \n\t"
+ "cmpl %%ebp, %%ebx \n\t"
"jb paeth_lp1 \n\t"
+ RESTORE_r11_r12_r13
+
"paeth_go: \n\t"
- "movl _FullLength, %%ecx \n\t"
+ RESTORE_FullLength "%%ecx \n\t" // FullLength -> ecx
"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__
- "popl %%ebx \n\t" // restore index to Global Offset Table
-#endif
+//out "movl %%ecx, MMXLength \n\t"
+ "movl %%ebp, %%eax \n\t" // ebp = diff, but no reg constraint(?)
+ RESTORE_ebp // (could swap ebp and edx functions)
+ RESTORE_r15
+ RESTORE_GOT_ebx
- : "=c" (dummy_value_c), // output regs (dummy)
+ : "=c" (MMXLength), // output regs
"=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
+ "=D" (dummy_value_D),
+ "=a" (diff)
+
+ : "0" (bpp), // ecx // input regs
+ "1" (prev_row), // esi/rsi
+ "2" (row), // edi/rdi
+ "3" (FullLength) // eax
+
+ : "%edx" // clobber list
+ _CLOBBER_r11_r12_r13
+ _CLOBBER_r15
+ _CLOBBER_ebp
+ _CLOBBER_GOT_ebx
);
// now do the math for the rest of the row
@@ -3594,26 +4166,26 @@ png_read_filter_row_mmx_paeth(png_row_infop row_info, png_bytep row,
{
case 3:
{
- _ActiveMask.use = 0x0000000000ffffffLL;
- _ActiveMaskEnd.use = 0xffff000000000000LL;
- _ShiftBpp.use = 24; // == bpp(3) * 8
- _ShiftRem.use = 40; // == 64 - 24
+// _ShiftBpp = 24; // == bpp * 8
+// _ShiftRem = 40; // == 64 - _ShiftBpp
__asm__ __volatile__ (
- "movl _dif, %%ecx \n\t"
-// preload "movl row, %%edi \n\t"
-// preload "movl prev_row, %%esi \n\t"
+ LOAD_GOT_rbp
+// preload "movl diff, %%ecx \n\t"
+// preload "movl row, %1 \n\t" // edi/rdi
+// preload "movl prev_row, %0 \n\t" // esi/rsi
"pxor %%mm0, %%mm0 \n\t"
+
// prime the pump: load the first Raw(x-bpp) data set
- "movq -8(%%edi,%%ecx,), %%mm1 \n\t"
+ "movq -8(%1," PCX ",), %%mm1 \n\t"
"paeth_3lp: \n\t"
- "psrlq _ShiftRem, %%mm1 \n\t" // shift last 3 bytes to 1st
+ "psrlq $40, %%mm1 \n\t" // shift last 3 bytes to 1st
// 3 bytes
- "movq (%%esi,%%ecx,), %%mm2 \n\t" // load b=Prior(x)
+ "movq (%0," PCX ",), %%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
+ "movq -8(%0," PCX ",), %%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
+ "psrlq $40, %%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"
@@ -3663,16 +4235,16 @@ png_read_filter_row_mmx_paeth(png_row_infop row_info, png_bytep row,
"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 (%0," PCX ",), %%mm3 \n\t" // load c=Prior(x-bpp)
+ "pand " AMASK5_3_0 ", %%mm7 \n\t" // _amask5_3_0 (was _ActiveMask)
"movq %%mm3, %%mm2 \n\t" // load b=Prior(x) step 1
- "paddb (%%edi,%%ecx,), %%mm7 \n\t" // add Paeth predictor with Raw(x)
+ "paddb (%1," PCX ",), %%mm7 \n\t" // add Paeth predictor + Raw(x)
"punpcklbw %%mm0, %%mm3 \n\t" // unpack High bytes of c
- "movq %%mm7, (%%edi,%%ecx,) \n\t" // write back updated value
+ "movq %%mm7, (%1," PCX ",) \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
+ "psrlq $24, %%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
@@ -3717,7 +4289,7 @@ png_read_filter_row_mmx_paeth(png_row_infop row_info, png_bytep row,
"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)
+ "movq (%0," PCX ",), %%mm2 \n\t" // load b=Prior(x)
"pand %%mm7, %%mm3 \n\t"
"pandn %%mm0, %%mm7 \n\t"
"pxor %%mm1, %%mm1 \n\t"
@@ -3725,18 +4297,18 @@ png_read_filter_row_mmx_paeth(png_row_infop row_info, png_bytep row,
"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"
+ "pand " AMASK5_3_0 ", %%mm7 \n\t" // _amask5_3_0 (was _ActiveMask)
"punpckhbw %%mm0, %%mm2 \n\t" // unpack High bytes of b
- "psllq _ShiftBpp, %%mm7 \n\t" // shift bytes to 2nd group of
+ "psllq $24, %%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
+ "paddb (%1," PCX ",), %%mm7 \n\t" // add Paeth predictor + Raw(x)
+ "psllq $24, %%mm3 \n\t" // load c=Prior(x-bpp) step 2
+ "movq %%mm7, (%1," PCX ",) \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
+ "psllq $24, %%mm1 \n\t" // shift bytes (was _ShiftBpp)
// 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"
@@ -3787,62 +4359,53 @@ png_read_filter_row_mmx_paeth(png_row_infop row_info, png_bytep row,
"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"
+ "pand " AMASK0_2_6 ", %%mm1 \n\t" // _amask0_2_6 (_ActiveMaskEnd)
+ "paddb -8(%1," PCX ",), %%mm1 \n\t" // add Paeth predictor + Raw(x)
+ "cmpl %%eax, %%ecx \n\t" // MMXLength
"pxor %%mm0, %%mm0 \n\t" // pxor does not affect flags
- "movq %%mm1, -8(%%edi,%%ecx,) \n\t" // write back updated value
+ "movq %%mm1, -8(%1," PCX ",) \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"
+ RESTORE_rbp
- : "=S" (dummy_value_S), // output regs (dummy)
- "=D" (dummy_value_D)
+ : "=S" (dummy_value_S), // output regs (dummy)
+ "=D" (dummy_value_D),
+ "=c" (dummy_value_c),
+ "=a" (dummy_value_a)
- : "0" (prev_row), // esi // input regs
- "1" (row) // edi
+ : "0" (prev_row), // esi/rsi // input regs
+ "1" (row), // edi/rdi
+ "2" (diff), // ecx
+ "3" (MMXLength) // eax
- : "%ecx" // clobber list
-#if 0 /* %mm0, ..., %mm7 not supported by gcc 2.7.2.3 or egcs 1.1 */
- , "%mm0", "%mm1", "%mm2", "%mm3"
+#if defined(CLOBBER_MMX_REGS_SUPPORTED)
+ : "%mm0", "%mm1", "%mm2", "%mm3" // clobber list
, "%mm4", "%mm5", "%mm6", "%mm7"
#endif
);
}
break; // end 3 bpp
- case 6:
- //case 7: // GRR BOGUS
- //case 5: // GRR BOGUS
+ case 4:
{
- _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"
+// preload "movl diff, %%ecx \n\t"
+// preload "movl row, %1 \n\t" // edi/rdi
+// preload "movl prev_row, %0 \n\t" // esi/rsi
"pxor %%mm0, %%mm0 \n\t"
-
- "paeth_6lp: \n\t"
- // must shift to position Raw(x-bpp) data
- "psrlq _ShiftRem, %%mm1 \n\t"
+ // prime the pump: load the first Raw(x-bpp) data set
+ "movq -8(%1," PCX ",), %%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
- "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"
+ "movq -8(%0," PCX ",), %%mm3 \n\t" // read c=Prior(x-bpp) bytes
+ "punpckhbw %%mm0, %%mm1 \n\t" // unpack Low bytes of a
+ "movq (%0," PCX ",), %%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"
- "punpcklbw %%mm0, %%mm3 \n\t" // unpack Low bytes of c
+ "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"
@@ -3887,24 +4450,19 @@ png_read_filter_row_mmx_paeth(png_row_infop row_info, png_bytep row,
"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"
+ "movq (%0," PCX ",), %%mm3 \n\t" // load c=Prior(x-bpp)
+ LOAD_GOT_rbp
+ "pand " AMASK4_4_0 ", %%mm7 \n\t" // _amask4_4_0 (was _ActiveMask)
+ RESTORE_rbp
+ "movq %%mm3, %%mm2 \n\t" // load b=Prior(x) step 1
+ "paddb (%1," PCX ",), %%mm7 \n\t" // add Paeth predictor + Raw(x)
+ "punpcklbw %%mm0, %%mm3 \n\t" // unpack High bytes of c
+ "movq %%mm7, (%1," PCX ",) \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 High bytes of b
- "punpckhbw %%mm0, %%mm1 \n\t" // unpack High bytes of a
+ "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
@@ -3954,48 +4512,178 @@ png_read_filter_row_mmx_paeth(png_row_infop row_info, png_bytep row,
// 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"
+ "paddb -8(%1," PCX ",), %%mm1 \n\t" // add predictor with Raw(x)
+ "cmpl %%eax, %%ecx \n\t" // MMXLength
+ "movq %%mm1, -8(%1," PCX ",) \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)
+ : "=S" (dummy_value_S), // output regs (dummy)
+ "=D" (dummy_value_D),
+ "=c" (dummy_value_c),
+ "=a" (dummy_value_a)
- : "0" (prev_row), // esi // input regs
- "1" (row) // edi
+ : "0" (prev_row), // esi/rsi // input regs
+ "1" (row), // edi/rdi
+ "2" (diff), // ecx
+ "3" (MMXLength) // eax
- : "%ecx" // clobber list
-#if 0 /* %mm0, ..., %mm7 not supported by gcc 2.7.2.3 or egcs 1.1 */
- , "%mm0", "%mm1", "%mm2", "%mm3"
+#if defined(CLOBBER_MMX_REGS_SUPPORTED)
+ : "%mm0", "%mm1", "%mm2", "%mm3" // clobber list
, "%mm4", "%mm5", "%mm6", "%mm7"
#endif
);
}
- break; // end 6 bpp
+ break; // end 4 bpp
- case 4:
+ case 1:
+ case 2:
{
- _ActiveMask.use = 0x00000000ffffffffLL;
+ __asm__ __volatile__ (
+// preload "movl diff, %%eax \n\t" // eax: x = offset to align. bdry
+// preload "movl FullLength, %%edx \n\t"
+ "cmpl %%edx, %%eax \n\t"
+ "jnb paeth_dend \n\t"
+
+ SAVE_ebp
+
+// preload "movl row, %2 \n\t" // edi/rdi
+ // do Paeth decode for remaining bytes
+// preload "movl prev_row, %1 \n\t" // esi/rsi
+ "movl %%eax, %%ebp \n\t"
+// preload "subl bpp, %%ebp \n\t" // (bpp is preloaded into ecx)
+ "subl %%ecx, %%ebp \n\t" // ebp = eax - bpp
+ "xorl %%ecx, %%ecx \n\t" // zero ecx before using cl & cx
+
+ SAVE_GOT_ebx
+ SAVE_r11_r12_r13
+
+ "paeth_dlp: \n\t"
+ "xorl %%ebx, %%ebx \n\t"
+ // pav = p - a = (a + b - c) - a = b - c
+ "movb (%1," PAX ",), %%bl \n\t" // load Prior(x) into bl
+ "movb (%1," PBP ",), %%cl \n\t" // load Prior(x-bpp) into cl
+ "subl %%ecx, %%ebx \n\t" // subtract Prior(x-bpp)
+ "movl %%ebx, " pa_TEMP " \n\t" // Save pav for later use
+ "xorl %%ebx, %%ebx \n\t"
+ // pbv = p - b = (a + b - c) - b = a - c
+ "movb (%2," PBP ",), %%bl \n\t" // load Raw(x-bpp) into bl
+ "subl %%ecx, %%ebx \n\t" // subtract Prior(x-bpp)
+ "movl %%ebx, %%ecx \n\t"
+ // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
+ "addl " pa_TEMP ", %%ebx \n\t" // pcv = pav + pbv
+ // pc = abs(pcv)
+ "testl $0x80000000, %%ebx \n\t"
+ "jz paeth_dpca \n\t"
+ "negl %%ebx \n\t" // reverse sign of neg values
+
+ "paeth_dpca: \n\t"
+ "movl %%ebx, " pc_TEMP " \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, " pb_TEMP " \n\t" // save pb for later use
+ // pa = abs(pav)
+ "movl " pa_TEMP ", %%ebx \n\t"
+ "testl $0x80000000, %%ebx \n\t"
+ "jz paeth_dpaa \n\t"
+ "negl %%ebx \n\t" // reverse sign of neg values
+
+ "paeth_dpaa: \n\t"
+ "movl %%ebx, " pa_TEMP " \n\t" // save pa for later use
+ // test if pa <= pb
+ "cmpl %%ecx, %%ebx \n\t"
+ "jna paeth_dabb \n\t"
+ // pa > pb; now test if pb <= pc
+ "cmpl " pc_TEMP ", %%ecx \n\t"
+ "jna paeth_dbbc \n\t"
+ // pb > pc; Raw(x) = Paeth(x) + Prior(x-bpp)
+ "movb (%1," PBP ",), %%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 (%1," PAX ",), %%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 " pc_TEMP ", %%ebx \n\t"
+ "jna paeth_dabc \n\t"
+ // pa > pc; Raw(x) = Paeth(x) + Prior(x-bpp)
+ "movb (%1," PBP ",), %%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 (%2," PBP ",), %%cl \n\t" // load Raw(x-bpp) into cl
+
+ "paeth_dpaeth: \n\t"
+ "incl %%eax \n\t"
+ "incl %%ebp \n\t"
+ // Raw(x) = (Paeth(x) + Paeth_Predictor( a, b, c )) mod 256
+ "addb %%cl, -1(%2," PAX ",) \n\t"
+ "cmpl %%edx, %%eax \n\t" // check against FullLength
+ "jb paeth_dlp \n\t"
+
+ RESTORE_r11_r12_r13
+ RESTORE_GOT_ebx
+ RESTORE_ebp
+
+ "paeth_dend: \n\t"
+
+ : "=c" (dummy_value_c), // output regs (dummy)
+ "=S" (dummy_value_S),
+ "=D" (dummy_value_D),
+ "=a" (dummy_value_a),
+ "=d" (dummy_value_d)
+
+ : "0" (bpp), // ecx // input regs
+ "1" (prev_row), // esi/rsi
+ "2" (row), // edi/rdi
+ "3" (diff), // eax
+ "4" (FullLength) // edx
+
+ CLOB_COLON_ebx_ebp_r1X // clobber list
+ CLOBBER_GOT_ebx
+ CLOB_COMMA_ebx_ebp
+ CLOBBER_ebp
+ CLOB_COMMA_ebX_r1X
+ CLOBBER_r11_r12_r13
+ );
+ }
+ return; // end 1 or 2 bpp (no need to go further with this one)
+
+ case 6:
+ {
+// _ActiveMask2 = 0xffffffff00000000LL; // NOT USED ("_amask_0_4_4")
+// _ShiftBpp = 48; // bpp << 3 == bpp * 8
+// _ShiftRem = 16; // 64 - _ShiftBpp
__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"
+// preload "movl diff, %%ecx \n\t"
+// preload "movl row, %1 \n\t" // edi/rdi
+// preload "movl prev_row, %0 \n\t" // esi/rsi
// 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"
+ "movq -8(%1," PCX ",), %%mm1 \n\t"
+ "pxor %%mm0, %%mm0 \n\t"
+
+ "paeth_6lp: \n\t"
+ // must shift to position Raw(x-bpp) data
+ "psrlq $16, %%mm1 \n\t" // was _ShiftRem
// 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
+ "movq -8(%0," PCX ",), %%mm3 \n\t" // read c=Prior(x-bpp) bytes
+ "punpcklbw %%mm0, %%mm1 \n\t" // unpack Low bytes of a
+ "movq (%0," PCX ",), %%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 $16, %%mm3 \n\t" // was _ShiftRem
// pav = p - a = (a + b - c) - a = b - c
"movq %%mm2, %%mm4 \n\t"
- "punpckhbw %%mm0, %%mm3 \n\t" // unpack High bytes of c
+ "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"
@@ -4040,16 +4728,26 @@ png_read_filter_row_mmx_paeth(png_row_infop row_info, png_bytep row,
"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)
+ "movq -8(%0," PCX ",), %%mm3 \n\t" // load c=Prior(x-bpp)
+ LOAD_GOT_rbp
+ "pand " AMASK4_4_0 ", %%mm7 \n\t" // _amask4_4_0 (was _ActiveMask)
+ RESTORE_rbp
+ "psrlq $16, %%mm3 \n\t"
+ "movq (%0," PCX ",), %%mm2 \n\t" // load b=Prior(x) step 1
+ "paddb (%1," PCX ",), %%mm7 \n\t" // add Paeth predictor + Raw(x)
+ "movq %%mm2, %%mm6 \n\t"
+ "movq %%mm7, (%1," PCX ",) \n\t" // write back updated value
+ "movq -8(%1," PCX ",), %%mm1 \n\t"
+ "psllq $48, %%mm6 \n\t" // bpp * 8 = bits per pixel
+ "movq %%mm7, %%mm5 \n\t"
+ "psrlq $16, %%mm1 \n\t" // 64 - (bpp * 8) = remainder
+ "por %%mm6, %%mm3 \n\t"
+ "psllq $48, %%mm5 \n\t" // was _ShiftBpp
+ "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 Low bytes of b
- "punpcklbw %%mm0, %%mm1 \n\t" // unpack Low bytes of a
+ "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
@@ -4099,44 +4797,45 @@ png_read_filter_row_mmx_paeth(png_row_infop row_info, png_bytep row,
// 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"
+ "paddb -8(%1," PCX ",), %%mm1 \n\t" // add Paeth predictor + Raw(x)
+ "cmpl %%eax, %%ecx \n\t" // MMXLength
+ "movq %%mm1, -8(%1," PCX ",) \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)
+ : "=S" (dummy_value_S), // output regs (dummy)
+ "=D" (dummy_value_D),
+ "=c" (dummy_value_c),
+ "=a" (dummy_value_a)
- : "0" (prev_row), // esi // input regs
- "1" (row) // edi
+ : "0" (prev_row), // esi/rsi // input regs
+ "1" (row), // edi/rdi
+ "2" (diff), // ecx
+ "3" (MMXLength) // eax
- : "%ecx" // clobber list
-#if 0 /* %mm0, ..., %mm7 not supported by gcc 2.7.2.3 or egcs 1.1 */
- , "%mm0", "%mm1", "%mm2", "%mm3"
+#if defined(CLOBBER_MMX_REGS_SUPPORTED)
+ : "%mm0", "%mm1", "%mm2", "%mm3" // clobber list
, "%mm4", "%mm5", "%mm6", "%mm7"
#endif
);
}
- break; // end 4 bpp
+ break; // end 6 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"
+// preload "movl diff, %%ecx \n\t"
+// preload "movl row, %1 \n\t" // edi/rdi
+// preload "movl prev_row, %0 \n\t" // esi/rsi
"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
+ "movq -8(%1," PCX ",), %%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
+ "movq -8(%0," PCX ",), %%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)
+ "movq (%0," PCX ",), %%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"
@@ -4185,13 +4884,15 @@ png_read_filter_row_mmx_paeth(png_row_infop row_info, png_bytep row,
"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)
+ "movq -8(%0," PCX ",), %%mm3 \n\t" // read c=Prior(x-bpp) bytes
+ LOAD_GOT_rbp
+ "pand " AMASK4_4_0 ", %%mm7 \n\t" // _amask4_4_0 (was _ActiveMask)
+ RESTORE_rbp
+ "movq (%0," PCX ",), %%mm2 \n\t" // load b=Prior(x)
+ "paddb (%1," PCX ",), %%mm7 \n\t" // add Paeth predictor + 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
+ "movq %%mm7, (%1," PCX ",) \n\t" // write back updated value
+ "movq -8(%1," PCX ",), %%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
@@ -4245,256 +4946,171 @@ png_read_filter_row_mmx_paeth(png_row_infop row_info, png_bytep row,
// 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
+ "paddb -8(%1," PCX ",), %%mm1 \n\t" // add Paeth predictor + Raw(x)
+ "cmpl %%eax, %%ecx \n\t" // MMXLength
+ "movq %%mm1, -8(%1," PCX ",) \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)
+ : "=S" (dummy_value_S), // output regs (dummy)
+ "=D" (dummy_value_D),
+ "=c" (dummy_value_c),
+ "=a" (dummy_value_a)
- : "0" (prev_row), // esi // input regs
- "1" (row) // edi
+ : "0" (prev_row), // esi/rsi // input regs
+ "1" (row), // edi/rdi
+ "2" (diff), // ecx
+ "3" (MMXLength) // eax
- : "%ecx" // clobber list
-#if 0 /* %mm0, ..., %mm7 not supported by gcc 2.7.2.3 or egcs 1.1 */
- , "%mm0", "%mm1", "%mm2", "%mm3"
+#if defined(CLOBBER_MMX_REGS_SUPPORTED)
+ : "%mm0", "%mm1", "%mm2", "%mm3" // clobber list
, "%mm4", "%mm5", "%mm6", "%mm7"
#endif
);
}
break; // end 8 bpp
- case 1: // bpp = 1
- case 2: // bpp = 2
- default: // bpp > 8
+ default: // bpp != 1,2,3,4,6,8: doesn't exist
{
- __asm__ __volatile__ (
-#ifdef __PIC__
- "pushl %%ebx \n\t" // save Global Offset Table index
-#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__
- "popl %%ebx \n\t" // index to Global Offset Table
-#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"
+ // ERROR: SHOULD NEVER BE REACHED
+#if defined(PNG_DEBUG)
+ png_debug(1, "Internal libpng logic error (GCC "
+ "png_read_filter_row_mmx_paeth())\n");
#endif
- );
}
- return; // No need to go further with this one
+ break;
} // end switch (bpp)
__asm__ __volatile__ (
// MMX acceleration complete; now do clean-up
// check if any remaining bytes left to decode
-#ifdef __PIC__
- "pushl %%ebx \n\t" // save index to Global Offset Table
-#endif
- "movl _MMXLength, %%ebx \n\t"
- "cmpl _FullLength, %%ebx \n\t"
+//pre "movl FullLength, %%edx \n\t"
+//pre "movl MMXLength, %%eax \n\t"
+ "cmpl %%edx, %%eax \n\t"
"jnb paeth_end \n\t"
-//pre "movl row, %%edi \n\t"
-//pre "movl prev_row, %%esi \n\t"
+
+ SAVE_ebp
+
+//pre "movl row, %2 \n\t" // edi/rdi
+//pre "movl prev_row, %1 \n\t" // esi/rsi
// 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
+ "movl %%eax, %%ebp \n\t"
+//pre "subl bpp, %%ebp \n\t" // (bpp is preloaded into ecx)
+ "subl %%ecx, %%ebp \n\t" // ebp = eax - bpp
"xorl %%ecx, %%ecx \n\t" // zero ecx before using cl & cx below
+ SAVE_GOT_ebx
+ SAVE_r11_r12_r13
+
"paeth_lp2: \n\t"
- "xorl %%eax, %%eax \n\t"
+ "xorl %%ebx, %%ebx \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"
+ "movb (%1," PAX ",), %%bl \n\t" // load Prior(x) into bl
+ "movb (%1," PBP ",), %%cl \n\t" // load Prior(x-bpp) into cl
+ "subl %%ecx, %%ebx \n\t" // subtract Prior(x-bpp)
+ "movl %%ebx, " pa_TEMP " \n\t" // Save pav for later use
+ "xorl %%ebx, %%ebx \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
+ "movb (%2," PBP ",), %%bl \n\t" // load Raw(x-bpp) into bl
+ "subl %%ecx, %%ebx \n\t" // subtract Prior(x-bpp)
+ "movl %%ebx, %%ecx \n\t"
+ // pcv = p - c = (a + b - c) - c = (a - c) + (b - c) = pav + pbv
+ "addl " pa_TEMP ", %%ebx \n\t" // pcv = pav + pbv
// pc = abs(pcv)
- "testl $0x80000000, %%eax \n\t"
+ "testl $0x80000000, %%ebx \n\t"
"jz paeth_pca2 \n\t"
- "negl %%eax \n\t" // reverse sign of neg values
+ "negl %%ebx \n\t" // reverse sign of neg values
"paeth_pca2: \n\t"
- "movl %%eax, _pctemp \n\t" // save pc for later use
+ "movl %%ebx, " pc_TEMP " \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
+ "movl %%ecx, " pb_TEMP " \n\t" // save pb for later use
// pa = abs(pav)
- "movl _patemp, %%eax \n\t"
- "testl $0x80000000, %%eax \n\t"
+ "movl " pa_TEMP ", %%ebx \n\t"
+ "testl $0x80000000, %%ebx \n\t"
"jz paeth_paa2 \n\t"
- "negl %%eax \n\t" // reverse sign of neg values
+ "negl %%ebx \n\t" // reverse sign of neg values
"paeth_paa2: \n\t"
- "movl %%eax, _patemp \n\t" // save pa for later use
+ "movl %%ebx, " pa_TEMP " \n\t" // save pa for later use
// test if pa <= pb
- "cmpl %%ecx, %%eax \n\t"
+ "cmpl %%ecx, %%ebx \n\t"
"jna paeth_abb2 \n\t"
// pa > pb; now test if pb <= pc
- "cmpl _pctemp, %%ecx \n\t"
+ "cmpl " pc_TEMP ", %%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
+ "movb (%1," PBP ",), %%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
+ "movb (%1," PAX ",), %%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"
+ "cmpl " pc_TEMP ", %%ebx \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
+ "movb (%1," PBP ",), %%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
+ "movb (%2," PBP ",), %%cl \n\t" // load Raw(x-bpp) into cl
"paeth_paeth2: \n\t"
- "incl %%ebx \n\t"
- "incl %%edx \n\t"
+ "incl %%eax \n\t"
+ "incl %%ebp \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"
+ "addb %%cl, -1(%2," PAX ",) \n\t"
+ "cmpl %%edx, %%eax \n\t" // check against FullLength
"jb paeth_lp2 \n\t"
+ RESTORE_r11_r12_r13
+ RESTORE_GOT_ebx
+ RESTORE_ebp
+
"paeth_end: \n\t"
"EMMS \n\t" // end MMX; prep for poss. FP instrs.
-#ifdef __PIC__
- "popl %%ebx \n\t" // restore index to Global Offset Table
-#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
+ "=D" (dummy_value_D),
+ "=a" (dummy_value_a),
+ "=d" (dummy_value_d)
+
+ : "0" (bpp), // ecx // input regs
+ "1" (prev_row), // esi/rsi
+ "2" (row), // edi/rdi
+ "3" (MMXLength), // eax
+ "4" (FullLength) // edx
+
+ CLOB_COLON_ebx_ebp_r1X // clobber list
+ CLOBBER_GOT_ebx
+ CLOB_COMMA_ebx_ebp
+ CLOBBER_ebp
+ CLOB_COMMA_ebX_r1X
+ CLOBBER_r11_r12_r13
);
} /* end png_read_filter_row_mmx_paeth() */
-#endif
+
+#endif // PNG_x86_64_USE_GOTPCREL || PNG_THREAD_UNSAFE_OK
+#endif /* PNG_MMX_READ_FILTER_PAETH_SUPPORTED */
-#ifdef PNG_THREAD_UNSAFE_OK
+#if defined(PNG_MMX_READ_FILTER_SUB_SUPPORTED)
+
//===========================================================================//
// //
// P N G _ R E A D _ F I L T E R _ R O W _ M M X _ S U B //
@@ -4506,55 +5122,68 @@ png_read_filter_row_mmx_paeth(png_row_infop row_info, png_bytep row,
static void /* PRIVATE */
png_read_filter_row_mmx_sub(png_row_infop row_info, png_bytep row)
{
+ unsigned FullLength, MMXLength; // png_uint_32 is actually 64-bit on x86-64
int bpp;
int dummy_value_a;
- int dummy_value_D;
+ int dummy_value_c;
+ int dummy_value_d;
+ png_bytep dummy_value_D;
+ int diff; // __attribute__((used));
- bpp = (row_info->pixel_depth + 7) >> 3; // calc number of bytes per pixel
- _FullLength = row_info->rowbytes - bpp; // number of bytes to filter
+ bpp = (row_info->pixel_depth + 7) >> 3; // calc number of bytes per pixel
+ FullLength = row_info->rowbytes - bpp; // number of bytes to filter
+ // (why do we subtract off bpp? not so in avg or paeth...)
__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
+ SAVE_r15
+ SAVE_ebp
+//pre "movl row, %1 \n\t" // edi/rdi
+ "mov %1, " PSI " \n\t" // lp = row
+//pre "movl bpp, %%ecx \n\t"
+ "add " PCX ", %1 \n\t" // rp = row + bpp
+//pre "movl FullLength, %%eax \n\t" // bring in via eax...
+ SAVE_FullLength // ...but store for later use
+
+ "xorl %%eax, %%eax \n\t"
+
+ // get # of bytes to alignment (note: computing _delta_ of two pointers,
+ // so hereafter %%ebp is sufficient even on 64-bit)
+ "mov %1, " PBP " \n\t" // take start of row
+ "add $0xf, " PBP " \n\t" // add 7+8 to incr past alignment bdry
+// "andl $0xfffffff8, %%ebp \n\t" // mask to alignment boundary (32-bit!)
+ CLEAR_BOTTOM_3_BITS PBP "\n\t" // mask to alignment boundary
+ "sub %1, " PBP " \n\t" // subtract row ptr again => ebp =
+ "jz sub_go \n\t" // target value of eax 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"
+ "movb (" PSI "," PAX ",), %%cl \n\t"
+ "addb %%cl, (%1," PAX ",) \n\t"
+ "incl %%eax \n\t"
+ "cmpl %%ebp, %%eax \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
+ RESTORE_FullLength "%%ecx \n\t" // FullLength -> ecx
+ "movl %%ecx, %%edx \n\t"
+ "subl %%eax, %%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
+ "subl %%edx, %%ecx \n\t" // drop over bytes from length
+//out "movl %%ecx, MMXLength \n\t"
+ "movl %%ebp, %%eax \n\t" // ebp = diff, but no reg constraint(?)
+ RESTORE_ebp // (could swap ebp and ecx functions,
+ RESTORE_r15 // but %%cl issues...)
+
+ : "=c" (MMXLength), // 0 // output regs
+ "=D" (dummy_value_D), // 1
+ "=a" (diff) // 2
+
+ : "0" (bpp), // ecx // input regs
+ "1" (row), // edi
+ "2" (FullLength) // eax
+
+ : "%esi", "%edx" // clobber list
+ _CLOBBER_r15
+ _CLOBBER_ebp
);
// now do the math for the rest of the row
@@ -4562,230 +5191,296 @@ png_read_filter_row_mmx_sub(png_row_infop row_info, png_bytep row)
{
case 3:
{
- _ActiveMask.use = 0x0000ffffff000000LL;
- _ShiftBpp.use = 24; // == 3 * 8
- _ShiftRem.use = 40; // == 64 - 24
+// _ShiftBpp = 24; // == 3 * 8
+// _ShiftRem = 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
+// preload "mov row, %1 \n\t" // edi/rdi
+ LOAD_GOT_rbp
+ // load (former) _ActiveMask for 2nd active byte group
+ "movq " AMASK2_3_3 ", %%mm7 \n\t" // _amask2_3_3
+ RESTORE_rbp
+
+// notused "mov %1, " PSI " \n\t" // lp = row
+// preload "movl bpp, %%ecx \n\t"
+ "add " PCX ", %1 \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
+// preload "movl diff, %%edx \n\t"
+ "psllq $24, %%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"
+ "movq -8(%1," PDX ",), %%mm1 \n\t"
"sub_3lp: \n\t" // shift data for adding first
- "psrlq _ShiftRem, %%mm1 \n\t" // bpp bytes (no need for mask;
+ "psrlq $40, %%mm1 \n\t" // bpp bytes (no need for mask;
// shift clears inactive bytes)
// add 1st active group
- "movq (%%edi,%%edx,), %%mm0 \n\t"
+ "movq (%1," PDX ",), %%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
+ "psllq $24, %%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
+ "psllq $24, %%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
+ "cmpl %%eax, %%edx \n\t" // MMXLength
+ "movq %%mm0, -8(%1," PDX ",) \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
+ : "=c" (dummy_value_c), // 0 // output regs (dummy)
+ "=D" (dummy_value_D), // 1
+ "=d" (dummy_value_d), // 2
+ "=a" (dummy_value_a) // 3
- : "0" (bpp), // eax // input regs
- "1" (row) // edi
+ : "0" (bpp), // ecx // input regs
+ "1" (row), // edi
+ "2" (diff), // edx
+ "3" (MMXLength) // eax
- : "%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"
+#if defined(CLOBBER_MMX_REGS_SUPPORTED)
+ : "%mm0", "%mm1", "%mm6", "%mm7" // clobber list
#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;
+ break; // end 3 bpp
- case 6:
- case 4:
- //case 7: // GRR BOGUS
- //case 5: // GRR BOGUS
- {
- _ShiftBpp.use = bpp << 3;
- _ShiftRem.use = 64 - _ShiftBpp.use;
+ case 4: // formerly shared with 6 bpp case via _ShiftBpp and _ShiftRem,
+ { // but 64-bit PIC/.so problems (could still share, moving vars
+ // into unused MMX regs via ecx/edx, but kludgy)
+// _ShiftBpp = bpp << 3; // 32 (psllq)
+// _ShiftRem = 64 - _ShiftBpp; // 32 (psrlq)
__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
+// preload "mov row, %1 \n\t" // edi/rdi
+// preload "movl diff, %%edx \n\t"
+// notused "mov %1, " PSI " \n\t" // lp = row
+// preload "movl bpp, %%ecx \n\t"
+ "add " PCX ", %1 \n\t" // rp = row + bpp
// prime the pump: load the first Raw(x-bpp) data set
- "movq -8(%%edi,%%edx,), %%mm1 \n\t"
+ "movq -8(%1," PDX ",), %%mm1 \n\t"
"sub_4lp: \n\t" // shift data for adding first
- "psrlq _ShiftRem, %%mm1 \n\t" // bpp bytes (no need for mask;
+ "psrlq $32, %%mm1 \n\t" // bpp bytes (no need for mask;
// shift clears inactive bytes)
- "movq (%%edi,%%edx,), %%mm0 \n\t"
+ "movq (%1," PDX ",), %%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
+ "psllq $32, %%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"
+ "cmpl %%eax, %%edx \n\t" // MMXLength
+ "movq %%mm0, -8(%1," PDX ",) \n\t" // write updated Raws to array
"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
+ : "=c" (dummy_value_c), // 0 // output regs (dummy)
+ "=D" (dummy_value_D), // 1
+ "=d" (dummy_value_d), // 2
+ "=a" (dummy_value_a) // 3
- : "0" (bpp), // eax // input regs
- "1" (row) // edi
+ : "0" (bpp), // ecx // input regs
+ "1" (row), // edi
+ "2" (diff), // edx
+ "3" (MMXLength) // eax
- : "%edx", "%esi" // clobber list
-#if 0 /* MMX regs (%mm0, etc.) not supported by gcc 2.7.2.3 or egcs 1.1 */
- , "%mm0", "%mm1"
+#if defined(CLOBBER_MMX_REGS_SUPPORTED)
+ : "%mm0", "%mm1" // clobber list
#endif
);
}
- break;
+ break; // end 4 bpp
+
+ case 1:
+ {
+ __asm__ __volatile__ (
+// preload "movl diff, %%edx \n\t"
+// preload "mov row, %1 \n\t" // edi/rdi
+// preload "cmpl FullLength, %%edx \n\t"
+ "cmpl %%eax, %%edx \n\t"
+ "jnb sub_1end \n\t"
+ "mov %1, " PSI " \n\t" // lp = row
+// irrel. "xorl %%ecx, %%ecx \n\t" // (actually bug with preload)
+// preload "movl bpp, %%ecx \n\t"
+ "add " PCX ", %1 \n\t" // rp = row + bpp
+
+ "sub_1lp: \n\t"
+ "movb (" PSI "," PDX ",), %%cl \n\t"
+ "addb %%cl, (%1," PDX ",) \n\t"
+ "incl %%edx \n\t"
+ "cmpl %%eax, %%edx \n\t" // compare with FullLength
+ "jb sub_1lp \n\t"
+
+ "sub_1end: \n\t"
+
+ : "=c" (dummy_value_c), // 0 // output regs (dummy)
+ "=D" (dummy_value_D), // 1
+ "=d" (dummy_value_d), // 2
+ "=a" (dummy_value_a) // 3
+
+ : "0" (bpp), // ecx // input regs
+ "1" (row), // edi
+ "2" (diff), // edx
+ "3" (FullLength) // eax
+
+ : "%esi" // clobber list
+ );
+ }
+ return; // end 1 bpp (bypassing cleanup block!)
case 2:
{
- _ActiveMask.use = 0x00000000ffff0000LL;
- _ShiftBpp.use = 16; // == 2 * 8
- _ShiftRem.use = 48; // == 64 - 16
+// _ShiftBpp = 16; // == 2 * 8
+// _ShiftRem = 48; // == 64 - 16
__asm__ __volatile__ (
- "movq _ActiveMask, %%mm7 \n\t" // load _ActiveMask for 2nd
- // active byte group
- "movl _dif, %%edx \n\t"
+ LOAD_GOT_rbp
+ // load (former) _ActiveMask for 2nd active byte group
+ "movq " AMASK4_2_2 ", %%mm7 \n\t" // _amask4_2_2
+ RESTORE_rbp
+// preload "movl diff, %%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
+// preload "mov row, %1 \n\t" // edi/rdi
+ "psllq $16, %%mm6 \n\t" // move mask in mm6 to cover
// 3rd active byte group
- "movl %%edi, %%esi \n\t" // lp = row
+// notused "mov %1, " PSI " \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
+// preload "movl bpp, %%ecx \n\t"
+ "add " PCX ", %1 \n\t" // rp = row + bpp
+ "psllq $16, %%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"
+ "movq -8(%1," PDX ",), %%mm1 \n\t"
"sub_2lp: \n\t" // shift data for adding first
- "psrlq _ShiftRem, %%mm1 \n\t" // bpp bytes (no need for mask;
+ "psrlq $48, %%mm1 \n\t" // bpp bytes (no need for mask;
// shift clears inactive bytes)
// add 1st active group
- "movq (%%edi,%%edx,), %%mm0 \n\t"
+ "movq (%1," PDX ",), %%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
+ "psllq $16, %%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
+ "psllq $16, %%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
+ "psllq $16, %%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
+ "cmpl %%eax, %%edx \n\t" // MMXLength
+ "movq %%mm0, -8(%1," PDX ",) \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
+ : "=c" (dummy_value_c), // 0 // output regs (dummy)
+ "=D" (dummy_value_D), // 1
+ "=d" (dummy_value_d), // 2
+ "=a" (dummy_value_a) // 3
- : "0" (bpp), // eax // input regs
- "1" (row) // edi
+ : "0" (bpp), // ecx // input regs
+ "1" (row), // edi
+ "2" (diff), // edx
+ "3" (MMXLength) // eax
- : "%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"
+#if defined(CLOBBER_MMX_REGS_SUPPORTED)
+ : "%mm0", "%mm1", "%mm5", "%mm6" // clobber list
+ , "%mm7"
#endif
);
}
- break;
+ break; // end 2 bpp
+
+ case 6: // formerly shared with 4 bpp case (see comments there)
+ {
+// _ShiftBpp = bpp << 3; // 48 (psllq)
+// _ShiftRem = 64 - _ShiftBpp; // 16 (psrlq)
+
+ __asm__ __volatile__ (
+// preload "mov row, %1 \n\t" // edi/rdi
+// preload "movl diff, %%edx \n\t"
+// notused "mov %1, " PSI " \n\t" // lp = row
+// preload "movl bpp, %%ecx \n\t"
+ "add " PCX ", %1 \n\t" // rp = row + bpp
+
+ // prime the pump: load the first Raw(x-bpp) data set
+ "movq -8(%1," PDX ",), %%mm1 \n\t"
+
+ "sub_6lp: \n\t" // shift data for adding first
+ "psrlq $16, %%mm1 \n\t" // bpp bytes (no need for mask;
+ // shift clears inactive bytes)
+ "movq (%1," PDX ",), %%mm0 \n\t"
+ "paddb %%mm1, %%mm0 \n\t"
+
+ // add 2nd active group
+ "movq %%mm0, %%mm1 \n\t" // mov updated Raws to mm1
+ "psllq $48, %%mm1 \n\t" // shift data to pos. correctly
+ "addl $8, %%edx \n\t"
+ "paddb %%mm1, %%mm0 \n\t"
+
+ "cmpl %%eax, %%edx \n\t" // MMXLength
+ "movq %%mm0, -8(%1," PDX ",) \n\t" // write updated Raws to array
+ "movq %%mm0, %%mm1 \n\t" // prep 1st add at top of loop
+ "jb sub_6lp \n\t"
+
+ : "=c" (dummy_value_c), // 0 // output regs (dummy)
+ "=D" (dummy_value_D), // 1
+ "=d" (dummy_value_d), // 2
+ "=a" (dummy_value_a) // 3
+
+ : "0" (bpp), // ecx // input regs
+ "1" (row), // edi
+ "2" (diff), // edx
+ "3" (MMXLength) // eax
+
+#if defined(CLOBBER_MMX_REGS_SUPPORTED)
+ : "%mm0", "%mm1" // clobber list
+#endif
+ );
+ }
+ break; // end 6 bpp
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"
+// preload "mov row, %1 \n\t" // edi/rdi
+// preload "movl diff, %%edx \n\t"
+// notused "mov %1, " PSI " \n\t" // lp = row
+// preload "movl bpp, %%ecx \n\t"
+ "add " PCX ", %1 \n\t" // rp = row + bpp
+// preload "movl MMXLength, %%eax \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
+ "movq -8(%1," PDX ",), %%mm7 \n\t"
+ "movl %%eax, %%esi \n\t" // copy of MMXLength -> esi
+ "andl $0x0000003f, %%esi \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
+ "movq (%1," PDX ",), %%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
+ "movq 8(%1," PDX ",), %%mm1 \n\t" // load Sub(x) for 2nd 8 bytes
+ "movq %%mm0, (%1," PDX ",) \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
@@ -4793,130 +5488,118 @@ png_read_filter_row_mmx_sub(png_row_infop row_info, png_bytep row)
// 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
+ "movq 16(%1," PDX ",), %%mm2 \n\t" // load Sub(x) for 3rd 8 bytes
+ "movq %%mm1, 8(%1," PDX ",) \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
+ "movq 24(%1," PDX ",), %%mm3 \n\t" // load Sub(x) for 4th 8 bytes
+ "movq %%mm2, 16(%1," PDX ",) \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
+ "movq 32(%1," PDX ",), %%mm4 \n\t" // load Sub(x) for 5th 8 bytes
+ "movq %%mm3, 24(%1," PDX ",) \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
+ "movq 40(%1," PDX ",), %%mm5 \n\t" // load Sub(x) for 6th 8 bytes
+ "movq %%mm4, 32(%1," PDX ",) \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
+ "movq 48(%1," PDX ",), %%mm6 \n\t" // load Sub(x) for 7th 8 bytes
+ "movq %%mm5, 40(%1," PDX ",) \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
+ "movq 56(%1," PDX ",), %%mm7 \n\t" // load Sub(x) for 8th 8 bytes
+ "movq %%mm6, 48(%1," PDX ",) \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
+ "cmpl %%esi, %%edx \n\t" // cmp to bytes over mult of 64
+ "movq %%mm7, -8(%1," PDX ",) \n\t" // write Raw(x) for 8th 8 bytes
"jb sub_8lp \n\t"
- "cmpl _MMXLength, %%edx \n\t"
+ "cmpl %%eax, %%edx \n\t" // compare to MMXLength
"jnb sub_8lt8 \n\t"
"sub_8lpA: \n\t"
- "movq (%%edi,%%edx,), %%mm0 \n\t"
+ "movq (%1," PDX ",), %%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
+ "cmpl %%eax, %%edx \n\t" // compare to MMXLength
+ "movq %%mm0, -8(%1," PDX ",) \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)
+ "jb sub_8lpA \n\t" // to mm7 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
+ : "=c" (dummy_value_c), // 0 // output regs (dummy)
+ "=D" (dummy_value_D), // 1
+ "=d" (dummy_value_d), // 2
+ "=a" (dummy_value_a) // 3
- : "0" (bpp), // eax // input regs
- "1" (row) // edi
+ : "0" (bpp), // ecx // input regs
+ "1" (row), // edi
+ "2" (diff), // edx
+ "3" (MMXLength) // eax
- : "%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"
+ : "%esi" // clobber list
+#if defined(CLOBBER_MMX_REGS_SUPPORTED)
+ , "%mm0", "%mm1", "%mm2", "%mm3"
+ , "%mm4", "%mm5", "%mm6", "%mm7"
#endif
);
}
- break;
+ break; // end 8 bpp
- default: // bpp greater than 8 bytes GRR BOGUS
+ default: // bpp != 1,2,3,4,6,8: doesn't exist
{
- __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"
+ // ERROR: SHOULD NEVER BE REACHED
+#if defined(PNG_DEBUG)
+ png_debug(1, "Internal libpng logic error (GCC "
+ "png_read_filter_row_mmx_sub())\n");
#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
+//pre "movl MMXLength, %%eax \n\t"
+//pre "mov row, %1 \n\t" // edi/rdi
+//pre "cmpl FullLength, %%eax \n\t"
+ "cmpl %%edx, %%eax \n\t"
+ "jnb sub_end \n\t"
+
+ "mov %1, " PSI " \n\t" // lp = row
+//pre "movl bpp, %%ecx \n\t"
+ "add " PCX ", %1 \n\t" // rp = row + bpp
+ "xorl %%ecx, %%ecx \n\t"
+
+ "sub_lp2: \n\t"
+ "movb (" PSI "," PAX ",), %%cl \n\t"
+ "addb %%cl, (%1," PAX ",) \n\t"
+ "incl %%eax \n\t"
+ "cmpl %%edx, %%eax \n\t" // FullLength
+ "jb sub_lp2 \n\t"
+
+ "sub_end: \n\t"
+ "EMMS \n\t" // end MMX instructions
+
+ : "=c" (dummy_value_c), // 0 // output regs (dummy)
+ "=D" (dummy_value_D), // 1
+ "=a" (dummy_value_a), // 2
+ "=d" (dummy_value_d) // 3
+
+ : "0" (bpp), // ecx // input regs
+ "1" (row), // edi
+ "2" (MMXLength), // eax
+ "3" (FullLength) // edx
+
+ : "%esi" // clobber list
);
} // end of png_read_filter_row_mmx_sub()
-#endif
+
+#endif /* PNG_MMX_READ_FILTER_SUB_SUPPORTED */
+#if defined(PNG_MMX_READ_FILTER_UP_SUPPORTED)
+
//===========================================================================//
// //
// P N G _ R E A D _ F I L T E R _ R O W _ M M X _ U P //
@@ -4929,136 +5612,133 @@ 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;
+ unsigned len; // png_uint_32 is actually 64-bit on x86-64
int dummy_value_d; // fix 'forbidden register 3 (dx) was spilled' error
- int dummy_value_S;
- int dummy_value_D;
+ png_bytep dummy_value_S;
+ png_bytep 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__
- "pushl %%ebx \n\t"
-#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
+ SAVE_GOT_ebx
+//pre "mov prev_row, %1 \n\t" // esi/rsi
+//pre "movl row, %2 \n\t" // edi/rdi
+
+ "xorl %%ebx, %%ebx \n\t"
+ "xorl %%eax, %%eax \n\t"
+
+ // get # of bytes to alignment (note: computing _delta_ of two pointers,
+ // so hereafter %%ecx is sufficient even on 64-bit)
+ "mov %2, " PCX " \n\t" // take start of row
+ "add $0x7, " PCX " \n\t" // add 7 to incr past alignment bdry
+// "andl $0xfffffff8, %%ecx \n\t" // mask to alignment boundary (32-bit!)
+ CLEAR_BOTTOM_3_BITS PCX "\n\t" // mask to alignment boundary
+ "sub %2, " PCX " \n\t" // subtract row ptr again => ebp =
+ "jz up_go \n\t" // target value of ecx at alignment
+
+ "up_lp1: \n\t" // fix alignment
+ "movb (%2," PBX ",), %%al \n\t"
+ "addb (%1," PBX ",), %%al \n\t"
+ "incl %%ebx \n\t"
+ "cmpl %%ecx, %%ebx \n\t"
+ "movb %%al, -1(%2," PBX ",) \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" // sub over-bytes from original 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__
- "popl %%ebx \n\t"
-#endif
+ "up_loop: \n\t"
+ "movq (%1," PBX ",), %%mm1 \n\t"
+ "movq (%2," PBX ",), %%mm0 \n\t"
+ "movq 8(%1," PBX ",), %%mm3 \n\t"
+ "paddb %%mm1, %%mm0 \n\t"
+ "movq 8(%2," PBX ",), %%mm2 \n\t"
+ "movq %%mm0, (%2," PBX ",) \n\t"
+ "paddb %%mm3, %%mm2 \n\t"
+ "movq 16(%1," PBX ",), %%mm5 \n\t"
+ "movq %%mm2, 8(%2," PBX ",) \n\t"
+ "movq 16(%2," PBX ",), %%mm4 \n\t"
+ "movq 24(%1," PBX ",), %%mm7 \n\t"
+ "paddb %%mm5, %%mm4 \n\t"
+ "movq 24(%2," PBX ",), %%mm6 \n\t"
+ "movq %%mm4, 16(%2," PBX ",) \n\t"
+ "paddb %%mm7, %%mm6 \n\t"
+ "movq 32(%1," PBX ",), %%mm1 \n\t"
+ "movq %%mm6, 24(%2," PBX ",) \n\t"
+ "movq 32(%2," PBX ",), %%mm0 \n\t"
+ "movq 40(%1," PBX ",), %%mm3 \n\t"
+ "paddb %%mm1, %%mm0 \n\t"
+ "movq 40(%2," PBX ",), %%mm2 \n\t"
+ "movq %%mm0, 32(%2," PBX ",) \n\t"
+ "paddb %%mm3, %%mm2 \n\t"
+ "movq 48(%1," PBX ",), %%mm5 \n\t"
+ "movq %%mm2, 40(%2," PBX ",) \n\t"
+ "movq 48(%2," PBX ",), %%mm4 \n\t"
+ "movq 56(%1," PBX ",), %%mm7 \n\t"
+ "paddb %%mm5, %%mm4 \n\t"
+ "movq 56(%2," PBX ",), %%mm6 \n\t"
+ "movq %%mm4, 48(%2," PBX ",) \n\t"
+ "addl $64, %%ebx \n\t"
+ "paddb %%mm7, %%mm6 \n\t"
+ "cmpl %%ecx, %%ebx \n\t"
+ "movq %%mm6, -8(%2," PBX ",) \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]
- : "=d" (dummy_value_d), // 0 // output regs (dummy)
+ "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 (%1," PBX ",), %%mm1 \n\t"
+ "movq (%2," PBX ",), %%mm0 \n\t"
+ "addl $8, %%ebx \n\t"
+ "paddb %%mm1, %%mm0 \n\t"
+ "cmpl %%ecx, %%ebx \n\t"
+ "movq %%mm0, -8(%2," PBX ",) \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 (%2," PBX ",), %%al \n\t"
+ "addb (%1," PBX ",), %%al \n\t"
+ "incl %%ebx \n\t"
+ "cmpl %%ecx, %%ebx \n\t"
+ "movb %%al, -1(%2," PBX ",) \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
+ RESTORE_GOT_ebx
+
+ : "=d" (dummy_value_d), // 0 // output regs (dummy)
"=S" (dummy_value_S), // 1
"=D" (dummy_value_D) // 2
- : "0" (len), // edx // input regs
+ : "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 */
+ : "%eax", "%ecx" // clobber list (no input regs!)
+ _CLOBBER_GOT_ebx
+#if defined(PNG_CLOBBER_MMX_REGS_SUPPORTED)
, "%mm0", "%mm1", "%mm2", "%mm3"
, "%mm4", "%mm5", "%mm6", "%mm7"
#endif
@@ -5066,7 +5746,7 @@ png_read_filter_row_mmx_up(png_row_infop row_info, png_bytep row,
} // end of png_read_filter_row_mmx_up()
-#endif /* PNG_MMX_CODE_SUPPORTED */
+#endif /* PNG_MMX_READ_FILTER_UP_SUPPORTED */
@@ -5077,79 +5757,105 @@ png_read_filter_row_mmx_up(png_row_infop row_info, png_bytep row,
/* */
/*===========================================================================*/
-
/* 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];
+#if defined(PNG_DEBUG)
+ char filtname[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 */
#if !defined(PNG_1_0_X)
+ /* this should have happened in png_init_mmx_flags() already */
png_warning(png_ptr, "asm_flags may not have been initialized");
#endif
png_mmx_support();
}
-#endif /* PNG_MMX_CODE_SUPPORTED */
-#ifdef PNG_DEBUG
+#if defined(PNG_DEBUG)
png_debug(1, "in png_read_filter_row (pnggccrd.c)\n");
switch (filter)
{
- case 0: sprintf(filnm, "none");
+ case 0:
+ png_snprintf(filtname, 10, "none");
break;
- case 1: sprintf(filnm, "sub-%s",
-#if defined(PNG_MMX_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK)
+
+ case 1:
+ png_snprintf(filtname, 10, "sub-%s",
+#ifdef PNG_MMX_READ_FILTER_SUB_SUPPORTED
#if !defined(PNG_1_0_X)
- (png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_SUB)? "MMX" :
+ ((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))
+#else
+ _mmx_supported
#endif
+ ? "MMX" :
#endif
-"x86");
+ "C");
break;
- case 2: sprintf(filnm, "up-%s",
-#ifdef PNG_MMX_CODE_SUPPORTED
+
+ case 2:
+ png_snprintf(filtname, 10, "up-%s",
+#ifdef PNG_MMX_READ_FILTER_UP_SUPPORTED
#if !defined(PNG_1_0_X)
- (png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_UP)? "MMX" :
+ ((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))
+#else
+ _mmx_supported
#endif
+ ? "MMX" :
#endif
- "x86");
+ "C");
break;
- case 3: sprintf(filnm, "avg-%s",
-#if defined(PNG_MMX_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK)
+
+ case 3:
+ png_snprintf(filtname, 10, "avg-%s",
+#ifdef PNG_MMX_READ_FILTER_AVG_SUPPORTED
#if !defined(PNG_1_0_X)
- (png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_AVG)? "MMX" :
+ ((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))
+#else
+ _mmx_supported
#endif
+ ? "MMX" :
#endif
- "x86");
+ "C");
break;
- case 4: sprintf(filnm, "Paeth-%s",
-#if defined(PNG_MMX_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK)
+
+ case 4:
+ png_snprintf(filtname, 10, "paeth-%s",
+#ifdef PNG_MMX_READ_FILTER_PAETH_SUPPORTED
+#if defined(PNG_x86_64_USE_GOTPCREL) || defined(PNG_THREAD_UNSAFE_OK)
#if !defined(PNG_1_0_X)
- (png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_PAETH)? "MMX":
+ ((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))
+#else
+ _mmx_supported
#endif
+ ? "MMX" :
+#endif /* PNG_x86_64_USE_GOTPCREL || PNG_THREAD_UNSAFE_OK */
#endif
-"x86");
+ "C");
break;
- default: sprintf(filnm, "unknw");
+
+ default:
+ png_snprintf(filtname, 10, "unknown");
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,
+ png_debug2(2, "row_number=%ld, %s, ", png_ptr->row_number, filtname);
+ //png_debug1(0, "png_ptr=%10p, ", png_ptr);
+ //png_debug1(0, "asm_flags=0x%08lx, ", png_ptr->asm_flags);
+ png_debug1(0, "row=%10p, ", row);
+ png_debug2(0, "pixdepth=%d, bytes=%d, ", (int)row_info->pixel_depth,
(int)((row_info->pixel_depth + 7) >> 3));
- png_debug1(0,"rowbytes=%8ld\n", row_info->rowbytes);
+ png_debug1(0, "rowbytes=%ld\n", row_info->rowbytes);
#endif /* PNG_DEBUG */
switch (filter)
@@ -5158,7 +5864,7 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep
break;
case PNG_FILTER_VALUE_SUB:
-#if defined(PNG_MMX_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK)
+#ifdef PNG_MMX_READ_FILTER_SUB_SUPPORTED
#if !defined(PNG_1_0_X)
if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_SUB) &&
(row_info->pixel_depth >= png_ptr->mmx_bitdepth_threshold) &&
@@ -5170,7 +5876,7 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep
png_read_filter_row_mmx_sub(row_info, row);
}
else
-#endif /* PNG_MMX_CODE_SUPPORTED */
+#endif
{
png_uint_32 i;
png_uint_32 istop = row_info->rowbytes;
@@ -5187,7 +5893,7 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep
break;
case PNG_FILTER_VALUE_UP:
-#if defined(PNG_MMX_CODE_SUPPORTED)
+#ifdef PNG_MMX_READ_FILTER_UP_SUPPORTED
#if !defined(PNG_1_0_X)
if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_UP) &&
(row_info->pixel_depth >= png_ptr->mmx_bitdepth_threshold) &&
@@ -5199,7 +5905,7 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep
png_read_filter_row_mmx_up(row_info, row, prev_row);
}
else
-#endif /* PNG_MMX_CODE_SUPPORTED */
+#endif
{
png_uint_32 i;
png_uint_32 istop = row_info->rowbytes;
@@ -5215,7 +5921,7 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep
break;
case PNG_FILTER_VALUE_AVG:
-#if defined(PNG_MMX_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK)
+#ifdef PNG_MMX_READ_FILTER_AVG_SUPPORTED
#if !defined(PNG_1_0_X)
if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_AVG) &&
(row_info->pixel_depth >= png_ptr->mmx_bitdepth_threshold) &&
@@ -5227,7 +5933,7 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep
png_read_filter_row_mmx_avg(row_info, row, prev_row);
}
else
-#endif /* PNG_MMX_CODE_SUPPORTED */
+#endif
{
png_uint_32 i;
png_bytep rp = row;
@@ -5253,7 +5959,8 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep
break;
case PNG_FILTER_VALUE_PAETH:
-#if defined(PNG_MMX_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK)
+#ifdef PNG_MMX_READ_FILTER_PAETH_SUPPORTED
+#if defined(PNG_x86_64_USE_GOTPCREL) || defined(PNG_THREAD_UNSAFE_OK)
#if !defined(PNG_1_0_X)
if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_PAETH) &&
(row_info->pixel_depth >= png_ptr->mmx_bitdepth_threshold) &&
@@ -5265,7 +5972,8 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep
png_read_filter_row_mmx_paeth(row_info, row, prev_row);
}
else
-#endif /* PNG_MMX_CODE_SUPPORTED */
+#endif /* PNG_x86_64_USE_GOTPCREL || PNG_THREAD_UNSAFE_OK */
+#endif
{
png_uint_32 i;
png_bytep rp = row;
@@ -5292,7 +6000,7 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep
p = b - c;
pc = a - c;
-#ifdef PNG_USE_ABS
+#if defined(PNG_USE_ABS)
pa = abs(p);
pb = abs(pc);
pc = abs(p + pc);
@@ -5329,92 +6037,5 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep
#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__ (
- "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)
-// ".byte 0x66 \n\t" // convert 16-bit pushf to 32-bit pushfd
-// "pushf \n\t" // 16-bit pushf
- "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
-// ".byte 0x66 \n\t" // convert 16-bit popf to 32-bit popfd
-// "popf \n\t" // 16-bit popf
- "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
- "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
- "popl %%edx \n\t" // restore edx
- "popl %%ecx \n\t" // restore ecx
- "popl %%ebx \n\t" // restore ebx
-
-// "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 */
+#endif /* PNG_ASSEMBLER_CODE_SUPPORTED && PNG_USE_PNGGCCRD */
+#endif /* __GNUC__ */
diff --git a/src/libpng/pngget.c b/src/libpng/pngget.c
index 036e9af6e..75d2ca015 100644
--- a/src/libpng/pngget.c
+++ b/src/libpng/pngget.c
@@ -512,8 +512,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
@@ -800,8 +803,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
@@ -951,5 +957,6 @@ png_get_user_height_max (png_structp png_ptr)
return (png_ptr? png_ptr->user_height_max : 0);
}
#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
+
#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
diff --git a/src/libpng/pngpread.c b/src/libpng/pngpread.c
index 1470b0fe0..7d29e9840 100644
--- a/src/libpng/pngpread.c
+++ b/src/libpng/pngpread.c
@@ -1,7 +1,7 @@
/* pngpread.c - read a png file in push mode
*
- * Last changed in libpng 1.2.17 May 15, 2007
+ * Last changed in libpng 1.2.19 August 18, 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)
@@ -137,60 +137,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
@@ -660,7 +660,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))
{
@@ -990,25 +990,25 @@ 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};
+ PNG_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_width[] = {8, 4, 4, 2, 2, 1, 1};
*/
/* Height of interlace block. This is not currently used - if you need
* it, uncomment it here and in png.h
- 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
@@ -1062,8 +1062,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
@@ -1159,8 +1158,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
@@ -1352,8 +1350,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
@@ -1480,9 +1477,7 @@ png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32
#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)
@@ -1496,8 +1491,9 @@ png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32
length = (png_uint_32)65535L;
}
#endif
- png_strcpy((png_charp)png_ptr->unknown_chunk.name,
- (png_charp)png_ptr->chunk_name);
+ png_strncpy((png_charp)png_ptr->unknown_chunk.name,
+ (png_charp)png_ptr->chunk_name,
+ png_sizeof((png_charp)png_ptr->chunk_name));
png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
png_ptr->unknown_chunk.size = (png_size_t)length;
png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
@@ -1559,7 +1555,7 @@ png_progressive_combine_row (png_structp png_ptr,
png_bytep old_row, png_bytep new_row)
{
#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;
diff --git a/src/libpng/pngread.c b/src/libpng/pngread.c
index 56dac8a80..2e561e8fa 100644
--- a/src/libpng/pngread.c
+++ b/src/libpng/pngread.c
@@ -1,7 +1,7 @@
/* pngread.c - read a PNG file
*
- * Last changed in libpng 1.2.15 January 5, 2007
+ * Last changed in libpng 1.2.19 August 18, 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)
@@ -117,11 +117,13 @@ png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
char msg[80];
if (user_png_ver)
{
- 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);
}
- 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
@@ -197,11 +199,13 @@ png_read_init_2(png_structp png_ptr, png_const_charp user_png_ver,
png_ptr->warning_fn=NULL;
if (user_png_ver)
{
- 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);
}
- 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);
}
@@ -346,60 +350,60 @@ png_read_info(png_structp png_ptr, png_infop info_ptr)
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_byte chunk_length[4];
@@ -567,9 +571,10 @@ 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;
@@ -925,60 +930,60 @@ png_read_end(png_structp png_ptr, png_infop info_ptr)
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 */
@@ -1464,8 +1469,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/src/libpng/pngrtran.c b/src/libpng/pngrtran.c
index 6ef0a1c07..3f0405133 100644
--- a/src/libpng/pngrtran.c
+++ b/src/libpng/pngrtran.c
@@ -1,7 +1,7 @@
/* pngrtran.c - transforms the data in a row for PNG readers
*
- * Last changed in libpng 1.2.15 January 5, 2007
+ * Last changed in libpng 1.2.19 August 18, 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)
@@ -548,6 +548,9 @@ png_set_expand(png_structp png_ptr)
png_debug(1, "in png_set_expand\n");
if(png_ptr == NULL) return;
png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
+#ifdef PNG_WARN_UNINITIALIZED_ROW
+ png_ptr->flags &= !(PNG_FLAG_ROW_INIT);
+#endif
}
/* GRR 19990627: the following three functions currently are identical
@@ -574,6 +577,9 @@ png_set_palette_to_rgb(png_structp png_ptr)
png_debug(1, "in png_set_palette_to_rgb\n");
if(png_ptr == NULL) return;
png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
+#ifdef PNG_WARN_UNINITIALIZED_ROW
+ png_ptr->flags &= !(PNG_FLAG_ROW_INIT);
+#endif
}
#if !defined(PNG_1_0_X)
@@ -584,6 +590,9 @@ 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;
+#ifdef PNG_WARN_UNINITIALIZED_ROW
+ png_ptr->flags &= !(PNG_FLAG_ROW_INIT);
+#endif
}
#endif
@@ -604,8 +613,11 @@ png_set_gray_1_2_4_to_8(png_structp png_ptr)
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);
+#ifdef PNG_WARN_UNINITIALIZED_ROW
+ png_ptr->flags &= !(PNG_FLAG_ROW_INIT);
+#endif
}
#endif /* defined(PNG_READ_EXPAND_SUPPORTED) */
@@ -615,6 +627,9 @@ 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;
+#ifdef PNG_WARN_UNINITIALIZED_ROW
+ png_ptr->flags &= !(PNG_FLAG_ROW_INIT);
+#endif
}
#endif
@@ -1244,19 +1259,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)
{
#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
char msg[50];
- sprintf(msg, "NULL row buffer for row %ld, pass %d", png_ptr->row_number,
+ png_snprintf2(msg, 50,
+ "NULL row buffer for row %ld, pass %d", 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)
@@ -1269,7 +1294,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
@@ -1293,9 +1319,11 @@ png_do_read_transformations(png_structp png_ptr)
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");
}
}
@@ -3699,7 +3727,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);
@@ -3723,7 +3751,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);
@@ -3746,7 +3774,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);
@@ -3776,6 +3804,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++)
@@ -3789,12 +3818,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;
@@ -3819,13 +3849,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;
@@ -3836,16 +3867,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;
@@ -3965,7 +4002,7 @@ png_do_dither(png_row_infop row_info, png_bytep row,
#ifdef PNG_FLOATING_POINT_SUPPORTED
#if defined(PNG_READ_GAMMA_SUPPORTED)
-const static int png_gamma_shift[] =
+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
diff --git a/src/libpng/pngrutil.c b/src/libpng/pngrutil.c
index 2abca7cc5..86e924c2d 100644
--- a/src/libpng/pngrutil.c
+++ b/src/libpng/pngrutil.c
@@ -1,7 +1,7 @@
/* pngrutil.c - utilities to read a PNG file
*
- * Last changed in libpng 1.2.17 May 15, 2007
+ * Last changed in libpng 1.2.19 August 18, 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)
@@ -16,10 +16,14 @@
#if defined(PNG_READ_SUPPORTED)
+#if defined(_WIN32_WCE) && (_WIN32_WCE<0x500)
+# define WIN32_WCE_OLD
+#endif
+
#ifdef PNG_FLOATING_POINT_SUPPORTED
-# if defined(_WIN32_WCE)
+# if defined(WIN32_WCE_OLD)
/* strtod() function is not supported on WindowsCE */
-__inline double png_strtod(png_structp png_ptr, const char *nptr, char **endptr)
+__inline double png_strtod(png_structp png_ptr, PNG_CONST char *nptr, char **endptr)
{
double result = 0;
int len;
@@ -33,7 +37,7 @@ __inline double png_strtod(png_structp png_ptr, const char *nptr, char **endptr)
result = wcstod(str, &end);
len = WideCharToMultiByte(CP_ACP, 0, end, -1, NULL, 0, NULL, NULL);
*endptr = (char *)nptr + (png_strlen(nptr) - len + 1);
- png_free(str);
+ png_free(png_ptr, str);
}
return result;
}
@@ -181,7 +185,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)
{
- const static char msg[] = "Error decoding compressed text";
+ static PNG_CONST char msg[] = "Error decoding compressed text";
png_charp text;
png_size_t text_size;
@@ -282,13 +286,16 @@ png_decompress_chunk(png_structp png_ptr, int comp_type,
char umsg[52];
if (ret == Z_BUF_ERROR)
- 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)
- 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
- 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
@@ -321,7 +328,8 @@ png_decompress_chunk(png_structp png_ptr, int comp_type,
#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
char umsg[50];
- 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");
@@ -563,8 +571,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)
@@ -1037,7 +1044,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");
@@ -1141,7 +1148,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");
@@ -1234,9 +1241,15 @@ void /* PRIVATE */
png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
{
png_byte readbuf[PNG_MAX_PALETTE_LENGTH];
+ int bit_mask;
png_debug(1, "in png_handle_tRNS\n");
+ /* For non-indexed color, mask off any bits in the tRNS value that
+ * exceed the bit depth. Some creators were writing extra bits there.
+ * This is not needed for indexed color. */
+ bit_mask = (1 << png_ptr->bit_depth) - 1;
+
if (!(png_ptr->mode & PNG_HAVE_IHDR))
png_error(png_ptr, "Missing IHDR before tRNS");
else if (png_ptr->mode & PNG_HAVE_IDAT)
@@ -1265,7 +1278,7 @@ png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_crc_read(png_ptr, buf, 2);
png_ptr->num_trans = 1;
- png_ptr->trans_values.gray = png_get_uint_16(buf);
+ png_ptr->trans_values.gray = png_get_uint_16(buf) & bit_mask;
}
else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
{
@@ -1279,9 +1292,9 @@ png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
}
png_crc_read(png_ptr, buf, (png_size_t)length);
png_ptr->num_trans = 1;
- png_ptr->trans_values.red = png_get_uint_16(buf);
- png_ptr->trans_values.green = png_get_uint_16(buf + 2);
- png_ptr->trans_values.blue = png_get_uint_16(buf + 4);
+ png_ptr->trans_values.red = png_get_uint_16(buf) & bit_mask;
+ png_ptr->trans_values.green = png_get_uint_16(buf + 2) & bit_mask;
+ png_ptr->trans_values.blue = png_get_uint_16(buf + 4) & bit_mask;
}
else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
{
@@ -1981,10 +1994,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 - 1)
{
- 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
{
@@ -2084,10 +2098,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
{
@@ -2102,6 +2117,12 @@ png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
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;
@@ -2151,7 +2172,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;
@@ -2184,8 +2205,9 @@ 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)png_ptr->unknown_chunk.name,
- (png_charp)png_ptr->chunk_name);
+ png_strncpy((png_charp)png_ptr->unknown_chunk.name,
+ (png_charp)png_ptr->chunk_name,
+ png_sizeof((png_charp)png_ptr->chunk_name));
png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
png_ptr->unknown_chunk.size = (png_size_t)length;
png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
@@ -2221,8 +2243,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
}
@@ -2255,11 +2276,1050 @@ 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
+
+/* Optimized C version of utilities to read a PNG file
+ *
+ * Based on code contributed by Nirav Chhatrapati, Intel Corp., 1998.
+ * Interface to libpng contributed by Gilles Vollant, 1999.
+ * GNU C port by Greg Roelofs, 1999-2001.
+ *
+ */
+
+#if defined(PNG_OPTIMIZED_CODE_SUPPORTED)
+#if !defined(PNG_HAVE_MMX_COMBINE_ROW)
+
+/*===========================================================================*/
+/* */
+/* P N G _ C O M B I N E _ R O W */
+/* */
+/*===========================================================================*/
+
+
+#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\n");
+
+#if defined(PNG_USE_LOCAL_ARRAYS)
+static PNG_CONST int FARDATA png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
+static PNG_CONST int FARDATA png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
+static PNG_CONST int FARDATA png_pass_width[7] = {8, 4, 4, 2, 2, 1, 1};
+#endif
+
+ png_debug(1, "in png_combine_row (pngrutil.c OPTIMIZED)\n");
+
+ if (mask == 0xff)
+ {
+ png_debug(2,"mask == 0xff: doing single png_memcpy()\n");
+ png_memcpy(row, png_ptr->row_buf + 1,
+ (png_size_t)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)
+ {
+ /* most common case: combining 24-bit RGB */
+ case 24: /* png_ptr->row_info.pixel_depth */
+ {
+ png_bytep srcptr;
+ png_bytep dstptr;
+
+ {
+ 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;
+
+ {
+ 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;
+ }
+ }
+ }
+
+ break;
+ } /* end 32 bpp */
+
+ case 8: /* png_ptr->row_info.pixel_depth */
+ {
+ png_bytep srcptr;
+ png_bytep dstptr;
+ {
+ 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;
+ }
+ }
+ }
+
+ break;
+ } /* end 8 bpp */
+
+ 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;
+ } /* end 1 bpp */
+
+ 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;
+ } /* end 2 bpp */
+
+ 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;
+ } /* end 4 bpp */
+
+ case 16: /* png_ptr->row_info.pixel_depth */
+ {
+ png_bytep srcptr;
+ png_bytep dstptr;
+
+ {
+ 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 48: /* png_ptr->row_info.pixel_depth */
+ {
+ png_bytep srcptr;
+ png_bytep dstptr;
+ {
+ 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;
+ }
+ }
+ }
+ 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 pngrutil");
+ 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)
+{
+#if defined(PNG_USE_LOCAL_ARRAYS)
+static PNG_CONST int FARDATA png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
+#endif
+ 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 (pngrutil.c OPTIMIZED)\n");
+
+ 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) */
+ {
+ 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;
+
+ /* 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 */
+ {
+ 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++)
+ {
+#if defined(PNG_DEBUG) && defined(PNG_1_0_X)
+ 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;
+ }
+ }
+
+ }
+ 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)
+/*===========================================================================*/
+/* */
+/* 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)
+{
+#if defined(PNG_DEBUG)
+ char filnm[10];
+#endif
+
+
+#if defined(PNG_DEBUG)
+ png_debug(1, "in png_read_filter_row (pngrutil.c OPTIMIZED)\n");
+ switch (filter)
+ {
+ case 0:
+ png_snprintf(filnm, 10, "none");
+ break;
+
+ case 1:
+ png_snprintf(filnm, 10, "sub-%s",
+ "x86");
+ break;
+
+ case 2:
+ png_snprintf(filnm, 10, "up-%s",
+ "x86");
+ break;
+
+ case 3:
+ png_snprintf(filnm, 10, "avg-%s",
+ "x86");
+ break;
+
+ case 4:
+ png_snprintf(filnm, 10, "Paeth-%s",
+ "x86");
+ break;
+
+ default:
+ png_snprintf(filnm, 10, "unknown");
+ break;
+ }
+ png_debug2(0, "row_number=%5ld, %10s, ", 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:
+ {
+ 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:
+ {
+ 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:
+ {
+ 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:
+ {
+ 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;
+
+#if defined(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_HAVE_MMX_READ_FILTER_ROW */
+#endif /* PNG_OPTIMIZED_CODE_SUPPORTED */
+
+#if !defined(PNG_USE_PNGGCCRD) && !defined(PNG_USE_PNGVCRD)
+#if !defined(PNG_OPTIMIZED_CODE_SUPPORTED)
+/* Use the unoptimized original C code. This might be removed from a future
+ * version of libpng if testing proves it to be worthless. */
+void /* PRIVATE */
+png_combine_row(png_structp png_ptr, png_bytep row, int mask)
+{
+ png_debug(1,"in png_combine_row NOT OPTIMIZED\n");
if (mask == 0xff)
{
png_memcpy(row, png_ptr->row_buf + 1,
@@ -2456,10 +3516,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)
@@ -2474,10 +3532,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 (pngrutil.c NOT OPTIMIZED)\n");
if (row != NULL && row_info != NULL)
{
png_uint_32 final_width;
@@ -2681,19 +3739,16 @@ png_do_read_interlace(png_structp png_ptr)
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_debug(1, "in png_read_filter_row (NOT OPTIMIZED)\n");
png_debug2(2,"row = %lu, filter = %d\n", png_ptr->row_number, filter);
switch (filter)
{
@@ -2811,7 +3866,8 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row,
break;
}
}
-#endif /* !PNG_HAVE_MMX_READ_FILTER_ROW */
+#endif /* !PNG_OPTIMIZED_CODE_SUPPORTED */
+#endif /* !PNG_USE_PNGGCCRD && !PNG_USE_PNGVCRD */
void /* PRIVATE */
png_read_finish_row(png_structp png_ptr)
@@ -2820,16 +3876,16 @@ png_read_finish_row(png_structp png_ptr)
/* 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_debug(1, "in png_read_finish_row\n");
@@ -2840,7 +3896,8 @@ png_read_finish_row(png_structp png_ptr)
if (png_ptr->interlaced)
{
png_ptr->row_number = 0;
- png_memset_check(png_ptr, png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
+ png_memset_check(png_ptr, png_ptr->prev_row, 0,
+ png_ptr->rowbytes + 1);
do
{
png_ptr->pass++;
@@ -2874,7 +3931,7 @@ png_read_finish_row(png_structp png_ptr)
if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
{
#ifdef PNG_USE_LOCAL_ARRAYS
- PNG_IDAT;
+ PNG_CONST PNG_IDAT;
#endif
char extra;
int ret;
@@ -2947,16 +4004,16 @@ png_read_start_row(png_structp png_ptr)
/* 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
int max_pixel_depth;
@@ -3105,7 +4162,7 @@ defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
#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)
+#if defined(PNG_DEBUG) && defined(PNG_USE_PNGGCCRD) && defined(PNG_1_0_X)
png_ptr->row_buf_size = row_bytes;
#endif
diff --git a/src/libpng/pngset.c b/src/libpng/pngset.c
index f1a1ef610..8d1cbfcd0 100644
--- a/src/libpng/pngset.c
+++ b/src/libpng/pngset.c
@@ -353,7 +353,7 @@ png_set_IHDR(png_structp png_ptr, png_infop info_ptr,
info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth);
/* check for potential overflow */
- if ( width > (PNG_UINT_32_MAX
+ if (width > (PNG_UINT_32_MAX
>> 3) /* 8-byte RGBA pixels */
- 64 /* bigrowbuf hack */
- 1 /* filter byte */
@@ -484,7 +484,8 @@ 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.");
}
png_memcpy(info_ptr->scal_s_width, swidth, (png_size_t)length);
@@ -494,7 +495,8 @@ 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.");
}
png_memcpy(info_ptr->scal_s_height, sheight, (png_size_t)length);
@@ -688,7 +690,7 @@ png_set_iCCP(png_structp png_ptr, png_infop info_ptr,
png_warning(png_ptr, "Insufficient memory to process iCCP chunk.");
return;
}
- png_strcpy(new_iccp_name, name);
+ png_strncpy(new_iccp_name, name, png_sizeof(new_iccp_name));
new_iccp_profile = (png_charp)png_malloc_warn(png_ptr, proflen);
if (new_iccp_profile == NULL)
{
@@ -877,9 +879,6 @@ png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
textp->itxt_length = 0;
#endif
}
-#if 0 /* appears to be redundant; */
- info_ptr->text[info_ptr->num_text]= *textp;
-#endif
info_ptr->num_text++;
png_debug1(3, "transferred text chunk %d\n", info_ptr->num_text);
}
@@ -973,15 +972,27 @@ png_set_sPLT(png_structp png_ptr,
png_sPLT_tp to = np + info_ptr->splt_palettes_num + i;
png_sPLT_tp from = entries + i;
- to->name = (png_charp)png_malloc(png_ptr,
- png_strlen(from->name) + 1);
+ to->name = (png_charp)png_malloc_warn(png_ptr,
+ png_strlen(from->name) + 1);
+ if (to->name == NULL)
+ {
+ png_warning(png_ptr,
+ "Out of memory while processing sPLT chunk");
+ }
/* TODO: use png_malloc_warn */
- png_strcpy(to->name, from->name);
- to->entries = (png_sPLT_entryp)png_malloc(png_ptr,
+ png_strncpy(to->name, from->name, png_strlen(from->name));
+ to->entries = (png_sPLT_entryp)png_malloc_warn(png_ptr,
from->nentries * png_sizeof(png_sPLT_entry));
/* TODO: use png_malloc_warn */
png_memcpy(to->entries, from->entries,
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;
+ }
to->nentries = from->nentries;
to->depth = from->depth;
}
@@ -1011,7 +1022,8 @@ png_set_unknown_chunks(png_structp png_ptr,
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;
}
@@ -1029,7 +1041,8 @@ png_set_unknown_chunks(png_structp png_ptr,
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.");
+ png_warning(png_ptr,
+ "Out of memory while processing unknown chunk.");
}
else
{
diff --git a/src/libpng/pngtest.c b/src/libpng/pngtest.c
index 299e2947d..866fd8c80 100644
--- a/src/libpng/pngtest.c
+++ b/src/libpng/pngtest.c
@@ -434,8 +434,9 @@ pngtest_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
png_error(png_ptr, "Write Error");
}
}
-
#endif /* USE_FAR_KEYWORD */
+#endif /* PNG_NO_STDIO */
+/* END of code to validate stdio-free compilation */
/* 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
@@ -463,8 +464,6 @@ pngtest_error(png_structp png_ptr, png_const_charp message)
/* We can return because png_error calls the default handler, which is
* actually OK in this case. */
}
-#endif /* PNG_NO_STDIO */
-/* END of code to validate stdio-free compilation */
/* START of code to validate memory allocation and deallocation */
#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
@@ -658,10 +657,8 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
read_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, png_voidp_NULL,
png_error_ptr_NULL, png_error_ptr_NULL);
#endif
-#if defined(PNG_NO_STDIO)
png_set_error_fn(read_ptr, (png_voidp)inname, pngtest_error,
pngtest_warning);
-#endif
#ifdef PNG_WRITE_SUPPORTED
#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
write_ptr = png_create_write_struct_2(PNG_LIBPNG_VER_STRING, png_voidp_NULL,
@@ -671,11 +668,9 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
write_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, png_voidp_NULL,
png_error_ptr_NULL, png_error_ptr_NULL);
#endif
-#if defined(PNG_NO_STDIO)
png_set_error_fn(write_ptr, (png_voidp)inname, pngtest_error,
pngtest_warning);
#endif
-#endif
png_debug(0, "Allocating read_info, write_info and end_info structures\n");
read_info_ptr = png_create_info_struct(read_ptr);
end_info_ptr = png_create_info_struct(read_ptr);
@@ -1007,10 +1002,11 @@ 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_strncpy 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_strncpy(tIME_string,png_convert_to_rfc1123(read_ptr,
+ mod_time),30);
tIME_chunk_present++;
#endif /* PNG_TIME_RFC1123_SUPPORTED */
}
@@ -1147,10 +1143,11 @@ 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_strncpy 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_strncpy(tIME_string,png_convert_to_rfc1123(read_ptr,
+ mod_time),30);
tIME_chunk_present++;
#endif /* PNG_TIME_RFC1123_SUPPORTED */
}
@@ -1551,4 +1548,4 @@ main(int argc, char *argv[])
}
/* Generate a compiler error if there is an old png.h in the search path. */
-typedef version_1_2_18 your_png_h_is_not_version_1_2_18;
+typedef version_1_2_19 your_png_h_is_not_version_1_2_19;
diff --git a/src/libpng/pngtrans.c b/src/libpng/pngtrans.c
index 8cb4b8861..164009502 100644
--- a/src/libpng/pngtrans.c
+++ b/src/libpng/pngtrans.c
@@ -1,9 +1,9 @@
/* pngtrans.c - transforms the data in a row (used by both readers and writers)
*
- * Last changed in libpng 1.2.13 November 13, 2006
+ * Last changed in libpng 1.2.17 May 15, 2007
* For conditions of distribution and use, see copyright notice in png.h
- * Copyright (c) 1998-2006 Glenn Randers-Pehrson
+ * Copyright (c) 1998-2007 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.)
*/
@@ -252,7 +252,7 @@ png_do_swap(png_row_infop row_info, png_bytep row)
#endif
#if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)
-const static PNG_CONST png_byte onebppswaptable[256] = {
+static PNG_CONST png_byte onebppswaptable[256] = {
0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0,
0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8,
@@ -287,7 +287,7 @@ const static PNG_CONST png_byte onebppswaptable[256] = {
0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
};
-const static PNG_CONST png_byte twobppswaptable[256] = {
+static PNG_CONST png_byte twobppswaptable[256] = {
0x00, 0x40, 0x80, 0xC0, 0x10, 0x50, 0x90, 0xD0,
0x20, 0x60, 0xA0, 0xE0, 0x30, 0x70, 0xB0, 0xF0,
0x04, 0x44, 0x84, 0xC4, 0x14, 0x54, 0x94, 0xD4,
@@ -322,7 +322,7 @@ const static PNG_CONST png_byte twobppswaptable[256] = {
0x2F, 0x6F, 0xAF, 0xEF, 0x3F, 0x7F, 0xBF, 0xFF
};
-const static PNG_CONST png_byte fourbppswaptable[256] = {
+static PNG_CONST png_byte fourbppswaptable[256] = {
0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70,
0x80, 0x90, 0xA0, 0xB0, 0xC0, 0xD0, 0xE0, 0xF0,
0x01, 0x11, 0x21, 0x31, 0x41, 0x51, 0x61, 0x71,
diff --git a/src/libpng/pngvcrd.c b/src/libpng/pngvcrd.c
index d1c6405e5..34d42c993 100644
--- a/src/libpng/pngvcrd.c
+++ b/src/libpng/pngvcrd.c
@@ -3,9 +3,9 @@
*
* For Intel x86 CPU and Microsoft Visual C++ compiler
*
- * Last changed in libpng 1.2.6 - August 15, 2004
+ * Last changed in libpng 1.2.19 August 18, 2007
* For conditions of distribution and use, see copyright notice in png.h
- * Copyright (c) 1998-2004 Glenn Randers-Pehrson
+ * Copyright (c) 1998-2007 Glenn Randers-Pehrson
* Copyright (c) 1998, Intel Corporation
*
* Contributed by Nirav Chhatrapati, Intel Corporation, 1998
@@ -22,15 +22,20 @@
*
* [runtime MMX configuration, GRR 20010102]
*
+ * [Copy 6 bytes per pixel, not 4, and use stride of 6, not 4, in the
+ * second loop of interlace processing of 48-bit pixels, GR-P 20070717]
+ *
+ * [move instances of uAll union into local, except for two constant
+ * instances, GR-P 20070805]
*/
#define PNG_INTERNAL
#include "png.h"
-#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) && defined(PNG_USE_PNGVCRD)
+#if defined(PNG_MMX_CODE_SUPPORTED) && defined(PNG_USE_PNGVCRD)
-static int mmx_supported=2;
+static int mmx_supported=2;
int PNGAPI
png_mmx_support(void)
@@ -110,7 +115,7 @@ 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};
+ PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
#endif
png_debug(1,"in png_combine_row_asm\n");
@@ -135,181 +140,23 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask)
{
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:
+ case 24:
{
png_bytep srcptr;
png_bytep dstptr;
png_uint_32 len;
- int m;
- int diff, unmask;
+ int unmask, diff;
- __int64 mask0=0x0102040810204080;
+ __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 !defined(PNG_1_0_X)
if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)
@@ -318,66 +165,87 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask)
if (mmx_supported)
#endif
{
- 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
+ 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
+ punpckldq mm7,mm7 //fill register with 8 masks
movq mm0,mask0
+ movq mm1,mask1
+ movq mm2,mask2
- pand mm0,mm7 //nonzero if keep byte
- pcmpeqb mm0,mm6 //zeros->1s, v versa
+ pand mm0,mm7
+ pand mm1,mm7
+ pand mm2,mm7
- mov ecx,len //load length of line (pixels)
- mov esi,srcptr //load source
- mov ebx,dstptr //load dest
- cmp ecx,0 //lcr
- je mainloop8end
+ pcmpeqb mm0,mm6
+ pcmpeqb mm1,mm6
+ pcmpeqb mm2,mm6
-mainloop8:
+ 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
- pandn mm6,[ebx]
+ movq mm7,[ebx]
+ pandn mm6,mm7
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:
+ 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 end8
+ jz end24
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
+ 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 secondloop8
-end8:
+ jnz secondloop24
+
+end24:
emms
}
}
@@ -405,16 +273,26 @@ end8:
} /* end of else */
break;
- } // end 8 bpp
+ } // end 24 bpp
- case 16:
+ case 32:
{
png_bytep srcptr;
png_bytep dstptr;
png_uint_32 len;
int unmask, diff;
- __int64 mask1=0x0101020204040808,
- mask0=0x1010202040408080;
+
+ __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 !defined(PNG_1_0_X)
if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)
@@ -423,12 +301,6 @@ end8:
if (mmx_supported)
#endif
{
- 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
@@ -439,20 +311,27 @@ end8:
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 mainloop16end
+ jz mainloop32end
-mainloop16:
+mainloop32:
movq mm4,[esi]
pand mm4,mm0
movq mm6,mm0
@@ -469,35 +348,52 @@ mainloop16:
por mm5,mm7
movq [ebx+8],mm5
- add esi,16 //inc by 16 bytes processed
- add ebx,16
+ 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 mainloop16
+ ja mainloop32
-mainloop16end:
+mainloop32end:
mov ecx,diff
cmp ecx,0
- jz end16
+ jz end32
mov edx,mask
sal edx,24 //make low byte the high byte
-secondloop16:
+secondloop32:
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
+ jnc skip32 //if CF = 0
+ mov eax,[esi]
+ mov [ebx],eax
+skip32:
+ add esi,4
+ add ebx,4
dec ecx
- jnz secondloop16
-end16:
+ jnz secondloop32
+
+end32:
emms
}
}
- else /* mmx not supported - use modified C routine */
+ else /* mmx _not supported - Use modified C routine */
{
register unsigned int incr1, initial_val, final_val;
png_size_t pixel_bytes;
@@ -521,25 +417,17 @@ end16:
} /* end of else */
break;
- } // end 16 bpp
+ } // end 32 bpp
- case 24:
+ case 8:
{
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;
+ int m;
+ int diff, unmask;
- unmask = ~mask;
- len = (png_ptr->width)&~7;
- diff = (png_ptr->width)&7;
+ __int64 mask0=0x0102040810204080;
#if !defined(PNG_1_0_X)
if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)
@@ -548,87 +436,66 @@ end16:
if (mmx_supported)
#endif
{
+ 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
+ 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
+ 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
+ pand mm0,mm7 //nonzero if keep byte
+ pcmpeqb mm0,mm6 //zeros->1s, v versa
- mov ecx,len //load length of line
- mov esi,srcptr //load source
- mov ebx,dstptr //load dest
- cmp ecx,0
- jz mainloop24end
+ mov ecx,len //load length of line (pixels)
+ mov esi,srcptr //load source
+ mov ebx,dstptr //load dest
+ cmp ecx,0 //lcr
+ je mainloop8end
-mainloop24:
+mainloop8:
movq mm4,[esi]
pand mm4,mm0
movq mm6,mm0
- movq mm7,[ebx]
- pandn mm6,mm7
+ 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
- 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
+ ja mainloop8
+mainloop8end:
-mainloop24end:
mov ecx,diff
cmp ecx,0
- jz end24
+ jz end8
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
+ sal edx,24 //make low byte the high byte
- dec ecx
- jnz secondloop24
+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
-end24:
+ dec ecx
+ jnz secondloop8
+end8:
emms
}
}
@@ -656,26 +523,182 @@ end24:
} /* end of else */
break;
- } // end 24 bpp
+ } // end 8 bpp
- case 32:
+ 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 16:
{
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;
+ __int64 mask1=0x0101020204040808,
+ mask0=0x1010202040408080;
#if !defined(PNG_1_0_X)
if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)
@@ -684,6 +707,12 @@ end24:
if (mmx_supported)
#endif
{
+ 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
@@ -694,27 +723,20 @@ end24:
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
+ jz mainloop16end
-mainloop32:
+mainloop16:
movq mm4,[esi]
pand mm4,mm0
movq mm6,mm0
@@ -731,52 +753,35 @@ mainloop32:
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
+ add esi,16 //inc by 16 bytes processed
+ add ebx,16
sub ecx,8 //dec by 8 pixels processed
- ja mainloop32
+ ja mainloop16
-mainloop32end:
+mainloop16end:
mov ecx,diff
cmp ecx,0
- jz end32
+ jz end16
mov edx,mask
sal edx,24 //make low byte the high byte
-secondloop32:
+secondloop16:
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
+ jnc skip16 //if CF = 0
+ mov ax,[esi]
+ mov [ebx],ax
+skip16:
+ add esi,2
+ add ebx,2
dec ecx
- jnz secondloop32
-
-end32:
+ jnz secondloop16
+end16:
emms
}
}
- else /* mmx _not supported - Use modified C routine */
+ else /* mmx not supported - use modified C routine */
{
register unsigned int incr1, initial_val, final_val;
png_size_t pixel_bytes;
@@ -800,7 +805,7 @@ end32:
} /* end of else */
break;
- } // end 32 bpp
+ } // end 16 bpp
case 48:
{
@@ -927,9 +932,11 @@ secondloop48:
jnc skip48 //if CF = 0
mov eax,[esi]
mov [ebx],eax
+ mov ax,[esi+4] // These 2 lines added 20070717
+ mov [ebx+4],ax // Glenn R-P
skip48:
- add esi,4
- add ebx,4
+ add esi,6 // Changed 4 to 6 on these 2
+ add ebx,6 // lines. Glenn R-P 20070717
dec ecx
jnz secondloop48
@@ -1005,7 +1012,7 @@ png_do_read_interlace(png_structp png_ptr)
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};
+ PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
#endif
png_debug(1,"in png_do_read_interlace\n");
@@ -1224,70 +1231,7 @@ png_do_read_interlace(png_structp png_ptr)
{
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)) */
+ if (((pass == 4) || (pass == 5)) && width)
{
int width_mmx = ((width >> 1) << 1) - 8;
if (width_mmx < 0)
@@ -1341,13 +1285,76 @@ loop_pass4:
sptr -= 3;
}
}
+ 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 == 0) || (pass == 1))) */
+ {
+ _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
+ }
+ }
} /* end of pixel_bytes == 3 */
else if (pixel_bytes == 1)
{
- if (((pass == 0) || (pass == 1)) && width)
+ if (((pass == 4) || (pass == 5)) && width)
{
- int width_mmx = ((width >> 2) << 2);
+ int width_mmx = ((width >> 3) << 3);
width -= width_mmx;
if (width_mmx)
{
@@ -1356,60 +1363,36 @@ loop_pass4:
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
+ 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*8;
+ dp -= width_mmx*2;
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--;
+ }
+ sptr --;
}
}
else if (((pass == 2) || (pass == 3)) && width)
@@ -1454,9 +1437,9 @@ loop1_pass2:
sptr --;
}
}
- else if (width) /* && ((pass == 4) || (pass == 5))) */
+ else if (width) /* && ((pass == 0) || (pass == 1))) */
{
- int width_mmx = ((width >> 3) << 3);
+ int width_mmx = ((width >> 2) << 2);
width -= width_mmx;
if (width_mmx)
{
@@ -1465,45 +1448,69 @@ loop1_pass2:
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
+ 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*2;
+ 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 --;
+ sptr--;
}
}
} /* end of pixel_bytes == 1 */
else if (pixel_bytes == 2)
{
- if (((pass == 0) || (pass == 1)) && width)
+ if (((pass == 4) || (pass == 5)) && width)
{
- int width_mmx = ((width >> 1) << 1);
+ int width_mmx = ((width >> 1) << 1) ;
width -= width_mmx;
if (width_mmx)
{
@@ -1513,27 +1520,21 @@ loop1_pass4:
mov edi, dp
mov ecx, width_mmx
sub esi, 2
- sub edi, 30
-loop2_pass0:
+ 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
- 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
+ movq [edi], mm0
+ sub edi, 8
sub ecx, 2
- jnz loop2_pass0
+ jnz loop2_pass4
EMMS
}
}
sptr -= (width_mmx*2 - 2); // sign fixed
- dp -= (width_mmx*16 - 2); // sign fixed
+ dp -= (width_mmx*4 - 2); // sign fixed
for (i = width; i; i--)
{
png_byte v[8];
@@ -1592,9 +1593,9 @@ loop2_pass2:
}
}
}
- else if (width) // pass == 4 or 5
+ else if (width) /* && ((pass == 0) || (pass == 1))) */
{
- int width_mmx = ((width >> 1) << 1) ;
+ int width_mmx = ((width >> 1) << 1);
width -= width_mmx;
if (width_mmx)
{
@@ -1604,21 +1605,27 @@ loop2_pass2:
mov edi, dp
mov ecx, width_mmx
sub esi, 2
- sub edi, 6
-loop2_pass4:
+ 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
- sub esi, 4
+ 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 edi, 8
+ movq [edi + 8], mm0
+ movq [edi + 16], mm1
+ movq [edi + 24], mm1
+ sub esi, 4
+ sub edi, 32
sub ecx, 2
- jnz loop2_pass4
+ jnz loop2_pass0
EMMS
}
}
sptr -= (width_mmx*2 - 2); // sign fixed
- dp -= (width_mmx*4 - 2); // sign fixed
+ dp -= (width_mmx*16 - 2); // sign fixed
for (i = width; i; i--)
{
png_byte v[8];
@@ -1636,7 +1643,7 @@ loop2_pass4:
else if (pixel_bytes == 4)
{
- if (((pass == 0) || (pass == 1)) && width)
+ if (((pass == 4) || (pass == 5)) && width)
{
int width_mmx = ((width >> 1) << 1) ;
width -= width_mmx;
@@ -1648,30 +1655,24 @@ loop2_pass4:
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
+ 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
- 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
+ movq [edi + 8], mm1
+ sub edi, 16
sub ecx, 2
- jnz loop4_pass0
+ jnz loop4_pass4
EMMS
}
}
- sptr -= (width_mmx*4 - 4); // sign fixed
- dp -= (width_mmx*32 - 4); // sign fixed
+ sptr -= (width_mmx*4 - 4); // sign fixed
+ dp -= (width_mmx*8 - 4); // sign fixed
for (i = width; i; i--)
{
png_byte v[8];
@@ -1730,7 +1731,7 @@ loop4_pass2:
}
}
}
- else if (width) // pass == 4 or 5
+ else if (width) /* && ((pass == 0) || (pass == 1))) */
{
int width_mmx = ((width >> 1) << 1) ;
width -= width_mmx;
@@ -1742,24 +1743,30 @@ loop4_pass2:
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
+ 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 + 8], mm1
- sub edi, 16
+ movq [edi + 56], mm1
+ sub edi, 64
sub ecx, 2
- jnz loop4_pass4
+ jnz loop4_pass0
EMMS
}
}
- sptr -= (width_mmx*4 - 4); // sign fixed
- dp -= (width_mmx*8 - 4); // sign fixed
+ sptr -= (width_mmx*4 - 4); // sign fixed
+ dp -= (width_mmx*32 - 4); // sign fixed
for (i = width; i; i--)
{
png_byte v[8];
@@ -1913,22 +1920,25 @@ loop4_pass4:
#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;
-
+// These global constants are declared
+// here to ensure alignment on 8-byte boundaries.
+ union uAll {
+ __int64 use;
+ double double_align;
+ long long long_long_align;
+ } ;
+ static PNG_CONST union uAll LBCarryMask = {0x0101010101010101},
+ HBClearMask = {0x7f7f7f7f7f7f7f7f};
// 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)
{
+ // These variables are declared
+ // here to ensure alignment on 8-byte boundaries.
+ union uAll ActiveMask, ShiftBpp, ShiftRem;
+
int bpp;
png_uint_32 FullLength;
png_uint_32 MMXLength;
@@ -2362,6 +2372,10 @@ void /* PRIVATE */
png_read_filter_row_mmx_paeth(png_row_infop row_info, png_bytep row,
png_bytep prev_row)
{
+ // These variables are declared
+ // here to ensure alignment on 8-byte boundaries.
+ union uAll ActiveMask, ActiveMask2, ActiveMaskEnd, ShiftBpp, ShiftRem;
+
png_uint_32 FullLength;
png_uint_32 MMXLength;
//png_uint_32 len;
@@ -3257,6 +3271,10 @@ dpthend:
void /* PRIVATE */
png_read_filter_row_mmx_sub(png_row_infop row_info, png_bytep row)
{
+ // These variables are declared
+ // here to ensure alignment on 8-byte boundaries.
+ union uAll ActiveMask, ShiftBpp, ShiftRem;
+
//int test;
int bpp;
png_uint_32 FullLength;
@@ -3693,32 +3711,32 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep
png_debug(1, "in png_read_filter_row\n");
switch (filter)
{
- case 0: sprintf(filnm, "none");
+ case 0: png_snprintf(filnm, 10, "none");
break;
#if !defined(PNG_1_0_X)
- case 1: sprintf(filnm, "sub-%s",
+ case 1: png_snprintf(filnm, 10, "sub-%s",
(png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_SUB)? "MMX" : "x86");
break;
- case 2: sprintf(filnm, "up-%s",
+ case 2: png_snprintf(filnm, 10, "up-%s",
(png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_UP)? "MMX" : "x86");
break;
- case 3: sprintf(filnm, "avg-%s",
+ case 3: png_snprintf(filnm, 10, "avg-%s",
(png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_AVG)? "MMX" : "x86");
break;
- case 4: sprintf(filnm, "Paeth-%s",
+ case 4: png_snprintf(filnm, 10, "Paeth-%s",
(png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_PAETH)? "MMX":"x86");
break;
#else
- case 1: sprintf(filnm, "sub");
+ case 1: png_snprintf(filnm, 10, "sub");
break;
- case 2: sprintf(filnm, "up");
+ case 2: png_snprintf(filnm, 10, "up");
break;
- case 3: sprintf(filnm, "avg");
+ case 3: png_snprintf(filnm, 10, "avg");
break;
- case 4: sprintf(filnm, "Paeth");
+ case 4: png_snprintf(filnm, 10, "Paeth");
break;
#endif
- default: sprintf(filnm, "unknw");
+ default: png_snprintf(filnm, 10, "unknw");
break;
}
png_debug2(0,"row=%5d, %s, ", png_ptr->row_number, filnm);
@@ -3901,4 +3919,4 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep
}
}
-#endif /* PNG_ASSEMBLER_CODE_SUPPORTED && PNG_USE_PNGVCRD */
+#endif /* PNG_MMX_CODE_SUPPORTED && PNG_USE_PNGVCRD */
diff --git a/src/libpng/pngwio.c b/src/libpng/pngwio.c
index 4d9d57e36..371a4fad6 100644
--- a/src/libpng/pngwio.c
+++ b/src/libpng/pngwio.c
@@ -3,7 +3,7 @@
*
* Last changed in libpng 1.2.13 November 13, 2006
* For conditions of distribution and use, see copyright notice in png.h
- * Copyright (c) 1998-2002 Glenn Randers-Pehrson
+ * Copyright (c) 1998-2006 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.)
*
diff --git a/src/libpng/pngwrite.c b/src/libpng/pngwrite.c
index df7ade334..8d5b98acf 100644
--- a/src/libpng/pngwrite.c
+++ b/src/libpng/pngwrite.c
@@ -391,11 +391,6 @@ 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 */
- png_flush(png_ptr);
-#endif
}
#if defined(PNG_WRITE_tIME_SUPPORTED)
@@ -517,11 +512,13 @@ png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
char msg[80];
if (user_png_ver)
{
- 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);
}
- 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
@@ -587,11 +584,13 @@ png_write_init_2(png_structp png_ptr, png_const_charp user_png_ver,
png_ptr->warning_fn=NULL;
if (user_png_ver)
{
- 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);
}
- 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);
}
@@ -1137,15 +1136,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
@@ -1159,6 +1169,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,
@@ -1213,6 +1224,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;
}
}
@@ -1511,8 +1523,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/src/libpng/pngwutil.c b/src/libpng/pngwutil.c
index 314bea20d..849ee7db5 100644
--- a/src/libpng/pngwutil.c
+++ b/src/libpng/pngwutil.c
@@ -1,7 +1,7 @@
/* pngwutil.c - utilities to write a PNG file
*
- * Last changed in libpng 1.2.15 January 5, 2007
+ * Last changed in libpng 1.2.19 August 18, 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)
@@ -182,7 +182,7 @@ png_text_compress(png_structp png_ptr,
{
#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
char msg[50];
- 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");
@@ -578,7 +578,7 @@ 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_PLTE, num_pal * 3);
#ifndef PNG_NO_POINTER_INDEXING
for (i = 0, pal_ptr = palette; i < num_pal; i++, pal_ptr++)
{
@@ -783,7 +783,7 @@ png_write_iCCP(png_structp png_ptr, png_charp name, int compression_type,
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_write_chunk_start(png_ptr, 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);
@@ -823,7 +823,7 @@ 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_write_chunk_start(png_ptr, 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);
@@ -1180,7 +1180,7 @@ png_write_hIST(png_structp png_ptr, png_uint_16p hist, int num_hist)
return;
}
- png_write_chunk_start(png_ptr, (png_bytep)png_hIST, (png_uint_32)(num_hist * 2));
+ png_write_chunk_start(png_ptr, png_hIST, (png_uint_32)(num_hist * 2));
for (i = 0; i < num_hist; i++)
{
png_save_uint_16(buf, hist[i]);
@@ -1231,12 +1231,14 @@ png_check_keyword(png_structp png_ptr, png_charp key, png_charpp new_key)
/* 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))
{
#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
char msg[40];
- 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");
@@ -1397,8 +1399,6 @@ png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,
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);
@@ -1407,7 +1407,9 @@ png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,
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, 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, (png_size_t)1);
@@ -1527,10 +1529,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, (png_size_t)9);
+ png_write_chunk(png_ptr, 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 */
@@ -1569,7 +1570,7 @@ 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_start(png_ptr, png_pCAL, (png_uint_32)total_len);
png_write_chunk_data(png_ptr, (png_bytep)new_purpose, purpose_len);
png_save_int_32(buf, X0);
png_save_int_32(buf + 4, X1);
@@ -1622,14 +1623,14 @@ png_write_sCAL(png_structp png_ptr, int unit, double width, double height)
total_len += wc_len;
}
#else
- sprintf(buf + 1, "%12.12e", width);
+ png_snprintf(buf + 1, 63, "%12.12e", width);
total_len = 1 + png_strlen(buf + 1) + 1;
- 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);
#endif
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);
+ png_write_chunk(png_ptr, png_sCAL, (png_bytep)buf, total_len);
}
#else
#ifdef PNG_FIXED_POINT_SUPPORTED
@@ -1659,7 +1660,7 @@ png_write_sCAL_s(png_structp png_ptr, int unit, png_charp width,
png_memcpy(buf + wlen + 2, height, hlen); /* do NOT append the '\0' here */
png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len);
- png_write_chunk(png_ptr, (png_bytep)png_sCAL, buf, total_len);
+ png_write_chunk(png_ptr, png_sCAL, buf, total_len);
}
#endif
#endif
@@ -1685,7 +1686,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, (png_size_t)9);
+ png_write_chunk(png_ptr, png_pHYs, buf, (png_size_t)9);
}
#endif
@@ -1717,7 +1718,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, (png_size_t)7);
+ png_write_chunk(png_ptr, png_tIME, buf, (png_size_t)7);
}
#endif
@@ -1751,6 +1752,7 @@ png_write_start_row(png_structp png_ptr)
png_ptr->row_buf = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size);
png_ptr->row_buf[0] = PNG_FILTER_VALUE_NONE;
+#ifndef PNG_NO_WRITE_FILTERING
/* set up filtering buffer, if using this filter */
if (png_ptr->do_filter & PNG_FILTER_SUB)
{
@@ -1768,7 +1770,7 @@ png_write_start_row(png_structp png_ptr)
if (png_ptr->do_filter & PNG_FILTER_UP)
{
- png_ptr->up_row = (png_bytep )png_malloc(png_ptr,
+ png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
(png_ptr->rowbytes + 1));
png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
}
@@ -1782,10 +1784,11 @@ png_write_start_row(png_structp png_ptr)
if (png_ptr->do_filter & PNG_FILTER_PAETH)
{
- png_ptr->paeth_row = (png_bytep )png_malloc(png_ptr,
+ png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
(png_ptr->rowbytes + 1));
png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
}
+#endif /* PNG_NO_WRITE_FILTERING */
}
#ifdef PNG_WRITE_INTERLACING_SUPPORTED
@@ -2121,6 +2124,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
prev_row = png_ptr->prev_row;
best_row = row_buf = png_ptr->row_buf;
+#ifndef PNG_NO_WRITE_FILTER
mins = PNG_MAXSUM;
/* The prediction method we use is to find which method provides the
@@ -2695,7 +2699,7 @@ 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);