Merge jdk8-b08
authorjcoomes
Tue, 04 Oct 2011 12:39:42 -0700
changeset 46451c023bcd0c5a
parent 4644 7b9a0c75f5d9
parent 4642 f38b39ed9ed0
child 4646 f1ec21b81421
Merge
src/share/classes/java/util/XMLUtils.java
src/share/classes/sun/tools/jar/JarImageSource.java
src/share/native/sun/awt/libpng/pnggccrd.c
src/share/native/sun/awt/libpng/pngvcrd.c
     1.1 --- a/make/com/sun/net/httpserver/Makefile	Fri Sep 30 17:20:56 2011 -0700
     1.2 +++ b/make/com/sun/net/httpserver/Makefile	Tue Oct 04 12:39:42 2011 -0700
     1.3 @@ -1,5 +1,5 @@
     1.4  #
     1.5 -# Copyright (c) 2005, 2007, Oracle and/or its affiliates. All rights reserved.
     1.6 +# Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
     1.7  # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.8  #
     1.9  # This code is free software; you can redistribute it and/or modify it
    1.10 @@ -26,6 +26,8 @@
    1.11  BUILDDIR = ../../../..
    1.12  PACKAGE = com.sun.net.httpserver
    1.13  PRODUCT = sun
    1.14 +JAVAC_MAX_WARNINGS = true
    1.15 +JAVAC_WARNINGS_FATAL = true
    1.16  include $(BUILDDIR)/common/Defs.gmk
    1.17  
    1.18  #
     2.1 --- a/make/com/sun/net/ssl/Makefile	Fri Sep 30 17:20:56 2011 -0700
     2.2 +++ b/make/com/sun/net/ssl/Makefile	Tue Oct 04 12:39:42 2011 -0700
     2.3 @@ -26,6 +26,9 @@
     2.4  BUILDDIR = ../../../..
     2.5  PACKAGE = com.sun.net.ssl
     2.6  PRODUCT = sun
     2.7 +JAVAC_LINT_OPTIONS=-Xlint:all,-deprecation
     2.8 +JAVAC_MAX_WARNINGS = true
     2.9 +JAVAC_WARNINGS_FATAL = true
    2.10  include $(BUILDDIR)/common/Defs.gmk
    2.11  
    2.12  #
     3.1 --- a/make/common/Defs-linux.gmk	Fri Sep 30 17:20:56 2011 -0700
     3.2 +++ b/make/common/Defs-linux.gmk	Tue Oct 04 12:39:42 2011 -0700
     3.3 @@ -74,6 +74,57 @@
     3.4  CC_OBJECT_OUTPUT_FLAG = -o #trailing blank required!
     3.5  CC_PROGRAM_OUTPUT_FLAG = -o #trailing blank required!
     3.6  
     3.7 +# Default OBJCOPY comes from GNU Binutils on Linux:
     3.8 +DEF_OBJCOPY=/usr/bin/objcopy
     3.9 +ifdef CROSS_COMPILE_ARCH
    3.10 +  # don't try to generate .debuginfo files when cross compiling
    3.11 +  _JUNK_ := $(shell \
    3.12 +    echo >&2 "INFO: cross compiling for ARCH $(CROSS_COMPILE_ARCH)," \
    3.13 +      "skipping .debuginfo generation.")
    3.14 +  OBJCOPY=
    3.15 +else
    3.16 +  OBJCOPY=$(shell test -x $(DEF_OBJCOPY) && echo $(DEF_OBJCOPY))
    3.17 +  ifneq ($(ALT_OBJCOPY),)
    3.18 +    _JUNK_ := $(shell echo >&2 "INFO: ALT_OBJCOPY=$(ALT_OBJCOPY)")
    3.19 +    # disable .debuginfo support by setting ALT_OBJCOPY to a non-existent path
    3.20 +    OBJCOPY=$(shell test -x $(ALT_OBJCOPY) && echo $(ALT_OBJCOPY))
    3.21 +  endif
    3.22 +endif
    3.23 +
    3.24 +ifdef LIBRARY_SUPPORTS_FULL_DEBUG_SYMBOLS
    3.25 +# The setting of OBJCOPY above enables the JDK build to import
    3.26 +# .debuginfo files from the HotSpot build. However, adding FDS
    3.27 +# support to the JDK build will occur in phases so a different
    3.28 +# make variable is used to indicate that a particular library
    3.29 +# supports FDS.
    3.30 +
    3.31 +ifeq ($(OBJCOPY),)
    3.32 +  _JUNK_ := $(shell \
    3.33 +    echo >&2 "INFO: no objcopy cmd found so cannot create .debuginfo files.")
    3.34 +else
    3.35 +  _JUNK_ := $(shell \
    3.36 +    echo >&2 "INFO: $(OBJCOPY) cmd found so will create .debuginfo files.")
    3.37 +
    3.38 +  # Library stripping policies for .debuginfo configs:
    3.39 +  #   all_strip - strips everything from the library
    3.40 +  #   min_strip - strips most stuff from the library; leaves minimum symbols
    3.41 +  #   no_strip  - does not strip the library at all
    3.42 +  #
    3.43 +  # Oracle security policy requires "all_strip". A waiver was granted on
    3.44 +  # 2011.09.01 that permits using "min_strip" in the Java JDK and Java JRE.
    3.45 +  #
    3.46 +  DEF_STRIP_POLICY="min_strip"
    3.47 +  ifeq ($(ALT_STRIP_POLICY),)
    3.48 +    STRIP_POLICY=$(DEF_STRIP_POLICY)
    3.49 +  else
    3.50 +    STRIP_POLICY=$(ALT_STRIP_POLICY)
    3.51 +  endif
    3.52 +
    3.53 +  _JUNK_ := $(shell \
    3.54 +    echo >&2 "INFO: STRIP_POLICY=$(STRIP_POLICY)")
    3.55 +endif
    3.56 +endif
    3.57 +
    3.58  #
    3.59  # Default optimization
    3.60  #
    3.61 @@ -359,6 +410,7 @@
    3.62  # Settings for the JDI - Serviceability Agent binding.
    3.63  HOTSPOT_SALIB_PATH   = $(HOTSPOT_IMPORT_PATH)/jre/lib/$(LIBARCH)
    3.64  SALIB_NAME = $(LIB_PREFIX)saproc.$(LIBRARY_SUFFIX)
    3.65 +SA_DEBUGINFO_NAME = $(LIB_PREFIX)saproc.debuginfo
    3.66  
    3.67  # The JDI - Serviceability Agent binding is not currently supported
    3.68  # on Linux-ia64.
     4.1 --- a/make/common/Defs-solaris.gmk	Fri Sep 30 17:20:56 2011 -0700
     4.2 +++ b/make/common/Defs-solaris.gmk	Tue Oct 04 12:39:42 2011 -0700
     4.3 @@ -74,6 +74,69 @@
     4.4  CC_OBJECT_OUTPUT_FLAG = -o #trailing blank required!
     4.5  CC_PROGRAM_OUTPUT_FLAG = -o #trailing blank required!
     4.6  
     4.7 +ifdef ENABLE_FULL_DEBUG_SYMBOLS
     4.8 +# Only check for Full Debug Symbols support on Solaris if it is
     4.9 +# specifically enabled. Hopefully, it can be enabled by default
    4.10 +# once the .debuginfo size issues are worked out.
    4.11 +
    4.12 +# Default OBJCOPY comes from the SUNWbinutils package:
    4.13 +DEF_OBJCOPY=/usr/sfw/bin/gobjcopy
    4.14 +ifeq ($(PLATFORM)-$(LIBARCH), solaris-amd64)
    4.15 +  # On Solaris AMD64/X64, gobjcopy is not happy and fails:
    4.16 +  #
    4.17 +  # usr/sfw/bin/gobjcopy --add-gnu-debuglink=<lib>.debuginfo <lib>.so
    4.18 +  # BFD: stKPaiop: Not enough room for program headers, try linking with -N
    4.19 +  # /usr/sfw/bin/gobjcopy: stKPaiop: Bad value
    4.20 +  # BFD: stKPaiop: Not enough room for program headers, try linking with -N
    4.21 +  # /usr/sfw/bin/gobjcopy: libsaproc.debuginfo: Bad value
    4.22 +  # BFD: stKPaiop: Not enough room for program headers, try linking with -N
    4.23 +  # /usr/sfw/bin/gobjcopy: stKPaiop: Bad value
    4.24 +  _JUNK_ := $(shell \
    4.25 +    echo >&2 "INFO: $(DEF_OBJCOPY) is not working on Solaris AMD64/X64")
    4.26 +  OBJCOPY=
    4.27 +else
    4.28 +  OBJCOPY=$(shell test -x $(DEF_OBJCOPY) && echo $(DEF_OBJCOPY))
    4.29 +  ifneq ($(ALT_OBJCOPY),)
    4.30 +    _JUNK_ := $(shell echo >&2 "INFO: ALT_OBJCOPY=$(ALT_OBJCOPY)")
    4.31 +    # disable .debuginfo support by setting ALT_OBJCOPY to a non-existent path
    4.32 +    OBJCOPY=$(shell test -x $(ALT_OBJCOPY) && echo $(ALT_OBJCOPY))
    4.33 +  endif
    4.34 +endif
    4.35 +
    4.36 +ifdef LIBRARY_SUPPORTS_FULL_DEBUG_SYMBOLS
    4.37 +# The setting of OBJCOPY above enables the JDK build to import
    4.38 +# .debuginfo files from the HotSpot build. However, adding FDS
    4.39 +# support to the JDK build will occur in phases so a different
    4.40 +# make variable is used to indicate that a particular library
    4.41 +# supports FDS.
    4.42 +
    4.43 +ifeq ($(OBJCOPY),)
    4.44 +  _JUNK_ := $(shell \
    4.45 +    echo >&2 "INFO: no objcopy cmd found so cannot create .debuginfo files.")
    4.46 +else
    4.47 +  _JUNK_ := $(shell \
    4.48 +    echo >&2 "INFO: $(OBJCOPY) cmd found so will create .debuginfo files.")
    4.49 +
    4.50 +  # Library stripping policies for .debuginfo configs:
    4.51 +  #   all_strip - strips everything from the library
    4.52 +  #   min_strip - strips most stuff from the library; leaves minimum symbols
    4.53 +  #   no_strip  - does not strip the library at all
    4.54 +  #
    4.55 +  # Oracle security policy requires "all_strip". A waiver was granted on
    4.56 +  # 2011.09.01 that permits using "min_strip" in the Java JDK and Java JRE.
    4.57 +  #
    4.58 +  DEF_STRIP_POLICY="min_strip"
    4.59 +  ifeq ($(ALT_STRIP_POLICY),)
    4.60 +    STRIP_POLICY=$(DEF_STRIP_POLICY)
    4.61 +  else
    4.62 +    STRIP_POLICY=$(ALT_STRIP_POLICY)
    4.63 +  endif
    4.64 +  _JUNK_ := $(shell \
    4.65 +    echo >&2 "INFO: STRIP_POLICY=$(STRIP_POLICY)")
    4.66 +endif
    4.67 +endif
    4.68 +endif
    4.69 +
    4.70  #
    4.71  # Java default optimization (-x04/-O2) etc.  Applies to the VM.
    4.72  #
    4.73 @@ -684,5 +747,6 @@
    4.74  # Settings for the JDI - Serviceability Agent binding.
    4.75  HOTSPOT_SALIB_PATH   = $(HOTSPOT_IMPORT_PATH)/jre/lib/$(LIBARCH)
    4.76  SALIB_NAME = $(LIB_PREFIX)saproc.$(LIBRARY_SUFFIX)
    4.77 +SA_DEBUGINFO_NAME = $(LIB_PREFIX)saproc.debuginfo
    4.78  INCLUDE_SA=true
    4.79  
     5.1 --- a/make/java/java/FILES_java.gmk	Fri Sep 30 17:20:56 2011 -0700
     5.2 +++ b/make/java/java/FILES_java.gmk	Tue Oct 04 12:39:42 2011 -0700
     5.3 @@ -208,7 +208,6 @@
     5.4      java/util/Observable.java \
     5.5      java/util/Observer.java \
     5.6      java/util/Properties.java \
     5.7 -        java/util/XMLUtils.java \
     5.8          java/util/InvalidPropertiesFormatException.java \
     5.9      java/util/PropertyPermission.java \
    5.10      java/util/PropertyResourceBundle.java \
     6.1 --- a/make/java/net/Makefile	Fri Sep 30 17:20:56 2011 -0700
     6.2 +++ b/make/java/net/Makefile	Tue Oct 04 12:39:42 2011 -0700
     6.3 @@ -27,6 +27,9 @@
     6.4  PACKAGE = java.net
     6.5  LIBRARY = net
     6.6  PRODUCT = sun
     6.7 +JAVAC_MAX_WARNINGS = true
     6.8 +JAVAC_WARNINGS_FATAL = true
     6.9 +JAVAC_LINT_OPTIONS = -Xlint:all,-deprecation
    6.10  include $(BUILDDIR)/common/Defs.gmk
    6.11  
    6.12  #
     7.1 --- a/make/java/nio/Makefile	Fri Sep 30 17:20:56 2011 -0700
     7.2 +++ b/make/java/nio/Makefile	Tue Oct 04 12:39:42 2011 -0700
     7.3 @@ -206,7 +206,6 @@
     7.4  	sun/nio/fs/LinuxUserDefinedFileAttributeView.java \
     7.5  	sun/nio/fs/LinuxNativeDispatcher.java \
     7.6  	sun/nio/fs/LinuxWatchService.java \
     7.7 -	sun/nio/fs/PollingWatchService.java \
     7.8  	sun/nio/fs/UnixChannelFactory.java \
     7.9  	sun/nio/fs/UnixCopyFile.java \
    7.10  	sun/nio/fs/UnixDirectoryStream.java \
     8.1 --- a/make/java/redist/Makefile	Fri Sep 30 17:20:56 2011 -0700
     8.2 +++ b/make/java/redist/Makefile	Tue Oct 04 12:39:42 2011 -0700
     8.3 @@ -58,6 +58,11 @@
     8.4  JVMDB_NAME             = $(LIB_PREFIX)jvm$(DB_SUFFIX).$(LIBRARY_SUFFIX)
     8.5  JVMDTRACE_NAME         = $(LIB_PREFIX)jvm$(DTRACE_SUFFIX).$(LIBRARY_SUFFIX)
     8.6  
     8.7 +JVM_DEBUGINFO_NAME       = $(LIB_PREFIX)jvm.debuginfo
     8.8 +LIBJSIG_DEBUGINFO_NAME   = $(LIB_PREFIX)jsig.debuginfo
     8.9 +JVMDB_DEBUGINFO_NAME     = $(LIB_PREFIX)jvm$(DB_SUFFIX).debuginfo
    8.10 +JVMDTRACE_DEBUGINFO_NAME = $(LIB_PREFIX)jvm$(DTRACE_SUFFIX).debuginfo
    8.11 +
    8.12  CLASSSHARINGDATA_DIR   = $(BUILDDIR)/tools/sharing
    8.13  
    8.14  # Needed to do file copy
    8.15 @@ -79,6 +84,12 @@
    8.16  ifndef BUILD_CLIENT_ONLY
    8.17    IMPORT_LIST = $(LIB_LOCATION)/$(SERVER_LOCATION)/$(JVM_NAME) \
    8.18                  $(LIB_LOCATION)/$(SERVER_LOCATION)/Xusage.txt
    8.19 +  ifneq ($(OBJCOPY),)
    8.20 +    # the import JDK may not contain .debuginfo files
    8.21 +    ifneq ($(wildcard $(HOTSPOT_SERVER_PATH)/$(JVM_DEBUGINFO_NAME)),)
    8.22 +      IMPORT_LIST += $(LIB_LOCATION)/$(SERVER_LOCATION)/$(JVM_DEBUGINFO_NAME)
    8.23 +    endif
    8.24 +  endif
    8.25  else
    8.26    IMPORT_LIST =
    8.27  endif
    8.28 @@ -88,6 +99,12 @@
    8.29  ifeq ($(ARCH_DATA_MODEL), 32)
    8.30    IMPORT_LIST += $(LIB_LOCATION)/$(CLIENT_LOCATION)/$(JVM_NAME) \
    8.31                   $(LIB_LOCATION)/$(CLIENT_LOCATION)/Xusage.txt
    8.32 +  ifneq ($(OBJCOPY),)
    8.33 +    # the import JDK may not contain .debuginfo files
    8.34 +    ifneq ($(wildcard $(HOTSPOT_CLIENT_PATH)/$(JVM_DEBUGINFO_NAME)),)
    8.35 +      IMPORT_LIST += $(LIB_LOCATION)/$(CLIENT_LOCATION)/$(JVM_DEBUGINFO_NAME)
    8.36 +    endif
    8.37 +  endif
    8.38  endif
    8.39  endif
    8.40  
    8.41 @@ -157,16 +174,40 @@
    8.42  #  NOT Windows vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv  NOT Windows
    8.43  
    8.44  IMPORT_LIST += $(LIB_LOCATION)/$(LIBJSIG_NAME) 
    8.45 +ifneq ($(OBJCOPY),)
    8.46 +  # the import JDK may not contain .debuginfo files
    8.47 +  ifneq ($(wildcard $(HOTSPOT_IMPORT_PATH)/$(ARCH_VM_SUBDIR)/$(LIBJSIG_DEBUGINFO_NAME)),)
    8.48 +    IMPORT_LIST += $(LIB_LOCATION)/$(LIBJSIG_DEBUGINFO_NAME)
    8.49 +  endif
    8.50 +endif
    8.51  ifndef BUILD_CLIENT_ONLY
    8.52    IMPORT_LIST += $(LIB_LOCATION)/$(SERVER_LOCATION)/$(LIBJSIG_NAME)
    8.53 +  ifneq ($(OBJCOPY),)
    8.54 +    # the import JDK may not contain the target of the symlink
    8.55 +    ifneq ($(wildcard $(HOTSPOT_IMPORT_PATH)/$(ARCH_VM_SUBDIR)/$(LIBJSIG_DEBUGINFO_NAME)),)
    8.56 +      IMPORT_LIST += $(LIB_LOCATION)/$(SERVER_LOCATION)/$(LIBJSIG_DEBUGINFO_NAME)
    8.57 +    endif
    8.58 +  endif
    8.59  endif
    8.60  
    8.61  ifeq ($(PLATFORM), solaris)
    8.62    ifndef BUILD_CLIENT_ONLY
    8.63      IMPORT_LIST += $(LIB_LOCATION)/$(SERVER_LOCATION)/$(JVMDB_NAME)
    8.64 +    ifneq ($(OBJCOPY),)
    8.65 +      # the import JDK may not contain .debuginfo files
    8.66 +      ifneq ($(wildcard $(HOTSPOT_SERVER_PATH)/$(JVMDB_DEBUGINFO_NAME)),)
    8.67 +        IMPORT_LIST += $(LIB_LOCATION)/$(SERVER_LOCATION)/$(JVMDB_DEBUGINFO_NAME)
    8.68 +      endif
    8.69 +    endif
    8.70      # The conditional can be removed when import JDKs contain these files.
    8.71      ifneq ($(wildcard $(HOTSPOT_SERVER_PATH)/$(JVMDTRACE_NAME)),)
    8.72        IMPORT_LIST += $(LIB_LOCATION)/$(SERVER_LOCATION)/$(JVMDTRACE_NAME)
    8.73 +      ifneq ($(OBJCOPY),)
    8.74 +        # the import JDK may not contain .debuginfo files
    8.75 +        ifneq ($(wildcard $(HOTSPOT_SERVER_PATH)/$(JVMDTRACE_DEBUGINFO_NAME)),)
    8.76 +          IMPORT_LIST += $(LIB_LOCATION)/$(SERVER_LOCATION)/$(JVMDTRACE_DEBUGINFO_NAME)
    8.77 +        endif
    8.78 +      endif
    8.79      else
    8.80        $(warning WARNING: $(HOTSPOT_SERVER_PATH)/$(JVMDB_NAME) not found!)
    8.81      endif 
    8.82 @@ -177,17 +218,37 @@
    8.83  ifeq ($(ARCH_DATA_MODEL), 32)
    8.84  
    8.85  IMPORT_LIST += $(LIB_LOCATION)/$(CLIENT_LOCATION)/$(LIBJSIG_NAME)
    8.86 +ifneq ($(OBJCOPY),)
    8.87 +  # the import JDK may not contain the target of the symlink
    8.88 +  ifneq ($(wildcard $(HOTSPOT_IMPORT_PATH)/$(ARCH_VM_SUBDIR)/$(LIBJSIG_DEBUGINFO_NAME)),)
    8.89 +    IMPORT_LIST += $(LIB_LOCATION)/$(CLIENT_LOCATION)/$(LIBJSIG_DEBUGINFO_NAME)
    8.90 +  endif
    8.91 +endif
    8.92  
    8.93  ifeq ($(PLATFORM), solaris)
    8.94  #  solaris   vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv  solaris
    8.95  
    8.96  IMPORT_LIST += $(LIB_LOCATION)/$(CLIENT_LOCATION)/$(JVMDB_NAME)
    8.97 +ifneq ($(OBJCOPY),)
    8.98 +  # the import JDK may not contain .debuginfo files
    8.99 +  ifneq ($(wildcard $(HOTSPOT_CLIENT_PATH)/$(JVMDB_DEBUGINFO_NAME)),)
   8.100 +    IMPORT_LIST += $(LIB_LOCATION)/$(CLIENT_LOCATION)/$(JVMDB_DEBUGINFO_NAME)
   8.101 +  endif
   8.102 +endif
   8.103  
   8.104  # The conditional can be removed when import JDKs contain these files.
   8.105  ifneq ($(wildcard $(HOTSPOT_CLIENT_PATH)/$(JVMDTRACE_NAME)),)
   8.106    IMPORT_LIST += $(LIB_LOCATION)/$(CLIENT_LOCATION)/$(JVMDTRACE_NAME)
   8.107    IMPORT_LIST += $(LIB_LOCATION)/$(CLIENT_LOCATION)/64/$(JVMDB_NAME)
   8.108    IMPORT_LIST += $(LIB_LOCATION)/$(CLIENT_LOCATION)/64/$(JVMDTRACE_NAME)
   8.109 +  ifneq ($(OBJCOPY),)
   8.110 +    # the import JDK may not contain .debuginfo files
   8.111 +    ifneq ($(wildcard $(HOTSPOT_CLIENT_PATH)/$(JVMDTRACE_DEBUGINFO_NAME)),)
   8.112 +      IMPORT_LIST += $(LIB_LOCATION)/$(CLIENT_LOCATION)/$(JVMDTRACE_DEBUGINFO_NAME)
   8.113 +      IMPORT_LIST += $(LIB_LOCATION)/$(CLIENT_LOCATION)/64/$(JVMDB_DEBUGINFO_NAME)
   8.114 +      IMPORT_LIST += $(LIB_LOCATION)/$(CLIENT_LOCATION)/64/$(JVMDTRACE_DEBUGINFO_NAME)
   8.115 +  endif
   8.116 +  endif
   8.117  else
   8.118    $(warning WARNING: $(HOTSPOT_CLIENT_PATH)/$(JVMDTRACE_NAME) not found!)
   8.119  endif
   8.120 @@ -196,6 +257,12 @@
   8.121    # The conditional can be removed when import JDKs contain these files.
   8.122    ifneq ($(wildcard $(HOTSPOT_SERVER_PATH)/64/$(JVMDB_NAME)),)
   8.123      IMPORT_LIST += $(LIB_LOCATION)/$(SERVER_LOCATION)/64/$(JVMDB_NAME)
   8.124 +    ifneq ($(OBJCOPY),)
   8.125 +      # the import JDK may not contain .debuginfo files
   8.126 +      ifneq ($(wildcard $(HOTSPOT_SERVER_PATH)/64/$(JVMDB_DEBUGINFO_NAME)),)
   8.127 +        IMPORT_LIST += $(LIB_LOCATION)/$(SERVER_LOCATION)/64/$(JVMDB_DEBUGINFO_NAME)
   8.128 +      endif
   8.129 +    endif
   8.130    else
   8.131      $(warning WARNING: $(HOTSPOT_SERVER_PATH)/64/$(JVMDB_NAME) not found!)
   8.132    endif
   8.133 @@ -203,6 +270,12 @@
   8.134    # The conditional can be removed when import JDKs contain these files.
   8.135    ifneq ($(wildcard $(HOTSPOT_SERVER_PATH)/64/$(JVMDTRACE_NAME)),)
   8.136      IMPORT_LIST += $(LIB_LOCATION)/$(SERVER_LOCATION)/64/$(JVMDTRACE_NAME)
   8.137 +    ifneq ($(OBJCOPY),)
   8.138 +      # the import JDK may not contain .debuginfo files
   8.139 +      ifneq ($(wildcard $(HOTSPOT_SERVER_PATH)/64/$(JVMDTRACE_DEBUGINFO_NAME)),)
   8.140 +        IMPORT_LIST += $(LIB_LOCATION)/$(SERVER_LOCATION)/64/$(JVMDTRACE_DEBUGINFO_NAME)
   8.141 +      endif
   8.142 +    endif
   8.143    else
   8.144      $(warning WARNING: $(HOTSPOT_SERVER_PATH)/64/$(JVMDTRACE_NAME) not found!)
   8.145   endif
   8.146 @@ -229,6 +302,11 @@
   8.147  	$(install-import-file)
   8.148  	@$(call binary_file_verification,$@)
   8.149  
   8.150 +ifneq ($(OBJCOPY),)
   8.151 +$(LIB_LOCATION)/$(CLIENT_LOCATION)/$(JVM_DEBUGINFO_NAME): $(HOTSPOT_CLIENT_PATH)/$(JVM_DEBUGINFO_NAME)
   8.152 +	$(install-import-file)
   8.153 +endif
   8.154 +
   8.155  $(LIB_LOCATION)/$(KERNEL_LOCATION)/$(JVM_NAME): $(HOTSPOT_KERNEL_PATH)/$(JVM_NAME)
   8.156  	$(install-file)
   8.157  	@$(call binary_file_verification,$@)
   8.158 @@ -237,15 +315,33 @@
   8.159  	$(install-import-file)
   8.160  	@$(call binary_file_verification,$@)
   8.161  
   8.162 +ifneq ($(OBJCOPY),)
   8.163 +$(LIB_LOCATION)/$(LIBJSIG_DEBUGINFO_NAME): $(HOTSPOT_IMPORT_PATH)/$(ARCH_VM_SUBDIR)/$(LIBJSIG_DEBUGINFO_NAME)
   8.164 +	$(install-import-file)
   8.165 +endif
   8.166 +
   8.167  ifndef BUILD_CLIENT_ONLY
   8.168  $(LIB_LOCATION)/$(CLIENT_LOCATION)/$(LIBJSIG_NAME) \
   8.169  $(LIB_LOCATION)/$(SERVER_LOCATION)/$(LIBJSIG_NAME):
   8.170  	@$(prep-target)
   8.171  	$(call install-sym-link, ../$(LIBJSIG_NAME))
   8.172 +
   8.173 +ifneq ($(OBJCOPY),)
   8.174 +$(LIB_LOCATION)/$(CLIENT_LOCATION)/$(LIBJSIG_DEBUGINFO_NAME) \
   8.175 +$(LIB_LOCATION)/$(SERVER_LOCATION)/$(LIBJSIG_DEBUGINFO_NAME):
   8.176 +	@$(prep-target)
   8.177 +	$(call install-sym-link, ../$(LIBJSIG_DEBUGINFO_NAME))
   8.178 +endif
   8.179  else
   8.180  $(LIB_LOCATION)/$(CLIENT_LOCATION)/$(LIBJSIG_NAME):
   8.181  	@$(prep-target)
   8.182  	$(call install-sym-link, ../$(LIBJSIG_NAME))
   8.183 +
   8.184 +ifneq ($(OBJCOPY),)
   8.185 +$(LIB_LOCATION)/$(CLIENT_LOCATION)/$(LIBJSIG_DEBUGINFO_NAME):
   8.186 +	@$(prep-target)
   8.187 +	$(call install-sym-link, ../$(LIBJSIG_DEBUGINFO_NAME))
   8.188 +endif
   8.189  endif
   8.190  
   8.191  $(LIB_LOCATION)/$(CLIENT_LOCATION)/$(JVMDB_NAME): $(HOTSPOT_CLIENT_PATH)/$(JVMDB_NAME)
   8.192 @@ -256,6 +352,14 @@
   8.193  	$(install-import-file)
   8.194  	@$(call binary_file_verification,$@)
   8.195  
   8.196 +ifneq ($(OBJCOPY),)
   8.197 +$(LIB_LOCATION)/$(CLIENT_LOCATION)/$(JVMDB_DEBUGINFO_NAME): $(HOTSPOT_CLIENT_PATH)/$(JVMDB_DEBUGINFO_NAME)
   8.198 +	$(install-import-file)
   8.199 +
   8.200 +$(LIB_LOCATION)/$(CLIENT_LOCATION)/64/$(JVMDB_DEBUGINFO_NAME): $(HOTSPOT_CLIENT_PATH)/64/$(JVMDB_DEBUGINFO_NAME)
   8.201 +	$(install-import-file)
   8.202 +endif
   8.203 +
   8.204  ifndef BUILD_CLIENT_ONLY
   8.205  $(LIB_LOCATION)/$(SERVER_LOCATION)/$(JVMDB_NAME): $(HOTSPOT_SERVER_PATH)/$(JVMDB_NAME)
   8.206  	$(install-import-file)
   8.207 @@ -264,6 +368,14 @@
   8.208  $(LIB_LOCATION)/$(SERVER_LOCATION)/64/$(JVMDB_NAME): $(HOTSPOT_SERVER_PATH)/64/$(JVMDB_NAME)
   8.209  	$(install-import-file)
   8.210  	@$(call binary_file_verification,$@)
   8.211 +
   8.212 +ifneq ($(OBJCOPY),)
   8.213 +$(LIB_LOCATION)/$(SERVER_LOCATION)/$(JVMDB_DEBUGINFO_NAME): $(HOTSPOT_SERVER_PATH)/$(JVMDB_DEBUGINFO_NAME)
   8.214 +	$(install-import-file)
   8.215 +
   8.216 +$(LIB_LOCATION)/$(SERVER_LOCATION)/64/$(JVMDB_DEBUGINFO_NAME): $(HOTSPOT_SERVER_PATH)/64/$(JVMDB_DEBUGINFO_NAME)
   8.217 +	$(install-import-file)
   8.218 +endif
   8.219  endif
   8.220  
   8.221  $(LIB_LOCATION)/$(CLIENT_LOCATION)/$(JVMDTRACE_NAME): $(HOTSPOT_CLIENT_PATH)/$(JVMDTRACE_NAME)
   8.222 @@ -274,6 +386,14 @@
   8.223  	$(install-import-file)
   8.224  	@$(call binary_file_verification,$@)
   8.225  
   8.226 +ifneq ($(OBJCOPY),)
   8.227 +$(LIB_LOCATION)/$(CLIENT_LOCATION)/$(JVMDTRACE_DEBUGINFO_NAME): $(HOTSPOT_CLIENT_PATH)/$(JVMDTRACE_DEBUGINFO_NAME)
   8.228 +	$(install-import-file)
   8.229 +
   8.230 +$(LIB_LOCATION)/$(CLIENT_LOCATION)/64/$(JVMDTRACE_DEBUGINFO_NAME): $(HOTSPOT_CLIENT_PATH)/64/$(JVMDTRACE_DEBUGINFO_NAME)
   8.231 +	$(install-import-file)
   8.232 +endif
   8.233 +
   8.234  ifndef BUILD_CLIENT_ONLY
   8.235  $(LIB_LOCATION)/$(SERVER_LOCATION)/$(JVMDTRACE_NAME): $(HOTSPOT_SERVER_PATH)/$(JVMDTRACE_NAME)
   8.236  	$(install-import-file)
   8.237 @@ -287,6 +407,17 @@
   8.238  	$(install-import-file)
   8.239  	@$(call binary_file_verification,$@)
   8.240  
   8.241 +ifneq ($(OBJCOPY),)
   8.242 +$(LIB_LOCATION)/$(SERVER_LOCATION)/$(JVMDTRACE_DEBUGINFO_NAME): $(HOTSPOT_SERVER_PATH)/$(JVMDTRACE_DEBUGINFO_NAME)
   8.243 +	$(install-import-file)
   8.244 +
   8.245 +$(LIB_LOCATION)/$(SERVER_LOCATION)/64/$(JVMDTRACE_DEBUGINFO_NAME): $(HOTSPOT_SERVER_PATH)/64/$(JVMDTRACE_DEBUGINFO_NAME)
   8.246 +	$(install-import-file)
   8.247 +
   8.248 +$(LIB_LOCATION)/$(SERVER_LOCATION)/$(JVM_DEBUGINFO_NAME): $(HOTSPOT_SERVER_PATH)/$(JVM_DEBUGINFO_NAME)
   8.249 +	$(install-import-file)
   8.250 +endif
   8.251 +
   8.252  $(LIB_LOCATION)/$(SERVER_LOCATION)/Xusage.txt : $(HOTSPOT_SERVER_PATH)/Xusage.txt
   8.253  	$(install-import-file)
   8.254  endif
     9.1 --- a/make/java/redist/sajdi/Makefile	Fri Sep 30 17:20:56 2011 -0700
     9.2 +++ b/make/java/redist/sajdi/Makefile	Tue Oct 04 12:39:42 2011 -0700
     9.3 @@ -56,6 +56,12 @@
     9.4      IMPORT_LIST += $(LIB_LOCATION)/$(SAMAP_NAME) \
     9.5                     $(LIB_LOCATION)/$(SAPDB_NAME)
     9.6    endif
     9.7 +  ifneq ($(OBJCOPY),)
     9.8 +    # the import JDK may not contain .debuginfo files
     9.9 +    ifneq ($(wildcard $(HOTSPOT_IMPORT_PATH)/$(ARCH_VM_SUBDIR)/$(SA_DEBUGINFO_NAME)),)
    9.10 +      IMPORT_LIST += $(LIB_LOCATION)/$(SA_DEBUGINFO_NAME)
    9.11 +    endif
    9.12 +  endif
    9.13  endif # INCLUDE_SA
    9.14  
    9.15  
    9.16 @@ -79,6 +85,11 @@
    9.17  $(LIB_LOCATION)/$(SAMAP_NAME): $(HOTSPOT_SALIB_PATH)/$(SAMAP_NAME)
    9.18  	$(install-import-file)
    9.19  endif # windows
    9.20 +
    9.21 +  ifneq ($(OBJCOPY),)
    9.22 +$(LIB_LOCATION)/$(SA_DEBUGINFO_NAME): $(HOTSPOT_SALIB_PATH)/$(SA_DEBUGINFO_NAME)
    9.23 +	$(install-import-file)
    9.24 +  endif
    9.25  endif # INCLUDE_SA
    9.26  
    9.27  all: $(IMPORT_LIST)
    10.1 --- a/make/javax/Makefile	Fri Sep 30 17:20:56 2011 -0700
    10.2 +++ b/make/javax/Makefile	Tue Oct 04 12:39:42 2011 -0700
    10.3 @@ -1,5 +1,5 @@
    10.4  #
    10.5 -# Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
    10.6 +# Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
    10.7  # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    10.8  #
    10.9  # This code is free software; you can redistribute it and/or modify it
    11.1 --- a/make/javax/others/Makefile	Fri Sep 30 17:20:56 2011 -0700
    11.2 +++ b/make/javax/others/Makefile	Tue Oct 04 12:39:42 2011 -0700
    11.3 @@ -28,7 +28,6 @@
    11.4  #
    11.5  
    11.6  BUILDDIR = ../..
    11.7 -JAVAC_MAX_WARNINGS = true
    11.8  include $(BUILDDIR)/common/Defs.gmk
    11.9  
   11.10  #
    12.1 --- a/make/netbeans/README	Fri Sep 30 17:20:56 2011 -0700
    12.2 +++ b/make/netbeans/README	Tue Oct 04 12:39:42 2011 -0700
    12.3 @@ -5,7 +5,7 @@
    12.4  
    12.5  Getting Started
    12.6      In addition to the source bundle for Open JDK, you'll need to download
    12.7 -    and install copies of the JDK and of NetBeans 6. And if you want to run
    12.8 +    and install copies of the JDK and of NetBeans. And if you want to run
    12.9      tests on the JDK (you do want to run tests, right?), you'll need to
   12.10      install the jtreg test harness.
   12.11  
   12.12 @@ -20,30 +20,28 @@
   12.13  
   12.14      Downloading the JDK
   12.15          You've probably done this a million times. Download and install it
   12.16 -        from http://java.sun.com/javase
   12.17 +        from http://www.oracle.com/technetwork/java/javase/overview/index.html
   12.18  
   12.19      Downloading the OpenJDK sources
   12.20          Since you're reading this, d you've already downloaded the OpenJDK
   12.21          source bundle.  Later in this document we'll refer to the location
   12.22          where you installed the Open JDK sources as *install-dir*.
   12.23  
   12.24 -    Downloading a pre-built, JDK 7
   12.25 +    Downloading a pre-built, JDK 8
   12.26          This will be necessary to do builds of some of the projects.  In
   12.27          general, you want to download and install a pre-built JDK that
   12.28          corresponds to the OpenJDK sources you download.  Building the entire
   12.29          OpenJDK depends on a few parts of the pre-built JDK.  Get this from
   12.30 -        http://download.java.net/jdk7/binaries
   12.31 +        http://download.java.net/jdk8/binaries
   12.32  
   12.33 -        Note: For working on certain projects, like JMX and JConsole, you 
   12.34 -              may find convenient to use a pre-built version of JDK 7 (or 
   12.35 +        Note: For working on certain projects, like JMX and JConsole, you
   12.36 +              may find convenient to use a pre-built version of JDK 8 (or
   12.37                OpenJDK) rather than building your own. This will allow you
   12.38                to build only that part of the OpenJDK sources which correspond
   12.39 -              to that project. 
   12.40 +              to that project.
   12.41  
   12.42 -    NetBeans 6
   12.43 -        Yep, NetBeans *6*. Nope, not FCS'd yet. We're on the edge here,
   12.44 -        enjoy it! Get the latest working development build of NetBeans 6
   12.45 -        from http://netbeans.org
   12.46 +    NetBeans 7.0 or later
   12.47 +        Older versions may also work but are unsupported.
   12.48  
   12.49      jtreg
   12.50          "jtreg" is the test harness for running OpenJDK's regression tests.
   12.51 @@ -51,7 +49,7 @@
   12.52  
   12.53      Ant
   12.54         NetBeans comes with ant, but if you use a separately-installed copy
   12.55 -       please make sure that it is at least version 1.7.0.
   12.56 +       please make sure that it is at least version 1.8.1.
   12.57  
   12.58  Configuring
   12.59      Building OpenJDK is hard and complex. No, strike that. While it's not
   12.60 @@ -92,8 +90,8 @@
   12.61          situation:
   12.62  
   12.63          make.options=\
   12.64 -            ALT_BOOTDIR=/home/me/bin/jdk1.6.0 \
   12.65 -            ALT_JDK_IMPORT_PATH=/home/me/bin/jdk1.7.0 \
   12.66 +            ALT_BOOTDIR=/home/me/bin/jdk1.7.0 \
   12.67 +            ALT_JDK_IMPORT_PATH=/home/me/bin/jdk1.8.0 \
   12.68              OPENJDK=true
   12.69  
   12.70          The trailing '\' are important, so that make gets the above as a
   12.71 @@ -107,7 +105,7 @@
   12.72    Windows-specific configuration
   12.73      First, please note that the entire JDK cannot currently be built on
   12.74      Windows platforms.  This will likely limit your ability to build
   12.75 -    make-based projects.  See 
   12.76 +    make-based projects.  See
   12.77           *install-dir*/jdk/make/README-builds.html
   12.78      for full information on issues with building on the Windows platform.
   12.79  
   12.80 @@ -141,7 +139,7 @@
   12.81      editor.
   12.82  
   12.83    Locale Requirements
   12.84 -    To build the Open JDK sources, be certain that you are using the "C"
   12.85 +    To build the OpenJDK sources, be certain that you are using the "C"
   12.86      locale on Unix (R) platforms, or "English (United States)" locale on
   12.87      Windows.
   12.88  
   12.89 @@ -220,13 +218,13 @@
   12.90          running and debugging JConsole.
   12.91  
   12.92          This ant-based project does *not* require that you build the jdk
   12.93 -        project first, provided that you use a pre-built version of JDK 7. 
   12.94 +        project first, provided that you use a pre-built version of JDK 7.
   12.95  
   12.96      Java (TM) Management Extensions (JMX(TM)) API (directory "jmx")
   12.97          For working on JMX source code. Creates ../dist/lib/jmx.jar.
   12.98  
   12.99          This ant-based project does *not* require that you build the jdk
  12.100 -        project first, provided that you use a pre-built version of JDK 7. 
  12.101 +        project first, provided that you use a pre-built version of JDK 7.
  12.102  
  12.103      Jar & Zip (directory "jarzip")
  12.104          For working on jar & zip. It builds the zip library (including
  12.105 @@ -242,12 +240,12 @@
  12.106          running and debugging the SampleTree demo.
  12.107  
  12.108          This ant-based project does *not* require that you build the jdk
  12.109 -        project first, provided that you use a pre-built version of JDK 7. 
  12.110 +        project first, provided that you use a pre-built version of JDK 7.
  12.111  
  12.112      In addition, there are projects for building the compiler, javadoc,
  12.113      and related tools, in the OpenJDK langtools component.  These
  12.114      projects are separate from those described here, and have their
  12.115 -    own set of guidelines and conventions. For more details, see the 
  12.116 +    own set of guidelines and conventions. For more details, see the
  12.117      README files in make/netbeans in the OpenJDK langtools component.
  12.118  
  12.119  Running Tests
  12.120 @@ -603,13 +601,6 @@
  12.121      * -clean-make
  12.122  
  12.123  Known Issues
  12.124 -  Tests won't run: waiting for lock
  12.125 -    Occasionally when running tests, there will be a delay, followed by a
  12.126 -    message like this:
  12.127 -        Waiting to lock test result cache for
  12.128 -           /tmp/jdk/build/linux-i586/jtreg/jconsole/JTwork for 20 seconds
  12.129 -    The workaround is to stop the tests, rm -rf the offending jtreg/<project>
  12.130 -    directory by hand, and re-run the tests.
  12.131  
  12.132    Can't run nor debug a single test in the JConsole test
  12.133      In most projects, you can run a single test by opening it in the editor,
    13.1 --- a/make/netbeans/common/closed-share-view.ent	Fri Sep 30 17:20:56 2011 -0700
    13.2 +++ b/make/netbeans/common/closed-share-view.ent	Tue Oct 04 12:39:42 2011 -0700
    13.3 @@ -31,8 +31,8 @@
    13.4   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    13.5  -->
    13.6  
    13.7 -<source-folder style="packages">
    13.8 -    <label>Closed-Source Packages</label>
    13.9 +<source-folder style="tree">
   13.10 +    <label>Closed Sources</label>
   13.11      <location>${root}/src/closed/share/classes</location>
   13.12      <includes>${includes}</includes>
   13.13      <excludes>${excludes}</excludes>
    14.1 --- a/make/netbeans/common/java-data-native.ent	Fri Sep 30 17:20:56 2011 -0700
    14.2 +++ b/make/netbeans/common/java-data-native.ent	Tue Oct 04 12:39:42 2011 -0700
    14.3 @@ -38,7 +38,12 @@
    14.4          <package-root>${root}/src/solaris/classes</package-root>
    14.5          <classpath mode="boot">${bootstrap.jdk}/jre/lib/rt.jar</classpath>
    14.6          <built-to>${root}/build/${platform}-${arch}/classes</built-to>
    14.7 -        <javadoc-built-to>${root}/build/javadoc/${name}</javadoc-built-to>
    14.8 +        <javadoc-built-to>${root}/build/${platform}-${arch}/docs/api</javadoc-built-to>
    14.9 +        <source-level>1.7</source-level>
   14.10 +    </compilation-unit>
   14.11 +    <compilation-unit>
   14.12 +        <package-root>${root}/test</package-root>
   14.13 +        <unit-tests/>
   14.14          <source-level>1.7</source-level>
   14.15      </compilation-unit>
   14.16  </java-data>
    15.1 --- a/make/netbeans/common/java-data-no-native.ent	Fri Sep 30 17:20:56 2011 -0700
    15.2 +++ b/make/netbeans/common/java-data-no-native.ent	Tue Oct 04 12:39:42 2011 -0700
    15.3 @@ -36,7 +36,12 @@
    15.4          <package-root>${root}/src/share/classes</package-root>
    15.5          <classpath mode="boot">${bootstrap.jdk}/jre/lib/rt.jar</classpath>
    15.6          <built-to>${root}/build/${platform}-${arch}/classes</built-to>
    15.7 -        <javadoc-built-to>${root}/build/javadoc/${name}</javadoc-built-to>
    15.8 +        <javadoc-built-to>${root}/build/${platform}-${arch}/docs/api</javadoc-built-to>
    15.9 +        <source-level>1.7</source-level>
   15.10 +    </compilation-unit>
   15.11 +    <compilation-unit>
   15.12 +        <package-root>${root}/test</package-root>
   15.13 +        <unit-tests/>
   15.14          <source-level>1.7</source-level>
   15.15      </compilation-unit>
   15.16  </java-data>
    16.1 --- a/make/netbeans/common/jtreg-view.ent	Fri Sep 30 17:20:56 2011 -0700
    16.2 +++ b/make/netbeans/common/jtreg-view.ent	Tue Oct 04 12:39:42 2011 -0700
    16.3 @@ -31,7 +31,7 @@
    16.4   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    16.5  -->
    16.6  
    16.7 -<source-folder style="packages">
    16.8 +<source-folder style="tree">
    16.9      <label>Tests</label>
   16.10      <location>${root}/test</location>
   16.11      <includes>${jtreg.tests}</includes>
    17.1 --- a/make/netbeans/common/sample-view.ent	Fri Sep 30 17:20:56 2011 -0700
    17.2 +++ b/make/netbeans/common/sample-view.ent	Tue Oct 04 12:39:42 2011 -0700
    17.3 @@ -31,7 +31,7 @@
    17.4   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    17.5  -->
    17.6  
    17.7 -<source-folder style="packages">
    17.8 +<source-folder style="tree">
    17.9      <label>Samples</label>
   17.10      <location>${root}/src/share/sample</location>
   17.11      <includes>${samples}</includes>
    18.1 --- a/make/netbeans/common/share-view.ent	Fri Sep 30 17:20:56 2011 -0700
    18.2 +++ b/make/netbeans/common/share-view.ent	Tue Oct 04 12:39:42 2011 -0700
    18.3 @@ -31,7 +31,7 @@
    18.4   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    18.5  -->
    18.6  
    18.7 -<source-folder style="packages">
    18.8 +<source-folder style="tree">
    18.9      <label>Sources for All Platforms</label>
   18.10      <location>${root}/src/share/classes</location>
   18.11      <includes>${includes}</includes>
    19.1 --- a/make/netbeans/common/unix-view.ent	Fri Sep 30 17:20:56 2011 -0700
    19.2 +++ b/make/netbeans/common/unix-view.ent	Tue Oct 04 12:39:42 2011 -0700
    19.3 @@ -35,7 +35,7 @@
    19.4    UNIX is a registered trademark in the United States and other countries,
    19.5    exclusively licensed through X/Open Company, Ltd.
    19.6  -->
    19.7 -<source-folder style="packages">
    19.8 +<source-folder style="tree">
    19.9      <label>Sources for Unix® Platform</label>
   19.10      <location>${root}/src/solaris/classes</location>
   19.11      <includes>${includes}</includes>
    20.1 --- a/make/netbeans/common/windows-view.ent	Fri Sep 30 17:20:56 2011 -0700
    20.2 +++ b/make/netbeans/common/windows-view.ent	Tue Oct 04 12:39:42 2011 -0700
    20.3 @@ -31,7 +31,7 @@
    20.4   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    20.5  -->
    20.6  
    20.7 -<source-folder style="packages">
    20.8 +<source-folder style="tree">
    20.9      <label>Sources for Windows Platform</label>
   20.10      <location>${root}/src/windows/classes</location>
   20.11      <includes>${includes}</includes>
    21.1 --- a/make/netbeans/j2se/nbproject/project.xml	Fri Sep 30 17:20:56 2011 -0700
    21.2 +++ b/make/netbeans/j2se/nbproject/project.xml	Tue Oct 04 12:39:42 2011 -0700
    21.3 @@ -1,7 +1,7 @@
    21.4  <?xml version="1.0" encoding="UTF-8"?>
    21.5  
    21.6  <!--
    21.7 - Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
    21.8 + Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
    21.9  
   21.10   Redistribution and use in source and binary forms, with or without
   21.11   modification, are permitted provided that the following conditions
   21.12 @@ -36,11 +36,13 @@
   21.13      <!ENTITY share-sources SYSTEM "../../common/share-sources.ent">
   21.14      <!ENTITY unix-sources SYSTEM "../../common/unix-sources.ent">
   21.15      <!ENTITY windows-sources SYSTEM "../../common/windows-sources.ent">
   21.16 +    <!ENTITY jtreg-sources SYSTEM "../../common/jtreg-sources.ent">
   21.17      <!ENTITY build-folder SYSTEM "../../common/build-folder.ent">
   21.18      <!ENTITY standard-bindings SYSTEM "../../common/standard-bindings.ent">
   21.19      <!ENTITY share-view SYSTEM "../../common/share-view.ent">
   21.20      <!ENTITY unix-view SYSTEM "../../common/unix-view.ent">
   21.21      <!ENTITY windows-view SYSTEM "../../common/windows-view.ent">
   21.22 +    <!ENTITY jtreg-view SYSTEM "../../common/jtreg-view.ent">
   21.23      <!ENTITY file-view SYSTEM "../../common/file-view.ent">
   21.24      <!ENTITY standard-actions SYSTEM "../../common/standard-actions.ent">
   21.25      <!ENTITY java-data-native SYSTEM "../../common/java-data-native.ent">
   21.26 @@ -59,6 +61,7 @@
   21.27                  &unix-sources;
   21.28                  &windows-sources;
   21.29                  &build-folder;
   21.30 +		&jtreg-sources;
   21.31              </folders>
   21.32              <ide-actions>
   21.33                  <action name="build">
   21.34 @@ -82,6 +85,7 @@
   21.35                      &share-view;
   21.36                      &unix-view;
   21.37                      &windows-view;
   21.38 +                    &jtreg-view;
   21.39                      &file-view;
   21.40                  </items>
   21.41                  <context-menu>
    22.1 --- a/make/sun/Makefile	Fri Sep 30 17:20:56 2011 -0700
    22.2 +++ b/make/sun/Makefile	Tue Oct 04 12:39:42 2011 -0700
    22.3 @@ -68,7 +68,7 @@
    22.4  endif
    22.5  
    22.6  # nio need to be compiled before awt to have all charsets ready
    22.7 -SUBDIRS            = jar security javazic misc net nio text launcher
    22.8 +SUBDIRS            = jar security javazic misc net nio text util launcher
    22.9  
   22.10  ifdef BUILD_HEADLESS_ONLY
   22.11    DISPLAY_LIBS = awt $(HEADLESS_SUBDIR)
    23.1 --- a/make/sun/javazic/tzdata/VERSION	Fri Sep 30 17:20:56 2011 -0700
    23.2 +++ b/make/sun/javazic/tzdata/VERSION	Tue Oct 04 12:39:42 2011 -0700
    23.3 @@ -21,4 +21,4 @@
    23.4  # or visit www.oracle.com if you need additional information or have any
    23.5  # questions.
    23.6  #
    23.7 -tzdata2011g
    23.8 +tzdata2011j
    24.1 --- a/make/sun/javazic/tzdata/africa	Fri Sep 30 17:20:56 2011 -0700
    24.2 +++ b/make/sun/javazic/tzdata/africa	Tue Oct 04 12:39:42 2011 -0700
    24.3 @@ -80,7 +80,7 @@
    24.4  # I invented the following abbreviations; corrections are welcome!
    24.5  #	 2:00	WAST	West Africa Summer Time
    24.6  #	 2:30	BEAT	British East Africa Time (no longer used)
    24.7 -#	 2:44:45 BEAUT	British East Africa Unified Time (no longer used)
    24.8 +#	 2:45	BEAUT	British East Africa Unified Time (no longer used)
    24.9  #	 3:00	CAST	Central Africa Summer Time (no longer used)
   24.10  #	 3:00	SAST	South Africa Summer Time (no longer used)
   24.11  #	 3:00	EAT	East Africa Time
   24.12 @@ -418,7 +418,7 @@
   24.13  Zone	Africa/Nairobi	2:27:16	-	LMT	1928 Jul
   24.14  			3:00	-	EAT	1930
   24.15  			2:30	-	BEAT	1940
   24.16 -			2:44:45	-	BEAUT	1960
   24.17 +			2:45	-	BEAUT	1960
   24.18  			3:00	-	EAT
   24.19  
   24.20  # Lesotho
   24.21 @@ -979,6 +979,11 @@
   24.22  			2:00	Sudan	CA%sT	2000 Jan 15 12:00
   24.23  			3:00	-	EAT
   24.24  
   24.25 +# South Sudan
   24.26 +Zone	Africa/Juba	2:06:24 -	LMT	1931
   24.27 +			2:00	Sudan	CA%sT	2000 Jan 15 12:00
   24.28 +			3:00	-	EAT
   24.29 +
   24.30  # Swaziland
   24.31  # Zone	NAME		GMTOFF	RULES	FORMAT	[UNTIL]
   24.32  Zone	Africa/Mbabane	2:04:24 -	LMT	1903 Mar
   24.33 @@ -988,7 +993,7 @@
   24.34  # Zone	NAME		GMTOFF	RULES	FORMAT	[UNTIL]
   24.35  Zone Africa/Dar_es_Salaam 2:37:08 -	LMT	1931
   24.36  			3:00	-	EAT	1948
   24.37 -			2:44:45	-	BEAUT	1961
   24.38 +			2:45	-	BEAUT	1961
   24.39  			3:00	-	EAT
   24.40  
   24.41  # Togo
   24.42 @@ -1114,7 +1119,7 @@
   24.43  Zone	Africa/Kampala	2:09:40 -	LMT	1928 Jul
   24.44  			3:00	-	EAT	1930
   24.45  			2:30	-	BEAT	1948
   24.46 -			2:44:45	-	BEAUT	1957
   24.47 +			2:45	-	BEAUT	1957
   24.48  			3:00	-	EAT
   24.49  
   24.50  # Zambia
    25.1 --- a/make/sun/javazic/tzdata/antarctica	Fri Sep 30 17:20:56 2011 -0700
    25.2 +++ b/make/sun/javazic/tzdata/antarctica	Tue Oct 04 12:39:42 2011 -0700
    25.3 @@ -41,18 +41,6 @@
    25.4  # I made up all time zone abbreviations mentioned here; corrections welcome!
    25.5  # FORMAT is `zzz' and GMTOFF is 0 for locations while uninhabited.
    25.6  
    25.7 -# These rules are stolen from the `europe' file.
    25.8 -# Rule	NAME	FROM	TO	TYPE	IN	ON	AT	SAVE	LETTER/S
    25.9 -Rule	RussAQ	1981	1984	-	Apr	 1	 0:00	1:00	S
   25.10 -Rule	RussAQ	1981	1983	-	Oct	 1	 0:00	0	-
   25.11 -Rule	RussAQ	1984	1991	-	Sep	lastSun	 2:00s	0	-
   25.12 -Rule	RussAQ	1985	1991	-	Mar	lastSun	 2:00s	1:00	S
   25.13 -Rule	RussAQ	1992	only	-	Mar	lastSat	 23:00	1:00	S
   25.14 -Rule	RussAQ	1992	only	-	Sep	lastSat	 23:00	0	-
   25.15 -Rule	RussAQ	1993	max	-	Mar	lastSun	 2:00s	1:00	S
   25.16 -Rule	RussAQ	1993	1995	-	Sep	lastSun	 2:00s	0	-
   25.17 -Rule	RussAQ	1996	max	-	Oct	lastSun	 2:00s	0	-
   25.18 -
   25.19  # These rules are stolen from the `southamerica' file.
   25.20  # Rule	NAME	FROM	TO	TYPE	IN	ON	AT	SAVE	LETTER/S
   25.21  Rule	ArgAQ	1964	1966	-	Mar	 1	0:00	0	-
    26.1 --- a/make/sun/javazic/tzdata/asia	Fri Sep 30 17:20:56 2011 -0700
    26.2 +++ b/make/sun/javazic/tzdata/asia	Tue Oct 04 12:39:42 2011 -0700
    26.3 @@ -99,6 +99,10 @@
    26.4  Rule RussiaAsia	1993	1995	-	Sep	lastSun	 2:00s	0	-
    26.5  Rule RussiaAsia	1996	max	-	Oct	lastSun	 2:00s	0	-
    26.6  
    26.7 +# From Arthur David Olson (2011-06-15):
    26.8 +# While Russia abandoned DST in 2011, Armenia may choose to
    26.9 +# follow Russia's "old" rules.
   26.10 +
   26.11  # Afghanistan
   26.12  # Zone	NAME		GMTOFF	RULES	FORMAT	[UNTIL]
   26.13  Zone	Asia/Kabul	4:36:48 -	LMT	1890
    27.1 --- a/make/sun/javazic/tzdata/australasia	Fri Sep 30 17:20:56 2011 -0700
    27.2 +++ b/make/sun/javazic/tzdata/australasia	Tue Oct 04 12:39:42 2011 -0700
    27.3 @@ -521,7 +521,7 @@
    27.4  # http://www.parliament.gov.ws/documents/acts/Daylight%20Saving%20Act%20%202009%20%28English%29%20-%20Final%207-7-091.pdf
    27.5  # </a>
    27.6  
    27.7 -# From Raymond Hughes (2010-10-07):
    27.8 +# From Laupue Raymond Hughes (2010-10-07):
    27.9  # Please see
   27.10  # <a href="http://www.mcil.gov.ws">
   27.11  # http://www.mcil.gov.ws
   27.12 @@ -531,7 +531,7 @@
   27.13  # to 01:00am and First Sunday April 2011 (03/04/11) - adjust clocks
   27.14  # backwards from 1:00am to 12:00am"
   27.15  
   27.16 -# From Raymond Hughes (2011-03-07)
   27.17 +# From Laupue Raymond Hughes (2011-03-07):
   27.18  # I believe this will be posted shortly on the website
   27.19  # <a href="http://www.mcil.gov.ws">
   27.20  # www.mcil.gov.ws
   27.21 @@ -551,12 +551,74 @@
   27.22  # Margaret Fruean ACTING CHIEF EXECUTIVE OFFICER MINISTRY OF COMMERCE,
   27.23  # INDUSTRY AND LABOUR 28th February 2011
   27.24  
   27.25 +# From David Zuelke (2011-05-09):
   27.26 +# Subject: Samoa to move timezone from east to west of international date line
   27.27 +# 
   27.28 +# <a href="http://www.morningstar.co.uk/uk/markets/newsfeeditem.aspx?id=138501958347963">
   27.29 +# http://www.morningstar.co.uk/uk/markets/newsfeeditem.aspx?id=138501958347963
   27.30 +# </a>
   27.31 +
   27.32 +# From Mark Sim-Smith (2011-08-17):
   27.33 +# I have been in contact with Leilani Tuala Warren from the Samoa Law
   27.34 +# Reform Commission, and she has sent me a copy of the Bill that she
   27.35 +# confirmed has been passed...Most of the sections are about maps rather
   27.36 +# than the time zone change, but I'll paste the relevant bits below. But
   27.37 +# the essence is that at midnight 29 Dec (UTC-11 I suppose), Samoa
   27.38 +# changes from UTC-11 to UTC+13:
   27.39 +#
   27.40 +# International Date Line Bill 2011
   27.41 +#
   27.42 +# AN ACT to provide for the change to standard time in Samoa and to make
   27.43 +# consequential amendments to the position of the International Date
   27.44 +# Line, and for related purposes.
   27.45 +#
   27.46 +# BE IT ENACTED by the Legislative Assembly of Samoa in Parliament
   27.47 +# assembled as follows:
   27.48 +#
   27.49 +# 1. Short title and commencement-(1) This Act may be cited as the
   27.50 +# International Date Line Act 2011. (2) Except for section 5(3) this Act
   27.51 +# commences at 12 o'clock midnight, on Thursday 29th December 2011. (3)
   27.52 +# Section 5(3) commences on the date of assent by the Head of State.
   27.53 +#
   27.54 +# [snip]
   27.55 +#
   27.56 +# 3. Interpretation - [snip] "Samoa standard time" in this Act and any
   27.57 +# other statute of Samoa which refers to 'Samoa standard time' means the
   27.58 +# time 13 hours in advance of Co-ordinated Universal Time.
   27.59 +#
   27.60 +# 4. Samoa standard time - (1) Upon the commencement of this Act, Samoa
   27.61 +# standard time shall be set at 13 hours in advance of Co-ordinated
   27.62 +# Universal Time for the whole of Samoa. (2) All references to Samoa's
   27.63 +# time zone and to Samoa standard time in Samoa in all legislation and
   27.64 +# instruments after the commencement of this Act shall be references to
   27.65 +# Samoa standard time as provided for in this Act. (3) Nothing in this
   27.66 +# Act affects the provisions of the Daylight Saving Act 2009, except that
   27.67 +# it defines Samoa standard time....
   27.68 +
   27.69 +# From Laupue Raymond Hughes (2011-09-02):
   27.70 +# <a href="http://www.mcil.gov.ws/mcil_publications.html">
   27.71 +# http://www.mcil.gov.ws/mcil_publications.html
   27.72 +# </a>
   27.73 +#
   27.74 +# here is the official website publication for Samoa DST and dateline change
   27.75 +#
   27.76 +# DST
   27.77 +# Year	End	Time	Start	Time
   27.78 +# 2011	- - -	- - -	24 September	3:00am to 4:00am
   27.79 +# 2012	01 April	4:00am to 3:00am	- - -	- - -
   27.80 +#
   27.81 +# Dateline Change skip Friday 30th Dec 2011
   27.82 +# Thursday 29th December 2011	23:59:59 Hours
   27.83 +# Saturday 31st December 2011	00:00:00 Hours
   27.84  Zone Pacific/Apia	 12:33:04 -	LMT	1879 Jul  5
   27.85  			-11:26:56 -	LMT	1911
   27.86  			-11:30	-	SAMT	1950		# Samoa Time
   27.87  			-11:00	-	WST	2010 Sep 26
   27.88  			-11:00	1:00	WSDT	2011 Apr 2 4:00
   27.89 -			-11:00	-	WST
   27.90 +			-11:00	-	WST	2011 Sep 24 3:00
   27.91 +			-11:00	1:00	WSDT	2011 Dec 30
   27.92 +			 13:00	1:00	WSDT	2012 Apr 1 4:00
   27.93 +			 13:00	-	WST
   27.94  
   27.95  # Solomon Is
   27.96  # excludes Bougainville, for which see Papua New Guinea
   27.97 @@ -1228,7 +1290,7 @@
   27.98  # Lord Howe Island Board (controlling authority for the Island) is
   27.99  # seeking the community's views on various options for summer time
  27.100  # arrangements on the Island, e.g. advance clocks by 1 full hour
  27.101 -# instead of only 30 minutes.  Dependant on the wishes of residents
  27.102 +# instead of only 30 minutes.  [Dependent] on the wishes of residents
  27.103  # the Board may approach the NSW government to change the existing
  27.104  # arrangements.  The starting date for summer time on the Island will
  27.105  # however always coincide with the rest of NSW.
  27.106 @@ -1354,7 +1416,7 @@
  27.107  
  27.108  # From Paul Eggert (1996-01-22):
  27.109  # Today's _Wall Street Journal_ (page 1) reports that Kiribati
  27.110 -# ``declared it the same day throught the country as of Jan. 1, 1995''
  27.111 +# ``declared it the same day [throughout] the country as of Jan. 1, 1995''
  27.112  # as part of the competition to be first into the 21st century.
  27.113  
  27.114  
    28.1 --- a/make/sun/javazic/tzdata/europe	Fri Sep 30 17:20:56 2011 -0700
    28.2 +++ b/make/sun/javazic/tzdata/europe	Tue Oct 04 12:39:42 2011 -0700
    28.3 @@ -587,6 +587,26 @@
    28.4  Rule	Russia	1993	1995	-	Sep	lastSun	 2:00s	0	-
    28.5  Rule	Russia	1996	max	-	Oct	lastSun	 2:00s	0	-
    28.6  
    28.7 +# From Alexander Krivenyshev (2011-06-14):
    28.8 +# According to Kremlin press service, Russian President Dmitry Medvedev
    28.9 +# signed a federal law "On calculation of time" on June 9, 2011.
   28.10 +# According to the law Russia is abolishing daylight saving time.
   28.11 +# 
   28.12 +# Medvedev signed a law "On the Calculation of Time" (in russian): 
   28.13 +# <a href="http://bmockbe.ru/events/?ID=7583">
   28.14 +# http://bmockbe.ru/events/?ID=7583
   28.15 +# </a>
   28.16 +# 
   28.17 +# Medvedev signed a law on the calculation of the time (in russian):
   28.18 +# <a href="http://www.regnum.ru/news/polit/1413906.html">
   28.19 +# http://www.regnum.ru/news/polit/1413906.html
   28.20 +# </a>
   28.21 +
   28.22 +# From Arthur David Olson (2011-06-15):
   28.23 +# Take "abolishing daylight saving time" to mean that time is now considered
   28.24 +# to be standard.
   28.25 +# At least for now, keep the "old" Russia rules for the benefit of Belarus.
   28.26 +
   28.27  # These are for backward compatibility with older versions.
   28.28  
   28.29  # Zone	NAME		GMTOFF	RULES	FORMAT	[UNTIL]
   28.30 @@ -2035,7 +2055,8 @@
   28.31  			 1:00	C-Eur	CE%sT	1945
   28.32  			 2:00	Poland	CE%sT	1946
   28.33  			 3:00	Russia	MSK/MSD	1991 Mar 31 2:00s
   28.34 -			 2:00	Russia	EE%sT
   28.35 +			 2:00	Russia	EE%sT	2011 Mar 27 2:00s
   28.36 +			 3:00	-	KALT
   28.37  #
   28.38  # From Oscar van Vlijmen (2001-08-25): [This region consists of]
   28.39  # Respublika Adygeya, Arkhangel'skaya oblast',
   28.40 @@ -2064,7 +2085,8 @@
   28.41  			 2:00	-	EET	1930 Jun 21
   28.42  			 3:00	Russia	MSK/MSD	1991 Mar 31 2:00s
   28.43  			 2:00	Russia	EE%sT	1992 Jan 19 2:00s
   28.44 -			 3:00	Russia	MSK/MSD
   28.45 +			 3:00	Russia	MSK/MSD	2011 Mar 27 2:00s
   28.46 +			 4:00	-	MSK
   28.47  #
   28.48  # Astrakhanskaya oblast', Kirovskaya oblast', Saratovskaya oblast',
   28.49  # Volgogradskaya oblast'.  Shanks & Pottenger say Kirov is still at +0400
   28.50 @@ -2077,7 +2099,8 @@
   28.51  			 4:00	Russia	VOL%sT	1989 Mar 26 2:00s # Volgograd T
   28.52  			 3:00	Russia	VOL%sT	1991 Mar 31 2:00s
   28.53  			 4:00	-	VOLT	1992 Mar 29 2:00s
   28.54 -			 3:00	Russia	VOL%sT
   28.55 +			 3:00	Russia	VOL%sT	2011 Mar 27 2:00s
   28.56 +			 4:00	-	VOLT
   28.57  #
   28.58  # From Oscar van Vlijmen (2001-08-25): [This region consists of]
   28.59  # Samarskaya oblast', Udmyrtskaya respublika
   28.60 @@ -2089,7 +2112,8 @@
   28.61  			 2:00	Russia	KUY%sT	1991 Sep 29 2:00s
   28.62  			 3:00	-	KUYT	1991 Oct 20 3:00
   28.63  			 4:00	Russia	SAM%sT	2010 Mar 28 2:00s # Samara Time
   28.64 -			 3:00	Russia	SAM%sT
   28.65 +			 3:00	Russia	SAM%sT	2011 Mar 27 2:00s
   28.66 +			 4:00	-	SAMT
   28.67  
   28.68  #
   28.69  # From Oscar van Vlijmen (2001-08-25): [This region consists of]
   28.70 @@ -2102,7 +2126,8 @@
   28.71  			 4:00	-	SVET	1930 Jun 21 # Sverdlovsk Time
   28.72  			 5:00	Russia	SVE%sT	1991 Mar 31 2:00s
   28.73  			 4:00	Russia	SVE%sT	1992 Jan 19 2:00s
   28.74 -			 5:00	Russia	YEK%sT	# Yekaterinburg Time
   28.75 +			 5:00	Russia	YEK%sT	2011 Mar 27 2:00s
   28.76 +			 6:00	-	YEKT	# Yekaterinburg Time
   28.77  #
   28.78  # From Oscar van Vlijmen (2001-08-25): [This region consists of]
   28.79  # Respublika Altaj, Altajskij kraj, Omskaya oblast'.
   28.80 @@ -2110,7 +2135,8 @@
   28.81  			 5:00	-	OMST	1930 Jun 21 # Omsk TIme
   28.82  			 6:00	Russia	OMS%sT	1991 Mar 31 2:00s
   28.83  			 5:00	Russia	OMS%sT	1992 Jan 19 2:00s
   28.84 -			 6:00	Russia	OMS%sT
   28.85 +			 6:00	Russia	OMS%sT	2011 Mar 27 2:00s
   28.86 +			 7:00	-	OMST
   28.87  #
   28.88  # From Paul Eggert (2006-08-19): I'm guessing about Tomsk here; it's
   28.89  # not clear when it switched from +7 to +6.
   28.90 @@ -2120,7 +2146,8 @@
   28.91  			 7:00	Russia	NOV%sT	1991 Mar 31 2:00s
   28.92  			 6:00	Russia	NOV%sT	1992 Jan 19 2:00s
   28.93  			 7:00	Russia	NOV%sT	1993 May 23 # say Shanks & P.
   28.94 -			 6:00	Russia	NOV%sT
   28.95 +			 6:00	Russia	NOV%sT	2011 Mar 27 2:00s
   28.96 +			 7:00	-	NOVT
   28.97  
   28.98  # From Alexander Krivenyshev (2009-10-13):
   28.99  # Kemerovo oblast' (Kemerovo region) in Russia will change current time zone on
  28.100 @@ -2153,7 +2180,8 @@
  28.101  			 7:00	Russia	KRA%sT	1991 Mar 31 2:00s
  28.102  			 6:00	Russia	KRA%sT	1992 Jan 19 2:00s
  28.103  			 7:00	Russia	KRA%sT	2010 Mar 28 2:00s
  28.104 -			 6:00	Russia	NOV%sT # Novosibirsk/Novokuznetsk Time
  28.105 +			 6:00	Russia	NOV%sT	2011 Mar 27 2:00s
  28.106 +			 7:00	-	NOVT # Novosibirsk/Novokuznetsk Time
  28.107  
  28.108  #
  28.109  # From Oscar van Vlijmen (2001-08-25): [This region consists of]
  28.110 @@ -2164,7 +2192,8 @@
  28.111  			 6:00	-	KRAT	1930 Jun 21 # Krasnoyarsk Time
  28.112  			 7:00	Russia	KRA%sT	1991 Mar 31 2:00s
  28.113  			 6:00	Russia	KRA%sT	1992 Jan 19 2:00s
  28.114 -			 7:00	Russia	KRA%sT
  28.115 +			 7:00	Russia	KRA%sT	2011 Mar 27 2:00s
  28.116 +			 8:00	-	KRAT
  28.117  #
  28.118  # From Oscar van Vlijmen (2001-08-25): [This region consists of]
  28.119  # Respublika Buryatiya, Irkutskaya oblast',
  28.120 @@ -2174,7 +2203,8 @@
  28.121  			 7:00	-	IRKT	1930 Jun 21 # Irkutsk Time
  28.122  			 8:00	Russia	IRK%sT	1991 Mar 31 2:00s
  28.123  			 7:00	Russia	IRK%sT	1992 Jan 19 2:00s
  28.124 -			 8:00	Russia	IRK%sT
  28.125 +			 8:00	Russia	IRK%sT	2011 Mar 27 2:00s
  28.126 +			 9:00	-	IRKT
  28.127  #
  28.128  # From Oscar van Vlijmen (2003-10-18): [This region consists of]
  28.129  # Aginskij Buryatskij avtonomnyj okrug, Amurskaya oblast',
  28.130 @@ -2197,7 +2227,8 @@
  28.131  			 8:00	-	YAKT	1930 Jun 21 # Yakutsk Time
  28.132  			 9:00	Russia	YAK%sT	1991 Mar 31 2:00s
  28.133  			 8:00	Russia	YAK%sT	1992 Jan 19 2:00s
  28.134 -			 9:00	Russia	YAK%sT
  28.135 +			 9:00	Russia	YAK%sT	2011 Mar 27 2:00s
  28.136 +			 10:00	-	YAKT
  28.137  #
  28.138  # From Oscar van Vlijmen (2003-10-18): [This region consists of]
  28.139  # Evrejskaya avtonomnaya oblast', Khabarovskij kraj, Primorskij kraj,
  28.140 @@ -2210,7 +2241,8 @@
  28.141  			 9:00	-	VLAT	1930 Jun 21 # Vladivostok Time
  28.142  			10:00	Russia	VLA%sT	1991 Mar 31 2:00s
  28.143  			 9:00	Russia	VLA%sST	1992 Jan 19 2:00s
  28.144 -			10:00	Russia	VLA%sT
  28.145 +			10:00	Russia	VLA%sT	2011 Mar 27 2:00s
  28.146 +			11:00	-	VLAT
  28.147  #
  28.148  # Sakhalinskaya oblast'.
  28.149  # The Zone name should be Yuzhno-Sakhalinsk, but that's too long.
  28.150 @@ -2220,7 +2252,8 @@
  28.151  			11:00	Russia	SAK%sT	1991 Mar 31 2:00s # Sakhalin T.
  28.152  			10:00	Russia	SAK%sT	1992 Jan 19 2:00s
  28.153  			11:00	Russia	SAK%sT	1997 Mar lastSun 2:00s
  28.154 -			10:00	Russia	SAK%sT
  28.155 +			10:00	Russia	SAK%sT	2011 Mar 27 2:00s
  28.156 +			11:00	-	SAKT
  28.157  #
  28.158  # From Oscar van Vlijmen (2003-10-18): [This region consists of]
  28.159  # Magadanskaya oblast', Respublika Sakha (Yakutiya).
  28.160 @@ -2233,7 +2266,8 @@
  28.161  			10:00	-	MAGT	1930 Jun 21 # Magadan Time
  28.162  			11:00	Russia	MAG%sT	1991 Mar 31 2:00s
  28.163  			10:00	Russia	MAG%sT	1992 Jan 19 2:00s
  28.164 -			11:00	Russia	MAG%sT
  28.165 +			11:00	Russia	MAG%sT	2011 Mar 27 2:00s
  28.166 +			12:00	-	MAGT
  28.167  #
  28.168  # From Oscar van Vlijmen (2001-08-25): [This region consists of]
  28.169  # Kamchatskaya oblast', Koryakskij avtonomnyj okrug.
  28.170 @@ -2244,7 +2278,8 @@
  28.171  			12:00	Russia	PET%sT	1991 Mar 31 2:00s
  28.172  			11:00	Russia	PET%sT	1992 Jan 19 2:00s
  28.173  			12:00	Russia	PET%sT	2010 Mar 28 2:00s
  28.174 -			11:00	Russia	PET%sT
  28.175 +			11:00	Russia	PET%sT	2011 Mar 27 2:00s
  28.176 +			12:00	-	PETT
  28.177  #
  28.178  # Chukotskij avtonomnyj okrug
  28.179  Zone Asia/Anadyr	11:49:56 -	LMT	1924 May  2
  28.180 @@ -2253,7 +2288,8 @@
  28.181  			12:00	Russia	ANA%sT	1991 Mar 31 2:00s
  28.182  			11:00	Russia	ANA%sT	1992 Jan 19 2:00s
  28.183  			12:00	Russia	ANA%sT	2010 Mar 28 2:00s
  28.184 -			11:00	Russia	ANA%sT
  28.185 +			11:00	Russia	ANA%sT	2011 Mar 27 2:00s
  28.186 +			12:00	-	ANAT
  28.187  
  28.188  # Serbia
  28.189  # Zone	NAME		GMTOFF	RULES	FORMAT	[UNTIL]
    29.1 --- a/make/sun/javazic/tzdata/iso3166.tab	Fri Sep 30 17:20:56 2011 -0700
    29.2 +++ b/make/sun/javazic/tzdata/iso3166.tab	Tue Oct 04 12:39:42 2011 -0700
    29.3 @@ -43,6 +43,9 @@
    29.4  #
    29.5  # Lines beginning with `#' are comments.
    29.6  #
    29.7 +# From Arthur David Olson (2011-08-17):
    29.8 +# Resynchronized today with the ISO 3166 site (adding SS for South Sudan).
    29.9 +#
   29.10  #country-
   29.11  #code	country name
   29.12  AD	Andorra
   29.13 @@ -52,7 +55,6 @@
   29.14  AI	Anguilla
   29.15  AL	Albania
   29.16  AM	Armenia
   29.17 -AN	Netherlands Antilles
   29.18  AO	Angola
   29.19  AQ	Antarctica
   29.20  AR	Argentina
   29.21 @@ -75,6 +77,7 @@
   29.22  BM	Bermuda
   29.23  BN	Brunei
   29.24  BO	Bolivia
   29.25 +BQ	Bonaire Sint Eustatius & Saba
   29.26  BR	Brazil
   29.27  BS	Bahamas
   29.28  BT	Bhutan
   29.29 @@ -97,6 +100,7 @@
   29.30  CR	Costa Rica
   29.31  CU	Cuba
   29.32  CV	Cape Verde
   29.33 +CW	Curacao
   29.34  CX	Christmas Island
   29.35  CY	Cyprus
   29.36  CZ	Czech Republic
   29.37 @@ -251,8 +255,10 @@
   29.38  SN	Senegal
   29.39  SO	Somalia
   29.40  SR	Suriname
   29.41 +SS	South Sudan
   29.42  ST	Sao Tome & Principe
   29.43  SV	El Salvador
   29.44 +SX	Sint Maarten
   29.45  SY	Syria
   29.46  SZ	Swaziland
   29.47  TC	Turks & Caicos Is
    30.1 --- a/make/sun/javazic/tzdata/northamerica	Fri Sep 30 17:20:56 2011 -0700
    30.2 +++ b/make/sun/javazic/tzdata/northamerica	Tue Oct 04 12:39:42 2011 -0700
    30.3 @@ -490,6 +490,10 @@
    30.4  # own time. I asked about daylight saving; they said it wasn't used. I
    30.5  # did not inquire about practices in the past.
    30.6  
    30.7 +# From Arthur David Olson (2011-08-17):
    30.8 +# For lack of better information, assume that Metlakatla's
    30.9 +# abandonment of use of daylight saving resulted from the 1983 vote.
   30.10 +
   30.11  # Zone	NAME		GMTOFF	RULES	FORMAT	[UNTIL]
   30.12  Zone America/Juneau	 15:02:19 -	LMT	1867 Oct 18
   30.13  			 -8:57:41 -	LMT	1900 Aug 20 12:00
   30.14 @@ -515,7 +519,7 @@
   30.15  			 -8:00	US	P%sT	1946
   30.16  			 -8:00	-	PST	1969
   30.17  			 -8:00	US	P%sT	1983 Oct 30 2:00
   30.18 -			 -8:00	US	MeST
   30.19 +			 -8:00	-	MeST
   30.20  Zone America/Yakutat	 14:41:05 -	LMT	1867 Oct 18
   30.21  			 -9:18:55 -	LMT	1900 Aug 20 12:00
   30.22  			 -9:00	-	YST	1942
   30.23 @@ -615,8 +619,8 @@
   30.24  			-10:30	-	HST	1933 Apr 30 2:00 #Laws 1933
   30.25  			-10:30	1:00	HDT	1933 May 21 12:00 #Laws 1933+12
   30.26  			-10:30	-	HST	1942 Feb 09 2:00 #Schmitt&Cox+2
   30.27 -			-10:30	1:00	HDT	1945 Sep 30 2:00 #Schmitt&Fox+2
   30.28 -			-10:30	US	H%sT	1947 Jun  8 2:00 #Schmitt&Fox+2
   30.29 +			-10:30	1:00	HDT	1945 Sep 30 2:00 #Schmitt&Cox+2
   30.30 +			-10:30	-	HST	1947 Jun  8 2:00 #Schmitt&Cox+2
   30.31  			-10:00	-	HST
   30.32  
   30.33  # Now we turn to US areas that have diverged from the consensus since 1970.
   30.34 @@ -1185,12 +1189,39 @@
   30.35  # From Paul Eggert (2000-10-02):
   30.36  # INMS (2000-09-12) says that, since 1988 at least, Newfoundland switches
   30.37  # at 00:01 local time.  For now, assume it started in 1987.
   30.38 +
   30.39 +# From Michael Pelley (2011-08-05):
   30.40 +# The Government of Newfoundland and Labrador has pending changes to
   30.41 +# modify the hour for daylight savings time to come into effect in
   30.42 +# November 2011. This modification would change the time from 12:01AM to
   30.43 +# 2:00AM on the dates of the switches of Daylight Savings Time to/from
   30.44 +# Standard Time.
   30.45 +#
   30.46 +# As a matter of reference, in Canada provinces have the authority of
   30.47 +# setting time zone information. The legislation has passed our
   30.48 +# legislative body (The House of Assembly) and is awaiting the
   30.49 +# proclamation to come into effect. You may find this information at:
   30.50 +# <a href="http://www.assembly.nl.ca/legislation/sr/lists/Proclamation.htm">
   30.51 +# http://www.assembly.nl.ca/legislation/sr/lists/Proclamation.htm
   30.52 +# </a>
   30.53 +# and
   30.54 +# search within that web page for Standard Time (Amendment) Act. The Act
   30.55 +# may be found at:
   30.56 +# <a href="http://www.assembly.nl.ca/business/bills/Bill1106.htm">
   30.57 +# http://www.assembly.nl.ca/business/bills/Bill1106.htm
   30.58 +# </a>
   30.59 +# ...
   30.60 +# MICHAEL PELLEY | Manager of Enterprise Architecture - Solution Delivery
   30.61 +# Office of the Chief Information Officer Executive Council Government of
   30.62 +# Newfoundland & Labrador P.O. Box 8700, 40 Higgins Line, St. John's NL
   30.63 +# A1B 4J6
   30.64 +
   30.65  Rule	StJohns	1987	only	-	Apr	Sun>=1	0:01	1:00	D
   30.66  Rule	StJohns	1987	2006	-	Oct	lastSun	0:01	0	S
   30.67  Rule	StJohns	1988	only	-	Apr	Sun>=1	0:01	2:00	DD
   30.68  Rule	StJohns	1989	2006	-	Apr	Sun>=1	0:01	1:00	D
   30.69 -Rule	StJohns	2007	max	-	Mar	Sun>=8	0:01	1:00	D
   30.70 -Rule	StJohns	2007	max	-	Nov	Sun>=1	0:01	0	S
   30.71 +Rule	StJohns	2007	2011	-	Mar	Sun>=8	0:01	1:00	D
   30.72 +Rule	StJohns	2007	2010	-	Nov	Sun>=1	0:01	0	S
   30.73  #
   30.74  # St John's has an apostrophe, but Posix file names can't have apostrophes.
   30.75  # Zone	NAME		GMTOFF	RULES	FORMAT	[UNTIL]
   30.76 @@ -1200,7 +1231,8 @@
   30.77  			-3:30:52 StJohns N%sT	1935 Mar 30
   30.78  			-3:30	StJohns	N%sT	1942 May 11
   30.79  			-3:30	Canada	N%sT	1946
   30.80 -			-3:30	StJohns	N%sT
   30.81 +			-3:30	StJohns	N%sT	2011 Nov
   30.82 +			-3:30	Canada	N%sT
   30.83  
   30.84  # most of east Labrador
   30.85  
   30.86 @@ -1214,7 +1246,8 @@
   30.87  			-3:30	StJohns	N%sT	1942 May 11
   30.88  			-3:30	Canada	N%sT	1946
   30.89  			-3:30	StJohns	N%sT	1966 Mar 15 2:00
   30.90 -			-4:00	StJohns	A%sT
   30.91 +			-4:00	StJohns	A%sT	2011 Nov
   30.92 +			-4:00	Canada	A%sT
   30.93  
   30.94  
   30.95  # west Labrador, Nova Scotia, Prince Edward I
   30.96 @@ -1946,20 +1979,69 @@
   30.97  # daylight saving....
   30.98  # http://www.nnsl.com/frames/newspapers/2006-11/nov13_06none.html
   30.99  
  30.100 -# From Chris Walton (2007-03-14):
  30.101 -# Today I phoned the "hamlet office" to find out what Resolute was doing with
  30.102 -# its clocks.
  30.103 +# From Chris Walton (2011-03-21):
  30.104 +# Back in 2007 I initiated the creation of a new "zone file" for Resolute
  30.105 +# Bay. Resolute Bay is a small community located about 900km north of
  30.106 +# the Arctic Circle. The zone file was required because Resolute Bay had
  30.107 +# decided to use UTC-5 instead of UTC-6 for the winter of 2006-2007.
  30.108  #
  30.109 -# The individual that answered the phone confirmed that the clocks did not
  30.110 -# move at the end of daylight saving on October 29/2006.  He also told me that
  30.111 -# the clocks did not move this past weekend (March 11/2007)....
  30.112 -
  30.113 -# From Chris Walton (2008-11-13):
  30.114 -# ...the residents of Resolute believe that they are changing "time zones"
  30.115 -# twice a year.  In winter months, local time is qualified with "Eastern
  30.116 -# Time" which is really "Eastern Standard Time (UTC-5)".  In summer
  30.117 -# months, local time is qualified with "Central Time" which is really
  30.118 -# "Central Daylight Time (UTC-5)"...
  30.119 +# According to new information which I received last week, Resolute Bay
  30.120 +# went back to using UTC-6 in the winter of 2007-2008...
  30.121 +#
  30.122 +# On March 11/2007 most of Canada went onto daylight saving. On March
  30.123 +# 14/2007 I phoned the Resolute Bay hamlet office to do a "time check." I
  30.124 +# talked to somebody that was both knowledgeable and helpful. I was able
  30.125 +# to confirm that Resolute Bay was still operating on UTC-5. It was
  30.126 +# explained to me that Resolute Bay had been on the Eastern Time zone
  30.127 +# (EST) in the winter, and was now back on the Central Time zone (CDT).
  30.128 +# i.e. the time zone had changed twice in the last year but the clocks
  30.129 +# had not moved. The residents had to know which time zone they were in
  30.130 +# so they could follow the correct TV schedule...
  30.131 +#
  30.132 +# On Nov 02/2008 most of Canada went onto standard time. On Nov 03/2008 I
  30.133 +# phoned the Resolute Bay hamlet office...[D]ue to the challenging nature
  30.134 +# of the phone call, I decided to seek out an alternate source of
  30.135 +# information. I found an e-mail address for somebody by the name of
  30.136 +# Stephanie Adams whose job was listed as "Inns North Support Officer for
  30.137 +# Arctic Co-operatives." I was under the impression that Stephanie lived
  30.138 +# and worked in Resolute Bay...
  30.139 +#
  30.140 +# On March 14/2011 I phoned the hamlet office again. I was told that
  30.141 +# Resolute Bay had been using Central Standard Time over the winter of
  30.142 +# 2010-2011 and that the clocks had therefore been moved one hour ahead
  30.143 +# on March 13/2011. The person I talked to was aware that Resolute Bay
  30.144 +# had previously experimented with Eastern Standard Time but he could not
  30.145 +# tell me when the practice had stopped.
  30.146 +#
  30.147 +# On March 17/2011 I searched the Web to find an e-mail address of
  30.148 +# somebody that might be able to tell me exactly when Resolute Bay went
  30.149 +# off Eastern Standard Time. I stumbled on the name "Aziz Kheraj." Aziz
  30.150 +# used to be the mayor of Resolute Bay and he apparently owns half the
  30.151 +# businesses including "South Camp Inn." This website has some info on
  30.152 +# Aziz:
  30.153 +# <a href="http://www.uphere.ca/node/493">
  30.154 +# http://www.uphere.ca/node/493
  30.155 +# </a>
  30.156 +#
  30.157 +# I sent Aziz an e-mail asking when Resolute Bay had stopped using
  30.158 +# Eastern Standard Time.
  30.159 +#
  30.160 +# Aziz responded quickly with this: "hi, The time was not changed for the
  30.161 +# 1 year only, the following year, the community went back to the old way
  30.162 +# of "spring ahead-fall behind" currently we are zulu plus 5 hrs and in
  30.163 +# the winter Zulu plus 6 hrs"
  30.164 +#
  30.165 +# This of course conflicted with everything I had ascertained in November 2008.
  30.166 +#
  30.167 +# I sent Aziz a copy of my 2008 e-mail exchange with Stephanie. Aziz
  30.168 +# responded with this: "Hi, Stephanie lives in Winnipeg. I live here, You
  30.169 +# may want to check with the weather office in Resolute Bay or do a
  30.170 +# search on the weather through Env. Canada. web site"
  30.171 +#
  30.172 +# If I had realized the Stephanie did not live in Resolute Bay I would
  30.173 +# never have contacted her.  I now believe that all the information I
  30.174 +# obtained in November 2008 should be ignored...
  30.175 +# I apologize for reporting incorrect information in 2008.
  30.176  
  30.177  # Rule	NAME	FROM	TO	TYPE	IN	ON	AT	SAVE	LETTER/S
  30.178  Rule	NT_YK	1918	only	-	Apr	14	2:00	1:00	D
  30.179 @@ -1987,14 +2069,12 @@
  30.180  			-6:00	Canada	C%sT	2000 Oct 29 2:00
  30.181  			-5:00	Canada	E%sT
  30.182  # aka Qausuittuq
  30.183 -# Rule	NAME	FROM	TO	TYPE	IN	ON	AT	SAVE	LETTER/S
  30.184 -Rule	Resolute 2006	max	-	Nov	Sun>=1	2:00	0	ES
  30.185 -Rule	Resolute 2007	max	-	Mar	Sun>=8	2:00	0	CD
  30.186  Zone America/Resolute	0	-	zzz	1947 Aug 31 # Resolute founded
  30.187  			-6:00	NT_YK	C%sT	2000 Oct 29 2:00
  30.188  			-5:00	-	EST	2001 Apr  1 3:00
  30.189  			-6:00	Canada	C%sT	2006 Oct 29 2:00
  30.190 -			-5:00	Resolute	%sT
  30.191 +			-5:00	-	EST	2007 Mar 11 3:00
  30.192 +			-6:00	Canada	C%sT
  30.193  # aka Kangiqiniq
  30.194  Zone America/Rankin_Inlet 0	-	zzz	1957 # Rankin Inlet founded
  30.195  			-6:00	NT_YK	C%sT	2000 Oct 29 2:00
    31.1 --- a/make/sun/javazic/tzdata/southamerica	Fri Sep 30 17:20:56 2011 -0700
    31.2 +++ b/make/sun/javazic/tzdata/southamerica	Tue Oct 04 12:39:42 2011 -0700
    31.3 @@ -1298,6 +1298,14 @@
    31.4  			-4:30	-	ANT	1965 # Netherlands Antilles Time
    31.5  			-4:00	-	AST
    31.6  
    31.7 +# From Arthur David Olson (2011-06-15):
    31.8 +# At least for now, use links for places with new iso3166 codes.
    31.9 +# The name "Lower Prince's Quarter" is both longer than fourteen charaters
   31.10 +# and contains an apostrophe; use "Lower_Princes" below.
   31.11 +
   31.12 +Link	America/Curacao	America/Lower_Princes # Sint Maarten
   31.13 +Link	America/Curacao	America/Kralendijk # Bonaire, Sint Estatius and Saba
   31.14 +
   31.15  # Ecuador
   31.16  #
   31.17  # From Paul Eggert (2007-03-04):
    32.1 --- a/make/sun/javazic/tzdata/zone.tab	Fri Sep 30 17:20:56 2011 -0700
    32.2 +++ b/make/sun/javazic/tzdata/zone.tab	Tue Oct 04 12:39:42 2011 -0700
    32.3 @@ -54,7 +54,6 @@
    32.4  AI	+1812-06304	America/Anguilla
    32.5  AL	+4120+01950	Europe/Tirane
    32.6  AM	+4011+04430	Asia/Yerevan
    32.7 -AN	+1211-06900	America/Curacao
    32.8  AO	-0848+01314	Africa/Luanda
    32.9  AQ	-7750+16636	Antarctica/McMurdo	McMurdo Station, Ross Island
   32.10  AQ	-9000+00000	Antarctica/South_Pole	Amundsen-Scott Station, South Pole
   32.11 @@ -109,6 +108,7 @@
   32.12  BM	+3217-06446	Atlantic/Bermuda
   32.13  BN	+0456+11455	Asia/Brunei
   32.14  BO	-1630-06809	America/La_Paz
   32.15 +BQ	+120903-0681636	America/Kralendijk
   32.16  BR	-0351-03225	America/Noronha	Atlantic islands
   32.17  BR	-0127-04829	America/Belem	Amapa, E Para
   32.18  BR	-0343-03830	America/Fortaleza	NE Brazil (MA, PI, CE, RN, PB)
   32.19 @@ -142,7 +142,7 @@
   32.20  CA	+4823-08915	America/Thunder_Bay	Eastern Time - Thunder Bay, Ontario
   32.21  CA	+6344-06828	America/Iqaluit	Eastern Time - east Nunavut - most locations
   32.22  CA	+6608-06544	America/Pangnirtung	Eastern Time - Pangnirtung, Nunavut
   32.23 -CA	+744144-0944945	America/Resolute	Eastern Standard Time - Resolute, Nunavut
   32.24 +CA	+744144-0944945	America/Resolute	Central Standard Time - Resolute, Nunavut
   32.25  CA	+484531-0913718	America/Atikokan	Eastern Standard Time - Atikokan, Ontario and Southampton I, Nunavut
   32.26  CA	+624900-0920459	America/Rankin_Inlet	Central Time - central Nunavut
   32.27  CA	+4953-09709	America/Winnipeg	Central Time - Manitoba & west Ontario
   32.28 @@ -177,6 +177,7 @@
   32.29  CR	+0956-08405	America/Costa_Rica
   32.30  CU	+2308-08222	America/Havana
   32.31  CV	+1455-02331	Atlantic/Cape_Verde
   32.32 +CW	+1211-06900	America/Curacao
   32.33  CX	-1025+10543	Indian/Christmas
   32.34  CY	+3510+03322	Asia/Nicosia
   32.35  CZ	+5005+01426	Europe/Prague
   32.36 @@ -382,8 +383,10 @@
   32.37  SN	+1440-01726	Africa/Dakar
   32.38  SO	+0204+04522	Africa/Mogadishu
   32.39  SR	+0550-05510	America/Paramaribo
   32.40 +SS	+0451+03136	Africa/Juba
   32.41  ST	+0020+00644	Africa/Sao_Tome
   32.42  SV	+1342-08912	America/El_Salvador
   32.43 +SX	+180305-0630250	America/Lower_Princes
   32.44  SY	+3330+03618	Asia/Damascus
   32.45  SZ	-2618+03106	Africa/Mbabane
   32.46  TC	+2128-07108	America/Grand_Turk
    33.1 --- a/make/sun/net/Makefile	Fri Sep 30 17:20:56 2011 -0700
    33.2 +++ b/make/sun/net/Makefile	Tue Oct 04 12:39:42 2011 -0700
    33.3 @@ -1,5 +1,5 @@
    33.4  #
    33.5 -# Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
    33.6 +# Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
    33.7  # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    33.8  #
    33.9  # This code is free software; you can redistribute it and/or modify it
   33.10 @@ -26,6 +26,8 @@
   33.11  BUILDDIR = ../..
   33.12  PACKAGE = sun.net
   33.13  PRODUCT = sun
   33.14 +SUBDIRS_MAKEFLAGS += JAVAC_MAX_WARNINGS=true
   33.15 +SUBDIRS_MAKEFLAGS += JAVAC_WARNINGS_FATAL=true
   33.16  include $(BUILDDIR)/common/Defs.gmk
   33.17  
   33.18  SUBDIRS = others spi
    34.1 --- a/make/sun/net/spi/Makefile	Fri Sep 30 17:20:56 2011 -0700
    34.2 +++ b/make/sun/net/spi/Makefile	Tue Oct 04 12:39:42 2011 -0700
    34.3 @@ -24,6 +24,8 @@
    34.4  #
    34.5  
    34.6  BUILDDIR = ../../..
    34.7 +SUBDIRS_MAKEFLAGS += JAVAC_WARNINGS_FATAL=true
    34.8 +
    34.9  include $(BUILDDIR)/common/Defs.gmk
   34.10  
   34.11  SUBDIRS_misc = nameservice 
    35.1 --- a/make/sun/net/spi/nameservice/dns/Makefile	Fri Sep 30 17:20:56 2011 -0700
    35.2 +++ b/make/sun/net/spi/nameservice/dns/Makefile	Tue Oct 04 12:39:42 2011 -0700
    35.3 @@ -28,7 +28,8 @@
    35.4  #
    35.5  
    35.6  BUILDDIR = ../../../../..
    35.7 -
    35.8 +JAVAC_MAX_WARNINGS = true
    35.9 +JAVAC_WARNINGS_FATAL = true
   35.10  # dns should probably be its own module
   35.11  PACKAGE = sun.net.spi.nameservice.dns
   35.12  PRODUCT = sun
    36.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    36.2 +++ b/make/sun/util/Makefile	Tue Oct 04 12:39:42 2011 -0700
    36.3 @@ -0,0 +1,40 @@
    36.4 +#
    36.5 +# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
    36.6 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    36.7 +#
    36.8 +# This code is free software; you can redistribute it and/or modify it
    36.9 +# under the terms of the GNU General Public License version 2 only, as
   36.10 +# published by the Free Software Foundation.  Oracle designates this
   36.11 +# particular file as subject to the "Classpath" exception as provided
   36.12 +# by Oracle in the LICENSE file that accompanied this code.
   36.13 +#
   36.14 +# This code is distributed in the hope that it will be useful, but WITHOUT
   36.15 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   36.16 +# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   36.17 +# version 2 for more details (a copy is included in the LICENSE file that
   36.18 +# accompanied this code).
   36.19 +#
   36.20 +# You should have received a copy of the GNU General Public License version
   36.21 +# 2 along with this work; if not, write to the Free Software Foundation,
   36.22 +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   36.23 +#
   36.24 +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   36.25 +# or visit www.oracle.com if you need additional information or have any
   36.26 +# questions.
   36.27 +#
   36.28 +
   36.29 +BUILDDIR = ../..
   36.30 +PACKAGE = sun.util
   36.31 +PRODUCT = sun
   36.32 +include $(BUILDDIR)/common/Defs.gmk
   36.33 +
   36.34 +#
   36.35 +# Files
   36.36 +#
   36.37 +AUTO_FILES_JAVA_DIRS = sun/util/xml
   36.38 +
   36.39 +#
   36.40 +# Rules
   36.41 +#
   36.42 +include $(BUILDDIR)/common/Classes.gmk
   36.43 +
    37.1 --- a/make/tools/src/build/tools/javazic/Mappings.java	Fri Sep 30 17:20:56 2011 -0700
    37.2 +++ b/make/tools/src/build/tools/javazic/Mappings.java	Tue Oct 04 12:39:42 2011 -0700
    37.3 @@ -76,8 +76,8 @@
    37.4              // If the GMT offset of this Zone will change in some
    37.5              // future time, this Zone is added to the exclude list.
    37.6              boolean isExcluded = false;
    37.7 -            if (zone.size() > 1) {
    37.8 -                ZoneRec zrec = zone.get(zone.size()-2);
    37.9 +            for (int i = 0; i < zone.size(); i++) {
   37.10 +                ZoneRec zrec = zone.get(i);
   37.11                  if ((zrec.getGmtOffset() != rawOffset)
   37.12                      && (zrec.getUntilTime(0) > Time.getCurrentTime())) {
   37.13                      if (excludeList == null) {
   37.14 @@ -85,6 +85,7 @@
   37.15                      }
   37.16                      excludeList.add(zone.getName());
   37.17                      isExcluded = true;
   37.18 +                    break;
   37.19                  }
   37.20              }
   37.21  
    38.1 --- a/src/share/classes/com/sun/net/httpserver/BasicAuthenticator.java	Fri Sep 30 17:20:56 2011 -0700
    38.2 +++ b/src/share/classes/com/sun/net/httpserver/BasicAuthenticator.java	Tue Oct 04 12:39:42 2011 -0700
    38.3 @@ -1,5 +1,5 @@
    38.4  /*
    38.5 - * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
    38.6 + * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
    38.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    38.8   *
    38.9   * This code is free software; you can redistribute it and/or modify it
   38.10 @@ -54,13 +54,13 @@
   38.11  
   38.12      public Result authenticate (HttpExchange t)
   38.13      {
   38.14 -        Headers rmap = (Headers) t.getRequestHeaders();
   38.15 +        Headers rmap = t.getRequestHeaders();
   38.16          /*
   38.17           * look for auth token
   38.18           */
   38.19          String auth = rmap.getFirst ("Authorization");
   38.20          if (auth == null) {
   38.21 -            Headers map = (Headers) t.getResponseHeaders();
   38.22 +            Headers map = t.getResponseHeaders();
   38.23              map.set ("WWW-Authenticate", "Basic realm=" + "\""+realm+"\"");
   38.24              return new Authenticator.Retry (401);
   38.25          }
   38.26 @@ -83,7 +83,7 @@
   38.27          } else {
   38.28              /* reject the request again with 401 */
   38.29  
   38.30 -            Headers map = (Headers) t.getResponseHeaders();
   38.31 +            Headers map = t.getResponseHeaders();
   38.32              map.set ("WWW-Authenticate", "Basic realm=" + "\""+realm+"\"");
   38.33              return new Authenticator.Failure(401);
   38.34          }
    39.1 --- a/src/share/classes/com/sun/net/httpserver/Headers.java	Fri Sep 30 17:20:56 2011 -0700
    39.2 +++ b/src/share/classes/com/sun/net/httpserver/Headers.java	Tue Oct 04 12:39:42 2011 -0700
    39.3 @@ -1,5 +1,5 @@
    39.4  /*
    39.5 - * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
    39.6 + * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
    39.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    39.8   *
    39.9   * This code is free software; you can redistribute it and/or modify it
   39.10 @@ -117,7 +117,7 @@
   39.11           * @return the first string value associated with the key
   39.12           */
   39.13          public String getFirst (String key) {
   39.14 -            List<String> l = map.get(normalize((String)key));
   39.15 +            List<String> l = map.get(normalize(key));
   39.16              if (l == null) {
   39.17                  return null;
   39.18              }
    40.1 --- a/src/share/classes/com/sun/net/httpserver/spi/HttpServerProvider.java	Fri Sep 30 17:20:56 2011 -0700
    40.2 +++ b/src/share/classes/com/sun/net/httpserver/spi/HttpServerProvider.java	Tue Oct 04 12:39:42 2011 -0700
    40.3 @@ -1,5 +1,5 @@
    40.4  /*
    40.5 - * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
    40.6 + * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
    40.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    40.8   *
    40.9   * This code is free software; you can redistribute it and/or modify it
   40.10 @@ -81,29 +81,27 @@
   40.11          if (cn == null)
   40.12              return false;
   40.13          try {
   40.14 -            Class c = Class.forName(cn, true,
   40.15 +            Class<?> c = Class.forName(cn, true,
   40.16                                      ClassLoader.getSystemClassLoader());
   40.17              provider = (HttpServerProvider)c.newInstance();
   40.18              return true;
   40.19 -        } catch (ClassNotFoundException x) {
   40.20 -            throw new ServiceConfigurationError(x);
   40.21 -        } catch (IllegalAccessException x) {
   40.22 -            throw new ServiceConfigurationError(x);
   40.23 -        } catch (InstantiationException x) {
   40.24 -            throw new ServiceConfigurationError(x);
   40.25 -        } catch (SecurityException x) {
   40.26 +        } catch (ClassNotFoundException |
   40.27 +                 IllegalAccessException |
   40.28 +                 InstantiationException |
   40.29 +                 SecurityException x) {
   40.30              throw new ServiceConfigurationError(x);
   40.31          }
   40.32      }
   40.33  
   40.34      private static boolean loadProviderAsService() {
   40.35 -        Iterator i = Service.providers(HttpServerProvider.class,
   40.36 +        @SuppressWarnings("unchecked")
   40.37 +        Iterator<HttpServerProvider> i = Service.providers(HttpServerProvider.class,
   40.38                                         ClassLoader.getSystemClassLoader());
   40.39          for (;;) {
   40.40              try {
   40.41                  if (!i.hasNext())
   40.42                      return false;
   40.43 -                provider = (HttpServerProvider)i.next();
   40.44 +                provider = i.next();
   40.45                  return true;
   40.46              } catch (ServiceConfigurationError sce) {
   40.47                  if (sce.getCause() instanceof SecurityException) {
    41.1 --- a/src/share/classes/com/sun/net/ssl/SSLSecurity.java	Fri Sep 30 17:20:56 2011 -0700
    41.2 +++ b/src/share/classes/com/sun/net/ssl/SSLSecurity.java	Tue Oct 04 12:39:42 2011 -0700
    41.3 @@ -1,5 +1,5 @@
    41.4  /*
    41.5 - * Copyright (c) 2000, 2006, Oracle and/or its affiliates. All rights reserved.
    41.6 + * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
    41.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    41.8   *
    41.9   * This code is free software; you can redistribute it and/or modify it
   41.10 @@ -77,7 +77,7 @@
   41.11      {
   41.12          Provider provider = service.getProvider();
   41.13          String className = service.getClassName();
   41.14 -        Class implClass;
   41.15 +        Class<?> implClass;
   41.16          try {
   41.17              ClassLoader cl = provider.getClass().getClassLoader();
   41.18              if (cl == null) {
   41.19 @@ -133,8 +133,8 @@
   41.20               * or someone has removed classes from the jsse.jar file.
   41.21               */
   41.22  
   41.23 -            Class typeClassJavax;
   41.24 -            Class typeClassCom;
   41.25 +            Class<?> typeClassJavax;
   41.26 +            Class<?> typeClassCom;
   41.27              Object obj = null;
   41.28  
   41.29              /*
   41.30 @@ -237,7 +237,7 @@
   41.31      /*
   41.32       * Checks whether one class is the superclass of another
   41.33       */
   41.34 -    private static boolean checkSuperclass(Class subclass, Class superclass) {
   41.35 +    private static boolean checkSuperclass(Class<?> subclass, Class<?> superclass) {
   41.36          if ((subclass == null) || (superclass == null))
   41.37                  return false;
   41.38  
   41.39 @@ -276,7 +276,6 @@
   41.40   * object.  This also mean that anything going down into the SPI
   41.41   * needs to be wrapped, as well as anything coming back up.
   41.42   */
   41.43 -
   41.44  final class SSLContextSpiWrapper extends SSLContextSpi {
   41.45  
   41.46      private javax.net.ssl.SSLContext theSSLContext;
    42.1 --- a/src/share/classes/com/sun/net/ssl/internal/www/protocol/https/DelegateHttpsURLConnection.java	Fri Sep 30 17:20:56 2011 -0700
    42.2 +++ b/src/share/classes/com/sun/net/ssl/internal/www/protocol/https/DelegateHttpsURLConnection.java	Tue Oct 04 12:39:42 2011 -0700
    42.3 @@ -165,10 +165,10 @@
    42.4      private static String getServername(X509Certificate peerCert) {
    42.5          try {
    42.6              // compare to subjectAltNames if dnsName is present
    42.7 -            Collection subjAltNames = peerCert.getSubjectAlternativeNames();
    42.8 +            Collection<List<?>> subjAltNames = peerCert.getSubjectAlternativeNames();
    42.9              if (subjAltNames != null) {
   42.10 -                for (Iterator itr = subjAltNames.iterator(); itr.hasNext(); ) {
   42.11 -                    List next = (List)itr.next();
   42.12 +                for (Iterator<List<?>> itr = subjAltNames.iterator(); itr.hasNext(); ) {
   42.13 +                    List<?> next = itr.next();
   42.14                      if (((Integer)next.get(0)).intValue() == 2) {
   42.15                          // compare dNSName with host in url
   42.16                          String dnsName = ((String)next.get(1));
    43.1 --- a/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic.properties	Fri Sep 30 17:20:56 2011 -0700
    43.2 +++ b/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic.properties	Tue Oct 04 12:39:42 2011 -0700
    43.3 @@ -91,6 +91,9 @@
    43.4  FileChooser.helpButtonToolTipText=FileChooser help
    43.5  FileChooser.directoryOpenButtonToolTipText=Open selected directory
    43.6  
    43.7 +FileChooser.filesListAccessibleName=Files List
    43.8 +FileChooser.filesDetailsAccessibleName=Files Details
    43.9 +
   43.10  ############ COLOR CHOOSER STRINGS #############
   43.11  ColorChooser.previewText=Preview
   43.12  ColorChooser.okText=OK
    44.1 --- a/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_de.properties	Fri Sep 30 17:20:56 2011 -0700
    44.2 +++ b/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_de.properties	Tue Oct 04 12:39:42 2011 -0700
    44.3 @@ -90,6 +90,9 @@
    44.4  FileChooser.helpButtonToolTipText=FileChooser-Hilfe
    44.5  FileChooser.directoryOpenButtonToolTipText=Ausgew\u00E4hltes Verzeichnis \u00F6ffnen
    44.6  
    44.7 +FileChooser.filesListAccessibleName=Files List
    44.8 +FileChooser.filesDetailsAccessibleName=Files Details
    44.9 +
   44.10  ############ COLOR CHOOSER STRINGS #############
   44.11  ColorChooser.previewText=Vorschau
   44.12  ColorChooser.okText=OK
    45.1 --- a/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_es.properties	Fri Sep 30 17:20:56 2011 -0700
    45.2 +++ b/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_es.properties	Tue Oct 04 12:39:42 2011 -0700
    45.3 @@ -90,6 +90,9 @@
    45.4  FileChooser.helpButtonToolTipText=Ayuda del Selector de Archivos
    45.5  FileChooser.directoryOpenButtonToolTipText=Abrir directorio seleccionado
    45.6  
    45.7 +FileChooser.filesListAccessibleName=Files List
    45.8 +FileChooser.filesDetailsAccessibleName=Files Details
    45.9 +
   45.10  ############ COLOR CHOOSER STRINGS #############
   45.11  ColorChooser.previewText=Presentaci\u00F3n Preliminar
   45.12  ColorChooser.okText=Aceptar
    46.1 --- a/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_fr.properties	Fri Sep 30 17:20:56 2011 -0700
    46.2 +++ b/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_fr.properties	Tue Oct 04 12:39:42 2011 -0700
    46.3 @@ -90,6 +90,9 @@
    46.4  FileChooser.helpButtonToolTipText=Aide du s\u00E9lecteur de fichiers
    46.5  FileChooser.directoryOpenButtonToolTipText=Ouvre le r\u00E9pertoire s\u00E9lectionn\u00E9
    46.6  
    46.7 +FileChooser.filesListAccessibleName=Files List
    46.8 +FileChooser.filesDetailsAccessibleName=Files Details
    46.9 +
   46.10  ############ COLOR CHOOSER STRINGS #############
   46.11  ColorChooser.previewText=Aper\u00E7u
   46.12  ColorChooser.okText=OK
    47.1 --- a/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_it.properties	Fri Sep 30 17:20:56 2011 -0700
    47.2 +++ b/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_it.properties	Tue Oct 04 12:39:42 2011 -0700
    47.3 @@ -90,6 +90,9 @@
    47.4  FileChooser.helpButtonToolTipText=Guida FileChooser
    47.5  FileChooser.directoryOpenButtonToolTipText=Apre la directory selezionata
    47.6  
    47.7 +FileChooser.filesListAccessibleName=Files List
    47.8 +FileChooser.filesDetailsAccessibleName=Files Details
    47.9 +
   47.10  ############ COLOR CHOOSER STRINGS #############
   47.11  ColorChooser.previewText=Anteprima
   47.12  ColorChooser.okText=OK
    48.1 --- a/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_ja.properties	Fri Sep 30 17:20:56 2011 -0700
    48.2 +++ b/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_ja.properties	Tue Oct 04 12:39:42 2011 -0700
    48.3 @@ -90,6 +90,9 @@
    48.4  FileChooser.helpButtonToolTipText=FileChooser\u306E\u30D8\u30EB\u30D7\u3067\u3059
    48.5  FileChooser.directoryOpenButtonToolTipText=\u9078\u629E\u3057\u305F\u30C7\u30A3\u30EC\u30AF\u30C8\u30EA\u3092\u958B\u304D\u307E\u3059
    48.6  
    48.7 +FileChooser.filesListAccessibleName=Files List
    48.8 +FileChooser.filesDetailsAccessibleName=Files Details
    48.9 +
   48.10  ############ COLOR CHOOSER STRINGS #############
   48.11  ColorChooser.previewText=\u30D7\u30EC\u30D3\u30E5\u30FC
   48.12  ColorChooser.okText=OK
    49.1 --- a/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_ko.properties	Fri Sep 30 17:20:56 2011 -0700
    49.2 +++ b/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_ko.properties	Tue Oct 04 12:39:42 2011 -0700
    49.3 @@ -90,6 +90,9 @@
    49.4  FileChooser.helpButtonToolTipText=FileChooser \uB3C4\uC6C0\uB9D0
    49.5  FileChooser.directoryOpenButtonToolTipText=\uC120\uD0DD\uB41C \uB514\uB809\uD1A0\uB9AC \uC5F4\uAE30
    49.6  
    49.7 +FileChooser.filesListAccessibleName=Files List
    49.8 +FileChooser.filesDetailsAccessibleName=Files Details
    49.9 +
   49.10  ############ COLOR CHOOSER STRINGS #############
   49.11  ColorChooser.previewText=\uBBF8\uB9AC\uBCF4\uAE30
   49.12  ColorChooser.okText=\uD655\uC778
    50.1 --- a/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_pt_BR.properties	Fri Sep 30 17:20:56 2011 -0700
    50.2 +++ b/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_pt_BR.properties	Tue Oct 04 12:39:42 2011 -0700
    50.3 @@ -90,6 +90,9 @@
    50.4  FileChooser.helpButtonToolTipText=Ajuda do FileChooser
    50.5  FileChooser.directoryOpenButtonToolTipText=Abrir diret\u00F3rio selecionado
    50.6  
    50.7 +FileChooser.filesListAccessibleName=Files List
    50.8 +FileChooser.filesDetailsAccessibleName=Files Details
    50.9 +
   50.10  ############ COLOR CHOOSER STRINGS #############
   50.11  ColorChooser.previewText=Visualizar
   50.12  ColorChooser.okText=OK
    51.1 --- a/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_sv.properties	Fri Sep 30 17:20:56 2011 -0700
    51.2 +++ b/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_sv.properties	Tue Oct 04 12:39:42 2011 -0700
    51.3 @@ -90,6 +90,9 @@
    51.4  FileChooser.helpButtonToolTipText=Hj\u00E4lp - Filv\u00E4ljare
    51.5  FileChooser.directoryOpenButtonToolTipText=\u00D6ppna vald katalog
    51.6  
    51.7 +FileChooser.filesListAccessibleName=Files List
    51.8 +FileChooser.filesDetailsAccessibleName=Files Details
    51.9 +
   51.10  ############ COLOR CHOOSER STRINGS #############
   51.11  ColorChooser.previewText=Granska
   51.12  ColorChooser.okText=OK
    52.1 --- a/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_zh_CN.properties	Fri Sep 30 17:20:56 2011 -0700
    52.2 +++ b/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_zh_CN.properties	Tue Oct 04 12:39:42 2011 -0700
    52.3 @@ -90,6 +90,9 @@
    52.4  FileChooser.helpButtonToolTipText=FileChooser \u5E2E\u52A9
    52.5  FileChooser.directoryOpenButtonToolTipText=\u6253\u5F00\u9009\u62E9\u7684\u76EE\u5F55
    52.6  
    52.7 +FileChooser.filesListAccessibleName=Files List
    52.8 +FileChooser.filesDetailsAccessibleName=Files Details
    52.9 +
   52.10  ############ COLOR CHOOSER STRINGS #############
   52.11  ColorChooser.previewText=\u9884\u89C8
   52.12  ColorChooser.okText=\u786E\u5B9A
    53.1 --- a/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_zh_TW.properties	Fri Sep 30 17:20:56 2011 -0700
    53.2 +++ b/src/share/classes/com/sun/swing/internal/plaf/basic/resources/basic_zh_TW.properties	Tue Oct 04 12:39:42 2011 -0700
    53.3 @@ -90,6 +90,9 @@
    53.4  FileChooser.helpButtonToolTipText=\u300C\u6A94\u6848\u9078\u64C7\u5668\u300D\u8AAA\u660E
    53.5  FileChooser.directoryOpenButtonToolTipText=\u958B\u555F\u9078\u53D6\u7684\u76EE\u9304
    53.6  
    53.7 +FileChooser.filesListAccessibleName=Files List
    53.8 +FileChooser.filesDetailsAccessibleName=Files Details
    53.9 +
   53.10  ############ COLOR CHOOSER STRINGS #############
   53.11  ColorChooser.previewText=\u9810\u89BD
   53.12  ColorChooser.okText=\u78BA\u5B9A
    54.1 --- a/src/share/classes/java/awt/AWTKeyStroke.java	Fri Sep 30 17:20:56 2011 -0700
    54.2 +++ b/src/share/classes/java/awt/AWTKeyStroke.java	Tue Oct 04 12:39:42 2011 -0700
    54.3 @@ -777,10 +777,6 @@
    54.4       */
    54.5      protected Object readResolve() throws java.io.ObjectStreamException {
    54.6          synchronized (AWTKeyStroke.class) {
    54.7 -            Class newClass = getClass();
    54.8 -            if (!newClass.equals(ctor.getDeclaringClass())) {
    54.9 -                registerSubclass(newClass);
   54.10 -            }
   54.11              return getCachedStroke(keyChar, keyCode, modifiers, onKeyRelease);
   54.12          }
   54.13      }
    55.1 --- a/src/share/classes/java/awt/EventDispatchThread.java	Fri Sep 30 17:20:56 2011 -0700
    55.2 +++ b/src/share/classes/java/awt/EventDispatchThread.java	Tue Oct 04 12:39:42 2011 -0700
    55.3 @@ -34,8 +34,10 @@
    55.4  import sun.security.action.GetPropertyAction;
    55.5  import sun.awt.AWTAutoShutdown;
    55.6  import sun.awt.SunToolkit;
    55.7 +import sun.awt.AppContext;
    55.8  
    55.9 -import java.util.Vector;
   55.10 +import java.util.ArrayList;
   55.11 +import java.util.List;
   55.12  import sun.util.logging.PlatformLogger;
   55.13  
   55.14  import sun.awt.dnd.SunDragSourceContextPeer;
   55.15 @@ -66,11 +68,11 @@
   55.16  
   55.17      private EventQueue theQueue;
   55.18      private boolean doDispatch = true;
   55.19 -    private boolean threadDeathCaught = false;
   55.20 +    private volatile boolean shutdown = false;
   55.21  
   55.22      private static final int ANY_EVENT = -1;
   55.23  
   55.24 -    private Vector<EventFilter> eventFilters = new Vector<EventFilter>();
   55.25 +    private ArrayList<EventFilter> eventFilters = new ArrayList<EventFilter>();
   55.26  
   55.27      EventDispatchThread(ThreadGroup group, String name, EventQueue queue) {
   55.28          super(group, name);
   55.29 @@ -84,6 +86,11 @@
   55.30          doDispatch = false;
   55.31      }
   55.32  
   55.33 +    public void interrupt() {
   55.34 +        shutdown = true;
   55.35 +        super.interrupt();
   55.36 +    }
   55.37 +
   55.38      public void run() {
   55.39          while (true) {
   55.40              try {
   55.41 @@ -93,8 +100,7 @@
   55.42                      }
   55.43                  });
   55.44              } finally {
   55.45 -                EventQueue eq = getEventQueue();
   55.46 -                if (eq.detachDispatchThread(this) || threadDeathCaught) {
   55.47 +                if(getEventQueue().detachDispatchThread(this, shutdown)) {
   55.48                      break;
   55.49                  }
   55.50              }
   55.51 @@ -124,10 +130,9 @@
   55.52      void pumpEventsForFilter(int id, Conditional cond, EventFilter filter) {
   55.53          addEventFilter(filter);
   55.54          doDispatch = true;
   55.55 -        while (doDispatch && cond.evaluate()) {
   55.56 -            if (isInterrupted() || !pumpOneEventForFilters(id)) {
   55.57 -                doDispatch = false;
   55.58 -            }
   55.59 +        shutdown |= isInterrupted();
   55.60 +        while (doDispatch && !shutdown && cond.evaluate()) {
   55.61 +            pumpOneEventForFilters(id);
   55.62          }
   55.63          removeEventFilter(filter);
   55.64      }
   55.65 @@ -163,7 +168,7 @@
   55.66          }
   55.67      }
   55.68  
   55.69 -    boolean pumpOneEventForFilters(int id) {
   55.70 +    void pumpOneEventForFilters(int id) {
   55.71          AWTEvent event = null;
   55.72          boolean eventOK = false;
   55.73          try {
   55.74 @@ -212,24 +217,18 @@
   55.75              if (delegate != null) {
   55.76                  delegate.afterDispatch(event, handle);
   55.77              }
   55.78 -
   55.79 -            return true;
   55.80          }
   55.81          catch (ThreadDeath death) {
   55.82 -            threadDeathCaught = true;
   55.83 -            return false;
   55.84 -
   55.85 +            shutdown = true;
   55.86 +            throw death;
   55.87          }
   55.88          catch (InterruptedException interruptedException) {
   55.89 -            return false; // AppContext.dispose() interrupts all
   55.90 -                          // Threads in the AppContext
   55.91 -
   55.92 +            shutdown = true; // AppContext.dispose() interrupts all
   55.93 +                             // Threads in the AppContext
   55.94          }
   55.95          catch (Throwable e) {
   55.96              processException(e);
   55.97          }
   55.98 -
   55.99 -        return true;
  55.100      }
  55.101  
  55.102      private void processException(Throwable e) {
    56.1 --- a/src/share/classes/java/awt/EventQueue.java	Fri Sep 30 17:20:56 2011 -0700
    56.2 +++ b/src/share/classes/java/awt/EventQueue.java	Tue Oct 04 12:39:42 2011 -0700
    56.3 @@ -47,6 +47,7 @@
    56.4  
    56.5  import java.util.concurrent.locks.Condition;
    56.6  import java.util.concurrent.locks.Lock;
    56.7 +import java.util.concurrent.atomic.AtomicInteger;
    56.8  
    56.9  import java.security.AccessControlContext;
   56.10  import java.security.ProtectionDomain;
   56.11 @@ -99,12 +100,7 @@
   56.12   * @since       1.1
   56.13   */
   56.14  public class EventQueue {
   56.15 -
   56.16 -    // From Thread.java
   56.17 -    private static int threadInitNumber;
   56.18 -    private static synchronized int nextThreadNum() {
   56.19 -        return threadInitNumber++;
   56.20 -    }
   56.21 +    private static final AtomicInteger threadInitNumber = new AtomicInteger(0);
   56.22  
   56.23      private static final int LOW_PRIORITY = 0;
   56.24      private static final int NORM_PRIORITY = 1;
   56.25 @@ -175,9 +171,9 @@
   56.26       * Non-zero if a thread is waiting in getNextEvent(int) for an event of
   56.27       * a particular ID to be posted to the queue.
   56.28       */
   56.29 -    private int waitForID;
   56.30 +    private volatile int waitForID;
   56.31  
   56.32 -    private final String name = "AWT-EventQueue-" + nextThreadNum();
   56.33 +    private final String name = "AWT-EventQueue-" + threadInitNumber.getAndIncrement();
   56.34  
   56.35      private static final PlatformLogger eventLog = PlatformLogger.getLogger("java.awt.event.EventQueue");
   56.36  
   56.37 @@ -1030,7 +1026,7 @@
   56.38          }
   56.39      }
   56.40  
   56.41 -    final boolean detachDispatchThread(EventDispatchThread edt) {
   56.42 +    final boolean detachDispatchThread(EventDispatchThread edt, boolean forceDetach) {
   56.43          /*
   56.44           * This synchronized block is to secure that the event dispatch
   56.45           * thread won't die in the middle of posting a new event to the
   56.46 @@ -1049,7 +1045,7 @@
   56.47                   * Fix for 4648733. Check both the associated java event
   56.48                   * queue and the PostEventQueue.
   56.49                   */
   56.50 -                if ((peekEvent() != null) || !SunToolkit.isPostEventQueueEmpty()) {
   56.51 +                if (!forceDetach && (peekEvent() != null) || !SunToolkit.isPostEventQueueEmpty()) {
   56.52                      return false;
   56.53                  }
   56.54                  dispatchThread = null;
    57.1 --- a/src/share/classes/java/io/FileInputStream.java	Fri Sep 30 17:20:56 2011 -0700
    57.2 +++ b/src/share/classes/java/io/FileInputStream.java	Tue Oct 04 12:39:42 2011 -0700
    57.3 @@ -56,16 +56,6 @@
    57.4      private final Object closeLock = new Object();
    57.5      private volatile boolean closed = false;
    57.6  
    57.7 -    private static final ThreadLocal<Boolean> runningFinalize =
    57.8 -        new ThreadLocal<>();
    57.9 -
   57.10 -    private static boolean isRunningFinalize() {
   57.11 -        Boolean val;
   57.12 -        if ((val = runningFinalize.get()) != null)
   57.13 -            return val.booleanValue();
   57.14 -        return false;
   57.15 -    }
   57.16 -
   57.17      /**
   57.18       * Creates a <code>FileInputStream</code> by
   57.19       * opening a connection to an actual file,
   57.20 @@ -319,10 +309,10 @@
   57.21          int useCount = fd.decrementAndGetUseCount();
   57.22  
   57.23          /*
   57.24 -         * If FileDescriptor is still in use by another stream, the finalizer
   57.25 +         * If FileDescriptor is still in use by another stream, we
   57.26           * will not close it.
   57.27           */
   57.28 -        if ((useCount <= 0) || !isRunningFinalize()) {
   57.29 +        if (useCount <= 0) {
   57.30              close0();
   57.31          }
   57.32      }
   57.33 @@ -391,18 +381,7 @@
   57.34       */
   57.35      protected void finalize() throws IOException {
   57.36          if ((fd != null) &&  (fd != FileDescriptor.in)) {
   57.37 -
   57.38 -            /*
   57.39 -             * Finalizer should not release the FileDescriptor if another
   57.40 -             * stream is still using it. If the user directly invokes
   57.41 -             * close() then the FileDescriptor is also released.
   57.42 -             */
   57.43 -            runningFinalize.set(Boolean.TRUE);
   57.44 -            try {
   57.45                  close();
   57.46 -            } finally {
   57.47 -                runningFinalize.set(Boolean.FALSE);
   57.48 -            }
   57.49          }
   57.50      }
   57.51  }
    58.1 --- a/src/share/classes/java/io/FileOutputStream.java	Fri Sep 30 17:20:56 2011 -0700
    58.2 +++ b/src/share/classes/java/io/FileOutputStream.java	Tue Oct 04 12:39:42 2011 -0700
    58.3 @@ -63,21 +63,12 @@
    58.4      private final boolean append;
    58.5  
    58.6      /**
    58.7 -     * The associated channel, initalized lazily.
    58.8 +     * The associated channel, initialized lazily.
    58.9       */
   58.10      private FileChannel channel;
   58.11  
   58.12      private final Object closeLock = new Object();
   58.13      private volatile boolean closed = false;
   58.14 -    private static final ThreadLocal<Boolean> runningFinalize =
   58.15 -        new ThreadLocal<>();
   58.16 -
   58.17 -    private static boolean isRunningFinalize() {
   58.18 -        Boolean val;
   58.19 -        if ((val = runningFinalize.get()) != null)
   58.20 -            return val.booleanValue();
   58.21 -        return false;
   58.22 -    }
   58.23  
   58.24      /**
   58.25       * Creates a file output stream to write to the file with the
   58.26 @@ -355,10 +346,10 @@
   58.27          int useCount = fd.decrementAndGetUseCount();
   58.28  
   58.29          /*
   58.30 -         * If FileDescriptor is still in use by another stream, the finalizer
   58.31 +         * If FileDescriptor is still in use by another stream, we
   58.32           * will not close it.
   58.33           */
   58.34 -        if ((useCount <= 0) || !isRunningFinalize()) {
   58.35 +        if (useCount <= 0) {
   58.36              close0();
   58.37          }
   58.38      }
   58.39 @@ -424,18 +415,7 @@
   58.40              if (fd == FileDescriptor.out || fd == FileDescriptor.err) {
   58.41                  flush();
   58.42              } else {
   58.43 -
   58.44 -                /*
   58.45 -                 * Finalizer should not release the FileDescriptor if another
   58.46 -                 * stream is still using it. If the user directly invokes
   58.47 -                 * close() then the FileDescriptor is also released.
   58.48 -                 */
   58.49 -                runningFinalize.set(Boolean.TRUE);
   58.50 -                try {
   58.51                      close();
   58.52 -                } finally {
   58.53 -                    runningFinalize.set(Boolean.FALSE);
   58.54 -                }
   58.55              }
   58.56          }
   58.57      }
    59.1 --- a/src/share/classes/java/io/RandomAccessFile.java	Fri Sep 30 17:20:56 2011 -0700
    59.2 +++ b/src/share/classes/java/io/RandomAccessFile.java	Tue Oct 04 12:39:42 2011 -0700
    59.3 @@ -1,5 +1,5 @@
    59.4  /*
    59.5 - * Copyright (c) 1994, 2007, Oracle and/or its affiliates. All rights reserved.
    59.6 + * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
    59.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    59.8   *
    59.9   * This code is free software; you can redistribute it and/or modify it
   59.10 @@ -590,8 +590,15 @@
   59.11           * Decrement FD use count associated with this stream.
   59.12           * The count got incremented by FileDescriptor during its construction.
   59.13           */
   59.14 -        fd.decrementAndGetUseCount();
   59.15 -        close0();
   59.16 +        int useCount = fd.decrementAndGetUseCount();
   59.17 +
   59.18 +        /*
   59.19 +         * If FileDescriptor is still in use by another stream, we
   59.20 +         * will not close it.
   59.21 +         */
   59.22 +        if (useCount <= 0) {
   59.23 +            close0();
   59.24 +        }
   59.25      }
   59.26  
   59.27      //
    60.1 --- a/src/share/classes/java/lang/Boolean.java	Fri Sep 30 17:20:56 2011 -0700
    60.2 +++ b/src/share/classes/java/lang/Boolean.java	Tue Oct 04 12:39:42 2011 -0700
    60.3 @@ -1,5 +1,5 @@
    60.4  /*
    60.5 - * Copyright (c) 1994, 2006, Oracle and/or its affiliates. All rights reserved.
    60.6 + * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
    60.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    60.8   *
    60.9   * This code is free software; you can redistribute it and/or modify it
   60.10 @@ -101,7 +101,7 @@
   60.11       * @param   s   the string to be converted to a {@code Boolean}.
   60.12       */
   60.13      public Boolean(String s) {
   60.14 -        this(toBoolean(s));
   60.15 +        this(parseBoolean(s));
   60.16      }
   60.17  
   60.18      /**
   60.19 @@ -118,7 +118,7 @@
   60.20       * @since 1.5
   60.21       */
   60.22      public static boolean parseBoolean(String s) {
   60.23 -        return toBoolean(s);
   60.24 +        return ((s != null) && s.equalsIgnoreCase("true"));
   60.25      }
   60.26  
   60.27      /**
   60.28 @@ -159,7 +159,7 @@
   60.29       * @return  the {@code Boolean} value represented by the string.
   60.30       */
   60.31      public static Boolean valueOf(String s) {
   60.32 -        return toBoolean(s) ? TRUE : FALSE;
   60.33 +        return parseBoolean(s) ? TRUE : FALSE;
   60.34      }
   60.35  
   60.36      /**
   60.37 @@ -229,15 +229,16 @@
   60.38       *
   60.39       * @param   name   the system property name.
   60.40       * @return  the {@code boolean} value of the system property.
   60.41 +     * @throws  SecurityException for the same reasons as
   60.42 +     *          {@link System#getProperty(String) System.getProperty}
   60.43       * @see     java.lang.System#getProperty(java.lang.String)
   60.44       * @see     java.lang.System#getProperty(java.lang.String, java.lang.String)
   60.45       */
   60.46      public static boolean getBoolean(String name) {
   60.47          boolean result = false;
   60.48          try {
   60.49 -            result = toBoolean(System.getProperty(name));
   60.50 -        } catch (IllegalArgumentException e) {
   60.51 -        } catch (NullPointerException e) {
   60.52 +            result = parseBoolean(System.getProperty(name));
   60.53 +        } catch (IllegalArgumentException | NullPointerException e) {
   60.54          }
   60.55          return result;
   60.56      }
   60.57 @@ -275,8 +276,4 @@
   60.58      public static int compare(boolean x, boolean y) {
   60.59          return (x == y) ? 0 : (x ? 1 : -1);
   60.60      }
   60.61 -
   60.62 -    private static boolean toBoolean(String name) {
   60.63 -        return ((name != null) && name.equalsIgnoreCase("true"));
   60.64 -    }
   60.65  }
    61.1 --- a/src/share/classes/java/lang/Double.java	Fri Sep 30 17:20:56 2011 -0700
    61.2 +++ b/src/share/classes/java/lang/Double.java	Tue Oct 04 12:39:42 2011 -0700
    61.3 @@ -276,14 +276,14 @@
    61.4           * 7.19.6.1; however, the output of this method is more
    61.5           * tightly specified.
    61.6           */
    61.7 -        if (!FpUtils.isFinite(d) )
    61.8 +        if (!isFinite(d) )
    61.9              // For infinity and NaN, use the decimal output.
   61.10              return Double.toString(d);
   61.11          else {
   61.12              // Initialized to maximum size of output.
   61.13              StringBuffer answer = new StringBuffer(24);
   61.14  
   61.15 -            if (FpUtils.rawCopySign(1.0, d) == -1.0) // value is negative,
   61.16 +            if (Math.copySign(1.0, d) == -1.0)    // value is negative,
   61.17                  answer.append("-");                  // so append sign info
   61.18  
   61.19              answer.append("0x");
   61.20 @@ -322,7 +322,7 @@
   61.21                  // E_min -1).
   61.22                  answer.append("p" + (subnormal ?
   61.23                                 DoubleConsts.MIN_EXPONENT:
   61.24 -                               FpUtils.getExponent(d) ));
   61.25 +                               Math.getExponent(d) ));
   61.26              }
   61.27              return answer.toString();
   61.28          }
   61.29 @@ -548,7 +548,7 @@
   61.30       * @return  {@code true} if the value of the argument is NaN;
   61.31       *          {@code false} otherwise.
   61.32       */
   61.33 -    static public boolean isNaN(double v) {
   61.34 +    public static boolean isNaN(double v) {
   61.35          return (v != v);
   61.36      }
   61.37  
   61.38 @@ -560,11 +560,25 @@
   61.39       * @return  {@code true} if the value of the argument is positive
   61.40       *          infinity or negative infinity; {@code false} otherwise.
   61.41       */
   61.42 -    static public boolean isInfinite(double v) {
   61.43 +    public static boolean isInfinite(double v) {
   61.44          return (v == POSITIVE_INFINITY) || (v == NEGATIVE_INFINITY);
   61.45      }
   61.46  
   61.47      /**
   61.48 +     * Returns {@code true} if the argument is a finite floating-point
   61.49 +     * value; returns {@code false} otherwise (for NaN and infinity
   61.50 +     * arguments).
   61.51 +     *
   61.52 +     * @param d the {@code double} value to be tested
   61.53 +     * @return {@code true} if the argument is a finite
   61.54 +     * floating-point value, {@code false} otherwise.
   61.55 +     * @since 1.8
   61.56 +     */
   61.57 +    public static boolean isFinite(double d) {
   61.58 +        return Math.abs(d) <= DoubleConsts.MAX_VALUE;
   61.59 +    }
   61.60 +
   61.61 +    /**
   61.62       * The value of the Double.
   61.63       *
   61.64       * @serial
    62.1 --- a/src/share/classes/java/lang/Float.java	Fri Sep 30 17:20:56 2011 -0700
    62.2 +++ b/src/share/classes/java/lang/Float.java	Tue Oct 04 12:39:42 2011 -0700
    62.3 @@ -26,7 +26,6 @@
    62.4  package java.lang;
    62.5  
    62.6  import sun.misc.FloatingDecimal;
    62.7 -import sun.misc.FpUtils;
    62.8  import sun.misc.FloatConsts;
    62.9  import sun.misc.DoubleConsts;
   62.10  
   62.11 @@ -279,10 +278,10 @@
   62.12              // Adjust exponent to create subnormal double, then
   62.13              // replace subnormal double exponent with subnormal float
   62.14              // exponent
   62.15 -            String s = Double.toHexString(FpUtils.scalb((double)f,
   62.16 -                                                        /* -1022+126 */
   62.17 -                                                        DoubleConsts.MIN_EXPONENT-
   62.18 -                                                        FloatConsts.MIN_EXPONENT));
   62.19 +            String s = Double.toHexString(Math.scalb((double)f,
   62.20 +                                                     /* -1022+126 */
   62.21 +                                                     DoubleConsts.MIN_EXPONENT-
   62.22 +                                                     FloatConsts.MIN_EXPONENT));
   62.23              return s.replaceFirst("p-1022$", "p-126");
   62.24          }
   62.25          else // double string will be the same as float string
   62.26 @@ -460,7 +459,7 @@
   62.27       * @return  {@code true} if the argument is NaN;
   62.28       *          {@code false} otherwise.
   62.29       */
   62.30 -    static public boolean isNaN(float v) {
   62.31 +    public static boolean isNaN(float v) {
   62.32          return (v != v);
   62.33      }
   62.34  
   62.35 @@ -472,10 +471,25 @@
   62.36       * @return  {@code true} if the argument is positive infinity or
   62.37       *          negative infinity; {@code false} otherwise.
   62.38       */
   62.39 -    static public boolean isInfinite(float v) {
   62.40 +    public static boolean isInfinite(float v) {
   62.41          return (v == POSITIVE_INFINITY) || (v == NEGATIVE_INFINITY);
   62.42      }
   62.43  
   62.44 +
   62.45 +    /**
   62.46 +     * Returns {@code true} if the argument is a finite floating-point
   62.47 +     * value; returns {@code false} otherwise (for NaN and infinity
   62.48 +     * arguments).
   62.49 +     *
   62.50 +     * @param f the {@code float} value to be tested
   62.51 +     * @return {@code true} if the argument is a finite
   62.52 +     * floating-point value, {@code false} otherwise.
   62.53 +     * @since 1.8
   62.54 +     */
   62.55 +     public static boolean isFinite(float f) {
   62.56 +        return Math.abs(f) <= FloatConsts.MAX_VALUE;
   62.57 +    }
   62.58 +
   62.59      /**
   62.60       * The value of the Float.
   62.61       *
    63.1 --- a/src/share/classes/java/lang/Integer.java	Fri Sep 30 17:20:56 2011 -0700
    63.2 +++ b/src/share/classes/java/lang/Integer.java	Tue Oct 04 12:39:42 2011 -0700
    63.3 @@ -797,6 +797,8 @@
    63.4       *
    63.5       * @param   nm   property name.
    63.6       * @return  the {@code Integer} value of the property.
    63.7 +     * @throws  SecurityException for the same reasons as
    63.8 +     *          {@link System#getProperty(String) System.getProperty}
    63.9       * @see     java.lang.System#getProperty(java.lang.String)
   63.10       * @see     java.lang.System#getProperty(java.lang.String, java.lang.String)
   63.11       */
   63.12 @@ -841,6 +843,8 @@
   63.13       * @param   nm   property name.
   63.14       * @param   val   default value.
   63.15       * @return  the {@code Integer} value of the property.
   63.16 +     * @throws  SecurityException for the same reasons as
   63.17 +     *          {@link System#getProperty(String) System.getProperty}
   63.18       * @see     java.lang.System#getProperty(java.lang.String)
   63.19       * @see     java.lang.System#getProperty(java.lang.String, java.lang.String)
   63.20       */
   63.21 @@ -881,6 +885,8 @@
   63.22       * @param   nm   property name.
   63.23       * @param   val   default value.
   63.24       * @return  the {@code Integer} value of the property.
   63.25 +     * @throws  SecurityException for the same reasons as
   63.26 +     *          {@link System#getProperty(String) System.getProperty}
   63.27       * @see     System#getProperty(java.lang.String)
   63.28       * @see     System#getProperty(java.lang.String, java.lang.String)
   63.29       */
    64.1 --- a/src/share/classes/java/lang/Long.java	Fri Sep 30 17:20:56 2011 -0700
    64.2 +++ b/src/share/classes/java/lang/Long.java	Tue Oct 04 12:39:42 2011 -0700
    64.3 @@ -827,6 +827,8 @@
    64.4       *
    64.5       * @param   nm   property name.
    64.6       * @return  the {@code Long} value of the property.
    64.7 +     * @throws  SecurityException for the same reasons as
    64.8 +     *          {@link System#getProperty(String) System.getProperty}
    64.9       * @see     java.lang.System#getProperty(java.lang.String)
   64.10       * @see     java.lang.System#getProperty(java.lang.String, java.lang.String)
   64.11       */
   64.12 @@ -870,6 +872,8 @@
   64.13       * @param   nm    property name.
   64.14       * @param   val   default value.
   64.15       * @return  the {@code Long} value of the property.
   64.16 +     * @throws  SecurityException for the same reasons as
   64.17 +     *          {@link System#getProperty(String) System.getProperty}
   64.18       * @see     java.lang.System#getProperty(java.lang.String)
   64.19       * @see     java.lang.System#getProperty(java.lang.String, java.lang.String)
   64.20       */
   64.21 @@ -917,6 +921,8 @@
   64.22       * @param   nm   property name.
   64.23       * @param   val   default value.
   64.24       * @return  the {@code Long} value of the property.
   64.25 +     * @throws  SecurityException for the same reasons as
   64.26 +     *          {@link System#getProperty(String) System.getProperty}
   64.27       * @see     System#getProperty(java.lang.String)
   64.28       * @see     System#getProperty(java.lang.String, java.lang.String)
   64.29       */
    65.1 --- a/src/share/classes/java/lang/Math.java	Fri Sep 30 17:20:56 2011 -0700
    65.2 +++ b/src/share/classes/java/lang/Math.java	Tue Oct 04 12:39:42 2011 -0700
    65.3 @@ -26,6 +26,8 @@
    65.4  package java.lang;
    65.5  import java.util.Random;
    65.6  
    65.7 +import sun.misc.FloatConsts;
    65.8 +import sun.misc.DoubleConsts;
    65.9  
   65.10  /**
   65.11   * The class {@code Math} contains methods for performing basic
   65.12 @@ -963,7 +965,31 @@
   65.13       * @since 1.5
   65.14       */
   65.15      public static double ulp(double d) {
   65.16 -        return sun.misc.FpUtils.ulp(d);
   65.17 +        int exp = getExponent(d);
   65.18 +
   65.19 +        switch(exp) {
   65.20 +        case DoubleConsts.MAX_EXPONENT+1:       // NaN or infinity
   65.21 +            return Math.abs(d);
   65.22 +
   65.23 +        case DoubleConsts.MIN_EXPONENT-1:       // zero or subnormal
   65.24 +            return Double.MIN_VALUE;
   65.25 +
   65.26 +        default:
   65.27 +            assert exp <= DoubleConsts.MAX_EXPONENT && exp >= DoubleConsts.MIN_EXPONENT;
   65.28 +
   65.29 +            // ulp(x) is usually 2^(SIGNIFICAND_WIDTH-1)*(2^ilogb(x))
   65.30 +            exp = exp - (DoubleConsts.SIGNIFICAND_WIDTH-1);
   65.31 +            if (exp >= DoubleConsts.MIN_EXPONENT) {
   65.32 +                return powerOfTwoD(exp);
   65.33 +            }
   65.34 +            else {
   65.35 +                // return a subnormal result; left shift integer
   65.36 +                // representation of Double.MIN_VALUE appropriate
   65.37 +                // number of positions
   65.38 +                return Double.longBitsToDouble(1L <<
   65.39 +                (exp - (DoubleConsts.MIN_EXPONENT - (DoubleConsts.SIGNIFICAND_WIDTH-1)) ));
   65.40 +            }
   65.41 +        }
   65.42      }
   65.43  
   65.44      /**
   65.45 @@ -990,7 +1016,31 @@
   65.46       * @since 1.5
   65.47       */
   65.48      public static float ulp(float f) {
   65.49 -        return sun.misc.FpUtils.ulp(f);
   65.50 +        int exp = getExponent(f);
   65.51 +
   65.52 +        switch(exp) {
   65.53 +        case FloatConsts.MAX_EXPONENT+1:        // NaN or infinity
   65.54 +            return Math.abs(f);
   65.55 +
   65.56 +        case FloatConsts.MIN_EXPONENT-1:        // zero or subnormal
   65.57 +            return FloatConsts.MIN_VALUE;
   65.58 +
   65.59 +        default:
   65.60 +            assert exp <= FloatConsts.MAX_EXPONENT && exp >= FloatConsts.MIN_EXPONENT;
   65.61 +
   65.62 +            // ulp(x) is usually 2^(SIGNIFICAND_WIDTH-1)*(2^ilogb(x))
   65.63 +            exp = exp - (FloatConsts.SIGNIFICAND_WIDTH-1);
   65.64 +            if (exp >= FloatConsts.MIN_EXPONENT) {
   65.65 +                return powerOfTwoF(exp);
   65.66 +            }
   65.67 +            else {
   65.68 +                // return a subnormal result; left shift integer
   65.69 +                // representation of FloatConsts.MIN_VALUE appropriate
   65.70 +                // number of positions
   65.71 +                return Float.intBitsToFloat(1 <<
   65.72 +                (exp - (FloatConsts.MIN_EXPONENT - (FloatConsts.SIGNIFICAND_WIDTH-1)) ));
   65.73 +            }
   65.74 +        }
   65.75      }
   65.76  
   65.77      /**
   65.78 @@ -1011,7 +1061,7 @@
   65.79       * @since 1.5
   65.80       */
   65.81      public static double signum(double d) {
   65.82 -        return sun.misc.FpUtils.signum(d);
   65.83 +        return (d == 0.0 || Double.isNaN(d))?d:copySign(1.0, d);
   65.84      }
   65.85  
   65.86      /**
   65.87 @@ -1032,7 +1082,7 @@
   65.88       * @since 1.5
   65.89       */
   65.90      public static float signum(float f) {
   65.91 -        return sun.misc.FpUtils.signum(f);
   65.92 +        return (f == 0.0f || Float.isNaN(f))?f:copySign(1.0f, f);
   65.93      }
   65.94  
   65.95      /**
   65.96 @@ -1252,7 +1302,11 @@
   65.97       * @since 1.6
   65.98       */
   65.99      public static double copySign(double magnitude, double sign) {
  65.100 -        return sun.misc.FpUtils.rawCopySign(magnitude, sign);
  65.101 +        return Double.longBitsToDouble((Double.doubleToRawLongBits(sign) &
  65.102 +                                        (DoubleConsts.SIGN_BIT_MASK)) |
  65.103 +                                       (Double.doubleToRawLongBits(magnitude) &
  65.104 +                                        (DoubleConsts.EXP_BIT_MASK |
  65.105 +                                         DoubleConsts.SIGNIF_BIT_MASK)));
  65.106      }
  65.107  
  65.108      /**
  65.109 @@ -1271,7 +1325,11 @@
  65.110       * @since 1.6
  65.111       */
  65.112      public static float copySign(float magnitude, float sign) {
  65.113 -        return sun.misc.FpUtils.rawCopySign(magnitude, sign);
  65.114 +        return Float.intBitsToFloat((Float.floatToRawIntBits(sign) &
  65.115 +                                     (FloatConsts.SIGN_BIT_MASK)) |
  65.116 +                                    (Float.floatToRawIntBits(magnitude) &
  65.117 +                                     (FloatConsts.EXP_BIT_MASK |
  65.118 +                                      FloatConsts.SIGNIF_BIT_MASK)));
  65.119      }
  65.120  
  65.121      /**
  65.122 @@ -1289,7 +1347,13 @@
  65.123       * @since 1.6
  65.124       */
  65.125      public static int getExponent(float f) {
  65.126 -        return sun.misc.FpUtils.getExponent(f);
  65.127 +        /*
  65.128 +         * Bitwise convert f to integer, mask out exponent bits, shift
  65.129 +         * to the right and then subtract out float's bias adjust to
  65.130 +         * get true exponent value
  65.131 +         */
  65.132 +        return ((Float.floatToRawIntBits(f) & FloatConsts.EXP_BIT_MASK) >>
  65.133 +                (FloatConsts.SIGNIFICAND_WIDTH - 1)) - FloatConsts.EXP_BIAS;
  65.134      }
  65.135  
  65.136      /**
  65.137 @@ -1307,7 +1371,13 @@
  65.138       * @since 1.6
  65.139       */
  65.140      public static int getExponent(double d) {
  65.141 -        return sun.misc.FpUtils.getExponent(d);
  65.142 +        /*
  65.143 +         * Bitwise convert d to long, mask out exponent bits, shift
  65.144 +         * to the right and then subtract out double's bias adjust to
  65.145 +         * get true exponent value.
  65.146 +         */
  65.147 +        return (int)(((Double.doubleToRawLongBits(d) & DoubleConsts.EXP_BIT_MASK) >>
  65.148 +                      (DoubleConsts.SIGNIFICAND_WIDTH - 1)) - DoubleConsts.EXP_BIAS);
  65.149      }
  65.150  
  65.151      /**
  65.152 @@ -1351,7 +1421,63 @@
  65.153       * @since 1.6
  65.154       */
  65.155      public static double nextAfter(double start, double direction) {
  65.156 -        return sun.misc.FpUtils.nextAfter(start, direction);
  65.157 +        /*
  65.158 +         * The cases:
  65.159 +         *
  65.160 +         * nextAfter(+infinity, 0)  == MAX_VALUE
  65.161 +         * nextAfter(+infinity, +infinity)  == +infinity
  65.162 +         * nextAfter(-infinity, 0)  == -MAX_VALUE
  65.163 +         * nextAfter(-infinity, -infinity)  == -infinity
  65.164 +         *
  65.165 +         * are naturally handled without any additional testing
  65.166 +         */
  65.167 +
  65.168 +        // First check for NaN values
  65.169 +        if (Double.isNaN(start) || Double.isNaN(direction)) {
  65.170 +            // return a NaN derived from the input NaN(s)
  65.171 +            return start + direction;
  65.172 +        } else if (start == direction) {
  65.173 +            return direction;
  65.174 +        } else {        // start > direction or start < direction
  65.175 +            // Add +0.0 to get rid of a -0.0 (+0.0 + -0.0 => +0.0)
  65.176 +            // then bitwise convert start to integer.
  65.177 +            long transducer = Double.doubleToRawLongBits(start + 0.0d);
  65.178 +
  65.179 +            /*
  65.180 +             * IEEE 754 floating-point numbers are lexicographically
  65.181 +             * ordered if treated as signed- magnitude integers .
  65.182 +             * Since Java's integers are two's complement,
  65.183 +             * incrementing" the two's complement representation of a
  65.184 +             * logically negative floating-point value *decrements*
  65.185 +             * the signed-magnitude representation. Therefore, when
  65.186 +             * the integer representation of a floating-point values
  65.187 +             * is less than zero, the adjustment to the representation
  65.188 +             * is in the opposite direction than would be expected at
  65.189 +             * first .
  65.190 +             */
  65.191 +            if (direction > start) { // Calculate next greater value
  65.192 +                transducer = transducer + (transducer >= 0L ? 1L:-1L);
  65.193 +            } else  { // Calculate next lesser value
  65.194 +                assert direction < start;
  65.195 +                if (transducer > 0L)
  65.196 +                    --transducer;
  65.197 +                else
  65.198 +                    if (transducer < 0L )
  65.199 +                        ++transducer;
  65.200 +                    /*
  65.201 +                     * transducer==0, the result is -MIN_VALUE
  65.202 +                     *
  65.203 +                     * The transition from zero (implicitly
  65.204 +                     * positive) to the smallest negative
  65.205 +                     * signed magnitude value must be done
  65.206 +                     * explicitly.
  65.207 +                     */
  65.208 +                    else
  65.209 +                        transducer = DoubleConsts.SIGN_BIT_MASK | 1L;
  65.210 +            }
  65.211 +
  65.212 +            return Double.longBitsToDouble(transducer);
  65.213 +        }
  65.214      }
  65.215  
  65.216      /**
  65.217 @@ -1394,7 +1520,63 @@
  65.218       * @since 1.6
  65.219       */
  65.220      public static float nextAfter(float start, double direction) {
  65.221 -        return sun.misc.FpUtils.nextAfter(start, direction);
  65.222 +        /*
  65.223 +         * The cases:
  65.224 +         *
  65.225 +         * nextAfter(+infinity, 0)  == MAX_VALUE
  65.226 +         * nextAfter(+infinity, +infinity)  == +infinity
  65.227 +         * nextAfter(-infinity, 0)  == -MAX_VALUE
  65.228 +         * nextAfter(-infinity, -infinity)  == -infinity
  65.229 +         *
  65.230 +         * are naturally handled without any additional testing
  65.231 +         */
  65.232 +
  65.233 +        // First check for NaN values
  65.234 +        if (Float.isNaN(start) || Double.isNaN(direction)) {
  65.235 +            // return a NaN derived from the input NaN(s)
  65.236 +            return start + (float)direction;
  65.237 +        } else if (start == direction) {
  65.238 +            return (float)direction;
  65.239 +        } else {        // start > direction or start < direction
  65.240 +            // Add +0.0 to get rid of a -0.0 (+0.0 + -0.0 => +0.0)
  65.241 +            // then bitwise convert start to integer.
  65.242 +            int transducer = Float.floatToRawIntBits(start + 0.0f);
  65.243 +
  65.244 +            /*
  65.245 +             * IEEE 754 floating-point numbers are lexicographically
  65.246 +             * ordered if treated as signed- magnitude integers .
  65.247 +             * Since Java's integers are two's complement,
  65.248 +             * incrementing" the two's complement representation of a
  65.249 +             * logically negative floating-point value *decrements*
  65.250 +             * the signed-magnitude representation. Therefore, when
  65.251 +             * the integer representation of a floating-point values
  65.252 +             * is less than zero, the adjustment to the representation
  65.253 +             * is in the opposite direction than would be expected at
  65.254 +             * first.
  65.255 +             */
  65.256 +            if (direction > start) {// Calculate next greater value
  65.257 +                transducer = transducer + (transducer >= 0 ? 1:-1);
  65.258 +            } else  { // Calculate next lesser value
  65.259 +                assert direction < start;
  65.260 +                if (transducer > 0)
  65.261 +                    --transducer;
  65.262 +                else
  65.263 +                    if (transducer < 0 )
  65.264 +                        ++transducer;
  65.265 +                    /*
  65.266 +                     * transducer==0, the result is -MIN_VALUE
  65.267 +                     *
  65.268 +                     * The transition from zero (implicitly
  65.269 +                     * positive) to the smallest negative
  65.270 +                     * signed magnitude value must be done
  65.271 +                     * explicitly.
  65.272 +                     */
  65.273 +                    else
  65.274 +                        transducer = FloatConsts.SIGN_BIT_MASK | 1;
  65.275 +            }
  65.276 +
  65.277 +            return Float.intBitsToFloat(transducer);
  65.278 +        }
  65.279      }
  65.280  
  65.281      /**
  65.282 @@ -1423,7 +1605,13 @@
  65.283       * @since 1.6
  65.284       */
  65.285      public static double nextUp(double d) {
  65.286 -        return sun.misc.FpUtils.nextUp(d);
  65.287 +        if( Double.isNaN(d) || d == Double.POSITIVE_INFINITY)
  65.288 +            return d;
  65.289 +        else {
  65.290 +            d += 0.0d;
  65.291 +            return Double.longBitsToDouble(Double.doubleToRawLongBits(d) +
  65.292 +                                           ((d >= 0.0d)?+1L:-1L));
  65.293 +        }
  65.294      }
  65.295  
  65.296      /**
  65.297 @@ -1452,9 +1640,88 @@
  65.298       * @since 1.6
  65.299       */
  65.300      public static float nextUp(float f) {
  65.301 -        return sun.misc.FpUtils.nextUp(f);
  65.302 +        if( Float.isNaN(f) || f == FloatConsts.POSITIVE_INFINITY)
  65.303 +            return f;
  65.304 +        else {
  65.305 +            f += 0.0f;
  65.306 +            return Float.intBitsToFloat(Float.floatToRawIntBits(f) +
  65.307 +                                        ((f >= 0.0f)?+1:-1));
  65.308 +        }
  65.309      }
  65.310  
  65.311 +    /**
  65.312 +     * Returns the floating-point value adjacent to {@code d} in
  65.313 +     * the direction of negative infinity.  This method is
  65.314 +     * semantically equivalent to {@code nextAfter(d,
  65.315 +     * Double.NEGATIVE_INFINITY)}; however, a
  65.316 +     * {@code nextDown} implementation may run faster than its
  65.317 +     * equivalent {@code nextAfter} call.
  65.318 +     *
  65.319 +     * <p>Special Cases:
  65.320 +     * <ul>
  65.321 +     * <li> If the argument is NaN, the result is NaN.
  65.322 +     *
  65.323 +     * <li> If the argument is negative infinity, the result is
  65.324 +     * negative infinity.
  65.325 +     *
  65.326 +     * <li> If the argument is zero, the result is
  65.327 +     * {@code -Double.MIN_VALUE}
  65.328 +     *
  65.329 +     * </ul>
  65.330 +     *
  65.331 +     * @param d  starting floating-point value
  65.332 +     * @return The adjacent floating-point value closer to negative
  65.333 +     * infinity.
  65.334 +     * @since 1.8
  65.335 +     */
  65.336 +    public static double nextDown(double d) {
  65.337 +        if (Double.isNaN(d) || d == Double.NEGATIVE_INFINITY)
  65.338 +            return d;
  65.339 +        else {
  65.340 +            if (d == 0.0)
  65.341 +                return -Double.MIN_VALUE;
  65.342 +            else
  65.343 +                return Double.longBitsToDouble(Double.doubleToRawLongBits(d) +
  65.344 +                                               ((d > 0.0d)?-1L:+1L));
  65.345 +        }
  65.346 +    }
  65.347 +
  65.348 +    /**
  65.349 +     * Returns the floating-point value adjacent to {@code f} in
  65.350 +     * the direction of negative infinity.  This method is
  65.351 +     * semantically equivalent to {@code nextAfter(f,
  65.352 +     * Float.NEGATIVE_INFINITY)}; however, a
  65.353 +     * {@code nextDown} implementation may run faster than its
  65.354 +     * equivalent {@code nextAfter} call.
  65.355 +     *
  65.356 +     * <p>Special Cases:
  65.357 +     * <ul>
  65.358 +     * <li> If the argument is NaN, the result is NaN.
  65.359 +     *
  65.360 +     * <li> If the argument is negative infinity, the result is
  65.361 +     * negative infinity.
  65.362 +     *
  65.363 +     * <li> If the argument is zero, the result is
  65.364 +     * {@code -Float.MIN_VALUE}
  65.365 +     *
  65.366 +     * </ul>
  65.367 +     *
  65.368 +     * @param f  starting floating-point value
  65.369 +     * @return The adjacent floating-point value closer to negative
  65.370 +     * infinity.
  65.371 +     * @since 1.8
  65.372 +     */
  65.373 +    public static float nextDown(float f) {
  65.374 +        if (Float.isNaN(f) || f == Float.NEGATIVE_INFINITY)
  65.375 +            return f;
  65.376 +        else {
  65.377 +            if (f == 0.0f)
  65.378 +                return -Float.MIN_VALUE;
  65.379 +            else
  65.380 +                return Float.intBitsToFloat(Float.floatToRawIntBits(f) +
  65.381 +                                            ((f > 0.0f)?-1:+1));
  65.382 +        }
  65.383 +    }
  65.384  
  65.385      /**
  65.386       * Return {@code d} &times;
  65.387 @@ -1487,7 +1754,80 @@
  65.388       * @since 1.6
  65.389       */
  65.390      public static double scalb(double d, int scaleFactor) {
  65.391 -        return sun.misc.FpUtils.scalb(d, scaleFactor);
  65.392 +        /*
  65.393 +         * This method does not need to be declared strictfp to
  65.394 +         * compute the same correct result on all platforms.  When
  65.395 +         * scaling up, it does not matter what order the
  65.396 +         * multiply-store operations are done; the result will be
  65.397 +         * finite or overflow regardless of the operation ordering.
  65.398 +         * However, to get the correct result when scaling down, a
  65.399 +         * particular ordering must be used.
  65.400 +         *
  65.401 +         * When scaling down, the multiply-store operations are
  65.402 +         * sequenced so that it is not possible for two consecutive
  65.403 +         * multiply-stores to return subnormal results.  If one
  65.404 +         * multiply-store result is subnormal, the next multiply will
  65.405 +         * round it away to zero.  This is done by first multiplying
  65.406 +         * by 2 ^ (scaleFactor % n) and then multiplying several
  65.407 +         * times by by 2^n as needed where n is the exponent of number
  65.408 +         * that is a covenient power of two.  In this way, at most one
  65.409 +         * real rounding error occurs.  If the double value set is
  65.410 +         * being used exclusively, the rounding will occur on a
  65.411 +         * multiply.  If the double-extended-exponent value set is
  65.412 +         * being used, the products will (perhaps) be exact but the
  65.413 +         * stores to d are guaranteed to round to the double value
  65.414 +         * set.
  65.415 +         *
  65.416 +         * It is _not_ a valid implementation to first multiply d by
  65.417 +         * 2^MIN_EXPONENT and then by 2 ^ (scaleFactor %
  65.418 +         * MIN_EXPONENT) since even in a strictfp program double
  65.419 +         * rounding on underflow could occur; e.g. if the scaleFactor
  65.420 +         * argument was (MIN_EXPONENT - n) and the exponent of d was a
  65.421 +         * little less than -(MIN_EXPONENT - n), meaning the final
  65.422 +         * result would be subnormal.
  65.423 +         *
  65.424 +         * Since exact reproducibility of this method can be achieved
  65.425 +         * without any undue performance burden, there is no
  65.426 +         * compelling reason to allow double rounding on underflow in
  65.427 +         * scalb.
  65.428 +         */
  65.429 +
  65.430 +        // magnitude of a power of two so large that scaling a finite
  65.431 +        // nonzero value by it would be guaranteed to over or
  65.432 +        // underflow; due to rounding, scaling down takes takes an
  65.433 +        // additional power of two which is reflected here
  65.434 +        final int MAX_SCALE = DoubleConsts.MAX_EXPONENT + -DoubleConsts.MIN_EXPONENT +
  65.435 +                              DoubleConsts.SIGNIFICAND_WIDTH + 1;
  65.436 +        int exp_adjust = 0;
  65.437 +        int scale_increment = 0;
  65.438 +        double exp_delta = Double.NaN;
  65.439 +
  65.440 +        // Make sure scaling factor is in a reasonable range
  65.441 +
  65.442 +        if(scaleFactor < 0) {
  65.443 +            scaleFactor = Math.max(scaleFactor, -MAX_SCALE);
  65.444 +            scale_increment = -512;
  65.445 +            exp_delta = twoToTheDoubleScaleDown;
  65.446 +        }
  65.447 +        else {
  65.448 +            scaleFactor = Math.min(scaleFactor, MAX_SCALE);
  65.449 +            scale_increment = 512;
  65.450 +            exp_delta = twoToTheDoubleScaleUp;
  65.451 +        }
  65.452 +
  65.453 +        // Calculate (scaleFactor % +/-512), 512 = 2^9, using
  65.454 +        // technique from "Hacker's Delight" section 10-2.
  65.455 +        int t = (scaleFactor >> 9-1) >>> 32 - 9;
  65.456 +        exp_adjust = ((scaleFactor + t) & (512 -1)) - t;
  65.457 +
  65.458 +        d *= powerOfTwoD(exp_adjust);
  65.459 +        scaleFactor -= exp_adjust;
  65.460 +
  65.461 +        while(scaleFactor != 0) {
  65.462 +            d *= exp_delta;
  65.463 +            scaleFactor -= scale_increment;
  65.464 +        }
  65.465 +        return d;
  65.466      }
  65.467  
  65.468      /**
  65.469 @@ -1521,6 +1861,49 @@
  65.470       * @since 1.6
  65.471       */
  65.472      public static float scalb(float f, int scaleFactor) {
  65.473 -        return sun.misc.FpUtils.scalb(f, scaleFactor);
  65.474 +        // magnitude of a power of two so large that scaling a finite
  65.475 +        // nonzero value by it would be guaranteed to over or
  65.476 +        // underflow; due to rounding, scaling down takes takes an
  65.477 +        // additional power of two which is reflected here
  65.478 +        final int MAX_SCALE = FloatConsts.MAX_EXPONENT + -FloatConsts.MIN_EXPONENT +
  65.479 +                              FloatConsts.SIGNIFICAND_WIDTH + 1;
  65.480 +
  65.481 +        // Make sure scaling factor is in a reasonable range
  65.482 +        scaleFactor = Math.max(Math.min(scaleFactor, MAX_SCALE), -MAX_SCALE);
  65.483 +
  65.484 +        /*
  65.485 +         * Since + MAX_SCALE for float fits well within the double
  65.486 +         * exponent range and + float -> double conversion is exact
  65.487 +         * the multiplication below will be exact. Therefore, the
  65.488 +         * rounding that occurs when the double product is cast to
  65.489 +         * float will be the correctly rounded float result.  Since
  65.490 +         * all operations other than the final multiply will be exact,
  65.491 +         * it is not necessary to declare this method strictfp.
  65.492 +         */
  65.493 +        return (float)((double)f*powerOfTwoD(scaleFactor));
  65.494 +    }
  65.495 +
  65.496 +    // Constants used in scalb
  65.497 +    static double twoToTheDoubleScaleUp = powerOfTwoD(512);
  65.498 +    static double twoToTheDoubleScaleDown = powerOfTwoD(-512);
  65.499 +
  65.500 +    /**
  65.501 +     * Returns a floating-point power of two in the normal range.
  65.502 +     */
  65.503 +    static double powerOfTwoD(int n) {
  65.504 +        assert(n >= DoubleConsts.MIN_EXPONENT && n <= DoubleConsts.MAX_EXPONENT);
  65.505 +        return Double.longBitsToDouble((((long)n + (long)DoubleConsts.EXP_BIAS) <<
  65.506 +                                        (DoubleConsts.SIGNIFICAND_WIDTH-1))
  65.507 +                                       & DoubleConsts.EXP_BIT_MASK);
  65.508 +    }
  65.509 +
  65.510 +    /**
  65.511 +     * Returns a floating-point power of two in the normal range.
  65.512 +     */
  65.513 +    public static float powerOfTwoF(int n) {
  65.514 +        assert(n >= FloatConsts.MIN_EXPONENT && n <= FloatConsts.MAX_EXPONENT);
  65.515 +        return Float.intBitsToFloat(((n + FloatConsts.EXP_BIAS) <<
  65.516 +                                     (FloatConsts.SIGNIFICAND_WIDTH-1))
  65.517 +                                    & FloatConsts.EXP_BIT_MASK);
  65.518      }
  65.519  }
    66.1 --- a/src/share/classes/java/lang/SafeVarargs.java	Fri Sep 30 17:20:56 2011 -0700
    66.2 +++ b/src/share/classes/java/lang/SafeVarargs.java	Tue Oct 04 12:39:42 2011 -0700
    66.3 @@ -82,6 +82,7 @@
    66.4   *
    66.5   * </ul>
    66.6   *
    66.7 + * @since 1.7
    66.8   * @jls 4.7 Reifiable Types
    66.9   * @jls 8.4.1 Formal Parameters
   66.10   */
    67.1 --- a/src/share/classes/java/lang/StrictMath.java	Fri Sep 30 17:20:56 2011 -0700
    67.2 +++ b/src/share/classes/java/lang/StrictMath.java	Tue Oct 04 12:39:42 2011 -0700
    67.3 @@ -25,7 +25,6 @@
    67.4  
    67.5  package java.lang;
    67.6  import java.util.Random;
    67.7 -import sun.misc.FpUtils;
    67.8  import sun.misc.DoubleConsts;
    67.9  
   67.10  /**
   67.11 @@ -428,7 +427,7 @@
   67.12           * 1.0, which is exact too.
   67.13           */
   67.14          double twoToThe52 = (double)(1L << 52); // 2^52
   67.15 -        double sign = FpUtils.rawCopySign(1.0, a); // preserve sign info
   67.16 +        double sign = Math.copySign(1.0, a); // preserve sign info
   67.17          a = Math.abs(a);
   67.18  
   67.19          if (a < twoToThe52) { // E_min <= ilogb(a) <= 51
   67.20 @@ -955,7 +954,7 @@
   67.21       * @since 1.5
   67.22       */
   67.23      public static double ulp(double d) {
   67.24 -        return sun.misc.FpUtils.ulp(d);
   67.25 +        return Math.ulp(d);
   67.26      }
   67.27  
   67.28      /**
   67.29 @@ -982,7 +981,7 @@
   67.30       * @since 1.5
   67.31       */
   67.32      public static float ulp(float f) {
   67.33 -        return sun.misc.FpUtils.ulp(f);
   67.34 +        return Math.ulp(f);
   67.35      }
   67.36  
   67.37      /**
   67.38 @@ -1003,7 +1002,7 @@
   67.39       * @since 1.5
   67.40       */
   67.41      public static double signum(double d) {
   67.42 -        return sun.misc.FpUtils.signum(d);
   67.43 +        return Math.signum(d);
   67.44      }
   67.45  
   67.46      /**
   67.47 @@ -1024,7 +1023,7 @@
   67.48       * @since 1.5
   67.49       */
   67.50      public static float signum(float f) {
   67.51 -        return sun.misc.FpUtils.signum(f);
   67.52 +        return Math.signum(f);
   67.53      }
   67.54  
   67.55      /**
   67.56 @@ -1202,7 +1201,7 @@
   67.57       * @since 1.6
   67.58       */
   67.59      public static double copySign(double magnitude, double sign) {
   67.60 -        return sun.misc.FpUtils.copySign(magnitude, sign);
   67.61 +        return Math.copySign(magnitude, (Double.isNaN(sign)?1.0d:sign));
   67.62      }
   67.63  
   67.64      /**
   67.65 @@ -1218,7 +1217,7 @@
   67.66       * @since 1.6
   67.67       */
   67.68      public static float copySign(float magnitude, float sign) {
   67.69 -        return sun.misc.FpUtils.copySign(magnitude, sign);
   67.70 +        return Math.copySign(magnitude, (Float.isNaN(sign)?1.0f:sign));
   67.71      }
   67.72      /**
   67.73       * Returns the unbiased exponent used in the representation of a
   67.74 @@ -1234,7 +1233,7 @@
   67.75       * @since 1.6
   67.76       */
   67.77      public static int getExponent(float f) {
   67.78 -        return sun.misc.FpUtils.getExponent(f);
   67.79 +        return Math.getExponent(f);
   67.80      }
   67.81  
   67.82      /**
   67.83 @@ -1251,7 +1250,7 @@
   67.84       * @since 1.6
   67.85       */
   67.86      public static int getExponent(double d) {
   67.87 -        return sun.misc.FpUtils.getExponent(d);
   67.88 +        return Math.getExponent(d);
   67.89      }
   67.90  
   67.91      /**
   67.92 @@ -1294,7 +1293,7 @@
   67.93       * @since 1.6
   67.94       */
   67.95      public static double nextAfter(double start, double direction) {
   67.96 -        return sun.misc.FpUtils.nextAfter(start, direction);
   67.97 +        return Math.nextAfter(start, direction);
   67.98      }
   67.99  
  67.100      /**
  67.101 @@ -1336,7 +1335,7 @@
  67.102       * @since 1.6
  67.103       */
  67.104      public static float nextAfter(float start, double direction) {
  67.105 -        return sun.misc.FpUtils.nextAfter(start, direction);
  67.106 +        return Math.nextAfter(start, direction);
  67.107      }
  67.108  
  67.109      /**
  67.110 @@ -1365,7 +1364,7 @@
  67.111       * @since 1.6
  67.112       */
  67.113      public static double nextUp(double d) {
  67.114 -        return sun.misc.FpUtils.nextUp(d);
  67.115 +        return Math.nextUp(d);
  67.116      }
  67.117  
  67.118      /**
  67.119 @@ -1394,9 +1393,66 @@
  67.120       * @since 1.6
  67.121       */
  67.122      public static float nextUp(float f) {
  67.123 -        return sun.misc.FpUtils.nextUp(f);
  67.124 +        return Math.nextUp(f);
  67.125      }
  67.126  
  67.127 +    /**
  67.128 +     * Returns the floating-point value adjacent to {@code d} in
  67.129 +     * the direction of negative infinity.  This method is
  67.130 +     * semantically equivalent to {@code nextAfter(d,
  67.131 +     * Double.NEGATIVE_INFINITY)}; however, a
  67.132 +     * {@code nextDown} implementation may run faster than its
  67.133 +     * equivalent {@code nextAfter} call.
  67.134 +     *
  67.135 +     * <p>Special Cases:
  67.136 +     * <ul>
  67.137 +     * <li> If the argument is NaN, the result is NaN.
  67.138 +     *
  67.139 +     * <li> If the argument is negative infinity, the result is
  67.140 +     * negative infinity.
  67.141 +     *
  67.142 +     * <li> If the argument is zero, the result is
  67.143 +     * {@code -Double.MIN_VALUE}
  67.144 +     *
  67.145 +     * </ul>
  67.146 +     *
  67.147 +     * @param d  starting floating-point value
  67.148 +     * @return The adjacent floating-point value closer to negative
  67.149 +     * infinity.
  67.150 +     * @since 1.8
  67.151 +     */
  67.152 +    public static double nextDown(double d) {
  67.153 +        return Math.nextDown(d);
  67.154 +    }
  67.155 +
  67.156 +    /**
  67.157 +     * Returns the floating-point value adjacent to {@code f} in
  67.158 +     * the direction of negative infinity.  This method is
  67.159 +     * semantically equivalent to {@code nextAfter(f,
  67.160 +     * Float.NEGATIVE_INFINITY)}; however, a
  67.161 +     * {@code nextDown} implementation may run faster than its
  67.162 +     * equivalent {@code nextAfter} call.
  67.163 +     *
  67.164 +     * <p>Special Cases:
  67.165 +     * <ul>
  67.166 +     * <li> If the argument is NaN, the result is NaN.
  67.167 +     *
  67.168 +     * <li> If the argument is negative infinity, the result is
  67.169 +     * negative infinity.
  67.170 +     *
  67.171 +     * <li> If the argument is zero, the result is
  67.172 +     * {@code -Float.MIN_VALUE}
  67.173 +     *
  67.174 +     * </ul>
  67.175 +     *
  67.176 +     * @param f  starting floating-point value
  67.177 +     * @return The adjacent floating-point value closer to negative
  67.178 +     * infinity.
  67.179 +     * @since 1.8
  67.180 +     */
  67.181 +    public static float nextDown(float f) {
  67.182 +        return Math.nextDown(f);
  67.183 +    }
  67.184  
  67.185      /**
  67.186       * Return {@code d} &times;
  67.187 @@ -1429,7 +1485,7 @@
  67.188       * @since 1.6
  67.189       */
  67.190      public static double scalb(double d, int scaleFactor) {
  67.191 -        return sun.misc.FpUtils.scalb(d, scaleFactor);
  67.192 +        return Math.scalb(d, scaleFactor);
  67.193      }
  67.194  
  67.195      /**
  67.196 @@ -1463,6 +1519,6 @@
  67.197       * @since 1.6
  67.198       */
  67.199      public static float scalb(float f, int scaleFactor) {
  67.200 -        return sun.misc.FpUtils.scalb(f, scaleFactor);
  67.201 +        return Math.scalb(f, scaleFactor);
  67.202      }
  67.203  }
    68.1 --- a/src/share/classes/java/math/BigInteger.java	Fri Sep 30 17:20:56 2011 -0700
    68.2 +++ b/src/share/classes/java/math/BigInteger.java	Tue Oct 04 12:39:42 2011 -0700
    68.3 @@ -2919,6 +2919,7 @@
    68.4       * result with the opposite sign.
    68.5       *
    68.6       * @return this BigInteger converted to an {@code int}.
    68.7 +     * @see #intValueExact()
    68.8       */
    68.9      public int intValue() {
   68.10          int result = 0;
   68.11 @@ -2939,6 +2940,7 @@
   68.12       * result with the opposite sign.
   68.13       *
   68.14       * @return this BigInteger converted to a {@code long}.
   68.15 +     * @see #longValueExact()
   68.16       */
   68.17      public long longValue() {
   68.18          long result = 0;
   68.19 @@ -3382,4 +3384,84 @@
   68.20          }
   68.21          return result;
   68.22      }
   68.23 +
   68.24 +    /**
   68.25 +     * Converts this {@code BigInteger} to a {@code long}, checking
   68.26 +     * for lost information.  If the value of this {@code BigInteger}
   68.27 +     * is out of the range of the {@code long} type, then an
   68.28 +     * {@code ArithmeticException} is thrown.
   68.29 +     *
   68.30 +     * @return this {@code BigInteger} converted to a {@code long}.
   68.31 +     * @throws ArithmeticException if the value of {@code this} will
   68.32 +     * not exactly fit in a {@code long}.
   68.33 +     * @see BigInteger#longValue
   68.34 +     * @since  1.8
   68.35 +     */
   68.36 +    public long longValueExact() {
   68.37 +        if (mag.length <= 2 && bitLength() <= 63)
   68.38 +            return longValue();
   68.39 +        else
   68.40 +            throw new ArithmeticException("BigInteger out of long range");
   68.41 +    }
   68.42 +
   68.43 +    /**
   68.44 +     * Converts this {@code BigInteger} to an {@code int}, checking
   68.45 +     * for lost information.  If the value of this {@code BigInteger}
   68.46 +     * is out of the range of the {@code int} type, then an
   68.47 +     * {@code ArithmeticException} is thrown.
   68.48 +     *
   68.49 +     * @return this {@code BigInteger} converted to an {@code int}.
   68.50 +     * @throws ArithmeticException if the value of {@code this} will
   68.51 +     * not exactly fit in a {@code int}.
   68.52 +     * @see BigInteger#intValue
   68.53 +     * @since  1.8
   68.54 +     */
   68.55 +    public int intValueExact() {
   68.56 +        if (mag.length <= 1 && bitLength() <= 31)
   68.57 +            return intValue();
   68.58 +        else
   68.59 +            throw new ArithmeticException("BigInteger out of int range");
   68.60 +    }
   68.61 +
   68.62 +    /**
   68.63 +     * Converts this {@code BigInteger} to a {@code short}, checking
   68.64 +     * for lost information.  If the value of this {@code BigInteger}
   68.65 +     * is out of the range of the {@code short} type, then an
   68.66 +     * {@code ArithmeticException} is thrown.
   68.67 +     *
   68.68 +     * @return this {@code BigInteger} converted to a {@code short}.
   68.69 +     * @throws ArithmeticException if the value of {@code this} will
   68.70 +     * not exactly fit in a {@code short}.
   68.71 +     * @see BigInteger#shortValue
   68.72 +     * @since  1.8
   68.73 +     */
   68.74 +    public short shortValueExact() {
   68.75 +        if (mag.length <= 1 && bitLength() <= 31) {
   68.76 +            int value = intValue();
   68.77 +            if (value >= Short.MIN_VALUE && value <= Short.MAX_VALUE)
   68.78 +                return shortValue();
   68.79 +        }
   68.80 +        throw new ArithmeticException("BigInteger out of short range");
   68.81 +    }
   68.82 +
   68.83 +    /**
   68.84 +     * Converts this {@code BigInteger} to a {@code byte}, checking
   68.85 +     * for lost information.  If the value of this {@code BigInteger}
   68.86 +     * is out of the range of the {@code byte} type, then an
   68.87 +     * {@code ArithmeticException} is thrown.
   68.88 +     *
   68.89 +     * @return this {@code BigInteger} converted to a {@code byte}.
   68.90 +     * @throws ArithmeticException if the value of {@code this} will
   68.91 +     * not exactly fit in a {@code byte}.
   68.92 +     * @see BigInteger#byteValue
   68.93 +     * @since  1.8
   68.94 +     */
   68.95 +    public byte byteValueExact() {
   68.96 +        if (mag.length <= 1 && bitLength() <= 31) {
   68.97 +            int value = intValue();
   68.98 +            if (value >= Byte.MIN_VALUE && value <= Byte.MAX_VALUE)
   68.99 +                return byteValue();
  68.100 +        }
  68.101 +        throw new ArithmeticException("BigInteger out of byte range");
  68.102 +    }
  68.103  }
    69.1 --- a/src/share/classes/java/net/AbstractPlainDatagramSocketImpl.java	Fri Sep 30 17:20:56 2011 -0700
    69.2 +++ b/src/share/classes/java/net/AbstractPlainDatagramSocketImpl.java	Tue Oct 04 12:39:42 2011 -0700
    69.3 @@ -26,8 +26,6 @@
    69.4  
    69.5  import java.io.FileDescriptor;
    69.6  import java.io.IOException;
    69.7 -import java.io.InterruptedIOException;
    69.8 -import java.util.Enumeration;
    69.9  import sun.net.ResourceManager;
   69.10  
   69.11  /**
   69.12 @@ -66,8 +64,8 @@
   69.13       * Creates a datagram socket
   69.14       */
   69.15      protected synchronized void create() throws SocketException {
   69.16 +        ResourceManager.beforeUdpCreate();
   69.17          fd = new FileDescriptor();
   69.18 -        ResourceManager.beforeUdpCreate();
   69.19          try {
   69.20              datagramSocketCreate();
   69.21          } catch (SocketException ioe) {
   69.22 @@ -153,11 +151,13 @@
   69.23       * Set the TTL (time-to-live) option.
   69.24       * @param TTL to be set.
   69.25       */
   69.26 +    @Deprecated
   69.27      protected abstract void setTTL(byte ttl) throws IOException;
   69.28  
   69.29      /**
   69.30       * Get the TTL (time-to-live) option.
   69.31       */
   69.32 +    @Deprecated
   69.33      protected abstract byte getTTL() throws IOException;
   69.34  
   69.35      /**
    70.1 --- a/src/share/classes/java/net/ContentHandler.java	Fri Sep 30 17:20:56 2011 -0700
    70.2 +++ b/src/share/classes/java/net/ContentHandler.java	Tue Oct 04 12:39:42 2011 -0700
    70.3 @@ -1,5 +1,5 @@
    70.4  /*
    70.5 - * Copyright (c) 1995, 2006, Oracle and/or its affiliates. All rights reserved.
    70.6 + * Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
    70.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    70.8   *
    70.9   * This code is free software; you can redistribute it and/or modify it
   70.10 @@ -96,7 +96,7 @@
   70.11       * @exception  IOException  if an I/O error occurs while reading the object.
   70.12       * @since 1.3
   70.13       */
   70.14 -    public Object getContent(URLConnection urlc, Class[] classes) throws IOException {
   70.15 +    public Object getContent(URLConnection urlc, Class<?>[] classes) throws IOException {
   70.16          Object obj = getContent(urlc);
   70.17  
   70.18          for (int i = 0; i < classes.length; i++) {
    71.1 --- a/src/share/classes/java/net/CookieManager.java	Fri Sep 30 17:20:56 2011 -0700
    71.2 +++ b/src/share/classes/java/net/CookieManager.java	Tue Oct 04 12:39:42 2011 -0700
    71.3 @@ -249,7 +249,6 @@
    71.4          return Collections.unmodifiableMap(cookieMap);
    71.5      }
    71.6  
    71.7 -
    71.8      public void
    71.9          put(URI uri, Map<String, List<String>> responseHeaders)
   71.10          throws IOException
   71.11 @@ -284,7 +283,7 @@
   71.12                          cookies = HttpCookie.parse(headerValue);
   71.13                      } catch (IllegalArgumentException e) {
   71.14                          // Bogus header, make an empty list and log the error
   71.15 -                        cookies = java.util.Collections.EMPTY_LIST;
   71.16 +                        cookies = java.util.Collections.emptyList();
   71.17                          if (logger.isLoggable(PlatformLogger.SEVERE)) {
   71.18                              logger.severe("Invalid cookie for " + uri + ": " + headerValue);
   71.19                          }
    72.1 --- a/src/share/classes/java/net/DatagramSocket.java	Fri Sep 30 17:20:56 2011 -0700
    72.2 +++ b/src/share/classes/java/net/DatagramSocket.java	Tue Oct 04 12:39:42 2011 -0700
    72.3 @@ -1,5 +1,5 @@
    72.4  /*
    72.5 - * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
    72.6 + * Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
    72.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    72.8   *
    72.9   * This code is free software; you can redistribute it and/or modify it
   72.10 @@ -25,9 +25,7 @@
   72.11  
   72.12  package java.net;
   72.13  
   72.14 -import java.io.FileDescriptor;
   72.15  import java.io.IOException;
   72.16 -import java.io.InterruptedIOException;
   72.17  import java.nio.channels.DatagramChannel;
   72.18  import java.security.AccessController;
   72.19  import java.security.PrivilegedExceptionAction;
   72.20 @@ -300,7 +298,7 @@
   72.21          }
   72.22      }
   72.23  
   72.24 -    static Class implClass = null;
   72.25 +    static Class<?> implClass = null;
   72.26  
   72.27      void createImpl() throws SocketException {
   72.28          if (impl == null) {
    73.1 --- a/src/share/classes/java/net/HttpURLConnection.java	Fri Sep 30 17:20:56 2011 -0700
    73.2 +++ b/src/share/classes/java/net/HttpURLConnection.java	Tue Oct 04 12:39:42 2011 -0700
    73.3 @@ -535,6 +535,7 @@
    73.4          return responseMessage;
    73.5      }
    73.6  
    73.7 +    @SuppressWarnings("deprecation")
    73.8      public long getHeaderFieldDate(String name, long Default) {
    73.9          String dateString = getHeaderField(name);
   73.10          try {
    74.1 --- a/src/share/classes/java/net/Inet4Address.java	Fri Sep 30 17:20:56 2011 -0700
    74.2 +++ b/src/share/classes/java/net/Inet4Address.java	Tue Oct 04 12:39:42 2011 -0700
    74.3 @@ -1,5 +1,5 @@
    74.4  /*
    74.5 - * Copyright (c) 2000, 2006, Oracle and/or its affiliates. All rights reserved.
    74.6 + * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
    74.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    74.8   *
    74.9   * This code is free software; you can redistribute it and/or modify it
   74.10 @@ -25,9 +25,7 @@
   74.11  
   74.12  package java.net;
   74.13  
   74.14 -import java.security.AccessController;
   74.15  import java.io.ObjectStreamException;
   74.16 -import sun.security.action.*;
   74.17  
   74.18  /**
   74.19   * This class represents an Internet Protocol version 4 (IPv4) address.
    75.1 --- a/src/share/classes/java/net/Inet4AddressImpl.java	Fri Sep 30 17:20:56 2011 -0700
    75.2 +++ b/src/share/classes/java/net/Inet4AddressImpl.java	Tue Oct 04 12:39:42 2011 -0700
    75.3 @@ -1,5 +1,5 @@
    75.4  /*
    75.5 - * Copyright (c) 2002, 2005, Oracle and/or its affiliates. All rights reserved.
    75.6 + * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
    75.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    75.8   *
    75.9   * This code is free software; you can redistribute it and/or modify it
   75.10 @@ -59,11 +59,11 @@
   75.11            /*
   75.12             * Let's make sure we use an address of the proper family
   75.13             */
   75.14 -          java.util.Enumeration it = netif.getInetAddresses();
   75.15 +          java.util.Enumeration<InetAddress> it = netif.getInetAddresses();
   75.16            InetAddress inetaddr = null;
   75.17            while (!(inetaddr instanceof Inet4Address) &&
   75.18                   it.hasMoreElements())
   75.19 -              inetaddr = (InetAddress) it.nextElement();
   75.20 +              inetaddr = it.nextElement();
   75.21            if (inetaddr instanceof Inet4Address)
   75.22                ifaddr = inetaddr.getAddress();
   75.23        }
    76.1 --- a/src/share/classes/java/net/Inet6Address.java	Fri Sep 30 17:20:56 2011 -0700
    76.2 +++ b/src/share/classes/java/net/Inet6Address.java	Tue Oct 04 12:39:42 2011 -0700
    76.3 @@ -1,5 +1,5 @@
    76.4  /*
    76.5 - * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
    76.6 + * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
    76.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    76.8   *
    76.9   * This code is free software; you can redistribute it and/or modify it
   76.10 @@ -383,9 +383,9 @@
   76.11          while (en.hasMoreElements()) {
   76.12              NetworkInterface ifc = en.nextElement();
   76.13              if (ifc.getName().equals (ifname)) {
   76.14 -                Enumeration addresses = ifc.getInetAddresses();
   76.15 +                Enumeration<InetAddress> addresses = ifc.getInetAddresses();
   76.16                  while (addresses.hasMoreElements()) {
   76.17 -                    InetAddress addr = (InetAddress)addresses.nextElement();
   76.18 +                    InetAddress addr = addresses.nextElement();
   76.19                      if (!(addr instanceof Inet6Address)) {
   76.20                          continue;
   76.21                      }
    77.1 --- a/src/share/classes/java/net/Inet6AddressImpl.java	Fri Sep 30 17:20:56 2011 -0700
    77.2 +++ b/src/share/classes/java/net/Inet6AddressImpl.java	Tue Oct 04 12:39:42 2011 -0700
    77.3 @@ -1,5 +1,5 @@
    77.4  /*
    77.5 - * Copyright (c) 2002, 2005, Oracle and/or its affiliates. All rights reserved.
    77.6 + * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
    77.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    77.8   *
    77.9   * This code is free software; you can redistribute it and/or modify it
   77.10 @@ -54,10 +54,10 @@
   77.11               * be either an IPv6 address or an IPv4 address (case of a dual
   77.12               * stack system).
   77.13               */
   77.14 -            java.util.Enumeration it = netif.getInetAddresses();
   77.15 +            java.util.Enumeration<InetAddress> it = netif.getInetAddresses();
   77.16              InetAddress inetaddr = null;
   77.17              while (it.hasMoreElements()) {
   77.18 -                inetaddr = (InetAddress) it.nextElement();
   77.19 +                inetaddr = it.nextElement();
   77.20                  if (inetaddr.getClass().isInstance(addr)) {
   77.21                      ifaddr = inetaddr.getAddress();
   77.22                      if (inetaddr instanceof Inet6Address) {
    78.1 --- a/src/share/classes/java/net/MulticastSocket.java	Fri Sep 30 17:20:56 2011 -0700
    78.2 +++ b/src/share/classes/java/net/MulticastSocket.java	Tue Oct 04 12:39:42 2011 -0700
    78.3 @@ -1,5 +1,5 @@
    78.4  /*
    78.5 - * Copyright (c) 1995, 2007, Oracle and/or its affiliates. All rights reserved.
    78.6 + * Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
    78.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    78.8   *
    78.9   * This code is free software; you can redistribute it and/or modify it
   78.10 @@ -26,7 +26,6 @@
   78.11  package java.net;
   78.12  
   78.13  import java.io.IOException;
   78.14 -import java.io.InterruptedIOException;
   78.15  import java.util.Enumeration;
   78.16  
   78.17  /**
   78.18 @@ -500,9 +499,9 @@
   78.19               */
   78.20              try {
   78.21                  NetworkInterface ni = NetworkInterface.getByInetAddress(ia);
   78.22 -                Enumeration addrs = ni.getInetAddresses();
   78.23 +                Enumeration<InetAddress> addrs = ni.getInetAddresses();
   78.24                  while (addrs.hasMoreElements()) {
   78.25 -                    InetAddress addr = (InetAddress)(addrs.nextElement());
   78.26 +                    InetAddress addr = addrs.nextElement();
   78.27                      if (addr.equals(infAddress)) {
   78.28                          return infAddress;
   78.29                      }
    79.1 --- a/src/share/classes/java/net/Proxy.java	Fri Sep 30 17:20:56 2011 -0700
    79.2 +++ b/src/share/classes/java/net/Proxy.java	Tue Oct 04 12:39:42 2011 -0700
    79.3 @@ -1,5 +1,5 @@
    79.4  /*
    79.5 - * Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved.
    79.6 + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
    79.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    79.8   *
    79.9   * This code is free software; you can redistribute it and/or modify it
   79.10 @@ -73,7 +73,7 @@
   79.11  
   79.12      // Creates the proxy that represents a <code>DIRECT</code> connection.
   79.13      private Proxy() {
   79.14 -        type = type.DIRECT;
   79.15 +        type = Type.DIRECT;
   79.16          sa = null;
   79.17      }
   79.18  
    80.1 --- a/src/share/classes/java/net/ProxySelector.java	Fri Sep 30 17:20:56 2011 -0700
    80.2 +++ b/src/share/classes/java/net/ProxySelector.java	Tue Oct 04 12:39:42 2011 -0700
    80.3 @@ -1,5 +1,5 @@
    80.4  /*
    80.5 - * Copyright (c) 2003, 2006, Oracle and/or its affiliates. All rights reserved.
    80.6 + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
    80.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    80.8   *
    80.9   * This code is free software; you can redistribute it and/or modify it
   80.10 @@ -69,7 +69,7 @@
   80.11  
   80.12      static {
   80.13          try {
   80.14 -            Class c = Class.forName("sun.net.spi.DefaultProxySelector");
   80.15 +            Class<?> c = Class.forName("sun.net.spi.DefaultProxySelector");
   80.16              if (c != null && ProxySelector.class.isAssignableFrom(c)) {
   80.17                  theProxySelector = (ProxySelector) c.newInstance();
   80.18              }
    81.1 --- a/src/share/classes/java/net/Socket.java	Fri Sep 30 17:20:56 2011 -0700
    81.2 +++ b/src/share/classes/java/net/Socket.java	Tue Oct 04 12:39:42 2011 -0700
    81.3 @@ -1,5 +1,5 @@
    81.4  /*
    81.5 - * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
    81.6 + * Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
    81.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    81.8   *
    81.9   * This code is free software; you can redistribute it and/or modify it
   81.10 @@ -459,13 +459,10 @@
   81.11          oldImpl = AccessController.doPrivileged
   81.12                                  (new PrivilegedAction<Boolean>() {
   81.13              public Boolean run() {
   81.14 -                Class[] cl = new Class[2];
   81.15 -                cl[0] = SocketAddress.class;
   81.16 -                cl[1] = Integer.TYPE;
   81.17 -                Class clazz = impl.getClass();
   81.18 +                Class<?> clazz = impl.getClass();
   81.19                  while (true) {
   81.20                      try {
   81.21 -                        clazz.getDeclaredMethod("connect", cl);
   81.22 +                        clazz.getDeclaredMethod("connect", SocketAddress.class, int.class);
   81.23                          return Boolean.FALSE;
   81.24                      } catch (NoSuchMethodException e) {
   81.25                          clazz = clazz.getSuperclass();
    82.1 --- a/src/share/classes/java/net/SocketPermission.java	Fri Sep 30 17:20:56 2011 -0700
    82.2 +++ b/src/share/classes/java/net/SocketPermission.java	Tue Oct 04 12:39:42 2011 -0700
    82.3 @@ -1,5 +1,5 @@
    82.4  /*
    82.5 - * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved.
    82.6 + * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
    82.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    82.8   *
    82.9   * This code is free software; you can redistribute it and/or modify it
   82.10 @@ -467,6 +467,7 @@
   82.11       * @param action the action string
   82.12       * @return the action mask
   82.13       */
   82.14 +    @SuppressWarnings("fallthrough")
   82.15      private static int getMask(String action) {
   82.16  
   82.17          if (action == null) {
   82.18 @@ -1231,7 +1232,7 @@
   82.19  implements Serializable
   82.20  {
   82.21      // Not serialized; see serialization section at end of class
   82.22 -    private transient List perms;
   82.23 +    private transient List<SocketPermission> perms;
   82.24  
   82.25      /**
   82.26       * Create an empty SocketPermissions object.
   82.27 @@ -1239,7 +1240,7 @@
   82.28       */
   82.29  
   82.30      public SocketPermissionCollection() {
   82.31 -        perms = new ArrayList();
   82.32 +        perms = new ArrayList<SocketPermission>();
   82.33      }
   82.34  
   82.35      /**
   82.36 @@ -1267,7 +1268,7 @@
   82.37          // optimization to ensure perms most likely to be tested
   82.38          // show up early (4301064)
   82.39          synchronized (this) {
   82.40 -            perms.add(0, permission);
   82.41 +            perms.add(0, (SocketPermission)permission);
   82.42          }
   82.43      }
   82.44  
   82.45 @@ -1296,7 +1297,7 @@
   82.46              int len = perms.size();
   82.47              //System.out.println("implies "+np);
   82.48              for (int i = 0; i < len; i++) {
   82.49 -                SocketPermission x = (SocketPermission) perms.get(i);
   82.50 +                SocketPermission x = perms.get(i);
   82.51                  //System.out.println("  trying "+x);
   82.52                  if (((needed & x.getMask()) != 0) && x.impliesIgnoreMask(np)) {
   82.53                      effective |=  x.getMask();
   82.54 @@ -1316,10 +1317,11 @@
   82.55       * @return an enumeration of all the SocketPermission objects.
   82.56       */
   82.57  
   82.58 -    public Enumeration elements() {
   82.59 +    @SuppressWarnings("unchecked")
   82.60 +    public Enumeration<Permission> elements() {
   82.61          // Convert Iterator into Enumeration
   82.62          synchronized (this) {
   82.63 -            return Collections.enumeration(perms);
   82.64 +            return Collections.enumeration((List<Permission>)(List)perms);
   82.65          }
   82.66      }
   82.67  
   82.68 @@ -1353,7 +1355,7 @@
   82.69          // Don't call out.defaultWriteObject()
   82.70  
   82.71          // Write out Vector
   82.72 -        Vector permissions = new Vector(perms.size());
   82.73 +        Vector<SocketPermission> permissions = new Vector<>(perms.size());
   82.74  
   82.75          synchronized (this) {
   82.76              permissions.addAll(perms);
   82.77 @@ -1375,8 +1377,9 @@
   82.78          ObjectInputStream.GetField gfields = in.readFields();
   82.79  
   82.80          // Get the one we want
   82.81 -        Vector permissions = (Vector)gfields.get("permissions", null);
   82.82 -        perms = new ArrayList(permissions.size());
   82.83 +        @SuppressWarnings("unchecked")
   82.84 +        Vector<SocketPermission> permissions = (Vector<SocketPermission>)gfields.get("permissions", null);
   82.85 +        perms = new ArrayList<SocketPermission>(permissions.size());
   82.86          perms.addAll(permissions);
   82.87      }
   82.88  }
    83.1 --- a/src/share/classes/java/net/URL.java	Fri Sep 30 17:20:56 2011 -0700
    83.2 +++ b/src/share/classes/java/net/URL.java	Tue Oct 04 12:39:42 2011 -0700
    83.3 @@ -1,5 +1,5 @@
    83.4  /*
    83.5 - * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
    83.6 + * Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
    83.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    83.8   *
    83.9   * This code is free software; you can redistribute it and/or modify it
   83.10 @@ -27,7 +27,6 @@
   83.11  
   83.12  import java.io.IOException;
   83.13  import java.io.InputStream;
   83.14 -import java.io.OutputStream;
   83.15  import java.util.Hashtable;
   83.16  import java.util.StringTokenizer;
   83.17  import sun.security.util.SecurityConstants;
   83.18 @@ -1113,7 +1112,7 @@
   83.19      /**
   83.20       * A table of protocol handlers.
   83.21       */
   83.22 -    static Hashtable handlers = new Hashtable();
   83.23 +    static Hashtable<String,URLStreamHandler> handlers = new Hashtable<>();
   83.24      private static Object streamHandlerLock = new Object();
   83.25  
   83.26      /**
   83.27 @@ -1122,7 +1121,7 @@
   83.28       */
   83.29      static URLStreamHandler getURLStreamHandler(String protocol) {
   83.30  
   83.31 -        URLStreamHandler handler = (URLStreamHandler)handlers.get(protocol);
   83.32 +        URLStreamHandler handler = handlers.get(protocol);
   83.33          if (handler == null) {
   83.34  
   83.35              boolean checkedWithFactory = false;
   83.36 @@ -1160,7 +1159,7 @@
   83.37                      try {
   83.38                          String clsName = packagePrefix + "." + protocol +
   83.39                            ".Handler";
   83.40 -                        Class cls = null;
   83.41 +                        Class<?> cls = null;
   83.42                          try {
   83.43                              cls = Class.forName(clsName);
   83.44                          } catch (ClassNotFoundException e) {
   83.45 @@ -1185,7 +1184,7 @@
   83.46  
   83.47                  // Check again with hashtable just in case another
   83.48                  // thread created a handler since we last checked
   83.49 -                handler2 = (URLStreamHandler)handlers.get(protocol);
   83.50 +                handler2 = handlers.get(protocol);
   83.51  
   83.52                  if (handler2 != null) {
   83.53                      return handler2;
    84.1 --- a/src/share/classes/java/net/URLClassLoader.java	Fri Sep 30 17:20:56 2011 -0700
    84.2 +++ b/src/share/classes/java/net/URLClassLoader.java	Tue Oct 04 12:39:42 2011 -0700
    84.3 @@ -25,14 +25,7 @@
    84.4  
    84.5  package java.net;
    84.6  
    84.7 -import java.lang.reflect.Method;
    84.8 -import java.lang.reflect.Modifier;
    84.9 -import java.lang.ref.*;
   84.10  import java.io.*;
   84.11 -import java.net.URL;
   84.12 -import java.net.URLConnection;
   84.13 -import java.net.URLStreamHandlerFactory;
   84.14 -import java.util.Enumeration;
   84.15  import java.util.*;
   84.16  import java.util.jar.Manifest;
   84.17  import java.util.jar.JarFile;
   84.18 @@ -352,8 +345,8 @@
   84.19      {
   84.20          try {
   84.21              return AccessController.doPrivileged(
   84.22 -                new PrivilegedExceptionAction<Class>() {
   84.23 -                    public Class run() throws ClassNotFoundException {
   84.24 +                new PrivilegedExceptionAction<Class<?>>() {
   84.25 +                    public Class<?> run() throws ClassNotFoundException {
   84.26                          String path = name.replace('.', '/').concat(".class");
   84.27                          Resource res = ucp.getResource(path, false);
   84.28                          if (res != null) {
   84.29 @@ -406,7 +399,7 @@
   84.30       * Resource. The resulting Class must be resolved before it can be
   84.31       * used.
   84.32       */
   84.33 -    private Class defineClass(String name, Resource res) throws IOException {
   84.34 +    private Class<?> defineClass(String name, Resource res) throws IOException {
   84.35          long t0 = System.nanoTime();
   84.36          int i = name.lastIndexOf('.');
   84.37          URL url = res.getCodeSourceURL();
   84.38 @@ -774,7 +767,7 @@
   84.39          super(urls, acc);
   84.40      }
   84.41  
   84.42 -    public final Class loadClass(String name, boolean resolve)
   84.43 +    public final Class<?> loadClass(String name, boolean resolve)
   84.44          throws ClassNotFoundException
   84.45      {
   84.46          // First check if we have permission to access the package. This
    85.1 --- a/src/share/classes/java/net/URLConnection.java	Fri Sep 30 17:20:56 2011 -0700
    85.2 +++ b/src/share/classes/java/net/URLConnection.java	Tue Oct 04 12:39:42 2011 -0700
    85.3 @@ -595,7 +595,7 @@
    85.4       * @since 1.4
    85.5       */
    85.6      public Map<String,List<String>> getHeaderFields() {
    85.7 -        return Collections.EMPTY_MAP;
    85.8 +        return Collections.emptyMap();
    85.9      }
   85.10  
   85.11      /**
   85.12 @@ -659,6 +659,7 @@
   85.13       *          <code>Default</code> argument is returned if the field is
   85.14       *          missing or malformed.
   85.15       */
   85.16 +    @SuppressWarnings("deprecation")
   85.17      public long getHeaderFieldDate(String name, long Default) {
   85.18          String value = getHeaderField(name);
   85.19          try {
   85.20 @@ -1153,7 +1154,7 @@
   85.21              throw new IllegalStateException("Already connected");
   85.22  
   85.23          if (requests == null)
   85.24 -            return Collections.EMPTY_MAP;
   85.25 +            return Collections.emptyMap();
   85.26  
   85.27          return requests.getHeaders(null);
   85.28      }
   85.29 @@ -1236,7 +1237,7 @@
   85.30          factory = fac;
   85.31      }
   85.32  
   85.33 -    private static Hashtable handlers = new Hashtable();
   85.34 +    private static Hashtable<String, ContentHandler> handlers = new Hashtable<>();
   85.35  
   85.36      /**
   85.37       * Gets the Content Handler appropriate for this connection.
   85.38 @@ -1250,7 +1251,7 @@
   85.39          if (contentType == null)
   85.40              throw new UnknownServiceException("no content-type");
   85.41          try {
   85.42 -            handler = (ContentHandler) handlers.get(contentType);
   85.43 +            handler = handlers.get(contentType);
   85.44              if (handler != null)
   85.45                  return handler;
   85.46          } catch(Exception e) {
   85.47 @@ -1316,7 +1317,7 @@
   85.48  
   85.49              try {
   85.50                  String clsName = packagePrefix + "." + contentHandlerClassName;
   85.51 -                Class cls = null;
   85.52 +                Class<?> cls = null;
   85.53                  try {
   85.54                      cls = Class.forName(clsName);
   85.55                  } catch (ClassNotFoundException e) {
    86.1 --- a/src/share/classes/java/util/Formatter.java	Fri Sep 30 17:20:56 2011 -0700
    86.2 +++ b/src/share/classes/java/util/Formatter.java	Tue Oct 04 12:39:42 2011 -0700
    86.3 @@ -50,7 +50,6 @@
    86.4  import java.util.regex.Matcher;
    86.5  import java.util.regex.Pattern;
    86.6  
    86.7 -import sun.misc.FpUtils;
    86.8  import sun.misc.DoubleConsts;
    86.9  import sun.misc.FormattedFloatingDecimal;
   86.10  
   86.11 @@ -3417,24 +3416,24 @@
   86.12          // Method assumes that d > 0.
   86.13          private String hexDouble(double d, int prec) {
   86.14              // Let Double.toHexString handle simple cases
   86.15 -            if(!FpUtils.isFinite(d) || d == 0.0 || prec == 0 || prec >= 13)
   86.16 +            if(!Double.isFinite(d) || d == 0.0 || prec == 0 || prec >= 13)
   86.17                  // remove "0x"
   86.18                  return Double.toHexString(d).substring(2);
   86.19              else {
   86.20                  assert(prec >= 1 && prec <= 12);
   86.21  
   86.22 -                int exponent  = FpUtils.getExponent(d);
   86.23 +                int exponent  = Math.getExponent(d);
   86.24                  boolean subnormal
   86.25                      = (exponent == DoubleConsts.MIN_EXPONENT - 1);
   86.26  
   86.27                  // If this is subnormal input so normalize (could be faster to
   86.28                  // do as integer operation).
   86.29                  if (subnormal) {
   86.30 -                    scaleUp = FpUtils.scalb(1.0, 54);
   86.31 +                    scaleUp = Math.scalb(1.0, 54);
   86.32                      d *= scaleUp;
   86.33                      // Calculate the exponent.  This is not just exponent + 54
   86.34                      // since the former is not the normalized exponent.
   86.35 -                    exponent = FpUtils.getExponent(d);
   86.36 +                    exponent = Math.getExponent(d);
   86.37                      assert exponent >= DoubleConsts.MIN_EXPONENT &&
   86.38                          exponent <= DoubleConsts.MAX_EXPONENT: exponent;
   86.39                  }
    87.1 --- a/src/share/classes/java/util/Properties.java	Fri Sep 30 17:20:56 2011 -0700
    87.2 +++ b/src/share/classes/java/util/Properties.java	Tue Oct 04 12:39:42 2011 -0700
    87.3 @@ -34,6 +34,7 @@
    87.4  import java.io.Writer;
    87.5  import java.io.OutputStreamWriter;
    87.6  import java.io.BufferedWriter;
    87.7 +import java.lang.reflect.*;
    87.8  
    87.9  /**
   87.10   * The <code>Properties</code> class represents a persistent set of
   87.11 @@ -1111,4 +1112,60 @@
   87.12      private static final char[] hexDigit = {
   87.13          '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
   87.14      };
   87.15 +
   87.16 +
   87.17 +    private static class XMLUtils {
   87.18 +        private static Method load = null;
   87.19 +        private static Method save = null;
   87.20 +        static {
   87.21 +            try {
   87.22 +                // reference sun.util.xml.Utils reflectively
   87.23 +                // to allow the Properties class be compiled in
   87.24 +                // the absence of XML
   87.25 +                Class<?> c = Class.forName("sun.util.xml.XMLUtils", true, null);
   87.26 +                load = c.getMethod("load", Properties.class, InputStream.class);
   87.27 +                save = c.getMethod("save", Properties.class, OutputStream.class,
   87.28 +                                   String.class, String.class);
   87.29 +            } catch (ClassNotFoundException cnf) {
   87.30 +                throw new AssertionError(cnf);
   87.31 +            } catch (NoSuchMethodException e) {
   87.32 +                throw new AssertionError(e);
   87.33 +            }
   87.34 +        }
   87.35 +
   87.36 +        static void invoke(Method m, Object... args) throws IOException {
   87.37 +            try {
   87.38 +                m.invoke(null, args);
   87.39 +            } catch (IllegalAccessException e) {
   87.40 +                throw new AssertionError(e);
   87.41 +            } catch (InvocationTargetException e) {
   87.42 +                Throwable t = e.getCause();
   87.43 +                if (t instanceof RuntimeException)
   87.44 +                    throw (RuntimeException)t;
   87.45 +
   87.46 +                if (t instanceof IOException) {
   87.47 +                    throw (IOException)t;
   87.48 +                } else {
   87.49 +                    throw new AssertionError(t);
   87.50 +                }
   87.51 +            }
   87.52 +        }
   87.53 +
   87.54 +        static void load(Properties props, InputStream in)
   87.55 +            throws IOException, InvalidPropertiesFormatException
   87.56 +        {
   87.57 +            if (load == null)
   87.58 +                throw new InternalError("sun.util.xml.XMLUtils not found");
   87.59 +            invoke(load, props, in);
   87.60 +        }
   87.61 +
   87.62 +        static void save(Properties props, OutputStream os, String comment,
   87.63 +                         String encoding)
   87.64 +            throws IOException
   87.65 +        {
   87.66 +            if (save == null)
   87.67 +                throw new InternalError("sun.util.xml.XMLUtils not found");
   87.68 +            invoke(save, props, os, comment, encoding);
   87.69 +        }
   87.70 +    }
   87.71  }
    88.1 --- a/src/share/classes/java/util/XMLUtils.java	Fri Sep 30 17:20:56 2011 -0700
    88.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    88.3 @@ -1,206 +0,0 @@
    88.4 -/*
    88.5 - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
    88.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    88.7 - *
    88.8 - * This code is free software; you can redistribute it and/or modify it
    88.9 - * under the terms of the GNU General Public License version 2 only, as
   88.10 - * published by the Free Software Foundation.  Oracle designates this
   88.11 - * particular file as subject to the "Classpath" exception as provided
   88.12 - * by Oracle in the LICENSE file that accompanied this code.
   88.13 - *
   88.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
   88.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   88.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   88.17 - * version 2 for more details (a copy is included in the LICENSE file that
   88.18 - * accompanied this code).
   88.19 - *
   88.20 - * You should have received a copy of the GNU General Public License version
   88.21 - * 2 along with this work; if not, write to the Free Software Foundation,
   88.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   88.23 - *
   88.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   88.25 - * or visit www.oracle.com if you need additional information or have any
   88.26 - * questions.
   88.27 - */
   88.28 -
   88.29 -package java.util;
   88.30 -
   88.31 -import java.io.*;
   88.32 -import org.xml.sax.*;
   88.33 -import org.xml.sax.helpers.*;
   88.34 -import org.w3c.dom.*;
   88.35 -import javax.xml.parsers.*;
   88.36 -import javax.xml.transform.*;
   88.37 -import javax.xml.transform.dom.*;
   88.38 -import javax.xml.transform.stream.*;
   88.39 -
   88.40 -/**
   88.41 - * A class used to aid in Properties load and save in XML. Keeping this
   88.42 - * code outside of Properties helps reduce the number of classes loaded
   88.43 - * when Properties is loaded.
   88.44 - *
   88.45 - * @author  Michael McCloskey
   88.46 - * @since   1.3
   88.47 - */
   88.48 -class XMLUtils {
   88.49 -
   88.50 -    // XML loading and saving methods for Properties
   88.51 -
   88.52 -    // The required DTD URI for exported properties
   88.53 -    private static final String PROPS_DTD_URI =
   88.54 -    "http://java.sun.com/dtd/properties.dtd";
   88.55 -
   88.56 -    private static final String PROPS_DTD =
   88.57 -    "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
   88.58 -    "<!-- DTD for properties -->"                +
   88.59 -    "<!ELEMENT properties ( comment?, entry* ) >"+
   88.60 -    "<!ATTLIST properties"                       +
   88.61 -        " version CDATA #FIXED \"1.0\">"         +
   88.62 -    "<!ELEMENT comment (#PCDATA) >"              +
   88.63 -    "<!ELEMENT entry (#PCDATA) >"                +
   88.64 -    "<!ATTLIST entry "                           +
   88.65 -        " key CDATA #REQUIRED>";
   88.66 -
   88.67 -    /**
   88.68 -     * Version number for the format of exported properties files.
   88.69 -     */
   88.70 -    private static final String EXTERNAL_XML_VERSION = "1.0";
   88.71 -
   88.72 -    static void load(Properties props, InputStream in)
   88.73 -        throws IOException, InvalidPropertiesFormatException
   88.74 -    {
   88.75 -        Document doc = null;
   88.76 -        try {
   88.77 -            doc = getLoadingDoc(in);
   88.78 -        } catch (SAXException saxe) {
   88.79 -            throw new InvalidPropertiesFormatException(saxe);
   88.80 -        }
   88.81 -        Element propertiesElement = (Element)doc.getChildNodes().item(1);
   88.82 -        String xmlVersion = propertiesElement.getAttribute("version");
   88.83 -        if (xmlVersion.compareTo(EXTERNAL_XML_VERSION) > 0)
   88.84 -            throw new InvalidPropertiesFormatException(
   88.85 -                "Exported Properties file format version " + xmlVersion +
   88.86 -                " is not supported. This java installation can read" +
   88.87 -                " versions " + EXTERNAL_XML_VERSION + " or older. You" +
   88.88 -                " may need to install a newer version of JDK.");
   88.89 -        importProperties(props, propertiesElement);
   88.90 -    }
   88.91 -
   88.92 -    static Document getLoadingDoc(InputStream in)
   88.93 -        throws SAXException, IOException
   88.94 -    {
   88.95 -        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
   88.96 -        dbf.setIgnoringElementContentWhitespace(true);
   88.97 -        dbf.setValidating(true);
   88.98 -        dbf.setCoalescing(true);
   88.99 -        dbf.setIgnoringComments(true);
  88.100 -        try {
  88.101 -            DocumentBuilder db = dbf.newDocumentBuilder();
  88.102 -            db.setEntityResolver(new Resolver());
  88.103 -            db.setErrorHandler(new EH());
  88.104 -            InputSource is = new InputSource(in);
  88.105 -            return db.parse(is);
  88.106 -        } catch (ParserConfigurationException x) {
  88.107 -            throw new Error(x);
  88.108 -        }
  88.109 -    }
  88.110 -
  88.111 -    static void importProperties(Properties props, Element propertiesElement) {
  88.112 -        NodeList entries = propertiesElement.getChildNodes();
  88.113 -        int numEntries = entries.getLength();
  88.114 -        int start = numEntries > 0 &&
  88.115 -            entries.item(0).getNodeName().equals("comment") ? 1 : 0;
  88.116 -        for (int i=start; i<numEntries; i++) {
  88.117 -            Element entry = (Element)entries.item(i);
  88.118 -            if (entry.hasAttribute("key")) {
  88.119 -                Node n = entry.getFirstChild();
  88.120 -                String val = (n == null) ? "" : n.getNodeValue();
  88.121 -                props.setProperty(entry.getAttribute("key"), val);
  88.122 -            }
  88.123 -        }
  88.124 -    }
  88.125 -
  88.126 -    static void save(Properties props, OutputStream os, String comment,
  88.127 -                     String encoding)
  88.128 -        throws IOException
  88.129 -    {
  88.130 -        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
  88.131 -        DocumentBuilder db = null;
  88.132 -        try {
  88.133 -            db = dbf.newDocumentBuilder();
  88.134 -        } catch (ParserConfigurationException pce) {
  88.135 -            assert(false);
  88.136 -        }
  88.137 -        Document doc = db.newDocument();
  88.138 -        Element properties =  (Element)
  88.139 -            doc.appendChild(doc.createElement("properties"));
  88.140 -
  88.141 -        if (comment != null) {
  88.142 -            Element comments = (Element)properties.appendChild(
  88.143 -                doc.createElement("comment"));
  88.144 -            comments.appendChild(doc.createTextNode(comment));
  88.145 -        }
  88.146 -
  88.147 -        synchronized (props) {
  88.148 -            for (String key : props.stringPropertyNames()) {
  88.149 -                Element entry = (Element)properties.appendChild(
  88.150 -                    doc.createElement("entry"));
  88.151 -                entry.setAttribute("key", key);
  88.152 -                entry.appendChild(doc.createTextNode(props.getProperty(key)));
  88.153 -            }
  88.154 -        }
  88.155 -        emitDocument(doc, os, encoding);
  88.156 -    }
  88.157 -
  88.158 -    static void emitDocument(Document doc, OutputStream os, String encoding)
  88.159 -        throws IOException
  88.160 -    {
  88.161 -        TransformerFactory tf = TransformerFactory.newInstance();
  88.162 -        Transformer t = null;
  88.163 -        try {
  88.164 -            t = tf.newTransformer();
  88.165 -            t.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, PROPS_DTD_URI);
  88.166 -            t.setOutputProperty(OutputKeys.INDENT, "yes");
  88.167 -            t.setOutputProperty(OutputKeys.METHOD, "xml");
  88.168 -            t.setOutputProperty(OutputKeys.ENCODING, encoding);
  88.169 -        } catch (TransformerConfigurationException tce) {
  88.170 -            assert(false);
  88.171 -        }
  88.172 -        DOMSource doms = new DOMSource(doc);
  88.173 -        StreamResult sr = new StreamResult(os);
  88.174 -        try {
  88.175 -            t.transform(doms, sr);
  88.176 -        } catch (TransformerException te) {
  88.177 -            IOException ioe = new IOException();
  88.178 -            ioe.initCause(te);
  88.179 -            throw ioe;
  88.180 -        }
  88.181 -    }
  88.182 -
  88.183 -    private static class Resolver implements EntityResolver {
  88.184 -        public InputSource resolveEntity(String pid, String sid)
  88.185 -            throws SAXException
  88.186 -        {
  88.187 -            if (sid.equals(PROPS_DTD_URI)) {
  88.188 -                InputSource is;
  88.189 -                is = new InputSource(new StringReader(PROPS_DTD));
  88.190 -                is.setSystemId(PROPS_DTD_URI);
  88.191 -                return is;
  88.192 -            }
  88.193 -            throw new SAXException("Invalid system identifier: " + sid);
  88.194 -        }
  88.195 -    }
  88.196 -
  88.197 -    private static class EH implements ErrorHandler {
  88.198 -        public void error(SAXParseException x) throws SAXException {
  88.199 -            throw x;
  88.200 -        }
  88.201 -        public void fatalError(SAXParseException x) throws SAXException {
  88.202 -            throw x;
  88.203 -        }
  88.204 -        public void warning(SAXParseException x) throws SAXException {
  88.205 -            throw x;
  88.206 -        }
  88.207 -    }
  88.208 -
  88.209 -}
    89.1 --- a/src/share/classes/java/util/concurrent/ScheduledThreadPoolExecutor.java	Fri Sep 30 17:20:56 2011 -0700
    89.2 +++ b/src/share/classes/java/util/concurrent/ScheduledThreadPoolExecutor.java	Tue Oct 04 12:39:42 2011 -0700
    89.3 @@ -330,7 +330,7 @@
    89.4                  remove(task))
    89.5                  task.cancel(false);
    89.6              else
    89.7 -                prestartCoreThread();
    89.8 +                ensurePrestart();
    89.9          }
   89.10      }
   89.11  
   89.12 @@ -346,7 +346,7 @@
   89.13              if (!canRunInCurrentRunState(true) && remove(task))
   89.14                  task.cancel(false);
   89.15              else
   89.16 -                prestartCoreThread();
   89.17 +                ensurePrestart();
   89.18          }
   89.19      }
   89.20  
    90.1 --- a/src/share/classes/java/util/concurrent/ThreadPoolExecutor.java	Fri Sep 30 17:20:56 2011 -0700
    90.2 +++ b/src/share/classes/java/util/concurrent/ThreadPoolExecutor.java	Tue Oct 04 12:39:42 2011 -0700
    90.3 @@ -1546,6 +1546,18 @@
    90.4      }
    90.5  
    90.6      /**
    90.7 +     * Same as prestartCoreThread except arranges that at least one
    90.8 +     * thread is started even if corePoolSize is 0.
    90.9 +     */
   90.10 +    void ensurePrestart() {
   90.11 +        int wc = workerCountOf(ctl.get());
   90.12 +        if (wc < corePoolSize)
   90.13 +            addWorker(null, true);
   90.14 +        else if (wc == 0)
   90.15 +            addWorker(null, false);
   90.16 +    }
   90.17 +
   90.18 +    /**
   90.19       * Starts all core threads, causing them to idly wait for work. This
   90.20       * overrides the default policy of starting core threads only when
   90.21       * new tasks are executed.
    91.1 --- a/src/share/classes/javax/net/ssl/SSLServerSocketFactory.java	Fri Sep 30 17:20:56 2011 -0700
    91.2 +++ b/src/share/classes/javax/net/ssl/SSLServerSocketFactory.java	Tue Oct 04 12:39:42 2011 -0700
    91.3 @@ -1,5 +1,5 @@
    91.4  /*
    91.5 - * Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved.
    91.6 + * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
    91.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    91.8   *
    91.9   * This code is free software; you can redistribute it and/or modify it
   91.10 @@ -87,7 +87,7 @@
   91.11              if (clsName != null) {
   91.12                  log("setting up default SSLServerSocketFactory");
   91.13                  try {
   91.14 -                    Class cls = null;
   91.15 +                    Class<?> cls = null;
   91.16                      try {
   91.17                          cls = Class.forName(clsName);
   91.18                      } catch (ClassNotFoundException e) {
    92.1 --- a/src/share/classes/javax/net/ssl/SSLSocketFactory.java	Fri Sep 30 17:20:56 2011 -0700
    92.2 +++ b/src/share/classes/javax/net/ssl/SSLSocketFactory.java	Tue Oct 04 12:39:42 2011 -0700
    92.3 @@ -1,5 +1,5 @@
    92.4  /*
    92.5 - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
    92.6 + * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
    92.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    92.8   *
    92.9   * This code is free software; you can redistribute it and/or modify it
   92.10 @@ -95,7 +95,7 @@
   92.11              if (clsName != null) {
   92.12                  log("setting up default SSLSocketFactory");
   92.13                  try {
   92.14 -                    Class cls = null;
   92.15 +                    Class<?> cls = null;
   92.16                      try {
   92.17                          cls = Class.forName(clsName);
   92.18                      } catch (ClassNotFoundException e) {
    93.1 --- a/src/share/classes/javax/swing/SwingUtilities.java	Fri Sep 30 17:20:56 2011 -0700
    93.2 +++ b/src/share/classes/javax/swing/SwingUtilities.java	Tue Oct 04 12:39:42 2011 -0700
    93.3 @@ -792,7 +792,7 @@
    93.4       * @return true if the left mouse button was active
    93.5       */
    93.6      public static boolean isLeftMouseButton(MouseEvent anEvent) {
    93.7 -         return ((anEvent.getModifiers() & InputEvent.BUTTON1_MASK) != 0);
    93.8 +         return (anEvent.getButton() == MouseEvent.BUTTON1);
    93.9      }
   93.10  
   93.11      /**
   93.12 @@ -802,7 +802,7 @@
   93.13       * @return true if the middle mouse button was active
   93.14       */
   93.15      public static boolean isMiddleMouseButton(MouseEvent anEvent) {
   93.16 -        return ((anEvent.getModifiers() & InputEvent.BUTTON2_MASK) == InputEvent.BUTTON2_MASK);
   93.17 +        return (anEvent.getButton() == MouseEvent.BUTTON2);
   93.18      }
   93.19  
   93.20      /**
   93.21 @@ -812,7 +812,7 @@
   93.22       * @return true if the right mouse button was active
   93.23       */
   93.24      public static boolean isRightMouseButton(MouseEvent anEvent) {
   93.25 -        return ((anEvent.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK);
   93.26 +        return (anEvent.getButton() == MouseEvent.BUTTON3);
   93.27      }
   93.28  
   93.29      /**
    94.1 --- a/src/share/classes/javax/swing/plaf/nimbus/doc-files/properties.html	Fri Sep 30 17:20:56 2011 -0700
    94.2 +++ b/src/share/classes/javax/swing/plaf/nimbus/doc-files/properties.html	Tue Oct 04 12:39:42 2011 -0700
    94.3 @@ -1,6 +1,5 @@
    94.4  <html>
    94.5  <head>
    94.6 -<link href="style.css" rel="stylesheet" type="text/css" />
    94.7  </head>
    94.8  <body>
    94.9  <h1 id="primaryColors">Primary Colors</h1>
    95.1 --- a/src/share/classes/org/ietf/jgss/Oid.java	Fri Sep 30 17:20:56 2011 -0700
    95.2 +++ b/src/share/classes/org/ietf/jgss/Oid.java	Tue Oct 04 12:39:42 2011 -0700
    95.3 @@ -157,7 +157,7 @@
    95.4              return (true);
    95.5  
    95.6          if (other instanceof Oid)
    95.7 -            return this.oid.equals(((Oid) other).oid);
    95.8 +            return this.oid.equals((Object)((Oid) other).oid);
    95.9          else if (other instanceof ObjectIdentifier)
   95.10              return this.oid.equals(other);
   95.11          else
    96.1 --- a/src/share/classes/sun/misc/FloatingDecimal.java	Fri Sep 30 17:20:56 2011 -0700
    96.2 +++ b/src/share/classes/sun/misc/FloatingDecimal.java	Tue Oct 04 12:39:42 2011 -0700
    96.3 @@ -25,7 +25,6 @@
    96.4  
    96.5  package sun.misc;
    96.6  
    96.7 -import sun.misc.FpUtils;
    96.8  import sun.misc.DoubleConsts;
    96.9  import sun.misc.FloatConsts;
   96.10  import java.util.regex.*;
   96.11 @@ -2297,9 +2296,9 @@
   96.12                      significand++;
   96.13                  }
   96.14  
   96.15 -                FloatingDecimal fd = new FloatingDecimal(FpUtils.rawCopySign(
   96.16 -                                                                 Double.longBitsToDouble(significand),
   96.17 -                                                                 sign));
   96.18 +                FloatingDecimal fd = new FloatingDecimal(Math.copySign(
   96.19 +                                                              Double.longBitsToDouble(significand),
   96.20 +                                                              sign));
   96.21  
   96.22                  /*
   96.23                   * Set roundingDir variable field of fd properly so
    97.1 --- a/src/share/classes/sun/misc/FormattedFloatingDecimal.java	Fri Sep 30 17:20:56 2011 -0700
    97.2 +++ b/src/share/classes/sun/misc/FormattedFloatingDecimal.java	Tue Oct 04 12:39:42 2011 -0700
    97.3 @@ -25,7 +25,6 @@
    97.4  
    97.5  package sun.misc;
    97.6  
    97.7 -import sun.misc.FpUtils;
    97.8  import sun.misc.DoubleConsts;
    97.9  import sun.misc.FloatConsts;
   97.10  import java.util.regex.*;
    98.1 --- a/src/share/classes/sun/misc/FpUtils.java	Fri Sep 30 17:20:56 2011 -0700
    98.2 +++ b/src/share/classes/sun/misc/FpUtils.java	Tue Oct 04 12:39:42 2011 -0700
    98.3 @@ -1,5 +1,5 @@
    98.4  /*
    98.5 - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
    98.6 + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
    98.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    98.8   *
    98.9   * This code is free software; you can redistribute it and/or modify it
   98.10 @@ -125,10 +125,6 @@
   98.11       */
   98.12      private FpUtils() {}
   98.13  
   98.14 -    // Constants used in scalb
   98.15 -    static double twoToTheDoubleScaleUp = powerOfTwoD(512);
   98.16 -    static double twoToTheDoubleScaleDown = powerOfTwoD(-512);
   98.17 -
   98.18      // Helper Methods
   98.19  
   98.20      // The following helper methods are used in the implementation of
   98.21 @@ -137,49 +133,22 @@
   98.22  
   98.23      /**
   98.24       * Returns unbiased exponent of a {@code double}.
   98.25 +     * @deprecated Use Math.getExponent.
   98.26       */
   98.27 +    @Deprecated
   98.28      public static int getExponent(double d){
   98.29 -        /*
   98.30 -         * Bitwise convert d to long, mask out exponent bits, shift
   98.31 -         * to the right and then subtract out double's bias adjust to
   98.32 -         * get true exponent value.
   98.33 -         */
   98.34 -        return (int)(((Double.doubleToRawLongBits(d) & DoubleConsts.EXP_BIT_MASK) >>
   98.35 -                      (DoubleConsts.SIGNIFICAND_WIDTH - 1)) - DoubleConsts.EXP_BIAS);
   98.36 +        return Math.getExponent(d);
   98.37      }
   98.38  
   98.39      /**
   98.40       * Returns unbiased exponent of a {@code float}.
   98.41 +     * @deprecated Use Math.getExponent.
   98.42       */
   98.43 +    @Deprecated
   98.44      public static int getExponent(float f){
   98.45 -        /*
   98.46 -         * Bitwise convert f to integer, mask out exponent bits, shift
   98.47 -         * to the right and then subtract out float's bias adjust to
   98.48 -         * get true exponent value
   98.49 -         */
   98.50 -        return ((Float.floatToRawIntBits(f) & FloatConsts.EXP_BIT_MASK) >>
   98.51 -                (FloatConsts.SIGNIFICAND_WIDTH - 1)) - FloatConsts.EXP_BIAS;
   98.52 +        return Math.getExponent(f);
   98.53      }
   98.54  
   98.55 -    /**
   98.56 -     * Returns a floating-point power of two in the normal range.
   98.57 -     */
   98.58 -    static double powerOfTwoD(int n) {
   98.59 -        assert(n >= DoubleConsts.MIN_EXPONENT && n <= DoubleConsts.MAX_EXPONENT);
   98.60 -        return Double.longBitsToDouble((((long)n + (long)DoubleConsts.EXP_BIAS) <<
   98.61 -                                        (DoubleConsts.SIGNIFICAND_WIDTH-1))
   98.62 -                                       & DoubleConsts.EXP_BIT_MASK);
   98.63 -    }
   98.64 -
   98.65 -    /**
   98.66 -     * Returns a floating-point power of two in the normal range.
   98.67 -     */
   98.68 -    static float powerOfTwoF(int n) {
   98.69 -        assert(n >= FloatConsts.MIN_EXPONENT && n <= FloatConsts.MAX_EXPONENT);
   98.70 -        return Float.intBitsToFloat(((n + FloatConsts.EXP_BIAS) <<
   98.71 -                                     (FloatConsts.SIGNIFICAND_WIDTH-1))
   98.72 -                                    & FloatConsts.EXP_BIT_MASK);
   98.73 -    }
   98.74  
   98.75      /**
   98.76       * Returns the first floating-point argument with the sign of the
   98.77 @@ -195,13 +164,11 @@
   98.78       * @return a value with the magnitude of {@code magnitude}
   98.79       * and the sign of {@code sign}.
   98.80       * @author Joseph D. Darcy
   98.81 +     * @deprecated Use Math.copySign.
   98.82       */
   98.83 +    @Deprecated
   98.84      public static double rawCopySign(double magnitude, double sign) {
   98.85 -        return Double.longBitsToDouble((Double.doubleToRawLongBits(sign) &
   98.86 -                                        (DoubleConsts.SIGN_BIT_MASK)) |
   98.87 -                                       (Double.doubleToRawLongBits(magnitude) &
   98.88 -                                        (DoubleConsts.EXP_BIT_MASK |
   98.89 -                                         DoubleConsts.SIGNIF_BIT_MASK)));
   98.90 +        return Math.copySign(magnitude, sign);
   98.91      }
   98.92  
   98.93      /**
   98.94 @@ -218,13 +185,11 @@
   98.95       * @return a value with the magnitude of {@code magnitude}
   98.96       * and the sign of {@code sign}.
   98.97       * @author Joseph D. Darcy
   98.98 +     * @deprecated Use Math.copySign.
   98.99       */
  98.100 +    @Deprecated
  98.101      public static float rawCopySign(float magnitude, float sign) {
  98.102 -        return Float.intBitsToFloat((Float.floatToRawIntBits(sign) &
  98.103 -                                     (FloatConsts.SIGN_BIT_MASK)) |
  98.104 -                                    (Float.floatToRawIntBits(magnitude) &
  98.105 -                                     (FloatConsts.EXP_BIT_MASK |
  98.106 -                                      FloatConsts.SIGNIF_BIT_MASK)));
  98.107 +        return Math.copySign(magnitude, sign);
  98.108      }
  98.109  
  98.110      /* ***************************************************************** */
  98.111 @@ -237,9 +202,11 @@
  98.112       * @param d the {@code double} value to be tested
  98.113       * @return {@code true} if the argument is a finite
  98.114       * floating-point value, {@code false} otherwise.
  98.115 +     * @deprecated Use Double.isFinite.
  98.116       */
  98.117 +    @Deprecated
  98.118      public static boolean isFinite(double d) {
  98.119 -        return Math.abs(d) <= DoubleConsts.MAX_VALUE;
  98.120 +        return Double.isFinite(d);
  98.121      }
  98.122  
  98.123      /**
  98.124 @@ -250,9 +217,11 @@
  98.125       * @param f the {@code float} value to be tested
  98.126       * @return {@code true} if the argument is a finite
  98.127       * floating-point value, {@code false} otherwise.
  98.128 +     * @deprecated Use Float.isFinite.
  98.129       */
  98.130 +     @Deprecated
  98.131       public static boolean isFinite(float f) {
  98.132 -        return Math.abs(f) <= FloatConsts.MAX_VALUE;
  98.133 +         return Float.isFinite(f);
  98.134      }
  98.135  
  98.136      /**
  98.137 @@ -558,82 +527,11 @@
  98.138       * @param scale_factor power of 2 used to scale {@code d}
  98.139       * @return {@code d * }2<sup>{@code scale_factor}</sup>
  98.140       * @author Joseph D. Darcy
  98.141 +     * @deprecated Use Math.scalb.
  98.142       */
  98.143 +    @Deprecated
  98.144      public static double scalb(double d, int scale_factor) {
  98.145 -        /*
  98.146 -         * This method does not need to be declared strictfp to
  98.147 -         * compute the same correct result on all platforms.  When
  98.148 -         * scaling up, it does not matter what order the
  98.149 -         * multiply-store operations are done; the result will be
  98.150 -         * finite or overflow regardless of the operation ordering.
  98.151 -         * However, to get the correct result when scaling down, a
  98.152 -         * particular ordering must be used.
  98.153 -         *
  98.154 -         * When scaling down, the multiply-store operations are
  98.155 -         * sequenced so that it is not possible for two consecutive
  98.156 -         * multiply-stores to return subnormal results.  If one
  98.157 -         * multiply-store result is subnormal, the next multiply will
  98.158 -         * round it away to zero.  This is done by first multiplying
  98.159 -         * by 2 ^ (scale_factor % n) and then multiplying several
  98.160 -         * times by by 2^n as needed where n is the exponent of number
  98.161 -         * that is a covenient power of two.  In this way, at most one
  98.162 -         * real rounding error occurs.  If the double value set is
  98.163 -         * being used exclusively, the rounding will occur on a
  98.164 -         * multiply.  If the double-extended-exponent value set is
  98.165 -         * being used, the products will (perhaps) be exact but the
  98.166 -         * stores to d are guaranteed to round to the double value
  98.167 -         * set.
  98.168 -         *
  98.169 -         * It is _not_ a valid implementation to first multiply d by
  98.170 -         * 2^MIN_EXPONENT and then by 2 ^ (scale_factor %
  98.171 -         * MIN_EXPONENT) since even in a strictfp program double
  98.172 -         * rounding on underflow could occur; e.g. if the scale_factor
  98.173 -         * argument was (MIN_EXPONENT - n) and the exponent of d was a
  98.174 -         * little less than -(MIN_EXPONENT - n), meaning the final
  98.175 -         * result would be subnormal.
  98.176 -         *
  98.177 -         * Since exact reproducibility of this method can be achieved
  98.178 -         * without any undue performance burden, there is no
  98.179 -         * compelling reason to allow double rounding on underflow in
  98.180 -         * scalb.
  98.181 -         */
  98.182 -
  98.183 -        // magnitude of a power of two so large that scaling a finite
  98.184 -        // nonzero value by it would be guaranteed to over or
  98.185 -        // underflow; due to rounding, scaling down takes takes an
  98.186 -        // additional power of two which is reflected here
  98.187 -        final int MAX_SCALE = DoubleConsts.MAX_EXPONENT + -DoubleConsts.MIN_EXPONENT +
  98.188 -                              DoubleConsts.SIGNIFICAND_WIDTH + 1;
  98.189 -        int exp_adjust = 0;
  98.190 -        int scale_increment = 0;
  98.191 -        double exp_delta = Double.NaN;
  98.192 -
  98.193 -        // Make sure scaling factor is in a reasonable range
  98.194 -
  98.195 -        if(scale_factor < 0) {
  98.196 -            scale_factor = Math.max(scale_factor, -MAX_SCALE);
  98.197 -            scale_increment = -512;
  98.198 -            exp_delta = twoToTheDoubleScaleDown;
  98.199 -        }
  98.200 -        else {
  98.201 -            scale_factor = Math.min(scale_factor, MAX_SCALE);
  98.202 -            scale_increment = 512;
  98.203 -            exp_delta = twoToTheDoubleScaleUp;
  98.204 -        }
  98.205 -
  98.206 -        // Calculate (scale_factor % +/-512), 512 = 2^9, using
  98.207 -        // technique from "Hacker's Delight" section 10-2.
  98.208 -        int t = (scale_factor >> 9-1) >>> 32 - 9;
  98.209 -        exp_adjust = ((scale_factor + t) & (512 -1)) - t;
  98.210 -
  98.211 -        d *= powerOfTwoD(exp_adjust);
  98.212 -        scale_factor -= exp_adjust;
  98.213 -
  98.214 -        while(scale_factor != 0) {
  98.215 -            d *= exp_delta;
  98.216 -            scale_factor -= scale_increment;
  98.217 -        }
  98.218 -        return d;
  98.219 +        return Math.scalb(d, scale_factor);
  98.220      }
  98.221  
  98.222      /**
  98.223 @@ -667,28 +565,11 @@
  98.224       * @param scale_factor power of 2 used to scale {@code f}
  98.225       * @return {@code f * }2<sup>{@code scale_factor}</sup>
  98.226       * @author Joseph D. Darcy
  98.227 +     * @deprecated Use Math.scalb.
  98.228       */
  98.229 -     public static float scalb(float f, int scale_factor) {
  98.230 -        // magnitude of a power of two so large that scaling a finite
  98.231 -        // nonzero value by it would be guaranteed to over or
  98.232 -        // underflow; due to rounding, scaling down takes takes an
  98.233 -        // additional power of two which is reflected here
  98.234 -        final int MAX_SCALE = FloatConsts.MAX_EXPONENT + -FloatConsts.MIN_EXPONENT +
  98.235 -                              FloatConsts.SIGNIFICAND_WIDTH + 1;
  98.236 -
  98.237 -        // Make sure scaling factor is in a reasonable range
  98.238 -        scale_factor = Math.max(Math.min(scale_factor, MAX_SCALE), -MAX_SCALE);
  98.239 -
  98.240 -        /*
  98.241 -         * Since + MAX_SCALE for float fits well within the double
  98.242 -         * exponent range and + float -> double conversion is exact
  98.243 -         * the multiplication below will be exact. Therefore, the
  98.244 -         * rounding that occurs when the double product is cast to
  98.245 -         * float will be the correctly rounded float result.  Since
  98.246 -         * all operations other than the final multiply will be exact,
  98.247 -         * it is not necessary to declare this method strictfp.
  98.248 -         */
  98.249 -        return (float)((double)f*powerOfTwoD(scale_factor));
  98.250 +    @Deprecated
  98.251 +    public static float scalb(float f, int scale_factor) {
  98.252 +        return Math.scalb(f, scale_factor);
  98.253      }
  98.254  
  98.255      /**
  98.256 @@ -730,65 +611,11 @@
  98.257       * @return The floating-point number adjacent to {@code start} in the
  98.258       * direction of {@code direction}.
  98.259       * @author Joseph D. Darcy
  98.260 +     * @deprecated Use Math.nextAfter
  98.261       */
  98.262 +    @Deprecated
  98.263      public static double nextAfter(double start, double direction) {
  98.264 -        /*
  98.265 -         * The cases:
  98.266 -         *
  98.267 -         * nextAfter(+infinity, 0)  == MAX_VALUE
  98.268 -         * nextAfter(+infinity, +infinity)  == +infinity
  98.269 -         * nextAfter(-infinity, 0)  == -MAX_VALUE
  98.270 -         * nextAfter(-infinity, -infinity)  == -infinity
  98.271 -         *
  98.272 -         * are naturally handled without any additional testing
  98.273 -         */
  98.274 -
  98.275 -        // First check for NaN values
  98.276 -        if (isNaN(start) || isNaN(direction)) {
  98.277 -            // return a NaN derived from the input NaN(s)
  98.278 -            return start + direction;
  98.279 -        } else if (start == direction) {
  98.280 -            return direction;
  98.281 -        } else {        // start > direction or start < direction
  98.282 -            // Add +0.0 to get rid of a -0.0 (+0.0 + -0.0 => +0.0)
  98.283 -            // then bitwise convert start to integer.
  98.284 -            long transducer = Double.doubleToRawLongBits(start + 0.0d);
  98.285 -
  98.286 -            /*
  98.287 -             * IEEE 754 floating-point numbers are lexicographically
  98.288 -             * ordered if treated as signed- magnitude integers .
  98.289 -             * Since Java's integers are two's complement,
  98.290 -             * incrementing" the two's complement representation of a
  98.291 -             * logically negative floating-point value *decrements*
  98.292 -             * the signed-magnitude representation. Therefore, when
  98.293 -             * the integer representation of a floating-point values
  98.294 -             * is less than zero, the adjustment to the representation
  98.295 -             * is in the opposite direction than would be expected at
  98.296 -             * first .
  98.297 -             */
  98.298 -            if (direction > start) { // Calculate next greater value
  98.299 -                transducer = transducer + (transducer >= 0L ? 1L:-1L);
  98.300 -            } else  { // Calculate next lesser value
  98.301 -                assert direction < start;
  98.302 -                if (transducer > 0L)
  98.303 -                    --transducer;
  98.304 -                else
  98.305 -                    if (transducer < 0L )
  98.306 -                        ++transducer;
  98.307 -                    /*
  98.308 -                     * transducer==0, the result is -MIN_VALUE
  98.309 -                     *
  98.310 -                     * The transition from zero (implicitly
  98.311 -                     * positive) to the smallest negative
  98.312 -                     * signed magnitude value must be done
  98.313 -                     * explicitly.
  98.314 -                     */
  98.315 -                    else
  98.316 -                        transducer = DoubleConsts.SIGN_BIT_MASK | 1L;
  98.317 -            }
  98.318 -
  98.319 -            return Double.longBitsToDouble(transducer);
  98.320 -        }
  98.321 +        return Math.nextAfter(start, direction);
  98.322      }
  98.323  
  98.324      /**
  98.325 @@ -830,65 +657,11 @@
  98.326       * @return The floating-point number adjacent to {@code start} in the
  98.327       * direction of {@code direction}.
  98.328       * @author Joseph D. Darcy
  98.329 +     * @deprecated Use Math.nextAfter.
  98.330       */
  98.331 -     public static float nextAfter(float start, double direction) {
  98.332 -        /*
  98.333 -         * The cases:
  98.334 -         *
  98.335 -         * nextAfter(+infinity, 0)  == MAX_VALUE
  98.336 -         * nextAfter(+infinity, +infinity)  == +infinity
  98.337 -         * nextAfter(-infinity, 0)  == -MAX_VALUE
  98.338 -         * nextAfter(-infinity, -infinity)  == -infinity
  98.339 -         *
  98.340 -         * are naturally handled without any additional testing
  98.341 -         */
  98.342 -
  98.343 -        // First check for NaN values
  98.344 -        if (isNaN(start) || isNaN(direction)) {
  98.345 -            // return a NaN derived from the input NaN(s)
  98.346 -            return start + (float)direction;
  98.347 -        } else if (start == direction) {
  98.348 -            return (float)direction;
  98.349 -        } else {        // start > direction or start < direction
  98.350 -            // Add +0.0 to get rid of a -0.0 (+0.0 + -0.0 => +0.0)
  98.351 -            // then bitwise convert start to integer.
  98.352 -            int transducer = Float.floatToRawIntBits(start + 0.0f);
  98.353 -
  98.354 -            /*
  98.355 -             * IEEE 754 floating-point numbers are lexicographically
  98.356 -             * ordered if treated as signed- magnitude integers .
  98.357 -             * Since Java's integers are two's complement,
  98.358 -             * incrementing" the two's complement representation of a
  98.359 -             * logically negative floating-point value *decrements*
  98.360 -             * the signed-magnitude representation. Therefore, when
  98.361 -             * the integer representation of a floating-point values
  98.362 -             * is less than zero, the adjustment to the representation
  98.363 -             * is in the opposite direction than would be expected at
  98.364 -             * first.
  98.365 -             */
  98.366 -            if (direction > start) {// Calculate next greater value
  98.367 -                transducer = transducer + (transducer >= 0 ? 1:-1);
  98.368 -            } else  { // Calculate next lesser value
  98.369 -                assert direction < start;
  98.370 -                if (transducer > 0)
  98.371 -                    --transducer;
  98.372 -                else
  98.373 -                    if (transducer < 0 )
  98.374 -                        ++transducer;
  98.375 -                    /*
  98.376 -                     * transducer==0, the result is -MIN_VALUE
  98.377 -                     *
  98.378 -                     * The transition from zero (implicitly
  98.379 -                     * positive) to the smallest negative
  98.380 -                     * signed magnitude value must be done
  98.381 -                     * explicitly.
  98.382 -                     */
  98.383 -                    else
  98.384 -                        transducer = FloatConsts.SIGN_BIT_MASK | 1;
  98.385 -            }
  98.386 -
  98.387 -            return Float.intBitsToFloat(transducer);
  98.388 -        }
  98.389 +    @Deprecated
  98.390 +    public static float nextAfter(float start, double direction) {
  98.391 +        return Math.nextAfter(start, direction);
  98.392      }
  98.393  
  98.394      /**
  98.395 @@ -915,15 +688,11 @@
  98.396       * @return The adjacent floating-point value closer to positive
  98.397       * infinity.
  98.398       * @author Joseph D. Darcy
  98.399 +     * @deprecated use Math.nextUp.
  98.400       */
  98.401 +    @Deprecated
  98.402      public static double nextUp(double d) {
  98.403 -        if( isNaN(d) || d == Double.POSITIVE_INFINITY)
  98.404 -            return d;
  98.405 -        else {
  98.406 -            d += 0.0d;
  98.407 -            return Double.longBitsToDouble(Double.doubleToRawLongBits(d) +
  98.408 -                                           ((d >= 0.0d)?+1L:-1L));
  98.409 -        }
  98.410 +        return Math.nextUp(d);
  98.411      }
  98.412  
  98.413      /**
  98.414 @@ -950,15 +719,11 @@
  98.415       * @return The adjacent floating-point value closer to positive
  98.416       * infinity.
  98.417       * @author Joseph D. Darcy
  98.418 +     * @deprecated Use Math.nextUp.
  98.419       */
  98.420 -     public static float nextUp(float f) {
  98.421 -        if( isNaN(f) || f == FloatConsts.POSITIVE_INFINITY)
  98.422 -            return f;
  98.423 -        else {
  98.424 -            f += 0.0f;
  98.425 -            return Float.intBitsToFloat(Float.floatToRawIntBits(f) +
  98.426 -                                        ((f >= 0.0f)?+1:-1));
  98.427 -        }
  98.428 +    @Deprecated
  98.429 +    public static float nextUp(float f) {
  98.430 +        return Math.nextUp(f);
  98.431      }
  98.432  
  98.433      /**
  98.434 @@ -985,17 +750,11 @@
  98.435       * @return The adjacent floating-point value closer to negative
  98.436       * infinity.
  98.437       * @author Joseph D. Darcy
  98.438 +     * @deprecated Use Math.nextDown.
  98.439       */
  98.440 +    @Deprecated
  98.441      public static double nextDown(double d) {
  98.442 -        if( isNaN(d) || d == Double.NEGATIVE_INFINITY)
  98.443 -            return d;
  98.444 -        else {
  98.445 -            if (d == 0.0)
  98.446 -                return -Double.MIN_VALUE;
  98.447 -            else
  98.448 -                return Double.longBitsToDouble(Double.doubleToRawLongBits(d) +
  98.449 -                                               ((d > 0.0d)?-1L:+1L));
  98.450 -        }
  98.451 +        return Math.nextDown(d);
  98.452      }
  98.453  
  98.454      /**
  98.455 @@ -1022,17 +781,11 @@
  98.456       * @return The adjacent floating-point value closer to negative
  98.457       * infinity.
  98.458       * @author Joseph D. Darcy
  98.459 +     * @deprecated Use Math.nextDown.
  98.460       */
  98.461 +    @Deprecated
  98.462      public static double nextDown(float f) {
  98.463 -        if( isNaN(f) || f == Float.NEGATIVE_INFINITY)
  98.464 -            return f;
  98.465 -        else {
  98.466 -            if (f == 0.0f)
  98.467 -                return -Float.MIN_VALUE;
  98.468 -            else
  98.469 -                return Float.intBitsToFloat(Float.floatToRawIntBits(f) +
  98.470 -                                            ((f > 0.0f)?-1:+1));
  98.471 -        }
  98.472 +        return Math.nextDown(f);
  98.473      }
  98.474  
  98.475      /**
  98.476 @@ -1047,9 +800,11 @@
  98.477       * and the sign of {@code sign}.
  98.478       * @author Joseph D. Darcy
  98.479       * @since 1.5
  98.480 +     * @deprecated Use StrictMath.copySign.
  98.481       */
  98.482 +    @Deprecated
  98.483      public static double copySign(double magnitude, double sign) {
  98.484 -        return rawCopySign(magnitude, (isNaN(sign)?1.0d:sign));
  98.485 +        return StrictMath.copySign(magnitude, sign);
  98.486      }
  98.487  
  98.488      /**
  98.489 @@ -1063,9 +818,11 @@
  98.490       * @return a value with the magnitude of {@code magnitude}
  98.491       * and the sign of {@code sign}.
  98.492       * @author Joseph D. Darcy
  98.493 +     * @deprecated Use StrictMath.copySign.
  98.494       */
  98.495 -     public static float copySign(float magnitude, float sign) {
  98.496 -        return rawCopySign(magnitude, (isNaN(sign)?1.0f:sign));
  98.497 +    @Deprecated
  98.498 +    public static float copySign(float magnitude, float sign) {
  98.499 +        return StrictMath.copySign(magnitude, sign);
  98.500      }
  98.501  
  98.502      /**
  98.503 @@ -1090,33 +847,11 @@
  98.504       * @return the size of an ulp of the argument
  98.505       * @author Joseph D. Darcy
  98.506       * @since 1.5
  98.507 +     * @deprecated Use Math.ulp.
  98.508       */
  98.509 +    @Deprecated
  98.510      public static double ulp(double d) {
  98.511 -        int exp = getExponent(d);
  98.512 -
  98.513 -        switch(exp) {
  98.514 -        case DoubleConsts.MAX_EXPONENT+1:       // NaN or infinity
  98.515 -            return Math.abs(d);
  98.516 -
  98.517 -        case DoubleConsts.MIN_EXPONENT-1:       // zero or subnormal
  98.518 -            return Double.MIN_VALUE;
  98.519 -
  98.520 -        default:
  98.521 -            assert exp <= DoubleConsts.MAX_EXPONENT && exp >= DoubleConsts.MIN_EXPONENT;
  98.522 -
  98.523 -            // ulp(x) is usually 2^(SIGNIFICAND_WIDTH-1)*(2^ilogb(x))
  98.524 -            exp = exp - (DoubleConsts.SIGNIFICAND_WIDTH-1);
  98.525 -            if (exp >= DoubleConsts.MIN_EXPONENT) {
  98.526 -                return powerOfTwoD(exp);
  98.527 -            }
  98.528 -            else {
  98.529 -                // return a subnormal result; left shift integer
  98.530 -                // representation of Double.MIN_VALUE appropriate
  98.531 -                // number of positions
  98.532 -                return Double.longBitsToDouble(1L <<
  98.533 -                (exp - (DoubleConsts.MIN_EXPONENT - (DoubleConsts.SIGNIFICAND_WIDTH-1)) ));
  98.534 -            }
  98.535 -        }
  98.536 +        return Math.ulp(d);
  98.537      }
  98.538  
  98.539      /**
  98.540 @@ -1141,33 +876,11 @@
  98.541       * @return the size of an ulp of the argument
  98.542       * @author Joseph D. Darcy
  98.543       * @since 1.5
  98.544 +     * @deprecated Use Math.ulp.
  98.545       */
  98.546 +     @Deprecated
  98.547       public static float ulp(float f) {
  98.548 -        int exp = getExponent(f);
  98.549 -
  98.550 -        switch(exp) {
  98.551 -        case FloatConsts.MAX_EXPONENT+1:        // NaN or infinity
  98.552 -            return Math.abs(f);
  98.553 -
  98.554 -        case FloatConsts.MIN_EXPONENT-1:        // zero or subnormal
  98.555 -            return FloatConsts.MIN_VALUE;
  98.556 -
  98.557 -        default:
  98.558 -            assert exp <= FloatConsts.MAX_EXPONENT && exp >= FloatConsts.MIN_EXPONENT;
  98.559 -
  98.560 -            // ulp(x) is usually 2^(SIGNIFICAND_WIDTH-1)*(2^ilogb(x))
  98.561 -            exp = exp - (FloatConsts.SIGNIFICAND_WIDTH-1);
  98.562 -            if (exp >= FloatConsts.MIN_EXPONENT) {
  98.563 -                return powerOfTwoF(exp);
  98.564 -            }
  98.565 -            else {
  98.566 -                // return a subnormal result; left shift integer
  98.567 -                // representation of FloatConsts.MIN_VALUE appropriate
  98.568 -                // number of positions
  98.569 -                return Float.intBitsToFloat(1 <<
  98.570 -                (exp - (FloatConsts.MIN_EXPONENT - (FloatConsts.SIGNIFICAND_WIDTH-1)) ));
  98.571 -            }
  98.572 -        }
  98.573 +        return Math.ulp(f);
  98.574       }
  98.575  
  98.576      /**
  98.577 @@ -1186,9 +899,11 @@
  98.578       * @return the signum function of the argument
  98.579       * @author Joseph D. Darcy
  98.580       * @since 1.5
  98.581 +     * @deprecated Use Math.signum.
  98.582       */
  98.583 +    @Deprecated
  98.584      public static double signum(double d) {
  98.585 -        return (d == 0.0 || isNaN(d))?d:copySign(1.0, d);
  98.586 +        return Math.signum(d);
  98.587      }
  98.588  
  98.589      /**
  98.590 @@ -1207,9 +922,10 @@
  98.591       * @return the signum function of the argument
  98.592       * @author Joseph D. Darcy
  98.593       * @since 1.5
  98.594 +     * @deprecated Use Math.signum.
  98.595       */
  98.596 +    @Deprecated
  98.597      public static float signum(float f) {
  98.598 -        return (f == 0.0f || isNaN(f))?f:copySign(1.0f, f);
  98.599 +        return Math.signum(f);
  98.600      }
  98.601 -
  98.602  }
    99.1 --- a/src/share/classes/sun/misc/REException.java	Fri Sep 30 17:20:56 2011 -0700
    99.2 +++ b/src/share/classes/sun/misc/REException.java	Tue Oct 04 12:39:42 2011 -0700
    99.3 @@ -31,6 +31,9 @@
    99.4   */
    99.5  
    99.6  public class REException extends Exception {
    99.7 +
    99.8 +    private static final long serialVersionUID = 4656584872733646963L;
    99.9 +
   99.10      REException (String s) {
   99.11          super(s);
   99.12      }
   100.1 --- a/src/share/classes/sun/net/TransferProtocolClient.java	Fri Sep 30 17:20:56 2011 -0700
   100.2 +++ b/src/share/classes/sun/net/TransferProtocolClient.java	Tue Oct 04 12:39:42 2011 -0700
   100.3 @@ -1,5 +1,5 @@
   100.4  /*
   100.5 - * Copyright (c) 1994, 2002, Oracle and/or its affiliates. All rights reserved.
   100.6 + * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
   100.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   100.8   *
   100.9   * This code is free software; you can redistribute it and/or modify it
  100.10 @@ -25,10 +25,8 @@
  100.11  
  100.12  package sun.net;
  100.13  
  100.14 -import java.lang.StringIndexOutOfBoundsException;
  100.15  import java.io.*;
  100.16  import java.util.Vector;
  100.17 -import sun.net.NetworkClient;
  100.18  
  100.19  /**
  100.20   * This class implements that basic intefaces of transfer protocols.
  100.21 @@ -44,7 +42,7 @@
  100.22  
  100.23      /** Array of strings (usually 1 entry) for the last reply
  100.24          from the server. */
  100.25 -    protected Vector    serverResponse = new Vector(1);
  100.26 +    protected Vector<String> serverResponse = new Vector<>(1);
  100.27  
  100.28      /** code for last reply */
  100.29      protected int       lastReplyCode;
  100.30 @@ -123,11 +121,11 @@
  100.31  
  100.32      /** converts the server response into a string. */
  100.33      public String getResponseString() {
  100.34 -        return (String) serverResponse.elementAt(0);
  100.35 +        return serverResponse.elementAt(0);
  100.36      }
  100.37  
  100.38      /** Returns all server response strings. */
  100.39 -    public Vector getResponseStrings() {
  100.40 +    public Vector<String> getResponseStrings() {
  100.41          return serverResponse;
  100.42      }
  100.43  
   101.1 --- a/src/share/classes/sun/net/ftp/FtpClientProvider.java	Fri Sep 30 17:20:56 2011 -0700
   101.2 +++ b/src/share/classes/sun/net/ftp/FtpClientProvider.java	Tue Oct 04 12:39:42 2011 -0700
   101.3 @@ -1,5 +1,5 @@
   101.4  /*
   101.5 - * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
   101.6 + * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
   101.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   101.8   *
   101.9   * This code is free software; you can redistribute it and/or modify it
  101.10 @@ -67,16 +67,13 @@
  101.11              return false;
  101.12          }
  101.13          try {
  101.14 -            Class c = Class.forName(cm, true, null);
  101.15 +            Class<?> c = Class.forName(cm, true, null);
  101.16              provider = (FtpClientProvider) c.newInstance();
  101.17              return true;
  101.18 -        } catch (ClassNotFoundException x) {
  101.19 -            throw new ServiceConfigurationError(x.toString());
  101.20 -        } catch (IllegalAccessException x) {
  101.21 -            throw new ServiceConfigurationError(x.toString());
  101.22 -        } catch (InstantiationException x) {
  101.23 -            throw new ServiceConfigurationError(x.toString());
  101.24 -        } catch (SecurityException x) {
  101.25 +        } catch (ClassNotFoundException |
  101.26 +                 IllegalAccessException |
  101.27 +                 InstantiationException |
  101.28 +                 SecurityException x) {
  101.29              throw new ServiceConfigurationError(x.toString());
  101.30          }
  101.31      }
   102.1 --- a/src/share/classes/sun/net/httpserver/Request.java	Fri Sep 30 17:20:56 2011 -0700
   102.2 +++ b/src/share/classes/sun/net/httpserver/Request.java	Tue Oct 04 12:39:42 2011 -0700
   102.3 @@ -1,5 +1,5 @@
   102.4  /*
   102.5 - * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
   102.6 + * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
   102.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   102.8   *
   102.9   * This code is free software; you can redistribute it and/or modify it
  102.10 @@ -25,13 +25,10 @@
  102.11  
  102.12  package sun.net.httpserver;
  102.13  
  102.14 -import java.util.*;
  102.15  import java.nio.*;
  102.16 -import java.net.*;
  102.17  import java.io.*;
  102.18  import java.nio.channels.*;
  102.19  import com.sun.net.httpserver.*;
  102.20 -import com.sun.net.httpserver.spi.*;
  102.21  
  102.22  /**
  102.23   */
  102.24 @@ -47,7 +44,6 @@
  102.25      private OutputStream os;
  102.26  
  102.27      Request (InputStream rawInputStream, OutputStream rawout) throws IOException {
  102.28 -        this.chan = chan;
  102.29          is = rawInputStream;
  102.30          os = rawout;
  102.31          do {
  102.32 @@ -121,7 +117,7 @@
  102.33      }
  102.34  
  102.35      Headers hdrs = null;
  102.36 -
  102.37 +    @SuppressWarnings("fallthrough")
  102.38      Headers headers () throws IOException {
  102.39          if (hdrs != null) {
  102.40              return hdrs;
  102.41 @@ -152,6 +148,7 @@
  102.42      parseloop:{
  102.43                  while ((c = is.read()) >= 0) {
  102.44                      switch (c) {
  102.45 +                      /*fallthrough*/
  102.46                        case ':':
  102.47                          if (inKey && len > 0)
  102.48                              keyend = len;
   103.1 --- a/src/share/classes/sun/net/httpserver/SSLStreams.java	Fri Sep 30 17:20:56 2011 -0700
   103.2 +++ b/src/share/classes/sun/net/httpserver/SSLStreams.java	Tue Oct 04 12:39:42 2011 -0700
   103.3 @@ -1,5 +1,5 @@
   103.4  /*
   103.5 - * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
   103.6 + * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
   103.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   103.8   *
   103.9   * This code is free software; you can redistribute it and/or modify it
  103.10 @@ -29,13 +29,10 @@
  103.11  import java.nio.*;
  103.12  import java.io.*;
  103.13  import java.nio.channels.*;
  103.14 -import java.util.*;
  103.15 -import java.util.concurrent.*;
  103.16  import java.util.concurrent.locks.*;
  103.17  import javax.net.ssl.*;
  103.18  import javax.net.ssl.SSLEngineResult.*;
  103.19  import com.sun.net.httpserver.*;
  103.20 -import com.sun.net.httpserver.spi.*;
  103.21  
  103.22  /**
  103.23   * given a non-blocking SocketChannel, it produces
  103.24 @@ -448,6 +445,7 @@
  103.25       * on the wrapper methods being idempotent. eg. if wrapAndSend()
  103.26       * is called with no data to send then there must be no problem
  103.27       */
  103.28 +    @SuppressWarnings("fallthrough")
  103.29      void doHandshake (HandshakeStatus hs_status) throws IOException {
  103.30          try {
  103.31              handshaking.lock();
   104.1 --- a/src/share/classes/sun/net/httpserver/ServerImpl.java	Fri Sep 30 17:20:56 2011 -0700
   104.2 +++ b/src/share/classes/sun/net/httpserver/ServerImpl.java	Tue Oct 04 12:39:42 2011 -0700
   104.3 @@ -1,5 +1,5 @@
   104.4  /*
   104.5 - * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
   104.6 + * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
   104.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   104.8   *
   104.9   * This code is free software; you can redistribute it and/or modify it
  104.10 @@ -593,8 +593,8 @@
  104.11                          rheaders.set ("Connection", "close");
  104.12                      } else if (chdr.equalsIgnoreCase ("keep-alive")) {
  104.13                          rheaders.set ("Connection", "keep-alive");
  104.14 -                        int idle=(int)ServerConfig.getIdleInterval()/1000;
  104.15 -                        int max=(int)ServerConfig.getMaxIdleConnections();
  104.16 +                        int idle=(int)(ServerConfig.getIdleInterval()/1000);
  104.17 +                        int max=ServerConfig.getMaxIdleConnections();
  104.18                          String val = "timeout="+idle+", max="+max;
  104.19                          rheaders.set ("Keep-Alive", val);
  104.20                      }
   105.1 --- a/src/share/classes/sun/net/idn/UCharacterEnums.java	Fri Sep 30 17:20:56 2011 -0700
   105.2 +++ b/src/share/classes/sun/net/idn/UCharacterEnums.java	Tue Oct 04 12:39:42 2011 -0700
   105.3 @@ -33,6 +33,22 @@
   105.4  //          - copy this file from icu4jsrc_3_2/src/com/ibm/icu/lang/UCharacterEnums.java
   105.5  //          - move from package com.ibm.icu.lang to package sun.net.idn
   105.6  //
   105.7 +//      2011-09-06 Kurchi Subhra Hazra
   105.8 +//          - Added @Deprecated tag to the following:
   105.9 +//            - class UCharacterEnums
  105.10 +//            - interfaces ECharacterCategory, ECharacterDirection
  105.11 +//            - fields INITIAL_QUOTE_PUNCTUATION, FINAL_QUOTE_PUNCTUATION,
  105.12 +//              DIRECTIONALITY_LEFT_TO_RIGHT, DIRECTIONALITY_RIGHT_TO_LEFT,
  105.13 +//              DIRECTIONALITY_EUROPEAN_NUMBER, DIRECTIONALITY_EUROPEAN_NUMBER_SEPARATOR
  105.14 +//              DIRECTIONALITY_EUROPEAN_NUMBER_TERMINATOR, DIRECTIONALITY_ARABIC_NUMBER,
  105.15 +//              DIRECTIONALITY_COMMON_NUMBER_SEPARATOR, DIRECTIONALITY_PARAGRAPH_SEPARATOR,
  105.16 +//              DIRECTIONALITY_SEGMENT_SEPARATOR, DIRECTIONALITY_WHITESPACE,
  105.17 +//              DIRECTIONALITY_OTHER_NEUTRALS, DIRECTIONALITY_LEFT_TO_RIGHT_EMBEDDING,
  105.18 +//              DIRECTIONALITY_LEFT_TO_RIGHT_OVERRIDE, DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC,
  105.19 +//              DIRECTIONALITY_RIGHT_TO_LEFT_EMBEDDING, DIRECTIONALITY_RIGHT_TO_LEFT_OVERRIDE,
  105.20 +//              DIRECTIONALITY_POP_DIRECTIONAL_FORMAT, DIRECTIONALITY_NON_SPACING_MARK,
  105.21 +//              DIRECTIONALITY_BOUNDARY_NEUTRAL, DIRECTIONALITY_UNDEFINED
  105.22 +//
  105.23  
  105.24  package sun.net.idn;
  105.25  
  105.26 @@ -41,6 +57,8 @@
  105.27   * @draft ICU 3.0
  105.28   * @deprecated This is a draft API and might change in a future release of ICU.
  105.29   */
  105.30 +
  105.31 +@Deprecated
  105.32  class UCharacterEnums {
  105.33  
  105.34      /** This is just a namespace, it is not instantiatable. */
  105.35 @@ -54,6 +72,7 @@
  105.36       * @draft ICU 3.0
  105.37       * @deprecated This is a draft API and might change in a future release of ICU.
  105.38       */
  105.39 +    @Deprecated
  105.40      public static interface ECharacterCategory {
  105.41          /**
  105.42           * Unassigned character type
  105.43 @@ -245,6 +264,7 @@
  105.44           * @draft ICU 2.8
  105.45       * @deprecated This is a draft API and might change in a future release of ICU.
  105.46           */
  105.47 +        @Deprecated
  105.48          public static final int INITIAL_QUOTE_PUNCTUATION = 28;
  105.49  
  105.50          /**
  105.51 @@ -261,6 +281,7 @@
  105.52           * @draft ICU 2.8
  105.53       * @deprecated This is a draft API and might change in a future release of ICU.
  105.54           */
  105.55 +        @Deprecated
  105.56          public static final int FINAL_QUOTE_PUNCTUATION   = 29;
  105.57  
  105.58          /**
  105.59 @@ -279,6 +300,8 @@
  105.60       * @draft ICU 3.0
  105.61       * @deprecated This is a draft API and might change in a future release of ICU.
  105.62       */
  105.63 +
  105.64 +    @Deprecated
  105.65      public static interface ECharacterDirection {
  105.66          /**
  105.67           * Directional type L
  105.68 @@ -291,6 +314,7 @@
  105.69           * @draft ICU 3.0
  105.70       * @deprecated This is a draft API and might change in a future release of ICU.
  105.71           */
  105.72 +        @Deprecated
  105.73          public static final byte DIRECTIONALITY_LEFT_TO_RIGHT = (byte)LEFT_TO_RIGHT;
  105.74  
  105.75          /**
  105.76 @@ -304,6 +328,7 @@
  105.77           * @draft ICU 3.0
  105.78       * @deprecated This is a draft API and might change in a future release of ICU.
  105.79           */
  105.80 +        @Deprecated
  105.81          public static final byte DIRECTIONALITY_RIGHT_TO_LEFT = (byte)RIGHT_TO_LEFT;
  105.82  
  105.83          /**
  105.84 @@ -317,6 +342,7 @@
  105.85           * @draft ICU 3.0
  105.86       * @deprecated This is a draft API and might change in a future release of ICU.
  105.87           */
  105.88 +        @Deprecated
  105.89          public static final byte DIRECTIONALITY_EUROPEAN_NUMBER = (byte)EUROPEAN_NUMBER;
  105.90  
  105.91          /**
  105.92 @@ -330,6 +356,7 @@
  105.93           * @draft ICU 3.0
  105.94       * @deprecated This is a draft API and might change in a future release of ICU.
  105.95           */
  105.96 +        @Deprecated
  105.97          public static final byte DIRECTIONALITY_EUROPEAN_NUMBER_SEPARATOR = (byte)EUROPEAN_NUMBER_SEPARATOR;
  105.98  
  105.99          /**
 105.100 @@ -343,6 +370,7 @@
 105.101           * @draft ICU 3.0
 105.102       * @deprecated This is a draft API and might change in a future release of ICU.
 105.103           */
 105.104 +        @Deprecated
 105.105          public static final byte DIRECTIONALITY_EUROPEAN_NUMBER_TERMINATOR = (byte)EUROPEAN_NUMBER_TERMINATOR;
 105.106  
 105.107          /**
 105.108 @@ -356,6 +384,7 @@
 105.109           * @draft ICU 3.0
 105.110       * @deprecated This is a draft API and might change in a future release of ICU.
 105.111           */
 105.112 +        @Deprecated
 105.113          public static final byte DIRECTIONALITY_ARABIC_NUMBER = (byte)ARABIC_NUMBER;
 105.114  
 105.115          /**
 105.116 @@ -369,6 +398,7 @@
 105.117           * @draft ICU 3.0
 105.118       * @deprecated This is a draft API and might change in a future release of ICU.
 105.119           */
 105.120 +        @Deprecated
 105.121          public static final byte DIRECTIONALITY_COMMON_NUMBER_SEPARATOR = (byte)COMMON_NUMBER_SEPARATOR;
 105.122  
 105.123          /**
 105.124 @@ -382,6 +412,7 @@
 105.125           * @draft ICU 3.0
 105.126       * @deprecated This is a draft API and might change in a future release of ICU.
 105.127           */
 105.128 +        @Deprecated
 105.129          public static final byte DIRECTIONALITY_PARAGRAPH_SEPARATOR = (byte)BLOCK_SEPARATOR;
 105.130  
 105.131          /**
 105.132 @@ -395,6 +426,7 @@
 105.133           * @draft ICU 3.0
 105.134       * @deprecated This is a draft API and might change in a future release of ICU.
 105.135           */
 105.136 +        @Deprecated
 105.137          public static final byte DIRECTIONALITY_SEGMENT_SEPARATOR = (byte)SEGMENT_SEPARATOR;
 105.138  
 105.139          /**
 105.140 @@ -408,6 +440,7 @@
 105.141           * @draft ICU 3.0
 105.142       * @deprecated This is a draft API and might change in a future release of ICU.
 105.143           */
 105.144 +        @Deprecated
 105.145          public static final byte DIRECTIONALITY_WHITESPACE = (byte)WHITE_SPACE_NEUTRAL;
 105.146  
 105.147          /**
 105.148 @@ -421,6 +454,7 @@
 105.149           * @draft ICU 3.0
 105.150       * @deprecated This is a draft API and might change in a future release of ICU.
 105.151           */
 105.152 +        @Deprecated
 105.153          public static final byte DIRECTIONALITY_OTHER_NEUTRALS = (byte)OTHER_NEUTRAL;
 105.154  
 105.155          /**
 105.156 @@ -434,6 +468,7 @@
 105.157           * @draft ICU 3.0
 105.158       * @deprecated This is a draft API and might change in a future release of ICU.
 105.159           */
 105.160 +        @Deprecated
 105.161          public static final byte DIRECTIONALITY_LEFT_TO_RIGHT_EMBEDDING = (byte)LEFT_TO_RIGHT_EMBEDDING;
 105.162  
 105.163          /**
 105.164 @@ -447,6 +482,7 @@
 105.165           * @draft ICU 3.0
 105.166       * @deprecated This is a draft API and might change in a future release of ICU.
 105.167           */
 105.168 +        @Deprecated
 105.169          public static final byte DIRECTIONALITY_LEFT_TO_RIGHT_OVERRIDE = (byte)LEFT_TO_RIGHT_OVERRIDE;
 105.170  
 105.171          /**
 105.172 @@ -460,6 +496,7 @@
 105.173           * @draft ICU 3.0
 105.174       * @deprecated This is a draft API and might change in a future release of ICU.
 105.175           */
 105.176 +        @Deprecated
 105.177          public static final byte DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC = (byte)RIGHT_TO_LEFT_ARABIC;
 105.178  
 105.179          /**
 105.180 @@ -473,6 +510,7 @@
 105.181           * @draft ICU 3.0
 105.182       * @deprecated This is a draft API and might change in a future release of ICU.
 105.183           */
 105.184 +        @Deprecated
 105.185          public static final byte DIRECTIONALITY_RIGHT_TO_LEFT_EMBEDDING = (byte)RIGHT_TO_LEFT_EMBEDDING;
 105.186  
 105.187          /**
 105.188 @@ -486,6 +524,7 @@
 105.189           * @draft ICU 3.0
 105.190       * @deprecated This is a draft API and might change in a future release of ICU.
 105.191           */
 105.192 +        @Deprecated
 105.193          public static final byte DIRECTIONALITY_RIGHT_TO_LEFT_OVERRIDE = (byte)RIGHT_TO_LEFT_OVERRIDE;
 105.194  
 105.195          /**
 105.196 @@ -499,6 +538,7 @@
 105.197           * @draft ICU 3.0
 105.198       * @deprecated This is a draft API and might change in a future release of ICU.
 105.199           */
 105.200 +        @Deprecated
 105.201          public static final byte DIRECTIONALITY_POP_DIRECTIONAL_FORMAT = (byte)POP_DIRECTIONAL_FORMAT;
 105.202  
 105.203          /**
 105.204 @@ -512,6 +552,7 @@
 105.205           * @draft ICU 3.0
 105.206       * @deprecated This is a draft API and might change in a future release of ICU.
 105.207           */
 105.208 +        @Deprecated
 105.209          public static final byte DIRECTIONALITY_NON_SPACING_MARK = (byte)DIR_NON_SPACING_MARK;
 105.210  
 105.211          /**
 105.212 @@ -525,6 +566,7 @@
 105.213           * @draft ICU 3.0
 105.214       * @deprecated This is a draft API and might change in a future release of ICU.
 105.215           */
 105.216 +        @Deprecated
 105.217          public static final byte DIRECTIONALITY_BOUNDARY_NEUTRAL = (byte)BOUNDARY_NEUTRAL;
 105.218  
 105.219          /**
 105.220 @@ -539,6 +581,7 @@
 105.221       * @draft ICU 3.0
 105.222       * @deprecated This is a draft API and might change in a future release of ICU.
 105.223           */
 105.224 +        @Deprecated
 105.225          public static final byte DIRECTIONALITY_UNDEFINED = -1;
 105.226      }
 105.227  }
   106.1 --- a/src/share/classes/sun/net/spi/nameservice/dns/DNSNameService.java	Fri Sep 30 17:20:56 2011 -0700
   106.2 +++ b/src/share/classes/sun/net/spi/nameservice/dns/DNSNameService.java	Tue Oct 04 12:39:42 2011 -0700
   106.3 @@ -1,5 +1,5 @@
   106.4  /*
   106.5 - * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
   106.6 + * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
   106.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   106.8   *
   106.9   * This code is free software; you can redistribute it and/or modify it
  106.10 @@ -140,7 +140,7 @@
  106.11              // create new soft reference to our thread context
  106.12              //
  106.13              thrCtxt = new ThreadContext(dirCtxt, nsList);
  106.14 -            contextRef.set(new SoftReference(thrCtxt));
  106.15 +            contextRef.set(new SoftReference<ThreadContext>(thrCtxt));
  106.16          }
  106.17  
  106.18          return thrCtxt.dirContext();
  106.19 @@ -193,7 +193,7 @@
  106.20                  Attribute attr = ne.next();
  106.21                  String attrID = attr.getID();
  106.22  
  106.23 -                for (NamingEnumeration e = attr.getAll(); e.hasMoreElements();) {
  106.24 +                for (NamingEnumeration<?> e = attr.getAll(); e.hasMoreElements();) {
  106.25                      String addr = (String)e.next();
  106.26  
  106.27                      // for canoncical name records do recursive lookup
  106.28 @@ -233,7 +233,7 @@
  106.29          String domain = AccessController.doPrivileged(
  106.30              new GetPropertyAction("sun.net.spi.nameservice.domain"));
  106.31          if (domain != null && domain.length() > 0) {
  106.32 -            domainList = new LinkedList();
  106.33 +            domainList = new LinkedList<String>();
  106.34              domainList.add(domain);
  106.35          }
  106.36  
  106.37 @@ -282,7 +282,7 @@
  106.38              throw new Error(nx);
  106.39          }
  106.40  
  106.41 -        ArrayList results = null;
  106.42 +        ArrayList<String> results = null;
  106.43          UnknownHostException uhe = null;
  106.44  
  106.45          // If host already contains a domain name then just look it up
  106.46 @@ -365,7 +365,7 @@
  106.47          InetAddress[] addrs = new InetAddress[results.size()];
  106.48          int count = 0;
  106.49          for (int i=0; i<results.size(); i++) {
  106.50 -            String addrString = (String)results.get(i);
  106.51 +            String addrString = results.get(i);
  106.52              byte addr[] = IPAddressUtil.textToNumericFormatV4(addrString);
  106.53              if (addr == null) {
  106.54                  addr = IPAddressUtil.textToNumericFormatV6(addrString);
   107.1 --- a/src/share/classes/sun/net/www/HeaderParser.java	Fri Sep 30 17:20:56 2011 -0700
   107.2 +++ b/src/share/classes/sun/net/www/HeaderParser.java	Tue Oct 04 12:39:42 2011 -0700
   107.3 @@ -1,5 +1,5 @@
   107.4  /*
   107.5 - * Copyright (c) 1996, 2002, Oracle and/or its affiliates. All rights reserved.
   107.6 + * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
   107.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   107.8   *
   107.9   * This code is free software; you can redistribute it and/or modify it
  107.10 @@ -192,7 +192,7 @@
  107.11          return Default;
  107.12      }
  107.13  
  107.14 -    class ParserIterator implements Iterator {
  107.15 +    class ParserIterator implements Iterator<String> {
  107.16          int index;
  107.17          boolean returnsValue; // or key
  107.18  
  107.19 @@ -202,7 +202,7 @@
  107.20          public boolean hasNext () {
  107.21              return index<nkeys;
  107.22          }
  107.23 -        public Object next () {
  107.24 +        public String next () {
  107.25              return tab[index++][returnsValue?1:0];
  107.26          }
  107.27          public void remove () {
  107.28 @@ -210,20 +210,20 @@
  107.29          }
  107.30      }
  107.31  
  107.32 -    public Iterator keys () {
  107.33 +    public Iterator<String> keys () {
  107.34          return new ParserIterator (false);
  107.35      }
  107.36  
  107.37 -    public Iterator values () {
  107.38 +    public Iterator<String> values () {
  107.39          return new ParserIterator (true);
  107.40      }
  107.41  
  107.42      public String toString () {
  107.43 -        Iterator k = keys();
  107.44 +        Iterator<String> k = keys();
  107.45          StringBuffer sbuf = new StringBuffer();
  107.46          sbuf.append ("{size="+asize+" nkeys="+nkeys+" ");
  107.47          for (int i=0; k.hasNext(); i++) {
  107.48 -            String key = (String)k.next();
  107.49 +            String key = k.next();
  107.50              String val = findValue (i);
  107.51              if (val != null && "".equals (val)) {
  107.52                  val = null;
   108.1 --- a/src/share/classes/sun/net/www/MessageHeader.java	Fri Sep 30 17:20:56 2011 -0700
   108.2 +++ b/src/share/classes/sun/net/www/MessageHeader.java	Tue Oct 04 12:39:42 2011 -0700
   108.3 @@ -1,5 +1,5 @@
   108.4  /*
   108.5 - * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
   108.6 + * Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
   108.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   108.8   *
   108.9   * This code is free software; you can redistribute it and/or modify it
  108.10 @@ -35,7 +35,6 @@
  108.11  import java.util.HashMap;
  108.12  import java.util.List;
  108.13  import java.util.ArrayList;
  108.14 -import java.util.Set;
  108.15  import java.util.Iterator;
  108.16  import java.util.NoSuchElementException;
  108.17  
  108.18 @@ -199,7 +198,8 @@
  108.19          return filterAndAddHeaders(excludeList, null);
  108.20      }
  108.21  
  108.22 -    public synchronized Map<String, List<String>> filterAndAddHeaders(String[] excludeList, Map<String, List<String>>  include) {
  108.23 +    public synchronized Map<String, List<String>> filterAndAddHeaders(
  108.24 +            String[] excludeList, Map<String, List<String>>  include) {
  108.25          boolean skipIt = false;
  108.26          Map<String, List<String>> m = new HashMap<String, List<String>>();
  108.27          for (int i = nkeys; --i >= 0;) {
  108.28 @@ -228,15 +228,13 @@
  108.29          }
  108.30  
  108.31          if (include != null) {
  108.32 -            Iterator entries = include.entrySet().iterator();
  108.33 -            while (entries.hasNext()) {
  108.34 -                Map.Entry entry = (Map.Entry)entries.next();
  108.35 -                List l = (List)m.get(entry.getKey());
  108.36 +                for (Map.Entry<String,List<String>> entry: include.entrySet()) {
  108.37 +                List<String> l = m.get(entry.getKey());
  108.38                  if (l == null) {
  108.39 -                    l = new ArrayList();
  108.40 -                    m.put((String)entry.getKey(), l);
  108.41 +                    l = new ArrayList<String>();
  108.42 +                    m.put(entry.getKey(), l);
  108.43                  }
  108.44 -                l.add(entry.getValue());
  108.45 +                l.addAll(entry.getValue());
  108.46              }
  108.47          }
  108.48  
  108.49 @@ -400,6 +398,7 @@
  108.50      }
  108.51  
  108.52      /** Parse and merge a MIME header from an input stream. */
  108.53 +    @SuppressWarnings("fallthrough")
  108.54      public void mergeHeader(InputStream is) throws java.io.IOException {
  108.55          if (is == null)
  108.56              return;
  108.57 @@ -421,6 +420,7 @@
  108.58                          break;
  108.59                        case '\t':
  108.60                          c = ' ';
  108.61 +                      /*fall through*/
  108.62                        case ' ':
  108.63                          inKey = false;
  108.64                          break;
   109.1 --- a/src/share/classes/sun/net/www/MimeTable.java	Fri Sep 30 17:20:56 2011 -0700
   109.2 +++ b/src/share/classes/sun/net/www/MimeTable.java	Tue Oct 04 12:39:42 2011 -0700
   109.3 @@ -1,5 +1,5 @@
   109.4  /*
   109.5 - * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
   109.6 + * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
   109.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   109.8   *
   109.9   * This code is free software; you can redistribute it and/or modify it
  109.10 @@ -25,10 +25,6 @@
  109.11  
  109.12  package sun.net.www;
  109.13  import java.io.*;
  109.14 -import java.util.Calendar;
  109.15 -import java.util.Date;
  109.16 -import java.text.SimpleDateFormat;
  109.17 -import java.net.URL;
  109.18  import java.net.FileNameMap;
  109.19  import java.util.Hashtable;
  109.20  import java.util.Enumeration;
  109.21 @@ -271,7 +267,7 @@
  109.22          String tempFileTemplate = (String)entries.get("temp.file.template");
  109.23          if (tempFileTemplate != null) {
  109.24              entries.remove("temp.file.template");
  109.25 -            this.tempFileTemplate = tempFileTemplate;
  109.26 +            MimeTable.tempFileTemplate = tempFileTemplate;
  109.27          }
  109.28  
  109.29          // now, parse the mime-type spec's
  109.30 @@ -417,10 +413,10 @@
  109.31              String user = System.getProperty("user.name");
  109.32              if (user != null) {
  109.33                  tag = "; customized for " + user;
  109.34 -                properties.save(os, filePreamble + tag);
  109.35 +                properties.store(os, filePreamble + tag);
  109.36              }
  109.37              else {
  109.38 -                properties.save(os, filePreamble);
  109.39 +                properties.store(os, filePreamble);
  109.40              }
  109.41          }
  109.42          catch (IOException e) {
   110.1 --- a/src/share/classes/sun/net/www/URLConnection.java	Fri Sep 30 17:20:56 2011 -0700
   110.2 +++ b/src/share/classes/sun/net/www/URLConnection.java	Tue Oct 04 12:39:42 2011 -0700
   110.3 @@ -1,5 +1,5 @@
   110.4  /*
   110.5 - * Copyright (c) 1995, 2006, Oracle and/or its affiliates. All rights reserved.
   110.6 + * Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
   110.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   110.8   *
   110.9   * This code is free software; you can redistribute it and/or modify it
  110.10 @@ -26,12 +26,7 @@
  110.11  package sun.net.www;
  110.12  
  110.13  import java.net.URL;
  110.14 -import java.net.ContentHandler;
  110.15  import java.util.*;
  110.16 -import java.io.InputStream;
  110.17 -import java.io.OutputStream;
  110.18 -import java.io.BufferedInputStream;
  110.19 -import java.net.UnknownServiceException;
  110.20  
  110.21  /**
  110.22   * A class to represent an active connection to an object
  110.23 @@ -99,7 +94,7 @@
  110.24      public Map<String,List<String>> getRequestProperties() {
  110.25          if (connected)
  110.26              throw new IllegalStateException("Already connected");
  110.27 -        return Collections.EMPTY_MAP;
  110.28 +        return Collections.emptyMap();
  110.29      }
  110.30  
  110.31      public String getHeaderField(String name) {
   111.1 --- a/src/share/classes/sun/net/www/content/image/gif.java	Fri Sep 30 17:20:56 2011 -0700
   111.2 +++ b/src/share/classes/sun/net/www/content/image/gif.java	Tue Oct 04 12:39:42 2011 -0700
   111.3 @@ -1,5 +1,5 @@
   111.4  /*
   111.5 - * Copyright (c) 1994, 1999, Oracle and/or its affiliates. All rights reserved.
   111.6 + * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
   111.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   111.8   *
   111.9   * This code is free software; you can redistribute it and/or modify it
  111.10 @@ -25,11 +25,8 @@
  111.11  
  111.12  package sun.net.www.content.image;
  111.13  
  111.14 -import java.net.URL;
  111.15 -import java.net.URLConnection;
  111.16  import java.net.*;
  111.17  import sun.awt.image.*;
  111.18 -import java.io.InputStream;
  111.19  import java.io.IOException;
  111.20  import java.awt.Image;
  111.21  import java.awt.Toolkit;
  111.22 @@ -40,7 +37,7 @@
  111.23          return new URLImageSource(urlc);
  111.24      }
  111.25  
  111.26 -    public Object getContent(URLConnection urlc, Class[] classes) throws IOException {
  111.27 +    public Object getContent(URLConnection urlc, Class<?>[] classes) throws IOException {
  111.28          for (int i = 0; i < classes.length; i++) {
  111.29            if (classes[i].isAssignableFrom(URLImageSource.class)) {
  111.30                  return new URLImageSource(urlc);
   112.1 --- a/src/share/classes/sun/net/www/content/image/jpeg.java	Fri Sep 30 17:20:56 2011 -0700
   112.2 +++ b/src/share/classes/sun/net/www/content/image/jpeg.java	Tue Oct 04 12:39:42 2011 -0700
   112.3 @@ -1,5 +1,5 @@
   112.4  /*
   112.5 - * Copyright (c) 1995, 1999, Oracle and/or its affiliates. All rights reserved.
   112.6 + * Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
   112.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   112.8   *
   112.9   * This code is free software; you can redistribute it and/or modify it
  112.10 @@ -25,11 +25,8 @@
  112.11  
  112.12  package sun.net.www.content.image;
  112.13  
  112.14 -import java.net.URL;
  112.15 -import java.net.URLConnection;
  112.16  import java.net.*;
  112.17  import sun.awt.image.*;
  112.18 -import java.io.InputStream;
  112.19  import java.io.IOException;
  112.20  import java.awt.Image;
  112.21  import java.awt.Toolkit;
  112.22 @@ -39,7 +36,7 @@
  112.23          return new URLImageSource(urlc);
  112.24      }
  112.25  
  112.26 -    public Object getContent(URLConnection urlc, Class[] classes) throws IOException {
  112.27 +    public Object getContent(URLConnection urlc, Class<?>[] classes) throws IOException {
  112.28          for (int i = 0; i < classes.length; i++) {
  112.29            if (classes[i].isAssignableFrom(URLImageSource.class)) {
  112.30                  return new URLImageSource(urlc);
   113.1 --- a/src/share/classes/sun/net/www/content/image/png.java	Fri Sep 30 17:20:56 2011 -0700
   113.2 +++ b/src/share/classes/sun/net/www/content/image/png.java	Tue Oct 04 12:39:42 2011 -0700
   113.3 @@ -1,5 +1,5 @@
   113.4  /*
   113.5 - * Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.
   113.6 + * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
   113.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   113.8   *
   113.9   * This code is free software; you can redistribute it and/or modify it
  113.10 @@ -25,10 +25,7 @@
  113.11  
  113.12  package sun.net.www.content.image;
  113.13  
  113.14 -import java.net.URL;
  113.15 -import java.net.URLConnection;
  113.16  import java.net.*;
  113.17 -import java.io.InputStream;
  113.18  import java.io.IOException;
  113.19  import sun.awt.image.*;
  113.20  import java.awt.Image;
  113.21 @@ -39,7 +36,7 @@
  113.22          return new URLImageSource(urlc);
  113.23      }
  113.24  
  113.25 -    public Object getContent(URLConnection urlc, Class[] classes) throws IOException {
  113.26 +    public Object getContent(URLConnection urlc, Class<?>[] classes) throws IOException {
  113.27          for (int i = 0; i < classes.length; i++) {
  113.28            if (classes[i].isAssignableFrom(URLImageSource.class)) {
  113.29                  return new URLImageSource(urlc);
   114.1 --- a/src/share/classes/sun/net/www/content/image/x_xbitmap.java	Fri Sep 30 17:20:56 2011 -0700
   114.2 +++ b/src/share/classes/sun/net/www/content/image/x_xbitmap.java	Tue Oct 04 12:39:42 2011 -0700
   114.3 @@ -1,5 +1,5 @@
   114.4  /*
   114.5 - * Copyright (c) 1994, 1999, Oracle and/or its affiliates. All rights reserved.
   114.6 + * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
   114.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   114.8   *
   114.9   * This code is free software; you can redistribute it and/or modify it
  114.10 @@ -35,7 +35,7 @@
  114.11          return new URLImageSource(urlc);
  114.12      }
  114.13  
  114.14 -    public Object getContent(URLConnection urlc, Class[] classes) throws java.io.IOException {
  114.15 +    public Object getContent(URLConnection urlc, Class<?>[] classes) throws java.io.IOException {
  114.16          for (int i = 0; i < classes.length; i++) {
  114.17            if (classes[i].isAssignableFrom(URLImageSource.class)) {
  114.18                  return new URLImageSource(urlc);
   115.1 --- a/src/share/classes/sun/net/www/content/image/x_xpixmap.java	Fri Sep 30 17:20:56 2011 -0700
   115.2 +++ b/src/share/classes/sun/net/www/content/image/x_xpixmap.java	Tue Oct 04 12:39:42 2011 -0700
   115.3 @@ -1,5 +1,5 @@
   115.4  /*
   115.5 - * Copyright (c) 1994, 1999, Oracle and/or its affiliates. All rights reserved.
   115.6 + * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
   115.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   115.8   *
   115.9   * This code is free software; you can redistribute it and/or modify it
  115.10 @@ -35,7 +35,7 @@
  115.11          return new URLImageSource(urlc);
  115.12      }
  115.13  
  115.14 -    public Object getContent(URLConnection urlc, Class[] classes) throws java.io.IOException {
  115.15 +    public Object getContent(URLConnection urlc, Class<?>[] classes) throws java.io.IOException {
  115.16          for (int i = 0; i < classes.length; i++) {
  115.17            if (classes[i].isAssignableFrom(URLImageSource.class)) {
  115.18                  return new URLImageSource(urlc);
   116.1 --- a/src/share/classes/sun/net/www/http/KeepAliveStream.java	Fri Sep 30 17:20:56 2011 -0700
   116.2 +++ b/src/share/classes/sun/net/www/http/KeepAliveStream.java	Tue Oct 04 12:39:42 2011 -0700
   116.3 @@ -81,7 +81,7 @@
   116.4          // NOTE: Don't close super class
   116.5          try {
   116.6              if (expected > count) {
   116.7 -                long nskip = (long) (expected - count);
   116.8 +                long nskip = expected - count;
   116.9                  if (nskip <= available()) {
  116.10                      long n = 0;
  116.11                      while (n < nskip) {
   117.1 --- a/src/share/classes/sun/net/www/protocol/gopher/GopherClient.java	Fri Sep 30 17:20:56 2011 -0700
   117.2 +++ b/src/share/classes/sun/net/www/protocol/gopher/GopherClient.java	Tue Oct 04 12:39:42 2011 -0700
   117.3 @@ -281,7 +281,7 @@
   117.4                  ps.print("</title></head>\n<body>\n<H1>");
   117.5                  ps.print(title);
   117.6                  ps.print("</h1><dl compact>\n");
   117.7 -                DataInputStream ds = new DataInputStream(serverInput);
   117.8 +                BufferedReader ds = new BufferedReader(new InputStreamReader(serverInput));
   117.9                  String s;
  117.10                  while ((s = ds.readLine()) != null) {
  117.11                      int len = s.length();
   118.1 --- a/src/share/classes/sun/net/www/protocol/http/AuthCacheImpl.java	Fri Sep 30 17:20:56 2011 -0700
   118.2 +++ b/src/share/classes/sun/net/www/protocol/http/AuthCacheImpl.java	Tue Oct 04 12:39:42 2011 -0700
   118.3 @@ -1,5 +1,5 @@
   118.4  /*
   118.5 - * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
   118.6 + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
   118.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   118.8   *
   118.9   * This code is free software; you can redistribute it and/or modify it
  118.10 @@ -25,12 +25,8 @@
  118.11  
  118.12  package sun.net.www.protocol.http;
  118.13  
  118.14 -import java.io.IOException;
  118.15 -import java.net.URL;
  118.16 -import java.util.Hashtable;
  118.17  import java.util.LinkedList;
  118.18  import java.util.ListIterator;
  118.19 -import java.util.Enumeration;
  118.20  import java.util.HashMap;
  118.21  
  118.22  /**
  118.23 @@ -38,13 +34,13 @@
  118.24   */
  118.25  
  118.26  public class AuthCacheImpl implements AuthCache {
  118.27 -    HashMap hashtable;
  118.28 +    HashMap<String,LinkedList<AuthCacheValue>> hashtable;
  118.29  
  118.30      public AuthCacheImpl () {
  118.31 -        hashtable = new HashMap ();
  118.32 +        hashtable = new HashMap<String,LinkedList<AuthCacheValue>>();
  118.33      }
  118.34  
  118.35 -    public void setMap (HashMap map) {
  118.36 +    public void setMap (HashMap<String,LinkedList<AuthCacheValue>> map) {
  118.37          hashtable = map;
  118.38      }
  118.39  
  118.40 @@ -52,21 +48,21 @@
  118.41      // is the path field of AuthenticationInfo
  118.42  
  118.43      public synchronized void put (String pkey, AuthCacheValue value) {
  118.44 -        LinkedList list = (LinkedList) hashtable.get (pkey);
  118.45 +        LinkedList<AuthCacheValue> list = hashtable.get (pkey);
  118.46          String skey = value.getPath();
  118.47          if (list == null) {
  118.48 -            list = new LinkedList ();
  118.49 -            hashtable.put (pkey, list);
  118.50 +            list = new LinkedList<AuthCacheValue>();
  118.51 +            hashtable.put(pkey, list);
  118.52          }
  118.53          // Check if the path already exists or a super-set of it exists
  118.54 -        ListIterator iter = list.listIterator();
  118.55 +        ListIterator<AuthCacheValue> iter = list.listIterator();
  118.56          while (iter.hasNext()) {
  118.57              AuthenticationInfo inf = (AuthenticationInfo)iter.next();
  118.58              if (inf.path == null || inf.path.startsWith (skey)) {
  118.59                  iter.remove ();
  118.60              }
  118.61          }
  118.62 -        iter.add (value);
  118.63 +        iter.add(value);
  118.64      }
  118.65  
  118.66      // get a value from map checking both primary
  118.67 @@ -74,7 +70,7 @@
  118.68  
  118.69      public synchronized AuthCacheValue get (String pkey, String skey) {
  118.70          AuthenticationInfo result = null;
  118.71 -        LinkedList list = (LinkedList) hashtable.get (pkey);
  118.72 +        LinkedList<AuthCacheValue> list = hashtable.get (pkey);
  118.73          if (list == null || list.size() == 0) {
  118.74              return null;
  118.75          }
  118.76 @@ -82,7 +78,7 @@
  118.77              // list should contain only one element
  118.78              return (AuthenticationInfo)list.get (0);
  118.79          }
  118.80 -        ListIterator iter = list.listIterator();
  118.81 +        ListIterator<AuthCacheValue> iter = list.listIterator();
  118.82          while (iter.hasNext()) {
  118.83              AuthenticationInfo inf = (AuthenticationInfo)iter.next();
  118.84              if (skey.startsWith (inf.path)) {
  118.85 @@ -93,7 +89,7 @@
  118.86      }
  118.87  
  118.88      public synchronized void remove (String pkey, AuthCacheValue entry) {
  118.89 -        LinkedList list = (LinkedList) hashtable.get (pkey);
  118.90 +        LinkedList<AuthCacheValue> list = hashtable.get (pkey);
  118.91          if (list == null) {
  118.92              return;
  118.93          }
  118.94 @@ -101,7 +97,7 @@
  118.95              list.clear();
  118.96              return;
  118.97          }
  118.98 -        ListIterator iter = list.listIterator ();
  118.99 +        ListIterator<AuthCacheValue> iter = list.listIterator ();
 118.100          while (iter.hasNext()) {
 118.101              AuthenticationInfo inf = (AuthenticationInfo)iter.next();
 118.102              if (entry.equals(inf)) {
   119.1 --- a/src/share/classes/sun/net/www/protocol/http/AuthenticationHeader.java	Fri Sep 30 17:20:56 2011 -0700
   119.2 +++ b/src/share/classes/sun/net/www/protocol/http/AuthenticationHeader.java	Tue Oct 04 12:39:42 2011 -0700
   119.3 @@ -1,5 +1,5 @@
   119.4  /*
   119.5 - * Copyright (c) 2002, 2009, Oracle and/or its affiliates. All rights reserved.
   119.6 + * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
   119.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   119.8   *
   119.9   * This code is free software; you can redistribute it and/or modify it
  119.10 @@ -122,7 +122,7 @@
  119.11          this.dontUseNegotiate = dontUseNegotiate;
  119.12          rsp = response;
  119.13          this.hdrname = hdrname;
  119.14 -        schemes = new HashMap();
  119.15 +        schemes = new HashMap<String,SchemeMapValue>();
  119.16          parse();
  119.17      }
  119.18  
  119.19 @@ -136,7 +136,7 @@
  119.20          HeaderParser parser;
  119.21      }
  119.22  
  119.23 -    HashMap schemes;
  119.24 +    HashMap<String, SchemeMapValue> schemes;
  119.25  
  119.26      /* Iterate through each header line, and then within each line.
  119.27       * If multiple entries exist for a particular scheme (unlikely)
  119.28 @@ -144,11 +144,11 @@
  119.29       * preferred scheme that we support will be used.
  119.30       */
  119.31      private void parse () {
  119.32 -        Iterator iter = rsp.multiValueIterator (hdrname);
  119.33 +        Iterator<String> iter = rsp.multiValueIterator(hdrname);
  119.34          while (iter.hasNext()) {
  119.35 -            String raw = (String)iter.next();
  119.36 -            HeaderParser hp = new HeaderParser (raw);
  119.37 -            Iterator keys = hp.keys();
  119.38 +            String raw = iter.next();
  119.39 +            HeaderParser hp = new HeaderParser(raw);
  119.40 +            Iterator<String> keys = hp.keys();
  119.41              int i, lastSchemeIndex;
  119.42              for (i=0, lastSchemeIndex = -1; keys.hasNext(); i++) {
  119.43                  keys.next();
  119.44 @@ -164,7 +164,7 @@
  119.45              if (i > lastSchemeIndex) {
  119.46                  HeaderParser hpn = hp.subsequence (lastSchemeIndex, i);
  119.47                  String scheme = hpn.findKey(0);
  119.48 -                schemes.put (scheme, new SchemeMapValue (hpn, raw));
  119.49 +                schemes.put(scheme, new SchemeMapValue (hpn, raw));
  119.50              }
  119.51          }
  119.52  
  119.53 @@ -172,10 +172,10 @@
  119.54           * negotiate -> kerberos -> digest -> ntlm -> basic
  119.55           */
  119.56          SchemeMapValue v = null;
  119.57 -        if (authPref == null || (v=(SchemeMapValue)schemes.get (authPref)) == null) {
  119.58 +        if (authPref == null || (v=schemes.get (authPref)) == null) {
  119.59  
  119.60              if(v == null && !dontUseNegotiate) {
  119.61 -                SchemeMapValue tmp = (SchemeMapValue)schemes.get("negotiate");
  119.62 +                SchemeMapValue tmp = schemes.get("negotiate");
  119.63                  if(tmp != null) {
  119.64                      if(hci == null || !NegotiateAuthentication.isSupported(new HttpCallerInfo(hci, "Negotiate"))) {
  119.65                          tmp = null;
  119.66 @@ -185,7 +185,7 @@
  119.67              }
  119.68  
  119.69              if(v == null && !dontUseNegotiate) {
  119.70 -                SchemeMapValue tmp = (SchemeMapValue)schemes.get("kerberos");
  119.71 +                SchemeMapValue tmp = schemes.get("kerberos");
  119.72                  if(tmp != null) {
  119.73                      // the Kerberos scheme is only observed in MS ISA Server. In
  119.74                      // fact i think it's a Kerberos-mechnism-only Negotiate.
  119.75 @@ -205,9 +205,9 @@
  119.76              }
  119.77  
  119.78              if(v == null) {
  119.79 -                if ((v=(SchemeMapValue)schemes.get ("digest")) == null) {
  119.80 -                    if (((v=(SchemeMapValue)schemes.get("ntlm"))==null)) {
  119.81 -                        v = (SchemeMapValue)schemes.get ("basic");
  119.82 +                if ((v=schemes.get ("digest")) == null) {
  119.83 +                    if (((v=schemes.get("ntlm"))==null)) {
  119.84 +                        v = schemes.get ("basic");
  119.85                      }
  119.86                  }
  119.87              }
   120.1 --- a/src/share/classes/sun/net/www/protocol/http/HttpURLConnection.java	Fri Sep 30 17:20:56 2011 -0700
   120.2 +++ b/src/share/classes/sun/net/www/protocol/http/HttpURLConnection.java	Tue Oct 04 12:39:42 2011 -0700
   120.3 @@ -25,6 +25,7 @@
   120.4  
   120.5  package sun.net.www.protocol.http;
   120.6  
   120.7 +import java.util.Arrays;
   120.8  import java.net.URL;
   120.9  import java.net.URLConnection;
  120.10  import java.net.ProtocolException;
  120.11 @@ -229,9 +230,9 @@
  120.12              bufSize4ES = 4096; // use the default
  120.13          }
  120.14  
  120.15 -        allowRestrictedHeaders = ((Boolean)java.security.AccessController.doPrivileged(
  120.16 +        allowRestrictedHeaders = java.security.AccessController.doPrivileged(
  120.17                  new sun.security.action.GetBooleanAction(
  120.18 -                    "sun.net.http.allowRestrictedHeaders"))).booleanValue();
  120.19 +                    "sun.net.http.allowRestrictedHeaders")).booleanValue();
  120.20          if (!allowRestrictedHeaders) {
  120.21              restrictedHeaderSet = new HashSet<String>(restrictedHeaders.length);
  120.22              for (int i=0; i < restrictedHeaders.length; i++) {
  120.23 @@ -289,6 +290,7 @@
  120.24       * REMIND:  backwards compatibility with JDK 1.1.  Should be
  120.25       * eliminated for JDK 2.0.
  120.26       */
  120.27 +    @Deprecated
  120.28      private static HttpAuthenticator defaultAuth;
  120.29  
  120.30      /* all the headers we send
  120.31 @@ -750,6 +752,7 @@
  120.32      /**
  120.33       * @deprecated.  Use java.net.Authenticator.setDefault() instead.
  120.34       */
  120.35 +    @Deprecated
  120.36      public static void setDefaultAuthenticator(HttpAuthenticator a) {
  120.37          defaultAuth = a;
  120.38      }
  120.39 @@ -830,8 +833,7 @@
  120.40                      InetAddress a1 = InetAddress.getByName(h1);
  120.41                      InetAddress a2 = InetAddress.getByName(h2);
  120.42                      result[0] = a1.equals(a2);
  120.43 -                } catch(UnknownHostException e) {
  120.44 -                } catch(SecurityException e) {
  120.45 +                } catch(UnknownHostException | SecurityException e) {
  120.46                  }
  120.47                  return null;
  120.48              }
  120.49 @@ -1336,9 +1338,9 @@
  120.50  
  120.51                      // Read comments labeled "Failed Negotiate" for details.
  120.52                      boolean dontUseNegotiate = false;
  120.53 -                    Iterator iter = responses.multiValueIterator("Proxy-Authenticate");
  120.54 +                    Iterator<String> iter = responses.multiValueIterator("Proxy-Authenticate");
  120.55                      while (iter.hasNext()) {
  120.56 -                        String value = ((String)iter.next()).trim();
  120.57 +                        String value = iter.next().trim();
  120.58                          if (value.equalsIgnoreCase("Negotiate") ||
  120.59                                  value.equalsIgnoreCase("Kerberos")) {
  120.60                              if (!inNegotiateProxy) {
  120.61 @@ -1414,9 +1416,9 @@
  120.62  
  120.63                      // Read comments labeled "Failed Negotiate" for details.
  120.64                      boolean dontUseNegotiate = false;
  120.65 -                    Iterator iter = responses.multiValueIterator("WWW-Authenticate");
  120.66 +                    Iterator<String> iter = responses.multiValueIterator("WWW-Authenticate");
  120.67                      while (iter.hasNext()) {
  120.68 -                        String value = ((String)iter.next()).trim();
  120.69 +                        String value = iter.next().trim();
  120.70                          if (value.equalsIgnoreCase("Negotiate") ||
  120.71                                  value.equalsIgnoreCase("Kerberos")) {
  120.72                              if (!inNegotiate) {
  120.73 @@ -1585,9 +1587,8 @@
  120.74                                  // HttpsURLConnection instance saved in
  120.75                                  // DelegateHttpsURLConnection
  120.76                                  uconn = (URLConnection)this.getClass().getField("httpsURLConnection").get(this);
  120.77 -                                } catch (IllegalAccessException iae) {
  120.78 -                                    // ignored; use 'this'
  120.79 -                                } catch (NoSuchFieldException nsfe) {
  120.80 +                                } catch (IllegalAccessException |
  120.81 +                                         NoSuchFieldException e) {
  120.82                                      // ignored; use 'this'
  120.83                                  }
  120.84                              }
  120.85 @@ -1786,9 +1787,9 @@
  120.86                  if (respCode == HTTP_PROXY_AUTH) {
  120.87                      // Read comments labeled "Failed Negotiate" for details.
  120.88                      boolean dontUseNegotiate = false;
  120.89 -                    Iterator iter = responses.multiValueIterator("Proxy-Authenticate");
  120.90 +                    Iterator<String> iter = responses.multiValueIterator("Proxy-Authenticate");
  120.91                      while (iter.hasNext()) {
  120.92 -                        String value = ((String)iter.next()).trim();
  120.93 +                        String value = iter.next().trim();
  120.94                          if (value.equalsIgnoreCase("Negotiate") ||
  120.95                                  value.equalsIgnoreCase("Kerberos")) {
  120.96                              if (!inNegotiateProxy) {
  120.97 @@ -1938,6 +1939,7 @@
  120.98       * Gets the authentication for an HTTP proxy, and applies it to
  120.99       * the connection.
 120.100       */
 120.101 +    @SuppressWarnings("fallthrough")
 120.102      private AuthenticationInfo getHttpProxyAuthentication (AuthenticationHeader authhdr) {
 120.103          /* get authorization from authenticator */
 120.104          AuthenticationInfo ret = null;
 120.105 @@ -2004,13 +2006,13 @@
 120.106                      }
 120.107                      break;
 120.108                  case NTLM:
 120.109 -                    if (NTLMAuthenticationProxy.proxy.supported) {
 120.110 +                    if (NTLMAuthenticationProxy.supported) {
 120.111                          /* tryTransparentNTLMProxy will always be true the first
 120.112                           * time around, but verify that the platform supports it
 120.113                           * otherwise don't try. */
 120.114                          if (tryTransparentNTLMProxy) {
 120.115                              tryTransparentNTLMProxy =
 120.116 -                                    NTLMAuthenticationProxy.proxy.supportsTransparentAuth;
 120.117 +                                    NTLMAuthenticationProxy.supportsTransparentAuth;
 120.118                          }
 120.119                          a = null;
 120.120                          if (tryTransparentNTLMProxy) {
 120.121 @@ -2043,6 +2045,7 @@
 120.122                      break;
 120.123                  case UNKNOWN:
 120.124                      logger.finest("Unknown/Unsupported authentication scheme: " + scheme);
 120.125 +                /*fall through*/
 120.126                  default:
 120.127                      throw new AssertionError("should not reach here");
 120.128                  }
 120.129 @@ -2080,6 +2083,7 @@
 120.130       * @param authHdr the AuthenticationHeader which tells what auth scheme is
 120.131       * prefered.
 120.132       */
 120.133 +    @SuppressWarnings("fallthrough")
 120.134      private AuthenticationInfo getServerAuthentication (AuthenticationHeader authhdr) {
 120.135          /* get authorization from authenticator */
 120.136          AuthenticationInfo ret = null;
 120.137 @@ -2150,7 +2154,7 @@
 120.138                      }
 120.139                      break;
 120.140                  case NTLM:
 120.141 -                    if (NTLMAuthenticationProxy.proxy.supported) {
 120.142 +                    if (NTLMAuthenticationProxy.supported) {
 120.143                          URL url1;
 120.144                          try {
 120.145                              url1 = new URL (url, "/"); /* truncate the path */
 120.146 @@ -2163,13 +2167,13 @@
 120.147                           * otherwise don't try. */
 120.148                          if (tryTransparentNTLMServer) {
 120.149                              tryTransparentNTLMServer =
 120.150 -                                    NTLMAuthenticationProxy.proxy.supportsTransparentAuth;
 120.151 +                                    NTLMAuthenticationProxy.supportsTransparentAuth;
 120.152                              /* If the platform supports transparent authentication
 120.153                               * then check if we are in a secure environment
 120.154                               * whether, or not, we should try transparent authentication.*/
 120.155                              if (tryTransparentNTLMServer) {
 120.156                                  tryTransparentNTLMServer =
 120.157 -                                        NTLMAuthenticationProxy.proxy.isTrustedSite(url);
 120.158 +                                        NTLMAuthenticationProxy.isTrustedSite(url);
 120.159                              }
 120.160                          }
 120.161                          a = null;
 120.162 @@ -2198,6 +2202,7 @@
 120.163                      break;
 120.164                  case UNKNOWN:
 120.165                      logger.finest("Unknown/Unsupported authentication scheme: " + scheme);
 120.166 +                /*fall through*/
 120.167                  default:
 120.168                      throw new AssertionError("should not reach here");
 120.169                  }
 120.170 @@ -2745,14 +2750,14 @@
 120.171           * The cookies in the requests message headers may have
 120.172           * been modified. Use the saved user cookies instead.
 120.173           */
 120.174 -        Map userCookiesMap = null;
 120.175 +        Map<String, List<String>> userCookiesMap = null;
 120.176          if (userCookies != null || userCookies2 != null) {
 120.177 -            userCookiesMap = new HashMap();
 120.178 +            userCookiesMap = new HashMap<>();
 120.179              if (userCookies != null) {
 120.180 -                userCookiesMap.put("Cookie", userCookies);
 120.181 +                userCookiesMap.put("Cookie", Arrays.asList(userCookies));
 120.182              }
 120.183              if (userCookies2 != null) {
 120.184 -                userCookiesMap.put("Cookie2", userCookies2);
 120.185 +                userCookiesMap.put("Cookie2", Arrays.asList(userCookies2));
 120.186              }
 120.187          }
 120.188          return requests.filterAndAddHeaders(EXCLUDE_HEADERS2, userCookiesMap);
   121.1 --- a/src/share/classes/sun/net/www/protocol/http/Negotiator.java	Fri Sep 30 17:20:56 2011 -0700
   121.2 +++ b/src/share/classes/sun/net/www/protocol/http/Negotiator.java	Tue Oct 04 12:39:42 2011 -0700
   121.3 @@ -1,5 +1,5 @@
   121.4  /*
   121.5 - * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
   121.6 + * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
   121.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   121.8   *
   121.9   * This code is free software; you can redistribute it and/or modify it
  121.10 @@ -45,8 +45,8 @@
  121.11          // Makes NegotiatorImpl, and the security classes it references, a
  121.12          // runtime dependency rather than a static one.
  121.13  
  121.14 -        Class clazz;
  121.15 -        Constructor c;
  121.16 +        Class<?> clazz;
  121.17 +        Constructor<?> c;
  121.18          try {
  121.19              clazz = Class.forName("sun.net.www.protocol.http.spnego.NegotiatorImpl", true, null);
  121.20              c = clazz.getConstructor(HttpCallerInfo.class);
   122.1 --- a/src/share/classes/sun/net/www/protocol/https/AbstractDelegateHttpsURLConnection.java	Fri Sep 30 17:20:56 2011 -0700
   122.2 +++ b/src/share/classes/sun/net/www/protocol/https/AbstractDelegateHttpsURLConnection.java	Tue Oct 04 12:39:42 2011 -0700
   122.3 @@ -1,5 +1,5 @@
   122.4  /*
   122.5 - * Copyright (c) 2001, 2006, Oracle and/or its affiliates. All rights reserved.
   122.6 + * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
   122.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   122.8   *
   122.9   * This code is free software; you can redistribute it and/or modify it
  122.10 @@ -221,11 +221,11 @@
  122.11       */
  122.12      public java.security.cert.Certificate[] getLocalCertificates() {
  122.13          if (cachedResponse != null) {
  122.14 -            List l = ((SecureCacheResponse)cachedResponse).getLocalCertificateChain();
  122.15 +            List<java.security.cert.Certificate> l = ((SecureCacheResponse)cachedResponse).getLocalCertificateChain();
  122.16              if (l == null) {
  122.17                  return null;
  122.18              } else {
  122.19 -                return (java.security.cert.Certificate[])l.toArray();
  122.20 +                return l.toArray(new java.security.cert.Certificate[0]);
  122.21              }
  122.22          }
  122.23          if (http == null) {
  122.24 @@ -243,11 +243,11 @@
  122.25      public java.security.cert.Certificate[] getServerCertificates()
  122.26              throws SSLPeerUnverifiedException {
  122.27          if (cachedResponse != null) {
  122.28 -            List l = ((SecureCacheResponse)cachedResponse).getServerCertificateChain();
  122.29 +            List<java.security.cert.Certificate> l = ((SecureCacheResponse)cachedResponse).getServerCertificateChain();
  122.30              if (l == null) {
  122.31                  return null;
  122.32              } else {
  122.33 -                return (java.security.cert.Certificate[])l.toArray();
  122.34 +                return l.toArray(new java.security.cert.Certificate[0]);
  122.35              }
  122.36          }
  122.37  
   123.1 --- a/src/share/classes/sun/net/www/protocol/https/HttpsClient.java	Fri Sep 30 17:20:56 2011 -0700
   123.2 +++ b/src/share/classes/sun/net/www/protocol/https/HttpsClient.java	Tue Oct 04 12:39:42 2011 -0700
   123.3 @@ -1,5 +1,5 @@
   123.4  /*
   123.5 - * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
   123.6 + * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
   123.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   123.8   *
   123.9   * This code is free software; you can redistribute it and/or modify it
  123.10 @@ -529,7 +529,7 @@
  123.11                      new BufferedOutputStream(serverSocket.getOutputStream()),
  123.12                      false, encoding);
  123.13              } catch (UnsupportedEncodingException e) {
  123.14 -                throw new InternalError(encoding+" encoding not found", e);
  123.15 +                throw new InternalError(encoding+" encoding not found");
  123.16              }
  123.17  
  123.18              // check URL spoofing if it has not been checked under handshaking
  123.19 @@ -623,7 +623,7 @@
  123.20       */
  123.21      @Override
  123.22      public void closeIdleConnection() {
  123.23 -        HttpClient http = (HttpClient) kac.get(url, sslSocketFactory);
  123.24 +        HttpClient http = kac.get(url, sslSocketFactory);
  123.25          if (http != null) {
  123.26              http.closeServer();
  123.27          }
  123.28 @@ -681,8 +681,7 @@
  123.29              // return the X500Principal of the end-entity cert.
  123.30              java.security.cert.Certificate[] certs =
  123.31                          session.getPeerCertificates();
  123.32 -            principal = (X500Principal)
  123.33 -                ((X509Certificate)certs[0]).getSubjectX500Principal();
  123.34 +            principal = ((X509Certificate)certs[0]).getSubjectX500Principal();
  123.35          }
  123.36          return principal;
  123.37      }
  123.38 @@ -703,8 +702,7 @@
  123.39              java.security.cert.Certificate[] certs =
  123.40                          session.getLocalCertificates();
  123.41              if (certs != null) {
  123.42 -                principal = (X500Principal)
  123.43 -                    ((X509Certificate)certs[0]).getSubjectX500Principal();
  123.44 +                principal = ((X509Certificate)certs[0]).getSubjectX500Principal();
  123.45              }
  123.46          }
  123.47          return principal;
   124.1 --- a/src/share/classes/sun/net/www/protocol/mailto/Handler.java	Fri Sep 30 17:20:56 2011 -0700
   124.2 +++ b/src/share/classes/sun/net/www/protocol/mailto/Handler.java	Tue Oct 04 12:39:42 2011 -0700
   124.3 @@ -139,6 +139,20 @@
   124.4          }
   124.5          if (nogood)
   124.6              throw new RuntimeException("No email address");
   124.7 -        setURL(u, protocol, host, port, file, null);
   124.8 +        setURLHandler(u, protocol, host, port, file, null);
   124.9 +    }
  124.10 +
  124.11 +    /**
  124.12 +     * This method is used to suppress the deprecated warning
  124.13 +     *
  124.14 +     * @param   u the URL to receive the result of parsing the spec
  124.15 +     * @param   spec the URL string to parse
  124.16 +     * @param   start the character position to start parsing at.  This is
  124.17 +     *          just past the ':'.
  124.18 +     * @param   limit the character position to stop parsing at.
  124.19 +     */
  124.20 +    @SuppressWarnings("deprecation")
  124.21 +    private void setURLHandler(URL u, String protocol, String host, int port, String file, String ref) {
  124.22 +        setURL(u,protocol,host,port,file,null);
  124.23      }
  124.24  }
   125.1 --- a/src/share/classes/sun/security/x509/AVA.java	Fri Sep 30 17:20:56 2011 -0700
   125.2 +++ b/src/share/classes/sun/security/x509/AVA.java	Tue Oct 04 12:39:42 2011 -0700
   125.3 @@ -1071,8 +1071,17 @@
   125.4                   * to need quoting, or at least escaping.  So do leading or
   125.5                   * trailing spaces, and multiple internal spaces.
   125.6                   */
   125.7 -                for (int i = 0; i < valStr.length(); i++) {
   125.8 +                int length = valStr.length();
   125.9 +                boolean alreadyQuoted =
  125.10 +                    (length > 1 && valStr.charAt(0) == '\"'
  125.11 +                     && valStr.charAt(length - 1) == '\"');
  125.12 +
  125.13 +                for (int i = 0; i < length; i++) {
  125.14                      char c = valStr.charAt(i);
  125.15 +                    if (alreadyQuoted && (i == 0 || i == length - 1)) {
  125.16 +                        sbuffer.append(c);
  125.17 +                        continue;
  125.18 +                    }
  125.19                      if (DerValue.isPrintableStringChar(c) ||
  125.20                          escapees.indexOf(c) >= 0) {
  125.21  
  125.22 @@ -1136,7 +1145,8 @@
  125.23                  }
  125.24  
  125.25                  // Emit the string ... quote it if needed
  125.26 -                if (quoteNeeded) {
  125.27 +                // if string is already quoted, don't re-quote
  125.28 +                if (!alreadyQuoted && quoteNeeded) {
  125.29                      retval.append("\"" + sbuffer.toString() + "\"");
  125.30                  } else {
  125.31                      retval.append(sbuffer.toString());
   126.1 --- a/src/share/classes/sun/swing/FilePane.java	Fri Sep 30 17:20:56 2011 -0700
   126.2 +++ b/src/share/classes/sun/swing/FilePane.java	Tue Oct 04 12:39:42 2011 -0700
   126.3 @@ -35,6 +35,7 @@
   126.4  import java.util.List;
   126.5  import java.util.concurrent.Callable;
   126.6  
   126.7 +import javax.accessibility.AccessibleContext;
   126.8  import javax.swing.*;
   126.9  import javax.swing.border.*;
  126.10  import javax.swing.event.*;
  126.11 @@ -82,6 +83,9 @@
  126.12      private JPanel currentViewPanel;
  126.13      private String[] viewTypeActionNames;
  126.14  
  126.15 +    private String filesListAccessibleName = null;
  126.16 +    private String filesDetailsAccessibleName = null;
  126.17 +
  126.18      private JPopupMenu contextMenu;
  126.19      private JMenu viewMenu;
  126.20  
  126.21 @@ -450,6 +454,9 @@
  126.22          gigaByteString = UIManager.getString("FileChooser.fileSizeGigaBytes", l);
  126.23          fullRowSelection = UIManager.getBoolean("FileView.fullRowSelection");
  126.24  
  126.25 +        filesListAccessibleName = UIManager.getString("FileChooser.filesListAccessibleName", l);
  126.26 +        filesDetailsAccessibleName = UIManager.getString("FileChooser.filesDetailsAccessibleName", l);
  126.27 +
  126.28          renameErrorTitleText = UIManager.getString("FileChooser.renameErrorTitleText", l);
  126.29          renameErrorText = UIManager.getString("FileChooser.renameErrorText", l);
  126.30          renameErrorFileExistsText = UIManager.getString("FileChooser.renameErrorFileExistsText", l);
  126.31 @@ -634,6 +641,9 @@
  126.32          if (listViewBorder != null) {
  126.33              scrollpane.setBorder(listViewBorder);
  126.34          }
  126.35 +
  126.36 +        list.putClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY, filesListAccessibleName);
  126.37 +
  126.38          p.add(scrollpane, BorderLayout.CENTER);
  126.39          return p;
  126.40      }
  126.41 @@ -1228,6 +1238,8 @@
  126.42  
  126.43          detailsTableModel.fireTableStructureChanged();
  126.44  
  126.45 +        detailsTable.putClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY, filesDetailsAccessibleName);
  126.46 +
  126.47          return p;
  126.48      } // createDetailsView
  126.49  
   127.1 --- a/src/share/classes/sun/tools/jar/JarImageSource.java	Fri Sep 30 17:20:56 2011 -0700
   127.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   127.3 @@ -1,88 +0,0 @@
   127.4 -/*
   127.5 - * Copyright (c) 1996, 1998, Oracle and/or its affiliates. All rights reserved.
   127.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   127.7 - *
   127.8 - * This code is free software; you can redistribute it and/or modify it
   127.9 - * under the terms of the GNU General Public License version 2 only, as
  127.10 - * published by the Free Software Foundation.  Oracle designates this
  127.11 - * particular file as subject to the "Classpath" exception as provided
  127.12 - * by Oracle in the LICENSE file that accompanied this code.
  127.13 - *
  127.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
  127.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  127.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  127.17 - * version 2 for more details (a copy is included in the LICENSE file that
  127.18 - * accompanied this code).
  127.19 - *
  127.20 - * You should have received a copy of the GNU General Public License version
  127.21 - * 2 along with this work; if not, write to the Free Software Foundation,
  127.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  127.23 - *
  127.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  127.25 - * or visit www.oracle.com if you need additional information or have any
  127.26 - * questions.
  127.27 - */
  127.28 -
  127.29 -
  127.30 -package sun.tools.jar;
  127.31 -
  127.32 -import sun.awt.image.URLImageSource;
  127.33 -import sun.awt.image.ImageDecoder;
  127.34 -import java.net.URL;
  127.35 -import java.net.JarURLConnection;
  127.36 -import java.util.jar.JarFile;
  127.37 -import java.util.jar.JarEntry;
  127.38 -import java.io.InputStream;
  127.39 -import java.io.IOException;
  127.40 -
  127.41 -
  127.42 -public class JarImageSource extends URLImageSource {
  127.43 -    String mimeType;
  127.44 -    String entryName = null;
  127.45 -    URL url;
  127.46 -
  127.47 -    /**
  127.48 -     * Create an image source from a Jar entry URL with the specified
  127.49 -     * mime type.
  127.50 -     */
  127.51 -    public JarImageSource(URL u, String type) {
  127.52 -        super(u);
  127.53 -        url = u;
  127.54 -        mimeType = type;
  127.55 -    }
  127.56 -
  127.57 -    /**
  127.58 -     * Create an image source from a Jar file/entry URL
  127.59 -     * with the specified entry name and mime type.
  127.60 -     */
  127.61 -    public JarImageSource(URL u, String name, String type) {
  127.62 -        this(u, type);
  127.63 -        this.entryName = name;
  127.64 -    }
  127.65 -
  127.66 -    protected ImageDecoder getDecoder() {
  127.67 -        InputStream is = null;
  127.68 -        try {
  127.69 -            JarURLConnection c = (JarURLConnection)url.openConnection();
  127.70 -            JarFile f = c.getJarFile();
  127.71 -            JarEntry e = c.getJarEntry();
  127.72 -
  127.73 -            if (entryName != null && e == null) {
  127.74 -                e = f.getJarEntry(entryName);
  127.75 -            }
  127.76 -            if (e == null || (e != null && entryName != null
  127.77 -                              && (!(entryName.equals(e.getName()))))) {
  127.78 -                return null;
  127.79 -            }
  127.80 -            is = f.getInputStream(e);
  127.81 -        } catch (IOException e) {
  127.82 -            return null;
  127.83 -        }
  127.84 -
  127.85 -        ImageDecoder id = decoderForType(is, mimeType);
  127.86 -        if (id == null) {
  127.87 -            id = getDecoder(is);
  127.88 -        }
  127.89 -        return id;
  127.90 -    }
  127.91 -}
   128.1 --- a/src/share/classes/sun/util/resources/TimeZoneNames.java	Fri Sep 30 17:20:56 2011 -0700
   128.2 +++ b/src/share/classes/sun/util/resources/TimeZoneNames.java	Tue Oct 04 12:39:42 2011 -0700
   128.3 @@ -159,8 +159,6 @@
   128.4                                        "Pohnpei Summer Time", "PONST"};
   128.5          String PST[] = new String[] {"Pacific Standard Time", "PST",
   128.6                                       "Pacific Daylight Time", "PDT"};
   128.7 -        String RST[] = new String[] {"Eastern Standard Time", "EST",
   128.8 -                                     "Central Daylight Time", "CDT"};
   128.9          String SAST[] = new String[] {"South Africa Standard Time", "SAST",
  128.10                                        "South Africa Summer Time", "SAST"};
  128.11          String SBT[] = new String[] {"Solomon Is. Time", "SBT",
  128.12 @@ -262,6 +260,7 @@
  128.13              {"Africa/Gaborone", CAT},
  128.14              {"Africa/Harare", CAT},
  128.15              {"Africa/Johannesburg", SAST},
  128.16 +            {"Africa/Juba", EAT},
  128.17              {"Africa/Kampala", EAT},
  128.18              {"Africa/Khartoum", EAT},
  128.19              {"Africa/Kigali", CAT},
  128.20 @@ -378,11 +377,13 @@
  128.21              {"America/Kentucky/Louisville", EST},
  128.22              {"America/Kentucky/Monticello", EST},
  128.23              {"America/Knox_IN", CST},
  128.24 +            {"America/Kralendijk", AST},
  128.25              {"America/La_Paz", new String[] {"Bolivia Time", "BOT",
  128.26                                               "Bolivia Summer Time", "BOST"}},
  128.27              {"America/Lima", new String[] {"Peru Time", "PET",
  128.28                                             "Peru Summer Time", "PEST"}},
  128.29              {"America/Louisville", EST},
  128.30 +            {"America/Lower_Princes", AST},
  128.31              {"America/Maceio", BRT},
  128.32              {"America/Managua", CST},
  128.33              {"America/Manaus", AMT},
  128.34 @@ -425,7 +426,7 @@
  128.35              {"America/Rankin_Inlet", CST},
  128.36              {"America/Recife", BRT},
  128.37              {"America/Regina", CST},
  128.38 -            {"America/Resolute", RST},
  128.39 +            {"America/Resolute", CST},
  128.40              {"America/Rio_Branco", AMT},
  128.41              {"America/Rosario", AGT},
  128.42              {"America/Santa_Isabel", PST},
  128.43 @@ -673,7 +674,8 @@
  128.44              {"Europe/Isle_of_Man", GMTBST},
  128.45              {"Europe/Istanbul", EET},
  128.46              {"Europe/Jersey", GMTBST},
  128.47 -            {"Europe/Kaliningrad", EET},
  128.48 +            {"Europe/Kaliningrad", new String[] {"Kaliningrad Time", "KALT",
  128.49 +                                                 "Kaliningrad Summer Time", "KALST"}},
  128.50              {"Europe/Kiev", EET},
  128.51              {"Europe/Lisbon", WET},
  128.52              {"Europe/Ljubljana", CET},
   129.1 --- a/src/share/classes/sun/util/resources/TimeZoneNames_de.java	Fri Sep 30 17:20:56 2011 -0700
   129.2 +++ b/src/share/classes/sun/util/resources/TimeZoneNames_de.java	Tue Oct 04 12:39:42 2011 -0700
   129.3 @@ -159,8 +159,6 @@
   129.4                                        "Pohnpei Summer Time", "PONST"};
   129.5          String PST[] = new String[] {"Pazifische Normalzeit", "PST",
   129.6                                       "Pazifische Sommerzeit", "PDT"};
   129.7 -        String RST[] = new String[] {"\u00d6stliche Normalzeit", "EST",
   129.8 -                                     "Zentrale Sommerzeit", "CDT"};
   129.9          String SAST[] = new String[] {"S\u00fcdafrikanische Normalzeit", "SAST",
  129.10                                        "S\u00fcdafrikanische Sommerzeit", "SAST"};
  129.11          String SBT[] = new String[] {"Salomoninseln Zeit", "SBT",
  129.12 @@ -262,6 +260,7 @@
  129.13              {"Africa/Gaborone", CAT},
  129.14              {"Africa/Harare", CAT},
  129.15              {"Africa/Johannesburg", SAST},
  129.16 +            {"Africa/Juba", EAT},
  129.17              {"Africa/Kampala", EAT},
  129.18              {"Africa/Khartoum", EAT},
  129.19              {"Africa/Kigali", CAT},
  129.20 @@ -378,11 +377,13 @@
  129.21              {"America/Kentucky/Louisville", EST},
  129.22              {"America/Kentucky/Monticello", EST},
  129.23              {"America/Knox_IN", CST},
  129.24 +            {"America/Kralendijk", AST},
  129.25              {"America/La_Paz", new String[] {"Bolivianische Zeit", "BOT",
  129.26                                               "Bolivianische Sommerzeit", "BOST"}},
  129.27              {"America/Lima", new String[] {"Peruanische Zeit", "PET",
  129.28                                             "Peruanische Sommerzeit", "PEST"}},
  129.29              {"America/Louisville", EST},
  129.30 +            {"America/Lower_Princes", AST},
  129.31              {"America/Maceio", BRT},
  129.32              {"America/Managua", CST},
  129.33              {"America/Manaus", AMT},
  129.34 @@ -425,7 +426,7 @@
  129.35              {"America/Rankin_Inlet", CST},
  129.36              {"America/Recife", BRT},
  129.37              {"America/Regina", CST},
  129.38 -            {"America/Resolute", RST},
  129.39 +            {"America/Resolute", CST},
  129.40              {"America/Rio_Branco", AMT},
  129.41              {"America/Rosario", AGT},
  129.42              {"America/Santa_Isabel", PST},
  129.43 @@ -673,7 +674,8 @@
  129.44              {"Europe/Isle_of_Man", GMTBST},
  129.45              {"Europe/Istanbul", EET},
  129.46              {"Europe/Jersey", GMTBST},
  129.47 -            {"Europe/Kaliningrad", EET},
  129.48 +            {"Europe/Kaliningrad", new String[] {"Kaliningrad Time", "KALT",
  129.49 +                                                 "Kaliningrad Summer Time", "KALST"}},
  129.50              {"Europe/Kiev", EET},
  129.51              {"Europe/Lisbon", WET},
  129.52              {"Europe/Ljubljana", CET},
   130.1 --- a/src/share/classes/sun/util/resources/TimeZoneNames_es.java	Fri Sep 30 17:20:56 2011 -0700
   130.2 +++ b/src/share/classes/sun/util/resources/TimeZoneNames_es.java	Tue Oct 04 12:39:42 2011 -0700
   130.3 @@ -159,8 +159,6 @@
   130.4                                        "Pohnpei Summer Time", "PONST"};
   130.5          String PST[] = new String[] {"Hora est\u00e1ndar del Pac\u00edfico", "PST",
   130.6                                       "Hora de verano del Pac\u00edfico", "PDT"};
   130.7 -        String RST[] = new String[] {"Hora est\u00e1ndar Oriental", "EST",
   130.8 -                                     "Hora de verano Central", "CDT"};
   130.9          String SAST[] = new String[] {"Hora est\u00e1ndar de Sud\u00e1frica", "SAST",
  130.10                                        "Hora de verano de Sud\u00e1frica", "SAST"};
  130.11          String SBT[] = new String[] {"Hora de las Islas Solomon", "SBT",
  130.12 @@ -262,6 +260,7 @@
  130.13              {"Africa/Gaborone", CAT},
  130.14              {"Africa/Harare", CAT},
  130.15              {"Africa/Johannesburg", SAST},
  130.16 +            {"Africa/Juba", EAT},
  130.17              {"Africa/Kampala", EAT},
  130.18              {"Africa/Khartoum", EAT},
  130.19              {"Africa/Kigali", CAT},
  130.20 @@ -378,11 +377,13 @@
  130.21              {"America/Kentucky/Louisville", EST},
  130.22              {"America/Kentucky/Monticello", EST},
  130.23              {"America/Knox_IN", CST},
  130.24 +            {"America/Kralendijk", AST},
  130.25              {"America/La_Paz", new String[] {"Hora de Bolivia", "BOT",
  130.26                                               "Hora de verano de Bolivia", "BOST"}},
  130.27              {"America/Lima", new String[] {"Hora de Per\u00fa", "PET",
  130.28                                             "Hora de verano de Per\u00fa", "PEST"}},
  130.29              {"America/Louisville", EST},
  130.30 +            {"America/Lower_Princes", AST},
  130.31              {"America/Maceio", BRT},
  130.32              {"America/Managua", CST},
  130.33              {"America/Manaus", AMT},
  130.34 @@ -425,7 +426,7 @@
  130.35              {"America/Rankin_Inlet", CST},
  130.36              {"America/Recife", BRT},
  130.37              {"America/Regina", CST},
  130.38 -            {"America/Resolute", RST},
  130.39 +            {"America/Resolute", CST},
  130.40              {"America/Rio_Branco", AMT},
  130.41              {"America/Rosario", AGT},
  130.42              {"America/Santa_Isabel", PST},
  130.43 @@ -673,7 +674,8 @@
  130.44              {"Europe/Isle_of_Man", GMTBST},
  130.45              {"Europe/Istanbul", EET},
  130.46              {"Europe/Jersey", GMTBST},
  130.47 -            {"Europe/Kaliningrad", EET},
  130.48 +            {"Europe/Kaliningrad", new String[] {"Kaliningrad Time", "KALT",
  130.49 +                                                 "Kaliningrad Summer Time", "KALST"}},
  130.50              {"Europe/Kiev", EET},
  130.51              {"Europe/Lisbon", WET},
  130.52              {"Europe/Ljubljana", CET},
   131.1 --- a/src/share/classes/sun/util/resources/TimeZoneNames_fr.java	Fri Sep 30 17:20:56 2011 -0700
   131.2 +++ b/src/share/classes/sun/util/resources/TimeZoneNames_fr.java	Tue Oct 04 12:39:42 2011 -0700
   131.3 @@ -159,8 +159,6 @@
   131.4                                        "Pohnpei Summer Time", "PONST"};
   131.5          String PST[] = new String[] {"Heure normale du Pacifique", "PST",
   131.6                                       "Heure avanc\u00e9e du Pacifique", "PDT"} ;
   131.7 -        String RST[] = new String[] {"Heure normale de l'Est", "EST",
   131.8 -                                     "Heure avanc\u00e9e du Centre", "CDT"} ;
   131.9          String SAST[] = new String[] {"Heure normale d'Afrique du Sud", "SAST",
  131.10                                        "Heure d'\u00e9t\u00e9 d'Afrique du Sud", "SAST"} ;
  131.11          String SBT[] = new String[] {"Heure des \u00celes Salomon", "SBT",
  131.12 @@ -262,6 +260,7 @@
  131.13              {"Africa/Gaborone", CAT},
  131.14              {"Africa/Harare", CAT},
  131.15              {"Africa/Johannesburg", SAST},
  131.16 +            {"Africa/Juba", EAT},
  131.17              {"Africa/Kampala", EAT},
  131.18              {"Africa/Khartoum", EAT},
  131.19              {"Africa/Kigali", CAT},
  131.20 @@ -378,11 +377,13 @@
  131.21              {"America/Kentucky/Louisville", EST},
  131.22              {"America/Kentucky/Monticello", EST},
  131.23              {"America/Knox_IN", CST},
  131.24 +            {"America/Kralendijk", AST},
  131.25              {"America/La_Paz", new String[] {"Heure de Bolivie", "BOT",
  131.26                                               "Heure d'\u00e9t\u00e9 de Bolivie", "BOST"}},
  131.27              {"America/Lima", new String[] {"Heure du P\u00e9rou", "PET",
  131.28                                             "Heure d'\u00e9t\u00e9 du P\u00e9rou", "PEST"}},
  131.29              {"America/Louisville", EST},
  131.30 +            {"America/Lower_Princes", AST},
  131.31              {"America/Maceio", BRT},
  131.32              {"America/Managua", CST},
  131.33              {"America/Manaus", AMT},
  131.34 @@ -425,7 +426,7 @@
  131.35              {"America/Rankin_Inlet", CST},
  131.36              {"America/Recife", BRT},
  131.37              {"America/Regina", CST},
  131.38 -            {"America/Resolute", RST},
  131.39 +            {"America/Resolute", CST},
  131.40              {"America/Rio_Branco", AMT},
  131.41              {"America/Rosario", AGT},
  131.42              {"America/Santa_Isabel", PST},
  131.43 @@ -673,7 +674,8 @@
  131.44              {"Europe/Isle_of_Man", GMTBST},
  131.45              {"Europe/Istanbul", EET},
  131.46              {"Europe/Jersey", GMTBST},
  131.47 -            {"Europe/Kaliningrad", EET},
  131.48 +            {"Europe/Kaliningrad", new String[] {"Kaliningrad Time", "KALT",
  131.49 +                                                 "Kaliningrad Summer Time", "KALST"}},
  131.50              {"Europe/Kiev", EET},
  131.51              {"Europe/Lisbon", WET},
  131.52              {"Europe/Ljubljana", CET},
   132.1 --- a/src/share/classes/sun/util/resources/TimeZoneNames_it.java	Fri Sep 30 17:20:56 2011 -0700
   132.2 +++ b/src/share/classes/sun/util/resources/TimeZoneNames_it.java	Tue Oct 04 12:39:42 2011 -0700
   132.3 @@ -159,8 +159,6 @@
   132.4                                        "Pohnpei Summer Time", "PONST"};
   132.5          String PST[] = new String[] {"Ora solare della costa occidentale USA", "PST",
   132.6                                       "Ora legale della costa occidentale USA", "PDT"};
   132.7 -        String RST[] = new String[] {"Ora solare USA orientale", "EST",
   132.8 -                                     "Ora legale USA centrale", "CDT"};
   132.9          String SAST[] = new String[] {"Ora solare del Sudafrica", "SAST",
  132.10                                        "Ora estiva del Sudafrica", "SAST"};
  132.11          String SBT[] = new String[] {"Ora delle Isole Salomone", "SBT",
  132.12 @@ -262,6 +260,7 @@
  132.13              {"Africa/Gaborone", CAT},
  132.14              {"Africa/Harare", CAT},
  132.15              {"Africa/Johannesburg", SAST},
  132.16 +            {"Africa/Juba", EAT},
  132.17              {"Africa/Kampala", EAT},
  132.18              {"Africa/Khartoum", EAT},
  132.19              {"Africa/Kigali", CAT},
  132.20 @@ -378,11 +377,13 @@
  132.21              {"America/Kentucky/Louisville", EST},
  132.22              {"America/Kentucky/Monticello", EST},
  132.23              {"America/Knox_IN", CST},
  132.24 +            {"America/Kralendijk", AST},
  132.25              {"America/La_Paz", new String[] {"Ora della Bolivia", "BOT",
  132.26                                               "Ora estiva della Bolivia", "BOST"}},
  132.27              {"America/Lima", new String[] {"Ora del Per\u00f9", "PET",
  132.28                                             "Ora estiva del Per\u00f9", "PEST"}},
  132.29              {"America/Louisville", EST},
  132.30 +            {"America/Lower_Princes", AST},
  132.31              {"America/Maceio", BRT},
  132.32              {"America/Managua", CST},
  132.33              {"America/Manaus", AMT},
  132.34 @@ -425,7 +426,7 @@
  132.35              {"America/Rankin_Inlet", CST},
  132.36              {"America/Recife", BRT},
  132.37              {"America/Regina", CST},
  132.38 -            {"America/Resolute", RST},
  132.39 +            {"America/Resolute", CST},
  132.40              {"America/Rio_Branco", AMT},
  132.41              {"America/Rosario", AGT},
  132.42              {"America/Santa_Isabel", PST},
  132.43 @@ -673,7 +674,8 @@
  132.44              {"Europe/Isle_of_Man", GMTBST},
  132.45              {"Europe/Istanbul", EET},
  132.46              {"Europe/Jersey", GMTBST},
  132.47 -            {"Europe/Kaliningrad", EET},
  132.48 +            {"Europe/Kaliningrad", new String[] {"Kaliningrad Time", "KALT",
  132.49 +                                                 "Kaliningrad Summer Time", "KALST"}},
  132.50              {"Europe/Kiev", EET},
  132.51              {"Europe/Lisbon", WET},
  132.52              {"Europe/Ljubljana", CET},
   133.1 --- a/src/share/classes/sun/util/resources/TimeZoneNames_ja.java	Fri Sep 30 17:20:56 2011 -0700
   133.2 +++ b/src/share/classes/sun/util/resources/TimeZoneNames_ja.java	Tue Oct 04 12:39:42 2011 -0700
   133.3 @@ -159,8 +159,6 @@
   133.4                                        "Pohnpei Summer Time", "PONST"};
   133.5          String PST[] = new String[] {"\u592a\u5e73\u6d0b\u6a19\u6e96\u6642", "PST",
   133.6                                       "\u592a\u5e73\u6d0b\u590f\u6642\u9593", "PDT"};
   133.7 -        String RST[] = new String[] {"\u6771\u90e8\u6a19\u6e96\u6642", "EST",
   133.8 -                                     "\u4e2d\u90e8\u590f\u6642\u9593", "CDT"};
   133.9          String SAST[] = new String[] {"\u5357\u30a2\u30d5\u30ea\u30ab\u6a19\u6e96\u6642", "SAST",
  133.10                                        "\u5357\u30a2\u30d5\u30ea\u30ab\u590f\u6642\u9593", "SAST"};
  133.11          String SBT[] = new String[] {"\u30bd\u30ed\u30e2\u30f3\u8af8\u5cf6\u6642\u9593", "SBT",
  133.12 @@ -262,6 +260,7 @@
  133.13              {"Africa/Gaborone", CAT},
  133.14              {"Africa/Harare", CAT},
  133.15              {"Africa/Johannesburg", SAST},
  133.16 +            {"Africa/Juba", EAT},
  133.17              {"Africa/Kampala", EAT},
  133.18              {"Africa/Khartoum", EAT},
  133.19              {"Africa/Kigali", CAT},
  133.20 @@ -378,11 +377,13 @@
  133.21              {"America/Kentucky/Louisville", EST},
  133.22              {"America/Kentucky/Monticello", EST},
  133.23              {"America/Knox_IN", CST},
  133.24 +            {"America/Kralendijk", AST},
  133.25              {"America/La_Paz", new String[] {"\u30dc\u30ea\u30d3\u30a2\u6642\u9593", "BOT",
  133.26                                               "\u30dc\u30ea\u30d3\u30a2\u590f\u6642\u9593", "BOST"}},
  133.27              {"America/Lima", new String[] {"\u30da\u30eb\u30fc\u6642\u9593", "PET",
  133.28                                             "\u30da\u30eb\u30fc\u590f\u6642\u9593", "PEST"}},
  133.29              {"America/Louisville", EST},
  133.30 +            {"America/Lower_Princes", AST},
  133.31              {"America/Maceio", BRT},
  133.32              {"America/Managua", CST},
  133.33              {"America/Manaus", AMT},
  133.34 @@ -425,7 +426,7 @@
  133.35              {"America/Rankin_Inlet", CST},
  133.36              {"America/Recife", BRT},
  133.37              {"America/Regina", CST},
  133.38 -            {"America/Resolute", RST},
  133.39 +            {"America/Resolute", CST},
  133.40              {"America/Rio_Branco", AMT},
  133.41              {"America/Rosario", AGT},
  133.42              {"America/Santa_Isabel", PST},
  133.43 @@ -673,7 +674,8 @@
  133.44              {"Europe/Isle_of_Man", GMTBST},
  133.45              {"Europe/Istanbul", EET},
  133.46              {"Europe/Jersey", GMTBST},
  133.47 -            {"Europe/Kaliningrad", EET},
  133.48 +            {"Europe/Kaliningrad", new String[] {"Kaliningrad Time", "KALT",
  133.49 +                                                 "Kaliningrad Summer Time", "KALST"}},
  133.50              {"Europe/Kiev", EET},
  133.51              {"Europe/Lisbon", WET},
  133.52              {"Europe/Ljubljana", CET},
   134.1 --- a/src/share/classes/sun/util/resources/TimeZoneNames_ko.java	Fri Sep 30 17:20:56 2011 -0700
   134.2 +++ b/src/share/classes/sun/util/resources/TimeZoneNames_ko.java	Tue Oct 04 12:39:42 2011 -0700
   134.3 @@ -159,8 +159,6 @@
   134.4                                        "Pohnpei Summer Time", "PONST"};
   134.5          String PST[] = new String[] {"\ud0dc\ud3c9\uc591 \ud45c\uc900\uc2dc", "PST",
   134.6                                       "\ud0dc\ud3c9\uc591 \uc77c\uad11\uc808\uc57d\uc2dc\uac04", "PDT"};
   134.7 -        String RST[] = new String[] {"\ub3d9\ubd80 \ud45c\uc900\uc2dc", "EST",
   134.8 -                                     "\uc911\ubd80 \uc77c\uad11\uc808\uc57d\uc2dc\uac04", "CDT"};
   134.9          String SAST[] = new String[] {"\ub0a8\uc544\ud504\ub9ac\uce74 \ud45c\uc900\uc2dc", "SAST",
  134.10                                        "\ub0a8\uc544\ud504\ub9ac\uce74 \uc77c\uad11\uc808\uc57d\uc2dc\uac04", "SAST"};
  134.11          String SBT[] = new String[] {"\uc194\ub85c\ubaac \uad70\ub3c4 \uc2dc\uac04", "SBT",
  134.12 @@ -262,6 +260,7 @@
  134.13              {"Africa/Gaborone", CAT},
  134.14              {"Africa/Harare", CAT},
  134.15              {"Africa/Johannesburg", SAST},
  134.16 +            {"Africa/Juba", EAT},
  134.17              {"Africa/Kampala", EAT},
  134.18              {"Africa/Khartoum", EAT},
  134.19              {"Africa/Kigali", CAT},
  134.20 @@ -378,11 +377,13 @@
  134.21              {"America/Kentucky/Louisville", EST},
  134.22              {"America/Kentucky/Monticello", EST},
  134.23              {"America/Knox_IN", CST},
  134.24 +            {"America/Kralendijk", AST},
  134.25              {"America/La_Paz", new String[] {"\ubcfc\ub9ac\ube44\uc544 \uc2dc\uac04", "BOT",
  134.26                                              "\ubcfc\ub9ac\ube44\uc544 \uc77c\uad11\uc808\uc57d\uc2dc\uac04", "BOST"}},
  134.27              {"America/Lima", new String[] {"\ud398\ub8e8 \uc2dc\uac04", "PET",
  134.28                                              "\ud398\ub8e8 \uc77c\uad11\uc808\uc57d\uc2dc\uac04", "PEST"}},
  134.29              {"America/Louisville", EST},
  134.30 +            {"America/Lower_Princes", AST},
  134.31              {"America/Maceio", BRT},
  134.32              {"America/Managua", CST},
  134.33              {"America/Manaus", AMT},
  134.34 @@ -425,7 +426,7 @@
  134.35              {"America/Rankin_Inlet", CST},
  134.36              {"America/Recife", BRT},
  134.37              {"America/Regina", CST},
  134.38 -            {"America/Resolute", RST},
  134.39 +            {"America/Resolute", CST},
  134.40              {"America/Rio_Branco", AMT},
  134.41              {"America/Rosario", AGT},
  134.42              {"America/Santa_Isabel", PST},
  134.43 @@ -673,7 +674,8 @@
  134.44              {"Europe/Isle_of_Man", GMTBST},
  134.45              {"Europe/Istanbul", EET},
  134.46              {"Europe/Jersey", GMTBST},
  134.47 -            {"Europe/Kaliningrad", EET},
  134.48 +            {"Europe/Kaliningrad", new String[] {"Kaliningrad Time", "KALT",
  134.49 +                                                 "Kaliningrad Summer Time", "KALST"}},
  134.50              {"Europe/Kiev", EET},
  134.51              {"Europe/Lisbon", WET},
  134.52              {"Europe/Ljubljana", CET},
   135.1 --- a/src/share/classes/sun/util/resources/TimeZoneNames_pt_BR.java	Fri Sep 30 17:20:56 2011 -0700
   135.2 +++ b/src/share/classes/sun/util/resources/TimeZoneNames_pt_BR.java	Tue Oct 04 12:39:42 2011 -0700
   135.3 @@ -157,8 +157,6 @@
   135.4                                        "Fuso hor\u00e1rio de ver\u00e3o de Pohnpei", "PONST"};
   135.5          String PST[] = new String[] {"Fuso hor\u00e1rio padr\u00e3o do Pac\u00edfico", "PST",
   135.6                                       "Hor\u00e1rio de luz natural do Pac\u00edfico", "PDT"};
   135.7 -        String RST[] = new String[] {"Fuso hor\u00e1rio padr\u00e3o oriental", "EST",
   135.8 -                                     "Hor\u00e1rio de luz natural central", "CDT"};
   135.9          String SAST[] = new String[] {"Fuso hor\u00e1rio padr\u00e3o da \u00c1frica do Sul", "SAST",
  135.10                                        "Fuso hor\u00e1rio de ver\u00e3o da \u00c1frica do Sul", "SAST"};
  135.11          String SBT[] = new String[] {"Fuso hor\u00e1rio das Ilhas Salom\u00e3o", "SBT",
  135.12 @@ -262,6 +260,7 @@
  135.13              {"Africa/Gaborone", CAT},
  135.14              {"Africa/Harare", CAT},
  135.15              {"Africa/Johannesburg", SAST},
  135.16 +            {"Africa/Juba", EAT},
  135.17              {"Africa/Kampala", EAT},
  135.18              {"Africa/Khartoum", EAT},
  135.19              {"Africa/Kigali", CAT},
  135.20 @@ -378,11 +377,13 @@
  135.21              {"America/Kentucky/Louisville", EST},
  135.22              {"America/Kentucky/Monticello", EST},
  135.23              {"America/Knox_IN", CST},
  135.24 +            {"America/Kralendijk", AST},
  135.25              {"America/La_Paz", new String[] {"Fuso hor\u00e1rio da Bol\u00edvia", "BOT",
  135.26                                               "Fuso hor\u00e1rio de ver\u00e3o da Bol\u00edvia", "BOST"}},
  135.27              {"America/Lima", new String[] {"Fuso hor\u00e1rio do Peru", "PET",
  135.28                                             "Fuso hor\u00e1rio de ver\u00e3o do Peru", "PEST"}},
  135.29              {"America/Louisville", EST},
  135.30 +            {"America/Lower_Princes", AST},
  135.31              {"America/Maceio", BRT},
  135.32              {"America/Managua", CST},
  135.33              {"America/Manaus", AMT},
  135.34 @@ -425,7 +426,7 @@
  135.35              {"America/Rankin_Inlet", CST},
  135.36              {"America/Recife", BRT},
  135.37              {"America/Regina", CST},
  135.38 -            {"America/Resolute", RST},
  135.39 +            {"America/Resolute", CST},
  135.40              {"America/Rio_Branco", AMT},
  135.41              {"America/Rosario", AGT},
  135.42              {"America/Santa_Isabel", PST},
  135.43 @@ -673,7 +674,8 @@
  135.44              {"Europe/Isle_of_Man", GMTBST},
  135.45              {"Europe/Istanbul", EET},
  135.46              {"Europe/Jersey", GMTBST},
  135.47 -            {"Europe/Kaliningrad", EET},
  135.48 +            {"Europe/Kaliningrad", new String[] {"Kaliningrad Time", "KALT",
  135.49 +                                                 "Kaliningrad Summer Time", "KALST"}},
  135.50              {"Europe/Kiev", EET},
  135.51              {"Europe/Lisbon", WET},
  135.52              {"Europe/Ljubljana", CET},
   136.1 --- a/src/share/classes/sun/util/resources/TimeZoneNames_sv.java	Fri Sep 30 17:20:56 2011 -0700
   136.2 +++ b/src/share/classes/sun/util/resources/TimeZoneNames_sv.java	Tue Oct 04 12:39:42 2011 -0700
   136.3 @@ -159,8 +159,6 @@
   136.4                                        "Pohnpei Summer Time", "PONST"};
   136.5          String PST[] = new String[] {"Stilla havet, normaltid", "PST",
   136.6                                       "Stilla havet, sommartid", "PDT"};
   136.7 -        String RST[] = new String[] {"Eastern, normaltid", "EST",
   136.8 -                                     "Central sommartid", "CDT"};
   136.9          String SAST[] = new String[] {"Sydafrika, normaltid", "SAST",
  136.10                                        "Sydafrika, sommartid", "SAST"};
  136.11          String SBT[] = new String[] {"Salomon\u00f6arna, normaltid", "SBT",
  136.12 @@ -262,6 +260,7 @@
  136.13              {"Africa/Gaborone", CAT},
  136.14              {"Africa/Harare", CAT},
  136.15              {"Africa/Johannesburg", SAST},
  136.16 +            {"Africa/Juba", EAT},
  136.17              {"Africa/Kampala", EAT},
  136.18              {"Africa/Khartoum", EAT},
  136.19              {"Africa/Kigali", CAT},
  136.20 @@ -378,11 +377,13 @@
  136.21              {"America/Kentucky/Louisville", EST},
  136.22              {"America/Kentucky/Monticello", EST},
  136.23              {"America/Knox_IN", CST},
  136.24 +            {"America/Kralendijk", AST},
  136.25              {"America/La_Paz", new String[] {"Bolivia, normaltid", "BOT",
  136.26                                               "Bolivia, sommartid", "BOST"}},
  136.27              {"America/Lima", new String[] {"Peru, normaltid", "PET",
  136.28                                             "Peru, sommartid", "PEST"}},
  136.29              {"America/Louisville", EST},
  136.30 +            {"America/Lower_Princes", AST},
  136.31              {"America/Maceio", BRT},
  136.32              {"America/Managua", CST},
  136.33              {"America/Manaus", AMT},
  136.34 @@ -425,7 +426,7 @@
  136.35              {"America/Rankin_Inlet", CST},
  136.36              {"America/Recife", BRT},
  136.37              {"America/Regina", CST},
  136.38 -            {"America/Resolute", RST},
  136.39 +            {"America/Resolute", CST},
  136.40              {"America/Rio_Branco", AMT},
  136.41              {"America/Rosario", AGT},
  136.42              {"America/Santa_Isabel", PST},
  136.43 @@ -673,7 +674,8 @@
  136.44              {"Europe/Isle_of_Man", GMTBST},
  136.45              {"Europe/Istanbul", EET},
  136.46              {"Europe/Jersey", GMTBST},
  136.47 -            {"Europe/Kaliningrad", EET},
  136.48 +            {"Europe/Kaliningrad", new String[] {"Kaliningrad Time", "KALT",
  136.49 +                                                 "Kaliningrad Summer Time", "KALST"}},
  136.50              {"Europe/Kiev", EET},
  136.51              {"Europe/Lisbon", WET},
  136.52              {"Europe/Ljubljana", CET},
   137.1 --- a/src/share/classes/sun/util/resources/TimeZoneNames_zh_CN.java	Fri Sep 30 17:20:56 2011 -0700
   137.2 +++ b/src/share/classes/sun/util/resources/TimeZoneNames_zh_CN.java	Tue Oct 04 12:39:42 2011 -0700
   137.3 @@ -159,8 +159,6 @@
   137.4                                        "Pohnpei Summer Time", "PONST"};
   137.5          String PST[] = new String[] {"\u592a\u5e73\u6d0b\u6807\u51c6\u65f6\u95f4", "PST",
   137.6                                       "\u592a\u5e73\u6d0b\u590f\u4ee4\u65f6", "PDT"};
   137.7 -        String RST[] = new String[] {"\u4e1c\u90e8\u6807\u51c6\u65f6\u95f4", "EST",
   137.8 -                                     "\u4e2d\u592e\u590f\u4ee4\u65f6", "CDT"};
   137.9          String SAST[] = new String[] {"\u5357\u975e\u6807\u51c6\u65f6\u95f4", "SAST",
  137.10                                        "\u5357\u975e\u590f\u4ee4\u65f6", "SAST"};
  137.11          String SBT[] = new String[] {"\u6240\u7f57\u95e8\u7fa4\u5c9b\u65f6\u95f4", "SBT",
  137.12 @@ -262,6 +260,7 @@
  137.13              {"Africa/Gaborone", CAT},
  137.14              {"Africa/Harare", CAT},
  137.15              {"Africa/Johannesburg", SAST},
  137.16 +            {"Africa/Juba", EAT},
  137.17              {"Africa/Kampala", EAT},
  137.18              {"Africa/Khartoum", EAT},
  137.19              {"Africa/Kigali", CAT},
  137.20 @@ -378,11 +377,13 @@
  137.21              {"America/Kentucky/Louisville", EST},
  137.22              {"America/Kentucky/Monticello", EST},
  137.23              {"America/Knox_IN", CST},
  137.24 +            {"America/Kralendijk", AST},
  137.25              {"America/La_Paz", new String[] {"\u73bb\u5229\u7ef4\u4e9a\u65f6\u95f4", "BOT",
  137.26                                               "\u73bb\u5229\u7ef4\u4e9a\u590f\u4ee4\u65f6", "BOST"}},
  137.27              {"America/Lima", new String[] {"\u79d8\u9c81\u65f6\u95f4", "PET",
  137.28                                             "\u79d8\u9c81\u590f\u4ee4\u65f6", "PEST"}},
  137.29              {"America/Louisville", EST},
  137.30 +            {"America/Lower_Princes", AST},
  137.31              {"America/Maceio", BRT},
  137.32              {"America/Managua", CST},
  137.33              {"America/Manaus", AMT},
  137.34 @@ -425,7 +426,7 @@
  137.35              {"America/Rankin_Inlet", CST},
  137.36              {"America/Recife", BRT},
  137.37              {"America/Regina", CST},
  137.38 -            {"America/Resolute", RST},
  137.39 +            {"America/Resolute", CST},
  137.40              {"America/Rio_Branco", AMT},
  137.41              {"America/Rosario", AGT},
  137.42              {"America/Santa_Isabel", PST},
  137.43 @@ -673,7 +674,8 @@
  137.44              {"Europe/Isle_of_Man", GMTBST},
  137.45              {"Europe/Istanbul", EET},
  137.46              {"Europe/Jersey", GMTBST},
  137.47 -            {"Europe/Kaliningrad", EET},
  137.48 +            {"Europe/Kaliningrad", new String[] {"Kaliningrad Time", "KALT",
  137.49 +                                                 "Kaliningrad Summer Time", "KALST"}},
  137.50              {"Europe/Kiev", EET},
  137.51              {"Europe/Lisbon", WET},
  137.52              {"Europe/Ljubljana", CET},
   138.1 --- a/src/share/classes/sun/util/resources/TimeZoneNames_zh_TW.java	Fri Sep 30 17:20:56 2011 -0700
   138.2 +++ b/src/share/classes/sun/util/resources/TimeZoneNames_zh_TW.java	Tue Oct 04 12:39:42 2011 -0700
   138.3 @@ -159,8 +159,6 @@
   138.4                                        "Pohnpei Summer Time", "PONST"};
   138.5          String PST[] = new String[] {"\u592a\u5e73\u6d0b\u6a19\u6e96\u6642\u9593", "PST",
   138.6                                       "\u592a\u5e73\u6d0b\u65e5\u5149\u7bc0\u7d04\u6642\u9593", "PDT"};
   138.7 -        String RST[] = new String[] {"\u6771\u65b9\u6a19\u6e96\u6642\u9593", "EST",
   138.8 -                                     "\u4e2d\u592e\u65e5\u5149\u7bc0\u7d04\u6642\u9593", "CDT"};
   138.9          String SAST[] = new String[] {"\u5357\u975e\u6a19\u6e96\u6642\u9593", "SAST",
  138.10                                        "\u5357\u975e\u590f\u4ee4\u6642\u9593", "SAST"};
  138.11          String SBT[] = new String[] {"\u6240\u7f85\u9580\u7fa4\u5cf6\u6642\u9593", "SBT",
  138.12 @@ -262,6 +260,7 @@
  138.13              {"Africa/Gaborone", CAT},
  138.14              {"Africa/Harare", CAT},
  138.15              {"Africa/Johannesburg", SAST},
  138.16 +            {"Africa/Juba", EAT},
  138.17              {"Africa/Kampala", EAT},
  138.18              {"Africa/Khartoum", EAT},
  138.19              {"Africa/Kigali", CAT},
  138.20 @@ -378,11 +377,13 @@
  138.21              {"America/Kentucky/Louisville", EST},
  138.22              {"America/Kentucky/Monticello", EST},
  138.23              {"America/Knox_IN", CST},
  138.24 +            {"America/Kralendijk", AST},
  138.25              {"America/La_Paz", new String[] {"\u73bb\u5229\u7dad\u4e9e\u6642\u9593", "BOT",
  138.26                                               "\u73bb\u5229\u7dad\u4e9e\u590f\u4ee4\u6642\u9593", "BOST"}},
  138.27              {"America/Lima", new String[] {"\u7955\u9b6f\u6642\u9593", "PET",
  138.28                                             "\u7955\u9b6f\u590f\u4ee4\u6642\u9593", "PEST"}},
  138.29              {"America/Louisville", EST},
  138.30 +            {"America/Lower_Princes", AST},
  138.31              {"America/Maceio", BRT},
  138.32              {"America/Managua", CST},
  138.33              {"America/Manaus", AMT},
  138.34 @@ -425,7 +426,7 @@
  138.35              {"America/Rankin_Inlet", CST},
  138.36              {"America/Recife", BRT},
  138.37              {"America/Regina", CST},
  138.38 -            {"America/Resolute", RST},
  138.39 +            {"America/Resolute", CST},
  138.40              {"America/Rio_Branco", AMT},
  138.41              {"America/Rosario", AGT},
  138.42              {"America/Santa_Isabel", PST},
  138.43 @@ -674,7 +675,8 @@
  138.44              {"Europe/Isle_of_Man", GMTBST},
  138.45              {"Europe/Istanbul", EET},
  138.46              {"Europe/Jersey", GMTBST},
  138.47 -            {"Europe/Kaliningrad", EET},
  138.48 +            {"Europe/Kaliningrad", new String[] {"Kaliningrad Time", "KALT",
  138.49 +                                                 "Kaliningrad Summer Time", "KALST"}},
  138.50              {"Europe/Kiev", EET},
  138.51              {"Europe/Lisbon", WET},
  138.52              {"Europe/Ljubljana", CET},
   139.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   139.2 +++ b/src/share/classes/sun/util/xml/XMLUtils.java	Tue Oct 04 12:39:42 2011 -0700
   139.3 @@ -0,0 +1,207 @@
   139.4 +/*
   139.5 + * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
   139.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   139.7 + *
   139.8 + * This code is free software; you can redistribute it and/or modify it
   139.9 + * under the terms of the GNU General Public License version 2 only, as
  139.10 + * published by the Free Software Foundation.  Oracle designates this
  139.11 + * particular file as subject to the "Classpath" exception as provided
  139.12 + * by Oracle in the LICENSE file that accompanied this code.
  139.13 + *
  139.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
  139.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  139.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  139.17 + * version 2 for more details (a copy is included in the LICENSE file that
  139.18 + * accompanied this code).
  139.19 + *
  139.20 + * You should have received a copy of the GNU General Public License version
  139.21 + * 2 along with this work; if not, write to the Free Software Foundation,
  139.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  139.23 + *
  139.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  139.25 + * or visit www.oracle.com if you need additional information or have any
  139.26 + * questions.
  139.27 + */
  139.28 +
  139.29 +package sun.util.xml;
  139.30 +
  139.31 +import java.io.*;
  139.32 +import java.util.*;
  139.33 +import org.xml.sax.*;
  139.34 +import org.xml.sax.helpers.*;
  139.35 +import org.w3c.dom.*;
  139.36 +import javax.xml.parsers.*;
  139.37 +import javax.xml.transform.*;
  139.38 +import javax.xml.transform.dom.*;
  139.39 +import javax.xml.transform.stream.*;
  139.40 +
  139.41 +/**
  139.42 + * A class used to aid in Properties load and save in XML. Keeping this
  139.43 + * code outside of Properties helps reduce the number of classes loaded
  139.44 + * when Properties is loaded.
  139.45 + *
  139.46 + * @author  Michael McCloskey
  139.47 + * @since   1.3
  139.48 + */
  139.49 +public class XMLUtils {
  139.50 +
  139.51 +    // XML loading and saving methods for Properties
  139.52 +
  139.53 +    // The required DTD URI for exported properties
  139.54 +    private static final String PROPS_DTD_URI =
  139.55 +    "http://java.sun.com/dtd/properties.dtd";
  139.56 +
  139.57 +    private static final String PROPS_DTD =
  139.58 +    "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
  139.59 +    "<!-- DTD for properties -->"                +
  139.60 +    "<!ELEMENT properties ( comment?, entry* ) >"+
  139.61 +    "<!ATTLIST properties"                       +
  139.62 +        " version CDATA #FIXED \"1.0\">"         +
  139.63 +    "<!ELEMENT comment (#PCDATA) >"              +
  139.64 +    "<!ELEMENT entry (#PCDATA) >"                +
  139.65 +    "<!ATTLIST entry "                           +
  139.66 +        " key CDATA #REQUIRED>";
  139.67 +
  139.68 +    /**
  139.69 +     * Version number for the format of exported properties files.
  139.70 +     */
  139.71 +    private static final String EXTERNAL_XML_VERSION = "1.0";
  139.72 +
  139.73 +    public static void load(Properties props, InputStream in)
  139.74 +        throws IOException, InvalidPropertiesFormatException
  139.75 +    {
  139.76 +        Document doc = null;
  139.77 +        try {
  139.78 +            doc = getLoadingDoc(in);
  139.79 +        } catch (SAXException saxe) {
  139.80 +            throw new InvalidPropertiesFormatException(saxe);
  139.81 +        }
  139.82 +        Element propertiesElement = (Element)doc.getChildNodes().item(1);
  139.83 +        String xmlVersion = propertiesElement.getAttribute("version");
  139.84 +        if (xmlVersion.compareTo(EXTERNAL_XML_VERSION) > 0)
  139.85 +            throw new InvalidPropertiesFormatException(
  139.86 +                "Exported Properties file format version " + xmlVersion +
  139.87 +                " is not supported. This java installation can read" +
  139.88 +                " versions " + EXTERNAL_XML_VERSION + " or older. You" +
  139.89 +                " may need to install a newer version of JDK.");
  139.90 +        importProperties(props, propertiesElement);
  139.91 +    }
  139.92 +
  139.93 +    static Document getLoadingDoc(InputStream in)
  139.94 +        throws SAXException, IOException
  139.95 +    {
  139.96 +        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
  139.97 +        dbf.setIgnoringElementContentWhitespace(true);
  139.98 +        dbf.setValidating(true);
  139.99 +        dbf.setCoalescing(true);
 139.100 +        dbf.setIgnoringComments(true);
 139.101 +        try {
 139.102 +            DocumentBuilder db = dbf.newDocumentBuilder();
 139.103 +            db.setEntityResolver(new Resolver());
 139.104 +            db.setErrorHandler(new EH());
 139.105 +            InputSource is = new InputSource(in);
 139.106 +            return db.parse(is);
 139.107 +        } catch (ParserConfigurationException x) {
 139.108 +            throw new Error(x);
 139.109 +        }
 139.110 +    }
 139.111 +
 139.112 +    static void importProperties(Properties props, Element propertiesElement) {
 139.113 +        NodeList entries = propertiesElement.getChildNodes();
 139.114 +        int numEntries = entries.getLength();
 139.115 +        int start = numEntries > 0 &&
 139.116 +            entries.item(0).getNodeName().equals("comment") ? 1 : 0;
 139.117 +        for (int i=start; i<numEntries; i++) {
 139.118 +            Element entry = (Element)entries.item(i);
 139.119 +            if (entry.hasAttribute("key")) {
 139.120 +                Node n = entry.getFirstChild();
 139.121 +                String val = (n == null) ? "" : n.getNodeValue();
 139.122 +                props.setProperty(entry.getAttribute("key"), val);
 139.123 +            }
 139.124 +        }
 139.125 +    }
 139.126 +
 139.127 +    public static void save(Properties props, OutputStream os, String comment,
 139.128 +                     String encoding)
 139.129 +        throws IOException
 139.130 +    {
 139.131 +        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
 139.132 +        DocumentBuilder db = null;
 139.133 +        try {
 139.134 +            db = dbf.newDocumentBuilder();
 139.135 +        } catch (ParserConfigurationException pce) {
 139.136 +            assert(false);
 139.137 +        }
 139.138 +        Document doc = db.newDocument();
 139.139 +        Element properties =  (Element)
 139.140 +            doc.appendChild(doc.createElement("properties"));
 139.141 +
 139.142 +        if (comment != null) {
 139.143 +            Element comments = (Element)properties.appendChild(
 139.144 +                doc.createElement("comment"));
 139.145 +            comments.appendChild(doc.createTextNode(comment));
 139.146 +        }
 139.147 +
 139.148 +        synchronized (props) {
 139.149 +            for (String key : props.stringPropertyNames()) {
 139.150 +                Element entry = (Element)properties.appendChild(
 139.151 +                    doc.createElement("entry"));
 139.152 +                entry.setAttribute("key", key);
 139.153 +                entry.appendChild(doc.createTextNode(props.getProperty(key)));
 139.154 +            }
 139.155 +        }
 139.156 +        emitDocument(doc, os, encoding);
 139.157 +    }
 139.158 +
 139.159 +    static void emitDocument(Document doc, OutputStream os, String encoding)
 139.160 +        throws IOException
 139.161 +    {
 139.162 +        TransformerFactory tf = TransformerFactory.newInstance();
 139.163 +        Transformer t = null;
 139.164 +        try {
 139.165 +            t = tf.newTransformer();
 139.166 +            t.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, PROPS_DTD_URI);
 139.167 +            t.setOutputProperty(OutputKeys.INDENT, "yes");
 139.168 +            t.setOutputProperty(OutputKeys.METHOD, "xml");
 139.169 +            t.setOutputProperty(OutputKeys.ENCODING, encoding);
 139.170 +        } catch (TransformerConfigurationException tce) {
 139.171 +            assert(false);
 139.172 +        }
 139.173 +        DOMSource doms = new DOMSource(doc);
 139.174 +        StreamResult sr = new StreamResult(os);
 139.175 +        try {
 139.176 +            t.transform(doms, sr);
 139.177 +        } catch (TransformerException te) {
 139.178 +            IOException ioe = new IOException();
 139.179 +            ioe.initCause(te);
 139.180 +            throw ioe;
 139.181 +        }
 139.182 +    }
 139.183 +
 139.184 +    private static class Resolver implements EntityResolver {
 139.185 +        public InputSource resolveEntity(String pid, String sid)
 139.186 +            throws SAXException
 139.187 +        {
 139.188 +            if (sid.equals(PROPS_DTD_URI)) {
 139.189 +                InputSource is;
 139.190 +                is = new InputSource(new StringReader(PROPS_DTD));
 139.191 +                is.setSystemId(PROPS_DTD_URI);
 139.192 +                return is;
 139.193 +            }
 139.194 +            throw new SAXException("Invalid system identifier: " + sid);
 139.195 +        }
 139.196 +    }
 139.197 +
 139.198 +    private static class EH implements ErrorHandler {
 139.199 +        public void error(SAXParseException x) throws SAXException {
 139.200 +            throw x;
 139.201 +        }
 139.202 +        public void fatalError(SAXParseException x) throws SAXException {
 139.203 +            throw x;
 139.204 +        }
 139.205 +        public void warning(SAXParseException x) throws SAXException {
 139.206 +            throw x;
 139.207 +        }
 139.208 +    }
 139.209 +
 139.210 +}
   140.1 --- a/src/share/native/sun/awt/libpng/CHANGES	Fri Sep 30 17:20:56 2011 -0700
   140.2 +++ b/src/share/native/sun/awt/libpng/CHANGES	Tue Oct 04 12:39:42 2011 -0700
   140.3 @@ -1,5 +1,5 @@
   140.4 -/* 
   140.5 - * Copyright (c) 2005, 2007, Oracle and/or its affiliates. All rights reserved.
   140.6 +/*
   140.7 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
   140.8   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   140.9   *
  140.10   * This code is free software; you can redistribute it and/or modify it
  140.11 @@ -23,13 +23,15 @@
  140.12   * questions.
  140.13   */
  140.14  
  140.15 +#if 0
  140.16 +libpng_changes(){ /*
  140.17  CHANGES - changes for libpng
  140.18  
  140.19 -version 0.2
  140.20 +Version 0.2
  140.21    added reader into png.h
  140.22    fixed small problems in stub file
  140.23  
  140.24 -version 0.3
  140.25 +Version 0.3
  140.26    added pull reader
  140.27    split up pngwrite.c to several files
  140.28    added pnglib.txt
  140.29 @@ -38,9 +40,9 @@
  140.30    fixed some bugs in writer
  140.31    interfaced with zlib 0.5
  140.32    added K&R support
  140.33 -  added check for 64 KB blocks for 16 bit machines
  140.34 -
  140.35 -version 0.4
  140.36 +  added check for 64 KB blocks for 16-bit machines
  140.37 +
  140.38 +Version 0.4
  140.39    cleaned up code and commented code
  140.40    simplified time handling into png_time
  140.41    created png_color_16 and png_color_8 to handle color needs
  140.42 @@ -51,28 +53,28 @@
  140.43    cleaned up zTXt reader and writer (using zlib's Reset functions)
  140.44    split transformations into pngrtran.c and pngwtran.c
  140.45  
  140.46 -version 0.5
  140.47 +Version 0.5
  140.48    interfaced with zlib 0.8
  140.49    fixed many reading and writing bugs
  140.50    saved using 3 spaces instead of tabs
  140.51  
  140.52 -version 0.6
  140.53 +Version 0.6
  140.54    added png_large_malloc() and png_large_free()
  140.55    added png_size_t
  140.56    cleaned up some compiler warnings
  140.57    added png_start_read_image()
  140.58  
  140.59 -version 0.7
  140.60 +Version 0.7
  140.61    cleaned up lots of bugs
  140.62    finished dithering and other stuff
  140.63    added test program
  140.64    changed name from pnglib to libpng
  140.65  
  140.66 -version 0.71 [June, 1995]
  140.67 +Version 0.71 [June, 1995]
  140.68    changed pngtest.png for zlib 0.93
  140.69    fixed error in libpng.txt and example.c
  140.70  
  140.71 -version 0.8
  140.72 +Version 0.8
  140.73    cleaned up some bugs
  140.74    added png_set_filler()
  140.75    split up pngstub.c into pngmem.c, pngio.c, and pngerror.c
  140.76 @@ -86,191 +88,194 @@
  140.77    changed external functions passing floats to doubles (k&r problems?)
  140.78    put all the configurable stuff in pngconf.h
  140.79    enabled png_set_shift to work with paletted images on read
  140.80 -  added png_read_update_info() - updates info structure with
  140.81 -     transformations
  140.82 -
  140.83 -version 0.81 [August, 1995]
  140.84 +  added png_read_update_info() - updates info structure with transformations
  140.85 +
  140.86 +Version 0.81 [August, 1995]
  140.87    incorporated Tim Wegner's medium model code (thanks, Tim)
  140.88  
  140.89 -version 0.82 [September, 1995]
  140.90 +Version 0.82 [September, 1995]
  140.91    [unspecified changes]
  140.92  
  140.93 -version 0.85 [December, 1995]
  140.94 +Version 0.85 [December, 1995]
  140.95    added more medium model code (almost everything's a far)
  140.96    added i/o, error, and memory callback functions
  140.97 -  fixed some bugs (16 bit, 4 bit interlaced, etc.)
  140.98 +  fixed some bugs (16-bit, 4-bit interlaced, etc.)
  140.99    added first run progressive reader (barely tested)
 140.100  
 140.101 -version 0.86 [January, 1996]
 140.102 +Version 0.86 [January, 1996]
 140.103    fixed bugs
 140.104    improved documentation
 140.105  
 140.106 -version 0.87 [January, 1996]
 140.107 +Version 0.87 [January, 1996]
 140.108    fixed medium model bugs
 140.109    fixed other bugs introduced in 0.85 and 0.86
 140.110    added some minor documentation
 140.111  
 140.112 -version 0.88 [January, 1996]
 140.113 +Version 0.88 [January, 1996]
 140.114    fixed progressive bugs
 140.115    replaced tabs with spaces
 140.116    cleaned up documentation
 140.117    added callbacks for read/write and warning/error functions
 140.118  
 140.119 -version 0.89 [July, 1996]
 140.120 -  added new initialization API to make libpng work better with shared libs
 140.121 -     we now have png_create_read_struct(), png_create_write_struct(),
 140.122 -     png_create_info_struct(), png_destroy_read_struct(), and
 140.123 -     png_destroy_write_struct() instead of the separate calls to
 140.124 -     malloc and png_read_init(), png_info_init(), and png_write_init()
 140.125 -  changed warning/error callback functions to fix bug - this means you
 140.126 -     should use the new initialization API if you were using the old
 140.127 -     png_set_message_fn() calls, and that the old API no longer exists
 140.128 -     so that people are aware that they need to change their code
 140.129 -  changed filter selection API to allow selection of multiple filters
 140.130 -     since it didn't work in previous versions of libpng anyways
 140.131 -  optimized filter selection code
 140.132 -  fixed png_set_background() to allow using an arbitrary RGB color for
 140.133 -     paletted images
 140.134 -  fixed gamma and background correction for paletted images, so
 140.135 -     png_correct_palette is not needed unless you are correcting an
 140.136 -     external palette (you will need to #define PNG_CORRECT_PALETTE_SUPPORTED
 140.137 -     in pngconf.h) - if nobody uses this, it may disappear in the future.
 140.138 -  fixed bug with Borland 64K memory allocation (Alexander Lehmann)
 140.139 -  fixed bug in interlace handling (Smarasderagd, I think)
 140.140 -  added more error checking for writing and image to reduce invalid files
 140.141 -  separated read and write functions so that they won't both be linked
 140.142 -     into a binary when only reading or writing functionality is used
 140.143 -  new pngtest image also has interlacing and zTXt
 140.144 -  updated documentation to reflect new API
 140.145 -
 140.146 -version 0.90 [January, 1997]
 140.147 -  made CRC errors/warnings on critical and ancillary chunks configurable
 140.148 +Version 0.89 [July, 1996]
 140.149 +  Added new initialization API to make libpng work better with shared libs
 140.150 +    we now have png_create_read_struct(), png_create_write_struct(),
 140.151 +    png_create_info_struct(), png_destroy_read_struct(), and
 140.152 +    png_destroy_write_struct() instead of the separate calls to
 140.153 +    malloc and png_read_init(), png_info_init(), and png_write_init()
 140.154 +  Changed warning/error callback functions to fix bug - this means you
 140.155 +    should use the new initialization API if you were using the old
 140.156 +    png_set_message_fn() calls, and that the old API no longer exists
 140.157 +    so that people are aware that they need to change their code
 140.158 +  Changed filter selection API to allow selection of multiple filters
 140.159 +    since it didn't work in previous versions of libpng anyways
 140.160 +  Optimized filter selection code
 140.161 +  Fixed png_set_background() to allow using an arbitrary RGB color for
 140.162 +    paletted images
 140.163 +  Fixed gamma and background correction for paletted images, so
 140.164 +    png_correct_palette is not needed unless you are correcting an
 140.165 +    external palette (you will need to #define PNG_CORRECT_PALETTE_SUPPORTED
 140.166 +    in pngconf.h) - if nobody uses this, it may disappear in the future.
 140.167 +  Fixed bug with Borland 64K memory allocation (Alexander Lehmann)
 140.168 +  Fixed bug in interlace handling (Smarasderagd, I think)
 140.169 +  Added more error checking for writing and image to reduce invalid files
 140.170 +  Separated read and write functions so that they won't both be linked
 140.171 +    into a binary when only reading or writing functionality is used
 140.172 +  New pngtest image also has interlacing and zTXt
 140.173 +  Updated documentation to reflect new API
 140.174 +
 140.175 +Version 0.90 [January, 1997]
 140.176 +  Made CRC errors/warnings on critical and ancillary chunks configurable
 140.177    libpng will use the zlib CRC routines by (compile-time) default
 140.178 -  changed DOS small/medium model memory support - needs zlib 1.04 (Tim Wegner)
 140.179 -  added external C++ wrapper statements to png.h (Gilles Dauphin)
 140.180 -  allow PNG file to be read when some or all of file signature has already
 140.181 -     been read from the beginning of the stream.  ****This affects the size
 140.182 -     of info_struct and invalidates all programs that use a shared libpng****
 140.183 -  fixed png_filler() declarations
 140.184 -  fixed? background color conversions
 140.185 -  fixed order of error function pointers to match documentation
 140.186 -  current chunk name is now available in png_struct to reduce the number
 140.187 -     of nearly identical error messages (will simplify multi-lingual
 140.188 -     support when available)
 140.189 -  try to get ready for unknown-chunk callback functions:
 140.190 -     - previously read critical chunks are flagged, so the chunk handling
 140.191 -       routines can determine if the chunk is in the right place
 140.192 -     - all chunk handling routines have the same prototypes, so we will
 140.193 -       be able to handle all chunks via a callback mechanism
 140.194 -  try to fix Linux "setjmp" buffer size problems
 140.195 -  removed png_large_malloc, png_large_free, and png_realloc functions.
 140.196 -
 140.197 -version 0.95 [March, 1997]
 140.198 -  fixed bug in pngwutil.c allocating "up_row" twice and "avg_row" never
 140.199 -  fixed bug in PNG file signature compares when start != 0
 140.200 -  changed parameter type of png_set_filler(...filler...) from png_byte
 140.201 -     to png_uint_32
 140.202 -  added test for MACOS to ensure that both math.h and fp.h are not #included
 140.203 -  added macros for libpng to be compiled as a Windows DLL (Andreas Kupries)
 140.204 -  added "packswap" transformation, which changes the endianness of
 140.205 -     packed-pixel bytes (Kevin Bracey)
 140.206 -  added "strip_alpha" transformation, which removes the alpha channel of
 140.207 -     input images without using it (not necessarily a good idea)
 140.208 -  added "swap_alpha" transformation, which puts the alpha channel in front
 140.209 -     of the color bytes instead of after
 140.210 -  removed all implicit variable tests which assume NULL == 0 (I think)
 140.211 -  changed several variables to "png_size_t" to show 16/32-bit limitations
 140.212 -  added new pCAL chunk read/write support
 140.213 -  added experimental filter selection weighting (Greg Roelofs)
 140.214 -  removed old png_set_rgbx() and png_set_xrgb() functions that have been
 140.215 +  Changed DOS small/medium model memory support - needs zlib 1.04 (Tim Wegner)
 140.216 +  Added external C++ wrapper statements to png.h (Gilles Dauphin)
 140.217 +  Allow PNG file to be read when some or all of file signature has already
 140.218 +    been read from the beginning of the stream.  ****This affects the size
 140.219 +    of info_struct and invalidates all programs that use a shared libpng****
 140.220 +  Fixed png_filler() declarations
 140.221 +  Fixed? background color conversions
 140.222 +  Fixed order of error function pointers to match documentation
 140.223 +  Current chunk name is now available in png_struct to reduce the number
 140.224 +    of nearly identical error messages (will simplify multi-lingual
 140.225 +    support when available)
 140.226 +  Try to get ready for unknown-chunk callback functions:
 140.227 +    - previously read critical chunks are flagged, so the chunk handling
 140.228 +      routines can determine if the chunk is in the right place
 140.229 +    - all chunk handling routines have the same prototypes, so we will
 140.230 +      be able to handle all chunks via a callback mechanism
 140.231 +  Try to fix Linux "setjmp" buffer size problems
 140.232 +  Removed png_large_malloc, png_large_free, and png_realloc functions.
 140.233 +
 140.234 +Version 0.95 [March, 1997]
 140.235 +  Fixed bug in pngwutil.c allocating "up_row" twice and "avg_row" never
 140.236 +  Fixed bug in PNG file signature compares when start != 0
 140.237 +  Changed parameter type of png_set_filler(...filler...) from png_byte
 140.238 +    to png_uint_32
 140.239 +  Added test for MACOS to ensure that both math.h and fp.h are not #included
 140.240 +  Added macros for libpng to be compiled as a Windows DLL (Andreas Kupries)
 140.241 +  Added "packswap" transformation, which changes the endianness of
 140.242 +    packed-pixel bytes (Kevin Bracey)
 140.243 +  Added "strip_alpha" transformation, which removes the alpha channel of
 140.244 +    input images without using it (not necessarily a good idea)
 140.245 +  Added "swap_alpha" transformation, which puts the alpha channel in front
 140.246 +    of the color bytes instead of after
 140.247 +  Removed all implicit variable tests which assume NULL == 0 (I think)
 140.248 +  Changed several variables to "png_size_t" to show 16/32-bit limitations
 140.249 +  Added new pCAL chunk read/write support
 140.250 +  Added experimental filter selection weighting (Greg Roelofs)
 140.251 +  Removed old png_set_rgbx() and png_set_xrgb() functions that have been
 140.252       obsolete for about 2 years now (use png_set_filler() instead)
 140.253 -  added macros to read 16- and 32-bit ints directly from buffer, to be
 140.254 -     used only on those systems that support it (namely PowerPC and 680x0)
 140.255 -     With some testing, this may become the default for MACOS/PPC systems.
 140.256 -  only calculate CRC on data if we are going to use it
 140.257 -  added macros for zTXt compression type PNG_zTXt_COMPRESSION_???
 140.258 -  added macros for simple libpng debugging output selectable at compile time
 140.259 -  removed PNG_READ_END_MODE in progressive reader (Smarasderagd)
 140.260 -  more description of info_struct in libpng.txt and png.h
 140.261 -  more instructions in example.c
 140.262 -  more chunk types tested in pngtest.c
 140.263 -  renamed pngrcb.c to pngset.c, and all png_read_<chunk> functions to be
 140.264 -     png_set_<chunk>.  We now have corresponding png_get_<chunk>
 140.265 -     functions in pngget.c to get information in info_ptr.  This isolates
 140.266 -     the application from the internal organization of png_info_struct
 140.267 -     (good for shared library implementations).
 140.268 -
 140.269 -version 0.96 [May, 1997]
 140.270 -  fixed serious bug with < 8bpp images introduced in 0.95
 140.271 -  fixed 256-color transparency bug (Greg Roelofs)
 140.272 -  fixed up documentation (Greg Roelofs, Laszlo Nyul)
 140.273 -  fixed "error" in pngconf.h for Linux setjmp() behaviour
 140.274 -  fixed DOS medium model support (Tim Wegner)
 140.275 -  fixed png_check_keyword() for case with error in static string text
 140.276 -  added read of CRC after IEND chunk for embedded PNGs (Laszlo Nyul)
 140.277 -  added typecasts to quiet compiler errors
 140.278 -  added more debugging info
 140.279 -
 140.280 -version 0.97 [January, 1998]
 140.281 -  removed PNG_USE_OWN_CRC capability
 140.282 -  relocated png_set_crc_action from pngrutil.c to pngrtran.c
 140.283 -  fixed typecasts of "new_key", etc. (Andreas Dilger)
 140.284 -  added RFC 1152 [sic] date support
 140.285 -  fixed bug in gamma handling of 4-bit grayscale
 140.286 -  added 2-bit grayscale gamma handling (Glenn R-P)
 140.287 -  added more typecasts. 65536L becomes (png_uint_32)65536L, etc. (Glenn R-P)
 140.288 -  minor corrections in libpng.txt
 140.289 -  added simple sRGB support (Glenn R-P)
 140.290 -  easier conditional compiling, e.g. define PNG_READ/WRITE_NOT_FULLY_SUPPORTED;
 140.291 -     all configurable options can be selected from command-line instead
 140.292 -     of having to edit pngconf.h (Glenn R-P)
 140.293 -  fixed memory leak in pngwrite.c (free info_ptr->text) (Glenn R-P)
 140.294 -  added more conditions for png_do_background, to avoid changing
 140.295 -     black pixels to background when a background is supplied and
 140.296 -     no pixels are transparent
 140.297 -  repaired PNG_NO_STDIO behaviour
 140.298 -  tested NODIV support and made it default behaviour (Greg Roelofs)
 140.299 -  added "-m" option and PNGTEST_DEBUG_MEMORY to pngtest (John Bowler)
 140.300 -  regularized version numbering scheme and bumped shared-library major
 140.301 +  Added macros to read 16- and 32-bit ints directly from buffer, to be
 140.302 +    used only on those systems that support it (namely PowerPC and 680x0)
 140.303 +    With some testing, this may become the default for MACOS/PPC systems.
 140.304 +  Only calculate CRC on data if we are going to use it
 140.305 +  Added macros for zTXt compression type PNG_zTXt_COMPRESSION_???
 140.306 +  Added macros for simple libpng debugging output selectable at compile time
 140.307 +  Removed PNG_READ_END_MODE in progressive reader (Smarasderagd)
 140.308 +  More description of info_struct in libpng.txt and png.h
 140.309 +  More instructions in example.c
 140.310 +  More chunk types tested in pngtest.c
 140.311 +  Renamed pngrcb.c to pngset.c, and all png_read_<chunk> functions to be
 140.312 +    png_set_<chunk>.  We now have corresponding png_get_<chunk>
 140.313 +    functions in pngget.c to get information in info_ptr.  This isolates
 140.314 +    the application from the internal organization of png_info_struct
 140.315 +    (good for shared library implementations).
 140.316 +
 140.317 +Version 0.96 [May, 1997]
 140.318 +  Fixed serious bug with < 8bpp images introduced in 0.95
 140.319 +  Fixed 256-color transparency bug (Greg Roelofs)
 140.320 +  Fixed up documentation (Greg Roelofs, Laszlo Nyul)
 140.321 +  Fixed "error" in pngconf.h for Linux setjmp() behaviour
 140.322 +  Fixed DOS medium model support (Tim Wegner)
 140.323 +  Fixed png_check_keyword() for case with error in static string text
 140.324 +  Added read of CRC after IEND chunk for embedded PNGs (Laszlo Nyul)
 140.325 +  Added typecasts to quiet compiler errors
 140.326 +  Added more debugging info
 140.327 +
 140.328 +Version 0.97 [January, 1998]
 140.329 +  Removed PNG_USE_OWN_CRC capability
 140.330 +  Relocated png_set_crc_action from pngrutil.c to pngrtran.c
 140.331 +  Fixed typecasts of "new_key", etc. (Andreas Dilger)
 140.332 +  Added RFC 1152 [sic] date support
 140.333 +  Fixed bug in gamma handling of 4-bit grayscale
 140.334 +  Added 2-bit grayscale gamma handling (Glenn R-P)
 140.335 +  Added more typecasts. 65536L becomes (png_uint_32)65536L, etc. (Glenn R-P)
 140.336 +  Minor corrections in libpng.txt
 140.337 +  Added simple sRGB support (Glenn R-P)
 140.338 +  Easier conditional compiling, e.g. define PNG_READ/WRITE_NOT_FULLY_SUPPORTED;
 140.339 +    all configurable options can be selected from command-line instead
 140.340 +    of having to edit pngconf.h (Glenn R-P)
 140.341 +  Fixed memory leak in pngwrite.c (free info_ptr->text) (Glenn R-P)
 140.342 +  Added more conditions for png_do_background, to avoid changing
 140.343 +    black pixels to background when a background is supplied and
 140.344 +    no pixels are transparent
 140.345 +  Repaired PNG_NO_STDIO behaviour
 140.346 +  Tested NODIV support and made it default behaviour (Greg Roelofs)
 140.347 +  Added "-m" option and PNGTEST_DEBUG_MEMORY to pngtest (John Bowler)
 140.348 +  Regularized version numbering scheme and bumped shared-library major
 140.349       version number to 2 to avoid problems with libpng 0.89 apps (Greg Roelofs)
 140.350  
 140.351 -version 0.98 [January, 1998]
 140.352 -  cleaned up some typos in libpng.txt and in code documentation
 140.353 -  fixed memory leaks in pCAL chunk processing (Glenn R-P and John Bowler)
 140.354 -  cosmetic change "display_gamma" to "screen_gamma" in pngrtran.c
 140.355 -  changed recommendation about file_gamma for PC images to .51 from .45,
 140.356 -     in example.c and libpng.txt, added comments to distinguish between
 140.357 -     screen_gamma, viewing_gamma, and display_gamma.
 140.358 -  changed all references to RFC1152 to read RFC1123 and changed the
 140.359 -     PNG_TIME_RFC1152_SUPPORTED macro to PNG_TIME_RFC1123_SUPPORTED
 140.360 -  added png_invert_alpha capability (Glenn R-P -- suggestion by Jon Vincent)
 140.361 -  changed srgb_intent from png_byte to int to avoid compiler bugs
 140.362 -
 140.363 -version 0.99 [January 30, 1998]
 140.364 -  free info_ptr->text instead of end_info_ptr->text in pngread.c (John Bowler)
 140.365 -  fixed a longstanding "packswap" bug in pngtrans.c
 140.366 -  fixed some inconsistencies in pngconf.h that prevented compiling with
 140.367 -     PNG_READ_GAMMA_SUPPORTED and PNG_READ_hIST_SUPPORTED undefined
 140.368 -  fixed some typos and made other minor rearrangement of libpng.txt (Andreas)
 140.369 -  changed recommendation about file_gamma for PC images to .50 from .51 in
 140.370 -     example.c and libpng.txt, and changed file_gamma for sRGB images to .45
 140.371 -  added a number of functions to access information from the png structure
 140.372 -     png_get_image_height(), etc. (Glenn R-P, suggestion by Brad Pettit)
 140.373 -  added TARGET_MACOS similar to zlib-1.0.8
 140.374 -  define PNG_ALWAYS_EXTERN when __MWERKS__ && WIN32 are defined
 140.375 -  added type casting to all png_malloc() function calls
 140.376 -version 0.99a [January 31, 1998]
 140.377 +Version 0.98 [January, 1998]
 140.378 +  Cleaned up some typos in libpng.txt and in code documentation
 140.379 +  Fixed memory leaks in pCAL chunk processing (Glenn R-P and John Bowler)
 140.380 +  Cosmetic change "display_gamma" to "screen_gamma" in pngrtran.c
 140.381 +  Changed recommendation about file_gamma for PC images to .51 from .45,
 140.382 +    in example.c and libpng.txt, added comments to distinguish between
 140.383 +    screen_gamma, viewing_gamma, and display_gamma.
 140.384 +  Changed all references to RFC1152 to read RFC1123 and changed the
 140.385 +    PNG_TIME_RFC1152_SUPPORTED macro to PNG_TIME_RFC1123_SUPPORTED
 140.386 +  Added png_invert_alpha capability (Glenn R-P -- suggestion by Jon Vincent)
 140.387 +  Changed srgb_intent from png_byte to int to avoid compiler bugs
 140.388 +
 140.389 +Version 0.99 [January 30, 1998]
 140.390 +  Free info_ptr->text instead of end_info_ptr->text in pngread.c (John Bowler)
 140.391 +  Fixed a longstanding "packswap" bug in pngtrans.c
 140.392 +  Fixed some inconsistencies in pngconf.h that prevented compiling with
 140.393 +    PNG_READ_GAMMA_SUPPORTED and PNG_READ_hIST_SUPPORTED undefined
 140.394 +  Fixed some typos and made other minor rearrangement of libpng.txt (Andreas)
 140.395 +  Changed recommendation about file_gamma for PC images to .50 from .51 in
 140.396 +    example.c and libpng.txt, and changed file_gamma for sRGB images to .45
 140.397 +  Added a number of functions to access information from the png structure
 140.398 +    png_get_image_height(), etc. (Glenn R-P, suggestion by Brad Pettit)
 140.399 +  Added TARGET_MACOS similar to zlib-1.0.8
 140.400 +  Define PNG_ALWAYS_EXTERN when __MWERKS__ && WIN32 are defined
 140.401 +  Added type casting to all png_malloc() function calls
 140.402 +
 140.403 +Version 0.99a [January 31, 1998]
 140.404    Added type casts and parentheses to all returns that return a value.(Tim W.)
 140.405 -version 0.99b [February 4, 1998]
 140.406 +
 140.407 +Version 0.99b [February 4, 1998]
 140.408    Added type cast png_uint_32 on malloc function calls where needed.
 140.409    Changed type of num_hist from png_uint_32 to int (same as num_palette).
 140.410    Added checks for rowbytes overflow, in case png_size_t is less than 32 bits.
 140.411    Renamed makefile.elf to makefile.lnx.
 140.412 -version 0.99c [February 7, 1998]
 140.413 +
 140.414 +Version 0.99c [February 7, 1998]
 140.415    More type casting.  Removed erroneous overflow test in pngmem.c.
 140.416    Added png_buffered_memcpy() and png_buffered_memset(), apply them to rowbytes.
 140.417    Added UNIX manual pages libpng.3 (incorporating libpng.txt) and  png.5.
 140.418 -version 0.99d [February 11, 1998]
 140.419 +
 140.420 +Version 0.99d [February 11, 1998]
 140.421    Renamed "far_to_near()" "png_far_to_near()"
 140.422    Revised libpng.3
 140.423    Version 99c "buffered" operations didn't work as intended.  Replaced them
 140.424 @@ -280,7 +285,8 @@
 140.425    Check for overlength tRNS chunk present when indexed-color PLTE is read.
 140.426    Cleaned up spelling errors in libpng.3/libpng.txt
 140.427    Corrected a problem with png_get_tRNS() which returned undefined trans array
 140.428 -version 0.99e [February 28, 1998]
 140.429 +
 140.430 +Version 0.99e [February 28, 1998]
 140.431    Corrected png_get_tRNS() again.
 140.432    Add parentheses for easier reading of pngget.c, fixed "||" should be "&&".
 140.433    Touched up example.c to make more of it compileable, although the entire
 140.434 @@ -290,53 +296,59 @@
 140.435    Replaced pngtest.png with one created with zlib 1.1.1
 140.436    Changed pngtest to report PASS even when file size is different (Jean-loup G.)
 140.437    Corrected some logic errors in png_do_invert_alpha() (Chris Patterson)
 140.438 -version 0.99f [March 5, 1998]
 140.439 +
 140.440 +Version 0.99f [March 5, 1998]
 140.441    Corrected a bug in pngpread() introduced in version 99c (Kevin Bracey)
 140.442    Moved makefiles into a "scripts" directory, and added INSTALL instruction file
 140.443    Added makefile.os2 and pngos2.def (A. Zabolotny) and makefile.s2x (W. Sebok)
 140.444    Added pointers to "note on libpng versions" in makefile.lnx and README
 140.445    Added row callback feature when reading and writing nonprogressive rows
 140.446 -     and added a test of this feature in pngtest.c
 140.447 +    and added a test of this feature in pngtest.c
 140.448    Added user transform callbacks, with test of the feature in pngtest.c
 140.449 -version 0.99g [March 6, 1998, morning]
 140.450 +
 140.451 +Version 0.99g [March 6, 1998, morning]
 140.452    Minor changes to pngtest.c to suppress compiler warnings.
 140.453    Removed "beta" language from documentation.
 140.454 -version 0.99h [March 6, 1998, evening]
 140.455 +
 140.456 +Version 0.99h [March 6, 1998, evening]
 140.457    Minor changes to previous minor changes to pngtest.c
 140.458    Changed PNG_READ_NOT_FULLY_SUPPORTED to PNG_READ_TRANSFORMS_NOT_SUPPORTED
 140.459 -  and added PNG_PROGRESSIVE_READ_NOT_SUPPORTED macro
 140.460 +    and added PNG_PROGRESSIVE_READ_NOT_SUPPORTED macro
 140.461    Added user transform capability
 140.462  
 140.463 -version 1.00 [March 7, 1998]
 140.464 +Version 1.00 [March 7, 1998]
 140.465    Changed several typedefs in pngrutil.c
 140.466    Added makefile.wat (Pawel Mrochen), updated makefile.tc3 (Willem van Schaik)
 140.467 -  replaced "while(1)" with "for(;;)"
 140.468 -  added PNGARG() to prototypes in pngtest.c and removed some prototypes
 140.469 -  updated some of the makefiles (Tom Lane)
 140.470 -  changed some typedefs (s_start, etc.) in pngrutil.c
 140.471 -  fixed dimensions of "short_months" array in pngwrite.c
 140.472 +  Replaced "while(1)" with "for(;;)"
 140.473 +  Added PNGARG() to prototypes in pngtest.c and removed some prototypes
 140.474 +  Updated some of the makefiles (Tom Lane)
 140.475 +  Changed some typedefs (s_start, etc.) in pngrutil.c
 140.476 +  Fixed dimensions of "short_months" array in pngwrite.c
 140.477    Replaced ansi2knr.c with the one from jpeg-v6
 140.478  
 140.479 -version 1.0.0 [March 8, 1998]
 140.480 +Version 1.0.0 [March 8, 1998]
 140.481    Changed name from 1.00 to 1.0.0 (Adam Costello)
 140.482    Added smakefile.ppc (with SCOPTIONS.ppc) for Amiga PPC (Andreas Kleinert)
 140.483 -version 1.0.0a [March 9, 1998]
 140.484 +
 140.485 +Version 1.0.0a [March 9, 1998]
 140.486    Fixed three bugs in pngrtran.c to make gamma+background handling consistent
 140.487 -  (Greg Roelofs)
 140.488 +    (Greg Roelofs)
 140.489    Changed format of the PNG_LIBPNG_VER integer to xyyzz instead of xyz
 140.490 -  for major, minor, and bugfix releases.  This is 10001. (Adam Costello,
 140.491 -  Tom Lane)
 140.492 +    for major, minor, and bugfix releases.  This is 10001. (Adam Costello,
 140.493 +    Tom Lane)
 140.494    Make months range from 1-12 in png_convert_to_rfc1123
 140.495 -version 1.0.0b [March 13, 1998]
 140.496 +
 140.497 +Version 1.0.0b [March 13, 1998]
 140.498    Quieted compiler complaints about two empty "for" loops in pngrutil.c
 140.499    Minor changes to makefile.s2x
 140.500    Removed #ifdef/#endif around a png_free() in pngread.c
 140.501  
 140.502 -version 1.0.1 [March 14, 1998]
 140.503 +Version 1.0.1 [March 14, 1998]
 140.504    Changed makefile.s2x to reduce security risk of using a relative pathname
 140.505    Fixed some typos in the documentation (Greg).
 140.506    Fixed a problem with value of "channels" returned by png_read_update_info()
 140.507 -version 1.0.1a [April 21, 1998]
 140.508 +
 140.509 +Version 1.0.1a [April 21, 1998]
 140.510    Optimized Paeth calculations by replacing abs() function calls with intrinsics
 140.511    plus other loop optimizations. Improves avg decoding speed by about 20%.
 140.512    Commented out i386istic "align" compiler flags in makefile.lnx.
 140.513 @@ -350,19 +362,24 @@
 140.514    Moved a misplaced pngrutil code block that truncates tRNS if it has more
 140.515      than num_palette entries -- test was done before num_palette was defined.
 140.516    Fixed a png_convert_to_rfc1123() bug that converts day 31 to 0 (Steve Eddins).
 140.517 -  Changed compiler flags in makefile.wat for better optimization (Pawel Mrochen).
 140.518 -version 1.0.1b [May 2, 1998]
 140.519 +  Changed compiler flags in makefile.wat for better optimization
 140.520 +    (Pawel Mrochen).
 140.521 +
 140.522 +Version 1.0.1b [May 2, 1998]
 140.523    Relocated png_do_gray_to_rgb() within png_do_read_transformations() (Greg).
 140.524    Relocated the png_composite macros from pngrtran.c to png.h (Greg).
 140.525    Added makefile.sco (contributed by Mike Hopkirk).
 140.526    Fixed two bugs (missing definitions of "istop") introduced in libpng-1.0.1a.
 140.527    Fixed a bug in pngrtran.c that would set channels=5 under some circumstances.
 140.528 -  More work on the Paeth-filtering, achieving imperceptible speedup (A Kleinert).
 140.529 -  More work on loop optimization which may help when compiled with C++ compilers.
 140.530 +  More work on the Paeth-filtering, achieving imperceptible speedup
 140.531 +    (A Kleinert).
 140.532 +  More work on loop optimization which may help when compiled with C++
 140.533 +    compilers.
 140.534    Added warnings when people try to use transforms they've defined out.
 140.535    Collapsed 4 "i" and "c" loops into single "i" loops in pngrtran and pngwtran.
 140.536    Revised paragraph about png_set_expand() in libpng.txt and libpng.3 (Greg)
 140.537 -version 1.0.1c [May 11, 1998]
 140.538 +
 140.539 +Version 1.0.1c [May 11, 1998]
 140.540    Fixed a bug in pngrtran.c (introduced in libpng-1.0.1a) where the masks for
 140.541      filler bytes should have been 0xff instead of 0xf.
 140.542    Added max_pixel_depth=32 in pngrutil.c when using FILLER with palette images.
 140.543 @@ -374,7 +391,8 @@
 140.544      to remove unwanted capabilities via the compile line
 140.545    Made some corrections to grammar (which, it's) in documentation (Greg).
 140.546    Corrected example.c, use of row_pointers in png_write_image().
 140.547 -version 1.0.1d [May 24, 1998]
 140.548 +
 140.549 +Version 1.0.1d [May 24, 1998]
 140.550    Corrected several statements that used side effects illegally in pngrutil.c
 140.551      and pngtrans.c, that were introduced in version 1.0.1b
 140.552    Revised png_read_rows() to avoid repeated if-testing for NULL (A Kleinert)
 140.553 @@ -384,7 +402,8 @@
 140.554      Bob Dellaca, to make a png32bd.dll with Borland C++ 4.5
 140.555    Fixed error in example.c with png_set_text: num_text is 3, not 2 (Guido V.)
 140.556    Changed several loops from count-down to count-up, for consistency.
 140.557 -version 1.0.1e [June 6, 1998]
 140.558 +
 140.559 +Version 1.0.1e [June 6, 1998]
 140.560    Revised libpng.txt and libpng.3 description of png_set_read|write_fn(), and
 140.561      added warnings when people try to set png_read_fn and png_write_fn in
 140.562      the same structure.
 140.563 @@ -401,9 +420,10 @@
 140.564      PNGTEST_DEBUG_MEM feature.
 140.565    Added makefile.w32, for Microsoft C++ 4.0 and later (Tim Wegner).
 140.566  
 140.567 -version 1.0.2 [June 14, 1998]
 140.568 +Version 1.0.2 [June 14, 1998]
 140.569    Fixed two bugs in makefile.bor .
 140.570 -version 1.0.2a [December 30, 1998]
 140.571 +
 140.572 +Version 1.0.2a [December 30, 1998]
 140.573    Replaced and extended code that was removed from png_set_filler() in 1.0.1a.
 140.574    Fixed a bug in png_do_filler() that made it fail to write filler bytes in
 140.575      the left-most pixel of each row (Kevin Bracey).
 140.576 @@ -425,21 +445,24 @@
 140.577    Added png_get_copyright() and png_get_header_version() functions.
 140.578    Revised comments on png_set_progressive_read_fn() in libpng.txt and example.c
 140.579    Added information about debugging in libpng.txt and libpng.3 .
 140.580 -  Changed "ln -sf" to "ln -s -f" in makefile.s2x, makefile.lnx, and makefile.sco.
 140.581 +  Changed "ln -sf" to "ln -s -f" in makefile.s2x, makefile.lnx, and
 140.582 +    makefile.sco.
 140.583    Removed lines after Dynamic Dependencies" in makefile.aco .
 140.584    Revised makefile.dec to make a shared library (Jeremie Petit).
 140.585    Removed trailing blanks from all files.
 140.586 -version 1.0.2a [January 6, 1999]
 140.587 +
 140.588 +Version 1.0.2a [January 6, 1999]
 140.589    Removed misplaced #endif and #ifdef PNG_NO_EXTERN near the end of png.h
 140.590    Added "if" tests to silence complaints about unused png_ptr in png.h and png.c
 140.591    Changed "check_if_png" function in example.c to return true (nonzero) if PNG.
 140.592    Changed libpng.txt to demonstrate png_sig_cmp() instead of png_check_sig()
 140.593      which is obsolete.
 140.594  
 140.595 -version 1.0.3 [January 14, 1999]
 140.596 +Version 1.0.3 [January 14, 1999]
 140.597    Added makefile.hux, for Hewlett Packard HPUX 10.20 and 11.00 (Jim Rice)
 140.598    Added a statement of Y2K compliance in png.h, libpng.3, and Y2KINFO.
 140.599 -version 1.0.3a [August 12, 1999]
 140.600 +
 140.601 +Version 1.0.3a [August 12, 1999]
 140.602    Added check for PNG_READ_INTERLACE_SUPPORTED in pngread.c; issue a warning
 140.603       if an attempt is made to read an interlaced image when it's not supported.
 140.604    Added check if png_ptr->trans is defined before freeing it in pngread.c
 140.605 @@ -466,13 +489,15 @@
 140.606    Correct gamma with srgb is 45455 instead of 45000 in pngrutil.c, to be
 140.607      consistent with PNG-1.2, and allow variance of 500 before complaining.
 140.608    Added assembler code contributed by Intel in file pngvcrd.c and modified
 140.609 -    makefile.w32 to use it (Nirav Chhatrapati, INTEL Corporation, Gilles Vollant)
 140.610 +    makefile.w32 to use it (Nirav Chhatrapati, INTEL Corporation,
 140.611 +    Gilles Vollant)
 140.612    Changed "ln -s -f" to "ln -f -s" in the makefiles to make Solaris happy.
 140.613    Added some aliases for png_set_expand() in pngrtran.c, namely
 140.614      png_set_expand_PLTE(), png_set_expand_depth(), and png_set_expand_tRNS()
 140.615      (Greg Roelofs, in "PNG: The Definitive Guide").
 140.616    Added makefile.beo for BEOS on X86, contributed by Sander Stok.
 140.617 -version 1.0.3b [August 26, 1999]
 140.618 +
 140.619 +Version 1.0.3b [August 26, 1999]
 140.620    Replaced 2147483647L several places with PNG_MAX_UINT macro, defined in png.h
 140.621    Changed leading blanks to tabs in all makefiles.
 140.622    Define PNG_USE_PNGVCRD in makefile.w32, to get MMX assembler code.
 140.623 @@ -484,12 +509,13 @@
 140.624      negative shift distance, whose results are undefined in the C language.
 140.625    Added a check in pngset.c to prevent writing multiple tIME chunks.
 140.626    Added a check in pngwrite.c to detect invalid small window_bits sizes.
 140.627 -version 1.0.3d [September 4, 1999]
 140.628 +
 140.629 +Version 1.0.3d [September 4, 1999]
 140.630    Fixed type casting of igamma in pngrutil.c
 140.631    Added new png_expand functions to scripts/pngdef.pas and pngos2.def
 140.632    Added a demo read_user_transform_fn that examines the row filters in pngtest.c
 140.633  
 140.634 -version 1.0.4 [September 24, 1999]
 140.635 +Version 1.0.4 [September 24, 1999]
 140.636    Define PNG_ALWAYS_EXTERN in pngconf.h if __STDC__ is defined
 140.637    Delete #define PNG_INTERNAL and include "png.h" from pngasmrd.h
 140.638    Made several minor corrections to pngtest.c
 140.639 @@ -503,24 +529,30 @@
 140.640      assembler code) and makefile.vcwin32 (doesn't).
 140.641    Added a CPU timing report to pngtest.c (enabled by defining PNGTEST_TIMING)
 140.642    Added a copy of pngnow.png to the distribution.
 140.643 -version 1.0.4a [September 25, 1999]
 140.644 +
 140.645 +Version 1.0.4a [September 25, 1999]
 140.646    Increase max_pixel_depth in pngrutil.c if a user transform needs it.
 140.647    Changed several division operations to right-shifts in pngvcrd.c
 140.648 -version 1.0.4b [September 30, 1999]
 140.649 +
 140.650 +Version 1.0.4b [September 30, 1999]
 140.651    Added parentheses in line 3732 of pngvcrd.c
 140.652    Added a comment in makefile.linux warning about buggy -O3 in pgcc 2.95.1
 140.653 -version 1.0.4c [October 1, 1999]
 140.654 +
 140.655 +Version 1.0.4c [October 1, 1999]
 140.656    Added a "png_check_version" function in png.c and pngtest.c that will generate
 140.657      a helpful compiler error if an old png.h is found in the search path.
 140.658    Changed type of png_user_transform_depth|channels from int to png_byte.
 140.659 -version 1.0.4d [October 6, 1999]
 140.660 +
 140.661 +Version 1.0.4d [October 6, 1999]
 140.662    Changed 0.45 to 0.45455 in png_set_sRGB()
 140.663    Removed unused PLTE entries from pngnow.png
 140.664    Re-enabled some parts of pngvcrd.c (png_combine_row) that work properly.
 140.665 -version 1.0.4e [October 10, 1999]
 140.666 +
 140.667 +Version 1.0.4e [October 10, 1999]
 140.668    Fixed sign error in pngvcrd.c (Greg Roelofs)
 140.669    Replaced some instances of memcpy with simple assignments in pngvcrd (GR-P)
 140.670 -version 1.0.4f [October 15, 1999]
 140.671 +
 140.672 +Version 1.0.4f [October 15, 1999]
 140.673    Surrounded example.c code with #if 0 .. #endif to prevent people from
 140.674      inadvertently trying to compile it.
 140.675    Changed png_get_header_version() from a function to a macro in png.h
 140.676 @@ -528,9 +560,10 @@
 140.677    Removed some pointless "ptr = NULL" in pngmem.c
 140.678    Added a "contrib" directory containing the source code from Greg's book.
 140.679  
 140.680 -version 1.0.5 [October 15, 1999]
 140.681 +Version 1.0.5 [October 15, 1999]
 140.682    Minor editing of the INSTALL and README files.
 140.683 -version 1.0.5a [October 23, 1999]
 140.684 +
 140.685 +Version 1.0.5a [October 23, 1999]
 140.686    Added contrib/pngsuite and contrib/pngminus (Willem van Schaik)
 140.687    Fixed a typo in the png_set_sRGB() function call in example.c (Jan Nijtmans)
 140.688    Further optimization and bugfix of pngvcrd.c
 140.689 @@ -538,14 +571,16 @@
 140.690      text_ptr structure.  Instead, it makes its own copy.
 140.691    Created separate write_end_info_struct in pngtest.c for a more severe test.
 140.692    Added code in pngwrite.c to free info_ptr->text[i].key to stop a memory leak.
 140.693 -version 1.0.5b [November 23, 1999]
 140.694 +
 140.695 +Version 1.0.5b [November 23, 1999]
 140.696    Moved PNG_FLAG_HAVE_CHUNK_HEADER, PNG_FLAG_BACKGROUND_IS_GRAY and
 140.697      PNG_FLAG_WROTE_tIME from flags to mode.
 140.698    Added png_write_info_before_PLTE() function.
 140.699    Fixed some typecasting in contrib/gregbook/*.c
 140.700    Updated scripts/makevms.com and added makevms.com to contrib/gregbook
 140.701      and contrib/pngminus (Martin Zinser)
 140.702 -version 1.0.5c [November 26, 1999]
 140.703 +
 140.704 +Version 1.0.5c [November 26, 1999]
 140.705    Moved png_get_header_version from png.h to png.c, to accommodate ansi2knr.
 140.706    Removed all global arrays (according to PNG_NO_GLOBAL_ARRAYS macro), to
 140.707      accommodate making DLL's: Moved usr_png_ver from global variable to function
 140.708 @@ -558,14 +593,17 @@
 140.709    Removed some extraneous "-I" from contrib/pngminus/makefile.std
 140.710    Changed the PNG_sRGB_INTENT macros in png.h to be consistent with PNG-1.2.
 140.711    Change PNG_SRGB_INTENT to PNG_sRGB_INTENT in libpng.txt and libpng.3
 140.712 -version 1.0.5d [November 29, 1999]
 140.713 +
 140.714 +Version 1.0.5d [November 29, 1999]
 140.715    Add type cast (png_const_charp) two places in png.c
 140.716    Eliminated pngtypes.h; use macros instead to declare PNG_CHNK arrays.
 140.717    Renamed "PNG_GLOBAL_ARRAYS" to "PNG_USE_GLOBAL_ARRAYS" and made available
 140.718      to applications a macro "PNG_USE_LOCAL_ARRAYS".
 140.719 -  #ifdef out all the new declarations when PNG_USE_GLOBAL_ARRAYS is defined.
 140.720 +  comment out (with #ifdef) all the new declarations when
 140.721 +    PNG_USE_GLOBAL_ARRAYS is defined.
 140.722    Added PNG_EXPORT_VAR macro to accommodate making DLL's.
 140.723 -version 1.0.5e [November 30, 1999]
 140.724 +
 140.725 +Version 1.0.5e [November 30, 1999]
 140.726    Added iCCP, iTXt, and sPLT support; added "lang" member to the png_text
 140.727      structure; refactored the inflate/deflate support to make adding new chunks
 140.728      with trailing compressed parts easier in the future, and added new functions
 140.729 @@ -586,18 +624,21 @@
 140.730      PNG_cHNK_SUPPORTED and combined the three types of PNG_text_SUPPORTED
 140.731      macros, leaving the separate macros also available.
 140.732    Removed comments on #endifs at the end of many short, non-nested #if-blocks.
 140.733 -version 1.0.5f [December 6, 1999]
 140.734 +
 140.735 +Version 1.0.5f [December 6, 1999]
 140.736    Changed makefile.solaris to issue a warning about potential problems when
 140.737      the ucb "ld" is in the path ahead of the ccs "ld".
 140.738    Removed "- [date]" from the "synopsis" line in libpng.3 and libpngpf.3.
 140.739    Added sCAL chunk support (Eric S. Raymond).
 140.740 -version 1.0.5g [December 7, 1999]
 140.741 +
 140.742 +Version 1.0.5g [December 7, 1999]
 140.743    Fixed "png_free_spallettes" typo in png.h
 140.744    Added code to handle new chunks in pngpread.c
 140.745    Moved PNG_CHNK string macro definitions outside of PNG_NO_EXTERN block
 140.746    Added "translated_key" to png_text structure and png_write_iTXt().
 140.747    Added code in pngwrite.c to work around a newly discovered zlib bug.
 140.748 -version 1.0.5h [December 10, 1999]
 140.749 +
 140.750 +Version 1.0.5h [December 10, 1999]
 140.751    NOTE: regarding the note for version 1.0.5e, the following must also
 140.752      be included in your code:
 140.753          png_text[i].translated_key = NULL;
 140.754 @@ -605,7 +646,8 @@
 140.755    Option to eliminate all floating point support was added.  Some new
 140.756      fixed-point functions such as png_set_gAMA_fixed() were added.
 140.757    Expanded tabs and removed trailing blanks in source files.
 140.758 -version 1.0.5i [December 13, 1999]
 140.759 +
 140.760 +Version 1.0.5i [December 13, 1999]
 140.761    Added some type casts to silence compiler warnings.
 140.762    Renamed "png_free_spalette" to "png_free_spalettes" for consistency.
 140.763    Removed leading blanks from a #define in pngvcrd.c
 140.764 @@ -617,7 +659,8 @@
 140.765    Added png_free_hIST() function.
 140.766    Various patches to fix bugs in the sCAL and integer cHRM processing,
 140.767      and to add some convenience macros for use with sCAL.
 140.768 -version 1.0.5j [December 21, 1999]
 140.769 +
 140.770 +Version 1.0.5j [December 21, 1999]
 140.771    Changed "unit" parameter of png_write_sCAL from png_byte to int, to work
 140.772      around buggy compilers.
 140.773    Added new type "png_fixed_point" for integers that hold float*100000 values
 140.774 @@ -633,7 +676,8 @@
 140.775      and to write the iTXt chunk after IDAT if it appears in the end_ptr.
 140.776    Added pnggccrd.c, version of pngvcrd.c Intel assembler for gcc (Greg Roelofs)
 140.777    Reversed the order of trying to write floating-point and fixed-point gAMA.
 140.778 -version 1.0.5k [December 27, 1999]
 140.779 +
 140.780 +Version 1.0.5k [December 27, 1999]
 140.781    Added many parentheses, e.g., "if (a && b & c)" becomes "if (a && (b & c))"
 140.782    Added png_handle_as_unknown() function (Glenn)
 140.783    Added png_free_chunk_list() function and chunk_list and num_chunk_list members
 140.784 @@ -644,33 +688,41 @@
 140.785    Added png_free_tRNS(); png_set_tRNS() now malloc's its own trans array (ESR).
 140.786    Define png_get_int_32 when oFFs chunk is supported as well as when pCAL is.
 140.787    Changed type of proflen from png_int_32 to png_uint_32 in png_get_iCCP().
 140.788 -version 1.0.5l [January 1, 2000]
 140.789 +
 140.790 +Version 1.0.5l [January 1, 2000]
 140.791    Added functions png_set_read_user_chunk_fn() and png_get_user_chunk_ptr()
 140.792      for setting a callback function to handle unknown chunks and for
 140.793      retrieving the associated user pointer (Glenn).
 140.794 -version 1.0.5m [January 7, 2000]
 140.795 +
 140.796 +Version 1.0.5m [January 7, 2000]
 140.797    Added high-level functions png_read_png(), png_write_png(), png_free_pixels().
 140.798 -version 1.0.5n [January 9, 2000]
 140.799 +
 140.800 +Version 1.0.5n [January 9, 2000]
 140.801    Added png_free_PLTE() function, and modified png_set_PLTE() to malloc its
 140.802      own memory for info_ptr->palette.  This makes it safe for the calling
 140.803      application to free its copy of the palette any time after it calls
 140.804      png_set_PLTE().
 140.805 -version 1.0.5o [January 20, 2000]
 140.806 +
 140.807 +Version 1.0.5o [January 20, 2000]
 140.808    Cosmetic changes only (removed some trailing blanks and TABs)
 140.809 -version 1.0.5p [January 31, 2000]
 140.810 +
 140.811 +Version 1.0.5p [January 31, 2000]
 140.812    Renamed pngdll.mak to makefile.bd32
 140.813    Cosmetic changes in pngtest.c
 140.814 -version 1.0.5q [February 5, 2000]
 140.815 +
 140.816 +Version 1.0.5q [February 5, 2000]
 140.817    Relocated the makefile.solaris warning about PATH problems.
 140.818    Fixed pngvcrd.c bug by pushing/popping registers in mmxsupport (Bruce Oberg)
 140.819    Revised makefile.gcmmx
 140.820    Added PNG_SETJMP_SUPPORTED, PNG_SETJMP_NOT_SUPPORTED, and PNG_ABORT() macros
 140.821 -version 1.0.5r [February 7, 2000]
 140.822 +
 140.823 +Version 1.0.5r [February 7, 2000]
 140.824    Removed superfluous prototype for png_get_itxt from png.h
 140.825    Fixed a bug in pngrtran.c that improperly expanded the background color.
 140.826    Return *num_text=0 from png_get_text() when appropriate, and fix documentation
 140.827      of png_get_text() in libpng.txt/libpng.3.
 140.828 -version 1.0.5s [February 18, 2000]
 140.829 +
 140.830 +Version 1.0.5s [February 18, 2000]
 140.831    Added "png_jmp_env()" macro to pngconf.h, to help people migrate to the
 140.832      new error handler that's planned for the next libpng release, and changed
 140.833      example.c, pngtest.c, and contrib programs to use this macro.
 140.834 @@ -689,7 +741,8 @@
 140.835    Added png_set_rows() and png_get_rows(), for use with png_read|write_png().
 140.836    Modified png_read_png() to allocate info_ptr->row_pointers only if it
 140.837      hasn't already been allocated.
 140.838 -version 1.0.5t [March 4, 2000]
 140.839 +
 140.840 +Version 1.0.5t [March 4, 2000]
 140.841    Changed png_jmp_env() migration aiding macro to png_jmpbuf().
 140.842    Fixed "interlace" typo (should be "interlaced") in contrib/gregbook/read2-x.c
 140.843    Fixed bug with use of PNG_BEFORE_IHDR bit in png_ptr->mode, introduced when
 140.844 @@ -698,13 +751,15 @@
 140.845      a 24-bit visual if one is available, and to allow abbreviated options.
 140.846    Files in contrib/pngminus were revised to use the png_jmpbuf() macro.
 140.847    Removed spaces in makefile.linux and makefile.gcmmx, introduced in 1.0.5s
 140.848 -version 1.0.5u [March 5, 2000]
 140.849 +
 140.850 +Version 1.0.5u [March 5, 2000]
 140.851    Simplified the code that detects old png.h in png.c and pngtest.c
 140.852    Renamed png_spalette (_p, _pp) to png_sPLT_t (_tp, _tpp)
 140.853    Increased precision of rgb_to_gray calculations from 8 to 15 bits and
 140.854      added png_set_rgb_to_gray_fixed() function.
 140.855    Added makefile.bc32 (32-bit Borland C++, C mode)
 140.856 -version 1.0.5v [March 11, 2000]
 140.857 +
 140.858 +Version 1.0.5v [March 11, 2000]
 140.859    Added some parentheses to the png_jmpbuf macro definition.
 140.860    Updated references to the zlib home page, which has moved to freesoftware.com.
 140.861    Corrected bugs in documentation regarding png_read_row() and png_write_row().
 140.862 @@ -712,10 +767,11 @@
 140.863    Renamed makefile.borland,turboc3 back to makefile.bor,tc3 as in version 1.0.3,
 140.864      revised borland makefiles; added makefile.ibmvac3 and makefile.gcc (Cosmin)
 140.865  
 140.866 -version 1.0.6 [March 20, 2000]
 140.867 +Version 1.0.6 [March 20, 2000]
 140.868    Minor revisions of makefile.bor, libpng.txt, and gregbook/rpng2-win.c
 140.869    Added makefile.sggcc (SGI IRIX with gcc)
 140.870 -version 1.0.6d [April 7, 2000]
 140.871 +
 140.872 +Version 1.0.6d [April 7, 2000]
 140.873    Changed sprintf() to strcpy() in png_write_sCAL_s() to work without STDIO
 140.874    Added data_length parameter to png_decompress_chunk() function
 140.875    Revised documentation to remove reference to abandoned png_free_chnk functions
 140.876 @@ -724,7 +780,8 @@
 140.877    Renamed makefile.ibmvac3 to makefile.ibmc, added libpng.icc IBM project file
 140.878    Added a check for info_ptr->free_me&PNG_FREE_TEXT when freeing text in png.c
 140.879    Simplify png_sig_bytes() function to remove use of non-ISO-C strdup().
 140.880 -version 1.0.6e [April 9, 2000]
 140.881 +
 140.882 +Version 1.0.6e [April 9, 2000]
 140.883    Added png_data_freer() function.
 140.884    In the code that checks for over-length tRNS chunks, added check of
 140.885      info_ptr->num_trans as well as png_ptr->num_trans (Matthias Benckmann)
 140.886 @@ -735,25 +792,29 @@
 140.887      is defined.
 140.888    Changed several instances of PNG_NO_CONSOLE_ID to PNG_NO_STDIO in pngrutil.c
 140.889      and mentioned the purposes of the two macros in libpng.txt/libpng.3.
 140.890 -version 1.0.6f [April 14, 2000]
 140.891 +
 140.892 +Version 1.0.6f [April 14, 2000]
 140.893    Revised png_set_iCCP() and png_set_rows() to avoid prematurely freeing data.
 140.894    Add checks in png_set_text() for NULL members of the input text structure.
 140.895    Revised libpng.txt/libpng.3.
 140.896 -  Removed superfluous prototype for png_set_itxt from png.h
 140.897 +  Removed superfluous prototype for png_set_iTXt from png.h
 140.898    Removed "else" from pngread.c, after png_error(), and changed "0" to "length".
 140.899    Changed several png_errors about malformed ancillary chunks to png_warnings.
 140.900 -version 1.0.6g [April 24, 2000]
 140.901 +
 140.902 +Version 1.0.6g [April 24, 2000]
 140.903    Added png_pass-* arrays to pnggccrd.c when PNG_USE_LOCAL_ARRAYS is defined.
 140.904    Relocated paragraph about png_set_background() in libpng.3/libpng.txt
 140.905      and other revisions (Matthias Benckmann)
 140.906    Relocated info_ptr->free_me, png_ptr->free_me, and other info_ptr and
 140.907      png_ptr members to restore binary compatibility with libpng-1.0.5
 140.908      (breaks compatibility with libpng-1.0.6).
 140.909 -version 1.0.6h [April 24, 2000]
 140.910 +
 140.911 +Version 1.0.6h [April 24, 2000]
 140.912    Changed shared library so-number pattern from 2.x.y.z to xy.z (this builds
 140.913      libpng.so.10 & libpng.so.10.6h instead of libpng.so.2 & libpng.so.2.1.0.6h)
 140.914      This is a temporary change for test purposes.
 140.915 -version 1.0.6i [May 2, 2000]
 140.916 +
 140.917 +Version 1.0.6i [May 2, 2000]
 140.918    Rearranged some members at the end of png_info and png_struct, to put
 140.919      unknown_chunks_num and free_me within the original size of the png_structs
 140.920      and free_me, png_read_user_fn, and png_free_fn within the original png_info,
 140.921 @@ -778,11 +839,13 @@
 140.922      generate a libpng error if the modes aren't set and PNG_LEGACY_SUPPORTED
 140.923      was not defined.
 140.924    Added makefile.intel and updated makefile.watcom (Pawel Mrochen)
 140.925 -version 1.0.6j [May 3, 2000]
 140.926 +
 140.927 +Version 1.0.6j [May 3, 2000]
 140.928    Overloaded png_read_init() and png_write_init() with macros that convert
 140.929      calls to png_read_init_2() or png_write_init_2() that check the version
 140.930      and structure sizes.
 140.931 -version 1.0.7beta11 [May 7, 2000]
 140.932 +
 140.933 +Version 1.0.7beta11 [May 7, 2000]
 140.934    Removed the new PNG_CREATED_READ_STRUCT and PNG_CREATED_WRITE_STRUCT modes
 140.935      which are no longer used.
 140.936    Eliminated the three new members of png_text when PNG_LEGACY_SUPPORTED is
 140.937 @@ -793,7 +856,8 @@
 140.938    Added PNGAPI macro, and added it to the definitions of all exported functions.
 140.939    Relocated version macro definitions ahead of the includes of zlib.h and
 140.940      pngconf.h in png.h.
 140.941 -version 1.0.7beta12 [May 12, 2000]
 140.942 +
 140.943 +Version 1.0.7beta12 [May 12, 2000]
 140.944    Revised pngset.c to avoid a problem with expanding the png_debug macro.
 140.945    Deleted some extraneous defines from pngconf.h
 140.946    Made PNG_NO_CONSOLE_IO the default condition when PNG_BUILD_DLL is defined.
 140.947 @@ -801,7 +865,8 @@
 140.948    Added png_access_version_number() function.
 140.949    Check for mask&PNG_FREE_CHNK (for TEXT, SCAL, PCAL) in png_free_data().
 140.950    Expanded libpng.3/libpng.txt information about png_data_freer().
 140.951 -version 1.0.7beta14 [May 17, 2000] (beta13 was not published)
 140.952 +
 140.953 +Version 1.0.7beta14 [May 17, 2000] (beta13 was not published)
 140.954    Changed pnggccrd.c and pngvcrd.c to handle bad adaptive filter types as
 140.955      warnings instead of errors, as pngrutil.c does.
 140.956    Set the PNG_INFO_IDAT valid flag in png_set_rows() so png_write_png()
 140.957 @@ -813,7 +878,8 @@
 140.958    Removed info_ptr->valid tests from png_free_data(), as in version 1.0.5.
 140.959    Added png_set_invalid() function.
 140.960    Fixed incorrect illustrations of png_destroy_write_struct() in example.c.
 140.961 -version 1.0.7beta15 [May 30, 2000]
 140.962 +
 140.963 +Version 1.0.7beta15 [May 30, 2000]
 140.964    Revised the deliberately erroneous Linux setjmp code in pngconf.h to produce
 140.965      fewer error messages.
 140.966    Rearranged checks for Z_OK to check the most likely path first in pngpread.c
 140.967 @@ -825,9 +891,11 @@
 140.968    Fixed some bugs in the unused PNG_INCH_CONVERSIONS functions in pngget.c
 140.969    Set each pointer to NULL after freeing it in png_free_data().
 140.970    Worked around a problem in pngconf.h; AIX's strings.h defines an "index"
 140.971 -    macro that conflicts with libpng's png_color_16.index. (Dimitri Papadapoulos)
 140.972 +    macro that conflicts with libpng's png_color_16.index. (Dimitri
 140.973 +    Papadapoulos)
 140.974    Added "msvc" directory with MSVC++ project files (Simon-Pierre Cadieux).
 140.975 -version 1.0.7beta16 [June 4, 2000]
 140.976 +
 140.977 +Version 1.0.7beta16 [June 4, 2000]
 140.978    Revised the workaround of AIX string.h "index" bug.
 140.979    Added a check for overlength PLTE chunk in pngrutil.c.
 140.980    Added PNG_NO_POINTER_INDEXING macro to use array-indexing instead of pointer
 140.981 @@ -837,23 +905,27 @@
 140.982    Added PNG_USE_DLL macro.
 140.983    Revised the copyright/disclaimer/license notice.
 140.984    Added contrib/msvctest directory
 140.985 -version 1.0.7rc1 [June 9, 2000]
 140.986 +
 140.987 +Version 1.0.7rc1 [June 9, 2000]
 140.988    Corrected the definition of PNG_TRANSFORM_INVERT_ALPHA  (0x0400 not 0x0200)
 140.989    Added contrib/visupng directory (Willem van Schaik)
 140.990 -version 1.0.7beta18 [June 23, 2000]
 140.991 +
 140.992 +Version 1.0.7beta18 [June 23, 2000]
 140.993    Revised PNGAPI definition, and pngvcrd.c to work with __GCC__
 140.994      and do not redefine PNGAPI if it is passed in via a compiler directive.
 140.995    Revised visupng/PngFile.c to remove returns from within the Try block.
 140.996    Removed leading underscores from "_PNG_H" and "_PNG_SAVE_BSD_SOURCE" macros.
 140.997    Updated contrib/visupng/cexcept.h to version 1.0.0.
 140.998    Fixed bugs in pngwrite.c and pngwutil.c that prevented writing iCCP chunks.
 140.999 -version 1.0.7rc2 [June 28, 2000]
140.1000 +
140.1001 +Version 1.0.7rc2 [June 28, 2000]
140.1002    Updated license to include disclaimers required by UCITA.
140.1003    Fixed "DJBPP" typo in pnggccrd.c introduced in beta18.
140.1004  
140.1005 -version 1.0.7 [July 1, 2000]
140.1006 +Version 1.0.7 [July 1, 2000]
140.1007    Revised the definition of "trans_values" in libpng.3/libpng.txt
140.1008 -version 1.0.8beta1 [July 8, 2000]
140.1009 +
140.1010 +Version 1.0.8beta1 [July 8, 2000]
140.1011    Added png_free(png_ptr, key) two places in pngpread.c to stop memory leaks.
140.1012    Changed PNG_NO_STDIO to PNG_NO_CONSOLE_IO, several places in pngrutil.c and
140.1013       pngwutil.c.
140.1014 @@ -861,25 +933,30 @@
140.1015    Removed unused "#include <assert.h>" from png.c
140.1016    Added WindowsCE support.
140.1017    Revised pnggccrd.c to work with gcc-2.95.2 and in the Cygwin environment.
140.1018 -version 1.0.8beta2 [July 10, 2000]
140.1019 +
140.1020 +Version 1.0.8beta2 [July 10, 2000]
140.1021    Added project files to the wince directory and made further revisions
140.1022       of pngtest.c, pngrio.c, and pngwio.c in support of WindowsCE.
140.1023 -version 1.0.8beta3 [July 11, 2000]
140.1024 +
140.1025 +Version 1.0.8beta3 [July 11, 2000]
140.1026    Only set the PNG_FLAG_FREE_TRNS or PNG_FREE_TRNS flag in png_handle_tRNS()
140.1027       for indexed-color input files to avoid potential double-freeing trans array
140.1028       under some unusual conditions; problem was introduced in version 1.0.6f.
140.1029    Further revisions to pngtest.c and files in the wince subdirectory.
140.1030 -version 1.0.8beta4 [July 14, 2000]
140.1031 +
140.1032 +Version 1.0.8beta4 [July 14, 2000]
140.1033    Added the files pngbar.png and pngbar.jpg to the distribution.
140.1034    Added makefile.cygwin, and cygwin support in pngconf.h
140.1035    Added PNG_NO_ZALLOC_ZERO macro (makes png_zalloc skip zeroing memory)
140.1036 -version 1.0.8rc1 [July 16, 2000]
140.1037 +
140.1038 +Version 1.0.8rc1 [July 16, 2000]
140.1039    Revised png_debug() macros and statements to eliminate compiler warnings.
140.1040  
140.1041 -version 1.0.8 [July 24, 2000]
140.1042 +Version 1.0.8 [July 24, 2000]
140.1043    Added png_flush() in pngwrite.c, after png_write_IEND().
140.1044    Updated makefile.hpux to build a shared library.
140.1045 -version 1.0.9beta1 [November 10, 2000]
140.1046 +
140.1047 +Version 1.0.9beta1 [November 10, 2000]
140.1048    Fixed typo in scripts/makefile.hpux
140.1049    Updated makevms.com in scripts and contrib/* and contrib/* (Martin Zinser)
140.1050    Fixed seqence-point bug in contrib/pngminus/png2pnm (Martin Zinser)
140.1051 @@ -898,59 +975,72 @@
140.1052    Revised makefile.cygwin
140.1053    Fixed bugs in iCCP support in pngrutil.c and pngwutil.c.
140.1054    Replaced png_set_empty_plte_permitted() with png_permit_mng_features().
140.1055 -version 1.0.9beta2 [November 19, 2000]
140.1056 +
140.1057 +Version 1.0.9beta2 [November 19, 2000]
140.1058    Renamed the "dll" subdirectory "projects".
140.1059    Added borland project files to "projects" subdirectory.
140.1060    Set VS_FF_PRERELEASE and VS_FF_PATCHED flags in msvc/png.rc when appropriate.
140.1061    Add error message in png_set_compression_buffer_size() when malloc fails.
140.1062 -version 1.0.9beta3 [November 23, 2000]
140.1063 +
140.1064 +Version 1.0.9beta3 [November 23, 2000]
140.1065    Revised PNG_LIBPNG_BUILD_TYPE macro in png.h, used in the msvc project.
140.1066    Removed the png_flush() in pngwrite.c that crashes some applications
140.1067      that don't set png_output_flush_fn.
140.1068    Added makefile.macosx and makefile.aix to scripts directory.
140.1069 -version 1.0.9beta4 [December 1, 2000]
140.1070 +
140.1071 +Version 1.0.9beta4 [December 1, 2000]
140.1072    Change png_chunk_warning to png_warning in png_check_keyword().
140.1073    Increased the first part of msg buffer from 16 to 18 in png_chunk_error().
140.1074 -version 1.0.9beta5 [December 15, 2000]
140.1075 +
140.1076 +Version 1.0.9beta5 [December 15, 2000]
140.1077    Added support for filter method 64 (for PNG datastreams embedded in MNG).
140.1078 -version 1.0.9beta6 [December 18, 2000]
140.1079 +
140.1080 +Version 1.0.9beta6 [December 18, 2000]
140.1081    Revised png_set_filter() to accept filter method 64 when appropriate.
140.1082    Added new PNG_HAVE_PNG_SIGNATURE bit to png_ptr->mode and use it to
140.1083      help prevent applications from using MNG features in PNG datastreams.
140.1084    Added png_permit_mng_features() function.
140.1085    Revised libpng.3/libpng.txt.  Changed "filter type" to "filter method".
140.1086 -version 1.0.9rc1 [December 23, 2000]
140.1087 +
140.1088 +Version 1.0.9rc1 [December 23, 2000]
140.1089    Revised test for PNG_HAVE_PNG_SIGNATURE in pngrutil.c
140.1090    Fixed error handling of unknown compression type in png_decompress_chunk().
140.1091    In pngconf.h, define __cdecl when _MSC_VER is defined.
140.1092 -version 1.0.9beta7 [December 28, 2000]
140.1093 +
140.1094 +Version 1.0.9beta7 [December 28, 2000]
140.1095    Changed PNG_TEXT_COMPRESSION_zTXt to PNG_COMPRESSION_TYPE_BASE several places.
140.1096    Revised memory management in png_set_hIST and png_handle_hIST in a backward
140.1097      compatible manner.  PLTE and tRNS were revised similarly.
140.1098    Revised the iCCP chunk reader to ignore trailing garbage.
140.1099 -version 1.0.9beta8 [January 12, 2001]
140.1100 +
140.1101 +Version 1.0.9beta8 [January 12, 2001]
140.1102    Moved pngasmrd.h into pngconf.h.
140.1103    Improved handling of out-of-spec garbage iCCP chunks generated by PhotoShop.
140.1104 -version 1.0.9beta9 [January 15, 2001]
140.1105 +
140.1106 +Version 1.0.9beta9 [January 15, 2001]
140.1107    Added png_set_invalid, png_permit_mng_features, and png_mmx_supported to
140.1108      wince and msvc project module definition files.
140.1109    Minor revision of makefile.cygwin.
140.1110    Fixed bug with progressive reading of narrow interlaced images in pngpread.c
140.1111 -version 1.0.9beta10 [January 16, 2001]
140.1112 +
140.1113 +Version 1.0.9beta10 [January 16, 2001]
140.1114    Do not typedef png_FILE_p in pngconf.h when PNG_NO_STDIO is defined.
140.1115    Fixed "png_mmx_supported" typo in project definition files.
140.1116 -version 1.0.9beta11 [January 19, 2001]
140.1117 +
140.1118 +Version 1.0.9beta11 [January 19, 2001]
140.1119    Updated makefile.sgi to make shared library.
140.1120    Removed png_mmx_support() function and disabled PNG_MNG_FEATURES_SUPPORTED
140.1121      by default, for the benefit of DLL forward compatibility.  These will
140.1122      be re-enabled in version 1.2.0.
140.1123 -version 1.0.9rc2 [January 22, 2001]
140.1124 +
140.1125 +Version 1.0.9rc2 [January 22, 2001]
140.1126    Revised cygwin support.
140.1127  
140.1128 -version 1.0.9 [January 31, 2001]
140.1129 +Version 1.0.9 [January 31, 2001]
140.1130    Added check of cygwin's ALL_STATIC in pngconf.h
140.1131    Added "-nommx" parameter to contrib/gregbook/rpng2-win and rpng2-x demos.
140.1132 -version 1.0.10beta1 [March 14, 2001]
140.1133 +
140.1134 +Version 1.0.10beta1 [March 14, 2001]
140.1135    Revised makefile.dec, makefile.sgi, and makefile.sggcc; added makefile.hpgcc.
140.1136    Reformatted libpng.3 to eliminate bad line breaks.
140.1137    Added checks for _mmx_supported in the read_filter_row function of pnggccrd.c
140.1138 @@ -963,33 +1053,39 @@
140.1139    Fixed bugs in png_combine_row() in pnggccrd.c and pngvcrd.c (C version)
140.1140    Added warnings when retrieving or setting gamma=0.
140.1141    Increased the first part of msg buffer from 16 to 18 in png_chunk_warning().
140.1142 -version 1.0.10rc1 [March 23, 2001]
140.1143 +
140.1144 +Version 1.0.10rc1 [March 23, 2001]
140.1145    Changed all instances of memcpy, strcpy, and strlen to png_memcpy, png_strcpy,
140.1146      and png_strlen.
140.1147    Revised png_mmx_supported() function in pnggccrd.c to return proper value.
140.1148    Fixed bug in progressive reading (pngpread.c) with small images (height < 8).
140.1149  
140.1150 -version 1.0.10 [March 30, 2001]
140.1151 +Version 1.0.10 [March 30, 2001]
140.1152    Deleted extraneous space (introduced in 1.0.9) from line 42 of makefile.cygwin
140.1153    Added beos project files (Chris Herborth)
140.1154 -version 1.0.11beta1 [April 3, 2001]
140.1155 +
140.1156 +Version 1.0.11beta1 [April 3, 2001]
140.1157    Added type casts on several png_malloc() calls (Dimitri Papadapoulos).
140.1158    Removed a no-longer needed AIX work-around from pngconf.h
140.1159    Changed several "//" single-line comments to C-style in pnggccrd.c
140.1160 -version 1.0.11beta2 [April 11, 2001]
140.1161 +
140.1162 +Version 1.0.11beta2 [April 11, 2001]
140.1163    Removed PNGAPI from several functions whose prototypes did not have PNGAPI.
140.1164    Updated scripts/pngos2.def
140.1165 -version 1.0.11beta3 [April 14, 2001]
140.1166 +
140.1167 +Version 1.0.11beta3 [April 14, 2001]
140.1168    Added checking the results of many instances of png_malloc() for NULL
140.1169 -version 1.0.11beta4 [April 20, 2001]
140.1170 +
140.1171 +Version 1.0.11beta4 [April 20, 2001]
140.1172    Undid the changes from version 1.0.11beta3.  Added a check for NULL return
140.1173      from user's malloc_fn().
140.1174    Removed some useless type casts of the NULL pointer.
140.1175    Added makefile.netbsd
140.1176  
140.1177 -version 1.0.11 [April 27, 2001]
140.1178 +Version 1.0.11 [April 27, 2001]
140.1179    Revised makefile.netbsd
140.1180 -version 1.0.12beta1 [May 14, 2001]
140.1181 +
140.1182 +Version 1.0.12beta1 [May 14, 2001]
140.1183    Test for Windows platform in pngconf.h when including malloc.h (Emmanuel Blot)
140.1184    Updated makefile.cygwin and handling of Cygwin's ALL_STATIC in pngconf.h
140.1185    Added some never-to-be-executed code in pnggccrd.c to quiet compiler warnings.
140.1186 @@ -997,21 +1093,25 @@
140.1187      libpng will reallocate the png_struct and info_struct if they are too small.
140.1188      This retains future binary compatibility for old applications written for
140.1189      libpng-0.88 and earlier.
140.1190 -version 1.2.0beta1 [May 6, 2001]
140.1191 +
140.1192 +Version 1.2.0beta1 [May 6, 2001]
140.1193    Bumped DLLNUM to 2.
140.1194    Re-enabled PNG_MNG_FEATURES_SUPPORTED and enabled PNG_ASSEMBLER_CODE_SUPPORTED
140.1195      by default.
140.1196    Added runtime selection of MMX features.
140.1197    Added png_set_strip_error_numbers function and related macros.
140.1198 -version 1.2.0beta2 [May 7, 2001]
140.1199 +
140.1200 +Version 1.2.0beta2 [May 7, 2001]
140.1201    Finished merging 1.2.0beta1 with version 1.0.11
140.1202    Added a check for attempts to read or write PLTE in grayscale PNG datastreams.
140.1203 -version 1.2.0beta3 [May 17, 2001]
140.1204 +
140.1205 +Version 1.2.0beta3 [May 17, 2001]
140.1206    Enabled user memory function by default.
140.1207    Modified png_create_struct so it passes user mem_ptr to user memory allocator.
140.1208    Increased png_mng_features flag from png_byte to png_uint_32.
140.1209    Bumped shared-library (so-number) and dll-number to 3.
140.1210 -version 1.2.0beta4 [June 23, 2001]
140.1211 +
140.1212 +Version 1.2.0beta4 [June 23, 2001]
140.1213    Check for missing profile length field in iCCP chunk and free chunk_data
140.1214       in case of truncated iCCP chunk.
140.1215    Bumped shared-library number to 3 in makefile.sgi and makefile.sggcc
140.1216 @@ -1025,7 +1125,8 @@
140.1217       of png_write_oFFS width and height from png_uint_32 to png_int_32.
140.1218    Updated example.c
140.1219    Revised prototypes for png_debug_malloc and png_debug_free in pngtest.c
140.1220 -version 1.2.0beta5 [August 8, 2001]
140.1221 +
140.1222 +Version 1.2.0beta5 [August 8, 2001]
140.1223    Revised contrib/gregbook
140.1224    Revised makefile.gcmmx
140.1225    Revised pnggccrd.c to conditionally compile some thread-unsafe code only
140.1226 @@ -1036,27 +1137,32 @@
140.1227    Replaced calls to fprintf(stderr,...) with png_warning() in pnggccrd.c
140.1228    Removed restriction that do_invert_mono only operate on 1-bit opaque files
140.1229  
140.1230 -version 1.2.0 [September 1, 2001]
140.1231 +Version 1.2.0 [September 1, 2001]
140.1232    Changed a png_warning() to png_debug() in pnggccrd.c
140.1233    Fixed contrib/gregbook/rpng-x.c, rpng2-x.c to avoid crash with XFreeGC().
140.1234 -version 1.2.1beta1 [October 19, 2001]
140.1235 +
140.1236 +Version 1.2.1beta1 [October 19, 2001]
140.1237    Revised makefile.std in contrib/pngminus
140.1238    Include background_1 in png_struct regardless of gamma support.
140.1239    Revised makefile.netbsd and makefile.macosx, added makefile.darwin.
140.1240    Revised example.c to provide more details about using row_callback().
140.1241 -version 1.2.1beta2 [October 25, 2001]
140.1242 +
140.1243 +Version 1.2.1beta2 [October 25, 2001]
140.1244    Added type cast to each NULL appearing in a function call, except for
140.1245      WINCE functions.
140.1246    Added makefile.so9.
140.1247 -version 1.2.1beta3 [October 27, 2001]
140.1248 +
140.1249 +Version 1.2.1beta3 [October 27, 2001]
140.1250    Removed type casts from all NULLs.
140.1251    Simplified png_create_struct_2().
140.1252 -version 1.2.1beta4 [November 7, 2001]
140.1253 +
140.1254 +Version 1.2.1beta4 [November 7, 2001]
140.1255    Revised png_create_info_struct() and png_creat_struct_2().
140.1256    Added error message if png_write_info() was omitted.
140.1257    Type cast NULLs appearing in function calls when _NO_PROTO or
140.1258      PNG_TYPECAST_NULL is defined.
140.1259 -version 1.2.1rc1 [November 24, 2001]
140.1260 +
140.1261 +Version 1.2.1rc1 [November 24, 2001]
140.1262    Type cast NULLs appearing in function calls except when PNG_NO_TYPECAST_NULL
140.1263      is defined.
140.1264    Changed typecast of "size" argument to png_size_t in pngmem.c calls to
140.1265 @@ -1065,14 +1171,16 @@
140.1266    Updated makefile.sgi to recognize LIBPATH and INCPATH.
140.1267    Updated various makefiles so "make clean" does not remove previous major
140.1268      version of the shared library.
140.1269 -version 1.2.1rc2 [December 4, 2001]
140.1270 +
140.1271 +Version 1.2.1rc2 [December 4, 2001]
140.1272    Always allocate 256-entry internal palette, hist, and trans arrays, to
140.1273      avoid out-of-bounds memory reference caused by invalid PNG datastreams.
140.1274    Added a check for prefix_length > data_length in iCCP chunk handler.
140.1275  
140.1276 -version 1.2.1 [December 7, 2001]
140.1277 +Version 1.2.1 [December 7, 2001]
140.1278    None.
140.1279 -version 1.2.2beta1 [February 22, 2002]
140.1280 +
140.1281 +Version 1.2.2beta1 [February 22, 2002]
140.1282    Fixed a bug with reading the length of iCCP profiles (Larry Reeves).
140.1283    Revised makefile.linux, makefile.gcmmx, and makefile.sgi to generate
140.1284      libpng.a, libpng12.so (not libpng.so.3), and libpng12/png.h
140.1285 @@ -1082,13 +1190,15 @@
140.1286    Revised calls to png_create_read_struct() and png_create_write_struct()
140.1287      for simpler debugging.
140.1288    Revised png_zalloc() so zlib handles errors (uses PNG_FLAG_MALLOC_NULL_MEM_OK)
140.1289 -version 1.2.2beta2 [February 23, 2002]
140.1290 +
140.1291 +Version 1.2.2beta2 [February 23, 2002]
140.1292    Check chunk_length and idat_size for invalid (over PNG_MAX_UINT) lengths.
140.1293    Check for invalid image dimensions in png_get_IHDR.
140.1294    Added missing "fi;" in the install target of the SGI makefiles.
140.1295    Added install-static to all makefiles that make shared libraries.
140.1296    Always do gamma compensation when image is partially transparent.
140.1297 -version 1.2.2beta3 [March 7, 2002]
140.1298 +
140.1299 +Version 1.2.2beta3 [March 7, 2002]
140.1300    Compute background.gray and background_1.gray even when color_type is RGB
140.1301      in case image gets reduced to gray later.
140.1302    Modified shared-library makefiles to install pkgconfig/libpngNN.pc.
140.1303 @@ -1098,12 +1208,14 @@
140.1304    Added install-shared target to all makefiles that make shared libraries.
140.1305    Stopped a double free of palette, hist, and trans when not using free_me.
140.1306    Added makefile.32sunu for Sun Ultra 32 and makefile.64sunu for Sun Ultra 64.
140.1307 -version 1.2.2beta4 [March 8, 2002]
140.1308 +
140.1309 +Version 1.2.2beta4 [March 8, 2002]
140.1310    Compute background.gray and background_1.gray even when color_type is RGB
140.1311      in case image gets reduced to gray later (Jason Summers).
140.1312    Relocated a misplaced /bin/rm in the "install-shared" makefile targets
140.1313    Added PNG_1_0_X macro which can be used to build a 1.0.x-compatible library.
140.1314 -version 1.2.2beta5 [March 26, 2002]
140.1315 +
140.1316 +Version 1.2.2beta5 [March 26, 2002]
140.1317    Added missing PNGAPI to several function definitions.
140.1318    Check for invalid bit_depth or color_type in png_get_IHDR(), and
140.1319      check for missing PLTE or IHDR in png_push_read_chunk() (Matthias Clasen).
140.1320 @@ -1112,33 +1224,45 @@
140.1321    Changed "()" to "{}" in scripts/libpng.pc.in.
140.1322    Revised makefiles to put png.h and pngconf.h only in $prefix/include/libpngNN
140.1323    Revised makefiles to make symlink to libpng.so.NN in addition to libpngNN.so
140.1324 -version 1.2.2beta6 [March 31, 2002]
140.1325 -version 1.0.13beta1 [March 31, 2002]
140.1326 +
140.1327 +Version 1.2.2beta6 [March 31, 2002]
140.1328 +
140.1329 +Version 1.0.13beta1 [March 31, 2002]
140.1330    Prevent png_zalloc() from trying to memset memory that it failed to acquire.
140.1331    Add typecasts of PNG_MAX_UINT in pngset_cHRM_fixed() (Matt Holgate).
140.1332    Ensure that the right function (user or default) is used to free the
140.1333      png_struct after an error in png_create_read_struct_2().
140.1334 -version 1.2.2rc1 [April 7, 2002]
140.1335 -version 1.0.13rc1 [April 7, 2002]
140.1336 +
140.1337 +Version 1.2.2rc1 [April 7, 2002]
140.1338 +
140.1339 +Version 1.0.13rc1 [April 7, 2002]
140.1340    Save the ebx register in pnggccrd.c (Sami Farin)
140.1341    Add "mem_ptr = png_ptr->mem_ptr" in png_destroy_write_struct() (Paul Gardner).
140.1342    Updated makefiles to put headers in include/libpng and remove old include/*.h.
140.1343  
140.1344 -version 1.2.2 [April 15, 2002]
140.1345 -version 1.0.13 [April 15, 2002]
140.1346 +Version 1.2.2 [April 15, 2002]
140.1347 +
140.1348 +Version 1.0.13 [April 15, 2002]
140.1349    Revised description of png_set_filter() in libpng.3/libpng.txt.
140.1350    Revised makefile.netbsd and added makefile.neNNbsd and makefile.freebsd
140.1351 -version 1.0.13patch01 [April 17, 2002]
140.1352 -version 1.2.2patch01 [April 17, 2002]
140.1353 -  Changed ${PNGMAJ}.${PNGVER} bug to ${PNGVER} in makefile.sgi and makefile.sggcc
140.1354 -  Fixed VER -> PNGVER typo in makefile.macosx and added install-static to install
140.1355 +
140.1356 +Version 1.0.13patch01 [April 17, 2002]
140.1357 +
140.1358 +Version 1.2.2patch01 [April 17, 2002]
140.1359 +  Changed ${PNGMAJ}.${PNGVER} bug to ${PNGVER} in makefile.sgi and
140.1360 +    makefile.sggcc
140.1361 +  Fixed VER -> PNGVER typo in makefile.macosx and added install-static to
140.1362 +    install
140.1363    Added install: target to makefile.32sunu and makefile.64sunu
140.1364 -version 1.0.13patch03 [April 18, 2002]
140.1365 -version 1.2.2patch03 [April 18, 2002]
140.1366 +
140.1367 +Version 1.0.13patch03 [April 18, 2002]
140.1368 +
140.1369 +Version 1.2.2patch03 [April 18, 2002]
140.1370    Revised 15 makefiles to link libpng.a to libpngNN.a and the include libpng
140.1371    subdirectory to libpngNN subdirectory without the full pathname.
140.1372    Moved generation of libpng.pc from "install" to "all" in 15 makefiles.
140.1373 -version 1.2.3rc1 [April 28, 2002]
140.1374 +
140.1375 +Version 1.2.3rc1 [April 28, 2002]
140.1376    Added install-man target to 15 makefiles (Dimitri Papadopolous-Orfanos).
140.1377    Added $(DESTDIR) feature to 24 makefiles (Tim Mooney)
140.1378    Fixed bug with $prefix, should be $(prefix) in makefile.hpux.
140.1379 @@ -1150,70 +1274,83 @@
140.1380      to put one in their application.
140.1381    Restored png_zalloc() and png_zfree() prototypes to version 1.2.1 and
140.1382      removed them from module definition files.
140.1383 -version 1.2.3rc2 [May 1, 2002]
140.1384 +
140.1385 +Version 1.2.3rc2 [May 1, 2002]
140.1386    Fixed bug in reporting number of channels in pngget.c and pngset.c,
140.1387      that was introduced in version 1.2.2beta5.
140.1388    Exported png_zalloc(), png_zfree(), png_default_read(), png_default_write(),
140.1389      png_default_flush(), and png_push_fill_buffer() and included them in
140.1390      module definition files.
140.1391    Added "libpng.pc" dependency to the "install-shared" target in 15 makefiles.
140.1392 -version 1.2.3rc3 [May 1, 2002]
140.1393 +
140.1394 +Version 1.2.3rc3 [May 1, 2002]
140.1395    Revised prototype for png_default_flush()
140.1396    Remove old libpng.pc and libpngNN.pc before installing new ones.
140.1397 -version 1.2.3rc4 [May 2, 2002]
140.1398 +
140.1399 +Version 1.2.3rc4 [May 2, 2002]
140.1400    Typos in *.def files (png_default_read|write -> png_default_read|write_data)
140.1401    In makefiles, changed rm libpng.NN.pc to rm libpngNN.pc
140.1402 -  Added libpng-config and libpngNN-config and modified makefiles to install them.
140.1403 +  Added libpng-config and libpngNN-config and modified makefiles to install
140.1404 +    them.
140.1405    Changed $(MANPATH) to $(DESTDIR)$(MANPATH) in makefiles
140.1406    Added "Win32 DLL VB" configuration to projects/msvc/libpng.dsp
140.1407 -version 1.2.3rc5 [May 11, 2002]
140.1408 +
140.1409 +Version 1.2.3rc5 [May 11, 2002]
140.1410    Changed "error" and "message" in prototypes to "error_message" and
140.1411      "warning_message" to avoid namespace conflict.
140.1412    Revised 15 makefiles to build libpng-config from libpng-config-*.in
140.1413    Once more restored png_zalloc and png_zfree to regular nonexported form.
140.1414    Restored png_default_read|write_data, png_default_flush, png_read_fill_buffer
140.1415 -    to nonexported form, but with PNGAPI, and removed them from module def files.
140.1416 -version 1.2.3rc6 [May 14, 2002]
140.1417 +    to nonexported form, but with PNGAPI, and removed them from module def
140.1418 +    files.
140.1419 +
140.1420 +Version 1.2.3rc6 [May 14, 2002]
140.1421    Removed "PNGAPI" from png_zalloc() and png_zfree() in png.c
140.1422    Changed "Gz" to "Gd" in projects/msvc/libpng.dsp and zlib.dsp.
140.1423    Removed leftover libpng-config "sed" script from four makefiles.
140.1424    Revised libpng-config creating script in 16 makefiles.
140.1425  
140.1426 -version 1.2.3 [May 22, 2002]
140.1427 +Version 1.2.3 [May 22, 2002]
140.1428    Revised libpng-config target in makefile.cygwin.
140.1429    Removed description of png_set_mem_fn() from documentation.
140.1430    Revised makefile.freebsd.
140.1431    Minor cosmetic changes to 15 makefiles, e.g., $(DI) = $(DESTDIR)/$(INCDIR).
140.1432    Revised projects/msvc/README.txt
140.1433    Changed -lpng to -lpngNN in LDFLAGS in several makefiles.
140.1434 -version 1.2.4beta1 [May 24, 2002]
140.1435 +
140.1436 +Version 1.2.4beta1 [May 24, 2002]
140.1437    Added libpng.pc and libpng-config to "all:" target in 16 makefiles.
140.1438    Fixed bug in 16 makefiles: $(DESTDIR)/$(LIBPATH) to $(DESTDIR)$(LIBPATH)
140.1439    Added missing "\" before closing double quote in makefile.gcmmx.
140.1440    Plugged various memory leaks; added png_malloc_warn() and png_set_text_2()
140.1441      functions.
140.1442 -version 1.2.4beta2 [June 25, 2002]
140.1443 +
140.1444 +Version 1.2.4beta2 [June 25, 2002]
140.1445    Plugged memory leak of png_ptr->current_text (Matt Holgate).
140.1446    Check for buffer overflow before reading CRC in pngpread.c (Warwick Allison)
140.1447    Added -soname to the loader flags in makefile.dec, makefile.sgi, and
140.1448      makefile.sggcc.
140.1449    Added "test-installed" target to makefile.linux, makefile.gcmmx,
140.1450      makefile.sgi, and makefile.sggcc.
140.1451 -version 1.2.4beta3 [June 28, 2002]
140.1452 +
140.1453 +Version 1.2.4beta3 [June 28, 2002]
140.1454    Plugged memory leak of row_buf in pngtest.c when there is a png_error().
140.1455    Detect buffer overflow in pngpread.c when IDAT is corrupted with extra data.
140.1456    Added "test-installed" target to makefile.32sunu, makefile.64sunu,
140.1457 -    makefile.beos, makefile.darwin, makefile.dec, makefile.macosx, 
140.1458 +    makefile.beos, makefile.darwin, makefile.dec, makefile.macosx,
140.1459      makefile.solaris, makefile.hpux, makefile.hpgcc, and makefile.so9.
140.1460 -version 1.2.4rc1 and 1.0.14rc1 [July 2, 2002]
140.1461 +
140.1462 +Version 1.2.4rc1 and 1.0.14rc1 [July 2, 2002]
140.1463    Added "test-installed" target to makefile.cygwin and makefile.sco.
140.1464    Revised pnggccrd.c to be able to back out version 1.0.x via PNG_1_0_X macro.
140.1465  
140.1466 -version 1.2.4 and 1.0.14 [July 8, 2002]
140.1467 +Version 1.2.4 and 1.0.14 [July 8, 2002]
140.1468    Changed png_warning() to png_error() when width is too large to process.
140.1469 -version 1.2.4patch01 [July 20, 2002]
140.1470 +
140.1471 +Version 1.2.4patch01 [July 20, 2002]
140.1472    Revised makefile.cygwin to use DLL number 12 instead of 13.
140.1473 -version 1.2.5beta1 [August 6, 2002]
140.1474 +
140.1475 +Version 1.2.5beta1 [August 6, 2002]
140.1476    Added code to contrib/gregbook/readpng2.c to ignore unused chunks.
140.1477    Replaced toucan.png in contrib/gregbook (it has been corrupt since 1.0.11)
140.1478    Removed some stray *.o files from contrib/gregbook.
140.1479 @@ -1222,36 +1359,43 @@
140.1480    Prevent png_ptr->pass from exceeding 7 in png_push_finish_row().
140.1481    Updated makefile.hpgcc
140.1482    Updated png.c and pnggccrd.c handling of return from png_mmx_support()
140.1483 -version 1.2.5beta2 [August 15, 2002]
140.1484 +
140.1485 +Version 1.2.5beta2 [August 15, 2002]
140.1486    Only issue png_warning() about "Too much data" in pngpread.c when avail_in
140.1487      is nonzero.
140.1488    Updated makefiles to install a separate libpng.so.3 with its own rpath.
140.1489 -version 1.2.5rc1 and 1.0.15rc1 [August 24, 2002]
140.1490 +
140.1491 +Version 1.2.5rc1 and 1.0.15rc1 [August 24, 2002]
140.1492    Revised makefiles to not remove previous minor versions of shared libraries.
140.1493 -version 1.2.5rc2 and 1.0.15rc2 [September 16, 2002]
140.1494 +
140.1495 +Version 1.2.5rc2 and 1.0.15rc2 [September 16, 2002]
140.1496    Revised 13 makefiles to remove "-lz" and "-L$(ZLIBLIB)", etc., from shared
140.1497      library loader directive.
140.1498    Added missing "$OBJSDLL" line to makefile.gcmmx.
140.1499    Added missing "; fi" to makefile.32sunu.
140.1500 -version 1.2.5rc3 and 1.0.15rc3 [September 18, 2002]
140.1501 +
140.1502 +Version 1.2.5rc3 and 1.0.15rc3 [September 18, 2002]
140.1503    Revised libpng-config script.
140.1504  
140.1505 -version 1.2.5 and 1.0.15 [October 3, 2002]
140.1506 +Version 1.2.5 and 1.0.15 [October 3, 2002]
140.1507    Revised makefile.macosx, makefile.darwin, makefile.hpgcc, and makefile.hpux,
140.1508      and makefile.aix.
140.1509    Relocated two misplaced PNGAPI lines in pngtest.c
140.1510 -version 1.2.6beta1 [October 22, 2002]
140.1511 +
140.1512 +Version 1.2.6beta1 [October 22, 2002]
140.1513    Commented out warning about uninitialized mmx_support in pnggccrd.c.
140.1514    Changed "IBMCPP__" flag to "__IBMCPP__" in pngconf.h.
140.1515    Relocated two more misplaced PNGAPI lines in pngtest.c
140.1516    Fixed memory overrun bug in png_do_read_filler() with 16-bit datastreams,
140.1517      introduced in version 1.0.2.
140.1518    Revised makefile.macosx, makefile.dec, makefile.aix, and makefile.32sunu.
140.1519 -version 1.2.6beta2 [November 1, 2002]
140.1520 +
140.1521 +Version 1.2.6beta2 [November 1, 2002]
140.1522    Added libpng-config "--ldopts" output.
140.1523    Added "AR=ar" and "ARFLAGS=rc" and changed "ar rc" to "$(AR) $(ARFLAGS)"
140.1524      in makefiles.
140.1525 -version 1.2.6beta3 [July 18, 2004]
140.1526 +
140.1527 +Version 1.2.6beta3 [July 18, 2004]
140.1528    Reverted makefile changes from version 1.2.6beta2 and some of the changes
140.1529      from version 1.2.6beta1; these will be postponed until version 1.2.7.
140.1530      Version 1.2.6 is going to be a simple bugfix release.
140.1531 @@ -1304,7 +1448,8 @@
140.1532    Updated contrib/visupng/VisualPng.dsp (Cosmin).
140.1533    Updated contrib/visupng/cexcept.h to version 2.0.0 (Cosmin).
140.1534    Added a separate distribution with "configure" and supporting files (Junichi).
140.1535 -version 1.2.6beta4 [July 28, 2004]
140.1536 +
140.1537 +Version 1.2.6beta4 [July 28, 2004]
140.1538    Added user ability to change png_size_t via a PNG_SIZE_T macro.
140.1539    Added png_sizeof() and png_convert_size() functions.
140.1540    Added PNG_SIZE_MAX (maximum value of a png_size_t variable.
140.1541 @@ -1324,9 +1469,10 @@
140.1542    Added PNG_NO_SEQUENTIAL_READ_SUPPORTED macro to conditionally remove
140.1543      sequential read support.
140.1544    Added some "#if PNG_WRITE_SUPPORTED" blocks.
140.1545 -  #ifdef'ed out some redundancy in png_malloc_default().
140.1546 +  Added #ifdef to remove some redundancy in png_malloc_default().
140.1547    Use png_malloc instead of png_zalloc to allocate the pallete.
140.1548 -version 1.0.16rc1 and 1.2.6rc1 [August 4, 2004]
140.1549 +
140.1550 +Version 1.0.16rc1 and 1.2.6rc1 [August 4, 2004]
140.1551    Fixed buffer overflow vulnerability in png_handle_tRNS()
140.1552    Fixed integer arithmetic overflow vulnerability in png_read_png().
140.1553    Fixed some harmless bugs in png_handle_sBIT, etc, that would cause
140.1554 @@ -1341,7 +1487,8 @@
140.1555    Fixed wrong cast of returns from png_get_user_width|height_max().
140.1556    Changed some "keep the compiler happy" from empty statements to returns,
140.1557    Revised libpng.txt to remove 1.2.x stuff from the 1.0.x distribution
140.1558 -version 1.0.16rc2 and 1.2.6rc2 [August 7, 2004]
140.1559 +
140.1560 +Version 1.0.16rc2 and 1.2.6rc2 [August 7, 2004]
140.1561    Revised makefile.darwin and makefile.solaris.  Removed makefile.macosx.
140.1562    Revised pngtest's png_debug_malloc() to use png_malloc() instead of
140.1563      png_malloc_default() which is not supposed to be exported.
140.1564 @@ -1355,90 +1502,106 @@
140.1565    Changed "HANDLE_CHUNK_*" to "PNG_HANDLE_CHUNK_*" (Cosmin)
140.1566    Added "-@/bin/rm -f $(DL)/$(LIBNAME).so.$(PNGMAJ)" to 15 *NIX makefiles.
140.1567    Added code to update the row_info->colortype in png_do_read_filler() (MSB).
140.1568 -version 1.0.16rc3 and 1.2.6rc3 [August 9, 2004]
140.1569 +
140.1570 +Version 1.0.16rc3 and 1.2.6rc3 [August 9, 2004]
140.1571    Eliminated use of "abs()" in testing cHRM and gAMA values, to avoid
140.1572      trouble with some 64-bit compilers.  Created PNG_OUT_OF_RANGE() macro.
140.1573    Revised documentation of png_set_keep_unknown_chunks().
140.1574    Check handle_as_unknown status in pngpread.c, as in pngread.c previously.
140.1575    Moved  "PNG_HANDLE_CHUNK_*" macros out of PNG_INTERNAL section of png.h
140.1576    Added "rim" definitions for CONST4 and CONST6 in pnggccrd.c
140.1577 -version 1.0.16rc4 and 1.2.6rc4 [August 10, 2004]
140.1578 +
140.1579 +Version 1.0.16rc4 and 1.2.6rc4 [August 10, 2004]
140.1580    Fixed mistake in pngtest.c introduced in 1.2.6rc2 (declaration of
140.1581      "pinfo" was out of place).
140.1582 -version 1.0.16rc5 and 1.2.6rc5 [August 10, 2004]
140.1583 +
140.1584 +Version 1.0.16rc5 and 1.2.6rc5 [August 10, 2004]
140.1585    Moved  "PNG_HANDLE_CHUNK_*" macros out of PNG_ASSEMBLER_CODE_SUPPORTED
140.1586       section of png.h where they were inadvertently placed in version rc3.
140.1587  
140.1588 -version 1.2.6 and 1.0.16 [August 15, 2004]
140.1589 +Version 1.2.6 and 1.0.16 [August 15, 2004]
140.1590    Revised pngtest so memory allocation testing is only done when PNG_DEBUG==1.
140.1591 -version 1.2.7beta1 [August 26, 2004]
140.1592 +
140.1593 +Version 1.2.7beta1 [August 26, 2004]
140.1594    Removed unused pngasmrd.h file.
140.1595    Removed references to uu.net for archived files.  Added references to
140.1596      PNG Spec (second edition) and the PNG ISO/IEC Standard.
140.1597    Added "test-dd" target in 15 makefiles, to run pngtest in DESTDIR.
140.1598    Fixed bug with "optimized window size" in the IDAT datastream, that
140.1599      causes libpng to write PNG files with incorrect zlib header bytes.
140.1600 -version 1.2.7beta2 [August 28, 2004]
140.1601 +
140.1602 +Version 1.2.7beta2 [August 28, 2004]
140.1603    Fixed bug with sCAL chunk and big-endian machines (David Munro).
140.1604    Undid new code added in 1.2.6rc2 to update the color_type in
140.1605      png_set_filler().
140.1606    Added png_set_add_alpha() that updates color type.
140.1607 -version 1.0.17rc1 and 1.2.7rc1 [September 4, 2004]
140.1608 +
140.1609 +Version 1.0.17rc1 and 1.2.7rc1 [September 4, 2004]
140.1610    Revised png_set_strip_filler() to not remove alpha if color_type has alpha.
140.1611  
140.1612 -version 1.2.7 and 1.0.17 [September 12, 2004]
140.1613 +Version 1.2.7 and 1.0.17 [September 12, 2004]
140.1614    Added makefile.hp64
140.1615    Changed projects/msvc/png32ms.def to scripts/png32ms.def in makefile.cygwin
140.1616 -version 1.2.8beta1 [November 1, 2004]
140.1617 +
140.1618 +Version 1.2.8beta1 [November 1, 2004]
140.1619    Fixed bug in png_text_compress() that would fail to complete a large block.
140.1620    Fixed bug, introduced in libpng-1.2.7, that overruns a buffer during
140.1621      strip alpha operation in png_do_strip_filler().
140.1622    Added PNG_1_2_X definition in pngconf.h
140.1623 -  #ifdef out png_info_init in png.c and png_read_init in pngread.c (as of 1.3.0)
140.1624 -version 1.2.8beta2 [November 2, 2004]
140.1625 +  Use #ifdef to comment out png_info_init in png.c and png_read_init in
140.1626 +    pngread.c (as of 1.3.0)
140.1627 +
140.1628 +Version 1.2.8beta2 [November 2, 2004]
140.1629    Reduce color_type to a nonalpha type after strip alpha operation in
140.1630      png_do_strip_filler().
140.1631 -version 1.2.8beta3 [November 3, 2004]
140.1632 +
140.1633 +Version 1.2.8beta3 [November 3, 2004]
140.1634    Revised definitions of PNG_MAX_UINT_32, PNG_MAX_SIZE, and PNG_MAXSUM
140.1635 -version 1.2.8beta4 [November 12, 2004]
140.1636 +
140.1637 +Version 1.2.8beta4 [November 12, 2004]
140.1638    Fixed (again) definition of PNG_LIBPNG_VER_DLLNUM in png.h (Cosmin).
140.1639    Added PNG_LIBPNG_BUILD_PRIVATE in png.h (Cosmin).
140.1640    Set png_ptr->zstream.data_type to Z_BINARY, to avoid unnecessary detection
140.1641      of data type in deflate (Cosmin).
140.1642    Deprecated but continue to support SPECIALBUILD and PRIVATEBUILD in favor of
140.1643      PNG_LIBPNG_BUILD_SPECIAL_STRING and PNG_LIBPNG_BUILD_PRIVATE_STRING.
140.1644 -version 1.2.8beta5 [November 20, 2004]
140.1645 +
140.1646 +Version 1.2.8beta5 [November 20, 2004]
140.1647    Use png_ptr->flags instead of png_ptr->transformations to pass
140.1648      PNG_STRIP_ALPHA info to png_do_strip_filler(), to preserve ABI
140.1649      compatibility.
140.1650 -  Revised handling of SPECIALBUILD, PRIVATEBUILD, 
140.1651 +  Revised handling of SPECIALBUILD, PRIVATEBUILD,
140.1652      PNG_LIBPNG_BUILD_SPECIAL_STRING and PNG_LIBPNG_BUILD_PRIVATE_STRING.
140.1653 -version 1.2.8rc1 [November 24, 2004]
140.1654 +
140.1655 +Version 1.2.8rc1 [November 24, 2004]
140.1656    Moved handling of BUILD macros from pngconf.h to png.h
140.1657    Added definition of PNG_LIBPNG_BASE_TYPE in png.h, inadvertently
140.1658      omitted from beta5.
140.1659    Revised scripts/pngw32.rc
140.1660    Despammed mailing addresses by masking "@" with "at".
140.1661    Inadvertently installed a supposedly faster test version of pngrutil.c
140.1662 -version 1.2.8rc2 [November 26, 2004]
140.1663 +
140.1664 +Version 1.2.8rc2 [November 26, 2004]
140.1665    Added two missing "\" in png.h
140.1666    Change tests in pngread.c and pngpread.c to
140.1667      if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
140.1668         png_do_read_transformations(png_ptr);
140.1669 -version 1.2.8rc3 [November 28, 2004]
140.1670 +
140.1671 +Version 1.2.8rc3 [November 28, 2004]
140.1672    Reverted pngrutil.c to version libpng-1.2.8beta5.
140.1673    Added scripts/makefile.elf with supporting code in pngconf.h for symbol
140.1674      versioning (John Bowler).
140.1675 -version 1.2.8rc4 [November 29, 2004]
140.1676 +
140.1677 +Version 1.2.8rc4 [November 29, 2004]
140.1678    Added projects/visualc7 (Simon-pierre).
140.1679 -version 1.2.8rc5 [November 29, 2004]
140.1680 +
140.1681 +Version 1.2.8rc5 [November 29, 2004]
140.1682    Fixed new typo in scripts/pngw32.rc
140.1683  
140.1684 -version 1.2.8 [December 3, 2004]
140.1685 +Version 1.2.8 [December 3, 2004]
140.1686    Removed projects/visualc7, added projects/visualc71.
140.1687  
140.1688 -version 1.2.9beta1 [February 21, 2006]
140.1689 -
140.1690 +Version 1.2.9beta1 [February 21, 2006]
140.1691    Initialized some structure members in pngwutil.c to avoid gcc-4.0.0 complaints
140.1692    Revised man page and libpng.txt to make it clear that one should not call
140.1693      png_read_end or png_write_end after png_read_png or png_write_png.
140.1694 @@ -1460,8 +1623,7 @@
140.1695    Fixed scripts/makefile.cygwin (Christian Biesinger, Cosmin).
140.1696    Default iTXt support was inadvertently enabled.
140.1697  
140.1698 -version 1.2.9beta2 [February 21, 2006]
140.1699 -
140.1700 +Version 1.2.9beta2 [February 21, 2006]
140.1701    Check for png_rgb_to_gray and png_gray_to_rgb read transformations before
140.1702      checking for png_read_dither in pngrtran.c
140.1703    Revised checking of chromaticity limits to accommodate extended RGB
140.1704 @@ -1474,8 +1636,7 @@
140.1705    Eliminated distributions without the "configure" script.
140.1706    Updated INSTALL instructions.
140.1707  
140.1708 -version 1.2.9beta3 [February 24, 2006]
140.1709 -
140.1710 +Version 1.2.9beta3 [February 24, 2006]
140.1711    Fixed CRCRLF line endings in contrib/visupng/VisualPng.dsp
140.1712    Made libpng.pc respect EXEC_PREFIX (D. P. Kreil, J. Bowler)
140.1713    Removed reference to pngasmrd.h from Makefile.am
140.1714 @@ -1484,8 +1645,7 @@
140.1715    Renamed ANNOUNCE to NEWS.
140.1716    Created AUTHORS file.
140.1717  
140.1718 -version 1.2.9beta4 [March 3, 2006]
140.1719 -
140.1720 +Version 1.2.9beta4 [March 3, 2006]
140.1721    Changed definition of PKGCONFIG from $prefix/lib to $libdir in configure.ac
140.1722    Reverted to filenames LICENSE and ANNOUNCE; removed AUTHORS and COPYING.
140.1723    Removed newline from the end of some error and warning messages.
140.1724 @@ -1496,17 +1656,17 @@
140.1725    Added "OS2" to list of systems that don't need underscores, in pnggccrd.c
140.1726    Removed libpng version and date from *.c files.
140.1727  
140.1728 -version 1.2.9beta5 [March 4, 2006]
140.1729 +Version 1.2.9beta5 [March 4, 2006]
140.1730    Removed trailing blanks from source files.
140.1731    Put version and date of latest change in each source file, and changed
140.1732      copyright year accordingly.
140.1733 -  More cleanup of configure.ac, Makefile.ac, and associated scripts.
140.1734 +  More cleanup of configure.ac, Makefile.am, and associated scripts.
140.1735    Restored scripts/makefile.elf which was inadvertently deleted.
140.1736  
140.1737 -version 1.2.9beta6 [March 6, 2006]
140.1738 -  Fixed typo (18) in configuration files.
140.1739 -
140.1740 -version 1.2.9beta7 [March 7, 2006]
140.1741 +Version 1.2.9beta6 [March 6, 2006]
140.1742 +  Fixed typo (RELEASE) in configuration files.
140.1743 +
140.1744 +Version 1.2.9beta7 [March 7, 2006]
140.1745    Removed libpng.vers and libpng.sym from libpng12_la_SOURCES in Makefile.am
140.1746    Fixed inconsistent #ifdef's around png_sig_bytes() and png_set_sCAL_s()
140.1747      in png.h.
140.1748 @@ -1514,7 +1674,7 @@
140.1749    Made cosmetic changes to some makefiles, adding LN_SF and other macros.
140.1750    Made some makefiles accept "exec_prefix".
140.1751  
140.1752 -version 1.2.9beta8 [March 9, 2006]
140.1753 +Version 1.2.9beta8 [March 9, 2006]
140.1754    Fixed some "#if defined (..." which should be "#if defined(..."
140.1755      Bug introduced in libpng-1.2.8.
140.1756    Fixed inconsistency in definition of png_default_read_data()
140.1757 @@ -1525,82 +1685,82 @@
140.1758    Added png_set_expand_gray_1_2_4_to_8() and deprecated
140.1759      png_set_gray_1_2_4_to_8() which also expands tRNS to alpha.
140.1760  
140.1761 -version 1.2.9beta9 [March 10, 2006]
140.1762 +Version 1.2.9beta9 [March 10, 2006]
140.1763    Include "config.h" in pngconf.h when available.
140.1764    Added some checks for NULL png_ptr or NULL info_ptr (timeless)
140.1765  
140.1766 -version 1.2.9beta10 [March 20, 2006]
140.1767 +Version 1.2.9beta10 [March 20, 2006]
140.1768    Removed extra CR from contrib/visualpng/VisualPng.dsw (Cosmin)
140.1769    Made pnggccrd.c PIC-compliant (Christian Aichinger).
140.1770    Added makefile.mingw (Wolfgang Glas).
140.1771    Revised pngconf.h MMX checking.
140.1772  
140.1773 -version 1.2.9beta11 [March 22, 2006]
140.1774 +Version 1.2.9beta11 [March 22, 2006]
140.1775    Fixed out-of-order declaration in pngwrite.c that was introduced in beta9
140.1776    Simplified some makefiles by using LIBSO, LIBSOMAJ, and LIBSOVER macros.
140.1777  
140.1778 -version 1.2.9rc1 [March 31, 2006]
140.1779 +Version 1.2.9rc1 [March 31, 2006]
140.1780    Defined PNG_USER_PRIVATEBUILD when including "pngusr.h" (Cosmin).
140.1781    Removed nonsensical assertion check from pngtest.c (Cosmin).
140.1782  
140.1783 -version 1.2.9 [April 14, 2006]
140.1784 +Version 1.2.9 [April 14, 2006]
140.1785    Revised makefile.beos and added "none" selector in ltmain.sh
140.1786  
140.1787 -version 1.2.10beta1 [April 15, 2006]
140.1788 +Version 1.2.10beta1 [April 15, 2006]
140.1789    Renamed "config.h" to "png_conf.h" and revised Makefile.am to add
140.1790      -DPNG_BUILDING_LIBPNG to compile directive, and modified pngconf.h
140.1791      to include png_conf.h only when PNG_BUILDING_LIBPNG is defined.
140.1792  
140.1793 -version 1.2.10beta2 [April 15, 2006]
140.1794 +Version 1.2.10beta2 [April 15, 2006]
140.1795    Manually updated Makefile.in and configure.  Changed png_conf.h.in
140.1796      back to config.h.
140.1797  
140.1798 -version 1.2.10beta3 [April 15, 2006]
140.1799 +Version 1.2.10beta3 [April 15, 2006]
140.1800    Change png_conf.h back to config.h in pngconf.h.
140.1801  
140.1802 -version 1.2.10beta4 [April 16, 2006]
140.1803 +Version 1.2.10beta4 [April 16, 2006]
140.1804    Change PNG_BUILDING_LIBPNG to PNG_CONFIGURE_LIBPNG in config/Makefile*.
140.1805  
140.1806 -version 1.2.10beta5 [April 16, 2006]
140.1807 +Version 1.2.10beta5 [April 16, 2006]
140.1808    Added a configure check for compiling assembler code in pnggccrd.c
140.1809  
140.1810 -version 1.2.10beta6 [April 17, 2006]
140.1811 +Version 1.2.10beta6 [April 17, 2006]
140.1812    Revised the configure check for pnggccrd.c
140.1813    Moved -DPNG_CONFIGURE_LIBPNG into @LIBPNG_DEFINES@
140.1814    Added @LIBPNG_DEFINES@ to arguments when building libpng.sym
140.1815  
140.1816 -version 1.2.10beta7 [April 18, 2006]
140.1817 +Version 1.2.10beta7 [April 18, 2006]
140.1818    Change "exec_prefix=$prefix" to "exec_prefix=$(prefix)" in makefiles.
140.1819  
140.1820 -version 1.2.10rc1 [April 19, 2006]
140.1821 +Version 1.2.10rc1 [April 19, 2006]
140.1822    Ensure pngconf.h doesn't define both PNG_USE_PNGGCCRD and PNG_USE_PNGVCRD
140.1823    Fixed "LN_FS" typo in makefile.sco and makefile.solaris.
140.1824  
140.1825 -version 1.2.10rc2 [April 20, 2006]
140.1826 +Version 1.2.10rc2 [April 20, 2006]
140.1827    Added a backslash between -DPNG_CONFIGURE_LIBPNG and -DPNG_NO_ASSEMBLER_CODE
140.1828     in configure.ac and configure
140.1829    Made the configure warning about versioned symbols less arrogant.
140.1830  
140.1831 -version 1.2.10rc3 [April 21, 2006]
140.1832 +Version 1.2.10rc3 [April 21, 2006]
140.1833    Added a note in libpng.txt that png_set_sig_bytes(8) can be used when
140.1834      writing an embedded PNG without the 8-byte signature.
140.1835    Revised makefiles and configure to avoid making links to libpng.so.*
140.1836  
140.1837 -version 1.2.10 [April 23, 2006]
140.1838 +Version 1.2.10 [April 23, 2006]
140.1839    Reverted configure to "rc2" state.
140.1840  
140.1841 -version 1.2.11beta1 [May 31, 2006]
140.1842 +Version 1.2.11beta1 [May 31, 2006]
140.1843    scripts/libpng.pc.in contained "configure" style version info and would
140.1844      not work with makefiles.
140.1845    The shared-library makefiles were linking to libpng.so.0 instead of
140.1846      libpng.so.3 compatibility as the library.
140.1847  
140.1848 -version 1.2.11beta2 [June 2, 2006]
140.1849 +Version 1.2.11beta2 [June 2, 2006]
140.1850    Increased sprintf buffer from 50 to 52 chars in pngrutil.c to avoid
140.1851      buffer overflow.
140.1852    Fixed bug in example.c (png_set_palette_rgb -> png_set_palette_to_rgb)
140.1853  
140.1854 -version 1.2.11beta3 [June 5, 2006]
140.1855 +Version 1.2.11beta3 [June 5, 2006]
140.1856    Prepended "#! /bin/sh" to ltmail.sh and contrib/pngminus/*.sh (Cosmin).
140.1857    Removed the accidental leftover Makefile.in~ (Cosmin).
140.1858    Avoided potential buffer overflow and optimized buffer in
140.1859 @@ -1608,116 +1768,116 @@
140.1860    Removed the include directories and libraries from CFLAGS and LDFLAGS
140.1861      in scripts/makefile.gcc (Nelson A. de Oliveira, Cosmin).
140.1862  
140.1863 -version 1.2.11beta4 [June 6, 2006]
140.1864 +Version 1.2.11beta4 [June 6, 2006]
140.1865    Allow zero-length IDAT chunks after the entire zlib datastream, but not
140.1866      after another intervening chunk type.
140.1867  
140.1868 -version 1.0.19rc1, 1.2.11rc1 [June 13, 2006]
140.1869 +Version 1.0.19rc1, 1.2.11rc1 [June 13, 2006]
140.1870    Deleted extraneous square brackets from [config.h] in configure.ac
140.1871  
140.1872 -version 1.0.19rc2, 1.2.11rc2 [June 14, 2006]
140.1873 +Version 1.0.19rc2, 1.2.11rc2 [June 14, 2006]
140.1874    Added prototypes for PNG_INCH_CONVERSIONS functions to png.h
140.1875    Revised INSTALL and autogen.sh
140.1876    Fixed typo in several makefiles (-W1 should be -Wl)
140.1877    Added typedef for png_int_32 and png_uint_32 on 64-bit systems.
140.1878  
140.1879 -version 1.0.19rc3, 1.2.11rc3 [June 15, 2006]
140.1880 +Version 1.0.19rc3, 1.2.11rc3 [June 15, 2006]
140.1881    Removed the new typedefs for 64-bit systems (delay until version 1.4.0)
140.1882    Added one zero element to png_gamma_shift[] array in pngrtran.c to avoid
140.1883      reading out of bounds.
140.1884  
140.1885 -version 1.0.19rc4, 1.2.11rc4 [June 15, 2006]
140.1886 +Version 1.0.19rc4, 1.2.11rc4 [June 15, 2006]
140.1887    Really removed the new typedefs for 64-bit systems.
140.1888  
140.1889 -version 1.0.19rc5, 1.2.11rc5 [June 22, 2006]
140.1890 +Version 1.0.19rc5, 1.2.11rc5 [June 22, 2006]
140.1891    Removed png_sig_bytes entry from scripts/pngw32.def
140.1892  
140.1893 -version 1.0.19, 1.2.11 [June 26, 2006]
140.1894 +Version 1.0.19, 1.2.11 [June 26, 2006]
140.1895    None.
140.1896  
140.1897 -version 1.0.20, 1.2.12 [June 27, 2006]
140.1898 +Version 1.0.20, 1.2.12 [June 27, 2006]
140.1899    Really increased sprintf buffer from 50 to 52 chars in pngrutil.c to avoid
140.1900      buffer overflow.
140.1901  
140.1902 -version 1.2.13beta1 [October 2, 2006]
140.1903 +Version 1.2.13beta1 [October 2, 2006]
140.1904    Removed AC_FUNC_MALLOC from configure.ac
140.1905    Work around Intel-Mac compiler bug by setting PNG_NO_MMX_CODE in pngconf.h
140.1906    Change "logical" to "bitwise" throughout documentation.
140.1907    Detect and fix attempt to write wrong iCCP profile length.
140.1908  
140.1909 -version 1.0.21, 1.2.13 [November 14, 2006]
140.1910 +Version 1.0.21, 1.2.13 [November 14, 2006]
140.1911    Fix potential buffer overflow in sPLT chunk handler.
140.1912    Fix Makefile.am to not try to link to noexistent files.
140.1913    Check all exported functions for NULL png_ptr.
140.1914  
140.1915 -version 1.2.14beta1 [November 17, 2006]
140.1916 +Version 1.2.14beta1 [November 17, 2006]
140.1917    Relocated three misplaced tests for NULL png_ptr.
140.1918    Built Makefile.in with automake-1.9.6 instead of 1.9.2.
140.1919    Build configure with autoconf-2.60 instead of 2.59
140.1920  
140.1921 -version 1.2.14beta2 [November 17, 2006]
140.1922 +Version 1.2.14beta2 [November 17, 2006]
140.1923    Added some typecasts in png_zalloc().
140.1924  
140.1925 -version 1.2.14rc1 [November 20, 2006]
140.1926 +Version 1.2.14rc1 [November 20, 2006]
140.1927    Changed "strtod" to "png_strtod" in pngrutil.c
140.1928  
140.1929 -version 1.0.22, 1.2.14    [November 27, 2006]
140.1930 +Version 1.0.22, 1.2.14    [November 27, 2006]
140.1931    Added missing "$(srcdir)" in Makefile.am and Makefile.in
140.1932  
140.1933 -version 1.2.15beta1 [December 3, 2006]
140.1934 +Version 1.2.15beta1 [December 3, 2006]
140.1935    Generated configure with autoconf-2.61 instead of 2.60
140.1936    Revised configure.ac to update libpng.pc and libpng-config.
140.1937  
140.1938 -version 1.2.15beta2 [December 3, 2006]
140.1939 +Version 1.2.15beta2 [December 3, 2006]
140.1940    Always export MMX asm functions, just stubs if not building pnggccrd.c
140.1941  
140.1942 -version 1.2.15beta3 [December 4, 2006]
140.1943 +Version 1.2.15beta3 [December 4, 2006]
140.1944    Add "png_bytep" typecast to profile while calculating length in pngwutil.c
140.1945  
140.1946 -version 1.2.15beta4 [December 7, 2006]
140.1947 +Version 1.2.15beta4 [December 7, 2006]
140.1948    Added scripts/CMakeLists.txt
140.1949    Changed PNG_NO_ASSEMBLER_CODE to PNG_NO_MMX_CODE in scripts, like 1.4.0beta
140.1950  
140.1951 -version 1.2.15beta5 [December 7, 2006]
140.1952 +Version 1.2.15beta5 [December 7, 2006]
140.1953    Changed some instances of PNG_ASSEMBLER_* to PNG_MMX_* in pnggccrd.c
140.1954    Revised scripts/CMakeLists.txt
140.1955  
140.1956 -version 1.2.15beta6 [December 13, 2006]
140.1957 +Version 1.2.15beta6 [December 13, 2006]
140.1958    Revised scripts/CMakeLists.txt and configure.ac
140.1959  
140.1960 -version 1.2.15rc1 [December 18, 2006]
140.1961 +Version 1.2.15rc1 [December 18, 2006]
140.1962    Revised scripts/CMakeLists.txt
140.1963  
140.1964 -version 1.2.15rc2 [December 21, 2006]
140.1965 +Version 1.2.15rc2 [December 21, 2006]
140.1966    Added conditional #undef jmpbuf in pngtest.c to undo #define in AIX headers.
140.1967    Added scripts/makefile.nommx
140.1968  
140.1969 -version 1.2.15rc3 [December 25, 2006]
140.1970 -  Fixed shared library numbering error that was intruduced in 1.2.15beta6.
140.1971 -
140.1972 -version 1.2.15rc4 [December 27, 2006]
140.1973 +Version 1.2.15rc3 [December 25, 2006]
140.1974 +  Fixed shared library numbering error that was introduced in 1.2.15beta6.
140.1975 +
140.1976 +Version 1.2.15rc4 [December 27, 2006]
140.1977    Fixed handling of rgb_to_gray when png_ptr->color.gray isn't set.
140.1978  
140.1979 -version 1.2.15rc5 [December 31, 2006]
140.1980 +Version 1.2.15rc5 [December 31, 2006]
140.1981    Revised handling of rgb_to_gray.
140.1982  
140.1983 -version 1.2.15 [January 5, 2007]
140.1984 +Version 1.2.15 [January 5, 2007]
140.1985    Added some (unsigned long) typecasts in pngtest.c to avoid printing errors.
140.1986  
140.1987 -version 1.2.16beta1 [January 6, 2007]
140.1988 +Version 1.2.16beta1 [January 6, 2007]
140.1989    Fix bugs in makefile.nommx
140.1990  
140.1991 -version 1.2.16beta2 [January 16, 2007]
140.1992 +Version 1.2.16beta2 [January 16, 2007]
140.1993    Revised scripts/CMakeLists.txt
140.1994 - 
140.1995 -version 1.2.16 [January 31, 2007]
140.1996 +
140.1997 +Version 1.2.16 [January 31, 2007]
140.1998    No changes.
140.1999 - 
140.2000 -version 1.2.17beta1 [March 6, 2007]
140.2001 +
140.2002 +Version 1.2.17beta1 [March 6, 2007]
140.2003    Revised scripts/CMakeLists.txt to install both shared and static libraries.
140.2004    Deleted a redundant line from pngset.c.
140.2005 - 
140.2006 -version 1.2.17beta2 [April 26, 2007]
140.2007 +
140.2008 +Version 1.2.17beta2 [April 26, 2007]
140.2009    Relocated misplaced test for png_ptr == NULL in pngpread.c
140.2010    Change "==" to "&" for testing PNG_RGB_TO_GRAY_ERR & PNG_RGB_TO_GRAY_WARN
140.2011      flags.
140.2012 @@ -1726,10 +1886,10 @@
140.2013    Added "const" to some array declarations.
140.2014    Mention examples of libpng usage in the libpng*.txt and libpng.3 documents.
140.2015  
140.2016 -version 1.2.17rc1 [May 4, 2007]
140.2017 +Version 1.2.17rc1 [May 4, 2007]
140.2018    No changes.
140.2019  
140.2020 -version 1.2.17rc2 [May 8, 2007]
140.2021 +Version 1.2.17rc2 [May 8, 2007]
140.2022    Moved several PNG_HAVE_* macros out of PNG_INTERNAL because applications
140.2023      calling set_unknown_chunk_location() need them.
140.2024    Changed transformation flag from PNG_EXPAND_tRNS to PNG_EXPAND in
140.2025 @@ -1737,22 +1897,1642 @@
140.2026    Added png_ptr->unknown_chunk to hold working unknown chunk data, so it
140.2027      can be free'ed in case of error.  Revised unknown chunk handling in
140.2028      pngrutil.c and pngpread.c to use this structure.
140.2029 - 
140.2030 -version 1.2.17rc3 [May 8, 2007]
140.2031 +
140.2032 +Version 1.2.17rc3 [May 8, 2007]
140.2033    Revised symbol-handling in configure script.
140.2034  
140.2035 -version 1.2.17rc4 [May 10, 2007]
140.2036 +Version 1.2.17rc4 [May 10, 2007]
140.2037    Revised unknown chunk handling to avoid storing unknown critical chunks.
140.2038  
140.2039 -version 1.0.25 [May 15, 2007]
140.2040 -version 1.2.17 [May 15, 2007]
140.2041 +Version 1.0.25 [May 15, 2007]
140.2042 +Version 1.2.17 [May 15, 2007]
140.2043    Added "png_ptr->num_trans=0" before error return in png_handle_tRNS,
140.2044 -    to eliminate a vulnerability (CVE-2007-2554, CERT VU#684664)
140.2045 -
140.2046 -version 1.0.26 [May 15, 2007]
140.2047 -version 1.2.18 [May 15, 2007]
140.2048 +    to eliminate a vulnerability (CVE-2007-2445, CERT VU#684664)
140.2049 +
140.2050 +Version 1.0.26 [May 15, 2007]
140.2051 +Version 1.2.18 [May 15, 2007]
140.2052    Reverted the libpng-1.2.17rc3 change to symbol-handling in configure script
140.2053  
140.2054 +Version 1.2.19beta1 [May 18, 2007]
140.2055 +  Changed "const static" to "static PNG_CONST" everywhere, mostly undoing
140.2056 +    change of libpng-1.2.17beta2.  Changed other "const" to "PNG_CONST"
140.2057 +  Changed some handling of unused parameters, to avoid compiler warnings.
140.2058 +    "if (unused == NULL) return;" becomes "unused = unused".
140.2059 +
140.2060 +Version 1.2.19beta2 [May 18, 2007]
140.2061 +  Only use the valid bits of tRNS value in png_do_expand() (Brian Cartier)
140.2062 +
140.2063 +Version 1.2.19beta3 [May 19, 2007]
140.2064 +  Add some "png_byte" typecasts in png_check_keyword() and write new_key
140.2065 +  instead of key in zTXt chunk (Kevin Ryde).
140.2066 +
140.2067 +Version 1.2.19beta4 [May 21, 2007]
140.2068 +  Add png_snprintf() function and use it in place of sprint() for improved
140.2069 +    defense against buffer overflows.
140.2070 +
140.2071 +Version 1.2.19beta5 [May 21, 2007]
140.2072 +  Fixed png_handle_tRNS() to only use the valid bits of tRNS value.
140.2073 +  Changed handling of more unused parameters, to avoid compiler warnings.
140.2074 +  Removed some PNG_CONST in pngwutil.c to avoid compiler warnings.
140.2075 +
140.2076 +Version 1.2.19beta6 [May 22, 2007]
140.2077 +  Added some #ifdef PNG_MMX_CODE_SUPPORTED where needed in pngvcrd.c
140.2078 +  Added a special "_MSC_VER" case that defines png_snprintf to _snprintf
140.2079 +
140.2080 +Version 1.2.19beta7 [May 22, 2007]
140.2081 +  Squelched png_squelch_warnings() in pnggccrd.c and added
140.2082 +    an #ifdef PNG_MMX_CODE_SUPPORTED block around the declarations that caused
140.2083 +    the warnings that png_squelch_warnings was squelching.
140.2084 +
140.2085 +Version 1.2.19beta8 [May 22, 2007]
140.2086 +  Removed __MMX__ from test in pngconf.h.
140.2087 +
140.2088 +Version 1.2.19beta9 [May 23, 2007]
140.2089 +  Made png_squelch_warnings() available via PNG_SQUELCH_WARNINGS macro.
140.2090 +  Revised png_squelch_warnings() so it might work.
140.2091 +  Updated makefile.sgcc and makefile.solaris; added makefile.solaris-x86.
140.2092 +
140.2093 +Version 1.2.19beta10 [May 24, 2007]
140.2094 +  Resquelched png_squelch_warnings(), use "__attribute__((used))" instead.
140.2095 +
140.2096 +Version 1.4.0beta1 [April 20, 2006]
140.2097 +  Enabled iTXt support (changes png_struct, thus requires so-number change).
140.2098 +  Cleaned up PNG_ASSEMBLER_CODE_SUPPORTED vs PNG_MMX_CODE_SUPPORTED
140.2099 +  Eliminated PNG_1_0_X and PNG_1_2_X macros.
140.2100 +  Removed deprecated functions png_read_init, png_write_init, png_info_init,
140.2101 +    png_permit_empty_plte, png_set_gray_1_2_4_to_8, png_check_sig, and
140.2102 +    removed the deprecated macro PNG_MAX_UINT.
140.2103 +  Moved "PNG_INTERNAL" parts of png.h and pngconf.h into pngintrn.h
140.2104 +  Removed many WIN32_WCE #ifdefs (Cosmin).
140.2105 +  Reduced dependency on C-runtime library when on Windows (Simon-Pierre)
140.2106 +  Replaced sprintf() with png_sprintf() (Simon-Pierre)
140.2107 +
140.2108 +Version 1.4.0beta2 [April 20, 2006]
140.2109 +  Revised makefiles and configure to avoid making links to libpng.so.*
140.2110 +  Moved some leftover MMX-related defines from pngconf.h to pngintrn.h
140.2111 +  Updated scripts/pngos2.def, pngw32.def, and projects/wince/png32ce.def
140.2112 +
140.2113 +Version 1.4.0beta3 [May 10, 2006]
140.2114 +  Updated scripts/pngw32.def to comment out MMX functions.
140.2115 +  Added PNG_NO_GET_INT_32 and PNG_NO_SAVE_INT_32 macros.
140.2116 +  Scripts/libpng.pc.in contained "configure" style version info and would
140.2117 +    not work with makefiles.
140.2118 +  Revised pngconf.h and added pngconf.h.in, so makefiles and configure can
140.2119 +    pass defines to libpng and applications.
140.2120 +
140.2121 +Version 1.4.0beta4 [May 11, 2006]
140.2122 +  Revised configure.ac, Makefile.am, and many of the makefiles to write
140.2123 +    their defines in pngconf.h.
140.2124 +
140.2125 +Version 1.4.0beta5 [May 15, 2006]
140.2126 +  Added a missing semicolon in Makefile.am and Makefile.in
140.2127 +  Deleted extraneous square brackets from configure.ac
140.2128 +
140.2129 +Version 1.4.0beta6 [June 2, 2006]
140.2130 +  Increased sprintf buffer from 50 to 52 chars in pngrutil.c to avoid
140.2131 +    buffer overflow.
140.2132 +  Changed sonum from 0 to 1.
140.2133 +  Removed unused prototype for png_check_sig() from png.h
140.2134 +
140.2135 +Version 1.4.0beta7 [June 16, 2006]
140.2136 +  Exported png_write_sig (Cosmin).
140.2137 +  Optimized buffer in png_handle_cHRM() (Cosmin).
140.2138 +  Set pHYs = 2835 x 2835 pixels per meter, and added
140.2139 +    sCAL = 0.352778e-3 x 0.352778e-3 meters, in pngtest.png (Cosmin).
140.2140 +  Added png_set_benign_errors(), png_benign_error(), png_chunk_benign_error().
140.2141 +  Added typedef for png_int_32 and png_uint_32 on 64-bit systems.
140.2142 +  Added "(unsigned long)" typecast on png_uint_32 variables in printf lists.
140.2143 +
140.2144 +Version 1.4.0beta8 [June 22, 2006]
140.2145 +  Added demonstration of user chunk support in pngtest.c, to support the
140.2146 +    public sTER chunk and a private vpAg chunk.
140.2147 +
140.2148 +Version 1.4.0beta9 [July 3, 2006]
140.2149 +  Removed ordinals from scripts/pngw32.def and removed png_info_int and
140.2150 +    png_set_gray_1_2_4_to_8 entries.
140.2151 +  Inline call of png_get_uint_32() in png_get_uint_31().
140.2152 +  Use png_get_uint_31() to get vpAg width and height in pngtest.c
140.2153 +  Removed WINCE and Netware projects.
140.2154 +  Removed standalone Y2KINFO file.
140.2155 +
140.2156 +Version 1.4.0beta10 [July 12, 2006]
140.2157 +  Eliminated automatic copy of pngconf.h to pngconf.h.in from configure and
140.2158 +    some makefiles, because it was not working reliably.  Instead, distribute
140.2159 +    pngconf.h.in along with pngconf.h and cause configure and some of the
140.2160 +    makefiles to update pngconf.h from pngconf.h.in.
140.2161 +  Added pngconf.h to DEPENDENCIES in Makefile.am
140.2162 +
140.2163 +Version 1.4.0beta11 [August 19, 2006]
140.2164 +  Removed AC_FUNC_MALLOC from configure.ac.
140.2165 +  Added a warning when writing iCCP profile with mismatched profile length.
140.2166 +  Patched pnggccrd.c to assemble on x86_64 platforms.
140.2167 +  Moved chunk header reading into a separate function png_read_chunk_header()
140.2168 +    in pngrutil.c.  The chunk header (len+sig) is now serialized in a single
140.2169 +    operation (Cosmin).
140.2170 +  Implemented support for I/O states. Added png_ptr member io_state, and
140.2171 +    functions png_get_io_chunk_name() and png_get_io_state() in pngget.c
140.2172 +    (Cosmin).
140.2173 +  Added png_get_io_chunk_name and png_get_io_state to scripts/*.def (Cosmin).
140.2174 +  Renamed scripts/pngw32.* to scripts/pngwin.* (Cosmin).
140.2175 +  Removed the include directories and libraries from CFLAGS and LDFLAGS
140.2176 +    in scripts/makefile.gcc (Cosmin).
140.2177 +  Used png_save_uint_32() to set vpAg width and height in pngtest.c (Cosmin).
140.2178 +  Cast to proper type when getting/setting vpAg units in pngtest.c (Cosmin).
140.2179 +  Added pngintrn.h to the Visual C++ projects (Cosmin).
140.2180 +  Removed scripts/list (Cosmin).
140.2181 +  Updated copyright year in scripts/pngwin.def (Cosmin).
140.2182 +  Removed PNG_TYPECAST_NULL and used standard NULL consistently (Cosmin).
140.2183 +  Disallowed the user to redefine png_size_t, and enforced a consistent use
140.2184 +    of png_size_t across libpng (Cosmin).
140.2185 +  Changed the type of png_ptr->rowbytes, PNG_ROWBYTES() and friends
140.2186 +    to png_size_t (Cosmin).
140.2187 +  Removed png_convert_size() and replaced png_sizeof with sizeof (Cosmin).
140.2188 +  Removed some unnecessary type casts (Cosmin).
140.2189 +  Changed prototype of png_get_compression_buffer_size() and
140.2190 +    png_set_compression_buffer_size() to work with png_size_t instead of
140.2191 +    png_uint_32 (Cosmin).
140.2192 +  Removed png_memcpy_check() and png_memset_check() (Cosmin).
140.2193 +  Fixed a typo (png_byte --> png_bytep) in libpng.3 and libpng.txt (Cosmin).
140.2194 +  Clarified that png_zalloc() does not clear the allocated memory,
140.2195 +    and png_zalloc() and png_zfree() cannot be PNGAPI (Cosmin).
140.2196 +  Renamed png_mem_size_t to png_alloc_size_t, fixed its definition in
140.2197 +    pngconf.h, and used it in all memory allocation functions (Cosmin).
140.2198 +  Renamed pngintrn.h to pngpriv.h, added a comment at the top of the file
140.2199 +    mentioning that the symbols declared in that file are private, and
140.2200 +    updated the scripts and the Visual C++ projects accordingly (Cosmin).
140.2201 +  Removed circular references between pngconf.h and pngconf.h.in in
140.2202 +    scripts/makefile.vc*win32 (Cosmin).
140.2203 +  Removing trailing '.' from the warning and error messages (Cosmin).
140.2204 +  Added pngdefs.h that is built by makefile or configure, instead of
140.2205 +    pngconf.h.in (Glenn).
140.2206 +  Detect and fix attempt to write wrong iCCP profile length.
140.2207 +
140.2208 +Version 1.4.0beta12 [October 19, 2006]
140.2209 +  Changed "logical" to "bitwise" in the documentation.
140.2210 +  Work around Intel-Mac compiler bug by setting PNG_NO_MMX_CODE in pngconf.h
140.2211 +  Add a typecast to stifle compiler warning in pngrutil.c
140.2212 +
140.2213 +Version 1.4.0beta13 [November 10, 2006]
140.2214 +  Fix potential buffer overflow in sPLT chunk handler.
140.2215 +  Fix Makefile.am to not try to link to noexistent files.
140.2216 +
140.2217 +Version 1.4.0beta14 [November 15, 2006]
140.2218 +  Check all exported functions for NULL png_ptr.
140.2219 +
140.2220 +Version 1.4.0beta15 [November 17, 2006]
140.2221 +  Relocated two misplaced tests for NULL png_ptr.
140.2222 +  Built Makefile.in with automake-1.9.6 instead of 1.9.2.
140.2223 +  Build configure with autoconf-2.60 instead of 2.59
140.2224 +  Add "install: all" in Makefile.am so "configure; make install" will work.
140.2225 +
140.2226 +Version 1.4.0beta16 [November 17, 2006]
140.2227 +  Added a typecast in png_zalloc().
140.2228 +
140.2229 +Version 1.4.0beta17 [December 4, 2006]
140.2230 +  Changed "new_key[79] = '\0';" to "(*new_key)[79] = '\0';" in pngwutil.c
140.2231 +  Add "png_bytep" typecast to profile while calculating length in pngwutil.c
140.2232 +
140.2233 +Version 1.4.0beta18 [December 7, 2006]
140.2234 +  Added scripts/CMakeLists.txt
140.2235 +
140.2236 +Version 1.4.0beta19 [May 16, 2007]
140.2237 +  Revised scripts/CMakeLists.txt
140.2238 +  Rebuilt configure and Makefile.in with newer tools.
140.2239 +  Added conditional #undef jmpbuf in pngtest.c to undo #define in AIX headers.
140.2240 +  Added scripts/makefile.nommx
140.2241 +
140.2242 +Version 1.4.0beta20 [July 9, 2008]
140.2243 +  Moved several PNG_HAVE_* macros from pngpriv.h to png.h because applications
140.2244 +    calling set_unknown_chunk_location() need them.
140.2245 +  Moved several macro definitions from pngpriv.h to pngconf.h
140.2246 +  Merge with changes to the 1.2.X branch, as of 1.2.30beta04.
140.2247 +  Deleted all use of the MMX assembler code and Intel-licensed optimizations.
140.2248 +  Revised makefile.mingw
140.2249 +
140.2250 +Version 1.4.0beta21 [July 21, 2008]
140.2251 +  Moved local array "chunkdata" from pngrutil.c to the png_struct, so
140.2252 +    it will be freed by png_read_destroy() in case of a read error (Kurt
140.2253 +    Christensen).
140.2254 +
140.2255 +Version 1.4.0beta22 [July 21, 2008]
140.2256 +  Change "purpose" and "buffer" to png_ptr->chunkdata to avoid memory leaking.
140.2257 +
140.2258 +Version 1.4.0beta23 [July 22, 2008]
140.2259 +  Change "chunkdata = NULL" to "png_ptr->chunkdata = NULL" several places in
140.2260 +    png_decompress_chunk().
140.2261 +
140.2262 +Version 1.4.0beta24 [July 25, 2008]
140.2263 +  Change all remaining "chunkdata" to "png_ptr->chunkdata" in
140.2264 +    png_decompress_chunk(), and remove "chunkdata" from parameter list.
140.2265 +  Put a call to png_check_chunk_name() in png_read_chunk_header().
140.2266 +  Revised png_check_chunk_name() to reject a name with a lowercase 3rd byte.
140.2267 +  Removed two calls to png_check_chunk_name() occuring later in the process.
140.2268 +  Define PNG_NO_ERROR_NUMBERS by default in pngconf.h
140.2269 +
140.2270 +Version 1.4.0beta25 [July 30, 2008]
140.2271 +  Added a call to png_check_chunk_name() in pngpread.c
140.2272 +  Reverted png_check_chunk_name() to accept a name with a lowercase 3rd byte.
140.2273 +  Added png_push_have_buffer() function to pngpread.c
140.2274 +  Eliminated PNG_BIG_ENDIAN_SUPPORTED and associated png_get_* macros.
140.2275 +  Made inline expansion of png_get_*() optional with PNG_USE_READ_MACROS.
140.2276 +  Eliminated all PNG_USELESS_TESTS and PNG_CORRECT_PALETTE_SUPPORTED code.
140.2277 +  Synced contrib directory and configure files with libpng-1.2.30beta06.
140.2278 +  Eliminated no-longer-used pngdefs.h (but it's still built in the makefiles)
140.2279 +  Relocated a misplaced "#endif /* PNG_NO_WRITE_FILTER */" in pngwutil.c
140.2280 +
140.2281 +Version 1.4.0beta26 [August 4, 2008]
140.2282 +  Removed png_push_have_buffer() function in pngpread.c.  It increased the
140.2283 +    compiled library size slightly.
140.2284 +  Changed "-Wall" to "-W -Wall" in the CFLAGS in all makefiles (Cosmin Truta)
140.2285 +  Declared png_ptr "volatile" in pngread.c and pngwrite.c to avoid warnings.
140.2286 +  Updated contrib/visupng/cexcept.h to version 2.0.1
140.2287 +  Added PNG_LITERAL_CHARACTER macros for #, [, and ].
140.2288 +
140.2289 +Version 1.4.0beta27 [August 5, 2008]
140.2290 +  Revised usage of PNG_LITERAL_SHARP in pngerror.c.
140.2291 +  Moved newline character from individual png_debug messages into the
140.2292 +    png_debug macros.
140.2293 +  Allow user to #define their own png_debug, png_debug1, and png_debug2.
140.2294 +
140.2295 +Version 1.4.0beta28 [August 5, 2008]
140.2296 +  Revised usage of PNG_LITERAL_SHARP in pngerror.c.
140.2297 +  Added PNG_STRING_NEWLINE macro
140.2298 +
140.2299 +Version 1.4.0beta29 [August 9, 2008]
140.2300 +  Revised usage of PNG_STRING_NEWLINE to work on non-ISO compilers.
140.2301 +  Added PNG_STRING_COPYRIGHT macro.
140.2302 +  Added non-ISO versions of png_debug macros.
140.2303 +
140.2304 +Version 1.4.0beta30 [August 14, 2008]
140.2305 +  Added premultiplied alpha feature (Volker Wiendl).
140.2306 +
140.2307 +Version 1.4.0beta31 [August 18, 2008]
140.2308 +  Moved png_set_premultiply_alpha from pngtrans.c to pngrtran.c
140.2309 +  Removed extra crc check at the end of png_handle_cHRM().  Bug introduced
140.2310 +    in libpng-1.4.0beta20.
140.2311 +
140.2312 +Version 1.4.0beta32 [August 19, 2008]
140.2313 +  Added PNG_WRITE_FLUSH_SUPPORTED block around new png_flush() call.
140.2314 +  Revised PNG_NO_STDIO version of png_write_flush()
140.2315 +
140.2316 +Version 1.4.0beta33 [August 20, 2008]
140.2317 +  Added png_get|set_chunk_cache_max() to limit the total number of sPLT,
140.2318 +    text, and unknown chunks that can be stored.
140.2319 +
140.2320 +Version 1.4.0beta34 [September 6, 2008]
140.2321 +  Shortened tIME_string to 29 bytes in pngtest.c
140.2322 +  Fixed off-by-one error introduced in png_push_read_zTXt() function in
140.2323 +    libpng-1.2.30beta04/pngpread.c (Harald van Dijk)
140.2324 +
140.2325 +Version 1.4.0beta35 [October 6, 2008]
140.2326 +  Changed "trans_values" to "trans_color".
140.2327 +  Changed so-number from 0 to 14.  Some OS do not like 0.
140.2328 +  Revised makefile.darwin to fix shared library numbering.
140.2329 +  Change png_set_gray_1_2_4_to_8() to png_set_expand_gray_1_2_4_to_8()
140.2330 +    in example.c (debian bug report)
140.2331 +
140.2332 +Version 1.4.0beta36 [October 25, 2008]
140.2333 +  Sync with tEXt vulnerability fix in libpng-1.2.33rc02.
140.2334 +
140.2335 +Version 1.4.0beta37 [November 13, 2008]
140.2336 +  Added png_check_cHRM in png.c and moved checking from pngget.c, pngrutil.c,
140.2337 +    and pngwrite.c
140.2338 +
140.2339 +Version 1.4.0beta38 [November 22, 2008]
140.2340 +  Added check for zero-area RGB cHRM triangle in png_check_cHRM() and
140.2341 +    png_check_cHRM_fixed().
140.2342 +
140.2343 +Version 1.4.0beta39 [November 23, 2008]
140.2344 +  Revised png_warning() to write its message on standard output by default
140.2345 +    when warning_fn is NULL.
140.2346 +
140.2347 +Version 1.4.0beta40 [November 24, 2008]
140.2348 +  Eliminated png_check_cHRM().  Instead, always use png_check_cHRM_fixed().
140.2349 +  In png_check_cHRM_fixed(), ensure white_y is > 0, and removed redundant
140.2350 +    check for all-zero coordinates that is detected by the triangle check.
140.2351 +
140.2352 +Version 1.4.0beta41 [November 26, 2008]
140.2353 +  Fixed string vs pointer-to-string error in png_check_keyword().
140.2354 +  Rearranged test expressions in png_check_cHRM_fixed() to avoid internal
140.2355 +    overflows.
140.2356 +  Added PNG_NO_CHECK_cHRM conditional.
140.2357 +
140.2358 +Version 1.4.0beta42, 43 [December 1, 2008]
140.2359 +  Merge png_debug with version 1.2.34beta04.
140.2360 +
140.2361 +Version 1.4.0beta44 [December 6, 2008]
140.2362 +  Removed redundant check for key==NULL before calling png_check_keyword()
140.2363 +    to ensure that new_key gets initialized and removed extra warning
140.2364 +    (Merge with version 1.2.34beta05 -- Arvan Pritchard).
140.2365 +
140.2366 +Version 1.4.0beta45 [December 9, 2008]
140.2367 +  In png_write_png(), respect the placement of the filler bytes in an earlier
140.2368 +    call to png_set_filler() (Jim Barry).
140.2369 +
140.2370 +Version 1.4.0beta46 [December 10, 2008]
140.2371 +  Undid previous change and added PNG_TRANSFORM_STRIP_FILLER_BEFORE and
140.2372 +    PNG_TRANSFORM_STRIP_FILLER_AFTER conditionals and deprecated
140.2373 +    PNG_TRANSFORM_STRIP_FILLER (Jim Barry).
140.2374 +
140.2375 +Version 1.4.0beta47 [December 15, 2008]
140.2376 +  Support for dithering was disabled by default, because it has never
140.2377 +    been well tested and doesn't work very well.  The code has not
140.2378 +    been removed, however, and can be enabled by building libpng with
140.2379 +    PNG_READ_DITHER_SUPPORTED defined.
140.2380 +
140.2381 +Version 1.4.0beta48 [February 14, 2009]
140.2382 +  Added new exported function png_calloc().
140.2383 +  Combined several instances of png_malloc(); png_memset() into png_calloc().
140.2384 +  Removed prototype for png_freeptr() that was added in libpng-1.4.0beta24
140.2385 +    but was never defined.
140.2386 +
140.2387 +Version 1.4.0beta49 [February 28, 2009]
140.2388 +  Added png_fileno() macro to pngconf.h, used in pngwio.c
140.2389 +  Corrected order of #ifdef's in png_debug definition in png.h
140.2390 +  Fixed bug introduced in libpng-1.4.0beta48 with the memset arguments
140.2391 +    for pcal_params.
140.2392 +  Fixed order of #ifdef directives in the png_debug defines in png.h
140.2393 +    (bug introduced in libpng-1.2.34/1.4.0beta29).
140.2394 +  Revised comments in png_set_read_fn() and png_set_write_fn().
140.2395 +
140.2396 +Version 1.4.0beta50 [March 18, 2009]
140.2397 +  Use png_calloc() instead of png_malloc() to allocate big_row_buf when
140.2398 +    reading an interlaced file, to avoid a possible UMR.
140.2399 +  Undid revision of PNG_NO_STDIO version of png_write_flush().  Users
140.2400 +    having trouble with fflush() can build with PNG_NO_WRITE_FLUSH defined
140.2401 +    or supply their own flush_fn() replacement.
140.2402 +  Revised libpng*.txt and png.h documentation about use of png_write_flush()
140.2403 +    and png_set_write_fn().
140.2404 +  Removed fflush() from pngtest.c.
140.2405 +  Added "#define PNG_NO_WRITE_FLUSH" to contrib/pngminim/encoder/pngusr.h
140.2406 +
140.2407 +Version 1.4.0beta51 [March 21, 2009]
140.2408 +  Removed new png_fileno() macro from pngconf.h .
140.2409 +
140.2410 +Version 1.4.0beta52 [March 27, 2009]
140.2411 +  Relocated png_do_chop() ahead of building gamma tables in pngrtran.c
140.2412 +    This avoids building 16-bit gamma tables unnecessarily.
140.2413 +  Removed fflush() from pngtest.c.
140.2414 +  Added "#define PNG_NO_WRITE_FLUSH" to contrib/pngminim/encoder/pngusr.h
140.2415 +  Added a section on differences between 1.0.x and 1.2.x to libpng.3/libpng.txt
140.2416 +
140.2417 +Version 1.4.0beta53 [April 1, 2009]
140.2418 +  Removed some remaining MMX macros from pngpriv.h
140.2419 +  Fixed potential memory leak of "new_name" in png_write_iCCP() (Ralph Giles)
140.2420 +
140.2421 +Version 1.4.0beta54 [April 13, 2009]
140.2422 +  Added "ifndef PNG_SKIP_SETJMP_CHECK" block in pngconf.h to allow
140.2423 +    application code writers to bypass the check for multiple inclusion
140.2424 +    of setjmp.h when they know that it is safe to ignore the situation.
140.2425 +  Eliminated internal use of setjmp() in pngread.c and pngwrite.c
140.2426 +  Reordered ancillary chunks in pngtest.png to be the same as what
140.2427 +    pngtest now produces, and made some cosmetic changes to pngtest output.
140.2428 +  Eliminated deprecated png_read_init_3() and png_write_init_3() functions.
140.2429 +
140.2430 +Version 1.4.0beta55 [April 15, 2009]
140.2431 +  Simplified error handling in pngread.c and pngwrite.c by putting
140.2432 +    the new png_read_cleanup() and png_write_cleanup() functions inline.
140.2433 +
140.2434 +Version 1.4.0beta56 [April 25, 2009]
140.2435 +  Renamed "user_chunk_data" to "my_user_chunk_data" in pngtest.c to suppress
140.2436 +    "shadowed declaration" warning from gcc-4.3.3.
140.2437 +  Renamed "gamma" to "png_gamma" in pngset.c to avoid "shadowed declaration"
140.2438 +    warning about a global "gamma" variable in math.h on some platforms.
140.2439 +
140.2440 +Version 1.4.0beta57 [May 2, 2009]
140.2441 +  Removed prototype for png_freeptr() that was added in libpng-1.4.0beta24
140.2442 +    but was never defined (again).
140.2443 +  Rebuilt configure scripts with autoconf-2.63 instead of 2.62
140.2444 +  Removed pngprefs.h and MMX from makefiles
140.2445 +
140.2446 +Version 1.4.0beta58 [May 14, 2009]
140.2447 +  Changed pngw32.def to pngwin.def in makefile.mingw (typo was introduced
140.2448 +    in beta57).
140.2449 +  Clarified usage of sig_bit versus sig_bit_p in example.c (Vincent Torri)
140.2450 +
140.2451 +Version 1.4.0beta59 [May 15, 2009]
140.2452 +  Reformated sources in libpng style (3-space intentation, comment format)
140.2453 +  Fixed typo in libpng docs (PNG_FILTER_AVE should be PNG_FILTER_AVG)
140.2454 +  Added sections about the git repository and our coding style to the
140.2455 +    documentation
140.2456 +  Relocated misplaced #endif in pngwrite.c, sCAL chunk handler.
140.2457 +
140.2458 +Version 1.4.0beta60 [May 19, 2009]
140.2459 +  Conditionally compile png_read_finish_row() which is not used by
140.2460 +    progressive readers.
140.2461 +  Added contrib/pngminim/preader to demonstrate building minimal progressive
140.2462 +    decoder, based on contrib/gregbook with embedded libpng and zlib.
140.2463 +
140.2464 +Version 1.4.0beta61 [May 20, 2009]
140.2465 +  In contrib/pngminim/*, renamed "makefile.std" to "makefile", since there
140.2466 +    is only one makefile in those directories, and revised the README files
140.2467 +    accordingly.
140.2468 +  More reformatting of comments, mostly to capitalize sentences.
140.2469 +
140.2470 +Version 1.4.0beta62 [June 2, 2009]
140.2471 +  Added "#define PNG_NO_WRITE_SWAP" to contrib/pngminim/encoder/pngusr.h
140.2472 +    and "define PNG_NO_READ_SWAP" to decoder/pngusr.h and preader/pngusr.h
140.2473 +  Reformatted several remaining "else statement" into two lines.
140.2474 +  Added a section to the libpng documentation about using png_get_io_ptr()
140.2475 +    in configure scripts to detect the presence of libpng.
140.2476 +
140.2477 +Version 1.4.0beta63 [June 15, 2009]
140.2478 +  Revised libpng*.txt and libpng.3 to mention calling png_set_IHDR()
140.2479 +    multiple times and to specify the sample order in the tRNS chunk,
140.2480 +    because the ISO PNG specification has a typo in the tRNS table.
140.2481 +  Changed several PNG_UNKNOWN_CHUNK_SUPPORTED to
140.2482 +    PNG_HANDLE_AS_UNKNOWN_SUPPORTED, to make the png_set_keep mechanism
140.2483 +    available for ignoring known chunks even when not saving unknown chunks.
140.2484 +  Adopted preference for consistent use of "#ifdef" and "#ifndef" versus
140.2485 +    "#if defined()" and "if !defined()" where possible.
140.2486 +
140.2487 +Version 1.4.0beta64 [June 24, 2009]
140.2488 +  Eliminated PNG_LEGACY_SUPPORTED code.
140.2489 +  Moved the various unknown chunk macro definitions outside of the
140.2490 +     PNG_READ|WRITE_ANCILLARY_CHUNK_SUPPORTED blocks.
140.2491 +
140.2492 +Version 1.4.0beta65 [June 26, 2009]
140.2493 +  Added a reference to the libpng license in each file.
140.2494 +
140.2495 +Version 1.4.0beta66 [June 27, 2009]
140.2496 +  Refer to the libpng license instead of the libpng license in each file.
140.2497 +
140.2498 +Version 1.4.0beta67 [July 6, 2009]
140.2499 +  Relocated INVERT_ALPHA within png_read_png() and png_write_png().
140.2500 +  Added high-level API transform PNG_TRANSFORM_GRAY_TO_RGB.
140.2501 +  Added an "xcode" project to the projects directory (Alam Arias).
140.2502 +
140.2503 +Version 1.4.0beta68 [July 19, 2009]
140.2504 +  Avoid some tests in filter selection in pngwutil.c
140.2505 +
140.2506 +Version 1.4.0beta69 [July 25, 2009]
140.2507 +  Simplified the new filter-selection test.  This runs faster in the
140.2508 +    common "PNG_ALL_FILTERS" and PNG_FILTER_NONE cases.
140.2509 +  Removed extraneous declaration from the new call to png_read_gray_to_rgb()
140.2510 +    (bug introduced in libpng-1.4.0beta67).
140.2511 +  Fixed up xcode project (Alam Arias)
140.2512 +  Added a prototype for png_64bit_product() in png.c
140.2513 +
140.2514 +Version 1.4.0beta70 [July 27, 2009]
140.2515 +  Avoid a possible NULL dereference in debug build, in png_set_text_2().
140.2516 +    (bug introduced in libpng-0.95, discovered by Evan Rouault)
140.2517 +
140.2518 +Version 1.4.0beta71 [July 29, 2009]
140.2519 +  Rebuilt configure scripts with autoconf-2.64.
140.2520 +
140.2521 +Version 1.4.0beta72 [August 1, 2009]
140.2522 +  Replaced *.tar.lzma with *.tar.xz in distribution.  Get the xz codec
140.2523 +    from <http://tukaani.org/xz>.
140.2524 +
140.2525 +Version 1.4.0beta73 [August 1, 2009]
140.2526 +  Reject attempt to write iCCP chunk with negative embedded profile length
140.2527 +    (JD Chen)
140.2528 +
140.2529 +Version 1.4.0beta74 [August 8, 2009]
140.2530 +  Changed png_ptr and info_ptr member "trans" to "trans_alpha".
140.2531 +
140.2532 +Version 1.4.0beta75 [August 21, 2009]
140.2533 +  Removed an extra png_debug() recently added to png_write_find_filter().
140.2534 +  Fixed incorrect #ifdef in pngset.c regarding unknown chunk support.
140.2535 +
140.2536 +Version 1.4.0beta76 [August 22, 2009]
140.2537 +  Moved an incorrectly located test in png_read_row() in pngread.c
140.2538 +
140.2539 +Version 1.4.0beta77 [August 27, 2009]
140.2540 +  Removed lpXYZ.tar.bz2 (with CRLF), KNOWNBUG, libpng-x.y.z-KNOWNBUG.txt,
140.2541 +    and the "noconfig" files from the distribution.
140.2542 +  Moved CMakeLists.txt from scripts into the main libpng directory.
140.2543 +  Various bugfixes and improvements to CMakeLists.txt (Philip Lowman)
140.2544 +
140.2545 +Version 1.4.0beta78 [August 31, 2009]
140.2546 +  Converted all PNG_NO_* tests to PNG_*_SUPPORTED everywhere except pngconf.h
140.2547 +  Eliminated PNG_NO_FREE_ME and PNG_FREE_ME_SUPPORTED macros.
140.2548 +  Use png_malloc plus a loop instead of png_calloc() to initialize
140.2549 +    row_pointers in png_read_png().
140.2550 +
140.2551 +Version 1.4.0beta79 [September 1, 2009]
140.2552 +  Eliminated PNG_GLOBAL_ARRAYS and PNG_LOCAL_ARRAYS; always use local arrays.
140.2553 +  Eliminated PNG_CALLOC_SUPPORTED macro and always provide png_calloc().
140.2554 +
140.2555 +Version 1.4.0beta80 [September 17, 2009]
140.2556 +  Removed scripts/libpng.icc
140.2557 +  Changed typecast of filler from png_byte to png_uint_16 in png_set_filler().
140.2558 +    (Dennis Gustafsson)
140.2559 +  Fixed typo introduced in beta78 in pngtest.c ("#if def " should be "#ifdef ")
140.2560 +
140.2561 +Version 1.4.0beta81 [September 23, 2009]
140.2562 +  Eliminated unused PNG_FLAG_FREE_* defines from pngpriv.h
140.2563 +  Expanded TAB characters in pngrtran.c
140.2564 +  Removed PNG_CONST from all "PNG_CONST PNG_CHNK" declarations to avoid
140.2565 +    compiler complaints about doubly declaring things "const".
140.2566 +  Changed all "#if [!]defined(X)" to "if[n]def X" where possible.
140.2567 +  Eliminated unused png_ptr->row_buf_size
140.2568 +
140.2569 +Version 1.4.0beta82 [September 25, 2009]
140.2570 +  Moved redundant IHDR checking into new png_check_IHDR() in png.c
140.2571 +    and report all errors found in the IHDR data.
140.2572 +  Eliminated useless call to png_check_cHRM() from pngset.c
140.2573 +
140.2574 +Version 1.4.0beta83 [September 25, 2009]
140.2575 +  Revised png_check_IHDR() to eliminate bogus complaint about filter_type.
140.2576 +
140.2577 +Version 1.4.0beta84 [September 30, 2009]
140.2578 +  Fixed some inconsistent indentation in pngconf.h
140.2579 +  Revised png_check_IHDR() to add a test for width variable less than 32-bit.
140.2580 +
140.2581 +Version 1.4.0beta85 [October 1, 2009]
140.2582 +  Revised png_check_IHDR() again, to check info_ptr members instead of
140.2583 +    the contents of the returned parameters.
140.2584 +
140.2585 +Version 1.4.0beta86 [October 9, 2009]
140.2586 +  Updated the "xcode" project (Alam Arias).
140.2587 +  Eliminated a shadowed declaration of "pp" in png_handle_sPLT().
140.2588 +
140.2589 +Version 1.4.0rc01 [October 19, 2009]
140.2590 +  Trivial cosmetic changes.
140.2591 +
140.2592 +Version 1.4.0beta87 [October 30, 2009]
140.2593 +  Moved version 1.4.0 back into beta.
140.2594 +
140.2595 +Version 1.4.0beta88 [October 30, 2009]
140.2596 +  Revised libpng*.txt section about differences between 1.2.x and 1.4.0
140.2597 +    because most of the new features have now been ported back to 1.2.41
140.2598 +
140.2599 +Version 1.4.0beta89 [November 1, 2009]
140.2600 +  More bugfixes and improvements to CMakeLists.txt (Philip Lowman)
140.2601 +  Removed a harmless extra png_set_invert_alpha() from pngwrite.c
140.2602 +  Apply png_user_chunk_cache_max within png_decompress_chunk().
140.2603 +  Merged libpng-1.2.41.txt with libpng-1.4.0.txt where appropriate.
140.2604 +
140.2605 +Version 1.4.0beta90 [November 2, 2009]
140.2606 +  Removed all remaining WIN32_WCE #ifdefs except those involving the
140.2607 +    time.h "tm" structure
140.2608 +
140.2609 +Version 1.4.0beta91 [November 3, 2009]
140.2610 +  Updated scripts/pngw32.def and projects/wince/png32ce.def
140.2611 +  Copied projects/wince/png32ce.def to the scripts directory.
140.2612 +  Added scripts/makefile.wce
140.2613 +  Patched ltmain.sh for wince support.
140.2614 +  Added PNG_CONVERT_tIME_SUPPORTED macro.
140.2615 +
140.2616 +Version 1.4.0beta92 [November 4, 2009]
140.2617 +  Make inclusion of time.h in pngconf.h depend on PNG_CONVERT_tIME_SUPPORTED
140.2618 +  Make #define PNG_CONVERT_tIME_SUPPORTED depend on PNG_WRITE_tIME_SUPPORTED
140.2619 +  Revised libpng*.txt to describe differences from 1.2.40 to 1.4.0 (instead
140.2620 +    of differences from 1.2.41 to 1.4.0)
140.2621 +
140.2622 +Version 1.4.0beta93 [November 7, 2009]
140.2623 +  Added PNG_DEPSTRUCT, PNG_DEPRECATED, PNG_USE_RESULT, PNG_NORETURN, and
140.2624 +    PNG_ALLOCATED macros to detect deprecated direct access to the
140.2625 +    png_struct or info_struct members and other deprecated usage in
140.2626 +    applications (John Bowler).
140.2627 +  Updated scripts/makefile* to add "-DPNG_CONFIGURE_LIBPNG" to CFLAGS,
140.2628 +    to prevent warnings about direct access to png structs by libpng
140.2629 +    functions while building libpng.  They need to be tested, especially
140.2630 +    those using compilers other than gcc.
140.2631 +  Updated projects/visualc6 and visualc71 with "/d PNG_CONFIGURE_LIBPNG".
140.2632 +    They should work but still need to be updated to remove
140.2633 +    references to pnggccrd.c or pngvcrd.c and ASM building.
140.2634 +  Added README.txt to the beos, cbuilder5, netware, and xcode projects warning
140.2635 +    that they need to be updated, to remove references to pnggccrd.c and
140.2636 +    pngvcrd.c and to depend on pngpriv.h
140.2637 +  Removed three direct references to read_info_ptr members in pngtest.c
140.2638 +    that were detected by the new PNG_DEPSTRUCT macro.
140.2639 +  Moved the png_debug macro definitions and the png_read_destroy(),
140.2640 +    png_write_destroy() and png_far_to_near() prototypes from png.h
140.2641 +    to pngpriv.h (John Bowler)
140.2642 +  Moved the synopsis lines for png_read_destroy(), png_write_destroy()
140.2643 +    png_debug(), png_debug1(), and png_debug2() from libpng.3 to libpngpf.3.
140.2644 +
140.2645 +Version 1.4.0beta94 [November 9, 2009]
140.2646 +  Removed the obsolete, unused pnggccrd.c and pngvcrd.c files.
140.2647 +  Updated CMakeLists.txt to add "-DPNG_CONFIGURE_LIBPNG" to the definitions.
140.2648 +  Removed dependency of pngtest.o on pngpriv.h in the makefiles.
140.2649 +  Only #define PNG_DEPSTRUCT, etc. in pngconf.h if not already defined.
140.2650 +
140.2651 +Version 1.4.0beta95 [November 10, 2009]
140.2652 +  Changed png_check_sig() to !png_sig_cmp() in contrib programs.
140.2653 +  Added -DPNG_CONFIGURE_LIBPNG to contrib/pngminm/*/makefile
140.2654 +  Changed png_check_sig() to !png_sig_cmp() in contrib programs.
140.2655 +  Corrected the png_get_IHDR() call in contrib/gregbook/readpng2.c
140.2656 +  Changed pngminim/*/gather.sh to stop trying to remove pnggccrd.c and pngvcrd.c
140.2657 +  Added dependency on pngpriv.h in contrib/pngminim/*/makefile
140.2658 +
140.2659 +Version 1.4.0beta96 [November 12, 2009]
140.2660 +  Renamed scripts/makefile.wce to scripts/makefile.cegcc
140.2661 +  Revised Makefile.am to use libpng.sys while building libpng.so
140.2662 +    so that only PNG_EXPORT functions are exported.
140.2663 +  Removed the deprecated png_check_sig() function/macro.
140.2664 +  Removed recently removed function names from scripts/*.def
140.2665 +  Revised pngtest.png to put chunks in the same order written by pngtest
140.2666 +    (evidently the same change made in libpng-1.0beta54 was lost).
140.2667 +  Added PNG_PRIVATE macro definition in pngconf.h for possible future use.
140.2668 +
140.2669 +Version 1.4.0beta97 [November 13, 2009]
140.2670 +  Restored pngtest.png to the libpng-1.4.0beta7 version.
140.2671 +  Removed projects/beos and netware.txt; no one seems to be supporting them.
140.2672 +  Revised Makefile.in
140.2673 +
140.2674 +Version 1.4.0beta98 [November 13, 2009]
140.2675 +  Added the "xcode" project to zip distributions,
140.2676 +  Fixed a typo in scripts/pngwin.def introduced in beta97.
140.2677 +
140.2678 +Version 1.4.0beta99 [November 14, 2009]
140.2679 +  Moved libpng-config.in and libpng.pc-configure.in out of the scripts
140.2680 +    directory, to libpng-config.in and libpng-pc.in, respectively, and
140.2681 +    modified Makefile.am and configure.ac accordingly.  Now "configure"
140.2682 +    needs nothing from the "scripts" directory.
140.2683 +  Avoid redefining PNG_CONST in pngconf.h
140.2684 +
140.2685 +Version 1.4.0beta100 [November 14, 2009]
140.2686 +  Removed ASM builds from projects/visualc6 and projects/visualc71
140.2687 +  Removed scripts/makefile.nommx and makefile.vcawin32
140.2688 +  Revised CMakeLists.txt to account for new location of libpng-config.in
140.2689 +    and libpng-pc.in
140.2690 +  Updated INSTALL to reflect removal and relocation of files.
140.2691 +
140.2692 +Version 1.4.0beta101 [November 14, 2009]
140.2693 +  Restored the binary files (*.jpg, *.png, some project files) that were
140.2694 +    accidentally deleted from the zip and 7z distributions when the xcode
140.2695 +    project was added.
140.2696 +
140.2697 +Version 1.4.0beta102 [November 18, 2009]
140.2698 +  Added libpng-config.in and libpng-pc.in to the zip and 7z distributions.
140.2699 +  Fixed a typo in projects/visualc6/pngtest.dsp, introduced in beta100.
140.2700 +  Moved descriptions of makefiles and other scripts out of INSTALL into
140.2701 +    scripts/README.txt
140.2702 +  Updated the copyright year in scripts/pngwin.rc from 2006 to 2009.
140.2703 +
140.2704 +Version 1.4.0beta103 [November 21, 2009]
140.2705 +  Removed obsolete comments about ASM from projects/visualc71/README_zlib.txt
140.2706 +  Align row_buf on 16-byte boundary in memory.
140.2707 +  Restored the PNG_WRITE_FLUSH_AFTER_IEND_SUPPORTED guard around the call
140.2708 +    to png_flush() after png_write_IEND().  See 1.4.0beta32, 1.4.0beta50
140.2709 +    changes above and 1.2.30, 1.2.30rc01 and rc03 in 1.2.41 CHANGES.  Someone
140.2710 +    needs this feature.
140.2711 +  Make the 'png_jmpbuf' macro expand to a call that records the correct
140.2712 +    longjmp function as well as returning a pointer to the setjmp
140.2713 +    jmp_buf buffer, and marked direct access to jmpbuf 'deprecated'.
140.2714 +    (John Bowler)
140.2715 +
140.2716 +Version 1.4.0beta104 [November 22, 2009]
140.2717 +  Removed png_longjmp_ptr from scripts/*.def and libpng.3
140.2718 +  Rebuilt configure scripts with autoconf-2.65
140.2719 +
140.2720 +Version 1.4.0beta105 [November 25, 2009]
140.2721 +  Use fast integer PNG_DIVIDE_BY_255() or PNG_DIVIDE_BY_65535()
140.2722 +    to accomplish alpha premultiplication when
140.2723 +    PNG_READ_COMPOSITE_NODIV_SUPPORTED is defined.
140.2724 +  Changed "/255" to "/255.0" in background calculations to make it clear
140.2725 +    that the 255 is used as a double.
140.2726 +
140.2727 +Version 1.4.0beta106 [November 27, 2009]
140.2728 +  Removed premultiplied alpha feature.
140.2729 +
140.2730 +Version 1.4.0beta107 [December 4, 2009]
140.2731 +  Updated README
140.2732 +  Added "#define PNG_NO_PEDANTIC_WARNINGS" in the libpng source files.
140.2733 +  Removed "-DPNG_CONFIGURE_LIBPNG" from the makefiles and projects.
140.2734 +  Revised scripts/makefile.netbsd, makefile.openbsd, and makefile.sco
140.2735 +    to put png.h and pngconf.h in $prefix/include, like the other scripts,
140.2736 +    instead of in $prefix/include/libpng.  Also revised makefile.sco
140.2737 +    to put them in $prefix/include/libpng15 instead of in
140.2738 +    $prefix/include/libpng/libpng15.
140.2739 +
140.2740 +Version 1.4.0beta108 [December 11, 2009]
140.2741 +  Removed leftover "-DPNG_CONFIGURE_LIBPNG" from contrib/pngminim/*/makefile
140.2742 +  Relocated png_do_chop() to its original position in pngrtran.c; the
140.2743 +    change in version 1.2.41beta08 caused transparency to be handled wrong
140.2744 +    in some 16-bit datastreams (Yusaku Sugai).
140.2745 +
140.2746 +Version 1.4.0beta109 [December 13, 2009]
140.2747 +  Added "bit_depth" parameter to the private png_build_gamma_table() function.
140.2748 +  Pass bit_depth=8 to png_build_gamma_table() when bit_depth is 16 but the
140.2749 +    PNG_16_TO_8 transform has been set, to avoid unnecessary build of 16-bit
140.2750 +    tables.
140.2751 +
140.2752 +Version 1.4.0rc02 [December 20, 2009]
140.2753 +  Declared png_cleanup_needed "volatile" in pngread.c and pngwrite.c
140.2754 +
140.2755 +Version 1.4.0rc03 [December 22, 2009]
140.2756 +  Renamed libpng-pc.in back to libpng.pc.in and revised CMakeLists.txt
140.2757 +    (revising the change in 1.4.0beta99)
140.2758 +
140.2759 +Version 1.4.0rc04 [December 25, 2009]
140.2760 +  Swapped PNG_UNKNOWN_CHUNKS_SUPPORTED and PNG_HANDLE_AS_UNKNOWN_SUPPORTED
140.2761 +    in pngset.c to be consistent with other changes in version 1.2.38.
140.2762 +
140.2763 +Version 1.4.0rc05 [December 25, 2009]
140.2764 +  Changed "libpng-pc.in" to "libpng.pc.in" in configure.ac, configure, and
140.2765 +    Makefile.in to be consistent with changes in libpng-1.4.0rc03
140.2766 +
140.2767 +Version 1.4.0rc06 [December 29, 2009]
140.2768 +  Reverted the gamma_table changes from libpng-1.4.0beta109.
140.2769 +  Fixed some indentation errors.
140.2770 +
140.2771 +Version 1.4.0rc07 [January 1, 2010]
140.2772 +  Revised libpng*.txt and libpng.3 about 1.2.x->1.4.x differences.
140.2773 +  Use png_calloc() instead of png_malloc(); png_memset() in pngrutil.c
140.2774 +  Update copyright year to 2010.
140.2775 +
140.2776 +Version 1.4.0rc08 [January 2, 2010]
140.2777 +  Avoid deprecated references to png_ptr-io_ptr and png_ptr->error_ptr
140.2778 +    in pngtest.c
140.2779 +
140.2780 +Version 1.4.0 [January 3, 2010]
140.2781 +  No changes.
140.2782 +
140.2783 +Version 1.4.1beta01 [January 8, 2010]
140.2784 +  Updated CMakeLists.txt for consistent indentation and to avoid an
140.2785 +    unclosed if-statement warning (Philip Lowman).
140.2786 +  Revised Makefile.am and Makefile.in to remove references to Y2KINFO,
140.2787 +    KNOWNBUG, and libpng.la (Robert Schwebel).
140.2788 +  Revised the makefiles to install the same files and symbolic
140.2789 +    links as configure, except for libpng.la and libpng14.la.
140.2790 +  Make png_set|get_compression_buffer_size() available even when
140.2791 +    PNG_WRITE_SUPPORTED is not enabled.
140.2792 +  Revised Makefile.am and Makefile.in to simplify their maintenance.
140.2793 +  Revised scripts/makefile.linux to install a link to libpng14.so.14.1
140.2794 +
140.2795 +Version 1.4.1beta02 [January 9, 2010]
140.2796 +  Revised the rest of the makefiles to install a link to libpng14.so.14.1
140.2797 +
140.2798 +Version 1.4.1beta03 [January 10, 2010]
140.2799 +  Removed png_set_premultiply_alpha() from scripts/*.def
140.2800 +
140.2801 +Version 1.4.1rc01 [January 16, 2010]
140.2802 +  No changes.
140.2803 +
140.2804 +Version 1.4.1beta04 [January 23, 2010]
140.2805 +  Revised png_decompress_chunk() to improve speed and memory usage when
140.2806 +    decoding large chunks.
140.2807 +  Added png_set|get_chunk_malloc_max() functions.
140.2808 +
140.2809 +Version 1.4.1beta05 [January 26, 2010]
140.2810 +  Relocated "int k" declaration in pngtest.c to minimize its scope.
140.2811 +
140.2812 +Version 1.4.1beta06 [January 28, 2010]
140.2813 +  Revised png_decompress_chunk() to use a two-pass method suggested by
140.2814 +    John Bowler.
140.2815 +
140.2816 +Version 1.4.1beta07 [February 6, 2010]
140.2817 +  Folded some long lines in the source files.
140.2818 +  Added defineable PNG_USER_CHUNK_CACHE_MAX, PNG_USER_CHUNK_MALLOC_MAX,
140.2819 +    and a PNG_USER_LIMITS_SUPPORTED flag.
140.2820 +  Eliminated use of png_ptr->irowbytes and reused the slot in png_ptr as
140.2821 +    png_ptr->png_user_chunk_malloc_max.
140.2822 +  Revised png_push_save_buffer() to do fewer but larger png_malloc() calls.
140.2823 +
140.2824 +Version 1.4.1beta08 [February 6, 2010]
140.2825 +  Minor cleanup and updating of dates and copyright year.
140.2826 +
140.2827 +Version 1.5.0beta01 [February 7, 2010]
140.2828 +  Moved declaration of png_struct into private pngstruct.h and png_info
140.2829 +    into pnginfo.h
140.2830 +
140.2831 +Version 1.4.1beta09 and 1.5.0beta02 [February 7, 2010]
140.2832 +  Reverted to original png_push_save_buffer() code.
140.2833 +
140.2834 +Version 1.4.1beta10 and 1.5.0beta03 [February 8, 2010]
140.2835 +  Return allocated "old_buffer" in png_push_save_buffer() before
140.2836 +    calling png_error(), to avoid a potential memory leak.
140.2837 +  Updated configure script to use SO number 15.
140.2838 +
140.2839 +Version 1.5.0beta04 [February 9, 2010]
140.2840 +  Removed malformed "incomplete struct declaration" of png_info from png.h
140.2841 +
140.2842 +Version 1.5.0beta05 [February 12, 2010]
140.2843 +  Removed PNG_DEPSTRUCT markup in pngstruct.h and pnginfo.h, and undid the
140.2844 +    linewrapping that it entailed.
140.2845 +  Revised comments in pngstruct.h and pnginfo.h and added pointers to
140.2846 +    the libpng license.
140.2847 +  Changed PNG_INTERNAL to PNG_EXPOSE_INTERNAL_STRUCTURES
140.2848 +  Removed the cbuilder5 project, which has not been updated to 1.4.0.
140.2849 +
140.2850 +Version 1.4.1beta12 and 1.5.0beta06 [February 14, 2010]
140.2851 +  Fixed type declaration of png_get_chunk_malloc_max() in pngget.c (Daisuke
140.2852 +    Nishikawa)
140.2853 +
140.2854 +Version 1.5.0beta07 [omitted]
140.2855 +
140.2856 +Version 1.5.0beta08 [February 19, 2010]
140.2857 +  Changed #ifdef PNG_NO_STDIO_SUPPORTED to #ifdef PNG_NO_CONSOLE_IO_SUPPORTED
140.2858 +    wherever png_snprintf() is used to construct error and warning messages.
140.2859 +  Noted in scripts/makefile.mingw that it expects to be run under MSYS.
140.2860 +  Removed obsolete unused MMX-querying support from contrib/gregbook
140.2861 +  Added exported png_longjmp() function.
140.2862 +  Removed the AIX redefinition of jmpbuf in png.h
140.2863 +  Added -D_ALLSOURCE in configure.ac, makefile.aix, and CMakeLists.txt
140.2864 +    when building on AIX.
140.2865 +
140.2866 +Version 1.5.0beta09 [February 19, 2010]
140.2867 +  Removed -D_ALLSOURCE from configure.ac, makefile.aix, and CMakeLists.txt.
140.2868 +  Changed the name of png_ptr->jmpbuf to png_ptr->png_jmpbuf in pngstruct.h
140.2869 +
140.2870 +Version 1.5.0beta10 [February 25, 2010]
140.2871 +  Removed unused gzio.c from contrib/pngminim gather and makefile scripts
140.2872 +  Removed replacement error handlers from contrib/gregbook.  Because of
140.2873 +    the new png_longjmp() function they are no longer needed.
140.2874 +
140.2875 +Version 1.5.0beta11 [March 6, 2010]
140.2876 +  Removed checking for already-included setjmp.h from pngconf.h
140.2877 +  Fixed inconsistent indentations and made numerous cosmetic changes.
140.2878 +  Revised the "SEE ALSO" style of libpng.3, libpngpf.3, and png.5
140.2879 +
140.2880 +Version 1.5.0beta12 [March 9, 2010]
140.2881 +  Moved "#include png.h" inside pngpriv.h and removed "#include png.h" from
140.2882 +    the source files, along with "#define PNG_EXPOSE_INTERNAL_STRUCTURES"
140.2883 +    and "#define PNG_NO_PEDANTIC_WARNINGS" (John Bowler).
140.2884 +  Created new pngdebug.h and moved debug definitions there.
140.2885 +
140.2886 +Version 1.5.0beta13 [March 10, 2010]
140.2887 +  Protect pngstruct.h, pnginfo.h, and pngdebug.h from being included twice.
140.2888 +  Revise the "#ifdef" blocks in png_inflate() so it will compile when neither
140.2889 +    PNG_USER_CHUNK_MALLOC_MAX nor PNG_SET_CHUNK_MALLOC_LIMIT_SUPPORTED
140.2890 +    is defined.
140.2891 +  Removed unused png_measure_compressed_chunk() from pngpriv.h and libpngpf.3
140.2892 +  Moved the 'config.h' support from pngconf.h to pngpriv.h
140.2893 +  Removed PNGAPI from the png_longjmp_ptr typedef.
140.2894 +  Eliminated dependence of pngtest.c on the private pngdebug.h file.
140.2895 +  Make all png_debug macros into *unterminated* statements or
140.2896 +    expressions (i.e. a trailing ';' must always be added) and correct
140.2897 +    the format statements in various png_debug messages.
140.2898 +
140.2899 +Version 1.5.0beta14 [March 14, 2010]
140.2900 +  Removed direct access to png_ptr->io_ptr from the Windows code in pngtest.c
140.2901 +  Revised Makefile.am to account for recent additions and replacements.
140.2902 +  Corrected CE and OS/2 DEF files (scripts/png*def) for symbols removed and
140.2903 +    added ordinal numbers to the Windows DEF file and corrected the duplicated
140.2904 +    ordinal numbers on CE symbols that are commented out.
140.2905 +  Added back in export symbols that can be present in the Windows build but
140.2906 +    are disabled by default.
140.2907 +  PNG_EXPORT changed to include an 'ordinal' field for DEF file generation.
140.2908 +    PNG_CALLBACK added to make callback definitions uniform.  PNGAPI split
140.2909 +    into PNGCAPI (base C form), PNGAPI (exports) and PNGCBAPI (callbacks),
140.2910 +    and appropriate changes made to all files.  Cygwin builds re-hinged to
140.2911 +    allow procedure call standard changes and to remove the need for the DEF
140.2912 +    file (fixes build on Cygwin).
140.2913 +  Enabled 'attribute' warnings that are relevant to library APIs and callbacks.
140.2914 +  Changed rules for generation of the various symbol files and added a new
140.2915 +    rule for a DEF file (which is also added to the distribution).
140.2916 +  Updated the symbol file generation to stop it adding spurious spaces
140.2917 +    to EOL (coming from preprocessor macro expansion).  Added a facility
140.2918 +    to join tokens in the output and rewrite *.dfn to use this.
140.2919 +  Eliminated scripts/*.def in favor of libpng.def; updated projects/visualc71
140.2920 +    and removed scripts/makefile.cygwin.
140.2921 +  Made PNG_BUILD_DLL safe: it can be set whenever a DLL is being built.
140.2922 +  Removed the include of sys/types.h - apparently unnecessary now on the
140.2923 +    platforms on which it happened (all but Mac OS and RISC OS).
140.2924 +  Moved the Mac OS test into pngpriv.h (the only place it is used.)
140.2925 +
140.2926 +Version 1.5.0beta15 [March 17, 2010]
140.2927 +  Added symbols.chk target to Makefile.am to validate the symbols in png.h
140.2928 +    against the new DEF file scripts/symbols.def.
140.2929 +  Changed the default DEF file back to pngwin.def.
140.2930 +  Removed makefile.mingw.
140.2931 +  Eliminated PNG_NO_EXTERN and PNG_ALL_EXTERN
140.2932 +
140.2933 +Version 1.5.0beta16 [April 1, 2010]
140.2934 +  Make png_text_struct independent of PNG_iTXt_SUPPORTED, so that
140.2935 +    fields are initialized in all configurations.  The READ/WRITE
140.2936 +    macros (PNG_(READ|WRITE)_iTXt_SUPPORTED) still function as
140.2937 +    before to disable code to actually read or write iTXt chunks
140.2938 +    and iTXt_SUPPORTED can be used to detect presence of either
140.2939 +    read or write support (but it is probably better to check for
140.2940 +    the one actually required - read or write.)
140.2941 +  Combined multiple png_warning() calls for a single error.
140.2942 +  Restored the macro definition of png_check_sig().
140.2943 +
140.2944 +Version 1.5.0beta17 [April 17, 2010]
140.2945 +  Added some "(long)" typecasts to printf calls in png_handle_cHRM().
140.2946 +  Documented the fact that png_set_dither() was disabled since libpng-1.4.0.
140.2947 +  Reenabled png_set_dither() but renamed it to png_set_quantize() to reflect
140.2948 +    more accurately what it actually does.  At the same time, renamed
140.2949 +    the PNG_DITHER_[RED,GREEN_BLUE]_BITS macros to
140.2950 +    PNG_QUANTIZE_[RED,GREEN,BLUE]_BITS.
140.2951 +  Added some "(long)" typecasts to printf calls in png_handle_cHRM().
140.2952 +  Freeze build-time only configuration in the build.
140.2953 +    In all prior versions of libpng most configuration options
140.2954 +    controlled by compiler #defines had to be repeated by the
140.2955 +    application code that used libpng.  This patch changes this
140.2956 +    so that compilation options that can only be changed at build
140.2957 +    time are frozen in the build.  Options that are compiler
140.2958 +    dependent (and those that are system dependent) are evaluated
140.2959 +    each time - pngconf.h holds these.  Options that can be changed
140.2960 +    per-file in the application are in png.h.  Frozen options are
140.2961 +    in the new installed header file pnglibconf.h (John Bowler)
140.2962 +  Removed the xcode project because it has not been updated to work
140.2963 +    with libpng-1.5.0.
140.2964 +  Removed the ability to include optional pngusr.h
140.2965 +
140.2966 +Version 1.5.0beta18 [April 17, 2010]
140.2967 +  Restored the ability to include optional pngusr.h
140.2968 +  Moved replacements for png_error() and png_warning() from the
140.2969 +    contrib/pngminim project to pngerror.c, for use when warnings or
140.2970 +    errors are disabled via PNG_NO_WARN or PNG_NO_ERROR_TEXT, to avoid
140.2971 +    storing unneeded error/warning text.
140.2972 +  Updated contrib/pngminim project to work with the new pnglibconf.h
140.2973 +  Added some PNG_NO_* defines to contrib/pngminim/*/pngusr.h to save space.
140.2974 +
140.2975 +Version 1.5.0beta19 [April 24, 2010]
140.2976 +  Added PNG_{READ,WRITE}_INT_FUNCTIONS_SUPPORTED.  This allows the functions
140.2977 +    to read and write ints to be disabled independently of PNG_USE_READ_MACROS,
140.2978 +    which allows libpng to be built with the functions even though the default
140.2979 +    is to use the macros - this allows applications to choose at app build
140.2980 +    time whether or not to use macros (previously impossible because the
140.2981 +    functions weren't in the default build.)
140.2982 +  Changed Windows calling convention back to __cdecl for API functions.
140.2983 +    For Windows/x86 platforms only:
140.2984 +      __stdcall is no longer needed for Visual Basic, so libpng-1.5.0 uses
140.2985 +      __cdecl throughout (both API functions and callbacks) on Windows/x86
140.2986 +      platforms.
140.2987 +  Replaced visualc6 and visualc71 projects with new vstudio project
140.2988 +  Relaxed the overly-restrictive permissions of some files.
140.2989 +
140.2990 +Version 1.5.0beta20 [April 24, 2010]
140.2991 +  Relaxed more overly-restrictive permissions of some files.
140.2992 +
140.2993 +Version 1.5.0beta21 [April 27, 2010]
140.2994 +  Removed some unwanted binary bytes and changed CRLF to NEWLINE in the new
140.2995 +    vstudio project files, and some trivial editing of some files in the
140.2996 +    scripts directory.
140.2997 +  Set PNG_NO_READ_BGR, PNG_NO_IO_STATE, and PNG_NO_TIME_RFC1123 in
140.2998 +    contrib/pngminim/decoder/pngusr.h to make a smaller decoder application.
140.2999 +
140.3000 +Version 1.5.0beta22 [April 28, 2010]
140.3001 +  Fixed dependencies of GET_INT_32 - it does not require READ_INT_FUNCTIONS
140.3002 +    because it has a macro equivalent.
140.3003 +  Improved the options.awk script; added an "everything off" option.
140.3004 +  Revised contrib/pngminim to use the "everything off" option in pngusr.dfa.
140.3005 +
140.3006 +Version 1.5.0beta23 [April 29, 2010]
140.3007 +  Corrected PNG_REMOVED macro to take five arguments.
140.3008 +    The macro was documented with two arguments (name,ordinal), however
140.3009 +    the symbol checking .dfn files assumed five arguments.  The five
140.3010 +    argument form seems more useful so it is changed to that.
140.3011 +  Corrected PNG_UNKNOWN_CHUNKS_SUPPORTED to PNG_HANDLE_AS_UNKNOWN_SUPPORTED
140.3012 +    in gregbook/readpng2.c
140.3013 +  Corrected protection of png_get_user_transform_ptr. The API declaration in
140.3014 +    png.h is removed if both READ and WRITE USER_TRANSFORM are turned off
140.3015 +    but was left defined in pngtrans.c
140.3016 +  Added logunsupported=1 to cause pnglibconf.h to document disabled options.
140.3017 +    This makes the installed pnglibconf.h more readable but causes no
140.3018 +    other change.  The intention is that users of libpng will find it
140.3019 +    easier to understand if an API they need is missing.
140.3020 +  Include png_reset_zstream() in png.c only when PNG_READ_SUPPORTED is defined.
140.3021 +  Removed dummy_inflate.c from contrib/pngminim/encoder
140.3022 +  Removed contrib/pngminim/*/gather.sh; gathering is now done in the makefile.
140.3023 +
140.3024 +Version 1.5.0beta24 [May 7, 2010]
140.3025 +  Use bitwise "&" instead of arithmetic mod in pngrutil.c calculation of the
140.3026 +    offset of the png_ptr->rowbuf pointer into png_ptr->big_row_buf.
140.3027 +  Added more blank lines for readability.
140.3028 +
140.3029 +Version 1.5.0beta25 [June 18, 2010]
140.3030 +  In pngpread.c: png_push_have_row() add check for new_row > height
140.3031 +  Removed the now-redundant check for out-of-bounds new_row from example.c
140.3032 +
140.3033 +Version 1.5.0beta26 [June 18, 2010]
140.3034 +  In pngpread.c: png_push_process_row() add check for too many rows.
140.3035 +
140.3036 +Version 1.5.0beta27 [June 18, 2010]
140.3037 +  Removed the check added in beta25 as it is now redundant.
140.3038 +
140.3039 +Version 1.5.0beta28 [June 20, 2010]
140.3040 +  Rewrote png_process_IDAT_data to consistently treat extra data as warnings
140.3041 +    and handle end conditions more cleanly.
140.3042 +  Removed the new (beta26) check in png_push_process_row().
140.3043 +
140.3044 +Version 1.5.0beta29 [June 21, 2010]
140.3045 +  Revised scripts/options.awk to work on Sunos (but still doesn't work)
140.3046 +  Added comment to options.awk and contrib/pngminim/*/makefile to try nawk.
140.3047 +
140.3048 +Version 1.5.0beta30 [June 22, 2010]
140.3049 +  Stop memory leak when reading a malformed sCAL chunk.
140.3050 +
140.3051 +Version 1.5.0beta31 [June 26, 2010]
140.3052 +  Revised pngpread.c patch of beta28 to avoid an endless loop.
140.3053 +  Removed some trailing blanks.
140.3054 +
140.3055 +Version 1.5.0beta32 [June 26, 2010]
140.3056 +  Removed leftover scripts/options.patch and scripts/options.rej
140.3057 +
140.3058 +Version 1.5.0beta33 [July 6, 3010]
140.3059 +  Made FIXED and FLOATING options consistent in the APIs they enable and
140.3060 +    disable.  Corrected scripts/options.awk to handle both command line
140.3061 +    options and options specified in the .dfa files.
140.3062 +  Changed char *msg to PNG_CONST char *msg in pngrutil.c
140.3063 +  Make png_set_sRGB_gAMA_and_cHRM set values using either the fixed or
140.3064 +    floating point APIs, but not both.
140.3065 +  Reversed patch to remove error handler when the jmp_buf is stored in the
140.3066 +    main program structure, not the png_struct.
140.3067 +    The error handler is needed because the default handler in libpng will
140.3068 +    always use the jmp_buf in the library control structure; this is never
140.3069 +    set.  The gregbook code is a useful example because, even though it
140.3070 +    uses setjmp/longjmp, it shows how error handling can be implemented
140.3071 +    using control mechanisms not directly supported by libpng.  The
140.3072 +    technique will work correctly with mechanisms such as Microsoft
140.3073 +    Structure Exceptions or C++ exceptions (compiler willing - note that gcc
140.3074 +    does not by default support interworking of C and C++ error handling.)
140.3075 +  Reverted changes to call png_longjmp in contrib/gregbook where it is not
140.3076 +    appropriate.  If mainprog->jmpbuf is used by setjmp, then png_longjmp
140.3077 +    cannot be used.
140.3078 +  Changed "extern PNG_EXPORT" to "PNG_EXPORT" in png.h (Jan Nijtmans)
140.3079 +  Changed "extern" to "PNG_EXTERN" in pngpriv.h (except for the 'extern "C" {')
140.3080 +
140.3081 +Version 1.5.0beta34 [July 12, 2010]
140.3082 +  Put #ifndef PNG_EXTERN, #endif around the define PNG_EXTERN in pngpriv.h
140.3083 +
140.3084 +Version 1.5.0beta35 [July 24, 2010]
140.3085 +  Removed some newly-added TAB characters.
140.3086 +  Added -DNO_PNG_SNPRINTF to CFLAGS in scripts/makefile.dj2
140.3087 +  Moved the definition of png_snprintf() outside of the enclosing
140.3088 +    #ifdef blocks in pngconf.h
140.3089 +
140.3090 +Version 1.5.0beta36 [July 29, 2010]
140.3091 +  Patches by John Bowler:
140.3092 +  Fixed point APIs are now supported throughout (no missing APIs).
140.3093 +  Internal fixed point arithmetic support exists for all internal floating
140.3094 +    point operations.
140.3095 +  sCAL validates the floating point strings it is passed.
140.3096 +  Safe, albeit rudimentary, Watcom support is provided by PNG_API_RULE==2
140.3097 +  Two new APIs exist to get the number of passes without turning on the
140.3098 +    PNG_INTERLACE transform and to get the number of rows in the current
140.3099 +    pass.
140.3100 +  A new test program, pngvalid.c, validates the gamma code.
140.3101 +  Errors in the 16-bit gamma correction (overflows) have been corrected.
140.3102 +  cHRM chunk testing is done consistently (previously the floating point
140.3103 +    API bypassed it, because the test really didn't work on FP, now the test
140.3104 +    is performed on the actual values to be stored in the PNG file so it
140.3105 +    works in the FP case too.)
140.3106 +  Most floating point APIs now simply call the fixed point APIs after
140.3107 +    converting the values to the fixed point form used in the PNG file.
140.3108 +  The standard headers no longer include zlib.h, which is currently only
140.3109 +    required for pngstruct.h and can therefore be internal.
140.3110 +  Revised png_get_int_32 to undo the PNG two's complement representation of
140.3111 +    negative numbers.
140.3112 +
140.3113 +Version 1.5.0beta37 [July 30, 2010]
140.3114 +  Added a typecast in png_get_int_32() in png.h and pngrutil.h to avoid
140.3115 +    a compiler warning.
140.3116 +  Replaced oFFs 0,0 with oFFs -10,20 in pngtest.png
140.3117 +
140.3118 +Version 1.5.0beta38 [July 31, 2010]
140.3119 +  Implemented remaining "_fixed" functions.
140.3120 +  Corrected a number of recently introduced warnings mostly resulting from
140.3121 +    safe but uncast assignments to shorter integers.  Also added a zlib
140.3122 +    VStudio release library project because the latest zlib Official Windows
140.3123 +    build does not include such a thing.
140.3124 +  Revised png_get_int_16() to be similar to png_get_int_32().
140.3125 +  Restored projects/visualc71.
140.3126 +
140.3127 +Version 1.5.0beta39 [August 2, 2010]
140.3128 +  VisualC/GCC warning fixes, VisualC build fixes
140.3129 +  The changes include support for function attributes in VC in addition to
140.3130 +    those already present in GCC - necessary because without these some
140.3131 +    warnings are unavoidable.  Fixes include signed/unsigned fixes in
140.3132 +    pngvalid and checks with gcc -Wall -Wextra -Wunused.
140.3133 +  VC requires function attributes on function definitions as well as
140.3134 +    declarations, PNG_FUNCTION has been added to enable this and the
140.3135 +    relevant function definitions changed.
140.3136 +
140.3137 +Version 1.5.0beta40 [August 6, 2010]
140.3138 +  Correct use of _WINDOWS_ in pngconf.h
140.3139 +  Removed png_mem_ #defines; they are no longer used.
140.3140 +  Added the sRGB chunk to pngtest.png
140.3141 +
140.3142 +Version 1.5.0beta41 [August 11, 2010]
140.3143 +  Added the cHRM chunk to pngtest.png
140.3144 +  Don't try to use version-script with cygwin/mingw.
140.3145 +  Revised contrib/gregbook to work under cygwin/mingw.
140.3146 +
140.3147 +Version 1.5.0beta42 [August 18, 2010]
140.3148 +  Add .dll.a to the list of extensions to be symlinked by Makefile.am (Yaakov)
140.3149 +  Made all API functions that have const arguments and constant string
140.3150 +    literal pointers declare them (John Bowler).
140.3151 +
140.3152 +Version 1.5.0beta43 [August 20, 2010]
140.3153 +  Removed spurious tabs, shorten long lines (no source change)
140.3154 +    Also added scripts/chkfmt to validate the format of all the files that can
140.3155 +    reasonably be validated (it is suggested to run "make distclean" before
140.3156 +    checking, because some machine generated files have long lines.)
140.3157 +  Reformatted the CHANGES file to be more consistent throughout.
140.3158 +  Made changes to address various issues identified by GCC, mostly
140.3159 +    signed/unsigned and shortening problems on assignment but also a few
140.3160 +    difficult to optimize (for GCC) loops.
140.3161 +  Fixed non-GCC fixed point builds.  In png.c a declaration was misplaced
140.3162 +    in an earlier update.  Fixed to declare the auto variables at the head.
140.3163 +  Use cexcept.h in pngvalid.c.
140.3164 +
140.3165 +Version 1.5.0beta44 [August 24, 2010]
140.3166 +  Updated CMakeLists.txt to use CMAKE_INSTALL_LIBDIR variable; useful for
140.3167 +    installing libpng in /usr/lib64 (Funda Wang).
140.3168 +  Revised CMakeLists.txt to put the man pages in share/man/man* not man/man*
140.3169 +  Revised CMakeLists.txt to make symlinks instead of copies when installing.
140.3170 +  Changed PNG_LIB_NAME from pngNN to libpngNN in CMakeLists.txt (Philip Lowman)
140.3171 +  Implemented memory checks within pngvalid
140.3172 +  Reformatted/rearranged pngvalid.c to assist use of progressive reader.
140.3173 +  Check interlaced images in pngvalid
140.3174 +  Clarified pngusr.h comments in pnglibconf.dfa
140.3175 +  Simplified the pngvalid error-handling code now that cexcept.h is in place.
140.3176 +  Implemented progressive reader in pngvalid.c for standard tests
140.3177 +  Implemented progressive read in pngvalid.c gamma tests
140.3178 +  Turn on progressive reader in pngvalid.c by default and tidy code.
140.3179 +
140.3180 +Version 1.5.0beta45 [August 26, 2010]
140.3181 +  Added an explicit make step to projects/vstudio for pnglibconf.h
140.3182 +    Also corrected zlib.vcxproj into which Visual Studio had introduced
140.3183 +    what it calls an "authoring error".  The change to make pnglibconf.h
140.3184 +    simply copies the file; in the future it may actually generate the
140.3185 +    file from scripts/pnglibconf.dfa as the other build systems do.
140.3186 +  Changed pngvalid to work when floating point APIs are disabled
140.3187 +  Renamed the prebuilt scripts/pnglibconf.h to scripts/pnglibconf.h.prebuilt
140.3188 +  Supply default values for PNG_USER_PRIVATEBUILD and PNG_USER_DLLFNAME_POSTFIX
140.3189 +    in pngpriv.h in case the user neglected to define them in their pngusr.h
140.3190 +
140.3191 +Version 1.5.0beta46 [August 28, 2010]
140.3192 +  Added new private header files to libpng_sources in CMakeLists.txt
140.3193 +  Added PNG_READ_16BIT, PNG_WRITE_16BIT, and PNG_16BIT options.
140.3194 +  Added reference to scripts/pnglibconf.h.prebuilt in the visualc71 project.
140.3195 +
140.3196 +Version 1.5.0beta47 [September 11, 2010]
140.3197 +  Fixed a number of problems with 64-bit compilation reported by Visual
140.3198 +    Studio 2010 (John Bowler).
140.3199 +
140.3200 +Version 1.5.0beta48 [October 4, 2010]
140.3201 +  Updated CMakeLists.txt (Philip Lowman).
140.3202 +  Revised autogen.sh to recognize and use $AUTOCONF, $AUTOMAKE, $AUTOHEADER,
140.3203 +    $AUTOPOINT, $ACLOCAL and $LIBTOOLIZE
140.3204 +  Fixed problem with symbols creation in Makefile.am which was assuming that
140.3205 +    all versions of ccp write to standard output by default (Martin Banky). The
140.3206 +    bug was introduced in libpng-1.2.9beta5.
140.3207 +  Removed unused mkinstalldirs.
140.3208 +
140.3209 +Version 1.5.0beta49 [October 8, 2010]
140.3210 +  Undid Makefile.am revision of 1.5.0beta48.
140.3211 +
140.3212 +Version 1.5.0beta50 [October 14, 2010]
140.3213 +  Revised Makefile.in to account for mkinstalldirs being removed.
140.3214 +  Added some "(unsigned long)" typecasts in printf statements in pngvalid.c.
140.3215 +  Suppressed a compiler warning in png_handle_sPLT().
140.3216 +  Check for out-of-range text compression mode in png_set_text().
140.3217 +
140.3218 +Version 1.5.0beta51 [October 15, 2010]
140.3219 +  Changed embedded dates to "(PENDING RELEASE) in beta releases (and future
140.3220 +    rc releases) to minimize the difference between releases.
140.3221 +
140.3222 +Version 1.5.0beta52 [October 16, 2010]
140.3223 +  Restored some of the embedded dates (in png.h, png.c, documentation, etc.)
140.3224 +
140.3225 +Version 1.5.0beta53 [October 18, 2010]
140.3226 +  Updated INSTALL to mention using "make maintainer-clean" and to remove
140.3227 +    obsolete statement about a custom ltmain.sh
140.3228 +  Disabled "color-tests" by default in Makefile.am so it will work with
140.3229 +    automake versions earlier than 1.11.1
140.3230 +  Use document name "libpng-manual.txt" instead of "libpng-<version>.txt"
140.3231 +    to simplify version differences.
140.3232 +  Removed obsolete remarks about setjmp handling from INSTALL.
140.3233 +  Revised and renamed the typedef in png.h and png.c that was designed
140.3234 +    to catch library and header mismatch.
140.3235 +
140.3236 +Version 1.5.0beta54 [November 10, 2010]
140.3237 +  Require 48 bytes, not 64 bytes, for big_row_buf in overflow checks.
140.3238 +  Used a consistent structure for the pngget.c functions.
140.3239 +
140.3240 +Version 1.5.0beta55 [November 21, 2010]
140.3241 +  Revised png_get_uint_32, png_get_int_32, png_get_uint_16 (Cosmin)
140.3242 +  Moved reading of file signature into png_read_sig (Cosmin)
140.3243 +  Fixed atomicity of chunk header serialization (Cosmin)
140.3244 +  Added test for io_state in pngtest.c (Cosmin)
140.3245 +  Added "#!/bin/sh" at the top of contrib/pngminim/*/gather.sh scripts.
140.3246 +  Changes to remove gcc warnings (John Bowler)
140.3247 +    Certain optional gcc warning flags resulted in warnings in libpng code.
140.3248 +    With these changes only -Wconversion and -Wcast-qual cannot be turned on.
140.3249 +    Changes are trivial rearrangements of code.  -Wconversion is not possible
140.3250 +    for pngrutil.c (because of the widespread use of += et al on variables
140.3251 +    smaller than (int) or (unsigned int)) and -Wcast-qual is not possible
140.3252 +    with pngwio.c and pngwutil.c because the 'write' callback and zlib
140.3253 +    compression both fail to declare their input buffers with 'const'.
140.3254 +
140.3255 +Version 1.5.0beta56 [December 7, 2010]
140.3256 +  Added the private PNG_UNUSED() macro definition in pngpriv.h.
140.3257 +  Added some commentary about PNG_EXPORT in png.h and pngconf.h
140.3258 +  Revised PNG_EXPORT() macro and added PNG_EXPORTA() macro, with the
140.3259 +    objective of simplifying and improving the cosmetic appearance of png.h.
140.3260 +  Fixed some incorrect "=" macro names in pnglibconf.dfa
140.3261 +  Included documentation of changes in 1.5.0 from 1.4.x in libpng-manual.txt
140.3262 +
140.3263 +Version 1.5.0beta57 [December 9, 2010]
140.3264 +  Documented the pngvalid gamma error summary with additional comments and
140.3265 +    print statements.
140.3266 +  Improved missing symbol handling in checksym.awk; symbols missing in both
140.3267 +    the old and new files can now be optionally ignored, treated as errors
140.3268 +    or warnings.
140.3269 +  Removed references to pngvcrd.c and pnggccrd.c from the vstudio project.
140.3270 +  Updated "libpng14" to "libpng15" in the visualc71 project.
140.3271 +  Enabled the strip16 tests in pngvalid.`
140.3272 +  Don't display test results (except PASS/FAIL) when running "make test".
140.3273 +    Instead put them in pngtest-log.txt
140.3274 +  Added "--with-zprefix=<string>" to configure.ac
140.3275 +  Updated the prebuilt configuration files to autoconf version 2.68
140.3276 +
140.3277 +Version 1.5.0beta58 [December 19, 2010]
140.3278 +  Fixed interlace image handling and add test cases (John Bowler)
140.3279 +  Fixed the clean rule in Makefile.am to remove pngtest-log.txt
140.3280 +  Made minor changes to work around warnings in gcc 3.4
140.3281 +
140.3282 +Version 1.5.0rc01 [December 27, 2010]
140.3283 +  No changes.
140.3284 +
140.3285 +Version 1.5.0rc02 [December 27, 2010]
140.3286 +  Eliminated references to the scripts/*.def files in project/visualc71.
140.3287 +
140.3288 +Version 1.5.0rc03 [December 28, 2010]
140.3289 +  Eliminated scripts/*.def and revised Makefile.am accordingly
140.3290 +
140.3291 +Version 1.5.0rc04 [December 29, 2010]
140.3292 +  Fixed bug in background transformation handling in pngrtran.c (it was
140.3293 +    looking for the flag in png_ptr->transformations instead of in
140.3294 +    png_ptr->flags) (David Raymond).
140.3295 +
140.3296 +Version 1.5.0rc05 [December 31, 2010]
140.3297 +  Fixed typo in a comment in CMakeLists.txt (libpng14 => libpng15) (Cosmin)
140.3298 +
140.3299 +Version 1.5.0rc06 [January 4, 2011]
140.3300 +  Changed the new configure option "zprefix=string" to "zlib-prefix=string"
140.3301 +
140.3302 +Version 1.5.0rc07 [January 4, 2011]
140.3303 +  Updated copyright year.
140.3304 +
140.3305 +Version 1.5.0 [January 6, 2011]
140.3306 +  No changes.
140.3307 +
140.3308 +version 1.5.1beta01 [January 8, 2011]
140.3309 +  Added description of png_set_crc_action() to the manual.
140.3310 +  Added a note in the manual that the type of the iCCP profile was changed
140.3311 +    from png_charpp to png_bytepp in png_get_iCCP().  This change happened
140.3312 +    in version 1.5.0beta36 but is not noted in the CHANGES.  Similarly,
140.3313 +    it was changed from png_charpp to png_const_bytepp in png_set_iCCP().
140.3314 +  Ensure that png_rgb_to_gray ignores palette mapped images, if libpng
140.3315 +    internally happens to call it with one.
140.3316 +  Fixed a failure to handle palette mapped images correctly.
140.3317 +
140.3318 +Version 1.5.1beta02 [January 14, 2011]
140.3319 +  Fixed a bug in handling of interlaced images (bero at arklinux.org).
140.3320 +  Updated CMakeLists.txt (Clifford Yapp)
140.3321 +
140.3322 +Version 1.5.1beta03 [January 14, 2011]
140.3323 +  Fixed typecasting of some png_debug() statements (Cosmin)
140.3324 +
140.3325 +Version 1.5.1beta04 [January 16, 2011]
140.3326 +  Updated documentation of png_set|get_tRNS() (Thomas Klausner).
140.3327 +  Mentioned in the documentation that applications must #include "zlib.h"
140.3328 +    if they need access to anything in zlib.h, and that a number of
140.3329 +    macros such as png_memset() are no longer accessible by applications.
140.3330 +  Corrected pngvalid gamma test "sample" function to access all of the color
140.3331 +    samples of each pixel, instead of sampling the red channel three times.
140.3332 +  Prefixed variable names index, div, exp, gamma with "png_" to avoid "shadow"
140.3333 +    warnings, and (mistakenly) changed png_exp() to exp().
140.3334 +
140.3335 +Version 1.5.1beta05 [January 16, 2011]
140.3336 +  Changed variable names png_index, png_div, png_exp, and png_gamma to
140.3337 +    char_index, divisor, exp_b10, and gamma_val, respectively, and
140.3338 +    changed exp() back to png_exp().
140.3339 +
140.3340 +Version 1.5.1beta06 [January 20, 2011]
140.3341 +  Prevent png_push_crc_skip() from hanging while reading an unknown chunk
140.3342 +    or an over-large compressed zTXt chunk with the progressive reader.
140.3343 +  Eliminated more GCC "shadow" warnings.
140.3344 +  Revised png_fixed() in png.c to avoid compiler warning about reaching the
140.3345 +    end without returning anything.
140.3346 +
140.3347 +Version 1.5.1beta07 [January 22, 2011]
140.3348 +  In the manual, describe the png_get_IHDR() arguments in the correct order.
140.3349 +  Added const_png_structp and const_png_infop types, and used them in
140.3350 +    prototypes for most png_get_*() functions.
140.3351 +
140.3352 +Version 1.5.1beta08 [January 23, 2011]
140.3353 +  Added png_get_io_chunk_type() and deprecated png_get_io_chunk_name()
140.3354 +  Added synopses for the IO_STATE functions and other missing synopses
140.3355 +    to the manual. Removed the synopses from libpngpf.3 because they
140.3356 +    were out of date and no longer useful.  Better information can be
140.3357 +    obtained by reading the prototypes and comments in pngpriv.h
140.3358 +  Attempted to fix cpp on Solaris with S. Studio 12 cc, fix build
140.3359 +    Added a make macro DFNCPP that is a CPP that will accept the tokens in
140.3360 +    a .dfn file and adds configure stuff to test for such a CPP.  ./configure
140.3361 +    should fail if one is not available.
140.3362 +  Corrected const_png_ in png.h to png_const_ to avoid polluting the namespace.
140.3363 +  Added png_get_current_row_number and png_get_current_pass_number for the
140.3364 +    benefit of the user transform callback.
140.3365 +  Added png_process_data_pause and png_process_data_skip for the benefit of
140.3366 +    progressive readers that need to stop data processing or want to optimize
140.3367 +    skipping of unread data (e.g., if the reader marks a chunk to be skipped.)
140.3368 +
140.3369 +Version 1.5.1beta09 [January 24, 2011]
140.3370 +  Enhanced pngvalid, corrected an error in gray_to_rgb, corrected doc error.
140.3371 +    pngvalid contains tests of transforms, which tests are currently disabled
140.3372 +    because they are incompletely tested.  gray_to_rgb was failing to expand
140.3373 +    the bit depth for smaller bit depth images; this seems to be a long
140.3374 +    standing error and resulted, apparently, in invalid output
140.3375 +    (CVE-2011-0408, CERT VU#643140).  The documentation did not accurately
140.3376 +    describe what libpng really does when converting RGB to gray.
140.3377 +
140.3378 +Version 1.5.1beta10 [January 27, 2010]
140.3379 +  Fixed incorrect examples of callback prototypes in the manual, that were
140.3380 +    introduced in libpng-1.0.0.
140.3381 +  In addition the order of the png_get_uint macros with respect to the
140.3382 +    relevant function definitions has been reversed.  This helps the
140.3383 +    preprocessing of the symbol files be more robust.  Furthermore, the
140.3384 +    symbol file preprocessing now uses -DPNG_NO_USE_READ_MACROS even when
140.3385 +    the library may actually be built with PNG_USE_READ_MACROS; this stops
140.3386 +    the read macros interfering with the symbol file format.
140.3387 +  Made the manual, synopses, and function prototypes use the function
140.3388 +    argument names file_gamma, int_file_gamma, and srgb_intent consistently.
140.3389 +
140.3390 +Version 1.5.1beta11 [January 28, 2011]
140.3391 +  Changed PNG_UNUSED from "param=param;" to "{if(param){}}".
140.3392 +  Corrected local variable type in new API png_process_data_skip()
140.3393 +    The type was self-evidently incorrect but only causes problems on 64-bit
140.3394 +    architectures.
140.3395 +  Added transform tests to pngvalid and simplified the arguments.
140.3396 +
140.3397 +Version 1.5.1rc01 [January 29, 2011]
140.3398 +  No changes.
140.3399 +
140.3400 +Version 1.5.1rc02 [January 31, 2011]
140.3401 +  Added a request in the manual that applications do not use "png_" or
140.3402 +    "PNG_" to begin any of their own symbols.
140.3403 +  Changed PNG_UNUSED to "(void)param;" and updated the commentary in pngpriv.h
140.3404 +
140.3405 +Version 1.5.1 [February 3, 2011]
140.3406 +  No changes.
140.3407 +
140.3408 +Version 1.5.2beta01 [February 13, 2011]
140.3409 +  More -Wshadow fixes for older gcc compilers.  Older gcc versions apparently
140.3410 +    check formal parameters names in function declarations (as well as
140.3411 +    definitions) to see if they match a name in the global namespace.
140.3412 +  Revised PNG_EXPORTA macro to not use an empty parameter, to accommodate the
140.3413 +    old VisualC++ preprocessor.
140.3414 +  Turned on interlace handling in png_read_png().
140.3415 +  Fixed gcc pendantic warnings.
140.3416 +  Handle longjmp in Cygwin.
140.3417 +  Fixed png_get_current_row_number() in the interlaced case.
140.3418 +  Cleaned up ALPHA flags and transformations.
140.3419 +  Implemented expansion to 16 bits.
140.3420 +
140.3421 +Version 1.5.2beta02 [February 19, 2011]
140.3422 +  Fixed mistake in the descriptions of user read_transform and write_transform
140.3423 +    function prototypes in the manual.  The row_info struct is png_row_infop.
140.3424 +  Reverted png_get_current_row_number() to previous (1.5.2beta01) behavior.
140.3425 +  Corrected png_get_current_row_number documentation
140.3426 +  Fixed the read/write row callback documentation.
140.3427 +    This documents the current behavior, where the callback is called after
140.3428 +    every row with information pertaining to the next row.
140.3429 +
140.3430 +Version 1.5.2beta03 [March 3, 2011]
140.3431 +  Fixed scripts/makefile.vcwin32
140.3432 +  Updated contrib/pngsuite/README to add the word "modify".
140.3433 +  Define PNG_ALLOCATED to blank when _MSC_VER<1300.
140.3434 +
140.3435 +Version 1.5.2rc01 [March 19, 2011]
140.3436 +  Define remaining attributes to blank when MSC_VER<1300.
140.3437 +  ifdef out mask arrays in pngread.c when interlacing is not supported.
140.3438 +
140.3439 +Version 1.5.2rc02 [March 22, 2011]
140.3440 +  Added a hint to try CPP=/bin/cpp if "cpp -E" fails in scripts/pnglibconf.mak
140.3441 +    and in contrib/pngminim/*/makefile, eg., on SunOS 5.10, and removed "strip"
140.3442 +    from the makefiles.
140.3443 +  Fixed a bug (present since libpng-1.0.7) that makes png_handle_sPLT() fail
140.3444 +    to compile when PNG_NO_POINTER_INDEXING is defined (Chubanov Kirill)
140.3445 +
140.3446 +Version 1.5.2rc03 [March 24, 2011]
140.3447 +  Don't include standard header files in png.h while building the symbol table,
140.3448 +    to avoid cpp failure on SunOS (introduced PNG_BUILDING_SYMBOL_TABLE macro).
140.3449 +
140.3450 +Version 1.5.2 [March 31, 2011]
140.3451 +  No changes.
140.3452 +
140.3453 +Version 1.5.3beta01 [April 1, 2011]
140.3454 +  Re-initialize the zlib compressor before compressing non-IDAT chunks.
140.3455 +  Added API functions to set parameters for zlib compression of non-IDAT
140.3456 +    chunks.
140.3457 +
140.3458 +Version 1.5.3beta02 [April 3, 2011]
140.3459 +  Updated scripts/symbols.def with new API functions.
140.3460 +  Only compile the new zlib re-initializing code when text or iCCP is
140.3461 +    supported, using PNG_WRITE_COMPRESSED_TEXT_SUPPORTED macro.
140.3462 +  Improved the optimization of the zlib CMF byte (see libpng-1.2.6beta03).
140.3463 +  Optimize the zlib CMF byte in non-IDAT compressed chunks
140.3464 +
140.3465 +Version 1.5.3beta03 [April 16, 2011]
140.3466 +  Fixed gcc -ansi -pedantic compile. A strict ANSI system does not have
140.3467 +    snprintf, and the "__STRICT_ANSI__" detects that condition more reliably
140.3468 +    than __STDC__ (John Bowler).
140.3469 +  Removed the PNG_PTR_NORETURN attribute because it too dangerous. It tells
140.3470 +    the compiler that a user supplied callback (the error handler) does not
140.3471 +    return, yet there is no guarantee in practice that the application code
140.3472 +    will correctly implement the error handler because the compiler only
140.3473 +    issues a warning if there is a mistake (John Bowler).
140.3474 +  Removed the no-longer-used PNG_DEPSTRUCT macro.
140.3475 +  Updated the zlib version to 1.2.5 in the VStudio project.
140.3476 +  Fixed 64-bit builds where png_uint_32 is smaller than png_size_t in
140.3477 +    pngwutil.c (John Bowler).
140.3478 +  Fixed bug with stripping the filler or alpha channel when writing, that
140.3479 +    was introduced in libpng-1.5.2beta01 (bug report by Andrew Church).
140.3480 +
140.3481 +Version 1.5.3beta04 [April 27, 2011]
140.3482 +  Updated pngtest.png with the new zlib CMF optimization.
140.3483 +  Cleaned up conditional compilation code and of background/gamma handling
140.3484 +    Internal changes only except a new option to avoid compiling the
140.3485 +    png_build_grayscale_palette API (which is not used at all internally.)
140.3486 +    The main change is to move the transform tests (READ_TRANSFORMS,
140.3487 +    WRITE_TRANSFORMS) up one level to the caller of the APIs.  This avoids
140.3488 +    calls to spurious functions if all transforms are disabled and slightly
140.3489 +    simplifies those functions.  Pngvalid modified to handle this.
140.3490 +    A minor change is to stop the strip_16 and expand_16 interfaces from
140.3491 +    disabling each other; this allows the future alpha premultiplication
140.3492 +    code to use 16-bit intermediate values while still producing 8-bit output.
140.3493 +    png_do_background and png_do_gamma have been simplified to take a single
140.3494 +    pointer to the png_struct rather than pointers to every item required
140.3495 +    from the png_struct. This makes no practical difference to the internal
140.3496 +    code.
140.3497 +  A serious bug in the pngvalid internal routine 'standard_display_init' has
140.3498 +    been fixed - this failed to initialize the red channel and accidentally
140.3499 +    initialized the alpha channel twice.
140.3500 +  Changed png_struct jmp_buf member name from png_jmpbuf to tmp_jmpbuf to
140.3501 +    avoid a possible clash with the png_jmpbuf macro on some platforms.
140.3502 +
140.3503 +Version 1.5.3beta05 [May 6, 2011]
140.3504 +  Added the "_POSIX_SOURCE" feature test macro to ensure libpng sees the
140.3505 +    correct API. _POSIX_SOURCE is defined in pngpriv.h, pngtest.c and
140.3506 +    pngvalid.c to ensure that POSIX conformant systems disable non-POSIX APIs.
140.3507 +  Removed png_snprintf and added formatted warning messages.  This change adds
140.3508 +    internal APIs to allow png_warning messages to have parameters without
140.3509 +    requiring the host OS to implement snprintf.  As a side effect the
140.3510 +    dependency of the tIME-supporting RFC1132 code on stdio is removed and
140.3511 +    PNG_NO_WARNINGS does actually work now.
140.3512 +  Pass "" instead of '\0' to png_default_error() in png_err().  This mistake
140.3513 +    was introduced in libpng-1.2.20beta01.
140.3514 +  Added PNG_WRITE_OPTIMIZE_CMF_SUPPORTED macro to make the zlib "CMF" byte
140.3515 +    optimization configureable.
140.3516 +  IDAT compression failed if preceded by a compressed text chunk (bug
140.3517 +    introduced in libpng-1.5.3beta01-02).  This was because the attempt to
140.3518 +    reset the zlib stream in png_write_IDAT happened after the first IDAT
140.3519 +    chunk had been deflated - much too late.  In this change internal
140.3520 +    functions were added to claim/release the z_stream and, hopefully, make
140.3521 +    the code more robust.  Also deflateEnd checking is added - previously
140.3522 +    libpng would ignore an error at the end of the stream.
140.3523 +
140.3524 +Version 1.5.3beta06 [May 8, 2011]
140.3525 +  Removed the -D_ALL_SOURCE from definitions for AIX in CMakeLists.txt
140.3526 +  Implemented premultiplied alpha support: png_set_alpha_mode API
140.3527 +
140.3528 +Version 1.5.3beta07 [May 11, 2011]
140.3529 +  Added expand_16 support to the high level interface.
140.3530 +  Added named value and 'flag' gamma support to png_set_gamma.  Made a minor
140.3531 +    change from the previous (unreleased) ABI/API to hide the exact value used
140.3532 +    for Macs - it's not a good idea to embed this in the ABI!
140.3533 +  Moved macro definitions for PNG_HAVE_IHDR, PNG_HAVE_PLTE, and PNG_AFTER_IDAT
140.3534 +    from pngpriv.h to png.h because they must be visible to applications
140.3535 +    that call png_set_unknown_chunks().
140.3536 +  Check for up->location !PNG_AFTER_IDAT when writing unknown chunks
140.3537 +    before IDAT.
140.3538 +
140.3539 +Version 1.5.3beta08 [May 16, 2011]
140.3540 +  Improved "pngvalid --speed" to exclude more of pngvalid from the time.
140.3541 +  Documented png_set_alpha_mode(), other changes in libpng.3/libpng-manual.txt
140.3542 +  The cHRM chunk now sets the defaults for png_set_rgb_to_gray() (when negative
140.3543 +    parameters are supplied by the caller), while in the absence of cHRM
140.3544 +    sRGB/Rec 709 values are still used.
140.3545 +  The bKGD chunk no longer overwrites the background value set by
140.3546 +    png_set_background(), allowing the latter to be used before the file
140.3547 +    header is read. It never performed any useful function to override
140.3548 +    the default anyway.
140.3549 +  Added memory overwrite and palette image checks to pngvalid.c
140.3550 +    Previously palette image code was poorly checked. Since the transformation
140.3551 +    code has a special palette path in most cases this was a severe weakness.
140.3552 +  Minor cleanup and some extra checking in pngrutil.c and pngrtran.c. When
140.3553 +    expanding an indexed image, always expand to RGBA if transparency is
140.3554 +    present.
140.3555 +
140.3556 +Version 1.5.3beta09 [May 17, 2011]
140.3557 +  Reversed earlier 1.5.3 change of transformation order; move png_expand_16
140.3558 +    back where it was.  The change doesn't work because it requires 16-bit
140.3559 +    gamma tables when the code only generates 8-bit ones.  This fails
140.3560 +    silently; the libpng code just doesn't do any gamma correction.  Moving
140.3561 +    the tests back leaves the old, inaccurate, 8-bit gamma calculations, but
140.3562 +    these are clearly better than none!
140.3563 +
140.3564 +Version 1.5.3beta10 [May 20, 2011]
140.3565 +
140.3566 +  png_set_background() and png_expand_16() did not work together correctly.
140.3567 +    This problem is present in 1.5.2; if png_set_background is called with
140.3568 +    need_expand false and the matching 16 bit color libpng erroneously just
140.3569 +    treats it as an 8-bit color because of where png_do_expand_16 is in the
140.3570 +    transform list.  This simple fix reduces the supplied colour to 8-bits,
140.3571 +    so it gets smashed, but this is better than the current behavior.
140.3572 +  Added tests for expand16, more fixes for palette image tests to pngvalid.
140.3573 +    Corrects the code for palette image tests and disables attempts to
140.3574 +    validate palette colors.
140.3575 +
140.3576 +Version 1.5.3rc01 [June 3, 2011]
140.3577 +  No changes.
140.3578 +
140.3579 +Version 1.5.3rc02 [June 8, 2011]
140.3580 +  Fixed uninitialized memory read in png_format_buffer() (Bug report by
140.3581 +    Frank Busse, CVE-2011-2501, related to CVE-2004-0421).
140.3582 +
140.3583 +Version 1.5.3beta11 [June 11, 2011]
140.3584 +  Fixed png_handle_sCAL which is broken in 1.5; added sCAL to pngtest.png
140.3585 +  Revised documentation about png_set_user_limits() to say that it also affects
140.3586 +    png writing.
140.3587 +  Revised handling of png_set_user_limits() so that it can increase the
140.3588 +    limit beyond the PNG_USER_WIDTH|HEIGHT_MAX; previously it could only
140.3589 +    reduce it.
140.3590 +  Make the 16-to-8 scaling accurate. Dividing by 256 with no rounding is
140.3591 +    wrong (high by one) 25% of the time. Dividing by 257 with rounding is
140.3592 +    wrong in 128 out of 65536 cases. Getting the right answer all the time
140.3593 +    without division is easy.
140.3594 +  Added "_SUPPORTED" to the PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION macro.
140.3595 +  Added projects/owatcom, an IDE project for OpenWatcom to replace
140.3596 +    scripts/makefile.watcom.  This project works with OpenWatcom 1.9. The
140.3597 +    IDE autogenerates appropriate makefiles (libpng.mk) for batch processing.
140.3598 +    The project is configurable, unlike the Visual Studio project, so long
140.3599 +    as the developer has an awk.
140.3600 +  Changed png_set_gAMA to limit the gamma value range so that the inverse
140.3601 +    of the stored value cannot overflow the fixed point representation,
140.3602 +    and changed other things OpenWatcom warns about.
140.3603 +  Revised pngvalid.c to test PNG_ALPHA_MODE_SUPPORTED correctly. This allows
140.3604 +    pngvalid to build when ALPHA_MODE is not supported, which is required if
140.3605 +    it is to build on libpng 1.4.
140.3606 +  Removed string/memory macros that are no longer used and are not
140.3607 +    necessarily fully supportable, particularly png_strncpy and png_snprintf.
140.3608 +  Added log option to pngvalid.c and attempted to improve gamma messages.
140.3609 +  
140.3610 +Version 1.5.3 [omitted]
140.3611 +  People found the presence of a beta release following an rc release
140.3612 +    to be confusing; therefore we bump the version to libpng-1.5.4beta01
140.3613 +    and there will be no libpng-1.5.3 release.
140.3614 +
140.3615 +Version 1.5.4beta01 [June 14, 2011]
140.3616 +  Made it possible to undefine PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED
140.3617 +    to get the same (inaccurate) output as libpng-1.5.2 and earlier.
140.3618 +  Moved definitions of PNG_HAVE_IHDR, PNG_AFTER_IDAT, and PNG_HAVE_PLTE
140.3619 +    outside of an unknown-chunk block in png.h because they are also
140.3620 +    needed for other uses.
140.3621 +
140.3622 +Version 1.5.4beta02 [June 14, 2011]
140.3623 +  Fixed and clarified LEGACY 16-to-8 scaling code.
140.3624 +  Added png_set_chop_16() API, to match inaccurate results from previous
140.3625 +    libpng versions.
140.3626 +  Removed the ACCURATE and LEGACY options (they are no longer useable)
140.3627 +  Use the old scaling method for background if png_set_chop_16() was
140.3628 +    called.
140.3629 +  Made png_set_chop_16() API removeable by disabling PNG_CHOP_16_TO_8_SUPPORTED
140.3630 +
140.3631 +Version 1.5.4beta03 [June 15, 2011]
140.3632 +  Fixed a problem in png_do_expand_palette() exposed by optimization in
140.3633 +    1.5.3beta06
140.3634 +  Also removed a spurious and confusing "trans" member ("trans") from png_info.
140.3635 +  The palette expand optimization prevented expansion to an intermediate RGBA
140.3636 +    form if tRNS was present but alpha was marked to be stripped; this exposed
140.3637 +    a check for tRNS in png_do_expand_palette() which is inconsistent with the
140.3638 +    code elsewhere in libpng.
140.3639 +  Correction to the expand_16 code; removed extra instance of
140.3640 +    png_set_scale_16_to_8 from pngpriv.h
140.3641 +
140.3642 +Version 1.5.4beta04 [June 16, 2011]
140.3643 +  Added a missing "#ifdef PNG_READ_BACKGROUND_SUPPORTED/#endif" in pngrtran.c
140.3644 +  Added PNG_TRANSFORM_CHOP_16 to the high-level read transforms.
140.3645 +  Made PNG_READ_16_TO_8_ACCURATE_SCALE configurable again.  If this is
140.3646 +    not enabled, png_set_strip_16() and png_do_scale_16_to_8() aren't built.
140.3647 +  Revised contrib/visupng, gregbook, and pngminim to demonstrate chop_16_to_8
140.3648 +
140.3649 +Version 1.5.4beta05 [June 16, 2011]
140.3650 +  Renamed png_set_strip_16() to png_set_scale_16() and renamed
140.3651 +    png_set_chop_16() to png_set_strip(16) in an attempt to minimize the
140.3652 +    behavior changes between libpng14 and libpng15.
140.3653 +
140.3654 +Version 1.5.4beta06 [June 18, 2011]
140.3655 +  Fixed new bug that was causing both strip_16 and scale_16 to be applied.
140.3656 +
140.3657 +Version 1.5.4beta07 [June 19, 2011]
140.3658 +  Fixed pngvalid, simplified macros, added checking for 0 in sCAL.
140.3659 +    The ACCURATE scale macro is no longer defined in 1.5 - call the
140.3660 +    png_scale_16_to_8 API.  Made sure that PNG_READ_16_TO_8 is still defined
140.3661 +    if the png_strip_16_to_8 API is present.  png_check_fp_number now
140.3662 +    maintains some state so that positive, negative and zero values are
140.3663 +    identified.  sCAL uses these to be strictly spec conformant.
140.3664 +
140.3665 +Version 1.5.4beta08 [June 23, 2011]
140.3666 +  Fixed pngvalid if ACCURATE_SCALE is defined.
140.3667 +  Updated scripts/pnglibconf.h.prebuilt.
140.3668 +
140.3669 +Version 1.5.4rc01 [June 30, 2011]
140.3670 +  Define PNG_ALLOCATED to "restrict" only if MSC_VER >= 1400.
140.3671 +
140.3672 +Version 1.5.4 [July 7, 2011]
140.3673 +
140.3674  Send comments/corrections/commendations to png-mng-implement at lists.sf.net
140.3675  (subscription required; visit
140.3676  https://lists.sourceforge.net/lists/listinfo/png-mng-implement
140.3677 @@ -1760,3 +3540,5 @@
140.3678  or to glennrp at users.sourceforge.net
140.3679  
140.3680  Glenn R-P
140.3681 +*/ }
140.3682 +#endif
   141.1 --- a/src/share/native/sun/awt/libpng/LICENSE	Fri Sep 30 17:20:56 2011 -0700
   141.2 +++ b/src/share/native/sun/awt/libpng/LICENSE	Tue Oct 04 12:39:42 2011 -0700
   141.3 @@ -8,8 +8,10 @@
   141.4  If you modify libpng you may insert additional notices immediately following
   141.5  this sentence.
   141.6  
   141.7 -libpng versions 1.2.6, August 15, 2004, through 1.2.18, May 15, 2007, are
   141.8 -Copyright (c) 2004, 2006-2007 Glenn Randers-Pehrson, and are
   141.9 +This code is released under the libpng license.
  141.10 +
  141.11 +libpng versions 1.2.6, August 15, 2004, through 1.5.4, July 7, 2011, are
  141.12 +Copyright (c) 2004, 2006-2011 Glenn Randers-Pehrson, and are
  141.13  distributed according to the same disclaimer and license as libpng-1.2.5
  141.14  with the following individual added to the list of Contributing Authors
  141.15  
  141.16 @@ -106,4 +108,4 @@
  141.17  
  141.18  Glenn Randers-Pehrson
  141.19  glennrp at users.sourceforge.net
  141.20 -May 15, 2007
  141.21 +July 7, 2011
   142.1 --- a/src/share/native/sun/awt/libpng/README	Fri Sep 30 17:20:56 2011 -0700
   142.2 +++ b/src/share/native/sun/awt/libpng/README	Tue Oct 04 12:39:42 2011 -0700
   142.3 @@ -1,11 +1,11 @@
   142.4 -README for libpng version 1.2.18 - May 15, 2007 (shared library 12.0)
   142.5 +README for libpng version 1.5.4 - July 7, 2011 (shared library 15.0)
   142.6  See the note about version numbers near the top of png.h
   142.7  
   142.8  See INSTALL for instructions on how to install libpng.
   142.9  
  142.10 -Libpng comes in several distribution formats.  Get libpng-*.tar.gz
  142.11 -or libpng-*.tar.bz2 if you want UNIX-style line endings in the text
  142.12 -files, or lpng*.zip if you want DOS-style line endings.
  142.13 +Libpng comes in several distribution formats.  Get libpng-*.tar.gz,
  142.14 +libpng-*.tar.xz or libpng-*.tar.bz2 if you want UNIX-style line endings
  142.15 +in the text files, or lpng*.zip if you want DOS-style line endings.
  142.16  
  142.17  Version 0.89 was the first official release of libpng.  Don't let the
  142.18  fact that it's the first release fool you.  The libpng library has been in
  142.19 @@ -54,11 +54,11 @@
  142.20  critical or an ancillary chunk.
  142.21  
  142.22  The changes made to the library, and bugs fixed are based on discussions
  142.23 -on the PNG-implement mailing list
  142.24 -and not on material submitted privately to Guy, Andreas, or Glenn.  They will
  142.25 -forward any good suggestions to the list.
  142.26 +on the PNG-implement mailing list and not on material submitted
  142.27 +privately to Guy, Andreas, or Glenn.  They will forward any good
  142.28 +suggestions to the list.
  142.29  
  142.30 -For a detailed description on using libpng, read libpng.txt.  For
  142.31 +For a detailed description on using libpng, read libpng-manual.txt.  For
  142.32  examples of libpng in a program, see example.c and pngtest.c.  For usage
  142.33  information and restrictions (what little they are) on libpng, see
  142.34  png.h.  For a description on using zlib (the compression library used by
  142.35 @@ -101,31 +101,29 @@
  142.36  fix.  Please mention "libpng" somewhere in the subject line.  Thanks.
  142.37  
  142.38  This release was created and will be supported by myself (of course
  142.39 -based in a large way on Guy's and Andreas' earlier work), and the PNG group.
  142.40 +based in a large way on Guy's and Andreas' earlier work), and the PNG
  142.41 +development group.
  142.42  
  142.43 -Send comments/corrections/commendations to png-mng-implement at lists.sf.net
  142.44 -(subscription required; visit 
  142.45 +Send comments/corrections/commendations to png-mng-implement at
  142.46 +lists.sourceforge.net (subscription required; visit 
  142.47  https://lists.sourceforge.net/lists/listinfo/png-mng-implement
  142.48  to subscribe) or to glennrp at users.sourceforge.net
  142.49  
  142.50  You can't reach Guy, the original libpng author, at the addresses
  142.51 -given in previous versions of this document.  He and Andreas will read mail
  142.52 -addressed to the png-implement list, however.
  142.53 +given in previous versions of this document.  He and Andreas will
  142.54 +read mail addressed to the png-implement list, however.
  142.55  
  142.56  Please do not send general questions about PNG.  Send them to
  142.57 -the (png-list at ccrc.wustl.edu, subscription required, write to
  142.58 -majordomo at ccrc.wustl.edu with "subscribe png-list" in your message).
  142.59 -On the other hand,
  142.60 -please do not send libpng questions to that address, send them to me
  142.61 -or to the png-implement list.  I'll
  142.62 -get them in the end anyway.  If you have a question about something
  142.63 +png-mng-misc at lists.sf.net (subscription required; visit
  142.64 +https://lists.sourceforge.net/lists/listinfo/png-mng-misc to
  142.65 +subscribe).  If you have a question about something
  142.66  in the PNG specification that is related to using libpng, send it
  142.67  to me.  Send me any questions that start with "I was using libpng,
  142.68  and ...".  If in doubt, send questions to me.  I'll bounce them
  142.69  to others, if necessary.
  142.70  
  142.71  Please do not send suggestions on how to change PNG.  We have
  142.72 -been discussing PNG for nine years now, and it is official and
  142.73 +been discussing PNG for sixteen years now, and it is official and
  142.74  finished.  If you have suggestions for libpng, however, I'll
  142.75  gladly listen.  Even if your suggestion is not used immediately,
  142.76  it may be used later.
  142.77 @@ -140,14 +138,17 @@
  142.78        TODO          =>  Things not implemented in the current library
  142.79        Y2KINFO       =>  Statement of Y2K compliance
  142.80        example.c     =>  Example code for using libpng functions
  142.81 -      libpng.3      =>  manual page for libpng (includes libpng.txt)
  142.82 -      libpng.txt    =>  Description of libpng and its functions
  142.83 +      libpng.3      =>  manual page for libpng (includes libpng-manual.txt)
  142.84 +      libpng-manual.txt  =>  Description of libpng and its functions
  142.85        libpngpf.3    =>  manual page for libpng's private functions
  142.86        png.5         =>  manual page for the PNG format
  142.87        png.c         =>  Basic interface functions common to library
  142.88 -      png.h         =>  Library function and interface declarations
  142.89 -      pngconf.h     =>  System specific library configuration
  142.90 -      pngasmrd.h    =>  Header file for assembler-coded functions
  142.91 +      png.h         =>  Library function and interface declarations (public)
  142.92 +      pngpriv.h     =>  Library function and interface declarations (private)
  142.93 +      pngconf.h     =>  System specific library configuration (public)
  142.94 +      pngstruct.h   =>  png_struct declaration (private)
  142.95 +      pnginfo.h     =>  png_info struct declaration (private)
  142.96 +      pngdebug.h    =>  debugging macros (private)
  142.97        pngerror.c    =>  Error/warning message I/O functions
  142.98        pngget.c      =>  Functions for retrieving info from struct
  142.99        pngmem.c      =>  Memory handling functions
 142.100 @@ -174,84 +175,22 @@
 142.101         pngminus     =>  Simple pnm2png and png2pnm programs
 142.102         pngsuite     =>  Test images
 142.103         visupng      =>  Contains a MSVC workspace for VisualPng
 142.104 -      projects      =>  Contains project files and workspaces for building DLL
 142.105 -       beos             =>  Contains a Beos workspace for building libpng
 142.106 -       c5builder        =>  Contains a Borland workspace for building libpng
 142.107 -                            and zlib
 142.108 -       visualc6         =>  Contains a Microsoft Visual C++ (MSVC) workspace
 142.109 -                            for building libpng and zlib
 142.110 -       netware.txt      =>  Contains instructions for downloading a set of
 142.111 -                            project files for building libpng and zlib on
 142.112 -                            Netware.
 142.113 -       wince.txt        =>  Contains instructions for downloading a Microsoft
 142.114 -                            Visual C++ (Windows CD Toolkit) workspace for
 142.115 -                            building libpng and zlib on WindowsCE
 142.116 +      projects      =>  Contains project files and workspaces for
 142.117 +                        building a DLL
 142.118 +       cbuilder5        =>  Contains a Borland workspace for building
 142.119 +                            libpng and zlib
 142.120 +       visualc6         =>  Contains a Microsoft Visual C++ (MSVC)
 142.121 +                            workspace for building libpng and zlib
 142.122 +       visualc71        =>  Contains a Microsoft Visual C++ (MSVC)
 142.123 +                            workspace for building libpng and zlib
 142.124 +       xcode            =>  Contains an Apple xcode
 142.125 +                            workspace for building libpng and zlib
 142.126        scripts       =>  Directory containing scripts for building libpng:
 142.127 -       descrip.mms      =>  VMS makefile for MMS or MMK
 142.128 -       makefile.std     =>  Generic UNIX makefile (cc, creates static libpng.a)
 142.129 -       makefile.elf     =>  Linux/ELF makefile symbol versioning,
 142.130 -                            gcc, creates libpng12.so.0.1.2.18)
 142.131 -       makefile.linux   =>  Linux/ELF makefile
 142.132 -                            (gcc, creates libpng12.so.0.1.2.18)
 142.133 -       makefile.gcmmx   =>  Linux/ELF makefile
 142.134 -                            (gcc, creates libpng12.so.0.1.2.18,
 142.135 -                            uses assembler code tuned for Intel MMX platform)
 142.136 -       makefile.gcc     =>  Generic makefile (gcc, creates static libpng.a)
 142.137 -       makefile.knr     =>  Archaic UNIX Makefile that converts files with
 142.138 -                            ansi2knr (Requires ansi2knr.c from
 142.139 -                            ftp://ftp.cs.wisc.edu/ghost)
 142.140 -       makefile.aix     =>  AIX makefile
 142.141 -       makefile.cygwin  =>  Cygwin/gcc makefile
 142.142 -       makefile.darwin  =>  Darwin makefile
 142.143 -       makefile.dec     =>  DEC Alpha UNIX makefile
 142.144 -       makefile.freebsd =>  FreeBSD makefile
 142.145 -       makefile.hpgcc   =>  HPUX makefile using gcc
 142.146 -       makefile.hpux    =>  HPUX (10.20 and 11.00) makefile
 142.147 -       makefile.hp64    =>  HPUX (10.20 and 11.00) makefile, 64 bit
 142.148 -       makefile.ibmc    =>  IBM C/C++ version 3.x for Win32 and OS/2 (static)
 142.149 -       makefile.intel   =>  Intel C/C++ version 4.0 and later
 142.150 -       libpng.icc       =>  Project file, IBM VisualAge/C++ 4.0 or later
 142.151 -       makefile.netbsd  =>  NetBSD/cc makefile, PNGGCCRD, makes libpng.so.
 142.152 -       makefile.ne12bsd  =>  NetBSD/cc makefile, PNGGCCRD, makes libpng12.so
 142.153 -       makefile.openbsd =>  OpenBSD makefile
 142.154 -       makefile.sgi     =>  Silicon Graphics IRIX (cc, creates static lib)
 142.155 -       makefile.sggcc   =>  Silicon Graphics
 142.156 -                            (gcc, creates libpng12.so.0.1.2.18)
 142.157 -       makefile.sunos   =>  Sun makefile
 142.158 -       makefile.solaris =>  Solaris 2.X makefile
 142.159 -                            (gcc, creates libpng12.so.0.1.2.18)
 142.160 -       makefile.so9     =>  Solaris 9 makefile
 142.161 -                            (gcc, creates libpng12.so.0.1.2.18)
 142.162 -       makefile.32sunu  =>  Sun Ultra 32-bit makefile
 142.163 -       makefile.64sunu  =>  Sun Ultra 64-bit makefile
 142.164 -       makefile.sco     =>  For SCO OSr5  ELF and Unixware 7 with Native cc
 142.165 -       makefile.mips    =>  MIPS makefile
 142.166 -       makefile.acorn   =>  Acorn makefile
 142.167 -       makefile.amiga   =>  Amiga makefile
 142.168 -       smakefile.ppc    =>  AMIGA smakefile for SAS C V6.58/7.00 PPC
 142.169 -                            compiler (Requires SCOPTIONS, copied from
 142.170 -                            scripts/SCOPTIONS.ppc)
 142.171 -       makefile.atari   =>  Atari makefile
 142.172 -       makefile.beos    =>  BEOS makefile for X86
 142.173 -       makefile.bor     =>  Borland makefile (uses bcc)
 142.174 -       makefile.bc32    =>  32-bit Borland C++ (all modules compiled in C mode)
 142.175 -       makefile.tc3     =>  Turbo C 3.0 makefile
 142.176 -       makefile.dj2     =>  DJGPP 2 makefile
 142.177 -       makefile.msc     =>  Microsoft C makefile
 142.178 -       makefile.vcawin32=>  makefile for Microsoft Visual C++ 5.0 and
 142.179 -                            later (uses assembler code tuned for Intel MMX
 142.180 -                            platform)
 142.181 -       makefile.vcwin32 =>  makefile for Microsoft Visual C++ 4.0 and
 142.182 -                            later (does not use assembler code)
 142.183 -       makefile.os2     =>  OS/2 Makefile (gcc and emx, requires pngos2.def)
 142.184 -       pngos2.def       =>  OS/2 module definition file used by makefile.os2
 142.185 -       makefile.watcom  =>  Watcom 10a+ Makefile, 32-bit flat memory model
 142.186 -       makevms.com      =>  VMS build script
 142.187 -       SCOPTIONS.ppc    =>  Used with smakefile.ppc
 142.188 +                            (see scripts/README.txt for the list of scripts)
 142.189  
 142.190  Good luck, and happy coding.
 142.191  
 142.192 --Glenn Randers-Pehrson (current maintainer)
 142.193 +-Glenn Randers-Pehrson (current maintainer, since 1998)
 142.194   Internet: glennrp at users.sourceforge.net
 142.195  
 142.196  -Andreas Eric Dilger (former maintainer, 1996-1997)
   143.1 --- a/src/share/native/sun/awt/libpng/png.c	Fri Sep 30 17:20:56 2011 -0700
   143.2 +++ b/src/share/native/sun/awt/libpng/png.c	Tue Oct 04 12:39:42 2011 -0700
   143.3 @@ -29,91 +29,20 @@
   143.4   * However, the following notice accompanied the original version of this
   143.5   * file and, per its terms, should not be removed:
   143.6   *
   143.7 - * Last changed in libpng 1.2.17 May 15, 2007
   143.8 - * For conditions of distribution and use, see copyright notice in png.h
   143.9 - * Copyright (c) 1998-2007 Glenn Randers-Pehrson
  143.10 + * Last changed in libpng 1.5.4 [July 7, 2011]
  143.11 + * Copyright (c) 1998-2011 Glenn Randers-Pehrson
  143.12   * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
  143.13   * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
  143.14 + *
  143.15 + * This code is released under the libpng license.
  143.16 + * For conditions of distribution and use, see the disclaimer
  143.17 + * and license in png.h
  143.18   */
  143.19  
  143.20 -#define PNG_INTERNAL
  143.21 -#define PNG_NO_EXTERN
  143.22 -#include "png.h"
  143.23 +#include "pngpriv.h"
  143.24  
  143.25  /* Generate a compiler error if there is an old png.h in the search path. */
  143.26 -typedef version_1_2_18 Your_png_h_is_not_version_1_2_18;
  143.27 -
  143.28 -/* Version information for C files.  This had better match the version
  143.29 - * string defined in png.h.  */
  143.30 -
  143.31 -#ifdef PNG_USE_GLOBAL_ARRAYS
  143.32 -/* png_libpng_ver was changed to a function in version 1.0.5c */
  143.33 -const char png_libpng_ver[18] = PNG_LIBPNG_VER_STRING;
  143.34 -
  143.35 -#ifdef PNG_READ_SUPPORTED
  143.36 -
  143.37 -/* png_sig was changed to a function in version 1.0.5c */
  143.38 -/* Place to hold the signature string for a PNG file. */
  143.39 -const png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  143.40 -#endif /* PNG_READ_SUPPORTED */
  143.41 -
  143.42 -/* Invoke global declarations for constant strings for known chunk types */
  143.43 -PNG_IHDR;
  143.44 -PNG_IDAT;
  143.45 -PNG_IEND;
  143.46 -PNG_PLTE;
  143.47 -PNG_bKGD;
  143.48 -PNG_cHRM;
  143.49 -PNG_gAMA;
  143.50 -PNG_hIST;
  143.51 -PNG_iCCP;
  143.52 -PNG_iTXt;
  143.53 -PNG_oFFs;
  143.54 -PNG_pCAL;
  143.55 -PNG_sCAL;
  143.56 -PNG_pHYs;
  143.57 -PNG_sBIT;
  143.58 -PNG_sPLT;
  143.59 -PNG_sRGB;
  143.60 -PNG_tEXt;
  143.61 -PNG_tIME;
  143.62 -PNG_tRNS;
  143.63 -PNG_zTXt;
  143.64 -
  143.65 -#ifdef PNG_READ_SUPPORTED
  143.66 -/* arrays to facilitate easy interlacing - use pass (0 - 6) as index */
  143.67 -
  143.68 -/* start of interlace block */
  143.69 -const int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
  143.70 -
  143.71 -/* offset to next interlace block */
  143.72 -const int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
  143.73 -
  143.74 -/* start of interlace block in the y direction */
  143.75 -const int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
  143.76 -
  143.77 -/* offset to next interlace block in the y direction */
  143.78 -const int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
  143.79 -
  143.80 -/* width of interlace block (used in assembler routines only) */
  143.81 -#ifdef PNG_HAVE_MMX_COMBINE_ROW
  143.82 -const int FARDATA png_pass_width[] = {8, 4, 4, 2, 2, 1, 1};
  143.83 -#endif
  143.84 -
  143.85 -/* Height of interlace block.  This is not currently used - if you need
  143.86 - * it, uncomment it here and in png.h
  143.87 -const int FARDATA png_pass_height[] = {8, 8, 4, 4, 2, 2, 1};
  143.88 -*/
  143.89 -
  143.90 -/* Mask to determine which pixels are valid in a pass */
  143.91 -const int FARDATA png_pass_mask[] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
  143.92 -
  143.93 -/* Mask to determine which pixels to overwrite while displaying */
  143.94 -const int FARDATA png_pass_dsp_mask[]
  143.95 -   = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
  143.96 -
  143.97 -#endif /* PNG_READ_SUPPORTED */
  143.98 -#endif /* PNG_USE_GLOBAL_ARRAYS */
  143.99 +typedef png_libpng_version_1_5_4 Your_png_h_is_not_version_1_5_4;
 143.100  
 143.101  /* Tells libpng that we have already handled the first "num_bytes" bytes
 143.102   * of the PNG file signature.  If the PNG data is embedded into another
 143.103 @@ -125,10 +54,13 @@
 143.104  void PNGAPI
 143.105  png_set_sig_bytes(png_structp png_ptr, int num_bytes)
 143.106  {
 143.107 -   if(png_ptr == NULL) return;
 143.108 -   png_debug(1, "in png_set_sig_bytes\n");
 143.109 +   png_debug(1, "in png_set_sig_bytes");
 143.110 +
 143.111 +   if (png_ptr == NULL)
 143.112 +      return;
 143.113 +
 143.114     if (num_bytes > 8)
 143.115 -      png_error(png_ptr, "Too many bytes for PNG signature.");
 143.116 +      png_error(png_ptr, "Too many bytes for PNG signature");
 143.117  
 143.118     png_ptr->sig_bytes = (png_byte)(num_bytes < 0 ? 0 : num_bytes);
 143.119  }
 143.120 @@ -142,11 +74,13 @@
 143.121   * PNG signature (this is the same behaviour as strcmp, memcmp, etc).
 143.122   */
 143.123  int PNGAPI
 143.124 -png_sig_cmp(png_bytep sig, png_size_t start, png_size_t num_to_check)
 143.125 +png_sig_cmp(png_const_bytep sig, png_size_t start, png_size_t num_to_check)
 143.126  {
 143.127     png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
 143.128 +
 143.129     if (num_to_check > 8)
 143.130        num_to_check = 8;
 143.131 +
 143.132     else if (num_to_check < 1)
 143.133        return (-1);
 143.134  
 143.135 @@ -159,69 +93,37 @@
 143.136     return ((int)(png_memcmp(&sig[start], &png_signature[start], num_to_check)));
 143.137  }
 143.138  
 143.139 -#if defined(PNG_1_0_X) || defined(PNG_1_2_X)
 143.140 -/* (Obsolete) function to check signature bytes.  It does not allow one
 143.141 - * to check a partial signature.  This function might be removed in the
 143.142 - * future - use png_sig_cmp().  Returns true (nonzero) if the file is a PNG.
 143.143 - */
 143.144 -int PNGAPI
 143.145 -png_check_sig(png_bytep sig, int num)
 143.146 -{
 143.147 -  return ((int)!png_sig_cmp(sig, (png_size_t)0, (png_size_t)num));
 143.148 -}
 143.149 -#endif
 143.150  #endif /* PNG_READ_SUPPORTED */
 143.151  
 143.152  #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
 143.153 -/* Function to allocate memory for zlib and clear it to 0. */
 143.154 -#ifdef PNG_1_0_X
 143.155 -voidpf PNGAPI
 143.156 -#else
 143.157 -voidpf /* private */
 143.158 -#endif
 143.159 -png_zalloc(voidpf png_ptr, uInt items, uInt size)
 143.160 +/* Function to allocate memory for zlib */
 143.161 +PNG_FUNCTION(voidpf /* PRIVATE */,
 143.162 +png_zalloc,(voidpf png_ptr, uInt items, uInt size),PNG_ALLOCATED)
 143.163  {
 143.164     png_voidp ptr;
 143.165     png_structp p=(png_structp)png_ptr;
 143.166     png_uint_32 save_flags=p->flags;
 143.167 -   png_uint_32 num_bytes;
 143.168 +   png_alloc_size_t num_bytes;
 143.169  
 143.170 -   if(png_ptr == NULL) return (NULL);
 143.171 +   if (png_ptr == NULL)
 143.172 +      return (NULL);
 143.173 +
 143.174     if (items > PNG_UINT_32_MAX/size)
 143.175     {
 143.176       png_warning (p, "Potential overflow in png_zalloc()");
 143.177       return (NULL);
 143.178     }
 143.179 -   num_bytes = (png_uint_32)items * size;
 143.180 +   num_bytes = (png_alloc_size_t)items * size;
 143.181  
 143.182     p->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
 143.183     ptr = (png_voidp)png_malloc((png_structp)png_ptr, num_bytes);
 143.184     p->flags=save_flags;
 143.185  
 143.186 -#if defined(PNG_1_0_X) && !defined(PNG_NO_ZALLOC_ZERO)
 143.187 -   if (ptr == NULL)
 143.188 -       return ((voidpf)ptr);
 143.189 -
 143.190 -   if (num_bytes > (png_uint_32)0x8000L)
 143.191 -   {
 143.192 -      png_memset(ptr, 0, (png_size_t)0x8000L);
 143.193 -      png_memset((png_bytep)ptr + (png_size_t)0x8000L, 0,
 143.194 -         (png_size_t)(num_bytes - (png_uint_32)0x8000L));
 143.195 -   }
 143.196 -   else
 143.197 -   {
 143.198 -      png_memset(ptr, 0, (png_size_t)num_bytes);
 143.199 -   }
 143.200 -#endif
 143.201     return ((voidpf)ptr);
 143.202  }
 143.203  
 143.204 -/* function to free memory for zlib */
 143.205 -#ifdef PNG_1_0_X
 143.206 -void PNGAPI
 143.207 -#else
 143.208 -void /* private */
 143.209 -#endif
 143.210 +/* Function to free memory for zlib */
 143.211 +void /* PRIVATE */
 143.212  png_zfree(voidpf png_ptr, voidpf ptr)
 143.213  {
 143.214     png_free((png_structp)png_ptr, (png_voidp)ptr);
 143.215 @@ -242,7 +144,7 @@
 143.216   * trouble of calculating it.
 143.217   */
 143.218  void /* PRIVATE */
 143.219 -png_calculate_crc(png_structp png_ptr, png_bytep ptr, png_size_t length)
 143.220 +png_calculate_crc(png_structp png_ptr, png_const_bytep ptr, png_size_t length)
 143.221  {
 143.222     int need_crc = 1;
 143.223  
 143.224 @@ -252,6 +154,7 @@
 143.225            (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
 143.226           need_crc = 0;
 143.227     }
 143.228 +
 143.229     else                                                    /* critical */
 143.230     {
 143.231        if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
 143.232 @@ -262,19 +165,77 @@
 143.233        png_ptr->crc = crc32(png_ptr->crc, ptr, (uInt)length);
 143.234  }
 143.235  
 143.236 +/* Check a user supplied version number, called from both read and write
 143.237 + * functions that create a png_struct
 143.238 + */
 143.239 +int
 143.240 +png_user_version_check(png_structp png_ptr, png_const_charp user_png_ver)
 143.241 +{
 143.242 +   if (user_png_ver)
 143.243 +   {
 143.244 +      int i = 0;
 143.245 +
 143.246 +      do
 143.247 +      {
 143.248 +         if (user_png_ver[i] != png_libpng_ver[i])
 143.249 +            png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
 143.250 +      } while (png_libpng_ver[i++]);
 143.251 +   }
 143.252 +
 143.253 +   else
 143.254 +      png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
 143.255 +
 143.256 +   if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
 143.257 +   {
 143.258 +     /* Libpng 0.90 and later are binary incompatible with libpng 0.89, so
 143.259 +      * we must recompile any applications that use any older library version.
 143.260 +      * For versions after libpng 1.0, we will be compatible, so we need
 143.261 +      * only check the first digit.
 143.262 +      */
 143.263 +      if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
 143.264 +          (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
 143.265 +          (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
 143.266 +      {
 143.267 +#ifdef PNG_WARNINGS_SUPPORTED
 143.268 +         size_t pos = 0;
 143.269 +         char m[128];
 143.270 +
 143.271 +         pos = png_safecat(m, sizeof m, pos, "Application built with libpng-");
 143.272 +         pos = png_safecat(m, sizeof m, pos, user_png_ver);
 143.273 +         pos = png_safecat(m, sizeof m, pos, " but running with ");
 143.274 +         pos = png_safecat(m, sizeof m, pos, png_libpng_ver);
 143.275 +
 143.276 +         png_warning(png_ptr, m);
 143.277 +#endif
 143.278 +
 143.279 +#ifdef PNG_ERROR_NUMBERS_SUPPORTED
 143.280 +         png_ptr->flags = 0;
 143.281 +#endif
 143.282 +
 143.283 +         return 0;
 143.284 +      }
 143.285 +   }
 143.286 +
 143.287 +   /* Success return. */
 143.288 +   return 1;
 143.289 +}
 143.290 +
 143.291  /* Allocate the memory for an info_struct for the application.  We don't
 143.292   * really need the png_ptr, but it could potentially be useful in the
 143.293   * future.  This should be used in favour of malloc(png_sizeof(png_info))
 143.294   * and png_info_init() so that applications that want to use a shared
 143.295   * libpng don't have to be recompiled if png_info changes size.
 143.296   */
 143.297 -png_infop PNGAPI
 143.298 -png_create_info_struct(png_structp png_ptr)
 143.299 +PNG_FUNCTION(png_infop,PNGAPI
 143.300 +png_create_info_struct,(png_structp png_ptr),PNG_ALLOCATED)
 143.301  {
 143.302     png_infop info_ptr;
 143.303  
 143.304 -   png_debug(1, "in png_create_info_struct\n");
 143.305 -   if(png_ptr == NULL) return (NULL);
 143.306 +   png_debug(1, "in png_create_info_struct");
 143.307 +
 143.308 +   if (png_ptr == NULL)
 143.309 +      return (NULL);
 143.310 +
 143.311  #ifdef PNG_USER_MEM_SUPPORTED
 143.312     info_ptr = (png_infop)png_create_struct_2(PNG_STRUCT_INFO,
 143.313        png_ptr->malloc_fn, png_ptr->mem_ptr);
 143.314 @@ -296,9 +257,12 @@
 143.315  png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr)
 143.316  {
 143.317     png_infop info_ptr = NULL;
 143.318 -   if(png_ptr == NULL) return;
 143.319  
 143.320 -   png_debug(1, "in png_destroy_info_struct\n");
 143.321 +   png_debug(1, "in png_destroy_info_struct");
 143.322 +
 143.323 +   if (png_ptr == NULL)
 143.324 +      return;
 143.325 +
 143.326     if (info_ptr_ptr != NULL)
 143.327        info_ptr = *info_ptr_ptr;
 143.328  
 143.329 @@ -320,302 +284,248 @@
 143.330   * and applications using it are urged to use png_create_info_struct()
 143.331   * instead.
 143.332   */
 143.333 -#if defined(PNG_1_0_X) || defined(PNG_1_2_X)
 143.334 -#undef png_info_init
 143.335 -void PNGAPI
 143.336 -png_info_init(png_infop info_ptr)
 143.337 -{
 143.338 -   /* We only come here via pre-1.0.12-compiled applications */
 143.339 -   png_info_init_3(&info_ptr, 0);
 143.340 -}
 143.341 -#endif
 143.342  
 143.343  void PNGAPI
 143.344  png_info_init_3(png_infopp ptr_ptr, png_size_t png_info_struct_size)
 143.345  {
 143.346     png_infop info_ptr = *ptr_ptr;
 143.347  
 143.348 -   if(info_ptr == NULL) return;
 143.349 +   png_debug(1, "in png_info_init_3");
 143.350  
 143.351 -   png_debug(1, "in png_info_init_3\n");
 143.352 +   if (info_ptr == NULL)
 143.353 +      return;
 143.354  
 143.355 -   if(png_sizeof(png_info) > png_info_struct_size)
 143.356 -     {
 143.357 -       png_destroy_struct(info_ptr);
 143.358 -       info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
 143.359 -       *ptr_ptr = info_ptr;
 143.360 -     }
 143.361 +   if (png_sizeof(png_info) > png_info_struct_size)
 143.362 +   {
 143.363 +      png_destroy_struct(info_ptr);
 143.364 +      info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
 143.365 +      *ptr_ptr = info_ptr;
 143.366 +   }
 143.367  
 143.368 -   /* set everything to 0 */
 143.369 -   png_memset(info_ptr, 0, png_sizeof (png_info));
 143.370 +   /* Set everything to 0 */
 143.371 +   png_memset(info_ptr, 0, png_sizeof(png_info));
 143.372  }
 143.373  
 143.374 -#ifdef PNG_FREE_ME_SUPPORTED
 143.375  void PNGAPI
 143.376  png_data_freer(png_structp png_ptr, png_infop info_ptr,
 143.377     int freer, png_uint_32 mask)
 143.378  {
 143.379 -   png_debug(1, "in png_data_freer\n");
 143.380 +   png_debug(1, "in png_data_freer");
 143.381 +
 143.382     if (png_ptr == NULL || info_ptr == NULL)
 143.383        return;
 143.384 -   if(freer == PNG_DESTROY_WILL_FREE_DATA)
 143.385 +
 143.386 +   if (freer == PNG_DESTROY_WILL_FREE_DATA)
 143.387        info_ptr->free_me |= mask;
 143.388 -   else if(freer == PNG_USER_WILL_FREE_DATA)
 143.389 +
 143.390 +   else if (freer == PNG_USER_WILL_FREE_DATA)
 143.391        info_ptr->free_me &= ~mask;
 143.392 +
 143.393     else
 143.394        png_warning(png_ptr,
 143.395 -         "Unknown freer parameter in png_data_freer.");
 143.396 +         "Unknown freer parameter in png_data_freer");
 143.397  }
 143.398 -#endif
 143.399  
 143.400  void PNGAPI
 143.401  png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask,
 143.402     int num)
 143.403  {
 143.404 -   png_debug(1, "in png_free_data\n");
 143.405 +   png_debug(1, "in png_free_data");
 143.406 +
 143.407     if (png_ptr == NULL || info_ptr == NULL)
 143.408        return;
 143.409  
 143.410 -#if defined(PNG_TEXT_SUPPORTED)
 143.411 -/* free text item num or (if num == -1) all text items */
 143.412 -#ifdef PNG_FREE_ME_SUPPORTED
 143.413 -if ((mask & PNG_FREE_TEXT) & info_ptr->free_me)
 143.414 -#else
 143.415 -if (mask & PNG_FREE_TEXT)
 143.416 -#endif
 143.417 -{
 143.418 -   if (num != -1)
 143.419 +#ifdef PNG_TEXT_SUPPORTED
 143.420 +   /* Free text item num or (if num == -1) all text items */
 143.421 +   if ((mask & PNG_FREE_TEXT) & info_ptr->free_me)
 143.422     {
 143.423 -     if (info_ptr->text && info_ptr->text[num].key)
 143.424 -     {
 143.425 -         png_free(png_ptr, info_ptr->text[num].key);
 143.426 -         info_ptr->text[num].key = NULL;
 143.427 -     }
 143.428 +      if (num != -1)
 143.429 +      {
 143.430 +         if (info_ptr->text && info_ptr->text[num].key)
 143.431 +         {
 143.432 +            png_free(png_ptr, info_ptr->text[num].key);
 143.433 +            info_ptr->text[num].key = NULL;
 143.434 +         }
 143.435 +      }
 143.436 +
 143.437 +      else
 143.438 +      {
 143.439 +         int i;
 143.440 +         for (i = 0; i < info_ptr->num_text; i++)
 143.441 +             png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, i);
 143.442 +         png_free(png_ptr, info_ptr->text);
 143.443 +         info_ptr->text = NULL;
 143.444 +         info_ptr->num_text=0;
 143.445 +      }
 143.446     }
 143.447 -   else
 143.448 -   {
 143.449 -       int i;
 143.450 -       for (i = 0; i < info_ptr->num_text; i++)
 143.451 -           png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, i);
 143.452 -       png_free(png_ptr, info_ptr->text);
 143.453 -       info_ptr->text = NULL;
 143.454 -       info_ptr->num_text=0;
 143.455 -   }
 143.456 -}
 143.457  #endif
 143.458  
 143.459 -#if defined(PNG_tRNS_SUPPORTED)
 143.460 -/* free any tRNS entry */
 143.461 -#ifdef PNG_FREE_ME_SUPPORTED
 143.462 -if ((mask & PNG_FREE_TRNS) & info_ptr->free_me)
 143.463 -#else
 143.464 -if ((mask & PNG_FREE_TRNS) && (png_ptr->flags & PNG_FLAG_FREE_TRNS))
 143.465 -#endif
 143.466 -{
 143.467 -    png_free(png_ptr, info_ptr->trans);
 143.468 -    info_ptr->valid &= ~PNG_INFO_tRNS;
 143.469 -#ifndef PNG_FREE_ME_SUPPORTED
 143.470 -    png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
 143.471 -#endif
 143.472 -    info_ptr->trans = NULL;
 143.473 -}
 143.474 +#ifdef PNG_tRNS_SUPPORTED
 143.475 +   /* Free any tRNS entry */
 143.476 +   if ((mask & PNG_FREE_TRNS) & info_ptr->free_me)
 143.477 +   {
 143.478 +      png_free(png_ptr, info_ptr->trans_alpha);
 143.479 +      info_ptr->trans_alpha = NULL;
 143.480 +      info_ptr->valid &= ~PNG_INFO_tRNS;
 143.481 +   }
 143.482  #endif
 143.483  
 143.484 -#if defined(PNG_sCAL_SUPPORTED)
 143.485 -/* free any sCAL entry */
 143.486 -#ifdef PNG_FREE_ME_SUPPORTED
 143.487 -if ((mask & PNG_FREE_SCAL) & info_ptr->free_me)
 143.488 -#else
 143.489 -if (mask & PNG_FREE_SCAL)
 143.490 -#endif
 143.491 -{
 143.492 -#if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
 143.493 -    png_free(png_ptr, info_ptr->scal_s_width);
 143.494 -    png_free(png_ptr, info_ptr->scal_s_height);
 143.495 -    info_ptr->scal_s_width = NULL;
 143.496 -    info_ptr->scal_s_height = NULL;
 143.497 -#endif
 143.498 -    info_ptr->valid &= ~PNG_INFO_sCAL;
 143.499 -}
 143.500 +#ifdef PNG_sCAL_SUPPORTED
 143.501 +   /* Free any sCAL entry */
 143.502 +   if ((mask & PNG_FREE_SCAL) & info_ptr->free_me)
 143.503 +   {
 143.504 +      png_free(png_ptr, info_ptr->scal_s_width);
 143.505 +      png_free(png_ptr, info_ptr->scal_s_height);
 143.506 +      info_ptr->scal_s_width = NULL;
 143.507 +      info_ptr->scal_s_height = NULL;
 143.508 +      info_ptr->valid &= ~PNG_INFO_sCAL;
 143.509 +   }
 143.510  #endif
 143.511  
 143.512 -#if defined(PNG_pCAL_SUPPORTED)
 143.513 -/* free any pCAL entry */
 143.514 -#ifdef PNG_FREE_ME_SUPPORTED
 143.515 -if ((mask & PNG_FREE_PCAL) & info_ptr->free_me)
 143.516 -#else
 143.517 -if (mask & PNG_FREE_PCAL)
 143.518 -#endif
 143.519 -{
 143.520 -    png_free(png_ptr, info_ptr->pcal_purpose);
 143.521 -    png_free(png_ptr, info_ptr->pcal_units);
 143.522 -    info_ptr->pcal_purpose = NULL;
 143.523 -    info_ptr->pcal_units = NULL;
 143.524 -    if (info_ptr->pcal_params != NULL)
 143.525 -    {
 143.526 -        int i;
 143.527 -        for (i = 0; i < (int)info_ptr->pcal_nparams; i++)
 143.528 -        {
 143.529 -          png_free(png_ptr, info_ptr->pcal_params[i]);
 143.530 -          info_ptr->pcal_params[i]=NULL;
 143.531 -        }
 143.532 -        png_free(png_ptr, info_ptr->pcal_params);
 143.533 -        info_ptr->pcal_params = NULL;
 143.534 -    }
 143.535 -    info_ptr->valid &= ~PNG_INFO_pCAL;
 143.536 -}
 143.537 +#ifdef PNG_pCAL_SUPPORTED
 143.538 +   /* Free any pCAL entry */
 143.539 +   if ((mask & PNG_FREE_PCAL) & info_ptr->free_me)
 143.540 +   {
 143.541 +      png_free(png_ptr, info_ptr->pcal_purpose);
 143.542 +      png_free(png_ptr, info_ptr->pcal_units);
 143.543 +      info_ptr->pcal_purpose = NULL;
 143.544 +      info_ptr->pcal_units = NULL;
 143.545 +      if (info_ptr->pcal_params != NULL)
 143.546 +         {
 143.547 +            int i;
 143.548 +            for (i = 0; i < (int)info_ptr->pcal_nparams; i++)
 143.549 +            {
 143.550 +               png_free(png_ptr, info_ptr->pcal_params[i]);
 143.551 +               info_ptr->pcal_params[i] = NULL;
 143.552 +            }
 143.553 +            png_free(png_ptr, info_ptr->pcal_params);
 143.554 +            info_ptr->pcal_params = NULL;
 143.555 +         }
 143.556 +      info_ptr->valid &= ~PNG_INFO_pCAL;
 143.557 +   }
 143.558  #endif
 143.559  
 143.560 -#if defined(PNG_iCCP_SUPPORTED)
 143.561 -/* free any iCCP entry */
 143.562 -#ifdef PNG_FREE_ME_SUPPORTED
 143.563 -if ((mask & PNG_FREE_ICCP) & info_ptr->free_me)
 143.564 -#else
 143.565 -if (mask & PNG_FREE_ICCP)
 143.566 -#endif
 143.567 -{
 143.568 -    png_free(png_ptr, info_ptr->iccp_name);
 143.569 -    png_free(png_ptr, info_ptr->iccp_profile);
 143.570 -    info_ptr->iccp_name = NULL;
 143.571 -    info_ptr->iccp_profile = NULL;
 143.572 -    info_ptr->valid &= ~PNG_INFO_iCCP;
 143.573 -}
 143.574 +#ifdef PNG_iCCP_SUPPORTED
 143.575 +   /* Free any iCCP entry */
 143.576 +   if ((mask & PNG_FREE_ICCP) & info_ptr->free_me)
 143.577 +   {
 143.578 +      png_free(png_ptr, info_ptr->iccp_name);
 143.579 +      png_free(png_ptr, info_ptr->iccp_profile);
 143.580 +      info_ptr->iccp_name = NULL;
 143.581 +      info_ptr->iccp_profile = NULL;
 143.582 +      info_ptr->valid &= ~PNG_INFO_iCCP;
 143.583 +   }
 143.584  #endif
 143.585  
 143.586 -#if defined(PNG_sPLT_SUPPORTED)
 143.587 -/* free a given sPLT entry, or (if num == -1) all sPLT entries */
 143.588 -#ifdef PNG_FREE_ME_SUPPORTED
 143.589 -if ((mask & PNG_FREE_SPLT) & info_ptr->free_me)
 143.590 -#else
 143.591 -if (mask & PNG_FREE_SPLT)
 143.592 -#endif
 143.593 -{
 143.594 -   if (num != -1)
 143.595 +#ifdef PNG_sPLT_SUPPORTED
 143.596 +   /* Free a given sPLT entry, or (if num == -1) all sPLT entries */
 143.597 +   if ((mask & PNG_FREE_SPLT) & info_ptr->free_me)
 143.598     {
 143.599 -      if(info_ptr->splt_palettes)
 143.600 +      if (num != -1)
 143.601        {
 143.602 -          png_free(png_ptr, info_ptr->splt_palettes[num].name);
 143.603 -          png_free(png_ptr, info_ptr->splt_palettes[num].entries);
 143.604 -          info_ptr->splt_palettes[num].name = NULL;
 143.605 -          info_ptr->splt_palettes[num].entries = NULL;
 143.606 +         if (info_ptr->splt_palettes)
 143.607 +         {
 143.608 +            png_free(png_ptr, info_ptr->splt_palettes[num].name);
 143.609 +            png_free(png_ptr, info_ptr->splt_palettes[num].entries);
 143.610 +            info_ptr->splt_palettes[num].name = NULL;
 143.611 +            info_ptr->splt_palettes[num].entries = NULL;
 143.612 +         }
 143.613 +      }
 143.614 +
 143.615 +      else
 143.616 +      {
 143.617 +         if (info_ptr->splt_palettes_num)
 143.618 +         {
 143.619 +            int i;
 143.620 +            for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
 143.621 +               png_free_data(png_ptr, info_ptr, PNG_FREE_SPLT, i);
 143.622 +
 143.623 +            png_free(png_ptr, info_ptr->splt_palettes);
 143.624 +            info_ptr->splt_palettes = NULL;
 143.625 +            info_ptr->splt_palettes_num = 0;
 143.626 +         }
 143.627 +         info_ptr->valid &= ~PNG_INFO_sPLT;
 143.628        }
 143.629     }
 143.630 -   else
 143.631 -   {
 143.632 -       if(info_ptr->splt_palettes_num)
 143.633 -       {
 143.634 -         int i;
 143.635 -         for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
 143.636 -            png_free_data(png_ptr, info_ptr, PNG_FREE_SPLT, i);
 143.637 -
 143.638 -         png_free(png_ptr, info_ptr->splt_palettes);
 143.639 -         info_ptr->splt_palettes = NULL;
 143.640 -         info_ptr->splt_palettes_num = 0;
 143.641 -       }
 143.642 -       info_ptr->valid &= ~PNG_INFO_sPLT;
 143.643 -   }
 143.644 -}
 143.645  #endif
 143.646  
 143.647 -#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
 143.648 -  if(png_ptr->unknown_chunk.data)
 143.649 -  {
 143.650 -    png_free(png_ptr, png_ptr->unknown_chunk.data);
 143.651 -    png_ptr->unknown_chunk.data = NULL;
 143.652 -  }
 143.653 -#ifdef PNG_FREE_ME_SUPPORTED
 143.654 -if ((mask & PNG_FREE_UNKN) & info_ptr->free_me)
 143.655 -#else
 143.656 -if (mask & PNG_FREE_UNKN)
 143.657 -#endif
 143.658 -{
 143.659 -   if (num != -1)
 143.660 +#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
 143.661 +   if (png_ptr->unknown_chunk.data)
 143.662     {
 143.663 -       if(info_ptr->unknown_chunks)
 143.664 -       {
 143.665 -          png_free(png_ptr, info_ptr->unknown_chunks[num].data);
 143.666 -          info_ptr->unknown_chunks[num].data = NULL;
 143.667 -       }
 143.668 +      png_free(png_ptr, png_ptr->unknown_chunk.data);
 143.669 +      png_ptr->unknown_chunk.data = NULL;
 143.670     }
 143.671 -   else
 143.672 +
 143.673 +   if ((mask & PNG_FREE_UNKN) & info_ptr->free_me)
 143.674     {
 143.675 -       int i;
 143.676 +      if (num != -1)
 143.677 +      {
 143.678 +          if (info_ptr->unknown_chunks)
 143.679 +          {
 143.680 +             png_free(png_ptr, info_ptr->unknown_chunks[num].data);
 143.681 +             info_ptr->unknown_chunks[num].data = NULL;
 143.682 +          }
 143.683 +      }
 143.684  
 143.685 -       if(info_ptr->unknown_chunks_num)
 143.686 -       {
 143.687 -         for (i = 0; i < (int)info_ptr->unknown_chunks_num; i++)
 143.688 -            png_free_data(png_ptr, info_ptr, PNG_FREE_UNKN, i);
 143.689 +      else
 143.690 +      {
 143.691 +         int i;
 143.692  
 143.693 -         png_free(png_ptr, info_ptr->unknown_chunks);
 143.694 -         info_ptr->unknown_chunks = NULL;
 143.695 -         info_ptr->unknown_chunks_num = 0;
 143.696 -       }
 143.697 +         if (info_ptr->unknown_chunks_num)
 143.698 +         {
 143.699 +            for (i = 0; i < info_ptr->unknown_chunks_num; i++)
 143.700 +               png_free_data(png_ptr, info_ptr, PNG_FREE_UNKN, i);
 143.701 +
 143.702 +            png_free(png_ptr, info_ptr->unknown_chunks);
 143.703 +            info_ptr->unknown_chunks = NULL;
 143.704 +            info_ptr->unknown_chunks_num = 0;
 143.705 +         }
 143.706 +      }
 143.707     }
 143.708 -}
 143.709  #endif
 143.710  
 143.711 -#if defined(PNG_hIST_SUPPORTED)
 143.712 -/* free any hIST entry */
 143.713 -#ifdef PNG_FREE_ME_SUPPORTED
 143.714 -if ((mask & PNG_FREE_HIST)  & info_ptr->free_me)
 143.715 -#else
 143.716 -if ((mask & PNG_FREE_HIST) && (png_ptr->flags & PNG_FLAG_FREE_HIST))
 143.717 -#endif
 143.718 -{
 143.719 -    png_free(png_ptr, info_ptr->hist);
 143.720 -    info_ptr->hist = NULL;
 143.721 -    info_ptr->valid &= ~PNG_INFO_hIST;
 143.722 -#ifndef PNG_FREE_ME_SUPPORTED
 143.723 -    png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
 143.724 -#endif
 143.725 -}
 143.726 +#ifdef PNG_hIST_SUPPORTED
 143.727 +   /* Free any hIST entry */
 143.728 +   if ((mask & PNG_FREE_HIST)  & info_ptr->free_me)
 143.729 +   {
 143.730 +      png_free(png_ptr, info_ptr->hist);
 143.731 +      info_ptr->hist = NULL;
 143.732 +      info_ptr->valid &= ~PNG_INFO_hIST;
 143.733 +   }
 143.734  #endif
 143.735  
 143.736 -/* free any PLTE entry that was internally allocated */
 143.737 -#ifdef PNG_FREE_ME_SUPPORTED
 143.738 -if ((mask & PNG_FREE_PLTE) & info_ptr->free_me)
 143.739 -#else
 143.740 -if ((mask & PNG_FREE_PLTE) && (png_ptr->flags & PNG_FLAG_FREE_PLTE))
 143.741 -#endif
 143.742 -{
 143.743 -    png_zfree(png_ptr, info_ptr->palette);
 143.744 -    info_ptr->palette = NULL;
 143.745 -    info_ptr->valid &= ~PNG_INFO_PLTE;
 143.746 -#ifndef PNG_FREE_ME_SUPPORTED
 143.747 -    png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;
 143.748 -#endif
 143.749 -    info_ptr->num_palette = 0;
 143.750 -}
 143.751 +   /* Free any PLTE entry that was internally allocated */
 143.752 +   if ((mask & PNG_FREE_PLTE) & info_ptr->free_me)
 143.753 +   {
 143.754 +      png_zfree(png_ptr, info_ptr->palette);
 143.755 +      info_ptr->palette = NULL;
 143.756 +      info_ptr->valid &= ~PNG_INFO_PLTE;
 143.757 +      info_ptr->num_palette = 0;
 143.758 +   }
 143.759  
 143.760 -#if defined(PNG_INFO_IMAGE_SUPPORTED)
 143.761 -/* free any image bits attached to the info structure */
 143.762 -#ifdef PNG_FREE_ME_SUPPORTED
 143.763 -if ((mask & PNG_FREE_ROWS) & info_ptr->free_me)
 143.764 -#else
 143.765 -if (mask & PNG_FREE_ROWS)
 143.766 -#endif
 143.767 -{
 143.768 -    if(info_ptr->row_pointers)
 143.769 -    {
 143.770 -       int row;
 143.771 -       for (row = 0; row < (int)info_ptr->height; row++)
 143.772 -       {
 143.773 -          png_free(png_ptr, info_ptr->row_pointers[row]);
 143.774 -          info_ptr->row_pointers[row]=NULL;
 143.775 -       }
 143.776 -       png_free(png_ptr, info_ptr->row_pointers);
 143.777 -       info_ptr->row_pointers=NULL;
 143.778 -    }
 143.779 -    info_ptr->valid &= ~PNG_INFO_IDAT;
 143.780 -}
 143.781 +#ifdef PNG_INFO_IMAGE_SUPPORTED
 143.782 +   /* Free any image bits attached to the info structure */
 143.783 +   if ((mask & PNG_FREE_ROWS) & info_ptr->free_me)
 143.784 +   {
 143.785 +      if (info_ptr->row_pointers)
 143.786 +      {
 143.787 +         int row;
 143.788 +         for (row = 0; row < (int)info_ptr->height; row++)
 143.789 +         {
 143.790 +            png_free(png_ptr, info_ptr->row_pointers[row]);
 143.791 +            info_ptr->row_pointers[row] = NULL;
 143.792 +         }
 143.793 +         png_free(png_ptr, info_ptr->row_pointers);
 143.794 +         info_ptr->row_pointers = NULL;
 143.795 +      }
 143.796 +      info_ptr->valid &= ~PNG_INFO_IDAT;
 143.797 +   }
 143.798  #endif
 143.799  
 143.800 -#ifdef PNG_FREE_ME_SUPPORTED
 143.801 -   if(num == -1)
 143.802 -     info_ptr->free_me &= ~mask;
 143.803 -   else
 143.804 -     info_ptr->free_me &= ~(mask & ~PNG_FREE_MUL);
 143.805 -#endif
 143.806 +   if (num != -1)
 143.807 +      mask &= ~PNG_FREE_MUL;
 143.808 +
 143.809 +   info_ptr->free_me &= ~mask;
 143.810  }
 143.811  
 143.812  /* This is an internal routine to free any memory that the info struct is
 143.813 @@ -625,16 +535,16 @@
 143.814  void /* PRIVATE */
 143.815  png_info_destroy(png_structp png_ptr, png_infop info_ptr)
 143.816  {
 143.817 -   png_debug(1, "in png_info_destroy\n");
 143.818 +   png_debug(1, "in png_info_destroy");
 143.819  
 143.820     png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
 143.821  
 143.822 -#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
 143.823 +#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
 143.824     if (png_ptr->num_chunk_list)
 143.825     {
 143.826 -       png_free(png_ptr, png_ptr->chunk_list);
 143.827 -       png_ptr->chunk_list=NULL;
 143.828 -       png_ptr->num_chunk_list=0;
 143.829 +      png_free(png_ptr, png_ptr->chunk_list);
 143.830 +      png_ptr->chunk_list = NULL;
 143.831 +      png_ptr->num_chunk_list = 0;
 143.832     }
 143.833  #endif
 143.834  
 143.835 @@ -649,12 +559,14 @@
 143.836  png_voidp PNGAPI
 143.837  png_get_io_ptr(png_structp png_ptr)
 143.838  {
 143.839 -   if(png_ptr == NULL) return (NULL);
 143.840 +   if (png_ptr == NULL)
 143.841 +      return (NULL);
 143.842 +
 143.843     return (png_ptr->io_ptr);
 143.844  }
 143.845  
 143.846  #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
 143.847 -#if !defined(PNG_NO_STDIO)
 143.848 +#  ifdef PNG_STDIO_SUPPORTED
 143.849  /* Initialize the default input/output functions for the PNG file.  If you
 143.850   * use your own read or write routines, you can call either png_set_read_fn()
 143.851   * or png_set_write_fn() instead of png_init_io().  If you have defined
 143.852 @@ -664,81 +576,87 @@
 143.853  void PNGAPI
 143.854  png_init_io(png_structp png_ptr, png_FILE_p fp)
 143.855  {
 143.856 -   png_debug(1, "in png_init_io\n");
 143.857 -   if(png_ptr == NULL) return;
 143.858 +   png_debug(1, "in png_init_io");
 143.859 +
 143.860 +   if (png_ptr == NULL)
 143.861 +      return;
 143.862 +
 143.863     png_ptr->io_ptr = (png_voidp)fp;
 143.864  }
 143.865 -#endif
 143.866 +#  endif
 143.867  
 143.868 -#if defined(PNG_TIME_RFC1123_SUPPORTED)
 143.869 +#  ifdef PNG_TIME_RFC1123_SUPPORTED
 143.870  /* Convert the supplied time into an RFC 1123 string suitable for use in
 143.871   * a "Creation Time" or other text-based time string.
 143.872   */
 143.873 -png_charp PNGAPI
 143.874 -png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime)
 143.875 +png_const_charp PNGAPI
 143.876 +png_convert_to_rfc1123(png_structp png_ptr, png_const_timep ptime)
 143.877  {
 143.878     static PNG_CONST char short_months[12][4] =
 143.879          {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
 143.880           "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
 143.881  
 143.882 -   if(png_ptr == NULL) return (NULL);
 143.883 -   if (png_ptr->time_buffer == NULL)
 143.884 +   if (png_ptr == NULL)
 143.885 +      return (NULL);
 143.886 +
 143.887     {
 143.888 -      png_ptr->time_buffer = (png_charp)png_malloc(png_ptr, (png_uint_32)(29*
 143.889 -         png_sizeof(char)));
 143.890 +      size_t pos = 0;
 143.891 +      char number_buf[5]; /* enough for a four digit year */
 143.892 +
 143.893 +#     define APPEND_STRING(string)\
 143.894 +         pos = png_safecat(png_ptr->time_buffer, sizeof png_ptr->time_buffer,\
 143.895 +            pos, (string))
 143.896 +#     define APPEND_NUMBER(format, value)\
 143.897 +         APPEND_STRING(PNG_FORMAT_NUMBER(number_buf, format, (value)))
 143.898 +#     define APPEND(ch)\
 143.899 +         if (pos < (sizeof png_ptr->time_buffer)-1)\
 143.900 +            png_ptr->time_buffer[pos++] = (ch)
 143.901 +
 143.902 +      APPEND_NUMBER(PNG_NUMBER_FORMAT_u, (unsigned)ptime->day % 32);
 143.903 +      APPEND(' ');
 143.904 +      APPEND_STRING(short_months[(ptime->month - 1) % 12]);
 143.905 +      APPEND(' ');
 143.906 +      APPEND_NUMBER(PNG_NUMBER_FORMAT_u, ptime->year);
 143.907 +      APPEND(' ');
 143.908 +      APPEND_NUMBER(PNG_NUMBER_FORMAT_02u, (unsigned)ptime->hour % 24);
 143.909 +      APPEND(':');
 143.910 +      APPEND_NUMBER(PNG_NUMBER_FORMAT_02u, (unsigned)ptime->minute % 60);
 143.911 +      APPEND(':');
 143.912 +      APPEND_NUMBER(PNG_NUMBER_FORMAT_02u, (unsigned)ptime->second % 61);
 143.913 +      APPEND_STRING(" +0000"); /* This reliably terminates the buffer */
 143.914 +
 143.915 +#     undef APPEND
 143.916 +#     undef APPEND_NUMBER
 143.917 +#     undef APPEND_STRING
 143.918     }
 143.919  
 143.920 -#if defined(_WIN32_WCE)
 143.921 -   {
 143.922 -      wchar_t time_buf[29];
 143.923 -      wsprintf(time_buf, TEXT("%d %S %d %02d:%02d:%02d +0000"),
 143.924 -          ptime->day % 32, short_months[(ptime->month - 1) % 12],
 143.925 -        ptime->year, ptime->hour % 24, ptime->minute % 60,
 143.926 -          ptime->second % 61);
 143.927 -      WideCharToMultiByte(CP_ACP, 0, time_buf, -1, png_ptr->time_buffer, 29,
 143.928 -          NULL, NULL);
 143.929 -   }
 143.930 -#else
 143.931 -#ifdef USE_FAR_KEYWORD
 143.932 -   {
 143.933 -      char near_time_buf[29];
 143.934 -      sprintf(near_time_buf, "%d %s %d %02d:%02d:%02d +0000",
 143.935 -          ptime->day % 32, short_months[(ptime->month - 1) % 12],
 143.936 -          ptime->year, ptime->hour % 24, ptime->minute % 60,
 143.937 -          ptime->second % 61);
 143.938 -      png_memcpy(png_ptr->time_buffer, near_time_buf,
 143.939 -          29*png_sizeof(char));
 143.940 -   }
 143.941 -#else
 143.942 -   sprintf(png_ptr->time_buffer, "%d %s %d %02d:%02d:%02d +0000",
 143.943 -       ptime->day % 32, short_months[(ptime->month - 1) % 12],
 143.944 -       ptime->year, ptime->hour % 24, ptime->minute % 60,
 143.945 -       ptime->second % 61);
 143.946 -#endif
 143.947 -#endif /* _WIN32_WCE */
 143.948 -   return ((png_charp)png_ptr->time_buffer);
 143.949 +   return png_ptr->time_buffer;
 143.950  }
 143.951 -#endif /* PNG_TIME_RFC1123_SUPPORTED */
 143.952 +#  endif /* PNG_TIME_RFC1123_SUPPORTED */
 143.953  
 143.954 -#if 0
 143.955 -/* Signature string for a PNG file. */
 143.956 -png_bytep PNGAPI
 143.957 -png_sig_bytes(void)
 143.958 -{
 143.959 -   return ((png_bytep)"\211\120\116\107\015\012\032\012");
 143.960 -}
 143.961 -#endif
 143.962  #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
 143.963  
 143.964 -png_charp PNGAPI
 143.965 -png_get_copyright(png_structp png_ptr)
 143.966 +png_const_charp PNGAPI
 143.967 +png_get_copyright(png_const_structp png_ptr)
 143.968  {
 143.969 -   if (&png_ptr != NULL)  /* silence compiler warning about unused png_ptr */
 143.970 -   return ((png_charp) "\n libpng version 1.2.18 - May 15, 2007\n\
 143.971 -   Copyright (c) 1998-2007 Glenn Randers-Pehrson\n\
 143.972 -   Copyright (c) 1996-1997 Andreas Dilger\n\
 143.973 -   Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.\n");
 143.974 -   return ((png_charp) "");
 143.975 +   PNG_UNUSED(png_ptr)  /* Silence compiler warning about unused png_ptr */
 143.976 +#ifdef PNG_STRING_COPYRIGHT
 143.977 +   return PNG_STRING_COPYRIGHT
 143.978 +#else
 143.979 +#  ifdef __STDC__
 143.980 +   return PNG_STRING_NEWLINE \
 143.981 +     "libpng version 1.5.4 - July 7, 2011" PNG_STRING_NEWLINE \
 143.982 +     "Copyright (c) 1998-2011 Glenn Randers-Pehrson" PNG_STRING_NEWLINE \
 143.983 +     "Copyright (c) 1996-1997 Andreas Dilger" PNG_STRING_NEWLINE \
 143.984 +     "Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc." \
 143.985 +     PNG_STRING_NEWLINE;
 143.986 +#  else
 143.987 +      return "libpng version 1.5.4 - July 7, 2011\
 143.988 +      Copyright (c) 1998-2011 Glenn Randers-Pehrson\
 143.989 +      Copyright (c) 1996-1997 Andreas Dilger\
 143.990 +      Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.";
 143.991 +#  endif
 143.992 +#endif
 143.993  }
 143.994  
 143.995  /* The following return the library version as a short string in the
 143.996 @@ -749,141 +667,1784 @@
 143.997   * png_get_header_ver().  Due to the version_nn_nn_nn typedef guard,
 143.998   * it is guaranteed that png.c uses the correct version of png.h.
 143.999   */
143.1000 -png_charp PNGAPI
143.1001 -png_get_libpng_ver(png_structp png_ptr)
143.1002 +png_const_charp PNGAPI
143.1003 +png_get_libpng_ver(png_const_structp png_ptr)
143.1004  {
143.1005     /* Version of *.c files used when building libpng */
143.1006 -   if (&png_ptr != NULL)  /* silence compiler warning about unused png_ptr */
143.1007 -      return ((png_charp) PNG_LIBPNG_VER_STRING);
143.1008 -   return ((png_charp) "");
143.1009 +   return png_get_header_ver(png_ptr);
143.1010  }
143.1011  
143.1012 -png_charp PNGAPI
143.1013 -png_get_header_ver(png_structp png_ptr)
143.1014 +png_const_charp PNGAPI
143.1015 +png_get_header_ver(png_const_structp png_ptr)
143.1016  {
143.1017     /* Version of *.h files used when building libpng */
143.1018 -   if (&png_ptr != NULL)  /* silence compiler warning about unused png_ptr */
143.1019 -      return ((png_charp) PNG_LIBPNG_VER_STRING);
143.1020 -   return ((png_charp) "");
143.1021 +   PNG_UNUSED(png_ptr)  /* Silence compiler warning about unused png_ptr */
143.1022 +   return PNG_LIBPNG_VER_STRING;
143.1023  }
143.1024  
143.1025 -png_charp PNGAPI
143.1026 -png_get_header_version(png_structp png_ptr)
143.1027 +png_const_charp PNGAPI
143.1028 +png_get_header_version(png_const_structp png_ptr)
143.1029  {
143.1030     /* Returns longer string containing both version and date */
143.1031 -   if (&png_ptr != NULL)  /* silence compiler warning about unused png_ptr */
143.1032 -      return ((png_charp) PNG_HEADER_VERSION_STRING);
143.1033 -   return ((png_charp) "");
143.1034 +   PNG_UNUSED(png_ptr)  /* Silence compiler warning about unused png_ptr */
143.1035 +#ifdef __STDC__
143.1036 +   return PNG_HEADER_VERSION_STRING
143.1037 +#  ifndef PNG_READ_SUPPORTED
143.1038 +   "     (NO READ SUPPORT)"
143.1039 +#  endif
143.1040 +   PNG_STRING_NEWLINE;
143.1041 +#else
143.1042 +   return PNG_HEADER_VERSION_STRING;
143.1043 +#endif
143.1044  }
143.1045  
143.1046  #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
143.1047 -#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
143.1048 +#  ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
143.1049  int PNGAPI
143.1050 -png_handle_as_unknown(png_structp png_ptr, png_bytep chunk_name)
143.1051 +png_handle_as_unknown(png_structp png_ptr, png_const_bytep chunk_name)
143.1052  {
143.1053 -   /* check chunk_name and return "keep" value if it's on the list, else 0 */
143.1054 +   /* Check chunk_name and return "keep" value if it's on the list, else 0 */
143.1055     int i;
143.1056     png_bytep p;
143.1057 -   if((png_ptr == NULL && chunk_name == NULL) || png_ptr->num_chunk_list<=0)
143.1058 +   if (png_ptr == NULL || chunk_name == NULL || png_ptr->num_chunk_list<=0)
143.1059        return 0;
143.1060 -   p=png_ptr->chunk_list+png_ptr->num_chunk_list*5-5;
143.1061 -   for (i = png_ptr->num_chunk_list; i; i--, p-=5)
143.1062 +
143.1063 +   p = png_ptr->chunk_list + png_ptr->num_chunk_list*5 - 5;
143.1064 +   for (i = png_ptr->num_chunk_list; i; i--, p -= 5)
143.1065        if (!png_memcmp(chunk_name, p, 4))
143.1066 -        return ((int)*(p+4));
143.1067 +        return ((int)*(p + 4));
143.1068     return 0;
143.1069  }
143.1070 -#endif
143.1071 +#  endif
143.1072 +#endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
143.1073  
143.1074 +#ifdef PNG_READ_SUPPORTED
143.1075  /* This function, added to libpng-1.0.6g, is untested. */
143.1076  int PNGAPI
143.1077  png_reset_zstream(png_structp png_ptr)
143.1078  {
143.1079 -   if (png_ptr == NULL) return Z_STREAM_ERROR;
143.1080 +   if (png_ptr == NULL)
143.1081 +      return Z_STREAM_ERROR;
143.1082 +
143.1083     return (inflateReset(&png_ptr->zstream));
143.1084  }
143.1085 -#endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
143.1086 +#endif /* PNG_READ_SUPPORTED */
143.1087  
143.1088  /* This function was added to libpng-1.0.7 */
143.1089  png_uint_32 PNGAPI
143.1090  png_access_version_number(void)
143.1091  {
143.1092     /* Version of *.c files used when building libpng */
143.1093 -   return((png_uint_32) PNG_LIBPNG_VER);
143.1094 +   return((png_uint_32)PNG_LIBPNG_VER);
143.1095  }
143.1096  
143.1097  
143.1098 -#if defined(PNG_READ_SUPPORTED) && defined(PNG_ASSEMBLER_CODE_SUPPORTED)
143.1099 -#if !defined(PNG_1_0_X)
143.1100 -#if defined(PNG_MMX_CODE_SUPPORTED)
143.1101 -/* this INTERNAL function was added to libpng 1.2.0 */
143.1102 -void /* PRIVATE */
143.1103 -png_init_mmx_flags (png_structp png_ptr)
143.1104 -{
143.1105 -    if(png_ptr == NULL) return;
143.1106 -    png_ptr->mmx_rowbytes_threshold = 0;
143.1107 -    png_ptr->mmx_bitdepth_threshold = 0;
143.1108 -
143.1109 -#  if (defined(PNG_USE_PNGVCRD) || defined(PNG_USE_PNGGCCRD))
143.1110 -
143.1111 -    png_ptr->asm_flags |= PNG_ASM_FLAG_MMX_SUPPORT_COMPILED;
143.1112 -
143.1113 -    if (png_mmx_support() > 0) {
143.1114 -        png_ptr->asm_flags |= PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU
143.1115 -#    ifdef PNG_HAVE_MMX_COMBINE_ROW
143.1116 -                              | PNG_ASM_FLAG_MMX_READ_COMBINE_ROW
143.1117 -#    endif
143.1118 -#    ifdef PNG_HAVE_MMX_READ_INTERLACE
143.1119 -                              | PNG_ASM_FLAG_MMX_READ_INTERLACE
143.1120 -#    endif
143.1121 -#    ifndef PNG_HAVE_MMX_READ_FILTER_ROW
143.1122 -                              ;
143.1123 -#    else
143.1124 -                              | PNG_ASM_FLAG_MMX_READ_FILTER_SUB
143.1125 -                              | PNG_ASM_FLAG_MMX_READ_FILTER_UP
143.1126 -                              | PNG_ASM_FLAG_MMX_READ_FILTER_AVG
143.1127 -                              | PNG_ASM_FLAG_MMX_READ_FILTER_PAETH ;
143.1128 -
143.1129 -        png_ptr->mmx_rowbytes_threshold = PNG_MMX_ROWBYTES_THRESHOLD_DEFAULT;
143.1130 -        png_ptr->mmx_bitdepth_threshold = PNG_MMX_BITDEPTH_THRESHOLD_DEFAULT;
143.1131 -#    endif
143.1132 -    } else {
143.1133 -        png_ptr->asm_flags &= ~( PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU
143.1134 -                               | PNG_MMX_READ_FLAGS
143.1135 -                               | PNG_MMX_WRITE_FLAGS );
143.1136 -    }
143.1137 -
143.1138 -#  else /* !(PNGVCRD || PNGGCCRD) */
143.1139 -
143.1140 -    /* clear all MMX flags; no support is compiled in */
143.1141 -    png_ptr->asm_flags &= ~( PNG_MMX_FLAGS );
143.1142 -
143.1143 -#  endif /* ?(PNGVCRD || PNGGCCRD) */
143.1144 -}
143.1145 -
143.1146 -#endif /* !(PNG_MMX_CODE_SUPPORTED) */
143.1147 -
143.1148 -/* this function was added to libpng 1.2.0 */
143.1149 -#if !defined(PNG_USE_PNGGCCRD) && \
143.1150 -    !(defined(PNG_MMX_CODE_SUPPORTED) && defined(PNG_USE_PNGVCRD))
143.1151 -int PNGAPI
143.1152 -png_mmx_support(void)
143.1153 -{
143.1154 -    return -1;
143.1155 -}
143.1156 -#endif
143.1157 -#endif /* PNG_1_0_X  && PNG_ASSEMBLER_CODE_SUPPORTED */
143.1158 -#endif /* PNG_READ_SUPPORTED */
143.1159  
143.1160  #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
143.1161 -#ifdef PNG_SIZE_T
143.1162 +#  ifdef PNG_SIZE_T
143.1163  /* Added at libpng version 1.2.6 */
143.1164     PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size));
143.1165  png_size_t PNGAPI
143.1166  png_convert_size(size_t size)
143.1167  {
143.1168 -  if (size > (png_size_t)-1)
143.1169 -     PNG_ABORT();  /* We haven't got access to png_ptr, so no png_error() */
143.1170 -  return ((png_size_t)size);
143.1171 +   if (size > (png_size_t)-1)
143.1172 +      PNG_ABORT();  /* We haven't got access to png_ptr, so no png_error() */
143.1173 +
143.1174 +   return ((png_size_t)size);
143.1175  }
143.1176 -#endif /* PNG_SIZE_T */
143.1177 +#  endif /* PNG_SIZE_T */
143.1178 +
143.1179 +/* Added at libpng version 1.2.34 and 1.4.0 (moved from pngset.c) */
143.1180 +#  ifdef PNG_CHECK_cHRM_SUPPORTED
143.1181 +
143.1182 +int /* PRIVATE */
143.1183 +png_check_cHRM_fixed(png_structp png_ptr,
143.1184 +   png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x,
143.1185 +   png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y,
143.1186 +   png_fixed_point blue_x, png_fixed_point blue_y)
143.1187 +{
143.1188 +   int ret = 1;
143.1189 +   unsigned long xy_hi,xy_lo,yx_hi,yx_lo;
143.1190 +
143.1191 +   png_debug(1, "in function png_check_cHRM_fixed");
143.1192 +
143.1193 +   if (png_ptr == NULL)
143.1194 +      return 0;
143.1195 +
143.1196 +   /* (x,y,z) values are first limited to 0..100000 (PNG_FP_1), the white
143.1197 +    * y must also be greater than 0.  To test for the upper limit calculate
143.1198 +    * (PNG_FP_1-y) - x must be <= to this for z to be >= 0 (and the expression
143.1199 +    * cannot overflow.)  At this point we know x and y are >= 0 and (x+y) is
143.1200 +    * <= PNG_FP_1.  The previous test on PNG_MAX_UINT_31 is removed because it
143.1201 +    * pointless (and it produces compiler warnings!)
143.1202 +    */
143.1203 +   if (white_x < 0 || white_y <= 0 ||
143.1204 +         red_x < 0 ||   red_y <  0 ||
143.1205 +       green_x < 0 || green_y <  0 ||
143.1206 +        blue_x < 0 ||  blue_y <  0)
143.1207 +   {
143.1208 +      png_warning(png_ptr,
143.1209 +        "Ignoring attempt to set negative chromaticity value");
143.1210 +      ret = 0;
143.1211 +   }
143.1212 +   /* And (x+y) must be <= PNG_FP_1 (so z is >= 0) */
143.1213 +   if (white_x > PNG_FP_1 - white_y)
143.1214 +   {
143.1215 +      png_warning(png_ptr, "Invalid cHRM white point");
143.1216 +      ret = 0;
143.1217 +   }
143.1218 +
143.1219 +   if (red_x > PNG_FP_1 - red_y)
143.1220 +   {
143.1221 +      png_warning(png_ptr, "Invalid cHRM red point");
143.1222 +      ret = 0;
143.1223 +   }
143.1224 +
143.1225 +   if (green_x > PNG_FP_1 - green_y)
143.1226 +   {
143.1227 +      png_warning(png_ptr, "Invalid cHRM green point");
143.1228 +      ret = 0;
143.1229 +   }
143.1230 +
143.1231 +   if (blue_x > PNG_FP_1 - blue_y)
143.1232 +   {
143.1233 +      png_warning(png_ptr, "Invalid cHRM blue point");
143.1234 +      ret = 0;
143.1235 +   }
143.1236 +
143.1237 +   png_64bit_product(green_x - red_x, blue_y - red_y, &xy_hi, &xy_lo);
143.1238 +   png_64bit_product(green_y - red_y, blue_x - red_x, &yx_hi, &yx_lo);
143.1239 +
143.1240 +   if (xy_hi == yx_hi && xy_lo == yx_lo)
143.1241 +   {
143.1242 +      png_warning(png_ptr,
143.1243 +         "Ignoring attempt to set cHRM RGB triangle with zero area");
143.1244 +      ret = 0;
143.1245 +   }
143.1246 +
143.1247 +   return ret;
143.1248 +}
143.1249 +#  endif /* PNG_CHECK_cHRM_SUPPORTED */
143.1250 +
143.1251 +void /* PRIVATE */
143.1252 +png_check_IHDR(png_structp png_ptr,
143.1253 +   png_uint_32 width, png_uint_32 height, int bit_depth,
143.1254 +   int color_type, int interlace_type, int compression_type,
143.1255 +   int filter_type)
143.1256 +{
143.1257 +   int error = 0;
143.1258 +
143.1259 +   /* Check for width and height valid values */
143.1260 +   if (width == 0)
143.1261 +   {
143.1262 +      png_warning(png_ptr, "Image width is zero in IHDR");
143.1263 +      error = 1;
143.1264 +   }
143.1265 +
143.1266 +   if (height == 0)
143.1267 +   {
143.1268 +      png_warning(png_ptr, "Image height is zero in IHDR");
143.1269 +      error = 1;
143.1270 +   }
143.1271 +
143.1272 +#  ifdef PNG_SET_USER_LIMITS_SUPPORTED
143.1273 +   if (width > png_ptr->user_width_max)
143.1274 +
143.1275 +#  else
143.1276 +   if (width > PNG_USER_WIDTH_MAX)
143.1277 +#  endif
143.1278 +   {
143.1279 +      png_warning(png_ptr, "Image width exceeds user limit in IHDR");
143.1280 +      error = 1;
143.1281 +   }
143.1282 +
143.1283 +#  ifdef PNG_SET_USER_LIMITS_SUPPORTED
143.1284 +   if (height > png_ptr->user_height_max)
143.1285 +#  else
143.1286 +   if (height > PNG_USER_HEIGHT_MAX)
143.1287 +#  endif
143.1288 +   {
143.1289 +      png_warning(png_ptr, "Image height exceeds user limit in IHDR");
143.1290 +      error = 1;
143.1291 +   }
143.1292 +
143.1293 +   if (width > PNG_UINT_31_MAX)
143.1294 +   {
143.1295 +      png_warning(png_ptr, "Invalid image width in IHDR");
143.1296 +      error = 1;
143.1297 +   }
143.1298 +
143.1299 +   if (height > PNG_UINT_31_MAX)
143.1300 +   {
143.1301 +      png_warning(png_ptr, "Invalid image height in IHDR");
143.1302 +      error = 1;
143.1303 +   }
143.1304 +
143.1305 +   if (width > (PNG_UINT_32_MAX
143.1306 +                 >> 3)      /* 8-byte RGBA pixels */
143.1307 +                 - 48       /* bigrowbuf hack */
143.1308 +                 - 1        /* filter byte */
143.1309 +                 - 7*8      /* rounding of width to multiple of 8 pixels */
143.1310 +                 - 8)       /* extra max_pixel_depth pad */
143.1311 +      png_warning(png_ptr, "Width is too large for libpng to process pixels");
143.1312 +
143.1313 +   /* Check other values */
143.1314 +   if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 &&
143.1315 +       bit_depth != 8 && bit_depth != 16)
143.1316 +   {
143.1317 +      png_warning(png_ptr, "Invalid bit depth in IHDR");
143.1318 +      error = 1;
143.1319 +   }
143.1320 +
143.1321 +   if (color_type < 0 || color_type == 1 ||
143.1322 +       color_type == 5 || color_type > 6)
143.1323 +   {
143.1324 +      png_warning(png_ptr, "Invalid color type in IHDR");
143.1325 +      error = 1;
143.1326 +   }
143.1327 +
143.1328 +   if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) ||
143.1329 +       ((color_type == PNG_COLOR_TYPE_RGB ||
143.1330 +         color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
143.1331 +         color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8))
143.1332 +   {
143.1333 +      png_warning(png_ptr, "Invalid color type/bit depth combination in IHDR");
143.1334 +      error = 1;
143.1335 +   }
143.1336 +
143.1337 +   if (interlace_type >= PNG_INTERLACE_LAST)
143.1338 +   {
143.1339 +      png_warning(png_ptr, "Unknown interlace method in IHDR");
143.1340 +      error = 1;
143.1341 +   }
143.1342 +
143.1343 +   if (compression_type != PNG_COMPRESSION_TYPE_BASE)
143.1344 +   {
143.1345 +      png_warning(png_ptr, "Unknown compression method in IHDR");
143.1346 +      error = 1;
143.1347 +   }
143.1348 +
143.1349 +#  ifdef PNG_MNG_FEATURES_SUPPORTED
143.1350 +   /* Accept filter_method 64 (intrapixel differencing) only if
143.1351 +    * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and
143.1352 +    * 2. Libpng did not read a PNG signature (this filter_method is only
143.1353 +    *    used in PNG datastreams that are embedded in MNG datastreams) and
143.1354 +    * 3. The application called png_permit_mng_features with a mask that
143.1355 +    *    included PNG_FLAG_MNG_FILTER_64 and
143.1356 +    * 4. The filter_method is 64 and
143.1357 +    * 5. The color_type is RGB or RGBA
143.1358 +    */
143.1359 +   if ((png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) &&
143.1360 +       png_ptr->mng_features_permitted)
143.1361 +      png_warning(png_ptr, "MNG features are not allowed in a PNG datastream");
143.1362 +
143.1363 +   if (filter_type != PNG_FILTER_TYPE_BASE)
143.1364 +   {
143.1365 +      if (!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
143.1366 +          (filter_type == PNG_INTRAPIXEL_DIFFERENCING) &&
143.1367 +          ((png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) == 0) &&
143.1368 +          (color_type == PNG_COLOR_TYPE_RGB ||
143.1369 +          color_type == PNG_COLOR_TYPE_RGB_ALPHA)))
143.1370 +      {
143.1371 +         png_warning(png_ptr, "Unknown filter method in IHDR");
143.1372 +         error = 1;
143.1373 +      }
143.1374 +
143.1375 +      if (png_ptr->mode & PNG_HAVE_PNG_SIGNATURE)
143.1376 +      {
143.1377 +         png_warning(png_ptr, "Invalid filter method in IHDR");
143.1378 +         error = 1;
143.1379 +      }
143.1380 +   }
143.1381 +
143.1382 +#  else
143.1383 +   if (filter_type != PNG_FILTER_TYPE_BASE)
143.1384 +   {
143.1385 +      png_warning(png_ptr, "Unknown filter method in IHDR");
143.1386 +      error = 1;
143.1387 +   }
143.1388 +#  endif
143.1389 +
143.1390 +   if (error == 1)
143.1391 +      png_error(png_ptr, "Invalid IHDR data");
143.1392 +}
143.1393 +
143.1394 +#if defined(PNG_sCAL_SUPPORTED) || defined(PNG_pCAL_SUPPORTED)
143.1395 +/* ASCII to fp functions */
143.1396 +/* Check an ASCII formated floating point value, see the more detailed
143.1397 + * comments in pngpriv.h
143.1398 + */
143.1399 +/* The following is used internally to preserve the sticky flags */
143.1400 +#define png_fp_add(state, flags) ((state) |= (flags))
143.1401 +#define png_fp_set(state, value) ((state) = (value) | ((state) & PNG_FP_STICKY))
143.1402 +
143.1403 +int /* PRIVATE */
143.1404 +png_check_fp_number(png_const_charp string, png_size_t size, int *statep,
143.1405 +   png_size_tp whereami)
143.1406 +{
143.1407 +   int state = *statep;
143.1408 +   png_size_t i = *whereami;
143.1409 +
143.1410 +   while (i < size)
143.1411 +   {
143.1412 +      int type;
143.1413 +      /* First find the type of the next character */
143.1414 +      switch (string[i])
143.1415 +      {
143.1416 +      case 43:  type = PNG_FP_SAW_SIGN;                   break;
143.1417 +      case 45:  type = PNG_FP_SAW_SIGN + PNG_FP_NEGATIVE; break;
143.1418 +      case 46:  type = PNG_FP_SAW_DOT;                    break;
143.1419 +      case 48:  type = PNG_FP_SAW_DIGIT;                  break;
143.1420 +      case 49: case 50: case 51: case 52:
143.1421 +      case 53: case 54: case 55: case 56:
143.1422 +      case 57:  type = PNG_FP_SAW_DIGIT + PNG_FP_NONZERO; break;
143.1423 +      case 69:
143.1424 +      case 101: type = PNG_FP_SAW_E;                      break;
143.1425 +      default:  goto PNG_FP_End;
143.1426 +      }
143.1427 +
143.1428 +      /* Now deal with this type according to the current
143.1429 +       * state, the type is arranged to not overlap the
143.1430 +       * bits of the PNG_FP_STATE.
143.1431 +       */
143.1432 +      switch ((state & PNG_FP_STATE) + (type & PNG_FP_SAW_ANY))
143.1433 +      {
143.1434 +      case PNG_FP_INTEGER + PNG_FP_SAW_SIGN:
143.1435 +         if (state & PNG_FP_SAW_ANY)
143.1436 +            goto PNG_FP_End; /* not a part of the number */
143.1437 +
143.1438 +         png_fp_add(state, type);
143.1439 +         break;
143.1440 +
143.1441 +      case PNG_FP_INTEGER + PNG_FP_SAW_DOT:
143.1442 +         /* Ok as trailer, ok as lead of fraction. */
143.1443 +         if (state & PNG_FP_SAW_DOT) /* two dots */
143.1444 +            goto PNG_FP_End;
143.1445 +
143.1446 +         else if (state & PNG_FP_SAW_DIGIT) /* trailing dot? */
143.1447 +            png_fp_add(state, type);
143.1448 +
143.1449 +         else
143.1450 +            png_fp_set(state, PNG_FP_FRACTION | type);
143.1451 +
143.1452 +         break;
143.1453 +
143.1454 +      case PNG_FP_INTEGER + PNG_FP_SAW_DIGIT:
143.1455 +         if (state & PNG_FP_SAW_DOT) /* delayed fraction */
143.1456 +            png_fp_set(state, PNG_FP_FRACTION | PNG_FP_SAW_DOT);
143.1457 +
143.1458 +         png_fp_add(state, type | PNG_FP_WAS_VALID);
143.1459 +
143.1460 +         break;
143.1461 +
143.1462 +      case PNG_FP_INTEGER + PNG_FP_SAW_E:
143.1463 +         if ((state & PNG_FP_SAW_DIGIT) == 0)
143.1464 +            goto PNG_FP_End;
143.1465 +
143.1466 +         png_fp_set(state, PNG_FP_EXPONENT);
143.1467 +
143.1468 +         break;
143.1469 +
143.1470 +   /* case PNG_FP_FRACTION + PNG_FP_SAW_SIGN:
143.1471 +         goto PNG_FP_End; ** no sign in fraction */
143.1472 +
143.1473 +   /* case PNG_FP_FRACTION + PNG_FP_SAW_DOT:
143.1474 +         goto PNG_FP_End; ** Because SAW_DOT is always set */
143.1475 +
143.1476 +      case PNG_FP_FRACTION + PNG_FP_SAW_DIGIT:
143.1477 +         png_fp_add(state, type | PNG_FP_WAS_VALID);
143.1478 +         break;
143.1479 +
143.1480 +      case PNG_FP_FRACTION + PNG_FP_SAW_E:
143.1481 +         /* This is correct because the trailing '.' on an
143.1482 +          * integer is handled above - so we can only get here
143.1483 +          * with the sequence ".E" (with no preceding digits).
143.1484 +          */
143.1485 +         if ((state & PNG_FP_SAW_DIGIT) == 0)
143.1486 +            goto PNG_FP_End;
143.1487 +
143.1488 +         png_fp_set(state, PNG_FP_EXPONENT);
143.1489 +
143.1490 +         break;
143.1491 +
143.1492 +      case PNG_FP_EXPONENT + PNG_FP_SAW_SIGN:
143.1493 +         if (state & PNG_FP_SAW_ANY)
143.1494 +            goto PNG_FP_End; /* not a part of the number */
143.1495 +
143.1496 +         png_fp_add(state, PNG_FP_SAW_SIGN);
143.1497 +
143.1498 +         break;
143.1499 +
143.1500 +   /* case PNG_FP_EXPONENT + PNG_FP_SAW_DOT:
143.1501 +         goto PNG_FP_End; */
143.1502 +
143.1503 +      case PNG_FP_EXPONENT + PNG_FP_SAW_DIGIT:
143.1504 +         png_fp_add(state, PNG_FP_SAW_DIGIT | PNG_FP_WAS_VALID);
143.1505 +
143.1506 +         break;
143.1507 +
143.1508 +   /* case PNG_FP_EXPONEXT + PNG_FP_SAW_E:
143.1509 +         goto PNG_FP_End; */
143.1510 +
143.1511 +      default: goto PNG_FP_End; /* I.e. break 2 */
143.1512 +      }
143.1513 +
143.1514 +      /* The character seems ok, continue. */
143.1515 +      ++i;
143.1516 +   }
143.1517 +
143.1518 +PNG_FP_End:
143.1519 +   /* Here at the end, update the state and return the correct
143.1520 +    * return code.
143.1521 +    */
143.1522 +   *statep = state;
143.1523 +   *whereami = i;
143.1524 +
143.1525 +   return (state & PNG_FP_SAW_DIGIT) != 0;
143.1526 +}
143.1527 +
143.1528 +
143.1529 +/* The same but for a complete string. */
143.1530 +int
143.1531 +png_check_fp_string(png_const_charp string, png_size_t size)
143.1532 +{
143.1533 +   int        state=0;
143.1534 +   png_size_t char_index=0;
143.1535 +
143.1536 +   if (png_check_fp_number(string, size, &state, &char_index) &&
143.1537 +      (char_index == size || string[char_index] == 0))
143.1538 +      return state /* must be non-zero - see above */;
143.1539 +
143.1540 +   return 0; /* i.e. fail */
143.1541 +}
143.1542 +#endif /* pCAL or sCAL */
143.1543 +
143.1544 +#ifdef PNG_READ_sCAL_SUPPORTED
143.1545 +#  ifdef PNG_FLOATING_POINT_SUPPORTED
143.1546 +/* Utility used below - a simple accurate power of ten from an integral
143.1547 + * exponent.
143.1548 + */
143.1549 +static double
143.1550 +png_pow10(int power)
143.1551 +{
143.1552 +   int recip = 0;
143.1553 +   double d = 1;
143.1554 +
143.1555 +   /* Handle negative exponent with a reciprocal at the end because
143.1556 +    * 10 is exact whereas .1 is inexact in base 2
143.1557 +    */
143.1558 +   if (power < 0)
143.1559 +   {
143.1560 +      if (power < DBL_MIN_10_EXP) return 0;
143.1561 +      recip = 1, power = -power;
143.1562 +   }
143.1563 +
143.1564 +   if (power > 0)
143.1565 +   {
143.1566 +      /* Decompose power bitwise. */
143.1567 +      double mult = 10;
143.1568 +      do
143.1569 +      {
143.1570 +         if (power & 1) d *= mult;
143.1571 +         mult *= mult;
143.1572 +         power >>= 1;
143.1573 +      }
143.1574 +      while (power > 0);
143.1575 +
143.1576 +      if (recip) d = 1/d;
143.1577 +   }
143.1578 +   /* else power is 0 and d is 1 */
143.1579 +
143.1580 +   return d;
143.1581 +}
143.1582 +
143.1583 +/* Function to format a floating point value in ASCII with a given
143.1584 + * precision.
143.1585 + */
143.1586 +void /* PRIVATE */
143.1587 +png_ascii_from_fp(png_structp png_ptr, png_charp ascii, png_size_t size,
143.1588 +    double fp, unsigned int precision)
143.1589 +{
143.1590 +   /* We use standard functions from math.h, but not printf because
143.1591 +    * that would require stdio.  The caller must supply a buffer of
143.1592 +    * sufficient size or we will png_error.  The tests on size and
143.1593 +    * the space in ascii[] consumed are indicated below.
143.1594 +    */
143.1595 +   if (precision < 1)
143.1596 +      precision = DBL_DIG;
143.1597 +
143.1598 +   /* Enforce the limit of the implementation precision too. */
143.1599 +   if (precision > DBL_DIG+1)
143.1600 +      precision = DBL_DIG+1;
143.1601 +
143.1602 +   /* Basic sanity checks */
143.1603 +   if (size >= precision+5) /* See the requirements below. */
143.1604 +   {
143.1605 +      if (fp < 0)
143.1606 +      {
143.1607 +         fp = -fp;
143.1608 +         *ascii++ = 45; /* '-'  PLUS 1 TOTAL 1 */
143.1609 +         --size;
143.1610 +      }
143.1611 +
143.1612 +      if (fp >= DBL_MIN && fp <= DBL_MAX)
143.1613 +      {
143.1614 +         int exp_b10;       /* A base 10 exponent */
143.1615 +         double base;   /* 10^exp_b10 */
143.1616 +
143.1617 +         /* First extract a base 10 exponent of the number,
143.1618 +          * the calculation below rounds down when converting
143.1619 +          * from base 2 to base 10 (multiply by log10(2) -
143.1620 +          * 0.3010, but 77/256 is 0.3008, so exp_b10 needs to
143.1621 +          * be increased.  Note that the arithmetic shift
143.1622 +          * performs a floor() unlike C arithmetic - using a
143.1623 +          * C multiply would break the following for negative
143.1624 +          * exponents.
143.1625 +          */
143.1626 +         (void)frexp(fp, &exp_b10); /* exponent to base 2 */
143.1627 +
143.1628 +         exp_b10 = (exp_b10 * 77) >> 8; /* <= exponent to base 10 */
143.1629 +
143.1630 +         /* Avoid underflow here. */
143.1631 +         base = png_pow10(exp_b10); /* May underflow */
143.1632 +
143.1633 +         while (base < DBL_MIN || base < fp)
143.1634 +         {
143.1635 +            /* And this may overflow. */
143.1636 +            double test = png_pow10(exp_b10+1);
143.1637 +
143.1638 +            if (test <= DBL_MAX)
143.1639 +               ++exp_b10, base = test;
143.1640 +
143.1641 +            else
143.1642 +               break;
143.1643 +         }
143.1644 +
143.1645 +         /* Normalize fp and correct exp_b10, after this fp is in the
143.1646 +          * range [.1,1) and exp_b10 is both the exponent and the digit
143.1647 +          * *before* which the decimal point should be inserted
143.1648 +          * (starting with 0 for the first digit).  Note that this
143.1649 +          * works even if 10^exp_b10 is out of range because of the
143.1650 +          * test on DBL_MAX above.
143.1651 +          */
143.1652 +         fp /= base;
143.1653 +         while (fp >= 1) fp /= 10, ++exp_b10;
143.1654 +
143.1655 +         /* Because of the code above fp may, at this point, be
143.1656 +          * less than .1, this is ok because the code below can
143.1657 +          * handle the leading zeros this generates, so no attempt
143.1658 +          * is made to correct that here.
143.1659 +          */
143.1660 +
143.1661 +         {
143.1662 +            int czero, clead, cdigits;
143.1663 +            char exponent[10];
143.1664 +
143.1665 +            /* Allow up to two leading zeros - this will not lengthen
143.1666 +             * the number compared to using E-n.
143.1667 +             */
143.1668 +            if (exp_b10 < 0 && exp_b10 > -3) /* PLUS 3 TOTAL 4 */
143.1669 +            {
143.1670 +               czero = -exp_b10; /* PLUS 2 digits: TOTAL 3 */
143.1671 +               exp_b10 = 0;      /* Dot added below before first output. */
143.1672 +            }
143.1673 +            else
143.1674 +               czero = 0;    /* No zeros to add */
143.1675 +
143.1676 +            /* Generate the digit list, stripping trailing zeros and
143.1677 +             * inserting a '.' before a digit if the exponent is 0.
143.1678 +             */
143.1679 +            clead = czero; /* Count of leading zeros */
143.1680 +            cdigits = 0;   /* Count of digits in list. */
143.1681 +
143.1682 +            do
143.1683 +            {
143.1684 +               double d;
143.1685 +
143.1686 +               fp *= 10;
143.1687 +               /* Use modf here, not floor and subtract, so that
143.1688 +                * the separation is done in one step.  At the end
143.1689 +                * of the loop don't break the number into parts so
143.1690 +                * that the final digit is rounded.
143.1691 +                */
143.1692 +               if (cdigits+czero-clead+1 < (int)precision)
143.1693 +                  fp = modf(fp, &d);
143.1694 +
143.1695 +               else
143.1696 +               {
143.1697 +                  d = floor(fp + .5);
143.1698 +
143.1699 +                  if (d > 9)
143.1700 +                  {
143.1701 +                     /* Rounding up to 10, handle that here. */
143.1702 +                     if (czero > 0)
143.1703 +                     {
143.1704 +                        --czero, d = 1;
143.1705 +                        if (cdigits == 0) --clead;
143.1706 +                     }
143.1707 +                     else
143.1708 +                     {
143.1709 +                        while (cdigits > 0 && d > 9)
143.1710 +                        {
143.1711 +                           int ch = *--ascii;
143.1712 +
143.1713 +                           if (exp_b10 != (-1))
143.1714 +                              ++exp_b10;
143.1715 +
143.1716 +                           else if (ch == 46)
143.1717 +                           {
143.1718 +                              ch = *--ascii, ++size;
143.1719 +                              /* Advance exp_b10 to '1', so that the
143.1720 +                               * decimal point happens after the
143.1721 +                               * previous digit.
143.1722 +                               */
143.1723 +                              exp_b10 = 1;
143.1724 +                           }
143.1725 +
143.1726 +                           --cdigits;
143.1727 +                           d = ch - 47;  /* I.e. 1+(ch-48) */
143.1728 +                        }
143.1729 +
143.1730 +                        /* Did we reach the beginning? If so adjust the
143.1731 +                         * exponent but take into account the leading
143.1732 +                         * decimal point.
143.1733 +                         */
143.1734 +                        if (d > 9)  /* cdigits == 0 */
143.1735 +                        {
143.1736 +                           if (exp_b10 == (-1))
143.1737 +                           {
143.1738 +                              /* Leading decimal point (plus zeros?), if
143.1739 +                               * we lose the decimal point here it must
143.1740 +                               * be reentered below.
143.1741 +                               */
143.1742 +                              int ch = *--ascii;
143.1743 +
143.1744 +                              if (ch == 46)
143.1745 +                                 ++size, exp_b10 = 1;
143.1746 +
143.1747 +                              /* Else lost a leading zero, so 'exp_b10' is
143.1748 +                               * still ok at (-1)
143.1749 +                               */
143.1750 +                           }
143.1751 +                           else
143.1752 +                              ++exp_b10;
143.1753 +
143.1754 +                           /* In all cases we output a '1' */
143.1755 +                           d = 1;
143.1756 +                        }
143.1757 +                     }
143.1758 +                  }
143.1759 +                  fp = 0; /* Guarantees termination below. */
143.1760 +               }
143.1761 +
143.1762 +               if (d == 0)
143.1763 +               {
143.1764 +                  ++czero;
143.1765 +                  if (cdigits == 0) ++clead;
143.1766 +               }
143.1767 +               else
143.1768 +               {
143.1769 +                  /* Included embedded zeros in the digit count. */
143.1770 +                  cdigits += czero - clead;
143.1771 +                  clead = 0;
143.1772 +
143.1773 +                  while (czero > 0)
143.1774 +                  {
143.1775 +                     /* exp_b10 == (-1) means we just output the decimal
143.1776 +                      * place - after the DP don't adjust 'exp_b10' any
143.1777 +                      * more!
143.1778 +                      */
143.1779 +                     if (exp_b10 != (-1))
143.1780 +                     {
143.1781 +                        if (exp_b10 == 0) *ascii++ = 46, --size;
143.1782 +                        /* PLUS 1: TOTAL 4 */
143.1783 +                        --exp_b10;
143.1784 +                     }
143.1785 +                     *ascii++ = 48, --czero;
143.1786 +                  }
143.1787 +
143.1788 +                  if (exp_b10 != (-1))
143.1789 +                  {
143.1790 +                     if (exp_b10 == 0) *ascii++ = 46, --size; /* counted
143.1791 +                                                                 above */
143.1792 +                     --exp_b10;
143.1793 +                  }
143.1794 +                  *ascii++ = (char)(48 + (int)d), ++cdigits;
143.1795 +               }
143.1796 +            }
143.1797 +            while (cdigits+czero-clead < (int)precision && fp > DBL_MIN);
143.1798 +
143.1799 +            /* The total output count (max) is now 4+precision */
143.1800 +
143.1801 +            /* Check for an exponent, if we don't need one we are
143.1802 +             * done and just need to terminate the string.  At
143.1803 +             * this point exp_b10==(-1) is effectively if flag - it got
143.1804 +             * to '-1' because of the decrement after outputing
143.1805 +             * the decimal point above (the exponent required is
143.1806 +             * *not* -1!)
143.1807 +             */
143.1808 +            if (exp_b10 >= (-1) && exp_b10 <= 2)
143.1809 +            {
143.1810 +               /* The following only happens if we didn't output the
143.1811 +                * leading zeros above for negative exponent, so this
143.1812 +                * doest add to the digit requirement.  Note that the
143.1813 +                * two zeros here can only be output if the two leading
143.1814 +                * zeros were *not* output, so this doesn't increase
143.1815 +                * the output count.
143.1816 +                */
143.1817 +               while (--exp_b10 >= 0) *ascii++ = 48;
143.1818 +
143.1819 +               *ascii = 0;
143.1820 +
143.1821 +               /* Total buffer requirement (including the '\0') is
143.1822 +                * 5+precision - see check at the start.
143.1823 +                */
143.1824 +               return;
143.1825 +            }
143.1826 +
143.1827 +            /* Here if an exponent is required, adjust size for
143.1828 +             * the digits we output but did not count.  The total
143.1829 +             * digit output here so far is at most 1+precision - no
143.1830 +             * decimal point and no leading or trailing zeros have
143.1831 +             * been output.
143.1832 +             */
143.1833 +            size -= cdigits;
143.1834 +
143.1835 +            *ascii++ = 69, --size;    /* 'E': PLUS 1 TOTAL 2+precision */
143.1836 +            if (exp_b10 < 0)
143.1837 +            {
143.1838 +               *ascii++ = 45, --size; /* '-': PLUS 1 TOTAL 3+precision */
143.1839 +               exp_b10 = -exp_b10;
143.1840 +            }
143.1841 +
143.1842 +            cdigits = 0;
143.1843 +
143.1844 +            while (exp_b10 > 0)
143.1845 +            {
143.1846 +               exponent[cdigits++] = (char)(48 + exp_b10 % 10);
143.1847 +               exp_b10 /= 10;
143.1848 +            }
143.1849 +
143.1850 +            /* Need another size check here for the exponent digits, so
143.1851 +             * this need not be considered above.
143.1852 +             */
143.1853 +            if ((int)size > cdigits)
143.1854 +            {
143.1855 +               while (cdigits > 0) *ascii++ = exponent[--cdigits];
143.1856 +
143.1857 +               *ascii = 0;
143.1858 +
143.1859 +               return;
143.1860 +            }
143.1861 +         }
143.1862 +      }
143.1863 +      else if (!(fp >= DBL_MIN))
143.1864 +      {
143.1865 +         *ascii++ = 48; /* '0' */
143.1866 +         *ascii = 0;
143.1867 +         return;
143.1868 +      }
143.1869 +      else
143.1870 +      {
143.1871 +         *ascii++ = 105; /* 'i' */
143.1872 +         *ascii++ = 110; /* 'n' */
143.1873 +         *ascii++ = 102; /* 'f' */
143.1874 +         *ascii = 0;
143.1875 +         return;
143.1876 +      }
143.1877 +   }
143.1878 +
143.1879 +   /* Here on buffer too small. */
143.1880 +   png_error(png_ptr, "ASCII conversion buffer too small");
143.1881 +}
143.1882 +
143.1883 +#  endif /* FLOATING_POINT */
143.1884 +
143.1885 +#  ifdef PNG_FIXED_POINT_SUPPORTED
143.1886 +/* Function to format a fixed point value in ASCII.
143.1887 + */
143.1888 +void /* PRIVATE */
143.1889 +png_ascii_from_fixed(png_structp png_ptr, png_charp ascii, png_size_t size,
143.1890 +    png_fixed_point fp)
143.1891 +{
143.1892 +   /* Require space for 10 decimal digits, a decimal point, a minus sign and a
143.1893 +    * trailing \0, 13 characters:
143.1894 +    */
143.1895 +   if (size > 12)
143.1896 +   {
143.1897 +      png_uint_32 num;
143.1898 +
143.1899 +      /* Avoid overflow here on the minimum integer. */
143.1900 +      if (fp < 0)
143.1901 +         *ascii++ = 45, --size, num = -fp;
143.1902 +      else
143.1903 +         num = fp;
143.1904 +
143.1905 +      if (num <= 0x80000000U) /* else overflowed */
143.1906 +      {
143.1907 +         unsigned int ndigits = 0, first = 16 /* flag value */;
143.1908 +         char digits[10];
143.1909 +
143.1910 +         while (num)
143.1911 +         {
143.1912 +            /* Split the low digit off num: */
143.1913 +            unsigned int tmp = num/10;
143.1914 +            num -= tmp*10;
143.1915 +            digits[ndigits++] = (char)(48 + num);
143.1916 +            /* Record the first non-zero digit, note that this is a number
143.1917 +             * starting at 1, it's not actually the array index.
143.1918 +             */
143.1919 +            if (first == 16 && num > 0)
143.1920 +               first = ndigits;
143.1921 +            num = tmp;
143.1922 +         }
143.1923 +
143.1924 +         if (ndigits > 0)
143.1925 +         {
143.1926 +            while (ndigits > 5) *ascii++ = digits[--ndigits];
143.1927 +            /* The remaining digits are fractional digits, ndigits is '5' or
143.1928 +             * smaller at this point.  It is certainly not zero.  Check for a
143.1929 +             * non-zero fractional digit:
143.1930 +             */
143.1931 +            if (first <= 5)
143.1932 +            {
143.1933 +               unsigned int i;
143.1934 +               *ascii++ = 46; /* decimal point */
143.1935 +               /* ndigits may be <5 for small numbers, output leading zeros
143.1936 +                * then ndigits digits to first:
143.1937 +                */
143.1938 +               i = 5;
143.1939 +               while (ndigits < i) *ascii++ = 48, --i;
143.1940 +               while (ndigits >= first) *ascii++ = digits[--ndigits];
143.1941 +               /* Don't output the trailing zeros! */
143.1942 +            }
143.1943 +         }
143.1944 +         else
143.1945 +            *ascii++ = 48;
143.1946 +
143.1947 +         /* And null terminate the string: */
143.1948 +         *ascii = 0;
143.1949 +         return;
143.1950 +      }
143.1951 +   }
143.1952 +
143.1953 +   /* Here on buffer too small. */
143.1954 +   png_error(png_ptr, "ASCII conversion buffer too small");
143.1955 +}
143.1956 +#   endif /* FIXED_POINT */
143.1957 +#endif /* READ_SCAL */
143.1958 +
143.1959 +#if defined(PNG_FLOATING_POINT_SUPPORTED) && \
143.1960 +   !defined(PNG_FIXED_POINT_MACRO_SUPPORTED)
143.1961 +png_fixed_point
143.1962 +png_fixed(png_structp png_ptr, double fp, png_const_charp text)
143.1963 +{
143.1964 +   double r = floor(100000 * fp + .5);
143.1965 +
143.1966 +   if (r > 2147483647. || r < -2147483648.)
143.1967 +      png_fixed_error(png_ptr, text);
143.1968 +
143.1969 +   return (png_fixed_point)r;
143.1970 +}
143.1971 +#endif
143.1972 +
143.1973 +#if defined(PNG_READ_GAMMA_SUPPORTED) || \
143.1974 +    defined(PNG_INCH_CONVERSIONS_SUPPORTED) || defined(PNG__READ_pHYs_SUPPORTED)
143.1975 +/* muldiv functions */
143.1976 +/* This API takes signed arguments and rounds the result to the nearest
143.1977 + * integer (or, for a fixed point number - the standard argument - to
143.1978 + * the nearest .00001).  Overflow and divide by zero are signalled in
143.1979 + * the result, a boolean - true on success, false on overflow.
143.1980 + */
143.1981 +int
143.1982 +png_muldiv(png_fixed_point_p res, png_fixed_point a, png_int_32 times,
143.1983 +    png_int_32 divisor)
143.1984 +{
143.1985 +   /* Return a * times / divisor, rounded. */
143.1986 +   if (divisor != 0)
143.1987 +   {
143.1988 +      if (a == 0 || times == 0)
143.1989 +      {
143.1990 +         *res = 0;
143.1991 +         return 1;
143.1992 +      }
143.1993 +      else
143.1994 +      {
143.1995 +#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
143.1996 +         double r = a;
143.1997 +         r *= times;
143.1998 +         r /= divisor;
143.1999 +         r = floor(r+.5);
143.2000 +
143.2001 +         /* A png_fixed_point is a 32-bit integer. */
143.2002 +         if (r <= 2147483647. && r >= -2147483648.)
143.2003 +         {
143.2004 +            *res = (png_fixed_point)r;
143.2005 +            return 1;
143.2006 +         }
143.2007 +#else
143.2008 +         int negative = 0;
143.2009 +         png_uint_32 A, T, D;
143.2010 +         png_uint_32 s16, s32, s00;
143.2011 +
143.2012 +         if (a < 0)
143.2013 +            negative = 1, A = -a;
143.2014 +         else
143.2015 +            A = a;
143.2016 +
143.2017 +         if (times < 0)
143.2018 +            negative = !negative, T = -times;
143.2019 +         else
143.2020 +            T = times;
143.2021 +
143.2022 +         if (divisor < 0)
143.2023 +            negative = !negative, D = -divisor;
143.2024 +         else
143.2025 +            D = divisor;
143.2026 +
143.2027 +         /* Following can't overflow because the arguments only
143.2028 +          * have 31 bits each, however the result may be 32 bits.
143.2029 +          */
143.2030 +         s16 = (A >> 16) * (T & 0xffff) +
143.2031 +                           (A & 0xffff) * (T >> 16);
143.2032 +         /* Can't overflow because the a*times bit is only 30
143.2033 +          * bits at most.
143.2034 +          */
143.2035 +         s32 = (A >> 16) * (T >> 16) + (s16 >> 16);
143.2036 +         s00 = (A & 0xffff) * (T & 0xffff);
143.2037 +
143.2038 +         s16 = (s16 & 0xffff) << 16;
143.2039 +         s00 += s16;
143.2040 +
143.2041 +         if (s00 < s16)
143.2042 +            ++s32; /* carry */
143.2043 +
143.2044 +         if (s32 < D) /* else overflow */
143.2045 +         {
143.2046 +            /* s32.s00 is now the 64-bit product, do a standard
143.2047 +             * division, we know that s32 < D, so the maximum
143.2048 +             * required shift is 31.
143.2049 +             */
143.2050 +            int bitshift = 32;
143.2051 +            png_fixed_point result = 0; /* NOTE: signed */
143.2052 +
143.2053 +            while (--bitshift >= 0)
143.2054 +            {
143.2055 +               png_uint_32 d32, d00;
143.2056 +
143.2057 +               if (bitshift > 0)
143.2058 +                  d32 = D >> (32-bitshift), d00 = D << bitshift;
143.2059 +
143.2060 +               else
143.2061 +                  d32 = 0, d00 = D;
143.2062 +
143.2063 +               if (s32 > d32)
143.2064 +               {
143.2065 +                  if (s00 < d00) --s32; /* carry */
143.2066 +                  s32 -= d32, s00 -= d00, result += 1<<bitshift;
143.2067 +               }
143.2068 +
143.2069 +               else
143.2070 +                  if (s32 == d32 && s00 >= d00)
143.2071 +                     s32 = 0, s00 -= d00, result += 1<<bitshift;
143.2072 +            }
143.2073 +
143.2074 +            /* Handle the rounding. */
143.2075 +            if (s00 >= (D >> 1))
143.2076 +               ++result;
143.2077 +
143.2078 +            if (negative)
143.2079 +               result = -result;
143.2080 +
143.2081 +            /* Check for overflow. */
143.2082 +            if ((negative && result <= 0) || (!negative && result >= 0))
143.2083 +            {
143.2084 +               *res = result;
143.2085 +               return 1;
143.2086 +            }
143.2087 +         }
143.2088 +#endif
143.2089 +      }
143.2090 +   }
143.2091 +
143.2092 +   return 0;
143.2093 +}
143.2094 +#endif /* READ_GAMMA || INCH_CONVERSIONS */
143.2095 +
143.2096 +#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_INCH_CONVERSIONS_SUPPORTED)
143.2097 +/* The following is for when the caller doesn't much care about the
143.2098 + * result.
143.2099 + */
143.2100 +png_fixed_point
143.2101 +png_muldiv_warn(png_structp png_ptr, png_fixed_point a, png_int_32 times,
143.2102 +    png_int_32 divisor)
143.2103 +{
143.2104 +   png_fixed_point result;
143.2105 +
143.2106 +   if (png_muldiv(&result, a, times, divisor))
143.2107 +      return result;
143.2108 +
143.2109 +   png_warning(png_ptr, "fixed point overflow ignored");
143.2110 +   return 0;
143.2111 +}
143.2112 +#endif
143.2113 +
143.2114 +#ifdef PNG_READ_GAMMA_SUPPORTED /* more fixed point functions for gammma */
143.2115 +/* Calculate a reciprocal, return 0 on div-by-zero or overflow. */
143.2116 +png_fixed_point
143.2117 +png_reciprocal(png_fixed_point a)
143.2118 +{
143.2119 +#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
143.2120 +   double r = floor(1E10/a+.5);
143.2121 +
143.2122 +   if (r <= 2147483647. && r >= -2147483648.)
143.2123 +      return (png_fixed_point)r;
143.2124 +#else
143.2125 +   png_fixed_point res;
143.2126 +
143.2127 +   if (png_muldiv(&res, 100000, 100000, a))
143.2128 +      return res;
143.2129 +#endif
143.2130 +
143.2131 +   return 0; /* error/overflow */
143.2132 +}
143.2133 +
143.2134 +/* A local convenience routine. */
143.2135 +static png_fixed_point
143.2136 +png_product2(png_fixed_point a, png_fixed_point b)
143.2137 +{
143.2138 +   /* The required result is 1/a * 1/b; the following preserves accuracy. */
143.2139 +#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
143.2140 +   double r = a * 1E-5;
143.2141 +   r *= b;
143.2142 +   r = floor(r+.5);
143.2143 +
143.2144 +   if (r <= 2147483647. && r >= -2147483648.)
143.2145 +      return (png_fixed_point)r;
143.2146 +#else
143.2147 +   png_fixed_point res;
143.2148 +
143.2149 +   if (png_muldiv(&res, a, b, 100000))
143.2150 +      return res;
143.2151 +#endif
143.2152 +
143.2153 +   return 0; /* overflow */
143.2154 +}
143.2155 +
143.2156 +/* The inverse of the above. */
143.2157 +png_fixed_point
143.2158 +png_reciprocal2(png_fixed_point a, png_fixed_point b)
143.2159 +{
143.2160 +   /* The required result is 1/a * 1/b; the following preserves accuracy. */
143.2161 +#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
143.2162 +   double r = 1E15/a;
143.2163 +   r /= b;
143.2164 +   r = floor(r+.5);
143.2165 +
143.2166 +   if (r <= 2147483647. && r >= -2147483648.)
143.2167 +      return (png_fixed_point)r;
143.2168 +#else
143.2169 +   /* This may overflow because the range of png_fixed_point isn't symmetric,
143.2170 +    * but this API is only used for the product of file and screen gamma so it
143.2171 +    * doesn't matter that the smallest number it can produce is 1/21474, not
143.2172 +    * 1/100000
143.2173 +    */
143.2174 +   png_fixed_point res = png_product2(a, b);
143.2175 +
143.2176 +   if (res != 0)
143.2177 +      return png_reciprocal(res);
143.2178 +#endif
143.2179 +
143.2180 +   return 0; /* overflow */
143.2181 +}
143.2182 +#endif /* READ_GAMMA */
143.2183 +
143.2184 +#ifdef PNG_CHECK_cHRM_SUPPORTED
143.2185 +/* Added at libpng version 1.2.34 (Dec 8, 2008) and 1.4.0 (Jan 2,
143.2186 + * 2010: moved from pngset.c) */
143.2187 +/*
143.2188 + *    Multiply two 32-bit numbers, V1 and V2, using 32-bit
143.2189 + *    arithmetic, to produce a 64-bit result in the HI/LO words.
143.2190 + *
143.2191 + *                  A B
143.2192 + *                x C D
143.2193 + *               ------
143.2194 + *              AD || BD
143.2195 + *        AC || CB || 0
143.2196 + *
143.2197 + *    where A and B are the high and low 16-bit words of V1,
143.2198 + *    C and D are the 16-bit words of V2, AD is the product of
143.2199 + *    A and D, and X || Y is (X << 16) + Y.
143.2200 +*/
143.2201 +
143.2202 +void /* PRIVATE */
143.2203 +png_64bit_product (long v1, long v2, unsigned long *hi_product,
143.2204 +    unsigned long *lo_product)
143.2205 +{
143.2206 +   int a, b, c, d;
143.2207 +   long lo, hi, x, y;
143.2208 +
143.2209 +   a = (v1 >> 16) & 0xffff;
143.2210 +   b = v1 & 0xffff;
143.2211 +   c = (v2 >> 16) & 0xffff;
143.2212 +   d = v2 & 0xffff;
143.2213 +
143.2214 +   lo = b * d;                   /* BD */
143.2215 +   x = a * d + c * b;            /* AD + CB */
143.2216 +   y = ((lo >> 16) & 0xffff) + x;
143.2217 +
143.2218 +   lo = (lo & 0xffff) | ((y & 0xffff) << 16);
143.2219 +   hi = (y >> 16) & 0xffff;
143.2220 +
143.2221 +   hi += a * c;                  /* AC */
143.2222 +
143.2223 +   *hi_product = (unsigned long)hi;
143.2224 +   *lo_product = (unsigned long)lo;
143.2225 +}
143.2226 +#endif /* CHECK_cHRM */
143.2227 +
143.2228 +#ifdef PNG_READ_GAMMA_SUPPORTED /* gamma table code */
143.2229 +#ifndef PNG_FLOATING_ARITHMETIC_SUPPORTED
143.2230 +/* Fixed point gamma.
143.2231 + *
143.2232 + * To calculate gamma this code implements fast log() and exp() calls using only
143.2233 + * fixed point arithmetic.  This code has sufficient precision for either 8-bit
143.2234 + * or 16-bit sample values.
143.2235 + *
143.2236 + * The tables used here were calculated using simple 'bc' programs, but C double
143.2237 + * precision floating point arithmetic would work fine.  The programs are given
143.2238 + * at the head of each table.
143.2239 + *
143.2240 + * 8-bit log table
143.2241 + *   This is a table of -log(value/255)/log(2) for 'value' in the range 128 to
143.2242 + *   255, so it's the base 2 logarithm of a normalized 8-bit floating point
143.2243 + *   mantissa.  The numbers are 32-bit fractions.
143.2244 + */
143.2245 +static png_uint_32
143.2246 +png_8bit_l2[128] =
143.2247 +{
143.2248 +#  if PNG_DO_BC
143.2249 +      for (i=128;i<256;++i) { .5 - l(i/255)/l(2)*65536*65536; }
143.2250 +#  endif
143.2251 +   4270715492U, 4222494797U, 4174646467U, 4127164793U, 4080044201U, 4033279239U,
143.2252 +   3986864580U, 3940795015U, 3895065449U, 3849670902U, 3804606499U, 3759867474U,
143.2253 +   3715449162U, 3671346997U, 3627556511U, 3584073329U, 3540893168U, 3498011834U,
143.2254 +   3455425220U, 3413129301U, 3371120137U, 3329393864U, 3287946700U, 3246774933U,
143.2255 +   3205874930U, 3165243125U, 3124876025U, 3084770202U, 3044922296U, 3005329011U,
143.2256 +   2965987113U, 2926893432U, 2888044853U, 2849438323U, 2811070844U, 2772939474U,
143.2257 +   2735041326U, 2697373562U, 2659933400U, 2622718104U, 2585724991U, 2548951424U,
143.2258 +   2512394810U, 2476052606U, 2439922311U, 2404001468U, 2368287663U, 2332778523U,
143.2259 +   2297471715U, 2262364947U, 2227455964U, 2192742551U, 2158222529U, 2123893754U,
143.2260 +   2089754119U, 2055801552U, 2022034013U, 1988449497U, 1955046031U, 1921821672U,
143.2261 +   1888774511U, 1855902668U, 1823204291U, 1790677560U, 1758320682U, 1726131893U,
143.2262 +   1694109454U, 1662251657U, 1630556815U, 1599023271U, 1567649391U, 1536433567U,
143.2263 +   1505374214U, 1474469770U, 1443718700U, 1413119487U, 1382670639U, 1352370686U,
143.2264 +   1322218179U, 1292211689U, 1262349810U, 1232631153U, 1203054352U, 1173618059U,
143.2265 +   1144320946U, 1115161701U, 1086139034U, 1057251672U, 1028498358U, 999877854U,
143.2266 +   971388940U, 943030410U, 914801076U, 886699767U, 858725327U, 830876614U,
143.2267 +   803152505U, 775551890U, 748073672U, 720716771U, 693480120U, 666362667U,
143.2268 +   639363374U, 612481215U, 585715177U, 559064263U, 532527486U, 506103872U,
143.2269 +   479792461U, 453592303U, 427502463U, 401522014U, 375650043U, 349885648U,
143.2270 +   324227938U, 298676034U, 273229066U, 247886176U, 222646516U, 197509248U,
143.2271 +   172473545U, 147538590U, 122703574U, 97967701U, 73330182U, 48790236U,
143.2272 +   24347096U, 0U
143.2273 +#if 0
143.2274 +   /* The following are the values for 16-bit tables - these work fine for the
143.2275 +    * 8-bit conversions but produce very slightly larger errors in the 16-bit
143.2276 +    * log (about 1.2 as opposed to 0.7 absolute error in the final value).  To
143.2277 +    * use these all the shifts below must be adjusted appropriately.
143.2278 +    */
143.2279 +   65166, 64430, 63700, 62976, 62257, 61543, 60835, 60132, 59434, 58741, 58054,
143.2280 +   57371, 56693, 56020, 55352, 54689, 54030, 53375, 52726, 52080, 51439, 50803,
143.2281 +   50170, 49542, 48918, 48298, 47682, 47070, 46462, 45858, 45257, 44661, 44068,
143.2282 +   43479, 42894, 42312, 41733, 41159, 40587, 40020, 39455, 38894, 38336, 37782,
143.2283 +   37230, 36682, 36137, 35595, 35057, 34521, 33988, 33459, 32932, 32408, 31887,
143.2284 +   31369, 30854, 30341, 29832, 29325, 28820, 28319, 27820, 27324, 26830, 26339,
143.2285 +   25850, 25364, 24880, 24399, 23920, 23444, 22970, 22499, 22029, 21562, 21098,
143.2286 +   20636, 20175, 19718, 19262, 18808, 18357, 17908, 17461, 17016, 16573, 16132,
143.2287 +   15694, 15257, 14822, 14390, 13959, 13530, 13103, 12678, 12255, 11834, 11415,
143.2288 +   10997, 10582, 10168, 9756, 9346, 8937, 8531, 8126, 7723, 7321, 6921, 6523,
143.2289 +   6127, 5732, 5339, 4947, 4557, 4169, 3782, 3397, 3014, 2632, 2251, 1872, 1495,
143.2290 +   1119, 744, 372
143.2291 +#endif
143.2292 +};
143.2293 +
143.2294 +PNG_STATIC png_int_32
143.2295 +png_log8bit(unsigned int x)
143.2296 +{
143.2297 +   unsigned int lg2 = 0;
143.2298 +   /* Each time 'x' is multiplied by 2, 1 must be subtracted off the final log,
143.2299 +    * because the log is actually negate that means adding 1.  The final
143.2300 +    * returned value thus has the range 0 (for 255 input) to 7.994 (for 1
143.2301 +    * input), return 7.99998 for the overflow (log 0) case - so the result is
143.2302 +    * always at most 19 bits.
143.2303 +    */
143.2304 +   if ((x &= 0xff) == 0)
143.2305 +      return 0xffffffff;
143.2306 +
143.2307 +   if ((x & 0xf0) == 0)
143.2308 +      lg2  = 4, x <<= 4;
143.2309 +
143.2310 +   if ((x & 0xc0) == 0)
143.2311 +      lg2 += 2, x <<= 2;
143.2312 +
143.2313 +   if ((x & 0x80) == 0)
143.2314 +      lg2 += 1, x <<= 1;
143.2315 +
143.2316 +   /* result is at most 19 bits, so this cast is safe: */
143.2317 +   return (png_int_32)((lg2 << 16) + ((png_8bit_l2[x-128]+32768)>>16));
143.2318 +}
143.2319 +
143.2320 +/* The above gives exact (to 16 binary places) log2 values for 8-bit images,
143.2321 + * for 16-bit images we use the most significant 8 bits of the 16-bit value to
143.2322 + * get an approximation then multiply the approximation by a correction factor
143.2323 + * determined by the remaining up to 8 bits.  This requires an additional step
143.2324 + * in the 16-bit case.
143.2325 + *
143.2326 + * We want log2(value/65535), we have log2(v'/255), where:
143.2327 + *
143.2328 + *    value = v' * 256 + v''
143.2329 + *          = v' * f
143.2330 + *
143.2331 + * So f is value/v', which is equal to (256+v''/v') since v' is in the range 128
143.2332 + * to 255 and v'' is in the range 0 to 255 f will be in the range 256 to less
143.2333 + * than 258.  The final factor also needs to correct for the fact that our 8-bit
143.2334 + * value is scaled by 255, whereas the 16-bit values must be scaled by 65535.
143.2335 + *
143.2336 + * This gives a final formula using a calculated value 'x' which is value/v' and
143.2337 + * scaling by 65536 to match the above table:
143.2338 + *
143.2339 + *   log2(x/257) * 65536
143.2340 + *
143.2341 + * Since these numbers are so close to '1' we can use simple linear
143.2342 + * interpolation between the two end values 256/257 (result -368.61) and 258/257
143.2343 + * (result 367.179).  The values used below are scaled by a further 64 to give
143.2344 + * 16-bit precision in the interpolation:
143.2345 + *
143.2346 + * Start (256): -23591
143.2347 + * Zero  (257):      0
143.2348 + * End   (258):  23499
143.2349 + */
143.2350 +PNG_STATIC png_int_32
143.2351 +png_log16bit(png_uint_32 x)
143.2352 +{
143.2353 +   unsigned int lg2 = 0;
143.2354 +
143.2355 +   /* As above, but now the input has 16 bits. */
143.2356 +   if ((x &= 0xffff) == 0)
143.2357 +      return 0xffffffff;
143.2358 +
143.2359 +   if ((x & 0xff00) == 0)
143.2360 +      lg2  = 8, x <<= 8;
143.2361 +
143.2362 +   if ((x & 0xf000) == 0)
143.2363 +      lg2 += 4, x <<= 4;
143.2364 +
143.2365 +   if ((x & 0xc000) == 0)
143.2366 +      lg2 += 2, x <<= 2;
143.2367 +
143.2368 +   if ((x & 0x8000) == 0)
143.2369 +      lg2 += 1, x <<= 1;
143.2370 +
143.2371 +   /* Calculate the base logarithm from the top 8 bits as a 28-bit fractional
143.2372 +    * value.
143.2373 +    */
143.2374 +   lg2 <<= 28;
143.2375 +   lg2 += (png_8bit_l2[(x>>8)-128]+8) >> 4;
143.2376 +
143.2377 +   /* Now we need to interpolate the factor, this requires a division by the top
143.2378 +    * 8 bits.  Do this with maximum precision.
143.2379 +    */
143.2380 +   x = ((x << 16) + (x >> 9)) / (x >> 8);
143.2381 +
143.2382 +   /* Since we divided by the top 8 bits of 'x' there will be a '1' at 1<<24,
143.2383 +    * the value at 1<<16 (ignoring this) will be 0 or 1; this gives us exactly
143.2384 +    * 16 bits to interpolate to get the low bits of the result.  Round the
143.2385 +    * answer.  Note that the end point values are scaled by 64 to retain overall
143.2386 +    * precision and that 'lg2' is current scaled by an extra 12 bits, so adjust
143.2387 +    * the overall scaling by 6-12.  Round at every step.
143.2388 +    */
143.2389 +   x -= 1U << 24;
143.2390 +
143.2391 +   if (x <= 65536U) /* <= '257' */
143.2392 +      lg2 += ((23591U * (65536U-x)) + (1U << (16+6-12-1))) >> (16+6-12);
143.2393 +
143.2394 +   else
143.2395 +      lg2 -= ((23499U * (x-65536U)) + (1U << (16+6-12-1))) >> (16+6-12);
143.2396 +
143.2397 +   /* Safe, because the result can't have more than 20 bits: */
143.2398 +   return (png_int_32)((lg2 + 2048) >> 12);
143.2399 +}
143.2400 +
143.2401 +/* The 'exp()' case must invert the above, taking a 20-bit fixed point
143.2402 + * logarithmic value and returning a 16 or 8-bit number as appropriate.  In
143.2403 + * each case only the low 16 bits are relevant - the fraction - since the
143.2404 + * integer bits (the top 4) simply determine a shift.
143.2405 + *
143.2406 + * The worst case is the 16-bit distinction between 65535 and 65534, this
143.2407 + * requires perhaps spurious accuracty in the decoding of the logarithm to
143.2408 + * distinguish log2(65535/65534.5) - 10^-5 or 17 bits.  There is little chance
143.2409 + * of getting this accuracy in practice.
143.2410 + *
143.2411 + * To deal with this the following exp() function works out the exponent of the
143.2412 + * frational part of the logarithm by using an accurate 32-bit value from the
143.2413 + * top four fractional bits then multiplying in the remaining bits.
143.2414 + */
143.2415 +static png_uint_32
143.2416 +png_32bit_exp[16] =
143.2417 +{
143.2418 +#  if PNG_DO_BC
143.2419 +      for (i=0;i<16;++i) { .5 + e(-i/16*l(2))*2^32; }
143.2420 +#  endif
143.2421 +   /* NOTE: the first entry is deliberately set to the maximum 32-bit value. */
143.2422 +   4294967295U, 4112874773U, 3938502376U, 3771522796U, 3611622603U, 3458501653U,
143.2423 +   3311872529U, 3171459999U, 3037000500U, 2908241642U, 2784941738U, 2666869345U,
143.2424 +   2553802834U, 2445529972U, 2341847524U, 2242560872U
143.2425 +};
143.2426 +
143.2427 +/* Adjustment table; provided to explain the numbers in the code below. */
143.2428 +#if PNG_DO_BC
143.2429 +for (i=11;i>=0;--i){ print i, " ", (1 - e(-(2^i)/65536*l(2))) * 2^(32-i), "\n"}
143.2430 +   11 44937.64284865548751208448
143.2431 +   10 45180.98734845585101160448
143.2432 +    9 45303.31936980687359311872
143.2433 +    8 45364.65110595323018870784
143.2434 +    7 45395.35850361789624614912
143.2435 +    6 45410.72259715102037508096
143.2436 +    5 45418.40724413220722311168
143.2437 +    4 45422.25021786898173001728
143.2438 +    3 45424.17186732298419044352
143.2439 +    2 45425.13273269940811464704
143.2440 +    1 45425.61317555035558641664
143.2441 +    0 45425.85339951654943850496
143.2442 +#endif
143.2443 +
143.2444 +PNG_STATIC png_uint_32
143.2445 +png_exp(png_fixed_point x)
143.2446 +{
143.2447 +   if (x > 0 && x <= 0xfffff) /* Else overflow or zero (underflow) */
143.2448 +   {
143.2449 +      /* Obtain a 4-bit approximation */
143.2450 +      png_uint_32 e = png_32bit_exp[(x >> 12) & 0xf];
143.2451 +
143.2452 +      /* Incorporate the low 12 bits - these decrease the returned value by
143.2453 +       * multiplying by a number less than 1 if the bit is set.  The multiplier
143.2454 +       * is determined by the above table and the shift. Notice that the values
143.2455 +       * converge on 45426 and this is used to allow linear interpolation of the
143.2456 +       * low bits.
143.2457 +       */
143.2458 +      if (x & 0x800)
143.2459 +         e -= (((e >> 16) * 44938U) +  16U) >> 5;
143.2460 +
143.2461 +      if (x & 0x400)
143.2462 +         e -= (((e >> 16) * 45181U) +  32U) >> 6;
143.2463 +
143.2464 +      if (x & 0x200)
143.2465 +         e -= (((e >> 16) * 45303U) +  64U) >> 7;
143.2466 +
143.2467 +      if (x & 0x100)
143.2468 +         e -= (((e >> 16) * 45365U) + 128U) >> 8;
143.2469 +
143.2470 +      if (x & 0x080)
143.2471 +         e -= (((e >> 16) * 45395U) + 256U) >> 9;
143.2472 +
143.2473 +      if (x & 0x040)
143.2474 +         e -= (((e >> 16) * 45410U) + 512U) >> 10;
143.2475 +
143.2476 +      /* And handle the low 6 bits in a single block. */
143.2477 +      e -= (((e >> 16) * 355U * (x & 0x3fU)) + 256U) >> 9;
143.2478 +
143.2479 +      /* Handle the upper bits of x. */
143.2480 +      e >>= x >> 16;
143.2481 +      return e;
143.2482 +   }
143.2483 +
143.2484 +   /* Check for overflow */
143.2485 +   if (x <= 0)
143.2486 +      return png_32bit_exp[0];
143.2487 +
143.2488 +   /* Else underflow */
143.2489 +   return 0;
143.2490 +}
143.2491 +
143.2492 +PNG_STATIC png_byte
143.2493 +png_exp8bit(png_fixed_point lg2)
143.2494 +{
143.2495 +   /* Get a 32-bit value: */
143.2496 +   png_uint_32 x = png_exp(lg2);
143.2497 +
143.2498 +   /* Convert the 32-bit value to 0..255 by multiplying by 256-1, note that the
143.2499 +    * second, rounding, step can't overflow because of the first, subtraction,
143.2500 +    * step.
143.2501 +    */
143.2502 +   x -= x >> 8;
143.2503 +   return (png_byte)((x + 0x7fffffU) >> 24);
143.2504 +}
143.2505 +
143.2506 +PNG_STATIC png_uint_16
143.2507 +png_exp16bit(png_fixed_point lg2)
143.2508 +{
143.2509 +   /* Get a 32-bit value: */
143.2510 +   png_uint_32 x = png_exp(lg2);
143.2511 +
143.2512 +   /* Convert the 32-bit value to 0..65535 by multiplying by 65536-1: */
143.2513 +   x -= x >> 16;
143.2514 +   return (png_uint_16)((x + 32767U) >> 16);
143.2515 +}
143.2516 +#endif /* FLOATING_ARITHMETIC */
143.2517 +
143.2518 +png_byte
143.2519 +png_gamma_8bit_correct(unsigned int value, png_fixed_point gamma_val)
143.2520 +{
143.2521 +   if (value > 0 && value < 255)
143.2522 +   {
143.2523 +#     ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
143.2524 +         double r = floor(255*pow(value/255.,gamma_val*.00001)+.5);
143.2525 +         return (png_byte)r;
143.2526 +#     else
143.2527 +         png_int_32 lg2 = png_log8bit(value);
143.2528 +         png_fixed_point res;
143.2529 +
143.2530 +         if (png_muldiv(&res, gamma_val, lg2, PNG_FP_1))
143.2531 +            return png_exp8bit(res);
143.2532 +
143.2533 +         /* Overflow. */
143.2534 +         value = 0;
143.2535 +#     endif
143.2536 +   }
143.2537 +
143.2538 +   return (png_byte)value;
143.2539 +}
143.2540 +
143.2541 +png_uint_16
143.2542 +png_gamma_16bit_correct(unsigned int value, png_fixed_point gamma_val)
143.2543 +{
143.2544 +   if (value > 0 && value < 65535)
143.2545 +   {
143.2546 +#     ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
143.2547 +         double r = floor(65535*pow(value/65535.,gamma_val*.00001)+.5);
143.2548 +         return (png_uint_16)r;
143.2549 +#     else
143.2550 +         png_int_32 lg2 = png_log16bit(value);
143.2551 +         png_fixed_point res;
143.2552 +
143.2553 +         if (png_muldiv(&res, gamma_val, lg2, PNG_FP_1))
143.2554 +            return png_exp16bit(res);
143.2555 +
143.2556 +         /* Overflow. */
143.2557 +         value = 0;
143.2558 +#     endif
143.2559 +   }
143.2560 +
143.2561 +   return (png_uint_16)value;
143.2562 +}
143.2563 +
143.2564 +/* This does the right thing based on the bit_depth field of the
143.2565 + * png_struct, interpreting values as 8-bit or 16-bit.  While the result
143.2566 + * is nominally a 16-bit value if bit depth is 8 then the result is
143.2567 + * 8-bit (as are the arguments.)
143.2568 + */
143.2569 +png_uint_16 /* PRIVATE */
143.2570 +png_gamma_correct(png_structp png_ptr, unsigned int value,
143.2571 +    png_fixed_point gamma_val)
143.2572 +{
143.2573 +   if (png_ptr->bit_depth == 8)
143.2574 +      return png_gamma_8bit_correct(value, gamma_val);
143.2575 +
143.2576 +   else
143.2577 +      return png_gamma_16bit_correct(value, gamma_val);
143.2578 +}
143.2579 +
143.2580 +/* This is the shared test on whether a gamma value is 'significant' - whether
143.2581 + * it is worth doing gamma correction.
143.2582 + */
143.2583 +int /* PRIVATE */
143.2584 +png_gamma_significant(png_fixed_point gamma_val)
143.2585 +{
143.2586 +   return gamma_val < PNG_FP_1 - PNG_GAMMA_THRESHOLD_FIXED ||
143.2587 +       gamma_val > PNG_FP_1 + PNG_GAMMA_THRESHOLD_FIXED;
143.2588 +}
143.2589 +
143.2590 +/* Internal function to build a single 16-bit table - the table consists of
143.2591 + * 'num' 256 entry subtables, where 'num' is determined by 'shift' - the amount
143.2592 + * to shift the input values right (or 16-number_of_signifiant_bits).
143.2593 + *
143.2594 + * The caller is responsible for ensuring that the table gets cleaned up on
143.2595 + * png_error (i.e. if one of the mallocs below fails) - i.e. the *table argument
143.2596 + * should be somewhere that will be cleaned.
143.2597 + */
143.2598 +static void
143.2599 +png_build_16bit_table(png_structp png_ptr, png_uint_16pp *ptable,
143.2600 +   PNG_CONST unsigned int shift, PNG_CONST png_fixed_point gamma_val)
143.2601 +{
143.2602 +   /* Various values derived from 'shift': */
143.2603 +   PNG_CONST unsigned int num = 1U << (8U - shift);
143.2604 +   PNG_CONST unsigned int max = (1U << (16U - shift))-1U;
143.2605 +   PNG_CONST unsigned int max_by_2 = 1U << (15U-shift);
143.2606 +   unsigned int i;
143.2607 +
143.2608 +   png_uint_16pp table = *ptable =
143.2609 +       (png_uint_16pp)png_calloc(png_ptr, num * png_sizeof(png_uint_16p));
143.2610 +
143.2611 +   for (i = 0; i < num; i++)
143.2612 +   {
143.2613 +      png_uint_16p sub_table = table[i] =
143.2614 +          (png_uint_16p)png_malloc(png_ptr, 256 * png_sizeof(png_uint_16));
143.2615 +
143.2616 +      /* The 'threshold' test is repeated here because it can arise for one of
143.2617 +       * the 16-bit tables even if the others don't hit it.
143.2618 +       */
143.2619 +      if (png_gamma_significant(gamma_val))
143.2620 +      {
143.2621 +         /* The old code would overflow at the end and this would cause the
143.2622 +          * 'pow' function to return a result >1, resulting in an
143.2623 +          * arithmetic error.  This code follows the spec exactly; ig is
143.2624 +          * the recovered input sample, it always has 8-16 bits.
143.2625 +          *
143.2626 +          * We want input * 65535/max, rounded, the arithmetic fits in 32
143.2627 +          * bits (unsigned) so long as max <= 32767.
143.2628 +          */
143.2629 +         unsigned int j;
143.2630 +         for (j = 0; j < 256; j++)
143.2631 +         {
143.2632 +            png_uint_32 ig = (j << (8-shift)) + i;
143.2633 +#           ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
143.2634 +               /* Inline the 'max' scaling operation: */
143.2635 +               double d = floor(65535*pow(ig/(double)max, gamma_val*.00001)+.5);
143.2636 +               sub_table[j] = (png_uint_16)d;
143.2637 +#           else
143.2638 +               if (shift)
143.2639 +                  ig = (ig * 65535U + max_by_2)/max;
143.2640 +
143.2641 +               sub_table[j] = png_gamma_16bit_correct(ig, gamma_val);
143.2642 +#           endif
143.2643 +         }
143.2644 +      }
143.2645 +      else
143.2646 +      {
143.2647 +         /* We must still build a table, but do it the fast way. */
143.2648 +         unsigned int j;
143.2649 +
143.2650 +         for (j = 0; j < 256; j++)
143.2651 +         {
143.2652 +            png_uint_32 ig = (j << (8-shift)) + i;
143.2653 +
143.2654 +            if (shift)
143.2655 +               ig = (ig * 65535U + max_by_2)/max;
143.2656 +
143.2657 +            sub_table[j] = (png_uint_16)ig;
143.2658 +         }
143.2659 +      }
143.2660 +   }
143.2661 +}
143.2662 +
143.2663 +/* NOTE: this function expects the *inverse* of the overall gamma transformation
143.2664 + * required.
143.2665 + */
143.2666 +static void
143.2667 +png_build_16to8_table(png_structp png_ptr, png_uint_16pp *ptable,
143.2668 +   PNG_CONST unsigned int shift, PNG_CONST png_fixed_point gamma_val)
143.2669 +{
143.2670 +   PNG_CONST unsigned int num = 1U << (8U - shift);
143.2671 +   PNG_CONST unsigned int max = (1U << (16U - shift))-1U;
143.2672 +   unsigned int i;
143.2673 +   png_uint_32 last;
143.2674 +
143.2675 +   png_uint_16pp table = *ptable =
143.2676 +       (png_uint_16pp)png_calloc(png_ptr, num * png_sizeof(png_uint_16p));
143.2677 +
143.2678 +   /* 'num' is the number of tables and also the number of low bits of low
143.2679 +    * bits of the input 16-bit value used to select a table.  Each table is
143.2680 +    * itself index by the high 8 bits of the value.
143.2681 +    */
143.2682 +   for (i = 0; i < num; i++)
143.2683 +      table[i] = (png_uint_16p)png_malloc(png_ptr,
143.2684 +          256 * png_sizeof(png_uint_16));
143.2685 +
143.2686 +   /* 'gamma_val' is set to the reciprocal of the value calculated above, so
143.2687 +    * pow(out,g) is an *input* value.  'last' is the last input value set.
143.2688 +    *
143.2689 +    * In the loop 'i' is used to find output values.  Since the output is
143.2690 +    * 8-bit there are only 256 possible values.  The tables are set up to
143.2691 +    * select the closest possible output value for each input by finding
143.2692 +    * the input value at the boundary between each pair of output values
143.2693 +    * and filling the table up to that boundary with the lower output
143.2694 +    * value.
143.2695 +    *
143.2696 +    * The boundary values are 0.5,1.5..253.5,254.5.  Since these are 9-bit
143.2697 +    * values the code below uses a 16-bit value in i; the values start at
143.2698 +    * 128.5 (for 0.5) and step by 257, for a total of 254 values (the last
143.2699 +    * entries are filled with 255).  Start i at 128 and fill all 'last'
143.2700 +    * table entries <= 'max'
143.2701 +    */
143.2702 +   last = 0;
143.2703 +   for (i = 0; i < 255; ++i) /* 8-bit output value */
143.2704 +   {
143.2705 +      /* Find the corresponding maximum input value */
143.2706 +      png_uint_16 out = (png_uint_16)(i * 257U); /* 16-bit output value */
143.2707 +
143.2708 +      /* Find the boundary value in 16 bits: */
143.2709 +      png_uint_32 bound = png_gamma_16bit_correct(out+128U, gamma_val);
143.2710 +
143.2711 +      /* Adjust (round) to (16-shift) bits: */
143.2712 +      bound = (bound * max + 32768U)/65535U + 1U;
143.2713 +
143.2714 +      while (last < bound)
143.2715 +      {
143.2716 +         table[last & (0xffU >> shift)][last >> (8U - shift)] = out;
143.2717 +         last++;
143.2718 +      }
143.2719 +   }
143.2720 +
143.2721 +   /* And fill in the final entries. */
143.2722 +   while (last < (num << 8))
143.2723 +   {
143.2724 +      table[last & (0xff >> shift)][last >> (8U - shift)] = 65535U;
143.2725 +      last++;
143.2726 +   }
143.2727 +}
143.2728 +
143.2729 +/* Build a single 8-bit table: same as the 16-bit case but much simpler (and
143.2730 + * typically much faster).  Note that libpng currently does no sBIT processing
143.2731 + * (apparently contrary to the spec) so a 256 entry table is always generated.
143.2732 + */
143.2733 +static void
143.2734 +png_build_8bit_table(png_structp png_ptr, png_bytepp ptable,
143.2735 +   PNG_CONST png_fixed_point gamma_val)
143.2736 +{
143.2737 +   unsigned int i;
143.2738 +   png_bytep table = *ptable = (png_bytep)png_malloc(png_ptr, 256);
143.2739 +
143.2740 +   if (png_gamma_significant(gamma_val)) for (i=0; i<256; i++)
143.2741 +      table[i] = png_gamma_8bit_correct(i, gamma_val);
143.2742 +
143.2743 +   else for (i=0; i<256; ++i)
143.2744 +      table[i] = (png_byte)i;
143.2745 +}
143.2746 +
143.2747 +/* We build the 8- or 16-bit gamma tables here.  Note that for 16-bit
143.2748 + * tables, we don't make a full table if we are reducing to 8-bit in
143.2749 + * the future.  Note also how the gamma_16 tables are segmented so that
143.2750 + * we don't need to allocate > 64K chunks for a full 16-bit table.
143.2751 + */
143.2752 +void /* PRIVATE */
143.2753 +png_build_gamma_table(png_structp png_ptr, int bit_depth)
143.2754 +{
143.2755 +  png_debug(1, "in png_build_gamma_table");
143.2756 +
143.2757 +  if (bit_depth <= 8)
143.2758 +  {
143.2759 +     png_build_8bit_table(png_ptr, &png_ptr->gamma_table,
143.2760 +         png_ptr->screen_gamma > 0 ?  png_reciprocal2(png_ptr->gamma,
143.2761 +         png_ptr->screen_gamma) : PNG_FP_1);
143.2762 +
143.2763 +#if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
143.2764 +   defined(PNG_READ_ALPHA_MODE_SUPPORTED) || \
143.2765 +   defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
143.2766 +     if (png_ptr->transformations & (PNG_COMPOSE | PNG_RGB_TO_GRAY))
143.2767 +     {
143.2768 +        png_build_8bit_table(png_ptr, &png_ptr->gamma_to_1,
143.2769 +            png_reciprocal(png_ptr->gamma));
143.2770 +
143.2771 +        png_build_8bit_table(png_ptr, &png_ptr->gamma_from_1,
143.2772 +            png_ptr->screen_gamma > 0 ?  png_reciprocal(png_ptr->screen_gamma) :
143.2773 +            png_ptr->gamma/* Probably doing rgb_to_gray */);
143.2774 +     }
143.2775 +#endif /* READ_BACKGROUND || READ_ALPHA_MODE || RGB_TO_GRAY */
143.2776 +  }
143.2777 +  else
143.2778 +  {
143.2779 +     png_byte shift, sig_bit;
143.2780 +
143.2781 +     if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
143.2782 +     {
143.2783 +        sig_bit = png_ptr->sig_bit.red;
143.2784 +
143.2785 +        if (png_ptr->sig_bit.green > sig_bit)
143.2786 +           sig_bit = png_ptr->sig_bit.green;
143.2787 +
143.2788 +        if (png_ptr->sig_bit.blue > sig_bit)
143.2789 +           sig_bit = png_ptr->sig_bit.blue;
143.2790 +     }
143.2791 +     else
143.2792 +        sig_bit = png_ptr->sig_bit.gray;
143.2793 +
143.2794 +     /* 16-bit gamma code uses this equation:
143.2795 +      *
143.2796 +      *   ov = table[(iv & 0xff) >> gamma_shift][iv >> 8]
143.2797 +      *
143.2798 +      * Where 'iv' is the input color value and 'ov' is the output value -
143.2799 +      * pow(iv, gamma).
143.2800 +      *
143.2801 +      * Thus the gamma table consists of up to 256 256 entry tables.  The table
143.2802 +      * is selected by the (8-gamma_shift) most significant of the low 8 bits of
143.2803 +      * the color value then indexed by the upper 8 bits:
143.2804 +      *
143.2805 +      *   table[low bits][high 8 bits]
143.2806 +      *
143.2807 +      * So the table 'n' corresponds to all those 'iv' of:
143.2808 +      *
143.2809 +      *   <all high 8-bit values><n << gamma_shift>..<(n+1 << gamma_shift)-1>
143.2810 +      *
143.2811 +      */
143.2812 +     if (sig_bit > 0 && sig_bit < 16U)
143.2813 +        shift = (png_byte)(16U - sig_bit); /* shift == insignificant bits */
143.2814 +
143.2815 +     else
143.2816 +        shift = 0; /* keep all 16 bits */
143.2817 +
143.2818 +     if (png_ptr->transformations & (PNG_16_TO_8 | PNG_SCALE_16_TO_8))
143.2819 +     {
143.2820 +        /* PNG_MAX_GAMMA_8 is the number of bits to keep - effectively
143.2821 +         * the significant bits in the *input* when the output will
143.2822 +         * eventually be 8 bits.  By default it is 11.
143.2823 +         */
143.2824 +        if (shift < (16U - PNG_MAX_GAMMA_8))
143.2825 +           shift = (16U - PNG_MAX_GAMMA_8);
143.2826 +     }
143.2827 +
143.2828 +     if (shift > 8U)
143.2829 +        shift = 8U; /* Guarantees at least one table! */
143.2830 +
143.2831 +     png_ptr->gamma_shift = shift;
143.2832 +
143.2833 +#ifdef PNG_16BIT_SUPPORTED
143.2834 +     /* NOTE: prior to 1.5.4 this test used to include PNG_BACKGROUND (now
143.2835 +      * PNG_COMPOSE).  This effectively smashed the background calculation for
143.2836 +      * 16-bit output because the 8-bit table assumes the result will be reduced
143.2837 +      * to 8 bits.
143.2838 +      */
143.2839 +     if (png_ptr->transformations & (PNG_16_TO_8 | PNG_SCALE_16_TO_8))
143.2840 +#endif
143.2841 +         png_build_16to8_table(png_ptr, &png_ptr->gamma_16_table, shift,
143.2842 +         png_ptr->screen_gamma > 0 ? png_product2(png_ptr->gamma,
143.2843 +         png_ptr->screen_gamma) : PNG_FP_1);
143.2844 +
143.2845 +#ifdef PNG_16BIT_SUPPORTED
143.2846 +     else
143.2847 +         png_build_16bit_table(png_ptr, &png_ptr->gamma_16_table, shift,
143.2848 +         png_ptr->screen_gamma > 0 ? png_reciprocal2(png_ptr->gamma,
143.2849 +         png_ptr->screen_gamma) : PNG_FP_1);
143.2850 +#endif
143.2851 +
143.2852 +#if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
143.2853 +   defined(PNG_READ_ALPHA_MODE_SUPPORTED) || \
143.2854 +   defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
143.2855 +     if (png_ptr->transformations & (PNG_COMPOSE | PNG_RGB_TO_GRAY))
143.2856 +     {
143.2857 +        png_build_16bit_table(png_ptr, &png_ptr->gamma_16_to_1, shift,
143.2858 +            png_reciprocal(png_ptr->gamma));
143.2859 +
143.2860 +        /* Notice that the '16 from 1' table should be full precision, however
143.2861 +         * the lookup on this table still uses gamma_shift, so it can't be.
143.2862 +         * TODO: fix this.
143.2863 +         */
143.2864 +        png_build_16bit_table(png_ptr, &png_ptr->gamma_16_from_1, shift,
143.2865 +            png_ptr->screen_gamma > 0 ? png_reciprocal(png_ptr->screen_gamma) :
143.2866 +            png_ptr->gamma/* Probably doing rgb_to_gray */);
143.2867 +     }
143.2868 +#endif /* READ_BACKGROUND || READ_ALPHA_MODE || RGB_TO_GRAY */
143.2869 +  }
143.2870 +}
143.2871 +#endif /* READ_GAMMA */
143.2872  #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
   144.1 --- a/src/share/native/sun/awt/libpng/png.h	Fri Sep 30 17:20:56 2011 -0700
   144.2 +++ b/src/share/native/sun/awt/libpng/png.h	Tue Oct 04 12:39:42 2011 -0700
   144.3 @@ -29,24 +29,26 @@
   144.4   * However, the following notice accompanied the original version of this
   144.5   * file and, per its terms, should not be removed:
   144.6   *
   144.7 - * libpng version 1.2.18 - May 15, 2007
   144.8 - * Copyright (c) 1998-2007 Glenn Randers-Pehrson
   144.9 + * libpng version 1.5.4 - July 7, 2011
  144.10 + * Copyright (c) 1998-2011 Glenn Randers-Pehrson
  144.11   * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
  144.12   * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
  144.13   *
  144.14 + * This code is released under the libpng license (See LICENSE, below)
  144.15 + *
  144.16   * Authors and maintainers:
  144.17 - *  libpng versions 0.71, May 1995, through 0.88, January 1996: Guy Schalnat
  144.18 - *  libpng versions 0.89c, June 1996, through 0.96, May 1997: Andreas Dilger
  144.19 - *  libpng versions 0.97, January 1998, through 1.2.18 - May 15, 2007: Glenn
  144.20 - *  See also "Contributing Authors", below.
  144.21 + *   libpng versions 0.71, May 1995, through 0.88, January 1996: Guy Schalnat
  144.22 + *   libpng versions 0.89c, June 1996, through 0.96, May 1997: Andreas Dilger
  144.23 + *   libpng versions 0.97, January 1998, through 1.5.4 - July 7, 2011: Glenn
  144.24 + *   See also "Contributing Authors", below.
  144.25   *
  144.26   * Note about libpng version numbers:
  144.27   *
  144.28 - *    Due to various miscommunications, unforeseen code incompatibilities
  144.29 - *    and occasional factors outside the authors' control, version numbering
  144.30 - *    on the library has not always been consistent and straightforward.
  144.31 - *    The following table summarizes matters since version 0.89c, which was
  144.32 - *    the first widely used release:
  144.33 + *   Due to various miscommunications, unforeseen code incompatibilities
  144.34 + *   and occasional factors outside the authors' control, version numbering
  144.35 + *   on the library has not always been consistent and straightforward.
  144.36 + *   The following table summarizes matters since version 0.89c, which was
  144.37 + *   the first widely used release:
  144.38   *
  144.39   *    source                 png.h  png.h  shared-lib
  144.40   *    version                string   int  version
  144.41 @@ -131,74 +133,79 @@
  144.42   *    1.0.16                  10    10016  10.so.0.1.0.16
  144.43   *    1.2.6                   13    10206  12.so.0.1.2.6
  144.44   *    1.2.7beta1-2            13    10207  12.so.0.1.2.7beta1-2
  144.45 - *    1.0.17rc1               10    10017  10.so.0.1.0.17rc1
  144.46 + *    1.0.17rc1               10    10017  12.so.0.1.0.17rc1
  144.47   *    1.2.7rc1                13    10207  12.so.0.1.2.7rc1
  144.48 - *    1.0.17                  10    10017  10.so.0.1.0.17
  144.49 + *    1.0.17                  10    10017  12.so.0.1.0.17
  144.50   *    1.2.7                   13    10207  12.so.0.1.2.7
  144.51   *    1.2.8beta1-5            13    10208  12.so.0.1.2.8beta1-5
  144.52 - *    1.0.18rc1-5             10    10018  10.so.0.1.0.18rc1-5
  144.53 + *    1.0.18rc1-5             10    10018  12.so.0.1.0.18rc1-5
  144.54   *    1.2.8rc1-5              13    10208  12.so.0.1.2.8rc1-5
  144.55 - *    1.0.18                  10    10018  10.so.0.1.0.18
  144.56 + *    1.0.18                  10    10018  12.so.0.1.0.18
  144.57   *    1.2.8                   13    10208  12.so.0.1.2.8
  144.58   *    1.2.9beta1-3            13    10209  12.so.0.1.2.9beta1-3
  144.59   *    1.2.9beta4-11           13    10209  12.so.0.9[.0]
  144.60   *    1.2.9rc1                13    10209  12.so.0.9[.0]
  144.61   *    1.2.9                   13    10209  12.so.0.9[.0]
  144.62 - *    1.2.10beta1-8           13    10210  12.so.0.10[.0]
  144.63 - *    1.2.10rc1-3             13    10210  12.so.0.10[.0]
  144.64 + *    1.2.10beta1-7           13    10210  12.so.0.10[.0]
  144.65 + *    1.2.10rc1-2             13    10210  12.so.0.10[.0]
  144.66   *    1.2.10                  13    10210  12.so.0.10[.0]
  144.67 + *    1.4.0beta1-5            14    10400  14.so.0.0[.0]
  144.68   *    1.2.11beta1-4           13    10211  12.so.0.11[.0]
  144.69 - *    1.0.19rc1-5             10    10019  10.so.0.19[.0]
  144.70 - *    1.2.11rc1-5             13    10211  12.so.0.11[.0]
  144.71 - *    1.0.19                  10    10019  10.so.0.19[.0]
  144.72 + *    1.4.0beta7-8            14    10400  14.so.0.0[.0]
  144.73   *    1.2.11                  13    10211  12.so.0.11[.0]
  144.74 - *    1.0.20                  10    10020  10.so.0.20[.0]
  144.75   *    1.2.12                  13    10212  12.so.0.12[.0]
  144.76 - *    1.2.13beta1             13    10213  12.so.0.13[.0]
  144.77 - *    1.0.21                  10    10021  10.so.0.21[.0]
  144.78 + *    1.4.0beta9-14           14    10400  14.so.0.0[.0]
  144.79   *    1.2.13                  13    10213  12.so.0.13[.0]
  144.80 - *    1.2.14beta1-2           13    10214  12.so.0.14[.0]
  144.81 - *    1.0.22rc1               10    10022  10.so.0.22[.0]
  144.82 - *    1.2.14rc1               13    10214  12.so.0.14[.0]
  144.83 - *    1.0.22                  10    10022  10.so.0.22[.0]
  144.84 - *    1.2.14                  13    10214  12.so.0.14[.0]
  144.85 - *    1.2.15beta1-6           13    10215  12.so.0.15[.0]
  144.86 - *    1.0.23rc1-5             10    10023  10.so.0.23[.0]
  144.87 - *    1.2.15rc1-5             13    10215  12.so.0.15[.0]
  144.88 - *    1.0.23                  10    10023  10.so.0.23[.0]
  144.89 - *    1.2.15                  13    10215  12.so.0.15[.0]
  144.90 - *    1.2.16beta1-2           13    10216  12.so.0.16[.0]
  144.91 - *    1.2.16rc1               13    10216  12.so.0.16[.0]
  144.92 - *    1.0.24                  10    10024  10.so.0.24[.0]
  144.93 - *    1.2.16                  13    10216  12.so.0.16[.0]
  144.94 - *    1.2.17beta1-2           13    10217  12.so.0.17[.0]
  144.95 - *    1.0.25rc1               10    10025  10.so.0.25[.0]
  144.96 - *    1.2.17rc1-3             13    10217  12.so.0.17[.0]
  144.97 - *    1.0.25                  10    10025  10.so.0.25[.0]
  144.98 - *    1.2.17                  13    10217  12.so.0.17[.0]
  144.99 - *    1.0.26                  10    10026  10.so.0.26[.0]
 144.100 - *    1.2.18                  13    10218  12.so.0.18[.0]
 144.101 + *    1.4.0beta15-36          14    10400  14.so.0.0[.0]
 144.102 + *    1.4.0beta37-87          14    10400  14.so.14.0[.0]
 144.103 + *    1.4.0rc01               14    10400  14.so.14.0[.0]
 144.104 + *    1.4.0beta88-109         14    10400  14.so.14.0[.0]
 144.105 + *    1.4.0rc02-08            14    10400  14.so.14.0[.0]
 144.106 + *    1.4.0                   14    10400  14.so.14.0[.0]
 144.107 + *    1.4.1beta01-03          14    10401  14.so.14.1[.0]
 144.108 + *    1.4.1rc01               14    10401  14.so.14.1[.0]
 144.109 + *    1.4.1beta04-12          14    10401  14.so.14.1[.0]
 144.110 + *    1.4.1                   14    10401  14.so.14.1[.0]
 144.111 + *    1.4.2                   14    10402  14.so.14.2[.0]
 144.112 + *    1.4.3                   14    10403  14.so.14.3[.0]
 144.113 + *    1.4.4                   14    10404  14.so.14.4[.0]
 144.114 + *    1.5.0beta01-58          15    10500  15.so.15.0[.0]
 144.115 + *    1.5.0rc01-07            15    10500  15.so.15.0[.0]
 144.116 + *    1.5.0                   15    10500  15.so.15.0[.0]
 144.117 + *    1.5.1beta01-11          15    10501  15.so.15.1[.0]
 144.118 + *    1.5.1rc01-02            15    10501  15.so.15.1[.0]
 144.119 + *    1.5.1                   15    10501  15.so.15.1[.0]
 144.120 + *    1.5.2beta01-03          15    10502  15.so.15.2[.0]
 144.121 + *    1.5.2rc01-03            15    10502  15.so.15.2[.0]
 144.122 + *    1.5.2                   15    10502  15.so.15.2[.0]
 144.123 + *    1.5.3beta01-10          15    10503  15.so.15.3[.0]
 144.124 + *    1.5.3rc01-02            15    10503  15.so.15.3[.0]
 144.125 + *    1.5.3beta11             15    10503  15.so.15.3[.0]
 144.126 + *    1.5.3 [omitted]
 144.127 + *    1.5.4beta01-08          15    10504  15.so.15.4[.0]
 144.128 + *    1.5.4rc01               15    10504  15.so.15.4[.0]
 144.129 + *    1.5.4                   15    10504  15.so.15.4[.0]
 144.130   *
 144.131 - *    Henceforth the source version will match the shared-library major
 144.132 - *    and minor numbers; the shared-library major version number will be
 144.133 - *    used for changes in backward compatibility, as it is intended.  The
 144.134 - *    PNG_LIBPNG_VER macro, which is not used within libpng but is available
 144.135 - *    for applications, is an unsigned integer of the form xyyzz corresponding
 144.136 - *    to the source version x.y.z (leading zeros in y and z).  Beta versions
 144.137 - *    were given the previous public release number plus a letter, until
 144.138 - *    version 1.0.6j; from then on they were given the upcoming public
 144.139 - *    release number plus "betaNN" or "rcN".
 144.140 + *   Henceforth the source version will match the shared-library major
 144.141 + *   and minor numbers; the shared-library major version number will be
 144.142 + *   used for changes in backward compatibility, as it is intended.  The
 144.143 + *   PNG_LIBPNG_VER macro, which is not used within libpng but is available
 144.144 + *   for applications, is an unsigned integer of the form xyyzz corresponding
 144.145 + *   to the source version x.y.z (leading zeros in y and z).  Beta versions
 144.146 + *   were given the previous public release number plus a letter, until
 144.147 + *   version 1.0.6j; from then on they were given the upcoming public
 144.148 + *   release number plus "betaNN" or "rcN".
 144.149   *
 144.150 - *    Binary incompatibility exists only when applications make direct access
 144.151 - *    to the info_ptr or png_ptr members through png.h, and the compiled
 144.152 - *    application is loaded with a different version of the library.
 144.153 + *   Binary incompatibility exists only when applications make direct access
 144.154 + *   to the info_ptr or png_ptr members through png.h, and the compiled
 144.155 + *   application is loaded with a different version of the library.
 144.156   *
 144.157 - *    DLLNUM will change each time there are forward or backward changes
 144.158 - *    in binary compatibility (e.g., when a new feature is added).
 144.159 + *   DLLNUM will change each time there are forward or backward changes
 144.160 + *   in binary compatibility (e.g., when a new feature is added).
 144.161   *
 144.162 - * See libpng.txt or libpng.3 for more information.  The PNG specification
 144.163 - * is available as a W3C Recommendation and as an ISO Specification,
 144.164 - * <http://www.w3.org/TR/2003/REC-PNG-20031110/
 144.165 + * See libpng-manual.txt or libpng.3 for more information.  The PNG
 144.166 + * specification is available as a W3C Recommendation and as an ISO
 144.167 + * Specification, <http://www.w3.org/TR/2003/REC-PNG-20031110/
 144.168   */
 144.169  
 144.170  /*
 144.171 @@ -207,8 +214,10 @@
 144.172   * If you modify libpng you may insert additional notices immediately following
 144.173   * this sentence.
 144.174   *
 144.175 - * libpng versions 1.2.6, August 15, 2004, through 1.2.18, May 15, 2007, are
 144.176 - * Copyright (c) 2004, 2006-2007 Glenn Randers-Pehrson, and are
 144.177 + * This code is released under the libpng license.
 144.178 + *
 144.179 + * libpng versions 1.2.6, August 15, 2004, through 1.5.4, July 7, 2011, are
 144.180 + * Copyright (c) 2004, 2006-2011 Glenn Randers-Pehrson, and are
 144.181   * distributed according to the same disclaimer and license as libpng-1.2.5
 144.182   * with the following individual added to the list of Contributing Authors:
 144.183   *
 144.184 @@ -277,13 +286,13 @@
 144.185   * source code, or portions hereof, for any purpose, without fee, subject
 144.186   * to the following restrictions:
 144.187   *
 144.188 - * 1. The origin of this source code must not be misrepresented.
 144.189 + *   1. The origin of this source code must not be misrepresented.
 144.190   *
 144.191 - * 2. Altered versions must be plainly marked as such and
 144.192 - * must not be misrepresented as being the original source.
 144.193 + *   2. Altered versions must be plainly marked as such and must not
 144.194 + *      be misrepresented as being the original source.
 144.195   *
 144.196 - * 3. This Copyright notice may not be removed or altered from
 144.197 - *    any source or altered source distribution.
 144.198 + *   3. This Copyright notice may not be removed or altered from
 144.199 + *      any source or altered source distribution.
 144.200   *
 144.201   * The Contributing Authors and Group 42, Inc. specifically permit, without
 144.202   * fee, and encourage the use of this source code as a component to
 144.203 @@ -296,7 +305,7 @@
 144.204   * A "png_get_copyright" function is available, for convenient use in "about"
 144.205   * boxes and the like:
 144.206   *
 144.207 - * printf("%s",png_get_copyright(NULL));
 144.208 + *     printf("%s", png_get_copyright(NULL));
 144.209   *
 144.210   * Also, the PNG logo (in PNG format, of course) is supplied in the
 144.211   * files "pngbar.png" and "pngbar.jpg (88x31) and "pngnow.png" (98x31).
 144.212 @@ -319,25 +328,24 @@
 144.213   * Y2K compliance in libpng:
 144.214   * =========================
 144.215   *
 144.216 - *    May 15, 2007
 144.217 + *    July 7, 2011
 144.218   *
 144.219   *    Since the PNG Development group is an ad-hoc body, we can't make
 144.220   *    an official declaration.
 144.221   *
 144.222   *    This is your unofficial assurance that libpng from version 0.71 and
 144.223 - *    upward through 1.2.18 are Y2K compliant.  It is my belief that earlier
 144.224 - *    versions were also Y2K compliant.
 144.225 + *    upward through 1.5.4 are Y2K compliant.  It is my belief that
 144.226 + *    earlier versions were also Y2K compliant.
 144.227   *
 144.228 - *    Libpng only has three year fields.  One is a 2-byte unsigned integer
 144.229 - *    that will hold years up to 65535.  The other two hold the date in text
 144.230 + *    Libpng only has two year fields.  One is a 2-byte unsigned integer
 144.231 + *    that will hold years up to 65535.  The other holds the date in text
 144.232   *    format, and will hold years up to 9999.
 144.233   *
 144.234   *    The integer is
 144.235   *        "png_uint_16 year" in png_time_struct.
 144.236   *
 144.237 - *    The strings are
 144.238 - *        "png_charp time_buffer" in png_struct and
 144.239 - *        "near_time_buffer", which is a local character string in png.c.
 144.240 + *    The string is
 144.241 + *        "png_char time_buffer" in png_struct
 144.242   *
 144.243   *    There are seven time-related functions:
 144.244   *        png.c: png_convert_to_rfc_1123() in png.c
 144.245 @@ -374,26 +382,27 @@
 144.246  #ifndef PNG_H
 144.247  #define PNG_H
 144.248  
 144.249 -/* This is not the place to learn how to use libpng.  The file libpng.txt
 144.250 +/* This is not the place to learn how to use libpng. The file libpng-manual.txt
 144.251   * describes how to use libpng, and the file example.c summarizes it
 144.252   * with some code on which to build.  This file is useful for looking
 144.253   * at the actual function definitions and structure components.
 144.254   */
 144.255  
 144.256  /* Version information for png.h - this should match the version in png.c */
 144.257 -#define PNG_LIBPNG_VER_STRING "1.2.18"
 144.258 +#define PNG_LIBPNG_VER_STRING "1.5.4"
 144.259  #define PNG_HEADER_VERSION_STRING \
 144.260 -   " libpng version 1.2.18 - May 15, 2007 (header)\n"
 144.261 +     " libpng version 1.5.4 - July 7, 2011\n"
 144.262  
 144.263 -#define PNG_LIBPNG_VER_SONUM   0
 144.264 -#define PNG_LIBPNG_VER_DLLNUM  13
 144.265 +#define PNG_LIBPNG_VER_SONUM   15
 144.266 +#define PNG_LIBPNG_VER_DLLNUM  15
 144.267  
 144.268  /* These should match the first 3 components of PNG_LIBPNG_VER_STRING: */
 144.269  #define PNG_LIBPNG_VER_MAJOR   1
 144.270 -#define PNG_LIBPNG_VER_MINOR   2
 144.271 -#define PNG_LIBPNG_VER_RELEASE 18
 144.272 +#define PNG_LIBPNG_VER_MINOR   5
 144.273 +#define PNG_LIBPNG_VER_RELEASE 4
 144.274  /* This should match the numeric part of the final component of
 144.275 - * PNG_LIBPNG_VER_STRING, omitting any leading zero: */
 144.276 + * PNG_LIBPNG_VER_STRING, omitting any leading zero:
 144.277 + */
 144.278  
 144.279  #define PNG_LIBPNG_VER_BUILD  0
 144.280  
 144.281 @@ -412,26 +421,53 @@
 144.282  #define PNG_LIBPNG_BUILD_SPECIAL 32 /* Cannot be OR'ed with
 144.283                                         PNG_LIBPNG_BUILD_PRIVATE */
 144.284  
 144.285 -#define PNG_LIBPNG_BUILD_BASE_TYPE PNG_LIBPNG_BUILD_STABLE
 144.286 +#define PNG_LIBPNG_BUILD_BASE_TYPE PNG_LIBPNG_BUILD_BETA
 144.287  
 144.288  /* Careful here.  At one time, Guy wanted to use 082, but that would be octal.
 144.289   * We must not include leading zeros.
 144.290   * Versions 0.7 through 1.0.0 were in the range 0 to 100 here (only
 144.291   * version 1.0.0 was mis-numbered 100 instead of 10000).  From
 144.292 - * version 1.0.1 it's    xxyyzz, where x=major, y=minor, z=release */
 144.293 -#define PNG_LIBPNG_VER 10218 /* 1.2.18 */
 144.294 + * version 1.0.1 it's    xxyyzz, where x=major, y=minor, z=release
 144.295 + */
 144.296 +#define PNG_LIBPNG_VER 10504 /* 1.5.4 */
 144.297 +
 144.298 +/* Library configuration: these options cannot be changed after
 144.299 + * the library has been built.
 144.300 + */
 144.301 +#ifndef PNGLCONF_H
 144.302 +    /* If pnglibconf.h is missing, you can
 144.303 +     * copy scripts/pnglibconf.h.prebuilt to pnglibconf.h
 144.304 +     */
 144.305 +#   include "pnglibconf.h"
 144.306 +#endif
 144.307  
 144.308  #ifndef PNG_VERSION_INFO_ONLY
 144.309 -/* include the compression library's header */
 144.310 -#include "zlib.h"
 144.311 +#  ifndef PNG_BUILDING_SYMBOL_TABLE
 144.312 +  /*
 144.313 +   *   Standard header files (not needed for the version info or while
 144.314 +   *   building symbol table -- see scripts/pnglibconf.dfa)
 144.315 +   */
 144.316 +#    ifdef PNG_SETJMP_SUPPORTED
 144.317 +#      include <setjmp.h>
 144.318 +#    endif
 144.319 +
 144.320 +    /* Need the time information for converting tIME chunks, it
 144.321 +     * defines struct tm:
 144.322 +     */
 144.323 +#    ifdef PNG_CONVERT_tIME_SUPPORTED
 144.324 +       /* "time.h" functions are not supported on all operating systems */
 144.325 +#      include <time.h>
 144.326 +#    endif
 144.327 +#  endif
 144.328 +
 144.329 +/* Machine specific configuration. */
 144.330 +#  include "pngconf.h"
 144.331  #endif
 144.332  
 144.333 -/* include all user configurable info, including optional assembler routines */
 144.334 -#include "pngconf.h"
 144.335 -
 144.336  /*
 144.337 - * Added at libpng-1.2.8 */
 144.338 -/* Ref MSDN: Private as priority over Special
 144.339 + * Added at libpng-1.2.8
 144.340 + *
 144.341 + * Ref MSDN: Private as priority over Special
 144.342   * VS_FF_PRIVATEBUILD File *was not* built using standard release
 144.343   * procedures. If this value is given, the StringFileInfo block must
 144.344   * contain a PrivateBuild string.
 144.345 @@ -442,13 +478,13 @@
 144.346   * StringFileInfo block must contain a SpecialBuild string.
 144.347   */
 144.348  
 144.349 -#if defined(PNG_USER_PRIVATEBUILD)
 144.350 +#ifdef PNG_USER_PRIVATEBUILD /* From pnglibconf.h */
 144.351  #  define PNG_LIBPNG_BUILD_TYPE \
 144.352 -          (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_PRIVATE)
 144.353 +       (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_PRIVATE)
 144.354  #else
 144.355 -#  if defined(PNG_LIBPNG_SPECIALBUILD)
 144.356 +#  ifdef PNG_LIBPNG_SPECIALBUILD
 144.357  #    define PNG_LIBPNG_BUILD_TYPE \
 144.358 -            (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_SPECIAL)
 144.359 +         (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_SPECIAL)
 144.360  #  else
 144.361  #    define PNG_LIBPNG_BUILD_TYPE (PNG_LIBPNG_BUILD_BASE_TYPE)
 144.362  #  endif
 144.363 @@ -461,76 +497,61 @@
 144.364  extern "C" {
 144.365  #endif /* __cplusplus */
 144.366  
 144.367 -/* This file is arranged in several sections.  The first section contains
 144.368 - * structure and type definitions.  The second section contains the external
 144.369 - * library functions, while the third has the internal library functions,
 144.370 - * which applications aren't expected to use directly.
 144.371 - */
 144.372 -
 144.373 -#ifndef PNG_NO_TYPECAST_NULL
 144.374 -#define int_p_NULL                (int *)NULL
 144.375 -#define png_bytep_NULL            (png_bytep)NULL
 144.376 -#define png_bytepp_NULL           (png_bytepp)NULL
 144.377 -#define png_doublep_NULL          (png_doublep)NULL
 144.378 -#define png_error_ptr_NULL        (png_error_ptr)NULL
 144.379 -#define png_flush_ptr_NULL        (png_flush_ptr)NULL
 144.380 -#define png_free_ptr_NULL         (png_free_ptr)NULL
 144.381 -#define png_infopp_NULL           (png_infopp)NULL
 144.382 -#define png_malloc_ptr_NULL       (png_malloc_ptr)NULL
 144.383 -#define png_read_status_ptr_NULL  (png_read_status_ptr)NULL
 144.384 -#define png_rw_ptr_NULL           (png_rw_ptr)NULL
 144.385 -#define png_structp_NULL          (png_structp)NULL
 144.386 -#define png_uint_16p_NULL         (png_uint_16p)NULL
 144.387 -#define png_voidp_NULL            (png_voidp)NULL
 144.388 -#define png_write_status_ptr_NULL (png_write_status_ptr)NULL
 144.389 -#else
 144.390 -#define int_p_NULL                NULL
 144.391 -#define png_bytep_NULL            NULL
 144.392 -#define png_bytepp_NULL           NULL
 144.393 -#define png_doublep_NULL          NULL
 144.394 -#define png_error_ptr_NULL        NULL
 144.395 -#define png_flush_ptr_NULL        NULL
 144.396 -#define png_free_ptr_NULL         NULL
 144.397 -#define png_infopp_NULL           NULL
 144.398 -#define png_malloc_ptr_NULL       NULL
 144.399 -#define png_read_status_ptr_NULL  NULL
 144.400 -#define png_rw_ptr_NULL           NULL
 144.401 -#define png_structp_NULL          NULL
 144.402 -#define png_uint_16p_NULL         NULL
 144.403 -#define png_voidp_NULL            NULL
 144.404 -#define png_write_status_ptr_NULL NULL
 144.405 -#endif
 144.406 -
 144.407 -/* variables declared in png.c - only it needs to define PNG_NO_EXTERN */
 144.408 -#if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
 144.409  /* Version information for C files, stored in png.c.  This had better match
 144.410   * the version above.
 144.411   */
 144.412 -#ifdef PNG_USE_GLOBAL_ARRAYS
 144.413 -PNG_EXPORT_VAR (const char) png_libpng_ver[18];
 144.414 -  /* need room for 99.99.99beta99z */
 144.415 -#else
 144.416  #define png_libpng_ver png_get_header_ver(NULL)
 144.417 -#endif
 144.418  
 144.419 -#ifdef PNG_USE_GLOBAL_ARRAYS
 144.420 -/* This was removed in version 1.0.5c */
 144.421 -/* Structures to facilitate easy interlacing.  See png.c for more details */
 144.422 -PNG_EXPORT_VAR (const int FARDATA) png_pass_start[7];
 144.423 -PNG_EXPORT_VAR (const int FARDATA) png_pass_inc[7];
 144.424 -PNG_EXPORT_VAR (const int FARDATA) png_pass_ystart[7];
 144.425 -PNG_EXPORT_VAR (const int FARDATA) png_pass_yinc[7];
 144.426 -PNG_EXPORT_VAR (const int FARDATA) png_pass_mask[7];
 144.427 -PNG_EXPORT_VAR (const int FARDATA) png_pass_dsp_mask[7];
 144.428 -#ifdef PNG_USE_PNGGCCRD
 144.429 -PNG_EXPORT_VAR (const int FARDATA) png_pass_width[7];
 144.430 -#endif
 144.431 -/* This isn't currently used.  If you need it, see png.c for more details.
 144.432 -PNG_EXPORT_VAR (const int FARDATA) png_pass_height[7];
 144.433 -*/
 144.434 -#endif
 144.435 +/* This file is arranged in several sections:
 144.436 + *
 144.437 + * 1. Any configuration options that can be specified by for the application
 144.438 + *    code when it is built.  (Build time configuration is in pnglibconf.h)
 144.439 + * 2. Type definitions (base types are defined in pngconf.h), structure
 144.440 + *    definitions.
 144.441 + * 3. Exported library functions.
 144.442 + *
 144.443 + * The library source code has additional files (principally pngpriv.h) that
 144.444 + * allow configuration of the library.
 144.445 + */
 144.446 +/* Section 1: run time configuration
 144.447 + * See pnglibconf.h for build time configuration
 144.448 + *
 144.449 + * Run time configuration allows the application to choose between
 144.450 + * implementations of certain arithmetic APIs.  The default is set
 144.451 + * at build time and recorded in pnglibconf.h, but it is safe to
 144.452 + * override these (and only these) settings.  Note that this won't
 144.453 + * change what the library does, only application code, and the
 144.454 + * settings can (and probably should) be made on a per-file basis
 144.455 + * by setting the #defines before including png.h
 144.456 + *
 144.457 + * Use macros to read integers from PNG data or use the exported
 144.458 + * functions?
 144.459 + *   PNG_USE_READ_MACROS: use the macros (see below)  Note that
 144.460 + *     the macros evaluate their argument multiple times.
 144.461 + *   PNG_NO_USE_READ_MACROS: call the relevant library function.
 144.462 + *
 144.463 + * Use the alternative algorithm for compositing alpha samples that
 144.464 + * does not use division?
 144.465 + *   PNG_READ_COMPOSITE_NODIV_SUPPORTED: use the 'no division'
 144.466 + *      algorithm.
 144.467 + *   PNG_NO_READ_COMPOSITE_NODIV: use the 'division' algorithm.
 144.468 + *
 144.469 + * How to handle benign errors if PNG_ALLOW_BENIGN_ERRORS is
 144.470 + * false?
 144.471 + *   PNG_ALLOW_BENIGN_ERRORS: map calls to the benign error
 144.472 + *      APIs to png_warning.
 144.473 + * Otherwise the calls are mapped to png_error.
 144.474 + */
 144.475  
 144.476 -#endif /* PNG_NO_EXTERN */
 144.477 +/* Section 2: type definitions, including structures and compile time
 144.478 + * constants.
 144.479 + * See pngconf.h for base types that vary by machine/system
 144.480 + */
 144.481 +
 144.482 +/* This triggers a compiler error in png.c, if png.c and png.h
 144.483 + * do not agree upon the version number.
 144.484 + */
 144.485 +typedef char* png_libpng_version_1_5_4;
 144.486  
 144.487  /* Three color definitions.  The order of the red, green, and blue, (and the
 144.488   * exact size) is not important, although the size of the fields need to
 144.489 @@ -543,6 +564,7 @@
 144.490     png_byte blue;
 144.491  } png_color;
 144.492  typedef png_color FAR * png_colorp;
 144.493 +typedef PNG_CONST png_color FAR * png_const_colorp;
 144.494  typedef png_color FAR * FAR * png_colorpp;
 144.495  
 144.496  typedef struct png_color_16_struct
 144.497 @@ -554,6 +576,7 @@
 144.498     png_uint_16 gray;  /* for use in grayscale files */
 144.499  } png_color_16;
 144.500  typedef png_color_16 FAR * png_color_16p;
 144.501 +typedef PNG_CONST png_color_16 FAR * png_const_color_16p;
 144.502  typedef png_color_16 FAR * FAR * png_color_16pp;
 144.503  
 144.504  typedef struct png_color_8_struct
 144.505 @@ -565,6 +588,7 @@
 144.506     png_byte alpha; /* for alpha channel files */
 144.507  } png_color_8;
 144.508  typedef png_color_8 FAR * png_color_8p;
 144.509 +typedef PNG_CONST png_color_8 FAR * png_const_color_8p;
 144.510  typedef png_color_8 FAR * FAR * png_color_8pp;
 144.511  
 144.512  /*
 144.513 @@ -580,6 +604,7 @@
 144.514     png_uint_16 frequency;
 144.515  } png_sPLT_entry;
 144.516  typedef png_sPLT_entry FAR * png_sPLT_entryp;
 144.517 +typedef PNG_CONST png_sPLT_entry FAR * png_const_sPLT_entryp;
 144.518  typedef png_sPLT_entry FAR * FAR * png_sPLT_entrypp;
 144.519  
 144.520  /*  When the depth of the sPLT palette is 8 bits, the color and alpha samples
 144.521 @@ -595,6 +620,7 @@
 144.522     png_int_32 nentries;      /* number of palette entries */
 144.523  } png_sPLT_t;
 144.524  typedef png_sPLT_t FAR * png_sPLT_tp;
 144.525 +typedef PNG_CONST png_sPLT_t FAR * png_const_sPLT_tp;
 144.526  typedef png_sPLT_t FAR * FAR * png_sPLT_tpp;
 144.527  
 144.528  #ifdef PNG_TEXT_SUPPORTED
 144.529 @@ -602,7 +628,7 @@
 144.530   * and whether that contents is compressed or not.  The "key" field
 144.531   * points to a regular zero-terminated C string.  The "text", "lang", and
 144.532   * "lang_key" fields can be regular C strings, empty strings, or NULL pointers.
 144.533 - * However, the * structure returned by png_get_text() will always contain
 144.534 + * However, the structure returned by png_get_text() will always contain
 144.535   * regular zero-terminated C strings (possibly empty), never NULL pointers,
 144.536   * so they can be safely used in printf() and other string-handling functions.
 144.537   */
 144.538 @@ -617,15 +643,14 @@
 144.539     png_charp text;         /* comment, may be an empty string (ie "")
 144.540                                or a NULL pointer */
 144.541     png_size_t text_length; /* length of the text string */
 144.542 -#ifdef PNG_iTXt_SUPPORTED
 144.543     png_size_t itxt_length; /* length of the itxt string */
 144.544     png_charp lang;         /* language code, 0-79 characters
 144.545                                or a NULL pointer */
 144.546     png_charp lang_key;     /* keyword translated UTF-8 string, 0 or more
 144.547                                chars or a NULL pointer */
 144.548 -#endif
 144.549  } png_text;
 144.550  typedef png_text FAR * png_textp;
 144.551 +typedef PNG_CONST png_text FAR * png_const_textp;
 144.552  typedef png_text FAR * FAR * png_textpp;
 144.553  #endif
 144.554  
 144.555 @@ -655,9 +680,11 @@
 144.556     png_byte second;  /* second of minute, 0 - 60 (for leap seconds) */
 144.557  } png_time;
 144.558  typedef png_time FAR * png_timep;
 144.559 +typedef PNG_CONST png_time FAR * png_const_timep;
 144.560  typedef png_time FAR * FAR * png_timepp;
 144.561  
 144.562 -#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
 144.563 +#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) || \
 144.564 +    defined(PNG_HANDLE_AS_UNKNOWN_SUPPORTED)
 144.565  /* png_unknown_chunk is a structure to hold queued chunks for which there is
 144.566   * no specific support.  The idea is that we can use this to queue
 144.567   * up private chunks for output even though the library doesn't actually
 144.568 @@ -672,299 +699,41 @@
 144.569      /* libpng-using applications should NOT directly modify this byte. */
 144.570      png_byte location; /* mode of operation at read time */
 144.571  }
 144.572 +
 144.573 +
 144.574  png_unknown_chunk;
 144.575  typedef png_unknown_chunk FAR * png_unknown_chunkp;
 144.576 +typedef PNG_CONST png_unknown_chunk FAR * png_const_unknown_chunkp;
 144.577  typedef png_unknown_chunk FAR * FAR * png_unknown_chunkpp;
 144.578  #endif
 144.579  
 144.580 -/* png_info is a structure that holds the information in a PNG file so
 144.581 - * that the application can find out the characteristics of the image.
 144.582 - * If you are reading the file, this structure will tell you what is
 144.583 - * in the PNG file.  If you are writing the file, fill in the information
 144.584 - * you want to put into the PNG file, then call png_write_info().
 144.585 - * The names chosen should be very close to the PNG specification, so
 144.586 - * consult that document for information about the meaning of each field.
 144.587 - *
 144.588 - * With libpng < 0.95, it was only possible to directly set and read the
 144.589 - * the values in the png_info_struct, which meant that the contents and
 144.590 - * order of the values had to remain fixed.  With libpng 0.95 and later,
 144.591 - * however, there are now functions that abstract the contents of
 144.592 - * png_info_struct from the application, so this makes it easier to use
 144.593 - * libpng with dynamic libraries, and even makes it possible to use
 144.594 - * libraries that don't have all of the libpng ancillary chunk-handing
 144.595 - * functionality.
 144.596 - *
 144.597 - * In any case, the order of the parameters in png_info_struct should NOT
 144.598 - * be changed for as long as possible to keep compatibility with applications
 144.599 - * that use the old direct-access method with png_info_struct.
 144.600 - *
 144.601 - * The following members may have allocated storage attached that should be
 144.602 - * cleaned up before the structure is discarded: palette, trans, text,
 144.603 - * pcal_purpose, pcal_units, pcal_params, hist, iccp_name, iccp_profile,
 144.604 - * splt_palettes, scal_unit, row_pointers, and unknowns.   By default, these
 144.605 - * are automatically freed when the info structure is deallocated, if they were
 144.606 - * allocated internally by libpng.  This behavior can be changed by means
 144.607 - * of the png_data_freer() function.
 144.608 - *
 144.609 - * More allocation details: all the chunk-reading functions that
 144.610 - * change these members go through the corresponding png_set_*
 144.611 - * functions.  A function to clear these members is available: see
 144.612 - * png_free_data().  The png_set_* functions do not depend on being
 144.613 - * able to point info structure members to any of the storage they are
 144.614 - * passed (they make their own copies), EXCEPT that the png_set_text
 144.615 - * functions use the same storage passed to them in the text_ptr or
 144.616 - * itxt_ptr structure argument, and the png_set_rows and png_set_unknowns
 144.617 - * functions do not make their own copies.
 144.618 +/* Values for the unknown chunk location byte */
 144.619 +
 144.620 +#define PNG_HAVE_IHDR  0x01
 144.621 +#define PNG_HAVE_PLTE  0x02
 144.622 +#define PNG_AFTER_IDAT 0x08
 144.623 +
 144.624 +/* The complete definition of png_info has, as of libpng-1.5.0,
 144.625 + * been moved into a separate header file that is not accessible to
 144.626 + * applications.  Read libpng-manual.txt or libpng.3 for more info.
 144.627   */
 144.628 -typedef struct png_info_struct
 144.629 -{
 144.630 -   /* the following are necessary for every PNG file */
 144.631 -   png_uint_32 width;       /* width of image in pixels (from IHDR) */
 144.632 -   png_uint_32 height;      /* height of image in pixels (from IHDR) */
 144.633 -   png_uint_32 valid;       /* valid chunk data (see PNG_INFO_ below) */
 144.634 -   png_uint_32 rowbytes;    /* bytes needed to hold an untransformed row */
 144.635 -   png_colorp palette;      /* array of color values (valid & PNG_INFO_PLTE) */
 144.636 -   png_uint_16 num_palette; /* number of color entries in "palette" (PLTE) */
 144.637 -   png_uint_16 num_trans;   /* number of transparent palette color (tRNS) */
 144.638 -   png_byte bit_depth;      /* 1, 2, 4, 8, or 16 bits/channel (from IHDR) */
 144.639 -   png_byte color_type;     /* see PNG_COLOR_TYPE_ below (from IHDR) */
 144.640 -   /* The following three should have been named *_method not *_type */
 144.641 -   png_byte compression_type; /* must be PNG_COMPRESSION_TYPE_BASE (IHDR) */
 144.642 -   png_byte filter_type;    /* must be PNG_FILTER_TYPE_BASE (from IHDR) */
 144.643 -   png_byte interlace_type; /* One of PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
 144.644 -
 144.645 -   /* The following is informational only on read, and not used on writes. */
 144.646 -   png_byte channels;       /* number of data channels per pixel (1, 2, 3, 4) */
 144.647 -   png_byte pixel_depth;    /* number of bits per pixel */
 144.648 -   png_byte spare_byte;     /* to align the data, and for future use */
 144.649 -   png_byte signature[8];   /* magic bytes read by libpng from start of file */
 144.650 -
 144.651 -   /* The rest of the data is optional.  If you are reading, check the
 144.652 -    * valid field to see if the information in these are valid.  If you
 144.653 -    * are writing, set the valid field to those chunks you want written,
 144.654 -    * and initialize the appropriate fields below.
 144.655 -    */
 144.656 -
 144.657 -#if defined(PNG_gAMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
 144.658 -   /* The gAMA chunk describes the gamma characteristics of the system
 144.659 -    * on which the image was created, normally in the range [1.0, 2.5].
 144.660 -    * Data is valid if (valid & PNG_INFO_gAMA) is non-zero.
 144.661 -    */
 144.662 -   float gamma; /* gamma value of image, if (valid & PNG_INFO_gAMA) */
 144.663 -#endif
 144.664 -
 144.665 -#if defined(PNG_sRGB_SUPPORTED)
 144.666 -    /* GR-P, 0.96a */
 144.667 -    /* Data valid if (valid & PNG_INFO_sRGB) non-zero. */
 144.668 -   png_byte srgb_intent; /* sRGB rendering intent [0, 1, 2, or 3] */
 144.669 -#endif
 144.670 -
 144.671 -#if defined(PNG_TEXT_SUPPORTED)
 144.672 -   /* The tEXt, and zTXt chunks contain human-readable textual data in
 144.673 -    * uncompressed, compressed, and optionally compressed forms, respectively.
 144.674 -    * The data in "text" is an array of pointers to uncompressed,
 144.675 -    * null-terminated C strings. Each chunk has a keyword that describes the
 144.676 -    * textual data contained in that chunk.  Keywords are not required to be
 144.677 -    * unique, and the text string may be empty.  Any number of text chunks may
 144.678 -    * be in an image.
 144.679 -    */
 144.680 -   int num_text; /* number of comments read/to write */
 144.681 -   int max_text; /* current size of text array */
 144.682 -   png_textp text; /* array of comments read/to write */
 144.683 -#endif /* PNG_TEXT_SUPPORTED */
 144.684 -
 144.685 -#if defined(PNG_tIME_SUPPORTED)
 144.686 -   /* The tIME chunk holds the last time the displayed image data was
 144.687 -    * modified.  See the png_time struct for the contents of this struct.
 144.688 -    */
 144.689 -   png_time mod_time;
 144.690 -#endif
 144.691 -
 144.692 -#if defined(PNG_sBIT_SUPPORTED)
 144.693 -   /* The sBIT chunk specifies the number of significant high-order bits
 144.694 -    * in the pixel data.  Values are in the range [1, bit_depth], and are
 144.695 -    * only specified for the channels in the pixel data.  The contents of
 144.696 -    * the low-order bits is not specified.  Data is valid if
 144.697 -    * (valid & PNG_INFO_sBIT) is non-zero.
 144.698 -    */
 144.699 -   png_color_8 sig_bit; /* significant bits in color channels */
 144.700 -#endif
 144.701 -
 144.702 -#if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_EXPAND_SUPPORTED) || \
 144.703 -defined(PNG_READ_BACKGROUND_SUPPORTED)
 144.704 -   /* The tRNS chunk supplies transparency data for paletted images and
 144.705 -    * other image types that don't need a full alpha channel.  There are
 144.706 -    * "num_trans" transparency values for a paletted image, stored in the
 144.707 -    * same order as the palette colors, starting from index 0.  Values
 144.708 -    * for the data are in the range [0, 255], ranging from fully transparent
 144.709 -    * to fully opaque, respectively.  For non-paletted images, there is a
 144.710 -    * single color specified that should be treated as fully transparent.
 144.711 -    * Data is valid if (valid & PNG_INFO_tRNS) is non-zero.
 144.712 -    */
 144.713 -   png_bytep trans; /* transparent values for paletted image */
 144.714 -   png_color_16 trans_values; /* transparent color for non-palette image */
 144.715 -#endif
 144.716 -
 144.717 -#if defined(PNG_bKGD_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
 144.718 -   /* The bKGD chunk gives the suggested image background color if the
 144.719 -    * display program does not have its own background color and the image
 144.720 -    * is needs to composited onto a background before display.  The colors
 144.721 -    * in "background" are normally in the same color space/depth as the
 144.722 -    * pixel data.  Data is valid if (valid & PNG_INFO_bKGD) is non-zero.
 144.723 -    */
 144.724 -   png_color_16 background;
 144.725 -#endif
 144.726 -
 144.727 -#if defined(PNG_oFFs_SUPPORTED)
 144.728 -   /* The oFFs chunk gives the offset in "offset_unit_type" units rightwards
 144.729 -    * and downwards from the top-left corner of the display, page, or other
 144.730 -    * application-specific co-ordinate space.  See the PNG_OFFSET_ defines
 144.731 -    * below for the unit types.  Valid if (valid & PNG_INFO_oFFs) non-zero.
 144.732 -    */
 144.733 -   png_int_32 x_offset; /* x offset on page */
 144.734 -   png_int_32 y_offset; /* y offset on page */
 144.735 -   png_byte offset_unit_type; /* offset units type */
 144.736 -#endif
 144.737 -
 144.738 -#if defined(PNG_pHYs_SUPPORTED)
 144.739 -   /* The pHYs chunk gives the physical pixel density of the image for
 144.740 -    * display or printing in "phys_unit_type" units (see PNG_RESOLUTION_
 144.741 -    * defines below).  Data is valid if (valid & PNG_INFO_pHYs) is non-zero.
 144.742 -    */
 144.743 -   png_uint_32 x_pixels_per_unit; /* horizontal pixel density */
 144.744 -   png_uint_32 y_pixels_per_unit; /* vertical pixel density */
 144.745 -   png_byte phys_unit_type; /* resolution type (see PNG_RESOLUTION_ below) */
 144.746 -#endif
 144.747 -
 144.748 -#if defined(PNG_hIST_SUPPORTED)
 144.749 -   /* The hIST chunk contains the relative frequency or importance of the
 144.750 -    * various palette entries, so that a viewer can intelligently select a
 144.751 -    * reduced-color palette, if required.  Data is an array of "num_palette"
 144.752 -    * values in the range [0,65535]. Data valid if (valid & PNG_INFO_hIST)
 144.753 -    * is non-zero.
 144.754 -    */
 144.755 -   png_uint_16p hist;
 144.756 -#endif
 144.757 -
 144.758 -#ifdef PNG_cHRM_SUPPORTED
 144.759 -   /* The cHRM chunk describes the CIE color characteristics of the monitor
 144.760 -    * on which the PNG was created.  This data allows the viewer to do gamut
 144.761 -    * mapping of the input image to ensure that the viewer sees the same
 144.762 -    * colors in the image as the creator.  Values are in the range
 144.763 -    * [0.0, 0.8].  Data valid if (valid & PNG_INFO_cHRM) non-zero.
 144.764 -    */
 144.765 -#ifdef PNG_FLOATING_POINT_SUPPORTED
 144.766 -   float x_white;
 144.767 -   float y_white;
 144.768 -   float x_red;
 144.769 -   float y_red;
 144.770 -   float x_green;
 144.771 -   float y_green;
 144.772 -   float x_blue;
 144.773 -   float y_blue;
 144.774 -#endif
 144.775 -#endif
 144.776 -
 144.777 -#if defined(PNG_pCAL_SUPPORTED)
 144.778 -   /* The pCAL chunk describes a transformation between the stored pixel
 144.779 -    * values and original physical data values used to create the image.
 144.780 -    * The integer range [0, 2^bit_depth - 1] maps to the floating-point
 144.781 -    * range given by [pcal_X0, pcal_X1], and are further transformed by a
 144.782 -    * (possibly non-linear) transformation function given by "pcal_type"
 144.783 -    * and "pcal_params" into "pcal_units".  Please see the PNG_EQUATION_
 144.784 -    * defines below, and the PNG-Group's PNG extensions document for a
 144.785 -    * complete description of the transformations and how they should be
 144.786 -    * implemented, and for a description of the ASCII parameter strings.
 144.787 -    * Data values are valid if (valid & PNG_INFO_pCAL) non-zero.
 144.788 -    */
 144.789 -   png_charp pcal_purpose;  /* pCAL chunk description string */
 144.790 -   png_int_32 pcal_X0;      /* minimum value */
 144.791 -   png_int_32 pcal_X1;      /* maximum value */
 144.792 -   png_charp pcal_units;    /* Latin-1 string giving physical units */
 144.793 -   png_charpp pcal_params;  /* ASCII strings containing parameter values */
 144.794 -   png_byte pcal_type;      /* equation type (see PNG_EQUATION_ below) */
 144.795 -   png_byte pcal_nparams;   /* number of parameters given in pcal_params */
 144.796 -#endif
 144.797 -
 144.798 -/* New members added in libpng-1.0.6 */
 144.799 -#ifdef PNG_FREE_ME_SUPPORTED
 144.800 -   png_uint_32 free_me;     /* flags items libpng is responsible for freeing */
 144.801 -#endif
 144.802 -
 144.803 -#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
 144.804 -   /* storage for unknown chunks that the library doesn't recognize. */
 144.805 -   png_unknown_chunkp unknown_chunks;
 144.806 -   png_size_t unknown_chunks_num;
 144.807 -#endif
 144.808 -
 144.809 -#if defined(PNG_iCCP_SUPPORTED)
 144.810 -   /* iCCP chunk data. */
 144.811 -   png_charp iccp_name;     /* profile name */
 144.812 -   png_charp iccp_profile;  /* International Color Consortium profile data */
 144.813 -                            /* Note to maintainer: should be png_bytep */
 144.814 -   png_uint_32 iccp_proflen;  /* ICC profile data length */
 144.815 -   png_byte iccp_compression; /* Always zero */
 144.816 -#endif
 144.817 -
 144.818 -#if defined(PNG_sPLT_SUPPORTED)
 144.819 -   /* data on sPLT chunks (there may be more than one). */
 144.820 -   png_sPLT_tp splt_palettes;
 144.821 -   png_uint_32 splt_palettes_num;
 144.822 -#endif
 144.823 -
 144.824 -#if defined(PNG_sCAL_SUPPORTED)
 144.825 -   /* The sCAL chunk describes the actual physical dimensions of the
 144.826 -    * subject matter of the graphic.  The chunk contains a unit specification
 144.827 -    * a byte value, and two ASCII strings representing floating-point
 144.828 -    * values.  The values are width and height corresponsing to one pixel
 144.829 -    * in the image.  This external representation is converted to double
 144.830 -    * here.  Data values are valid if (valid & PNG_INFO_sCAL) is non-zero.
 144.831 -    */
 144.832 -   png_byte scal_unit;         /* unit of physical scale */
 144.833 -#ifdef PNG_FLOATING_POINT_SUPPORTED
 144.834 -   double scal_pixel_width;    /* width of one pixel */
 144.835 -   double scal_pixel_height;   /* height of one pixel */
 144.836 -#endif
 144.837 -#ifdef PNG_FIXED_POINT_SUPPORTED
 144.838 -   png_charp scal_s_width;     /* string containing height */
 144.839 -   png_charp scal_s_height;    /* string containing width */
 144.840 -#endif
 144.841 -#endif
 144.842 -
 144.843 -#if defined(PNG_INFO_IMAGE_SUPPORTED)
 144.844 -   /* Memory has been allocated if (valid & PNG_ALLOCATED_INFO_ROWS) non-zero */
 144.845 -   /* Data valid if (valid & PNG_INFO_IDAT) non-zero */
 144.846 -   png_bytepp row_pointers;        /* the image bits */
 144.847 -#endif
 144.848 -
 144.849 -#if defined(PNG_FIXED_POINT_SUPPORTED) && defined(PNG_gAMA_SUPPORTED)
 144.850 -   png_fixed_point int_gamma; /* gamma of image, if (valid & PNG_INFO_gAMA) */
 144.851 -#endif
 144.852 -
 144.853 -#if defined(PNG_cHRM_SUPPORTED) && defined(PNG_FIXED_POINT_SUPPORTED)
 144.854 -   png_fixed_point int_x_white;
 144.855 -   png_fixed_point int_y_white;
 144.856 -   png_fixed_point int_x_red;
 144.857 -   png_fixed_point int_y_red;
 144.858 -   png_fixed_point int_x_green;
 144.859 -   png_fixed_point int_y_green;
 144.860 -   png_fixed_point int_x_blue;
 144.861 -   png_fixed_point int_y_blue;
 144.862 -#endif
 144.863 -
 144.864 -} png_info;
 144.865 -
 144.866 +typedef struct png_info_def png_info;
 144.867  typedef png_info FAR * png_infop;
 144.868 +typedef PNG_CONST png_info FAR * png_const_infop;
 144.869  typedef png_info FAR * FAR * png_infopp;
 144.870  
 144.871  /* Maximum positive integer used in PNG is (2^31)-1 */
 144.872  #define PNG_UINT_31_MAX ((png_uint_32)0x7fffffffL)
 144.873  #define PNG_UINT_32_MAX ((png_uint_32)(-1))
 144.874  #define PNG_SIZE_MAX ((png_size_t)(-1))
 144.875 -#if defined(PNG_1_0_X) || defined (PNG_1_2_X)
 144.876 -/* PNG_MAX_UINT is deprecated; use PNG_UINT_31_MAX instead. */
 144.877 -#define PNG_MAX_UINT PNG_UINT_31_MAX
 144.878 -#endif
 144.879 +
 144.880 +/* These are constants for fixed point values encoded in the
 144.881 + * PNG specification manner (x100000)
 144.882 + */
 144.883 +#define PNG_FP_1    100000
 144.884 +#define PNG_FP_HALF  50000
 144.885 +#define PNG_FP_MAX  ((png_fixed_point)0x7fffffffL)
 144.886 +#define PNG_FP_MIN  (-PNG_FP_MAX)
 144.887  
 144.888  /* These describe the color_type field in png_info. */
 144.889  /* color type masks */
 144.890 @@ -1060,53 +829,86 @@
 144.891   */
 144.892  typedef struct png_row_info_struct
 144.893  {
 144.894 -   png_uint_32 width; /* width of row */
 144.895 -   png_uint_32 rowbytes; /* number of bytes in row */
 144.896 -   png_byte color_type; /* color type of row */
 144.897 -   png_byte bit_depth; /* bit depth of row */
 144.898 -   png_byte channels; /* number of channels (1, 2, 3, or 4) */
 144.899 +   png_uint_32 width;    /* width of row */
 144.900 +   png_size_t rowbytes;  /* number of bytes in row */
 144.901 +   png_byte color_type;  /* color type of row */
 144.902 +   png_byte bit_depth;   /* bit depth of row */
 144.903 +   png_byte channels;    /* number of channels (1, 2, 3, or 4) */
 144.904     png_byte pixel_depth; /* bits per pixel (depth * channels) */
 144.905  } png_row_info;
 144.906  
 144.907  typedef png_row_info FAR * png_row_infop;
 144.908  typedef png_row_info FAR * FAR * png_row_infopp;
 144.909  
 144.910 +/* The complete definition of png_struct has, as of libpng-1.5.0,
 144.911 + * been moved into a separate header file that is not accessible to
 144.912 + * applications.  Read libpng-manual.txt or libpng.3 for more info.
 144.913 + */
 144.914 +typedef struct png_struct_def png_struct;
 144.915 +typedef PNG_CONST png_struct FAR * png_const_structp;
 144.916 +typedef png_struct FAR * png_structp;
 144.917 +
 144.918  /* These are the function types for the I/O functions and for the functions
 144.919   * that allow the user to override the default I/O functions with his or her
 144.920   * own.  The png_error_ptr type should match that of user-supplied warning
 144.921   * and error functions, while the png_rw_ptr type should match that of the
 144.922 - * user read/write data functions.
 144.923 + * user read/write data functions.  Note that the 'write' function must not
 144.924 + * modify the buffer it is passed. The 'read' function, on the other hand, is
 144.925 + * expected to return the read data in the buffer.
 144.926   */
 144.927 -typedef struct png_struct_def png_struct;
 144.928 -typedef png_struct FAR * png_structp;
 144.929 -
 144.930 -typedef void (PNGAPI *png_error_ptr) PNGARG((png_structp, png_const_charp));
 144.931 -typedef void (PNGAPI *png_rw_ptr) PNGARG((png_structp, png_bytep, png_size_t));
 144.932 -typedef void (PNGAPI *png_flush_ptr) PNGARG((png_structp));
 144.933 -typedef void (PNGAPI *png_read_status_ptr) PNGARG((png_structp, png_uint_32,
 144.934 -   int));
 144.935 -typedef void (PNGAPI *png_write_status_ptr) PNGARG((png_structp, png_uint_32,
 144.936 -   int));
 144.937 +typedef PNG_CALLBACK(void, *png_error_ptr, (png_structp, png_const_charp));
 144.938 +typedef PNG_CALLBACK(void, *png_rw_ptr, (png_structp, png_bytep, png_size_t));
 144.939 +typedef PNG_CALLBACK(void, *png_flush_ptr, (png_structp));
 144.940 +typedef PNG_CALLBACK(void, *png_read_status_ptr, (png_structp, png_uint_32,
 144.941 +    int));
 144.942 +typedef PNG_CALLBACK(void, *png_write_status_ptr, (png_structp, png_uint_32,
 144.943 +    int));
 144.944  
 144.945  #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
 144.946 -typedef void (PNGAPI *png_progressive_info_ptr) PNGARG((png_structp, png_infop));
 144.947 -typedef void (PNGAPI *png_progressive_end_ptr) PNGARG((png_structp, png_infop));
 144.948 -typedef void (PNGAPI *png_progressive_row_ptr) PNGARG((png_structp, png_bytep,
 144.949 -   png_uint_32, int));
 144.950 +typedef PNG_CALLBACK(void, *png_progressive_info_ptr, (png_structp, png_infop));
 144.951 +typedef PNG_CALLBACK(void, *png_progressive_end_ptr, (png_structp, png_infop));
 144.952 +
 144.953 +/* The following callback receives png_uint_32 row_number, int pass for the
 144.954 + * png_bytep data of the row.  When transforming an interlaced image the
 144.955 + * row number is the row number within the sub-image of the interlace pass, so
 144.956 + * the value will increase to the height of the sub-image (not the full image)
 144.957 + * then reset to 0 for the next pass.
 144.958 + *
 144.959 + * Use PNG_ROW_FROM_PASS_ROW(row, pass) and PNG_COL_FROM_PASS_COL(col, pass) to
 144.960 + * find the output pixel (x,y) given an interlaced sub-image pixel
 144.961 + * (row,col,pass).  (See below for these macros.)
 144.962 + */
 144.963 +typedef PNG_CALLBACK(void, *png_progressive_row_ptr, (png_structp, png_bytep,
 144.964 +    png_uint_32, int));
 144.965  #endif
 144.966  
 144.967  #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
 144.968 -    defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
 144.969 -    defined(PNG_LEGACY_SUPPORTED)
 144.970 -typedef void (PNGAPI *png_user_transform_ptr) PNGARG((png_structp,
 144.971 -    png_row_infop, png_bytep));
 144.972 +    defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
 144.973 +typedef PNG_CALLBACK(void, *png_user_transform_ptr, (png_structp, png_row_infop,
 144.974 +    png_bytep));
 144.975  #endif
 144.976  
 144.977 -#if defined(PNG_USER_CHUNKS_SUPPORTED)
 144.978 -typedef int (PNGAPI *png_user_chunk_ptr) PNGARG((png_structp, png_unknown_chunkp));
 144.979 +#ifdef PNG_USER_CHUNKS_SUPPORTED
 144.980 +typedef PNG_CALLBACK(int, *png_user_chunk_ptr, (png_structp,
 144.981 +    png_unknown_chunkp));
 144.982  #endif
 144.983 -#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
 144.984 -typedef void (PNGAPI *png_unknown_chunk_ptr) PNGARG((png_structp));
 144.985 +#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
 144.986 +typedef PNG_CALLBACK(void, *png_unknown_chunk_ptr, (png_structp));
 144.987 +#endif
 144.988 +
 144.989 +#ifdef PNG_SETJMP_SUPPORTED
 144.990 +/* This must match the function definition in <setjmp.h>, and the application
 144.991 + * must include this before png.h to obtain the definition of jmp_buf.  The
 144.992 + * function is required to be PNG_NORETURN, but this is not checked.  If the
 144.993 + * function does return the application will crash via an abort() or similar
 144.994 + * system level call.
 144.995 + *
 144.996 + * If you get a warning here while building the library you may need to make
 144.997 + * changes to ensure that pnglibconf.h records the calling convention used by
 144.998 + * your compiler.  This may be very difficult - try using a different compiler
 144.999 + * to build the library!
144.1000 + */
144.1001 +PNG_FUNCTION(void, (PNGCAPI *png_longjmp_ptr), PNGARG((jmp_buf, int)), typedef);
144.1002  #endif
144.1003  
144.1004  /* Transform masks for the high-level interface */
144.1005 @@ -1122,667 +924,653 @@
144.1006  #define PNG_TRANSFORM_SWAP_ALPHA     0x0100    /* read and write */
144.1007  #define PNG_TRANSFORM_SWAP_ENDIAN    0x0200    /* read and write */
144.1008  #define PNG_TRANSFORM_INVERT_ALPHA   0x0400    /* read and write */
144.1009 -#define PNG_TRANSFORM_STRIP_FILLER   0x0800    /* WRITE only */
144.1010 +#define PNG_TRANSFORM_STRIP_FILLER   0x0800    /* write only */
144.1011 +/* Added to libpng-1.2.34 */
144.1012 +#define PNG_TRANSFORM_STRIP_FILLER_BEFORE PNG_TRANSFORM_STRIP_FILLER
144.1013 +#define PNG_TRANSFORM_STRIP_FILLER_AFTER 0x1000 /* write only */
144.1014 +/* Added to libpng-1.4.0 */
144.1015 +#define PNG_TRANSFORM_GRAY_TO_RGB   0x2000      /* read only */
144.1016 +/* Added to libpng-1.5.4 */
144.1017 +#define PNG_TRANSFORM_EXPAND_16     0x4000      /* read only */
144.1018 +#define PNG_TRANSFORM_SCALE_16      0x8000      /* read only */
144.1019  
144.1020  /* Flags for MNG supported features */
144.1021  #define PNG_FLAG_MNG_EMPTY_PLTE     0x01
144.1022  #define PNG_FLAG_MNG_FILTER_64      0x04
144.1023  #define PNG_ALL_MNG_FEATURES        0x05
144.1024  
144.1025 -typedef png_voidp (*png_malloc_ptr) PNGARG((png_structp, png_size_t));
144.1026 -typedef void (*png_free_ptr) PNGARG((png_structp, png_voidp));
144.1027 -
144.1028 -/* The structure that holds the information to read and write PNG files.
144.1029 - * The only people who need to care about what is inside of this are the
144.1030 - * people who will be modifying the library for their own special needs.
144.1031 - * It should NOT be accessed directly by an application, except to store
144.1032 - * the jmp_buf.
144.1033 +/* NOTE: prior to 1.5 these functions had no 'API' style declaration,
144.1034 + * this allowed the zlib default functions to be used on Windows
144.1035 + * platforms.  In 1.5 the zlib default malloc (which just calls malloc and
144.1036 + * ignores the first argument) should be completely compatible with the
144.1037 + * following.
144.1038   */
144.1039 -
144.1040 -struct png_struct_def
144.1041 -{
144.1042 -#ifdef PNG_SETJMP_SUPPORTED
144.1043 -   jmp_buf jmpbuf;            /* used in png_error */
144.1044 -#endif
144.1045 -   png_error_ptr error_fn;    /* function for printing errors and aborting */
144.1046 -   png_error_ptr warning_fn;  /* function for printing warnings */
144.1047 -   png_voidp error_ptr;       /* user supplied struct for error functions */
144.1048 -   png_rw_ptr write_data_fn;  /* function for writing output data */
144.1049 -   png_rw_ptr read_data_fn;   /* function for reading input data */
144.1050 -   png_voidp io_ptr;          /* ptr to application struct for I/O functions */
144.1051 -
144.1052 -#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
144.1053 -   png_user_transform_ptr read_user_transform_fn; /* user read transform */
144.1054 -#endif
144.1055 -
144.1056 -#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
144.1057 -   png_user_transform_ptr write_user_transform_fn; /* user write transform */
144.1058 -#endif
144.1059 -
144.1060 -/* These were added in libpng-1.0.2 */
144.1061 -#if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
144.1062 -#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
144.1063 -    defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
144.1064 -   png_voidp user_transform_ptr; /* user supplied struct for user transform */
144.1065 -   png_byte user_transform_depth;    /* bit depth of user transformed pixels */
144.1066 -   png_byte user_transform_channels; /* channels in user transformed pixels */
144.1067 -#endif
144.1068 -#endif
144.1069 -
144.1070 -   png_uint_32 mode;          /* tells us where we are in the PNG file */
144.1071 -   png_uint_32 flags;         /* flags indicating various things to libpng */
144.1072 -   png_uint_32 transformations; /* which transformations to perform */
144.1073 -
144.1074 -   z_stream zstream;          /* pointer to decompression structure (below) */
144.1075 -   png_bytep zbuf;            /* buffer for zlib */
144.1076 -   png_size_t zbuf_size;      /* size of zbuf */
144.1077 -   int zlib_level;            /* holds zlib compression level */
144.1078 -   int zlib_method;           /* holds zlib compression method */
144.1079 -   int zlib_window_bits;      /* holds zlib compression window bits */
144.1080 -   int zlib_mem_level;        /* holds zlib compression memory level */
144.1081 -   int zlib_strategy;         /* holds zlib compression strategy */
144.1082 -
144.1083 -   png_uint_32 width;         /* width of image in pixels */
144.1084 -   png_uint_32 height;        /* height of image in pixels */
144.1085 -   png_uint_32 num_rows;      /* number of rows in current pass */
144.1086 -   png_uint_32 usr_width;     /* width of row at start of write */
144.1087 -   png_uint_32 rowbytes;      /* size of row in bytes */
144.1088 -   png_uint_32 irowbytes;     /* size of current interlaced row in bytes */
144.1089 -   png_uint_32 iwidth;        /* width of current interlaced row in pixels */
144.1090 -   png_uint_32 row_number;    /* current row in interlace pass */
144.1091 -   png_bytep prev_row;        /* buffer to save previous (unfiltered) row */
144.1092 -   png_bytep row_buf;         /* buffer to save current (unfiltered) row */
144.1093 -   png_bytep sub_row;         /* buffer to save "sub" row when filtering */
144.1094 -   png_bytep up_row;          /* buffer to save "up" row when filtering */
144.1095 -   png_bytep avg_row;         /* buffer to save "avg" row when filtering */
144.1096 -   png_bytep paeth_row;       /* buffer to save "Paeth" row when filtering */
144.1097 -   png_row_info row_info;     /* used for transformation routines */
144.1098 -
144.1099 -   png_uint_32 idat_size;     /* current IDAT size for read */
144.1100 -   png_uint_32 crc;           /* current chunk CRC value */
144.1101 -   png_colorp palette;        /* palette from the input file */
144.1102 -   png_uint_16 num_palette;   /* number of color entries in palette */
144.1103 -   png_uint_16 num_trans;     /* number of transparency values */
144.1104 -   png_byte chunk_name[5];    /* null-terminated name of current chunk */
144.1105 -   png_byte compression;      /* file compression type (always 0) */
144.1106 -   png_byte filter;           /* file filter type (always 0) */
144.1107 -   png_byte interlaced;       /* PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
144.1108 -   png_byte pass;             /* current interlace pass (0 - 6) */
144.1109 -   png_byte do_filter;        /* row filter flags (see PNG_FILTER_ below ) */
144.1110 -   png_byte color_type;       /* color type of file */
144.1111 -   png_byte bit_depth;        /* bit depth of file */
144.1112 -   png_byte usr_bit_depth;    /* bit depth of users row */
144.1113 -   png_byte pixel_depth;      /* number of bits per pixel */
144.1114 -   png_byte channels;         /* number of channels in file */
144.1115 -   png_byte usr_channels;     /* channels at start of write */
144.1116 -   png_byte sig_bytes;        /* magic bytes read/written from start of file */
144.1117 -
144.1118 -#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
144.1119 -#ifdef PNG_LEGACY_SUPPORTED
144.1120 -   png_byte filler;           /* filler byte for pixel expansion */
144.1121 -#else
144.1122 -   png_uint_16 filler;           /* filler bytes for pixel expansion */
144.1123 -#endif
144.1124 -#endif
144.1125 -
144.1126 -#if defined(PNG_bKGD_SUPPORTED)
144.1127 -   png_byte background_gamma_type;
144.1128 -#  ifdef PNG_FLOATING_POINT_SUPPORTED
144.1129 -   float background_gamma;
144.1130 -#  endif
144.1131 -   png_color_16 background;   /* background color in screen gamma space */
144.1132 -#if defined(PNG_READ_GAMMA_SUPPORTED)
144.1133 -   png_color_16 background_1; /* background normalized to gamma 1.0 */
144.1134 -#endif
144.1135 -#endif /* PNG_bKGD_SUPPORTED */
144.1136 -
144.1137 -#if defined(PNG_WRITE_FLUSH_SUPPORTED)
144.1138 -   png_flush_ptr output_flush_fn;/* Function for flushing output */
144.1139 -   png_uint_32 flush_dist;    /* how many rows apart to flush, 0 - no flush */
144.1140 -   png_uint_32 flush_rows;    /* number of rows written since last flush */
144.1141 -#endif
144.1142 -
144.1143 -#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
144.1144 -   int gamma_shift;      /* number of "insignificant" bits 16-bit gamma */
144.1145 -#ifdef PNG_FLOATING_POINT_SUPPORTED
144.1146 -   float gamma;          /* file gamma value */
144.1147 -   float screen_gamma;   /* screen gamma value (display_exponent) */
144.1148 -#endif
144.1149 -#endif
144.1150 -
144.1151 -#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
144.1152 -   png_bytep gamma_table;     /* gamma table for 8-bit depth files */
144.1153 -   png_bytep gamma_from_1;    /* converts from 1.0 to screen */
144.1154 -   png_bytep gamma_to_1;      /* converts from file to 1.0 */
144.1155 -   png_uint_16pp gamma_16_table; /* gamma table for 16-bit depth files */
144.1156 -   png_uint_16pp gamma_16_from_1; /* converts from 1.0 to screen */
144.1157 -   png_uint_16pp gamma_16_to_1; /* converts from file to 1.0 */
144.1158 -#endif
144.1159 -
144.1160 -#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_sBIT_SUPPORTED)
144.1161 -   png_color_8 sig_bit;       /* significant bits in each available channel */
144.1162 -#endif
144.1163 -
144.1164 -#if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
144.1165 -   png_color_8 shift;         /* shift for significant bit tranformation */
144.1166 -#endif
144.1167 -
144.1168 -#if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) \
144.1169 - || defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
144.1170 -   png_bytep trans;           /* transparency values for paletted files */
144.1171 -   png_color_16 trans_values; /* transparency values for non-paletted files */
144.1172 -#endif
144.1173 -
144.1174 -   png_read_status_ptr read_row_fn;   /* called after each row is decoded */
144.1175 -   png_write_status_ptr write_row_fn; /* called after each row is encoded */
144.1176 -#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
144.1177 -   png_progressive_info_ptr info_fn; /* called after header data fully read */
144.1178 -   png_progressive_row_ptr row_fn;   /* called after each prog. row is decoded */
144.1179 -   png_progressive_end_ptr end_fn;   /* called after image is complete */
144.1180 -   png_bytep save_buffer_ptr;        /* current location in save_buffer */
144.1181 -   png_bytep save_buffer;            /* buffer for previously read data */
144.1182 -   png_bytep current_buffer_ptr;     /* current location in current_buffer */
144.1183 -   png_bytep current_buffer;         /* buffer for recently used data */
144.1184 -   png_uint_32 push_length;          /* size of current input chunk */
144.1185 -   png_uint_32 skip_length;          /* bytes to skip in input data */
144.1186 -   png_size_t save_buffer_size;      /* amount of data now in save_buffer */
144.1187 -   png_size_t save_buffer_max;       /* total size of save_buffer */
144.1188 -   png_size_t buffer_size;           /* total amount of available input data */
144.1189 -   png_size_t current_buffer_size;   /* amount of data now in current_buffer */
144.1190 -   int process_mode;                 /* what push library is currently doing */
144.1191 -   int cur_palette;                  /* current push library palette index */
144.1192 -
144.1193 -#  if defined(PNG_TEXT_SUPPORTED)
144.1194 -     png_size_t current_text_size;   /* current size of text input data */
144.1195 -     png_size_t current_text_left;   /* how much text left to read in input */
144.1196 -     png_charp current_text;         /* current text chunk buffer */
144.1197 -     png_charp current_text_ptr;     /* current location in current_text */
144.1198 -#  endif /* PNG_PROGRESSIVE_READ_SUPPORTED && PNG_TEXT_SUPPORTED */
144.1199 -
144.1200 -#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
144.1201 -
144.1202 -#if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
144.1203 -/* for the Borland special 64K segment handler */
144.1204 -   png_bytepp offset_table_ptr;
144.1205 -   png_bytep offset_table;
144.1206 -   png_uint_16 offset_table_number;
144.1207 -   png_uint_16 offset_table_count;
144.1208 -   png_uint_16 offset_table_count_free;
144.1209 -#endif
144.1210 -
144.1211 -#if defined(PNG_READ_DITHER_SUPPORTED)
144.1212 -   png_bytep palette_lookup;         /* lookup table for dithering */
144.1213 -   png_bytep dither_index;           /* index translation for palette files */
144.1214 -#endif
144.1215 -
144.1216 -#if defined(PNG_READ_DITHER_SUPPORTED) || defined(PNG_hIST_SUPPORTED)
144.1217 -   png_uint_16p hist;                /* histogram */
144.1218 -#endif
144.1219 -
144.1220 -#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
144.1221 -   png_byte heuristic_method;        /* heuristic for row filter selection */
144.1222 -   png_byte num_prev_filters;        /* number of weights for previous rows */
144.1223 -   png_bytep prev_filters;           /* filter type(s) of previous row(s) */
144.1224 -   png_uint_16p filter_weights;      /* weight(s) for previous line(s) */
144.1225 -   png_uint_16p inv_filter_weights;  /* 1/weight(s) for previous line(s) */
144.1226 -   png_uint_16p filter_costs;        /* relative filter calculation cost */
144.1227 -   png_uint_16p inv_filter_costs;    /* 1/relative filter calculation cost */
144.1228 -#endif
144.1229 -
144.1230 -#if defined(PNG_TIME_RFC1123_SUPPORTED)
144.1231 -   png_charp time_buffer;            /* String to hold RFC 1123 time text */
144.1232 -#endif
144.1233 -
144.1234 -/* New members added in libpng-1.0.6 */
144.1235 -
144.1236 -#ifdef PNG_FREE_ME_SUPPORTED
144.1237 -   png_uint_32 free_me;       /* flags items libpng is responsible for freeing */
144.1238 -#endif
144.1239 -
144.1240 -#if defined(PNG_USER_CHUNKS_SUPPORTED)
144.1241 -   png_voidp user_chunk_ptr;
144.1242 -   png_user_chunk_ptr read_user_chunk_fn; /* user read chunk handler */
144.1243 -#endif
144.1244 -
144.1245 -#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
144.1246 -   int num_chunk_list;
144.1247 -   png_bytep chunk_list;
144.1248 -#endif
144.1249 -
144.1250 -/* New members added in libpng-1.0.3 */
144.1251 -#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
144.1252 -   png_byte rgb_to_gray_status;
144.1253 -   /* These were changed from png_byte in libpng-1.0.6 */
144.1254 -   png_uint_16 rgb_to_gray_red_coeff;
144.1255 -   png_uint_16 rgb_to_gray_green_coeff;
144.1256 -   png_uint_16 rgb_to_gray_blue_coeff;
144.1257 -#endif
144.1258 -
144.1259 -/* New member added in libpng-1.0.4 (renamed in 1.0.9) */
144.1260 -#if defined(PNG_MNG_FEATURES_SUPPORTED) || \
144.1261 -    defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
144.1262 -    defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
144.1263 -/* changed from png_byte to png_uint_32 at version 1.2.0 */
144.1264 -#ifdef PNG_1_0_X
144.1265 -   png_byte mng_features_permitted;
144.1266 -#else
144.1267 -   png_uint_32 mng_features_permitted;
144.1268 -#endif /* PNG_1_0_X */
144.1269 -#endif
144.1270 -
144.1271 -/* New member added in libpng-1.0.7 */
144.1272 -#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
144.1273 -   png_fixed_point int_gamma;
144.1274 -#endif
144.1275 -
144.1276 -/* New member added in libpng-1.0.9, ifdef'ed out in 1.0.12, enabled in 1.2.0 */
144.1277 -#if defined(PNG_MNG_FEATURES_SUPPORTED)
144.1278 -   png_byte filter_type;
144.1279 -#endif
144.1280 -
144.1281 -#if defined(PNG_1_0_X) || (defined(PNG_DEBUG) && defined(PNG_USE_PNGGCCRD))
144.1282 -/* New member added in libpng-1.0.10, ifdef'ed out in 1.2.0 */
144.1283 -   png_uint_32 row_buf_size;
144.1284 -#endif
144.1285 -
144.1286 -/* New members added in libpng-1.2.0 */
144.1287 -#if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
144.1288 -#  if !defined(PNG_1_0_X)
144.1289 -#    if defined(PNG_MMX_CODE_SUPPORTED)
144.1290 -   png_byte     mmx_bitdepth_threshold;
144.1291 -   png_uint_32  mmx_rowbytes_threshold;
144.1292 -#    endif
144.1293 -   png_uint_32  asm_flags;
144.1294 -#  endif
144.1295 -#endif
144.1296 -
144.1297 -/* New members added in libpng-1.0.2 but first enabled by default in 1.2.0 */
144.1298 -#ifdef PNG_USER_MEM_SUPPORTED
144.1299 -   png_voidp mem_ptr;                /* user supplied struct for mem functions */
144.1300 -   png_malloc_ptr malloc_fn;         /* function for allocating memory */
144.1301 -   png_free_ptr free_fn;             /* function for freeing memory */
144.1302 -#endif
144.1303 -
144.1304 -/* New member added in libpng-1.0.13 and 1.2.0 */
144.1305 -   png_bytep big_row_buf;         /* buffer to save current (unfiltered) row */
144.1306 -
144.1307 -#if defined(PNG_READ_DITHER_SUPPORTED)
144.1308 -/* The following three members were added at version 1.0.14 and 1.2.4 */
144.1309 -   png_bytep dither_sort;            /* working sort array */
144.1310 -   png_bytep index_to_palette;       /* where the original index currently is */
144.1311 -                                     /* in the palette */
144.1312 -   png_bytep palette_to_index;       /* which original index points to this */
144.1313 -                                     /* palette color */
144.1314 -#endif
144.1315 -
144.1316 -/* New members added in libpng-1.0.16 and 1.2.6 */
144.1317 -   png_byte compression_type;
144.1318 -
144.1319 -#ifdef PNG_SET_USER_LIMITS_SUPPORTED
144.1320 -   png_uint_32 user_width_max;
144.1321 -   png_uint_32 user_height_max;
144.1322 -#endif
144.1323 -
144.1324 -/* New member added in libpng-1.0.25 and 1.2.17 */
144.1325 -#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
144.1326 -   /* storage for unknown chunk that the library doesn't recognize. */
144.1327 -   png_unknown_chunk unknown_chunk;
144.1328 -#endif
144.1329 -};
144.1330 -
144.1331 -
144.1332 -/* This triggers a compiler error in png.c, if png.c and png.h
144.1333 - * do not agree upon the version number.
144.1334 - */
144.1335 -typedef png_structp version_1_2_18;
144.1336 +typedef PNG_CALLBACK(png_voidp, *png_malloc_ptr, (png_structp,
144.1337 +    png_alloc_size_t));
144.1338 +typedef PNG_CALLBACK(void, *png_free_ptr, (png_structp, png_voidp));
144.1339  
144.1340  typedef png_struct FAR * FAR * png_structpp;
144.1341  
144.1342 -/* Here are the function definitions most commonly used.  This is not
144.1343 - * the place to find out how to use libpng.  See libpng.txt for the
144.1344 +/* Section 3: exported functions
144.1345 + * Here are the function definitions most commonly used.  This is not
144.1346 + * the place to find out how to use libpng.  See libpng-manual.txt for the
144.1347   * full explanation, see example.c for the summary.  This just provides
144.1348   * a simple one line description of the use of each function.
144.1349 + *
144.1350 + * The PNG_EXPORT() and PNG_EXPORTA() macros used below are defined in
144.1351 + * pngconf.h and in the *.dfn files in the scripts directory.
144.1352 + *
144.1353 + *   PNG_EXPORT(ordinal, type, name, (args));
144.1354 + *
144.1355 + *       ordinal:    ordinal that is used while building
144.1356 + *                   *.def files. The ordinal value is only
144.1357 + *                   relevant when preprocessing png.h with
144.1358 + *                   the *.dfn files for building symbol table
144.1359 + *                   entries, and are removed by pngconf.h.
144.1360 + *       type:       return type of the function
144.1361 + *       name:       function name
144.1362 + *       args:       function arguments, with types
144.1363 + *
144.1364 + * When we wish to append attributes to a function prototype we use
144.1365 + * the PNG_EXPORTA() macro instead.
144.1366 + *
144.1367 + *   PNG_EXPORTA(ordinal, type, name, (args), attributes);
144.1368 + *
144.1369 + *       ordinal, type, name, and args: same as in PNG_EXPORT().
144.1370 + *       attributes: function attributes
144.1371   */
144.1372  
144.1373  /* Returns the version number of the library */
144.1374 -extern PNG_EXPORT(png_uint_32,png_access_version_number) PNGARG((void));
144.1375 +PNG_EXPORT(1, png_uint_32, png_access_version_number, (void));
144.1376  
144.1377  /* Tell lib we have already handled the first <num_bytes> magic bytes.
144.1378   * Handling more than 8 bytes from the beginning of the file is an error.
144.1379   */
144.1380 -extern PNG_EXPORT(void,png_set_sig_bytes) PNGARG((png_structp png_ptr,
144.1381 -   int num_bytes));
144.1382 +PNG_EXPORT(2, void, png_set_sig_bytes, (png_structp png_ptr, int num_bytes));
144.1383  
144.1384  /* Check sig[start] through sig[start + num_to_check - 1] to see if it's a
144.1385   * PNG file.  Returns zero if the supplied bytes match the 8-byte PNG
144.1386   * signature, and non-zero otherwise.  Having num_to_check == 0 or
144.1387   * start > 7 will always fail (ie return non-zero).
144.1388   */
144.1389 -extern PNG_EXPORT(int,png_sig_cmp) PNGARG((png_bytep sig, png_size_t start,
144.1390 -   png_size_t num_to_check));
144.1391 +PNG_EXPORT(3, int, png_sig_cmp, (png_const_bytep sig, png_size_t start,
144.1392 +    png_size_t num_to_check));
144.1393  
144.1394  /* Simple signature checking function.  This is the same as calling
144.1395   * png_check_sig(sig, n) := !png_sig_cmp(sig, 0, n).
144.1396   */
144.1397 -extern PNG_EXPORT(int,png_check_sig) PNGARG((png_bytep sig, int num));
144.1398 +#define png_check_sig(sig, n) !png_sig_cmp((sig), 0, (n))
144.1399  
144.1400  /* Allocate and initialize png_ptr struct for reading, and any other memory. */
144.1401 -extern PNG_EXPORT(png_structp,png_create_read_struct)
144.1402 -   PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
144.1403 -   png_error_ptr error_fn, png_error_ptr warn_fn));
144.1404 +PNG_EXPORTA(4, png_structp, png_create_read_struct,
144.1405 +    (png_const_charp user_png_ver, png_voidp error_ptr,
144.1406 +    png_error_ptr error_fn, png_error_ptr warn_fn),
144.1407 +    PNG_ALLOCATED);
144.1408  
144.1409  /* Allocate and initialize png_ptr struct for writing, and any other memory */
144.1410 -extern PNG_EXPORT(png_structp,png_create_write_struct)
144.1411 -   PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
144.1412 -   png_error_ptr error_fn, png_error_ptr warn_fn));
144.1413 +PNG_EXPORTA(5, png_structp, png_create_write_struct,
144.1414 +    (png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn,
144.1415 +    png_error_ptr warn_fn),
144.1416 +    PNG_ALLOCATED);
144.1417  
144.1418 -#ifdef PNG_WRITE_SUPPORTED
144.1419 -extern PNG_EXPORT(png_uint_32,png_get_compression_buffer_size)
144.1420 -   PNGARG((png_structp png_ptr));
144.1421 +PNG_EXPORT(6, png_size_t, png_get_compression_buffer_size,
144.1422 +    (png_const_structp png_ptr));
144.1423 +
144.1424 +PNG_EXPORT(7, void, png_set_compression_buffer_size, (png_structp png_ptr,
144.1425 +    png_size_t size));
144.1426 +
144.1427 +/* Moved from pngconf.h in 1.4.0 and modified to ensure setjmp/longjmp
144.1428 + * match up.
144.1429 + */
144.1430 +#ifdef PNG_SETJMP_SUPPORTED
144.1431 +/* This function returns the jmp_buf built in to *png_ptr.  It must be
144.1432 + * supplied with an appropriate 'longjmp' function to use on that jmp_buf
144.1433 + * unless the default error function is overridden in which case NULL is
144.1434 + * acceptable.  The size of the jmp_buf is checked against the actual size
144.1435 + * allocated by the library - the call will return NULL on a mismatch
144.1436 + * indicating an ABI mismatch.
144.1437 + */
144.1438 +PNG_EXPORT(8, jmp_buf*, png_set_longjmp_fn, (png_structp png_ptr,
144.1439 +    png_longjmp_ptr longjmp_fn, size_t jmp_buf_size));
144.1440 +#  define png_jmpbuf(png_ptr) \
144.1441 +      (*png_set_longjmp_fn((png_ptr), longjmp, sizeof (jmp_buf)))
144.1442 +#else
144.1443 +#  define png_jmpbuf(png_ptr) \
144.1444 +      (LIBPNG_WAS_COMPILED_WITH__PNG_NO_SETJMP)
144.1445  #endif
144.1446 +/* This function should be used by libpng applications in place of
144.1447 + * longjmp(png_ptr->jmpbuf, val).  If longjmp_fn() has been set, it
144.1448 + * will use it; otherwise it will call PNG_ABORT().  This function was
144.1449 + * added in libpng-1.5.0.
144.1450 + */
144.1451 +PNG_EXPORTA(9, void, png_longjmp, (png_structp png_ptr, int val),
144.1452 +    PNG_NORETURN);
144.1453  
144.1454 -#ifdef PNG_WRITE_SUPPORTED
144.1455 -extern PNG_EXPORT(void,png_set_compression_buffer_size)
144.1456 -   PNGARG((png_structp png_ptr, png_uint_32 size));
144.1457 +#ifdef PNG_READ_SUPPORTED
144.1458 +/* Reset the compression stream */
144.1459 +PNG_EXPORT(10, int, png_reset_zstream, (png_structp png_ptr));
144.1460  #endif
144.1461  
144.1462 -/* Reset the compression stream */
144.1463 -extern PNG_EXPORT(int,png_reset_zstream) PNGARG((png_structp png_ptr));
144.1464 -
144.1465  /* New functions added in libpng-1.0.2 (not enabled by default until 1.2.0) */
144.1466  #ifdef PNG_USER_MEM_SUPPORTED
144.1467 -extern PNG_EXPORT(png_structp,png_create_read_struct_2)
144.1468 -   PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
144.1469 -   png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
144.1470 -   png_malloc_ptr malloc_fn, png_free_ptr free_fn));
144.1471 -extern PNG_EXPORT(png_structp,png_create_write_struct_2)
144.1472 -   PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
144.1473 -   png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
144.1474 -   png_malloc_ptr malloc_fn, png_free_ptr free_fn));
144.1475 +PNG_EXPORTA(11, png_structp, png_create_read_struct_2,
144.1476 +    (png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn,
144.1477 +    png_error_ptr warn_fn,
144.1478 +    png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn),
144.1479 +    PNG_ALLOCATED);
144.1480 +PNG_EXPORTA(12, png_structp, png_create_write_struct_2,
144.1481 +    (png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn,
144.1482 +    png_error_ptr warn_fn,
144.1483 +    png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn),
144.1484 +    PNG_ALLOCATED);
144.1485  #endif
144.1486  
144.1487 +/* Write the PNG file signature. */
144.1488 +PNG_EXPORT(13, void, png_write_sig, (png_structp png_ptr));
144.1489 +
144.1490  /* Write a PNG chunk - size, type, (optional) data, CRC. */
144.1491 -extern PNG_EXPORT(void,png_write_chunk) PNGARG((png_structp png_ptr,
144.1492 -   png_bytep chunk_name, png_bytep data, png_size_t length));
144.1493 +PNG_EXPORT(14, void, png_write_chunk, (png_structp png_ptr, png_const_bytep
144.1494 +    chunk_name, png_const_bytep data, png_size_t length));
144.1495  
144.1496  /* Write the start of a PNG chunk - length and chunk name. */
144.1497 -extern PNG_EXPORT(void,png_write_chunk_start) PNGARG((png_structp png_ptr,
144.1498 -   png_bytep chunk_name, png_uint_32 length));
144.1499 +PNG_EXPORT(15, void, png_write_chunk_start, (png_structp png_ptr,
144.1500 +    png_const_bytep chunk_name, png_uint_32 length));
144.1501  
144.1502  /* Write the data of a PNG chunk started with png_write_chunk_start(). */
144.1503 -extern PNG_EXPORT(void,png_write_chunk_data) PNGARG((png_structp png_ptr,
144.1504 -   png_bytep data, png_size_t length));
144.1505 +PNG_EXPORT(16, void, png_write_chunk_data, (png_structp png_ptr,
144.1506 +    png_const_bytep data, png_size_t length));
144.1507  
144.1508  /* Finish a chunk started with png_write_chunk_start() (includes CRC). */
144.1509 -extern PNG_EXPORT(void,png_write_chunk_end) PNGARG((png_structp png_ptr));
144.1510 +PNG_EXPORT(17, void, png_write_chunk_end, (png_structp png_ptr));
144.1511  
144.1512  /* Allocate and initialize the info structure */
144.1513 -extern PNG_EXPORT(png_infop,png_create_info_struct)
144.1514 -   PNGARG((png_structp png_ptr));
144.1515 +PNG_EXPORTA(18, png_infop, png_create_info_struct, (png_structp png_ptr),
144.1516 +    PNG_ALLOCATED);
144.1517  
144.1518 -#if defined(PNG_1_0_X) || defined (PNG_1_2_X)
144.1519 -/* Initialize the info structure (old interface - DEPRECATED) */
144.1520 -extern PNG_EXPORT(void,png_info_init) PNGARG((png_infop info_ptr));
144.1521 -#undef png_info_init
144.1522 -#define png_info_init(info_ptr) png_info_init_3(&info_ptr,\
144.1523 -    png_sizeof(png_info));
144.1524 -#endif
144.1525 -
144.1526 -extern PNG_EXPORT(void,png_info_init_3) PNGARG((png_infopp info_ptr,
144.1527 +PNG_EXPORT(19, void, png_info_init_3, (png_infopp info_ptr,
144.1528      png_size_t png_info_struct_size));
144.1529  
144.1530  /* Writes all the PNG information before the image. */
144.1531 -extern PNG_EXPORT(void,png_write_info_before_PLTE) PNGARG((png_structp png_ptr,
144.1532 -   png_infop info_ptr));
144.1533 -extern PNG_EXPORT(void,png_write_info) PNGARG((png_structp png_ptr,
144.1534 -   png_infop info_ptr));
144.1535 +PNG_EXPORT(20, void, png_write_info_before_PLTE,
144.1536 +    (png_structp png_ptr, png_infop info_ptr));
144.1537 +PNG_EXPORT(21, void, png_write_info,
144.1538 +    (png_structp png_ptr, png_infop info_ptr));
144.1539  
144.1540 -#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
144.1541 -/* read the information before the actual image data. */
144.1542 -extern PNG_EXPORT(void,png_read_info) PNGARG((png_structp png_ptr,
144.1543 -   png_infop info_ptr));
144.1544 +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
144.1545 +/* Read the information before the actual image data. */
144.1546 +PNG_EXPORT(22, void, png_read_info,
144.1547 +    (png_structp png_ptr, png_infop info_ptr));
144.1548  #endif
144.1549  
144.1550 -#if defined(PNG_TIME_RFC1123_SUPPORTED)
144.1551 -extern PNG_EXPORT(png_charp,png_convert_to_rfc1123)
144.1552 -   PNGARG((png_structp png_ptr, png_timep ptime));
144.1553 +#ifdef PNG_TIME_RFC1123_SUPPORTED
144.1554 +PNG_EXPORT(23, png_const_charp, png_convert_to_rfc1123,
144.1555 +    (png_structp png_ptr,
144.1556 +    png_const_timep ptime));
144.1557  #endif
144.1558  
144.1559 -#if !defined(_WIN32_WCE)
144.1560 -/* "time.h" functions are not supported on WindowsCE */
144.1561 -#if defined(PNG_WRITE_tIME_SUPPORTED)
144.1562 -/* convert from a struct tm to png_time */
144.1563 -extern PNG_EXPORT(void,png_convert_from_struct_tm) PNGARG((png_timep ptime,
144.1564 -   struct tm FAR * ttime));
144.1565 +#ifdef PNG_CONVERT_tIME_SUPPORTED
144.1566 +/* Convert from a struct tm to png_time */
144.1567 +PNG_EXPORT(24, void, png_convert_from_struct_tm, (png_timep ptime,
144.1568 +    PNG_CONST struct tm FAR * ttime));
144.1569  
144.1570 -/* convert from time_t to png_time.  Uses gmtime() */
144.1571 -extern PNG_EXPORT(void,png_convert_from_time_t) PNGARG((png_timep ptime,
144.1572 -   time_t ttime));
144.1573 -#endif /* PNG_WRITE_tIME_SUPPORTED */
144.1574 -#endif /* _WIN32_WCE */
144.1575 +/* Convert from time_t to png_time.  Uses gmtime() */
144.1576 +PNG_EXPORT(25, void, png_convert_from_time_t,
144.1577 +    (png_timep ptime, time_t ttime));
144.1578 +#endif /* PNG_CONVERT_tIME_SUPPORTED */
144.1579  
144.1580 -#if defined(PNG_READ_EXPAND_SUPPORTED)
144.1581 +#ifdef PNG_READ_EXPAND_SUPPORTED
144.1582  /* Expand data to 24-bit RGB, or 8-bit grayscale, with alpha if available. */
144.1583 -extern PNG_EXPORT(void,png_set_expand) PNGARG((png_structp png_ptr));
144.1584 -#if !defined(PNG_1_0_X)
144.1585 -extern PNG_EXPORT(void,png_set_expand_gray_1_2_4_to_8) PNGARG((png_structp
144.1586 -  png_ptr));
144.1587 +PNG_EXPORT(26, void, png_set_expand, (png_structp png_ptr));
144.1588 +PNG_EXPORT(27, void, png_set_expand_gray_1_2_4_to_8, (png_structp png_ptr));
144.1589 +PNG_EXPORT(28, void, png_set_palette_to_rgb, (png_structp png_ptr));
144.1590 +PNG_EXPORT(29, void, png_set_tRNS_to_alpha, (png_structp png_ptr));
144.1591  #endif
144.1592 -extern PNG_EXPORT(void,png_set_palette_to_rgb) PNGARG((png_structp png_ptr));
144.1593 -extern PNG_EXPORT(void,png_set_tRNS_to_alpha) PNGARG((png_structp png_ptr));
144.1594 -#if defined(PNG_1_0_X) || defined (PNG_1_2_X)
144.1595 -/* Deprecated */
144.1596 -extern PNG_EXPORT(void,png_set_gray_1_2_4_to_8) PNGARG((png_structp png_ptr));
144.1597 -#endif
144.1598 +
144.1599 +#ifdef PNG_READ_EXPAND_16_SUPPORTED
144.1600 +/* Expand to 16-bit channels, forces conversion of palette to RGB and expansion
144.1601 + * of a tRNS chunk if present.
144.1602 + */
144.1603 +PNG_EXPORT(221, void, png_set_expand_16, (png_structp png_ptr));
144.1604  #endif
144.1605  
144.1606  #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
144.1607  /* Use blue, green, red order for pixels. */
144.1608 -extern PNG_EXPORT(void,png_set_bgr) PNGARG((png_structp png_ptr));
144.1609 +PNG_EXPORT(30, void, png_set_bgr, (png_structp png_ptr));
144.1610  #endif
144.1611  
144.1612 -#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
144.1613 +#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
144.1614  /* Expand the grayscale to 24-bit RGB if necessary. */
144.1615 -extern PNG_EXPORT(void,png_set_gray_to_rgb) PNGARG((png_structp png_ptr));
144.1616 +PNG_EXPORT(31, void, png_set_gray_to_rgb, (png_structp png_ptr));
144.1617  #endif
144.1618  
144.1619 -#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
144.1620 +#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
144.1621  /* Reduce RGB to grayscale. */
144.1622 -#ifdef PNG_FLOATING_POINT_SUPPORTED
144.1623 -extern PNG_EXPORT(void,png_set_rgb_to_gray) PNGARG((png_structp png_ptr,
144.1624 -   int error_action, double red, double green ));
144.1625 -#endif
144.1626 -extern PNG_EXPORT(void,png_set_rgb_to_gray_fixed) PNGARG((png_structp png_ptr,
144.1627 -   int error_action, png_fixed_point red, png_fixed_point green ));
144.1628 -extern PNG_EXPORT(png_byte,png_get_rgb_to_gray_status) PNGARG((png_structp
144.1629 -   png_ptr));
144.1630 +PNG_FP_EXPORT(32, void, png_set_rgb_to_gray, (png_structp png_ptr,
144.1631 +    int error_action, double red, double green));
144.1632 +PNG_FIXED_EXPORT(33, void, png_set_rgb_to_gray_fixed, (png_structp png_ptr,
144.1633 +    int error_action, png_fixed_point red, png_fixed_point green));
144.1634 +
144.1635 +PNG_EXPORT(34, png_byte, png_get_rgb_to_gray_status, (png_const_structp
144.1636 +    png_ptr));
144.1637  #endif
144.1638  
144.1639 -extern PNG_EXPORT(void,png_build_grayscale_palette) PNGARG((int bit_depth,
144.1640 -   png_colorp palette));
144.1641 +#ifdef PNG_BUILD_GRAYSCALE_PALETTE_SUPPORTED
144.1642 +PNG_EXPORT(35, void, png_build_grayscale_palette, (int bit_depth,
144.1643 +    png_colorp palette));
144.1644 +#endif
144.1645  
144.1646 -#if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
144.1647 -extern PNG_EXPORT(void,png_set_strip_alpha) PNGARG((png_structp png_ptr));
144.1648 +#ifdef PNG_READ_ALPHA_MODE_SUPPORTED
144.1649 +/* How the alpha channel is interpreted - this affects how the color channels of
144.1650 + * a PNG file are returned when an alpha channel, or tRNS chunk in a palette
144.1651 + * file, is present.
144.1652 + *
144.1653 + * This has no effect on the way pixels are written into a PNG output
144.1654 + * datastream. The color samples in a PNG datastream are never premultiplied
144.1655 + * with the alpha samples.
144.1656 + *
144.1657 + * The default is to return data according to the PNG specification: the alpha
144.1658 + * channel is a linear measure of the contribution of the pixel to the
144.1659 + * corresponding composited pixel.  The gamma encoded color channels must be
144.1660 + * scaled according to the contribution and to do this it is necessary to undo
144.1661 + * the encoding, scale the color values, perform the composition and reencode
144.1662 + * the values.  This is the 'PNG' mode.
144.1663 + *
144.1664 + * The alternative is to 'associate' the alpha with the color information by
144.1665 + * storing color channel values that have been scaled by the alpha.  The
144.1666 + * advantage is that the color channels can be resampled (the image can be
144.1667 + * scaled) in this form.  The disadvantage is that normal practice is to store
144.1668 + * linear, not (gamma) encoded, values and this requires 16-bit channels for
144.1669 + * still images rather than the 8-bit channels that are just about sufficient if
144.1670 + * gamma encoding is used.  In addition all non-transparent pixel values,
144.1671 + * including completely opaque ones, must be gamma encoded to produce the final
144.1672 + * image.  This is the 'STANDARD', 'ASSOCIATED' or 'PREMULTIPLIED' mode (the
144.1673 + * latter being the two common names for associated alpha color channels.)
144.1674 + *
144.1675 + * Since it is not necessary to perform arithmetic on opaque color values so
144.1676 + * long as they are not to be resampled and are in the final color space it is
144.1677 + * possible to optimize the handling of alpha by storing the opaque pixels in
144.1678 + * the PNG format (adjusted for the output color space) while storing partially
144.1679 + * opaque pixels in the standard, linear, format.  The accuracy required for
144.1680 + * standard alpha composition is relatively low, because the pixels are
144.1681 + * isolated, therefore typically the accuracy loss in storing 8-bit linear
144.1682 + * values is acceptable.  (This is not true if the alpha channel is used to
144.1683 + * simulate transparency over large areas - use 16 bits or the PNG mode in
144.1684 + * this case!)  This is the 'OPTIMIZED' mode.  For this mode a pixel is
144.1685 + * treated as opaque only if the alpha value is equal to the maximum value.
144.1686 + *
144.1687 + * The final choice is to gamma encode the alpha channel as well.  This is
144.1688 + * broken because, in practice, no implementation that uses this choice
144.1689 + * correctly undoes the encoding before handling alpha composition.  Use this
144.1690 + * choice only if other serious errors in the software or hardware you use
144.1691 + * mandate it; the typical serious error is for dark halos to appear around
144.1692 + * opaque areas of the composited PNG image because of arithmetic overflow.
144.1693 + *
144.1694 + * The API function png_set_alpha_mode specifies which of these choices to use
144.1695 + * with an enumerated 'mode' value and the gamma of the required output:
144.1696 + */
144.1697 +#define PNG_ALPHA_PNG           0 /* according to the PNG standard */
144.1698 +#define PNG_ALPHA_STANDARD      1 /* according to Porter/Duff */
144.1699 +#define PNG_ALPHA_ASSOCIATED    1 /* as above; this is the normal practice */
144.1700 +#define PNG_ALPHA_PREMULTIPLIED 1 /* as above */
144.1701 +#define PNG_ALPHA_OPTIMIZED     2 /* 'PNG' for opaque pixels, else 'STANDARD' */
144.1702 +#define PNG_ALPHA_BROKEN        3 /* the alpha channel is gamma encoded */
144.1703 +
144.1704 +PNG_FP_EXPORT(227, void, png_set_alpha_mode, (png_structp png_ptr, int mode,
144.1705 +    double output_gamma));
144.1706 +PNG_FIXED_EXPORT(228, void, png_set_alpha_mode_fixed, (png_structp png_ptr,
144.1707 +    int mode, png_fixed_point output_gamma));
144.1708 +#endif
144.1709 +
144.1710 +#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_ALPHA_MODE_SUPPORTED)
144.1711 +/* The output_gamma value is a screen gamma in libpng terminology: it expresses
144.1712 + * how to decode the output values, not how they are encoded.  The values used
144.1713 + * correspond to the normal numbers used to describe the overall gamma of a
144.1714 + * computer display system; for example 2.2 for an sRGB conformant system.  The
144.1715 + * values are scaled by 100000 in the _fixed version of the API (so 220000 for
144.1716 + * sRGB.)
144.1717 + *
144.1718 + * The inverse of the value is always used to provide a default for the PNG file
144.1719 + * encoding if it has no gAMA chunk and if png_set_gamma() has not been called
144.1720 + * to override the PNG gamma information.
144.1721 + *
144.1722 + * When the ALPHA_OPTIMIZED mode is selected the output gamma is used to encode
144.1723 + * opaque pixels however pixels with lower alpha values are not encoded,
144.1724 + * regardless of the output gamma setting.
144.1725 + *
144.1726 + * When the standard Porter Duff handling is requested with mode 1 the output
144.1727 + * encoding is set to be linear and the output_gamma value is only relevant
144.1728 + * as a default for input data that has no gamma information.  The linear output
144.1729 + * encoding will be overridden if png_set_gamma() is called - the results may be
144.1730 + * highly unexpected!
144.1731 + *
144.1732 + * The following numbers are derived from the sRGB standard and the research
144.1733 + * behind it.  sRGB is defined to be approximated by a PNG gAMA chunk value of
144.1734 + * 0.45455 (1/2.2) for PNG.  The value implicitly includes any viewing
144.1735 + * correction required to take account of any differences in the color
144.1736 + * environment of the original scene and the intended display environment; the
144.1737 + * value expresses how to *decode* the image for display, not how the original
144.1738 + * data was *encoded*.
144.1739 + *
144.1740 + * sRGB provides a peg for the PNG standard by defining a viewing environment.
144.1741 + * sRGB itself, and earlier TV standards, actually use a more complex transform
144.1742 + * (a linear portion then a gamma 2.4 power law) than PNG can express.  (PNG is
144.1743 + * limited to simple power laws.)  By saying that an image for direct display on
144.1744 + * an sRGB conformant system should be stored with a gAMA chunk value of 45455
144.1745 + * (11.3.3.2 and 11.3.3.5 of the ISO PNG specification) the PNG specification
144.1746 + * makes it possible to derive values for other display systems and
144.1747 + * environments.
144.1748 + *
144.1749 + * The Mac value is deduced from the sRGB based on an assumption that the actual
144.1750 + * extra viewing correction used in early Mac display systems was implemented as
144.1751 + * a power 1.45 lookup table.
144.1752 + *
144.1753 + * Any system where a programmable lookup table is used or where the behavior of
144.1754 + * the final display device characteristics can be changed requires system
144.1755 + * specific code to obtain the current characteristic.  However this can be
144.1756 + * difficult and most PNG gamma correction only requires an approximate value.
144.1757 + *
144.1758 + * By default, if png_set_alpha_mode() is not called, libpng assumes that all
144.1759 + * values are unencoded, linear, values and that the output device also has a
144.1760 + * linear characteristic.  This is only very rarely correct - it is invariably
144.1761 + * better to call png_set_alpha_mode() with PNG_DEFAULT_sRGB than rely on the
144.1762 + * default if you don't know what the right answer is!
144.1763 + *
144.1764 + * The special value PNG_GAMMA_MAC_18 indicates an older Mac system (pre Mac OS
144.1765 + * 10.6) which used a correction table to implement a somewhat lower gamma on an
144.1766 + * otherwise sRGB system.
144.1767 + *
144.1768 + * Both these values are reserved (not simple gamma values) in order to allow
144.1769 + * more precise correction internally in the future.
144.1770 + *
144.1771 + * NOTE: the following values can be passed to either the fixed or floating
144.1772 + * point APIs, but the floating point API will also accept floating point
144.1773 + * values.
144.1774 + */
144.1775 +#define PNG_DEFAULT_sRGB -1       /* sRGB gamma and color space */
144.1776 +#define PNG_GAMMA_MAC_18 -2       /* Old Mac '1.8' gamma and color space */
144.1777 +#define PNG_GAMMA_sRGB   220000   /* Television standards--matches sRGB gamma */
144.1778 +#define PNG_GAMMA_LINEAR PNG_FP_1 /* Linear */
144.1779 +#endif
144.1780 +
144.1781 +/* The following are examples of calls to png_set_alpha_mode to achieve the
144.1782 + * required overall gamma correction and, where necessary, alpha
144.1783 + * premultiplication.
144.1784 + *
144.1785 + * png_set_alpha_mode(pp, PNG_ALPHA_PNG, PNG_DEFAULT_sRGB);
144.1786 + *    This is the default libpng handling of the alpha channel - it is not
144.1787 + *    pre-multiplied into the color components.  In addition the call states
144.1788 + *    that the output is for a sRGB system and causes all PNG files without gAMA
144.1789 + *    chunks to be assumed to be encoded using sRGB.
144.1790 + *
144.1791 + * png_set_alpha_mode(pp, PNG_ALPHA_PNG, PNG_GAMMA_MAC);
144.1792 + *    In this case the output is assumed to be something like an sRGB conformant
144.1793 + *    display preceeded by a power-law lookup table of power 1.45.  This is how
144.1794 + *    early Mac systems behaved.
144.1795 + *
144.1796 + * png_set_alpha_mode(pp, PNG_ALPHA_STANDARD, PNG_GAMMA_LINEAR);
144.1797 + *    This is the classic Jim Blinn approach and will work in academic
144.1798 + *    environments where everything is done by the book.  It has the shortcoming
144.1799 + *    of assuming that input PNG data with no gamma information is linear - this
144.1800 + *    is unlikely to be correct unless the PNG files where generated locally.
144.1801 + *    Most of the time the output precision will be so low as to show
144.1802 + *    significant banding in dark areas of the image.
144.1803 + *
144.1804 + * png_set_expand_16(pp);
144.1805 + * png_set_alpha_mode(pp, PNG_ALPHA_STANDARD, PNG_DEFAULT_sRGB);
144.1806 + *    This is a somewhat more realistic Jim Blinn inspired approach.  PNG files
144.1807 + *    are assumed to have the sRGB encoding if not marked with a gamma value and
144.1808 + *    the output is always 16 bits per component.  This permits accurate scaling
144.1809 + *    and processing of the data.  If you know that your input PNG files were
144.1810 + *    generated locally you might need to replace PNG_DEFAULT_sRGB with the
144.1811 + *    correct value for your system.
144.1812 + *
144.1813 + * png_set_alpha_mode(pp, PNG_ALPHA_OPTIMIZED, PNG_DEFAULT_sRGB);
144.1814 + *    If you just need to composite the PNG image onto an existing background
144.1815 + *    and if you control the code that does this you can use the optimization
144.1816 + *    setting.  In this case you just copy completely opaque pixels to the
144.1817 + *    output.  For pixels that are not completely transparent (you just skip
144.1818 + *    those) you do the composition math using png_composite or png_composite_16
144.1819 + *    below then encode the resultant 8-bit or 16-bit values to match the output
144.1820 + *    encoding.
144.1821 + *
144.1822 + * Other cases
144.1823 + *    If neither the PNG nor the standard linear encoding work for you because
144.1824 + *    of the software or hardware you use then you have a big problem.  The PNG
144.1825 + *    case will probably result in halos around the image.  The linear encoding
144.1826 + *    will probably result in a washed out, too bright, image (it's actually too
144.1827 + *    contrasty.)  Try the ALPHA_OPTIMIZED mode above - this will probably
144.1828 + *    substantially reduce the halos.  Alternatively try:
144.1829 + *
144.1830 + * png_set_alpha_mode(pp, PNG_ALPHA_BROKEN, PNG_DEFAULT_sRGB);
144.1831 + *    This option will also reduce the halos, but there will be slight dark
144.1832 + *    halos round the opaque parts of the image where the background is light.
144.1833 + *    In the OPTIMIZED mode the halos will be light halos where the background
144.1834 + *    is dark.  Take your pick - the halos are unavoidable unless you can get
144.1835 + *    your hardware/software fixed!  (The OPTIMIZED approach is slightly
144.1836 + *    faster.)
144.1837 + *
144.1838 + * When the default gamma of PNG files doesn't match the output gamma.
144.1839 + *    If you have PNG files with no gamma information png_set_alpha_mode allows
144.1840 + *    you to provide a default gamma, but it also sets the ouput gamma to the
144.1841 + *    matching value.  If you know your PNG files have a gamma that doesn't
144.1842 + *    match the output you can take advantage of the fact that
144.1843 + *    png_set_alpha_mode always sets the output gamma but only sets the PNG
144.1844 + *    default if it is not already set:
144.1845 + *
144.1846 + * png_set_alpha_mode(pp, PNG_ALPHA_PNG, PNG_DEFAULT_sRGB);
144.1847 + * png_set_alpha_mode(pp, PNG_ALPHA_PNG, PNG_GAMMA_MAC);
144.1848 + *    The first call sets both the default and the output gamma values, the
144.1849 + *    second call overrides the output gamma without changing the default.  This
144.1850 + *    is easier than achieving the same effect with png_set_gamma.  You must use
144.1851 + *    PNG_ALPHA_PNG for the first call - internal checking in png_set_alpha will
144.1852 + *    fire if more than one call to png_set_alpha_mode and png_set_background is
144.1853 + *    made in the same read operation, however multiple calls with PNG_ALPHA_PNG
144.1854 + *    are ignored.
144.1855 + */
144.1856 +
144.1857 +#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
144.1858 +PNG_EXPORT(36, void, png_set_strip_alpha, (png_structp png_ptr));
144.1859  #endif
144.1860  
144.1861  #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \
144.1862      defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
144.1863 -extern PNG_EXPORT(void,png_set_swap_alpha) PNGARG((png_structp png_ptr));
144.1864 +PNG_EXPORT(37, void, png_set_swap_alpha, (png_structp png_ptr));
144.1865  #endif
144.1866  
144.1867  #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
144.1868      defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
144.1869 -extern PNG_EXPORT(void,png_set_invert_alpha) PNGARG((png_structp png_ptr));
144.1870 +PNG_EXPORT(38, void, png_set_invert_alpha, (png_structp png_ptr));
144.1871  #endif
144.1872  
144.1873  #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
144.1874  /* Add a filler byte to 8-bit Gray or 24-bit RGB images. */
144.1875 -extern PNG_EXPORT(void,png_set_filler) PNGARG((png_structp png_ptr,
144.1876 -   png_uint_32 filler, int flags));
144.1877 +PNG_EXPORT(39, void, png_set_filler, (png_structp png_ptr, png_uint_32 filler,
144.1878 +    int flags));
144.1879  /* The values of the PNG_FILLER_ defines should NOT be changed */
144.1880 -#define PNG_FILLER_BEFORE 0
144.1881 -#define PNG_FILLER_AFTER 1
144.1882 +#  define PNG_FILLER_BEFORE 0
144.1883 +#  define PNG_FILLER_AFTER 1
144.1884  /* Add an alpha byte to 8-bit Gray or 24-bit RGB images. */
144.1885 -#if !defined(PNG_1_0_X)
144.1886 -extern PNG_EXPORT(void,png_set_add_alpha) PNGARG((png_structp png_ptr,
144.1887 -   png_uint_32 filler, int flags));
144.1888 -#endif
144.1889 +PNG_EXPORT(40, void, png_set_add_alpha,
144.1890 +    (png_structp png_ptr, png_uint_32 filler,
144.1891 +    int flags));
144.1892  #endif /* PNG_READ_FILLER_SUPPORTED || PNG_WRITE_FILLER_SUPPORTED */
144.1893  
144.1894  #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
144.1895  /* Swap bytes in 16-bit depth files. */
144.1896 -extern PNG_EXPORT(void,png_set_swap) PNGARG((png_structp png_ptr));
144.1897 +PNG_EXPORT(41, void, png_set_swap, (png_structp png_ptr));
144.1898  #endif
144.1899  
144.1900  #if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
144.1901  /* Use 1 byte per pixel in 1, 2, or 4-bit depth files. */
144.1902 -extern PNG_EXPORT(void,png_set_packing) PNGARG((png_structp png_ptr));
144.1903 +PNG_EXPORT(42, void, png_set_packing, (png_structp png_ptr));
144.1904  #endif
144.1905  
144.1906 -#if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED)
144.1907 +#if defined(PNG_READ_PACKSWAP_SUPPORTED) || \
144.1908 +    defined(PNG_WRITE_PACKSWAP_SUPPORTED)
144.1909  /* Swap packing order of pixels in bytes. */
144.1910 -extern PNG_EXPORT(void,png_set_packswap) PNGARG((png_structp png_ptr));
144.1911 +PNG_EXPORT(43, void, png_set_packswap, (png_structp png_ptr));
144.1912  #endif
144.1913  
144.1914  #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
144.1915  /* Converts files to legal bit depths. */
144.1916 -extern PNG_EXPORT(void,png_set_shift) PNGARG((png_structp png_ptr,
144.1917 -   png_color_8p true_bits));
144.1918 +PNG_EXPORT(44, void, png_set_shift, (png_structp png_ptr, png_const_color_8p
144.1919 +    true_bits));
144.1920  #endif
144.1921  
144.1922  #if defined(PNG_READ_INTERLACING_SUPPORTED) || \
144.1923      defined(PNG_WRITE_INTERLACING_SUPPORTED)
144.1924 -/* Have the code handle the interlacing.  Returns the number of passes. */
144.1925 -extern PNG_EXPORT(int,png_set_interlace_handling) PNGARG((png_structp png_ptr));
144.1926 +/* Have the code handle the interlacing.  Returns the number of passes.
144.1927 + * MUST be called before png_read_update_info or png_start_read_image,
144.1928 + * otherwise it will not have the desired effect.  Note that it is still
144.1929 + * necessary to call png_read_row or png_read_rows png_get_image_height
144.1930 + * times for each pass.
144.1931 +*/
144.1932 +PNG_EXPORT(45, int, png_set_interlace_handling, (png_structp png_ptr));
144.1933  #endif
144.1934  
144.1935  #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
144.1936  /* Invert monochrome files */
144.1937 -extern PNG_EXPORT(void,png_set_invert_mono) PNGARG((png_structp png_ptr));
144.1938 +PNG_EXPORT(46, void, png_set_invert_mono, (png_structp png_ptr));
144.1939  #endif
144.1940  
144.1941 -#if defined(PNG_READ_BACKGROUND_SUPPORTED)
144.1942 -/* Handle alpha and tRNS by replacing with a background color. */
144.1943 -#ifdef PNG_FLOATING_POINT_SUPPORTED
144.1944 -extern PNG_EXPORT(void,png_set_background) PNGARG((png_structp png_ptr,
144.1945 -   png_color_16p background_color, int background_gamma_code,
144.1946 -   int need_expand, double background_gamma));
144.1947 +#ifdef PNG_READ_BACKGROUND_SUPPORTED
144.1948 +/* Handle alpha and tRNS by replacing with a background color.  Prior to
144.1949 + * libpng-1.5.4 this API must not be called before the PNG file header has been
144.1950 + * read.  Doing so will result in unexpected behavior and possible warnings or
144.1951 + * errors if the PNG file contains a bKGD chunk.
144.1952 + */
144.1953 +PNG_FP_EXPORT(47, void, png_set_background, (png_structp png_ptr,
144.1954 +    png_const_color_16p background_color, int background_gamma_code,
144.1955 +    int need_expand, double background_gamma));
144.1956 +PNG_FIXED_EXPORT(215, void, png_set_background_fixed, (png_structp png_ptr,
144.1957 +    png_const_color_16p background_color, int background_gamma_code,
144.1958 +    int need_expand, png_fixed_point background_gamma));
144.1959  #endif
144.1960 -#define PNG_BACKGROUND_GAMMA_UNKNOWN 0
144.1961 -#define PNG_BACKGROUND_GAMMA_SCREEN  1
144.1962 -#define PNG_BACKGROUND_GAMMA_FILE    2
144.1963 -#define PNG_BACKGROUND_GAMMA_UNIQUE  3
144.1964 +#ifdef PNG_READ_BACKGROUND_SUPPORTED
144.1965 +#  define PNG_BACKGROUND_GAMMA_UNKNOWN 0
144.1966 +#  define PNG_BACKGROUND_GAMMA_SCREEN  1
144.1967 +#  define PNG_BACKGROUND_GAMMA_FILE    2
144.1968 +#  define PNG_BACKGROUND_GAMMA_UNIQUE  3
144.1969  #endif
144.1970  
144.1971 -#if defined(PNG_READ_16_TO_8_SUPPORTED)
144.1972 -/* strip the second byte of information from a 16-bit depth file. */
144.1973 -extern PNG_EXPORT(void,png_set_strip_16) PNGARG((png_structp png_ptr));
144.1974 +#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
144.1975 +/* Scale a 16-bit depth file down to 8-bit, accurately. */
144.1976 +PNG_EXPORT(229, void, png_set_scale_16, (png_structp png_ptr));
144.1977  #endif
144.1978  
144.1979 -#if defined(PNG_READ_DITHER_SUPPORTED)
144.1980 -/* Turn on dithering, and reduce the palette to the number of colors available. */
144.1981 -extern PNG_EXPORT(void,png_set_dither) PNGARG((png_structp png_ptr,
144.1982 -   png_colorp palette, int num_palette, int maximum_colors,
144.1983 -   png_uint_16p histogram, int full_dither));
144.1984 +#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED
144.1985 +#define PNG_READ_16_TO_8 SUPPORTED /* Name prior to 1.5.4 */
144.1986 +/* Strip the second byte of information from a 16-bit depth file. */
144.1987 +PNG_EXPORT(48, void, png_set_strip_16, (png_structp png_ptr));
144.1988  #endif
144.1989  
144.1990 -#if defined(PNG_READ_GAMMA_SUPPORTED)
144.1991 -/* Handle gamma correction. Screen_gamma=(display_exponent) */
144.1992 -#ifdef PNG_FLOATING_POINT_SUPPORTED
144.1993 -extern PNG_EXPORT(void,png_set_gamma) PNGARG((png_structp png_ptr,
144.1994 -   double screen_gamma, double default_file_gamma));
144.1995 -#endif
144.1996 +#ifdef PNG_READ_QUANTIZE_SUPPORTED
144.1997 +/* Turn on quantizing, and reduce the palette to the number of colors
144.1998 + * available.
144.1999 + */
144.2000 +PNG_EXPORT(49, void, png_set_quantize,
144.2001 +    (png_structp png_ptr, png_colorp palette,
144.2002 +    int num_palette, int maximum_colors, png_const_uint_16p histogram,
144.2003 +    int full_quantize));
144.2004  #endif
144.2005  
144.2006 -#if defined(PNG_1_0_X) || defined (PNG_1_2_X)
144.2007 -#if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
144.2008 -    defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
144.2009 -/* Permit or disallow empty PLTE (0: not permitted, 1: permitted) */
144.2010 -/* Deprecated and will be removed.  Use png_permit_mng_features() instead. */
144.2011 -extern PNG_EXPORT(void,png_permit_empty_plte) PNGARG((png_structp png_ptr,
144.2012 -   int empty_plte_permitted));
144.2013 -#endif
144.2014 +#ifdef PNG_READ_GAMMA_SUPPORTED
144.2015 +/* The threshold on gamma processing is configurable but hard-wired into the
144.2016 + * library.  The following is the floating point variant.
144.2017 + */
144.2018 +#define PNG_GAMMA_THRESHOLD (PNG_GAMMA_THRESHOLD_FIXED*.00001)
144.2019 +
144.2020 +/* Handle gamma correction. Screen_gamma=(display_exponent).
144.2021 + * NOTE: this API simply sets the screen and file gamma values. It will
144.2022 + * therefore override the value for gamma in a PNG file if it is called after
144.2023 + * the file header has been read - use with care  - call before reading the PNG
144.2024 + * file for best results!
144.2025 + *
144.2026 + * These routines accept the same gamma values as png_set_alpha_mode (described
144.2027 + * above).  The PNG_GAMMA_ defines and PNG_DEFAULT_sRGB can be passed to either
144.2028 + * API (floating point or fixed.)  Notice, however, that the 'file_gamma' value
144.2029 + * is the inverse of a 'screen gamma' value.
144.2030 + */
144.2031 +PNG_FP_EXPORT(50, void, png_set_gamma,
144.2032 +    (png_structp png_ptr, double screen_gamma,
144.2033 +    double override_file_gamma));
144.2034 +PNG_FIXED_EXPORT(208, void, png_set_gamma_fixed, (png_structp png_ptr,
144.2035 +    png_fixed_point screen_gamma, png_fixed_point override_file_gamma));
144.2036  #endif
144.2037  
144.2038 -#if defined(PNG_WRITE_FLUSH_SUPPORTED)
144.2039 +#ifdef PNG_WRITE_FLUSH_SUPPORTED
144.2040  /* Set how many lines between output flushes - 0 for no flushing */
144.2041 -extern PNG_EXPORT(void,png_set_flush) PNGARG((png_structp png_ptr, int nrows));
144.2042 +PNG_EXPORT(51, void, png_set_flush, (png_structp png_ptr, int nrows));
144.2043  /* Flush the current PNG output buffer */
144.2044 -extern PNG_EXPORT(void,png_write_flush) PNGARG((png_structp png_ptr));
144.2045 +PNG_EXPORT(52, void, png_write_flush, (png_structp png_ptr));
144.2046  #endif
144.2047  
144.2048 -/* optional update palette with requested transformations */
144.2049 -extern PNG_EXPORT(void,png_start_read_image) PNGARG((png_structp png_ptr));
144.2050 +/* Optional update palette with requested transformations */
144.2051 +PNG_EXPORT(53, void, png_start_read_image, (png_structp png_ptr));
144.2052  
144.2053 -/* optional call to update the users info structure */
144.2054 -extern PNG_EXPORT(void,png_read_update_info) PNGARG((png_structp png_ptr,
144.2055 -   png_infop info_ptr));
144.2056 +/* Optional call to update the users info structure */
144.2057 +PNG_EXPORT(54, void, png_read_update_info,
144.2058 +    (png_structp png_ptr, png_infop info_ptr));
144.2059  
144.2060 -#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
144.2061 -/* read one or more rows of image data. */
144.2062 -extern PNG_EXPORT(void,png_read_rows) PNGARG((png_structp png_ptr,
144.2063 -   png_bytepp row, png_bytepp display_row, png_uint_32 num_rows));
144.2064 +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
144.2065 +/* Read one or more rows of image data. */
144.2066 +PNG_EXPORT(55, void, png_read_rows, (png_structp png_ptr, png_bytepp row,
144.2067 +    png_bytepp display_row, png_uint_32 num_rows));
144.2068  #endif
144.2069  
144.2070 -#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
144.2071 -/* read a row of data. */
144.2072 -extern PNG_EXPORT(void,png_read_row) PNGARG((png_structp png_ptr,
144.2073 -   png_bytep row,
144.2074 -   png_bytep display_row));
144.2075 +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
144.2076 +/* Read a row of data. */
144.2077 +PNG_EXPORT(56, void, png_read_row, (png_structp png_ptr, png_bytep row,
144.2078 +    png_bytep display_row));
144.2079  #endif
144.2080  
144.2081 -#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
144.2082 -/* read the whole image into memory at once. */
144.2083 -extern PNG_EXPORT(void,png_read_image) PNGARG((png_structp png_ptr,
144.2084 -   png_bytepp image));
144.2085 +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
144.2086 +/* Read the whole image into memory at once. */
144.2087 +PNG_EXPORT(57, void, png_read_image, (png_structp png_ptr, png_bytepp image));
144.2088  #endif
144.2089  
144.2090 -/* write a row of image data */
144.2091 -extern PNG_EXPORT(void,png_write_row) PNGARG((png_structp png_ptr,
144.2092 -   png_bytep row));
144.2093 +/* Write a row of image data */
144.2094 +PNG_EXPORT(58, void, png_write_row,
144.2095 +    (png_structp png_ptr, png_const_bytep row));
144.2096  
144.2097 -/* write a few rows of image data */
144.2098 -extern PNG_EXPORT(void,png_write_rows) PNGARG((png_structp png_ptr,
144.2099 -   png_bytepp row, png_uint_32 num_rows));
144.2100 +/* Write a few rows of image data: (*row) is not written; however, the type
144.2101 + * is declared as writeable to maintain compatibility with previous versions
144.2102 + * of libpng and to allow the 'display_row' array from read_rows to be passed
144.2103 + * unchanged to write_rows.
144.2104 + */
144.2105 +PNG_EXPORT(59, void, png_write_rows, (png_structp png_ptr, png_bytepp row,
144.2106 +    png_uint_32 num_rows));
144.2107  
144.2108 -/* write the image data */
144.2109 -extern PNG_EXPORT(void,png_write_image) PNGARG((png_structp png_ptr,
144.2110 -   png_bytepp image));
144.2111 +/* Write the image data */
144.2112 +PNG_EXPORT(60, void, png_write_image,
144.2113 +    (png_structp png_ptr, png_bytepp image));
144.2114  
144.2115 -/* writes the end of the PNG file. */
144.2116 -extern PNG_EXPORT(void,png_write_end) PNGARG((png_structp png_ptr,
144.2117 -   png_infop info_ptr));
144.2118 +/* Write the end of the PNG file. */
144.2119 +PNG_EXPORT(61, void, png_write_end,
144.2120 +    (png_structp png_ptr, png_infop info_ptr));
144.2121  
144.2122 -#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
144.2123 -/* read the end of the PNG file. */
144.2124 -extern PNG_EXPORT(void,png_read_end) PNGARG((png_structp png_ptr,
144.2125 -   png_infop info_ptr));
144.2126 +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
144.2127 +/* Read the end of the PNG file. */
144.2128 +PNG_EXPORT(62, void, png_read_end, (png_structp png_ptr, png_infop info_ptr));
144.2129  #endif
144.2130  
144.2131 -/* free any memory associated with the png_info_struct */
144.2132 -extern PNG_EXPORT(void,png_destroy_info_struct) PNGARG((png_structp png_ptr,
144.2133 -   png_infopp info_ptr_ptr));
144.2134 +/* Free any memory associated with the png_info_struct */
144.2135 +PNG_EXPORT(63, void, png_destroy_info_struct, (png_structp png_ptr,
144.2136 +    png_infopp info_ptr_ptr));
144.2137  
144.2138 -/* free any memory associated with the png_struct and the png_info_structs */
144.2139 -extern PNG_EXPORT(void,png_destroy_read_struct) PNGARG((png_structpp
144.2140 -   png_ptr_ptr, png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr));
144.2141 +/* Free any memory associated with the png_struct and the png_info_structs */
144.2142 +PNG_EXPORT(64, void, png_destroy_read_struct, (png_structpp png_ptr_ptr,
144.2143 +    png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr));
144.2144  
144.2145 -/* free all memory used by the read (old method - NOT DLL EXPORTED) */
144.2146 -extern void png_read_destroy PNGARG((png_structp png_ptr, png_infop info_ptr,
144.2147 -   png_infop end_info_ptr));
144.2148 +/* Free any memory associated with the png_struct and the png_info_structs */
144.2149 +PNG_EXPORT(65, void, png_destroy_write_struct, (png_structpp png_ptr_ptr,
144.2150 +    png_infopp info_ptr_ptr));
144.2151  
144.2152 -/* free any memory associated with the png_struct and the png_info_structs */
144.2153 -extern PNG_EXPORT(void,png_destroy_write_struct)
144.2154 -   PNGARG((png_structpp png_ptr_ptr, png_infopp info_ptr_ptr));
144.2155 +/* Set the libpng method of handling chunk CRC errors */
144.2156 +PNG_EXPORT(66, void, png_set_crc_action,
144.2157 +    (png_structp png_ptr, int crit_action, int ancil_action));
144.2158  
144.2159 -/* free any memory used in png_ptr struct (old method - NOT DLL EXPORTED) */
144.2160 -extern void png_write_destroy PNGARG((png_structp png_ptr));
144.2161 -
144.2162 -/* set the libpng method of handling chunk CRC errors */
144.2163 -extern PNG_EXPORT(void,png_set_crc_action) PNGARG((png_structp png_ptr,
144.2164 -   int crit_action, int ancil_action));
144.2165 -
144.2166 -/* Values for png_set_crc_action() to say how to handle CRC errors in
144.2167 +/* Values for png_set_crc_action() say how to handle CRC errors in
144.2168   * ancillary and critical chunks, and whether to use the data contained
144.2169   * therein.  Note that it is impossible to "discard" data in a critical
144.2170   * chunk.  For versions prior to 0.90, the action was always error/quit,
144.2171 @@ -1806,11 +1594,11 @@
144.2172   * header file (zlib.h) for an explination of the compression functions.
144.2173   */
144.2174  
144.2175 -/* set the filtering method(s) used by libpng.  Currently, the only valid
144.2176 +/* Set the filtering method(s) used by libpng.  Currently, the only valid
144.2177   * value for "method" is 0.
144.2178   */
144.2179 -extern PNG_EXPORT(void,png_set_filter) PNGARG((png_structp png_ptr, int method,
144.2180 -   int filters));
144.2181 +PNG_EXPORT(67, void, png_set_filter,
144.2182 +    (png_structp png_ptr, int method, int filters));
144.2183  
144.2184  /* Flags for png_set_filter() to say which filters to use.  The flags
144.2185   * are chosen so that they don't conflict with real filter types
144.2186 @@ -1836,7 +1624,7 @@
144.2187  #define PNG_FILTER_VALUE_PAETH 4
144.2188  #define PNG_FILTER_VALUE_LAST  5
144.2189  
144.2190 -#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* EXPERIMENTAL */
144.2191 +#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED /* EXPERIMENTAL */
144.2192  /* The "heuristic_method" is given by one of the PNG_FILTER_HEURISTIC_
144.2193   * defines, either the default (minimum-sum-of-absolute-differences), or
144.2194   * the experimental method (weighted-minimum-sum-of-absolute-differences).
144.2195 @@ -1865,11 +1653,13 @@
144.2196   * the weights and costs are set to 1.0, this degenerates the WEIGHTED method
144.2197   * to the UNWEIGHTED method, but with added encoding time/computation.
144.2198   */
144.2199 -#ifdef PNG_FLOATING_POINT_SUPPORTED
144.2200 -extern PNG_EXPORT(void,png_set_filter_heuristics) PNGARG((png_structp png_ptr,
144.2201 -   int heuristic_method, int num_weights, png_doublep filter_weights,
144.2202 -   png_doublep filter_costs));
144.2203 -#endif
144.2204 +PNG_FP_EXPORT(68, void, png_set_filter_heuristics, (png_structp png_ptr,
144.2205 +    int heuristic_method, int num_weights, png_const_doublep filter_weights,
144.2206 +    png_const_doublep filter_costs));
144.2207 +PNG_FIXED_EXPORT(209, void, png_set_filter_heuristics_fixed,
144.2208 +    (png_structp png_ptr,
144.2209 +    int heuristic_method, int num_weights, png_const_fixed_point_p
144.2210 +    filter_weights, png_const_fixed_point_p filter_costs));
144.2211  #endif /*  PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
144.2212  
144.2213  /* Heuristic used for row filter selection.  These defines should NOT be
144.2214 @@ -1880,6 +1670,7 @@
144.2215  #define PNG_FILTER_HEURISTIC_WEIGHTED   2  /* Experimental feature */
144.2216  #define PNG_FILTER_HEURISTIC_LAST       3  /* Not a valid value */
144.2217  
144.2218 +#ifdef PNG_WRITE_SUPPORTED
144.2219  /* Set the library compression level.  Currently, valid values range from
144.2220   * 0 - 9, corresponding directly to the zlib compression levels 0 - 9
144.2221   * (0 - no compression, 9 - "maximal" compression).  Note that tests have
144.2222 @@ -1887,33 +1678,58 @@
144.2223   * for PNG images, and do considerably fewer caclulations.  In the future,
144.2224   * these values may not correspond directly to the zlib compression levels.
144.2225   */
144.2226 -extern PNG_EXPORT(void,png_set_compression_level) PNGARG((png_structp png_ptr,
144.2227 -   int level));
144.2228 +PNG_EXPORT(69, void, png_set_compression_level,
144.2229 +    (png_structp png_ptr, int level));
144.2230  
144.2231 -extern PNG_EXPORT(void,png_set_compression_mem_level)
144.2232 -   PNGARG((png_structp png_ptr, int mem_level));
144.2233 +PNG_EXPORT(70, void, png_set_compression_mem_level, (png_structp png_ptr,
144.2234 +    int mem_level));
144.2235  
144.2236 -extern PNG_EXPORT(void,png_set_compression_strategy)
144.2237 -   PNGARG((png_structp png_ptr, int strategy));
144.2238 +PNG_EXPORT(71, void, png_set_compression_strategy, (png_structp png_ptr,
144.2239 +    int strategy));
144.2240  
144.2241 -extern PNG_EXPORT(void,png_set_compression_window_bits)
144.2242 -   PNGARG((png_structp png_ptr, int window_bits));
144.2243 +/* If PNG_WRITE_OPTIMIZE_CMF_SUPPORTED is defined, libpng will use a
144.2244 + * smaller value of window_bits if it can do so safely.
144.2245 + */
144.2246 +PNG_EXPORT(72, void, png_set_compression_window_bits, (png_structp png_ptr,
144.2247 +    int window_bits));
144.2248  
144.2249 -extern PNG_EXPORT(void,png_set_compression_method) PNGARG((png_structp png_ptr,
144.2250 -   int method));
144.2251 +PNG_EXPORT(73, void, png_set_compression_method, (png_structp png_ptr,
144.2252 +    int method));
144.2253 +#endif
144.2254 +
144.2255 +#ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED
144.2256 +/* Also set zlib parameters for compressing non-IDAT chunks */
144.2257 +PNG_EXPORT(222, void, png_set_text_compression_level,
144.2258 +    (png_structp png_ptr, int level));
144.2259 +
144.2260 +PNG_EXPORT(223, void, png_set_text_compression_mem_level, (png_structp png_ptr,
144.2261 +    int mem_level));
144.2262 +
144.2263 +PNG_EXPORT(224, void, png_set_text_compression_strategy, (png_structp png_ptr,
144.2264 +    int strategy));
144.2265 +
144.2266 +/* If PNG_WRITE_OPTIMIZE_CMF_SUPPORTED is defined, libpng will use a
144.2267 + * smaller value of window_bits if it can do so safely.
144.2268 + */
144.2269 +PNG_EXPORT(225, void, png_set_text_compression_window_bits, (png_structp
144.2270 +    png_ptr, int window_bits));
144.2271 +
144.2272 +PNG_EXPORT(226, void, png_set_text_compression_method, (png_structp png_ptr,
144.2273 +    int method));
144.2274 +#endif /* PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED */
144.2275  
144.2276  /* These next functions are called for input/output, memory, and error
144.2277   * handling.  They are in the file pngrio.c, pngwio.c, and pngerror.c,
144.2278   * and call standard C I/O routines such as fread(), fwrite(), and
144.2279   * fprintf().  These functions can be made to use other I/O routines
144.2280   * at run time for those applications that need to handle I/O in a
144.2281 - * different manner by calling png_set_???_fn().  See libpng.txt for
144.2282 + * different manner by calling png_set_???_fn().  See libpng-manual.txt for
144.2283   * more information.
144.2284   */
144.2285  
144.2286 -#if !defined(PNG_NO_STDIO)
144.2287 +#ifdef PNG_STDIO_SUPPORTED
144.2288  /* Initialize the input/output for the PNG file to the default functions. */
144.2289 -extern PNG_EXPORT(void,png_init_io) PNGARG((png_structp png_ptr, png_FILE_p fp));
144.2290 +PNG_EXPORT(74, void, png_init_io, (png_structp png_ptr, png_FILE_p fp));
144.2291  #endif
144.2292  
144.2293  /* Replace the (error and abort), and warning functions with user
144.2294 @@ -1924,128 +1740,155 @@
144.2295   * default function will be used.
144.2296   */
144.2297  
144.2298 -extern PNG_EXPORT(void,png_set_error_fn) PNGARG((png_structp png_ptr,
144.2299 -   png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warning_fn));
144.2300 +PNG_EXPORT(75, void, png_set_error_fn,
144.2301 +    (png_structp png_ptr, png_voidp error_ptr,
144.2302 +    png_error_ptr error_fn, png_error_ptr warning_fn));
144.2303  
144.2304  /* Return the user pointer associated with the error functions */
144.2305 -extern PNG_EXPORT(png_voidp,png_get_error_ptr) PNGARG((png_structp png_ptr));
144.2306 +PNG_EXPORT(76, png_voidp, png_get_error_ptr, (png_const_structp png_ptr));
144.2307  
144.2308  /* Replace the default data output functions with a user supplied one(s).
144.2309   * If buffered output is not used, then output_flush_fn can be set to NULL.
144.2310   * If PNG_WRITE_FLUSH_SUPPORTED is not defined at libpng compile time
144.2311   * output_flush_fn will be ignored (and thus can be NULL).
144.2312 + * It is probably a mistake to use NULL for output_flush_fn if
144.2313 + * write_data_fn is not also NULL unless you have built libpng with
144.2314 + * PNG_WRITE_FLUSH_SUPPORTED undefined, because in this case libpng's
144.2315 + * default flush function, which uses the standard *FILE structure, will
144.2316 + * be used.
144.2317   */
144.2318 -extern PNG_EXPORT(void,png_set_write_fn) PNGARG((png_structp png_ptr,
144.2319 -   png_voidp io_ptr, png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn));
144.2320 +PNG_EXPORT(77, void, png_set_write_fn, (png_structp png_ptr, png_voidp io_ptr,
144.2321 +    png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn));
144.2322  
144.2323  /* Replace the default data input function with a user supplied one. */
144.2324 -extern PNG_EXPORT(void,png_set_read_fn) PNGARG((png_structp png_ptr,
144.2325 -   png_voidp io_ptr, png_rw_ptr read_data_fn));
144.2326 +PNG_EXPORT(78, void, png_set_read_fn, (png_structp png_ptr, png_voidp io_ptr,
144.2327 +    png_rw_ptr read_data_fn));
144.2328  
144.2329  /* Return the user pointer associated with the I/O functions */
144.2330 -extern PNG_EXPORT(png_voidp,png_get_io_ptr) PNGARG((png_structp png_ptr));
144.2331 +PNG_EXPORT(79, png_voidp, png_get_io_ptr, (png_structp png_ptr));
144.2332  
144.2333 -extern PNG_EXPORT(void,png_set_read_status_fn) PNGARG((png_structp png_ptr,
144.2334 -   png_read_status_ptr read_row_fn));
144.2335 +PNG_EXPORT(80, void, png_set_read_status_fn, (png_structp png_ptr,
144.2336 +    png_read_status_ptr read_row_fn));
144.2337  
144.2338 -extern PNG_EXPORT(void,png_set_write_status_fn) PNGARG((png_structp png_ptr,
144.2339 -   png_write_status_ptr write_row_fn));
144.2340 +PNG_EXPORT(81, void, png_set_write_status_fn, (png_structp png_ptr,
144.2341 +    png_write_status_ptr write_row_fn));
144.2342  
144.2343  #ifdef PNG_USER_MEM_SUPPORTED
144.2344  /* Replace the default memory allocation functions with user supplied one(s). */
144.2345 -extern PNG_EXPORT(void,png_set_mem_fn) PNGARG((png_structp png_ptr,
144.2346 -   png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn));
144.2347 +PNG_EXPORT(82, void, png_set_mem_fn, (png_structp png_ptr, png_voidp mem_ptr,
144.2348 +    png_malloc_ptr malloc_fn, png_free_ptr free_fn));
144.2349  /* Return the user pointer associated with the memory functions */
144.2350 -extern PNG_EXPORT(png_voidp,png_get_mem_ptr) PNGARG((png_structp png_ptr));
144.2351 +PNG_EXPORT(83, png_voidp, png_get_mem_ptr, (png_const_structp png_ptr));
144.2352  #endif
144.2353  
144.2354 -#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
144.2355 -    defined(PNG_LEGACY_SUPPORTED)
144.2356 -extern PNG_EXPORT(void,png_set_read_user_transform_fn) PNGARG((png_structp
144.2357 -   png_ptr, png_user_transform_ptr read_user_transform_fn));
144.2358 +#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
144.2359 +PNG_EXPORT(84, void, png_set_read_user_transform_fn, (png_structp png_ptr,
144.2360 +    png_user_transform_ptr read_user_transform_fn));
144.2361  #endif
144.2362  
144.2363 -#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
144.2364 -    defined(PNG_LEGACY_SUPPORTED)
144.2365 -extern PNG_EXPORT(void,png_set_write_user_transform_fn) PNGARG((png_structp
144.2366 -   png_ptr, png_user_transform_ptr write_user_transform_fn));
144.2367 +#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
144.2368 +PNG_EXPORT(85, void, png_set_write_user_transform_fn, (png_structp png_ptr,
144.2369 +    png_user_transform_ptr write_user_transform_fn));
144.2370  #endif
144.2371  
144.2372 -#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
144.2373 -    defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
144.2374 -    defined(PNG_LEGACY_SUPPORTED)
144.2375 -extern PNG_EXPORT(void,png_set_user_transform_info) PNGARG((png_structp
144.2376 -   png_ptr, png_voidp user_transform_ptr, int user_transform_depth,
144.2377 -   int user_transform_channels));
144.2378 +#ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED
144.2379 +PNG_EXPORT(86, void, png_set_user_transform_info, (png_structp png_ptr,
144.2380 +    png_voidp user_transform_ptr, int user_transform_depth,
144.2381 +    int user_transform_channels));
144.2382  /* Return the user pointer associated with the user transform functions */
144.2383 -extern PNG_EXPORT(png_voidp,png_get_user_transform_ptr)
144.2384 -   PNGARG((png_structp png_ptr));
144.2385 +PNG_EXPORT(87, png_voidp, png_get_user_transform_ptr,
144.2386 +    (png_const_structp png_ptr));
144.2387 +#endif
144.2388 +
144.2389 +#ifdef PNG_USER_TRANSFORM_INFO_SUPPORTED
144.2390 +/* Return information about the row currently being processed.  Note that these
144.2391 + * APIs do not fail but will return unexpected results if called outside a user
144.2392 + * transform callback.  Also note that when transforming an interlaced image the
144.2393 + * row number is the row number within the sub-image of the interlace pass, so
144.2394 + * the value will increase to the height of the sub-image (not the full image)
144.2395 + * then reset to 0 for the next pass.
144.2396 + *
144.2397 + * Use PNG_ROW_FROM_PASS_ROW(row, pass) and PNG_COL_FROM_PASS_COL(col, pass) to
144.2398 + * find the output pixel (x,y) given an interlaced sub-image pixel
144.2399 + * (row,col,pass).  (See below for these macros.)
144.2400 + */
144.2401 +PNG_EXPORT(217, png_uint_32, png_get_current_row_number, (png_const_structp));
144.2402 +PNG_EXPORT(218, png_byte, png_get_current_pass_number, (png_const_structp));
144.2403  #endif
144.2404  
144.2405  #ifdef PNG_USER_CHUNKS_SUPPORTED
144.2406 -extern PNG_EXPORT(void,png_set_read_user_chunk_fn) PNGARG((png_structp png_ptr,
144.2407 -   png_voidp user_chunk_ptr, png_user_chunk_ptr read_user_chunk_fn));
144.2408 -extern PNG_EXPORT(png_voidp,png_get_user_chunk_ptr) PNGARG((png_structp
144.2409 -   png_ptr));
144.2410 +PNG_EXPORT(88, void, png_set_read_user_chunk_fn, (png_structp png_ptr,
144.2411 +    png_voidp user_chunk_ptr, png_user_chunk_ptr read_user_chunk_fn));
144.2412 +PNG_EXPORT(89, png_voidp, png_get_user_chunk_ptr, (png_const_structp png_ptr));
144.2413  #endif
144.2414  
144.2415  #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
144.2416  /* Sets the function callbacks for the push reader, and a pointer to a
144.2417   * user-defined structure available to the callback functions.
144.2418   */
144.2419 -extern PNG_EXPORT(void,png_set_progressive_read_fn) PNGARG((png_structp png_ptr,
144.2420 -   png_voidp progressive_ptr,
144.2421 -   png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
144.2422 -   png_progressive_end_ptr end_fn));
144.2423 +PNG_EXPORT(90, void, png_set_progressive_read_fn, (png_structp png_ptr,
144.2424 +    png_voidp progressive_ptr, png_progressive_info_ptr info_fn,
144.2425 +    png_progressive_row_ptr row_fn, png_progressive_end_ptr end_fn));
144.2426  
144.2427 -/* returns the user pointer associated with the push read functions */
144.2428 -extern PNG_EXPORT(png_voidp,png_get_progressive_ptr)
144.2429 -   PNGARG((png_structp png_ptr));
144.2430 +/* Returns the user pointer associated with the push read functions */
144.2431 +PNG_EXPORT(91, png_voidp, png_get_progressive_ptr, (png_const_structp png_ptr));
144.2432  
144.2433 -/* function to be called when data becomes available */
144.2434 -extern PNG_EXPORT(void,png_process_data) PNGARG((png_structp png_ptr,
144.2435 -   png_infop info_ptr, png_bytep buffer, png_size_t buffer_size));
144.2436 +/* Function to be called when data becomes available */
144.2437 +PNG_EXPORT(92, void, png_process_data,
144.2438 +    (png_structp png_ptr, png_infop info_ptr,
144.2439 +    png_bytep buffer, png_size_t buffer_size));
144.2440  
144.2441 -/* function that combines rows.  Not very much different than the
144.2442 - * png_combine_row() call.  Is this even used?????
144.2443 +/* A function which may be called *only* within png_process_data to stop the
144.2444 + * processing of any more data.  The function returns the number of bytes
144.2445 + * remaining, excluding any that libpng has cached internally.  A subsequent
144.2446 + * call to png_process_data must supply these bytes again.  If the argument
144.2447 + * 'save' is set to true the routine will first save all the pending data and
144.2448 + * will always return 0.
144.2449   */
144.2450 -extern PNG_EXPORT(void,png_progressive_combine_row) PNGARG((png_structp png_ptr,
144.2451 -   png_bytep old_row, png_bytep new_row));
144.2452 +PNG_EXPORT(219, png_size_t, png_process_data_pause, (png_structp, int save));
144.2453 +
144.2454 +/* A function which may be called *only* outside (after) a call to
144.2455 + * png_process_data.  It returns the number of bytes of data to skip in the
144.2456 + * input.  Normally it will return 0, but if it returns a non-zero value the
144.2457 + * application must skip than number of bytes of input data and pass the
144.2458 + * following data to the next call to png_process_data.
144.2459 + */
144.2460 +PNG_EXPORT(220, png_uint_32, png_process_data_skip, (png_structp));
144.2461 +
144.2462 +/* Function that combines rows.  'new_row' is a flag that should come from
144.2463 + * the callback and be non-NULL if anything needs to be done; the library
144.2464 + * stores its own version of the new data internally and ignores the passed
144.2465 + * in value.
144.2466 + */
144.2467 +PNG_EXPORT(93, void, png_progressive_combine_row, (png_structp png_ptr,
144.2468 +    png_bytep old_row, png_const_bytep new_row));
144.2469  #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
144.2470  
144.2471 -extern PNG_EXPORT(png_voidp,png_malloc) PNGARG((png_structp png_ptr,
144.2472 -   png_uint_32 size));
144.2473 +PNG_EXPORTA(94, png_voidp, png_malloc,
144.2474 +    (png_structp png_ptr, png_alloc_size_t size),
144.2475 +    PNG_ALLOCATED);
144.2476 +/* Added at libpng version 1.4.0 */
144.2477 +PNG_EXPORTA(95, png_voidp, png_calloc,
144.2478 +    (png_structp png_ptr, png_alloc_size_t size),
144.2479 +    PNG_ALLOCATED);
144.2480  
144.2481 -#if defined(PNG_1_0_X)
144.2482 -#  define png_malloc_warn png_malloc
144.2483 -#else
144.2484  /* Added at libpng version 1.2.4 */
144.2485 -extern PNG_EXPORT(png_voidp,png_malloc_warn) PNGARG((png_structp png_ptr,
144.2486 -   png_uint_32 size));
144.2487 -#endif
144.2488 +PNG_EXPORTA(96, png_voidp, png_malloc_warn, (png_structp png_ptr,
144.2489 +    png_alloc_size_t size), PNG_ALLOCATED);
144.2490  
144.2491 -/* frees a pointer allocated by png_malloc() */
144.2492 -extern PNG_EXPORT(void,png_free) PNGARG((png_structp png_ptr, png_voidp ptr));
144.2493 -
144.2494 -#if defined(PNG_1_0_X)
144.2495 -/* Function to allocate memory for zlib. */
144.2496 -extern PNG_EXPORT(voidpf,png_zalloc) PNGARG((voidpf png_ptr, uInt items,
144.2497 -   uInt size));
144.2498 -
144.2499 -/* Function to free memory for zlib */
144.2500 -extern PNG_EXPORT(void,png_zfree) PNGARG((voidpf png_ptr, voidpf ptr));
144.2501 -#endif
144.2502 +/* Frees a pointer allocated by png_malloc() */
144.2503 +PNG_EXPORT(97, void, png_free, (png_structp png_ptr, png_voidp ptr));
144.2504  
144.2505  /* Free data that was allocated internally */
144.2506 -extern PNG_EXPORT(void,png_free_data) PNGARG((png_structp png_ptr,
144.2507 -   png_infop info_ptr, png_uint_32 free_me, int num));
144.2508 -#ifdef PNG_FREE_ME_SUPPORTED
144.2509 +PNG_EXPORT(98, void, png_free_data,
144.2510 +    (png_structp png_ptr, png_infop info_ptr, png_uint_32 free_me, int num));
144.2511 +
144.2512  /* Reassign responsibility for freeing existing data, whether allocated
144.2513   * by libpng or by the application */
144.2514 -extern PNG_EXPORT(void,png_data_freer) PNGARG((png_structp png_ptr,
144.2515 -   png_infop info_ptr, int freer, png_uint_32 mask));
144.2516 -#endif
144.2517 -/* assignments for png_data_freer */
144.2518 +PNG_EXPORT(99, void, png_data_freer,
144.2519 +    (png_structp png_ptr, png_infop info_ptr, int freer, png_uint_32 mask));
144.2520 +
144.2521 +/* Assignments for png_data_freer */
144.2522  #define PNG_DESTROY_WILL_FREE_DATA 1
144.2523  #define PNG_SET_WILL_FREE_DATA 1
144.2524  #define PNG_USER_WILL_FREE_DATA 2
144.2525 @@ -2065,38 +1908,59 @@
144.2526  #define PNG_FREE_MUL  0x4220 /* PNG_FREE_SPLT|PNG_FREE_TEXT|PNG_FREE_UNKN */
144.2527  
144.2528  #ifdef PNG_USER_MEM_SUPPORTED
144.2529 -extern PNG_EXPORT(png_voidp,png_malloc_default) PNGARG((png_structp png_ptr,
144.2530 -   png_uint_32 size));
144.2531 -extern PNG_EXPORT(void,png_free_default) PNGARG((png_structp png_ptr,
144.2532 -   png_voidp ptr));
144.2533 +PNG_EXPORTA(100, png_voidp, png_malloc_default, (png_structp png_ptr,
144.2534 +    png_alloc_size_t size), PNG_ALLOCATED);
144.2535 +PNG_EXPORT(101, void, png_free_default, (png_structp png_ptr, png_voidp ptr));
144.2536  #endif
144.2537  
144.2538 -extern PNG_EXPORT(png_voidp,png_memcpy_check) PNGARG((png_structp png_ptr,
144.2539 -   png_voidp s1, png_voidp s2, png_uint_32 size));
144.2540 -
144.2541 -extern PNG_EXPORT(png_voidp,png_memset_check) PNGARG((png_structp png_ptr,
144.2542 -   png_voidp s1, int value, png_uint_32 size));
144.2543 -
144.2544 -#if defined(USE_FAR_KEYWORD)  /* memory model conversion function */
144.2545 -extern void *png_far_to_near PNGARG((png_structp png_ptr,png_voidp ptr,
144.2546 -   int check));
144.2547 -#endif /* USE_FAR_KEYWORD */
144.2548 -
144.2549 +#ifdef PNG_ERROR_TEXT_SUPPORTED
144.2550  /* Fatal error in PNG image of libpng - can't continue */
144.2551 -extern PNG_EXPORT(void,png_error) PNGARG((png_structp png_ptr,
144.2552 -   png_const_charp error_message));
144.2553 +PNG_EXPORTA(102, void, png_error,
144.2554 +    (png_structp png_ptr, png_const_charp error_message),
144.2555 +    PNG_NORETURN);
144.2556  
144.2557  /* The same, but the chunk name is prepended to the error string. */
144.2558 -extern PNG_EXPORT(void,png_chunk_error) PNGARG((png_structp png_ptr,
144.2559 -   png_const_charp error_message));
144.2560 +PNG_EXPORTA(103, void, png_chunk_error, (png_structp png_ptr,
144.2561 +    png_const_charp error_message), PNG_NORETURN);
144.2562  
144.2563 +#else
144.2564 +/* Fatal error in PNG image of libpng - can't continue */
144.2565 +PNG_EXPORTA(104, void, png_err, (png_structp png_ptr), PNG_NORETURN);
144.2566 +#endif
144.2567 +
144.2568 +#ifdef PNG_WARNINGS_SUPPORTED
144.2569  /* Non-fatal error in libpng.  Can continue, but may have a problem. */
144.2570 -extern PNG_EXPORT(void,png_warning) PNGARG((png_structp png_ptr,
144.2571 -   png_const_charp warning_message));
144.2572 +PNG_EXPORT(105, void, png_warning, (png_structp png_ptr,
144.2573 +    png_const_charp warning_message));
144.2574  
144.2575  /* Non-fatal error in libpng, chunk name is prepended to message. */
144.2576 -extern PNG_EXPORT(void,png_chunk_warning) PNGARG((png_structp png_ptr,
144.2577 -   png_const_charp warning_message));
144.2578 +PNG_EXPORT(106, void, png_chunk_warning, (png_structp png_ptr,
144.2579 +    png_const_charp warning_message));
144.2580 +#endif
144.2581 +
144.2582 +#ifdef PNG_BENIGN_ERRORS_SUPPORTED
144.2583 +/* Benign error in libpng.  Can continue, but may have a problem.
144.2584 + * User can choose whether to handle as a fatal error or as a warning. */
144.2585 +#  undef png_benign_error
144.2586 +PNG_EXPORT(107, void, png_benign_error, (png_structp png_ptr,
144.2587 +    png_const_charp warning_message));
144.2588 +
144.2589 +/* Same, chunk name is prepended to message. */
144.2590 +#  undef png_chunk_benign_error
144.2591 +PNG_EXPORT(108, void, png_chunk_benign_error, (png_structp png_ptr,
144.2592 +    png_const_charp warning_message));
144.2593 +
144.2594 +PNG_EXPORT(109, void, png_set_benign_errors,
144.2595 +    (png_structp png_ptr, int allowed));
144.2596 +#else
144.2597 +#  ifdef PNG_ALLOW_BENIGN_ERRORS
144.2598 +#    define png_benign_error png_warning
144.2599 +#    define png_chunk_benign_error png_chunk_warning
144.2600 +#  else
144.2601 +#    define png_benign_error png_error
144.2602 +#    define png_chunk_benign_error png_chunk_error
144.2603 +#  endif
144.2604 +#endif
144.2605  
144.2606  /* The png_set_<chunk> functions are for storing values in the png_info_struct.
144.2607   * Similarly, the png_get_<chunk> calls are used to read values from the
144.2608 @@ -2111,322 +1975,338 @@
144.2609   * png_info_struct.
144.2610   */
144.2611  /* Returns "flag" if chunk data is valid in info_ptr. */
144.2612 -extern PNG_EXPORT(png_uint_32,png_get_valid) PNGARG((png_structp png_ptr,
144.2613 -png_infop info_ptr, png_uint_32 flag));
144.2614 +PNG_EXPORT(110, png_uint_32, png_get_valid,
144.2615 +    (png_const_structp png_ptr, png_const_infop info_ptr,
144.2616 +    png_uint_32 flag));
144.2617  
144.2618  /* Returns number of bytes needed to hold a transformed row. */
144.2619 -extern PNG_EXPORT(png_uint_32,png_get_rowbytes) PNGARG((png_structp png_ptr,
144.2620 -png_infop info_ptr));
144.2621 +PNG_EXPORT(111, png_size_t, png_get_rowbytes, (png_const_structp png_ptr,
144.2622 +    png_const_infop info_ptr));
144.2623  
144.2624 -#if defined(PNG_INFO_IMAGE_SUPPORTED)
144.2625 +#ifdef PNG_INFO_IMAGE_SUPPORTED
144.2626  /* Returns row_pointers, which is an array of pointers to scanlines that was
144.2627 -returned from png_read_png(). */
144.2628 -extern PNG_EXPORT(png_bytepp,png_get_rows) PNGARG((png_structp png_ptr,
144.2629 -png_infop info_ptr));
144.2630 + * returned from png_read_png().
144.2631 + */
144.2632 +PNG_EXPORT(112, png_bytepp, png_get_rows,
144.2633 +    (png_const_structp png_ptr, png_const_infop info_ptr));
144.2634  /* Set row_pointers, which is an array of pointers to scanlines for use
144.2635 -by png_write_png(). */
144.2636 -extern PNG_EXPORT(void,png_set_rows) PNGARG((png_structp png_ptr,
144.2637 -   png_infop info_ptr, png_bytepp row_pointers));
144.2638 + * by png_write_png().
144.2639 + */
144.2640 +PNG_EXPORT(113, void, png_set_rows, (png_structp png_ptr,
144.2641 +    png_infop info_ptr, png_bytepp row_pointers));
144.2642  #endif
144.2643  
144.2644  /* Returns number of color channels in image. */
144.2645 -extern PNG_EXPORT(png_byte,png_get_channels) PNGARG((png_structp png_ptr,
144.2646 -png_infop info_ptr));
144.2647 +PNG_EXPORT(114, png_byte, png_get_channels,
144.2648 +    (png_const_structp png_ptr, png_const_infop info_ptr));
144.2649  
144.2650  #ifdef PNG_EASY_ACCESS_SUPPORTED
144.2651  /* Returns image width in pixels. */
144.2652 -extern PNG_EXPORT(png_uint_32, png_get_image_width) PNGARG((png_structp
144.2653 -png_ptr, png_infop info_ptr));
144.2654 +PNG_EXPORT(115, png_uint_32, png_get_image_width, (png_const_structp png_ptr,
144.2655 +    png_const_infop info_ptr));
144.2656  
144.2657  /* Returns image height in pixels. */
144.2658 -extern PNG_EXPORT(png_uint_32, png_get_image_height) PNGARG((png_structp
144.2659 -png_ptr, png_infop info_ptr));
144.2660 +PNG_EXPORT(116, png_uint_32, png_get_image_height, (png_const_structp png_ptr,
144.2661 +    png_const_infop info_ptr));
144.2662  
144.2663  /* Returns image bit_depth. */
144.2664 -extern PNG_EXPORT(png_byte, png_get_bit_depth) PNGARG((png_structp
144.2665 -png_ptr, png_infop info_ptr));
144.2666 +PNG_EXPORT(117, png_byte, png_get_bit_depth,
144.2667 +    (png_const_structp png_ptr, png_const_infop info_ptr));
144.2668  
144.2669  /* Returns image color_type. */
144.2670 -extern PNG_EXPORT(png_byte, png_get_color_type) PNGARG((png_structp
144.2671 -png_ptr, png_infop info_ptr));
144.2672 +PNG_EXPORT(118, png_byte, png_get_color_type, (png_const_structp png_ptr,
144.2673 +    png_const_infop info_ptr));
144.2674  
144.2675  /* Returns image filter_type. */
144.2676 -extern PNG_EXPORT(png_byte, png_get_filter_type) PNGARG((png_structp
144.2677 -png_ptr, png_infop info_ptr));
144.2678 +PNG_EXPORT(119, png_byte, png_get_filter_type, (png_const_structp png_ptr,
144.2679 +    png_const_infop info_ptr));
144.2680  
144.2681  /* Returns image interlace_type. */
144.2682 -extern PNG_EXPORT(png_byte, png_get_interlace_type) PNGARG((png_structp
144.2683 -png_ptr, png_infop info_ptr));
144.2684 +PNG_EXPORT(120, png_byte, png_get_interlace_type, (png_const_structp png_ptr,
144.2685 +    png_const_infop info_ptr));
144.2686  
144.2687  /* Returns image compression_type. */
144.2688 -extern PNG_EXPORT(png_byte, png_get_compression_type) PNGARG((png_structp
144.2689 -png_ptr, png_infop info_ptr));
144.2690 +PNG_EXPORT(121, png_byte, png_get_compression_type, (png_const_structp png_ptr,
144.2691 +    png_const_infop info_ptr));
144.2692  
144.2693  /* Returns image resolution in pixels per meter, from pHYs chunk data. */
144.2694 -extern PNG_EXPORT(png_uint_32, png_get_pixels_per_meter) PNGARG((png_structp
144.2695 -png_ptr, png_infop info_ptr));
144.2696 -extern PNG_EXPORT(png_uint_32, png_get_x_pixels_per_meter) PNGARG((png_structp
144.2697 -png_ptr, png_infop info_ptr));
144.2698 -extern PNG_EXPORT(png_uint_32, png_get_y_pixels_per_meter) PNGARG((png_structp
144.2699 -png_ptr, png_infop info_ptr));
144.2700 +PNG_EXPORT(122, png_uint_32, png_get_pixels_per_meter,
144.2701 +    (png_const_structp png_ptr, png_const_infop info_ptr));
144.2702 +PNG_EXPORT(123, png_uint_32, png_get_x_pixels_per_meter,
144.2703 +    (png_const_structp png_ptr, png_const_infop info_ptr));
144.2704 +PNG_EXPORT(124, png_uint_32, png_get_y_pixels_per_meter,
144.2705 +    (png_const_structp png_ptr, png_const_infop info_ptr));
144.2706  
144.2707  /* Returns pixel aspect ratio, computed from pHYs chunk data.  */
144.2708 -#ifdef PNG_FLOATING_POINT_SUPPORTED
144.2709 -extern PNG_EXPORT(float, png_get_pixel_aspect_ratio) PNGARG((png_structp
144.2710 -png_ptr, png_infop info_ptr));
144.2711 -#endif
144.2712 +PNG_FP_EXPORT(125, float, png_get_pixel_aspect_ratio,
144.2713 +    (png_const_structp png_ptr, png_const_infop info_ptr));
144.2714 +PNG_FIXED_EXPORT(210, png_fixed_point, png_get_pixel_aspect_ratio_fixed,
144.2715 +    (png_const_structp png_ptr, png_const_infop info_ptr));
144.2716  
144.2717  /* Returns image x, y offset in pixels or microns, from oFFs chunk data. */
144.2718 -extern PNG_EXPORT(png_int_32, png_get_x_offset_pixels) PNGARG((png_structp
144.2719 -png_ptr, png_infop info_ptr));
144.2720 -extern PNG_EXPORT(png_int_32, png_get_y_offset_pixels) PNGARG((png_structp
144.2721 -png_ptr, png_infop info_ptr));
144.2722 -extern PNG_EXPORT(png_int_32, png_get_x_offset_microns) PNGARG((png_structp
144.2723 -png_ptr, png_infop info_ptr));
144.2724 -extern PNG_EXPORT(png_int_32, png_get_y_offset_microns) PNGARG((png_structp
144.2725 -png_ptr, png_infop info_ptr));
144.2726 +PNG_EXPORT(126, png_int_32, png_get_x_offset_pixels,
144.2727 +    (png_const_structp png_ptr, png_const_infop info_ptr));
144.2728 +PNG_EXPORT(127, png_int_32, png_get_y_offset_pixels,
144.2729 +    (png_const_structp png_ptr, png_const_infop info_ptr));
144.2730 +PNG_EXPORT(128, png_int_32, png_get_x_offset_microns,
144.2731 +    (png_const_structp png_ptr, png_const_infop info_ptr));
144.2732 +PNG_EXPORT(129, png_int_32, png_get_y_offset_microns,
144.2733 +    (png_const_structp png_ptr, png_const_infop info_ptr));
144.2734  
144.2735  #endif /* PNG_EASY_ACCESS_SUPPORTED */
144.2736  
144.2737  /* Returns pointer to signature string read from PNG header */
144.2738 -extern PNG_EXPORT(png_bytep,png_get_signature) PNGARG((png_structp png_ptr,
144.2739 -png_infop info_ptr));
144.2740 +PNG_EXPORT(130, png_const_bytep, png_get_signature,
144.2741 +    (png_const_structp png_ptr, png_infop info_ptr));
144.2742  
144.2743 -#if defined(PNG_bKGD_SUPPORTED)
144.2744 -extern PNG_EXPORT(png_uint_32,png_get_bKGD) PNGARG((png_structp png_ptr,
144.2745 -   png_infop info_ptr, png_color_16p *background));
144.2746 +#ifdef PNG_bKGD_SUPPORTED
144.2747 +PNG_EXPORT(131, png_uint_32, png_get_bKGD,
144.2748 +    (png_const_structp png_ptr, png_infop info_ptr,
144.2749 +    png_color_16p *background));
144.2750  #endif
144.2751  
144.2752 -#if defined(PNG_bKGD_SUPPORTED)
144.2753 -extern PNG_EXPORT(void,png_set_bKGD) PNGARG((png_structp png_ptr,
144.2754 -   png_infop info_ptr, png_color_16p background));
144.2755 +#ifdef PNG_bKGD_SUPPORTED
144.2756 +PNG_EXPORT(132, void, png_set_bKGD, (png_structp png_ptr, png_infop info_ptr,
144.2757 +    png_const_color_16p background));
144.2758  #endif
144.2759  
144.2760 -#if defined(PNG_cHRM_SUPPORTED)
144.2761 -#ifdef PNG_FLOATING_POINT_SUPPORTED
144.2762 -extern PNG_EXPORT(png_uint_32,png_get_cHRM) PNGARG((png_structp png_ptr,
144.2763 -   png_infop info_ptr, double *white_x, double *white_y, double *red_x,
144.2764 -   double *red_y, double *green_x, double *green_y, double *blue_x,
144.2765 -   double *blue_y));
144.2766 -#endif
144.2767 -#ifdef PNG_FIXED_POINT_SUPPORTED
144.2768 -extern PNG_EXPORT(png_uint_32,png_get_cHRM_fixed) PNGARG((png_structp png_ptr,
144.2769 -   png_infop info_ptr, png_fixed_point *int_white_x, png_fixed_point
144.2770 -   *int_white_y, png_fixed_point *int_red_x, png_fixed_point *int_red_y,
144.2771 -   png_fixed_point *int_green_x, png_fixed_point *int_green_y, png_fixed_point
144.2772 -   *int_blue_x, png_fixed_point *int_blue_y));
144.2773 +#ifdef PNG_cHRM_SUPPORTED
144.2774 +PNG_FP_EXPORT(133, png_uint_32, png_get_cHRM, (png_const_structp png_ptr,
144.2775 +   png_const_infop info_ptr, double *white_x, double *white_y, double *red_x,
144.2776 +    double *red_y, double *green_x, double *green_y, double *blue_x,
144.2777 +    double *blue_y));
144.2778 +#ifdef PNG_FIXED_POINT_SUPPORTED /* Otherwise not implemented */
144.2779 +PNG_FIXED_EXPORT(134, png_uint_32, png_get_cHRM_fixed,
144.2780 +    (png_const_structp png_ptr,
144.2781 +    png_const_infop info_ptr, png_fixed_point *int_white_x,
144.2782 +    png_fixed_point *int_white_y, png_fixed_point *int_red_x,
144.2783 +    png_fixed_point *int_red_y, png_fixed_point *int_green_x,
144.2784 +    png_fixed_point *int_green_y, png_fixed_point *int_blue_x,
144.2785 +    png_fixed_point *int_blue_y));
144.2786  #endif
144.2787  #endif
144.2788  
144.2789 -#if defined(PNG_cHRM_SUPPORTED)
144.2790 -#ifdef PNG_FLOATING_POINT_SUPPORTED
144.2791 -extern PNG_EXPORT(void,png_set_cHRM) PNGARG((png_structp png_ptr,
144.2792 -   png_infop info_ptr, double white_x, double white_y, double red_x,
144.2793 -   double red_y, double green_x, double green_y, double blue_x, double blue_y));
144.2794 -#endif
144.2795 -#ifdef PNG_FIXED_POINT_SUPPORTED
144.2796 -extern PNG_EXPORT(void,png_set_cHRM_fixed) PNGARG((png_structp png_ptr,
144.2797 -   png_infop info_ptr, png_fixed_point int_white_x, png_fixed_point int_white_y,
144.2798 -   png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point
144.2799 -   int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x,
144.2800 -   png_fixed_point int_blue_y));
144.2801 -#endif
144.2802 +#ifdef PNG_cHRM_SUPPORTED
144.2803 +PNG_FP_EXPORT(135, void, png_set_cHRM,
144.2804 +    (png_structp png_ptr, png_infop info_ptr,
144.2805 +    double white_x, double white_y, double red_x, double red_y, double green_x,
144.2806 +    double green_y, double blue_x, double blue_y));
144.2807 +PNG_FIXED_EXPORT(136, void, png_set_cHRM_fixed, (png_structp png_ptr,
144.2808 +    png_infop info_ptr, png_fixed_point int_white_x,
144.2809 +    png_fixed_point int_white_y, png_fixed_point int_red_x,
144.2810 +    png_fixed_point int_red_y, png_fixed_point int_green_x,
144.2811 +    png_fixed_point int_green_y, png_fixed_point int_blue_x,
144.2812 +    png_fixed_point int_blue_y));
144.2813  #endif
144.2814  
144.2815 -#if defined(PNG_gAMA_SUPPORTED)
144.2816 -#ifdef PNG_FLOATING_POINT_SUPPORTED
144.2817 -extern PNG_EXPORT(png_uint_32,png_get_gAMA) PNGARG((png_structp png_ptr,
144.2818 -   png_infop info_ptr, double *file_gamma));
144.2819 -#endif
144.2820 -extern PNG_EXPORT(png_uint_32,png_get_gAMA_fixed) PNGARG((png_structp png_ptr,
144.2821 -   png_infop info_ptr, png_fixed_point *int_file_gamma));
144.2822 +#ifdef PNG_gAMA_SUPPORTED
144.2823 +PNG_FP_EXPORT(137, png_uint_32, png_get_gAMA,
144.2824 +    (png_const_structp png_ptr, png_const_infop info_ptr,
144.2825 +    double *file_gamma));
144.2826 +PNG_FIXED_EXPORT(138, png_uint_32, png_get_gAMA_fixed,
144.2827 +    (png_const_structp png_ptr, png_const_infop info_ptr,
144.2828 +    png_fixed_point *int_file_gamma));
144.2829  #endif
144.2830  
144.2831 -#if defined(PNG_gAMA_SUPPORTED)
144.2832 -#ifdef PNG_FLOATING_POINT_SUPPORTED
144.2833 -extern PNG_EXPORT(void,png_set_gAMA) PNGARG((png_structp png_ptr,
144.2834 -   png_infop info_ptr, double file_gamma));
144.2835 -#endif
144.2836 -extern PNG_EXPORT(void,png_set_gAMA_fixed) PNGARG((png_structp png_ptr,
144.2837 -   png_infop info_ptr, png_fixed_point int_file_gamma));
144.2838 +#ifdef PNG_gAMA_SUPPORTED
144.2839 +PNG_FP_EXPORT(139, void, png_set_gAMA, (png_structp png_ptr,
144.2840 +    png_infop info_ptr, double file_gamma));
144.2841 +PNG_FIXED_EXPORT(140, void, png_set_gAMA_fixed, (png_structp png_ptr,
144.2842 +    png_infop info_ptr, png_fixed_point int_file_gamma));
144.2843  #endif
144.2844  
144.2845 -#if defined(PNG_hIST_SUPPORTED)
144.2846 -extern PNG_EXPORT(png_uint_32,png_get_hIST) PNGARG((png_structp png_ptr,
144.2847 -   png_infop info_ptr, png_uint_16p *hist));
144.2848 +#ifdef PNG_hIST_SUPPORTED
144.2849 +PNG_EXPORT(141, png_uint_32, png_get_hIST,
144.2850 +    (png_const_structp png_ptr, png_const_infop info_ptr,
144.2851 +    png_uint_16p *hist));
144.2852  #endif
144.2853  
144.2854 -#if defined(PNG_hIST_SUPPORTED)
144.2855 -extern PNG_EXPORT(void,png_set_hIST) PNGARG((png_structp png_ptr,
144.2856 -   png_infop info_ptr, png_uint_16p hist));
144.2857 +#ifdef PNG_hIST_SUPPORTED
144.2858 +PNG_EXPORT(142, void, png_set_hIST, (png_structp png_ptr,
144.2859 +    png_infop info_ptr, png_const_uint_16p hist));
144.2860  #endif
144.2861  
144.2862 -extern PNG_EXPORT(png_uint_32,png_get_IHDR) PNGARG((png_structp png_ptr,
144.2863 -   png_infop info_ptr, png_uint_32 *width, png_uint_32 *height,
144.2864 -   int *bit_depth, int *color_type, int *interlace_method,
144.2865 -   int *compression_method, int *filter_method));
144.2866 +PNG_EXPORT(143, png_uint_32, png_get_IHDR,
144.2867 +    (png_structp png_ptr, png_infop info_ptr,
144.2868 +    png_uint_32 *width, png_uint_32 *height, int *bit_depth, int *color_type,
144.2869 +    int *interlace_method, int *compression_method, int *filter_method));
144.2870  
144.2871 -extern PNG_EXPORT(void,png_set_IHDR) PNGARG((png_structp png_ptr,
144.2872 -   png_infop info_ptr, png_uint_32 width, png_uint_32 height, int bit_depth,
144.2873 -   int color_type, int interlace_method, int compression_method,
144.2874 -   int filter_method));
144.2875 +PNG_EXPORT(144, void, png_set_IHDR,
144.2876 +    (png_structp png_ptr, png_infop info_ptr,
144.2877 +    png_uint_32 width, png_uint_32 height, int bit_depth, int color_type,
144.2878 +    int interlace_method, int compression_method, int filter_method));
144.2879  
144.2880 -#if defined(PNG_oFFs_SUPPORTED)
144.2881 -extern PNG_EXPORT(png_uint_32,png_get_oFFs) PNGARG((png_structp png_ptr,
144.2882 -   png_infop info_ptr, png_int_32 *offset_x, png_int_32 *offset_y,
144.2883 -   int *unit_type));
144.2884 +#ifdef PNG_oFFs_SUPPORTED
144.2885 +PNG_EXPORT(145, png_uint_32, png_get_oFFs,
144.2886 +    (png_const_structp png_ptr, png_const_infop info_ptr,
144.2887 +    png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type));
144.2888  #endif
144.2889  
144.2890 -#if defined(PNG_oFFs_SUPPORTED)
144.2891 -extern PNG_EXPORT(void,png_set_oFFs) PNGARG((png_structp png_ptr,
144.2892 -   png_infop info_ptr, png_int_32 offset_x, png_int_32 offset_y,
144.2893 -   int unit_type));
144.2894 +#ifdef PNG_oFFs_SUPPORTED
144.2895 +PNG_EXPORT(146, void, png_set_oFFs,
144.2896 +    (png_structp png_ptr, png_infop info_ptr,
144.2897 +    png_int_32 offset_x, png_int_32 offset_y, int unit_type));
144.2898  #endif
144.2899  
144.2900 -#if defined(PNG_pCAL_SUPPORTED)
144.2901 -extern PNG_EXPORT(png_uint_32,png_get_pCAL) PNGARG((png_structp png_ptr,
144.2902 -   png_infop info_ptr, png_charp *purpose, png_int_32 *X0, png_int_32 *X1,
144.2903 -   int *type, int *nparams, png_charp *units, png_charpp *params));
144.2904 +#ifdef PNG_pCAL_SUPPORTED
144.2905 +PNG_EXPORT(147, png_uint_32, png_get_pCAL,
144.2906 +    (png_const_structp png_ptr, png_const_infop info_ptr,
144.2907 +    png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type,
144.2908 +    int *nparams,
144.2909 +    png_charp *units, png_charpp *params));
144.2910  #endif
144.2911  
144.2912 -#if defined(PNG_pCAL_SUPPORTED)
144.2913 -extern PNG_EXPORT(void,png_set_pCAL) PNGARG((png_structp png_ptr,
144.2914 -   png_infop info_ptr, png_charp purpose, png_int_32 X0, png_int_32 X1,
144.2915 -   int type, int nparams, png_charp units, png_charpp params));
144.2916 +#ifdef PNG_pCAL_SUPPORTED
144.2917 +PNG_EXPORT(148, void, png_set_pCAL, (png_structp png_ptr,
144.2918 +    png_infop info_ptr,
144.2919 +    png_const_charp purpose, png_int_32 X0, png_int_32 X1, int type,
144.2920 +    int nparams, png_const_charp units, png_charpp params));
144.2921  #endif
144.2922  
144.2923 -#if defined(PNG_pHYs_SUPPORTED)
144.2924 -extern PNG_EXPORT(png_uint_32,png_get_pHYs) PNGARG((png_structp png_ptr,
144.2925 -   png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type));
144.2926 +#ifdef PNG_pHYs_SUPPORTED
144.2927 +PNG_EXPORT(149, png_uint_32, png_get_pHYs,
144.2928 +    (png_const_structp png_ptr, png_const_infop info_ptr,
144.2929 +    png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type));
144.2930  #endif
144.2931  
144.2932 -#if defined(PNG_pHYs_SUPPORTED)
144.2933 -extern PNG_EXPORT(void,png_set_pHYs) PNGARG((png_structp png_ptr,
144.2934 -   png_infop info_ptr, png_uint_32 res_x, png_uint_32 res_y, int unit_type));
144.2935 +#ifdef PNG_pHYs_SUPPORTED
144.2936 +PNG_EXPORT(150, void, png_set_pHYs,
144.2937 +    (png_structp png_ptr, png_infop info_ptr,
144.2938 +    png_uint_32 res_x, png_uint_32 res_y, int unit_type));
144.2939  #endif
144.2940  
144.2941 -extern PNG_EXPORT(png_uint_32,png_get_PLTE) PNGARG((png_structp png_ptr,
144.2942 -   png_infop info_ptr, png_colorp *palette, int *num_palette));
144.2943 +PNG_EXPORT(151, png_uint_32, png_get_PLTE,
144.2944 +    (png_const_structp png_ptr, png_const_infop info_ptr,
144.2945 +    png_colorp *palette, int *num_palette));
144.2946  
144.2947 -extern PNG_EXPORT(void,png_set_PLTE) PNGARG((png_structp png_ptr,
144.2948 -   png_infop info_ptr, png_colorp palette, int num_palette));
144.2949 +PNG_EXPORT(152, void, png_set_PLTE,
144.2950 +    (png_structp png_ptr, png_infop info_ptr,
144.2951 +    png_const_colorp palette, int num_palette));
144.2952  
144.2953 -#if defined(PNG_sBIT_SUPPORTED)
144.2954 -extern PNG_EXPORT(png_uint_32,png_get_sBIT) PNGARG((png_structp png_ptr,
144.2955 -   png_infop info_ptr, png_color_8p *sig_bit));
144.2956 +#ifdef PNG_sBIT_SUPPORTED
144.2957 +PNG_EXPORT(153, png_uint_32, png_get_sBIT,
144.2958 +    (png_const_structp png_ptr, png_infop info_ptr,
144.2959 +    png_color_8p *sig_bit));
144.2960  #endif
144.2961  
144.2962 -#if defined(PNG_sBIT_SUPPORTED)
144.2963 -extern PNG_EXPORT(void,png_set_sBIT) PNGARG((png_structp png_ptr,
144.2964 -   png_infop info_ptr, png_color_8p sig_bit));
144.2965 +#ifdef PNG_sBIT_SUPPORTED
144.2966 +PNG_EXPORT(154, void, png_set_sBIT,
144.2967 +    (png_structp png_ptr, png_infop info_ptr, png_const_color_8p sig_bit));
144.2968  #endif
144.2969  
144.2970 -#if defined(PNG_sRGB_SUPPORTED)
144.2971 -extern PNG_EXPORT(png_uint_32,png_get_sRGB) PNGARG((png_structp png_ptr,
144.2972 -   png_infop info_ptr, int *intent));
144.2973 +#ifdef PNG_sRGB_SUPPORTED
144.2974 +PNG_EXPORT(155, png_uint_32, png_get_sRGB, (png_const_structp png_ptr,
144.2975 +    png_const_infop info_ptr, int *file_srgb_intent));
144.2976  #endif
144.2977  
144.2978 -#if defined(PNG_sRGB_SUPPORTED)
144.2979 -extern PNG_EXPORT(void,png_set_sRGB) PNGARG((png_structp png_ptr,
144.2980 -   png_infop info_ptr, int intent));
144.2981 -extern PNG_EXPORT(void,png_set_sRGB_gAMA_and_cHRM) PNGARG((png_structp png_ptr,
144.2982 -   png_infop info_ptr, int intent));
144.2983 +#ifdef PNG_sRGB_SUPPORTED
144.2984 +PNG_EXPORT(156, void, png_set_sRGB,
144.2985 +    (png_structp png_ptr, png_infop info_ptr, int srgb_intent));
144.2986 +PNG_EXPORT(157, void, png_set_sRGB_gAMA_and_cHRM, (png_structp png_ptr,
144.2987 +    png_infop info_ptr, int srgb_intent));
144.2988  #endif
144.2989  
144.2990 -#if defined(PNG_iCCP_SUPPORTED)
144.2991 -extern PNG_EXPORT(png_uint_32,png_get_iCCP) PNGARG((png_structp png_ptr,
144.2992 -   png_infop info_ptr, png_charpp name, int *compression_type,
144.2993 -   png_charpp profile, png_uint_32 *proflen));
144.2994 -   /* Note to maintainer: profile should be png_bytepp */
144.2995 +#ifdef PNG_iCCP_SUPPORTED
144.2996 +PNG_EXPORT(158, png_uint_32, png_get_iCCP,
144.2997 +    (png_const_structp png_ptr, png_const_infop info_ptr,
144.2998 +    png_charpp name, int *compression_type, png_bytepp profile,
144.2999 +    png_uint_32 *proflen));
144.3000  #endif
144.3001  
144.3002 -#if defined(PNG_iCCP_SUPPORTED)
144.3003 -extern PNG_EXPORT(void,png_set_iCCP) PNGARG((png_structp png_ptr,
144.3004 -   png_infop info_ptr, png_charp name, int compression_type,
144.3005 -   png_charp profile, png_uint_32 proflen));
144.3006 -   /* Note to maintainer: profile should be png_bytep */
144.3007 +#ifdef PNG_iCCP_SUPPORTED
144.3008 +PNG_EXPORT(159, void, png_set_iCCP,
144.3009 +    (png_structp png_ptr, png_infop info_ptr,
144.3010 +    png_const_charp name, int compression_type, png_const_bytep profile,
144.3011 +    png_uint_32 proflen));
144.3012  #endif
144.3013  
144.3014 -#if defined(PNG_sPLT_SUPPORTED)
144.3015 -extern PNG_EXPORT(png_uint_32,png_get_sPLT) PNGARG((png_structp png_ptr,
144.3016 -   png_infop info_ptr, png_sPLT_tpp entries));
144.3017 +#ifdef PNG_sPLT_SUPPORTED
144.3018 +PNG_EXPORT(160, png_uint_32, png_get_sPLT,
144.3019 +    (png_const_structp png_ptr, png_const_infop info_ptr,
144.3020 +    png_sPLT_tpp entries));
144.3021  #endif
144.3022  
144.3023 -#if defined(PNG_sPLT_SUPPORTED)
144.3024 -extern PNG_EXPORT(void,png_set_sPLT) PNGARG((png_structp png_ptr,
144.3025 -   png_infop info_ptr, png_sPLT_tp entries, int nentries));
144.3026 +#ifdef PNG_sPLT_SUPPORTED
144.3027 +PNG_EXPORT(161, void, png_set_sPLT,
144.3028 +    (png_structp png_ptr, png_infop info_ptr,
144.3029 +    png_const_sPLT_tp entries, int nentries));
144.3030  #endif
144.3031  
144.3032 -#if defined(PNG_TEXT_SUPPORTED)
144.3033 +#ifdef PNG_TEXT_SUPPORTED
144.3034  /* png_get_text also returns the number of text chunks in *num_text */
144.3035 -extern PNG_EXPORT(png_uint_32,png_get_text) PNGARG((png_structp png_ptr,
144.3036 -   png_infop info_ptr, png_textp *text_ptr, int *num_text));
144.3037 +PNG_EXPORT(162, png_uint_32, png_get_text,
144.3038 +    (png_const_structp png_ptr, png_const_infop info_ptr,
144.3039 +    png_textp *text_ptr, int *num_text));
144.3040  #endif
144.3041  
144.3042 -/*
144.3043 - *  Note while png_set_text() will accept a structure whose text,
144.3044 - *  language, and  translated keywords are NULL pointers, the structure
144.3045 - *  returned by png_get_text will always contain regular
144.3046 - *  zero-terminated C strings.  They might be empty strings but
144.3047 - *  they will never be NULL pointers.
144.3048 +/* Note while png_set_text() will accept a structure whose text,
144.3049 + * language, and  translated keywords are NULL pointers, the structure
144.3050 + * returned by png_get_text will always contain regular
144.3051 + * zero-terminated C strings.  They might be empty strings but
144.3052 + * they will never be NULL pointers.
144.3053   */
144.3054  
144.3055 -#if defined(PNG_TEXT_SUPPORTED)
144.3056 -extern PNG_EXPORT(void,png_set_text) PNGARG((png_structp png_ptr,
144.3057 -   png_infop info_ptr, png_textp text_ptr, int num_text));
144.3058 +#ifdef PNG_TEXT_SUPPORTED
144.3059 +PNG_EXPORT(163, void, png_set_text,
144.3060 +    (png_structp png_ptr, png_infop info_ptr,
144.3061 +    png_const_textp text_ptr, int num_text));
144.3062  #endif
144.3063  
144.3064 -#if defined(PNG_tIME_SUPPORTED)
144.3065 -extern PNG_EXPORT(png_uint_32,png_get_tIME) PNGARG((png_structp png_ptr,
144.3066 -   png_infop info_ptr, png_timep *mod_time));
144.3067 +#ifdef PNG_tIME_SUPPORTED
144.3068 +PNG_EXPORT(164, png_uint_32, png_get_tIME,
144.3069 +    (png_const_structp png_ptr, png_infop info_ptr, png_timep *mod_time));
144.3070  #endif
144.3071  
144.3072 -#if defined(PNG_tIME_SUPPORTED)
144.3073 -extern PNG_EXPORT(void,png_set_tIME) PNGARG((png_structp png_ptr,
144.3074 -   png_infop info_ptr, png_timep mod_time));
144.3075 +#ifdef PNG_tIME_SUPPORTED
144.3076 +PNG_EXPORT(165, void, png_set_tIME,
144.3077 +    (png_structp png_ptr, png_infop info_ptr, png_const_timep mod_time));
144.3078  #endif
144.3079  
144.3080 -#if defined(PNG_tRNS_SUPPORTED)
144.3081 -extern PNG_EXPORT(png_uint_32,png_get_tRNS) PNGARG((png_structp png_ptr,
144.3082 -   png_infop info_ptr, png_bytep *trans, int *num_trans,
144.3083 -   png_color_16p *trans_values));
144.3084 +#ifdef PNG_tRNS_SUPPORTED
144.3085 +PNG_EXPORT(166, png_uint_32, png_get_tRNS,
144.3086 +    (png_const_structp png_ptr, png_infop info_ptr,
144.3087 +    png_bytep *trans_alpha, int *num_trans, png_color_16p *trans_color));
144.3088  #endif
144.3089  
144.3090 -#if defined(PNG_tRNS_SUPPORTED)
144.3091 -extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr,
144.3092 -   png_infop info_ptr, png_bytep trans, int num_trans,
144.3093 -   png_color_16p trans_values));
144.3094 +#ifdef PNG_tRNS_SUPPORTED
144.3095 +PNG_EXPORT(167, void, png_set_tRNS,
144.3096 +    (png_structp png_ptr, png_infop info_ptr,
144.3097 +    png_const_bytep trans_alpha, int num_trans,
144.3098 +    png_const_color_16p trans_color));
144.3099  #endif
144.3100  
144.3101 -#if defined(PNG_tRNS_SUPPORTED)
144.3102 +#ifdef PNG_sCAL_SUPPORTED
144.3103 +PNG_FP_EXPORT(168, png_uint_32, png_get_sCAL,
144.3104 +    (png_const_structp png_ptr, png_const_infop info_ptr,
144.3105 +    int *unit, double *width, double *height));
144.3106 +#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
144.3107 +/* NOTE: this API is currently implemented using floating point arithmetic,
144.3108 + * consequently it can only be used on systems with floating point support.
144.3109 + * In any case the range of values supported by png_fixed_point is small and it
144.3110 + * is highly recommended that png_get_sCAL_s be used instead.
144.3111 + */
144.3112 +PNG_FIXED_EXPORT(214, png_uint_32, png_get_sCAL_fixed,
144.3113 +    (png_structp png_ptr, png_const_infop info_ptr, int *unit,
144.3114 +    png_fixed_point *width,
144.3115 +    png_fixed_point *height));
144.3116  #endif
144.3117 +PNG_EXPORT(169, png_uint_32, png_get_sCAL_s,
144.3118 +    (png_const_structp png_ptr, png_const_infop info_ptr,
144.3119 +    int *unit, png_charpp swidth, png_charpp sheight));
144.3120  
144.3121 -#if defined(PNG_sCAL_SUPPORTED)
144.3122 -#ifdef PNG_FLOATING_POINT_SUPPORTED
144.3123 -extern PNG_EXPORT(png_uint_32,png_get_sCAL) PNGARG((png_structp png_ptr,
144.3124 -   png_infop info_ptr, int *unit, double *width, double *height));
144.3125 -#else
144.3126 -#ifdef PNG_FIXED_POINT_SUPPORTED
144.3127 -extern PNG_EXPORT(png_uint_32,png_get_sCAL_s) PNGARG((png_structp png_ptr,
144.3128 -   png_infop info_ptr, int *unit, png_charpp swidth, png_charpp sheight));
144.3129 -#endif
144.3130 -#endif
144.3131 +PNG_FP_EXPORT(170, void, png_set_sCAL,
144.3132 +    (png_structp png_ptr, png_infop info_ptr,
144.3133 +    int unit, double width, double height));
144.3134 +PNG_FIXED_EXPORT(213, void, png_set_sCAL_fixed, (png_structp png_ptr,
144.3135 +   png_infop info_ptr, int unit, png_fixed_point width,
144.3136 +   png_fixed_point height));
144.3137 +PNG_EXPORT(171, void, png_set_sCAL_s,
144.3138 +    (png_structp png_ptr, png_infop info_ptr,
144.3139 +    int unit, png_const_charp swidth, png_const_charp sheight));
144.3140  #endif /* PNG_sCAL_SUPPORTED */
144.3141  
144.3142 -#if defined(PNG_sCAL_SUPPORTED)
144.3143 -#ifdef PNG_FLOATING_POINT_SUPPORTED
144.3144 -extern PNG_EXPORT(void,png_set_sCAL) PNGARG((png_structp png_ptr,
144.3145 -   png_infop info_ptr, int unit, double width, double height));
144.3146 -#else
144.3147 -#ifdef PNG_FIXED_POINT_SUPPORTED
144.3148 -extern PNG_EXPORT(void,png_set_sCAL_s) PNGARG((png_structp png_ptr,
144.3149 -   png_infop info_ptr, int unit, png_charp swidth, png_charp sheight));
144.3150 -#endif
144.3151 -#endif
144.3152 -#endif /* PNG_sCAL_SUPPORTED || PNG_WRITE_sCAL_SUPPORTED */
144.3153 -
144.3154 -#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
144.3155 -/* provide a list of chunks and how they are to be handled, if the built-in
144.3156 +#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
144.3157 +/* Provide a list of chunks and how they are to be handled, if the built-in
144.3158     handling or default unknown chunk handling is not desired.  Any chunks not
144.3159     listed will be handled in the default manner.  The IHDR and IEND chunks
144.3160     must not be listed.
144.3161 @@ -2435,101 +2315,49 @@
144.3162             = 2: keep only if safe-to-copy
144.3163             = 3: keep even if unsafe-to-copy
144.3164  */
144.3165 -extern PNG_EXPORT(void, png_set_keep_unknown_chunks) PNGARG((png_structp
144.3166 -   png_ptr, int keep, png_bytep chunk_list, int num_chunks));
144.3167 -extern PNG_EXPORT(void, png_set_unknown_chunks) PNGARG((png_structp png_ptr,
144.3168 -   png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns));
144.3169 -extern PNG_EXPORT(void, png_set_unknown_chunk_location)
144.3170 -   PNGARG((png_structp png_ptr, png_infop info_ptr, int chunk, int location));
144.3171 -extern PNG_EXPORT(png_uint_32,png_get_unknown_chunks) PNGARG((png_structp
144.3172 -   png_ptr, png_infop info_ptr, png_unknown_chunkpp entries));
144.3173 +PNG_EXPORT(172, void, png_set_keep_unknown_chunks,
144.3174 +    (png_structp png_ptr, int keep,
144.3175 +    png_const_bytep chunk_list, int num_chunks));
144.3176 +PNG_EXPORT(173, int, png_handle_as_unknown, (png_structp png_ptr,
144.3177 +    png_const_bytep chunk_name));
144.3178  #endif
144.3179 -#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
144.3180 -PNG_EXPORT(int,png_handle_as_unknown) PNGARG((png_structp png_ptr, png_bytep
144.3181 -   chunk_name));
144.3182 +#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
144.3183 +PNG_EXPORT(174, void, png_set_unknown_chunks, (png_structp png_ptr,
144.3184 +    png_infop info_ptr, png_const_unknown_chunkp unknowns,
144.3185 +    int num_unknowns));
144.3186 +PNG_EXPORT(175, void, png_set_unknown_chunk_location,
144.3187 +    (png_structp png_ptr, png_infop info_ptr, int chunk, int location));
144.3188 +PNG_EXPORT(176, int, png_get_unknown_chunks, (png_const_structp png_ptr,
144.3189 +    png_const_infop info_ptr, png_unknown_chunkpp entries));
144.3190  #endif
144.3191  
144.3192  /* Png_free_data() will turn off the "valid" flag for anything it frees.
144.3193 -   If you need to turn it off for a chunk that your application has freed,
144.3194 -   you can use png_set_invalid(png_ptr, info_ptr, PNG_INFO_CHNK); */
144.3195 -extern PNG_EXPORT(void, png_set_invalid) PNGARG((png_structp png_ptr,
144.3196 -   png_infop info_ptr, int mask));
144.3197 + * If you need to turn it off for a chunk that your application has freed,
144.3198 + * you can use png_set_invalid(png_ptr, info_ptr, PNG_INFO_CHNK);
144.3199 + */
144.3200 +PNG_EXPORT(177, void, png_set_invalid,
144.3201 +    (png_structp png_ptr, png_infop info_ptr, int mask));
144.3202  
144.3203 -#if defined(PNG_INFO_IMAGE_SUPPORTED)
144.3204 +#ifdef PNG_INFO_IMAGE_SUPPORTED
144.3205  /* The "params" pointer is currently not used and is for future expansion. */
144.3206 -extern PNG_EXPORT(void, png_read_png) PNGARG((png_structp png_ptr,
144.3207 -                        png_infop info_ptr,
144.3208 -                        int transforms,
144.3209 -                        png_voidp params));
144.3210 -extern PNG_EXPORT(void, png_write_png) PNGARG((png_structp png_ptr,
144.3211 -                        png_infop info_ptr,
144.3212 -                        int transforms,
144.3213 -                        png_voidp params));
144.3214 +PNG_EXPORT(178, void, png_read_png, (png_structp png_ptr, png_infop info_ptr,
144.3215 +    int transforms, png_voidp params));
144.3216 +PNG_EXPORT(179, void, png_write_png, (png_structp png_ptr, png_infop info_ptr,
144.3217 +    int transforms, png_voidp params));
144.3218  #endif
144.3219  
144.3220 -/* Define PNG_DEBUG at compile time for debugging information.  Higher
144.3221 - * numbers for PNG_DEBUG mean more debugging information.  This has
144.3222 - * only been added since version 0.95 so it is not implemented throughout
144.3223 - * libpng yet, but more support will be added as needed.
144.3224 - */
144.3225 -#ifdef PNG_DEBUG
144.3226 -#if (PNG_DEBUG > 0)
144.3227 -#if !defined(PNG_DEBUG_FILE) && defined(_MSC_VER)
144.3228 -#include <crtdbg.h>
144.3229 -#if (PNG_DEBUG > 1)
144.3230 -#define png_debug(l,m)  _RPT0(_CRT_WARN,m)
144.3231 -#define png_debug1(l,m,p1)  _RPT1(_CRT_WARN,m,p1)
144.3232 -#define png_debug2(l,m,p1,p2) _RPT2(_CRT_WARN,m,p1,p2)
144.3233 -#endif
144.3234 -#else /* PNG_DEBUG_FILE || !_MSC_VER */
144.3235 -#ifndef PNG_DEBUG_FILE
144.3236 -#define PNG_DEBUG_FILE stderr
144.3237 -#endif /* PNG_DEBUG_FILE */
144.3238 -#if (PNG_DEBUG > 1)
144.3239 -#define png_debug(l,m) \
144.3240 -{ \
144.3241 -     int num_tabs=l; \
144.3242 -     fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
144.3243 -       (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":"")))); \
144.3244 -}
144.3245 -#define png_debug1(l,m,p1) \
144.3246 -{ \
144.3247 -     int num_tabs=l; \
144.3248 -     fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
144.3249 -       (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1); \
144.3250 -}
144.3251 -#define png_debug2(l,m,p1,p2) \
144.3252 -{ \
144.3253 -     int num_tabs=l; \
144.3254 -     fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
144.3255 -       (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1,p2); \
144.3256 -}
144.3257 -#endif /* (PNG_DEBUG > 1) */
144.3258 -#endif /* _MSC_VER */
144.3259 -#endif /* (PNG_DEBUG > 0) */
144.3260 -#endif /* PNG_DEBUG */
144.3261 -#ifndef png_debug
144.3262 -#define png_debug(l, m)
144.3263 -#endif
144.3264 -#ifndef png_debug1
144.3265 -#define png_debug1(l, m, p1)
144.3266 -#endif
144.3267 -#ifndef png_debug2
144.3268 -#define png_debug2(l, m, p1, p2)
144.3269 -#endif
144.3270 -
144.3271 -#if 0
144.3272 -extern PNG_EXPORT(png_bytep,png_sig_bytes) PNGARG((void));
144.3273 -#endif
144.3274 -
144.3275 -extern PNG_EXPORT(png_charp,png_get_copyright) PNGARG((png_structp png_ptr));
144.3276 -extern PNG_EXPORT(png_charp,png_get_header_ver) PNGARG((png_structp png_ptr));
144.3277 -extern PNG_EXPORT(png_charp,png_get_header_version) PNGARG((png_structp png_ptr));
144.3278 -extern PNG_EXPORT(png_charp,png_get_libpng_ver) PNGARG((png_structp png_ptr));
144.3279 +PNG_EXPORT(180, png_const_charp, png_get_copyright,
144.3280 +    (png_const_structp png_ptr));
144.3281 +PNG_EXPORT(181, png_const_charp, png_get_header_ver,
144.3282 +    (png_const_structp png_ptr));
144.3283 +PNG_EXPORT(182, png_const_charp, png_get_header_version,
144.3284 +    (png_const_structp png_ptr));
144.3285 +PNG_EXPORT(183, png_const_charp, png_get_libpng_ver,
144.3286 +    (png_const_structp png_ptr));
144.3287  
144.3288  #ifdef PNG_MNG_FEATURES_SUPPORTED
144.3289 -extern PNG_EXPORT(png_uint_32,png_permit_mng_features) PNGARG((png_structp
144.3290 -   png_ptr, png_uint_32 mng_features_permitted));
144.3291 +PNG_EXPORT(184, png_uint_32, png_permit_mng_features, (png_structp png_ptr,
144.3292 +    png_uint_32 mng_features_permitted));
144.3293  #endif
144.3294  
144.3295  /* For use in png_set_keep_unknown, added to version 1.2.6 */
144.3296 @@ -2538,93 +2366,140 @@
144.3297  #define PNG_HANDLE_CHUNK_IF_SAFE      2
144.3298  #define PNG_HANDLE_CHUNK_ALWAYS       3
144.3299  
144.3300 -/* Added to version 1.2.0 */
144.3301 -#if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
144.3302 -#if defined(PNG_MMX_CODE_SUPPORTED)
144.3303 -#define PNG_ASM_FLAG_MMX_SUPPORT_COMPILED  0x01  /* not user-settable */
144.3304 -#define PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU    0x02  /* not user-settable */
144.3305 -#define PNG_ASM_FLAG_MMX_READ_COMBINE_ROW  0x04
144.3306 -#define PNG_ASM_FLAG_MMX_READ_INTERLACE    0x08
144.3307 -#define PNG_ASM_FLAG_MMX_READ_FILTER_SUB   0x10
144.3308 -#define PNG_ASM_FLAG_MMX_READ_FILTER_UP    0x20
144.3309 -#define PNG_ASM_FLAG_MMX_READ_FILTER_AVG   0x40
144.3310 -#define PNG_ASM_FLAG_MMX_READ_FILTER_PAETH 0x80
144.3311 -#define PNG_ASM_FLAGS_INITIALIZED          0x80000000  /* not user-settable */
144.3312 -
144.3313 -#define PNG_MMX_READ_FLAGS ( PNG_ASM_FLAG_MMX_READ_COMBINE_ROW  \
144.3314 -                           | PNG_ASM_FLAG_MMX_READ_INTERLACE    \
144.3315 -                           | PNG_ASM_FLAG_MMX_READ_FILTER_SUB   \
144.3316 -                           | PNG_ASM_FLAG_MMX_READ_FILTER_UP    \
144.3317 -                           | PNG_ASM_FLAG_MMX_READ_FILTER_AVG   \
144.3318 -                           | PNG_ASM_FLAG_MMX_READ_FILTER_PAETH )
144.3319 -#define PNG_MMX_WRITE_FLAGS ( 0 )
144.3320 -
144.3321 -#define PNG_MMX_FLAGS ( PNG_ASM_FLAG_MMX_SUPPORT_COMPILED \
144.3322 -                      | PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU   \
144.3323 -                      | PNG_MMX_READ_FLAGS                \
144.3324 -                      | PNG_MMX_WRITE_FLAGS )
144.3325 -
144.3326 -#define PNG_SELECT_READ   1
144.3327 -#define PNG_SELECT_WRITE  2
144.3328 -#endif /* PNG_MMX_CODE_SUPPORTED */
144.3329 -
144.3330 -#if !defined(PNG_1_0_X)
144.3331 -/* pngget.c */
144.3332 -extern PNG_EXPORT(png_uint_32,png_get_mmx_flagmask)
144.3333 -   PNGARG((int flag_select, int *compilerID));
144.3334 -
144.3335 -/* pngget.c */
144.3336 -extern PNG_EXPORT(png_uint_32,png_get_asm_flagmask)
144.3337 -   PNGARG((int flag_select));
144.3338 -
144.3339 -/* pngget.c */
144.3340 -extern PNG_EXPORT(png_uint_32,png_get_asm_flags)
144.3341 -   PNGARG((png_structp png_ptr));
144.3342 -
144.3343 -/* pngget.c */
144.3344 -extern PNG_EXPORT(png_byte,png_get_mmx_bitdepth_threshold)
144.3345 -   PNGARG((png_structp png_ptr));
144.3346 -
144.3347 -/* pngget.c */
144.3348 -extern PNG_EXPORT(png_uint_32,png_get_mmx_rowbytes_threshold)
144.3349 -   PNGARG((png_structp png_ptr));
144.3350 -
144.3351 -/* pngset.c */
144.3352 -extern PNG_EXPORT(void,png_set_asm_flags)
144.3353 -   PNGARG((png_structp png_ptr, png_uint_32 asm_flags));
144.3354 -
144.3355 -/* pngset.c */
144.3356 -extern PNG_EXPORT(void,png_set_mmx_thresholds)
144.3357 -   PNGARG((png_structp png_ptr, png_byte mmx_bitdepth_threshold,
144.3358 -   png_uint_32 mmx_rowbytes_threshold));
144.3359 -
144.3360 -#endif /* PNG_1_0_X */
144.3361 -
144.3362 -#if !defined(PNG_1_0_X)
144.3363 -/* png.c, pnggccrd.c, or pngvcrd.c */
144.3364 -extern PNG_EXPORT(int,png_mmx_support) PNGARG((void));
144.3365 -#endif /* PNG_ASSEMBLER_CODE_SUPPORTED */
144.3366 -
144.3367  /* Strip the prepended error numbers ("#nnn ") from error and warning
144.3368 - * messages before passing them to the error or warning handler. */
144.3369 + * messages before passing them to the error or warning handler.
144.3370 + */
144.3371  #ifdef PNG_ERROR_NUMBERS_SUPPORTED
144.3372 -extern PNG_EXPORT(void,png_set_strip_error_numbers) PNGARG((png_structp
144.3373 -   png_ptr, png_uint_32 strip_mode));
144.3374 +PNG_EXPORT(185, void, png_set_strip_error_numbers,
144.3375 +    (png_structp png_ptr,
144.3376 +    png_uint_32 strip_mode));
144.3377  #endif
144.3378  
144.3379 -#endif /* PNG_1_0_X */
144.3380 -
144.3381 -/* Added at libpng-1.2.6 */
144.3382 +/* Added in libpng-1.2.6 */
144.3383  #ifdef PNG_SET_USER_LIMITS_SUPPORTED
144.3384 -extern PNG_EXPORT(void,png_set_user_limits) PNGARG((png_structp
144.3385 -   png_ptr, png_uint_32 user_width_max, png_uint_32 user_height_max));
144.3386 -extern PNG_EXPORT(png_uint_32,png_get_user_width_max) PNGARG((png_structp
144.3387 -   png_ptr));
144.3388 -extern PNG_EXPORT(png_uint_32,png_get_user_height_max) PNGARG((png_structp
144.3389 -   png_ptr));
144.3390 +PNG_EXPORT(186, void, png_set_user_limits, (png_structp png_ptr,
144.3391 +    png_uint_32 user_width_max, png_uint_32 user_height_max));
144.3392 +PNG_EXPORT(187, png_uint_32, png_get_user_width_max,
144.3393 +    (png_const_structp png_ptr));
144.3394 +PNG_EXPORT(188, png_uint_32, png_get_user_height_max,
144.3395 +    (png_const_structp png_ptr));
144.3396 +/* Added in libpng-1.4.0 */
144.3397 +PNG_EXPORT(189, void, png_set_chunk_cache_max, (png_structp png_ptr,
144.3398 +    png_uint_32 user_chunk_cache_max));
144.3399 +PNG_EXPORT(190, png_uint_32, png_get_chunk_cache_max,
144.3400 +    (png_const_structp png_ptr));
144.3401 +/* Added in libpng-1.4.1 */
144.3402 +PNG_EXPORT(191, void, png_set_chunk_malloc_max, (png_structp png_ptr,
144.3403 +    png_alloc_size_t user_chunk_cache_max));
144.3404 +PNG_EXPORT(192, png_alloc_size_t, png_get_chunk_malloc_max,
144.3405 +    (png_const_structp png_ptr));
144.3406  #endif
144.3407  
144.3408 -/* Maintainer: Put new public prototypes here ^, in libpng.3, and project defs */
144.3409 +#if defined(PNG_INCH_CONVERSIONS_SUPPORTED)
144.3410 +PNG_EXPORT(193, png_uint_32, png_get_pixels_per_inch,
144.3411 +    (png_const_structp png_ptr, png_const_infop info_ptr));
144.3412 +
144.3413 +PNG_EXPORT(194, png_uint_32, png_get_x_pixels_per_inch,
144.3414 +    (png_const_structp png_ptr, png_const_infop info_ptr));
144.3415 +
144.3416 +PNG_EXPORT(195, png_uint_32, png_get_y_pixels_per_inch,
144.3417 +    (png_const_structp png_ptr, png_const_infop info_ptr));
144.3418 +
144.3419 +PNG_FP_EXPORT(196, float, png_get_x_offset_inches,
144.3420 +    (png_const_structp png_ptr, png_const_infop info_ptr));
144.3421 +#ifdef PNG_FIXED_POINT_SUPPORTED /* otherwise not implemented. */
144.3422 +PNG_FIXED_EXPORT(211, png_fixed_point, png_get_x_offset_inches_fixed,
144.3423 +    (png_structp png_ptr, png_const_infop info_ptr));
144.3424 +#endif
144.3425 +
144.3426 +PNG_FP_EXPORT(197, float, png_get_y_offset_inches, (png_const_structp png_ptr,
144.3427 +    png_const_infop info_ptr));
144.3428 +#ifdef PNG_FIXED_POINT_SUPPORTED /* otherwise not implemented. */
144.3429 +PNG_FIXED_EXPORT(212, png_fixed_point, png_get_y_offset_inches_fixed,
144.3430 +    (png_structp png_ptr, png_const_infop info_ptr));
144.3431 +#endif
144.3432 +
144.3433 +#  ifdef PNG_pHYs_SUPPORTED
144.3434 +PNG_EXPORT(198, png_uint_32, png_get_pHYs_dpi, (png_const_structp png_ptr,
144.3435 +    png_const_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y,
144.3436 +    int *unit_type));
144.3437 +#  endif /* PNG_pHYs_SUPPORTED */
144.3438 +#endif  /* PNG_INCH_CONVERSIONS_SUPPORTED */
144.3439 +
144.3440 +/* Added in libpng-1.4.0 */
144.3441 +#ifdef PNG_IO_STATE_SUPPORTED
144.3442 +PNG_EXPORT(199, png_uint_32, png_get_io_state, (png_structp png_ptr));
144.3443 +
144.3444 +PNG_EXPORTA(200, png_const_bytep, png_get_io_chunk_name,
144.3445 +    (png_structp png_ptr), PNG_DEPRECATED);
144.3446 +PNG_EXPORT(216, png_uint_32, png_get_io_chunk_type,
144.3447 +    (png_const_structp png_ptr));
144.3448 +
144.3449 +/* The flags returned by png_get_io_state() are the following: */
144.3450 +#  define PNG_IO_NONE        0x0000   /* no I/O at this moment */
144.3451 +#  define PNG_IO_READING     0x0001   /* currently reading */
144.3452 +#  define PNG_IO_WRITING     0x0002   /* currently writing */
144.3453 +#  define PNG_IO_SIGNATURE   0x0010   /* currently at the file signature */
144.3454 +#  define PNG_IO_CHUNK_HDR   0x0020   /* currently at the chunk header */
144.3455 +#  define PNG_IO_CHUNK_DATA  0x0040   /* currently at the chunk data */
144.3456 +#  define PNG_IO_CHUNK_CRC   0x0080   /* currently at the chunk crc */
144.3457 +#  define PNG_IO_MASK_OP     0x000f   /* current operation: reading/writing */
144.3458 +#  define PNG_IO_MASK_LOC    0x00f0   /* current location: sig/hdr/data/crc */
144.3459 +#endif /* ?PNG_IO_STATE_SUPPORTED */
144.3460 +
144.3461 +/* Interlace support.  The following macros are always defined so that if
144.3462 + * libpng interlace handling is turned off the macros may be used to handle
144.3463 + * interlaced images within the application.
144.3464 + */
144.3465 +#define PNG_INTERLACE_ADAM7_PASSES 7
144.3466 +
144.3467 +/* Two macros to return the first row and first column of the original,
144.3468 + * full, image which appears in a given pass.  'pass' is in the range 0
144.3469 + * to 6 and the result is in the range 0 to 7.
144.3470 + */
144.3471 +#define PNG_PASS_START_ROW(pass) (((1U&~(pass))<<(3-((pass)>>1)))&7)
144.3472 +#define PNG_PASS_START_COL(pass) (((1U& (pass))<<(3-(((pass)+1)>>1)))&7)
144.3473 +
144.3474 +/* Two macros to help evaluate the number of rows or columns in each
144.3475 + * pass.  This is expressed as a shift - effectively log2 of the number or
144.3476 + * rows or columns in each 8x8 tile of the original image.
144.3477 + */
144.3478 +#define PNG_PASS_ROW_SHIFT(pass) ((pass)>2?(8-(pass))>>1:3)
144.3479 +#define PNG_PASS_COL_SHIFT(pass) ((pass)>1?(7-(pass))>>1:3)
144.3480 +
144.3481 +/* Hence two macros to determine the number of rows or columns in a given
144.3482 + * pass of an image given its height or width.  In fact these macros may
144.3483 + * return non-zero even though the sub-image is empty, because the other
144.3484 + * dimension may be empty for a small image.
144.3485 + */
144.3486 +#define PNG_PASS_ROWS(height, pass) (((height)+(((1<<PNG_PASS_ROW_SHIFT(pass))\
144.3487 +   -1)-PNG_PASS_START_ROW(pass)))>>PNG_PASS_ROW_SHIFT(pass))
144.3488 +#define PNG_PASS_COLS(width, pass) (((width)+(((1<<PNG_PASS_COL_SHIFT(pass))\
144.3489 +   -1)-PNG_PASS_START_COL(pass)))>>PNG_PASS_COL_SHIFT(pass))
144.3490 +
144.3491 +/* For the reader row callbacks (both progressive and sequential) it is
144.3492 + * necessary to find the row in the output image given a row in an interlaced
144.3493 + * image, so two more macros:
144.3494 + */
144.3495 +#define PNG_ROW_FROM_PASS_ROW(yIn, pass) \
144.3496 +   (((yIn)<<PNG_PASS_ROW_SHIFT(pass))+PNG_PASS_START_ROW(pass))
144.3497 +#define PNG_COL_FROM_PASS_COL(xIn, pass) \
144.3498 +   (((xIn)<<PNG_PASS_COL_SHIFT(pass))+PNG_PASS_START_COL(pass))
144.3499 +
144.3500 +/* Two macros which return a boolean (0 or 1) saying whether the given row
144.3501 + * or column is in a particular pass.  These use a common utility macro that
144.3502 + * returns a mask for a given pass - the offset 'off' selects the row or
144.3503 + * column version.  The mask has the appropriate bit set for each column in
144.3504 + * the tile.
144.3505 + */
144.3506 +#define PNG_PASS_MASK(pass,off) ( \
144.3507 +   ((0x110145AFU>>(((7-(off))-(pass))<<2)) & 0xFU) | \
144.3508 +   ((0x01145AF0U>>(((7-(off))-(pass))<<2)) & 0xF0U))
144.3509 +
144.3510 +#define PNG_ROW_IN_INTERLACE_PASS(y, pass) \
144.3511 +   ((PNG_PASS_MASK(pass,0) >> ((y)&7)) & 1)
144.3512 +#define PNG_COL_IN_INTERLACE_PASS(x, pass) \
144.3513 +   ((PNG_PASS_MASK(pass,1) >> ((x)&7)) & 1)
144.3514  
144.3515  #ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED
144.3516  /* With these routines we avoid an integer divide, which will be slower on
144.3517 @@ -2639,913 +2514,103 @@
144.3518   * [Optimized code by Greg Roelofs and Mark Adler...blame us for bugs. :-) ]
144.3519   */
144.3520  
144.3521 - /* fg and bg should be in `gamma 1.0' space; alpha is the opacity          */
144.3522 + /* fg and bg should be in `gamma 1.0' space; alpha is the opacity */
144.3523  
144.3524 -#  define png_composite(composite, fg, alpha, bg)                            \
144.3525 -     { png_uint_16 temp = (png_uint_16)((png_uint_16)(fg) * (png_uint_16)(alpha) \
144.3526 -                        +        (png_uint_16)(bg)*(png_uint_16)(255 -       \
144.3527 -                        (png_uint_16)(alpha)) + (png_uint_16)128);           \
144.3528 +#  define png_composite(composite, fg, alpha, bg)         \
144.3529 +     { png_uint_16 temp = (png_uint_16)((png_uint_16)(fg) \
144.3530 +           * (png_uint_16)(alpha)                         \
144.3531 +           + (png_uint_16)(bg)*(png_uint_16)(255          \
144.3532 +           - (png_uint_16)(alpha)) + (png_uint_16)128);   \
144.3533         (composite) = (png_byte)((temp + (temp >> 8)) >> 8); }
144.3534  
144.3535 -#  define png_composite_16(composite, fg, alpha, bg)                         \
144.3536 -     { png_uint_32 temp = (png_uint_32)((png_uint_32)(fg) * (png_uint_32)(alpha) \
144.3537 -                        + (png_uint_32)(bg)*(png_uint_32)(65535L -           \
144.3538 -                        (png_uint_32)(alpha)) + (png_uint_32)32768L);        \
144.3539 +#  define png_composite_16(composite, fg, alpha, bg)       \
144.3540 +     { png_uint_32 temp = (png_uint_32)((png_uint_32)(fg)  \
144.3541 +           * (png_uint_32)(alpha)                          \
144.3542 +           + (png_uint_32)(bg)*(png_uint_32)(65535L        \
144.3543 +           - (png_uint_32)(alpha)) + (png_uint_32)32768L); \
144.3544         (composite) = (png_uint_16)((temp + (temp >> 16)) >> 16); }
144.3545  
144.3546 -#else  /* standard method using integer division */
144.3547 +#else  /* Standard method using integer division */
144.3548  
144.3549 -#  define png_composite(composite, fg, alpha, bg)                            \
144.3550 -     (composite) = (png_byte)(((png_uint_16)(fg) * (png_uint_16)(alpha) +    \
144.3551 -       (png_uint_16)(bg) * (png_uint_16)(255 - (png_uint_16)(alpha)) +       \
144.3552 -       (png_uint_16)127) / 255)
144.3553 +#  define png_composite(composite, fg, alpha, bg)                          \
144.3554 +     (composite) = (png_byte)(((png_uint_16)(fg) * (png_uint_16)(alpha) +  \
144.3555 +     (png_uint_16)(bg) * (png_uint_16)(255 - (png_uint_16)(alpha)) +       \
144.3556 +     (png_uint_16)127) / 255)
144.3557  
144.3558  #  define png_composite_16(composite, fg, alpha, bg)                         \
144.3559       (composite) = (png_uint_16)(((png_uint_32)(fg) * (png_uint_32)(alpha) + \
144.3560 -       (png_uint_32)(bg)*(png_uint_32)(65535L - (png_uint_32)(alpha)) +      \
144.3561 -       (png_uint_32)32767) / (png_uint_32)65535L)
144.3562 -
144.3563 +     (png_uint_32)(bg)*(png_uint_32)(65535L - (png_uint_32)(alpha)) +        \
144.3564 +     (png_uint_32)32767) / (png_uint_32)65535L)
144.3565  #endif /* PNG_READ_COMPOSITE_NODIV_SUPPORTED */
144.3566  
144.3567 -/* Inline macros to do direct reads of bytes from the input buffer.  These
144.3568 - * require that you are using an architecture that uses PNG byte ordering
144.3569 - * (MSB first) and supports unaligned data storage.  I think that PowerPC
144.3570 - * in big-endian mode and 680x0 are the only ones that will support this.
144.3571 - * The x86 line of processors definitely do not.  The png_get_int_32()
144.3572 - * routine also assumes we are using two's complement format for negative
144.3573 - * values, which is almost certainly true.
144.3574 - */
144.3575 -#if defined(PNG_READ_BIG_ENDIAN_SUPPORTED)
144.3576 -#  define png_get_uint_32(buf) ( *((png_uint_32p) (buf)))
144.3577 -#  define png_get_uint_16(buf) ( *((png_uint_16p) (buf)))
144.3578 -#  define png_get_int_32(buf)  ( *((png_int_32p)  (buf)))
144.3579 -#else
144.3580 -extern PNG_EXPORT(png_uint_32,png_get_uint_32) PNGARG((png_bytep buf));
144.3581 -extern PNG_EXPORT(png_uint_16,png_get_uint_16) PNGARG((png_bytep buf));
144.3582 -extern PNG_EXPORT(png_int_32,png_get_int_32) PNGARG((png_bytep buf));
144.3583 -#endif /* !PNG_READ_BIG_ENDIAN_SUPPORTED */
144.3584 -extern PNG_EXPORT(png_uint_32,png_get_uint_31)
144.3585 -  PNGARG((png_structp png_ptr, png_bytep buf));
144.3586 +#ifdef PNG_READ_INT_FUNCTIONS_SUPPORTED
144.3587 +PNG_EXPORT(201, png_uint_32, png_get_uint_32, (png_const_bytep buf));
144.3588 +PNG_EXPORT(202, png_uint_16, png_get_uint_16, (png_const_bytep buf));
144.3589 +PNG_EXPORT(203, png_int_32, png_get_int_32, (png_const_bytep buf));
144.3590 +#endif
144.3591 +
144.3592 +PNG_EXPORT(204, png_uint_32, png_get_uint_31, (png_structp png_ptr,
144.3593 +    png_const_bytep buf));
144.3594  /* No png_get_int_16 -- may be added if there's a real need for it. */
144.3595  
144.3596 -/* Place a 32-bit number into a buffer in PNG byte order (big-endian).
144.3597 - */
144.3598 -extern PNG_EXPORT(void,png_save_uint_32)
144.3599 -   PNGARG((png_bytep buf, png_uint_32 i));
144.3600 -extern PNG_EXPORT(void,png_save_int_32)
144.3601 -   PNGARG((png_bytep buf, png_int_32 i));
144.3602 +/* Place a 32-bit number into a buffer in PNG byte order (big-endian). */
144.3603 +#ifdef PNG_WRITE_INT_FUNCTIONS_SUPPORTED
144.3604 +PNG_EXPORT(205, void, png_save_uint_32, (png_bytep buf, png_uint_32 i));
144.3605 +#endif
144.3606 +#ifdef PNG_SAVE_INT_32_SUPPORTED
144.3607 +PNG_EXPORT(206, void, png_save_int_32, (png_bytep buf, png_int_32 i));
144.3608 +#endif
144.3609  
144.3610  /* Place a 16-bit number into a buffer in PNG byte order.
144.3611   * The parameter is declared unsigned int, not png_uint_16,
144.3612   * just to avoid potential problems on pre-ANSI C compilers.
144.3613   */
144.3614 -extern PNG_EXPORT(void,png_save_uint_16)
144.3615 -   PNGARG((png_bytep buf, unsigned int i));
144.3616 +#ifdef PNG_WRITE_INT_FUNCTIONS_SUPPORTED
144.3617 +PNG_EXPORT(207, void, png_save_uint_16, (png_bytep buf, unsigned int i));
144.3618  /* No png_save_int_16 -- may be added if there's a real need for it. */
144.3619 +#endif
144.3620  
144.3621 -/* ************************************************************************* */
144.3622 +#ifdef PNG_USE_READ_MACROS
144.3623 +/* Inline macros to do direct reads of bytes from the input buffer.
144.3624 + * The png_get_int_32() routine assumes we are using two's complement
144.3625 + * format for negative values, which is almost certainly true.
144.3626 + */
144.3627 +#  define png_get_uint_32(buf) \
144.3628 +     (((png_uint_32)(*(buf)) << 24) + \
144.3629 +      ((png_uint_32)(*((buf) + 1)) << 16) + \
144.3630 +      ((png_uint_32)(*((buf) + 2)) << 8) + \
144.3631 +      ((png_uint_32)(*((buf) + 3))))
144.3632  
144.3633 -/* These next functions are used internally in the code.  They generally
144.3634 - * shouldn't be used unless you are writing code to add or replace some
144.3635 - * functionality in libpng.  More information about most functions can
144.3636 - * be found in the files where the functions are located.
144.3637 +   /* From libpng-1.4.0 until 1.4.4, the png_get_uint_16 macro (but not the
144.3638 +    * function) incorrectly returned a value of type png_uint_32.
144.3639 +    */
144.3640 +#  define png_get_uint_16(buf) \
144.3641 +     ((png_uint_16) \
144.3642 +      (((unsigned int)(*(buf)) << 8) + \
144.3643 +       ((unsigned int)(*((buf) + 1)))))
144.3644 +
144.3645 +#  define png_get_int_32(buf) \
144.3646 +     ((png_int_32)((*(buf) & 0x80) \
144.3647 +      ? -((png_int_32)((png_get_uint_32(buf) ^ 0xffffffffL) + 1)) \
144.3648 +      : (png_int_32)png_get_uint_32(buf)))
144.3649 +#endif
144.3650 +
144.3651 +/* Maintainer: Put new public prototypes here ^, in libpng.3, and project
144.3652 + * defs
144.3653   */
144.3654  
144.3655 -
144.3656 -/* Various modes of operation, that are visible to applications because
144.3657 - * they are used for unknown chunk location.
144.3658 +/* The last ordinal number (this is the *last* one already used; the next
144.3659 + * one to use is one more than this.)  Maintainer, remember to add an entry to
144.3660 + * scripts/symbols.def as well.
144.3661   */
144.3662 -#define PNG_HAVE_IHDR               0x01
144.3663 -#define PNG_HAVE_PLTE               0x02
144.3664 -#define PNG_HAVE_IDAT               0x04
144.3665 -#define PNG_AFTER_IDAT              0x08 /* Have complete zlib datastream */
144.3666 -#define PNG_HAVE_IEND               0x10
144.3667 -
144.3668 -#if defined(PNG_INTERNAL)
144.3669 -
144.3670 -/* More modes of operation.  Note that after an init, mode is set to
144.3671 - * zero automatically when the structure is created.
144.3672 - */
144.3673 -#define PNG_HAVE_gAMA               0x20
144.3674 -#define PNG_HAVE_cHRM               0x40
144.3675 -#define PNG_HAVE_sRGB               0x80
144.3676 -#define PNG_HAVE_CHUNK_HEADER      0x100
144.3677 -#define PNG_WROTE_tIME             0x200
144.3678 -#define PNG_WROTE_INFO_BEFORE_PLTE 0x400
144.3679 -#define PNG_BACKGROUND_IS_GRAY     0x800
144.3680 -#define PNG_HAVE_PNG_SIGNATURE    0x1000
144.3681 -#define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000 /* Have another chunk after IDAT */
144.3682 -
144.3683 -/* flags for the transformations the PNG library does on the image data */
144.3684 -#define PNG_BGR                0x0001
144.3685 -#define PNG_INTERLACE          0x0002
144.3686 -#define PNG_PACK               0x0004
144.3687 -#define PNG_SHIFT              0x0008
144.3688 -#define PNG_SWAP_BYTES         0x0010
144.3689 -#define PNG_INVERT_MONO        0x0020
144.3690 -#define PNG_DITHER             0x0040
144.3691 -#define PNG_BACKGROUND         0x0080
144.3692 -#define PNG_BACKGROUND_EXPAND  0x0100
144.3693 -                          /*   0x0200 unused */
144.3694 -#define PNG_16_TO_8            0x0400
144.3695 -#define PNG_RGBA               0x0800
144.3696 -#define PNG_EXPAND             0x1000
144.3697 -#define PNG_GAMMA              0x2000
144.3698 -#define PNG_GRAY_TO_RGB        0x4000
144.3699 -#define PNG_FILLER             0x8000L
144.3700 -#define PNG_PACKSWAP          0x10000L
144.3701 -#define PNG_SWAP_ALPHA        0x20000L
144.3702 -#define PNG_STRIP_ALPHA       0x40000L
144.3703 -#define PNG_INVERT_ALPHA      0x80000L
144.3704 -#define PNG_USER_TRANSFORM   0x100000L
144.3705 -#define PNG_RGB_TO_GRAY_ERR  0x200000L
144.3706 -#define PNG_RGB_TO_GRAY_WARN 0x400000L
144.3707 -#define PNG_RGB_TO_GRAY      0x600000L  /* two bits, RGB_TO_GRAY_ERR|WARN */
144.3708 -                       /*    0x800000L     Unused */
144.3709 -#define PNG_ADD_ALPHA       0x1000000L  /* Added to libpng-1.2.7 */
144.3710 -#define PNG_EXPAND_tRNS     0x2000000L  /* Added to libpng-1.2.9 */
144.3711 -                       /*   0x4000000L  unused */
144.3712 -                       /*   0x8000000L  unused */
144.3713 -                       /*  0x10000000L  unused */
144.3714 -                       /*  0x20000000L  unused */
144.3715 -                       /*  0x40000000L  unused */
144.3716 -
144.3717 -/* flags for png_create_struct */
144.3718 -#define PNG_STRUCT_PNG   0x0001
144.3719 -#define PNG_STRUCT_INFO  0x0002
144.3720 -
144.3721 -/* Scaling factor for filter heuristic weighting calculations */
144.3722 -#define PNG_WEIGHT_SHIFT 8
144.3723 -#define PNG_WEIGHT_FACTOR (1<<(PNG_WEIGHT_SHIFT))
144.3724 -#define PNG_COST_SHIFT 3
144.3725 -#define PNG_COST_FACTOR (1<<(PNG_COST_SHIFT))
144.3726 -
144.3727 -/* flags for the png_ptr->flags rather than declaring a byte for each one */
144.3728 -#define PNG_FLAG_ZLIB_CUSTOM_STRATEGY     0x0001
144.3729 -#define PNG_FLAG_ZLIB_CUSTOM_LEVEL        0x0002
144.3730 -#define PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL    0x0004
144.3731 -#define PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS  0x0008
144.3732 -#define PNG_FLAG_ZLIB_CUSTOM_METHOD       0x0010
144.3733 -#define PNG_FLAG_ZLIB_FINISHED            0x0020
144.3734 -#define PNG_FLAG_ROW_INIT                 0x0040
144.3735 -#define PNG_FLAG_FILLER_AFTER             0x0080
144.3736 -#define PNG_FLAG_CRC_ANCILLARY_USE        0x0100
144.3737 -#define PNG_FLAG_CRC_ANCILLARY_NOWARN     0x0200
144.3738 -#define PNG_FLAG_CRC_CRITICAL_USE         0x0400
144.3739 -#define PNG_FLAG_CRC_CRITICAL_IGNORE      0x0800
144.3740 -#define PNG_FLAG_FREE_PLTE                0x1000
144.3741 -#define PNG_FLAG_FREE_TRNS                0x2000
144.3742 -#define PNG_FLAG_FREE_HIST                0x4000
144.3743 -#define PNG_FLAG_KEEP_UNKNOWN_CHUNKS      0x8000L
144.3744 -#define PNG_FLAG_KEEP_UNSAFE_CHUNKS       0x10000L
144.3745 -#define PNG_FLAG_LIBRARY_MISMATCH         0x20000L
144.3746 -#define PNG_FLAG_STRIP_ERROR_NUMBERS      0x40000L
144.3747 -#define PNG_FLAG_STRIP_ERROR_TEXT         0x80000L
144.3748 -#define PNG_FLAG_MALLOC_NULL_MEM_OK       0x100000L
144.3749 -#define PNG_FLAG_ADD_ALPHA                0x200000L  /* Added to libpng-1.2.8 */
144.3750 -#define PNG_FLAG_STRIP_ALPHA              0x400000L  /* Added to libpng-1.2.8 */
144.3751 -                                  /*      0x800000L  unused */
144.3752 -                                  /*     0x1000000L  unused */
144.3753 -                                  /*     0x2000000L  unused */
144.3754 -                                  /*     0x4000000L  unused */
144.3755 -                                  /*     0x8000000L  unused */
144.3756 -                                  /*    0x10000000L  unused */
144.3757 -                                  /*    0x20000000L  unused */
144.3758 -                                  /*    0x40000000L  unused */
144.3759 -
144.3760 -#define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \
144.3761 -                                     PNG_FLAG_CRC_ANCILLARY_NOWARN)
144.3762 -
144.3763 -#define PNG_FLAG_CRC_CRITICAL_MASK  (PNG_FLAG_CRC_CRITICAL_USE | \
144.3764 -                                     PNG_FLAG_CRC_CRITICAL_IGNORE)
144.3765 -
144.3766 -#define PNG_FLAG_CRC_MASK           (PNG_FLAG_CRC_ANCILLARY_MASK | \
144.3767 -                                     PNG_FLAG_CRC_CRITICAL_MASK)
144.3768 -
144.3769 -/* save typing and make code easier to understand */
144.3770 -
144.3771 -#define PNG_COLOR_DIST(c1, c2) (abs((int)((c1).red) - (int)((c2).red)) + \
144.3772 -   abs((int)((c1).green) - (int)((c2).green)) + \
144.3773 -   abs((int)((c1).blue) - (int)((c2).blue)))
144.3774 -
144.3775 -/* Added to libpng-1.2.6 JB */
144.3776 -#define PNG_ROWBYTES(pixel_bits, width) \
144.3777 -    ((pixel_bits) >= 8 ? \
144.3778 -    ((width) * (((png_uint_32)(pixel_bits)) >> 3)) : \
144.3779 -    (( ((width) * ((png_uint_32)(pixel_bits))) + 7) >> 3) )
144.3780 -
144.3781 -/* PNG_OUT_OF_RANGE returns true if value is outside the range
144.3782 -   ideal-delta..ideal+delta.  Each argument is evaluated twice.
144.3783 -   "ideal" and "delta" should be constants, normally simple
144.3784 -   integers, "value" a variable. Added to libpng-1.2.6 JB */
144.3785 -#define PNG_OUT_OF_RANGE(value, ideal, delta) \
144.3786 -        ( (value) < (ideal)-(delta) || (value) > (ideal)+(delta) )
144.3787 -
144.3788 -/* variables declared in png.c - only it needs to define PNG_NO_EXTERN */
144.3789 -#if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
144.3790 -/* place to hold the signature string for a PNG file. */
144.3791 -#ifdef PNG_USE_GLOBAL_ARRAYS
144.3792 -   PNG_EXPORT_VAR (const png_byte FARDATA) png_sig[8];
144.3793 -#else
144.3794 -#if 0
144.3795 -#define png_sig png_sig_bytes(NULL)
144.3796 +#ifdef PNG_EXPORT_LAST_ORDINAL
144.3797 +  PNG_EXPORT_LAST_ORDINAL(229);
144.3798  #endif
144.3799 -#endif
144.3800 -#endif /* PNG_NO_EXTERN */
144.3801 -
144.3802 -/* Constant strings for known chunk types.  If you need to add a chunk,
144.3803 - * define the name here, and add an invocation of the macro in png.c and
144.3804 - * wherever it's needed.
144.3805 - */
144.3806 -#define PNG_IHDR const png_byte png_IHDR[5] = { 73,  72,  68,  82, '\0'}
144.3807 -#define PNG_IDAT const png_byte png_IDAT[5] = { 73,  68,  65,  84, '\0'}
144.3808 -#define PNG_IEND const png_byte png_IEND[5] = { 73,  69,  78,  68, '\0'}
144.3809 -#define PNG_PLTE const png_byte png_PLTE[5] = { 80,  76,  84,  69, '\0'}
144.3810 -#define PNG_bKGD const png_byte png_bKGD[5] = { 98,  75,  71,  68, '\0'}
144.3811 -#define PNG_cHRM const png_byte png_cHRM[5] = { 99,  72,  82,  77, '\0'}
144.3812 -#define PNG_gAMA const png_byte png_gAMA[5] = {103,  65,  77,  65, '\0'}
144.3813 -#define PNG_hIST const png_byte png_hIST[5] = {104,  73,  83,  84, '\0'}
144.3814 -#define PNG_iCCP const png_byte png_iCCP[5] = {105,  67,  67,  80, '\0'}
144.3815 -#define PNG_iTXt const png_byte png_iTXt[5] = {105,  84,  88, 116, '\0'}
144.3816 -#define PNG_oFFs const png_byte png_oFFs[5] = {111,  70,  70, 115, '\0'}
144.3817 -#define PNG_pCAL const png_byte png_pCAL[5] = {112,  67,  65,  76, '\0'}
144.3818 -#define PNG_sCAL const png_byte png_sCAL[5] = {115,  67,  65,  76, '\0'}
144.3819 -#define PNG_pHYs const png_byte png_pHYs[5] = {112,  72,  89, 115, '\0'}
144.3820 -#define PNG_sBIT const png_byte png_sBIT[5] = {115,  66,  73,  84, '\0'}
144.3821 -#define PNG_sPLT const png_byte png_sPLT[5] = {115,  80,  76,  84, '\0'}
144.3822 -#define PNG_sRGB const png_byte png_sRGB[5] = {115,  82,  71,  66, '\0'}
144.3823 -#define PNG_tEXt const png_byte png_tEXt[5] = {116,  69,  88, 116, '\0'}
144.3824 -#define PNG_tIME const png_byte png_tIME[5] = {116,  73,  77,  69, '\0'}
144.3825 -#define PNG_tRNS const png_byte png_tRNS[5] = {116,  82,  78,  83, '\0'}
144.3826 -#define PNG_zTXt const png_byte png_zTXt[5] = {122,  84,  88, 116, '\0'}
144.3827 -
144.3828 -#ifdef PNG_USE_GLOBAL_ARRAYS
144.3829 -PNG_EXPORT_VAR (const png_byte FARDATA) png_IHDR[5];
144.3830 -PNG_EXPORT_VAR (const png_byte FARDATA) png_IDAT[5];
144.3831 -PNG_EXPORT_VAR (const png_byte FARDATA) png_IEND[5];
144.3832 -PNG_EXPORT_VAR (const png_byte FARDATA) png_PLTE[5];
144.3833 -PNG_EXPORT_VAR (const png_byte FARDATA) png_bKGD[5];
144.3834 -PNG_EXPORT_VAR (const png_byte FARDATA) png_cHRM[5];
144.3835 -PNG_EXPORT_VAR (const png_byte FARDATA) png_gAMA[5];
144.3836 -PNG_EXPORT_VAR (const png_byte FARDATA) png_hIST[5];
144.3837 -PNG_EXPORT_VAR (const png_byte FARDATA) png_iCCP[5];
144.3838 -PNG_EXPORT_VAR (const png_byte FARDATA) png_iTXt[5];
144.3839 -PNG_EXPORT_VAR (const png_byte FARDATA) png_oFFs[5];
144.3840 -PNG_EXPORT_VAR (const png_byte FARDATA) png_pCAL[5];
144.3841 -PNG_EXPORT_VAR (const png_byte FARDATA) png_sCAL[5];
144.3842 -PNG_EXPORT_VAR (const png_byte FARDATA) png_pHYs[5];
144.3843 -PNG_EXPORT_VAR (const png_byte FARDATA) png_sBIT[5];
144.3844 -PNG_EXPORT_VAR (const png_byte FARDATA) png_sPLT[5];
144.3845 -PNG_EXPORT_VAR (const png_byte FARDATA) png_sRGB[5];
144.3846 -PNG_EXPORT_VAR (const png_byte FARDATA) png_tEXt[5];
144.3847 -PNG_EXPORT_VAR (const png_byte FARDATA) png_tIME[5];
144.3848 -PNG_EXPORT_VAR (const png_byte FARDATA) png_tRNS[5];
144.3849 -PNG_EXPORT_VAR (const png_byte FARDATA) png_zTXt[5];
144.3850 -#endif /* PNG_USE_GLOBAL_ARRAYS */
144.3851 -
144.3852 -#if defined(PNG_1_0_X) || defined (PNG_1_2_X)
144.3853 -/* Initialize png_ptr struct for reading, and allocate any other memory.
144.3854 - * (old interface - DEPRECATED - use png_create_read_struct instead).
144.3855 - */
144.3856 -extern PNG_EXPORT(void,png_read_init) PNGARG((png_structp png_ptr));
144.3857 -#undef png_read_init
144.3858 -#define png_read_init(png_ptr) png_read_init_3(&png_ptr, \
144.3859 -    PNG_LIBPNG_VER_STRING,  png_sizeof(png_struct));
144.3860 -#endif
144.3861 -
144.3862 -extern PNG_EXPORT(void,png_read_init_3) PNGARG((png_structpp ptr_ptr,
144.3863 -    png_const_charp user_png_ver, png_size_t png_struct_size));
144.3864 -#if defined(PNG_1_0_X) || defined (PNG_1_2_X)
144.3865 -extern PNG_EXPORT(void,png_read_init_2) PNGARG((png_structp png_ptr,
144.3866 -    png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t
144.3867 -    png_info_size));
144.3868 -#endif
144.3869 -
144.3870 -#if defined(PNG_1_0_X) || defined (PNG_1_2_X)
144.3871 -/* Initialize png_ptr struct for writing, and allocate any other memory.
144.3872 - * (old interface - DEPRECATED - use png_create_write_struct instead).
144.3873 - */
144.3874 -extern PNG_EXPORT(void,png_write_init) PNGARG((png_structp png_ptr));
144.3875 -#undef png_write_init
144.3876 -#define png_write_init(png_ptr) png_write_init_3(&png_ptr, \
144.3877 -    PNG_LIBPNG_VER_STRING, png_sizeof(png_struct));
144.3878 -#endif
144.3879 -
144.3880 -extern PNG_EXPORT(void,png_write_init_3) PNGARG((png_structpp ptr_ptr,
144.3881 -    png_const_charp user_png_ver, png_size_t png_struct_size));
144.3882 -extern PNG_EXPORT(void,png_write_init_2) PNGARG((png_structp png_ptr,
144.3883 -    png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t
144.3884 -    png_info_size));
144.3885 -
144.3886 -/* Allocate memory for an internal libpng struct */
144.3887 -PNG_EXTERN png_voidp png_create_struct PNGARG((int type));
144.3888 -
144.3889 -/* Free memory from internal libpng struct */
144.3890 -PNG_EXTERN void png_destroy_struct PNGARG((png_voidp struct_ptr));
144.3891 -
144.3892 -PNG_EXTERN png_voidp png_create_struct_2 PNGARG((int type, png_malloc_ptr
144.3893 -  malloc_fn, png_voidp mem_ptr));
144.3894 -PNG_EXTERN void png_destroy_struct_2 PNGARG((png_voidp struct_ptr,
144.3895 -   png_free_ptr free_fn, png_voidp mem_ptr));
144.3896 -
144.3897 -/* Free any memory that info_ptr points to and reset struct. */
144.3898 -PNG_EXTERN void png_info_destroy PNGARG((png_structp png_ptr,
144.3899 -   png_infop info_ptr));
144.3900 -
144.3901 -#ifndef PNG_1_0_X
144.3902 -/* Function to allocate memory for zlib. */
144.3903 -PNG_EXTERN voidpf png_zalloc PNGARG((voidpf png_ptr, uInt items, uInt size));
144.3904 -
144.3905 -/* Function to free memory for zlib */
144.3906 -PNG_EXTERN void png_zfree PNGARG((voidpf png_ptr, voidpf ptr));
144.3907 -
144.3908 -#ifdef PNG_SIZE_T
144.3909 -/* Function to convert a sizeof an item to png_sizeof item */
144.3910 -   PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size));
144.3911 -#endif
144.3912 -
144.3913 -/* Next four functions are used internally as callbacks.  PNGAPI is required
144.3914 - * but not PNG_EXPORT.  PNGAPI added at libpng version 1.2.3. */
144.3915 -
144.3916 -PNG_EXTERN void PNGAPI png_default_read_data PNGARG((png_structp png_ptr,
144.3917 -   png_bytep data, png_size_t length));
144.3918 -
144.3919 -#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
144.3920 -PNG_EXTERN void PNGAPI png_push_fill_buffer PNGARG((png_structp png_ptr,
144.3921 -   png_bytep buffer, png_size_t length));
144.3922 -#endif
144.3923 -
144.3924 -PNG_EXTERN void PNGAPI png_default_write_data PNGARG((png_structp png_ptr,
144.3925 -   png_bytep data, png_size_t length));
144.3926 -
144.3927 -#if defined(PNG_WRITE_FLUSH_SUPPORTED)
144.3928 -#if !defined(PNG_NO_STDIO)
144.3929 -PNG_EXTERN void PNGAPI png_default_flush PNGARG((png_structp png_ptr));
144.3930 -#endif
144.3931 -#endif
144.3932 -#else /* PNG_1_0_X */
144.3933 -#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
144.3934 -PNG_EXTERN void png_push_fill_buffer PNGARG((png_structp png_ptr,
144.3935 -   png_bytep buffer, png_size_t length));
144.3936 -#endif
144.3937 -#endif /* PNG_1_0_X */
144.3938 -
144.3939 -/* Reset the CRC variable */
144.3940 -PNG_EXTERN void png_reset_crc PNGARG((png_structp png_ptr));
144.3941 -
144.3942 -/* Write the "data" buffer to whatever output you are using. */
144.3943 -PNG_EXTERN void png_write_data PNGARG((png_structp png_ptr, png_bytep data,
144.3944 -   png_size_t length));
144.3945 -
144.3946 -/* Read data from whatever input you are using into the "data" buffer */
144.3947 -PNG_EXTERN void png_read_data PNGARG((png_structp png_ptr, png_bytep data,
144.3948 -   png_size_t length));
144.3949 -
144.3950 -/* Read bytes into buf, and update png_ptr->crc */
144.3951 -PNG_EXTERN void png_crc_read PNGARG((png_structp png_ptr, png_bytep buf,
144.3952 -   png_size_t length));
144.3953 -
144.3954 -/* Decompress data in a chunk that uses compression */
144.3955 -#if defined(PNG_zTXt_SUPPORTED) || defined(PNG_iTXt_SUPPORTED) || \
144.3956 -    defined(PNG_iCCP_SUPPORTED) || defined(PNG_sPLT_SUPPORTED)
144.3957 -PNG_EXTERN png_charp png_decompress_chunk PNGARG((png_structp png_ptr,
144.3958 -   int comp_type, png_charp chunkdata, png_size_t chunklength,
144.3959 -   png_size_t prefix_length, png_size_t *data_length));
144.3960 -#endif
144.3961 -
144.3962 -/* Read "skip" bytes, read the file crc, and (optionally) verify png_ptr->crc */
144.3963 -PNG_EXTERN int png_crc_finish PNGARG((png_structp png_ptr, png_uint_32 skip));
144.3964 -
144.3965 -/* Read the CRC from the file and compare it to the libpng calculated CRC */
144.3966 -PNG_EXTERN int png_crc_error PNGARG((png_structp png_ptr));
144.3967 -
144.3968 -/* Calculate the CRC over a section of data.  Note that we are only
144.3969 - * passing a maximum of 64K on systems that have this as a memory limit,
144.3970 - * since this is the maximum buffer size we can specify.
144.3971 - */
144.3972 -PNG_EXTERN void png_calculate_crc PNGARG((png_structp png_ptr, png_bytep ptr,
144.3973 -   png_size_t length));
144.3974 -
144.3975 -#if defined(PNG_WRITE_FLUSH_SUPPORTED)
144.3976 -PNG_EXTERN void png_flush PNGARG((png_structp png_ptr));
144.3977 -#endif
144.3978 -
144.3979 -/* simple function to write the signature */
144.3980 -PNG_EXTERN void png_write_sig PNGARG((png_structp png_ptr));
144.3981 -
144.3982 -/* write various chunks */
144.3983 -
144.3984 -/* Write the IHDR chunk, and update the png_struct with the necessary
144.3985 - * information.
144.3986 - */
144.3987 -PNG_EXTERN void png_write_IHDR PNGARG((png_structp png_ptr, png_uint_32 width,
144.3988 -   png_uint_32 height,
144.3989 -   int bit_depth, int color_type, int compression_method, int filter_method,
144.3990 -   int interlace_method));
144.3991 -
144.3992 -PNG_EXTERN void png_write_PLTE PNGARG((png_structp png_ptr, png_colorp palette,
144.3993 -   png_uint_32 num_pal));
144.3994 -
144.3995 -PNG_EXTERN void png_write_IDAT PNGARG((png_structp png_ptr, png_bytep data,
144.3996 -   png_size_t length));
144.3997 -
144.3998 -PNG_EXTERN void png_write_IEND PNGARG((png_structp png_ptr));
144.3999 -
144.4000 -#if defined(PNG_WRITE_gAMA_SUPPORTED)
144.4001 -#ifdef PNG_FLOATING_POINT_SUPPORTED
144.4002 -PNG_EXTERN void png_write_gAMA PNGARG((png_structp png_ptr, double file_gamma));
144.4003 -#endif
144.4004 -#ifdef PNG_FIXED_POINT_SUPPORTED
144.4005 -PNG_EXTERN void png_write_gAMA_fixed PNGARG((png_structp png_ptr, png_fixed_point
144.4006 -    file_gamma));
144.4007 -#endif
144.4008 -#endif
144.4009 -
144.4010 -#if defined(PNG_WRITE_sBIT_SUPPORTED)
144.4011 -PNG_EXTERN void png_write_sBIT PNGARG((png_structp png_ptr, png_color_8p sbit,
144.4012 -   int color_type));
144.4013 -#endif
144.4014 -
144.4015 -#if defined(PNG_WRITE_cHRM_SUPPORTED)
144.4016 -#ifdef PNG_FLOATING_POINT_SUPPORTED
144.4017 -PNG_EXTERN void png_write_cHRM PNGARG((png_structp png_ptr,
144.4018 -   double white_x, double white_y,
144.4019 -   double red_x, double red_y, double green_x, double green_y,
144.4020 -   double blue_x, double blue_y));
144.4021 -#endif
144.4022 -#ifdef PNG_FIXED_POINT_SUPPORTED
144.4023 -PNG_EXTERN void png_write_cHRM_fixed PNGARG((png_structp png_ptr,
144.4024 -   png_fixed_point int_white_x, png_fixed_point int_white_y,
144.4025 -   png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point
144.4026 -   int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x,
144.4027 -   png_fixed_point int_blue_y));
144.4028 -#endif
144.4029 -#endif
144.4030 -
144.4031 -#if defined(PNG_WRITE_sRGB_SUPPORTED)
144.4032 -PNG_EXTERN void png_write_sRGB PNGARG((png_structp png_ptr,
144.4033 -   int intent));
144.4034 -#endif
144.4035 -
144.4036 -#if defined(PNG_WRITE_iCCP_SUPPORTED)
144.4037 -PNG_EXTERN void png_write_iCCP PNGARG((png_structp png_ptr,
144.4038 -   png_charp name, int compression_type,
144.4039 -   png_charp profile, int proflen));
144.4040 -   /* Note to maintainer: profile should be png_bytep */
144.4041 -#endif
144.4042 -
144.4043 -#if defined(PNG_WRITE_sPLT_SUPPORTED)
144.4044 -PNG_EXTERN void png_write_sPLT PNGARG((png_structp png_ptr,
144.4045 -   png_sPLT_tp palette));
144.4046 -#endif
144.4047 -
144.4048 -#if defined(PNG_WRITE_tRNS_SUPPORTED)
144.4049 -PNG_EXTERN void png_write_tRNS PNGARG((png_structp png_ptr, png_bytep trans,
144.4050 -   png_color_16p values, int number, int color_type));
144.4051 -#endif
144.4052 -
144.4053 -#if defined(PNG_WRITE_bKGD_SUPPORTED)
144.4054 -PNG_EXTERN void png_write_bKGD PNGARG((png_structp png_ptr,
144.4055 -   png_color_16p values, int color_type));
144.4056 -#endif
144.4057 -
144.4058 -#if defined(PNG_WRITE_hIST_SUPPORTED)
144.4059 -PNG_EXTERN void png_write_hIST PNGARG((png_structp png_ptr, png_uint_16p hist,
144.4060 -   int num_hist));
144.4061 -#endif
144.4062 -
144.4063 -#if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \
144.4064 -    defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
144.4065 -PNG_EXTERN png_size_t png_check_keyword PNGARG((png_structp png_ptr,
144.4066 -   png_charp key, png_charpp new_key));
144.4067 -#endif
144.4068 -
144.4069 -#if defined(PNG_WRITE_tEXt_SUPPORTED)
144.4070 -PNG_EXTERN void png_write_tEXt PNGARG((png_structp png_ptr, png_charp key,
144.4071 -   png_charp text, png_size_t text_len));
144.4072 -#endif
144.4073 -
144.4074 -#if defined(PNG_WRITE_zTXt_SUPPORTED)
144.4075 -PNG_EXTERN void png_write_zTXt PNGARG((png_structp png_ptr, png_charp key,
144.4076 -   png_charp text, png_size_t text_len, int compression));
144.4077 -#endif
144.4078 -
144.4079 -#if defined(PNG_WRITE_iTXt_SUPPORTED)
144.4080 -PNG_EXTERN void png_write_iTXt PNGARG((png_structp png_ptr,
144.4081 -   int compression, png_charp key, png_charp lang, png_charp lang_key,
144.4082 -   png_charp text));
144.4083 -#endif
144.4084 -
144.4085 -#if defined(PNG_TEXT_SUPPORTED)  /* Added at version 1.0.14 and 1.2.4 */
144.4086 -PNG_EXTERN int png_set_text_2 PNGARG((png_structp png_ptr,
144.4087 -   png_infop info_ptr, png_textp text_ptr, int num_text));
144.4088 -#endif
144.4089 -
144.4090 -#if defined(PNG_WRITE_oFFs_SUPPORTED)
144.4091 -PNG_EXTERN void png_write_oFFs PNGARG((png_structp png_ptr,
144.4092 -   png_int_32 x_offset, png_int_32 y_offset, int unit_type));
144.4093 -#endif
144.4094 -
144.4095 -#if defined(PNG_WRITE_pCAL_SUPPORTED)
144.4096 -PNG_EXTERN void png_write_pCAL PNGARG((png_structp png_ptr, png_charp purpose,
144.4097 -   png_int_32 X0, png_int_32 X1, int type, int nparams,
144.4098 -   png_charp units, png_charpp params));
144.4099 -#endif
144.4100 -
144.4101 -#if defined(PNG_WRITE_pHYs_SUPPORTED)
144.4102 -PNG_EXTERN void png_write_pHYs PNGARG((png_structp png_ptr,
144.4103 -   png_uint_32 x_pixels_per_unit, png_uint_32 y_pixels_per_unit,
144.4104 -   int unit_type));
144.4105 -#endif
144.4106 -
144.4107 -#if defined(PNG_WRITE_tIME_SUPPORTED)
144.4108 -PNG_EXTERN void png_write_tIME PNGARG((png_structp png_ptr,
144.4109 -   png_timep mod_time));
144.4110 -#endif
144.4111 -
144.4112 -#if defined(PNG_WRITE_sCAL_SUPPORTED)
144.4113 -#if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
144.4114 -PNG_EXTERN void png_write_sCAL PNGARG((png_structp png_ptr,
144.4115 -   int unit, double width, double height));
144.4116 -#else
144.4117 -#ifdef PNG_FIXED_POINT_SUPPORTED
144.4118 -PNG_EXTERN void png_write_sCAL_s PNGARG((png_structp png_ptr,
144.4119 -   int unit, png_charp width, png_charp height));
144.4120 -#endif
144.4121 -#endif
144.4122 -#endif
144.4123 -
144.4124 -/* Called when finished processing a row of data */
144.4125 -PNG_EXTERN void png_write_finish_row PNGARG((png_structp png_ptr));
144.4126 -
144.4127 -/* Internal use only.   Called before first row of data */
144.4128 -PNG_EXTERN void png_write_start_row PNGARG((png_structp png_ptr));
144.4129 -
144.4130 -#if defined(PNG_READ_GAMMA_SUPPORTED)
144.4131 -PNG_EXTERN void png_build_gamma_table PNGARG((png_structp png_ptr));
144.4132 -#endif
144.4133 -
144.4134 -/* combine a row of data, dealing with alpha, etc. if requested */
144.4135 -PNG_EXTERN void png_combine_row PNGARG((png_structp png_ptr, png_bytep row,
144.4136 -   int mask));
144.4137 -
144.4138 -#if defined(PNG_READ_INTERLACING_SUPPORTED)
144.4139 -/* expand an interlaced row */
144.4140 -/* OLD pre-1.0.9 interface:
144.4141 -PNG_EXTERN void png_do_read_interlace PNGARG((png_row_infop row_info,
144.4142 -   png_bytep row, int pass, png_uint_32 transformations));
144.4143 - */
144.4144 -PNG_EXTERN void png_do_read_interlace PNGARG((png_structp png_ptr));
144.4145 -#endif
144.4146 -
144.4147 -/* GRR TO DO (2.0 or whenever):  simplify other internal calling interfaces */
144.4148 -
144.4149 -#if defined(PNG_WRITE_INTERLACING_SUPPORTED)
144.4150 -/* grab pixels out of a row for an interlaced pass */
144.4151 -PNG_EXTERN void png_do_write_interlace PNGARG((png_row_infop row_info,
144.4152 -   png_bytep row, int pass));
144.4153 -#endif
144.4154 -
144.4155 -/* unfilter a row */
144.4156 -PNG_EXTERN void png_read_filter_row PNGARG((png_structp png_ptr,
144.4157 -   png_row_infop row_info, png_bytep row, png_bytep prev_row, int filter));
144.4158 -
144.4159 -/* Choose the best filter to use and filter the row data */
144.4160 -PNG_EXTERN void png_write_find_filter PNGARG((png_structp png_ptr,
144.4161 -   png_row_infop row_info));
144.4162 -
144.4163 -/* Write out the filtered row. */
144.4164 -PNG_EXTERN void png_write_filtered_row PNGARG((png_structp png_ptr,
144.4165 -   png_bytep filtered_row));
144.4166 -/* finish a row while reading, dealing with interlacing passes, etc. */
144.4167 -PNG_EXTERN void png_read_finish_row PNGARG((png_structp png_ptr));
144.4168 -
144.4169 -/* initialize the row buffers, etc. */
144.4170 -PNG_EXTERN void png_read_start_row PNGARG((png_structp png_ptr));
144.4171 -/* optional call to update the users info structure */
144.4172 -PNG_EXTERN void png_read_transform_info PNGARG((png_structp png_ptr,
144.4173 -   png_infop info_ptr));
144.4174 -
144.4175 -/* these are the functions that do the transformations */
144.4176 -#if defined(PNG_READ_FILLER_SUPPORTED)
144.4177 -PNG_EXTERN void png_do_read_filler PNGARG((png_row_infop row_info,
144.4178 -   png_bytep row, png_uint_32 filler, png_uint_32 flags));
144.4179 -#endif
144.4180 -
144.4181 -#if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
144.4182 -PNG_EXTERN void png_do_read_swap_alpha PNGARG((png_row_infop row_info,
144.4183 -   png_bytep row));
144.4184 -#endif
144.4185 -
144.4186 -#if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
144.4187 -PNG_EXTERN void png_do_write_swap_alpha PNGARG((png_row_infop row_info,
144.4188 -   png_bytep row));
144.4189 -#endif
144.4190 -
144.4191 -#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
144.4192 -PNG_EXTERN void png_do_read_invert_alpha PNGARG((png_row_infop row_info,
144.4193 -   png_bytep row));
144.4194 -#endif
144.4195 -
144.4196 -#if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
144.4197 -PNG_EXTERN void png_do_write_invert_alpha PNGARG((png_row_infop row_info,
144.4198 -   png_bytep row));
144.4199 -#endif
144.4200 -
144.4201 -#if defined(PNG_WRITE_FILLER_SUPPORTED) || \
144.4202 -    defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
144.4203 -PNG_EXTERN void png_do_strip_filler PNGARG((png_row_infop row_info,
144.4204 -   png_bytep row, png_uint_32 flags));
144.4205 -#endif
144.4206 -
144.4207 -#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
144.4208 -PNG_EXTERN void png_do_swap PNGARG((png_row_infop row_info, png_bytep row));
144.4209 -#endif
144.4210 -
144.4211 -#if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED)
144.4212 -PNG_EXTERN void png_do_packswap PNGARG((png_row_infop row_info, png_bytep row));
144.4213 -#endif
144.4214 -
144.4215 -#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
144.4216 -PNG_EXTERN int png_do_rgb_to_gray PNGARG((png_structp png_ptr, png_row_infop
144.4217 -   row_info, png_bytep row));
144.4218 -#endif
144.4219 -
144.4220 -#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
144.4221 -PNG_EXTERN void png_do_gray_to_rgb PNGARG((png_row_infop row_info,
144.4222 -   png_bytep row));
144.4223 -#endif
144.4224 -
144.4225 -#if defined(PNG_READ_PACK_SUPPORTED)
144.4226 -PNG_EXTERN void png_do_unpack PNGARG((png_row_infop row_info, png_bytep row));
144.4227 -#endif
144.4228 -
144.4229 -#if defined(PNG_READ_SHIFT_SUPPORTED)
144.4230 -PNG_EXTERN void png_do_unshift PNGARG((png_row_infop row_info, png_bytep row,
144.4231 -   png_color_8p sig_bits));
144.4232 -#endif
144.4233 -
144.4234 -#if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
144.4235 -PNG_EXTERN void png_do_invert PNGARG((png_row_infop row_info, png_bytep row));
144.4236 -#endif
144.4237 -
144.4238 -#if defined(PNG_READ_16_TO_8_SUPPORTED)
144.4239 -PNG_EXTERN void png_do_chop PNGARG((png_row_infop row_info, png_bytep row));
144.4240 -#endif
144.4241 -
144.4242 -#if defined(PNG_READ_DITHER_SUPPORTED)
144.4243 -PNG_EXTERN void png_do_dither PNGARG((png_row_infop row_info,
144.4244 -   png_bytep row, png_bytep palette_lookup, png_bytep dither_lookup));
144.4245 -
144.4246 -#  if defined(PNG_CORRECT_PALETTE_SUPPORTED)
144.4247 -PNG_EXTERN void png_correct_palette PNGARG((png_structp png_ptr,
144.4248 -   png_colorp palette, int num_palette));
144.4249 -#  endif
144.4250 -#endif
144.4251 -
144.4252 -#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
144.4253 -PNG_EXTERN void png_do_bgr PNGARG((png_row_infop row_info, png_bytep row));
144.4254 -#endif
144.4255 -
144.4256 -#if defined(PNG_WRITE_PACK_SUPPORTED)
144.4257 -PNG_EXTERN void png_do_pack PNGARG((png_row_infop row_info,
144.4258 -   png_bytep row, png_uint_32 bit_depth));
144.4259 -#endif
144.4260 -
144.4261 -#if defined(PNG_WRITE_SHIFT_SUPPORTED)
144.4262 -PNG_EXTERN void png_do_shift PNGARG((png_row_infop row_info, png_bytep row,
144.4263 -   png_color_8p bit_depth));
144.4264 -#endif
144.4265 -
144.4266 -#if defined(PNG_READ_BACKGROUND_SUPPORTED)
144.4267 -#if defined(PNG_READ_GAMMA_SUPPORTED)
144.4268 -PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row,
144.4269 -   png_color_16p trans_values, png_color_16p background,
144.4270 -   png_color_16p background_1,
144.4271 -   png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1,
144.4272 -   png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1,
144.4273 -   png_uint_16pp gamma_16_to_1, int gamma_shift));
144.4274 -#else
144.4275 -PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row,
144.4276 -   png_color_16p trans_values, png_color_16p background));
144.4277 -#endif
144.4278 -#endif
144.4279 -
144.4280 -#if defined(PNG_READ_GAMMA_SUPPORTED)
144.4281 -PNG_EXTERN void png_do_gamma PNGARG((png_row_infop row_info, png_bytep row,
144.4282 -   png_bytep gamma_table, png_uint_16pp gamma_16_table,
144.4283 -   int gamma_shift));
144.4284 -#endif
144.4285 -
144.4286 -#if defined(PNG_READ_EXPAND_SUPPORTED)
144.4287 -PNG_EXTERN void png_do_expand_palette PNGARG((png_row_infop row_info,
144.4288 -   png_bytep row, png_colorp palette, png_bytep trans, int num_trans));
144.4289 -PNG_EXTERN void png_do_expand PNGARG((png_row_infop row_info,
144.4290 -   png_bytep row, png_color_16p trans_value));
144.4291 -#endif
144.4292 -
144.4293 -/* The following decodes the appropriate chunks, and does error correction,
144.4294 - * then calls the appropriate callback for the chunk if it is valid.
144.4295 - */
144.4296 -
144.4297 -/* decode the IHDR chunk */
144.4298 -PNG_EXTERN void png_handle_IHDR PNGARG((png_structp png_ptr, png_infop info_ptr,
144.4299 -   png_uint_32 length));
144.4300 -PNG_EXTERN void png_handle_PLTE PNGARG((png_structp png_ptr, png_infop info_ptr,
144.4301 -   png_uint_32 length));
144.4302 -PNG_EXTERN void png_handle_IEND PNGARG((png_structp png_ptr, png_infop info_ptr,
144.4303 -   png_uint_32 length));
144.4304 -
144.4305 -#if defined(PNG_READ_bKGD_SUPPORTED)
144.4306 -PNG_EXTERN void png_handle_bKGD PNGARG((png_structp png_ptr, png_infop info_ptr,
144.4307 -   png_uint_32 length));
144.4308 -#endif
144.4309 -
144.4310 -#if defined(PNG_READ_cHRM_SUPPORTED)
144.4311 -PNG_EXTERN void png_handle_cHRM PNGARG((png_structp png_ptr, png_infop info_ptr,
144.4312 -   png_uint_32 length));
144.4313 -#endif
144.4314 -
144.4315 -#if defined(PNG_READ_gAMA_SUPPORTED)
144.4316 -PNG_EXTERN void png_handle_gAMA PNGARG((png_structp png_ptr, png_infop info_ptr,
144.4317 -   png_uint_32 length));
144.4318 -#endif
144.4319 -
144.4320 -#if defined(PNG_READ_hIST_SUPPORTED)
144.4321 -PNG_EXTERN void png_handle_hIST PNGARG((png_structp png_ptr, png_infop info_ptr,
144.4322 -   png_uint_32 length));
144.4323 -#endif
144.4324 -
144.4325 -#if defined(PNG_READ_iCCP_SUPPORTED)
144.4326 -extern void png_handle_iCCP PNGARG((png_structp png_ptr, png_infop info_ptr,
144.4327 -   png_uint_32 length));
144.4328 -#endif /* PNG_READ_iCCP_SUPPORTED */
144.4329 -
144.4330 -#if defined(PNG_READ_iTXt_SUPPORTED)
144.4331 -PNG_EXTERN void png_handle_iTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
144.4332 -   png_uint_32 length));
144.4333 -#endif
144.4334 -
144.4335 -#if defined(PNG_READ_oFFs_SUPPORTED)
144.4336 -PNG_EXTERN void png_handle_oFFs PNGARG((png_structp png_ptr, png_infop info_ptr,
144.4337 -   png_uint_32 length));
144.4338 -#endif
144.4339 -
144.4340 -#if defined(PNG_READ_pCAL_SUPPORTED)
144.4341 -PNG_EXTERN void png_handle_pCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
144.4342 -   png_uint_32 length));
144.4343 -#endif
144.4344 -
144.4345 -#if defined(PNG_READ_pHYs_SUPPORTED)
144.4346 -PNG_EXTERN void png_handle_pHYs PNGARG((png_structp png_ptr, png_infop info_ptr,
144.4347 -   png_uint_32 length));
144.4348 -#endif
144.4349 -
144.4350 -#if defined(PNG_READ_sBIT_SUPPORTED)
144.4351 -PNG_EXTERN void png_handle_sBIT PNGARG((png_structp png_ptr, png_infop info_ptr,
144.4352 -   png_uint_32 length));
144.4353 -#endif
144.4354 -
144.4355 -#if defined(PNG_READ_sCAL_SUPPORTED)
144.4356 -PNG_EXTERN void png_handle_sCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
144.4357 -   png_uint_32 length));
144.4358 -#endif
144.4359 -
144.4360 -#if defined(PNG_READ_sPLT_SUPPORTED)
144.4361 -extern void png_handle_sPLT PNGARG((png_structp png_ptr, png_infop info_ptr,
144.4362 -   png_uint_32 length));
144.4363 -#endif /* PNG_READ_sPLT_SUPPORTED */
144.4364 -
144.4365 -#if defined(PNG_READ_sRGB_SUPPORTED)
144.4366 -PNG_EXTERN void png_handle_sRGB PNGARG((png_structp png_ptr, png_infop info_ptr,
144.4367 -   png_uint_32 length));
144.4368 -#endif
144.4369 -
144.4370 -#if defined(PNG_READ_tEXt_SUPPORTED)
144.4371 -PNG_EXTERN void png_handle_tEXt PNGARG((png_structp png_ptr, png_infop info_ptr,
144.4372 -   png_uint_32 length));
144.4373 -#endif
144.4374 -
144.4375 -#if defined(PNG_READ_tIME_SUPPORTED)
144.4376 -PNG_EXTERN void png_handle_tIME PNGARG((png_structp png_ptr, png_infop info_ptr,
144.4377 -   png_uint_32 length));
144.4378 -#endif
144.4379 -
144.4380 -#if defined(PNG_READ_tRNS_SUPPORTED)
144.4381 -PNG_EXTERN void png_handle_tRNS PNGARG((png_structp png_ptr, png_infop info_ptr,
144.4382 -   png_uint_32 length));
144.4383 -#endif
144.4384 -
144.4385 -#if defined(PNG_READ_zTXt_SUPPORTED)
144.4386 -PNG_EXTERN void png_handle_zTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
144.4387 -   png_uint_32 length));
144.4388 -#endif
144.4389 -
144.4390 -PNG_EXTERN void png_handle_unknown PNGARG((png_structp png_ptr,
144.4391 -   png_infop info_ptr, png_uint_32 length));
144.4392 -
144.4393 -PNG_EXTERN void png_check_chunk_name PNGARG((png_structp png_ptr,
144.4394 -   png_bytep chunk_name));
144.4395 -
144.4396 -/* handle the transformations for reading and writing */
144.4397 -PNG_EXTERN void png_do_read_transformations PNGARG((png_structp png_ptr));
144.4398 -PNG_EXTERN void png_do_write_transformations PNGARG((png_structp png_ptr));
144.4399 -
144.4400 -PNG_EXTERN void png_init_read_transformations PNGARG((png_structp png_ptr));
144.4401 -
144.4402 -#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
144.4403 -PNG_EXTERN void png_push_read_chunk PNGARG((png_structp png_ptr,
144.4404 -   png_infop info_ptr));
144.4405 -PNG_EXTERN void png_push_read_sig PNGARG((png_structp png_ptr,
144.4406 -   png_infop info_ptr));
144.4407 -PNG_EXTERN void png_push_check_crc PNGARG((png_structp png_ptr));
144.4408 -PNG_EXTERN void png_push_crc_skip PNGARG((png_structp png_ptr,
144.4409 -   png_uint_32 length));
144.4410 -PNG_EXTERN void png_push_crc_finish PNGARG((png_structp png_ptr));
144.4411 -PNG_EXTERN void png_push_save_buffer PNGARG((png_structp png_ptr));
144.4412 -PNG_EXTERN void png_push_restore_buffer PNGARG((png_structp png_ptr,
144.4413 -   png_bytep buffer, png_size_t buffer_length));
144.4414 -PNG_EXTERN void png_push_read_IDAT PNGARG((png_structp png_ptr));
144.4415 -PNG_EXTERN void png_process_IDAT_data PNGARG((png_structp png_ptr,
144.4416 -   png_bytep buffer, png_size_t buffer_length));
144.4417 -PNG_EXTERN void png_push_process_row PNGARG((png_structp png_ptr));
144.4418 -PNG_EXTERN void png_push_handle_unknown PNGARG((png_structp png_ptr,
144.4419 -   png_infop info_ptr, png_uint_32 length));
144.4420 -PNG_EXTERN void png_push_have_info PNGARG((png_structp png_ptr,
144.4421 -   png_infop info_ptr));
144.4422 -PNG_EXTERN void png_push_have_end PNGARG((png_structp png_ptr,
144.4423 -   png_infop info_ptr));
144.4424 -PNG_EXTERN void png_push_have_row PNGARG((png_structp png_ptr, png_bytep row));
144.4425 -PNG_EXTERN void png_push_read_end PNGARG((png_structp png_ptr,
144.4426 -   png_infop info_ptr));
144.4427 -PNG_EXTERN void png_process_some_data PNGARG((png_structp png_ptr,
144.4428 -   png_infop info_ptr));
144.4429 -PNG_EXTERN void png_read_push_finish_row PNGARG((png_structp png_ptr));
144.4430 -#if defined(PNG_READ_tEXt_SUPPORTED)
144.4431 -PNG_EXTERN void png_push_handle_tEXt PNGARG((png_structp png_ptr,
144.4432 -   png_infop info_ptr, png_uint_32 length));
144.4433 -PNG_EXTERN void png_push_read_tEXt PNGARG((png_structp png_ptr,
144.4434 -   png_infop info_ptr));
144.4435 -#endif
144.4436 -#if defined(PNG_READ_zTXt_SUPPORTED)
144.4437 -PNG_EXTERN void png_push_handle_zTXt PNGARG((png_structp png_ptr,
144.4438 -   png_infop info_ptr, png_uint_32 length));
144.4439 -PNG_EXTERN void png_push_read_zTXt PNGARG((png_structp png_ptr,
144.4440 -   png_infop info_ptr));
144.4441 -#endif
144.4442 -#if defined(PNG_READ_iTXt_SUPPORTED)
144.4443 -PNG_EXTERN void png_push_handle_iTXt PNGARG((png_structp png_ptr,
144.4444 -   png_infop info_ptr, png_uint_32 length));
144.4445 -PNG_EXTERN void png_push_read_iTXt PNGARG((png_structp png_ptr,
144.4446 -   png_infop info_ptr));
144.4447 -#endif
144.4448 -
144.4449 -#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
144.4450 -
144.4451 -#ifdef PNG_MNG_FEATURES_SUPPORTED
144.4452 -PNG_EXTERN void png_do_read_intrapixel PNGARG((png_row_infop row_info,
144.4453 -   png_bytep row));
144.4454 -PNG_EXTERN void png_do_write_intrapixel PNGARG((png_row_infop row_info,
144.4455 -   png_bytep row));
144.4456 -#endif
144.4457 -
144.4458 -#if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
144.4459 -#if defined(PNG_MMX_CODE_SUPPORTED)
144.4460 -/* png.c */ /* PRIVATE */
144.4461 -PNG_EXTERN void png_init_mmx_flags PNGARG((png_structp png_ptr));
144.4462 -#endif
144.4463 -#endif
144.4464 -
144.4465 -#if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
144.4466 -PNG_EXTERN png_uint_32 png_get_pixels_per_inch PNGARG((png_structp png_ptr,
144.4467 -png_infop info_ptr));
144.4468 -
144.4469 -PNG_EXTERN png_uint_32 png_get_x_pixels_per_inch PNGARG((png_structp png_ptr,
144.4470 -png_infop info_ptr));
144.4471 -
144.4472 -PNG_EXTERN png_uint_32 png_get_y_pixels_per_inch PNGARG((png_structp png_ptr,
144.4473 -png_infop info_ptr));
144.4474 -
144.4475 -PNG_EXTERN float png_get_x_offset_inches PNGARG((png_structp png_ptr,
144.4476 -png_infop info_ptr));
144.4477 -
144.4478 -PNG_EXTERN float png_get_y_offset_inches PNGARG((png_structp png_ptr,
144.4479 -png_infop info_ptr));
144.4480 -
144.4481 -#if defined(PNG_pHYs_SUPPORTED)
144.4482 -PNG_EXTERN png_uint_32 png_get_pHYs_dpi PNGARG((png_structp png_ptr,
144.4483 -png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type));
144.4484 -#endif /* PNG_pHYs_SUPPORTED */
144.4485 -#endif  /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
144.4486 -
144.4487 -/* Maintainer: Put new private prototypes here ^ and in libpngpf.3 */
144.4488 -
144.4489 -#endif /* PNG_INTERNAL */
144.4490  
144.4491  #ifdef __cplusplus
144.4492  }
144.4493  #endif
144.4494  
144.4495  #endif /* PNG_VERSION_INFO_ONLY */
144.4496 -/* do not put anything past this line */
144.4497 +/* Do not put anything past this line */
144.4498  #endif /* PNG_H */
   145.1 --- a/src/share/native/sun/awt/libpng/pngconf.h	Fri Sep 30 17:20:56 2011 -0700
   145.2 +++ b/src/share/native/sun/awt/libpng/pngconf.h	Tue Oct 04 12:39:42 2011 -0700
   145.3 @@ -29,11 +29,16 @@
   145.4   * However, the following notice accompanied the original version of this
   145.5   * file and, per its terms, should not be removed:
   145.6   *
   145.7 - * libpng version 1.2.18 - May 15, 2007
   145.8 - * For conditions of distribution and use, see copyright notice in png.h
   145.9 - * Copyright (c) 1998-2007 Glenn Randers-Pehrson
  145.10 + * libpng version 1.5.4 - July 7, 2011
  145.11 + *
  145.12 + * Copyright (c) 1998-2011 Glenn Randers-Pehrson
  145.13   * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
  145.14   * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
  145.15 + *
  145.16 + * This code is released under the libpng license.
  145.17 + * For conditions of distribution and use, see the disclaimer
  145.18 + * and license in png.h
  145.19 + *
  145.20   */
  145.21  
  145.22  /* Any machine specific code is near the front of this file, so if you
  145.23 @@ -45,244 +50,57 @@
  145.24  #ifndef PNGCONF_H
  145.25  #define PNGCONF_H
  145.26  
  145.27 -#define PNG_1_2_X
  145.28 +#ifndef PNG_BUILDING_SYMBOL_TABLE
  145.29 +/* PNG_NO_LIMITS_H may be used to turn off the use of the standard C
  145.30 + * definition file for  machine specific limits, this may impact the
  145.31 + * correctness of the definitons below (see uses of INT_MAX).
  145.32 + */
  145.33 +#  ifndef PNG_NO_LIMITS_H
  145.34 +#    include <limits.h>
  145.35 +#  endif
  145.36  
  145.37 -/*
  145.38 - * PNG_USER_CONFIG has to be defined on the compiler command line. This
  145.39 - * includes the resource compiler for Windows DLL configurations.
  145.40 +/* For the memory copy APIs (i.e. the standard definitions of these),
  145.41 + * because this file defines png_memcpy and so on the base APIs must
  145.42 + * be defined here.
  145.43   */
  145.44 -#ifdef PNG_USER_CONFIG
  145.45 -#  ifndef PNG_USER_PRIVATEBUILD
  145.46 -#    define PNG_USER_PRIVATEBUILD
  145.47 +#  ifdef BSD
  145.48 +#    include <strings.h>
  145.49 +#  else
  145.50 +#    include <string.h>
  145.51  #  endif
  145.52 -#include "pngusr.h"
  145.53 -#endif
  145.54  
  145.55 -/* PNG_CONFIGURE_LIBPNG is set by the "configure" script. */
  145.56 -#ifdef PNG_CONFIGURE_LIBPNG
  145.57 -#ifdef HAVE_CONFIG_H
  145.58 -#include "config.h"
  145.59 -#endif
  145.60 -#endif
  145.61 -
  145.62 -/*
  145.63 - * Added at libpng-1.2.8
  145.64 - *
  145.65 - * If you create a private DLL you need to define in "pngusr.h" the followings:
  145.66 - * #define PNG_USER_PRIVATEBUILD <Describes by whom and why this version of
  145.67 - *        the DLL was built>
  145.68 - *  e.g. #define PNG_USER_PRIVATEBUILD "Build by MyCompany for xyz reasons."
  145.69 - * #define PNG_USER_DLLFNAME_POSTFIX <two-letter postfix that serve to
  145.70 - *        distinguish your DLL from those of the official release. These
  145.71 - *        correspond to the trailing letters that come after the version
  145.72 - *        number and must match your private DLL name>
  145.73 - *  e.g. // private DLL "libpng13gx.dll"
  145.74 - *       #define PNG_USER_DLLFNAME_POSTFIX "gx"
  145.75 - *
  145.76 - * The following macros are also at your disposal if you want to complete the
  145.77 - * DLL VERSIONINFO structure.
  145.78 - * - PNG_USER_VERSIONINFO_COMMENTS
  145.79 - * - PNG_USER_VERSIONINFO_COMPANYNAME
  145.80 - * - PNG_USER_VERSIONINFO_LEGALTRADEMARKS
  145.81 +/* For png_FILE_p - this provides the standard definition of a
  145.82 + * FILE
  145.83   */
  145.84 -
  145.85 -#ifdef __STDC__
  145.86 -#ifdef SPECIALBUILD
  145.87 -#  pragma message("PNG_LIBPNG_SPECIALBUILD (and deprecated SPECIALBUILD)\
  145.88 - are now LIBPNG reserved macros. Use PNG_USER_PRIVATEBUILD instead.")
  145.89 -#endif
  145.90 -
  145.91 -#ifdef PRIVATEBUILD
  145.92 -# pragma message("PRIVATEBUILD is deprecated.\
  145.93 - Use PNG_USER_PRIVATEBUILD instead.")
  145.94 -# define PNG_USER_PRIVATEBUILD PRIVATEBUILD
  145.95 -#endif
  145.96 -#endif /* __STDC__ */
  145.97 -
  145.98 -#ifndef PNG_VERSION_INFO_ONLY
  145.99 -
 145.100 -/* End of material added to libpng-1.2.8 */
 145.101 -
 145.102 -/* This is the size of the compression buffer, and thus the size of
 145.103 - * an IDAT chunk.  Make this whatever size you feel is best for your
 145.104 - * machine.  One of these will be allocated per png_struct.  When this
 145.105 - * is full, it writes the data to the disk, and does some other
 145.106 - * calculations.  Making this an extremely small size will slow
 145.107 - * the library down, but you may want to experiment to determine
 145.108 - * where it becomes significant, if you are concerned with memory
 145.109 - * usage.  Note that zlib allocates at least 32Kb also.  For readers,
 145.110 - * this describes the size of the buffer available to read the data in.
 145.111 - * Unless this gets smaller than the size of a row (compressed),
 145.112 - * it should not make much difference how big this is.
 145.113 - */
 145.114 -
 145.115 -#ifndef PNG_ZBUF_SIZE
 145.116 -#  define PNG_ZBUF_SIZE 8192
 145.117 -#endif
 145.118 -
 145.119 -/* Enable if you want a write-only libpng */
 145.120 -
 145.121 -#ifndef PNG_NO_READ_SUPPORTED
 145.122 -#  define PNG_READ_SUPPORTED
 145.123 -#endif
 145.124 -
 145.125 -/* Enable if you want a read-only libpng */
 145.126 -
 145.127 -#ifndef PNG_NO_WRITE_SUPPORTED
 145.128 -#  define PNG_WRITE_SUPPORTED
 145.129 -#endif
 145.130 -
 145.131 -/* Enabled by default in 1.2.0.  You can disable this if you don't need to
 145.132 -   support PNGs that are embedded in MNG datastreams */
 145.133 -#if !defined(PNG_1_0_X) && !defined(PNG_NO_MNG_FEATURES)
 145.134 -#  ifndef PNG_MNG_FEATURES_SUPPORTED
 145.135 -#    define PNG_MNG_FEATURES_SUPPORTED
 145.136 +#  ifdef PNG_STDIO_SUPPORTED
 145.137 +#    include <stdio.h>
 145.138  #  endif
 145.139  #endif
 145.140  
 145.141 -#ifndef PNG_NO_FLOATING_POINT_SUPPORTED
 145.142 -#  ifndef PNG_FLOATING_POINT_SUPPORTED
 145.143 -#    define PNG_FLOATING_POINT_SUPPORTED
 145.144 +/* This controls optimization of the reading of 16 and 32 bit values
 145.145 + * from PNG files.  It can be set on a per-app-file basis - it
 145.146 + * just changes whether a macro is used to the function is called.
 145.147 + * The library builder sets the default, if read functions are not
 145.148 + * built into the library the macro implementation is forced on.
 145.149 + */
 145.150 +#ifndef PNG_READ_INT_FUNCTIONS_SUPPORTED
 145.151 +#  define PNG_USE_READ_MACROS
 145.152 +#endif
 145.153 +#if !defined(PNG_NO_USE_READ_MACROS) && !defined(PNG_USE_READ_MACROS)
 145.154 +#  if PNG_DEFAULT_READ_MACROS
 145.155 +#    define PNG_USE_READ_MACROS
 145.156  #  endif
 145.157  #endif
 145.158  
 145.159 -/* If you are running on a machine where you cannot allocate more
 145.160 - * than 64K of memory at once, uncomment this.  While libpng will not
 145.161 - * normally need that much memory in a chunk (unless you load up a very
 145.162 - * large file), zlib needs to know how big of a chunk it can use, and
 145.163 - * libpng thus makes sure to check any memory allocation to verify it
 145.164 - * will fit into memory.
 145.165 -#define PNG_MAX_MALLOC_64K
 145.166 - */
 145.167 -#if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K)
 145.168 -#  define PNG_MAX_MALLOC_64K
 145.169 -#endif
 145.170 -
 145.171 -/* Special munging to support doing things the 'cygwin' way:
 145.172 - * 'Normal' png-on-win32 defines/defaults:
 145.173 - *   PNG_BUILD_DLL -- building dll
 145.174 - *   PNG_USE_DLL   -- building an application, linking to dll
 145.175 - *   (no define)   -- building static library, or building an
 145.176 - *                    application and linking to the static lib
 145.177 - * 'Cygwin' defines/defaults:
 145.178 - *   PNG_BUILD_DLL -- (ignored) building the dll
 145.179 - *   (no define)   -- (ignored) building an application, linking to the dll
 145.180 - *   PNG_STATIC    -- (ignored) building the static lib, or building an
 145.181 - *                    application that links to the static lib.
 145.182 - *   ALL_STATIC    -- (ignored) building various static libs, or building an
 145.183 - *                    application that links to the static libs.
 145.184 - * Thus,
 145.185 - * a cygwin user should define either PNG_BUILD_DLL or PNG_STATIC, and
 145.186 - * this bit of #ifdefs will define the 'correct' config variables based on
 145.187 - * that. If a cygwin user *wants* to define 'PNG_USE_DLL' that's okay, but
 145.188 - * unnecessary.
 145.189 +/* COMPILER SPECIFIC OPTIONS.
 145.190   *
 145.191 - * Also, the precedence order is:
 145.192 - *   ALL_STATIC (since we can't #undef something outside our namespace)
 145.193 - *   PNG_BUILD_DLL
 145.194 - *   PNG_STATIC
 145.195 - *   (nothing) == PNG_USE_DLL
 145.196 - *
 145.197 - * CYGWIN (2002-01-20): The preceding is now obsolete. With the advent
 145.198 - *   of auto-import in binutils, we no longer need to worry about
 145.199 - *   __declspec(dllexport) / __declspec(dllimport) and friends.  Therefore,
 145.200 - *   we don't need to worry about PNG_STATIC or ALL_STATIC when it comes
 145.201 - *   to __declspec() stuff.  However, we DO need to worry about
 145.202 - *   PNG_BUILD_DLL and PNG_STATIC because those change some defaults
 145.203 - *   such as CONSOLE_IO and whether GLOBAL_ARRAYS are allowed.
 145.204 - */
 145.205 -#if defined(__CYGWIN__)
 145.206 -#  if defined(ALL_STATIC)
 145.207 -#    if defined(PNG_BUILD_DLL)
 145.208 -#      undef PNG_BUILD_DLL
 145.209 -#    endif
 145.210 -#    if defined(PNG_USE_DLL)
 145.211 -#      undef PNG_USE_DLL
 145.212 -#    endif
 145.213 -#    if defined(PNG_DLL)
 145.214 -#      undef PNG_DLL
 145.215 -#    endif
 145.216 -#    if !defined(PNG_STATIC)
 145.217 -#      define PNG_STATIC
 145.218 -#    endif
 145.219 -#  else
 145.220 -#    if defined (PNG_BUILD_DLL)
 145.221 -#      if defined(PNG_STATIC)
 145.222 -#        undef PNG_STATIC
 145.223 -#      endif
 145.224 -#      if defined(PNG_USE_DLL)
 145.225 -#        undef PNG_USE_DLL
 145.226 -#      endif
 145.227 -#      if !defined(PNG_DLL)
 145.228 -#        define PNG_DLL
 145.229 -#      endif
 145.230 -#    else
 145.231 -#      if defined(PNG_STATIC)
 145.232 -#        if defined(PNG_USE_DLL)
 145.233 -#          undef PNG_USE_DLL
 145.234 -#        endif
 145.235 -#        if defined(PNG_DLL)
 145.236 -#          undef PNG_DLL
 145.237 -#        endif
 145.238 -#      else
 145.239 -#        if !defined(PNG_USE_DLL)
 145.240 -#          define PNG_USE_DLL
 145.241 -#        endif
 145.242 -#        if !defined(PNG_DLL)
 145.243 -#          define PNG_DLL
 145.244 -#        endif
 145.245 -#      endif
 145.246 -#    endif
 145.247 -#  endif
 145.248 -#endif
 145.249 -
 145.250 -/* This protects us against compilers that run on a windowing system
 145.251 - * and thus don't have or would rather us not use the stdio types:
 145.252 - * stdin, stdout, and stderr.  The only one currently used is stderr
 145.253 - * in png_error() and png_warning().  #defining PNG_NO_CONSOLE_IO will
 145.254 - * prevent these from being compiled and used. #defining PNG_NO_STDIO
 145.255 - * will also prevent these, plus will prevent the entire set of stdio
 145.256 - * macros and functions (FILE *, printf, etc.) from being compiled and used,
 145.257 - * unless (PNG_DEBUG > 0) has been #defined.
 145.258 - *
 145.259 - * #define PNG_NO_CONSOLE_IO
 145.260 - * #define PNG_NO_STDIO
 145.261 + * These options are provided so that a variety of difficult compilers
 145.262 + * can be used.  Some are fixed at build time (e.g. PNG_API_RULE
 145.263 + * below) but still have compiler specific implementations, others
 145.264 + * may be changed on a per-file basis when compiling against libpng.
 145.265   */
 145.266  
 145.267 -#if defined(_WIN32_WCE)
 145.268 -#  include <windows.h>
 145.269 -   /* Console I/O functions are not supported on WindowsCE */
 145.270 -#  define PNG_NO_CONSOLE_IO
 145.271 -#  ifdef PNG_DEBUG
 145.272 -#    undef PNG_DEBUG
 145.273 -#  endif
 145.274 -#endif
 145.275 -
 145.276 -#ifdef PNG_BUILD_DLL
 145.277 -#  ifndef PNG_CONSOLE_IO_SUPPORTED
 145.278 -#    ifndef PNG_NO_CONSOLE_IO
 145.279 -#      define PNG_NO_CONSOLE_IO
 145.280 -#    endif
 145.281 -#  endif
 145.282 -#endif
 145.283 -
 145.284 -#  ifdef PNG_NO_STDIO
 145.285 -#    ifndef PNG_NO_CONSOLE_IO
 145.286 -#      define PNG_NO_CONSOLE_IO
 145.287 -#    endif
 145.288 -#    ifdef PNG_DEBUG
 145.289 -#      if (PNG_DEBUG > 0)
 145.290 -#        include <stdio.h>
 145.291 -#      endif
 145.292 -#    endif
 145.293 -#  else
 145.294 -#    if !defined(_WIN32_WCE)
 145.295 -/* "stdio.h" functions are not supported on WindowsCE */
 145.296 -#      include <stdio.h>
 145.297 -#    endif
 145.298 -#  endif
 145.299 -
 145.300 -/* This macro protects us against machines that don't have function
 145.301 +/* The PNGARG macro protects us against machines that don't have function
 145.302   * prototypes (ie K&R style headers).  If your compiler does not handle
 145.303   * function prototypes, define this macro and use the included ansi2knr.
 145.304   * I've always been able to use _NO_PROTO as the indicator, but you may
 145.305 @@ -291,824 +109,374 @@
 145.306   */
 145.307  #ifndef PNGARG
 145.308  
 145.309 -#ifdef OF /* zlib prototype munger */
 145.310 -#  define PNGARG(arglist) OF(arglist)
 145.311 -#else
 145.312 +#  ifdef OF /* zlib prototype munger */
 145.313 +#    define PNGARG(arglist) OF(arglist)
 145.314 +#  else
 145.315  
 145.316 -#ifdef _NO_PROTO
 145.317 -#  define PNGARG(arglist) ()
 145.318 -#  ifndef PNG_TYPECAST_NULL
 145.319 -#     define PNG_TYPECAST_NULL
 145.320 -#  endif
 145.321 -#else
 145.322 -#  define PNGARG(arglist) arglist
 145.323 -#endif /* _NO_PROTO */
 145.324 +#    ifdef _NO_PROTO
 145.325 +#      define PNGARG(arglist) ()
 145.326 +#    else
 145.327 +#      define PNGARG(arglist) arglist
 145.328 +#    endif /* _NO_PROTO */
 145.329  
 145.330 -#endif /* OF */
 145.331 +#  endif /* OF */
 145.332  
 145.333  #endif /* PNGARG */
 145.334  
 145.335 -/* Try to determine if we are compiling on a Mac.  Note that testing for
 145.336 - * just __MWERKS__ is not good enough, because the Codewarrior is now used
 145.337 - * on non-Mac platforms.
 145.338 +/* Function calling conventions.
 145.339 + * =============================
 145.340 + * Normally it is not necessary to specify to the compiler how to call
 145.341 + * a function - it just does it - however on x86 systems derived from
 145.342 + * Microsoft and Borland C compilers ('IBM PC', 'DOS', 'Windows' systems
 145.343 + * and some others) there are multiple ways to call a function and the
 145.344 + * default can be changed on the compiler command line.  For this reason
 145.345 + * libpng specifies the calling convention of every exported function and
 145.346 + * every function called via a user supplied function pointer.  This is
 145.347 + * done in this file by defining the following macros:
 145.348 + *
 145.349 + * PNGAPI    Calling convention for exported functions.
 145.350 + * PNGCBAPI  Calling convention for user provided (callback) functions.
 145.351 + * PNGCAPI   Calling convention used by the ANSI-C library (required
 145.352 + *           for longjmp callbacks and sometimes used internally to
 145.353 + *           specify the calling convention for zlib).
 145.354 + *
 145.355 + * These macros should never be overridden.  If it is necessary to
 145.356 + * change calling convention in a private build this can be done
 145.357 + * by setting PNG_API_RULE (which defaults to 0) to one of the values
 145.358 + * below to select the correct 'API' variants.
 145.359 + *
 145.360 + * PNG_API_RULE=0 Use PNGCAPI - the 'C' calling convention - throughout.
 145.361 + *                This is correct in every known environment.
 145.362 + * PNG_API_RULE=1 Use the operating system convention for PNGAPI and
 145.363 + *                the 'C' calling convention (from PNGCAPI) for
 145.364 + *                callbacks (PNGCBAPI).  This is no longer required
 145.365 + *                in any known environment - if it has to be used
 145.366 + *                please post an explanation of the problem to the
 145.367 + *                libpng mailing list.
 145.368 + *
 145.369 + * These cases only differ if the operating system does not use the C
 145.370 + * calling convention, at present this just means the above cases
 145.371 + * (x86 DOS/Windows sytems) and, even then, this does not apply to
 145.372 + * Cygwin running on those systems.
 145.373 + *
 145.374 + * Note that the value must be defined in pnglibconf.h so that what
 145.375 + * the application uses to call the library matches the conventions
 145.376 + * set when building the library.
 145.377   */
 145.378 -#ifndef MACOS
 145.379 -#  if (defined(__MWERKS__) && defined(macintosh)) || defined(applec) || \
 145.380 -      defined(THINK_C) || defined(__SC__) || defined(TARGET_OS_MAC)
 145.381 -#    define MACOS
 145.382 +
 145.383 +/* Symbol export
 145.384 + * =============
 145.385 + * When building a shared library it is almost always necessary to tell
 145.386 + * the compiler which symbols to export.  The png.h macro 'PNG_EXPORT'
 145.387 + * is used to mark the symbols.  On some systems these symbols can be
 145.388 + * extracted at link time and need no special processing by the compiler,
 145.389 + * on other systems the symbols are flagged by the compiler and just
 145.390 + * the declaration requires a special tag applied (unfortunately) in a
 145.391 + * compiler dependent way.  Some systems can do either.
 145.392 + *
 145.393 + * A small number of older systems also require a symbol from a DLL to
 145.394 + * be flagged to the program that calls it.  This is a problem because
 145.395 + * we do not know in the header file included by application code that
 145.396 + * the symbol will come from a shared library, as opposed to a statically
 145.397 + * linked one.  For this reason the application must tell us by setting
 145.398 + * the magic flag PNG_USE_DLL to turn on the special processing before
 145.399 + * it includes png.h.
 145.400 + *
 145.401 + * Four additional macros are used to make this happen:
 145.402 + *
 145.403 + * PNG_IMPEXP The magic (if any) to cause a symbol to be exported from
 145.404 + *            the build or imported if PNG_USE_DLL is set - compiler
 145.405 + *            and system specific.
 145.406 + *
 145.407 + * PNG_EXPORT_TYPE(type) A macro that pre or appends PNG_IMPEXP to
 145.408 + *                       'type', compiler specific.
 145.409 + *
 145.410 + * PNG_DLL_EXPORT Set to the magic to use during a libpng build to
 145.411 + *                make a symbol exported from the DLL.
 145.412 + *
 145.413 + * PNG_DLL_IMPORT Set to the magic to force the libpng symbols to come
 145.414 + *                from a DLL - used to define PNG_IMPEXP when
 145.415 + *                PNG_USE_DLL is set.
 145.416 + */
 145.417 +
 145.418 +/* System specific discovery.
 145.419 + * ==========================
 145.420 + * This code is used at build time to find PNG_IMPEXP, the API settings
 145.421 + * and PNG_EXPORT_TYPE(), it may also set a macro to indicate the DLL
 145.422 + * import processing is possible.  On Windows/x86 systems it also sets
 145.423 + * compiler-specific macros to the values required to change the calling
 145.424 + * conventions of the various functions.
 145.425 + */
 145.426 +#if ( defined(_Windows) || defined(_WINDOWS) || defined(WIN32) ||\
 145.427 +      defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) ) &&\
 145.428 +    ( defined(_X86_) || defined(_X64_) || defined(_M_IX86) ||\
 145.429 +      defined(_M_X64) || defined(_M_IA64) )
 145.430 +  /* Windows system (DOS doesn't support DLLs) running on x86/x64.  Includes
 145.431 +   * builds under Cygwin or MinGW.  Also includes Watcom builds but these need
 145.432 +   * special treatment because they are not compatible with GCC or Visual C
 145.433 +   * because of different calling conventions.
 145.434 +   */
 145.435 +#  if PNG_API_RULE == 2
 145.436 +    /* If this line results in an error, either because __watcall is not
 145.437 +     * understood or because of a redefine just below you cannot use *this*
 145.438 +     * build of the library with the compiler you are using.  *This* build was
 145.439 +     * build using Watcom and applications must also be built using Watcom!
 145.440 +     */
 145.441 +#    define PNGCAPI __watcall
 145.442 +#  endif
 145.443 +
 145.444 +#  if defined(__GNUC__) || (defined (_MSC_VER) && (_MSC_VER >= 800))
 145.445 +#    define PNGCAPI __cdecl
 145.446 +#    if PNG_API_RULE == 1
 145.447 +#      define PNGAPI __stdcall
 145.448 +#    endif
 145.449 +#  else
 145.450 +    /* An older compiler, or one not detected (erroneously) above,
 145.451 +     * if necessary override on the command line to get the correct
 145.452 +     * variants for the compiler.
 145.453 +     */
 145.454 +#    ifndef PNGCAPI
 145.455 +#      define PNGCAPI _cdecl
 145.456 +#    endif
 145.457 +#    if PNG_API_RULE == 1 && !defined(PNGAPI)
 145.458 +#      define PNGAPI _stdcall
 145.459 +#    endif
 145.460 +#  endif /* compiler/api */
 145.461 +  /* NOTE: PNGCBAPI always defaults to PNGCAPI. */
 145.462 +
 145.463 +#  if defined(PNGAPI) && !defined(PNG_USER_PRIVATEBUILD)
 145.464 +   ERROR: PNG_USER_PRIVATEBUILD must be defined if PNGAPI is changed
 145.465 +#  endif
 145.466 +
 145.467 +#  if (defined(_MSC_VER) && _MSC_VER < 800) ||\
 145.468 +      (defined(__BORLANDC__) && __BORLANDC__ < 0x500)
 145.469 +    /* older Borland and MSC
 145.470 +     * compilers used '__export' and required this to be after
 145.471 +     * the type.
 145.472 +     */
 145.473 +#    ifndef PNG_EXPORT_TYPE
 145.474 +#      define PNG_EXPORT_TYPE(type) type PNG_IMPEXP
 145.475 +#    endif
 145.476 +#    define PNG_DLL_EXPORT __export
 145.477 +#  else /* newer compiler */
 145.478 +#    define PNG_DLL_EXPORT __declspec(dllexport)
 145.479 +#    ifndef PNG_DLL_IMPORT
 145.480 +#      define PNG_DLL_IMPORT __declspec(dllimport)
 145.481 +#    endif
 145.482 +#  endif /* compiler */
 145.483 +
 145.484 +#else /* !Windows/x86 */
 145.485 +#  if (defined(__IBMC__) || defined(__IBMCPP__)) && defined(__OS2__)
 145.486 +#    define PNGAPI _System
 145.487 +#  else /* !Windows/x86 && !OS/2 */
 145.488 +    /* Use the defaults, or define PNG*API on the command line (but
 145.489 +     * this will have to be done for every compile!)
 145.490 +     */
 145.491 +#  endif /* other system, !OS/2 */
 145.492 +#endif /* !Windows/x86 */
 145.493 +
 145.494 +/* Now do all the defaulting . */
 145.495 +#ifndef PNGCAPI
 145.496 +#  define PNGCAPI
 145.497 +#endif
 145.498 +#ifndef PNGCBAPI
 145.499 +#  define PNGCBAPI PNGCAPI
 145.500 +#endif
 145.501 +#ifndef PNGAPI
 145.502 +#  define PNGAPI PNGCAPI
 145.503 +#endif
 145.504 +
 145.505 +/* The default for PNG_IMPEXP depends on whether the library is
 145.506 + * being built or used.
 145.507 + */
 145.508 +#ifndef PNG_IMPEXP
 145.509 +#  ifdef PNGLIB_BUILD
 145.510 +    /* Building the library */
 145.511 +#    if (defined(DLL_EXPORT)/*from libtool*/ ||\
 145.512 +        defined(_WINDLL) || defined(_DLL) || defined(__DLL__) ||\
 145.513 +        defined(_USRDLL) ||\
 145.514 +        defined(PNG_BUILD_DLL)) && defined(PNG_DLL_EXPORT)
 145.515 +      /* Building a DLL. */
 145.516 +#      define PNG_IMPEXP PNG_DLL_EXPORT
 145.517 +#    endif /* DLL */
 145.518 +#  else
 145.519 +    /* Using the library */
 145.520 +#    if defined(PNG_USE_DLL) && defined(PNG_DLL_IMPORT)
 145.521 +      /* This forces use of a DLL, disallowing static linking */
 145.522 +#      define PNG_IMPEXP PNG_DLL_IMPORT
 145.523 +#    endif
 145.524 +#  endif
 145.525 +
 145.526 +#  ifndef PNG_IMPEXP
 145.527 +#    define PNG_IMPEXP
 145.528  #  endif
 145.529  #endif
 145.530  
 145.531 -/* enough people need this for various reasons to include it here */
 145.532 -#if !defined(MACOS) && !defined(RISCOS) && !defined(_WIN32_WCE)
 145.533 -#  include <sys/types.h>
 145.534 +/* In 1.5.2 the definition of PNG_FUNCTION has been changed to always treat
 145.535 + * 'attributes' as a storage class - the attributes go at the start of the
 145.536 + * function definition, and attributes are always appended regardless of the
 145.537 + * compiler.  This considerably simplifies these macros but may cause problems
 145.538 + * if any compilers both need function attributes and fail to handle them as
 145.539 + * a storage class (this is unlikely.)
 145.540 + */
 145.541 +#ifndef PNG_FUNCTION
 145.542 +#  define PNG_FUNCTION(type, name, args, attributes) attributes type name args
 145.543  #endif
 145.544  
 145.545 -#if !defined(PNG_SETJMP_NOT_SUPPORTED) && !defined(PNG_NO_SETJMP_SUPPORTED)
 145.546 -#  define PNG_SETJMP_SUPPORTED
 145.547 +#ifndef PNG_EXPORT_TYPE
 145.548 +#  define PNG_EXPORT_TYPE(type) PNG_IMPEXP type
 145.549  #endif
 145.550  
 145.551 -#ifdef PNG_SETJMP_SUPPORTED
 145.552 -/* This is an attempt to force a single setjmp behaviour on Linux.  If
 145.553 - * the X config stuff didn't define _BSD_SOURCE we wouldn't need this.
 145.554 +   /* The ordinal value is only relevant when preprocessing png.h for symbol
 145.555 +    * table entries, so we discard it here.  See the .dfn files in the
 145.556 +    * scripts directory.
 145.557 +    */
 145.558 +#ifndef PNG_EXPORTA
 145.559 +
 145.560 +#  define PNG_EXPORTA(ordinal, type, name, args, attributes)\
 145.561 +      PNG_FUNCTION(PNG_EXPORT_TYPE(type),(PNGAPI name),PNGARG(args), \
 145.562 +        extern attributes)
 145.563 +#endif
 145.564 +
 145.565 +/* ANSI-C (C90) does not permit a macro to be invoked with an empty argument,
 145.566 + * so make something non-empty to satisfy the requirement:
 145.567 + */
 145.568 +#define PNG_EMPTY /*empty list*/
 145.569 +
 145.570 +#define PNG_EXPORT(ordinal, type, name, args)\
 145.571 +   PNG_EXPORTA(ordinal, type, name, args, PNG_EMPTY)
 145.572 +
 145.573 +/* Use PNG_REMOVED to comment out a removed interface. */
 145.574 +#ifndef PNG_REMOVED
 145.575 +#  define PNG_REMOVED(ordinal, type, name, args, attributes)
 145.576 +#endif
 145.577 +
 145.578 +#ifndef PNG_CALLBACK
 145.579 +#  define PNG_CALLBACK(type, name, args) type (PNGCBAPI name) PNGARG(args)
 145.580 +#endif
 145.581 +
 145.582 +/* Support for compiler specific function attributes.  These are used
 145.583 + * so that where compiler support is available incorrect use of API
 145.584 + * functions in png.h will generate compiler warnings.
 145.585 + *
 145.586 + * Added at libpng-1.2.41.
 145.587   */
 145.588  
 145.589 -#  ifdef __linux__
 145.590 -#    ifdef _BSD_SOURCE
 145.591 -#      define PNG_SAVE_BSD_SOURCE
 145.592 -#      undef _BSD_SOURCE
 145.593 -#    endif
 145.594 -#    ifdef _SETJMP_H
 145.595 -     /* If you encounter a compiler error here, see the explanation
 145.596 -      * near the end of INSTALL.
 145.597 -      */
 145.598 -         __png.h__ already includes setjmp.h;
 145.599 -         __dont__ include it again.;
 145.600 -#    endif
 145.601 -#  endif /* __linux__ */
 145.602 -
 145.603 -   /* include setjmp.h for error handling */
 145.604 -#  include <setjmp.h>
 145.605 -
 145.606 -#  ifdef __linux__
 145.607 -#    ifdef PNG_SAVE_BSD_SOURCE
 145.608 -#      define _BSD_SOURCE
 145.609 -#      undef PNG_SAVE_BSD_SOURCE
 145.610 -#    endif
 145.611 -#  endif /* __linux__ */
 145.612 -#endif /* PNG_SETJMP_SUPPORTED */
 145.613 -
 145.614 -#ifdef BSD
 145.615 -#  include <strings.h>
 145.616 -#else
 145.617 -#  include <string.h>
 145.618 -#endif
 145.619 -
 145.620 -/* Other defines for things like memory and the like can go here.  */
 145.621 -#ifdef PNG_INTERNAL
 145.622 -
 145.623 -#include <stdlib.h>
 145.624 -
 145.625 -/* The functions exported by PNG_EXTERN are PNG_INTERNAL functions, which
 145.626 - * aren't usually used outside the library (as far as I know), so it is
 145.627 - * debatable if they should be exported at all.  In the future, when it is
 145.628 - * possible to have run-time registry of chunk-handling functions, some of
 145.629 - * these will be made available again.
 145.630 -#define PNG_EXTERN extern
 145.631 - */
 145.632 -#define PNG_EXTERN
 145.633 -
 145.634 -/* Other defines specific to compilers can go here.  Try to keep
 145.635 - * them inside an appropriate ifdef/endif pair for portability.
 145.636 - */
 145.637 -
 145.638 -#if defined(PNG_FLOATING_POINT_SUPPORTED)
 145.639 -#  if defined(MACOS)
 145.640 -     /* We need to check that <math.h> hasn't already been included earlier
 145.641 -      * as it seems it doesn't agree with <fp.h>, yet we should really use
 145.642 -      * <fp.h> if possible.
 145.643 -      */
 145.644 -#    if !defined(__MATH_H__) && !defined(__MATH_H) && !defined(__cmath__)
 145.645 -#      include <fp.h>
 145.646 -#    endif
 145.647 -#  else
 145.648 -#    include <math.h>
 145.649 -#  endif
 145.650 -#  if defined(_AMIGA) && defined(__SASC) && defined(_M68881)
 145.651 -     /* Amiga SAS/C: We must include builtin FPU functions when compiling using
 145.652 -      * MATH=68881
 145.653 -      */
 145.654 -#    include <m68881.h>
 145.655 +#ifndef PNG_NO_PEDANTIC_WARNINGS
 145.656 +#  ifndef PNG_PEDANTIC_WARNINGS_SUPPORTED
 145.657 +#    define PNG_PEDANTIC_WARNINGS_SUPPORTED
 145.658  #  endif
 145.659  #endif
 145.660  
 145.661 -/* Codewarrior on NT has linking problems without this. */
 145.662 -#if (defined(__MWERKS__) && defined(WIN32)) || defined(__STDC__)
 145.663 -#  define PNG_ALWAYS_EXTERN
 145.664 +#ifdef PNG_PEDANTIC_WARNINGS_SUPPORTED
 145.665 +  /* Support for compiler specific function attributes.  These are used
 145.666 +   * so that where compiler support is available incorrect use of API
 145.667 +   * functions in png.h will generate compiler warnings.  Added at libpng
 145.668 +   * version 1.2.41.
 145.669 +   */
 145.670 +#  if defined(__GNUC__)
 145.671 +#    ifndef PNG_USE_RESULT
 145.672 +#      define PNG_USE_RESULT __attribute__((__warn_unused_result__))
 145.673 +#    endif
 145.674 +#    ifndef PNG_NORETURN
 145.675 +#      define PNG_NORETURN   __attribute__((__noreturn__))
 145.676 +#    endif
 145.677 +#    ifndef PNG_ALLOCATED
 145.678 +#      define PNG_ALLOCATED  __attribute__((__malloc__))
 145.679 +#    endif
 145.680 +
 145.681 +    /* This specifically protects structure members that should only be
 145.682 +     * accessed from within the library, therefore should be empty during
 145.683 +     * a library build.
 145.684 +     */
 145.685 +#    ifndef PNGLIB_BUILD
 145.686 +#      ifndef PNG_DEPRECATED
 145.687 +#        define PNG_DEPRECATED __attribute__((__deprecated__))
 145.688 +#      endif
 145.689 +#      ifndef PNG_PRIVATE
 145.690 +#        if 0 /* Doesn't work so we use deprecated instead*/
 145.691 +#          define PNG_PRIVATE \
 145.692 +            __attribute__((warning("This function is not exported by libpng.")))
 145.693 +#        else
 145.694 +#          define PNG_PRIVATE \
 145.695 +            __attribute__((__deprecated__))
 145.696 +#        endif
 145.697 +#      endif
 145.698 +#    endif /* PNGLIB_BUILD */
 145.699 +#  endif /* __GNUC__ */
 145.700 +
 145.701 +#  if defined(_MSC_VER)  && (_MSC_VER >= 1300)
 145.702 +#    ifndef PNG_USE_RESULT
 145.703 +#      define PNG_USE_RESULT /* not supported */
 145.704 +#    endif
 145.705 +#    ifndef PNG_NORETURN
 145.706 +#      define PNG_NORETURN   __declspec(noreturn)
 145.707 +#    endif
 145.708 +#    ifndef PNG_ALLOCATED
 145.709 +#      if (_MSC_VER >= 1400)
 145.710 +#        define PNG_ALLOCATED __declspec(restrict)
 145.711 +#      endif
 145.712 +#    endif
 145.713 +
 145.714 +    /* This specifically protects structure members that should only be
 145.715 +     * accessed from within the library, therefore should be empty during
 145.716 +     * a library build.
 145.717 +     */
 145.718 +#    ifndef PNGLIB_BUILD
 145.719 +#      ifndef PNG_DEPRECATED
 145.720 +#        define PNG_DEPRECATED __declspec(deprecated)
 145.721 +#      endif
 145.722 +#      ifndef PNG_PRIVATE
 145.723 +#        define PNG_PRIVATE __declspec(deprecated)
 145.724 +#      endif
 145.725 +#    endif /* PNGLIB_BUILD */
 145.726 +#  endif /* _MSC_VER */
 145.727 +#endif /* PNG_PEDANTIC_WARNINGS */
 145.728 +
 145.729 +#ifndef PNG_DEPRECATED
 145.730 +#  define PNG_DEPRECATED  /* Use of this function is deprecated */
 145.731  #endif
 145.732 -
 145.733 -/* This provides the non-ANSI (far) memory allocation routines. */
 145.734 -#if defined(__TURBOC__) && defined(__MSDOS__)
 145.735 -#  include <mem.h>
 145.736 -#  include <alloc.h>
 145.737 +#ifndef PNG_USE_RESULT
 145.738 +#  define PNG_USE_RESULT  /* The result of this function must be checked */
 145.739  #endif
 145.740 -
 145.741 -/* I have no idea why is this necessary... */
 145.742 -#if defined(_MSC_VER) && (defined(WIN32) || defined(_Windows) || \
 145.743 -    defined(_WINDOWS) || defined(_WIN32) || defined(__WIN32__))
 145.744 -#  include <malloc.h>
 145.745 +#ifndef PNG_NORETURN
 145.746 +#  define PNG_NORETURN    /* This function does not return */
 145.747  #endif
 145.748 -
 145.749 -/* This controls how fine the dithering gets.  As this allocates
 145.750 - * a largish chunk of memory (32K), those who are not as concerned
 145.751 - * with dithering quality can decrease some or all of these.
 145.752 - */
 145.753 -#ifndef PNG_DITHER_RED_BITS
 145.754 -#  define PNG_DITHER_RED_BITS 5
 145.755 +#ifndef PNG_ALLOCATED
 145.756 +#  define PNG_ALLOCATED   /* The result of the function is new memory */
 145.757  #endif
 145.758 -#ifndef PNG_DITHER_GREEN_BITS
 145.759 -#  define PNG_DITHER_GREEN_BITS 5
 145.760 +#ifndef PNG_PRIVATE
 145.761 +#  define PNG_PRIVATE     /* This is a private libpng function */
 145.762  #endif
 145.763 -#ifndef PNG_DITHER_BLUE_BITS
 145.764 -#  define PNG_DITHER_BLUE_BITS 5
 145.765 +#ifndef PNG_FP_EXPORT     /* A floating point API. */
 145.766 +#  ifdef PNG_FLOATING_POINT_SUPPORTED
 145.767 +#     define PNG_FP_EXPORT(ordinal, type, name, args)\
 145.768 +         PNG_EXPORT(ordinal, type, name, args)
 145.769 +#  else                   /* No floating point APIs */
 145.770 +#     define PNG_FP_EXPORT(ordinal, type, name, args)
 145.771 +#  endif
 145.772  #endif
 145.773 -
 145.774 -/* This controls how fine the gamma correction becomes when you
 145.775 - * are only interested in 8 bits anyway.  Increasing this value
 145.776 - * results in more memory being used, and more pow() functions
 145.777 - * being called to fill in the gamma tables.  Don't set this value
 145.778 - * less then 8, and even that may not work (I haven't tested it).
 145.779 - */
 145.780 -
 145.781 -#ifndef PNG_MAX_GAMMA_8
 145.782 -#  define PNG_MAX_GAMMA_8 11
 145.783 +#ifndef PNG_FIXED_EXPORT  /* A fixed point API. */
 145.784 +#  ifdef PNG_FIXED_POINT_SUPPORTED
 145.785 +#     define PNG_FIXED_EXPORT(ordinal, type, name, args)\
 145.786 +         PNG_EXPORT(ordinal, type, name, args)
 145.787 +#  else                   /* No fixed point APIs */
 145.788 +#     define PNG_FIXED_EXPORT(ordinal, type, name, args)
 145.789 +#  endif
 145.790  #endif
 145.791  
 145.792 -/* This controls how much a difference in gamma we can tolerate before
 145.793 - * we actually start doing gamma conversion.
 145.794 - */
 145.795 -#ifndef PNG_GAMMA_THRESHOLD
 145.796 -#  define PNG_GAMMA_THRESHOLD 0.05
 145.797 -#endif
 145.798 -
 145.799 -#endif /* PNG_INTERNAL */
 145.800 -
 145.801  /* The following uses const char * instead of char * for error
 145.802   * and warning message functions, so some compilers won't complain.
 145.803   * If you do not want to use const, define PNG_NO_CONST here.
 145.804 + *
 145.805 + * This should not change how the APIs are called, so it can be done
 145.806 + * on a per-file basis in the application.
 145.807   */
 145.808 -
 145.809 -#ifndef PNG_NO_CONST
 145.810 -#  define PNG_CONST const
 145.811 -#else
 145.812 -#  define PNG_CONST
 145.813 -#endif
 145.814 -
 145.815 -/* The following defines give you the ability to remove code from the
 145.816 - * library that you will not be using.  I wish I could figure out how to
 145.817 - * automate this, but I can't do that without making it seriously hard
 145.818 - * on the users.  So if you are not using an ability, change the #define
 145.819 - * to and #undef, and that part of the library will not be compiled.  If
 145.820 - * your linker can't find a function, you may want to make sure the
 145.821 - * ability is defined here.  Some of these depend upon some others being
 145.822 - * defined.  I haven't figured out all the interactions here, so you may
 145.823 - * have to experiment awhile to get everything to compile.  If you are
 145.824 - * creating or using a shared library, you probably shouldn't touch this,
 145.825 - * as it will affect the size of the structures, and this will cause bad
 145.826 - * things to happen if the library and/or application ever change.
 145.827 - */
 145.828 -
 145.829 -/* Any features you will not be using can be undef'ed here */
 145.830 -
 145.831 -/* GR-P, 0.96a: Set "*TRANSFORMS_SUPPORTED as default but allow user
 145.832 - * to turn it off with "*TRANSFORMS_NOT_SUPPORTED" or *PNG_NO_*_TRANSFORMS
 145.833 - * on the compile line, then pick and choose which ones to define without
 145.834 - * having to edit this file. It is safe to use the *TRANSFORMS_NOT_SUPPORTED
 145.835 - * if you only want to have a png-compliant reader/writer but don't need
 145.836 - * any of the extra transformations.  This saves about 80 kbytes in a
 145.837 - * typical installation of the library. (PNG_NO_* form added in version
 145.838 - * 1.0.1c, for consistency)
 145.839 - */
 145.840 -
 145.841 -/* The size of the png_text structure changed in libpng-1.0.6 when
 145.842 - * iTXt support was added.  iTXt support was turned off by default through
 145.843 - * libpng-1.2.x, to support old apps that malloc the png_text structure
 145.844 - * instead of calling png_set_text() and letting libpng malloc it.  It
 145.845 - * was turned on by default in libpng-1.3.0.
 145.846 - */
 145.847 -
 145.848 -#if defined(PNG_1_0_X) || defined (PNG_1_2_X)
 145.849 -#  ifndef PNG_NO_iTXt_SUPPORTED
 145.850 -#    define PNG_NO_iTXt_SUPPORTED
 145.851 -#  endif
 145.852 -#  ifndef PNG_NO_READ_iTXt
 145.853 -#    define PNG_NO_READ_iTXt
 145.854 -#  endif
 145.855 -#  ifndef PNG_NO_WRITE_iTXt
 145.856 -#    define PNG_NO_WRITE_iTXt
 145.857 -#  endif
 145.858 -#endif
 145.859 -
 145.860 -#if !defined(PNG_NO_iTXt_SUPPORTED)
 145.861 -#  if !defined(PNG_READ_iTXt_SUPPORTED) && !defined(PNG_NO_READ_iTXt)
 145.862 -#    define PNG_READ_iTXt
 145.863 -#  endif
 145.864 -#  if !defined(PNG_WRITE_iTXt_SUPPORTED) && !defined(PNG_NO_WRITE_iTXt)
 145.865 -#    define PNG_WRITE_iTXt
 145.866 -#  endif
 145.867 -#endif
 145.868 -
 145.869 -/* The following support, added after version 1.0.0, can be turned off here en
 145.870 - * masse by defining PNG_LEGACY_SUPPORTED in case you need binary compatibility
 145.871 - * with old applications that require the length of png_struct and png_info
 145.872 - * to remain unchanged.
 145.873 - */
 145.874 -
 145.875 -#ifdef PNG_LEGACY_SUPPORTED
 145.876 -#  define PNG_NO_FREE_ME
 145.877 -#  define PNG_NO_READ_UNKNOWN_CHUNKS
 145.878 -#  define PNG_NO_WRITE_UNKNOWN_CHUNKS
 145.879 -#  define PNG_NO_READ_USER_CHUNKS
 145.880 -#  define PNG_NO_READ_iCCP
 145.881 -#  define PNG_NO_WRITE_iCCP
 145.882 -#  define PNG_NO_READ_iTXt
 145.883 -#  define PNG_NO_WRITE_iTXt
 145.884 -#  define PNG_NO_READ_sCAL
 145.885 -#  define PNG_NO_WRITE_sCAL
 145.886 -#  define PNG_NO_READ_sPLT
 145.887 -#  define PNG_NO_WRITE_sPLT
 145.888 -#  define PNG_NO_INFO_IMAGE
 145.889 -#  define PNG_NO_READ_RGB_TO_GRAY
 145.890 -#  define PNG_NO_READ_USER_TRANSFORM
 145.891 -#  define PNG_NO_WRITE_USER_TRANSFORM
 145.892 -#  define PNG_NO_USER_MEM
 145.893 -#  define PNG_NO_READ_EMPTY_PLTE
 145.894 -#  define PNG_NO_MNG_FEATURES
 145.895 -#  define PNG_NO_FIXED_POINT_SUPPORTED
 145.896 -#endif
 145.897 -
 145.898 -/* Ignore attempt to turn off both floating and fixed point support */
 145.899 -#if !defined(PNG_FLOATING_POINT_SUPPORTED) || \
 145.900 -    !defined(PNG_NO_FIXED_POINT_SUPPORTED)
 145.901 -#  define PNG_FIXED_POINT_SUPPORTED
 145.902 -#endif
 145.903 -
 145.904 -#ifndef PNG_NO_FREE_ME
 145.905 -#  define PNG_FREE_ME_SUPPORTED
 145.906 -#endif
 145.907 -
 145.908 -#if defined(PNG_READ_SUPPORTED)
 145.909 -
 145.910 -#if !defined(PNG_READ_TRANSFORMS_NOT_SUPPORTED) && \
 145.911 -      !defined(PNG_NO_READ_TRANSFORMS)
 145.912 -#  define PNG_READ_TRANSFORMS_SUPPORTED
 145.913 -#endif
 145.914 -
 145.915 -#ifdef PNG_READ_TRANSFORMS_SUPPORTED
 145.916 -#  ifndef PNG_NO_READ_EXPAND
 145.917 -#    define PNG_READ_EXPAND_SUPPORTED
 145.918 -#  endif
 145.919 -#  ifndef PNG_NO_READ_SHIFT
 145.920 -#    define PNG_READ_SHIFT_SUPPORTED
 145.921 -#  endif
 145.922 -#  ifndef PNG_NO_READ_PACK
 145.923 -#    define PNG_READ_PACK_SUPPORTED
 145.924 -#  endif
 145.925 -#  ifndef PNG_NO_READ_BGR
 145.926 -#    define PNG_READ_BGR_SUPPORTED
 145.927 -#  endif
 145.928 -#  ifndef PNG_NO_READ_SWAP
 145.929 -#    define PNG_READ_SWAP_SUPPORTED
 145.930 -#  endif
 145.931 -#  ifndef PNG_NO_READ_PACKSWAP
 145.932 -#    define PNG_READ_PACKSWAP_SUPPORTED
 145.933 -#  endif
 145.934 -#  ifndef PNG_NO_READ_INVERT
 145.935 -#    define PNG_READ_INVERT_SUPPORTED
 145.936 -#  endif
 145.937 -#  ifndef PNG_NO_READ_DITHER
 145.938 -#    define PNG_READ_DITHER_SUPPORTED
 145.939 -#  endif
 145.940 -#  ifndef PNG_NO_READ_BACKGROUND
 145.941 -#    define PNG_READ_BACKGROUND_SUPPORTED
 145.942 -#  endif
 145.943 -#  ifndef PNG_NO_READ_16_TO_8
 145.944 -#    define PNG_READ_16_TO_8_SUPPORTED
 145.945 -#  endif
 145.946 -#  ifndef PNG_NO_READ_FILLER
 145.947 -#    define PNG_READ_FILLER_SUPPORTED
 145.948 -#  endif
 145.949 -#  ifndef PNG_NO_READ_GAMMA
 145.950 -#    define PNG_READ_GAMMA_SUPPORTED
 145.951 -#  endif
 145.952 -#  ifndef PNG_NO_READ_GRAY_TO_RGB
 145.953 -#    define PNG_READ_GRAY_TO_RGB_SUPPORTED
 145.954 -#  endif
 145.955 -#  ifndef PNG_NO_READ_SWAP_ALPHA
 145.956 -#    define PNG_READ_SWAP_ALPHA_SUPPORTED
 145.957 -#  endif
 145.958 -#  ifndef PNG_NO_READ_INVERT_ALPHA
 145.959 -#    define PNG_READ_INVERT_ALPHA_SUPPORTED
 145.960 -#  endif
 145.961 -#  ifndef PNG_NO_READ_STRIP_ALPHA
 145.962 -#    define PNG_READ_STRIP_ALPHA_SUPPORTED
 145.963 -#  endif
 145.964 -#  ifndef PNG_NO_READ_USER_TRANSFORM
 145.965 -#    define PNG_READ_USER_TRANSFORM_SUPPORTED
 145.966 -#  endif
 145.967 -#  ifndef PNG_NO_READ_RGB_TO_GRAY
 145.968 -#    define PNG_READ_RGB_TO_GRAY_SUPPORTED
 145.969 -#  endif
 145.970 -#endif /* PNG_READ_TRANSFORMS_SUPPORTED */
 145.971 -
 145.972 -#if !defined(PNG_NO_PROGRESSIVE_READ) && \
 145.973 - !defined(PNG_PROGRESSIVE_READ_NOT_SUPPORTED)  /* if you don't do progressive */
 145.974 -#  define PNG_PROGRESSIVE_READ_SUPPORTED     /* reading.  This is not talking */
 145.975 -#endif                               /* about interlacing capability!  You'll */
 145.976 -              /* still have interlacing unless you change the following line: */
 145.977 -
 145.978 -#define PNG_READ_INTERLACING_SUPPORTED /* required for PNG-compliant decoders */
 145.979 -
 145.980 -#ifndef PNG_NO_READ_COMPOSITE_NODIV
 145.981 -#  ifndef PNG_NO_READ_COMPOSITED_NODIV  /* libpng-1.0.x misspelling */
 145.982 -#    define PNG_READ_COMPOSITE_NODIV_SUPPORTED   /* well tested on Intel, SGI */
 145.983 -#  endif
 145.984 -#endif
 145.985 -
 145.986 -#if defined(PNG_1_0_X) || defined (PNG_1_2_X)
 145.987 -/* Deprecated, will be removed from version 2.0.0.
 145.988 -   Use PNG_MNG_FEATURES_SUPPORTED instead. */
 145.989 -#ifndef PNG_NO_READ_EMPTY_PLTE
 145.990 -#  define PNG_READ_EMPTY_PLTE_SUPPORTED
 145.991 -#endif
 145.992 -#endif
 145.993 -
 145.994 -#endif /* PNG_READ_SUPPORTED */
 145.995 -
 145.996 -#if defined(PNG_WRITE_SUPPORTED)
 145.997 -
 145.998 -# if !defined(PNG_WRITE_TRANSFORMS_NOT_SUPPORTED) && \
 145.999 -    !defined(PNG_NO_WRITE_TRANSFORMS)
145.1000 -#  define PNG_WRITE_TRANSFORMS_SUPPORTED
145.1001 -#endif
145.1002 -
145.1003 -#ifdef PNG_WRITE_TRANSFORMS_SUPPORTED
145.1004 -#  ifndef PNG_NO_WRITE_SHIFT
145.1005 -#    define PNG_WRITE_SHIFT_SUPPORTED
145.1006 -#  endif
145.1007 -#  ifndef PNG_NO_WRITE_PACK
145.1008 -#    define PNG_WRITE_PACK_SUPPORTED
145.1009 -#  endif
145.1010 -#  ifndef PNG_NO_WRITE_BGR
145.1011 -#    define PNG_WRITE_BGR_SUPPORTED
145.1012 -#  endif
145.1013 -#  ifndef PNG_NO_WRITE_SWAP
145.1014 -#    define PNG_WRITE_SWAP_SUPPORTED
145.1015 -#  endif
145.1016 -#  ifndef PNG_NO_WRITE_PACKSWAP
145.1017 -#    define PNG_WRITE_PACKSWAP_SUPPORTED
145.1018 -#  endif
145.1019 -#  ifndef PNG_NO_WRITE_INVERT
145.1020 -#    define PNG_WRITE_INVERT_SUPPORTED
145.1021 -#  endif
145.1022 -#  ifndef PNG_NO_WRITE_FILLER
145.1023 -#    define PNG_WRITE_FILLER_SUPPORTED   /* same as WRITE_STRIP_ALPHA */
145.1024 -#  endif
145.1025 -#  ifndef PNG_NO_WRITE_SWAP_ALPHA
145.1026 -#    define PNG_WRITE_SWAP_ALPHA_SUPPORTED
145.1027 -#  endif
145.1028 -#  ifndef PNG_NO_WRITE_INVERT_ALPHA
145.1029 -#    define PNG_WRITE_INVERT_ALPHA_SUPPORTED
145.1030 -#  endif
145.1031 -#  ifndef PNG_NO_WRITE_USER_TRANSFORM
145.1032 -#    define PNG_WRITE_USER_TRANSFORM_SUPPORTED
145.1033 -#  endif
145.1034 -#endif /* PNG_WRITE_TRANSFORMS_SUPPORTED */
145.1035 -
145.1036 -#if !defined(PNG_NO_WRITE_INTERLACING_SUPPORTED) && \
145.1037 -    !defined(PNG_WRITE_INTERLACING_SUPPORTED)
145.1038 -#define PNG_WRITE_INTERLACING_SUPPORTED  /* not required for PNG-compliant
145.1039 -                                            encoders, but can cause trouble
145.1040 -                                            if left undefined */
145.1041 -#endif
145.1042 -
145.1043 -#if !defined(PNG_NO_WRITE_WEIGHTED_FILTER) && \
145.1044 -    !defined(PNG_WRITE_WEIGHTED_FILTER) && \
145.1045 -     defined(PNG_FLOATING_POINT_SUPPORTED)
145.1046 -#  define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
145.1047 -#endif
145.1048 -
145.1049 -#ifndef PNG_NO_WRITE_FLUSH
145.1050 -#  define PNG_WRITE_FLUSH_SUPPORTED
145.1051 -#endif
145.1052 -
145.1053 -#if defined(PNG_1_0_X) || defined (PNG_1_2_X)
145.1054 -/* Deprecated, see PNG_MNG_FEATURES_SUPPORTED, above */
145.1055 -#ifndef PNG_NO_WRITE_EMPTY_PLTE
145.1056 -#  define PNG_WRITE_EMPTY_PLTE_SUPPORTED
145.1057 -#endif
145.1058 -#endif
145.1059 -
145.1060 -#endif /* PNG_WRITE_SUPPORTED */
145.1061 -
145.1062 -#ifndef PNG_1_0_X
145.1063 -#  ifndef PNG_NO_ERROR_NUMBERS
145.1064 -#    define PNG_ERROR_NUMBERS_SUPPORTED
145.1065 -#  endif
145.1066 -#endif /* PNG_1_0_X */
145.1067 -
145.1068 -#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
145.1069 -    defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
145.1070 -#  ifndef PNG_NO_USER_TRANSFORM_PTR
145.1071 -#    define PNG_USER_TRANSFORM_PTR_SUPPORTED
145.1072 -#  endif
145.1073 -#endif
145.1074 -
145.1075 -#ifndef PNG_NO_STDIO
145.1076 -#  define PNG_TIME_RFC1123_SUPPORTED
145.1077 -#endif
145.1078 -
145.1079 -/* This adds extra functions in pngget.c for accessing data from the
145.1080 - * info pointer (added in version 0.99)
145.1081 - * png_get_image_width()
145.1082 - * png_get_image_height()
145.1083 - * png_get_bit_depth()
145.1084 - * png_get_color_type()
145.1085 - * png_get_compression_type()
145.1086 - * png_get_filter_type()
145.1087 - * png_get_interlace_type()
145.1088 - * png_get_pixel_aspect_ratio()
145.1089 - * png_get_pixels_per_meter()
145.1090 - * png_get_x_offset_pixels()
145.1091 - * png_get_y_offset_pixels()
145.1092 - * png_get_x_offset_microns()
145.1093 - * png_get_y_offset_microns()
145.1094 - */
145.1095 -#if !defined(PNG_NO_EASY_ACCESS) && !defined(PNG_EASY_ACCESS_SUPPORTED)
145.1096 -#  define PNG_EASY_ACCESS_SUPPORTED
145.1097 -#endif
145.1098 -
145.1099 -/* PNG_ASSEMBLER_CODE was enabled by default in version 1.2.0
145.1100 - * even when PNG_USE_PNGVCRD or PNG_USE_PNGGCCRD is not defined.
145.1101 - *
145.1102 - * PNG_NO_ASSEMBLER_CODE disables use of all assembler code and optimized C,
145.1103 - * and removes or includes several functions in the API.
145.1104 - *
145.1105 - * PNG_NO_MMX_CODE disables the use of MMX code without changing the API.
145.1106 - * When MMX code is off, then optimized C replacement functions are used.
145.1107 -*/
145.1108 -#if defined(PNG_READ_SUPPORTED) && !defined(PNG_NO_ASSEMBLER_CODE)
145.1109 -#  ifndef PNG_ASSEMBLER_CODE_SUPPORTED
145.1110 -#    define PNG_ASSEMBLER_CODE_SUPPORTED
145.1111 -#  endif
145.1112 -#  if defined(XP_MACOSX) && !defined(PNG_NO_MMX_CODE)
145.1113 -     /* work around Intel-Mac compiler bug */
145.1114 -#    define PNG_NO_MMX_CODE
145.1115 -#  endif
145.1116 -#  if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE) && \
145.1117 -     defined(__MMX__)
145.1118 -#    define PNG_MMX_CODE_SUPPORTED
145.1119 -#  endif
145.1120 -#  if !defined(PNG_USE_PNGGCCRD) && !defined(PNG_NO_MMX_CODE) && \
145.1121 -     !defined(PNG_USE_PNGVCRD) && defined(__MMX__)
145.1122 -#    define PNG_USE_PNGGCCRD
145.1123 -#  endif
145.1124 -#endif
145.1125 -
145.1126 -/* If you are sure that you don't need thread safety and you are compiling
145.1127 -   with PNG_USE_PNGCCRD for an MMX application, you can define this for
145.1128 -   faster execution.  See pnggccrd.c.
145.1129 -#define PNG_THREAD_UNSAFE_OK
145.1130 -*/
145.1131 -
145.1132 -#if !defined(PNG_1_0_X)
145.1133 -#if !defined(PNG_NO_USER_MEM) && !defined(PNG_USER_MEM_SUPPORTED)
145.1134 -#  define PNG_USER_MEM_SUPPORTED
145.1135 -#endif
145.1136 -#endif /* PNG_1_0_X */
145.1137 -
145.1138 -/* Added at libpng-1.2.6 */
145.1139 -#if !defined(PNG_1_0_X)
145.1140 -#ifndef PNG_SET_USER_LIMITS_SUPPORTED
145.1141 -#if !defined(PNG_NO_SET_USER_LIMITS) && !defined(PNG_SET_USER_LIMITS_SUPPORTED)
145.1142 -#  define PNG_SET_USER_LIMITS_SUPPORTED
145.1143 -#endif
145.1144 -#endif
145.1145 -#endif /* PNG_1_0_X */
145.1146 -
145.1147 -/* Added at libpng-1.0.16 and 1.2.6.  To accept all valid PNGS no matter
145.1148 - * how large, set these limits to 0x7fffffffL
145.1149 - */
145.1150 -#ifndef PNG_USER_WIDTH_MAX
145.1151 -#  define PNG_USER_WIDTH_MAX 1000000L
145.1152 -#endif
145.1153 -#ifndef PNG_USER_HEIGHT_MAX
145.1154 -#  define PNG_USER_HEIGHT_MAX 1000000L
145.1155 -#endif
145.1156 -
145.1157 -/* These are currently experimental features, define them if you want */
145.1158 -
145.1159 -/* very little testing */
145.1160 -/*
145.1161 -#ifdef PNG_READ_SUPPORTED
145.1162 -#  ifndef PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED
145.1163 -#    define PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED
145.1164 -#  endif
145.1165 -#endif
145.1166 -*/
145.1167 -
145.1168 -/* This is only for PowerPC big-endian and 680x0 systems */
145.1169 -/* some testing */
145.1170 -/*
145.1171 -#ifndef PNG_READ_BIG_ENDIAN_SUPPORTED
145.1172 -#  define PNG_READ_BIG_ENDIAN_SUPPORTED
145.1173 -#endif
145.1174 -*/
145.1175 -
145.1176 -/* Buggy compilers (e.g., gcc 2.7.2.2) need this */
145.1177 -/*
145.1178 -#define PNG_NO_POINTER_INDEXING
145.1179 -*/
145.1180 -
145.1181 -/* These functions are turned off by default, as they will be phased out. */
145.1182 -/*
145.1183 -#define  PNG_USELESS_TESTS_SUPPORTED
145.1184 -#define  PNG_CORRECT_PALETTE_SUPPORTED
145.1185 -*/
145.1186 -
145.1187 -/* Any chunks you are not interested in, you can undef here.  The
145.1188 - * ones that allocate memory may be expecially important (hIST,
145.1189 - * tEXt, zTXt, tRNS, pCAL).  Others will just save time and make png_info
145.1190 - * a bit smaller.
145.1191 - */
145.1192 -
145.1193 -#if defined(PNG_READ_SUPPORTED) && \
145.1194 -    !defined(PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \
145.1195 -    !defined(PNG_NO_READ_ANCILLARY_CHUNKS)
145.1196 -#  define PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
145.1197 -#endif
145.1198 -
145.1199 -#if defined(PNG_WRITE_SUPPORTED) && \
145.1200 -    !defined(PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \
145.1201 -    !defined(PNG_NO_WRITE_ANCILLARY_CHUNKS)
145.1202 -#  define PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
145.1203 -#endif
145.1204 -
145.1205 -#ifdef PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
145.1206 -
145.1207 -#ifdef PNG_NO_READ_TEXT
145.1208 -#  define PNG_NO_READ_iTXt
145.1209 -#  define PNG_NO_READ_tEXt
145.1210 -#  define PNG_NO_READ_zTXt
145.1211 -#endif
145.1212 -#ifndef PNG_NO_READ_bKGD
145.1213 -#  define PNG_READ_bKGD_SUPPORTED
145.1214 -#  define PNG_bKGD_SUPPORTED
145.1215 -#endif
145.1216 -#ifndef PNG_NO_READ_cHRM
145.1217 -#  define PNG_READ_cHRM_SUPPORTED
145.1218 -#  define PNG_cHRM_SUPPORTED
145.1219 -#endif
145.1220 -#ifndef PNG_NO_READ_gAMA
145.1221 -#  define PNG_READ_gAMA_SUPPORTED
145.1222 -#  define PNG_gAMA_SUPPORTED
145.1223 -#endif
145.1224 -#ifndef PNG_NO_READ_hIST
145.1225 -#  define PNG_READ_hIST_SUPPORTED
145.1226 -#  define PNG_hIST_SUPPORTED
145.1227 -#endif
145.1228 -#ifndef PNG_NO_READ_iCCP
145.1229 -#  define PNG_READ_iCCP_SUPPORTED
145.1230 -#  define PNG_iCCP_SUPPORTED
145.1231 -#endif
145.1232 -#ifndef PNG_NO_READ_iTXt
145.1233 -#  ifndef PNG_READ_iTXt_SUPPORTED
145.1234 -#    define PNG_READ_iTXt_SUPPORTED
145.1235 -#  endif
145.1236 -#  ifndef PNG_iTXt_SUPPORTED
145.1237 -#    define PNG_iTXt_SUPPORTED
145.1238 -#  endif
145.1239 -#endif
145.1240 -#ifndef PNG_NO_READ_oFFs
145.1241 -#  define PNG_READ_oFFs_SUPPORTED
145.1242 -#  define PNG_oFFs_SUPPORTED
145.1243 -#endif
145.1244 -#ifndef PNG_NO_READ_pCAL
145.1245 -#  define PNG_READ_pCAL_SUPPORTED
145.1246 -#  define PNG_pCAL_SUPPORTED
145.1247 -#endif
145.1248 -#ifndef PNG_NO_READ_sCAL
145.1249 -#  define PNG_READ_sCAL_SUPPORTED
145.1250 -#  define PNG_sCAL_SUPPORTED
145.1251 -#endif
145.1252 -#ifndef PNG_NO_READ_pHYs
145.1253 -#  define PNG_READ_pHYs_SUPPORTED
145.1254 -#  define PNG_pHYs_SUPPORTED
145.1255 -#endif
145.1256 -#ifndef PNG_NO_READ_sBIT
145.1257 -#  define PNG_READ_sBIT_SUPPORTED
145.1258 -#  define PNG_sBIT_SUPPORTED
145.1259 -#endif
145.1260 -#ifndef PNG_NO_READ_sPLT
145.1261 -#  define PNG_READ_sPLT_SUPPORTED
145.1262 -#  define PNG_sPLT_SUPPORTED
145.1263 -#endif
145.1264 -#ifndef PNG_NO_READ_sRGB
145.1265 -#  define PNG_READ_sRGB_SUPPORTED
145.1266 -#  define PNG_sRGB_SUPPORTED
145.1267 -#endif
145.1268 -#ifndef PNG_NO_READ_tEXt
145.1269 -#  define PNG_READ_tEXt_SUPPORTED
145.1270 -#  define PNG_tEXt_SUPPORTED
145.1271 -#endif
145.1272 -#ifndef PNG_NO_READ_tIME
145.1273 -#  define PNG_READ_tIME_SUPPORTED
145.1274 -#  define PNG_tIME_SUPPORTED
145.1275 -#endif
145.1276 -#ifndef PNG_NO_READ_tRNS
145.1277 -#  define PNG_READ_tRNS_SUPPORTED
145.1278 -#  define PNG_tRNS_SUPPORTED
145.1279 -#endif
145.1280 -#ifndef PNG_NO_READ_zTXt
145.1281 -#  define PNG_READ_zTXt_SUPPORTED
145.1282 -#  define PNG_zTXt_SUPPORTED
145.1283 -#endif
145.1284 -#ifndef PNG_NO_READ_UNKNOWN_CHUNKS
145.1285 -#  define PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
145.1286 -#  ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED
145.1287 -#    define PNG_UNKNOWN_CHUNKS_SUPPORTED
145.1288 -#  endif
145.1289 -#  ifndef PNG_NO_HANDLE_AS_UNKNOWN
145.1290 -#    define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
145.1291 -#  endif
145.1292 -#endif
145.1293 -#if !defined(PNG_NO_READ_USER_CHUNKS) && \
145.1294 -     defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
145.1295 -#  define PNG_READ_USER_CHUNKS_SUPPORTED
145.1296 -#  define PNG_USER_CHUNKS_SUPPORTED
145.1297 -#  ifdef PNG_NO_READ_UNKNOWN_CHUNKS
145.1298 -#    undef PNG_NO_READ_UNKNOWN_CHUNKS
145.1299 -#  endif
145.1300 -#  ifdef PNG_NO_HANDLE_AS_UNKNOWN
145.1301 -#    undef PNG_NO_HANDLE_AS_UNKNOWN
145.1302 -#  endif
145.1303 -#endif
145.1304 -#ifndef PNG_NO_READ_OPT_PLTE
145.1305 -#  define PNG_READ_OPT_PLTE_SUPPORTED /* only affects support of the */
145.1306 -#endif                      /* optional PLTE chunk in RGB and RGBA images */
145.1307 -#if defined(PNG_READ_iTXt_SUPPORTED) || defined(PNG_READ_tEXt_SUPPORTED) || \
145.1308 -    defined(PNG_READ_zTXt_SUPPORTED)
145.1309 -#  define PNG_READ_TEXT_SUPPORTED
145.1310 -#  define PNG_TEXT_SUPPORTED
145.1311 -#endif
145.1312 -
145.1313 -#endif /* PNG_READ_ANCILLARY_CHUNKS_SUPPORTED */
145.1314 -
145.1315 -#ifdef PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
145.1316 -
145.1317 -#ifdef PNG_NO_WRITE_TEXT
145.1318 -#  define PNG_NO_WRITE_iTXt
145.1319 -#  define PNG_NO_WRITE_tEXt
145.1320 -#  define PNG_NO_WRITE_zTXt
145.1321 -#endif
145.1322 -#ifndef PNG_NO_WRITE_bKGD
145.1323 -#  define PNG_WRITE_bKGD_SUPPORTED
145.1324 -#  ifndef PNG_bKGD_SUPPORTED
145.1325 -#    define PNG_bKGD_SUPPORTED
145.1326 -#  endif
145.1327 -#endif
145.1328 -#ifndef PNG_NO_WRITE_cHRM
145.1329 -#  define PNG_WRITE_cHRM_SUPPORTED
145.1330 -#  ifndef PNG_cHRM_SUPPORTED
145.1331 -#    define PNG_cHRM_SUPPORTED
145.1332 -#  endif
145.1333 -#endif
145.1334 -#ifndef PNG_NO_WRITE_gAMA
145.1335 -#  define PNG_WRITE_gAMA_SUPPORTED
145.1336 -#  ifndef PNG_gAMA_SUPPORTED
145.1337 -#    define PNG_gAMA_SUPPORTED
145.1338 -#  endif
145.1339 -#endif
145.1340 -#ifndef PNG_NO_WRITE_hIST
145.1341 -#  define PNG_WRITE_hIST_SUPPORTED
145.1342 -#  ifndef PNG_hIST_SUPPORTED
145.1343 -#    define PNG_hIST_SUPPORTED
145.1344 -#  endif
145.1345 -#endif
145.1346 -#ifndef PNG_NO_WRITE_iCCP
145.1347 -#  define PNG_WRITE_iCCP_SUPPORTED
145.1348 -#  ifndef PNG_iCCP_SUPPORTED
145.1349 -#    define PNG_iCCP_SUPPORTED
145.1350 -#  endif
145.1351 -#endif
145.1352 -#ifndef PNG_NO_WRITE_iTXt
145.1353 -#  ifndef PNG_WRITE_iTXt_SUPPORTED
145.1354 -#    define PNG_WRITE_iTXt_SUPPORTED
145.1355 -#  endif
145.1356 -#  ifndef PNG_iTXt_SUPPORTED
145.1357 -#    define PNG_iTXt_SUPPORTED
145.1358 -#  endif
145.1359 -#endif
145.1360 -#ifndef PNG_NO_WRITE_oFFs
145.1361 -#  define PNG_WRITE_oFFs_SUPPORTED
145.1362 -#  ifndef PNG_oFFs_SUPPORTED
145.1363 -#    define PNG_oFFs_SUPPORTED
145.1364 -#  endif
145.1365 -#endif
145.1366 -#ifndef PNG_NO_WRITE_pCAL
145.1367 -#  define PNG_WRITE_pCAL_SUPPORTED
145.1368 -#  ifndef PNG_pCAL_SUPPORTED
145.1369 -#    define PNG_pCAL_SUPPORTED
145.1370 -#  endif
145.1371 -#endif
145.1372 -#ifndef PNG_NO_WRITE_sCAL
145.1373 -#  define PNG_WRITE_sCAL_SUPPORTED
145.1374 -#  ifndef PNG_sCAL_SUPPORTED
145.1375 -#    define PNG_sCAL_SUPPORTED
145.1376 -#  endif
145.1377 -#endif
145.1378 -#ifndef PNG_NO_WRITE_pHYs
145.1379 -#  define PNG_WRITE_pHYs_SUPPORTED
145.1380 -#  ifndef PNG_pHYs_SUPPORTED
145.1381 -#    define PNG_pHYs_SUPPORTED
145.1382 -#  endif
145.1383 -#endif
145.1384 -#ifndef PNG_NO_WRITE_sBIT
145.1385 -#  define PNG_WRITE_sBIT_SUPPORTED
145.1386 -#  ifndef PNG_sBIT_SUPPORTED
145.1387 -#    define PNG_sBIT_SUPPORTED
145.1388 -#  endif
145.1389 -#endif
145.1390 -#ifndef PNG_NO_WRITE_sPLT
145.1391 -#  define PNG_WRITE_sPLT_SUPPORTED
145.1392 -#  ifndef PNG_sPLT_SUPPORTED
145.1393 -#    define PNG_sPLT_SUPPORTED
145.1394 -#  endif
145.1395 -#endif
145.1396 -#ifndef PNG_NO_WRITE_sRGB
145.1397 -#  define PNG_WRITE_sRGB_SUPPORTED
145.1398 -#  ifndef PNG_sRGB_SUPPORTED
145.1399 -#    define PNG_sRGB_SUPPORTED
145.1400 -#  endif
145.1401 -#endif
145.1402 -#ifndef PNG_NO_WRITE_tEXt
145.1403 -#  define PNG_WRITE_tEXt_SUPPORTED
145.1404 -#  ifndef PNG_tEXt_SUPPORTED
145.1405 -#    define PNG_tEXt_SUPPORTED
145.1406 -#  endif
145.1407 -#endif
145.1408 -#ifndef PNG_NO_WRITE_tIME
145.1409 -#  define PNG_WRITE_tIME_SUPPORTED
145.1410 -#  ifndef PNG_tIME_SUPPORTED
145.1411 -#    define PNG_tIME_SUPPORTED
145.1412 -#  endif
145.1413 -#endif
145.1414 -#ifndef PNG_NO_WRITE_tRNS
145.1415 -#  define PNG_WRITE_tRNS_SUPPORTED
145.1416 -#  ifndef PNG_tRNS_SUPPORTED
145.1417 -#    define PNG_tRNS_SUPPORTED
145.1418 -#  endif
145.1419 -#endif
145.1420 -#ifndef PNG_NO_WRITE_zTXt
145.1421 -#  define PNG_WRITE_zTXt_SUPPORTED
145.1422 -#  ifndef PNG_zTXt_SUPPORTED
145.1423 -#    define PNG_zTXt_SUPPORTED
145.1424 -#  endif
145.1425 -#endif
145.1426 -#ifndef PNG_NO_WRITE_UNKNOWN_CHUNKS
145.1427 -#  define PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
145.1428 -#  ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED
145.1429 -#    define PNG_UNKNOWN_CHUNKS_SUPPORTED
145.1430 -#  endif
145.1431 -#  ifndef PNG_NO_HANDLE_AS_UNKNOWN
145.1432 -#     ifndef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
145.1433 -#       define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
145.1434 -#     endif
145.1435 -#  endif
145.1436 -#endif
145.1437 -#if defined(PNG_WRITE_iTXt_SUPPORTED) || defined(PNG_WRITE_tEXt_SUPPORTED) || \
145.1438 -    defined(PNG_WRITE_zTXt_SUPPORTED)
145.1439 -#  define PNG_WRITE_TEXT_SUPPORTED
145.1440 -#  ifndef PNG_TEXT_SUPPORTED
145.1441 -#    define PNG_TEXT_SUPPORTED
145.1442 -#  endif
145.1443 -#endif
145.1444 -
145.1445 -#endif /* PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED */
145.1446 -
145.1447 -/* Turn this off to disable png_read_png() and
145.1448 - * png_write_png() and leave the row_pointers member
145.1449 - * out of the info structure.
145.1450 - */
145.1451 -#ifndef PNG_NO_INFO_IMAGE
145.1452 -#  define PNG_INFO_IMAGE_SUPPORTED
145.1453 -#endif
145.1454 -
145.1455 -/* need the time information for reading tIME chunks */
145.1456 -#if defined(PNG_tIME_SUPPORTED)
145.1457 -#  if !defined(_WIN32_WCE)
145.1458 -     /* "time.h" functions are not supported on WindowsCE */
145.1459 -#    include <time.h>
145.1460 +#ifndef PNG_CONST
145.1461 +#  ifndef PNG_NO_CONST
145.1462 +#    define PNG_CONST const
145.1463 +#  else
145.1464 +#    define PNG_CONST
145.1465  #  endif
145.1466  #endif
145.1467  
145.1468 @@ -1117,28 +485,29 @@
145.1469   * numbers suggest (a png_uint_32 must be at least 32 bits long), but they
145.1470   * don't have to be exactly that size.  Some compilers dislike passing
145.1471   * unsigned shorts as function parameters, so you may be better off using
145.1472 - * unsigned int for png_uint_16.  Likewise, for 64-bit systems, you may
145.1473 - * want to have unsigned int for png_uint_32 instead of unsigned long.
145.1474 + * unsigned int for png_uint_16.
145.1475   */
145.1476  
145.1477 +#if defined(INT_MAX) && (INT_MAX > 0x7ffffffeL)
145.1478 +typedef unsigned int png_uint_32;
145.1479 +typedef int png_int_32;
145.1480 +#else
145.1481  typedef unsigned long png_uint_32;
145.1482  typedef long png_int_32;
145.1483 +#endif
145.1484  typedef unsigned short png_uint_16;
145.1485  typedef short png_int_16;
145.1486  typedef unsigned char png_byte;
145.1487  
145.1488 -/* This is usually size_t.  It is typedef'ed just in case you need it to
145.1489 -   change (I'm not sure if you will or not, so I thought I'd be safe) */
145.1490 -#ifdef PNG_SIZE_T
145.1491 -   typedef PNG_SIZE_T png_size_t;
145.1492 -#  define png_sizeof(x) png_convert_size(sizeof (x))
145.1493 +#ifdef PNG_NO_SIZE_T
145.1494 +typedef unsigned int png_size_t;
145.1495  #else
145.1496 -   typedef size_t png_size_t;
145.1497 -#  define png_sizeof(x) sizeof (x)
145.1498 +typedef size_t png_size_t;
145.1499  #endif
145.1500 +#define png_sizeof(x) (sizeof (x))
145.1501  
145.1502  /* The following is needed for medium model support.  It cannot be in the
145.1503 - * PNG_INTERNAL section.  Needs modification for other compilers besides
145.1504 + * pngpriv.h header.  Needs modification for other compilers besides
145.1505   * MSC.  Model independent support declares all arrays and pointers to be
145.1506   * large using the far keyword.  The zlib version used must also support
145.1507   * model independent data.  As of version zlib 1.0.4, the necessary changes
145.1508 @@ -1147,27 +516,28 @@
145.1509   */
145.1510  
145.1511  /* Separate compiler dependencies (problem here is that zlib.h always
145.1512 -   defines FAR. (SJT) */
145.1513 + * defines FAR. (SJT)
145.1514 + */
145.1515  #ifdef __BORLANDC__
145.1516  #  if defined(__LARGE__) || defined(__HUGE__) || defined(__COMPACT__)
145.1517  #    define LDATA 1
145.1518  #  else
145.1519  #    define LDATA 0
145.1520  #  endif
145.1521 -   /* GRR:  why is Cygwin in here?  Cygwin is not Borland C... */
145.1522 +  /* GRR:  why is Cygwin in here?  Cygwin is not Borland C... */
145.1523  #  if !defined(__WIN32__) && !defined(__FLAT__) && !defined(__CYGWIN__)
145.1524 -#    define PNG_MAX_MALLOC_64K
145.1525 +#    define PNG_MAX_MALLOC_64K /* only used in build */
145.1526  #    if (LDATA != 1)
145.1527  #      ifndef FAR
145.1528  #        define FAR __far
145.1529  #      endif
145.1530  #      define USE_FAR_KEYWORD
145.1531  #    endif   /* LDATA != 1 */
145.1532 -     /* Possibly useful for moving data out of default segment.
145.1533 -      * Uncomment it if you want. Could also define FARDATA as
145.1534 -      * const if your compiler supports it. (SJT)
145.1535 -#    define FARDATA FAR
145.1536 -      */
145.1537 +         /* Possibly useful for moving data out of default segment.
145.1538 +          * Uncomment it if you want. Could also define FARDATA as
145.1539 +          * const if your compiler supports it. (SJT)
145.1540 +#        define FARDATA FAR
145.1541 +          */
145.1542  #  endif  /* __WIN32__, __FLAT__, __CYGWIN__ */
145.1543  #endif   /* __BORLANDC__ */
145.1544  
145.1545 @@ -1178,8 +548,8 @@
145.1546   */
145.1547  
145.1548  /* MSC Medium model */
145.1549 -#if defined(FAR)
145.1550 -#  if defined(M_I86MM)
145.1551 +#ifdef FAR
145.1552 +#  ifdef M_I86MM
145.1553  #    define USE_FAR_KEYWORD
145.1554  #    define FARDATA FAR
145.1555  #    include <dos.h>
145.1556 @@ -1197,30 +567,37 @@
145.1557  #endif
145.1558  
145.1559  /* Typedef for floating-point numbers that are converted
145.1560 -   to fixed-point with a multiple of 100,000, e.g., int_gamma */
145.1561 + * to fixed-point with a multiple of 100,000, e.g., gamma
145.1562 + */
145.1563  typedef png_int_32 png_fixed_point;
145.1564  
145.1565  /* Add typedefs for pointers */
145.1566 -typedef void            FAR * png_voidp;
145.1567 -typedef png_byte        FAR * png_bytep;
145.1568 -typedef png_uint_32     FAR * png_uint_32p;
145.1569 -typedef png_int_32      FAR * png_int_32p;
145.1570 -typedef png_uint_16     FAR * png_uint_16p;
145.1571 -typedef png_int_16      FAR * png_int_16p;
145.1572 -typedef PNG_CONST char  FAR * png_const_charp;
145.1573 -typedef char            FAR * png_charp;
145.1574 -typedef png_fixed_point FAR * png_fixed_point_p;
145.1575 +typedef void                      FAR * png_voidp;
145.1576 +typedef PNG_CONST void            FAR * png_const_voidp;
145.1577 +typedef png_byte                  FAR * png_bytep;
145.1578 +typedef PNG_CONST png_byte        FAR * png_const_bytep;
145.1579 +typedef png_uint_32               FAR * png_uint_32p;
145.1580 +typedef PNG_CONST png_uint_32     FAR * png_const_uint_32p;
145.1581 +typedef png_int_32                FAR * png_int_32p;
145.1582 +typedef PNG_CONST png_int_32      FAR * png_const_int_32p;
145.1583 +typedef png_uint_16               FAR * png_uint_16p;
145.1584 +typedef PNG_CONST png_uint_16     FAR * png_const_uint_16p;
145.1585 +typedef png_int_16                FAR * png_int_16p;
145.1586 +typedef PNG_CONST png_int_16      FAR * png_const_int_16p;
145.1587 +typedef char                      FAR * png_charp;
145.1588 +typedef PNG_CONST char            FAR * png_const_charp;
145.1589 +typedef png_fixed_point           FAR * png_fixed_point_p;
145.1590 +typedef PNG_CONST png_fixed_point FAR * png_const_fixed_point_p;
145.1591 +typedef png_size_t                FAR * png_size_tp;
145.1592 +typedef PNG_CONST png_size_t      FAR * png_const_size_tp;
145.1593  
145.1594 -#ifndef PNG_NO_STDIO
145.1595 -#if defined(_WIN32_WCE)
145.1596 -typedef HANDLE                png_FILE_p;
145.1597 -#else
145.1598 -typedef FILE                * png_FILE_p;
145.1599 -#endif
145.1600 +#ifdef PNG_STDIO_SUPPORTED
145.1601 +typedef FILE            * png_FILE_p;
145.1602  #endif
145.1603  
145.1604  #ifdef PNG_FLOATING_POINT_SUPPORTED
145.1605 -typedef double          FAR * png_doublep;
145.1606 +typedef double           FAR * png_doublep;
145.1607 +typedef PNG_CONST double FAR * png_const_doublep;
145.1608  #endif
145.1609  
145.1610  /* Pointers to pointers; i.e. arrays */
145.1611 @@ -1239,273 +616,32 @@
145.1612  /* Pointers to pointers to pointers; i.e., pointer to array */
145.1613  typedef char            FAR * FAR * FAR * png_charppp;
145.1614  
145.1615 -#if defined(PNG_1_0_X) || defined(PNG_1_2_X)
145.1616 -/* SPC -  Is this stuff deprecated? */
145.1617 -/* It'll be removed as of libpng-1.3.0 - GR-P */
145.1618 -/* libpng typedefs for types in zlib. If zlib changes
145.1619 - * or another compression library is used, then change these.
145.1620 - * Eliminates need to change all the source files.
145.1621 +/* png_alloc_size_t is guaranteed to be no smaller than png_size_t,
145.1622 + * and no smaller than png_uint_32.  Casts from png_size_t or png_uint_32
145.1623 + * to png_alloc_size_t are not necessary; in fact, it is recommended
145.1624 + * not to use them at all so that the compiler can complain when something
145.1625 + * turns out to be problematic.
145.1626 + * Casts in the other direction (from png_alloc_size_t to png_size_t or
145.1627 + * png_uint_32) should be explicitly applied; however, we do not expect
145.1628 + * to encounter practical situations that require such conversions.
145.1629   */
145.1630 -typedef charf *         png_zcharp;
145.1631 -typedef charf * FAR *   png_zcharpp;
145.1632 -typedef z_stream FAR *  png_zstreamp;
145.1633 -#endif /* (PNG_1_0_X) || defined(PNG_1_2_X) */
145.1634 -
145.1635 -/*
145.1636 - * Define PNG_BUILD_DLL if the module being built is a Windows
145.1637 - * LIBPNG DLL.
145.1638 - *
145.1639 - * Define PNG_USE_DLL if you want to *link* to the Windows LIBPNG DLL.
145.1640 - * It is equivalent to Microsoft predefined macro _DLL that is
145.1641 - * automatically defined when you compile using the share
145.1642 - * version of the CRT (C Run-Time library)
145.1643 - *
145.1644 - * The cygwin mods make this behavior a little different:
145.1645 - * Define PNG_BUILD_DLL if you are building a dll for use with cygwin
145.1646 - * Define PNG_STATIC if you are building a static library for use with cygwin,
145.1647 - *   -or- if you are building an application that you want to link to the
145.1648 - *   static library.
145.1649 - * PNG_USE_DLL is defined by default (no user action needed) unless one of
145.1650 - *   the other flags is defined.
145.1651 - */
145.1652 -
145.1653 -#if !defined(PNG_DLL) && (defined(PNG_BUILD_DLL) || defined(PNG_USE_DLL))
145.1654 -#  define PNG_DLL
145.1655 -#endif
145.1656 -/* If CYGWIN, then disallow GLOBAL ARRAYS unless building a static lib.
145.1657 - * When building a static lib, default to no GLOBAL ARRAYS, but allow
145.1658 - * command-line override
145.1659 - */
145.1660 -#if defined(__CYGWIN__)
145.1661 -#  if !defined(PNG_STATIC)
145.1662 -#    if defined(PNG_USE_GLOBAL_ARRAYS)
145.1663 -#      undef PNG_USE_GLOBAL_ARRAYS
145.1664 -#    endif
145.1665 -#    if !defined(PNG_USE_LOCAL_ARRAYS)
145.1666 -#      define PNG_USE_LOCAL_ARRAYS
145.1667 -#    endif
145.1668 +#if defined(__TURBOC__) && !defined(__FLAT__)
145.1669 +   typedef unsigned long png_alloc_size_t;
145.1670 +#else
145.1671 +#  if defined(_MSC_VER) && defined(MAXSEG_64K)
145.1672 +     typedef unsigned long    png_alloc_size_t;
145.1673  #  else
145.1674 -#    if defined(PNG_USE_LOCAL_ARRAYS) || defined(PNG_NO_GLOBAL_ARRAYS)
145.1675 -#      if defined(PNG_USE_GLOBAL_ARRAYS)
145.1676 -#        undef PNG_USE_GLOBAL_ARRAYS
145.1677 -#      endif
145.1678 -#    endif
145.1679 -#  endif
145.1680 -#  if !defined(PNG_USE_LOCAL_ARRAYS) && !defined(PNG_USE_GLOBAL_ARRAYS)
145.1681 -#    define PNG_USE_LOCAL_ARRAYS
145.1682 -#  endif
145.1683 -#endif
145.1684 -
145.1685 -/* Do not use global arrays (helps with building DLL's)
145.1686 - * They are no longer used in libpng itself, since version 1.0.5c,
145.1687 - * but might be required for some pre-1.0.5c applications.
145.1688 - */
145.1689 -#if !defined(PNG_USE_LOCAL_ARRAYS) && !defined(PNG_USE_GLOBAL_ARRAYS)
145.1690 -#  if defined(PNG_NO_GLOBAL_ARRAYS) || (defined(__GNUC__) && defined(PNG_DLL))
145.1691 -#    define PNG_USE_LOCAL_ARRAYS
145.1692 -#  else
145.1693 -#    define PNG_USE_GLOBAL_ARRAYS
145.1694 -#  endif
145.1695 -#endif
145.1696 -
145.1697 -#if defined(__CYGWIN__)
145.1698 -#  undef PNGAPI
145.1699 -#  define PNGAPI __cdecl
145.1700 -#  undef PNG_IMPEXP
145.1701 -#  define PNG_IMPEXP
145.1702 -#endif
145.1703 -
145.1704 -/* If you define PNGAPI, e.g., with compiler option "-DPNGAPI=__stdcall",
145.1705 - * you may get warnings regarding the linkage of png_zalloc and png_zfree.
145.1706 - * Don't ignore those warnings; you must also reset the default calling
145.1707 - * convention in your compiler to match your PNGAPI, and you must build
145.1708 - * zlib and your applications the same way you build libpng.
145.1709 - */
145.1710 -
145.1711 -#if defined(__MINGW32__) && !defined(PNG_MODULEDEF)
145.1712 -#  ifndef PNG_NO_MODULEDEF
145.1713 -#    define PNG_NO_MODULEDEF
145.1714 -#  endif
145.1715 -#endif
145.1716 -
145.1717 -#if !defined(PNG_IMPEXP) && defined(PNG_BUILD_DLL) && !defined(PNG_NO_MODULEDEF)
145.1718 -#  define PNG_IMPEXP
145.1719 -#endif
145.1720 -
145.1721 -#if defined(PNG_DLL) || defined(_DLL) || defined(__DLL__ ) || \
145.1722 -    (( defined(_Windows) || defined(_WINDOWS) || \
145.1723 -       defined(WIN32) || defined(_WIN32) || defined(__WIN32__) ))
145.1724 -
145.1725 -#  ifndef PNGAPI
145.1726 -#     if defined(__GNUC__) || (defined (_MSC_VER) && (_MSC_VER >= 800))
145.1727 -#        define PNGAPI __cdecl
145.1728 -#     else
145.1729 -#        define PNGAPI _cdecl
145.1730 -#     endif
145.1731 -#  endif
145.1732 -
145.1733 -#  if !defined(PNG_IMPEXP) && (!defined(PNG_DLL) || \
145.1734 -       0 /* WINCOMPILER_WITH_NO_SUPPORT_FOR_DECLIMPEXP */)
145.1735 -#     define PNG_IMPEXP
145.1736 -#  endif
145.1737 -
145.1738 -#  if !defined(PNG_IMPEXP)
145.1739 -
145.1740 -#     define PNG_EXPORT_TYPE1(type,symbol)  PNG_IMPEXP type PNGAPI symbol
145.1741 -#     define PNG_EXPORT_TYPE2(type,symbol)  type PNG_IMPEXP PNGAPI symbol
145.1742 -
145.1743 -      /* Borland/Microsoft */
145.1744 -#     if defined(_MSC_VER) || defined(__BORLANDC__)
145.1745 -#        if (_MSC_VER >= 800) || (__BORLANDC__ >= 0x500)
145.1746 -#           define PNG_EXPORT PNG_EXPORT_TYPE1
145.1747 -#        else
145.1748 -#           define PNG_EXPORT PNG_EXPORT_TYPE2
145.1749 -#           if defined(PNG_BUILD_DLL)
145.1750 -#              define PNG_IMPEXP __export
145.1751 -#           else
145.1752 -#              define PNG_IMPEXP /*__import */ /* doesn't exist AFAIK in
145.1753 -                                                 VC++ */
145.1754 -#           endif                             /* Exists in Borland C++ for
145.1755 -                                                 C++ classes (== huge) */
145.1756 -#        endif
145.1757 -#     endif
145.1758 -
145.1759 -#     if !defined(PNG_IMPEXP)
145.1760 -#        if defined(PNG_BUILD_DLL)
145.1761 -#           define PNG_IMPEXP __declspec(dllexport)
145.1762 -#        else
145.1763 -#           define PNG_IMPEXP __declspec(dllimport)
145.1764 -#        endif
145.1765 -#     endif
145.1766 -#  endif  /* PNG_IMPEXP */
145.1767 -#else /* !(DLL || non-cygwin WINDOWS) */
145.1768 -#   if (defined(__IBMC__) || defined(__IBMCPP__)) && defined(__OS2__)
145.1769 -#      ifndef PNGAPI
145.1770 -#         define PNGAPI _System
145.1771 -#      endif
145.1772 -#   else
145.1773 -#      if 0 /* ... other platforms, with other meanings */
145.1774 -#      endif
145.1775 -#   endif
145.1776 -#endif
145.1777 -
145.1778 -#ifndef PNGAPI
145.1779 -#  define PNGAPI
145.1780 -#endif
145.1781 -#ifndef PNG_IMPEXP
145.1782 -#  define PNG_IMPEXP
145.1783 -#endif
145.1784 -
145.1785 -#ifdef PNG_BUILDSYMS
145.1786 -#  ifndef PNG_EXPORT
145.1787 -#    define PNG_EXPORT(type,symbol) PNG_FUNCTION_EXPORT symbol END
145.1788 -#  endif
145.1789 -#  ifdef PNG_USE_GLOBAL_ARRAYS
145.1790 -#    ifndef PNG_EXPORT_VAR
145.1791 -#      define PNG_EXPORT_VAR(type) PNG_DATA_EXPORT
145.1792 +     /* This is an attempt to detect an old Windows system where (int) is
145.1793 +      * actually 16 bits, in that case png_malloc must have an argument with a
145.1794 +      * bigger size to accomodate the requirements of the library.
145.1795 +      */
145.1796 +#    if (defined(_Windows) || defined(_WINDOWS) || defined(_WINDOWS_)) && \
145.1797 +        (!defined(INT_MAX) || INT_MAX <= 0x7ffffffeL)
145.1798 +       typedef DWORD         png_alloc_size_t;
145.1799 +#    else
145.1800 +       typedef png_size_t    png_alloc_size_t;
145.1801  #    endif
145.1802  #  endif
145.1803  #endif
145.1804  
145.1805 -#ifndef PNG_EXPORT
145.1806 -#  define PNG_EXPORT(type,symbol) PNG_IMPEXP type PNGAPI symbol
145.1807 -#endif
145.1808 -
145.1809 -#ifdef PNG_USE_GLOBAL_ARRAYS
145.1810 -#  ifndef PNG_EXPORT_VAR
145.1811 -#    define PNG_EXPORT_VAR(type) extern PNG_IMPEXP type
145.1812 -#  endif
145.1813 -#endif
145.1814 -
145.1815 -/* User may want to use these so they are not in PNG_INTERNAL. Any library
145.1816 - * functions that are passed far data must be model independent.
145.1817 - */
145.1818 -
145.1819 -#ifndef PNG_ABORT
145.1820 -#  define PNG_ABORT() abort()
145.1821 -#endif
145.1822 -
145.1823 -#ifdef PNG_SETJMP_SUPPORTED
145.1824 -#  define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf)
145.1825 -#else
145.1826 -#  define png_jmpbuf(png_ptr) \
145.1827 -   (LIBPNG_WAS_COMPILED_WITH__PNG_SETJMP_NOT_SUPPORTED)
145.1828 -#endif
145.1829 -
145.1830 -#if defined(USE_FAR_KEYWORD)  /* memory model independent fns */
145.1831 -/* use this to make far-to-near assignments */
145.1832 -#  define CHECK   1
145.1833 -#  define NOCHECK 0
145.1834 -#  define CVT_PTR(ptr) (png_far_to_near(png_ptr,ptr,CHECK))
145.1835 -#  define CVT_PTR_NOCHECK(ptr) (png_far_to_near(png_ptr,ptr,NOCHECK))
145.1836 -#  define png_strcpy  _fstrcpy
145.1837 -#  define png_strncpy _fstrncpy   /* Added to v 1.2.6 */
145.1838 -#  define png_strlen  _fstrlen
145.1839 -#  define png_memcmp  _fmemcmp    /* SJT: added */
145.1840 -#  define png_memcpy  _fmemcpy
145.1841 -#  define png_memset  _fmemset
145.1842 -#else /* use the usual functions */
145.1843 -#  define CVT_PTR(ptr)         (ptr)
145.1844 -#  define CVT_PTR_NOCHECK(ptr) (ptr)
145.1845 -#  define png_strcpy  strcpy
145.1846 -#  define png_strncpy strncpy     /* Added to v 1.2.6 */
145.1847 -#  define png_strlen  strlen
145.1848 -#  define png_memcmp  memcmp      /* SJT: added */
145.1849 -#  define png_memcpy  memcpy
145.1850 -#  define png_memset  memset
145.1851 -#endif
145.1852 -/* End of memory model independent support */
145.1853 -
145.1854 -/* Just a little check that someone hasn't tried to define something
145.1855 - * contradictory.
145.1856 - */
145.1857 -#if (PNG_ZBUF_SIZE > 65536L) && defined(PNG_MAX_MALLOC_64K)
145.1858 -#  undef PNG_ZBUF_SIZE
145.1859 -#  define PNG_ZBUF_SIZE 65536L
145.1860 -#endif
145.1861 -
145.1862 -#ifdef PNG_READ_SUPPORTED
145.1863 -/* Prior to libpng-1.0.9, this block was in pngasmrd.h */
145.1864 -#if defined(PNG_INTERNAL)
145.1865 -
145.1866 -/* These are the default thresholds before the MMX code kicks in; if either
145.1867 - * rowbytes or bitdepth is below the threshold, plain C code is used.  These
145.1868 - * can be overridden at runtime via the png_set_mmx_thresholds() call in
145.1869 - * libpng 1.2.0 and later.  The values below were chosen by Intel.
145.1870 - */
145.1871 -
145.1872 -#ifndef PNG_MMX_ROWBYTES_THRESHOLD_DEFAULT
145.1873 -#  define PNG_MMX_ROWBYTES_THRESHOLD_DEFAULT  128  /*  >=  */
145.1874 -#endif
145.1875 -#ifndef PNG_MMX_BITDEPTH_THRESHOLD_DEFAULT
145.1876 -#  define PNG_MMX_BITDEPTH_THRESHOLD_DEFAULT  9    /*  >=  */
145.1877 -#endif
145.1878 -
145.1879 -/* Set this in the makefile for VC++ on Pentium, not here. */
145.1880 -/* Platform must be Pentium.  Makefile must assemble and load pngvcrd.c .
145.1881 - * MMX will be detected at run time and used if present.
145.1882 - */
145.1883 -#ifdef PNG_USE_PNGVCRD
145.1884 -#  define PNG_HAVE_MMX_COMBINE_ROW
145.1885 -#  define PNG_HAVE_MMX_READ_INTERLACE
145.1886 -#  define PNG_HAVE_MMX_READ_FILTER_ROW
145.1887 -#endif
145.1888 -
145.1889 -/* Set this in the makefile for gcc/as on Pentium, not here. */
145.1890 -/* Platform must be Pentium.  Makefile must assemble and load pnggccrd.c .
145.1891 - * MMX will be detected at run time and used if present.
145.1892 - */
145.1893 -#ifdef PNG_USE_PNGGCCRD
145.1894 -#  define PNG_HAVE_MMX_COMBINE_ROW
145.1895 -#  define PNG_HAVE_MMX_READ_INTERLACE
145.1896 -#  define PNG_HAVE_MMX_READ_FILTER_ROW
145.1897 -#endif
145.1898 -/* - see pnggccrd.c for info about what is currently enabled */
145.1899 -
145.1900 -#endif /* PNG_INTERNAL */
145.1901 -#endif /* PNG_READ_SUPPORTED */
145.1902 -
145.1903 -/* Added at libpng-1.2.8 */
145.1904 -#endif /* PNG_VERSION_INFO_ONLY */
145.1905 -
145.1906  #endif /* PNGCONF_H */
   146.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   146.2 +++ b/src/share/native/sun/awt/libpng/pngdebug.h	Tue Oct 04 12:39:42 2011 -0700
   146.3 @@ -0,0 +1,185 @@
   146.4 +/*
   146.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   146.6 + *
   146.7 + * This code is free software; you can redistribute it and/or modify it
   146.8 + * under the terms of the GNU General Public License version 2 only, as
   146.9 + * published by the Free Software Foundation.  Oracle designates this
  146.10 + * particular file as subject to the "Classpath" exception as provided
  146.11 + * by Oracle in the LICENSE file that accompanied this code.
  146.12 + *
  146.13 + * This code is distributed in the hope that it will be useful, but WITHOUT
  146.14 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  146.15 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  146.16 + * version 2 for more details (a copy is included in the LICENSE file that
  146.17 + * accompanied this code).
  146.18 + *
  146.19 + * You should have received a copy of the GNU General Public License version
  146.20 + * 2 along with this work; if not, write to the Free Software Foundation,
  146.21 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  146.22 + *
  146.23 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  146.24 + * or visit www.oracle.com if you need additional information or have any
  146.25 + * questions.
  146.26 + */
  146.27 +
  146.28 +/* pngdebug.h - Debugging macros for libpng, also used in pngtest.c
  146.29 + *
  146.30 + * This file is available under and governed by the GNU General Public
  146.31 + * License version 2 only, as published by the Free Software Foundation.
  146.32 + * However, the following notice accompanied the original version of this
  146.33 + * file and, per its terms, should not be removed:
  146.34 + *
  146.35 + * Copyright (c) 1998-2011 Glenn Randers-Pehrson
  146.36 + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
  146.37 + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
  146.38 + *
  146.39 + * Last changed in libpng 1.5.0 [January 6, 2011]
  146.40 + *
  146.41 + * This code is released under the libpng license.
  146.42 + * For conditions of distribution and use, see the disclaimer
  146.43 + * and license in png.h
  146.44 + */
  146.45 +
  146.46 +/* Define PNG_DEBUG at compile time for debugging information.  Higher
  146.47 + * numbers for PNG_DEBUG mean more debugging information.  This has
  146.48 + * only been added since version 0.95 so it is not implemented throughout
  146.49 + * libpng yet, but more support will be added as needed.
  146.50 + *
  146.51 + * png_debug[1-2]?(level, message ,arg{0-2})
  146.52 + *   Expands to a statement (either a simple expression or a compound
  146.53 + *   do..while(0) statement) that outputs a message with parameter
  146.54 + *   substitution if PNG_DEBUG is defined to 2 or more.  If PNG_DEBUG
  146.55 + *   is undefined, 0 or 1 every png_debug expands to a simple expression
  146.56 + *   (actually ((void)0)).
  146.57 + *
  146.58 + *   level: level of detail of message, starting at 0.  A level 'n'
  146.59 + *          message is preceded by 'n' tab characters (not implemented
  146.60 + *          on Microsoft compilers unless PNG_DEBUG_FILE is also
  146.61 + *          defined, to allow debug DLL compilation with no standard IO).
  146.62 + *   message: a printf(3) style text string.  A trailing '\n' is added
  146.63 + *            to the message.
  146.64 + *   arg: 0 to 2 arguments for printf(3) style substitution in message.
  146.65 + */
  146.66 +#ifndef PNGDEBUG_H
  146.67 +#define PNGDEBUG_H
  146.68 +/* These settings control the formatting of messages in png.c and pngerror.c */
  146.69 +/* Moved to pngdebug.h at 1.5.0 */
  146.70 +#  ifndef PNG_LITERAL_SHARP
  146.71 +#    define PNG_LITERAL_SHARP 0x23
  146.72 +#  endif
  146.73 +#  ifndef PNG_LITERAL_LEFT_SQUARE_BRACKET
  146.74 +#    define PNG_LITERAL_LEFT_SQUARE_BRACKET 0x5b
  146.75 +#  endif
  146.76 +#  ifndef PNG_LITERAL_RIGHT_SQUARE_BRACKET
  146.77 +#    define PNG_LITERAL_RIGHT_SQUARE_BRACKET 0x5d
  146.78 +#  endif
  146.79 +#  ifndef PNG_STRING_NEWLINE
  146.80 +#    define PNG_STRING_NEWLINE "\n"
  146.81 +#  endif
  146.82 +
  146.83 +#ifdef PNG_DEBUG
  146.84 +#  if (PNG_DEBUG > 0)
  146.85 +#    if !defined(PNG_DEBUG_FILE) && defined(_MSC_VER)
  146.86 +#      include <crtdbg.h>
  146.87 +#      if (PNG_DEBUG > 1)
  146.88 +#        ifndef _DEBUG
  146.89 +#          define _DEBUG
  146.90 +#        endif
  146.91 +#        ifndef png_debug
  146.92 +#          define png_debug(l,m)  _RPT0(_CRT_WARN,m PNG_STRING_NEWLINE)
  146.93 +#        endif
  146.94 +#        ifndef png_debug1
  146.95 +#          define png_debug1(l,m,p1)  _RPT1(_CRT_WARN,m PNG_STRING_NEWLINE,p1)
  146.96 +#        endif
  146.97 +#        ifndef png_debug2
  146.98 +#          define png_debug2(l,m,p1,p2) \
  146.99 +             _RPT2(_CRT_WARN,m PNG_STRING_NEWLINE,p1,p2)
 146.100 +#        endif
 146.101 +#      endif
 146.102 +#    else /* PNG_DEBUG_FILE || !_MSC_VER */
 146.103 +#      ifndef PNG_STDIO_SUPPORTED
 146.104 +#        include <stdio.h> /* not included yet */
 146.105 +#      endif
 146.106 +#      ifndef PNG_DEBUG_FILE
 146.107 +#        define PNG_DEBUG_FILE stderr
 146.108 +#      endif /* PNG_DEBUG_FILE */
 146.109 +
 146.110 +#      if (PNG_DEBUG > 1)
 146.111 +/* Note: ["%s"m PNG_STRING_NEWLINE] probably does not work on
 146.112 + * non-ISO compilers
 146.113 + */
 146.114 +#        ifdef __STDC__
 146.115 +#          ifndef png_debug
 146.116 +#            define png_debug(l,m) \
 146.117 +       do { \
 146.118 +       int num_tabs=l; \
 146.119 +       fprintf(PNG_DEBUG_FILE,"%s"m PNG_STRING_NEWLINE,(num_tabs==1 ? "\t" : \
 146.120 +         (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":"")))); \
 146.121 +       } while (0)
 146.122 +#          endif
 146.123 +#          ifndef png_debug1
 146.124 +#            define png_debug1(l,m,p1) \
 146.125 +       do { \
 146.126 +       int num_tabs=l; \
 146.127 +       fprintf(PNG_DEBUG_FILE,"%s"m PNG_STRING_NEWLINE,(num_tabs==1 ? "\t" : \
 146.128 +         (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1); \
 146.129 +       } while (0)
 146.130 +#          endif
 146.131 +#          ifndef png_debug2
 146.132 +#            define png_debug2(l,m,p1,p2) \
 146.133 +       do { \
 146.134 +       int num_tabs=l; \
 146.135 +       fprintf(PNG_DEBUG_FILE,"%s"m PNG_STRING_NEWLINE,(num_tabs==1 ? "\t" : \
 146.136 +         (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1,p2); \
 146.137 +       } while (0)
 146.138 +#          endif
 146.139 +#        else /* __STDC __ */
 146.140 +#          ifndef png_debug
 146.141 +#            define png_debug(l,m) \
 146.142 +       do { \
 146.143 +       int num_tabs=l; \
 146.144 +       char format[256]; \
 146.145 +       snprintf(format,256,"%s%s%s",(num_tabs==1 ? "\t" : \
 146.146 +         (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))), \
 146.147 +         m,PNG_STRING_NEWLINE); \
 146.148 +       fprintf(PNG_DEBUG_FILE,format); \
 146.149 +       } while (0)
 146.150 +#          endif
 146.151 +#          ifndef png_debug1
 146.152 +#            define png_debug1(l,m,p1) \
 146.153 +       do { \
 146.154 +       int num_tabs=l; \
 146.155 +       char format[256]; \
 146.156 +       snprintf(format,256,"%s%s%s",(num_tabs==1 ? "\t" : \
 146.157 +         (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))), \
 146.158 +         m,PNG_STRING_NEWLINE); \
 146.159 +       fprintf(PNG_DEBUG_FILE,format,p1); \
 146.160 +       } while (0)
 146.161 +#          endif
 146.162 +#          ifndef png_debug2
 146.163 +#            define png_debug2(l,m,p1,p2) \
 146.164 +       do { \
 146.165 +       int num_tabs=l; \
 146.166 +       char format[256]; \
 146.167 +       snprintf(format,256,"%s%s%s",(num_tabs==1 ? "\t" : \
 146.168 +         (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))), \
 146.169 +         m,PNG_STRING_NEWLINE); \
 146.170 +       fprintf(PNG_DEBUG_FILE,format,p1,p2); \
 146.171 +       } while (0)
 146.172 +#          endif
 146.173 +#        endif /* __STDC __ */
 146.174 +#      endif /* (PNG_DEBUG > 1) */
 146.175 +
 146.176 +#    endif /* _MSC_VER */
 146.177 +#  endif /* (PNG_DEBUG > 0) */
 146.178 +#endif /* PNG_DEBUG */
 146.179 +#ifndef png_debug
 146.180 +#  define png_debug(l, m) ((void)0)
 146.181 +#endif
 146.182 +#ifndef png_debug1
 146.183 +#  define png_debug1(l, m, p1) ((void)0)
 146.184 +#endif
 146.185 +#ifndef png_debug2
 146.186 +#  define png_debug2(l, m, p1, p2) ((void)0)
 146.187 +#endif
 146.188 +#endif /* PNGDEBUG_H */
   147.1 --- a/src/share/native/sun/awt/libpng/pngerror.c	Fri Sep 30 17:20:56 2011 -0700
   147.2 +++ b/src/share/native/sun/awt/libpng/pngerror.c	Tue Oct 04 12:39:42 2011 -0700
   147.3 @@ -20,8 +20,6 @@
   147.4   * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   147.5   * or visit www.oracle.com if you need additional information or have any
   147.6   * questions.
   147.7 - *
   147.8 - * THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
   147.9   */
  147.10  
  147.11  /* pngerror.c - stub functions for i/o and memory allocation
  147.12 @@ -31,69 +29,79 @@
  147.13   * However, the following notice accompanied the original version of this
  147.14   * file and, per its terms, should not be removed:
  147.15   *
  147.16 - * Last changed in libpng 1.2.13 November 13, 2006
  147.17 - * For conditions of distribution and use, see copyright notice in png.h
  147.18 - * Copyright (c) 1998-2006 Glenn Randers-Pehrson
  147.19 + * Last changed in libpng 1.5.4 [July 7, 2011]
  147.20 + * Copyright (c) 1998-2011 Glenn Randers-Pehrson
  147.21   * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
  147.22   * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
  147.23   *
  147.24 + * This code is released under the libpng license.
  147.25 + * For conditions of distribution and use, see the disclaimer
  147.26 + * and license in png.h
  147.27 + *
  147.28   * This file provides a location for all error handling.  Users who
  147.29   * need special error handling are expected to write replacement functions
  147.30   * and use png_set_error_fn() to use those functions.  See the instructions
  147.31   * at each function.
  147.32   */
  147.33  
  147.34 -#define PNG_INTERNAL
  147.35 -#include "png.h"
  147.36 +#include "pngpriv.h"
  147.37  
  147.38  #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  147.39 -static void /* PRIVATE */
  147.40 -png_default_error PNGARG((png_structp png_ptr,
  147.41 -  png_const_charp error_message));
  147.42 +
  147.43 +static PNG_FUNCTION(void, png_default_error,PNGARG((png_structp png_ptr,
  147.44 +    png_const_charp error_message)),PNG_NORETURN);
  147.45 +
  147.46 +#ifdef PNG_WARNINGS_SUPPORTED
  147.47  static void /* PRIVATE */
  147.48  png_default_warning PNGARG((png_structp png_ptr,
  147.49 -  png_const_charp warning_message));
  147.50 +   png_const_charp warning_message));
  147.51 +#endif /* PNG_WARNINGS_SUPPORTED */
  147.52  
  147.53  /* This function is called whenever there is a fatal error.  This function
  147.54   * should not be changed.  If there is a need to handle errors differently,
  147.55   * you should supply a replacement error function and use png_set_error_fn()
  147.56   * to replace the error function at run-time.
  147.57   */
  147.58 -void PNGAPI
  147.59 -png_error(png_structp png_ptr, png_const_charp error_message)
  147.60 +#ifdef PNG_ERROR_TEXT_SUPPORTED
  147.61 +PNG_FUNCTION(void,PNGAPI
  147.62 +png_error,(png_structp png_ptr, png_const_charp error_message),PNG_NORETURN)
  147.63  {
  147.64  #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  147.65     char msg[16];
  147.66     if (png_ptr != NULL)
  147.67     {
  147.68 -     if (png_ptr->flags&
  147.69 -       (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
  147.70 -     {
  147.71 -       if (*error_message == '#')
  147.72 -       {
  147.73 -           int offset;
  147.74 -           for (offset=1; offset<15; offset++)
  147.75 -              if (*(error_message+offset) == ' ')
  147.76 +      if (png_ptr->flags&
  147.77 +         (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
  147.78 +      {
  147.79 +         if (*error_message == PNG_LITERAL_SHARP)
  147.80 +         {
  147.81 +            /* Strip "#nnnn " from beginning of error message. */
  147.82 +            int offset;
  147.83 +            for (offset = 1; offset<15; offset++)
  147.84 +               if (error_message[offset] == ' ')
  147.85                    break;
  147.86 -           if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
  147.87 -           {
  147.88 -              int i;
  147.89 -              for (i=0; i<offset-1; i++)
  147.90 -                 msg[i]=error_message[i+1];
  147.91 -              msg[i]='\0';
  147.92 -              error_message=msg;
  147.93 -           }
  147.94 -           else
  147.95 -              error_message+=offset;
  147.96 -       }
  147.97 -       else
  147.98 -       {
  147.99 -           if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
 147.100 -           {
 147.101 -              msg[0]='0';
 147.102 -              msg[1]='\0';
 147.103 -              error_message=msg;
 147.104 -           }
 147.105 +
 147.106 +            if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
 147.107 +            {
 147.108 +               int i;
 147.109 +               for (i = 0; i < offset - 1; i++)
 147.110 +                  msg[i] = error_message[i + 1];
 147.111 +               msg[i - 1] = '\0';
 147.112 +               error_message = msg;
 147.113 +            }
 147.114 +
 147.115 +            else
 147.116 +               error_message += offset;
 147.117 +      }
 147.118 +
 147.119 +      else
 147.120 +      {
 147.121 +         if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
 147.122 +         {
 147.123 +            msg[0] = '0';
 147.124 +            msg[1] = '\0';
 147.125 +            error_message = msg;
 147.126 +         }
 147.127         }
 147.128       }
 147.129     }
 147.130 @@ -105,7 +113,126 @@
 147.131        use the default handler, which will not return. */
 147.132     png_default_error(png_ptr, error_message);
 147.133  }
 147.134 +#else
 147.135 +PNG_FUNCTION(void,PNGAPI
 147.136 +png_err,(png_structp png_ptr),PNG_NORETURN)
 147.137 +{
 147.138 +   /* Prior to 1.5.2 the error_fn received a NULL pointer, expressed
 147.139 +    * erroneously as '\0', instead of the empty string "".  This was
 147.140 +    * apparently an error, introduced in libpng-1.2.20, and png_default_error
 147.141 +    * will crash in this case.
 147.142 +    */
 147.143 +   if (png_ptr != NULL && png_ptr->error_fn != NULL)
 147.144 +      (*(png_ptr->error_fn))(png_ptr, "");
 147.145  
 147.146 +   /* If the custom handler doesn't exist, or if it returns,
 147.147 +      use the default handler, which will not return. */
 147.148 +   png_default_error(png_ptr, "");
 147.149 +}
 147.150 +#endif /* PNG_ERROR_TEXT_SUPPORTED */
 147.151 +
 147.152 +/* Utility to safely appends strings to a buffer.  This never errors out so
 147.153 + * error checking is not required in the caller.
 147.154 + */
 147.155 +size_t
 147.156 +png_safecat(png_charp buffer, size_t bufsize, size_t pos,
 147.157 +   png_const_charp string)
 147.158 +{
 147.159 +   if (buffer != NULL && pos < bufsize)
 147.160 +   {
 147.161 +      if (string != NULL)
 147.162 +         while (*string != '\0' && pos < bufsize-1)
 147.163 +           buffer[pos++] = *string++;
 147.164 +
 147.165 +      buffer[pos] = '\0';
 147.166 +   }
 147.167 +
 147.168 +   return pos;
 147.169 +}
 147.170 +
 147.171 +#if defined(PNG_WARNINGS_SUPPORTED) || defined(PNG_TIME_RFC1123_SUPPORTED)
 147.172 +/* Utility to dump an unsigned value into a buffer, given a start pointer and
 147.173 + * and end pointer (which should point just *beyond* the end of the buffer!)
 147.174 + * Returns the pointer to the start of the formatted string.
 147.175 + */
 147.176 +png_charp
 147.177 +png_format_number(png_const_charp start, png_charp end, int format,
 147.178 +   png_alloc_size_t number)
 147.179 +{
 147.180 +   int count = 0;    /* number of digits output */
 147.181 +   int mincount = 1; /* minimum number required */
 147.182 +   int output = 0;   /* digit output (for the fixed point format) */
 147.183 +
 147.184 +   *--end = '\0';
 147.185 +
 147.186 +   /* This is written so that the loop always runs at least once, even with
 147.187 +    * number zero.
 147.188 +    */
 147.189 +   while (end > start && (number != 0 || count < mincount))
 147.190 +   {
 147.191 +
 147.192 +      static const char digits[] = "0123456789ABCDEF";
 147.193 +
 147.194 +      switch (format)
 147.195 +      {
 147.196 +         case PNG_NUMBER_FORMAT_fixed:
 147.197 +            /* Needs five digits (the fraction) */
 147.198 +            mincount = 5;
 147.199 +            if (output || number % 10 != 0)
 147.200 +            {
 147.201 +               *--end = digits[number % 10];
 147.202 +               output = 1;
 147.203 +            }
 147.204 +            number /= 10;
 147.205 +            break;
 147.206 +
 147.207 +         case PNG_NUMBER_FORMAT_02u:
 147.208 +            /* Expects at least 2 digits. */
 147.209 +            mincount = 2;
 147.210 +            /* fall through */
 147.211 +
 147.212 +         case PNG_NUMBER_FORMAT_u:
 147.213 +            *--end = digits[number % 10];
 147.214 +            number /= 10;
 147.215 +            break;
 147.216 +
 147.217 +         case PNG_NUMBER_FORMAT_02x:
 147.218 +            /* This format expects at least two digits */
 147.219 +            mincount = 2;
 147.220 +            /* fall through */
 147.221 +
 147.222 +         case PNG_NUMBER_FORMAT_x:
 147.223 +            *--end = digits[number & 0xf];
 147.224 +            number >>= 4;
 147.225 +            break;
 147.226 +
 147.227 +         default: /* an error */
 147.228 +            number = 0;
 147.229 +            break;
 147.230 +      }
 147.231 +
 147.232 +      /* Keep track of the number of digits added */
 147.233 +      ++count;
 147.234 +
 147.235 +      /* Float a fixed number here: */
 147.236 +      if (format == PNG_NUMBER_FORMAT_fixed) if (count == 5) if (end > start)
 147.237 +      {
 147.238 +         /* End of the fraction, but maybe nothing was output?  In that case
 147.239 +          * drop the decimal point.  If the number is a true zero handle that
 147.240 +          * here.
 147.241 +          */
 147.242 +         if (output)
 147.243 +            *--end = '.';
 147.244 +         else if (number == 0) /* and !output */
 147.245 +            *--end = '0';
 147.246 +      }
 147.247 +   }
 147.248 +
 147.249 +   return end;
 147.250 +}
 147.251 +#endif
 147.252 +
 147.253 +#ifdef PNG_WARNINGS_SUPPORTED
 147.254  /* This function is called whenever there is a non-fatal error.  This function
 147.255   * should not be changed.  If there is a need to handle warnings differently,
 147.256   * you should supply a replacement warning function and use
 147.257 @@ -119,23 +246,144 @@
 147.258     {
 147.259  #ifdef PNG_ERROR_NUMBERS_SUPPORTED
 147.260     if (png_ptr->flags&
 147.261 -     (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
 147.262 +       (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
 147.263  #endif
 147.264 -     {
 147.265 -       if (*warning_message == '#')
 147.266 -       {
 147.267 -           for (offset=1; offset<15; offset++)
 147.268 -              if (*(warning_message+offset) == ' ')
 147.269 +      {
 147.270 +         if (*warning_message == PNG_LITERAL_SHARP)
 147.271 +         {
 147.272 +            for (offset = 1; offset < 15; offset++)
 147.273 +               if (warning_message[offset] == ' ')
 147.274                    break;
 147.275 -       }
 147.276 -     }
 147.277 -     if (png_ptr != NULL && png_ptr->warning_fn != NULL)
 147.278 -        (*(png_ptr->warning_fn))(png_ptr, warning_message+offset);
 147.279 +         }
 147.280 +      }
 147.281     }
 147.282 +   if (png_ptr != NULL && png_ptr->warning_fn != NULL)
 147.283 +      (*(png_ptr->warning_fn))(png_ptr, warning_message + offset);
 147.284     else
 147.285 -      png_default_warning(png_ptr, warning_message+offset);
 147.286 +      png_default_warning(png_ptr, warning_message + offset);
 147.287  }
 147.288  
 147.289 +/* These functions support 'formatted' warning messages with up to
 147.290 + * PNG_WARNING_PARAMETER_COUNT parameters.  In the format string the parameter
 147.291 + * is introduced by @<number>, where 'number' starts at 1.  This follows the
 147.292 + * standard established by X/Open for internationalizable error messages.
 147.293 + */
 147.294 +void
 147.295 +png_warning_parameter(png_warning_parameters p, int number,
 147.296 +   png_const_charp string)
 147.297 +{
 147.298 +   if (number > 0 && number <= PNG_WARNING_PARAMETER_COUNT)
 147.299 +      (void)png_safecat(p[number-1], (sizeof p[number-1]), 0, string);
 147.300 +}
 147.301 +
 147.302 +void
 147.303 +png_warning_parameter_unsigned(png_warning_parameters p, int number, int format,
 147.304 +   png_alloc_size_t value)
 147.305 +{
 147.306 +   char buffer[PNG_NUMBER_BUFFER_SIZE];
 147.307 +   png_warning_parameter(p, number, PNG_FORMAT_NUMBER(buffer, format, value));
 147.308 +}
 147.309 +
 147.310 +void
 147.311 +png_warning_parameter_signed(png_warning_parameters p, int number, int format,
 147.312 +   png_int_32 value)
 147.313 +{
 147.314 +   png_alloc_size_t u;
 147.315 +   png_charp str;
 147.316 +   char buffer[PNG_NUMBER_BUFFER_SIZE];
 147.317 +
 147.318 +   /* Avoid overflow by doing the negate in a png_alloc_size_t: */
 147.319 +   u = (png_alloc_size_t)value;
 147.320 +   if (value < 0)
 147.321 +      u = ~u + 1;
 147.322 +
 147.323 +   str = PNG_FORMAT_NUMBER(buffer, format, u);
 147.324 +
 147.325 +   if (value < 0 && str > buffer)
 147.326 +      *--str = '-';
 147.327 +
 147.328 +   png_warning_parameter(p, number, str);
 147.329 +}
 147.330 +
 147.331 +void
 147.332 +png_formatted_warning(png_structp png_ptr, png_warning_parameters p,
 147.333 +   png_const_charp message)
 147.334 +{
 147.335 +   /* The internal buffer is just 128 bytes - enough for all our messages,
 147.336 +    * overflow doesn't happen because this code checks!
 147.337 +    */
 147.338 +   size_t i;
 147.339 +   char msg[128];
 147.340 +
 147.341 +   for (i=0; i<(sizeof msg)-1 && *message != '\0'; ++i)
 147.342 +   {
 147.343 +      if (*message == '@')
 147.344 +      {
 147.345 +         int parameter = -1;
 147.346 +         switch (*++message)
 147.347 +         {
 147.348 +            case '1':
 147.349 +               parameter = 0;
 147.350 +               break;
 147.351 +
 147.352 +            case '2':
 147.353 +               parameter = 1;
 147.354 +               break;
 147.355 +
 147.356 +            case '\0':
 147.357 +               continue; /* To break out of the for loop above. */
 147.358 +
 147.359 +            default:
 147.360 +               break;
 147.361 +         }
 147.362 +
 147.363 +         if (parameter >= 0 && parameter < PNG_WARNING_PARAMETER_COUNT)
 147.364 +         {
 147.365 +            /* Append this parameter */
 147.366 +            png_const_charp parm = p[parameter];
 147.367 +            png_const_charp pend = p[parameter] + (sizeof p[parameter]);
 147.368 +
 147.369 +            /* No need to copy the trailing '\0' here, but there is no guarantee
 147.370 +             * that parm[] has been initialized, so there is no guarantee of a
 147.371 +             * trailing '\0':
 147.372 +             */
 147.373 +            for (; i<(sizeof msg)-1 && parm != '\0' && parm < pend; ++i)
 147.374 +               msg[i] = *parm++;
 147.375 +
 147.376 +            ++message;
 147.377 +            continue;
 147.378 +         }
 147.379 +
 147.380 +         /* else not a parameter and there is a character after the @ sign; just
 147.381 +          * copy that.
 147.382 +          */
 147.383 +      }
 147.384 +
 147.385 +      /* At this point *message can't be '\0', even in the bad parameter case
 147.386 +       * above where there is a lone '@' at the end of the message string.
 147.387 +       */
 147.388 +      msg[i] = *message++;
 147.389 +   }
 147.390 +
 147.391 +   /* i is always less than (sizeof msg), so: */
 147.392 +   msg[i] = '\0';
 147.393 +
 147.394 +   /* And this is the formatted message: */
 147.395 +   png_warning(png_ptr, msg);
 147.396 +}
 147.397 +#endif /* PNG_WARNINGS_SUPPORTED */
 147.398 +
 147.399 +#ifdef PNG_BENIGN_ERRORS_SUPPORTED
 147.400 +void PNGAPI
 147.401 +png_benign_error(png_structp png_ptr, png_const_charp error_message)
 147.402 +{
 147.403 +  if (png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN)
 147.404 +     png_warning(png_ptr, error_message);
 147.405 +  else
 147.406 +     png_error(png_ptr, error_message);
 147.407 +}
 147.408 +#endif
 147.409 +
 147.410  /* These utilities are used internally to build an error message that relates
 147.411   * to the current chunk.  The chunk name comes from png_ptr->chunk_name,
 147.412   * this is used to prefix the message.  The message is limited in length
 147.413 @@ -148,9 +396,11 @@
 147.414     'A', 'B', 'C', 'D', 'E', 'F'
 147.415  };
 147.416  
 147.417 +#define PNG_MAX_ERROR_TEXT 64
 147.418 +#if defined(PNG_WARNINGS_SUPPORTED) || defined(PNG_ERROR_TEXT_SUPPORTED)
 147.419  static void /* PRIVATE */
 147.420  png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp
 147.421 -   error_message)
 147.422 +    error_message)
 147.423  {
 147.424     int iout = 0, iin = 0;
 147.425  
 147.426 @@ -159,11 +409,12 @@
 147.427        int c = png_ptr->chunk_name[iin++];
 147.428        if (isnonalpha(c))
 147.429        {
 147.430 -         buffer[iout++] = '[';
 147.431 +         buffer[iout++] = PNG_LITERAL_LEFT_SQUARE_BRACKET;
 147.432           buffer[iout++] = png_digit[(c & 0xf0) >> 4];
 147.433           buffer[iout++] = png_digit[c & 0x0f];
 147.434 -         buffer[iout++] = ']';
 147.435 +         buffer[iout++] = PNG_LITERAL_RIGHT_SQUARE_BRACKET;
 147.436        }
 147.437 +
 147.438        else
 147.439        {
 147.440           buffer[iout++] = (png_byte)c;
 147.441 @@ -171,99 +422,183 @@
 147.442     }
 147.443  
 147.444     if (error_message == NULL)
 147.445 -      buffer[iout] = 0;
 147.446 +      buffer[iout] = '\0';
 147.447 +
 147.448     else
 147.449     {
 147.450        buffer[iout++] = ':';
 147.451        buffer[iout++] = ' ';
 147.452 -      png_strncpy(buffer+iout, error_message, 63);
 147.453 -      buffer[iout+63] = 0;
 147.454 +
 147.455 +      iin = 0;
 147.456 +      while (iin < PNG_MAX_ERROR_TEXT-1 && error_message[iin] != '\0')
 147.457 +         buffer[iout++] = error_message[iin++];
 147.458 +
 147.459 +      /* iin < PNG_MAX_ERROR_TEXT, so the following is safe: */
 147.460 +      buffer[iout] = '\0';
 147.461     }
 147.462  }
 147.463 +#endif /* PNG_WARNINGS_SUPPORTED || PNG_ERROR_TEXT_SUPPORTED */
 147.464  
 147.465 -void PNGAPI
 147.466 -png_chunk_error(png_structp png_ptr, png_const_charp error_message)
 147.467 +#if defined(PNG_READ_SUPPORTED) && defined(PNG_ERROR_TEXT_SUPPORTED)
 147.468 +PNG_FUNCTION(void,PNGAPI
 147.469 +png_chunk_error,(png_structp png_ptr, png_const_charp error_message),
 147.470 +   PNG_NORETURN)
 147.471  {
 147.472 -   char msg[18+64];
 147.473 +   char msg[18+PNG_MAX_ERROR_TEXT];
 147.474     if (png_ptr == NULL)
 147.475 -     png_error(png_ptr, error_message);
 147.476 +      png_error(png_ptr, error_message);
 147.477 +
 147.478     else
 147.479     {
 147.480 -     png_format_buffer(png_ptr, msg, error_message);
 147.481 -     png_error(png_ptr, msg);
 147.482 +      png_format_buffer(png_ptr, msg, error_message);
 147.483 +      png_error(png_ptr, msg);
 147.484     }
 147.485  }
 147.486 +#endif /* PNG_READ_SUPPORTED && PNG_ERROR_TEXT_SUPPORTED */
 147.487  
 147.488 +#ifdef PNG_WARNINGS_SUPPORTED
 147.489  void PNGAPI
 147.490  png_chunk_warning(png_structp png_ptr, png_const_charp warning_message)
 147.491  {
 147.492 -   char msg[18+64];
 147.493 +   char msg[18+PNG_MAX_ERROR_TEXT];
 147.494     if (png_ptr == NULL)
 147.495 -     png_warning(png_ptr, warning_message);
 147.496 +      png_warning(png_ptr, warning_message);
 147.497 +
 147.498     else
 147.499     {
 147.500 -     png_format_buffer(png_ptr, msg, warning_message);
 147.501 -     png_warning(png_ptr, msg);
 147.502 +      png_format_buffer(png_ptr, msg, warning_message);
 147.503 +      png_warning(png_ptr, msg);
 147.504     }
 147.505  }
 147.506 +#endif /* PNG_WARNINGS_SUPPORTED */
 147.507 +
 147.508 +#ifdef PNG_READ_SUPPORTED
 147.509 +#ifdef PNG_BENIGN_ERRORS_SUPPORTED
 147.510 +void PNGAPI
 147.511 +png_chunk_benign_error(png_structp png_ptr, png_const_charp error_message)
 147.512 +{
 147.513 +   if (png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN)
 147.514 +      png_chunk_warning(png_ptr, error_message);
 147.515 +
 147.516 +   else
 147.517 +      png_chunk_error(png_ptr, error_message);
 147.518 +}
 147.519 +#endif
 147.520 +#endif /* PNG_READ_SUPPORTED */
 147.521 +
 147.522 +#ifdef PNG_ERROR_TEXT_SUPPORTED
 147.523 +#ifdef PNG_FLOATING_POINT_SUPPORTED
 147.524 +PNG_FUNCTION(void,
 147.525 +png_fixed_error,(png_structp png_ptr, png_const_charp name),PNG_NORETURN)
 147.526 +{
 147.527 +#  define fixed_message "fixed point overflow in "
 147.528 +#  define fixed_message_ln ((sizeof fixed_message)-1)
 147.529 +   int  iin;
 147.530 +   char msg[fixed_message_ln+PNG_MAX_ERROR_TEXT];
 147.531 +   png_memcpy(msg, fixed_message, fixed_message_ln);
 147.532 +   iin = 0;
 147.533 +   if (name != NULL) while (iin < (PNG_MAX_ERROR_TEXT-1) && name[iin] != 0)
 147.534 +   {
 147.535 +      msg[fixed_message_ln + iin] = name[iin];
 147.536 +      ++iin;
 147.537 +   }
 147.538 +   msg[fixed_message_ln + iin] = 0;
 147.539 +   png_error(png_ptr, msg);
 147.540 +}
 147.541 +#endif
 147.542 +#endif
 147.543 +
 147.544 +#ifdef PNG_SETJMP_SUPPORTED
 147.545 +/* This API only exists if ANSI-C style error handling is used,
 147.546 + * otherwise it is necessary for png_default_error to be overridden.
 147.547 + */
 147.548 +jmp_buf* PNGAPI
 147.549 +png_set_longjmp_fn(png_structp png_ptr, png_longjmp_ptr longjmp_fn,
 147.550 +    size_t jmp_buf_size)
 147.551 +{
 147.552 +   if (png_ptr == NULL || jmp_buf_size != png_sizeof(jmp_buf))
 147.553 +      return NULL;
 147.554 +
 147.555 +   png_ptr->longjmp_fn = longjmp_fn;
 147.556 +   return &png_ptr->longjmp_buffer;
 147.557 +}
 147.558 +#endif
 147.559  
 147.560  /* This is the default error handling function.  Note that replacements for
 147.561   * this function MUST NOT RETURN, or the program will likely crash.  This
 147.562   * function is used by default, or if the program supplies NULL for the
 147.563   * error function pointer in png_set_error_fn().
 147.564   */
 147.565 -static void /* PRIVATE */
 147.566 -png_default_error(png_structp png_ptr, png_const_charp error_message)
 147.567 +static PNG_FUNCTION(void /* PRIVATE */,
 147.568 +png_default_error,(png_structp png_ptr, png_const_charp error_message),
 147.569 +   PNG_NORETURN)
 147.570  {
 147.571 -#ifndef PNG_NO_CONSOLE_IO
 147.572 +#ifdef PNG_CONSOLE_IO_SUPPORTED
 147.573  #ifdef PNG_ERROR_NUMBERS_SUPPORTED
 147.574 -   if (*error_message == '#')
 147.575 +   /* Check on NULL only added in 1.5.4 */
 147.576 +   if (error_message != NULL && *error_message == PNG_LITERAL_SHARP)
 147.577     {
 147.578 -     int offset;
 147.579 -     char error_number[16];
 147.580 -     for (offset=0; offset<15; offset++)
 147.581 -     {
 147.582 -         error_number[offset] = *(error_message+offset+1);
 147.583 -         if (*(error_message+offset) == ' ')
 147.584 -             break;
 147.585 -     }
 147.586 -     if((offset > 1) && (offset < 15))
 147.587 -     {
 147.588 -       error_number[offset-1]='\0';
 147.589 -       fprintf(stderr, "libpng error no. %s: %s\n", error_number,
 147.590 -          error_message+offset);
 147.591 -     }
 147.592 -     else
 147.593 -       fprintf(stderr, "libpng error: %s, offset=%d\n", error_message,offset);
 147.594 +      /* Strip "#nnnn " from beginning of error message. */
 147.595 +      int offset;
 147.596 +      char error_number[16];
 147.597 +      for (offset = 0; offset<15; offset++)
 147.598 +      {
 147.599 +         error_number[offset] = error_message[offset + 1];
 147.600 +         if (error_message[offset] == ' ')
 147.601 +            break;
 147.602 +      }
 147.603 +
 147.604 +      if ((offset > 1) && (offset < 15))
 147.605 +      {
 147.606 +         error_number[offset - 1] = '\0';
 147.607 +         fprintf(stderr, "libpng error no. %s: %s",
 147.608 +             error_number, error_message + offset + 1);
 147.609 +         fprintf(stderr, PNG_STRING_NEWLINE);
 147.610 +      }
 147.611 +
 147.612 +      else
 147.613 +      {
 147.614 +         fprintf(stderr, "libpng error: %s, offset=%d",
 147.615 +             error_message, offset);
 147.616 +         fprintf(stderr, PNG_STRING_NEWLINE);
 147.617 +      }
 147.618     }
 147.619     else
 147.620  #endif
 147.621 -   fprintf(stderr, "libpng error: %s\n", error_message);
 147.622 +   {
 147.623 +      fprintf(stderr, "libpng error: %s", error_message ? error_message :
 147.624 +         "undefined");
 147.625 +      fprintf(stderr, PNG_STRING_NEWLINE);
 147.626 +   }
 147.627 +#else
 147.628 +   PNG_UNUSED(error_message) /* Make compiler happy */
 147.629  #endif
 147.630 +   png_longjmp(png_ptr, 1);
 147.631 +}
 147.632  
 147.633 +PNG_FUNCTION(void,PNGAPI
 147.634 +png_longjmp,(png_structp png_ptr, int val),PNG_NORETURN)
 147.635 +{
 147.636  #ifdef PNG_SETJMP_SUPPORTED
 147.637 -   if (png_ptr)
 147.638 +   if (png_ptr && png_ptr->longjmp_fn)
 147.639     {
 147.640  #  ifdef USE_FAR_KEYWORD
 147.641 -   {
 147.642 -      jmp_buf jmpbuf;
 147.643 -      png_memcpy(jmpbuf,png_ptr->jmpbuf,png_sizeof(jmp_buf));
 147.644 -      longjmp(jmpbuf, 1);
 147.645 -   }
 147.646 +      {
 147.647 +         jmp_buf tmp_jmpbuf;
 147.648 +         png_memcpy(tmp_jmpbuf, png_ptr->longjmp_buffer, png_sizeof(jmp_buf));
 147.649 +         png_ptr->longjmp_fn(tmp_jmpbuf, val);
 147.650 +      }
 147.651 +
 147.652  #  else
 147.653 -   longjmp(png_ptr->jmpbuf, 1);
 147.654 +   png_ptr->longjmp_fn(png_ptr->longjmp_buffer, val);
 147.655  #  endif
 147.656     }
 147.657 -#else
 147.658 +#endif
 147.659 +   /* Here if not setjmp support or if png_ptr is null. */
 147.660     PNG_ABORT();
 147.661 -#endif
 147.662 -#ifdef PNG_NO_CONSOLE_IO
 147.663 -   /* make compiler happy */ ;
 147.664 -   if (&error_message != NULL)
 147.665 -      return;
 147.666 -#endif
 147.667  }
 147.668  
 147.669 +#ifdef PNG_WARNINGS_SUPPORTED
 147.670  /* This function is called when there is a warning, but the library thinks
 147.671   * it can continue anyway.  Replacement functions don't have to do anything
 147.672   * here if you don't want them to.  In the default configuration, png_ptr is
 147.673 @@ -272,54 +607,67 @@
 147.674  static void /* PRIVATE */
 147.675  png_default_warning(png_structp png_ptr, png_const_charp warning_message)
 147.676  {
 147.677 -#ifndef PNG_NO_CONSOLE_IO
 147.678 +#ifdef PNG_CONSOLE_IO_SUPPORTED
 147.679  #  ifdef PNG_ERROR_NUMBERS_SUPPORTED
 147.680 -   if (*warning_message == '#')
 147.681 +   if (*warning_message == PNG_LITERAL_SHARP)
 147.682     {
 147.683 -     int offset;
 147.684 -     char warning_number[16];
 147.685 -     for (offset=0; offset<15; offset++)
 147.686 -     {
 147.687 -        warning_number[offset]=*(warning_message+offset+1);
 147.688 -        if (*(warning_message+offset) == ' ')
 147.689 +      int offset;
 147.690 +      char warning_number[16];
 147.691 +      for (offset = 0; offset < 15; offset++)
 147.692 +      {
 147.693 +         warning_number[offset] = warning_message[offset + 1];
 147.694 +         if (warning_message[offset] == ' ')
 147.695              break;
 147.696 -     }
 147.697 -     if((offset > 1) && (offset < 15))
 147.698 -     {
 147.699 -       warning_number[offset-1]='\0';
 147.700 -       fprintf(stderr, "libpng warning no. %s: %s\n", warning_number,
 147.701 -          warning_message+offset);
 147.702 -     }
 147.703 -     else
 147.704 -       fprintf(stderr, "libpng warning: %s\n", warning_message);
 147.705 +      }
 147.706 +
 147.707 +      if ((offset > 1) && (offset < 15))
 147.708 +      {
 147.709 +         warning_number[offset + 1] = '\0';
 147.710 +         fprintf(stderr, "libpng warning no. %s: %s",
 147.711 +             warning_number, warning_message + offset);
 147.712 +         fprintf(stderr, PNG_STRING_NEWLINE);
 147.713 +      }
 147.714 +
 147.715 +      else
 147.716 +      {
 147.717 +         fprintf(stderr, "libpng warning: %s",
 147.718 +             warning_message);
 147.719 +         fprintf(stderr, PNG_STRING_NEWLINE);
 147.720 +      }
 147.721     }
 147.722     else
 147.723  #  endif
 147.724 -     fprintf(stderr, "libpng warning: %s\n", warning_message);
 147.725 +
 147.726 +   {
 147.727 +      fprintf(stderr, "libpng warning: %s", warning_message);
 147.728 +      fprintf(stderr, PNG_STRING_NEWLINE);
 147.729 +   }
 147.730  #else
 147.731 -   /* make compiler happy */ ;
 147.732 -   if (warning_message)
 147.733 -     return;
 147.734 +   PNG_UNUSED(warning_message) /* Make compiler happy */
 147.735  #endif
 147.736 -   /* make compiler happy */ ;
 147.737 -   if (png_ptr)
 147.738 -      return;
 147.739 +   PNG_UNUSED(png_ptr) /* Make compiler happy */
 147.740  }
 147.741 +#endif /* PNG_WARNINGS_SUPPORTED */
 147.742  
 147.743  /* This function is called when the application wants to use another method
 147.744   * of handling errors and warnings.  Note that the error function MUST NOT
 147.745   * return to the calling routine or serious problems will occur.  The return
 147.746 - * method used in the default routine calls longjmp(png_ptr->jmpbuf, 1)
 147.747 + * method used in the default routine calls longjmp(png_ptr->longjmp_buffer, 1)
 147.748   */
 147.749  void PNGAPI
 147.750  png_set_error_fn(png_structp png_ptr, png_voidp error_ptr,
 147.751 -   png_error_ptr error_fn, png_error_ptr warning_fn)
 147.752 +    png_error_ptr error_fn, png_error_ptr warning_fn)
 147.753  {
 147.754     if (png_ptr == NULL)
 147.755        return;
 147.756 +
 147.757     png_ptr->error_ptr = error_ptr;
 147.758     png_ptr->error_fn = error_fn;
 147.759 +#ifdef PNG_WARNINGS_SUPPORTED
 147.760     png_ptr->warning_fn = warning_fn;
 147.761 +#else
 147.762 +   PNG_UNUSED(warning_fn)
 147.763 +#endif
 147.764  }
 147.765  
 147.766  
 147.767 @@ -328,10 +676,11 @@
 147.768   * pointer before png_write_destroy and png_read_destroy are called.
 147.769   */
 147.770  png_voidp PNGAPI
 147.771 -png_get_error_ptr(png_structp png_ptr)
 147.772 +png_get_error_ptr(png_const_structp png_ptr)
 147.773  {
 147.774     if (png_ptr == NULL)
 147.775        return NULL;
 147.776 +
 147.777     return ((png_voidp)png_ptr->error_ptr);
 147.778  }
 147.779  
 147.780 @@ -340,10 +689,11 @@
 147.781  void PNGAPI
 147.782  png_set_strip_error_numbers(png_structp png_ptr, png_uint_32 strip_mode)
 147.783  {
 147.784 -   if(png_ptr != NULL)
 147.785 +   if (png_ptr != NULL)
 147.786     {
 147.787 -     png_ptr->flags &=
 147.788 -       ((~(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))&strip_mode);
 147.789 +      png_ptr->flags &=
 147.790 +         ((~(PNG_FLAG_STRIP_ERROR_NUMBERS |
 147.791 +         PNG_FLAG_STRIP_ERROR_TEXT))&strip_mode);
 147.792     }
 147.793  }
 147.794  #endif
   148.1 --- a/src/share/native/sun/awt/libpng/pnggccrd.c	Fri Sep 30 17:20:56 2011 -0700
   148.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   148.3 @@ -1,5448 +0,0 @@
   148.4 -/*
   148.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   148.6 - *
   148.7 - * This code is free software; you can redistribute it and/or modify it
   148.8 - * under the terms of the GNU General Public License version 2 only, as
   148.9 - * published by the Free Software Foundation.  Oracle designates this
  148.10 - * particular file as subject to the "Classpath" exception as provided
  148.11 - * by Oracle in the LICENSE file that accompanied this code.
  148.12 - *
  148.13 - * This code is distributed in the hope that it will be useful, but WITHOUT
  148.14 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  148.15 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  148.16 - * version 2 for more details (a copy is included in the LICENSE file that
  148.17 - * accompanied this code).
  148.18 - *
  148.19 - * You should have received a copy of the GNU General Public License version
  148.20 - * 2 along with this work; if not, write to the Free Software Foundation,
  148.21 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  148.22 - *
  148.23 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  148.24 - * or visit www.oracle.com if you need additional information or have any
  148.25 - * questions.
  148.26 - */
  148.27 -
  148.28 -/* pnggccrd.c - mixed C/assembler version of utilities to read a PNG file
  148.29 - *
  148.30 - * This file is available under and governed by the GNU General Public
  148.31 - * License version 2 only, as published by the Free Software Foundation.
  148.32 - * However, the following notice accompanied the original version of this
  148.33 - * file and, per its terms, should not be removed:
  148.34 - *
  148.35 - * For Intel x86 CPU (Pentium-MMX or later) and GNU C compiler.
  148.36 - *
  148.37 - *     See http://www.intel.com/drg/pentiumII/appnotes/916/916.htm
  148.38 - *     and http://www.intel.com/drg/pentiumII/appnotes/923/923.htm
  148.39 - *     for Intel's performance analysis of the MMX vs. non-MMX code.
  148.40 - *
  148.41 - * Last changed in libpng 1.2.15 January 5, 2007
  148.42 - * For conditions of distribution and use, see copyright notice in png.h
  148.43 - * Copyright (c) 1998-2007 Glenn Randers-Pehrson
  148.44 - * Copyright (c) 1998, Intel Corporation
  148.45 - *
  148.46 - * Based on MSVC code contributed by Nirav Chhatrapati, Intel Corp., 1998.
  148.47 - * Interface to libpng contributed by Gilles Vollant, 1999.
  148.48 - * GNU C port by Greg Roelofs, 1999-2001.
  148.49 - *
  148.50 - * Lines 2350-4300 converted in place with intel2gas 1.3.1:
  148.51 - *
  148.52 - *   intel2gas -mdI pnggccrd.c.partially-msvc -o pnggccrd.c
  148.53 - *
  148.54 - * and then cleaned up by hand.  See http://hermes.terminal.at/intel2gas/ .
  148.55 - *
  148.56 - * NOTE:  A sufficiently recent version of GNU as (or as.exe under DOS/Windows)
  148.57 - *        is required to assemble the newer MMX instructions such as movq.
  148.58 - *        For djgpp, see
  148.59 - *
  148.60 - *           ftp://ftp.simtel.net/pub/simtelnet/gnu/djgpp/v2gnu/bnu281b.zip
  148.61 - *
  148.62 - *        (or a later version in the same directory).  For Linux, check your
  148.63 - *        distribution's web site(s) or try these links:
  148.64 - *
  148.65 - *           http://rufus.w3.org/linux/RPM/binutils.html
  148.66 - *           http://www.debian.org/Packages/stable/devel/binutils.html
  148.67 - *           ftp://ftp.slackware.com/pub/linux/slackware/slackware/slakware/d1/
  148.68 - *             binutils.tgz
  148.69 - *
  148.70 - *        For other platforms, see the main GNU site:
  148.71 - *
  148.72 - *           ftp://ftp.gnu.org/pub/gnu/binutils/
  148.73 - *
  148.74 - *        Version 2.5.2l.15 is definitely too old...
  148.75 - */
  148.76 -
  148.77 -/*
  148.78 - * TEMPORARY PORTING NOTES AND CHANGELOG (mostly by Greg Roelofs)
  148.79 - * =====================================
  148.80 - *
  148.81 - * 19991006:
  148.82 - *  - fixed sign error in post-MMX cleanup code (16- & 32-bit cases)
  148.83 - *
  148.84 - * 19991007:
  148.85 - *  - additional optimizations (possible or definite):
  148.86 - *     x [DONE] write MMX code for 64-bit case (pixel_bytes == 8) [not tested]
  148.87 - *     - write MMX code for 48-bit case (pixel_bytes == 6)
  148.88 - *     - figure out what's up with 24-bit case (pixel_bytes == 3):
  148.89 - *        why subtract 8 from width_mmx in the pass 4/5 case?
  148.90 - *        (only width_mmx case) (near line 1606)
  148.91 - *     x [DONE] replace pixel_bytes within each block with the true
  148.92 - *        constant value (or are compilers smart enough to do that?)
  148.93 - *     - rewrite all MMX interlacing code so it's aligned with
  148.94 - *        the *beginning* of the row buffer, not the end.  This
  148.95 - *        would not only allow one to eliminate half of the memory
  148.96 - *        writes for odd passes (that is, pass == odd), it may also
  148.97 - *        eliminate some unaligned-data-access exceptions (assuming
  148.98 - *        there's a penalty for not aligning 64-bit accesses on
  148.99 - *        64-bit boundaries).  The only catch is that the "leftover"
 148.100 - *        pixel(s) at the end of the row would have to be saved,
 148.101 - *        but there are enough unused MMX registers in every case,
 148.102 - *        so this is not a problem.  A further benefit is that the
 148.103 - *        post-MMX cleanup code (C code) in at least some of the
 148.104 - *        cases could be done within the assembler block.
 148.105 - *  x [DONE] the "v3 v2 v1 v0 v7 v6 v5 v4" comments are confusing,
 148.106 - *     inconsistent, and don't match the MMX Programmer's Reference
 148.107 - *     Manual conventions anyway.  They should be changed to
 148.108 - *     "b7 b6 b5 b4 b3 b2 b1 b0," where b0 indicates the byte that
 148.109 - *     was lowest in memory (e.g., corresponding to a left pixel)
 148.110 - *     and b7 is the byte that was highest (e.g., a right pixel).
 148.111 - *
 148.112 - * 19991016:
 148.113 - *  - Brennan's Guide notwithstanding, gcc under Linux does *not*
 148.114 - *     want globals prefixed by underscores when referencing them--
 148.115 - *     i.e., if the variable is const4, then refer to it as const4,
 148.116 - *     not _const4.  This seems to be a djgpp-specific requirement.
 148.117 - *     Also, such variables apparently *must* be declared outside
 148.118 - *     of functions; neither static nor automatic variables work if
 148.119 - *     defined within the scope of a single function, but both
 148.120 - *     static and truly global (multi-module) variables work fine.
 148.121 - *
 148.122 - * 19991023:
 148.123 - *  - fixed png_combine_row() non-MMX replication bug (odd passes only?)
 148.124 - *  - switched from string-concatenation-with-macros to cleaner method of
 148.125 - *     renaming global variables for djgpp--i.e., always use prefixes in
 148.126 - *     inlined assembler code (== strings) and conditionally rename the
 148.127 - *     variables, not the other way around.  Hence _const4, _mask8_0, etc.
 148.128 - *
 148.129 - * 19991024:
 148.130 - *  - fixed mmxsupport()/png_do_read_interlace() first-row bug
 148.131 - *     This one was severely weird:  even though mmxsupport() doesn't touch
 148.132 - *     ebx (where "row" pointer was stored), it nevertheless managed to zero
 148.133 - *     the register (even in static/non-fPIC code--see below), which in turn
 148.134 - *     caused png_do_read_interlace() to return prematurely on the first row of
 148.135 - *     interlaced images (i.e., without expanding the interlaced pixels).
 148.136 - *     Inspection of the generated assembly code didn't turn up any clues,
 148.137 - *     although it did point at a minor optimization (i.e., get rid of
 148.138 - *     mmx_supported_local variable and just use eax).  Possibly the CPUID
 148.139 - *     instruction is more destructive than it looks?  (Not yet checked.)
 148.140 - *  - "info gcc" was next to useless, so compared fPIC and non-fPIC assembly
 148.141 - *     listings...  Apparently register spillage has to do with ebx, since
 148.142 - *     it's used to index the global offset table.  Commenting it out of the
 148.143 - *     input-reg lists in png_combine_row() eliminated compiler barfage, so
 148.144 - *     ifdef'd with __PIC__ macro:  if defined, use a global for unmask
 148.145 - *
 148.146 - * 19991107:
 148.147 - *  - verified CPUID clobberage:  12-char string constant ("GenuineIntel",
 148.148 - *     "AuthenticAMD", etc.) placed in ebx:ecx:edx.  Still need to polish.
 148.149 - *
 148.150 - * 19991120:
 148.151 - *  - made "diff" variable (now "_dif") global to simplify conversion of
 148.152 - *     filtering routines (running out of regs, sigh).  "diff" is still used
 148.153 - *     in interlacing routines, however.
 148.154 - *  - fixed up both versions of mmxsupport() (ORIG_THAT_USED_TO_CLOBBER_EBX
 148.155 - *     macro determines which is used); original not yet tested.
 148.156 - *
 148.157 - * 20000213:
 148.158 - *  - when compiling with gcc, be sure to use  -fomit-frame-pointer
 148.159 - *
 148.160 - * 20000319:
 148.161 - *  - fixed a register-name typo in png_do_read_interlace(), default (MMX) case,
 148.162 - *     pass == 4 or 5, that caused visible corruption of interlaced images
 148.163 - *
 148.164 - * 20000623:
 148.165 - *  - Various problems were reported with gcc 2.95.2 in the Cygwin environment,
 148.166 - *     many of the form "forbidden register 0 (ax) was spilled for class AREG."
 148.167 - *     This is explained at http://gcc.gnu.org/fom_serv/cache/23.html, and
 148.168 - *     Chuck Wilson supplied a patch involving dummy output registers.  See
 148.169 - *     http://sourceforge.net/bugs/?func=detailbug&bug_id=108741&group_id=5624
 148.170 - *     for the original (anonymous) SourceForge bug report.
 148.171 - *
 148.172 - * 20000706:
 148.173 - *  - Chuck Wilson passed along these remaining gcc 2.95.2 errors:
 148.174 - *       pnggccrd.c: In function `png_combine_row':
 148.175 - *       pnggccrd.c:525: more than 10 operands in `asm'
 148.176 - *       pnggccrd.c:669: more than 10 operands in `asm'
 148.177 - *       pnggccrd.c:828: more than 10 operands in `asm'
 148.178 - *       pnggccrd.c:994: more than 10 operands in `asm'
 148.179 - *       pnggccrd.c:1177: more than 10 operands in `asm'
 148.180 - *     They are all the same problem and can be worked around by using the
 148.181 - *     global _unmask variable unconditionally, not just in the -fPIC case.
 148.182 - *     Reportedly earlier versions of gcc also have the problem with more than
 148.183 - *     10 operands; they just don't report it.  Much strangeness ensues, etc.
 148.184 - *
 148.185 - * 20000729:
 148.186 - *  - enabled png_read_filter_row_mmx_up() (shortest remaining unconverted
 148.187 - *     MMX routine); began converting png_read_filter_row_mmx_sub()
 148.188 - *  - to finish remaining sections:
 148.189 - *     - clean up indentation and comments
 148.190 - *     - preload local variables
 148.191 - *     - add output and input regs (order of former determines numerical
 148.192 - *        mapping of latter)
 148.193 - *     - avoid all usage of ebx (including bx, bh, bl) register [20000823]
 148.194 - *     - remove "$" from addressing of Shift and Mask variables [20000823]
 148.195 - *
 148.196 - * 20000731:
 148.197 - *  - global union vars causing segfaults in png_read_filter_row_mmx_sub()?
 148.198 - *
 148.199 - * 20000822:
 148.200 - *  - ARGH, stupid png_read_filter_row_mmx_sub() segfault only happens with
 148.201 - *     shared-library (-fPIC) version!  Code works just fine as part of static
 148.202 - *     library.  Damn damn damn damn damn, should have tested that sooner.
 148.203 - *     ebx is getting clobbered again (explicitly this time); need to save it
 148.204 - *     on stack or rewrite asm code to avoid using it altogether.  Blargh!
 148.205 - *
 148.206 - * 20000823:
 148.207 - *  - first section was trickiest; all remaining sections have ebx -> edx now.
 148.208 - *     (-fPIC works again.)  Also added missing underscores to various Shift*
 148.209 - *     and *Mask* globals and got rid of leading "$" signs.
 148.210 - *
 148.211 - * 20000826:
 148.212 - *  - added visual separators to help navigate microscopic printed copies
 148.213 - *     (http://pobox.com/~newt/code/gpr-latest.zip, mode 10); started working
 148.214 - *     on png_read_filter_row_mmx_avg()
 148.215 - *
 148.216 - * 20000828:
 148.217 - *  - finished png_read_filter_row_mmx_avg():  only Paeth left! (930 lines...)
 148.218 - *     What the hell, did png_read_filter_row_mmx_paeth(), too.  Comments not
 148.219 - *     cleaned up/shortened in either routine, but functionality is complete
 148.220 - *     and seems to be working fine.
 148.221 - *
 148.222 - * 20000829:
 148.223 - *  - ahhh, figured out last(?) bit of gcc/gas asm-fu:  if register is listed
 148.224 - *     as an input reg (with dummy output variables, etc.), then it *cannot*
 148.225 - *     also appear in the clobber list or gcc 2.95.2 will barf.  The solution
 148.226 - *     is simple enough...
 148.227 - *
 148.228 - * 20000914:
 148.229 - *  - bug in png_read_filter_row_mmx_avg():  16-bit grayscale not handled
 148.230 - *     correctly (but 48-bit RGB just fine)
 148.231 - *
 148.232 - * 20000916:
 148.233 - *  - fixed bug in png_read_filter_row_mmx_avg(), bpp == 2 case; three errors:
 148.234 - *     - "_ShiftBpp.use = 24;"      should have been   "_ShiftBpp.use = 16;"
 148.235 - *     - "_ShiftRem.use = 40;"      should have been   "_ShiftRem.use = 48;"
 148.236 - *     - "psllq _ShiftRem, %%mm2"   should have been   "psrlq _ShiftRem, %%mm2"
 148.237 - *
 148.238 - * 20010101:
 148.239 - *  - added new png_init_mmx_flags() function (here only because it needs to
 148.240 - *     call mmxsupport(), which should probably become global png_mmxsupport());
 148.241 - *     modified other MMX routines to run conditionally (png_ptr->asm_flags)
 148.242 - *
 148.243 - * 20010103:
 148.244 - *  - renamed mmxsupport() to png_mmx_support(), with auto-set of mmx_supported,
 148.245 - *     and made it public; moved png_init_mmx_flags() to png.c as internal func
 148.246 - *
 148.247 - * 20010104:
 148.248 - *  - removed dependency on png_read_filter_row_c() (C code already duplicated
 148.249 - *     within MMX version of png_read_filter_row()) so no longer necessary to
 148.250 - *     compile it into pngrutil.o
 148.251 - *
 148.252 - * 20010310:
 148.253 - *  - fixed buffer-overrun bug in png_combine_row() C code (non-MMX)
 148.254 - *
 148.255 - * 20020304:
 148.256 - *  - eliminated incorrect use of width_mmx in pixel_bytes == 8 case
 148.257 - *
 148.258 - * 20040724:
 148.259 - *   - more tinkering with clobber list at lines 4529 and 5033, to get
 148.260 - *     it to compile on gcc-3.4.
 148.261 - *
 148.262 - * STILL TO DO:
 148.263 - *     - test png_do_read_interlace() 64-bit case (pixel_bytes == 8)
 148.264 - *     - write MMX code for 48-bit case (pixel_bytes == 6)
 148.265 - *     - figure out what's up with 24-bit case (pixel_bytes == 3):
 148.266 - *        why subtract 8 from width_mmx in the pass 4/5 case?
 148.267 - *        (only width_mmx case) (near line 1606)
 148.268 - *     - rewrite all MMX interlacing code so it's aligned with beginning
 148.269 - *        of the row buffer, not the end (see 19991007 for details)
 148.270 - *     x pick one version of mmxsupport() and get rid of the other
 148.271 - *     - add error messages to any remaining bogus default cases
 148.272 - *     - enable pixel_depth == 8 cases in png_read_filter_row()? (test speed)
 148.273 - *     x add support for runtime enable/disable/query of various MMX routines
 148.274 - */
 148.275 -
 148.276 -#define PNG_INTERNAL
 148.277 -#include "png.h"
 148.278 -
 148.279 -#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) && defined(PNG_USE_PNGGCCRD)
 148.280 -
 148.281 -int PNGAPI png_mmx_support(void);
 148.282 -
 148.283 -#ifdef PNG_USE_LOCAL_ARRAYS
 148.284 -const static int FARDATA png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
 148.285 -const static int FARDATA png_pass_inc[7]   = {8, 8, 4, 4, 2, 2, 1};
 148.286 -const static int FARDATA png_pass_width[7] = {8, 4, 4, 2, 2, 1, 1};
 148.287 -#endif
 148.288 -
 148.289 -#if defined(PNG_MMX_CODE_SUPPORTED)
 148.290 -/* djgpp, Win32, Cygwin, and OS2 add their own underscores to global variables,
 148.291 - * so define them without: */
 148.292 -#if defined(__DJGPP__) || defined(WIN32) || defined(__CYGWIN__) || \
 148.293 -    defined(__OS2__)
 148.294 -#  define _mmx_supported  mmx_supported
 148.295 -#  define _const4         const4
 148.296 -#  define _const6         const6
 148.297 -#  define _mask8_0        mask8_0
 148.298 -#  define _mask16_1       mask16_1
 148.299 -#  define _mask16_0       mask16_0
 148.300 -#  define _mask24_2       mask24_2
 148.301 -#  define _mask24_1       mask24_1
 148.302 -#  define _mask24_0       mask24_0
 148.303 -#  define _mask32_3       mask32_3
 148.304 -#  define _mask32_2       mask32_2
 148.305 -#  define _mask32_1       mask32_1
 148.306 -#  define _mask32_0       mask32_0
 148.307 -#  define _mask48_5       mask48_5
 148.308 -#  define _mask48_4       mask48_4
 148.309 -#  define _mask48_3       mask48_3
 148.310 -#  define _mask48_2       mask48_2
 148.311 -#  define _mask48_1       mask48_1
 148.312 -#  define _mask48_0       mask48_0
 148.313 -#  define _LBCarryMask    LBCarryMask
 148.314 -#  define _HBClearMask    HBClearMask
 148.315 -#  define _ActiveMask     ActiveMask
 148.316 -#  define _ActiveMask2    ActiveMask2
 148.317 -#  define _ActiveMaskEnd  ActiveMaskEnd
 148.318 -#  define _ShiftBpp       ShiftBpp
 148.319 -#  define _ShiftRem       ShiftRem
 148.320 -#ifdef PNG_THREAD_UNSAFE_OK
 148.321 -#  define _unmask         unmask
 148.322 -#  define _FullLength     FullLength
 148.323 -#  define _MMXLength      MMXLength
 148.324 -#  define _dif            dif
 148.325 -#  define _patemp         patemp
 148.326 -#  define _pbtemp         pbtemp
 148.327 -#  define _pctemp         pctemp
 148.328 -#endif
 148.329 -#endif
 148.330 -
 148.331 -
 148.332 -/* These constants are used in the inlined MMX assembly code.
 148.333 -   Ignore gcc's "At top level: defined but not used" warnings. */
 148.334 -
 148.335 -/* GRR 20000706:  originally _unmask was needed only when compiling with -fPIC,
 148.336 - *  since that case uses the %ebx register for indexing the Global Offset Table
 148.337 - *  and there were no other registers available.  But gcc 2.95 and later emit
 148.338 - *  "more than 10 operands in `asm'" errors when %ebx is used to preload unmask
 148.339 - *  in the non-PIC case, so we'll just use the global unconditionally now.
 148.340 - */
 148.341 -#ifdef PNG_THREAD_UNSAFE_OK
 148.342 -static int _unmask;
 148.343 -#endif
 148.344 -
 148.345 -const static unsigned long long _mask8_0  = 0x0102040810204080LL;
 148.346 -
 148.347 -const static unsigned long long _mask16_1 = 0x0101020204040808LL;
 148.348 -const static unsigned long long _mask16_0 = 0x1010202040408080LL;
 148.349 -
 148.350 -const static unsigned long long _mask24_2 = 0x0101010202020404LL;
 148.351 -const static unsigned long long _mask24_1 = 0x0408080810101020LL;
 148.352 -const static unsigned long long _mask24_0 = 0x2020404040808080LL;
 148.353 -
 148.354 -const static unsigned long long _mask32_3 = 0x0101010102020202LL;
 148.355 -const static unsigned long long _mask32_2 = 0x0404040408080808LL;
 148.356 -const static unsigned long long _mask32_1 = 0x1010101020202020LL;
 148.357 -const static unsigned long long _mask32_0 = 0x4040404080808080LL;
 148.358 -
 148.359 -const static unsigned long long _mask48_5 = 0x0101010101010202LL;
 148.360 -const static unsigned long long _mask48_4 = 0x0202020204040404LL;
 148.361 -const static unsigned long long _mask48_3 = 0x0404080808080808LL;
 148.362 -const static unsigned long long _mask48_2 = 0x1010101010102020LL;
 148.363 -const static unsigned long long _mask48_1 = 0x2020202040404040LL;
 148.364 -const static unsigned long long _mask48_0 = 0x4040808080808080LL;
 148.365 -
 148.366 -const static unsigned long long _const4   = 0x0000000000FFFFFFLL;
 148.367 -//const static unsigned long long _const5 = 0x000000FFFFFF0000LL;     // NOT USED
 148.368 -const static unsigned long long _const6   = 0x00000000000000FFLL;
 148.369 -
 148.370 -// These are used in the row-filter routines and should/would be local
 148.371 -//  variables if not for gcc addressing limitations.
 148.372 -// WARNING: Their presence probably defeats the thread safety of libpng.
 148.373 -
 148.374 -#ifdef PNG_THREAD_UNSAFE_OK
 148.375 -static png_uint_32  _FullLength;
 148.376 -static png_uint_32  _MMXLength;
 148.377 -static int          _dif;
 148.378 -static int          _patemp; // temp variables for Paeth routine
 148.379 -static int          _pbtemp;
 148.380 -static int          _pctemp;
 148.381 -#endif
 148.382 -
 148.383 -void /* PRIVATE */
 148.384 -png_squelch_warnings(void)
 148.385 -{
 148.386 -#ifdef PNG_THREAD_UNSAFE_OK
 148.387 -   _dif = _dif;
 148.388 -   _patemp = _patemp;
 148.389 -   _pbtemp = _pbtemp;
 148.390 -   _pctemp = _pctemp;
 148.391 -   _MMXLength = _MMXLength;
 148.392 -#endif
 148.393 -   _const4  = _const4;
 148.394 -   _const6  = _const6;
 148.395 -   _mask8_0  = _mask8_0;
 148.396 -   _mask16_1 = _mask16_1;
 148.397 -   _mask16_0 = _mask16_0;
 148.398 -   _mask24_2 = _mask24_2;
 148.399 -   _mask24_1 = _mask24_1;
 148.400 -   _mask24_0 = _mask24_0;
 148.401 -   _mask32_3 = _mask32_3;
 148.402 -   _mask32_2 = _mask32_2;
 148.403 -   _mask32_1 = _mask32_1;
 148.404 -   _mask32_0 = _mask32_0;
 148.405 -   _mask48_5 = _mask48_5;
 148.406 -   _mask48_4 = _mask48_4;
 148.407 -   _mask48_3 = _mask48_3;
 148.408 -   _mask48_2 = _mask48_2;
 148.409 -   _mask48_1 = _mask48_1;
 148.410 -   _mask48_0 = _mask48_0;
 148.411 -}
 148.412 -#endif /* PNG_MMX_CODE_SUPPORTED */
 148.413 -
 148.414 -
 148.415 -static int _mmx_supported = 2;
 148.416 -
 148.417 -/*===========================================================================*/
 148.418 -/*                                                                           */
 148.419 -/*                       P N G _ C O M B I N E _ R O W                       */
 148.420 -/*                                                                           */
 148.421 -/*===========================================================================*/
 148.422 -
 148.423 -#if defined(PNG_HAVE_MMX_COMBINE_ROW)
 148.424 -
 148.425 -#define BPP2  2
 148.426 -#define BPP3  3 /* bytes per pixel (a.k.a. pixel_bytes) */
 148.427 -#define BPP4  4
 148.428 -#define BPP6  6 /* (defined only to help avoid cut-and-paste errors) */
 148.429 -#define BPP8  8
 148.430 -
 148.431 -/* Combines the row recently read in with the previous row.
 148.432 -   This routine takes care of alpha and transparency if requested.
 148.433 -   This routine also handles the two methods of progressive display
 148.434 -   of interlaced images, depending on the mask value.
 148.435 -   The mask value describes which pixels are to be combined with
 148.436 -   the row.  The pattern always repeats every 8 pixels, so just 8
 148.437 -   bits are needed.  A one indicates the pixel is to be combined; a
 148.438 -   zero indicates the pixel is to be skipped.  This is in addition
 148.439 -   to any alpha or transparency value associated with the pixel.
 148.440 -   If you want all pixels to be combined, pass 0xff (255) in mask. */
 148.441 -
 148.442 -/* Use this routine for the x86 platform - it uses a faster MMX routine
 148.443 -   if the machine supports MMX. */
 148.444 -
 148.445 -void /* PRIVATE */
 148.446 -png_combine_row(png_structp png_ptr, png_bytep row, int mask)
 148.447 -{
 148.448 -   png_debug(1, "in png_combine_row (pnggccrd.c)\n");
 148.449 -
 148.450 -#if defined(PNG_MMX_CODE_SUPPORTED)
 148.451 -   if (_mmx_supported == 2) {
 148.452 -#if !defined(PNG_1_0_X)
 148.453 -       /* this should have happened in png_init_mmx_flags() already */
 148.454 -       png_warning(png_ptr, "asm_flags may not have been initialized");
 148.455 -#endif
 148.456 -       png_mmx_support();
 148.457 -   }
 148.458 -#endif
 148.459 -
 148.460 -   if (mask == 0xff)
 148.461 -   {
 148.462 -      png_debug(2,"mask == 0xff:  doing single png_memcpy()\n");
 148.463 -      png_memcpy(row, png_ptr->row_buf + 1,
 148.464 -       (png_size_t)PNG_ROWBYTES(png_ptr->row_info.pixel_depth,png_ptr->width));
 148.465 -   }
 148.466 -   else   /* (png_combine_row() is never called with mask == 0) */
 148.467 -   {
 148.468 -      switch (png_ptr->row_info.pixel_depth)
 148.469 -      {
 148.470 -         case 1:        /* png_ptr->row_info.pixel_depth */
 148.471 -         {
 148.472 -            png_bytep sp;
 148.473 -            png_bytep dp;
 148.474 -            int s_inc, s_start, s_end;
 148.475 -            int m;
 148.476 -            int shift;
 148.477 -            png_uint_32 i;
 148.478 -
 148.479 -            sp = png_ptr->row_buf + 1;
 148.480 -            dp = row;
 148.481 -            m = 0x80;
 148.482 -#if defined(PNG_READ_PACKSWAP_SUPPORTED)
 148.483 -            if (png_ptr->transformations & PNG_PACKSWAP)
 148.484 -            {
 148.485 -                s_start = 0;
 148.486 -                s_end = 7;
 148.487 -                s_inc = 1;
 148.488 -            }
 148.489 -            else
 148.490 -#endif
 148.491 -            {
 148.492 -                s_start = 7;
 148.493 -                s_end = 0;
 148.494 -                s_inc = -1;
 148.495 -            }
 148.496 -
 148.497 -            shift = s_start;
 148.498 -
 148.499 -            for (i = 0; i < png_ptr->width; i++)
 148.500 -            {
 148.501 -               if (m & mask)
 148.502 -               {
 148.503 -                  int value;
 148.504 -
 148.505 -                  value = (*sp >> shift) & 0x1;
 148.506 -                  *dp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
 148.507 -                  *dp |= (png_byte)(value << shift);
 148.508 -               }
 148.509 -
 148.510 -               if (shift == s_end)
 148.511 -               {
 148.512 -                  shift = s_start;
 148.513 -                  sp++;
 148.514 -                  dp++;
 148.515 -               }
 148.516 -               else
 148.517 -                  shift += s_inc;
 148.518 -
 148.519 -               if (m == 1)
 148.520 -                  m = 0x80;
 148.521 -               else
 148.522 -                  m >>= 1;
 148.523 -            }
 148.524 -            break;
 148.525 -         }
 148.526 -
 148.527 -         case 2:        /* png_ptr->row_info.pixel_depth */
 148.528 -         {
 148.529 -            png_bytep sp;
 148.530 -            png_bytep dp;
 148.531 -            int s_start, s_end, s_inc;
 148.532 -            int m;
 148.533 -            int shift;
 148.534 -            png_uint_32 i;
 148.535 -            int value;
 148.536 -
 148.537 -            sp = png_ptr->row_buf + 1;
 148.538 -            dp = row;
 148.539 -            m = 0x80;
 148.540 -#if defined(PNG_READ_PACKSWAP_SUPPORTED)
 148.541 -            if (png_ptr->transformations & PNG_PACKSWAP)
 148.542 -            {
 148.543 -               s_start = 0;
 148.544 -               s_end = 6;
 148.545 -               s_inc = 2;
 148.546 -            }
 148.547 -            else
 148.548 -#endif
 148.549 -            {
 148.550 -               s_start = 6;
 148.551 -               s_end = 0;
 148.552 -               s_inc = -2;
 148.553 -            }
 148.554 -
 148.555 -            shift = s_start;
 148.556 -
 148.557 -            for (i = 0; i < png_ptr->width; i++)
 148.558 -            {
 148.559 -               if (m & mask)
 148.560 -               {
 148.561 -                  value = (*sp >> shift) & 0x3;
 148.562 -                  *dp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
 148.563 -                  *dp |= (png_byte)(value << shift);
 148.564 -               }
 148.565 -
 148.566 -               if (shift == s_end)
 148.567 -               {
 148.568 -                  shift = s_start;
 148.569 -                  sp++;
 148.570 -                  dp++;
 148.571 -               }
 148.572 -               else
 148.573 -                  shift += s_inc;
 148.574 -               if (m == 1)
 148.575 -                  m = 0x80;
 148.576 -               else
 148.577 -                  m >>= 1;
 148.578 -            }
 148.579 -            break;
 148.580 -         }
 148.581 -
 148.582 -         case 4:        /* png_ptr->row_info.pixel_depth */
 148.583 -         {
 148.584 -            png_bytep sp;
 148.585 -            png_bytep dp;
 148.586 -            int s_start, s_end, s_inc;
 148.587 -            int m;
 148.588 -            int shift;
 148.589 -            png_uint_32 i;
 148.590 -            int value;
 148.591 -
 148.592 -            sp = png_ptr->row_buf + 1;
 148.593 -            dp = row;
 148.594 -            m = 0x80;
 148.595 -#if defined(PNG_READ_PACKSWAP_SUPPORTED)
 148.596 -            if (png_ptr->transformations & PNG_PACKSWAP)
 148.597 -            {
 148.598 -               s_start = 0;
 148.599 -               s_end = 4;
 148.600 -               s_inc = 4;
 148.601 -            }
 148.602 -            else
 148.603 -#endif
 148.604 -            {
 148.605 -               s_start = 4;
 148.606 -               s_end = 0;
 148.607 -               s_inc = -4;
 148.608 -            }
 148.609 -            shift = s_start;
 148.610 -
 148.611 -            for (i = 0; i < png_ptr->width; i++)
 148.612 -            {
 148.613 -               if (m & mask)
 148.614 -               {
 148.615 -                  value = (*sp >> shift) & 0xf;
 148.616 -                  *dp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
 148.617 -                  *dp |= (png_byte)(value << shift);
 148.618 -               }
 148.619 -
 148.620 -               if (shift == s_end)
 148.621 -               {
 148.622 -                  shift = s_start;
 148.623 -                  sp++;
 148.624 -                  dp++;
 148.625 -               }
 148.626 -               else
 148.627 -                  shift += s_inc;
 148.628 -               if (m == 1)
 148.629 -                  m = 0x80;
 148.630 -               else
 148.631 -                  m >>= 1;
 148.632 -            }
 148.633 -            break;
 148.634 -         }
 148.635 -
 148.636 -         case 8:        /* png_ptr->row_info.pixel_depth */
 148.637 -         {
 148.638 -            png_bytep srcptr;
 148.639 -            png_bytep dstptr;
 148.640 -
 148.641 -#if defined(PNG_MMX_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK)
 148.642 -#if !defined(PNG_1_0_X)
 148.643 -            if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)
 148.644 -                /* && _mmx_supported */ )
 148.645 -#else
 148.646 -            if (_mmx_supported)
 148.647 -#endif
 148.648 -            {
 148.649 -               png_uint_32 len;
 148.650 -               int diff;
 148.651 -               int dummy_value_a;   // fix 'forbidden register spilled' error
 148.652 -               int dummy_value_d;
 148.653 -               int dummy_value_c;
 148.654 -               int dummy_value_S;
 148.655 -               int dummy_value_D;
 148.656 -               _unmask = ~mask;            // global variable for -fPIC version
 148.657 -               srcptr = png_ptr->row_buf + 1;
 148.658 -               dstptr = row;
 148.659 -               len  = png_ptr->width &~7;  // reduce to multiple of 8
 148.660 -               diff = (int) (png_ptr->width & 7);  // amount lost
 148.661 -
 148.662 -               __asm__ __volatile__ (
 148.663 -                  "movd      _unmask, %%mm7  \n\t" // load bit pattern
 148.664 -                  "psubb     %%mm6, %%mm6    \n\t" // zero mm6
 148.665 -                  "punpcklbw %%mm7, %%mm7    \n\t"
 148.666 -                  "punpcklwd %%mm7, %%mm7    \n\t"
 148.667 -                  "punpckldq %%mm7, %%mm7    \n\t" // fill reg with 8 masks
 148.668 -
 148.669 -                  "movq      _mask8_0, %%mm0 \n\t"
 148.670 -                  "pand      %%mm7, %%mm0    \n\t" // nonzero if keep byte
 148.671 -                  "pcmpeqb   %%mm6, %%mm0    \n\t" // zeros->1s, v versa
 148.672 -
 148.673 -// preload        "movl      len, %%ecx      \n\t" // load length of line
 148.674 -// preload        "movl      srcptr, %%esi   \n\t" // load source
 148.675 -// preload        "movl      dstptr, %%edi   \n\t" // load dest
 148.676 -
 148.677 -                  "cmpl      $0, %%ecx       \n\t" // len == 0 ?
 148.678 -                  "je        mainloop8end    \n\t"
 148.679 -
 148.680 -                "mainloop8:                  \n\t"
 148.681 -                  "movq      (%%esi), %%mm4  \n\t" // *srcptr
 148.682 -                  "pand      %%mm0, %%mm4    \n\t"
 148.683 -                  "movq      %%mm0, %%mm6    \n\t"
 148.684 -                  "pandn     (%%edi), %%mm6  \n\t" // *dstptr
 148.685 -                  "por       %%mm6, %%mm4    \n\t"
 148.686 -                  "movq      %%mm4, (%%edi)  \n\t"
 148.687 -                  "addl      $8, %%esi       \n\t" // inc by 8 bytes processed
 148.688 -                  "addl      $8, %%edi       \n\t"
 148.689 -                  "subl      $8, %%ecx       \n\t" // dec by 8 pixels processed
 148.690 -                  "ja        mainloop8       \n\t"
 148.691 -
 148.692 -                "mainloop8end:               \n\t"
 148.693 -// preload        "movl      diff, %%ecx     \n\t" // (diff is in eax)
 148.694 -                  "movl      %%eax, %%ecx    \n\t"
 148.695 -                  "cmpl      $0, %%ecx       \n\t"
 148.696 -                  "jz        end8            \n\t"
 148.697 -// preload        "movl      mask, %%edx     \n\t"
 148.698 -                  "sall      $24, %%edx      \n\t" // make low byte, high byte
 148.699 -
 148.700 -                "secondloop8:                \n\t"
 148.701 -                  "sall      %%edx           \n\t" // move high bit to CF
 148.702 -                  "jnc       skip8           \n\t" // if CF = 0
 148.703 -                  "movb      (%%esi), %%al   \n\t"
 148.704 -                  "movb      %%al, (%%edi)   \n\t"
 148.705 -
 148.706 -                "skip8:                      \n\t"
 148.707 -                  "incl      %%esi           \n\t"
 148.708 -                  "incl      %%edi           \n\t"
 148.709 -                  "decl      %%ecx           \n\t"
 148.710 -                  "jnz       secondloop8     \n\t"
 148.711 -
 148.712 -                "end8:                       \n\t"
 148.713 -                  "EMMS                      \n\t"  // DONE
 148.714 -
 148.715 -                  : "=a" (dummy_value_a),           // output regs (dummy)
 148.716 -                    "=d" (dummy_value_d),
 148.717 -                    "=c" (dummy_value_c),
 148.718 -                    "=S" (dummy_value_S),
 148.719 -                    "=D" (dummy_value_D)
 148.720 -
 148.721 -                  : "3" (srcptr),      // esi       // input regs
 148.722 -                    "4" (dstptr),      // edi
 148.723 -                    "0" (diff),        // eax
 148.724 -// was (unmask)     "b"    RESERVED    // ebx       // Global Offset Table idx
 148.725 -                    "2" (len),         // ecx
 148.726 -                    "1" (mask)         // edx
 148.727 -
 148.728 -#if 0  /* MMX regs (%mm0, etc.) not supported by gcc 2.7.2.3 or egcs 1.1 */
 148.729 -                  : "%mm0", "%mm4", "%mm6", "%mm7"  // clobber list
 148.730 -#endif
 148.731 -               );
 148.732 -            }
 148.733 -            else /* mmx _not supported - Use modified C routine */
 148.734 -#endif /* PNG_MMX_CODE_SUPPORTED */
 148.735 -            {
 148.736 -               register png_uint_32 i;
 148.737 -               png_uint_32 initial_val = png_pass_start[png_ptr->pass];
 148.738 -                 /* png.c:  png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; */
 148.739 -               register int stride = png_pass_inc[png_ptr->pass];
 148.740 -                 /* png.c:  png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; */
 148.741 -               register int rep_bytes = png_pass_width[png_ptr->pass];
 148.742 -                 /* png.c:  png_pass_width[] = {8, 4, 4, 2, 2, 1, 1}; */
 148.743 -               png_uint_32 len = png_ptr->width &~7;  /* reduce to mult. of 8 */
 148.744 -               int diff = (int) (png_ptr->width & 7); /* amount lost */
 148.745 -               register png_uint_32 final_val = len;  /* GRR bugfix */
 148.746 -
 148.747 -               srcptr = png_ptr->row_buf + 1 + initial_val;
 148.748 -               dstptr = row + initial_val;
 148.749 -
 148.750 -               for (i = initial_val; i < final_val; i += stride)
 148.751 -               {
 148.752 -                  png_memcpy(dstptr, srcptr, rep_bytes);
 148.753 -                  srcptr += stride;
 148.754 -                  dstptr += stride;
 148.755 -               }
 148.756 -               if (diff)  /* number of leftover pixels:  3 for pngtest */
 148.757 -               {
 148.758 -                  final_val+=diff /* *BPP1 */ ;
 148.759 -                  for (; i < final_val; i += stride)
 148.760 -                  {
 148.761 -                     if (rep_bytes > (int)(final_val-i))
 148.762 -                        rep_bytes = (int)(final_val-i);
 148.763 -                     png_memcpy(dstptr, srcptr, rep_bytes);
 148.764 -                     srcptr += stride;
 148.765 -                     dstptr += stride;
 148.766 -                  }
 148.767 -               }
 148.768 -
 148.769 -            } /* end of else (_mmx_supported) */
 148.770 -
 148.771 -            break;
 148.772 -         }       /* end 8 bpp */
 148.773 -
 148.774 -         case 16:       /* png_ptr->row_info.pixel_depth */
 148.775 -         {
 148.776 -            png_bytep srcptr;
 148.777 -            png_bytep dstptr;
 148.778 -
 148.779 -#if defined(PNG_MMX_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK)
 148.780 -#if !defined(PNG_1_0_X)
 148.781 -            if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)
 148.782 -                /* && _mmx_supported */ )
 148.783 -#else
 148.784 -            if (_mmx_supported)
 148.785 -#endif
 148.786 -            {
 148.787 -               png_uint_32 len;
 148.788 -               int diff;
 148.789 -               int dummy_value_a;   // fix 'forbidden register spilled' error
 148.790 -               int dummy_value_d;
 148.791 -               int dummy_value_c;
 148.792 -               int dummy_value_S;
 148.793 -               int dummy_value_D;
 148.794 -               _unmask = ~mask;            // global variable for -fPIC version
 148.795 -               srcptr = png_ptr->row_buf + 1;
 148.796 -               dstptr = row;
 148.797 -               len  = png_ptr->width &~7;  // reduce to multiple of 8
 148.798 -               diff = (int) (png_ptr->width & 7); // amount lost //
 148.799 -
 148.800 -               __asm__ __volatile__ (
 148.801 -                  "movd      _unmask, %%mm7   \n\t" // load bit pattern
 148.802 -                  "psubb     %%mm6, %%mm6     \n\t" // zero mm6
 148.803 -                  "punpcklbw %%mm7, %%mm7     \n\t"
 148.804 -                  "punpcklwd %%mm7, %%mm7     \n\t"
 148.805 -                  "punpckldq %%mm7, %%mm7     \n\t" // fill reg with 8 masks
 148.806 -
 148.807 -                  "movq      _mask16_0, %%mm0 \n\t"
 148.808 -                  "movq      _mask16_1, %%mm1 \n\t"
 148.809 -
 148.810 -                  "pand      %%mm7, %%mm0     \n\t"
 148.811 -                  "pand      %%mm7, %%mm1     \n\t"
 148.812 -
 148.813 -                  "pcmpeqb   %%mm6, %%mm0     \n\t"
 148.814 -                  "pcmpeqb   %%mm6, %%mm1     \n\t"
 148.815 -
 148.816 -// preload        "movl      len, %%ecx       \n\t" // load length of line
 148.817 -// preload        "movl      srcptr, %%esi    \n\t" // load source
 148.818 -// preload        "movl      dstptr, %%edi    \n\t" // load dest
 148.819 -
 148.820 -                  "cmpl      $0, %%ecx        \n\t"
 148.821 -                  "jz        mainloop16end    \n\t"
 148.822 -
 148.823 -                "mainloop16:                  \n\t"
 148.824 -                  "movq      (%%esi), %%mm4   \n\t"
 148.825 -                  "pand      %%mm0, %%mm4     \n\t"
 148.826 -                  "movq      %%mm0, %%mm6     \n\t"
 148.827 -                  "movq      (%%edi), %%mm7   \n\t"
 148.828 -                  "pandn     %%mm7, %%mm6     \n\t"
 148.829 -                  "por       %%mm6, %%mm4     \n\t"
 148.830 -                  "movq      %%mm4, (%%edi)   \n\t"
 148.831 -
 148.832 -                  "movq      8(%%esi), %%mm5  \n\t"
 148.833 -                  "pand      %%mm1, %%mm5     \n\t"
 148.834 -                  "movq      %%mm1, %%mm7     \n\t"
 148.835 -                  "movq      8(%%edi), %%mm6  \n\t"
 148.836 -                  "pandn     %%mm6, %%mm7     \n\t"
 148.837 -                  "por       %%mm7, %%mm5     \n\t"
 148.838 -                  "movq      %%mm5, 8(%%edi)  \n\t"
 148.839 -
 148.840 -                  "addl      $16, %%esi       \n\t" // inc by 16 bytes processed
 148.841 -                  "addl      $16, %%edi       \n\t"
 148.842 -                  "subl      $8, %%ecx        \n\t" // dec by 8 pixels processed
 148.843 -                  "ja        mainloop16       \n\t"
 148.844 -
 148.845 -                "mainloop16end:               \n\t"
 148.846 -// preload        "movl      diff, %%ecx      \n\t" // (diff is in eax)
 148.847 -                  "movl      %%eax, %%ecx     \n\t"
 148.848 -                  "cmpl      $0, %%ecx        \n\t"
 148.849 -                  "jz        end16            \n\t"
 148.850 -// preload        "movl      mask, %%edx      \n\t"
 148.851 -                  "sall      $24, %%edx       \n\t" // make low byte, high byte
 148.852 -
 148.853 -                "secondloop16:                \n\t"
 148.854 -                  "sall      %%edx            \n\t" // move high bit to CF
 148.855 -                  "jnc       skip16           \n\t" // if CF = 0
 148.856 -                  "movw      (%%esi), %%ax    \n\t"
 148.857 -                  "movw      %%ax, (%%edi)    \n\t"
 148.858 -
 148.859 -                "skip16:                      \n\t"
 148.860 -                  "addl      $2, %%esi        \n\t"
 148.861 -                  "addl      $2, %%edi        \n\t"
 148.862 -                  "decl      %%ecx            \n\t"
 148.863 -                  "jnz       secondloop16     \n\t"
 148.864 -
 148.865 -                "end16:                       \n\t"
 148.866 -                  "EMMS                       \n\t" // DONE
 148.867 -
 148.868 -                  : "=a" (dummy_value_a),           // output regs (dummy)
 148.869 -                    "=c" (dummy_value_c),
 148.870 -                    "=d" (dummy_value_d),
 148.871 -                    "=S" (dummy_value_S),
 148.872 -                    "=D" (dummy_value_D)
 148.873 -
 148.874 -                  : "0" (diff),        // eax       // input regs
 148.875 -// was (unmask)     " "    RESERVED    // ebx       // Global Offset Table idx
 148.876 -                    "1" (len),         // ecx
 148.877 -                    "2" (mask),        // edx
 148.878 -                    "3" (srcptr),      // esi
 148.879 -                    "4" (dstptr)       // edi
 148.880 -
 148.881 -#if 0  /* MMX regs (%mm0, etc.) not supported by gcc 2.7.2.3 or egcs 1.1 */
 148.882 -                  : "%mm0", "%mm1", "%mm4"          // clobber list
 148.883 -                  , "%mm5", "%mm6", "%mm7"
 148.884 -#endif
 148.885 -               );
 148.886 -            }
 148.887 -            else /* mmx _not supported - Use modified C routine */
 148.888 -#endif /* PNG_MMX_CODE_SUPPORTED */
 148.889 -            {
 148.890 -               register png_uint_32 i;
 148.891 -               png_uint_32 initial_val = BPP2 * png_pass_start[png_ptr->pass];
 148.892 -                 /* png.c:  png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; */
 148.893 -               register int stride = BPP2 * png_pass_inc[png_ptr->pass];
 148.894 -                 /* png.c:  png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; */
 148.895 -               register int rep_bytes = BPP2 * png_pass_width[png_ptr->pass];
 148.896 -                 /* png.c:  png_pass_width[] = {8, 4, 4, 2, 2, 1, 1}; */
 148.897 -               png_uint_32 len = png_ptr->width &~7;  /* reduce to mult. of 8 */
 148.898 -               int diff = (int) (png_ptr->width & 7); /* amount lost */
 148.899 -               register png_uint_32 final_val = BPP2 * len;   /* GRR bugfix */
 148.900 -
 148.901 -               srcptr = png_ptr->row_buf + 1 + initial_val;
 148.902 -               dstptr = row + initial_val;
 148.903 -
 148.904 -               for (i = initial_val; i < final_val; i += stride)
 148.905 -               {
 148.906 -                  png_memcpy(dstptr, srcptr, rep_bytes);
 148.907 -                  srcptr += stride;
 148.908 -                  dstptr += stride;
 148.909 -               }
 148.910 -               if (diff)  /* number of leftover pixels:  3 for pngtest */
 148.911 -               {
 148.912 -                  final_val+=diff*BPP2;
 148.913 -                  for (; i < final_val; i += stride)
 148.914 -                  {
 148.915 -                     if (rep_bytes > (int)(final_val-i))
 148.916 -                        rep_bytes = (int)(final_val-i);
 148.917 -                     png_memcpy(dstptr, srcptr, rep_bytes);
 148.918 -                     srcptr += stride;
 148.919 -                     dstptr += stride;
 148.920 -                  }
 148.921 -               }
 148.922 -            } /* end of else (_mmx_supported) */
 148.923 -
 148.924 -            break;
 148.925 -         }       /* end 16 bpp */
 148.926 -
 148.927 -         case 24:       /* png_ptr->row_info.pixel_depth */
 148.928 -         {
 148.929 -            png_bytep srcptr;
 148.930 -            png_bytep dstptr;
 148.931 -
 148.932 -#if defined(PNG_MMX_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK)
 148.933 -#if !defined(PNG_1_0_X)
 148.934 -            if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)
 148.935 -                /* && _mmx_supported */ )
 148.936 -#else
 148.937 -            if (_mmx_supported)
 148.938 -#endif
 148.939 -            {
 148.940 -               png_uint_32 len;
 148.941 -               int diff;
 148.942 -               int dummy_value_a;   // fix 'forbidden register spilled' error
 148.943 -               int dummy_value_d;
 148.944 -               int dummy_value_c;
 148.945 -               int dummy_value_S;
 148.946 -               int dummy_value_D;
 148.947 -               _unmask = ~mask;            // global variable for -fPIC version
 148.948 -               srcptr = png_ptr->row_buf + 1;
 148.949 -               dstptr = row;
 148.950 -               len  = png_ptr->width &~7;  // reduce to multiple of 8
 148.951 -               diff = (int) (png_ptr->width & 7); // amount lost //
 148.952 -
 148.953 -               __asm__ __volatile__ (
 148.954 -                  "movd      _unmask, %%mm7   \n\t" // load bit pattern
 148.955 -                  "psubb     %%mm6, %%mm6     \n\t" // zero mm6
 148.956 -                  "punpcklbw %%mm7, %%mm7     \n\t"
 148.957 -                  "punpcklwd %%mm7, %%mm7     \n\t"
 148.958 -                  "punpckldq %%mm7, %%mm7     \n\t" // fill reg with 8 masks
 148.959 -
 148.960 -                  "movq      _mask24_0, %%mm0 \n\t"
 148.961 -                  "movq      _mask24_1, %%mm1 \n\t"
 148.962 -                  "movq      _mask24_2, %%mm2 \n\t"
 148.963 -
 148.964 -                  "pand      %%mm7, %%mm0     \n\t"
 148.965 -                  "pand      %%mm7, %%mm1     \n\t"
 148.966 -                  "pand      %%mm7, %%mm2     \n\t"
 148.967 -
 148.968 -                  "pcmpeqb   %%mm6, %%mm0     \n\t"
 148.969 -                  "pcmpeqb   %%mm6, %%mm1     \n\t"
 148.970 -                  "pcmpeqb   %%mm6, %%mm2     \n\t"
 148.971 -
 148.972 -// preload        "movl      len, %%ecx       \n\t" // load length of line
 148.973 -// preload        "movl      srcptr, %%esi    \n\t" // load source
 148.974 -// preload        "movl      dstptr, %%edi    \n\t" // load dest
 148.975 -
 148.976 -                  "cmpl      $0, %%ecx        \n\t"
 148.977 -                  "jz        mainloop24end    \n\t"
 148.978 -
 148.979 -                "mainloop24:                  \n\t"
 148.980 -                  "movq      (%%esi), %%mm4   \n\t"
 148.981 -                  "pand      %%mm0, %%mm4     \n\t"
 148.982 -                  "movq      %%mm0, %%mm6     \n\t"
 148.983 -                  "movq      (%%edi), %%mm7   \n\t"
 148.984 -                  "pandn     %%mm7, %%mm6     \n\t"
 148.985 -                  "por       %%mm6, %%mm4     \n\t"
 148.986 -                  "movq      %%mm4, (%%edi)   \n\t"
 148.987 -
 148.988 -                  "movq      8(%%esi), %%mm5  \n\t"
 148.989 -                  "pand      %%mm1, %%mm5     \n\t"
 148.990 -                  "movq      %%mm1, %%mm7     \n\t"
 148.991 -                  "movq      8(%%edi), %%mm6  \n\t"
 148.992 -                  "pandn     %%mm6, %%mm7     \n\t"
 148.993 -                  "por       %%mm7, %%mm5     \n\t"
 148.994 -                  "movq      %%mm5, 8(%%edi)  \n\t"
 148.995 -
 148.996 -                  "movq      16(%%esi), %%mm6 \n\t"
 148.997 -                  "pand      %%mm2, %%mm6     \n\t"
 148.998 -                  "movq      %%mm2, %%mm4     \n\t"
 148.999 -                  "movq      16(%%edi), %%mm7 \n\t"
148.1000 -                  "pandn     %%mm7, %%mm4     \n\t"
148.1001 -                  "por       %%mm4, %%mm6     \n\t"
148.1002 -                  "movq      %%mm6, 16(%%edi) \n\t"
148.1003 -
148.1004 -                  "addl      $24, %%esi       \n\t" // inc by 24 bytes processed
148.1005 -                  "addl      $24, %%edi       \n\t"
148.1006 -                  "subl      $8, %%ecx        \n\t" // dec by 8 pixels processed
148.1007 -
148.1008 -                  "ja        mainloop24       \n\t"
148.1009 -
148.1010 -                "mainloop24end:               \n\t"
148.1011 -// preload        "movl      diff, %%ecx      \n\t" // (diff is in eax)
148.1012 -                  "movl      %%eax, %%ecx     \n\t"
148.1013 -                  "cmpl      $0, %%ecx        \n\t"
148.1014 -                  "jz        end24            \n\t"
148.1015 -// preload        "movl      mask, %%edx      \n\t"
148.1016 -                  "sall      $24, %%edx       \n\t" // make low byte, high byte
148.1017 -
148.1018 -                "secondloop24:                \n\t"
148.1019 -                  "sall      %%edx            \n\t" // move high bit to CF
148.1020 -                  "jnc       skip24           \n\t" // if CF = 0
148.1021 -                  "movw      (%%esi), %%ax    \n\t"
148.1022 -                  "movw      %%ax, (%%edi)    \n\t"
148.1023 -                  "xorl      %%eax, %%eax     \n\t"
148.1024 -                  "movb      2(%%esi), %%al   \n\t"
148.1025 -                  "movb      %%al, 2(%%edi)   \n\t"
148.1026 -
148.1027 -                "skip24:                      \n\t"
148.1028 -                  "addl      $3, %%esi        \n\t"
148.1029 -                  "addl      $3, %%edi        \n\t"
148.1030 -                  "decl      %%ecx            \n\t"
148.1031 -                  "jnz       secondloop24     \n\t"
148.1032 -
148.1033 -                "end24:                       \n\t"
148.1034 -                  "EMMS                       \n\t" // DONE
148.1035 -
148.1036 -                  : "=a" (dummy_value_a),           // output regs (dummy)
148.1037 -                    "=d" (dummy_value_d),
148.1038 -                    "=c" (dummy_value_c),
148.1039 -                    "=S" (dummy_value_S),
148.1040 -                    "=D" (dummy_value_D)
148.1041 -
148.1042 -                  : "3" (srcptr),      // esi       // input regs
148.1043 -                    "4" (dstptr),      // edi
148.1044 -                    "0" (diff),        // eax
148.1045 -// was (unmask)     "b"    RESERVED    // ebx       // Global Offset Table idx
148.1046 -                    "2" (len),         // ecx
148.1047 -                    "1" (mask)         // edx
148.1048 -
148.1049 -#if 0  /* MMX regs (%mm0, etc.) not supported by gcc 2.7.2.3 or egcs 1.1 */
148.1050 -                  : "%mm0", "%mm1", "%mm2"          // clobber list
148.1051 -                  , "%mm4", "%mm5", "%mm6", "%mm7"
148.1052 -#endif
148.1053 -               );
148.1054 -            }
148.1055 -            else /* mmx _not supported - Use modified C routine */
148.1056 -#endif /* PNG_MMX_CODE_SUPPORTED */
148.1057 -            {
148.1058 -               register png_uint_32 i;
148.1059 -               png_uint_32 initial_val = BPP3 * png_pass_start[png_ptr->pass];
148.1060 -                 /* png.c:  png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; */
148.1061 -               register int stride = BPP3 * png_pass_inc[png_ptr->pass];
148.1062 -                 /* png.c:  png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; */
148.1063 -               register int rep_bytes = BPP3 * png_pass_width[png_ptr->pass];
148.1064 -                 /* png.c:  png_pass_width[] = {8, 4, 4, 2, 2, 1, 1}; */
148.1065 -               png_uint_32 len = png_ptr->width &~7;  /* reduce to mult. of 8 */
148.1066 -               int diff = (int) (png_ptr->width & 7); /* amount lost */
148.1067 -               register png_uint_32 final_val = BPP3 * len;   /* GRR bugfix */
148.1068 -
148.1069 -               srcptr = png_ptr->row_buf + 1 + initial_val;
148.1070 -               dstptr = row + initial_val;
148.1071 -
148.1072 -               for (i = initial_val; i < final_val; i += stride)
148.1073 -               {
148.1074 -                  png_memcpy(dstptr, srcptr, rep_bytes);
148.1075 -                  srcptr += stride;
148.1076 -                  dstptr += stride;
148.1077 -               }
148.1078 -               if (diff)  /* number of leftover pixels:  3 for pngtest */
148.1079 -               {
148.1080 -                  final_val+=diff*BPP3;
148.1081 -                  for (; i < final_val; i += stride)
148.1082 -                  {
148.1083 -                     if (rep_bytes > (int)(final_val-i))
148.1084 -                        rep_bytes = (int)(final_val-i);
148.1085 -                     png_memcpy(dstptr, srcptr, rep_bytes);
148.1086 -                     srcptr += stride;
148.1087 -                     dstptr += stride;
148.1088 -                  }
148.1089 -               }
148.1090 -            } /* end of else (_mmx_supported) */
148.1091 -
148.1092 -            break;
148.1093 -         }       /* end 24 bpp */
148.1094 -
148.1095 -         case 32:       /* png_ptr->row_info.pixel_depth */
148.1096 -         {
148.1097 -            png_bytep srcptr;
148.1098 -            png_bytep dstptr;
148.1099 -
148.1100 -#if defined(PNG_MMX_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK)
148.1101 -#if !defined(PNG_1_0_X)
148.1102 -            if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)
148.1103 -                /* && _mmx_supported */ )
148.1104 -#else
148.1105 -            if (_mmx_supported)
148.1106 -#endif
148.1107 -            {
148.1108 -               png_uint_32 len;
148.1109 -               int diff;
148.1110 -               int dummy_value_a;   // fix 'forbidden register spilled' error
148.1111 -               int dummy_value_d;
148.1112 -               int dummy_value_c;
148.1113 -               int dummy_value_S;
148.1114 -               int dummy_value_D;
148.1115 -               _unmask = ~mask;            // global variable for -fPIC version
148.1116 -               srcptr = png_ptr->row_buf + 1;
148.1117 -               dstptr = row;
148.1118 -               len  = png_ptr->width &~7;  // reduce to multiple of 8
148.1119 -               diff = (int) (png_ptr->width & 7); // amount lost //
148.1120 -
148.1121 -               __asm__ __volatile__ (
148.1122 -                  "movd      _unmask, %%mm7   \n\t" // load bit pattern
148.1123 -                  "psubb     %%mm6, %%mm6     \n\t" // zero mm6
148.1124 -                  "punpcklbw %%mm7, %%mm7     \n\t"
148.1125 -                  "punpcklwd %%mm7, %%mm7     \n\t"
148.1126 -                  "punpckldq %%mm7, %%mm7     \n\t" // fill reg with 8 masks
148.1127 -
148.1128 -                  "movq      _mask32_0, %%mm0 \n\t"
148.1129 -                  "movq      _mask32_1, %%mm1 \n\t"
148.1130 -                  "movq      _mask32_2, %%mm2 \n\t"
148.1131 -                  "movq      _mask32_3, %%mm3 \n\t"
148.1132 -
148.1133 -                  "pand      %%mm7, %%mm0     \n\t"
148.1134 -                  "pand      %%mm7, %%mm1     \n\t"
148.1135 -                  "pand      %%mm7, %%mm2     \n\t"
148.1136 -                  "pand      %%mm7, %%mm3     \n\t"
148.1137 -
148.1138 -                  "pcmpeqb   %%mm6, %%mm0     \n\t"
148.1139 -                  "pcmpeqb   %%mm6, %%mm1     \n\t"
148.1140 -                  "pcmpeqb   %%mm6, %%mm2     \n\t"
148.1141 -                  "pcmpeqb   %%mm6, %%mm3     \n\t"
148.1142 -
148.1143 -// preload        "movl      len, %%ecx       \n\t" // load length of line
148.1144 -// preload        "movl      srcptr, %%esi    \n\t" // load source
148.1145 -// preload        "movl      dstptr, %%edi    \n\t" // load dest
148.1146 -
148.1147 -                  "cmpl      $0, %%ecx        \n\t" // lcr
148.1148 -                  "jz        mainloop32end    \n\t"
148.1149 -
148.1150 -                "mainloop32:                  \n\t"
148.1151 -                  "movq      (%%esi), %%mm4   \n\t"
148.1152 -                  "pand      %%mm0, %%mm4     \n\t"
148.1153 -                  "movq      %%mm0, %%mm6     \n\t"
148.1154 -                  "movq      (%%edi), %%mm7   \n\t"
148.1155 -                  "pandn     %%mm7, %%mm6     \n\t"
148.1156 -                  "por       %%mm6, %%mm4     \n\t"
148.1157 -                  "movq      %%mm4, (%%edi)   \n\t"
148.1158 -
148.1159 -                  "movq      8(%%esi), %%mm5  \n\t"
148.1160 -                  "pand      %%mm1, %%mm5     \n\t"
148.1161 -                  "movq      %%mm1, %%mm7     \n\t"
148.1162 -                  "movq      8(%%edi), %%mm6  \n\t"
148.1163 -                  "pandn     %%mm6, %%mm7     \n\t"
148.1164 -                  "por       %%mm7, %%mm5     \n\t"
148.1165 -                  "movq      %%mm5, 8(%%edi)  \n\t"
148.1166 -
148.1167 -                  "movq      16(%%esi), %%mm6 \n\t"
148.1168 -                  "pand      %%mm2, %%mm6     \n\t"
148.1169 -                  "movq      %%mm2, %%mm4     \n\t"
148.1170 -                  "movq      16(%%edi), %%mm7 \n\t"
148.1171 -                  "pandn     %%mm7, %%mm4     \n\t"
148.1172 -                  "por       %%mm4, %%mm6     \n\t"
148.1173 -                  "movq      %%mm6, 16(%%edi) \n\t"
148.1174 -
148.1175 -                  "movq      24(%%esi), %%mm7 \n\t"
148.1176 -                  "pand      %%mm3, %%mm7     \n\t"
148.1177 -                  "movq      %%mm3, %%mm5     \n\t"
148.1178 -                  "movq      24(%%edi), %%mm4 \n\t"
148.1179 -                  "pandn     %%mm4, %%mm5     \n\t"
148.1180 -                  "por       %%mm5, %%mm7     \n\t"
148.1181 -                  "movq      %%mm7, 24(%%edi) \n\t"
148.1182 -
148.1183 -                  "addl      $32, %%esi       \n\t" // inc by 32 bytes processed
148.1184 -                  "addl      $32, %%edi       \n\t"
148.1185 -                  "subl      $8, %%ecx        \n\t" // dec by 8 pixels processed
148.1186 -                  "ja        mainloop32       \n\t"
148.1187 -
148.1188 -                "mainloop32end:               \n\t"
148.1189 -// preload        "movl      diff, %%ecx      \n\t" // (diff is in eax)
148.1190 -                  "movl      %%eax, %%ecx     \n\t"
148.1191 -                  "cmpl      $0, %%ecx        \n\t"
148.1192 -                  "jz        end32            \n\t"
148.1193 -// preload        "movl      mask, %%edx      \n\t"
148.1194 -                  "sall      $24, %%edx       \n\t" // low byte => high byte
148.1195 -
148.1196 -                "secondloop32:                \n\t"
148.1197 -                  "sall      %%edx            \n\t" // move high bit to CF
148.1198 -                  "jnc       skip32           \n\t" // if CF = 0
148.1199 -                  "movl      (%%esi), %%eax   \n\t"
148.1200 -                  "movl      %%eax, (%%edi)   \n\t"
148.1201 -
148.1202 -                "skip32:                      \n\t"
148.1203 -                  "addl      $4, %%esi        \n\t"
148.1204 -                  "addl      $4, %%edi        \n\t"
148.1205 -                  "decl      %%ecx            \n\t"
148.1206 -                  "jnz       secondloop32     \n\t"
148.1207 -
148.1208 -                "end32:                       \n\t"
148.1209 -                  "EMMS                       \n\t" // DONE
148.1210 -
148.1211 -                  : "=a" (dummy_value_a),           // output regs (dummy)
148.1212 -                    "=d" (dummy_value_d),
148.1213 -                    "=c" (dummy_value_c),
148.1214 -                    "=S" (dummy_value_S),
148.1215 -                    "=D" (dummy_value_D)
148.1216 -
148.1217 -                  : "3" (srcptr),      // esi       // input regs
148.1218 -                    "4" (dstptr),      // edi
148.1219 -                    "0" (diff),        // eax
148.1220 -// was (unmask)     "b"    RESERVED    // ebx       // Global Offset Table idx
148.1221 -                    "2" (len),         // ecx
148.1222 -                    "1" (mask)         // edx
148.1223 -
148.1224 -#if 0  /* MMX regs (%mm0, etc.) not supported by gcc 2.7.2.3 or egcs 1.1 */
148.1225 -                  : "%mm0", "%mm1", "%mm2", "%mm3"  // clobber list
148.1226 -                  , "%mm4", "%mm5", "%mm6", "%mm7"
148.1227 -#endif
148.1228 -               );
148.1229 -            }
148.1230 -            else /* mmx _not supported - Use modified C routine */
148.1231 -#endif /* PNG_MMX_CODE_SUPPORTED */
148.1232 -            {
148.1233 -               register png_uint_32 i;
148.1234 -               png_uint_32 initial_val = BPP4 * png_pass_start[png_ptr->pass];
148.1235 -                 /* png.c:  png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; */
148.1236 -               register int stride = BPP4 * png_pass_inc[png_ptr->pass];
148.1237 -                 /* png.c:  png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; */
148.1238 -               register int rep_bytes = BPP4 * png_pass_width[png_ptr->pass];
148.1239 -                 /* png.c:  png_pass_width[] = {8, 4, 4, 2, 2, 1, 1}; */
148.1240 -               png_uint_32 len = png_ptr->width &~7;  /* reduce to mult. of 8 */
148.1241 -               int diff = (int) (png_ptr->width & 7); /* amount lost */
148.1242 -               register png_uint_32 final_val = BPP4 * len;   /* GRR bugfix */
148.1243 -
148.1244 -               srcptr = png_ptr->row_buf + 1 + initial_val;
148.1245 -               dstptr = row + initial_val;
148.1246 -
148.1247 -               for (i = initial_val; i < final_val; i += stride)
148.1248 -               {
148.1249 -                  png_memcpy(dstptr, srcptr, rep_bytes);
148.1250 -                  srcptr += stride;
148.1251 -                  dstptr += stride;
148.1252 -               }
148.1253 -               if (diff)  /* number of leftover pixels:  3 for pngtest */
148.1254 -               {
148.1255 -                  final_val+=diff*BPP4;
148.1256 -                  for (; i < final_val; i += stride)
148.1257 -                  {
148.1258 -                     if (rep_bytes > (int)(final_val-i))
148.1259 -                        rep_bytes = (int)(final_val-i);
148.1260 -                     png_memcpy(dstptr, srcptr, rep_bytes);
148.1261 -                     srcptr += stride;
148.1262 -                     dstptr += stride;
148.1263 -                  }
148.1264 -               }
148.1265 -            } /* end of else (_mmx_supported) */
148.1266 -
148.1267 -            break;
148.1268 -         }       /* end 32 bpp */
148.1269 -
148.1270 -         case 48:       /* png_ptr->row_info.pixel_depth */
148.1271 -         {
148.1272 -            png_bytep srcptr;
148.1273 -            png_bytep dstptr;
148.1274 -
148.1275 -#if defined(PNG_MMX_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK)
148.1276 -#if !defined(PNG_1_0_X)
148.1277 -            if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)
148.1278 -                /* && _mmx_supported */ )
148.1279 -#else
148.1280 -            if (_mmx_supported)
148.1281 -#endif
148.1282 -            {
148.1283 -               png_uint_32 len;
148.1284 -               int diff;
148.1285 -               int dummy_value_a;   // fix 'forbidden register spilled' error
148.1286 -               int dummy_value_d;
148.1287 -               int dummy_value_c;
148.1288 -               int dummy_value_S;
148.1289 -               int dummy_value_D;
148.1290 -               _unmask = ~mask;            // global variable for -fPIC version
148.1291 -               srcptr = png_ptr->row_buf + 1;
148.1292 -               dstptr = row;
148.1293 -               len  = png_ptr->width &~7;  // reduce to multiple of 8
148.1294 -               diff = (int) (png_ptr->width & 7); // amount lost //
148.1295 -
148.1296 -               __asm__ __volatile__ (
148.1297 -                  "movd      _unmask, %%mm7   \n\t" // load bit pattern
148.1298 -                  "psubb     %%mm6, %%mm6     \n\t" // zero mm6
148.1299 -                  "punpcklbw %%mm7, %%mm7     \n\t"
148.1300 -                  "punpcklwd %%mm7, %%mm7     \n\t"
148.1301 -                  "punpckldq %%mm7, %%mm7     \n\t" // fill reg with 8 masks
148.1302 -
148.1303 -                  "movq      _mask48_0, %%mm0 \n\t"
148.1304 -                  "movq      _mask48_1, %%mm1 \n\t"
148.1305 -                  "movq      _mask48_2, %%mm2 \n\t"
148.1306 -                  "movq      _mask48_3, %%mm3 \n\t"
148.1307 -                  "movq      _mask48_4, %%mm4 \n\t"
148.1308 -                  "movq      _mask48_5, %%mm5 \n\t"
148.1309 -
148.1310 -                  "pand      %%mm7, %%mm0     \n\t"
148.1311 -                  "pand      %%mm7, %%mm1     \n\t"
148.1312 -                  "pand      %%mm7, %%mm2     \n\t"
148.1313 -                  "pand      %%mm7, %%mm3     \n\t"
148.1314 -                  "pand      %%mm7, %%mm4     \n\t"
148.1315 -                  "pand      %%mm7, %%mm5     \n\t"
148.1316 -
148.1317 -                  "pcmpeqb   %%mm6, %%mm0     \n\t"
148.1318 -                  "pcmpeqb   %%mm6, %%mm1     \n\t"
148.1319 -                  "pcmpeqb   %%mm6, %%mm2     \n\t"
148.1320 -                  "pcmpeqb   %%mm6, %%mm3     \n\t"
148.1321 -                  "pcmpeqb   %%mm6, %%mm4     \n\t"
148.1322 -                  "pcmpeqb   %%mm6, %%mm5     \n\t"
148.1323 -
148.1324 -// preload        "movl      len, %%ecx       \n\t" // load length of line
148.1325 -// preload        "movl      srcptr, %%esi    \n\t" // load source
148.1326 -// preload        "movl      dstptr, %%edi    \n\t" // load dest
148.1327 -
148.1328 -                  "cmpl      $0, %%ecx        \n\t"
148.1329 -                  "jz        mainloop48end    \n\t"
148.1330 -
148.1331 -                "mainloop48:                  \n\t"
148.1332 -                  "movq      (%%esi), %%mm7   \n\t"
148.1333 -                  "pand      %%mm0, %%mm7     \n\t"
148.1334 -                  "movq      %%mm0, %%mm6     \n\t"
148.1335 -                  "pandn     (%%edi), %%mm6   \n\t"
148.1336 -                  "por       %%mm6, %%mm7     \n\t"
148.1337 -                  "movq      %%mm7, (%%edi)   \n\t"
148.1338 -
148.1339 -                  "movq      8(%%esi), %%mm6  \n\t"
148.1340 -                  "pand      %%mm1, %%mm6     \n\t"
148.1341 -                  "movq      %%mm1, %%mm7     \n\t"
148.1342 -                  "pandn     8(%%edi), %%mm7  \n\t"
148.1343 -                  "por       %%mm7, %%mm6     \n\t"
148.1344 -                  "movq      %%mm6, 8(%%edi)  \n\t"
148.1345 -
148.1346 -                  "movq      16(%%esi), %%mm6 \n\t"
148.1347 -                  "pand      %%mm2, %%mm6     \n\t"
148.1348 -                  "movq      %%mm2, %%mm7     \n\t"
148.1349 -                  "pandn     16(%%edi), %%mm7 \n\t"
148.1350 -                  "por       %%mm7, %%mm6     \n\t"
148.1351 -                  "movq      %%mm6, 16(%%edi) \n\t"
148.1352 -
148.1353 -                  "movq      24(%%esi), %%mm7 \n\t"
148.1354 -                  "pand      %%mm3, %%mm7     \n\t"
148.1355 -                  "movq      %%mm3, %%mm6     \n\t"
148.1356 -                  "pandn     24(%%edi), %%mm6 \n\t"
148.1357 -                  "por       %%mm6, %%mm7     \n\t"
148.1358 -                  "movq      %%mm7, 24(%%edi) \n\t"
148.1359 -
148.1360 -                  "movq      32(%%esi), %%mm6 \n\t"
148.1361 -                  "pand      %%mm4, %%mm6     \n\t"
148.1362 -                  "movq      %%mm4, %%mm7     \n\t"
148.1363 -                  "pandn     32(%%edi), %%mm7 \n\t"
148.1364 -                  "por       %%mm7, %%mm6     \n\t"
148.1365 -                  "movq      %%mm6, 32(%%edi) \n\t"
148.1366 -
148.1367 -                  "movq      40(%%esi), %%mm7 \n\t"
148.1368 -                  "pand      %%mm5, %%mm7     \n\t"
148.1369 -                  "movq      %%mm5, %%mm6     \n\t"
148.1370 -                  "pandn     40(%%edi), %%mm6 \n\t"
148.1371 -                  "por       %%mm6, %%mm7     \n\t"
148.1372 -                  "movq      %%mm7, 40(%%edi) \n\t"
148.1373 -
148.1374 -                  "addl      $48, %%esi       \n\t" // inc by 48 bytes processed
148.1375 -                  "addl      $48, %%edi       \n\t"
148.1376 -                  "subl      $8, %%ecx        \n\t" // dec by 8 pixels processed
148.1377 -
148.1378 -                  "ja        mainloop48       \n\t"
148.1379 -
148.1380 -                "mainloop48end:               \n\t"
148.1381 -// preload        "movl      diff, %%ecx      \n\t" // (diff is in eax)
148.1382 -                  "movl      %%eax, %%ecx     \n\t"
148.1383 -                  "cmpl      $0, %%ecx        \n\t"
148.1384 -                  "jz        end48            \n\t"
148.1385 -// preload        "movl      mask, %%edx      \n\t"
148.1386 -                  "sall      $24, %%edx       \n\t" // make low byte, high byte
148.1387 -
148.1388 -                "secondloop48:                \n\t"
148.1389 -                  "sall      %%edx            \n\t" // move high bit to CF
148.1390 -                  "jnc       skip48           \n\t" // if CF = 0
148.1391 -                  "movl      (%%esi), %%eax   \n\t"
148.1392 -                  "movl      %%eax, (%%edi)   \n\t"
148.1393 -
148.1394 -                "skip48:                      \n\t"
148.1395 -                  "addl      $4, %%esi        \n\t"
148.1396 -                  "addl      $4, %%edi        \n\t"
148.1397 -                  "decl      %%ecx            \n\t"
148.1398 -                  "jnz       secondloop48     \n\t"
148.1399 -
148.1400 -                "end48:                       \n\t"
148.1401 -                  "EMMS                       \n\t" // DONE
148.1402 -
148.1403 -                  : "=a" (dummy_value_a),           // output regs (dummy)
148.1404 -                    "=d" (dummy_value_d),
148.1405 -                    "=c" (dummy_value_c),
148.1406 -                    "=S" (dummy_value_S),
148.1407 -                    "=D" (dummy_value_D)
148.1408 -
148.1409 -                  : "3" (srcptr),      // esi       // input regs
148.1410 -                    "4" (dstptr),      // edi
148.1411 -                    "0" (diff),        // eax
148.1412 -// was (unmask)     "b"    RESERVED    // ebx       // Global Offset Table idx
148.1413 -                    "2" (len),         // ecx
148.1414 -                    "1" (mask)         // edx
148.1415 -
148.1416 -#if 0  /* MMX regs (%mm0, etc.) not supported by gcc 2.7.2.3 or egcs 1.1 */
148.1417 -                  : "%mm0", "%mm1", "%mm2", "%mm3"  // clobber list
148.1418 -                  , "%mm4", "%mm5", "%mm6", "%mm7"
148.1419 -#endif
148.1420 -               );
148.1421 -            }
148.1422 -            else /* mmx _not supported - Use modified C routine */
148.1423 -#endif /* PNG_MMX_CODE_SUPPORTED */
148.1424 -            {
148.1425 -               register png_uint_32 i;
148.1426 -               png_uint_32 initial_val = BPP6 * png_pass_start[png_ptr->pass];
148.1427 -                 /* png.c:  png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; */
148.1428 -               register int stride = BPP6 * png_pass_inc[png_ptr->pass];
148.1429 -                 /* png.c:  png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; */
148.1430 -               register int rep_bytes = BPP6 * png_pass_width[png_ptr->pass];
148.1431 -                 /* png.c:  png_pass_width[] = {8, 4, 4, 2, 2, 1, 1}; */
148.1432 -               png_uint_32 len = png_ptr->width &~7;  /* reduce to mult. of 8 */
148.1433 -               int diff = (int) (png_ptr->width & 7); /* amount lost */
148.1434 -               register png_uint_32 final_val = BPP6 * len;   /* GRR bugfix */
148.1435 -
148.1436 -               srcptr = png_ptr->row_buf + 1 + initial_val;
148.1437 -               dstptr = row + initial_val;
148.1438 -
148.1439 -               for (i = initial_val; i < final_val; i += stride)
148.1440 -               {
148.1441 -                  png_memcpy(dstptr, srcptr, rep_bytes);
148.1442 -                  srcptr += stride;
148.1443 -                  dstptr += stride;
148.1444 -               }
148.1445 -               if (diff)  /* number of leftover pixels:  3 for pngtest */
148.1446 -               {
148.1447 -                  final_val+=diff*BPP6;
148.1448 -                  for (; i < final_val; i += stride)
148.1449 -                  {
148.1450 -                     if (rep_bytes > (int)(final_val-i))
148.1451 -                        rep_bytes = (int)(final_val-i);
148.1452 -                     png_memcpy(dstptr, srcptr, rep_bytes);
148.1453 -                     srcptr += stride;
148.1454 -                     dstptr += stride;
148.1455 -                  }
148.1456 -               }
148.1457 -            } /* end of else (_mmx_supported) */
148.1458 -
148.1459 -            break;
148.1460 -         }       /* end 48 bpp */
148.1461 -
148.1462 -         case 64:       /* png_ptr->row_info.pixel_depth */
148.1463 -         {
148.1464 -            png_bytep srcptr;
148.1465 -            png_bytep dstptr;
148.1466 -            register png_uint_32 i;
148.1467 -            png_uint_32 initial_val = BPP8 * png_pass_start[png_ptr->pass];
148.1468 -              /* png.c:  png_pass_start[] = {0, 4, 0, 2, 0, 1, 0}; */
148.1469 -            register int stride = BPP8 * png_pass_inc[png_ptr->pass];
148.1470 -              /* png.c:  png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1}; */
148.1471 -            register int rep_bytes = BPP8 * png_pass_width[png_ptr->pass];
148.1472 -              /* png.c:  png_pass_width[] = {8, 4, 4, 2, 2, 1, 1}; */
148.1473 -            png_uint_32 len = png_ptr->width &~7;  /* reduce to mult. of 8 */
148.1474 -            int diff = (int) (png_ptr->width & 7); /* amount lost */
148.1475 -            register png_uint_32 final_val = BPP8 * len;   /* GRR bugfix */
148.1476 -
148.1477 -            srcptr = png_ptr->row_buf + 1 + initial_val;
148.1478 -            dstptr = row + initial_val;
148.1479 -
148.1480 -            for (i = initial_val; i < final_val; i += stride)
148.1481 -            {
148.1482 -               png_memcpy(dstptr, srcptr, rep_bytes);
148.1483 -               srcptr += stride;
148.1484 -               dstptr += stride;
148.1485 -            }
148.1486 -            if (diff)  /* number of leftover pixels:  3 for pngtest */
148.1487 -            {
148.1488 -               final_val+=diff*BPP8;
148.1489 -               for (; i < final_val; i += stride)
148.1490 -               {
148.1491 -                  if (rep_bytes > (int)(final_val-i))
148.1492 -                     rep_bytes = (int)(final_val-i);
148.1493 -                  png_memcpy(dstptr, srcptr, rep_bytes);
148.1494 -                  srcptr += stride;
148.1495 -                  dstptr += stride;
148.1496 -               }
148.1497 -            }
148.1498 -
148.1499 -            break;
148.1500 -         }       /* end 64 bpp */
148.1501 -
148.1502 -         default: /* png_ptr->row_info.pixel_depth != 1,2,4,8,16,24,32,48,64 */
148.1503 -         {
148.1504 -            /* this should never happen */
148.1505 -            png_warning(png_ptr, "Invalid row_info.pixel_depth in pnggccrd");
148.1506 -            break;
148.1507 -         }
148.1508 -      } /* end switch (png_ptr->row_info.pixel_depth) */
148.1509 -
148.1510 -   } /* end if (non-trivial mask) */
148.1511 -
148.1512 -} /* end png_combine_row() */
148.1513 -
148.1514 -#endif /* PNG_HAVE_MMX_COMBINE_ROW */
148.1515 -
148.1516 -
148.1517 -
148.1518 -
148.1519 -/*===========================================================================*/
148.1520 -/*                                                                           */
148.1521 -/*                 P N G _ D O _ R E A D _ I N T E R L A C E                 */
148.1522 -/*                                                                           */
148.1523 -/*===========================================================================*/
148.1524 -
148.1525 -#if defined(PNG_READ_INTERLACING_SUPPORTED)
148.1526 -#if defined(PNG_HAVE_MMX_READ_INTERLACE)
148.1527 -
148.1528 -/* png_do_read_interlace() is called after any 16-bit to 8-bit conversion
148.1529 - * has taken place.  [GRR: what other steps come before and/or after?]
148.1530 - */
148.1531 -
148.1532 -void /* PRIVATE */
148.1533 -png_do_read_interlace(png_structp png_ptr)
148.1534 -{
148.1535 -   png_row_infop row_info = &(png_ptr->row_info);
148.1536 -   png_bytep row = png_ptr->row_buf + 1;
148.1537 -   int pass = png_ptr->pass;
148.1538 -#if defined(PNG_READ_PACKSWAP_SUPPORTED)
148.1539 -   png_uint_32 transformations = png_ptr->transformations;
148.1540 -#endif
148.1541 -
148.1542 -   png_debug(1, "in png_do_read_interlace (pnggccrd.c)\n");
148.1543 -
148.1544 -#if defined(PNG_MMX_CODE_SUPPORTED)
148.1545 -   if (_mmx_supported == 2) {
148.1546 -#if !defined(PNG_1_0_X)
148.1547 -       /* this should have happened in png_init_mmx_flags() already */
148.1548 -       png_warning(png_ptr, "asm_flags may not have been initialized");
148.1549 -#endif
148.1550 -       png_mmx_support();
148.1551 -   }
148.1552 -#endif
148.1553 -
148.1554 -   if (row != NULL && row_info != NULL)
148.1555 -   {
148.1556 -      png_uint_32 final_width;
148.1557 -
148.1558 -      final_width = row_info->width * png_pass_inc[pass];
148.1559 -
148.1560 -      switch (row_info->pixel_depth)
148.1561 -      {
148.1562 -         case 1:
148.1563 -         {
148.1564 -            png_bytep sp, dp;
148.1565 -            int sshift, dshift;
148.1566 -            int s_start, s_end, s_inc;
148.1567 -            png_byte v;
148.1568 -            png_uint_32 i;
148.1569 -            int j;
148.1570 -
148.1571 -            sp = row + (png_size_t)((row_info->width - 1) >> 3);
148.1572 -            dp = row + (png_size_t)((final_width - 1) >> 3);
148.1573 -#if defined(PNG_READ_PACKSWAP_SUPPORTED)
148.1574 -            if (transformations & PNG_PACKSWAP)
148.1575 -            {
148.1576 -               sshift = (int)((row_info->width + 7) & 7);
148.1577 -               dshift = (int)((final_width + 7) & 7);
148.1578 -               s_start = 7;
148.1579 -               s_end = 0;
148.1580 -               s_inc = -1;
148.1581 -            }
148.1582 -            else
148.1583 -#endif
148.1584 -            {
148.1585 -               sshift = 7 - (int)((row_info->width + 7) & 7);
148.1586 -               dshift = 7 - (int)((final_width + 7) & 7);
148.1587 -               s_start = 0;
148.1588 -               s_end = 7;
148.1589 -               s_inc = 1;
148.1590 -            }
148.1591 -
148.1592 -            for (i = row_info->width; i; i--)
148.1593 -            {
148.1594 -               v = (png_byte)((*sp >> sshift) & 0x1);
148.1595 -               for (j = 0; j < png_pass_inc[pass]; j++)
148.1596 -               {
148.1597 -                  *dp &= (png_byte)((0x7f7f >> (7 - dshift)) & 0xff);
148.1598 -                  *dp |= (png_byte)(v << dshift);
148.1599 -                  if (dshift == s_end)
148.1600 -                  {
148.1601 -                     dshift = s_start;
148.1602 -                     dp--;
148.1603 -                  }
148.1604 -                  else
148.1605 -                     dshift += s_inc;
148.1606 -               }
148.1607 -               if (sshift == s_end)
148.1608 -               {
148.1609 -                  sshift = s_start;
148.1610 -                  sp--;
148.1611 -               }
148.1612 -               else
148.1613 -                  sshift += s_inc;
148.1614 -            }
148.1615 -            break;
148.1616 -         }
148.1617 -
148.1618 -         case 2:
148.1619 -         {
148.1620 -            png_bytep sp, dp;
148.1621 -            int sshift, dshift;
148.1622 -            int s_start, s_end, s_inc;
148.1623 -            png_uint_32 i;
148.1624 -
148.1625 -            sp = row + (png_size_t)((row_info->width - 1) >> 2);
148.1626 -            dp = row + (png_size_t)((final_width - 1) >> 2);
148.1627 -#if defined(PNG_READ_PACKSWAP_SUPPORTED)
148.1628 -            if (transformations & PNG_PACKSWAP)
148.1629 -            {
148.1630 -               sshift = (png_size_t)(((row_info->width + 3) & 3) << 1);
148.1631 -               dshift = (png_size_t)(((final_width + 3) & 3) << 1);
148.1632 -               s_start = 6;
148.1633 -               s_end = 0;
148.1634 -               s_inc = -2;
148.1635 -            }
148.1636 -            else
148.1637 -#endif
148.1638 -            {
148.1639 -               sshift = (png_size_t)((3 - ((row_info->width + 3) & 3)) << 1);
148.1640 -               dshift = (png_size_t)((3 - ((final_width + 3) & 3)) << 1);
148.1641 -               s_start = 0;
148.1642 -               s_end = 6;
148.1643 -               s_inc = 2;
148.1644 -            }
148.1645 -
148.1646 -            for (i = row_info->width; i; i--)
148.1647 -            {
148.1648 -               png_byte v;
148.1649 -               int j;
148.1650 -
148.1651 -               v = (png_byte)((*sp >> sshift) & 0x3);
148.1652 -               for (j = 0; j < png_pass_inc[pass]; j++)
148.1653 -               {
148.1654 -                  *dp &= (png_byte)((0x3f3f >> (6 - dshift)) & 0xff);
148.1655 -                  *dp |= (png_byte)(v << dshift);
148.1656 -                  if (dshift == s_end)
148.1657 -                  {
148.1658 -                     dshift = s_start;
148.1659 -                     dp--;
148.1660 -                  }
148.1661 -                  else
148.1662 -                     dshift += s_inc;
148.1663 -               }
148.1664 -               if (sshift == s_end)
148.1665 -               {
148.1666 -                  sshift = s_start;
148.1667 -                  sp--;
148.1668 -               }
148.1669 -               else
148.1670 -                  sshift += s_inc;
148.1671 -            }
148.1672 -            break;
148.1673 -         }
148.1674 -
148.1675 -         case 4:
148.1676 -         {
148.1677 -            png_bytep sp, dp;
148.1678 -            int sshift, dshift;
148.1679 -            int s_start, s_end, s_inc;
148.1680 -            png_uint_32 i;
148.1681 -
148.1682 -            sp = row + (png_size_t)((row_info->width - 1) >> 1);
148.1683 -            dp = row + (png_size_t)((final_width - 1) >> 1);
148.1684 -#if defined(PNG_READ_PACKSWAP_SUPPORTED)
148.1685 -            if (transformations & PNG_PACKSWAP)
148.1686 -            {
148.1687 -               sshift = (png_size_t)(((row_info->width + 1) & 1) << 2);
148.1688 -               dshift = (png_size_t)(((final_width + 1) & 1) << 2);
148.1689 -               s_start = 4;
148.1690 -               s_end = 0;
148.1691 -               s_inc = -4;
148.1692 -            }
148.1693 -            else
148.1694 -#endif
148.1695 -            {
148.1696 -               sshift = (png_size_t)((1 - ((row_info->width + 1) & 1)) << 2);
148.1697 -               dshift = (png_size_t)((1 - ((final_width + 1) & 1)) << 2);
148.1698 -               s_start = 0;
148.1699 -               s_end = 4;
148.1700 -               s_inc = 4;
148.1701 -            }
148.1702 -
148.1703 -            for (i = row_info->width; i; i--)
148.1704 -            {
148.1705 -               png_byte v;
148.1706 -               int j;
148.1707 -
148.1708 -               v = (png_byte)((*sp >> sshift) & 0xf);
148.1709 -               for (j = 0; j < png_pass_inc[pass]; j++)
148.1710 -               {
148.1711 -                  *dp &= (png_byte)((0xf0f >> (4 - dshift)) & 0xff);
148.1712 -                  *dp |= (png_byte)(v << dshift);
148.1713 -                  if (dshift == s_end)
148.1714 -                  {
148.1715 -                     dshift = s_start;
148.1716 -                     dp--;
148.1717 -                  }
148.1718 -                  else
148.1719 -                     dshift += s_inc;
148.1720 -               }
148.1721 -               if (sshift == s_end)
148.1722 -               {
148.1723 -                  sshift = s_start;
148.1724 -                  sp--;
148.1725 -               }
148.1726 -               else
148.1727 -                  sshift += s_inc;
148.1728 -            }
148.1729 -            break;
148.1730 -         }
148.1731 -
148.1732 -       /*====================================================================*/
148.1733 -
148.1734 -         default: /* 8-bit or larger (this is where the routine is modified) */
148.1735 -         {
148.1736 -#if 0
148.1737 -//          static unsigned long long _const4 = 0x0000000000FFFFFFLL;  no good
148.1738 -//          static unsigned long long const4 = 0x0000000000FFFFFFLL;   no good
148.1739 -//          unsigned long long _const4 = 0x0000000000FFFFFFLL;         no good
148.1740 -//          unsigned long long const4 = 0x0000000000FFFFFFLL;          no good
148.1741 -#endif
148.1742 -            png_bytep sptr, dp;
148.1743 -            png_uint_32 i;
148.1744 -            png_size_t pixel_bytes;
148.1745 -            int width = (int)row_info->width;
148.1746 -
148.1747 -            pixel_bytes = (row_info->pixel_depth >> 3);
148.1748 -
148.1749 -            /* point sptr at the last pixel in the pre-expanded row: */
148.1750 -            sptr = row + (width - 1) * pixel_bytes;
148.1751 -
148.1752 -            /* point dp at the last pixel position in the expanded row: */
148.1753 -            dp = row + (final_width - 1) * pixel_bytes;
148.1754 -
148.1755 -            /* New code by Nirav Chhatrapati - Intel Corporation */
148.1756 -
148.1757 -#if defined(PNG_MMX_CODE_SUPPORTED)
148.1758 -#if !defined(PNG_1_0_X)
148.1759 -            if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_INTERLACE)
148.1760 -                /* && _mmx_supported */ )
148.1761 -#else
148.1762 -            if (_mmx_supported)
148.1763 -#endif
148.1764 -            {
148.1765 -               //--------------------------------------------------------------
148.1766 -               if (pixel_bytes == 3)
148.1767 -               {
148.1768 -                  if (((pass == 0) || (pass == 1)) && width)
148.1769 -                  {
148.1770 -                     int dummy_value_c;   // fix 'forbidden register spilled'
148.1771 -                     int dummy_value_S;
148.1772 -                     int dummy_value_D;
148.1773 -                     int dummy_value_a;
148.1774 -
148.1775 -                     __asm__ __volatile__ (
148.1776 -                        "subl $21, %%edi         \n\t"
148.1777 -                                     // (png_pass_inc[pass] - 1)*pixel_bytes
148.1778 -
148.1779 -                     ".loop3_pass0:              \n\t"
148.1780 -                        "movd (%%esi), %%mm0     \n\t" // x x x x x 2 1 0
148.1781 -                        "pand (%3), %%mm0        \n\t" // z z z z z 2 1 0
148.1782 -                        "movq %%mm0, %%mm1       \n\t" // z z z z z 2 1 0
148.1783 -                        "psllq $16, %%mm0        \n\t" // z z z 2 1 0 z z
148.1784 -                        "movq %%mm0, %%mm2       \n\t" // z z z 2 1 0 z z
148.1785 -                        "psllq $24, %%mm0        \n\t" // 2 1 0 z z z z z
148.1786 -                        "psrlq $8, %%mm1         \n\t" // z z z z z z 2 1
148.1787 -                        "por %%mm2, %%mm0        \n\t" // 2 1 0 2 1 0 z z
148.1788 -                        "por %%mm1, %%mm0        \n\t" // 2 1 0 2 1 0 2 1
148.1789 -                        "movq %%mm0, %%mm3       \n\t" // 2 1 0 2 1 0 2 1
148.1790 -                        "psllq $16, %%mm0        \n\t" // 0 2 1 0 2 1 z z
148.1791 -                        "movq %%mm3, %%mm4       \n\t" // 2 1 0 2 1 0 2 1
148.1792 -                        "punpckhdq %%mm0, %%mm3  \n\t" // 0 2 1 0 2 1 0 2
148.1793 -                        "movq %%mm4, 16(%%edi)   \n\t"
148.1794 -                        "psrlq $32, %%mm0        \n\t" // z z z z 0 2 1 0
148.1795 -                        "movq %%mm3, 8(%%edi)    \n\t"
148.1796 -                        "punpckldq %%mm4, %%mm0  \n\t" // 1 0 2 1 0 2 1 0
148.1797 -                        "subl $3, %%esi          \n\t"
148.1798 -                        "movq %%mm0, (%%edi)     \n\t"
148.1799 -                        "subl $24, %%edi         \n\t"
148.1800 -                        "decl %%ecx              \n\t"
148.1801 -                        "jnz .loop3_pass0        \n\t"
148.1802 -                        "EMMS                    \n\t" // DONE
148.1803 -
148.1804 -                        : "=c" (dummy_value_c),        // output regs (dummy)
148.1805 -                          "=S" (dummy_value_S),
148.1806 -                          "=D" (dummy_value_D),
148.1807 -                          "=a" (dummy_value_a)
148.1808 -
148.1809 -
148.1810 -                        : "1" (sptr),      // esi      // input regs
148.1811 -                          "2" (dp),        // edi
148.1812 -                          "0" (width),     // ecx
148.1813 -                          "3" (&_const4)  // %1(?)  (0x0000000000FFFFFFLL)
148.1814 -
148.1815 -#if 0  /* %mm0, ..., %mm4 not supported by gcc 2.7.2.3 or egcs 1.1 */
148.1816 -                        : "%mm0", "%mm1", "%mm2"       // clobber list
148.1817 -                        , "%mm3", "%mm4"
148.1818 -#endif
148.1819 -                     );
148.1820 -                  }
148.1821 -                  else if (((pass == 2) || (pass == 3)) && width)
148.1822 -                  {
148.1823 -                     int dummy_value_c;   // fix 'forbidden register spilled'
148.1824 -                     int dummy_value_S;
148.1825 -                     int dummy_value_D;
148.1826 -                     int dummy_value_a;
148.1827 -
148.1828 -                     __asm__ __volatile__ (
148.1829 -                        "subl $9, %%edi          \n\t"
148.1830 -                                     // (png_pass_inc[pass] - 1)*pixel_bytes
148.1831 -
148.1832 -                     ".loop3_pass2:              \n\t"
148.1833 -                        "movd (%%esi), %%mm0     \n\t" // x x x x x 2 1 0
148.1834 -                        "pand (%3), %%mm0     \n\t" // z z z z z 2 1 0
148.1835 -                        "movq %%mm0, %%mm1       \n\t" // z z z z z 2 1 0
148.1836 -                        "psllq $16, %%mm0        \n\t" // z z z 2 1 0 z z
148.1837 -                        "movq %%mm0, %%mm2       \n\t" // z z z 2 1 0 z z
148.1838 -                        "psllq $24, %%mm0        \n\t" // 2 1 0 z z z z z
148.1839 -                        "psrlq $8, %%mm1         \n\t" // z z z z z z 2 1
148.1840 -                        "por %%mm2, %%mm0        \n\t" // 2 1 0 2 1 0 z z
148.1841 -                        "por %%mm1, %%mm0        \n\t" // 2 1 0 2 1 0 2 1
148.1842 -                        "movq %%mm0, 4(%%edi)    \n\t"
148.1843 -                        "psrlq $16, %%mm0        \n\t" // z z 2 1 0 2 1 0
148.1844 -                        "subl $3, %%esi          \n\t"
148.1845 -                        "movd %%mm0, (%%edi)     \n\t"
148.1846 -                        "subl $12, %%edi         \n\t"
148.1847 -                        "decl %%ecx              \n\t"
148.1848 -                        "jnz .loop3_pass2        \n\t"
148.1849 -                        "EMMS                    \n\t" // DONE
148.1850 -
148.1851 -                        : "=c" (dummy_value_c),        // output regs (dummy)
148.1852 -                          "=S" (dummy_value_S),
148.1853 -                          "=D" (dummy_value_D),
148.1854 -                          "=a" (dummy_value_a)
148.1855 -
148.1856 -                        : "1" (sptr),      // esi      // input regs
148.1857 -                          "2" (dp),        // edi
148.1858 -                          "0" (width),     // ecx
148.1859 -                          "3" (&_const4)  // (0x0000000000FFFFFFLL)
148.1860 -
148.1861 -#if 0  /* %mm0, ..., %mm2 not supported by gcc 2.7.2.3 or egcs 1.1 */
148.1862 -                        : "%mm0", "%mm1", "%mm2"       // clobber list
148.1863 -#endif
148.1864 -                     );
148.1865 -                  }
148.1866 -                  else if (width) /* && ((pass == 4) || (pass == 5)) */
148.1867 -                  {
148.1868 -                     int width_mmx = ((width >> 1) << 1) - 8;   // GRR:  huh?
148.1869 -                     if (width_mmx < 0)
148.1870 -                         width_mmx = 0;
148.1871 -                     width -= width_mmx;        // 8 or 9 pix, 24 or 27 bytes
148.1872 -                     if (width_mmx)
148.1873 -                     {
148.1874 -                        // png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
148.1875 -                        // sptr points at last pixel in pre-expanded row
148.1876 -                        // dp points at last pixel position in expanded row
148.1877 -                        int dummy_value_c;  // fix 'forbidden register spilled'
148.1878 -                        int dummy_value_S;
148.1879 -                        int dummy_value_D;
148.1880 -                        int dummy_value_a;
148.1881 -                        int dummy_value_d;
148.1882 -
148.1883 -                        __asm__ __volatile__ (
148.1884 -                           "subl $3, %%esi          \n\t"
148.1885 -                           "subl $9, %%edi          \n\t"
148.1886 -                                        // (png_pass_inc[pass] + 1)*pixel_bytes
148.1887 -
148.1888 -                        ".loop3_pass4:              \n\t"
148.1889 -                           "movq (%%esi), %%mm0     \n\t" // x x 5 4 3 2 1 0
148.1890 -                           "movq %%mm0, %%mm1       \n\t" // x x 5 4 3 2 1 0
148.1891 -                           "movq %%mm0, %%mm2       \n\t" // x x 5 4 3 2 1 0
148.1892 -                           "psllq $24, %%mm0        \n\t" // 4 3 2 1 0 z z z
148.1893 -                           "pand (%3), %%mm1          \n\t" // z z z z z 2 1 0
148.1894 -                           "psrlq $24, %%mm2        \n\t" // z z z x x 5 4 3
148.1895 -                           "por %%mm1, %%mm0        \n\t" // 4 3 2 1 0 2 1 0
148.1896 -                           "movq %%mm2, %%mm3       \n\t" // z z z x x 5 4 3
148.1897 -                           "psllq $8, %%mm2         \n\t" // z z x x 5 4 3 z
148.1898 -                           "movq %%mm0, (%%edi)     \n\t"
148.1899 -                           "psrlq $16, %%mm3        \n\t" // z z z z z x x 5
148.1900 -                           "pand (%4), %%mm3     \n\t" // z z z z z z z 5
148.1901 -                           "por %%mm3, %%mm2        \n\t" // z z x x 5 4 3 5
148.1902 -                           "subl $6, %%esi          \n\t"
148.1903 -                           "movd %%mm2, 8(%%edi)    \n\t"
148.1904 -                           "subl $12, %%edi         \n\t"
148.1905 -                           "subl $2, %%ecx          \n\t"
148.1906 -                           "jnz .loop3_pass4        \n\t"
148.1907 -                           "EMMS                    \n\t" // DONE
148.1908 -
148.1909 -                           : "=c" (dummy_value_c),        // output regs (dummy)
148.1910 -                             "=S" (dummy_value_S),
148.1911 -                             "=D" (dummy_value_D),
148.1912 -                             "=a" (dummy_value_a),
148.1913 -                             "=d" (dummy_value_d)
148.1914 -
148.1915 -                           : "1" (sptr),      // esi      // input regs
148.1916 -                             "2" (dp),        // edi
148.1917 -                             "0" (width_mmx), // ecx
148.1918 -                             "3" (&_const4), // 0x0000000000FFFFFFLL
148.1919 -                             "4" (&_const6)  // 0x00000000000000FFLL
148.1920 -
148.1921 -#if 0  /* %mm0, ..., %mm3 not supported by gcc 2.7.2.3 or egcs 1.1 */
148.1922 -                           : "%mm0", "%mm1"               // clobber list
148.1923 -                           , "%mm2", "%mm3"
148.1924 -#endif
148.1925 -                        );
148.1926 -                     }
148.1927 -
148.1928 -                     sptr -= width_mmx*3;
148.1929 -                     dp -= width_mmx*6;
148.1930 -                     for (i = width; i; i--)
148.1931 -                     {
148.1932 -                        png_byte v[8];
148.1933 -                        int j;
148.1934 -
148.1935 -                        png_memcpy(v, sptr, 3);
148.1936 -                        for (j = 0; j < png_pass_inc[pass]; j++)
148.1937 -                        {
148.1938 -                           png_memcpy(dp, v, 3);
148.1939 -                           dp -= 3;
148.1940 -                        }
148.1941 -                        sptr -= 3;
148.1942 -                     }
148.1943 -                  }
148.1944 -               } /* end of pixel_bytes == 3 */
148.1945 -
148.1946 -               //--------------------------------------------------------------
148.1947 -               else if (pixel_bytes == 1)
148.1948 -               {
148.1949 -                  if (((pass == 0) || (pass == 1)) && width)
148.1950 -                  {
148.1951 -                     int width_mmx = ((width >> 2) << 2);
148.1952 -                     width -= width_mmx;        // 0-3 pixels => 0-3 bytes
148.1953 -                     if (width_mmx)
148.1954 -                     {
148.1955 -                        int dummy_value_c;  // fix 'forbidden register spilled'
148.1956 -                        int dummy_value_S;
148.1957 -                        int dummy_value_D;
148.1958 -
148.1959 -                        __asm__ __volatile__ (
148.1960 -                           "subl $3, %%esi          \n\t"
148.1961 -                           "subl $31, %%edi         \n\t"
148.1962 -
148.1963 -                        ".loop1_pass0:              \n\t"
148.1964 -                           "movd (%%esi), %%mm0     \n\t" // x x x x 3 2 1 0
148.1965 -                           "movq %%mm0, %%mm1       \n\t" // x x x x 3 2 1 0
148.1966 -                           "punpcklbw %%mm0, %%mm0  \n\t" // 3 3 2 2 1 1 0 0
148.1967 -                           "movq %%mm0, %%mm2       \n\t" // 3 3 2 2 1 1 0 0
148.1968 -                           "punpcklwd %%mm0, %%mm0  \n\t" // 1 1 1 1 0 0 0 0
148.1969 -                           "movq %%mm0, %%mm3       \n\t" // 1 1 1 1 0 0 0 0
148.1970 -                           "punpckldq %%mm0, %%mm0  \n\t" // 0 0 0 0 0 0 0 0
148.1971 -                           "punpckhdq %%mm3, %%mm3  \n\t" // 1 1 1 1 1 1 1 1
148.1972 -                           "movq %%mm0, (%%edi)     \n\t"
148.1973 -                           "punpckhwd %%mm2, %%mm2  \n\t" // 3 3 3 3 2 2 2 2
148.1974 -                           "movq %%mm3, 8(%%edi)    \n\t"
148.1975 -                           "movq %%mm2, %%mm4       \n\t" // 3 3 3 3 2 2 2 2
148.1976 -                           "punpckldq %%mm2, %%mm2  \n\t" // 2 2 2 2 2 2 2 2
148.1977 -                           "punpckhdq %%mm4, %%mm4  \n\t" // 3 3 3 3 3 3 3 3
148.1978 -                           "movq %%mm2, 16(%%edi)   \n\t"
148.1979 -                           "subl $4, %%esi          \n\t"
148.1980 -                           "movq %%mm4, 24(%%edi)   \n\t"
148.1981 -                           "subl $32, %%edi         \n\t"
148.1982 -                           "subl $4, %%ecx          \n\t"
148.1983 -                           "jnz .loop1_pass0        \n\t"
148.1984 -                           "EMMS                    \n\t" // DONE
148.1985 -
148.1986 -                           : "=c" (dummy_value_c),        // output regs (dummy)
148.1987 -                             "=S" (dummy_value_S),
148.1988 -                             "=D" (dummy_value_D)
148.1989 -
148.1990 -                           : "1" (sptr),      // esi      // input regs
148.1991 -                             "2" (dp),        // edi
148.1992 -                             "0" (width_mmx)  // ecx
148.1993 -
148.1994 -#if 0  /* %mm0, ..., %mm4 not supported by gcc 2.7.2.3 or egcs 1.1 */
148.1995 -                           : "%mm0", "%mm1", "%mm2"       // clobber list
148.1996 -                           , "%mm3", "%mm4"
148.1997 -#endif
148.1998 -                        );
148.1999 -                     }
148.2000 -
148.2001 -                     sptr -= width_mmx;
148.2002 -                     dp -= width_mmx*8;
148.2003 -                     for (i = width; i; i--)
148.2004 -                     {
148.2005 -                        int j;
148.2006 -
148.2007 -                       /* I simplified this part in version 1.0.4e
148.2008 -                        * here and in several other instances where
148.2009 -                        * pixel_bytes == 1  -- GR-P
148.2010 -                        *
148.2011 -                        * Original code:
148.2012 -                        *
148.2013 -                        * png_byte v[8];
148.2014 -                        * png_memcpy(v, sptr, pixel_bytes);
148.2015 -                        * for (j = 0; j < png_pass_inc[pass]; j++)
148.2016 -                        * {
148.2017 -                        *    png_memcpy(dp, v, pixel_bytes);
148.2018 -                        *    dp -= pixel_bytes;
148.2019 -                        * }
148.2020 -                        * sptr -= pixel_bytes;
148.2021 -                        *
148.2022 -                        * Replacement code is in the next three lines:
148.2023 -                        */
148.2024 -
148.2025 -                        for (j = 0; j < png_pass_inc[pass]; j++)
148.2026 -                        {
148.2027 -                           *dp-- = *sptr;
148.2028 -                        }
148.2029 -                        --sptr;
148.2030 -                     }
148.2031 -                  }
148.2032 -                  else if (((pass == 2) || (pass == 3)) && width)
148.2033 -                  {
148.2034 -                     int width_mmx = ((width >> 2) << 2);
148.2035 -                     width -= width_mmx;        // 0-3 pixels => 0-3 bytes
148.2036 -                     if (width_mmx)
148.2037 -                     {
148.2038 -                        int dummy_value_c;  // fix 'forbidden register spilled'
148.2039 -                        int dummy_value_S;
148.2040 -                        int dummy_value_D;
148.2041 -
148.2042 -                        __asm__ __volatile__ (
148.2043 -                           "subl $3, %%esi          \n\t"
148.2044 -                           "subl $15, %%edi         \n\t"
148.2045 -
148.2046 -                        ".loop1_pass2:              \n\t"
148.2047 -                           "movd (%%esi), %%mm0     \n\t" // x x x x 3 2 1 0
148.2048 -                           "punpcklbw %%mm0, %%mm0  \n\t" // 3 3 2 2 1 1 0 0
148.2049 -                           "movq %%mm0, %%mm1       \n\t" // 3 3 2 2 1 1 0 0
148.2050 -                           "punpcklwd %%mm0, %%mm0  \n\t" // 1 1 1 1 0 0 0 0
148.2051 -                           "punpckhwd %%mm1, %%mm1  \n\t" // 3 3 3 3 2 2 2 2
148.2052 -                           "movq %%mm0, (%%edi)     \n\t"
148.2053 -                           "subl $4, %%esi          \n\t"
148.2054 -                           "movq %%mm1, 8(%%edi)    \n\t"
148.2055 -                           "subl $16, %%edi         \n\t"
148.2056 -                           "subl $4, %%ecx          \n\t"
148.2057 -                           "jnz .loop1_pass2        \n\t"
148.2058 -                           "EMMS                    \n\t" // DONE
148.2059 -
148.2060 -                           : "=c" (dummy_value_c),        // output regs (dummy)
148.2061 -                             "=S" (dummy_value_S),
148.2062 -                             "=D" (dummy_value_D)
148.2063 -
148.2064 -                           : "1" (sptr),      // esi      // input regs
148.2065 -                             "2" (dp),        // edi
148.2066 -                             "0" (width_mmx)  // ecx
148.2067 -
148.2068 -#if 0  /* %mm0, %mm1 not supported by gcc 2.7.2.3 or egcs 1.1 */
148.2069 -                           : "%mm0", "%mm1"               // clobber list
148.2070 -#endif
148.2071 -                        );
148.2072 -                     }
148.2073 -
148.2074 -                     sptr -= width_mmx;
148.2075 -                     dp -= width_mmx*4;
148.2076 -                     for (i = width; i; i--)
148.2077 -                     {
148.2078 -                        int j;
148.2079 -
148.2080 -                        for (j = 0; j < png_pass_inc[pass]; j++)
148.2081 -                        {
148.2082 -                           *dp-- = *sptr;
148.2083 -                        }
148.2084 -                        --sptr;
148.2085 -                     }
148.2086 -                  }
148.2087 -                  else if (width)  /* && ((pass == 4) || (pass == 5)) */
148.2088 -                  {
148.2089 -                     int width_mmx = ((width >> 3) << 3);
148.2090 -                     width -= width_mmx;        // 0-3 pixels => 0-3 bytes
148.2091 -                     if (width_mmx)
148.2092 -                     {
148.2093 -                        int dummy_value_c;  // fix 'forbidden register spilled'
148.2094 -                        int dummy_value_S;
148.2095 -                        int dummy_value_D;
148.2096 -
148.2097 -                        __asm__ __volatile__ (
148.2098 -                           "subl $7, %%esi          \n\t"
148.2099 -                           "subl $15, %%edi         \n\t"
148.2100 -
148.2101 -                        ".loop1_pass4:              \n\t"
148.2102 -                           "movq (%%esi), %%mm0     \n\t" // 7 6 5 4 3 2 1 0
148.2103 -                           "movq %%mm0, %%mm1       \n\t" // 7 6 5 4 3 2 1 0
148.2104 -                           "punpcklbw %%mm0, %%mm0  \n\t" // 3 3 2 2 1 1 0 0
148.2105 -                           "punpckhbw %%mm1, %%mm1  \n\t" // 7 7 6 6 5 5 4 4
148.2106 -                           "movq %%mm1, 8(%%edi)    \n\t"
148.2107 -                           "subl $8, %%esi          \n\t"
148.2108 -                           "movq %%mm0, (%%edi)     \n\t"
148.2109 -                           "subl $16, %%edi         \n\t"
148.2110 -                           "subl $8, %%ecx          \n\t"
148.2111 -                           "jnz .loop1_pass4        \n\t"
148.2112 -                           "EMMS                    \n\t" // DONE
148.2113 -
148.2114 -                           : "=c" (dummy_value_c),        // output regs (none)
148.2115 -                             "=S" (dummy_value_S),
148.2116 -                             "=D" (dummy_value_D)
148.2117 -
148.2118 -                           : "1" (sptr),      // esi      // input regs
148.2119 -                             "2" (dp),        // edi
148.2120 -                             "0" (width_mmx)  // ecx
148.2121 -
148.2122 -#if 0  /* %mm0, %mm1 not supported by gcc 2.7.2.3 or egcs 1.1 */
148.2123 -                           : "%mm0", "%mm1"               // clobber list
148.2124 -#endif
148.2125 -                        );
148.2126 -                     }
148.2127 -
148.2128 -                     sptr -= width_mmx;
148.2129 -                     dp -= width_mmx*2;
148.2130 -                     for (i = width; i; i--)
148.2131 -                     {
148.2132 -                        int j;
148.2133 -
148.2134 -                        for (j = 0; j < png_pass_inc[pass]; j++)
148.2135 -                        {
148.2136 -                           *dp-- = *sptr;
148.2137 -                        }
148.2138 -                        --sptr;
148.2139 -                     }
148.2140 -                  }
148.2141 -               } /* end of pixel_bytes == 1 */
148.2142 -
148.2143 -               //--------------------------------------------------------------
148.2144 -               else if (pixel_bytes == 2)
148.2145 -               {
148.2146 -                  if (((pass == 0) || (pass == 1)) && width)
148.2147 -                  {
148.2148 -                     int width_mmx = ((width >> 1) << 1);
148.2149 -                     width -= width_mmx;        // 0,1 pixels => 0,2 bytes
148.2150 -                     if (width_mmx)
148.2151 -                     {
148.2152 -                        int dummy_value_c;  // fix 'forbidden register spilled'
148.2153 -                        int dummy_value_S;
148.2154 -                        int dummy_value_D;
148.2155 -
148.2156 -                        __asm__ __volatile__ (
148.2157 -                           "subl $2, %%esi          \n\t"
148.2158 -                           "subl $30, %%edi         \n\t"
148.2159 -
148.2160 -                        ".loop2_pass0:              \n\t"
148.2161 -                           "movd (%%esi), %%mm0     \n\t" // x x x x 3 2 1 0
148.2162 -                           "punpcklwd %%mm0, %%mm0  \n\t" // 3 2 3 2 1 0 1 0
148.2163 -                           "movq %%mm0, %%mm1       \n\t" // 3 2 3 2 1 0 1 0
148.2164 -                           "punpckldq %%mm0, %%mm0  \n\t" // 1 0 1 0 1 0 1 0
148.2165 -                           "punpckhdq %%mm1, %%mm1  \n\t" // 3 2 3 2 3 2 3 2
148.2166 -                           "movq %%mm0, (%%edi)     \n\t"
148.2167 -                           "movq %%mm0, 8(%%edi)    \n\t"
148.2168 -                           "movq %%mm1, 16(%%edi)   \n\t"
148.2169 -                           "subl $4, %%esi          \n\t"
148.2170 -                           "movq %%mm1, 24(%%edi)   \n\t"
148.2171 -                           "subl $32, %%edi         \n\t"
148.2172 -                           "subl $2, %%ecx          \n\t"
148.2173 -                           "jnz .loop2_pass0        \n\t"
148.2174 -                           "EMMS                    \n\t" // DONE
148.2175 -
148.2176 -                           : "=c" (dummy_value_c),        // output regs (dummy)
148.2177 -                             "=S" (dummy_value_S),
148.2178 -                             "=D" (dummy_value_D)
148.2179 -
148.2180 -                           : "1" (sptr),      // esi      // input regs
148.2181 -                             "2" (dp),        // edi
148.2182 -                             "0" (width_mmx)  // ecx
148.2183 -
148.2184 -#if 0  /* %mm0, %mm1 not supported by gcc 2.7.2.3 or egcs 1.1 */
148.2185 -                           : "%mm0", "%mm1"               // clobber list
148.2186 -#endif
148.2187 -                        );
148.2188 -                     }
148.2189 -
148.2190 -                     sptr -= (width_mmx*2 - 2); // sign fixed
148.2191 -                     dp -= (width_mmx*16 - 2);  // sign fixed
148.2192 -                     for (i = width; i; i--)
148.2193 -                     {
148.2194 -                        png_byte v[8];
148.2195 -                        int j;
148.2196 -                        sptr -= 2;
148.2197 -                        png_memcpy(v, sptr, 2);
148.2198 -                        for (j = 0; j < png_pass_inc[pass]; j++)
148.2199 -                        {
148.2200 -                           dp -= 2;
148.2201 -                           png_memcpy(dp, v, 2);
148.2202 -                        }
148.2203 -                     }
148.2204 -                  }
148.2205 -                  else if (((pass == 2) || (pass == 3)) && width)
148.2206 -                  {
148.2207 -                     int width_mmx = ((width >> 1) << 1) ;
148.2208 -                     width -= width_mmx;        // 0,1 pixels => 0,2 bytes
148.2209 -                     if (width_mmx)
148.2210 -                     {
148.2211 -                        int dummy_value_c;  // fix 'forbidden register spilled'
148.2212 -                        int dummy_value_S;
148.2213 -                        int dummy_value_D;
148.2214 -
148.2215 -                        __asm__ __volatile__ (
148.2216 -                           "subl $2, %%esi          \n\t"
148.2217 -                           "subl $14, %%edi         \n\t"
148.2218 -
148.2219 -                        ".loop2_pass2:              \n\t"
148.2220 -                           "movd (%%esi), %%mm0     \n\t" // x x x x 3 2 1 0
148.2221 -                           "punpcklwd %%mm0, %%mm0  \n\t" // 3 2 3 2 1 0 1 0
148.2222 -                           "movq %%mm0, %%mm1       \n\t" // 3 2 3 2 1 0 1 0
148.2223 -                           "punpckldq %%mm0, %%mm0  \n\t" // 1 0 1 0 1 0 1 0
148.2224 -                           "punpckhdq %%mm1, %%mm1  \n\t" // 3 2 3 2 3 2 3 2
148.2225 -                           "movq %%mm0, (%%edi)     \n\t"
148.2226 -                           "subl $4, %%esi          \n\t"
148.2227 -                           "movq %%mm1, 8(%%edi)    \n\t"
148.2228 -                           "subl $16, %%edi         \n\t"
148.2229 -                           "subl $2, %%ecx          \n\t"
148.2230 -                           "jnz .loop2_pass2        \n\t"
148.2231 -                           "EMMS                    \n\t" // DONE
148.2232 -
148.2233 -                           : "=c" (dummy_value_c),        // output regs (dummy)
148.2234 -                             "=S" (dummy_value_S),
148.2235 -                             "=D" (dummy_value_D)
148.2236 -
148.2237 -                           : "1" (sptr),      // esi      // input regs
148.2238 -                             "2" (dp),        // edi
148.2239 -                             "0" (width_mmx)  // ecx
148.2240 -
148.2241 -#if 0  /* %mm0, %mm1 not supported by gcc 2.7.2.3 or egcs 1.1 */
148.2242 -                           : "%mm0", "%mm1"               // clobber list
148.2243 -#endif
148.2244 -                        );
148.2245 -                     }
148.2246 -
148.2247 -                     sptr -= (width_mmx*2 - 2); // sign fixed
148.2248 -                     dp -= (width_mmx*8 - 2);   // sign fixed
148.2249 -                     for (i = width; i; i--)
148.2250 -                     {
148.2251 -                        png_byte v[8];
148.2252 -                        int j;
148.2253 -                        sptr -= 2;
148.2254 -                        png_memcpy(v, sptr, 2);
148.2255 -                        for (j = 0; j < png_pass_inc[pass]; j++)
148.2256 -                        {
148.2257 -                           dp -= 2;
148.2258 -                           png_memcpy(dp, v, 2);
148.2259 -                        }
148.2260 -                     }
148.2261 -                  }
148.2262 -                  else if (width)  // pass == 4 or 5
148.2263 -                  {
148.2264 -                     int width_mmx = ((width >> 1) << 1) ;
148.2265 -                     width -= width_mmx;        // 0,1 pixels => 0,2 bytes
148.2266 -                     if (width_mmx)
148.2267 -                     {
148.2268 -                        int dummy_value_c;  // fix 'forbidden register spilled'
148.2269 -                        int dummy_value_S;
148.2270 -                        int dummy_value_D;
148.2271 -
148.2272 -                        __asm__ __volatile__ (
148.2273 -                           "subl $2, %%esi          \n\t"
148.2274 -                           "subl $6, %%edi          \n\t"
148.2275 -
148.2276 -                        ".loop2_pass4:              \n\t"
148.2277 -                           "movd (%%esi), %%mm0     \n\t" // x x x x 3 2 1 0
148.2278 -                           "punpcklwd %%mm0, %%mm0  \n\t" // 3 2 3 2 1 0 1 0
148.2279 -                           "subl $4, %%esi          \n\t"
148.2280 -                           "movq %%mm0, (%%edi)     \n\t"
148.2281 -                           "subl $8, %%edi          \n\t"
148.2282 -                           "subl $2, %%ecx          \n\t"
148.2283 -                           "jnz .loop2_pass4        \n\t"
148.2284 -                           "EMMS                    \n\t" // DONE
148.2285 -
148.2286 -                           : "=c" (dummy_value_c),        // output regs (dummy)
148.2287 -                             "=S" (dummy_value_S),
148.2288 -                             "=D" (dummy_value_D)
148.2289 -
148.2290 -                           : "1" (sptr),      // esi      // input regs
148.2291 -                             "2" (dp),        // edi
148.2292 -                             "0" (width_mmx)  // ecx
148.2293 -
148.2294 -#if 0  /* %mm0 not supported by gcc 2.7.2.3 or egcs 1.1 */
148.2295 -                           : "%mm0"                       // clobber list
148.2296 -#endif
148.2297 -                        );
148.2298 -                     }
148.2299 -
148.2300 -                     sptr -= (width_mmx*2 - 2); // sign fixed
148.2301 -                     dp -= (width_mmx*4 - 2);   // sign fixed
148.2302 -                     for (i = width; i; i--)
148.2303 -                     {
148.2304 -                        png_byte v[8];
148.2305 -                        int j;
148.2306 -                        sptr -= 2;
148.2307 -                        png_memcpy(v, sptr, 2);
148.2308 -                        for (j = 0; j < png_pass_inc[pass]; j++)
148.2309 -                        {
148.2310 -                           dp -= 2;
148.2311 -                           png_memcpy(dp, v, 2);
148.2312 -                        }
148.2313 -                     }
148.2314 -                  }
148.2315 -               } /* end of pixel_bytes == 2 */
148.2316 -
148.2317 -               //--------------------------------------------------------------
148.2318 -               else if (pixel_bytes == 4)
148.2319 -               {
148.2320 -                  if (((pass == 0) || (pass == 1)) && width)
148.2321 -                  {
148.2322 -                     int width_mmx = ((width >> 1) << 1);
148.2323 -                     width -= width_mmx;        // 0,1 pixels => 0,4 bytes
148.2324 -                     if (width_mmx)
148.2325 -                     {
148.2326 -                        int dummy_value_c;  // fix 'forbidden register spilled'
148.2327 -                        int dummy_value_S;
148.2328 -                        int dummy_value_D;
148.2329 -
148.2330 -                        __asm__ __volatile__ (
148.2331 -                           "subl $4, %%esi          \n\t"
148.2332 -                           "subl $60, %%edi         \n\t"
148.2333 -
148.2334 -                        ".loop4_pass0:              \n\t"
148.2335 -                           "movq (%%esi), %%mm0     \n\t" // 7 6 5 4 3 2 1 0
148.2336 -                           "movq %%mm0, %%mm1       \n\t" // 7 6 5 4 3 2 1 0
148.2337 -                           "punpckldq %%mm0, %%mm0  \n\t" // 3 2 1 0 3 2 1 0
148.2338 -                           "punpckhdq %%mm1, %%mm1  \n\t" // 7 6 5 4 7 6 5 4
148.2339 -                           "movq %%mm0, (%%edi)     \n\t"
148.2340 -                           "movq %%mm0, 8(%%edi)    \n\t"
148.2341 -                           "movq %%mm0, 16(%%edi)   \n\t"
148.2342 -                           "movq %%mm0, 24(%%edi)   \n\t"
148.2343 -                           "movq %%mm1, 32(%%edi)   \n\t"
148.2344 -                           "movq %%mm1, 40(%%edi)   \n\t"
148.2345 -                           "movq %%mm1, 48(%%edi)   \n\t"
148.2346 -                           "subl $8, %%esi          \n\t"
148.2347 -                           "movq %%mm1, 56(%%edi)   \n\t"
148.2348 -                           "subl $64, %%edi         \n\t"
148.2349 -                           "subl $2, %%ecx          \n\t"
148.2350 -                           "jnz .loop4_pass0        \n\t"
148.2351 -                           "EMMS                    \n\t" // DONE
148.2352 -
148.2353 -                           : "=c" (dummy_value_c),        // output regs (dummy)
148.2354 -                             "=S" (dummy_value_S),
148.2355 -                             "=D" (dummy_value_D)
148.2356 -
148.2357 -                           : "1" (sptr),      // esi      // input regs
148.2358 -                             "2" (dp),        // edi
148.2359 -                             "0" (width_mmx)  // ecx
148.2360 -
148.2361 -#if 0  /* %mm0, %mm1 not supported by gcc 2.7.2.3 or egcs 1.1 */
148.2362 -                           : "%mm0", "%mm1"               // clobber list
148.2363 -#endif
148.2364 -                        );
148.2365 -                     }
148.2366 -
148.2367 -                     sptr -= (width_mmx*4 - 4); // sign fixed
148.2368 -                     dp -= (width_mmx*32 - 4);  // sign fixed
148.2369 -                     for (i = width; i; i--)
148.2370 -                     {
148.2371 -                        png_byte v[8];
148.2372 -                        int j;
148.2373 -                        sptr -= 4;
148.2374 -                        png_memcpy(v, sptr, 4);
148.2375 -                        for (j = 0; j < png_pass_inc[pass]; j++)
148.2376 -                        {
148.2377 -                           dp -= 4;
148.2378 -                           png_memcpy(dp, v, 4);
148.2379 -                        }
148.2380 -                     }
148.2381 -                  }
148.2382 -                  else if (((pass == 2) || (pass == 3)) && width)
148.2383 -                  {
148.2384 -                     int width_mmx = ((width >> 1) << 1);
148.2385 -                     width -= width_mmx;        // 0,1 pixels => 0,4 bytes
148.2386 -                     if (width_mmx)
148.2387 -                     {
148.2388 -                        int dummy_value_c;  // fix 'forbidden register spilled'
148.2389 -                        int dummy_value_S;
148.2390 -                        int dummy_value_D;
148.2391 -
148.2392 -                        __asm__ __volatile__ (
148.2393 -                           "subl $4, %%esi          \n\t"
148.2394 -                           "subl $28, %%edi         \n\t"
148.2395 -
148.2396 -                        ".loop4_pass2:              \n\t"
148.2397 -                           "movq (%%esi), %%mm0     \n\t" // 7 6 5 4 3 2 1 0
148.2398 -                           "movq %%mm0, %%mm1       \n\t" // 7 6 5 4 3 2 1 0
148.2399 -                           "punpckldq %%mm0, %%mm0  \n\t" // 3 2 1 0 3 2 1 0
148.2400 -                           "punpckhdq %%mm1, %%mm1  \n\t" // 7 6 5 4 7 6 5 4
148.2401 -                           "movq %%mm0, (%%edi)     \n\t"
148.2402 -                           "movq %%mm0, 8(%%edi)    \n\t"
148.2403 -                           "movq %%mm1, 16(%%edi)   \n\t"
148.2404 -                           "movq %%mm1, 24(%%edi)   \n\t"
148.2405 -                           "subl $8, %%esi          \n\t"
148.2406 -                           "subl $32, %%edi         \n\t"
148.2407 -                           "subl $2, %%ecx          \n\t"
148.2408 -                           "jnz .loop4_pass2        \n\t"
148.2409 -                           "EMMS                    \n\t" // DONE
148.2410 -
148.2411 -                           : "=c" (dummy_value_c),        // output regs (dummy)
148.2412 -                             "=S" (dummy_value_S),
148.2413 -                             "=D" (dummy_value_D)
148.2414 -
148.2415 -                           : "1" (sptr),      // esi      // input regs
148.2416 -                             "2" (dp),        // edi
148.2417 -                             "0" (width_mmx)  // ecx
148.2418 -
148.2419 -#if 0  /* %mm0, %mm1 not supported by gcc 2.7.2.3 or egcs 1.1 */
148.2420 -                           : "%mm0", "%mm1"               // clobber list
148.2421 -#endif
148.2422 -                        );
148.2423 -                     }
148.2424 -
148.2425 -                     sptr -= (width_mmx*4 - 4); // sign fixed
148.2426 -                     dp -= (width_mmx*16 - 4);  // sign fixed
148.2427 -                     for (i = width; i; i--)
148.2428 -                     {
148.2429 -                        png_byte v[8];
148.2430 -                        int j;
148.2431 -                        sptr -= 4;
148.2432 -                        png_memcpy(v, sptr, 4);
148.2433 -                        for (j = 0; j < png_pass_inc[pass]; j++)
148.2434 -                        {
148.2435 -                           dp -= 4;
148.2436 -                           png_memcpy(dp, v, 4);
148.2437 -                        }
148.2438 -                     }
148.2439 -                  }
148.2440 -                  else if (width)  // pass == 4 or 5
148.2441 -                  {
148.2442 -                     int width_mmx = ((width >> 1) << 1) ;
148.2443 -                     width -= width_mmx;        // 0,1 pixels => 0,4 bytes
148.2444 -                     if (width_mmx)
148.2445 -                     {
148.2446 -                        int dummy_value_c;  // fix 'forbidden register spilled'
148.2447 -                        int dummy_value_S;
148.2448 -                        int dummy_value_D;
148.2449 -
148.2450 -                        __asm__ __volatile__ (
148.2451 -                           "subl $4, %%esi          \n\t"
148.2452 -                           "subl $12, %%edi         \n\t"
148.2453 -
148.2454 -                        ".loop4_pass4:              \n\t"
148.2455 -                           "movq (%%esi), %%mm0     \n\t" // 7 6 5 4 3 2 1 0
148.2456 -                           "movq %%mm0, %%mm1       \n\t" // 7 6 5 4 3 2 1 0
148.2457 -                           "punpckldq %%mm0, %%mm0  \n\t" // 3 2 1 0 3 2 1 0
148.2458 -                           "punpckhdq %%mm1, %%mm1  \n\t" // 7 6 5 4 7 6 5 4
148.2459 -                           "movq %%mm0, (%%edi)     \n\t"
148.2460 -                           "subl $8, %%esi          \n\t"
148.2461 -                           "movq %%mm1, 8(%%edi)    \n\t"
148.2462 -                           "subl $16, %%edi         \n\t"
148.2463 -                           "subl $2, %%ecx          \n\t"
148.2464 -                           "jnz .loop4_pass4        \n\t"
148.2465 -                           "EMMS                    \n\t" // DONE
148.2466 -
148.2467 -                           : "=c" (dummy_value_c),        // output regs (dummy)
148.2468 -                             "=S" (dummy_value_S),
148.2469 -                             "=D" (dummy_value_D)
148.2470 -
148.2471 -                           : "1" (sptr),      // esi      // input regs
148.2472 -                             "2" (dp),        // edi
148.2473 -                             "0" (width_mmx)  // ecx
148.2474 -
148.2475 -#if 0  /* %mm0, %mm1 not supported by gcc 2.7.2.3 or egcs 1.1 */
148.2476 -                           : "%mm0", "%mm1"               // clobber list
148.2477 -#endif
148.2478 -                        );
148.2479 -                     }
148.2480 -
148.2481 -                     sptr -= (width_mmx*4 - 4); // sign fixed
148.2482 -                     dp -= (width_mmx*8 - 4);   // sign fixed
148.2483 -                     for (i = width; i; i--)
148.2484 -                     {
148.2485 -                        png_byte v[8];
148.2486 -                        int j;
148.2487 -                        sptr -= 4;
148.2488 -                        png_memcpy(v, sptr, 4);
148.2489 -                        for (j = 0; j < png_pass_inc[pass]; j++)
148.2490 -                        {
148.2491 -                           dp -= 4;
148.2492 -                           png_memcpy(dp, v, 4);
148.2493 -                        }
148.2494 -                     }
148.2495 -                  }
148.2496 -               } /* end of pixel_bytes == 4 */
148.2497 -
148.2498 -               //--------------------------------------------------------------
148.2499 -               else if (pixel_bytes == 8)
148.2500 -               {
148.2501 -// GRR TEST:  should work, but needs testing (special 64-bit version of rpng2?)
148.2502 -                  // GRR NOTE:  no need to combine passes here!
148.2503 -                  if (((pass == 0) || (pass == 1)) && width)
148.2504 -                  {
148.2505 -                     int dummy_value_c;  // fix 'forbidden register spilled'
148.2506 -                     int dummy_value_S;
148.2507 -                     int dummy_value_D;
148.2508 -
148.2509 -                     // source is 8-byte RRGGBBAA
148.2510 -                     // dest is 64-byte RRGGBBAA RRGGBBAA RRGGBBAA RRGGBBAA ...
148.2511 -                     __asm__ __volatile__ (
148.2512 -                        "subl $56, %%edi         \n\t" // start of last block
148.2513 -
148.2514 -                     ".loop8_pass0:              \n\t"
148.2515 -                        "movq (%%esi), %%mm0     \n\t" // 7 6 5 4 3 2 1 0
148.2516 -                        "movq %%mm0, (%%edi)     \n\t"
148.2517 -                        "movq %%mm0, 8(%%edi)    \n\t"
148.2518 -                        "movq %%mm0, 16(%%edi)   \n\t"
148.2519 -                        "movq %%mm0, 24(%%edi)   \n\t"
148.2520 -                        "movq %%mm0, 32(%%edi)   \n\t"
148.2521 -                        "movq %%mm0, 40(%%edi)   \n\t"
148.2522 -                        "movq %%mm0, 48(%%edi)   \n\t"
148.2523 -                        "subl $8, %%esi          \n\t"
148.2524 -                        "movq %%mm0, 56(%%edi)   \n\t"
148.2525 -                        "subl $64, %%edi         \n\t"
148.2526 -                        "decl %%ecx              \n\t"
148.2527 -                        "jnz .loop8_pass0        \n\t"
148.2528 -                        "EMMS                    \n\t" // DONE
148.2529 -
148.2530 -                        : "=c" (dummy_value_c),        // output regs (dummy)
148.2531 -                          "=S" (dummy_value_S),
148.2532 -                          "=D" (dummy_value_D)
148.2533 -
148.2534 -                        : "1" (sptr),      // esi      // input regs
148.2535 -                          "2" (dp),        // edi
148.2536 -                          "0" (width)      // ecx
148.2537 -
148.2538 -#if 0  /* %mm0 not supported by gcc 2.7.2.3 or egcs 1.1 */
148.2539 -                        : "%mm0"                       // clobber list
148.2540 -#endif
148.2541 -                     );
148.2542 -                  }
148.2543 -                  else if (((pass == 2) || (pass == 3)) && width)
148.2544 -                  {
148.2545 -                     // source is 8-byte RRGGBBAA
148.2546 -                     // dest is 32-byte RRGGBBAA RRGGBBAA RRGGBBAA RRGGBBAA
148.2547 -                     // (recall that expansion is _in place_:  sptr and dp
148.2548 -                     //  both point at locations within same row buffer)
148.2549 -                     {
148.2550 -                        int dummy_value_c;  // fix 'forbidden register spilled'
148.2551 -                        int dummy_value_S;
148.2552 -                        int dummy_value_D;
148.2553 -
148.2554 -                        __asm__ __volatile__ (
148.2555 -                           "subl $24, %%edi         \n\t" // start of last block
148.2556 -
148.2557 -                        ".loop8_pass2:              \n\t"
148.2558 -                           "movq (%%esi), %%mm0     \n\t" // 7 6 5 4 3 2 1 0
148.2559 -                           "movq %%mm0, (%%edi)     \n\t"
148.2560 -                           "movq %%mm0, 8(%%edi)    \n\t"
148.2561 -                           "movq %%mm0, 16(%%edi)   \n\t"
148.2562 -                           "subl $8, %%esi          \n\t"
148.2563 -                           "movq %%mm0, 24(%%edi)   \n\t"
148.2564 -                           "subl $32, %%edi         \n\t"
148.2565 -                           "decl %%ecx              \n\t"
148.2566 -                           "jnz .loop8_pass2        \n\t"
148.2567 -                           "EMMS                    \n\t" // DONE
148.2568 -
148.2569 -                           : "=c" (dummy_value_c),        // output regs (dummy)
148.2570 -                             "=S" (dummy_value_S),
148.2571 -                             "=D" (dummy_value_D)
148.2572 -
148.2573 -                           : "1" (sptr),      // esi      // input regs
148.2574 -                             "2" (dp),        // edi
148.2575 -                             "0" (width)      // ecx
148.2576 -
148.2577 -#if 0  /* %mm0 not supported by gcc 2.7.2.3 or egcs 1.1 */
148.2578 -                           : "%mm0"                       // clobber list
148.2579 -#endif
148.2580 -                        );
148.2581 -                     }
148.2582 -                  }
148.2583 -                  else if (width)  // pass == 4 or 5
148.2584 -                  {
148.2585 -                     // source is 8-byte RRGGBBAA
148.2586 -                     // dest is 16-byte RRGGBBAA RRGGBBAA
148.2587 -                     {
148.2588 -                        int dummy_value_c;  // fix 'forbidden register spilled'
148.2589 -                        int dummy_value_S;
148.2590 -                        int dummy_value_D;
148.2591 -
148.2592 -                        __asm__ __volatile__ (
148.2593 -                           "subl $8, %%edi          \n\t" // start of last block
148.2594 -
148.2595 -                        ".loop8_pass4:              \n\t"
148.2596 -                           "movq (%%esi), %%mm0     \n\t" // 7 6 5 4 3 2 1 0
148.2597 -                           "movq %%mm0, (%%edi)     \n\t"
148.2598 -                           "subl $8, %%esi          \n\t"
148.2599 -                           "movq %%mm0, 8(%%edi)    \n\t"
148.2600 -                           "subl $16, %%edi         \n\t"
148.2601 -                           "decl %%ecx              \n\t"
148.2602 -                           "jnz .loop8_pass4        \n\t"
148.2603 -                           "EMMS                    \n\t" // DONE
148.2604 -
148.2605 -                           : "=c" (dummy_value_c),        // output regs (dummy)
148.2606 -                             "=S" (dummy_value_S),
148.2607 -                             "=D" (dummy_value_D)
148.2608 -
148.2609 -                           : "1" (sptr),      // esi      // input regs
148.2610 -                             "2" (dp),        // edi
148.2611 -                             "0" (width)      // ecx
148.2612 -
148.2613 -#if 0  /* %mm0 not supported by gcc 2.7.2.3 or egcs 1.1 */
148.2614 -                           : "%mm0"                       // clobber list
148.2615 -#endif
148.2616 -                        );
148.2617 -                     }
148.2618 -                  }
148.2619 -
148.2620 -               } /* end of pixel_bytes == 8 */
148.2621 -
148.2622 -               //--------------------------------------------------------------
148.2623 -               else if (pixel_bytes == 6)
148.2624 -               {
148.2625 -                  for (i = width; i; i--)
148.2626 -                  {
148.2627 -                     png_byte v[8];
148.2628 -                     int j;
148.2629 -                     png_memcpy(v, sptr, 6);
148.2630 -                     for (j = 0; j < png_pass_inc[pass]; j++)
148.2631 -                     {
148.2632 -                        png_memcpy(dp, v, 6);
148.2633 -                        dp -= 6;
148.2634 -                     }
148.2635 -                     sptr -= 6;
148.2636 -                  }
148.2637 -               } /* end of pixel_bytes == 6 */
148.2638 -
148.2639 -               //--------------------------------------------------------------
148.2640 -               else
148.2641 -               {
148.2642 -                  for (i = width; i; i--)
148.2643 -                  {
148.2644 -                     png_byte v[8];
148.2645 -                     int j;
148.2646 -                     png_memcpy(v, sptr, pixel_bytes);
148.2647 -                     for (j = 0; j < png_pass_inc[pass]; j++)
148.2648 -                     {
148.2649 -                        png_memcpy(dp, v, pixel_bytes);
148.2650 -                        dp -= pixel_bytes;
148.2651 -                     }
148.2652 -                     sptr-= pixel_bytes;
148.2653 -                  }
148.2654 -               }
148.2655 -            } // end of _mmx_supported ========================================
148.2656 -
148.2657 -            else /* MMX not supported:  use modified C code - takes advantage
148.2658 -                  *   of inlining of png_memcpy for a constant */
148.2659 -                 /* GRR 19991007:  does it?  or should pixel_bytes in each
148.2660 -                  *   block be replaced with immediate value (e.g., 1)? */
148.2661 -                 /* GRR 19991017:  replaced with constants in each case */
148.2662 -#endif /* PNG_MMX_CODE_SUPPORTED */
148.2663 -            {
148.2664 -               if (pixel_bytes == 1)
148.2665 -               {
148.2666 -                  for (i = width; i; i--)
148.2667 -                  {
148.2668 -                     int j;
148.2669 -                     for (j = 0; j < png_pass_inc[pass]; j++)
148.2670 -                     {
148.2671 -                        *dp-- = *sptr;
148.2672 -                     }
148.2673 -                     --sptr;
148.2674 -                  }
148.2675 -               }
148.2676 -               else if (pixel_bytes == 3)
148.2677 -               {
148.2678 -                  for (i = width; i; i--)
148.2679 -                  {
148.2680 -                     png_byte v[8];
148.2681 -                     int j;
148.2682 -                     png_memcpy(v, sptr, 3);
148.2683 -                     for (j = 0; j < png_pass_inc[pass]; j++)
148.2684 -                     {
148.2685 -                        png_memcpy(dp, v, 3);
148.2686 -                        dp -= 3;
148.2687 -                     }
148.2688 -                     sptr -= 3;
148.2689 -                  }
148.2690 -               }
148.2691 -               else if (pixel_bytes == 2)
148.2692 -               {
148.2693 -                  for (i = width; i; i--)
148.2694 -                  {
148.2695 -                     png_byte v[8];
148.2696 -                     int j;
148.2697 -                     png_memcpy(v, sptr, 2);
148.2698 -                     for (j = 0; j < png_pass_inc[pass]; j++)
148.2699 -                     {
148.2700 -                        png_memcpy(dp, v, 2);
148.2701 -                        dp -= 2;
148.2702 -                     }
148.2703 -                     sptr -= 2;
148.2704 -                  }
148.2705 -               }
148.2706 -               else if (pixel_bytes == 4)
148.2707 -               {
148.2708 -                  for (i = width; i; i--)
148.2709 -                  {
148.2710 -                     png_byte v[8];
148.2711 -                     int j;
148.2712 -                     png_memcpy(v, sptr, 4);
148.2713 -                     for (j = 0; j < png_pass_inc[pass]; j++)
148.2714 -                     {
148.2715 -#ifdef PNG_DEBUG
148.2716 -                        if (dp < row || dp+3 > row+png_ptr->row_buf_size)
148.2717 -                        {
148.2718 -                           printf("dp out of bounds: row=%d, dp=%d, rp=%d\n",
148.2719 -                             row, dp, row+png_ptr->row_buf_size);
148.2720 -                           printf("row_buf=%d\n",png_ptr->row_buf_size);
148.2721 -                        }
148.2722 -#endif
148.2723 -                        png_memcpy(dp, v, 4);
148.2724 -                        dp -= 4;
148.2725 -                     }
148.2726 -                     sptr -= 4;
148.2727 -                  }
148.2728 -               }
148.2729 -               else if (pixel_bytes == 6)
148.2730 -               {
148.2731 -                  for (i = width; i; i--)
148.2732 -                  {
148.2733 -                     png_byte v[8];
148.2734 -                     int j;
148.2735 -                     png_memcpy(v, sptr, 6);
148.2736 -                     for (j = 0; j < png_pass_inc[pass]; j++)
148.2737 -                     {
148.2738 -                        png_memcpy(dp, v, 6);
148.2739 -                        dp -= 6;
148.2740 -                     }
148.2741 -                     sptr -= 6;
148.2742 -                  }
148.2743 -               }
148.2744 -               else if (pixel_bytes == 8)
148.2745 -               {
148.2746 -                  for (i = width; i; i--)
148.2747 -                  {
148.2748 -                     png_byte v[8];
148.2749 -                     int j;
148.2750 -                     png_memcpy(v, sptr, 8);
148.2751 -                     for (j = 0; j < png_pass_inc[pass]; j++)
148.2752 -                     {
148.2753 -                        png_memcpy(dp, v, 8);
148.2754 -                        dp -= 8;
148.2755 -                     }
148.2756 -                     sptr -= 8;
148.2757 -                  }
148.2758 -               }
148.2759 -               else     /* GRR:  should never be reached */
148.2760 -               {
148.2761 -                  for (i = width; i; i--)
148.2762 -                  {
148.2763 -                     png_byte v[8];
148.2764 -                     int j;
148.2765 -                     png_memcpy(v, sptr, pixel_bytes);
148.2766 -                     for (j = 0; j < png_pass_inc[pass]; j++)
148.2767 -                     {
148.2768 -                        png_memcpy(dp, v, pixel_bytes);
148.2769 -                        dp -= pixel_bytes;
148.2770 -                     }
148.2771 -                     sptr -= pixel_bytes;
148.2772 -                  }
148.2773 -               }
148.2774 -
148.2775 -            } /* end if (MMX not supported) */
148.2776 -            break;
148.2777 -         }
148.2778 -      } /* end switch (row_info->pixel_depth) */
148.2779 -
148.2780 -      row_info->width = final_width;
148.2781 -
148.2782 -      row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,final_width);
148.2783 -   }
148.2784 -
148.2785 -} /* end png_do_read_interlace() */
148.2786 -
148.2787 -#endif /* PNG_HAVE_MMX_READ_INTERLACE */
148.2788 -#endif /* PNG_READ_INTERLACING_SUPPORTED */
148.2789 -
148.2790 -
148.2791 -
148.2792 -#if defined(PNG_HAVE_MMX_READ_FILTER_ROW)
148.2793 -#if defined(PNG_MMX_CODE_SUPPORTED)
148.2794 -
148.2795 -// These variables are utilized in the functions below.  They are declared
148.2796 -// globally here to ensure alignment on 8-byte boundaries.
148.2797 -
148.2798 -union uAll {
148.2799 -   long long use;
148.2800 -   double  align;
148.2801 -} _LBCarryMask = {0x0101010101010101LL},
148.2802 -  _HBClearMask = {0x7f7f7f7f7f7f7f7fLL},
148.2803 -  _ActiveMask, _ActiveMask2, _ActiveMaskEnd, _ShiftBpp, _ShiftRem;
148.2804 -
148.2805 -#ifdef PNG_THREAD_UNSAFE_OK
148.2806 -//===========================================================================//
148.2807 -//                                                                           //
148.2808 -//           P N G _ R E A D _ F I L T E R _ R O W _ M M X _ A V G           //
148.2809 -//                                                                           //
148.2810 -//===========================================================================//
148.2811 -
148.2812 -// Optimized code for PNG Average filter decoder
148.2813 -
148.2814 -static void /* PRIVATE */
148.2815 -png_read_filter_row_mmx_avg(png_row_infop row_info, png_bytep row,
148.2816 -                            png_bytep prev_row)
148.2817 -{
148.2818 -   int bpp;
148.2819 -   int dummy_value_c;   // fix 'forbidden register 2 (cx) was spilled' error
148.2820 -   int dummy_value_S;
148.2821 -   int dummy_value_D;
148.2822 -
148.2823 -   bpp = (row_info->pixel_depth + 7) >> 3;  // get # bytes per pixel
148.2824 -   _FullLength  = row_info->rowbytes;       // # of bytes to filter
148.2825 -
148.2826 -   __asm__ __volatile__ (
148.2827 -      // initialize address pointers and offset
148.2828 -#ifdef __PIC__
148.2829 -      "pushl %%ebx                 \n\t" // save index to Global Offset Table
148.2830 -#endif
148.2831 -//pre "movl row, %%edi             \n\t" // edi:  Avg(x)
148.2832 -      "xorl %%ebx, %%ebx           \n\t" // ebx:  x
148.2833 -      "movl %%edi, %%edx           \n\t"
148.2834 -//pre "movl prev_row, %%esi        \n\t" // esi:  Prior(x)
148.2835 -//pre "subl bpp, %%edx             \n\t" // (bpp is preloaded into ecx)
148.2836 -      "subl %%ecx, %%edx           \n\t" // edx:  Raw(x-bpp)
148.2837 -
148.2838 -      "xorl %%eax,%%eax            \n\t"
148.2839 -
148.2840 -      // Compute the Raw value for the first bpp bytes
148.2841 -      //    Raw(x) = Avg(x) + (Prior(x)/2)
148.2842 -   "avg_rlp:                       \n\t"
148.2843 -      "movb (%%esi,%%ebx,),%%al    \n\t" // load al with Prior(x)
148.2844 -      "incl %%ebx                  \n\t"
148.2845 -      "shrb %%al                   \n\t" // divide by 2
148.2846 -      "addb -1(%%edi,%%ebx,),%%al  \n\t" // add Avg(x); -1 to offset inc ebx
148.2847 -//pre "cmpl bpp, %%ebx             \n\t" // (bpp is preloaded into ecx)
148.2848 -      "cmpl %%ecx, %%ebx           \n\t"
148.2849 -      "movb %%al,-1(%%edi,%%ebx,)  \n\t" // write Raw(x); -1 to offset inc ebx
148.2850 -      "jb avg_rlp                  \n\t" // mov does not affect flags
148.2851 -
148.2852 -      // get # of bytes to alignment
148.2853 -      "movl %%edi, _dif            \n\t" // take start of row
148.2854 -      "addl %%ebx, _dif            \n\t" // add bpp
148.2855 -      "addl $0xf, _dif             \n\t" // add 7+8 to incr past alignment bdry
148.2856 -      "andl $0xfffffff8, _dif      \n\t" // mask to alignment boundary
148.2857 -      "subl %%edi, _dif            \n\t" // subtract from start => value ebx at
148.2858 -      "jz avg_go                   \n\t" //  alignment
148.2859 -
148.2860 -      // fix alignment
148.2861 -      // Compute the Raw value for the bytes up to the alignment boundary
148.2862 -      //    Raw(x) = Avg(x) + ((Raw(x-bpp) + Prior(x))/2)
148.2863 -      "xorl %%ecx, %%ecx           \n\t"
148.2864 -
148.2865 -   "avg_lp1:                       \n\t"
148.2866 -      "xorl %%eax, %%eax           \n\t"
148.2867 -      "movb (%%esi,%%ebx,), %%cl   \n\t" // load cl with Prior(x)
148.2868 -      "movb (%%edx,%%ebx,), %%al   \n\t" // load al with Raw(x-bpp)
148.2869 -      "addw %%cx, %%ax             \n\t"
148.2870 -      "incl %%ebx                  \n\t"
148.2871 -      "shrw %%ax                   \n\t" // divide by 2
148.2872 -      "addb -1(%%edi,%%ebx,), %%al \n\t" // add Avg(x); -1 to offset inc ebx
148.2873 -      "cmpl _dif, %%ebx            \n\t" // check if at alignment boundary
148.2874 -      "movb %%al, -1(%%edi,%%ebx,) \n\t" // write Raw(x); -1 to offset inc ebx
148.2875 -      "jb avg_lp1                  \n\t" // repeat until at alignment boundary
148.2876 -
148.2877 -   "avg_go:                        \n\t"
148.2878 -      "movl _FullLength, %%eax     \n\t"
148.2879 -      "movl %%eax, %%ecx           \n\t"
148.2880 -      "subl %%ebx, %%eax           \n\t" // subtract alignment fix
148.2881 -      "andl $0x00000007, %%eax     \n\t" // calc bytes over mult of 8
148.2882 -      "subl %%eax, %%ecx           \n\t" // drop over bytes from original length
148.2883 -      "movl %%ecx, _MMXLength      \n\t"
148.2884 -#ifdef __PIC__
148.2885 -      "popl %%ebx                  \n\t" // restore index to Global Offset Table
148.2886 -#endif
148.2887 -
148.2888 -      : "=c" (dummy_value_c),            // output regs (dummy)
148.2889 -        "=S" (dummy_value_S),
148.2890 -        "=D" (dummy_value_D)
148.2891 -
148.2892 -      : "0" (bpp),       // ecx          // input regs
148.2893 -        "1" (prev_row),  // esi
148.2894 -        "2" (row)        // edi
148.2895 -
148.2896 -      : "%eax", "%edx"                   // clobber list
148.2897 -#ifndef __PIC__
148.2898 -      , "%ebx"
148.2899 -#endif
148.2900 -      // GRR: INCLUDE "memory" as clobbered? (_dif, _MMXLength)
148.2901 -      // (seems to work fine without...)
148.2902 -   );
148.2903 -
148.2904 -   // now do the math for the rest of the row
148.2905 -   switch (bpp)
148.2906 -   {
148.2907 -      case 3:
148.2908 -      {
148.2909 -         _ActiveMask.use  = 0x0000000000ffffffLL;
148.2910 -         _ShiftBpp.use = 24;    // == 3 * 8
148.2911 -         _ShiftRem.use = 40;    // == 64 - 24
148.2912 -
148.2913 -         __asm__ __volatile__ (
148.2914 -            // re-init address pointers and offset
148.2915 -            "movq _ActiveMask, %%mm7      \n\t"
148.2916 -            "movl _dif, %%ecx             \n\t" // ecx:  x = offset to
148.2917 -            "movq _LBCarryMask, %%mm5     \n\t" //  alignment boundary
148.2918 -// preload  "movl row, %%edi              \n\t" // edi:  Avg(x)
148.2919 -            "movq _HBClearMask, %%mm4     \n\t"
148.2920 -// preload  "movl prev_row, %%esi         \n\t" // esi:  Prior(x)
148.2921 -
148.2922 -            // prime the pump:  load the first Raw(x-bpp) data set
148.2923 -            "movq -8(%%edi,%%ecx,), %%mm2 \n\t" // load previous aligned 8 bytes
148.2924 -                                                // (correct pos. in loop below)
148.2925 -         "avg_3lp:                        \n\t"
148.2926 -            "movq (%%edi,%%ecx,), %%mm0   \n\t" // load mm0 with Avg(x)
148.2927 -            "movq %%mm5, %%mm3            \n\t"
148.2928 -            "psrlq _ShiftRem, %%mm2       \n\t" // correct position Raw(x-bpp)
148.2929 -                                                // data
148.2930 -            "movq (%%esi,%%ecx,), %%mm1   \n\t" // load mm1 with Prior(x)
148.2931 -            "movq %%mm7, %%mm6            \n\t"
148.2932 -            "pand %%mm1, %%mm3            \n\t" // get lsb for each prev_row byte
148.2933 -            "psrlq $1, %%mm1              \n\t" // divide prev_row bytes by 2
148.2934 -            "pand  %%mm4, %%mm1           \n\t" // clear invalid bit 7 of each
148.2935 -                                                // byte
148.2936 -            "paddb %%mm1, %%mm0           \n\t" // add (Prev_row/2) to Avg for
148.2937 -                                                // each byte
148.2938 -            // add 1st active group (Raw(x-bpp)/2) to average with LBCarry
148.2939 -            "movq %%mm3, %%mm1            \n\t" // now use mm1 for getting
148.2940 -                                                // LBCarrys
148.2941 -            "pand %%mm2, %%mm1            \n\t" // get LBCarrys for each byte
148.2942 -                                                // where both
148.2943 -                               // lsb's were == 1 (only valid for active group)
148.2944 -            "psrlq $1, %%mm2              \n\t" // divide raw bytes by 2
148.2945 -            "pand  %%mm4, %%mm2           \n\t" // clear invalid bit 7 of each
148.2946 -                                                // byte
148.2947 -            "paddb %%mm1, %%mm2           \n\t" // add LBCarrys to (Raw(x-bpp)/2)
148.2948 -                                                // for each byte
148.2949 -            "pand %%mm6, %%mm2            \n\t" // leave only Active Group 1
148.2950 -                                                // bytes to add to Avg
148.2951 -            "paddb %%mm2, %%mm0           \n\t" // add (Raw/2) + LBCarrys to
148.2952 -                                                // Avg for each Active
148.2953 -                               //  byte
148.2954 -            // add 2nd active group (Raw(x-bpp)/2) to average with _LBCarry
148.2955 -            "psllq _ShiftBpp, %%mm6       \n\t" // shift the mm6 mask to cover
148.2956 -                                                // bytes 3-5
148.2957 -            "movq %%mm0, %%mm2            \n\t" // mov updated Raws to mm2
148.2958 -            "psllq _ShiftBpp, %%mm2       \n\t" // shift data to pos. correctly
148.2959 -            "movq %%mm3, %%mm1            \n\t" // now use mm1 for getting
148.2960 -                                                // LBCarrys
148.2961 -            "pand %%mm2, %%mm1            \n\t" // get LBCarrys for each byte
148.2962 -                                                // where both
148.2963 -                               // lsb's were == 1 (only valid for active group)
148.2964 -            "psrlq $1, %%mm2              \n\t" // divide raw bytes by 2
148.2965 -            "pand  %%mm4, %%mm2           \n\t" // clear invalid bit 7 of each
148.2966 -                                                // byte
148.2967 -            "paddb %%mm1, %%mm2           \n\t" // add LBCarrys to (Raw(x-bpp)/2)
148.2968 -                                                // for each byte
148.2969 -            "pand %%mm6, %%mm2            \n\t" // leave only Active Group 2
148.2970 -                                                // bytes to add to Avg
148.2971 -            "paddb %%mm2, %%mm0           \n\t" // add (Raw/2) + LBCarrys to
148.2972 -                                                // Avg for each Active
148.2973 -                               //  byte
148.2974 -
148.2975 -            // add 3rd active group (Raw(x-bpp)/2) to average with _LBCarry
148.2976 -            "psllq _ShiftBpp, %%mm6       \n\t" // shift mm6 mask to cover last
148.2977 -                                                // two
148.2978 -                                 // bytes
148.2979 -            "movq %%mm0, %%mm2            \n\t" // mov updated Raws to mm2
148.2980 -            "psllq _ShiftBpp, %%mm2       \n\t" // shift data to pos. correctly
148.2981 -                              // Data only needs to be shifted once here to
148.2982 -                              // get the correct x-bpp offset.
148.2983 -            "movq %%mm3, %%mm1            \n\t" // now use mm1 for getting
148.2984 -                                                // LBCarrys
148.2985 -            "pand %%mm2, %%mm1            \n\t" // get LBCarrys for each byte
148.2986 -                                                // where both
148.2987 -                              // lsb's were == 1 (only valid for active group)
148.2988 -            "psrlq $1, %%mm2              \n\t" // divide raw bytes by 2
148.2989 -            "pand  %%mm4, %%mm2           \n\t" // clear invalid bit 7 of each
148.2990 -                                                // byte
148.2991 -            "paddb %%mm1, %%mm2           \n\t" // add LBCarrys to (Raw(x-bpp)/2)
148.2992 -                                                // for each byte
148.2993 -            "pand %%mm6, %%mm2            \n\t" // leave only Active Group 2
148.2994 -                                                // bytes to add to Avg
148.2995 -            "addl $8, %%ecx               \n\t"
148.2996 -            "paddb %%mm2, %%mm0           \n\t" // add (Raw/2) + LBCarrys to
148.2997 -                                                // Avg for each Active
148.2998 -                                                // byte
148.2999 -            // now ready to write back to memory
148.3000 -            "movq %%mm0, -8(%%edi,%%ecx,) \n\t"
148.3001 -            // move updated Raw(x) to use as Raw(x-bpp) for next loop
148.3002 -            "cmpl _MMXLength, %%ecx       \n\t"
148.3003 -            "movq %%mm0, %%mm2            \n\t" // mov updated Raw(x) to mm2
148.3004 -            "jb avg_3lp                   \n\t"
148.3005 -
148.3006 -            : "=S" (dummy_value_S),             // output regs (dummy)
148.3007 -              "=D" (dummy_value_D)
148.3008 -
148.3009 -            : "0" (prev_row),  // esi           // input regs
148.3010 -              "1" (row)        // edi
148.3011 -
148.3012 -            : "%ecx"                            // clobber list
148.3013 -#if 0  /* %mm0, ..., %mm7 not supported by gcc 2.7.2.3 or egcs 1.1 */
148.3014 -            , "%mm0", "%mm1", "%mm2", "%mm3"
148.3015 -            , "%mm4", "%mm5", "%mm6", "%mm7"
148.3016 -#endif
148.3017 -         );
148.3018 -      }
148.3019 -      break;  // end 3 bpp
148.3020 -
148.3021 -      case 6:
148.3022 -      case 4:
148.3023 -      //case 7:   // who wrote this?  PNG doesn't support 5 or 7 bytes/pixel
148.3024 -      //case 5:   // GRR BOGUS
148.3025 -      {
148.3026 -         _ActiveMask.use  = 0xffffffffffffffffLL; // use shift below to clear
148.3027 -                                                  // appropriate inactive bytes
148.3028 -         _ShiftBpp.use = bpp << 3;
148.3029 -         _ShiftRem.use = 64 - _ShiftBpp.use;
148.3030 -
148.3031 -         __asm__ __volatile__ (
148.3032 -            "movq _HBClearMask, %%mm4    \n\t"
148.3033 -
148.3034 -            // re-init address pointers and offset
148.3035 -            "movl _dif, %%ecx            \n\t" // ecx:  x = offset to
148.3036 -                                               // alignment boundary
148.3037 -
148.3038 -            // load _ActiveMask and clear all bytes except for 1st active group
148.3039 -            "movq _ActiveMask, %%mm7     \n\t"
148.3040 -// preload  "movl row, %%edi             \n\t" // edi:  Avg(x)
148.3041 -            "psrlq _ShiftRem, %%mm7      \n\t"
148.3042 -// preload  "movl prev_row, %%esi        \n\t" // esi:  Prior(x)
148.3043 -            "movq %%mm7, %%mm6           \n\t"
148.3044 -            "movq _LBCarryMask, %%mm5    \n\t"
148.3045 -            "psllq _ShiftBpp, %%mm6      \n\t" // create mask for 2nd active
148.3046 -                                               // group
148.3047 -
148.3048 -            // prime the pump:  load the first Raw(x-bpp) data set
148.3049 -            "movq -8(%%edi,%%ecx,), %%mm2 \n\t" // load previous aligned 8 bytes
148.3050 -                                          // (we correct pos. in loop below)
148.3051 -         "avg_4lp:                       \n\t"
148.3052 -            "movq (%%edi,%%ecx,), %%mm0  \n\t"
148.3053 -            "psrlq _ShiftRem, %%mm2      \n\t" // shift data to pos. correctly
148.3054 -            "movq (%%esi,%%ecx,), %%mm1  \n\t"
148.3055 -            // add (Prev_row/2) to average
148.3056 -            "movq %%mm5, %%mm3           \n\t"
148.3057 -            "pand %%mm1, %%mm3           \n\t" // get lsb for each prev_row byte
148.3058 -            "psrlq $1, %%mm1             \n\t" // divide prev_row bytes by 2
148.3059 -            "pand  %%mm4, %%mm1          \n\t" // clear invalid bit 7 of each
148.3060 -                                               // byte
148.3061 -            "paddb %%mm1, %%mm0          \n\t" // add (Prev_row/2) to Avg for
148.3062 -                                               // each byte
148.3063 -            // add 1st active group (Raw(x-bpp)/2) to average with _LBCarry
148.3064 -            "movq %%mm3, %%mm1           \n\t" // now use mm1 for getting
148.3065 -                                               // LBCarrys
148.3066 -            "pand %%mm2, %%mm1           \n\t" // get LBCarrys for each byte
148.3067 -                                               // where both
148.3068 -                              // lsb's were == 1 (only valid for active group)
148.3069 -            "psrlq $1, %%mm2             \n\t" // divide raw bytes by 2
148.3070 -            "pand  %%mm4, %%mm2          \n\t" // clear invalid bit 7 of each
148.3071 -                                               // byte
148.3072 -            "paddb %%mm1, %%mm2          \n\t" // add LBCarrys to (Raw(x-bpp)/2)
148.3073 -                                               // for each byte
148.3074 -            "pand %%mm7, %%mm2           \n\t" // leave only Active Group 1
148.3075 -                                               // bytes to add to Avg
148.3076 -            "paddb %%mm2, %%mm0          \n\t" // add (Raw/2) + LBCarrys to Avg
148.3077 -                                               // for each Active
148.3078 -                              // byte
148.3079 -            // add 2nd active group (Raw(x-bpp)/2) to average with _LBCarry
148.3080 -            "movq %%mm0, %%mm2           \n\t" // mov updated Raws to mm2
148.3081 -            "psllq _ShiftBpp, %%mm2      \n\t" // shift data to pos. correctly
148.3082 -            "addl $8, %%ecx              \n\t"
148.3083 -            "movq %%mm3, %%mm1           \n\t" // now use mm1 for getting
148.3084 -                                               // LBCarrys
148.3085 -            "pand %%mm2, %%mm1           \n\t" // get LBCarrys for each byte
148.3086 -                                               // where both
148.3087 -                              // lsb's were == 1 (only valid for active group)
148.3088 -            "psrlq $1, %%mm2             \n\t" // divide raw bytes by 2
148.3089 -            "pand  %%mm4, %%mm2          \n\t" // clear invalid bit 7 of each
148.3090 -                                               // byte
148.3091 -            "paddb %%mm1, %%mm2          \n\t" // add LBCarrys to (Raw(x-bpp)/2)
148.3092 -                                               // for each byte
148.3093 -            "pand %%mm6, %%mm2           \n\t" // leave only Active Group 2
148.3094 -                                               // bytes to add to Avg
148.3095 -            "paddb %%mm2, %%mm0          \n\t" // add (Raw/2) + LBCarrys to
148.3096 -                                               // Avg for each Active
148.3097 -                              // byte
148.3098 -            "cmpl _MMXLength, %%ecx      \n\t"
148.3099 -            // now ready to write back to memory
148.3100 -            "movq %%mm0, -8(%%edi,%%ecx,) \n\t"
148.3101 -            // prep Raw(x-bpp) for next loop
148.3102 -            "movq %%mm0, %%mm2           \n\t" // mov updated Raws to mm2
148.3103 -            "jb avg_4lp                  \n\t"
148.3104 -
148.3105 -            : "=S" (dummy_value_S),            // output regs (dummy)
148.3106 -              "=D" (dummy_value_D)
148.3107 -
148.3108 -            : "0" (prev_row),  // esi          // input regs
148.3109 -              "1" (row)        // edi
148.3110 -
148.3111 -            : "%ecx"                           // clobber list
148.3112 -#if 0  /* %mm0, ..., %mm7 not supported by gcc 2.7.2.3 or egcs 1.1 */
148.3113 -            , "%mm0", "%mm1", "%mm2", "%mm3"
148.3114 -            , "%mm4", "%mm5", "%mm6", "%mm7"
148.3115 -#endif
148.3116 -         );
148.3117 -      }
148.3118 -      break;  // end 4,6 bpp
148.3119 -
148.3120 -      case 2:
148.3121 -      {
148.3122 -         _ActiveMask.use  = 0x000000000000ffffLL;
148.3123 -         _ShiftBpp.use = 16;   // == 2 * 8
148.3124 -         _ShiftRem.use = 48;   // == 64 - 16
148.3125 -
148.3126 -         __asm__ __volatile__ (
148.3127 -            // load _ActiveMask
148.3128 -            "movq _ActiveMask, %%mm7     \n\t"
148.3129 -            // re-init address pointers and offset
148.3130 -            "movl _dif, %%ecx            \n\t" // ecx:  x = offset to alignment
148.3131 -                                               // boundary
148.3132 -            "movq _LBCarryMask, %%mm5    \n\t"
148.3133 -// preload  "movl row, %%edi             \n\t" // edi:  Avg(x)
148.3134 -            "movq _HBClearMask, %%mm4    \n\t"
148.3135 -// preload  "movl prev_row, %%esi        \n\t" // esi:  Prior(x)
148.3136 -
148.3137 -            // prime the pump:  load the first Raw(x-bpp) data set
148.3138 -            "movq -8(%%edi,%%ecx,), %%mm2 \n\t" // load previous aligned 8 bytes
148.3139 -                              // (we correct pos. in loop below)
148.3140 -         "avg_2lp:                       \n\t"
148.3141 -            "movq (%%edi,%%ecx,), %%mm0  \n\t"
148.3142 -            "psrlq _ShiftRem, %%mm2      \n\t" // shift data to pos. correctly
148.3143 -            "movq (%%esi,%%ecx,), %%mm1  \n\t" //  (GRR BUGFIX:  was psllq)
148.3144 -            // add (Prev_row/2) to average
148.3145 -            "movq %%mm5, %%mm3           \n\t"
148.3146 -            "pand %%mm1, %%mm3           \n\t" // get lsb for each prev_row byte
148.3147 -            "psrlq $1, %%mm1             \n\t" // divide prev_row bytes by 2
148.3148 -            "pand  %%mm4, %%mm1          \n\t" // clear invalid bit 7 of each
148.3149 -                                               // byte
148.3150 -            "movq %%mm7, %%mm6           \n\t"
148.3151 -            "paddb %%mm1, %%mm0          \n\t" // add (Prev_row/2) to Avg for
148.3152 -                                               // each byte
148.3153 -
148.3154 -            // add 1st active group (Raw(x-bpp)/2) to average with _LBCarry
148.3155 -            "movq %%mm3, %%mm1           \n\t" // now use mm1 for getting
148.3156 -                                               // LBCarrys
148.3157 -            "pand %%mm2, %%mm1           \n\t" // get LBCarrys for each byte
148.3158 -                                               // where both
148.3159 -                                               // lsb's were == 1 (only valid
148.3160 -                                               // for active group)
148.3161 -            "psrlq $1, %%mm2             \n\t" // divide raw bytes by 2
148.3162 -            "pand  %%mm4, %%mm2          \n\t" // clear invalid bit 7 of each
148.3163 -                                               // byte
148.3164 -            "paddb %%mm1, %%mm2          \n\t" // add LBCarrys to (Raw(x-bpp)/2)
148.3165 -                                               // for each byte
148.3166 -            "pand %%mm6, %%mm2           \n\t" // leave only Active Group 1
148.3167 -                                               // bytes to add to Avg
148.3168 -            "paddb %%mm2, %%mm0          \n\t" // add (Raw/2) + LBCarrys to Avg
148.3169 -                                               // for each Active byte
148.3170 -
148.3171 -            // add 2nd active group (Raw(x-bpp)/2) to average with _LBCarry
148.3172 -            "psllq _ShiftBpp, %%mm6      \n\t" // shift the mm6 mask to cover
148.3173 -                                               // bytes 2 & 3
148.3174 -            "movq %%mm0, %%mm2           \n\t" // mov updated Raws to mm2
148.3175 -            "psllq _ShiftBpp, %%mm2      \n\t" // shift data to pos. correctly
148.3176 -            "movq %%mm3, %%mm1           \n\t" // now use mm1 for getting
148.3177 -                                               // LBCarrys
148.3178 -            "pand %%mm2, %%mm1           \n\t" // get LBCarrys for each byte
148.3179 -                                               // where both
148.3180 -                                               // lsb's were == 1 (only valid
148.3181 -                                               // for active group)
148.3182 -            "psrlq $1, %%mm2             \n\t" // divide raw bytes by 2
148.3183 -            "pand  %%mm4, %%mm2          \n\t" // clear invalid bit 7 of each
148.3184 -                                               // byte
148.3185 -            "paddb %%mm1, %%mm2          \n\t" // add LBCarrys to (Raw(x-bpp)/2)
148.3186 -                                               // for each byte
148.3187 -            "pand %%mm6, %%mm2           \n\t" // leave only Active Group 2
148.3188 -                                               // bytes to add to Avg
148.3189 -            "paddb %%mm2, %%mm0          \n\t" // add (Raw/2) + LBCarrys to
148.3190 -                                               // Avg for each Active byte
148.3191 -
148.3192 -            // add 3rd active group (Raw(x-bpp)/2) to average with _LBCarry
148.3193 -            "psllq _ShiftBpp, %%mm6      \n\t" // shift the mm6 mask to cover
148.3194 -                                               // bytes 4 & 5
148.3195 -            "movq %%mm0, %%mm2           \n\t" // mov updated Raws to mm2
148.3196 -            "psllq _ShiftBpp, %%mm2      \n\t" // shift data to pos. correctly
148.3197 -            "movq %%mm3, %%mm1           \n\t" // now use mm1 for getting
148.3198 -                                               // LBCarrys
148.3199 -            "pand %%mm2, %%mm1           \n\t" // get LBCarrys for each byte
148.3200 -                                               // where both lsb's were == 1
148.3201 -                                               // (only valid for active group)
148.3202 -            "psrlq $1, %%mm2             \n\t" // divide raw bytes by 2
148.3203 -            "pand  %%mm4, %%mm2          \n\t" // clear invalid bit 7 of each
148.3204 -                                               // byte
148.3205 -            "paddb %%mm1, %%mm2          \n\t" // add LBCarrys to (Raw(x-bpp)/2)
148.3206 -                                               // for each byte
148.3207 -            "pand %%mm6, %%mm2           \n\t" // leave only Active Group 2
148.3208 -                                               // bytes to add to Avg
148.3209 -            "paddb %%mm2, %%mm0          \n\t" // add (Raw/2) + LBCarrys to
148.3210 -                                               // Avg for each Active byte
148.3211 -
148.3212 -            // add 4th active group (Raw(x-bpp)/2) to average with _LBCarry
148.3213 -            "psllq _ShiftBpp, %%mm6      \n\t" // shift the mm6 mask to cover
148.3214 -                                               // bytes 6 & 7
148.3215 -            "movq %%mm0, %%mm2           \n\t" // mov updated Raws to mm2
148.3216 -            "psllq _ShiftBpp, %%mm2      \n\t" // shift data to pos. correctly
148.3217 -            "addl $8, %%ecx              \n\t"
148.3218 -            "movq %%mm3, %%mm1           \n\t" // now use mm1 for getting
148.3219 -                                               // LBCarrys
148.3220 -            "pand %%mm2, %%mm1           \n\t" // get LBCarrys for each byte
148.3221 -                                               // where both
148.3222 -                                               // lsb's were == 1 (only valid
148.3223 -                                               // for active group)
148.3224 -            "psrlq $1, %%mm2             \n\t" // divide raw bytes by 2
148.3225 -            "pand  %%mm4, %%mm2          \n\t" // clear invalid bit 7 of each
148.3226 -                                               // byte
148.3227 -            "paddb %%mm1, %%mm2          \n\t" // add LBCarrys to (Raw(x-bpp)/2)
148.3228 -                                               // for each byte
148.3229 -            "pand %%mm6, %%mm2           \n\t" // leave only Active Group 2
148.3230 -                                               // bytes to add to Avg
148.3231 -            "paddb %%mm2, %%mm0          \n\t" // add (Raw/2) + LBCarrys to
148.3232 -                                               // Avg for each Active byte
148.3233 -
148.3234 -            "cmpl _MMXLength, %%ecx      \n\t"
148.3235 -            // now ready to write back to memory
148.3236 -            "movq %%mm0, -8(%%edi,%%ecx,) \n\t"
148.3237 -            // prep Raw(x-bpp) for next loop
148.3238 -            "movq %%mm0, %%mm2           \n\t" // mov updated Raws to mm2
148.3239 -            "jb avg_2lp                  \n\t"
148.3240 -
148.3241 -            : "=S" (dummy_value_S),            // output regs (dummy)
148.3242 -              "=D" (dummy_value_D)
148.3243 -
148.3244 -            : "0" (prev_row),  // esi          // input regs
148.3245 -              "1" (row)        // edi
148.3246 -
148.3247 -            : "%ecx"                           // clobber list
148.3248 -#if 0  /* %mm0, ..., %mm7 not supported by gcc 2.7.2.3 or egcs 1.1 */
148.3249 -            , "%mm0", "%mm1", "%mm2", "%mm3"
148.3250 -            , "%mm4", "%mm5", "%mm6", "%mm7"
148.3251 -#endif
148.3252 -         );
148.3253 -      }
148.3254 -      break;  // end 2 bpp
148.3255 -
148.3256 -      case 1:
148.3257 -      {
148.3258 -         __asm__ __volatile__ (
148.3259 -            // re-init address pointers and offset
148.3260 -#ifdef __PIC__
148.3261 -            "pushl %%ebx                 \n\t" // save Global Offset Table index
148.3262 -#endif
148.3263 -            "movl _dif, %%ebx            \n\t" // ebx:  x = offset to alignment
148.3264 -                                               // boundary
148.3265 -// preload  "movl row, %%edi             \n\t" // edi:  Avg(x)
148.3266 -            "cmpl _FullLength, %%ebx     \n\t" // test if offset at end of array
148.3267 -            "jnb avg_1end                \n\t"
148.3268 -            // do Paeth decode for remaining bytes
148.3269 -// preload  "movl prev_row, %%esi        \n\t" // esi:  Prior(x)
148.3270 -            "movl %%edi, %%edx           \n\t"
148.3271 -// preload  "subl bpp, %%edx             \n\t" // (bpp is preloaded into ecx)
148.3272 -            "subl %%ecx, %%edx           \n\t" // edx:  Raw(x-bpp)
148.3273 -            "xorl %%ecx, %%ecx           \n\t" // zero ecx before using cl & cx
148.3274 -                                               //  in loop below
148.3275 -         "avg_1lp:                       \n\t"
148.3276 -            // Raw(x) = Avg(x) + ((Raw(x-bpp) + Prior(x))/2)
148.3277 -            "xorl %%eax, %%eax           \n\t"
148.3278 -            "movb (%%esi,%%ebx,), %%cl   \n\t" // load cl with Prior(x)
148.3279 -            "movb (%%edx,%%ebx,), %%al   \n\t" // load al with Raw(x-bpp)
148.3280 -            "addw %%cx, %%ax             \n\t"
148.3281 -            "incl %%ebx                  \n\t"
148.3282 -            "shrw %%ax                   \n\t" // divide by 2
148.3283 -            "addb -1(%%edi,%%ebx,), %%al \n\t" // add Avg(x); -1 to offset
148.3284 -                                               // inc ebx
148.3285 -            "cmpl _FullLength, %%ebx     \n\t" // check if at end of array
148.3286 -            "movb %%al, -1(%%edi,%%ebx,) \n\t" // write back Raw(x);
148.3287 -                         // mov does not affect flags; -1 to offset inc ebx
148.3288 -            "jb avg_1lp                  \n\t"
148.3289 -
148.3290 -         "avg_1end:                      \n\t"
148.3291 -#ifdef __PIC__
148.3292 -            "popl %%ebx                  \n\t" // Global Offset Table index
148.3293 -#endif
148.3294 -
148.3295 -            : "=c" (dummy_value_c),            // output regs (dummy)
148.3296 -              "=S" (dummy_value_S),
148.3297 -              "=D" (dummy_value_D)
148.3298 -
148.3299 -            : "0" (bpp),       // ecx          // input regs
148.3300 -              "1" (prev_row),  // esi
148.3301 -              "2" (row)        // edi
148.3302 -
148.3303 -            : "%eax", "%edx"                   // clobber list
148.3304 -#ifndef __PIC__
148.3305 -            , "%ebx"
148.3306 -#endif
148.3307 -         );
148.3308 -      }
148.3309 -      return;  // end 1 bpp
148.3310 -
148.3311 -      case 8:
148.3312 -      {
148.3313 -         __asm__ __volatile__ (
148.3314 -            // re-init address pointers and offset
148.3315 -            "movl _dif, %%ecx            \n\t" // ecx:  x == offset to alignment
148.3316 -            "movq _LBCarryMask, %%mm5    \n\t" //            boundary
148.3317 -// preload  "movl row, %%edi             \n\t" // edi:  Avg(x)
148.3318 -            "movq _HBClearMask, %%mm4    \n\t"
148.3319 -// preload  "movl prev_row, %%esi        \n\t" // esi:  Prior(x)
148.3320 -
148.3321 -            // prime the pump:  load the first Raw(x-bpp) data set
148.3322 -            "movq -8(%%edi,%%ecx,), %%mm2 \n\t" // load previous aligned 8 bytes
148.3323 -                                      // (NO NEED to correct pos. in loop below)
148.3324 -
148.3325 -         "avg_8lp:                       \n\t"
148.3326 -            "movq (%%edi,%%ecx,), %%mm0  \n\t"
148.3327 -            "movq %%mm5, %%mm3           \n\t"
148.3328 -            "movq (%%esi,%%ecx,), %%mm1  \n\t"
148.3329 -            "addl $8, %%ecx              \n\t"
148.3330 -            "pand %%mm1, %%mm3           \n\t" // get lsb for each prev_row byte
148.3331 -            "psrlq $1, %%mm1             \n\t" // divide prev_row bytes by 2
148.3332 -            "pand %%mm2, %%mm3           \n\t" // get LBCarrys for each byte
148.3333 -                                               //  where both lsb's were == 1
148.3334 -            "psrlq $1, %%mm2             \n\t" // divide raw bytes by 2
148.3335 -            "pand  %%mm4, %%mm1          \n\t" // clear invalid bit 7, each byte
148.3336 -            "paddb %%mm3, %%mm0          \n\t" // add LBCarrys to Avg, each byte
148.3337 -            "pand  %%mm4, %%mm2          \n\t" // clear invalid bit 7, each byte
148.3338 -            "paddb %%mm1, %%mm0          \n\t" // add (Prev_row/2) to Avg, each
148.3339 -            "paddb %%mm2, %%mm0          \n\t" // add (Raw/2) to Avg for each
148.3340 -            "cmpl _MMXLength, %%ecx      \n\t"
148.3341 -            "movq %%mm0, -8(%%edi,%%ecx,) \n\t"
148.3342 -            "movq %%mm0, %%mm2           \n\t" // reuse as Raw(x-bpp)
148.3343 -            "jb avg_8lp                  \n\t"
148.3344 -
148.3345 -            : "=S" (dummy_value_S),            // output regs (dummy)
148.3346 -              "=D" (dummy_value_D)
148.3347 -
148.3348 -            : "0" (prev_row),  // esi          // input regs
148.3349 -              "1" (row)        // edi
148.3350 -
148.3351 -            : "%ecx"                           // clobber list
148.3352 -#if 0  /* %mm0, ..., %mm5 not supported by gcc 2.7.2.3 or egcs 1.1 */
148.3353 -            , "%mm0", "%mm1", "%mm2"
148.3354 -            , "%mm3", "%mm4", "%mm5"
148.3355 -#endif
148.3356 -         );
148.3357 -      }
148.3358 -      break;  // end 8 bpp
148.3359 -
148.3360 -      default:                  // bpp greater than 8 (!= 1,2,3,4,[5],6,[7],8)
148.3361 -      {
148.3362 -
148.3363 -#ifdef PNG_DEBUG
148.3364 -         // GRR:  PRINT ERROR HERE:  SHOULD NEVER BE REACHED
148.3365 -        png_debug(1,
148.3366 -        "Internal logic error in pnggccrd (png_read_filter_row_mmx_avg())\n");
148.3367 -#endif
148.3368 -
148.3369 -#if 0
148.3370 -        __asm__ __volatile__ (
148.3371 -            "movq _LBCarryMask, %%mm5    \n\t"
148.3372 -            // re-init address pointers and offset
148.3373 -            "movl _dif, %%ebx            \n\t" // ebx:  x = offset to
148.3374 -                                               // alignment boundary
148.3375 -            "movl row, %%edi             \n\t" // edi:  Avg(x)
148.3376 -            "movq _HBClearMask, %%mm4    \n\t"
148.3377 -            "movl %%edi, %%edx           \n\t"
148.3378 -            "movl prev_row, %%esi        \n\t" // esi:  Prior(x)
148.3379 -            "subl bpp, %%edx             \n\t" // edx:  Raw(x-bpp)
148.3380 -         "avg_Alp:                       \n\t"
148.3381 -            "movq (%%edi,%%ebx,), %%mm0  \n\t"
148.3382 -            "movq %%mm5, %%mm3           \n\t"
148.3383 -            "movq (%%esi,%%ebx,), %%mm1  \n\t"
148.3384 -            "pand %%mm1, %%mm3           \n\t" // get lsb for each prev_row byte
148.3385 -            "movq (%%edx,%%ebx,), %%mm2  \n\t"
148.3386 -            "psrlq $1, %%mm1             \n\t" // divide prev_row bytes by 2
148.3387 -            "pand %%mm2, %%mm3           \n\t" // get LBCarrys for each byte
148.3388 -                                               // where both lsb's were == 1
148.3389 -            "psrlq $1, %%mm2             \n\t" // divide raw bytes by 2
148.3390 -            "pand  %%mm4, %%mm1          \n\t" // clear invalid bit 7 of each
148.3391 -                                               // byte
148.3392 -            "paddb %%mm3, %%mm0          \n\t" // add LBCarrys to Avg for each
148.3393 -                                               // byte
148.3394 -            "pand  %%mm4, %%mm2          \n\t" // clear invalid bit 7 of each
148.3395 -                                               // byte
148.3396 -            "paddb %%mm1, %%mm0          \n\t" // add (Prev_row/2) to Avg for
148.3397 -                                               // each byte
148.3398 -            "addl $8, %%ebx              \n\t"
148.3399 -            "paddb %%mm2, %%mm0          \n\t" // add (Raw/2) to Avg for each
148.3400 -                                               // byte
148.3401 -            "cmpl _MMXLength, %%ebx      \n\t"
148.3402 -            "movq %%mm0, -8(%%edi,%%ebx,) \n\t"
148.3403 -            "jb avg_Alp                  \n\t"
148.3404 -
148.3405 -            : // FIXASM: output regs/vars go here, e.g.:  "=m" (memory_var)
148.3406 -
148.3407 -            : // FIXASM: input regs, e.g.:  "c" (count), "S" (src), "D" (dest)
148.3408 -
148.3409 -            : "%ebx", "%edx", "%edi", "%esi" // CHECKASM: clobber list
148.3410 -         );
148.3411 -#endif /* 0 - NEVER REACHED */
148.3412 -      }
148.3413 -      break;
148.3414 -
148.3415 -   } // end switch (bpp)
148.3416 -
148.3417 -   __asm__ __volatile__ (
148.3418 -      // MMX acceleration complete; now do clean-up
148.3419 -      // check if any remaining bytes left to decode
148.3420 -#ifdef __PIC__
148.3421 -      "pushl %%ebx                 \n\t" // save index to Global Offset Table
148.3422 -#endif
148.3423 -      "movl _MMXLength, %%ebx      \n\t" // ebx:  x == offset bytes after MMX
148.3424 -//pre "movl row, %%edi             \n\t" // edi:  Avg(x)
148.3425 -      "cmpl _FullLength, %%ebx     \n\t" // test if offset at end of array
148.3426 -      "jnb avg_end                 \n\t"
148.3427 -
148.3428 -      // do Avg decode for remaining bytes
148.3429 -//pre "movl prev_row, %%esi        \n\t" // esi:  Prior(x)
148.3430 -      "movl %%edi, %%edx           \n\t"
148.3431 -//pre "subl bpp, %%edx             \n\t" // (bpp is preloaded into ecx)
148.3432 -      "subl %%ecx, %%edx           \n\t" // edx:  Raw(x-bpp)
148.3433 -      "xorl %%ecx, %%ecx           \n\t" // zero ecx before using cl & cx below
148.3434 -
148.3435 -   "avg_lp2:                       \n\t"
148.3436 -      // Raw(x) = Avg(x) + ((Raw(x-bpp) + Prior(x))/2)
148.3437 -      "xorl %%eax, %%eax           \n\t"
148.3438 -      "movb (%%esi,%%ebx,), %%cl   \n\t" // load cl with Prior(x)
148.3439 -      "movb (%%edx,%%ebx,), %%al   \n\t" // load al with Raw(x-bpp)
148.3440 -      "addw %%cx, %%ax             \n\t"
148.3441 -      "incl %%ebx                  \n\t"
148.3442 -      "shrw %%ax                   \n\t" // divide by 2
148.3443 -      "addb -1(%%edi,%%ebx,), %%al \n\t" // add Avg(x); -1 to offset inc ebx
148.3444 -      "cmpl _FullLength, %%ebx     \n\t" // check if at end of array
148.3445 -      "movb %%al, -1(%%edi,%%ebx,) \n\t" // write back Raw(x) [mov does not
148.3446 -      "jb avg_lp2                  \n\t" //  affect flags; -1 to offset inc ebx]
148.3447 -
148.3448 -   "avg_end:                       \n\t"
148.3449 -      "EMMS                        \n\t" // end MMX; prep for poss. FP instrs.
148.3450 -#ifdef __PIC__
148.3451 -      "popl %%ebx                  \n\t" // restore index to Global Offset Table
148.3452 -#endif
148.3453 -
148.3454 -      : "=c" (dummy_value_c),            // output regs (dummy)
148.3455 -        "=S" (dummy_value_S),
148.3456 -        "=D" (dummy_value_D)
148.3457 -
148.3458 -      : "0" (bpp),       // ecx          // input regs
148.3459 -        "1" (prev_row),  // esi
148.3460 -        "2" (row)        // edi
148.3461 -
148.3462 -      : "%eax", "%edx"                   // clobber list
148.3463 -#ifndef __PIC__
148.3464 -      , "%ebx"
148.3465 -#endif
148.3466 -   );
148.3467 -
148.3468 -} /* end png_read_filter_row_mmx_avg() */
148.3469 -#endif
148.3470 -
148.3471 -
148.3472 -
148.3473 -#ifdef PNG_THREAD_UNSAFE_OK
148.3474 -//===========================================================================//
148.3475 -//                                                                           //
148.3476 -//         P N G _ R E A D _ F I L T E R _ R O W _ M M X _ P A E T H         //
148.3477 -//                                                                           //
148.3478 -//===========================================================================//
148.3479 -
148.3480 -// Optimized code for PNG Paeth filter decoder
148.3481 -
148.3482 -static void /* PRIVATE */
148.3483 -png_read_filter_row_mmx_paeth(png_row_infop row_info, png_bytep row,
148.3484 -                              png_bytep prev_row)
148.3485 -{
148.3486 -   int bpp;
148.3487 -   int dummy_value_c;   // fix 'forbidden register 2 (cx) was spilled' error
148.3488 -   int dummy_value_S;
148.3489 -   int dummy_value_D;
148.3490 -
148.3491 -   bpp = (row_info->pixel_depth + 7) >> 3; // Get # bytes per pixel
148.3492 -   _FullLength  = row_info->rowbytes; // # of bytes to filter
148.3493 -
148.3494 -   __asm__ __volatile__ (
148.3495 -#ifdef __PIC__
148.3496 -      "pushl %%ebx                 \n\t" // save index to Global Offset Table
148.3497 -#endif
148.3498 -      "xorl %%ebx, %%ebx           \n\t" // ebx:  x offset
148.3499 -//pre "movl row, %%edi             \n\t"
148.3500 -      "xorl %%edx, %%edx           \n\t" // edx:  x-bpp offset
148.3501 -//pre "movl prev_row, %%esi        \n\t"
148.3502 -      "xorl %%eax, %%eax           \n\t"
148.3503 -
148.3504 -      // Compute the Raw value for the first bpp bytes
148.3505 -      // Note: the formula works out to be always
148.3506 -      //   Paeth(x) = Raw(x) + Prior(x)      where x < bpp
148.3507 -   "paeth_rlp:                     \n\t"
148.3508 -      "movb (%%edi,%%ebx,), %%al   \n\t"
148.3509 -      "addb (%%esi,%%ebx,), %%al   \n\t"
148.3510 -      "incl %%ebx                  \n\t"
148.3511 -//pre "cmpl bpp, %%ebx             \n\t" (bpp is preloaded into ecx)
148.3512 -      "cmpl %%ecx, %%ebx           \n\t"
148.3513 -      "movb %%al, -1(%%edi,%%ebx,) \n\t"
148.3514 -      "jb paeth_rlp                \n\t"
148.3515 -      // get # of bytes to alignment
148.3516 -      "movl %%edi, _dif            \n\t" // take start of row
148.3517 -      "addl %%ebx, _dif            \n\t" // add bpp
148.3518 -      "xorl %%ecx, %%ecx           \n\t"
148.3519 -      "addl $0xf, _dif             \n\t" // add 7 + 8 to incr past alignment
148.3520 -                                         // boundary
148.3521 -      "andl $0xfffffff8, _dif      \n\t" // mask to alignment boundary
148.3522 -      "subl %%edi, _dif            \n\t" // subtract from start ==> value ebx
148.3523 -                                         // at alignment
148.3524 -      "jz paeth_go                 \n\t"
148.3525 -      // fix alignment
148.3526 -
148.3527 -   "paeth_lp1:                     \n\t"
148.3528 -      "xorl %%eax, %%eax           \n\t"
148.3529 -      // pav = p - a = (a + b - c) - a = b - c
148.3530 -      "movb (%%esi,%%ebx,), %%al   \n\t" // load Prior(x) into al
148.3531 -      "movb (%%esi,%%edx,), %%cl   \n\t" // load Prior(x-bpp) into cl
148.3532 -      "subl %%ecx, %%eax           \n\t" // subtract Prior(x-bpp)
148.3533 -      "movl %%eax, _patemp         \n\t" // Save pav for later use
148.3534 -      "xorl %%eax, %%eax           \n\t"
148.3535 -      // pbv = p - b = (a + b - c) - b = a - c
148.3536 -      "movb (%%edi,%%edx,), %%al   \n\t" // load Raw(x-bpp) into al
148.3537 -      "subl %%ecx, %%eax           \n\t" // subtract Prior(x-bpp)
148.3538 -      "movl %%eax, %%ecx           \n\t"
148.3539 -      // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
148.3540 -      "addl _patemp, %%eax         \n\t" // pcv = pav + pbv
148.3541 -      // pc = abs(pcv)
148.3542 -      "testl $0x80000000, %%eax    \n\t"
148.3543 -      "jz paeth_pca                \n\t"
148.3544 -      "negl %%eax                  \n\t" // reverse sign of neg values
148.3545 -
148.3546 -   "paeth_pca:                     \n\t"
148.3547 -      "movl %%eax, _pctemp         \n\t" // save pc for later use
148.3548 -      // pb = abs(pbv)
148.3549 -      "testl $0x80000000, %%ecx    \n\t"
148.3550 -      "jz paeth_pba                \n\t"
148.3551 -      "negl %%ecx                  \n\t" // reverse sign of neg values
148.3552 -
148.3553 -   "paeth_pba:                     \n\t"
148.3554 -      "movl %%ecx, _pbtemp         \n\t" // save pb for later use
148.3555 -      // pa = abs(pav)
148.3556 -      "movl _patemp, %%eax         \n\t"
148.3557 -      "testl $0x80000000, %%eax    \n\t"
148.3558 -      "jz paeth_paa                \n\t"
148.3559 -      "negl %%eax                  \n\t" // reverse sign of neg values
148.3560 -
148.3561 -   "paeth_paa:                     \n\t"
148.3562 -      "movl %%eax, _patemp         \n\t" // save pa for later use
148.3563 -      // test if pa <= pb
148.3564 -      "cmpl %%ecx, %%eax           \n\t"
148.3565 -      "jna paeth_abb               \n\t"
148.3566 -      // pa > pb; now test if pb <= pc
148.3567 -      "cmpl _pctemp, %%ecx         \n\t"
148.3568 -      "jna paeth_bbc               \n\t"
148.3569 -      // pb > pc; Raw(x) = Paeth(x) + Prior(x-bpp)
148.3570 -      "movb (%%esi,%%edx,), %%cl   \n\t" // load Prior(x-bpp) into cl
148.3571 -      "jmp paeth_paeth             \n\t"
148.3572 -
148.3573 -   "paeth_bbc:                     \n\t"
148.3574 -      // pb <= pc; Raw(x) = Paeth(x) + Prior(x)
148.3575 -      "movb (%%esi,%%ebx,), %%cl   \n\t" // load Prior(x) into cl
148.3576 -      "jmp paeth_paeth             \n\t"
148.3577 -
148.3578 -   "paeth_abb:                     \n\t"
148.3579 -      // pa <= pb; now test if pa <= pc
148.3580 -      "cmpl _pctemp, %%eax         \n\t"
148.3581 -      "jna paeth_abc               \n\t"
148.3582 -      // pa > pc; Raw(x) = Paeth(x) + Prior(x-bpp)
148.3583 -      "movb (%%esi,%%edx,), %%cl   \n\t" // load Prior(x-bpp) into cl
148.3584 -      "jmp paeth_paeth             \n\t"
148.3585 -
148.3586 -   "paeth_abc:                     \n\t"
148.3587 -      // pa <= pc; Raw(x) = Paeth(x) + Raw(x-bpp)
148.3588 -      "movb (%%edi,%%edx,), %%cl   \n\t" // load Raw(x-bpp) into cl
148.3589 -
148.3590 -   "paeth_paeth:                   \n\t"
148.3591 -      "incl %%ebx                  \n\t"
148.3592 -      "incl %%edx                  \n\t"
148.3593 -      // Raw(x) = (Paeth(x) + Paeth_Predictor( a, b, c )) mod 256
148.3594 -      "addb %%cl, -1(%%edi,%%ebx,) \n\t"
148.3595 -      "cmpl _dif, %%ebx            \n\t"
148.3596 -      "jb paeth_lp1                \n\t"
148.3597 -
148.3598 -   "paeth_go:                      \n\t"
148.3599 -      "movl _FullLength, %%ecx     \n\t"
148.3600 -      "movl %%ecx, %%eax           \n\t"
148.3601 -      "subl %%ebx, %%eax           \n\t" // subtract alignment fix
148.3602 -      "andl $0x00000007, %%eax     \n\t" // calc bytes over mult of 8
148.3603 -      "subl %%eax, %%ecx           \n\t" // drop over bytes from original length
148.3604 -      "movl %%ecx, _MMXLength      \n\t"
148.3605 -#ifdef __PIC__
148.3606 -      "popl %%ebx                  \n\t" // restore index to Global Offset Table
148.3607 -#endif
148.3608 -
148.3609 -      : "=c" (dummy_value_c),            // output regs (dummy)
148.3610 -        "=S" (dummy_value_S),
148.3611 -        "=D" (dummy_value_D)
148.3612 -
148.3613 -      : "0" (bpp),       // ecx          // input regs
148.3614 -        "1" (prev_row),  // esi
148.3615 -        "2" (row)        // edi
148.3616 -
148.3617 -      : "%eax", "%edx"                   // clobber list
148.3618 -#ifndef __PIC__
148.3619 -      , "%ebx"
148.3620 -#endif
148.3621 -   );
148.3622 -
148.3623 -   // now do the math for the rest of the row
148.3624 -   switch (bpp)
148.3625 -   {
148.3626 -      case 3:
148.3627 -      {
148.3628 -         _ActiveMask.use = 0x0000000000ffffffLL;
148.3629 -         _ActiveMaskEnd.use = 0xffff000000000000LL;
148.3630 -         _ShiftBpp.use = 24;    // == bpp(3) * 8
148.3631 -         _ShiftRem.use = 40;    // == 64 - 24
148.3632 -
148.3633 -         __asm__ __volatile__ (
148.3634 -            "movl _dif, %%ecx            \n\t"
148.3635 -// preload  "movl row, %%edi             \n\t"
148.3636 -// preload  "movl prev_row, %%esi        \n\t"
148.3637 -            "pxor %%mm0, %%mm0           \n\t"
148.3638 -            // prime the pump:  load the first Raw(x-bpp) data set
148.3639 -            "movq -8(%%edi,%%ecx,), %%mm1 \n\t"
148.3640 -         "paeth_3lp:                     \n\t"
148.3641 -            "psrlq _ShiftRem, %%mm1      \n\t" // shift last 3 bytes to 1st
148.3642 -                                               // 3 bytes
148.3643 -            "movq (%%esi,%%ecx,), %%mm2  \n\t" // load b=Prior(x)
148.3644 -            "punpcklbw %%mm0, %%mm1      \n\t" // unpack High bytes of a
148.3645 -            "movq -8(%%esi,%%ecx,), %%mm3 \n\t" // prep c=Prior(x-bpp) bytes
148.3646 -            "punpcklbw %%mm0, %%mm2      \n\t" // unpack High bytes of b
148.3647 -            "psrlq _ShiftRem, %%mm3      \n\t" // shift last 3 bytes to 1st
148.3648 -                                               // 3 bytes
148.3649 -            // pav = p - a = (a + b - c) - a = b - c
148.3650 -            "movq %%mm2, %%mm4           \n\t"
148.3651 -            "punpcklbw %%mm0, %%mm3      \n\t" // unpack High bytes of c
148.3652 -            // pbv = p - b = (a + b - c) - b = a - c
148.3653 -            "movq %%mm1, %%mm5           \n\t"
148.3654 -            "psubw %%mm3, %%mm4          \n\t"
148.3655 -            "pxor %%mm7, %%mm7           \n\t"
148.3656 -            // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
148.3657 -            "movq %%mm4, %%mm6           \n\t"
148.3658 -            "psubw %%mm3, %%mm5          \n\t"
148.3659 -
148.3660 -            // pa = abs(p-a) = abs(pav)
148.3661 -            // pb = abs(p-b) = abs(pbv)
148.3662 -            // pc = abs(p-c) = abs(pcv)
148.3663 -            "pcmpgtw %%mm4, %%mm0        \n\t" // create mask pav bytes < 0
148.3664 -            "paddw %%mm5, %%mm6          \n\t"
148.3665 -            "pand %%mm4, %%mm0           \n\t" // only pav bytes < 0 in mm7
148.3666 -            "pcmpgtw %%mm5, %%mm7        \n\t" // create mask pbv bytes < 0
148.3667 -            "psubw %%mm0, %%mm4          \n\t"
148.3668 -            "pand %%mm5, %%mm7           \n\t" // only pbv bytes < 0 in mm0
148.3669 -            "psubw %%mm0, %%mm4          \n\t"
148.3670 -            "psubw %%mm7, %%mm5          \n\t"
148.3671 -            "pxor %%mm0, %%mm0           \n\t"
148.3672 -            "pcmpgtw %%mm6, %%mm0        \n\t" // create mask pcv bytes < 0
148.3673 -            "pand %%mm6, %%mm0           \n\t" // only pav bytes < 0 in mm7
148.3674 -            "psubw %%mm7, %%mm5          \n\t"
148.3675 -            "psubw %%mm0, %%mm6          \n\t"
148.3676 -            //  test pa <= pb
148.3677 -            "movq %%mm4, %%mm7           \n\t"
148.3678 -            "psubw %%mm0, %%mm6          \n\t"
148.3679 -            "pcmpgtw %%mm5, %%mm7        \n\t" // pa > pb?
148.3680 -            "movq %%mm7, %%mm0           \n\t"
148.3681 -            // use mm7 mask to merge pa & pb
148.3682 -            "pand %%mm7, %%mm5           \n\t"
148.3683 -            // use mm0 mask copy to merge a & b
148.3684 -            "pand %%mm0, %%mm2           \n\t"
148.3685 -            "pandn %%mm4, %%mm7          \n\t"
148.3686 -            "pandn %%mm1, %%mm0          \n\t"
148.3687 -            "paddw %%mm5, %%mm7          \n\t"
148.3688 -            "paddw %%mm2, %%mm0          \n\t"
148.3689 -            //  test  ((pa <= pb)? pa:pb) <= pc
148.3690 -            "pcmpgtw %%mm6, %%mm7        \n\t" // pab > pc?
148.3691 -            "pxor %%mm1, %%mm1           \n\t"
148.3692 -            "pand %%mm7, %%mm3           \n\t"
148.3693 -            "pandn %%mm0, %%mm7          \n\t"
148.3694 -            "paddw %%mm3, %%mm7          \n\t"
148.3695 -            "pxor %%mm0, %%mm0           \n\t"
148.3696 -            "packuswb %%mm1, %%mm7       \n\t"
148.3697 -            "movq (%%esi,%%ecx,), %%mm3  \n\t" // load c=Prior(x-bpp)
148.3698 -            "pand _ActiveMask, %%mm7     \n\t"
148.3699 -            "movq %%mm3, %%mm2           \n\t" // load b=Prior(x) step 1
148.3700 -            "paddb (%%edi,%%ecx,), %%mm7 \n\t" // add Paeth predictor with Raw(x)
148.3701 -            "punpcklbw %%mm0, %%mm3      \n\t" // unpack High bytes of c
148.3702 -            "movq %%mm7, (%%edi,%%ecx,)  \n\t" // write back updated value
148.3703 -            "movq %%mm7, %%mm1           \n\t" // now mm1 will be used as
148.3704 -                                               // Raw(x-bpp)
148.3705 -            // now do Paeth for 2nd set of bytes (3-5)
148.3706 -            "psrlq _ShiftBpp, %%mm2      \n\t" // load b=Prior(x) step 2
148.3707 -            "punpcklbw %%mm0, %%mm1      \n\t" // unpack High bytes of a
148.3708 -            "pxor %%mm7, %%mm7           \n\t"
148.3709 -            "punpcklbw %%mm0, %%mm2      \n\t" // unpack High bytes of b
148.3710 -            // pbv = p - b = (a + b - c) - b = a - c
148.3711 -            "movq %%mm1, %%mm5           \n\t"
148.3712 -            // pav = p - a = (a + b - c) - a = b - c
148.3713 -            "movq %%mm2, %%mm4           \n\t"
148.3714 -            "psubw %%mm3, %%mm5          \n\t"
148.3715 -            "psubw %%mm3, %%mm4          \n\t"
148.3716 -            // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) =
148.3717 -            //       pav + pbv = pbv + pav
148.3718 -            "movq %%mm5, %%mm6           \n\t"
148.3719 -            "paddw %%mm4, %%mm6          \n\t"
148.3720 -
148.3721 -            // pa = abs(p-a) = abs(pav)
148.3722 -            // pb = abs(p-b) = abs(pbv)
148.3723 -            // pc = abs(p-c) = abs(pcv)
148.3724 -            "pcmpgtw %%mm5, %%mm0        \n\t" // create mask pbv bytes < 0
148.3725 -            "pcmpgtw %%mm4, %%mm7        \n\t" // create mask pav bytes < 0
148.3726 -            "pand %%mm5, %%mm0           \n\t" // only pbv bytes < 0 in mm0
148.3727 -            "pand %%mm4, %%mm7           \n\t" // only pav bytes < 0 in mm7
148.3728 -            "psubw %%mm0, %%mm5          \n\t"
148.3729 -            "psubw %%mm7, %%mm4          \n\t"
148.3730 -            "psubw %%mm0, %%mm5          \n\t"
148.3731 -            "psubw %%mm7, %%mm4          \n\t"
148.3732 -            "pxor %%mm0, %%mm0           \n\t"
148.3733 -            "pcmpgtw %%mm6, %%mm0        \n\t" // create mask pcv bytes < 0
148.3734 -            "pand %%mm6, %%mm0           \n\t" // only pav bytes < 0 in mm7
148.3735 -            "psubw %%mm0, %%mm6          \n\t"
148.3736 -            //  test pa <= pb
148.3737 -            "movq %%mm4, %%mm7           \n\t"
148.3738 -            "psubw %%mm0, %%mm6          \n\t"
148.3739 -            "pcmpgtw %%mm5, %%mm7        \n\t" // pa > pb?
148.3740 -            "movq %%mm7, %%mm0           \n\t"
148.3741 -            // use mm7 mask to merge pa & pb
148.3742 -            "pand %%mm7, %%mm5           \n\t"
148.3743 -            // use mm0 mask copy to merge a & b
148.3744 -            "pand %%mm0, %%mm2           \n\t"
148.3745 -            "pandn %%mm4, %%mm7          \n\t"
148.3746 -            "pandn %%mm1, %%mm0          \n\t"
148.3747 -            "paddw %%mm5, %%mm7          \n\t"
148.3748 -            "paddw %%mm2, %%mm0          \n\t"
148.3749 -            //  test  ((pa <= pb)? pa:pb) <= pc
148.3750 -            "pcmpgtw %%mm6, %%mm7        \n\t" // pab > pc?
148.3751 -            "movq (%%esi,%%ecx,), %%mm2  \n\t" // load b=Prior(x)
148.3752 -            "pand %%mm7, %%mm3           \n\t"
148.3753 -            "pandn %%mm0, %%mm7          \n\t"
148.3754 -            "pxor %%mm1, %%mm1           \n\t"
148.3755 -            "paddw %%mm3, %%mm7          \n\t"
148.3756 -            "pxor %%mm0, %%mm0           \n\t"
148.3757 -            "packuswb %%mm1, %%mm7       \n\t"
148.3758 -            "movq %%mm2, %%mm3           \n\t" // load c=Prior(x-bpp) step 1
148.3759 -            "pand _ActiveMask, %%mm7     \n\t"
148.3760 -            "punpckhbw %%mm0, %%mm2      \n\t" // unpack High bytes of b
148.3761 -            "psllq _ShiftBpp, %%mm7      \n\t" // shift bytes to 2nd group of
148.3762 -                                               // 3 bytes
148.3763 -             // pav = p - a = (a + b - c) - a = b - c
148.3764 -            "movq %%mm2, %%mm4           \n\t"
148.3765 -            "paddb (%%edi,%%ecx,), %%mm7 \n\t" // add Paeth predictor with Raw(x)
148.3766 -            "psllq _ShiftBpp, %%mm3      \n\t" // load c=Prior(x-bpp) step 2
148.3767 -            "movq %%mm7, (%%edi,%%ecx,)  \n\t" // write back updated value
148.3768 -            "movq %%mm7, %%mm1           \n\t"
148.3769 -            "punpckhbw %%mm0, %%mm3      \n\t" // unpack High bytes of c
148.3770 -            "psllq _ShiftBpp, %%mm1      \n\t" // shift bytes
148.3771 -                                    // now mm1 will be used as Raw(x-bpp)
148.3772 -            // now do Paeth for 3rd, and final, set of bytes (6-7)
148.3773 -            "pxor %%mm7, %%mm7           \n\t"
148.3774 -            "punpckhbw %%mm0, %%mm1      \n\t" // unpack High bytes of a
148.3775 -            "psubw %%mm3, %%mm4          \n\t"
148.3776 -            // pbv = p - b = (a + b - c) - b = a - c
148.3777 -            "movq %%mm1, %%mm5           \n\t"
148.3778 -            // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
148.3779 -            "movq %%mm4, %%mm6           \n\t"
148.3780 -            "psubw %%mm3, %%mm5          \n\t"
148.3781 -            "pxor %%mm0, %%mm0           \n\t"
148.3782 -            "paddw %%mm5, %%mm6          \n\t"
148.3783 -
148.3784 -            // pa = abs(p-a) = abs(pav)
148.3785 -            // pb = abs(p-b) = abs(pbv)
148.3786 -            // pc = abs(p-c) = abs(pcv)
148.3787 -            "pcmpgtw %%mm4, %%mm0        \n\t" // create mask pav bytes < 0
148.3788 -            "pcmpgtw %%mm5, %%mm7        \n\t" // create mask pbv bytes < 0
148.3789 -            "pand %%mm4, %%mm0           \n\t" // only pav bytes < 0 in mm7
148.3790 -            "pand %%mm5, %%mm7           \n\t" // only pbv bytes < 0 in mm0
148.3791 -            "psubw %%mm0, %%mm4          \n\t"
148.3792 -            "psubw %%mm7, %%mm5          \n\t"
148.3793 -            "psubw %%mm0, %%mm4          \n\t"
148.3794 -            "psubw %%mm7, %%mm5          \n\t"
148.3795 -            "pxor %%mm0, %%mm0           \n\t"
148.3796 -            "pcmpgtw %%mm6, %%mm0        \n\t" // create mask pcv bytes < 0
148.3797 -            "pand %%mm6, %%mm0           \n\t" // only pav bytes < 0 in mm7
148.3798 -            "psubw %%mm0, %%mm6          \n\t"
148.3799 -            //  test pa <= pb
148.3800 -            "movq %%mm4, %%mm7           \n\t"
148.3801 -            "psubw %%mm0, %%mm6          \n\t"
148.3802 -            "pcmpgtw %%mm5, %%mm7        \n\t" // pa > pb?
148.3803 -            "movq %%mm7, %%mm0           \n\t"
148.3804 -            // use mm0 mask copy to merge a & b
148.3805 -            "pand %%mm0, %%mm2           \n\t"
148.3806 -            // use mm7 mask to merge pa & pb
148.3807 -            "pand %%mm7, %%mm5           \n\t"
148.3808 -            "pandn %%mm1, %%mm0          \n\t"
148.3809 -            "pandn %%mm4, %%mm7          \n\t"
148.3810 -            "paddw %%mm2, %%mm0          \n\t"
148.3811 -            "paddw %%mm5, %%mm7          \n\t"
148.3812 -            //  test  ((pa <= pb)? pa:pb) <= pc
148.3813 -            "pcmpgtw %%mm6, %%mm7        \n\t" // pab > pc?
148.3814 -            "pand %%mm7, %%mm3           \n\t"
148.3815 -            "pandn %%mm0, %%mm7          \n\t"
148.3816 -            "paddw %%mm3, %%mm7          \n\t"
148.3817 -            "pxor %%mm1, %%mm1           \n\t"
148.3818 -            "packuswb %%mm7, %%mm1       \n\t"
148.3819 -            // step ecx to next set of 8 bytes and repeat loop til done
148.3820 -            "addl $8, %%ecx              \n\t"
148.3821 -            "pand _ActiveMaskEnd, %%mm1  \n\t"
148.3822 -            "paddb -8(%%edi,%%ecx,), %%mm1 \n\t" // add Paeth predictor with
148.3823 -                                                 // Raw(x)
148.3824 -
148.3825 -            "cmpl _MMXLength, %%ecx      \n\t"
148.3826 -            "pxor %%mm0, %%mm0           \n\t" // pxor does not affect flags
148.3827 -            "movq %%mm1, -8(%%edi,%%ecx,) \n\t" // write back updated value
148.3828 -                                 // mm1 will be used as Raw(x-bpp) next loop
148.3829 -                           // mm3 ready to be used as Prior(x-bpp) next loop
148.3830 -            "jb paeth_3lp                \n\t"
148.3831 -
148.3832 -            : "=S" (dummy_value_S),             // output regs (dummy)
148.3833 -              "=D" (dummy_value_D)
148.3834 -
148.3835 -            : "0" (prev_row),  // esi           // input regs
148.3836 -              "1" (row)        // edi
148.3837 -
148.3838 -            : "%ecx"                            // clobber list
148.3839 -#if 0  /* %mm0, ..., %mm7 not supported by gcc 2.7.2.3 or egcs 1.1 */
148.3840 -            , "%mm0", "%mm1", "%mm2", "%mm3"
148.3841 -            , "%mm4", "%mm5", "%mm6", "%mm7"
148.3842 -#endif
148.3843 -         );
148.3844 -      }
148.3845 -      break;  // end 3 bpp
148.3846 -
148.3847 -      case 6:
148.3848 -      //case 7:   // GRR BOGUS
148.3849 -      //case 5:   // GRR BOGUS
148.3850 -      {
148.3851 -         _ActiveMask.use  = 0x00000000ffffffffLL;
148.3852 -         _ActiveMask2.use = 0xffffffff00000000LL;
148.3853 -         _ShiftBpp.use = bpp << 3;    // == bpp * 8
148.3854 -         _ShiftRem.use = 64 - _ShiftBpp.use;
148.3855 -
148.3856 -         __asm__ __volatile__ (
148.3857 -            "movl _dif, %%ecx            \n\t"
148.3858 -// preload  "movl row, %%edi             \n\t"
148.3859 -// preload  "movl prev_row, %%esi        \n\t"
148.3860 -            // prime the pump:  load the first Raw(x-bpp) data set
148.3861 -            "movq -8(%%edi,%%ecx,), %%mm1 \n\t"
148.3862 -            "pxor %%mm0, %%mm0           \n\t"
148.3863 -
148.3864 -         "paeth_6lp:                     \n\t"
148.3865 -            // must shift to position Raw(x-bpp) data
148.3866 -            "psrlq _ShiftRem, %%mm1      \n\t"
148.3867 -            // do first set of 4 bytes
148.3868 -            "movq -8(%%esi,%%ecx,), %%mm3 \n\t" // read c=Prior(x-bpp) bytes
148.3869 -            "punpcklbw %%mm0, %%mm1      \n\t" // unpack Low bytes of a
148.3870 -            "movq (%%esi,%%ecx,), %%mm2  \n\t" // load b=Prior(x)
148.3871 -            "punpcklbw %%mm0, %%mm2      \n\t" // unpack Low bytes of b
148.3872 -            // must shift to position Prior(x-bpp) data
148.3873 -            "psrlq _ShiftRem, %%mm3      \n\t"
148.3874 -            // pav = p - a = (a + b - c) - a = b - c
148.3875 -            "movq %%mm2, %%mm4           \n\t"
148.3876 -            "punpcklbw %%mm0, %%mm3      \n\t" // unpack Low bytes of c
148.3877 -            // pbv = p - b = (a + b - c) - b = a - c
148.3878 -            "movq %%mm1, %%mm5           \n\t"
148.3879 -            "psubw %%mm3, %%mm4          \n\t"
148.3880 -            "pxor %%mm7, %%mm7           \n\t"
148.3881 -            // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
148.3882 -            "movq %%mm4, %%mm6           \n\t"
148.3883 -            "psubw %%mm3, %%mm5          \n\t"
148.3884 -            // pa = abs(p-a) = abs(pav)
148.3885 -            // pb = abs(p-b) = abs(pbv)
148.3886 -            // pc = abs(p-c) = abs(pcv)
148.3887 -            "pcmpgtw %%mm4, %%mm0        \n\t" // create mask pav bytes < 0
148.3888 -            "paddw %%mm5, %%mm6          \n\t"
148.3889 -            "pand %%mm4, %%mm0           \n\t" // only pav bytes < 0 in mm7
148.3890 -            "pcmpgtw %%mm5, %%mm7        \n\t" // create mask pbv bytes < 0
148.3891 -            "psubw %%mm0, %%mm4          \n\t"
148.3892 -            "pand %%mm5, %%mm7           \n\t" // only pbv bytes < 0 in mm0
148.3893 -            "psubw %%mm0, %%mm4          \n\t"
148.3894 -            "psubw %%mm7, %%mm5          \n\t"
148.3895 -            "pxor %%mm0, %%mm0           \n\t"
148.3896 -            "pcmpgtw %%mm6, %%mm0        \n\t" // create mask pcv bytes < 0
148.3897 -            "pand %%mm6, %%mm0           \n\t" // only pav bytes < 0 in mm7
148.3898 -            "psubw %%mm7, %%mm5          \n\t"
148.3899 -            "psubw %%mm0, %%mm6          \n\t"
148.3900 -            //  test pa <= pb
148.3901 -            "movq %%mm4, %%mm7           \n\t"
148.3902 -            "psubw %%mm0, %%mm6          \n\t"
148.3903 -            "pcmpgtw %%mm5, %%mm7        \n\t" // pa > pb?
148.3904 -            "movq %%mm7, %%mm0           \n\t"
148.3905 -            // use mm7 mask to merge pa & pb
148.3906 -            "pand %%mm7, %%mm5           \n\t"
148.3907 -            // use mm0 mask copy to merge a & b
148.3908 -            "pand %%mm0, %%mm2           \n\t"
148.3909 -            "pandn %%mm4, %%mm7          \n\t"
148.3910 -            "pandn %%mm1, %%mm0          \n\t"
148.3911 -            "paddw %%mm5, %%mm7          \n\t"
148.3912 -            "paddw %%mm2, %%mm0          \n\t"
148.3913 -            //  test  ((pa <= pb)? pa:pb) <= pc
148.3914 -            "pcmpgtw %%mm6, %%mm7        \n\t" // pab > pc?
148.3915 -            "pxor %%mm1, %%mm1           \n\t"
148.3916 -            "pand %%mm7, %%mm3           \n\t"
148.3917 -            "pandn %%mm0, %%mm7          \n\t"
148.3918 -            "paddw %%mm3, %%mm7          \n\t"
148.3919 -            "pxor %%mm0, %%mm0           \n\t"
148.3920 -            "packuswb %%mm1, %%mm7       \n\t"
148.3921 -            "movq -8(%%esi,%%ecx,), %%mm3 \n\t" // load c=Prior(x-bpp)
148.3922 -            "pand _ActiveMask, %%mm7     \n\t"
148.3923 -            "psrlq _ShiftRem, %%mm3      \n\t"
148.3924 -            "movq (%%esi,%%ecx,), %%mm2  \n\t" // load b=Prior(x) step 1
148.3925 -            "paddb (%%edi,%%ecx,), %%mm7 \n\t" // add Paeth predictor and Raw(x)
148.3926 -            "movq %%mm2, %%mm6           \n\t"
148.3927 -            "movq %%mm7, (%%edi,%%ecx,)  \n\t" // write back updated value
148.3928 -            "movq -8(%%edi,%%ecx,), %%mm1 \n\t"
148.3929 -            "psllq _ShiftBpp, %%mm6      \n\t"
148.3930 -            "movq %%mm7, %%mm5           \n\t"
148.3931 -            "psrlq _ShiftRem, %%mm1      \n\t"
148.3932 -            "por %%mm6, %%mm3            \n\t"
148.3933 -            "psllq _ShiftBpp, %%mm5      \n\t"
148.3934 -            "punpckhbw %%mm0, %%mm3      \n\t" // unpack High bytes of c
148.3935 -            "por %%mm5, %%mm1            \n\t"
148.3936 -            // do second set of 4 bytes
148.3937 -            "punpckhbw %%mm0, %%mm2      \n\t" // unpack High bytes of b
148.3938 -            "punpckhbw %%mm0, %%mm1      \n\t" // unpack High bytes of a
148.3939 -            // pav = p - a = (a + b - c) - a = b - c
148.3940 -            "movq %%mm2, %%mm4           \n\t"
148.3941 -            // pbv = p - b = (a + b - c) - b = a - c
148.3942 -            "movq %%mm1, %%mm5           \n\t"
148.3943 -            "psubw %%mm3, %%mm4          \n\t"
148.3944 -            "pxor %%mm7, %%mm7           \n\t"
148.3945 -            // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
148.3946 -            "movq %%mm4, %%mm6           \n\t"
148.3947 -            "psubw %%mm3, %%mm5          \n\t"
148.3948 -            // pa = abs(p-a) = abs(pav)
148.3949 -            // pb = abs(p-b) = abs(pbv)
148.3950 -            // pc = abs(p-c) = abs(pcv)
148.3951 -            "pcmpgtw %%mm4, %%mm0        \n\t" // create mask pav bytes < 0
148.3952 -            "paddw %%mm5, %%mm6          \n\t"
148.3953 -            "pand %%mm4, %%mm0           \n\t" // only pav bytes < 0 in mm7
148.3954 -            "pcmpgtw %%mm5, %%mm7        \n\t" // create mask pbv bytes < 0
148.3955 -            "psubw %%mm0, %%mm4          \n\t"
148.3956 -            "pand %%mm5, %%mm7           \n\t" // only pbv bytes < 0 in mm0
148.3957 -            "psubw %%mm0, %%mm4          \n\t"
148.3958 -            "psubw %%mm7, %%mm5          \n\t"
148.3959 -            "pxor %%mm0, %%mm0           \n\t"
148.3960 -            "pcmpgtw %%mm6, %%mm0        \n\t" // create mask pcv bytes < 0
148.3961 -            "pand %%mm6, %%mm0           \n\t" // only pav bytes < 0 in mm7
148.3962 -            "psubw %%mm7, %%mm5          \n\t"
148.3963 -            "psubw %%mm0, %%mm6          \n\t"
148.3964 -            //  test pa <= pb
148.3965 -            "movq %%mm4, %%mm7           \n\t"
148.3966 -            "psubw %%mm0, %%mm6          \n\t"
148.3967 -            "pcmpgtw %%mm5, %%mm7        \n\t" // pa > pb?
148.3968 -            "movq %%mm7, %%mm0           \n\t"
148.3969 -            // use mm7 mask to merge pa & pb
148.3970 -            "pand %%mm7, %%mm5           \n\t"
148.3971 -            // use mm0 mask copy to merge a & b
148.3972 -            "pand %%mm0, %%mm2           \n\t"
148.3973 -            "pandn %%mm4, %%mm7          \n\t"
148.3974 -            "pandn %%mm1, %%mm0          \n\t"
148.3975 -            "paddw %%mm5, %%mm7          \n\t"
148.3976 -            "paddw %%mm2, %%mm0          \n\t"
148.3977 -            //  test  ((pa <= pb)? pa:pb) <= pc
148.3978 -            "pcmpgtw %%mm6, %%mm7        \n\t" // pab > pc?
148.3979 -            "pxor %%mm1, %%mm1           \n\t"
148.3980 -            "pand %%mm7, %%mm3           \n\t"
148.3981 -            "pandn %%mm0, %%mm7          \n\t"
148.3982 -            "pxor %%mm1, %%mm1           \n\t"
148.3983 -            "paddw %%mm3, %%mm7          \n\t"
148.3984 -            "pxor %%mm0, %%mm0           \n\t"
148.3985 -            // step ecx to next set of 8 bytes and repeat loop til done
148.3986 -            "addl $8, %%ecx              \n\t"
148.3987 -            "packuswb %%mm7, %%mm1       \n\t"
148.3988 -            "paddb -8(%%edi,%%ecx,), %%mm1 \n\t" // add Paeth predictor with Raw(x)
148.3989 -            "cmpl _MMXLength, %%ecx      \n\t"
148.3990 -            "movq %%mm1, -8(%%edi,%%ecx,) \n\t" // write back updated value
148.3991 -                                // mm1 will be used as Raw(x-bpp) next loop
148.3992 -            "jb paeth_6lp                \n\t"
148.3993 -
148.3994 -            : "=S" (dummy_value_S),             // output regs (dummy)
148.3995 -              "=D" (dummy_value_D)
148.3996 -
148.3997 -            : "0" (prev_row),  // esi           // input regs
148.3998 -              "1" (row)        // edi
148.3999 -
148.4000 -            : "%ecx"                            // clobber list
148.4001 -#if 0  /* %mm0, ..., %mm7 not supported by gcc 2.7.2.3 or egcs 1.1 */
148.4002 -            , "%mm0", "%mm1", "%mm2", "%mm3"
148.4003 -            , "%mm4", "%mm5", "%mm6", "%mm7"
148.4004 -#endif
148.4005 -         );
148.4006 -      }
148.4007 -      break;  // end 6 bpp
148.4008 -
148.4009 -      case 4:
148.4010 -      {
148.4011 -         _ActiveMask.use  = 0x00000000ffffffffLL;
148.4012 -
148.4013 -         __asm__ __volatile__ (
148.4014 -            "movl _dif, %%ecx            \n\t"
148.4015 -// preload  "movl row, %%edi             \n\t"
148.4016 -// preload  "movl prev_row, %%esi        \n\t"
148.4017 -            "pxor %%mm0, %%mm0           \n\t"
148.4018 -            // prime the pump:  load the first Raw(x-bpp) data set
148.4019 -            "movq -8(%%edi,%%ecx,), %%mm1 \n\t" // only time should need to read
148.4020 -                                     //  a=Raw(x-bpp) bytes
148.4021 -         "paeth_4lp:                     \n\t"
148.4022 -            // do first set of 4 bytes
148.4023 -            "movq -8(%%esi,%%ecx,), %%mm3 \n\t" // read c=Prior(x-bpp) bytes
148.4024 -            "punpckhbw %%mm0, %%mm1      \n\t" // unpack Low bytes of a
148.4025 -            "movq (%%esi,%%ecx,), %%mm2  \n\t" // load b=Prior(x)
148.4026 -            "punpcklbw %%mm0, %%mm2      \n\t" // unpack High bytes of b
148.4027 -            // pav = p - a = (a + b - c) - a = b - c
148.4028 -            "movq %%mm2, %%mm4           \n\t"
148.4029 -            "punpckhbw %%mm0, %%mm3      \n\t" // unpack High bytes of c
148.4030 -            // pbv = p - b = (a + b - c) - b = a - c
148.4031 -            "movq %%mm1, %%mm5           \n\t"
148.4032 -            "psubw %%mm3, %%mm4          \n\t"
148.4033 -            "pxor %%mm7, %%mm7           \n\t"
148.4034 -            // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
148.4035 -            "movq %%mm4, %%mm6           \n\t"
148.4036 -            "psubw %%mm3, %%mm5          \n\t"
148.4037 -            // pa = abs(p-a) = abs(pav)
148.4038 -            // pb = abs(p-b) = abs(pbv)
148.4039 -            // pc = abs(p-c) = abs(pcv)
148.4040 -            "pcmpgtw %%mm4, %%mm0        \n\t" // create mask pav bytes < 0
148.4041 -            "paddw %%mm5, %%mm6          \n\t"
148.4042 -            "pand %%mm4, %%mm0           \n\t" // only pav bytes < 0 in mm7
148.4043 -            "pcmpgtw %%mm5, %%mm7        \n\t" // create mask pbv bytes < 0
148.4044 -            "psubw %%mm0, %%mm4          \n\t"
148.4045 -            "pand %%mm5, %%mm7           \n\t" // only pbv bytes < 0 in mm0
148.4046 -            "psubw %%mm0, %%mm4          \n\t"
148.4047 -            "psubw %%mm7, %%mm5          \n\t"
148.4048 -            "pxor %%mm0, %%mm0           \n\t"
148.4049 -            "pcmpgtw %%mm6, %%mm0        \n\t" // create mask pcv bytes < 0
148.4050 -            "pand %%mm6, %%mm0           \n\t" // only pav bytes < 0 in mm7
148.4051 -            "psubw %%mm7, %%mm5          \n\t"
148.4052 -            "psubw %%mm0, %%mm6          \n\t"
148.4053 -            //  test pa <= pb
148.4054 -            "movq %%mm4, %%mm7           \n\t"
148.4055 -            "psubw %%mm0, %%mm6          \n\t"
148.4056 -            "pcmpgtw %%mm5, %%mm7        \n\t" // pa > pb?
148.4057 -            "movq %%mm7, %%mm0           \n\t"
148.4058 -            // use mm7 mask to merge pa & pb
148.4059 -            "pand %%mm7, %%mm5           \n\t"
148.4060 -            // use mm0 mask copy to merge a & b
148.4061 -            "pand %%mm0, %%mm2           \n\t"
148.4062 -            "pandn %%mm4, %%mm7          \n\t"
148.4063 -            "pandn %%mm1, %%mm0          \n\t"
148.4064 -            "paddw %%mm5, %%mm7          \n\t"
148.4065 -            "paddw %%mm2, %%mm0          \n\t"
148.4066 -            //  test  ((pa <= pb)? pa:pb) <= pc
148.4067 -            "pcmpgtw %%mm6, %%mm7        \n\t" // pab > pc?
148.4068 -            "pxor %%mm1, %%mm1           \n\t"
148.4069 -            "pand %%mm7, %%mm3           \n\t"
148.4070 -            "pandn %%mm0, %%mm7          \n\t"
148.4071 -            "paddw %%mm3, %%mm7          \n\t"
148.4072 -            "pxor %%mm0, %%mm0           \n\t"
148.4073 -            "packuswb %%mm1, %%mm7       \n\t"
148.4074 -            "movq (%%esi,%%ecx,), %%mm3  \n\t" // load c=Prior(x-bpp)
148.4075 -            "pand _ActiveMask, %%mm7     \n\t"
148.4076 -            "movq %%mm3, %%mm2           \n\t" // load b=Prior(x) step 1
148.4077 -            "paddb (%%edi,%%ecx,), %%mm7 \n\t" // add Paeth predictor with Raw(x)
148.4078 -            "punpcklbw %%mm0, %%mm3      \n\t" // unpack High bytes of c
148.4079 -            "movq %%mm7, (%%edi,%%ecx,)  \n\t" // write back updated value
148.4080 -            "movq %%mm7, %%mm1           \n\t" // now mm1 will be used as Raw(x-bpp)
148.4081 -            // do second set of 4 bytes
148.4082 -            "punpckhbw %%mm0, %%mm2      \n\t" // unpack Low bytes of b
148.4083 -            "punpcklbw %%mm0, %%mm1      \n\t" // unpack Low bytes of a
148.4084 -            // pav = p - a = (a + b - c) - a = b - c
148.4085 -            "movq %%mm2, %%mm4           \n\t"
148.4086 -            // pbv = p - b = (a + b - c) - b = a - c
148.4087 -            "movq %%mm1, %%mm5           \n\t"
148.4088 -            "psubw %%mm3, %%mm4          \n\t"
148.4089 -            "pxor %%mm7, %%mm7           \n\t"
148.4090 -            // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
148.4091 -            "movq %%mm4, %%mm6           \n\t"
148.4092 -            "psubw %%mm3, %%mm5          \n\t"
148.4093 -            // pa = abs(p-a) = abs(pav)
148.4094 -            // pb = abs(p-b) = abs(pbv)
148.4095 -            // pc = abs(p-c) = abs(pcv)
148.4096 -            "pcmpgtw %%mm4, %%mm0        \n\t" // create mask pav bytes < 0
148.4097 -            "paddw %%mm5, %%mm6          \n\t"
148.4098 -            "pand %%mm4, %%mm0           \n\t" // only pav bytes < 0 in mm7
148.4099 -            "pcmpgtw %%mm5, %%mm7        \n\t" // create mask pbv bytes < 0
148.4100 -            "psubw %%mm0, %%mm4          \n\t"
148.4101 -            "pand %%mm5, %%mm7           \n\t" // only pbv bytes < 0 in mm0
148.4102 -            "psubw %%mm0, %%mm4          \n\t"
148.4103 -            "psubw %%mm7, %%mm5          \n\t"
148.4104 -            "pxor %%mm0, %%mm0           \n\t"
148.4105 -            "pcmpgtw %%mm6, %%mm0        \n\t" // create mask pcv bytes < 0
148.4106 -            "pand %%mm6, %%mm0           \n\t" // only pav bytes < 0 in mm7
148.4107 -            "psubw %%mm7, %%mm5          \n\t"
148.4108 -            "psubw %%mm0, %%mm6          \n\t"
148.4109 -            //  test pa <= pb
148.4110 -            "movq %%mm4, %%mm7           \n\t"
148.4111 -            "psubw %%mm0, %%mm6          \n\t"
148.4112 -            "pcmpgtw %%mm5, %%mm7        \n\t" // pa > pb?
148.4113 -            "movq %%mm7, %%mm0           \n\t"
148.4114 -            // use mm7 mask to merge pa & pb
148.4115 -            "pand %%mm7, %%mm5           \n\t"
148.4116 -            // use mm0 mask copy to merge a & b
148.4117 -            "pand %%mm0, %%mm2           \n\t"
148.4118 -            "pandn %%mm4, %%mm7          \n\t"
148.4119 -            "pandn %%mm1, %%mm0          \n\t"
148.4120 -            "paddw %%mm5, %%mm7          \n\t"
148.4121 -            "paddw %%mm2, %%mm0          \n\t"
148.4122 -            //  test  ((pa <= pb)? pa:pb) <= pc
148.4123 -            "pcmpgtw %%mm6, %%mm7        \n\t" // pab > pc?
148.4124 -            "pxor %%mm1, %%mm1           \n\t"
148.4125 -            "pand %%mm7, %%mm3           \n\t"
148.4126 -            "pandn %%mm0, %%mm7          \n\t"
148.4127 -            "pxor %%mm1, %%mm1           \n\t"
148.4128 -            "paddw %%mm3, %%mm7          \n\t"
148.4129 -            "pxor %%mm0, %%mm0           \n\t"
148.4130 -            // step ecx to next set of 8 bytes and repeat loop til done
148.4131 -            "addl $8, %%ecx              \n\t"
148.4132 -            "packuswb %%mm7, %%mm1       \n\t"
148.4133 -            "paddb -8(%%edi,%%ecx,), %%mm1 \n\t" // add predictor with Raw(x)
148.4134 -            "cmpl _MMXLength, %%ecx      \n\t"
148.4135 -            "movq %%mm1, -8(%%edi,%%ecx,) \n\t" // write back updated value
148.4136 -                                // mm1 will be used as Raw(x-bpp) next loop
148.4137 -            "jb paeth_4lp                \n\t"
148.4138 -
148.4139 -            : "=S" (dummy_value_S),             // output regs (dummy)
148.4140 -              "=D" (dummy_value_D)
148.4141 -
148.4142 -            : "0" (prev_row),  // esi           // input regs
148.4143 -              "1" (row)        // edi
148.4144 -
148.4145 -            : "%ecx"                            // clobber list
148.4146 -#if 0  /* %mm0, ..., %mm7 not supported by gcc 2.7.2.3 or egcs 1.1 */
148.4147 -            , "%mm0", "%mm1", "%mm2", "%mm3"
148.4148 -            , "%mm4", "%mm5", "%mm6", "%mm7"
148.4149 -#endif
148.4150 -         );
148.4151 -      }
148.4152 -      break;  // end 4 bpp
148.4153 -
148.4154 -      case 8:                          // bpp == 8
148.4155 -      {
148.4156 -         _ActiveMask.use  = 0x00000000ffffffffLL;
148.4157 -
148.4158 -         __asm__ __volatile__ (
148.4159 -            "movl _dif, %%ecx            \n\t"
148.4160 -// preload  "movl row, %%edi             \n\t"
148.4161 -// preload  "movl prev_row, %%esi        \n\t"
148.4162 -            "pxor %%mm0, %%mm0           \n\t"
148.4163 -            // prime the pump:  load the first Raw(x-bpp) data set
148.4164 -            "movq -8(%%edi,%%ecx,), %%mm1 \n\t" // only time should need to read
148.4165 -                                       //  a=Raw(x-bpp) bytes
148.4166 -         "paeth_8lp:                     \n\t"
148.4167 -            // do first set of 4 bytes
148.4168 -            "movq -8(%%esi,%%ecx,), %%mm3 \n\t" // read c=Prior(x-bpp) bytes
148.4169 -            "punpcklbw %%mm0, %%mm1      \n\t" // unpack Low bytes of a
148.4170 -            "movq (%%esi,%%ecx,), %%mm2  \n\t" // load b=Prior(x)
148.4171 -            "punpcklbw %%mm0, %%mm2      \n\t" // unpack Low bytes of b
148.4172 -            // pav = p - a = (a + b - c) - a = b - c
148.4173 -            "movq %%mm2, %%mm4           \n\t"
148.4174 -            "punpcklbw %%mm0, %%mm3      \n\t" // unpack Low bytes of c
148.4175 -            // pbv = p - b = (a + b - c) - b = a - c
148.4176 -            "movq %%mm1, %%mm5           \n\t"
148.4177 -            "psubw %%mm3, %%mm4          \n\t"
148.4178 -            "pxor %%mm7, %%mm7           \n\t"
148.4179 -            // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
148.4180 -            "movq %%mm4, %%mm6           \n\t"
148.4181 -            "psubw %%mm3, %%mm5          \n\t"
148.4182 -            // pa = abs(p-a) = abs(pav)
148.4183 -            // pb = abs(p-b) = abs(pbv)
148.4184 -            // pc = abs(p-c) = abs(pcv)
148.4185 -            "pcmpgtw %%mm4, %%mm0        \n\t" // create mask pav bytes < 0
148.4186 -            "paddw %%mm5, %%mm6          \n\t"
148.4187 -            "pand %%mm4, %%mm0           \n\t" // only pav bytes < 0 in mm7
148.4188 -            "pcmpgtw %%mm5, %%mm7        \n\t" // create mask pbv bytes < 0
148.4189 -            "psubw %%mm0, %%mm4          \n\t"
148.4190 -            "pand %%mm5, %%mm7           \n\t" // only pbv bytes < 0 in mm0
148.4191 -            "psubw %%mm0, %%mm4          \n\t"
148.4192 -            "psubw %%mm7, %%mm5          \n\t"
148.4193 -            "pxor %%mm0, %%mm0           \n\t"
148.4194 -            "pcmpgtw %%mm6, %%mm0        \n\t" // create mask pcv bytes < 0
148.4195 -            "pand %%mm6, %%mm0           \n\t" // only pav bytes < 0 in mm7
148.4196 -            "psubw %%mm7, %%mm5          \n\t"
148.4197 -            "psubw %%mm0, %%mm6          \n\t"
148.4198 -            //  test pa <= pb
148.4199 -            "movq %%mm4, %%mm7           \n\t"
148.4200 -            "psubw %%mm0, %%mm6          \n\t"
148.4201 -            "pcmpgtw %%mm5, %%mm7        \n\t" // pa > pb?
148.4202 -            "movq %%mm7, %%mm0           \n\t"
148.4203 -            // use mm7 mask to merge pa & pb
148.4204 -            "pand %%mm7, %%mm5           \n\t"
148.4205 -            // use mm0 mask copy to merge a & b
148.4206 -            "pand %%mm0, %%mm2           \n\t"
148.4207 -            "pandn %%mm4, %%mm7          \n\t"
148.4208 -            "pandn %%mm1, %%mm0          \n\t"
148.4209 -            "paddw %%mm5, %%mm7          \n\t"
148.4210 -            "paddw %%mm2, %%mm0          \n\t"
148.4211 -            //  test  ((pa <= pb)? pa:pb) <= pc
148.4212 -            "pcmpgtw %%mm6, %%mm7        \n\t" // pab > pc?
148.4213 -            "pxor %%mm1, %%mm1           \n\t"
148.4214 -            "pand %%mm7, %%mm3           \n\t"
148.4215 -            "pandn %%mm0, %%mm7          \n\t"
148.4216 -            "paddw %%mm3, %%mm7          \n\t"
148.4217 -            "pxor %%mm0, %%mm0           \n\t"
148.4218 -            "packuswb %%mm1, %%mm7       \n\t"
148.4219 -            "movq -8(%%esi,%%ecx,), %%mm3 \n\t" // read c=Prior(x-bpp) bytes
148.4220 -            "pand _ActiveMask, %%mm7     \n\t"
148.4221 -            "movq (%%esi,%%ecx,), %%mm2  \n\t" // load b=Prior(x)
148.4222 -            "paddb (%%edi,%%ecx,), %%mm7 \n\t" // add Paeth predictor with Raw(x)
148.4223 -            "punpckhbw %%mm0, %%mm3      \n\t" // unpack High bytes of c
148.4224 -            "movq %%mm7, (%%edi,%%ecx,)  \n\t" // write back updated value
148.4225 -            "movq -8(%%edi,%%ecx,), %%mm1 \n\t" // read a=Raw(x-bpp) bytes
148.4226 -
148.4227 -            // do second set of 4 bytes
148.4228 -            "punpckhbw %%mm0, %%mm2      \n\t" // unpack High bytes of b
148.4229 -            "punpckhbw %%mm0, %%mm1      \n\t" // unpack High bytes of a
148.4230 -            // pav = p - a = (a + b - c) - a = b - c
148.4231 -            "movq %%mm2, %%mm4           \n\t"
148.4232 -            // pbv = p - b = (a + b - c) - b = a - c
148.4233 -            "movq %%mm1, %%mm5           \n\t"
148.4234 -            "psubw %%mm3, %%mm4          \n\t"
148.4235 -            "pxor %%mm7, %%mm7           \n\t"
148.4236 -            // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
148.4237 -            "movq %%mm4, %%mm6           \n\t"
148.4238 -            "psubw %%mm3, %%mm5          \n\t"
148.4239 -            // pa = abs(p-a) = abs(pav)
148.4240 -            // pb = abs(p-b) = abs(pbv)
148.4241 -            // pc = abs(p-c) = abs(pcv)
148.4242 -            "pcmpgtw %%mm4, %%mm0        \n\t" // create mask pav bytes < 0
148.4243 -            "paddw %%mm5, %%mm6          \n\t"
148.4244 -            "pand %%mm4, %%mm0           \n\t" // only pav bytes < 0 in mm7
148.4245 -            "pcmpgtw %%mm5, %%mm7        \n\t" // create mask pbv bytes < 0
148.4246 -            "psubw %%mm0, %%mm4          \n\t"
148.4247 -            "pand %%mm5, %%mm7           \n\t" // only pbv bytes < 0 in mm0
148.4248 -            "psubw %%mm0, %%mm4          \n\t"
148.4249 -            "psubw %%mm7, %%mm5          \n\t"
148.4250 -            "pxor %%mm0, %%mm0           \n\t"
148.4251 -            "pcmpgtw %%mm6, %%mm0        \n\t" // create mask pcv bytes < 0
148.4252 -            "pand %%mm6, %%mm0           \n\t" // only pav bytes < 0 in mm7
148.4253 -            "psubw %%mm7, %%mm5          \n\t"
148.4254 -            "psubw %%mm0, %%mm6          \n\t"
148.4255 -            //  test pa <= pb
148.4256 -            "movq %%mm4, %%mm7           \n\t"
148.4257 -            "psubw %%mm0, %%mm6          \n\t"
148.4258 -            "pcmpgtw %%mm5, %%mm7        \n\t" // pa > pb?
148.4259 -            "movq %%mm7, %%mm0           \n\t"
148.4260 -            // use mm7 mask to merge pa & pb
148.4261 -            "pand %%mm7, %%mm5           \n\t"
148.4262 -            // use mm0 mask copy to merge a & b
148.4263 -            "pand %%mm0, %%mm2           \n\t"
148.4264 -            "pandn %%mm4, %%mm7          \n\t"
148.4265 -            "pandn %%mm1, %%mm0          \n\t"
148.4266 -            "paddw %%mm5, %%mm7          \n\t"
148.4267 -            "paddw %%mm2, %%mm0          \n\t"
148.4268 -            //  test  ((pa <= pb)? pa:pb) <= pc
148.4269 -            "pcmpgtw %%mm6, %%mm7        \n\t" // pab > pc?
148.4270 -            "pxor %%mm1, %%mm1           \n\t"
148.4271 -            "pand %%mm7, %%mm3           \n\t"
148.4272 -            "pandn %%mm0, %%mm7          \n\t"
148.4273 -            "pxor %%mm1, %%mm1           \n\t"
148.4274 -            "paddw %%mm3, %%mm7          \n\t"
148.4275 -            "pxor %%mm0, %%mm0           \n\t"
148.4276 -            // step ecx to next set of 8 bytes and repeat loop til done
148.4277 -            "addl $8, %%ecx              \n\t"
148.4278 -            "packuswb %%mm7, %%mm1       \n\t"
148.4279 -            "paddb -8(%%edi,%%ecx,), %%mm1 \n\t" // add Paeth predictor with Raw(x)
148.4280 -            "cmpl _MMXLength, %%ecx      \n\t"
148.4281 -            "movq %%mm1, -8(%%edi,%%ecx,) \n\t" // write back updated value
148.4282 -                            // mm1 will be used as Raw(x-bpp) next loop
148.4283 -            "jb paeth_8lp                \n\t"
148.4284 -
148.4285 -            : "=S" (dummy_value_S),             // output regs (dummy)
148.4286 -              "=D" (dummy_value_D)
148.4287 -
148.4288 -            : "0" (prev_row),  // esi           // input regs
148.4289 -              "1" (row)        // edi
148.4290 -
148.4291 -            : "%ecx"                            // clobber list
148.4292 -#if 0  /* %mm0, ..., %mm7 not supported by gcc 2.7.2.3 or egcs 1.1 */
148.4293 -            , "%mm0", "%mm1", "%mm2", "%mm3"
148.4294 -            , "%mm4", "%mm5", "%mm6", "%mm7"
148.4295 -#endif
148.4296 -         );
148.4297 -      }
148.4298 -      break;  // end 8 bpp
148.4299 -
148.4300 -      case 1:                // bpp = 1
148.4301 -      case 2:                // bpp = 2
148.4302 -      default:               // bpp > 8
148.4303 -      {
148.4304 -         __asm__ __volatile__ (
148.4305 -#ifdef __PIC__
148.4306 -            "pushl %%ebx                 \n\t" // save Global Offset Table index
148.4307 -#endif
148.4308 -            "movl _dif, %%ebx            \n\t"
148.4309 -            "cmpl _FullLength, %%ebx     \n\t"
148.4310 -            "jnb paeth_dend              \n\t"
148.4311 -
148.4312 -// preload  "movl row, %%edi             \n\t"
148.4313 -// preload  "movl prev_row, %%esi        \n\t"
148.4314 -            // do Paeth decode for remaining bytes
148.4315 -            "movl %%ebx, %%edx           \n\t"
148.4316 -// preload  "subl bpp, %%edx             \n\t" // (bpp is preloaded into ecx)
148.4317 -            "subl %%ecx, %%edx           \n\t" // edx = ebx - bpp
148.4318 -            "xorl %%ecx, %%ecx           \n\t" // zero ecx before using cl & cx
148.4319 -
148.4320 -         "paeth_dlp:                     \n\t"
148.4321 -            "xorl %%eax, %%eax           \n\t"
148.4322 -            // pav = p - a = (a + b - c) - a = b - c
148.4323 -            "movb (%%esi,%%ebx,), %%al   \n\t" // load Prior(x) into al
148.4324 -            "movb (%%esi,%%edx,), %%cl   \n\t" // load Prior(x-bpp) into cl
148.4325 -            "subl %%ecx, %%eax           \n\t" // subtract Prior(x-bpp)
148.4326 -            "movl %%eax, _patemp         \n\t" // Save pav for later use
148.4327 -            "xorl %%eax, %%eax           \n\t"
148.4328 -            // pbv = p - b = (a + b - c) - b = a - c
148.4329 -            "movb (%%edi,%%edx,), %%al   \n\t" // load Raw(x-bpp) into al
148.4330 -            "subl %%ecx, %%eax           \n\t" // subtract Prior(x-bpp)
148.4331 -            "movl %%eax, %%ecx           \n\t"
148.4332 -            // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
148.4333 -            "addl _patemp, %%eax         \n\t" // pcv = pav + pbv
148.4334 -            // pc = abs(pcv)
148.4335 -            "testl $0x80000000, %%eax    \n\t"
148.4336 -            "jz paeth_dpca               \n\t"
148.4337 -            "negl %%eax                  \n\t" // reverse sign of neg values
148.4338 -
148.4339 -         "paeth_dpca:                    \n\t"
148.4340 -            "movl %%eax, _pctemp         \n\t" // save pc for later use
148.4341 -            // pb = abs(pbv)
148.4342 -            "testl $0x80000000, %%ecx    \n\t"
148.4343 -            "jz paeth_dpba               \n\t"
148.4344 -            "negl %%ecx                  \n\t" // reverse sign of neg values
148.4345 -
148.4346 -         "paeth_dpba:                    \n\t"
148.4347 -            "movl %%ecx, _pbtemp         \n\t" // save pb for later use
148.4348 -            // pa = abs(pav)
148.4349 -            "movl _patemp, %%eax         \n\t"
148.4350 -            "testl $0x80000000, %%eax    \n\t"
148.4351 -            "jz paeth_dpaa               \n\t"
148.4352 -            "negl %%eax                  \n\t" // reverse sign of neg values
148.4353 -
148.4354 -         "paeth_dpaa:                    \n\t"
148.4355 -            "movl %%eax, _patemp         \n\t" // save pa for later use
148.4356 -            // test if pa <= pb
148.4357 -            "cmpl %%ecx, %%eax           \n\t"
148.4358 -            "jna paeth_dabb              \n\t"
148.4359 -            // pa > pb; now test if pb <= pc
148.4360 -            "cmpl _pctemp, %%ecx         \n\t"
148.4361 -            "jna paeth_dbbc              \n\t"
148.4362 -            // pb > pc; Raw(x) = Paeth(x) + Prior(x-bpp)
148.4363 -            "movb (%%esi,%%edx,), %%cl   \n\t" // load Prior(x-bpp) into cl
148.4364 -            "jmp paeth_dpaeth            \n\t"
148.4365 -
148.4366 -         "paeth_dbbc:                    \n\t"
148.4367 -            // pb <= pc; Raw(x) = Paeth(x) + Prior(x)
148.4368 -            "movb (%%esi,%%ebx,), %%cl   \n\t" // load Prior(x) into cl
148.4369 -            "jmp paeth_dpaeth            \n\t"
148.4370 -
148.4371 -         "paeth_dabb:                    \n\t"
148.4372 -            // pa <= pb; now test if pa <= pc
148.4373 -            "cmpl _pctemp, %%eax         \n\t"
148.4374 -            "jna paeth_dabc              \n\t"
148.4375 -            // pa > pc; Raw(x) = Paeth(x) + Prior(x-bpp)
148.4376 -            "movb (%%esi,%%edx,), %%cl   \n\t" // load Prior(x-bpp) into cl
148.4377 -            "jmp paeth_dpaeth            \n\t"
148.4378 -
148.4379 -         "paeth_dabc:                    \n\t"
148.4380 -            // pa <= pc; Raw(x) = Paeth(x) + Raw(x-bpp)
148.4381 -            "movb (%%edi,%%edx,), %%cl   \n\t" // load Raw(x-bpp) into cl
148.4382 -
148.4383 -         "paeth_dpaeth:                  \n\t"
148.4384 -            "incl %%ebx                  \n\t"
148.4385 -            "incl %%edx                  \n\t"
148.4386 -            // Raw(x) = (Paeth(x) + Paeth_Predictor( a, b, c )) mod 256
148.4387 -            "addb %%cl, -1(%%edi,%%ebx,) \n\t"
148.4388 -            "cmpl _FullLength, %%ebx     \n\t"
148.4389 -            "jb paeth_dlp                \n\t"
148.4390 -
148.4391 -         "paeth_dend:                    \n\t"
148.4392 -#ifdef __PIC__
148.4393 -            "popl %%ebx                  \n\t" // index to Global Offset Table
148.4394 -#endif
148.4395 -
148.4396 -            : "=c" (dummy_value_c),            // output regs (dummy)
148.4397 -              "=S" (dummy_value_S),
148.4398 -              "=D" (dummy_value_D)
148.4399 -
148.4400 -            : "0" (bpp),       // ecx          // input regs
148.4401 -              "1" (prev_row),  // esi
148.4402 -              "2" (row)        // edi
148.4403 -
148.4404 -            : "%eax", "%edx"                   // clobber list
148.4405 -#ifndef __PIC__
148.4406 -            , "%ebx"
148.4407 -#endif
148.4408 -         );
148.4409 -      }
148.4410 -      return;                   // No need to go further with this one
148.4411 -
148.4412 -   } // end switch (bpp)
148.4413 -
148.4414 -   __asm__ __volatile__ (
148.4415 -      // MMX acceleration complete; now do clean-up
148.4416 -      // check if any remaining bytes left to decode
148.4417 -#ifdef __PIC__
148.4418 -      "pushl %%ebx                 \n\t" // save index to Global Offset Table
148.4419 -#endif
148.4420 -      "movl _MMXLength, %%ebx      \n\t"
148.4421 -      "cmpl _FullLength, %%ebx     \n\t"
148.4422 -      "jnb paeth_end               \n\t"
148.4423 -//pre "movl row, %%edi             \n\t"
148.4424 -//pre "movl prev_row, %%esi        \n\t"
148.4425 -      // do Paeth decode for remaining bytes
148.4426 -      "movl %%ebx, %%edx           \n\t"
148.4427 -//pre "subl bpp, %%edx             \n\t" // (bpp is preloaded into ecx)
148.4428 -      "subl %%ecx, %%edx           \n\t" // edx = ebx - bpp
148.4429 -      "xorl %%ecx, %%ecx           \n\t" // zero ecx before using cl & cx below
148.4430 -
148.4431 -   "paeth_lp2:                     \n\t"
148.4432 -      "xorl %%eax, %%eax           \n\t"
148.4433 -      // pav = p - a = (a + b - c) - a = b - c
148.4434 -      "movb (%%esi,%%ebx,), %%al   \n\t" // load Prior(x) into al
148.4435 -      "movb (%%esi,%%edx,), %%cl   \n\t" // load Prior(x-bpp) into cl
148.4436 -      "subl %%ecx, %%eax           \n\t" // subtract Prior(x-bpp)
148.4437 -      "movl %%eax, _patemp         \n\t" // Save pav for later use
148.4438 -      "xorl %%eax, %%eax           \n\t"
148.4439 -      // pbv = p - b = (a + b - c) - b = a - c
148.4440 -      "movb (%%edi,%%edx,), %%al   \n\t" // load Raw(x-bpp) into al
148.4441 -      "subl %%ecx, %%eax           \n\t" // subtract Prior(x-bpp)
148.4442 -      "movl %%eax, %%ecx           \n\t"
148.4443 -      // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
148.4444 -      "addl _patemp, %%eax         \n\t" // pcv = pav + pbv
148.4445 -      // pc = abs(pcv)
148.4446 -      "testl $0x80000000, %%eax    \n\t"
148.4447 -      "jz paeth_pca2               \n\t"
148.4448 -      "negl %%eax                  \n\t" // reverse sign of neg values
148.4449 -
148.4450 -   "paeth_pca2:                    \n\t"
148.4451 -      "movl %%eax, _pctemp         \n\t" // save pc for later use
148.4452 -      // pb = abs(pbv)
148.4453 -      "testl $0x80000000, %%ecx    \n\t"
148.4454 -      "jz paeth_pba2               \n\t"
148.4455 -      "negl %%ecx                  \n\t" // reverse sign of neg values
148.4456 -
148.4457 -   "paeth_pba2:                    \n\t"
148.4458 -      "movl %%ecx, _pbtemp         \n\t" // save pb for later use
148.4459 -      // pa = abs(pav)
148.4460 -      "movl _patemp, %%eax         \n\t"
148.4461 -      "testl $0x80000000, %%eax    \n\t"
148.4462 -      "jz paeth_paa2               \n\t"
148.4463 -      "negl %%eax                  \n\t" // reverse sign of neg values
148.4464 -
148.4465 -   "paeth_paa2:                    \n\t"
148.4466 -      "movl %%eax, _patemp         \n\t" // save pa for later use
148.4467 -      // test if pa <= pb
148.4468 -      "cmpl %%ecx, %%eax           \n\t"
148.4469 -      "jna paeth_abb2              \n\t"
148.4470 -      // pa > pb; now test if pb <= pc
148.4471 -      "cmpl _pctemp, %%ecx         \n\t"
148.4472 -      "jna paeth_bbc2              \n\t"
148.4473 -      // pb > pc; Raw(x) = Paeth(x) + Prior(x-bpp)
148.4474 -      "movb (%%esi,%%edx,), %%cl   \n\t" // load Prior(x-bpp) into cl
148.4475 -      "jmp paeth_paeth2            \n\t"
148.4476 -
148.4477 -   "paeth_bbc2:                    \n\t"
148.4478 -      // pb <= pc; Raw(x) = Paeth(x) + Prior(x)
148.4479 -      "movb (%%esi,%%ebx,), %%cl   \n\t" // load Prior(x) into cl
148.4480 -      "jmp paeth_paeth2            \n\t"
148.4481 -
148.4482 -   "paeth_abb2:                    \n\t"
148.4483 -      // pa <= pb; now test if pa <= pc
148.4484 -      "cmpl _pctemp, %%eax         \n\t"
148.4485 -      "jna paeth_abc2              \n\t"
148.4486 -      // pa > pc; Raw(x) = Paeth(x) + Prior(x-bpp)
148.4487 -      "movb (%%esi,%%edx,), %%cl   \n\t" // load Prior(x-bpp) into cl
148.4488 -      "jmp paeth_paeth2            \n\t"
148.4489 -
148.4490 -   "paeth_abc2:                    \n\t"
148.4491 -      // pa <= pc; Raw(x) = Paeth(x) + Raw(x-bpp)
148.4492 -      "movb (%%edi,%%edx,), %%cl   \n\t" // load Raw(x-bpp) into cl
148.4493 -
148.4494 -   "paeth_paeth2:                  \n\t"
148.4495 -      "incl %%ebx                  \n\t"
148.4496 -      "incl %%edx                  \n\t"
148.4497 -      // Raw(x) = (Paeth(x) + Paeth_Predictor( a, b, c )) mod 256
148.4498 -      "addb %%cl, -1(%%edi,%%ebx,) \n\t"
148.4499 -      "cmpl _FullLength, %%ebx     \n\t"
148.4500 -      "jb paeth_lp2                \n\t"
148.4501 -
148.4502 -   "paeth_end:                     \n\t"
148.4503 -      "EMMS                        \n\t" // end MMX; prep for poss. FP instrs.
148.4504 -#ifdef __PIC__
148.4505 -      "popl %%ebx                  \n\t" // restore index to Global Offset Table
148.4506 -#endif
148.4507 -
148.4508 -      : "=c" (dummy_value_c),            // output regs (dummy)
148.4509 -        "=S" (dummy_value_S),
148.4510 -        "=D" (dummy_value_D)
148.4511 -
148.4512 -      : "0" (bpp),       // ecx          // input regs
148.4513 -        "1" (prev_row),  // esi
148.4514 -        "2" (row)        // edi
148.4515 -
148.4516 -      : "%eax", "%edx"                   // clobber list (no input regs!)
148.4517 -#ifndef __PIC__
148.4518 -      , "%ebx"
148.4519 -#endif
148.4520 -   );
148.4521 -
148.4522 -} /* end png_read_filter_row_mmx_paeth() */
148.4523 -#endif
148.4524 -
148.4525 -
148.4526 -
148.4527 -
148.4528 -#ifdef PNG_THREAD_UNSAFE_OK
148.4529 -//===========================================================================//
148.4530 -//                                                                           //
148.4531 -//           P N G _ R E A D _ F I L T E R _ R O W _ M M X _ S U B           //
148.4532 -//                                                                           //
148.4533 -//===========================================================================//
148.4534 -
148.4535 -// Optimized code for PNG Sub filter decoder
148.4536 -
148.4537 -static void /* PRIVATE */
148.4538 -png_read_filter_row_mmx_sub(png_row_infop row_info, png_bytep row)
148.4539 -{
148.4540 -   int bpp;
148.4541 -   int dummy_value_a;
148.4542 -   int dummy_value_D;
148.4543 -
148.4544 -   bpp = (row_info->pixel_depth + 7) >> 3;   // calc number of bytes per pixel
148.4545 -   _FullLength = row_info->rowbytes - bpp;   // number of bytes to filter
148.4546 -
148.4547 -   __asm__ __volatile__ (
148.4548 -//pre "movl row, %%edi             \n\t"
148.4549 -      "movl %%edi, %%esi           \n\t" // lp = row
148.4550 -//pre "movl bpp, %%eax             \n\t"
148.4551 -      "addl %%eax, %%edi           \n\t" // rp = row + bpp
148.4552 -//irr "xorl %%eax, %%eax           \n\t"
148.4553 -      // get # of bytes to alignment
148.4554 -      "movl %%edi, _dif            \n\t" // take start of row
148.4555 -      "addl $0xf, _dif             \n\t" // add 7 + 8 to incr past
148.4556 -                                         //  alignment boundary
148.4557 -      "xorl %%ecx, %%ecx           \n\t"
148.4558 -      "andl $0xfffffff8, _dif      \n\t" // mask to alignment boundary
148.4559 -      "subl %%edi, _dif            \n\t" // subtract from start ==> value
148.4560 -      "jz sub_go                   \n\t" //  ecx at alignment
148.4561 -
148.4562 -   "sub_lp1:                       \n\t" // fix alignment
148.4563 -      "movb (%%esi,%%ecx,), %%al   \n\t"
148.4564 -      "addb %%al, (%%edi,%%ecx,)   \n\t"
148.4565 -      "incl %%ecx                  \n\t"
148.4566 -      "cmpl _dif, %%ecx            \n\t"
148.4567 -      "jb sub_lp1                  \n\t"
148.4568 -
148.4569 -   "sub_go:                        \n\t"
148.4570 -      "movl _FullLength, %%eax     \n\t"
148.4571 -      "movl %%eax, %%edx           \n\t"
148.4572 -      "subl %%ecx, %%edx           \n\t" // subtract alignment fix
148.4573 -      "andl $0x00000007, %%edx     \n\t" // calc bytes over mult of 8
148.4574 -      "subl %%edx, %%eax           \n\t" // drop over bytes from length
148.4575 -      "movl %%eax, _MMXLength      \n\t"
148.4576 -
148.4577 -      : "=a" (dummy_value_a),   // 0      // output regs (dummy)
148.4578 -        "=D" (dummy_value_D)    // 1
148.4579 -
148.4580 -      : "0" (bpp),              // eax    // input regs
148.4581 -        "1" (row)               // edi
148.4582 -
148.4583 -      : "%esi", "%ecx", "%edx"            // clobber list
148.4584 -
148.4585 -#if 0  /* MMX regs (%mm0, etc.) not supported by gcc 2.7.2.3 or egcs 1.1 */
148.4586 -      , "%mm0", "%mm1", "%mm2", "%mm3"
148.4587 -      , "%mm4", "%mm5", "%mm6", "%mm7"
148.4588 -#endif
148.4589 -   );
148.4590 -
148.4591 -   // now do the math for the rest of the row
148.4592 -   switch (bpp)
148.4593 -   {
148.4594 -      case 3:
148.4595 -      {
148.4596 -         _ActiveMask.use  = 0x0000ffffff000000LL;
148.4597 -         _ShiftBpp.use = 24;       // == 3 * 8
148.4598 -         _ShiftRem.use  = 40;      // == 64 - 24
148.4599 -
148.4600 -         __asm__ __volatile__ (
148.4601 -// preload  "movl row, %%edi              \n\t"
148.4602 -            "movq _ActiveMask, %%mm7       \n\t" // load _ActiveMask for 2nd
148.4603 -                                                //  active byte group
148.4604 -            "movl %%edi, %%esi            \n\t" // lp = row
148.4605 -// preload  "movl bpp, %%eax              \n\t"
148.4606 -            "addl %%eax, %%edi            \n\t" // rp = row + bpp
148.4607 -            "movq %%mm7, %%mm6            \n\t"
148.4608 -            "movl _dif, %%edx             \n\t"
148.4609 -            "psllq _ShiftBpp, %%mm6       \n\t" // move mask in mm6 to cover
148.4610 -                                                //  3rd active byte group
148.4611 -            // prime the pump:  load the first Raw(x-bpp) data set
148.4612 -            "movq -8(%%edi,%%edx,), %%mm1 \n\t"
148.4613 -
148.4614 -         "sub_3lp:                        \n\t" // shift data for adding first
148.4615 -            "psrlq _ShiftRem, %%mm1       \n\t" //  bpp bytes (no need for mask;
148.4616 -                                                //  shift clears inactive bytes)
148.4617 -            // add 1st active group
148.4618 -            "movq (%%edi,%%edx,), %%mm0   \n\t"
148.4619 -            "paddb %%mm1, %%mm0           \n\t"
148.4620 -
148.4621 -            // add 2nd active group
148.4622 -            "movq %%mm0, %%mm1            \n\t" // mov updated Raws to mm1
148.4623 -            "psllq _ShiftBpp, %%mm1       \n\t" // shift data to pos. correctly
148.4624 -            "pand %%mm7, %%mm1            \n\t" // mask to use 2nd active group
148.4625 -            "paddb %%mm1, %%mm0           \n\t"
148.4626 -
148.4627 -            // add 3rd active group
148.4628 -            "movq %%mm0, %%mm1            \n\t" // mov updated Raws to mm1
148.4629 -            "psllq _ShiftBpp, %%mm1       \n\t" // shift data to pos. correctly
148.4630 -            "pand %%mm6, %%mm1            \n\t" // mask to use 3rd active group
148.4631 -            "addl $8, %%edx               \n\t"
148.4632 -            "paddb %%mm1, %%mm0           \n\t"
148.4633 -
148.4634 -            "cmpl _MMXLength, %%edx       \n\t"
148.4635 -            "movq %%mm0, -8(%%edi,%%edx,) \n\t" // write updated Raws to array
148.4636 -            "movq %%mm0, %%mm1            \n\t" // prep 1st add at top of loop
148.4637 -            "jb sub_3lp                   \n\t"
148.4638 -
148.4639 -            : "=a" (dummy_value_a),   // 0      // output regs (dummy)
148.4640 -              "=D" (dummy_value_D)    // 1
148.4641 -
148.4642 -            : "0" (bpp),              // eax    // input regs
148.4643 -              "1" (row)               // edi
148.4644 -
148.4645 -            : "%edx", "%esi"                    // clobber list
148.4646 -#if 0  /* MMX regs (%mm0, etc.) not supported by gcc 2.7.2.3 or egcs 1.1 */
148.4647 -            , "%mm0", "%mm1", "%mm6", "%mm7"
148.4648 -#endif
148.4649 -         );
148.4650 -      }
148.4651 -      break;
148.4652 -
148.4653 -      case 1:
148.4654 -      {
148.4655 -         __asm__ __volatile__ (
148.4656 -            "movl _dif, %%edx            \n\t"
148.4657 -// preload  "movl row, %%edi             \n\t"
148.4658 -            "cmpl _FullLength, %%edx     \n\t"
148.4659 -            "jnb sub_1end                \n\t"
148.4660 -            "movl %%edi, %%esi           \n\t" // lp = row
148.4661 -            "xorl %%eax, %%eax           \n\t"
148.4662 -// preload  "movl bpp, %%eax             \n\t"
148.4663 -            "addl %%eax, %%edi           \n\t" // rp = row + bpp
148.4664 -
148.4665 -         "sub_1lp:                       \n\t"
148.4666 -            "movb (%%esi,%%edx,), %%al   \n\t"
148.4667 -            "addb %%al, (%%edi,%%edx,)   \n\t"
148.4668 -            "incl %%edx                  \n\t"
148.4669 -            "cmpl _FullLength, %%edx     \n\t"
148.4670 -            "jb sub_1lp                  \n\t"
148.4671 -
148.4672 -         "sub_1end:                      \n\t"
148.4673 -
148.4674 -            : "=a" (dummy_value_a),   // 0      // output regs (dummy)
148.4675 -              "=D" (dummy_value_D)    // 1
148.4676 -
148.4677 -            : "0" (bpp),              // eax    // input regs
148.4678 -              "1" (row)               // edi
148.4679 -
148.4680 -            : "%edx", "%esi"                    // clobber list
148.4681 -         );
148.4682 -      }
148.4683 -      return;
148.4684 -
148.4685 -      case 6:
148.4686 -      case 4:
148.4687 -      //case 7:   // GRR BOGUS
148.4688 -      //case 5:   // GRR BOGUS
148.4689 -      {
148.4690 -         _ShiftBpp.use = bpp << 3;
148.4691 -         _ShiftRem.use = 64 - _ShiftBpp.use;
148.4692 -
148.4693 -         __asm__ __volatile__ (
148.4694 -// preload  "movl row, %%edi              \n\t"
148.4695 -            "movl _dif, %%edx             \n\t"
148.4696 -            "movl %%edi, %%esi            \n\t" // lp = row
148.4697 -// preload  "movl bpp, %%eax              \n\t"
148.4698 -            "addl %%eax, %%edi            \n\t" // rp = row + bpp
148.4699 -
148.4700 -            // prime the pump:  load the first Raw(x-bpp) data set
148.4701 -            "movq -8(%%edi,%%edx,), %%mm1 \n\t"
148.4702 -
148.4703 -         "sub_4lp:                        \n\t" // shift data for adding first
148.4704 -            "psrlq _ShiftRem, %%mm1       \n\t" //  bpp bytes (no need for mask;
148.4705 -                                                //  shift clears inactive bytes)
148.4706 -            "movq (%%edi,%%edx,), %%mm0   \n\t"
148.4707 -            "paddb %%mm1, %%mm0           \n\t"
148.4708 -
148.4709 -            // add 2nd active group
148.4710 -            "movq %%mm0, %%mm1            \n\t" // mov updated Raws to mm1
148.4711 -            "psllq _ShiftBpp, %%mm1       \n\t" // shift data to pos. correctly
148.4712 -            "addl $8, %%edx               \n\t"
148.4713 -            "paddb %%mm1, %%mm0           \n\t"
148.4714 -
148.4715 -            "cmpl _MMXLength, %%edx       \n\t"
148.4716 -            "movq %%mm0, -8(%%edi,%%edx,) \n\t"
148.4717 -            "movq %%mm0, %%mm1            \n\t" // prep 1st add at top of loop
148.4718 -            "jb sub_4lp                   \n\t"
148.4719 -
148.4720 -            : "=a" (dummy_value_a),   // 0      // output regs (dummy)
148.4721 -              "=D" (dummy_value_D)    // 1
148.4722 -
148.4723 -            : "0" (bpp),              // eax    // input regs
148.4724 -              "1" (row)               // edi
148.4725 -
148.4726 -            : "%edx", "%esi"                    // clobber list
148.4727 -#if 0  /* MMX regs (%mm0, etc.) not supported by gcc 2.7.2.3 or egcs 1.1 */
148.4728 -            , "%mm0", "%mm1"
148.4729 -#endif
148.4730 -         );
148.4731 -      }
148.4732 -      break;
148.4733 -
148.4734 -      case 2:
148.4735 -      {
148.4736 -         _ActiveMask.use = 0x00000000ffff0000LL;
148.4737 -         _ShiftBpp.use = 16;       // == 2 * 8
148.4738 -         _ShiftRem.use = 48;       // == 64 - 16
148.4739 -
148.4740 -         __asm__ __volatile__ (
148.4741 -            "movq _ActiveMask, %%mm7      \n\t" // load _ActiveMask for 2nd
148.4742 -                                                //  active byte group
148.4743 -            "movl _dif, %%edx             \n\t"
148.4744 -            "movq %%mm7, %%mm6            \n\t"
148.4745 -// preload  "movl row, %%edi              \n\t"
148.4746 -            "psllq _ShiftBpp, %%mm6       \n\t" // move mask in mm6 to cover
148.4747 -                                                //  3rd active byte group
148.4748 -            "movl %%edi, %%esi            \n\t" // lp = row
148.4749 -            "movq %%mm6, %%mm5            \n\t"
148.4750 -// preload  "movl bpp, %%eax              \n\t"
148.4751 -            "addl %%eax, %%edi            \n\t" // rp = row + bpp
148.4752 -            "psllq _ShiftBpp, %%mm5       \n\t" // move mask in mm5 to cover
148.4753 -                                                //  4th active byte group
148.4754 -            // prime the pump:  load the first Raw(x-bpp) data set
148.4755 -            "movq -8(%%edi,%%edx,), %%mm1 \n\t"
148.4756 -
148.4757 -         "sub_2lp:                        \n\t" // shift data for adding first
148.4758 -            "psrlq _ShiftRem, %%mm1       \n\t" //  bpp bytes (no need for mask;
148.4759 -                                                //  shift clears inactive bytes)
148.4760 -            // add 1st active group
148.4761 -            "movq (%%edi,%%edx,), %%mm0   \n\t"
148.4762 -            "paddb %%mm1, %%mm0           \n\t"
148.4763 -
148.4764 -            // add 2nd active group
148.4765 -            "movq %%mm0, %%mm1            \n\t" // mov updated Raws to mm1
148.4766 -            "psllq _ShiftBpp, %%mm1       \n\t" // shift data to pos. correctly
148.4767 -            "pand %%mm7, %%mm1            \n\t" // mask to use 2nd active group
148.4768 -            "paddb %%mm1, %%mm0           \n\t"
148.4769 -
148.4770 -            // add 3rd active group
148.4771 -            "movq %%mm0, %%mm1            \n\t" // mov updated Raws to mm1
148.4772 -            "psllq _ShiftBpp, %%mm1       \n\t" // shift data to pos. correctly
148.4773 -            "pand %%mm6, %%mm1            \n\t" // mask to use 3rd active group
148.4774 -            "paddb %%mm1, %%mm0           \n\t"
148.4775 -
148.4776 -            // add 4th active group
148.4777 -            "movq %%mm0, %%mm1            \n\t" // mov updated Raws to mm1
148.4778 -            "psllq _ShiftBpp, %%mm1       \n\t" // shift data to pos. correctly
148.4779 -            "pand %%mm5, %%mm1            \n\t" // mask to use 4th active group
148.4780 -            "addl $8, %%edx               \n\t"
148.4781 -            "paddb %%mm1, %%mm0           \n\t"
148.4782 -            "cmpl _MMXLength, %%edx       \n\t"
148.4783 -            "movq %%mm0, -8(%%edi,%%edx,) \n\t" // write updated Raws to array
148.4784 -            "movq %%mm0, %%mm1            \n\t" // prep 1st add at top of loop
148.4785 -            "jb sub_2lp                   \n\t"
148.4786 -
148.4787 -            : "=a" (dummy_value_a),   // 0      // output regs (dummy)
148.4788 -              "=D" (dummy_value_D)    // 1
148.4789 -
148.4790 -            : "0" (bpp),              // eax    // input regs
148.4791 -              "1" (row)               // edi
148.4792 -
148.4793 -            : "%edx", "%esi"                    // clobber list
148.4794 -#if 0  /* MMX regs (%mm0, etc.) not supported by gcc 2.7.2.3 or egcs 1.1 */
148.4795 -            , "%mm0", "%mm1", "%mm5", "%mm6", "%mm7"
148.4796 -#endif
148.4797 -         );
148.4798 -      }
148.4799 -      break;
148.4800 -
148.4801 -      case 8:
148.4802 -      {
148.4803 -         __asm__ __volatile__ (
148.4804 -// preload  "movl row, %%edi              \n\t"
148.4805 -            "movl _dif, %%edx             \n\t"
148.4806 -            "movl %%edi, %%esi            \n\t" // lp = row
148.4807 -// preload  "movl bpp, %%eax              \n\t"
148.4808 -            "addl %%eax, %%edi            \n\t" // rp = row + bpp
148.4809 -            "movl _MMXLength, %%ecx       \n\t"
148.4810 -
148.4811 -            // prime the pump:  load the first Raw(x-bpp) data set
148.4812 -            "movq -8(%%edi,%%edx,), %%mm7 \n\t"
148.4813 -            "andl $0x0000003f, %%ecx      \n\t" // calc bytes over mult of 64
148.4814 -
148.4815 -         "sub_8lp:                        \n\t"
148.4816 -            "movq (%%edi,%%edx,), %%mm0   \n\t" // load Sub(x) for 1st 8 bytes
148.4817 -            "paddb %%mm7, %%mm0           \n\t"
148.4818 -            "movq 8(%%edi,%%edx,), %%mm1  \n\t" // load Sub(x) for 2nd 8 bytes
148.4819 -            "movq %%mm0, (%%edi,%%edx,)   \n\t" // write Raw(x) for 1st 8 bytes
148.4820 -
148.4821 -            // Now mm0 will be used as Raw(x-bpp) for the 2nd group of 8 bytes.
148.4822 -            // This will be repeated for each group of 8 bytes with the 8th
148.4823 -            // group being used as the Raw(x-bpp) for the 1st group of the
148.4824 -            // next loop.
148.4825 -
148.4826 -            "paddb %%mm0, %%mm1           \n\t"
148.4827 -            "movq 16(%%edi,%%edx,), %%mm2 \n\t" // load Sub(x) for 3rd 8 bytes
148.4828 -            "movq %%mm1, 8(%%edi,%%edx,)  \n\t" // write Raw(x) for 2nd 8 bytes
148.4829 -            "paddb %%mm1, %%mm2           \n\t"
148.4830 -            "movq 24(%%edi,%%edx,), %%mm3 \n\t" // load Sub(x) for 4th 8 bytes
148.4831 -            "movq %%mm2, 16(%%edi,%%edx,) \n\t" // write Raw(x) for 3rd 8 bytes
148.4832 -            "paddb %%mm2, %%mm3           \n\t"
148.4833 -            "movq 32(%%edi,%%edx,), %%mm4 \n\t" // load Sub(x) for 5th 8 bytes
148.4834 -            "movq %%mm3, 24(%%edi,%%edx,) \n\t" // write Raw(x) for 4th 8 bytes
148.4835 -            "paddb %%mm3, %%mm4           \n\t"
148.4836 -            "movq 40(%%edi,%%edx,), %%mm5 \n\t" // load Sub(x) for 6th 8 bytes
148.4837 -            "movq %%mm4, 32(%%edi,%%edx,) \n\t" // write Raw(x) for 5th 8 bytes
148.4838 -            "paddb %%mm4, %%mm5           \n\t"
148.4839 -            "movq 48(%%edi,%%edx,), %%mm6 \n\t" // load Sub(x) for 7th 8 bytes
148.4840 -            "movq %%mm5, 40(%%edi,%%edx,) \n\t" // write Raw(x) for 6th 8 bytes
148.4841 -            "paddb %%mm5, %%mm6           \n\t"
148.4842 -            "movq 56(%%edi,%%edx,), %%mm7 \n\t" // load Sub(x) for 8th 8 bytes
148.4843 -            "movq %%mm6, 48(%%edi,%%edx,) \n\t" // write Raw(x) for 7th 8 bytes
148.4844 -            "addl $64, %%edx              \n\t"
148.4845 -            "paddb %%mm6, %%mm7           \n\t"
148.4846 -            "cmpl %%ecx, %%edx            \n\t"
148.4847 -            "movq %%mm7, -8(%%edi,%%edx,) \n\t" // write Raw(x) for 8th 8 bytes
148.4848 -            "jb sub_8lp                   \n\t"
148.4849 -
148.4850 -            "cmpl _MMXLength, %%edx       \n\t"
148.4851 -            "jnb sub_8lt8                 \n\t"
148.4852 -
148.4853 -         "sub_8lpA:                       \n\t"
148.4854 -            "movq (%%edi,%%edx,), %%mm0   \n\t"
148.4855 -            "addl $8, %%edx               \n\t"
148.4856 -            "paddb %%mm7, %%mm0           \n\t"
148.4857 -            "cmpl _MMXLength, %%edx       \n\t"
148.4858 -            "movq %%mm0, -8(%%edi,%%edx,) \n\t" // -8 to offset early addl edx
148.4859 -            "movq %%mm0, %%mm7            \n\t" // move calculated Raw(x) data
148.4860 -                                                //  to mm1 to be new Raw(x-bpp)
148.4861 -                                                //  for next loop
148.4862 -            "jb sub_8lpA                  \n\t"
148.4863 -
148.4864 -         "sub_8lt8:                       \n\t"
148.4865 -
148.4866 -            : "=a" (dummy_value_a),   // 0      // output regs (dummy)
148.4867 -              "=D" (dummy_value_D)    // 1
148.4868 -
148.4869 -            : "0" (bpp),              // eax    // input regs
148.4870 -              "1" (row)               // edi
148.4871 -
148.4872 -            : "%ecx", "%edx", "%esi"            // clobber list
148.4873 -#if 0  /* MMX regs (%mm0, etc.) not supported by gcc 2.7.2.3 or egcs 1.1 */
148.4874 -            , "%mm0", "%mm1", "%mm2", "%mm3", "%mm4", "%mm5", "%mm6", "%mm7"
148.4875 -#endif
148.4876 -         );
148.4877 -      }
148.4878 -      break;
148.4879 -
148.4880 -      default:                // bpp greater than 8 bytes   GRR BOGUS
148.4881 -      {
148.4882 -         __asm__ __volatile__ (
148.4883 -            "movl _dif, %%edx             \n\t"
148.4884 -// preload  "movl row, %%edi              \n\t"
148.4885 -            "movl %%edi, %%esi            \n\t" // lp = row
148.4886 -// preload  "movl bpp, %%eax              \n\t"
148.4887 -            "addl %%eax, %%edi            \n\t" // rp = row + bpp
148.4888 -
148.4889 -         "sub_Alp:                        \n\t"
148.4890 -            "movq (%%edi,%%edx,), %%mm0   \n\t"
148.4891 -            "movq (%%esi,%%edx,), %%mm1   \n\t"
148.4892 -            "addl $8, %%edx               \n\t"
148.4893 -            "paddb %%mm1, %%mm0           \n\t"
148.4894 -            "cmpl _MMXLength, %%edx       \n\t"
148.4895 -            "movq %%mm0, -8(%%edi,%%edx,) \n\t" // mov does not affect flags;
148.4896 -                                                //  -8 to offset addl edx
148.4897 -            "jb sub_Alp                   \n\t"
148.4898 -
148.4899 -            : "=a" (dummy_value_a),   // 0      // output regs (dummy)
148.4900 -              "=D" (dummy_value_D)    // 1
148.4901 -
148.4902 -            : "0" (bpp),              // eax    // input regs
148.4903 -              "1" (row)               // edi
148.4904 -
148.4905 -            : "%edx", "%esi"                    // clobber list
148.4906 -#if 0  /* MMX regs (%mm0, etc.) not supported by gcc 2.7.2.3 or egcs 1.1 */
148.4907 -            , "%mm0", "%mm1"
148.4908 -#endif
148.4909 -         );
148.4910 -      }
148.4911 -      break;
148.4912 -
148.4913 -   } // end switch (bpp)
148.4914 -
148.4915 -   __asm__ __volatile__ (
148.4916 -      "movl _MMXLength, %%edx       \n\t"
148.4917 -//pre "movl row, %%edi              \n\t"
148.4918 -      "cmpl _FullLength, %%edx      \n\t"
148.4919 -      "jnb sub_end                  \n\t"
148.4920 -
148.4921 -      "movl %%edi, %%esi            \n\t" // lp = row
148.4922 -//pre "movl bpp, %%eax              \n\t"
148.4923 -      "addl %%eax, %%edi            \n\t" // rp = row + bpp
148.4924 -      "xorl %%eax, %%eax            \n\t"
148.4925 -
148.4926 -   "sub_lp2:                        \n\t"
148.4927 -      "movb (%%esi,%%edx,), %%al    \n\t"
148.4928 -      "addb %%al, (%%edi,%%edx,)    \n\t"
148.4929 -      "incl %%edx                   \n\t"
148.4930 -      "cmpl _FullLength, %%edx      \n\t"
148.4931 -      "jb sub_lp2                   \n\t"
148.4932 -
148.4933 -   "sub_end:                        \n\t"
148.4934 -      "EMMS                         \n\t" // end MMX instructions
148.4935 -
148.4936 -      : "=a" (dummy_value_a),   // 0      // output regs (dummy)
148.4937 -        "=D" (dummy_value_D)    // 1
148.4938 -
148.4939 -      : "0" (bpp),              // eax    // input regs
148.4940 -        "1" (row)               // edi
148.4941 -
148.4942 -      : "%edx", "%esi"                    // clobber list
148.4943 -   );
148.4944 -
148.4945 -} // end of png_read_filter_row_mmx_sub()
148.4946 -#endif
148.4947 -
148.4948 -
148.4949 -
148.4950 -
148.4951 -//===========================================================================//
148.4952 -//                                                                           //
148.4953 -//            P N G _ R E A D _ F I L T E R _ R O W _ M M X _ U P            //
148.4954 -//                                                                           //
148.4955 -//===========================================================================//
148.4956 -
148.4957 -// Optimized code for PNG Up filter decoder
148.4958 -
148.4959 -static void /* PRIVATE */
148.4960 -png_read_filter_row_mmx_up(png_row_infop row_info, png_bytep row,
148.4961 -                           png_bytep prev_row)
148.4962 -{
148.4963 -   png_uint_32 len;
148.4964 -   int dummy_value_d;   // fix 'forbidden register 3 (dx) was spilled' error
148.4965 -   int dummy_value_S;
148.4966 -   int dummy_value_D;
148.4967 -
148.4968 -   len = row_info->rowbytes;              // number of bytes to filter
148.4969 -
148.4970 -   __asm__ __volatile__ (
148.4971 -//pre "movl row, %%edi              \n\t"
148.4972 -      // get # of bytes to alignment
148.4973 -#ifdef __PIC__
148.4974 -      "pushl %%ebx                  \n\t"
148.4975 -#endif
148.4976 -      "movl %%edi, %%ecx            \n\t"
148.4977 -      "xorl %%ebx, %%ebx            \n\t"
148.4978 -      "addl $0x7, %%ecx             \n\t"
148.4979 -      "xorl %%eax, %%eax            \n\t"
148.4980 -      "andl $0xfffffff8, %%ecx      \n\t"
148.4981 -//pre "movl prev_row, %%esi         \n\t"
148.4982 -      "subl %%edi, %%ecx            \n\t"
148.4983 -      "jz up_go                     \n\t"
148.4984 -
148.4985 -   "up_lp1:                         \n\t" // fix alignment
148.4986 -      "movb (%%edi,%%ebx,), %%al    \n\t"
148.4987 -      "addb (%%esi,%%ebx,), %%al    \n\t"
148.4988 -      "incl %%ebx                   \n\t"
148.4989 -      "cmpl %%ecx, %%ebx            \n\t"
148.4990 -      "movb %%al, -1(%%edi,%%ebx,)  \n\t" // mov does not affect flags; -1 to
148.4991 -      "jb up_lp1                    \n\t" //  offset incl ebx
148.4992 -
148.4993 -   "up_go:                          \n\t"
148.4994 -//pre "movl len, %%edx              \n\t"
148.4995 -      "movl %%edx, %%ecx            \n\t"
148.4996 -      "subl %%ebx, %%edx            \n\t" // subtract alignment fix
148.4997 -      "andl $0x0000003f, %%edx      \n\t" // calc bytes over mult of 64
148.4998 -      "subl %%edx, %%ecx            \n\t" // drop over bytes from length
148.4999 -
148.5000 -      // unrolled loop - use all MMX registers and interleave to reduce
148.5001 -      // number of branch instructions (loops) and reduce partial stalls
148.5002 -   "up_loop:                        \n\t"
148.5003 -      "movq (%%esi,%%ebx,), %%mm1   \n\t"
148.5004 -      "movq (%%edi,%%ebx,), %%mm0   \n\t"
148.5005 -      "movq 8(%%esi,%%ebx,), %%mm3  \n\t"
148.5006 -      "paddb %%mm1, %%mm0           \n\t"
148.5007 -      "movq 8(%%edi,%%ebx,), %%mm2  \n\t"
148.5008 -      "movq %%mm0, (%%edi,%%ebx,)   \n\t"
148.5009 -      "paddb %%mm3, %%mm2           \n\t"
148.5010 -      "movq 16(%%esi,%%ebx,), %%mm5 \n\t"
148.5011 -      "movq %%mm2, 8(%%edi,%%ebx,)  \n\t"
148.5012 -      "movq 16(%%edi,%%ebx,), %%mm4 \n\t"
148.5013 -      "movq 24(%%esi,%%ebx,), %%mm7 \n\t"
148.5014 -      "paddb %%mm5, %%mm4           \n\t"
148.5015 -      "movq 24(%%edi,%%ebx,), %%mm6 \n\t"
148.5016 -      "movq %%mm4, 16(%%edi,%%ebx,) \n\t"
148.5017 -      "paddb %%mm7, %%mm6           \n\t"
148.5018 -      "movq 32(%%esi,%%ebx,), %%mm1 \n\t"
148.5019 -      "movq %%mm6, 24(%%edi,%%ebx,) \n\t"
148.5020 -      "movq 32(%%edi,%%ebx,), %%mm0 \n\t"
148.5021 -      "movq 40(%%esi,%%ebx,), %%mm3 \n\t"
148.5022 -      "paddb %%mm1, %%mm0           \n\t"
148.5023 -      "movq 40(%%edi,%%ebx,), %%mm2 \n\t"
148.5024 -      "movq %%mm0, 32(%%edi,%%ebx,) \n\t"
148.5025 -      "paddb %%mm3, %%mm2           \n\t"
148.5026 -      "movq 48(%%esi,%%ebx,), %%mm5 \n\t"
148.5027 -      "movq %%mm2, 40(%%edi,%%ebx,) \n\t"
148.5028 -      "movq 48(%%edi,%%ebx,), %%mm4 \n\t"
148.5029 -      "movq 56(%%esi,%%ebx,), %%mm7 \n\t"
148.5030 -      "paddb %%mm5, %%mm4           \n\t"
148.5031 -      "movq 56(%%edi,%%ebx,), %%mm6 \n\t"
148.5032 -      "movq %%mm4, 48(%%edi,%%ebx,) \n\t"
148.5033 -      "addl $64, %%ebx              \n\t"
148.5034 -      "paddb %%mm7, %%mm6           \n\t"
148.5035 -      "cmpl %%ecx, %%ebx            \n\t"
148.5036 -      "movq %%mm6, -8(%%edi,%%ebx,) \n\t" // (+56)movq does not affect flags;
148.5037 -      "jb up_loop                   \n\t" //  -8 to offset addl ebx
148.5038 -
148.5039 -      "cmpl $0, %%edx               \n\t" // test for bytes over mult of 64
148.5040 -      "jz up_end                    \n\t"
148.5041 -
148.5042 -      "cmpl $8, %%edx               \n\t" // test for less than 8 bytes
148.5043 -      "jb up_lt8                    \n\t" //  [added by lcreeve at netins.net]
148.5044 -
148.5045 -      "addl %%edx, %%ecx            \n\t"
148.5046 -      "andl $0x00000007, %%edx      \n\t" // calc bytes over mult of 8
148.5047 -      "subl %%edx, %%ecx            \n\t" // drop over bytes from length
148.5048 -      "jz up_lt8                    \n\t"
148.5049 -
148.5050 -   "up_lpA:                         \n\t" // use MMX regs to update 8 bytes sim.
148.5051 -      "movq (%%esi,%%ebx,), %%mm1   \n\t"
148.5052 -      "movq (%%edi,%%ebx,), %%mm0   \n\t"
148.5053 -      "addl $8, %%ebx               \n\t"
148.5054 -      "paddb %%mm1, %%mm0           \n\t"
148.5055 -      "cmpl %%ecx, %%ebx            \n\t"
148.5056 -      "movq %%mm0, -8(%%edi,%%ebx,) \n\t" // movq does not affect flags; -8 to
148.5057 -      "jb up_lpA                    \n\t" //  offset add ebx
148.5058 -      "cmpl $0, %%edx               \n\t" // test for bytes over mult of 8
148.5059 -      "jz up_end                    \n\t"
148.5060 -
148.5061 -   "up_lt8:                         \n\t"
148.5062 -      "xorl %%eax, %%eax            \n\t"
148.5063 -      "addl %%edx, %%ecx            \n\t" // move over byte count into counter
148.5064 -
148.5065 -   "up_lp2:                         \n\t" // use x86 regs for remaining bytes
148.5066 -      "movb (%%edi,%%ebx,), %%al    \n\t"
148.5067 -      "addb (%%esi,%%ebx,), %%al    \n\t"
148.5068 -      "incl %%ebx                   \n\t"
148.5069 -      "cmpl %%ecx, %%ebx            \n\t"
148.5070 -      "movb %%al, -1(%%edi,%%ebx,)  \n\t" // mov does not affect flags; -1 to
148.5071 -      "jb up_lp2                    \n\t" //  offset inc ebx
148.5072 -
148.5073 -   "up_end:                         \n\t"
148.5074 -      "EMMS                         \n\t" // conversion of filtered row complete
148.5075 -#ifdef __PIC__
148.5076 -      "popl %%ebx                   \n\t"
148.5077 -#endif
148.5078 -
148.5079 -      : "=d" (dummy_value_d),   // 0      // output regs (dummy)
148.5080 -        "=S" (dummy_value_S),   // 1
148.5081 -        "=D" (dummy_value_D)    // 2
148.5082 -
148.5083 -      : "0" (len),              // edx    // input regs
148.5084 -        "1" (prev_row),         // esi
148.5085 -        "2" (row)               // edi
148.5086 -
148.5087 -      : "%eax", "%ecx"            // clobber list (no input regs!)
148.5088 -#ifndef __PIC__
148.5089 -      , "%ebx"
148.5090 -#endif
148.5091 -
148.5092 -#if 0  /* MMX regs (%mm0, etc.) not supported by gcc 2.7.2.3 or egcs 1.1 */
148.5093 -      , "%mm0", "%mm1", "%mm2", "%mm3"
148.5094 -      , "%mm4", "%mm5", "%mm6", "%mm7"
148.5095 -#endif
148.5096 -   );
148.5097 -
148.5098 -} // end of png_read_filter_row_mmx_up()
148.5099 -
148.5100 -#endif /* PNG_MMX_CODE_SUPPORTED */
148.5101 -
148.5102 -
148.5103 -
148.5104 -
148.5105 -/*===========================================================================*/
148.5106 -/*                                                                           */
148.5107 -/*                   P N G _ R E A D _ F I L T E R _ R O W                   */
148.5108 -/*                                                                           */
148.5109 -/*===========================================================================*/
148.5110 -
148.5111 -
148.5112 -/* Optimized png_read_filter_row routines */
148.5113 -
148.5114 -void /* PRIVATE */
148.5115 -png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep
148.5116 -   row, png_bytep prev_row, int filter)
148.5117 -{
148.5118 -#ifdef PNG_DEBUG
148.5119 -   char filnm[10];
148.5120 -#endif
148.5121 -
148.5122 -#if defined(PNG_MMX_CODE_SUPPORTED)
148.5123 -/* GRR:  these are superseded by png_ptr->asm_flags: */
148.5124 -#define UseMMX_sub    1   // GRR:  converted 20000730
148.5125 -#define UseMMX_up     1   // GRR:  converted 20000729
148.5126 -#define UseMMX_avg    1   // GRR:  converted 20000828 (+ 16-bit bugfix 20000916)
148.5127 -#define UseMMX_paeth  1   // GRR:  converted 20000828
148.5128 -
148.5129 -   if (_mmx_supported == 2) {
148.5130 -       /* this should have happened in png_init_mmx_flags() already */
148.5131 -#if !defined(PNG_1_0_X)
148.5132 -       png_warning(png_ptr, "asm_flags may not have been initialized");
148.5133 -#endif
148.5134 -       png_mmx_support();
148.5135 -   }
148.5136 -#endif /* PNG_MMX_CODE_SUPPORTED */
148.5137 -
148.5138 -#ifdef PNG_DEBUG
148.5139 -   png_debug(1, "in png_read_filter_row (pnggccrd.c)\n");
148.5140 -   switch (filter)
148.5141 -   {
148.5142 -      case 0: sprintf(filnm, "none");
148.5143 -         break;
148.5144 -      case 1: sprintf(filnm, "sub-%s",
148.5145 -#if defined(PNG_MMX_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK)
148.5146 -#if !defined(PNG_1_0_X)
148.5147 -        (png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_SUB)? "MMX" :
148.5148 -#endif
148.5149 -#endif
148.5150 -"x86");
148.5151 -         break;
148.5152 -      case 2: sprintf(filnm, "up-%s",
148.5153 -#ifdef PNG_MMX_CODE_SUPPORTED
148.5154 -#if !defined(PNG_1_0_X)
148.5155 -        (png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_UP)? "MMX" :
148.5156 -#endif
148.5157 -#endif
148.5158 - "x86");
148.5159 -         break;
148.5160 -      case 3: sprintf(filnm, "avg-%s",
148.5161 -#if defined(PNG_MMX_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK)
148.5162 -#if !defined(PNG_1_0_X)
148.5163 -        (png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_AVG)? "MMX" :
148.5164 -#endif
148.5165 -#endif
148.5166 - "x86");
148.5167 -         break;
148.5168 -      case 4: sprintf(filnm, "Paeth-%s",
148.5169 -#if defined(PNG_MMX_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK)
148.5170 -#if !defined(PNG_1_0_X)
148.5171 -        (png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_PAETH)? "MMX":
148.5172 -#endif
148.5173 -#endif
148.5174 -"x86");
148.5175 -         break;
148.5176 -      default: sprintf(filnm, "unknw");
148.5177 -         break;
148.5178 -   }
148.5179 -   png_debug2(0, "row_number=%5ld, %5s, ", png_ptr->row_number, filnm);
148.5180 -   png_debug1(0, "row=0x%08lx, ", (unsigned long)row);
148.5181 -   png_debug2(0, "pixdepth=%2d, bytes=%d, ", (int)row_info->pixel_depth,
148.5182 -      (int)((row_info->pixel_depth + 7) >> 3));
148.5183 -   png_debug1(0,"rowbytes=%8ld\n", row_info->rowbytes);
148.5184 -#endif /* PNG_DEBUG */
148.5185 -
148.5186 -   switch (filter)
148.5187 -   {
148.5188 -      case PNG_FILTER_VALUE_NONE:
148.5189 -         break;
148.5190 -
148.5191 -      case PNG_FILTER_VALUE_SUB:
148.5192 -#if defined(PNG_MMX_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK)
148.5193 -#if !defined(PNG_1_0_X)
148.5194 -         if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_SUB) &&
148.5195 -             (row_info->pixel_depth >= png_ptr->mmx_bitdepth_threshold) &&
148.5196 -             (row_info->rowbytes >= png_ptr->mmx_rowbytes_threshold))
148.5197 -#else
148.5198 -         if (_mmx_supported)
148.5199 -#endif
148.5200 -         {
148.5201 -            png_read_filter_row_mmx_sub(row_info, row);
148.5202 -         }
148.5203 -         else
148.5204 -#endif /* PNG_MMX_CODE_SUPPORTED */
148.5205 -         {
148.5206 -            png_uint_32 i;
148.5207 -            png_uint_32 istop = row_info->rowbytes;
148.5208 -            png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
148.5209 -            png_bytep rp = row + bpp;
148.5210 -            png_bytep lp = row;
148.5211 -
148.5212 -            for (i = bpp; i < istop; i++)
148.5213 -            {
148.5214 -               *rp = (png_byte)(((int)(*rp) + (int)(*lp++)) & 0xff);
148.5215 -               rp++;
148.5216 -            }
148.5217 -         }  /* end !UseMMX_sub */
148.5218 -         break;
148.5219 -
148.5220 -      case PNG_FILTER_VALUE_UP:
148.5221 -#if defined(PNG_MMX_CODE_SUPPORTED)
148.5222 -#if !defined(PNG_1_0_X)
148.5223 -         if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_UP) &&
148.5224 -             (row_info->pixel_depth >= png_ptr->mmx_bitdepth_threshold) &&
148.5225 -             (row_info->rowbytes >= png_ptr->mmx_rowbytes_threshold))
148.5226 -#else
148.5227 -         if (_mmx_supported)
148.5228 -#endif
148.5229 -         {
148.5230 -            png_read_filter_row_mmx_up(row_info, row, prev_row);
148.5231 -         }
148.5232 -          else
148.5233 -#endif /* PNG_MMX_CODE_SUPPORTED */
148.5234 -         {
148.5235 -            png_uint_32 i;
148.5236 -            png_uint_32 istop = row_info->rowbytes;
148.5237 -            png_bytep rp = row;
148.5238 -            png_bytep pp = prev_row;
148.5239 -
148.5240 -            for (i = 0; i < istop; ++i)
148.5241 -            {
148.5242 -               *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
148.5243 -               rp++;
148.5244 -            }
148.5245 -         }  /* end !UseMMX_up */
148.5246 -         break;
148.5247 -
148.5248 -      case PNG_FILTER_VALUE_AVG:
148.5249 -#if defined(PNG_MMX_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK)
148.5250 -#if !defined(PNG_1_0_X)
148.5251 -         if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_AVG) &&
148.5252 -             (row_info->pixel_depth >= png_ptr->mmx_bitdepth_threshold) &&
148.5253 -             (row_info->rowbytes >= png_ptr->mmx_rowbytes_threshold))
148.5254 -#else
148.5255 -         if (_mmx_supported)
148.5256 -#endif
148.5257 -         {
148.5258 -            png_read_filter_row_mmx_avg(row_info, row, prev_row);
148.5259 -         }
148.5260 -         else
148.5261 -#endif /* PNG_MMX_CODE_SUPPORTED */
148.5262 -         {
148.5263 -            png_uint_32 i;
148.5264 -            png_bytep rp = row;
148.5265 -            png_bytep pp = prev_row;
148.5266 -            png_bytep lp = row;
148.5267 -            png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
148.5268 -            png_uint_32 istop = row_info->rowbytes - bpp;
148.5269 -
148.5270 -            for (i = 0; i < bpp; i++)
148.5271 -            {
148.5272 -               *rp = (png_byte)(((int)(*rp) +
148.5273 -                  ((int)(*pp++) >> 1)) & 0xff);
148.5274 -               rp++;
148.5275 -            }
148.5276 -
148.5277 -            for (i = 0; i < istop; i++)
148.5278 -            {
148.5279 -               *rp = (png_byte)(((int)(*rp) +
148.5280 -                  ((int)(*pp++ + *lp++) >> 1)) & 0xff);
148.5281 -               rp++;
148.5282 -            }
148.5283 -         }  /* end !UseMMX_avg */
148.5284 -         break;
148.5285 -
148.5286 -      case PNG_FILTER_VALUE_PAETH:
148.5287 -#if defined(PNG_MMX_CODE_SUPPORTED) && defined(PNG_THREAD_UNSAFE_OK)
148.5288 -#if !defined(PNG_1_0_X)
148.5289 -         if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_PAETH) &&
148.5290 -             (row_info->pixel_depth >= png_ptr->mmx_bitdepth_threshold) &&
148.5291 -             (row_info->rowbytes >= png_ptr->mmx_rowbytes_threshold))
148.5292 -#else
148.5293 -         if (_mmx_supported)
148.5294 -#endif
148.5295 -         {
148.5296 -            png_read_filter_row_mmx_paeth(row_info, row, prev_row);
148.5297 -         }
148.5298 -         else
148.5299 -#endif /* PNG_MMX_CODE_SUPPORTED */
148.5300 -         {
148.5301 -            png_uint_32 i;
148.5302 -            png_bytep rp = row;
148.5303 -            png_bytep pp = prev_row;
148.5304 -            png_bytep lp = row;
148.5305 -            png_bytep cp = prev_row;
148.5306 -            png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
148.5307 -            png_uint_32 istop = row_info->rowbytes - bpp;
148.5308 -
148.5309 -            for (i = 0; i < bpp; i++)
148.5310 -            {
148.5311 -               *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
148.5312 -               rp++;
148.5313 -            }
148.5314 -
148.5315 -            for (i = 0; i < istop; i++)   /* use leftover rp,pp */
148.5316 -            {
148.5317 -               int a, b, c, pa, pb, pc, p;
148.5318 -
148.5319 -               a = *lp++;
148.5320 -               b = *pp++;
148.5321 -               c = *cp++;
148.5322 -
148.5323 -               p = b - c;
148.5324 -               pc = a - c;
148.5325 -
148.5326 -#ifdef PNG_USE_ABS
148.5327 -               pa = abs(p);
148.5328 -               pb = abs(pc);
148.5329 -               pc = abs(p + pc);
148.5330 -#else
148.5331 -               pa = p < 0 ? -p : p;
148.5332 -               pb = pc < 0 ? -pc : pc;
148.5333 -               pc = (p + pc) < 0 ? -(p + pc) : p + pc;
148.5334 -#endif
148.5335 -
148.5336 -               /*
148.5337 -                  if (pa <= pb && pa <= pc)
148.5338 -                     p = a;
148.5339 -                  else if (pb <= pc)
148.5340 -                     p = b;
148.5341 -                  else
148.5342 -                     p = c;
148.5343 -                */
148.5344 -
148.5345 -               p = (pa <= pb && pa <= pc) ? a : (pb <= pc) ? b : c;
148.5346 -
148.5347 -               *rp = (png_byte)(((int)(*rp) + p) & 0xff);
148.5348 -               rp++;
148.5349 -            }
148.5350 -         }  /* end !UseMMX_paeth */
148.5351 -         break;
148.5352 -
148.5353 -      default:
148.5354 -         png_warning(png_ptr, "Ignoring bad row-filter type");
148.5355 -         *row=0;
148.5356 -         break;
148.5357 -   }
148.5358 -}
148.5359 -
148.5360 -#endif /* PNG_HAVE_MMX_READ_FILTER_ROW */
148.5361 -
148.5362 -
148.5363 -/*===========================================================================*/
148.5364 -/*                                                                           */
148.5365 -/*                      P N G _ M M X _ S U P P O R T                        */
148.5366 -/*                                                                           */
148.5367 -/*===========================================================================*/
148.5368 -
148.5369 -/* GRR NOTES:  (1) the following code assumes 386 or better (pushfl/popfl)
148.5370 - *             (2) all instructions compile with gcc 2.7.2.3 and later
148.5371 - *             (3) the function is moved down here to prevent gcc from
148.5372 - *                  inlining it in multiple places and then barfing be-
148.5373 - *                  cause the ".NOT_SUPPORTED" label is multiply defined
148.5374 - *             [is there a way to signal that a *single* function should
148.5375 - *              not be inlined?  is there a way to modify the label for
148.5376 - *              each inlined instance, e.g., by appending _1, _2, etc.?
148.5377 - *              maybe if don't use leading "." in label name? (nope...sigh)]
148.5378 - */
148.5379 -
148.5380 -int PNGAPI
148.5381 -png_mmx_support(void)
148.5382 -{
148.5383 -#if defined(PNG_MMX_CODE_SUPPORTED)
148.5384 -    int result;
148.5385 -    __asm__ __volatile__ (
148.5386 -        "pushl %%ebx          \n\t"  // ebx gets clobbered by CPUID instruction
148.5387 -        "pushl %%ecx          \n\t"  // so does ecx...
148.5388 -        "pushl %%edx          \n\t"  // ...and edx (but ecx & edx safe on Linux)
148.5389 -//      ".byte  0x66          \n\t"  // convert 16-bit pushf to 32-bit pushfd
148.5390 -//      "pushf                \n\t"  // 16-bit pushf
148.5391 -        "pushfl               \n\t"  // save Eflag to stack
148.5392 -        "popl %%eax           \n\t"  // get Eflag from stack into eax
148.5393 -        "movl %%eax, %%ecx    \n\t"  // make another copy of Eflag in ecx
148.5394 -        "xorl $0x200000, %%eax \n\t" // toggle ID bit in Eflag (i.e., bit 21)
148.5395 -        "pushl %%eax          \n\t"  // save modified Eflag back to stack
148.5396 -//      ".byte  0x66          \n\t"  // convert 16-bit popf to 32-bit popfd
148.5397 -//      "popf                 \n\t"  // 16-bit popf
148.5398 -        "popfl                \n\t"  // restore modified value to Eflag reg
148.5399 -        "pushfl               \n\t"  // save Eflag to stack
148.5400 -        "popl %%eax           \n\t"  // get Eflag from stack
148.5401 -        "pushl %%ecx          \n\t"  // save original Eflag to stack
148.5402 -        "popfl                \n\t"  // restore original Eflag
148.5403 -        "xorl %%ecx, %%eax    \n\t"  // compare new Eflag with original Eflag
148.5404 -        "jz 0f                \n\t"  // if same, CPUID instr. is not supported
148.5405 -
148.5406 -        "xorl %%eax, %%eax    \n\t"  // set eax to zero
148.5407 -//      ".byte  0x0f, 0xa2    \n\t"  // CPUID instruction (two-byte opcode)
148.5408 -        "cpuid                \n\t"  // get the CPU identification info
148.5409 -        "cmpl $1, %%eax       \n\t"  // make sure eax return non-zero value
148.5410 -        "jl 0f                \n\t"  // if eax is zero, MMX is not supported
148.5411 -
148.5412 -        "xorl %%eax, %%eax    \n\t"  // set eax to zero and...
148.5413 -        "incl %%eax           \n\t"  // ...increment eax to 1.  This pair is
148.5414 -                                     // faster than the instruction "mov eax, 1"
148.5415 -        "cpuid                \n\t"  // get the CPU identification info again
148.5416 -        "andl $0x800000, %%edx \n\t" // mask out all bits but MMX bit (23)
148.5417 -        "cmpl $0, %%edx       \n\t"  // 0 = MMX not supported
148.5418 -        "jz 0f                \n\t"  // non-zero = yes, MMX IS supported
148.5419 -
148.5420 -        "movl $1, %%eax       \n\t"  // set return value to 1
148.5421 -        "jmp  1f              \n\t"  // DONE:  have MMX support
148.5422 -
148.5423 -    "0:                       \n\t"  // .NOT_SUPPORTED: target label for jump instructions
148.5424 -        "movl $0, %%eax       \n\t"  // set return value to 0
148.5425 -    "1:                       \n\t"  // .RETURN: target label for jump instructions
148.5426 -        "popl %%edx           \n\t"  // restore edx
148.5427 -        "popl %%ecx           \n\t"  // restore ecx
148.5428 -        "popl %%ebx           \n\t"  // restore ebx
148.5429 -
148.5430 -//      "ret                  \n\t"  // DONE:  no MMX support
148.5431 -                                     // (fall through to standard C "ret")
148.5432 -
148.5433 -        : "=a" (result)              // output list
148.5434 -
148.5435 -        :                            // any variables used on input (none)
148.5436 -
148.5437 -                                     // no clobber list
148.5438 -//      , "%ebx", "%ecx", "%edx"     // GRR:  we handle these manually
148.5439 -//      , "memory"   // if write to a variable gcc thought was in a reg
148.5440 -//      , "cc"       // "condition codes" (flag bits)
148.5441 -    );
148.5442 -    _mmx_supported = result;
148.5443 -#else
148.5444 -    _mmx_supported = 0;
148.5445 -#endif /* PNG_MMX_CODE_SUPPORTED */
148.5446 -
148.5447 -    return _mmx_supported;
148.5448 -}
148.5449 -
148.5450 -
148.5451 -#endif /* PNG_USE_PNGGCCRD */
   149.1 --- a/src/share/native/sun/awt/libpng/pngget.c	Fri Sep 30 17:20:56 2011 -0700
   149.2 +++ b/src/share/native/sun/awt/libpng/pngget.c	Tue Oct 04 12:39:42 2011 -0700
   149.3 @@ -29,612 +29,712 @@
   149.4   * However, the following notice accompanied the original version of this
   149.5   * file and, per its terms, should not be removed:
   149.6   *
   149.7 - * Last changed in libpng 1.2.15 January 5, 2007
   149.8 - * For conditions of distribution and use, see copyright notice in png.h
   149.9 - * Copyright (c) 1998-2007 Glenn Randers-Pehrson
  149.10 + * Last changed in libpng 1.5.1 [February 3, 2011]
  149.11 + * Copyright (c) 1998-2011 Glenn Randers-Pehrson
  149.12   * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
  149.13   * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
  149.14 + *
  149.15 + * This code is released under the libpng license.
  149.16 + * For conditions of distribution and use, see the disclaimer
  149.17 + * and license in png.h
  149.18 + *
  149.19   */
  149.20  
  149.21 -#define PNG_INTERNAL
  149.22 -#include "png.h"
  149.23 +#include "pngpriv.h"
  149.24  
  149.25  #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  149.26  
  149.27  png_uint_32 PNGAPI
  149.28 -png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag)
  149.29 +png_get_valid(png_const_structp png_ptr, png_const_infop info_ptr,
  149.30 +    png_uint_32 flag)
  149.31  {
  149.32     if (png_ptr != NULL && info_ptr != NULL)
  149.33        return(info_ptr->valid & flag);
  149.34 -   else
  149.35 -      return(0);
  149.36 +
  149.37 +   return(0);
  149.38  }
  149.39  
  149.40 -png_uint_32 PNGAPI
  149.41 -png_get_rowbytes(png_structp png_ptr, png_infop info_ptr)
  149.42 +png_size_t PNGAPI
  149.43 +png_get_rowbytes(png_const_structp png_ptr, png_const_infop info_ptr)
  149.44  {
  149.45     if (png_ptr != NULL && info_ptr != NULL)
  149.46        return(info_ptr->rowbytes);
  149.47 -   else
  149.48 -      return(0);
  149.49 +
  149.50 +   return(0);
  149.51  }
  149.52  
  149.53 -#if defined(PNG_INFO_IMAGE_SUPPORTED)
  149.54 +#ifdef PNG_INFO_IMAGE_SUPPORTED
  149.55  png_bytepp PNGAPI
  149.56 -png_get_rows(png_structp png_ptr, png_infop info_ptr)
  149.57 +png_get_rows(png_const_structp png_ptr, png_const_infop info_ptr)
  149.58  {
  149.59     if (png_ptr != NULL && info_ptr != NULL)
  149.60        return(info_ptr->row_pointers);
  149.61 -   else
  149.62 -      return(0);
  149.63 +
  149.64 +   return(0);
  149.65  }
  149.66  #endif
  149.67  
  149.68  #ifdef PNG_EASY_ACCESS_SUPPORTED
  149.69 -/* easy access to info, added in libpng-0.99 */
  149.70 +/* Easy access to info, added in libpng-0.99 */
  149.71  png_uint_32 PNGAPI
  149.72 -png_get_image_width(png_structp png_ptr, png_infop info_ptr)
  149.73 +png_get_image_width(png_const_structp png_ptr, png_const_infop info_ptr)
  149.74  {
  149.75     if (png_ptr != NULL && info_ptr != NULL)
  149.76 -   {
  149.77        return info_ptr->width;
  149.78 -   }
  149.79 +
  149.80     return (0);
  149.81  }
  149.82  
  149.83  png_uint_32 PNGAPI
  149.84 -png_get_image_height(png_structp png_ptr, png_infop info_ptr)
  149.85 +png_get_image_height(png_const_structp png_ptr, png_const_infop info_ptr)
  149.86  {
  149.87     if (png_ptr != NULL && info_ptr != NULL)
  149.88 -   {
  149.89        return info_ptr->height;
  149.90 -   }
  149.91 +
  149.92     return (0);
  149.93  }
  149.94  
  149.95  png_byte PNGAPI
  149.96 -png_get_bit_depth(png_structp png_ptr, png_infop info_ptr)
  149.97 +png_get_bit_depth(png_const_structp png_ptr, png_const_infop info_ptr)
  149.98  {
  149.99     if (png_ptr != NULL && info_ptr != NULL)
 149.100 -   {
 149.101        return info_ptr->bit_depth;
 149.102 -   }
 149.103 +
 149.104     return (0);
 149.105  }
 149.106  
 149.107  png_byte PNGAPI
 149.108 -png_get_color_type(png_structp png_ptr, png_infop info_ptr)
 149.109 +png_get_color_type(png_const_structp png_ptr, png_const_infop info_ptr)
 149.110  {
 149.111     if (png_ptr != NULL && info_ptr != NULL)
 149.112 -   {
 149.113        return info_ptr->color_type;
 149.114 -   }
 149.115 +
 149.116     return (0);
 149.117  }
 149.118  
 149.119  png_byte PNGAPI
 149.120 -png_get_filter_type(png_structp png_ptr, png_infop info_ptr)
 149.121 +png_get_filter_type(png_const_structp png_ptr, png_const_infop info_ptr)
 149.122  {
 149.123     if (png_ptr != NULL && info_ptr != NULL)
 149.124 -   {
 149.125        return info_ptr->filter_type;
 149.126 -   }
 149.127 +
 149.128     return (0);
 149.129  }
 149.130  
 149.131  png_byte PNGAPI
 149.132 -png_get_interlace_type(png_structp png_ptr, png_infop info_ptr)
 149.133 +png_get_interlace_type(png_const_structp png_ptr, png_const_infop info_ptr)
 149.134  {
 149.135     if (png_ptr != NULL && info_ptr != NULL)
 149.136 -   {
 149.137        return info_ptr->interlace_type;
 149.138 -   }
 149.139 +
 149.140     return (0);
 149.141  }
 149.142  
 149.143  png_byte PNGAPI
 149.144 -png_get_compression_type(png_structp png_ptr, png_infop info_ptr)
 149.145 +png_get_compression_type(png_const_structp png_ptr, png_const_infop info_ptr)
 149.146  {
 149.147     if (png_ptr != NULL && info_ptr != NULL)
 149.148 -   {
 149.149        return info_ptr->compression_type;
 149.150 -   }
 149.151 +
 149.152     return (0);
 149.153  }
 149.154  
 149.155  png_uint_32 PNGAPI
 149.156 -png_get_x_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
 149.157 +png_get_x_pixels_per_meter(png_const_structp png_ptr, png_const_infop info_ptr)
 149.158  {
 149.159 -   if (png_ptr != NULL && info_ptr != NULL)
 149.160 -#if defined(PNG_pHYs_SUPPORTED)
 149.161 -   if (info_ptr->valid & PNG_INFO_pHYs)
 149.162 -   {
 149.163 -      png_debug1(1, "in %s retrieval function\n", "png_get_x_pixels_per_meter");
 149.164 -      if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
 149.165 -          return (0);
 149.166 -      else return (info_ptr->x_pixels_per_unit);
 149.167 -   }
 149.168 -#else
 149.169 -   return (0);
 149.170 +#ifdef PNG_pHYs_SUPPORTED
 149.171 +   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
 149.172 +      {
 149.173 +         png_debug1(1, "in %s retrieval function",
 149.174 +             "png_get_x_pixels_per_meter");
 149.175 +
 149.176 +         if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER)
 149.177 +            return (info_ptr->x_pixels_per_unit);
 149.178 +      }
 149.179  #endif
 149.180 +
 149.181     return (0);
 149.182  }
 149.183  
 149.184  png_uint_32 PNGAPI
 149.185 -png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
 149.186 +png_get_y_pixels_per_meter(png_const_structp png_ptr, png_const_infop info_ptr)
 149.187  {
 149.188 -   if (png_ptr != NULL && info_ptr != NULL)
 149.189 -#if defined(PNG_pHYs_SUPPORTED)
 149.190 -   if (info_ptr->valid & PNG_INFO_pHYs)
 149.191 +#ifdef PNG_pHYs_SUPPORTED
 149.192 +   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
 149.193     {
 149.194 -      png_debug1(1, "in %s retrieval function\n", "png_get_y_pixels_per_meter");
 149.195 -      if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
 149.196 -          return (0);
 149.197 -      else return (info_ptr->y_pixels_per_unit);
 149.198 +      png_debug1(1, "in %s retrieval function",
 149.199 +          "png_get_y_pixels_per_meter");
 149.200 +
 149.201 +      if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER)
 149.202 +         return (info_ptr->y_pixels_per_unit);
 149.203     }
 149.204 -#else
 149.205 -   return (0);
 149.206  #endif
 149.207 +
 149.208     return (0);
 149.209  }
 149.210  
 149.211  png_uint_32 PNGAPI
 149.212 -png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
 149.213 +png_get_pixels_per_meter(png_const_structp png_ptr, png_const_infop info_ptr)
 149.214  {
 149.215 -   if (png_ptr != NULL && info_ptr != NULL)
 149.216 -#if defined(PNG_pHYs_SUPPORTED)
 149.217 -   if (info_ptr->valid & PNG_INFO_pHYs)
 149.218 +#ifdef PNG_pHYs_SUPPORTED
 149.219 +   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
 149.220     {
 149.221 -      png_debug1(1, "in %s retrieval function\n", "png_get_pixels_per_meter");
 149.222 -      if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER ||
 149.223 -         info_ptr->x_pixels_per_unit != info_ptr->y_pixels_per_unit)
 149.224 -          return (0);
 149.225 -      else return (info_ptr->x_pixels_per_unit);
 149.226 +      png_debug1(1, "in %s retrieval function", "png_get_pixels_per_meter");
 149.227 +
 149.228 +      if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER &&
 149.229 +          info_ptr->x_pixels_per_unit == info_ptr->y_pixels_per_unit)
 149.230 +         return (info_ptr->x_pixels_per_unit);
 149.231     }
 149.232 -#else
 149.233 -   return (0);
 149.234  #endif
 149.235 +
 149.236     return (0);
 149.237  }
 149.238  
 149.239  #ifdef PNG_FLOATING_POINT_SUPPORTED
 149.240  float PNGAPI
 149.241 -png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr)
 149.242 +png_get_pixel_aspect_ratio(png_const_structp png_ptr, png_const_infop info_ptr)
 149.243 +{
 149.244 +#ifdef PNG_READ_pHYs_SUPPORTED
 149.245 +   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
 149.246     {
 149.247 -   if (png_ptr != NULL && info_ptr != NULL)
 149.248 -#if defined(PNG_pHYs_SUPPORTED)
 149.249 -   if (info_ptr->valid & PNG_INFO_pHYs)
 149.250 -   {
 149.251 -      png_debug1(1, "in %s retrieval function\n", "png_get_aspect_ratio");
 149.252 -      if (info_ptr->x_pixels_per_unit == 0)
 149.253 -         return ((float)0.0);
 149.254 -      else
 149.255 +      png_debug1(1, "in %s retrieval function", "png_get_aspect_ratio");
 149.256 +
 149.257 +      if (info_ptr->x_pixels_per_unit != 0)
 149.258           return ((float)((float)info_ptr->y_pixels_per_unit
 149.259 -            /(float)info_ptr->x_pixels_per_unit));
 149.260 +             /(float)info_ptr->x_pixels_per_unit));
 149.261     }
 149.262 -#else
 149.263 -   return (0.0);
 149.264  #endif
 149.265 +
 149.266     return ((float)0.0);
 149.267  }
 149.268  #endif
 149.269  
 149.270 +#ifdef PNG_FIXED_POINT_SUPPORTED
 149.271 +png_fixed_point PNGAPI
 149.272 +png_get_pixel_aspect_ratio_fixed(png_const_structp png_ptr,
 149.273 +    png_const_infop info_ptr)
 149.274 +{
 149.275 +#ifdef PNG_READ_pHYs_SUPPORTED
 149.276 +   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)
 149.277 +       && info_ptr->x_pixels_per_unit > 0 && info_ptr->y_pixels_per_unit > 0
 149.278 +       && info_ptr->x_pixels_per_unit <= PNG_UINT_31_MAX
 149.279 +       && info_ptr->y_pixels_per_unit <= PNG_UINT_31_MAX)
 149.280 +   {
 149.281 +      png_fixed_point res;
 149.282 +
 149.283 +      png_debug1(1, "in %s retrieval function", "png_get_aspect_ratio_fixed");
 149.284 +
 149.285 +      /* The following casts work because a PNG 4 byte integer only has a valid
 149.286 +       * range of 0..2^31-1; otherwise the cast might overflow.
 149.287 +       */
 149.288 +      if (png_muldiv(&res, (png_int_32)info_ptr->y_pixels_per_unit, PNG_FP_1,
 149.289 +          (png_int_32)info_ptr->x_pixels_per_unit))
 149.290 +         return res;
 149.291 +   }
 149.292 +#endif
 149.293 +
 149.294 +   return 0;
 149.295 +}
 149.296 +#endif
 149.297 +
 149.298  png_int_32 PNGAPI
 149.299 -png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr)
 149.300 +png_get_x_offset_microns(png_const_structp png_ptr, png_const_infop info_ptr)
 149.301  {
 149.302 -   if (png_ptr != NULL && info_ptr != NULL)
 149.303 -#if defined(PNG_oFFs_SUPPORTED)
 149.304 -   if (info_ptr->valid & PNG_INFO_oFFs)
 149.305 +#ifdef PNG_oFFs_SUPPORTED
 149.306 +   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
 149.307     {
 149.308 -      png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
 149.309 -      if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
 149.310 -          return (0);
 149.311 -      else return (info_ptr->x_offset);
 149.312 +      png_debug1(1, "in %s retrieval function", "png_get_x_offset_microns");
 149.313 +
 149.314 +      if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER)
 149.315 +         return (info_ptr->x_offset);
 149.316     }
 149.317 -#else
 149.318 -   return (0);
 149.319  #endif
 149.320 +
 149.321     return (0);
 149.322  }
 149.323  
 149.324  png_int_32 PNGAPI
 149.325 -png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr)
 149.326 +png_get_y_offset_microns(png_const_structp png_ptr, png_const_infop info_ptr)
 149.327  {
 149.328 -   if (png_ptr != NULL && info_ptr != NULL)
 149.329 -#if defined(PNG_oFFs_SUPPORTED)
 149.330 -   if (info_ptr->valid & PNG_INFO_oFFs)
 149.331 +#ifdef PNG_oFFs_SUPPORTED
 149.332 +   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
 149.333     {
 149.334 -      png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
 149.335 -      if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
 149.336 -          return (0);
 149.337 -      else return (info_ptr->y_offset);
 149.338 +      png_debug1(1, "in %s retrieval function", "png_get_y_offset_microns");
 149.339 +
 149.340 +      if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER)
 149.341 +         return (info_ptr->y_offset);
 149.342     }
 149.343 -#else
 149.344 -   return (0);
 149.345  #endif
 149.346 +
 149.347     return (0);
 149.348  }
 149.349  
 149.350  png_int_32 PNGAPI
 149.351 -png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr)
 149.352 +png_get_x_offset_pixels(png_const_structp png_ptr, png_const_infop info_ptr)
 149.353  {
 149.354 -   if (png_ptr != NULL && info_ptr != NULL)
 149.355 -#if defined(PNG_oFFs_SUPPORTED)
 149.356 -   if (info_ptr->valid & PNG_INFO_oFFs)
 149.357 +#ifdef PNG_oFFs_SUPPORTED
 149.358 +   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
 149.359     {
 149.360 -      png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
 149.361 -      if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
 149.362 -          return (0);
 149.363 -      else return (info_ptr->x_offset);
 149.364 +      png_debug1(1, "in %s retrieval function", "png_get_x_offset_pixels");
 149.365 +
 149.366 +      if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL)
 149.367 +         return (info_ptr->x_offset);
 149.368     }
 149.369 -#else
 149.370 -   return (0);
 149.371  #endif
 149.372 +
 149.373     return (0);
 149.374  }
 149.375  
 149.376  png_int_32 PNGAPI
 149.377 -png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr)
 149.378 +png_get_y_offset_pixels(png_const_structp png_ptr, png_const_infop info_ptr)
 149.379  {
 149.380 -   if (png_ptr != NULL && info_ptr != NULL)
 149.381 -#if defined(PNG_oFFs_SUPPORTED)
 149.382 -   if (info_ptr->valid & PNG_INFO_oFFs)
 149.383 +#ifdef PNG_oFFs_SUPPORTED
 149.384 +   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
 149.385     {
 149.386 -      png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
 149.387 -      if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
 149.388 -          return (0);
 149.389 -      else return (info_ptr->y_offset);
 149.390 +      png_debug1(1, "in %s retrieval function", "png_get_y_offset_pixels");
 149.391 +
 149.392 +      if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL)
 149.393 +         return (info_ptr->y_offset);
 149.394     }
 149.395 -#else
 149.396 -   return (0);
 149.397  #endif
 149.398 +
 149.399     return (0);
 149.400  }
 149.401  
 149.402 -#if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
 149.403 -png_uint_32 PNGAPI
 149.404 -png_get_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
 149.405 +#ifdef PNG_INCH_CONVERSIONS_SUPPORTED
 149.406 +static png_uint_32
 149.407 +ppi_from_ppm(png_uint_32 ppm)
 149.408  {
 149.409 -   return ((png_uint_32)((float)png_get_pixels_per_meter(png_ptr, info_ptr)
 149.410 -     *.0254 +.5));
 149.411 +#if 0
 149.412 +   /* The conversion is *(2.54/100), in binary (32 digits):
 149.413 +    * .00000110100000001001110101001001
 149.414 +    */
 149.415 +   png_uint_32 t1001, t1101;
 149.416 +   ppm >>= 1;                  /* .1 */
 149.417 +   t1001 = ppm + (ppm >> 3);   /* .1001 */
 149.418 +   t1101 = t1001 + (ppm >> 1); /* .1101 */
 149.419 +   ppm >>= 20;                 /* .000000000000000000001 */
 149.420 +   t1101 += t1101 >> 15;       /* .1101000000000001101 */
 149.421 +   t1001 >>= 11;               /* .000000000001001 */
 149.422 +   t1001 += t1001 >> 12;       /* .000000000001001000000001001 */
 149.423 +   ppm += t1001;               /* .000000000001001000001001001 */
 149.424 +   ppm += t1101;               /* .110100000001001110101001001 */
 149.425 +   return (ppm + 16) >> 5;/* .00000110100000001001110101001001 */
 149.426 +#else
 149.427 +   /* The argument is a PNG unsigned integer, so it is not permitted
 149.428 +    * to be bigger than 2^31.
 149.429 +    */
 149.430 +   png_fixed_point result;
 149.431 +   if (ppm <= PNG_UINT_31_MAX && png_muldiv(&result, (png_int_32)ppm, 127,
 149.432 +       5000))
 149.433 +      return result;
 149.434 +
 149.435 +   /* Overflow. */
 149.436 +   return 0;
 149.437 +#endif
 149.438  }
 149.439  
 149.440  png_uint_32 PNGAPI
 149.441 -png_get_x_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
 149.442 +png_get_pixels_per_inch(png_const_structp png_ptr, png_const_infop info_ptr)
 149.443  {
 149.444 -   return ((png_uint_32)((float)png_get_x_pixels_per_meter(png_ptr, info_ptr)
 149.445 -     *.0254 +.5));
 149.446 +   return ppi_from_ppm(png_get_pixels_per_meter(png_ptr, info_ptr));
 149.447  }
 149.448  
 149.449  png_uint_32 PNGAPI
 149.450 -png_get_y_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
 149.451 +png_get_x_pixels_per_inch(png_const_structp png_ptr, png_const_infop info_ptr)
 149.452  {
 149.453 -   return ((png_uint_32)((float)png_get_y_pixels_per_meter(png_ptr, info_ptr)
 149.454 -     *.0254 +.5));
 149.455 +   return ppi_from_ppm(png_get_x_pixels_per_meter(png_ptr, info_ptr));
 149.456  }
 149.457  
 149.458 -float PNGAPI
 149.459 -png_get_x_offset_inches(png_structp png_ptr, png_infop info_ptr)
 149.460 +png_uint_32 PNGAPI
 149.461 +png_get_y_pixels_per_inch(png_const_structp png_ptr, png_const_infop info_ptr)
 149.462  {
 149.463 -   return ((float)png_get_x_offset_microns(png_ptr, info_ptr)
 149.464 -     *.00003937);
 149.465 +   return ppi_from_ppm(png_get_y_pixels_per_meter(png_ptr, info_ptr));
 149.466  }
 149.467  
 149.468 -float PNGAPI
 149.469 -png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr)
 149.470 +#ifdef PNG_FIXED_POINT_SUPPORTED
 149.471 +static png_fixed_point
 149.472 +png_fixed_inches_from_microns(png_structp png_ptr, png_int_32 microns)
 149.473  {
 149.474 -   return ((float)png_get_y_offset_microns(png_ptr, info_ptr)
 149.475 -     *.00003937);
 149.476 +   /* Convert from metres * 1,000,000 to inches * 100,000, meters to
 149.477 +    * inches is simply *(100/2.54), so we want *(10/2.54) == 500/127.
 149.478 +    * Notice that this can overflow - a warning is output and 0 is
 149.479 +    * returned.
 149.480 +    */
 149.481 +   return png_muldiv_warn(png_ptr, microns, 500, 127);
 149.482  }
 149.483  
 149.484 -#if defined(PNG_pHYs_SUPPORTED)
 149.485 +png_fixed_point PNGAPI
 149.486 +png_get_x_offset_inches_fixed(png_structp png_ptr,
 149.487 +    png_const_infop info_ptr)
 149.488 +{
 149.489 +   return png_fixed_inches_from_microns(png_ptr,
 149.490 +       png_get_x_offset_microns(png_ptr, info_ptr));
 149.491 +}
 149.492 +#endif
 149.493 +
 149.494 +#ifdef PNG_FIXED_POINT_SUPPORTED
 149.495 +png_fixed_point PNGAPI
 149.496 +png_get_y_offset_inches_fixed(png_structp png_ptr,
 149.497 +    png_const_infop info_ptr)
 149.498 +{
 149.499 +   return png_fixed_inches_from_microns(png_ptr,
 149.500 +       png_get_y_offset_microns(png_ptr, info_ptr));
 149.501 +}
 149.502 +#endif
 149.503 +
 149.504 +#ifdef PNG_FLOATING_POINT_SUPPORTED
 149.505 +float PNGAPI
 149.506 +png_get_x_offset_inches(png_const_structp png_ptr, png_const_infop info_ptr)
 149.507 +{
 149.508 +   /* To avoid the overflow do the conversion directly in floating
 149.509 +    * point.
 149.510 +    */
 149.511 +   return (float)(png_get_x_offset_microns(png_ptr, info_ptr) * .00003937);
 149.512 +}
 149.513 +#endif
 149.514 +
 149.515 +#ifdef PNG_FLOATING_POINT_SUPPORTED
 149.516 +float PNGAPI
 149.517 +png_get_y_offset_inches(png_const_structp png_ptr, png_const_infop info_ptr)
 149.518 +{
 149.519 +   /* To avoid the overflow do the conversion directly in floating
 149.520 +    * point.
 149.521 +    */
 149.522 +   return (float)(png_get_y_offset_microns(png_ptr, info_ptr) * .00003937);
 149.523 +}
 149.524 +#endif
 149.525 +
 149.526 +#ifdef PNG_pHYs_SUPPORTED
 149.527  png_uint_32 PNGAPI
 149.528 -png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr,
 149.529 -   png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
 149.530 +png_get_pHYs_dpi(png_const_structp png_ptr, png_const_infop info_ptr,
 149.531 +    png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
 149.532  {
 149.533     png_uint_32 retval = 0;
 149.534  
 149.535     if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
 149.536     {
 149.537 -      png_debug1(1, "in %s retrieval function\n", "pHYs");
 149.538 +      png_debug1(1, "in %s retrieval function", "pHYs");
 149.539 +
 149.540        if (res_x != NULL)
 149.541        {
 149.542           *res_x = info_ptr->x_pixels_per_unit;
 149.543           retval |= PNG_INFO_pHYs;
 149.544        }
 149.545 +
 149.546        if (res_y != NULL)
 149.547        {
 149.548           *res_y = info_ptr->y_pixels_per_unit;
 149.549           retval |= PNG_INFO_pHYs;
 149.550        }
 149.551 +
 149.552        if (unit_type != NULL)
 149.553        {
 149.554           *unit_type = (int)info_ptr->phys_unit_type;
 149.555           retval |= PNG_INFO_pHYs;
 149.556 -         if(*unit_type == 1)
 149.557 +
 149.558 +         if (*unit_type == 1)
 149.559           {
 149.560              if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50);
 149.561              if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50);
 149.562           }
 149.563        }
 149.564     }
 149.565 +
 149.566     return (retval);
 149.567  }
 149.568  #endif /* PNG_pHYs_SUPPORTED */
 149.569 -#endif  /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
 149.570 +#endif  /* PNG_INCH_CONVERSIONS_SUPPORTED */
 149.571  
 149.572  /* png_get_channels really belongs in here, too, but it's been around longer */
 149.573  
 149.574  #endif  /* PNG_EASY_ACCESS_SUPPORTED */
 149.575  
 149.576  png_byte PNGAPI
 149.577 -png_get_channels(png_structp png_ptr, png_infop info_ptr)
 149.578 +png_get_channels(png_const_structp png_ptr, png_const_infop info_ptr)
 149.579  {
 149.580     if (png_ptr != NULL && info_ptr != NULL)
 149.581        return(info_ptr->channels);
 149.582 -   else
 149.583 -      return (0);
 149.584 +
 149.585 +   return (0);
 149.586  }
 149.587  
 149.588 -png_bytep PNGAPI
 149.589 -png_get_signature(png_structp png_ptr, png_infop info_ptr)
 149.590 +png_const_bytep PNGAPI
 149.591 +png_get_signature(png_const_structp png_ptr, png_infop info_ptr)
 149.592  {
 149.593     if (png_ptr != NULL && info_ptr != NULL)
 149.594        return(info_ptr->signature);
 149.595 -   else
 149.596 -      return (NULL);
 149.597 +
 149.598 +   return (NULL);
 149.599  }
 149.600  
 149.601 -#if defined(PNG_bKGD_SUPPORTED)
 149.602 +#ifdef PNG_bKGD_SUPPORTED
 149.603  png_uint_32 PNGAPI
 149.604 -png_get_bKGD(png_structp png_ptr, png_infop info_ptr,
 149.605 +png_get_bKGD(png_const_structp png_ptr, png_infop info_ptr,
 149.606     png_color_16p *background)
 149.607  {
 149.608     if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)
 149.609 -      && background != NULL)
 149.610 +       && background != NULL)
 149.611     {
 149.612 -      png_debug1(1, "in %s retrieval function\n", "bKGD");
 149.613 +      png_debug1(1, "in %s retrieval function", "bKGD");
 149.614 +
 149.615        *background = &(info_ptr->background);
 149.616        return (PNG_INFO_bKGD);
 149.617     }
 149.618 +
 149.619     return (0);
 149.620  }
 149.621  #endif
 149.622  
 149.623 -#if defined(PNG_cHRM_SUPPORTED)
 149.624 -#ifdef PNG_FLOATING_POINT_SUPPORTED
 149.625 +#ifdef PNG_cHRM_SUPPORTED
 149.626 +#  ifdef PNG_FLOATING_POINT_SUPPORTED
 149.627  png_uint_32 PNGAPI
 149.628 -png_get_cHRM(png_structp png_ptr, png_infop info_ptr,
 149.629 -   double *white_x, double *white_y, double *red_x, double *red_y,
 149.630 -   double *green_x, double *green_y, double *blue_x, double *blue_y)
 149.631 +png_get_cHRM(png_const_structp png_ptr, png_const_infop info_ptr,
 149.632 +    double *white_x, double *white_y, double *red_x, double *red_y,
 149.633 +    double *green_x, double *green_y, double *blue_x, double *blue_y)
 149.634  {
 149.635     if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
 149.636     {
 149.637 -      png_debug1(1, "in %s retrieval function\n", "cHRM");
 149.638 +      png_debug1(1, "in %s retrieval function", "cHRM");
 149.639 +
 149.640        if (white_x != NULL)
 149.641 -         *white_x = (double)info_ptr->x_white;
 149.642 +         *white_x = png_float(png_ptr, info_ptr->x_white, "cHRM white X");
 149.643        if (white_y != NULL)
 149.644 -         *white_y = (double)info_ptr->y_white;
 149.645 +         *white_y = png_float(png_ptr, info_ptr->y_white, "cHRM white Y");
 149.646        if (red_x != NULL)
 149.647 -         *red_x = (double)info_ptr->x_red;
 149.648 +         *red_x = png_float(png_ptr, info_ptr->x_red, "cHRM red X");
 149.649        if (red_y != NULL)
 149.650 -         *red_y = (double)info_ptr->y_red;
 149.651 +         *red_y = png_float(png_ptr, info_ptr->y_red, "cHRM red Y");
 149.652        if (green_x != NULL)
 149.653 -         *green_x = (double)info_ptr->x_green;
 149.654 +         *green_x = png_float(png_ptr, info_ptr->x_green, "cHRM green X");
 149.655        if (green_y != NULL)
 149.656 -         *green_y = (double)info_ptr->y_green;
 149.657 +         *green_y = png_float(png_ptr, info_ptr->y_green, "cHRM green Y");
 149.658        if (blue_x != NULL)
 149.659 -         *blue_x = (double)info_ptr->x_blue;
 149.660 +         *blue_x = png_float(png_ptr, info_ptr->x_blue, "cHRM blue X");
 149.661        if (blue_y != NULL)
 149.662 -         *blue_y = (double)info_ptr->y_blue;
 149.663 +         *blue_y = png_float(png_ptr, info_ptr->y_blue, "cHRM blue Y");
 149.664        return (PNG_INFO_cHRM);
 149.665     }
 149.666 +
 149.667     return (0);
 149.668  }
 149.669 -#endif
 149.670 -#ifdef PNG_FIXED_POINT_SUPPORTED
 149.671 +#  endif
 149.672 +
 149.673 +#  ifdef PNG_FIXED_POINT_SUPPORTED
 149.674  png_uint_32 PNGAPI
 149.675 -png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
 149.676 -   png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x,
 149.677 -   png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y,
 149.678 -   png_fixed_point *blue_x, png_fixed_point *blue_y)
 149.679 +png_get_cHRM_fixed(png_const_structp png_ptr, png_const_infop info_ptr,
 149.680 +    png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x,
 149.681 +    png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y,
 149.682 +    png_fixed_point *blue_x, png_fixed_point *blue_y)
 149.683  {
 149.684 +   png_debug1(1, "in %s retrieval function", "cHRM");
 149.685 +
 149.686     if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
 149.687     {
 149.688 -      png_debug1(1, "in %s retrieval function\n", "cHRM");
 149.689        if (white_x != NULL)
 149.690 -         *white_x = info_ptr->int_x_white;
 149.691 +         *white_x = info_ptr->x_white;
 149.692        if (white_y != NULL)
 149.693 -         *white_y = info_ptr->int_y_white;
 149.694 +         *white_y = info_ptr->y_white;
 149.695        if (red_x != NULL)
 149.696 -         *red_x = info_ptr->int_x_red;
 149.697 +         *red_x = info_ptr->x_red;
 149.698        if (red_y != NULL)
 149.699 -         *red_y = info_ptr->int_y_red;
 149.700 +         *red_y = info_ptr->y_red;
 149.701        if (green_x != NULL)
 149.702 -         *green_x = info_ptr->int_x_green;
 149.703 +         *green_x = info_ptr->x_green;
 149.704        if (green_y != NULL)
 149.705 -         *green_y = info_ptr->int_y_green;
 149.706 +         *green_y = info_ptr->y_green;
 149.707        if (blue_x != NULL)
 149.708 -         *blue_x = info_ptr->int_x_blue;
 149.709 +         *blue_x = info_ptr->x_blue;
 149.710        if (blue_y != NULL)
 149.711 -         *blue_y = info_ptr->int_y_blue;
 149.712 +         *blue_y = info_ptr->y_blue;
 149.713        return (PNG_INFO_cHRM);
 149.714     }
 149.715 +
 149.716     return (0);
 149.717  }
 149.718 -#endif
 149.719 +#  endif
 149.720  #endif
 149.721  
 149.722 -#if defined(PNG_gAMA_SUPPORTED)
 149.723 -#ifdef PNG_FLOATING_POINT_SUPPORTED
 149.724 -png_uint_32 PNGAPI
 149.725 -png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma)
 149.726 +#ifdef PNG_gAMA_SUPPORTED
 149.727 +png_uint_32 PNGFAPI
 149.728 +png_get_gAMA_fixed(png_const_structp png_ptr, png_const_infop info_ptr,
 149.729 +    png_fixed_point *file_gamma)
 149.730  {
 149.731 +   png_debug1(1, "in %s retrieval function", "gAMA");
 149.732 +
 149.733     if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
 149.734 -      && file_gamma != NULL)
 149.735 +       && file_gamma != NULL)
 149.736     {
 149.737 -      png_debug1(1, "in %s retrieval function\n", "gAMA");
 149.738 -      *file_gamma = (double)info_ptr->gamma;
 149.739 +      *file_gamma = info_ptr->gamma;
 149.740        return (PNG_INFO_gAMA);
 149.741     }
 149.742 +
 149.743     return (0);
 149.744  }
 149.745 -#endif
 149.746 -#ifdef PNG_FIXED_POINT_SUPPORTED
 149.747 +#  ifdef PNG_FLOATING_POINT_SUPPORTED
 149.748  png_uint_32 PNGAPI
 149.749 -png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr,
 149.750 -    png_fixed_point *int_file_gamma)
 149.751 +png_get_gAMA(png_const_structp png_ptr, png_const_infop info_ptr,
 149.752 +    double *file_gamma)
 149.753  {
 149.754 -   if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
 149.755 -      && int_file_gamma != NULL)
 149.756 -   {
 149.757 -      png_debug1(1, "in %s retrieval function\n", "gAMA");
 149.758 -      *int_file_gamma = info_ptr->int_gamma;
 149.759 -      return (PNG_INFO_gAMA);
 149.760 -   }
 149.761 -   return (0);
 149.762 +   png_fixed_point igamma;
 149.763 +   png_uint_32 ok = png_get_gAMA_fixed(png_ptr, info_ptr, &igamma);
 149.764 +
 149.765 +   if (ok)
 149.766 +      *file_gamma = png_float(png_ptr, igamma, "png_get_gAMA");
 149.767 +
 149.768 +   return ok;
 149.769  }
 149.770 -#endif
 149.771 +
 149.772 +#  endif
 149.773  #endif
 149.774  
 149.775 -#if defined(PNG_sRGB_SUPPORTED)
 149.776 +#ifdef PNG_sRGB_SUPPORTED
 149.777  png_uint_32 PNGAPI
 149.778 -png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent)
 149.779 +png_get_sRGB(png_const_structp png_ptr, png_const_infop info_ptr,
 149.780 +    int *file_srgb_intent)
 149.781  {
 149.782 +   png_debug1(1, "in %s retrieval function", "sRGB");
 149.783 +
 149.784     if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)
 149.785 -      && file_srgb_intent != NULL)
 149.786 +       && file_srgb_intent != NULL)
 149.787     {
 149.788 -      png_debug1(1, "in %s retrieval function\n", "sRGB");
 149.789        *file_srgb_intent = (int)info_ptr->srgb_intent;
 149.790        return (PNG_INFO_sRGB);
 149.791     }
 149.792 +
 149.793     return (0);
 149.794  }
 149.795  #endif
 149.796  
 149.797 -#if defined(PNG_iCCP_SUPPORTED)
 149.798 +#ifdef PNG_iCCP_SUPPORTED
 149.799  png_uint_32 PNGAPI
 149.800 -png_get_iCCP(png_structp png_ptr, png_infop info_ptr,
 149.801 -             png_charpp name, int *compression_type,
 149.802 -             png_charpp profile, png_uint_32 *proflen)
 149.803 +png_get_iCCP(png_const_structp png_ptr, png_const_infop info_ptr,
 149.804 +    png_charpp name, int *compression_type,
 149.805 +    png_bytepp profile, png_uint_32 *proflen)
 149.806  {
 149.807 +   png_debug1(1, "in %s retrieval function", "iCCP");
 149.808 +
 149.809     if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP)
 149.810 -      && name != NULL && profile != NULL && proflen != NULL)
 149.811 +       && name != NULL && profile != NULL && proflen != NULL)
 149.812     {
 149.813 -      png_debug1(1, "in %s retrieval function\n", "iCCP");
 149.814        *name = info_ptr->iccp_name;
 149.815        *profile = info_ptr->iccp_profile;
 149.816 -      /* compression_type is a dummy so the API won't have to change
 149.817 -         if we introduce multiple compression types later. */
 149.818 +      /* Compression_type is a dummy so the API won't have to change
 149.819 +       * if we introduce multiple compression types later.
 149.820 +       */
 149.821        *proflen = (int)info_ptr->iccp_proflen;
 149.822        *compression_type = (int)info_ptr->iccp_compression;
 149.823        return (PNG_INFO_iCCP);
 149.824     }
 149.825 +
 149.826     return (0);
 149.827  }
 149.828  #endif
 149.829  
 149.830 -#if defined(PNG_sPLT_SUPPORTED)
 149.831 +#ifdef PNG_sPLT_SUPPORTED
 149.832  png_uint_32 PNGAPI
 149.833 -png_get_sPLT(png_structp png_ptr, png_infop info_ptr,
 149.834 -             png_sPLT_tpp spalettes)
 149.835 +png_get_sPLT(png_const_structp png_ptr, png_const_infop info_ptr,
 149.836 +    png_sPLT_tpp spalettes)
 149.837  {
 149.838     if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
 149.839 -     *spalettes = info_ptr->splt_palettes;
 149.840 -   return ((png_uint_32)info_ptr->splt_palettes_num);
 149.841 +   {
 149.842 +      *spalettes = info_ptr->splt_palettes;
 149.843 +      return ((png_uint_32)info_ptr->splt_palettes_num);
 149.844 +   }
 149.845 +
 149.846 +   return (0);
 149.847  }
 149.848  #endif
 149.849  
 149.850 -#if defined(PNG_hIST_SUPPORTED)
 149.851 +#ifdef PNG_hIST_SUPPORTED
 149.852  png_uint_32 PNGAPI
 149.853 -png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist)
 149.854 +png_get_hIST(png_const_structp png_ptr, png_const_infop info_ptr,
 149.855 +    png_uint_16p *hist)
 149.856  {
 149.857 +   png_debug1(1, "in %s retrieval function", "hIST");
 149.858 +
 149.859     if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)
 149.860 -      && hist != NULL)
 149.861 +       && hist != NULL)
 149.862     {
 149.863 -      png_debug1(1, "in %s retrieval function\n", "hIST");
 149.864        *hist = info_ptr->hist;
 149.865        return (PNG_INFO_hIST);
 149.866     }
 149.867 +
 149.868     return (0);
 149.869  }
 149.870  #endif
 149.871  
 149.872  png_uint_32 PNGAPI
 149.873  png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
 149.874 -   png_uint_32 *width, png_uint_32 *height, int *bit_depth,
 149.875 -   int *color_type, int *interlace_type, int *compression_type,
 149.876 -   int *filter_type)
 149.877 +    png_uint_32 *width, png_uint_32 *height, int *bit_depth,
 149.878 +    int *color_type, int *interlace_type, int *compression_type,
 149.879 +    int *filter_type)
 149.880  
 149.881  {
 149.882 -   if (png_ptr != NULL && info_ptr != NULL && width != NULL && height != NULL &&
 149.883 -      bit_depth != NULL && color_type != NULL)
 149.884 -   {
 149.885 -      png_debug1(1, "in %s retrieval function\n", "IHDR");
 149.886 -      *width = info_ptr->width;
 149.887 -      *height = info_ptr->height;
 149.888 -      *bit_depth = info_ptr->bit_depth;
 149.889 -      if (info_ptr->bit_depth < 1 || info_ptr->bit_depth > 16)
 149.890 -        png_error(png_ptr, "Invalid bit depth");
 149.891 -      *color_type = info_ptr->color_type;
 149.892 -      if (info_ptr->color_type > 6)
 149.893 -        png_error(png_ptr, "Invalid color type");
 149.894 -      if (compression_type != NULL)
 149.895 -         *compression_type = info_ptr->compression_type;
 149.896 -      if (filter_type != NULL)
 149.897 -         *filter_type = info_ptr->filter_type;
 149.898 -      if (interlace_type != NULL)
 149.899 -         *interlace_type = info_ptr->interlace_type;
 149.900 +   png_debug1(1, "in %s retrieval function", "IHDR");
 149.901  
 149.902 -      /* check for potential overflow of rowbytes */
 149.903 -      if (*width == 0 || *width > PNG_UINT_31_MAX)
 149.904 -        png_error(png_ptr, "Invalid image width");
 149.905 -      if (*height == 0 || *height > PNG_UINT_31_MAX)
 149.906 -        png_error(png_ptr, "Invalid image height");
 149.907 -      if (info_ptr->width > (PNG_UINT_32_MAX
 149.908 -                 >> 3)      /* 8-byte RGBA pixels */
 149.909 -                 - 64       /* bigrowbuf hack */
 149.910 -                 - 1        /* filter byte */
 149.911 -                 - 7*8      /* rounding of width to multiple of 8 pixels */
 149.912 -                 - 8)       /* extra max_pixel_depth pad */
 149.913 -      {
 149.914 -         png_warning(png_ptr,
 149.915 -            "Width too large for libpng to process image data.");
 149.916 -      }
 149.917 -      return (1);
 149.918 -   }
 149.919 -   return (0);
 149.920 +   if (png_ptr == NULL || info_ptr == NULL || width == NULL ||
 149.921 +       height == NULL || bit_depth == NULL || color_type == NULL)
 149.922 +      return (0);
 149.923 +
 149.924 +   *width = info_ptr->width;
 149.925 +   *height = info_ptr->height;
 149.926 +   *bit_depth = info_ptr->bit_depth;
 149.927 +   *color_type = info_ptr->color_type;
 149.928 +
 149.929 +   if (compression_type != NULL)
 149.930 +      *compression_type = info_ptr->compression_type;
 149.931 +
 149.932 +   if (filter_type != NULL)
 149.933 +      *filter_type = info_ptr->filter_type;
 149.934 +
 149.935 +   if (interlace_type != NULL)
 149.936 +      *interlace_type = info_ptr->interlace_type;
 149.937 +
 149.938 +   /* This is redundant if we can be sure that the info_ptr values were all
 149.939 +    * assigned in png_set_IHDR().  We do the check anyhow in case an
 149.940 +    * application has ignored our advice not to mess with the members
 149.941 +    * of info_ptr directly.
 149.942 +    */
 149.943 +   png_check_IHDR (png_ptr, info_ptr->width, info_ptr->height,
 149.944 +       info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type,
 149.945 +       info_ptr->compression_type, info_ptr->filter_type);
 149.946 +
 149.947 +   return (1);
 149.948  }
 149.949  
 149.950 -#if defined(PNG_oFFs_SUPPORTED)
 149.951 +#ifdef PNG_oFFs_SUPPORTED
 149.952  png_uint_32 PNGAPI
 149.953 -png_get_oFFs(png_structp png_ptr, png_infop info_ptr,
 149.954 -   png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
 149.955 +png_get_oFFs(png_const_structp png_ptr, png_const_infop info_ptr,
 149.956 +    png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
 149.957  {
 149.958 +   png_debug1(1, "in %s retrieval function", "oFFs");
 149.959 +
 149.960     if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)
 149.961 -      && offset_x != NULL && offset_y != NULL && unit_type != NULL)
 149.962 +       && offset_x != NULL && offset_y != NULL && unit_type != NULL)
 149.963     {
 149.964 -      png_debug1(1, "in %s retrieval function\n", "oFFs");
 149.965        *offset_x = info_ptr->x_offset;
 149.966        *offset_y = info_ptr->y_offset;
 149.967        *unit_type = (int)info_ptr->offset_unit_type;
 149.968        return (PNG_INFO_oFFs);
 149.969     }
 149.970 +
 149.971     return (0);
 149.972  }
 149.973  #endif
 149.974  
 149.975 -#if defined(PNG_pCAL_SUPPORTED)
 149.976 +#ifdef PNG_pCAL_SUPPORTED
 149.977  png_uint_32 PNGAPI
 149.978 -png_get_pCAL(png_structp png_ptr, png_infop info_ptr,
 149.979 -   png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
 149.980 -   png_charp *units, png_charpp *params)
 149.981 +png_get_pCAL(png_const_structp png_ptr, png_const_infop info_ptr,
 149.982 +    png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
 149.983 +    png_charp *units, png_charpp *params)
 149.984  {
 149.985 +   png_debug1(1, "in %s retrieval function", "pCAL");
 149.986 +
 149.987     if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)
 149.988 -      && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
 149.989 -      nparams != NULL && units != NULL && params != NULL)
 149.990 +       && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
 149.991 +       nparams != NULL && units != NULL && params != NULL)
 149.992     {
 149.993 -      png_debug1(1, "in %s retrieval function\n", "pCAL");
 149.994        *purpose = info_ptr->pcal_purpose;
 149.995        *X0 = info_ptr->pcal_X0;
 149.996        *X1 = info_ptr->pcal_X1;
 149.997 @@ -644,340 +744,317 @@
 149.998        *params = info_ptr->pcal_params;
 149.999        return (PNG_INFO_pCAL);
149.1000     }
149.1001 +
149.1002     return (0);
149.1003  }
149.1004  #endif
149.1005  
149.1006 -#if defined(PNG_sCAL_SUPPORTED)
149.1007 -#ifdef PNG_FLOATING_POINT_SUPPORTED
149.1008 +#ifdef PNG_sCAL_SUPPORTED
149.1009 +#  ifdef PNG_FIXED_POINT_SUPPORTED
149.1010 +#    ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
149.1011  png_uint_32 PNGAPI
149.1012 -png_get_sCAL(png_structp png_ptr, png_infop info_ptr,
149.1013 -             int *unit, double *width, double *height)
149.1014 +png_get_sCAL_fixed(png_structp png_ptr, png_const_infop info_ptr,
149.1015 +    int *unit, png_fixed_point *width, png_fixed_point *height)
149.1016  {
149.1017 -    if (png_ptr != NULL && info_ptr != NULL &&
149.1018 +   if (png_ptr != NULL && info_ptr != NULL &&
149.1019         (info_ptr->valid & PNG_INFO_sCAL))
149.1020 -    {
149.1021 -        *unit = info_ptr->scal_unit;
149.1022 -        *width = info_ptr->scal_pixel_width;
149.1023 -        *height = info_ptr->scal_pixel_height;
149.1024 -        return (PNG_INFO_sCAL);
149.1025 -    }
149.1026 -    return(0);
149.1027 +   {
149.1028 +      *unit = info_ptr->scal_unit;
149.1029 +      /*TODO: make this work without FP support */
149.1030 +      *width = png_fixed(png_ptr, atof(info_ptr->scal_s_width), "sCAL width");
149.1031 +      *height = png_fixed(png_ptr, atof(info_ptr->scal_s_height),
149.1032 +         "sCAL height");
149.1033 +      return (PNG_INFO_sCAL);
149.1034 +   }
149.1035 +
149.1036 +   return(0);
149.1037  }
149.1038 -#else
149.1039 -#ifdef PNG_FIXED_POINT_SUPPORTED
149.1040 +#    endif /* FLOATING_ARITHMETIC */
149.1041 +#  endif /* FIXED_POINT */
149.1042 +#  ifdef PNG_FLOATING_POINT_SUPPORTED
149.1043  png_uint_32 PNGAPI
149.1044 -png_get_sCAL_s(png_structp png_ptr, png_infop info_ptr,
149.1045 -             int *unit, png_charpp width, png_charpp height)
149.1046 +png_get_sCAL(png_const_structp png_ptr, png_const_infop info_ptr,
149.1047 +    int *unit, double *width, double *height)
149.1048  {
149.1049 -    if (png_ptr != NULL && info_ptr != NULL &&
149.1050 +   if (png_ptr != NULL && info_ptr != NULL &&
149.1051         (info_ptr->valid & PNG_INFO_sCAL))
149.1052 -    {
149.1053 -        *unit = info_ptr->scal_unit;
149.1054 -        *width = info_ptr->scal_s_width;
149.1055 -        *height = info_ptr->scal_s_height;
149.1056 -        return (PNG_INFO_sCAL);
149.1057 -    }
149.1058 -    return(0);
149.1059 +   {
149.1060 +      *unit = info_ptr->scal_unit;
149.1061 +      *width = atof(info_ptr->scal_s_width);
149.1062 +      *height = atof(info_ptr->scal_s_height);
149.1063 +      return (PNG_INFO_sCAL);
149.1064 +   }
149.1065 +
149.1066 +   return(0);
149.1067  }
149.1068 -#endif
149.1069 -#endif
149.1070 -#endif
149.1071 +#  endif /* FLOATING POINT */
149.1072 +png_uint_32 PNGAPI
149.1073 +png_get_sCAL_s(png_const_structp png_ptr, png_const_infop info_ptr,
149.1074 +    int *unit, png_charpp width, png_charpp height)
149.1075 +{
149.1076 +   if (png_ptr != NULL && info_ptr != NULL &&
149.1077 +       (info_ptr->valid & PNG_INFO_sCAL))
149.1078 +   {
149.1079 +      *unit = info_ptr->scal_unit;
149.1080 +      *width = info_ptr->scal_s_width;
149.1081 +      *height = info_ptr->scal_s_height;
149.1082 +      return (PNG_INFO_sCAL);
149.1083 +   }
149.1084  
149.1085 -#if defined(PNG_pHYs_SUPPORTED)
149.1086 +   return(0);
149.1087 +}
149.1088 +#endif /* sCAL */
149.1089 +
149.1090 +#ifdef PNG_pHYs_SUPPORTED
149.1091  png_uint_32 PNGAPI
149.1092 -png_get_pHYs(png_structp png_ptr, png_infop info_ptr,
149.1093 -   png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
149.1094 +png_get_pHYs(png_const_structp png_ptr, png_const_infop info_ptr,
149.1095 +    png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
149.1096  {
149.1097     png_uint_32 retval = 0;
149.1098  
149.1099 +   png_debug1(1, "in %s retrieval function", "pHYs");
149.1100 +
149.1101     if (png_ptr != NULL && info_ptr != NULL &&
149.1102 -      (info_ptr->valid & PNG_INFO_pHYs))
149.1103 +       (info_ptr->valid & PNG_INFO_pHYs))
149.1104     {
149.1105 -      png_debug1(1, "in %s retrieval function\n", "pHYs");
149.1106        if (res_x != NULL)
149.1107        {
149.1108           *res_x = info_ptr->x_pixels_per_unit;
149.1109           retval |= PNG_INFO_pHYs;
149.1110        }
149.1111 +
149.1112        if (res_y != NULL)
149.1113        {
149.1114           *res_y = info_ptr->y_pixels_per_unit;
149.1115           retval |= PNG_INFO_pHYs;
149.1116        }
149.1117 +
149.1118        if (unit_type != NULL)
149.1119        {
149.1120           *unit_type = (int)info_ptr->phys_unit_type;
149.1121           retval |= PNG_INFO_pHYs;
149.1122        }
149.1123     }
149.1124 +
149.1125     return (retval);
149.1126  }
149.1127 -#endif
149.1128 +#endif /* pHYs */
149.1129  
149.1130  png_uint_32 PNGAPI
149.1131 -png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette,
149.1132 -   int *num_palette)
149.1133 +png_get_PLTE(png_const_structp png_ptr, png_const_infop info_ptr,
149.1134 +    png_colorp *palette, int *num_palette)
149.1135  {
149.1136 +   png_debug1(1, "in %s retrieval function", "PLTE");
149.1137 +
149.1138     if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE)
149.1139         && palette != NULL)
149.1140     {
149.1141 -      png_debug1(1, "in %s retrieval function\n", "PLTE");
149.1142        *palette = info_ptr->palette;
149.1143        *num_palette = info_ptr->num_palette;
149.1144 -      png_debug1(3, "num_palette = %d\n", *num_palette);
149.1145 +      png_debug1(3, "num_palette = %d", *num_palette);
149.1146        return (PNG_INFO_PLTE);
149.1147     }
149.1148 +
149.1149     return (0);
149.1150  }
149.1151  
149.1152 -#if defined(PNG_sBIT_SUPPORTED)
149.1153 +#ifdef PNG_sBIT_SUPPORTED
149.1154  png_uint_32 PNGAPI
149.1155 -png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit)
149.1156 +png_get_sBIT(png_const_structp png_ptr, png_infop info_ptr,
149.1157 +    png_color_8p *sig_bit)
149.1158  {
149.1159 +   png_debug1(1, "in %s retrieval function", "sBIT");
149.1160 +
149.1161     if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)
149.1162 -      && sig_bit != NULL)
149.1163 +       && sig_bit != NULL)
149.1164     {
149.1165 -      png_debug1(1, "in %s retrieval function\n", "sBIT");
149.1166        *sig_bit = &(info_ptr->sig_bit);
149.1167        return (PNG_INFO_sBIT);
149.1168     }
149.1169 +
149.1170     return (0);
149.1171  }
149.1172  #endif
149.1173  
149.1174 -#if defined(PNG_TEXT_SUPPORTED)
149.1175 +#ifdef PNG_TEXT_SUPPORTED
149.1176  png_uint_32 PNGAPI
149.1177 -png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr,
149.1178 -   int *num_text)
149.1179 +png_get_text(png_const_structp png_ptr, png_const_infop info_ptr,
149.1180 +    png_textp *text_ptr, int *num_text)
149.1181  {
149.1182     if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
149.1183     {
149.1184 -      png_debug1(1, "in %s retrieval function\n",
149.1185 -         (png_ptr->chunk_name[0] == '\0' ? "text"
149.1186 -             : (png_const_charp)png_ptr->chunk_name));
149.1187 +      png_debug1(1, "in %s retrieval function",
149.1188 +          (png_ptr->chunk_name[0] == '\0' ? "text" :
149.1189 +          (png_const_charp)png_ptr->chunk_name));
149.1190 +
149.1191        if (text_ptr != NULL)
149.1192           *text_ptr = info_ptr->text;
149.1193 +
149.1194        if (num_text != NULL)
149.1195           *num_text = info_ptr->num_text;
149.1196 +
149.1197        return ((png_uint_32)info_ptr->num_text);
149.1198     }
149.1199 +
149.1200     if (num_text != NULL)
149.1201 -     *num_text = 0;
149.1202 +      *num_text = 0;
149.1203 +
149.1204     return(0);
149.1205  }
149.1206  #endif
149.1207  
149.1208 -#if defined(PNG_tIME_SUPPORTED)
149.1209 +#ifdef PNG_tIME_SUPPORTED
149.1210  png_uint_32 PNGAPI
149.1211 -png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time)
149.1212 +png_get_tIME(png_const_structp png_ptr, png_infop info_ptr, png_timep *mod_time)
149.1213  {
149.1214 +   png_debug1(1, "in %s retrieval function", "tIME");
149.1215 +
149.1216     if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)
149.1217         && mod_time != NULL)
149.1218     {
149.1219 -      png_debug1(1, "in %s retrieval function\n", "tIME");
149.1220        *mod_time = &(info_ptr->mod_time);
149.1221        return (PNG_INFO_tIME);
149.1222     }
149.1223 +
149.1224     return (0);
149.1225  }
149.1226  #endif
149.1227  
149.1228 -#if defined(PNG_tRNS_SUPPORTED)
149.1229 +#ifdef PNG_tRNS_SUPPORTED
149.1230  png_uint_32 PNGAPI
149.1231 -png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
149.1232 -   png_bytep *trans, int *num_trans, png_color_16p *trans_values)
149.1233 +png_get_tRNS(png_const_structp png_ptr, png_infop info_ptr,
149.1234 +    png_bytep *trans_alpha, int *num_trans, png_color_16p *trans_color)
149.1235  {
149.1236     png_uint_32 retval = 0;
149.1237     if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
149.1238     {
149.1239 -      png_debug1(1, "in %s retrieval function\n", "tRNS");
149.1240 +      png_debug1(1, "in %s retrieval function", "tRNS");
149.1241 +
149.1242        if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
149.1243        {
149.1244 -          if (trans != NULL)
149.1245 -          {
149.1246 -             *trans = info_ptr->trans;
149.1247 -             retval |= PNG_INFO_tRNS;
149.1248 -          }
149.1249 -          if (trans_values != NULL)
149.1250 -             *trans_values = &(info_ptr->trans_values);
149.1251 +         if (trans_alpha != NULL)
149.1252 +         {
149.1253 +            *trans_alpha = info_ptr->trans_alpha;
149.1254 +            retval |= PNG_INFO_tRNS;
149.1255 +         }
149.1256 +
149.1257 +         if (trans_color != NULL)
149.1258 +            *trans_color = &(info_ptr->trans_color);
149.1259        }
149.1260 +
149.1261        else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
149.1262        {
149.1263 -          if (trans_values != NULL)
149.1264 -          {
149.1265 -             *trans_values = &(info_ptr->trans_values);
149.1266 -             retval |= PNG_INFO_tRNS;
149.1267 -          }
149.1268 -          if(trans != NULL)
149.1269 -             *trans = NULL;
149.1270 +         if (trans_color != NULL)
149.1271 +         {
149.1272 +            *trans_color = &(info_ptr->trans_color);
149.1273 +            retval |= PNG_INFO_tRNS;
149.1274 +         }
149.1275 +
149.1276 +         if (trans_alpha != NULL)
149.1277 +            *trans_alpha = NULL;
149.1278        }
149.1279 -      if(num_trans != NULL)
149.1280 +
149.1281 +      if (num_trans != NULL)
149.1282        {
149.1283           *num_trans = info_ptr->num_trans;
149.1284           retval |= PNG_INFO_tRNS;
149.1285        }
149.1286     }
149.1287 +
149.1288     return (retval);
149.1289  }
149.1290  #endif
149.1291  
149.1292 -#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
149.1293 -png_uint_32 PNGAPI
149.1294 -png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr,
149.1295 -             png_unknown_chunkpp unknowns)
149.1296 +#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
149.1297 +int PNGAPI
149.1298 +png_get_unknown_chunks(png_const_structp png_ptr, png_const_infop info_ptr,
149.1299 +    png_unknown_chunkpp unknowns)
149.1300  {
149.1301     if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)
149.1302 -     *unknowns = info_ptr->unknown_chunks;
149.1303 -   return ((png_uint_32)info_ptr->unknown_chunks_num);
149.1304 +   {
149.1305 +      *unknowns = info_ptr->unknown_chunks;
149.1306 +      return info_ptr->unknown_chunks_num;
149.1307 +   }
149.1308 +
149.1309 +   return (0);
149.1310  }
149.1311  #endif
149.1312  
149.1313 -#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
149.1314 +#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
149.1315  png_byte PNGAPI
149.1316 -png_get_rgb_to_gray_status (png_structp png_ptr)
149.1317 +png_get_rgb_to_gray_status (png_const_structp png_ptr)
149.1318  {
149.1319 -   return (png_byte)(png_ptr? png_ptr->rgb_to_gray_status : 0);
149.1320 +   return (png_byte)(png_ptr ? png_ptr->rgb_to_gray_status : 0);
149.1321  }
149.1322  #endif
149.1323  
149.1324 -#if defined(PNG_USER_CHUNKS_SUPPORTED)
149.1325 +#ifdef PNG_USER_CHUNKS_SUPPORTED
149.1326  png_voidp PNGAPI
149.1327 -png_get_user_chunk_ptr(png_structp png_ptr)
149.1328 +png_get_user_chunk_ptr(png_const_structp png_ptr)
149.1329  {
149.1330 -   return (png_ptr? png_ptr->user_chunk_ptr : NULL);
149.1331 +   return (png_ptr ? png_ptr->user_chunk_ptr : NULL);
149.1332  }
149.1333  #endif
149.1334  
149.1335 -#ifdef PNG_WRITE_SUPPORTED
149.1336 -png_uint_32 PNGAPI
149.1337 -png_get_compression_buffer_size(png_structp png_ptr)
149.1338 +png_size_t PNGAPI
149.1339 +png_get_compression_buffer_size(png_const_structp png_ptr)
149.1340  {
149.1341 -   return (png_uint_32)(png_ptr? png_ptr->zbuf_size : 0L);
149.1342 -}
149.1343 -#endif
149.1344 -
149.1345 -#ifdef PNG_ASSEMBLER_CODE_SUPPORTED
149.1346 -#ifndef PNG_1_0_X
149.1347 -/* this function was added to libpng 1.2.0 and should exist by default */
149.1348 -png_uint_32 PNGAPI
149.1349 -png_get_asm_flags (png_structp png_ptr)
149.1350 -{
149.1351 -#ifdef PNG_MMX_CODE_SUPPORTED
149.1352 -    return (png_uint_32)(png_ptr? png_ptr->asm_flags : 0L);
149.1353 -#else
149.1354 -    return (png_ptr? 0L: 0L);
149.1355 -#endif
149.1356 +   return (png_ptr ? png_ptr->zbuf_size : 0L);
149.1357  }
149.1358  
149.1359 -/* this function was added to libpng 1.2.0 and should exist by default */
149.1360 +
149.1361 +#ifdef PNG_SET_USER_LIMITS_SUPPORTED
149.1362 +/* These functions were added to libpng 1.2.6 and were enabled
149.1363 + * by default in libpng-1.4.0 */
149.1364  png_uint_32 PNGAPI
149.1365 -png_get_asm_flagmask (int flag_select)
149.1366 +png_get_user_width_max (png_const_structp png_ptr)
149.1367  {
149.1368 -#ifdef PNG_MMX_CODE_SUPPORTED
149.1369 -    png_uint_32 settable_asm_flags = 0;
149.1370 -
149.1371 -    if (flag_select & PNG_SELECT_READ)
149.1372 -        settable_asm_flags |=
149.1373 -          PNG_ASM_FLAG_MMX_READ_COMBINE_ROW  |
149.1374 -          PNG_ASM_FLAG_MMX_READ_INTERLACE    |
149.1375 -          PNG_ASM_FLAG_MMX_READ_FILTER_SUB   |
149.1376 -          PNG_ASM_FLAG_MMX_READ_FILTER_UP    |
149.1377 -          PNG_ASM_FLAG_MMX_READ_FILTER_AVG   |
149.1378 -          PNG_ASM_FLAG_MMX_READ_FILTER_PAETH ;
149.1379 -          /* no non-MMX flags yet */
149.1380 -
149.1381 -#if 0
149.1382 -    /* GRR:  no write-flags yet, either, but someday... */
149.1383 -    if (flag_select & PNG_SELECT_WRITE)
149.1384 -        settable_asm_flags |=
149.1385 -          PNG_ASM_FLAG_MMX_WRITE_ [whatever] ;
149.1386 -#endif /* 0 */
149.1387 -
149.1388 -    return settable_asm_flags;  /* _theoretically_ settable capabilities only */
149.1389 -#else
149.1390 -    return (0L);
149.1391 -#endif /* PNG_MMX_CODE_SUPPORTED */
149.1392 +   return (png_ptr ? png_ptr->user_width_max : 0);
149.1393  }
149.1394  
149.1395 -
149.1396 -    /* GRR:  could add this:   && defined(PNG_MMX_CODE_SUPPORTED) */
149.1397 -/* this function was added to libpng 1.2.0 */
149.1398  png_uint_32 PNGAPI
149.1399 -png_get_mmx_flagmask (int flag_select, int *compilerID)
149.1400 +png_get_user_height_max (png_const_structp png_ptr)
149.1401  {
149.1402 -#if defined(PNG_MMX_CODE_SUPPORTED)
149.1403 -    png_uint_32 settable_mmx_flags = 0;
149.1404 -
149.1405 -    if (flag_select & PNG_SELECT_READ)
149.1406 -        settable_mmx_flags |=
149.1407 -          PNG_ASM_FLAG_MMX_READ_COMBINE_ROW  |
149.1408 -          PNG_ASM_FLAG_MMX_READ_INTERLACE    |
149.1409 -          PNG_ASM_FLAG_MMX_READ_FILTER_SUB   |
149.1410 -          PNG_ASM_FLAG_MMX_READ_FILTER_UP    |
149.1411 -          PNG_ASM_FLAG_MMX_READ_FILTER_AVG   |
149.1412 -          PNG_ASM_FLAG_MMX_READ_FILTER_PAETH ;
149.1413 -#if 0
149.1414 -    /* GRR:  no MMX write support yet, but someday... */
149.1415 -    if (flag_select & PNG_SELECT_WRITE)
149.1416 -        settable_mmx_flags |=
149.1417 -          PNG_ASM_FLAG_MMX_WRITE_ [whatever] ;
149.1418 -#endif /* 0 */
149.1419 -
149.1420 -    if (compilerID != NULL) {
149.1421 -#ifdef PNG_USE_PNGVCRD
149.1422 -        *compilerID = 1;    /* MSVC */
149.1423 -#else
149.1424 -#ifdef PNG_USE_PNGGCCRD
149.1425 -        *compilerID = 2;    /* gcc/gas */
149.1426 -#else
149.1427 -        *compilerID = -1;   /* unknown (i.e., no asm/MMX code compiled) */
149.1428 -#endif
149.1429 -#endif
149.1430 -    }
149.1431 -
149.1432 -    return settable_mmx_flags;  /* _theoretically_ settable capabilities only */
149.1433 -#else
149.1434 -    return (0L);
149.1435 -#endif /* ?PNG_MMX_CODE_SUPPORTED */
149.1436 +   return (png_ptr ? png_ptr->user_height_max : 0);
149.1437  }
149.1438  
149.1439 -/* this function was added to libpng 1.2.0 */
149.1440 -png_byte PNGAPI
149.1441 -png_get_mmx_bitdepth_threshold (png_structp png_ptr)
149.1442 +/* This function was added to libpng 1.4.0 */
149.1443 +png_uint_32 PNGAPI
149.1444 +png_get_chunk_cache_max (png_const_structp png_ptr)
149.1445  {
149.1446 -#if defined(PNG_MMX_CODE_SUPPORTED)
149.1447 -    return (png_byte)(png_ptr? png_ptr->mmx_bitdepth_threshold : 0);
149.1448 -#else
149.1449 -    return (png_ptr? 0: 0);
149.1450 -#endif /* ?PNG_MMX_CODE_SUPPORTED */
149.1451 +   return (png_ptr ? png_ptr->user_chunk_cache_max : 0);
149.1452  }
149.1453  
149.1454 -/* this function was added to libpng 1.2.0 */
149.1455 -png_uint_32 PNGAPI
149.1456 -png_get_mmx_rowbytes_threshold (png_structp png_ptr)
149.1457 +/* This function was added to libpng 1.4.1 */
149.1458 +png_alloc_size_t PNGAPI
149.1459 +png_get_chunk_malloc_max (png_const_structp png_ptr)
149.1460  {
149.1461 -#if defined(PNG_MMX_CODE_SUPPORTED)
149.1462 -    return (png_uint_32)(png_ptr? png_ptr->mmx_rowbytes_threshold : 0L);
149.1463 -#else
149.1464 -    return (png_ptr? 0L: 0L);
149.1465 -#endif /* ?PNG_MMX_CODE_SUPPORTED */
149.1466 -}
149.1467 -#endif /* ?PNG_1_0_X */
149.1468 -#endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
149.1469 -
149.1470 -#ifdef PNG_SET_USER_LIMITS_SUPPORTED
149.1471 -/* these functions were added to libpng 1.2.6 */
149.1472 -png_uint_32 PNGAPI
149.1473 -png_get_user_width_max (png_structp png_ptr)
149.1474 -{
149.1475 -    return (png_ptr? png_ptr->user_width_max : 0);
149.1476 -}
149.1477 -png_uint_32 PNGAPI
149.1478 -png_get_user_height_max (png_structp png_ptr)
149.1479 -{
149.1480 -    return (png_ptr? png_ptr->user_height_max : 0);
149.1481 +   return (png_ptr ? png_ptr->user_chunk_malloc_max : 0);
149.1482  }
149.1483  #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
149.1484  
149.1485 +/* These functions were added to libpng 1.4.0 */
149.1486 +#ifdef PNG_IO_STATE_SUPPORTED
149.1487 +png_uint_32 PNGAPI
149.1488 +png_get_io_state (png_structp png_ptr)
149.1489 +{
149.1490 +   return png_ptr->io_state;
149.1491 +}
149.1492 +
149.1493 +png_uint_32 PNGAPI
149.1494 +png_get_io_chunk_type (png_const_structp png_ptr)
149.1495 +{
149.1496 +   return ((png_ptr->chunk_name[0] << 24) +
149.1497 +           (png_ptr->chunk_name[1] << 16) +
149.1498 +           (png_ptr->chunk_name[2] <<  8) +
149.1499 +           (png_ptr->chunk_name[3]));
149.1500 +}
149.1501 +
149.1502 +png_const_bytep PNGAPI
149.1503 +png_get_io_chunk_name (png_structp png_ptr)
149.1504 +{
149.1505 +   return png_ptr->chunk_name;
149.1506 +}
149.1507 +#endif /* ?PNG_IO_STATE_SUPPORTED */
149.1508 +
149.1509  #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
   150.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   150.2 +++ b/src/share/native/sun/awt/libpng/pnginfo.h	Tue Oct 04 12:39:42 2011 -0700
   150.3 @@ -0,0 +1,297 @@
   150.4 +/*
   150.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   150.6 + *
   150.7 + * This code is free software; you can redistribute it and/or modify it
   150.8 + * under the terms of the GNU General Public License version 2 only, as
   150.9 + * published by the Free Software Foundation.  Oracle designates this
  150.10 + * particular file as subject to the "Classpath" exception as provided
  150.11 + * by Oracle in the LICENSE file that accompanied this code.
  150.12 + *
  150.13 + * This code is distributed in the hope that it will be useful, but WITHOUT
  150.14 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  150.15 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  150.16 + * version 2 for more details (a copy is included in the LICENSE file that
  150.17 + * accompanied this code).
  150.18 + *
  150.19 + * You should have received a copy of the GNU General Public License version
  150.20 + * 2 along with this work; if not, write to the Free Software Foundation,
  150.21 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  150.22 + *
  150.23 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  150.24 + * or visit www.oracle.com if you need additional information or have any
  150.25 + * questions.
  150.26 + */
  150.27 +
  150.28 +/* pnginfo.h - header file for PNG reference library
  150.29 + *
  150.30 + * This file is available under and governed by the GNU General Public
  150.31 + * License version 2 only, as published by the Free Software Foundation.
  150.32 + * However, the following notice accompanied the original version of this
  150.33 + * file and, per its terms, should not be removed:
  150.34 + *
  150.35 + * Copyright (c) 1998-2011 Glenn Randers-Pehrson
  150.36 + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
  150.37 + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
  150.38 + *
  150.39 + * Last changed in libpng 1.5.0 [January 6, 2011]
  150.40 + *
  150.41 + * This code is released under the libpng license.
  150.42 + * For conditions of distribution and use, see the disclaimer
  150.43 + * and license in png.h
  150.44 + */
  150.45 +
  150.46 + /* png_info is a structure that holds the information in a PNG file so
  150.47 + * that the application can find out the characteristics of the image.
  150.48 + * If you are reading the file, this structure will tell you what is
  150.49 + * in the PNG file.  If you are writing the file, fill in the information
  150.50 + * you want to put into the PNG file, using png_set_*() functions, then
  150.51 + * call png_write_info().
  150.52 + *
  150.53 + * The names chosen should be very close to the PNG specification, so
  150.54 + * consult that document for information about the meaning of each field.
  150.55 + *
  150.56 + * With libpng < 0.95, it was only possible to directly set and read the
  150.57 + * the values in the png_info_struct, which meant that the contents and
  150.58 + * order of the values had to remain fixed.  With libpng 0.95 and later,
  150.59 + * however, there are now functions that abstract the contents of
  150.60 + * png_info_struct from the application, so this makes it easier to use
  150.61 + * libpng with dynamic libraries, and even makes it possible to use
  150.62 + * libraries that don't have all of the libpng ancillary chunk-handing
  150.63 + * functionality.  In libpng-1.5.0 this was moved into a separate private
  150.64 + * file that is not visible to applications.
  150.65 + *
  150.66 + * The following members may have allocated storage attached that should be
  150.67 + * cleaned up before the structure is discarded: palette, trans, text,
  150.68 + * pcal_purpose, pcal_units, pcal_params, hist, iccp_name, iccp_profile,
  150.69 + * splt_palettes, scal_unit, row_pointers, and unknowns.   By default, these
  150.70 + * are automatically freed when the info structure is deallocated, if they were
  150.71 + * allocated internally by libpng.  This behavior can be changed by means
  150.72 + * of the png_data_freer() function.
  150.73 + *
  150.74 + * More allocation details: all the chunk-reading functions that
  150.75 + * change these members go through the corresponding png_set_*
  150.76 + * functions.  A function to clear these members is available: see
  150.77 + * png_free_data().  The png_set_* functions do not depend on being
  150.78 + * able to point info structure members to any of the storage they are
  150.79 + * passed (they make their own copies), EXCEPT that the png_set_text
  150.80 + * functions use the same storage passed to them in the text_ptr or
  150.81 + * itxt_ptr structure argument, and the png_set_rows and png_set_unknowns
  150.82 + * functions do not make their own copies.
  150.83 + */
  150.84 +#ifndef PNGINFO_H
  150.85 +#define PNGINFO_H
  150.86 +
  150.87 +struct png_info_def
  150.88 +{
  150.89 +   /* the following are necessary for every PNG file */
  150.90 +   png_uint_32 width;  /* width of image in pixels (from IHDR) */
  150.91 +   png_uint_32 height; /* height of image in pixels (from IHDR) */
  150.92 +   png_uint_32 valid;  /* valid chunk data (see PNG_INFO_ below) */
  150.93 +   png_size_t rowbytes; /* bytes needed to hold an untransformed row */
  150.94 +   png_colorp palette;      /* array of color values (valid & PNG_INFO_PLTE) */
  150.95 +   png_uint_16 num_palette; /* number of color entries in "palette" (PLTE) */
  150.96 +   png_uint_16 num_trans;   /* number of transparent palette color (tRNS) */
  150.97 +   png_byte bit_depth;      /* 1, 2, 4, 8, or 16 bits/channel (from IHDR) */
  150.98 +   png_byte color_type;     /* see PNG_COLOR_TYPE_ below (from IHDR) */
  150.99 +   /* The following three should have been named *_method not *_type */
 150.100 +   png_byte compression_type; /* must be PNG_COMPRESSION_TYPE_BASE (IHDR) */
 150.101 +   png_byte filter_type;    /* must be PNG_FILTER_TYPE_BASE (from IHDR) */
 150.102 +   png_byte interlace_type; /* One of PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
 150.103 +
 150.104 +   /* The following is informational only on read, and not used on writes. */
 150.105 +   png_byte channels;       /* number of data channels per pixel (1, 2, 3, 4) */
 150.106 +   png_byte pixel_depth;    /* number of bits per pixel */
 150.107 +   png_byte spare_byte;     /* to align the data, and for future use */
 150.108 +   png_byte signature[8];   /* magic bytes read by libpng from start of file */
 150.109 +
 150.110 +   /* The rest of the data is optional.  If you are reading, check the
 150.111 +    * valid field to see if the information in these are valid.  If you
 150.112 +    * are writing, set the valid field to those chunks you want written,
 150.113 +    * and initialize the appropriate fields below.
 150.114 +    */
 150.115 +
 150.116 +#if defined(PNG_gAMA_SUPPORTED)
 150.117 +   /* The gAMA chunk describes the gamma characteristics of the system
 150.118 +    * on which the image was created, normally in the range [1.0, 2.5].
 150.119 +    * Data is valid if (valid & PNG_INFO_gAMA) is non-zero.
 150.120 +    */
 150.121 +   png_fixed_point gamma;
 150.122 +#endif
 150.123 +
 150.124 +#ifdef PNG_sRGB_SUPPORTED
 150.125 +    /* GR-P, 0.96a */
 150.126 +    /* Data valid if (valid & PNG_INFO_sRGB) non-zero. */
 150.127 +   png_byte srgb_intent; /* sRGB rendering intent [0, 1, 2, or 3] */
 150.128 +#endif
 150.129 +
 150.130 +#ifdef PNG_TEXT_SUPPORTED
 150.131 +   /* The tEXt, and zTXt chunks contain human-readable textual data in
 150.132 +    * uncompressed, compressed, and optionally compressed forms, respectively.
 150.133 +    * The data in "text" is an array of pointers to uncompressed,
 150.134 +    * null-terminated C strings. Each chunk has a keyword that describes the
 150.135 +    * textual data contained in that chunk.  Keywords are not required to be
 150.136 +    * unique, and the text string may be empty.  Any number of text chunks may
 150.137 +    * be in an image.
 150.138 +    */
 150.139 +   int num_text; /* number of comments read or comments to write */
 150.140 +   int max_text; /* current size of text array */
 150.141 +   png_textp text; /* array of comments read or comments to write */
 150.142 +#endif /* PNG_TEXT_SUPPORTED */
 150.143 +
 150.144 +#ifdef PNG_tIME_SUPPORTED
 150.145 +   /* The tIME chunk holds the last time the displayed image data was
 150.146 +    * modified.  See the png_time struct for the contents of this struct.
 150.147 +    */
 150.148 +   png_time mod_time;
 150.149 +#endif
 150.150 +
 150.151 +#ifdef PNG_sBIT_SUPPORTED
 150.152 +   /* The sBIT chunk specifies the number of significant high-order bits
 150.153 +    * in the pixel data.  Values are in the range [1, bit_depth], and are
 150.154 +    * only specified for the channels in the pixel data.  The contents of
 150.155 +    * the low-order bits is not specified.  Data is valid if
 150.156 +    * (valid & PNG_INFO_sBIT) is non-zero.
 150.157 +    */
 150.158 +   png_color_8 sig_bit; /* significant bits in color channels */
 150.159 +#endif
 150.160 +
 150.161 +#if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_EXPAND_SUPPORTED) || \
 150.162 +defined(PNG_READ_BACKGROUND_SUPPORTED)
 150.163 +   /* The tRNS chunk supplies transparency data for paletted images and
 150.164 +    * other image types that don't need a full alpha channel.  There are
 150.165 +    * "num_trans" transparency values for a paletted image, stored in the
 150.166 +    * same order as the palette colors, starting from index 0.  Values
 150.167 +    * for the data are in the range [0, 255], ranging from fully transparent
 150.168 +    * to fully opaque, respectively.  For non-paletted images, there is a
 150.169 +    * single color specified that should be treated as fully transparent.
 150.170 +    * Data is valid if (valid & PNG_INFO_tRNS) is non-zero.
 150.171 +    */
 150.172 +   png_bytep trans_alpha;    /* alpha values for paletted image */
 150.173 +   png_color_16 trans_color; /* transparent color for non-palette image */
 150.174 +#endif
 150.175 +
 150.176 +#if defined(PNG_bKGD_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
 150.177 +   /* The bKGD chunk gives the suggested image background color if the
 150.178 +    * display program does not have its own background color and the image
 150.179 +    * is needs to composited onto a background before display.  The colors
 150.180 +    * in "background" are normally in the same color space/depth as the
 150.181 +    * pixel data.  Data is valid if (valid & PNG_INFO_bKGD) is non-zero.
 150.182 +    */
 150.183 +   png_color_16 background;
 150.184 +#endif
 150.185 +
 150.186 +#ifdef PNG_oFFs_SUPPORTED
 150.187 +   /* The oFFs chunk gives the offset in "offset_unit_type" units rightwards
 150.188 +    * and downwards from the top-left corner of the display, page, or other
 150.189 +    * application-specific co-ordinate space.  See the PNG_OFFSET_ defines
 150.190 +    * below for the unit types.  Valid if (valid & PNG_INFO_oFFs) non-zero.
 150.191 +    */
 150.192 +   png_int_32 x_offset; /* x offset on page */
 150.193 +   png_int_32 y_offset; /* y offset on page */
 150.194 +   png_byte offset_unit_type; /* offset units type */
 150.195 +#endif
 150.196 +
 150.197 +#ifdef PNG_pHYs_SUPPORTED
 150.198 +   /* The pHYs chunk gives the physical pixel density of the image for
 150.199 +    * display or printing in "phys_unit_type" units (see PNG_RESOLUTION_
 150.200 +    * defines below).  Data is valid if (valid & PNG_INFO_pHYs) is non-zero.
 150.201 +    */
 150.202 +   png_uint_32 x_pixels_per_unit; /* horizontal pixel density */
 150.203 +   png_uint_32 y_pixels_per_unit; /* vertical pixel density */
 150.204 +   png_byte phys_unit_type; /* resolution type (see PNG_RESOLUTION_ below) */
 150.205 +#endif
 150.206 +
 150.207 +#ifdef PNG_hIST_SUPPORTED
 150.208 +   /* The hIST chunk contains the relative frequency or importance of the
 150.209 +    * various palette entries, so that a viewer can intelligently select a
 150.210 +    * reduced-color palette, if required.  Data is an array of "num_palette"
 150.211 +    * values in the range [0,65535]. Data valid if (valid & PNG_INFO_hIST)
 150.212 +    * is non-zero.
 150.213 +    */
 150.214 +   png_uint_16p hist;
 150.215 +#endif
 150.216 +
 150.217 +#ifdef PNG_cHRM_SUPPORTED
 150.218 +   /* The cHRM chunk describes the CIE color characteristics of the monitor
 150.219 +    * on which the PNG was created.  This data allows the viewer to do gamut
 150.220 +    * mapping of the input image to ensure that the viewer sees the same
 150.221 +    * colors in the image as the creator.  Values are in the range
 150.222 +    * [0.0, 0.8].  Data valid if (valid & PNG_INFO_cHRM) non-zero.
 150.223 +    */
 150.224 +   png_fixed_point x_white;
 150.225 +   png_fixed_point y_white;
 150.226 +   png_fixed_point x_red;
 150.227 +   png_fixed_point y_red;
 150.228 +   png_fixed_point x_green;
 150.229 +   png_fixed_point y_green;
 150.230 +   png_fixed_point x_blue;
 150.231 +   png_fixed_point y_blue;
 150.232 +#endif
 150.233 +
 150.234 +#ifdef PNG_pCAL_SUPPORTED
 150.235 +   /* The pCAL chunk describes a transformation between the stored pixel
 150.236 +    * values and original physical data values used to create the image.
 150.237 +    * The integer range [0, 2^bit_depth - 1] maps to the floating-point
 150.238 +    * range given by [pcal_X0, pcal_X1], and are further transformed by a
 150.239 +    * (possibly non-linear) transformation function given by "pcal_type"
 150.240 +    * and "pcal_params" into "pcal_units".  Please see the PNG_EQUATION_
 150.241 +    * defines below, and the PNG-Group's PNG extensions document for a
 150.242 +    * complete description of the transformations and how they should be
 150.243 +    * implemented, and for a description of the ASCII parameter strings.
 150.244 +    * Data values are valid if (valid & PNG_INFO_pCAL) non-zero.
 150.245 +    */
 150.246 +   png_charp pcal_purpose;  /* pCAL chunk description string */
 150.247 +   png_int_32 pcal_X0;      /* minimum value */
 150.248 +   png_int_32 pcal_X1;      /* maximum value */
 150.249 +   png_charp pcal_units;    /* Latin-1 string giving physical units */
 150.250 +   png_charpp pcal_params;  /* ASCII strings containing parameter values */
 150.251 +   png_byte pcal_type;      /* equation type (see PNG_EQUATION_ below) */
 150.252 +   png_byte pcal_nparams;   /* number of parameters given in pcal_params */
 150.253 +#endif
 150.254 +
 150.255 +/* New members added in libpng-1.0.6 */
 150.256 +   png_uint_32 free_me;     /* flags items libpng is responsible for freeing */
 150.257 +
 150.258 +#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) || \
 150.259 + defined(PNG_HANDLE_AS_UNKNOWN_SUPPORTED)
 150.260 +   /* Storage for unknown chunks that the library doesn't recognize. */
 150.261 +   png_unknown_chunkp unknown_chunks;
 150.262 +   int unknown_chunks_num;
 150.263 +#endif
 150.264 +
 150.265 +#ifdef PNG_iCCP_SUPPORTED
 150.266 +   /* iCCP chunk data. */
 150.267 +   png_charp iccp_name;     /* profile name */
 150.268 +   png_bytep iccp_profile;  /* International Color Consortium profile data */
 150.269 +   png_uint_32 iccp_proflen;  /* ICC profile data length */
 150.270 +   png_byte iccp_compression; /* Always zero */
 150.271 +#endif
 150.272 +
 150.273 +#ifdef PNG_sPLT_SUPPORTED
 150.274 +   /* Data on sPLT chunks (there may be more than one). */
 150.275 +   png_sPLT_tp splt_palettes;
 150.276 +   png_uint_32 splt_palettes_num;
 150.277 +#endif
 150.278 +
 150.279 +#ifdef PNG_sCAL_SUPPORTED
 150.280 +   /* The sCAL chunk describes the actual physical dimensions of the
 150.281 +    * subject matter of the graphic.  The chunk contains a unit specification
 150.282 +    * a byte value, and two ASCII strings representing floating-point
 150.283 +    * values.  The values are width and height corresponsing to one pixel
 150.284 +    * in the image.  Data values are valid if (valid & PNG_INFO_sCAL) is
 150.285 +    * non-zero.
 150.286 +    */
 150.287 +   png_byte scal_unit;         /* unit of physical scale */
 150.288 +   png_charp scal_s_width;     /* string containing height */
 150.289 +   png_charp scal_s_height;    /* string containing width */
 150.290 +#endif
 150.291 +
 150.292 +#ifdef PNG_INFO_IMAGE_SUPPORTED
 150.293 +   /* Memory has been allocated if (valid & PNG_ALLOCATED_INFO_ROWS)
 150.294 +      non-zero */
 150.295 +   /* Data valid if (valid & PNG_INFO_IDAT) non-zero */
 150.296 +   png_bytepp row_pointers;        /* the image bits */
 150.297 +#endif
 150.298 +
 150.299 +};
 150.300 +#endif /* PNGINFO_H */
   151.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   151.2 +++ b/src/share/native/sun/awt/libpng/pnglibconf.h	Tue Oct 04 12:39:42 2011 -0700
   151.3 @@ -0,0 +1,177 @@
   151.4 +/*
   151.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   151.6 + *
   151.7 + * This code is free software; you can redistribute it and/or modify it
   151.8 + * under the terms of the GNU General Public License version 2 only, as
   151.9 + * published by the Free Software Foundation.  Oracle designates this
  151.10 + * particular file as subject to the "Classpath" exception as provided
  151.11 + * by Oracle in the LICENSE file that accompanied this code.
  151.12 + *
  151.13 + * This code is distributed in the hope that it will be useful, but WITHOUT
  151.14 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  151.15 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  151.16 + * version 2 for more details (a copy is included in the LICENSE file that
  151.17 + * accompanied this code).
  151.18 + *
  151.19 + * You should have received a copy of the GNU General Public License version
  151.20 + * 2 along with this work; if not, write to the Free Software Foundation,
  151.21 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  151.22 + *
  151.23 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  151.24 + * or visit www.oracle.com if you need additional information or have any
  151.25 + * questions.
  151.26 + *
  151.27 + * THIS FILE WAS MODIFIED BY ORACLE, INC.
  151.28 + */
  151.29 +
  151.30 +/* libpng STANDARD API DEFINITION */
  151.31 +
  151.32 +/* pnglibconf.h - library build configuration */
  151.33 +
  151.34 +/* This file is available under and governed by the GNU General Public
  151.35 + * License version 2 only, as published by the Free Software Foundation.
  151.36 + * However, the following notice accompanied the original version of this
  151.37 + * file and, per its terms, should not be removed:
  151.38 + */
  151.39 +
  151.40 +/* libpng version 1.5.4 - last changed on June 22, 2011 */
  151.41 +
  151.42 +/* Copyright (c) 1998-2011 Glenn Randers-Pehrson */
  151.43 +
  151.44 +/* This code is released under the libpng license. */
  151.45 +/* For conditions of distribution and use, see the disclaimer */
  151.46 +/* and license in png.h */
  151.47 +
  151.48 +/* pnglibconf.h */
  151.49 +/* Derived from: scripts/pnglibconf.dfa */
  151.50 +/* If you edit this file by hand you must obey the rules expressed in */
  151.51 +/* pnglibconf.dfa with respect to the dependencies between the following */
  151.52 +/* symbols.  It is much better to generate a new file using */
  151.53 +/* scripts/libpngconf.mak */
  151.54 +
  151.55 +#ifndef PNGLCONF_H
  151.56 +#define PNGLCONF_H
  151.57 +/* settings */
  151.58 +#define PNG_API_RULE 0
  151.59 +#define PNG_CALLOC_SUPPORTED
  151.60 +#define PNG_COST_SHIFT 3
  151.61 +#define PNG_DEFAULT_READ_MACROS 1
  151.62 +#define PNG_GAMMA_THRESHOLD_FIXED 5000
  151.63 +#define PNG_MAX_GAMMA_8 11
  151.64 +#define PNG_QUANTIZE_BLUE_BITS 5
  151.65 +#define PNG_QUANTIZE_GREEN_BITS 5
  151.66 +#define PNG_QUANTIZE_RED_BITS 5
  151.67 +#define PNG_sCAL_PRECISION 5
  151.68 +#define PNG_USER_CHUNK_CACHE_MAX 0
  151.69 +#define PNG_USER_CHUNK_MALLOC_MAX 0
  151.70 +#define PNG_USER_HEIGHT_MAX 1000000L
  151.71 +#define PNG_USER_WIDTH_MAX 1000000L
  151.72 +#define PNG_WEIGHT_SHIFT 8
  151.73 +#define PNG_ZBUF_SIZE 8192
  151.74 +/* end of settings */
  151.75 +/* options */
  151.76 +#define PNG_16BIT_SUPPORTED
  151.77 +#define PNG_ALIGN_MEMORY_SUPPORTED
  151.78 +#define PNG_BENIGN_ERRORS_SUPPORTED
  151.79 +#define PNG_bKGD_SUPPORTED
  151.80 +#define PNG_BUILD_GRAYSCALE_PALETTE_SUPPORTED
  151.81 +#define PNG_CHECK_cHRM_SUPPORTED
  151.82 +#define PNG_cHRM_SUPPORTED
  151.83 +#define PNG_CONSOLE_IO_SUPPORTED
  151.84 +#define PNG_CONVERT_tIME_SUPPORTED
  151.85 +#define PNG_EASY_ACCESS_SUPPORTED
  151.86 +/*#undef PNG_ERROR_NUMBERS_SUPPORTED*/
  151.87 +#define PNG_ERROR_TEXT_SUPPORTED
  151.88 +#define PNG_FIXED_POINT_SUPPORTED
  151.89 +#define PNG_FLOATING_ARITHMETIC_SUPPORTED
  151.90 +#define PNG_FLOATING_POINT_SUPPORTED
  151.91 +#define PNG_gAMA_SUPPORTED
  151.92 +#define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  151.93 +#define PNG_hIST_SUPPORTED
  151.94 +#define PNG_iCCP_SUPPORTED
  151.95 +#define PNG_INCH_CONVERSIONS_SUPPORTED
  151.96 +#define PNG_INFO_IMAGE_SUPPORTED
  151.97 +#define PNG_IO_STATE_SUPPORTED
  151.98 +#define PNG_iTXt_SUPPORTED
  151.99 +#define PNG_MNG_FEATURES_SUPPORTED
 151.100 +#define PNG_oFFs_SUPPORTED
 151.101 +#define PNG_pCAL_SUPPORTED
 151.102 +#define PNG_pHYs_SUPPORTED
 151.103 +#define PNG_POINTER_INDEXING_SUPPORTED
 151.104 +#define PNG_PROGRESSIVE_READ_SUPPORTED
 151.105 +#define PNG_READ_16BIT_SUPPORTED
 151.106 +#define PNG_READ_ALPHA_MODE_SUPPORTED
 151.107 +#define PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
 151.108 +#define PNG_READ_BACKGROUND_SUPPORTED
 151.109 +#define PNG_READ_BGR_SUPPORTED
 151.110 +#define PNG_READ_bKGD_SUPPORTED
 151.111 +#define PNG_READ_cHRM_SUPPORTED
 151.112 +#define PNG_READ_COMPOSITE_NODIV_SUPPORTED
 151.113 +#define PNG_READ_COMPRESSED_TEXT_SUPPORTED
 151.114 +#define PNG_READ_EXPAND_16_SUPPORTED
 151.115 +#define PNG_READ_EXPAND_SUPPORTED
 151.116 +#define PNG_READ_FILLER_SUPPORTED
 151.117 +#define PNG_READ_gAMA_SUPPORTED
 151.118 +#define PNG_READ_GAMMA_SUPPORTED
 151.119 +#define PNG_READ_GRAY_TO_RGB_SUPPORTED
 151.120 +#define PNG_READ_hIST_SUPPORTED
 151.121 +#define PNG_READ_iCCP_SUPPORTED
 151.122 +#define PNG_READ_INTERLACING_SUPPORTED
 151.123 +#define PNG_READ_INT_FUNCTIONS_SUPPORTED
 151.124 +#define PNG_READ_INVERT_ALPHA_SUPPORTED
 151.125 +#define PNG_READ_INVERT_SUPPORTED
 151.126 +#define PNG_READ_iTXt_SUPPORTED
 151.127 +#define PNG_READ_oFFs_SUPPORTED
 151.128 +#define PNG_READ_OPT_PLTE_SUPPORTED
 151.129 +#define PNG_READ_PACK_SUPPORTED
 151.130 +#define PNG_READ_PACKSWAP_SUPPORTED
 151.131 +#define PNG_READ_pCAL_SUPPORTED
 151.132 +#define PNG_READ_pHYs_SUPPORTED
 151.133 +#define PNG_READ_QUANTIZE_SUPPORTED
 151.134 +#define PNG_READ_RGB_TO_GRAY_SUPPORTED
 151.135 +#define PNG_READ_sBIT_SUPPORTED
 151.136 +#define PNG_READ_SCALE_16_TO_8_SUPPORTED
 151.137 +#define PNG_READ_sCAL_SUPPORTED
 151.138 +#define PNG_READ_SHIFT_SUPPORTED
 151.139 +#define PNG_READ_sPLT_SUPPORTED
 151.140 +#define PNG_READ_sRGB_SUPPORTED
 151.141 +#define PNG_READ_STRIP_16_TO_8_SUPPORTED
 151.142 +#define PNG_READ_STRIP_ALPHA_SUPPORTED
 151.143 +#define PNG_READ_SUPPORTED
 151.144 +#define PNG_READ_SWAP_ALPHA_SUPPORTED
 151.145 +#define PNG_READ_SWAP_SUPPORTED
 151.146 +#define PNG_READ_tEXt_SUPPORTED
 151.147 +#define PNG_READ_TEXT_SUPPORTED
 151.148 +#define PNG_READ_tIME_SUPPORTED
 151.149 +#define PNG_READ_TRANSFORMS_SUPPORTED
 151.150 +#define PNG_READ_tRNS_SUPPORTED
 151.151 +#define PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
 151.152 +#define PNG_READ_USER_CHUNKS_SUPPORTED
 151.153 +#define PNG_READ_USER_TRANSFORM_SUPPORTED
 151.154 +#define PNG_READ_zTXt_SUPPORTED
 151.155 +#define PNG_SAVE_INT_32_SUPPORTED
 151.156 +#define PNG_sBIT_SUPPORTED
 151.157 +#define PNG_sCAL_SUPPORTED
 151.158 +#define PNG_SEQUENTIAL_READ_SUPPORTED
 151.159 +#define PNG_SET_CHUNK_CACHE_LIMIT_SUPPORTED
 151.160 +#define PNG_SET_CHUNK_MALLOC_LIMIT_SUPPORTED
 151.161 +#define PNG_SETJMP_SUPPORTED
 151.162 +#define PNG_SET_USER_LIMITS_SUPPORTED
 151.163 +#define PNG_sPLT_SUPPORTED
 151.164 +#define PNG_sRGB_SUPPORTED
 151.165 +#define PNG_STDIO_SUPPORTED
 151.166 +#define PNG_tEXt_SUPPORTED
 151.167 +#define PNG_TEXT_SUPPORTED
 151.168 +#define PNG_TIME_RFC1123_SUPPORTED
 151.169 +#define PNG_tIME_SUPPORTED
 151.170 +#define PNG_tRNS_SUPPORTED
 151.171 +#define PNG_UNKNOWN_CHUNKS_SUPPORTED
 151.172 +#define PNG_USER_CHUNKS_SUPPORTED
 151.173 +#define PNG_USER_LIMITS_SUPPORTED
 151.174 +#define PNG_USER_MEM_SUPPORTED
 151.175 +#define PNG_USER_TRANSFORM_INFO_SUPPORTED
 151.176 +#define PNG_USER_TRANSFORM_PTR_SUPPORTED
 151.177 +#define PNG_WARNINGS_SUPPORTED
 151.178 +#define PNG_zTXt_SUPPORTED
 151.179 +/* end of options */
 151.180 +#endif /* PNGLCONF_H */
   152.1 --- a/src/share/native/sun/awt/libpng/pngmem.c	Fri Sep 30 17:20:56 2011 -0700
   152.2 +++ b/src/share/native/sun/awt/libpng/pngmem.c	Tue Oct 04 12:39:42 2011 -0700
   152.3 @@ -29,12 +29,15 @@
   152.4   * However, the following notice accompanied the original version of this
   152.5   * file and, per its terms, should not be removed:
   152.6   *
   152.7 - * Last changed in libpng 1.2.13 November 13, 2006
   152.8 - * For conditions of distribution and use, see copyright notice in png.h
   152.9 - * Copyright (c) 1998-2006 Glenn Randers-Pehrson
  152.10 + * Last changed in libpng 1.5.4 [July 7, 2011]
  152.11 + * Copyright (c) 1998-2011 Glenn Randers-Pehrson
  152.12   * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
  152.13   * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
  152.14   *
  152.15 + * This code is released under the libpng license.
  152.16 + * For conditions of distribution and use, see the disclaimer
  152.17 + * and license in png.h
  152.18 + *
  152.19   * This file provides a location for all memory allocation.  Users who
  152.20   * need special memory handling are expected to supply replacement
  152.21   * functions for png_malloc() and png_free(), and to use
  152.22 @@ -42,52 +45,56 @@
  152.23   * identify the replacement functions.
  152.24   */
  152.25  
  152.26 -#define PNG_INTERNAL
  152.27 -#include "png.h"
  152.28 +#include "pngpriv.h"
  152.29  
  152.30  #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  152.31  
  152.32  /* Borland DOS special memory handler */
  152.33  #if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
  152.34 -/* if you change this, be sure to change the one in png.h also */
  152.35 +/* If you change this, be sure to change the one in png.h also */
  152.36  
  152.37  /* Allocate memory for a png_struct.  The malloc and memset can be replaced
  152.38     by a single call to calloc() if this is thought to improve performance. */
  152.39 -png_voidp /* PRIVATE */
  152.40 -png_create_struct(int type)
  152.41 +PNG_FUNCTION(png_voidp /* PRIVATE */,
  152.42 +png_create_struct,(int type),PNG_ALLOCATED)
  152.43  {
  152.44 -#ifdef PNG_USER_MEM_SUPPORTED
  152.45 -   return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL));
  152.46 +#  ifdef PNG_USER_MEM_SUPPORTED
  152.47 +   return (png_create_struct_2(type, NULL, NULL));
  152.48  }
  152.49  
  152.50  /* Alternate version of png_create_struct, for use with user-defined malloc. */
  152.51 -png_voidp /* PRIVATE */
  152.52 -png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
  152.53 +PNG_FUNCTION(png_voidp /* PRIVATE */,
  152.54 +png_create_struct_2,(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr),
  152.55 +   PNG_ALLOCATED)
  152.56  {
  152.57 -#endif /* PNG_USER_MEM_SUPPORTED */
  152.58 +#  endif /* PNG_USER_MEM_SUPPORTED */
  152.59     png_size_t size;
  152.60     png_voidp struct_ptr;
  152.61  
  152.62     if (type == PNG_STRUCT_INFO)
  152.63 -     size = png_sizeof(png_info);
  152.64 +      size = png_sizeof(png_info);
  152.65 +
  152.66     else if (type == PNG_STRUCT_PNG)
  152.67 -     size = png_sizeof(png_struct);
  152.68 +      size = png_sizeof(png_struct);
  152.69 +
  152.70     else
  152.71 -     return (png_get_copyright(NULL));
  152.72 +      return (png_get_copyright(NULL));
  152.73  
  152.74 -#ifdef PNG_USER_MEM_SUPPORTED
  152.75 -   if(malloc_fn != NULL)
  152.76 +#  ifdef PNG_USER_MEM_SUPPORTED
  152.77 +   if (malloc_fn != NULL)
  152.78     {
  152.79        png_struct dummy_struct;
  152.80        png_structp png_ptr = &dummy_struct;
  152.81        png_ptr->mem_ptr=mem_ptr;
  152.82        struct_ptr = (*(malloc_fn))(png_ptr, (png_uint_32)size);
  152.83     }
  152.84 +
  152.85     else
  152.86 -#endif /* PNG_USER_MEM_SUPPORTED */
  152.87 -      struct_ptr = (png_voidp)farmalloc(size);
  152.88 +#  endif /* PNG_USER_MEM_SUPPORTED */
  152.89 +   struct_ptr = (png_voidp)farmalloc(size);
  152.90     if (struct_ptr != NULL)
  152.91        png_memset(struct_ptr, 0, size);
  152.92 +
  152.93     return (struct_ptr);
  152.94  }
  152.95  
  152.96 @@ -95,8 +102,8 @@
  152.97  void /* PRIVATE */
  152.98  png_destroy_struct(png_voidp struct_ptr)
  152.99  {
 152.100 -#ifdef PNG_USER_MEM_SUPPORTED
 152.101 -   png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL);
 152.102 +#  ifdef PNG_USER_MEM_SUPPORTED
 152.103 +   png_destroy_struct_2(struct_ptr, NULL, NULL);
 152.104  }
 152.105  
 152.106  /* Free memory allocated by a png_create_struct() call */
 152.107 @@ -104,11 +111,11 @@
 152.108  png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
 152.109      png_voidp mem_ptr)
 152.110  {
 152.111 -#endif
 152.112 +#  endif
 152.113     if (struct_ptr != NULL)
 152.114     {
 152.115 -#ifdef PNG_USER_MEM_SUPPORTED
 152.116 -      if(free_fn != NULL)
 152.117 +#  ifdef PNG_USER_MEM_SUPPORTED
 152.118 +      if (free_fn != NULL)
 152.119        {
 152.120           png_struct dummy_struct;
 152.121           png_structp png_ptr = &dummy_struct;
 152.122 @@ -116,7 +123,8 @@
 152.123           (*(free_fn))(png_ptr, struct_ptr);
 152.124           return;
 152.125        }
 152.126 -#endif /* PNG_USER_MEM_SUPPORTED */
 152.127 +
 152.128 +#  endif /* PNG_USER_MEM_SUPPORTED */
 152.129        farfree (struct_ptr);
 152.130     }
 152.131  }
 152.132 @@ -140,58 +148,76 @@
 152.133   * result, we would be truncating potentially larger memory requests
 152.134   * (which should cause a fatal error) and introducing major problems.
 152.135   */
 152.136 +PNG_FUNCTION(png_voidp,PNGAPI
 152.137 +png_calloc,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED)
 152.138 +{
 152.139 +   png_voidp ret;
 152.140  
 152.141 -png_voidp PNGAPI
 152.142 -png_malloc(png_structp png_ptr, png_uint_32 size)
 152.143 +   ret = (png_malloc(png_ptr, size));
 152.144 +
 152.145 +   if (ret != NULL)
 152.146 +      png_memset(ret,0,(png_size_t)size);
 152.147 +
 152.148 +   return (ret);
 152.149 +}
 152.150 +
 152.151 +PNG_FUNCTION(png_voidp,PNGAPI
 152.152 +png_malloc,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED)
 152.153  {
 152.154     png_voidp ret;
 152.155  
 152.156     if (png_ptr == NULL || size == 0)
 152.157        return (NULL);
 152.158  
 152.159 -#ifdef PNG_USER_MEM_SUPPORTED
 152.160 -   if(png_ptr->malloc_fn != NULL)
 152.161 -       ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
 152.162 +#  ifdef PNG_USER_MEM_SUPPORTED
 152.163 +   if (png_ptr->malloc_fn != NULL)
 152.164 +      ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
 152.165 +
 152.166     else
 152.167 -       ret = (png_malloc_default(png_ptr, size));
 152.168 +      ret = (png_malloc_default(png_ptr, size));
 152.169 +
 152.170     if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
 152.171 -       png_error(png_ptr, "Out of memory!");
 152.172 +       png_error(png_ptr, "Out of memory");
 152.173 +
 152.174     return (ret);
 152.175  }
 152.176  
 152.177 -png_voidp PNGAPI
 152.178 -png_malloc_default(png_structp png_ptr, png_uint_32 size)
 152.179 +PNG_FUNCTION(png_voidp,PNGAPI
 152.180 +png_malloc_default,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED)
 152.181  {
 152.182     png_voidp ret;
 152.183 -#endif /* PNG_USER_MEM_SUPPORTED */
 152.184 +#  endif /* PNG_USER_MEM_SUPPORTED */
 152.185  
 152.186     if (png_ptr == NULL || size == 0)
 152.187        return (NULL);
 152.188  
 152.189 -#ifdef PNG_MAX_MALLOC_64K
 152.190 +#  ifdef PNG_MAX_MALLOC_64K
 152.191     if (size > (png_uint_32)65536L)
 152.192     {
 152.193        png_warning(png_ptr, "Cannot Allocate > 64K");
 152.194        ret = NULL;
 152.195     }
 152.196 +
 152.197     else
 152.198 -#endif
 152.199 +#  endif
 152.200  
 152.201     if (size != (size_t)size)
 152.202 -     ret = NULL;
 152.203 +      ret = NULL;
 152.204 +
 152.205     else if (size == (png_uint_32)65536L)
 152.206     {
 152.207        if (png_ptr->offset_table == NULL)
 152.208        {
 152.209 -         /* try to see if we need to do any of this fancy stuff */
 152.210 +         /* Try to see if we need to do any of this fancy stuff */
 152.211           ret = farmalloc(size);
 152.212           if (ret == NULL || ((png_size_t)ret & 0xffff))
 152.213           {
 152.214              int num_blocks;
 152.215              png_uint_32 total_size;
 152.216              png_bytep table;
 152.217 -            int i;
 152.218 +            int i, mem_level, window_bits;
 152.219              png_byte huge * hptr;
 152.220 +            int window_bits
 152.221  
 152.222              if (ret != NULL)
 152.223              {
 152.224 @@ -199,12 +225,23 @@
 152.225                 ret = NULL;
 152.226              }
 152.227  
 152.228 -            if(png_ptr->zlib_window_bits > 14)
 152.229 -               num_blocks = (int)(1 << (png_ptr->zlib_window_bits - 14));
 152.230 +            window_bits =
 152.231 +                png_ptr->zlib_window_bits >= png_ptr->zlib_text_window_bits ?
 152.232 +                png_ptr->zlib_window_bits : png_ptr->zlib_text_window_bits;
 152.233 +
 152.234 +            if (window_bits > 14)
 152.235 +               num_blocks = (int)(1 << (window_bits - 14));
 152.236 +
 152.237              else
 152.238                 num_blocks = 1;
 152.239 -            if (png_ptr->zlib_mem_level >= 7)
 152.240 -               num_blocks += (int)(1 << (png_ptr->zlib_mem_level - 7));
 152.241 +
 152.242 +            mem_level =
 152.243 +                png_ptr->zlib_mem_level >= png_ptr->zlib_text_mem_level ?
 152.244 +                png_ptr->zlib_mem_level : png_ptr->zlib_text_mem_level;
 152.245 +
 152.246 +            if (mem_level >= 7)
 152.247 +               num_blocks += (int)(1 << (mem_level - 7));
 152.248 +
 152.249              else
 152.250                 num_blocks++;
 152.251  
 152.252 @@ -214,40 +251,43 @@
 152.253  
 152.254              if (table == NULL)
 152.255              {
 152.256 -#ifndef PNG_USER_MEM_SUPPORTED
 152.257 +#  ifndef PNG_USER_MEM_SUPPORTED
 152.258                 if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
 152.259 -                  png_error(png_ptr, "Out Of Memory."); /* Note "O" and "M" */
 152.260 +                  png_error(png_ptr, "Out Of Memory"); /* Note "O", "M" */
 152.261 +
 152.262                 else
 152.263 -                  png_warning(png_ptr, "Out Of Memory.");
 152.264 -#endif
 152.265 +                  png_warning(png_ptr, "Out Of Memory");
 152.266 +#  endif
 152.267                 return (NULL);
 152.268              }
 152.269  
 152.270              if ((png_size_t)table & 0xfff0)
 152.271              {
 152.272 -#ifndef PNG_USER_MEM_SUPPORTED
 152.273 +#  ifndef PNG_USER_MEM_SUPPORTED
 152.274                 if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
 152.275                    png_error(png_ptr,
 152.276                      "Farmalloc didn't return normalized pointer");
 152.277 +
 152.278                 else
 152.279                    png_warning(png_ptr,
 152.280                      "Farmalloc didn't return normalized pointer");
 152.281 -#endif
 152.282 +#  endif
 152.283                 return (NULL);
 152.284              }
 152.285  
 152.286              png_ptr->offset_table = table;
 152.287              png_ptr->offset_table_ptr = farmalloc(num_blocks *
 152.288 -               png_sizeof (png_bytep));
 152.289 +               png_sizeof(png_bytep));
 152.290  
 152.291              if (png_ptr->offset_table_ptr == NULL)
 152.292              {
 152.293 -#ifndef PNG_USER_MEM_SUPPORTED
 152.294 +#  ifndef PNG_USER_MEM_SUPPORTED
 152.295                 if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
 152.296 -                  png_error(png_ptr, "Out Of memory."); /* Note "O" and "M" */
 152.297 +                  png_error(png_ptr, "Out Of memory"); /* Note "O", "m" */
 152.298 +
 152.299                 else
 152.300 -                  png_warning(png_ptr, "Out Of memory.");
 152.301 -#endif
 152.302 +                  png_warning(png_ptr, "Out Of memory");
 152.303 +#  endif
 152.304                 return (NULL);
 152.305              }
 152.306  
 152.307 @@ -257,6 +297,7 @@
 152.308                 hptr = (png_byte huge *)((long)(hptr) & 0xfffffff0L);
 152.309                 hptr = hptr + 16L;  /* "hptr += 16L" fails on Turbo C++ 3.0 */
 152.310              }
 152.311 +
 152.312              for (i = 0; i < num_blocks; i++)
 152.313              {
 152.314                 png_ptr->offset_table_ptr[i] = (png_bytep)hptr;
 152.315 @@ -271,57 +312,64 @@
 152.316  
 152.317        if (png_ptr->offset_table_count >= png_ptr->offset_table_number)
 152.318        {
 152.319 -#ifndef PNG_USER_MEM_SUPPORTED
 152.320 +#  ifndef PNG_USER_MEM_SUPPORTED
 152.321           if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
 152.322 -            png_error(png_ptr, "Out of Memory."); /* Note "o" and "M" */
 152.323 +            png_error(png_ptr, "Out of Memory"); /* Note "O" and "M" */
 152.324 +
 152.325           else
 152.326 -            png_warning(png_ptr, "Out of Memory.");
 152.327 -#endif
 152.328 +            png_warning(png_ptr, "Out of Memory");
 152.329 +#  endif
 152.330           return (NULL);
 152.331        }
 152.332  
 152.333        ret = png_ptr->offset_table_ptr[png_ptr->offset_table_count++];
 152.334     }
 152.335 +
 152.336     else
 152.337        ret = farmalloc(size);
 152.338  
 152.339 -#ifndef PNG_USER_MEM_SUPPORTED
 152.340 +#  ifndef PNG_USER_MEM_SUPPORTED
 152.341     if (ret == NULL)
 152.342     {
 152.343        if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
 152.344 -         png_error(png_ptr, "Out of memory."); /* Note "o" and "m" */
 152.345 +         png_error(png_ptr, "Out of memory"); /* Note "o" and "m" */
 152.346 +
 152.347        else
 152.348 -         png_warning(png_ptr, "Out of memory."); /* Note "o" and "m" */
 152.349 +         png_warning(png_ptr, "Out of memory"); /* Note "o" and "m" */
 152.350     }
 152.351 -#endif
 152.352 +#  endif
 152.353  
 152.354     return (ret);
 152.355  }
 152.356  
 152.357 -/* free a pointer allocated by png_malloc().  In the default
 152.358 -   configuration, png_ptr is not used, but is passed in case it
 152.359 -   is needed.  If ptr is NULL, return without taking any action. */
 152.360 +/* Free a pointer allocated by png_malloc().  In the default
 152.361 + * configuration, png_ptr is not used, but is passed in case it
 152.362 + * is needed.  If ptr is NULL, return without taking any action.
 152.363 + */
 152.364  void PNGAPI
 152.365  png_free(png_structp png_ptr, png_voidp ptr)
 152.366  {
 152.367     if (png_ptr == NULL || ptr == NULL)
 152.368        return;
 152.369  
 152.370 -#ifdef PNG_USER_MEM_SUPPORTED
 152.371 +#  ifdef PNG_USER_MEM_SUPPORTED
 152.372     if (png_ptr->free_fn != NULL)
 152.373     {
 152.374        (*(png_ptr->free_fn))(png_ptr, ptr);
 152.375        return;
 152.376     }
 152.377 -   else png_free_default(png_ptr, ptr);
 152.378 +
 152.379 +   else
 152.380 +      png_free_default(png_ptr, ptr);
 152.381  }
 152.382  
 152.383  void PNGAPI
 152.384  png_free_default(png_structp png_ptr, png_voidp ptr)
 152.385  {
 152.386 -#endif /* PNG_USER_MEM_SUPPORTED */
 152.387 +#  endif /* PNG_USER_MEM_SUPPORTED */
 152.388  
 152.389 -   if(png_ptr == NULL) return;
 152.390 +   if (png_ptr == NULL || ptr == NULL)
 152.391 +      return;
 152.392  
 152.393     if (png_ptr->offset_table != NULL)
 152.394     {
 152.395 @@ -346,9 +394,7 @@
 152.396     }
 152.397  
 152.398     if (ptr != NULL)
 152.399 -   {
 152.400        farfree(ptr);
 152.401 -   }
 152.402  }
 152.403  
 152.404  #else /* Not the Borland DOS special memory handler */
 152.405 @@ -356,52 +402,58 @@
 152.406  /* Allocate memory for a png_struct or a png_info.  The malloc and
 152.407     memset can be replaced by a single call to calloc() if this is thought
 152.408     to improve performance noticably. */
 152.409 -png_voidp /* PRIVATE */
 152.410 -png_create_struct(int type)
 152.411 +PNG_FUNCTION(png_voidp /* PRIVATE */,
 152.412 +png_create_struct,(int type),PNG_ALLOCATED)
 152.413  {
 152.414 -#ifdef PNG_USER_MEM_SUPPORTED
 152.415 -   return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL));
 152.416 +#  ifdef PNG_USER_MEM_SUPPORTED
 152.417 +   return (png_create_struct_2(type, NULL, NULL));
 152.418  }
 152.419  
 152.420  /* Allocate memory for a png_struct or a png_info.  The malloc and
 152.421     memset can be replaced by a single call to calloc() if this is thought
 152.422     to improve performance noticably. */
 152.423 -png_voidp /* PRIVATE */
 152.424 -png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
 152.425 +PNG_FUNCTION(png_voidp /* PRIVATE */,
 152.426 +png_create_struct_2,(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr),
 152.427 +   PNG_ALLOCATED)
 152.428  {
 152.429 -#endif /* PNG_USER_MEM_SUPPORTED */
 152.430 +#  endif /* PNG_USER_MEM_SUPPORTED */
 152.431     png_size_t size;
 152.432     png_voidp struct_ptr;
 152.433  
 152.434     if (type == PNG_STRUCT_INFO)
 152.435        size = png_sizeof(png_info);
 152.436 +
 152.437     else if (type == PNG_STRUCT_PNG)
 152.438        size = png_sizeof(png_struct);
 152.439 +
 152.440     else
 152.441        return (NULL);
 152.442  
 152.443 -#ifdef PNG_USER_MEM_SUPPORTED
 152.444 -   if(malloc_fn != NULL)
 152.445 +#  ifdef PNG_USER_MEM_SUPPORTED
 152.446 +   if (malloc_fn != NULL)
 152.447     {
 152.448        png_struct dummy_struct;
 152.449        png_structp png_ptr = &dummy_struct;
 152.450        png_ptr->mem_ptr=mem_ptr;
 152.451        struct_ptr = (*(malloc_fn))(png_ptr, size);
 152.452 +
 152.453        if (struct_ptr != NULL)
 152.454           png_memset(struct_ptr, 0, size);
 152.455 +
 152.456        return (struct_ptr);
 152.457     }
 152.458 -#endif /* PNG_USER_MEM_SUPPORTED */
 152.459 +#  endif /* PNG_USER_MEM_SUPPORTED */
 152.460  
 152.461 -#if defined(__TURBOC__) && !defined(__FLAT__)
 152.462 +#  if defined(__TURBOC__) && !defined(__FLAT__)
 152.463     struct_ptr = (png_voidp)farmalloc(size);
 152.464 -#else
 152.465 -# if defined(_MSC_VER) && defined(MAXSEG_64K)
 152.466 -   struct_ptr = (png_voidp)halloc(size,1);
 152.467 -# else
 152.468 +#  else
 152.469 +#    if defined(_MSC_VER) && defined(MAXSEG_64K)
 152.470 +   struct_ptr = (png_voidp)halloc(size, 1);
 152.471 +#    else
 152.472     struct_ptr = (png_voidp)malloc(size);
 152.473 -# endif
 152.474 -#endif
 152.475 +#    endif
 152.476 +#  endif
 152.477 +
 152.478     if (struct_ptr != NULL)
 152.479        png_memset(struct_ptr, 0, size);
 152.480  
 152.481 @@ -413,8 +465,8 @@
 152.482  void /* PRIVATE */
 152.483  png_destroy_struct(png_voidp struct_ptr)
 152.484  {
 152.485 -#ifdef PNG_USER_MEM_SUPPORTED
 152.486 -   png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL);
 152.487 +#  ifdef PNG_USER_MEM_SUPPORTED
 152.488 +   png_destroy_struct_2(struct_ptr, NULL, NULL);
 152.489  }
 152.490  
 152.491  /* Free memory allocated by a png_create_struct() call */
 152.492 @@ -422,11 +474,11 @@
 152.493  png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
 152.494      png_voidp mem_ptr)
 152.495  {
 152.496 -#endif /* PNG_USER_MEM_SUPPORTED */
 152.497 +#  endif /* PNG_USER_MEM_SUPPORTED */
 152.498     if (struct_ptr != NULL)
 152.499     {
 152.500 -#ifdef PNG_USER_MEM_SUPPORTED
 152.501 -      if(free_fn != NULL)
 152.502 +#  ifdef PNG_USER_MEM_SUPPORTED
 152.503 +      if (free_fn != NULL)
 152.504        {
 152.505           png_struct dummy_struct;
 152.506           png_structp png_ptr = &dummy_struct;
 152.507 @@ -434,178 +486,182 @@
 152.508           (*(free_fn))(png_ptr, struct_ptr);
 152.509           return;
 152.510        }
 152.511 -#endif /* PNG_USER_MEM_SUPPORTED */
 152.512 -#if defined(__TURBOC__) && !defined(__FLAT__)
 152.513 +#  endif /* PNG_USER_MEM_SUPPORTED */
 152.514 +#  if defined(__TURBOC__) && !defined(__FLAT__)
 152.515        farfree(struct_ptr);
 152.516 -#else
 152.517 -# if defined(_MSC_VER) && defined(MAXSEG_64K)
 152.518 +
 152.519 +#  else
 152.520 +#    if defined(_MSC_VER) && defined(MAXSEG_64K)
 152.521        hfree(struct_ptr);
 152.522 -# else
 152.523 +
 152.524 +#    else
 152.525        free(struct_ptr);
 152.526 -# endif
 152.527 -#endif
 152.528 +
 152.529 +#    endif
 152.530 +#  endif
 152.531     }
 152.532  }
 152.533  
 152.534  /* Allocate memory.  For reasonable files, size should never exceed
 152.535 -   64K.  However, zlib may allocate more then 64K if you don't tell
 152.536 -   it not to.  See zconf.h and png.h for more information.  zlib does
 152.537 -   need to allocate exactly 64K, so whatever you call here must
 152.538 -   have the ability to do that. */
 152.539 + * 64K.  However, zlib may allocate more then 64K if you don't tell
 152.540 + * it not to.  See zconf.h and png.h for more information.  zlib does
 152.541 + * need to allocate exactly 64K, so whatever you call here must
 152.542 + * have the ability to do that.
 152.543 + */
 152.544  
 152.545 -png_voidp PNGAPI
 152.546 -png_malloc(png_structp png_ptr, png_uint_32 size)
 152.547 +PNG_FUNCTION(png_voidp,PNGAPI
 152.548 +png_calloc,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED)
 152.549  {
 152.550     png_voidp ret;
 152.551  
 152.552 -#ifdef PNG_USER_MEM_SUPPORTED
 152.553 +   ret = (png_malloc(png_ptr, size));
 152.554 +
 152.555 +   if (ret != NULL)
 152.556 +      png_memset(ret,0,(png_size_t)size);
 152.557 +
 152.558 +   return (ret);
 152.559 +}
 152.560 +
 152.561 +PNG_FUNCTION(png_voidp,PNGAPI
 152.562 +png_malloc,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED)
 152.563 +{
 152.564 +   png_voidp ret;
 152.565 +
 152.566 +#  ifdef PNG_USER_MEM_SUPPORTED
 152.567     if (png_ptr == NULL || size == 0)
 152.568        return (NULL);
 152.569  
 152.570 -   if(png_ptr->malloc_fn != NULL)
 152.571 -       ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
 152.572 +   if (png_ptr->malloc_fn != NULL)
 152.573 +      ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
 152.574 +
 152.575     else
 152.576 -       ret = (png_malloc_default(png_ptr, size));
 152.577 +      ret = (png_malloc_default(png_ptr, size));
 152.578 +
 152.579     if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
 152.580 -       png_error(png_ptr, "Out of Memory!");
 152.581 +       png_error(png_ptr, "Out of Memory");
 152.582 +
 152.583     return (ret);
 152.584  }
 152.585  
 152.586 -png_voidp PNGAPI
 152.587 -png_malloc_default(png_structp png_ptr, png_uint_32 size)
 152.588 +PNG_FUNCTION(png_voidp,PNGAPI
 152.589 +png_malloc_default,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED)
 152.590  {
 152.591     png_voidp ret;
 152.592 -#endif /* PNG_USER_MEM_SUPPORTED */
 152.593 +#  endif /* PNG_USER_MEM_SUPPORTED */
 152.594  
 152.595     if (png_ptr == NULL || size == 0)
 152.596        return (NULL);
 152.597  
 152.598 -#ifdef PNG_MAX_MALLOC_64K
 152.599 +#  ifdef PNG_MAX_MALLOC_64K
 152.600     if (size > (png_uint_32)65536L)
 152.601     {
 152.602 -#ifndef PNG_USER_MEM_SUPPORTED
 152.603 -      if(png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
 152.604 +#    ifndef PNG_USER_MEM_SUPPORTED
 152.605 +      if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
 152.606           png_error(png_ptr, "Cannot Allocate > 64K");
 152.607 +
 152.608        else
 152.609 -#endif
 152.610 +#    endif
 152.611           return NULL;
 152.612     }
 152.613 -#endif
 152.614 +#  endif
 152.615  
 152.616 - /* Check for overflow */
 152.617 -#if defined(__TURBOC__) && !defined(__FLAT__)
 152.618 - if (size != (unsigned long)size)
 152.619 -   ret = NULL;
 152.620 - else
 152.621 -   ret = farmalloc(size);
 152.622 -#else
 152.623 -# if defined(_MSC_VER) && defined(MAXSEG_64K)
 152.624 - if (size != (unsigned long)size)
 152.625 -   ret = NULL;
 152.626 - else
 152.627 -   ret = halloc(size, 1);
 152.628 -# else
 152.629 - if (size != (size_t)size)
 152.630 -   ret = NULL;
 152.631 - else
 152.632 -   ret = malloc((size_t)size);
 152.633 -# endif
 152.634 -#endif
 152.635 +   /* Check for overflow */
 152.636 +#  if defined(__TURBOC__) && !defined(__FLAT__)
 152.637  
 152.638 -#ifndef PNG_USER_MEM_SUPPORTED
 152.639 +   if (size != (unsigned long)size)
 152.640 +      ret = NULL;
 152.641 +
 152.642 +   else
 152.643 +      ret = farmalloc(size);
 152.644 +
 152.645 +#  else
 152.646 +#    if defined(_MSC_VER) && defined(MAXSEG_64K)
 152.647 +   if (size != (unsigned long)size)
 152.648 +      ret = NULL;
 152.649 +
 152.650 +   else
 152.651 +      ret = halloc(size, 1);
 152.652 +
 152.653 +#    else
 152.654 +   if (size != (size_t)size)
 152.655 +      ret = NULL;
 152.656 +
 152.657 +   else
 152.658 +      ret = malloc((size_t)size);
 152.659 +#    endif
 152.660 +#  endif
 152.661 +
 152.662 +#  ifndef PNG_USER_MEM_SUPPORTED
 152.663     if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
 152.664        png_error(png_ptr, "Out of Memory");
 152.665 -#endif
 152.666 +#  endif
 152.667  
 152.668     return (ret);
 152.669  }
 152.670  
 152.671  /* Free a pointer allocated by png_malloc().  If ptr is NULL, return
 152.672 -   without taking any action. */
 152.673 + * without taking any action.
 152.674 + */
 152.675  void PNGAPI
 152.676  png_free(png_structp png_ptr, png_voidp ptr)
 152.677  {
 152.678     if (png_ptr == NULL || ptr == NULL)
 152.679        return;
 152.680  
 152.681 -#ifdef PNG_USER_MEM_SUPPORTED
 152.682 +#  ifdef PNG_USER_MEM_SUPPORTED
 152.683     if (png_ptr->free_fn != NULL)
 152.684     {
 152.685        (*(png_ptr->free_fn))(png_ptr, ptr);
 152.686        return;
 152.687     }
 152.688 -   else png_free_default(png_ptr, ptr);
 152.689 +
 152.690 +   else
 152.691 +      png_free_default(png_ptr, ptr);
 152.692  }
 152.693 +
 152.694  void PNGAPI
 152.695  png_free_default(png_structp png_ptr, png_voidp ptr)
 152.696  {
 152.697     if (png_ptr == NULL || ptr == NULL)
 152.698        return;
 152.699  
 152.700 -#endif /* PNG_USER_MEM_SUPPORTED */
 152.701 +#  endif /* PNG_USER_MEM_SUPPORTED */
 152.702  
 152.703 -#if defined(__TURBOC__) && !defined(__FLAT__)
 152.704 +#  if defined(__TURBOC__) && !defined(__FLAT__)
 152.705     farfree(ptr);
 152.706 -#else
 152.707 -# if defined(_MSC_VER) && defined(MAXSEG_64K)
 152.708 +
 152.709 +#  else
 152.710 +#    if defined(_MSC_VER) && defined(MAXSEG_64K)
 152.711     hfree(ptr);
 152.712 -# else
 152.713 +
 152.714 +#    else
 152.715     free(ptr);
 152.716 -# endif
 152.717 -#endif
 152.718 +
 152.719 +#    endif
 152.720 +#  endif
 152.721  }
 152.722 -
 152.723  #endif /* Not Borland DOS special memory handler */
 152.724  
 152.725 -#if defined(PNG_1_0_X)
 152.726 -#  define png_malloc_warn png_malloc
 152.727 -#else
 152.728  /* This function was added at libpng version 1.2.3.  The png_malloc_warn()
 152.729   * function will set up png_malloc() to issue a png_warning and return NULL
 152.730   * instead of issuing a png_error, if it fails to allocate the requested
 152.731   * memory.
 152.732   */
 152.733 -png_voidp PNGAPI
 152.734 -png_malloc_warn(png_structp png_ptr, png_uint_32 size)
 152.735 +PNG_FUNCTION(png_voidp,PNGAPI
 152.736 +png_malloc_warn,(png_structp png_ptr, png_alloc_size_t size),PNG_ALLOCATED)
 152.737  {
 152.738     png_voidp ptr;
 152.739     png_uint_32 save_flags;
 152.740 -   if(png_ptr == NULL) return (NULL);
 152.741 +   if (png_ptr == NULL)
 152.742 +      return (NULL);
 152.743  
 152.744 -   save_flags=png_ptr->flags;
 152.745 +   save_flags = png_ptr->flags;
 152.746     png_ptr->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
 152.747     ptr = (png_voidp)png_malloc((png_structp)png_ptr, size);
 152.748     png_ptr->flags=save_flags;
 152.749     return(ptr);
 152.750  }
 152.751 -#endif
 152.752  
 152.753 -png_voidp PNGAPI
 152.754 -png_memcpy_check (png_structp png_ptr, png_voidp s1, png_voidp s2,
 152.755 -   png_uint_32 length)
 152.756 -{
 152.757 -   png_size_t size;
 152.758 -
 152.759 -   size = (png_size_t)length;
 152.760 -   if ((png_uint_32)size != length)
 152.761 -      png_error(png_ptr,"Overflow in png_memcpy_check.");
 152.762 -
 152.763 -   return(png_memcpy (s1, s2, size));
 152.764 -}
 152.765 -
 152.766 -png_voidp PNGAPI
 152.767 -png_memset_check (png_structp png_ptr, png_voidp s1, int value,
 152.768 -   png_uint_32 length)
 152.769 -{
 152.770 -   png_size_t size;
 152.771 -
 152.772 -   size = (png_size_t)length;
 152.773 -   if ((png_uint_32)size != length)
 152.774 -      png_error(png_ptr,"Overflow in png_memset_check.");
 152.775 -
 152.776 -   return (png_memset (s1, value, size));
 152.777 -
 152.778 -}
 152.779  
 152.780  #ifdef PNG_USER_MEM_SUPPORTED
 152.781  /* This function is called when the application wants to use another method
 152.782 @@ -615,10 +671,11 @@
 152.783  png_set_mem_fn(png_structp png_ptr, png_voidp mem_ptr, png_malloc_ptr
 152.784    malloc_fn, png_free_ptr free_fn)
 152.785  {
 152.786 -   if(png_ptr != NULL) {
 152.787 -   png_ptr->mem_ptr = mem_ptr;
 152.788 -   png_ptr->malloc_fn = malloc_fn;
 152.789 -   png_ptr->free_fn = free_fn;
 152.790 +   if (png_ptr != NULL)
 152.791 +   {
 152.792 +      png_ptr->mem_ptr = mem_ptr;
 152.793 +      png_ptr->malloc_fn = malloc_fn;
 152.794 +      png_ptr->free_fn = free_fn;
 152.795     }
 152.796  }
 152.797  
 152.798 @@ -627,9 +684,11 @@
 152.799   * pointer before png_write_destroy and png_read_destroy are called.
 152.800   */
 152.801  png_voidp PNGAPI
 152.802 -png_get_mem_ptr(png_structp png_ptr)
 152.803 +png_get_mem_ptr(png_const_structp png_ptr)
 152.804  {
 152.805 -   if(png_ptr == NULL) return (NULL);
 152.806 +   if (png_ptr == NULL)
 152.807 +      return (NULL);
 152.808 +
 152.809     return ((png_voidp)png_ptr->mem_ptr);
 152.810  }
 152.811  #endif /* PNG_USER_MEM_SUPPORTED */
   153.1 --- a/src/share/native/sun/awt/libpng/pngpread.c	Fri Sep 30 17:20:56 2011 -0700
   153.2 +++ b/src/share/native/sun/awt/libpng/pngpread.c	Tue Oct 04 12:39:42 2011 -0700
   153.3 @@ -29,19 +29,21 @@
   153.4   * However, the following notice accompanied the original version of this
   153.5   * file and, per its terms, should not be removed:
   153.6   *
   153.7 - * Last changed in libpng 1.2.17 May 15, 2007
   153.8 - * For conditions of distribution and use, see copyright notice in png.h
   153.9 - * Copyright (c) 1998-2007 Glenn Randers-Pehrson
  153.10 + * Last changed in libpng 1.5.2 [March 31, 2011]
  153.11 + * Copyright (c) 1998-2011 Glenn Randers-Pehrson
  153.12   * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
  153.13   * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
  153.14 + *
  153.15 + * This code is released under the libpng license.
  153.16 + * For conditions of distribution and use, see the disclaimer
  153.17 + * and license in png.h
  153.18   */
  153.19  
  153.20 -#define PNG_INTERNAL
  153.21 -#include "png.h"
  153.22 +#include "pngpriv.h"
  153.23  
  153.24  #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  153.25  
  153.26 -/* push model modes */
  153.27 +/* Push model modes */
  153.28  #define PNG_READ_SIG_MODE   0
  153.29  #define PNG_READ_CHUNK_MODE 1
  153.30  #define PNG_READ_IDAT_MODE  2
  153.31 @@ -54,9 +56,11 @@
  153.32  
  153.33  void PNGAPI
  153.34  png_process_data(png_structp png_ptr, png_infop info_ptr,
  153.35 -   png_bytep buffer, png_size_t buffer_size)
  153.36 +    png_bytep buffer, png_size_t buffer_size)
  153.37  {
  153.38 -   if(png_ptr == NULL) return;
  153.39 +   if (png_ptr == NULL || info_ptr == NULL)
  153.40 +      return;
  153.41 +
  153.42     png_push_restore_buffer(png_ptr, buffer, buffer_size);
  153.43  
  153.44     while (png_ptr->buffer_size)
  153.45 @@ -65,13 +69,73 @@
  153.46     }
  153.47  }
  153.48  
  153.49 +png_size_t PNGAPI
  153.50 +png_process_data_pause(png_structp png_ptr, int save)
  153.51 +{
  153.52 +   if (png_ptr != NULL)
  153.53 +   {
  153.54 +      /* It's easiest for the caller if we do the save, then the caller doesn't
  153.55 +       * have to supply the same data again:
  153.56 +       */
  153.57 +      if (save)
  153.58 +         png_push_save_buffer(png_ptr);
  153.59 +      else
  153.60 +      {
  153.61 +         /* This includes any pending saved bytes: */
  153.62 +         png_size_t remaining = png_ptr->buffer_size;
  153.63 +         png_ptr->buffer_size = 0;
  153.64 +
  153.65 +         /* So subtract the saved buffer size, unless all the data
  153.66 +          * is actually 'saved', in which case we just return 0
  153.67 +          */
  153.68 +         if (png_ptr->save_buffer_size < remaining)
  153.69 +            return remaining - png_ptr->save_buffer_size;
  153.70 +      }
  153.71 +   }
  153.72 +
  153.73 +   return 0;
  153.74 +}
  153.75 +
  153.76 +png_uint_32 PNGAPI
  153.77 +png_process_data_skip(png_structp png_ptr)
  153.78 +{
  153.79 +   png_uint_32 remaining = 0;
  153.80 +
  153.81 +   if (png_ptr != NULL && png_ptr->process_mode == PNG_SKIP_MODE &&
  153.82 +      png_ptr->skip_length > 0)
  153.83 +   {
  153.84 +      /* At the end of png_process_data the buffer size must be 0 (see the loop
  153.85 +       * above) so we can detect a broken call here:
  153.86 +       */
  153.87 +      if (png_ptr->buffer_size != 0)
  153.88 +         png_error(png_ptr,
  153.89 +            "png_process_data_skip called inside png_process_data");
  153.90 +
  153.91 +      /* If is impossible for there to be a saved buffer at this point -
  153.92 +       * otherwise we could not be in SKIP mode.  This will also happen if
  153.93 +       * png_process_skip is called inside png_process_data (but only very
  153.94 +       * rarely.)
  153.95 +       */
  153.96 +      if (png_ptr->save_buffer_size != 0)
  153.97 +         png_error(png_ptr, "png_process_data_skip called with saved data");
  153.98 +
  153.99 +      remaining = png_ptr->skip_length;
 153.100 +      png_ptr->skip_length = 0;
 153.101 +      png_ptr->process_mode = PNG_READ_CHUNK_MODE;
 153.102 +   }
 153.103 +
 153.104 +   return remaining;
 153.105 +}
 153.106 +
 153.107  /* What we do with the incoming data depends on what we were previously
 153.108   * doing before we ran out of data...
 153.109   */
 153.110  void /* PRIVATE */
 153.111  png_process_some_data(png_structp png_ptr, png_infop info_ptr)
 153.112  {
 153.113 -   if(png_ptr == NULL) return;
 153.114 +   if (png_ptr == NULL)
 153.115 +      return;
 153.116 +
 153.117     switch (png_ptr->process_mode)
 153.118     {
 153.119        case PNG_READ_SIG_MODE:
 153.120 @@ -79,42 +143,49 @@
 153.121           png_push_read_sig(png_ptr, info_ptr);
 153.122           break;
 153.123        }
 153.124 +
 153.125        case PNG_READ_CHUNK_MODE:
 153.126        {
 153.127           png_push_read_chunk(png_ptr, info_ptr);
 153.128           break;
 153.129        }
 153.130 +
 153.131        case PNG_READ_IDAT_MODE:
 153.132        {
 153.133           png_push_read_IDAT(png_ptr);
 153.134           break;
 153.135        }
 153.136 -#if defined(PNG_READ_tEXt_SUPPORTED)
 153.137 +
 153.138 +#ifdef PNG_READ_tEXt_SUPPORTED
 153.139        case PNG_READ_tEXt_MODE:
 153.140        {
 153.141           png_push_read_tEXt(png_ptr, info_ptr);
 153.142           break;
 153.143        }
 153.144 +
 153.145  #endif
 153.146 -#if defined(PNG_READ_zTXt_SUPPORTED)
 153.147 +#ifdef PNG_READ_zTXt_SUPPORTED
 153.148        case PNG_READ_zTXt_MODE:
 153.149        {
 153.150           png_push_read_zTXt(png_ptr, info_ptr);
 153.151           break;
 153.152        }
 153.153 +
 153.154  #endif
 153.155 -#if defined(PNG_READ_iTXt_SUPPORTED)
 153.156 +#ifdef PNG_READ_iTXt_SUPPORTED
 153.157        case PNG_READ_iTXt_MODE:
 153.158        {
 153.159           png_push_read_iTXt(png_ptr, info_ptr);
 153.160           break;
 153.161        }
 153.162 +
 153.163  #endif
 153.164        case PNG_SKIP_MODE:
 153.165        {
 153.166           png_push_crc_finish(png_ptr);
 153.167           break;
 153.168        }
 153.169 +
 153.170        default:
 153.171        {
 153.172           png_ptr->buffer_size = 0;
 153.173 @@ -141,14 +212,15 @@
 153.174     }
 153.175  
 153.176     png_push_fill_buffer(png_ptr, &(info_ptr->signature[num_checked]),
 153.177 -      num_to_check);
 153.178 -   png_ptr->sig_bytes = (png_byte)(png_ptr->sig_bytes+num_to_check);
 153.179 +       num_to_check);
 153.180 +   png_ptr->sig_bytes = (png_byte)(png_ptr->sig_bytes + num_to_check);
 153.181  
 153.182     if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
 153.183     {
 153.184        if (num_checked < 4 &&
 153.185            png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
 153.186           png_error(png_ptr, "Not a PNG file");
 153.187 +
 153.188        else
 153.189           png_error(png_ptr, "PNG file corrupted by ASCII conversion");
 153.190     }
 153.191 @@ -164,63 +236,62 @@
 153.192  void /* PRIVATE */
 153.193  png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
 153.194  {
 153.195 -#ifdef PNG_USE_LOCAL_ARRAYS
 153.196        PNG_IHDR;
 153.197        PNG_IDAT;
 153.198        PNG_IEND;
 153.199        PNG_PLTE;
 153.200 -#if defined(PNG_READ_bKGD_SUPPORTED)
 153.201 +#ifdef PNG_READ_bKGD_SUPPORTED
 153.202        PNG_bKGD;
 153.203  #endif
 153.204 -#if defined(PNG_READ_cHRM_SUPPORTED)
 153.205 +#ifdef PNG_READ_cHRM_SUPPORTED
 153.206        PNG_cHRM;
 153.207  #endif
 153.208 -#if defined(PNG_READ_gAMA_SUPPORTED)
 153.209 +#ifdef PNG_READ_gAMA_SUPPORTED
 153.210        PNG_gAMA;
 153.211  #endif
 153.212 -#if defined(PNG_READ_hIST_SUPPORTED)
 153.213 +#ifdef PNG_READ_hIST_SUPPORTED
 153.214        PNG_hIST;
 153.215  #endif
 153.216 -#if defined(PNG_READ_iCCP_SUPPORTED)
 153.217 +#ifdef PNG_READ_iCCP_SUPPORTED
 153.218        PNG_iCCP;
 153.219  #endif
 153.220 -#if defined(PNG_READ_iTXt_SUPPORTED)
 153.221 +#ifdef PNG_READ_iTXt_SUPPORTED
 153.222        PNG_iTXt;
 153.223  #endif
 153.224 -#if defined(PNG_READ_oFFs_SUPPORTED)
 153.225 +#ifdef PNG_READ_oFFs_SUPPORTED
 153.226        PNG_oFFs;
 153.227  #endif
 153.228 -#if defined(PNG_READ_pCAL_SUPPORTED)
 153.229 +#ifdef PNG_READ_pCAL_SUPPORTED
 153.230        PNG_pCAL;
 153.231  #endif
 153.232 -#if defined(PNG_READ_pHYs_SUPPORTED)
 153.233 +#ifdef PNG_READ_pHYs_SUPPORTED
 153.234        PNG_pHYs;
 153.235  #endif
 153.236 -#if defined(PNG_READ_sBIT_SUPPORTED)
 153.237 +#ifdef PNG_READ_sBIT_SUPPORTED
 153.238        PNG_sBIT;
 153.239  #endif
 153.240 -#if defined(PNG_READ_sCAL_SUPPORTED)
 153.241 +#ifdef PNG_READ_sCAL_SUPPORTED
 153.242        PNG_sCAL;
 153.243  #endif
 153.244 -#if defined(PNG_READ_sRGB_SUPPORTED)
 153.245 +#ifdef PNG_READ_sRGB_SUPPORTED
 153.246        PNG_sRGB;
 153.247  #endif
 153.248 -#if defined(PNG_READ_sPLT_SUPPORTED)
 153.249 +#ifdef PNG_READ_sPLT_SUPPORTED
 153.250        PNG_sPLT;
 153.251  #endif
 153.252 -#if defined(PNG_READ_tEXt_SUPPORTED)
 153.253 +#ifdef PNG_READ_tEXt_SUPPORTED
 153.254        PNG_tEXt;
 153.255  #endif
 153.256 -#if defined(PNG_READ_tIME_SUPPORTED)
 153.257 +#ifdef PNG_READ_tIME_SUPPORTED
 153.258        PNG_tIME;
 153.259  #endif
 153.260 -#if defined(PNG_READ_tRNS_SUPPORTED)
 153.261 +#ifdef PNG_READ_tRNS_SUPPORTED
 153.262        PNG_tRNS;
 153.263  #endif
 153.264 -#if defined(PNG_READ_zTXt_SUPPORTED)
 153.265 +#ifdef PNG_READ_zTXt_SUPPORTED
 153.266        PNG_zTXt;
 153.267  #endif
 153.268 -#endif /* PNG_USE_LOCAL_ARRAYS */
 153.269 +
 153.270     /* First we make sure we have enough data for the 4 byte chunk name
 153.271      * and the 4 byte chunk length before proceeding with decoding the
 153.272      * chunk data.  To fully decode each of these chunks, we also make
 153.273 @@ -238,25 +309,31 @@
 153.274        }
 153.275  
 153.276        png_push_fill_buffer(png_ptr, chunk_length, 4);
 153.277 -      png_ptr->push_length = png_get_uint_31(png_ptr,chunk_length);
 153.278 +      png_ptr->push_length = png_get_uint_31(png_ptr, chunk_length);
 153.279        png_reset_crc(png_ptr);
 153.280        png_crc_read(png_ptr, png_ptr->chunk_name, 4);
 153.281 +      png_check_chunk_name(png_ptr, png_ptr->chunk_name);
 153.282        png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
 153.283     }
 153.284  
 153.285 -   if (!png_memcmp(png_ptr->chunk_name, (png_bytep)png_IDAT, 4))
 153.286 -     if(png_ptr->mode & PNG_AFTER_IDAT)
 153.287 -        png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
 153.288 +   if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
 153.289 +      if (png_ptr->mode & PNG_AFTER_IDAT)
 153.290 +         png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
 153.291  
 153.292     if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
 153.293     {
 153.294 +      if (png_ptr->push_length != 13)
 153.295 +         png_error(png_ptr, "Invalid IHDR length");
 153.296 +
 153.297        if (png_ptr->push_length + 4 > png_ptr->buffer_size)
 153.298        {
 153.299           png_push_save_buffer(png_ptr);
 153.300           return;
 153.301        }
 153.302 +
 153.303        png_handle_IHDR(png_ptr, info_ptr, png_ptr->push_length);
 153.304     }
 153.305 +
 153.306     else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
 153.307     {
 153.308        if (png_ptr->push_length + 4 > png_ptr->buffer_size)
 153.309 @@ -264,11 +341,13 @@
 153.310           png_push_save_buffer(png_ptr);
 153.311           return;
 153.312        }
 153.313 +
 153.314        png_handle_IEND(png_ptr, info_ptr, png_ptr->push_length);
 153.315  
 153.316        png_ptr->process_mode = PNG_READ_DONE_MODE;
 153.317        png_push_have_end(png_ptr, info_ptr);
 153.318     }
 153.319 +
 153.320  #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
 153.321     else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
 153.322     {
 153.323 @@ -277,20 +356,26 @@
 153.324           png_push_save_buffer(png_ptr);
 153.325           return;
 153.326        }
 153.327 +
 153.328        if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
 153.329           png_ptr->mode |= PNG_HAVE_IDAT;
 153.330 +
 153.331        png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
 153.332 +
 153.333        if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
 153.334           png_ptr->mode |= PNG_HAVE_PLTE;
 153.335 +
 153.336        else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
 153.337        {
 153.338           if (!(png_ptr->mode & PNG_HAVE_IHDR))
 153.339              png_error(png_ptr, "Missing IHDR before IDAT");
 153.340 +
 153.341           else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
 153.342 -                  !(png_ptr->mode & PNG_HAVE_PLTE))
 153.343 +             !(png_ptr->mode & PNG_HAVE_PLTE))
 153.344              png_error(png_ptr, "Missing PLTE before IDAT");
 153.345        }
 153.346     }
 153.347 +
 153.348  #endif
 153.349     else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
 153.350     {
 153.351 @@ -301,37 +386,43 @@
 153.352        }
 153.353        png_handle_PLTE(png_ptr, info_ptr, png_ptr->push_length);
 153.354     }
 153.355 -   else if (!png_memcmp(png_ptr->chunk_name, (png_bytep)png_IDAT, 4))
 153.356 +
 153.357 +   else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
 153.358     {
 153.359        /* If we reach an IDAT chunk, this means we have read all of the
 153.360         * header chunks, and we can start reading the image (or if this
 153.361         * is called after the image has been read - we have an error).
 153.362         */
 153.363 -     if (!(png_ptr->mode & PNG_HAVE_IHDR))
 153.364 -       png_error(png_ptr, "Missing IHDR before IDAT");
 153.365 -     else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
 153.366 -         !(png_ptr->mode & PNG_HAVE_PLTE))
 153.367 -       png_error(png_ptr, "Missing PLTE before IDAT");
 153.368 +
 153.369 +      if (!(png_ptr->mode & PNG_HAVE_IHDR))
 153.370 +         png_error(png_ptr, "Missing IHDR before IDAT");
 153.371 +
 153.372 +      else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
 153.373 +          !(png_ptr->mode & PNG_HAVE_PLTE))
 153.374 +         png_error(png_ptr, "Missing PLTE before IDAT");
 153.375  
 153.376        if (png_ptr->mode & PNG_HAVE_IDAT)
 153.377        {
 153.378           if (!(png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
 153.379 -           if (png_ptr->push_length == 0)
 153.380 -              return;
 153.381 +            if (png_ptr->push_length == 0)
 153.382 +               return;
 153.383  
 153.384           if (png_ptr->mode & PNG_AFTER_IDAT)
 153.385 -            png_error(png_ptr, "Too many IDAT's found");
 153.386 +            png_benign_error(png_ptr, "Too many IDATs found");
 153.387        }
 153.388  
 153.389        png_ptr->idat_size = png_ptr->push_length;
 153.390        png_ptr->mode |= PNG_HAVE_IDAT;
 153.391        png_ptr->process_mode = PNG_READ_IDAT_MODE;
 153.392        png_push_have_info(png_ptr, info_ptr);
 153.393 -      png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
 153.394 +      png_ptr->zstream.avail_out =
 153.395 +          (uInt) PNG_ROWBYTES(png_ptr->pixel_depth,
 153.396 +          png_ptr->iwidth) + 1;
 153.397        png_ptr->zstream.next_out = png_ptr->row_buf;
 153.398        return;
 153.399     }
 153.400 -#if defined(PNG_READ_gAMA_SUPPORTED)
 153.401 +
 153.402 +#ifdef PNG_READ_gAMA_SUPPORTED
 153.403     else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
 153.404     {
 153.405        if (png_ptr->push_length + 4 > png_ptr->buffer_size)
 153.406 @@ -339,10 +430,12 @@
 153.407           png_push_save_buffer(png_ptr);
 153.408           return;
 153.409        }
 153.410 +
 153.411        png_handle_gAMA(png_ptr, info_ptr, png_ptr->push_length);
 153.412     }
 153.413 +
 153.414  #endif
 153.415 -#if defined(PNG_READ_sBIT_SUPPORTED)
 153.416 +#ifdef PNG_READ_sBIT_SUPPORTED
 153.417     else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
 153.418     {
 153.419        if (png_ptr->push_length + 4 > png_ptr->buffer_size)
 153.420 @@ -350,10 +443,12 @@
 153.421           png_push_save_buffer(png_ptr);
 153.422           return;
 153.423        }
 153.424 +
 153.425        png_handle_sBIT(png_ptr, info_ptr, png_ptr->push_length);
 153.426     }
 153.427 +
 153.428  #endif
 153.429 -#if defined(PNG_READ_cHRM_SUPPORTED)
 153.430 +#ifdef PNG_READ_cHRM_SUPPORTED
 153.431     else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
 153.432     {
 153.433        if (png_ptr->push_length + 4 > png_ptr->buffer_size)
 153.434 @@ -361,10 +456,12 @@
 153.435           png_push_save_buffer(png_ptr);
 153.436           return;
 153.437        }
 153.438 +
 153.439        png_handle_cHRM(png_ptr, info_ptr, png_ptr->push_length);
 153.440     }
 153.441 +
 153.442  #endif
 153.443 -#if defined(PNG_READ_sRGB_SUPPORTED)
 153.444 +#ifdef PNG_READ_sRGB_SUPPORTED
 153.445     else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
 153.446     {
 153.447        if (png_ptr->push_length + 4 > png_ptr->buffer_size)
 153.448 @@ -372,10 +469,12 @@
 153.449           png_push_save_buffer(png_ptr);
 153.450           return;
 153.451        }
 153.452 +
 153.453        png_handle_sRGB(png_ptr, info_ptr, png_ptr->push_length);
 153.454     }
 153.455 +
 153.456  #endif
 153.457 -#if defined(PNG_READ_iCCP_SUPPORTED)
 153.458 +#ifdef PNG_READ_iCCP_SUPPORTED
 153.459     else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
 153.460     {
 153.461        if (png_ptr->push_length + 4 > png_ptr->buffer_size)
 153.462 @@ -383,10 +482,12 @@
 153.463           png_push_save_buffer(png_ptr);
 153.464           return;
 153.465        }
 153.466 +
 153.467        png_handle_iCCP(png_ptr, info_ptr, png_ptr->push_length);
 153.468     }
 153.469 +
 153.470  #endif
 153.471 -#if defined(PNG_READ_sPLT_SUPPORTED)
 153.472 +#ifdef PNG_READ_sPLT_SUPPORTED
 153.473     else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
 153.474     {
 153.475        if (png_ptr->push_length + 4 > png_ptr->buffer_size)
 153.476 @@ -394,10 +495,12 @@
 153.477           png_push_save_buffer(png_ptr);
 153.478           return;
 153.479        }
 153.480 +
 153.481        png_handle_sPLT(png_ptr, info_ptr, png_ptr->push_length);
 153.482     }
 153.483 +
 153.484  #endif
 153.485 -#if defined(PNG_READ_tRNS_SUPPORTED)
 153.486 +#ifdef PNG_READ_tRNS_SUPPORTED
 153.487     else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
 153.488     {
 153.489        if (png_ptr->push_length + 4 > png_ptr->buffer_size)
 153.490 @@ -405,10 +508,12 @@
 153.491           png_push_save_buffer(png_ptr);
 153.492           return;
 153.493        }
 153.494 +
 153.495        png_handle_tRNS(png_ptr, info_ptr, png_ptr->push_length);
 153.496     }
 153.497 +
 153.498  #endif
 153.499 -#if defined(PNG_READ_bKGD_SUPPORTED)
 153.500 +#ifdef PNG_READ_bKGD_SUPPORTED
 153.501     else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
 153.502     {
 153.503        if (png_ptr->push_length + 4 > png_ptr->buffer_size)
 153.504 @@ -416,10 +521,12 @@
 153.505           png_push_save_buffer(png_ptr);
 153.506           return;
 153.507        }
 153.508 +
 153.509        png_handle_bKGD(png_ptr, info_ptr, png_ptr->push_length);
 153.510     }
 153.511 +
 153.512  #endif
 153.513 -#if defined(PNG_READ_hIST_SUPPORTED)
 153.514 +#ifdef PNG_READ_hIST_SUPPORTED
 153.515     else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
 153.516     {
 153.517        if (png_ptr->push_length + 4 > png_ptr->buffer_size)
 153.518 @@ -427,10 +534,12 @@
 153.519           png_push_save_buffer(png_ptr);
 153.520           return;
 153.521        }
 153.522 +
 153.523        png_handle_hIST(png_ptr, info_ptr, png_ptr->push_length);
 153.524     }
 153.525 +
 153.526  #endif
 153.527 -#if defined(PNG_READ_pHYs_SUPPORTED)
 153.528 +#ifdef PNG_READ_pHYs_SUPPORTED
 153.529     else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
 153.530     {
 153.531        if (png_ptr->push_length + 4 > png_ptr->buffer_size)
 153.532 @@ -438,10 +547,12 @@
 153.533           png_push_save_buffer(png_ptr);
 153.534           return;
 153.535        }
 153.536 +
 153.537        png_handle_pHYs(png_ptr, info_ptr, png_ptr->push_length);
 153.538     }
 153.539 +
 153.540  #endif
 153.541 -#if defined(PNG_READ_oFFs_SUPPORTED)
 153.542 +#ifdef PNG_READ_oFFs_SUPPORTED
 153.543     else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
 153.544     {
 153.545        if (png_ptr->push_length + 4 > png_ptr->buffer_size)
 153.546 @@ -449,10 +560,12 @@
 153.547           png_push_save_buffer(png_ptr);
 153.548           return;
 153.549        }
 153.550 +
 153.551        png_handle_oFFs(png_ptr, info_ptr, png_ptr->push_length);
 153.552     }
 153.553  #endif
 153.554 -#if defined(PNG_READ_pCAL_SUPPORTED)
 153.555 +
 153.556 +#ifdef PNG_READ_pCAL_SUPPORTED
 153.557     else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
 153.558     {
 153.559        if (png_ptr->push_length + 4 > png_ptr->buffer_size)
 153.560 @@ -460,10 +573,12 @@
 153.561           png_push_save_buffer(png_ptr);
 153.562           return;
 153.563        }
 153.564 +
 153.565        png_handle_pCAL(png_ptr, info_ptr, png_ptr->push_length);
 153.566     }
 153.567 +
 153.568  #endif
 153.569 -#if defined(PNG_READ_sCAL_SUPPORTED)
 153.570 +#ifdef PNG_READ_sCAL_SUPPORTED
 153.571     else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
 153.572     {
 153.573        if (png_ptr->push_length + 4 > png_ptr->buffer_size)
 153.574 @@ -471,10 +586,12 @@
 153.575           png_push_save_buffer(png_ptr);
 153.576           return;
 153.577        }
 153.578 +
 153.579        png_handle_sCAL(png_ptr, info_ptr, png_ptr->push_length);
 153.580     }
 153.581 +
 153.582  #endif
 153.583 -#if defined(PNG_READ_tIME_SUPPORTED)
 153.584 +#ifdef PNG_READ_tIME_SUPPORTED
 153.585     else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
 153.586     {
 153.587        if (png_ptr->push_length + 4 > png_ptr->buffer_size)
 153.588 @@ -482,10 +599,12 @@
 153.589           png_push_save_buffer(png_ptr);
 153.590           return;
 153.591        }
 153.592 +
 153.593        png_handle_tIME(png_ptr, info_ptr, png_ptr->push_length);
 153.594     }
 153.595 +
 153.596  #endif
 153.597 -#if defined(PNG_READ_tEXt_SUPPORTED)
 153.598 +#ifdef PNG_READ_tEXt_SUPPORTED
 153.599     else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
 153.600     {
 153.601        if (png_ptr->push_length + 4 > png_ptr->buffer_size)
 153.602 @@ -493,10 +612,12 @@
 153.603           png_push_save_buffer(png_ptr);
 153.604           return;
 153.605        }
 153.606 +
 153.607        png_push_handle_tEXt(png_ptr, info_ptr, png_ptr->push_length);
 153.608     }
 153.609 +
 153.610  #endif
 153.611 -#if defined(PNG_READ_zTXt_SUPPORTED)
 153.612 +#ifdef PNG_READ_zTXt_SUPPORTED
 153.613     else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
 153.614     {
 153.615        if (png_ptr->push_length + 4 > png_ptr->buffer_size)
 153.616 @@ -504,10 +625,12 @@
 153.617           png_push_save_buffer(png_ptr);
 153.618           return;
 153.619        }
 153.620 +
 153.621        png_push_handle_zTXt(png_ptr, info_ptr, png_ptr->push_length);
 153.622     }
 153.623 +
 153.624  #endif
 153.625 -#if defined(PNG_READ_iTXt_SUPPORTED)
 153.626 +#ifdef PNG_READ_iTXt_SUPPORTED
 153.627     else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
 153.628     {
 153.629        if (png_ptr->push_length + 4 > png_ptr->buffer_size)
 153.630 @@ -515,8 +638,10 @@
 153.631           png_push_save_buffer(png_ptr);
 153.632           return;
 153.633        }
 153.634 +
 153.635        png_push_handle_iTXt(png_ptr, info_ptr, png_ptr->push_length);
 153.636     }
 153.637 +
 153.638  #endif
 153.639     else
 153.640     {
 153.641 @@ -543,32 +668,45 @@
 153.642  {
 153.643     if (png_ptr->skip_length && png_ptr->save_buffer_size)
 153.644     {
 153.645 -      png_size_t save_size;
 153.646 +      png_size_t save_size = png_ptr->save_buffer_size;
 153.647 +      png_uint_32 skip_length = png_ptr->skip_length;
 153.648  
 153.649 -      if (png_ptr->skip_length < (png_uint_32)png_ptr->save_buffer_size)
 153.650 -         save_size = (png_size_t)png_ptr->skip_length;
 153.651 +      /* We want the smaller of 'skip_length' and 'save_buffer_size', but
 153.652 +       * they are of different types and we don't know which variable has the
 153.653 +       * fewest bits.  Carefully select the smaller and cast it to the type of
 153.654 +       * the larger - this cannot overflow.  Do not cast in the following test
 153.655 +       * - it will break on either 16 or 64 bit platforms.
 153.656 +       */
 153.657 +      if (skip_length < save_size)
 153.658 +         save_size = (png_size_t)skip_length;
 153.659 +
 153.660        else
 153.661 -         save_size = png_ptr->save_buffer_size;
 153.662 +         skip_length = (png_uint_32)save_size;
 153.663  
 153.664        png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
 153.665  
 153.666 -      png_ptr->skip_length -= save_size;
 153.667 +      png_ptr->skip_length -= skip_length;
 153.668        png_ptr->buffer_size -= save_size;
 153.669        png_ptr->save_buffer_size -= save_size;
 153.670        png_ptr->save_buffer_ptr += save_size;
 153.671     }
 153.672     if (png_ptr->skip_length && png_ptr->current_buffer_size)
 153.673     {
 153.674 -      png_size_t save_size;
 153.675 +      png_size_t save_size = png_ptr->current_buffer_size;
 153.676 +      png_uint_32 skip_length = png_ptr->skip_length;
 153.677  
 153.678 -      if (png_ptr->skip_length < (png_uint_32)png_ptr->current_buffer_size)
 153.679 -         save_size = (png_size_t)png_ptr->skip_length;
 153.680 +      /* We want the smaller of 'skip_length' and 'current_buffer_size', here,
 153.681 +       * the same problem exists as above and the same solution.
 153.682 +       */
 153.683 +      if (skip_length < save_size)
 153.684 +         save_size = (png_size_t)skip_length;
 153.685 +
 153.686        else
 153.687 -         save_size = png_ptr->current_buffer_size;
 153.688 +         skip_length = (png_uint_32)save_size;
 153.689  
 153.690        png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
 153.691  
 153.692 -      png_ptr->skip_length -= save_size;
 153.693 +      png_ptr->skip_length -= skip_length;
 153.694        png_ptr->buffer_size -= save_size;
 153.695        png_ptr->current_buffer_size -= save_size;
 153.696        png_ptr->current_buffer_ptr += save_size;
 153.697 @@ -586,12 +724,14 @@
 153.698     }
 153.699  }
 153.700  
 153.701 -void PNGAPI
 153.702 +void PNGCBAPI
 153.703  png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length)
 153.704  {
 153.705     png_bytep ptr;
 153.706  
 153.707 -   if(png_ptr == NULL) return;
 153.708 +   if (png_ptr == NULL)
 153.709 +      return;
 153.710 +
 153.711     ptr = buffer;
 153.712     if (png_ptr->save_buffer_size)
 153.713     {
 153.714 @@ -599,6 +739,7 @@
 153.715  
 153.716        if (length < png_ptr->save_buffer_size)
 153.717           save_size = length;
 153.718 +
 153.719        else
 153.720           save_size = png_ptr->save_buffer_size;
 153.721  
 153.722 @@ -615,6 +756,7 @@
 153.723  
 153.724        if (length < png_ptr->current_buffer_size)
 153.725           save_size = length;
 153.726 +
 153.727        else
 153.728           save_size = png_ptr->current_buffer_size;
 153.729  
 153.730 @@ -632,33 +774,41 @@
 153.731     {
 153.732        if (png_ptr->save_buffer_ptr != png_ptr->save_buffer)
 153.733        {
 153.734 -         png_size_t i,istop;
 153.735 +         png_size_t i, istop;
 153.736           png_bytep sp;
 153.737           png_bytep dp;
 153.738  
 153.739           istop = png_ptr->save_buffer_size;
 153.740           for (i = 0, sp = png_ptr->save_buffer_ptr, dp = png_ptr->save_buffer;
 153.741 -            i < istop; i++, sp++, dp++)
 153.742 +             i < istop; i++, sp++, dp++)
 153.743           {
 153.744              *dp = *sp;
 153.745           }
 153.746        }
 153.747     }
 153.748     if (png_ptr->save_buffer_size + png_ptr->current_buffer_size >
 153.749 -      png_ptr->save_buffer_max)
 153.750 +       png_ptr->save_buffer_max)
 153.751     {
 153.752        png_size_t new_max;
 153.753        png_bytep old_buffer;
 153.754  
 153.755        if (png_ptr->save_buffer_size > PNG_SIZE_MAX -
 153.756 -         (png_ptr->current_buffer_size + 256))
 153.757 +          (png_ptr->current_buffer_size + 256))
 153.758        {
 153.759 -        png_error(png_ptr, "Potential overflow of save_buffer");
 153.760 +         png_error(png_ptr, "Potential overflow of save_buffer");
 153.761        }
 153.762 +
 153.763        new_max = png_ptr->save_buffer_size + png_ptr->current_buffer_size + 256;
 153.764        old_buffer = png_ptr->save_buffer;
 153.765 -      png_ptr->save_buffer = (png_bytep)png_malloc(png_ptr,
 153.766 -         (png_uint_32)new_max);
 153.767 +      png_ptr->save_buffer = (png_bytep)png_malloc_warn(png_ptr,
 153.768 +          (png_size_t)new_max);
 153.769 +
 153.770 +      if (png_ptr->save_buffer == NULL)
 153.771 +      {
 153.772 +         png_free(png_ptr, old_buffer);
 153.773 +         png_error(png_ptr, "Insufficient memory for save_buffer");
 153.774 +      }
 153.775 +
 153.776        png_memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size);
 153.777        png_free(png_ptr, old_buffer);
 153.778        png_ptr->save_buffer_max = new_max;
 153.779 @@ -687,9 +837,7 @@
 153.780  void /* PRIVATE */
 153.781  png_push_read_IDAT(png_structp png_ptr)
 153.782  {
 153.783 -#ifdef PNG_USE_LOCAL_ARRAYS
 153.784     PNG_IDAT;
 153.785 -#endif
 153.786     if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
 153.787     {
 153.788        png_byte chunk_length[4];
 153.789 @@ -701,16 +849,18 @@
 153.790        }
 153.791  
 153.792        png_push_fill_buffer(png_ptr, chunk_length, 4);
 153.793 -      png_ptr->push_length = png_get_uint_31(png_ptr,chunk_length);
 153.794 +      png_ptr->push_length = png_get_uint_31(png_ptr, chunk_length);
 153.795        png_reset_crc(png_ptr);
 153.796        png_crc_read(png_ptr, png_ptr->chunk_name, 4);
 153.797        png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
 153.798  
 153.799 -      if (png_memcmp(png_ptr->chunk_name, (png_bytep)png_IDAT, 4))
 153.800 +      if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
 153.801        {
 153.802           png_ptr->process_mode = PNG_READ_CHUNK_MODE;
 153.803 +
 153.804           if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
 153.805              png_error(png_ptr, "Not enough compressed data");
 153.806 +
 153.807           return;
 153.808        }
 153.809  
 153.810 @@ -718,45 +868,52 @@
 153.811     }
 153.812     if (png_ptr->idat_size && png_ptr->save_buffer_size)
 153.813     {
 153.814 -      png_size_t save_size;
 153.815 +      png_size_t save_size = png_ptr->save_buffer_size;
 153.816 +      png_uint_32 idat_size = png_ptr->idat_size;
 153.817  
 153.818 -      if (png_ptr->idat_size < (png_uint_32)png_ptr->save_buffer_size)
 153.819 -      {
 153.820 -         save_size = (png_size_t)png_ptr->idat_size;
 153.821 -         /* check for overflow */
 153.822 -         if((png_uint_32)save_size != png_ptr->idat_size)
 153.823 -            png_error(png_ptr, "save_size overflowed in pngpread");
 153.824 -      }
 153.825 +      /* We want the smaller of 'idat_size' and 'current_buffer_size', but they
 153.826 +       * are of different types and we don't know which variable has the fewest
 153.827 +       * bits.  Carefully select the smaller and cast it to the type of the
 153.828 +       * larger - this cannot overflow.  Do not cast in the following test - it
 153.829 +       * will break on either 16 or 64 bit platforms.
 153.830 +       */
 153.831 +      if (idat_size < save_size)
 153.832 +         save_size = (png_size_t)idat_size;
 153.833 +
 153.834        else
 153.835 -         save_size = png_ptr->save_buffer_size;
 153.836 +         idat_size = (png_uint_32)save_size;
 153.837  
 153.838        png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
 153.839 -      if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
 153.840 -         png_process_IDAT_data(png_ptr, png_ptr->save_buffer_ptr, save_size);
 153.841 -      png_ptr->idat_size -= save_size;
 153.842 +
 153.843 +      png_process_IDAT_data(png_ptr, png_ptr->save_buffer_ptr, save_size);
 153.844 +
 153.845 +      png_ptr->idat_size -= idat_size;
 153.846        png_ptr->buffer_size -= save_size;
 153.847        png_ptr->save_buffer_size -= save_size;
 153.848        png_ptr->save_buffer_ptr += save_size;
 153.849     }
 153.850 +
 153.851     if (png_ptr->idat_size && png_ptr->current_buffer_size)
 153.852     {
 153.853 -      png_size_t save_size;
 153.854 +      png_size_t save_size = png_ptr->current_buffer_size;
 153.855 +      png_uint_32 idat_size = png_ptr->idat_size;
 153.856  
 153.857 -      if (png_ptr->idat_size < (png_uint_32)png_ptr->current_buffer_size)
 153.858 -      {
 153.859 -         save_size = (png_size_t)png_ptr->idat_size;
 153.860 -         /* check for overflow */
 153.861 -         if((png_uint_32)save_size != png_ptr->idat_size)
 153.862 -            png_error(png_ptr, "save_size overflowed in pngpread");
 153.863 -      }
 153.864 +      /* We want the smaller of 'idat_size' and 'current_buffer_size', but they
 153.865 +       * are of different types and we don't know which variable has the fewest
 153.866 +       * bits.  Carefully select the smaller and cast it to the type of the
 153.867 +       * larger - this cannot overflow.
 153.868 +       */
 153.869 +      if (idat_size < save_size)
 153.870 +         save_size = (png_size_t)idat_size;
 153.871 +
 153.872        else
 153.873 -         save_size = png_ptr->current_buffer_size;
 153.874 +         idat_size = (png_uint_32)save_size;
 153.875  
 153.876        png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
 153.877 -      if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
 153.878 -        png_process_IDAT_data(png_ptr, png_ptr->current_buffer_ptr, save_size);
 153.879  
 153.880 -      png_ptr->idat_size -= save_size;
 153.881 +      png_process_IDAT_data(png_ptr, png_ptr->current_buffer_ptr, save_size);
 153.882 +
 153.883 +      png_ptr->idat_size -= idat_size;
 153.884        png_ptr->buffer_size -= save_size;
 153.885        png_ptr->current_buffer_size -= save_size;
 153.886        png_ptr->current_buffer_ptr += save_size;
 153.887 @@ -779,57 +936,104 @@
 153.888  png_process_IDAT_data(png_structp png_ptr, png_bytep buffer,
 153.889     png_size_t buffer_length)
 153.890  {
 153.891 -   int ret;
 153.892 +   /* The caller checks for a non-zero buffer length. */
 153.893 +   if (!(buffer_length > 0) || buffer == NULL)
 153.894 +      png_error(png_ptr, "No IDAT data (internal error)");
 153.895  
 153.896 -   if ((png_ptr->flags & PNG_FLAG_ZLIB_FINISHED) && buffer_length)
 153.897 -      png_error(png_ptr, "Extra compression data");
 153.898 -
 153.899 +   /* This routine must process all the data it has been given
 153.900 +    * before returning, calling the row callback as required to
 153.901 +    * handle the uncompressed results.
 153.902 +    */
 153.903     png_ptr->zstream.next_in = buffer;
 153.904     png_ptr->zstream.avail_in = (uInt)buffer_length;
 153.905 -   for(;;)
 153.906 +
 153.907 +   /* Keep going until the decompressed data is all processed
 153.908 +    * or the stream marked as finished.
 153.909 +    */
 153.910 +   while (png_ptr->zstream.avail_in > 0 &&
 153.911 +          !(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
 153.912     {
 153.913 -      ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
 153.914 -      if (ret != Z_OK)
 153.915 +      int ret;
 153.916 +
 153.917 +      /* We have data for zlib, but we must check that zlib
 153.918 +       * has someplace to put the results.  It doesn't matter
 153.919 +       * if we don't expect any results -- it may be the input
 153.920 +       * data is just the LZ end code.
 153.921 +       */
 153.922 +      if (!(png_ptr->zstream.avail_out > 0))
 153.923        {
 153.924 -         if (ret == Z_STREAM_END)
 153.925 -         {
 153.926 -            if (png_ptr->zstream.avail_in)
 153.927 -               png_error(png_ptr, "Extra compressed data");
 153.928 -            if (!(png_ptr->zstream.avail_out))
 153.929 -            {
 153.930 -               png_push_process_row(png_ptr);
 153.931 -            }
 153.932 +         png_ptr->zstream.avail_out =
 153.933 +             (uInt) PNG_ROWBYTES(png_ptr->pixel_depth,
 153.934 +             png_ptr->iwidth) + 1;
 153.935  
 153.936 -            png_ptr->mode |= PNG_AFTER_IDAT;
 153.937 -            png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
 153.938 -            break;
 153.939 -         }
 153.940 -         else if (ret == Z_BUF_ERROR)
 153.941 -            break;
 153.942 -         else
 153.943 -            png_error(png_ptr, "Decompression Error");
 153.944 -      }
 153.945 -      if (!(png_ptr->zstream.avail_out))
 153.946 -      {
 153.947 -         if ((
 153.948 -#if defined(PNG_READ_INTERLACING_SUPPORTED)
 153.949 -             png_ptr->interlaced && png_ptr->pass > 6) ||
 153.950 -             (!png_ptr->interlaced &&
 153.951 -#endif
 153.952 -             png_ptr->row_number == png_ptr->num_rows))
 153.953 -         {
 153.954 -           if (png_ptr->zstream.avail_in)
 153.955 -             png_warning(png_ptr, "Too much data in IDAT chunks");
 153.956 -           png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
 153.957 -           break;
 153.958 -         }
 153.959 -         png_push_process_row(png_ptr);
 153.960 -         png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
 153.961           png_ptr->zstream.next_out = png_ptr->row_buf;
 153.962        }
 153.963 -      else
 153.964 -         break;
 153.965 +
 153.966 +      /* Using Z_SYNC_FLUSH here means that an unterminated
 153.967 +       * LZ stream (a stream with a missing end code) can still
 153.968 +       * be handled, otherwise (Z_NO_FLUSH) a future zlib
 153.969 +       * implementation might defer output and therefore
 153.970 +       * change the current behavior (see comments in inflate.c
 153.971 +       * for why this doesn't happen at present with zlib 1.2.5).
 153.972 +       */
 153.973 +      ret = inflate(&png_ptr->zstream, Z_SYNC_FLUSH);
 153.974 +
 153.975 +      /* Check for any failure before proceeding. */
 153.976 +      if (ret != Z_OK && ret != Z_STREAM_END)
 153.977 +      {
 153.978 +         /* Terminate the decompression. */
 153.979 +         png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
 153.980 +
 153.981 +         /* This may be a truncated stream (missing or
 153.982 +          * damaged end code).  Treat that as a warning.
 153.983 +          */
 153.984 +         if (png_ptr->row_number >= png_ptr->num_rows ||
 153.985 +             png_ptr->pass > 6)
 153.986 +            png_warning(png_ptr, "Truncated compressed data in IDAT");
 153.987 +
 153.988 +         else
 153.989 +            png_error(png_ptr, "Decompression error in IDAT");
 153.990 +
 153.991 +         /* Skip the check on unprocessed input */
 153.992 +         return;
 153.993 +      }
 153.994 +
 153.995 +      /* Did inflate output any data? */
 153.996 +      if (png_ptr->zstream.next_out != png_ptr->row_buf)
 153.997 +      {
 153.998 +         /* Is this unexpected data after the last row?
 153.999 +          * If it is, artificially terminate the LZ output
153.1000 +          * here.
153.1001 +          */
153.1002 +         if (png_ptr->row_number >= png_ptr->num_rows ||
153.1003 +             png_ptr->pass > 6)
153.1004 +         {
153.1005 +            /* Extra data. */
153.1006 +            png_warning(png_ptr, "Extra compressed data in IDAT");
153.1007 +            png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
153.1008 +
153.1009 +            /* Do no more processing; skip the unprocessed
153.1010 +             * input check below.
153.1011 +             */
153.1012 +            return;
153.1013 +         }
153.1014 +
153.1015 +         /* Do we have a complete row? */
153.1016 +         if (png_ptr->zstream.avail_out == 0)
153.1017 +            png_push_process_row(png_ptr);
153.1018 +      }
153.1019 +
153.1020 +      /* And check for the end of the stream. */
153.1021 +      if (ret == Z_STREAM_END)
153.1022 +         png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
153.1023     }
153.1024 +
153.1025 +   /* All the data should have been processed, if anything
153.1026 +    * is left at this point we have bytes of IDAT data
153.1027 +    * after the zlib end code.
153.1028 +    */
153.1029 +   if (png_ptr->zstream.avail_in > 0)
153.1030 +      png_warning(png_ptr, "Extra compression data in IDAT");
153.1031  }
153.1032  
153.1033  void /* PRIVATE */
153.1034 @@ -845,23 +1049,24 @@
153.1035         png_ptr->row_info.width);
153.1036  
153.1037     png_read_filter_row(png_ptr, &(png_ptr->row_info),
153.1038 -      png_ptr->row_buf + 1, png_ptr->prev_row + 1,
153.1039 -      (int)(png_ptr->row_buf[0]));
153.1040 +       png_ptr->row_buf + 1, png_ptr->prev_row + 1,
153.1041 +       (int)(png_ptr->row_buf[0]));
153.1042  
153.1043 -   png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
153.1044 -      png_ptr->rowbytes + 1);
153.1045 +   png_memcpy(png_ptr->prev_row, png_ptr->row_buf, png_ptr->rowbytes + 1);
153.1046  
153.1047 -   if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
153.1048 +#ifdef PNG_READ_TRANSFORMS_SUPPORTED
153.1049 +   if (png_ptr->transformations)
153.1050        png_do_read_transformations(png_ptr);
153.1051 +#endif
153.1052  
153.1053 -#if defined(PNG_READ_INTERLACING_SUPPORTED)
153.1054 -   /* blow up interlaced rows to full size */
153.1055 +#ifdef PNG_READ_INTERLACING_SUPPORTED
153.1056 +   /* Blow up interlaced rows to full size */
153.1057     if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
153.1058     {
153.1059        if (png_ptr->pass < 6)
153.1060  /*       old interface (pre-1.0.9):
153.1061           png_do_read_interlace(&(png_ptr->row_info),
153.1062 -            png_ptr->row_buf + 1, png_ptr->pass, png_ptr->transformations);
153.1063 +             png_ptr->row_buf + 1, png_ptr->pass, png_ptr->transformations);
153.1064   */
153.1065           png_do_read_interlace(png_ptr);
153.1066  
153.1067 @@ -873,31 +1078,36 @@
153.1068              for (i = 0; i < 8 && png_ptr->pass == 0; i++)
153.1069              {
153.1070                 png_push_have_row(png_ptr, png_ptr->row_buf + 1);
153.1071 -               png_read_push_finish_row(png_ptr); /* updates png_ptr->pass */
153.1072 +               png_read_push_finish_row(png_ptr); /* Updates png_ptr->pass */
153.1073              }
153.1074 -            if (png_ptr->pass == 2) /* pass 1 might be empty */
153.1075 +
153.1076 +            if (png_ptr->pass == 2) /* Pass 1 might be empty */
153.1077              {
153.1078                 for (i = 0; i < 4 && png_ptr->pass == 2; i++)
153.1079                 {
153.1080 -                  png_push_have_row(png_ptr, png_bytep_NULL);
153.1081 +                  png_push_have_row(png_ptr, NULL);
153.1082                    png_read_push_finish_row(png_ptr);
153.1083                 }
153.1084              }
153.1085 +
153.1086              if (png_ptr->pass == 4 && png_ptr->height <= 4)
153.1087              {
153.1088                 for (i = 0; i < 2 && png_ptr->pass == 4; i++)
153.1089                 {
153.1090 -                  png_push_have_row(png_ptr, png_bytep_NULL);
153.1091 +                  png_push_have_row(png_ptr, NULL);
153.1092                    png_read_push_finish_row(png_ptr);
153.1093                 }
153.1094              }
153.1095 +
153.1096              if (png_ptr->pass == 6 && png_ptr->height <= 4)
153.1097              {
153.1098 -                png_push_have_row(png_ptr, png_bytep_NULL);
153.1099 +                png_push_have_row(png_ptr, NULL);
153.1100                  png_read_push_finish_row(png_ptr);
153.1101              }
153.1102 +
153.1103              break;
153.1104           }
153.1105 +
153.1106           case 1:
153.1107           {
153.1108              int i;
153.1109 @@ -906,99 +1116,123 @@
153.1110                 png_push_have_row(png_ptr, png_ptr->row_buf + 1);
153.1111                 png_read_push_finish_row(png_ptr);
153.1112              }
153.1113 -            if (png_ptr->pass == 2) /* skip top 4 generated rows */
153.1114 +
153.1115 +            if (png_ptr->pass == 2) /* Skip top 4 generated rows */
153.1116              {
153.1117                 for (i = 0; i < 4 && png_ptr->pass == 2; i++)
153.1118                 {
153.1119 -                  png_push_have_row(png_ptr, png_bytep_NULL);
153.1120 +                  png_push_have_row(png_ptr, NULL);
153.1121                    png_read_push_finish_row(png_ptr);
153.1122                 }
153.1123              }
153.1124 +
153.1125              break;
153.1126           }
153.1127 +
153.1128           case 2:
153.1129           {
153.1130              int i;
153.1131 +
153.1132              for (i = 0; i < 4 && png_ptr->pass == 2; i++)
153.1133              {
153.1134                 png_push_have_row(png_ptr, png_ptr->row_buf + 1);
153.1135                 png_read_push_finish_row(png_ptr);
153.1136              }
153.1137 +
153.1138              for (i = 0; i < 4 && png_ptr->pass == 2; i++)
153.1139              {
153.1140 -               png_push_have_row(png_ptr, png_bytep_NULL);
153.1141 +               png_push_have_row(png_ptr, NULL);
153.1142                 png_read_push_finish_row(png_ptr);
153.1143              }
153.1144 -            if (png_ptr->pass == 4) /* pass 3 might be empty */
153.1145 +
153.1146 +            if (png_ptr->pass == 4) /* Pass 3 might be empty */
153.1147              {
153.1148                 for (i = 0; i < 2 && png_ptr->pass == 4; i++)
153.1149                 {
153.1150 -                  png_push_have_row(png_ptr, png_bytep_NULL);
153.1151 +                  png_push_have_row(png_ptr, NULL);
153.1152                    png_read_push_finish_row(png_ptr);
153.1153                 }
153.1154              }
153.1155 +
153.1156              break;
153.1157           }
153.1158 +
153.1159           case 3:
153.1160           {
153.1161              int i;
153.1162 +
153.1163              for (i = 0; i < 4 && png_ptr->pass == 3; i++)
153.1164              {
153.1165                 png_push_have_row(png_ptr, png_ptr->row_buf + 1);
153.1166                 png_read_push_finish_row(png_ptr);
153.1167              }
153.1168 -            if (png_ptr->pass == 4) /* skip top two generated rows */
153.1169 +
153.1170 +            if (png_ptr->pass == 4) /* Skip top two generated rows */
153.1171              {
153.1172                 for (i = 0; i < 2 && png_ptr->pass == 4; i++)
153.1173                 {
153.1174 -                  png_push_have_row(png_ptr, png_bytep_NULL);
153.1175 +                  png_push_have_row(png_ptr, NULL);
153.1176                    png_read_push_finish_row(png_ptr);
153.1177                 }
153.1178              }
153.1179 +
153.1180              break;
153.1181           }
153.1182 +
153.1183           case 4:
153.1184           {
153.1185              int i;
153.1186 +
153.1187              for (i = 0; i < 2 && png_ptr->pass == 4; i++)
153.1188              {
153.1189                 png_push_have_row(png_ptr, png_ptr->row_buf + 1);
153.1190                 png_read_push_finish_row(png_ptr);
153.1191              }
153.1192 +
153.1193              for (i = 0; i < 2 && png_ptr->pass == 4; i++)
153.1194              {
153.1195 -               png_push_have_row(png_ptr, png_bytep_NULL);
153.1196 +               png_push_have_row(png_ptr, NULL);
153.1197                 png_read_push_finish_row(png_ptr);
153.1198              }
153.1199 -            if (png_ptr->pass == 6) /* pass 5 might be empty */
153.1200 +
153.1201 +            if (png_ptr->pass == 6) /* Pass 5 might be empty */
153.1202              {
153.1203 -               png_push_have_row(png_ptr, png_bytep_NULL);
153.1204 +               png_push_have_row(png_ptr, NULL);
153.1205                 png_read_push_finish_row(png_ptr);
153.1206              }
153.1207 +
153.1208              break;
153.1209           }
153.1210 +
153.1211           case 5:
153.1212           {
153.1213              int i;
153.1214 +
153.1215              for (i = 0; i < 2 && png_ptr->pass == 5; i++)
153.1216              {
153.1217                 png_push_have_row(png_ptr, png_ptr->row_buf + 1);
153.1218                 png_read_push_finish_row(png_ptr);
153.1219              }
153.1220 -            if (png_ptr->pass == 6) /* skip top generated row */
153.1221 +
153.1222 +            if (png_ptr->pass == 6) /* Skip top generated row */
153.1223              {
153.1224 -               png_push_have_row(png_ptr, png_bytep_NULL);
153.1225 +               png_push_have_row(png_ptr, NULL);
153.1226                 png_read_push_finish_row(png_ptr);
153.1227              }
153.1228 +
153.1229              break;
153.1230           }
153.1231 +
153.1232 +         default:
153.1233           case 6:
153.1234           {
153.1235              png_push_have_row(png_ptr, png_ptr->row_buf + 1);
153.1236              png_read_push_finish_row(png_ptr);
153.1237 +
153.1238              if (png_ptr->pass != 6)
153.1239                 break;
153.1240 -            png_push_have_row(png_ptr, png_bytep_NULL);
153.1241 +
153.1242 +            png_push_have_row(png_ptr, NULL);
153.1243              png_read_push_finish_row(png_ptr);
153.1244           }
153.1245        }
153.1246 @@ -1014,84 +1248,77 @@
153.1247  void /* PRIVATE */
153.1248  png_read_push_finish_row(png_structp png_ptr)
153.1249  {
153.1250 -#ifdef PNG_USE_LOCAL_ARRAYS
153.1251 -   /* arrays to facilitate easy interlacing - use pass (0 - 6) as index */
153.1252 +   /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
153.1253  
153.1254 -   /* start of interlace block */
153.1255 -   const int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
153.1256 +   /* Start of interlace block */
153.1257 +   PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
153.1258  
153.1259 -   /* offset to next interlace block */
153.1260 -   const int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
153.1261 +   /* Offset to next interlace block */
153.1262 +   PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
153.1263  
153.1264 -   /* start of interlace block in the y direction */
153.1265 -   const int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
153.1266 +   /* Start of interlace block in the y direction */
153.1267 +   PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
153.1268  
153.1269 -   /* offset to next interlace block in the y direction */
153.1270 -   const int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
153.1271 -
153.1272 -   /* Width of interlace block.  This is not currently used - if you need
153.1273 -    * it, uncomment it here and in png.h
153.1274 -   const int FARDATA png_pass_width[] = {8, 4, 4, 2, 2, 1, 1};
153.1275 -   */
153.1276 +   /* Offset to next interlace block in the y direction */
153.1277 +   PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
153.1278  
153.1279     /* Height of interlace block.  This is not currently used - if you need
153.1280      * it, uncomment it here and in png.h
153.1281 -   const int FARDATA png_pass_height[] = {8, 8, 4, 4, 2, 2, 1};
153.1282 +   PNG_CONST int FARDATA png_pass_height[] = {8, 8, 4, 4, 2, 2, 1};
153.1283     */
153.1284 -#endif
153.1285  
153.1286     png_ptr->row_number++;
153.1287     if (png_ptr->row_number < png_ptr->num_rows)
153.1288        return;
153.1289  
153.1290 +#ifdef PNG_READ_INTERLACING_SUPPORTED
153.1291     if (png_ptr->interlaced)
153.1292     {
153.1293        png_ptr->row_number = 0;
153.1294 -      png_memset_check(png_ptr, png_ptr->prev_row, 0,
153.1295 -         png_ptr->rowbytes + 1);
153.1296 +      png_memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
153.1297 +
153.1298        do
153.1299        {
153.1300           png_ptr->pass++;
153.1301           if ((png_ptr->pass == 1 && png_ptr->width < 5) ||
153.1302               (png_ptr->pass == 3 && png_ptr->width < 3) ||
153.1303               (png_ptr->pass == 5 && png_ptr->width < 2))
153.1304 -           png_ptr->pass++;
153.1305 +            png_ptr->pass++;
153.1306  
153.1307           if (png_ptr->pass > 7)
153.1308              png_ptr->pass--;
153.1309 +
153.1310           if (png_ptr->pass >= 7)
153.1311              break;
153.1312  
153.1313           png_ptr->iwidth = (png_ptr->width +
153.1314 -            png_pass_inc[png_ptr->pass] - 1 -
153.1315 -            png_pass_start[png_ptr->pass]) /
153.1316 -            png_pass_inc[png_ptr->pass];
153.1317 -
153.1318 -         png_ptr->irowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,
153.1319 -            png_ptr->iwidth) + 1;
153.1320 +             png_pass_inc[png_ptr->pass] - 1 -
153.1321 +             png_pass_start[png_ptr->pass]) /
153.1322 +             png_pass_inc[png_ptr->pass];
153.1323  
153.1324           if (png_ptr->transformations & PNG_INTERLACE)
153.1325              break;
153.1326  
153.1327           png_ptr->num_rows = (png_ptr->height +
153.1328 -            png_pass_yinc[png_ptr->pass] - 1 -
153.1329 -            png_pass_ystart[png_ptr->pass]) /
153.1330 -            png_pass_yinc[png_ptr->pass];
153.1331 +             png_pass_yinc[png_ptr->pass] - 1 -
153.1332 +             png_pass_ystart[png_ptr->pass]) /
153.1333 +             png_pass_yinc[png_ptr->pass];
153.1334  
153.1335        } while (png_ptr->iwidth == 0 || png_ptr->num_rows == 0);
153.1336     }
153.1337 +#endif /* PNG_READ_INTERLACING_SUPPORTED */
153.1338  }
153.1339  
153.1340 -#if defined(PNG_READ_tEXt_SUPPORTED)
153.1341 +#ifdef PNG_READ_tEXt_SUPPORTED
153.1342  void /* PRIVATE */
153.1343  png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
153.1344 -   length)
153.1345 +    length)
153.1346  {
153.1347     if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
153.1348        {
153.1349 +         PNG_UNUSED(info_ptr) /* To quiet some compiler warnings */
153.1350           png_error(png_ptr, "Out of place tEXt");
153.1351 -         /* to quiet some compiler warnings */
153.1352 -         if(info_ptr == NULL) return;
153.1353 +         /* NOT REACHED */
153.1354        }
153.1355  
153.1356  #ifdef PNG_MAX_MALLOC_64K
153.1357 @@ -1106,7 +1333,7 @@
153.1358  #endif
153.1359  
153.1360     png_ptr->current_text = (png_charp)png_malloc(png_ptr,
153.1361 -         (png_uint_32)(length+1));
153.1362 +       (png_size_t)(length + 1));
153.1363     png_ptr->current_text[length] = '\0';
153.1364     png_ptr->current_text_ptr = png_ptr->current_text;
153.1365     png_ptr->current_text_size = (png_size_t)length;
153.1366 @@ -1123,8 +1350,10 @@
153.1367  
153.1368        if (png_ptr->buffer_size < png_ptr->current_text_left)
153.1369           text_size = png_ptr->buffer_size;
153.1370 +
153.1371        else
153.1372           text_size = png_ptr->current_text_left;
153.1373 +
153.1374        png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
153.1375        png_ptr->current_text_left -= text_size;
153.1376        png_ptr->current_text_ptr += text_size;
153.1377 @@ -1144,7 +1373,7 @@
153.1378  
153.1379        png_push_crc_finish(png_ptr);
153.1380  
153.1381 -#if defined(PNG_MAX_MALLOC_64K)
153.1382 +#ifdef PNG_MAX_MALLOC_64K
153.1383        if (png_ptr->skip_length)
153.1384           return;
153.1385  #endif
153.1386 @@ -1152,19 +1381,17 @@
153.1387        key = png_ptr->current_text;
153.1388  
153.1389        for (text = key; *text; text++)
153.1390 -         /* empty loop */ ;
153.1391 +         /* Empty loop */ ;
153.1392  
153.1393 -      if (text != key + png_ptr->current_text_size)
153.1394 +      if (text < key + png_ptr->current_text_size)
153.1395           text++;
153.1396  
153.1397 -      text_ptr = (png_textp)png_malloc(png_ptr,
153.1398 -         (png_uint_32)png_sizeof(png_text));
153.1399 +      text_ptr = (png_textp)png_malloc(png_ptr, png_sizeof(png_text));
153.1400        text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
153.1401        text_ptr->key = key;
153.1402 -#ifdef PNG_iTXt_SUPPORTED
153.1403 +      text_ptr->itxt_length = 0;
153.1404        text_ptr->lang = NULL;
153.1405        text_ptr->lang_key = NULL;
153.1406 -#endif
153.1407        text_ptr->text = text;
153.1408  
153.1409        ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
153.1410 @@ -1174,22 +1401,22 @@
153.1411        png_ptr->current_text = NULL;
153.1412  
153.1413        if (ret)
153.1414 -        png_warning(png_ptr, "Insufficient memory to store text chunk.");
153.1415 +         png_warning(png_ptr, "Insufficient memory to store text chunk");
153.1416     }
153.1417  }
153.1418  #endif
153.1419  
153.1420 -#if defined(PNG_READ_zTXt_SUPPORTED)
153.1421 +#ifdef PNG_READ_zTXt_SUPPORTED
153.1422  void /* PRIVATE */
153.1423  png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
153.1424     length)
153.1425  {
153.1426     if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
153.1427 -      {
153.1428 -         png_error(png_ptr, "Out of place zTXt");
153.1429 -         /* to quiet some compiler warnings */
153.1430 -         if(info_ptr == NULL) return;
153.1431 -      }
153.1432 +   {
153.1433 +      PNG_UNUSED(info_ptr) /* To quiet some compiler warnings */
153.1434 +      png_error(png_ptr, "Out of place zTXt");
153.1435 +      /* NOT REACHED */
153.1436 +   }
153.1437  
153.1438  #ifdef PNG_MAX_MALLOC_64K
153.1439     /* We can't handle zTXt chunks > 64K, since we don't have enough space
153.1440 @@ -1205,7 +1432,7 @@
153.1441  #endif
153.1442  
153.1443     png_ptr->current_text = (png_charp)png_malloc(png_ptr,
153.1444 -       (png_uint_32)(length+1));
153.1445 +       (png_size_t)(length + 1));
153.1446     png_ptr->current_text[length] = '\0';
153.1447     png_ptr->current_text_ptr = png_ptr->current_text;
153.1448     png_ptr->current_text_size = (png_size_t)length;
153.1449 @@ -1222,8 +1449,10 @@
153.1450  
153.1451        if (png_ptr->buffer_size < (png_uint_32)png_ptr->current_text_left)
153.1452           text_size = png_ptr->buffer_size;
153.1453 +
153.1454        else
153.1455           text_size = png_ptr->current_text_left;
153.1456 +
153.1457        png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
153.1458        png_ptr->current_text_left -= text_size;
153.1459        png_ptr->current_text_ptr += text_size;
153.1460 @@ -1247,10 +1476,10 @@
153.1461        key = png_ptr->current_text;
153.1462  
153.1463        for (text = key; *text; text++)
153.1464 -         /* empty loop */ ;
153.1465 +         /* Empty loop */ ;
153.1466  
153.1467        /* zTXt can't have zero text */
153.1468 -      if (text == key + png_ptr->current_text_size)
153.1469 +      if (text >= key + png_ptr->current_text_size)
153.1470        {
153.1471           png_ptr->current_text = NULL;
153.1472           png_free(png_ptr, key);
153.1473 @@ -1259,7 +1488,7 @@
153.1474  
153.1475        text++;
153.1476  
153.1477 -      if (*text != PNG_TEXT_COMPRESSION_zTXt) /* check compression byte */
153.1478 +      if (*text != PNG_TEXT_COMPRESSION_zTXt) /* Check compression byte */
153.1479        {
153.1480           png_ptr->current_text = NULL;
153.1481           png_free(png_ptr, key);
153.1482 @@ -1268,9 +1497,9 @@
153.1483  
153.1484        text++;
153.1485  
153.1486 -      png_ptr->zstream.next_in = (png_bytep )text;
153.1487 +      png_ptr->zstream.next_in = (png_bytep)text;
153.1488        png_ptr->zstream.avail_in = (uInt)(png_ptr->current_text_size -
153.1489 -         (text - key));
153.1490 +          (text - key));
153.1491        png_ptr->zstream.next_out = png_ptr->zbuf;
153.1492        png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
153.1493  
153.1494 @@ -1291,35 +1520,45 @@
153.1495              png_free(png_ptr, text);
153.1496              return;
153.1497           }
153.1498 +
153.1499           if (!(png_ptr->zstream.avail_out) || ret == Z_STREAM_END)
153.1500           {
153.1501              if (text == NULL)
153.1502              {
153.1503                 text = (png_charp)png_malloc(png_ptr,
153.1504 -                  (png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out
153.1505 -                     + key_size + 1));
153.1506 +                   (png_ptr->zbuf_size
153.1507 +                   - png_ptr->zstream.avail_out + key_size + 1));
153.1508 +
153.1509                 png_memcpy(text + key_size, png_ptr->zbuf,
153.1510 -                  png_ptr->zbuf_size - png_ptr->zstream.avail_out);
153.1511 +                   png_ptr->zbuf_size - png_ptr->zstream.avail_out);
153.1512 +
153.1513                 png_memcpy(text, key, key_size);
153.1514 +
153.1515                 text_size = key_size + png_ptr->zbuf_size -
153.1516 -                  png_ptr->zstream.avail_out;
153.1517 +                   png_ptr->zstream.avail_out;
153.1518 +
153.1519                 *(text + text_size) = '\0';
153.1520              }
153.1521 +
153.1522              else
153.1523              {
153.1524                 png_charp tmp;
153.1525  
153.1526                 tmp = text;
153.1527                 text = (png_charp)png_malloc(png_ptr, text_size +
153.1528 -                  (png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out
153.1529 -                   + 1));
153.1530 +                   (png_ptr->zbuf_size
153.1531 +                   - png_ptr->zstream.avail_out + 1));
153.1532 +
153.1533                 png_memcpy(text, tmp, text_size);
153.1534                 png_free(png_ptr, tmp);
153.1535 +
153.1536                 png_memcpy(text + text_size, png_ptr->zbuf,
153.1537 -                  png_ptr->zbuf_size - png_ptr->zstream.avail_out);
153.1538 +                   png_ptr->zbuf_size - png_ptr->zstream.avail_out);
153.1539 +
153.1540                 text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out;
153.1541                 *(text + text_size) = '\0';
153.1542              }
153.1543 +
153.1544              if (ret != Z_STREAM_END)
153.1545              {
153.1546                 png_ptr->zstream.next_out = png_ptr->zbuf;
153.1547 @@ -1352,13 +1591,12 @@
153.1548        text += key_size;
153.1549  
153.1550        text_ptr = (png_textp)png_malloc(png_ptr,
153.1551 -          (png_uint_32)png_sizeof(png_text));
153.1552 +          png_sizeof(png_text));
153.1553        text_ptr->compression = PNG_TEXT_COMPRESSION_zTXt;
153.1554        text_ptr->key = key;
153.1555 -#ifdef PNG_iTXt_SUPPORTED
153.1556 +      text_ptr->itxt_length = 0;
153.1557        text_ptr->lang = NULL;
153.1558        text_ptr->lang_key = NULL;
153.1559 -#endif
153.1560        text_ptr->text = text;
153.1561  
153.1562        ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
153.1563 @@ -1367,22 +1605,22 @@
153.1564        png_free(png_ptr, text_ptr);
153.1565  
153.1566        if (ret)
153.1567 -        png_warning(png_ptr, "Insufficient memory to store text chunk.");
153.1568 +         png_warning(png_ptr, "Insufficient memory to store text chunk");
153.1569     }
153.1570  }
153.1571  #endif
153.1572  
153.1573 -#if defined(PNG_READ_iTXt_SUPPORTED)
153.1574 +#ifdef PNG_READ_iTXt_SUPPORTED
153.1575  void /* PRIVATE */
153.1576  png_push_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
153.1577 -   length)
153.1578 +    length)
153.1579  {
153.1580     if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
153.1581 -      {
153.1582 -         png_error(png_ptr, "Out of place iTXt");
153.1583 -         /* to quiet some compiler warnings */
153.1584 -         if(info_ptr == NULL) return;
153.1585 -      }
153.1586 +   {
153.1587 +      PNG_UNUSED(info_ptr) /* To quiet some compiler warnings */
153.1588 +      png_error(png_ptr, "Out of place iTXt");
153.1589 +      /* NOT REACHED */
153.1590 +   }
153.1591  
153.1592  #ifdef PNG_MAX_MALLOC_64K
153.1593     png_ptr->skip_length = 0;  /* This may not be necessary */
153.1594 @@ -1396,7 +1634,7 @@
153.1595  #endif
153.1596  
153.1597     png_ptr->current_text = (png_charp)png_malloc(png_ptr,
153.1598 -         (png_uint_32)(length+1));
153.1599 +       (png_size_t)(length + 1));
153.1600     png_ptr->current_text[length] = '\0';
153.1601     png_ptr->current_text_ptr = png_ptr->current_text;
153.1602     png_ptr->current_text_size = (png_size_t)length;
153.1603 @@ -1414,12 +1652,15 @@
153.1604  
153.1605        if (png_ptr->buffer_size < png_ptr->current_text_left)
153.1606           text_size = png_ptr->buffer_size;
153.1607 +
153.1608        else
153.1609           text_size = png_ptr->current_text_left;
153.1610 +
153.1611        png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
153.1612        png_ptr->current_text_left -= text_size;
153.1613        png_ptr->current_text_ptr += text_size;
153.1614     }
153.1615 +
153.1616     if (!(png_ptr->current_text_left))
153.1617     {
153.1618        png_textp text_ptr;
153.1619 @@ -1438,7 +1679,7 @@
153.1620  
153.1621        png_push_crc_finish(png_ptr);
153.1622  
153.1623 -#if defined(PNG_MAX_MALLOC_64K)
153.1624 +#ifdef PNG_MAX_MALLOC_64K
153.1625        if (png_ptr->skip_length)
153.1626           return;
153.1627  #endif
153.1628 @@ -1446,26 +1687,33 @@
153.1629        key = png_ptr->current_text;
153.1630  
153.1631        for (lang = key; *lang; lang++)
153.1632 -         /* empty loop */ ;
153.1633 +         /* Empty loop */ ;
153.1634  
153.1635 -      if (lang != key + png_ptr->current_text_size)
153.1636 +      if (lang < key + png_ptr->current_text_size - 3)
153.1637           lang++;
153.1638  
153.1639        comp_flag = *lang++;
153.1640 -      lang++;     /* skip comp_type, always zero */
153.1641 +      lang++;     /* Skip comp_type, always zero */
153.1642  
153.1643        for (lang_key = lang; *lang_key; lang_key++)
153.1644 -         /* empty loop */ ;
153.1645 -      lang_key++;        /* skip NUL separator */
153.1646 +         /* Empty loop */ ;
153.1647  
153.1648 -      for (text = lang_key; *text; text++)
153.1649 -         /* empty loop */ ;
153.1650 +      lang_key++;        /* Skip NUL separator */
153.1651  
153.1652 -      if (text != key + png_ptr->current_text_size)
153.1653 +      text=lang_key;
153.1654 +
153.1655 +      if (lang_key < key + png_ptr->current_text_size - 1)
153.1656 +      {
153.1657 +         for (; *text; text++)
153.1658 +            /* Empty loop */ ;
153.1659 +      }
153.1660 +
153.1661 +      if (text < key + png_ptr->current_text_size)
153.1662           text++;
153.1663  
153.1664        text_ptr = (png_textp)png_malloc(png_ptr,
153.1665 -         (png_uint_32)png_sizeof(png_text));
153.1666 +          png_sizeof(png_text));
153.1667 +
153.1668        text_ptr->compression = comp_flag + 2;
153.1669        text_ptr->key = key;
153.1670        text_ptr->lang = lang;
153.1671 @@ -1480,7 +1728,7 @@
153.1672  
153.1673        png_free(png_ptr, text_ptr);
153.1674        if (ret)
153.1675 -        png_warning(png_ptr, "Insufficient memory to store iTXt chunk.");
153.1676 +         png_warning(png_ptr, "Insufficient memory to store iTXt chunk");
153.1677     }
153.1678  }
153.1679  #endif
153.1680 @@ -1491,69 +1739,83 @@
153.1681   */
153.1682  void /* PRIVATE */
153.1683  png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32
153.1684 -   length)
153.1685 +    length)
153.1686  {
153.1687 -   png_uint_32 skip=0;
153.1688 -   png_check_chunk_name(png_ptr, png_ptr->chunk_name);
153.1689 +   png_uint_32 skip = 0;
153.1690  
153.1691     if (!(png_ptr->chunk_name[0] & 0x20))
153.1692     {
153.1693 -#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
153.1694 -      if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
153.1695 -           PNG_HANDLE_CHUNK_ALWAYS
153.1696 -#if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
153.1697 -           && png_ptr->read_user_chunk_fn == NULL
153.1698 +#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
153.1699 +      if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
153.1700 +          PNG_HANDLE_CHUNK_ALWAYS
153.1701 +#ifdef PNG_READ_USER_CHUNKS_SUPPORTED
153.1702 +          && png_ptr->read_user_chunk_fn == NULL
153.1703  #endif
153.1704 -         )
153.1705 +          )
153.1706  #endif
153.1707           png_chunk_error(png_ptr, "unknown critical chunk");
153.1708  
153.1709 -      /* to quiet compiler warnings about unused info_ptr */
153.1710 -      if (info_ptr == NULL)
153.1711 -         return;
153.1712 +      PNG_UNUSED(info_ptr) /* To quiet some compiler warnings */
153.1713     }
153.1714  
153.1715 -#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
153.1716 +#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
153.1717     if (png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS)
153.1718     {
153.1719  #ifdef PNG_MAX_MALLOC_64K
153.1720 -       if (length > (png_uint_32)65535L)
153.1721 -       {
153.1722 -           png_warning(png_ptr, "unknown chunk too large to fit in memory");
153.1723 -           skip = length - (png_uint_32)65535L;
153.1724 -           length = (png_uint_32)65535L;
153.1725 -       }
153.1726 +      if (length > (png_uint_32)65535L)
153.1727 +      {
153.1728 +         png_warning(png_ptr, "unknown chunk too large to fit in memory");
153.1729 +         skip = length - (png_uint_32)65535L;
153.1730 +         length = (png_uint_32)65535L;
153.1731 +      }
153.1732  #endif
153.1733 -       png_strcpy((png_charp)png_ptr->unknown_chunk.name,
153.1734 -         (png_charp)png_ptr->chunk_name);
153.1735 -       png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
153.1736 -       png_ptr->unknown_chunk.size = (png_size_t)length;
153.1737 -       png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
153.1738 -#if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
153.1739 -       if(png_ptr->read_user_chunk_fn != NULL)
153.1740 -       {
153.1741 -          /* callback to user unknown chunk handler */
153.1742 -          int ret;
153.1743 -          ret = (*(png_ptr->read_user_chunk_fn))
153.1744 -            (png_ptr, &png_ptr->unknown_chunk);
153.1745 -          if (ret < 0)
153.1746 -             png_chunk_error(png_ptr, "error in user chunk");
153.1747 -          if (ret == 0)
153.1748 -          {
153.1749 -             if (!(png_ptr->chunk_name[0] & 0x20))
153.1750 -                if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
153.1751 -                     PNG_HANDLE_CHUNK_ALWAYS)
153.1752 -                   png_chunk_error(png_ptr, "unknown critical chunk");
153.1753 -                png_set_unknown_chunks(png_ptr, info_ptr,
153.1754 -                   &png_ptr->unknown_chunk, 1);
153.1755 -          }
153.1756 -       }
153.1757 -#else
153.1758 -       png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
153.1759 +      png_memcpy((png_charp)png_ptr->unknown_chunk.name,
153.1760 +          (png_charp)png_ptr->chunk_name,
153.1761 +          png_sizeof(png_ptr->unknown_chunk.name));
153.1762 +      png_ptr->unknown_chunk.name[png_sizeof(png_ptr->unknown_chunk.name) - 1]
153.1763 +          = '\0';
153.1764 +
153.1765 +      png_ptr->unknown_chunk.size = (png_size_t)length;
153.1766 +
153.1767 +      if (length == 0)
153.1768 +         png_ptr->unknown_chunk.data = NULL;
153.1769 +
153.1770 +      else
153.1771 +      {
153.1772 +         png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr,
153.1773 +             (png_size_t)length);
153.1774 +         png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
153.1775 +      }
153.1776 +
153.1777 +#ifdef PNG_READ_USER_CHUNKS_SUPPORTED
153.1778 +      if (png_ptr->read_user_chunk_fn != NULL)
153.1779 +      {
153.1780 +         /* Callback to user unknown chunk handler */
153.1781 +         int ret;
153.1782 +         ret = (*(png_ptr->read_user_chunk_fn))
153.1783 +             (png_ptr, &png_ptr->unknown_chunk);
153.1784 +
153.1785 +         if (ret < 0)
153.1786 +            png_chunk_error(png_ptr, "error in user chunk");
153.1787 +
153.1788 +         if (ret == 0)
153.1789 +         {
153.1790 +            if (!(png_ptr->chunk_name[0] & 0x20))
153.1791 +               if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
153.1792 +                   PNG_HANDLE_CHUNK_ALWAYS)
153.1793 +                  png_chunk_error(png_ptr, "unknown critical chunk");
153.1794 +            png_set_unknown_chunks(png_ptr, info_ptr,
153.1795 +                &png_ptr->unknown_chunk, 1);
153.1796 +         }
153.1797 +      }
153.1798 +
153.1799 +      else
153.1800  #endif
153.1801 -       png_free(png_ptr, png_ptr->unknown_chunk.data);
153.1802 -       png_ptr->unknown_chunk.data = NULL;
153.1803 +         png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
153.1804 +      png_free(png_ptr, png_ptr->unknown_chunk.data);
153.1805 +      png_ptr->unknown_chunk.data = NULL;
153.1806     }
153.1807 +
153.1808     else
153.1809  #endif
153.1810        skip=length;
153.1811 @@ -1583,24 +1845,27 @@
153.1812  }
153.1813  
153.1814  void PNGAPI
153.1815 -png_progressive_combine_row (png_structp png_ptr,
153.1816 -   png_bytep old_row, png_bytep new_row)
153.1817 +png_progressive_combine_row (png_structp png_ptr, png_bytep old_row,
153.1818 +    png_const_bytep new_row)
153.1819  {
153.1820 -#ifdef PNG_USE_LOCAL_ARRAYS
153.1821 -   const int FARDATA png_pass_dsp_mask[7] =
153.1822 +   PNG_CONST int FARDATA png_pass_dsp_mask[7] =
153.1823        {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
153.1824 -#endif
153.1825 -   if(png_ptr == NULL) return;
153.1826 +
153.1827 +   if (png_ptr == NULL)
153.1828 +      return;
153.1829 +
153.1830     if (new_row != NULL)    /* new_row must == png_ptr->row_buf here. */
153.1831        png_combine_row(png_ptr, old_row, png_pass_dsp_mask[png_ptr->pass]);
153.1832  }
153.1833  
153.1834  void PNGAPI
153.1835  png_set_progressive_read_fn(png_structp png_ptr, png_voidp progressive_ptr,
153.1836 -   png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
153.1837 -   png_progressive_end_ptr end_fn)
153.1838 +    png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
153.1839 +    png_progressive_end_ptr end_fn)
153.1840  {
153.1841 -   if(png_ptr == NULL) return;
153.1842 +   if (png_ptr == NULL)
153.1843 +      return;
153.1844 +
153.1845     png_ptr->info_fn = info_fn;
153.1846     png_ptr->row_fn = row_fn;
153.1847     png_ptr->end_fn = end_fn;
153.1848 @@ -1609,9 +1874,11 @@
153.1849  }
153.1850  
153.1851  png_voidp PNGAPI
153.1852 -png_get_progressive_ptr(png_structp png_ptr)
153.1853 +png_get_progressive_ptr(png_const_structp png_ptr)
153.1854  {
153.1855 -   if(png_ptr == NULL) return (NULL);
153.1856 +   if (png_ptr == NULL)
153.1857 +      return (NULL);
153.1858 +
153.1859     return png_ptr->io_ptr;
153.1860  }
153.1861  #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
   154.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   154.2 +++ b/src/share/native/sun/awt/libpng/pngpriv.h	Tue Oct 04 12:39:42 2011 -0700
   154.3 @@ -0,0 +1,1386 @@
   154.4 +/*
   154.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   154.6 + *
   154.7 + * This code is free software; you can redistribute it and/or modify it
   154.8 + * under the terms of the GNU General Public License version 2 only, as
   154.9 + * published by the Free Software Foundation.  Oracle designates this
  154.10 + * particular file as subject to the "Classpath" exception as provided
  154.11 + * by Oracle in the LICENSE file that accompanied this code.
  154.12 + *
  154.13 + * This code is distributed in the hope that it will be useful, but WITHOUT
  154.14 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  154.15 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  154.16 + * version 2 for more details (a copy is included in the LICENSE file that
  154.17 + * accompanied this code).
  154.18 + *
  154.19 + * You should have received a copy of the GNU General Public License version
  154.20 + * 2 along with this work; if not, write to the Free Software Foundation,
  154.21 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  154.22 + *
  154.23 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  154.24 + * or visit www.oracle.com if you need additional information or have any
  154.25 + * questions.
  154.26 + */
  154.27 +
  154.28 +/* pngpriv.h - private declarations for use inside libpng
  154.29 + *
  154.30 + * This file is available under and governed by the GNU General Public
  154.31 + * License version 2 only, as published by the Free Software Foundation.
  154.32 + * However, the following notice accompanied the original version of this
  154.33 + * file and, per its terms, should not be removed:
  154.34 + *
  154.35 + * For conditions of distribution and use, see copyright notice in png.h
  154.36 + * Copyright (c) 1998-2011 Glenn Randers-Pehrson
  154.37 + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
  154.38 + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
  154.39 + *
  154.40 + * Last changed in libpng 1.5.4 [July 7, 2011]
  154.41 + *
  154.42 + * This code is released under the libpng license.
  154.43 + * For conditions of distribution and use, see the disclaimer
  154.44 + * and license in png.h
  154.45 + */
  154.46 +
  154.47 +/* The symbols declared in this file (including the functions declared
  154.48 + * as PNG_EXTERN) are PRIVATE.  They are not part of the libpng public
  154.49 + * interface, and are not recommended for use by regular applications.
  154.50 + * Some of them may become public in the future; others may stay private,
  154.51 + * change in an incompatible way, or even disappear.
  154.52 + * Although the libpng users are not forbidden to include this header,
  154.53 + * they should be well aware of the issues that may arise from doing so.
  154.54 + */
  154.55 +
  154.56 +#ifndef PNGPRIV_H
  154.57 +#define PNGPRIV_H
  154.58 +
  154.59 +/* Feature Test Macros.  The following are defined here to ensure that correctly
  154.60 + * implemented libraries reveal the APIs libpng needs to build and hide those
  154.61 + * that are not needed and potentially damaging to the compilation.
  154.62 + *
  154.63 + * Feature Test Macros must be defined before any system header is included (see
  154.64 + * POSIX 1003.1 2.8.2 "POSIX Symbols."
  154.65 + *
  154.66 + * These macros only have an effect if the operating system supports either
  154.67 + * POSIX 1003.1 or C99, or both.  On other operating systems (particularly
  154.68 + * Windows/Visual Studio) there is no effect; the OS specific tests below are
  154.69 + * still required (as of 2011-05-02.)
  154.70 + */
  154.71 +#define _POSIX_SOURCE 1 /* Just the POSIX 1003.1 and C89 APIs */
  154.72 +
  154.73 +/* This is required for the definition of abort(), used as a last ditch
  154.74 + * error handler when all else fails.
  154.75 + */
  154.76 +#include <stdlib.h>
  154.77 +
  154.78 +#define PNGLIB_BUILD
  154.79 +#ifdef PNG_USER_CONFIG
  154.80 +#  include "pngusr.h"
  154.81 +   /* These should have been defined in pngusr.h */
  154.82 +#  ifndef PNG_USER_PRIVATEBUILD
  154.83 +#    define PNG_USER_PRIVATEBUILD "Custom libpng build"
  154.84 +#  endif
  154.85 +#  ifndef PNG_USER_DLLFNAME_POSTFIX
  154.86 +#    define PNG_USER_DLLFNAME_POSTFIX "Cb"
  154.87 +#  endif
  154.88 +#endif
  154.89 +#include "png.h"
  154.90 +#include "pnginfo.h"
  154.91 +#include "pngstruct.h"
  154.92 +
  154.93 +/* This is used for 16 bit gamma tables - only the top level pointers are const,
  154.94 + * this could be changed:
  154.95 + */
  154.96 +typedef PNG_CONST png_uint_16p FAR * png_const_uint_16pp;
  154.97 +
  154.98 +/* Added at libpng-1.2.9 */
  154.99 +/* Moved to pngpriv.h at libpng-1.5.0 */
 154.100 +
 154.101 +/* config.h is created by and PNG_CONFIGURE_LIBPNG is set by the "configure"
 154.102 + * script.  We may need it here to get the correct configuration on things
 154.103 + * like limits.
 154.104 + */
 154.105 +#ifdef PNG_CONFIGURE_LIBPNG
 154.106 +#  ifdef HAVE_CONFIG_H
 154.107 +#    include "config.h"
 154.108 +#  endif
 154.109 +#endif
 154.110 +
 154.111 +/* Moved to pngpriv.h at libpng-1.5.0 */
 154.112 +/* NOTE: some of these may have been used in external applications as
 154.113 + * these definitions were exposed in pngconf.h prior to 1.5.
 154.114 + */
 154.115 +
 154.116 +/* If you are running on a machine where you cannot allocate more
 154.117 + * than 64K of memory at once, uncomment this.  While libpng will not
 154.118 + * normally need that much memory in a chunk (unless you load up a very
 154.119 + * large file), zlib needs to know how big of a chunk it can use, and
 154.120 + * libpng thus makes sure to check any memory allocation to verify it
 154.121 + * will fit into memory.
 154.122 + *
 154.123 + * zlib provides 'MAXSEG_64K' which, if defined, indicates the
 154.124 + * same limit and pngconf.h (already included) sets the limit
 154.125 + * if certain operating systems are detected.
 154.126 + */
 154.127 +#if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K)
 154.128 +#  define PNG_MAX_MALLOC_64K
 154.129 +#endif
 154.130 +
 154.131 +#ifndef PNG_UNUSED
 154.132 +/* Unused formal parameter warnings are silenced using the following macro
 154.133 + * which is expected to have no bad effects on performance (optimizing
 154.134 + * compilers will probably remove it entirely).  Note that if you replace
 154.135 + * it with something other than whitespace, you must include the terminating
 154.136 + * semicolon.
 154.137 + */
 154.138 +#  define PNG_UNUSED(param) (void)param;
 154.139 +#endif
 154.140 +
 154.141 +/* Just a little check that someone hasn't tried to define something
 154.142 + * contradictory.
 154.143 + */
 154.144 +#if (PNG_ZBUF_SIZE > 65536L) && defined(PNG_MAX_MALLOC_64K)
 154.145 +#  undef PNG_ZBUF_SIZE
 154.146 +#  define PNG_ZBUF_SIZE 65536L
 154.147 +#endif
 154.148 +
 154.149 +/* PNG_STATIC is used to mark internal file scope functions if they need to be
 154.150 + * accessed for implementation tests (see the code in tests/?*).
 154.151 + */
 154.152 +#ifndef PNG_STATIC
 154.153 +#   define PNG_STATIC static
 154.154 +#endif
 154.155 +
 154.156 +/* If warnings or errors are turned off the code is disabled or redirected here.
 154.157 + * From 1.5.4 functions have been added to allow very limited formatting of
 154.158 + * error and warning messages - this code will also be disabled here.
 154.159 + */
 154.160 +#ifdef PNG_WARNINGS_SUPPORTED
 154.161 +#  define PNG_WARNING_PARAMETERS(p) png_warning_parameters p;
 154.162 +#else
 154.163 +#  define png_warning(s1,s2) ((void)(s1))
 154.164 +#  define png_chunk_warning(s1,s2) ((void)(s1))
 154.165 +#  define png_warning_parameter(p,number,string) ((void)0)
 154.166 +#  define png_warning_parameter_unsigned(p,number,format,value) ((void)0)
 154.167 +#  define png_warning_parameter_signed(p,number,format,value) ((void)0)
 154.168 +#  define png_formatted_warning(pp,p,message) ((void)(pp))
 154.169 +#  define PNG_WARNING_PARAMETERS(p)
 154.170 +#endif
 154.171 +#ifndef PNG_ERROR_TEXT_SUPPORTED
 154.172 +#  define png_error(s1,s2) png_err(s1)
 154.173 +#  define png_chunk_error(s1,s2) png_err(s1)
 154.174 +#  define png_fixed_error(s1,s2) png_err(s1)
 154.175 +#endif
 154.176 +
 154.177 +#ifndef PNG_EXTERN
 154.178 +/* The functions exported by PNG_EXTERN are internal functions, which
 154.179 + * aren't usually used outside the library (as far as I know), so it is
 154.180 + * debatable if they should be exported at all.  In the future, when it
 154.181 + * is possible to have run-time registry of chunk-handling functions,
 154.182 + * some of these might be made available again.
 154.183 +#  define PNG_EXTERN extern
 154.184 + */
 154.185 +#  define PNG_EXTERN
 154.186 +#endif
 154.187 +
 154.188 +/* Some fixed point APIs are still required even if not exported because
 154.189 + * they get used by the corresponding floating point APIs.  This magic
 154.190 + * deals with this:
 154.191 + */
 154.192 +#ifdef PNG_FIXED_POINT_SUPPORTED
 154.193 +#  define PNGFAPI PNGAPI
 154.194 +#else
 154.195 +#  define PNGFAPI /* PRIVATE */
 154.196 +#endif
 154.197 +
 154.198 +/* Other defines specific to compilers can go here.  Try to keep
 154.199 + * them inside an appropriate ifdef/endif pair for portability.
 154.200 + */
 154.201 +#if defined(PNG_FLOATING_POINT_SUPPORTED) ||\
 154.202 +    defined(PNG_FLOATING_ARITHMETIC_SUPPORTED)
 154.203 +   /* png.c requires the following ANSI-C constants if the conversion of
 154.204 +    * floating point to ASCII is implemented therein:
 154.205 +    *
 154.206 +    *  DBL_DIG  Maximum number of decimal digits (can be set to any constant)
 154.207 +    *  DBL_MIN  Smallest normalized fp number (can be set to an arbitrary value)
 154.208 +    *  DBL_MAX  Maximum floating point number (can be set to an arbitrary value)
 154.209 +    */
 154.210 +#  include <float.h>
 154.211 +
 154.212 +#  if (defined(__MWERKS__) && defined(macintosh)) || defined(applec) || \
 154.213 +    defined(THINK_C) || defined(__SC__) || defined(TARGET_OS_MAC)
 154.214 +     /* We need to check that <math.h> hasn't already been included earlier
 154.215 +      * as it seems it doesn't agree with <fp.h>, yet we should really use
 154.216 +      * <fp.h> if possible.
 154.217 +      */
 154.218 +#    if !defined(__MATH_H__) && !defined(__MATH_H) && !defined(__cmath__)
 154.219 +#      include <fp.h>
 154.220 +#    endif
 154.221 +#  else
 154.222 +#    include <math.h>
 154.223 +#  endif
 154.224 +#  if defined(_AMIGA) && defined(__SASC) && defined(_M68881)
 154.225 +     /* Amiga SAS/C: We must include builtin FPU functions when compiling using
 154.226 +      * MATH=68881
 154.227 +      */
 154.228 +#    include <m68881.h>
 154.229 +#  endif
 154.230 +#endif
 154.231 +
 154.232 +/* This provides the non-ANSI (far) memory allocation routines. */
 154.233 +#if defined(__TURBOC__) && defined(__MSDOS__)
 154.234 +#  include <mem.h>
 154.235 +#  include <alloc.h>
 154.236 +#endif
 154.237 +
 154.238 +#if defined(WIN32) || defined(_Windows) || defined(_WINDOWS) || \
 154.239 +    defined(_WIN32) || defined(__WIN32__)
 154.240 +#  include <windows.h>  /* defines _WINDOWS_ macro */
 154.241 +#endif
 154.242 +
 154.243 +/* Moved here around 1.5.0beta36 from pngconf.h */
 154.244 +/* Users may want to use these so they are not private.  Any library
 154.245 + * functions that are passed far data must be model-independent.
 154.246 + */
 154.247 +
 154.248 +/* Memory model/platform independent fns */
 154.249 +#ifndef PNG_ABORT
 154.250 +#  ifdef _WINDOWS_
 154.251 +#    define PNG_ABORT() ExitProcess(0)
 154.252 +#  else
 154.253 +#    define PNG_ABORT() abort()
 154.254 +#  endif
 154.255 +#endif
 154.256 +
 154.257 +#ifdef USE_FAR_KEYWORD
 154.258 +/* Use this to make far-to-near assignments */
 154.259 +#  define CHECK   1
 154.260 +#  define NOCHECK 0
 154.261 +#  define CVT_PTR(ptr) (png_far_to_near(png_ptr,ptr,CHECK))
 154.262 +#  define CVT_PTR_NOCHECK(ptr) (png_far_to_near(png_ptr,ptr,NOCHECK))
 154.263 +#  define png_strlen  _fstrlen
 154.264 +#  define png_memcmp  _fmemcmp    /* SJT: added */
 154.265 +#  define png_memcpy  _fmemcpy
 154.266 +#  define png_memset  _fmemset
 154.267 +#else
 154.268 +#  ifdef _WINDOWS_  /* Favor Windows over C runtime fns */
 154.269 +#    define CVT_PTR(ptr)         (ptr)
 154.270 +#    define CVT_PTR_NOCHECK(ptr) (ptr)
 154.271 +#    define png_strlen  lstrlenA
 154.272 +#    define png_memcmp  memcmp
 154.273 +#    define png_memcpy  CopyMemory
 154.274 +#    define png_memset  memset
 154.275 +#  else
 154.276 +#    define CVT_PTR(ptr)         (ptr)
 154.277 +#    define CVT_PTR_NOCHECK(ptr) (ptr)
 154.278 +#    define png_strlen  strlen
 154.279 +#    define png_memcmp  memcmp      /* SJT: added */
 154.280 +#    define png_memcpy  memcpy
 154.281 +#    define png_memset  memset
 154.282 +#  endif
 154.283 +#endif
 154.284 +/* End of memory model/platform independent support */
 154.285 +/* End of 1.5.0beta36 move from pngconf.h */
 154.286 +
 154.287 +/* CONSTANTS and UTILITY MACROS
 154.288 + * These are used internally by libpng and not exposed in the API
 154.289 + */
 154.290 +
 154.291 +/* Various modes of operation.  Note that after an init, mode is set to
 154.292 + * zero automatically when the structure is created.  Three of these
 154.293 + * are defined in png.h because they need to be visible to applications
 154.294 + * that call png_set_unknown_chunk().
 154.295 + */
 154.296 +/* #define PNG_HAVE_IHDR            0x01 (defined in png.h) */
 154.297 +/* #define PNG_HAVE_PLTE            0x02 (defined in png.h) */
 154.298 +#define PNG_HAVE_IDAT               0x04
 154.299 +/* #define PNG_AFTER_IDAT           0x08 (defined in png.h) */
 154.300 +#define PNG_HAVE_IEND               0x10
 154.301 +#define PNG_HAVE_gAMA               0x20
 154.302 +#define PNG_HAVE_cHRM               0x40
 154.303 +#define PNG_HAVE_sRGB               0x80
 154.304 +#define PNG_HAVE_CHUNK_HEADER      0x100
 154.305 +#define PNG_WROTE_tIME             0x200
 154.306 +#define PNG_WROTE_INFO_BEFORE_PLTE 0x400
 154.307 +#define PNG_BACKGROUND_IS_GRAY     0x800
 154.308 +#define PNG_HAVE_PNG_SIGNATURE    0x1000
 154.309 +#define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000 /* Have another chunk after IDAT */
 154.310 +
 154.311 +/* Flags for the transformations the PNG library does on the image data */
 154.312 +#define PNG_BGR                 0x0001
 154.313 +#define PNG_INTERLACE           0x0002
 154.314 +#define PNG_PACK                0x0004
 154.315 +#define PNG_SHIFT               0x0008
 154.316 +#define PNG_SWAP_BYTES          0x0010
 154.317 +#define PNG_INVERT_MONO         0x0020
 154.318 +#define PNG_QUANTIZE            0x0040
 154.319 +#define PNG_COMPOSE             0x0080     /* Was PNG_BACKGROUND */
 154.320 +#define PNG_BACKGROUND_EXPAND   0x0100
 154.321 +#define PNG_EXPAND_16           0x0200     /* Added to libpng 1.5.2 */
 154.322 +#define PNG_16_TO_8             0x0400     /* Becomes 'chop' in 1.5.4 */
 154.323 +#define PNG_RGBA                0x0800
 154.324 +#define PNG_EXPAND              0x1000
 154.325 +#define PNG_GAMMA               0x2000
 154.326 +#define PNG_GRAY_TO_RGB         0x4000
 154.327 +#define PNG_FILLER              0x8000L
 154.328 +#define PNG_PACKSWAP           0x10000L
 154.329 +#define PNG_SWAP_ALPHA         0x20000L
 154.330 +#define PNG_STRIP_ALPHA        0x40000L
 154.331 +#define PNG_INVERT_ALPHA       0x80000L
 154.332 +#define PNG_USER_TRANSFORM    0x100000L
 154.333 +#define PNG_RGB_TO_GRAY_ERR   0x200000L
 154.334 +#define PNG_RGB_TO_GRAY_WARN  0x400000L
 154.335 +#define PNG_RGB_TO_GRAY       0x600000L  /* two bits, RGB_TO_GRAY_ERR|WARN */
 154.336 +#define PNG_ENCODE_ALPHA      0x800000L  /* Added to libpng-1.5.4 */
 154.337 +#define PNG_ADD_ALPHA         0x1000000L  /* Added to libpng-1.2.7 */
 154.338 +#define PNG_EXPAND_tRNS       0x2000000L  /* Added to libpng-1.2.9 */
 154.339 +#define PNG_SCALE_16_TO_8     0x4000000L  /* Added to libpng-1.5.4 */
 154.340 +                       /*   0x8000000L  unused */
 154.341 +                       /*  0x10000000L  unused */
 154.342 +                       /*  0x20000000L  unused */
 154.343 +                       /*  0x40000000L  unused */
 154.344 +
 154.345 +/* Flags for png_create_struct */
 154.346 +#define PNG_STRUCT_PNG   0x0001
 154.347 +#define PNG_STRUCT_INFO  0x0002
 154.348 +
 154.349 +/* Scaling factor for filter heuristic weighting calculations */
 154.350 +#define PNG_WEIGHT_FACTOR (1<<(PNG_WEIGHT_SHIFT))
 154.351 +#define PNG_COST_FACTOR (1<<(PNG_COST_SHIFT))
 154.352 +
 154.353 +/* Flags for the png_ptr->flags rather than declaring a byte for each one */
 154.354 +#define PNG_FLAG_ZLIB_CUSTOM_STRATEGY     0x0001
 154.355 +#define PNG_FLAG_ZLIB_CUSTOM_LEVEL        0x0002
 154.356 +#define PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL    0x0004
 154.357 +#define PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS  0x0008
 154.358 +#define PNG_FLAG_ZLIB_CUSTOM_METHOD       0x0010
 154.359 +#define PNG_FLAG_ZLIB_FINISHED            0x0020
 154.360 +#define PNG_FLAG_ROW_INIT                 0x0040
 154.361 +#define PNG_FLAG_FILLER_AFTER             0x0080
 154.362 +#define PNG_FLAG_CRC_ANCILLARY_USE        0x0100
 154.363 +#define PNG_FLAG_CRC_ANCILLARY_NOWARN     0x0200
 154.364 +#define PNG_FLAG_CRC_CRITICAL_USE         0x0400
 154.365 +#define PNG_FLAG_CRC_CRITICAL_IGNORE      0x0800
 154.366 +#define PNG_FLAG_ASSUME_sRGB              0x1000  /* Added to libpng-1.5.4 */
 154.367 +#define PNG_FLAG_OPTIMIZE_ALPHA           0x2000  /* Added to libpng-1.5.4 */
 154.368 +#define PNG_FLAG_DETECT_UNINITIALIZED     0x4000  /* Added to libpng-1.5.4 */
 154.369 +#define PNG_FLAG_KEEP_UNKNOWN_CHUNKS      0x8000L
 154.370 +#define PNG_FLAG_KEEP_UNSAFE_CHUNKS       0x10000L
 154.371 +#define PNG_FLAG_LIBRARY_MISMATCH         0x20000L
 154.372 +#define PNG_FLAG_STRIP_ERROR_NUMBERS      0x40000L
 154.373 +#define PNG_FLAG_STRIP_ERROR_TEXT         0x80000L
 154.374 +#define PNG_FLAG_MALLOC_NULL_MEM_OK       0x100000L
 154.375 +                                  /*      0x200000L  unused */
 154.376 +                                  /*      0x400000L  unused */
 154.377 +#define PNG_FLAG_BENIGN_ERRORS_WARN       0x800000L  /* Added to libpng-1.4.0 */
 154.378 +#define PNG_FLAG_ZTXT_CUSTOM_STRATEGY    0x1000000L  /* 5 lines added */
 154.379 +#define PNG_FLAG_ZTXT_CUSTOM_LEVEL       0x2000000L  /* to libpng-1.5.4 */
 154.380 +#define PNG_FLAG_ZTXT_CUSTOM_MEM_LEVEL   0x4000000L
 154.381 +#define PNG_FLAG_ZTXT_CUSTOM_WINDOW_BITS 0x8000000L
 154.382 +#define PNG_FLAG_ZTXT_CUSTOM_METHOD      0x10000000L
 154.383 +                                  /*     0x20000000L  unused */
 154.384 +                                  /*     0x40000000L  unused */
 154.385 +
 154.386 +#define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \
 154.387 +                                     PNG_FLAG_CRC_ANCILLARY_NOWARN)
 154.388 +
 154.389 +#define PNG_FLAG_CRC_CRITICAL_MASK  (PNG_FLAG_CRC_CRITICAL_USE | \
 154.390 +                                     PNG_FLAG_CRC_CRITICAL_IGNORE)
 154.391 +
 154.392 +#define PNG_FLAG_CRC_MASK           (PNG_FLAG_CRC_ANCILLARY_MASK | \
 154.393 +                                     PNG_FLAG_CRC_CRITICAL_MASK)
 154.394 +
 154.395 +/* zlib.h declares a magic type 'uInt' that limits the amount of data that zlib
 154.396 + * can handle at once.  This type need be no larger than 16 bits (so maximum of
 154.397 + * 65535), this define allows us to discover how big it is, but limited by the
 154.398 + * maximuum for png_size_t.  The value can be overriden in a library build
 154.399 + * (pngusr.h, or set it in CPPFLAGS) and it works to set it to a considerably
 154.400 + * lower value (e.g. 255 works).  A lower value may help memory usage (slightly)
 154.401 + * and may even improve performance on some systems (and degrade it on others.)
 154.402 + */
 154.403 +#ifndef ZLIB_IO_MAX
 154.404 +#  define ZLIB_IO_MAX ((uInt)-1)
 154.405 +#endif
 154.406 +
 154.407 +/* Save typing and make code easier to understand */
 154.408 +
 154.409 +#define PNG_COLOR_DIST(c1, c2) (abs((int)((c1).red) - (int)((c2).red)) + \
 154.410 +   abs((int)((c1).green) - (int)((c2).green)) + \
 154.411 +   abs((int)((c1).blue) - (int)((c2).blue)))
 154.412 +
 154.413 +/* Added to libpng-1.2.6 JB */
 154.414 +#define PNG_ROWBYTES(pixel_bits, width) \
 154.415 +    ((pixel_bits) >= 8 ? \
 154.416 +    ((png_size_t)(width) * (((png_size_t)(pixel_bits)) >> 3)) : \
 154.417 +    (( ((png_size_t)(width) * ((png_size_t)(pixel_bits))) + 7) >> 3) )
 154.418 +
 154.419 +/* PNG_OUT_OF_RANGE returns true if value is outside the range
 154.420 + * ideal-delta..ideal+delta.  Each argument is evaluated twice.
 154.421 + * "ideal" and "delta" should be constants, normally simple
 154.422 + * integers, "value" a variable. Added to libpng-1.2.6 JB
 154.423 + */
 154.424 +#define PNG_OUT_OF_RANGE(value, ideal, delta) \
 154.425 +   ( (value) < (ideal)-(delta) || (value) > (ideal)+(delta) )
 154.426 +
 154.427 +/* Conversions between fixed and floating point, only defined if
 154.428 + * required (to make sure the code doesn't accidentally use float
 154.429 + * when it is supposedly disabled.)
 154.430 + */
 154.431 +#ifdef PNG_FLOATING_POINT_SUPPORTED
 154.432 +/* The floating point conversion can't overflow, though it can and
 154.433 + * does lose accuracy relative to the original fixed point value.
 154.434 + * In practice this doesn't matter because png_fixed_point only
 154.435 + * stores numbers with very low precision.  The png_ptr and s
 154.436 + * arguments are unused by default but are there in case error
 154.437 + * checking becomes a requirement.
 154.438 + */
 154.439 +#define png_float(png_ptr, fixed, s) (.00001 * (fixed))
 154.440 +
 154.441 +/* The fixed point conversion performs range checking and evaluates
 154.442 + * its argument multiple times, so must be used with care.  The
 154.443 + * range checking uses the PNG specification values for a signed
 154.444 + * 32 bit fixed point value except that the values are deliberately
 154.445 + * rounded-to-zero to an integral value - 21474 (21474.83 is roughly
 154.446 + * (2^31-1) * 100000). 's' is a string that describes the value being
 154.447 + * converted.
 154.448 + *
 154.449 + * NOTE: this macro will raise a png_error if the range check fails,
 154.450 + * therefore it is normally only appropriate to use this on values
 154.451 + * that come from API calls or other sources where an out of range
 154.452 + * error indicates a programming error, not a data error!
 154.453 + *
 154.454 + * NOTE: by default this is off - the macro is not used - because the
 154.455 + * function call saves a lot of code.
 154.456 + */
 154.457 +#ifdef PNG_FIXED_POINT_MACRO_SUPPORTED
 154.458 +#define png_fixed(png_ptr, fp, s) ((fp) <= 21474 && (fp) >= -21474 ?\
 154.459 +    ((png_fixed_point)(100000 * (fp))) : (png_fixed_error(png_ptr, s),0))
 154.460 +#else
 154.461 +PNG_EXTERN png_fixed_point png_fixed PNGARG((png_structp png_ptr, double fp,
 154.462 +   png_const_charp text));
 154.463 +#endif
 154.464 +#endif
 154.465 +
 154.466 +/* Constant strings for known chunk types.  If you need to add a chunk,
 154.467 + * define the name here, and add an invocation of the macro wherever it's
 154.468 + * needed.
 154.469 + */
 154.470 +#define PNG_IHDR PNG_CONST png_byte png_IHDR[5] = { 73,  72,  68,  82, '\0'}
 154.471 +#define PNG_IDAT PNG_CONST png_byte png_IDAT[5] = { 73,  68,  65,  84, '\0'}
 154.472 +#define PNG_IEND PNG_CONST png_byte png_IEND[5] = { 73,  69,  78,  68, '\0'}
 154.473 +#define PNG_PLTE PNG_CONST png_byte png_PLTE[5] = { 80,  76,  84,  69, '\0'}
 154.474 +#define PNG_bKGD PNG_CONST png_byte png_bKGD[5] = { 98,  75,  71,  68, '\0'}
 154.475 +#define PNG_cHRM PNG_CONST png_byte png_cHRM[5] = { 99,  72,  82,  77, '\0'}
 154.476 +#define PNG_gAMA PNG_CONST png_byte png_gAMA[5] = {103,  65,  77,  65, '\0'}
 154.477 +#define PNG_hIST PNG_CONST png_byte png_hIST[5] = {104,  73,  83,  84, '\0'}
 154.478 +#define PNG_iCCP PNG_CONST png_byte png_iCCP[5] = {105,  67,  67,  80, '\0'}
 154.479 +#define PNG_iTXt PNG_CONST png_byte png_iTXt[5] = {105,  84,  88, 116, '\0'}
 154.480 +#define PNG_oFFs PNG_CONST png_byte png_oFFs[5] = {111,  70,  70, 115, '\0'}
 154.481 +#define PNG_pCAL PNG_CONST png_byte png_pCAL[5] = {112,  67,  65,  76, '\0'}
 154.482 +#define PNG_sCAL PNG_CONST png_byte png_sCAL[5] = {115,  67,  65,  76, '\0'}
 154.483 +#define PNG_pHYs PNG_CONST png_byte png_pHYs[5] = {112,  72,  89, 115, '\0'}
 154.484 +#define PNG_sBIT PNG_CONST png_byte png_sBIT[5] = {115,  66,  73,  84, '\0'}
 154.485 +#define PNG_sPLT PNG_CONST png_byte png_sPLT[5] = {115,  80,  76,  84, '\0'}
 154.486 +#define PNG_sRGB PNG_CONST png_byte png_sRGB[5] = {115,  82,  71,  66, '\0'}
 154.487 +#define PNG_sTER PNG_CONST png_byte png_sTER[5] = {115,  84,  69,  82, '\0'}
 154.488 +#define PNG_tEXt PNG_CONST png_byte png_tEXt[5] = {116,  69,  88, 116, '\0'}
 154.489 +#define PNG_tIME PNG_CONST png_byte png_tIME[5] = {116,  73,  77,  69, '\0'}
 154.490 +#define PNG_tRNS PNG_CONST png_byte png_tRNS[5] = {116,  82,  78,  83, '\0'}
 154.491 +#define PNG_zTXt PNG_CONST png_byte png_zTXt[5] = {122,  84,  88, 116, '\0'}
 154.492 +
 154.493 +/* Gamma values (new at libpng-1.5.4): */
 154.494 +#define PNG_GAMMA_MAC_OLD 151724  /* Assume '1.8' is really 2.2/1.45! */
 154.495 +#define PNG_GAMMA_MAC_INVERSE 65909
 154.496 +#define PNG_GAMMA_sRGB_INVERSE 45455
 154.497 +
 154.498 +
 154.499 +/* Inhibit C++ name-mangling for libpng functions but not for system calls. */
 154.500 +#ifdef __cplusplus
 154.501 +extern "C" {
 154.502 +#endif /* __cplusplus */
 154.503 +
 154.504 +/* These functions are used internally in the code.  They generally
 154.505 + * shouldn't be used unless you are writing code to add or replace some
 154.506 + * functionality in libpng.  More information about most functions can
 154.507 + * be found in the files where the functions are located.
 154.508 + */
 154.509 +
 154.510 +/* Check the user version string for compatibility, returns false if the version
 154.511 + * numbers aren't compatible.
 154.512 + */
 154.513 +PNG_EXTERN int png_user_version_check(png_structp png_ptr,
 154.514 +   png_const_charp user_png_ver);
 154.515 +
 154.516 +/* Allocate memory for an internal libpng struct */
 154.517 +PNG_EXTERN PNG_FUNCTION(png_voidp,png_create_struct,PNGARG((int type)),
 154.518 +   PNG_ALLOCATED);
 154.519 +
 154.520 +/* Free memory from internal libpng struct */
 154.521 +PNG_EXTERN void png_destroy_struct PNGARG((png_voidp struct_ptr));
 154.522 +
 154.523 +PNG_EXTERN PNG_FUNCTION(png_voidp,png_create_struct_2,
 154.524 +   PNGARG((int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)),
 154.525 +   PNG_ALLOCATED);
 154.526 +PNG_EXTERN void png_destroy_struct_2 PNGARG((png_voidp struct_ptr,
 154.527 +    png_free_ptr free_fn, png_voidp mem_ptr));
 154.528 +
 154.529 +/* Free any memory that info_ptr points to and reset struct. */
 154.530 +PNG_EXTERN void png_info_destroy PNGARG((png_structp png_ptr,
 154.531 +    png_infop info_ptr));
 154.532 +
 154.533 +/* Function to allocate memory for zlib.  PNGAPI is disallowed. */
 154.534 +PNG_EXTERN PNG_FUNCTION(voidpf,png_zalloc,PNGARG((voidpf png_ptr, uInt items,
 154.535 +   uInt size)),PNG_ALLOCATED);
 154.536 +
 154.537 +/* Function to free memory for zlib.  PNGAPI is disallowed. */
 154.538 +PNG_EXTERN void png_zfree PNGARG((voidpf png_ptr, voidpf ptr));
 154.539 +
 154.540 +/* Next four functions are used internally as callbacks.  PNGCBAPI is required
 154.541 + * but not PNG_EXPORT.  PNGAPI added at libpng version 1.2.3, changed to
 154.542 + * PNGCBAPI at 1.5.0
 154.543 + */
 154.544 +
 154.545 +PNG_EXTERN void PNGCBAPI png_default_read_data PNGARG((png_structp png_ptr,
 154.546 +    png_bytep data, png_size_t length));
 154.547 +
 154.548 +#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
 154.549 +PNG_EXTERN void PNGCBAPI png_push_fill_buffer PNGARG((png_structp png_ptr,
 154.550 +    png_bytep buffer, png_size_t length));
 154.551 +#endif
 154.552 +
 154.553 +PNG_EXTERN void PNGCBAPI png_default_write_data PNGARG((png_structp png_ptr,
 154.554 +    png_bytep data, png_size_t length));
 154.555 +
 154.556 +#ifdef PNG_WRITE_FLUSH_SUPPORTED
 154.557 +#  ifdef PNG_STDIO_SUPPORTED
 154.558 +PNG_EXTERN void PNGCBAPI png_default_flush PNGARG((png_structp png_ptr));
 154.559 +#  endif
 154.560 +#endif
 154.561 +
 154.562 +/* Reset the CRC variable */
 154.563 +PNG_EXTERN void png_reset_crc PNGARG((png_structp png_ptr));
 154.564 +
 154.565 +/* Write the "data" buffer to whatever output you are using */
 154.566 +PNG_EXTERN void png_write_data PNGARG((png_structp png_ptr,
 154.567 +    png_const_bytep data, png_size_t length));
 154.568 +
 154.569 +/* Read and check the PNG file signature */
 154.570 +PNG_EXTERN void png_read_sig PNGARG((png_structp png_ptr, png_infop info_ptr));
 154.571 +
 154.572 +/* Read the chunk header (length + type name) */
 154.573 +PNG_EXTERN png_uint_32 png_read_chunk_header PNGARG((png_structp png_ptr));
 154.574 +
 154.575 +/* Read data from whatever input you are using into the "data" buffer */
 154.576 +PNG_EXTERN void png_read_data PNGARG((png_structp png_ptr, png_bytep data,
 154.577 +    png_size_t length));
 154.578 +
 154.579 +/* Read bytes into buf, and update png_ptr->crc */
 154.580 +PNG_EXTERN void png_crc_read PNGARG((png_structp png_ptr, png_bytep buf,
 154.581 +    png_size_t length));
 154.582 +
 154.583 +/* Decompress data in a chunk that uses compression */
 154.584 +#if defined(PNG_READ_COMPRESSED_TEXT_SUPPORTED)
 154.585 +PNG_EXTERN void png_decompress_chunk PNGARG((png_structp png_ptr,
 154.586 +    int comp_type, png_size_t chunklength, png_size_t prefix_length,
 154.587 +    png_size_t *data_length));
 154.588 +#endif
 154.589 +
 154.590 +/* Read "skip" bytes, read the file crc, and (optionally) verify png_ptr->crc */
 154.591 +PNG_EXTERN int png_crc_finish PNGARG((png_structp png_ptr, png_uint_32 skip));
 154.592 +
 154.593 +/* Read the CRC from the file and compare it to the libpng calculated CRC */
 154.594 +PNG_EXTERN int png_crc_error PNGARG((png_structp png_ptr));
 154.595 +
 154.596 +/* Calculate the CRC over a section of data.  Note that we are only
 154.597 + * passing a maximum of 64K on systems that have this as a memory limit,
 154.598 + * since this is the maximum buffer size we can specify.
 154.599 + */
 154.600 +PNG_EXTERN void png_calculate_crc PNGARG((png_structp png_ptr,
 154.601 +    png_const_bytep ptr, png_size_t length));
 154.602 +
 154.603 +#ifdef PNG_WRITE_FLUSH_SUPPORTED
 154.604 +PNG_EXTERN void png_flush PNGARG((png_structp png_ptr));
 154.605 +#endif
 154.606 +
 154.607 +/* Write various chunks */
 154.608 +
 154.609 +/* Write the IHDR chunk, and update the png_struct with the necessary
 154.610 + * information.
 154.611 + */
 154.612 +PNG_EXTERN void png_write_IHDR PNGARG((png_structp png_ptr, png_uint_32 width,
 154.613 +    png_uint_32 height,
 154.614 +    int bit_depth, int color_type, int compression_method, int filter_method,
 154.615 +    int interlace_method));
 154.616 +
 154.617 +PNG_EXTERN void png_write_PLTE PNGARG((png_structp png_ptr,
 154.618 +    png_const_colorp palette, png_uint_32 num_pal));
 154.619 +
 154.620 +PNG_EXTERN void png_write_IDAT PNGARG((png_structp png_ptr, png_bytep data,
 154.621 +    png_size_t length));
 154.622 +
 154.623 +PNG_EXTERN void png_write_IEND PNGARG((png_structp png_ptr));
 154.624 +
 154.625 +#ifdef PNG_WRITE_gAMA_SUPPORTED
 154.626 +#  ifdef PNG_FLOATING_POINT_SUPPORTED
 154.627 +PNG_EXTERN void png_write_gAMA PNGARG((png_structp png_ptr, double file_gamma));
 154.628 +#  endif
 154.629 +#  ifdef PNG_FIXED_POINT_SUPPORTED
 154.630 +PNG_EXTERN void png_write_gAMA_fixed PNGARG((png_structp png_ptr,
 154.631 +    png_fixed_point file_gamma));
 154.632 +#  endif
 154.633 +#endif
 154.634 +
 154.635 +#ifdef PNG_WRITE_sBIT_SUPPORTED
 154.636 +PNG_EXTERN void png_write_sBIT PNGARG((png_structp png_ptr,
 154.637 +    png_const_color_8p sbit, int color_type));
 154.638 +#endif
 154.639 +
 154.640 +#ifdef PNG_WRITE_cHRM_SUPPORTED
 154.641 +#  ifdef PNG_FLOATING_POINT_SUPPORTED
 154.642 +PNG_EXTERN void png_write_cHRM PNGARG((png_structp png_ptr,
 154.643 +    double white_x, double white_y,
 154.644 +    double red_x, double red_y, double green_x, double green_y,
 154.645 +    double blue_x, double blue_y));
 154.646 +#  endif
 154.647 +PNG_EXTERN void png_write_cHRM_fixed PNGARG((png_structp png_ptr,
 154.648 +    png_fixed_point int_white_x, png_fixed_point int_white_y,
 154.649 +    png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point
 154.650 +    int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x,
 154.651 +    png_fixed_point int_blue_y));
 154.652 +#endif
 154.653 +
 154.654 +#ifdef PNG_WRITE_sRGB_SUPPORTED
 154.655 +PNG_EXTERN void png_write_sRGB PNGARG((png_structp png_ptr,
 154.656 +    int intent));
 154.657 +#endif
 154.658 +
 154.659 +#ifdef PNG_WRITE_iCCP_SUPPORTED
 154.660 +PNG_EXTERN void png_write_iCCP PNGARG((png_structp png_ptr,
 154.661 +    png_const_charp name, int compression_type,
 154.662 +    png_const_charp profile, int proflen));
 154.663 +   /* Note to maintainer: profile should be png_bytep */
 154.664 +#endif
 154.665 +
 154.666 +#ifdef PNG_WRITE_sPLT_SUPPORTED
 154.667 +PNG_EXTERN void png_write_sPLT PNGARG((png_structp png_ptr,
 154.668 +    png_const_sPLT_tp palette));
 154.669 +#endif
 154.670 +
 154.671 +#ifdef PNG_WRITE_tRNS_SUPPORTED
 154.672 +PNG_EXTERN void png_write_tRNS PNGARG((png_structp png_ptr,
 154.673 +    png_const_bytep trans, png_const_color_16p values, int number,
 154.674 +    int color_type));
 154.675 +#endif
 154.676 +
 154.677 +#ifdef PNG_WRITE_bKGD_SUPPORTED
 154.678 +PNG_EXTERN void png_write_bKGD PNGARG((png_structp png_ptr,
 154.679 +    png_const_color_16p values, int color_type));
 154.680 +#endif
 154.681 +
 154.682 +#ifdef PNG_WRITE_hIST_SUPPORTED
 154.683 +PNG_EXTERN void png_write_hIST PNGARG((png_structp png_ptr,
 154.684 +    png_const_uint_16p hist, int num_hist));
 154.685 +#endif
 154.686 +
 154.687 +/* Chunks that have keywords */
 154.688 +#if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \
 154.689 +    defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
 154.690 +PNG_EXTERN png_size_t png_check_keyword PNGARG((png_structp png_ptr,
 154.691 +    png_const_charp key, png_charpp new_key));
 154.692 +#endif
 154.693 +
 154.694 +#ifdef PNG_WRITE_tEXt_SUPPORTED
 154.695 +PNG_EXTERN void png_write_tEXt PNGARG((png_structp png_ptr, png_const_charp key,
 154.696 +    png_const_charp text, png_size_t text_len));
 154.697 +#endif
 154.698 +
 154.699 +#ifdef PNG_WRITE_zTXt_SUPPORTED
 154.700 +PNG_EXTERN void png_write_zTXt PNGARG((png_structp png_ptr, png_const_charp key,
 154.701 +    png_const_charp text, png_size_t text_len, int compression));
 154.702 +#endif
 154.703 +
 154.704 +#ifdef PNG_WRITE_iTXt_SUPPORTED
 154.705 +PNG_EXTERN void png_write_iTXt PNGARG((png_structp png_ptr,
 154.706 +    int compression, png_const_charp key, png_const_charp lang,
 154.707 +    png_const_charp lang_key, png_const_charp text));
 154.708 +#endif
 154.709 +
 154.710 +#ifdef PNG_TEXT_SUPPORTED  /* Added at version 1.0.14 and 1.2.4 */
 154.711 +PNG_EXTERN int png_set_text_2 PNGARG((png_structp png_ptr,
 154.712 +    png_infop info_ptr, png_const_textp text_ptr, int num_text));
 154.713 +#endif
 154.714 +
 154.715 +#ifdef PNG_WRITE_oFFs_SUPPORTED
 154.716 +PNG_EXTERN void png_write_oFFs PNGARG((png_structp png_ptr,
 154.717 +    png_int_32 x_offset, png_int_32 y_offset, int unit_type));
 154.718 +#endif
 154.719 +
 154.720 +#ifdef PNG_WRITE_pCAL_SUPPORTED
 154.721 +PNG_EXTERN void png_write_pCAL PNGARG((png_structp png_ptr, png_charp purpose,
 154.722 +    png_int_32 X0, png_int_32 X1, int type, int nparams,
 154.723 +    png_const_charp units, png_charpp params));
 154.724 +#endif
 154.725 +
 154.726 +#ifdef PNG_WRITE_pHYs_SUPPORTED
 154.727 +PNG_EXTERN void png_write_pHYs PNGARG((png_structp png_ptr,
 154.728 +    png_uint_32 x_pixels_per_unit, png_uint_32 y_pixels_per_unit,
 154.729 +    int unit_type));
 154.730 +#endif
 154.731 +
 154.732 +#ifdef PNG_WRITE_tIME_SUPPORTED
 154.733 +PNG_EXTERN void png_write_tIME PNGARG((png_structp png_ptr,
 154.734 +    png_const_timep mod_time));
 154.735 +#endif
 154.736 +
 154.737 +#ifdef PNG_WRITE_sCAL_SUPPORTED
 154.738 +PNG_EXTERN void png_write_sCAL_s PNGARG((png_structp png_ptr,
 154.739 +    int unit, png_const_charp width, png_const_charp height));
 154.740 +#endif
 154.741 +
 154.742 +/* Called when finished processing a row of data */
 154.743 +PNG_EXTERN void png_write_finish_row PNGARG((png_structp png_ptr));
 154.744 +
 154.745 +/* Internal use only.   Called before first row of data */
 154.746 +PNG_EXTERN void png_write_start_row PNGARG((png_structp png_ptr));
 154.747 +
 154.748 +/* Combine a row of data, dealing with alpha, etc. if requested */
 154.749 +PNG_EXTERN void png_combine_row PNGARG((png_structp png_ptr, png_bytep row,
 154.750 +    int mask));
 154.751 +
 154.752 +#ifdef PNG_READ_INTERLACING_SUPPORTED
 154.753 +/* Expand an interlaced row */
 154.754 +/* OLD pre-1.0.9 interface:
 154.755 +PNG_EXTERN void png_do_read_interlace PNGARG((png_row_infop row_info,
 154.756 +    png_bytep row, int pass, png_uint_32 transformations));
 154.757 + */
 154.758 +PNG_EXTERN void png_do_read_interlace PNGARG((png_structp png_ptr));
 154.759 +#endif
 154.760 +
 154.761 +/* GRR TO DO (2.0 or whenever):  simplify other internal calling interfaces */
 154.762 +
 154.763 +#ifdef PNG_WRITE_INTERLACING_SUPPORTED
 154.764 +/* Grab pixels out of a row for an interlaced pass */
 154.765 +PNG_EXTERN void png_do_write_interlace PNGARG((png_row_infop row_info,
 154.766 +    png_bytep row, int pass));
 154.767 +#endif
 154.768 +
 154.769 +/* Unfilter a row */
 154.770 +PNG_EXTERN void png_read_filter_row PNGARG((png_structp png_ptr,
 154.771 +    png_row_infop row_info, png_bytep row, png_const_bytep prev_row,
 154.772 +    int filter));
 154.773 +
 154.774 +/* Choose the best filter to use and filter the row data */
 154.775 +PNG_EXTERN void png_write_find_filter PNGARG((png_structp png_ptr,
 154.776 +    png_row_infop row_info));
 154.777 +
 154.778 +/* Finish a row while reading, dealing with interlacing passes, etc. */
 154.779 +PNG_EXTERN void png_read_finish_row PNGARG((png_structp png_ptr));
 154.780 +
 154.781 +/* Initialize the row buffers, etc. */
 154.782 +PNG_EXTERN void png_read_start_row PNGARG((png_structp png_ptr));
 154.783 +
 154.784 +#ifdef PNG_READ_TRANSFORMS_SUPPORTED
 154.785 +/* Optional call to update the users info structure */
 154.786 +PNG_EXTERN void png_read_transform_info PNGARG((png_structp png_ptr,
 154.787 +    png_infop info_ptr));
 154.788 +#endif
 154.789 +
 154.790 +/* These are the functions that do the transformations */
 154.791 +#ifdef PNG_READ_FILLER_SUPPORTED
 154.792 +PNG_EXTERN void png_do_read_filler PNGARG((png_row_infop row_info,
 154.793 +    png_bytep row, png_uint_32 filler, png_uint_32 flags));
 154.794 +#endif
 154.795 +
 154.796 +#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED
 154.797 +PNG_EXTERN void png_do_read_swap_alpha PNGARG((png_row_infop row_info,
 154.798 +    png_bytep row));
 154.799 +#endif
 154.800 +
 154.801 +#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED
 154.802 +PNG_EXTERN void png_do_write_swap_alpha PNGARG((png_row_infop row_info,
 154.803 +    png_bytep row));
 154.804 +#endif
 154.805 +
 154.806 +#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED
 154.807 +PNG_EXTERN void png_do_read_invert_alpha PNGARG((png_row_infop row_info,
 154.808 +    png_bytep row));
 154.809 +#endif
 154.810 +
 154.811 +#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED
 154.812 +PNG_EXTERN void png_do_write_invert_alpha PNGARG((png_row_infop row_info,
 154.813 +    png_bytep row));
 154.814 +#endif
 154.815 +
 154.816 +#if defined(PNG_WRITE_FILLER_SUPPORTED) || \
 154.817 +    defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
 154.818 +PNG_EXTERN void png_do_strip_channel PNGARG((png_row_infop row_info,
 154.819 +    png_bytep row, int at_start));
 154.820 +#endif
 154.821 +
 154.822 +#ifdef PNG_16BIT_SUPPORTED
 154.823 +#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
 154.824 +PNG_EXTERN void png_do_swap PNGARG((png_row_infop row_info,
 154.825 +    png_bytep row));
 154.826 +#endif
 154.827 +#endif
 154.828 +
 154.829 +#if defined(PNG_READ_PACKSWAP_SUPPORTED) || \
 154.830 +    defined(PNG_WRITE_PACKSWAP_SUPPORTED)
 154.831 +PNG_EXTERN void png_do_packswap PNGARG((png_row_infop row_info,
 154.832 +    png_bytep row));
 154.833 +#endif
 154.834 +
 154.835 +#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
 154.836 +PNG_EXTERN int png_do_rgb_to_gray PNGARG((png_structp png_ptr,
 154.837 +    png_row_infop row_info, png_bytep row));
 154.838 +#endif
 154.839 +
 154.840 +#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
 154.841 +PNG_EXTERN void png_do_gray_to_rgb PNGARG((png_row_infop row_info,
 154.842 +    png_bytep row));
 154.843 +#endif
 154.844 +
 154.845 +#ifdef PNG_READ_PACK_SUPPORTED
 154.846 +PNG_EXTERN void png_do_unpack PNGARG((png_row_infop row_info,
 154.847 +    png_bytep row));
 154.848 +#endif
 154.849 +
 154.850 +#ifdef PNG_READ_SHIFT_SUPPORTED
 154.851 +PNG_EXTERN void png_do_unshift PNGARG((png_row_infop row_info,
 154.852 +    png_bytep row, png_const_color_8p sig_bits));
 154.853 +#endif
 154.854 +
 154.855 +#if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
 154.856 +PNG_EXTERN void png_do_invert PNGARG((png_row_infop row_info,
 154.857 +    png_bytep row));
 154.858 +#endif
 154.859 +
 154.860 +#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
 154.861 +PNG_EXTERN void png_do_scale_16_to_8 PNGARG((png_row_infop row_info,
 154.862 +    png_bytep row));
 154.863 +#endif
 154.864 +
 154.865 +#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED
 154.866 +PNG_EXTERN void png_do_chop PNGARG((png_row_infop row_info,
 154.867 +    png_bytep row));
 154.868 +#endif
 154.869 +
 154.870 +#ifdef PNG_READ_QUANTIZE_SUPPORTED
 154.871 +PNG_EXTERN void png_do_quantize PNGARG((png_row_infop row_info,
 154.872 +    png_bytep row, png_const_bytep palette_lookup,
 154.873 +    png_const_bytep quantize_lookup));
 154.874 +
 154.875 +#  ifdef PNG_CORRECT_PALETTE_SUPPORTED
 154.876 +PNG_EXTERN void png_correct_palette PNGARG((png_structp png_ptr,
 154.877 +    png_colorp palette, int num_palette));
 154.878 +#  endif
 154.879 +#endif
 154.880 +
 154.881 +#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
 154.882 +PNG_EXTERN void png_do_bgr PNGARG((png_row_infop row_info,
 154.883 +    png_bytep row));
 154.884 +#endif
 154.885 +
 154.886 +#ifdef PNG_WRITE_PACK_SUPPORTED
 154.887 +PNG_EXTERN void png_do_pack PNGARG((png_row_infop row_info,
 154.888 +   png_bytep row, png_uint_32 bit_depth));
 154.889 +#endif
 154.890 +
 154.891 +#ifdef PNG_WRITE_SHIFT_SUPPORTED
 154.892 +PNG_EXTERN void png_do_shift PNGARG((png_row_infop row_info,
 154.893 +    png_bytep row, png_const_color_8p bit_depth));
 154.894 +#endif
 154.895 +
 154.896 +#if defined(PNG_READ_BACKGROUND_SUPPORTED) ||\
 154.897 +    defined(PNG_READ_ALPHA_MODE_SUPPORTED)
 154.898 +PNG_EXTERN void png_do_compose PNGARG((png_row_infop row_info,
 154.899 +    png_bytep row, png_structp png_ptr));
 154.900 +#endif
 154.901 +
 154.902 +#ifdef PNG_READ_GAMMA_SUPPORTED
 154.903 +PNG_EXTERN void png_do_gamma PNGARG((png_row_infop row_info,
 154.904 +    png_bytep row, png_structp png_ptr));
 154.905 +#endif
 154.906 +
 154.907 +#ifdef PNG_READ_ALPHA_MODE_SUPPORTED
 154.908 +PNG_EXTERN void png_do_encode_alpha PNGARG((png_row_infop row_info,
 154.909 +   png_bytep row, png_structp png_ptr));
 154.910 +#endif
 154.911 +
 154.912 +#ifdef PNG_READ_EXPAND_SUPPORTED
 154.913 +PNG_EXTERN void png_do_expand_palette PNGARG((png_row_infop row_info,
 154.914 +    png_bytep row, png_const_colorp palette, png_const_bytep trans,
 154.915 +    int num_trans));
 154.916 +PNG_EXTERN void png_do_expand PNGARG((png_row_infop row_info,
 154.917 +    png_bytep row, png_const_color_16p trans_color));
 154.918 +#endif
 154.919 +
 154.920 +#ifdef PNG_READ_EXPAND_16_SUPPORTED
 154.921 +PNG_EXTERN void png_do_expand_16 PNGARG((png_row_infop row_info,
 154.922 +    png_bytep row));
 154.923 +#endif
 154.924 +
 154.925 +/* The following decodes the appropriate chunks, and does error correction,
 154.926 + * then calls the appropriate callback for the chunk if it is valid.
 154.927 + */
 154.928 +
 154.929 +/* Decode the IHDR chunk */
 154.930 +PNG_EXTERN void png_handle_IHDR PNGARG((png_structp png_ptr, png_infop info_ptr,
 154.931 +    png_uint_32 length));
 154.932 +PNG_EXTERN void png_handle_PLTE PNGARG((png_structp png_ptr, png_infop info_ptr,
 154.933 +    png_uint_32 length));
 154.934 +PNG_EXTERN void png_handle_IEND PNGARG((png_structp png_ptr, png_infop info_ptr,
 154.935 +    png_uint_32 length));
 154.936 +
 154.937 +#ifdef PNG_READ_bKGD_SUPPORTED
 154.938 +PNG_EXTERN void png_handle_bKGD PNGARG((png_structp png_ptr, png_infop info_ptr,
 154.939 +    png_uint_32 length));
 154.940 +#endif
 154.941 +
 154.942 +#ifdef PNG_READ_cHRM_SUPPORTED
 154.943 +PNG_EXTERN void png_handle_cHRM PNGARG((png_structp png_ptr, png_infop info_ptr,
 154.944 +    png_uint_32 length));
 154.945 +#endif
 154.946 +
 154.947 +#ifdef PNG_READ_gAMA_SUPPORTED
 154.948 +PNG_EXTERN void png_handle_gAMA PNGARG((png_structp png_ptr, png_infop info_ptr,
 154.949 +    png_uint_32 length));
 154.950 +#endif
 154.951 +
 154.952 +#ifdef PNG_READ_hIST_SUPPORTED
 154.953 +PNG_EXTERN void png_handle_hIST PNGARG((png_structp png_ptr, png_infop info_ptr,
 154.954 +    png_uint_32 length));
 154.955 +#endif
 154.956 +
 154.957 +#ifdef PNG_READ_iCCP_SUPPORTED
 154.958 +PNG_EXTERN void png_handle_iCCP PNGARG((png_structp png_ptr, png_infop info_ptr,
 154.959 +    png_uint_32 length));
 154.960 +#endif /* PNG_READ_iCCP_SUPPORTED */
 154.961 +
 154.962 +#ifdef PNG_READ_iTXt_SUPPORTED
 154.963 +PNG_EXTERN void png_handle_iTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
 154.964 +    png_uint_32 length));
 154.965 +#endif
 154.966 +
 154.967 +#ifdef PNG_READ_oFFs_SUPPORTED
 154.968 +PNG_EXTERN void png_handle_oFFs PNGARG((png_structp png_ptr, png_infop info_ptr,
 154.969 +    png_uint_32 length));
 154.970 +#endif
 154.971 +
 154.972 +#ifdef PNG_READ_pCAL_SUPPORTED
 154.973 +PNG_EXTERN void png_handle_pCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
 154.974 +    png_uint_32 length));
 154.975 +#endif
 154.976 +
 154.977 +#ifdef PNG_READ_pHYs_SUPPORTED
 154.978 +PNG_EXTERN void png_handle_pHYs PNGARG((png_structp png_ptr, png_infop info_ptr,
 154.979 +    png_uint_32 length));
 154.980 +#endif
 154.981 +
 154.982 +#ifdef PNG_READ_sBIT_SUPPORTED
 154.983 +PNG_EXTERN void png_handle_sBIT PNGARG((png_structp png_ptr, png_infop info_ptr,
 154.984 +    png_uint_32 length));
 154.985 +#endif
 154.986 +
 154.987 +#ifdef PNG_READ_sCAL_SUPPORTED
 154.988 +PNG_EXTERN void png_handle_sCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
 154.989 +    png_uint_32 length));
 154.990 +#endif
 154.991 +
 154.992 +#ifdef PNG_READ_sPLT_SUPPORTED
 154.993 +PNG_EXTERN void png_handle_sPLT PNGARG((png_structp png_ptr, png_infop info_ptr,
 154.994 +    png_uint_32 length));
 154.995 +#endif /* PNG_READ_sPLT_SUPPORTED */
 154.996 +
 154.997 +#ifdef PNG_READ_sRGB_SUPPORTED
 154.998 +PNG_EXTERN void png_handle_sRGB PNGARG((png_structp png_ptr, png_infop info_ptr,
 154.999 +    png_uint_32 length));
154.1000 +#endif
154.1001 +
154.1002 +#ifdef PNG_READ_tEXt_SUPPORTED
154.1003 +PNG_EXTERN void png_handle_tEXt PNGARG((png_structp png_ptr, png_infop info_ptr,
154.1004 +    png_uint_32 length));
154.1005 +#endif
154.1006 +
154.1007 +#ifdef PNG_READ_tIME_SUPPORTED
154.1008 +PNG_EXTERN void png_handle_tIME PNGARG((png_structp png_ptr, png_infop info_ptr,
154.1009 +    png_uint_32 length));
154.1010 +#endif
154.1011 +
154.1012 +#ifdef PNG_READ_tRNS_SUPPORTED
154.1013 +PNG_EXTERN void png_handle_tRNS PNGARG((png_structp png_ptr, png_infop info_ptr,
154.1014 +    png_uint_32 length));
154.1015 +#endif
154.1016 +
154.1017 +#ifdef PNG_READ_zTXt_SUPPORTED
154.1018 +PNG_EXTERN void png_handle_zTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
154.1019 +    png_uint_32 length));
154.1020 +#endif
154.1021 +
154.1022 +PNG_EXTERN void png_handle_unknown PNGARG((png_structp png_ptr,
154.1023 +    png_infop info_ptr, png_uint_32 length));
154.1024 +
154.1025 +PNG_EXTERN void png_check_chunk_name PNGARG((png_structp png_ptr,
154.1026 +    png_const_bytep chunk_name));
154.1027 +
154.1028 +/* Handle the transformations for reading and writing */
154.1029 +#ifdef PNG_READ_TRANSFORMS_SUPPORTED
154.1030 +PNG_EXTERN void png_do_read_transformations PNGARG((png_structp png_ptr));
154.1031 +#endif
154.1032 +#ifdef PNG_WRITE_TRANSFORMS_SUPPORTED
154.1033 +PNG_EXTERN void png_do_write_transformations PNGARG((png_structp png_ptr));
154.1034 +#endif
154.1035 +
154.1036 +#ifdef PNG_READ_TRANSFORMS_SUPPORTED
154.1037 +PNG_EXTERN void png_init_read_transformations PNGARG((png_structp png_ptr));
154.1038 +#endif
154.1039 +
154.1040 +#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
154.1041 +PNG_EXTERN void png_push_read_chunk PNGARG((png_structp png_ptr,
154.1042 +    png_infop info_ptr));
154.1043 +PNG_EXTERN void png_push_read_sig PNGARG((png_structp png_ptr,
154.1044 +    png_infop info_ptr));
154.1045 +PNG_EXTERN void png_push_check_crc PNGARG((png_structp png_ptr));
154.1046 +PNG_EXTERN void png_push_crc_skip PNGARG((png_structp png_ptr,
154.1047 +    png_uint_32 length));
154.1048 +PNG_EXTERN void png_push_crc_finish PNGARG((png_structp png_ptr));
154.1049 +PNG_EXTERN void png_push_save_buffer PNGARG((png_structp png_ptr));
154.1050 +PNG_EXTERN void png_push_restore_buffer PNGARG((png_structp png_ptr,
154.1051 +    png_bytep buffer, png_size_t buffer_length));
154.1052 +PNG_EXTERN void png_push_read_IDAT PNGARG((png_structp png_ptr));
154.1053 +PNG_EXTERN void png_process_IDAT_data PNGARG((png_structp png_ptr,
154.1054 +    png_bytep buffer, png_size_t buffer_length));
154.1055 +PNG_EXTERN void png_push_process_row PNGARG((png_structp png_ptr));
154.1056 +PNG_EXTERN void png_push_handle_unknown PNGARG((png_structp png_ptr,
154.1057 +   png_infop info_ptr, png_uint_32 length));
154.1058 +PNG_EXTERN void png_push_have_info PNGARG((png_structp png_ptr,
154.1059 +   png_infop info_ptr));
154.1060 +PNG_EXTERN void png_push_have_end PNGARG((png_structp png_ptr,
154.1061 +   png_infop info_ptr));
154.1062 +PNG_EXTERN void png_push_have_row PNGARG((png_structp png_ptr, png_bytep row));
154.1063 +PNG_EXTERN void png_push_read_end PNGARG((png_structp png_ptr,
154.1064 +    png_infop info_ptr));
154.1065 +PNG_EXTERN void png_process_some_data PNGARG((png_structp png_ptr,
154.1066 +    png_infop info_ptr));
154.1067 +PNG_EXTERN void png_read_push_finish_row PNGARG((png_structp png_ptr));
154.1068 +#  ifdef PNG_READ_tEXt_SUPPORTED
154.1069 +PNG_EXTERN void png_push_handle_tEXt PNGARG((png_structp png_ptr,
154.1070 +    png_infop info_ptr, png_uint_32 length));
154.1071 +PNG_EXTERN void png_push_read_tEXt PNGARG((png_structp png_ptr,
154.1072 +    png_infop info_ptr));
154.1073 +#  endif
154.1074 +#  ifdef PNG_READ_zTXt_SUPPORTED
154.1075 +PNG_EXTERN void png_push_handle_zTXt PNGARG((png_structp png_ptr,
154.1076 +    png_infop info_ptr, png_uint_32 length));
154.1077 +PNG_EXTERN void png_push_read_zTXt PNGARG((png_structp png_ptr,
154.1078 +    png_infop info_ptr));
154.1079 +#  endif
154.1080 +#  ifdef PNG_READ_iTXt_SUPPORTED
154.1081 +PNG_EXTERN void png_push_handle_iTXt PNGARG((png_structp png_ptr,
154.1082 +    png_infop info_ptr, png_uint_32 length));
154.1083 +PNG_EXTERN void png_push_read_iTXt PNGARG((png_structp png_ptr,
154.1084 +    png_infop info_ptr));
154.1085 +#  endif
154.1086 +
154.1087 +#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
154.1088 +
154.1089 +#ifdef PNG_MNG_FEATURES_SUPPORTED
154.1090 +PNG_EXTERN void png_do_read_intrapixel PNGARG((png_row_infop row_info,
154.1091 +    png_bytep row));
154.1092 +PNG_EXTERN void png_do_write_intrapixel PNGARG((png_row_infop row_info,
154.1093 +    png_bytep row));
154.1094 +#endif
154.1095 +
154.1096 +/* Added at libpng version 1.4.0 */
154.1097 +#ifdef PNG_CHECK_cHRM_SUPPORTED
154.1098 +PNG_EXTERN int png_check_cHRM_fixed PNGARG((png_structp png_ptr,
154.1099 +    png_fixed_point int_white_x, png_fixed_point int_white_y,
154.1100 +    png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point
154.1101 +    int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x,
154.1102 +    png_fixed_point int_blue_y));
154.1103 +#endif
154.1104 +
154.1105 +#ifdef PNG_CHECK_cHRM_SUPPORTED
154.1106 +/* Added at libpng version 1.2.34 and 1.4.0 */
154.1107 +/* Currently only used by png_check_cHRM_fixed */
154.1108 +PNG_EXTERN void png_64bit_product PNGARG((long v1, long v2,
154.1109 +    unsigned long *hi_product, unsigned long *lo_product));
154.1110 +#endif
154.1111 +
154.1112 +/* Added at libpng version 1.4.0 */
154.1113 +PNG_EXTERN void png_check_IHDR PNGARG((png_structp png_ptr,
154.1114 +    png_uint_32 width, png_uint_32 height, int bit_depth,
154.1115 +    int color_type, int interlace_type, int compression_type,
154.1116 +    int filter_type));
154.1117 +
154.1118 +/* Free all memory used by the read (old method - NOT DLL EXPORTED) */
154.1119 +PNG_EXTERN void png_read_destroy PNGARG((png_structp png_ptr,
154.1120 +    png_infop info_ptr, png_infop end_info_ptr));
154.1121 +
154.1122 +/* Free any memory used in png_ptr struct (old method - NOT DLL EXPORTED) */
154.1123 +PNG_EXTERN void png_write_destroy PNGARG((png_structp png_ptr));
154.1124 +
154.1125 +#ifdef USE_FAR_KEYWORD  /* memory model conversion function */
154.1126 +PNG_EXTERN void *png_far_to_near PNGARG((png_structp png_ptr, png_voidp ptr,
154.1127 +    int check));
154.1128 +#endif /* USE_FAR_KEYWORD */
154.1129 +
154.1130 +#if defined(PNG_FLOATING_POINT_SUPPORTED) && defined(PNG_ERROR_TEXT_SUPPORTED)
154.1131 +PNG_EXTERN PNG_FUNCTION(void, png_fixed_error, (png_structp png_ptr,
154.1132 +   png_const_charp name),PNG_NORETURN);
154.1133 +#endif
154.1134 +
154.1135 +/* Puts 'string' into 'buffer' at buffer[pos], taking care never to overwrite
154.1136 + * the end.  Always leaves the buffer nul terminated.  Never errors out (and
154.1137 + * there is no error code.)
154.1138 + */
154.1139 +PNG_EXTERN size_t png_safecat(png_charp buffer, size_t bufsize, size_t pos,
154.1140 +    png_const_charp string);
154.1141 +
154.1142 +/* Various internal functions to handle formatted warning messages, currently
154.1143 + * only implemented for warnings.
154.1144 + */
154.1145 +#if defined(PNG_WARNINGS_SUPPORTED) || defined(PNG_TIME_RFC1123_SUPPORTED)
154.1146 +/* Utility to dump an unsigned value into a buffer, given a start pointer and
154.1147 + * and end pointer (which should point just *beyond* the end of the buffer!)
154.1148 + * Returns the pointer to the start of the formatted string.  This utility only
154.1149 + * does unsigned values.
154.1150 + */
154.1151 +PNG_EXTERN png_charp png_format_number(png_const_charp start, png_charp end,
154.1152 +   int format, png_alloc_size_t number);
154.1153 +
154.1154 +/* Convenience macro that takes an array: */
154.1155 +#define PNG_FORMAT_NUMBER(buffer,format,number) \
154.1156 +   png_format_number(buffer, buffer + (sizeof buffer), format, number)
154.1157 +
154.1158 +/* Suggested size for a number buffer (enough for 64 bits and a sign!) */
154.1159 +#define PNG_NUMBER_BUFFER_SIZE 24
154.1160 +
154.1161 +/* These are the integer formats currently supported, the name is formed from
154.1162 + * the standard printf(3) format string.
154.1163 + */
154.1164 +#define PNG_NUMBER_FORMAT_u     1 /* chose unsigned API! */
154.1165 +#define PNG_NUMBER_FORMAT_02u   2
154.1166 +#define PNG_NUMBER_FORMAT_d     1 /* chose signed API! */
154.1167 +#define PNG_NUMBER_FORMAT_02d   2
154.1168 +#define PNG_NUMBER_FORMAT_x     3
154.1169 +#define PNG_NUMBER_FORMAT_02x   4
154.1170 +#define PNG_NUMBER_FORMAT_fixed 5 /* choose the signed API */
154.1171 +#endif
154.1172 +
154.1173 +#ifdef PNG_WARNINGS_SUPPORTED
154.1174 +/* New defines and members adding in libpng-1.5.4 */
154.1175 +#  define PNG_WARNING_PARAMETER_SIZE 32
154.1176 +#  define PNG_WARNING_PARAMETER_COUNT 8
154.1177 +
154.1178 +/* An l-value of this type has to be passed to the APIs below to cache the
154.1179 + * values of the parameters to a formatted warning message.
154.1180 + */
154.1181 +typedef char png_warning_parameters[PNG_WARNING_PARAMETER_COUNT][
154.1182 +   PNG_WARNING_PARAMETER_SIZE];
154.1183 +
154.1184 +PNG_EXTERN void png_warning_parameter(png_warning_parameters p, int number,
154.1185 +    png_const_charp string);
154.1186 +    /* Parameters are limited in size to PNG_WARNING_PARAMETER_SIZE characters,
154.1187 +     * including the trailing '\0'.
154.1188 +     */
154.1189 +PNG_EXTERN void png_warning_parameter_unsigned(png_warning_parameters p,
154.1190 +    int number, int format, png_alloc_size_t value);
154.1191 +    /* Use png_alloc_size_t because it is an unsigned type as big as any we
154.1192 +     * need to output.  Use the following for a signed value.
154.1193 +     */
154.1194 +PNG_EXTERN void png_warning_parameter_signed(png_warning_parameters p,
154.1195 +    int number, int format, png_int_32 value);
154.1196 +
154.1197 +PNG_EXTERN void png_formatted_warning(png_structp png_ptr,
154.1198 +    png_warning_parameters p, png_const_charp message);
154.1199 +    /* 'message' follows the X/Open approach of using @1, @2 to insert
154.1200 +     * parameters previously supplied using the above functions.  Errors in
154.1201 +     * specifying the paramters will simple result in garbage substitutions.
154.1202 +     */
154.1203 +#endif
154.1204 +
154.1205 +/* ASCII to FP interfaces, currently only implemented if sCAL
154.1206 + * support is required.
154.1207 + */
154.1208 +#if defined(PNG_READ_sCAL_SUPPORTED)
154.1209 +/* MAX_DIGITS is actually the maximum number of characters in an sCAL
154.1210 + * width or height, derived from the precision (number of significant
154.1211 + * digits - a build time settable option) and assumpitions about the
154.1212 + * maximum ridiculous exponent.
154.1213 + */
154.1214 +#define PNG_sCAL_MAX_DIGITS (PNG_sCAL_PRECISION+1/*.*/+1/*E*/+10/*exponent*/)
154.1215 +
154.1216 +#ifdef PNG_FLOATING_POINT_SUPPORTED
154.1217 +PNG_EXTERN void png_ascii_from_fp PNGARG((png_structp png_ptr, png_charp ascii,
154.1218 +    png_size_t size, double fp, unsigned int precision));
154.1219 +#endif /* FLOATING_POINT */
154.1220 +
154.1221 +#ifdef PNG_FIXED_POINT_SUPPORTED
154.1222 +PNG_EXTERN void png_ascii_from_fixed PNGARG((png_structp png_ptr,
154.1223 +    png_charp ascii, png_size_t size, png_fixed_point fp));
154.1224 +#endif /* FIXED_POINT */
154.1225 +#endif /* READ_sCAL */
154.1226 +
154.1227 +#if defined(PNG_sCAL_SUPPORTED) || defined(PNG_pCAL_SUPPORTED)
154.1228 +/* An internal API to validate the format of a floating point number.
154.1229 + * The result is the index of the next character.  If the number is
154.1230 + * not valid it will be the index of a character in the supposed number.
154.1231 + *
154.1232 + * The format of a number is defined in the PNG extensions specification
154.1233 + * and this API is strictly conformant to that spec, not anyone elses!
154.1234 + *
154.1235 + * The format as a regular expression is:
154.1236 + *
154.1237 + * [+-]?[0-9]+.?([Ee][+-]?[0-9]+)?
154.1238 + *
154.1239 + * or:
154.1240 + *
154.1241 + * [+-]?.[0-9]+(.[0-9]+)?([Ee][+-]?[0-9]+)?
154.1242 + *
154.1243 + * The complexity is that either integer or fraction must be present and the
154.1244 + * fraction is permitted to have no digits only if the integer is present.
154.1245 + *
154.1246 + * NOTE: The dangling E problem.
154.1247 + *   There is a PNG valid floating point number in the following:
154.1248 + *
154.1249 + *       PNG floating point numb1.ers are not greedy.
154.1250 + *
154.1251 + *   Working this out requires *TWO* character lookahead (because of the
154.1252 + *   sign), the parser does not do this - it will fail at the 'r' - this
154.1253 + *   doesn't matter for PNG sCAL chunk values, but it requires more care
154.1254 + *   if the value were ever to be embedded in something more complex.  Use
154.1255 + *   ANSI-C strtod if you need the lookahead.
154.1256 + */
154.1257 +/* State table for the parser. */
154.1258 +#define PNG_FP_INTEGER    0  /* before or in integer */
154.1259 +#define PNG_FP_FRACTION   1  /* before or in fraction */
154.1260 +#define PNG_FP_EXPONENT   2  /* before or in exponent */
154.1261 +#define PNG_FP_STATE      3  /* mask for the above */
154.1262 +#define PNG_FP_SAW_SIGN   4  /* Saw +/- in current state */
154.1263 +#define PNG_FP_SAW_DIGIT  8  /* Saw a digit in current state */
154.1264 +#define PNG_FP_SAW_DOT   16  /* Saw a dot in current state */
154.1265 +#define PNG_FP_SAW_E     32  /* Saw an E (or e) in current state */
154.1266 +#define PNG_FP_SAW_ANY   60  /* Saw any of the above 4 */
154.1267 +
154.1268 +/* These three values don't affect the parser.  They are set but not used.
154.1269 + */
154.1270 +#define PNG_FP_WAS_VALID 64  /* Preceding substring is a valid fp number */
154.1271 +#define PNG_FP_NEGATIVE 128  /* A negative number, including "-0" */
154.1272 +#define PNG_FP_NONZERO  256  /* A non-zero value */
154.1273 +#define PNG_FP_STICKY   448  /* The above three flags */
154.1274 +
154.1275 +/* This is available for the caller to store in 'state' if required.  Do not
154.1276 + * call the parser after setting it (the parser sometimes clears it.)
154.1277 + */
154.1278 +#define PNG_FP_INVALID  512  /* Available for callers as a distinct value */
154.1279 +
154.1280 +/* Result codes for the parser (boolean - true meants ok, false means
154.1281 + * not ok yet.)
154.1282 + */
154.1283 +#define PNG_FP_MAYBE      0  /* The number may be valid in the future */
154.1284 +#define PNG_FP_OK         1  /* The number is valid */
154.1285 +
154.1286 +/* Tests on the sticky non-zero and negative flags.  To pass these checks
154.1287 + * the state must also indicate that the whole number is valid - this is
154.1288 + * achieved by testing PNG_FP_SAW_DIGIT (see the implementation for why this
154.1289 + * is equivalent to PNG_FP_OK above.)
154.1290 + */
154.1291 +#define PNG_FP_NZ_MASK (PNG_FP_SAW_DIGIT | PNG_FP_NEGATIVE | PNG_FP_NONZERO)
154.1292 +   /* NZ_MASK: the string is valid and a non-zero negative value */
154.1293 +#define PNG_FP_Z_MASK (PNG_FP_SAW_DIGIT | PNG_FP_NONZERO)
154.1294 +   /* Z MASK: the string is valid and a non-zero value. */
154.1295 +   /* PNG_FP_SAW_DIGIT: the string is valid. */
154.1296 +#define PNG_FP_IS_ZERO(state) (((state) & PNG_FP_Z_MASK) == PNG_FP_SAW_DIGIT)
154.1297 +#define PNG_FP_IS_POSITIVE(state) (((state) & PNG_FP_NZ_MASK) == PNG_FP_Z_MASK)
154.1298 +#define PNG_FP_IS_NEGATIVE(state) (((state) & PNG_FP_NZ_MASK) == PNG_FP_NZ_MASK)
154.1299 +
154.1300 +/* The actual parser.  This can be called repeatedly, it updates
154.1301 + * the index into the string and the state variable (which must
154.1302 + * be initialzed to 0).  It returns a result code, as above.  There
154.1303 + * is no point calling the parser any more if it fails to advance to
154.1304 + * the end of the string - it is stuck on an invalid character (or
154.1305 + * terminated by '\0').
154.1306 + *
154.1307 + * Note that the pointer will consume an E or even an E+ then leave
154.1308 + * a 'maybe' state even though a preceding integer.fraction is valid.
154.1309 + * The PNG_FP_WAS_VALID flag indicates that a preceding substring was
154.1310 + * a valid number.  It's possible to recover from this by calling
154.1311 + * the parser again (from the start, with state 0) but with a string
154.1312 + * that omits the last character (i.e. set the size to the index of
154.1313 + * the problem character.)  This has not been tested within libpng.
154.1314 + */
154.1315 +PNG_EXTERN int png_check_fp_number PNGARG((png_const_charp string,
154.1316 +    png_size_t size, int *statep, png_size_tp whereami));
154.1317 +
154.1318 +/* This is the same but it checks a complete string and returns true
154.1319 + * only if it just contains a floating point number.  As of 1.5.4 this
154.1320 + * function also returns the state at the end of parsing the number if
154.1321 + * it was valid (otherwise it returns 0.)  This can be used for testing
154.1322 + * for negative or zero values using the sticky flag.
154.1323 + */
154.1324 +PNG_EXTERN int png_check_fp_string PNGARG((png_const_charp string,
154.1325 +    png_size_t size));
154.1326 +#endif /* pCAL || sCAL */
154.1327 +
154.1328 +#if defined(PNG_READ_GAMMA_SUPPORTED) ||\
154.1329 +    defined(PNG_INCH_CONVERSIONS_SUPPORTED) || defined(PNG_READ_pHYs_SUPPORTED)
154.1330 +/* Added at libpng version 1.5.0 */
154.1331 +/* This is a utility to provide a*times/div (rounded) and indicate
154.1332 + * if there is an overflow.  The result is a boolean - false (0)
154.1333 + * for overflow, true (1) if no overflow, in which case *res
154.1334 + * holds the result.
154.1335 + */
154.1336 +PNG_EXTERN int png_muldiv PNGARG((png_fixed_point_p res, png_fixed_point a,
154.1337 +    png_int_32 multiplied_by, png_int_32 divided_by));
154.1338 +#endif
154.1339 +
154.1340 +#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_INCH_CONVERSIONS_SUPPORTED)
154.1341 +/* Same deal, but issue a warning on overflow and return 0. */
154.1342 +PNG_EXTERN png_fixed_point png_muldiv_warn PNGARG((png_structp png_ptr,
154.1343 +    png_fixed_point a, png_int_32 multiplied_by, png_int_32 divided_by));
154.1344 +#endif
154.1345 +
154.1346 +#ifdef PNG_READ_GAMMA_SUPPORTED
154.1347 +/* Calculate a reciprocal - used for gamma values.  This returns
154.1348 + * 0 if the argument is 0 in order to maintain an undefined value,
154.1349 + * there are no warnings.
154.1350 + */
154.1351 +PNG_EXTERN png_fixed_point png_reciprocal PNGARG((png_fixed_point a));
154.1352 +
154.1353 +/* The same but gives a reciprocal of the product of two fixed point
154.1354 + * values.  Accuracy is suitable for gamma calculations but this is
154.1355 + * not exact - use png_muldiv for that.
154.1356 + */
154.1357 +PNG_EXTERN png_fixed_point png_reciprocal2 PNGARG((png_fixed_point a,
154.1358 +    png_fixed_point b));
154.1359 +#endif
154.1360 +
154.1361 +#ifdef PNG_READ_GAMMA_SUPPORTED
154.1362 +/* Internal fixed point gamma correction.  These APIs are called as
154.1363 + * required to convert single values - they don't need to be fast,
154.1364 + * they are not used when processing image pixel values.
154.1365 + *
154.1366 + * While the input is an 'unsigned' value it must actually be the
154.1367 + * correct bit value - 0..255 or 0..65535 as required.
154.1368 + */
154.1369 +PNG_EXTERN png_uint_16 png_gamma_correct PNGARG((png_structp png_ptr,
154.1370 +    unsigned int value, png_fixed_point gamma_value));
154.1371 +PNG_EXTERN int png_gamma_significant PNGARG((png_fixed_point gamma_value));
154.1372 +PNG_EXTERN png_uint_16 png_gamma_16bit_correct PNGARG((unsigned int value,
154.1373 +    png_fixed_point gamma_value));
154.1374 +PNG_EXTERN png_byte png_gamma_8bit_correct PNGARG((unsigned int value,
154.1375 +    png_fixed_point gamma_value));
154.1376 +PNG_EXTERN void png_build_gamma_table PNGARG((png_structp png_ptr,
154.1377 +    int bit_depth));
154.1378 +#endif
154.1379 +
154.1380 +/* Maintainer: Put new private prototypes here ^ and in libpngpf.3 */
154.1381 +
154.1382 +
154.1383 +#include "pngdebug.h"
154.1384 +
154.1385 +#ifdef __cplusplus
154.1386 +}
154.1387 +#endif
154.1388 +
154.1389 +#endif /* PNGPRIV_H */
   155.1 --- a/src/share/native/sun/awt/libpng/pngread.c	Fri Sep 30 17:20:56 2011 -0700
   155.2 +++ b/src/share/native/sun/awt/libpng/pngread.c	Tue Oct 04 12:39:42 2011 -0700
   155.3 @@ -29,93 +29,97 @@
   155.4   * However, the following notice accompanied the original version of this
   155.5   * file and, per its terms, should not be removed:
   155.6   *
   155.7 - * Last changed in libpng 1.2.15 January 5, 2007
   155.8 - * For conditions of distribution and use, see copyright notice in png.h
   155.9 - * Copyright (c) 1998-2007 Glenn Randers-Pehrson
  155.10 + * Last changed in libpng 1.5.4 [July 7, 2011]
  155.11 + * Copyright (c) 1998-2011 Glenn Randers-Pehrson
  155.12   * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
  155.13   * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
  155.14   *
  155.15 + * This code is released under the libpng license.
  155.16 + * For conditions of distribution and use, see the disclaimer
  155.17 + * and license in png.h
  155.18 + *
  155.19   * This file contains routines that an application calls directly to
  155.20   * read a PNG file or stream.
  155.21   */
  155.22  
  155.23 -#define PNG_INTERNAL
  155.24 -#include "png.h"
  155.25 +#include "pngpriv.h"
  155.26  
  155.27 -#if defined(PNG_READ_SUPPORTED)
  155.28 +#ifdef PNG_READ_SUPPORTED
  155.29  
  155.30  /* Create a PNG structure for reading, and allocate any memory needed. */
  155.31 -png_structp PNGAPI
  155.32 -png_create_read_struct(png_const_charp user_png_ver, png_voidp error_ptr,
  155.33 -   png_error_ptr error_fn, png_error_ptr warn_fn)
  155.34 +PNG_FUNCTION(png_structp,PNGAPI
  155.35 +png_create_read_struct,(png_const_charp user_png_ver, png_voidp error_ptr,
  155.36 +    png_error_ptr error_fn, png_error_ptr warn_fn),PNG_ALLOCATED)
  155.37  {
  155.38  
  155.39  #ifdef PNG_USER_MEM_SUPPORTED
  155.40     return (png_create_read_struct_2(user_png_ver, error_ptr, error_fn,
  155.41 -      warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL));
  155.42 +       warn_fn, NULL, NULL, NULL));
  155.43  }
  155.44  
  155.45 -/* Alternate create PNG structure for reading, and allocate any memory needed. */
  155.46 -png_structp PNGAPI
  155.47 -png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
  155.48 -   png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  155.49 -   png_malloc_ptr malloc_fn, png_free_ptr free_fn)
  155.50 +/* Alternate create PNG structure for reading, and allocate any memory
  155.51 + * needed.
  155.52 + */
  155.53 +PNG_FUNCTION(png_structp,PNGAPI
  155.54 +png_create_read_struct_2,(png_const_charp user_png_ver, png_voidp error_ptr,
  155.55 +    png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  155.56 +    png_malloc_ptr malloc_fn, png_free_ptr free_fn),PNG_ALLOCATED)
  155.57  {
  155.58  #endif /* PNG_USER_MEM_SUPPORTED */
  155.59  
  155.60 +#ifdef PNG_SETJMP_SUPPORTED
  155.61 +   volatile
  155.62 +#endif
  155.63     png_structp png_ptr;
  155.64 +   volatile int png_cleanup_needed = 0;
  155.65  
  155.66  #ifdef PNG_SETJMP_SUPPORTED
  155.67  #ifdef USE_FAR_KEYWORD
  155.68 -   jmp_buf jmpbuf;
  155.69 +   jmp_buf tmp_jmpbuf;
  155.70  #endif
  155.71  #endif
  155.72  
  155.73 -   int i;
  155.74 +   png_debug(1, "in png_create_read_struct");
  155.75  
  155.76 -   png_debug(1, "in png_create_read_struct\n");
  155.77  #ifdef PNG_USER_MEM_SUPPORTED
  155.78     png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
  155.79 -      (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
  155.80 +       malloc_fn, mem_ptr);
  155.81  #else
  155.82     png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  155.83  #endif
  155.84     if (png_ptr == NULL)
  155.85        return (NULL);
  155.86  
  155.87 -#if !defined(PNG_1_0_X)
  155.88 -#ifdef PNG_MMX_CODE_SUPPORTED
  155.89 -   png_init_mmx_flags(png_ptr);   /* 1.2.0 addition */
  155.90 -#endif
  155.91 -#endif /* PNG_1_0_X */
  155.92 +   /* Added at libpng-1.2.6 */
  155.93 +#ifdef PNG_USER_LIMITS_SUPPORTED
  155.94 +   png_ptr->user_width_max = PNG_USER_WIDTH_MAX;
  155.95 +   png_ptr->user_height_max = PNG_USER_HEIGHT_MAX;
  155.96  
  155.97 -   /* added at libpng-1.2.6 */
  155.98 -#ifdef PNG_SET_USER_LIMITS_SUPPORTED
  155.99 -   png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
 155.100 -   png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
 155.101 +#  ifdef PNG_USER_CHUNK_CACHE_MAX
 155.102 +   /* Added at libpng-1.2.43 and 1.4.0 */
 155.103 +   png_ptr->user_chunk_cache_max = PNG_USER_CHUNK_CACHE_MAX;
 155.104 +#  endif
 155.105 +
 155.106 +#  ifdef PNG_SET_USER_CHUNK_MALLOC_MAX
 155.107 +   /* Added at libpng-1.2.43 and 1.4.1 */
 155.108 +   png_ptr->user_chunk_malloc_max = PNG_USER_CHUNK_MALLOC_MAX;
 155.109 +#  endif
 155.110  #endif
 155.111  
 155.112  #ifdef PNG_SETJMP_SUPPORTED
 155.113 +/* Applications that neglect to set up their own setjmp() and then
 155.114 +   encounter a png_error() will longjmp here.  Since the jmpbuf is
 155.115 +   then meaningless we abort instead of returning. */
 155.116  #ifdef USE_FAR_KEYWORD
 155.117 -   if (setjmp(jmpbuf))
 155.118 +   if (setjmp(tmp_jmpbuf))
 155.119  #else
 155.120 -   if (setjmp(png_ptr->jmpbuf))
 155.121 +   if (setjmp(png_jmpbuf(png_ptr))) /* Sets longjmp to match setjmp */
 155.122  #endif
 155.123 -   {
 155.124 -      png_free(png_ptr, png_ptr->zbuf);
 155.125 -      png_ptr->zbuf=NULL;
 155.126 -#ifdef PNG_USER_MEM_SUPPORTED
 155.127 -      png_destroy_struct_2((png_voidp)png_ptr,
 155.128 -         (png_free_ptr)free_fn, (png_voidp)mem_ptr);
 155.129 -#else
 155.130 -      png_destroy_struct((png_voidp)png_ptr);
 155.131 +      PNG_ABORT();
 155.132 +#ifdef USE_FAR_KEYWORD
 155.133 +   png_memcpy(png_jmpbuf(png_ptr), tmp_jmpbuf, png_sizeof(jmp_buf));
 155.134  #endif
 155.135 -      return (NULL);
 155.136 -   }
 155.137 -#ifdef USE_FAR_KEYWORD
 155.138 -   png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
 155.139 -#endif
 155.140 -#endif
 155.141 +#endif /* PNG_SETJMP_SUPPORTED */
 155.142  
 155.143  #ifdef PNG_USER_MEM_SUPPORTED
 155.144     png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
 155.145 @@ -123,220 +127,76 @@
 155.146  
 155.147     png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
 155.148  
 155.149 -   i=0;
 155.150 -   do
 155.151 +   /* Call the general version checker (shared with read and write code): */
 155.152 +   if (!png_user_version_check(png_ptr, user_png_ver))
 155.153 +      png_cleanup_needed = 1;
 155.154 +
 155.155 +   if (!png_cleanup_needed)
 155.156     {
 155.157 -     if(user_png_ver[i] != png_libpng_ver[i])
 155.158 -        png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
 155.159 -   } while (png_libpng_ver[i++]);
 155.160 +   /* Initialize zbuf - compression buffer */
 155.161 +   png_ptr->zbuf_size = PNG_ZBUF_SIZE;
 155.162 +   png_ptr->zbuf = (png_bytep)png_malloc_warn(png_ptr, png_ptr->zbuf_size);
 155.163  
 155.164 -   if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
 155.165 -   {
 155.166 -     /* Libpng 0.90 and later are binary incompatible with libpng 0.89, so
 155.167 -      * we must recompile any applications that use any older library version.
 155.168 -      * For versions after libpng 1.0, we will be compatible, so we need
 155.169 -      * only check the first digit.
 155.170 -      */
 155.171 -     if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
 155.172 -         (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
 155.173 -         (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
 155.174 -     {
 155.175 -#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
 155.176 -        char msg[80];
 155.177 -        if (user_png_ver)
 155.178 -        {
 155.179 -          sprintf(msg, "Application was compiled with png.h from libpng-%.20s",
 155.180 -             user_png_ver);
 155.181 -          png_warning(png_ptr, msg);
 155.182 -        }
 155.183 -        sprintf(msg, "Application  is  running with png.c from libpng-%.20s",
 155.184 -           png_libpng_ver);
 155.185 -        png_warning(png_ptr, msg);
 155.186 -#endif
 155.187 -#ifdef PNG_ERROR_NUMBERS_SUPPORTED
 155.188 -        png_ptr->flags=0;
 155.189 -#endif
 155.190 -        png_error(png_ptr,
 155.191 -           "Incompatible libpng version in application and library");
 155.192 -     }
 155.193 +   if (png_ptr->zbuf == NULL)
 155.194 +      png_cleanup_needed = 1;
 155.195     }
 155.196  
 155.197 -   /* initialize zbuf - compression buffer */
 155.198 -   png_ptr->zbuf_size = PNG_ZBUF_SIZE;
 155.199 -   png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
 155.200 -     (png_uint_32)png_ptr->zbuf_size);
 155.201     png_ptr->zstream.zalloc = png_zalloc;
 155.202     png_ptr->zstream.zfree = png_zfree;
 155.203     png_ptr->zstream.opaque = (voidpf)png_ptr;
 155.204  
 155.205 -   switch (inflateInit(&png_ptr->zstream))
 155.206 +   if (!png_cleanup_needed)
 155.207     {
 155.208 -     case Z_OK: /* Do nothing */ break;
 155.209 -     case Z_MEM_ERROR:
 155.210 -     case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory error"); break;
 155.211 -     case Z_VERSION_ERROR: png_error(png_ptr, "zlib version error"); break;
 155.212 -     default: png_error(png_ptr, "Unknown zlib error");
 155.213 +      switch (inflateInit(&png_ptr->zstream))
 155.214 +      {
 155.215 +         case Z_OK:
 155.216 +            break; /* Do nothing */
 155.217 +
 155.218 +         case Z_MEM_ERROR:
 155.219 +            png_warning(png_ptr, "zlib memory error");
 155.220 +            png_cleanup_needed = 1;
 155.221 +            break;
 155.222 +
 155.223 +         case Z_STREAM_ERROR:
 155.224 +            png_warning(png_ptr, "zlib stream error");
 155.225 +            png_cleanup_needed = 1;
 155.226 +            break;
 155.227 +
 155.228 +         case Z_VERSION_ERROR:
 155.229 +            png_warning(png_ptr, "zlib version error");
 155.230 +            png_cleanup_needed = 1;
 155.231 +            break;
 155.232 +
 155.233 +         default: png_warning(png_ptr, "Unknown zlib error");
 155.234 +            png_cleanup_needed = 1;
 155.235 +      }
 155.236 +   }
 155.237 +
 155.238 +   if (png_cleanup_needed)
 155.239 +   {
 155.240 +      /* Clean up PNG structure and deallocate any memory. */
 155.241 +      png_free(png_ptr, png_ptr->zbuf);
 155.242 +      png_ptr->zbuf = NULL;
 155.243 +#ifdef PNG_USER_MEM_SUPPORTED
 155.244 +      png_destroy_struct_2((png_voidp)png_ptr,
 155.245 +          (png_free_ptr)free_fn, (png_voidp)mem_ptr);
 155.246 +#else
 155.247 +      png_destroy_struct((png_voidp)png_ptr);
 155.248 +#endif
 155.249 +      return (NULL);
 155.250     }
 155.251  
 155.252     png_ptr->zstream.next_out = png_ptr->zbuf;
 155.253     png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
 155.254  
 155.255 -   png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL);
 155.256 +   png_set_read_fn(png_ptr, NULL, NULL);
 155.257  
 155.258 -#ifdef PNG_SETJMP_SUPPORTED
 155.259 -/* Applications that neglect to set up their own setjmp() and then encounter
 155.260 -   a png_error() will longjmp here.  Since the jmpbuf is then meaningless we
 155.261 -   abort instead of returning. */
 155.262 -#ifdef USE_FAR_KEYWORD
 155.263 -   if (setjmp(jmpbuf))
 155.264 -      PNG_ABORT();
 155.265 -   png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
 155.266 -#else
 155.267 -   if (setjmp(png_ptr->jmpbuf))
 155.268 -      PNG_ABORT();
 155.269 -#endif
 155.270 -#endif
 155.271 +
 155.272     return (png_ptr);
 155.273  }
 155.274  
 155.275 -#if defined(PNG_1_0_X) || defined(PNG_1_2_X)
 155.276 -/* Initialize PNG structure for reading, and allocate any memory needed.
 155.277 -   This interface is deprecated in favour of the png_create_read_struct(),
 155.278 -   and it will disappear as of libpng-1.3.0. */
 155.279 -#undef png_read_init
 155.280 -void PNGAPI
 155.281 -png_read_init(png_structp png_ptr)
 155.282 -{
 155.283 -   /* We only come here via pre-1.0.7-compiled applications */
 155.284 -   png_read_init_2(png_ptr, "1.0.6 or earlier", 0, 0);
 155.285 -}
 155.286  
 155.287 -void PNGAPI
 155.288 -png_read_init_2(png_structp png_ptr, png_const_charp user_png_ver,
 155.289 -   png_size_t png_struct_size, png_size_t png_info_size)
 155.290 -{
 155.291 -   /* We only come here via pre-1.0.12-compiled applications */
 155.292 -   if(png_ptr == NULL) return;
 155.293 -#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
 155.294 -   if(png_sizeof(png_struct) > png_struct_size ||
 155.295 -      png_sizeof(png_info) > png_info_size)
 155.296 -   {
 155.297 -      char msg[80];
 155.298 -      png_ptr->warning_fn=NULL;
 155.299 -      if (user_png_ver)
 155.300 -      {
 155.301 -        sprintf(msg, "Application was compiled with png.h from libpng-%.20s",
 155.302 -           user_png_ver);
 155.303 -        png_warning(png_ptr, msg);
 155.304 -      }
 155.305 -      sprintf(msg, "Application  is  running with png.c from libpng-%.20s",
 155.306 -         png_libpng_ver);
 155.307 -      png_warning(png_ptr, msg);
 155.308 -   }
 155.309 -#endif
 155.310 -   if(png_sizeof(png_struct) > png_struct_size)
 155.311 -     {
 155.312 -       png_ptr->error_fn=NULL;
 155.313 -#ifdef PNG_ERROR_NUMBERS_SUPPORTED
 155.314 -       png_ptr->flags=0;
 155.315 -#endif
 155.316 -       png_error(png_ptr,
 155.317 -       "The png struct allocated by the application for reading is too small.");
 155.318 -     }
 155.319 -   if(png_sizeof(png_info) > png_info_size)
 155.320 -     {
 155.321 -       png_ptr->error_fn=NULL;
 155.322 -#ifdef PNG_ERROR_NUMBERS_SUPPORTED
 155.323 -       png_ptr->flags=0;
 155.324 -#endif
 155.325 -       png_error(png_ptr,
 155.326 -         "The info struct allocated by application for reading is too small.");
 155.327 -     }
 155.328 -   png_read_init_3(&png_ptr, user_png_ver, png_struct_size);
 155.329 -}
 155.330 -#endif /* PNG_1_0_X || PNG_1_2_X */
 155.331 -
 155.332 -void PNGAPI
 155.333 -png_read_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
 155.334 -   png_size_t png_struct_size)
 155.335 -{
 155.336 -#ifdef PNG_SETJMP_SUPPORTED
 155.337 -   jmp_buf tmp_jmp;  /* to save current jump buffer */
 155.338 -#endif
 155.339 -
 155.340 -   int i=0;
 155.341 -
 155.342 -   png_structp png_ptr=*ptr_ptr;
 155.343 -
 155.344 -   if(png_ptr == NULL) return;
 155.345 -
 155.346 -   do
 155.347 -   {
 155.348 -     if(user_png_ver[i] != png_libpng_ver[i])
 155.349 -     {
 155.350 -#ifdef PNG_LEGACY_SUPPORTED
 155.351 -       png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
 155.352 -#else
 155.353 -       png_ptr->warning_fn=NULL;
 155.354 -       png_warning(png_ptr,
 155.355 -        "Application uses deprecated png_read_init() and should be recompiled.");
 155.356 -       break;
 155.357 -#endif
 155.358 -     }
 155.359 -   } while (png_libpng_ver[i++]);
 155.360 -
 155.361 -   png_debug(1, "in png_read_init_3\n");
 155.362 -
 155.363 -#ifdef PNG_SETJMP_SUPPORTED
 155.364 -   /* save jump buffer and error functions */
 155.365 -   png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
 155.366 -#endif
 155.367 -
 155.368 -   if(png_sizeof(png_struct) > png_struct_size)
 155.369 -     {
 155.370 -       png_destroy_struct(png_ptr);
 155.371 -       *ptr_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
 155.372 -       png_ptr = *ptr_ptr;
 155.373 -     }
 155.374 -
 155.375 -   /* reset all variables to 0 */
 155.376 -   png_memset(png_ptr, 0, png_sizeof (png_struct));
 155.377 -
 155.378 -#ifdef PNG_SETJMP_SUPPORTED
 155.379 -   /* restore jump buffer */
 155.380 -   png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
 155.381 -#endif
 155.382 -
 155.383 -   /* added at libpng-1.2.6 */
 155.384 -#ifdef PNG_SET_USER_LIMITS_SUPPORTED
 155.385 -   png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
 155.386 -   png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
 155.387 -#endif
 155.388 -
 155.389 -   /* initialize zbuf - compression buffer */
 155.390 -   png_ptr->zbuf_size = PNG_ZBUF_SIZE;
 155.391 -   png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
 155.392 -     (png_uint_32)png_ptr->zbuf_size);
 155.393 -   png_ptr->zstream.zalloc = png_zalloc;
 155.394 -   png_ptr->zstream.zfree = png_zfree;
 155.395 -   png_ptr->zstream.opaque = (voidpf)png_ptr;
 155.396 -
 155.397 -   switch (inflateInit(&png_ptr->zstream))
 155.398 -   {
 155.399 -     case Z_OK: /* Do nothing */ break;
 155.400 -     case Z_MEM_ERROR:
 155.401 -     case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory"); break;
 155.402 -     case Z_VERSION_ERROR: png_error(png_ptr, "zlib version"); break;
 155.403 -     default: png_error(png_ptr, "Unknown zlib error");
 155.404 -   }
 155.405 -
 155.406 -   png_ptr->zstream.next_out = png_ptr->zbuf;
 155.407 -   png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
 155.408 -
 155.409 -   png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL);
 155.410 -}
 155.411 -
 155.412 -#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
 155.413 +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
 155.414  /* Read the information before the actual image data.  This has been
 155.415   * changed in v0.90 to allow reading a file that already has the magic
 155.416   * bytes read from the stream.  You can tell libpng how many bytes have
 155.417 @@ -348,233 +208,244 @@
 155.418  void PNGAPI
 155.419  png_read_info(png_structp png_ptr, png_infop info_ptr)
 155.420  {
 155.421 -   if(png_ptr == NULL) return;
 155.422 -   png_debug(1, "in png_read_info\n");
 155.423 -   /* If we haven't checked all of the PNG signature bytes, do so now. */
 155.424 -   if (png_ptr->sig_bytes < 8)
 155.425 +   png_debug(1, "in png_read_info");
 155.426 +
 155.427 +   if (png_ptr == NULL || info_ptr == NULL)
 155.428 +      return;
 155.429 +
 155.430 +   /* Read and check the PNG file signature. */
 155.431 +   png_read_sig(png_ptr, info_ptr);
 155.432 +
 155.433 +   for (;;)
 155.434     {
 155.435 -      png_size_t num_checked = png_ptr->sig_bytes,
 155.436 -                 num_to_check = 8 - num_checked;
 155.437 -
 155.438 -      png_read_data(png_ptr, &(info_ptr->signature[num_checked]), num_to_check);
 155.439 -      png_ptr->sig_bytes = 8;
 155.440 -
 155.441 -      if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
 155.442 -      {
 155.443 -         if (num_checked < 4 &&
 155.444 -             png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
 155.445 -            png_error(png_ptr, "Not a PNG file");
 155.446 -         else
 155.447 -            png_error(png_ptr, "PNG file corrupted by ASCII conversion");
 155.448 -      }
 155.449 -      if (num_checked < 3)
 155.450 -         png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
 155.451 -   }
 155.452 -
 155.453 -   for(;;)
 155.454 -   {
 155.455 -#ifdef PNG_USE_LOCAL_ARRAYS
 155.456        PNG_IHDR;
 155.457        PNG_IDAT;
 155.458        PNG_IEND;
 155.459        PNG_PLTE;
 155.460 -#if defined(PNG_READ_bKGD_SUPPORTED)
 155.461 +#ifdef PNG_READ_bKGD_SUPPORTED
 155.462        PNG_bKGD;
 155.463  #endif
 155.464 -#if defined(PNG_READ_cHRM_SUPPORTED)
 155.465 +#ifdef PNG_READ_cHRM_SUPPORTED
 155.466        PNG_cHRM;
 155.467  #endif
 155.468 -#if defined(PNG_READ_gAMA_SUPPORTED)
 155.469 +#ifdef PNG_READ_gAMA_SUPPORTED
 155.470        PNG_gAMA;
 155.471  #endif
 155.472 -#if defined(PNG_READ_hIST_SUPPORTED)
 155.473 +#ifdef PNG_READ_hIST_SUPPORTED
 155.474        PNG_hIST;
 155.475  #endif
 155.476 -#if defined(PNG_READ_iCCP_SUPPORTED)
 155.477 +#ifdef PNG_READ_iCCP_SUPPORTED
 155.478        PNG_iCCP;
 155.479  #endif
 155.480 -#if defined(PNG_READ_iTXt_SUPPORTED)
 155.481 +#ifdef PNG_READ_iTXt_SUPPORTED
 155.482        PNG_iTXt;
 155.483  #endif
 155.484 -#if defined(PNG_READ_oFFs_SUPPORTED)
 155.485 +#ifdef PNG_READ_oFFs_SUPPORTED
 155.486        PNG_oFFs;
 155.487  #endif
 155.488 -#if defined(PNG_READ_pCAL_SUPPORTED)
 155.489 +#ifdef PNG_READ_pCAL_SUPPORTED
 155.490        PNG_pCAL;
 155.491  #endif
 155.492 -#if defined(PNG_READ_pHYs_SUPPORTED)
 155.493 +#ifdef PNG_READ_pHYs_SUPPORTED
 155.494        PNG_pHYs;
 155.495  #endif
 155.496 -#if defined(PNG_READ_sBIT_SUPPORTED)
 155.497 +#ifdef PNG_READ_sBIT_SUPPORTED
 155.498        PNG_sBIT;
 155.499  #endif
 155.500 -#if defined(PNG_READ_sCAL_SUPPORTED)
 155.501 +#ifdef PNG_READ_sCAL_SUPPORTED
 155.502        PNG_sCAL;
 155.503  #endif
 155.504 -#if defined(PNG_READ_sPLT_SUPPORTED)
 155.505 +#ifdef PNG_READ_sPLT_SUPPORTED
 155.506        PNG_sPLT;
 155.507  #endif
 155.508 -#if defined(PNG_READ_sRGB_SUPPORTED)
 155.509 +#ifdef PNG_READ_sRGB_SUPPORTED
 155.510        PNG_sRGB;
 155.511  #endif
 155.512 -#if defined(PNG_READ_tEXt_SUPPORTED)
 155.513 +#ifdef PNG_READ_tEXt_SUPPORTED
 155.514        PNG_tEXt;
 155.515  #endif
 155.516 -#if defined(PNG_READ_tIME_SUPPORTED)
 155.517 +#ifdef PNG_READ_tIME_SUPPORTED
 155.518        PNG_tIME;
 155.519  #endif
 155.520 -#if defined(PNG_READ_tRNS_SUPPORTED)
 155.521 +#ifdef PNG_READ_tRNS_SUPPORTED
 155.522        PNG_tRNS;
 155.523  #endif
 155.524 -#if defined(PNG_READ_zTXt_SUPPORTED)
 155.525 +#ifdef PNG_READ_zTXt_SUPPORTED
 155.526        PNG_zTXt;
 155.527  #endif
 155.528 -#endif /* PNG_USE_LOCAL_ARRAYS */
 155.529 -      png_byte chunk_length[4];
 155.530 -      png_uint_32 length;
 155.531 -
 155.532 -      png_read_data(png_ptr, chunk_length, 4);
 155.533 -      length = png_get_uint_31(png_ptr,chunk_length);
 155.534 -
 155.535 -      png_reset_crc(png_ptr);
 155.536 -      png_crc_read(png_ptr, png_ptr->chunk_name, 4);
 155.537 -
 155.538 -      png_debug2(0, "Reading %s chunk, length=%lu.\n", png_ptr->chunk_name,
 155.539 -         length);
 155.540 +      png_uint_32 length = png_read_chunk_header(png_ptr);
 155.541 +      PNG_CONST png_bytep chunk_name = png_ptr->chunk_name;
 155.542  
 155.543        /* This should be a binary subdivision search or a hash for
 155.544         * matching the chunk name rather than a linear search.
 155.545         */
 155.546 -      if (!png_memcmp(png_ptr->chunk_name, (png_bytep)png_IDAT, 4))
 155.547 -        if(png_ptr->mode & PNG_AFTER_IDAT)
 155.548 -          png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
 155.549 +      if (!png_memcmp(chunk_name, png_IDAT, 4))
 155.550 +         if (png_ptr->mode & PNG_AFTER_IDAT)
 155.551 +            png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
 155.552  
 155.553 -      if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
 155.554 +      if (!png_memcmp(chunk_name, png_IHDR, 4))
 155.555           png_handle_IHDR(png_ptr, info_ptr, length);
 155.556 -      else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
 155.557 +
 155.558 +      else if (!png_memcmp(chunk_name, png_IEND, 4))
 155.559           png_handle_IEND(png_ptr, info_ptr, length);
 155.560 +
 155.561  #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
 155.562 -      else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
 155.563 +      else if (png_handle_as_unknown(png_ptr, chunk_name))
 155.564        {
 155.565 -         if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
 155.566 +         if (!png_memcmp(chunk_name, png_IDAT, 4))
 155.567              png_ptr->mode |= PNG_HAVE_IDAT;
 155.568 +
 155.569           png_handle_unknown(png_ptr, info_ptr, length);
 155.570 -         if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
 155.571 +
 155.572 +         if (!png_memcmp(chunk_name, png_PLTE, 4))
 155.573              png_ptr->mode |= PNG_HAVE_PLTE;
 155.574 -         else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
 155.575 +
 155.576 +         else if (!png_memcmp(chunk_name, png_IDAT, 4))
 155.577           {
 155.578              if (!(png_ptr->mode & PNG_HAVE_IHDR))
 155.579                 png_error(png_ptr, "Missing IHDR before IDAT");
 155.580 +
 155.581              else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
 155.582 -                     !(png_ptr->mode & PNG_HAVE_PLTE))
 155.583 +                !(png_ptr->mode & PNG_HAVE_PLTE))
 155.584                 png_error(png_ptr, "Missing PLTE before IDAT");
 155.585 +
 155.586              break;
 155.587           }
 155.588        }
 155.589  #endif
 155.590 -      else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
 155.591 +      else if (!png_memcmp(chunk_name, png_PLTE, 4))
 155.592           png_handle_PLTE(png_ptr, info_ptr, length);
 155.593 -      else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
 155.594 +
 155.595 +      else if (!png_memcmp(chunk_name, png_IDAT, 4))
 155.596        {
 155.597           if (!(png_ptr->mode & PNG_HAVE_IHDR))
 155.598              png_error(png_ptr, "Missing IHDR before IDAT");
 155.599 +
 155.600           else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
 155.601 -                  !(png_ptr->mode & PNG_HAVE_PLTE))
 155.602 +             !(png_ptr->mode & PNG_HAVE_PLTE))
 155.603              png_error(png_ptr, "Missing PLTE before IDAT");
 155.604  
 155.605           png_ptr->idat_size = length;
 155.606           png_ptr->mode |= PNG_HAVE_IDAT;
 155.607           break;
 155.608        }
 155.609 -#if defined(PNG_READ_bKGD_SUPPORTED)
 155.610 -      else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
 155.611 +
 155.612 +#ifdef PNG_READ_bKGD_SUPPORTED
 155.613 +      else if (!png_memcmp(chunk_name, png_bKGD, 4))
 155.614           png_handle_bKGD(png_ptr, info_ptr, length);
 155.615  #endif
 155.616 -#if defined(PNG_READ_cHRM_SUPPORTED)
 155.617 -      else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
 155.618 +
 155.619 +#ifdef PNG_READ_cHRM_SUPPORTED
 155.620 +      else if (!png_memcmp(chunk_name, png_cHRM, 4))
 155.621           png_handle_cHRM(png_ptr, info_ptr, length);
 155.622  #endif
 155.623 -#if defined(PNG_READ_gAMA_SUPPORTED)
 155.624 -      else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
 155.625 +
 155.626 +#ifdef PNG_READ_gAMA_SUPPORTED
 155.627 +      else if (!png_memcmp(chunk_name, png_gAMA, 4))
 155.628           png_handle_gAMA(png_ptr, info_ptr, length);
 155.629  #endif
 155.630 -#if defined(PNG_READ_hIST_SUPPORTED)
 155.631 -      else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
 155.632 +
 155.633 +#ifdef PNG_READ_hIST_SUPPORTED
 155.634 +      else if (!png_memcmp(chunk_name, png_hIST, 4))
 155.635           png_handle_hIST(png_ptr, info_ptr, length);
 155.636  #endif
 155.637 -#if defined(PNG_READ_oFFs_SUPPORTED)
 155.638 -      else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
 155.639 +
 155.640 +#ifdef PNG_READ_oFFs_SUPPORTED
 155.641 +      else if (!png_memcmp(chunk_name, png_oFFs, 4))
 155.642           png_handle_oFFs(png_ptr, info_ptr, length);
 155.643  #endif
 155.644 -#if defined(PNG_READ_pCAL_SUPPORTED)
 155.645 -      else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
 155.646 +
 155.647 +#ifdef PNG_READ_pCAL_SUPPORTED
 155.648 +      else if (!png_memcmp(chunk_name, png_pCAL, 4))
 155.649           png_handle_pCAL(png_ptr, info_ptr, length);
 155.650  #endif
 155.651 -#if defined(PNG_READ_sCAL_SUPPORTED)
 155.652 -      else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
 155.653 +
 155.654 +#ifdef PNG_READ_sCAL_SUPPORTED
 155.655 +      else if (!png_memcmp(chunk_name, png_sCAL, 4))
 155.656           png_handle_sCAL(png_ptr, info_ptr, length);
 155.657  #endif
 155.658 -#if defined(PNG_READ_pHYs_SUPPORTED)
 155.659 -      else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
 155.660 +
 155.661 +#ifdef PNG_READ_pHYs_SUPPORTED
 155.662 +      else if (!png_memcmp(chunk_name, png_pHYs, 4))
 155.663           png_handle_pHYs(png_ptr, info_ptr, length);
 155.664  #endif
 155.665 -#if defined(PNG_READ_sBIT_SUPPORTED)
 155.666 -      else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
 155.667 +
 155.668 +#ifdef PNG_READ_sBIT_SUPPORTED
 155.669 +      else if (!png_memcmp(chunk_name, png_sBIT, 4))
 155.670           png_handle_sBIT(png_ptr, info_ptr, length);
 155.671  #endif
 155.672 -#if defined(PNG_READ_sRGB_SUPPORTED)
 155.673 -      else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
 155.674 +
 155.675 +#ifdef PNG_READ_sRGB_SUPPORTED
 155.676 +      else if (!png_memcmp(chunk_name, png_sRGB, 4))
 155.677           png_handle_sRGB(png_ptr, info_ptr, length);
 155.678  #endif
 155.679 -#if defined(PNG_READ_iCCP_SUPPORTED)
 155.680 -      else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
 155.681 +
 155.682 +#ifdef PNG_READ_iCCP_SUPPORTED
 155.683 +      else if (!png_memcmp(chunk_name, png_iCCP, 4))
 155.684           png_handle_iCCP(png_ptr, info_ptr, length);
 155.685  #endif
 155.686 -#if defined(PNG_READ_sPLT_SUPPORTED)
 155.687 -      else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
 155.688 +
 155.689 +#ifdef PNG_READ_sPLT_SUPPORTED
 155.690 +      else if (!png_memcmp(chunk_name, png_sPLT, 4))
 155.691           png_handle_sPLT(png_ptr, info_ptr, length);
 155.692  #endif
 155.693 -#if defined(PNG_READ_tEXt_SUPPORTED)
 155.694 -      else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
 155.695 +
 155.696 +#ifdef PNG_READ_tEXt_SUPPORTED
 155.697 +      else if (!png_memcmp(chunk_name, png_tEXt, 4))
 155.698           png_handle_tEXt(png_ptr, info_ptr, length);
 155.699  #endif
 155.700 -#if defined(PNG_READ_tIME_SUPPORTED)
 155.701 -      else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
 155.702 +
 155.703 +#ifdef PNG_READ_tIME_SUPPORTED
 155.704 +      else if (!png_memcmp(chunk_name, png_tIME, 4))
 155.705           png_handle_tIME(png_ptr, info_ptr, length);
 155.706  #endif
 155.707 -#if defined(PNG_READ_tRNS_SUPPORTED)
 155.708 -      else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
 155.709 +
 155.710 +#ifdef PNG_READ_tRNS_SUPPORTED
 155.711 +      else if (!png_memcmp(chunk_name, png_tRNS, 4))
 155.712           png_handle_tRNS(png_ptr, info_ptr, length);
 155.713  #endif
 155.714 -#if defined(PNG_READ_zTXt_SUPPORTED)
 155.715 -      else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
 155.716 +
 155.717 +#ifdef PNG_READ_zTXt_SUPPORTED
 155.718 +      else if (!png_memcmp(chunk_name, png_zTXt, 4))
 155.719           png_handle_zTXt(png_ptr, info_ptr, length);
 155.720  #endif
 155.721 -#if defined(PNG_READ_iTXt_SUPPORTED)
 155.722 -      else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
 155.723 +
 155.724 +#ifdef PNG_READ_iTXt_SUPPORTED
 155.725 +      else if (!png_memcmp(chunk_name, png_iTXt, 4))
 155.726           png_handle_iTXt(png_ptr, info_ptr, length);
 155.727  #endif
 155.728 +
 155.729        else
 155.730           png_handle_unknown(png_ptr, info_ptr, length);
 155.731     }
 155.732  }
 155.733 -#endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
 155.734 +#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
 155.735  
 155.736 -/* optional call to update the users info_ptr structure */
 155.737 +/* Optional call to update the users info_ptr structure */
 155.738  void PNGAPI
 155.739  png_read_update_info(png_structp png_ptr, png_infop info_ptr)
 155.740  {
 155.741 -   png_debug(1, "in png_read_update_info\n");
 155.742 -   if(png_ptr == NULL) return;
 155.743 +   png_debug(1, "in png_read_update_info");
 155.744 +
 155.745 +   if (png_ptr == NULL)
 155.746 +      return;
 155.747 +
 155.748     if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
 155.749        png_read_start_row(png_ptr);
 155.750 +
 155.751     else
 155.752        png_warning(png_ptr,
 155.753 -      "Ignoring extra png_read_update_info() call; row buffer not reallocated");
 155.754 +          "Ignoring extra png_read_update_info() call;"
 155.755 +          " row buffer not reallocated");
 155.756 +
 155.757 +#ifdef PNG_READ_TRANSFORMS_SUPPORTED
 155.758     png_read_transform_info(png_ptr, info_ptr);
 155.759 +#else
 155.760 +   PNG_UNUSED(info_ptr)
 155.761 +#endif
 155.762  }
 155.763  
 155.764 -#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
 155.765 +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
 155.766  /* Initialize palette, background, etc, after transformations
 155.767   * are set, but before any reading takes place.  This allows
 155.768   * the user to obtain a gamma-corrected palette, for example.
 155.769 @@ -583,63 +454,83 @@
 155.770  void PNGAPI
 155.771  png_start_read_image(png_structp png_ptr)
 155.772  {
 155.773 -   png_debug(1, "in png_start_read_image\n");
 155.774 -   if(png_ptr == NULL) return;
 155.775 +   png_debug(1, "in png_start_read_image");
 155.776 +
 155.777 +   if (png_ptr == NULL)
 155.778 +      return;
 155.779 +
 155.780     if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
 155.781        png_read_start_row(png_ptr);
 155.782 +   else
 155.783 +      png_warning(png_ptr,
 155.784 +          "Ignoring extra png_start_read_image() call;"
 155.785 +          " row buffer not reallocated");
 155.786  }
 155.787 -#endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
 155.788 +#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
 155.789  
 155.790 -#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
 155.791 +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
 155.792  void PNGAPI
 155.793  png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
 155.794  {
 155.795 -#ifdef PNG_USE_LOCAL_ARRAYS
 155.796     PNG_IDAT;
 155.797 -   const int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
 155.798 -   const int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
 155.799 +#ifdef PNG_READ_INTERLACING_SUPPORTED
 155.800 +   PNG_CONST int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55,
 155.801 +       0xff};
 155.802 +   PNG_CONST int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
 155.803  #endif
 155.804     int ret;
 155.805 -   if(png_ptr == NULL) return;
 155.806 -   png_debug2(1, "in png_read_row (row %lu, pass %d)\n",
 155.807 -      png_ptr->row_number, png_ptr->pass);
 155.808 +
 155.809 +   if (png_ptr == NULL)
 155.810 +      return;
 155.811 +
 155.812 +   png_debug2(1, "in png_read_row (row %lu, pass %d)",
 155.813 +       (unsigned long)png_ptr->row_number, png_ptr->pass);
 155.814 +
 155.815     if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
 155.816        png_read_start_row(png_ptr);
 155.817 +
 155.818     if (png_ptr->row_number == 0 && png_ptr->pass == 0)
 155.819     {
 155.820 -   /* check for transforms that have been set but were defined out */
 155.821 +   /* Check for transforms that have been set but were defined out */
 155.822  #if defined(PNG_WRITE_INVERT_SUPPORTED) && !defined(PNG_READ_INVERT_SUPPORTED)
 155.823     if (png_ptr->transformations & PNG_INVERT_MONO)
 155.824 -      png_warning(png_ptr, "PNG_READ_INVERT_SUPPORTED is not defined.");
 155.825 +      png_warning(png_ptr, "PNG_READ_INVERT_SUPPORTED is not defined");
 155.826  #endif
 155.827 +
 155.828  #if defined(PNG_WRITE_FILLER_SUPPORTED) && !defined(PNG_READ_FILLER_SUPPORTED)
 155.829     if (png_ptr->transformations & PNG_FILLER)
 155.830 -      png_warning(png_ptr, "PNG_READ_FILLER_SUPPORTED is not defined.");
 155.831 +      png_warning(png_ptr, "PNG_READ_FILLER_SUPPORTED is not defined");
 155.832  #endif
 155.833 -#if defined(PNG_WRITE_PACKSWAP_SUPPORTED) && !defined(PNG_READ_PACKSWAP_SUPPORTED)
 155.834 +
 155.835 +#if defined(PNG_WRITE_PACKSWAP_SUPPORTED) && \
 155.836 +    !defined(PNG_READ_PACKSWAP_SUPPORTED)
 155.837     if (png_ptr->transformations & PNG_PACKSWAP)
 155.838 -      png_warning(png_ptr, "PNG_READ_PACKSWAP_SUPPORTED is not defined.");
 155.839 +      png_warning(png_ptr, "PNG_READ_PACKSWAP_SUPPORTED is not defined");
 155.840  #endif
 155.841 +
 155.842  #if defined(PNG_WRITE_PACK_SUPPORTED) && !defined(PNG_READ_PACK_SUPPORTED)
 155.843     if (png_ptr->transformations & PNG_PACK)
 155.844 -      png_warning(png_ptr, "PNG_READ_PACK_SUPPORTED is not defined.");
 155.845 +      png_warning(png_ptr, "PNG_READ_PACK_SUPPORTED is not defined");
 155.846  #endif
 155.847 +
 155.848  #if defined(PNG_WRITE_SHIFT_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED)
 155.849     if (png_ptr->transformations & PNG_SHIFT)
 155.850 -      png_warning(png_ptr, "PNG_READ_SHIFT_SUPPORTED is not defined.");
 155.851 +      png_warning(png_ptr, "PNG_READ_SHIFT_SUPPORTED is not defined");
 155.852  #endif
 155.853 +
 155.854  #if defined(PNG_WRITE_BGR_SUPPORTED) && !defined(PNG_READ_BGR_SUPPORTED)
 155.855     if (png_ptr->transformations & PNG_BGR)
 155.856 -      png_warning(png_ptr, "PNG_READ_BGR_SUPPORTED is not defined.");
 155.857 +      png_warning(png_ptr, "PNG_READ_BGR_SUPPORTED is not defined");
 155.858  #endif
 155.859 +
 155.860  #if defined(PNG_WRITE_SWAP_SUPPORTED) && !defined(PNG_READ_SWAP_SUPPORTED)
 155.861     if (png_ptr->transformations & PNG_SWAP_BYTES)
 155.862 -      png_warning(png_ptr, "PNG_READ_SWAP_SUPPORTED is not defined.");
 155.863 +      png_warning(png_ptr, "PNG_READ_SWAP_SUPPORTED is not defined");
 155.864  #endif
 155.865     }
 155.866  
 155.867 -#if defined(PNG_READ_INTERLACING_SUPPORTED)
 155.868 -   /* if interlaced and we do not need a new row, combine row and return */
 155.869 +#ifdef PNG_READ_INTERLACING_SUPPORTED
 155.870 +   /* If interlaced and we do not need a new row, combine row and return */
 155.871     if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
 155.872     {
 155.873        switch (png_ptr->pass)
 155.874 @@ -654,42 +545,50 @@
 155.875                 return;
 155.876              }
 155.877              break;
 155.878 +
 155.879           case 1:
 155.880              if ((png_ptr->row_number & 0x07) || png_ptr->width < 5)
 155.881              {
 155.882                 if (dsp_row != NULL)
 155.883                    png_combine_row(png_ptr, dsp_row,
 155.884 -                     png_pass_dsp_mask[png_ptr->pass]);
 155.885 +                      png_pass_dsp_mask[png_ptr->pass]);
 155.886 +
 155.887                 png_read_finish_row(png_ptr);
 155.888                 return;
 155.889              }
 155.890              break;
 155.891 +
 155.892           case 2:
 155.893              if ((png_ptr->row_number & 0x07) != 4)
 155.894              {
 155.895                 if (dsp_row != NULL && (png_ptr->row_number & 4))
 155.896                    png_combine_row(png_ptr, dsp_row,
 155.897 -                     png_pass_dsp_mask[png_ptr->pass]);
 155.898 +                      png_pass_dsp_mask[png_ptr->pass]);
 155.899 +
 155.900                 png_read_finish_row(png_ptr);
 155.901                 return;
 155.902              }
 155.903              break;
 155.904 +
 155.905           case 3:
 155.906              if ((png_ptr->row_number & 3) || png_ptr->width < 3)
 155.907              {
 155.908                 if (dsp_row != NULL)
 155.909                    png_combine_row(png_ptr, dsp_row,
 155.910 -                     png_pass_dsp_mask[png_ptr->pass]);
 155.911 +                      png_pass_dsp_mask[png_ptr->pass]);
 155.912 +
 155.913                 png_read_finish_row(png_ptr);
 155.914                 return;
 155.915              }
 155.916              break;
 155.917 +
 155.918           case 4:
 155.919              if ((png_ptr->row_number & 3) != 2)
 155.920              {
 155.921                 if (dsp_row != NULL && (png_ptr->row_number & 2))
 155.922                    png_combine_row(png_ptr, dsp_row,
 155.923 -                     png_pass_dsp_mask[png_ptr->pass]);
 155.924 +                      png_pass_dsp_mask[png_ptr->pass]);
 155.925 +
 155.926                 png_read_finish_row(png_ptr);
 155.927                 return;
 155.928              }
 155.929 @@ -699,11 +598,14 @@
 155.930              {
 155.931                 if (dsp_row != NULL)
 155.932                    png_combine_row(png_ptr, dsp_row,
 155.933 -                     png_pass_dsp_mask[png_ptr->pass]);
 155.934 +                      png_pass_dsp_mask[png_ptr->pass]);
 155.935 +
 155.936                 png_read_finish_row(png_ptr);
 155.937                 return;
 155.938              }
 155.939              break;
 155.940 +
 155.941 +         default:
 155.942           case 6:
 155.943              if (!(png_ptr->row_number & 1))
 155.944              {
 155.945 @@ -719,22 +621,19 @@
 155.946        png_error(png_ptr, "Invalid attempt to read row data");
 155.947  
 155.948     png_ptr->zstream.next_out = png_ptr->row_buf;
 155.949 -   png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
 155.950 +   png_ptr->zstream.avail_out =
 155.951 +       (uInt)(PNG_ROWBYTES(png_ptr->pixel_depth,
 155.952 +       png_ptr->iwidth) + 1);
 155.953 +
 155.954     do
 155.955     {
 155.956        if (!(png_ptr->zstream.avail_in))
 155.957        {
 155.958           while (!png_ptr->idat_size)
 155.959           {
 155.960 -            png_byte chunk_length[4];
 155.961 -
 155.962              png_crc_finish(png_ptr, 0);
 155.963  
 155.964 -            png_read_data(png_ptr, chunk_length, 4);
 155.965 -            png_ptr->idat_size = png_get_uint_31(png_ptr,chunk_length);
 155.966 -
 155.967 -            png_reset_crc(png_ptr);
 155.968 -            png_crc_read(png_ptr, png_ptr->chunk_name, 4);
 155.969 +            png_ptr->idat_size = png_read_chunk_header(png_ptr);
 155.970              if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
 155.971                 png_error(png_ptr, "Not enough image data");
 155.972           }
 155.973 @@ -743,22 +642,25 @@
 155.974           if (png_ptr->zbuf_size > png_ptr->idat_size)
 155.975              png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size;
 155.976           png_crc_read(png_ptr, png_ptr->zbuf,
 155.977 -            (png_size_t)png_ptr->zstream.avail_in);
 155.978 +             (png_size_t)png_ptr->zstream.avail_in);
 155.979           png_ptr->idat_size -= png_ptr->zstream.avail_in;
 155.980        }
 155.981 +
 155.982        ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
 155.983 +
 155.984        if (ret == Z_STREAM_END)
 155.985        {
 155.986           if (png_ptr->zstream.avail_out || png_ptr->zstream.avail_in ||
 155.987              png_ptr->idat_size)
 155.988 -            png_error(png_ptr, "Extra compressed data");
 155.989 +            png_benign_error(png_ptr, "Extra compressed data");
 155.990           png_ptr->mode |= PNG_AFTER_IDAT;
 155.991           png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
 155.992           break;
 155.993        }
 155.994 +
 155.995        if (ret != Z_OK)
 155.996           png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg :
 155.997 -                   "Decompression error");
 155.998 +             "Decompression error");
 155.999  
155.1000     } while (png_ptr->zstream.avail_out);
155.1001  
155.1002 @@ -770,17 +672,16 @@
155.1003     png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
155.1004         png_ptr->row_info.width);
155.1005  
155.1006 -   if(png_ptr->row_buf[0])
155.1007 +   if (png_ptr->row_buf[0])
155.1008     png_read_filter_row(png_ptr, &(png_ptr->row_info),
155.1009 -      png_ptr->row_buf + 1, png_ptr->prev_row + 1,
155.1010 -      (int)(png_ptr->row_buf[0]));
155.1011 +       png_ptr->row_buf + 1, png_ptr->prev_row + 1,
155.1012 +       (int)(png_ptr->row_buf[0]));
155.1013  
155.1014 -   png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
155.1015 -      png_ptr->rowbytes + 1);
155.1016 +   png_memcpy(png_ptr->prev_row, png_ptr->row_buf, png_ptr->rowbytes + 1);
155.1017  
155.1018 -#if defined(PNG_MNG_FEATURES_SUPPORTED)
155.1019 -   if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
155.1020 -      (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
155.1021 +#ifdef PNG_MNG_FEATURES_SUPPORTED
155.1022 +   if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
155.1023 +       (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
155.1024     {
155.1025        /* Intrapixel differencing */
155.1026        png_do_read_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1);
155.1027 @@ -788,33 +689,36 @@
155.1028  #endif
155.1029  
155.1030  
155.1031 -   if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
155.1032 +#ifdef PNG_READ_TRANSFORMS_SUPPORTED
155.1033 +   if (png_ptr->transformations)
155.1034        png_do_read_transformations(png_ptr);
155.1035 +#endif
155.1036  
155.1037 -#if defined(PNG_READ_INTERLACING_SUPPORTED)
155.1038 -   /* blow up interlaced rows to full size */
155.1039 +#ifdef PNG_READ_INTERLACING_SUPPORTED
155.1040 +   /* Blow up interlaced rows to full size */
155.1041     if (png_ptr->interlaced &&
155.1042        (png_ptr->transformations & PNG_INTERLACE))
155.1043     {
155.1044        if (png_ptr->pass < 6)
155.1045 -/*       old interface (pre-1.0.9):
155.1046 -         png_do_read_interlace(&(png_ptr->row_info),
155.1047 -            png_ptr->row_buf + 1, png_ptr->pass, png_ptr->transformations);
155.1048 - */
155.1049 +         /* Old interface (pre-1.0.9):
155.1050 +          * png_do_read_interlace(&(png_ptr->row_info),
155.1051 +          *    png_ptr->row_buf + 1, png_ptr->pass, png_ptr->transformations);
155.1052 +          */
155.1053           png_do_read_interlace(png_ptr);
155.1054  
155.1055        if (dsp_row != NULL)
155.1056 -         png_combine_row(png_ptr, dsp_row,
155.1057 -            png_pass_dsp_mask[png_ptr->pass]);
155.1058 +         png_combine_row(png_ptr, dsp_row, png_pass_dsp_mask[png_ptr->pass]);
155.1059 +
155.1060        if (row != NULL)
155.1061 -         png_combine_row(png_ptr, row,
155.1062 -            png_pass_mask[png_ptr->pass]);
155.1063 +         png_combine_row(png_ptr, row, png_pass_mask[png_ptr->pass]);
155.1064     }
155.1065 +
155.1066     else
155.1067  #endif
155.1068     {
155.1069        if (row != NULL)
155.1070           png_combine_row(png_ptr, row, 0xff);
155.1071 +
155.1072        if (dsp_row != NULL)
155.1073           png_combine_row(png_ptr, dsp_row, 0xff);
155.1074     }
155.1075 @@ -823,9 +727,9 @@
155.1076     if (png_ptr->read_row_fn != NULL)
155.1077        (*(png_ptr->read_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
155.1078  }
155.1079 -#endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
155.1080 +#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
155.1081  
155.1082 -#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
155.1083 +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
155.1084  /* Read one or more rows of image data.  If the image is interlaced,
155.1085   * and png_set_interlace_handling() has been called, the rows need to
155.1086   * contain the contents of the rows from the previous pass.  If the
155.1087 @@ -852,14 +756,17 @@
155.1088  
155.1089  void PNGAPI
155.1090  png_read_rows(png_structp png_ptr, png_bytepp row,
155.1091 -   png_bytepp display_row, png_uint_32 num_rows)
155.1092 +    png_bytepp display_row, png_uint_32 num_rows)
155.1093  {
155.1094     png_uint_32 i;
155.1095     png_bytepp rp;
155.1096     png_bytepp dp;
155.1097  
155.1098 -   png_debug(1, "in png_read_rows\n");
155.1099 -   if(png_ptr == NULL) return;
155.1100 +   png_debug(1, "in png_read_rows");
155.1101 +
155.1102 +   if (png_ptr == NULL)
155.1103 +      return;
155.1104 +
155.1105     rp = row;
155.1106     dp = display_row;
155.1107     if (rp != NULL && dp != NULL)
155.1108 @@ -870,24 +777,26 @@
155.1109  
155.1110           png_read_row(png_ptr, rptr, dptr);
155.1111        }
155.1112 -   else if(rp != NULL)
155.1113 +
155.1114 +   else if (rp != NULL)
155.1115        for (i = 0; i < num_rows; i++)
155.1116        {
155.1117           png_bytep rptr = *rp;
155.1118 -         png_read_row(png_ptr, rptr, png_bytep_NULL);
155.1119 +         png_read_row(png_ptr, rptr, NULL);
155.1120           rp++;
155.1121        }
155.1122 -   else if(dp != NULL)
155.1123 +
155.1124 +   else if (dp != NULL)
155.1125        for (i = 0; i < num_rows; i++)
155.1126        {
155.1127           png_bytep dptr = *dp;
155.1128 -         png_read_row(png_ptr, png_bytep_NULL, dptr);
155.1129 +         png_read_row(png_ptr, NULL, dptr);
155.1130           dp++;
155.1131        }
155.1132  }
155.1133 -#endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
155.1134 +#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
155.1135  
155.1136 -#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
155.1137 +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
155.1138  /* Read the entire image.  If the image has an alpha channel or a tRNS
155.1139   * chunk, and you have called png_handle_alpha()[*], you will need to
155.1140   * initialize the image to the current image that PNG will be overlaying.
155.1141 @@ -903,39 +812,64 @@
155.1142  void PNGAPI
155.1143  png_read_image(png_structp png_ptr, png_bytepp image)
155.1144  {
155.1145 -   png_uint_32 i,image_height;
155.1146 +   png_uint_32 i, image_height;
155.1147     int pass, j;
155.1148     png_bytepp rp;
155.1149  
155.1150 -   png_debug(1, "in png_read_image\n");
155.1151 -   if(png_ptr == NULL) return;
155.1152 +   png_debug(1, "in png_read_image");
155.1153 +
155.1154 +   if (png_ptr == NULL)
155.1155 +      return;
155.1156  
155.1157  #ifdef PNG_READ_INTERLACING_SUPPORTED
155.1158 -   pass = png_set_interlace_handling(png_ptr);
155.1159 +   if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
155.1160 +   {
155.1161 +      pass = png_set_interlace_handling(png_ptr);
155.1162 +      /* And make sure transforms are initialized. */
155.1163 +      png_start_read_image(png_ptr);
155.1164 +   }
155.1165 +   else
155.1166 +   {
155.1167 +      if (png_ptr->interlaced && !(png_ptr->transformations & PNG_INTERLACE))
155.1168 +      {
155.1169 +         /* Caller called png_start_read_image or png_read_update_info without
155.1170 +          * first turning on the PNG_INTERLACE transform.  We can fix this here,
155.1171 +          * but the caller should do it!
155.1172 +          */
155.1173 +         png_warning(png_ptr, "Interlace handling should be turned on when "
155.1174 +            "using png_read_image");
155.1175 +         /* Make sure this is set correctly */
155.1176 +         png_ptr->num_rows = png_ptr->height;
155.1177 +      }
155.1178 +
155.1179 +      /* Obtain the pass number, which also turns on the PNG_INTERLACE flag in
155.1180 +       * the above error case.
155.1181 +       */
155.1182 +      pass = png_set_interlace_handling(png_ptr);
155.1183 +   }
155.1184  #else
155.1185     if (png_ptr->interlaced)
155.1186        png_error(png_ptr,
155.1187 -        "Cannot read interlaced image -- interlace handler disabled.");
155.1188 +          "Cannot read interlaced image -- interlace handler disabled");
155.1189 +
155.1190     pass = 1;
155.1191  #endif
155.1192  
155.1193 -
155.1194     image_height=png_ptr->height;
155.1195 -   png_ptr->num_rows = image_height; /* Make sure this is set correctly */
155.1196  
155.1197     for (j = 0; j < pass; j++)
155.1198     {
155.1199        rp = image;
155.1200        for (i = 0; i < image_height; i++)
155.1201        {
155.1202 -         png_read_row(png_ptr, *rp, png_bytep_NULL);
155.1203 +         png_read_row(png_ptr, *rp, NULL);
155.1204           rp++;
155.1205        }
155.1206     }
155.1207  }
155.1208 -#endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
155.1209 +#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
155.1210  
155.1211 -#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
155.1212 +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
155.1213  /* Read the end of the PNG file.  Will not read past the end of the
155.1214   * file, will verify the end is accurate, and will read any comments
155.1215   * or time information at the end of the file, if info is not NULL.
155.1216 @@ -943,198 +877,220 @@
155.1217  void PNGAPI
155.1218  png_read_end(png_structp png_ptr, png_infop info_ptr)
155.1219  {
155.1220 -   png_byte chunk_length[4];
155.1221 -   png_uint_32 length;
155.1222 +   png_debug(1, "in png_read_end");
155.1223  
155.1224 -   png_debug(1, "in png_read_end\n");
155.1225 -   if(png_ptr == NULL) return;
155.1226 +   if (png_ptr == NULL)
155.1227 +      return;
155.1228 +
155.1229     png_crc_finish(png_ptr, 0); /* Finish off CRC from last IDAT chunk */
155.1230  
155.1231     do
155.1232     {
155.1233 -#ifdef PNG_USE_LOCAL_ARRAYS
155.1234        PNG_IHDR;
155.1235        PNG_IDAT;
155.1236        PNG_IEND;
155.1237        PNG_PLTE;
155.1238 -#if defined(PNG_READ_bKGD_SUPPORTED)
155.1239 +#ifdef PNG_READ_bKGD_SUPPORTED
155.1240        PNG_bKGD;
155.1241  #endif
155.1242 -#if defined(PNG_READ_cHRM_SUPPORTED)
155.1243 +#ifdef PNG_READ_cHRM_SUPPORTED
155.1244        PNG_cHRM;
155.1245  #endif
155.1246 -#if defined(PNG_READ_gAMA_SUPPORTED)
155.1247 +#ifdef PNG_READ_gAMA_SUPPORTED
155.1248        PNG_gAMA;
155.1249  #endif
155.1250 -#if defined(PNG_READ_hIST_SUPPORTED)
155.1251 +#ifdef PNG_READ_hIST_SUPPORTED
155.1252        PNG_hIST;
155.1253  #endif
155.1254 -#if defined(PNG_READ_iCCP_SUPPORTED)
155.1255 +#ifdef PNG_READ_iCCP_SUPPORTED
155.1256        PNG_iCCP;
155.1257  #endif
155.1258 -#if defined(PNG_READ_iTXt_SUPPORTED)
155.1259 +#ifdef PNG_READ_iTXt_SUPPORTED
155.1260        PNG_iTXt;
155.1261  #endif
155.1262 -#if defined(PNG_READ_oFFs_SUPPORTED)
155.1263 +#ifdef PNG_READ_oFFs_SUPPORTED
155.1264        PNG_oFFs;
155.1265  #endif
155.1266 -#if defined(PNG_READ_pCAL_SUPPORTED)
155.1267 +#ifdef PNG_READ_pCAL_SUPPORTED
155.1268        PNG_pCAL;
155.1269  #endif
155.1270 -#if defined(PNG_READ_pHYs_SUPPORTED)
155.1271 +#ifdef PNG_READ_pHYs_SUPPORTED
155.1272        PNG_pHYs;
155.1273  #endif
155.1274 -#if defined(PNG_READ_sBIT_SUPPORTED)
155.1275 +#ifdef PNG_READ_sBIT_SUPPORTED
155.1276        PNG_sBIT;
155.1277  #endif
155.1278 -#if defined(PNG_READ_sCAL_SUPPORTED)
155.1279 +#ifdef PNG_READ_sCAL_SUPPORTED
155.1280        PNG_sCAL;
155.1281  #endif
155.1282 -#if defined(PNG_READ_sPLT_SUPPORTED)
155.1283 +#ifdef PNG_READ_sPLT_SUPPORTED
155.1284        PNG_sPLT;
155.1285  #endif
155.1286 -#if defined(PNG_READ_sRGB_SUPPORTED)
155.1287 +#ifdef PNG_READ_sRGB_SUPPORTED
155.1288        PNG_sRGB;
155.1289  #endif
155.1290 -#if defined(PNG_READ_tEXt_SUPPORTED)
155.1291 +#ifdef PNG_READ_tEXt_SUPPORTED
155.1292        PNG_tEXt;
155.1293  #endif
155.1294 -#if defined(PNG_READ_tIME_SUPPORTED)
155.1295 +#ifdef PNG_READ_tIME_SUPPORTED
155.1296        PNG_tIME;
155.1297  #endif
155.1298 -#if defined(PNG_READ_tRNS_SUPPORTED)
155.1299 +#ifdef PNG_READ_tRNS_SUPPORTED
155.1300        PNG_tRNS;
155.1301  #endif
155.1302 -#if defined(PNG_READ_zTXt_SUPPORTED)
155.1303 +#ifdef PNG_READ_zTXt_SUPPORTED
155.1304        PNG_zTXt;
155.1305  #endif
155.1306 -#endif /* PNG_USE_LOCAL_ARRAYS */
155.1307 +      png_uint_32 length = png_read_chunk_header(png_ptr);
155.1308 +      PNG_CONST png_bytep chunk_name = png_ptr->chunk_name;
155.1309  
155.1310 -      png_read_data(png_ptr, chunk_length, 4);
155.1311 -      length = png_get_uint_31(png_ptr,chunk_length);
155.1312 +      if (!png_memcmp(chunk_name, png_IHDR, 4))
155.1313 +         png_handle_IHDR(png_ptr, info_ptr, length);
155.1314  
155.1315 -      png_reset_crc(png_ptr);
155.1316 -      png_crc_read(png_ptr, png_ptr->chunk_name, 4);
155.1317 +      else if (!png_memcmp(chunk_name, png_IEND, 4))
155.1318 +         png_handle_IEND(png_ptr, info_ptr, length);
155.1319  
155.1320 -      png_debug1(0, "Reading %s chunk.\n", png_ptr->chunk_name);
155.1321 -
155.1322 -      if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
155.1323 -         png_handle_IHDR(png_ptr, info_ptr, length);
155.1324 -      else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
155.1325 -         png_handle_IEND(png_ptr, info_ptr, length);
155.1326  #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
155.1327 -      else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
155.1328 +      else if (png_handle_as_unknown(png_ptr, chunk_name))
155.1329        {
155.1330 -         if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
155.1331 +         if (!png_memcmp(chunk_name, png_IDAT, 4))
155.1332           {
155.1333              if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
155.1334 -               png_error(png_ptr, "Too many IDAT's found");
155.1335 +               png_benign_error(png_ptr, "Too many IDATs found");
155.1336           }
155.1337           png_handle_unknown(png_ptr, info_ptr, length);
155.1338 -         if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
155.1339 +         if (!png_memcmp(chunk_name, png_PLTE, 4))
155.1340              png_ptr->mode |= PNG_HAVE_PLTE;
155.1341        }
155.1342  #endif
155.1343 -      else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
155.1344 +
155.1345 +      else if (!png_memcmp(chunk_name, png_IDAT, 4))
155.1346        {
155.1347           /* Zero length IDATs are legal after the last IDAT has been
155.1348            * read, but not after other chunks have been read.
155.1349            */
155.1350           if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
155.1351 -            png_error(png_ptr, "Too many IDAT's found");
155.1352 +            png_benign_error(png_ptr, "Too many IDATs found");
155.1353 +
155.1354           png_crc_finish(png_ptr, length);
155.1355        }
155.1356 -      else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
155.1357 +      else if (!png_memcmp(chunk_name, png_PLTE, 4))
155.1358           png_handle_PLTE(png_ptr, info_ptr, length);
155.1359 -#if defined(PNG_READ_bKGD_SUPPORTED)
155.1360 -      else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
155.1361 +
155.1362 +#ifdef PNG_READ_bKGD_SUPPORTED
155.1363 +      else if (!png_memcmp(chunk_name, png_bKGD, 4))
155.1364           png_handle_bKGD(png_ptr, info_ptr, length);
155.1365  #endif
155.1366 -#if defined(PNG_READ_cHRM_SUPPORTED)
155.1367 -      else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
155.1368 +
155.1369 +#ifdef PNG_READ_cHRM_SUPPORTED
155.1370 +      else if (!png_memcmp(chunk_name, png_cHRM, 4))
155.1371           png_handle_cHRM(png_ptr, info_ptr, length);
155.1372  #endif
155.1373 -#if defined(PNG_READ_gAMA_SUPPORTED)
155.1374 -      else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
155.1375 +
155.1376 +#ifdef PNG_READ_gAMA_SUPPORTED
155.1377 +      else if (!png_memcmp(chunk_name, png_gAMA, 4))
155.1378           png_handle_gAMA(png_ptr, info_ptr, length);
155.1379  #endif
155.1380 -#if defined(PNG_READ_hIST_SUPPORTED)
155.1381 -      else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
155.1382 +
155.1383 +#ifdef PNG_READ_hIST_SUPPORTED
155.1384 +      else if (!png_memcmp(chunk_name, png_hIST, 4))
155.1385           png_handle_hIST(png_ptr, info_ptr, length);
155.1386  #endif
155.1387 -#if defined(PNG_READ_oFFs_SUPPORTED)
155.1388 -      else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
155.1389 +
155.1390 +#ifdef PNG_READ_oFFs_SUPPORTED
155.1391 +      else if (!png_memcmp(chunk_name, png_oFFs, 4))
155.1392           png_handle_oFFs(png_ptr, info_ptr, length);
155.1393  #endif
155.1394 -#if defined(PNG_READ_pCAL_SUPPORTED)
155.1395 -      else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
155.1396 +
155.1397 +#ifdef PNG_READ_pCAL_SUPPORTED
155.1398 +      else if (!png_memcmp(chunk_name, png_pCAL, 4))
155.1399           png_handle_pCAL(png_ptr, info_ptr, length);
155.1400  #endif
155.1401 -#if defined(PNG_READ_sCAL_SUPPORTED)
155.1402 -      else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
155.1403 +
155.1404 +#ifdef PNG_READ_sCAL_SUPPORTED
155.1405 +      else if (!png_memcmp(chunk_name, png_sCAL, 4))
155.1406           png_handle_sCAL(png_ptr, info_ptr, length);
155.1407  #endif
155.1408 -#if defined(PNG_READ_pHYs_SUPPORTED)
155.1409 -      else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
155.1410 +
155.1411 +#ifdef PNG_READ_pHYs_SUPPORTED
155.1412 +      else if (!png_memcmp(chunk_name, png_pHYs, 4))
155.1413           png_handle_pHYs(png_ptr, info_ptr, length);
155.1414  #endif
155.1415 -#if defined(PNG_READ_sBIT_SUPPORTED)
155.1416 -      else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
155.1417 +
155.1418 +#ifdef PNG_READ_sBIT_SUPPORTED
155.1419 +      else if (!png_memcmp(chunk_name, png_sBIT, 4))
155.1420           png_handle_sBIT(png_ptr, info_ptr, length);
155.1421  #endif
155.1422 -#if defined(PNG_READ_sRGB_SUPPORTED)
155.1423 -      else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
155.1424 +
155.1425 +#ifdef PNG_READ_sRGB_SUPPORTED
155.1426 +      else if (!png_memcmp(chunk_name, png_sRGB, 4))
155.1427           png_handle_sRGB(png_ptr, info_ptr, length);
155.1428  #endif
155.1429 -#if defined(PNG_READ_iCCP_SUPPORTED)
155.1430 -      else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
155.1431 +
155.1432 +#ifdef PNG_READ_iCCP_SUPPORTED
155.1433 +      else if (!png_memcmp(chunk_name, png_iCCP, 4))
155.1434           png_handle_iCCP(png_ptr, info_ptr, length);
155.1435  #endif
155.1436 -#if defined(PNG_READ_sPLT_SUPPORTED)
155.1437 -      else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
155.1438 +
155.1439 +#ifdef PNG_READ_sPLT_SUPPORTED
155.1440 +      else if (!png_memcmp(chunk_name, png_sPLT, 4))
155.1441           png_handle_sPLT(png_ptr, info_ptr, length);
155.1442  #endif
155.1443 -#if defined(PNG_READ_tEXt_SUPPORTED)
155.1444 -      else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
155.1445 +
155.1446 +#ifdef PNG_READ_tEXt_SUPPORTED
155.1447 +      else if (!png_memcmp(chunk_name, png_tEXt, 4))
155.1448           png_handle_tEXt(png_ptr, info_ptr, length);
155.1449  #endif
155.1450 -#if defined(PNG_READ_tIME_SUPPORTED)
155.1451 -      else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
155.1452 +
155.1453 +#ifdef PNG_READ_tIME_SUPPORTED
155.1454 +      else if (!png_memcmp(chunk_name, png_tIME, 4))
155.1455           png_handle_tIME(png_ptr, info_ptr, length);
155.1456  #endif
155.1457 -#if defined(PNG_READ_tRNS_SUPPORTED)
155.1458 -      else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
155.1459 +
155.1460 +#ifdef PNG_READ_tRNS_SUPPORTED
155.1461 +      else if (!png_memcmp(chunk_name, png_tRNS, 4))
155.1462           png_handle_tRNS(png_ptr, info_ptr, length);
155.1463  #endif
155.1464 -#if defined(PNG_READ_zTXt_SUPPORTED)
155.1465 -      else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
155.1466 +
155.1467 +#ifdef PNG_READ_zTXt_SUPPORTED
155.1468 +      else if (!png_memcmp(chunk_name, png_zTXt, 4))
155.1469           png_handle_zTXt(png_ptr, info_ptr, length);
155.1470  #endif
155.1471 -#if defined(PNG_READ_iTXt_SUPPORTED)
155.1472 -      else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
155.1473 +
155.1474 +#ifdef PNG_READ_iTXt_SUPPORTED
155.1475 +      else if (!png_memcmp(chunk_name, png_iTXt, 4))
155.1476           png_handle_iTXt(png_ptr, info_ptr, length);
155.1477  #endif
155.1478 +
155.1479        else
155.1480           png_handle_unknown(png_ptr, info_ptr, length);
155.1481     } while (!(png_ptr->mode & PNG_HAVE_IEND));
155.1482  }
155.1483 -#endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
155.1484 +#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
155.1485  
155.1486 -/* free all memory used by the read */
155.1487 +/* Free all memory used by the read */
155.1488  void PNGAPI
155.1489  png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
155.1490 -   png_infopp end_info_ptr_ptr)
155.1491 +    png_infopp end_info_ptr_ptr)
155.1492  {
155.1493     png_structp png_ptr = NULL;
155.1494     png_infop info_ptr = NULL, end_info_ptr = NULL;
155.1495  #ifdef PNG_USER_MEM_SUPPORTED
155.1496 -   png_free_ptr free_fn;
155.1497 -   png_voidp mem_ptr;
155.1498 +   png_free_ptr free_fn = NULL;
155.1499 +   png_voidp mem_ptr = NULL;
155.1500  #endif
155.1501  
155.1502 -   png_debug(1, "in png_destroy_read_struct\n");
155.1503 +   png_debug(1, "in png_destroy_read_struct");
155.1504 +
155.1505     if (png_ptr_ptr != NULL)
155.1506        png_ptr = *png_ptr_ptr;
155.1507 +   if (png_ptr == NULL)
155.1508 +      return;
155.1509 +
155.1510 +#ifdef PNG_USER_MEM_SUPPORTED
155.1511 +   free_fn = png_ptr->free_fn;
155.1512 +   mem_ptr = png_ptr->mem_ptr;
155.1513 +#endif
155.1514  
155.1515     if (info_ptr_ptr != NULL)
155.1516        info_ptr = *info_ptr_ptr;
155.1517 @@ -1142,16 +1098,11 @@
155.1518     if (end_info_ptr_ptr != NULL)
155.1519        end_info_ptr = *end_info_ptr_ptr;
155.1520  
155.1521 -#ifdef PNG_USER_MEM_SUPPORTED
155.1522 -   free_fn = png_ptr->free_fn;
155.1523 -   mem_ptr = png_ptr->mem_ptr;
155.1524 -#endif
155.1525 -
155.1526     png_read_destroy(png_ptr, info_ptr, end_info_ptr);
155.1527  
155.1528     if (info_ptr != NULL)
155.1529     {
155.1530 -#if defined(PNG_TEXT_SUPPORTED)
155.1531 +#ifdef PNG_TEXT_SUPPORTED
155.1532        png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, -1);
155.1533  #endif
155.1534  
155.1535 @@ -1166,12 +1117,12 @@
155.1536  
155.1537     if (end_info_ptr != NULL)
155.1538     {
155.1539 -#if defined(PNG_READ_TEXT_SUPPORTED)
155.1540 +#ifdef PNG_READ_TEXT_SUPPORTED
155.1541        png_free_data(png_ptr, end_info_ptr, PNG_FREE_TEXT, -1);
155.1542  #endif
155.1543  #ifdef PNG_USER_MEM_SUPPORTED
155.1544        png_destroy_struct_2((png_voidp)end_info_ptr, (png_free_ptr)free_fn,
155.1545 -         (png_voidp)mem_ptr);
155.1546 +          (png_voidp)mem_ptr);
155.1547  #else
155.1548        png_destroy_struct((png_voidp)end_info_ptr);
155.1549  #endif
155.1550 @@ -1190,21 +1141,25 @@
155.1551     }
155.1552  }
155.1553  
155.1554 -/* free all memory used by the read (old method) */
155.1555 +/* Free all memory used by the read (old method) */
155.1556  void /* PRIVATE */
155.1557 -png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr)
155.1558 +png_read_destroy(png_structp png_ptr, png_infop info_ptr,
155.1559 +    png_infop end_info_ptr)
155.1560  {
155.1561  #ifdef PNG_SETJMP_SUPPORTED
155.1562     jmp_buf tmp_jmp;
155.1563  #endif
155.1564     png_error_ptr error_fn;
155.1565 +#ifdef PNG_WARNINGS_SUPPORTED
155.1566     png_error_ptr warning_fn;
155.1567 +#endif
155.1568     png_voidp error_ptr;
155.1569  #ifdef PNG_USER_MEM_SUPPORTED
155.1570     png_free_ptr free_fn;
155.1571  #endif
155.1572  
155.1573 -   png_debug(1, "in png_read_destroy\n");
155.1574 +   png_debug(1, "in png_read_destroy");
155.1575 +
155.1576     if (info_ptr != NULL)
155.1577        png_info_destroy(png_ptr, info_ptr);
155.1578  
155.1579 @@ -1214,50 +1169,40 @@
155.1580     png_free(png_ptr, png_ptr->zbuf);
155.1581     png_free(png_ptr, png_ptr->big_row_buf);
155.1582     png_free(png_ptr, png_ptr->prev_row);
155.1583 -#if defined(PNG_READ_DITHER_SUPPORTED)
155.1584 +   png_free(png_ptr, png_ptr->chunkdata);
155.1585 +
155.1586 +#ifdef PNG_READ_QUANTIZE_SUPPORTED
155.1587     png_free(png_ptr, png_ptr->palette_lookup);
155.1588 -   png_free(png_ptr, png_ptr->dither_index);
155.1589 +   png_free(png_ptr, png_ptr->quantize_index);
155.1590  #endif
155.1591 -#if defined(PNG_READ_GAMMA_SUPPORTED)
155.1592 +
155.1593 +#ifdef PNG_READ_GAMMA_SUPPORTED
155.1594     png_free(png_ptr, png_ptr->gamma_table);
155.1595  #endif
155.1596 -#if defined(PNG_READ_BACKGROUND_SUPPORTED)
155.1597 +
155.1598 +#ifdef PNG_READ_BACKGROUND_SUPPORTED
155.1599     png_free(png_ptr, png_ptr->gamma_from_1);
155.1600     png_free(png_ptr, png_ptr->gamma_to_1);
155.1601  #endif
155.1602 -#ifdef PNG_FREE_ME_SUPPORTED
155.1603 +
155.1604     if (png_ptr->free_me & PNG_FREE_PLTE)
155.1605        png_zfree(png_ptr, png_ptr->palette);
155.1606     png_ptr->free_me &= ~PNG_FREE_PLTE;
155.1607 -#else
155.1608 -   if (png_ptr->flags & PNG_FLAG_FREE_PLTE)
155.1609 -      png_zfree(png_ptr, png_ptr->palette);
155.1610 -   png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;
155.1611 -#endif
155.1612 +
155.1613  #if defined(PNG_tRNS_SUPPORTED) || \
155.1614      defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
155.1615 -#ifdef PNG_FREE_ME_SUPPORTED
155.1616     if (png_ptr->free_me & PNG_FREE_TRNS)
155.1617 -      png_free(png_ptr, png_ptr->trans);
155.1618 +      png_free(png_ptr, png_ptr->trans_alpha);
155.1619     png_ptr->free_me &= ~PNG_FREE_TRNS;
155.1620 -#else
155.1621 -   if (png_ptr->flags & PNG_FLAG_FREE_TRNS)
155.1622 -      png_free(png_ptr, png_ptr->trans);
155.1623 -   png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
155.1624  #endif
155.1625 -#endif
155.1626 -#if defined(PNG_READ_hIST_SUPPORTED)
155.1627 -#ifdef PNG_FREE_ME_SUPPORTED
155.1628 +
155.1629 +#ifdef PNG_READ_hIST_SUPPORTED
155.1630     if (png_ptr->free_me & PNG_FREE_HIST)
155.1631        png_free(png_ptr, png_ptr->hist);
155.1632     png_ptr->free_me &= ~PNG_FREE_HIST;
155.1633 -#else
155.1634 -   if (png_ptr->flags & PNG_FLAG_FREE_HIST)
155.1635 -      png_free(png_ptr, png_ptr->hist);
155.1636 -   png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
155.1637  #endif
155.1638 -#endif
155.1639 -#if defined(PNG_READ_GAMMA_SUPPORTED)
155.1640 +
155.1641 +#ifdef PNG_READ_GAMMA_SUPPORTED
155.1642     if (png_ptr->gamma_16_table != NULL)
155.1643     {
155.1644        int i;
155.1645 @@ -1268,7 +1213,8 @@
155.1646        }
155.1647     png_free(png_ptr, png_ptr->gamma_16_table);
155.1648     }
155.1649 -#if defined(PNG_READ_BACKGROUND_SUPPORTED)
155.1650 +
155.1651 +#ifdef PNG_READ_BACKGROUND_SUPPORTED
155.1652     if (png_ptr->gamma_16_from_1 != NULL)
155.1653     {
155.1654        int i;
155.1655 @@ -1291,11 +1237,9 @@
155.1656     }
155.1657  #endif
155.1658  #endif
155.1659 -#if defined(PNG_TIME_RFC1123_SUPPORTED)
155.1660 -   png_free(png_ptr, png_ptr->time_buffer);
155.1661 -#endif
155.1662  
155.1663     inflateEnd(&png_ptr->zstream);
155.1664 +
155.1665  #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
155.1666     png_free(png_ptr, png_ptr->save_buffer);
155.1667  #endif
155.1668 @@ -1310,27 +1254,31 @@
155.1669      * being used again.
155.1670      */
155.1671  #ifdef PNG_SETJMP_SUPPORTED
155.1672 -   png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
155.1673 +   png_memcpy(tmp_jmp, png_ptr->longjmp_buffer, png_sizeof(jmp_buf));
155.1674  #endif
155.1675  
155.1676     error_fn = png_ptr->error_fn;
155.1677 +#ifdef PNG_WARNINGS_SUPPORTED
155.1678     warning_fn = png_ptr->warning_fn;
155.1679 +#endif
155.1680     error_ptr = png_ptr->error_ptr;
155.1681  #ifdef PNG_USER_MEM_SUPPORTED
155.1682     free_fn = png_ptr->free_fn;
155.1683  #endif
155.1684  
155.1685 -   png_memset(png_ptr, 0, png_sizeof (png_struct));
155.1686 +   png_memset(png_ptr, 0, png_sizeof(png_struct));
155.1687  
155.1688     png_ptr->error_fn = error_fn;
155.1689 +#ifdef PNG_WARNINGS_SUPPORTED
155.1690     png_ptr->warning_fn = warning_fn;
155.1691 +#endif
155.1692     png_ptr->error_ptr = error_ptr;
155.1693  #ifdef PNG_USER_MEM_SUPPORTED
155.1694     png_ptr->free_fn = free_fn;
155.1695  #endif
155.1696  
155.1697  #ifdef PNG_SETJMP_SUPPORTED
155.1698 -   png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
155.1699 +   png_memcpy(png_ptr->longjmp_buffer, tmp_jmp, png_sizeof(jmp_buf));
155.1700  #endif
155.1701  
155.1702  }
155.1703 @@ -1338,13 +1286,15 @@
155.1704  void PNGAPI
155.1705  png_set_read_status_fn(png_structp png_ptr, png_read_status_ptr read_row_fn)
155.1706  {
155.1707 -   if(png_ptr == NULL) return;
155.1708 +   if (png_ptr == NULL)
155.1709 +      return;
155.1710 +
155.1711     png_ptr->read_row_fn = read_row_fn;
155.1712  }
155.1713  
155.1714  
155.1715 -#ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
155.1716 -#if defined(PNG_INFO_IMAGE_SUPPORTED)
155.1717 +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
155.1718 +#ifdef PNG_INFO_IMAGE_SUPPORTED
155.1719  void PNGAPI
155.1720  png_read_png(png_structp png_ptr, png_infop info_ptr,
155.1721                             int transforms,
155.1722 @@ -1352,36 +1302,45 @@
155.1723  {
155.1724     int row;
155.1725  
155.1726 -   if(png_ptr == NULL) return;
155.1727 -#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
155.1728 -   /* invert the alpha channel from opacity to transparency
155.1729 -    */
155.1730 -   if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
155.1731 -       png_set_invert_alpha(png_ptr);
155.1732 -#endif
155.1733 +   if (png_ptr == NULL || info_ptr == NULL)
155.1734 +      return;
155.1735  
155.1736     /* png_read_info() gives us all of the information from the
155.1737      * PNG file before the first IDAT (image data chunk).
155.1738      */
155.1739     png_read_info(png_ptr, info_ptr);
155.1740     if (info_ptr->height > PNG_UINT_32_MAX/png_sizeof(png_bytep))
155.1741 -      png_error(png_ptr,"Image is too high to process with png_read_png()");
155.1742 +      png_error(png_ptr, "Image is too high to process with png_read_png()");
155.1743  
155.1744     /* -------------- image transformations start here ------------------- */
155.1745  
155.1746 -#if defined(PNG_READ_16_TO_8_SUPPORTED)
155.1747 -   /* tell libpng to strip 16 bit/color files down to 8 bits per color
155.1748 +#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
155.1749 +   /* Tell libpng to strip 16-bit/color files down to 8 bits per color.
155.1750 +    */
155.1751 +   if (transforms & PNG_TRANSFORM_SCALE_16)
155.1752 +   {
155.1753 +     /* Added at libpng-1.5.4. "strip_16" produces the same result that it
155.1754 +      * did in earlier versions, while "scale_16" is now more accurate.
155.1755 +      */
155.1756 +      png_set_scale_16(png_ptr);
155.1757 +   }
155.1758 +#endif
155.1759 +
155.1760 +#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED
155.1761 +   /* If both SCALE and STRIP are required pngrtran will effectively cancel the
155.1762 +    * latter by doing SCALE first.  This is ok and allows apps not to check for
155.1763 +    * which is supported to get the right answer.
155.1764      */
155.1765     if (transforms & PNG_TRANSFORM_STRIP_16)
155.1766 -       png_set_strip_16(png_ptr);
155.1767 +      png_set_strip_16(png_ptr);
155.1768  #endif
155.1769  
155.1770 -#if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
155.1771 +#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
155.1772     /* Strip alpha bytes from the input data without combining with
155.1773      * the background (not recommended).
155.1774      */
155.1775     if (transforms & PNG_TRANSFORM_STRIP_ALPHA)
155.1776 -       png_set_strip_alpha(png_ptr);
155.1777 +      png_set_strip_alpha(png_ptr);
155.1778  #endif
155.1779  
155.1780  #if defined(PNG_READ_PACK_SUPPORTED) && !defined(PNG_READ_EXPAND_SUPPORTED)
155.1781 @@ -1389,41 +1348,41 @@
155.1782      * byte into separate bytes (useful for paletted and grayscale images).
155.1783      */
155.1784     if (transforms & PNG_TRANSFORM_PACKING)
155.1785 -       png_set_packing(png_ptr);
155.1786 +      png_set_packing(png_ptr);
155.1787  #endif
155.1788  
155.1789 -#if defined(PNG_READ_PACKSWAP_SUPPORTED)
155.1790 +#ifdef PNG_READ_PACKSWAP_SUPPORTED
155.1791     /* Change the order of packed pixels to least significant bit first
155.1792      * (not useful if you are using png_set_packing).
155.1793      */
155.1794     if (transforms & PNG_TRANSFORM_PACKSWAP)
155.1795 -       png_set_packswap(png_ptr);
155.1796 +      png_set_packswap(png_ptr);
155.1797  #endif
155.1798  
155.1799 -#if defined(PNG_READ_EXPAND_SUPPORTED)
155.1800 +#ifdef PNG_READ_EXPAND_SUPPORTED
155.1801     /* Expand paletted colors into true RGB triplets
155.1802      * Expand grayscale images to full 8 bits from 1, 2, or 4 bits/pixel
155.1803      * Expand paletted or RGB images with transparency to full alpha
155.1804      * channels so the data will be available as RGBA quartets.
155.1805      */
155.1806     if (transforms & PNG_TRANSFORM_EXPAND)
155.1807 -       if ((png_ptr->bit_depth < 8) ||
155.1808 -           (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ||
155.1809 -           (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)))
155.1810 +      if ((png_ptr->bit_depth < 8) ||
155.1811 +          (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ||
155.1812 +          (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)))
155.1813           png_set_expand(png_ptr);
155.1814  #endif
155.1815  
155.1816 -   /* We don't handle background color or gamma transformation or dithering.
155.1817 +   /* We don't handle background color or gamma transformation or quantizing.
155.1818      */
155.1819  
155.1820 -#if defined(PNG_READ_INVERT_SUPPORTED)
155.1821 -   /* invert monochrome files to have 0 as white and 1 as black
155.1822 +#ifdef PNG_READ_INVERT_SUPPORTED
155.1823 +   /* Invert monochrome files to have 0 as white and 1 as black
155.1824      */
155.1825     if (transforms & PNG_TRANSFORM_INVERT_MONO)
155.1826 -       png_set_invert_mono(png_ptr);
155.1827 +      png_set_invert_mono(png_ptr);
155.1828  #endif
155.1829  
155.1830 -#if defined(PNG_READ_SHIFT_SUPPORTED)
155.1831 +#ifdef PNG_READ_SHIFT_SUPPORTED
155.1832     /* If you want to shift the pixel values from the range [0,255] or
155.1833      * [0,65535] to the original [0,7] or [0,31], or whatever range the
155.1834      * colors were originally in:
155.1835 @@ -1438,29 +1397,51 @@
155.1836     }
155.1837  #endif
155.1838  
155.1839 -#if defined(PNG_READ_BGR_SUPPORTED)
155.1840 -   /* flip the RGB pixels to BGR (or RGBA to BGRA)
155.1841 -    */
155.1842 +#ifdef PNG_READ_BGR_SUPPORTED
155.1843 +   /* Flip the RGB pixels to BGR (or RGBA to BGRA) */
155.1844     if (transforms & PNG_TRANSFORM_BGR)
155.1845 -       png_set_bgr(png_ptr);
155.1846 +      png_set_bgr(png_ptr);
155.1847  #endif
155.1848  
155.1849 -#if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
155.1850 -   /* swap the RGBA or GA data to ARGB or AG (or BGRA to ABGR)
155.1851 -    */
155.1852 +#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED
155.1853 +   /* Swap the RGBA or GA data to ARGB or AG (or BGRA to ABGR) */
155.1854     if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
155.1855 -       png_set_swap_alpha(png_ptr);
155.1856 +      png_set_swap_alpha(png_ptr);
155.1857  #endif
155.1858  
155.1859 -#if defined(PNG_READ_SWAP_SUPPORTED)
155.1860 -   /* swap bytes of 16 bit files to least significant byte first
155.1861 -    */
155.1862 +#ifdef PNG_READ_SWAP_SUPPORTED
155.1863 +   /* Swap bytes of 16-bit files to least significant byte first */
155.1864     if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
155.1865 -       png_set_swap(png_ptr);
155.1866 +      png_set_swap(png_ptr);
155.1867 +#endif
155.1868 +
155.1869 +/* Added at libpng-1.2.41 */
155.1870 +#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED
155.1871 +   /* Invert the alpha channel from opacity to transparency */
155.1872 +   if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
155.1873 +      png_set_invert_alpha(png_ptr);
155.1874 +#endif
155.1875 +
155.1876 +/* Added at libpng-1.2.41 */
155.1877 +#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
155.1878 +   /* Expand grayscale image to RGB */
155.1879 +   if (transforms & PNG_TRANSFORM_GRAY_TO_RGB)
155.1880 +      png_set_gray_to_rgb(png_ptr);
155.1881 +#endif
155.1882 +
155.1883 +/* Added at libpng-1.5.4 */
155.1884 +#ifdef PNG_READ_EXPAND_16_SUPPORTED
155.1885 +   if (transforms & PNG_TRANSFORM_EXPAND_16)
155.1886 +      png_set_expand_16(png_ptr);
155.1887  #endif
155.1888  
155.1889     /* We don't handle adding filler bytes */
155.1890  
155.1891 +   /* We use png_read_image and rely on that for interlace handling, but we also
155.1892 +    * call png_read_update_info therefore must turn on interlace handling now:
155.1893 +    */
155.1894 +   (void)png_set_interlace_handling(png_ptr);
155.1895 +
155.1896     /* Optional call to gamma correct and add the background to the palette
155.1897      * and update info structure.  REQUIRED if you are expecting libpng to
155.1898      * update the palette for you (i.e., you selected such a transform above).
155.1899 @@ -1469,33 +1450,33 @@
155.1900  
155.1901     /* -------------- image transformations end here ------------------- */
155.1902  
155.1903 -#ifdef PNG_FREE_ME_SUPPORTED
155.1904     png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
155.1905 -#endif
155.1906 -   if(info_ptr->row_pointers == NULL)
155.1907 +   if (info_ptr->row_pointers == NULL)
155.1908     {
155.1909 +      png_uint_32 iptr;
155.1910 +
155.1911        info_ptr->row_pointers = (png_bytepp)png_malloc(png_ptr,
155.1912 -         info_ptr->height * png_sizeof(png_bytep));
155.1913 -#ifdef PNG_FREE_ME_SUPPORTED
155.1914 +          info_ptr->height * png_sizeof(png_bytep));
155.1915 +      for (iptr=0; iptr<info_ptr->height; iptr++)
155.1916 +         info_ptr->row_pointers[iptr] = NULL;
155.1917 +
155.1918        info_ptr->free_me |= PNG_FREE_ROWS;
155.1919 -#endif
155.1920 +
155.1921        for (row = 0; row < (int)info_ptr->height; row++)
155.1922 -      {
155.1923           info_ptr->row_pointers[row] = (png_bytep)png_malloc(png_ptr,
155.1924              png_get_rowbytes(png_ptr, info_ptr));
155.1925 -      }
155.1926     }
155.1927  
155.1928     png_read_image(png_ptr, info_ptr->row_pointers);
155.1929     info_ptr->valid |= PNG_INFO_IDAT;
155.1930  
155.1931 -   /* read rest of file, and get additional chunks in info_ptr - REQUIRED */
155.1932 +   /* Read rest of file, and get additional chunks in info_ptr - REQUIRED */
155.1933     png_read_end(png_ptr, info_ptr);
155.1934  
155.1935 -   if(transforms == 0 || params == NULL)
155.1936 -      /* quiet compiler warnings */ return;
155.1937 +   PNG_UNUSED(transforms)   /* Quiet compiler warnings */
155.1938 +   PNG_UNUSED(params)
155.1939  
155.1940  }
155.1941  #endif /* PNG_INFO_IMAGE_SUPPORTED */
155.1942 -#endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
155.1943 +#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
155.1944  #endif /* PNG_READ_SUPPORTED */
   156.1 --- a/src/share/native/sun/awt/libpng/pngrio.c	Fri Sep 30 17:20:56 2011 -0700
   156.2 +++ b/src/share/native/sun/awt/libpng/pngrio.c	Tue Oct 04 12:39:42 2011 -0700
   156.3 @@ -29,12 +29,15 @@
   156.4   * However, the following notice accompanied the original version of this
   156.5   * file and, per its terms, should not be removed:
   156.6   *
   156.7 - * Last changed in libpng 1.2.13 November 13, 2006
   156.8 - * For conditions of distribution and use, see copyright notice in png.h
   156.9 - * Copyright (c) 1998-2006 Glenn Randers-Pehrson
  156.10 + * Last changed in libpng 1.5.0 [January 6, 2011]
  156.11 + * Copyright (c) 1998-2011 Glenn Randers-Pehrson
  156.12   * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
  156.13   * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
  156.14   *
  156.15 + * This code is released under the libpng license.
  156.16 + * For conditions of distribution and use, see the disclaimer
  156.17 + * and license in png.h
  156.18 + *
  156.19   * This file provides a location for all input.  Users who need
  156.20   * special handling are expected to write a function that has the same
  156.21   * arguments as this and performs a similar function, but that possibly
  156.22 @@ -43,54 +46,53 @@
  156.23   * libpng use it at run time with png_set_read_fn(...).
  156.24   */
  156.25  
  156.26 -#define PNG_INTERNAL
  156.27 -#include "png.h"
  156.28 +#include "pngpriv.h"
  156.29  
  156.30 -#if defined(PNG_READ_SUPPORTED)
  156.31 +#ifdef PNG_READ_SUPPORTED
  156.32  
  156.33  /* Read the data from whatever input you are using.  The default routine
  156.34 -   reads from a file pointer.  Note that this routine sometimes gets called
  156.35 -   with very small lengths, so you should implement some kind of simple
  156.36 -   buffering if you are using unbuffered reads.  This should never be asked
  156.37 -   to read more then 64K on a 16 bit machine. */
  156.38 + * reads from a file pointer.  Note that this routine sometimes gets called
  156.39 + * with very small lengths, so you should implement some kind of simple
  156.40 + * buffering if you are using unbuffered reads.  This should never be asked
  156.41 + * to read more then 64K on a 16 bit machine.
  156.42 + */
  156.43  void /* PRIVATE */
  156.44  png_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  156.45  {
  156.46 -   png_debug1(4,"reading %d bytes\n", (int)length);
  156.47 +   png_debug1(4, "reading %d bytes", (int)length);
  156.48 +
  156.49     if (png_ptr->read_data_fn != NULL)
  156.50        (*(png_ptr->read_data_fn))(png_ptr, data, length);
  156.51 +
  156.52     else
  156.53        png_error(png_ptr, "Call to NULL read function");
  156.54  }
  156.55  
  156.56 -#if !defined(PNG_NO_STDIO)
  156.57 +#ifdef PNG_STDIO_SUPPORTED
  156.58  /* This is the function that does the actual reading of data.  If you are
  156.59 -   not reading from a standard C stream, you should create a replacement
  156.60 -   read_data function and use it at run time with png_set_read_fn(), rather
  156.61 -   than changing the library. */
  156.62 -#ifndef USE_FAR_KEYWORD
  156.63 -void PNGAPI
  156.64 + * not reading from a standard C stream, you should create a replacement
  156.65 + * read_data function and use it at run time with png_set_read_fn(), rather
  156.66 + * than changing the library.
  156.67 + */
  156.68 +#  ifndef USE_FAR_KEYWORD
  156.69 +void PNGCBAPI
  156.70  png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  156.71  {
  156.72     png_size_t check;
  156.73  
  156.74 -   if(png_ptr == NULL) return;
  156.75 +   if (png_ptr == NULL)
  156.76 +      return;
  156.77 +
  156.78     /* fread() returns 0 on error, so it is OK to store this in a png_size_t
  156.79      * instead of an int, which is what fread() actually returns.
  156.80      */
  156.81 -#if defined(_WIN32_WCE)
  156.82 -   if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  156.83 -      check = 0;
  156.84 -#else
  156.85 -   check = (png_size_t)fread(data, (png_size_t)1, length,
  156.86 -      (png_FILE_p)png_ptr->io_ptr);
  156.87 -#endif
  156.88 +   check = fread(data, 1, length, (png_FILE_p)png_ptr->io_ptr);
  156.89  
  156.90     if (check != length)
  156.91        png_error(png_ptr, "Read Error");
  156.92  }
  156.93 -#else
  156.94 -/* this is the model-independent version. Since the standard I/O library
  156.95 +#  else
  156.96 +/* This is the model-independent version. Since the standard I/O library
  156.97     can't handle far buffers in the medium and small models, we have to copy
  156.98     the data.
  156.99  */
 156.100 @@ -98,80 +100,88 @@
 156.101  #define NEAR_BUF_SIZE 1024
 156.102  #define MIN(a,b) (a <= b ? a : b)
 156.103  
 156.104 -static void PNGAPI
 156.105 +static void PNGCBAPI
 156.106  png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
 156.107  {
 156.108 -   int check;
 156.109 +   png_size_t check;
 156.110     png_byte *n_data;
 156.111     png_FILE_p io_ptr;
 156.112  
 156.113 -   if(png_ptr == NULL) return;
 156.114 +   if (png_ptr == NULL)
 156.115 +      return;
 156.116 +
 156.117     /* Check if data really is near. If so, use usual code. */
 156.118     n_data = (png_byte *)CVT_PTR_NOCHECK(data);
 156.119     io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
 156.120 +
 156.121     if ((png_bytep)n_data == data)
 156.122     {
 156.123 -#if defined(_WIN32_WCE)
 156.124 -      if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
 156.125 -         check = 0;
 156.126 -#else
 156.127        check = fread(n_data, 1, length, io_ptr);
 156.128 -#endif
 156.129     }
 156.130 +
 156.131     else
 156.132     {
 156.133        png_byte buf[NEAR_BUF_SIZE];
 156.134        png_size_t read, remaining, err;
 156.135        check = 0;
 156.136        remaining = length;
 156.137 +
 156.138        do
 156.139        {
 156.140           read = MIN(NEAR_BUF_SIZE, remaining);
 156.141 -#if defined(_WIN32_WCE)
 156.142 -         if ( !ReadFile((HANDLE)(io_ptr), buf, read, &err, NULL) )
 156.143 -            err = 0;
 156.144 -#else
 156.145 -         err = fread(buf, (png_size_t)1, read, io_ptr);
 156.146 -#endif
 156.147 +         err = fread(buf, 1, read, io_ptr);
 156.148           png_memcpy(data, buf, read); /* copy far buffer to near buffer */
 156.149 -         if(err != read)
 156.150 +
 156.151 +         if (err != read)
 156.152              break;
 156.153 +
 156.154           else
 156.155              check += err;
 156.156 +
 156.157           data += read;
 156.158           remaining -= read;
 156.159        }
 156.160        while (remaining != 0);
 156.161     }
 156.162 +
 156.163     if ((png_uint_32)check != (png_uint_32)length)
 156.164        png_error(png_ptr, "read Error");
 156.165  }
 156.166 -#endif
 156.167 +#  endif
 156.168  #endif
 156.169  
 156.170  /* This function allows the application to supply a new input function
 156.171 -   for libpng if standard C streams aren't being used.
 156.172 -
 156.173 -   This function takes as its arguments:
 156.174 -   png_ptr      - pointer to a png input data structure
 156.175 -   io_ptr       - pointer to user supplied structure containing info about
 156.176 -                  the input functions.  May be NULL.
 156.177 -   read_data_fn - pointer to a new input function that takes as its
 156.178 -                  arguments a pointer to a png_struct, a pointer to
 156.179 -                  a location where input data can be stored, and a 32-bit
 156.180 -                  unsigned int that is the number of bytes to be read.
 156.181 -                  To exit and output any fatal error messages the new write
 156.182 -                  function should call png_error(png_ptr, "Error msg"). */
 156.183 + * for libpng if standard C streams aren't being used.
 156.184 + *
 156.185 + * This function takes as its arguments:
 156.186 + *
 156.187 + * png_ptr      - pointer to a png input data structure
 156.188 + *
 156.189 + * io_ptr       - pointer to user supplied structure containing info about
 156.190 + *                the input functions.  May be NULL.
 156.191 + *
 156.192 + * read_data_fn - pointer to a new input function that takes as its
 156.193 + *                arguments a pointer to a png_struct, a pointer to
 156.194 + *                a location where input data can be stored, and a 32-bit
 156.195 + *                unsigned int that is the number of bytes to be read.
 156.196 + *                To exit and output any fatal error messages the new write
 156.197 + *                function should call png_error(png_ptr, "Error msg").
 156.198 + *                May be NULL, in which case libpng's default function will
 156.199 + *                be used.
 156.200 + */
 156.201  void PNGAPI
 156.202  png_set_read_fn(png_structp png_ptr, png_voidp io_ptr,
 156.203     png_rw_ptr read_data_fn)
 156.204  {
 156.205 -   if(png_ptr == NULL) return;
 156.206 +   if (png_ptr == NULL)
 156.207 +      return;
 156.208 +
 156.209     png_ptr->io_ptr = io_ptr;
 156.210  
 156.211 -#if !defined(PNG_NO_STDIO)
 156.212 +#ifdef PNG_STDIO_SUPPORTED
 156.213     if (read_data_fn != NULL)
 156.214        png_ptr->read_data_fn = read_data_fn;
 156.215 +
 156.216     else
 156.217        png_ptr->read_data_fn = png_default_read_data;
 156.218  #else
 156.219 @@ -183,12 +193,11 @@
 156.220     {
 156.221        png_ptr->write_data_fn = NULL;
 156.222        png_warning(png_ptr,
 156.223 -         "It's an error to set both read_data_fn and write_data_fn in the ");
 156.224 -      png_warning(png_ptr,
 156.225 -         "same structure.  Resetting write_data_fn to NULL.");
 156.226 +          "Can't set both read_data_fn and write_data_fn in the"
 156.227 +          " same structure");
 156.228     }
 156.229  
 156.230 -#if defined(PNG_WRITE_FLUSH_SUPPORTED)
 156.231 +#ifdef PNG_WRITE_FLUSH_SUPPORTED
 156.232     png_ptr->output_flush_fn = NULL;
 156.233  #endif
 156.234  }
   157.1 --- a/src/share/native/sun/awt/libpng/pngrtran.c	Fri Sep 30 17:20:56 2011 -0700
   157.2 +++ b/src/share/native/sun/awt/libpng/pngrtran.c	Tue Oct 04 12:39:42 2011 -0700
   157.3 @@ -29,70 +29,86 @@
   157.4   * However, the following notice accompanied the original version of this
   157.5   * file and, per its terms, should not be removed:
   157.6   *
   157.7 - * Last changed in libpng 1.2.15 January 5, 2007
   157.8 - * For conditions of distribution and use, see copyright notice in png.h
   157.9 - * Copyright (c) 1998-2007 Glenn Randers-Pehrson
  157.10 + * Last changed in libpng 1.5.4 [July 7, 2011]
  157.11 + * Copyright (c) 1998-2011 Glenn Randers-Pehrson
  157.12   * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
  157.13   * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
  157.14   *
  157.15 + * This code is released under the libpng license.
  157.16 + * For conditions of distribution and use, see the disclaimer
  157.17 + * and license in png.h
  157.18 + *
  157.19   * This file contains functions optionally called by an application
  157.20   * in order to tell libpng how to handle data when reading a PNG.
  157.21   * Transformations that are used in both reading and writing are
  157.22   * in pngtrans.c.
  157.23   */
  157.24  
  157.25 -#define PNG_INTERNAL
  157.26 -#include "png.h"
  157.27 -
  157.28 -#if defined(PNG_READ_SUPPORTED)
  157.29 +#include "pngpriv.h"
  157.30 +
  157.31 +#ifdef PNG_READ_SUPPORTED
  157.32  
  157.33  /* Set the action on getting a CRC error for an ancillary or critical chunk. */
  157.34  void PNGAPI
  157.35  png_set_crc_action(png_structp png_ptr, int crit_action, int ancil_action)
  157.36  {
  157.37 -   png_debug(1, "in png_set_crc_action\n");
  157.38 +   png_debug(1, "in png_set_crc_action");
  157.39 +
  157.40 +   if (png_ptr == NULL)
  157.41 +      return;
  157.42 +
  157.43     /* Tell libpng how we react to CRC errors in critical chunks */
  157.44 -   if(png_ptr == NULL) return;
  157.45     switch (crit_action)
  157.46     {
  157.47 -      case PNG_CRC_NO_CHANGE:                        /* leave setting as is */
  157.48 +      case PNG_CRC_NO_CHANGE:                        /* Leave setting as is */
  157.49           break;
  157.50 -      case PNG_CRC_WARN_USE:                               /* warn/use data */
  157.51 +
  157.52 +      case PNG_CRC_WARN_USE:                               /* Warn/use data */
  157.53           png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  157.54           png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE;
  157.55           break;
  157.56 -      case PNG_CRC_QUIET_USE:                             /* quiet/use data */
  157.57 +
  157.58 +      case PNG_CRC_QUIET_USE:                             /* Quiet/use data */
  157.59           png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  157.60           png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE |
  157.61                             PNG_FLAG_CRC_CRITICAL_IGNORE;
  157.62           break;
  157.63 -      case PNG_CRC_WARN_DISCARD:    /* not a valid action for critical data */
  157.64 -         png_warning(png_ptr, "Can't discard critical data on CRC error.");
  157.65 -      case PNG_CRC_ERROR_QUIT:                                /* error/quit */
  157.66 +
  157.67 +      case PNG_CRC_WARN_DISCARD:    /* Not a valid action for critical data */
  157.68 +         png_warning(png_ptr,
  157.69 +            "Can't discard critical data on CRC error");
  157.70 +      case PNG_CRC_ERROR_QUIT:                                /* Error/quit */
  157.71 +
  157.72        case PNG_CRC_DEFAULT:
  157.73        default:
  157.74           png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  157.75           break;
  157.76     }
  157.77  
  157.78 +   /* Tell libpng how we react to CRC errors in ancillary chunks */
  157.79     switch (ancil_action)
  157.80     {
  157.81 -      case PNG_CRC_NO_CHANGE:                       /* leave setting as is */
  157.82 +      case PNG_CRC_NO_CHANGE:                       /* Leave setting as is */
  157.83           break;
  157.84 -      case PNG_CRC_WARN_USE:                              /* warn/use data */
  157.85 +
  157.86 +      case PNG_CRC_WARN_USE:                              /* Warn/use data */
  157.87           png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  157.88           png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE;
  157.89           break;
  157.90 -      case PNG_CRC_QUIET_USE:                            /* quiet/use data */
  157.91 +
  157.92 +      case PNG_CRC_QUIET_USE:                            /* Quiet/use data */
  157.93           png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  157.94           png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE |
  157.95                             PNG_FLAG_CRC_ANCILLARY_NOWARN;
  157.96           break;
  157.97 -      case PNG_CRC_ERROR_QUIT:                               /* error/quit */
  157.98 +
  157.99 +      case PNG_CRC_ERROR_QUIT:                               /* Error/quit */
 157.100           png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
 157.101           png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_NOWARN;
 157.102           break;
 157.103 -      case PNG_CRC_WARN_DISCARD:                      /* warn/discard data */
 157.104 +
 157.105 +      case PNG_CRC_WARN_DISCARD:                      /* Warn/discard data */
 157.106 +
 157.107        case PNG_CRC_DEFAULT:
 157.108        default:
 157.109           png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
 157.110 @@ -100,59 +116,283 @@
 157.111     }
 157.112  }
 157.113  
 157.114 -#if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
 157.115 -    defined(PNG_FLOATING_POINT_SUPPORTED)
 157.116 -/* handle alpha and tRNS via a background color */
 157.117 -void PNGAPI
 157.118 -png_set_background(png_structp png_ptr,
 157.119 -   png_color_16p background_color, int background_gamma_code,
 157.120 -   int need_expand, double background_gamma)
 157.121 +#ifdef PNG_READ_BACKGROUND_SUPPORTED
 157.122 +/* Handle alpha and tRNS via a background color */
 157.123 +void PNGFAPI
 157.124 +png_set_background_fixed(png_structp png_ptr,
 157.125 +    png_const_color_16p background_color, int background_gamma_code,
 157.126 +    int need_expand, png_fixed_point background_gamma)
 157.127  {
 157.128 -   png_debug(1, "in png_set_background\n");
 157.129 -   if(png_ptr == NULL) return;
 157.130 +   png_debug(1, "in png_set_background_fixed");
 157.131 +
 157.132 +   if (png_ptr == NULL)
 157.133 +      return;
 157.134 +
 157.135     if (background_gamma_code == PNG_BACKGROUND_GAMMA_UNKNOWN)
 157.136     {
 157.137        png_warning(png_ptr, "Application must supply a known background gamma");
 157.138        return;
 157.139     }
 157.140  
 157.141 -   png_ptr->transformations |= PNG_BACKGROUND;
 157.142 +   png_ptr->transformations |= PNG_COMPOSE | PNG_STRIP_ALPHA;
 157.143 +   png_ptr->transformations &= ~PNG_ENCODE_ALPHA;
 157.144 +   png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA;
 157.145 +
 157.146     png_memcpy(&(png_ptr->background), background_color,
 157.147        png_sizeof(png_color_16));
 157.148 -   png_ptr->background_gamma = (float)background_gamma;
 157.149 +   png_ptr->background_gamma = background_gamma;
 157.150     png_ptr->background_gamma_type = (png_byte)(background_gamma_code);
 157.151 -   png_ptr->transformations |= (need_expand ? PNG_BACKGROUND_EXPAND : 0);
 157.152 +   if (need_expand)
 157.153 +      png_ptr->transformations |= PNG_BACKGROUND_EXPAND;
 157.154 +   else
 157.155 +      png_ptr->transformations &= ~PNG_BACKGROUND_EXPAND;
 157.156 +}
 157.157 +
 157.158 +#  ifdef PNG_FLOATING_POINT_SUPPORTED
 157.159 +void PNGAPI
 157.160 +png_set_background(png_structp png_ptr,
 157.161 +    png_const_color_16p background_color, int background_gamma_code,
 157.162 +    int need_expand, double background_gamma)
 157.163 +{
 157.164 +   png_set_background_fixed(png_ptr, background_color, background_gamma_code,
 157.165 +      need_expand, png_fixed(png_ptr, background_gamma, "png_set_background"));
 157.166 +}
 157.167 +#  endif  /* FLOATING_POINT */
 157.168 +#endif /* READ_BACKGROUND */
 157.169 +
 157.170 +/* Scale 16-bit depth files to 8-bit depth.  If both of these are set then the
 157.171 + * one that pngrtran does first (scale) happens.  This is necessary to allow the
 157.172 + * TRANSFORM and API behavior to be somewhat consistent, and it's simpler.
 157.173 + */
 157.174 +#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
 157.175 +void PNGAPI
 157.176 +png_set_scale_16(png_structp png_ptr)
 157.177 +{
 157.178 +   png_debug(1, "in png_set_scale_16");
 157.179 +
 157.180 +   if (png_ptr == NULL)
 157.181 +      return;
 157.182 +
 157.183 +   png_ptr->transformations |= PNG_SCALE_16_TO_8;
 157.184  }
 157.185  #endif
 157.186  
 157.187 -#if defined(PNG_READ_16_TO_8_SUPPORTED)
 157.188 -/* strip 16 bit depth files to 8 bit depth */
 157.189 +#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED
 157.190 +/* Chop 16-bit depth files to 8-bit depth */
 157.191  void PNGAPI
 157.192  png_set_strip_16(png_structp png_ptr)
 157.193  {
 157.194 -   png_debug(1, "in png_set_strip_16\n");
 157.195 -   if(png_ptr == NULL) return;
 157.196 +   png_debug(1, "in png_set_strip_16");
 157.197 +
 157.198 +   if (png_ptr == NULL)
 157.199 +      return;
 157.200 +
 157.201     png_ptr->transformations |= PNG_16_TO_8;
 157.202  }
 157.203  #endif
 157.204  
 157.205 -#if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
 157.206 +#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
 157.207  void PNGAPI
 157.208  png_set_strip_alpha(png_structp png_ptr)
 157.209  {
 157.210 -   png_debug(1, "in png_set_strip_alpha\n");
 157.211 -   if(png_ptr == NULL) return;
 157.212 -   png_ptr->flags |= PNG_FLAG_STRIP_ALPHA;
 157.213 +   png_debug(1, "in png_set_strip_alpha");
 157.214 +
 157.215 +   if (png_ptr == NULL)
 157.216 +      return;
 157.217 +
 157.218 +   png_ptr->transformations |= PNG_STRIP_ALPHA;
 157.219  }
 157.220  #endif
 157.221  
 157.222 -#if defined(PNG_READ_DITHER_SUPPORTED)
 157.223 -/* Dither file to 8 bit.  Supply a palette, the current number
 157.224 +#if defined(PNG_READ_ALPHA_MODE_SUPPORTED) || defined(PNG_READ_GAMMA_SUPPORTED)
 157.225 +static png_fixed_point
 157.226 +translate_gamma_flags(png_structp png_ptr, png_fixed_point output_gamma,
 157.227 +   int is_screen)
 157.228 +{
 157.229 +   /* Check for flag values.  The main reason for having the old Mac value as a
 157.230 +    * flag is that it is pretty near impossible to work out what the correct
 157.231 +    * value is from Apple documentation - a working Mac system is needed to
 157.232 +    * discover the value!
 157.233 +    */
 157.234 +   if (output_gamma == PNG_DEFAULT_sRGB ||
 157.235 +      output_gamma == PNG_FP_1 / PNG_DEFAULT_sRGB)
 157.236 +   {
 157.237 +      /* If there is no sRGB support this just sets the gamma to the standard
 157.238 +       * sRGB value.  (This is a side effect of using this function!)
 157.239 +       */
 157.240 +#     ifdef PNG_READ_sRGB_SUPPORTED
 157.241 +         png_ptr->flags |= PNG_FLAG_ASSUME_sRGB;
 157.242 +#     endif
 157.243 +      if (is_screen)
 157.244 +         output_gamma = PNG_GAMMA_sRGB;
 157.245 +      else
 157.246 +         output_gamma = PNG_GAMMA_sRGB_INVERSE;
 157.247 +   }
 157.248 +
 157.249 +   else if (output_gamma == PNG_GAMMA_MAC_18 ||
 157.250 +      output_gamma == PNG_FP_1 / PNG_GAMMA_MAC_18)
 157.251 +   {
 157.252 +      if (is_screen)
 157.253 +         output_gamma = PNG_GAMMA_MAC_OLD;
 157.254 +      else
 157.255 +         output_gamma = PNG_GAMMA_MAC_INVERSE;
 157.256 +   }
 157.257 +
 157.258 +   return output_gamma;
 157.259 +}
 157.260 +
 157.261 +#  ifdef PNG_FLOATING_POINT_SUPPORTED
 157.262 +static png_fixed_point
 157.263 +convert_gamma_value(png_structp png_ptr, double output_gamma)
 157.264 +{
 157.265 +   /* The following silently ignores cases where fixed point (times 100,000)
 157.266 +    * gamma values are passed to the floating point API.  This is safe and it
 157.267 +    * means the fixed point constants work just fine with the floating point
 157.268 +    * API.  The alternative would just lead to undetected errors and spurious
 157.269 +    * bug reports.  Negative values fail inside the _fixed API unless they
 157.270 +    * correspond to the flag values.
 157.271 +    */
 157.272 +   if (output_gamma > 0 && output_gamma < 128)
 157.273 +      output_gamma *= PNG_FP_1;
 157.274 +
 157.275 +   /* This preserves -1 and -2 exactly: */
 157.276 +   output_gamma = floor(output_gamma + .5);
 157.277 +
 157.278 +   if (output_gamma > PNG_FP_MAX || output_gamma < PNG_FP_MIN)
 157.279 +      png_fixed_error(png_ptr, "gamma value");
 157.280 +
 157.281 +   return (png_fixed_point)output_gamma;
 157.282 +}
 157.283 +#  endif
 157.284 +#endif /* READ_ALPHA_MODE || READ_GAMMA */
 157.285 +
 157.286 +#ifdef PNG_READ_ALPHA_MODE_SUPPORTED
 157.287 +void PNGFAPI
 157.288 +png_set_alpha_mode_fixed(png_structp png_ptr, int mode,
 157.289 +   png_fixed_point output_gamma)
 157.290 +{
 157.291 +   int compose = 0;
 157.292 +   png_fixed_point file_gamma;
 157.293 +
 157.294 +   png_debug(1, "in png_set_alpha_mode");
 157.295 +
 157.296 +   if (png_ptr == NULL)
 157.297 +      return;
 157.298 +
 157.299 +   output_gamma = translate_gamma_flags(png_ptr, output_gamma, 1/*screen*/);
 157.300 +
 157.301 +   /* Validate the value to ensure it is in a reasonable range. The value
 157.302 +    * is expected to be 1 or greater, but this range test allows for some
 157.303 +    * viewing correction values.  The intent is to weed out users of this API
 157.304 +    * who use the inverse of the gamma value accidentally!  Since some of these
 157.305 +    * values are reasonable this may have to be changed.
 157.306 +    */
 157.307 +   if (output_gamma < 70000 || output_gamma > 300000)
 157.308 +      png_error(png_ptr, "output gamma out of expected range");
 157.309 +
 157.310 +   /* The default file gamma is the inverse of the output gamma; the output
 157.311 +    * gamma may be changed below so get the file value first:
 157.312 +    */
 157.313 +   file_gamma = png_reciprocal(output_gamma);
 157.314 +
 157.315 +   /* There are really 8 possibilities here, composed of any combination
 157.316 +    * of:
 157.317 +    *
 157.318 +    *    premultiply the color channels
 157.319 +    *    do not encode non-opaque pixels
 157.320 +    *    encode the alpha as well as the color channels
 157.321 +    *
 157.322 +    * The differences disappear if the input/output ('screen') gamma is 1.0,
 157.323 +    * because then the encoding is a no-op and there is only the choice of
 157.324 +    * premultiplying the color channels or not.
 157.325 +    *
 157.326 +    * png_set_alpha_mode and png_set_background interact because both use
 157.327 +    * png_compose to do the work.  Calling both is only useful when
 157.328 +    * png_set_alpha_mode is used to set the default mode - PNG_ALPHA_PNG - along
 157.329 +    * with a default gamma value.  Otherwise PNG_COMPOSE must not be set.
 157.330 +    */
 157.331 +   switch (mode)
 157.332 +   {
 157.333 +      case PNG_ALPHA_PNG:        /* default: png standard */
 157.334 +         /* No compose, but it may be set by png_set_background! */
 157.335 +         png_ptr->transformations &= ~PNG_ENCODE_ALPHA;
 157.336 +         png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA;
 157.337 +         break;
 157.338 +
 157.339 +      case PNG_ALPHA_ASSOCIATED: /* color channels premultiplied */
 157.340 +         compose = 1;
 157.341 +         png_ptr->transformations &= ~PNG_ENCODE_ALPHA;
 157.342 +         png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA;
 157.343 +         /* The output is linear: */
 157.344 +         output_gamma = PNG_FP_1;
 157.345 +         break;
 157.346 +
 157.347 +      case PNG_ALPHA_OPTIMIZED:  /* associated, non-opaque pixels linear */
 157.348 +         compose = 1;
 157.349 +         png_ptr->transformations &= ~PNG_ENCODE_ALPHA;
 157.350 +         png_ptr->flags |= PNG_FLAG_OPTIMIZE_ALPHA;
 157.351 +         /* output_gamma records the encoding of opaque pixels! */
 157.352 +         break;
 157.353 +
 157.354 +      case PNG_ALPHA_BROKEN:     /* associated, non-linear, alpha encoded */
 157.355 +         compose = 1;
 157.356 +         png_ptr->transformations |= PNG_ENCODE_ALPHA;
 157.357 +         png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA;
 157.358 +         break;
 157.359 +
 157.360 +      default:
 157.361 +         png_error(png_ptr, "invalid alpha mode");
 157.362 +   }
 157.363 +
 157.364 +   /* Only set the default gamma if the file gamma has not been set (this has
 157.365 +    * the side effect that the gamma in a second call to png_set_alpha_mode will
 157.366 +    * be ignored.)
 157.367 +    */
 157.368 +   if (png_ptr->gamma == 0)
 157.369 +      png_ptr->gamma = file_gamma;
 157.370 +
 157.371 +   /* But always set the output gamma: */
 157.372 +   png_ptr->screen_gamma = output_gamma;
 157.373 +
 157.374 +   /* Finally, if pre-multiplying, set the background fields to achieve the
 157.375 +    * desired result.
 157.376 +    */
 157.377 +   if (compose)
 157.378 +   {
 157.379 +      /* And obtain alpha pre-multiplication by composing on black: */
 157.380 +      png_memset(&png_ptr->background, 0, sizeof png_ptr->background);
 157.381 +      png_ptr->background_gamma = png_ptr->gamma; /* just in case */
 157.382 +      png_ptr->background_gamma_type = PNG_BACKGROUND_GAMMA_FILE;
 157.383 +      png_ptr->transformations &= ~PNG_BACKGROUND_EXPAND;
 157.384 +
 157.385 +      if (png_ptr->transformations & PNG_COMPOSE)
 157.386 +         png_error(png_ptr,
 157.387 +            "conflicting calls to set alpha mode and background");
 157.388 +
 157.389 +      png_ptr->transformations |= PNG_COMPOSE;
 157.390 +   }
 157.391 +
 157.392 +   /* New API, make sure apps call the correct initializers: */
 157.393 +   png_ptr->flags |= PNG_FLAG_DETECT_UNINITIALIZED;
 157.394 +}
 157.395 +
 157.396 +#  ifdef PNG_FLOATING_POINT_SUPPORTED
 157.397 +void PNGAPI
 157.398 +png_set_alpha_mode(png_structp png_ptr, int mode, double output_gamma)
 157.399 +{
 157.400 +   png_set_alpha_mode_fixed(png_ptr, mode, convert_gamma_value(png_ptr,
 157.401 +      output_gamma));
 157.402 +}
 157.403 +#  endif
 157.404 +#endif
 157.405 +
 157.406 +#ifdef PNG_READ_QUANTIZE_SUPPORTED
 157.407 +/* Dither file to 8-bit.  Supply a palette, the current number
 157.408   * of elements in the palette, the maximum number of elements
 157.409   * allowed, and a histogram if possible.  If the current number
 157.410   * of colors is greater then the maximum number, the palette will be
 157.411 - * modified to fit in the maximum number.  "full_dither" indicates
 157.412 - * whether we need a dithering cube set up for RGB images, or if we
 157.413 + * modified to fit in the maximum number.  "full_quantize" indicates
 157.414 + * whether we need a quantizing cube set up for RGB images, or if we
 157.415   * simply are reducing the number of colors in a paletted image.
 157.416   */
 157.417  
 157.418 @@ -166,22 +406,25 @@
 157.419  typedef png_dsort FAR * FAR * png_dsortpp;
 157.420  
 157.421  void PNGAPI
 157.422 -png_set_dither(png_structp png_ptr, png_colorp palette,
 157.423 -   int num_palette, int maximum_colors, png_uint_16p histogram,
 157.424 -   int full_dither)
 157.425 +png_set_quantize(png_structp png_ptr, png_colorp palette,
 157.426 +    int num_palette, int maximum_colors, png_const_uint_16p histogram,
 157.427 +    int full_quantize)
 157.428  {
 157.429 -   png_debug(1, "in png_set_dither\n");
 157.430 -   if(png_ptr == NULL) return;
 157.431 -   png_ptr->transformations |= PNG_DITHER;
 157.432 -
 157.433 -   if (!full_dither)
 157.434 +   png_debug(1, "in png_set_quantize");
 157.435 +
 157.436 +   if (png_ptr == NULL)
 157.437 +      return;
 157.438 +
 157.439 +   png_ptr->transformations |= PNG_QUANTIZE;
 157.440 +
 157.441 +   if (!full_quantize)
 157.442     {
 157.443        int i;
 157.444  
 157.445 -      png_ptr->dither_index = (png_bytep)png_malloc(png_ptr,
 157.446 -         (png_uint_32)(num_palette * png_sizeof (png_byte)));
 157.447 +      png_ptr->quantize_index = (png_bytep)png_malloc(png_ptr,
 157.448 +          (png_uint_32)(num_palette * png_sizeof(png_byte)));
 157.449        for (i = 0; i < num_palette; i++)
 157.450 -         png_ptr->dither_index[i] = (png_byte)i;
 157.451 +         png_ptr->quantize_index[i] = (png_byte)i;
 157.452     }
 157.453  
 157.454     if (num_palette > maximum_colors)
 157.455 @@ -189,61 +432,66 @@
 157.456        if (histogram != NULL)
 157.457        {
 157.458           /* This is easy enough, just throw out the least used colors.
 157.459 -            Perhaps not the best solution, but good enough. */
 157.460 +          * Perhaps not the best solution, but good enough.
 157.461 +          */
 157.462  
 157.463           int i;
 157.464  
 157.465 -         /* initialize an array to sort colors */
 157.466 -         png_ptr->dither_sort = (png_bytep)png_malloc(png_ptr,
 157.467 -            (png_uint_32)(num_palette * png_sizeof (png_byte)));
 157.468 -
 157.469 -         /* initialize the dither_sort array */
 157.470 +         /* Initialize an array to sort colors */
 157.471 +         png_ptr->quantize_sort = (png_bytep)png_malloc(png_ptr,
 157.472 +             (png_uint_32)(num_palette * png_sizeof(png_byte)));
 157.473 +
 157.474 +         /* Initialize the quantize_sort array */
 157.475           for (i = 0; i < num_palette; i++)
 157.476 -            png_ptr->dither_sort[i] = (png_byte)i;
 157.477 +            png_ptr->quantize_sort[i] = (png_byte)i;
 157.478  
 157.479           /* Find the least used palette entries by starting a
 157.480 -            bubble sort, and running it until we have sorted
 157.481 -            out enough colors.  Note that we don't care about
 157.482 -            sorting all the colors, just finding which are
 157.483 -            least used. */
 157.484 +          * bubble sort, and running it until we have sorted
 157.485 +          * out enough colors.  Note that we don't care about
 157.486 +          * sorting all the colors, just finding which are
 157.487 +          * least used.
 157.488 +          */
 157.489  
 157.490           for (i = num_palette - 1; i >= maximum_colors; i--)
 157.491           {
 157.492 -            int done; /* to stop early if the list is pre-sorted */
 157.493 +            int done; /* To stop early if the list is pre-sorted */
 157.494              int j;
 157.495  
 157.496              done = 1;
 157.497              for (j = 0; j < i; j++)
 157.498              {
 157.499 -               if (histogram[png_ptr->dither_sort[j]]
 157.500 -                   < histogram[png_ptr->dither_sort[j + 1]])
 157.501 +               if (histogram[png_ptr->quantize_sort[j]]
 157.502 +                   < histogram[png_ptr->quantize_sort[j + 1]])
 157.503                 {
 157.504                    png_byte t;
 157.505  
 157.506 -                  t = png_ptr->dither_sort[j];
 157.507 -                  png_ptr->dither_sort[j] = png_ptr->dither_sort[j + 1];
 157.508 -                  png_ptr->dither_sort[j + 1] = t;
 157.509 +                  t = png_ptr->quantize_sort[j];
 157.510 +                  png_ptr->quantize_sort[j] = png_ptr->quantize_sort[j + 1];
 157.511 +                  png_ptr->quantize_sort[j + 1] = t;
 157.512                    done = 0;
 157.513                 }
 157.514              }
 157.515 +
 157.516              if (done)
 157.517                 break;
 157.518           }
 157.519  
 157.520 -         /* swap the palette around, and set up a table, if necessary */
 157.521 -         if (full_dither)
 157.522 +         /* Swap the palette around, and set up a table, if necessary */
 157.523 +         if (full_quantize)
 157.524           {
 157.525              int j = num_palette;
 157.526  
 157.527 -            /* put all the useful colors within the max, but don't
 157.528 -               move the others */
 157.529 +            /* Put all the useful colors within the max, but don't
 157.530 +             * move the others.
 157.531 +             */
 157.532              for (i = 0; i < maximum_colors; i++)
 157.533              {
 157.534 -               if ((int)png_ptr->dither_sort[i] >= maximum_colors)
 157.535 +               if ((int)png_ptr->quantize_sort[i] >= maximum_colors)
 157.536                 {
 157.537                    do
 157.538                       j--;
 157.539 -                  while ((int)png_ptr->dither_sort[j] >= maximum_colors);
 157.540 +                  while ((int)png_ptr->quantize_sort[j] >= maximum_colors);
 157.541 +
 157.542                    palette[i] = palette[j];
 157.543                 }
 157.544              }
 157.545 @@ -252,37 +500,38 @@
 157.546           {
 157.547              int j = num_palette;
 157.548  
 157.549 -            /* move all the used colors inside the max limit, and
 157.550 -               develop a translation table */
 157.551 +            /* Move all the used colors inside the max limit, and
 157.552 +             * develop a translation table.
 157.553 +             */
 157.554              for (i = 0; i < maximum_colors; i++)
 157.555              {
 157.556 -               /* only move the colors we need to */
 157.557 -               if ((int)png_ptr->dither_sort[i] >= maximum_colors)
 157.558 +               /* Only move the colors we need to */
 157.559 +               if ((int)png_ptr->quantize_sort[i] >= maximum_colors)
 157.560                 {
 157.561                    png_color tmp_color;
 157.562  
 157.563                    do
 157.564                       j--;
 157.565 -                  while ((int)png_ptr->dither_sort[j] >= maximum_colors);
 157.566 +                  while ((int)png_ptr->quantize_sort[j] >= maximum_colors);
 157.567  
 157.568                    tmp_color = palette[j];
 157.569                    palette[j] = palette[i];
 157.570                    palette[i] = tmp_color;
 157.571 -                  /* indicate where the color went */
 157.572 -                  png_ptr->dither_index[j] = (png_byte)i;
 157.573 -                  png_ptr->dither_index[i] = (png_byte)j;
 157.574 +                  /* Indicate where the color went */
 157.575 +                  png_ptr->quantize_index[j] = (png_byte)i;
 157.576 +                  png_ptr->quantize_index[i] = (png_byte)j;
 157.577                 }
 157.578              }
 157.579  
 157.580 -            /* find closest color for those colors we are not using */
 157.581 +            /* Find closest color for those colors we are not using */
 157.582              for (i = 0; i < num_palette; i++)
 157.583              {
 157.584 -               if ((int)png_ptr->dither_index[i] >= maximum_colors)
 157.585 +               if ((int)png_ptr->quantize_index[i] >= maximum_colors)
 157.586                 {
 157.587                    int min_d, k, min_k, d_index;
 157.588  
 157.589 -                  /* find the closest color to one we threw out */
 157.590 -                  d_index = png_ptr->dither_index[i];
 157.591 +                  /* Find the closest color to one we threw out */
 157.592 +                  d_index = png_ptr->quantize_index[i];
 157.593                    min_d = PNG_COLOR_DIST(palette[d_index], palette[0]);
 157.594                    for (k = 1, min_k = 0; k < maximum_colors; k++)
 157.595                    {
 157.596 @@ -296,61 +545,58 @@
 157.597                          min_k = k;
 157.598                       }
 157.599                    }
 157.600 -                  /* point to closest color */
 157.601 -                  png_ptr->dither_index[i] = (png_byte)min_k;
 157.602 +                  /* Point to closest color */
 157.603 +                  png_ptr->quantize_index[i] = (png_byte)min_k;
 157.604                 }
 157.605              }
 157.606           }
 157.607 -         png_free(png_ptr, png_ptr->dither_sort);
 157.608 -         png_ptr->dither_sort=NULL;
 157.609 +         png_free(png_ptr, png_ptr->quantize_sort);
 157.610 +         png_ptr->quantize_sort = NULL;
 157.611        }
 157.612        else
 157.613        {
 157.614           /* This is much harder to do simply (and quickly).  Perhaps
 157.615 -            we need to go through a median cut routine, but those
 157.616 -            don't always behave themselves with only a few colors
 157.617 -            as input.  So we will just find the closest two colors,
 157.618 -            and throw out one of them (chosen somewhat randomly).
 157.619 -            [We don't understand this at all, so if someone wants to
 157.620 -             work on improving it, be our guest - AED, GRP]
 157.621 -            */
 157.622 +          * we need to go through a median cut routine, but those
 157.623 +          * don't always behave themselves with only a few colors
 157.624 +          * as input.  So we will just find the closest two colors,
 157.625 +          * and throw out one of them (chosen somewhat randomly).
 157.626 +          * [We don't understand this at all, so if someone wants to
 157.627 +          *  work on improving it, be our guest - AED, GRP]
 157.628 +          */
 157.629           int i;
 157.630           int max_d;
 157.631           int num_new_palette;
 157.632           png_dsortp t;
 157.633           png_dsortpp hash;
 157.634  
 157.635 -         t=NULL;
 157.636 -
 157.637 -         /* initialize palette index arrays */
 157.638 +         t = NULL;
 157.639 +
 157.640 +         /* Initialize palette index arrays */
 157.641           png_ptr->index_to_palette = (png_bytep)png_malloc(png_ptr,
 157.642 -            (png_uint_32)(num_palette * png_sizeof (png_byte)));
 157.643 +             (png_uint_32)(num_palette * png_sizeof(png_byte)));
 157.644           png_ptr->palette_to_index = (png_bytep)png_malloc(png_ptr,
 157.645 -            (png_uint_32)(num_palette * png_sizeof (png_byte)));
 157.646 -
 157.647 -         /* initialize the sort array */
 157.648 +             (png_uint_32)(num_palette * png_sizeof(png_byte)));
 157.649 +
 157.650 +         /* Initialize the sort array */
 157.651           for (i = 0; i < num_palette; i++)
 157.652           {
 157.653              png_ptr->index_to_palette[i] = (png_byte)i;
 157.654              png_ptr->palette_to_index[i] = (png_byte)i;
 157.655           }
 157.656  
 157.657 -         hash = (png_dsortpp)png_malloc(png_ptr, (png_uint_32)(769 *
 157.658 -            png_sizeof (png_dsortp)));
 157.659 -         for (i = 0; i < 769; i++)
 157.660 -            hash[i] = NULL;
 157.661 -/*         png_memset(hash, 0, 769 * png_sizeof (png_dsortp)); */
 157.662 +         hash = (png_dsortpp)png_calloc(png_ptr, (png_uint_32)(769 *
 157.663 +             png_sizeof(png_dsortp)));
 157.664  
 157.665           num_new_palette = num_palette;
 157.666  
 157.667 -         /* initial wild guess at how far apart the farthest pixel
 157.668 -            pair we will be eliminating will be.  Larger
 157.669 -            numbers mean more areas will be allocated, Smaller
 157.670 -            numbers run the risk of not saving enough data, and
 157.671 -            having to do this all over again.
 157.672 -
 157.673 -            I have not done extensive checking on this number.
 157.674 -            */
 157.675 +         /* Initial wild guess at how far apart the farthest pixel
 157.676 +          * pair we will be eliminating will be.  Larger
 157.677 +          * numbers mean more areas will be allocated, Smaller
 157.678 +          * numbers run the risk of not saving enough data, and
 157.679 +          * having to do this all over again.
 157.680 +          *
 157.681 +          * I have not done extensive checking on this number.
 157.682 +          */
 157.683           max_d = 96;
 157.684  
 157.685           while (num_new_palette > maximum_colors)
 157.686 @@ -370,8 +616,10 @@
 157.687  
 157.688                       t = (png_dsortp)png_malloc_warn(png_ptr,
 157.689                           (png_uint_32)(png_sizeof(png_dsort)));
 157.690 +
 157.691                       if (t == NULL)
 157.692                           break;
 157.693 +
 157.694                       t->next = hash[d];
 157.695                       t->left = (png_byte)i;
 157.696                       t->right = (png_byte)j;
 157.697 @@ -392,9 +640,9 @@
 157.698                    for (p = hash[i]; p; p = p->next)
 157.699                    {
 157.700                       if ((int)png_ptr->index_to_palette[p->left]
 157.701 -                        < num_new_palette &&
 157.702 -                        (int)png_ptr->index_to_palette[p->right]
 157.703 -                        < num_new_palette)
 157.704 +                         < num_new_palette &&
 157.705 +                         (int)png_ptr->index_to_palette[p->right]
 157.706 +                         < num_new_palette)
 157.707                       {
 157.708                          int j, next_j;
 157.709  
 157.710 @@ -411,31 +659,36 @@
 157.711  
 157.712                          num_new_palette--;
 157.713                          palette[png_ptr->index_to_palette[j]]
 157.714 -                          = palette[num_new_palette];
 157.715 -                        if (!full_dither)
 157.716 +                            = palette[num_new_palette];
 157.717 +                        if (!full_quantize)
 157.718                          {
 157.719                             int k;
 157.720  
 157.721                             for (k = 0; k < num_palette; k++)
 157.722                             {
 157.723 -                              if (png_ptr->dither_index[k] ==
 157.724 -                                 png_ptr->index_to_palette[j])
 157.725 -                                 png_ptr->dither_index[k] =
 157.726 -                                    png_ptr->index_to_palette[next_j];
 157.727 -                              if ((int)png_ptr->dither_index[k] ==
 157.728 -                                 num_new_palette)
 157.729 -                                 png_ptr->dither_index[k] =
 157.730 -                                    png_ptr->index_to_palette[j];
 157.731 +                              if (png_ptr->quantize_index[k] ==
 157.732 +                                  png_ptr->index_to_palette[j])
 157.733 +                                 png_ptr->quantize_index[k] =
 157.734 +                                     png_ptr->index_to_palette[next_j];
 157.735 +
 157.736 +                              if ((int)png_ptr->quantize_index[k] ==
 157.737 +                                  num_new_palette)
 157.738 +                                 png_ptr->quantize_index[k] =
 157.739 +                                     png_ptr->index_to_palette[j];
 157.740                             }
 157.741                          }
 157.742  
 157.743                          png_ptr->index_to_palette[png_ptr->palette_to_index
 157.744 -                           [num_new_palette]] = png_ptr->index_to_palette[j];
 157.745 +                            [num_new_palette]] = png_ptr->index_to_palette[j];
 157.746 +
 157.747                          png_ptr->palette_to_index[png_ptr->index_to_palette[j]]
 157.748 -                           = png_ptr->palette_to_index[num_new_palette];
 157.749 -
 157.750 -                        png_ptr->index_to_palette[j] = (png_byte)num_new_palette;
 157.751 -                        png_ptr->palette_to_index[num_new_palette] = (png_byte)j;
 157.752 +                            = png_ptr->palette_to_index[num_new_palette];
 157.753 +
 157.754 +                        png_ptr->index_to_palette[j] =
 157.755 +                            (png_byte)num_new_palette;
 157.756 +
 157.757 +                        png_ptr->palette_to_index[num_new_palette] =
 157.758 +                            (png_byte)j;
 157.759                       }
 157.760                       if (num_new_palette <= maximum_colors)
 157.761                          break;
 157.762 @@ -464,8 +717,8 @@
 157.763           png_free(png_ptr, hash);
 157.764           png_free(png_ptr, png_ptr->palette_to_index);
 157.765           png_free(png_ptr, png_ptr->index_to_palette);
 157.766 -         png_ptr->palette_to_index=NULL;
 157.767 -         png_ptr->index_to_palette=NULL;
 157.768 +         png_ptr->palette_to_index = NULL;
 157.769 +         png_ptr->index_to_palette = NULL;
 157.770        }
 157.771        num_palette = maximum_colors;
 157.772     }
 157.773 @@ -475,40 +728,38 @@
 157.774     }
 157.775     png_ptr->num_palette = (png_uint_16)num_palette;
 157.776  
 157.777 -   if (full_dither)
 157.778 +   if (full_quantize)
 157.779     {
 157.780        int i;
 157.781        png_bytep distance;
 157.782 -      int total_bits = PNG_DITHER_RED_BITS + PNG_DITHER_GREEN_BITS +
 157.783 -         PNG_DITHER_BLUE_BITS;
 157.784 -      int num_red = (1 << PNG_DITHER_RED_BITS);
 157.785 -      int num_green = (1 << PNG_DITHER_GREEN_BITS);
 157.786 -      int num_blue = (1 << PNG_DITHER_BLUE_BITS);
 157.787 +      int total_bits = PNG_QUANTIZE_RED_BITS + PNG_QUANTIZE_GREEN_BITS +
 157.788 +          PNG_QUANTIZE_BLUE_BITS;
 157.789 +      int num_red = (1 << PNG_QUANTIZE_RED_BITS);
 157.790 +      int num_green = (1 << PNG_QUANTIZE_GREEN_BITS);
 157.791 +      int num_blue = (1 << PNG_QUANTIZE_BLUE_BITS);
 157.792        png_size_t num_entries = ((png_size_t)1 << total_bits);
 157.793  
 157.794 -      png_ptr->palette_lookup = (png_bytep )png_malloc(png_ptr,
 157.795 -         (png_uint_32)(num_entries * png_sizeof (png_byte)));
 157.796 -
 157.797 -      png_memset(png_ptr->palette_lookup, 0, num_entries *
 157.798 -         png_sizeof (png_byte));
 157.799 +      png_ptr->palette_lookup = (png_bytep)png_calloc(png_ptr,
 157.800 +          (png_uint_32)(num_entries * png_sizeof(png_byte)));
 157.801  
 157.802        distance = (png_bytep)png_malloc(png_ptr, (png_uint_32)(num_entries *
 157.803 -         png_sizeof(png_byte)));
 157.804 +          png_sizeof(png_byte)));
 157.805  
 157.806        png_memset(distance, 0xff, num_entries * png_sizeof(png_byte));
 157.807  
 157.808        for (i = 0; i < num_palette; i++)
 157.809        {
 157.810           int ir, ig, ib;
 157.811 -         int r = (palette[i].red >> (8 - PNG_DITHER_RED_BITS));
 157.812 -         int g = (palette[i].green >> (8 - PNG_DITHER_GREEN_BITS));
 157.813 -         int b = (palette[i].blue >> (8 - PNG_DITHER_BLUE_BITS));
 157.814 +         int r = (palette[i].red >> (8 - PNG_QUANTIZE_RED_BITS));
 157.815 +         int g = (palette[i].green >> (8 - PNG_QUANTIZE_GREEN_BITS));
 157.816 +         int b = (palette[i].blue >> (8 - PNG_QUANTIZE_BLUE_BITS));
 157.817  
 157.818           for (ir = 0; ir < num_red; ir++)
 157.819           {
 157.820              /* int dr = abs(ir - r); */
 157.821              int dr = ((ir > r) ? ir - r : r - ir);
 157.822 -            int index_r = (ir << (PNG_DITHER_BLUE_BITS + PNG_DITHER_GREEN_BITS));
 157.823 +            int index_r = (ir << (PNG_QUANTIZE_BLUE_BITS +
 157.824 +                PNG_QUANTIZE_GREEN_BITS));
 157.825  
 157.826              for (ig = 0; ig < num_green; ig++)
 157.827              {
 157.828 @@ -516,7 +767,7 @@
 157.829                 int dg = ((ig > g) ? ig - g : g - ig);
 157.830                 int dt = dr + dg;
 157.831                 int dm = ((dr > dg) ? dr : dg);
 157.832 -               int index_g = index_r | (ig << PNG_DITHER_BLUE_BITS);
 157.833 +               int index_g = index_r | (ig << PNG_QUANTIZE_BLUE_BITS);
 157.834  
 157.835                 for (ib = 0; ib < num_blue; ib++)
 157.836                 {
 157.837 @@ -539,33 +790,59 @@
 157.838        png_free(png_ptr, distance);
 157.839     }
 157.840  }
 157.841 +#endif /* PNG_READ_QUANTIZE_SUPPORTED */
 157.842 +
 157.843 +#ifdef PNG_READ_GAMMA_SUPPORTED
 157.844 +void PNGFAPI
 157.845 +png_set_gamma_fixed(png_structp png_ptr, png_fixed_point scrn_gamma,
 157.846 +   png_fixed_point file_gamma)
 157.847 +{
 157.848 +   png_debug(1, "in png_set_gamma_fixed");
 157.849 +
 157.850 +   if (png_ptr == NULL)
 157.851 +      return;
 157.852 +
 157.853 +   /* New in libpng-1.5.4 - reserve particular negative values as flags. */
 157.854 +   scrn_gamma = translate_gamma_flags(png_ptr, scrn_gamma, 1/*screen*/);
 157.855 +   file_gamma = translate_gamma_flags(png_ptr, file_gamma, 0/*file*/);
 157.856 +
 157.857 +#if PNG_LIBPNG_VER >= 10600
 157.858 +   /* Checking the gamma values for being >0 was added in 1.5.4 along with the
 157.859 +    * premultiplied alpha support; this actually hides an undocumented feature
 157.860 +    * of the previous implementation which allowed gamma processing to be
 157.861 +    * disabled in background handling.  There is no evidence (so far) that this
 157.862 +    * was being used; however, png_set_background itself accepted and must still
 157.863 +    * accept '0' for the gamma value it takes, because it isn't always used.
 157.864 +    *
 157.865 +    * Since this is an API change (albeit a very minor one that removes an
 157.866 +    * undocumented API feature) it will not be made until libpng-1.6.0.
 157.867 +    */
 157.868 +   if (file_gamma <= 0)
 157.869 +      png_error(png_ptr, "invalid file gamma in png_set_gamma");
 157.870 +
 157.871 +   if (scrn_gamma <= 0)
 157.872 +      png_error(png_ptr, "invalid screen gamma in png_set_gamma");
 157.873  #endif
 157.874  
 157.875 -#if defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
 157.876 -/* Transform the image from the file_gamma to the screen_gamma.  We
 157.877 - * only do transformations on images where the file_gamma and screen_gamma
 157.878 - * are not close reciprocals, otherwise it slows things down slightly, and
 157.879 - * also needlessly introduces small errors.
 157.880 - *
 157.881 - * We will turn off gamma transformation later if no semitransparent entries
 157.882 - * are present in the tRNS array for palette images.  We can't do it here
 157.883 - * because we don't necessarily have the tRNS chunk yet.
 157.884 - */
 157.885 +   /* Set the gamma values unconditionally - this overrides the value in the PNG
 157.886 +    * file if a gAMA chunk was present.  png_set_alpha_mode provides a
 157.887 +    * different, easier, way to default the file gamma.
 157.888 +    */
 157.889 +   png_ptr->gamma = file_gamma;
 157.890 +   png_ptr->screen_gamma = scrn_gamma;
 157.891 +}
 157.892 +
 157.893 +#  ifdef PNG_FLOATING_POINT_SUPPORTED
 157.894  void PNGAPI
 157.895  png_set_gamma(png_structp png_ptr, double scrn_gamma, double file_gamma)
 157.896  {
 157.897 -   png_debug(1, "in png_set_gamma\n");
 157.898 -   if(png_ptr == NULL) return;
 157.899 -   if ((fabs(scrn_gamma * file_gamma - 1.0) > PNG_GAMMA_THRESHOLD) ||
 157.900 -       (png_ptr->color_type & PNG_COLOR_MASK_ALPHA) ||
 157.901 -       (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE))
 157.902 -     png_ptr->transformations |= PNG_GAMMA;
 157.903 -   png_ptr->gamma = (float)file_gamma;
 157.904 -   png_ptr->screen_gamma = (float)scrn_gamma;
 157.905 +   png_set_gamma_fixed(png_ptr, convert_gamma_value(png_ptr, scrn_gamma),
 157.906 +      convert_gamma_value(png_ptr, file_gamma));
 157.907  }
 157.908 -#endif
 157.909 -
 157.910 -#if defined(PNG_READ_EXPAND_SUPPORTED)
 157.911 +#  endif /* FLOATING_POINT_SUPPORTED */
 157.912 +#endif /* READ_GAMMA */
 157.913 +
 157.914 +#ifdef PNG_READ_EXPAND_SUPPORTED
 157.915  /* Expand paletted images to RGB, expand grayscale images of
 157.916   * less than 8-bit depth to 8-bit depth, and expand tRNS chunks
 157.917   * to alpha channels.
 157.918 @@ -573,9 +850,13 @@
 157.919  void PNGAPI
 157.920  png_set_expand(png_structp png_ptr)
 157.921  {
 157.922 -   png_debug(1, "in png_set_expand\n");
 157.923 -   if(png_ptr == NULL) return;
 157.924 +   png_debug(1, "in png_set_expand");
 157.925 +
 157.926 +   if (png_ptr == NULL)
 157.927 +      return;
 157.928 +
 157.929     png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
 157.930 +   png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
 157.931  }
 157.932  
 157.933  /* GRR 19990627:  the following three functions currently are identical
 157.934 @@ -591,63 +872,162 @@
 157.935   *  More to the point, these functions make it obvious what libpng will be
 157.936   *  doing, whereas "expand" can (and does) mean any number of things.
 157.937   *
 157.938 - *  GRP 20060307: In libpng-1.4.0, png_set_gray_1_2_4_to_8() was modified
 157.939 - *  to expand only the sample depth but not to expand the tRNS to alpha.
 157.940 + *  GRP 20060307: In libpng-1.2.9, png_set_gray_1_2_4_to_8() was modified
 157.941 + *  to expand only the sample depth but not to expand the tRNS to alpha
 157.942 + *  and its name was changed to png_set_expand_gray_1_2_4_to_8().
 157.943   */
 157.944  
 157.945  /* Expand paletted images to RGB. */
 157.946  void PNGAPI
 157.947  png_set_palette_to_rgb(png_structp png_ptr)
 157.948  {
 157.949 -   png_debug(1, "in png_set_palette_to_rgb\n");
 157.950 -   if(png_ptr == NULL) return;
 157.951 +   png_debug(1, "in png_set_palette_to_rgb");
 157.952 +
 157.953 +   if (png_ptr == NULL)
 157.954 +      return;
 157.955 +
 157.956     png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
 157.957 +   png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
 157.958  }
 157.959  
 157.960 -#if !defined(PNG_1_0_X)
 157.961  /* Expand grayscale images of less than 8-bit depth to 8 bits. */
 157.962  void PNGAPI
 157.963  png_set_expand_gray_1_2_4_to_8(png_structp png_ptr)
 157.964  {
 157.965 -   png_debug(1, "in png_set_expand_gray_1_2_4_to_8\n");
 157.966 -   if(png_ptr == NULL) return;
 157.967 +   png_debug(1, "in png_set_expand_gray_1_2_4_to_8");
 157.968 +
 157.969 +   if (png_ptr == NULL)
 157.970 +      return;
 157.971 +
 157.972     png_ptr->transformations |= PNG_EXPAND;
 157.973 +   png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
 157.974  }
 157.975 -#endif
 157.976 -
 157.977 -#if defined(PNG_1_0_X) || defined(PNG_1_2_X)
 157.978 -/* Expand grayscale images of less than 8-bit depth to 8 bits. */
 157.979 -/* Deprecated as of libpng-1.2.9 */
 157.980 -void PNGAPI
 157.981 -png_set_gray_1_2_4_to_8(png_structp png_ptr)
 157.982 -{
 157.983 -   png_debug(1, "in png_set_gray_1_2_4_to_8\n");
 157.984 -   if(png_ptr == NULL) return;
 157.985 -   png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
 157.986 -}
 157.987 -#endif
 157.988 +
 157.989  
 157.990  
 157.991  /* Expand tRNS chunks to alpha channels. */
 157.992  void PNGAPI
 157.993  png_set_tRNS_to_alpha(png_structp png_ptr)
 157.994  {
 157.995 -   png_debug(1, "in png_set_expand\n");
 157.996 +   png_debug(1, "in png_set_tRNS_to_alpha");
 157.997 +
 157.998     png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
 157.999 +   png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
157.1000  }
157.1001  #endif /* defined(PNG_READ_EXPAND_SUPPORTED) */
157.1002  
157.1003 -#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
157.1004 +#ifdef PNG_READ_EXPAND_16_SUPPORTED
157.1005 +/* Expand to 16-bit channels, expand the tRNS chunk too (because otherwise
157.1006 + * it may not work correctly.)
157.1007 + */
157.1008 +void PNGAPI
157.1009 +png_set_expand_16(png_structp png_ptr)
157.1010 +{
157.1011 +   png_debug(1, "in png_set_expand_16");
157.1012 +
157.1013 +   if (png_ptr == NULL)
157.1014 +      return;
157.1015 +
157.1016 +   png_ptr->transformations |= (PNG_EXPAND_16 | PNG_EXPAND | PNG_EXPAND_tRNS);
157.1017 +   png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
157.1018 +
157.1019 +   /* New API, make sure apps call the correct initializers: */
157.1020 +   png_ptr->flags |= PNG_FLAG_DETECT_UNINITIALIZED;
157.1021 +}
157.1022 +#endif
157.1023 +
157.1024 +#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
157.1025  void PNGAPI
157.1026  png_set_gray_to_rgb(png_structp png_ptr)
157.1027  {
157.1028 -   png_debug(1, "in png_set_gray_to_rgb\n");
157.1029 -   png_ptr->transformations |= PNG_GRAY_TO_RGB;
157.1030 +   png_debug(1, "in png_set_gray_to_rgb");
157.1031 +
157.1032 +   if (png_ptr != NULL)
157.1033 +   {
157.1034 +      /* Because rgb must be 8 bits or more: */
157.1035 +      png_set_expand_gray_1_2_4_to_8(png_ptr);
157.1036 +      png_ptr->transformations |= PNG_GRAY_TO_RGB;
157.1037 +      png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
157.1038 +   }
157.1039  }
157.1040  #endif
157.1041  
157.1042 -#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
157.1043 -#if defined(PNG_FLOATING_POINT_SUPPORTED)
157.1044 +#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
157.1045 +void PNGFAPI
157.1046 +png_set_rgb_to_gray_fixed(png_structp png_ptr, int error_action,
157.1047 +    png_fixed_point red, png_fixed_point green)
157.1048 +{
157.1049 +   png_debug(1, "in png_set_rgb_to_gray");
157.1050 +
157.1051 +   if (png_ptr == NULL)
157.1052 +      return;
157.1053 +
157.1054 +   switch(error_action)
157.1055 +   {
157.1056 +      case 1:
157.1057 +         png_ptr->transformations |= PNG_RGB_TO_GRAY;
157.1058 +         break;
157.1059 +
157.1060 +      case 2:
157.1061 +         png_ptr->transformations |= PNG_RGB_TO_GRAY_WARN;
157.1062 +         break;
157.1063 +
157.1064 +      case 3:
157.1065 +         png_ptr->transformations |= PNG_RGB_TO_GRAY_ERR;
157.1066 +         break;
157.1067 +
157.1068 +      default:
157.1069 +         png_error(png_ptr, "invalid error action to rgb_to_gray");
157.1070 +         break;
157.1071 +   }
157.1072 +   if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
157.1073 +#ifdef PNG_READ_EXPAND_SUPPORTED
157.1074 +      png_ptr->transformations |= PNG_EXPAND;
157.1075 +#else
157.1076 +   {
157.1077 +      png_warning(png_ptr,
157.1078 +        "Cannot do RGB_TO_GRAY without EXPAND_SUPPORTED");
157.1079 +
157.1080 +      png_ptr->transformations &= ~PNG_RGB_TO_GRAY;
157.1081 +   }
157.1082 +#endif
157.1083 +   {
157.1084 +      if (red >= 0 && green >= 0 && red + green <= PNG_FP_1)
157.1085 +      {
157.1086 +         png_uint_16 red_int, green_int;
157.1087 +
157.1088 +         red_int = (png_uint_16)(((png_uint_32)red*32768L)/100000L);
157.1089 +         green_int = (png_uint_16)(((png_uint_32)green*32768L)/100000L);
157.1090 +
157.1091 +         png_ptr->rgb_to_gray_red_coeff   = red_int;
157.1092 +         png_ptr->rgb_to_gray_green_coeff = green_int;
157.1093 +         png_ptr->rgb_to_gray_blue_coeff  =
157.1094 +          (png_uint_16)(32768 - red_int - green_int);
157.1095 +      }
157.1096 +
157.1097 +      else
157.1098 +      {
157.1099 +         if (red >= 0 && green >= 0)
157.1100 +            png_warning(png_ptr,
157.1101 +               "ignoring out of range rgb_to_gray coefficients");
157.1102 +
157.1103 +         /* Use the defaults, from the cHRM chunk if set, else the built in Rec
157.1104 +          * 709 values (which correspond to sRGB, so we don't have to worry
157.1105 +          * about the sRGB chunk!)
157.1106 +          */
157.1107 +         if (png_ptr->rgb_to_gray_red_coeff == 0 &&
157.1108 +            png_ptr->rgb_to_gray_green_coeff == 0 &&
157.1109 +            png_ptr->rgb_to_gray_blue_coeff == 0)
157.1110 +         {
157.1111 +            png_ptr->rgb_to_gray_red_coeff   = 6968;  /* .212671 * 32768 + .5 */
157.1112 +            png_ptr->rgb_to_gray_green_coeff = 23434; /* .715160 * 32768 + .5 */
157.1113 +            png_ptr->rgb_to_gray_blue_coeff  = 2366;
157.1114 +         }
157.1115 +      }
157.1116 +   }
157.1117 +}
157.1118 +
157.1119 +#ifdef PNG_FLOATING_POINT_SUPPORTED
157.1120  /* Convert a RGB image to a grayscale of the same width.  This allows us,
157.1121   * for example, to convert a 24 bpp RGB image into an 8 bpp grayscale image.
157.1122   */
157.1123 @@ -656,240 +1036,526 @@
157.1124  png_set_rgb_to_gray(png_structp png_ptr, int error_action, double red,
157.1125     double green)
157.1126  {
157.1127 -      int red_fixed = (int)((float)red*100000.0 + 0.5);
157.1128 -      int green_fixed = (int)((float)green*100000.0 + 0.5);
157.1129 -      if(png_ptr == NULL) return;
157.1130 -      png_set_rgb_to_gray_fixed(png_ptr, error_action, red_fixed, green_fixed);
157.1131 +   if (png_ptr == NULL)
157.1132 +      return;
157.1133 +
157.1134 +   png_set_rgb_to_gray_fixed(png_ptr, error_action,
157.1135 +      png_fixed(png_ptr, red, "rgb to gray red coefficient"),
157.1136 +      png_fixed(png_ptr, green, "rgb to gray green coefficient"));
157.1137  }
157.1138 +#endif /* FLOATING POINT */
157.1139 +
157.1140  #endif
157.1141  
157.1142 -void PNGAPI
157.1143 -png_set_rgb_to_gray_fixed(png_structp png_ptr, int error_action,
157.1144 -   png_fixed_point red, png_fixed_point green)
157.1145 -{
157.1146 -   png_debug(1, "in png_set_rgb_to_gray\n");
157.1147 -   if(png_ptr == NULL) return;
157.1148 -   switch(error_action)
157.1149 -   {
157.1150 -      case 1: png_ptr->transformations |= PNG_RGB_TO_GRAY;
157.1151 -              break;
157.1152 -      case 2: png_ptr->transformations |= PNG_RGB_TO_GRAY_WARN;
157.1153 -              break;
157.1154 -      case 3: png_ptr->transformations |= PNG_RGB_TO_GRAY_ERR;
157.1155 -   }
157.1156 -   if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
157.1157 -#if defined(PNG_READ_EXPAND_SUPPORTED)
157.1158 -      png_ptr->transformations |= PNG_EXPAND;
157.1159 -#else
157.1160 -   {
157.1161 -      png_warning(png_ptr, "Cannot do RGB_TO_GRAY without EXPAND_SUPPORTED.");
157.1162 -      png_ptr->transformations &= ~PNG_RGB_TO_GRAY;
157.1163 -   }
157.1164 -#endif
157.1165 -   {
157.1166 -      png_uint_16 red_int, green_int;
157.1167 -      if(red < 0 || green < 0)
157.1168 -      {
157.1169 -         red_int   =  6968; /* .212671 * 32768 + .5 */
157.1170 -         green_int = 23434; /* .715160 * 32768 + .5 */
157.1171 -      }
157.1172 -      else if(red + green < 100000L)
157.1173 -      {
157.1174 -        red_int = (png_uint_16)(((png_uint_32)red*32768L)/100000L);
157.1175 -        green_int = (png_uint_16)(((png_uint_32)green*32768L)/100000L);
157.1176 -      }
157.1177 -      else
157.1178 -      {
157.1179 -         png_warning(png_ptr, "ignoring out of range rgb_to_gray coefficients");
157.1180 -         red_int   =  6968;
157.1181 -         green_int = 23434;
157.1182 -      }
157.1183 -      png_ptr->rgb_to_gray_red_coeff   = red_int;
157.1184 -      png_ptr->rgb_to_gray_green_coeff = green_int;
157.1185 -      png_ptr->rgb_to_gray_blue_coeff  = (png_uint_16)(32768-red_int-green_int);
157.1186 -   }
157.1187 -}
157.1188 -#endif
157.1189 -
157.1190  #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
157.1191 -    defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
157.1192 -    defined(PNG_LEGACY_SUPPORTED)
157.1193 +    defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
157.1194  void PNGAPI
157.1195  png_set_read_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
157.1196 -   read_user_transform_fn)
157.1197 +    read_user_transform_fn)
157.1198  {
157.1199 -   png_debug(1, "in png_set_read_user_transform_fn\n");
157.1200 -   if(png_ptr == NULL) return;
157.1201 -#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
157.1202 +   png_debug(1, "in png_set_read_user_transform_fn");
157.1203 +
157.1204 +   if (png_ptr == NULL)
157.1205 +      return;
157.1206 +
157.1207 +#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
157.1208     png_ptr->transformations |= PNG_USER_TRANSFORM;
157.1209     png_ptr->read_user_transform_fn = read_user_transform_fn;
157.1210  #endif
157.1211 -#ifdef PNG_LEGACY_SUPPORTED
157.1212 -   if(read_user_transform_fn)
157.1213 -      png_warning(png_ptr,
157.1214 -        "This version of libpng does not support user transforms");
157.1215 +}
157.1216  #endif
157.1217 +
157.1218 +#ifdef PNG_READ_TRANSFORMS_SUPPORTED
157.1219 +#ifdef PNG_READ_GAMMA_SUPPORTED
157.1220 +/* In the case of gamma transformations only do transformations on images where
157.1221 + * the [file] gamma and screen_gamma are not close reciprocals, otherwise it
157.1222 + * slows things down slightly, and also needlessly introduces small errors.
157.1223 + */
157.1224 +static int /* PRIVATE */
157.1225 +png_gamma_threshold(png_fixed_point screen_gamma, png_fixed_point file_gamma)
157.1226 +{
157.1227 +   /* PNG_GAMMA_THRESHOLD is the threshold for performing gamma
157.1228 +    * correction as a difference of the overall transform from 1.0
157.1229 +    *
157.1230 +    * We want to compare the threshold with s*f - 1, if we get
157.1231 +    * overflow here it is because of wacky gamma values so we
157.1232 +    * turn on processing anyway.
157.1233 +    */
157.1234 +   png_fixed_point gtest;
157.1235 +   return !png_muldiv(&gtest, screen_gamma, file_gamma, PNG_FP_1) ||
157.1236 +       png_gamma_significant(gtest);
157.1237  }
157.1238  #endif
157.1239  
157.1240  /* Initialize everything needed for the read.  This includes modifying
157.1241   * the palette.
157.1242   */
157.1243 +
157.1244 +/*For the moment 'png_init_palette_transformations' and
157.1245 + * 'png_init_rgb_transformations' only do some flag canceling optimizations.
157.1246 + * The intent is that these two routines should have palette or rgb operations
157.1247 + * extracted from 'png_init_read_transformations'.
157.1248 + */
157.1249 +static void /* PRIVATE */
157.1250 +png_init_palette_transformations(png_structp png_ptr)
157.1251 +{
157.1252 +   /* Called to handle the (input) palette case.  In png_do_read_transformations
157.1253 +    * the first step is to expand the palette if requested, so this code must
157.1254 +    * take care to only make changes that are invariant with respect to the
157.1255 +    * palette expansion, or only do them if there is no expansion.
157.1256 +    *
157.1257 +    * STRIP_ALPHA has already been handled in the caller (by setting num_trans
157.1258 +    * to 0.)
157.1259 +    */
157.1260 +   int input_has_alpha = 0;
157.1261 +   int input_has_transparency = 0;
157.1262 +
157.1263 +   if (png_ptr->num_trans > 0)
157.1264 +   {
157.1265 +      int i;
157.1266 +
157.1267 +      /* Ignore if all the entries are opaque (unlikely!) */
157.1268 +      for (i=0; i<png_ptr->num_trans; ++i)
157.1269 +         if (png_ptr->trans_alpha[i] == 255)
157.1270 +            continue;
157.1271 +         else if (png_ptr->trans_alpha[i] == 0)
157.1272 +            input_has_transparency = 1;
157.1273 +         else
157.1274 +            input_has_alpha = 1;
157.1275 +   }
157.1276 +
157.1277 +   /* If no alpha we can optimize. */
157.1278 +   if (!input_has_alpha)
157.1279 +   {
157.1280 +      /* Any alpha means background and associative alpha processing is
157.1281 +       * required, however if the alpha is 0 or 1 throughout OPTIIMIZE_ALPHA
157.1282 +       * and ENCODE_ALPHA are irrelevant.
157.1283 +       */
157.1284 +      png_ptr->transformations &= ~PNG_ENCODE_ALPHA;
157.1285 +      png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA;
157.1286 +
157.1287 +      if (!input_has_transparency)
157.1288 +         png_ptr->transformations &= ~(PNG_COMPOSE | PNG_BACKGROUND_EXPAND);
157.1289 +   }
157.1290 +
157.1291 +#if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED)
157.1292 +   /* png_set_background handling - deals with the complexity of whether the
157.1293 +    * background color is in the file format or the screen format in the case
157.1294 +    * where an 'expand' will happen.
157.1295 +    */
157.1296 +
157.1297 +   /* The following code cannot be entered in the alpha pre-multiplication case
157.1298 +    * because PNG_BACKGROUND_EXPAND is cancelled below.
157.1299 +    */
157.1300 +   if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
157.1301 +       (png_ptr->transformations & PNG_EXPAND))
157.1302 +   {
157.1303 +      {
157.1304 +         png_ptr->background.red   =
157.1305 +             png_ptr->palette[png_ptr->background.index].red;
157.1306 +         png_ptr->background.green =
157.1307 +             png_ptr->palette[png_ptr->background.index].green;
157.1308 +         png_ptr->background.blue  =
157.1309 +             png_ptr->palette[png_ptr->background.index].blue;
157.1310 +
157.1311 +#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED
157.1312 +        if (png_ptr->transformations & PNG_INVERT_ALPHA)
157.1313 +        {
157.1314 +           if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
157.1315 +           {
157.1316 +              /* Invert the alpha channel (in tRNS) unless the pixels are
157.1317 +               * going to be expanded, in which case leave it for later
157.1318 +               */
157.1319 +              int i, istop = png_ptr->num_trans;
157.1320 +
157.1321 +              for (i=0; i<istop; i++)
157.1322 +                 png_ptr->trans_alpha[i] = (png_byte)(255 -
157.1323 +                    png_ptr->trans_alpha[i]);
157.1324 +           }
157.1325 +        }
157.1326 +#endif /* PNG_READ_INVERT_ALPHA_SUPPORTED */
157.1327 +      }
157.1328 +   } /* background expand and (therefore) no alpha association. */
157.1329 +#endif /* PNG_READ_EXPAND_SUPPORTED && PNG_READ_BACKGROUND_SUPPORTED */
157.1330 +}
157.1331 +
157.1332 +static void /* PRIVATE */
157.1333 +png_init_rgb_transformations(png_structp png_ptr)
157.1334 +{
157.1335 +   /* Added to libpng-1.5.4: check the color type to determine whether there
157.1336 +    * is any alpha or transparency in the image and simply cancel the
157.1337 +    * background and alpha mode stuff if there isn't.
157.1338 +    */
157.1339 +   int input_has_alpha = (png_ptr->color_type & PNG_COLOR_MASK_ALPHA) != 0;
157.1340 +   int input_has_transparency = png_ptr->num_trans > 0;
157.1341 +
157.1342 +   /* If no alpha we can optimize. */
157.1343 +   if (!input_has_alpha)
157.1344 +   {
157.1345 +      /* Any alpha means background and associative alpha processing is
157.1346 +       * required, however if the alpha is 0 or 1 throughout OPTIIMIZE_ALPHA
157.1347 +       * and ENCODE_ALPHA are irrelevant.
157.1348 +       */
157.1349 +#     ifdef PNG_READ_ALPHA_MODE_SUPPORTED
157.1350 +         png_ptr->transformations &= ~PNG_ENCODE_ALPHA;
157.1351 +         png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA;
157.1352 +#     endif
157.1353 +
157.1354 +      if (!input_has_transparency)
157.1355 +         png_ptr->transformations &= ~(PNG_COMPOSE | PNG_BACKGROUND_EXPAND);
157.1356 +   }
157.1357 +
157.1358 +#if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED)
157.1359 +   /* png_set_background handling - deals with the complexity of whether the
157.1360 +    * background color is in the file format or the screen format in the case
157.1361 +    * where an 'expand' will happen.
157.1362 +    */
157.1363 +
157.1364 +   /* The following code cannot be entered in the alpha pre-multiplication case
157.1365 +    * because PNG_BACKGROUND_EXPAND is cancelled below.
157.1366 +    */
157.1367 +   if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
157.1368 +       (png_ptr->transformations & PNG_EXPAND) &&
157.1369 +       !(png_ptr->color_type & PNG_COLOR_MASK_COLOR))
157.1370 +       /* i.e., GRAY or GRAY_ALPHA */
157.1371 +   {
157.1372 +      {
157.1373 +         /* Expand background and tRNS chunks */
157.1374 +         switch (png_ptr->bit_depth)
157.1375 +         {
157.1376 +            case 1:
157.1377 +               png_ptr->background.gray *= (png_uint_16)0xff;
157.1378 +               png_ptr->background.red = png_ptr->background.green
157.1379 +                   =  png_ptr->background.blue = png_ptr->background.gray;
157.1380 +               if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
157.1381 +               {
157.1382 +                 png_ptr->trans_color.gray *= (png_uint_16)0xff;
157.1383 +                 png_ptr->trans_color.red = png_ptr->trans_color.green
157.1384 +                     = png_ptr->trans_color.blue = png_ptr->trans_color.gray;
157.1385 +               }
157.1386 +               break;
157.1387 +
157.1388 +            case 2:
157.1389 +               png_ptr->background.gray *= (png_uint_16)0x55;
157.1390 +               png_ptr->background.red = png_ptr->background.green
157.1391 +                   = png_ptr->background.blue = png_ptr->background.gray;
157.1392 +               if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
157.1393 +               {
157.1394 +                  png_ptr->trans_color.gray *= (png_uint_16)0x55;
157.1395 +                  png_ptr->trans_color.red = png_ptr->trans_color.green
157.1396 +                      = png_ptr->trans_color.blue = png_ptr->trans_color.gray;
157.1397 +               }
157.1398 +               break;
157.1399 +
157.1400 +            case 4:
157.1401 +               png_ptr->background.gray *= (png_uint_16)0x11;
157.1402 +               png_ptr->background.red = png_ptr->background.green
157.1403 +                   = png_ptr->background.blue = png_ptr->background.gray;
157.1404 +               if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
157.1405 +               {
157.1406 +                  png_ptr->trans_color.gray *= (png_uint_16)0x11;
157.1407 +                  png_ptr->trans_color.red = png_ptr->trans_color.green
157.1408 +                      = png_ptr->trans_color.blue = png_ptr->trans_color.gray;
157.1409 +               }
157.1410 +               break;
157.1411 +
157.1412 +            default:
157.1413 +
157.1414 +            case 8:
157.1415 +
157.1416 +            case 16:
157.1417 +               png_ptr->background.red = png_ptr->background.green
157.1418 +                   = png_ptr->background.blue = png_ptr->background.gray;
157.1419 +               break;
157.1420 +         }
157.1421 +      }
157.1422 +   } /* background expand and (therefore) no alpha association. */
157.1423 +#endif /* PNG_READ_EXPAND_SUPPORTED && PNG_READ_BACKGROUND_SUPPORTED */
157.1424 +}
157.1425 +
157.1426  void /* PRIVATE */
157.1427  png_init_read_transformations(png_structp png_ptr)
157.1428  {
157.1429 -   png_debug(1, "in png_init_read_transformations\n");
157.1430 -#if defined(PNG_USELESS_TESTS_SUPPORTED)
157.1431 -   if(png_ptr != NULL)
157.1432 +   png_debug(1, "in png_init_read_transformations");
157.1433 +
157.1434 +   /* This internal function is called from png_read_start_row in pngrutil.c
157.1435 +    * and it is called before the 'rowbytes' calculation is done, so the code
157.1436 +    * in here can change or update the transformations flags.
157.1437 +    *
157.1438 +    * First do updates that do not depend on the details of the PNG image data
157.1439 +    * being processed.
157.1440 +    */
157.1441 +
157.1442 +#ifdef PNG_READ_GAMMA_SUPPORTED
157.1443 +   /* Prior to 1.5.4 these tests were performed from png_set_gamma, 1.5.4 adds
157.1444 +    * png_set_alpha_mode and this is another source for a default file gamma so
157.1445 +    * the test needs to be performed later - here.  In addition prior to 1.5.4
157.1446 +    * the tests were repeated for the PALETTE color type here - this is no
157.1447 +    * longer necessary (and doesn't seem to have been necessary before.)
157.1448 +    */
157.1449 +   {
157.1450 +      /* The following temporary indicates if overall gamma correction is
157.1451 +       * required.
157.1452 +       */
157.1453 +      int gamma_correction = 0;
157.1454 +
157.1455 +      if (png_ptr->gamma != 0) /* has been set */
157.1456 +      {
157.1457 +         if (png_ptr->screen_gamma != 0) /* screen set too */
157.1458 +            gamma_correction = png_gamma_threshold(png_ptr->gamma,
157.1459 +               png_ptr->screen_gamma);
157.1460 +
157.1461 +         else
157.1462 +            /* Assume the output matches the input; a long time default behavior
157.1463 +             * of libpng, although the standard has nothing to say about this.
157.1464 +             */
157.1465 +            png_ptr->screen_gamma = png_reciprocal(png_ptr->gamma);
157.1466 +      }
157.1467 +
157.1468 +      else if (png_ptr->screen_gamma != 0)
157.1469 +         /* The converse - assume the file matches the screen, note that this
157.1470 +          * perhaps undesireable default can (from 1.5.4) be changed by calling
157.1471 +          * png_set_alpha_mode (even if the alpha handling mode isn't required
157.1472 +          * or isn't changed from the default.)
157.1473 +          */
157.1474 +         png_ptr->gamma = png_reciprocal(png_ptr->screen_gamma);
157.1475 +
157.1476 +      else /* neither are set */
157.1477 +         /* Just in case the following prevents any processing - file and screen
157.1478 +          * are both assumed to be linear and there is no way to introduce a
157.1479 +          * third gamma value other than png_set_background with 'UNIQUE', and,
157.1480 +          * prior to 1.5.4
157.1481 +          */
157.1482 +         png_ptr->screen_gamma = png_ptr->gamma = PNG_FP_1;
157.1483 +
157.1484 +      /* Now turn the gamma transformation on or off as appropriate.  Notice
157.1485 +       * that PNG_GAMMA just refers to the file->screen correction.  Alpha
157.1486 +       * composition may independently cause gamma correction because it needs
157.1487 +       * linear data (e.g. if the file has a gAMA chunk but the screen gamma
157.1488 +       * hasn't been specified.)  In any case this flag may get turned off in
157.1489 +       * the code immediately below if the transform can be handled outside the
157.1490 +       * row loop.
157.1491 +       */
157.1492 +      if (gamma_correction)
157.1493 +         png_ptr->transformations |= PNG_GAMMA;
157.1494 +
157.1495 +      else
157.1496 +         png_ptr->transformations &= ~PNG_GAMMA;
157.1497 +   }
157.1498  #endif
157.1499 -  {
157.1500 -#if defined(PNG_READ_BACKGROUND_SUPPORTED) || defined(PNG_READ_SHIFT_SUPPORTED) \
157.1501 - || defined(PNG_READ_GAMMA_SUPPORTED)
157.1502 -   int color_type = png_ptr->color_type;
157.1503 +
157.1504 +   /* Certain transformations have the effect of preventing other
157.1505 +    * transformations that happen afterward in png_do_read_transformations,
157.1506 +    * resolve the interdependencies here.  From the code of
157.1507 +    * png_do_read_transformations the order is:
157.1508 +    *
157.1509 +    *  1) PNG_EXPAND (including PNG_EXPAND_tRNS)
157.1510 +    *  2) PNG_STRIP_ALPHA (if no compose)
157.1511 +    *  3) PNG_RGB_TO_GRAY
157.1512 +    *  4) PNG_GRAY_TO_RGB iff !PNG_BACKGROUND_IS_GRAY
157.1513 +    *  5) PNG_COMPOSE
157.1514 +    *  6) PNG_GAMMA
157.1515 +    *  7) PNG_STRIP_ALPHA (if compose)
157.1516 +    *  8) PNG_ENCODE_ALPHA
157.1517 +    *  9) PNG_SCALE_16_TO_8
157.1518 +    * 10) PNG_16_TO_8
157.1519 +    * 11) PNG_QUANTIZE (converts to palette)
157.1520 +    * 12) PNG_EXPAND_16
157.1521 +    * 13) PNG_GRAY_TO_RGB iff PNG_BACKGROUND_IS_GRAY
157.1522 +    * 14) PNG_INVERT_MONO
157.1523 +    * 15) PNG_SHIFT
157.1524 +    * 16) PNG_PACK
157.1525 +    * 17) PNG_BGR
157.1526 +    * 18) PNG_PACKSWAP
157.1527 +    * 19) PNG_FILLER (includes PNG_ADD_ALPHA)
157.1528 +    * 20) PNG_INVERT_ALPHA
157.1529 +    * 21) PNG_SWAP_ALPHA
157.1530 +    * 22) PNG_SWAP_BYTES
157.1531 +    * 23) PNG_USER_TRANSFORM [must be last]
157.1532 +    */
157.1533 +#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
157.1534 +   if ((png_ptr->transformations & PNG_STRIP_ALPHA) &&
157.1535 +      !(png_ptr->transformations & PNG_COMPOSE))
157.1536 +   {
157.1537 +      /* Stripping the alpha channel happens immediately after the 'expand'
157.1538 +       * transformations, before all other transformation, so it cancels out
157.1539 +       * the alpha handling.  It has the side effect negating the effect of
157.1540 +       * PNG_EXPAND_tRNS too:
157.1541 +       */
157.1542 +      png_ptr->transformations &= ~(PNG_BACKGROUND_EXPAND | PNG_ENCODE_ALPHA |
157.1543 +         PNG_EXPAND_tRNS);
157.1544 +      png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA;
157.1545 +
157.1546 +      /* Kill the tRNS chunk itself too.  Prior to 1.5.4 this did not happen
157.1547 +       * so transparency information would remain just so long as it wasn't
157.1548 +       * expanded.  This produces unexpected API changes if the set of things
157.1549 +       * that do PNG_EXPAND_tRNS changes (perfectly possible given the
157.1550 +       * documentation - which says ask for what you want, accept what you
157.1551 +       * get.)  This makes the behavior consistent from 1.5.4:
157.1552 +       */
157.1553 +      png_ptr->num_trans = 0;
157.1554 +   }
157.1555 +#endif /* STRIP_ALPHA supported, no COMPOSE */
157.1556 +
157.1557 +#ifdef PNG_READ_ALPHA_MODE_SUPPORTED
157.1558 +   /* If the screen gamma is about 1.0 then the OPTIMIZE_ALPHA and ENCODE_ALPHA
157.1559 +    * settings will have no effect.
157.1560 +    */
157.1561 +   if (!png_gamma_significant(png_ptr->screen_gamma))
157.1562 +   {
157.1563 +      png_ptr->transformations &= ~PNG_ENCODE_ALPHA;
157.1564 +      png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA;
157.1565 +   }
157.1566  #endif
157.1567  
157.1568 -#if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED)
157.1569 -
157.1570 -#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
157.1571 -   /* Detect gray background and attempt to enable optimization
157.1572 -    * for gray --> RGB case */
157.1573 -   /* Note:  if PNG_BACKGROUND_EXPAND is set and color_type is either RGB or
157.1574 +#if defined(PNG_READ_EXPAND_SUPPORTED) && \
157.1575 +   defined(PNG_READ_BACKGROUND_SUPPORTED) && \
157.1576 +   defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
157.1577 +   /* Detect gray background and attempt to enable optimization for
157.1578 +    * gray --> RGB case.
157.1579 +    *
157.1580 +    * Note:  if PNG_BACKGROUND_EXPAND is set and color_type is either RGB or
157.1581      * RGB_ALPHA (in which case need_expand is superfluous anyway), the
157.1582      * background color might actually be gray yet not be flagged as such.
157.1583      * This is not a problem for the current code, which uses
157.1584      * PNG_BACKGROUND_IS_GRAY only to decide when to do the
157.1585      * png_do_gray_to_rgb() transformation.
157.1586 +    *
157.1587 +    * TODO: this code needs to be revised to avoid the complexity and
157.1588 +    * interdependencies.  The color type of the background should be recorded in
157.1589 +    * png_set_background, along with the bit depth, then the code has a record
157.1590 +    * of exactly what color space the background is currently in.
157.1591      */
157.1592 -   if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
157.1593 -       !(color_type & PNG_COLOR_MASK_COLOR))
157.1594 +   if (png_ptr->transformations & PNG_BACKGROUND_EXPAND)
157.1595     {
157.1596 -          png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
157.1597 -   } else if ((png_ptr->transformations & PNG_BACKGROUND) &&
157.1598 -              !(png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
157.1599 -              (png_ptr->transformations & PNG_GRAY_TO_RGB) &&
157.1600 -              png_ptr->background.red == png_ptr->background.green &&
157.1601 -              png_ptr->background.red == png_ptr->background.blue)
157.1602 +      /* PNG_BACKGROUND_EXPAND: the background is in the file color space, so if
157.1603 +       * the file was greyscale the background value is gray.
157.1604 +       */
157.1605 +      if (!(png_ptr->color_type & PNG_COLOR_MASK_COLOR))
157.1606 +         png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
157.1607 +   }
157.1608 +
157.1609 +   else if (png_ptr->transformations & PNG_COMPOSE)
157.1610     {
157.1611 -          png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
157.1612 -          png_ptr->background.gray = png_ptr->background.red;
157.1613 -   }
157.1614 -#endif
157.1615 -
157.1616 -   if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
157.1617 -       (png_ptr->transformations & PNG_EXPAND))
157.1618 -   {
157.1619 -      if (!(color_type & PNG_COLOR_MASK_COLOR))  /* i.e., GRAY or GRAY_ALPHA */
157.1620 +      /* PNG_COMPOSE: png_set_background was called with need_expand false,
157.1621 +       * so the color is in the color space of the output or png_set_alpha_mode
157.1622 +       * was called and the color is black.  Ignore RGB_TO_GRAY because that
157.1623 +       * happens before GRAY_TO_RGB.
157.1624 +       */
157.1625 +      if (png_ptr->transformations & PNG_GRAY_TO_RGB)
157.1626        {
157.1627 -         /* expand background and tRNS chunks */
157.1628 -         switch (png_ptr->bit_depth)
157.1629 +         if (png_ptr->background.red == png_ptr->background.green &&
157.1630 +             png_ptr->background.red == png_ptr->background.blue)
157.1631           {
157.1632 -            case 1:
157.1633 -               png_ptr->background.gray *= (png_uint_16)0xff;
157.1634 -               png_ptr->background.red = png_ptr->background.green
157.1635 -                 =  png_ptr->background.blue = png_ptr->background.gray;
157.1636 -               if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
157.1637 -               {
157.1638 -                 png_ptr->trans_values.gray *= (png_uint_16)0xff;
157.1639 -                 png_ptr->trans_values.red = png_ptr->trans_values.green
157.1640 -                   = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
157.1641 -               }
157.1642 -               break;
157.1643 -            case 2:
157.1644 -               png_ptr->background.gray *= (png_uint_16)0x55;
157.1645 -               png_ptr->background.red = png_ptr->background.green
157.1646 -                 = png_ptr->background.blue = png_ptr->background.gray;
157.1647 -               if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
157.1648 -               {
157.1649 -                 png_ptr->trans_values.gray *= (png_uint_16)0x55;
157.1650 -                 png_ptr->trans_values.red = png_ptr->trans_values.green
157.1651 -                   = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
157.1652 -               }
157.1653 -               break;
157.1654 -            case 4:
157.1655 -               png_ptr->background.gray *= (png_uint_16)0x11;
157.1656 -               png_ptr->background.red = png_ptr->background.green
157.1657 -                 = png_ptr->background.blue = png_ptr->background.gray;
157.1658 -               if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
157.1659 -               {
157.1660 -                 png_ptr->trans_values.gray *= (png_uint_16)0x11;
157.1661 -                 png_ptr->trans_values.red = png_ptr->trans_values.green
157.1662 -                   = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
157.1663 -               }
157.1664 -               break;
157.1665 -            case 8:
157.1666 -            case 16:
157.1667 -               png_ptr->background.red = png_ptr->background.green
157.1668 -                 = png_ptr->background.blue = png_ptr->background.gray;
157.1669 -               break;
157.1670 +            png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
157.1671 +            png_ptr->background.gray = png_ptr->background.red;
157.1672           }
157.1673        }
157.1674 -      else if (color_type == PNG_COLOR_TYPE_PALETTE)
157.1675 +   }
157.1676 +#endif /* PNG_READ_GRAY_TO_RGB_SUPPORTED (etc) */
157.1677 +
157.1678 +   /* For indexed PNG data (PNG_COLOR_TYPE_PALETTE) many of the transformations
157.1679 +    * can be performed directly on the palette, and some (such as rgb to gray)
157.1680 +    * can be optimized inside the palette.  This is particularly true of the
157.1681 +    * composite (background and alpha) stuff, which can be pretty much all done
157.1682 +    * in the palette even if the result is expanded to RGB or gray afterward.
157.1683 +    *
157.1684 +    * NOTE: this is Not Yet Implemented, the code behaves as in 1.5.1 and
157.1685 +    * earlier and the palette stuff is actually handled on the first row.  This
157.1686 +    * leads to the reported bug that the palette returned by png_get_PLTE is not
157.1687 +    * updated.
157.1688 +    */
157.1689 +   if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
157.1690 +      png_init_palette_transformations(png_ptr);
157.1691 +
157.1692 +   else
157.1693 +      png_init_rgb_transformations(png_ptr);
157.1694 +
157.1695 +#if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
157.1696 +   defined(PNG_READ_EXPAND_16_SUPPORTED)
157.1697 +   if ((png_ptr->transformations & PNG_EXPAND_16) &&
157.1698 +      (png_ptr->transformations & PNG_COMPOSE) &&
157.1699 +      !(png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
157.1700 +      png_ptr->bit_depth != 16)
157.1701 +   {
157.1702 +      /* TODO: fix this.  Because the expand_16 operation is after the compose
157.1703 +       * handling the background color must be 8, not 16, bits deep, but the
157.1704 +       * application will supply a 16-bit value so reduce it here.
157.1705 +       *
157.1706 +       * The PNG_BACKGROUND_EXPAND code above does not expand to 16 bits at
157.1707 +       * present, so that case is ok (until do_expand_16 is moved.)
157.1708 +       *
157.1709 +       * NOTE: this discards the low 16 bits of the user supplied background
157.1710 +       * color, but until expand_16 works properly there is no choice!
157.1711 +       */
157.1712 +#     define CHOP(x) (x)=((png_uint_16)(((png_uint_32)(x)*255+32895) >> 16))
157.1713 +      CHOP(png_ptr->background.red);
157.1714 +      CHOP(png_ptr->background.green);
157.1715 +      CHOP(png_ptr->background.blue);
157.1716 +      CHOP(png_ptr->background.gray);
157.1717 +#     undef CHOP
157.1718 +   }
157.1719 +#endif /* PNG_READ_BACKGROUND_SUPPORTED && PNG_READ_EXPAND_16_SUPPORTED */
157.1720 +
157.1721 +   /* NOTE: below 'PNG_READ_ALPHA_MODE_SUPPORTED' is presumed to also enable the
157.1722 +    * background support (see the comments in scripts/pnglibconf.dfa), this
157.1723 +    * allows pre-multiplication of the alpha channel to be implemented as
157.1724 +    * compositing on black.  This is probably sub-optimal and has been done in
157.1725 +    * 1.5.4 betas simply to enable external critique and testing (i.e. to
157.1726 +    * implement the new API quickly, without lots of internal changes.)
157.1727 +    */
157.1728 +
157.1729 +#ifdef PNG_READ_GAMMA_SUPPORTED
157.1730 +#  ifdef PNG_READ_BACKGROUND_SUPPORTED
157.1731 +      /* Includes ALPHA_MODE */
157.1732 +      png_ptr->background_1 = png_ptr->background;
157.1733 +#  endif
157.1734 +
157.1735 +   /* This needs to change - in the palette image case a whole set of tables are
157.1736 +    * built when it would be quicker to just calculate the correct value for
157.1737 +    * each palette entry directly.  Also, the test is too tricky - why check
157.1738 +    * PNG_RGB_TO_GRAY if PNG_GAMMA is not set?  The answer seems to be that
157.1739 +    * PNG_GAMMA is cancelled even if the gamma is known?  The test excludes the
157.1740 +    * PNG_COMPOSE case, so apparently if there is no *overall* gamma correction
157.1741 +    * the gamma tables will not be built even if composition is required on a
157.1742 +    * gamma encoded value.
157.1743 +    *
157.1744 +    * In 1.5.4 this is addressed below by an additional check on the individual
157.1745 +    * file gamma - if it is not 1.0 both RGB_TO_GRAY and COMPOSE need the
157.1746 +    * tables.
157.1747 +    */
157.1748 +   if ((png_ptr->transformations & PNG_GAMMA)
157.1749 +      || ((png_ptr->transformations & PNG_RGB_TO_GRAY)
157.1750 +         && (png_gamma_significant(png_ptr->gamma) ||
157.1751 +            png_gamma_significant(png_ptr->screen_gamma)))
157.1752 +      || ((png_ptr->transformations & PNG_COMPOSE)
157.1753 +         && (png_gamma_significant(png_ptr->gamma)
157.1754 +            || png_gamma_significant(png_ptr->screen_gamma)
157.1755 +#  ifdef PNG_READ_BACKGROUND_SUPPORTED
157.1756 +            || (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_UNIQUE
157.1757 +               && png_gamma_significant(png_ptr->background_gamma))
157.1758 +#  endif
157.1759 +      )) || ((png_ptr->transformations & PNG_ENCODE_ALPHA)
157.1760 +         && png_gamma_significant(png_ptr->screen_gamma))
157.1761 +      )
157.1762 +   {
157.1763 +      png_build_gamma_table(png_ptr, png_ptr->bit_depth);
157.1764 +
157.1765 +#ifdef PNG_READ_BACKGROUND_SUPPORTED
157.1766 +      if (png_ptr->transformations & PNG_COMPOSE)
157.1767        {
157.1768 -         png_ptr->background.red   =
157.1769 -            png_ptr->palette[png_ptr->background.index].red;
157.1770 -         png_ptr->background.green =
157.1771 -            png_ptr->palette[png_ptr->background.index].green;
157.1772 -         png_ptr->background.blue  =
157.1773 -            png_ptr->palette[png_ptr->background.index].blue;
157.1774 -
157.1775 -#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
157.1776 -        if (png_ptr->transformations & PNG_INVERT_ALPHA)
157.1777 -        {
157.1778 -#if defined(PNG_READ_EXPAND_SUPPORTED)
157.1779 -           if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
157.1780 -#endif
157.1781 -           {
157.1782 -           /* invert the alpha channel (in tRNS) unless the pixels are
157.1783 -              going to be expanded, in which case leave it for later */
157.1784 -              int i,istop;
157.1785 -              istop=(int)png_ptr->num_trans;
157.1786 -              for (i=0; i<istop; i++)
157.1787 -                 png_ptr->trans[i] = (png_byte)(255 - png_ptr->trans[i]);
157.1788 -           }
157.1789 -        }
157.1790 -#endif
157.1791 -
157.1792 -      }
157.1793 -   }
157.1794 -#endif
157.1795 -
157.1796 -#if defined(PNG_READ_BACKGROUND_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
157.1797 -   png_ptr->background_1 = png_ptr->background;
157.1798 -#endif
157.1799 -#if defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
157.1800 -
157.1801 -   if ((color_type == PNG_COLOR_TYPE_PALETTE && png_ptr->num_trans != 0)
157.1802 -       && (fabs(png_ptr->screen_gamma * png_ptr->gamma - 1.0)
157.1803 -         < PNG_GAMMA_THRESHOLD))
157.1804 -   {
157.1805 -    int i,k;
157.1806 -    k=0;
157.1807 -    for (i=0; i<png_ptr->num_trans; i++)
157.1808 -    {
157.1809 -      if (png_ptr->trans[i] != 0 && png_ptr->trans[i] != 0xff)
157.1810 -        k=1; /* partial transparency is present */
157.1811 -    }
157.1812 -    if (k == 0)
157.1813 -      png_ptr->transformations &= (~PNG_GAMMA);
157.1814 -   }
157.1815 -
157.1816 -   if ((png_ptr->transformations & (PNG_GAMMA | PNG_RGB_TO_GRAY)) &&
157.1817 -        png_ptr->gamma != 0.0)
157.1818 -   {
157.1819 -      png_build_gamma_table(png_ptr);
157.1820 -#if defined(PNG_READ_BACKGROUND_SUPPORTED)
157.1821 -      if (png_ptr->transformations & PNG_BACKGROUND)
157.1822 -      {
157.1823 -         if (color_type == PNG_COLOR_TYPE_PALETTE)
157.1824 +         if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
157.1825           {
157.1826 -           /* could skip if no transparency and
157.1827 -           */
157.1828 +            /* We don't get to here unless there is a tRNS chunk with non-opaque
157.1829 +             * entries - see the checking code at the start of this function.
157.1830 +             */
157.1831              png_color back, back_1;
157.1832              png_colorp palette = png_ptr->palette;
157.1833              int num_palette = png_ptr->num_palette;
157.1834              int i;
157.1835              if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE)
157.1836              {
157.1837 +
157.1838                 back.red = png_ptr->gamma_table[png_ptr->background.red];
157.1839                 back.green = png_ptr->gamma_table[png_ptr->background.green];
157.1840                 back.blue = png_ptr->gamma_table[png_ptr->background.blue];
157.1841 @@ -900,73 +1566,90 @@
157.1842              }
157.1843              else
157.1844              {
157.1845 -               double g, gs;
157.1846 +               png_fixed_point g, gs;
157.1847  
157.1848                 switch (png_ptr->background_gamma_type)
157.1849                 {
157.1850                    case PNG_BACKGROUND_GAMMA_SCREEN:
157.1851                       g = (png_ptr->screen_gamma);
157.1852 -                     gs = 1.0;
157.1853 +                     gs = PNG_FP_1;
157.1854                       break;
157.1855 +
157.1856                    case PNG_BACKGROUND_GAMMA_FILE:
157.1857 -                     g = 1.0 / (png_ptr->gamma);
157.1858 -                     gs = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
157.1859 +                     g = png_reciprocal(png_ptr->gamma);
157.1860 +                     gs = png_reciprocal2(png_ptr->gamma,
157.1861 +                        png_ptr->screen_gamma);
157.1862                       break;
157.1863 +
157.1864                    case PNG_BACKGROUND_GAMMA_UNIQUE:
157.1865 -                     g = 1.0 / (png_ptr->background_gamma);
157.1866 -                     gs = 1.0 / (png_ptr->background_gamma *
157.1867 -                                 png_ptr->screen_gamma);
157.1868 +                     g = png_reciprocal(png_ptr->background_gamma);
157.1869 +                     gs = png_reciprocal2(png_ptr->background_gamma,
157.1870 +                        png_ptr->screen_gamma);
157.1871                       break;
157.1872                    default:
157.1873 -                     g = 1.0;    /* back_1 */
157.1874 -                     gs = 1.0;   /* back */
157.1875 +                     g = PNG_FP_1;    /* back_1 */
157.1876 +                     gs = PNG_FP_1;   /* back */
157.1877 +                     break;
157.1878                 }
157.1879  
157.1880 -               if ( fabs(gs - 1.0) < PNG_GAMMA_THRESHOLD)
157.1881 +               if (png_gamma_significant(gs))
157.1882 +               {
157.1883 +                  back.red = png_gamma_8bit_correct(png_ptr->background.red,
157.1884 +                      gs);
157.1885 +                  back.green = png_gamma_8bit_correct(png_ptr->background.green,
157.1886 +                      gs);
157.1887 +                  back.blue = png_gamma_8bit_correct(png_ptr->background.blue,
157.1888 +                      gs);
157.1889 +               }
157.1890 +
157.1891 +               else
157.1892                 {
157.1893                    back.red   = (png_byte)png_ptr->background.red;
157.1894                    back.green = (png_byte)png_ptr->background.green;
157.1895                    back.blue  = (png_byte)png_ptr->background.blue;
157.1896                 }
157.1897 +
157.1898 +               if (png_gamma_significant(g))
157.1899 +               {
157.1900 +                  back_1.red = png_gamma_8bit_correct(png_ptr->background.red,
157.1901 +                     g);
157.1902 +                  back_1.green = png_gamma_8bit_correct(
157.1903 +                     png_ptr->background.green, g);
157.1904 +                  back_1.blue = png_gamma_8bit_correct(png_ptr->background.blue,
157.1905 +                     g);
157.1906 +               }
157.1907 +
157.1908                 else
157.1909                 {
157.1910 -                  back.red = (png_byte)(pow(
157.1911 -                     (double)png_ptr->background.red/255, gs) * 255.0 + .5);
157.1912 -                  back.green = (png_byte)(pow(
157.1913 -                     (double)png_ptr->background.green/255, gs) * 255.0 + .5);
157.1914 -                  back.blue = (png_byte)(pow(
157.1915 -                     (double)png_ptr->background.blue/255, gs) * 255.0 + .5);
157.1916 +                  back_1.red   = (png_byte)png_ptr->background.red;
157.1917 +                  back_1.green = (png_byte)png_ptr->background.green;
157.1918 +                  back_1.blue  = (png_byte)png_ptr->background.blue;
157.1919                 }
157.1920 -
157.1921 -               back_1.red = (png_byte)(pow(
157.1922 -                  (double)png_ptr->background.red/255, g) * 255.0 + .5);
157.1923 -               back_1.green = (png_byte)(pow(
157.1924 -                  (double)png_ptr->background.green/255, g) * 255.0 + .5);
157.1925 -               back_1.blue = (png_byte)(pow(
157.1926 -                  (double)png_ptr->background.blue/255, g) * 255.0 + .5);
157.1927              }
157.1928 +
157.1929              for (i = 0; i < num_palette; i++)
157.1930              {
157.1931 -               if (i < (int)png_ptr->num_trans && png_ptr->trans[i] != 0xff)
157.1932 +               if (i < (int)png_ptr->num_trans &&
157.1933 +                   png_ptr->trans_alpha[i] != 0xff)
157.1934                 {
157.1935 -                  if (png_ptr->trans[i] == 0)
157.1936 +                  if (png_ptr->trans_alpha[i] == 0)
157.1937                    {
157.1938                       palette[i] = back;
157.1939                    }
157.1940 -                  else /* if (png_ptr->trans[i] != 0xff) */
157.1941 +                  else /* if (png_ptr->trans_alpha[i] != 0xff) */
157.1942                    {
157.1943                       png_byte v, w;
157.1944  
157.1945                       v = png_ptr->gamma_to_1[palette[i].red];
157.1946 -                     png_composite(w, v, png_ptr->trans[i], back_1.red);
157.1947 +                     png_composite(w, v, png_ptr->trans_alpha[i], back_1.red);
157.1948                       palette[i].red = png_ptr->gamma_from_1[w];
157.1949  
157.1950                       v = png_ptr->gamma_to_1[palette[i].green];
157.1951 -                     png_composite(w, v, png_ptr->trans[i], back_1.green);
157.1952 +                     png_composite(w, v, png_ptr->trans_alpha[i], back_1.green);
157.1953                       palette[i].green = png_ptr->gamma_from_1[w];
157.1954  
157.1955                       v = png_ptr->gamma_to_1[palette[i].blue];
157.1956 -                     png_composite(w, v, png_ptr->trans[i], back_1.blue);
157.1957 +                     png_composite(w, v, png_ptr->trans_alpha[i], back_1.blue);
157.1958                       palette[i].blue = png_ptr->gamma_from_1[w];
157.1959                    }
157.1960                 }
157.1961 @@ -977,90 +1660,118 @@
157.1962                    palette[i].blue = png_ptr->gamma_table[palette[i].blue];
157.1963                 }
157.1964              }
157.1965 -         }
157.1966 +
157.1967 +            /* Prevent the transformations being done again.
157.1968 +             *
157.1969 +             * NOTE: this is highly dubious; it zaps the transformations in
157.1970 +             * place.  This seems inconsistent with the general treatment of the
157.1971 +             * transformations elsewhere.
157.1972 +             */
157.1973 +            png_ptr->transformations &= ~(PNG_COMPOSE | PNG_GAMMA);
157.1974 +         } /* color_type == PNG_COLOR_TYPE_PALETTE */
157.1975 +
157.1976           /* if (png_ptr->background_gamma_type!=PNG_BACKGROUND_GAMMA_UNKNOWN) */
157.1977 -         else
157.1978 -         /* color_type != PNG_COLOR_TYPE_PALETTE */
157.1979 +         else /* color_type != PNG_COLOR_TYPE_PALETTE */
157.1980           {
157.1981 -            double m = (double)(((png_uint_32)1 << png_ptr->bit_depth) - 1);
157.1982 -            double g = 1.0;
157.1983 -            double gs = 1.0;
157.1984 +            png_fixed_point g = PNG_FP_1;
157.1985 +            png_fixed_point gs = PNG_FP_1;
157.1986  
157.1987              switch (png_ptr->background_gamma_type)
157.1988              {
157.1989                 case PNG_BACKGROUND_GAMMA_SCREEN:
157.1990 -                  g = (png_ptr->screen_gamma);
157.1991 -                  gs = 1.0;
157.1992 +                  g = png_ptr->screen_gamma;
157.1993 +                  /* gs = PNG_FP_1; */
157.1994                    break;
157.1995 +
157.1996                 case PNG_BACKGROUND_GAMMA_FILE:
157.1997 -                  g = 1.0 / (png_ptr->gamma);
157.1998 -                  gs = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
157.1999 +                  g = png_reciprocal(png_ptr->gamma);
157.2000 +                  gs = png_reciprocal2(png_ptr->gamma, png_ptr->screen_gamma);
157.2001                    break;
157.2002 +
157.2003                 case PNG_BACKGROUND_GAMMA_UNIQUE:
157.2004 -                  g = 1.0 / (png_ptr->background_gamma);
157.2005 -                  gs = 1.0 / (png_ptr->background_gamma *
157.2006 -                     png_ptr->screen_gamma);
157.2007 +                  g = png_reciprocal(png_ptr->background_gamma);
157.2008 +                  gs = png_reciprocal2(png_ptr->background_gamma,
157.2009 +                      png_ptr->screen_gamma);
157.2010                    break;
157.2011 +
157.2012 +               default:
157.2013 +                  png_error(png_ptr, "invalid background gamma type");
157.2014              }
157.2015  
157.2016 -            png_ptr->background_1.gray = (png_uint_16)(pow(
157.2017 -               (double)png_ptr->background.gray / m, g) * m + .5);
157.2018 -            png_ptr->background.gray = (png_uint_16)(pow(
157.2019 -               (double)png_ptr->background.gray / m, gs) * m + .5);
157.2020 +            png_ptr->background_1.gray = png_gamma_correct(png_ptr,
157.2021 +                png_ptr->background.gray, g);
157.2022 +
157.2023 +            png_ptr->background.gray = png_gamma_correct(png_ptr,
157.2024 +                png_ptr->background.gray, gs);
157.2025  
157.2026              if ((png_ptr->background.red != png_ptr->background.green) ||
157.2027                  (png_ptr->background.red != png_ptr->background.blue) ||
157.2028                  (png_ptr->background.red != png_ptr->background.gray))
157.2029              {
157.2030                 /* RGB or RGBA with color background */
157.2031 -               png_ptr->background_1.red = (png_uint_16)(pow(
157.2032 -                  (double)png_ptr->background.red / m, g) * m + .5);
157.2033 -               png_ptr->background_1.green = (png_uint_16)(pow(
157.2034 -                  (double)png_ptr->background.green / m, g) * m + .5);
157.2035 -               png_ptr->background_1.blue = (png_uint_16)(pow(
157.2036 -                  (double)png_ptr->background.blue / m, g) * m + .5);
157.2037 -               png_ptr->background.red = (png_uint_16)(pow(
157.2038 -                  (double)png_ptr->background.red / m, gs) * m + .5);
157.2039 -               png_ptr->background.green = (png_uint_16)(pow(
157.2040 -                  (double)png_ptr->background.green / m, gs) * m + .5);
157.2041 -               png_ptr->background.blue = (png_uint_16)(pow(
157.2042 -                  (double)png_ptr->background.blue / m, gs) * m + .5);
157.2043 +               png_ptr->background_1.red = png_gamma_correct(png_ptr,
157.2044 +                   png_ptr->background.red, g);
157.2045 +
157.2046 +               png_ptr->background_1.green = png_gamma_correct(png_ptr,
157.2047 +                   png_ptr->background.green, g);
157.2048 +
157.2049 +               png_ptr->background_1.blue = png_gamma_correct(png_ptr,
157.2050 +                   png_ptr->background.blue, g);
157.2051 +
157.2052 +               png_ptr->background.red = png_gamma_correct(png_ptr,
157.2053 +                   png_ptr->background.red, gs);
157.2054 +
157.2055 +               png_ptr->background.green = png_gamma_correct(png_ptr,
157.2056 +                   png_ptr->background.green, gs);
157.2057 +
157.2058 +               png_ptr->background.blue = png_gamma_correct(png_ptr,
157.2059 +                   png_ptr->background.blue, gs);
157.2060              }
157.2061 +
157.2062              else
157.2063              {
157.2064                 /* GRAY, GRAY ALPHA, RGB, or RGBA with gray background */
157.2065                 png_ptr->background_1.red = png_ptr->background_1.green
157.2066 -                 = png_ptr->background_1.blue = png_ptr->background_1.gray;
157.2067 +                   = png_ptr->background_1.blue = png_ptr->background_1.gray;
157.2068 +
157.2069                 png_ptr->background.red = png_ptr->background.green
157.2070 -                 = png_ptr->background.blue = png_ptr->background.gray;
157.2071 +                   = png_ptr->background.blue = png_ptr->background.gray;
157.2072              }
157.2073 -         }
157.2074 -      }
157.2075 +         } /* color_type != PNG_COLOR_TYPE_PALETTE */
157.2076 +      }/* png_ptr->transformations & PNG_BACKGROUND */
157.2077 +
157.2078        else
157.2079 -      /* transformation does not include PNG_BACKGROUND */
157.2080 +      /* Transformation does not include PNG_BACKGROUND */
157.2081  #endif /* PNG_READ_BACKGROUND_SUPPORTED */
157.2082 -      if (color_type == PNG_COLOR_TYPE_PALETTE)
157.2083 +      if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
157.2084        {
157.2085           png_colorp palette = png_ptr->palette;
157.2086           int num_palette = png_ptr->num_palette;
157.2087           int i;
157.2088  
157.2089 +         /*NOTE: there are other transformations that should probably be in here
157.2090 +          * too.
157.2091 +          */
157.2092           for (i = 0; i < num_palette; i++)
157.2093           {
157.2094              palette[i].red = png_ptr->gamma_table[palette[i].red];
157.2095              palette[i].green = png_ptr->gamma_table[palette[i].green];
157.2096              palette[i].blue = png_ptr->gamma_table[palette[i].blue];
157.2097           }
157.2098 -      }
157.2099 +
157.2100 +         /* Done the gamma correction. */
157.2101 +         png_ptr->transformations &= ~PNG_GAMMA;
157.2102 +      } /* color_type == PALETTE && !PNG_BACKGROUND transformation */
157.2103     }
157.2104 -#if defined(PNG_READ_BACKGROUND_SUPPORTED)
157.2105 +#ifdef PNG_READ_BACKGROUND_SUPPORTED
157.2106     else
157.2107  #endif
157.2108 -#endif /* PNG_READ_GAMMA_SUPPORTED && PNG_FLOATING_POINT_SUPPORTED */
157.2109 -#if defined(PNG_READ_BACKGROUND_SUPPORTED)
157.2110 -   /* No GAMMA transformation */
157.2111 -   if ((png_ptr->transformations & PNG_BACKGROUND) &&
157.2112 -       (color_type == PNG_COLOR_TYPE_PALETTE))
157.2113 +#endif /* PNG_READ_GAMMA_SUPPORTED */
157.2114 +
157.2115 +#ifdef PNG_READ_BACKGROUND_SUPPORTED
157.2116 +   /* No GAMMA transformation (see the hanging else 4 lines above) */
157.2117 +   if ((png_ptr->transformations & PNG_COMPOSE) &&
157.2118 +       (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE))
157.2119     {
157.2120        int i;
157.2121        int istop = (int)png_ptr->num_trans;
157.2122 @@ -1073,27 +1784,32 @@
157.2123  
157.2124        for (i = 0; i < istop; i++)
157.2125        {
157.2126 -         if (png_ptr->trans[i] == 0)
157.2127 +         if (png_ptr->trans_alpha[i] == 0)
157.2128           {
157.2129              palette[i] = back;
157.2130           }
157.2131 -         else if (png_ptr->trans[i] != 0xff)
157.2132 +
157.2133 +         else if (png_ptr->trans_alpha[i] != 0xff)
157.2134           {
157.2135              /* The png_composite() macro is defined in png.h */
157.2136              png_composite(palette[i].red, palette[i].red,
157.2137 -               png_ptr->trans[i], back.red);
157.2138 +                png_ptr->trans_alpha[i], back.red);
157.2139 +
157.2140              png_composite(palette[i].green, palette[i].green,
157.2141 -               png_ptr->trans[i], back.green);
157.2142 +                png_ptr->trans_alpha[i], back.green);
157.2143 +
157.2144              png_composite(palette[i].blue, palette[i].blue,
157.2145 -               png_ptr->trans[i], back.blue);
157.2146 +                png_ptr->trans_alpha[i], back.blue);
157.2147           }
157.2148        }
157.2149 +
157.2150 +      png_ptr->transformations &= ~PNG_COMPOSE;
157.2151     }
157.2152  #endif /* PNG_READ_BACKGROUND_SUPPORTED */
157.2153  
157.2154 -#if defined(PNG_READ_SHIFT_SUPPORTED)
157.2155 +#ifdef PNG_READ_SHIFT_SUPPORTED
157.2156     if ((png_ptr->transformations & PNG_SHIFT) &&
157.2157 -      (color_type == PNG_COLOR_TYPE_PALETTE))
157.2158 +       (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE))
157.2159     {
157.2160        png_uint_16 i;
157.2161        png_uint_16 istop = png_ptr->num_palette;
157.2162 @@ -1103,10 +1819,13 @@
157.2163  
157.2164        if (sr < 0 || sr > 8)
157.2165           sr = 0;
157.2166 +
157.2167        if (sg < 0 || sg > 8)
157.2168           sg = 0;
157.2169 +
157.2170        if (sb < 0 || sb > 8)
157.2171           sb = 0;
157.2172 +
157.2173        for (i = 0; i < istop; i++)
157.2174        {
157.2175           png_ptr->palette[i].red >>= sr;
157.2176 @@ -1115,12 +1834,6 @@
157.2177        }
157.2178     }
157.2179  #endif  /* PNG_READ_SHIFT_SUPPORTED */
157.2180 - }
157.2181 -#if !defined(PNG_READ_GAMMA_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED) \
157.2182 - && !defined(PNG_READ_BACKGROUND_SUPPORTED)
157.2183 -   if(png_ptr)
157.2184 -      return;
157.2185 -#endif
157.2186  }
157.2187  
157.2188  /* Modify the info structure to reflect the transformations.  The
157.2189 @@ -1130,16 +1843,23 @@
157.2190  void /* PRIVATE */
157.2191  png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
157.2192  {
157.2193 -   png_debug(1, "in png_read_transform_info\n");
157.2194 -#if defined(PNG_READ_EXPAND_SUPPORTED)
157.2195 +   png_debug(1, "in png_read_transform_info");
157.2196 +
157.2197 +#ifdef PNG_READ_EXPAND_SUPPORTED
157.2198     if (png_ptr->transformations & PNG_EXPAND)
157.2199     {
157.2200        if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
157.2201        {
157.2202 -         if (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND_tRNS))
157.2203 +         /* This check must match what actually happens in
157.2204 +          * png_do_expand_palette; if it ever checks the tRNS chunk to see if
157.2205 +          * it is all opaque we must do the same (at present it does not.)
157.2206 +          */
157.2207 +         if (png_ptr->num_trans > 0)
157.2208              info_ptr->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
157.2209 +
157.2210           else
157.2211              info_ptr->color_type = PNG_COLOR_TYPE_RGB;
157.2212 +
157.2213           info_ptr->bit_depth = 8;
157.2214           info_ptr->num_trans = 0;
157.2215        }
157.2216 @@ -1148,118 +1868,167 @@
157.2217           if (png_ptr->num_trans)
157.2218           {
157.2219              if (png_ptr->transformations & PNG_EXPAND_tRNS)
157.2220 -              info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
157.2221 -            else
157.2222 -              info_ptr->color_type |= PNG_COLOR_MASK_COLOR;
157.2223 +               info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
157.2224           }
157.2225           if (info_ptr->bit_depth < 8)
157.2226              info_ptr->bit_depth = 8;
157.2227 +
157.2228           info_ptr->num_trans = 0;
157.2229        }
157.2230     }
157.2231  #endif
157.2232  
157.2233 -#if defined(PNG_READ_BACKGROUND_SUPPORTED)
157.2234 -   if (png_ptr->transformations & PNG_BACKGROUND)
157.2235 +#if defined(PNG_READ_BACKGROUND_SUPPORTED) ||\
157.2236 +   defined(PNG_READ_ALPHA_MODE_SUPPORTED)
157.2237 +   /* The following is almost certainly wrong unless the background value is in
157.2238 +    * the screen space!
157.2239 +    */
157.2240 +   if (png_ptr->transformations & PNG_COMPOSE)
157.2241 +      info_ptr->background = png_ptr->background;
157.2242 +#endif
157.2243 +
157.2244 +#ifdef PNG_READ_GAMMA_SUPPORTED
157.2245 +   /* The following used to be conditional on PNG_GAMMA (prior to 1.5.4),
157.2246 +    * however it seems that the code in png_init_read_transformations, which has
157.2247 +    * been called before this from png_read_update_info->png_read_start_row
157.2248 +    * sometimes does the gamma transform and cancels the flag.
157.2249 +    */
157.2250 +   info_ptr->gamma = png_ptr->gamma;
157.2251 +#endif
157.2252 +
157.2253 +   if (info_ptr->bit_depth == 16)
157.2254     {
157.2255 -      info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA;
157.2256 -      info_ptr->num_trans = 0;
157.2257 -      info_ptr->background = png_ptr->background;
157.2258 +#  ifdef PNG_READ_16BIT_SUPPORTED
157.2259 +#     ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
157.2260 +         if (png_ptr->transformations & PNG_SCALE_16_TO_8)
157.2261 +            info_ptr->bit_depth = 8;
157.2262 +#     endif
157.2263 +
157.2264 +#     ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED
157.2265 +         if (png_ptr->transformations & PNG_16_TO_8)
157.2266 +            info_ptr->bit_depth = 8;
157.2267 +#     endif
157.2268 +
157.2269 +#  else
157.2270 +      /* No 16 bit support: force chopping 16-bit input down to 8, in this case
157.2271 +       * the app program can chose if both APIs are available by setting the
157.2272 +       * correct scaling to use.
157.2273 +       */
157.2274 +#     ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED
157.2275 +         /* For compatibility with previous versions use the strip method by
157.2276 +          * default.  This code works because if PNG_SCALE_16_TO_8 is already
157.2277 +          * set the code below will do that in preference to the chop.
157.2278 +          */
157.2279 +         png_ptr->transformations |= PNG_16_TO_8;
157.2280 +         info_ptr->bit_depth = 8;
157.2281 +#     else
157.2282 +
157.2283 +#        if PNG_READ_SCALE_16_TO_8_SUPPORTED
157.2284 +            png_ptr->transformations |= PNG_SCALE_16_TO_8;
157.2285 +            info_ptr->bit_depth = 8;
157.2286 +#        else
157.2287 +
157.2288 +            CONFIGURATION ERROR: you must enable at least one 16 to 8 method
157.2289 +#        endif
157.2290 +#    endif
157.2291 +#endif /* !READ_16BIT_SUPPORTED */
157.2292     }
157.2293 -#endif
157.2294 -
157.2295 -#if defined(PNG_READ_GAMMA_SUPPORTED)
157.2296 -   if (png_ptr->transformations & PNG_GAMMA)
157.2297 -   {
157.2298 -#ifdef PNG_FLOATING_POINT_SUPPORTED
157.2299 -      info_ptr->gamma = png_ptr->gamma;
157.2300 -#endif
157.2301 -#ifdef PNG_FIXED_POINT_SUPPORTED
157.2302 -      info_ptr->int_gamma = png_ptr->int_gamma;
157.2303 -#endif
157.2304 -   }
157.2305 -#endif
157.2306 -
157.2307 -#if defined(PNG_READ_16_TO_8_SUPPORTED)
157.2308 -   if ((png_ptr->transformations & PNG_16_TO_8) && (info_ptr->bit_depth == 16))
157.2309 -      info_ptr->bit_depth = 8;
157.2310 -#endif
157.2311 -
157.2312 -#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
157.2313 +
157.2314 +#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
157.2315     if (png_ptr->transformations & PNG_GRAY_TO_RGB)
157.2316        info_ptr->color_type |= PNG_COLOR_MASK_COLOR;
157.2317  #endif
157.2318  
157.2319 -#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
157.2320 +#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
157.2321     if (png_ptr->transformations & PNG_RGB_TO_GRAY)
157.2322        info_ptr->color_type &= ~PNG_COLOR_MASK_COLOR;
157.2323  #endif
157.2324  
157.2325 -#if defined(PNG_READ_DITHER_SUPPORTED)
157.2326 -   if (png_ptr->transformations & PNG_DITHER)
157.2327 +#ifdef PNG_READ_QUANTIZE_SUPPORTED
157.2328 +   if (png_ptr->transformations & PNG_QUANTIZE)
157.2329     {
157.2330        if (((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||
157.2331 -         (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)) &&
157.2332 -         png_ptr->palette_lookup && info_ptr->bit_depth == 8)
157.2333 +          (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)) &&
157.2334 +          png_ptr->palette_lookup && info_ptr->bit_depth == 8)
157.2335        {
157.2336           info_ptr->color_type = PNG_COLOR_TYPE_PALETTE;
157.2337        }
157.2338     }
157.2339  #endif
157.2340  
157.2341 -#if defined(PNG_READ_PACK_SUPPORTED)
157.2342 +#ifdef PNG_READ_EXPAND_16_SUPPORTED
157.2343 +   if (png_ptr->transformations & PNG_EXPAND_16 && info_ptr->bit_depth == 8 &&
157.2344 +      info_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
157.2345 +   {
157.2346 +      info_ptr->bit_depth = 16;
157.2347 +   }
157.2348 +#endif
157.2349 +
157.2350 +#ifdef PNG_READ_PACK_SUPPORTED
157.2351     if ((png_ptr->transformations & PNG_PACK) && (info_ptr->bit_depth < 8))
157.2352        info_ptr->bit_depth = 8;
157.2353  #endif
157.2354  
157.2355     if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
157.2356        info_ptr->channels = 1;
157.2357 +
157.2358     else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
157.2359        info_ptr->channels = 3;
157.2360 +
157.2361     else
157.2362        info_ptr->channels = 1;
157.2363  
157.2364 -#if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
157.2365 -   if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA)
157.2366 +#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
157.2367 +   if (png_ptr->transformations & PNG_STRIP_ALPHA)
157.2368 +   {
157.2369        info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA;
157.2370 +      info_ptr->num_trans = 0;
157.2371 +   }
157.2372  #endif
157.2373  
157.2374     if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
157.2375        info_ptr->channels++;
157.2376  
157.2377 -#if defined(PNG_READ_FILLER_SUPPORTED)
157.2378 +#ifdef PNG_READ_FILLER_SUPPORTED
157.2379     /* STRIP_ALPHA and FILLER allowed:  MASK_ALPHA bit stripped above */
157.2380     if ((png_ptr->transformations & PNG_FILLER) &&
157.2381         ((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||
157.2382         (info_ptr->color_type == PNG_COLOR_TYPE_GRAY)))
157.2383     {
157.2384        info_ptr->channels++;
157.2385 -      /* if adding a true alpha channel not just filler */
157.2386 -#if !defined(PNG_1_0_X)
157.2387 +      /* If adding a true alpha channel not just filler */
157.2388        if (png_ptr->transformations & PNG_ADD_ALPHA)
157.2389 -        info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
157.2390 -#endif
157.2391 +         info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
157.2392     }
157.2393  #endif
157.2394  
157.2395  #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) && \
157.2396  defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
157.2397 -   if(png_ptr->transformations & PNG_USER_TRANSFORM)
157.2398 -     {
157.2399 -       if(info_ptr->bit_depth < png_ptr->user_transform_depth)
157.2400 +   if (png_ptr->transformations & PNG_USER_TRANSFORM)
157.2401 +   {
157.2402 +      if (info_ptr->bit_depth < png_ptr->user_transform_depth)
157.2403           info_ptr->bit_depth = png_ptr->user_transform_depth;
157.2404 -       if(info_ptr->channels < png_ptr->user_transform_channels)
157.2405 +
157.2406 +      if (info_ptr->channels < png_ptr->user_transform_channels)
157.2407           info_ptr->channels = png_ptr->user_transform_channels;
157.2408 -     }
157.2409 +   }
157.2410  #endif
157.2411  
157.2412     info_ptr->pixel_depth = (png_byte)(info_ptr->channels *
157.2413 -      info_ptr->bit_depth);
157.2414 -
157.2415 -   info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,info_ptr->width);
157.2416 -
157.2417 -#if !defined(PNG_READ_EXPAND_SUPPORTED)
157.2418 -   if(png_ptr)
157.2419 +       info_ptr->bit_depth);
157.2420 +
157.2421 +   info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, info_ptr->width);
157.2422 +
157.2423 +   /* Adding in 1.5.4: cache the above value in png_struct so that we can later
157.2424 +    * check in png_rowbytes that the user buffer won't get overwritten.  Note
157.2425 +    * that the field is not always set - if png_read_update_info isn't called
157.2426 +    * the application has to either not do any transforms or get the calculation
157.2427 +    * right itself.
157.2428 +    */
157.2429 +   png_ptr->info_rowbytes = info_ptr->rowbytes;
157.2430 +
157.2431 +#ifndef PNG_READ_EXPAND_SUPPORTED
157.2432 +   if (png_ptr)
157.2433        return;
157.2434  #endif
157.2435  }
157.2436 @@ -1271,230 +2040,280 @@
157.2437  void /* PRIVATE */
157.2438  png_do_read_transformations(png_structp png_ptr)
157.2439  {
157.2440 -   png_debug(1, "in png_do_read_transformations\n");
157.2441 -#if !defined(PNG_USELESS_TESTS_SUPPORTED)
157.2442 +   png_debug(1, "in png_do_read_transformations");
157.2443 +
157.2444     if (png_ptr->row_buf == NULL)
157.2445     {
157.2446 -#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
157.2447 -      char msg[50];
157.2448 -
157.2449 -      sprintf(msg, "NULL row buffer for row %ld, pass %d", png_ptr->row_number,
157.2450 -         png_ptr->pass);
157.2451 -      png_error(png_ptr, msg);
157.2452 -#else
157.2453 +      /* Prior to 1.5.4 this output row/pass where the NULL pointer is, but this
157.2454 +       * error is incredibly rare and incredibly easy to debug without this
157.2455 +       * information.
157.2456 +       */
157.2457        png_error(png_ptr, "NULL row buffer");
157.2458 -#endif
157.2459     }
157.2460 -#endif
157.2461 -
157.2462 -#if defined(PNG_READ_EXPAND_SUPPORTED)
157.2463 +
157.2464 +   /* The following is debugging; prior to 1.5.4 the code was never compiled in;
157.2465 +    * in 1.5.4 PNG_FLAG_DETECT_UNINITIALIZED was added and the macro
157.2466 +    * PNG_WARN_UNINITIALIZED_ROW removed.  In 1.5 the new flag is set only for
157.2467 +    * selected new APIs to ensure that there is no API change.
157.2468 +    */
157.2469 +   if ((png_ptr->flags & PNG_FLAG_DETECT_UNINITIALIZED) != 0 &&
157.2470 +      !(png_ptr->flags & PNG_FLAG_ROW_INIT))
157.2471 +   {
157.2472 +      /* Application has failed to call either png_read_start_image() or
157.2473 +       * png_read_update_info() after setting transforms that expand pixels.
157.2474 +       * This check added to libpng-1.2.19 (but not enabled until 1.5.4).
157.2475 +       */
157.2476 +      png_error(png_ptr, "Uninitialized row");
157.2477 +   }
157.2478 +
157.2479 +#ifdef PNG_READ_EXPAND_SUPPORTED
157.2480     if (png_ptr->transformations & PNG_EXPAND)
157.2481     {
157.2482        if (png_ptr->row_info.color_type == PNG_COLOR_TYPE_PALETTE)
157.2483        {
157.2484           png_do_expand_palette(&(png_ptr->row_info), png_ptr->row_buf + 1,
157.2485 -            png_ptr->palette, png_ptr->trans, png_ptr->num_trans);
157.2486 +             png_ptr->palette, png_ptr->trans_alpha, png_ptr->num_trans);
157.2487        }
157.2488 +
157.2489        else
157.2490        {
157.2491 -         if (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND_tRNS))
157.2492 +         if (png_ptr->num_trans &&
157.2493 +             (png_ptr->transformations & PNG_EXPAND_tRNS))
157.2494              png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1,
157.2495 -               &(png_ptr->trans_values));
157.2496 +                &(png_ptr->trans_color));
157.2497 +
157.2498           else
157.2499              png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1,
157.2500 -               NULL);
157.2501 +                NULL);
157.2502        }
157.2503     }
157.2504  #endif
157.2505  
157.2506 -#if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
157.2507 -   if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA)
157.2508 -      png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
157.2509 -         PNG_FLAG_FILLER_AFTER | (png_ptr->flags & PNG_FLAG_STRIP_ALPHA));
157.2510 +#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
157.2511 +   if ((png_ptr->transformations & PNG_STRIP_ALPHA) &&
157.2512 +      !(png_ptr->transformations & PNG_COMPOSE) &&
157.2513 +      (png_ptr->row_info.color_type == PNG_COLOR_TYPE_RGB_ALPHA ||
157.2514 +      png_ptr->row_info.color_type == PNG_COLOR_TYPE_GRAY_ALPHA))
157.2515 +      png_do_strip_channel(&(png_ptr->row_info), png_ptr->row_buf + 1,
157.2516 +         0 /* at_start == false, because SWAP_ALPHA happens later */);
157.2517  #endif
157.2518  
157.2519 -#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
157.2520 +#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
157.2521     if (png_ptr->transformations & PNG_RGB_TO_GRAY)
157.2522     {
157.2523        int rgb_error =
157.2524 -         png_do_rgb_to_gray(png_ptr, &(png_ptr->row_info), png_ptr->row_buf + 1);
157.2525 -      if(rgb_error)
157.2526 +          png_do_rgb_to_gray(png_ptr, &(png_ptr->row_info),
157.2527 +              png_ptr->row_buf + 1);
157.2528 +
157.2529 +      if (rgb_error)
157.2530        {
157.2531           png_ptr->rgb_to_gray_status=1;
157.2532 -         if(png_ptr->transformations & PNG_RGB_TO_GRAY_WARN)
157.2533 +         if ((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
157.2534 +             PNG_RGB_TO_GRAY_WARN)
157.2535              png_warning(png_ptr, "png_do_rgb_to_gray found nongray pixel");
157.2536 -         if(png_ptr->transformations & PNG_RGB_TO_GRAY_ERR)
157.2537 +
157.2538 +         if ((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
157.2539 +             PNG_RGB_TO_GRAY_ERR)
157.2540              png_error(png_ptr, "png_do_rgb_to_gray found nongray pixel");
157.2541        }
157.2542     }
157.2543  #endif
157.2544  
157.2545 -/*
157.2546 -From Andreas Dilger e-mail to png-implement, 26 March 1998:
157.2547 -
157.2548 -  In most cases, the "simple transparency" should be done prior to doing
157.2549 -  gray-to-RGB, or you will have to test 3x as many bytes to check if a
157.2550 -  pixel is transparent.  You would also need to make sure that the
157.2551 -  transparency information is upgraded to RGB.
157.2552 -
157.2553 -  To summarize, the current flow is:
157.2554 -  - Gray + simple transparency -> compare 1 or 2 gray bytes and composite
157.2555 -                                  with background "in place" if transparent,
157.2556 -                                  convert to RGB if necessary
157.2557 -  - Gray + alpha -> composite with gray background and remove alpha bytes,
157.2558 -                                  convert to RGB if necessary
157.2559 -
157.2560 -  To support RGB backgrounds for gray images we need:
157.2561 -  - Gray + simple transparency -> convert to RGB + simple transparency, compare
157.2562 -                                  3 or 6 bytes and composite with background
157.2563 -                                  "in place" if transparent (3x compare/pixel
157.2564 -                                  compared to doing composite with gray bkgrnd)
157.2565 -  - Gray + alpha -> convert to RGB + alpha, composite with background and
157.2566 -                                  remove alpha bytes (3x float operations/pixel
157.2567 -                                  compared with composite on gray background)
157.2568 -
157.2569 -  Greg's change will do this.  The reason it wasn't done before is for
157.2570 -  performance, as this increases the per-pixel operations.  If we would check
157.2571 -  in advance if the background was gray or RGB, and position the gray-to-RGB
157.2572 -  transform appropriately, then it would save a lot of work/time.
157.2573 +/* From Andreas Dilger e-mail to png-implement, 26 March 1998:
157.2574 + *
157.2575 + *   In most cases, the "simple transparency" should be done prior to doing
157.2576 + *   gray-to-RGB, or you will have to test 3x as many bytes to check if a
157.2577 + *   pixel is transparent.  You would also need to make sure that the
157.2578 + *   transparency information is upgraded to RGB.
157.2579 + *
157.2580 + *   To summarize, the current flow is:
157.2581 + *   - Gray + simple transparency -> compare 1 or 2 gray bytes and composite
157.2582 + *                                   with background "in place" if transparent,
157.2583 + *                                   convert to RGB if necessary
157.2584 + *   - Gray + alpha -> composite with gray background and remove alpha bytes,
157.2585 + *                                   convert to RGB if necessary
157.2586 + *
157.2587 + *   To support RGB backgrounds for gray images we need:
157.2588 + *   - Gray + simple transparency -> convert to RGB + simple transparency,
157.2589 + *                                   compare 3 or 6 bytes and composite with
157.2590 + *                                   background "in place" if transparent
157.2591 + *                                   (3x compare/pixel compared to doing
157.2592 + *                                   composite with gray bkgrnd)
157.2593 + *   - Gray + alpha -> convert to RGB + alpha, composite with background and
157.2594 + *                                   remove alpha bytes (3x float
157.2595 + *                                   operations/pixel compared with composite
157.2596 + *                                   on gray background)
157.2597 + *
157.2598 + *  Greg's change will do this.  The reason it wasn't done before is for
157.2599 + *  performance, as this increases the per-pixel operations.  If we would check
157.2600 + *  in advance if the background was gray or RGB, and position the gray-to-RGB
157.2601 + *  transform appropriately, then it would save a lot of work/time.
157.2602   */
157.2603  
157.2604 -#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
157.2605 -   /* if gray -> RGB, do so now only if background is non-gray; else do later
157.2606 -    * for performance reasons */
157.2607 +#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
157.2608 +   /* If gray -> RGB, do so now only if background is non-gray; else do later
157.2609 +    * for performance reasons
157.2610 +    */
157.2611     if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
157.2612         !(png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
157.2613        png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1);
157.2614  #endif
157.2615  
157.2616 -#if defined(PNG_READ_BACKGROUND_SUPPORTED)
157.2617 -   if ((png_ptr->transformations & PNG_BACKGROUND) &&
157.2618 -      ((png_ptr->num_trans != 0 ) ||
157.2619 -      (png_ptr->color_type & PNG_COLOR_MASK_ALPHA)))
157.2620 -      png_do_background(&(png_ptr->row_info), png_ptr->row_buf + 1,
157.2621 -         &(png_ptr->trans_values), &(png_ptr->background)
157.2622 -#if defined(PNG_READ_GAMMA_SUPPORTED)
157.2623 -         , &(png_ptr->background_1),
157.2624 -         png_ptr->gamma_table, png_ptr->gamma_from_1,
157.2625 -         png_ptr->gamma_to_1, png_ptr->gamma_16_table,
157.2626 -         png_ptr->gamma_16_from_1, png_ptr->gamma_16_to_1,
157.2627 -         png_ptr->gamma_shift
157.2628 +#if (defined PNG_READ_BACKGROUND_SUPPORTED) ||\
157.2629 +   (defined PNG_READ_ALPHA_MODE_SUPPORTED)
157.2630 +   if (png_ptr->transformations & PNG_COMPOSE)
157.2631 +      png_do_compose(&(png_ptr->row_info), png_ptr->row_buf + 1, png_ptr);
157.2632  #endif
157.2633 -);
157.2634 +
157.2635 +#ifdef PNG_READ_GAMMA_SUPPORTED
157.2636 +   if ((png_ptr->transformations & PNG_GAMMA) &&
157.2637 +#if (defined PNG_READ_BACKGROUND_SUPPORTED) ||\
157.2638 +   (defined PNG_READ_ALPHA_MODE_SUPPORTED)
157.2639 +       !((png_ptr->transformations & PNG_COMPOSE) &&
157.2640 +       ((png_ptr->num_trans != 0) ||
157.2641 +       (png_ptr->color_type & PNG_COLOR_MASK_ALPHA))) &&
157.2642  #endif
157.2643 -
157.2644 -#if defined(PNG_READ_GAMMA_SUPPORTED)
157.2645 -   if ((png_ptr->transformations & PNG_GAMMA) &&
157.2646 -#if defined(PNG_READ_BACKGROUND_SUPPORTED)
157.2647 -      !((png_ptr->transformations & PNG_BACKGROUND) &&
157.2648 -      ((png_ptr->num_trans != 0) ||
157.2649 -      (png_ptr->color_type & PNG_COLOR_MASK_ALPHA))) &&
157.2650 +       (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE))
157.2651 +      png_do_gamma(&(png_ptr->row_info), png_ptr->row_buf + 1, png_ptr);
157.2652  #endif
157.2653 -      (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE))
157.2654 -      png_do_gamma(&(png_ptr->row_info), png_ptr->row_buf + 1,
157.2655 -         png_ptr->gamma_table, png_ptr->gamma_16_table,
157.2656 -         png_ptr->gamma_shift);
157.2657 +
157.2658 +#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED
157.2659 +   if ((png_ptr->transformations & PNG_STRIP_ALPHA) &&
157.2660 +      (png_ptr->transformations & PNG_COMPOSE) &&
157.2661 +      (png_ptr->row_info.color_type == PNG_COLOR_TYPE_RGB_ALPHA ||
157.2662 +      png_ptr->row_info.color_type == PNG_COLOR_TYPE_GRAY_ALPHA))
157.2663 +      png_do_strip_channel(&(png_ptr->row_info), png_ptr->row_buf + 1,
157.2664 +         0 /* at_start == false, because SWAP_ALPHA happens later */);
157.2665  #endif
157.2666  
157.2667 -#if defined(PNG_READ_16_TO_8_SUPPORTED)
157.2668 +#ifdef PNG_READ_ALPHA_MODE_SUPPORTED
157.2669 +   if ((png_ptr->transformations & PNG_ENCODE_ALPHA) &&
157.2670 +      (png_ptr->row_info.color_type & PNG_COLOR_MASK_ALPHA))
157.2671 +      png_do_encode_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1, png_ptr);
157.2672 +#endif
157.2673 +
157.2674 +#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
157.2675 +   if (png_ptr->transformations & PNG_SCALE_16_TO_8)
157.2676 +      png_do_scale_16_to_8(&(png_ptr->row_info), png_ptr->row_buf + 1);
157.2677 +#endif
157.2678 +
157.2679 +#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED
157.2680 +   /* There is no harm in doing both of these because only one has any effect,
157.2681 +    * by putting the 'scale' option first if the app asks for scale (either by
157.2682 +    * calling the API or in a TRANSFORM flag) this is what happens.
157.2683 +    */
157.2684     if (png_ptr->transformations & PNG_16_TO_8)
157.2685        png_do_chop(&(png_ptr->row_info), png_ptr->row_buf + 1);
157.2686  #endif
157.2687  
157.2688 -#if defined(PNG_READ_DITHER_SUPPORTED)
157.2689 -   if (png_ptr->transformations & PNG_DITHER)
157.2690 +#ifdef PNG_READ_QUANTIZE_SUPPORTED
157.2691 +   if (png_ptr->transformations & PNG_QUANTIZE)
157.2692     {
157.2693 -      png_do_dither((png_row_infop)&(png_ptr->row_info), png_ptr->row_buf + 1,
157.2694 -         png_ptr->palette_lookup, png_ptr->dither_index);
157.2695 -      if(png_ptr->row_info.rowbytes == (png_uint_32)0)
157.2696 -         png_error(png_ptr, "png_do_dither returned rowbytes=0");
157.2697 +      png_do_quantize(&(png_ptr->row_info), png_ptr->row_buf + 1,
157.2698 +          png_ptr->palette_lookup, png_ptr->quantize_index);
157.2699 +
157.2700 +      if (png_ptr->row_info.rowbytes == 0)
157.2701 +         png_error(png_ptr, "png_do_quantize returned rowbytes=0");
157.2702     }
157.2703 +#endif /* PNG_READ_QUANTIZE_SUPPORTED */
157.2704 +
157.2705 +#ifdef PNG_READ_EXPAND_16_SUPPORTED
157.2706 +   /* Do the expansion now, after all the arithmetic has been done.  Notice
157.2707 +    * that previous transformations can handle the PNG_EXPAND_16 flag if this
157.2708 +    * is efficient (particularly true in the case of gamma correction, where
157.2709 +    * better accuracy results faster!)
157.2710 +    */
157.2711 +   if (png_ptr->transformations & PNG_EXPAND_16)
157.2712 +      png_do_expand_16(&png_ptr->row_info, png_ptr->row_buf + 1);
157.2713  #endif
157.2714  
157.2715 -#if defined(PNG_READ_INVERT_SUPPORTED)
157.2716 -   if (png_ptr->transformations & PNG_INVERT_MONO)
157.2717 -      png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1);
157.2718 -#endif
157.2719 -
157.2720 -#if defined(PNG_READ_SHIFT_SUPPORTED)
157.2721 -   if (png_ptr->transformations & PNG_SHIFT)
157.2722 -      png_do_unshift(&(png_ptr->row_info), png_ptr->row_buf + 1,
157.2723 -         &(png_ptr->shift));
157.2724 -#endif
157.2725 -
157.2726 -#if defined(PNG_READ_PACK_SUPPORTED)
157.2727 -   if (png_ptr->transformations & PNG_PACK)
157.2728 -      png_do_unpack(&(png_ptr->row_info), png_ptr->row_buf + 1);
157.2729 -#endif
157.2730 -
157.2731 -#if defined(PNG_READ_BGR_SUPPORTED)
157.2732 -   if (png_ptr->transformations & PNG_BGR)
157.2733 -      png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
157.2734 -#endif
157.2735 -
157.2736 -#if defined(PNG_READ_PACKSWAP_SUPPORTED)
157.2737 -   if (png_ptr->transformations & PNG_PACKSWAP)
157.2738 -      png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1);
157.2739 -#endif
157.2740 -
157.2741 -#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
157.2742 -   /* if gray -> RGB, do so now only if we did not do so above */
157.2743 +#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
157.2744 +   /*NOTE: moved here in 1.5.4 (from much later in this list.) */
157.2745     if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
157.2746         (png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
157.2747        png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1);
157.2748  #endif
157.2749  
157.2750 -#if defined(PNG_READ_FILLER_SUPPORTED)
157.2751 +#ifdef PNG_READ_INVERT_SUPPORTED
157.2752 +   if (png_ptr->transformations & PNG_INVERT_MONO)
157.2753 +      png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1);
157.2754 +#endif
157.2755 +
157.2756 +#ifdef PNG_READ_SHIFT_SUPPORTED
157.2757 +   if (png_ptr->transformations & PNG_SHIFT)
157.2758 +      png_do_unshift(&(png_ptr->row_info), png_ptr->row_buf + 1,
157.2759 +          &(png_ptr->shift));
157.2760 +#endif
157.2761 +
157.2762 +#ifdef PNG_READ_PACK_SUPPORTED
157.2763 +   if (png_ptr->transformations & PNG_PACK)
157.2764 +      png_do_unpack(&(png_ptr->row_info), png_ptr->row_buf + 1);
157.2765 +#endif
157.2766 +
157.2767 +#ifdef PNG_READ_BGR_SUPPORTED
157.2768 +   if (png_ptr->transformations & PNG_BGR)
157.2769 +      png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
157.2770 +#endif
157.2771 +
157.2772 +#ifdef PNG_READ_PACKSWAP_SUPPORTED
157.2773 +   if (png_ptr->transformations & PNG_PACKSWAP)
157.2774 +      png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1);
157.2775 +#endif
157.2776 +
157.2777 +#ifdef PNG_READ_FILLER_SUPPORTED
157.2778     if (png_ptr->transformations & PNG_FILLER)
157.2779        png_do_read_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
157.2780 -         (png_uint_32)png_ptr->filler, png_ptr->flags);
157.2781 +          (png_uint_32)png_ptr->filler, png_ptr->flags);
157.2782  #endif
157.2783  
157.2784 -#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
157.2785 +#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED
157.2786     if (png_ptr->transformations & PNG_INVERT_ALPHA)
157.2787        png_do_read_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
157.2788  #endif
157.2789  
157.2790 -#if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
157.2791 +#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED
157.2792     if (png_ptr->transformations & PNG_SWAP_ALPHA)
157.2793        png_do_read_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
157.2794  #endif
157.2795  
157.2796 -#if defined(PNG_READ_SWAP_SUPPORTED)
157.2797 +#ifdef PNG_READ_16BIT_SUPPORTED
157.2798 +#ifdef PNG_READ_SWAP_SUPPORTED
157.2799     if (png_ptr->transformations & PNG_SWAP_BYTES)
157.2800        png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
157.2801  #endif
157.2802 -
157.2803 -#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
157.2804 +#endif
157.2805 +
157.2806 +#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
157.2807     if (png_ptr->transformations & PNG_USER_TRANSFORM)
157.2808      {
157.2809 -      if(png_ptr->read_user_transform_fn != NULL)
157.2810 -        (*(png_ptr->read_user_transform_fn)) /* user read transform function */
157.2811 -          (png_ptr,                    /* png_ptr */
157.2812 -           &(png_ptr->row_info),       /* row_info:     */
157.2813 -             /*  png_uint_32 width;          width of row */
157.2814 -             /*  png_uint_32 rowbytes;       number of bytes in row */
157.2815 -             /*  png_byte color_type;        color type of pixels */
157.2816 -             /*  png_byte bit_depth;         bit depth of samples */
157.2817 -             /*  png_byte channels;          number of channels (1-4) */
157.2818 -             /*  png_byte pixel_depth;       bits per pixel (depth*channels) */
157.2819 -           png_ptr->row_buf + 1);      /* start of pixel data for row */
157.2820 -#if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
157.2821 -      if(png_ptr->user_transform_depth)
157.2822 +      if (png_ptr->read_user_transform_fn != NULL)
157.2823 +         (*(png_ptr->read_user_transform_fn)) /* User read transform function */
157.2824 +             (png_ptr,                    /* png_ptr */
157.2825 +             &(png_ptr->row_info),     /* row_info: */
157.2826 +                /*  png_uint_32 width;       width of row */
157.2827 +                /*  png_size_t rowbytes;     number of bytes in row */
157.2828 +                /*  png_byte color_type;     color type of pixels */
157.2829 +                /*  png_byte bit_depth;      bit depth of samples */
157.2830 +                /*  png_byte channels;       number of channels (1-4) */
157.2831 +                /*  png_byte pixel_depth;    bits per pixel (depth*channels) */
157.2832 +             png_ptr->row_buf + 1);    /* start of pixel data for row */
157.2833 +#ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED
157.2834 +      if (png_ptr->user_transform_depth)
157.2835           png_ptr->row_info.bit_depth = png_ptr->user_transform_depth;
157.2836 -      if(png_ptr->user_transform_channels)
157.2837 +
157.2838 +      if (png_ptr->user_transform_channels)
157.2839           png_ptr->row_info.channels = png_ptr->user_transform_channels;
157.2840  #endif
157.2841        png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth *
157.2842 -         png_ptr->row_info.channels);
157.2843 +          png_ptr->row_info.channels);
157.2844 +
157.2845        png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
157.2846 -         png_ptr->row_info.width);
157.2847 +          png_ptr->row_info.width);
157.2848     }
157.2849  #endif
157.2850 -
157.2851  }
157.2852  
157.2853 -#if defined(PNG_READ_PACK_SUPPORTED)
157.2854 +#ifdef PNG_READ_PACK_SUPPORTED
157.2855  /* Unpack pixels of 1, 2, or 4 bits per pixel into 1 byte per pixel,
157.2856   * without changing the actual values.  Thus, if you had a row with
157.2857   * a bit depth of 1, you would end up with bytes that only contained
157.2858 @@ -1504,12 +2323,9 @@
157.2859  void /* PRIVATE */
157.2860  png_do_unpack(png_row_infop row_info, png_bytep row)
157.2861  {
157.2862 -   png_debug(1, "in png_do_unpack\n");
157.2863 -#if defined(PNG_USELESS_TESTS_SUPPORTED)
157.2864 -   if (row != NULL && row_info != NULL && row_info->bit_depth < 8)
157.2865 -#else
157.2866 +   png_debug(1, "in png_do_unpack");
157.2867 +
157.2868     if (row_info->bit_depth < 8)
157.2869 -#endif
157.2870     {
157.2871        png_uint_32 i;
157.2872        png_uint_32 row_width=row_info->width;
157.2873 @@ -1524,11 +2340,13 @@
157.2874              for (i = 0; i < row_width; i++)
157.2875              {
157.2876                 *dp = (png_byte)((*sp >> shift) & 0x01);
157.2877 +
157.2878                 if (shift == 7)
157.2879                 {
157.2880                    shift = 0;
157.2881                    sp--;
157.2882                 }
157.2883 +
157.2884                 else
157.2885                    shift++;
157.2886  
157.2887 @@ -1536,6 +2354,7 @@
157.2888              }
157.2889              break;
157.2890           }
157.2891 +
157.2892           case 2:
157.2893           {
157.2894  
157.2895 @@ -1545,11 +2364,13 @@
157.2896              for (i = 0; i < row_width; i++)
157.2897              {
157.2898                 *dp = (png_byte)((*sp >> shift) & 0x03);
157.2899 +
157.2900                 if (shift == 6)
157.2901                 {
157.2902                    shift = 0;
157.2903                    sp--;
157.2904                 }
157.2905 +
157.2906                 else
157.2907                    shift += 2;
157.2908  
157.2909 @@ -1557,6 +2378,7 @@
157.2910              }
157.2911              break;
157.2912           }
157.2913 +
157.2914           case 4:
157.2915           {
157.2916              png_bytep sp = row + (png_size_t)((row_width - 1) >> 1);
157.2917 @@ -1565,11 +2387,13 @@
157.2918              for (i = 0; i < row_width; i++)
157.2919              {
157.2920                 *dp = (png_byte)((*sp >> shift) & 0x0f);
157.2921 +
157.2922                 if (shift == 4)
157.2923                 {
157.2924                    shift = 0;
157.2925                    sp--;
157.2926                 }
157.2927 +
157.2928                 else
157.2929                    shift = 4;
157.2930  
157.2931 @@ -1577,6 +2401,9 @@
157.2932              }
157.2933              break;
157.2934           }
157.2935 +
157.2936 +         default:
157.2937 +            break;
157.2938        }
157.2939        row_info->bit_depth = 8;
157.2940        row_info->pixel_depth = (png_byte)(8 * row_info->channels);
157.2941 @@ -1585,20 +2412,19 @@
157.2942  }
157.2943  #endif
157.2944  
157.2945 -#if defined(PNG_READ_SHIFT_SUPPORTED)
157.2946 +#ifdef PNG_READ_SHIFT_SUPPORTED
157.2947  /* Reverse the effects of png_do_shift.  This routine merely shifts the
157.2948   * pixels back to their significant bits values.  Thus, if you have
157.2949   * a row of bit depth 8, but only 5 are significant, this will shift
157.2950   * the values back to 0 through 31.
157.2951   */
157.2952  void /* PRIVATE */
157.2953 -png_do_unshift(png_row_infop row_info, png_bytep row, png_color_8p sig_bits)
157.2954 +png_do_unshift(png_row_infop row_info, png_bytep row,
157.2955 +    png_const_color_8p sig_bits)
157.2956  {
157.2957 -   png_debug(1, "in png_do_unshift\n");
157.2958 +   png_debug(1, "in png_do_unshift");
157.2959 +
157.2960     if (
157.2961 -#if defined(PNG_USELESS_TESTS_SUPPORTED)
157.2962 -       row != NULL && row_info != NULL && sig_bits != NULL &&
157.2963 -#endif
157.2964         row_info->color_type != PNG_COLOR_TYPE_PALETTE)
157.2965     {
157.2966        int shift[4];
157.2967 @@ -1613,10 +2439,12 @@
157.2968           shift[channels++] = row_info->bit_depth - sig_bits->green;
157.2969           shift[channels++] = row_info->bit_depth - sig_bits->blue;
157.2970        }
157.2971 +
157.2972        else
157.2973        {
157.2974           shift[channels++] = row_info->bit_depth - sig_bits->gray;
157.2975        }
157.2976 +
157.2977        if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
157.2978        {
157.2979           shift[channels++] = row_info->bit_depth - sig_bits->alpha;
157.2980 @@ -1626,6 +2454,7 @@
157.2981        {
157.2982           if (shift[c] <= 0)
157.2983              shift[c] = 0;
157.2984 +
157.2985           else
157.2986              value = 1;
157.2987        }
157.2988 @@ -1635,11 +2464,14 @@
157.2989  
157.2990        switch (row_info->bit_depth)
157.2991        {
157.2992 +         default:
157.2993 +            break;
157.2994 +
157.2995           case 2:
157.2996           {
157.2997              png_bytep bp;
157.2998 -            png_uint_32 i;
157.2999 -            png_uint_32 istop = row_info->rowbytes;
157.3000 +            png_size_t i;
157.3001 +            png_size_t istop = row_info->rowbytes;
157.3002  
157.3003              for (bp = row, i = 0; i < istop; i++)
157.3004              {
157.3005 @@ -1648,13 +2480,14 @@
157.3006              }
157.3007              break;
157.3008           }
157.3009 +
157.3010           case 4:
157.3011           {
157.3012              png_bytep bp = row;
157.3013 -            png_uint_32 i;
157.3014 -            png_uint_32 istop = row_info->rowbytes;
157.3015 +            png_size_t i;
157.3016 +            png_size_t istop = row_info->rowbytes;
157.3017              png_byte mask = (png_byte)((((int)0xf0 >> shift[0]) & (int)0xf0) |
157.3018 -               (png_byte)((int)0xf >> shift[0]));
157.3019 +                (png_byte)((int)0xf >> shift[0]));
157.3020  
157.3021              for (i = 0; i < istop; i++)
157.3022              {
157.3023 @@ -1663,6 +2496,7 @@
157.3024              }
157.3025              break;
157.3026           }
157.3027 +
157.3028           case 8:
157.3029           {
157.3030              png_bytep bp = row;
157.3031 @@ -1675,6 +2509,8 @@
157.3032              }
157.3033              break;
157.3034           }
157.3035 +
157.3036 +#ifdef PNG_READ_16BIT_SUPPORTED
157.3037           case 16:
157.3038           {
157.3039              png_bytep bp = row;
157.3040 @@ -1690,59 +2526,64 @@
157.3041              }
157.3042              break;
157.3043           }
157.3044 +#endif
157.3045        }
157.3046     }
157.3047  }
157.3048  #endif
157.3049  
157.3050 -#if defined(PNG_READ_16_TO_8_SUPPORTED)
157.3051 -/* chop rows of bit depth 16 down to 8 */
157.3052 +#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
157.3053 +/* Scale rows of bit depth 16 down to 8 accurately */
157.3054  void /* PRIVATE */
157.3055 -png_do_chop(png_row_infop row_info, png_bytep row)
157.3056 +png_do_scale_16_to_8(png_row_infop row_info, png_bytep row)
157.3057  {
157.3058 -   png_debug(1, "in png_do_chop\n");
157.3059 -#if defined(PNG_USELESS_TESTS_SUPPORTED)
157.3060 -   if (row != NULL && row_info != NULL && row_info->bit_depth == 16)
157.3061 -#else
157.3062 +   png_debug(1, "in png_do_scale_16_to_8");
157.3063 +
157.3064     if (row_info->bit_depth == 16)
157.3065 -#endif
157.3066     {
157.3067 -      png_bytep sp = row;
157.3068 -      png_bytep dp = row;
157.3069 -      png_uint_32 i;
157.3070 -      png_uint_32 istop = row_info->width * row_info->channels;
157.3071 -
157.3072 -      for (i = 0; i<istop; i++, sp += 2, dp++)
157.3073 +      png_bytep sp = row; /* source */
157.3074 +      png_bytep dp = row; /* destinaton */
157.3075 +      png_bytep ep = sp + row_info->rowbytes; /* end+1 */
157.3076 +
157.3077 +      while (sp < ep)
157.3078        {
157.3079 -#if defined(PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED)
157.3080 -      /* This does a more accurate scaling of the 16-bit color
157.3081 -       * value, rather than a simple low-byte truncation.
157.3082 -       *
157.3083 -       * What the ideal calculation should be:
157.3084 -       *   *dp = (((((png_uint_32)(*sp) << 8) |
157.3085 -       *          (png_uint_32)(*(sp + 1))) * 255 + 127) / (png_uint_32)65535L;
157.3086 -       *
157.3087 -       * GRR: no, I think this is what it really should be:
157.3088 -       *   *dp = (((((png_uint_32)(*sp) << 8) |
157.3089 -       *           (png_uint_32)(*(sp + 1))) + 128L) / (png_uint_32)257L;
157.3090 -       *
157.3091 -       * GRR: here's the exact calculation with shifts:
157.3092 -       *   temp = (((png_uint_32)(*sp) << 8) | (png_uint_32)(*(sp + 1))) + 128L;
157.3093 -       *   *dp = (temp - (temp >> 8)) >> 8;
157.3094 -       *
157.3095 -       * Approximate calculation with shift/add instead of multiply/divide:
157.3096 -       *   *dp = ((((png_uint_32)(*sp) << 8) |
157.3097 -       *          (png_uint_32)((int)(*(sp + 1)) - *sp)) + 128) >> 8;
157.3098 -       *
157.3099 -       * What we actually do to avoid extra shifting and conversion:
157.3100 -       */
157.3101 -
157.3102 -         *dp = *sp + ((((int)(*(sp + 1)) - *sp) > 128) ? 1 : 0);
157.3103 -#else
157.3104 -       /* Simply discard the low order byte */
157.3105 -         *dp = *sp;
157.3106 -#endif
157.3107 +         /* The input is an array of 16 bit components, these must be scaled to
157.3108 +          * 8 bits each.  For a 16 bit value V the required value (from the PNG
157.3109 +          * specification) is:
157.3110 +          *
157.3111 +          *    (V * 255) / 65535
157.3112 +          *
157.3113 +          * This reduces to round(V / 257), or floor((V + 128.5)/257)
157.3114 +          *
157.3115 +          * Represent V as the two byte value vhi.vlo.  Make a guess that the
157.3116 +          * result is the top byte of V, vhi, then the correction to this value
157.3117 +          * is:
157.3118 +          *
157.3119 +          *    error = floor(((V-vhi.vhi) + 128.5) / 257)
157.3120 +          *          = floor(((vlo-vhi) + 128.5) / 257)
157.3121 +          *
157.3122 +          * This can be approximated using integer arithmetic (and a signed
157.3123 +          * shift):
157.3124 +          *
157.3125 +          *    error = (vlo-vhi+128) >> 8;
157.3126 +          *
157.3127 +          * The approximate differs from the exact answer only when (vlo-vhi) is
157.3128 +          * 128; it then gives a correction of +1 when the exact correction is
157.3129 +          * 0.  This gives 128 errors.  The exact answer (correct for all 16 bit
157.3130 +          * input values) is:
157.3131 +          *
157.3132 +          *    error = (vlo-vhi+128)*65535 >> 24;
157.3133 +          *
157.3134 +          * An alternative arithmetic calculation which also gives no errors is:
157.3135 +          *
157.3136 +          *    (V * 255 + 32895) >> 16
157.3137 +          */
157.3138 +
157.3139 +         png_int_32 tmp = *sp++; /* must be signed! */
157.3140 +         tmp += (((int)*sp++ - tmp + 128) * 65535) >> 24;
157.3141 +         *dp++ = (png_byte)tmp;
157.3142        }
157.3143 +
157.3144        row_info->bit_depth = 8;
157.3145        row_info->pixel_depth = (png_byte)(8 * row_info->channels);
157.3146        row_info->rowbytes = row_info->width * row_info->channels;
157.3147 @@ -1750,14 +2591,40 @@
157.3148  }
157.3149  #endif
157.3150  
157.3151 -#if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
157.3152 +#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED
157.3153 +void /* PRIVATE */
157.3154 +/* Simply discard the low byte.  This was the default behavior prior
157.3155 + * to libpng-1.5.4.
157.3156 + */
157.3157 +png_do_chop(png_row_infop row_info, png_bytep row)
157.3158 +{
157.3159 +   png_debug(1, "in png_do_chop");
157.3160 +
157.3161 +   if (row_info->bit_depth == 16)
157.3162 +   {
157.3163 +      png_bytep sp = row; /* source */
157.3164 +      png_bytep dp = row; /* destinaton */
157.3165 +      png_bytep ep = sp + row_info->rowbytes; /* end+1 */
157.3166 +
157.3167 +      while (sp < ep)
157.3168 +      {
157.3169 +         *dp++ = *sp;
157.3170 +         sp += 2; /* skip low byte */
157.3171 +      }
157.3172 +
157.3173 +      row_info->bit_depth = 8;
157.3174 +      row_info->pixel_depth = (png_byte)(8 * row_info->channels);
157.3175 +      row_info->rowbytes = row_info->width * row_info->channels;
157.3176 +   }
157.3177 +}
157.3178 +#endif
157.3179 +
157.3180 +#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED
157.3181  void /* PRIVATE */
157.3182  png_do_read_swap_alpha(png_row_infop row_info, png_bytep row)
157.3183  {
157.3184 -   png_debug(1, "in png_do_read_swap_alpha\n");
157.3185 -#if defined(PNG_USELESS_TESTS_SUPPORTED)
157.3186 -   if (row != NULL && row_info != NULL)
157.3187 -#endif
157.3188 +   png_debug(1, "in png_do_read_swap_alpha");
157.3189 +
157.3190     {
157.3191        png_uint_32 row_width = row_info->width;
157.3192        if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
157.3193 @@ -1779,6 +2646,8 @@
157.3194                 *(--dp) = save;
157.3195              }
157.3196           }
157.3197 +
157.3198 +#ifdef PNG_READ_16BIT_SUPPORTED
157.3199           /* This converts from RRGGBBAA to AARRGGBB */
157.3200           else
157.3201           {
157.3202 @@ -1801,7 +2670,9 @@
157.3203                 *(--dp) = save[1];
157.3204              }
157.3205           }
157.3206 +#endif
157.3207        }
157.3208 +
157.3209        else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
157.3210        {
157.3211           /* This converts from GA to AG */
157.3212 @@ -1819,6 +2690,8 @@
157.3213                 *(--dp) = save;
157.3214              }
157.3215           }
157.3216 +
157.3217 +#ifdef PNG_READ_16BIT_SUPPORTED
157.3218           /* This converts from GGAA to AAGG */
157.3219           else
157.3220           {
157.3221 @@ -1837,133 +2710,137 @@
157.3222                 *(--dp) = save[1];
157.3223              }
157.3224           }
157.3225 +#endif
157.3226        }
157.3227     }
157.3228  }
157.3229  #endif
157.3230  
157.3231 -#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
157.3232 +#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED
157.3233  void /* PRIVATE */
157.3234  png_do_read_invert_alpha(png_row_infop row_info, png_bytep row)
157.3235  {
157.3236 -   png_debug(1, "in png_do_read_invert_alpha\n");
157.3237 -#if defined(PNG_USELESS_TESTS_SUPPORTED)
157.3238 -   if (row != NULL && row_info != NULL)
157.3239 -#endif
157.3240 +   png_uint_32 row_width;
157.3241 +   png_debug(1, "in png_do_read_invert_alpha");
157.3242 +
157.3243 +   row_width = row_info->width;
157.3244 +   if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
157.3245     {
157.3246 -      png_uint_32 row_width = row_info->width;
157.3247 -      if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
157.3248 +      if (row_info->bit_depth == 8)
157.3249        {
157.3250           /* This inverts the alpha channel in RGBA */
157.3251 -         if (row_info->bit_depth == 8)
157.3252 +         png_bytep sp = row + row_info->rowbytes;
157.3253 +         png_bytep dp = sp;
157.3254 +         png_uint_32 i;
157.3255 +
157.3256 +         for (i = 0; i < row_width; i++)
157.3257           {
157.3258 -            png_bytep sp = row + row_info->rowbytes;
157.3259 -            png_bytep dp = sp;
157.3260 -            png_uint_32 i;
157.3261 -
157.3262 -            for (i = 0; i < row_width; i++)
157.3263 -            {
157.3264 -               *(--dp) = (png_byte)(255 - *(--sp));
157.3265 -
157.3266 -/*             This does nothing:
157.3267 -               *(--dp) = *(--sp);
157.3268 -               *(--dp) = *(--sp);
157.3269 -               *(--dp) = *(--sp);
157.3270 -               We can replace it with:
157.3271 +            *(--dp) = (png_byte)(255 - *(--sp));
157.3272 +
157.3273 +/*          This does nothing:
157.3274 +            *(--dp) = *(--sp);
157.3275 +            *(--dp) = *(--sp);
157.3276 +            *(--dp) = *(--sp);
157.3277 +            We can replace it with:
157.3278  */
157.3279 -               sp-=3;
157.3280 -               dp=sp;
157.3281 -            }
157.3282 -         }
157.3283 -         /* This inverts the alpha channel in RRGGBBAA */
157.3284 -         else
157.3285 -         {
157.3286 -            png_bytep sp = row + row_info->rowbytes;
157.3287 -            png_bytep dp = sp;
157.3288 -            png_uint_32 i;
157.3289 -
157.3290 -            for (i = 0; i < row_width; i++)
157.3291 -            {
157.3292 -               *(--dp) = (png_byte)(255 - *(--sp));
157.3293 -               *(--dp) = (png_byte)(255 - *(--sp));
157.3294 -
157.3295 -/*             This does nothing:
157.3296 -               *(--dp) = *(--sp);
157.3297 -               *(--dp) = *(--sp);
157.3298 -               *(--dp) = *(--sp);
157.3299 -               *(--dp) = *(--sp);
157.3300 -               *(--dp) = *(--sp);
157.3301 -               *(--dp) = *(--sp);
157.3302 -               We can replace it with:
157.3303 -*/
157.3304 -               sp-=6;
157.3305 -               dp=sp;
157.3306 -            }
157.3307 +            sp-=3;
157.3308 +            dp=sp;
157.3309           }
157.3310        }
157.3311 -      else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
157.3312 +
157.3313 +#ifdef PNG_READ_16BIT_SUPPORTED
157.3314 +      /* This inverts the alpha channel in RRGGBBAA */
157.3315 +      else
157.3316 +      {
157.3317 +         png_bytep sp = row + row_info->rowbytes;
157.3318 +         png_bytep dp = sp;
157.3319 +         png_uint_32 i;
157.3320 +
157.3321 +         for (i = 0; i < row_width; i++)
157.3322 +         {
157.3323 +            *(--dp) = (png_byte)(255 - *(--sp));
157.3324 +            *(--dp) = (png_byte)(255 - *(--sp));
157.3325 +
157.3326 +/*          This does nothing:
157.3327 +            *(--dp) = *(--sp);
157.3328 +            *(--dp) = *(--sp);
157.3329 +            *(--dp) = *(--sp);
157.3330 +            *(--dp) = *(--sp);
157.3331 +            *(--dp) = *(--sp);
157.3332 +            *(--dp) = *(--sp);
157.3333 +            We can replace it with:
157.3334 +*/
157.3335 +            sp-=6;
157.3336 +            dp=sp;
157.3337 +         }
157.3338 +      }
157.3339 +#endif
157.3340 +   }
157.3341 +   else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
157.3342 +   {
157.3343 +      if (row_info->bit_depth == 8)
157.3344        {
157.3345           /* This inverts the alpha channel in GA */
157.3346 -         if (row_info->bit_depth == 8)
157.3347 +         png_bytep sp = row + row_info->rowbytes;
157.3348 +         png_bytep dp = sp;
157.3349 +         png_uint_32 i;
157.3350 +
157.3351 +         for (i = 0; i < row_width; i++)
157.3352           {
157.3353 -            png_bytep sp = row + row_info->rowbytes;
157.3354 -            png_bytep dp = sp;
157.3355 -            png_uint_32 i;
157.3356 -
157.3357 -            for (i = 0; i < row_width; i++)
157.3358 -            {
157.3359 -               *(--dp) = (png_byte)(255 - *(--sp));
157.3360 -               *(--dp) = *(--sp);
157.3361 -            }
157.3362 -         }
157.3363 -         /* This inverts the alpha channel in GGAA */
157.3364 -         else
157.3365 -         {
157.3366 -            png_bytep sp  = row + row_info->rowbytes;
157.3367 -            png_bytep dp = sp;
157.3368 -            png_uint_32 i;
157.3369 -
157.3370 -            for (i = 0; i < row_width; i++)
157.3371 -            {
157.3372 -               *(--dp) = (png_byte)(255 - *(--sp));
157.3373 -               *(--dp) = (png_byte)(255 - *(--sp));
157.3374 -/*
157.3375 -               *(--dp) = *(--sp);
157.3376 -               *(--dp) = *(--sp);
157.3377 -*/
157.3378 -               sp-=2;
157.3379 -               dp=sp;
157.3380 -            }
157.3381 +            *(--dp) = (png_byte)(255 - *(--sp));
157.3382 +            *(--dp) = *(--sp);
157.3383           }
157.3384        }
157.3385 +
157.3386 +#ifdef PNG_READ_16BIT_SUPPORTED
157.3387 +      else
157.3388 +      {
157.3389 +         /* This inverts the alpha channel in GGAA */
157.3390 +         png_bytep sp  = row + row_info->rowbytes;
157.3391 +         png_bytep dp = sp;
157.3392 +         png_uint_32 i;
157.3393 +
157.3394 +         for (i = 0; i < row_width; i++)
157.3395 +         {
157.3396 +            *(--dp) = (png_byte)(255 - *(--sp));
157.3397 +            *(--dp) = (png_byte)(255 - *(--sp));
157.3398 +/*
157.3399 +            *(--dp) = *(--sp);
157.3400 +            *(--dp) = *(--sp);
157.3401 +*/
157.3402 +            sp-=2;
157.3403 +            dp=sp;
157.3404 +         }
157.3405 +      }
157.3406 +#endif
157.3407     }
157.3408  }
157.3409  #endif
157.3410  
157.3411 -#if defined(PNG_READ_FILLER_SUPPORTED)
157.3412 +#ifdef PNG_READ_FILLER_SUPPORTED
157.3413  /* Add filler channel if we have RGB color */
157.3414  void /* PRIVATE */
157.3415  png_do_read_filler(png_row_infop row_info, png_bytep row,
157.3416 -   png_uint_32 filler, png_uint_32 flags)
157.3417 +    png_uint_32 filler, png_uint_32 flags)
157.3418  {
157.3419     png_uint_32 i;
157.3420     png_uint_32 row_width = row_info->width;
157.3421  
157.3422 +#ifdef PNG_READ_16BIT_SUPPORTED
157.3423     png_byte hi_filler = (png_byte)((filler>>8) & 0xff);
157.3424 +#endif
157.3425     png_byte lo_filler = (png_byte)(filler & 0xff);
157.3426  
157.3427 -   png_debug(1, "in png_do_read_filler\n");
157.3428 +   png_debug(1, "in png_do_read_filler");
157.3429 +
157.3430     if (
157.3431 -#if defined(PNG_USELESS_TESTS_SUPPORTED)
157.3432 -       row != NULL  && row_info != NULL &&
157.3433 -#endif
157.3434         row_info->color_type == PNG_COLOR_TYPE_GRAY)
157.3435     {
157.3436 -      if(row_info->bit_depth == 8)
157.3437 +      if (row_info->bit_depth == 8)
157.3438        {
157.3439 -         /* This changes the data from G to GX */
157.3440           if (flags & PNG_FLAG_FILLER_AFTER)
157.3441           {
157.3442 +            /* This changes the data from G to GX */
157.3443              png_bytep sp = row + (png_size_t)row_width;
157.3444              png_bytep dp =  sp + (png_size_t)row_width;
157.3445              for (i = 1; i < row_width; i++)
157.3446 @@ -1976,9 +2853,10 @@
157.3447              row_info->pixel_depth = 16;
157.3448              row_info->rowbytes = row_width * 2;
157.3449           }
157.3450 -      /* This changes the data from G to XG */
157.3451 +
157.3452           else
157.3453           {
157.3454 +            /* This changes the data from G to XG */
157.3455              png_bytep sp = row + (png_size_t)row_width;
157.3456              png_bytep dp = sp  + (png_size_t)row_width;
157.3457              for (i = 0; i < row_width; i++)
157.3458 @@ -1991,11 +2869,13 @@
157.3459              row_info->rowbytes = row_width * 2;
157.3460           }
157.3461        }
157.3462 -      else if(row_info->bit_depth == 16)
157.3463 +
157.3464 +#ifdef PNG_READ_16BIT_SUPPORTED
157.3465 +      else if (row_info->bit_depth == 16)
157.3466        {
157.3467 -         /* This changes the data from GG to GGXX */
157.3468           if (flags & PNG_FLAG_FILLER_AFTER)
157.3469           {
157.3470 +            /* This changes the data from GG to GGXX */
157.3471              png_bytep sp = row + (png_size_t)row_width * 2;
157.3472              png_bytep dp = sp  + (png_size_t)row_width * 2;
157.3473              for (i = 1; i < row_width; i++)
157.3474 @@ -2011,9 +2891,10 @@
157.3475              row_info->pixel_depth = 32;
157.3476              row_info->rowbytes = row_width * 4;
157.3477           }
157.3478 -         /* This changes the data from GG to XXGG */
157.3479 +
157.3480           else
157.3481           {
157.3482 +            /* This changes the data from GG to XXGG */
157.3483              png_bytep sp = row + (png_size_t)row_width * 2;
157.3484              png_bytep dp = sp  + (png_size_t)row_width * 2;
157.3485              for (i = 0; i < row_width; i++)
157.3486 @@ -2028,14 +2909,15 @@
157.3487              row_info->rowbytes = row_width * 4;
157.3488           }
157.3489        }
157.3490 +#endif
157.3491     } /* COLOR_TYPE == GRAY */
157.3492     else if (row_info->color_type == PNG_COLOR_TYPE_RGB)
157.3493     {
157.3494 -      if(row_info->bit_depth == 8)
157.3495 +      if (row_info->bit_depth == 8)
157.3496        {
157.3497 -         /* This changes the data from RGB to RGBX */
157.3498           if (flags & PNG_FLAG_FILLER_AFTER)
157.3499           {
157.3500 +            /* This changes the data from RGB to RGBX */
157.3501              png_bytep sp = row + (png_size_t)row_width * 3;
157.3502              png_bytep dp = sp  + (png_size_t)row_width;
157.3503              for (i = 1; i < row_width; i++)
157.3504 @@ -2050,9 +2932,10 @@
157.3505              row_info->pixel_depth = 32;
157.3506              row_info->rowbytes = row_width * 4;
157.3507           }
157.3508 -      /* This changes the data from RGB to XRGB */
157.3509 +
157.3510           else
157.3511           {
157.3512 +            /* This changes the data from RGB to XRGB */
157.3513              png_bytep sp = row + (png_size_t)row_width * 3;
157.3514              png_bytep dp = sp + (png_size_t)row_width;
157.3515              for (i = 0; i < row_width; i++)
157.3516 @@ -2067,11 +2950,13 @@
157.3517              row_info->rowbytes = row_width * 4;
157.3518           }
157.3519        }
157.3520 -      else if(row_info->bit_depth == 16)
157.3521 +
157.3522 +#ifdef PNG_READ_16BIT_SUPPORTED
157.3523 +      else if (row_info->bit_depth == 16)
157.3524        {
157.3525 -         /* This changes the data from RRGGBB to RRGGBBXX */
157.3526           if (flags & PNG_FLAG_FILLER_AFTER)
157.3527           {
157.3528 +            /* This changes the data from RRGGBB to RRGGBBXX */
157.3529              png_bytep sp = row + (png_size_t)row_width * 6;
157.3530              png_bytep dp = sp  + (png_size_t)row_width * 2;
157.3531              for (i = 1; i < row_width; i++)
157.3532 @@ -2091,9 +2976,10 @@
157.3533              row_info->pixel_depth = 64;
157.3534              row_info->rowbytes = row_width * 8;
157.3535           }
157.3536 -         /* This changes the data from RRGGBB to XXRRGGBB */
157.3537 +
157.3538           else
157.3539           {
157.3540 +            /* This changes the data from RRGGBB to XXRRGGBB */
157.3541              png_bytep sp = row + (png_size_t)row_width * 6;
157.3542              png_bytep dp = sp  + (png_size_t)row_width * 2;
157.3543              for (i = 0; i < row_width; i++)
157.3544 @@ -2107,34 +2993,35 @@
157.3545                 *(--dp) = hi_filler;
157.3546                 *(--dp) = lo_filler;
157.3547              }
157.3548 +
157.3549              row_info->channels = 4;
157.3550              row_info->pixel_depth = 64;
157.3551              row_info->rowbytes = row_width * 8;
157.3552           }
157.3553        }
157.3554 +#endif
157.3555     } /* COLOR_TYPE == RGB */
157.3556  }
157.3557  #endif
157.3558  
157.3559 -#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
157.3560 -/* expand grayscale files to RGB, with or without alpha */
157.3561 +#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
157.3562 +/* Expand grayscale files to RGB, with or without alpha */
157.3563  void /* PRIVATE */
157.3564  png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
157.3565  {
157.3566     png_uint_32 i;
157.3567     png_uint_32 row_width = row_info->width;
157.3568  
157.3569 -   png_debug(1, "in png_do_gray_to_rgb\n");
157.3570 +   png_debug(1, "in png_do_gray_to_rgb");
157.3571 +
157.3572     if (row_info->bit_depth >= 8 &&
157.3573 -#if defined(PNG_USELESS_TESTS_SUPPORTED)
157.3574 -       row != NULL && row_info != NULL &&
157.3575 -#endif
157.3576 -      !(row_info->color_type & PNG_COLOR_MASK_COLOR))
157.3577 +       !(row_info->color_type & PNG_COLOR_MASK_COLOR))
157.3578     {
157.3579        if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
157.3580        {
157.3581           if (row_info->bit_depth == 8)
157.3582           {
157.3583 +            /* This changes G to RGB */
157.3584              png_bytep sp = row + (png_size_t)row_width - 1;
157.3585              png_bytep dp = sp  + (png_size_t)row_width * 2;
157.3586              for (i = 0; i < row_width; i++)
157.3587 @@ -2144,8 +3031,10 @@
157.3588                 *(dp--) = *(sp--);
157.3589              }
157.3590           }
157.3591 +
157.3592           else
157.3593           {
157.3594 +            /* This changes GG to RRGGBB */
157.3595              png_bytep sp = row + (png_size_t)row_width * 2 - 1;
157.3596              png_bytep dp = sp  + (png_size_t)row_width * 4;
157.3597              for (i = 0; i < row_width; i++)
157.3598 @@ -2159,10 +3048,12 @@
157.3599              }
157.3600           }
157.3601        }
157.3602 +
157.3603        else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
157.3604        {
157.3605           if (row_info->bit_depth == 8)
157.3606           {
157.3607 +            /* This changes GA to RGBA */
157.3608              png_bytep sp = row + (png_size_t)row_width * 2 - 1;
157.3609              png_bytep dp = sp  + (png_size_t)row_width * 2;
157.3610              for (i = 0; i < row_width; i++)
157.3611 @@ -2173,8 +3064,10 @@
157.3612                 *(dp--) = *(sp--);
157.3613              }
157.3614           }
157.3615 +
157.3616           else
157.3617           {
157.3618 +            /* This changes GGAA to RRGGBBAA */
157.3619              png_bytep sp = row + (png_size_t)row_width * 4 - 1;
157.3620              png_bytep dp = sp  + (png_size_t)row_width * 4;
157.3621              for (i = 0; i < row_width; i++)
157.3622 @@ -2193,17 +3086,19 @@
157.3623        row_info->channels += (png_byte)2;
157.3624        row_info->color_type |= PNG_COLOR_MASK_COLOR;
157.3625        row_info->pixel_depth = (png_byte)(row_info->channels *
157.3626 -         row_info->bit_depth);
157.3627 -      row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
157.3628 +          row_info->bit_depth);
157.3629 +      row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width);
157.3630     }
157.3631  }
157.3632  #endif
157.3633  
157.3634 -#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
157.3635 -/* reduce RGB files to grayscale, with or without alpha
157.3636 +#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
157.3637 +/* Reduce RGB files to grayscale, with or without alpha
157.3638   * using the equation given in Poynton's ColorFAQ at
157.3639 - * <http://www.inforamp.net/~poynton/>
157.3640 - * Copyright (c) 1998-01-04 Charles Poynton poynton at inforamp.net
157.3641 + * <http://www.inforamp.net/~poynton/>  (THIS LINK IS DEAD June 2008)
157.3642 + * New link:
157.3643 + * <http://www.poynton.com/notes/colour_and_gamma/>
157.3644 + * Charles Poynton poynton at poynton.com
157.3645   *
157.3646   *     Y = 0.212671 * R + 0.715160 * G + 0.072169 * B
157.3647   *
157.3648 @@ -2228,12 +3123,10 @@
157.3649     png_uint_32 row_width = row_info->width;
157.3650     int rgb_error = 0;
157.3651  
157.3652 -   png_debug(1, "in png_do_rgb_to_gray\n");
157.3653 -   if (
157.3654 -#if defined(PNG_USELESS_TESTS_SUPPORTED)
157.3655 -       row != NULL && row_info != NULL &&
157.3656 -#endif
157.3657 -      (row_info->color_type & PNG_COLOR_MASK_COLOR))
157.3658 +   png_debug(1, "in png_do_rgb_to_gray");
157.3659 +
157.3660 +   if (!(row_info->color_type & PNG_COLOR_MASK_PALETTE) &&
157.3661 +       (row_info->color_type & PNG_COLOR_MASK_COLOR))
157.3662     {
157.3663        png_uint_32 rc = png_ptr->rgb_to_gray_red_coeff;
157.3664        png_uint_32 gc = png_ptr->rgb_to_gray_green_coeff;
157.3665 @@ -2254,14 +3147,16 @@
157.3666                    png_byte red   = png_ptr->gamma_to_1[*(sp++)];
157.3667                    png_byte green = png_ptr->gamma_to_1[*(sp++)];
157.3668                    png_byte blue  = png_ptr->gamma_to_1[*(sp++)];
157.3669 -                  if(red != green || red != blue)
157.3670 +
157.3671 +                  if (red != green || red != blue)
157.3672                    {
157.3673                       rgb_error |= 1;
157.3674                       *(dp++) = png_ptr->gamma_from_1[
157.3675 -                       (rc*red+gc*green+bc*blue)>>15];
157.3676 +                         (rc*red + gc*green + bc*blue)>>15];
157.3677                    }
157.3678 +
157.3679                    else
157.3680 -                     *(dp++) = *(sp-1);
157.3681 +                     *(dp++) = *(sp - 1);
157.3682                 }
157.3683              }
157.3684              else
157.3685 @@ -2274,13 +3169,15 @@
157.3686                    png_byte red   = *(sp++);
157.3687                    png_byte green = *(sp++);
157.3688                    png_byte blue  = *(sp++);
157.3689 -                  if(red != green || red != blue)
157.3690 +
157.3691 +                  if (red != green || red != blue)
157.3692                    {
157.3693                       rgb_error |= 1;
157.3694 -                     *(dp++) = (png_byte)((rc*red+gc*green+bc*blue)>>15);
157.3695 +                     *(dp++) = (png_byte)((rc*red + gc*green + bc*blue)>>15);
157.3696                    }
157.3697 +
157.3698                    else
157.3699 -                     *(dp++) = *(sp-1);
157.3700 +                     *(dp++) = *(sp - 1);
157.3701                 }
157.3702              }
157.3703           }
157.3704 @@ -2297,22 +3194,24 @@
157.3705                 {
157.3706                    png_uint_16 red, green, blue, w;
157.3707  
157.3708 -                  red   = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
157.3709 -                  green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
157.3710 -                  blue  = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
157.3711 -
157.3712 -                  if(red == green && red == blue)
157.3713 +                  red   = (png_uint_16)(((*(sp))<<8) | *(sp + 1)); sp += 2;
157.3714 +                  green = (png_uint_16)(((*(sp))<<8) | *(sp + 1)); sp += 2;
157.3715 +                  blue  = (png_uint_16)(((*(sp))<<8) | *(sp + 1)); sp += 2;
157.3716 +
157.3717 +                  if (red == green && red == blue)
157.3718                       w = red;
157.3719 +
157.3720                    else
157.3721                    {
157.3722 -                     png_uint_16 red_1   = png_ptr->gamma_16_to_1[(red&0xff) >>
157.3723 -                                  png_ptr->gamma_shift][red>>8];
157.3724 -                     png_uint_16 green_1 = png_ptr->gamma_16_to_1[(green&0xff) >>
157.3725 -                                  png_ptr->gamma_shift][green>>8];
157.3726 -                     png_uint_16 blue_1  = png_ptr->gamma_16_to_1[(blue&0xff) >>
157.3727 -                                  png_ptr->gamma_shift][blue>>8];
157.3728 +                     png_uint_16 red_1   = png_ptr->gamma_16_to_1[(red&0xff)
157.3729 +                         >> png_ptr->gamma_shift][red>>8];
157.3730 +                     png_uint_16 green_1 =
157.3731 +                         png_ptr->gamma_16_to_1[(green&0xff) >>
157.3732 +                         png_ptr->gamma_shift][green>>8];
157.3733 +                     png_uint_16 blue_1  = png_ptr->gamma_16_to_1[(blue&0xff)
157.3734 +                         >> png_ptr->gamma_shift][blue>>8];
157.3735                       png_uint_16 gray16  = (png_uint_16)((rc*red_1 + gc*green_1
157.3736 -                                  + bc*blue_1)>>15);
157.3737 +                         + bc*blue_1)>>15);
157.3738                       w = png_ptr->gamma_16_from_1[(gray16&0xff) >>
157.3739                           png_ptr->gamma_shift][gray16 >> 8];
157.3740                       rgb_error |= 1;
157.3741 @@ -2331,12 +3230,13 @@
157.3742                 {
157.3743                    png_uint_16 red, green, blue, gray16;
157.3744  
157.3745 -                  red   = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
157.3746 -                  green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
157.3747 -                  blue  = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
157.3748 -
157.3749 -                  if(red != green || red != blue)
157.3750 +                  red   = (png_uint_16)(((*(sp))<<8) | *(sp + 1)); sp += 2;
157.3751 +                  green = (png_uint_16)(((*(sp))<<8) | *(sp + 1)); sp += 2;
157.3752 +                  blue  = (png_uint_16)(((*(sp))<<8) | *(sp + 1)); sp += 2;
157.3753 +
157.3754 +                  if (red != green || red != blue)
157.3755                       rgb_error |= 1;
157.3756 +
157.3757                    gray16  = (png_uint_16)((rc*red + gc*green + bc*blue)>>15);
157.3758                    *(dp++) = (png_byte)((gray16>>8) & 0xff);
157.3759                    *(dp++) = (png_byte)(gray16 & 0xff);
157.3760 @@ -2358,10 +3258,13 @@
157.3761                    png_byte red   = png_ptr->gamma_to_1[*(sp++)];
157.3762                    png_byte green = png_ptr->gamma_to_1[*(sp++)];
157.3763                    png_byte blue  = png_ptr->gamma_to_1[*(sp++)];
157.3764 -                  if(red != green || red != blue)
157.3765 +
157.3766 +                  if (red != green || red != blue)
157.3767                       rgb_error |= 1;
157.3768 +
157.3769                    *(dp++) =  png_ptr->gamma_from_1
157.3770 -                             [(rc*red + gc*green + bc*blue)>>15];
157.3771 +                      [(rc*red + gc*green + bc*blue)>>15];
157.3772 +
157.3773                    *(dp++) = *(sp++);  /* alpha */
157.3774                 }
157.3775              }
157.3776 @@ -2375,8 +3278,9 @@
157.3777                    png_byte red   = *(sp++);
157.3778                    png_byte green = *(sp++);
157.3779                    png_byte blue  = *(sp++);
157.3780 -                  if(red != green || red != blue)
157.3781 +                  if (red != green || red != blue)
157.3782                       rgb_error |= 1;
157.3783 +
157.3784                    *(dp++) =  (png_byte)((rc*red + gc*green + bc*blue)>>15);
157.3785                    *(dp++) = *(sp++);  /* alpha */
157.3786                 }
157.3787 @@ -2394,24 +3298,31 @@
157.3788                 {
157.3789                    png_uint_16 red, green, blue, w;
157.3790  
157.3791 -                  red   = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
157.3792 -                  green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
157.3793 -                  blue  = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
157.3794 -
157.3795 -                  if(red == green && red == blue)
157.3796 +                  red   = (png_uint_16)(((*(sp))<<8) | *(sp + 1)); sp += 2;
157.3797 +                  green = (png_uint_16)(((*(sp))<<8) | *(sp + 1)); sp += 2;
157.3798 +                  blue  = (png_uint_16)(((*(sp))<<8) | *(sp + 1)); sp += 2;
157.3799 +
157.3800 +                  if (red == green && red == blue)
157.3801                       w = red;
157.3802 +
157.3803                    else
157.3804                    {
157.3805                       png_uint_16 red_1   = png_ptr->gamma_16_to_1[(red&0xff) >>
157.3806 -                                  png_ptr->gamma_shift][red>>8];
157.3807 -                     png_uint_16 green_1 = png_ptr->gamma_16_to_1[(green&0xff) >>
157.3808 -                                  png_ptr->gamma_shift][green>>8];
157.3809 +                         png_ptr->gamma_shift][red>>8];
157.3810 +
157.3811 +                     png_uint_16 green_1 =
157.3812 +                         png_ptr->gamma_16_to_1[(green&0xff) >>
157.3813 +                         png_ptr->gamma_shift][green>>8];
157.3814 +
157.3815                       png_uint_16 blue_1  = png_ptr->gamma_16_to_1[(blue&0xff) >>
157.3816 -                                  png_ptr->gamma_shift][blue>>8];
157.3817 +                         png_ptr->gamma_shift][blue>>8];
157.3818 +
157.3819                       png_uint_16 gray16  = (png_uint_16)((rc * red_1
157.3820 -                                  + gc * green_1 + bc * blue_1)>>15);
157.3821 +                         + gc * green_1 + bc * blue_1)>>15);
157.3822 +
157.3823                       w = png_ptr->gamma_16_from_1[(gray16&0xff) >>
157.3824                           png_ptr->gamma_shift][gray16 >> 8];
157.3825 +
157.3826                       rgb_error |= 1;
157.3827                    }
157.3828  
157.3829 @@ -2429,11 +3340,13 @@
157.3830                 for (i = 0; i < row_width; i++)
157.3831                 {
157.3832                    png_uint_16 red, green, blue, gray16;
157.3833 -                  red   = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
157.3834 -                  green = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
157.3835 -                  blue  = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
157.3836 -                  if(red != green || red != blue)
157.3837 +                  red   = (png_uint_16)((*(sp)<<8) | *(sp + 1)); sp += 2;
157.3838 +                  green = (png_uint_16)((*(sp)<<8) | *(sp + 1)); sp += 2;
157.3839 +                  blue  = (png_uint_16)((*(sp)<<8) | *(sp + 1)); sp += 2;
157.3840 +
157.3841 +                  if (red != green || red != blue)
157.3842                       rgb_error |= 1;
157.3843 +
157.3844                    gray16  = (png_uint_16)((rc*red + gc*green + bc*blue)>>15);
157.3845                    *(dp++) = (png_byte)((gray16>>8) & 0xff);
157.3846                    *(dp++) = (png_byte)(gray16 & 0xff);
157.3847 @@ -2443,20 +3356,23 @@
157.3848              }
157.3849           }
157.3850        }
157.3851 -   row_info->channels -= (png_byte)2;
157.3852 -      row_info->color_type &= ~PNG_COLOR_MASK_COLOR;
157.3853 +      row_info->channels -= 2;
157.3854 +      row_info->color_type = (png_byte)(row_info->color_type &
157.3855 +          ~PNG_COLOR_MASK_COLOR);
157.3856        row_info->pixel_depth = (png_byte)(row_info->channels *
157.3857 -         row_info->bit_depth);
157.3858 -      row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
157.3859 +          row_info->bit_depth);
157.3860 +      row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width);
157.3861     }
157.3862     return rgb_error;
157.3863  }
157.3864  #endif
157.3865 -
157.3866 +#endif /* PNG_READ_TRANSFORMS_SUPPORTED */
157.3867 +
157.3868 +#ifdef PNG_BUILD_GRAYSCALE_PALETTE_SUPPORTED
157.3869  /* Build a grayscale palette.  Palette is assumed to be 1 << bit_depth
157.3870   * large of png_color.  This lets grayscale images be treated as
157.3871   * paletted.  Most useful for gamma correction and simplification
157.3872 - * of code.
157.3873 + * of code.  This API is not used internally.
157.3874   */
157.3875  void PNGAPI
157.3876  png_build_grayscale_palette(int bit_depth, png_colorp palette)
157.3877 @@ -2466,7 +3382,8 @@
157.3878     int i;
157.3879     int v;
157.3880  
157.3881 -   png_debug(1, "in png_do_build_grayscale_palette\n");
157.3882 +   png_debug(1, "in png_do_build_grayscale_palette");
157.3883 +
157.3884     if (palette == NULL)
157.3885        return;
157.3886  
157.3887 @@ -2476,18 +3393,22 @@
157.3888           num_palette = 2;
157.3889           color_inc = 0xff;
157.3890           break;
157.3891 +
157.3892        case 2:
157.3893           num_palette = 4;
157.3894           color_inc = 0x55;
157.3895           break;
157.3896 +
157.3897        case 4:
157.3898           num_palette = 16;
157.3899           color_inc = 0x11;
157.3900           break;
157.3901 +
157.3902        case 8:
157.3903           num_palette = 256;
157.3904           color_inc = 1;
157.3905           break;
157.3906 +
157.3907        default:
157.3908           num_palette = 0;
157.3909           color_inc = 0;
157.3910 @@ -2501,217 +3422,36 @@
157.3911        palette[i].blue = (png_byte)v;
157.3912     }
157.3913  }
157.3914 -
157.3915 -/* This function is currently unused.  Do we really need it? */
157.3916 -#if defined(PNG_READ_DITHER_SUPPORTED) && defined(PNG_CORRECT_PALETTE_SUPPORTED)
157.3917 -void /* PRIVATE */
157.3918 -png_correct_palette(png_structp png_ptr, png_colorp palette,
157.3919 -   int num_palette)
157.3920 -{
157.3921 -   png_debug(1, "in png_correct_palette\n");
157.3922 -#if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
157.3923 -    defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
157.3924 -   if (png_ptr->transformations & (PNG_GAMMA | PNG_BACKGROUND))
157.3925 -   {
157.3926 -      png_color back, back_1;
157.3927 -
157.3928 -      if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE)
157.3929 -      {
157.3930 -         back.red = png_ptr->gamma_table[png_ptr->background.red];
157.3931 -         back.green = png_ptr->gamma_table[png_ptr->background.green];
157.3932 -         back.blue = png_ptr->gamma_table[png_ptr->background.blue];
157.3933 -
157.3934 -         back_1.red = png_ptr->gamma_to_1[png_ptr->background.red];
157.3935 -         back_1.green = png_ptr->gamma_to_1[png_ptr->background.green];
157.3936 -         back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue];
157.3937 -      }
157.3938 -      else
157.3939 -      {
157.3940 -         double g;
157.3941 -
157.3942 -         g = 1.0 / (png_ptr->background_gamma * png_ptr->screen_gamma);
157.3943 -
157.3944 -         if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_SCREEN ||
157.3945 -             fabs(g - 1.0) < PNG_GAMMA_THRESHOLD)
157.3946 -         {
157.3947 -            back.red = png_ptr->background.red;
157.3948 -            back.green = png_ptr->background.green;
157.3949 -            back.blue = png_ptr->background.blue;
157.3950 -         }
157.3951 -         else
157.3952 -         {
157.3953 -            back.red =
157.3954 -               (png_byte)(pow((double)png_ptr->background.red/255, g) *
157.3955 -                255.0 + 0.5);
157.3956 -            back.green =
157.3957 -               (png_byte)(pow((double)png_ptr->background.green/255, g) *
157.3958 -                255.0 + 0.5);
157.3959 -            back.blue =
157.3960 -               (png_byte)(pow((double)png_ptr->background.blue/255, g) *
157.3961 -                255.0 + 0.5);
157.3962 -         }
157.3963 -
157.3964 -         g = 1.0 / png_ptr->background_gamma;
157.3965 -
157.3966 -         back_1.red =
157.3967 -            (png_byte)(pow((double)png_ptr->background.red/255, g) *
157.3968 -             255.0 + 0.5);
157.3969 -         back_1.green =
157.3970 -            (png_byte)(pow((double)png_ptr->background.green/255, g) *
157.3971 -             255.0 + 0.5);
157.3972 -         back_1.blue =
157.3973 -            (png_byte)(pow((double)png_ptr->background.blue/255, g) *
157.3974 -             255.0 + 0.5);
157.3975 -      }
157.3976 -
157.3977 -      if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
157.3978 -      {
157.3979 -         png_uint_32 i;
157.3980 -
157.3981 -         for (i = 0; i < (png_uint_32)num_palette; i++)
157.3982 -         {
157.3983 -            if (i < png_ptr->num_trans && png_ptr->trans[i] == 0)
157.3984 -            {
157.3985 -               palette[i] = back;
157.3986 -            }
157.3987 -            else if (i < png_ptr->num_trans && png_ptr->trans[i] != 0xff)
157.3988 -            {
157.3989 -               png_byte v, w;
157.3990 -
157.3991 -               v = png_ptr->gamma_to_1[png_ptr->palette[i].red];
157.3992 -               png_composite(w, v, png_ptr->trans[i], back_1.red);
157.3993 -               palette[i].red = png_ptr->gamma_from_1[w];
157.3994 -
157.3995 -               v = png_ptr->gamma_to_1[png_ptr->palette[i].green];
157.3996 -               png_composite(w, v, png_ptr->trans[i], back_1.green);
157.3997 -               palette[i].green = png_ptr->gamma_from_1[w];
157.3998 -
157.3999 -               v = png_ptr->gamma_to_1[png_ptr->palette[i].blue];
157.4000 -               png_composite(w, v, png_ptr->trans[i], back_1.blue);
157.4001 -               palette[i].blue = png_ptr->gamma_from_1[w];
157.4002 -            }
157.4003 -            else
157.4004 -            {
157.4005 -               palette[i].red = png_ptr->gamma_table[palette[i].red];
157.4006 -               palette[i].green = png_ptr->gamma_table[palette[i].green];
157.4007 -               palette[i].blue = png_ptr->gamma_table[palette[i].blue];
157.4008 -            }
157.4009 -         }
157.4010 -      }
157.4011 -      else
157.4012 -      {
157.4013 -         int i;
157.4014 -
157.4015 -         for (i = 0; i < num_palette; i++)
157.4016 -         {
157.4017 -            if (palette[i].red == (png_byte)png_ptr->trans_values.gray)
157.4018 -            {
157.4019 -               palette[i] = back;
157.4020 -            }
157.4021 -            else
157.4022 -            {
157.4023 -               palette[i].red = png_ptr->gamma_table[palette[i].red];
157.4024 -               palette[i].green = png_ptr->gamma_table[palette[i].green];
157.4025 -               palette[i].blue = png_ptr->gamma_table[palette[i].blue];
157.4026 -            }
157.4027 -         }
157.4028 -      }
157.4029 -   }
157.4030 -   else
157.4031  #endif
157.4032 -#if defined(PNG_READ_GAMMA_SUPPORTED)
157.4033 -   if (png_ptr->transformations & PNG_GAMMA)
157.4034 -   {
157.4035 -      int i;
157.4036 -
157.4037 -      for (i = 0; i < num_palette; i++)
157.4038 -      {
157.4039 -         palette[i].red = png_ptr->gamma_table[palette[i].red];
157.4040 -         palette[i].green = png_ptr->gamma_table[palette[i].green];
157.4041 -         palette[i].blue = png_ptr->gamma_table[palette[i].blue];
157.4042 -      }
157.4043 -   }
157.4044 -#if defined(PNG_READ_BACKGROUND_SUPPORTED)
157.4045 -   else
157.4046 -#endif
157.4047 -#endif
157.4048 -#if defined(PNG_READ_BACKGROUND_SUPPORTED)
157.4049 -   if (png_ptr->transformations & PNG_BACKGROUND)
157.4050 -   {
157.4051 -      if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
157.4052 -      {
157.4053 -         png_color back;
157.4054 -
157.4055 -         back.red   = (png_byte)png_ptr->background.red;
157.4056 -         back.green = (png_byte)png_ptr->background.green;
157.4057 -         back.blue  = (png_byte)png_ptr->background.blue;
157.4058 -
157.4059 -         for (i = 0; i < (int)png_ptr->num_trans; i++)
157.4060 -         {
157.4061 -            if (png_ptr->trans[i] == 0)
157.4062 -            {
157.4063 -               palette[i].red = back.red;
157.4064 -               palette[i].green = back.green;
157.4065 -               palette[i].blue = back.blue;
157.4066 -            }
157.4067 -            else if (png_ptr->trans[i] != 0xff)
157.4068 -            {
157.4069 -               png_composite(palette[i].red, png_ptr->palette[i].red,
157.4070 -                  png_ptr->trans[i], back.red);
157.4071 -               png_composite(palette[i].green, png_ptr->palette[i].green,
157.4072 -                  png_ptr->trans[i], back.green);
157.4073 -               png_composite(palette[i].blue, png_ptr->palette[i].blue,
157.4074 -                  png_ptr->trans[i], back.blue);
157.4075 -            }
157.4076 -         }
157.4077 -      }
157.4078 -      else /* assume grayscale palette (what else could it be?) */
157.4079 -      {
157.4080 -         int i;
157.4081 -
157.4082 -         for (i = 0; i < num_palette; i++)
157.4083 -         {
157.4084 -            if (i == (png_byte)png_ptr->trans_values.gray)
157.4085 -            {
157.4086 -               palette[i].red = (png_byte)png_ptr->background.red;
157.4087 -               palette[i].green = (png_byte)png_ptr->background.green;
157.4088 -               palette[i].blue = (png_byte)png_ptr->background.blue;
157.4089 -            }
157.4090 -         }
157.4091 -      }
157.4092 -   }
157.4093 -#endif
157.4094 -}
157.4095 -#endif
157.4096 -
157.4097 -#if defined(PNG_READ_BACKGROUND_SUPPORTED)
157.4098 +
157.4099 +
157.4100 +#ifdef PNG_READ_TRANSFORMS_SUPPORTED
157.4101 +#ifdef PNG_READ_BACKGROUND_SUPPORTED
157.4102  /* Replace any alpha or transparency with the supplied background color.
157.4103   * "background" is already in the screen gamma, while "background_1" is
157.4104   * at a gamma of 1.0.  Paletted files have already been taken care of.
157.4105   */
157.4106  void /* PRIVATE */
157.4107 -png_do_background(png_row_infop row_info, png_bytep row,
157.4108 -   png_color_16p trans_values, png_color_16p background
157.4109 -#if defined(PNG_READ_GAMMA_SUPPORTED)
157.4110 -   , png_color_16p background_1,
157.4111 -   png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1,
157.4112 -   png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1,
157.4113 -   png_uint_16pp gamma_16_to_1, int gamma_shift
157.4114 +png_do_compose(png_row_infop row_info, png_bytep row, png_structp png_ptr)
157.4115 +{
157.4116 +#ifdef PNG_READ_GAMMA_SUPPORTED
157.4117 +   png_const_bytep gamma_table = png_ptr->gamma_table;
157.4118 +   png_const_bytep gamma_from_1 = png_ptr->gamma_from_1;
157.4119 +   png_const_bytep gamma_to_1 = png_ptr->gamma_to_1;
157.4120 +   png_const_uint_16pp gamma_16 = png_ptr->gamma_16_table;
157.4121 +   png_const_uint_16pp gamma_16_from_1 = png_ptr->gamma_16_from_1;
157.4122 +   png_const_uint_16pp gamma_16_to_1 = png_ptr->gamma_16_to_1;
157.4123 +   int gamma_shift = png_ptr->gamma_shift;
157.4124  #endif
157.4125 -   )
157.4126 -{
157.4127 -   png_bytep sp, dp;
157.4128 +
157.4129 +   png_bytep sp;
157.4130     png_uint_32 i;
157.4131 -   png_uint_32 row_width=row_info->width;
157.4132 +   png_uint_32 row_width = row_info->width;
157.4133 +   int optimize = (png_ptr->flags & PNG_FLAG_OPTIMIZE_ALPHA) != 0;
157.4134     int shift;
157.4135  
157.4136 -   png_debug(1, "in png_do_background\n");
157.4137 -   if (background != NULL &&
157.4138 -#if defined(PNG_USELESS_TESTS_SUPPORTED)
157.4139 -       row != NULL && row_info != NULL &&
157.4140 -#endif
157.4141 -      (!(row_info->color_type & PNG_COLOR_MASK_ALPHA) ||
157.4142 -      (row_info->color_type != PNG_COLOR_TYPE_PALETTE && trans_values)))
157.4143 +   png_debug(1, "in png_do_compose");
157.4144 +
157.4145     {
157.4146        switch (row_info->color_type)
157.4147        {
157.4148 @@ -2726,24 +3466,27 @@
157.4149                    for (i = 0; i < row_width; i++)
157.4150                    {
157.4151                       if ((png_uint_16)((*sp >> shift) & 0x01)
157.4152 -                        == trans_values->gray)
157.4153 +                        == png_ptr->trans_color.gray)
157.4154                       {
157.4155                          *sp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
157.4156 -                        *sp |= (png_byte)(background->gray << shift);
157.4157 +                        *sp |= (png_byte)(png_ptr->background.gray << shift);
157.4158                       }
157.4159 +
157.4160                       if (!shift)
157.4161                       {
157.4162                          shift = 7;
157.4163                          sp++;
157.4164                       }
157.4165 +
157.4166                       else
157.4167                          shift--;
157.4168                    }
157.4169                    break;
157.4170                 }
157.4171 +
157.4172                 case 2:
157.4173                 {
157.4174 -#if defined(PNG_READ_GAMMA_SUPPORTED)
157.4175 +#ifdef PNG_READ_GAMMA_SUPPORTED
157.4176                    if (gamma_table != NULL)
157.4177                    {
157.4178                       sp = row;
157.4179 @@ -2751,11 +3494,12 @@
157.4180                       for (i = 0; i < row_width; i++)
157.4181                       {
157.4182                          if ((png_uint_16)((*sp >> shift) & 0x03)
157.4183 -                            == trans_values->gray)
157.4184 +                            == png_ptr->trans_color.gray)
157.4185                          {
157.4186                             *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
157.4187 -                           *sp |= (png_byte)(background->gray << shift);
157.4188 +                           *sp |= (png_byte)(png_ptr->background.gray << shift);
157.4189                          }
157.4190 +
157.4191                          else
157.4192                          {
157.4193                             png_byte p = (png_byte)((*sp >> shift) & 0x03);
157.4194 @@ -2764,15 +3508,18 @@
157.4195                             *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
157.4196                             *sp |= (png_byte)(g << shift);
157.4197                          }
157.4198 +
157.4199                          if (!shift)
157.4200                          {
157.4201                             shift = 6;
157.4202                             sp++;
157.4203                          }
157.4204 +
157.4205                          else
157.4206                             shift -= 2;
157.4207                       }
157.4208                    }
157.4209 +
157.4210                    else
157.4211  #endif
157.4212                    {
157.4213 @@ -2781,25 +3528,28 @@
157.4214                       for (i = 0; i < row_width; i++)
157.4215                       {
157.4216                          if ((png_uint_16)((*sp >> shift) & 0x03)
157.4217 -                            == trans_values->gray)
157.4218 +                            == png_ptr->trans_color.gray)
157.4219                          {
157.4220                             *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
157.4221 -                           *sp |= (png_byte)(background->gray << shift);
157.4222 +                           *sp |= (png_byte)(png_ptr->background.gray << shift);
157.4223                          }
157.4224 +
157.4225                          if (!shift)
157.4226                          {
157.4227                             shift = 6;
157.4228                             sp++;
157.4229                          }
157.4230 +
157.4231                          else
157.4232                             shift -= 2;
157.4233                       }
157.4234                    }
157.4235                    break;
157.4236                 }
157.4237 +
157.4238                 case 4:
157.4239                 {
157.4240 -#if defined(PNG_READ_GAMMA_SUPPORTED)
157.4241 +#ifdef PNG_READ_GAMMA_SUPPORTED
157.4242                    if (gamma_table != NULL)
157.4243                    {
157.4244                       sp = row;
157.4245 @@ -2807,28 +3557,32 @@
157.4246                       for (i = 0; i < row_width; i++)
157.4247                       {
157.4248                          if ((png_uint_16)((*sp >> shift) & 0x0f)
157.4249 -                            == trans_values->gray)
157.4250 +                            == png_ptr->trans_color.gray)
157.4251                          {
157.4252                             *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
157.4253 -                           *sp |= (png_byte)(background->gray << shift);
157.4254 +                           *sp |= (png_byte)(png_ptr->background.gray << shift);
157.4255                          }
157.4256 +
157.4257                          else
157.4258                          {
157.4259                             png_byte p = (png_byte)((*sp >> shift) & 0x0f);
157.4260                             png_byte g = (png_byte)((gamma_table[p |
157.4261 -                             (p << 4)] >> 4) & 0x0f);
157.4262 +                               (p << 4)] >> 4) & 0x0f);
157.4263                             *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
157.4264                             *sp |= (png_byte)(g << shift);
157.4265                          }
157.4266 +
157.4267                          if (!shift)
157.4268                          {
157.4269                             shift = 4;
157.4270                             sp++;
157.4271                          }
157.4272 +
157.4273                          else
157.4274                             shift -= 4;
157.4275                       }
157.4276                    }
157.4277 +
157.4278                    else
157.4279  #endif
157.4280                    {
157.4281 @@ -2837,38 +3591,38 @@
157.4282                       for (i = 0; i < row_width; i++)
157.4283                       {
157.4284                          if ((png_uint_16)((*sp >> shift) & 0x0f)
157.4285 -                            == trans_values->gray)
157.4286 +                            == png_ptr->trans_color.gray)
157.4287                          {
157.4288                             *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
157.4289 -                           *sp |= (png_byte)(background->gray << shift);
157.4290 +                           *sp |= (png_byte)(png_ptr->background.gray << shift);
157.4291                          }
157.4292 +
157.4293                          if (!shift)
157.4294                          {
157.4295                             shift = 4;
157.4296                             sp++;
157.4297                          }
157.4298 +
157.4299                          else
157.4300                             shift -= 4;
157.4301                       }
157.4302                    }
157.4303                    break;
157.4304                 }
157.4305 +
157.4306                 case 8:
157.4307                 {
157.4308 -#if defined(PNG_READ_GAMMA_SUPPORTED)
157.4309 +#ifdef PNG_READ_GAMMA_SUPPORTED
157.4310                    if (gamma_table != NULL)
157.4311                    {
157.4312                       sp = row;
157.4313                       for (i = 0; i < row_width; i++, sp++)
157.4314                       {
157.4315 -                        if (*sp == trans_values->gray)
157.4316 -                        {
157.4317 -                           *sp = (png_byte)background->gray;
157.4318 -                        }
157.4319 +                        if (*sp == png_ptr->trans_color.gray)
157.4320 +                           *sp = (png_byte)png_ptr->background.gray;
157.4321 +
157.4322                          else
157.4323 -                        {
157.4324                             *sp = gamma_table[*sp];
157.4325 -                        }
157.4326                       }
157.4327                    }
157.4328                    else
157.4329 @@ -2877,17 +3631,16 @@
157.4330                       sp = row;
157.4331                       for (i = 0; i < row_width; i++, sp++)
157.4332                       {
157.4333 -                        if (*sp == trans_values->gray)
157.4334 -                        {
157.4335 -                           *sp = (png_byte)background->gray;
157.4336 -                        }
157.4337 +                        if (*sp == png_ptr->trans_color.gray)
157.4338 +                           *sp = (png_byte)png_ptr->background.gray;
157.4339                       }
157.4340                    }
157.4341                    break;
157.4342                 }
157.4343 +
157.4344                 case 16:
157.4345                 {
157.4346 -#if defined(PNG_READ_GAMMA_SUPPORTED)
157.4347 +#ifdef PNG_READ_GAMMA_SUPPORTED
157.4348                    if (gamma_16 != NULL)
157.4349                    {
157.4350                       sp = row;
157.4351 @@ -2896,12 +3649,14 @@
157.4352                          png_uint_16 v;
157.4353  
157.4354                          v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
157.4355 -                        if (v == trans_values->gray)
157.4356 +
157.4357 +                        if (v == png_ptr->trans_color.gray)
157.4358                          {
157.4359 -                           /* background is already in screen gamma */
157.4360 -                           *sp = (png_byte)((background->gray >> 8) & 0xff);
157.4361 -                           *(sp + 1) = (png_byte)(background->gray & 0xff);
157.4362 +                           /* Background is already in screen gamma */
157.4363 +                           *sp = (png_byte)((png_ptr->background.gray >> 8) & 0xff);
157.4364 +                           *(sp + 1) = (png_byte)(png_ptr->background.gray & 0xff);
157.4365                          }
157.4366 +
157.4367                          else
157.4368                          {
157.4369                             v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
157.4370 @@ -2919,36 +3674,42 @@
157.4371                          png_uint_16 v;
157.4372  
157.4373                          v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
157.4374 -                        if (v == trans_values->gray)
157.4375 +
157.4376 +                        if (v == png_ptr->trans_color.gray)
157.4377                          {
157.4378 -                           *sp = (png_byte)((background->gray >> 8) & 0xff);
157.4379 -                           *(sp + 1) = (png_byte)(background->gray & 0xff);
157.4380 +                           *sp = (png_byte)((png_ptr->background.gray >> 8) & 0xff);
157.4381 +                           *(sp + 1) = (png_byte)(png_ptr->background.gray & 0xff);
157.4382                          }
157.4383                       }
157.4384                    }
157.4385                    break;
157.4386                 }
157.4387 +
157.4388 +               default:
157.4389 +                  break;
157.4390              }
157.4391              break;
157.4392           }
157.4393 +
157.4394           case PNG_COLOR_TYPE_RGB:
157.4395           {
157.4396              if (row_info->bit_depth == 8)
157.4397              {
157.4398 -#if defined(PNG_READ_GAMMA_SUPPORTED)
157.4399 +#ifdef PNG_READ_GAMMA_SUPPORTED
157.4400                 if (gamma_table != NULL)
157.4401                 {
157.4402                    sp = row;
157.4403                    for (i = 0; i < row_width; i++, sp += 3)
157.4404                    {
157.4405 -                     if (*sp == trans_values->red &&
157.4406 -                        *(sp + 1) == trans_values->green &&
157.4407 -                        *(sp + 2) == trans_values->blue)
157.4408 +                     if (*sp == png_ptr->trans_color.red &&
157.4409 +                         *(sp + 1) == png_ptr->trans_color.green &&
157.4410 +                         *(sp + 2) == png_ptr->trans_color.blue)
157.4411                       {
157.4412 -                        *sp = (png_byte)background->red;
157.4413 -                        *(sp + 1) = (png_byte)background->green;
157.4414 -                        *(sp + 2) = (png_byte)background->blue;
157.4415 +                        *sp = (png_byte)png_ptr->background.red;
157.4416 +                        *(sp + 1) = (png_byte)png_ptr->background.green;
157.4417 +                        *(sp + 2) = (png_byte)png_ptr->background.blue;
157.4418                       }
157.4419 +
157.4420                       else
157.4421                       {
157.4422                          *sp = gamma_table[*sp];
157.4423 @@ -2963,108 +3724,184 @@
157.4424                    sp = row;
157.4425                    for (i = 0; i < row_width; i++, sp += 3)
157.4426                    {
157.4427 -                     if (*sp == trans_values->red &&
157.4428 -                        *(sp + 1) == trans_values->green &&
157.4429 -                        *(sp + 2) == trans_values->blue)
157.4430 +                     if (*sp == png_ptr->trans_color.red &&
157.4431 +                         *(sp + 1) == png_ptr->trans_color.green &&
157.4432 +                         *(sp + 2) == png_ptr->trans_color.blue)
157.4433                       {
157.4434 -                        *sp = (png_byte)background->red;
157.4435 -                        *(sp + 1) = (png_byte)background->green;
157.4436 -                        *(sp + 2) = (png_byte)background->blue;
157.4437 +                        *sp = (png_byte)png_ptr->background.red;
157.4438 +                        *(sp + 1) = (png_byte)png_ptr->background.green;
157.4439 +                        *(sp + 2) = (png_byte)png_ptr->background.blue;
157.4440                       }
157.4441                    }
157.4442                 }
157.4443              }
157.4444              else /* if (row_info->bit_depth == 16) */
157.4445              {
157.4446 -#if defined(PNG_READ_GAMMA_SUPPORTED)
157.4447 +#ifdef PNG_READ_GAMMA_SUPPORTED
157.4448                 if (gamma_16 != NULL)
157.4449                 {
157.4450                    sp = row;
157.4451                    for (i = 0; i < row_width; i++, sp += 6)
157.4452                    {
157.4453                       png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
157.4454 -                     png_uint_16 g = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
157.4455 -                     png_uint_16 b = (png_uint_16)(((*(sp+4)) << 8) + *(sp+5));
157.4456 -                     if (r == trans_values->red && g == trans_values->green &&
157.4457 -                        b == trans_values->blue)
157.4458 +
157.4459 +                     png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8)
157.4460 +                         + *(sp + 3));
157.4461 +
157.4462 +                     png_uint_16 b = (png_uint_16)(((*(sp + 4)) << 8)
157.4463 +                         + *(sp + 5));
157.4464 +
157.4465 +                     if (r == png_ptr->trans_color.red &&
157.4466 +                         g == png_ptr->trans_color.green &&
157.4467 +                         b == png_ptr->trans_color.blue)
157.4468                       {
157.4469 -                        /* background is already in screen gamma */
157.4470 -                        *sp = (png_byte)((background->red >> 8) & 0xff);
157.4471 -                        *(sp + 1) = (png_byte)(background->red & 0xff);
157.4472 -                        *(sp + 2) = (png_byte)((background->green >> 8) & 0xff);
157.4473 -                        *(sp + 3) = (png_byte)(background->green & 0xff);
157.4474 -                        *(sp + 4) = (png_byte)((background->blue >> 8) & 0xff);
157.4475 -                        *(sp + 5) = (png_byte)(background->blue & 0xff);
157.4476 +                        /* Background is already in screen gamma */
157.4477 +                        *sp = (png_byte)((png_ptr->background.red >> 8) & 0xff);
157.4478 +                        *(sp + 1) = (png_byte)(png_ptr->background.red & 0xff);
157.4479 +                        *(sp + 2) = (png_byte)((png_ptr->background.green >> 8) & 0xff);
157.4480 +                        *(sp + 3) = (png_byte)(png_ptr->background.green & 0xff);
157.4481 +                        *(sp + 4) = (png_byte)((png_ptr->background.blue >> 8) & 0xff);
157.4482 +                        *(sp + 5) = (png_byte)(png_ptr->background.blue & 0xff);
157.4483                       }
157.4484 +
157.4485                       else
157.4486                       {
157.4487                          png_uint_16 v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
157.4488                          *sp = (png_byte)((v >> 8) & 0xff);
157.4489                          *(sp + 1) = (png_byte)(v & 0xff);
157.4490 +
157.4491                          v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
157.4492                          *(sp + 2) = (png_byte)((v >> 8) & 0xff);
157.4493                          *(sp + 3) = (png_byte)(v & 0xff);
157.4494 +
157.4495                          v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];
157.4496                          *(sp + 4) = (png_byte)((v >> 8) & 0xff);
157.4497                          *(sp + 5) = (png_byte)(v & 0xff);
157.4498                       }
157.4499                    }
157.4500                 }
157.4501 +
157.4502 +               else
157.4503 +#endif
157.4504 +               {
157.4505 +                  sp = row;
157.4506 +                  for (i = 0; i < row_width; i++, sp += 6)
157.4507 +                  {
157.4508 +                     png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
157.4509 +
157.4510 +                     png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8)
157.4511 +                         + *(sp + 3));
157.4512 +
157.4513 +                     png_uint_16 b = (png_uint_16)(((*(sp + 4)) << 8)
157.4514 +                         + *(sp + 5));
157.4515 +
157.4516 +                     if (r == png_ptr->trans_color.red &&
157.4517 +                         g == png_ptr->trans_color.green &&
157.4518 +                         b == png_ptr->trans_color.blue)
157.4519 +                     {
157.4520 +                        *sp = (png_byte)((png_ptr->background.red >> 8) & 0xff);
157.4521 +                        *(sp + 1) = (png_byte)(png_ptr->background.red & 0xff);
157.4522 +                        *(sp + 2) = (png_byte)((png_ptr->background.green >> 8) & 0xff);
157.4523 +                        *(sp + 3) = (png_byte)(png_ptr->background.green & 0xff);
157.4524 +                        *(sp + 4) = (png_byte)((png_ptr->background.blue >> 8) & 0xff);
157.4525 +                        *(sp + 5) = (png_byte)(png_ptr->background.blue & 0xff);
157.4526 +                     }
157.4527 +                  }
157.4528 +               }
157.4529 +            }
157.4530 +            break;
157.4531 +         }
157.4532 +
157.4533 +         case PNG_COLOR_TYPE_GRAY_ALPHA:
157.4534 +         {
157.4535 +            if (row_info->bit_depth == 8)
157.4536 +            {
157.4537 +#ifdef PNG_READ_GAMMA_SUPPORTED
157.4538 +               if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
157.4539 +                   gamma_table != NULL)
157.4540 +               {
157.4541 +                  sp = row;
157.4542 +                  for (i = 0; i < row_width; i++, sp += 2)
157.4543 +                  {
157.4544 +                     png_uint_16 a = *(sp + 1);
157.4545 +
157.4546 +                     if (a == 0xff)
157.4547 +                        *sp = gamma_table[*sp];
157.4548 +
157.4549 +                     else if (a == 0)
157.4550 +                     {
157.4551 +                        /* Background is already in screen gamma */
157.4552 +                        *sp = (png_byte)png_ptr->background.gray;
157.4553 +                     }
157.4554 +
157.4555 +                     else
157.4556 +                     {
157.4557 +                        png_byte v, w;
157.4558 +
157.4559 +                        v = gamma_to_1[*sp];
157.4560 +                        png_composite(w, v, a, png_ptr->background_1.gray);
157.4561 +                        if (!optimize)
157.4562 +                           w = gamma_from_1[w];
157.4563 +                        *sp = w;
157.4564 +                     }
157.4565 +                  }
157.4566 +               }
157.4567                 else
157.4568  #endif
157.4569                 {
157.4570                    sp = row;
157.4571 -                  for (i = 0; i < row_width; i++, sp += 6)
157.4572 +                  for (i = 0; i < row_width; i++, sp += 2)
157.4573                    {
157.4574 -                     png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp+1));
157.4575 -                     png_uint_16 g = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
157.4576 -                     png_uint_16 b = (png_uint_16)(((*(sp+4)) << 8) + *(sp+5));
157.4577 -
157.4578 -                     if (r == trans_values->red && g == trans_values->green &&
157.4579 -                        b == trans_values->blue)
157.4580 -                     {
157.4581 -                        *sp = (png_byte)((background->red >> 8) & 0xff);
157.4582 -                        *(sp + 1) = (png_byte)(background->red & 0xff);
157.4583 -                        *(sp + 2) = (png_byte)((background->green >> 8) & 0xff);
157.4584 -                        *(sp + 3) = (png_byte)(background->green & 0xff);
157.4585 -                        *(sp + 4) = (png_byte)((background->blue >> 8) & 0xff);
157.4586 -                        *(sp + 5) = (png_byte)(background->blue & 0xff);
157.4587 -                     }
157.4588 +                     png_byte a = *(sp + 1);
157.4589 +
157.4590 +                     if (a == 0)
157.4591 +                        *sp = (png_byte)png_ptr->background.gray;
157.4592 +
157.4593 +                     else if (a < 0xff)
157.4594 +                        png_composite(*sp, *sp, a, png_ptr->background_1.gray);
157.4595                    }
157.4596                 }
157.4597              }
157.4598 -            break;
157.4599 -         }
157.4600 -         case PNG_COLOR_TYPE_GRAY_ALPHA:
157.4601 -         {
157.4602 -            if (row_info->bit_depth == 8)
157.4603 +            else /* if (png_ptr->bit_depth == 16) */
157.4604              {
157.4605 -#if defined(PNG_READ_GAMMA_SUPPORTED)
157.4606 -               if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
157.4607 -                   gamma_table != NULL)
157.4608 +#ifdef PNG_READ_GAMMA_SUPPORTED
157.4609 +               if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
157.4610 +                   gamma_16_to_1 != NULL)
157.4611                 {
157.4612                    sp = row;
157.4613 -                  dp = row;
157.4614 -                  for (i = 0; i < row_width; i++, sp += 2, dp++)
157.4615 +                  for (i = 0; i < row_width; i++, sp += 4)
157.4616                    {
157.4617 -                     png_uint_16 a = *(sp + 1);
157.4618 -
157.4619 -                     if (a == 0xff)
157.4620 +                     png_uint_16 a = (png_uint_16)(((*(sp + 2)) << 8)
157.4621 +                         + *(sp + 3));
157.4622 +
157.4623 +                     if (a == (png_uint_16)0xffff)
157.4624                       {
157.4625 -                        *dp = gamma_table[*sp];
157.4626 +                        png_uint_16 v;
157.4627 +
157.4628 +                        v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
157.4629 +                        *sp = (png_byte)((v >> 8) & 0xff);
157.4630 +                        *(sp + 1) = (png_byte)(v & 0xff);
157.4631                       }
157.4632 +
157.4633                       else if (a == 0)
157.4634                       {
157.4635 -                        /* background is already in screen gamma */
157.4636 -                        *dp = (png_byte)background->gray;
157.4637 +                        /* Background is already in screen gamma */
157.4638 +                        *sp = (png_byte)((png_ptr->background.gray >> 8) & 0xff);
157.4639 +                        *(sp + 1) = (png_byte)(png_ptr->background.gray & 0xff);
157.4640                       }
157.4641 +
157.4642                       else
157.4643                       {
157.4644 -                        png_byte v, w;
157.4645 -
157.4646 -                        v = gamma_to_1[*sp];
157.4647 -                        png_composite(w, v, a, background_1->gray);
157.4648 -                        *dp = gamma_from_1[w];
157.4649 +                        png_uint_16 g, v, w;
157.4650 +
157.4651 +                        g = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
157.4652 +                        png_composite_16(v, g, a, png_ptr->background_1.gray);
157.4653 +                        if (optimize)
157.4654 +                           w = v;
157.4655 +                        else
157.4656 +                           w = gamma_16_from_1[(v&0xff) >> gamma_shift][v >> 8];
157.4657 +                        *sp = (png_byte)((w >> 8) & 0xff);
157.4658 +                        *(sp + 1) = (png_byte)(w & 0xff);
157.4659                       }
157.4660                    }
157.4661                 }
157.4662 @@ -3072,151 +3909,78 @@
157.4663  #endif
157.4664                 {
157.4665                    sp = row;
157.4666 -                  dp = row;
157.4667 -                  for (i = 0; i < row_width; i++, sp += 2, dp++)
157.4668 +                  for (i = 0; i < row_width; i++, sp += 4)
157.4669                    {
157.4670 -                     png_byte a = *(sp + 1);
157.4671 -
157.4672 -                     if (a == 0xff)
157.4673 +                     png_uint_16 a = (png_uint_16)(((*(sp + 2)) << 8)
157.4674 +                         + *(sp + 3));
157.4675 +
157.4676 +                     if (a == 0)
157.4677                       {
157.4678 -                        *dp = *sp;
157.4679 +                        *sp = (png_byte)((png_ptr->background.gray >> 8) & 0xff);
157.4680 +                        *(sp + 1) = (png_byte)(png_ptr->background.gray & 0xff);
157.4681                       }
157.4682 -#if defined(PNG_READ_GAMMA_SUPPORTED)
157.4683 -                     else if (a == 0)
157.4684 -                     {
157.4685 -                        *dp = (png_byte)background->gray;
157.4686 -                     }
157.4687 -                     else
157.4688 -                     {
157.4689 -                        png_composite(*dp, *sp, a, background_1->gray);
157.4690 -                     }
157.4691 -#else
157.4692 -                     *dp = (png_byte)background->gray;
157.4693 -#endif
157.4694 -                  }
157.4695 -               }
157.4696 -            }
157.4697 -            else /* if (png_ptr->bit_depth == 16) */
157.4698 -            {
157.4699 -#if defined(PNG_READ_GAMMA_SUPPORTED)
157.4700 -               if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
157.4701 -                   gamma_16_to_1 != NULL)
157.4702 -               {
157.4703 -                  sp = row;
157.4704 -                  dp = row;
157.4705 -                  for (i = 0; i < row_width; i++, sp += 4, dp += 2)
157.4706 -                  {
157.4707 -                     png_uint_16 a = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
157.4708 -
157.4709 -                     if (a == (png_uint_16)0xffff)
157.4710 -                     {
157.4711 -                        png_uint_16 v;
157.4712 -
157.4713 -                        v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
157.4714 -                        *dp = (png_byte)((v >> 8) & 0xff);
157.4715 -                        *(dp + 1) = (png_byte)(v & 0xff);
157.4716 -                     }
157.4717 -#if defined(PNG_READ_GAMMA_SUPPORTED)
157.4718 -                     else if (a == 0)
157.4719 -#else
157.4720 -                     else
157.4721 -#endif
157.4722 -                     {
157.4723 -                        /* background is already in screen gamma */
157.4724 -                        *dp = (png_byte)((background->gray >> 8) & 0xff);
157.4725 -                        *(dp + 1) = (png_byte)(background->gray & 0xff);
157.4726 -                     }
157.4727 -#if defined(PNG_READ_GAMMA_SUPPORTED)
157.4728 -                     else
157.4729 -                     {
157.4730 -                        png_uint_16 g, v, w;
157.4731 -
157.4732 -                        g = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
157.4733 -                        png_composite_16(v, g, a, background_1->gray);
157.4734 -                        w = gamma_16_from_1[(v&0xff) >> gamma_shift][v >> 8];
157.4735 -                        *dp = (png_byte)((w >> 8) & 0xff);
157.4736 -                        *(dp + 1) = (png_byte)(w & 0xff);
157.4737 -                     }
157.4738 -#endif
157.4739 -                  }
157.4740 -               }
157.4741 -               else
157.4742 -#endif
157.4743 -               {
157.4744 -                  sp = row;
157.4745 -                  dp = row;
157.4746 -                  for (i = 0; i < row_width; i++, sp += 4, dp += 2)
157.4747 -                  {
157.4748 -                     png_uint_16 a = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
157.4749 -                     if (a == (png_uint_16)0xffff)
157.4750 -                     {
157.4751 -                        png_memcpy(dp, sp, 2);
157.4752 -                     }
157.4753 -#if defined(PNG_READ_GAMMA_SUPPORTED)
157.4754 -                     else if (a == 0)
157.4755 -#else
157.4756 -                     else
157.4757 -#endif
157.4758 -                     {
157.4759 -                        *dp = (png_byte)((background->gray >> 8) & 0xff);
157.4760 -                        *(dp + 1) = (png_byte)(background->gray & 0xff);
157.4761 -                     }
157.4762 -#if defined(PNG_READ_GAMMA_SUPPORTED)
157.4763 -                     else
157.4764 +
157.4765 +                     else if (a < 0xffff)
157.4766                       {
157.4767                          png_uint_16 g, v;
157.4768  
157.4769                          g = (png_uint_16)(((*sp) << 8) + *(sp + 1));
157.4770 -                        png_composite_16(v, g, a, background_1->gray);
157.4771 -                        *dp = (png_byte)((v >> 8) & 0xff);
157.4772 -                        *(dp + 1) = (png_byte)(v & 0xff);
157.4773 +                        png_composite_16(v, g, a, png_ptr->background_1.gray);
157.4774 +                        *sp = (png_byte)((v >> 8) & 0xff);
157.4775 +                        *(sp + 1) = (png_byte)(v & 0xff);
157.4776                       }
157.4777 -#endif
157.4778                    }
157.4779                 }
157.4780              }
157.4781              break;
157.4782           }
157.4783 +
157.4784           case PNG_COLOR_TYPE_RGB_ALPHA:
157.4785           {
157.4786              if (row_info->bit_depth == 8)
157.4787              {
157.4788 -#if defined(PNG_READ_GAMMA_SUPPORTED)
157.4789 +#ifdef PNG_READ_GAMMA_SUPPORTED
157.4790                 if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
157.4791                     gamma_table != NULL)
157.4792                 {
157.4793                    sp = row;
157.4794 -                  dp = row;
157.4795 -                  for (i = 0; i < row_width; i++, sp += 4, dp += 3)
157.4796 +                  for (i = 0; i < row_width; i++, sp += 4)
157.4797                    {
157.4798                       png_byte a = *(sp + 3);
157.4799  
157.4800                       if (a == 0xff)
157.4801                       {
157.4802 -                        *dp = gamma_table[*sp];
157.4803 -                        *(dp + 1) = gamma_table[*(sp + 1)];
157.4804 -                        *(dp + 2) = gamma_table[*(sp + 2)];
157.4805 +                        *sp = gamma_table[*sp];
157.4806 +                        *(sp + 1) = gamma_table[*(sp + 1)];
157.4807 +                        *(sp + 2) = gamma_table[*(sp + 2)];
157.4808                       }
157.4809 +
157.4810                       else if (a == 0)
157.4811                       {
157.4812 -                        /* background is already in screen gamma */
157.4813 -                        *dp = (png_byte)background->red;
157.4814 -                        *(dp + 1) = (png_byte)background->green;
157.4815 -                        *(dp + 2) = (png_byte)background->blue;
157.4816 +                        /* Background is already in screen gamma */
157.4817 +                        *sp = (png_byte)png_ptr->background.red;
157.4818 +                        *(sp + 1) = (png_byte)png_ptr->background.green;
157.4819 +                        *(sp + 2) = (png_byte)png_ptr->background.blue;
157.4820                       }
157.4821 +
157.4822                       else
157.4823                       {
157.4824                          png_byte v, w;
157.4825  
157.4826                          v = gamma_to_1[*sp];
157.4827 -                        png_composite(w, v, a, background_1->red);
157.4828 -                        *dp = gamma_from_1[w];
157.4829 +                        png_composite(w, v, a, png_ptr->background_1.red);
157.4830 +                        if (!optimize) w = gamma_from_1[w];
157.4831 +                        *sp = w;
157.4832 +
157.4833                          v = gamma_to_1[*(sp + 1)];
157.4834 -                        png_composite(w, v, a, background_1->green);
157.4835 -                        *(dp + 1) = gamma_from_1[w];
157.4836 +                        png_composite(w, v, a, png_ptr->background_1.green);
157.4837 +                        if (!optimize) w = gamma_from_1[w];
157.4838 +                        *(sp + 1) = w;
157.4839 +
157.4840                          v = gamma_to_1[*(sp + 2)];
157.4841 -                        png_composite(w, v, a, background_1->blue);
157.4842 -                        *(dp + 2) = gamma_from_1[w];
157.4843 +                        png_composite(w, v, a, png_ptr->background_1.blue);
157.4844 +                        if (!optimize) w = gamma_from_1[w];
157.4845 +                        *(sp + 2) = w;
157.4846                       }
157.4847                    }
157.4848                 }
157.4849 @@ -3224,115 +3988,120 @@
157.4850  #endif
157.4851                 {
157.4852                    sp = row;
157.4853 -                  dp = row;
157.4854 -                  for (i = 0; i < row_width; i++, sp += 4, dp += 3)
157.4855 +                  for (i = 0; i < row_width; i++, sp += 4)
157.4856                    {
157.4857                       png_byte a = *(sp + 3);
157.4858  
157.4859 -                     if (a == 0xff)
157.4860 +                     if (a == 0)
157.4861                       {
157.4862 -                        *dp = *sp;
157.4863 -                        *(dp + 1) = *(sp + 1);
157.4864 -                        *(dp + 2) = *(sp + 2);
157.4865 +                        *sp = (png_byte)png_ptr->background.red;
157.4866 +                        *(sp + 1) = (png_byte)png_ptr->background.green;
157.4867 +                        *(sp + 2) = (png_byte)png_ptr->background.blue;
157.4868                       }
157.4869 -                     else if (a == 0)
157.4870 +
157.4871 +                     else if (a < 0xff)
157.4872                       {
157.4873 -                        *dp = (png_byte)background->red;
157.4874 -                        *(dp + 1) = (png_byte)background->green;
157.4875 -                        *(dp + 2) = (png_byte)background->blue;
157.4876 -                     }
157.4877 -                     else
157.4878 -                     {
157.4879 -                        png_composite(*dp, *sp, a, background->red);
157.4880 -                        png_composite(*(dp + 1), *(sp + 1), a,
157.4881 -                           background->green);
157.4882 -                        png_composite(*(dp + 2), *(sp + 2), a,
157.4883 -                           background->blue);
157.4884 +                        png_composite(*sp, *sp, a, png_ptr->background.red);
157.4885 +
157.4886 +                        png_composite(*(sp + 1), *(sp + 1), a,
157.4887 +                            png_ptr->background.green);
157.4888 +
157.4889 +                        png_composite(*(sp + 2), *(sp + 2), a,
157.4890 +                            png_ptr->background.blue);
157.4891                       }
157.4892                    }
157.4893                 }
157.4894              }
157.4895              else /* if (row_info->bit_depth == 16) */
157.4896              {
157.4897 -#if defined(PNG_READ_GAMMA_SUPPORTED)
157.4898 +#ifdef PNG_READ_GAMMA_SUPPORTED
157.4899                 if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
157.4900                     gamma_16_to_1 != NULL)
157.4901                 {
157.4902                    sp = row;
157.4903 -                  dp = row;
157.4904 -                  for (i = 0; i < row_width; i++, sp += 8, dp += 6)
157.4905 +                  for (i = 0; i < row_width; i++, sp += 8)
157.4906                    {
157.4907                       png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
157.4908                           << 8) + (png_uint_16)(*(sp + 7)));
157.4909 +
157.4910                       if (a == (png_uint_16)0xffff)
157.4911                       {
157.4912                          png_uint_16 v;
157.4913  
157.4914                          v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
157.4915 -                        *dp = (png_byte)((v >> 8) & 0xff);
157.4916 -                        *(dp + 1) = (png_byte)(v & 0xff);
157.4917 +                        *sp = (png_byte)((v >> 8) & 0xff);
157.4918 +                        *(sp + 1) = (png_byte)(v & 0xff);
157.4919 +
157.4920                          v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
157.4921 -                        *(dp + 2) = (png_byte)((v >> 8) & 0xff);
157.4922 -                        *(dp + 3) = (png_byte)(v & 0xff);
157.4923 +                        *(sp + 2) = (png_byte)((v >> 8) & 0xff);
157.4924 +                        *(sp + 3) = (png_byte)(v & 0xff);
157.4925 +
157.4926                          v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];
157.4927 -                        *(dp + 4) = (png_byte)((v >> 8) & 0xff);
157.4928 -                        *(dp + 5) = (png_byte)(v & 0xff);
157.4929 +                        *(sp + 4) = (png_byte)((v >> 8) & 0xff);
157.4930 +                        *(sp + 5) = (png_byte)(v & 0xff);
157.4931                       }
157.4932 +
157.4933                       else if (a == 0)
157.4934                       {
157.4935 -                        /* background is already in screen gamma */
157.4936 -                        *dp = (png_byte)((background->red >> 8) & 0xff);
157.4937 -                        *(dp + 1) = (png_byte)(background->red & 0xff);
157.4938 -                        *(dp + 2) = (png_byte)((background->green >> 8) & 0xff);
157.4939 -                        *(dp + 3) = (png_byte)(background->green & 0xff);
157.4940 -                        *(dp + 4) = (png_byte)((background->blue >> 8) & 0xff);
157.4941 -                        *(dp + 5) = (png_byte)(background->blue & 0xff);
157.4942 +                        /* Background is already in screen gamma */
157.4943 +                        *sp = (png_byte)((png_ptr->background.red >> 8) & 0xff);
157.4944 +                        *(sp + 1) = (png_byte)(png_ptr->background.red & 0xff);
157.4945 +                        *(sp + 2) = (png_byte)((png_ptr->background.green >> 8) & 0xff);
157.4946 +                        *(sp + 3) = (png_byte)(png_ptr->background.green & 0xff);
157.4947 +                        *(sp + 4) = (png_byte)((png_ptr->background.blue >> 8) & 0xff);
157.4948 +                        *(sp + 5) = (png_byte)(png_ptr->background.blue & 0xff);
157.4949                       }
157.4950 +
157.4951                       else
157.4952                       {
157.4953 -                        png_uint_16 v, w, x;
157.4954 +                        png_uint_16 v, w;
157.4955  
157.4956                          v = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
157.4957 -                        png_composite_16(w, v, a, background_1->red);
157.4958 -                        x = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8];
157.4959 -                        *dp = (png_byte)((x >> 8) & 0xff);
157.4960 -                        *(dp + 1) = (png_byte)(x & 0xff);
157.4961 +                        png_composite_16(w, v, a, png_ptr->background_1.red);
157.4962 +                        if (!optimize)
157.4963 +                           w = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8];
157.4964 +                        *sp = (png_byte)((w >> 8) & 0xff);
157.4965 +                        *(sp + 1) = (png_byte)(w & 0xff);
157.4966 +
157.4967                          v = gamma_16_to_1[*(sp + 3) >> gamma_shift][*(sp + 2)];
157.4968 -                        png_composite_16(w, v, a, background_1->green);
157.4969 -                        x = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8];
157.4970 -                        *(dp + 2) = (png_byte)((x >> 8) & 0xff);
157.4971 -                        *(dp + 3) = (png_byte)(x & 0xff);
157.4972 +                        png_composite_16(w, v, a, png_ptr->background_1.green);
157.4973 +                        if (!optimize)
157.4974 +                           w = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8];
157.4975 +
157.4976 +                        *(sp + 2) = (png_byte)((w >> 8) & 0xff);
157.4977 +                        *(sp + 3) = (png_byte)(w & 0xff);
157.4978 +
157.4979                          v = gamma_16_to_1[*(sp + 5) >> gamma_shift][*(sp + 4)];
157.4980 -                        png_composite_16(w, v, a, background_1->blue);
157.4981 -                        x = gamma_16_from_1[(w & 0xff) >> gamma_shift][w >> 8];
157.4982 -                        *(dp + 4) = (png_byte)((x >> 8) & 0xff);
157.4983 -                        *(dp + 5) = (png_byte)(x & 0xff);
157.4984 +                        png_composite_16(w, v, a, png_ptr->background_1.blue);
157.4985 +                        if (!optimize)
157.4986 +                           w = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8];
157.4987 +
157.4988 +                        *(sp + 4) = (png_byte)((w >> 8) & 0xff);
157.4989 +                        *(sp + 5) = (png_byte)(w & 0xff);
157.4990                       }
157.4991                    }
157.4992                 }
157.4993 +
157.4994                 else
157.4995  #endif
157.4996                 {
157.4997                    sp = row;
157.4998 -                  dp = row;
157.4999 -                  for (i = 0; i < row_width; i++, sp += 8, dp += 6)
157.5000 +                  for (i = 0; i < row_width; i++, sp += 8)
157.5001                    {
157.5002                       png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
157.5003 -                        << 8) + (png_uint_16)(*(sp + 7)));
157.5004 -                     if (a == (png_uint_16)0xffff)
157.5005 +                         << 8) + (png_uint_16)(*(sp + 7)));
157.5006 +
157.5007 +                     if (a == 0)
157.5008                       {
157.5009 -                        png_memcpy(dp, sp, 6);
157.5010 +                        *sp = (png_byte)((png_ptr->background.red >> 8) & 0xff);
157.5011 +                        *(sp + 1) = (png_byte)(png_ptr->background.red & 0xff);
157.5012 +                        *(sp + 2) = (png_byte)((png_ptr->background.green >> 8) & 0xff);
157.5013 +                        *(sp + 3) = (png_byte)(png_ptr->background.green & 0xff);
157.5014 +                        *(sp + 4) = (png_byte)((png_ptr->background.blue >> 8) & 0xff);
157.5015 +                        *(sp + 5) = (png_byte)(png_ptr->background.blue & 0xff);
157.5016                       }
157.5017 -                     else if (a == 0)
157.5018 -                     {
157.5019 -                        *dp = (png_byte)((background->red >> 8) & 0xff);
157.5020 -                        *(dp + 1) = (png_byte)(background->red & 0xff);
157.5021 -                        *(dp + 2) = (png_byte)((background->green >> 8) & 0xff);
157.5022 -                        *(dp + 3) = (png_byte)(background->green & 0xff);
157.5023 -                        *(dp + 4) = (png_byte)((background->blue >> 8) & 0xff);
157.5024 -                        *(dp + 5) = (png_byte)(background->blue & 0xff);
157.5025 -                     }
157.5026 -                     else
157.5027 +
157.5028 +                     else if (a < 0xffff)
157.5029                       {
157.5030                          png_uint_16 v;
157.5031  
157.5032 @@ -3342,36 +4111,32 @@
157.5033                          png_uint_16 b = (png_uint_16)(((*(sp + 4)) << 8)
157.5034                              + *(sp + 5));
157.5035  
157.5036 -                        png_composite_16(v, r, a, background->red);
157.5037 -                        *dp = (png_byte)((v >> 8) & 0xff);
157.5038 -                        *(dp + 1) = (png_byte)(v & 0xff);
157.5039 -                        png_composite_16(v, g, a, background->green);
157.5040 -                        *(dp + 2) = (png_byte)((v >> 8) & 0xff);
157.5041 -                        *(dp + 3) = (png_byte)(v & 0xff);
157.5042 -                        png_composite_16(v, b, a, background->blue);
157.5043 -                        *(dp + 4) = (png_byte)((v >> 8) & 0xff);
157.5044 -                        *(dp + 5) = (png_byte)(v & 0xff);
157.5045 +                        png_composite_16(v, r, a, png_ptr->background.red);
157.5046 +                        *sp = (png_byte)((v >> 8) & 0xff);
157.5047 +                        *(sp + 1) = (png_byte)(v & 0xff);
157.5048 +
157.5049 +                        png_composite_16(v, g, a, png_ptr->background.green);
157.5050 +                        *(sp + 2) = (png_byte)((v >> 8) & 0xff);
157.5051 +                        *(sp + 3) = (png_byte)(v & 0xff);
157.5052 +
157.5053 +                        png_composite_16(v, b, a, png_ptr->background.blue);
157.5054 +                        *(sp + 4) = (png_byte)((v >> 8) & 0xff);
157.5055 +                        *(sp + 5) = (png_byte)(v & 0xff);
157.5056                       }
157.5057                    }
157.5058                 }
157.5059              }
157.5060              break;
157.5061           }
157.5062 -      }
157.5063 -
157.5064 -      if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
157.5065 -      {
157.5066 -         row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
157.5067 -         row_info->channels--;
157.5068 -         row_info->pixel_depth = (png_byte)(row_info->channels *
157.5069 -            row_info->bit_depth);
157.5070 -         row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
157.5071 +
157.5072 +         default:
157.5073 +            break;
157.5074        }
157.5075     }
157.5076  }
157.5077  #endif
157.5078  
157.5079 -#if defined(PNG_READ_GAMMA_SUPPORTED)
157.5080 +#ifdef PNG_READ_GAMMA_SUPPORTED
157.5081  /* Gamma correct the image, avoiding the alpha channel.  Make sure
157.5082   * you do this after you deal with the transparency issue on grayscale
157.5083   * or RGB images. If your bit depth is 8, use gamma_table, if it
157.5084 @@ -3379,21 +4144,20 @@
157.5085   * build_gamma_table().
157.5086   */
157.5087  void /* PRIVATE */
157.5088 -png_do_gamma(png_row_infop row_info, png_bytep row,
157.5089 -   png_bytep gamma_table, png_uint_16pp gamma_16_table,
157.5090 -   int gamma_shift)
157.5091 +png_do_gamma(png_row_infop row_info, png_bytep row, png_structp png_ptr)
157.5092  {
157.5093 +   png_const_bytep gamma_table = png_ptr->gamma_table;
157.5094 +   png_const_uint_16pp gamma_16_table = png_ptr->gamma_16_table;
157.5095 +   int gamma_shift = png_ptr->gamma_shift;
157.5096 +
157.5097     png_bytep sp;
157.5098     png_uint_32 i;
157.5099     png_uint_32 row_width=row_info->width;
157.5100  
157.5101 -   png_debug(1, "in png_do_gamma\n");
157.5102 -   if (
157.5103 -#if defined(PNG_USELESS_TESTS_SUPPORTED)
157.5104 -       row != NULL && row_info != NULL &&
157.5105 -#endif
157.5106 -       ((row_info->bit_depth <= 8 && gamma_table != NULL) ||
157.5107 -        (row_info->bit_depth == 16 && gamma_16_table != NULL)))
157.5108 +   png_debug(1, "in png_do_gamma");
157.5109 +
157.5110 +   if (((row_info->bit_depth <= 8 && gamma_table != NULL) ||
157.5111 +       (row_info->bit_depth == 16 && gamma_16_table != NULL)))
157.5112     {
157.5113        switch (row_info->color_type)
157.5114        {
157.5115 @@ -3412,6 +4176,7 @@
157.5116                    sp++;
157.5117                 }
157.5118              }
157.5119 +
157.5120              else /* if (row_info->bit_depth == 16) */
157.5121              {
157.5122                 sp = row;
157.5123 @@ -3423,10 +4188,12 @@
157.5124                    *sp = (png_byte)((v >> 8) & 0xff);
157.5125                    *(sp + 1) = (png_byte)(v & 0xff);
157.5126                    sp += 2;
157.5127 +
157.5128                    v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
157.5129                    *sp = (png_byte)((v >> 8) & 0xff);
157.5130                    *(sp + 1) = (png_byte)(v & 0xff);
157.5131                    sp += 2;
157.5132 +
157.5133                    v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
157.5134                    *sp = (png_byte)((v >> 8) & 0xff);
157.5135                    *(sp + 1) = (png_byte)(v & 0xff);
157.5136 @@ -3435,6 +4202,7 @@
157.5137              }
157.5138              break;
157.5139           }
157.5140 +
157.5141           case PNG_COLOR_TYPE_RGB_ALPHA:
157.5142           {
157.5143              if (row_info->bit_depth == 8)
157.5144 @@ -3444,13 +4212,17 @@
157.5145                 {
157.5146                    *sp = gamma_table[*sp];
157.5147                    sp++;
157.5148 +
157.5149                    *sp = gamma_table[*sp];
157.5150                    sp++;
157.5151 +
157.5152                    *sp = gamma_table[*sp];
157.5153                    sp++;
157.5154 +
157.5155                    sp++;
157.5156                 }
157.5157              }
157.5158 +
157.5159              else /* if (row_info->bit_depth == 16) */
157.5160              {
157.5161                 sp = row;
157.5162 @@ -3460,10 +4232,12 @@
157.5163                    *sp = (png_byte)((v >> 8) & 0xff);
157.5164                    *(sp + 1) = (png_byte)(v & 0xff);
157.5165                    sp += 2;
157.5166 +
157.5167                    v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
157.5168                    *sp = (png_byte)((v >> 8) & 0xff);
157.5169                    *(sp + 1) = (png_byte)(v & 0xff);
157.5170                    sp += 2;
157.5171 +
157.5172                    v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
157.5173                    *sp = (png_byte)((v >> 8) & 0xff);
157.5174                    *(sp + 1) = (png_byte)(v & 0xff);
157.5175 @@ -3472,6 +4246,7 @@
157.5176              }
157.5177              break;
157.5178           }
157.5179 +
157.5180           case PNG_COLOR_TYPE_GRAY_ALPHA:
157.5181           {
157.5182              if (row_info->bit_depth == 8)
157.5183 @@ -3483,6 +4258,7 @@
157.5184                    sp += 2;
157.5185                 }
157.5186              }
157.5187 +
157.5188              else /* if (row_info->bit_depth == 16) */
157.5189              {
157.5190                 sp = row;
157.5191 @@ -3496,6 +4272,7 @@
157.5192              }
157.5193              break;
157.5194           }
157.5195 +
157.5196           case PNG_COLOR_TYPE_GRAY:
157.5197           {
157.5198              if (row_info->bit_depth == 2)
157.5199 @@ -3509,13 +4286,14 @@
157.5200                    int d = *sp & 0x03;
157.5201  
157.5202                    *sp = (png_byte)(
157.5203 -                        ((((int)gamma_table[a|(a>>2)|(a>>4)|(a>>6)])   ) & 0xc0)|
157.5204 -                        ((((int)gamma_table[(b<<2)|b|(b>>2)|(b>>4)])>>2) & 0x30)|
157.5205 -                        ((((int)gamma_table[(c<<4)|(c<<2)|c|(c>>2)])>>4) & 0x0c)|
157.5206 -                        ((((int)gamma_table[(d<<6)|(d<<4)|(d<<2)|d])>>6) ));
157.5207 +                      ((((int)gamma_table[a|(a>>2)|(a>>4)|(a>>6)])   ) & 0xc0)|
157.5208 +                      ((((int)gamma_table[(b<<2)|b|(b>>2)|(b>>4)])>>2) & 0x30)|
157.5209 +                      ((((int)gamma_table[(c<<4)|(c<<2)|c|(c>>2)])>>4) & 0x0c)|
157.5210 +                      ((((int)gamma_table[(d<<6)|(d<<4)|(d<<2)|d])>>6) ));
157.5211                    sp++;
157.5212                 }
157.5213              }
157.5214 +
157.5215              if (row_info->bit_depth == 4)
157.5216              {
157.5217                 sp = row;
157.5218 @@ -3525,10 +4303,11 @@
157.5219                    int lsb = *sp & 0x0f;
157.5220  
157.5221                    *sp = (png_byte)((((int)gamma_table[msb | (msb >> 4)]) & 0xf0)
157.5222 -                          | (((int)gamma_table[(lsb << 4) | lsb]) >> 4));
157.5223 +                      | (((int)gamma_table[(lsb << 4) | lsb]) >> 4));
157.5224                    sp++;
157.5225                 }
157.5226              }
157.5227 +
157.5228              else if (row_info->bit_depth == 8)
157.5229              {
157.5230                 sp = row;
157.5231 @@ -3538,6 +4317,7 @@
157.5232                    sp++;
157.5233                 }
157.5234              }
157.5235 +
157.5236              else if (row_info->bit_depth == 16)
157.5237              {
157.5238                 sp = row;
157.5239 @@ -3551,30 +4331,97 @@
157.5240              }
157.5241              break;
157.5242           }
157.5243 +
157.5244 +         default:
157.5245 +            break;
157.5246        }
157.5247     }
157.5248  }
157.5249  #endif
157.5250  
157.5251 -#if defined(PNG_READ_EXPAND_SUPPORTED)
157.5252 +#ifdef PNG_READ_ALPHA_MODE_SUPPORTED
157.5253 +/* Encode the alpha channel to the output gamma (the input channel is always
157.5254 + * linear.)  Called only with color types that have an alpha channel.  Needs the
157.5255 + * from_1 tables.
157.5256 + */
157.5257 +void /* PRIVATE */
157.5258 +png_do_encode_alpha(png_row_infop row_info, png_bytep row, png_structp png_ptr)
157.5259 +{
157.5260 +   png_uint_32 row_width = row_info->width;
157.5261 +
157.5262 +   png_debug(1, "in png_do_encode_alpha");
157.5263 +
157.5264 +   if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
157.5265 +   {
157.5266 +      if (row_info->bit_depth == 8)
157.5267 +      {
157.5268 +         PNG_CONST png_bytep table = png_ptr->gamma_from_1;
157.5269 +
157.5270 +         if (table != NULL)
157.5271 +         {
157.5272 +            PNG_CONST int step =
157.5273 +               (row_info->color_type & PNG_COLOR_MASK_COLOR) ? 4 : 2;
157.5274 +
157.5275 +            /* The alpha channel is the last component: */
157.5276 +            row += step - 1;
157.5277 +
157.5278 +            for (; row_width > 0; --row_width, row += step)
157.5279 +               *row = table[*row];
157.5280 +
157.5281 +            return;
157.5282 +         }
157.5283 +      }
157.5284 +
157.5285 +      else if (row_info->bit_depth == 16)
157.5286 +      {
157.5287 +         PNG_CONST png_uint_16pp table = png_ptr->gamma_16_from_1;
157.5288 +         PNG_CONST int gamma_shift = png_ptr->gamma_shift;
157.5289 +
157.5290 +         if (table != NULL)
157.5291 +         {
157.5292 +            PNG_CONST int step =
157.5293 +               (row_info->color_type & PNG_COLOR_MASK_COLOR) ? 8 : 4;
157.5294 +
157.5295 +            /* The alpha channel is the last component: */
157.5296 +            row += step - 2;
157.5297 +
157.5298 +            for (; row_width > 0; --row_width, row += step)
157.5299 +            {
157.5300 +               png_uint_16 v;
157.5301 +
157.5302 +               v = table[*(row + 1) >> gamma_shift][*row];
157.5303 +               *row = (png_byte)((v >> 8) & 0xff);
157.5304 +               *(row + 1) = (png_byte)(v & 0xff);
157.5305 +            }
157.5306 +
157.5307 +            return;
157.5308 +         }
157.5309 +      }
157.5310 +   }
157.5311 +
157.5312 +   /* Only get to here if called with a weird row_info; no harm has been done,
157.5313 +    * so just issue a warning.
157.5314 +    */
157.5315 +   png_warning(png_ptr, "png_do_encode_alpha: unexpected call");
157.5316 +}
157.5317 +#endif
157.5318 +
157.5319 +#ifdef PNG_READ_EXPAND_SUPPORTED
157.5320  /* Expands a palette row to an RGB or RGBA row depending
157.5321   * upon whether you supply trans and num_trans.
157.5322   */
157.5323  void /* PRIVATE */
157.5324  png_do_expand_palette(png_row_infop row_info, png_bytep row,
157.5325 -   png_colorp palette, png_bytep trans, int num_trans)
157.5326 +   png_const_colorp palette, png_const_bytep trans_alpha, int num_trans)
157.5327  {
157.5328     int shift, value;
157.5329     png_bytep sp, dp;
157.5330     png_uint_32 i;
157.5331     png_uint_32 row_width=row_info->width;
157.5332  
157.5333 -   png_debug(1, "in png_do_expand_palette\n");
157.5334 -   if (
157.5335 -#if defined(PNG_USELESS_TESTS_SUPPORTED)
157.5336 -       row != NULL && row_info != NULL &&
157.5337 -#endif
157.5338 -       row_info->color_type == PNG_COLOR_TYPE_PALETTE)
157.5339 +   png_debug(1, "in png_do_expand_palette");
157.5340 +
157.5341 +   if (row_info->color_type == PNG_COLOR_TYPE_PALETTE)
157.5342     {
157.5343        if (row_info->bit_depth < 8)
157.5344        {
157.5345 @@ -3589,13 +4436,16 @@
157.5346                 {
157.5347                    if ((*sp >> shift) & 0x01)
157.5348                       *dp = 1;
157.5349 +
157.5350                    else
157.5351                       *dp = 0;
157.5352 +
157.5353                    if (shift == 7)
157.5354                    {
157.5355                       shift = 0;
157.5356                       sp--;
157.5357                    }
157.5358 +
157.5359                    else
157.5360                       shift++;
157.5361  
157.5362 @@ -3603,6 +4453,7 @@
157.5363                 }
157.5364                 break;
157.5365              }
157.5366 +
157.5367              case 2:
157.5368              {
157.5369                 sp = row + (png_size_t)((row_width - 1) >> 2);
157.5370 @@ -3617,6 +4468,7 @@
157.5371                       shift = 0;
157.5372                       sp--;
157.5373                    }
157.5374 +
157.5375                    else
157.5376                       shift += 2;
157.5377  
157.5378 @@ -3624,6 +4476,7 @@
157.5379                 }
157.5380                 break;
157.5381              }
157.5382 +
157.5383              case 4:
157.5384              {
157.5385                 sp = row + (png_size_t)((row_width - 1) >> 1);
157.5386 @@ -3638,6 +4491,7 @@
157.5387                       shift = 0;
157.5388                       sp--;
157.5389                    }
157.5390 +
157.5391                    else
157.5392                       shift += 4;
157.5393  
157.5394 @@ -3645,16 +4499,19 @@
157.5395                 }
157.5396                 break;
157.5397              }
157.5398 +
157.5399 +            default:
157.5400 +               break;
157.5401           }
157.5402           row_info->bit_depth = 8;
157.5403           row_info->pixel_depth = 8;
157.5404           row_info->rowbytes = row_width;
157.5405        }
157.5406 -      switch (row_info->bit_depth)
157.5407 +
157.5408 +      if (row_info->bit_depth == 8)
157.5409        {
157.5410 -         case 8:
157.5411           {
157.5412 -            if (trans != NULL)
157.5413 +            if (num_trans > 0)
157.5414              {
157.5415                 sp = row + (png_size_t)row_width - 1;
157.5416                 dp = row + (png_size_t)(row_width << 2) - 1;
157.5417 @@ -3663,8 +4520,10 @@
157.5418                 {
157.5419                    if ((int)(*sp) >= num_trans)
157.5420                       *dp-- = 0xff;
157.5421 +
157.5422                    else
157.5423 -                     *dp-- = trans[*sp];
157.5424 +                     *dp-- = trans_alpha[*sp];
157.5425 +
157.5426                    *dp-- = palette[*sp].blue;
157.5427                    *dp-- = palette[*sp].green;
157.5428                    *dp-- = palette[*sp].red;
157.5429 @@ -3676,6 +4535,7 @@
157.5430                 row_info->color_type = 6;
157.5431                 row_info->channels = 4;
157.5432              }
157.5433 +
157.5434              else
157.5435              {
157.5436                 sp = row + (png_size_t)row_width - 1;
157.5437 @@ -3688,13 +4548,13 @@
157.5438                    *dp-- = palette[*sp].red;
157.5439                    sp--;
157.5440                 }
157.5441 +
157.5442                 row_info->bit_depth = 8;
157.5443                 row_info->pixel_depth = 24;
157.5444                 row_info->rowbytes = row_width * 3;
157.5445                 row_info->color_type = 2;
157.5446                 row_info->channels = 3;
157.5447              }
157.5448 -            break;
157.5449           }
157.5450        }
157.5451     }
157.5452 @@ -3705,21 +4565,19 @@
157.5453   */
157.5454  void /* PRIVATE */
157.5455  png_do_expand(png_row_infop row_info, png_bytep row,
157.5456 -   png_color_16p trans_value)
157.5457 +    png_const_color_16p trans_color)
157.5458  {
157.5459     int shift, value;
157.5460     png_bytep sp, dp;
157.5461     png_uint_32 i;
157.5462     png_uint_32 row_width=row_info->width;
157.5463  
157.5464 -   png_debug(1, "in png_do_expand\n");
157.5465 -#if defined(PNG_USELESS_TESTS_SUPPORTED)
157.5466 -   if (row != NULL && row_info != NULL)
157.5467 -#endif
157.5468 +   png_debug(1, "in png_do_expand");
157.5469 +
157.5470     {
157.5471        if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
157.5472        {
157.5473 -         png_uint_16 gray = (png_uint_16)(trans_value ? trans_value->gray : 0);
157.5474 +         png_uint_16 gray = (png_uint_16)(trans_color ? trans_color->gray : 0);
157.5475  
157.5476           if (row_info->bit_depth < 8)
157.5477           {
157.5478 @@ -3727,7 +4585,7 @@
157.5479              {
157.5480                 case 1:
157.5481                 {
157.5482 -                  gray = (png_uint_16)(gray*0xff);
157.5483 +                  gray = (png_uint_16)((gray & 0x01) * 0xff);
157.5484                    sp = row + (png_size_t)((row_width - 1) >> 3);
157.5485                    dp = row + (png_size_t)row_width - 1;
157.5486                    shift = 7 - (int)((row_width + 7) & 0x07);
157.5487 @@ -3735,13 +4593,16 @@
157.5488                    {
157.5489                       if ((*sp >> shift) & 0x01)
157.5490                          *dp = 0xff;
157.5491 +
157.5492                       else
157.5493                          *dp = 0;
157.5494 +
157.5495                       if (shift == 7)
157.5496                       {
157.5497                          shift = 0;
157.5498                          sp--;
157.5499                       }
157.5500 +
157.5501                       else
157.5502                          shift++;
157.5503  
157.5504 @@ -3749,9 +4610,10 @@
157.5505                    }
157.5506                    break;
157.5507                 }
157.5508 +
157.5509                 case 2:
157.5510                 {
157.5511 -                  gray = (png_uint_16)(gray*0x55);
157.5512 +                  gray = (png_uint_16)((gray & 0x03) * 0x55);
157.5513                    sp = row + (png_size_t)((row_width - 1) >> 2);
157.5514                    dp = row + (png_size_t)row_width - 1;
157.5515                    shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
157.5516 @@ -3765,6 +4627,7 @@
157.5517                          shift = 0;
157.5518                          sp--;
157.5519                       }
157.5520 +
157.5521                       else
157.5522                          shift += 2;
157.5523  
157.5524 @@ -3772,9 +4635,10 @@
157.5525                    }
157.5526                    break;
157.5527                 }
157.5528 +
157.5529                 case 4:
157.5530                 {
157.5531 -                  gray = (png_uint_16)(gray*0x11);
157.5532 +                  gray = (png_uint_16)((gray & 0x0f) * 0x11);
157.5533                    sp = row + (png_size_t)((row_width - 1) >> 1);
157.5534                    dp = row + (png_size_t)row_width - 1;
157.5535                    shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
157.5536 @@ -3787,6 +4651,7 @@
157.5537                          shift = 0;
157.5538                          sp--;
157.5539                       }
157.5540 +
157.5541                       else
157.5542                          shift = 4;
157.5543  
157.5544 @@ -3794,48 +4659,61 @@
157.5545                    }
157.5546                    break;
157.5547                 }
157.5548 +
157.5549 +               default:
157.5550 +                  break;
157.5551              }
157.5552 +
157.5553              row_info->bit_depth = 8;
157.5554              row_info->pixel_depth = 8;
157.5555              row_info->rowbytes = row_width;
157.5556           }
157.5557  
157.5558 -         if (trans_value != NULL)
157.5559 +         if (trans_color != NULL)
157.5560           {
157.5561              if (row_info->bit_depth == 8)
157.5562              {
157.5563 +               gray = gray & 0xff;
157.5564                 sp = row + (png_size_t)row_width - 1;
157.5565                 dp = row + (png_size_t)(row_width << 1) - 1;
157.5566 +
157.5567                 for (i = 0; i < row_width; i++)
157.5568                 {
157.5569                    if (*sp == gray)
157.5570                       *dp-- = 0;
157.5571 +
157.5572                    else
157.5573                       *dp-- = 0xff;
157.5574 +
157.5575                    *dp-- = *sp--;
157.5576                 }
157.5577              }
157.5578 +
157.5579              else if (row_info->bit_depth == 16)
157.5580              {
157.5581 +               png_byte gray_high = (png_byte)((gray >> 8) & 0xff);
157.5582 +               png_byte gray_low = (png_byte)(gray & 0xff);
157.5583                 sp = row + row_info->rowbytes - 1;
157.5584                 dp = row + (row_info->rowbytes << 1) - 1;
157.5585                 for (i = 0; i < row_width; i++)
157.5586                 {
157.5587 -                  if (((png_uint_16)*(sp) |
157.5588 -                     ((png_uint_16)*(sp - 1) << 8)) == gray)
157.5589 +                  if (*(sp - 1) == gray_high && *(sp) == gray_low)
157.5590                    {
157.5591                       *dp-- = 0;
157.5592                       *dp-- = 0;
157.5593                    }
157.5594 +
157.5595                    else
157.5596                    {
157.5597                       *dp-- = 0xff;
157.5598                       *dp-- = 0xff;
157.5599                    }
157.5600 +
157.5601                    *dp-- = *sp--;
157.5602                    *dp-- = *sp--;
157.5603                 }
157.5604              }
157.5605 +
157.5606              row_info->color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
157.5607              row_info->channels = 2;
157.5608              row_info->pixel_depth = (png_byte)(row_info->bit_depth << 1);
157.5609 @@ -3843,20 +4721,23 @@
157.5610                 row_width);
157.5611           }
157.5612        }
157.5613 -      else if (row_info->color_type == PNG_COLOR_TYPE_RGB && trans_value)
157.5614 +      else if (row_info->color_type == PNG_COLOR_TYPE_RGB && trans_color)
157.5615        {
157.5616           if (row_info->bit_depth == 8)
157.5617           {
157.5618 +            png_byte red = (png_byte)(trans_color->red & 0xff);
157.5619 +            png_byte green = (png_byte)(trans_color->green & 0xff);
157.5620 +            png_byte blue = (png_byte)(trans_color->blue & 0xff);
157.5621              sp = row + (png_size_t)row_info->rowbytes - 1;
157.5622              dp = row + (png_size_t)(row_width << 2) - 1;
157.5623              for (i = 0; i < row_width; i++)
157.5624              {
157.5625 -               if (*(sp - 2) == trans_value->red &&
157.5626 -                  *(sp - 1) == trans_value->green &&
157.5627 -                  *(sp - 0) == trans_value->blue)
157.5628 +               if (*(sp - 2) == red && *(sp - 1) == green && *(sp) == blue)
157.5629                    *dp-- = 0;
157.5630 +
157.5631                 else
157.5632                    *dp-- = 0xff;
157.5633 +
157.5634                 *dp-- = *sp--;
157.5635                 *dp-- = *sp--;
157.5636                 *dp-- = *sp--;
157.5637 @@ -3864,25 +4745,33 @@
157.5638           }
157.5639           else if (row_info->bit_depth == 16)
157.5640           {
157.5641 +            png_byte red_high = (png_byte)((trans_color->red >> 8) & 0xff);
157.5642 +            png_byte green_high = (png_byte)((trans_color->green >> 8) & 0xff);
157.5643 +            png_byte blue_high = (png_byte)((trans_color->blue >> 8) & 0xff);
157.5644 +            png_byte red_low = (png_byte)(trans_color->red & 0xff);
157.5645 +            png_byte green_low = (png_byte)(trans_color->green & 0xff);
157.5646 +            png_byte blue_low = (png_byte)(trans_color->blue & 0xff);
157.5647              sp = row + row_info->rowbytes - 1;
157.5648              dp = row + (png_size_t)(row_width << 3) - 1;
157.5649              for (i = 0; i < row_width; i++)
157.5650              {
157.5651 -               if ((((png_uint_16)*(sp - 4) |
157.5652 -                  ((png_uint_16)*(sp - 5) << 8)) == trans_value->red) &&
157.5653 -                  (((png_uint_16)*(sp - 2) |
157.5654 -                  ((png_uint_16)*(sp - 3) << 8)) == trans_value->green) &&
157.5655 -                  (((png_uint_16)*(sp - 0) |
157.5656 -                  ((png_uint_16)*(sp - 1) << 8)) == trans_value->blue))
157.5657 +               if (*(sp - 5) == red_high &&
157.5658 +                   *(sp - 4) == red_low &&
157.5659 +                   *(sp - 3) == green_high &&
157.5660 +                   *(sp - 2) == green_low &&
157.5661 +                   *(sp - 1) == blue_high &&
157.5662 +                   *(sp    ) == blue_low)
157.5663                 {
157.5664                    *dp-- = 0;
157.5665                    *dp-- = 0;
157.5666                 }
157.5667 +
157.5668                 else
157.5669                 {
157.5670                    *dp-- = 0xff;
157.5671                    *dp-- = 0xff;
157.5672                 }
157.5673 +
157.5674                 *dp-- = *sp--;
157.5675                 *dp-- = *sp--;
157.5676                 *dp-- = *sp--;
157.5677 @@ -3894,28 +4783,57 @@
157.5678           row_info->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
157.5679           row_info->channels = 4;
157.5680           row_info->pixel_depth = (png_byte)(row_info->bit_depth << 2);
157.5681 -         row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
157.5682 +         row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width);
157.5683        }
157.5684     }
157.5685  }
157.5686  #endif
157.5687  
157.5688 -#if defined(PNG_READ_DITHER_SUPPORTED)
157.5689 +#ifdef PNG_READ_EXPAND_16_SUPPORTED
157.5690 +/* If the bit depth is 8 and the colour type is not a palette type expand the
157.5691 + * whole row to 16 bits.  Has no effect otherwise.
157.5692 + */
157.5693  void /* PRIVATE */
157.5694 -png_do_dither(png_row_infop row_info, png_bytep row,
157.5695 -    png_bytep palette_lookup, png_bytep dither_lookup)
157.5696 +png_do_expand_16(png_row_infop row_info, png_bytep row)
157.5697 +{
157.5698 +   if (row_info->bit_depth == 8 &&
157.5699 +      row_info->color_type != PNG_COLOR_TYPE_PALETTE)
157.5700 +   {
157.5701 +      /* The row have a sequence of bytes containing [0..255] and we need
157.5702 +       * to turn it into another row containing [0..65535], to do this we
157.5703 +       * calculate:
157.5704 +       *
157.5705 +       *  (input / 255) * 65535
157.5706 +       *
157.5707 +       *  Which happens to be exactly input * 257 and this can be achieved
157.5708 +       *  simply by byte replication in place (copying backwards).
157.5709 +       */
157.5710 +      png_byte *sp = row + row_info->rowbytes; /* source, last byte + 1 */
157.5711 +      png_byte *dp = sp + row_info->rowbytes;  /* destination, end + 1 */
157.5712 +      while (dp > sp)
157.5713 +         dp[-2] = dp[-1] = *--sp, dp -= 2;
157.5714 +
157.5715 +      row_info->rowbytes *= 2;
157.5716 +      row_info->bit_depth = 16;
157.5717 +      row_info->pixel_depth = (png_byte)(row_info->channels * 16);
157.5718 +   }
157.5719 +}
157.5720 +#endif
157.5721 +
157.5722 +#ifdef PNG_READ_QUANTIZE_SUPPORTED
157.5723 +void /* PRIVATE */
157.5724 +png_do_quantize(png_row_infop row_info, png_bytep row,
157.5725 +    png_const_bytep palette_lookup, png_const_bytep quantize_lookup)
157.5726  {
157.5727     png_bytep sp, dp;
157.5728     png_uint_32 i;
157.5729     png_uint_32 row_width=row_info->width;
157.5730  
157.5731 -   png_debug(1, "in png_do_dither\n");
157.5732 -#if defined(PNG_USELESS_TESTS_SUPPORTED)
157.5733 -   if (row != NULL && row_info != NULL)
157.5734 -#endif
157.5735 +   png_debug(1, "in png_do_quantize");
157.5736 +
157.5737 +   if (row_info->bit_depth == 8)
157.5738     {
157.5739 -      if (row_info->color_type == PNG_COLOR_TYPE_RGB &&
157.5740 -         palette_lookup && row_info->bit_depth == 8)
157.5741 +      if (row_info->color_type == PNG_COLOR_TYPE_RGB && palette_lookup)
157.5742        {
157.5743           int r, g, b, p;
157.5744           sp = row;
157.5745 @@ -3926,31 +4844,33 @@
157.5746              g = *sp++;
157.5747              b = *sp++;
157.5748  
157.5749 -            /* this looks real messy, but the compiler will reduce
157.5750 -               it down to a reasonable formula.  For example, with
157.5751 -               5 bits per color, we get:
157.5752 -               p = (((r >> 3) & 0x1f) << 10) |
157.5753 -                  (((g >> 3) & 0x1f) << 5) |
157.5754 -                  ((b >> 3) & 0x1f);
157.5755 -               */
157.5756 -            p = (((r >> (8 - PNG_DITHER_RED_BITS)) &
157.5757 -               ((1 << PNG_DITHER_RED_BITS) - 1)) <<
157.5758 -               (PNG_DITHER_GREEN_BITS + PNG_DITHER_BLUE_BITS)) |
157.5759 -               (((g >> (8 - PNG_DITHER_GREEN_BITS)) &
157.5760 -               ((1 << PNG_DITHER_GREEN_BITS) - 1)) <<
157.5761 -               (PNG_DITHER_BLUE_BITS)) |
157.5762 -               ((b >> (8 - PNG_DITHER_BLUE_BITS)) &
157.5763 -               ((1 << PNG_DITHER_BLUE_BITS) - 1));
157.5764 +            /* This looks real messy, but the compiler will reduce
157.5765 +             * it down to a reasonable formula.  For example, with
157.5766 +             * 5 bits per color, we get:
157.5767 +             * p = (((r >> 3) & 0x1f) << 10) |
157.5768 +             *    (((g >> 3) & 0x1f) << 5) |
157.5769 +             *    ((b >> 3) & 0x1f);
157.5770 +             */
157.5771 +            p = (((r >> (8 - PNG_QUANTIZE_RED_BITS)) &
157.5772 +                ((1 << PNG_QUANTIZE_RED_BITS) - 1)) <<
157.5773 +                (PNG_QUANTIZE_GREEN_BITS + PNG_QUANTIZE_BLUE_BITS)) |
157.5774 +                (((g >> (8 - PNG_QUANTIZE_GREEN_BITS)) &
157.5775 +                ((1 << PNG_QUANTIZE_GREEN_BITS) - 1)) <<
157.5776 +                (PNG_QUANTIZE_BLUE_BITS)) |
157.5777 +                ((b >> (8 - PNG_QUANTIZE_BLUE_BITS)) &
157.5778 +                ((1 << PNG_QUANTIZE_BLUE_BITS) - 1));
157.5779  
157.5780              *dp++ = palette_lookup[p];
157.5781           }
157.5782 +
157.5783           row_info->color_type = PNG_COLOR_TYPE_PALETTE;
157.5784           row_info->channels = 1;
157.5785           row_info->pixel_depth = row_info->bit_depth;
157.5786 -         row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
157.5787 +         row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width);
157.5788        }
157.5789 +
157.5790        else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
157.5791 -         palette_lookup != NULL && row_info->bit_depth == 8)
157.5792 +         palette_lookup != NULL)
157.5793        {
157.5794           int r, g, b, p;
157.5795           sp = row;
157.5796 @@ -3962,270 +4882,52 @@
157.5797              b = *sp++;
157.5798              sp++;
157.5799  
157.5800 -            p = (((r >> (8 - PNG_DITHER_RED_BITS)) &
157.5801 -               ((1 << PNG_DITHER_RED_BITS) - 1)) <<
157.5802 -               (PNG_DITHER_GREEN_BITS + PNG_DITHER_BLUE_BITS)) |
157.5803 -               (((g >> (8 - PNG_DITHER_GREEN_BITS)) &
157.5804 -               ((1 << PNG_DITHER_GREEN_BITS) - 1)) <<
157.5805 -               (PNG_DITHER_BLUE_BITS)) |
157.5806 -               ((b >> (8 - PNG_DITHER_BLUE_BITS)) &
157.5807 -               ((1 << PNG_DITHER_BLUE_BITS) - 1));
157.5808 +            p = (((r >> (8 - PNG_QUANTIZE_RED_BITS)) &
157.5809 +                ((1 << PNG_QUANTIZE_RED_BITS) - 1)) <<
157.5810 +                (PNG_QUANTIZE_GREEN_BITS + PNG_QUANTIZE_BLUE_BITS)) |
157.5811 +                (((g >> (8 - PNG_QUANTIZE_GREEN_BITS)) &
157.5812 +                ((1 << PNG_QUANTIZE_GREEN_BITS) - 1)) <<
157.5813 +                (PNG_QUANTIZE_BLUE_BITS)) |
157.5814 +                ((b >> (8 - PNG_QUANTIZE_BLUE_BITS)) &
157.5815 +                ((1 << PNG_QUANTIZE_BLUE_BITS) - 1));
157.5816  
157.5817              *dp++ = palette_lookup[p];
157.5818           }
157.5819 +
157.5820           row_info->color_type = PNG_COLOR_TYPE_PALETTE;
157.5821           row_info->channels = 1;
157.5822           row_info->pixel_depth = row_info->bit_depth;
157.5823 -         row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
157.5824 +         row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width);
157.5825        }
157.5826 +
157.5827        else if (row_info->color_type == PNG_COLOR_TYPE_PALETTE &&
157.5828 -         dither_lookup && row_info->bit_depth == 8)
157.5829 +         quantize_lookup)
157.5830        {
157.5831           sp = row;
157.5832 +
157.5833           for (i = 0; i < row_width; i++, sp++)
157.5834           {
157.5835 -            *sp = dither_lookup[*sp];
157.5836 +            *sp = quantize_lookup[*sp];
157.5837           }
157.5838        }
157.5839     }
157.5840  }
157.5841 -#endif
157.5842 -
157.5843 -#ifdef PNG_FLOATING_POINT_SUPPORTED
157.5844 -#if defined(PNG_READ_GAMMA_SUPPORTED)
157.5845 -static PNG_CONST int png_gamma_shift[] =
157.5846 -   {0x10, 0x21, 0x42, 0x84, 0x110, 0x248, 0x550, 0xff0, 0x00};
157.5847 -
157.5848 -/* We build the 8- or 16-bit gamma tables here.  Note that for 16-bit
157.5849 - * tables, we don't make a full table if we are reducing to 8-bit in
157.5850 - * the future.  Note also how the gamma_16 tables are segmented so that
157.5851 - * we don't need to allocate > 64K chunks for a full 16-bit table.
157.5852 - */
157.5853 -void /* PRIVATE */
157.5854 -png_build_gamma_table(png_structp png_ptr)
157.5855 -{
157.5856 -  png_debug(1, "in png_build_gamma_table\n");
157.5857 -
157.5858 -  if (png_ptr->bit_depth <= 8)
157.5859 -  {
157.5860 -     int i;
157.5861 -     double g;
157.5862 -
157.5863 -     if (png_ptr->screen_gamma > .000001)
157.5864 -        g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
157.5865 -     else
157.5866 -        g = 1.0;
157.5867 -
157.5868 -     png_ptr->gamma_table = (png_bytep)png_malloc(png_ptr,
157.5869 -        (png_uint_32)256);
157.5870 -
157.5871 -     for (i = 0; i < 256; i++)
157.5872 -     {
157.5873 -        png_ptr->gamma_table[i] = (png_byte)(pow((double)i / 255.0,
157.5874 -           g) * 255.0 + .5);
157.5875 -     }
157.5876 -
157.5877 -#if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
157.5878 -   defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
157.5879 -     if (png_ptr->transformations & ((PNG_BACKGROUND) | PNG_RGB_TO_GRAY))
157.5880 -     {
157.5881 -
157.5882 -        g = 1.0 / (png_ptr->gamma);
157.5883 -
157.5884 -        png_ptr->gamma_to_1 = (png_bytep)png_malloc(png_ptr,
157.5885 -           (png_uint_32)256);
157.5886 -
157.5887 -        for (i = 0; i < 256; i++)
157.5888 -        {
157.5889 -           png_ptr->gamma_to_1[i] = (png_byte)(pow((double)i / 255.0,
157.5890 -              g) * 255.0 + .5);
157.5891 -        }
157.5892 -
157.5893 -
157.5894 -        png_ptr->gamma_from_1 = (png_bytep)png_malloc(png_ptr,
157.5895 -           (png_uint_32)256);
157.5896 -
157.5897 -        if(png_ptr->screen_gamma > 0.000001)
157.5898 -           g = 1.0 / png_ptr->screen_gamma;
157.5899 -        else
157.5900 -           g = png_ptr->gamma;   /* probably doing rgb_to_gray */
157.5901 -
157.5902 -        for (i = 0; i < 256; i++)
157.5903 -        {
157.5904 -           png_ptr->gamma_from_1[i] = (png_byte)(pow((double)i / 255.0,
157.5905 -              g) * 255.0 + .5);
157.5906 -
157.5907 -        }
157.5908 -     }
157.5909 -#endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_RGB_TO_GRAY_SUPPORTED */
157.5910 -  }
157.5911 -  else
157.5912 -  {
157.5913 -     double g;
157.5914 -     int i, j, shift, num;
157.5915 -     int sig_bit;
157.5916 -     png_uint_32 ig;
157.5917 -
157.5918 -     if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
157.5919 -     {
157.5920 -        sig_bit = (int)png_ptr->sig_bit.red;
157.5921 -        if ((int)png_ptr->sig_bit.green > sig_bit)
157.5922 -           sig_bit = png_ptr->sig_bit.green;
157.5923 -        if ((int)png_ptr->sig_bit.blue > sig_bit)
157.5924 -           sig_bit = png_ptr->sig_bit.blue;
157.5925 -     }
157.5926 -     else
157.5927 -     {
157.5928 -        sig_bit = (int)png_ptr->sig_bit.gray;
157.5929 -     }
157.5930 -
157.5931 -     if (sig_bit > 0)
157.5932 -        shift = 16 - sig_bit;
157.5933 -     else
157.5934 -        shift = 0;
157.5935 -
157.5936 -     if (png_ptr->transformations & PNG_16_TO_8)
157.5937 -     {
157.5938 -        if (shift < (16 - PNG_MAX_GAMMA_8))
157.5939 -           shift = (16 - PNG_MAX_GAMMA_8);
157.5940 -     }
157.5941 -
157.5942 -     if (shift > 8)
157.5943 -        shift = 8;
157.5944 -     if (shift < 0)
157.5945 -        shift = 0;
157.5946 -
157.5947 -     png_ptr->gamma_shift = (png_byte)shift;
157.5948 -
157.5949 -     num = (1 << (8 - shift));
157.5950 -
157.5951 -     if (png_ptr->screen_gamma > .000001)
157.5952 -        g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
157.5953 -     else
157.5954 -        g = 1.0;
157.5955 -
157.5956 -     png_ptr->gamma_16_table = (png_uint_16pp)png_malloc(png_ptr,
157.5957 -        (png_uint_32)(num * png_sizeof (png_uint_16p)));
157.5958 -
157.5959 -     if (png_ptr->transformations & (PNG_16_TO_8 | PNG_BACKGROUND))
157.5960 -     {
157.5961 -        double fin, fout;
157.5962 -        png_uint_32 last, max;
157.5963 -
157.5964 -        for (i = 0; i < num; i++)
157.5965 -        {
157.5966 -           png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
157.5967 -              (png_uint_32)(256 * png_sizeof (png_uint_16)));
157.5968 -        }
157.5969 -
157.5970 -        g = 1.0 / g;
157.5971 -        last = 0;
157.5972 -        for (i = 0; i < 256; i++)
157.5973 -        {
157.5974 -           fout = ((double)i + 0.5) / 256.0;
157.5975 -           fin = pow(fout, g);
157.5976 -           max = (png_uint_32)(fin * (double)((png_uint_32)num << 8));
157.5977 -           while (last <= max)
157.5978 -           {
157.5979 -              png_ptr->gamma_16_table[(int)(last & (0xff >> shift))]
157.5980 -                 [(int)(last >> (8 - shift))] = (png_uint_16)(
157.5981 -                 (png_uint_16)i | ((png_uint_16)i << 8));
157.5982 -              last++;
157.5983 -           }
157.5984 -        }
157.5985 -        while (last < ((png_uint_32)num << 8))
157.5986 -        {
157.5987 -           png_ptr->gamma_16_table[(int)(last & (0xff >> shift))]
157.5988 -              [(int)(last >> (8 - shift))] = (png_uint_16)65535L;
157.5989 -           last++;
157.5990 -        }
157.5991 -     }
157.5992 -     else
157.5993 -     {
157.5994 -        for (i = 0; i < num; i++)
157.5995 -        {
157.5996 -           png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
157.5997 -              (png_uint_32)(256 * png_sizeof (png_uint_16)));
157.5998 -
157.5999 -           ig = (((png_uint_32)i * (png_uint_32)png_gamma_shift[shift]) >> 4);
157.6000 -           for (j = 0; j < 256; j++)
157.6001 -           {
157.6002 -              png_ptr->gamma_16_table[i][j] =
157.6003 -                 (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
157.6004 -                    65535.0, g) * 65535.0 + .5);
157.6005 -           }
157.6006 -        }
157.6007 -     }
157.6008 -
157.6009 -#if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
157.6010 -   defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
157.6011 -     if (png_ptr->transformations & (PNG_BACKGROUND | PNG_RGB_TO_GRAY))
157.6012 -     {
157.6013 -
157.6014 -        g = 1.0 / (png_ptr->gamma);
157.6015 -
157.6016 -        png_ptr->gamma_16_to_1 = (png_uint_16pp)png_malloc(png_ptr,
157.6017 -           (png_uint_32)(num * png_sizeof (png_uint_16p )));
157.6018 -
157.6019 -        for (i = 0; i < num; i++)
157.6020 -        {
157.6021 -           png_ptr->gamma_16_to_1[i] = (png_uint_16p)png_malloc(png_ptr,
157.6022 -              (png_uint_32)(256 * png_sizeof (png_uint_16)));
157.6023 -
157.6024 -           ig = (((png_uint_32)i *
157.6025 -              (png_uint_32)png_gamma_shift[shift]) >> 4);
157.6026 -           for (j = 0; j < 256; j++)
157.6027 -           {
157.6028 -              png_ptr->gamma_16_to_1[i][j] =
157.6029 -                 (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
157.6030 -                    65535.0, g) * 65535.0 + .5);
157.6031 -           }
157.6032 -        }
157.6033 -
157.6034 -        if(png_ptr->screen_gamma > 0.000001)
157.6035 -           g = 1.0 / png_ptr->screen_gamma;
157.6036 -        else
157.6037 -           g = png_ptr->gamma;   /* probably doing rgb_to_gray */
157.6038 -
157.6039 -        png_ptr->gamma_16_from_1 = (png_uint_16pp)png_malloc(png_ptr,
157.6040 -           (png_uint_32)(num * png_sizeof (png_uint_16p)));
157.6041 -
157.6042 -        for (i = 0; i < num; i++)
157.6043 -        {
157.6044 -           png_ptr->gamma_16_from_1[i] = (png_uint_16p)png_malloc(png_ptr,
157.6045 -              (png_uint_32)(256 * png_sizeof (png_uint_16)));
157.6046 -
157.6047 -           ig = (((png_uint_32)i *
157.6048 -              (png_uint_32)png_gamma_shift[shift]) >> 4);
157.6049 -           for (j = 0; j < 256; j++)
157.6050 -           {
157.6051 -              png_ptr->gamma_16_from_1[i][j] =
157.6052 -                 (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
157.6053 -                    65535.0, g) * 65535.0 + .5);
157.6054 -           }
157.6055 -        }
157.6056 -     }
157.6057 -#endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_RGB_TO_GRAY_SUPPORTED */
157.6058 -  }
157.6059 -}
157.6060 -#endif
157.6061 -/* To do: install integer version of png_build_gamma_table here */
157.6062 -#endif
157.6063 -
157.6064 -#if defined(PNG_MNG_FEATURES_SUPPORTED)
157.6065 -/* undoes intrapixel differencing  */
157.6066 +#endif /* PNG_READ_QUANTIZE_SUPPORTED */
157.6067 +#endif /* PNG_READ_TRANSFORMS_SUPPORTED */
157.6068 +
157.6069 +#ifdef PNG_MNG_FEATURES_SUPPORTED
157.6070 +/* Undoes intrapixel differencing  */
157.6071  void /* PRIVATE */
157.6072  png_do_read_intrapixel(png_row_infop row_info, png_bytep row)
157.6073  {
157.6074 -   png_debug(1, "in png_do_read_intrapixel\n");
157.6075 +   png_debug(1, "in png_do_read_intrapixel");
157.6076 +
157.6077     if (
157.6078 -#if defined(PNG_USELESS_TESTS_SUPPORTED)
157.6079 -       row != NULL && row_info != NULL &&
157.6080 -#endif
157.6081         (row_info->color_type & PNG_COLOR_MASK_COLOR))
157.6082     {
157.6083        int bytes_per_pixel;
157.6084        png_uint_32 row_width = row_info->width;
157.6085 +
157.6086        if (row_info->bit_depth == 8)
157.6087        {
157.6088           png_bytep rp;
157.6089 @@ -4233,15 +4935,17 @@
157.6090  
157.6091           if (row_info->color_type == PNG_COLOR_TYPE_RGB)
157.6092              bytes_per_pixel = 3;
157.6093 +
157.6094           else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
157.6095              bytes_per_pixel = 4;
157.6096 +
157.6097           else
157.6098              return;
157.6099  
157.6100           for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
157.6101           {
157.6102 -            *(rp) = (png_byte)((256 + *rp + *(rp+1))&0xff);
157.6103 -            *(rp+2) = (png_byte)((256 + *(rp+2) + *(rp+1))&0xff);
157.6104 +            *(rp) = (png_byte)((256 + *rp + *(rp + 1)) & 0xff);
157.6105 +            *(rp+2) = (png_byte)((256 + *(rp + 2) + *(rp + 1)) & 0xff);
157.6106           }
157.6107        }
157.6108        else if (row_info->bit_depth == 16)
157.6109 @@ -4251,22 +4955,24 @@
157.6110  
157.6111           if (row_info->color_type == PNG_COLOR_TYPE_RGB)
157.6112              bytes_per_pixel = 6;
157.6113 +
157.6114           else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
157.6115              bytes_per_pixel = 8;
157.6116 +
157.6117           else
157.6118              return;
157.6119  
157.6120           for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
157.6121           {
157.6122 -            png_uint_32 s0   = (*(rp  ) << 8) | *(rp+1);
157.6123 -            png_uint_32 s1   = (*(rp+2) << 8) | *(rp+3);
157.6124 -            png_uint_32 s2   = (*(rp+4) << 8) | *(rp+5);
157.6125 -            png_uint_32 red  = (png_uint_32)((s0+s1+65536L) & 0xffffL);
157.6126 -            png_uint_32 blue = (png_uint_32)((s2+s1+65536L) & 0xffffL);
157.6127 -            *(rp  ) = (png_byte)((red >> 8) & 0xff);
157.6128 -            *(rp+1) = (png_byte)(red & 0xff);
157.6129 -            *(rp+4) = (png_byte)((blue >> 8) & 0xff);
157.6130 -            *(rp+5) = (png_byte)(blue & 0xff);
157.6131 +            png_uint_32 s0   = (*(rp    ) << 8) | *(rp + 1);
157.6132 +            png_uint_32 s1   = (*(rp + 2) << 8) | *(rp + 3);
157.6133 +            png_uint_32 s2   = (*(rp + 4) << 8) | *(rp + 5);
157.6134 +            png_uint_32 red  = (png_uint_32)((s0 + s1 + 65536L) & 0xffffL);
157.6135 +            png_uint_32 blue = (png_uint_32)((s2 + s1 + 65536L) & 0xffffL);
157.6136 +            *(rp    ) = (png_byte)((red >> 8) & 0xff);
157.6137 +            *(rp + 1) = (png_byte)(red & 0xff);
157.6138 +            *(rp + 4) = (png_byte)((blue >> 8) & 0xff);
157.6139 +            *(rp + 5) = (png_byte)(blue & 0xff);
157.6140           }
157.6141        }
157.6142     }
   158.1 --- a/src/share/native/sun/awt/libpng/pngrutil.c	Fri Sep 30 17:20:56 2011 -0700
   158.2 +++ b/src/share/native/sun/awt/libpng/pngrutil.c	Tue Oct 04 12:39:42 2011 -0700
   158.3 @@ -29,106 +29,205 @@
   158.4   * However, the following notice accompanied the original version of this
   158.5   * file and, per its terms, should not be removed:
   158.6   *
   158.7 - * Last changed in libpng 1.2.17 May 15, 2007
   158.8 - * For conditions of distribution and use, see copyright notice in png.h
   158.9 - * Copyright (c) 1998-2007 Glenn Randers-Pehrson
  158.10 + * Last changed in libpng 1.5.4 [July 7, 2011]
  158.11 + * Copyright (c) 1998-2011 Glenn Randers-Pehrson
  158.12   * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
  158.13   * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
  158.14   *
  158.15 + * This code is released under the libpng license.
  158.16 + * For conditions of distribution and use, see the disclaimer
  158.17 + * and license in png.h
  158.18 + *
  158.19   * This file contains routines that are only called from within
  158.20   * libpng itself during the course of reading an image.
  158.21   */
  158.22  
  158.23 -#define PNG_INTERNAL
  158.24 -#include "png.h"
  158.25 -
  158.26 -#if defined(PNG_READ_SUPPORTED)
  158.27 -
  158.28 -#ifdef PNG_FLOATING_POINT_SUPPORTED
  158.29 -#  if defined(_WIN32_WCE)
  158.30 -/* strtod() function is not supported on WindowsCE */
  158.31 -__inline double png_strtod(png_structp png_ptr, const char *nptr, char **endptr)
  158.32 +#include "pngpriv.h"
  158.33 +
  158.34 +#ifdef PNG_READ_SUPPORTED
  158.35 +
  158.36 +#define png_strtod(p,a,b) strtod(a,b)
  158.37 +
  158.38 +png_uint_32 PNGAPI
  158.39 +png_get_uint_31(png_structp png_ptr, png_const_bytep buf)
  158.40  {
  158.41 -   double result = 0;
  158.42 -   int len;
  158.43 -   wchar_t *str, *end;
  158.44 -
  158.45 -   len = MultiByteToWideChar(CP_ACP, 0, nptr, -1, NULL, 0);
  158.46 -   str = (wchar_t *)png_malloc(png_ptr, len * sizeof(wchar_t));
  158.47 -   if ( NULL != str )
  158.48 +   png_uint_32 uval = png_get_uint_32(buf);
  158.49 +
  158.50 +   if (uval > PNG_UINT_31_MAX)
  158.51 +      png_error(png_ptr, "PNG unsigned integer out of range");
  158.52 +
  158.53 +   return (uval);
  158.54 +}
  158.55 +
  158.56 +#if defined(PNG_READ_gAMA_SUPPORTED) || defined(PNG_READ_cHRM_SUPPORTED)
  158.57 +/* The following is a variation on the above for use with the fixed
  158.58 + * point values used for gAMA and cHRM.  Instead of png_error it
  158.59 + * issues a warning and returns (-1) - an invalid value because both
  158.60 + * gAMA and cHRM use *unsigned* integers for fixed point values.
  158.61 + */
  158.62 +#define PNG_FIXED_ERROR (-1)
  158.63 +
  158.64 +static png_fixed_point /* PRIVATE */
  158.65 +png_get_fixed_point(png_structp png_ptr, png_const_bytep buf)
  158.66 +{
  158.67 +   png_uint_32 uval = png_get_uint_32(buf);
  158.68 +
  158.69 +   if (uval <= PNG_UINT_31_MAX)
  158.70 +      return (png_fixed_point)uval; /* known to be in range */
  158.71 +
  158.72 +   /* The caller can turn off the warning by passing NULL. */
  158.73 +   if (png_ptr != NULL)
  158.74 +      png_warning(png_ptr, "PNG fixed point integer out of range");
  158.75 +
  158.76 +   return PNG_FIXED_ERROR;
  158.77 +}
  158.78 +#endif
  158.79 +
  158.80 +#ifdef PNG_READ_INT_FUNCTIONS_SUPPORTED
  158.81 +/* NOTE: the read macros will obscure these definitions, so that if
  158.82 + * PNG_USE_READ_MACROS is set the library will not use them internally,
  158.83 + * but the APIs will still be available externally.
  158.84 + *
  158.85 + * The parentheses around "PNGAPI function_name" in the following three
  158.86 + * functions are necessary because they allow the macros to co-exist with
  158.87 + * these (unused but exported) functions.
  158.88 + */
  158.89 +
  158.90 +/* Grab an unsigned 32-bit integer from a buffer in big-endian format. */
  158.91 +png_uint_32 (PNGAPI
  158.92 +png_get_uint_32)(png_const_bytep buf)
  158.93 +{
  158.94 +   png_uint_32 uval =
  158.95 +       ((png_uint_32)(*(buf    )) << 24) +
  158.96 +       ((png_uint_32)(*(buf + 1)) << 16) +
  158.97 +       ((png_uint_32)(*(buf + 2)) <<  8) +
  158.98 +       ((png_uint_32)(*(buf + 3))      ) ;
  158.99 +
 158.100 +   return uval;
 158.101 +}
 158.102 +
 158.103 +/* Grab a signed 32-bit integer from a buffer in big-endian format.  The
 158.104 + * data is stored in the PNG file in two's complement format and there
 158.105 + * is no guarantee that a 'png_int_32' is exactly 32 bits, therefore
 158.106 + * the following code does a two's complement to native conversion.
 158.107 + */
 158.108 +png_int_32 (PNGAPI
 158.109 +png_get_int_32)(png_const_bytep buf)
 158.110 +{
 158.111 +   png_uint_32 uval = png_get_uint_32(buf);
 158.112 +   if ((uval & 0x80000000L) == 0) /* non-negative */
 158.113 +      return uval;
 158.114 +
 158.115 +   uval = (uval ^ 0xffffffffL) + 1;  /* 2's complement: -x = ~x+1 */
 158.116 +   return -(png_int_32)uval;
 158.117 +}
 158.118 +
 158.119 +/* Grab an unsigned 16-bit integer from a buffer in big-endian format. */
 158.120 +png_uint_16 (PNGAPI
 158.121 +png_get_uint_16)(png_const_bytep buf)
 158.122 +{
 158.123 +   /* ANSI-C requires an int value to accomodate at least 16 bits so this
 158.124 +    * works and allows the compiler not to worry about possible narrowing
 158.125 +    * on 32 bit systems.  (Pre-ANSI systems did not make integers smaller
 158.126 +    * than 16 bits either.)
 158.127 +    */
 158.128 +   unsigned int val =
 158.129 +       ((unsigned int)(*buf) << 8) +
 158.130 +       ((unsigned int)(*(buf + 1)));
 158.131 +
 158.132 +   return (png_uint_16)val;
 158.133 +}
 158.134 +
 158.135 +#endif /* PNG_READ_INT_FUNCTIONS_SUPPORTED */
 158.136 +
 158.137 +/* Read and check the PNG file signature */
 158.138 +void /* PRIVATE */
 158.139 +png_read_sig(png_structp png_ptr, png_infop info_ptr)
 158.140 +{
 158.141 +   png_size_t num_checked, num_to_check;
 158.142 +
 158.143 +   /* Exit if the user application does not expect a signature. */
 158.144 +   if (png_ptr->sig_bytes >= 8)
 158.145 +      return;
 158.146 +
 158.147 +   num_checked = png_ptr->sig_bytes;
 158.148 +   num_to_check = 8 - num_checked;
 158.149 +
 158.150 +#ifdef PNG_IO_STATE_SUPPORTED
 158.151 +   png_ptr->io_state = PNG_IO_READING | PNG_IO_SIGNATURE;
 158.152 +#endif
 158.153 +
 158.154 +   /* The signature must be serialized in a single I/O call. */
 158.155 +   png_read_data(png_ptr, &(info_ptr->signature[num_checked]), num_to_check);
 158.156 +   png_ptr->sig_bytes = 8;
 158.157 +
 158.158 +   if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
 158.159     {
 158.160 -      MultiByteToWideChar(CP_ACP, 0, nptr, -1, str, len);
 158.161 -      result = wcstod(str, &end);
 158.162 -      len = WideCharToMultiByte(CP_ACP, 0, end, -1, NULL, 0, NULL, NULL);
 158.163 -      *endptr = (char *)nptr + (png_strlen(nptr) - len + 1);
 158.164 -      png_free(str);
 158.165 +      if (num_checked < 4 &&
 158.166 +          png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
 158.167 +         png_error(png_ptr, "Not a PNG file");
 158.168 +      else
 158.169 +         png_error(png_ptr, "PNG file corrupted by ASCII conversion");
 158.170     }
 158.171 -   return result;
 158.172 +   if (num_checked < 3)
 158.173 +      png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
 158.174  }
 158.175 -#  else
 158.176 -#    define png_strtod(p,a,b) strtod(a,b)
 158.177 -#  endif
 158.178 +
 158.179 +/* Read the chunk header (length + type name).
 158.180 + * Put the type name into png_ptr->chunk_name, and return the length.
 158.181 + */
 158.182 +png_uint_32 /* PRIVATE */
 158.183 +png_read_chunk_header(png_structp png_ptr)
 158.184 +{
 158.185 +   png_byte buf[8];
 158.186 +   png_uint_32 length;
 158.187 +
 158.188 +#ifdef PNG_IO_STATE_SUPPORTED
 158.189 +   png_ptr->io_state = PNG_IO_READING | PNG_IO_CHUNK_HDR;
 158.190  #endif
 158.191  
 158.192 -png_uint_32 PNGAPI
 158.193 -png_get_uint_31(png_structp png_ptr, png_bytep buf)
 158.194 -{
 158.195 -   png_uint_32 i = png_get_uint_32(buf);
 158.196 -   if (i > PNG_UINT_31_MAX)
 158.197 -     png_error(png_ptr, "PNG unsigned integer out of range.");
 158.198 -   return (i);
 158.199 +   /* Read the length and the chunk name.
 158.200 +    * This must be performed in a single I/O call.
 158.201 +    */
 158.202 +   png_read_data(png_ptr, buf, 8);
 158.203 +   length = png_get_uint_31(png_ptr, buf);
 158.204 +
 158.205 +   /* Put the chunk name into png_ptr->chunk_name. */
 158.206 +   png_memcpy(png_ptr->chunk_name, buf + 4, 4);
 158.207 +
 158.208 +   png_debug2(0, "Reading %s chunk, length = %u",
 158.209 +       png_ptr->chunk_name, length);
 158.210 +
 158.211 +   /* Reset the crc and run it over the chunk name. */
 158.212 +   png_reset_crc(png_ptr);
 158.213 +   png_calculate_crc(png_ptr, png_ptr->chunk_name, 4);
 158.214 +
 158.215 +   /* Check to see if chunk name is valid. */
 158.216 +   png_check_chunk_name(png_ptr, png_ptr->chunk_name);
 158.217 +
 158.218 +#ifdef PNG_IO_STATE_SUPPORTED
 158.219 +   png_ptr->io_state = PNG_IO_READING | PNG_IO_CHUNK_DATA;
 158.220 +#endif
 158.221 +
 158.222 +   return length;
 158.223  }
 158.224 -#ifndef PNG_READ_BIG_ENDIAN_SUPPORTED
 158.225 -/* Grab an unsigned 32-bit integer from a buffer in big-endian format. */
 158.226 -png_uint_32 PNGAPI
 158.227 -png_get_uint_32(png_bytep buf)
 158.228 -{
 158.229 -   png_uint_32 i = ((png_uint_32)(*buf) << 24) +
 158.230 -      ((png_uint_32)(*(buf + 1)) << 16) +
 158.231 -      ((png_uint_32)(*(buf + 2)) << 8) +
 158.232 -      (png_uint_32)(*(buf + 3));
 158.233 -
 158.234 -   return (i);
 158.235 -}
 158.236 -
 158.237 -/* Grab a signed 32-bit integer from a buffer in big-endian format.  The
 158.238 - * data is stored in the PNG file in two's complement format, and it is
 158.239 - * assumed that the machine format for signed integers is the same. */
 158.240 -png_int_32 PNGAPI
 158.241 -png_get_int_32(png_bytep buf)
 158.242 -{
 158.243 -   png_int_32 i = ((png_int_32)(*buf) << 24) +
 158.244 -      ((png_int_32)(*(buf + 1)) << 16) +
 158.245 -      ((png_int_32)(*(buf + 2)) << 8) +
 158.246 -      (png_int_32)(*(buf + 3));
 158.247 -
 158.248 -   return (i);
 158.249 -}
 158.250 -
 158.251 -/* Grab an unsigned 16-bit integer from a buffer in big-endian format. */
 158.252 -png_uint_16 PNGAPI
 158.253 -png_get_uint_16(png_bytep buf)
 158.254 -{
 158.255 -   png_uint_16 i = (png_uint_16)(((png_uint_16)(*buf) << 8) +
 158.256 -      (png_uint_16)(*(buf + 1)));
 158.257 -
 158.258 -   return (i);
 158.259 -}
 158.260 -#endif /* PNG_READ_BIG_ENDIAN_SUPPORTED */
 158.261  
 158.262  /* Read data, and (optionally) run it through the CRC. */
 158.263  void /* PRIVATE */
 158.264  png_crc_read(png_structp png_ptr, png_bytep buf, png_size_t length)
 158.265  {
 158.266 -   if(png_ptr == NULL) return;
 158.267 +   if (png_ptr == NULL)
 158.268 +      return;
 158.269 +
 158.270     png_read_data(png_ptr, buf, length);
 158.271     png_calculate_crc(png_ptr, buf, length);
 158.272  }
 158.273  
 158.274  /* Optionally skip data and then check the CRC.  Depending on whether we
 158.275 -   are reading a ancillary or critical chunk, and how the program has set
 158.276 -   things up, we may calculate the CRC on the data and print a message.
 158.277 -   Returns '1' if there was a CRC error, '0' otherwise. */
 158.278 + * are reading a ancillary or critical chunk, and how the program has set
 158.279 + * things up, we may calculate the CRC on the data and print a message.
 158.280 + * Returns '1' if there was a CRC error, '0' otherwise.
 158.281 + */
 158.282  int /* PRIVATE */
 158.283  png_crc_finish(png_structp png_ptr, png_uint_32 skip)
 158.284  {
 158.285 @@ -139,6 +238,7 @@
 158.286     {
 158.287        png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
 158.288     }
 158.289 +
 158.290     if (i)
 158.291     {
 158.292        png_crc_read(png_ptr, png_ptr->zbuf, i);
 158.293 @@ -147,16 +247,19 @@
 158.294     if (png_crc_error(png_ptr))
 158.295     {
 158.296        if (((png_ptr->chunk_name[0] & 0x20) &&                /* Ancillary */
 158.297 -           !(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)) ||
 158.298 +          !(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)) ||
 158.299            (!(png_ptr->chunk_name[0] & 0x20) &&             /* Critical  */
 158.300            (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_USE)))
 158.301        {
 158.302           png_chunk_warning(png_ptr, "CRC error");
 158.303        }
 158.304 +
 158.305        else
 158.306        {
 158.307 -         png_chunk_error(png_ptr, "CRC error");
 158.308 +         png_chunk_benign_error(png_ptr, "CRC error");
 158.309 +         return (0);
 158.310        }
 158.311 +
 158.312        return (1);
 158.313     }
 158.314  
 158.315 @@ -164,7 +267,8 @@
 158.316  }
 158.317  
 158.318  /* Compare the CRC stored in the PNG file with that calculated by libpng from
 158.319 -   the data it has read thus far. */
 158.320 + * the data it has read thus far.
 158.321 + */
 158.322  int /* PRIVATE */
 158.323  png_crc_error(png_structp png_ptr)
 158.324  {
 158.325 @@ -178,12 +282,18 @@
 158.326            (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
 158.327           need_crc = 0;
 158.328     }
 158.329 +
 158.330     else                                                    /* critical */
 158.331     {
 158.332        if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
 158.333           need_crc = 0;
 158.334     }
 158.335  
 158.336 +#ifdef PNG_IO_STATE_SUPPORTED
 158.337 +   png_ptr->io_state = PNG_IO_READING | PNG_IO_CHUNK_CRC;
 158.338 +#endif
 158.339 +
 158.340 +   /* The chunk CRC must be serialized in a single I/O call. */
 158.341     png_read_data(png_ptr, crc_bytes, 4);
 158.342  
 158.343     if (need_crc)
 158.344 @@ -191,12 +301,135 @@
 158.345        crc = png_get_uint_32(crc_bytes);
 158.346        return ((int)(crc != png_ptr->crc));
 158.347     }
 158.348 +
 158.349     else
 158.350        return (0);
 158.351  }
 158.352  
 158.353 -#if defined(PNG_READ_zTXt_SUPPORTED) || defined(PNG_READ_iTXt_SUPPORTED) || \
 158.354 -    defined(PNG_READ_iCCP_SUPPORTED)
 158.355 +#ifdef PNG_READ_COMPRESSED_TEXT_SUPPORTED
 158.356 +static png_size_t
 158.357 +png_inflate(png_structp png_ptr, png_bytep data, png_size_t size,
 158.358 +    png_bytep output, png_size_t output_size)
 158.359 +{
 158.360 +   png_size_t count = 0;
 158.361 +
 158.362 +   /* zlib can't necessarily handle more than 65535 bytes at once (i.e. it can't
 158.363 +    * even necessarily handle 65536 bytes) because the type uInt is "16 bits or
 158.364 +    * more".  Consequently it is necessary to chunk the input to zlib.  This
 158.365 +    * code uses ZLIB_IO_MAX, from pngpriv.h, as the maximum (the maximum value
 158.366 +    * that can be stored in a uInt.)  It is possible to set ZLIB_IO_MAX to a
 158.367 +    * lower value in pngpriv.h and this may sometimes have a performance
 158.368 +    * advantage, because it forces access of the input data to be separated from
 158.369 +    * at least some of the use by some period of time.
 158.370 +    */
 158.371 +   png_ptr->zstream.next_in = data;
 158.372 +   /* avail_in is set below from 'size' */
 158.373 +   png_ptr->zstream.avail_in = 0;
 158.374 +
 158.375 +   while (1)
 158.376 +   {
 158.377 +      int ret, avail;
 158.378 +
 158.379 +      /* The setting of 'avail_in' used to be outside the loop, by setting it
 158.380 +       * inside it is possible to chunk the input to zlib and simply rely on
 158.381 +       * zlib to advance the 'next_in' pointer.  This allows arbitrary amounts o
 158.382 +       * data to be passed through zlib at the unavoidable cost of requiring a
 158.383 +       * window save (memcpy of up to 32768 output bytes) every ZLIB_IO_MAX
 158.384 +       * input bytes.
 158.385 +       */
 158.386 +      if (png_ptr->zstream.avail_in == 0 && size > 0)
 158.387 +      {
 158.388 +         if (size <= ZLIB_IO_MAX)
 158.389 +         {
 158.390 +            /* The value is less than ZLIB_IO_MAX so the cast is safe: */
 158.391 +            png_ptr->zstream.avail_in = (uInt)size;
 158.392 +            size = 0;
 158.393 +         }
 158.394 +
 158.395 +         else
 158.396 +         {
 158.397 +            png_ptr->zstream.avail_in = ZLIB_IO_MAX;
 158.398 +            size -= ZLIB_IO_MAX;
 158.399 +         }
 158.400 +      }
 158.401 +
 158.402 +      /* Reset the output buffer each time round - we empty it
 158.403 +       * after every inflate call.
 158.404 +       */
 158.405 +      png_ptr->zstream.next_out = png_ptr->zbuf;
 158.406 +      png_ptr->zstream.avail_out = png_ptr->zbuf_size;
 158.407 +
 158.408 +      ret = inflate(&png_ptr->zstream, Z_NO_FLUSH);
 158.409 +      avail = png_ptr->zbuf_size - png_ptr->zstream.avail_out;
 158.410 +
 158.411 +      /* First copy/count any new output - but only if we didn't
 158.412 +       * get an error code.
 158.413 +       */
 158.414 +      if ((ret == Z_OK || ret == Z_STREAM_END) && avail > 0)
 158.415 +      {
 158.416 +         png_size_t space = avail; /* > 0, see above */
 158.417 +
 158.418 +         if (output != 0 && output_size > count)
 158.419 +         {
 158.420 +            png_size_t copy = output_size - count;
 158.421 +
 158.422 +            if (space < copy)
 158.423 +               copy = space;
 158.424 +
 158.425 +            png_memcpy(output + count, png_ptr->zbuf, copy);
 158.426 +         }
 158.427 +         count += space;
 158.428 +      }
 158.429 +
 158.430 +      if (ret == Z_OK)
 158.431 +         continue;
 158.432 +
 158.433 +      /* Termination conditions - always reset the zstream, it
 158.434 +       * must be left in inflateInit state.
 158.435 +       */
 158.436 +      png_ptr->zstream.avail_in = 0;
 158.437 +      inflateReset(&png_ptr->zstream);
 158.438 +
 158.439 +      if (ret == Z_STREAM_END)
 158.440 +         return count; /* NOTE: may be zero. */
 158.441 +
 158.442 +      /* Now handle the error codes - the API always returns 0
 158.443 +       * and the error message is dumped into the uncompressed
 158.444 +       * buffer if available.
 158.445 +       */
 158.446 +#     ifdef PNG_WARNINGS_SUPPORTED
 158.447 +      {
 158.448 +         png_const_charp msg;
 158.449 +
 158.450 +         if (png_ptr->zstream.msg != 0)
 158.451 +            msg = png_ptr->zstream.msg;
 158.452 +
 158.453 +         else switch (ret)
 158.454 +         {
 158.455 +            case Z_BUF_ERROR:
 158.456 +               msg = "Buffer error in compressed datastream";
 158.457 +               break;
 158.458 +
 158.459 +            case Z_DATA_ERROR:
 158.460 +               msg = "Data error in compressed datastream";
 158.461 +               break;
 158.462 +
 158.463 +            default:
 158.464 +               msg = "Incomplete compressed datastream";
 158.465 +               break;
 158.466 +         }
 158.467 +
 158.468 +         png_chunk_warning(png_ptr, msg);
 158.469 +      }
 158.470 +#     endif
 158.471 +
 158.472 +      /* 0 means an error - notice that this code simply ignores
 158.473 +       * zero length compressed chunks as a result.
 158.474 +       */
 158.475 +      return 0;
 158.476 +   }
 158.477 +}
 158.478 +
 158.479  /*
 158.480   * Decompress trailing data in a chunk.  The assumption is that chunkdata
 158.481   * points at an allocated area holding the contents of a chunk with a
 158.482 @@ -204,166 +437,119 @@
 158.483   * holding the original prefix part and an uncompressed version of the
 158.484   * trailing part (the malloc area passed in is freed).
 158.485   */
 158.486 -png_charp /* PRIVATE */
 158.487 +void /* PRIVATE */
 158.488  png_decompress_chunk(png_structp png_ptr, int comp_type,
 158.489 -                              png_charp chunkdata, png_size_t chunklength,
 158.490 -                              png_size_t prefix_size, png_size_t *newlength)
 158.491 +    png_size_t chunklength,
 158.492 +    png_size_t prefix_size, png_size_t *newlength)
 158.493  {
 158.494 -   static PNG_CONST char msg[] = "Error decoding compressed text";
 158.495 -   png_charp text;
 158.496 -   png_size_t text_size;
 158.497 -
 158.498 -   if (comp_type == PNG_COMPRESSION_TYPE_BASE)
 158.499 +   /* The caller should guarantee this */
 158.500 +   if (prefix_size > chunklength)
 158.501     {
 158.502 -      int ret = Z_OK;
 158.503 -      png_ptr->zstream.next_in = (png_bytep)(chunkdata + prefix_size);
 158.504 -      png_ptr->zstream.avail_in = (uInt)(chunklength - prefix_size);
 158.505 -      png_ptr->zstream.next_out = png_ptr->zbuf;
 158.506 -      png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
 158.507 -
 158.508 -      text_size = 0;
 158.509 -      text = NULL;
 158.510 -
 158.511 -      while (png_ptr->zstream.avail_in)
 158.512 +      /* The recovery is to delete the chunk. */
 158.513 +      png_warning(png_ptr, "invalid chunklength");
 158.514 +      prefix_size = 0; /* To delete everything */
 158.515 +   }
 158.516 +
 158.517 +   else if (comp_type == PNG_COMPRESSION_TYPE_BASE)
 158.518 +   {
 158.519 +      png_size_t expanded_size = png_inflate(png_ptr,
 158.520 +          (png_bytep)(png_ptr->chunkdata + prefix_size),
 158.521 +          chunklength - prefix_size,
 158.522 +          0,            /* output */
 158.523 +          0);           /* output size */
 158.524 +
 158.525 +      /* Now check the limits on this chunk - if the limit fails the
 158.526 +       * compressed data will be removed, the prefix will remain.
 158.527 +       */
 158.528 +#ifdef PNG_SET_CHUNK_MALLOC_LIMIT_SUPPORTED
 158.529 +      if (png_ptr->user_chunk_malloc_max &&
 158.530 +          (prefix_size + expanded_size >= png_ptr->user_chunk_malloc_max - 1))
 158.531 +#else
 158.532 +#  ifdef PNG_USER_CHUNK_MALLOC_MAX
 158.533 +      if ((PNG_USER_CHUNK_MALLOC_MAX > 0) &&
 158.534 +          prefix_size + expanded_size >= PNG_USER_CHUNK_MALLOC_MAX - 1)
 158.535 +#  endif
 158.536 +#endif
 158.537 +         png_warning(png_ptr, "Exceeded size limit while expanding chunk");
 158.538 +
 158.539 +      /* If the size is zero either there was an error and a message
 158.540 +       * has already been output (warning) or the size really is zero
 158.541 +       * and we have nothing to do - the code will exit through the
 158.542 +       * error case below.
 158.543 +       */
 158.544 +#if defined(PNG_SET_CHUNK_MALLOC_LIMIT_SUPPORTED) || \
 158.545 +    defined(PNG_USER_CHUNK_MALLOC_MAX)
 158.546 +      else if (expanded_size > 0)
 158.547 +#else
 158.548 +      if (expanded_size > 0)
 158.549 +#endif
 158.550        {
 158.551 -         ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
 158.552 -         if (ret != Z_OK && ret != Z_STREAM_END)
 158.553 +         /* Success (maybe) - really uncompress the chunk. */
 158.554 +         png_size_t new_size = 0;
 158.555 +         png_charp text = png_malloc_warn(png_ptr,
 158.556 +             prefix_size + expanded_size + 1);
 158.557 +
 158.558 +         if (text != NULL)
 158.559           {
 158.560 -            if (png_ptr->zstream.msg != NULL)
 158.561 -               png_warning(png_ptr, png_ptr->zstream.msg);
 158.562 -            else
 158.563 -               png_warning(png_ptr, msg);
 158.564 -            inflateReset(&png_ptr->zstream);
 158.565 -            png_ptr->zstream.avail_in = 0;
 158.566 -
 158.567 -            if (text ==  NULL)
 158.568 +            png_memcpy(text, png_ptr->chunkdata, prefix_size);
 158.569 +            new_size = png_inflate(png_ptr,
 158.570 +                (png_bytep)(png_ptr->chunkdata + prefix_size),
 158.571 +                chunklength - prefix_size,
 158.572 +                (png_bytep)(text + prefix_size), expanded_size);
 158.573 +            text[prefix_size + expanded_size] = 0; /* just in case */
 158.574 +
 158.575 +            if (new_size == expanded_size)
 158.576              {
 158.577 -               text_size = prefix_size + png_sizeof(msg) + 1;
 158.578 -               text = (png_charp)png_malloc_warn(png_ptr, text_size);
 158.579 -               if (text ==  NULL)
 158.580 -                 {
 158.581 -                    png_free(png_ptr,chunkdata);
 158.582 -                    png_error(png_ptr,"Not enough memory to decompress chunk");
 158.583 -                 }
 158.584 -               png_memcpy(text, chunkdata, prefix_size);
 158.585 +               png_free(png_ptr, png_ptr->chunkdata);
 158.586 +               png_ptr->chunkdata = text;
 158.587 +               *newlength = prefix_size + expanded_size;
 158.588 +               return; /* The success return! */
 158.589              }
 158.590  
 158.591 -            text[text_size - 1] = 0x00;
 158.592 -
 158.593 -            /* Copy what we can of the error message into the text chunk */
 158.594 -            text_size = (png_size_t)(chunklength - (text - chunkdata) - 1);
 158.595 -            text_size = png_sizeof(msg) > text_size ? text_size :
 158.596 -               png_sizeof(msg);
 158.597 -            png_memcpy(text + prefix_size, msg, text_size + 1);
 158.598 -            break;
 158.599 +            png_warning(png_ptr, "png_inflate logic error");
 158.600 +            png_free(png_ptr, text);
 158.601           }
 158.602 -         if (!png_ptr->zstream.avail_out || ret == Z_STREAM_END)
 158.603 -         {
 158.604 -            if (text == NULL)
 158.605 -            {
 158.606 -               text_size = prefix_size +
 158.607 -                   png_ptr->zbuf_size - png_ptr->zstream.avail_out;
 158.608 -               text = (png_charp)png_malloc_warn(png_ptr, text_size + 1);
 158.609 -               if (text ==  NULL)
 158.610 -                 {
 158.611 -                    png_free(png_ptr,chunkdata);
 158.612 -                    png_error(png_ptr,"Not enough memory to decompress chunk.");
 158.613 -                 }
 158.614 -               png_memcpy(text + prefix_size, png_ptr->zbuf,
 158.615 -                    text_size - prefix_size);
 158.616 -               png_memcpy(text, chunkdata, prefix_size);
 158.617 -               *(text + text_size) = 0x00;
 158.618 -            }
 158.619 -            else
 158.620 -            {
 158.621 -               png_charp tmp;
 158.622 -
 158.623 -               tmp = text;
 158.624 -               text = (png_charp)png_malloc_warn(png_ptr,
 158.625 -                  (png_uint_32)(text_size +
 158.626 -                  png_ptr->zbuf_size - png_ptr->zstream.avail_out + 1));
 158.627 -               if (text == NULL)
 158.628 -               {
 158.629 -                  png_free(png_ptr, tmp);
 158.630 -                  png_free(png_ptr, chunkdata);
 158.631 -                  png_error(png_ptr,"Not enough memory to decompress chunk..");
 158.632 -               }
 158.633 -               png_memcpy(text, tmp, text_size);
 158.634 -               png_free(png_ptr, tmp);
 158.635 -               png_memcpy(text + text_size, png_ptr->zbuf,
 158.636 -                  (png_ptr->zbuf_size - png_ptr->zstream.avail_out));
 158.637 -               text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out;
 158.638 -               *(text + text_size) = 0x00;
 158.639 -            }
 158.640 -            if (ret == Z_STREAM_END)
 158.641 -               break;
 158.642 -            else
 158.643 -            {
 158.644 -               png_ptr->zstream.next_out = png_ptr->zbuf;
 158.645 -               png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
 158.646 -            }
 158.647 -         }
 158.648 +
 158.649 +         else
 158.650 +            png_warning(png_ptr, "Not enough memory to decompress chunk");
 158.651        }
 158.652 -      if (ret != Z_STREAM_END)
 158.653 -      {
 158.654 -#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
 158.655 -         char umsg[52];
 158.656 -
 158.657 -         if (ret == Z_BUF_ERROR)
 158.658 -            sprintf(umsg,"Buffer error in compressed datastream in %s chunk",
 158.659 -                png_ptr->chunk_name);
 158.660 -         else if (ret == Z_DATA_ERROR)
 158.661 -            sprintf(umsg,"Data error in compressed datastream in %s chunk",
 158.662 -                png_ptr->chunk_name);
 158.663 -         else
 158.664 -            sprintf(umsg,"Incomplete compressed datastream in %s chunk",
 158.665 -                png_ptr->chunk_name);
 158.666 -         png_warning(png_ptr, umsg);
 158.667 -#else
 158.668 -         png_warning(png_ptr,
 158.669 -            "Incomplete compressed datastream in chunk other than IDAT");
 158.670 -#endif
 158.671 -         text_size=prefix_size;
 158.672 -         if (text ==  NULL)
 158.673 -         {
 158.674 -            text = (png_charp)png_malloc_warn(png_ptr, text_size+1);
 158.675 -            if (text == NULL)
 158.676 -              {
 158.677 -                png_free(png_ptr, chunkdata);
 158.678 -                png_error(png_ptr,"Not enough memory for text.");
 158.679 -              }
 158.680 -            png_memcpy(text, chunkdata, prefix_size);
 158.681 -         }
 158.682 -         *(text + text_size) = 0x00;
 158.683 -      }
 158.684 -
 158.685 -      inflateReset(&png_ptr->zstream);
 158.686 -      png_ptr->zstream.avail_in = 0;
 158.687 -
 158.688 -      png_free(png_ptr, chunkdata);
 158.689 -      chunkdata = text;
 158.690 -      *newlength=text_size;
 158.691     }
 158.692 +
 158.693     else /* if (comp_type != PNG_COMPRESSION_TYPE_BASE) */
 158.694     {
 158.695 -#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
 158.696 -      char umsg[50];
 158.697 -
 158.698 -      sprintf(umsg, "Unknown zTXt compression type %d", comp_type);
 158.699 -      png_warning(png_ptr, umsg);
 158.700 -#else
 158.701 -      png_warning(png_ptr, "Unknown zTXt compression type");
 158.702 -#endif
 158.703 -
 158.704 -      *(chunkdata + prefix_size) = 0x00;
 158.705 -      *newlength=prefix_size;
 158.706 +      PNG_WARNING_PARAMETERS(p)
 158.707 +      png_warning_parameter_signed(p, 1, PNG_NUMBER_FORMAT_d, comp_type);
 158.708 +      png_formatted_warning(png_ptr, p, "Unknown zTXt compression type @1");
 158.709 +
 158.710 +      /* The recovery is to simply drop the data. */
 158.711     }
 158.712  
 158.713 -   return chunkdata;
 158.714 +   /* Generic error return - leave the prefix, delete the compressed
 158.715 +    * data, reallocate the chunkdata to remove the potentially large
 158.716 +    * amount of compressed data.
 158.717 +    */
 158.718 +   {
 158.719 +      png_charp text = png_malloc_warn(png_ptr, prefix_size + 1);
 158.720 +
 158.721 +      if (text != NULL)
 158.722 +      {
 158.723 +         if (prefix_size > 0)
 158.724 +            png_memcpy(text, png_ptr->chunkdata, prefix_size);
 158.725 +
 158.726 +         png_free(png_ptr, png_ptr->chunkdata);
 158.727 +         png_ptr->chunkdata = text;
 158.728 +
 158.729 +         /* This is an extra zero in the 'uncompressed' part. */
 158.730 +         *(png_ptr->chunkdata + prefix_size) = 0x00;
 158.731 +      }
 158.732 +      /* Ignore a malloc error here - it is safe. */
 158.733 +   }
 158.734 +
 158.735 +   *newlength = prefix_size;
 158.736  }
 158.737 -#endif
 158.738 -
 158.739 -/* read and check the IDHR chunk */
 158.740 +#endif /* PNG_READ_COMPRESSED_TEXT_SUPPORTED */
 158.741 +
 158.742 +/* Read and check the IDHR chunk */
 158.743  void /* PRIVATE */
 158.744  png_handle_IHDR(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
 158.745  {
 158.746 @@ -372,12 +558,12 @@
 158.747     int bit_depth, color_type, compression_type, filter_type;
 158.748     int interlace_type;
 158.749  
 158.750 -   png_debug(1, "in png_handle_IHDR\n");
 158.751 +   png_debug(1, "in png_handle_IHDR");
 158.752  
 158.753     if (png_ptr->mode & PNG_HAVE_IHDR)
 158.754        png_error(png_ptr, "Out of place IHDR");
 158.755  
 158.756 -   /* check the length */
 158.757 +   /* Check the length */
 158.758     if (length != 13)
 158.759        png_error(png_ptr, "Invalid IHDR chunk");
 158.760  
 158.761 @@ -394,66 +580,72 @@
 158.762     filter_type = buf[11];
 158.763     interlace_type = buf[12];
 158.764  
 158.765 -   /* set internal variables */
 158.766 +   /* Set internal variables */
 158.767     png_ptr->width = width;
 158.768     png_ptr->height = height;
 158.769     png_ptr->bit_depth = (png_byte)bit_depth;
 158.770     png_ptr->interlaced = (png_byte)interlace_type;
 158.771     png_ptr->color_type = (png_byte)color_type;
 158.772 -#if defined(PNG_MNG_FEATURES_SUPPORTED)
 158.773 +#ifdef PNG_MNG_FEATURES_SUPPORTED
 158.774     png_ptr->filter_type = (png_byte)filter_type;
 158.775  #endif
 158.776     png_ptr->compression_type = (png_byte)compression_type;
 158.777  
 158.778 -   /* find number of channels */
 158.779 +   /* Find number of channels */
 158.780     switch (png_ptr->color_type)
 158.781     {
 158.782 +      default: /* invalid, png_set_IHDR calls png_error */
 158.783        case PNG_COLOR_TYPE_GRAY:
 158.784        case PNG_COLOR_TYPE_PALETTE:
 158.785           png_ptr->channels = 1;
 158.786           break;
 158.787 +
 158.788        case PNG_COLOR_TYPE_RGB:
 158.789           png_ptr->channels = 3;
 158.790           break;
 158.791 +
 158.792        case PNG_COLOR_TYPE_GRAY_ALPHA:
 158.793           png_ptr->channels = 2;
 158.794           break;
 158.795 +
 158.796        case PNG_COLOR_TYPE_RGB_ALPHA:
 158.797           png_ptr->channels = 4;
 158.798           break;
 158.799     }
 158.800  
 158.801 -   /* set up other useful info */
 158.802 +   /* Set up other useful info */
 158.803     png_ptr->pixel_depth = (png_byte)(png_ptr->bit_depth *
 158.804     png_ptr->channels);
 158.805 -   png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->width);
 158.806 -   png_debug1(3,"bit_depth = %d\n", png_ptr->bit_depth);
 158.807 -   png_debug1(3,"channels = %d\n", png_ptr->channels);
 158.808 -   png_debug1(3,"rowbytes = %lu\n", png_ptr->rowbytes);
 158.809 +   png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, png_ptr->width);
 158.810 +   png_debug1(3, "bit_depth = %d", png_ptr->bit_depth);
 158.811 +   png_debug1(3, "channels = %d", png_ptr->channels);
 158.812 +   png_debug1(3, "rowbytes = %lu", (unsigned long)png_ptr->rowbytes);
 158.813     png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth,
 158.814 -      color_type, interlace_type, compression_type, filter_type);
 158.815 +       color_type, interlace_type, compression_type, filter_type);
 158.816  }
 158.817  
 158.818 -/* read and check the palette */
 158.819 +/* Read and check the palette */
 158.820  void /* PRIVATE */
 158.821  png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
 158.822  {
 158.823     png_color palette[PNG_MAX_PALETTE_LENGTH];
 158.824     int num, i;
 158.825 -#ifndef PNG_NO_POINTER_INDEXING
 158.826 +#ifdef PNG_POINTER_INDEXING_SUPPORTED
 158.827     png_colorp pal_ptr;
 158.828  #endif
 158.829  
 158.830 -   png_debug(1, "in png_handle_PLTE\n");
 158.831 +   png_debug(1, "in png_handle_PLTE");
 158.832  
 158.833     if (!(png_ptr->mode & PNG_HAVE_IHDR))
 158.834        png_error(png_ptr, "Missing IHDR before PLTE");
 158.835 +
 158.836     else if (png_ptr->mode & PNG_HAVE_IDAT)
 158.837     {
 158.838        png_warning(png_ptr, "Invalid PLTE after IDAT");
 158.839        png_crc_finish(png_ptr, length);
 158.840        return;
 158.841     }
 158.842 +
 158.843     else if (png_ptr->mode & PNG_HAVE_PLTE)
 158.844        png_error(png_ptr, "Duplicate PLTE chunk");
 158.845  
 158.846 @@ -462,11 +654,12 @@
 158.847     if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR))
 158.848     {
 158.849        png_warning(png_ptr,
 158.850 -        "Ignoring PLTE chunk in grayscale PNG");
 158.851 +          "Ignoring PLTE chunk in grayscale PNG");
 158.852        png_crc_finish(png_ptr, length);
 158.853        return;
 158.854     }
 158.855 -#if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
 158.856 +
 158.857 +#ifndef PNG_READ_OPT_PLTE_SUPPORTED
 158.858     if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
 158.859     {
 158.860        png_crc_finish(png_ptr, length);
 158.861 @@ -482,6 +675,7 @@
 158.862           png_crc_finish(png_ptr, length);
 158.863           return;
 158.864        }
 158.865 +
 158.866        else
 158.867        {
 158.868           png_error(png_ptr, "Invalid palette chunk");
 158.869 @@ -490,7 +684,7 @@
 158.870  
 158.871     num = (int)length / 3;
 158.872  
 158.873 -#ifndef PNG_NO_POINTER_INDEXING
 158.874 +#ifdef PNG_POINTER_INDEXING_SUPPORTED
 158.875     for (i = 0, pal_ptr = palette; i < num; i++, pal_ptr++)
 158.876     {
 158.877        png_byte buf[3];
 158.878 @@ -506,42 +700,47 @@
 158.879        png_byte buf[3];
 158.880  
 158.881        png_crc_read(png_ptr, buf, 3);
 158.882 -      /* don't depend upon png_color being any order */
 158.883 +      /* Don't depend upon png_color being any order */
 158.884        palette[i].red = buf[0];
 158.885        palette[i].green = buf[1];
 158.886        palette[i].blue = buf[2];
 158.887     }
 158.888  #endif
 158.889  
 158.890 -   /* If we actually NEED the PLTE chunk (ie for a paletted image), we do
 158.891 -      whatever the normal CRC configuration tells us.  However, if we
 158.892 -      have an RGB image, the PLTE can be considered ancillary, so
 158.893 -      we will act as though it is. */
 158.894 -#if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
 158.895 +   /* If we actually need the PLTE chunk (ie for a paletted image), we do
 158.896 +    * whatever the normal CRC configuration tells us.  However, if we
 158.897 +    * have an RGB image, the PLTE can be considered ancillary, so
 158.898 +    * we will act as though it is.
 158.899 +    */
 158.900 +#ifndef PNG_READ_OPT_PLTE_SUPPORTED
 158.901     if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
 158.902  #endif
 158.903     {
 158.904        png_crc_finish(png_ptr, 0);
 158.905     }
 158.906 -#if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
 158.907 +
 158.908 +#ifndef PNG_READ_OPT_PLTE_SUPPORTED
 158.909     else if (png_crc_error(png_ptr))  /* Only if we have a CRC error */
 158.910     {
 158.911        /* If we don't want to use the data from an ancillary chunk,
 158.912 -         we have two options: an error abort, or a warning and we
 158.913 -         ignore the data in this chunk (which should be OK, since
 158.914 -         it's considered ancillary for a RGB or RGBA image). */
 158.915 +       * we have two options: an error abort, or a warning and we
 158.916 +       * ignore the data in this chunk (which should be OK, since
 158.917 +       * it's considered ancillary for a RGB or RGBA image).
 158.918 +       */
 158.919        if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_USE))
 158.920        {
 158.921           if (png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)
 158.922           {
 158.923 -            png_chunk_error(png_ptr, "CRC error");
 158.924 +            png_chunk_benign_error(png_ptr, "CRC error");
 158.925           }
 158.926 +
 158.927           else
 158.928           {
 158.929              png_chunk_warning(png_ptr, "CRC error");
 158.930              return;
 158.931           }
 158.932        }
 158.933 +
 158.934        /* Otherwise, we (optionally) emit a warning and use the chunk. */
 158.935        else if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN))
 158.936        {
 158.937 @@ -552,7 +751,7 @@
 158.938  
 158.939     png_set_PLTE(png_ptr, info_ptr, palette, num);
 158.940  
 158.941 -#if defined(PNG_READ_tRNS_SUPPORTED)
 158.942 +#ifdef PNG_READ_tRNS_SUPPORTED
 158.943     if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
 158.944     {
 158.945        if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
 158.946 @@ -562,6 +761,7 @@
 158.947              png_warning(png_ptr, "Truncating incorrect tRNS chunk length");
 158.948              png_ptr->num_trans = (png_uint_16)num;
 158.949           }
 158.950 +
 158.951           if (info_ptr->num_trans > (png_uint_16)num)
 158.952           {
 158.953              png_warning(png_ptr, "Truncating incorrect info tRNS chunk length");
 158.954 @@ -576,7 +776,7 @@
 158.955  void /* PRIVATE */
 158.956  png_handle_IEND(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
 158.957  {
 158.958 -   png_debug(1, "in png_handle_IEND\n");
 158.959 +   png_debug(1, "in png_handle_IEND");
 158.960  
 158.961     if (!(png_ptr->mode & PNG_HAVE_IHDR) || !(png_ptr->mode & PNG_HAVE_IDAT))
 158.962     {
 158.963 @@ -589,41 +789,40 @@
 158.964     {
 158.965        png_warning(png_ptr, "Incorrect IEND chunk length");
 158.966     }
 158.967 +
 158.968     png_crc_finish(png_ptr, length);
 158.969  
 158.970 -   if (&info_ptr == NULL) /* quiet compiler warnings about unused info_ptr */
 158.971 -      return;
 158.972 +   PNG_UNUSED(info_ptr) /* Quiet compiler warnings about unused info_ptr */
 158.973  }
 158.974  
 158.975 -#if defined(PNG_READ_gAMA_SUPPORTED)
 158.976 +#ifdef PNG_READ_gAMA_SUPPORTED
 158.977  void /* PRIVATE */
 158.978  png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
 158.979  {
 158.980     png_fixed_point igamma;
 158.981 -#ifdef PNG_FLOATING_POINT_SUPPORTED
 158.982 -   float file_gamma;
 158.983 -#endif
 158.984     png_byte buf[4];
 158.985  
 158.986 -   png_debug(1, "in png_handle_gAMA\n");
 158.987 +   png_debug(1, "in png_handle_gAMA");
 158.988  
 158.989     if (!(png_ptr->mode & PNG_HAVE_IHDR))
 158.990        png_error(png_ptr, "Missing IHDR before gAMA");
 158.991 +
 158.992     else if (png_ptr->mode & PNG_HAVE_IDAT)
 158.993     {
 158.994        png_warning(png_ptr, "Invalid gAMA after IDAT");
 158.995        png_crc_finish(png_ptr, length);
 158.996        return;
 158.997     }
 158.998 +
 158.999     else if (png_ptr->mode & PNG_HAVE_PLTE)
158.1000        /* Should be an error, but we can cope with it */
158.1001        png_warning(png_ptr, "Out of place gAMA chunk");
158.1002  
158.1003     if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
158.1004 -#if defined(PNG_READ_sRGB_SUPPORTED)
158.1005 -      && !(info_ptr->valid & PNG_INFO_sRGB)
158.1006 +#ifdef PNG_READ_sRGB_SUPPORTED
158.1007 +       && !(info_ptr->valid & PNG_INFO_sRGB)
158.1008  #endif
158.1009 -      )
158.1010 +       )
158.1011     {
158.1012        png_warning(png_ptr, "Duplicate gAMA chunk");
158.1013        png_crc_finish(png_ptr, length);
158.1014 @@ -638,68 +837,71 @@
158.1015     }
158.1016  
158.1017     png_crc_read(png_ptr, buf, 4);
158.1018 +
158.1019     if (png_crc_finish(png_ptr, 0))
158.1020        return;
158.1021  
158.1022 -   igamma = (png_fixed_point)png_get_uint_32(buf);
158.1023 -   /* check for zero gamma */
158.1024 -   if (igamma == 0)
158.1025 +   igamma = png_get_fixed_point(NULL, buf);
158.1026 +
158.1027 +   /* Check for zero gamma or an error. */
158.1028 +   if (igamma <= 0)
158.1029 +   {
158.1030 +      png_warning(png_ptr,
158.1031 +          "Ignoring gAMA chunk with out of range gamma");
158.1032 +
158.1033 +      return;
158.1034 +   }
158.1035 +
158.1036 +#  ifdef PNG_READ_sRGB_SUPPORTED
158.1037 +   if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB))
158.1038 +   {
158.1039 +      if (PNG_OUT_OF_RANGE(igamma, 45500L, 500))
158.1040        {
158.1041 -         png_warning(png_ptr,
158.1042 -           "Ignoring gAMA chunk with gamma=0");
158.1043 +         PNG_WARNING_PARAMETERS(p)
158.1044 +         png_warning_parameter_signed(p, 1, PNG_NUMBER_FORMAT_fixed, igamma);
158.1045 +         png_formatted_warning(png_ptr, p,
158.1046 +             "Ignoring incorrect gAMA value @1 when sRGB is also present");
158.1047           return;
158.1048        }
158.1049 -
158.1050 -#if defined(PNG_READ_sRGB_SUPPORTED)
158.1051 -   if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB))
158.1052 -      if (PNG_OUT_OF_RANGE(igamma, 45500L, 500))
158.1053 -      {
158.1054 -         png_warning(png_ptr,
158.1055 -           "Ignoring incorrect gAMA value when sRGB is also present");
158.1056 -#ifndef PNG_NO_CONSOLE_IO
158.1057 -         fprintf(stderr, "gamma = (%d/100000)\n", (int)igamma);
158.1058 -#endif
158.1059 -         return;
158.1060 -      }
158.1061 -#endif /* PNG_READ_sRGB_SUPPORTED */
158.1062 -
158.1063 -#ifdef PNG_FLOATING_POINT_SUPPORTED
158.1064 -   file_gamma = (float)igamma / (float)100000.0;
158.1065 +   }
158.1066 +#  endif /* PNG_READ_sRGB_SUPPORTED */
158.1067 +
158.1068  #  ifdef PNG_READ_GAMMA_SUPPORTED
158.1069 -     png_ptr->gamma = file_gamma;
158.1070 +   /* Gamma correction on read is supported. */
158.1071 +   png_ptr->gamma = igamma;
158.1072  #  endif
158.1073 -     png_set_gAMA(png_ptr, info_ptr, file_gamma);
158.1074 -#endif
158.1075 -#ifdef PNG_FIXED_POINT_SUPPORTED
158.1076 +   /* And set the 'info' structure members. */
158.1077     png_set_gAMA_fixed(png_ptr, info_ptr, igamma);
158.1078 -#endif
158.1079  }
158.1080  #endif
158.1081  
158.1082 -#if defined(PNG_READ_sBIT_SUPPORTED)
158.1083 +#ifdef PNG_READ_sBIT_SUPPORTED
158.1084  void /* PRIVATE */
158.1085  png_handle_sBIT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
158.1086  {
158.1087     png_size_t truelen;
158.1088     png_byte buf[4];
158.1089  
158.1090 -   png_debug(1, "in png_handle_sBIT\n");
158.1091 +   png_debug(1, "in png_handle_sBIT");
158.1092  
158.1093     buf[0] = buf[1] = buf[2] = buf[3] = 0;
158.1094  
158.1095     if (!(png_ptr->mode & PNG_HAVE_IHDR))
158.1096        png_error(png_ptr, "Missing IHDR before sBIT");
158.1097 +
158.1098     else if (png_ptr->mode & PNG_HAVE_IDAT)
158.1099     {
158.1100        png_warning(png_ptr, "Invalid sBIT after IDAT");
158.1101        png_crc_finish(png_ptr, length);
158.1102        return;
158.1103     }
158.1104 +
158.1105     else if (png_ptr->mode & PNG_HAVE_PLTE)
158.1106     {
158.1107        /* Should be an error, but we can cope with it */
158.1108        png_warning(png_ptr, "Out of place sBIT chunk");
158.1109     }
158.1110 +
158.1111     if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT))
158.1112     {
158.1113        png_warning(png_ptr, "Duplicate sBIT chunk");
158.1114 @@ -709,6 +911,7 @@
158.1115  
158.1116     if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
158.1117        truelen = 3;
158.1118 +
158.1119     else
158.1120        truelen = (png_size_t)png_ptr->channels;
158.1121  
158.1122 @@ -720,6 +923,7 @@
158.1123     }
158.1124  
158.1125     png_crc_read(png_ptr, buf, truelen);
158.1126 +
158.1127     if (png_crc_finish(png_ptr, 0))
158.1128        return;
158.1129  
158.1130 @@ -730,6 +934,7 @@
158.1131        png_ptr->sig_bit.blue = buf[2];
158.1132        png_ptr->sig_bit.alpha = buf[3];
158.1133     }
158.1134 +
158.1135     else
158.1136     {
158.1137        png_ptr->sig_bit.gray = buf[0];
158.1138 @@ -738,41 +943,39 @@
158.1139        png_ptr->sig_bit.blue = buf[0];
158.1140        png_ptr->sig_bit.alpha = buf[1];
158.1141     }
158.1142 +
158.1143     png_set_sBIT(png_ptr, info_ptr, &(png_ptr->sig_bit));
158.1144  }
158.1145  #endif
158.1146  
158.1147 -#if defined(PNG_READ_cHRM_SUPPORTED)
158.1148 +#ifdef PNG_READ_cHRM_SUPPORTED
158.1149  void /* PRIVATE */
158.1150  png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
158.1151  {
158.1152 -   png_byte buf[4];
158.1153 -#ifdef PNG_FLOATING_POINT_SUPPORTED
158.1154 -   float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
158.1155 -#endif
158.1156 -   png_fixed_point int_x_white, int_y_white, int_x_red, int_y_red, int_x_green,
158.1157 -      int_y_green, int_x_blue, int_y_blue;
158.1158 -
158.1159 -   png_uint_32 uint_x, uint_y;
158.1160 -
158.1161 -   png_debug(1, "in png_handle_cHRM\n");
158.1162 +   png_byte buf[32];
158.1163 +   png_fixed_point x_white, y_white, x_red, y_red, x_green, y_green, x_blue,
158.1164 +      y_blue;
158.1165 +
158.1166 +   png_debug(1, "in png_handle_cHRM");
158.1167  
158.1168     if (!(png_ptr->mode & PNG_HAVE_IHDR))
158.1169        png_error(png_ptr, "Missing IHDR before cHRM");
158.1170 +
158.1171     else if (png_ptr->mode & PNG_HAVE_IDAT)
158.1172     {
158.1173        png_warning(png_ptr, "Invalid cHRM after IDAT");
158.1174        png_crc_finish(png_ptr, length);
158.1175        return;
158.1176     }
158.1177 +
158.1178     else if (png_ptr->mode & PNG_HAVE_PLTE)
158.1179        /* Should be an error, but we can cope with it */
158.1180        png_warning(png_ptr, "Missing PLTE before cHRM");
158.1181  
158.1182     if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)
158.1183 -#if defined(PNG_READ_sRGB_SUPPORTED)
158.1184 -      && !(info_ptr->valid & PNG_INFO_sRGB)
158.1185 -#endif
158.1186 +#  ifdef PNG_READ_sRGB_SUPPORTED
158.1187 +       && !(info_ptr->valid & PNG_INFO_sRGB)
158.1188 +#  endif
158.1189        )
158.1190     {
158.1191        png_warning(png_ptr, "Duplicate cHRM chunk");
158.1192 @@ -787,142 +990,115 @@
158.1193        return;
158.1194     }
158.1195  
158.1196 -   png_crc_read(png_ptr, buf, 4);
158.1197 -   uint_x = png_get_uint_32(buf);
158.1198 -
158.1199 -   png_crc_read(png_ptr, buf, 4);
158.1200 -   uint_y = png_get_uint_32(buf);
158.1201 -
158.1202 -   if (uint_x > 80000L || uint_y > 80000L ||
158.1203 -      uint_x + uint_y > 100000L)
158.1204 +   png_crc_read(png_ptr, buf, 32);
158.1205 +
158.1206 +   if (png_crc_finish(png_ptr, 0))
158.1207 +      return;
158.1208 +
158.1209 +   x_white = png_get_fixed_point(NULL, buf);
158.1210 +   y_white = png_get_fixed_point(NULL, buf + 4);
158.1211 +   x_red   = png_get_fixed_point(NULL, buf + 8);
158.1212 +   y_red   = png_get_fixed_point(NULL, buf + 12);
158.1213 +   x_green = png_get_fixed_point(NULL, buf + 16);
158.1214 +   y_green = png_get_fixed_point(NULL, buf + 20);
158.1215 +   x_blue  = png_get_fixed_point(NULL, buf + 24);
158.1216 +   y_blue  = png_get_fixed_point(NULL, buf + 28);
158.1217 +
158.1218 +   if (x_white == PNG_FIXED_ERROR ||
158.1219 +       y_white == PNG_FIXED_ERROR ||
158.1220 +       x_red   == PNG_FIXED_ERROR ||
158.1221 +       y_red   == PNG_FIXED_ERROR ||
158.1222 +       x_green == PNG_FIXED_ERROR ||
158.1223 +       y_green == PNG_FIXED_ERROR ||
158.1224 +       x_blue  == PNG_FIXED_ERROR ||
158.1225 +       y_blue  == PNG_FIXED_ERROR)
158.1226     {
158.1227 -      png_warning(png_ptr, "Invalid cHRM white point");
158.1228 -      png_crc_finish(png_ptr, 24);
158.1229 +      png_warning(png_ptr, "Ignoring cHRM chunk with negative chromaticities");
158.1230        return;
158.1231     }
158.1232 -   int_x_white = (png_fixed_point)uint_x;
158.1233 -   int_y_white = (png_fixed_point)uint_y;
158.1234 -
158.1235 -   png_crc_read(png_ptr, buf, 4);
158.1236 -   uint_x = png_get_uint_32(buf);
158.1237 -
158.1238 -   png_crc_read(png_ptr, buf, 4);
158.1239 -   uint_y = png_get_uint_32(buf);
158.1240 -
158.1241 -   if (uint_x + uint_y > 100000L)
158.1242 +
158.1243 +#ifdef PNG_READ_sRGB_SUPPORTED
158.1244 +   if ((info_ptr != NULL) && (info_ptr->valid & PNG_INFO_sRGB))
158.1245     {
158.1246 -      png_warning(png_ptr, "Invalid cHRM red point");
158.1247 -      png_crc_finish(png_ptr, 16);
158.1248 +      if (PNG_OUT_OF_RANGE(x_white, 31270,  1000) ||
158.1249 +          PNG_OUT_OF_RANGE(y_white, 32900,  1000) ||
158.1250 +          PNG_OUT_OF_RANGE(x_red,   64000L, 1000) ||
158.1251 +          PNG_OUT_OF_RANGE(y_red,   33000,  1000) ||
158.1252 +          PNG_OUT_OF_RANGE(x_green, 30000,  1000) ||
158.1253 +          PNG_OUT_OF_RANGE(y_green, 60000L, 1000) ||
158.1254 +          PNG_OUT_OF_RANGE(x_blue,  15000,  1000) ||
158.1255 +          PNG_OUT_OF_RANGE(y_blue,   6000,  1000))
158.1256 +      {
158.1257 +         PNG_WARNING_PARAMETERS(p)
158.1258 +
158.1259 +         png_warning_parameter_signed(p, 1, PNG_NUMBER_FORMAT_fixed, x_white);
158.1260 +         png_warning_parameter_signed(p, 2, PNG_NUMBER_FORMAT_fixed, y_white);
158.1261 +         png_warning_parameter_signed(p, 3, PNG_NUMBER_FORMAT_fixed, x_red);
158.1262 +         png_warning_parameter_signed(p, 4, PNG_NUMBER_FORMAT_fixed, y_red);
158.1263 +         png_warning_parameter_signed(p, 5, PNG_NUMBER_FORMAT_fixed, x_green);
158.1264 +         png_warning_parameter_signed(p, 6, PNG_NUMBER_FORMAT_fixed, y_green);
158.1265 +         png_warning_parameter_signed(p, 7, PNG_NUMBER_FORMAT_fixed, x_blue);
158.1266 +         png_warning_parameter_signed(p, 8, PNG_NUMBER_FORMAT_fixed, y_blue);
158.1267 +
158.1268 +         png_formatted_warning(png_ptr, p,
158.1269 +             "Ignoring incorrect cHRM white(@1,@2) r(@3,@4)g(@5,@6)b(@7,@8) "
158.1270 +             "when sRGB is also present");
158.1271 +      }
158.1272        return;
158.1273     }
158.1274 -   int_x_red = (png_fixed_point)uint_x;
158.1275 -   int_y_red = (png_fixed_point)uint_y;
158.1276 -
158.1277 -   png_crc_read(png_ptr, buf, 4);
158.1278 -   uint_x = png_get_uint_32(buf);
158.1279 -
158.1280 -   png_crc_read(png_ptr, buf, 4);
158.1281 -   uint_y = png_get_uint_32(buf);
158.1282 -
158.1283 -   if (uint_x + uint_y > 100000L)
158.1284 +#endif /* PNG_READ_sRGB_SUPPORTED */
158.1285 +
158.1286 +#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
158.1287 +   /* Store the _white values as default coefficients for the rgb to gray
158.1288 +    * operation if it is supported.
158.1289 +    */
158.1290 +   if ((png_ptr->transformations & PNG_RGB_TO_GRAY) == 0)
158.1291     {
158.1292 -      png_warning(png_ptr, "Invalid cHRM green point");
158.1293 -      png_crc_finish(png_ptr, 8);
158.1294 -      return;
158.1295 +      /* png_set_background has not been called, the coefficients must be in
158.1296 +       * range for the following to work without overflow.
158.1297 +       */
158.1298 +      if (y_red <= (1<<17) && y_green <= (1<<17) && y_blue <= (1<<17))
158.1299 +      {
158.1300 +         /* The y values are chromaticities: Y/X+Y+Z, the weights for the gray
158.1301 +          * transformation are simply the normalized Y values for red, green and
158.1302 +          * blue scaled by 32768.
158.1303 +          */
158.1304 +         png_uint_32 w = y_red + y_green + y_blue;
158.1305 +
158.1306 +         png_ptr->rgb_to_gray_red_coeff   = (png_uint_16)(((png_uint_32)y_red *
158.1307 +            32768)/w);
158.1308 +         png_ptr->rgb_to_gray_green_coeff = (png_uint_16)(((png_uint_32)y_green
158.1309 +            * 32768)/w);
158.1310 +         png_ptr->rgb_to_gray_blue_coeff  = (png_uint_16)(((png_uint_32)y_blue *
158.1311 +            32768)/w);
158.1312 +      }
158.1313     }
158.1314 -   int_x_green = (png_fixed_point)uint_x;
158.1315 -   int_y_green = (png_fixed_point)uint_y;
158.1316 -
158.1317 -   png_crc_read(png_ptr, buf, 4);
158.1318 -   uint_x = png_get_uint_32(buf);
158.1319 -
158.1320 -   png_crc_read(png_ptr, buf, 4);
158.1321 -   uint_y = png_get_uint_32(buf);
158.1322 -
158.1323 -   if (uint_x + uint_y > 100000L)
158.1324 -   {
158.1325 -      png_warning(png_ptr, "Invalid cHRM blue point");
158.1326 -      png_crc_finish(png_ptr, 0);
158.1327 -      return;
158.1328 -   }
158.1329 -   int_x_blue = (png_fixed_point)uint_x;
158.1330 -   int_y_blue = (png_fixed_point)uint_y;
158.1331 -
158.1332 -#ifdef PNG_FLOATING_POINT_SUPPORTED
158.1333 -   white_x = (float)int_x_white / (float)100000.0;
158.1334 -   white_y = (float)int_y_white / (float)100000.0;
158.1335 -   red_x   = (float)int_x_red   / (float)100000.0;
158.1336 -   red_y   = (float)int_y_red   / (float)100000.0;
158.1337 -   green_x = (float)int_x_green / (float)100000.0;
158.1338 -   green_y = (float)int_y_green / (float)100000.0;
158.1339 -   blue_x  = (float)int_x_blue  / (float)100000.0;
158.1340 -   blue_y  = (float)int_y_blue  / (float)100000.0;
158.1341  #endif
158.1342  
158.1343 -#if defined(PNG_READ_sRGB_SUPPORTED)
158.1344 -   if ((info_ptr != NULL) && (info_ptr->valid & PNG_INFO_sRGB))
158.1345 -      {
158.1346 -      if (PNG_OUT_OF_RANGE(int_x_white, 31270,  1000) ||
158.1347 -          PNG_OUT_OF_RANGE(int_y_white, 32900,  1000) ||
158.1348 -          PNG_OUT_OF_RANGE(int_x_red,   64000L, 1000) ||
158.1349 -          PNG_OUT_OF_RANGE(int_y_red,   33000,  1000) ||
158.1350 -          PNG_OUT_OF_RANGE(int_x_green, 30000,  1000) ||
158.1351 -          PNG_OUT_OF_RANGE(int_y_green, 60000L, 1000) ||
158.1352 -          PNG_OUT_OF_RANGE(int_x_blue,  15000,  1000) ||
158.1353 -          PNG_OUT_OF_RANGE(int_y_blue,   6000,  1000))
158.1354 -         {
158.1355 -            png_warning(png_ptr,
158.1356 -              "Ignoring incorrect cHRM value when sRGB is also present");
158.1357 -#ifndef PNG_NO_CONSOLE_IO
158.1358 -#ifdef PNG_FLOATING_POINT_SUPPORTED
158.1359 -            fprintf(stderr,"wx=%f, wy=%f, rx=%f, ry=%f\n",
158.1360 -               white_x, white_y, red_x, red_y);
158.1361 -            fprintf(stderr,"gx=%f, gy=%f, bx=%f, by=%f\n",
158.1362 -               green_x, green_y, blue_x, blue_y);
158.1363 -#else
158.1364 -            fprintf(stderr,"wx=%ld, wy=%ld, rx=%ld, ry=%ld\n",
158.1365 -               int_x_white, int_y_white, int_x_red, int_y_red);
158.1366 -            fprintf(stderr,"gx=%ld, gy=%ld, bx=%ld, by=%ld\n",
158.1367 -               int_x_green, int_y_green, int_x_blue, int_y_blue);
158.1368 -#endif
158.1369 -#endif /* PNG_NO_CONSOLE_IO */
158.1370 -         }
158.1371 -         png_crc_finish(png_ptr, 0);
158.1372 -         return;
158.1373 -      }
158.1374 -#endif /* PNG_READ_sRGB_SUPPORTED */
158.1375 -
158.1376 -#ifdef PNG_FLOATING_POINT_SUPPORTED
158.1377 -   png_set_cHRM(png_ptr, info_ptr,
158.1378 -      white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
158.1379 -#endif
158.1380 -#ifdef PNG_FIXED_POINT_SUPPORTED
158.1381 -   png_set_cHRM_fixed(png_ptr, info_ptr,
158.1382 -      int_x_white, int_y_white, int_x_red, int_y_red, int_x_green,
158.1383 -      int_y_green, int_x_blue, int_y_blue);
158.1384 -#endif
158.1385 -   if (png_crc_finish(png_ptr, 0))
158.1386 -      return;
158.1387 +   png_set_cHRM_fixed(png_ptr, info_ptr, x_white, y_white, x_red, y_red,
158.1388 +      x_green, y_green, x_blue, y_blue);
158.1389  }
158.1390  #endif
158.1391  
158.1392 -#if defined(PNG_READ_sRGB_SUPPORTED)
158.1393 +#ifdef PNG_READ_sRGB_SUPPORTED
158.1394  void /* PRIVATE */
158.1395  png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
158.1396  {
158.1397     int intent;
158.1398     png_byte buf[1];
158.1399  
158.1400 -   png_debug(1, "in png_handle_sRGB\n");
158.1401 +   png_debug(1, "in png_handle_sRGB");
158.1402  
158.1403     if (!(png_ptr->mode & PNG_HAVE_IHDR))
158.1404        png_error(png_ptr, "Missing IHDR before sRGB");
158.1405 +
158.1406     else if (png_ptr->mode & PNG_HAVE_IDAT)
158.1407     {
158.1408        png_warning(png_ptr, "Invalid sRGB after IDAT");
158.1409        png_crc_finish(png_ptr, length);
158.1410        return;
158.1411     }
158.1412 +
158.1413     else if (png_ptr->mode & PNG_HAVE_PLTE)
158.1414        /* Should be an error, but we can cope with it */
158.1415        png_warning(png_ptr, "Out of place sRGB chunk");
158.1416 @@ -942,11 +1118,13 @@
158.1417     }
158.1418  
158.1419     png_crc_read(png_ptr, buf, 1);
158.1420 +
158.1421     if (png_crc_finish(png_ptr, 0))
158.1422        return;
158.1423  
158.1424     intent = buf[0];
158.1425 -   /* check for bad intent */
158.1426 +
158.1427 +   /* Check for bad intent */
158.1428     if (intent >= PNG_sRGB_INTENT_LAST)
158.1429     {
158.1430        png_warning(png_ptr, "Unknown sRGB intent");
158.1431 @@ -956,76 +1134,64 @@
158.1432  #if defined(PNG_READ_gAMA_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
158.1433     if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA))
158.1434     {
158.1435 -   png_fixed_point igamma;
158.1436 -#ifdef PNG_FIXED_POINT_SUPPORTED
158.1437 -      igamma=info_ptr->int_gamma;
158.1438 -#else
158.1439 -#  ifdef PNG_FLOATING_POINT_SUPPORTED
158.1440 -      igamma=(png_fixed_point)(info_ptr->gamma * 100000.);
158.1441 -#  endif
158.1442 -#endif
158.1443 -      if (PNG_OUT_OF_RANGE(igamma, 45500L, 500))
158.1444 +      if (PNG_OUT_OF_RANGE(info_ptr->gamma, 45500L, 500))
158.1445        {
158.1446 -         png_warning(png_ptr,
158.1447 -           "Ignoring incorrect gAMA value when sRGB is also present");
158.1448 -#ifndef PNG_NO_CONSOLE_IO
158.1449 -#  ifdef PNG_FIXED_POINT_SUPPORTED
158.1450 -         fprintf(stderr,"incorrect gamma=(%d/100000)\n",(int)png_ptr->int_gamma);
158.1451 -#  else
158.1452 -#    ifdef PNG_FLOATING_POINT_SUPPORTED
158.1453 -         fprintf(stderr,"incorrect gamma=%f\n",png_ptr->gamma);
158.1454 -#    endif
158.1455 -#  endif
158.1456 -#endif
158.1457 +         PNG_WARNING_PARAMETERS(p)
158.1458 +
158.1459 +         png_warning_parameter_signed(p, 1, PNG_NUMBER_FORMAT_fixed,
158.1460 +            info_ptr->gamma);
158.1461 +
158.1462 +         png_formatted_warning(png_ptr, p,
158.1463 +             "Ignoring incorrect gAMA value @1 when sRGB is also present");
158.1464        }
158.1465     }
158.1466  #endif /* PNG_READ_gAMA_SUPPORTED */
158.1467  
158.1468  #ifdef PNG_READ_cHRM_SUPPORTED
158.1469 -#ifdef PNG_FIXED_POINT_SUPPORTED
158.1470     if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
158.1471 -      if (PNG_OUT_OF_RANGE(info_ptr->int_x_white, 31270,  1000) ||
158.1472 -          PNG_OUT_OF_RANGE(info_ptr->int_y_white, 32900,  1000) ||
158.1473 -          PNG_OUT_OF_RANGE(info_ptr->int_x_red,   64000L, 1000) ||
158.1474 -          PNG_OUT_OF_RANGE(info_ptr->int_y_red,   33000,  1000) ||
158.1475 -          PNG_OUT_OF_RANGE(info_ptr->int_x_green, 30000,  1000) ||
158.1476 -          PNG_OUT_OF_RANGE(info_ptr->int_y_green, 60000L, 1000) ||
158.1477 -          PNG_OUT_OF_RANGE(info_ptr->int_x_blue,  15000,  1000) ||
158.1478 -          PNG_OUT_OF_RANGE(info_ptr->int_y_blue,   6000,  1000))
158.1479 -         {
158.1480 -            png_warning(png_ptr,
158.1481 -              "Ignoring incorrect cHRM value when sRGB is also present");
158.1482 -         }
158.1483 -#endif /* PNG_FIXED_POINT_SUPPORTED */
158.1484 +      if (PNG_OUT_OF_RANGE(info_ptr->x_white, 31270,  1000) ||
158.1485 +          PNG_OUT_OF_RANGE(info_ptr->y_white, 32900,  1000) ||
158.1486 +          PNG_OUT_OF_RANGE(info_ptr->x_red,   64000L, 1000) ||
158.1487 +          PNG_OUT_OF_RANGE(info_ptr->y_red,   33000,  1000) ||
158.1488 +          PNG_OUT_OF_RANGE(info_ptr->x_green, 30000,  1000) ||
158.1489 +          PNG_OUT_OF_RANGE(info_ptr->y_green, 60000L, 1000) ||
158.1490 +          PNG_OUT_OF_RANGE(info_ptr->x_blue,  15000,  1000) ||
158.1491 +          PNG_OUT_OF_RANGE(info_ptr->y_blue,   6000,  1000))
158.1492 +      {
158.1493 +         png_warning(png_ptr,
158.1494 +             "Ignoring incorrect cHRM value when sRGB is also present");
158.1495 +      }
158.1496  #endif /* PNG_READ_cHRM_SUPPORTED */
158.1497  
158.1498     png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr, intent);
158.1499  }
158.1500  #endif /* PNG_READ_sRGB_SUPPORTED */
158.1501  
158.1502 -#if defined(PNG_READ_iCCP_SUPPORTED)
158.1503 +#ifdef PNG_READ_iCCP_SUPPORTED
158.1504  void /* PRIVATE */
158.1505  png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
158.1506  /* Note: this does not properly handle chunks that are > 64K under DOS */
158.1507  {
158.1508 -   png_charp chunkdata;
158.1509     png_byte compression_type;
158.1510     png_bytep pC;
158.1511     png_charp profile;
158.1512     png_uint_32 skip = 0;
158.1513 -   png_uint_32 profile_size, profile_length;
158.1514 +   png_uint_32 profile_size;
158.1515 +   png_alloc_size_t profile_length;
158.1516     png_size_t slength, prefix_length, data_length;
158.1517  
158.1518 -   png_debug(1, "in png_handle_iCCP\n");
158.1519 +   png_debug(1, "in png_handle_iCCP");
158.1520  
158.1521     if (!(png_ptr->mode & PNG_HAVE_IHDR))
158.1522        png_error(png_ptr, "Missing IHDR before iCCP");
158.1523 +
158.1524     else if (png_ptr->mode & PNG_HAVE_IDAT)
158.1525     {
158.1526        png_warning(png_ptr, "Invalid iCCP after IDAT");
158.1527        png_crc_finish(png_ptr, length);
158.1528        return;
158.1529     }
158.1530 +
158.1531     else if (png_ptr->mode & PNG_HAVE_PLTE)
158.1532        /* Should be an error, but we can cope with it */
158.1533        png_warning(png_ptr, "Out of place iCCP chunk");
158.1534 @@ -1046,96 +1212,135 @@
158.1535     }
158.1536  #endif
158.1537  
158.1538 -   chunkdata = (png_charp)png_malloc(png_ptr, length + 1);
158.1539 +   png_free(png_ptr, png_ptr->chunkdata);
158.1540 +   png_ptr->chunkdata = (png_charp)png_malloc(png_ptr, length + 1);
158.1541     slength = (png_size_t)length;
158.1542 -   png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
158.1543 +   png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength);
158.1544  
158.1545     if (png_crc_finish(png_ptr, skip))
158.1546     {
158.1547 -      png_free(png_ptr, chunkdata);
158.1548 +      png_free(png_ptr, png_ptr->chunkdata);
158.1549 +      png_ptr->chunkdata = NULL;
158.1550        return;
158.1551     }
158.1552  
158.1553 -   chunkdata[slength] = 0x00;
158.1554 -
158.1555 -   for (profile = chunkdata; *profile; profile++)
158.1556 -      /* empty loop to find end of name */ ;
158.1557 +   png_ptr->chunkdata[slength] = 0x00;
158.1558 +
158.1559 +   for (profile = png_ptr->chunkdata; *profile; profile++)
158.1560 +      /* Empty loop to find end of name */ ;
158.1561  
158.1562     ++profile;
158.1563  
158.1564 -   /* there should be at least one zero (the compression type byte)
158.1565 -      following the separator, and we should be on it  */
158.1566 -   if ( profile >= chunkdata + slength)
158.1567 +   /* There should be at least one zero (the compression type byte)
158.1568 +    * following the separator, and we should be on it
158.1569 +    */
158.1570 +   if (profile >= png_ptr->chunkdata + slength - 1)
158.1571     {
158.1572 -      png_free(png_ptr, chunkdata);
158.1573 +      png_free(png_ptr, png_ptr->chunkdata);
158.1574 +      png_ptr->chunkdata = NULL;
158.1575        png_warning(png_ptr, "Malformed iCCP chunk");
158.1576        return;
158.1577     }
158.1578  
158.1579 -   /* compression_type should always be zero */
158.1580 +   /* Compression_type should always be zero */
158.1581     compression_type = *profile++;
158.1582 +
158.1583     if (compression_type)
158.1584     {
158.1585        png_warning(png_ptr, "Ignoring nonzero compression type in iCCP chunk");
158.1586 -      compression_type=0x00;  /* Reset it to zero (libpng-1.0.6 through 1.0.8
158.1587 +      compression_type = 0x00;  /* Reset it to zero (libpng-1.0.6 through 1.0.8
158.1588                                   wrote nonzero) */
158.1589     }
158.1590  
158.1591 -   prefix_length = profile - chunkdata;
158.1592 -   chunkdata = png_decompress_chunk(png_ptr, compression_type, chunkdata,
158.1593 -                                    slength, prefix_length, &data_length);
158.1594 +   prefix_length = profile - png_ptr->chunkdata;
158.1595 +   png_decompress_chunk(png_ptr, compression_type,
158.1596 +       slength, prefix_length, &data_length);
158.1597  
158.1598     profile_length = data_length - prefix_length;
158.1599  
158.1600 -   if ( prefix_length > data_length || profile_length < 4)
158.1601 +   if (prefix_length > data_length || profile_length < 4)
158.1602     {
158.1603 -      png_free(png_ptr, chunkdata);
158.1604 +      png_free(png_ptr, png_ptr->chunkdata);
158.1605 +      png_ptr->chunkdata = NULL;
158.1606        png_warning(png_ptr, "Profile size field missing from iCCP chunk");
158.1607        return;
158.1608     }
158.1609  
158.1610     /* Check the profile_size recorded in the first 32 bits of the ICC profile */
158.1611 -   pC = (png_bytep)(chunkdata+prefix_length);
158.1612 -   profile_size = ((*(pC  ))<<24) |
158.1613 -                  ((*(pC+1))<<16) |
158.1614 -                  ((*(pC+2))<< 8) |
158.1615 -                  ((*(pC+3))    );
158.1616 -
158.1617 -   if(profile_size < profile_length)
158.1618 +   pC = (png_bytep)(png_ptr->chunkdata + prefix_length);
158.1619 +   profile_size = ((*(pC    )) << 24) |
158.1620 +                  ((*(pC + 1)) << 16) |
158.1621 +                  ((*(pC + 2)) <<  8) |
158.1622 +                  ((*(pC + 3))      );
158.1623 +
158.1624 +   /* NOTE: the following guarantees that 'profile_length' fits into 32 bits,
158.1625 +    * because profile_size is a 32 bit value.
158.1626 +    */
158.1627 +   if (profile_size < profile_length)
158.1628        profile_length = profile_size;
158.1629  
158.1630 -   if(profile_size > profile_length)
158.1631 +   /* And the following guarantees that profile_size == profile_length. */
158.1632 +   if (profile_size > profile_length)
158.1633     {
158.1634 -      png_free(png_ptr, chunkdata);
158.1635 -      png_warning(png_ptr, "Ignoring truncated iCCP profile.");
158.1636 +      PNG_WARNING_PARAMETERS(p)
158.1637 +
158.1638 +      png_free(png_ptr, png_ptr->chunkdata);
158.1639 +      png_ptr->chunkdata = NULL;
158.1640 +
158.1641 +      png_warning_parameter_unsigned(p, 1, PNG_NUMBER_FORMAT_u, profile_size);
158.1642 +      png_warning_parameter_unsigned(p, 2, PNG_NUMBER_FORMAT_u, profile_length);
158.1643 +      png_formatted_warning(png_ptr, p,
158.1644 +         "Ignoring iCCP chunk with declared size = @1 and actual length = @2");
158.1645        return;
158.1646     }
158.1647  
158.1648 -   png_set_iCCP(png_ptr, info_ptr, chunkdata, compression_type,
158.1649 -                chunkdata + prefix_length, profile_length);
158.1650 -   png_free(png_ptr, chunkdata);
158.1651 +   png_set_iCCP(png_ptr, info_ptr, png_ptr->chunkdata,
158.1652 +       compression_type, (png_bytep)png_ptr->chunkdata + prefix_length,
158.1653 +       profile_size);
158.1654 +   png_free(png_ptr, png_ptr->chunkdata);
158.1655 +   png_ptr->chunkdata = NULL;
158.1656  }
158.1657  #endif /* PNG_READ_iCCP_SUPPORTED */
158.1658  
158.1659 -#if defined(PNG_READ_sPLT_SUPPORTED)
158.1660 +#ifdef PNG_READ_sPLT_SUPPORTED
158.1661  void /* PRIVATE */
158.1662  png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
158.1663  /* Note: this does not properly handle chunks that are > 64K under DOS */
158.1664  {
158.1665 -   png_bytep chunkdata;
158.1666     png_bytep entry_start;
158.1667     png_sPLT_t new_palette;
158.1668 -#ifdef PNG_NO_POINTER_INDEXING
158.1669     png_sPLT_entryp pp;
158.1670 -#endif
158.1671 -   int data_length, entry_size, i;
158.1672 +   png_uint_32 data_length;
158.1673 +   int entry_size, i;
158.1674     png_uint_32 skip = 0;
158.1675     png_size_t slength;
158.1676 -
158.1677 -   png_debug(1, "in png_handle_sPLT\n");
158.1678 +   png_uint_32 dl;
158.1679 +   png_size_t max_dl;
158.1680 +
158.1681 +   png_debug(1, "in png_handle_sPLT");
158.1682 +
158.1683 +#ifdef PNG_USER_LIMITS_SUPPORTED
158.1684 +
158.1685 +   if (png_ptr->user_chunk_cache_max != 0)
158.1686 +   {
158.1687 +      if (png_ptr->user_chunk_cache_max == 1)
158.1688 +      {
158.1689 +         png_crc_finish(png_ptr, length);
158.1690 +         return;
158.1691 +      }
158.1692 +
158.1693 +      if (--png_ptr->user_chunk_cache_max == 1)
158.1694 +      {
158.1695 +         png_warning(png_ptr, "No space in chunk cache for sPLT");
158.1696 +         png_crc_finish(png_ptr, length);
158.1697 +         return;
158.1698 +      }
158.1699 +   }
158.1700 +#endif
158.1701  
158.1702     if (!(png_ptr->mode & PNG_HAVE_IHDR))
158.1703        png_error(png_ptr, "Missing IHDR before sPLT");
158.1704 +
158.1705     else if (png_ptr->mode & PNG_HAVE_IDAT)
158.1706     {
158.1707        png_warning(png_ptr, "Invalid sPLT after IDAT");
158.1708 @@ -1152,127 +1357,156 @@
158.1709     }
158.1710  #endif
158.1711  
158.1712 -   chunkdata = (png_bytep)png_malloc(png_ptr, length + 1);
158.1713 +   png_free(png_ptr, png_ptr->chunkdata);
158.1714 +   png_ptr->chunkdata = (png_charp)png_malloc(png_ptr, length + 1);
158.1715 +
158.1716 +   /* WARNING: this may break if size_t is less than 32 bits; it is assumed
158.1717 +    * that the PNG_MAX_MALLOC_64K test is enabled in this case, but this is a
158.1718 +    * potential breakage point if the types in pngconf.h aren't exactly right.
158.1719 +    */
158.1720     slength = (png_size_t)length;
158.1721 -   png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
158.1722 +   png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength);
158.1723  
158.1724     if (png_crc_finish(png_ptr, skip))
158.1725     {
158.1726 -      png_free(png_ptr, chunkdata);
158.1727 +      png_free(png_ptr, png_ptr->chunkdata);
158.1728 +      png_ptr->chunkdata = NULL;
158.1729        return;
158.1730     }
158.1731  
158.1732 -   chunkdata[slength] = 0x00;
158.1733 -
158.1734 -   for (entry_start = chunkdata; *entry_start; entry_start++)
158.1735 -      /* empty loop to find end of name */ ;
158.1736 +   png_ptr->chunkdata[slength] = 0x00;
158.1737 +
158.1738 +   for (entry_start = (png_bytep)png_ptr->chunkdata; *entry_start;
158.1739 +       entry_start++)
158.1740 +      /* Empty loop to find end of name */ ;
158.1741 +
158.1742     ++entry_start;
158.1743  
158.1744 -   /* a sample depth should follow the separator, and we should be on it  */
158.1745 -   if (entry_start > chunkdata + slength)
158.1746 +   /* A sample depth should follow the separator, and we should be on it  */
158.1747 +   if (entry_start > (png_bytep)png_ptr->chunkdata + slength - 2)
158.1748     {
158.1749 -      png_free(png_ptr, chunkdata);
158.1750 +      png_free(png_ptr, png_ptr->chunkdata);
158.1751 +      png_ptr->chunkdata = NULL;
158.1752        png_warning(png_ptr, "malformed sPLT chunk");
158.1753        return;
158.1754     }
158.1755  
158.1756     new_palette.depth = *entry_start++;
158.1757     entry_size = (new_palette.depth == 8 ? 6 : 10);
158.1758 -   data_length = (slength - (entry_start - chunkdata));
158.1759 -
158.1760 -   /* integrity-check the data length */
158.1761 +   /* This must fit in a png_uint_32 because it is derived from the original
158.1762 +    * chunk data length (and use 'length', not 'slength' here for clarity -
158.1763 +    * they are guaranteed to be the same, see the tests above.)
158.1764 +    */
158.1765 +   data_length = length - (png_uint_32)(entry_start -
158.1766 +      (png_bytep)png_ptr->chunkdata);
158.1767 +
158.1768 +   /* Integrity-check the data length */
158.1769     if (data_length % entry_size)
158.1770     {
158.1771 -      png_free(png_ptr, chunkdata);
158.1772 +      png_free(png_ptr, png_ptr->chunkdata);
158.1773 +      png_ptr->chunkdata = NULL;
158.1774        png_warning(png_ptr, "sPLT chunk has bad length");
158.1775        return;
158.1776     }
158.1777  
158.1778 -   new_palette.nentries = (png_int_32) ( data_length / entry_size);
158.1779 -   if ((png_uint_32) new_palette.nentries > (png_uint_32) (PNG_SIZE_MAX /
158.1780 -       png_sizeof(png_sPLT_entry)))
158.1781 +   dl = (png_int_32)(data_length / entry_size);
158.1782 +   max_dl = PNG_SIZE_MAX / png_sizeof(png_sPLT_entry);
158.1783 +
158.1784 +   if (dl > max_dl)
158.1785     {
158.1786         png_warning(png_ptr, "sPLT chunk too long");
158.1787         return;
158.1788     }
158.1789 +
158.1790 +   new_palette.nentries = (png_int_32)(data_length / entry_size);
158.1791 +
158.1792     new_palette.entries = (png_sPLT_entryp)png_malloc_warn(
158.1793         png_ptr, new_palette.nentries * png_sizeof(png_sPLT_entry));
158.1794 +
158.1795     if (new_palette.entries == NULL)
158.1796     {
158.1797         png_warning(png_ptr, "sPLT chunk requires too much memory");
158.1798         return;
158.1799     }
158.1800  
158.1801 -#ifndef PNG_NO_POINTER_INDEXING
158.1802 +#ifdef PNG_POINTER_INDEXING_SUPPORTED
158.1803     for (i = 0; i < new_palette.nentries; i++)
158.1804     {
158.1805 -      png_sPLT_entryp pp = new_palette.entries + i;
158.1806 +      pp = new_palette.entries + i;
158.1807  
158.1808        if (new_palette.depth == 8)
158.1809        {
158.1810 -          pp->red = *entry_start++;
158.1811 -          pp->green = *entry_start++;
158.1812 -          pp->blue = *entry_start++;
158.1813 -          pp->alpha = *entry_start++;
158.1814 +         pp->red = *entry_start++;
158.1815 +         pp->green = *entry_start++;
158.1816 +         pp->blue = *entry_start++;
158.1817 +         pp->alpha = *entry_start++;
158.1818        }
158.1819 +
158.1820        else
158.1821        {
158.1822 -          pp->red   = png_get_uint_16(entry_start); entry_start += 2;
158.1823 -          pp->green = png_get_uint_16(entry_start); entry_start += 2;
158.1824 -          pp->blue  = png_get_uint_16(entry_start); entry_start += 2;
158.1825 -          pp->alpha = png_get_uint_16(entry_start); entry_start += 2;
158.1826 +         pp->red   = png_get_uint_16(entry_start); entry_start += 2;
158.1827 +         pp->green = png_get_uint_16(entry_start); entry_start += 2;
158.1828 +         pp->blue  = png_get_uint_16(entry_start); entry_start += 2;
158.1829 +         pp->alpha = png_get_uint_16(entry_start); entry_start += 2;
158.1830        }
158.1831 +
158.1832        pp->frequency = png_get_uint_16(entry_start); entry_start += 2;
158.1833     }
158.1834  #else
158.1835     pp = new_palette.entries;
158.1836 +
158.1837     for (i = 0; i < new_palette.nentries; i++)
158.1838     {
158.1839  
158.1840        if (new_palette.depth == 8)
158.1841        {
158.1842 -          pp[i].red   = *entry_start++;
158.1843 -          pp[i].green = *entry_start++;
158.1844 -          pp[i].blue  = *entry_start++;
158.1845 -          pp[i].alpha = *entry_start++;
158.1846 +         pp[i].red   = *entry_start++;
158.1847 +         pp[i].green = *entry_start++;
158.1848 +         pp[i].blue  = *entry_start++;
158.1849 +         pp[i].alpha = *entry_start++;
158.1850        }
158.1851 +
158.1852        else
158.1853        {
158.1854 -          pp[i].red   = png_get_uint_16(entry_start); entry_start += 2;
158.1855 -          pp[i].green = png_get_uint_16(entry_start); entry_start += 2;
158.1856 -          pp[i].blue  = png_get_uint_16(entry_start); entry_start += 2;
158.1857 -          pp[i].alpha = png_get_uint_16(entry_start); entry_start += 2;
158.1858 +         pp[i].red   = png_get_uint_16(entry_start); entry_start += 2;
158.1859 +         pp[i].green = png_get_uint_16(entry_start); entry_start += 2;
158.1860 +         pp[i].blue  = png_get_uint_16(entry_start); entry_start += 2;
158.1861 +         pp[i].alpha = png_get_uint_16(entry_start); entry_start += 2;
158.1862        }
158.1863 -      pp->frequency = png_get_uint_16(entry_start); entry_start += 2;
158.1864 +
158.1865 +      pp[i].frequency = png_get_uint_16(entry_start); entry_start += 2;
158.1866     }
158.1867  #endif
158.1868  
158.1869 -   /* discard all chunk data except the name and stash that */
158.1870 -   new_palette.name = (png_charp)chunkdata;
158.1871 +   /* Discard all chunk data except the name and stash that */
158.1872 +   new_palette.name = png_ptr->chunkdata;
158.1873  
158.1874     png_set_sPLT(png_ptr, info_ptr, &new_palette, 1);
158.1875  
158.1876 -   png_free(png_ptr, chunkdata);
158.1877 +   png_free(png_ptr, png_ptr->chunkdata);
158.1878 +   png_ptr->chunkdata = NULL;
158.1879     png_free(png_ptr, new_palette.entries);
158.1880  }
158.1881  #endif /* PNG_READ_sPLT_SUPPORTED */
158.1882  
158.1883 -#if defined(PNG_READ_tRNS_SUPPORTED)
158.1884 +#ifdef PNG_READ_tRNS_SUPPORTED
158.1885  void /* PRIVATE */
158.1886  png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
158.1887  {
158.1888     png_byte readbuf[PNG_MAX_PALETTE_LENGTH];
158.1889  
158.1890 -   png_debug(1, "in png_handle_tRNS\n");
158.1891 +   png_debug(1, "in png_handle_tRNS");
158.1892  
158.1893     if (!(png_ptr->mode & PNG_HAVE_IHDR))
158.1894        png_error(png_ptr, "Missing IHDR before tRNS");
158.1895 +
158.1896     else if (png_ptr->mode & PNG_HAVE_IDAT)
158.1897     {
158.1898        png_warning(png_ptr, "Invalid tRNS after IDAT");
158.1899        png_crc_finish(png_ptr, length);
158.1900        return;
158.1901     }
158.1902 +
158.1903     else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
158.1904     {
158.1905        png_warning(png_ptr, "Duplicate tRNS chunk");
158.1906 @@ -1293,8 +1527,9 @@
158.1907  
158.1908        png_crc_read(png_ptr, buf, 2);
158.1909        png_ptr->num_trans = 1;
158.1910 -      png_ptr->trans_values.gray = png_get_uint_16(buf);
158.1911 +      png_ptr->trans_color.gray = png_get_uint_16(buf);
158.1912     }
158.1913 +
158.1914     else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
158.1915     {
158.1916        png_byte buf[6];
158.1917 @@ -1305,12 +1540,14 @@
158.1918           png_crc_finish(png_ptr, length);
158.1919           return;
158.1920        }
158.1921 +
158.1922        png_crc_read(png_ptr, buf, (png_size_t)length);
158.1923        png_ptr->num_trans = 1;
158.1924 -      png_ptr->trans_values.red = png_get_uint_16(buf);
158.1925 -      png_ptr->trans_values.green = png_get_uint_16(buf + 2);
158.1926 -      png_ptr->trans_values.blue = png_get_uint_16(buf + 4);
158.1927 +      png_ptr->trans_color.red = png_get_uint_16(buf);
158.1928 +      png_ptr->trans_color.green = png_get_uint_16(buf + 2);
158.1929 +      png_ptr->trans_color.blue = png_get_uint_16(buf + 4);
158.1930     }
158.1931 +
158.1932     else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
158.1933     {
158.1934        if (!(png_ptr->mode & PNG_HAVE_PLTE))
158.1935 @@ -1318,6 +1555,7 @@
158.1936           /* Should be an error, but we can cope with it. */
158.1937           png_warning(png_ptr, "Missing PLTE before tRNS");
158.1938        }
158.1939 +
158.1940        if (length > (png_uint_32)png_ptr->num_palette ||
158.1941            length > PNG_MAX_PALETTE_LENGTH)
158.1942        {
158.1943 @@ -1325,15 +1563,18 @@
158.1944           png_crc_finish(png_ptr, length);
158.1945           return;
158.1946        }
158.1947 +
158.1948        if (length == 0)
158.1949        {
158.1950           png_warning(png_ptr, "Zero length tRNS chunk");
158.1951           png_crc_finish(png_ptr, length);
158.1952           return;
158.1953        }
158.1954 +
158.1955        png_crc_read(png_ptr, readbuf, (png_size_t)length);
158.1956        png_ptr->num_trans = (png_uint_16)length;
158.1957     }
158.1958 +
158.1959     else
158.1960     {
158.1961        png_warning(png_ptr, "tRNS chunk not allowed with alpha channel");
158.1962 @@ -1348,34 +1589,38 @@
158.1963     }
158.1964  
158.1965     png_set_tRNS(png_ptr, info_ptr, readbuf, png_ptr->num_trans,
158.1966 -      &(png_ptr->trans_values));
158.1967 +       &(png_ptr->trans_color));
158.1968  }
158.1969  #endif
158.1970  
158.1971 -#if defined(PNG_READ_bKGD_SUPPORTED)
158.1972 +#ifdef PNG_READ_bKGD_SUPPORTED
158.1973  void /* PRIVATE */
158.1974  png_handle_bKGD(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
158.1975  {
158.1976     png_size_t truelen;
158.1977     png_byte buf[6];
158.1978 -
158.1979 -   png_debug(1, "in png_handle_bKGD\n");
158.1980 +   png_color_16 background;
158.1981 +
158.1982 +   png_debug(1, "in png_handle_bKGD");
158.1983  
158.1984     if (!(png_ptr->mode & PNG_HAVE_IHDR))
158.1985        png_error(png_ptr, "Missing IHDR before bKGD");
158.1986 +
158.1987     else if (png_ptr->mode & PNG_HAVE_IDAT)
158.1988     {
158.1989        png_warning(png_ptr, "Invalid bKGD after IDAT");
158.1990        png_crc_finish(png_ptr, length);
158.1991        return;
158.1992     }
158.1993 +
158.1994     else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
158.1995 -            !(png_ptr->mode & PNG_HAVE_PLTE))
158.1996 +       !(png_ptr->mode & PNG_HAVE_PLTE))
158.1997     {
158.1998        png_warning(png_ptr, "Missing PLTE before bKGD");
158.1999        png_crc_finish(png_ptr, length);
158.2000        return;
158.2001     }
158.2002 +
158.2003     else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD))
158.2004     {
158.2005        png_warning(png_ptr, "Duplicate bKGD chunk");
158.2006 @@ -1385,8 +1630,10 @@
158.2007  
158.2008     if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
158.2009        truelen = 1;
158.2010 +
158.2011     else if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
158.2012        truelen = 6;
158.2013 +
158.2014     else
158.2015        truelen = 2;
158.2016  
158.2017 @@ -1398,72 +1645,86 @@
158.2018     }
158.2019  
158.2020     png_crc_read(png_ptr, buf, truelen);
158.2021 +
158.2022     if (png_crc_finish(png_ptr, 0))
158.2023        return;
158.2024  
158.2025     /* We convert the index value into RGB components so that we can allow
158.2026      * arbitrary RGB values for background when we have transparency, and
158.2027      * so it is easy to determine the RGB values of the background color
158.2028 -    * from the info_ptr struct. */
158.2029 +    * from the info_ptr struct.
158.2030 +    */
158.2031     if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
158.2032     {
158.2033 -      png_ptr->background.index = buf[0];
158.2034 -      if(info_ptr->num_palette)
158.2035 +      background.index = buf[0];
158.2036 +
158.2037 +      if (info_ptr && info_ptr->num_palette)
158.2038        {
158.2039 -          if(buf[0] > info_ptr->num_palette)
158.2040 -          {
158.2041 -             png_warning(png_ptr, "Incorrect bKGD chunk index value");
158.2042 -             return;
158.2043 -          }
158.2044 -          png_ptr->background.red =
158.2045 -             (png_uint_16)png_ptr->palette[buf[0]].red;
158.2046 -          png_ptr->background.green =
158.2047 -             (png_uint_16)png_ptr->palette[buf[0]].green;
158.2048 -          png_ptr->background.blue =
158.2049 -             (png_uint_16)png_ptr->palette[buf[0]].blue;
158.2050 +         if (buf[0] >= info_ptr->num_palette)
158.2051 +         {
158.2052 +            png_warning(png_ptr, "Incorrect bKGD chunk index value");
158.2053 +            return;
158.2054 +         }
158.2055 +
158.2056 +         background.red = (png_uint_16)png_ptr->palette[buf[0]].red;
158.2057 +         background.green = (png_uint_16)png_ptr->palette[buf[0]].green;
158.2058 +         background.blue = (png_uint_16)png_ptr->palette[buf[0]].blue;
158.2059        }
158.2060 +
158.2061 +      else
158.2062 +         background.red = background.green = background.blue = 0;
158.2063 +
158.2064 +      background.gray = 0;
158.2065     }
158.2066 +
158.2067     else if (!(png_ptr->color_type & PNG_COLOR_MASK_COLOR)) /* GRAY */
158.2068     {
158.2069 -      png_ptr->background.red =
158.2070 -      png_ptr->background.green =
158.2071 -      png_ptr->background.blue =
158.2072 -      png_ptr->background.gray = png_get_uint_16(buf);
158.2073 +      background.index = 0;
158.2074 +      background.red =
158.2075 +      background.green =
158.2076 +      background.blue =
158.2077 +      background.gray = png_get_uint_16(buf);
158.2078     }
158.2079 +
158.2080     else
158.2081     {
158.2082 -      png_ptr->background.red = png_get_uint_16(buf);
158.2083 -      png_ptr->background.green = png_get_uint_16(buf + 2);
158.2084 -      png_ptr->background.blue = png_get_uint_16(buf + 4);
158.2085 +      background.index = 0;
158.2086 +      background.red = png_get_uint_16(buf);
158.2087 +      background.green = png_get_uint_16(buf + 2);
158.2088 +      background.blue = png_get_uint_16(buf + 4);
158.2089 +      background.gray = 0;
158.2090     }
158.2091  
158.2092 -   png_set_bKGD(png_ptr, info_ptr, &(png_ptr->background));
158.2093 +   png_set_bKGD(png_ptr, info_ptr, &background);
158.2094  }
158.2095  #endif
158.2096  
158.2097 -#if defined(PNG_READ_hIST_SUPPORTED)
158.2098 +#ifdef PNG_READ_hIST_SUPPORTED
158.2099  void /* PRIVATE */
158.2100  png_handle_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
158.2101  {
158.2102     unsigned int num, i;
158.2103     png_uint_16 readbuf[PNG_MAX_PALETTE_LENGTH];
158.2104  
158.2105 -   png_debug(1, "in png_handle_hIST\n");
158.2106 +   png_debug(1, "in png_handle_hIST");
158.2107  
158.2108     if (!(png_ptr->mode & PNG_HAVE_IHDR))
158.2109        png_error(png_ptr, "Missing IHDR before hIST");
158.2110 +
158.2111     else if (png_ptr->mode & PNG_HAVE_IDAT)
158.2112     {
158.2113        png_warning(png_ptr, "Invalid hIST after IDAT");
158.2114        png_crc_finish(png_ptr, length);
158.2115        return;
158.2116     }
158.2117 +
158.2118     else if (!(png_ptr->mode & PNG_HAVE_PLTE))
158.2119     {
158.2120        png_warning(png_ptr, "Missing PLTE before hIST");
158.2121        png_crc_finish(png_ptr, length);
158.2122        return;
158.2123     }
158.2124 +
158.2125     else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST))
158.2126     {
158.2127        png_warning(png_ptr, "Duplicate hIST chunk");
158.2128 @@ -1472,8 +1733,9 @@
158.2129     }
158.2130  
158.2131     num = length / 2 ;
158.2132 -   if (num != (unsigned int) png_ptr->num_palette || num >
158.2133 -      (unsigned int) PNG_MAX_PALETTE_LENGTH)
158.2134 +
158.2135 +   if (num != (unsigned int)png_ptr->num_palette || num >
158.2136 +       (unsigned int)PNG_MAX_PALETTE_LENGTH)
158.2137     {
158.2138        png_warning(png_ptr, "Incorrect hIST chunk length");
158.2139        png_crc_finish(png_ptr, length);
158.2140 @@ -1495,7 +1757,7 @@
158.2141  }
158.2142  #endif
158.2143  
158.2144 -#if defined(PNG_READ_pHYs_SUPPORTED)
158.2145 +#ifdef PNG_READ_pHYs_SUPPORTED
158.2146  void /* PRIVATE */
158.2147  png_handle_pHYs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
158.2148  {
158.2149 @@ -1503,16 +1765,18 @@
158.2150     png_uint_32 res_x, res_y;
158.2151     int unit_type;
158.2152  
158.2153 -   png_debug(1, "in png_handle_pHYs\n");
158.2154 +   png_debug(1, "in png_handle_pHYs");
158.2155  
158.2156     if (!(png_ptr->mode & PNG_HAVE_IHDR))
158.2157        png_error(png_ptr, "Missing IHDR before pHYs");
158.2158 +
158.2159     else if (png_ptr->mode & PNG_HAVE_IDAT)
158.2160     {
158.2161        png_warning(png_ptr, "Invalid pHYs after IDAT");
158.2162        png_crc_finish(png_ptr, length);
158.2163        return;
158.2164     }
158.2165 +
158.2166     else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
158.2167     {
158.2168        png_warning(png_ptr, "Duplicate pHYs chunk");
158.2169 @@ -1528,6 +1792,7 @@
158.2170     }
158.2171  
158.2172     png_crc_read(png_ptr, buf, 9);
158.2173 +
158.2174     if (png_crc_finish(png_ptr, 0))
158.2175        return;
158.2176  
158.2177 @@ -1538,7 +1803,7 @@
158.2178  }
158.2179  #endif
158.2180  
158.2181 -#if defined(PNG_READ_oFFs_SUPPORTED)
158.2182 +#ifdef PNG_READ_oFFs_SUPPORTED
158.2183  void /* PRIVATE */
158.2184  png_handle_oFFs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
158.2185  {
158.2186 @@ -1546,16 +1811,18 @@
158.2187     png_int_32 offset_x, offset_y;
158.2188     int unit_type;
158.2189  
158.2190 -   png_debug(1, "in png_handle_oFFs\n");
158.2191 +   png_debug(1, "in png_handle_oFFs");
158.2192  
158.2193     if (!(png_ptr->mode & PNG_HAVE_IHDR))
158.2194        png_error(png_ptr, "Missing IHDR before oFFs");
158.2195 +
158.2196     else if (png_ptr->mode & PNG_HAVE_IDAT)
158.2197     {
158.2198        png_warning(png_ptr, "Invalid oFFs after IDAT");
158.2199        png_crc_finish(png_ptr, length);
158.2200        return;
158.2201     }
158.2202 +
158.2203     else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
158.2204     {
158.2205        png_warning(png_ptr, "Duplicate oFFs chunk");
158.2206 @@ -1571,6 +1838,7 @@
158.2207     }
158.2208  
158.2209     png_crc_read(png_ptr, buf, 9);
158.2210 +
158.2211     if (png_crc_finish(png_ptr, 0))
158.2212        return;
158.2213  
158.2214 @@ -1581,12 +1849,11 @@
158.2215  }
158.2216  #endif
158.2217  
158.2218 -#if defined(PNG_READ_pCAL_SUPPORTED)
158.2219 -/* read the pCAL chunk (described in the PNG Extensions document) */
158.2220 +#ifdef PNG_READ_pCAL_SUPPORTED
158.2221 +/* Read the pCAL chunk (described in the PNG Extensions document) */
158.2222  void /* PRIVATE */
158.2223  png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
158.2224  {
158.2225 -   png_charp purpose;
158.2226     png_int_32 X0, X1;
158.2227     png_byte type, nparams;
158.2228     png_charp buf, units, endptr;
158.2229 @@ -1594,16 +1861,18 @@
158.2230     png_size_t slength;
158.2231     int i;
158.2232  
158.2233 -   png_debug(1, "in png_handle_pCAL\n");
158.2234 +   png_debug(1, "in png_handle_pCAL");
158.2235  
158.2236     if (!(png_ptr->mode & PNG_HAVE_IHDR))
158.2237        png_error(png_ptr, "Missing IHDR before pCAL");
158.2238 +
158.2239     else if (png_ptr->mode & PNG_HAVE_IDAT)
158.2240     {
158.2241        png_warning(png_ptr, "Invalid pCAL after IDAT");
158.2242        png_crc_finish(png_ptr, length);
158.2243        return;
158.2244     }
158.2245 +
158.2246     else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL))
158.2247     {
158.2248        png_warning(png_ptr, "Duplicate pCAL chunk");
158.2249 @@ -1611,59 +1880,68 @@
158.2250        return;
158.2251     }
158.2252  
158.2253 -   png_debug1(2, "Allocating and reading pCAL chunk data (%lu bytes)\n",
158.2254 -      length + 1);
158.2255 -   purpose = (png_charp)png_malloc_warn(png_ptr, length + 1);
158.2256 -   if (purpose == NULL)
158.2257 -     {
158.2258 -       png_warning(png_ptr, "No memory for pCAL purpose.");
158.2259 -       return;
158.2260 -     }
158.2261 +   png_debug1(2, "Allocating and reading pCAL chunk data (%u bytes)",
158.2262 +       length + 1);
158.2263 +   png_free(png_ptr, png_ptr->chunkdata);
158.2264 +   png_ptr->chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
158.2265 +
158.2266 +   if (png_ptr->chunkdata == NULL)
158.2267 +   {
158.2268 +      png_warning(png_ptr, "No memory for pCAL purpose");
158.2269 +      return;
158.2270 +   }
158.2271 +
158.2272     slength = (png_size_t)length;
158.2273 -   png_crc_read(png_ptr, (png_bytep)purpose, slength);
158.2274 +   png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength);
158.2275  
158.2276     if (png_crc_finish(png_ptr, 0))
158.2277     {
158.2278 -      png_free(png_ptr, purpose);
158.2279 +      png_free(png_ptr, png_ptr->chunkdata);
158.2280 +      png_ptr->chunkdata = NULL;
158.2281        return;
158.2282     }
158.2283  
158.2284 -   purpose[slength] = 0x00; /* null terminate the last string */
158.2285 -
158.2286 -   png_debug(3, "Finding end of pCAL purpose string\n");
158.2287 -   for (buf = purpose; *buf; buf++)
158.2288 -      /* empty loop */ ;
158.2289 -
158.2290 -   endptr = purpose + slength;
158.2291 +   png_ptr->chunkdata[slength] = 0x00; /* Null terminate the last string */
158.2292 +
158.2293 +   png_debug(3, "Finding end of pCAL purpose string");
158.2294 +   for (buf = png_ptr->chunkdata; *buf; buf++)
158.2295 +      /* Empty loop */ ;
158.2296 +
158.2297 +   endptr = png_ptr->chunkdata + slength;
158.2298  
158.2299     /* We need to have at least 12 bytes after the purpose string
158.2300 -      in order to get the parameter information. */
158.2301 +    * in order to get the parameter information.
158.2302 +    */
158.2303     if (endptr <= buf + 12)
158.2304     {
158.2305        png_warning(png_ptr, "Invalid pCAL data");
158.2306 -      png_free(png_ptr, purpose);
158.2307 +      png_free(png_ptr, png_ptr->chunkdata);
158.2308 +      png_ptr->chunkdata = NULL;
158.2309        return;
158.2310     }
158.2311  
158.2312 -   png_debug(3, "Reading pCAL X0, X1, type, nparams, and units\n");
158.2313 +   png_debug(3, "Reading pCAL X0, X1, type, nparams, and units");
158.2314     X0 = png_get_int_32((png_bytep)buf+1);
158.2315     X1 = png_get_int_32((png_bytep)buf+5);
158.2316     type = buf[9];
158.2317     nparams = buf[10];
158.2318     units = buf + 11;
158.2319  
158.2320 -   png_debug(3, "Checking pCAL equation type and number of parameters\n");
158.2321 +   png_debug(3, "Checking pCAL equation type and number of parameters");
158.2322     /* Check that we have the right number of parameters for known
158.2323 -      equation types. */
158.2324 +    * equation types.
158.2325 +    */
158.2326     if ((type == PNG_EQUATION_LINEAR && nparams != 2) ||
158.2327         (type == PNG_EQUATION_BASE_E && nparams != 3) ||
158.2328         (type == PNG_EQUATION_ARBITRARY && nparams != 3) ||
158.2329         (type == PNG_EQUATION_HYPERBOLIC && nparams != 4))
158.2330     {
158.2331        png_warning(png_ptr, "Invalid pCAL parameters for equation type");
158.2332 -      png_free(png_ptr, purpose);
158.2333 +      png_free(png_ptr, png_ptr->chunkdata);
158.2334 +      png_ptr->chunkdata = NULL;
158.2335        return;
158.2336     }
158.2337 +
158.2338     else if (type >= PNG_EQUATION_LAST)
158.2339     {
158.2340        png_warning(png_ptr, "Unrecognized equation type for pCAL chunk");
158.2341 @@ -1672,69 +1950,69 @@
158.2342     for (buf = units; *buf; buf++)
158.2343        /* Empty loop to move past the units string. */ ;
158.2344  
158.2345 -   png_debug(3, "Allocating pCAL parameters array\n");
158.2346 -   params = (png_charpp)png_malloc_warn(png_ptr, (png_uint_32)(nparams
158.2347 -      *png_sizeof(png_charp))) ;
158.2348 +   png_debug(3, "Allocating pCAL parameters array");
158.2349 +
158.2350 +   params = (png_charpp)png_malloc_warn(png_ptr,
158.2351 +       (png_size_t)(nparams * png_sizeof(png_charp)));
158.2352 +
158.2353     if (params == NULL)
158.2354 -     {
158.2355 -       png_free(png_ptr, purpose);
158.2356 -       png_warning(png_ptr, "No memory for pCAL params.");
158.2357 -       return;
158.2358 -     }
158.2359 +   {
158.2360 +      png_free(png_ptr, png_ptr->chunkdata);
158.2361 +      png_ptr->chunkdata = NULL;
158.2362 +      png_warning(png_ptr, "No memory for pCAL params");
158.2363 +      return;
158.2364 +   }
158.2365  
158.2366     /* Get pointers to the start of each parameter string. */
158.2367     for (i = 0; i < (int)nparams; i++)
158.2368     {
158.2369        buf++; /* Skip the null string terminator from previous parameter. */
158.2370  
158.2371 -      png_debug1(3, "Reading pCAL parameter %d\n", i);
158.2372 -      for (params[i] = buf; *buf != 0x00 && buf <= endptr; buf++)
158.2373 +      png_debug1(3, "Reading pCAL parameter %d", i);
158.2374 +
158.2375 +      for (params[i] = buf; buf <= endptr && *buf != 0x00; buf++)
158.2376           /* Empty loop to move past each parameter string */ ;
158.2377  
158.2378        /* Make sure we haven't run out of data yet */
158.2379        if (buf > endptr)
158.2380        {
158.2381           png_warning(png_ptr, "Invalid pCAL data");
158.2382 -         png_free(png_ptr, purpose);
158.2383 +         png_free(png_ptr, png_ptr->chunkdata);
158.2384 +         png_ptr->chunkdata = NULL;
158.2385           png_free(png_ptr, params);
158.2386           return;
158.2387        }
158.2388     }
158.2389  
158.2390 -   png_set_pCAL(png_ptr, info_ptr, purpose, X0, X1, type, nparams,
158.2391 +   png_set_pCAL(png_ptr, info_ptr, png_ptr->chunkdata, X0, X1, type, nparams,
158.2392        units, params);
158.2393  
158.2394 -   png_free(png_ptr, purpose);
158.2395 +   png_free(png_ptr, png_ptr->chunkdata);
158.2396 +   png_ptr->chunkdata = NULL;
158.2397     png_free(png_ptr, params);
158.2398  }
158.2399  #endif
158.2400  
158.2401 -#if defined(PNG_READ_sCAL_SUPPORTED)
158.2402 -/* read the sCAL chunk */
158.2403 +#ifdef PNG_READ_sCAL_SUPPORTED
158.2404 +/* Read the sCAL chunk */
158.2405  void /* PRIVATE */
158.2406  png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
158.2407  {
158.2408 -   png_charp buffer, ep;
158.2409 -#ifdef PNG_FLOATING_POINT_SUPPORTED
158.2410 -   double width, height;
158.2411 -   png_charp vp;
158.2412 -#else
158.2413 -#ifdef PNG_FIXED_POINT_SUPPORTED
158.2414 -   png_charp swidth, sheight;
158.2415 -#endif
158.2416 -#endif
158.2417 -   png_size_t slength;
158.2418 -
158.2419 -   png_debug(1, "in png_handle_sCAL\n");
158.2420 +   png_size_t slength, i;
158.2421 +   int state;
158.2422 +
158.2423 +   png_debug(1, "in png_handle_sCAL");
158.2424  
158.2425     if (!(png_ptr->mode & PNG_HAVE_IHDR))
158.2426        png_error(png_ptr, "Missing IHDR before sCAL");
158.2427 +
158.2428     else if (png_ptr->mode & PNG_HAVE_IDAT)
158.2429     {
158.2430        png_warning(png_ptr, "Invalid sCAL after IDAT");
158.2431        png_crc_finish(png_ptr, length);
158.2432        return;
158.2433     }
158.2434 +
158.2435     else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sCAL))
158.2436     {
158.2437        png_warning(png_ptr, "Duplicate sCAL chunk");
158.2438 @@ -1742,112 +2020,96 @@
158.2439        return;
158.2440     }
158.2441  
158.2442 -   png_debug1(2, "Allocating and reading sCAL chunk data (%lu bytes)\n",
158.2443 +   /* Need unit type, width, \0, height: minimum 4 bytes */
158.2444 +   else if (length < 4)
158.2445 +   {
158.2446 +      png_warning(png_ptr, "sCAL chunk too short");
158.2447 +      png_crc_finish(png_ptr, length);
158.2448 +      return;
158.2449 +   }
158.2450 +
158.2451 +   png_debug1(2, "Allocating and reading sCAL chunk data (%u bytes)",
158.2452        length + 1);
158.2453 -   buffer = (png_charp)png_malloc_warn(png_ptr, length + 1);
158.2454 -   if (buffer == NULL)
158.2455 -     {
158.2456 -       png_warning(png_ptr, "Out of memory while processing sCAL chunk");
158.2457 -       return;
158.2458 -     }
158.2459 +
158.2460 +   png_ptr->chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
158.2461 +
158.2462 +   if (png_ptr->chunkdata == NULL)
158.2463 +   {
158.2464 +      png_warning(png_ptr, "Out of memory while processing sCAL chunk");
158.2465 +      png_crc_finish(png_ptr, length);
158.2466 +      return;
158.2467 +   }
158.2468 +
158.2469     slength = (png_size_t)length;
158.2470 -   png_crc_read(png_ptr, (png_bytep)buffer, slength);
158.2471 +   png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength);
158.2472 +   png_ptr->chunkdata[slength] = 0x00; /* Null terminate the last string */
158.2473  
158.2474     if (png_crc_finish(png_ptr, 0))
158.2475     {
158.2476 -      png_free(png_ptr, buffer);
158.2477 +      png_free(png_ptr, png_ptr->chunkdata);
158.2478 +      png_ptr->chunkdata = NULL;
158.2479        return;
158.2480     }
158.2481  
158.2482 -   buffer[slength] = 0x00; /* null terminate the last string */
158.2483 -
158.2484 -   ep = buffer + 1;        /* skip unit byte */
158.2485 -
158.2486 -#ifdef PNG_FLOATING_POINT_SUPPORTED
158.2487 -   width = png_strtod(png_ptr, ep, &vp);
158.2488 -   if (*vp)
158.2489 +   /* Validate the unit. */
158.2490 +   if (png_ptr->chunkdata[0] != 1 && png_ptr->chunkdata[0] != 2)
158.2491     {
158.2492 -       png_warning(png_ptr, "malformed width string in sCAL chunk");
158.2493 -       return;
158.2494 -   }
158.2495 -#else
158.2496 -#ifdef PNG_FIXED_POINT_SUPPORTED
158.2497 -   swidth = (png_charp)png_malloc_warn(png_ptr, png_strlen(ep) + 1);
158.2498 -   if (swidth == NULL)
158.2499 -     {
158.2500 -       png_warning(png_ptr, "Out of memory while processing sCAL chunk width");
158.2501 -       return;
158.2502 -     }
158.2503 -   png_memcpy(swidth, ep, (png_size_t)png_strlen(ep));
158.2504 -#endif
158.2505 -#endif
158.2506 -
158.2507 -   for (ep = buffer; *ep; ep++)
158.2508 -      /* empty loop */ ;
158.2509 -   ep++;
158.2510 -
158.2511 -#ifdef PNG_FLOATING_POINT_SUPPORTED
158.2512 -   height = png_strtod(png_ptr, ep, &vp);
158.2513 -   if (*vp)
158.2514 -   {
158.2515 -       png_warning(png_ptr, "malformed height string in sCAL chunk");
158.2516 -       return;
158.2517 -   }
158.2518 -#else
158.2519 -#ifdef PNG_FIXED_POINT_SUPPORTED
158.2520 -   sheight = (png_charp)png_malloc_warn(png_ptr, png_strlen(ep) + 1);
158.2521 -   if (swidth == NULL)
158.2522 -     {
158.2523 -       png_warning(png_ptr, "Out of memory while processing sCAL chunk height");
158.2524 -       return;
158.2525 -     }
158.2526 -   png_memcpy(sheight, ep, (png_size_t)png_strlen(ep));
158.2527 -#endif
158.2528 -#endif
158.2529 -
158.2530 -   if (buffer + slength < ep
158.2531 -#ifdef PNG_FLOATING_POINT_SUPPORTED
158.2532 -      || width <= 0. || height <= 0.
158.2533 -#endif
158.2534 -      )
158.2535 -   {
158.2536 -      png_warning(png_ptr, "Invalid sCAL data");
158.2537 -      png_free(png_ptr, buffer);
158.2538 -#if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
158.2539 -      png_free(png_ptr, swidth);
158.2540 -      png_free(png_ptr, sheight);
158.2541 -#endif
158.2542 +      png_warning(png_ptr, "Invalid sCAL ignored: invalid unit");
158.2543 +      png_free(png_ptr, png_ptr->chunkdata);
158.2544 +      png_ptr->chunkdata = NULL;
158.2545        return;
158.2546     }
158.2547  
158.2548 -
158.2549 -#ifdef PNG_FLOATING_POINT_SUPPORTED
158.2550 -   png_set_sCAL(png_ptr, info_ptr, buffer[0], width, height);
158.2551 -#else
158.2552 -#ifdef PNG_FIXED_POINT_SUPPORTED
158.2553 -   png_set_sCAL_s(png_ptr, info_ptr, buffer[0], swidth, sheight);
158.2554 -#endif
158.2555 -#endif
158.2556 -
158.2557 -   png_free(png_ptr, buffer);
158.2558 -#if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
158.2559 -   png_free(png_ptr, swidth);
158.2560 -   png_free(png_ptr, sheight);
158.2561 -#endif
158.2562 +   /* Validate the ASCII numbers, need two ASCII numbers separated by
158.2563 +    * a '\0' and they need to fit exactly in the chunk data.
158.2564 +    */
158.2565 +   i = 1;
158.2566 +   state = 0;
158.2567 +
158.2568 +   if (!png_check_fp_number(png_ptr->chunkdata, slength, &state, &i) ||
158.2569 +       i >= slength || png_ptr->chunkdata[i++] != 0)
158.2570 +      png_warning(png_ptr, "Invalid sCAL chunk ignored: bad width format");
158.2571 +
158.2572 +   else if (!PNG_FP_IS_POSITIVE(state))
158.2573 +      png_warning(png_ptr, "Invalid sCAL chunk ignored: non-positive width");
158.2574 +
158.2575 +   else
158.2576 +   {
158.2577 +      png_size_t heighti = i;
158.2578 +
158.2579 +      state = 0;
158.2580 +      if (!png_check_fp_number(png_ptr->chunkdata, slength, &state, &i) ||
158.2581 +          i != slength)
158.2582 +         png_warning(png_ptr, "Invalid sCAL chunk ignored: bad height format");
158.2583 +
158.2584 +      else if (!PNG_FP_IS_POSITIVE(state))
158.2585 +         png_warning(png_ptr,
158.2586 +            "Invalid sCAL chunk ignored: non-positive height");
158.2587 +
158.2588 +      else
158.2589 +         /* This is the (only) success case. */
158.2590 +         png_set_sCAL_s(png_ptr, info_ptr, png_ptr->chunkdata[0],
158.2591 +            png_ptr->chunkdata+1, png_ptr->chunkdata+heighti);
158.2592 +   }
158.2593 +
158.2594 +   /* Clean up - just free the temporarily allocated buffer. */
158.2595 +   png_free(png_ptr, png_ptr->chunkdata);
158.2596 +   png_ptr->chunkdata = NULL;
158.2597  }
158.2598  #endif
158.2599  
158.2600 -#if defined(PNG_READ_tIME_SUPPORTED)
158.2601 +#ifdef PNG_READ_tIME_SUPPORTED
158.2602  void /* PRIVATE */
158.2603  png_handle_tIME(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
158.2604  {
158.2605     png_byte buf[7];
158.2606     png_time mod_time;
158.2607  
158.2608 -   png_debug(1, "in png_handle_tIME\n");
158.2609 +   png_debug(1, "in png_handle_tIME");
158.2610  
158.2611     if (!(png_ptr->mode & PNG_HAVE_IHDR))
158.2612        png_error(png_ptr, "Out of place tIME chunk");
158.2613 +
158.2614     else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME))
158.2615     {
158.2616        png_warning(png_ptr, "Duplicate tIME chunk");
158.2617 @@ -1866,6 +2128,7 @@
158.2618     }
158.2619  
158.2620     png_crc_read(png_ptr, buf, 7);
158.2621 +
158.2622     if (png_crc_finish(png_ptr, 0))
158.2623        return;
158.2624  
158.2625 @@ -1880,7 +2143,7 @@
158.2626  }
158.2627  #endif
158.2628  
158.2629 -#if defined(PNG_READ_tEXt_SUPPORTED)
158.2630 +#ifdef PNG_READ_tEXt_SUPPORTED
158.2631  /* Note: this does not properly handle chunks that are > 64K under DOS */
158.2632  void /* PRIVATE */
158.2633  png_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
158.2634 @@ -1892,7 +2155,25 @@
158.2635     png_size_t slength;
158.2636     int ret;
158.2637  
158.2638 -   png_debug(1, "in png_handle_tEXt\n");
158.2639 +   png_debug(1, "in png_handle_tEXt");
158.2640 +
158.2641 +#ifdef PNG_USER_LIMITS_SUPPORTED
158.2642 +   if (png_ptr->user_chunk_cache_max != 0)
158.2643 +   {
158.2644 +      if (png_ptr->user_chunk_cache_max == 1)
158.2645 +      {
158.2646 +         png_crc_finish(png_ptr, length);
158.2647 +         return;
158.2648 +      }
158.2649 +
158.2650 +      if (--png_ptr->user_chunk_cache_max == 1)
158.2651 +      {
158.2652 +         png_warning(png_ptr, "No space in chunk cache for tEXt");
158.2653 +         png_crc_finish(png_ptr, length);
158.2654 +         return;
158.2655 +      }
158.2656 +   }
158.2657 +#endif
158.2658  
158.2659     if (!(png_ptr->mode & PNG_HAVE_IHDR))
158.2660        png_error(png_ptr, "Missing IHDR before tEXt");
158.2661 @@ -1909,69 +2190,97 @@
158.2662     }
158.2663  #endif
158.2664  
158.2665 -   key = (png_charp)png_malloc_warn(png_ptr, length + 1);
158.2666 -   if (key == NULL)
158.2667 +   png_free(png_ptr, png_ptr->chunkdata);
158.2668 +
158.2669 +   png_ptr->chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
158.2670 +
158.2671 +   if (png_ptr->chunkdata == NULL)
158.2672     {
158.2673 -     png_warning(png_ptr, "No memory to process text chunk.");
158.2674 +     png_warning(png_ptr, "No memory to process text chunk");
158.2675       return;
158.2676     }
158.2677 +
158.2678     slength = (png_size_t)length;
158.2679 -   png_crc_read(png_ptr, (png_bytep)key, slength);
158.2680 +   png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength);
158.2681  
158.2682     if (png_crc_finish(png_ptr, skip))
158.2683     {
158.2684 -      png_free(png_ptr, key);
158.2685 +      png_free(png_ptr, png_ptr->chunkdata);
158.2686 +      png_ptr->chunkdata = NULL;
158.2687        return;
158.2688     }
158.2689  
158.2690 +   key = png_ptr->chunkdata;
158.2691 +
158.2692     key[slength] = 0x00;
158.2693  
158.2694     for (text = key; *text; text++)
158.2695 -      /* empty loop to find end of key */ ;
158.2696 +      /* Empty loop to find end of key */ ;
158.2697  
158.2698     if (text != key + slength)
158.2699        text++;
158.2700  
158.2701     text_ptr = (png_textp)png_malloc_warn(png_ptr,
158.2702 -      (png_uint_32)png_sizeof(png_text));
158.2703 +       png_sizeof(png_text));
158.2704 +
158.2705     if (text_ptr == NULL)
158.2706     {
158.2707 -     png_warning(png_ptr, "Not enough memory to process text chunk.");
158.2708 -     png_free(png_ptr, key);
158.2709 -     return;
158.2710 +      png_warning(png_ptr, "Not enough memory to process text chunk");
158.2711 +      png_free(png_ptr, png_ptr->chunkdata);
158.2712 +      png_ptr->chunkdata = NULL;
158.2713 +      return;
158.2714     }
158.2715 +
158.2716     text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
158.2717     text_ptr->key = key;
158.2718 -#ifdef PNG_iTXt_SUPPORTED
158.2719     text_ptr->lang = NULL;
158.2720     text_ptr->lang_key = NULL;
158.2721     text_ptr->itxt_length = 0;
158.2722 -#endif
158.2723     text_ptr->text = text;
158.2724     text_ptr->text_length = png_strlen(text);
158.2725  
158.2726 -   ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
158.2727 -
158.2728 -   png_free(png_ptr, key);
158.2729 +   ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
158.2730 +
158.2731 +   png_free(png_ptr, png_ptr->chunkdata);
158.2732 +   png_ptr->chunkdata = NULL;
158.2733     png_free(png_ptr, text_ptr);
158.2734 +
158.2735     if (ret)
158.2736 -     png_warning(png_ptr, "Insufficient memory to process text chunk.");
158.2737 +      png_warning(png_ptr, "Insufficient memory to process text chunk");
158.2738  }
158.2739  #endif
158.2740  
158.2741 -#if defined(PNG_READ_zTXt_SUPPORTED)
158.2742 -/* note: this does not correctly handle chunks that are > 64K under DOS */
158.2743 +#ifdef PNG_READ_zTXt_SUPPORTED
158.2744 +/* Note: this does not correctly handle chunks that are > 64K under DOS */
158.2745  void /* PRIVATE */
158.2746  png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
158.2747  {
158.2748     png_textp text_ptr;
158.2749 -   png_charp chunkdata;
158.2750     png_charp text;
158.2751     int comp_type;
158.2752     int ret;
158.2753     png_size_t slength, prefix_len, data_len;
158.2754  
158.2755 -   png_debug(1, "in png_handle_zTXt\n");
158.2756 +   png_debug(1, "in png_handle_zTXt");
158.2757 +
158.2758 +#ifdef PNG_USER_LIMITS_SUPPORTED
158.2759 +   if (png_ptr->user_chunk_cache_max != 0)
158.2760 +   {
158.2761 +      if (png_ptr->user_chunk_cache_max == 1)
158.2762 +      {
158.2763 +         png_crc_finish(png_ptr, length);
158.2764 +         return;
158.2765 +      }
158.2766 +
158.2767 +      if (--png_ptr->user_chunk_cache_max == 1)
158.2768 +      {
158.2769 +         png_warning(png_ptr, "No space in chunk cache for zTXt");
158.2770 +         png_crc_finish(png_ptr, length);
158.2771 +         return;
158.2772 +      }
158.2773 +   }
158.2774 +#endif
158.2775 +
158.2776     if (!(png_ptr->mode & PNG_HAVE_IHDR))
158.2777        png_error(png_ptr, "Missing IHDR before zTXt");
158.2778  
158.2779 @@ -1980,96 +2289,128 @@
158.2780  
158.2781  #ifdef PNG_MAX_MALLOC_64K
158.2782     /* We will no doubt have problems with chunks even half this size, but
158.2783 -      there is no hard and fast rule to tell us where to stop. */
158.2784 +    * there is no hard and fast rule to tell us where to stop.
158.2785 +    */
158.2786     if (length > (png_uint_32)65535L)
158.2787     {
158.2788 -     png_warning(png_ptr,"zTXt chunk too large to fit in memory");
158.2789 -     png_crc_finish(png_ptr, length);
158.2790 -     return;
158.2791 +      png_warning(png_ptr, "zTXt chunk too large to fit in memory");
158.2792 +      png_crc_finish(png_ptr, length);
158.2793 +      return;
158.2794     }
158.2795  #endif
158.2796  
158.2797 -   chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
158.2798 -   if (chunkdata == NULL)
158.2799 +   png_free(png_ptr, png_ptr->chunkdata);
158.2800 +   png_ptr->chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
158.2801 +
158.2802 +   if (png_ptr->chunkdata == NULL)
158.2803     {
158.2804 -     png_warning(png_ptr,"Out of memory processing zTXt chunk.");
158.2805 -     return;
158.2806 +      png_warning(png_ptr, "Out of memory processing zTXt chunk");
158.2807 +      return;
158.2808     }
158.2809 +
158.2810     slength = (png_size_t)length;
158.2811 -   png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
158.2812 +   png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength);
158.2813 +
158.2814     if (png_crc_finish(png_ptr, 0))
158.2815     {
158.2816 -      png_free(png_ptr, chunkdata);
158.2817 +      png_free(png_ptr, png_ptr->chunkdata);
158.2818 +      png_ptr->chunkdata = NULL;
158.2819        return;
158.2820     }
158.2821  
158.2822 -   chunkdata[slength] = 0x00;
158.2823 -
158.2824 -   for (text = chunkdata; *text; text++)
158.2825 -      /* empty loop */ ;
158.2826 +   png_ptr->chunkdata[slength] = 0x00;
158.2827 +
158.2828 +   for (text = png_ptr->chunkdata; *text; text++)
158.2829 +      /* Empty loop */ ;
158.2830  
158.2831     /* zTXt must have some text after the chunkdataword */
158.2832 -   if (text == chunkdata + slength)
158.2833 +   if (text >= png_ptr->chunkdata + slength - 2)
158.2834     {
158.2835 -      comp_type = PNG_TEXT_COMPRESSION_NONE;
158.2836 -      png_warning(png_ptr, "Zero length zTXt chunk");
158.2837 +      png_warning(png_ptr, "Truncated zTXt chunk");
158.2838 +      png_free(png_ptr, png_ptr->chunkdata);
158.2839 +      png_ptr->chunkdata = NULL;
158.2840 +      return;
158.2841     }
158.2842 +
158.2843     else
158.2844     {
158.2845         comp_type = *(++text);
158.2846 +
158.2847         if (comp_type != PNG_TEXT_COMPRESSION_zTXt)
158.2848         {
158.2849            png_warning(png_ptr, "Unknown compression type in zTXt chunk");
158.2850            comp_type = PNG_TEXT_COMPRESSION_zTXt;
158.2851         }
158.2852 -       text++;        /* skip the compression_method byte */
158.2853 +
158.2854 +       text++;        /* Skip the compression_method byte */
158.2855     }
158.2856 -   prefix_len = text - chunkdata;
158.2857 -
158.2858 -   chunkdata = (png_charp)png_decompress_chunk(png_ptr, comp_type, chunkdata,
158.2859 -                                    (png_size_t)length, prefix_len, &data_len);
158.2860 +
158.2861 +   prefix_len = text - png_ptr->chunkdata;
158.2862 +
158.2863 +   png_decompress_chunk(png_ptr, comp_type,
158.2864 +       (png_size_t)length, prefix_len, &data_len);
158.2865  
158.2866     text_ptr = (png_textp)png_malloc_warn(png_ptr,
158.2867 -     (png_uint_32)png_sizeof(png_text));
158.2868 +       png_sizeof(png_text));
158.2869 +
158.2870     if (text_ptr == NULL)
158.2871     {
158.2872 -     png_warning(png_ptr,"Not enough memory to process zTXt chunk.");
158.2873 -     png_free(png_ptr, chunkdata);
158.2874 -     return;
158.2875 +      png_warning(png_ptr, "Not enough memory to process zTXt chunk");
158.2876 +      png_free(png_ptr, png_ptr->chunkdata);
158.2877 +      png_ptr->chunkdata = NULL;
158.2878 +      return;
158.2879     }
158.2880 +
158.2881     text_ptr->compression = comp_type;
158.2882 -   text_ptr->key = chunkdata;
158.2883 -#ifdef PNG_iTXt_SUPPORTED
158.2884 +   text_ptr->key = png_ptr->chunkdata;
158.2885     text_ptr->lang = NULL;
158.2886     text_ptr->lang_key = NULL;
158.2887     text_ptr->itxt_length = 0;
158.2888 -#endif
158.2889 -   text_ptr->text = chunkdata + prefix_len;
158.2890 +   text_ptr->text = png_ptr->chunkdata + prefix_len;
158.2891     text_ptr->text_length = data_len;
158.2892  
158.2893 -   ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
158.2894 +   ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
158.2895  
158.2896     png_free(png_ptr, text_ptr);
158.2897 -   png_free(png_ptr, chunkdata);
158.2898 +   png_free(png_ptr, png_ptr->chunkdata);
158.2899 +   png_ptr->chunkdata = NULL;
158.2900 +
158.2901     if (ret)
158.2902 -     png_error(png_ptr, "Insufficient memory to store zTXt chunk.");
158.2903 +      png_error(png_ptr, "Insufficient memory to store zTXt chunk");
158.2904  }
158.2905  #endif
158.2906  
158.2907 -#if defined(PNG_READ_iTXt_SUPPORTED)
158.2908 -/* note: this does not correctly handle chunks that are > 64K under DOS */
158.2909 +#ifdef PNG_READ_iTXt_SUPPORTED
158.2910 +/* Note: this does not correctly handle chunks that are > 64K under DOS */
158.2911  void /* PRIVATE */
158.2912  png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
158.2913  {
158.2914     png_textp text_ptr;
158.2915 -   png_charp chunkdata;
158.2916     png_charp key, lang, text, lang_key;
158.2917     int comp_flag;
158.2918     int comp_type = 0;
158.2919     int ret;
158.2920     png_size_t slength, prefix_len, data_len;
158.2921  
158.2922 -   png_debug(1, "in png_handle_iTXt\n");
158.2923 +   png_debug(1, "in png_handle_iTXt");
158.2924 +
158.2925 +#ifdef PNG_USER_LIMITS_SUPPORTED
158.2926 +   if (png_ptr->user_chunk_cache_max != 0)
158.2927 +   {
158.2928 +      if (png_ptr->user_chunk_cache_max == 1)
158.2929 +      {
158.2930 +         png_crc_finish(png_ptr, length);
158.2931 +         return;
158.2932 +      }
158.2933 +
158.2934 +      if (--png_ptr->user_chunk_cache_max == 1)
158.2935 +      {
158.2936 +         png_warning(png_ptr, "No space in chunk cache for iTXt");
158.2937 +         png_crc_finish(png_ptr, length);
158.2938 +         return;
158.2939 +      }
158.2940 +   }
158.2941 +#endif
158.2942  
158.2943     if (!(png_ptr->mode & PNG_HAVE_IHDR))
158.2944        png_error(png_ptr, "Missing IHDR before iTXt");
158.2945 @@ -2079,193 +2420,274 @@
158.2946  
158.2947  #ifdef PNG_MAX_MALLOC_64K
158.2948     /* We will no doubt have problems with chunks even half this size, but
158.2949 -      there is no hard and fast rule to tell us where to stop. */
158.2950 +    * there is no hard and fast rule to tell us where to stop.
158.2951 +    */
158.2952     if (length > (png_uint_32)65535L)
158.2953     {
158.2954 -     png_warning(png_ptr,"iTXt chunk too large to fit in memory");
158.2955 -     png_crc_finish(png_ptr, length);
158.2956 -     return;
158.2957 +      png_warning(png_ptr, "iTXt chunk too large to fit in memory");
158.2958 +      png_crc_finish(png_ptr, length);
158.2959 +      return;
158.2960     }
158.2961  #endif
158.2962  
158.2963 -   chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
158.2964 -   if (chunkdata == NULL)
158.2965 +   png_free(png_ptr, png_ptr->chunkdata);
158.2966 +   png_ptr->chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
158.2967 +
158.2968 +   if (png_ptr->chunkdata == NULL)
158.2969     {
158.2970 -     png_warning(png_ptr, "No memory to process iTXt chunk.");
158.2971 -     return;
158.2972 +      png_warning(png_ptr, "No memory to process iTXt chunk");
158.2973 +      return;
158.2974     }
158.2975 +
158.2976     slength = (png_size_t)length;
158.2977 -   png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
158.2978 +   png_crc_read(png_ptr, (png_bytep)png_ptr->chunkdata, slength);
158.2979 +
158.2980     if (png_crc_finish(png_ptr, 0))
158.2981     {
158.2982 -      png_free(png_ptr, chunkdata);
158.2983 +      png_free(png_ptr, png_ptr->chunkdata);
158.2984 +      png_ptr->chunkdata = NULL;
158.2985        return;
158.2986     }
158.2987  
158.2988 -   chunkdata[slength] = 0x00;
158.2989 -
158.2990 -   for (lang = chunkdata; *lang; lang++)
158.2991 -      /* empty loop */ ;
158.2992 -   lang++;        /* skip NUL separator */
158.2993 +   png_ptr->chunkdata[slength] = 0x00;
158.2994 +
158.2995 +   for (lang = png_ptr->chunkdata; *lang; lang++)
158.2996 +      /* Empty loop */ ;
158.2997 +
158.2998 +   lang++;        /* Skip NUL separator */
158.2999  
158.3000     /* iTXt must have a language tag (possibly empty), two compression bytes,
158.3001 -      translated keyword (possibly empty), and possibly some text after the
158.3002 -      keyword */
158.3003 -
158.3004 -   if (lang >= chunkdata + slength)
158.3005 +    * translated keyword (possibly empty), and possibly some text after the
158.3006 +    * keyword
158.3007 +    */
158.3008 +
158.3009 +   if (lang >= png_ptr->chunkdata + slength - 3)
158.3010     {
158.3011 -      comp_flag = PNG_TEXT_COMPRESSION_NONE;
158.3012 -      png_warning(png_ptr, "Zero length iTXt chunk");
158.3013 +      png_warning(png_ptr, "Truncated iTXt chunk");
158.3014 +      png_free(png_ptr, png_ptr->chunkdata);
158.3015 +      png_ptr->chunkdata = NULL;
158.3016 +      return;
158.3017     }
158.3018 +
158.3019     else
158.3020     {
158.3021 -       comp_flag = *lang++;
158.3022 -       comp_type = *lang++;
158.3023 +      comp_flag = *lang++;
158.3024 +      comp_type = *lang++;
158.3025     }
158.3026  
158.3027     for (lang_key = lang; *lang_key; lang_key++)
158.3028 -      /* empty loop */ ;
158.3029 -   lang_key++;        /* skip NUL separator */
158.3030 +      /* Empty loop */ ;
158.3031 +
158.3032 +   lang_key++;        /* Skip NUL separator */
158.3033 +
158.3034 +   if (lang_key >= png_ptr->chunkdata + slength)
158.3035 +   {
158.3036 +      png_warning(png_ptr, "Truncated iTXt chunk");
158.3037 +      png_free(png_ptr, png_ptr->chunkdata);
158.3038 +      png_ptr->chunkdata = NULL;
158.3039 +      return;
158.3040 +   }
158.3041  
158.3042     for (text = lang_key; *text; text++)
158.3043 -      /* empty loop */ ;
158.3044 -   text++;        /* skip NUL separator */
158.3045 -
158.3046 -   prefix_len = text - chunkdata;
158.3047 -
158.3048 -   key=chunkdata;
158.3049 +      /* Empty loop */ ;
158.3050 +
158.3051 +   text++;        /* Skip NUL separator */
158.3052 +
158.3053 +   if (text >= png_ptr->chunkdata + slength)
158.3054 +   {
158.3055 +      png_warning(png_ptr, "Malformed iTXt chunk");
158.3056 +      png_free(png_ptr, png_ptr->chunkdata);
158.3057 +      png_ptr->chunkdata = NULL;
158.3058 +      return;
158.3059 +   }
158.3060 +
158.3061 +   prefix_len = text - png_ptr->chunkdata;
158.3062 +
158.3063 +   key=png_ptr->chunkdata;
158.3064 +
158.3065     if (comp_flag)
158.3066 -       chunkdata = png_decompress_chunk(png_ptr, comp_type, chunkdata,
158.3067 +      png_decompress_chunk(png_ptr, comp_type,
158.3068            (size_t)length, prefix_len, &data_len);
158.3069 +
158.3070     else
158.3071 -       data_len=png_strlen(chunkdata + prefix_len);
158.3072 +      data_len = png_strlen(png_ptr->chunkdata + prefix_len);
158.3073 +
158.3074     text_ptr = (png_textp)png_malloc_warn(png_ptr,
158.3075 -      (png_uint_32)png_sizeof(png_text));
158.3076 +       png_sizeof(png_text));
158.3077 +
158.3078     if (text_ptr == NULL)
158.3079     {
158.3080 -     png_warning(png_ptr,"Not enough memory to process iTXt chunk.");
158.3081 -     png_free(png_ptr, chunkdata);
158.3082 -     return;
158.3083 +      png_warning(png_ptr, "Not enough memory to process iTXt chunk");
158.3084 +      png_free(png_ptr, png_ptr->chunkdata);
158.3085 +      png_ptr->chunkdata = NULL;
158.3086 +      return;
158.3087     }
158.3088 +
158.3089     text_ptr->compression = (int)comp_flag + 1;
158.3090 -   text_ptr->lang_key = chunkdata+(lang_key-key);
158.3091 -   text_ptr->lang = chunkdata+(lang-key);
158.3092 +   text_ptr->lang_key = png_ptr->chunkdata + (lang_key - key);
158.3093 +   text_ptr->lang = png_ptr->chunkdata + (lang - key);
158.3094     text_ptr->itxt_length = data_len;
158.3095     text_ptr->text_length = 0;
158.3096 -   text_ptr->key = chunkdata;
158.3097 -   text_ptr->text = chunkdata + prefix_len;
158.3098 -
158.3099 -   ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
158.3100 +   text_ptr->key = png_ptr->chunkdata;
158.3101 +   text_ptr->text = png_ptr->chunkdata + prefix_len;
158.3102 +
158.3103 +   ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
158.3104  
158.3105     png_free(png_ptr, text_ptr);
158.3106 -   png_free(png_ptr, chunkdata);
158.3107 +   png_free(png_ptr, png_ptr->chunkdata);
158.3108 +   png_ptr->chunkdata = NULL;
158.3109 +
158.3110     if (ret)
158.3111 -     png_error(png_ptr, "Insufficient memory to store iTXt chunk.");
158.3112 +      png_error(png_ptr, "Insufficient memory to store iTXt chunk");
158.3113  }
158.3114  #endif
158.3115  
158.3116  /* This function is called when we haven't found a handler for a
158.3117 -   chunk.  If there isn't a problem with the chunk itself (ie bad
158.3118 -   chunk name, CRC, or a critical chunk), the chunk is silently ignored
158.3119 -   -- unless the PNG_FLAG_UNKNOWN_CHUNKS_SUPPORTED flag is on in which
158.3120 -   case it will be saved away to be written out later. */
158.3121 + * chunk.  If there isn't a problem with the chunk itself (ie bad
158.3122 + * chunk name, CRC, or a critical chunk), the chunk is silently ignored
158.3123 + * -- unless the PNG_FLAG_UNKNOWN_CHUNKS_SUPPORTED flag is on in which
158.3124 + * case it will be saved away to be written out later.
158.3125 + */
158.3126  void /* PRIVATE */
158.3127  png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
158.3128  {
158.3129     png_uint_32 skip = 0;
158.3130  
158.3131 -   png_debug(1, "in png_handle_unknown\n");
158.3132 +   png_debug(1, "in png_handle_unknown");
158.3133 +
158.3134 +#ifdef PNG_USER_LIMITS_SUPPORTED
158.3135 +   if (png_ptr->user_chunk_cache_max != 0)
158.3136 +   {
158.3137 +      if (png_ptr->user_chunk_cache_max == 1)
158.3138 +      {
158.3139 +         png_crc_finish(png_ptr, length);
158.3140 +         return;
158.3141 +      }
158.3142 +
158.3143 +      if (--png_ptr->user_chunk_cache_max == 1)
158.3144 +      {
158.3145 +         png_warning(png_ptr, "No space in chunk cache for unknown chunk");
158.3146 +         png_crc_finish(png_ptr, length);
158.3147 +         return;
158.3148 +      }
158.3149 +   }
158.3150 +#endif
158.3151  
158.3152     if (png_ptr->mode & PNG_HAVE_IDAT)
158.3153     {
158.3154 -#ifdef PNG_USE_LOCAL_ARRAYS
158.3155        PNG_IDAT;
158.3156 -#endif
158.3157 -      if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))  /* not an IDAT */
158.3158 +
158.3159 +      if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))  /* Not an IDAT */
158.3160           png_ptr->mode |= PNG_AFTER_IDAT;
158.3161     }
158.3162  
158.3163 -   png_check_chunk_name(png_ptr, png_ptr->chunk_name);
158.3164 -
158.3165     if (!(png_ptr->chunk_name[0] & 0x20))
158.3166     {
158.3167 -#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
158.3168 -      if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
158.3169 -           PNG_HANDLE_CHUNK_ALWAYS
158.3170 -#if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
158.3171 -           && png_ptr->read_user_chunk_fn == NULL
158.3172 +#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
158.3173 +      if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
158.3174 +          PNG_HANDLE_CHUNK_ALWAYS
158.3175 +#ifdef PNG_READ_USER_CHUNKS_SUPPORTED
158.3176 +          && png_ptr->read_user_chunk_fn == NULL
158.3177  #endif
158.3178 -        )
158.3179 +          )
158.3180  #endif
158.3181 -          png_chunk_error(png_ptr, "unknown critical chunk");
158.3182 +         png_chunk_error(png_ptr, "unknown critical chunk");
158.3183     }
158.3184  
158.3185 -#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
158.3186 -   if ((png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS) ||
158.3187 -       (png_ptr->read_user_chunk_fn != NULL))
158.3188 +#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
158.3189 +   if ((png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS)
158.3190 +#ifdef PNG_READ_USER_CHUNKS_SUPPORTED
158.3191 +       || (png_ptr->read_user_chunk_fn != NULL)
158.3192 +#endif
158.3193 +       )
158.3194     {
158.3195  #ifdef PNG_MAX_MALLOC_64K
158.3196 -       if (length > (png_uint_32)65535L)
158.3197 -       {
158.3198 -           png_warning(png_ptr, "unknown chunk too large to fit in memory");
158.3199 -           skip = length - (png_uint_32)65535L;
158.3200 -           length = (png_uint_32)65535L;
158.3201 -       }
158.3202 +      if (length > (png_uint_32)65535L)
158.3203 +      {
158.3204 +         png_warning(png_ptr, "unknown chunk too large to fit in memory");
158.3205 +         skip = length - (png_uint_32)65535L;
158.3206 +         length = (png_uint_32)65535L;
158.3207 +      }
158.3208  #endif
158.3209 -       png_strcpy((png_charp)png_ptr->unknown_chunk.name,
158.3210 -         (png_charp)png_ptr->chunk_name);
158.3211 -       png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
158.3212 -       png_ptr->unknown_chunk.size = (png_size_t)length;
158.3213 -       png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
158.3214 -#if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
158.3215 -       if(png_ptr->read_user_chunk_fn != NULL)
158.3216 -       {
158.3217 -          /* callback to user unknown chunk handler */
158.3218 -          int ret;
158.3219 -          ret = (*(png_ptr->read_user_chunk_fn))
158.3220 -            (png_ptr, &png_ptr->unknown_chunk);
158.3221 -          if (ret < 0)
158.3222 -             png_chunk_error(png_ptr, "error in user chunk");
158.3223 -          if (ret == 0)
158.3224 -          {
158.3225 -             if (!(png_ptr->chunk_name[0] & 0x20))
158.3226 -                if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
158.3227 -                     PNG_HANDLE_CHUNK_ALWAYS)
158.3228 -                   png_chunk_error(png_ptr, "unknown critical chunk");
158.3229 -             png_set_unknown_chunks(png_ptr, info_ptr,
158.3230 -               &png_ptr->unknown_chunk, 1);
158.3231 -          }
158.3232 -       }
158.3233 -#else
158.3234 -       png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
158.3235 +
158.3236 +      png_memcpy((png_charp)png_ptr->unknown_chunk.name,
158.3237 +          (png_charp)png_ptr->chunk_name,
158.3238 +          png_sizeof(png_ptr->unknown_chunk.name));
158.3239 +
158.3240 +      png_ptr->unknown_chunk.name[png_sizeof(png_ptr->unknown_chunk.name)-1]
158.3241 +          = '\0';
158.3242 +
158.3243 +      png_ptr->unknown_chunk.size = (png_size_t)length;
158.3244 +
158.3245 +      if (length == 0)
158.3246 +         png_ptr->unknown_chunk.data = NULL;
158.3247 +
158.3248 +      else
158.3249 +      {
158.3250 +         png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
158.3251 +         png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
158.3252 +      }
158.3253 +
158.3254 +#ifdef PNG_READ_USER_CHUNKS_SUPPORTED
158.3255 +      if (png_ptr->read_user_chunk_fn != NULL)
158.3256 +      {
158.3257 +         /* Callback to user unknown chunk handler */
158.3258 +         int ret;
158.3259 +
158.3260 +         ret = (*(png_ptr->read_user_chunk_fn))
158.3261 +             (png_ptr, &png_ptr->unknown_chunk);
158.3262 +
158.3263 +         if (ret < 0)
158.3264 +            png_chunk_error(png_ptr, "error in user chunk");
158.3265 +
158.3266 +         if (ret == 0)
158.3267 +         {
158.3268 +            if (!(png_ptr->chunk_name[0] & 0x20))
158.3269 +            {
158.3270 +#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
158.3271 +               if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
158.3272 +                   PNG_HANDLE_CHUNK_ALWAYS)
158.3273  #endif
158.3274 -       png_free(png_ptr, png_ptr->unknown_chunk.data);
158.3275 -       png_ptr->unknown_chunk.data = NULL;
158.3276 +                  png_chunk_error(png_ptr, "unknown critical chunk");
158.3277 +            }
158.3278 +
158.3279 +            png_set_unknown_chunks(png_ptr, info_ptr,
158.3280 +                &png_ptr->unknown_chunk, 1);
158.3281 +         }
158.3282 +      }
158.3283 +
158.3284 +      else
158.3285 +#endif
158.3286 +         png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
158.3287 +
158.3288 +      png_free(png_ptr, png_ptr->unknown_chunk.data);
158.3289 +      png_ptr->unknown_chunk.data = NULL;
158.3290     }
158.3291 +
158.3292     else
158.3293  #endif
158.3294        skip = length;
158.3295  
158.3296     png_crc_finish(png_ptr, skip);
158.3297  
158.3298 -#if !defined(PNG_READ_USER_CHUNKS_SUPPORTED)
158.3299 -   if (&info_ptr == NULL) /* quiet compiler warnings about unused info_ptr */
158.3300 -      return;
158.3301 +#ifndef PNG_READ_USER_CHUNKS_SUPPORTED
158.3302 +   PNG_UNUSED(info_ptr) /* Quiet compiler warnings about unused info_ptr */
158.3303  #endif
158.3304  }
158.3305  
158.3306  /* This function is called to verify that a chunk name is valid.
158.3307 -   This function can't have the "critical chunk check" incorporated
158.3308 -   into it, since in the future we will need to be able to call user
158.3309 -   functions to handle unknown critical chunks after we check that
158.3310 -   the chunk name itself is valid. */
158.3311 + * This function can't have the "critical chunk check" incorporated
158.3312 + * into it, since in the future we will need to be able to call user
158.3313 + * functions to handle unknown critical chunks after we check that
158.3314 + * the chunk name itself is valid.
158.3315 + */
158.3316  
158.3317  #define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
158.3318  
158.3319  void /* PRIVATE */
158.3320 -png_check_chunk_name(png_structp png_ptr, png_bytep chunk_name)
158.3321 +png_check_chunk_name(png_structp png_ptr, png_const_bytep chunk_name)
158.3322  {
158.3323 -   png_debug(1, "in png_check_chunk_name\n");
158.3324 +   png_debug(1, "in png_check_chunk_name");
158.3325     if (isnonalpha(chunk_name[0]) || isnonalpha(chunk_name[1]) ||
158.3326         isnonalpha(chunk_name[2]) || isnonalpha(chunk_name[3]))
158.3327     {
158.3328 @@ -2274,25 +2696,36 @@
158.3329  }
158.3330  
158.3331  /* Combines the row recently read in with the existing pixels in the
158.3332 -   row.  This routine takes care of alpha and transparency if requested.
158.3333 -   This routine also handles the two methods of progressive display
158.3334 -   of interlaced images, depending on the mask value.
158.3335 -   The mask value describes which pixels are to be combined with
158.3336 -   the row.  The pattern always repeats every 8 pixels, so just 8
158.3337 -   bits are needed.  A one indicates the pixel is to be combined,
158.3338 -   a zero indicates the pixel is to be skipped.  This is in addition
158.3339 -   to any alpha or transparency value associated with the pixel.  If
158.3340 -   you want all pixels to be combined, pass 0xff (255) in mask.  */
158.3341 -#ifndef PNG_HAVE_MMX_COMBINE_ROW
158.3342 + * row.  This routine takes care of alpha and transparency if requested.
158.3343 + * This routine also handles the two methods of progressive display
158.3344 + * of interlaced images, depending on the mask value.
158.3345 + * The mask value describes which pixels are to be combined with
158.3346 + * the row.  The pattern always repeats every 8 pixels, so just 8
158.3347 + * bits are needed.  A one indicates the pixel is to be combined,
158.3348 + * a zero indicates the pixel is to be skipped.  This is in addition
158.3349 + * to any alpha or transparency value associated with the pixel.  If
158.3350 + * you want all pixels to be combined, pass 0xff (255) in mask.
158.3351 + */
158.3352 +
158.3353  void /* PRIVATE */
158.3354  png_combine_row(png_structp png_ptr, png_bytep row, int mask)
158.3355  {
158.3356 -   png_debug(1,"in png_combine_row\n");
158.3357 +   png_debug(1, "in png_combine_row");
158.3358 +
158.3359 +   /* Added in 1.5.4: the row_info should match the information returned by any
158.3360 +    * call to png_read_update_info at this point.  Do not continue if we got
158.3361 +    * this wrong.
158.3362 +    */
158.3363 +   if (png_ptr->info_rowbytes != 0 && png_ptr->info_rowbytes !=
158.3364 +          PNG_ROWBYTES(png_ptr->row_info.pixel_depth, png_ptr->width))
158.3365 +      png_error(png_ptr, "internal row size calculation error");
158.3366 +
158.3367     if (mask == 0xff)
158.3368     {
158.3369        png_memcpy(row, png_ptr->row_buf + 1,
158.3370 -         PNG_ROWBYTES(png_ptr->row_info.pixel_depth, png_ptr->width));
158.3371 +          PNG_ROWBYTES(png_ptr->row_info.pixel_depth, png_ptr->width));
158.3372     }
158.3373 +
158.3374     else
158.3375     {
158.3376        switch (png_ptr->row_info.pixel_depth)
158.3377 @@ -2307,13 +2740,14 @@
158.3378              png_uint_32 i;
158.3379              png_uint_32 row_width = png_ptr->width;
158.3380  
158.3381 -#if defined(PNG_READ_PACKSWAP_SUPPORTED)
158.3382 +#ifdef PNG_READ_PACKSWAP_SUPPORTED
158.3383              if (png_ptr->transformations & PNG_PACKSWAP)
158.3384              {
158.3385                  s_start = 0;
158.3386                  s_end = 7;
158.3387                  s_inc = 1;
158.3388              }
158.3389 +
158.3390              else
158.3391  #endif
158.3392              {
158.3393 @@ -2341,16 +2775,19 @@
158.3394                    sp++;
158.3395                    dp++;
158.3396                 }
158.3397 +
158.3398                 else
158.3399                    shift += s_inc;
158.3400  
158.3401                 if (m == 1)
158.3402                    m = 0x80;
158.3403 +
158.3404                 else
158.3405                    m >>= 1;
158.3406              }
158.3407              break;
158.3408           }
158.3409 +
158.3410           case 2:
158.3411           {
158.3412              png_bytep sp = png_ptr->row_buf + 1;
158.3413 @@ -2362,13 +2799,14 @@
158.3414              png_uint_32 row_width = png_ptr->width;
158.3415              int value;
158.3416  
158.3417 -#if defined(PNG_READ_PACKSWAP_SUPPORTED)
158.3418 +#ifdef PNG_READ_PACKSWAP_SUPPORTED
158.3419              if (png_ptr->transformations & PNG_PACKSWAP)
158.3420              {
158.3421                 s_start = 0;
158.3422                 s_end = 6;
158.3423                 s_inc = 2;
158.3424              }
158.3425 +
158.3426              else
158.3427  #endif
158.3428              {
158.3429 @@ -2394,15 +2832,19 @@
158.3430                    sp++;
158.3431                    dp++;
158.3432                 }
158.3433 +
158.3434                 else
158.3435                    shift += s_inc;
158.3436 +
158.3437                 if (m == 1)
158.3438                    m = 0x80;
158.3439 +
158.3440                 else
158.3441                    m >>= 1;
158.3442              }
158.3443              break;
158.3444           }
158.3445 +
158.3446           case 4:
158.3447           {
158.3448              png_bytep sp = png_ptr->row_buf + 1;
158.3449 @@ -2414,13 +2856,14 @@
158.3450              png_uint_32 row_width = png_ptr->width;
158.3451              int value;
158.3452  
158.3453 -#if defined(PNG_READ_PACKSWAP_SUPPORTED)
158.3454 +#ifdef PNG_READ_PACKSWAP_SUPPORTED
158.3455              if (png_ptr->transformations & PNG_PACKSWAP)
158.3456              {
158.3457                 s_start = 0;
158.3458                 s_end = 4;
158.3459                 s_inc = 4;
158.3460              }
158.3461 +
158.3462              else
158.3463  #endif
158.3464              {
158.3465 @@ -2445,15 +2888,19 @@
158.3466                    sp++;
158.3467                    dp++;
158.3468                 }
158.3469 +
158.3470                 else
158.3471                    shift += s_inc;
158.3472 +
158.3473                 if (m == 1)
158.3474                    m = 0x80;
158.3475 +
158.3476                 else
158.3477                    m >>= 1;
158.3478              }
158.3479              break;
158.3480           }
158.3481 +
158.3482           default:
158.3483           {
158.3484              png_bytep sp = png_ptr->row_buf + 1;
158.3485 @@ -2463,7 +2910,6 @@
158.3486              png_uint_32 row_width = png_ptr->width;
158.3487              png_byte m = 0x80;
158.3488  
158.3489 -
158.3490              for (i = 0; i < row_width; i++)
158.3491              {
158.3492                 if (m & mask)
158.3493 @@ -2476,6 +2922,7 @@
158.3494  
158.3495                 if (m == 1)
158.3496                    m = 0x80;
158.3497 +
158.3498                 else
158.3499                    m >>= 1;
158.3500              }
158.3501 @@ -2484,14 +2931,8 @@
158.3502        }
158.3503     }
158.3504  }
158.3505 -#endif /* !PNG_HAVE_MMX_COMBINE_ROW */
158.3506  
158.3507  #ifdef PNG_READ_INTERLACING_SUPPORTED
158.3508 -#ifndef PNG_HAVE_MMX_READ_INTERLACE   /* else in pngvcrd.c, pnggccrd.c */
158.3509 -/* OLD pre-1.0.9 interface:
158.3510 -void png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
158.3511 -   png_uint_32 transformations)
158.3512 - */
158.3513  void /* PRIVATE */
158.3514  png_do_read_interlace(png_structp png_ptr)
158.3515  {
158.3516 @@ -2499,13 +2940,11 @@
158.3517     png_bytep row = png_ptr->row_buf + 1;
158.3518     int pass = png_ptr->pass;
158.3519     png_uint_32 transformations = png_ptr->transformations;
158.3520 -#ifdef PNG_USE_LOCAL_ARRAYS
158.3521 -   /* arrays to facilitate easy interlacing - use pass (0 - 6) as index */
158.3522 -   /* offset to next interlace block */
158.3523 -   const int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
158.3524 -#endif
158.3525 -
158.3526 -   png_debug(1,"in png_do_read_interlace (stock C version)\n");
158.3527 +   /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
158.3528 +   /* Offset to next interlace block */
158.3529 +   PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
158.3530 +
158.3531 +   png_debug(1, "in png_do_read_interlace");
158.3532     if (row != NULL && row_info != NULL)
158.3533     {
158.3534        png_uint_32 final_width;
158.3535 @@ -2525,7 +2964,7 @@
158.3536              png_uint_32 i;
158.3537              int j;
158.3538  
158.3539 -#if defined(PNG_READ_PACKSWAP_SUPPORTED)
158.3540 +#ifdef PNG_READ_PACKSWAP_SUPPORTED
158.3541              if (transformations & PNG_PACKSWAP)
158.3542              {
158.3543                  sshift = (int)((row_info->width + 7) & 0x07);
158.3544 @@ -2534,6 +2973,7 @@
158.3545                  s_end = 0;
158.3546                  s_inc = -1;
158.3547              }
158.3548 +
158.3549              else
158.3550  #endif
158.3551              {
158.3552 @@ -2551,24 +2991,29 @@
158.3553                 {
158.3554                    *dp &= (png_byte)((0x7f7f >> (7 - dshift)) & 0xff);
158.3555                    *dp |= (png_byte)(v << dshift);
158.3556 +
158.3557                    if (dshift == s_end)
158.3558                    {
158.3559                       dshift = s_start;
158.3560                       dp--;
158.3561                    }
158.3562 +
158.3563                    else
158.3564                       dshift += s_inc;
158.3565                 }
158.3566 +
158.3567                 if (sshift == s_end)
158.3568                 {
158.3569                    sshift = s_start;
158.3570                    sp--;
158.3571                 }
158.3572 +
158.3573                 else
158.3574                    sshift += s_inc;
158.3575              }
158.3576              break;
158.3577           }
158.3578 +
158.3579           case 2:
158.3580           {
158.3581              png_bytep sp = row + (png_uint_32)((row_info->width - 1) >> 2);
158.3582 @@ -2578,7 +3023,7 @@
158.3583              int jstop = png_pass_inc[pass];
158.3584              png_uint_32 i;
158.3585  
158.3586 -#if defined(PNG_READ_PACKSWAP_SUPPORTED)
158.3587 +#ifdef PNG_READ_PACKSWAP_SUPPORTED
158.3588              if (transformations & PNG_PACKSWAP)
158.3589              {
158.3590                 sshift = (int)(((row_info->width + 3) & 0x03) << 1);
158.3591 @@ -2587,6 +3032,7 @@
158.3592                 s_end = 0;
158.3593                 s_inc = -2;
158.3594              }
158.3595 +
158.3596              else
158.3597  #endif
158.3598              {
158.3599 @@ -2607,24 +3053,29 @@
158.3600                 {
158.3601                    *dp &= (png_byte)((0x3f3f >> (6 - dshift)) & 0xff);
158.3602                    *dp |= (png_byte)(v << dshift);
158.3603 +
158.3604                    if (dshift == s_end)
158.3605                    {
158.3606                       dshift = s_start;
158.3607                       dp--;
158.3608                    }
158.3609 +
158.3610                    else
158.3611                       dshift += s_inc;
158.3612                 }
158.3613 +
158.3614                 if (sshift == s_end)
158.3615                 {
158.3616                    sshift = s_start;
158.3617                    sp--;
158.3618                 }
158.3619 +
158.3620                 else
158.3621                    sshift += s_inc;
158.3622              }
158.3623              break;
158.3624           }
158.3625 +
158.3626           case 4:
158.3627           {
158.3628              png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 1);
158.3629 @@ -2634,7 +3085,7 @@
158.3630              png_uint_32 i;
158.3631              int jstop = png_pass_inc[pass];
158.3632  
158.3633 -#if defined(PNG_READ_PACKSWAP_SUPPORTED)
158.3634 +#ifdef PNG_READ_PACKSWAP_SUPPORTED
158.3635              if (transformations & PNG_PACKSWAP)
158.3636              {
158.3637                 sshift = (int)(((row_info->width + 1) & 0x01) << 2);
158.3638 @@ -2643,6 +3094,7 @@
158.3639                 s_end = 0;
158.3640                 s_inc = -4;
158.3641              }
158.3642 +
158.3643              else
158.3644  #endif
158.3645              {
158.3646 @@ -2662,19 +3114,23 @@
158.3647                 {
158.3648                    *dp &= (png_byte)((0xf0f >> (4 - dshift)) & 0xff);
158.3649                    *dp |= (png_byte)(v << dshift);
158.3650 +
158.3651                    if (dshift == s_end)
158.3652                    {
158.3653                       dshift = s_start;
158.3654                       dp--;
158.3655                    }
158.3656 +
158.3657                    else
158.3658                       dshift += s_inc;
158.3659                 }
158.3660 +
158.3661                 if (sshift == s_end)
158.3662                 {
158.3663                    sshift = s_start;
158.3664                    sp--;
158.3665                 }
158.3666 +
158.3667                 else
158.3668                    sshift += s_inc;
158.3669              }
158.3670 @@ -2683,7 +3139,10 @@
158.3671           default:
158.3672           {
158.3673              png_size_t pixel_bytes = (row_info->pixel_depth >> 3);
158.3674 -            png_bytep sp = row + (png_size_t)(row_info->width - 1) * pixel_bytes;
158.3675 +
158.3676 +            png_bytep sp = row + (png_size_t)(row_info->width - 1)
158.3677 +                * pixel_bytes;
158.3678 +
158.3679              png_bytep dp = row + (png_size_t)(final_width - 1) * pixel_bytes;
158.3680  
158.3681              int jstop = png_pass_inc[pass];
158.3682 @@ -2695,43 +3154,43 @@
158.3683                 int j;
158.3684  
158.3685                 png_memcpy(v, sp, pixel_bytes);
158.3686 +
158.3687                 for (j = 0; j < jstop; j++)
158.3688                 {
158.3689                    png_memcpy(dp, v, pixel_bytes);
158.3690                    dp -= pixel_bytes;
158.3691                 }
158.3692 +
158.3693                 sp -= pixel_bytes;
158.3694              }
158.3695              break;
158.3696           }
158.3697        }
158.3698        row_info->width = final_width;
158.3699 -      row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,final_width);
158.3700 +      row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, final_width);
158.3701     }
158.3702 -#if !defined(PNG_READ_PACKSWAP_SUPPORTED)
158.3703 -   if (&transformations == NULL) /* silence compiler warning */
158.3704 -      return;
158.3705 +#ifndef PNG_READ_PACKSWAP_SUPPORTED
158.3706 +   PNG_UNUSED(transformations)  /* Silence compiler warning */
158.3707  #endif
158.3708  }
158.3709 -#endif /* !PNG_HAVE_MMX_READ_INTERLACE */
158.3710  #endif /* PNG_READ_INTERLACING_SUPPORTED */
158.3711  
158.3712 -#ifndef PNG_HAVE_MMX_READ_FILTER_ROW
158.3713  void /* PRIVATE */
158.3714  png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row,
158.3715 -   png_bytep prev_row, int filter)
158.3716 +    png_const_bytep prev_row, int filter)
158.3717  {
158.3718 -   png_debug(1, "in png_read_filter_row\n");
158.3719 -   png_debug2(2,"row = %lu, filter = %d\n", png_ptr->row_number, filter);
158.3720 +   png_debug(1, "in png_read_filter_row");
158.3721 +   png_debug2(2, "row = %u, filter = %d", png_ptr->row_number, filter);
158.3722     switch (filter)
158.3723     {
158.3724        case PNG_FILTER_VALUE_NONE:
158.3725           break;
158.3726 +
158.3727        case PNG_FILTER_VALUE_SUB:
158.3728        {
158.3729 -         png_uint_32 i;
158.3730 -         png_uint_32 istop = row_info->rowbytes;
158.3731 -         png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
158.3732 +         png_size_t i;
158.3733 +         png_size_t istop = row_info->rowbytes;
158.3734 +         unsigned int bpp = (row_info->pixel_depth + 7) >> 3;
158.3735           png_bytep rp = row + bpp;
158.3736           png_bytep lp = row;
158.3737  
158.3738 @@ -2744,10 +3203,10 @@
158.3739        }
158.3740        case PNG_FILTER_VALUE_UP:
158.3741        {
158.3742 -         png_uint_32 i;
158.3743 -         png_uint_32 istop = row_info->rowbytes;
158.3744 +         png_size_t i;
158.3745 +         png_size_t istop = row_info->rowbytes;
158.3746           png_bytep rp = row;
158.3747 -         png_bytep pp = prev_row;
158.3748 +         png_const_bytep pp = prev_row;
158.3749  
158.3750           for (i = 0; i < istop; i++)
158.3751           {
158.3752 @@ -2758,37 +3217,39 @@
158.3753        }
158.3754        case PNG_FILTER_VALUE_AVG:
158.3755        {
158.3756 -         png_uint_32 i;
158.3757 +         png_size_t i;
158.3758           png_bytep rp = row;
158.3759 -         png_bytep pp = prev_row;
158.3760 +         png_const_bytep pp = prev_row;
158.3761           png_bytep lp = row;
158.3762 -         png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
158.3763 -         png_uint_32 istop = row_info->rowbytes - bpp;
158.3764 +         unsigned int bpp = (row_info->pixel_depth + 7) >> 3;
158.3765 +         png_size_t istop = row_info->rowbytes - bpp;
158.3766  
158.3767           for (i = 0; i < bpp; i++)
158.3768           {
158.3769              *rp = (png_byte)(((int)(*rp) +
158.3770 -               ((int)(*pp++) / 2 )) & 0xff);
158.3771 +                ((int)(*pp++) / 2 )) & 0xff);
158.3772 +
158.3773              rp++;
158.3774           }
158.3775  
158.3776           for (i = 0; i < istop; i++)
158.3777           {
158.3778              *rp = (png_byte)(((int)(*rp) +
158.3779 -               (int)(*pp++ + *lp++) / 2 ) & 0xff);
158.3780 +                (int)(*pp++ + *lp++) / 2 ) & 0xff);
158.3781 +
158.3782              rp++;
158.3783           }
158.3784           break;
158.3785        }
158.3786        case PNG_FILTER_VALUE_PAETH:
158.3787        {
158.3788 -         png_uint_32 i;
158.3789 +         png_size_t i;
158.3790           png_bytep rp = row;
158.3791 -         png_bytep pp = prev_row;
158.3792 +         png_const_bytep pp = prev_row;
158.3793           png_bytep lp = row;
158.3794 -         png_bytep cp = prev_row;
158.3795 -         png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
158.3796 -         png_uint_32 istop=row_info->rowbytes - bpp;
158.3797 +         png_const_bytep cp = prev_row;
158.3798 +         unsigned int bpp = (row_info->pixel_depth + 7) >> 3;
158.3799 +         png_size_t istop=row_info->rowbytes - bpp;
158.3800  
158.3801           for (i = 0; i < bpp; i++)
158.3802           {
158.3803 @@ -2796,7 +3257,7 @@
158.3804              rp++;
158.3805           }
158.3806  
158.3807 -         for (i = 0; i < istop; i++)   /* use leftover rp,pp */
158.3808 +         for (i = 0; i < istop; i++)   /* Use leftover rp,pp */
158.3809           {
158.3810              int a, b, c, pa, pb, pc, p;
158.3811  
158.3812 @@ -2820,13 +3281,15 @@
158.3813              /*
158.3814                 if (pa <= pb && pa <= pc)
158.3815                    p = a;
158.3816 +
158.3817                 else if (pb <= pc)
158.3818                    p = b;
158.3819 +
158.3820                 else
158.3821                    p = c;
158.3822               */
158.3823  
158.3824 -            p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
158.3825 +            p = (pa <= pb && pa <= pc) ? a : (pb <= pc) ? b : c;
158.3826  
158.3827              *rp = (png_byte)(((int)(*rp) + p) & 0xff);
158.3828              rp++;
158.3829 @@ -2834,123 +3297,125 @@
158.3830           break;
158.3831        }
158.3832        default:
158.3833 -         png_warning(png_ptr, "Ignoring bad adaptive filter type");
158.3834 -         *row=0;
158.3835 +         png_error(png_ptr, "Ignoring bad adaptive filter type");
158.3836 +         /*NOT REACHED */
158.3837           break;
158.3838     }
158.3839  }
158.3840 -#endif /* !PNG_HAVE_MMX_READ_FILTER_ROW */
158.3841 -
158.3842 +
158.3843 +#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
158.3844  void /* PRIVATE */
158.3845  png_read_finish_row(png_structp png_ptr)
158.3846  {
158.3847 -#ifdef PNG_USE_LOCAL_ARRAYS
158.3848 -   /* arrays to facilitate easy interlacing - use pass (0 - 6) as index */
158.3849 -
158.3850 -   /* start of interlace block */
158.3851 -   const int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
158.3852 -
158.3853 -   /* offset to next interlace block */
158.3854 -   const int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
158.3855 -
158.3856 -   /* start of interlace block in the y direction */
158.3857 -   const int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
158.3858 -
158.3859 -   /* offset to next interlace block in the y direction */
158.3860 -   const int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
158.3861 -#endif
158.3862 -
158.3863 -   png_debug(1, "in png_read_finish_row\n");
158.3864 +#ifdef PNG_READ_INTERLACING_SUPPORTED
158.3865 +   /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
158.3866 +
158.3867 +   /* Start of interlace block */
158.3868 +   PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
158.3869 +
158.3870 +   /* Offset to next interlace block */
158.3871 +   PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
158.3872 +
158.3873 +   /* Start of interlace block in the y direction */
158.3874 +   PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
158.3875 +
158.3876 +   /* Offset to next interlace block in the y direction */
158.3877 +   PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
158.3878 +#endif /* PNG_READ_INTERLACING_SUPPORTED */
158.3879 +
158.3880 +   png_debug(1, "in png_read_finish_row");
158.3881     png_ptr->row_number++;
158.3882     if (png_ptr->row_number < png_ptr->num_rows)
158.3883        return;
158.3884  
158.3885 +#ifdef PNG_READ_INTERLACING_SUPPORTED
158.3886     if (png_ptr->interlaced)
158.3887     {
158.3888        png_ptr->row_number = 0;
158.3889 -      png_memset_check(png_ptr, png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
158.3890 +
158.3891 +      png_memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
158.3892 +
158.3893        do
158.3894        {
158.3895           png_ptr->pass++;
158.3896 +
158.3897           if (png_ptr->pass >= 7)
158.3898              break;
158.3899 +
158.3900           png_ptr->iwidth = (png_ptr->width +
158.3901              png_pass_inc[png_ptr->pass] - 1 -
158.3902              png_pass_start[png_ptr->pass]) /
158.3903              png_pass_inc[png_ptr->pass];
158.3904  
158.3905 -         png_ptr->irowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,
158.3906 -            png_ptr->iwidth) + 1;
158.3907 -
158.3908           if (!(png_ptr->transformations & PNG_INTERLACE))
158.3909           {
158.3910              png_ptr->num_rows = (png_ptr->height +
158.3911 -               png_pass_yinc[png_ptr->pass] - 1 -
158.3912 -               png_pass_ystart[png_ptr->pass]) /
158.3913 -               png_pass_yinc[png_ptr->pass];
158.3914 -            if (!(png_ptr->num_rows))
158.3915 -               continue;
158.3916 +                png_pass_yinc[png_ptr->pass] - 1 -
158.3917 +                png_pass_ystart[png_ptr->pass]) /
158.3918 +                png_pass_yinc[png_ptr->pass];
158.3919           }
158.3920 +
158.3921           else  /* if (png_ptr->transformations & PNG_INTERLACE) */
158.3922 -            break;
158.3923 -      } while (png_ptr->iwidth == 0);
158.3924 +            break; /* libpng deinterlacing sees every row */
158.3925 +
158.3926 +      } while (png_ptr->num_rows == 0 || png_ptr->iwidth == 0);
158.3927  
158.3928        if (png_ptr->pass < 7)
158.3929           return;
158.3930     }
158.3931 +#endif /* PNG_READ_INTERLACING_SUPPORTED */
158.3932  
158.3933     if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
158.3934     {
158.3935 -#ifdef PNG_USE_LOCAL_ARRAYS
158.3936        PNG_IDAT;
158.3937 -#endif
158.3938        char extra;
158.3939        int ret;
158.3940  
158.3941        png_ptr->zstream.next_out = (Byte *)&extra;
158.3942        png_ptr->zstream.avail_out = (uInt)1;
158.3943 -      for(;;)
158.3944 +
158.3945 +      for (;;)
158.3946        {
158.3947           if (!(png_ptr->zstream.avail_in))
158.3948           {
158.3949              while (!png_ptr->idat_size)
158.3950              {
158.3951 -               png_byte chunk_length[4];
158.3952 -
158.3953                 png_crc_finish(png_ptr, 0);
158.3954 -
158.3955 -               png_read_data(png_ptr, chunk_length, 4);
158.3956 -               png_ptr->idat_size = png_get_uint_31(png_ptr, chunk_length);
158.3957 -               png_reset_crc(png_ptr);
158.3958 -               png_crc_read(png_ptr, png_ptr->chunk_name, 4);
158.3959 -               if (png_memcmp(png_ptr->chunk_name, (png_bytep)png_IDAT, 4))
158.3960 +               png_ptr->idat_size = png_read_chunk_header(png_ptr);
158.3961 +               if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
158.3962                    png_error(png_ptr, "Not enough image data");
158.3963 -
158.3964              }
158.3965 +
158.3966              png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size;
158.3967              png_ptr->zstream.next_in = png_ptr->zbuf;
158.3968 +
158.3969              if (png_ptr->zbuf_size > png_ptr->idat_size)
158.3970                 png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size;
158.3971 +
158.3972              png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zstream.avail_in);
158.3973              png_ptr->idat_size -= png_ptr->zstream.avail_in;
158.3974           }
158.3975 +
158.3976           ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
158.3977 +
158.3978           if (ret == Z_STREAM_END)
158.3979           {
158.3980              if (!(png_ptr->zstream.avail_out) || png_ptr->zstream.avail_in ||
158.3981 -               png_ptr->idat_size)
158.3982 +                png_ptr->idat_size)
158.3983                 png_warning(png_ptr, "Extra compressed data");
158.3984 +
158.3985              png_ptr->mode |= PNG_AFTER_IDAT;
158.3986              png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
158.3987              break;
158.3988           }
158.3989 +
158.3990           if (ret != Z_OK)
158.3991              png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg :
158.3992 -                      "Decompression Error");
158.3993 +                "Decompression Error");
158.3994  
158.3995           if (!(png_ptr->zstream.avail_out))
158.3996           {
158.3997 -            png_warning(png_ptr, "Extra compressed data.");
158.3998 +            png_warning(png_ptr, "Extra compressed data");
158.3999              png_ptr->mode |= PNG_AFTER_IDAT;
158.4000              png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
158.4001              break;
158.4002 @@ -2967,81 +3432,86 @@
158.4003  
158.4004     png_ptr->mode |= PNG_AFTER_IDAT;
158.4005  }
158.4006 +#endif /* PNG_SEQUENTIAL_READ_SUPPORTED */
158.4007  
158.4008  void /* PRIVATE */
158.4009  png_read_start_row(png_structp png_ptr)
158.4010  {
158.4011 -#ifdef PNG_USE_LOCAL_ARRAYS
158.4012 -   /* arrays to facilitate easy interlacing - use pass (0 - 6) as index */
158.4013 -
158.4014 -   /* start of interlace block */
158.4015 -   const int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
158.4016 -
158.4017 -   /* offset to next interlace block */
158.4018 -   const int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
158.4019 -
158.4020 -   /* start of interlace block in the y direction */
158.4021 -   const int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
158.4022 -
158.4023 -   /* offset to next interlace block in the y direction */
158.4024 -   const int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
158.4025 +#ifdef PNG_READ_INTERLACING_SUPPORTED
158.4026 +   /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
158.4027 +
158.4028 +   /* Start of interlace block */
158.4029 +   PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
158.4030 +
158.4031 +   /* Offset to next interlace block */
158.4032 +   PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
158.4033 +
158.4034 +   /* Start of interlace block in the y direction */
158.4035 +   PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
158.4036 +
158.4037 +   /* Offset to next interlace block in the y direction */
158.4038 +   PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
158.4039  #endif
158.4040  
158.4041     int max_pixel_depth;
158.4042 -   png_uint_32 row_bytes;
158.4043 -
158.4044 -   png_debug(1, "in png_read_start_row\n");
158.4045 +   png_size_t row_bytes;
158.4046 +
158.4047 +   png_debug(1, "in png_read_start_row");
158.4048     png_ptr->zstream.avail_in = 0;
158.4049 +#ifdef PNG_READ_TRANSFORMS_SUPPORTED
158.4050     png_init_read_transformations(png_ptr);
158.4051 +#endif
158.4052 +#ifdef PNG_READ_INTERLACING_SUPPORTED
158.4053     if (png_ptr->interlaced)
158.4054     {
158.4055        if (!(png_ptr->transformations & PNG_INTERLACE))
158.4056           png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
158.4057 -            png_pass_ystart[0]) / png_pass_yinc[0];
158.4058 +             png_pass_ystart[0]) / png_pass_yinc[0];
158.4059 +
158.4060        else
158.4061           png_ptr->num_rows = png_ptr->height;
158.4062  
158.4063        png_ptr->iwidth = (png_ptr->width +
158.4064 -         png_pass_inc[png_ptr->pass] - 1 -
158.4065 -         png_pass_start[png_ptr->pass]) /
158.4066 -         png_pass_inc[png_ptr->pass];
158.4067 -
158.4068 -         row_bytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->iwidth) + 1;
158.4069 -
158.4070 -         png_ptr->irowbytes = (png_size_t)row_bytes;
158.4071 -         if((png_uint_32)png_ptr->irowbytes != row_bytes)
158.4072 -            png_error(png_ptr, "Rowbytes overflow in png_read_start_row");
158.4073 +          png_pass_inc[png_ptr->pass] - 1 -
158.4074 +          png_pass_start[png_ptr->pass]) /
158.4075 +          png_pass_inc[png_ptr->pass];
158.4076     }
158.4077 +
158.4078     else
158.4079 +#endif /* PNG_READ_INTERLACING_SUPPORTED */
158.4080     {
158.4081        png_ptr->num_rows = png_ptr->height;
158.4082        png_ptr->iwidth = png_ptr->width;
158.4083 -      png_ptr->irowbytes = png_ptr->rowbytes + 1;
158.4084     }
158.4085 +
158.4086     max_pixel_depth = png_ptr->pixel_depth;
158.4087  
158.4088 -#if defined(PNG_READ_PACK_SUPPORTED)
158.4089 +#ifdef PNG_READ_PACK_SUPPORTED
158.4090     if ((png_ptr->transformations & PNG_PACK) && png_ptr->bit_depth < 8)
158.4091        max_pixel_depth = 8;
158.4092  #endif
158.4093  
158.4094 -#if defined(PNG_READ_EXPAND_SUPPORTED)
158.4095 +#ifdef PNG_READ_EXPAND_SUPPORTED
158.4096     if (png_ptr->transformations & PNG_EXPAND)
158.4097     {
158.4098        if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
158.4099        {
158.4100           if (png_ptr->num_trans)
158.4101              max_pixel_depth = 32;
158.4102 +
158.4103           else
158.4104              max_pixel_depth = 24;
158.4105        }
158.4106 +
158.4107        else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
158.4108        {
158.4109           if (max_pixel_depth < 8)
158.4110              max_pixel_depth = 8;
158.4111 +
158.4112           if (png_ptr->num_trans)
158.4113              max_pixel_depth *= 2;
158.4114        }
158.4115 +
158.4116        else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
158.4117        {
158.4118           if (png_ptr->num_trans)
158.4119 @@ -3053,56 +3523,83 @@
158.4120     }
158.4121  #endif
158.4122  
158.4123 -#if defined(PNG_READ_FILLER_SUPPORTED)
158.4124 +#ifdef PNG_READ_EXPAND_16_SUPPORTED
158.4125 +   if (png_ptr->transformations & PNG_EXPAND_16)
158.4126 +   {
158.4127 +#     ifdef PNG_READ_EXPAND_SUPPORTED
158.4128 +         /* In fact it is an error if it isn't supported, but checking is
158.4129 +          * the safe way.
158.4130 +          */
158.4131 +         if (png_ptr->transformations & PNG_EXPAND)
158.4132 +         {
158.4133 +            if (png_ptr->bit_depth < 16)
158.4134 +               max_pixel_depth *= 2;
158.4135 +         }
158.4136 +         else
158.4137 +#     endif
158.4138 +         png_ptr->transformations &= ~PNG_EXPAND_16;
158.4139 +   }
158.4140 +#endif
158.4141 +
158.4142 +#ifdef PNG_READ_FILLER_SUPPORTED
158.4143     if (png_ptr->transformations & (PNG_FILLER))
158.4144     {
158.4145        if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
158.4146           max_pixel_depth = 32;
158.4147 +
158.4148        else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
158.4149        {
158.4150           if (max_pixel_depth <= 8)
158.4151              max_pixel_depth = 16;
158.4152 +
158.4153           else
158.4154              max_pixel_depth = 32;
158.4155        }
158.4156 +
158.4157        else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
158.4158        {
158.4159           if (max_pixel_depth <= 32)
158.4160              max_pixel_depth = 32;
158.4161 +
158.4162           else
158.4163              max_pixel_depth = 64;
158.4164        }
158.4165     }
158.4166  #endif
158.4167  
158.4168 -#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
158.4169 +#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED
158.4170     if (png_ptr->transformations & PNG_GRAY_TO_RGB)
158.4171     {
158.4172        if (
158.4173 -#if defined(PNG_READ_EXPAND_SUPPORTED)
158.4174 -        (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND)) ||
158.4175 +#ifdef PNG_READ_EXPAND_SUPPORTED
158.4176 +          (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND)) ||
158.4177  #endif
158.4178 -#if defined(PNG_READ_FILLER_SUPPORTED)
158.4179 -        (png_ptr->transformations & (PNG_FILLER)) ||
158.4180 +#ifdef PNG_READ_FILLER_SUPPORTED
158.4181 +          (png_ptr->transformations & (PNG_FILLER)) ||
158.4182  #endif
158.4183 -        png_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
158.4184 +          png_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
158.4185        {
158.4186           if (max_pixel_depth <= 16)
158.4187              max_pixel_depth = 32;
158.4188 +
158.4189           else
158.4190              max_pixel_depth = 64;
158.4191        }
158.4192 +
158.4193        else
158.4194        {
158.4195           if (max_pixel_depth <= 8)
158.4196 -           {
158.4197 -             if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
158.4198 +         {
158.4199 +            if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
158.4200                 max_pixel_depth = 32;
158.4201 -             else
158.4202 +
158.4203 +            else
158.4204                 max_pixel_depth = 24;
158.4205 -           }
158.4206 +         }
158.4207 +
158.4208           else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
158.4209              max_pixel_depth = 64;
158.4210 +
158.4211           else
158.4212              max_pixel_depth = 48;
158.4213        }
158.4214 @@ -3111,49 +3608,86 @@
158.4215  
158.4216  #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) && \
158.4217  defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
158.4218 -   if(png_ptr->transformations & PNG_USER_TRANSFORM)
158.4219 -     {
158.4220 -       int user_pixel_depth=png_ptr->user_transform_depth*
158.4221 +   if (png_ptr->transformations & PNG_USER_TRANSFORM)
158.4222 +   {
158.4223 +      int user_pixel_depth = png_ptr->user_transform_depth*
158.4224           png_ptr->user_transform_channels;
158.4225 -       if(user_pixel_depth > max_pixel_depth)
158.4226 +
158.4227 +      if (user_pixel_depth > max_pixel_depth)
158.4228           max_pixel_depth=user_pixel_depth;
158.4229 -     }
158.4230 +   }
158.4231  #endif
158.4232  
158.4233 -   /* align the width on the next larger 8 pixels.  Mainly used
158.4234 -      for interlacing */
158.4235 +   /* Align the width on the next larger 8 pixels.  Mainly used
158.4236 +    * for interlacing
158.4237 +    */
158.4238     row_bytes = ((png_ptr->width + 7) & ~((png_uint_32)7));
158.4239 -   /* calculate the maximum bytes needed, adding a byte and a pixel
158.4240 -      for safety's sake */
158.4241 -   row_bytes = PNG_ROWBYTES(max_pixel_depth,row_bytes) +
158.4242 -      1 + ((max_pixel_depth + 7) >> 3);
158.4243 +   /* Calculate the maximum bytes needed, adding a byte and a pixel
158.4244 +    * for safety's sake
158.4245 +    */
158.4246 +   row_bytes = PNG_ROWBYTES(max_pixel_depth, row_bytes) +
158.4247 +       1 + ((max_pixel_depth + 7) >> 3);
158.4248 +
158.4249  #ifdef PNG_MAX_MALLOC_64K
158.4250     if (row_bytes > (png_uint_32)65536L)
158.4251        png_error(png_ptr, "This image requires a row greater than 64KB");
158.4252  #endif
158.4253 -   png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes+64);
158.4254 -   png_ptr->row_buf = png_ptr->big_row_buf+32;
158.4255 -#if defined(PNG_DEBUG) && defined(PNG_USE_PNGGCCRD)
158.4256 -   png_ptr->row_buf_size = row_bytes;
158.4257 +
158.4258 +   if (row_bytes + 48 > png_ptr->old_big_row_buf_size)
158.4259 +   {
158.4260 +     png_free(png_ptr, png_ptr->big_row_buf);
158.4261 +
158.4262 +     if (png_ptr->interlaced)
158.4263 +        png_ptr->big_row_buf = (png_bytep)png_calloc(png_ptr,
158.4264 +            row_bytes + 48);
158.4265 +
158.4266 +     else
158.4267 +        png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr,
158.4268 +            row_bytes + 48);
158.4269 +
158.4270 +     png_ptr->old_big_row_buf_size = row_bytes + 48;
158.4271 +
158.4272 +#ifdef PNG_ALIGNED_MEMORY_SUPPORTED
158.4273 +     /* Use 16-byte aligned memory for row_buf with at least 16 bytes
158.4274 +      * of padding before and after row_buf.
158.4275 +      */
158.4276 +     png_ptr->row_buf = png_ptr->big_row_buf + 32 -
158.4277 +         (((png_alloc_size_t)png_ptr->big_row_buf + 15) & 0x0F);
158.4278 +
158.4279 +     png_ptr->old_big_row_buf_size = row_bytes + 48;
158.4280 +#else
158.4281 +     /* Use 32 bytes of padding before and 16 bytes after row_buf. */
158.4282 +     png_ptr->row_buf = png_ptr->big_row_buf + 32;
158.4283  #endif
158.4284 +     png_ptr->old_big_row_buf_size = row_bytes + 48;
158.4285 +   }
158.4286  
158.4287  #ifdef PNG_MAX_MALLOC_64K
158.4288 -   if ((png_uint_32)png_ptr->rowbytes + 1 > (png_uint_32)65536L)
158.4289 +   if (png_ptr->rowbytes > 65535)
158.4290        png_error(png_ptr, "This image requires a row greater than 64KB");
158.4291 +
158.4292  #endif
158.4293 -   if ((png_uint_32)png_ptr->rowbytes > (png_uint_32)(PNG_SIZE_MAX - 1))
158.4294 -      png_error(png_ptr, "Row has too many bytes to allocate in memory.");
158.4295 -   png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)(
158.4296 -      png_ptr->rowbytes + 1));
158.4297 -
158.4298 -   png_memset_check(png_ptr, png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
158.4299 -
158.4300 -   png_debug1(3, "width = %lu,\n", png_ptr->width);
158.4301 -   png_debug1(3, "height = %lu,\n", png_ptr->height);
158.4302 -   png_debug1(3, "iwidth = %lu,\n", png_ptr->iwidth);
158.4303 -   png_debug1(3, "num_rows = %lu\n", png_ptr->num_rows);
158.4304 -   png_debug1(3, "rowbytes = %lu,\n", png_ptr->rowbytes);
158.4305 -   png_debug1(3, "irowbytes = %lu,\n", png_ptr->irowbytes);
158.4306 +   if (png_ptr->rowbytes > (PNG_SIZE_MAX - 1))
158.4307 +      png_error(png_ptr, "Row has too many bytes to allocate in memory");
158.4308 +
158.4309 +   if (png_ptr->rowbytes + 1 > png_ptr->old_prev_row_size)
158.4310 +   {
158.4311 +      png_free(png_ptr, png_ptr->prev_row);
158.4312 +
158.4313 +      png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, png_ptr->rowbytes + 1);
158.4314 +
158.4315 +      png_ptr->old_prev_row_size = png_ptr->rowbytes + 1;
158.4316 +   }
158.4317 +
158.4318 +   png_memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
158.4319 +
158.4320 +   png_debug1(3, "width = %u,", png_ptr->width);
158.4321 +   png_debug1(3, "height = %u,", png_ptr->height);
158.4322 +   png_debug1(3, "iwidth = %u,", png_ptr->iwidth);
158.4323 +   png_debug1(3, "num_rows = %u,", png_ptr->num_rows);
158.4324 +   png_debug1(3, "rowbytes = %lu,", (unsigned long)png_ptr->rowbytes);
158.4325 +   png_debug1(3, "irowbytes = %lu",
158.4326 +       (unsigned long)PNG_ROWBYTES(png_ptr->pixel_depth, png_ptr->iwidth) + 1);
158.4327  
158.4328     png_ptr->flags |= PNG_FLAG_ROW_INIT;
158.4329  }
   159.1 --- a/src/share/native/sun/awt/libpng/pngset.c	Fri Sep 30 17:20:56 2011 -0700
   159.2 +++ b/src/share/native/sun/awt/libpng/pngset.c	Tue Oct 04 12:39:42 2011 -0700
   159.3 @@ -29,28 +29,32 @@
   159.4   * However, the following notice accompanied the original version of this
   159.5   * file and, per its terms, should not be removed:
   159.6   *
   159.7 - * Last changed in libpng 1.2.17 May 15, 2007
   159.8 - * For conditions of distribution and use, see copyright notice in png.h
   159.9 - * Copyright (c) 1998-2007 Glenn Randers-Pehrson
  159.10 + * Last changed in libpng 1.5.4 [July 7, 2011]
  159.11 + * Copyright (c) 1998-2011 Glenn Randers-Pehrson
  159.12   * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
  159.13   * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
  159.14   *
  159.15 + * This code is released under the libpng license.
  159.16 + * For conditions of distribution and use, see the disclaimer
  159.17 + * and license in png.h
  159.18 + *
  159.19   * The functions here are used during reads to store data from the file
  159.20   * into the info struct, and during writes to store application data
  159.21   * into the info struct for writing into the file.  This abstracts the
  159.22   * info struct and allows us to change the structure in the future.
  159.23   */
  159.24  
  159.25 -#define PNG_INTERNAL
  159.26 -#include "png.h"
  159.27 +#include "pngpriv.h"
  159.28  
  159.29  #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  159.30  
  159.31 -#if defined(PNG_bKGD_SUPPORTED)
  159.32 +#ifdef PNG_bKGD_SUPPORTED
  159.33  void PNGAPI
  159.34 -png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background)
  159.35 +png_set_bKGD(png_structp png_ptr, png_infop info_ptr,
  159.36 +    png_const_color_16p background)
  159.37  {
  159.38 -   png_debug1(1, "in %s storage function\n", "bKGD");
  159.39 +   png_debug1(1, "in %s storage function", "bKGD");
  159.40 +
  159.41     if (png_ptr == NULL || info_ptr == NULL)
  159.42        return;
  159.43  
  159.44 @@ -59,345 +63,192 @@
  159.45  }
  159.46  #endif
  159.47  
  159.48 -#if defined(PNG_cHRM_SUPPORTED)
  159.49 -#ifdef PNG_FLOATING_POINT_SUPPORTED
  159.50 -void PNGAPI
  159.51 -png_set_cHRM(png_structp png_ptr, png_infop info_ptr,
  159.52 -   double white_x, double white_y, double red_x, double red_y,
  159.53 -   double green_x, double green_y, double blue_x, double blue_y)
  159.54 +#ifdef PNG_cHRM_SUPPORTED
  159.55 +void PNGFAPI
  159.56 +png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
  159.57 +    png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x,
  159.58 +    png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y,
  159.59 +    png_fixed_point blue_x, png_fixed_point blue_y)
  159.60  {
  159.61 -   png_debug1(1, "in %s storage function\n", "cHRM");
  159.62 +   png_debug1(1, "in %s storage function", "cHRM fixed");
  159.63 +
  159.64     if (png_ptr == NULL || info_ptr == NULL)
  159.65        return;
  159.66  
  159.67 -   if (white_x < 0.0 || white_y < 0.0 ||
  159.68 -         red_x < 0.0 ||   red_y < 0.0 ||
  159.69 -       green_x < 0.0 || green_y < 0.0 ||
  159.70 -        blue_x < 0.0 ||  blue_y < 0.0)
  159.71 +#  ifdef PNG_CHECK_cHRM_SUPPORTED
  159.72 +   if (png_check_cHRM_fixed(png_ptr,
  159.73 +       white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y))
  159.74 +#  endif
  159.75 +   {
  159.76 +      info_ptr->x_white = white_x;
  159.77 +      info_ptr->y_white = white_y;
  159.78 +      info_ptr->x_red   = red_x;
  159.79 +      info_ptr->y_red   = red_y;
  159.80 +      info_ptr->x_green = green_x;
  159.81 +      info_ptr->y_green = green_y;
  159.82 +      info_ptr->x_blue  = blue_x;
  159.83 +      info_ptr->y_blue  = blue_y;
  159.84 +      info_ptr->valid |= PNG_INFO_cHRM;
  159.85 +   }
  159.86 +}
  159.87 +
  159.88 +#  ifdef PNG_FLOATING_POINT_SUPPORTED
  159.89 +void PNGAPI
  159.90 +png_set_cHRM(png_structp png_ptr, png_infop info_ptr,
  159.91 +    double white_x, double white_y, double red_x, double red_y,
  159.92 +    double green_x, double green_y, double blue_x, double blue_y)
  159.93 +{
  159.94 +   png_set_cHRM_fixed(png_ptr, info_ptr,
  159.95 +      png_fixed(png_ptr, white_x, "cHRM White X"),
  159.96 +      png_fixed(png_ptr, white_y, "cHRM White Y"),
  159.97 +      png_fixed(png_ptr, red_x, "cHRM Red X"),
  159.98 +      png_fixed(png_ptr, red_y, "cHRM Red Y"),
  159.99 +      png_fixed(png_ptr, green_x, "cHRM Green X"),
 159.100 +      png_fixed(png_ptr, green_y, "cHRM Green Y"),
 159.101 +      png_fixed(png_ptr, blue_x, "cHRM Blue X"),
 159.102 +      png_fixed(png_ptr, blue_y, "cHRM Blue Y"));
 159.103 +}
 159.104 +#  endif /* PNG_FLOATING_POINT_SUPPORTED */
 159.105 +
 159.106 +#endif /* PNG_cHRM_SUPPORTED */
 159.107 +
 159.108 +#ifdef PNG_gAMA_SUPPORTED
 159.109 +void PNGFAPI
 159.110 +png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point
 159.111 +    file_gamma)
 159.112 +{
 159.113 +   png_debug1(1, "in %s storage function", "gAMA");
 159.114 +
 159.115 +   if (png_ptr == NULL || info_ptr == NULL)
 159.116 +      return;
 159.117 +
 159.118 +   /* Changed in libpng-1.5.4 to limit the values to ensure overflow can't
 159.119 +    * occur.  Since the fixed point representation is assymetrical it is
 159.120 +    * possible for 1/gamma to overflow the limit of 21474 and this means the
 159.121 +    * gamma value must be at least 5/100000 and hence at most 20000.0.  For
 159.122 +    * safety the limits here are a little narrower.  The values are 0.00016 to
 159.123 +    * 6250.0, which are truely ridiculous gammma values (and will produce
 159.124 +    * displays that are all black or all white.)
 159.125 +    */
 159.126 +   if (file_gamma < 16 || file_gamma > 625000000)
 159.127 +      png_warning(png_ptr, "Out of range gamma value ignored");
 159.128 +
 159.129 +   else
 159.130 +   {
 159.131 +      info_ptr->gamma = file_gamma;
 159.132 +      info_ptr->valid |= PNG_INFO_gAMA;
 159.133 +   }
 159.134 +}
 159.135 +
 159.136 +#  ifdef PNG_FLOATING_POINT_SUPPORTED
 159.137 +void PNGAPI
 159.138 +png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma)
 159.139 +{
 159.140 +   png_set_gAMA_fixed(png_ptr, info_ptr, png_fixed(png_ptr, file_gamma,
 159.141 +       "png_set_gAMA"));
 159.142 +}
 159.143 +#  endif
 159.144 +#endif
 159.145 +
 159.146 +#ifdef PNG_hIST_SUPPORTED
 159.147 +void PNGAPI
 159.148 +png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_const_uint_16p hist)
 159.149 +{
 159.150 +   int i;
 159.151 +
 159.152 +   png_debug1(1, "in %s storage function", "hIST");
 159.153 +
 159.154 +   if (png_ptr == NULL || info_ptr == NULL)
 159.155 +      return;
 159.156 +
 159.157 +   if (info_ptr->num_palette == 0 || info_ptr->num_palette
 159.158 +       > PNG_MAX_PALETTE_LENGTH)
 159.159     {
 159.160        png_warning(png_ptr,
 159.161 -        "Ignoring attempt to set negative chromaticity value");
 159.162 -      return;
 159.163 -   }
 159.164 -   if (white_x > 21474.83 || white_y > 21474.83 ||
 159.165 -         red_x > 21474.83 ||   red_y > 21474.83 ||
 159.166 -       green_x > 21474.83 || green_y > 21474.83 ||
 159.167 -        blue_x > 21474.83 ||  blue_y > 21474.83)
 159.168 -   {
 159.169 -      png_warning(png_ptr,
 159.170 -        "Ignoring attempt to set chromaticity value exceeding 21474.83");
 159.171 +          "Invalid palette size, hIST allocation skipped");
 159.172 +
 159.173        return;
 159.174     }
 159.175  
 159.176 -   info_ptr->x_white = (float)white_x;
 159.177 -   info_ptr->y_white = (float)white_y;
 159.178 -   info_ptr->x_red   = (float)red_x;
 159.179 -   info_ptr->y_red   = (float)red_y;
 159.180 -   info_ptr->x_green = (float)green_x;
 159.181 -   info_ptr->y_green = (float)green_y;
 159.182 -   info_ptr->x_blue  = (float)blue_x;
 159.183 -   info_ptr->y_blue  = (float)blue_y;
 159.184 -#ifdef PNG_FIXED_POINT_SUPPORTED
 159.185 -   info_ptr->int_x_white = (png_fixed_point)(white_x*100000.+0.5);
 159.186 -   info_ptr->int_y_white = (png_fixed_point)(white_y*100000.+0.5);
 159.187 -   info_ptr->int_x_red   = (png_fixed_point)(  red_x*100000.+0.5);
 159.188 -   info_ptr->int_y_red   = (png_fixed_point)(  red_y*100000.+0.5);
 159.189 -   info_ptr->int_x_green = (png_fixed_point)(green_x*100000.+0.5);
 159.190 -   info_ptr->int_y_green = (png_fixed_point)(green_y*100000.+0.5);
 159.191 -   info_ptr->int_x_blue  = (png_fixed_point)( blue_x*100000.+0.5);
 159.192 -   info_ptr->int_y_blue  = (png_fixed_point)( blue_y*100000.+0.5);
 159.193 -#endif
 159.194 -   info_ptr->valid |= PNG_INFO_cHRM;
 159.195 -}
 159.196 -#endif
 159.197 -#ifdef PNG_FIXED_POINT_SUPPORTED
 159.198 -void PNGAPI
 159.199 -png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
 159.200 -   png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x,
 159.201 -   png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y,
 159.202 -   png_fixed_point blue_x, png_fixed_point blue_y)
 159.203 -{
 159.204 -   png_debug1(1, "in %s storage function\n", "cHRM");
 159.205 -   if (png_ptr == NULL || info_ptr == NULL)
 159.206 -      return;
 159.207 +   png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0);
 159.208  
 159.209 -   if (white_x < 0 || white_y < 0 ||
 159.210 -         red_x < 0 ||   red_y < 0 ||
 159.211 -       green_x < 0 || green_y < 0 ||
 159.212 -        blue_x < 0 ||  blue_y < 0)
 159.213 +   /* Changed from info->num_palette to PNG_MAX_PALETTE_LENGTH in
 159.214 +    * version 1.2.1
 159.215 +    */
 159.216 +   png_ptr->hist = (png_uint_16p)png_malloc_warn(png_ptr,
 159.217 +       PNG_MAX_PALETTE_LENGTH * png_sizeof(png_uint_16));
 159.218 +
 159.219 +   if (png_ptr->hist == NULL)
 159.220     {
 159.221 -      png_warning(png_ptr,
 159.222 -        "Ignoring attempt to set negative chromaticity value");
 159.223 +      png_warning(png_ptr, "Insufficient memory for hIST chunk data");
 159.224        return;
 159.225     }
 159.226 -#ifdef PNG_FLOATING_POINT_SUPPORTED
 159.227 -   if (white_x > (double) PNG_UINT_31_MAX ||
 159.228 -       white_y > (double) PNG_UINT_31_MAX ||
 159.229 -         red_x > (double) PNG_UINT_31_MAX ||
 159.230 -         red_y > (double) PNG_UINT_31_MAX ||
 159.231 -       green_x > (double) PNG_UINT_31_MAX ||
 159.232 -       green_y > (double) PNG_UINT_31_MAX ||
 159.233 -        blue_x > (double) PNG_UINT_31_MAX ||
 159.234 -        blue_y > (double) PNG_UINT_31_MAX)
 159.235 -#else
 159.236 -   if (white_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
 159.237 -       white_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
 159.238 -         red_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
 159.239 -         red_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
 159.240 -       green_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
 159.241 -       green_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
 159.242 -        blue_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
 159.243 -        blue_y > (png_fixed_point) PNG_UINT_31_MAX/100000L)
 159.244 -#endif
 159.245 -   {
 159.246 -      png_warning(png_ptr,
 159.247 -        "Ignoring attempt to set chromaticity value exceeding 21474.83");
 159.248 -      return;
 159.249 -   }
 159.250 -   info_ptr->int_x_white = white_x;
 159.251 -   info_ptr->int_y_white = white_y;
 159.252 -   info_ptr->int_x_red   = red_x;
 159.253 -   info_ptr->int_y_red   = red_y;
 159.254 -   info_ptr->int_x_green = green_x;
 159.255 -   info_ptr->int_y_green = green_y;
 159.256 -   info_ptr->int_x_blue  = blue_x;
 159.257 -   info_ptr->int_y_blue  = blue_y;
 159.258 -#ifdef PNG_FLOATING_POINT_SUPPORTED
 159.259 -   info_ptr->x_white = (float)(white_x/100000.);
 159.260 -   info_ptr->y_white = (float)(white_y/100000.);
 159.261 -   info_ptr->x_red   = (float)(  red_x/100000.);
 159.262 -   info_ptr->y_red   = (float)(  red_y/100000.);
 159.263 -   info_ptr->x_green = (float)(green_x/100000.);
 159.264 -   info_ptr->y_green = (float)(green_y/100000.);
 159.265 -   info_ptr->x_blue  = (float)( blue_x/100000.);
 159.266 -   info_ptr->y_blue  = (float)( blue_y/100000.);
 159.267 -#endif
 159.268 -   info_ptr->valid |= PNG_INFO_cHRM;
 159.269 -}
 159.270 -#endif
 159.271 -#endif
 159.272 -
 159.273 -#if defined(PNG_gAMA_SUPPORTED)
 159.274 -#ifdef PNG_FLOATING_POINT_SUPPORTED
 159.275 -void PNGAPI
 159.276 -png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma)
 159.277 -{
 159.278 -   double gamma;
 159.279 -   png_debug1(1, "in %s storage function\n", "gAMA");
 159.280 -   if (png_ptr == NULL || info_ptr == NULL)
 159.281 -      return;
 159.282 -
 159.283 -   /* Check for overflow */
 159.284 -   if (file_gamma > 21474.83)
 159.285 -   {
 159.286 -      png_warning(png_ptr, "Limiting gamma to 21474.83");
 159.287 -      gamma=21474.83;
 159.288 -   }
 159.289 -   else
 159.290 -      gamma=file_gamma;
 159.291 -   info_ptr->gamma = (float)gamma;
 159.292 -#ifdef PNG_FIXED_POINT_SUPPORTED
 159.293 -   info_ptr->int_gamma = (int)(gamma*100000.+.5);
 159.294 -#endif
 159.295 -   info_ptr->valid |= PNG_INFO_gAMA;
 159.296 -   if(gamma == 0.0)
 159.297 -      png_warning(png_ptr, "Setting gamma=0");
 159.298 -}
 159.299 -#endif
 159.300 -void PNGAPI
 159.301 -png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point
 159.302 -   int_gamma)
 159.303 -{
 159.304 -   png_fixed_point gamma;
 159.305 -
 159.306 -   png_debug1(1, "in %s storage function\n", "gAMA");
 159.307 -   if (png_ptr == NULL || info_ptr == NULL)
 159.308 -      return;
 159.309 -
 159.310 -   if (int_gamma > (png_fixed_point) PNG_UINT_31_MAX)
 159.311 -   {
 159.312 -     png_warning(png_ptr, "Limiting gamma to 21474.83");
 159.313 -     gamma=PNG_UINT_31_MAX;
 159.314 -   }
 159.315 -   else
 159.316 -   {
 159.317 -     if (int_gamma < 0)
 159.318 -     {
 159.319 -       png_warning(png_ptr, "Setting negative gamma to zero");
 159.320 -       gamma=0;
 159.321 -     }
 159.322 -     else
 159.323 -       gamma=int_gamma;
 159.324 -   }
 159.325 -#ifdef PNG_FLOATING_POINT_SUPPORTED
 159.326 -   info_ptr->gamma = (float)(gamma/100000.);
 159.327 -#endif
 159.328 -#ifdef PNG_FIXED_POINT_SUPPORTED
 159.329 -   info_ptr->int_gamma = gamma;
 159.330 -#endif
 159.331 -   info_ptr->valid |= PNG_INFO_gAMA;
 159.332 -   if(gamma == 0)
 159.333 -      png_warning(png_ptr, "Setting gamma=0");
 159.334 -}
 159.335 -#endif
 159.336 -
 159.337 -#if defined(PNG_hIST_SUPPORTED)
 159.338 -void PNGAPI
 159.339 -png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist)
 159.340 -{
 159.341 -   int i;
 159.342 -
 159.343 -   png_debug1(1, "in %s storage function\n", "hIST");
 159.344 -   if (png_ptr == NULL || info_ptr == NULL)
 159.345 -      return;
 159.346 -   if (info_ptr->num_palette <= 0 || info_ptr->num_palette
 159.347 -       > PNG_MAX_PALETTE_LENGTH)
 159.348 -   {
 159.349 -       png_warning(png_ptr,
 159.350 -          "Invalid palette size, hIST allocation skipped.");
 159.351 -       return;
 159.352 -   }
 159.353 -
 159.354 -#ifdef PNG_FREE_ME_SUPPORTED
 159.355 -   png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0);
 159.356 -#endif
 159.357 -   /* Changed from info->num_palette to PNG_MAX_PALETTE_LENGTH in version
 159.358 -      1.2.1 */
 159.359 -   png_ptr->hist = (png_uint_16p)png_malloc_warn(png_ptr,
 159.360 -      (png_uint_32)(PNG_MAX_PALETTE_LENGTH * png_sizeof (png_uint_16)));
 159.361 -   if (png_ptr->hist == NULL)
 159.362 -     {
 159.363 -       png_warning(png_ptr, "Insufficient memory for hIST chunk data.");
 159.364 -       return;
 159.365 -     }
 159.366  
 159.367     for (i = 0; i < info_ptr->num_palette; i++)
 159.368 -       png_ptr->hist[i] = hist[i];
 159.369 +      png_ptr->hist[i] = hist[i];
 159.370 +
 159.371     info_ptr->hist = png_ptr->hist;
 159.372     info_ptr->valid |= PNG_INFO_hIST;
 159.373 -
 159.374 -#ifdef PNG_FREE_ME_SUPPORTED
 159.375     info_ptr->free_me |= PNG_FREE_HIST;
 159.376 -#else
 159.377 -   png_ptr->flags |= PNG_FLAG_FREE_HIST;
 159.378 -#endif
 159.379  }
 159.380  #endif
 159.381  
 159.382  void PNGAPI
 159.383  png_set_IHDR(png_structp png_ptr, png_infop info_ptr,
 159.384 -   png_uint_32 width, png_uint_32 height, int bit_depth,
 159.385 -   int color_type, int interlace_type, int compression_type,
 159.386 -   int filter_type)
 159.387 +    png_uint_32 width, png_uint_32 height, int bit_depth,
 159.388 +    int color_type, int interlace_type, int compression_type,
 159.389 +    int filter_type)
 159.390  {
 159.391 -   png_debug1(1, "in %s storage function\n", "IHDR");
 159.392 +   png_debug1(1, "in %s storage function", "IHDR");
 159.393 +
 159.394     if (png_ptr == NULL || info_ptr == NULL)
 159.395        return;
 159.396  
 159.397 -   /* check for width and height valid values */
 159.398 -   if (width == 0 || height == 0)
 159.399 -      png_error(png_ptr, "Image width or height is zero in IHDR");
 159.400 -#ifdef PNG_SET_USER_LIMITS_SUPPORTED
 159.401 -   if (width > png_ptr->user_width_max || height > png_ptr->user_height_max)
 159.402 -      png_error(png_ptr, "image size exceeds user limits in IHDR");
 159.403 -#else
 159.404 -   if (width > PNG_USER_WIDTH_MAX || height > PNG_USER_HEIGHT_MAX)
 159.405 -      png_error(png_ptr, "image size exceeds user limits in IHDR");
 159.406 -#endif
 159.407 -   if (width > PNG_UINT_31_MAX || height > PNG_UINT_31_MAX)
 159.408 -      png_error(png_ptr, "Invalid image size in IHDR");
 159.409 -   if ( width > (PNG_UINT_32_MAX
 159.410 -                 >> 3)      /* 8-byte RGBA pixels */
 159.411 -                 - 64       /* bigrowbuf hack */
 159.412 -                 - 1        /* filter byte */
 159.413 -                 - 7*8      /* rounding of width to multiple of 8 pixels */
 159.414 -                 - 8)       /* extra max_pixel_depth pad */
 159.415 -      png_warning(png_ptr, "Width is too large for libpng to process pixels");
 159.416 -
 159.417 -   /* check other values */
 159.418 -   if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 &&
 159.419 -      bit_depth != 8 && bit_depth != 16)
 159.420 -      png_error(png_ptr, "Invalid bit depth in IHDR");
 159.421 -
 159.422 -   if (color_type < 0 || color_type == 1 ||
 159.423 -      color_type == 5 || color_type > 6)
 159.424 -      png_error(png_ptr, "Invalid color type in IHDR");
 159.425 -
 159.426 -   if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) ||
 159.427 -       ((color_type == PNG_COLOR_TYPE_RGB ||
 159.428 -         color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
 159.429 -         color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8))
 159.430 -      png_error(png_ptr, "Invalid color type/bit depth combination in IHDR");
 159.431 -
 159.432 -   if (interlace_type >= PNG_INTERLACE_LAST)
 159.433 -      png_error(png_ptr, "Unknown interlace method in IHDR");
 159.434 -
 159.435 -   if (compression_type != PNG_COMPRESSION_TYPE_BASE)
 159.436 -      png_error(png_ptr, "Unknown compression method in IHDR");
 159.437 -
 159.438 -#if defined(PNG_MNG_FEATURES_SUPPORTED)
 159.439 -   /* Accept filter_method 64 (intrapixel differencing) only if
 159.440 -    * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and
 159.441 -    * 2. Libpng did not read a PNG signature (this filter_method is only
 159.442 -    *    used in PNG datastreams that are embedded in MNG datastreams) and
 159.443 -    * 3. The application called png_permit_mng_features with a mask that
 159.444 -    *    included PNG_FLAG_MNG_FILTER_64 and
 159.445 -    * 4. The filter_method is 64 and
 159.446 -    * 5. The color_type is RGB or RGBA
 159.447 -    */
 159.448 -   if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&png_ptr->mng_features_permitted)
 159.449 -      png_warning(png_ptr,"MNG features are not allowed in a PNG datastream");
 159.450 -   if(filter_type != PNG_FILTER_TYPE_BASE)
 159.451 -   {
 159.452 -     if(!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
 159.453 -        (filter_type == PNG_INTRAPIXEL_DIFFERENCING) &&
 159.454 -        ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
 159.455 -        (color_type == PNG_COLOR_TYPE_RGB ||
 159.456 -         color_type == PNG_COLOR_TYPE_RGB_ALPHA)))
 159.457 -        png_error(png_ptr, "Unknown filter method in IHDR");
 159.458 -     if(png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)
 159.459 -        png_warning(png_ptr, "Invalid filter method in IHDR");
 159.460 -   }
 159.461 -#else
 159.462 -   if(filter_type != PNG_FILTER_TYPE_BASE)
 159.463 -      png_error(png_ptr, "Unknown filter method in IHDR");
 159.464 -#endif
 159.465 -
 159.466     info_ptr->width = width;
 159.467     info_ptr->height = height;
 159.468     info_ptr->bit_depth = (png_byte)bit_depth;
 159.469 -   info_ptr->color_type =(png_byte) color_type;
 159.470 +   info_ptr->color_type = (png_byte)color_type;
 159.471     info_ptr->compression_type = (png_byte)compression_type;
 159.472     info_ptr->filter_type = (png_byte)filter_type;
 159.473     info_ptr->interlace_type = (png_byte)interlace_type;
 159.474 +
 159.475 +   png_check_IHDR (png_ptr, info_ptr->width, info_ptr->height,
 159.476 +       info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type,
 159.477 +       info_ptr->compression_type, info_ptr->filter_type);
 159.478 +
 159.479     if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
 159.480        info_ptr->channels = 1;
 159.481 +
 159.482     else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
 159.483        info_ptr->channels = 3;
 159.484 +
 159.485     else
 159.486        info_ptr->channels = 1;
 159.487 +
 159.488     if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
 159.489        info_ptr->channels++;
 159.490 +
 159.491     info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth);
 159.492  
 159.493 -   /* check for potential overflow */
 159.494 -   if ( width > (PNG_UINT_32_MAX
 159.495 -                 >> 3)      /* 8-byte RGBA pixels */
 159.496 -                 - 64       /* bigrowbuf hack */
 159.497 -                 - 1        /* filter byte */
 159.498 -                 - 7*8      /* rounding of width to multiple of 8 pixels */
 159.499 -                 - 8)       /* extra max_pixel_depth pad */
 159.500 -      info_ptr->rowbytes = (png_size_t)0;
 159.501 +   /* Check for potential overflow */
 159.502 +   if (width >
 159.503 +       (PNG_UINT_32_MAX >> 3)      /* 8-byte RRGGBBAA pixels */
 159.504 +       - 48       /* bigrowbuf hack */
 159.505 +       - 1        /* filter byte */
 159.506 +       - 7*8      /* rounding of width to multiple of 8 pixels */
 159.507 +       - 8)       /* extra max_pixel_depth pad */
 159.508 +      info_ptr->rowbytes = 0;
 159.509     else
 159.510 -      info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,width);
 159.511 +      info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, width);
 159.512  }
 159.513  
 159.514 -#if defined(PNG_oFFs_SUPPORTED)
 159.515 +#ifdef PNG_oFFs_SUPPORTED
 159.516  void PNGAPI
 159.517  png_set_oFFs(png_structp png_ptr, png_infop info_ptr,
 159.518 -   png_int_32 offset_x, png_int_32 offset_y, int unit_type)
 159.519 +    png_int_32 offset_x, png_int_32 offset_y, int unit_type)
 159.520  {
 159.521 -   png_debug1(1, "in %s storage function\n", "oFFs");
 159.522 +   png_debug1(1, "in %s storage function", "oFFs");
 159.523 +
 159.524     if (png_ptr == NULL || info_ptr == NULL)
 159.525        return;
 159.526  
 159.527 @@ -408,139 +259,227 @@
 159.528  }
 159.529  #endif
 159.530  
 159.531 -#if defined(PNG_pCAL_SUPPORTED)
 159.532 +#ifdef PNG_pCAL_SUPPORTED
 159.533  void PNGAPI
 159.534  png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
 159.535 -   png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams,
 159.536 -   png_charp units, png_charpp params)
 159.537 +    png_const_charp purpose, png_int_32 X0, png_int_32 X1, int type,
 159.538 +    int nparams, png_const_charp units, png_charpp params)
 159.539  {
 159.540 -   png_uint_32 length;
 159.541 +   png_size_t length;
 159.542     int i;
 159.543  
 159.544 -   png_debug1(1, "in %s storage function\n", "pCAL");
 159.545 +   png_debug1(1, "in %s storage function", "pCAL");
 159.546 +
 159.547     if (png_ptr == NULL || info_ptr == NULL)
 159.548        return;
 159.549  
 159.550     length = png_strlen(purpose) + 1;
 159.551 -   png_debug1(3, "allocating purpose for info (%lu bytes)\n", length);
 159.552 +   png_debug1(3, "allocating purpose for info (%lu bytes)",
 159.553 +       (unsigned long)length);
 159.554 +
 159.555 +   /* TODO: validate format of calibration name and unit name */
 159.556 +
 159.557 +   /* Check that the type matches the specification. */
 159.558 +   if (type < 0 || type > 3)
 159.559 +      png_error(png_ptr, "Invalid pCAL equation type");
 159.560 +
 159.561 +   /* Validate params[nparams] */
 159.562 +   for (i=0; i<nparams; ++i)
 159.563 +      if (!png_check_fp_string(params[i], png_strlen(params[i])))
 159.564 +         png_error(png_ptr, "Invalid format for pCAL parameter");
 159.565 +
 159.566     info_ptr->pcal_purpose = (png_charp)png_malloc_warn(png_ptr, length);
 159.567 +
 159.568     if (info_ptr->pcal_purpose == NULL)
 159.569 -     {
 159.570 -       png_warning(png_ptr, "Insufficient memory for pCAL purpose.");
 159.571 -       return;
 159.572 -     }
 159.573 -   png_memcpy(info_ptr->pcal_purpose, purpose, (png_size_t)length);
 159.574 +   {
 159.575 +      png_warning(png_ptr, "Insufficient memory for pCAL purpose");
 159.576 +      return;
 159.577 +   }
 159.578  
 159.579 -   png_debug(3, "storing X0, X1, type, and nparams in info\n");
 159.580 +   png_memcpy(info_ptr->pcal_purpose, purpose, length);
 159.581 +
 159.582 +   png_debug(3, "storing X0, X1, type, and nparams in info");
 159.583     info_ptr->pcal_X0 = X0;
 159.584     info_ptr->pcal_X1 = X1;
 159.585     info_ptr->pcal_type = (png_byte)type;
 159.586     info_ptr->pcal_nparams = (png_byte)nparams;
 159.587  
 159.588     length = png_strlen(units) + 1;
 159.589 -   png_debug1(3, "allocating units for info (%lu bytes)\n", length);
 159.590 +   png_debug1(3, "allocating units for info (%lu bytes)",
 159.591 +     (unsigned long)length);
 159.592 +
 159.593     info_ptr->pcal_units = (png_charp)png_malloc_warn(png_ptr, length);
 159.594 +
 159.595     if (info_ptr->pcal_units == NULL)
 159.596 -     {
 159.597 -       png_warning(png_ptr, "Insufficient memory for pCAL units.");
 159.598 -       return;
 159.599 -     }
 159.600 -   png_memcpy(info_ptr->pcal_units, units, (png_size_t)length);
 159.601 +   {
 159.602 +      png_warning(png_ptr, "Insufficient memory for pCAL units");
 159.603 +      return;
 159.604 +   }
 159.605 +
 159.606 +   png_memcpy(info_ptr->pcal_units, units, length);
 159.607  
 159.608     info_ptr->pcal_params = (png_charpp)png_malloc_warn(png_ptr,
 159.609 -      (png_uint_32)((nparams + 1) * png_sizeof(png_charp)));
 159.610 +       (png_size_t)((nparams + 1) * png_sizeof(png_charp)));
 159.611 +
 159.612     if (info_ptr->pcal_params == NULL)
 159.613 -     {
 159.614 -       png_warning(png_ptr, "Insufficient memory for pCAL params.");
 159.615 -       return;
 159.616 -     }
 159.617 +   {
 159.618 +      png_warning(png_ptr, "Insufficient memory for pCAL params");
 159.619 +      return;
 159.620 +   }
 159.621  
 159.622 -   info_ptr->pcal_params[nparams] = NULL;
 159.623 +   png_memset(info_ptr->pcal_params, 0, (nparams + 1) * png_sizeof(png_charp));
 159.624  
 159.625     for (i = 0; i < nparams; i++)
 159.626     {
 159.627        length = png_strlen(params[i]) + 1;
 159.628 -      png_debug2(3, "allocating parameter %d for info (%lu bytes)\n", i, length);
 159.629 +      png_debug2(3, "allocating parameter %d for info (%lu bytes)", i,
 159.630 +          (unsigned long)length);
 159.631 +
 159.632        info_ptr->pcal_params[i] = (png_charp)png_malloc_warn(png_ptr, length);
 159.633 +
 159.634        if (info_ptr->pcal_params[i] == NULL)
 159.635 -        {
 159.636 -          png_warning(png_ptr, "Insufficient memory for pCAL parameter.");
 159.637 -          return;
 159.638 -        }
 159.639 -      png_memcpy(info_ptr->pcal_params[i], params[i], (png_size_t)length);
 159.640 +      {
 159.641 +         png_warning(png_ptr, "Insufficient memory for pCAL parameter");
 159.642 +         return;
 159.643 +      }
 159.644 +
 159.645 +      png_memcpy(info_ptr->pcal_params[i], params[i], length);
 159.646     }
 159.647  
 159.648     info_ptr->valid |= PNG_INFO_pCAL;
 159.649 -#ifdef PNG_FREE_ME_SUPPORTED
 159.650     info_ptr->free_me |= PNG_FREE_PCAL;
 159.651 -#endif
 159.652  }
 159.653  #endif
 159.654  
 159.655 -#if defined(PNG_READ_sCAL_SUPPORTED) || defined(PNG_WRITE_sCAL_SUPPORTED)
 159.656 -#ifdef PNG_FLOATING_POINT_SUPPORTED
 159.657 +#ifdef PNG_sCAL_SUPPORTED
 159.658  void PNGAPI
 159.659 -png_set_sCAL(png_structp png_ptr, png_infop info_ptr,
 159.660 -             int unit, double width, double height)
 159.661 +png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr,
 159.662 +    int unit, png_const_charp swidth, png_const_charp sheight)
 159.663  {
 159.664 -   png_debug1(1, "in %s storage function\n", "sCAL");
 159.665 +   png_size_t lengthw = 0, lengthh = 0;
 159.666 +
 159.667 +   png_debug1(1, "in %s storage function", "sCAL");
 159.668 +
 159.669     if (png_ptr == NULL || info_ptr == NULL)
 159.670        return;
 159.671  
 159.672 -   info_ptr->scal_unit = (png_byte)unit;
 159.673 -   info_ptr->scal_pixel_width = width;
 159.674 -   info_ptr->scal_pixel_height = height;
 159.675 +   /* Double check the unit (should never get here with an invalid
 159.676 +    * unit unless this is an API call.)
 159.677 +    */
 159.678 +   if (unit != 1 && unit != 2)
 159.679 +      png_error(png_ptr, "Invalid sCAL unit");
 159.680  
 159.681 -   info_ptr->valid |= PNG_INFO_sCAL;
 159.682 -}
 159.683 -#else
 159.684 -#ifdef PNG_FIXED_POINT_SUPPORTED
 159.685 -void PNGAPI
 159.686 -png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr,
 159.687 -             int unit, png_charp swidth, png_charp sheight)
 159.688 -{
 159.689 -   png_uint_32 length;
 159.690 +   if (swidth == NULL || (lengthw = png_strlen(swidth)) == 0 ||
 159.691 +       swidth[0] == 45 /* '-' */ || !png_check_fp_string(swidth, lengthw))
 159.692 +      png_error(png_ptr, "Invalid sCAL width");
 159.693  
 159.694 -   png_debug1(1, "in %s storage function\n", "sCAL");
 159.695 -   if (png_ptr == NULL || info_ptr == NULL)
 159.696 -      return;
 159.697 +   if (sheight == NULL || (lengthh = png_strlen(sheight)) == 0 ||
 159.698 +       sheight[0] == 45 /* '-' */ || !png_check_fp_string(sheight, lengthh))
 159.699 +      png_error(png_ptr, "Invalid sCAL height");
 159.700  
 159.701     info_ptr->scal_unit = (png_byte)unit;
 159.702  
 159.703 -   length = png_strlen(swidth) + 1;
 159.704 -   png_debug1(3, "allocating unit for info (%d bytes)\n", length);
 159.705 -   info_ptr->scal_s_width = (png_charp)png_malloc_warn(png_ptr, length);
 159.706 +   ++lengthw;
 159.707 +
 159.708 +   png_debug1(3, "allocating unit for info (%u bytes)", (unsigned int)lengthw);
 159.709 +
 159.710 +   info_ptr->scal_s_width = (png_charp)png_malloc_warn(png_ptr, lengthw);
 159.711 +
 159.712     if (info_ptr->scal_s_width == NULL)
 159.713     {
 159.714 -      png_warning(png_ptr, "Memory allocation failed while processing sCAL.");
 159.715 +      png_warning(png_ptr, "Memory allocation failed while processing sCAL");
 159.716 +      return;
 159.717     }
 159.718 -   png_memcpy(info_ptr->scal_s_width, swidth, (png_size_t)length);
 159.719  
 159.720 -   length = png_strlen(sheight) + 1;
 159.721 -   png_debug1(3, "allocating unit for info (%d bytes)\n", length);
 159.722 -   info_ptr->scal_s_height = (png_charp)png_malloc_warn(png_ptr, length);
 159.723 +   png_memcpy(info_ptr->scal_s_width, swidth, lengthw);
 159.724 +
 159.725 +   ++lengthh;
 159.726 +
 159.727 +   png_debug1(3, "allocating unit for info (%u bytes)", (unsigned int)lengthh);
 159.728 +
 159.729 +   info_ptr->scal_s_height = (png_charp)png_malloc_warn(png_ptr, lengthh);
 159.730 +
 159.731     if (info_ptr->scal_s_height == NULL)
 159.732     {
 159.733        png_free (png_ptr, info_ptr->scal_s_width);
 159.734 -      png_warning(png_ptr, "Memory allocation failed while processing sCAL.");
 159.735 +      info_ptr->scal_s_width = NULL;
 159.736 +
 159.737 +      png_warning(png_ptr, "Memory allocation failed while processing sCAL");
 159.738 +      return;
 159.739     }
 159.740 -   png_memcpy(info_ptr->scal_s_height, sheight, (png_size_t)length);
 159.741 +
 159.742 +   png_memcpy(info_ptr->scal_s_height, sheight, lengthh);
 159.743  
 159.744     info_ptr->valid |= PNG_INFO_sCAL;
 159.745 -#ifdef PNG_FREE_ME_SUPPORTED
 159.746     info_ptr->free_me |= PNG_FREE_SCAL;
 159.747 -#endif
 159.748  }
 159.749 -#endif
 159.750 -#endif
 159.751 +
 159.752 +#  ifdef PNG_FLOATING_POINT_SUPPORTED
 159.753 +void PNGAPI
 159.754 +png_set_sCAL(png_structp png_ptr, png_infop info_ptr, int unit, double width,
 159.755 +    double height)
 159.756 +{
 159.757 +   png_debug1(1, "in %s storage function", "sCAL");
 159.758 +
 159.759 +   /* Check the arguments. */
 159.760 +   if (width <= 0)
 159.761 +      png_warning(png_ptr, "Invalid sCAL width ignored");
 159.762 +
 159.763 +   else if (height <= 0)
 159.764 +      png_warning(png_ptr, "Invalid sCAL height ignored");
 159.765 +
 159.766 +   else
 159.767 +   {
 159.768 +      /* Convert 'width' and 'height' to ASCII. */
 159.769 +      char swidth[PNG_sCAL_MAX_DIGITS+1];
 159.770 +      char sheight[PNG_sCAL_MAX_DIGITS+1];
 159.771 +
 159.772 +      png_ascii_from_fp(png_ptr, swidth, sizeof swidth, width,
 159.773 +         PNG_sCAL_PRECISION);
 159.774 +      png_ascii_from_fp(png_ptr, sheight, sizeof sheight, height,
 159.775 +         PNG_sCAL_PRECISION);
 159.776 +
 159.777 +      png_set_sCAL_s(png_ptr, info_ptr, unit, swidth, sheight);
 159.778 +   }
 159.779 +}
 159.780 +#  endif
 159.781 +
 159.782 +#  ifdef PNG_FIXED_POINT_SUPPORTED
 159.783 +void PNGAPI
 159.784 +png_set_sCAL_fixed(png_structp png_ptr, png_infop info_ptr, int unit,
 159.785 +    png_fixed_point width, png_fixed_point height)
 159.786 +{
 159.787 +   png_debug1(1, "in %s storage function", "sCAL");
 159.788 +
 159.789 +   /* Check the arguments. */
 159.790 +   if (width <= 0)
 159.791 +      png_warning(png_ptr, "Invalid sCAL width ignored");
 159.792 +
 159.793 +   else if (height <= 0)
 159.794 +      png_warning(png_ptr, "Invalid sCAL height ignored");
 159.795 +
 159.796 +   else
 159.797 +   {
 159.798 +      /* Convert 'width' and 'height' to ASCII. */
 159.799 +      char swidth[PNG_sCAL_MAX_DIGITS+1];
 159.800 +      char sheight[PNG_sCAL_MAX_DIGITS+1];
 159.801 +
 159.802 +      png_ascii_from_fixed(png_ptr, swidth, sizeof swidth, width);
 159.803 +      png_ascii_from_fixed(png_ptr, sheight, sizeof sheight, height);
 159.804 +
 159.805 +      png_set_sCAL_s(png_ptr, info_ptr, unit, swidth, sheight);
 159.806 +   }
 159.807 +}
 159.808 +#  endif
 159.809  #endif
 159.810  
 159.811 -#if defined(PNG_pHYs_SUPPORTED)
 159.812 +#ifdef PNG_pHYs_SUPPORTED
 159.813  void PNGAPI
 159.814  png_set_pHYs(png_structp png_ptr, png_infop info_ptr,
 159.815 -   png_uint_32 res_x, png_uint_32 res_y, int unit_type)
 159.816 +    png_uint_32 res_x, png_uint_32 res_y, int unit_type)
 159.817  {
 159.818 -   png_debug1(1, "in %s storage function\n", "pHYs");
 159.819 +   png_debug1(1, "in %s storage function", "pHYs");
 159.820 +
 159.821     if (png_ptr == NULL || info_ptr == NULL)
 159.822        return;
 159.823  
 159.824 @@ -553,177 +492,139 @@
 159.825  
 159.826  void PNGAPI
 159.827  png_set_PLTE(png_structp png_ptr, png_infop info_ptr,
 159.828 -   png_colorp palette, int num_palette)
 159.829 +    png_const_colorp palette, int num_palette)
 159.830  {
 159.831  
 159.832 -   png_debug1(1, "in %s storage function\n", "PLTE");
 159.833 +   png_debug1(1, "in %s storage function", "PLTE");
 159.834 +
 159.835     if (png_ptr == NULL || info_ptr == NULL)
 159.836        return;
 159.837  
 159.838     if (num_palette < 0 || num_palette > PNG_MAX_PALETTE_LENGTH)
 159.839 -     {
 159.840 -       if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
 159.841 +   {
 159.842 +      if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
 159.843           png_error(png_ptr, "Invalid palette length");
 159.844 -       else
 159.845 -       {
 159.846 +
 159.847 +      else
 159.848 +      {
 159.849           png_warning(png_ptr, "Invalid palette length");
 159.850           return;
 159.851 -       }
 159.852 -     }
 159.853 +      }
 159.854 +   }
 159.855  
 159.856 -   /*
 159.857 -    * It may not actually be necessary to set png_ptr->palette here;
 159.858 +   /* It may not actually be necessary to set png_ptr->palette here;
 159.859      * we do it for backward compatibility with the way the png_handle_tRNS
 159.860      * function used to do the allocation.
 159.861      */
 159.862 -#ifdef PNG_FREE_ME_SUPPORTED
 159.863     png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0);
 159.864 -#endif
 159.865  
 159.866     /* Changed in libpng-1.2.1 to allocate PNG_MAX_PALETTE_LENGTH instead
 159.867 -      of num_palette entries,
 159.868 -      in case of an invalid PNG file that has too-large sample values. */
 159.869 -   png_ptr->palette = (png_colorp)png_malloc(png_ptr,
 159.870 -      PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color));
 159.871 -   png_memset(png_ptr->palette, 0, PNG_MAX_PALETTE_LENGTH *
 159.872 -      png_sizeof(png_color));
 159.873 -   png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof (png_color));
 159.874 +    * of num_palette entries, in case of an invalid PNG file that has
 159.875 +    * too-large sample values.
 159.876 +    */
 159.877 +   png_ptr->palette = (png_colorp)png_calloc(png_ptr,
 159.878 +       PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color));
 159.879 +
 159.880 +   png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof(png_color));
 159.881     info_ptr->palette = png_ptr->palette;
 159.882     info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;
 159.883  
 159.884 -#ifdef PNG_FREE_ME_SUPPORTED
 159.885     info_ptr->free_me |= PNG_FREE_PLTE;
 159.886 -#else
 159.887 -   png_ptr->flags |= PNG_FLAG_FREE_PLTE;
 159.888 -#endif
 159.889  
 159.890     info_ptr->valid |= PNG_INFO_PLTE;
 159.891  }
 159.892  
 159.893 -#if defined(PNG_sBIT_SUPPORTED)
 159.894 +#ifdef PNG_sBIT_SUPPORTED
 159.895  void PNGAPI
 159.896  png_set_sBIT(png_structp png_ptr, png_infop info_ptr,
 159.897 -   png_color_8p sig_bit)
 159.898 +    png_const_color_8p sig_bit)
 159.899  {
 159.900 -   png_debug1(1, "in %s storage function\n", "sBIT");
 159.901 +   png_debug1(1, "in %s storage function", "sBIT");
 159.902 +
 159.903     if (png_ptr == NULL || info_ptr == NULL)
 159.904        return;
 159.905  
 159.906 -   png_memcpy(&(info_ptr->sig_bit), sig_bit, png_sizeof (png_color_8));
 159.907 +   png_memcpy(&(info_ptr->sig_bit), sig_bit, png_sizeof(png_color_8));
 159.908     info_ptr->valid |= PNG_INFO_sBIT;
 159.909  }
 159.910  #endif
 159.911  
 159.912 -#if defined(PNG_sRGB_SUPPORTED)
 159.913 +#ifdef PNG_sRGB_SUPPORTED
 159.914  void PNGAPI
 159.915 -png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int intent)
 159.916 +png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int srgb_intent)
 159.917  {
 159.918 -   png_debug1(1, "in %s storage function\n", "sRGB");
 159.919 +   png_debug1(1, "in %s storage function", "sRGB");
 159.920 +
 159.921     if (png_ptr == NULL || info_ptr == NULL)
 159.922        return;
 159.923  
 159.924 -   info_ptr->srgb_intent = (png_byte)intent;
 159.925 +   info_ptr->srgb_intent = (png_byte)srgb_intent;
 159.926     info_ptr->valid |= PNG_INFO_sRGB;
 159.927  }
 159.928  
 159.929  void PNGAPI
 159.930  png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
 159.931 -   int intent)
 159.932 +    int srgb_intent)
 159.933  {
 159.934 -#if defined(PNG_gAMA_SUPPORTED)
 159.935 -#ifdef PNG_FLOATING_POINT_SUPPORTED
 159.936 -   float file_gamma;
 159.937 -#endif
 159.938 -#ifdef PNG_FIXED_POINT_SUPPORTED
 159.939 -   png_fixed_point int_file_gamma;
 159.940 -#endif
 159.941 -#endif
 159.942 -#if defined(PNG_cHRM_SUPPORTED)
 159.943 -#ifdef PNG_FLOATING_POINT_SUPPORTED
 159.944 -   float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
 159.945 -#endif
 159.946 -#ifdef PNG_FIXED_POINT_SUPPORTED
 159.947 -   png_fixed_point int_white_x, int_white_y, int_red_x, int_red_y, int_green_x,
 159.948 -      int_green_y, int_blue_x, int_blue_y;
 159.949 -#endif
 159.950 -#endif
 159.951 -   png_debug1(1, "in %s storage function\n", "sRGB_gAMA_and_cHRM");
 159.952 +   png_debug1(1, "in %s storage function", "sRGB_gAMA_and_cHRM");
 159.953 +
 159.954     if (png_ptr == NULL || info_ptr == NULL)
 159.955        return;
 159.956  
 159.957 -   png_set_sRGB(png_ptr, info_ptr, intent);
 159.958 +   png_set_sRGB(png_ptr, info_ptr, srgb_intent);
 159.959  
 159.960 -#if defined(PNG_gAMA_SUPPORTED)
 159.961 -#ifdef PNG_FLOATING_POINT_SUPPORTED
 159.962 -   file_gamma = (float).45455;
 159.963 -   png_set_gAMA(png_ptr, info_ptr, file_gamma);
 159.964 -#endif
 159.965 -#ifdef PNG_FIXED_POINT_SUPPORTED
 159.966 -   int_file_gamma = 45455L;
 159.967 -   png_set_gAMA_fixed(png_ptr, info_ptr, int_file_gamma);
 159.968 -#endif
 159.969 -#endif
 159.970 +#  ifdef PNG_gAMA_SUPPORTED
 159.971 +   png_set_gAMA_fixed(png_ptr, info_ptr, PNG_GAMMA_sRGB_INVERSE);
 159.972 +#  endif
 159.973  
 159.974 -#if defined(PNG_cHRM_SUPPORTED)
 159.975 -#ifdef PNG_FIXED_POINT_SUPPORTED
 159.976 -   int_white_x = 31270L;
 159.977 -   int_white_y = 32900L;
 159.978 -   int_red_x   = 64000L;
 159.979 -   int_red_y   = 33000L;
 159.980 -   int_green_x = 30000L;
 159.981 -   int_green_y = 60000L;
 159.982 -   int_blue_x  = 15000L;
 159.983 -   int_blue_y  =  6000L;
 159.984 +#  ifdef PNG_cHRM_SUPPORTED
 159.985 +   png_set_cHRM_fixed(png_ptr, info_ptr,
 159.986 +      /* color      x       y */
 159.987 +      /* white */ 31270L, 32900L,
 159.988 +      /* red   */ 64000L, 33000L,
 159.989 +      /* green */ 30000L, 60000L,
 159.990 +      /* blue  */ 15000L,  6000L
 159.991 +   );
 159.992 +#  endif /* cHRM */
 159.993 +}
 159.994 +#endif /* sRGB */
 159.995  
 159.996 -   png_set_cHRM_fixed(png_ptr, info_ptr,
 159.997 -      int_white_x, int_white_y, int_red_x, int_red_y, int_green_x, int_green_y,
 159.998 -      int_blue_x, int_blue_y);
 159.999 -#endif
159.1000 -#ifdef PNG_FLOATING_POINT_SUPPORTED
159.1001 -   white_x = (float).3127;
159.1002 -   white_y = (float).3290;
159.1003 -   red_x   = (float).64;
159.1004 -   red_y   = (float).33;
159.1005 -   green_x = (float).30;
159.1006 -   green_y = (float).60;
159.1007 -   blue_x  = (float).15;
159.1008 -   blue_y  = (float).06;
159.1009  
159.1010 -   png_set_cHRM(png_ptr, info_ptr,
159.1011 -      white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
159.1012 -#endif
159.1013 -#endif
159.1014 -}
159.1015 -#endif
159.1016 -
159.1017 -
159.1018 -#if defined(PNG_iCCP_SUPPORTED)
159.1019 +#ifdef PNG_iCCP_SUPPORTED
159.1020  void PNGAPI
159.1021  png_set_iCCP(png_structp png_ptr, png_infop info_ptr,
159.1022 -             png_charp name, int compression_type,
159.1023 -             png_charp profile, png_uint_32 proflen)
159.1024 +    png_const_charp name, int compression_type,
159.1025 +    png_const_bytep profile, png_uint_32 proflen)
159.1026  {
159.1027     png_charp new_iccp_name;
159.1028 -   png_charp new_iccp_profile;
159.1029 +   png_bytep new_iccp_profile;
159.1030 +   png_uint_32 length;
159.1031  
159.1032 -   png_debug1(1, "in %s storage function\n", "iCCP");
159.1033 +   png_debug1(1, "in %s storage function", "iCCP");
159.1034 +
159.1035     if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL)
159.1036        return;
159.1037  
159.1038 -   new_iccp_name = (png_charp)png_malloc_warn(png_ptr, png_strlen(name)+1);
159.1039 +   length = png_strlen(name)+1;
159.1040 +   new_iccp_name = (png_charp)png_malloc_warn(png_ptr, length);
159.1041 +
159.1042     if (new_iccp_name == NULL)
159.1043     {
159.1044 -      png_warning(png_ptr, "Insufficient memory to process iCCP chunk.");
159.1045 +        png_warning(png_ptr, "Insufficient memory to process iCCP chunk");
159.1046        return;
159.1047     }
159.1048 -   png_strcpy(new_iccp_name, name);
159.1049 -   new_iccp_profile = (png_charp)png_malloc_warn(png_ptr, proflen);
159.1050 +
159.1051 +   png_memcpy(new_iccp_name, name, length);
159.1052 +   new_iccp_profile = (png_bytep)png_malloc_warn(png_ptr, proflen);
159.1053 +
159.1054     if (new_iccp_profile == NULL)
159.1055     {
159.1056        png_free (png_ptr, new_iccp_name);
159.1057 -      png_warning(png_ptr, "Insufficient memory to process iCCP profile.");
159.1058 +      png_warning(png_ptr,
159.1059 +          "Insufficient memory to process iCCP profile");
159.1060        return;
159.1061     }
159.1062 +
159.1063     png_memcpy(new_iccp_profile, profile, (png_size_t)proflen);
159.1064  
159.1065     png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, 0);
159.1066 @@ -732,34 +633,35 @@
159.1067     info_ptr->iccp_name = new_iccp_name;
159.1068     info_ptr->iccp_profile = new_iccp_profile;
159.1069     /* Compression is always zero but is here so the API and info structure
159.1070 -    * does not have to change if we introduce multiple compression types */
159.1071 +    * does not have to change if we introduce multiple compression types
159.1072 +    */
159.1073     info_ptr->iccp_compression = (png_byte)compression_type;
159.1074 -#ifdef PNG_FREE_ME_SUPPORTED
159.1075     info_ptr->free_me |= PNG_FREE_ICCP;
159.1076 -#endif
159.1077     info_ptr->valid |= PNG_INFO_iCCP;
159.1078  }
159.1079  #endif
159.1080  
159.1081 -#if defined(PNG_TEXT_SUPPORTED)
159.1082 +#ifdef PNG_TEXT_SUPPORTED
159.1083  void PNGAPI
159.1084 -png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
159.1085 -   int num_text)
159.1086 +png_set_text(png_structp png_ptr, png_infop info_ptr, png_const_textp text_ptr,
159.1087 +    int num_text)
159.1088  {
159.1089     int ret;
159.1090 -   ret=png_set_text_2(png_ptr, info_ptr, text_ptr, num_text);
159.1091 +   ret = png_set_text_2(png_ptr, info_ptr, text_ptr, num_text);
159.1092 +
159.1093     if (ret)
159.1094 -     png_error(png_ptr, "Insufficient memory to store text");
159.1095 +      png_error(png_ptr, "Insufficient memory to store text");
159.1096  }
159.1097  
159.1098  int /* PRIVATE */
159.1099 -png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
159.1100 -   int num_text)
159.1101 +png_set_text_2(png_structp png_ptr, png_infop info_ptr,
159.1102 +    png_const_textp text_ptr, int num_text)
159.1103  {
159.1104     int i;
159.1105  
159.1106 -   png_debug1(1, "in %s storage function\n", (png_ptr->chunk_name[0] == '\0' ?
159.1107 -      "text" : (png_const_charp)png_ptr->chunk_name));
159.1108 +   png_debug1(1, "in %s storage function", ((png_ptr == NULL ||
159.1109 +       png_ptr->chunk_name[0] == '\0') ?
159.1110 +       "text" : (png_const_charp)png_ptr->chunk_name));
159.1111  
159.1112     if (png_ptr == NULL || info_ptr == NULL || num_text == 0)
159.1113        return(0);
159.1114 @@ -778,77 +680,93 @@
159.1115           info_ptr->max_text = info_ptr->num_text + num_text + 8;
159.1116           old_text = info_ptr->text;
159.1117           info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
159.1118 -            (png_uint_32)(info_ptr->max_text * png_sizeof (png_text)));
159.1119 +            (png_size_t)(info_ptr->max_text * png_sizeof(png_text)));
159.1120 +
159.1121           if (info_ptr->text == NULL)
159.1122 -           {
159.1123 -             png_free(png_ptr, old_text);
159.1124 -             return(1);
159.1125 -           }
159.1126 +         {
159.1127 +            png_free(png_ptr, old_text);
159.1128 +            return(1);
159.1129 +         }
159.1130 +
159.1131           png_memcpy(info_ptr->text, old_text, (png_size_t)(old_max *
159.1132 -            png_sizeof(png_text)));
159.1133 +             png_sizeof(png_text)));
159.1134           png_free(png_ptr, old_text);
159.1135        }
159.1136 +
159.1137        else
159.1138        {
159.1139           info_ptr->max_text = num_text + 8;
159.1140           info_ptr->num_text = 0;
159.1141           info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
159.1142 -            (png_uint_32)(info_ptr->max_text * png_sizeof (png_text)));
159.1143 +             (png_size_t)(info_ptr->max_text * png_sizeof(png_text)));
159.1144           if (info_ptr->text == NULL)
159.1145 -           return(1);
159.1146 -#ifdef PNG_FREE_ME_SUPPORTED
159.1147 +            return(1);
159.1148           info_ptr->free_me |= PNG_FREE_TEXT;
159.1149 -#endif
159.1150        }
159.1151 -      png_debug1(3, "allocated %d entries for info_ptr->text\n",
159.1152 -         info_ptr->max_text);
159.1153 +
159.1154 +      png_debug1(3, "allocated %d entries for info_ptr->text",
159.1155 +          info_ptr->max_text);
159.1156     }
159.1157     for (i = 0; i < num_text; i++)
159.1158     {
159.1159 -      png_size_t text_length,key_len;
159.1160 -      png_size_t lang_len,lang_key_len;
159.1161 +      png_size_t text_length, key_len;
159.1162 +      png_size_t lang_len, lang_key_len;
159.1163        png_textp textp = &(info_ptr->text[info_ptr->num_text]);
159.1164  
159.1165        if (text_ptr[i].key == NULL)
159.1166            continue;
159.1167  
159.1168 +      if (text_ptr[i].compression < PNG_TEXT_COMPRESSION_NONE ||
159.1169 +          text_ptr[i].compression >= PNG_TEXT_COMPRESSION_LAST)
159.1170 +      {
159.1171 +         png_warning(png_ptr, "text compression mode is out of range");
159.1172 +         continue;
159.1173 +      }
159.1174 +
159.1175        key_len = png_strlen(text_ptr[i].key);
159.1176  
159.1177 -      if(text_ptr[i].compression <= 0)
159.1178 +      if (text_ptr[i].compression <= 0)
159.1179        {
159.1180 -        lang_len = 0;
159.1181 -        lang_key_len = 0;
159.1182 +         lang_len = 0;
159.1183 +         lang_key_len = 0;
159.1184        }
159.1185 +
159.1186        else
159.1187 -#ifdef PNG_iTXt_SUPPORTED
159.1188 +#  ifdef PNG_iTXt_SUPPORTED
159.1189        {
159.1190 -        /* set iTXt data */
159.1191 -        if (text_ptr[i].lang != NULL)
159.1192 -          lang_len = png_strlen(text_ptr[i].lang);
159.1193 -        else
159.1194 -          lang_len = 0;
159.1195 -        if (text_ptr[i].lang_key != NULL)
159.1196 -          lang_key_len = png_strlen(text_ptr[i].lang_key);
159.1197 -        else
159.1198 -          lang_key_len = 0;
159.1199 +         /* Set iTXt data */
159.1200 +
159.1201 +         if (text_ptr[i].lang != NULL)
159.1202 +            lang_len = png_strlen(text_ptr[i].lang);
159.1203 +
159.1204 +         else
159.1205 +            lang_len = 0;
159.1206 +
159.1207 +         if (text_ptr[i].lang_key != NULL)
159.1208 +            lang_key_len = png_strlen(text_ptr[i].lang_key);
159.1209 +
159.1210 +         else
159.1211 +            lang_key_len = 0;
159.1212        }
159.1213 -#else
159.1214 +#  else /* PNG_iTXt_SUPPORTED */
159.1215        {
159.1216 -        png_warning(png_ptr, "iTXt chunk not supported.");
159.1217 -        continue;
159.1218 +         png_warning(png_ptr, "iTXt chunk not supported");
159.1219 +         continue;
159.1220        }
159.1221 -#endif
159.1222 +#  endif
159.1223  
159.1224        if (text_ptr[i].text == NULL || text_ptr[i].text[0] == '\0')
159.1225        {
159.1226           text_length = 0;
159.1227 -#ifdef PNG_iTXt_SUPPORTED
159.1228 -         if(text_ptr[i].compression > 0)
159.1229 +#  ifdef PNG_iTXt_SUPPORTED
159.1230 +         if (text_ptr[i].compression > 0)
159.1231              textp->compression = PNG_ITXT_COMPRESSION_NONE;
159.1232 +
159.1233           else
159.1234 -#endif
159.1235 +#  endif
159.1236              textp->compression = PNG_TEXT_COMPRESSION_NONE;
159.1237        }
159.1238 +
159.1239        else
159.1240        {
159.1241           text_length = png_strlen(text_ptr[i].text);
159.1242 @@ -856,444 +774,481 @@
159.1243        }
159.1244  
159.1245        textp->key = (png_charp)png_malloc_warn(png_ptr,
159.1246 -         (png_uint_32)(key_len + text_length + lang_len + lang_key_len + 4));
159.1247 +          (png_size_t)
159.1248 +          (key_len + text_length + lang_len + lang_key_len + 4));
159.1249 +
159.1250        if (textp->key == NULL)
159.1251 -        return(1);
159.1252 -      png_debug2(2, "Allocated %lu bytes at %x in png_set_text\n",
159.1253 -         (png_uint_32)(key_len + lang_len + lang_key_len + text_length + 4),
159.1254 -         (int)textp->key);
159.1255 +         return(1);
159.1256  
159.1257 -      png_memcpy(textp->key, text_ptr[i].key,
159.1258 -         (png_size_t)(key_len));
159.1259 -      *(textp->key+key_len) = '\0';
159.1260 -#ifdef PNG_iTXt_SUPPORTED
159.1261 +      png_debug2(2, "Allocated %lu bytes at %p in png_set_text",
159.1262 +          (unsigned long)(png_uint_32)
159.1263 +          (key_len + lang_len + lang_key_len + text_length + 4),
159.1264 +          textp->key);
159.1265 +
159.1266 +      png_memcpy(textp->key, text_ptr[i].key,(png_size_t)(key_len));
159.1267 +      *(textp->key + key_len) = '\0';
159.1268 +
159.1269        if (text_ptr[i].compression > 0)
159.1270        {
159.1271 -         textp->lang=textp->key + key_len + 1;
159.1272 +         textp->lang = textp->key + key_len + 1;
159.1273           png_memcpy(textp->lang, text_ptr[i].lang, lang_len);
159.1274 -         *(textp->lang+lang_len) = '\0';
159.1275 -         textp->lang_key=textp->lang + lang_len + 1;
159.1276 +         *(textp->lang + lang_len) = '\0';
159.1277 +         textp->lang_key = textp->lang + lang_len + 1;
159.1278           png_memcpy(textp->lang_key, text_ptr[i].lang_key, lang_key_len);
159.1279 -         *(textp->lang_key+lang_key_len) = '\0';
159.1280 -         textp->text=textp->lang_key + lang_key_len + 1;
159.1281 +         *(textp->lang_key + lang_key_len) = '\0';
159.1282 +         textp->text = textp->lang_key + lang_key_len + 1;
159.1283        }
159.1284 +
159.1285        else
159.1286 -#endif
159.1287        {
159.1288 -#ifdef PNG_iTXt_SUPPORTED
159.1289           textp->lang=NULL;
159.1290           textp->lang_key=NULL;
159.1291 -#endif
159.1292 -         textp->text=textp->key + key_len + 1;
159.1293 +         textp->text = textp->key + key_len + 1;
159.1294        }
159.1295 -      if(text_length)
159.1296 +
159.1297 +      if (text_length)
159.1298           png_memcpy(textp->text, text_ptr[i].text,
159.1299 -            (png_size_t)(text_length));
159.1300 -      *(textp->text+text_length) = '\0';
159.1301 +             (png_size_t)(text_length));
159.1302  
159.1303 -#ifdef PNG_iTXt_SUPPORTED
159.1304 -      if(textp->compression > 0)
159.1305 +      *(textp->text + text_length) = '\0';
159.1306 +
159.1307 +#  ifdef PNG_iTXt_SUPPORTED
159.1308 +      if (textp->compression > 0)
159.1309        {
159.1310           textp->text_length = 0;
159.1311           textp->itxt_length = text_length;
159.1312        }
159.1313 +
159.1314        else
159.1315 -#endif
159.1316 +#  endif
159.1317        {
159.1318           textp->text_length = text_length;
159.1319 -#ifdef PNG_iTXt_SUPPORTED
159.1320           textp->itxt_length = 0;
159.1321 -#endif
159.1322        }
159.1323 -#if 0 /* appears to be redundant; */
159.1324 -      info_ptr->text[info_ptr->num_text]= *textp;
159.1325 -#endif
159.1326 +
159.1327        info_ptr->num_text++;
159.1328 -      png_debug1(3, "transferred text chunk %d\n", info_ptr->num_text);
159.1329 +      png_debug1(3, "transferred text chunk %d", info_ptr->num_text);
159.1330     }
159.1331     return(0);
159.1332  }
159.1333  #endif
159.1334  
159.1335 -#if defined(PNG_tIME_SUPPORTED)
159.1336 +#ifdef PNG_tIME_SUPPORTED
159.1337  void PNGAPI
159.1338 -png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time)
159.1339 +png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_const_timep mod_time)
159.1340  {
159.1341 -   png_debug1(1, "in %s storage function\n", "tIME");
159.1342 +   png_debug1(1, "in %s storage function", "tIME");
159.1343 +
159.1344     if (png_ptr == NULL || info_ptr == NULL ||
159.1345         (png_ptr->mode & PNG_WROTE_tIME))
159.1346        return;
159.1347  
159.1348 -   png_memcpy(&(info_ptr->mod_time), mod_time, png_sizeof (png_time));
159.1349 +   png_memcpy(&(info_ptr->mod_time), mod_time, png_sizeof(png_time));
159.1350     info_ptr->valid |= PNG_INFO_tIME;
159.1351  }
159.1352  #endif
159.1353  
159.1354 -#if defined(PNG_tRNS_SUPPORTED)
159.1355 +#ifdef PNG_tRNS_SUPPORTED
159.1356  void PNGAPI
159.1357  png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
159.1358 -   png_bytep trans, int num_trans, png_color_16p trans_values)
159.1359 +    png_const_bytep trans_alpha, int num_trans, png_const_color_16p trans_color)
159.1360  {
159.1361 -   png_debug1(1, "in %s storage function\n", "tRNS");
159.1362 +   png_debug1(1, "in %s storage function", "tRNS");
159.1363 +
159.1364     if (png_ptr == NULL || info_ptr == NULL)
159.1365        return;
159.1366  
159.1367 -   if (trans != NULL)
159.1368 +   if (trans_alpha != NULL)
159.1369     {
159.1370 -       /*
159.1371 -        * It may not actually be necessary to set png_ptr->trans here;
159.1372 +       /* It may not actually be necessary to set png_ptr->trans_alpha here;
159.1373          * we do it for backward compatibility with the way the png_handle_tRNS
159.1374          * function used to do the allocation.
159.1375          */
159.1376 -#ifdef PNG_FREE_ME_SUPPORTED
159.1377 +
159.1378         png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
159.1379 -#endif
159.1380 +
159.1381         /* Changed from num_trans to PNG_MAX_PALETTE_LENGTH in version 1.2.1 */
159.1382 -       png_ptr->trans = info_ptr->trans = (png_bytep)png_malloc(png_ptr,
159.1383 -           (png_uint_32)PNG_MAX_PALETTE_LENGTH);
159.1384 -       if (num_trans <= PNG_MAX_PALETTE_LENGTH)
159.1385 -         png_memcpy(info_ptr->trans, trans, (png_size_t)num_trans);
159.1386 -#ifdef PNG_FREE_ME_SUPPORTED
159.1387 -       info_ptr->free_me |= PNG_FREE_TRNS;
159.1388 -#else
159.1389 -       png_ptr->flags |= PNG_FLAG_FREE_TRNS;
159.1390 -#endif
159.1391 +       png_ptr->trans_alpha = info_ptr->trans_alpha =
159.1392 +           (png_bytep)png_malloc(png_ptr, (png_size_t)PNG_MAX_PALETTE_LENGTH);
159.1393 +
159.1394 +       if (num_trans > 0 && num_trans <= PNG_MAX_PALETTE_LENGTH)
159.1395 +          png_memcpy(info_ptr->trans_alpha, trans_alpha, (png_size_t)num_trans);
159.1396     }
159.1397  
159.1398 -   if (trans_values != NULL)
159.1399 +   if (trans_color != NULL)
159.1400     {
159.1401 -      png_memcpy(&(info_ptr->trans_values), trans_values,
159.1402 +      int sample_max = (1 << info_ptr->bit_depth);
159.1403 +
159.1404 +      if ((info_ptr->color_type == PNG_COLOR_TYPE_GRAY &&
159.1405 +          (int)trans_color->gray > sample_max) ||
159.1406 +          (info_ptr->color_type == PNG_COLOR_TYPE_RGB &&
159.1407 +          ((int)trans_color->red > sample_max ||
159.1408 +          (int)trans_color->green > sample_max ||
159.1409 +          (int)trans_color->blue > sample_max)))
159.1410 +         png_warning(png_ptr,
159.1411 +            "tRNS chunk has out-of-range samples for bit_depth");
159.1412 +
159.1413 +      png_memcpy(&(info_ptr->trans_color), trans_color,
159.1414           png_sizeof(png_color_16));
159.1415 +
159.1416        if (num_trans == 0)
159.1417 -        num_trans = 1;
159.1418 +         num_trans = 1;
159.1419     }
159.1420 +
159.1421     info_ptr->num_trans = (png_uint_16)num_trans;
159.1422 -   info_ptr->valid |= PNG_INFO_tRNS;
159.1423 +
159.1424 +   if (num_trans != 0)
159.1425 +   {
159.1426 +      info_ptr->valid |= PNG_INFO_tRNS;
159.1427 +      info_ptr->free_me |= PNG_FREE_TRNS;
159.1428 +   }
159.1429  }
159.1430  #endif
159.1431  
159.1432 -#if defined(PNG_sPLT_SUPPORTED)
159.1433 +#ifdef PNG_sPLT_SUPPORTED
159.1434  void PNGAPI
159.1435  png_set_sPLT(png_structp png_ptr,
159.1436 -             png_infop info_ptr, png_sPLT_tp entries, int nentries)
159.1437 +    png_infop info_ptr, png_const_sPLT_tp entries, int nentries)
159.1438 +/*
159.1439 + *  entries        - array of png_sPLT_t structures
159.1440 + *                   to be added to the list of palettes
159.1441 + *                   in the info structure.
159.1442 + *
159.1443 + *  nentries       - number of palette structures to be
159.1444 + *                   added.
159.1445 + */
159.1446  {
159.1447 -    png_sPLT_tp np;
159.1448 -    int i;
159.1449 +   png_sPLT_tp np;
159.1450 +   int i;
159.1451  
159.1452 -    if (png_ptr == NULL || info_ptr == NULL)
159.1453 -       return;
159.1454 +   if (png_ptr == NULL || info_ptr == NULL)
159.1455 +      return;
159.1456  
159.1457 -    np = (png_sPLT_tp)png_malloc_warn(png_ptr,
159.1458 -        (info_ptr->splt_palettes_num + nentries) * png_sizeof(png_sPLT_t));
159.1459 -    if (np == NULL)
159.1460 -    {
159.1461 -      png_warning(png_ptr, "No memory for sPLT palettes.");
159.1462 +   np = (png_sPLT_tp)png_malloc_warn(png_ptr,
159.1463 +       (info_ptr->splt_palettes_num + nentries) *
159.1464 +       (png_size_t)png_sizeof(png_sPLT_t));
159.1465 +
159.1466 +   if (np == NULL)
159.1467 +   {
159.1468 +      png_warning(png_ptr, "No memory for sPLT palettes");
159.1469        return;
159.1470 -    }
159.1471 +   }
159.1472  
159.1473 -    png_memcpy(np, info_ptr->splt_palettes,
159.1474 -           info_ptr->splt_palettes_num * png_sizeof(png_sPLT_t));
159.1475 -    png_free(png_ptr, info_ptr->splt_palettes);
159.1476 -    info_ptr->splt_palettes=NULL;
159.1477 +   png_memcpy(np, info_ptr->splt_palettes,
159.1478 +       info_ptr->splt_palettes_num * png_sizeof(png_sPLT_t));
159.1479  
159.1480 -    for (i = 0; i < nentries; i++)
159.1481 -    {
159.1482 -        png_sPLT_tp to = np + info_ptr->splt_palettes_num + i;
159.1483 -        png_sPLT_tp from = entries + i;
159.1484 +   png_free(png_ptr, info_ptr->splt_palettes);
159.1485 +   info_ptr->splt_palettes=NULL;
159.1486  
159.1487 -        to->name = (png_charp)png_malloc(png_ptr,
159.1488 -            png_strlen(from->name) + 1);
159.1489 -        /* TODO: use png_malloc_warn */
159.1490 -        png_strcpy(to->name, from->name);
159.1491 -        to->entries = (png_sPLT_entryp)png_malloc(png_ptr,
159.1492 -            from->nentries * png_sizeof(png_sPLT_entry));
159.1493 -        /* TODO: use png_malloc_warn */
159.1494 -        png_memcpy(to->entries, from->entries,
159.1495 -            from->nentries * png_sizeof(png_sPLT_entry));
159.1496 -        to->nentries = from->nentries;
159.1497 -        to->depth = from->depth;
159.1498 -    }
159.1499 +   for (i = 0; i < nentries; i++)
159.1500 +   {
159.1501 +      png_sPLT_tp to = np + info_ptr->splt_palettes_num + i;
159.1502 +      png_const_sPLT_tp from = entries + i;
159.1503 +      png_uint_32 length;
159.1504  
159.1505 -    info_ptr->splt_palettes = np;
159.1506 -    info_ptr->splt_palettes_num += nentries;
159.1507 -    info_ptr->valid |= PNG_INFO_sPLT;
159.1508 -#ifdef PNG_FREE_ME_SUPPORTED
159.1509 -    info_ptr->free_me |= PNG_FREE_SPLT;
159.1510 -#endif
159.1511 +      length = png_strlen(from->name) + 1;
159.1512 +      to->name = (png_charp)png_malloc_warn(png_ptr, (png_size_t)length);
159.1513 +
159.1514 +      if (to->name == NULL)
159.1515 +      {
159.1516 +         png_warning(png_ptr,
159.1517 +             "Out of memory while processing sPLT chunk");
159.1518 +         continue;
159.1519 +      }
159.1520 +
159.1521 +      png_memcpy(to->name, from->name, length);
159.1522 +      to->entries = (png_sPLT_entryp)png_malloc_warn(png_ptr,
159.1523 +          (png_size_t)(from->nentries * png_sizeof(png_sPLT_entry)));
159.1524 +
159.1525 +      if (to->entries == NULL)
159.1526 +      {
159.1527 +         png_warning(png_ptr,
159.1528 +             "Out of memory while processing sPLT chunk");
159.1529 +         png_free(png_ptr, to->name);
159.1530 +         to->name = NULL;
159.1531 +         continue;
159.1532 +      }
159.1533 +
159.1534 +      png_memcpy(to->entries, from->entries,
159.1535 +          from->nentries * png_sizeof(png_sPLT_entry));
159.1536 +
159.1537 +      to->nentries = from->nentries;
159.1538 +      to->depth = from->depth;
159.1539 +   }
159.1540 +
159.1541 +   info_ptr->splt_palettes = np;
159.1542 +   info_ptr->splt_palettes_num += nentries;
159.1543 +   info_ptr->valid |= PNG_INFO_sPLT;
159.1544 +   info_ptr->free_me |= PNG_FREE_SPLT;
159.1545  }
159.1546  #endif /* PNG_sPLT_SUPPORTED */
159.1547  
159.1548 -#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
159.1549 +#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
159.1550  void PNGAPI
159.1551  png_set_unknown_chunks(png_structp png_ptr,
159.1552 -   png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns)
159.1553 +   png_infop info_ptr, png_const_unknown_chunkp unknowns, int num_unknowns)
159.1554  {
159.1555 -    png_unknown_chunkp np;
159.1556 -    int i;
159.1557 +   png_unknown_chunkp np;
159.1558 +   int i;
159.1559  
159.1560 -    if (png_ptr == NULL || info_ptr == NULL || num_unknowns == 0)
159.1561 -        return;
159.1562 +   if (png_ptr == NULL || info_ptr == NULL || num_unknowns == 0)
159.1563 +      return;
159.1564  
159.1565 -    np = (png_unknown_chunkp)png_malloc_warn(png_ptr,
159.1566 -        (info_ptr->unknown_chunks_num + num_unknowns) *
159.1567 -        png_sizeof(png_unknown_chunk));
159.1568 -    if (np == NULL)
159.1569 -    {
159.1570 -       png_warning(png_ptr, "Out of memory while processing unknown chunk.");
159.1571 -       return;
159.1572 -    }
159.1573 +   np = (png_unknown_chunkp)png_malloc_warn(png_ptr,
159.1574 +       (png_size_t)(info_ptr->unknown_chunks_num + num_unknowns) *
159.1575 +       png_sizeof(png_unknown_chunk));
159.1576  
159.1577 -    png_memcpy(np, info_ptr->unknown_chunks,
159.1578 -           info_ptr->unknown_chunks_num * png_sizeof(png_unknown_chunk));
159.1579 -    png_free(png_ptr, info_ptr->unknown_chunks);
159.1580 -    info_ptr->unknown_chunks=NULL;
159.1581 +   if (np == NULL)
159.1582 +   {
159.1583 +      png_warning(png_ptr,
159.1584 +          "Out of memory while processing unknown chunk");
159.1585 +      return;
159.1586 +   }
159.1587  
159.1588 -    for (i = 0; i < num_unknowns; i++)
159.1589 -    {
159.1590 -        png_unknown_chunkp to = np + info_ptr->unknown_chunks_num + i;
159.1591 -        png_unknown_chunkp from = unknowns + i;
159.1592 +   png_memcpy(np, info_ptr->unknown_chunks,
159.1593 +       (png_size_t)info_ptr->unknown_chunks_num *
159.1594 +       png_sizeof(png_unknown_chunk));
159.1595  
159.1596 -        png_strncpy((png_charp)to->name, (png_charp)from->name, 5);
159.1597 -        to->data = (png_bytep)png_malloc_warn(png_ptr, from->size);
159.1598 -        if (to->data == NULL)
159.1599 -        {
159.1600 -           png_warning(png_ptr, "Out of memory processing unknown chunk.");
159.1601 -        }
159.1602 -        else
159.1603 -        {
159.1604 -           png_memcpy(to->data, from->data, from->size);
159.1605 -           to->size = from->size;
159.1606 +   png_free(png_ptr, info_ptr->unknown_chunks);
159.1607 +   info_ptr->unknown_chunks = NULL;
159.1608  
159.1609 -           /* note our location in the read or write sequence */
159.1610 -           to->location = (png_byte)(png_ptr->mode & 0xff);
159.1611 -        }
159.1612 -    }
159.1613 +   for (i = 0; i < num_unknowns; i++)
159.1614 +   {
159.1615 +      png_unknown_chunkp to = np + info_ptr->unknown_chunks_num + i;
159.1616 +      png_const_unknown_chunkp from = unknowns + i;
159.1617  
159.1618 -    info_ptr->unknown_chunks = np;
159.1619 -    info_ptr->unknown_chunks_num += num_unknowns;
159.1620 -#ifdef PNG_FREE_ME_SUPPORTED
159.1621 -    info_ptr->free_me |= PNG_FREE_UNKN;
159.1622 -#endif
159.1623 +      png_memcpy(to->name, from->name, png_sizeof(from->name));
159.1624 +      to->name[png_sizeof(to->name)-1] = '\0';
159.1625 +      to->size = from->size;
159.1626 +
159.1627 +      /* Note our location in the read or write sequence */
159.1628 +      to->location = (png_byte)(png_ptr->mode & 0xff);
159.1629 +
159.1630 +      if (from->size == 0)
159.1631 +         to->data=NULL;
159.1632 +
159.1633 +      else
159.1634 +      {
159.1635 +         to->data = (png_bytep)png_malloc_warn(png_ptr,
159.1636 +             (png_size_t)from->size);
159.1637 +
159.1638 +         if (to->data == NULL)
159.1639 +         {
159.1640 +            png_warning(png_ptr,
159.1641 +                "Out of memory while processing unknown chunk");
159.1642 +            to->size = 0;
159.1643 +         }
159.1644 +
159.1645 +         else
159.1646 +            png_memcpy(to->data, from->data, from->size);
159.1647 +      }
159.1648 +   }
159.1649 +
159.1650 +   info_ptr->unknown_chunks = np;
159.1651 +   info_ptr->unknown_chunks_num += num_unknowns;
159.1652 +   info_ptr->free_me |= PNG_FREE_UNKN;
159.1653  }
159.1654 +
159.1655  void PNGAPI
159.1656  png_set_unknown_chunk_location(png_structp png_ptr, png_infop info_ptr,
159.1657 -   int chunk, int location)
159.1658 +    int chunk, int location)
159.1659  {
159.1660 -   if(png_ptr != NULL && info_ptr != NULL && chunk >= 0 && chunk <
159.1661 -         (int)info_ptr->unknown_chunks_num)
159.1662 +   if (png_ptr != NULL && info_ptr != NULL && chunk >= 0 && chunk <
159.1663 +       info_ptr->unknown_chunks_num)
159.1664        info_ptr->unknown_chunks[chunk].location = (png_byte)location;
159.1665  }
159.1666  #endif
159.1667  
159.1668 -#if defined(PNG_1_0_X) || defined(PNG_1_2_X)
159.1669 -#if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
159.1670 -    defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
159.1671 -void PNGAPI
159.1672 -png_permit_empty_plte (png_structp png_ptr, int empty_plte_permitted)
159.1673 -{
159.1674 -   /* This function is deprecated in favor of png_permit_mng_features()
159.1675 -      and will be removed from libpng-1.3.0 */
159.1676 -   png_debug(1, "in png_permit_empty_plte, DEPRECATED.\n");
159.1677 -   if (png_ptr == NULL)
159.1678 -      return;
159.1679 -   png_ptr->mng_features_permitted = (png_byte)
159.1680 -     ((png_ptr->mng_features_permitted & (~(PNG_FLAG_MNG_EMPTY_PLTE))) |
159.1681 -     ((empty_plte_permitted & PNG_FLAG_MNG_EMPTY_PLTE)));
159.1682 -}
159.1683 -#endif
159.1684 -#endif
159.1685  
159.1686 -#if defined(PNG_MNG_FEATURES_SUPPORTED)
159.1687 +#ifdef PNG_MNG_FEATURES_SUPPORTED
159.1688  png_uint_32 PNGAPI
159.1689  png_permit_mng_features (png_structp png_ptr, png_uint_32 mng_features)
159.1690  {
159.1691 -   png_debug(1, "in png_permit_mng_features\n");
159.1692 +   png_debug(1, "in png_permit_mng_features");
159.1693 +
159.1694     if (png_ptr == NULL)
159.1695        return (png_uint_32)0;
159.1696 +
159.1697     png_ptr->mng_features_permitted =
159.1698 -     (png_byte)(mng_features & PNG_ALL_MNG_FEATURES);
159.1699 +       (png_byte)(mng_features & PNG_ALL_MNG_FEATURES);
159.1700 +
159.1701     return (png_uint_32)png_ptr->mng_features_permitted;
159.1702  }
159.1703  #endif
159.1704  
159.1705 -#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
159.1706 +#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
159.1707  void PNGAPI
159.1708 -png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep
159.1709 -   chunk_list, int num_chunks)
159.1710 +png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_const_bytep
159.1711 +    chunk_list, int num_chunks)
159.1712  {
159.1713 -    png_bytep new_list, p;
159.1714 -    int i, old_num_chunks;
159.1715 -    if (png_ptr == NULL)
159.1716 -       return;
159.1717 -    if (num_chunks == 0)
159.1718 -    {
159.1719 -      if(keep == PNG_HANDLE_CHUNK_ALWAYS || keep == PNG_HANDLE_CHUNK_IF_SAFE)
159.1720 -        png_ptr->flags |= PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
159.1721 +   png_bytep new_list, p;
159.1722 +   int i, old_num_chunks;
159.1723 +   if (png_ptr == NULL)
159.1724 +      return;
159.1725 +
159.1726 +   if (num_chunks == 0)
159.1727 +   {
159.1728 +      if (keep == PNG_HANDLE_CHUNK_ALWAYS || keep == PNG_HANDLE_CHUNK_IF_SAFE)
159.1729 +         png_ptr->flags |= PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
159.1730 +
159.1731        else
159.1732 -        png_ptr->flags &= ~PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
159.1733 +         png_ptr->flags &= ~PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
159.1734  
159.1735 -      if(keep == PNG_HANDLE_CHUNK_ALWAYS)
159.1736 -        png_ptr->flags |= PNG_FLAG_KEEP_UNSAFE_CHUNKS;
159.1737 +      if (keep == PNG_HANDLE_CHUNK_ALWAYS)
159.1738 +         png_ptr->flags |= PNG_FLAG_KEEP_UNSAFE_CHUNKS;
159.1739 +
159.1740        else
159.1741 -        png_ptr->flags &= ~PNG_FLAG_KEEP_UNSAFE_CHUNKS;
159.1742 +         png_ptr->flags &= ~PNG_FLAG_KEEP_UNSAFE_CHUNKS;
159.1743 +
159.1744        return;
159.1745 -    }
159.1746 -    if (chunk_list == NULL)
159.1747 +   }
159.1748 +
159.1749 +   if (chunk_list == NULL)
159.1750        return;
159.1751 -    old_num_chunks=png_ptr->num_chunk_list;
159.1752 -    new_list=(png_bytep)png_malloc(png_ptr,
159.1753 -       (png_uint_32)(5*(num_chunks+old_num_chunks)));
159.1754 -    if(png_ptr->chunk_list != NULL)
159.1755 -    {
159.1756 -       png_memcpy(new_list, png_ptr->chunk_list,
159.1757 +
159.1758 +   old_num_chunks = png_ptr->num_chunk_list;
159.1759 +   new_list=(png_bytep)png_malloc(png_ptr,
159.1760 +       (png_size_t)(5*(num_chunks + old_num_chunks)));
159.1761 +
159.1762 +   if (png_ptr->chunk_list != NULL)
159.1763 +   {
159.1764 +      png_memcpy(new_list, png_ptr->chunk_list,
159.1765            (png_size_t)(5*old_num_chunks));
159.1766 -       png_free(png_ptr, png_ptr->chunk_list);
159.1767 -       png_ptr->chunk_list=NULL;
159.1768 -    }
159.1769 -    png_memcpy(new_list+5*old_num_chunks, chunk_list,
159.1770 +      png_free(png_ptr, png_ptr->chunk_list);
159.1771 +      png_ptr->chunk_list=NULL;
159.1772 +   }
159.1773 +
159.1774 +   png_memcpy(new_list + 5*old_num_chunks, chunk_list,
159.1775         (png_size_t)(5*num_chunks));
159.1776 -    for (p=new_list+5*old_num_chunks+4, i=0; i<num_chunks; i++, p+=5)
159.1777 -       *p=(png_byte)keep;
159.1778 -    png_ptr->num_chunk_list=old_num_chunks+num_chunks;
159.1779 -    png_ptr->chunk_list=new_list;
159.1780 -#ifdef PNG_FREE_ME_SUPPORTED
159.1781 -    png_ptr->free_me |= PNG_FREE_LIST;
159.1782 -#endif
159.1783 +
159.1784 +   for (p = new_list + 5*old_num_chunks + 4, i = 0; i<num_chunks; i++, p += 5)
159.1785 +      *p=(png_byte)keep;
159.1786 +
159.1787 +   png_ptr->num_chunk_list = old_num_chunks + num_chunks;
159.1788 +   png_ptr->chunk_list = new_list;
159.1789 +   png_ptr->free_me |= PNG_FREE_LIST;
159.1790  }
159.1791  #endif
159.1792  
159.1793 -#if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
159.1794 +#ifdef PNG_READ_USER_CHUNKS_SUPPORTED
159.1795  void PNGAPI
159.1796  png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp user_chunk_ptr,
159.1797 -   png_user_chunk_ptr read_user_chunk_fn)
159.1798 +    png_user_chunk_ptr read_user_chunk_fn)
159.1799  {
159.1800 -   png_debug(1, "in png_set_read_user_chunk_fn\n");
159.1801 +   png_debug(1, "in png_set_read_user_chunk_fn");
159.1802 +
159.1803     if (png_ptr == NULL)
159.1804        return;
159.1805 +
159.1806     png_ptr->read_user_chunk_fn = read_user_chunk_fn;
159.1807     png_ptr->user_chunk_ptr = user_chunk_ptr;
159.1808  }
159.1809  #endif
159.1810  
159.1811 -#if defined(PNG_INFO_IMAGE_SUPPORTED)
159.1812 +#ifdef PNG_INFO_IMAGE_SUPPORTED
159.1813  void PNGAPI
159.1814  png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers)
159.1815  {
159.1816 -   png_debug1(1, "in %s storage function\n", "rows");
159.1817 +   png_debug1(1, "in %s storage function", "rows");
159.1818  
159.1819     if (png_ptr == NULL || info_ptr == NULL)
159.1820        return;
159.1821  
159.1822 -   if(info_ptr->row_pointers && (info_ptr->row_pointers != row_pointers))
159.1823 +   if (info_ptr->row_pointers && (info_ptr->row_pointers != row_pointers))
159.1824        png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
159.1825 +
159.1826     info_ptr->row_pointers = row_pointers;
159.1827 -   if(row_pointers)
159.1828 +
159.1829 +   if (row_pointers)
159.1830        info_ptr->valid |= PNG_INFO_IDAT;
159.1831  }
159.1832  #endif
159.1833  
159.1834 -#ifdef PNG_WRITE_SUPPORTED
159.1835  void PNGAPI
159.1836 -png_set_compression_buffer_size(png_structp png_ptr, png_uint_32 size)
159.1837 +png_set_compression_buffer_size(png_structp png_ptr, png_size_t size)
159.1838  {
159.1839      if (png_ptr == NULL)
159.1840         return;
159.1841 -    if(png_ptr->zbuf)
159.1842 -       png_free(png_ptr, png_ptr->zbuf);
159.1843 -    png_ptr->zbuf_size = (png_size_t)size;
159.1844 +
159.1845 +    png_free(png_ptr, png_ptr->zbuf);
159.1846 +
159.1847 +    if (size > ZLIB_IO_MAX)
159.1848 +    {
159.1849 +       png_warning(png_ptr, "Attempt to set buffer size beyond max ignored");
159.1850 +       png_ptr->zbuf_size = ZLIB_IO_MAX;
159.1851 +       size = ZLIB_IO_MAX; /* must fit */
159.1852 +    }
159.1853 +
159.1854 +    else
159.1855 +       png_ptr->zbuf_size = (uInt)size;
159.1856 +
159.1857      png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, size);
159.1858 +
159.1859 +    /* The following ensures a relatively safe failure if this gets called while
159.1860 +     * the buffer is actually in use.
159.1861 +     */
159.1862      png_ptr->zstream.next_out = png_ptr->zbuf;
159.1863 -    png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
159.1864 +    png_ptr->zstream.avail_out = 0;
159.1865 +    png_ptr->zstream.avail_in = 0;
159.1866  }
159.1867 -#endif
159.1868  
159.1869  void PNGAPI
159.1870  png_set_invalid(png_structp png_ptr, png_infop info_ptr, int mask)
159.1871  {
159.1872     if (png_ptr && info_ptr)
159.1873 -      info_ptr->valid &= ~(mask);
159.1874 +      info_ptr->valid &= ~mask;
159.1875  }
159.1876  
159.1877  
159.1878 -#ifndef PNG_1_0_X
159.1879 -#ifdef PNG_ASSEMBLER_CODE_SUPPORTED
159.1880 -/* this function was added to libpng 1.2.0 and should always exist by default */
159.1881 -void PNGAPI
159.1882 -png_set_asm_flags (png_structp png_ptr, png_uint_32 asm_flags)
159.1883 -{
159.1884 -#ifdef PNG_MMX_CODE_SUPPORTED
159.1885 -    png_uint_32 settable_asm_flags;
159.1886 -    png_uint_32 settable_mmx_flags;
159.1887 -#endif
159.1888 -    if (png_ptr == NULL)
159.1889 -       return;
159.1890 -#ifdef PNG_MMX_CODE_SUPPORTED
159.1891 -
159.1892 -    settable_mmx_flags =
159.1893 -#ifdef PNG_HAVE_MMX_COMBINE_ROW
159.1894 -                         PNG_ASM_FLAG_MMX_READ_COMBINE_ROW  |
159.1895 -#endif
159.1896 -#ifdef PNG_HAVE_MMX_READ_INTERLACE
159.1897 -                         PNG_ASM_FLAG_MMX_READ_INTERLACE    |
159.1898 -#endif
159.1899 -#ifdef PNG_HAVE_MMX_READ_FILTER_ROW
159.1900 -                         PNG_ASM_FLAG_MMX_READ_FILTER_SUB   |
159.1901 -                         PNG_ASM_FLAG_MMX_READ_FILTER_UP    |
159.1902 -                         PNG_ASM_FLAG_MMX_READ_FILTER_AVG   |
159.1903 -                         PNG_ASM_FLAG_MMX_READ_FILTER_PAETH |
159.1904 -#endif
159.1905 -                         0;
159.1906 -
159.1907 -    /* could be some non-MMX ones in the future, but not currently: */
159.1908 -    settable_asm_flags = settable_mmx_flags;
159.1909 -
159.1910 -    if (!(png_ptr->asm_flags & PNG_ASM_FLAG_MMX_SUPPORT_COMPILED) ||
159.1911 -        !(png_ptr->asm_flags & PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU))
159.1912 -    {
159.1913 -        /* clear all MMX flags if MMX isn't supported */
159.1914 -        settable_asm_flags &= ~settable_mmx_flags;
159.1915 -        png_ptr->asm_flags &= ~settable_mmx_flags;
159.1916 -    }
159.1917 -
159.1918 -    /* we're replacing the settable bits with those passed in by the user,
159.1919 -     * so first zero them out of the master copy, then bitwise-OR in the
159.1920 -     * allowed subset that was requested */
159.1921 -
159.1922 -    png_ptr->asm_flags &= ~settable_asm_flags;               /* zero them */
159.1923 -    png_ptr->asm_flags |= (asm_flags & settable_asm_flags);  /* set them */
159.1924 -#endif /* ?PNG_MMX_CODE_SUPPORTED */
159.1925 -}
159.1926 -
159.1927 -/* this function was added to libpng 1.2.0 */
159.1928 -void PNGAPI
159.1929 -png_set_mmx_thresholds (png_structp png_ptr,
159.1930 -                        png_byte mmx_bitdepth_threshold,
159.1931 -                        png_uint_32 mmx_rowbytes_threshold)
159.1932 -{
159.1933 -    if (png_ptr == NULL)
159.1934 -       return;
159.1935 -#ifdef PNG_MMX_CODE_SUPPORTED
159.1936 -    png_ptr->mmx_bitdepth_threshold = mmx_bitdepth_threshold;
159.1937 -    png_ptr->mmx_rowbytes_threshold = mmx_rowbytes_threshold;
159.1938 -#endif /* ?PNG_MMX_CODE_SUPPORTED */
159.1939 -}
159.1940 -#endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
159.1941  
159.1942  #ifdef PNG_SET_USER_LIMITS_SUPPORTED
159.1943 -/* this function was added to libpng 1.2.6 */
159.1944 +/* This function was added to libpng 1.2.6 */
159.1945  void PNGAPI
159.1946  png_set_user_limits (png_structp png_ptr, png_uint_32 user_width_max,
159.1947      png_uint_32 user_height_max)
159.1948  {
159.1949 -    /* Images with dimensions larger than these limits will be
159.1950 -     * rejected by png_set_IHDR().  To accept any PNG datastream
159.1951 -     * regardless of dimensions, set both limits to 0x7ffffffL.
159.1952 -     */
159.1953 -    if(png_ptr == NULL) return;
159.1954 -    png_ptr->user_width_max = user_width_max;
159.1955 -    png_ptr->user_height_max = user_height_max;
159.1956 +   /* Images with dimensions larger than these limits will be
159.1957 +    * rejected by png_set_IHDR().  To accept any PNG datastream
159.1958 +    * regardless of dimensions, set both limits to 0x7ffffffL.
159.1959 +    */
159.1960 +   if (png_ptr == NULL)
159.1961 +      return;
159.1962 +
159.1963 +   png_ptr->user_width_max = user_width_max;
159.1964 +   png_ptr->user_height_max = user_height_max;
159.1965 +}
159.1966 +
159.1967 +/* This function was added to libpng 1.4.0 */
159.1968 +void PNGAPI
159.1969 +png_set_chunk_cache_max (png_structp png_ptr,
159.1970 +   png_uint_32 user_chunk_cache_max)
159.1971 +{
159.1972 +    if (png_ptr)
159.1973 +       png_ptr->user_chunk_cache_max = user_chunk_cache_max;
159.1974 +}
159.1975 +
159.1976 +/* This function was added to libpng 1.4.1 */
159.1977 +void PNGAPI
159.1978 +png_set_chunk_malloc_max (png_structp png_ptr,
159.1979 +    png_alloc_size_t user_chunk_malloc_max)
159.1980 +{
159.1981 +   if (png_ptr)
159.1982 +      png_ptr->user_chunk_malloc_max = user_chunk_malloc_max;
159.1983  }
159.1984  #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
159.1985  
159.1986 -#endif /* ?PNG_1_0_X */
159.1987 +
159.1988 +#ifdef PNG_BENIGN_ERRORS_SUPPORTED
159.1989 +void PNGAPI
159.1990 +png_set_benign_errors(png_structp png_ptr, int allowed)
159.1991 +{
159.1992 +   png_debug(1, "in png_set_benign_errors");
159.1993 +
159.1994 +   if (allowed)
159.1995 +      png_ptr->flags |= PNG_FLAG_BENIGN_ERRORS_WARN;
159.1996 +
159.1997 +   else
159.1998 +      png_ptr->flags &= ~PNG_FLAG_BENIGN_ERRORS_WARN;
159.1999 +}
159.2000 +#endif /* PNG_BENIGN_ERRORS_SUPPORTED */
159.2001  #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
   160.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   160.2 +++ b/src/share/native/sun/awt/libpng/pngstruct.h	Tue Oct 04 12:39:42 2011 -0700
   160.3 @@ -0,0 +1,365 @@
   160.4 +/*
   160.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   160.6 + *
   160.7 + * This code is free software; you can redistribute it and/or modify it
   160.8 + * under the terms of the GNU General Public License version 2 only, as
   160.9 + * published by the Free Software Foundation.  Oracle designates this
  160.10 + * particular file as subject to the "Classpath" exception as provided
  160.11 + * by Oracle in the LICENSE file that accompanied this code.
  160.12 + *
  160.13 + * This code is distributed in the hope that it will be useful, but WITHOUT
  160.14 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  160.15 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  160.16 + * version 2 for more details (a copy is included in the LICENSE file that
  160.17 + * accompanied this code).
  160.18 + *
  160.19 + * You should have received a copy of the GNU General Public License version
  160.20 + * 2 along with this work; if not, write to the Free Software Foundation,
  160.21 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  160.22 + *
  160.23 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  160.24 + * or visit www.oracle.com if you need additional information or have any
  160.25 + * questions.
  160.26 + */
  160.27 +
  160.28 +/* pngstruct.h - header file for PNG reference library
  160.29 + *
  160.30 + * This file is available under and governed by the GNU General Public
  160.31 + * License version 2 only, as published by the Free Software Foundation.
  160.32 + * However, the following notice accompanied the original version of this
  160.33 + * file and, per its terms, should not be removed:
  160.34 + *
  160.35 + * Copyright (c) 1998-2011 Glenn Randers-Pehrson
  160.36 + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
  160.37 + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
  160.38 + *
  160.39 + * Last changed in libpng 1.5.4 [July 7, 2011]
  160.40 + *
  160.41 + * This code is released under the libpng license.
  160.42 + * For conditions of distribution and use, see the disclaimer
  160.43 + * and license in png.h
  160.44 + */
  160.45 +
  160.46 +/* The structure that holds the information to read and write PNG files.
  160.47 + * The only people who need to care about what is inside of this are the
  160.48 + * people who will be modifying the library for their own special needs.
  160.49 + * It should NOT be accessed directly by an application.
  160.50 + */
  160.51 +
  160.52 +#ifndef PNGSTRUCT_H
  160.53 +#define PNGSTRUCT_H
  160.54 +/* zlib.h defines the structure z_stream, an instance of which is included
  160.55 + * in this structure and is required for decompressing the LZ compressed
  160.56 + * data in PNG files.
  160.57 + */
  160.58 +#include "zlib.h"
  160.59 +
  160.60 +struct png_struct_def
  160.61 +{
  160.62 +#ifdef PNG_SETJMP_SUPPORTED
  160.63 +   jmp_buf longjmp_buffer;    /* used in png_error */
  160.64 +   png_longjmp_ptr longjmp_fn;/* setjmp non-local goto function. */
  160.65 +#endif
  160.66 +   png_error_ptr error_fn;    /* function for printing errors and aborting */
  160.67 +#ifdef PNG_WARNINGS_SUPPORTED
  160.68 +   png_error_ptr warning_fn;  /* function for printing warnings */
  160.69 +#endif
  160.70 +   png_voidp error_ptr;       /* user supplied struct for error functions */
  160.71 +   png_rw_ptr write_data_fn;  /* function for writing output data */
  160.72 +   png_rw_ptr read_data_fn;   /* function for reading input data */
  160.73 +   png_voidp io_ptr;          /* ptr to application struct for I/O functions */
  160.74 +
  160.75 +#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
  160.76 +   png_user_transform_ptr read_user_transform_fn; /* user read transform */
  160.77 +#endif
  160.78 +
  160.79 +#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
  160.80 +   png_user_transform_ptr write_user_transform_fn; /* user write transform */
  160.81 +#endif
  160.82 +
  160.83 +/* These were added in libpng-1.0.2 */
  160.84 +#ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED
  160.85 +#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  160.86 +    defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  160.87 +   png_voidp user_transform_ptr; /* user supplied struct for user transform */
  160.88 +   png_byte user_transform_depth;    /* bit depth of user transformed pixels */
  160.89 +   png_byte user_transform_channels; /* channels in user transformed pixels */
  160.90 +#endif
  160.91 +#endif
  160.92 +
  160.93 +   png_uint_32 mode;          /* tells us where we are in the PNG file */
  160.94 +   png_uint_32 flags;         /* flags indicating various things to libpng */
  160.95 +   png_uint_32 transformations; /* which transformations to perform */
  160.96 +
  160.97 +   z_stream zstream;          /* pointer to decompression structure (below) */
  160.98 +   png_bytep zbuf;            /* buffer for zlib */
  160.99 +   uInt zbuf_size;            /* size of zbuf (typically 65536) */
 160.100 +#ifdef PNG_WRITE_SUPPORTED
 160.101 +
 160.102 +/* Added in 1.5.4: state to keep track of whether the zstream has been
 160.103 + * initialized and if so whether it is for IDAT or some other chunk.
 160.104 + */
 160.105 +#define PNG_ZLIB_UNINITIALIZED 0
 160.106 +#define PNG_ZLIB_FOR_IDAT      1
 160.107 +#define PNG_ZLIB_FOR_TEXT      2 /* anything other than IDAT */
 160.108 +#define PNG_ZLIB_USE_MASK      3 /* bottom two bits */
 160.109 +#define PNG_ZLIB_IN_USE        4 /* a flag value */
 160.110 +
 160.111 +   png_uint_32 zlib_state;       /* State of zlib initialization */
 160.112 +/* End of material added at libpng 1.5.4 */
 160.113 +
 160.114 +   int zlib_level;            /* holds zlib compression level */
 160.115 +   int zlib_method;           /* holds zlib compression method */
 160.116 +   int zlib_window_bits;      /* holds zlib compression window bits */
 160.117 +   int zlib_mem_level;        /* holds zlib compression memory level */
 160.118 +   int zlib_strategy;         /* holds zlib compression strategy */
 160.119 +#endif
 160.120 +/* Added at libpng 1.5.4 */
 160.121 +#if defined(PNG_WRITE_COMPRESSED_TEXT_SUPPORTED) || \
 160.122 +    defined(PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED)
 160.123 +   int zlib_text_level;            /* holds zlib compression level */
 160.124 +   int zlib_text_method;           /* holds zlib compression method */
 160.125 +   int zlib_text_window_bits;      /* holds zlib compression window bits */
 160.126 +   int zlib_text_mem_level;        /* holds zlib compression memory level */
 160.127 +   int zlib_text_strategy;         /* holds zlib compression strategy */
 160.128 +#endif
 160.129 +/* End of material added at libpng 1.5.4 */
 160.130 +
 160.131 +   png_uint_32 width;         /* width of image in pixels */
 160.132 +   png_uint_32 height;        /* height of image in pixels */
 160.133 +   png_uint_32 num_rows;      /* number of rows in current pass */
 160.134 +   png_uint_32 usr_width;     /* width of row at start of write */
 160.135 +   png_size_t rowbytes;       /* size of row in bytes */
 160.136 +   png_uint_32 iwidth;        /* width of current interlaced row in pixels */
 160.137 +   png_uint_32 row_number;    /* current row in interlace pass */
 160.138 +   png_bytep prev_row;        /* buffer to save previous (unfiltered) row */
 160.139 +   png_bytep row_buf;         /* buffer to save current (unfiltered) row */
 160.140 +   png_bytep sub_row;         /* buffer to save "sub" row when filtering */
 160.141 +   png_bytep up_row;          /* buffer to save "up" row when filtering */
 160.142 +   png_bytep avg_row;         /* buffer to save "avg" row when filtering */
 160.143 +   png_bytep paeth_row;       /* buffer to save "Paeth" row when filtering */
 160.144 +   png_row_info row_info;     /* used for transformation routines */
 160.145 +   png_size_t info_rowbytes;  /* Added in 1.5.4: cache of updated row bytes */
 160.146 +
 160.147 +   png_uint_32 idat_size;     /* current IDAT size for read */
 160.148 +   png_uint_32 crc;           /* current chunk CRC value */
 160.149 +   png_colorp palette;        /* palette from the input file */
 160.150 +   png_uint_16 num_palette;   /* number of color entries in palette */
 160.151 +   png_uint_16 num_trans;     /* number of transparency values */
 160.152 +   png_byte chunk_name[5];    /* null-terminated name of current chunk */
 160.153 +   png_byte compression;      /* file compression type (always 0) */
 160.154 +   png_byte filter;           /* file filter type (always 0) */
 160.155 +   png_byte interlaced;       /* PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
 160.156 +   png_byte pass;             /* current interlace pass (0 - 6) */
 160.157 +   png_byte do_filter;        /* row filter flags (see PNG_FILTER_ below ) */
 160.158 +   png_byte color_type;       /* color type of file */
 160.159 +   png_byte bit_depth;        /* bit depth of file */
 160.160 +   png_byte usr_bit_depth;    /* bit depth of users row */
 160.161 +   png_byte pixel_depth;      /* number of bits per pixel */
 160.162 +   png_byte channels;         /* number of channels in file */
 160.163 +   png_byte usr_channels;     /* channels at start of write */
 160.164 +   png_byte sig_bytes;        /* magic bytes read/written from start of file */
 160.165 +
 160.166 +#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
 160.167 +   png_uint_16 filler;           /* filler bytes for pixel expansion */
 160.168 +#endif
 160.169 +
 160.170 +#if defined(PNG_bKGD_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) ||\
 160.171 +   defined(PNG_READ_ALPHA_MODE_SUPPORTED)
 160.172 +   png_byte background_gamma_type;
 160.173 +   png_fixed_point background_gamma;
 160.174 +   png_color_16 background;   /* background color in screen gamma space */
 160.175 +#ifdef PNG_READ_GAMMA_SUPPORTED
 160.176 +   png_color_16 background_1; /* background normalized to gamma 1.0 */
 160.177 +#endif
 160.178 +#endif /* PNG_bKGD_SUPPORTED */
 160.179 +
 160.180 +#ifdef PNG_WRITE_FLUSH_SUPPORTED
 160.181 +   png_flush_ptr output_flush_fn; /* Function for flushing output */
 160.182 +   png_uint_32 flush_dist;    /* how many rows apart to flush, 0 - no flush */
 160.183 +   png_uint_32 flush_rows;    /* number of rows written since last flush */
 160.184 +#endif
 160.185 +
 160.186 +#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
 160.187 +   int gamma_shift;      /* number of "insignificant" bits in 16-bit gamma */
 160.188 +   png_fixed_point gamma;        /* file gamma value */
 160.189 +   png_fixed_point screen_gamma; /* screen gamma value (display_exponent) */
 160.190 +#endif
 160.191 +
 160.192 +#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
 160.193 +   png_bytep gamma_table;     /* gamma table for 8-bit depth files */
 160.194 +   png_bytep gamma_from_1;    /* converts from 1.0 to screen */
 160.195 +   png_bytep gamma_to_1;      /* converts from file to 1.0 */
 160.196 +   png_uint_16pp gamma_16_table; /* gamma table for 16-bit depth files */
 160.197 +   png_uint_16pp gamma_16_from_1; /* converts from 1.0 to screen */
 160.198 +   png_uint_16pp gamma_16_to_1; /* converts from file to 1.0 */
 160.199 +#endif
 160.200 +
 160.201 +#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_sBIT_SUPPORTED)
 160.202 +   png_color_8 sig_bit;       /* significant bits in each available channel */
 160.203 +#endif
 160.204 +
 160.205 +#if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
 160.206 +   png_color_8 shift;         /* shift for significant bit tranformation */
 160.207 +#endif
 160.208 +
 160.209 +#if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) \
 160.210 + || defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
 160.211 +   png_bytep trans_alpha;           /* alpha values for paletted files */
 160.212 +   png_color_16 trans_color;  /* transparent color for non-paletted files */
 160.213 +#endif
 160.214 +
 160.215 +   png_read_status_ptr read_row_fn;   /* called after each row is decoded */
 160.216 +   png_write_status_ptr write_row_fn; /* called after each row is encoded */
 160.217 +#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
 160.218 +   png_progressive_info_ptr info_fn; /* called after header data fully read */
 160.219 +   png_progressive_row_ptr row_fn;   /* called after a prog. row is decoded */
 160.220 +   png_progressive_end_ptr end_fn;   /* called after image is complete */
 160.221 +   png_bytep save_buffer_ptr;        /* current location in save_buffer */
 160.222 +   png_bytep save_buffer;            /* buffer for previously read data */
 160.223 +   png_bytep current_buffer_ptr;     /* current location in current_buffer */
 160.224 +   png_bytep current_buffer;         /* buffer for recently used data */
 160.225 +   png_uint_32 push_length;          /* size of current input chunk */
 160.226 +   png_uint_32 skip_length;          /* bytes to skip in input data */
 160.227 +   png_size_t save_buffer_size;      /* amount of data now in save_buffer */
 160.228 +   png_size_t save_buffer_max;       /* total size of save_buffer */
 160.229 +   png_size_t buffer_size;           /* total amount of available input data */
 160.230 +   png_size_t current_buffer_size;   /* amount of data now in current_buffer */
 160.231 +   int process_mode;                 /* what push library is currently doing */
 160.232 +   int cur_palette;                  /* current push library palette index */
 160.233 +
 160.234 +#  ifdef PNG_TEXT_SUPPORTED
 160.235 +     png_size_t current_text_size;   /* current size of text input data */
 160.236 +     png_size_t current_text_left;   /* how much text left to read in input */
 160.237 +     png_charp current_text;         /* current text chunk buffer */
 160.238 +     png_charp current_text_ptr;     /* current location in current_text */
 160.239 +#  endif /* PNG_PROGRESSIVE_READ_SUPPORTED && PNG_TEXT_SUPPORTED */
 160.240 +
 160.241 +#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
 160.242 +
 160.243 +#if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
 160.244 +/* For the Borland special 64K segment handler */
 160.245 +   png_bytepp offset_table_ptr;
 160.246 +   png_bytep offset_table;
 160.247 +   png_uint_16 offset_table_number;
 160.248 +   png_uint_16 offset_table_count;
 160.249 +   png_uint_16 offset_table_count_free;
 160.250 +#endif
 160.251 +
 160.252 +#ifdef PNG_READ_QUANTIZE_SUPPORTED
 160.253 +   png_bytep palette_lookup; /* lookup table for quantizing */
 160.254 +   png_bytep quantize_index; /* index translation for palette files */
 160.255 +#endif
 160.256 +
 160.257 +#if defined(PNG_READ_QUANTIZE_SUPPORTED) || defined(PNG_hIST_SUPPORTED)
 160.258 +   png_uint_16p hist;                /* histogram */
 160.259 +#endif
 160.260 +
 160.261 +#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
 160.262 +   png_byte heuristic_method;        /* heuristic for row filter selection */
 160.263 +   png_byte num_prev_filters;        /* number of weights for previous rows */
 160.264 +   png_bytep prev_filters;           /* filter type(s) of previous row(s) */
 160.265 +   png_uint_16p filter_weights;      /* weight(s) for previous line(s) */
 160.266 +   png_uint_16p inv_filter_weights;  /* 1/weight(s) for previous line(s) */
 160.267 +   png_uint_16p filter_costs;        /* relative filter calculation cost */
 160.268 +   png_uint_16p inv_filter_costs;    /* 1/relative filter calculation cost */
 160.269 +#endif
 160.270 +
 160.271 +#ifdef PNG_TIME_RFC1123_SUPPORTED
 160.272 +   char time_buffer[29]; /* String to hold RFC 1123 time text */
 160.273 +#endif
 160.274 +
 160.275 +/* New members added in libpng-1.0.6 */
 160.276 +
 160.277 +   png_uint_32 free_me;    /* flags items libpng is responsible for freeing */
 160.278 +
 160.279 +#ifdef PNG_USER_CHUNKS_SUPPORTED
 160.280 +   png_voidp user_chunk_ptr;
 160.281 +   png_user_chunk_ptr read_user_chunk_fn; /* user read chunk handler */
 160.282 +#endif
 160.283 +
 160.284 +#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
 160.285 +   int num_chunk_list;
 160.286 +   png_bytep chunk_list;
 160.287 +#endif
 160.288 +
 160.289 +/* New members added in libpng-1.0.3 */
 160.290 +#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
 160.291 +   png_byte rgb_to_gray_status;
 160.292 +   /* These were changed from png_byte in libpng-1.0.6 */
 160.293 +   png_uint_16 rgb_to_gray_red_coeff;
 160.294 +   png_uint_16 rgb_to_gray_green_coeff;
 160.295 +   png_uint_16 rgb_to_gray_blue_coeff;
 160.296 +#endif
 160.297 +
 160.298 +/* New member added in libpng-1.0.4 (renamed in 1.0.9) */
 160.299 +#if defined(PNG_MNG_FEATURES_SUPPORTED) || \
 160.300 +    defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
 160.301 +    defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
 160.302 +/* Changed from png_byte to png_uint_32 at version 1.2.0 */
 160.303 +   png_uint_32 mng_features_permitted;
 160.304 +#endif
 160.305 +
 160.306 +/* New member added in libpng-1.0.9, ifdef'ed out in 1.0.12, enabled in 1.2.0 */
 160.307 +#ifdef PNG_MNG_FEATURES_SUPPORTED
 160.308 +   png_byte filter_type;
 160.309 +#endif
 160.310 +
 160.311 +/* New members added in libpng-1.2.0 */
 160.312 +
 160.313 +/* New members added in libpng-1.0.2 but first enabled by default in 1.2.0 */
 160.314 +#ifdef PNG_USER_MEM_SUPPORTED
 160.315 +   png_voidp mem_ptr;             /* user supplied struct for mem functions */
 160.316 +   png_malloc_ptr malloc_fn;      /* function for allocating memory */
 160.317 +   png_free_ptr free_fn;          /* function for freeing memory */
 160.318 +#endif
 160.319 +
 160.320 +/* New member added in libpng-1.0.13 and 1.2.0 */
 160.321 +   png_bytep big_row_buf;         /* buffer to save current (unfiltered) row */
 160.322 +
 160.323 +#ifdef PNG_READ_QUANTIZE_SUPPORTED
 160.324 +/* The following three members were added at version 1.0.14 and 1.2.4 */
 160.325 +   png_bytep quantize_sort;          /* working sort array */
 160.326 +   png_bytep index_to_palette;       /* where the original index currently is
 160.327 +                                        in the palette */
 160.328 +   png_bytep palette_to_index;       /* which original index points to this
 160.329 +                                         palette color */
 160.330 +#endif
 160.331 +
 160.332 +/* New members added in libpng-1.0.16 and 1.2.6 */
 160.333 +   png_byte compression_type;
 160.334 +
 160.335 +#ifdef PNG_USER_LIMITS_SUPPORTED
 160.336 +   png_uint_32 user_width_max;
 160.337 +   png_uint_32 user_height_max;
 160.338 +
 160.339 +   /* Added in libpng-1.4.0: Total number of sPLT, text, and unknown
 160.340 +    * chunks that can be stored (0 means unlimited).
 160.341 +    */
 160.342 +   png_uint_32 user_chunk_cache_max;
 160.343 +
 160.344 +   /* Total memory that a zTXt, sPLT, iTXt, iCCP, or unknown chunk
 160.345 +    * can occupy when decompressed.  0 means unlimited.
 160.346 +    */
 160.347 +   png_alloc_size_t user_chunk_malloc_max;
 160.348 +#endif
 160.349 +
 160.350 +/* New member added in libpng-1.0.25 and 1.2.17 */
 160.351 +#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
 160.352 +   /* Storage for unknown chunk that the library doesn't recognize. */
 160.353 +   png_unknown_chunk unknown_chunk;
 160.354 +#endif
 160.355 +
 160.356 +/* New members added in libpng-1.2.26 */
 160.357 +  png_size_t old_big_row_buf_size;
 160.358 +  png_size_t old_prev_row_size;
 160.359 +
 160.360 +/* New member added in libpng-1.2.30 */
 160.361 +  png_charp chunkdata;  /* buffer for reading chunk data */
 160.362 +
 160.363 +#ifdef PNG_IO_STATE_SUPPORTED
 160.364 +/* New member added in libpng-1.4.0 */
 160.365 +   png_uint_32 io_state;
 160.366 +#endif
 160.367 +};
 160.368 +#endif /* PNGSTRUCT_H */
   161.1 --- a/src/share/native/sun/awt/libpng/pngtest.c	Fri Sep 30 17:20:56 2011 -0700
   161.2 +++ b/src/share/native/sun/awt/libpng/pngtest.c	Tue Oct 04 12:39:42 2011 -0700
   161.3 @@ -29,12 +29,15 @@
   161.4   * However, the following notice accompanied the original version of this
   161.5   * file and, per its terms, should not be removed:
   161.6   *
   161.7 - * Last changed in libpng 1.2.6 - August 15, 2004
   161.8 - * For conditions of distribution and use, see copyright notice in png.h
   161.9 - * Copyright (c) 1998-2004 Glenn Randers-Pehrson
  161.10 + * Last changed in libpng 1.5.4 [July 7, 2011]
  161.11 + * Copyright (c) 1998-2011 Glenn Randers-Pehrson
  161.12   * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
  161.13   * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
  161.14   *
  161.15 + * This code is released under the libpng license.
  161.16 + * For conditions of distribution and use, see the disclaimer
  161.17 + * and license in png.h
  161.18 + *
  161.19   * This program reads in a PNG image, writes it out again, and then
  161.20   * compares the two files.  If the files are identical, this shows that
  161.21   * the basic chunk handling, filtering, and (de)compression code is working
  161.22 @@ -56,51 +59,58 @@
  161.23   * of files at once by typing "pngtest -m file1.png file2.png ..."
  161.24   */
  161.25  
  161.26 +#define _POSIX_SOURCE 1
  161.27 +
  161.28 +#include "zlib.h"
  161.29  #include "png.h"
  161.30 -
  161.31 -#if defined(_WIN32_WCE)
  161.32 -#  if _WIN32_WCE < 211
  161.33 -     __error__ (f|w)printf functions are not supported on old WindowsCE.;
  161.34 -#  endif
  161.35 -#  include <windows.h>
  161.36 -#  include <stdlib.h>
  161.37 -#  define READFILE(file, data, length, check) \
  161.38 -     if (ReadFile(file, data, length, &check,NULL)) check = 0
  161.39 -#  define WRITEFILE(file, data, length, check)) \
  161.40 -     if (WriteFile(file, data, length, &check, NULL)) check = 0
  161.41 -#  define FCLOSE(file) CloseHandle(file)
  161.42 -#else
  161.43 +/* Copied from pngpriv.h but only used in error messages below. */
  161.44 +#ifndef PNG_ZBUF_SIZE
  161.45 +#  define PNG_ZBUF_SIZE 8192
  161.46 +#endif
  161.47  #  include <stdio.h>
  161.48  #  include <stdlib.h>
  161.49 -#  define READFILE(file, data, length, check) \
  161.50 -     check=(png_size_t)fread(data,(png_size_t)1,length,file)
  161.51 -#  define WRITEFILE(file, data, length, check) \
  161.52 -     check=(png_size_t)fwrite(data,(png_size_t)1, length, file)
  161.53 +#  include <string.h>
  161.54  #  define FCLOSE(file) fclose(file)
  161.55 +
  161.56 +#ifndef PNG_STDIO_SUPPORTED
  161.57 +typedef FILE                * png_FILE_p;
  161.58  #endif
  161.59  
  161.60 -#if defined(PNG_NO_STDIO)
  161.61 -#  if defined(_WIN32_WCE)
  161.62 -     typedef HANDLE                png_FILE_p;
  161.63 -#  else
  161.64 -     typedef FILE                * png_FILE_p;
  161.65 -#  endif
  161.66 -#endif
  161.67 -
  161.68 -/* Makes pngtest verbose so we can find problems (needs to be before png.h) */
  161.69 +/* Makes pngtest verbose so we can find problems. */
  161.70  #ifndef PNG_DEBUG
  161.71  #  define PNG_DEBUG 0
  161.72  #endif
  161.73  
  161.74 +#if PNG_DEBUG > 1
  161.75 +#  define pngtest_debug(m)        ((void)fprintf(stderr, m "\n"))
  161.76 +#  define pngtest_debug1(m,p1)    ((void)fprintf(stderr, m "\n", p1))
  161.77 +#  define pngtest_debug2(m,p1,p2) ((void)fprintf(stderr, m "\n", p1, p2))
  161.78 +#else
  161.79 +#  define pngtest_debug(m)        ((void)0)
  161.80 +#  define pngtest_debug1(m,p1)    ((void)0)
  161.81 +#  define pngtest_debug2(m,p1,p2) ((void)0)
  161.82 +#endif
  161.83 +
  161.84  #if !PNG_DEBUG
  161.85 -#  define SINGLE_ROWBUF_ALLOC  /* makes buffer overruns easier to nail */
  161.86 +#  define SINGLE_ROWBUF_ALLOC  /* Makes buffer overruns easier to nail */
  161.87  #endif
  161.88  
  161.89 +/* The code uses memcmp and memcpy on large objects (typically row pointers) so
  161.90 + * it is necessary to do soemthing special on certain architectures, note that
  161.91 + * the actual support for this was effectively removed in 1.4, so only the
  161.92 + * memory remains in this program:
  161.93 + */
  161.94 +#define CVT_PTR(ptr)         (ptr)
  161.95 +#define CVT_PTR_NOCHECK(ptr) (ptr)
  161.96 +#define png_memcmp  memcmp
  161.97 +#define png_memcpy  memcpy
  161.98 +#define png_memset  memset
  161.99 +
 161.100  /* Turn on CPU timing
 161.101  #define PNGTEST_TIMING
 161.102  */
 161.103  
 161.104 -#ifdef PNG_NO_FLOATING_POINT_SUPPORTED
 161.105 +#ifndef PNG_FLOATING_POINT_SUPPORTED
 161.106  #undef PNGTEST_TIMING
 161.107  #endif
 161.108  
 161.109 @@ -109,9 +119,10 @@
 161.110  #include <time.h>
 161.111  #endif
 161.112  
 161.113 -#if defined(PNG_TIME_RFC1123_SUPPORTED)
 161.114 -static int tIME_chunk_present=0;
 161.115 -static char tIME_string[30] = "no tIME chunk present in file";
 161.116 +#ifdef PNG_TIME_RFC1123_SUPPORTED
 161.117 +#define PNG_tIME_STRING_LENGTH 29
 161.118 +static int tIME_chunk_present = 0;
 161.119 +static char tIME_string[PNG_tIME_STRING_LENGTH] = "tIME chunk is not present";
 161.120  #endif
 161.121  
 161.122  static int verbose = 0;
 161.123 @@ -122,110 +133,91 @@
 161.124  #include <mem.h>
 161.125  #endif
 161.126  
 161.127 -/* defined so I can write to a file on gui/windowing platforms */
 161.128 +/* Defined so I can write to a file on gui/windowing platforms */
 161.129  /*  #define STDERR stderr  */
 161.130 -#define STDERR stdout   /* for DOS */
 161.131 -
 161.132 -/* example of using row callbacks to make a simple progress meter */
 161.133 -static int status_pass=1;
 161.134 -static int status_dots_requested=0;
 161.135 -static int status_dots=1;
 161.136 -
 161.137 -/* In case a system header (e.g., on AIX) defined jmpbuf */
 161.138 -#ifdef jmpbuf
 161.139 -#  undef jmpbuf
 161.140 -#endif
 161.141 +#define STDERR stdout   /* For DOS */
 161.142  
 161.143  /* Define png_jmpbuf() in case we are using a pre-1.0.6 version of libpng */
 161.144  #ifndef png_jmpbuf
 161.145  #  define png_jmpbuf(png_ptr) png_ptr->jmpbuf
 161.146  #endif
 161.147  
 161.148 -void
 161.149 -#ifdef PNG_1_0_X
 161.150 -PNGAPI
 161.151 -#endif
 161.152 +/* Example of using row callbacks to make a simple progress meter */
 161.153 +static int status_pass = 1;
 161.154 +static int status_dots_requested = 0;
 161.155 +static int status_dots = 1;
 161.156 +
 161.157 +void PNGCBAPI
 161.158  read_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass);
 161.159 -void
 161.160 -#ifdef PNG_1_0_X
 161.161 -PNGAPI
 161.162 -#endif
 161.163 +void PNGCBAPI
 161.164  read_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass)
 161.165  {
 161.166 -    if(png_ptr == NULL || row_number > PNG_UINT_31_MAX) return;
 161.167 -    if(status_pass != pass)
 161.168 -    {
 161.169 -       fprintf(stdout,"\n Pass %d: ",pass);
 161.170 -       status_pass = pass;
 161.171 -       status_dots = 31;
 161.172 -    }
 161.173 -    status_dots--;
 161.174 -    if(status_dots == 0)
 161.175 -    {
 161.176 -       fprintf(stdout, "\n         ");
 161.177 -       status_dots=30;
 161.178 -    }
 161.179 -    fprintf(stdout, "r");
 161.180 +   if (png_ptr == NULL || row_number > PNG_UINT_31_MAX)
 161.181 +      return;
 161.182 +
 161.183 +   if (status_pass != pass)
 161.184 +   {
 161.185 +      fprintf(stdout, "\n Pass %d: ", pass);
 161.186 +      status_pass = pass;
 161.187 +      status_dots = 31;
 161.188 +   }
 161.189 +
 161.190 +   status_dots--;
 161.191 +
 161.192 +   if (status_dots == 0)
 161.193 +   {
 161.194 +      fprintf(stdout, "\n         ");
 161.195 +      status_dots=30;
 161.196 +   }
 161.197 +
 161.198 +   fprintf(stdout, "r");
 161.199  }
 161.200  
 161.201 -void
 161.202 -#ifdef PNG_1_0_X
 161.203 -PNGAPI
 161.204 -#endif
 161.205 +void PNGCBAPI
 161.206  write_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass);
 161.207 -void
 161.208 -#ifdef PNG_1_0_X
 161.209 -PNGAPI
 161.210 -#endif
 161.211 +void PNGCBAPI
 161.212  write_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass)
 161.213  {
 161.214 -    if(png_ptr == NULL || row_number > PNG_UINT_31_MAX || pass > 7) return;
 161.215 -    fprintf(stdout, "w");
 161.216 +   if (png_ptr == NULL || row_number > PNG_UINT_31_MAX || pass > 7)
 161.217 +      return;
 161.218 +
 161.219 +   fprintf(stdout, "w");
 161.220  }
 161.221  
 161.222  
 161.223 -#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
 161.224 +#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
 161.225  /* Example of using user transform callback (we don't transform anything,
 161.226 -   but merely examine the row filters.  We set this to 256 rather than
 161.227 -   5 in case illegal filter values are present.) */
 161.228 + * but merely examine the row filters.  We set this to 256 rather than
 161.229 + * 5 in case illegal filter values are present.)
 161.230 + */
 161.231  static png_uint_32 filters_used[256];
 161.232 -void
 161.233 -#ifdef PNG_1_0_X
 161.234 -PNGAPI
 161.235 -#endif
 161.236 +void PNGCBAPI
 161.237  count_filters(png_structp png_ptr, png_row_infop row_info, png_bytep data);
 161.238 -void
 161.239 -#ifdef PNG_1_0_X
 161.240 -PNGAPI
 161.241 -#endif
 161.242 +void PNGCBAPI
 161.243  count_filters(png_structp png_ptr, png_row_infop row_info, png_bytep data)
 161.244  {
 161.245 -    if(png_ptr != NULL && row_info != NULL)
 161.246 -      ++filters_used[*(data-1)];
 161.247 +   if (png_ptr != NULL && row_info != NULL)
 161.248 +      ++filters_used[*(data - 1)];
 161.249  }
 161.250  #endif
 161.251  
 161.252 -#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
 161.253 -/* example of using user transform callback (we don't transform anything,
 161.254 -   but merely count the zero samples) */
 161.255 +#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
 161.256 +/* Example of using user transform callback (we don't transform anything,
 161.257 + * but merely count the zero samples)
 161.258 + */
 161.259  
 161.260  static png_uint_32 zero_samples;
 161.261  
 161.262 -void
 161.263 -#ifdef PNG_1_0_X
 161.264 -PNGAPI
 161.265 -#endif
 161.266 +void PNGCBAPI
 161.267  count_zero_samples(png_structp png_ptr, png_row_infop row_info, png_bytep data);
 161.268 -void
 161.269 -#ifdef PNG_1_0_X
 161.270 -PNGAPI
 161.271 -#endif
 161.272 +void PNGCBAPI
 161.273  count_zero_samples(png_structp png_ptr, png_row_infop row_info, png_bytep data)
 161.274  {
 161.275     png_bytep dp = data;
 161.276 -   if(png_ptr == NULL)return;
 161.277 +   if (png_ptr == NULL)
 161.278 +      return;
 161.279  
 161.280 -   /* contents of row_info:
 161.281 +   /* Contents of row_info:
 161.282      *  png_uint_32 width      width of row
 161.283      *  png_uint_32 rowbytes   number of bytes in row
 161.284      *  png_byte color_type    color type of pixels
 161.285 @@ -234,74 +226,91 @@
 161.286      *  png_byte pixel_depth   bits per pixel (depth*channels)
 161.287      */
 161.288  
 161.289 +    /* Counts the number of zero samples (or zero pixels if color_type is 3 */
 161.290  
 161.291 -    /* counts the number of zero samples (or zero pixels if color_type is 3 */
 161.292 +    if (row_info->color_type == 0 || row_info->color_type == 3)
 161.293 +    {
 161.294 +       int pos = 0;
 161.295 +       png_uint_32 n, nstop;
 161.296  
 161.297 -    if(row_info->color_type == 0 || row_info->color_type == 3)
 161.298 -    {
 161.299 -       int pos=0;
 161.300 -       png_uint_32 n, nstop;
 161.301 -       for (n=0, nstop=row_info->width; n<nstop; n++)
 161.302 +       for (n = 0, nstop=row_info->width; n<nstop; n++)
 161.303         {
 161.304 -          if(row_info->bit_depth == 1)
 161.305 +          if (row_info->bit_depth == 1)
 161.306            {
 161.307 -             if(((*dp << pos++ ) & 0x80) == 0) zero_samples++;
 161.308 -             if(pos == 8)
 161.309 +             if (((*dp << pos++ ) & 0x80) == 0)
 161.310 +                zero_samples++;
 161.311 +
 161.312 +             if (pos == 8)
 161.313               {
 161.314                  pos = 0;
 161.315                  dp++;
 161.316               }
 161.317            }
 161.318 -          if(row_info->bit_depth == 2)
 161.319 +
 161.320 +          if (row_info->bit_depth == 2)
 161.321            {
 161.322 -             if(((*dp << (pos+=2)) & 0xc0) == 0) zero_samples++;
 161.323 -             if(pos == 8)
 161.324 +             if (((*dp << (pos+=2)) & 0xc0) == 0)
 161.325 +                zero_samples++;
 161.326 +
 161.327 +             if (pos == 8)
 161.328               {
 161.329                  pos = 0;
 161.330                  dp++;
 161.331               }
 161.332            }
 161.333 -          if(row_info->bit_depth == 4)
 161.334 +
 161.335 +          if (row_info->bit_depth == 4)
 161.336            {
 161.337 -             if(((*dp << (pos+=4)) & 0xf0) == 0) zero_samples++;
 161.338 -             if(pos == 8)
 161.339 +             if (((*dp << (pos+=4)) & 0xf0) == 0)
 161.340 +                zero_samples++;
 161.341 +
 161.342 +             if (pos == 8)
 161.343               {
 161.344                  pos = 0;
 161.345                  dp++;
 161.346               }
 161.347            }
 161.348 -          if(row_info->bit_depth == 8)
 161.349 -             if(*dp++ == 0) zero_samples++;
 161.350 -          if(row_info->bit_depth == 16)
 161.351 +
 161.352 +          if (row_info->bit_depth == 8)
 161.353 +             if (*dp++ == 0)
 161.354 +                zero_samples++;
 161.355 +
 161.356 +          if (row_info->bit_depth == 16)
 161.357            {
 161.358 -             if((*dp | *(dp+1)) == 0) zero_samples++;
 161.359 +             if ((*dp | *(dp+1)) == 0)
 161.360 +                zero_samples++;
 161.361               dp+=2;
 161.362            }
 161.363         }
 161.364      }
 161.365 -    else /* other color types */
 161.366 +    else /* Other color types */
 161.367      {
 161.368         png_uint_32 n, nstop;
 161.369         int channel;
 161.370         int color_channels = row_info->channels;
 161.371 -       if(row_info->color_type > 3)color_channels--;
 161.372 +       if (row_info->color_type > 3)color_channels--;
 161.373  
 161.374 -       for (n=0, nstop=row_info->width; n<nstop; n++)
 161.375 +       for (n = 0, nstop=row_info->width; n<nstop; n++)
 161.376         {
 161.377            for (channel = 0; channel < color_channels; channel++)
 161.378            {
 161.379 -             if(row_info->bit_depth == 8)
 161.380 -                if(*dp++ == 0) zero_samples++;
 161.381 -             if(row_info->bit_depth == 16)
 161.382 +             if (row_info->bit_depth == 8)
 161.383 +                if (*dp++ == 0)
 161.384 +                   zero_samples++;
 161.385 +
 161.386 +             if (row_info->bit_depth == 16)
 161.387               {
 161.388 -                if((*dp | *(dp+1)) == 0) zero_samples++;
 161.389 +                if ((*dp | *(dp+1)) == 0)
 161.390 +                   zero_samples++;
 161.391 +
 161.392                  dp+=2;
 161.393               }
 161.394            }
 161.395 -          if(row_info->color_type > 3)
 161.396 +          if (row_info->color_type > 3)
 161.397            {
 161.398               dp++;
 161.399 -             if(row_info->bit_depth == 16)dp++;
 161.400 +             if (row_info->bit_depth == 16)
 161.401 +                dp++;
 161.402            }
 161.403         }
 161.404      }
 161.405 @@ -310,33 +319,85 @@
 161.406  
 161.407  static int wrote_question = 0;
 161.408  
 161.409 -#if defined(PNG_NO_STDIO)
 161.410 +#ifndef PNG_STDIO_SUPPORTED
 161.411  /* START of code to validate stdio-free compilation */
 161.412 -/* These copies of the default read/write functions come from pngrio.c and */
 161.413 -/* pngwio.c.  They allow "don't include stdio" testing of the library. */
 161.414 -/* This is the function that does the actual reading of data.  If you are
 161.415 -   not reading from a standard C stream, you should create a replacement
 161.416 -   read_data function and use it at run time with png_set_read_fn(), rather
 161.417 -   than changing the library. */
 161.418 +/* These copies of the default read/write functions come from pngrio.c and
 161.419 + * pngwio.c.  They allow "don't include stdio" testing of the library.
 161.420 + * This is the function that does the actual reading of data.  If you are
 161.421 + * not reading from a standard C stream, you should create a replacement
 161.422 + * read_data function and use it at run time with png_set_read_fn(), rather
 161.423 + * than changing the library.
 161.424 + */
 161.425 +
 161.426 +#ifdef PNG_IO_STATE_SUPPORTED
 161.427 +void
 161.428 +pngtest_check_io_state(png_structp png_ptr, png_size_t data_length,
 161.429 +   png_uint_32 io_op);
 161.430 +void
 161.431 +pngtest_check_io_state(png_structp png_ptr, png_size_t data_length,
 161.432 +   png_uint_32 io_op)
 161.433 +{
 161.434 +   png_uint_32 io_state = png_get_io_state(png_ptr);
 161.435 +   int err = 0;
 161.436 +
 161.437 +   /* Check if the current operation (reading / writing) is as expected. */
 161.438 +   if ((io_state & PNG_IO_MASK_OP) != io_op)
 161.439 +      png_error(png_ptr, "Incorrect operation in I/O state");
 161.440 +
 161.441 +   /* Check if the buffer size specific to the current location
 161.442 +    * (file signature / header / data / crc) is as expected.
 161.443 +    */
 161.444 +   switch (io_state & PNG_IO_MASK_LOC)
 161.445 +   {
 161.446 +   case PNG_IO_SIGNATURE:
 161.447 +      if (data_length > 8)
 161.448 +         err = 1;
 161.449 +      break;
 161.450 +   case PNG_IO_CHUNK_HDR:
 161.451 +      if (data_length != 8)
 161.452 +         err = 1;
 161.453 +      break;
 161.454 +   case PNG_IO_CHUNK_DATA:
 161.455 +      break;  /* no restrictions here */
 161.456 +   case PNG_IO_CHUNK_CRC:
 161.457 +      if (data_length != 4)
 161.458 +         err = 1;
 161.459 +      break;
 161.460 +   default:
 161.461 +      err = 1;  /* uninitialized */
 161.462 +   }
 161.463 +   if (err)
 161.464 +      png_error(png_ptr, "Bad I/O state or buffer size");
 161.465 +}
 161.466 +#endif
 161.467  
 161.468  #ifndef USE_FAR_KEYWORD
 161.469 -static void
 161.470 +static void PNGCBAPI
 161.471  pngtest_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
 161.472  {
 161.473 -   png_size_t check;
 161.474 +   png_size_t check = 0;
 161.475 +   png_voidp io_ptr;
 161.476  
 161.477     /* fread() returns 0 on error, so it is OK to store this in a png_size_t
 161.478      * instead of an int, which is what fread() actually returns.
 161.479      */
 161.480 -   READFILE((png_FILE_p)png_ptr->io_ptr, data, length, check);
 161.481 +   io_ptr = png_get_io_ptr(png_ptr);
 161.482 +   if (io_ptr != NULL)
 161.483 +   {
 161.484 +      check = fread(data, 1, length, (png_FILE_p)io_ptr);
 161.485 +   }
 161.486  
 161.487     if (check != length)
 161.488     {
 161.489 -      png_error(png_ptr, "Read Error!");
 161.490 +      png_error(png_ptr, "Read Error");
 161.491     }
 161.492 +
 161.493 +#ifdef PNG_IO_STATE_SUPPORTED
 161.494 +   pngtest_check_io_state(png_ptr, length, PNG_IO_READING);
 161.495 +#endif
 161.496  }
 161.497  #else
 161.498 -/* this is the model-independent version. Since the standard I/O library
 161.499 +/* This is the model-independent version. Since the standard I/O library
 161.500     can't handle far buffers in the medium and small models, we have to copy
 161.501     the data.
 161.502  */
 161.503 @@ -344,19 +405,19 @@
 161.504  #define NEAR_BUF_SIZE 1024
 161.505  #define MIN(a,b) (a <= b ? a : b)
 161.506  
 161.507 -static void
 161.508 +static void PNGCBAPI
 161.509  pngtest_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
 161.510  {
 161.511 -   int check;
 161.512 +   png_size_t check;
 161.513     png_byte *n_data;
 161.514     png_FILE_p io_ptr;
 161.515  
 161.516     /* Check if data really is near. If so, use usual code. */
 161.517     n_data = (png_byte *)CVT_PTR_NOCHECK(data);
 161.518 -   io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
 161.519 +   io_ptr = (png_FILE_p)CVT_PTR(png_get_io_ptr(png_ptr));
 161.520     if ((png_bytep)n_data == data)
 161.521     {
 161.522 -      READFILE(io_ptr, n_data, length, check);
 161.523 +      check = fread(n_data, 1, length, io_ptr);
 161.524     }
 161.525     else
 161.526     {
 161.527 @@ -364,12 +425,13 @@
 161.528        png_size_t read, remaining, err;
 161.529        check = 0;
 161.530        remaining = length;
 161.531 +
 161.532        do
 161.533        {
 161.534           read = MIN(NEAR_BUF_SIZE, remaining);
 161.535 -         READFILE(io_ptr, buf, 1, err);
 161.536 -         png_memcpy(data, buf, read); /* copy far buffer to near buffer */
 161.537 -         if(err != read)
 161.538 +         err = fread(buf, 1, 1, io_ptr);
 161.539 +         png_memcpy(data, buf, read); /* Copy far buffer to near buffer */
 161.540 +         if (err != read)
 161.541              break;
 161.542           else
 161.543              check += err;
 161.544 @@ -378,44 +440,49 @@
 161.545        }
 161.546        while (remaining != 0);
 161.547     }
 161.548 +
 161.549     if (check != length)
 161.550 -   {
 161.551 -      png_error(png_ptr, "read Error");
 161.552 -   }
 161.553 +      png_error(png_ptr, "Read Error");
 161.554 +
 161.555 +#ifdef PNG_IO_STATE_SUPPORTED
 161.556 +   pngtest_check_io_state(png_ptr, length, PNG_IO_READING);
 161.557 +#endif
 161.558  }
 161.559  #endif /* USE_FAR_KEYWORD */
 161.560  
 161.561 -#if defined(PNG_WRITE_FLUSH_SUPPORTED)
 161.562 -static void
 161.563 +#ifdef PNG_WRITE_FLUSH_SUPPORTED
 161.564 +static void PNGCBAPI
 161.565  pngtest_flush(png_structp png_ptr)
 161.566  {
 161.567 -#if !defined(_WIN32_WCE)
 161.568 -   png_FILE_p io_ptr;
 161.569 -   io_ptr = (png_FILE_p)CVT_PTR((png_ptr->io_ptr));
 161.570 -   if (io_ptr != NULL)
 161.571 -      fflush(io_ptr);
 161.572 -#endif
 161.573 +   /* Do nothing; fflush() is said to be just a waste of energy. */
 161.574 +   PNG_UNUSED(png_ptr)   /* Stifle compiler warning */
 161.575  }
 161.576  #endif
 161.577  
 161.578  /* This is the function that does the actual writing of data.  If you are
 161.579 -   not writing to a standard C stream, you should create a replacement
 161.580 -   write_data function and use it at run time with png_set_write_fn(), rather
 161.581 -   than changing the library. */
 161.582 + * not writing to a standard C stream, you should create a replacement
 161.583 + * write_data function and use it at run time with png_set_write_fn(), rather
 161.584 + * than changing the library.
 161.585 + */
 161.586  #ifndef USE_FAR_KEYWORD
 161.587 -static void
 161.588 +static void PNGCBAPI
 161.589  pngtest_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
 161.590  {
 161.591 -   png_uint_32 check;
 161.592 +   png_size_t check;
 161.593  
 161.594 -   WRITEFILE((png_FILE_p)png_ptr->io_ptr,  data, length, check);
 161.595 +   check = fwrite(data, 1, length, (png_FILE_p)png_get_io_ptr(png_ptr));
 161.596 +
 161.597     if (check != length)
 161.598     {
 161.599        png_error(png_ptr, "Write Error");
 161.600     }
 161.601 +
 161.602 +#ifdef PNG_IO_STATE_SUPPORTED
 161.603 +   pngtest_check_io_state(png_ptr, length, PNG_IO_WRITING);
 161.604 +#endif
 161.605  }
 161.606  #else
 161.607 -/* this is the model-independent version. Since the standard I/O library
 161.608 +/* This is the model-independent version. Since the standard I/O library
 161.609     can't handle far buffers in the medium and small models, we have to copy
 161.610     the data.
 161.611  */
 161.612 @@ -423,31 +490,34 @@
 161.613  #define NEAR_BUF_SIZE 1024
 161.614  #define MIN(a,b) (a <= b ? a : b)
 161.615  
 161.616 -static void
 161.617 +static void PNGCBAPI
 161.618  pngtest_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
 161.619  {
 161.620 -   png_uint_32 check;
 161.621 +   png_size_t check;
 161.622     png_byte *near_data;  /* Needs to be "png_byte *" instead of "png_bytep" */
 161.623     png_FILE_p io_ptr;
 161.624  
 161.625     /* Check if data really is near. If so, use usual code. */
 161.626     near_data = (png_byte *)CVT_PTR_NOCHECK(data);
 161.627 -   io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
 161.628 +   io_ptr = (png_FILE_p)CVT_PTR(png_get_io_ptr(png_ptr));
 161.629 +
 161.630     if ((png_bytep)near_data == data)
 161.631     {
 161.632 -      WRITEFILE(io_ptr, near_data, length, check);
 161.633 +      check = fwrite(near_data, 1, length, io_ptr);
 161.634     }
 161.635 +
 161.636     else
 161.637     {
 161.638        png_byte buf[NEAR_BUF_SIZE];
 161.639        png_size_t written, remaining, err;
 161.640        check = 0;
 161.641        remaining = length;
 161.642 +
 161.643        do
 161.644        {
 161.645           written = MIN(NEAR_BUF_SIZE, remaining);
 161.646 -         png_memcpy(buf, data, written); /* copy far buffer to near buffer */
 161.647 -         WRITEFILE(io_ptr, buf, written, err);
 161.648 +         png_memcpy(buf, data, written); /* Copy far buffer to near buffer */
 161.649 +         err = fwrite(buf, 1, written, io_ptr);
 161.650           if (err != written)
 161.651              break;
 161.652           else
 161.653 @@ -457,12 +527,16 @@
 161.654        }
 161.655        while (remaining != 0);
 161.656     }
 161.657 +
 161.658     if (check != length)
 161.659     {
 161.660        png_error(png_ptr, "Write Error");
 161.661     }
 161.662 +
 161.663 +#ifdef PNG_IO_STATE_SUPPORTED
 161.664 +   pngtest_check_io_state(png_ptr, length, PNG_IO_WRITING);
 161.665 +#endif
 161.666  }
 161.667 -
 161.668  #endif /* USE_FAR_KEYWORD */
 161.669  
 161.670  /* This function is called when there is a warning, but the library thinks
 161.671 @@ -470,13 +544,18 @@
 161.672   * here if you don't want to.  In the default configuration, png_ptr is
 161.673   * not used, but it is passed in case it may be useful.
 161.674   */
 161.675 -static void
 161.676 +static void PNGCBAPI
 161.677  pngtest_warning(png_structp png_ptr, png_const_charp message)
 161.678  {
 161.679     PNG_CONST char *name = "UNKNOWN (ERROR!)";
 161.680 -   if (png_ptr != NULL && png_ptr->error_ptr != NULL)
 161.681 -      name = png_ptr->error_ptr;
 161.682 -   fprintf(STDERR, "%s: libpng warning: %s\n", name, message);
 161.683 +   char *test;
 161.684 +   test = png_get_error_ptr(png_ptr);
 161.685 +
 161.686 +   if (test == NULL)
 161.687 +     fprintf(STDERR, "%s: libpng warning: %s\n", name, message);
 161.688 +
 161.689 +   else
 161.690 +     fprintf(STDERR, "%s: libpng warning: %s\n", test, message);
 161.691  }
 161.692  
 161.693  /* This is the default error handling function.  Note that replacements for
 161.694 @@ -484,30 +563,32 @@
 161.695   * function is used by default, or if the program supplies NULL for the
 161.696   * error function pointer in png_set_error_fn().
 161.697   */
 161.698 -static void
 161.699 +static void PNGCBAPI
 161.700  pngtest_error(png_structp png_ptr, png_const_charp message)
 161.701  {
 161.702     pngtest_warning(png_ptr, message);
 161.703     /* We can return because png_error calls the default handler, which is
 161.704 -    * actually OK in this case. */
 161.705 +    * actually OK in this case.
 161.706 +    */
 161.707  }
 161.708 -#endif /* PNG_NO_STDIO */
 161.709 +#endif /* !PNG_STDIO_SUPPORTED */
 161.710  /* END of code to validate stdio-free compilation */
 161.711  
 161.712  /* START of code to validate memory allocation and deallocation */
 161.713  #if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
 161.714  
 161.715  /* Allocate memory.  For reasonable files, size should never exceed
 161.716 -   64K.  However, zlib may allocate more then 64K if you don't tell
 161.717 -   it not to.  See zconf.h and png.h for more information.  zlib does
 161.718 -   need to allocate exactly 64K, so whatever you call here must
 161.719 -   have the ability to do that.
 161.720 -
 161.721 -   This piece of code can be compiled to validate max 64K allocations
 161.722 -   by setting MAXSEG_64K in zlib zconf.h *or* PNG_MAX_MALLOC_64K. */
 161.723 + * 64K.  However, zlib may allocate more then 64K if you don't tell
 161.724 + * it not to.  See zconf.h and png.h for more information.  zlib does
 161.725 + * need to allocate exactly 64K, so whatever you call here must
 161.726 + * have the ability to do that.
 161.727 + *
 161.728 + * This piece of code can be compiled to validate max 64K allocations
 161.729 + * by setting MAXSEG_64K in zlib zconf.h *or* PNG_MAX_MALLOC_64K.
 161.730 + */
 161.731  typedef struct memory_information
 161.732  {
 161.733 -   png_uint_32               size;
 161.734 +   png_alloc_size_t          size;
 161.735     png_voidp                 pointer;
 161.736     struct memory_information FAR *next;
 161.737  } memory_information;
 161.738 @@ -519,15 +600,17 @@
 161.739  static int total_allocation = 0;
 161.740  static int num_allocations = 0;
 161.741  
 161.742 -png_voidp png_debug_malloc PNGARG((png_structp png_ptr, png_uint_32 size));
 161.743 -void png_debug_free PNGARG((png_structp png_ptr, png_voidp ptr));
 161.744 +png_voidp PNGCBAPI png_debug_malloc PNGARG((png_structp png_ptr,
 161.745 +    png_alloc_size_t size));
 161.746 +void PNGCBAPI png_debug_free PNGARG((png_structp png_ptr, png_voidp ptr));
 161.747  
 161.748  png_voidp
 161.749 -png_debug_malloc(png_structp png_ptr, png_uint_32 size)
 161.750 +PNGCBAPI png_debug_malloc(png_structp png_ptr, png_alloc_size_t size)
 161.751  {
 161.752  
 161.753     /* png_malloc has already tested for NULL; png_create_struct calls
 161.754 -      png_debug_malloc directly, with png_ptr == NULL which is OK */
 161.755 +    * png_debug_malloc directly, with png_ptr == NULL which is OK
 161.756 +    */
 161.757  
 161.758     if (size == 0)
 161.759        return (NULL);
 161.760 @@ -539,41 +622,49 @@
 161.761        memory_infop pinfo;
 161.762        png_set_mem_fn(png_ptr, NULL, NULL, NULL);
 161.763        pinfo = (memory_infop)png_malloc(png_ptr,
 161.764 -         (png_uint_32)png_sizeof (*pinfo));
 161.765 +         png_sizeof(*pinfo));
 161.766        pinfo->size = size;
 161.767        current_allocation += size;
 161.768        total_allocation += size;
 161.769        num_allocations ++;
 161.770 +
 161.771        if (current_allocation > maximum_allocation)
 161.772           maximum_allocation = current_allocation;
 161.773 -      pinfo->pointer = (png_voidp)png_malloc(png_ptr, size);
 161.774 +
 161.775 +      pinfo->pointer = png_malloc(png_ptr, size);
 161.776        /* Restore malloc_fn and free_fn */
 161.777 -      png_set_mem_fn(png_ptr, png_voidp_NULL, (png_malloc_ptr)png_debug_malloc,
 161.778 -         (png_free_ptr)png_debug_free);
 161.779 +
 161.780 +      png_set_mem_fn(png_ptr,
 161.781 +          NULL, png_debug_malloc, png_debug_free);
 161.782 +
 161.783        if (size != 0 && pinfo->pointer == NULL)
 161.784        {
 161.785           current_allocation -= size;
 161.786           total_allocation -= size;
 161.787           png_error(png_ptr,
 161.788 -           "out of memory in pngtest->png_debug_malloc.");
 161.789 +           "out of memory in pngtest->png_debug_malloc");
 161.790        }
 161.791 +
 161.792        pinfo->next = pinformation;
 161.793        pinformation = pinfo;
 161.794        /* Make sure the caller isn't assuming zeroed memory. */
 161.795        png_memset(pinfo->pointer, 0xdd, pinfo->size);
 161.796 -      if(verbose)
 161.797 -         printf("png_malloc %lu bytes at %x\n",(unsigned long)size,
 161.798 -          pinfo->pointer);
 161.799 +
 161.800 +      if (verbose)
 161.801 +         printf("png_malloc %lu bytes at %p\n", (unsigned long)size,
 161.802 +            pinfo->pointer);
 161.803 +
 161.804        return (png_voidp)(pinfo->pointer);
 161.805     }
 161.806  }
 161.807  
 161.808  /* Free a pointer.  It is removed from the list at the same time. */
 161.809 -void
 161.810 +void PNGCBAPI
 161.811  png_debug_free(png_structp png_ptr, png_voidp ptr)
 161.812  {
 161.813     if (png_ptr == NULL)
 161.814        fprintf(STDERR, "NULL pointer to png_debug_free.\n");
 161.815 +
 161.816     if (ptr == 0)
 161.817     {
 161.818  #if 0 /* This happens all the time. */
 161.819 @@ -585,9 +676,11 @@
 161.820     /* Unlink the element from the list. */
 161.821     {
 161.822        memory_infop FAR *ppinfo = &pinformation;
 161.823 +
 161.824        for (;;)
 161.825        {
 161.826           memory_infop pinfo = *ppinfo;
 161.827 +
 161.828           if (pinfo->pointer == ptr)
 161.829           {
 161.830              *ppinfo = pinfo->next;
 161.831 @@ -598,27 +691,100 @@
 161.832                 the memory that is to be freed. */
 161.833              png_memset(ptr, 0x55, pinfo->size);
 161.834              png_free_default(png_ptr, pinfo);
 161.835 -            pinfo=NULL;
 161.836 +            pinfo = NULL;
 161.837              break;
 161.838           }
 161.839 +
 161.840           if (pinfo->next == NULL)
 161.841           {
 161.842              fprintf(STDERR, "Pointer %x not found\n", (unsigned int)ptr);
 161.843              break;
 161.844           }
 161.845 +
 161.846           ppinfo = &pinfo->next;
 161.847        }
 161.848     }
 161.849  
 161.850     /* Finally free the data. */
 161.851 -   if(verbose)
 161.852 -      printf("Freeing %x\n",ptr);
 161.853 +   if (verbose)
 161.854 +      printf("Freeing %p\n", ptr);
 161.855 +
 161.856     png_free_default(png_ptr, ptr);
 161.857 -   ptr=NULL;
 161.858 +   ptr = NULL;
 161.859  }
 161.860  #endif /* PNG_USER_MEM_SUPPORTED && PNG_DEBUG */
 161.861  /* END of code to test memory allocation/deallocation */
 161.862  
 161.863 +
 161.864 +/* Demonstration of user chunk support of the sTER and vpAg chunks */
 161.865 +#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
 161.866 +
 161.867 +/* (sTER is a public chunk not yet known by libpng.  vpAg is a private
 161.868 +chunk used in ImageMagick to store "virtual page" size).  */
 161.869 +
 161.870 +static png_uint_32 user_chunk_data[4];
 161.871 +
 161.872 +    /* 0: sTER mode + 1
 161.873 +     * 1: vpAg width
 161.874 +     * 2: vpAg height
 161.875 +     * 3: vpAg units
 161.876 +     */
 161.877 +
 161.878 +static int PNGCBAPI read_user_chunk_callback(png_struct *png_ptr,
 161.879 +   png_unknown_chunkp chunk)
 161.880 +{
 161.881 +   png_uint_32
 161.882 +     *my_user_chunk_data;
 161.883 +
 161.884 +   /* Return one of the following:
 161.885 +    *    return (-n);  chunk had an error
 161.886 +    *    return (0);  did not recognize
 161.887 +    *    return (n);  success
 161.888 +    *
 161.889 +    * The unknown chunk structure contains the chunk data:
 161.890 +    * png_byte name[5];
 161.891 +    * png_byte *data;
 161.892 +    * png_size_t size;
 161.893 +    *
 161.894 +    * Note that libpng has already taken care of the CRC handling.
 161.895 +    */
 161.896 +
 161.897 +   if (chunk->name[0] == 115 && chunk->name[1] ==  84 &&     /* s  T */
 161.898 +       chunk->name[2] ==  69 && chunk->name[3] ==  82)       /* E  R */
 161.899 +      {
 161.900 +         /* Found sTER chunk */
 161.901 +         if (chunk->size != 1)
 161.902 +            return (-1); /* Error return */
 161.903 +
 161.904 +         if (chunk->data[0] != 0 && chunk->data[0] != 1)
 161.905 +            return (-1);  /* Invalid mode */
 161.906 +
 161.907 +         my_user_chunk_data=(png_uint_32 *) png_get_user_chunk_ptr(png_ptr);
 161.908 +         my_user_chunk_data[0]=chunk->data[0]+1;
 161.909 +         return (1);
 161.910 +      }
 161.911 +
 161.912 +   if (chunk->name[0] != 118 || chunk->name[1] != 112 ||    /* v  p */
 161.913 +       chunk->name[2] !=  65 || chunk->name[3] != 103)      /* A  g */
 161.914 +      return (0); /* Did not recognize */
 161.915 +
 161.916 +   /* Found ImageMagick vpAg chunk */
 161.917 +
 161.918 +   if (chunk->size != 9)
 161.919 +      return (-1); /* Error return */
 161.920 +
 161.921 +   my_user_chunk_data=(png_uint_32 *) png_get_user_chunk_ptr(png_ptr);
 161.922 +
 161.923 +   my_user_chunk_data[1]=png_get_uint_31(png_ptr, chunk->data);
 161.924 +   my_user_chunk_data[2]=png_get_uint_31(png_ptr, chunk->data + 4);
 161.925 +   my_user_chunk_data[3]=(png_uint_32)chunk->data[8];
 161.926 +
 161.927 +   return (1);
 161.928 +
 161.929 +}
 161.930 +#endif
 161.931 +/* END of code to demonstrate user chunk support */
 161.932 +
 161.933  /* Test one file */
 161.934  int
 161.935  test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
 161.936 @@ -643,68 +809,65 @@
 161.937     int bit_depth, color_type;
 161.938  #ifdef PNG_SETJMP_SUPPORTED
 161.939  #ifdef USE_FAR_KEYWORD
 161.940 -   jmp_buf jmpbuf;
 161.941 +   jmp_buf tmp_jmpbuf;
 161.942  #endif
 161.943  #endif
 161.944  
 161.945 -#if defined(_WIN32_WCE)
 161.946 -   TCHAR path[MAX_PATH];
 161.947 -#endif
 161.948     char inbuf[256], outbuf[256];
 161.949  
 161.950     row_buf = NULL;
 161.951  
 161.952 -#if defined(_WIN32_WCE)
 161.953 -   MultiByteToWideChar(CP_ACP, 0, inname, -1, path, MAX_PATH);
 161.954 -   if ((fpin = CreateFile(path, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL)) == INVALID_HANDLE_VALUE)
 161.955 -#else
 161.956     if ((fpin = fopen(inname, "rb")) == NULL)
 161.957 -#endif
 161.958     {
 161.959        fprintf(STDERR, "Could not find input file %s\n", inname);
 161.960        return (1);
 161.961     }
 161.962  
 161.963 -#if defined(_WIN32_WCE)
 161.964 -   MultiByteToWideChar(CP_ACP, 0, outname, -1, path, MAX_PATH);
 161.965 -   if ((fpout = CreateFile(path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL)) == INVALID_HANDLE_VALUE)
 161.966 -#else
 161.967     if ((fpout = fopen(outname, "wb")) == NULL)
 161.968 -#endif
 161.969     {
 161.970        fprintf(STDERR, "Could not open output file %s\n", outname);
 161.971        FCLOSE(fpin);
 161.972        return (1);
 161.973     }
 161.974  
 161.975 -   png_debug(0, "Allocating read and write structures\n");
 161.976 +   pngtest_debug("Allocating read and write structures");
 161.977  #if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
 161.978 -   read_ptr = png_create_read_struct_2(PNG_LIBPNG_VER_STRING, png_voidp_NULL,
 161.979 -      png_error_ptr_NULL, png_error_ptr_NULL, png_voidp_NULL,
 161.980 -      (png_malloc_ptr)png_debug_malloc, (png_free_ptr)png_debug_free);
 161.981 +   read_ptr =
 161.982 +      png_create_read_struct_2(PNG_LIBPNG_VER_STRING, NULL,
 161.983 +      NULL, NULL, NULL, png_debug_malloc, png_debug_free);
 161.984  #else
 161.985 -   read_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, png_voidp_NULL,
 161.986 -      png_error_ptr_NULL, png_error_ptr_NULL);
 161.987 +   read_ptr =
 161.988 +      png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
 161.989  #endif
 161.990 -#if defined(PNG_NO_STDIO)
 161.991 +#ifndef PNG_STDIO_SUPPORTED
 161.992     png_set_error_fn(read_ptr, (png_voidp)inname, pngtest_error,
 161.993         pngtest_warning);
 161.994  #endif
 161.995 +
 161.996 +#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
 161.997 +   user_chunk_data[0] = 0;
 161.998 +   user_chunk_data[1] = 0;
 161.999 +   user_chunk_data[2] = 0;
161.1000 +   user_chunk_data[3] = 0;
161.1001 +   png_set_read_user_chunk_fn(read_ptr, user_chunk_data,
161.1002 +     read_user_chunk_callback);
161.1003 +
161.1004 +#endif
161.1005  #ifdef PNG_WRITE_SUPPORTED
161.1006  #if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
161.1007 -   write_ptr = png_create_write_struct_2(PNG_LIBPNG_VER_STRING, png_voidp_NULL,
161.1008 -      png_error_ptr_NULL, png_error_ptr_NULL, png_voidp_NULL,
161.1009 -      (png_malloc_ptr)png_debug_malloc, (png_free_ptr)png_debug_free);
161.1010 +   write_ptr =
161.1011 +      png_create_write_struct_2(PNG_LIBPNG_VER_STRING, NULL,
161.1012 +      NULL, NULL, NULL, png_debug_malloc, png_debug_free);
161.1013  #else
161.1014 -   write_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, png_voidp_NULL,
161.1015 -      png_error_ptr_NULL, png_error_ptr_NULL);
161.1016 +   write_ptr =
161.1017 +      png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
161.1018  #endif
161.1019 -#if defined(PNG_NO_STDIO)
161.1020 +#ifndef PNG_STDIO_SUPPORTED
161.1021     png_set_error_fn(write_ptr, (png_voidp)inname, pngtest_error,
161.1022         pngtest_warning);
161.1023  #endif
161.1024  #endif
161.1025 -   png_debug(0, "Allocating read_info, write_info and end_info structures\n");
161.1026 +   pngtest_debug("Allocating read_info, write_info and end_info structures");
161.1027     read_info_ptr = png_create_info_struct(read_ptr);
161.1028     end_info_ptr = png_create_info_struct(read_ptr);
161.1029  #ifdef PNG_WRITE_SUPPORTED
161.1030 @@ -713,16 +876,16 @@
161.1031  #endif
161.1032  
161.1033  #ifdef PNG_SETJMP_SUPPORTED
161.1034 -   png_debug(0, "Setting jmpbuf for read struct\n");
161.1035 +   pngtest_debug("Setting jmpbuf for read struct");
161.1036  #ifdef USE_FAR_KEYWORD
161.1037 -   if (setjmp(jmpbuf))
161.1038 +   if (setjmp(tmp_jmpbuf))
161.1039  #else
161.1040     if (setjmp(png_jmpbuf(read_ptr)))
161.1041  #endif
161.1042     {
161.1043        fprintf(STDERR, "%s -> %s: libpng read error\n", inname, outname);
161.1044 -      if (row_buf)
161.1045 -         png_free(read_ptr, row_buf);
161.1046 +      png_free(read_ptr, row_buf);
161.1047 +      row_buf = NULL;
161.1048        png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr);
161.1049  #ifdef PNG_WRITE_SUPPORTED
161.1050        png_destroy_info_struct(write_ptr, &write_end_info_ptr);
161.1051 @@ -733,13 +896,14 @@
161.1052        return (1);
161.1053     }
161.1054  #ifdef USE_FAR_KEYWORD
161.1055 -   png_memcpy(png_jmpbuf(read_ptr),jmpbuf,png_sizeof(jmp_buf));
161.1056 +   png_memcpy(png_jmpbuf(read_ptr), tmp_jmpbuf, png_sizeof(jmp_buf));
161.1057  #endif
161.1058  
161.1059  #ifdef PNG_WRITE_SUPPORTED
161.1060 -   png_debug(0, "Setting jmpbuf for write struct\n");
161.1061 +   pngtest_debug("Setting jmpbuf for write struct");
161.1062  #ifdef USE_FAR_KEYWORD
161.1063 -   if (setjmp(jmpbuf))
161.1064 +
161.1065 +   if (setjmp(tmp_jmpbuf))
161.1066  #else
161.1067     if (setjmp(png_jmpbuf(write_ptr)))
161.1068  #endif
161.1069 @@ -754,14 +918,15 @@
161.1070        FCLOSE(fpout);
161.1071        return (1);
161.1072     }
161.1073 +
161.1074  #ifdef USE_FAR_KEYWORD
161.1075 -   png_memcpy(png_jmpbuf(write_ptr),jmpbuf,png_sizeof(jmp_buf));
161.1076 +   png_memcpy(png_jmpbuf(write_ptr), tmp_jmpbuf, png_sizeof(jmp_buf));
161.1077  #endif
161.1078  #endif
161.1079  #endif
161.1080  
161.1081 -   png_debug(0, "Initializing input and output streams\n");
161.1082 -#if !defined(PNG_NO_STDIO)
161.1083 +   pngtest_debug("Initializing input and output streams");
161.1084 +#ifdef PNG_STDIO_SUPPORTED
161.1085     png_init_io(read_ptr, fpin);
161.1086  #  ifdef PNG_WRITE_SUPPORTED
161.1087     png_init_io(write_ptr, fpout);
161.1088 @@ -770,60 +935,72 @@
161.1089     png_set_read_fn(read_ptr, (png_voidp)fpin, pngtest_read_data);
161.1090  #  ifdef PNG_WRITE_SUPPORTED
161.1091     png_set_write_fn(write_ptr, (png_voidp)fpout,  pngtest_write_data,
161.1092 -#    if defined(PNG_WRITE_FLUSH_SUPPORTED)
161.1093 +#    ifdef PNG_WRITE_FLUSH_SUPPORTED
161.1094        pngtest_flush);
161.1095  #    else
161.1096        NULL);
161.1097  #    endif
161.1098  #  endif
161.1099  #endif
161.1100 -   if(status_dots_requested == 1)
161.1101 +
161.1102 +#ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED
161.1103 +   /* Normally one would use Z_DEFAULT_STRATEGY for text compression.
161.1104 +    * This is here just to make pngtest replicate the results from libpng
161.1105 +    * versions prior to 1.5.4, and to test this new API.
161.1106 +    */
161.1107 +   png_set_text_compression_strategy(write_ptr, Z_FILTERED);
161.1108 +#endif
161.1109 +
161.1110 +   if (status_dots_requested == 1)
161.1111     {
161.1112  #ifdef PNG_WRITE_SUPPORTED
161.1113        png_set_write_status_fn(write_ptr, write_row_callback);
161.1114  #endif
161.1115        png_set_read_status_fn(read_ptr, read_row_callback);
161.1116     }
161.1117 +
161.1118     else
161.1119     {
161.1120  #ifdef PNG_WRITE_SUPPORTED
161.1121 -      png_set_write_status_fn(write_ptr, png_write_status_ptr_NULL);
161.1122 +      png_set_write_status_fn(write_ptr, NULL);
161.1123  #endif
161.1124 -      png_set_read_status_fn(read_ptr, png_read_status_ptr_NULL);
161.1125 +      png_set_read_status_fn(read_ptr, NULL);
161.1126     }
161.1127  
161.1128 -#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
161.1129 +#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
161.1130     {
161.1131 -     int i;
161.1132 -     for(i=0; i<256; i++)
161.1133 -        filters_used[i]=0;
161.1134 -     png_set_read_user_transform_fn(read_ptr, count_filters);
161.1135 +      int i;
161.1136 +
161.1137 +      for (i = 0; i<256; i++)
161.1138 +         filters_used[i] = 0;
161.1139 +
161.1140 +      png_set_read_user_transform_fn(read_ptr, count_filters);
161.1141     }
161.1142  #endif
161.1143 -#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
161.1144 -   zero_samples=0;
161.1145 +#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
161.1146 +   zero_samples = 0;
161.1147     png_set_write_user_transform_fn(write_ptr, count_zero_samples);
161.1148  #endif
161.1149  
161.1150 -#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
161.1151 +#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
161.1152  #  ifndef PNG_HANDLE_CHUNK_ALWAYS
161.1153  #    define PNG_HANDLE_CHUNK_ALWAYS       3
161.1154  #  endif
161.1155     png_set_keep_unknown_chunks(read_ptr, PNG_HANDLE_CHUNK_ALWAYS,
161.1156 -      png_bytep_NULL, 0);
161.1157 +      NULL, 0);
161.1158  #endif
161.1159 -#if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
161.1160 +#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
161.1161  #  ifndef PNG_HANDLE_CHUNK_IF_SAFE
161.1162  #    define PNG_HANDLE_CHUNK_IF_SAFE      2
161.1163  #  endif
161.1164     png_set_keep_unknown_chunks(write_ptr, PNG_HANDLE_CHUNK_IF_SAFE,
161.1165 -      png_bytep_NULL, 0);
161.1166 +      NULL, 0);
161.1167  #endif
161.1168  
161.1169 -   png_debug(0, "Reading info struct\n");
161.1170 +   pngtest_debug("Reading info struct");
161.1171     png_read_info(read_ptr, read_info_ptr);
161.1172  
161.1173 -   png_debug(0, "Transferring info struct\n");
161.1174 +   pngtest_debug("Transferring info struct");
161.1175     {
161.1176        int interlace_type, compression_type, filter_type;
161.1177  
161.1178 @@ -831,42 +1008,42 @@
161.1179            &color_type, &interlace_type, &compression_type, &filter_type))
161.1180        {
161.1181           png_set_IHDR(write_ptr, write_info_ptr, width, height, bit_depth,
161.1182 -#if defined(PNG_WRITE_INTERLACING_SUPPORTED)
161.1183 +#ifdef PNG_WRITE_INTERLACING_SUPPORTED
161.1184              color_type, interlace_type, compression_type, filter_type);
161.1185  #else
161.1186              color_type, PNG_INTERLACE_NONE, compression_type, filter_type);
161.1187  #endif
161.1188        }
161.1189     }
161.1190 -#if defined(PNG_FIXED_POINT_SUPPORTED)
161.1191 -#if defined(PNG_cHRM_SUPPORTED)
161.1192 +#ifdef PNG_FIXED_POINT_SUPPORTED
161.1193 +#ifdef PNG_cHRM_SUPPORTED
161.1194     {
161.1195        png_fixed_point white_x, white_y, red_x, red_y, green_x, green_y, blue_x,
161.1196           blue_y;
161.1197 -      if (png_get_cHRM_fixed(read_ptr, read_info_ptr, &white_x, &white_y, &red_x,
161.1198 -         &red_y, &green_x, &green_y, &blue_x, &blue_y))
161.1199 +
161.1200 +      if (png_get_cHRM_fixed(read_ptr, read_info_ptr, &white_x, &white_y,
161.1201 +         &red_x, &red_y, &green_x, &green_y, &blue_x, &blue_y))
161.1202        {
161.1203           png_set_cHRM_fixed(write_ptr, write_info_ptr, white_x, white_y, red_x,
161.1204              red_y, green_x, green_y, blue_x, blue_y);
161.1205        }
161.1206     }
161.1207  #endif
161.1208 -#if defined(PNG_gAMA_SUPPORTED)
161.1209 +#ifdef PNG_gAMA_SUPPORTED
161.1210     {
161.1211        png_fixed_point gamma;
161.1212  
161.1213        if (png_get_gAMA_fixed(read_ptr, read_info_ptr, &gamma))
161.1214 -      {
161.1215           png_set_gAMA_fixed(write_ptr, write_info_ptr, gamma);
161.1216 -      }
161.1217     }
161.1218  #endif
161.1219  #else /* Use floating point versions */
161.1220 -#if defined(PNG_FLOATING_POINT_SUPPORTED)
161.1221 -#if defined(PNG_cHRM_SUPPORTED)
161.1222 +#ifdef PNG_FLOATING_POINT_SUPPORTED
161.1223 +#ifdef PNG_cHRM_SUPPORTED
161.1224     {
161.1225        double white_x, white_y, red_x, red_y, green_x, green_y, blue_x,
161.1226           blue_y;
161.1227 +
161.1228        if (png_get_cHRM(read_ptr, read_info_ptr, &white_x, &white_y, &red_x,
161.1229           &red_y, &green_x, &green_y, &blue_x, &blue_y))
161.1230        {
161.1231 @@ -875,22 +1052,20 @@
161.1232        }
161.1233     }
161.1234  #endif
161.1235 -#if defined(PNG_gAMA_SUPPORTED)
161.1236 +#ifdef PNG_gAMA_SUPPORTED
161.1237     {
161.1238        double gamma;
161.1239  
161.1240        if (png_get_gAMA(read_ptr, read_info_ptr, &gamma))
161.1241 -      {
161.1242           png_set_gAMA(write_ptr, write_info_ptr, gamma);
161.1243 -      }
161.1244     }
161.1245  #endif
161.1246 -#endif /* floating point */
161.1247 -#endif /* fixed point */
161.1248 -#if defined(PNG_iCCP_SUPPORTED)
161.1249 +#endif /* Floating point */
161.1250 +#endif /* Fixed point */
161.1251 +#ifdef PNG_iCCP_SUPPORTED
161.1252     {
161.1253        png_charp name;
161.1254 -      png_charp profile;
161.1255 +      png_bytep profile;
161.1256        png_uint_32 proflen;
161.1257        int compression_type;
161.1258  
161.1259 @@ -902,14 +1077,12 @@
161.1260        }
161.1261     }
161.1262  #endif
161.1263 -#if defined(PNG_sRGB_SUPPORTED)
161.1264 +#ifdef PNG_sRGB_SUPPORTED
161.1265     {
161.1266        int intent;
161.1267  
161.1268        if (png_get_sRGB(read_ptr, read_info_ptr, &intent))
161.1269 -      {
161.1270           png_set_sRGB(write_ptr, write_info_ptr, intent);
161.1271 -      }
161.1272     }
161.1273  #endif
161.1274     {
161.1275 @@ -917,11 +1090,9 @@
161.1276        int num_palette;
161.1277  
161.1278        if (png_get_PLTE(read_ptr, read_info_ptr, &palette, &num_palette))
161.1279 -      {
161.1280           png_set_PLTE(write_ptr, write_info_ptr, palette, num_palette);
161.1281 -      }
161.1282     }
161.1283 -#if defined(PNG_bKGD_SUPPORTED)
161.1284 +#ifdef PNG_bKGD_SUPPORTED
161.1285     {
161.1286        png_color_16p background;
161.1287  
161.1288 @@ -931,28 +1102,27 @@
161.1289        }
161.1290     }
161.1291  #endif
161.1292 -#if defined(PNG_hIST_SUPPORTED)
161.1293 +#ifdef PNG_hIST_SUPPORTED
161.1294     {
161.1295        png_uint_16p hist;
161.1296  
161.1297        if (png_get_hIST(read_ptr, read_info_ptr, &hist))
161.1298 -      {
161.1299           png_set_hIST(write_ptr, write_info_ptr, hist);
161.1300 -      }
161.1301     }
161.1302  #endif
161.1303 -#if defined(PNG_oFFs_SUPPORTED)
161.1304 +#ifdef PNG_oFFs_SUPPORTED
161.1305     {
161.1306        png_int_32 offset_x, offset_y;
161.1307        int unit_type;
161.1308  
161.1309 -      if (png_get_oFFs(read_ptr, read_info_ptr,&offset_x,&offset_y,&unit_type))
161.1310 +      if (png_get_oFFs(read_ptr, read_info_ptr, &offset_x, &offset_y,
161.1311 +          &unit_type))
161.1312        {
161.1313           png_set_oFFs(write_ptr, write_info_ptr, offset_x, offset_y, unit_type);
161.1314        }
161.1315     }
161.1316  #endif
161.1317 -#if defined(PNG_pCAL_SUPPORTED)
161.1318 +#ifdef PNG_pCAL_SUPPORTED
161.1319     {
161.1320        png_charp purpose, units;
161.1321        png_charpp params;
161.1322 @@ -967,28 +1137,24 @@
161.1323        }
161.1324     }
161.1325  #endif
161.1326 -#if defined(PNG_pHYs_SUPPORTED)
161.1327 +#ifdef PNG_pHYs_SUPPORTED
161.1328     {
161.1329        png_uint_32 res_x, res_y;
161.1330        int unit_type;
161.1331  
161.1332        if (png_get_pHYs(read_ptr, read_info_ptr, &res_x, &res_y, &unit_type))
161.1333 -      {
161.1334           png_set_pHYs(write_ptr, write_info_ptr, res_x, res_y, unit_type);
161.1335 -      }
161.1336     }
161.1337  #endif
161.1338 -#if defined(PNG_sBIT_SUPPORTED)
161.1339 +#ifdef PNG_sBIT_SUPPORTED
161.1340     {
161.1341        png_color_8p sig_bit;
161.1342  
161.1343        if (png_get_sBIT(read_ptr, read_info_ptr, &sig_bit))
161.1344 -      {
161.1345           png_set_sBIT(write_ptr, write_info_ptr, sig_bit);
161.1346 -      }
161.1347     }
161.1348  #endif
161.1349 -#if defined(PNG_sCAL_SUPPORTED)
161.1350 +#ifdef PNG_sCAL_SUPPORTED
161.1351  #ifdef PNG_FLOATING_POINT_SUPPORTED
161.1352     {
161.1353        int unit;
161.1354 @@ -1009,69 +1175,85 @@
161.1355        if (png_get_sCAL_s(read_ptr, read_info_ptr, &unit, &scal_width,
161.1356            &scal_height))
161.1357        {
161.1358 -         png_set_sCAL_s(write_ptr, write_info_ptr, unit, scal_width, scal_height);
161.1359 +         png_set_sCAL_s(write_ptr, write_info_ptr, unit, scal_width,
161.1360 +             scal_height);
161.1361        }
161.1362     }
161.1363  #endif
161.1364  #endif
161.1365  #endif
161.1366 -#if defined(PNG_TEXT_SUPPORTED)
161.1367 +#ifdef PNG_TEXT_SUPPORTED
161.1368     {
161.1369        png_textp text_ptr;
161.1370        int num_text;
161.1371  
161.1372        if (png_get_text(read_ptr, read_info_ptr, &text_ptr, &num_text) > 0)
161.1373        {
161.1374 -         png_debug1(0, "Handling %d iTXt/tEXt/zTXt chunks\n", num_text);
161.1375 +         pngtest_debug1("Handling %d iTXt/tEXt/zTXt chunks", num_text);
161.1376           png_set_text(write_ptr, write_info_ptr, text_ptr, num_text);
161.1377        }
161.1378     }
161.1379  #endif
161.1380 -#if defined(PNG_tIME_SUPPORTED)
161.1381 +#ifdef PNG_tIME_SUPPORTED
161.1382     {
161.1383        png_timep mod_time;
161.1384  
161.1385        if (png_get_tIME(read_ptr, read_info_ptr, &mod_time))
161.1386        {
161.1387           png_set_tIME(write_ptr, write_info_ptr, mod_time);
161.1388 -#if defined(PNG_TIME_RFC1123_SUPPORTED)
161.1389 -         /* we have to use png_strcpy instead of "=" because the string
161.1390 -            pointed to by png_convert_to_rfc1123() gets free'ed before
161.1391 -            we use it */
161.1392 -         png_strcpy(tIME_string,png_convert_to_rfc1123(read_ptr, mod_time));
161.1393 +#ifdef PNG_TIME_RFC1123_SUPPORTED
161.1394 +         /* We have to use png_memcpy instead of "=" because the string
161.1395 +          * pointed to by png_convert_to_rfc1123() gets free'ed before
161.1396 +          * we use it.
161.1397 +          */
161.1398 +         png_memcpy(tIME_string,
161.1399 +                    png_convert_to_rfc1123(read_ptr, mod_time),
161.1400 +                    png_sizeof(tIME_string));
161.1401 +
161.1402 +         tIME_string[png_sizeof(tIME_string) - 1] = '\0';
161.1403           tIME_chunk_present++;
161.1404  #endif /* PNG_TIME_RFC1123_SUPPORTED */
161.1405        }
161.1406     }
161.1407  #endif
161.1408 -#if defined(PNG_tRNS_SUPPORTED)
161.1409 +#ifdef PNG_tRNS_SUPPORTED
161.1410     {
161.1411 -      png_bytep trans;
161.1412 +      png_bytep trans_alpha;
161.1413        int num_trans;
161.1414 -      png_color_16p trans_values;
161.1415 +      png_color_16p trans_color;
161.1416  
161.1417 -      if (png_get_tRNS(read_ptr, read_info_ptr, &trans, &num_trans,
161.1418 -         &trans_values))
161.1419 +      if (png_get_tRNS(read_ptr, read_info_ptr, &trans_alpha, &num_trans,
161.1420 +         &trans_color))
161.1421        {
161.1422 -         png_set_tRNS(write_ptr, write_info_ptr, trans, num_trans,
161.1423 -            trans_values);
161.1424 +         int sample_max = (1 << bit_depth);
161.1425 +         /* libpng doesn't reject a tRNS chunk with out-of-range samples */
161.1426 +         if (!((color_type == PNG_COLOR_TYPE_GRAY &&
161.1427 +             (int)trans_color->gray > sample_max) ||
161.1428 +             (color_type == PNG_COLOR_TYPE_RGB &&
161.1429 +             ((int)trans_color->red > sample_max ||
161.1430 +             (int)trans_color->green > sample_max ||
161.1431 +             (int)trans_color->blue > sample_max))))
161.1432 +            png_set_tRNS(write_ptr, write_info_ptr, trans_alpha, num_trans,
161.1433 +               trans_color);
161.1434        }
161.1435     }
161.1436  #endif
161.1437 -#if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
161.1438 +#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
161.1439     {
161.1440        png_unknown_chunkp unknowns;
161.1441 -      int num_unknowns = (int)png_get_unknown_chunks(read_ptr, read_info_ptr,
161.1442 +      int num_unknowns = png_get_unknown_chunks(read_ptr, read_info_ptr,
161.1443           &unknowns);
161.1444 +
161.1445        if (num_unknowns)
161.1446        {
161.1447 -         png_size_t i;
161.1448 +         int i;
161.1449           png_set_unknown_chunks(write_ptr, write_info_ptr, unknowns,
161.1450             num_unknowns);
161.1451 -         /* copy the locations from the read_info_ptr.  The automatically
161.1452 -            generated locations in write_info_ptr are wrong because we
161.1453 -            haven't written anything yet */
161.1454 -         for (i = 0; i < (png_size_t)num_unknowns; i++)
161.1455 +         /* Copy the locations from the read_info_ptr.  The automatically
161.1456 +          * generated locations in write_info_ptr are wrong because we
161.1457 +          * haven't written anything yet.
161.1458 +          */
161.1459 +         for (i = 0; i < num_unknowns; i++)
161.1460             png_set_unknown_chunk_location(write_ptr, write_info_ptr, i,
161.1461               unknowns[i].location);
161.1462        }
161.1463 @@ -1079,21 +1261,59 @@
161.1464  #endif
161.1465  
161.1466  #ifdef PNG_WRITE_SUPPORTED
161.1467 -   png_debug(0, "\nWriting info struct\n");
161.1468 +   pngtest_debug("Writing info struct");
161.1469  
161.1470  /* If we wanted, we could write info in two steps:
161.1471 -   png_write_info_before_PLTE(write_ptr, write_info_ptr);
161.1472 + * png_write_info_before_PLTE(write_ptr, write_info_ptr);
161.1473   */
161.1474     png_write_info(write_ptr, write_info_ptr);
161.1475 +
161.1476 +#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
161.1477 +   if (user_chunk_data[0] != 0)
161.1478 +   {
161.1479 +      png_byte png_sTER[5] = {115,  84,  69,  82, '\0'};
161.1480 +
161.1481 +      unsigned char
161.1482 +        ster_chunk_data[1];
161.1483 +
161.1484 +      if (verbose)
161.1485 +         fprintf(STDERR, "\n stereo mode = %lu\n",
161.1486 +           (unsigned long)(user_chunk_data[0] - 1));
161.1487 +
161.1488 +      ster_chunk_data[0]=(unsigned char)(user_chunk_data[0] - 1);
161.1489 +      png_write_chunk(write_ptr, png_sTER, ster_chunk_data, 1);
161.1490 +   }
161.1491 +
161.1492 +   if (user_chunk_data[1] != 0 || user_chunk_data[2] != 0)
161.1493 +   {
161.1494 +      png_byte png_vpAg[5] = {118, 112,  65, 103, '\0'};
161.1495 +
161.1496 +      unsigned char
161.1497 +        vpag_chunk_data[9];
161.1498 +
161.1499 +      if (verbose)
161.1500 +         fprintf(STDERR, " vpAg = %lu x %lu, units = %lu\n",
161.1501 +           (unsigned long)user_chunk_data[1],
161.1502 +           (unsigned long)user_chunk_data[2],
161.1503 +           (unsigned long)user_chunk_data[3]);
161.1504 +
161.1505 +      png_save_uint_32(vpag_chunk_data, user_chunk_data[1]);
161.1506 +      png_save_uint_32(vpag_chunk_data + 4, user_chunk_data[2]);
161.1507 +      vpag_chunk_data[8] = (unsigned char)(user_chunk_data[3] & 0xff);
161.1508 +      png_write_chunk(write_ptr, png_vpAg, vpag_chunk_data, 9);
161.1509 +   }
161.1510 +
161.1511 +#endif
161.1512  #endif
161.1513  
161.1514  #ifdef SINGLE_ROWBUF_ALLOC
161.1515 -   png_debug(0, "\nAllocating row buffer...");
161.1516 +   pngtest_debug("Allocating row buffer...");
161.1517     row_buf = (png_bytep)png_malloc(read_ptr,
161.1518        png_get_rowbytes(read_ptr, read_info_ptr));
161.1519 -   png_debug1(0, "0x%08lx\n\n", (unsigned long)row_buf);
161.1520 +
161.1521 +   pngtest_debug1("\t0x%08lx", (unsigned long)row_buf);
161.1522  #endif /* SINGLE_ROWBUF_ALLOC */
161.1523 -   png_debug(0, "Writing row data\n");
161.1524 +   pngtest_debug("Writing row data");
161.1525  
161.1526  #if defined(PNG_READ_INTERLACING_SUPPORTED) || \
161.1527    defined(PNG_WRITE_INTERLACING_SUPPORTED)
161.1528 @@ -1102,7 +1322,7 @@
161.1529     png_set_interlace_handling(write_ptr);
161.1530  #  endif
161.1531  #else
161.1532 -   num_pass=1;
161.1533 +   num_pass = 1;
161.1534  #endif
161.1535  
161.1536  #ifdef PNGTEST_TIMING
161.1537 @@ -1112,17 +1332,19 @@
161.1538  #endif
161.1539     for (pass = 0; pass < num_pass; pass++)
161.1540     {
161.1541 -      png_debug1(0, "Writing row data for pass %d\n",pass);
161.1542 +      pngtest_debug1("Writing row data for pass %d", pass);
161.1543        for (y = 0; y < height; y++)
161.1544        {
161.1545  #ifndef SINGLE_ROWBUF_ALLOC
161.1546 -         png_debug2(0, "\nAllocating row buffer (pass %d, y = %ld)...", pass,y);
161.1547 +         pngtest_debug2("Allocating row buffer (pass %d, y = %u)...", pass, y);
161.1548           row_buf = (png_bytep)png_malloc(read_ptr,
161.1549              png_get_rowbytes(read_ptr, read_info_ptr));
161.1550 -         png_debug2(0, "0x%08lx (%ld bytes)\n", (unsigned long)row_buf,
161.1551 +
161.1552 +         pngtest_debug2("\t0x%08lx (%u bytes)", (unsigned long)row_buf,
161.1553              png_get_rowbytes(read_ptr, read_info_ptr));
161.1554 +
161.1555  #endif /* !SINGLE_ROWBUF_ALLOC */
161.1556 -         png_read_rows(read_ptr, (png_bytepp)&row_buf, png_bytepp_NULL, 1);
161.1557 +         png_read_rows(read_ptr, (png_bytepp)&row_buf, NULL, 1);
161.1558  
161.1559  #ifdef PNG_WRITE_SUPPORTED
161.1560  #ifdef PNGTEST_TIMING
161.1561 @@ -1139,66 +1361,72 @@
161.1562  #endif /* PNG_WRITE_SUPPORTED */
161.1563  
161.1564  #ifndef SINGLE_ROWBUF_ALLOC
161.1565 -         png_debug2(0, "Freeing row buffer (pass %d, y = %ld)\n\n", pass, y);
161.1566 +         pngtest_debug2("Freeing row buffer (pass %d, y = %u)", pass, y);
161.1567           png_free(read_ptr, row_buf);
161.1568 +         row_buf = NULL;
161.1569  #endif /* !SINGLE_ROWBUF_ALLOC */
161.1570        }
161.1571     }
161.1572  
161.1573 -#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
161.1574 +#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
161.1575     png_free_data(read_ptr, read_info_ptr, PNG_FREE_UNKN, -1);
161.1576  #endif
161.1577 -#if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
161.1578 +#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
161.1579     png_free_data(write_ptr, write_info_ptr, PNG_FREE_UNKN, -1);
161.1580  #endif
161.1581  
161.1582 -   png_debug(0, "Reading and writing end_info data\n");
161.1583 +   pngtest_debug("Reading and writing end_info data");
161.1584  
161.1585     png_read_end(read_ptr, end_info_ptr);
161.1586 -#if defined(PNG_TEXT_SUPPORTED)
161.1587 +#ifdef PNG_TEXT_SUPPORTED
161.1588     {
161.1589        png_textp text_ptr;
161.1590        int num_text;
161.1591  
161.1592        if (png_get_text(read_ptr, end_info_ptr, &text_ptr, &num_text) > 0)
161.1593        {
161.1594 -         png_debug1(0, "Handling %d iTXt/tEXt/zTXt chunks\n", num_text);
161.1595 +         pngtest_debug1("Handling %d iTXt/tEXt/zTXt chunks", num_text);
161.1596           png_set_text(write_ptr, write_end_info_ptr, text_ptr, num_text);
161.1597        }
161.1598     }
161.1599  #endif
161.1600 -#if defined(PNG_tIME_SUPPORTED)
161.1601 +#ifdef PNG_tIME_SUPPORTED
161.1602     {
161.1603        png_timep mod_time;
161.1604  
161.1605        if (png_get_tIME(read_ptr, end_info_ptr, &mod_time))
161.1606        {
161.1607           png_set_tIME(write_ptr, write_end_info_ptr, mod_time);
161.1608 -#if defined(PNG_TIME_RFC1123_SUPPORTED)
161.1609 -         /* we have to use png_strcpy instead of "=" because the string
161.1610 +#ifdef PNG_TIME_RFC1123_SUPPORTED
161.1611 +         /* We have to use png_memcpy instead of "=" because the string
161.1612              pointed to by png_convert_to_rfc1123() gets free'ed before
161.1613              we use it */
161.1614 -         png_strcpy(tIME_string,png_convert_to_rfc1123(read_ptr, mod_time));
161.1615 +         png_memcpy(tIME_string,
161.1616 +                    png_convert_to_rfc1123(read_ptr, mod_time),
161.1617 +                    png_sizeof(tIME_string));
161.1618 +
161.1619 +         tIME_string[png_sizeof(tIME_string) - 1] = '\0';
161.1620           tIME_chunk_present++;
161.1621  #endif /* PNG_TIME_RFC1123_SUPPORTED */
161.1622        }
161.1623     }
161.1624  #endif
161.1625 -#if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
161.1626 +#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
161.1627     {
161.1628        png_unknown_chunkp unknowns;
161.1629 -      int num_unknowns;
161.1630 -      num_unknowns = (int)png_get_unknown_chunks(read_ptr, end_info_ptr,
161.1631 +      int num_unknowns = png_get_unknown_chunks(read_ptr, end_info_ptr,
161.1632           &unknowns);
161.1633 +
161.1634        if (num_unknowns)
161.1635        {
161.1636 -         png_size_t i;
161.1637 +         int i;
161.1638           png_set_unknown_chunks(write_ptr, write_end_info_ptr, unknowns,
161.1639             num_unknowns);
161.1640 -         /* copy the locations from the read_info_ptr.  The automatically
161.1641 -            generated locations in write_end_info_ptr are wrong because we
161.1642 -            haven't written the end_info yet */
161.1643 -         for (i = 0; i < (png_size_t)num_unknowns; i++)
161.1644 +         /* Copy the locations from the read_info_ptr.  The automatically
161.1645 +          * generated locations in write_end_info_ptr are wrong because we
161.1646 +          * haven't written the end_info yet.
161.1647 +          */
161.1648 +         for (i = 0; i < num_unknowns; i++)
161.1649             png_set_unknown_chunk_location(write_ptr, write_end_info_ptr, i,
161.1650               unknowns[i].location);
161.1651        }
161.1652 @@ -1209,82 +1437,74 @@
161.1653  #endif
161.1654  
161.1655  #ifdef PNG_EASY_ACCESS_SUPPORTED
161.1656 -   if(verbose)
161.1657 +   if (verbose)
161.1658     {
161.1659        png_uint_32 iwidth, iheight;
161.1660        iwidth = png_get_image_width(write_ptr, write_info_ptr);
161.1661        iheight = png_get_image_height(write_ptr, write_info_ptr);
161.1662 -      fprintf(STDERR, "Image width = %lu, height = %lu\n",
161.1663 +      fprintf(STDERR, "\n Image width = %lu, height = %lu\n",
161.1664           (unsigned long)iwidth, (unsigned long)iheight);
161.1665     }
161.1666  #endif
161.1667  
161.1668 -   png_debug(0, "Destroying data structs\n");
161.1669 +   pngtest_debug("Destroying data structs");
161.1670  #ifdef SINGLE_ROWBUF_ALLOC
161.1671 -   png_debug(1, "destroying row_buf for read_ptr\n");
161.1672 +   pngtest_debug("destroying row_buf for read_ptr");
161.1673     png_free(read_ptr, row_buf);
161.1674 -   row_buf=NULL;
161.1675 +   row_buf = NULL;
161.1676  #endif /* SINGLE_ROWBUF_ALLOC */
161.1677 -   png_debug(1, "destroying read_ptr, read_info_ptr, end_info_ptr\n");
161.1678 +   pngtest_debug("destroying read_ptr, read_info_ptr, end_info_ptr");
161.1679     png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr);
161.1680  #ifdef PNG_WRITE_SUPPORTED
161.1681 -   png_debug(1, "destroying write_end_info_ptr\n");
161.1682 +   pngtest_debug("destroying write_end_info_ptr");
161.1683     png_destroy_info_struct(write_ptr, &write_end_info_ptr);
161.1684 -   png_debug(1, "destroying write_ptr, write_info_ptr\n");
161.1685 +   pngtest_debug("destroying write_ptr, write_info_ptr");
161.1686     png_destroy_write_struct(&write_ptr, &write_info_ptr);
161.1687  #endif
161.1688 -   png_debug(0, "Destruction complete.\n");
161.1689 +   pngtest_debug("Destruction complete.");
161.1690  
161.1691     FCLOSE(fpin);
161.1692     FCLOSE(fpout);
161.1693  
161.1694 -   png_debug(0, "Opening files for comparison\n");
161.1695 -#if defined(_WIN32_WCE)
161.1696 -   MultiByteToWideChar(CP_ACP, 0, inname, -1, path, MAX_PATH);
161.1697 -   if ((fpin = CreateFile(path, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL)) == INVALID_HANDLE_VALUE)
161.1698 -#else
161.1699 +   pngtest_debug("Opening files for comparison");
161.1700     if ((fpin = fopen(inname, "rb")) == NULL)
161.1701 -#endif
161.1702     {
161.1703        fprintf(STDERR, "Could not find file %s\n", inname);
161.1704        return (1);
161.1705     }
161.1706  
161.1707 -#if defined(_WIN32_WCE)
161.1708 -   MultiByteToWideChar(CP_ACP, 0, outname, -1, path, MAX_PATH);
161.1709 -   if ((fpout = CreateFile(path, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL)) == INVALID_HANDLE_VALUE)
161.1710 -#else
161.1711     if ((fpout = fopen(outname, "rb")) == NULL)
161.1712 -#endif
161.1713     {
161.1714        fprintf(STDERR, "Could not find file %s\n", outname);
161.1715        FCLOSE(fpin);
161.1716        return (1);
161.1717     }
161.1718  
161.1719 -   for(;;)
161.1720 +   for (;;)
161.1721     {
161.1722        png_size_t num_in, num_out;
161.1723  
161.1724 -      READFILE(fpin, inbuf, 1, num_in);
161.1725 -      READFILE(fpout, outbuf, 1, num_out);
161.1726 +         num_in = fread(inbuf, 1, 1, fpin);
161.1727 +         num_out = fread(outbuf, 1, 1, fpout);
161.1728  
161.1729        if (num_in != num_out)
161.1730        {
161.1731           fprintf(STDERR, "\nFiles %s and %s are of a different size\n",
161.1732                   inname, outname);
161.1733 -         if(wrote_question == 0)
161.1734 +
161.1735 +         if (wrote_question == 0)
161.1736           {
161.1737              fprintf(STDERR,
161.1738           "   Was %s written with the same maximum IDAT chunk size (%d bytes),",
161.1739 -              inname,PNG_ZBUF_SIZE);
161.1740 +              inname, PNG_ZBUF_SIZE);
161.1741              fprintf(STDERR,
161.1742                "\n   filtering heuristic (libpng default), compression");
161.1743              fprintf(STDERR,
161.1744                " level (zlib default),\n   and zlib version (%s)?\n\n",
161.1745                ZLIB_VERSION);
161.1746 -            wrote_question=1;
161.1747 +            wrote_question = 1;
161.1748           }
161.1749 +
161.1750           FCLOSE(fpin);
161.1751           FCLOSE(fpout);
161.1752           return (0);
161.1753 @@ -1296,18 +1516,20 @@
161.1754        if (png_memcmp(inbuf, outbuf, num_in))
161.1755        {
161.1756           fprintf(STDERR, "\nFiles %s and %s are different\n", inname, outname);
161.1757 -         if(wrote_question == 0)
161.1758 +
161.1759 +         if (wrote_question == 0)
161.1760           {
161.1761              fprintf(STDERR,
161.1762           "   Was %s written with the same maximum IDAT chunk size (%d bytes),",
161.1763 -                 inname,PNG_ZBUF_SIZE);
161.1764 +                 inname, PNG_ZBUF_SIZE);
161.1765              fprintf(STDERR,
161.1766                "\n   filtering heuristic (libpng default), compression");
161.1767              fprintf(STDERR,
161.1768                " level (zlib default),\n   and zlib version (%s)?\n\n",
161.1769                ZLIB_VERSION);
161.1770 -            wrote_question=1;
161.1771 +            wrote_question = 1;
161.1772           }
161.1773 +
161.1774           FCLOSE(fpin);
161.1775           FCLOSE(fpout);
161.1776           return (0);
161.1777 @@ -1320,7 +1542,7 @@
161.1778     return (0);
161.1779  }
161.1780  
161.1781 -/* input and output filenames */
161.1782 +/* Input and output filenames */
161.1783  #ifdef RISCOS
161.1784  static PNG_CONST char *inname = "pngtest/png";
161.1785  static PNG_CONST char *outname = "pngout/png";
161.1786 @@ -1335,23 +1557,23 @@
161.1787     int multiple = 0;
161.1788     int ierror = 0;
161.1789  
161.1790 -   fprintf(STDERR, "Testing libpng version %s\n", PNG_LIBPNG_VER_STRING);
161.1791 +   fprintf(STDERR, "\n Testing libpng version %s\n", PNG_LIBPNG_VER_STRING);
161.1792     fprintf(STDERR, "   with zlib   version %s\n", ZLIB_VERSION);
161.1793 -   fprintf(STDERR,"%s",png_get_copyright(NULL));
161.1794 +   fprintf(STDERR, "%s", png_get_copyright(NULL));
161.1795     /* Show the version of libpng used in building the library */
161.1796 -   fprintf(STDERR," library (%lu):%s",
161.1797 +   fprintf(STDERR, " library (%lu):%s",
161.1798        (unsigned long)png_access_version_number(),
161.1799        png_get_header_version(NULL));
161.1800 +
161.1801     /* Show the version of libpng used in building the application */
161.1802 -   fprintf(STDERR," pngtest (%lu):%s", (unsigned long)PNG_LIBPNG_VER,
161.1803 +   fprintf(STDERR, " pngtest (%lu):%s", (unsigned long)PNG_LIBPNG_VER,
161.1804        PNG_HEADER_VERSION_STRING);
161.1805 -   fprintf(STDERR," png_sizeof(png_struct)=%ld, png_sizeof(png_info)=%ld\n",
161.1806 -                    (long)png_sizeof(png_struct), (long)png_sizeof(png_info));
161.1807  
161.1808     /* Do some consistency checking on the memory allocation settings, I'm
161.1809 -      not sure this matters, but it is nice to know, the first of these
161.1810 -      tests should be impossible because of the way the macros are set
161.1811 -      in pngconf.h */
161.1812 +    * not sure this matters, but it is nice to know, the first of these
161.1813 +    * tests should be impossible because of the way the macros are set
161.1814 +    * in pngconf.h
161.1815 +    */
161.1816  #if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K)
161.1817        fprintf(STDERR, " NOTE: Zlib compiled for max 64k, libpng not\n");
161.1818  #endif
161.1819 @@ -1376,6 +1598,7 @@
161.1820           multiple = 1;
161.1821           status_dots_requested = 0;
161.1822        }
161.1823 +
161.1824        else if (strcmp(argv[1], "-mv") == 0 ||
161.1825                 strcmp(argv[1], "-vm") == 0 )
161.1826        {
161.1827 @@ -1383,12 +1606,14 @@
161.1828           verbose = 1;
161.1829           status_dots_requested = 1;
161.1830        }
161.1831 +
161.1832        else if (strcmp(argv[1], "-v") == 0)
161.1833        {
161.1834           verbose = 1;
161.1835           status_dots_requested = 1;
161.1836           inname = argv[2];
161.1837        }
161.1838 +
161.1839        else
161.1840        {
161.1841           inname = argv[1];
161.1842 @@ -1396,10 +1621,10 @@
161.1843        }
161.1844     }
161.1845  
161.1846 -   if (!multiple && argc == 3+verbose)
161.1847 -     outname = argv[2+verbose];
161.1848 +   if (!multiple && argc == 3 + verbose)
161.1849 +     outname = argv[2 + verbose];
161.1850  
161.1851 -   if ((!multiple && argc > 3+verbose) || (multiple && argc < 2))
161.1852 +   if ((!multiple && argc > 3 + verbose) || (multiple && argc < 2))
161.1853     {
161.1854       fprintf(STDERR,
161.1855         "usage: %s [infile.png] [outfile.png]\n\t%s -m {infile.png}\n",
161.1856 @@ -1419,32 +1644,34 @@
161.1857  #endif
161.1858        for (i=2; i<argc; ++i)
161.1859        {
161.1860 -#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
161.1861 -         int k;
161.1862 -#endif
161.1863           int kerror;
161.1864 -         fprintf(STDERR, "Testing %s:",argv[i]);
161.1865 +         fprintf(STDERR, "\n Testing %s:", argv[i]);
161.1866           kerror = test_one_file(argv[i], outname);
161.1867           if (kerror == 0)
161.1868           {
161.1869 -#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
161.1870 +#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
161.1871 +            int k;
161.1872 +#endif
161.1873 +#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
161.1874              fprintf(STDERR, "\n PASS (%lu zero samples)\n",
161.1875                 (unsigned long)zero_samples);
161.1876  #else
161.1877              fprintf(STDERR, " PASS\n");
161.1878  #endif
161.1879 -#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
161.1880 -            for (k=0; k<256; k++)
161.1881 -               if(filters_used[k])
161.1882 +#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
161.1883 +            for (k = 0; k<256; k++)
161.1884 +               if (filters_used[k])
161.1885                    fprintf(STDERR, " Filter %d was used %lu times\n",
161.1886 -                     k,(unsigned long)filters_used[k]);
161.1887 +                     k, (unsigned long)filters_used[k]);
161.1888  #endif
161.1889 -#if defined(PNG_TIME_RFC1123_SUPPORTED)
161.1890 -         if(tIME_chunk_present != 0)
161.1891 -            fprintf(STDERR, " tIME = %s\n",tIME_string);
161.1892 +#ifdef PNG_TIME_RFC1123_SUPPORTED
161.1893 +         if (tIME_chunk_present != 0)
161.1894 +            fprintf(STDERR, " tIME = %s\n", tIME_string);
161.1895 +
161.1896           tIME_chunk_present = 0;
161.1897  #endif /* PNG_TIME_RFC1123_SUPPORTED */
161.1898           }
161.1899 +
161.1900           else
161.1901           {
161.1902              fprintf(STDERR, " FAIL\n");
161.1903 @@ -1453,17 +1680,20 @@
161.1904  #if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
161.1905           if (allocation_now != current_allocation)
161.1906              fprintf(STDERR, "MEMORY ERROR: %d bytes lost\n",
161.1907 -               current_allocation-allocation_now);
161.1908 +               current_allocation - allocation_now);
161.1909 +
161.1910           if (current_allocation != 0)
161.1911           {
161.1912              memory_infop pinfo = pinformation;
161.1913  
161.1914              fprintf(STDERR, "MEMORY ERROR: %d bytes still allocated\n",
161.1915                 current_allocation);
161.1916 +
161.1917              while (pinfo != NULL)
161.1918              {
161.1919 -               fprintf(STDERR, " %lu bytes at %x\n", (unsigned long)pinfo->size,
161.1920 -                 (unsigned int) pinfo->pointer);
161.1921 +               fprintf(STDERR, " %lu bytes at %x\n",
161.1922 +                 (unsigned long)pinfo->size,
161.1923 +                 (unsigned int)pinfo->pointer);
161.1924                 pinfo = pinfo->next;
161.1925              }
161.1926           }
161.1927 @@ -1480,65 +1710,76 @@
161.1928              num_allocations);
161.1929  #endif
161.1930     }
161.1931 +
161.1932     else
161.1933     {
161.1934        int i;
161.1935 -      for (i=0; i<3; ++i)
161.1936 +      for (i = 0; i<3; ++i)
161.1937        {
161.1938           int kerror;
161.1939  #if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
161.1940           int allocation_now = current_allocation;
161.1941  #endif
161.1942 -         if (i == 1) status_dots_requested = 1;
161.1943 -         else if(verbose == 0)status_dots_requested = 0;
161.1944 +         if (i == 1)
161.1945 +            status_dots_requested = 1;
161.1946 +
161.1947 +         else if (verbose == 0)
161.1948 +            status_dots_requested = 0;
161.1949 +
161.1950           if (i == 0 || verbose == 1 || ierror != 0)
161.1951 -            fprintf(STDERR, "Testing %s:",inname);
161.1952 +            fprintf(STDERR, "\n Testing %s:", inname);
161.1953 +
161.1954           kerror = test_one_file(inname, outname);
161.1955 -         if(kerror == 0)
161.1956 +
161.1957 +         if (kerror == 0)
161.1958           {
161.1959 -            if(verbose == 1 || i == 2)
161.1960 +            if (verbose == 1 || i == 2)
161.1961              {
161.1962 -#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
161.1963 +#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
161.1964                  int k;
161.1965  #endif
161.1966 -#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
161.1967 +#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
161.1968                  fprintf(STDERR, "\n PASS (%lu zero samples)\n",
161.1969                     (unsigned long)zero_samples);
161.1970  #else
161.1971                  fprintf(STDERR, " PASS\n");
161.1972  #endif
161.1973 -#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
161.1974 -                for (k=0; k<256; k++)
161.1975 -                   if(filters_used[k])
161.1976 +#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED
161.1977 +                for (k = 0; k<256; k++)
161.1978 +                   if (filters_used[k])
161.1979                        fprintf(STDERR, " Filter %d was used %lu times\n",
161.1980 -                         k,(unsigned long)filters_used[k]);
161.1981 +                         k, (unsigned long)filters_used[k]);
161.1982  #endif
161.1983 -#if defined(PNG_TIME_RFC1123_SUPPORTED)
161.1984 -             if(tIME_chunk_present != 0)
161.1985 -                fprintf(STDERR, " tIME = %s\n",tIME_string);
161.1986 +#ifdef PNG_TIME_RFC1123_SUPPORTED
161.1987 +             if (tIME_chunk_present != 0)
161.1988 +                fprintf(STDERR, " tIME = %s\n", tIME_string);
161.1989  #endif /* PNG_TIME_RFC1123_SUPPORTED */
161.1990              }
161.1991           }
161.1992 +
161.1993           else
161.1994           {
161.1995 -            if(verbose == 0 && i != 2)
161.1996 -               fprintf(STDERR, "Testing %s:",inname);
161.1997 +            if (verbose == 0 && i != 2)
161.1998 +               fprintf(STDERR, "\n Testing %s:", inname);
161.1999 +
161.2000              fprintf(STDERR, " FAIL\n");
161.2001              ierror += kerror;
161.2002           }
161.2003  #if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG
161.2004           if (allocation_now != current_allocation)
161.2005               fprintf(STDERR, "MEMORY ERROR: %d bytes lost\n",
161.2006 -               current_allocation-allocation_now);
161.2007 +               current_allocation - allocation_now);
161.2008 +
161.2009           if (current_allocation != 0)
161.2010           {
161.2011               memory_infop pinfo = pinformation;
161.2012  
161.2013               fprintf(STDERR, "MEMORY ERROR: %d bytes still allocated\n",
161.2014                  current_allocation);
161.2015 +
161.2016               while (pinfo != NULL)
161.2017               {
161.2018 -                fprintf(STDERR," %lu bytes at %x\n",
161.2019 +                fprintf(STDERR, " %lu bytes at %x\n",
161.2020                     (unsigned long)pinfo->size, (unsigned int)pinfo->pointer);
161.2021                  pinfo = pinfo->next;
161.2022               }
161.2023 @@ -1561,22 +1802,24 @@
161.2024     t_stop = (float)clock();
161.2025     t_misc += (t_stop - t_start);
161.2026     t_start = t_stop;
161.2027 -   fprintf(STDERR," CPU time used = %.3f seconds",
161.2028 +   fprintf(STDERR, " CPU time used = %.3f seconds",
161.2029        (t_misc+t_decode+t_encode)/(float)CLOCKS_PER_SEC);
161.2030 -   fprintf(STDERR," (decoding %.3f,\n",
161.2031 +   fprintf(STDERR, " (decoding %.3f,\n",
161.2032        t_decode/(float)CLOCKS_PER_SEC);
161.2033 -   fprintf(STDERR,"        encoding %.3f ,",
161.2034 +   fprintf(STDERR, "        encoding %.3f ,",
161.2035        t_encode/(float)CLOCKS_PER_SEC);
161.2036 -   fprintf(STDERR," other %.3f seconds)\n\n",
161.2037 +   fprintf(STDERR, " other %.3f seconds)\n\n",
161.2038        t_misc/(float)CLOCKS_PER_SEC);
161.2039  #endif
161.2040  
161.2041     if (ierror == 0)
161.2042 -      fprintf(STDERR, "libpng passes test\n");
161.2043 +      fprintf(STDERR, " libpng passes test\n");
161.2044 +
161.2045     else
161.2046 -      fprintf(STDERR, "libpng FAILS test\n");
161.2047 +      fprintf(STDERR, " libpng FAILS test\n");
161.2048 +
161.2049     return (int)(ierror != 0);
161.2050  }
161.2051  
161.2052  /* Generate a compiler error if there is an old png.h in the search path. */
161.2053 -typedef version_1_2_18 your_png_h_is_not_version_1_2_18;
161.2054 +typedef png_libpng_version_1_5_4 Your_png_h_is_not_version_1_5_4;
   162.1 --- a/src/share/native/sun/awt/libpng/pngtrans.c	Fri Sep 30 17:20:56 2011 -0700
   162.2 +++ b/src/share/native/sun/awt/libpng/pngtrans.c	Tue Oct 04 12:39:42 2011 -0700
   162.3 @@ -20,8 +20,6 @@
   162.4   * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   162.5   * or visit www.oracle.com if you need additional information or have any
   162.6   * questions.
   162.7 - *
   162.8 - * THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
   162.9   */
  162.10  
  162.11  /* pngtrans.c - transforms the data in a row (used by both readers and writers)
  162.12 @@ -31,47 +29,59 @@
  162.13   * However, the following notice accompanied the original version of this
  162.14   * file and, per its terms, should not be removed:
  162.15   *
  162.16 - * Last changed in libpng 1.2.13 November 13, 2006
  162.17 - * For conditions of distribution and use, see copyright notice in png.h
  162.18 - * Copyright (c) 1998-2006 Glenn Randers-Pehrson
  162.19 + * Last changed in libpng 1.5.4 [July 7, 2011]
  162.20 + * Copyright (c) 1998-2011 Glenn Randers-Pehrson
  162.21   * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
  162.22   * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
  162.23 + *
  162.24 + * This code is released under the libpng license.
  162.25 + * For conditions of distribution and use, see the disclaimer
  162.26 + * and license in png.h
  162.27   */
  162.28  
  162.29 -#define PNG_INTERNAL
  162.30 -#include "png.h"
  162.31 +#include "pngpriv.h"
  162.32  
  162.33  #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162.34 +
  162.35  #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  162.36 -/* turn on BGR-to-RGB mapping */
  162.37 +/* Turn on BGR-to-RGB mapping */
  162.38  void PNGAPI
  162.39  png_set_bgr(png_structp png_ptr)
  162.40  {
  162.41 -   png_debug(1, "in png_set_bgr\n");
  162.42 -   if(png_ptr == NULL) return;
  162.43 +   png_debug(1, "in png_set_bgr");
  162.44 +
  162.45 +   if (png_ptr == NULL)
  162.46 +      return;
  162.47 +
  162.48     png_ptr->transformations |= PNG_BGR;
  162.49  }
  162.50  #endif
  162.51  
  162.52  #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  162.53 -/* turn on 16 bit byte swapping */
  162.54 +/* Turn on 16 bit byte swapping */
  162.55  void PNGAPI
  162.56  png_set_swap(png_structp png_ptr)
  162.57  {
  162.58 -   png_debug(1, "in png_set_swap\n");
  162.59 -   if(png_ptr == NULL) return;
  162.60 +   png_debug(1, "in png_set_swap");
  162.61 +
  162.62 +   if (png_ptr == NULL)
  162.63 +      return;
  162.64 +
  162.65     if (png_ptr->bit_depth == 16)
  162.66        png_ptr->transformations |= PNG_SWAP_BYTES;
  162.67  }
  162.68  #endif
  162.69  
  162.70  #if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
  162.71 -/* turn on pixel packing */
  162.72 +/* Turn on pixel packing */
  162.73  void PNGAPI
  162.74  png_set_packing(png_structp png_ptr)
  162.75  {
  162.76 -   png_debug(1, "in png_set_packing\n");
  162.77 -   if(png_ptr == NULL) return;
  162.78 +   png_debug(1, "in png_set_packing");
  162.79 +
  162.80 +   if (png_ptr == NULL)
  162.81 +      return;
  162.82 +
  162.83     if (png_ptr->bit_depth < 8)
  162.84     {
  162.85        png_ptr->transformations |= PNG_PACK;
  162.86 @@ -81,12 +91,15 @@
  162.87  #endif
  162.88  
  162.89  #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  162.90 -/* turn on packed pixel swapping */
  162.91 +/* Turn on packed pixel swapping */
  162.92  void PNGAPI
  162.93  png_set_packswap(png_structp png_ptr)
  162.94  {
  162.95 -   png_debug(1, "in png_set_packswap\n");
  162.96 -   if(png_ptr == NULL) return;
  162.97 +   png_debug(1, "in png_set_packswap");
  162.98 +
  162.99 +   if (png_ptr == NULL)
 162.100 +      return;
 162.101 +
 162.102     if (png_ptr->bit_depth < 8)
 162.103        png_ptr->transformations |= PNG_PACKSWAP;
 162.104  }
 162.105 @@ -94,10 +107,13 @@
 162.106  
 162.107  #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
 162.108  void PNGAPI
 162.109 -png_set_shift(png_structp png_ptr, png_color_8p true_bits)
 162.110 +png_set_shift(png_structp png_ptr, png_const_color_8p true_bits)
 162.111  {
 162.112 -   png_debug(1, "in png_set_shift\n");
 162.113 -   if(png_ptr == NULL) return;
 162.114 +   png_debug(1, "in png_set_shift");
 162.115 +
 162.116 +   if (png_ptr == NULL)
 162.117 +      return;
 162.118 +
 162.119     png_ptr->transformations |= PNG_SHIFT;
 162.120     png_ptr->shift = *true_bits;
 162.121  }
 162.122 @@ -108,7 +124,8 @@
 162.123  int PNGAPI
 162.124  png_set_interlace_handling(png_structp png_ptr)
 162.125  {
 162.126 -   png_debug(1, "in png_set_interlace handling\n");
 162.127 +   png_debug(1, "in png_set_interlace handling");
 162.128 +
 162.129     if (png_ptr && png_ptr->interlaced)
 162.130     {
 162.131        png_ptr->transformations |= PNG_INTERLACE;
 162.132 @@ -128,12 +145,17 @@
 162.133  void PNGAPI
 162.134  png_set_filler(png_structp png_ptr, png_uint_32 filler, int filler_loc)
 162.135  {
 162.136 -   png_debug(1, "in png_set_filler\n");
 162.137 -   if(png_ptr == NULL) return;
 162.138 +   png_debug(1, "in png_set_filler");
 162.139 +
 162.140 +   if (png_ptr == NULL)
 162.141 +      return;
 162.142 +
 162.143     png_ptr->transformations |= PNG_FILLER;
 162.144 -   png_ptr->filler = (png_byte)filler;
 162.145 +   png_ptr->filler = (png_uint_16)filler;
 162.146 +
 162.147     if (filler_loc == PNG_FILLER_AFTER)
 162.148        png_ptr->flags |= PNG_FLAG_FILLER_AFTER;
 162.149 +
 162.150     else
 162.151        png_ptr->flags &= ~PNG_FLAG_FILLER_AFTER;
 162.152  
 162.153 @@ -148,7 +170,7 @@
 162.154     }
 162.155  
 162.156     /* Also I added this in libpng-1.0.2a (what happens when we expand
 162.157 -    * a less-than-8-bit grayscale to GA? */
 162.158 +    * a less-than-8-bit grayscale to GA?) */
 162.159  
 162.160     if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY && png_ptr->bit_depth >= 8)
 162.161     {
 162.162 @@ -156,17 +178,18 @@
 162.163     }
 162.164  }
 162.165  
 162.166 -#if !defined(PNG_1_0_X)
 162.167  /* Added to libpng-1.2.7 */
 162.168  void PNGAPI
 162.169  png_set_add_alpha(png_structp png_ptr, png_uint_32 filler, int filler_loc)
 162.170  {
 162.171 -   png_debug(1, "in png_set_add_alpha\n");
 162.172 -   if(png_ptr == NULL) return;
 162.173 +   png_debug(1, "in png_set_add_alpha");
 162.174 +
 162.175 +   if (png_ptr == NULL)
 162.176 +      return;
 162.177 +
 162.178     png_set_filler(png_ptr, filler, filler_loc);
 162.179     png_ptr->transformations |= PNG_ADD_ALPHA;
 162.180  }
 162.181 -#endif
 162.182  
 162.183  #endif
 162.184  
 162.185 @@ -175,8 +198,11 @@
 162.186  void PNGAPI
 162.187  png_set_swap_alpha(png_structp png_ptr)
 162.188  {
 162.189 -   png_debug(1, "in png_set_swap_alpha\n");
 162.190 -   if(png_ptr == NULL) return;
 162.191 +   png_debug(1, "in png_set_swap_alpha");
 162.192 +
 162.193 +   if (png_ptr == NULL)
 162.194 +      return;
 162.195 +
 162.196     png_ptr->transformations |= PNG_SWAP_ALPHA;
 162.197  }
 162.198  #endif
 162.199 @@ -186,8 +212,11 @@
 162.200  void PNGAPI
 162.201  png_set_invert_alpha(png_structp png_ptr)
 162.202  {
 162.203 -   png_debug(1, "in png_set_invert_alpha\n");
 162.204 -   if(png_ptr == NULL) return;
 162.205 +   png_debug(1, "in png_set_invert_alpha");
 162.206 +
 162.207 +   if (png_ptr == NULL)
 162.208 +      return;
 162.209 +
 162.210     png_ptr->transformations |= PNG_INVERT_ALPHA;
 162.211  }
 162.212  #endif
 162.213 @@ -196,28 +225,28 @@
 162.214  void PNGAPI
 162.215  png_set_invert_mono(png_structp png_ptr)
 162.216  {
 162.217 -   png_debug(1, "in png_set_invert_mono\n");
 162.218 -   if(png_ptr == NULL) return;
 162.219 +   png_debug(1, "in png_set_invert_mono");
 162.220 +
 162.221 +   if (png_ptr == NULL)
 162.222 +      return;
 162.223 +
 162.224     png_ptr->transformations |= PNG_INVERT_MONO;
 162.225  }
 162.226  
 162.227 -/* invert monochrome grayscale data */
 162.228 +/* Invert monochrome grayscale data */
 162.229  void /* PRIVATE */
 162.230  png_do_invert(png_row_infop row_info, png_bytep row)
 162.231  {
 162.232 -   png_debug(1, "in png_do_invert\n");
 162.233 +   png_debug(1, "in png_do_invert");
 162.234 +
 162.235    /* This test removed from libpng version 1.0.13 and 1.2.0:
 162.236     *   if (row_info->bit_depth == 1 &&
 162.237     */
 162.238 -#if defined(PNG_USELESS_TESTS_SUPPORTED)
 162.239 -   if (row == NULL || row_info == NULL)
 162.240 -     return;
 162.241 -#endif
 162.242     if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
 162.243     {
 162.244        png_bytep rp = row;
 162.245 -      png_uint_32 i;
 162.246 -      png_uint_32 istop = row_info->rowbytes;
 162.247 +      png_size_t i;
 162.248 +      png_size_t istop = row_info->rowbytes;
 162.249  
 162.250        for (i = 0; i < istop; i++)
 162.251        {
 162.252 @@ -225,47 +254,49 @@
 162.253           rp++;
 162.254        }
 162.255     }
 162.256 +
 162.257     else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
 162.258        row_info->bit_depth == 8)
 162.259     {
 162.260        png_bytep rp = row;
 162.261 -      png_uint_32 i;
 162.262 -      png_uint_32 istop = row_info->rowbytes;
 162.263 +      png_size_t i;
 162.264 +      png_size_t istop = row_info->rowbytes;
 162.265  
 162.266 -      for (i = 0; i < istop; i+=2)
 162.267 +      for (i = 0; i < istop; i += 2)
 162.268        {
 162.269           *rp = (png_byte)(~(*rp));
 162.270 -         rp+=2;
 162.271 +         rp += 2;
 162.272        }
 162.273     }
 162.274 +
 162.275 +#ifdef PNG_16BIT_SUPPORTED
 162.276     else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
 162.277        row_info->bit_depth == 16)
 162.278     {
 162.279        png_bytep rp = row;
 162.280 -      png_uint_32 i;
 162.281 -      png_uint_32 istop = row_info->rowbytes;
 162.282 +      png_size_t i;
 162.283 +      png_size_t istop = row_info->rowbytes;
 162.284  
 162.285 -      for (i = 0; i < istop; i+=4)
 162.286 +      for (i = 0; i < istop; i += 4)
 162.287        {
 162.288           *rp = (png_byte)(~(*rp));
 162.289 -         *(rp+1) = (png_byte)(~(*(rp+1)));
 162.290 -         rp+=4;
 162.291 +         *(rp + 1) = (png_byte)(~(*(rp + 1)));
 162.292 +         rp += 4;
 162.293        }
 162.294     }
 162.295 +#endif
 162.296  }
 162.297  #endif
 162.298  
 162.299 +#ifdef PNG_16BIT_SUPPORTED
 162.300  #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
 162.301 -/* swaps byte order on 16 bit depth images */
 162.302 +/* Swaps byte order on 16 bit depth images */
 162.303  void /* PRIVATE */
 162.304  png_do_swap(png_row_infop row_info, png_bytep row)
 162.305  {
 162.306 -   png_debug(1, "in png_do_swap\n");
 162.307 -   if (
 162.308 -#if defined(PNG_USELESS_TESTS_SUPPORTED)
 162.309 -       row != NULL && row_info != NULL &&
 162.310 -#endif
 162.311 -       row_info->bit_depth == 16)
 162.312 +   png_debug(1, "in png_do_swap");
 162.313 +
 162.314 +   if (row_info->bit_depth == 16)
 162.315     {
 162.316        png_bytep rp = row;
 162.317        png_uint_32 i;
 162.318 @@ -280,6 +311,7 @@
 162.319     }
 162.320  }
 162.321  #endif
 162.322 +#endif
 162.323  
 162.324  #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)
 162.325  static PNG_CONST png_byte onebppswaptable[256] = {
 162.326 @@ -387,27 +419,28 @@
 162.327     0x8F, 0x9F, 0xAF, 0xBF, 0xCF, 0xDF, 0xEF, 0xFF
 162.328  };
 162.329  
 162.330 -/* swaps pixel packing order within bytes */
 162.331 +/* Swaps pixel packing order within bytes */
 162.332  void /* PRIVATE */
 162.333  png_do_packswap(png_row_infop row_info, png_bytep row)
 162.334  {
 162.335 -   png_debug(1, "in png_do_packswap\n");
 162.336 -   if (
 162.337 -#if defined(PNG_USELESS_TESTS_SUPPORTED)
 162.338 -       row != NULL && row_info != NULL &&
 162.339 -#endif
 162.340 -       row_info->bit_depth < 8)
 162.341 +   png_debug(1, "in png_do_packswap");
 162.342 +
 162.343 +   if (row_info->bit_depth < 8)
 162.344     {
 162.345 -      png_bytep rp, end, table;
 162.346 +      png_bytep rp;
 162.347 +      png_const_bytep end, table;
 162.348  
 162.349        end = row + row_info->rowbytes;
 162.350  
 162.351        if (row_info->bit_depth == 1)
 162.352 -         table = (png_bytep)onebppswaptable;
 162.353 +         table = onebppswaptable;
 162.354 +
 162.355        else if (row_info->bit_depth == 2)
 162.356 -         table = (png_bytep)twobppswaptable;
 162.357 +         table = twobppswaptable;
 162.358 +
 162.359        else if (row_info->bit_depth == 4)
 162.360 -         table = (png_bytep)fourbppswaptable;
 162.361 +         table = fourbppswaptable;
 162.362 +
 162.363        else
 162.364           return;
 162.365  
 162.366 @@ -419,174 +452,130 @@
 162.367  
 162.368  #if defined(PNG_WRITE_FILLER_SUPPORTED) || \
 162.369      defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
 162.370 -/* remove filler or alpha byte(s) */
 162.371 +/* Remove a channel - this used to be 'png_do_strip_filler' but it used a
 162.372 + * somewhat weird combination of flags to determine what to do.  All the calls
 162.373 + * to png_do_strip_filler are changed in 1.5.2 to call this instead with the
 162.374 + * correct arguments.
 162.375 + *
 162.376 + * The routine isn't general - the channel must be the channel at the start or
 162.377 + * end (not in the middle) of each pixel.
 162.378 + */
 162.379  void /* PRIVATE */
 162.380 -png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags)
 162.381 +png_do_strip_channel(png_row_infop row_info, png_bytep row, int at_start)
 162.382  {
 162.383 -   png_debug(1, "in png_do_strip_filler\n");
 162.384 -#if defined(PNG_USELESS_TESTS_SUPPORTED)
 162.385 -   if (row != NULL && row_info != NULL)
 162.386 -#endif
 162.387 +   png_bytep sp = row; /* source pointer */
 162.388 +   png_bytep dp = row; /* destination pointer */
 162.389 +   png_bytep ep = row + row_info->rowbytes; /* One beyond end of row */
 162.390 +
 162.391 +   /* At the start sp will point to the first byte to copy and dp to where
 162.392 +    * it is copied to.  ep always points just beyond the end of the row, so
 162.393 +    * the loop simply copies (channels-1) channels until sp reaches ep.
 162.394 +    *
 162.395 +    * at_start:        0 -- convert AG, XG, ARGB, XRGB, AAGG, XXGG, etc.
 162.396 +    *            nonzero -- convert GA, GX, RGBA, RGBX, GGAA, RRGGBBXX, etc.
 162.397 +    */
 162.398 +
 162.399 +   /* GA, GX, XG cases */
 162.400 +   if (row_info->channels == 2)
 162.401     {
 162.402 -      png_bytep sp=row;
 162.403 -      png_bytep dp=row;
 162.404 -      png_uint_32 row_width=row_info->width;
 162.405 -      png_uint_32 i;
 162.406 +      if (row_info->bit_depth == 8)
 162.407 +      {
 162.408 +         if (at_start) /* Skip initial filler */
 162.409 +            ++sp;
 162.410 +         else          /* Skip initial channel and, for sp, the filler */
 162.411 +            sp += 2, ++dp;
 162.412  
 162.413 -      if ((row_info->color_type == PNG_COLOR_TYPE_RGB ||
 162.414 -         (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
 162.415 -         (flags & PNG_FLAG_STRIP_ALPHA))) &&
 162.416 -         row_info->channels == 4)
 162.417 +         /* For a 1 pixel wide image there is nothing to do */
 162.418 +         while (sp < ep)
 162.419 +            *dp++ = *sp, sp += 2;
 162.420 +
 162.421 +         row_info->pixel_depth = 8;
 162.422 +      }
 162.423 +
 162.424 +      else if (row_info->bit_depth == 16)
 162.425        {
 162.426 -         if (row_info->bit_depth == 8)
 162.427 +         if (at_start) /* Skip initial filler */
 162.428 +            sp += 2;
 162.429 +         else          /* Skip initial channel and, for sp, the filler */
 162.430 +            sp += 4, dp += 2;
 162.431 +
 162.432 +         while (sp < ep)
 162.433 +            *dp++ = *sp++, *dp++ = *sp, sp += 3;
 162.434 +
 162.435 +         row_info->pixel_depth = 16;
 162.436 +      }
 162.437 +
 162.438 +      else
 162.439 +         return; /* bad bit depth */
 162.440 +
 162.441 +      row_info->channels = 1;
 162.442 +
 162.443 +      /* Finally fix the color type if it records an alpha channel */
 162.444 +      if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
 162.445 +         row_info->color_type = PNG_COLOR_TYPE_GRAY;
 162.446 +   }
 162.447 +
 162.448 +   /* RGBA, RGBX, XRGB cases */
 162.449 +   else if (row_info->channels == 4)
 162.450 +   {
 162.451 +      if (row_info->bit_depth == 8)
 162.452 +      {
 162.453 +         if (at_start) /* Skip initial filler */
 162.454 +            ++sp;
 162.455 +         else          /* Skip initial channels and, for sp, the filler */
 162.456 +            sp += 4, dp += 3;
 162.457 +
 162.458 +         /* Note that the loop adds 3 to dp and 4 to sp each time. */
 162.459 +         while (sp < ep)
 162.460 +            *dp++ = *sp++, *dp++ = *sp++, *dp++ = *sp, sp += 2;
 162.461 +
 162.462 +         row_info->pixel_depth = 24;
 162.463 +      }
 162.464 +
 162.465 +      else if (row_info->bit_depth == 16)
 162.466 +      {
 162.467 +         if (at_start) /* Skip initial filler */
 162.468 +            sp += 2;
 162.469 +         else          /* Skip initial channels and, for sp, the filler */
 162.470 +            sp += 8, dp += 6;
 162.471 +
 162.472 +         while (sp < ep)
 162.473           {
 162.474 -            /* This converts from RGBX or RGBA to RGB */
 162.475 -            if (flags & PNG_FLAG_FILLER_AFTER)
 162.476 -            {
 162.477 -               dp+=3; sp+=4;
 162.478 -               for (i = 1; i < row_width; i++)
 162.479 -               {
 162.480 -                  *dp++ = *sp++;
 162.481 -                  *dp++ = *sp++;
 162.482 -                  *dp++ = *sp++;
 162.483 -                  sp++;
 162.484 -               }
 162.485 -            }
 162.486 -            /* This converts from XRGB or ARGB to RGB */
 162.487 -            else
 162.488 -            {
 162.489 -               for (i = 0; i < row_width; i++)
 162.490 -               {
 162.491 -                  sp++;
 162.492 -                  *dp++ = *sp++;
 162.493 -                  *dp++ = *sp++;
 162.494 -                  *dp++ = *sp++;
 162.495 -               }
 162.496 -            }
 162.497 -            row_info->pixel_depth = 24;
 162.498 -            row_info->rowbytes = row_width * 3;
 162.499 +            /* Copy 6 bytes, skip 2 */
 162.500 +            *dp++ = *sp++, *dp++ = *sp++;
 162.501 +            *dp++ = *sp++, *dp++ = *sp++;
 162.502 +            *dp++ = *sp++, *dp++ = *sp, sp += 3;
 162.503           }
 162.504 -         else /* if (row_info->bit_depth == 16) */
 162.505 -         {
 162.506 -            if (flags & PNG_FLAG_FILLER_AFTER)
 162.507 -            {
 162.508 -               /* This converts from RRGGBBXX or RRGGBBAA to RRGGBB */
 162.509 -               sp += 8; dp += 6;
 162.510 -               for (i = 1; i < row_width; i++)
 162.511 -               {
 162.512 -                  /* This could be (although png_memcpy is probably slower):
 162.513 -                  png_memcpy(dp, sp, 6);
 162.514 -                  sp += 8;
 162.515 -                  dp += 6;
 162.516 -                  */
 162.517  
 162.518 -                  *dp++ = *sp++;
 162.519 -                  *dp++ = *sp++;
 162.520 -                  *dp++ = *sp++;
 162.521 -                  *dp++ = *sp++;
 162.522 -                  *dp++ = *sp++;
 162.523 -                  *dp++ = *sp++;
 162.524 -                  sp += 2;
 162.525 -               }
 162.526 -            }
 162.527 -            else
 162.528 -            {
 162.529 -               /* This converts from XXRRGGBB or AARRGGBB to RRGGBB */
 162.530 -               for (i = 0; i < row_width; i++)
 162.531 -               {
 162.532 -                  /* This could be (although png_memcpy is probably slower):
 162.533 -                  png_memcpy(dp, sp, 6);
 162.534 -                  sp += 8;
 162.535 -                  dp += 6;
 162.536 -                  */
 162.537 +         row_info->pixel_depth = 48;
 162.538 +      }
 162.539  
 162.540 -                  sp+=2;
 162.541 -                  *dp++ = *sp++;
 162.542 -                  *dp++ = *sp++;
 162.543 -                  *dp++ = *sp++;
 162.544 -                  *dp++ = *sp++;
 162.545 -                  *dp++ = *sp++;
 162.546 -                  *dp++ = *sp++;
 162.547 -               }
 162.548 -            }
 162.549 -            row_info->pixel_depth = 48;
 162.550 -            row_info->rowbytes = row_width * 6;
 162.551 -         }
 162.552 -         row_info->channels = 3;
 162.553 -      }
 162.554 -      else if ((row_info->color_type == PNG_COLOR_TYPE_GRAY ||
 162.555 -         (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
 162.556 -         (flags & PNG_FLAG_STRIP_ALPHA))) &&
 162.557 -          row_info->channels == 2)
 162.558 -      {
 162.559 -         if (row_info->bit_depth == 8)
 162.560 -         {
 162.561 -            /* This converts from GX or GA to G */
 162.562 -            if (flags & PNG_FLAG_FILLER_AFTER)
 162.563 -            {
 162.564 -               for (i = 0; i < row_width; i++)
 162.565 -               {
 162.566 -                  *dp++ = *sp++;
 162.567 -                  sp++;
 162.568 -               }
 162.569 -            }
 162.570 -            /* This converts from XG or AG to G */
 162.571 -            else
 162.572 -            {
 162.573 -               for (i = 0; i < row_width; i++)
 162.574 -               {
 162.575 -                  sp++;
 162.576 -                  *dp++ = *sp++;
 162.577 -               }
 162.578 -            }
 162.579 -            row_info->pixel_depth = 8;
 162.580 -            row_info->rowbytes = row_width;
 162.581 -         }
 162.582 -         else /* if (row_info->bit_depth == 16) */
 162.583 -         {
 162.584 -            if (flags & PNG_FLAG_FILLER_AFTER)
 162.585 -            {
 162.586 -               /* This converts from GGXX or GGAA to GG */
 162.587 -               sp += 4; dp += 2;
 162.588 -               for (i = 1; i < row_width; i++)
 162.589 -               {
 162.590 -                  *dp++ = *sp++;
 162.591 -                  *dp++ = *sp++;
 162.592 -                  sp += 2;
 162.593 -               }
 162.594 -            }
 162.595 -            else
 162.596 -            {
 162.597 -               /* This converts from XXGG or AAGG to GG */
 162.598 -               for (i = 0; i < row_width; i++)
 162.599 -               {
 162.600 -                  sp += 2;
 162.601 -                  *dp++ = *sp++;
 162.602 -                  *dp++ = *sp++;
 162.603 -               }
 162.604 -            }
 162.605 -            row_info->pixel_depth = 16;
 162.606 -            row_info->rowbytes = row_width * 2;
 162.607 -         }
 162.608 -         row_info->channels = 1;
 162.609 -      }
 162.610 -      if (flags & PNG_FLAG_STRIP_ALPHA)
 162.611 -        row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
 162.612 +      else
 162.613 +         return; /* bad bit depth */
 162.614 +
 162.615 +      row_info->channels = 3;
 162.616 +
 162.617 +      /* Finally fix the color type if it records an alpha channel */
 162.618 +      if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
 162.619 +         row_info->color_type = PNG_COLOR_TYPE_RGB;
 162.620     }
 162.621 +
 162.622 +   else
 162.623 +      return; /* The filler channel has gone already */
 162.624 +
 162.625 +   /* Fix the rowbytes value. */
 162.626 +   row_info->rowbytes = dp-row;
 162.627  }
 162.628  #endif
 162.629  
 162.630  #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
 162.631 -/* swaps red and blue bytes within a pixel */
 162.632 +/* Swaps red and blue bytes within a pixel */
 162.633  void /* PRIVATE */
 162.634  png_do_bgr(png_row_infop row_info, png_bytep row)
 162.635  {
 162.636 -   png_debug(1, "in png_do_bgr\n");
 162.637 -   if (
 162.638 -#if defined(PNG_USELESS_TESTS_SUPPORTED)
 162.639 -       row != NULL && row_info != NULL &&
 162.640 -#endif
 162.641 -       (row_info->color_type & PNG_COLOR_MASK_COLOR))
 162.642 +   png_debug(1, "in png_do_bgr");
 162.643 +
 162.644 +   if ((row_info->color_type & PNG_COLOR_MASK_COLOR))
 162.645     {
 162.646        png_uint_32 row_width = row_info->width;
 162.647        if (row_info->bit_depth == 8)
 162.648 @@ -603,6 +592,7 @@
 162.649                 *(rp + 2) = save;
 162.650              }
 162.651           }
 162.652 +
 162.653           else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
 162.654           {
 162.655              png_bytep rp;
 162.656 @@ -616,6 +606,8 @@
 162.657              }
 162.658           }
 162.659        }
 162.660 +
 162.661 +#ifdef PNG_16BIT_SUPPORTED
 162.662        else if (row_info->bit_depth == 16)
 162.663        {
 162.664           if (row_info->color_type == PNG_COLOR_TYPE_RGB)
 162.665 @@ -633,6 +625,7 @@
 162.666                 *(rp + 5) = save;
 162.667              }
 162.668           }
 162.669 +
 162.670           else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
 162.671           {
 162.672              png_bytep rp;
 162.673 @@ -649,28 +642,25 @@
 162.674              }
 162.675           }
 162.676        }
 162.677 +#endif
 162.678     }
 162.679  }
 162.680  #endif /* PNG_READ_BGR_SUPPORTED or PNG_WRITE_BGR_SUPPORTED */
 162.681  
 162.682  #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
 162.683 -    defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
 162.684 -    defined(PNG_LEGACY_SUPPORTED)
 162.685 +    defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
 162.686 +#ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED
 162.687  void PNGAPI
 162.688  png_set_user_transform_info(png_structp png_ptr, png_voidp
 162.689     user_transform_ptr, int user_transform_depth, int user_transform_channels)
 162.690  {
 162.691 -   png_debug(1, "in png_set_user_transform_info\n");
 162.692 -   if(png_ptr == NULL) return;
 162.693 -#if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
 162.694 +   png_debug(1, "in png_set_user_transform_info");
 162.695 +
 162.696 +   if (png_ptr == NULL)
 162.697 +      return;
 162.698     png_ptr->user_transform_ptr = user_transform_ptr;
 162.699     png_ptr->user_transform_depth = (png_byte)user_transform_depth;
 162.700     png_ptr->user_transform_channels = (png_byte)user_transform_channels;
 162.701 -#else
 162.702 -   if(user_transform_ptr || user_transform_depth || user_transform_channels)
 162.703 -      png_warning(png_ptr,
 162.704 -        "This version of libpng does not support user transform info");
 162.705 -#endif
 162.706  }
 162.707  #endif
 162.708  
 162.709 @@ -679,14 +669,38 @@
 162.710   * associated with this pointer before png_write_destroy and png_read_destroy
 162.711   * are called.
 162.712   */
 162.713 +#ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED
 162.714  png_voidp PNGAPI
 162.715 -png_get_user_transform_ptr(png_structp png_ptr)
 162.716 +png_get_user_transform_ptr(png_const_structp png_ptr)
 162.717  {
 162.718 -#if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
 162.719 -   if (png_ptr == NULL) return (NULL);
 162.720 +   if (png_ptr == NULL)
 162.721 +      return (NULL);
 162.722 +
 162.723     return ((png_voidp)png_ptr->user_transform_ptr);
 162.724 -#else
 162.725 -   return (NULL);
 162.726 +}
 162.727  #endif
 162.728 +
 162.729 +#ifdef PNG_USER_TRANSFORM_INFO_SUPPORTED
 162.730 +png_uint_32 PNGAPI
 162.731 +png_get_current_row_number(png_const_structp png_ptr)
 162.732 +{
 162.733 +   /* See the comments in png.h - this is the sub-image row when reading and
 162.734 +    * interlaced image.
 162.735 +    */
 162.736 +   if (png_ptr != NULL)
 162.737 +      return png_ptr->row_number;
 162.738 +
 162.739 +   return PNG_UINT_32_MAX; /* help the app not to fail silently */
 162.740  }
 162.741 +
 162.742 +png_byte PNGAPI
 162.743 +png_get_current_pass_number(png_const_structp png_ptr)
 162.744 +{
 162.745 +   if (png_ptr != NULL)
 162.746 +      return png_ptr->pass;
 162.747 +   return 8; /* invalid */
 162.748 +}
 162.749 +#endif /* PNG_USER_TRANSFORM_INFO_SUPPORTED */
 162.750 +#endif /* PNG_READ_USER_TRANSFORM_SUPPORTED ||
 162.751 +          PNG_WRITE_USER_TRANSFORM_SUPPORTED */
 162.752  #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
   163.1 --- a/src/share/native/sun/awt/libpng/pngvcrd.c	Fri Sep 30 17:20:56 2011 -0700
   163.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
   163.3 @@ -1,3932 +0,0 @@
   163.4 -/*
   163.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   163.6 - *
   163.7 - * This code is free software; you can redistribute it and/or modify it
   163.8 - * under the terms of the GNU General Public License version 2 only, as
   163.9 - * published by the Free Software Foundation.  Oracle designates this
  163.10 - * particular file as subject to the "Classpath" exception as provided
  163.11 - * by Oracle in the LICENSE file that accompanied this code.
  163.12 - *
  163.13 - * This code is distributed in the hope that it will be useful, but WITHOUT
  163.14 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  163.15 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  163.16 - * version 2 for more details (a copy is included in the LICENSE file that
  163.17 - * accompanied this code).
  163.18 - *
  163.19 - * You should have received a copy of the GNU General Public License version
  163.20 - * 2 along with this work; if not, write to the Free Software Foundation,
  163.21 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  163.22 - *
  163.23 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  163.24 - * or visit www.oracle.com if you need additional information or have any
  163.25 - * questions.
  163.26 - */
  163.27 -
  163.28 -/* pngvcrd.c - mixed C/assembler version of utilities to read a PNG file
  163.29 - *
  163.30 - * This file is available under and governed by the GNU General Public
  163.31 - * License version 2 only, as published by the Free Software Foundation.
  163.32 - * However, the following notice accompanied the original version of this
  163.33 - * file and, per its terms, should not be removed:
  163.34 - *
  163.35 - * For Intel x86 CPU and Microsoft Visual C++ compiler
  163.36 - *
  163.37 - * Last changed in libpng 1.2.6 - August 15, 2004
  163.38 - * For conditions of distribution and use, see copyright notice in png.h
  163.39 - * Copyright (c) 1998-2004 Glenn Randers-Pehrson
  163.40 - * Copyright (c) 1998, Intel Corporation
  163.41 - *
  163.42 - * Contributed by Nirav Chhatrapati, Intel Corporation, 1998
  163.43 - * Interface to libpng contributed by Gilles Vollant, 1999
  163.44 - *
  163.45 - *
  163.46 - * In png_do_read_interlace() in libpng versions 1.0.3a through 1.0.4d,
  163.47 - * a sign error in the post-MMX cleanup code for each pixel_depth resulted
  163.48 - * in bad pixels at the beginning of some rows of some images, and also
  163.49 - * (due to out-of-range memory reads and writes) caused heap corruption
  163.50 - * when compiled with MSVC 6.0.  The error was fixed in version 1.0.4e.
  163.51 - *
  163.52 - * [png_read_filter_row_mmx_avg() bpp == 2 bugfix, GRR 20000916]
  163.53 - *
  163.54 - * [runtime MMX configuration, GRR 20010102]
  163.55 - *
  163.56 - */
  163.57 -
  163.58 -#define PNG_INTERNAL
  163.59 -#include "png.h"
  163.60 -
  163.61 -#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) && defined(PNG_USE_PNGVCRD)
  163.62 -
  163.63 -static int mmx_supported=2;
  163.64 -
  163.65 -
  163.66 -int PNGAPI
  163.67 -png_mmx_support(void)
  163.68 -{
  163.69 -  int mmx_supported_local = 0;
  163.70 -  _asm {
  163.71 -    push ebx          //CPUID will trash these
  163.72 -    push ecx
  163.73 -    push edx
  163.74 -
  163.75 -    pushfd            //Save Eflag to stack
  163.76 -    pop eax           //Get Eflag from stack into eax
  163.77 -    mov ecx, eax      //Make another copy of Eflag in ecx
  163.78 -    xor eax, 0x200000 //Toggle ID bit in Eflag [i.e. bit(21)]
  163.79 -    push eax          //Save modified Eflag back to stack
  163.80 -
  163.81 -    popfd             //Restored modified value back to Eflag reg
  163.82 -    pushfd            //Save Eflag to stack
  163.83 -    pop eax           //Get Eflag from stack
  163.84 -    push ecx          // save original Eflag to stack
  163.85 -    popfd             // restore original Eflag
  163.86 -    xor eax, ecx      //Compare the new Eflag with the original Eflag
  163.87 -    jz NOT_SUPPORTED  //If the same, CPUID instruction is not supported,
  163.88 -                      //skip following instructions and jump to
  163.89 -                      //NOT_SUPPORTED label
  163.90 -
  163.91 -    xor eax, eax      //Set eax to zero
  163.92 -
  163.93 -    _asm _emit 0x0f   //CPUID instruction  (two bytes opcode)
  163.94 -    _asm _emit 0xa2
  163.95 -
  163.96 -    cmp eax, 1        //make sure eax return non-zero value
  163.97 -    jl NOT_SUPPORTED  //If eax is zero, mmx not supported
  163.98 -
  163.99 -    xor eax, eax      //set eax to zero
 163.100 -    inc eax           //Now increment eax to 1.  This instruction is
 163.101 -                      //faster than the instruction "mov eax, 1"
 163.102 -
 163.103 -    _asm _emit 0x0f   //CPUID instruction
 163.104 -    _asm _emit 0xa2
 163.105 -
 163.106 -    and edx, 0x00800000  //mask out all bits but mmx bit(24)
 163.107 -    cmp edx, 0        // 0 = mmx not supported
 163.108 -    jz  NOT_SUPPORTED // non-zero = Yes, mmx IS supported
 163.109 -
 163.110 -    mov  mmx_supported_local, 1  //set return value to 1
 163.111 -
 163.112 -NOT_SUPPORTED:
 163.113 -    mov  eax, mmx_supported_local  //move return value to eax
 163.114 -    pop edx          //CPUID trashed these
 163.115 -    pop ecx
 163.116 -    pop ebx
 163.117 -  }
 163.118 -
 163.119 -  //mmx_supported_local=0; // test code for force don't support MMX
 163.120 -  //printf("MMX : %u (1=MMX supported)\n",mmx_supported_local);
 163.121 -
 163.122 -  mmx_supported = mmx_supported_local;
 163.123 -  return mmx_supported_local;
 163.124 -}
 163.125 -
 163.126 -/* Combines the row recently read in with the previous row.
 163.127 -   This routine takes care of alpha and transparency if requested.
 163.128 -   This routine also handles the two methods of progressive display
 163.129 -   of interlaced images, depending on the mask value.
 163.130 -   The mask value describes which pixels are to be combined with
 163.131 -   the row.  The pattern always repeats every 8 pixels, so just 8
 163.132 -   bits are needed.  A one indicates the pixel is to be combined; a
 163.133 -   zero indicates the pixel is to be skipped.  This is in addition
 163.134 -   to any alpha or transparency value associated with the pixel.  If
 163.135 -   you want all pixels to be combined, pass 0xff (255) in mask.  */
 163.136 -
 163.137 -/* Use this routine for x86 platform - uses faster MMX routine if machine
 163.138 -   supports MMX */
 163.139 -
 163.140 -void /* PRIVATE */
 163.141 -png_combine_row(png_structp png_ptr, png_bytep row, int mask)
 163.142 -{
 163.143 -#ifdef PNG_USE_LOCAL_ARRAYS
 163.144 -   const int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
 163.145 -#endif
 163.146 -
 163.147 -   png_debug(1,"in png_combine_row_asm\n");
 163.148 -
 163.149 -   if (mmx_supported == 2) {
 163.150 -#if !defined(PNG_1_0_X)
 163.151 -       /* this should have happened in png_init_mmx_flags() already */
 163.152 -       png_warning(png_ptr, "asm_flags may not have been initialized");
 163.153 -#endif
 163.154 -       png_mmx_support();
 163.155 -   }
 163.156 -
 163.157 -   if (mask == 0xff)
 163.158 -   {
 163.159 -      png_memcpy(row, png_ptr->row_buf + 1,
 163.160 -       (png_size_t)PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
 163.161 -       png_ptr->width));
 163.162 -   }
 163.163 -   /* GRR:  add "else if (mask == 0)" case?
 163.164 -    *       or does png_combine_row() not even get called in that case? */
 163.165 -   else
 163.166 -   {
 163.167 -      switch (png_ptr->row_info.pixel_depth)
 163.168 -      {
 163.169 -         case 1:
 163.170 -         {
 163.171 -            png_bytep sp;
 163.172 -            png_bytep dp;
 163.173 -            int s_inc, s_start, s_end;
 163.174 -            int m;
 163.175 -            int shift;
 163.176 -            png_uint_32 i;
 163.177 -
 163.178 -            sp = png_ptr->row_buf + 1;
 163.179 -            dp = row;
 163.180 -            m = 0x80;
 163.181 -#if defined(PNG_READ_PACKSWAP_SUPPORTED)
 163.182 -            if (png_ptr->transformations & PNG_PACKSWAP)
 163.183 -            {
 163.184 -                s_start = 0;
 163.185 -                s_end = 7;
 163.186 -                s_inc = 1;
 163.187 -            }
 163.188 -            else
 163.189 -#endif
 163.190 -            {
 163.191 -                s_start = 7;
 163.192 -                s_end = 0;
 163.193 -                s_inc = -1;
 163.194 -            }
 163.195 -
 163.196 -            shift = s_start;
 163.197 -
 163.198 -            for (i = 0; i < png_ptr->width; i++)
 163.199 -            {
 163.200 -               if (m & mask)
 163.201 -               {
 163.202 -                  int value;
 163.203 -
 163.204 -                  value = (*sp >> shift) & 0x1;
 163.205 -                  *dp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
 163.206 -                  *dp |= (png_byte)(value << shift);
 163.207 -               }
 163.208 -
 163.209 -               if (shift == s_end)
 163.210 -               {
 163.211 -                  shift = s_start;
 163.212 -                  sp++;
 163.213 -                  dp++;
 163.214 -               }
 163.215 -               else
 163.216 -                  shift += s_inc;
 163.217 -
 163.218 -               if (m == 1)
 163.219 -                  m = 0x80;
 163.220 -               else
 163.221 -                  m >>= 1;
 163.222 -            }
 163.223 -            break;
 163.224 -         }
 163.225 -
 163.226 -         case 2:
 163.227 -         {
 163.228 -            png_bytep sp;
 163.229 -            png_bytep dp;
 163.230 -            int s_start, s_end, s_inc;
 163.231 -            int m;
 163.232 -            int shift;
 163.233 -            png_uint_32 i;
 163.234 -            int value;
 163.235 -
 163.236 -            sp = png_ptr->row_buf + 1;
 163.237 -            dp = row;
 163.238 -            m = 0x80;
 163.239 -#if defined(PNG_READ_PACKSWAP_SUPPORTED)
 163.240 -            if (png_ptr->transformations & PNG_PACKSWAP)
 163.241 -            {
 163.242 -               s_start = 0;
 163.243 -               s_end = 6;
 163.244 -               s_inc = 2;
 163.245 -            }
 163.246 -            else
 163.247 -#endif
 163.248 -            {
 163.249 -               s_start = 6;
 163.250 -               s_end = 0;
 163.251 -               s_inc = -2;
 163.252 -            }
 163.253 -
 163.254 -            shift = s_start;
 163.255 -
 163.256 -            for (i = 0; i < png_ptr->width; i++)
 163.257 -            {
 163.258 -               if (m & mask)
 163.259 -               {
 163.260 -                  value = (*sp >> shift) & 0x3;
 163.261 -                  *dp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
 163.262 -                  *dp |= (png_byte)(value << shift);
 163.263 -               }
 163.264 -
 163.265 -               if (shift == s_end)
 163.266 -               {
 163.267 -                  shift = s_start;
 163.268 -                  sp++;
 163.269 -                  dp++;
 163.270 -               }
 163.271 -               else
 163.272 -                  shift += s_inc;
 163.273 -               if (m == 1)
 163.274 -                  m = 0x80;
 163.275 -               else
 163.276 -                  m >>= 1;
 163.277 -            }
 163.278 -            break;
 163.279 -         }
 163.280 -
 163.281 -         case 4:
 163.282 -         {
 163.283 -            png_bytep sp;
 163.284 -            png_bytep dp;
 163.285 -            int s_start, s_end, s_inc;
 163.286 -            int m;
 163.287 -            int shift;
 163.288 -            png_uint_32 i;
 163.289 -            int value;
 163.290 -
 163.291 -            sp = png_ptr->row_buf + 1;
 163.292 -            dp = row;
 163.293 -            m = 0x80;
 163.294 -#if defined(PNG_READ_PACKSWAP_SUPPORTED)
 163.295 -            if (png_ptr->transformations & PNG_PACKSWAP)
 163.296 -            {
 163.297 -               s_start = 0;
 163.298 -               s_end = 4;
 163.299 -               s_inc = 4;
 163.300 -            }
 163.301 -            else
 163.302 -#endif
 163.303 -            {
 163.304 -               s_start = 4;
 163.305 -               s_end = 0;
 163.306 -               s_inc = -4;
 163.307 -            }
 163.308 -            shift = s_start;
 163.309 -
 163.310 -            for (i = 0; i < png_ptr->width; i++)
 163.311 -            {
 163.312 -               if (m & mask)
 163.313 -               {
 163.314 -                  value = (*sp >> shift) & 0xf;
 163.315 -                  *dp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
 163.316 -                  *dp |= (png_byte)(value << shift);
 163.317 -               }
 163.318 -
 163.319 -               if (shift == s_end)
 163.320 -               {
 163.321 -                  shift = s_start;
 163.322 -                  sp++;
 163.323 -                  dp++;
 163.324 -               }
 163.325 -               else
 163.326 -                  shift += s_inc;
 163.327 -               if (m == 1)
 163.328 -                  m = 0x80;
 163.329 -               else
 163.330 -                  m >>= 1;
 163.331 -            }
 163.332 -            break;
 163.333 -         }
 163.334 -
 163.335 -         case 8:
 163.336 -         {
 163.337 -            png_bytep srcptr;
 163.338 -            png_bytep dstptr;
 163.339 -            png_uint_32 len;
 163.340 -            int m;
 163.341 -            int diff, unmask;
 163.342 -
 163.343 -            __int64 mask0=0x0102040810204080;
 163.344 -
 163.345 -#if !defined(PNG_1_0_X)
 163.346 -            if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)
 163.347 -                /* && mmx_supported */ )
 163.348 -#else
 163.349 -            if (mmx_supported)
 163.350 -#endif
 163.351 -            {
 163.352 -               srcptr = png_ptr->row_buf + 1;
 163.353 -               dstptr = row;
 163.354 -               m = 0x80;
 163.355 -               unmask = ~mask;
 163.356 -               len  = png_ptr->width &~7;  //reduce to multiple of 8
 163.357 -               diff = png_ptr->width & 7;  //amount lost
 163.358 -
 163.359 -               _asm
 163.360 -               {
 163.361 -                  movd       mm7, unmask   //load bit pattern
 163.362 -                  psubb      mm6,mm6       //zero mm6
 163.363 -                  punpcklbw  mm7,mm7
 163.364 -                  punpcklwd  mm7,mm7
 163.365 -                  punpckldq  mm7,mm7       //fill register with 8 masks
 163.366 -
 163.367 -                  movq       mm0,mask0
 163.368 -
 163.369 -                  pand       mm0,mm7       //nonzero if keep byte
 163.370 -                  pcmpeqb    mm0,mm6       //zeros->1s, v versa
 163.371 -
 163.372 -                  mov        ecx,len       //load length of line (pixels)
 163.373 -                  mov        esi,srcptr    //load source
 163.374 -                  mov        ebx,dstptr    //load dest
 163.375 -                  cmp        ecx,0         //lcr
 163.376 -                  je         mainloop8end
 163.377 -
 163.378 -mainloop8:
 163.379 -                  movq       mm4,[esi]
 163.380 -                  pand       mm4,mm0
 163.381 -                  movq       mm6,mm0
 163.382 -                  pandn      mm6,[ebx]
 163.383 -                  por        mm4,mm6
 163.384 -                  movq       [ebx],mm4
 163.385 -
 163.386 -                  add        esi,8         //inc by 8 bytes processed
 163.387 -                  add        ebx,8
 163.388 -                  sub        ecx,8         //dec by 8 pixels processed
 163.389 -
 163.390 -                  ja         mainloop8
 163.391 -mainloop8end:
 163.392 -
 163.393 -                  mov        ecx,diff
 163.394 -                  cmp        ecx,0
 163.395 -                  jz         end8
 163.396 -
 163.397 -                  mov        edx,mask
 163.398 -                  sal        edx,24        //make low byte the high byte
 163.399 -
 163.400 -secondloop8:
 163.401 -                  sal        edx,1         //move high bit to CF
 163.402 -                  jnc        skip8         //if CF = 0
 163.403 -                  mov        al,[esi]
 163.404 -                  mov        [ebx],al
 163.405 -skip8:
 163.406 -                  inc        esi
 163.407 -                  inc        ebx
 163.408 -
 163.409 -                  dec        ecx
 163.410 -                  jnz        secondloop8
 163.411 -end8:
 163.412 -                  emms
 163.413 -               }
 163.414 -            }
 163.415 -            else /* mmx not supported - use modified C routine */
 163.416 -            {
 163.417 -               register unsigned int incr1, initial_val, final_val;
 163.418 -               png_size_t pixel_bytes;
 163.419 -               png_uint_32 i;
 163.420 -               register int disp = png_pass_inc[png_ptr->pass];
 163.421 -               int offset_table[7] = {0, 4, 0, 2, 0, 1, 0};
 163.422 -
 163.423 -               pixel_bytes = (png_ptr->row_info.pixel_depth >> 3);
 163.424 -               srcptr = png_ptr->row_buf + 1 + offset_table[png_ptr->pass]*
 163.425 -                  pixel_bytes;
 163.426 -               dstptr = row + offset_table[png_ptr->pass]*pixel_bytes;
 163.427 -               initial_val = offset_table[png_ptr->pass]*pixel_bytes;
 163.428 -               final_val = png_ptr->width*pixel_bytes;
 163.429 -               incr1 = (disp)*pixel_bytes;
 163.430 -               for (i = initial_val; i < final_val; i += incr1)
 163.431 -               {
 163.432 -                  png_memcpy(dstptr, srcptr, pixel_bytes);
 163.433 -                  srcptr += incr1;
 163.434 -                  dstptr += incr1;
 163.435 -               }
 163.436 -            } /* end of else */
 163.437 -
 163.438 -            break;
 163.439 -         }       // end 8 bpp
 163.440 -
 163.441 -         case 16:
 163.442 -         {
 163.443 -            png_bytep srcptr;
 163.444 -            png_bytep dstptr;
 163.445 -            png_uint_32 len;
 163.446 -            int unmask, diff;
 163.447 -            __int64 mask1=0x0101020204040808,
 163.448 -                    mask0=0x1010202040408080;
 163.449 -
 163.450 -#if !defined(PNG_1_0_X)
 163.451 -            if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)
 163.452 -                /* && mmx_supported */ )
 163.453 -#else
 163.454 -            if (mmx_supported)
 163.455 -#endif
 163.456 -            {
 163.457 -               srcptr = png_ptr->row_buf + 1;
 163.458 -               dstptr = row;
 163.459 -
 163.460 -               unmask = ~mask;
 163.461 -               len     = (png_ptr->width)&~7;
 163.462 -               diff = (png_ptr->width)&7;
 163.463 -               _asm
 163.464 -               {
 163.465 -                  movd       mm7, unmask       //load bit pattern
 163.466 -                  psubb      mm6,mm6           //zero mm6
 163.467 -                  punpcklbw  mm7,mm7
 163.468 -                  punpcklwd  mm7,mm7
 163.469 -                  punpckldq  mm7,mm7           //fill register with 8 masks
 163.470 -
 163.471 -                  movq       mm0,mask0
 163.472 -                  movq       mm1,mask1
 163.473 -
 163.474 -                  pand       mm0,mm7
 163.475 -                  pand       mm1,mm7
 163.476 -
 163.477 -                  pcmpeqb    mm0,mm6
 163.478 -                  pcmpeqb    mm1,mm6
 163.479 -
 163.480 -                  mov        ecx,len           //load length of line
 163.481 -                  mov        esi,srcptr        //load source
 163.482 -                  mov        ebx,dstptr        //load dest
 163.483 -                  cmp        ecx,0             //lcr
 163.484 -                  jz         mainloop16end
 163.485 -
 163.486 -mainloop16:
 163.487 -                  movq       mm4,[esi]
 163.488 -                  pand       mm4,mm0
 163.489 -                  movq       mm6,mm0
 163.490 -                  movq       mm7,[ebx]
 163.491 -                  pandn      mm6,mm7
 163.492 -                  por        mm4,mm6
 163.493 -                  movq       [ebx],mm4
 163.494 -
 163.495 -                  movq       mm5,[esi+8]
 163.496 -                  pand       mm5,mm1
 163.497 -                  movq       mm7,mm1
 163.498 -                  movq       mm6,[ebx+8]
 163.499 -                  pandn      mm7,mm6
 163.500 -                  por        mm5,mm7
 163.501 -                  movq       [ebx+8],mm5
 163.502 -
 163.503 -                  add        esi,16            //inc by 16 bytes processed
 163.504 -                  add        ebx,16
 163.505 -                  sub        ecx,8             //dec by 8 pixels processed
 163.506 -
 163.507 -                  ja         mainloop16
 163.508 -
 163.509 -mainloop16end:
 163.510 -                  mov        ecx,diff
 163.511 -                  cmp        ecx,0
 163.512 -                  jz         end16
 163.513 -
 163.514 -                  mov        edx,mask
 163.515 -                  sal        edx,24            //make low byte the high byte
 163.516 -secondloop16:
 163.517 -                  sal        edx,1             //move high bit to CF
 163.518 -                  jnc        skip16            //if CF = 0
 163.519 -                  mov        ax,[esi]
 163.520 -                  mov        [ebx],ax
 163.521 -skip16:
 163.522 -                  add        esi,2
 163.523 -                  add        ebx,2
 163.524 -
 163.525 -                  dec        ecx
 163.526 -                  jnz        secondloop16
 163.527 -end16:
 163.528 -                  emms
 163.529 -               }
 163.530 -            }
 163.531 -            else /* mmx not supported - use modified C routine */
 163.532 -            {
 163.533 -               register unsigned int incr1, initial_val, final_val;
 163.534 -               png_size_t pixel_bytes;
 163.535 -               png_uint_32 i;
 163.536 -               register int disp = png_pass_inc[png_ptr->pass];
 163.537 -               int offset_table[7] = {0, 4, 0, 2, 0, 1, 0};
 163.538 -
 163.539 -               pixel_bytes = (png_ptr->row_info.pixel_depth >> 3);
 163.540 -               srcptr = png_ptr->row_buf + 1 + offset_table[png_ptr->pass]*
 163.541 -                  pixel_bytes;
 163.542 -               dstptr = row + offset_table[png_ptr->pass]*pixel_bytes;
 163.543 -               initial_val = offset_table[png_ptr->pass]*pixel_bytes;
 163.544 -               final_val = png_ptr->width*pixel_bytes;
 163.545 -               incr1 = (disp)*pixel_bytes;
 163.546 -               for (i = initial_val; i < final_val; i += incr1)
 163.547 -               {
 163.548 -                  png_memcpy(dstptr, srcptr, pixel_bytes);
 163.549 -                  srcptr += incr1;
 163.550 -                  dstptr += incr1;
 163.551 -               }
 163.552 -            } /* end of else */
 163.553 -
 163.554 -            break;
 163.555 -         }       // end 16 bpp
 163.556 -
 163.557 -         case 24:
 163.558 -         {
 163.559 -            png_bytep srcptr;
 163.560 -            png_bytep dstptr;
 163.561 -            png_uint_32 len;
 163.562 -            int unmask, diff;
 163.563 -
 163.564 -            __int64 mask2=0x0101010202020404,  //24bpp
 163.565 -                    mask1=0x0408080810101020,
 163.566 -                    mask0=0x2020404040808080;
 163.567 -
 163.568 -            srcptr = png_ptr->row_buf + 1;
 163.569 -            dstptr = row;
 163.570 -
 163.571 -            unmask = ~mask;
 163.572 -            len     = (png_ptr->width)&~7;
 163.573 -            diff = (png_ptr->width)&7;
 163.574 -
 163.575 -#if !defined(PNG_1_0_X)
 163.576 -            if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)
 163.577 -                /* && mmx_supported */ )
 163.578 -#else
 163.579 -            if (mmx_supported)
 163.580 -#endif
 163.581 -            {
 163.582 -               _asm
 163.583 -               {
 163.584 -                  movd       mm7, unmask       //load bit pattern
 163.585 -                  psubb      mm6,mm6           //zero mm6
 163.586 -                  punpcklbw  mm7,mm7
 163.587 -                  punpcklwd  mm7,mm7
 163.588 -                  punpckldq  mm7,mm7           //fill register with 8 masks
 163.589 -
 163.590 -                  movq       mm0,mask0
 163.591 -                  movq       mm1,mask1
 163.592 -                  movq       mm2,mask2
 163.593 -
 163.594 -                  pand       mm0,mm7
 163.595 -                  pand       mm1,mm7
 163.596 -                  pand       mm2,mm7
 163.597 -
 163.598 -                  pcmpeqb    mm0,mm6
 163.599 -                  pcmpeqb    mm1,mm6
 163.600 -                  pcmpeqb    mm2,mm6
 163.601 -
 163.602 -                  mov        ecx,len           //load length of line
 163.603 -                  mov        esi,srcptr        //load source
 163.604 -                  mov        ebx,dstptr        //load dest
 163.605 -                  cmp        ecx,0
 163.606 -                  jz         mainloop24end
 163.607 -
 163.608 -mainloop24:
 163.609 -                  movq       mm4,[esi]
 163.610 -                  pand       mm4,mm0
 163.611 -                  movq       mm6,mm0
 163.612 -                  movq       mm7,[ebx]
 163.613 -                  pandn      mm6,mm7
 163.614 -                  por        mm4,mm6
 163.615 -                  movq       [ebx],mm4
 163.616 -
 163.617 -
 163.618 -                  movq       mm5,[esi+8]
 163.619 -                  pand       mm5,mm1
 163.620 -                  movq       mm7,mm1
 163.621 -                  movq       mm6,[ebx+8]
 163.622 -                  pandn      mm7,mm6
 163.623 -                  por        mm5,mm7
 163.624 -                  movq       [ebx+8],mm5
 163.625 -
 163.626 -                  movq       mm6,[esi+16]
 163.627 -                  pand       mm6,mm2
 163.628 -                  movq       mm4,mm2
 163.629 -                  movq       mm7,[ebx+16]
 163.630 -                  pandn      mm4,mm7
 163.631 -                  por        mm6,mm4
 163.632 -                  movq       [ebx+16],mm6
 163.633 -
 163.634 -                  add        esi,24            //inc by 24 bytes processed
 163.635 -                  add        ebx,24
 163.636 -                  sub        ecx,8             //dec by 8 pixels processed
 163.637 -
 163.638 -                  ja         mainloop24
 163.639 -
 163.640 -mainloop24end:
 163.641 -                  mov        ecx,diff
 163.642 -                  cmp        ecx,0
 163.643 -                  jz         end24
 163.644 -
 163.645 -                  mov        edx,mask
 163.646 -                  sal        edx,24            //make low byte the high byte
 163.647 -secondloop24:
 163.648 -                  sal        edx,1             //move high bit to CF
 163.649 -                  jnc        skip24            //if CF = 0
 163.650 -                  mov        ax,[esi]
 163.651 -                  mov        [ebx],ax
 163.652 -                  xor        eax,eax
 163.653 -                  mov        al,[esi+2]
 163.654 -                  mov        [ebx+2],al
 163.655 -skip24:
 163.656 -                  add        esi,3
 163.657 -                  add        ebx,3
 163.658 -
 163.659 -                  dec        ecx
 163.660 -                  jnz        secondloop24
 163.661 -
 163.662 -end24:
 163.663 -                  emms
 163.664 -               }
 163.665 -            }
 163.666 -            else /* mmx not supported - use modified C routine */
 163.667 -            {
 163.668 -               register unsigned int incr1, initial_val, final_val;
 163.669 -               png_size_t pixel_bytes;
 163.670 -               png_uint_32 i;
 163.671 -               register int disp = png_pass_inc[png_ptr->pass];
 163.672 -               int offset_table[7] = {0, 4, 0, 2, 0, 1, 0};
 163.673 -
 163.674 -               pixel_bytes = (png_ptr->row_info.pixel_depth >> 3);
 163.675 -               srcptr = png_ptr->row_buf + 1 + offset_table[png_ptr->pass]*
 163.676 -                  pixel_bytes;
 163.677 -               dstptr = row + offset_table[png_ptr->pass]*pixel_bytes;
 163.678 -               initial_val = offset_table[png_ptr->pass]*pixel_bytes;
 163.679 -               final_val = png_ptr->width*pixel_bytes;
 163.680 -               incr1 = (disp)*pixel_bytes;
 163.681 -               for (i = initial_val; i < final_val; i += incr1)
 163.682 -               {
 163.683 -                  png_memcpy(dstptr, srcptr, pixel_bytes);
 163.684 -                  srcptr += incr1;
 163.685 -                  dstptr += incr1;
 163.686 -               }
 163.687 -            } /* end of else */
 163.688 -
 163.689 -            break;
 163.690 -         }       // end 24 bpp
 163.691 -
 163.692 -         case 32:
 163.693 -         {
 163.694 -            png_bytep srcptr;
 163.695 -            png_bytep dstptr;
 163.696 -            png_uint_32 len;
 163.697 -            int unmask, diff;
 163.698 -
 163.699 -            __int64 mask3=0x0101010102020202,  //32bpp
 163.700 -                    mask2=0x0404040408080808,
 163.701 -                    mask1=0x1010101020202020,
 163.702 -                    mask0=0x4040404080808080;
 163.703 -
 163.704 -            srcptr = png_ptr->row_buf + 1;
 163.705 -            dstptr = row;
 163.706 -
 163.707 -            unmask = ~mask;
 163.708 -            len     = (png_ptr->width)&~7;
 163.709 -            diff = (png_ptr->width)&7;
 163.710 -
 163.711 -#if !defined(PNG_1_0_X)
 163.712 -            if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)
 163.713 -                /* && mmx_supported */ )
 163.714 -#else
 163.715 -            if (mmx_supported)
 163.716 -#endif
 163.717 -            {
 163.718 -               _asm
 163.719 -               {
 163.720 -                  movd       mm7, unmask       //load bit pattern
 163.721 -                  psubb      mm6,mm6           //zero mm6
 163.722 -                  punpcklbw  mm7,mm7
 163.723 -                  punpcklwd  mm7,mm7
 163.724 -                  punpckldq  mm7,mm7           //fill register with 8 masks
 163.725 -
 163.726 -                  movq       mm0,mask0
 163.727 -                  movq       mm1,mask1
 163.728 -                  movq       mm2,mask2
 163.729 -                  movq       mm3,mask3
 163.730 -
 163.731 -                  pand       mm0,mm7
 163.732 -                  pand       mm1,mm7
 163.733 -                  pand       mm2,mm7
 163.734 -                  pand       mm3,mm7
 163.735 -
 163.736 -                  pcmpeqb    mm0,mm6
 163.737 -                  pcmpeqb    mm1,mm6
 163.738 -                  pcmpeqb    mm2,mm6
 163.739 -                  pcmpeqb    mm3,mm6
 163.740 -
 163.741 -                  mov        ecx,len           //load length of line
 163.742 -                  mov        esi,srcptr        //load source
 163.743 -                  mov        ebx,dstptr        //load dest
 163.744 -
 163.745 -                  cmp        ecx,0             //lcr
 163.746 -                  jz         mainloop32end
 163.747 -
 163.748 -mainloop32:
 163.749 -                  movq       mm4,[esi]
 163.750 -                  pand       mm4,mm0
 163.751 -                  movq       mm6,mm0
 163.752 -                  movq       mm7,[ebx]
 163.753 -                  pandn      mm6,mm7
 163.754 -                  por        mm4,mm6
 163.755 -                  movq       [ebx],mm4
 163.756 -
 163.757 -                  movq       mm5,[esi+8]
 163.758 -                  pand       mm5,mm1
 163.759 -                  movq       mm7,mm1
 163.760 -                  movq       mm6,[ebx+8]
 163.761 -                  pandn      mm7,mm6
 163.762 -                  por        mm5,mm7
 163.763 -                  movq       [ebx+8],mm5
 163.764 -
 163.765 -                  movq       mm6,[esi+16]
 163.766 -                  pand       mm6,mm2
 163.767 -                  movq       mm4,mm2
 163.768 -                  movq       mm7,[ebx+16]
 163.769 -                  pandn      mm4,mm7
 163.770 -                  por        mm6,mm4
 163.771 -                  movq       [ebx+16],mm6
 163.772 -
 163.773 -                  movq       mm7,[esi+24]
 163.774 -                  pand       mm7,mm3
 163.775 -                  movq       mm5,mm3
 163.776 -                  movq       mm4,[ebx+24]
 163.777 -                  pandn      mm5,mm4
 163.778 -                  por        mm7,mm5
 163.779 -                  movq       [ebx+24],mm7
 163.780 -
 163.781 -                  add        esi,32            //inc by 32 bytes processed
 163.782 -                  add        ebx,32
 163.783 -                  sub        ecx,8             //dec by 8 pixels processed
 163.784 -
 163.785 -                  ja         mainloop32
 163.786 -
 163.787 -mainloop32end:
 163.788 -                  mov        ecx,diff
 163.789 -                  cmp        ecx,0
 163.790 -                  jz         end32
 163.791 -
 163.792 -                  mov        edx,mask
 163.793 -                  sal        edx,24            //make low byte the high byte
 163.794 -secondloop32:
 163.795 -                  sal        edx,1             //move high bit to CF
 163.796 -                  jnc        skip32            //if CF = 0
 163.797 -                  mov        eax,[esi]
 163.798 -                  mov        [ebx],eax
 163.799 -skip32:
 163.800 -                  add        esi,4
 163.801 -                  add        ebx,4
 163.802 -
 163.803 -                  dec        ecx
 163.804 -                  jnz        secondloop32
 163.805 -
 163.806 -end32:
 163.807 -                  emms
 163.808 -               }
 163.809 -            }
 163.810 -            else /* mmx _not supported - Use modified C routine */
 163.811 -            {
 163.812 -               register unsigned int incr1, initial_val, final_val;
 163.813 -               png_size_t pixel_bytes;
 163.814 -               png_uint_32 i;
 163.815 -               register int disp = png_pass_inc[png_ptr->pass];
 163.816 -               int offset_table[7] = {0, 4, 0, 2, 0, 1, 0};
 163.817 -
 163.818 -               pixel_bytes = (png_ptr->row_info.pixel_depth >> 3);
 163.819 -               srcptr = png_ptr->row_buf + 1 + offset_table[png_ptr->pass]*
 163.820 -                  pixel_bytes;
 163.821 -               dstptr = row + offset_table[png_ptr->pass]*pixel_bytes;
 163.822 -               initial_val = offset_table[png_ptr->pass]*pixel_bytes;
 163.823 -               final_val = png_ptr->width*pixel_bytes;
 163.824 -               incr1 = (disp)*pixel_bytes;
 163.825 -               for (i = initial_val; i < final_val; i += incr1)
 163.826 -               {
 163.827 -                  png_memcpy(dstptr, srcptr, pixel_bytes);
 163.828 -                  srcptr += incr1;
 163.829 -                  dstptr += incr1;
 163.830 -               }
 163.831 -            } /* end of else */
 163.832 -
 163.833 -            break;
 163.834 -         }       // end 32 bpp
 163.835 -
 163.836 -         case 48:
 163.837 -         {
 163.838 -            png_bytep srcptr;
 163.839 -            png_bytep dstptr;
 163.840 -            png_uint_32 len;
 163.841 -            int unmask, diff;
 163.842 -
 163.843 -            __int64 mask5=0x0101010101010202,
 163.844 -                    mask4=0x0202020204040404,
 163.845 -                    mask3=0x0404080808080808,
 163.846 -                    mask2=0x1010101010102020,
 163.847 -                    mask1=0x2020202040404040,
 163.848 -                    mask0=0x4040808080808080;
 163.849 -
 163.850 -#if !defined(PNG_1_0_X)
 163.851 -            if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)
 163.852 -                /* && mmx_supported */ )
 163.853 -#else
 163.854 -            if (mmx_supported)
 163.855 -#endif
 163.856 -            {
 163.857 -               srcptr = png_ptr->row_buf + 1;
 163.858 -               dstptr = row;
 163.859 -
 163.860 -               unmask = ~mask;
 163.861 -               len     = (png_ptr->width)&~7;
 163.862 -               diff = (png_ptr->width)&7;
 163.863 -               _asm
 163.864 -               {
 163.865 -                  movd       mm7, unmask       //load bit pattern
 163.866 -                  psubb      mm6,mm6           //zero mm6
 163.867 -                  punpcklbw  mm7,mm7
 163.868 -                  punpcklwd  mm7,mm7
 163.869 -                  punpckldq  mm7,mm7           //fill register with 8 masks
 163.870 -
 163.871 -                  movq       mm0,mask0
 163.872 -                  movq       mm1,mask1
 163.873 -                  movq       mm2,mask2
 163.874 -                  movq       mm3,mask3
 163.875 -                  movq       mm4,mask4
 163.876 -                  movq       mm5,mask5
 163.877 -
 163.878 -                  pand       mm0,mm7
 163.879 -                  pand       mm1,mm7
 163.880 -                  pand       mm2,mm7
 163.881 -                  pand       mm3,mm7
 163.882 -                  pand       mm4,mm7
 163.883 -                  pand       mm5,mm7
 163.884 -
 163.885 -                  pcmpeqb    mm0,mm6
 163.886 -                  pcmpeqb    mm1,mm6
 163.887 -                  pcmpeqb    mm2,mm6
 163.888 -                  pcmpeqb    mm3,mm6
 163.889 -                  pcmpeqb    mm4,mm6
 163.890 -                  pcmpeqb    mm5,mm6
 163.891 -
 163.892 -                  mov        ecx,len           //load length of line
 163.893 -                  mov        esi,srcptr        //load source
 163.894 -                  mov        ebx,dstptr        //load dest
 163.895 -
 163.896 -                  cmp        ecx,0
 163.897 -                  jz         mainloop48end
 163.898 -
 163.899 -mainloop48:
 163.900 -                  movq       mm7,[esi]
 163.901 -                  pand       mm7,mm0
 163.902 -                  movq       mm6,mm0
 163.903 -                  pandn      mm6,[ebx]
 163.904 -                  por        mm7,mm6
 163.905 -                  movq       [ebx],mm7
 163.906 -
 163.907 -                  movq       mm6,[esi+8]
 163.908 -                  pand       mm6,mm1
 163.909 -                  movq       mm7,mm1
 163.910 -                  pandn      mm7,[ebx+8]
 163.911 -                  por        mm6,mm7
 163.912 -                  movq       [ebx+8],mm6
 163.913 -
 163.914 -                  movq       mm6,[esi+16]
 163.915 -                  pand       mm6,mm2
 163.916 -                  movq       mm7,mm2
 163.917 -                  pandn      mm7,[ebx+16]
 163.918 -                  por        mm6,mm7
 163.919 -                  movq       [ebx+16],mm6
 163.920 -
 163.921 -                  movq       mm7,[esi+24]
 163.922 -                  pand       mm7,mm3
 163.923 -                  movq       mm6,mm3
 163.924 -                  pandn      mm6,[ebx+24]
 163.925 -                  por        mm7,mm6
 163.926 -                  movq       [ebx+24],mm7
 163.927 -
 163.928 -                  movq       mm6,[esi+32]
 163.929 -                  pand       mm6,mm4
 163.930 -                  movq       mm7,mm4
 163.931 -                  pandn      mm7,[ebx+32]
 163.932 -                  por        mm6,mm7
 163.933 -                  movq       [ebx+32],mm6
 163.934 -
 163.935 -                  movq       mm7,[esi+40]
 163.936 -                  pand       mm7,mm5
 163.937 -                  movq       mm6,mm5
 163.938 -                  pandn      mm6,[ebx+40]
 163.939 -                  por        mm7,mm6
 163.940 -                  movq       [ebx+40],mm7
 163.941 -
 163.942 -                  add        esi,48            //inc by 32 bytes processed
 163.943 -                  add        ebx,48
 163.944 -                  sub        ecx,8             //dec by 8 pixels processed
 163.945 -
 163.946 -                  ja         mainloop48
 163.947 -mainloop48end:
 163.948 -
 163.949 -                  mov        ecx,diff
 163.950 -                  cmp        ecx,0
 163.951 -                  jz         end48
 163.952 -
 163.953 -                  mov        edx,mask
 163.954 -                  sal        edx,24            //make low byte the high byte
 163.955 -
 163.956 -secondloop48:
 163.957 -                  sal        edx,1             //move high bit to CF
 163.958 -                  jnc        skip48            //if CF = 0
 163.959 -                  mov        eax,[esi]
 163.960 -                  mov        [ebx],eax
 163.961 -skip48:
 163.962 -                  add        esi,4
 163.963 -                  add        ebx,4
 163.964 -
 163.965 -                  dec        ecx
 163.966 -                  jnz        secondloop48
 163.967 -
 163.968 -end48:
 163.969 -                  emms
 163.970 -               }
 163.971 -            }
 163.972 -            else /* mmx _not supported - Use modified C routine */
 163.973 -            {
 163.974 -               register unsigned int incr1, initial_val, final_val;
 163.975 -               png_size_t pixel_bytes;
 163.976 -               png_uint_32 i;
 163.977 -               register int disp = png_pass_inc[png_ptr->pass];
 163.978 -               int offset_table[7] = {0, 4, 0, 2, 0, 1, 0};
 163.979 -
 163.980 -               pixel_bytes = (png_ptr->row_info.pixel_depth >> 3);
 163.981 -               srcptr = png_ptr->row_buf + 1 + offset_table[png_ptr->pass]*
 163.982 -                  pixel_bytes;
 163.983 -               dstptr = row + offset_table[png_ptr->pass]*pixel_bytes;
 163.984 -               initial_val = offset_table[png_ptr->pass]*pixel_bytes;
 163.985 -               final_val = png_ptr->width*pixel_bytes;
 163.986 -               incr1 = (disp)*pixel_bytes;
 163.987 -               for (i = initial_val; i < final_val; i += incr1)
 163.988 -               {
 163.989 -                  png_memcpy(dstptr, srcptr, pixel_bytes);
 163.990 -                  srcptr += incr1;
 163.991 -                  dstptr += incr1;
 163.992 -               }
 163.993 -            } /* end of else */
 163.994 -
 163.995 -            break;
 163.996 -         }       // end 48 bpp
 163.997 -
 163.998 -         default:
 163.999 -         {
163.1000 -            png_bytep sptr;
163.1001 -            png_bytep dp;
163.1002 -            png_size_t pixel_bytes;
163.1003 -            int offset_table[7] = {0, 4, 0, 2, 0, 1, 0};
163.1004 -            unsigned int i;
163.1005 -            register int disp = png_pass_inc[png_ptr->pass];  // get the offset
163.1006 -            register unsigned int incr1, initial_val, final_val;
163.1007 -
163.1008 -            pixel_bytes = (png_ptr->row_info.pixel_depth >> 3);
163.1009 -            sptr = png_ptr->row_buf + 1 + offset_table[png_ptr->pass]*
163.1010 -               pixel_bytes;
163.1011 -            dp = row + offset_table[png_ptr->pass]*pixel_bytes;
163.1012 -            initial_val = offset_table[png_ptr->pass]*pixel_bytes;
163.1013 -            final_val = png_ptr->width*pixel_bytes;
163.1014 -            incr1 = (disp)*pixel_bytes;
163.1015 -            for (i = initial_val; i < final_val; i += incr1)
163.1016 -            {
163.1017 -               png_memcpy(dp, sptr, pixel_bytes);
163.1018 -               sptr += incr1;
163.1019 -               dp += incr1;
163.1020 -            }
163.1021 -            break;
163.1022 -         }
163.1023 -      } /* end switch (png_ptr->row_info.pixel_depth) */
163.1024 -   } /* end if (non-trivial mask) */
163.1025 -
163.1026 -} /* end png_combine_row() */
163.1027 -
163.1028 -
163.1029 -#if defined(PNG_READ_INTERLACING_SUPPORTED)
163.1030 -
163.1031 -void /* PRIVATE */
163.1032 -png_do_read_interlace(png_structp png_ptr)
163.1033 -{
163.1034 -   png_row_infop row_info = &(png_ptr->row_info);
163.1035 -   png_bytep row = png_ptr->row_buf + 1;
163.1036 -   int pass = png_ptr->pass;
163.1037 -   png_uint_32 transformations = png_ptr->transformations;
163.1038 -#ifdef PNG_USE_LOCAL_ARRAYS
163.1039 -   const int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
163.1040 -#endif
163.1041 -
163.1042 -   png_debug(1,"in png_do_read_interlace\n");
163.1043 -
163.1044 -   if (mmx_supported == 2) {
163.1045 -#if !defined(PNG_1_0_X)
163.1046 -       /* this should have happened in png_init_mmx_flags() already */
163.1047 -       png_warning(png_ptr, "asm_flags may not have been initialized");
163.1048 -#endif
163.1049 -       png_mmx_support();
163.1050 -   }
163.1051 -
163.1052 -   if (row != NULL && row_info != NULL)
163.1053 -   {
163.1054 -      png_uint_32 final_width;
163.1055 -
163.1056 -      final_width = row_info->width * png_pass_inc[pass];
163.1057 -
163.1058 -      switch (row_info->pixel_depth)
163.1059 -      {
163.1060 -         case 1:
163.1061 -         {
163.1062 -            png_bytep sp, dp;
163.1063 -            int sshift, dshift;
163.1064 -            int s_start, s_end, s_inc;
163.1065 -            png_byte v;
163.1066 -            png_uint_32 i;
163.1067 -            int j;
163.1068 -
163.1069 -            sp = row + (png_size_t)((row_info->width - 1) >> 3);
163.1070 -            dp = row + (png_size_t)((final_width - 1) >> 3);
163.1071 -#if defined(PNG_READ_PACKSWAP_SUPPORTED)
163.1072 -            if (transformations & PNG_PACKSWAP)
163.1073 -            {
163.1074 -               sshift = (int)((row_info->width + 7) & 7);
163.1075 -               dshift = (int)((final_width + 7) & 7);
163.1076 -               s_start = 7;
163.1077 -               s_end = 0;
163.1078 -               s_inc = -1;
163.1079 -            }
163.1080 -            else
163.1081 -#endif
163.1082 -            {
163.1083 -               sshift = 7 - (int)((row_info->width + 7) & 7);
163.1084 -               dshift = 7 - (int)((final_width + 7) & 7);
163.1085 -               s_start = 0;
163.1086 -               s_end = 7;
163.1087 -               s_inc = 1;
163.1088 -            }
163.1089 -
163.1090 -            for (i = row_info->width; i; i--)
163.1091 -            {
163.1092 -               v = (png_byte)((*sp >> sshift) & 0x1);
163.1093 -               for (j = 0; j < png_pass_inc[pass]; j++)
163.1094 -               {
163.1095 -                  *dp &= (png_byte)((0x7f7f >> (7 - dshift)) & 0xff);
163.1096 -                  *dp |= (png_byte)(v << dshift);
163.1097 -                  if (dshift == s_end)
163.1098 -                  {
163.1099 -                     dshift = s_start;
163.1100 -                     dp--;
163.1101 -                  }
163.1102 -                  else
163.1103 -                     dshift += s_inc;
163.1104 -               }
163.1105 -               if (sshift == s_end)
163.1106 -               {
163.1107 -                  sshift = s_start;
163.1108 -                  sp--;
163.1109 -               }
163.1110 -               else
163.1111 -                  sshift += s_inc;
163.1112 -            }
163.1113 -            break;
163.1114 -         }
163.1115 -
163.1116 -         case 2:
163.1117 -         {
163.1118 -            png_bytep sp, dp;
163.1119 -            int sshift, dshift;
163.1120 -            int s_start, s_end, s_inc;
163.1121 -            png_uint_32 i;
163.1122 -
163.1123 -            sp = row + (png_size_t)((row_info->width - 1) >> 2);
163.1124 -            dp = row + (png_size_t)((final_width - 1) >> 2);
163.1125 -#if defined(PNG_READ_PACKSWAP_SUPPORTED)
163.1126 -            if (transformations & PNG_PACKSWAP)
163.1127 -            {
163.1128 -               sshift = (png_size_t)(((row_info->width + 3) & 3) << 1);
163.1129 -               dshift = (png_size_t)(((final_width + 3) & 3) << 1);
163.1130 -               s_start = 6;
163.1131 -               s_end = 0;
163.1132 -               s_inc = -2;
163.1133 -            }
163.1134 -            else
163.1135 -#endif
163.1136 -            {
163.1137 -               sshift = (png_size_t)((3 - ((row_info->width + 3) & 3)) << 1);
163.1138 -               dshift = (png_size_t)((3 - ((final_width + 3) & 3)) << 1);
163.1139 -               s_start = 0;
163.1140 -               s_end = 6;
163.1141 -               s_inc = 2;
163.1142 -            }
163.1143 -
163.1144 -            for (i = row_info->width; i; i--)
163.1145 -            {
163.1146 -               png_byte v;
163.1147 -               int j;
163.1148 -
163.1149 -               v = (png_byte)((*sp >> sshift) & 0x3);
163.1150 -               for (j = 0; j < png_pass_inc[pass]; j++)
163.1151 -               {
163.1152 -                  *dp &= (png_byte)((0x3f3f >> (6 - dshift)) & 0xff);
163.1153 -                  *dp |= (png_byte)(v << dshift);
163.1154 -                  if (dshift == s_end)
163.1155 -                  {
163.1156 -                     dshift = s_start;
163.1157 -                     dp--;
163.1158 -                  }
163.1159 -                  else
163.1160 -                     dshift += s_inc;
163.1161 -               }
163.1162 -               if (sshift == s_end)
163.1163 -               {
163.1164 -                  sshift = s_start;
163.1165 -                  sp--;
163.1166 -               }
163.1167 -               else
163.1168 -                  sshift += s_inc;
163.1169 -            }
163.1170 -            break;
163.1171 -         }
163.1172 -
163.1173 -         case 4:
163.1174 -         {
163.1175 -            png_bytep sp, dp;
163.1176 -            int sshift, dshift;
163.1177 -            int s_start, s_end, s_inc;
163.1178 -            png_uint_32 i;
163.1179 -
163.1180 -            sp = row + (png_size_t)((row_info->width - 1) >> 1);
163.1181 -            dp = row + (png_size_t)((final_width - 1) >> 1);
163.1182 -#if defined(PNG_READ_PACKSWAP_SUPPORTED)
163.1183 -            if (transformations & PNG_PACKSWAP)
163.1184 -            {
163.1185 -               sshift = (png_size_t)(((row_info->width + 1) & 1) << 2);
163.1186 -               dshift = (png_size_t)(((final_width + 1) & 1) << 2);
163.1187 -               s_start = 4;
163.1188 -               s_end = 0;
163.1189 -               s_inc = -4;
163.1190 -            }
163.1191 -            else
163.1192 -#endif
163.1193 -            {
163.1194 -               sshift = (png_size_t)((1 - ((row_info->width + 1) & 1)) << 2);
163.1195 -               dshift = (png_size_t)((1 - ((final_width + 1) & 1)) << 2);
163.1196 -               s_start = 0;
163.1197 -               s_end = 4;
163.1198 -               s_inc = 4;
163.1199 -            }
163.1200 -
163.1201 -            for (i = row_info->width; i; i--)
163.1202 -            {
163.1203 -               png_byte v;
163.1204 -               int j;
163.1205 -
163.1206 -               v = (png_byte)((*sp >> sshift) & 0xf);
163.1207 -               for (j = 0; j < png_pass_inc[pass]; j++)
163.1208 -               {
163.1209 -                  *dp &= (png_byte)((0xf0f >> (4 - dshift)) & 0xff);
163.1210 -                  *dp |= (png_byte)(v << dshift);
163.1211 -                  if (dshift == s_end)
163.1212 -                  {
163.1213 -                     dshift = s_start;
163.1214 -                     dp--;
163.1215 -                  }
163.1216 -                  else
163.1217 -                     dshift += s_inc;
163.1218 -               }
163.1219 -               if (sshift == s_end)
163.1220 -               {
163.1221 -                  sshift = s_start;
163.1222 -                  sp--;
163.1223 -               }
163.1224 -               else
163.1225 -                  sshift += s_inc;
163.1226 -            }
163.1227 -            break;
163.1228 -         }
163.1229 -
163.1230 -         default:         // This is the place where the routine is modified
163.1231 -         {
163.1232 -            __int64 const4 = 0x0000000000FFFFFF;
163.1233 -            // __int64 const5 = 0x000000FFFFFF0000;  // unused...
163.1234 -            __int64 const6 = 0x00000000000000FF;
163.1235 -            png_bytep sptr, dp;
163.1236 -            png_uint_32 i;
163.1237 -            png_size_t pixel_bytes;
163.1238 -            int width = row_info->width;
163.1239 -
163.1240 -            pixel_bytes = (row_info->pixel_depth >> 3);
163.1241 -
163.1242 -            sptr = row + (width - 1) * pixel_bytes;
163.1243 -            dp = row + (final_width - 1) * pixel_bytes;
163.1244 -            // New code by Nirav Chhatrapati - Intel Corporation
163.1245 -            // sign fix by GRR
163.1246 -            // NOTE:  there is NO MMX code for 48-bit and 64-bit images
163.1247 -
163.1248 -            // use MMX routine if machine supports it
163.1249 -#if !defined(PNG_1_0_X)
163.1250 -            if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_INTERLACE)
163.1251 -                /* && mmx_supported */ )
163.1252 -#else
163.1253 -            if (mmx_supported)
163.1254 -#endif
163.1255 -            {
163.1256 -               if (pixel_bytes == 3)
163.1257 -               {
163.1258 -                  if (((pass == 0) || (pass == 1)) && width)
163.1259 -                  {
163.1260 -                     _asm
163.1261 -                     {
163.1262 -                        mov esi, sptr
163.1263 -                        mov edi, dp
163.1264 -                        mov ecx, width
163.1265 -                        sub edi, 21   // (png_pass_inc[pass] - 1)*pixel_bytes
163.1266 -loop_pass0:
163.1267 -                        movd mm0, [esi]     ; X X X X X v2 v1 v0
163.1268 -                        pand mm0, const4    ; 0 0 0 0 0 v2 v1 v0
163.1269 -                        movq mm1, mm0       ; 0 0 0 0 0 v2 v1 v0
163.1270 -                        psllq mm0, 16       ; 0 0 0 v2 v1 v0 0 0
163.1271 -                        movq mm2, mm0       ; 0 0 0 v2 v1 v0 0 0
163.1272 -                        psllq mm0, 24       ; v2 v1 v0 0 0 0 0 0
163.1273 -                        psrlq mm1, 8        ; 0 0 0 0 0 0 v2 v1
163.1274 -                        por mm0, mm2        ; v2 v1 v0 v2 v1 v0 0 0
163.1275 -                        por mm0, mm1        ; v2 v1 v0 v2 v1 v0 v2 v1
163.1276 -                        movq mm3, mm0       ; v2 v1 v0 v2 v1 v0 v2 v1
163.1277 -                        psllq mm0, 16       ; v0 v2 v1 v0 v2 v1 0 0
163.1278 -                        movq mm4, mm3       ; v2 v1 v0 v2 v1 v0 v2 v1
163.1279 -                        punpckhdq mm3, mm0  ; v0 v2 v1 v0 v2 v1 v0 v2
163.1280 -                        movq [edi+16] , mm4
163.1281 -                        psrlq mm0, 32       ; 0 0 0 0 v0 v2 v1 v0
163.1282 -                        movq [edi+8] , mm3
163.1283 -                        punpckldq mm0, mm4  ; v1 v0 v2 v1 v0 v2 v1 v0
163.1284 -                        sub esi, 3
163.1285 -                        movq [edi], mm0
163.1286 -                        sub edi, 24
163.1287 -                        //sub esi, 3
163.1288 -                        dec ecx
163.1289 -                        jnz loop_pass0
163.1290 -                        EMMS
163.1291 -                     }
163.1292 -                  }
163.1293 -                  else if (((pass == 2) || (pass == 3)) && width)
163.1294 -                  {
163.1295 -                     _asm
163.1296 -                     {
163.1297 -                        mov esi, sptr
163.1298 -                        mov edi, dp
163.1299 -                        mov ecx, width
163.1300 -                        sub edi, 9   // (png_pass_inc[pass] - 1)*pixel_bytes
163.1301 -loop_pass2:
163.1302 -                        movd mm0, [esi]     ; X X X X X v2 v1 v0
163.1303 -                        pand mm0, const4    ; 0 0 0 0 0 v2 v1 v0
163.1304 -                        movq mm1, mm0       ; 0 0 0 0 0 v2 v1 v0
163.1305 -                        psllq mm0, 16       ; 0 0 0 v2 v1 v0 0 0
163.1306 -                        movq mm2, mm0       ; 0 0 0 v2 v1 v0 0 0
163.1307 -                        psllq mm0, 24       ; v2 v1 v0 0 0 0 0 0
163.1308 -                        psrlq mm1, 8        ; 0 0 0 0 0 0 v2 v1
163.1309 -                        por mm0, mm2        ; v2 v1 v0 v2 v1 v0 0 0
163.1310 -                        por mm0, mm1        ; v2 v1 v0 v2 v1 v0 v2 v1
163.1311 -                        movq [edi+4], mm0   ; move to memory
163.1312 -                        psrlq mm0, 16       ; 0 0 v2 v1 v0 v2 v1 v0
163.1313 -                        movd [edi], mm0     ; move to memory
163.1314 -                        sub esi, 3
163.1315 -                        sub edi, 12
163.1316 -                        dec ecx
163.1317 -                        jnz loop_pass2
163.1318 -                        EMMS
163.1319 -                     }
163.1320 -                  }
163.1321 -                  else if (width) /* && ((pass == 4) || (pass == 5)) */
163.1322 -                  {
163.1323 -                     int width_mmx = ((width >> 1) << 1) - 8;
163.1324 -                     if (width_mmx < 0)
163.1325 -                         width_mmx = 0;
163.1326 -                     width -= width_mmx;        // 8 or 9 pix, 24 or 27 bytes
163.1327 -                     if (width_mmx)
163.1328 -                     {
163.1329 -                        _asm
163.1330 -                        {
163.1331 -                           mov esi, sptr
163.1332 -                           mov edi, dp
163.1333 -                           mov ecx, width_mmx
163.1334 -                           sub esi, 3
163.1335 -                           sub edi, 9
163.1336 -loop_pass4:
163.1337 -                           movq mm0, [esi]     ; X X v2 v1 v0 v5 v4 v3
163.1338 -                           movq mm7, mm0       ; X X v2 v1 v0 v5 v4 v3
163.1339 -                           movq mm6, mm0       ; X X v2 v1 v0 v5 v4 v3
163.1340 -                           psllq mm0, 24       ; v1 v0 v5 v4 v3 0 0 0
163.1341 -                           pand mm7, const4    ; 0 0 0 0 0 v5 v4 v3
163.1342 -                           psrlq mm6, 24       ; 0 0 0 X X v2 v1 v0
163.1343 -                           por mm0, mm7        ; v1 v0 v5 v4 v3 v5 v4 v3
163.1344 -                           movq mm5, mm6       ; 0 0 0 X X v2 v1 v0
163.1345 -                           psllq mm6, 8        ; 0 0 X X v2 v1 v0 0
163.1346 -                           movq [edi], mm0     ; move quad to memory
163.1347 -                           psrlq mm5, 16       ; 0 0 0 0 0 X X v2
163.1348 -                           pand mm5, const6    ; 0 0 0 0 0 0 0 v2
163.1349 -                           por mm6, mm5        ; 0 0 X X v2 v1 v0 v2
163.1350 -                           movd [edi+8], mm6   ; move double to memory
163.1351 -                           sub esi, 6
163.1352 -                           sub edi, 12
163.1353 -                           sub ecx, 2
163.1354 -                           jnz loop_pass4
163.1355 -                           EMMS
163.1356 -                        }
163.1357 -                     }
163.1358 -
163.1359 -                     sptr -= width_mmx*3;
163.1360 -                     dp -= width_mmx*6;
163.1361 -                     for (i = width; i; i--)
163.1362 -                     {
163.1363 -                        png_byte v[8];
163.1364 -                        int j;
163.1365 -
163.1366 -                        png_memcpy(v, sptr, 3);
163.1367 -                        for (j = 0; j < png_pass_inc[pass]; j++)
163.1368 -                        {
163.1369 -                           png_memcpy(dp, v, 3);
163.1370 -                           dp -= 3;
163.1371 -                        }
163.1372 -                        sptr -= 3;
163.1373 -                     }
163.1374 -                  }
163.1375 -               } /* end of pixel_bytes == 3 */
163.1376 -
163.1377 -               else if (pixel_bytes == 1)
163.1378 -               {
163.1379 -                  if (((pass == 0) || (pass == 1)) && width)
163.1380 -                  {
163.1381 -                     int width_mmx = ((width >> 2) << 2);
163.1382 -                     width -= width_mmx;
163.1383 -                     if (width_mmx)
163.1384 -                     {
163.1385 -                        _asm
163.1386 -                        {
163.1387 -                           mov esi, sptr
163.1388 -                           mov edi, dp
163.1389 -                           mov ecx, width_mmx
163.1390 -                           sub edi, 31
163.1391 -                           sub esi, 3
163.1392 -loop1_pass0:
163.1393 -                           movd mm0, [esi]     ; X X X X v0 v1 v2 v3
163.1394 -                           movq mm1, mm0       ; X X X X v0 v1 v2 v3
163.1395 -                           punpcklbw mm0, mm0  ; v0 v0 v1 v1 v2 v2 v3 v3
163.1396 -                           movq mm2, mm0       ; v0 v0 v1 v1 v2 v2 v3 v3
163.1397 -                           punpcklwd mm0, mm0  ; v2 v2 v2 v2 v3 v3 v3 v3
163.1398 -                           movq mm3, mm0       ; v2 v2 v2 v2 v3 v3 v3 v3
163.1399 -                           punpckldq mm0, mm0  ; v3 v3 v3 v3 v3 v3 v3 v3
163.1400 -                           punpckhdq mm3, mm3  ; v2 v2 v2 v2 v2 v2 v2 v2
163.1401 -                           movq [edi], mm0     ; move to memory v3
163.1402 -                           punpckhwd mm2, mm2  ; v0 v0 v0 v0 v1 v1 v1 v1
163.1403 -                           movq [edi+8], mm3   ; move to memory v2
163.1404 -                           movq mm4, mm2       ; v0 v0 v0 v0 v1 v1 v1 v1
163.1405 -                           punpckldq mm2, mm2  ; v1 v1 v1 v1 v1 v1 v1 v1
163.1406 -                           punpckhdq mm4, mm4  ; v0 v0 v0 v0 v0 v0 v0 v0
163.1407 -                           movq [edi+16], mm2  ; move to memory v1
163.1408 -                           movq [edi+24], mm4  ; move to memory v0
163.1409 -                           sub esi, 4
163.1410 -                           sub edi, 32
163.1411 -                           sub ecx, 4
163.1412 -                           jnz loop1_pass0
163.1413 -                           EMMS
163.1414 -                        }
163.1415 -                     }
163.1416 -
163.1417 -                     sptr -= width_mmx;
163.1418 -                     dp -= width_mmx*8;
163.1419 -                     for (i = width; i; i--)
163.1420 -                     {
163.1421 -                        int j;
163.1422 -
163.1423 -                       /* I simplified this part in version 1.0.4e
163.1424 -                        * here and in several other instances where
163.1425 -                        * pixel_bytes == 1  -- GR-P
163.1426 -                        *
163.1427 -                        * Original code:
163.1428 -                        *
163.1429 -                        * png_byte v[8];
163.1430 -                        * png_memcpy(v, sptr, pixel_bytes);
163.1431 -                        * for (j = 0; j < png_pass_inc[pass]; j++)
163.1432 -                        * {
163.1433 -                        *    png_memcpy(dp, v, pixel_bytes);
163.1434 -                        *    dp -= pixel_bytes;
163.1435 -                        * }
163.1436 -                        * sptr -= pixel_bytes;
163.1437 -                        *
163.1438 -                        * Replacement code is in the next three lines:
163.1439 -                        */
163.1440 -
163.1441 -                        for (j = 0; j < png_pass_inc[pass]; j++)
163.1442 -                           *dp-- = *sptr;
163.1443 -                        sptr--;
163.1444 -                     }
163.1445 -                  }
163.1446 -                  else if (((pass == 2) || (pass == 3)) && width)
163.1447 -                  {
163.1448 -                     int width_mmx = ((width >> 2) << 2);
163.1449 -                     width -= width_mmx;
163.1450 -                     if (width_mmx)
163.1451 -                     {
163.1452 -                        _asm
163.1453 -                        {
163.1454 -                           mov esi, sptr
163.1455 -                           mov edi, dp
163.1456 -                           mov ecx, width_mmx
163.1457 -                           sub edi, 15
163.1458 -                           sub esi, 3
163.1459 -loop1_pass2:
163.1460 -                           movd mm0, [esi]     ; X X X X v0 v1 v2 v3
163.1461 -                           punpcklbw mm0, mm0  ; v0 v0 v1 v1 v2 v2 v3 v3
163.1462 -                           movq mm1, mm0       ; v0 v0 v1 v1 v2 v2 v3 v3
163.1463 -                           punpcklwd mm0, mm0  ; v2 v2 v2 v2 v3 v3 v3 v3
163.1464 -                           punpckhwd mm1, mm1  ; v0 v0 v0 v0 v1 v1 v1 v1
163.1465 -                           movq [edi], mm0     ; move to memory v2 and v3
163.1466 -                           sub esi, 4
163.1467 -                           movq [edi+8], mm1   ; move to memory v1     and v0
163.1468 -                           sub edi, 16
163.1469 -                           sub ecx, 4
163.1470 -                           jnz loop1_pass2
163.1471 -                           EMMS
163.1472 -                        }
163.1473 -                     }
163.1474 -
163.1475 -                     sptr -= width_mmx;
163.1476 -                     dp -= width_mmx*4;
163.1477 -                     for (i = width; i; i--)
163.1478 -                     {
163.1479 -                        int j;
163.1480 -
163.1481 -                        for (j = 0; j < png_pass_inc[pass]; j++)
163.1482 -                        {
163.1483 -                           *dp-- = *sptr;
163.1484 -                        }
163.1485 -                        sptr --;
163.1486 -                     }
163.1487 -                  }
163.1488 -                  else if (width) /* && ((pass == 4) || (pass == 5))) */
163.1489 -                  {
163.1490 -                     int width_mmx = ((width >> 3) << 3);
163.1491 -                     width -= width_mmx;
163.1492 -                     if (width_mmx)
163.1493 -                     {
163.1494 -                        _asm
163.1495 -                        {
163.1496 -                           mov esi, sptr
163.1497 -                           mov edi, dp
163.1498 -                           mov ecx, width_mmx
163.1499 -                           sub edi, 15
163.1500 -                           sub esi, 7
163.1501 -loop1_pass4:
163.1502 -                           movq mm0, [esi]     ; v0 v1 v2 v3 v4 v5 v6 v7
163.1503 -                           movq mm1, mm0       ; v0 v1 v2 v3 v4 v5 v6 v7
163.1504 -                           punpcklbw mm0, mm0  ; v4 v4 v5 v5 v6 v6 v7 v7
163.1505 -                           //movq mm1, mm0     ; v0 v0 v1 v1 v2 v2 v3 v3
163.1506 -                           punpckhbw mm1, mm1  ;v0 v0 v1 v1 v2 v2 v3 v3
163.1507 -                           movq [edi+8], mm1   ; move to memory v0 v1 v2 and v3
163.1508 -                           sub esi, 8
163.1509 -                           movq [edi], mm0     ; move to memory v4 v5 v6 and v7
163.1510 -                           //sub esi, 4
163.1511 -                           sub edi, 16
163.1512 -                           sub ecx, 8
163.1513 -                           jnz loop1_pass4
163.1514 -                           EMMS
163.1515 -                        }
163.1516 -                     }
163.1517 -
163.1518 -                     sptr -= width_mmx;
163.1519 -                     dp -= width_mmx*2;
163.1520 -                     for (i = width; i; i--)
163.1521 -                     {
163.1522 -                        int j;
163.1523 -
163.1524 -                        for (j = 0; j < png_pass_inc[pass]; j++)
163.1525 -                        {
163.1526 -                           *dp-- = *sptr;
163.1527 -                        }
163.1528 -                        sptr --;
163.1529 -                     }
163.1530 -                  }
163.1531 -               } /* end of pixel_bytes == 1 */
163.1532 -
163.1533 -               else if (pixel_bytes == 2)
163.1534 -               {
163.1535 -                  if (((pass == 0) || (pass == 1)) && width)
163.1536 -                  {
163.1537 -                     int width_mmx = ((width >> 1) << 1);
163.1538 -                     width -= width_mmx;
163.1539 -                     if (width_mmx)
163.1540 -                     {
163.1541 -                        _asm
163.1542 -                        {
163.1543 -                           mov esi, sptr
163.1544 -                           mov edi, dp
163.1545 -                           mov ecx, width_mmx
163.1546 -                           sub esi, 2
163.1547 -                           sub edi, 30
163.1548 -loop2_pass0:
163.1549 -                           movd mm0, [esi]        ; X X X X v1 v0 v3 v2
163.1550 -                           punpcklwd mm0, mm0     ; v1 v0 v1 v0 v3 v2 v3 v2
163.1551 -                           movq mm1, mm0          ; v1 v0 v1 v0 v3 v2 v3 v2
163.1552 -                           punpckldq mm0, mm0     ; v3 v2 v3 v2 v3 v2 v3 v2
163.1553 -                           punpckhdq mm1, mm1     ; v1 v0 v1 v0 v1 v0 v1 v0
163.1554 -                           movq [edi], mm0
163.1555 -                           movq [edi + 8], mm0
163.1556 -                           movq [edi + 16], mm1
163.1557 -                           movq [edi + 24], mm1
163.1558 -                           sub esi, 4
163.1559 -                           sub edi, 32
163.1560 -                           sub ecx, 2
163.1561 -                           jnz loop2_pass0
163.1562 -                           EMMS
163.1563 -                        }
163.1564 -                     }
163.1565 -
163.1566 -                     sptr -= (width_mmx*2 - 2);            // sign fixed
163.1567 -                     dp -= (width_mmx*16 - 2);            // sign fixed
163.1568 -                     for (i = width; i; i--)
163.1569 -                     {
163.1570 -                        png_byte v[8];
163.1571 -                        int j;
163.1572 -                        sptr -= 2;
163.1573 -                        png_memcpy(v, sptr, 2);
163.1574 -                        for (j = 0; j < png_pass_inc[pass]; j++)
163.1575 -                        {
163.1576 -                           dp -= 2;
163.1577 -                           png_memcpy(dp, v, 2);
163.1578 -                        }
163.1579 -                     }
163.1580 -                  }
163.1581 -                  else if (((pass == 2) || (pass == 3)) && width)
163.1582 -                  {
163.1583 -                     int width_mmx = ((width >> 1) << 1) ;
163.1584 -                     width -= width_mmx;
163.1585 -                     if (width_mmx)
163.1586 -                     {
163.1587 -                        _asm
163.1588 -                        {
163.1589 -                           mov esi, sptr
163.1590 -                           mov edi, dp
163.1591 -                           mov ecx, width_mmx
163.1592 -                           sub esi, 2
163.1593 -                           sub edi, 14
163.1594 -loop2_pass2:
163.1595 -                           movd mm0, [esi]        ; X X X X v1 v0 v3 v2
163.1596 -                           punpcklwd mm0, mm0     ; v1 v0 v1 v0 v3 v2 v3 v2
163.1597 -                           movq mm1, mm0          ; v1 v0 v1 v0 v3 v2 v3 v2
163.1598 -                           punpckldq mm0, mm0     ; v3 v2 v3 v2 v3 v2 v3 v2
163.1599 -                           punpckhdq mm1, mm1     ; v1 v0 v1 v0 v1 v0 v1 v0
163.1600 -                           movq [edi], mm0
163.1601 -                           sub esi, 4
163.1602 -                           movq [edi + 8], mm1
163.1603 -                           //sub esi, 4
163.1604 -                           sub edi, 16
163.1605 -                           sub ecx, 2
163.1606 -                           jnz loop2_pass2
163.1607 -                           EMMS
163.1608 -                        }
163.1609 -                     }
163.1610 -
163.1611 -                     sptr -= (width_mmx*2 - 2);            // sign fixed
163.1612 -                     dp -= (width_mmx*8 - 2);            // sign fixed
163.1613 -                     for (i = width; i; i--)
163.1614 -                     {
163.1615 -                        png_byte v[8];
163.1616 -                        int j;
163.1617 -                        sptr -= 2;
163.1618 -                        png_memcpy(v, sptr, 2);
163.1619 -                        for (j = 0; j < png_pass_inc[pass]; j++)
163.1620 -                        {
163.1621 -                           dp -= 2;
163.1622 -                           png_memcpy(dp, v, 2);
163.1623 -                        }
163.1624 -                     }
163.1625 -                  }
163.1626 -                  else if (width)  // pass == 4 or 5
163.1627 -                  {
163.1628 -                     int width_mmx = ((width >> 1) << 1) ;
163.1629 -                     width -= width_mmx;
163.1630 -                     if (width_mmx)
163.1631 -                     {
163.1632 -                        _asm
163.1633 -                        {
163.1634 -                           mov esi, sptr
163.1635 -                           mov edi, dp
163.1636 -                           mov ecx, width_mmx
163.1637 -                           sub esi, 2
163.1638 -                           sub edi, 6
163.1639 -loop2_pass4:
163.1640 -                           movd mm0, [esi]        ; X X X X v1 v0 v3 v2
163.1641 -                           punpcklwd mm0, mm0     ; v1 v0 v1 v0 v3 v2 v3 v2
163.1642 -                           sub esi, 4
163.1643 -                           movq [edi], mm0
163.1644 -                           sub edi, 8
163.1645 -                           sub ecx, 2
163.1646 -                           jnz loop2_pass4
163.1647 -                           EMMS
163.1648 -                        }
163.1649 -                     }
163.1650 -
163.1651 -                     sptr -= (width_mmx*2 - 2);            // sign fixed
163.1652 -                     dp -= (width_mmx*4 - 2);            // sign fixed
163.1653 -                     for (i = width; i; i--)
163.1654 -                     {
163.1655 -                        png_byte v[8];
163.1656 -                        int j;
163.1657 -                        sptr -= 2;
163.1658 -                        png_memcpy(v, sptr, 2);
163.1659 -                        for (j = 0; j < png_pass_inc[pass]; j++)
163.1660 -                        {
163.1661 -                           dp -= 2;
163.1662 -                           png_memcpy(dp, v, 2);
163.1663 -                        }
163.1664 -                     }
163.1665 -                  }
163.1666 -               } /* end of pixel_bytes == 2 */
163.1667 -
163.1668 -               else if (pixel_bytes == 4)
163.1669 -               {
163.1670 -                  if (((pass == 0) || (pass == 1)) && width)
163.1671 -                  {
163.1672 -                     int width_mmx = ((width >> 1) << 1) ;
163.1673 -                     width -= width_mmx;
163.1674 -                     if (width_mmx)
163.1675 -                     {
163.1676 -                        _asm
163.1677 -                        {
163.1678 -                           mov esi, sptr
163.1679 -                           mov edi, dp
163.1680 -                           mov ecx, width_mmx
163.1681 -                           sub esi, 4
163.1682 -                           sub edi, 60
163.1683 -loop4_pass0:
163.1684 -                           movq mm0, [esi]        ; v3 v2 v1 v0 v7 v6 v5 v4
163.1685 -                           movq mm1, mm0          ; v3 v2 v1 v0 v7 v6 v5 v4
163.1686 -                           punpckldq mm0, mm0     ; v7 v6 v5 v4 v7 v6 v5 v4
163.1687 -                           punpckhdq mm1, mm1     ; v3 v2 v1 v0 v3 v2 v1 v0
163.1688 -                           movq [edi], mm0
163.1689 -                           movq [edi + 8], mm0
163.1690 -                           movq [edi + 16], mm0
163.1691 -                           movq [edi + 24], mm0
163.1692 -                           movq [edi+32], mm1
163.1693 -                           movq [edi + 40], mm1
163.1694 -                           movq [edi+ 48], mm1
163.1695 -                           sub esi, 8
163.1696 -                           movq [edi + 56], mm1
163.1697 -                           sub edi, 64
163.1698 -                           sub ecx, 2
163.1699 -                           jnz loop4_pass0
163.1700 -                           EMMS
163.1701 -                        }
163.1702 -                     }
163.1703 -
163.1704 -                     sptr -= (width_mmx*4 - 4);            // sign fixed
163.1705 -                     dp -= (width_mmx*32 - 4);            // sign fixed
163.1706 -                     for (i = width; i; i--)
163.1707 -                     {
163.1708 -                        png_byte v[8];
163.1709 -                        int j;
163.1710 -                        sptr -= 4;
163.1711 -                        png_memcpy(v, sptr, 4);
163.1712 -                        for (j = 0; j < png_pass_inc[pass]; j++)
163.1713 -                        {
163.1714 -                           dp -= 4;
163.1715 -                           png_memcpy(dp, v, 4);
163.1716 -                        }
163.1717 -                     }
163.1718 -                  }
163.1719 -                  else if (((pass == 2) || (pass == 3)) && width)
163.1720 -                  {
163.1721 -                     int width_mmx = ((width >> 1) << 1) ;
163.1722 -                     width -= width_mmx;
163.1723 -                     if (width_mmx)
163.1724 -                     {
163.1725 -                        _asm
163.1726 -                        {
163.1727 -                           mov esi, sptr
163.1728 -                           mov edi, dp
163.1729 -                           mov ecx, width_mmx
163.1730 -                           sub esi, 4
163.1731 -                           sub edi, 28
163.1732 -loop4_pass2:
163.1733 -                           movq mm0, [esi]      ; v3 v2 v1 v0 v7 v6 v5 v4
163.1734 -                           movq mm1, mm0        ; v3 v2 v1 v0 v7 v6 v5 v4
163.1735 -                           punpckldq mm0, mm0   ; v7 v6 v5 v4 v7 v6 v5 v4
163.1736 -                           punpckhdq mm1, mm1   ; v3 v2 v1 v0 v3 v2 v1 v0
163.1737 -                           movq [edi], mm0
163.1738 -                           movq [edi + 8], mm0
163.1739 -                           movq [edi+16], mm1
163.1740 -                           movq [edi + 24], mm1
163.1741 -                           sub esi, 8
163.1742 -                           sub edi, 32
163.1743 -                           sub ecx, 2
163.1744 -                           jnz loop4_pass2
163.1745 -                           EMMS
163.1746 -                        }
163.1747 -                     }
163.1748 -
163.1749 -                     sptr -= (width_mmx*4 - 4);            // sign fixed
163.1750 -                     dp -= (width_mmx*16 - 4);            // sign fixed
163.1751 -                     for (i = width; i; i--)
163.1752 -                     {
163.1753 -                        png_byte v[8];
163.1754 -                        int j;
163.1755 -                        sptr -= 4;
163.1756 -                        png_memcpy(v, sptr, 4);
163.1757 -                        for (j = 0; j < png_pass_inc[pass]; j++)
163.1758 -                        {
163.1759 -                           dp -= 4;
163.1760 -                           png_memcpy(dp, v, 4);
163.1761 -                        }
163.1762 -                     }
163.1763 -                  }
163.1764 -                  else if (width)  // pass == 4 or 5
163.1765 -                  {
163.1766 -                     int width_mmx = ((width >> 1) << 1) ;
163.1767 -                     width -= width_mmx;
163.1768 -                     if (width_mmx)
163.1769 -                     {
163.1770 -                        _asm
163.1771 -                        {
163.1772 -                           mov esi, sptr
163.1773 -                           mov edi, dp
163.1774 -                           mov ecx, width_mmx
163.1775 -                           sub esi, 4
163.1776 -                           sub edi, 12
163.1777 -loop4_pass4:
163.1778 -                           movq mm0, [esi]      ; v3 v2 v1 v0 v7 v6 v5 v4
163.1779 -                           movq mm1, mm0        ; v3 v2 v1 v0 v7 v6 v5 v4
163.1780 -                           punpckldq mm0, mm0   ; v7 v6 v5 v4 v7 v6 v5 v4
163.1781 -                           punpckhdq mm1, mm1   ; v3 v2 v1 v0 v3 v2 v1 v0
163.1782 -                           movq [edi], mm0
163.1783 -                           sub esi, 8
163.1784 -                           movq [edi + 8], mm1
163.1785 -                           sub edi, 16
163.1786 -                           sub ecx, 2
163.1787 -                           jnz loop4_pass4
163.1788 -                           EMMS
163.1789 -                        }
163.1790 -                     }
163.1791 -
163.1792 -                     sptr -= (width_mmx*4 - 4);          // sign fixed
163.1793 -                     dp -= (width_mmx*8 - 4);            // sign fixed
163.1794 -                     for (i = width; i; i--)
163.1795 -                     {
163.1796 -                        png_byte v[8];
163.1797 -                        int j;
163.1798 -                        sptr -= 4;
163.1799 -                        png_memcpy(v, sptr, 4);
163.1800 -                        for (j = 0; j < png_pass_inc[pass]; j++)
163.1801 -                        {
163.1802 -                           dp -= 4;
163.1803 -                           png_memcpy(dp, v, 4);
163.1804 -                        }
163.1805 -                     }
163.1806 -                  }
163.1807 -
163.1808 -               } /* end of pixel_bytes == 4 */
163.1809 -
163.1810 -               else if (pixel_bytes == 6)
163.1811 -               {
163.1812 -                  for (i = width; i; i--)
163.1813 -                  {
163.1814 -                     png_byte v[8];
163.1815 -                     int j;
163.1816 -                     png_memcpy(v, sptr, 6);
163.1817 -                     for (j = 0; j < png_pass_inc[pass]; j++)
163.1818 -                     {
163.1819 -                        png_memcpy(dp, v, 6);
163.1820 -                        dp -= 6;
163.1821 -                     }
163.1822 -                     sptr -= 6;
163.1823 -                  }
163.1824 -               } /* end of pixel_bytes == 6 */
163.1825 -
163.1826 -               else
163.1827 -               {
163.1828 -                  for (i = width; i; i--)
163.1829 -                  {
163.1830 -                     png_byte v[8];
163.1831 -                     int j;
163.1832 -                     png_memcpy(v, sptr, pixel_bytes);
163.1833 -                     for (j = 0; j < png_pass_inc[pass]; j++)
163.1834 -                     {
163.1835 -                        png_memcpy(dp, v, pixel_bytes);
163.1836 -                        dp -= pixel_bytes;
163.1837 -                     }
163.1838 -                     sptr-= pixel_bytes;
163.1839 -                  }
163.1840 -               }
163.1841 -            } /* end of mmx_supported */
163.1842 -
163.1843 -            else /* MMX not supported:  use modified C code - takes advantage
163.1844 -                  * of inlining of memcpy for a constant */
163.1845 -            {
163.1846 -               if (pixel_bytes == 1)
163.1847 -               {
163.1848 -                  for (i = width; i; i--)
163.1849 -                  {
163.1850 -                     int j;
163.1851 -                     for (j = 0; j < png_pass_inc[pass]; j++)
163.1852 -                        *dp-- = *sptr;
163.1853 -                     sptr--;
163.1854 -                  }
163.1855 -               }
163.1856 -               else if (pixel_bytes == 3)
163.1857 -               {
163.1858 -                  for (i = width; i; i--)
163.1859 -                  {
163.1860 -                     png_byte v[8];
163.1861 -                     int j;
163.1862 -                     png_memcpy(v, sptr, pixel_bytes);
163.1863 -                     for (j = 0; j < png_pass_inc[pass]; j++)
163.1864 -                     {
163.1865 -                        png_memcpy(dp, v, pixel_bytes);
163.1866 -                        dp -= pixel_bytes;
163.1867 -                     }
163.1868 -                     sptr -= pixel_bytes;
163.1869 -                  }
163.1870 -               }
163.1871 -               else if (pixel_bytes == 2)
163.1872 -               {
163.1873 -                  for (i = width; i; i--)
163.1874 -                  {
163.1875 -                     png_byte v[8];
163.1876 -                     int j;
163.1877 -                     png_memcpy(v, sptr, pixel_bytes);
163.1878 -                     for (j = 0; j < png_pass_inc[pass]; j++)
163.1879 -                     {
163.1880 -                        png_memcpy(dp, v, pixel_bytes);
163.1881 -                        dp -= pixel_bytes;
163.1882 -                     }
163.1883 -                     sptr -= pixel_bytes;
163.1884 -                  }
163.1885 -               }
163.1886 -               else if (pixel_bytes == 4)
163.1887 -               {
163.1888 -                  for (i = width; i; i--)
163.1889 -                  {
163.1890 -                     png_byte v[8];
163.1891 -                     int j;
163.1892 -                     png_memcpy(v, sptr, pixel_bytes);
163.1893 -                     for (j = 0; j < png_pass_inc[pass]; j++)
163.1894 -                     {
163.1895 -                        png_memcpy(dp, v, pixel_bytes);
163.1896 -                        dp -= pixel_bytes;
163.1897 -                     }
163.1898 -                     sptr -= pixel_bytes;
163.1899 -                  }
163.1900 -               }
163.1901 -               else if (pixel_bytes == 6)
163.1902 -               {
163.1903 -                  for (i = width; i; i--)
163.1904 -                  {
163.1905 -                     png_byte v[8];
163.1906 -                     int j;
163.1907 -                     png_memcpy(v, sptr, pixel_bytes);
163.1908 -                     for (j = 0; j < png_pass_inc[pass]; j++)
163.1909 -                     {
163.1910 -                        png_memcpy(dp, v, pixel_bytes);
163.1911 -                        dp -= pixel_bytes;
163.1912 -                     }
163.1913 -                     sptr -= pixel_bytes;
163.1914 -                  }
163.1915 -               }
163.1916 -               else
163.1917 -               {
163.1918 -                  for (i = width; i; i--)
163.1919 -                  {
163.1920 -                     png_byte v[8];
163.1921 -                     int j;
163.1922 -                     png_memcpy(v, sptr, pixel_bytes);
163.1923 -                     for (j = 0; j < png_pass_inc[pass]; j++)
163.1924 -                     {
163.1925 -                        png_memcpy(dp, v, pixel_bytes);
163.1926 -                        dp -= pixel_bytes;
163.1927 -                     }
163.1928 -                     sptr -= pixel_bytes;
163.1929 -                  }
163.1930 -               }
163.1931 -
163.1932 -            } /* end of MMX not supported */
163.1933 -            break;
163.1934 -         }
163.1935 -      } /* end switch (row_info->pixel_depth) */
163.1936 -
163.1937 -      row_info->width = final_width;
163.1938 -
163.1939 -      row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,final_width);
163.1940 -   }
163.1941 -
163.1942 -}
163.1943 -
163.1944 -#endif /* PNG_READ_INTERLACING_SUPPORTED */
163.1945 -
163.1946 -
163.1947 -// These variables are utilized in the functions below.  They are declared
163.1948 -// globally here to ensure alignment on 8-byte boundaries.
163.1949 -
163.1950 -union uAll {
163.1951 -   __int64 use;
163.1952 -   double  align;
163.1953 -} LBCarryMask = {0x0101010101010101},
163.1954 -  HBClearMask = {0x7f7f7f7f7f7f7f7f},
163.1955 -  ActiveMask, ActiveMask2, ActiveMaskEnd, ShiftBpp, ShiftRem;
163.1956 -
163.1957 -
163.1958 -// Optimized code for PNG Average filter decoder
163.1959 -void /* PRIVATE */
163.1960 -png_read_filter_row_mmx_avg(png_row_infop row_info, png_bytep row
163.1961 -                            , png_bytep prev_row)
163.1962 -{
163.1963 -   int bpp;
163.1964 -   png_uint_32 FullLength;
163.1965 -   png_uint_32 MMXLength;
163.1966 -   //png_uint_32 len;
163.1967 -   int diff;
163.1968 -
163.1969 -   bpp = (row_info->pixel_depth + 7) >> 3; // Get # bytes per pixel
163.1970 -   FullLength  = row_info->rowbytes; // # of bytes to filter
163.1971 -   _asm {
163.1972 -         // Init address pointers and offset
163.1973 -         mov edi, row          // edi ==> Avg(x)
163.1974 -         xor ebx, ebx          // ebx ==> x
163.1975 -         mov edx, edi
163.1976 -         mov esi, prev_row           // esi ==> Prior(x)
163.1977 -         sub edx, bpp          // edx ==> Raw(x-bpp)
163.1978 -
163.1979 -         xor eax, eax
163.1980 -         // Compute the Raw value for the first bpp bytes
163.1981 -         //    Raw(x) = Avg(x) + (Prior(x)/2)
163.1982 -davgrlp:
163.1983 -         mov al, [esi + ebx]   // Load al with Prior(x)
163.1984 -         inc ebx
163.1985 -         shr al, 1             // divide by 2
163.1986 -         add al, [edi+ebx-1]   // Add Avg(x); -1 to offset inc ebx
163.1987 -         cmp ebx, bpp
163.1988 -         mov [edi+ebx-1], al    // Write back Raw(x);
163.1989 -                            // mov does not affect flags; -1 to offset inc ebx
163.1990 -         jb davgrlp
163.1991 -         // get # of bytes to alignment
163.1992 -         mov diff, edi         // take start of row
163.1993 -         add diff, ebx         // add bpp
163.1994 -         add diff, 0xf         // add 7 + 8 to incr past alignment boundary
163.1995 -         and diff, 0xfffffff8  // mask to alignment boundary
163.1996 -         sub diff, edi         // subtract from start ==> value ebx at alignment
163.1997 -         jz davggo
163.1998 -         // fix alignment
163.1999 -         // Compute the Raw value for the bytes upto the alignment boundary
163.2000 -         //    Raw(x) = Avg(x) + ((Raw(x-bpp) + Prior(x))/2)
163.2001 -         xor ecx, ecx
163.2002 -davglp1:
163.2003 -         xor eax, eax
163.2004 -         mov cl, [esi + ebx]        // load cl with Prior(x)
163.2005 -         mov al, [edx + ebx]  // load al with Raw(x-bpp)
163.2006 -         add ax, cx
163.2007 -         inc ebx
163.2008 -         shr ax, 1            // divide by 2
163.2009 -         add al, [edi+ebx-1]  // Add Avg(x); -1 to offset inc ebx
163.2010 -         cmp ebx, diff              // Check if at alignment boundary
163.2011 -         mov [edi+ebx-1], al        // Write back Raw(x);
163.2012 -                            // mov does not affect flags; -1 to offset inc ebx
163.2013 -         jb davglp1               // Repeat until at alignment boundary
163.2014 -davggo:
163.2015 -         mov eax, FullLength
163.2016 -         mov ecx, eax
163.2017 -         sub eax, ebx          // subtract alignment fix
163.2018 -         and eax, 0x00000007   // calc bytes over mult of 8
163.2019 -         sub ecx, eax          // drop over bytes from original length
163.2020 -         mov MMXLength, ecx
163.2021 -   } // end _asm block
163.2022 -   // Now do the math for the rest of the row
163.2023 -   switch ( bpp )
163.2024 -   {
163.2025 -      case 3:
163.2026 -      {
163.2027 -         ActiveMask.use  = 0x0000000000ffffff;
163.2028 -         ShiftBpp.use = 24;    // == 3 * 8
163.2029 -         ShiftRem.use = 40;    // == 64 - 24
163.2030 -         _asm {
163.2031 -            // Re-init address pointers and offset
163.2032 -            movq mm7, ActiveMask
163.2033 -            mov ebx, diff      // ebx ==> x = offset to alignment boundary
163.2034 -            movq mm5, LBCarryMask
163.2035 -            mov edi, row       // edi ==> Avg(x)
163.2036 -            movq mm4, HBClearMask
163.2037 -            mov esi, prev_row        // esi ==> Prior(x)
163.2038 -            // PRIME the pump (load the first Raw(x-bpp) data set
163.2039 -            movq mm2, [edi + ebx - 8]  // Load previous aligned 8 bytes
163.2040 -                               // (we correct position in loop below)
163.2041 -davg3lp:
163.2042 -            movq mm0, [edi + ebx]      // Load mm0 with Avg(x)
163.2043 -            // Add (Prev_row/2) to Average
163.2044 -            movq mm3, mm5
163.2045 -            psrlq mm2, ShiftRem      // Correct position Raw(x-bpp) data
163.2046 -            movq mm1, [esi + ebx]    // Load mm1 with Prior(x)
163.2047 -            movq mm6, mm7
163.2048 -            pand mm3, mm1      // get lsb for each prev_row byte
163.2049 -            psrlq mm1, 1       // divide prev_row bytes by 2
163.2050 -            pand  mm1, mm4     // clear invalid bit 7 of each byte
163.2051 -            paddb mm0, mm1     // add (Prev_row/2) to Avg for each byte
163.2052 -            // Add 1st active group (Raw(x-bpp)/2) to Average with LBCarry
163.2053 -            movq mm1, mm3      // now use mm1 for getting LBCarrys
163.2054 -            pand mm1, mm2      // get LBCarrys for each byte where both
163.2055 -                               // lsb's were == 1 (Only valid for active group)
163.2056 -            psrlq mm2, 1       // divide raw bytes by 2
163.2057 -            pand  mm2, mm4     // clear invalid bit 7 of each byte
163.2058 -            paddb mm2, mm1     // add LBCarrys to (Raw(x-bpp)/2) for each byte
163.2059 -            pand mm2, mm6      // Leave only Active Group 1 bytes to add to Avg
163.2060 -            paddb mm0, mm2     // add (Raw/2) + LBCarrys to Avg for each Active
163.2061 -                               //  byte
163.2062 -            // Add 2nd active group (Raw(x-bpp)/2) to Average with LBCarry
163.2063 -            psllq mm6, ShiftBpp  // shift the mm6 mask to cover bytes 3-5
163.2064 -            movq mm2, mm0        // mov updated Raws to mm2
163.2065 -            psllq mm2, ShiftBpp  // shift data to position correctly
163.2066 -            movq mm1, mm3        // now use mm1 for getting LBCarrys
163.2067 -            pand mm1, mm2      // get LBCarrys for each byte where both
163.2068 -                               // lsb's were == 1 (Only valid for active group)
163.2069 -            psrlq mm2, 1       // divide raw bytes by 2
163.2070 -            pand  mm2, mm4     // clear invalid bit 7 of each byte
163.2071 -            paddb mm2, mm1     // add LBCarrys to (Raw(x-bpp)/2) for each byte
163.2072 -            pand mm2, mm6      // Leave only Active Group 2 bytes to add to Avg
163.2073 -            paddb mm0, mm2     // add (Raw/2) + LBCarrys to Avg for each Active
163.2074 -                               //  byte
163.2075 -
163.2076 -            // Add 3rd active group (Raw(x-bpp)/2) to Average with LBCarry
163.2077 -            psllq mm6, ShiftBpp  // shift the mm6 mask to cover the last two
163.2078 -                                 // bytes
163.2079 -            movq mm2, mm0        // mov updated Raws to mm2
163.2080 -            psllq mm2, ShiftBpp  // shift data to position correctly
163.2081 -                              // Data only needs to be shifted once here to
163.2082 -                              // get the correct x-bpp offset.
163.2083 -            movq mm1, mm3     // now use mm1 for getting LBCarrys
163.2084 -            pand mm1, mm2     // get LBCarrys for each byte where both
163.2085 -                              // lsb's were == 1 (Only valid for active group)
163.2086 -            psrlq mm2, 1      // divide raw bytes by 2
163.2087 -            pand  mm2, mm4    // clear invalid bit 7 of each byte
163.2088 -            paddb mm2, mm1    // add LBCarrys to (Raw(x-bpp)/2) for each byte
163.2089 -            pand mm2, mm6     // Leave only Active Group 2 bytes to add to Avg
163.2090 -            add ebx, 8
163.2091 -            paddb mm0, mm2    // add (Raw/2) + LBCarrys to Avg for each Active
163.2092 -                              // byte
163.2093 -
163.2094 -            // Now ready to write back to memory
163.2095 -            movq [edi + ebx - 8], mm0
163.2096 -            // Move updated Raw(x) to use as Raw(x-bpp) for next loop
163.2097 -            cmp ebx, MMXLength
163.2098 -            movq mm2, mm0     // mov updated Raw(x) to mm2
163.2099 -            jb davg3lp
163.2100 -         } // end _asm block
163.2101 -      }
163.2102 -      break;
163.2103 -
163.2104 -      case 6:
163.2105 -      case 4:
163.2106 -      case 7:
163.2107 -      case 5:
163.2108 -      {
163.2109 -         ActiveMask.use  = 0xffffffffffffffff;  // use shift below to clear
163.2110 -                                                // appropriate inactive bytes
163.2111 -         ShiftBpp.use = bpp << 3;
163.2112 -         ShiftRem.use = 64 - ShiftBpp.use;
163.2113 -         _asm {
163.2114 -            movq mm4, HBClearMask
163.2115 -            // Re-init address pointers and offset
163.2116 -            mov ebx, diff       // ebx ==> x = offset to alignment boundary
163.2117 -            // Load ActiveMask and clear all bytes except for 1st active group
163.2118 -            movq mm7, ActiveMask
163.2119 -            mov edi, row         // edi ==> Avg(x)
163.2120 -            psrlq mm7, ShiftRem
163.2121 -            mov esi, prev_row    // esi ==> Prior(x)
163.2122 -            movq mm6, mm7
163.2123 -            movq mm5, LBCarryMask
163.2124 -            psllq mm6, ShiftBpp  // Create mask for 2nd active group
163.2125 -            // PRIME the pump (load the first Raw(x-bpp) data set
163.2126 -            movq mm2, [edi + ebx - 8]  // Load previous aligned 8 bytes
163.2127 -                                 // (we correct position in loop below)
163.2128 -davg4lp:
163.2129 -            movq mm0, [edi + ebx]
163.2130 -            psrlq mm2, ShiftRem  // shift data to position correctly
163.2131 -            movq mm1, [esi + ebx]
163.2132 -            // Add (Prev_row/2) to Average
163.2133 -            movq mm3, mm5
163.2134 -            pand mm3, mm1     // get lsb for each prev_row byte
163.2135 -            psrlq mm1, 1      // divide prev_row bytes by 2
163.2136 -            pand  mm1, mm4    // clear invalid bit 7 of each byte
163.2137 -            paddb mm0, mm1    // add (Prev_row/2) to Avg for each byte
163.2138 -            // Add 1st active group (Raw(x-bpp)/2) to Average with LBCarry
163.2139 -            movq mm1, mm3     // now use mm1 for getting LBCarrys
163.2140 -            pand mm1, mm2     // get LBCarrys for each byte where both
163.2141 -                              // lsb's were == 1 (Only valid for active group)
163.2142 -            psrlq mm2, 1      // divide raw bytes by 2
163.2143 -            pand  mm2, mm4    // clear invalid bit 7 of each byte
163.2144 -            paddb mm2, mm1    // add LBCarrys to (Raw(x-bpp)/2) for each byte
163.2145 -            pand mm2, mm7     // Leave only Active Group 1 bytes to add to Avg
163.2146 -            paddb mm0, mm2    // add (Raw/2) + LBCarrys to Avg for each Active
163.2147 -                              // byte
163.2148 -            // Add 2nd active group (Raw(x-bpp)/2) to Average with LBCarry
163.2149 -            movq mm2, mm0     // mov updated Raws to mm2
163.2150 -            psllq mm2, ShiftBpp // shift data to position correctly
163.2151 -            add ebx, 8
163.2152 -            movq mm1, mm3     // now use mm1 for getting LBCarrys
163.2153 -            pand mm1, mm2     // get LBCarrys for each byte where both
163.2154 -                              // lsb's were == 1 (Only valid for active group)
163.2155 -            psrlq mm2, 1      // divide raw bytes by 2
163.2156 -            pand  mm2, mm4    // clear invalid bit 7 of each byte
163.2157 -            paddb mm2, mm1    // add LBCarrys to (Raw(x-bpp)/2) for each byte
163.2158 -            pand mm2, mm6     // Leave only Active Group 2 bytes to add to Avg
163.2159 -            paddb mm0, mm2    // add (Raw/2) + LBCarrys to Avg for each Active
163.2160 -                              // byte
163.2161 -            cmp ebx, MMXLength
163.2162 -            // Now ready to write back to memory
163.2163 -            movq [edi + ebx - 8], mm0
163.2164 -            // Prep Raw(x-bpp) for next loop
163.2165 -            movq mm2, mm0     // mov updated Raws to mm2
163.2166 -            jb davg4lp
163.2167 -         } // end _asm block
163.2168 -      }
163.2169 -      break;
163.2170 -      case 2:
163.2171 -      {
163.2172 -         ActiveMask.use  = 0x000000000000ffff;
163.2173 -         ShiftBpp.use = 16;   // == 2 * 8     [BUGFIX]
163.2174 -         ShiftRem.use = 48;   // == 64 - 16   [BUGFIX]
163.2175 -         _asm {
163.2176 -            // Load ActiveMask
163.2177 -            movq mm7, ActiveMask
163.2178 -            // Re-init address pointers and offset
163.2179 -            mov ebx, diff     // ebx ==> x = offset to alignment boundary
163.2180 -            movq mm5, LBCarryMask
163.2181 -            mov edi, row      // edi ==> Avg(x)
163.2182 -            movq mm4, HBClearMask
163.2183 -            mov esi, prev_row  // esi ==> Prior(x)
163.2184 -            // PRIME the pump (load the first Raw(x-bpp) data set
163.2185 -            movq mm2, [edi + ebx - 8]  // Load previous aligned 8 bytes
163.2186 -                              // (we correct position in loop below)
163.2187 -davg2lp:
163.2188 -            movq mm0, [edi + ebx]
163.2189 -            psrlq mm2, ShiftRem  // shift data to position correctly   [BUGFIX]
163.2190 -            movq mm1, [esi + ebx]
163.2191 -            // Add (Prev_row/2) to Average
163.2192 -            movq mm3, mm5
163.2193 -            pand mm3, mm1     // get lsb for each prev_row byte
163.2194 -            psrlq mm1, 1      // divide prev_row bytes by 2
163.2195 -            pand  mm1, mm4    // clear invalid bit 7 of each byte
163.2196 -            movq mm6, mm7
163.2197 -            paddb mm0, mm1    // add (Prev_row/2) to Avg for each byte
163.2198 -            // Add 1st active group (Raw(x-bpp)/2) to Average with LBCarry
163.2199 -            movq mm1, mm3     // now use mm1 for getting LBCarrys
163.2200 -            pand mm1, mm2     // get LBCarrys for each byte where both
163.2201 -                              // lsb's were == 1 (Only valid for active group)
163.2202 -            psrlq mm2, 1      // divide raw bytes by 2
163.2203 -            pand  mm2, mm4    // clear invalid bit 7 of each byte
163.2204 -            paddb mm2, mm1    // add LBCarrys to (Raw(x-bpp)/2) for each byte
163.2205 -            pand mm2, mm6     // Leave only Active Group 1 bytes to add to Avg
163.2206 -            paddb mm0, mm2 // add (Raw/2) + LBCarrys to Avg for each Active byte
163.2207 -            // Add 2nd active group (Raw(x-bpp)/2) to Average with LBCarry
163.2208 -            psllq mm6, ShiftBpp // shift the mm6 mask to cover bytes 2 & 3
163.2209 -            movq mm2, mm0       // mov updated Raws to mm2
163.2210 -            psllq mm2, ShiftBpp // shift data to position correctly
163.2211 -            movq mm1, mm3       // now use mm1 for getting LBCarrys
163.2212 -            pand mm1, mm2       // get LBCarrys for each byte where both
163.2213 -                                // lsb's were == 1 (Only valid for active group)
163.2214 -            psrlq mm2, 1        // divide raw bytes by 2
163.2215 -            pand  mm2, mm4      // clear invalid bit 7 of each byte
163.2216 -            paddb mm2, mm1      // add LBCarrys to (Raw(x-bpp)/2) for each byte
163.2217 -            pand mm2, mm6       // Leave only Active Group 2 bytes to add to Avg
163.2218 -            paddb mm0, mm2 // add (Raw/2) + LBCarrys to Avg for each Active byte
163.2219 -
163.2220 -            // Add rdd active group (Raw(x-bpp)/2) to Average with LBCarry
163.2221 -            psllq mm6, ShiftBpp // shift the mm6 mask to cover bytes 4 & 5
163.2222 -            movq mm2, mm0       // mov updated Raws to mm2
163.2223 -            psllq mm2, ShiftBpp // shift data to position correctly
163.2224 -                                // Data only needs to be shifted once here to
163.2225 -                                // get the correct x-bpp offset.
163.2226 -            movq mm1, mm3       // now use mm1 for getting LBCarrys
163.2227 -            pand mm1, mm2       // get LBCarrys for each byte where both
163.2228 -                                // lsb's were == 1 (Only valid for active group)
163.2229 -            psrlq mm2, 1        // divide raw bytes by 2
163.2230 -            pand  mm2, mm4      // clear invalid bit 7 of each byte
163.2231 -            paddb mm2, mm1      // add LBCarrys to (Raw(x-bpp)/2) for each byte
163.2232 -            pand mm2, mm6       // Leave only Active Group 2 bytes to add to Avg
163.2233 -            paddb mm0, mm2 // add (Raw/2) + LBCarrys to Avg for each Active byte
163.2234 -
163.2235 -            // Add 4th active group (Raw(x-bpp)/2) to Average with LBCarry
163.2236 -            psllq mm6, ShiftBpp  // shift the mm6 mask to cover bytes 6 & 7
163.2237 -            movq mm2, mm0        // mov updated Raws to mm2
163.2238 -            psllq mm2, ShiftBpp  // shift data to position correctly
163.2239 -                                 // Data only needs to be shifted once here to
163.2240 -                                 // get the correct x-bpp offset.
163.2241 -            add ebx, 8
163.2242 -            movq mm1, mm3    // now use mm1 for getting LBCarrys
163.2243 -            pand mm1, mm2    // get LBCarrys for each byte where both
163.2244 -                             // lsb's were == 1 (Only valid for active group)
163.2245 -            psrlq mm2, 1     // divide raw bytes by 2
163.2246 -            pand  mm2, mm4   // clear invalid bit 7 of each byte
163.2247 -            paddb mm2, mm1   // add LBCarrys to (Raw(x-bpp)/2) for each byte
163.2248 -            pand mm2, mm6    // Leave only Active Group 2 bytes to add to Avg
163.2249 -            paddb mm0, mm2 // add (Raw/2) + LBCarrys to Avg for each Active byte
163.2250 -
163.2251 -            cmp ebx, MMXLength
163.2252 -            // Now ready to write back to memory
163.2253 -            movq [edi + ebx - 8], mm0
163.2254 -            // Prep Raw(x-bpp) for next loop
163.2255 -            movq mm2, mm0    // mov updated Raws to mm2
163.2256 -            jb davg2lp
163.2257 -        } // end _asm block
163.2258 -      }
163.2259 -      break;
163.2260 -
163.2261 -      case 1:                 // bpp == 1
163.2262 -      {
163.2263 -         _asm {
163.2264 -            // Re-init address pointers and offset
163.2265 -            mov ebx, diff     // ebx ==> x = offset to alignment boundary
163.2266 -            mov edi, row      // edi ==> Avg(x)
163.2267 -            cmp ebx, FullLength  // Test if offset at end of array
163.2268 -            jnb davg1end
163.2269 -            // Do Paeth decode for remaining bytes
163.2270 -            mov esi, prev_row    // esi ==> Prior(x)
163.2271 -            mov edx, edi
163.2272 -            xor ecx, ecx         // zero ecx before using cl & cx in loop below
163.2273 -            sub edx, bpp         // edx ==> Raw(x-bpp)
163.2274 -davg1lp:
163.2275 -            // Raw(x) = Avg(x) + ((Raw(x-bpp) + Prior(x))/2)
163.2276 -            xor eax, eax
163.2277 -            mov cl, [esi + ebx]  // load cl with Prior(x)
163.2278 -            mov al, [edx + ebx]  // load al with Raw(x-bpp)
163.2279 -            add ax, cx
163.2280 -            inc ebx
163.2281 -            shr ax, 1            // divide by 2
163.2282 -            add al, [edi+ebx-1]  // Add Avg(x); -1 to offset inc ebx
163.2283 -            cmp ebx, FullLength  // Check if at end of array
163.2284 -            mov [edi+ebx-1], al  // Write back Raw(x);
163.2285 -                         // mov does not affect flags; -1 to offset inc ebx
163.2286 -            jb davg1lp
163.2287 -davg1end:
163.2288 -         } // end _asm block
163.2289 -      }
163.2290 -      return;
163.2291 -
163.2292 -      case 8:             // bpp == 8
163.2293 -      {
163.2294 -         _asm {
163.2295 -            // Re-init address pointers and offset
163.2296 -            mov ebx, diff           // ebx ==> x = offset to alignment boundary
163.2297 -            movq mm5, LBCarryMask
163.2298 -            mov edi, row            // edi ==> Avg(x)
163.2299 -            movq mm4, HBClearMask
163.2300 -            mov esi, prev_row       // esi ==> Prior(x)
163.2301 -            // PRIME the pump (load the first Raw(x-bpp) data set
163.2302 -            movq mm2, [edi + ebx - 8]  // Load previous aligned 8 bytes
163.2303 -                                // (NO NEED to correct position in loop below)
163.2304 -davg8lp:
163.2305 -            movq mm0, [edi + ebx]
163.2306 -            movq mm3, mm5
163.2307 -            movq mm1, [esi + ebx]
163.2308 -            add ebx, 8
163.2309 -            pand mm3, mm1       // get lsb for each prev_row byte
163.2310 -            psrlq mm1, 1        // divide prev_row bytes by 2
163.2311 -            pand mm3, mm2       // get LBCarrys for each byte where both
163.2312 -                                // lsb's were == 1
163.2313 -            psrlq mm2, 1        // divide raw bytes by 2
163.2314 -            pand  mm1, mm4      // clear invalid bit 7 of each byte
163.2315 -            paddb mm0, mm3      // add LBCarrys to Avg for each byte
163.2316 -            pand  mm2, mm4      // clear invalid bit 7 of each byte
163.2317 -            paddb mm0, mm1      // add (Prev_row/2) to Avg for each byte
163.2318 -            paddb mm0, mm2      // add (Raw/2) to Avg for each byte
163.2319 -            cmp ebx, MMXLength
163.2320 -            movq [edi + ebx - 8], mm0
163.2321 -            movq mm2, mm0       // reuse as Raw(x-bpp)
163.2322 -            jb davg8lp
163.2323 -        } // end _asm block
163.2324 -      }
163.2325 -      break;
163.2326 -      default:                  // bpp greater than 8
163.2327 -      {
163.2328 -        _asm {
163.2329 -            movq mm5, LBCarryMask
163.2330 -            // Re-init address pointers and offset
163.2331 -            mov ebx, diff       // ebx ==> x = offset to alignment boundary
163.2332 -            mov edi, row        // edi ==> Avg(x)
163.2333 -            movq mm4, HBClearMask
163.2334 -            mov edx, edi
163.2335 -            mov esi, prev_row   // esi ==> Prior(x)
163.2336 -            sub edx, bpp        // edx ==> Raw(x-bpp)
163.2337 -davgAlp:
163.2338 -            movq mm0, [edi + ebx]
163.2339 -            movq mm3, mm5
163.2340 -            movq mm1, [esi + ebx]
163.2341 -            pand mm3, mm1       // get lsb for each prev_row byte
163.2342 -            movq mm2, [edx + ebx]
163.2343 -            psrlq mm1, 1        // divide prev_row bytes by 2
163.2344 -            pand mm3, mm2       // get LBCarrys for each byte where both
163.2345 -                                // lsb's were == 1
163.2346 -            psrlq mm2, 1        // divide raw bytes by 2
163.2347 -            pand  mm1, mm4      // clear invalid bit 7 of each byte
163.2348 -            paddb mm0, mm3      // add LBCarrys to Avg for each byte
163.2349 -            pand  mm2, mm4      // clear invalid bit 7 of each byte
163.2350 -            paddb mm0, mm1      // add (Prev_row/2) to Avg for each byte
163.2351 -            add ebx, 8
163.2352 -            paddb mm0, mm2      // add (Raw/2) to Avg for each byte
163.2353 -            cmp ebx, MMXLength
163.2354 -            movq [edi + ebx - 8], mm0
163.2355 -            jb davgAlp
163.2356 -        } // end _asm block
163.2357 -      }
163.2358 -      break;
163.2359 -   }                         // end switch ( bpp )
163.2360 -
163.2361 -   _asm {
163.2362 -         // MMX acceleration complete now do clean-up
163.2363 -         // Check if any remaining bytes left to decode
163.2364 -         mov ebx, MMXLength    // ebx ==> x = offset bytes remaining after MMX
163.2365 -         mov edi, row          // edi ==> Avg(x)
163.2366 -         cmp ebx, FullLength   // Test if offset at end of array
163.2367 -         jnb davgend
163.2368 -         // Do Paeth decode for remaining bytes
163.2369 -         mov esi, prev_row     // esi ==> Prior(x)
163.2370 -         mov edx, edi
163.2371 -         xor ecx, ecx          // zero ecx before using cl & cx in loop below
163.2372 -         sub edx, bpp          // edx ==> Raw(x-bpp)
163.2373 -davglp2:
163.2374 -         // Raw(x) = Avg(x) + ((Raw(x-bpp) + Prior(x))/2)
163.2375 -         xor eax, eax
163.2376 -         mov cl, [esi + ebx]   // load cl with Prior(x)
163.2377 -         mov al, [edx + ebx]   // load al with Raw(x-bpp)
163.2378 -         add ax, cx
163.2379 -         inc ebx
163.2380 -         shr ax, 1              // divide by 2
163.2381 -         add al, [edi+ebx-1]    // Add Avg(x); -1 to offset inc ebx
163.2382 -         cmp ebx, FullLength    // Check if at end of array
163.2383 -         mov [edi+ebx-1], al    // Write back Raw(x);
163.2384 -                          // mov does not affect flags; -1 to offset inc ebx
163.2385 -         jb davglp2
163.2386 -davgend:
163.2387 -         emms             // End MMX instructions; prep for possible FP instrs.
163.2388 -   } // end _asm block
163.2389 -}
163.2390 -
163.2391 -// Optimized code for PNG Paeth filter decoder
163.2392 -void /* PRIVATE */
163.2393 -png_read_filter_row_mmx_paeth(png_row_infop row_info, png_bytep row,
163.2394 -                              png_bytep prev_row)
163.2395 -{
163.2396 -   png_uint_32 FullLength;
163.2397 -   png_uint_32 MMXLength;
163.2398 -   //png_uint_32 len;
163.2399 -   int bpp;
163.2400 -   int diff;
163.2401 -   //int ptemp;
163.2402 -   int patemp, pbtemp, pctemp;
163.2403 -
163.2404 -   bpp = (row_info->pixel_depth + 7) >> 3; // Get # bytes per pixel
163.2405 -   FullLength  = row_info->rowbytes; // # of bytes to filter
163.2406 -   _asm
163.2407 -   {
163.2408 -         xor ebx, ebx        // ebx ==> x offset
163.2409 -         mov edi, row
163.2410 -         xor edx, edx        // edx ==> x-bpp offset
163.2411 -         mov esi, prev_row
163.2412 -         xor eax, eax
163.2413 -
163.2414 -         // Compute the Raw value for the first bpp bytes
163.2415 -         // Note: the formula works out to be always
163.2416 -         //   Paeth(x) = Raw(x) + Prior(x)      where x < bpp
163.2417 -dpthrlp:
163.2418 -         mov al, [edi + ebx]
163.2419 -         add al, [esi + ebx]
163.2420 -         inc ebx
163.2421 -         cmp ebx, bpp
163.2422 -         mov [edi + ebx - 1], al
163.2423 -         jb dpthrlp
163.2424 -         // get # of bytes to alignment
163.2425 -         mov diff, edi         // take start of row
163.2426 -         add diff, ebx         // add bpp
163.2427 -         xor ecx, ecx
163.2428 -         add diff, 0xf         // add 7 + 8 to incr past alignment boundary
163.2429 -         and diff, 0xfffffff8  // mask to alignment boundary
163.2430 -         sub diff, edi         // subtract from start ==> value ebx at alignment
163.2431 -         jz dpthgo
163.2432 -         // fix alignment
163.2433 -dpthlp1:
163.2434 -         xor eax, eax
163.2435 -         // pav = p - a = (a + b - c) - a = b - c
163.2436 -         mov al, [esi + ebx]   // load Prior(x) into al
163.2437 -         mov cl, [esi + edx]   // load Prior(x-bpp) into cl
163.2438 -         sub eax, ecx          // subtract Prior(x-bpp)
163.2439 -         mov patemp, eax       // Save pav for later use
163.2440 -         xor eax, eax
163.2441 -         // pbv = p - b = (a + b - c) - b = a - c
163.2442 -         mov al, [edi + edx]   // load Raw(x-bpp) into al
163.2443 -         sub eax, ecx          // subtract Prior(x-bpp)
163.2444 -         mov ecx, eax
163.2445 -         // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
163.2446 -         add eax, patemp       // pcv = pav + pbv
163.2447 -         // pc = abs(pcv)
163.2448 -         test eax, 0x80000000
163.2449 -         jz dpthpca
163.2450 -         neg eax               // reverse sign of neg values
163.2451 -dpthpca:
163.2452 -         mov pctemp, eax       // save pc for later use
163.2453 -         // pb = abs(pbv)
163.2454 -         test ecx, 0x80000000
163.2455 -         jz dpthpba
163.2456 -         neg ecx               // reverse sign of neg values
163.2457 -dpthpba:
163.2458 -         mov pbtemp, ecx       // save pb for later use
163.2459 -         // pa = abs(pav)
163.2460 -         mov eax, patemp
163.2461 -         test eax, 0x80000000
163.2462 -         jz dpthpaa
163.2463 -         neg eax               // reverse sign of neg values
163.2464 -dpthpaa:
163.2465 -         mov patemp, eax       // save pa for later use
163.2466 -         // test if pa <= pb
163.2467 -         cmp eax, ecx
163.2468 -         jna dpthabb
163.2469 -         // pa > pb; now test if pb <= pc
163.2470 -         cmp ecx, pctemp
163.2471 -         jna dpthbbc
163.2472 -         // pb > pc; Raw(x) = Paeth(x) + Prior(x-bpp)
163.2473 -         mov cl, [esi + edx]  // load Prior(x-bpp) into cl
163.2474 -         jmp dpthpaeth
163.2475 -dpthbbc:
163.2476 -         // pb <= pc; Raw(x) = Paeth(x) + Prior(x)
163.2477 -         mov cl, [esi + ebx]   // load Prior(x) into cl
163.2478 -         jmp dpthpaeth
163.2479 -dpthabb:
163.2480 -         // pa <= pb; now test if pa <= pc
163.2481 -         cmp eax, pctemp
163.2482 -         jna dpthabc
163.2483 -         // pa > pc; Raw(x) = Paeth(x) + Prior(x-bpp)
163.2484 -         mov cl, [esi + edx]  // load Prior(x-bpp) into cl
163.2485 -         jmp dpthpaeth
163.2486 -dpthabc:
163.2487 -         // pa <= pc; Raw(x) = Paeth(x) + Raw(x-bpp)
163.2488 -         mov cl, [edi + edx]  // load Raw(x-bpp) into cl
163.2489 -dpthpaeth:
163.2490 -         inc ebx
163.2491 -         inc edx
163.2492 -         // Raw(x) = (Paeth(x) + Paeth_Predictor( a, b, c )) mod 256
163.2493 -         add [edi + ebx - 1], cl
163.2494 -         cmp ebx, diff
163.2495 -         jb dpthlp1
163.2496 -dpthgo:
163.2497 -         mov ecx, FullLength
163.2498 -         mov eax, ecx
163.2499 -         sub eax, ebx          // subtract alignment fix
163.2500 -         and eax, 0x00000007   // calc bytes over mult of 8
163.2501 -         sub ecx, eax          // drop over bytes from original length
163.2502 -         mov MMXLength, ecx
163.2503 -   } // end _asm block
163.2504 -   // Now do the math for the rest of the row
163.2505 -   switch ( bpp )
163.2506 -   {
163.2507 -      case 3:
163.2508 -      {
163.2509 -         ActiveMask.use = 0x0000000000ffffff;
163.2510 -         ActiveMaskEnd.use = 0xffff000000000000;
163.2511 -         ShiftBpp.use = 24;    // == bpp(3) * 8
163.2512 -         ShiftRem.use = 40;    // == 64 - 24
163.2513 -         _asm
163.2514 -         {
163.2515 -            mov ebx, diff
163.2516 -            mov edi, row
163.2517 -            mov esi, prev_row
163.2518 -            pxor mm0, mm0
163.2519 -            // PRIME the pump (load the first Raw(x-bpp) data set
163.2520 -            movq mm1, [edi+ebx-8]
163.2521 -dpth3lp:
163.2522 -            psrlq mm1, ShiftRem     // shift last 3 bytes to 1st 3 bytes
163.2523 -            movq mm2, [esi + ebx]   // load b=Prior(x)
163.2524 -            punpcklbw mm1, mm0      // Unpack High bytes of a
163.2525 -            movq mm3, [esi+ebx-8]   // Prep c=Prior(x-bpp) bytes
163.2526 -            punpcklbw mm2, mm0      // Unpack High bytes of b
163.2527 -            psrlq mm3, ShiftRem     // shift last 3 bytes to 1st 3 bytes
163.2528 -            // pav = p - a = (a + b - c) - a = b - c
163.2529 -            movq mm4, mm2
163.2530 -            punpcklbw mm3, mm0      // Unpack High bytes of c
163.2531 -            // pbv = p - b = (a + b - c) - b = a - c
163.2532 -            movq mm5, mm1
163.2533 -            psubw mm4, mm3
163.2534 -            pxor mm7, mm7
163.2535 -            // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
163.2536 -            movq mm6, mm4
163.2537 -            psubw mm5, mm3
163.2538 -
163.2539 -            // pa = abs(p-a) = abs(pav)
163.2540 -            // pb = abs(p-b) = abs(pbv)
163.2541 -            // pc = abs(p-c) = abs(pcv)
163.2542 -            pcmpgtw mm0, mm4    // Create mask pav bytes < 0
163.2543 -            paddw mm6, mm5
163.2544 -            pand mm0, mm4       // Only pav bytes < 0 in mm7
163.2545 -            pcmpgtw mm7, mm5    // Create mask pbv bytes < 0
163.2546 -            psubw mm4, mm0
163.2547 -            pand mm7, mm5       // Only pbv bytes < 0 in mm0
163.2548 -            psubw mm4, mm0
163.2549 -            psubw mm5, mm7
163.2550 -            pxor mm0, mm0
163.2551 -            pcmpgtw mm0, mm6    // Create mask pcv bytes < 0
163.2552 -            pand mm0, mm6       // Only pav bytes < 0 in mm7
163.2553 -            psubw mm5, mm7
163.2554 -            psubw mm6, mm0
163.2555 -            //  test pa <= pb
163.2556 -            movq mm7, mm4
163.2557 -            psubw mm6, mm0
163.2558 -            pcmpgtw mm7, mm5    // pa > pb?
163.2559 -            movq mm0, mm7
163.2560 -            // use mm7 mask to merge pa & pb
163.2561 -            pand mm5, mm7
163.2562 -            // use mm0 mask copy to merge a & b
163.2563 -            pand mm2, mm0
163.2564 -            pandn mm7, mm4
163.2565 -            pandn mm0, mm1
163.2566 -            paddw mm7, mm5
163.2567 -            paddw mm0, mm2
163.2568 -            //  test  ((pa <= pb)? pa:pb) <= pc
163.2569 -            pcmpgtw mm7, mm6       // pab > pc?
163.2570 -            pxor mm1, mm1
163.2571 -            pand mm3, mm7
163.2572 -            pandn mm7, mm0
163.2573 -            paddw mm7, mm3
163.2574 -            pxor mm0, mm0
163.2575 -            packuswb mm7, mm1
163.2576 -            movq mm3, [esi + ebx]   // load c=Prior(x-bpp)
163.2577 -            pand mm7, ActiveMask
163.2578 -            movq mm2, mm3           // load b=Prior(x) step 1
163.2579 -            paddb mm7, [edi + ebx]  // add Paeth predictor with Raw(x)
163.2580 -            punpcklbw mm3, mm0      // Unpack High bytes of c
163.2581 -            movq [edi + ebx], mm7   // write back updated value
163.2582 -            movq mm1, mm7           // Now mm1 will be used as Raw(x-bpp)
163.2583 -            // Now do Paeth for 2nd set of bytes (3-5)
163.2584 -            psrlq mm2, ShiftBpp     // load b=Prior(x) step 2
163.2585 -            punpcklbw mm1, mm0      // Unpack High bytes of a
163.2586 -            pxor mm7, mm7
163.2587 -            punpcklbw mm2, mm0      // Unpack High bytes of b
163.2588 -            // pbv = p - b = (a + b - c) - b = a - c
163.2589 -            movq mm5, mm1
163.2590 -            // pav = p - a = (a + b - c) - a = b - c
163.2591 -            movq mm4, mm2
163.2592 -            psubw mm5, mm3
163.2593 -            psubw mm4, mm3
163.2594 -            // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) =
163.2595 -            //       pav + pbv = pbv + pav
163.2596 -            movq mm6, mm5
163.2597 -            paddw mm6, mm4
163.2598 -
163.2599 -            // pa = abs(p-a) = abs(pav)
163.2600 -            // pb = abs(p-b) = abs(pbv)
163.2601 -            // pc = abs(p-c) = abs(pcv)
163.2602 -            pcmpgtw mm0, mm5       // Create mask pbv bytes < 0
163.2603 -            pcmpgtw mm7, mm4       // Create mask pav bytes < 0
163.2604 -            pand mm0, mm5          // Only pbv bytes < 0 in mm0
163.2605 -            pand mm7, mm4          // Only pav bytes < 0 in mm7
163.2606 -            psubw mm5, mm0
163.2607 -            psubw mm4, mm7
163.2608 -            psubw mm5, mm0
163.2609 -            psubw mm4, mm7
163.2610 -            pxor mm0, mm0
163.2611 -            pcmpgtw mm0, mm6       // Create mask pcv bytes < 0
163.2612 -            pand mm0, mm6          // Only pav bytes < 0 in mm7
163.2613 -            psubw mm6, mm0
163.2614 -            //  test pa <= pb
163.2615 -            movq mm7, mm4
163.2616 -            psubw mm6, mm0
163.2617 -            pcmpgtw mm7, mm5       // pa > pb?
163.2618 -            movq mm0, mm7
163.2619 -            // use mm7 mask to merge pa & pb
163.2620 -            pand mm5, mm7
163.2621 -            // use mm0 mask copy to merge a & b
163.2622 -            pand mm2, mm0
163.2623 -            pandn mm7, mm4
163.2624 -            pandn mm0, mm1
163.2625 -            paddw mm7, mm5
163.2626 -            paddw mm0, mm2
163.2627 -            //  test  ((pa <= pb)? pa:pb) <= pc
163.2628 -            pcmpgtw mm7, mm6       // pab > pc?
163.2629 -            movq mm2, [esi + ebx]  // load b=Prior(x)
163.2630 -            pand mm3, mm7
163.2631 -            pandn mm7, mm0
163.2632 -            pxor mm1, mm1
163.2633 -            paddw mm7, mm3
163.2634 -            pxor mm0, mm0
163.2635 -            packuswb mm7, mm1
163.2636 -            movq mm3, mm2           // load c=Prior(x-bpp) step 1
163.2637 -            pand mm7, ActiveMask
163.2638 -            punpckhbw mm2, mm0      // Unpack High bytes of b
163.2639 -            psllq mm7, ShiftBpp     // Shift bytes to 2nd group of 3 bytes
163.2640 -             // pav = p - a = (a + b - c) - a = b - c
163.2641 -            movq mm4, mm2
163.2642 -            paddb mm7, [edi + ebx]  // add Paeth predictor with Raw(x)
163.2643 -            psllq mm3, ShiftBpp     // load c=Prior(x-bpp) step 2
163.2644 -            movq [edi + ebx], mm7   // write back updated value
163.2645 -            movq mm1, mm7
163.2646 -            punpckhbw mm3, mm0      // Unpack High bytes of c
163.2647 -            psllq mm1, ShiftBpp     // Shift bytes
163.2648 -                                    // Now mm1 will be used as Raw(x-bpp)
163.2649 -            // Now do Paeth for 3rd, and final, set of bytes (6-7)
163.2650 -            pxor mm7, mm7
163.2651 -            punpckhbw mm1, mm0      // Unpack High bytes of a
163.2652 -            psubw mm4, mm3
163.2653 -            // pbv = p - b = (a + b - c) - b = a - c
163.2654 -            movq mm5, mm1
163.2655 -            // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
163.2656 -            movq mm6, mm4
163.2657 -            psubw mm5, mm3
163.2658 -            pxor mm0, mm0
163.2659 -            paddw mm6, mm5
163.2660 -
163.2661 -            // pa = abs(p-a) = abs(pav)
163.2662 -            // pb = abs(p-b) = abs(pbv)
163.2663 -            // pc = abs(p-c) = abs(pcv)
163.2664 -            pcmpgtw mm0, mm4    // Create mask pav bytes < 0
163.2665 -            pcmpgtw mm7, mm5    // Create mask pbv bytes < 0
163.2666 -            pand mm0, mm4       // Only pav bytes < 0 in mm7
163.2667 -            pand mm7, mm5       // Only pbv bytes < 0 in mm0
163.2668 -            psubw mm4, mm0
163.2669 -            psubw mm5, mm7
163.2670 -            psubw mm4, mm0
163.2671 -            psubw mm5, mm7
163.2672 -            pxor mm0, mm0
163.2673 -            pcmpgtw mm0, mm6    // Create mask pcv bytes < 0
163.2674 -            pand mm0, mm6       // Only pav bytes < 0 in mm7
163.2675 -            psubw mm6, mm0
163.2676 -            //  test pa <= pb
163.2677 -            movq mm7, mm4
163.2678 -            psubw mm6, mm0
163.2679 -            pcmpgtw mm7, mm5    // pa > pb?
163.2680 -            movq mm0, mm7
163.2681 -            // use mm0 mask copy to merge a & b
163.2682 -            pand mm2, mm0
163.2683 -            // use mm7 mask to merge pa & pb
163.2684 -            pand mm5, mm7
163.2685 -            pandn mm0, mm1
163.2686 -            pandn mm7, mm4
163.2687 -            paddw mm0, mm2
163.2688 -            paddw mm7, mm5
163.2689 -            //  test  ((pa <= pb)? pa:pb) <= pc
163.2690 -            pcmpgtw mm7, mm6    // pab > pc?
163.2691 -            pand mm3, mm7
163.2692 -            pandn mm7, mm0
163.2693 -            paddw mm7, mm3
163.2694 -            pxor mm1, mm1
163.2695 -            packuswb mm1, mm7
163.2696 -            // Step ebx to next set of 8 bytes and repeat loop til done
163.2697 -            add ebx, 8
163.2698 -            pand mm1, ActiveMaskEnd
163.2699 -            paddb mm1, [edi + ebx - 8] // add Paeth predictor with Raw(x)
163.2700 -
163.2701 -            cmp ebx, MMXLength
163.2702 -            pxor mm0, mm0              // pxor does not affect flags
163.2703 -            movq [edi + ebx - 8], mm1  // write back updated value
163.2704 -                                 // mm1 will be used as Raw(x-bpp) next loop
163.2705 -                           // mm3 ready to be used as Prior(x-bpp) next loop
163.2706 -            jb dpth3lp
163.2707 -         } // end _asm block
163.2708 -      }
163.2709 -      break;
163.2710 -
163.2711 -      case 6:
163.2712 -      case 7:
163.2713 -      case 5:
163.2714 -      {
163.2715 -         ActiveMask.use  = 0x00000000ffffffff;
163.2716 -         ActiveMask2.use = 0xffffffff00000000;
163.2717 -         ShiftBpp.use = bpp << 3;    // == bpp * 8
163.2718 -         ShiftRem.use = 64 - ShiftBpp.use;
163.2719 -         _asm
163.2720 -         {
163.2721 -            mov ebx, diff
163.2722 -            mov edi, row
163.2723 -            mov esi, prev_row
163.2724 -            // PRIME the pump (load the first Raw(x-bpp) data set
163.2725 -            movq mm1, [edi+ebx-8]
163.2726 -            pxor mm0, mm0
163.2727 -dpth6lp:
163.2728 -            // Must shift to position Raw(x-bpp) data
163.2729 -            psrlq mm1, ShiftRem
163.2730 -            // Do first set of 4 bytes
163.2731 -            movq mm3, [esi+ebx-8]      // read c=Prior(x-bpp) bytes
163.2732 -            punpcklbw mm1, mm0      // Unpack Low bytes of a
163.2733 -            movq mm2, [esi + ebx]   // load b=Prior(x)
163.2734 -            punpcklbw mm2, mm0      // Unpack Low bytes of b
163.2735 -            // Must shift to position Prior(x-bpp) data
163.2736 -            psrlq mm3, ShiftRem
163.2737 -            // pav = p - a = (a + b - c) - a = b - c
163.2738 -            movq mm4, mm2
163.2739 -            punpcklbw mm3, mm0      // Unpack Low bytes of c
163.2740 -            // pbv = p - b = (a + b - c) - b = a - c
163.2741 -            movq mm5, mm1
163.2742 -            psubw mm4, mm3
163.2743 -            pxor mm7, mm7
163.2744 -            // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
163.2745 -            movq mm6, mm4
163.2746 -            psubw mm5, mm3
163.2747 -            // pa = abs(p-a) = abs(pav)
163.2748 -            // pb = abs(p-b) = abs(pbv)
163.2749 -            // pc = abs(p-c) = abs(pcv)
163.2750 -            pcmpgtw mm0, mm4    // Create mask pav bytes < 0
163.2751 -            paddw mm6, mm5
163.2752 -            pand mm0, mm4       // Only pav bytes < 0 in mm7
163.2753 -            pcmpgtw mm7, mm5    // Create mask pbv bytes < 0
163.2754 -            psubw mm4, mm0
163.2755 -            pand mm7, mm5       // Only pbv bytes < 0 in mm0
163.2756 -            psubw mm4, mm0
163.2757 -            psubw mm5, mm7
163.2758 -            pxor mm0, mm0
163.2759 -            pcmpgtw mm0, mm6    // Create mask pcv bytes < 0
163.2760 -            pand mm0, mm6       // Only pav bytes < 0 in mm7
163.2761 -            psubw mm5, mm7
163.2762 -            psubw mm6, mm0
163.2763 -            //  test pa <= pb
163.2764 -            movq mm7, mm4
163.2765 -            psubw mm6, mm0
163.2766 -            pcmpgtw mm7, mm5    // pa > pb?
163.2767 -            movq mm0, mm7
163.2768 -            // use mm7 mask to merge pa & pb
163.2769 -            pand mm5, mm7
163.2770 -            // use mm0 mask copy to merge a & b
163.2771 -            pand mm2, mm0
163.2772 -            pandn mm7, mm4
163.2773 -            pandn mm0, mm1
163.2774 -            paddw mm7, mm5
163.2775 -            paddw mm0, mm2
163.2776 -            //  test  ((pa <= pb)? pa:pb) <= pc
163.2777 -            pcmpgtw mm7, mm6    // pab > pc?
163.2778 -            pxor mm1, mm1
163.2779 -            pand mm3, mm7
163.2780 -            pandn mm7, mm0
163.2781 -            paddw mm7, mm3
163.2782 -            pxor mm0, mm0
163.2783 -            packuswb mm7, mm1
163.2784 -            movq mm3, [esi + ebx - 8]  // load c=Prior(x-bpp)
163.2785 -            pand mm7, ActiveMask
163.2786 -            psrlq mm3, ShiftRem
163.2787 -            movq mm2, [esi + ebx]      // load b=Prior(x) step 1
163.2788 -            paddb mm7, [edi + ebx]     // add Paeth predictor with Raw(x)
163.2789 -            movq mm6, mm2
163.2790 -            movq [edi + ebx], mm7      // write back updated value
163.2791 -            movq mm1, [edi+ebx-8]
163.2792 -            psllq mm6, ShiftBpp
163.2793 -            movq mm5, mm7
163.2794 -            psrlq mm1, ShiftRem
163.2795 -            por mm3, mm6
163.2796 -            psllq mm5, ShiftBpp
163.2797 -            punpckhbw mm3, mm0         // Unpack High bytes of c
163.2798 -            por mm1, mm5
163.2799 -            // Do second set of 4 bytes
163.2800 -            punpckhbw mm2, mm0         // Unpack High bytes of b
163.2801 -            punpckhbw mm1, mm0         // Unpack High bytes of a
163.2802 -            // pav = p - a = (a + b - c) - a = b - c
163.2803 -            movq mm4, mm2
163.2804 -            // pbv = p - b = (a + b - c) - b = a - c
163.2805 -            movq mm5, mm1
163.2806 -            psubw mm4, mm3
163.2807 -            pxor mm7, mm7
163.2808 -            // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
163.2809 -            movq mm6, mm4
163.2810 -            psubw mm5, mm3
163.2811 -            // pa = abs(p-a) = abs(pav)
163.2812 -            // pb = abs(p-b) = abs(pbv)
163.2813 -            // pc = abs(p-c) = abs(pcv)
163.2814 -            pcmpgtw mm0, mm4       // Create mask pav bytes < 0
163.2815 -            paddw mm6, mm5
163.2816 -            pand mm0, mm4          // Only pav bytes < 0 in mm7
163.2817 -            pcmpgtw mm7, mm5       // Create mask pbv bytes < 0
163.2818 -            psubw mm4, mm0
163.2819 -            pand mm7, mm5          // Only pbv bytes < 0 in mm0
163.2820 -            psubw mm4, mm0
163.2821 -            psubw mm5, mm7
163.2822 -            pxor mm0, mm0
163.2823 -            pcmpgtw mm0, mm6       // Create mask pcv bytes < 0
163.2824 -            pand mm0, mm6          // Only pav bytes < 0 in mm7
163.2825 -            psubw mm5, mm7
163.2826 -            psubw mm6, mm0
163.2827 -            //  test pa <= pb
163.2828 -            movq mm7, mm4
163.2829 -            psubw mm6, mm0
163.2830 -            pcmpgtw mm7, mm5       // pa > pb?
163.2831 -            movq mm0, mm7
163.2832 -            // use mm7 mask to merge pa & pb
163.2833 -            pand mm5, mm7
163.2834 -            // use mm0 mask copy to merge a & b
163.2835 -            pand mm2, mm0
163.2836 -            pandn mm7, mm4
163.2837 -            pandn mm0, mm1
163.2838 -            paddw mm7, mm5
163.2839 -            paddw mm0, mm2
163.2840 -            //  test  ((pa <= pb)? pa:pb) <= pc
163.2841 -            pcmpgtw mm7, mm6           // pab > pc?
163.2842 -            pxor mm1, mm1
163.2843 -            pand mm3, mm7
163.2844 -            pandn mm7, mm0
163.2845 -            pxor mm1, mm1
163.2846 -            paddw mm7, mm3
163.2847 -            pxor mm0, mm0
163.2848 -            // Step ex to next set of 8 bytes and repeat loop til done
163.2849 -            add ebx, 8
163.2850 -            packuswb mm1, mm7
163.2851 -            paddb mm1, [edi + ebx - 8]     // add Paeth predictor with Raw(x)
163.2852 -            cmp ebx, MMXLength
163.2853 -            movq [edi + ebx - 8], mm1      // write back updated value
163.2854 -                                // mm1 will be used as Raw(x-bpp) next loop
163.2855 -            jb dpth6lp
163.2856 -         } // end _asm block
163.2857 -      }
163.2858 -      break;
163.2859 -
163.2860 -      case 4:
163.2861 -      {
163.2862 -         ActiveMask.use  = 0x00000000ffffffff;
163.2863 -         _asm {
163.2864 -            mov ebx, diff
163.2865 -            mov edi, row
163.2866 -            mov esi, prev_row
163.2867 -            pxor mm0, mm0
163.2868 -            // PRIME the pump (load the first Raw(x-bpp) data set
163.2869 -            movq mm1, [edi+ebx-8]    // Only time should need to read
163.2870 -                                     //  a=Raw(x-bpp) bytes
163.2871 -dpth4lp:
163.2872 -            // Do first set of 4 bytes
163.2873 -            movq mm3, [esi+ebx-8]    // read c=Prior(x-bpp) bytes
163.2874 -            punpckhbw mm1, mm0       // Unpack Low bytes of a
163.2875 -            movq mm2, [esi + ebx]    // load b=Prior(x)
163.2876 -            punpcklbw mm2, mm0       // Unpack High bytes of b
163.2877 -            // pav = p - a = (a + b - c) - a = b - c
163.2878 -            movq mm4, mm2
163.2879 -            punpckhbw mm3, mm0       // Unpack High bytes of c
163.2880 -            // pbv = p - b = (a + b - c) - b = a - c
163.2881 -            movq mm5, mm1
163.2882 -            psubw mm4, mm3
163.2883 -            pxor mm7, mm7
163.2884 -            // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
163.2885 -            movq mm6, mm4
163.2886 -            psubw mm5, mm3
163.2887 -            // pa = abs(p-a) = abs(pav)
163.2888 -            // pb = abs(p-b) = abs(pbv)
163.2889 -            // pc = abs(p-c) = abs(pcv)
163.2890 -            pcmpgtw mm0, mm4       // Create mask pav bytes < 0
163.2891 -            paddw mm6, mm5
163.2892 -            pand mm0, mm4          // Only pav bytes < 0 in mm7
163.2893 -            pcmpgtw mm7, mm5       // Create mask pbv bytes < 0
163.2894 -            psubw mm4, mm0
163.2895 -            pand mm7, mm5          // Only pbv bytes < 0 in mm0
163.2896 -            psubw mm4, mm0
163.2897 -            psubw mm5, mm7
163.2898 -            pxor mm0, mm0
163.2899 -            pcmpgtw mm0, mm6       // Create mask pcv bytes < 0
163.2900 -            pand mm0, mm6          // Only pav bytes < 0 in mm7
163.2901 -            psubw mm5, mm7
163.2902 -            psubw mm6, mm0
163.2903 -            //  test pa <= pb
163.2904 -            movq mm7, mm4
163.2905 -            psubw mm6, mm0
163.2906 -            pcmpgtw mm7, mm5       // pa > pb?
163.2907 -            movq mm0, mm7
163.2908 -            // use mm7 mask to merge pa & pb
163.2909 -            pand mm5, mm7
163.2910 -            // use mm0 mask copy to merge a & b
163.2911 -            pand mm2, mm0
163.2912 -            pandn mm7, mm4
163.2913 -            pandn mm0, mm1
163.2914 -            paddw mm7, mm5
163.2915 -            paddw mm0, mm2
163.2916 -            //  test  ((pa <= pb)? pa:pb) <= pc
163.2917 -            pcmpgtw mm7, mm6       // pab > pc?
163.2918 -            pxor mm1, mm1
163.2919 -            pand mm3, mm7
163.2920 -            pandn mm7, mm0
163.2921 -            paddw mm7, mm3
163.2922 -            pxor mm0, mm0
163.2923 -            packuswb mm7, mm1
163.2924 -            movq mm3, [esi + ebx]      // load c=Prior(x-bpp)
163.2925 -            pand mm7, ActiveMask
163.2926 -            movq mm2, mm3              // load b=Prior(x) step 1
163.2927 -            paddb mm7, [edi + ebx]     // add Paeth predictor with Raw(x)
163.2928 -            punpcklbw mm3, mm0         // Unpack High bytes of c
163.2929 -            movq [edi + ebx], mm7      // write back updated value
163.2930 -            movq mm1, mm7              // Now mm1 will be used as Raw(x-bpp)
163.2931 -            // Do second set of 4 bytes
163.2932 -            punpckhbw mm2, mm0         // Unpack Low bytes of b
163.2933 -            punpcklbw mm1, mm0         // Unpack Low bytes of a
163.2934 -            // pav = p - a = (a + b - c) - a = b - c
163.2935 -            movq mm4, mm2
163.2936 -            // pbv = p - b = (a + b - c) - b = a - c
163.2937 -            movq mm5, mm1
163.2938 -            psubw mm4, mm3
163.2939 -            pxor mm7, mm7
163.2940 -            // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
163.2941 -            movq mm6, mm4
163.2942 -            psubw mm5, mm3
163.2943 -            // pa = abs(p-a) = abs(pav)
163.2944 -            // pb = abs(p-b) = abs(pbv)
163.2945 -            // pc = abs(p-c) = abs(pcv)
163.2946 -            pcmpgtw mm0, mm4       // Create mask pav bytes < 0
163.2947 -            paddw mm6, mm5
163.2948 -            pand mm0, mm4          // Only pav bytes < 0 in mm7
163.2949 -            pcmpgtw mm7, mm5       // Create mask pbv bytes < 0
163.2950 -            psubw mm4, mm0
163.2951 -            pand mm7, mm5          // Only pbv bytes < 0 in mm0
163.2952 -            psubw mm4, mm0
163.2953 -            psubw mm5, mm7
163.2954 -            pxor mm0, mm0
163.2955 -            pcmpgtw mm0, mm6       // Create mask pcv bytes < 0
163.2956 -            pand mm0, mm6          // Only pav bytes < 0 in mm7
163.2957 -            psubw mm5, mm7
163.2958 -            psubw mm6, mm0
163.2959 -            //  test pa <= pb
163.2960 -            movq mm7, mm4
163.2961 -            psubw mm6, mm0
163.2962 -            pcmpgtw mm7, mm5       // pa > pb?
163.2963 -            movq mm0, mm7
163.2964 -            // use mm7 mask to merge pa & pb
163.2965 -            pand mm5, mm7
163.2966 -            // use mm0 mask copy to merge a & b
163.2967 -            pand mm2, mm0
163.2968 -            pandn mm7, mm4
163.2969 -            pandn mm0, mm1
163.2970 -            paddw mm7, mm5
163.2971 -            paddw mm0, mm2
163.2972 -            //  test  ((pa <= pb)? pa:pb) <= pc
163.2973 -            pcmpgtw mm7, mm6       // pab > pc?
163.2974 -            pxor mm1, mm1
163.2975 -            pand mm3, mm7
163.2976 -            pandn mm7, mm0
163.2977 -            pxor mm1, mm1
163.2978 -            paddw mm7, mm3
163.2979 -            pxor mm0, mm0
163.2980 -            // Step ex to next set of 8 bytes and repeat loop til done
163.2981 -            add ebx, 8
163.2982 -            packuswb mm1, mm7
163.2983 -            paddb mm1, [edi + ebx - 8]     // add Paeth predictor with Raw(x)
163.2984 -            cmp ebx, MMXLength
163.2985 -            movq [edi + ebx - 8], mm1      // write back updated value
163.2986 -                                // mm1 will be used as Raw(x-bpp) next loop
163.2987 -            jb dpth4lp
163.2988 -         } // end _asm block
163.2989 -      }
163.2990 -      break;
163.2991 -      case 8:                          // bpp == 8
163.2992 -      {
163.2993 -         ActiveMask.use  = 0x00000000ffffffff;
163.2994 -         _asm {
163.2995 -            mov ebx, diff
163.2996 -            mov edi, row
163.2997 -            mov esi, prev_row
163.2998 -            pxor mm0, mm0
163.2999 -            // PRIME the pump (load the first Raw(x-bpp) data set
163.3000 -            movq mm1, [edi+ebx-8]      // Only time should need to read
163.3001 -                                       //  a=Raw(x-bpp) bytes
163.3002 -dpth8lp:
163.3003 -            // Do first set of 4 bytes
163.3004 -            movq mm3, [esi+ebx-8]      // read c=Prior(x-bpp) bytes
163.3005 -            punpcklbw mm1, mm0         // Unpack Low bytes of a
163.3006 -            movq mm2, [esi + ebx]      // load b=Prior(x)
163.3007 -            punpcklbw mm2, mm0         // Unpack Low bytes of b
163.3008 -            // pav = p - a = (a + b - c) - a = b - c
163.3009 -            movq mm4, mm2
163.3010 -            punpcklbw mm3, mm0         // Unpack Low bytes of c
163.3011 -            // pbv = p - b = (a + b - c) - b = a - c
163.3012 -            movq mm5, mm1
163.3013 -            psubw mm4, mm3
163.3014 -            pxor mm7, mm7
163.3015 -            // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
163.3016 -            movq mm6, mm4
163.3017 -            psubw mm5, mm3
163.3018 -            // pa = abs(p-a) = abs(pav)
163.3019 -            // pb = abs(p-b) = abs(pbv)
163.3020 -            // pc = abs(p-c) = abs(pcv)
163.3021 -            pcmpgtw mm0, mm4       // Create mask pav bytes < 0
163.3022 -            paddw mm6, mm5
163.3023 -            pand mm0, mm4          // Only pav bytes < 0 in mm7
163.3024 -            pcmpgtw mm7, mm5       // Create mask pbv bytes < 0
163.3025 -            psubw mm4, mm0
163.3026 -            pand mm7, mm5          // Only pbv bytes < 0 in mm0
163.3027 -            psubw mm4, mm0
163.3028 -            psubw mm5, mm7
163.3029 -            pxor mm0, mm0
163.3030 -            pcmpgtw mm0, mm6       // Create mask pcv bytes < 0
163.3031 -            pand mm0, mm6          // Only pav bytes < 0 in mm7
163.3032 -            psubw mm5, mm7
163.3033 -            psubw mm6, mm0
163.3034 -            //  test pa <= pb
163.3035 -            movq mm7, mm4
163.3036 -            psubw mm6, mm0
163.3037 -            pcmpgtw mm7, mm5       // pa > pb?
163.3038 -            movq mm0, mm7
163.3039 -            // use mm7 mask to merge pa & pb
163.3040 -            pand mm5, mm7
163.3041 -            // use mm0 mask copy to merge a & b
163.3042 -            pand mm2, mm0
163.3043 -            pandn mm7, mm4
163.3044 -            pandn mm0, mm1
163.3045 -            paddw mm7, mm5
163.3046 -            paddw mm0, mm2
163.3047 -            //  test  ((pa <= pb)? pa:pb) <= pc
163.3048 -            pcmpgtw mm7, mm6       // pab > pc?
163.3049 -            pxor mm1, mm1
163.3050 -            pand mm3, mm7
163.3051 -            pandn mm7, mm0
163.3052 -            paddw mm7, mm3
163.3053 -            pxor mm0, mm0
163.3054 -            packuswb mm7, mm1
163.3055 -            movq mm3, [esi+ebx-8]    // read c=Prior(x-bpp) bytes
163.3056 -            pand mm7, ActiveMask
163.3057 -            movq mm2, [esi + ebx]    // load b=Prior(x)
163.3058 -            paddb mm7, [edi + ebx]   // add Paeth predictor with Raw(x)
163.3059 -            punpckhbw mm3, mm0       // Unpack High bytes of c
163.3060 -            movq [edi + ebx], mm7    // write back updated value
163.3061 -            movq mm1, [edi+ebx-8]    // read a=Raw(x-bpp) bytes
163.3062 -
163.3063 -            // Do second set of 4 bytes
163.3064 -            punpckhbw mm2, mm0       // Unpack High bytes of b
163.3065 -            punpckhbw mm1, mm0       // Unpack High bytes of a
163.3066 -            // pav = p - a = (a + b - c) - a = b - c
163.3067 -            movq mm4, mm2
163.3068 -            // pbv = p - b = (a + b - c) - b = a - c
163.3069 -            movq mm5, mm1
163.3070 -            psubw mm4, mm3
163.3071 -            pxor mm7, mm7
163.3072 -            // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
163.3073 -            movq mm6, mm4
163.3074 -            psubw mm5, mm3
163.3075 -            // pa = abs(p-a) = abs(pav)
163.3076 -            // pb = abs(p-b) = abs(pbv)
163.3077 -            // pc = abs(p-c) = abs(pcv)
163.3078 -            pcmpgtw mm0, mm4       // Create mask pav bytes < 0
163.3079 -            paddw mm6, mm5
163.3080 -            pand mm0, mm4          // Only pav bytes < 0 in mm7
163.3081 -            pcmpgtw mm7, mm5       // Create mask pbv bytes < 0
163.3082 -            psubw mm4, mm0
163.3083 -            pand mm7, mm5          // Only pbv bytes < 0 in mm0
163.3084 -            psubw mm4, mm0
163.3085 -            psubw mm5, mm7
163.3086 -            pxor mm0, mm0
163.3087 -            pcmpgtw mm0, mm6       // Create mask pcv bytes < 0
163.3088 -            pand mm0, mm6          // Only pav bytes < 0 in mm7
163.3089 -            psubw mm5, mm7
163.3090 -            psubw mm6, mm0
163.3091 -            //  test pa <= pb
163.3092 -            movq mm7, mm4
163.3093 -            psubw mm6, mm0
163.3094 -            pcmpgtw mm7, mm5       // pa > pb?
163.3095 -            movq mm0, mm7
163.3096 -            // use mm7 mask to merge pa & pb
163.3097 -            pand mm5, mm7
163.3098 -            // use mm0 mask copy to merge a & b
163.3099 -            pand mm2, mm0
163.3100 -            pandn mm7, mm4
163.3101 -            pandn mm0, mm1
163.3102 -            paddw mm7, mm5
163.3103 -            paddw mm0, mm2
163.3104 -            //  test  ((pa <= pb)? pa:pb) <= pc
163.3105 -            pcmpgtw mm7, mm6       // pab > pc?
163.3106 -            pxor mm1, mm1
163.3107 -            pand mm3, mm7
163.3108 -            pandn mm7, mm0
163.3109 -            pxor mm1, mm1
163.3110 -            paddw mm7, mm3
163.3111 -            pxor mm0, mm0
163.3112 -            // Step ex to next set of 8 bytes and repeat loop til done
163.3113 -            add ebx, 8
163.3114 -            packuswb mm1, mm7
163.3115 -            paddb mm1, [edi + ebx - 8]     // add Paeth predictor with Raw(x)
163.3116 -            cmp ebx, MMXLength
163.3117 -            movq [edi + ebx - 8], mm1      // write back updated value
163.3118 -                            // mm1 will be used as Raw(x-bpp) next loop
163.3119 -            jb dpth8lp
163.3120 -         } // end _asm block
163.3121 -      }
163.3122 -      break;
163.3123 -
163.3124 -      case 1:                // bpp = 1
163.3125 -      case 2:                // bpp = 2
163.3126 -      default:               // bpp > 8
163.3127 -      {
163.3128 -         _asm {
163.3129 -            mov ebx, diff
163.3130 -            cmp ebx, FullLength
163.3131 -            jnb dpthdend
163.3132 -            mov edi, row
163.3133 -            mov esi, prev_row
163.3134 -            // Do Paeth decode for remaining bytes
163.3135 -            mov edx, ebx
163.3136 -            xor ecx, ecx        // zero ecx before using cl & cx in loop below
163.3137 -            sub edx, bpp        // Set edx = ebx - bpp
163.3138 -dpthdlp:
163.3139 -            xor eax, eax
163.3140 -            // pav = p - a = (a + b - c) - a = b - c
163.3141 -            mov al, [esi + ebx]        // load Prior(x) into al
163.3142 -            mov cl, [esi + edx]        // load Prior(x-bpp) into cl
163.3143 -            sub eax, ecx                 // subtract Prior(x-bpp)
163.3144 -            mov patemp, eax                 // Save pav for later use
163.3145 -            xor eax, eax
163.3146 -            // pbv = p - b = (a + b - c) - b = a - c
163.3147 -            mov al, [edi + edx]        // load Raw(x-bpp) into al
163.3148 -            sub eax, ecx                 // subtract Prior(x-bpp)
163.3149 -            mov ecx, eax
163.3150 -            // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
163.3151 -            add eax, patemp                 // pcv = pav + pbv
163.3152 -            // pc = abs(pcv)
163.3153 -            test eax, 0x80000000
163.3154 -            jz dpthdpca
163.3155 -            neg eax                     // reverse sign of neg values
163.3156 -dpthdpca:
163.3157 -            mov pctemp, eax             // save pc for later use
163.3158 -            // pb = abs(pbv)
163.3159 -            test ecx, 0x80000000
163.3160 -            jz dpthdpba
163.3161 -            neg ecx                     // reverse sign of neg values
163.3162 -dpthdpba:
163.3163 -            mov pbtemp, ecx             // save pb for later use
163.3164 -            // pa = abs(pav)
163.3165 -            mov eax, patemp
163.3166 -            test eax, 0x80000000
163.3167 -            jz dpthdpaa
163.3168 -            neg eax                     // reverse sign of neg values
163.3169 -dpthdpaa:
163.3170 -            mov patemp, eax             // save pa for later use
163.3171 -            // test if pa <= pb
163.3172 -            cmp eax, ecx
163.3173 -            jna dpthdabb
163.3174 -            // pa > pb; now test if pb <= pc
163.3175 -            cmp ecx, pctemp
163.3176 -            jna dpthdbbc
163.3177 -            // pb > pc; Raw(x) = Paeth(x) + Prior(x-bpp)
163.3178 -            mov cl, [esi + edx]  // load Prior(x-bpp) into cl
163.3179 -            jmp dpthdpaeth
163.3180 -dpthdbbc:
163.3181 -            // pb <= pc; Raw(x) = Paeth(x) + Prior(x)
163.3182 -            mov cl, [esi + ebx]        // load Prior(x) into cl
163.3183 -            jmp dpthdpaeth
163.3184 -dpthdabb:
163.3185 -            // pa <= pb; now test if pa <= pc
163.3186 -            cmp eax, pctemp
163.3187 -            jna dpthdabc
163.3188 -            // pa > pc; Raw(x) = Paeth(x) + Prior(x-bpp)
163.3189 -            mov cl, [esi + edx]  // load Prior(x-bpp) into cl
163.3190 -            jmp dpthdpaeth
163.3191 -dpthdabc:
163.3192 -            // pa <= pc; Raw(x) = Paeth(x) + Raw(x-bpp)
163.3193 -            mov cl, [edi + edx]  // load Raw(x-bpp) into cl
163.3194 -dpthdpaeth:
163.3195 -            inc ebx
163.3196 -            inc edx
163.3197 -            // Raw(x) = (Paeth(x) + Paeth_Predictor( a, b, c )) mod 256
163.3198 -            add [edi + ebx - 1], cl
163.3199 -            cmp ebx, FullLength
163.3200 -            jb dpthdlp
163.3201 -dpthdend:
163.3202 -         } // end _asm block
163.3203 -      }
163.3204 -      return;                   // No need to go further with this one
163.3205 -   }                         // end switch ( bpp )
163.3206 -   _asm
163.3207 -   {
163.3208 -         // MMX acceleration complete now do clean-up
163.3209 -         // Check if any remaining bytes left to decode
163.3210 -         mov ebx, MMXLength
163.3211 -         cmp ebx, FullLength
163.3212 -         jnb dpthend
163.3213 -         mov edi, row
163.3214 -         mov esi, prev_row
163.3215 -         // Do Paeth decode for remaining bytes
163.3216 -         mov edx, ebx
163.3217 -         xor ecx, ecx         // zero ecx before using cl & cx in loop below
163.3218 -         sub edx, bpp         // Set edx = ebx - bpp
163.3219 -dpthlp2:
163.3220 -         xor eax, eax
163.3221 -         // pav = p - a = (a + b - c) - a = b - c
163.3222 -         mov al, [esi + ebx]  // load Prior(x) into al
163.3223 -         mov cl, [esi + edx]  // load Prior(x-bpp) into cl
163.3224 -         sub eax, ecx         // subtract Prior(x-bpp)
163.3225 -         mov patemp, eax      // Save pav for later use
163.3226 -         xor eax, eax
163.3227 -         // pbv = p - b = (a + b - c) - b = a - c
163.3228 -         mov al, [edi + edx]  // load Raw(x-bpp) into al
163.3229 -         sub eax, ecx         // subtract Prior(x-bpp)
163.3230 -         mov ecx, eax
163.3231 -         // pcv = p - c = (a + b - c) -c = (a - c) + (b - c) = pav + pbv
163.3232 -         add eax, patemp      // pcv = pav + pbv
163.3233 -         // pc = abs(pcv)
163.3234 -         test eax, 0x80000000
163.3235 -         jz dpthpca2
163.3236 -         neg eax              // reverse sign of neg values
163.3237 -dpthpca2:
163.3238 -         mov pctemp, eax      // save pc for later use
163.3239 -         // pb = abs(pbv)
163.3240 -         test ecx, 0x80000000
163.3241 -         jz dpthpba2
163.3242 -         neg ecx              // reverse sign of neg values
163.3243 -dpthpba2:
163.3244 -         mov pbtemp, ecx      // save pb for later use
163.3245 -         // pa = abs(pav)
163.3246 -         mov eax, patemp
163.3247 -         test eax, 0x80000000
163.3248 -         jz dpthpaa2
163.3249 -         neg eax              // reverse sign of neg values
163.3250 -dpthpaa2:
163.3251 -         mov patemp, eax      // save pa for later use
163.3252 -         // test if pa <= pb
163.3253 -         cmp eax, ecx
163.3254 -         jna dpthabb2
163.3255 -         // pa > pb; now test if pb <= pc
163.3256 -         cmp ecx, pctemp
163.3257 -         jna dpthbbc2
163.3258 -         // pb > pc; Raw(x) = Paeth(x) + Prior(x-bpp)
163.3259 -         mov cl, [esi + edx]  // load Prior(x-bpp) into cl
163.3260 -         jmp dpthpaeth2
163.3261 -dpthbbc2:
163.3262 -         // pb <= pc; Raw(x) = Paeth(x) + Prior(x)
163.3263 -         mov cl, [esi + ebx]        // load Prior(x) into cl
163.3264 -         jmp dpthpaeth2
163.3265 -dpthabb2:
163.3266 -         // pa <= pb; now test if pa <= pc
163.3267 -         cmp eax, pctemp
163.3268 -         jna dpthabc2
163.3269 -         // pa > pc; Raw(x) = Paeth(x) + Prior(x-bpp)
163.3270 -         mov cl, [esi + edx]  // load Prior(x-bpp) into cl
163.3271 -         jmp dpthpaeth2
163.3272 -dpthabc2:
163.3273 -         // pa <= pc; Raw(x) = Paeth(x) + Raw(x-bpp)
163.3274 -         mov cl, [edi + edx]  // load Raw(x-bpp) into cl
163.3275 -dpthpaeth2:
163.3276 -         inc ebx
163.3277 -         inc edx
163.3278 -         // Raw(x) = (Paeth(x) + Paeth_Predictor( a, b, c )) mod 256
163.3279 -         add [edi + ebx - 1], cl
163.3280 -         cmp ebx, FullLength
163.3281 -         jb dpthlp2
163.3282 -dpthend:
163.3283 -         emms             // End MMX instructions; prep for possible FP instrs.
163.3284 -   } // end _asm block
163.3285 -}
163.3286 -
163.3287 -// Optimized code for PNG Sub filter decoder
163.3288 -void /* PRIVATE */
163.3289 -png_read_filter_row_mmx_sub(png_row_infop row_info, png_bytep row)
163.3290 -{
163.3291 -   //int test;
163.3292 -   int bpp;
163.3293 -   png_uint_32 FullLength;
163.3294 -   png_uint_32 MMXLength;
163.3295 -   int diff;
163.3296 -
163.3297 -   bpp = (row_info->pixel_depth + 7) >> 3; // Get # bytes per pixel
163.3298 -   FullLength  = row_info->rowbytes - bpp; // # of bytes to filter
163.3299 -   _asm {
163.3300 -        mov edi, row
163.3301 -        mov esi, edi               // lp = row
163.3302 -        add edi, bpp               // rp = row + bpp
163.3303 -        xor eax, eax
163.3304 -        // get # of bytes to alignment
163.3305 -        mov diff, edi               // take start of row
163.3306 -        add diff, 0xf               // add 7 + 8 to incr past
163.3307 -                                        // alignment boundary
163.3308 -        xor ebx, ebx
163.3309 -        and diff, 0xfffffff8        // mask to alignment boundary
163.3310 -        sub diff, edi               // subtract from start ==> value
163.3311 -                                        //  ebx at alignment
163.3312 -        jz dsubgo
163.3313 -        // fix alignment
163.3314 -dsublp1:
163.3315 -        mov al, [esi+ebx]
163.3316 -        add [edi+ebx], al
163.3317 -        inc ebx
163.3318 -        cmp ebx, diff
163.3319 -        jb dsublp1
163.3320 -dsubgo:
163.3321 -        mov ecx, FullLength
163.3322 -        mov edx, ecx
163.3323 -        sub edx, ebx                  // subtract alignment fix
163.3324 -        and edx, 0x00000007           // calc bytes over mult of 8
163.3325 -        sub ecx, edx                  // drop over bytes from length
163.3326 -        mov MMXLength, ecx
163.3327 -   } // end _asm block
163.3328 -
163.3329 -   // Now do the math for the rest of the row
163.3330 -   switch ( bpp )
163.3331 -   {
163.3332 -        case 3:
163.3333 -        {
163.3334 -         ActiveMask.use  = 0x0000ffffff000000;
163.3335 -         ShiftBpp.use = 24;       // == 3 * 8
163.3336 -         ShiftRem.use  = 40;      // == 64 - 24
163.3337 -         _asm {
163.3338 -            mov edi, row
163.3339 -            movq mm7, ActiveMask  // Load ActiveMask for 2nd active byte group
163.3340 -            mov esi, edi              // lp = row
163.3341 -            add edi, bpp          // rp = row + bpp
163.3342 -            movq mm6, mm7
163.3343 -            mov ebx, diff
163.3344 -            psllq mm6, ShiftBpp   // Move mask in mm6 to cover 3rd active
163.3345 -                                  // byte group
163.3346 -            // PRIME the pump (load the first Raw(x-bpp) data set
163.3347 -            movq mm1, [edi+ebx-8]
163.3348 -dsub3lp:
163.3349 -            psrlq mm1, ShiftRem   // Shift data for adding 1st bpp bytes
163.3350 -                          // no need for mask; shift clears inactive bytes
163.3351 -            // Add 1st active group
163.3352 -            movq mm0, [edi+ebx]
163.3353 -            paddb mm0, mm1
163.3354 -            // Add 2nd active group
163.3355 -            movq mm1, mm0         // mov updated Raws to mm1
163.3356 -            psllq mm1, ShiftBpp   // shift data to position correctly
163.3357 -            pand mm1, mm7         // mask to use only 2nd active group
163.3358 -            paddb mm0, mm1
163.3359 -            // Add 3rd active group
163.3360 -            movq mm1, mm0         // mov updated Raws to mm1
163.3361 -            psllq mm1, ShiftBpp   // shift data to position correctly
163.3362 -            pand mm1, mm6         // mask to use only 3rd active group
163.3363 -            add ebx, 8
163.3364 -            paddb mm0, mm1
163.3365 -            cmp ebx, MMXLength
163.3366 -            movq [edi+ebx-8], mm0     // Write updated Raws back to array
163.3367 -            // Prep for doing 1st add at top of loop
163.3368 -            movq mm1, mm0
163.3369 -            jb dsub3lp
163.3370 -         } // end _asm block
163.3371 -      }
163.3372 -      break;
163.3373 -
163.3374 -      case 1:
163.3375 -      {
163.3376 -         // Placed here just in case this is a duplicate of the
163.3377 -         // non-MMX code for the SUB filter in png_read_filter_row below
163.3378 -         //
163.3379 -         //         png_bytep rp;
163.3380 -         //         png_bytep lp;
163.3381 -         //         png_uint_32 i;
163.3382 -         //         bpp = (row_info->pixel_depth + 7) >> 3;
163.3383 -         //         for (i = (png_uint_32)bpp, rp = row + bpp, lp = row;
163.3384 -         //            i < row_info->rowbytes; i++, rp++, lp++)
163.3385 -         //      {
163.3386 -         //            *rp = (png_byte)(((int)(*rp) + (int)(*lp)) & 0xff);
163.3387 -         //      }
163.3388 -         _asm {
163.3389 -            mov ebx, diff
163.3390 -            mov edi, row
163.3391 -            cmp ebx, FullLength
163.3392 -            jnb dsub1end
163.3393 -            mov esi, edi          // lp = row
163.3394 -            xor eax, eax
163.3395 -            add edi, bpp      // rp = row + bpp
163.3396 -dsub1lp:
163.3397 -            mov al, [esi+ebx]
163.3398 -            add [edi+ebx], al
163.3399 -            inc ebx
163.3400 -            cmp ebx, FullLength
163.3401 -            jb dsub1lp
163.3402 -dsub1end:
163.3403 -         } // end _asm block
163.3404 -      }
163.3405 -      return;
163.3406 -
163.3407 -      case 6:
163.3408 -      case 7:
163.3409 -      case 4:
163.3410 -      case 5:
163.3411 -      {
163.3412 -         ShiftBpp.use = bpp << 3;
163.3413 -         ShiftRem.use = 64 - ShiftBpp.use;
163.3414 -         _asm {
163.3415 -            mov edi, row
163.3416 -            mov ebx, diff
163.3417 -            mov esi, edi               // lp = row
163.3418 -            add edi, bpp           // rp = row + bpp
163.3419 -            // PRIME the pump (load the first Raw(x-bpp) data set
163.3420 -            movq mm1, [edi+ebx-8]
163.3421 -dsub4lp:
163.3422 -            psrlq mm1, ShiftRem // Shift data for adding 1st bpp bytes
163.3423 -                          // no need for mask; shift clears inactive bytes
163.3424 -            movq mm0, [edi+ebx]
163.3425 -            paddb mm0, mm1
163.3426 -            // Add 2nd active group
163.3427 -            movq mm1, mm0          // mov updated Raws to mm1
163.3428 -            psllq mm1, ShiftBpp    // shift data to position correctly
163.3429 -                                   // there is no need for any mask
163.3430 -                                   // since shift clears inactive bits/bytes
163.3431 -            add ebx, 8
163.3432 -            paddb mm0, mm1
163.3433 -            cmp ebx, MMXLength
163.3434 -            movq [edi+ebx-8], mm0
163.3435 -            movq mm1, mm0          // Prep for doing 1st add at top of loop
163.3436 -            jb dsub4lp
163.3437 -         } // end _asm block
163.3438 -      }
163.3439 -      break;
163.3440 -
163.3441 -      case 2:
163.3442 -      {
163.3443 -         ActiveMask.use  = 0x00000000ffff0000;
163.3444 -         ShiftBpp.use = 16;       // == 2 * 8
163.3445 -         ShiftRem.use = 48;       // == 64 - 16
163.3446 -         _asm {
163.3447 -            movq mm7, ActiveMask  // Load ActiveMask for 2nd active byte group
163.3448 -            mov ebx, diff
163.3449 -            movq mm6, mm7
163.3450 -            mov edi, row
163.3451 -            psllq mm6, ShiftBpp     // Move mask in mm6 to cover 3rd active
163.3452 -                                    //  byte group
163.3453 -            mov esi, edi            // lp = row
163.3454 -            movq mm5, mm6
163.3455 -            add edi, bpp            // rp = row + bpp
163.3456 -            psllq mm5, ShiftBpp     // Move mask in mm5 to cover 4th active
163.3457 -                                    //  byte group
163.3458 -            // PRIME the pump (load the first Raw(x-bpp) data set
163.3459 -            movq mm1, [edi+ebx-8]
163.3460 -dsub2lp:
163.3461 -            // Add 1st active group
163.3462 -            psrlq mm1, ShiftRem     // Shift data for adding 1st bpp bytes
163.3463 -                                    // no need for mask; shift clears inactive
163.3464 -                                    //  bytes
163.3465 -            movq mm0, [edi+ebx]
163.3466 -            paddb mm0, mm1
163.3467 -            // Add 2nd active group
163.3468 -            movq mm1, mm0           // mov updated Raws to mm1
163.3469 -            psllq mm1, ShiftBpp     // shift data to position correctly
163.3470 -            pand mm1, mm7           // mask to use only 2nd active group
163.3471 -            paddb mm0, mm1
163.3472 -            // Add 3rd active group
163.3473 -            movq mm1, mm0           // mov updated Raws to mm1
163.3474 -            psllq mm1, ShiftBpp     // shift data to position correctly
163.3475 -            pand mm1, mm6           // mask to use only 3rd active group
163.3476 -            paddb mm0, mm1
163.3477 -            // Add 4th active group
163.3478 -            movq mm1, mm0           // mov updated Raws to mm1
163.3479 -            psllq mm1, ShiftBpp     // shift data to position correctly
163.3480 -            pand mm1, mm5           // mask to use only 4th active group
163.3481 -            add ebx, 8
163.3482 -            paddb mm0, mm1
163.3483 -            cmp ebx, MMXLength
163.3484 -            movq [edi+ebx-8], mm0   // Write updated Raws back to array
163.3485 -            movq mm1, mm0           // Prep for doing 1st add at top of loop
163.3486 -            jb dsub2lp
163.3487 -         } // end _asm block
163.3488 -      }
163.3489 -      break;
163.3490 -      case 8:
163.3491 -      {
163.3492 -         _asm {
163.3493 -            mov edi, row
163.3494 -            mov ebx, diff
163.3495 -            mov esi, edi            // lp = row
163.3496 -            add edi, bpp            // rp = row + bpp
163.3497 -            mov ecx, MMXLength
163.3498 -            movq mm7, [edi+ebx-8]   // PRIME the pump (load the first
163.3499 -                                    // Raw(x-bpp) data set
163.3500 -            and ecx, 0x0000003f     // calc bytes over mult of 64
163.3501 -dsub8lp:
163.3502 -            movq mm0, [edi+ebx]     // Load Sub(x) for 1st 8 bytes
163.3503 -            paddb mm0, mm7
163.3504 -            movq mm1, [edi+ebx+8]   // Load Sub(x) for 2nd 8 bytes
163.3505 -            movq [edi+ebx], mm0    // Write Raw(x) for 1st 8 bytes
163.3506 -                                   // Now mm0 will be used as Raw(x-bpp) for
163.3507 -                                   // the 2nd group of 8 bytes.  This will be
163.3508 -                                   // repeated for each group of 8 bytes with
163.3509 -                                   // the 8th group being used as the Raw(x-bpp)
163.3510 -                                   // for the 1st group of the next loop.
163.3511 -            paddb mm1, mm0
163.3512 -            movq mm2, [edi+ebx+16]  // Load Sub(x) for 3rd 8 bytes
163.3513 -            movq [edi+ebx+8], mm1   // Write Raw(x) for 2nd 8 bytes
163.3514 -            paddb mm2, mm1
163.3515 -            movq mm3, [edi+ebx+24]  // Load Sub(x) for 4th 8 bytes
163.3516 -            movq [edi+ebx+16], mm2  // Write Raw(x) for 3rd 8 bytes
163.3517 -            paddb mm3, mm2
163.3518 -            movq mm4, [edi+ebx+32]  // Load Sub(x) for 5th 8 bytes
163.3519 -            movq [edi+ebx+24], mm3  // Write Raw(x) for 4th 8 bytes
163.3520 -            paddb mm4, mm3
163.3521 -            movq mm5, [edi+ebx+40]  // Load Sub(x) for 6th 8 bytes
163.3522 -            movq [edi+ebx+32], mm4  // Write Raw(x) for 5th 8 bytes
163.3523 -            paddb mm5, mm4
163.3524 -            movq mm6, [edi+ebx+48]  // Load Sub(x) for 7th 8 bytes
163.3525 -            movq [edi+ebx+40], mm5  // Write Raw(x) for 6th 8 bytes
163.3526 -            paddb mm6, mm5
163.3527 -            movq mm7, [edi+ebx+56]  // Load Sub(x) for 8th 8 bytes
163.3528 -            movq [edi+ebx+48], mm6  // Write Raw(x) for 7th 8 bytes
163.3529 -            add ebx, 64
163.3530 -            paddb mm7, mm6
163.3531 -            cmp ebx, ecx
163.3532 -            movq [edi+ebx-8], mm7   // Write Raw(x) for 8th 8 bytes
163.3533 -            jb dsub8lp
163.3534 -            cmp ebx, MMXLength
163.3535 -            jnb dsub8lt8
163.3536 -dsub8lpA:
163.3537 -            movq mm0, [edi+ebx]
163.3538 -            add ebx, 8
163.3539 -            paddb mm0, mm7
163.3540 -            cmp ebx, MMXLength
163.3541 -            movq [edi+ebx-8], mm0   // use -8 to offset early add to ebx
163.3542 -            movq mm7, mm0           // Move calculated Raw(x) data to mm1 to
163.3543 -                                    // be the new Raw(x-bpp) for the next loop
163.3544 -            jb dsub8lpA
163.3545 -dsub8lt8:
163.3546 -         } // end _asm block
163.3547 -      }
163.3548 -      break;
163.3549 -
163.3550 -      default:                // bpp greater than 8 bytes
163.3551 -      {
163.3552 -         _asm {
163.3553 -            mov ebx, diff
163.3554 -            mov edi, row
163.3555 -            mov esi, edi           // lp = row
163.3556 -            add edi, bpp           // rp = row + bpp
163.3557 -dsubAlp:
163.3558 -            movq mm0, [edi+ebx]
163.3559 -            movq mm1, [esi+ebx]
163.3560 -            add ebx, 8
163.3561 -            paddb mm0, mm1
163.3562 -            cmp ebx, MMXLength
163.3563 -            movq [edi+ebx-8], mm0  // mov does not affect flags; -8 to offset
163.3564 -                                   //  add ebx
163.3565 -            jb dsubAlp
163.3566 -         } // end _asm block
163.3567 -      }
163.3568 -      break;
163.3569 -
163.3570 -   } // end switch ( bpp )
163.3571 -
163.3572 -   _asm {
163.3573 -        mov ebx, MMXLength
163.3574 -        mov edi, row
163.3575 -        cmp ebx, FullLength
163.3576 -        jnb dsubend
163.3577 -        mov esi, edi               // lp = row
163.3578 -        xor eax, eax
163.3579 -        add edi, bpp               // rp = row + bpp
163.3580 -dsublp2:
163.3581 -        mov al, [esi+ebx]
163.3582 -        add [edi+ebx], al
163.3583 -        inc ebx
163.3584 -        cmp ebx, FullLength
163.3585 -        jb dsublp2
163.3586 -dsubend:
163.3587 -        emms             // End MMX instructions; prep for possible FP instrs.
163.3588 -   } // end _asm block
163.3589 -}
163.3590 -
163.3591 -// Optimized code for PNG Up filter decoder
163.3592 -void /* PRIVATE */
163.3593 -png_read_filter_row_mmx_up(png_row_infop row_info, png_bytep row,
163.3594 -   png_bytep prev_row)
163.3595 -{
163.3596 -   png_uint_32 len;
163.3597 -   len  = row_info->rowbytes;       // # of bytes to filter
163.3598 -   _asm {
163.3599 -      mov edi, row
163.3600 -      // get # of bytes to alignment
163.3601 -      mov ecx, edi
163.3602 -      xor ebx, ebx
163.3603 -      add ecx, 0x7
163.3604 -      xor eax, eax
163.3605 -      and ecx, 0xfffffff8
163.3606 -      mov esi, prev_row
163.3607 -      sub ecx, edi
163.3608 -      jz dupgo
163.3609 -      // fix alignment
163.3610 -duplp1:
163.3611 -      mov al, [edi+ebx]
163.3612 -      add al, [esi+ebx]
163.3613 -      inc ebx
163.3614 -      cmp ebx, ecx
163.3615 -      mov [edi + ebx-1], al  // mov does not affect flags; -1 to offset inc ebx
163.3616 -      jb duplp1
163.3617 -dupgo:
163.3618 -      mov ecx, len
163.3619 -      mov edx, ecx
163.3620 -      sub edx, ebx                  // subtract alignment fix
163.3621 -      and edx, 0x0000003f           // calc bytes over mult of 64
163.3622 -      sub ecx, edx                  // drop over bytes from length
163.3623 -      // Unrolled loop - use all MMX registers and interleave to reduce
163.3624 -      // number of branch instructions (loops) and reduce partial stalls
163.3625 -duploop:
163.3626 -      movq mm1, [esi+ebx]
163.3627 -      movq mm0, [edi+ebx]
163.3628 -      movq mm3, [esi+ebx+8]
163.3629 -      paddb mm0, mm1
163.3630 -      movq mm2, [edi+ebx+8]
163.3631 -      movq [edi+ebx], mm0
163.3632 -      paddb mm2, mm3
163.3633 -      movq mm5, [esi+ebx+16]
163.3634 -      movq [edi+ebx+8], mm2
163.3635 -      movq mm4, [edi+ebx+16]
163.3636 -      movq mm7, [esi+ebx+24]
163.3637 -      paddb mm4, mm5
163.3638 -      movq mm6, [edi+ebx+24]
163.3639 -      movq [edi+ebx+16], mm4
163.3640 -      paddb mm6, mm7
163.3641 -      movq mm1, [esi+ebx+32]
163.3642 -      movq [edi+ebx+24], mm6
163.3643 -      movq mm0, [edi+ebx+32]
163.3644 -      movq mm3, [esi+ebx+40]
163.3645 -      paddb mm0, mm1
163.3646 -      movq mm2, [edi+ebx+40]
163.3647 -      movq [edi+ebx+32], mm0
163.3648 -      paddb mm2, mm3
163.3649 -      movq mm5, [esi+ebx+48]
163.3650 -      movq [edi+ebx+40], mm2
163.3651 -      movq mm4, [edi+ebx+48]
163.3652 -      movq mm7, [esi+ebx+56]
163.3653 -      paddb mm4, mm5
163.3654 -      movq mm6, [edi+ebx+56]
163.3655 -      movq [edi+ebx+48], mm4
163.3656 -      add ebx, 64
163.3657 -      paddb mm6, mm7
163.3658 -      cmp ebx, ecx
163.3659 -      movq [edi+ebx-8], mm6 // (+56)movq does not affect flags;
163.3660 -                                     // -8 to offset add ebx
163.3661 -      jb duploop
163.3662 -
163.3663 -      cmp edx, 0                     // Test for bytes over mult of 64
163.3664 -      jz dupend
163.3665 -
163.3666 -
163.3667 -      // 2 lines added by lcreeve at netins.net
163.3668 -      // (mail 11 Jul 98 in png-implement list)
163.3669 -      cmp edx, 8 //test for less than 8 bytes
163.3670 -      jb duplt8
163.3671 -
163.3672 -
163.3673 -      add ecx, edx
163.3674 -      and edx, 0x00000007           // calc bytes over mult of 8
163.3675 -      sub ecx, edx                  // drop over bytes from length
163.3676 -      jz duplt8
163.3677 -      // Loop using MMX registers mm0 & mm1 to update 8 bytes simultaneously
163.3678 -duplpA:
163.3679 -      movq mm1, [esi+ebx]
163.3680 -      movq mm0, [edi+ebx]
163.3681 -      add ebx, 8
163.3682 -      paddb mm0, mm1
163.3683 -      cmp ebx, ecx
163.3684 -      movq [edi+ebx-8], mm0 // movq does not affect flags; -8 to offset add ebx
163.3685 -      jb duplpA
163.3686 -      cmp edx, 0            // Test for bytes over mult of 8
163.3687 -      jz dupend
163.3688 -duplt8:
163.3689 -      xor eax, eax
163.3690 -      add ecx, edx          // move over byte count into counter
163.3691 -      // Loop using x86 registers to update remaining bytes
163.3692 -duplp2:
163.3693 -      mov al, [edi + ebx]
163.3694 -      add al, [esi + ebx]
163.3695 -      inc ebx
163.3696 -      cmp ebx, ecx
163.3697 -      mov [edi + ebx-1], al // mov does not affect flags; -1 to offset inc ebx
163.3698 -      jb duplp2
163.3699 -dupend:
163.3700 -      // Conversion of filtered row completed
163.3701 -      emms          // End MMX instructions; prep for possible FP instrs.
163.3702 -   } // end _asm block
163.3703 -}
163.3704 -
163.3705 -
163.3706 -// Optimized png_read_filter_row routines
163.3707 -void /* PRIVATE */
163.3708 -png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep
163.3709 -   row, png_bytep prev_row, int filter)
163.3710 -{
163.3711 -#ifdef PNG_DEBUG
163.3712 -   char filnm[10];
163.3713 -#endif
163.3714 -
163.3715 -   if (mmx_supported == 2) {
163.3716 -#if !defined(PNG_1_0_X)
163.3717 -       /* this should have happened in png_init_mmx_flags() already */
163.3718 -       png_warning(png_ptr, "asm_flags may not have been initialized");
163.3719 -#endif
163.3720 -       png_mmx_support();
163.3721 -   }
163.3722 -
163.3723 -#ifdef PNG_DEBUG
163.3724 -   png_debug(1, "in png_read_filter_row\n");
163.3725 -   switch (filter)
163.3726 -   {
163.3727 -      case 0: sprintf(filnm, "none");
163.3728 -         break;
163.3729 -#if !defined(PNG_1_0_X)
163.3730 -      case 1: sprintf(filnm, "sub-%s",
163.3731 -        (png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_SUB)? "MMX" : "x86");
163.3732 -         break;
163.3733 -      case 2: sprintf(filnm, "up-%s",
163.3734 -        (png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_UP)? "MMX" : "x86");
163.3735 -         break;
163.3736 -      case 3: sprintf(filnm, "avg-%s",
163.3737 -        (png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_AVG)? "MMX" : "x86");
163.3738 -         break;
163.3739 -      case 4: sprintf(filnm, "Paeth-%s",
163.3740 -        (png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_PAETH)? "MMX":"x86");
163.3741 -         break;
163.3742 -#else
163.3743 -      case 1: sprintf(filnm, "sub");
163.3744 -         break;
163.3745 -      case 2: sprintf(filnm, "up");
163.3746 -         break;
163.3747 -      case 3: sprintf(filnm, "avg");
163.3748 -         break;
163.3749 -      case 4: sprintf(filnm, "Paeth");
163.3750 -         break;
163.3751 -#endif
163.3752 -      default: sprintf(filnm, "unknw");
163.3753 -         break;
163.3754 -   }
163.3755 -   png_debug2(0,"row=%5d, %s, ", png_ptr->row_number, filnm);
163.3756 -   png_debug2(0, "pd=%2d, b=%d, ", (int)row_info->pixel_depth,
163.3757 -      (int)((row_info->pixel_depth + 7) >> 3));
163.3758 -   png_debug1(0,"len=%8d, ", row_info->rowbytes);
163.3759 -#endif /* PNG_DEBUG */
163.3760 -
163.3761 -   switch (filter)
163.3762 -   {
163.3763 -      case PNG_FILTER_VALUE_NONE:
163.3764 -         break;
163.3765 -
163.3766 -      case PNG_FILTER_VALUE_SUB:
163.3767 -      {
163.3768 -#if !defined(PNG_1_0_X)
163.3769 -         if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_SUB) &&
163.3770 -             (row_info->pixel_depth >= png_ptr->mmx_bitdepth_threshold) &&
163.3771 -             (row_info->rowbytes >= png_ptr->mmx_rowbytes_threshold))
163.3772 -#else
163.3773 -         if (mmx_supported)
163.3774 -#endif
163.3775 -         {
163.3776 -            png_read_filter_row_mmx_sub(row_info, row);
163.3777 -         }
163.3778 -         else
163.3779 -         {
163.3780 -            png_uint_32 i;
163.3781 -            png_uint_32 istop = row_info->rowbytes;
163.3782 -            png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
163.3783 -            png_bytep rp = row + bpp;
163.3784 -            png_bytep lp = row;
163.3785 -
163.3786 -            for (i = bpp; i < istop; i++)
163.3787 -            {
163.3788 -               *rp = (png_byte)(((int)(*rp) + (int)(*lp++)) & 0xff);
163.3789 -               rp++;
163.3790 -            }
163.3791 -         }
163.3792 -         break;
163.3793 -      }
163.3794 -
163.3795 -      case PNG_FILTER_VALUE_UP:
163.3796 -      {
163.3797 -#if !defined(PNG_1_0_X)
163.3798 -         if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_UP) &&
163.3799 -             (row_info->pixel_depth >= png_ptr->mmx_bitdepth_threshold) &&
163.3800 -             (row_info->rowbytes >= png_ptr->mmx_rowbytes_threshold))
163.3801 -#else
163.3802 -         if (mmx_supported)
163.3803 -#endif
163.3804 -         {
163.3805 -            png_read_filter_row_mmx_up(row_info, row, prev_row);
163.3806 -         }
163.3807 -         else
163.3808 -         {
163.3809 -            png_uint_32 i;
163.3810 -            png_uint_32 istop = row_info->rowbytes;
163.3811 -            png_bytep rp = row;
163.3812 -            png_bytep pp = prev_row;
163.3813 -
163.3814 -            for (i = 0; i < istop; ++i)
163.3815 -            {
163.3816 -               *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
163.3817 -               rp++;
163.3818 -            }
163.3819 -         }
163.3820 -         break;
163.3821 -      }
163.3822 -
163.3823 -      case PNG_FILTER_VALUE_AVG:
163.3824 -      {
163.3825 -#if !defined(PNG_1_0_X)
163.3826 -         if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_AVG) &&
163.3827 -             (row_info->pixel_depth >= png_ptr->mmx_bitdepth_threshold) &&
163.3828 -             (row_info->rowbytes >= png_ptr->mmx_rowbytes_threshold))
163.3829 -#else
163.3830 -         if (mmx_supported)
163.3831 -#endif
163.3832 -         {
163.3833 -            png_read_filter_row_mmx_avg(row_info, row, prev_row);
163.3834 -         }
163.3835 -         else
163.3836 -         {
163.3837 -            png_uint_32 i;
163.3838 -            png_bytep rp = row;
163.3839 -            png_bytep pp = prev_row;
163.3840 -            png_bytep lp = row;
163.3841 -            png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
163.3842 -            png_uint_32 istop = row_info->rowbytes - bpp;
163.3843 -
163.3844 -            for (i = 0; i < bpp; i++)
163.3845 -            {
163.3846 -               *rp = (png_byte)(((int)(*rp) +
163.3847 -                  ((int)(*pp++) >> 1)) & 0xff);
163.3848 -               rp++;
163.3849 -            }
163.3850 -
163.3851 -            for (i = 0; i < istop; i++)
163.3852 -            {
163.3853 -               *rp = (png_byte)(((int)(*rp) +
163.3854 -                  ((int)(*pp++ + *lp++) >> 1)) & 0xff);
163.3855 -               rp++;
163.3856 -            }
163.3857 -         }
163.3858 -         break;
163.3859 -      }
163.3860 -
163.3861 -      case PNG_FILTER_VALUE_PAETH:
163.3862 -      {
163.3863 -#if !defined(PNG_1_0_X)
163.3864 -         if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_PAETH) &&
163.3865 -             (row_info->pixel_depth >= png_ptr->mmx_bitdepth_threshold) &&
163.3866 -             (row_info->rowbytes >= png_ptr->mmx_rowbytes_threshold))
163.3867 -#else
163.3868 -         if (mmx_supported)
163.3869 -#endif
163.3870 -         {
163.3871 -            png_read_filter_row_mmx_paeth(row_info, row, prev_row);
163.3872 -         }
163.3873 -         else
163.3874 -         {
163.3875 -            png_uint_32 i;
163.3876 -            png_bytep rp = row;
163.3877 -            png_bytep pp = prev_row;
163.3878 -            png_bytep lp = row;
163.3879 -            png_bytep cp = prev_row;
163.3880 -            png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
163.3881 -            png_uint_32 istop=row_info->rowbytes - bpp;
163.3882 -
163.3883 -            for (i = 0; i < bpp; i++)
163.3884 -            {
163.3885 -               *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
163.3886 -               rp++;
163.3887 -            }
163.3888 -
163.3889 -            for (i = 0; i < istop; i++)   // use leftover rp,pp
163.3890 -            {
163.3891 -               int a, b, c, pa, pb, pc, p;
163.3892 -
163.3893 -               a = *lp++;
163.3894 -               b = *pp++;
163.3895 -               c = *cp++;
163.3896 -
163.3897 -               p = b - c;
163.3898 -               pc = a - c;
163.3899 -
163.3900 -#ifdef PNG_USE_ABS
163.3901 -               pa = abs(p);
163.3902 -               pb = abs(pc);
163.3903 -               pc = abs(p + pc);
163.3904 -#else
163.3905 -               pa = p < 0 ? -p : p;
163.3906 -               pb = pc < 0 ? -pc : pc;
163.3907 -               pc = (p + pc) < 0 ? -(p + pc) : p + pc;
163.3908 -#endif
163.3909 -
163.3910 -               /*
163.3911 -                  if (pa <= pb && pa <= pc)
163.3912 -                     p = a;
163.3913 -                  else if (pb <= pc)
163.3914 -                     p = b;
163.3915 -                  else
163.3916 -                     p = c;
163.3917 -                */
163.3918 -
163.3919 -               p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
163.3920 -
163.3921 -               *rp = (png_byte)(((int)(*rp) + p) & 0xff);
163.3922 -               rp++;
163.3923 -            }
163.3924 -         }
163.3925 -         break;
163.3926 -      }
163.3927 -
163.3928 -      default:
163.3929 -         png_warning(png_ptr, "Ignoring bad row filter type");
163.3930 -         *row=0;
163.3931 -         break;
163.3932 -   }
163.3933 -}
163.3934 -
163.3935 -#endif /* PNG_ASSEMBLER_CODE_SUPPORTED && PNG_USE_PNGVCRD */
   164.1 --- a/src/share/native/sun/awt/libpng/pngwio.c	Fri Sep 30 17:20:56 2011 -0700
   164.2 +++ b/src/share/native/sun/awt/libpng/pngwio.c	Tue Oct 04 12:39:42 2011 -0700
   164.3 @@ -29,12 +29,15 @@
   164.4   * However, the following notice accompanied the original version of this
   164.5   * file and, per its terms, should not be removed:
   164.6   *
   164.7 - * Last changed in libpng 1.2.13 November 13, 2006
   164.8 - * For conditions of distribution and use, see copyright notice in png.h
   164.9 - * Copyright (c) 1998-2002 Glenn Randers-Pehrson
  164.10 + * Last changed in libpng 1.5.0 [January 6, 2011]
  164.11 + * Copyright (c) 1998-2011 Glenn Randers-Pehrson
  164.12   * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
  164.13   * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
  164.14   *
  164.15 + * This code is released under the libpng license.
  164.16 + * For conditions of distribution and use, see the disclaimer
  164.17 + * and license in png.h
  164.18 + *
  164.19   * This file provides a location for all output.  Users who need
  164.20   * special handling are expected to write functions that have the same
  164.21   * arguments as these and perform similar functions, but that possibly
  164.22 @@ -43,100 +46,101 @@
  164.23   * them at run time with png_set_write_fn(...).
  164.24   */
  164.25  
  164.26 -#define PNG_INTERNAL
  164.27 -#include "png.h"
  164.28 +#include "pngpriv.h"
  164.29 +
  164.30  #ifdef PNG_WRITE_SUPPORTED
  164.31  
  164.32  /* Write the data to whatever output you are using.  The default routine
  164.33 -   writes to a file pointer.  Note that this routine sometimes gets called
  164.34 -   with very small lengths, so you should implement some kind of simple
  164.35 -   buffering if you are using unbuffered writes.  This should never be asked
  164.36 -   to write more than 64K on a 16 bit machine.  */
  164.37 + * writes to a file pointer.  Note that this routine sometimes gets called
  164.38 + * with very small lengths, so you should implement some kind of simple
  164.39 + * buffering if you are using unbuffered writes.  This should never be asked
  164.40 + * to write more than 64K on a 16 bit machine.
  164.41 + */
  164.42  
  164.43  void /* PRIVATE */
  164.44 -png_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  164.45 +png_write_data(png_structp png_ptr, png_const_bytep data, png_size_t length)
  164.46  {
  164.47 +   /* NOTE: write_data_fn must not change the buffer! */
  164.48     if (png_ptr->write_data_fn != NULL )
  164.49 -      (*(png_ptr->write_data_fn))(png_ptr, data, length);
  164.50 +      (*(png_ptr->write_data_fn))(png_ptr, (png_bytep)data, length);
  164.51 +
  164.52     else
  164.53        png_error(png_ptr, "Call to NULL write function");
  164.54  }
  164.55  
  164.56 -#if !defined(PNG_NO_STDIO)
  164.57 +#ifdef PNG_STDIO_SUPPORTED
  164.58  /* This is the function that does the actual writing of data.  If you are
  164.59 -   not writing to a standard C stream, you should create a replacement
  164.60 -   write_data function and use it at run time with png_set_write_fn(), rather
  164.61 -   than changing the library. */
  164.62 + * not writing to a standard C stream, you should create a replacement
  164.63 + * write_data function and use it at run time with png_set_write_fn(), rather
  164.64 + * than changing the library.
  164.65 + */
  164.66  #ifndef USE_FAR_KEYWORD
  164.67 -void PNGAPI
  164.68 +void PNGCBAPI
  164.69  png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  164.70  {
  164.71 -   png_uint_32 check;
  164.72 +   png_size_t check;
  164.73  
  164.74 -   if(png_ptr == NULL) return;
  164.75 -#if defined(_WIN32_WCE)
  164.76 -   if ( !WriteFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  164.77 -      check = 0;
  164.78 -#else
  164.79 +   if (png_ptr == NULL)
  164.80 +      return;
  164.81 +
  164.82     check = fwrite(data, 1, length, (png_FILE_p)(png_ptr->io_ptr));
  164.83 -#endif
  164.84 +
  164.85     if (check != length)
  164.86        png_error(png_ptr, "Write Error");
  164.87  }
  164.88  #else
  164.89 -/* this is the model-independent version. Since the standard I/O library
  164.90 -   can't handle far buffers in the medium and small models, we have to copy
  164.91 -   the data.
  164.92 -*/
  164.93 +/* This is the model-independent version. Since the standard I/O library
  164.94 + * can't handle far buffers in the medium and small models, we have to copy
  164.95 + * the data.
  164.96 + */
  164.97  
  164.98  #define NEAR_BUF_SIZE 1024
  164.99  #define MIN(a,b) (a <= b ? a : b)
 164.100  
 164.101 -void PNGAPI
 164.102 +void PNGCBAPI
 164.103  png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
 164.104  {
 164.105     png_uint_32 check;
 164.106     png_byte *near_data;  /* Needs to be "png_byte *" instead of "png_bytep" */
 164.107     png_FILE_p io_ptr;
 164.108  
 164.109 -   if(png_ptr == NULL) return;
 164.110 +   if (png_ptr == NULL)
 164.111 +      return;
 164.112 +
 164.113     /* Check if data really is near. If so, use usual code. */
 164.114     near_data = (png_byte *)CVT_PTR_NOCHECK(data);
 164.115     io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
 164.116 +
 164.117     if ((png_bytep)near_data == data)
 164.118     {
 164.119 -#if defined(_WIN32_WCE)
 164.120 -      if ( !WriteFile(io_ptr, near_data, length, &check, NULL) )
 164.121 -         check = 0;
 164.122 -#else
 164.123        check = fwrite(near_data, 1, length, io_ptr);
 164.124 -#endif
 164.125     }
 164.126 +
 164.127     else
 164.128     {
 164.129        png_byte buf[NEAR_BUF_SIZE];
 164.130        png_size_t written, remaining, err;
 164.131        check = 0;
 164.132        remaining = length;
 164.133 +
 164.134        do
 164.135        {
 164.136           written = MIN(NEAR_BUF_SIZE, remaining);
 164.137 -         png_memcpy(buf, data, written); /* copy far buffer to near buffer */
 164.138 -#if defined(_WIN32_WCE)
 164.139 -         if ( !WriteFile(io_ptr, buf, written, &err, NULL) )
 164.140 -            err = 0;
 164.141 -#else
 164.142 +         png_memcpy(buf, data, written); /* Copy far buffer to near buffer */
 164.143           err = fwrite(buf, 1, written, io_ptr);
 164.144 -#endif
 164.145 +
 164.146           if (err != written)
 164.147              break;
 164.148 +
 164.149           else
 164.150              check += err;
 164.151 +
 164.152           data += written;
 164.153           remaining -= written;
 164.154        }
 164.155        while (remaining != 0);
 164.156     }
 164.157 +
 164.158     if (check != length)
 164.159        png_error(png_ptr, "Write Error");
 164.160  }
 164.161 @@ -145,9 +149,10 @@
 164.162  #endif
 164.163  
 164.164  /* This function is called to output any data pending writing (normally
 164.165 -   to disk).  After png_flush is called, there should be no data pending
 164.166 -   writing in any buffers. */
 164.167 -#if defined(PNG_WRITE_FLUSH_SUPPORTED)
 164.168 + * to disk).  After png_flush is called, there should be no data pending
 164.169 + * writing in any buffers.
 164.170 + */
 164.171 +#ifdef PNG_WRITE_FLUSH_SUPPORTED
 164.172  void /* PRIVATE */
 164.173  png_flush(png_structp png_ptr)
 164.174  {
 164.175 @@ -155,108 +160,123 @@
 164.176        (*(png_ptr->output_flush_fn))(png_ptr);
 164.177  }
 164.178  
 164.179 -#if !defined(PNG_NO_STDIO)
 164.180 -void PNGAPI
 164.181 +#  ifdef PNG_STDIO_SUPPORTED
 164.182 +void PNGCBAPI
 164.183  png_default_flush(png_structp png_ptr)
 164.184  {
 164.185 -#if !defined(_WIN32_WCE)
 164.186     png_FILE_p io_ptr;
 164.187 -#endif
 164.188 -   if(png_ptr == NULL) return;
 164.189 -#if !defined(_WIN32_WCE)
 164.190 +
 164.191 +   if (png_ptr == NULL)
 164.192 +      return;
 164.193 +
 164.194     io_ptr = (png_FILE_p)CVT_PTR((png_ptr->io_ptr));
 164.195 -   if (io_ptr != NULL)
 164.196 -      fflush(io_ptr);
 164.197 -#endif
 164.198 +   fflush(io_ptr);
 164.199  }
 164.200 -#endif
 164.201 +#  endif
 164.202  #endif
 164.203  
 164.204  /* This function allows the application to supply new output functions for
 164.205 -   libpng if standard C streams aren't being used.
 164.206 -
 164.207 -   This function takes as its arguments:
 164.208 -   png_ptr       - pointer to a png output data structure
 164.209 -   io_ptr        - pointer to user supplied structure containing info about
 164.210 -                   the output functions.  May be NULL.
 164.211 -   write_data_fn - pointer to a new output function that takes as its
 164.212 -                   arguments a pointer to a png_struct, a pointer to
 164.213 -                   data to be written, and a 32-bit unsigned int that is
 164.214 -                   the number of bytes to be written.  The new write
 164.215 -                   function should call png_error(png_ptr, "Error msg")
 164.216 -                   to exit and output any fatal error messages.
 164.217 -   flush_data_fn - pointer to a new flush function that takes as its
 164.218 -                   arguments a pointer to a png_struct.  After a call to
 164.219 -                   the flush function, there should be no data in any buffers
 164.220 -                   or pending transmission.  If the output method doesn't do
 164.221 -                   any buffering of ouput, a function prototype must still be
 164.222 -                   supplied although it doesn't have to do anything.  If
 164.223 -                   PNG_WRITE_FLUSH_SUPPORTED is not defined at libpng compile
 164.224 -                   time, output_flush_fn will be ignored, although it must be
 164.225 -                   supplied for compatibility. */
 164.226 + * libpng if standard C streams aren't being used.
 164.227 + *
 164.228 + * This function takes as its arguments:
 164.229 + * png_ptr       - pointer to a png output data structure
 164.230 + * io_ptr        - pointer to user supplied structure containing info about
 164.231 + *                 the output functions.  May be NULL.
 164.232 + * write_data_fn - pointer to a new output function that takes as its
 164.233 + *                 arguments a pointer to a png_struct, a pointer to
 164.234 + *                 data to be written, and a 32-bit unsigned int that is
 164.235 + *                 the number of bytes to be written.  The new write
 164.236 + *                 function should call png_error(png_ptr, "Error msg")
 164.237 + *                 to exit and output any fatal error messages.  May be
 164.238 + *                 NULL, in which case libpng's default function will
 164.239 + *                 be used.
 164.240 + * flush_data_fn - pointer to a new flush function that takes as its
 164.241 + *                 arguments a pointer to a png_struct.  After a call to
 164.242 + *                 the flush function, there should be no data in any buffers
 164.243 + *                 or pending transmission.  If the output method doesn't do
 164.244 + *                 any buffering of output, a function prototype must still be
 164.245 + *                 supplied although it doesn't have to do anything.  If
 164.246 + *                 PNG_WRITE_FLUSH_SUPPORTED is not defined at libpng compile
 164.247 + *                 time, output_flush_fn will be ignored, although it must be
 164.248 + *                 supplied for compatibility.  May be NULL, in which case
 164.249 + *                 libpng's default function will be used, if
 164.250 + *                 PNG_WRITE_FLUSH_SUPPORTED is defined.  This is not
 164.251 + *                 a good idea if io_ptr does not point to a standard
 164.252 + *                 *FILE structure.
 164.253 + */
 164.254  void PNGAPI
 164.255  png_set_write_fn(png_structp png_ptr, png_voidp io_ptr,
 164.256 -   png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn)
 164.257 +    png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn)
 164.258  {
 164.259 -   if(png_ptr == NULL) return;
 164.260 +   if (png_ptr == NULL)
 164.261 +      return;
 164.262 +
 164.263     png_ptr->io_ptr = io_ptr;
 164.264  
 164.265 -#if !defined(PNG_NO_STDIO)
 164.266 +#ifdef PNG_STDIO_SUPPORTED
 164.267     if (write_data_fn != NULL)
 164.268        png_ptr->write_data_fn = write_data_fn;
 164.269 +
 164.270     else
 164.271        png_ptr->write_data_fn = png_default_write_data;
 164.272  #else
 164.273     png_ptr->write_data_fn = write_data_fn;
 164.274  #endif
 164.275  
 164.276 -#if defined(PNG_WRITE_FLUSH_SUPPORTED)
 164.277 -#if !defined(PNG_NO_STDIO)
 164.278 +#ifdef PNG_WRITE_FLUSH_SUPPORTED
 164.279 +#  ifdef PNG_STDIO_SUPPORTED
 164.280 +
 164.281     if (output_flush_fn != NULL)
 164.282        png_ptr->output_flush_fn = output_flush_fn;
 164.283 +
 164.284     else
 164.285        png_ptr->output_flush_fn = png_default_flush;
 164.286 -#else
 164.287 +
 164.288 +#  else
 164.289     png_ptr->output_flush_fn = output_flush_fn;
 164.290 -#endif
 164.291 +#  endif
 164.292  #endif /* PNG_WRITE_FLUSH_SUPPORTED */
 164.293  
 164.294     /* It is an error to read while writing a png file */
 164.295     if (png_ptr->read_data_fn != NULL)
 164.296     {
 164.297        png_ptr->read_data_fn = NULL;
 164.298 +
 164.299        png_warning(png_ptr,
 164.300 -         "Attempted to set both read_data_fn and write_data_fn in");
 164.301 -      png_warning(png_ptr,
 164.302 -         "the same structure.  Resetting read_data_fn to NULL.");
 164.303 +          "Can't set both read_data_fn and write_data_fn in the"
 164.304 +          " same structure");
 164.305     }
 164.306  }
 164.307  
 164.308 -#if defined(USE_FAR_KEYWORD)
 164.309 -#if defined(_MSC_VER)
 164.310 -void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check)
 164.311 +#ifdef USE_FAR_KEYWORD
 164.312 +#  ifdef _MSC_VER
 164.313 +void *png_far_to_near(png_structp png_ptr, png_voidp ptr, int check)
 164.314  {
 164.315     void *near_ptr;
 164.316     void FAR *far_ptr;
 164.317     FP_OFF(near_ptr) = FP_OFF(ptr);
 164.318     far_ptr = (void FAR *)near_ptr;
 164.319 -   if(check != 0)
 164.320 -      if(FP_SEG(ptr) != FP_SEG(far_ptr))
 164.321 -         png_error(png_ptr,"segment lost in conversion");
 164.322 +
 164.323 +   if (check != 0)
 164.324 +      if (FP_SEG(ptr) != FP_SEG(far_ptr))
 164.325 +         png_error(png_ptr, "segment lost in conversion");
 164.326 +
 164.327     return(near_ptr);
 164.328  }
 164.329  #  else
 164.330 -void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check)
 164.331 +void *png_far_to_near(png_structp png_ptr, png_voidp ptr, int check)
 164.332  {
 164.333     void *near_ptr;
 164.334     void FAR *far_ptr;
 164.335     near_ptr = (void FAR *)ptr;
 164.336     far_ptr = (void FAR *)near_ptr;
 164.337 -   if(check != 0)
 164.338 -      if(far_ptr != ptr)
 164.339 -         png_error(png_ptr,"segment lost in conversion");
 164.340 +
 164.341 +   if (check != 0)
 164.342 +      if (far_ptr != ptr)
 164.343 +         png_error(png_ptr, "segment lost in conversion");
 164.344 +
 164.345     return(near_ptr);
 164.346  }
 164.347 -#   endif
 164.348 -#   endif
 164.349 +#  endif
 164.350 +#endif
 164.351  #endif /* PNG_WRITE_SUPPORTED */
   165.1 --- a/src/share/native/sun/awt/libpng/pngwrite.c	Fri Sep 30 17:20:56 2011 -0700
   165.2 +++ b/src/share/native/sun/awt/libpng/pngwrite.c	Tue Oct 04 12:39:42 2011 -0700
   165.3 @@ -29,16 +29,18 @@
   165.4   * However, the following notice accompanied the original version of this
   165.5   * file and, per its terms, should not be removed:
   165.6   *
   165.7 - * Last changed in libpng 1.2.15 January 5, 2007
   165.8 - * For conditions of distribution and use, see copyright notice in png.h
   165.9 - * Copyright (c) 1998-2007 Glenn Randers-Pehrson
  165.10 + * Last changed in libpng 1.5.4 [July 7, 2011]
  165.11 + * Copyright (c) 1998-2011 Glenn Randers-Pehrson
  165.12   * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
  165.13   * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
  165.14 + *
  165.15 + * This code is released under the libpng license.
  165.16 + * For conditions of distribution and use, see the disclaimer
  165.17 + * and license in png.h
  165.18   */
  165.19  
  165.20 -/* get internal access to png.h */
  165.21 -#define PNG_INTERNAL
  165.22 -#include "png.h"
  165.23 +#include "pngpriv.h"
  165.24 +
  165.25  #ifdef PNG_WRITE_SUPPORTED
  165.26  
  165.27  /* Writes all the PNG information.  This is the suggested way to use the
  165.28 @@ -53,96 +55,91 @@
  165.29  void PNGAPI
  165.30  png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr)
  165.31  {
  165.32 -   png_debug(1, "in png_write_info_before_PLTE\n");
  165.33 +   png_debug(1, "in png_write_info_before_PLTE");
  165.34 +
  165.35     if (png_ptr == NULL || info_ptr == NULL)
  165.36        return;
  165.37 +
  165.38     if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
  165.39     {
  165.40 -   png_write_sig(png_ptr); /* write PNG signature */
  165.41 -#if defined(PNG_MNG_FEATURES_SUPPORTED)
  165.42 -   if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&(png_ptr->mng_features_permitted))
  165.43 +   /* Write PNG signature */
  165.44 +   png_write_sig(png_ptr);
  165.45 +
  165.46 +#ifdef PNG_MNG_FEATURES_SUPPORTED
  165.47 +   if ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) && \
  165.48 +       (png_ptr->mng_features_permitted))
  165.49     {
  165.50 -      png_warning(png_ptr,"MNG features are not allowed in a PNG datastream");
  165.51 -      png_ptr->mng_features_permitted=0;
  165.52 +      png_warning(png_ptr, "MNG features are not allowed in a PNG datastream");
  165.53 +      png_ptr->mng_features_permitted = 0;
  165.54     }
  165.55  #endif
  165.56 -   /* write IHDR information. */
  165.57 +
  165.58 +   /* Write IHDR information. */
  165.59     png_write_IHDR(png_ptr, info_ptr->width, info_ptr->height,
  165.60 -      info_ptr->bit_depth, info_ptr->color_type, info_ptr->compression_type,
  165.61 -      info_ptr->filter_type,
  165.62 -#if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  165.63 -      info_ptr->interlace_type);
  165.64 +       info_ptr->bit_depth, info_ptr->color_type, info_ptr->compression_type,
  165.65 +       info_ptr->filter_type,
  165.66 +#ifdef PNG_WRITE_INTERLACING_SUPPORTED
  165.67 +       info_ptr->interlace_type);
  165.68  #else
  165.69 -      0);
  165.70 +       0);
  165.71  #endif
  165.72 -   /* the rest of these check to see if the valid field has the appropriate
  165.73 -      flag set, and if it does, writes the chunk. */
  165.74 -#if defined(PNG_WRITE_gAMA_SUPPORTED)
  165.75 +   /* The rest of these check to see if the valid field has the appropriate
  165.76 +    * flag set, and if it does, writes the chunk.
  165.77 +    */
  165.78 +#ifdef PNG_WRITE_gAMA_SUPPORTED
  165.79     if (info_ptr->valid & PNG_INFO_gAMA)
  165.80 -   {
  165.81 -#  ifdef PNG_FLOATING_POINT_SUPPORTED
  165.82 -      png_write_gAMA(png_ptr, info_ptr->gamma);
  165.83 -#else
  165.84 -#ifdef PNG_FIXED_POINT_SUPPORTED
  165.85 -      png_write_gAMA_fixed(png_ptr, info_ptr->int_gamma);
  165.86 -#  endif
  165.87 +      png_write_gAMA_fixed(png_ptr, info_ptr->gamma);
  165.88  #endif
  165.89 -   }
  165.90 -#endif
  165.91 -#if defined(PNG_WRITE_sRGB_SUPPORTED)
  165.92 +#ifdef PNG_WRITE_sRGB_SUPPORTED
  165.93     if (info_ptr->valid & PNG_INFO_sRGB)
  165.94        png_write_sRGB(png_ptr, (int)info_ptr->srgb_intent);
  165.95  #endif
  165.96 -#if defined(PNG_WRITE_iCCP_SUPPORTED)
  165.97 +
  165.98 +#ifdef PNG_WRITE_iCCP_SUPPORTED
  165.99     if (info_ptr->valid & PNG_INFO_iCCP)
 165.100        png_write_iCCP(png_ptr, info_ptr->iccp_name, PNG_COMPRESSION_TYPE_BASE,
 165.101 -                     info_ptr->iccp_profile, (int)info_ptr->iccp_proflen);
 165.102 +          (png_charp)info_ptr->iccp_profile, (int)info_ptr->iccp_proflen);
 165.103  #endif
 165.104 -#if defined(PNG_WRITE_sBIT_SUPPORTED)
 165.105 +#ifdef PNG_WRITE_sBIT_SUPPORTED
 165.106     if (info_ptr->valid & PNG_INFO_sBIT)
 165.107        png_write_sBIT(png_ptr, &(info_ptr->sig_bit), info_ptr->color_type);
 165.108  #endif
 165.109 -#if defined(PNG_WRITE_cHRM_SUPPORTED)
 165.110 +#ifdef PNG_WRITE_cHRM_SUPPORTED
 165.111     if (info_ptr->valid & PNG_INFO_cHRM)
 165.112 -   {
 165.113 -#ifdef PNG_FLOATING_POINT_SUPPORTED
 165.114 -      png_write_cHRM(png_ptr,
 165.115 -         info_ptr->x_white, info_ptr->y_white,
 165.116 -         info_ptr->x_red, info_ptr->y_red,
 165.117 -         info_ptr->x_green, info_ptr->y_green,
 165.118 -         info_ptr->x_blue, info_ptr->y_blue);
 165.119 -#else
 165.120 -#  ifdef PNG_FIXED_POINT_SUPPORTED
 165.121        png_write_cHRM_fixed(png_ptr,
 165.122 -         info_ptr->int_x_white, info_ptr->int_y_white,
 165.123 -         info_ptr->int_x_red, info_ptr->int_y_red,
 165.124 -         info_ptr->int_x_green, info_ptr->int_y_green,
 165.125 -         info_ptr->int_x_blue, info_ptr->int_y_blue);
 165.126 -#  endif
 165.127 +          info_ptr->x_white, info_ptr->y_white,
 165.128 +          info_ptr->x_red, info_ptr->y_red,
 165.129 +          info_ptr->x_green, info_ptr->y_green,
 165.130 +          info_ptr->x_blue, info_ptr->y_blue);
 165.131  #endif
 165.132 -   }
 165.133 -#endif
 165.134 -#if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
 165.135 +
 165.136 +#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
 165.137     if (info_ptr->unknown_chunks_num)
 165.138     {
 165.139 -       png_unknown_chunk *up;
 165.140 +      png_unknown_chunk *up;
 165.141  
 165.142 -       png_debug(5, "writing extra chunks\n");
 165.143 +      png_debug(5, "writing extra chunks");
 165.144  
 165.145 -       for (up = info_ptr->unknown_chunks;
 165.146 -            up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
 165.147 -            up++)
 165.148 -       {
 165.149 -         int keep=png_handle_as_unknown(png_ptr, up->name);
 165.150 +      for (up = info_ptr->unknown_chunks;
 165.151 +           up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
 165.152 +           up++)
 165.153 +      {
 165.154 +         int keep = png_handle_as_unknown(png_ptr, up->name);
 165.155 +
 165.156           if (keep != PNG_HANDLE_CHUNK_NEVER &&
 165.157 -            up->location && !(up->location & PNG_HAVE_PLTE) &&
 165.158 -            !(up->location & PNG_HAVE_IDAT) &&
 165.159 -            ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
 165.160 -            (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
 165.161 +             up->location &&
 165.162 +             !(up->location & PNG_HAVE_PLTE) &&
 165.163 +             !(up->location & PNG_HAVE_IDAT) &&
 165.164 +             !(up->location & PNG_AFTER_IDAT) &&
 165.165 +             ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
 165.166 +             (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
 165.167           {
 165.168 +            if (up->size == 0)
 165.169 +               png_warning(png_ptr, "Writing zero-length unknown chunk");
 165.170 +
 165.171              png_write_chunk(png_ptr, up->name, up->data, up->size);
 165.172           }
 165.173 -       }
 165.174 +      }
 165.175     }
 165.176  #endif
 165.177        png_ptr->mode |= PNG_WROTE_INFO_BEFORE_PLTE;
 165.178 @@ -156,7 +153,7 @@
 165.179     int i;
 165.180  #endif
 165.181  
 165.182 -   png_debug(1, "in png_write_info\n");
 165.183 +   png_debug(1, "in png_write_info");
 165.184  
 165.185     if (png_ptr == NULL || info_ptr == NULL)
 165.186        return;
 165.187 @@ -165,151 +162,157 @@
 165.188  
 165.189     if (info_ptr->valid & PNG_INFO_PLTE)
 165.190        png_write_PLTE(png_ptr, info_ptr->palette,
 165.191 -         (png_uint_32)info_ptr->num_palette);
 165.192 +          (png_uint_32)info_ptr->num_palette);
 165.193 +
 165.194     else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
 165.195        png_error(png_ptr, "Valid palette required for paletted images");
 165.196  
 165.197 -#if defined(PNG_WRITE_tRNS_SUPPORTED)
 165.198 +#ifdef PNG_WRITE_tRNS_SUPPORTED
 165.199     if (info_ptr->valid & PNG_INFO_tRNS)
 165.200 +   {
 165.201 +#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED
 165.202 +      /* Invert the alpha channel (in tRNS) */
 165.203 +      if ((png_ptr->transformations & PNG_INVERT_ALPHA) &&
 165.204 +          info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
 165.205        {
 165.206 -#if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
 165.207 -         /* invert the alpha channel (in tRNS) */
 165.208 -         if ((png_ptr->transformations & PNG_INVERT_ALPHA) &&
 165.209 -            info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
 165.210 -         {
 165.211 -            int j;
 165.212 -            for (j=0; j<(int)info_ptr->num_trans; j++)
 165.213 -               info_ptr->trans[j] = (png_byte)(255 - info_ptr->trans[j]);
 165.214 -         }
 165.215 -#endif
 165.216 -      png_write_tRNS(png_ptr, info_ptr->trans, &(info_ptr->trans_values),
 165.217 -         info_ptr->num_trans, info_ptr->color_type);
 165.218 +         int j;
 165.219 +         for (j = 0; j<(int)info_ptr->num_trans; j++)
 165.220 +            info_ptr->trans_alpha[j] =
 165.221 +               (png_byte)(255 - info_ptr->trans_alpha[j]);
 165.222        }
 165.223  #endif
 165.224 -#if defined(PNG_WRITE_bKGD_SUPPORTED)
 165.225 +      png_write_tRNS(png_ptr, info_ptr->trans_alpha, &(info_ptr->trans_color),
 165.226 +          info_ptr->num_trans, info_ptr->color_type);
 165.227 +   }
 165.228 +#endif
 165.229 +#ifdef PNG_WRITE_bKGD_SUPPORTED
 165.230     if (info_ptr->valid & PNG_INFO_bKGD)
 165.231        png_write_bKGD(png_ptr, &(info_ptr->background), info_ptr->color_type);
 165.232  #endif
 165.233 -#if defined(PNG_WRITE_hIST_SUPPORTED)
 165.234 +
 165.235 +#ifdef PNG_WRITE_hIST_SUPPORTED
 165.236     if (info_ptr->valid & PNG_INFO_hIST)
 165.237        png_write_hIST(png_ptr, info_ptr->hist, info_ptr->num_palette);
 165.238  #endif
 165.239 -#if defined(PNG_WRITE_oFFs_SUPPORTED)
 165.240 +
 165.241 +#ifdef PNG_WRITE_oFFs_SUPPORTED
 165.242     if (info_ptr->valid & PNG_INFO_oFFs)
 165.243        png_write_oFFs(png_ptr, info_ptr->x_offset, info_ptr->y_offset,
 165.244 -         info_ptr->offset_unit_type);
 165.245 +          info_ptr->offset_unit_type);
 165.246  #endif
 165.247 -#if defined(PNG_WRITE_pCAL_SUPPORTED)
 165.248 +
 165.249 +#ifdef PNG_WRITE_pCAL_SUPPORTED
 165.250     if (info_ptr->valid & PNG_INFO_pCAL)
 165.251        png_write_pCAL(png_ptr, info_ptr->pcal_purpose, info_ptr->pcal_X0,
 165.252 -         info_ptr->pcal_X1, info_ptr->pcal_type, info_ptr->pcal_nparams,
 165.253 -         info_ptr->pcal_units, info_ptr->pcal_params);
 165.254 +          info_ptr->pcal_X1, info_ptr->pcal_type, info_ptr->pcal_nparams,
 165.255 +          info_ptr->pcal_units, info_ptr->pcal_params);
 165.256  #endif
 165.257 -#if defined(PNG_WRITE_sCAL_SUPPORTED)
 165.258 +
 165.259 +#ifdef PNG_WRITE_sCAL_SUPPORTED
 165.260     if (info_ptr->valid & PNG_INFO_sCAL)
 165.261 -#if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
 165.262 -      png_write_sCAL(png_ptr, (int)info_ptr->scal_unit,
 165.263 -          info_ptr->scal_pixel_width, info_ptr->scal_pixel_height);
 165.264 -#else
 165.265 -#ifdef PNG_FIXED_POINT_SUPPORTED
 165.266        png_write_sCAL_s(png_ptr, (int)info_ptr->scal_unit,
 165.267            info_ptr->scal_s_width, info_ptr->scal_s_height);
 165.268 -#else
 165.269 -      png_warning(png_ptr,
 165.270 -          "png_write_sCAL not supported; sCAL chunk not written.");
 165.271 -#endif
 165.272 -#endif
 165.273 -#endif
 165.274 -#if defined(PNG_WRITE_pHYs_SUPPORTED)
 165.275 +#endif /* sCAL */
 165.276 +
 165.277 +#ifdef PNG_WRITE_pHYs_SUPPORTED
 165.278     if (info_ptr->valid & PNG_INFO_pHYs)
 165.279        png_write_pHYs(png_ptr, info_ptr->x_pixels_per_unit,
 165.280 -         info_ptr->y_pixels_per_unit, info_ptr->phys_unit_type);
 165.281 -#endif
 165.282 -#if defined(PNG_WRITE_tIME_SUPPORTED)
 165.283 +          info_ptr->y_pixels_per_unit, info_ptr->phys_unit_type);
 165.284 +#endif /* pHYs */
 165.285 +
 165.286 +#ifdef PNG_WRITE_tIME_SUPPORTED
 165.287     if (info_ptr->valid & PNG_INFO_tIME)
 165.288     {
 165.289        png_write_tIME(png_ptr, &(info_ptr->mod_time));
 165.290        png_ptr->mode |= PNG_WROTE_tIME;
 165.291     }
 165.292 -#endif
 165.293 -#if defined(PNG_WRITE_sPLT_SUPPORTED)
 165.294 +#endif /* tIME */
 165.295 +
 165.296 +#ifdef PNG_WRITE_sPLT_SUPPORTED
 165.297     if (info_ptr->valid & PNG_INFO_sPLT)
 165.298 -     for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
 165.299 -       png_write_sPLT(png_ptr, info_ptr->splt_palettes + i);
 165.300 -#endif
 165.301 -#if defined(PNG_WRITE_TEXT_SUPPORTED)
 165.302 +      for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
 165.303 +         png_write_sPLT(png_ptr, info_ptr->splt_palettes + i);
 165.304 +#endif /* sPLT */
 165.305 +
 165.306 +#ifdef PNG_WRITE_TEXT_SUPPORTED
 165.307     /* Check to see if we need to write text chunks */
 165.308     for (i = 0; i < info_ptr->num_text; i++)
 165.309     {
 165.310 -      png_debug2(2, "Writing header text chunk %d, type %d\n", i,
 165.311 -         info_ptr->text[i].compression);
 165.312 -      /* an internationalized chunk? */
 165.313 +      png_debug2(2, "Writing header text chunk %d, type %d", i,
 165.314 +          info_ptr->text[i].compression);
 165.315 +      /* An internationalized chunk? */
 165.316        if (info_ptr->text[i].compression > 0)
 165.317        {
 165.318 -#if defined(PNG_WRITE_iTXt_SUPPORTED)
 165.319 -          /* write international chunk */
 165.320 -          png_write_iTXt(png_ptr,
 165.321 -                         info_ptr->text[i].compression,
 165.322 -                         info_ptr->text[i].key,
 165.323 -                         info_ptr->text[i].lang,
 165.324 -                         info_ptr->text[i].lang_key,
 165.325 -                         info_ptr->text[i].text);
 165.326 +#ifdef PNG_WRITE_iTXt_SUPPORTED
 165.327 +         /* Write international chunk */
 165.328 +         png_write_iTXt(png_ptr,
 165.329 +             info_ptr->text[i].compression,
 165.330 +             info_ptr->text[i].key,
 165.331 +             info_ptr->text[i].lang,
 165.332 +             info_ptr->text[i].lang_key,
 165.333 +             info_ptr->text[i].text);
 165.334  #else
 165.335            png_warning(png_ptr, "Unable to write international text");
 165.336  #endif
 165.337            /* Mark this chunk as written */
 165.338            info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
 165.339        }
 165.340 +
 165.341        /* If we want a compressed text chunk */
 165.342        else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_zTXt)
 165.343        {
 165.344 -#if defined(PNG_WRITE_zTXt_SUPPORTED)
 165.345 -         /* write compressed chunk */
 165.346 +#ifdef PNG_WRITE_zTXt_SUPPORTED
 165.347 +         /* Write compressed chunk */
 165.348           png_write_zTXt(png_ptr, info_ptr->text[i].key,
 165.349 -            info_ptr->text[i].text, 0,
 165.350 -            info_ptr->text[i].compression);
 165.351 +             info_ptr->text[i].text, 0,
 165.352 +             info_ptr->text[i].compression);
 165.353  #else
 165.354           png_warning(png_ptr, "Unable to write compressed text");
 165.355  #endif
 165.356           /* Mark this chunk as written */
 165.357           info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
 165.358        }
 165.359 +
 165.360        else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
 165.361        {
 165.362 -#if defined(PNG_WRITE_tEXt_SUPPORTED)
 165.363 -         /* write uncompressed chunk */
 165.364 +#ifdef PNG_WRITE_tEXt_SUPPORTED
 165.365 +         /* Write uncompressed chunk */
 165.366           png_write_tEXt(png_ptr, info_ptr->text[i].key,
 165.367 -                         info_ptr->text[i].text,
 165.368 -                         0);
 165.369 +             info_ptr->text[i].text,
 165.370 +             0);
 165.371 +         /* Mark this chunk as written */
 165.372 +         info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
 165.373  #else
 165.374 +         /* Can't get here */
 165.375           png_warning(png_ptr, "Unable to write uncompressed text");
 165.376  #endif
 165.377 -         /* Mark this chunk as written */
 165.378 -         info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
 165.379        }
 165.380     }
 165.381 -#endif
 165.382 -#if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
 165.383 +#endif /* tEXt */
 165.384 +
 165.385 +#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
 165.386     if (info_ptr->unknown_chunks_num)
 165.387     {
 165.388 -       png_unknown_chunk *up;
 165.389 +      png_unknown_chunk *up;
 165.390  
 165.391 -       png_debug(5, "writing extra chunks\n");
 165.392 +      png_debug(5, "writing extra chunks");
 165.393  
 165.394 -       for (up = info_ptr->unknown_chunks;
 165.395 -            up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
 165.396 -            up++)
 165.397 -       {
 165.398 -         int keep=png_handle_as_unknown(png_ptr, up->name);
 165.399 +      for (up = info_ptr->unknown_chunks;
 165.400 +           up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
 165.401 +           up++)
 165.402 +      {
 165.403 +         int keep = png_handle_as_unknown(png_ptr, up->name);
 165.404           if (keep != PNG_HANDLE_CHUNK_NEVER &&
 165.405 -            up->location && (up->location & PNG_HAVE_PLTE) &&
 165.406 -            !(up->location & PNG_HAVE_IDAT) &&
 165.407 -            ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
 165.408 -            (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
 165.409 +             up->location &&
 165.410 +             (up->location & PNG_HAVE_PLTE) &&
 165.411 +             !(up->location & PNG_HAVE_IDAT) &&
 165.412 +             !(up->location & PNG_AFTER_IDAT) &&
 165.413 +             ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
 165.414 +             (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
 165.415           {
 165.416              png_write_chunk(png_ptr, up->name, up->data, up->size);
 165.417           }
 165.418 -       }
 165.419 +      }
 165.420     }
 165.421  #endif
 165.422  }
 165.423 @@ -322,66 +325,71 @@
 165.424  void PNGAPI
 165.425  png_write_end(png_structp png_ptr, png_infop info_ptr)
 165.426  {
 165.427 -   png_debug(1, "in png_write_end\n");
 165.428 +   png_debug(1, "in png_write_end");
 165.429 +
 165.430     if (png_ptr == NULL)
 165.431        return;
 165.432 +
 165.433     if (!(png_ptr->mode & PNG_HAVE_IDAT))
 165.434        png_error(png_ptr, "No IDATs written into file");
 165.435  
 165.436 -   /* see if user wants us to write information chunks */
 165.437 +   /* See if user wants us to write information chunks */
 165.438     if (info_ptr != NULL)
 165.439     {
 165.440 -#if defined(PNG_WRITE_TEXT_SUPPORTED)
 165.441 +#ifdef PNG_WRITE_TEXT_SUPPORTED
 165.442        int i; /* local index variable */
 165.443  #endif
 165.444 -#if defined(PNG_WRITE_tIME_SUPPORTED)
 165.445 -      /* check to see if user has supplied a time chunk */
 165.446 +#ifdef PNG_WRITE_tIME_SUPPORTED
 165.447 +      /* Check to see if user has supplied a time chunk */
 165.448        if ((info_ptr->valid & PNG_INFO_tIME) &&
 165.449 -         !(png_ptr->mode & PNG_WROTE_tIME))
 165.450 +          !(png_ptr->mode & PNG_WROTE_tIME))
 165.451           png_write_tIME(png_ptr, &(info_ptr->mod_time));
 165.452 +
 165.453  #endif
 165.454 -#if defined(PNG_WRITE_TEXT_SUPPORTED)
 165.455 -      /* loop through comment chunks */
 165.456 +#ifdef PNG_WRITE_TEXT_SUPPORTED
 165.457 +      /* Loop through comment chunks */
 165.458        for (i = 0; i < info_ptr->num_text; i++)
 165.459        {
 165.460 -         png_debug2(2, "Writing trailer text chunk %d, type %d\n", i,
 165.461 +         png_debug2(2, "Writing trailer text chunk %d, type %d", i,
 165.462              info_ptr->text[i].compression);
 165.463 -         /* an internationalized chunk? */
 165.464 +         /* An internationalized chunk? */
 165.465           if (info_ptr->text[i].compression > 0)
 165.466           {
 165.467 -#if defined(PNG_WRITE_iTXt_SUPPORTED)
 165.468 -             /* write international chunk */
 165.469 -             png_write_iTXt(png_ptr,
 165.470 -                         info_ptr->text[i].compression,
 165.471 -                         info_ptr->text[i].key,
 165.472 -                         info_ptr->text[i].lang,
 165.473 -                         info_ptr->text[i].lang_key,
 165.474 -                         info_ptr->text[i].text);
 165.475 +#ifdef PNG_WRITE_iTXt_SUPPORTED
 165.476 +            /* Write international chunk */
 165.477 +            png_write_iTXt(png_ptr,
 165.478 +                info_ptr->text[i].compression,
 165.479 +                info_ptr->text[i].key,
 165.480 +                info_ptr->text[i].lang,
 165.481 +                info_ptr->text[i].lang_key,
 165.482 +                info_ptr->text[i].text);
 165.483  #else
 165.484 -             png_warning(png_ptr, "Unable to write international text");
 165.485 +            png_warning(png_ptr, "Unable to write international text");
 165.486  #endif
 165.487 -             /* Mark this chunk as written */
 165.488 -             info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
 165.489 +            /* Mark this chunk as written */
 165.490 +            info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
 165.491           }
 165.492 +
 165.493           else if (info_ptr->text[i].compression >= PNG_TEXT_COMPRESSION_zTXt)
 165.494           {
 165.495 -#if defined(PNG_WRITE_zTXt_SUPPORTED)
 165.496 -            /* write compressed chunk */
 165.497 +#ifdef PNG_WRITE_zTXt_SUPPORTED
 165.498 +            /* Write compressed chunk */
 165.499              png_write_zTXt(png_ptr, info_ptr->text[i].key,
 165.500 -               info_ptr->text[i].text, 0,
 165.501 -               info_ptr->text[i].compression);
 165.502 +                info_ptr->text[i].text, 0,
 165.503 +                info_ptr->text[i].compression);
 165.504  #else
 165.505              png_warning(png_ptr, "Unable to write compressed text");
 165.506  #endif
 165.507              /* Mark this chunk as written */
 165.508              info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
 165.509           }
 165.510 +
 165.511           else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
 165.512           {
 165.513 -#if defined(PNG_WRITE_tEXt_SUPPORTED)
 165.514 -            /* write uncompressed chunk */
 165.515 +#ifdef PNG_WRITE_tEXt_SUPPORTED
 165.516 +            /* Write uncompressed chunk */
 165.517              png_write_tEXt(png_ptr, info_ptr->text[i].key,
 165.518 -               info_ptr->text[i].text, 0);
 165.519 +                info_ptr->text[i].text, 0);
 165.520  #else
 165.521              png_warning(png_ptr, "Unable to write uncompressed text");
 165.522  #endif
 165.523 @@ -391,48 +399,56 @@
 165.524           }
 165.525        }
 165.526  #endif
 165.527 -#if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
 165.528 +#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
 165.529     if (info_ptr->unknown_chunks_num)
 165.530     {
 165.531 -       png_unknown_chunk *up;
 165.532 +      png_unknown_chunk *up;
 165.533  
 165.534 -       png_debug(5, "writing extra chunks\n");
 165.535 +      png_debug(5, "writing extra chunks");
 165.536  
 165.537 -       for (up = info_ptr->unknown_chunks;
 165.538 -            up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
 165.539 -            up++)
 165.540 -       {
 165.541 -         int keep=png_handle_as_unknown(png_ptr, up->name);
 165.542 +      for (up = info_ptr->unknown_chunks;
 165.543 +           up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
 165.544 +           up++)
 165.545 +      {
 165.546 +         int keep = png_handle_as_unknown(png_ptr, up->name);
 165.547           if (keep != PNG_HANDLE_CHUNK_NEVER &&
 165.548 -            up->location && (up->location & PNG_AFTER_IDAT) &&
 165.549 -            ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
 165.550 -            (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
 165.551 +             up->location &&
 165.552 +             (up->location & PNG_AFTER_IDAT) &&
 165.553 +             ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
 165.554 +             (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
 165.555           {
 165.556              png_write_chunk(png_ptr, up->name, up->data, up->size);
 165.557           }
 165.558 -       }
 165.559 +      }
 165.560     }
 165.561  #endif
 165.562     }
 165.563  
 165.564     png_ptr->mode |= PNG_AFTER_IDAT;
 165.565  
 165.566 -   /* write end of PNG file */
 165.567 +   /* Write end of PNG file */
 165.568     png_write_IEND(png_ptr);
 165.569 -#if 0
 165.570 -/* This flush, added in libpng-1.0.8,  causes some applications to crash
 165.571 -   because they do not set png_ptr->output_flush_fn */
 165.572 +   /* This flush, added in libpng-1.0.8, removed from libpng-1.0.9beta03,
 165.573 +    * and restored again in libpng-1.2.30, may cause some applications that
 165.574 +    * do not set png_ptr->output_flush_fn to crash.  If your application
 165.575 +    * experiences a problem, please try building libpng with
 165.576 +    * PNG_WRITE_FLUSH_AFTER_IEND_SUPPORTED defined, and report the event to
 165.577 +    * png-mng-implement at lists.sf.net .
 165.578 +    */
 165.579 +#ifdef PNG_WRITE_FLUSH_SUPPORTED
 165.580 +#  ifdef PNG_WRITE_FLUSH_AFTER_IEND_SUPPORTED
 165.581     png_flush(png_ptr);
 165.582 +#  endif
 165.583  #endif
 165.584  }
 165.585  
 165.586 -#if defined(PNG_WRITE_tIME_SUPPORTED)
 165.587 -#if !defined(_WIN32_WCE)
 165.588 -/* "time.h" functions are not supported on WindowsCE */
 165.589 +#ifdef PNG_CONVERT_tIME_SUPPORTED
 165.590 +/* "tm" structure is not supported on WindowsCE */
 165.591  void PNGAPI
 165.592 -png_convert_from_struct_tm(png_timep ptime, struct tm FAR * ttime)
 165.593 +png_convert_from_struct_tm(png_timep ptime, PNG_CONST struct tm FAR * ttime)
 165.594  {
 165.595 -   png_debug(1, "in png_convert_from_struct_tm\n");
 165.596 +   png_debug(1, "in png_convert_from_struct_tm");
 165.597 +
 165.598     ptime->year = (png_uint_16)(1900 + ttime->tm_year);
 165.599     ptime->month = (png_byte)(ttime->tm_mon + 1);
 165.600     ptime->day = (png_byte)ttime->tm_mday;
 165.601 @@ -446,76 +462,73 @@
 165.602  {
 165.603     struct tm *tbuf;
 165.604  
 165.605 -   png_debug(1, "in png_convert_from_time_t\n");
 165.606 +   png_debug(1, "in png_convert_from_time_t");
 165.607 +
 165.608     tbuf = gmtime(&ttime);
 165.609     png_convert_from_struct_tm(ptime, tbuf);
 165.610  }
 165.611  #endif
 165.612 -#endif
 165.613  
 165.614  /* Initialize png_ptr structure, and allocate any memory needed */
 165.615 -png_structp PNGAPI
 165.616 -png_create_write_struct(png_const_charp user_png_ver, png_voidp error_ptr,
 165.617 -   png_error_ptr error_fn, png_error_ptr warn_fn)
 165.618 +PNG_FUNCTION(png_structp,PNGAPI
 165.619 +png_create_write_struct,(png_const_charp user_png_ver, png_voidp error_ptr,
 165.620 +    png_error_ptr error_fn, png_error_ptr warn_fn),PNG_ALLOCATED)
 165.621  {
 165.622  #ifdef PNG_USER_MEM_SUPPORTED
 165.623     return (png_create_write_struct_2(user_png_ver, error_ptr, error_fn,
 165.624 -      warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL));
 165.625 +       warn_fn, NULL, NULL, NULL));
 165.626  }
 165.627  
 165.628  /* Alternate initialize png_ptr structure, and allocate any memory needed */
 165.629 -png_structp PNGAPI
 165.630 -png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
 165.631 -   png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
 165.632 -   png_malloc_ptr malloc_fn, png_free_ptr free_fn)
 165.633 +static void png_reset_filter_heuristics(png_structp png_ptr); /* forward decl */
 165.634 +
 165.635 +PNG_FUNCTION(png_structp,PNGAPI
 165.636 +png_create_write_struct_2,(png_const_charp user_png_ver, png_voidp error_ptr,
 165.637 +    png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
 165.638 +    png_malloc_ptr malloc_fn, png_free_ptr free_fn),PNG_ALLOCATED)
 165.639  {
 165.640  #endif /* PNG_USER_MEM_SUPPORTED */
 165.641 +   volatile int png_cleanup_needed = 0;
 165.642 +#ifdef PNG_SETJMP_SUPPORTED
 165.643 +   volatile
 165.644 +#endif
 165.645     png_structp png_ptr;
 165.646  #ifdef PNG_SETJMP_SUPPORTED
 165.647  #ifdef USE_FAR_KEYWORD
 165.648 -   jmp_buf jmpbuf;
 165.649 +   jmp_buf tmp_jmpbuf;
 165.650  #endif
 165.651  #endif
 165.652 -   int i;
 165.653 -   png_debug(1, "in png_create_write_struct\n");
 165.654 +
 165.655 +   png_debug(1, "in png_create_write_struct");
 165.656 +
 165.657  #ifdef PNG_USER_MEM_SUPPORTED
 165.658     png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
 165.659 -      (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
 165.660 +       (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
 165.661  #else
 165.662     png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
 165.663  #endif /* PNG_USER_MEM_SUPPORTED */
 165.664     if (png_ptr == NULL)
 165.665        return (NULL);
 165.666  
 165.667 -#if !defined(PNG_1_0_X)
 165.668 -#ifdef PNG_ASSEMBLER_CODE_SUPPORTED
 165.669 -#ifdef PNG_MMX_CODE_SUPPORTED
 165.670 -   png_init_mmx_flags(png_ptr);   /* 1.2.0 addition */
 165.671 -#endif
 165.672 -#endif
 165.673 -#endif /* PNG_1_0_X */
 165.674 -
 165.675 -   /* added at libpng-1.2.6 */
 165.676 +   /* Added at libpng-1.2.6 */
 165.677  #ifdef PNG_SET_USER_LIMITS_SUPPORTED
 165.678 -   png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
 165.679 -   png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
 165.680 +   png_ptr->user_width_max = PNG_USER_WIDTH_MAX;
 165.681 +   png_ptr->user_height_max = PNG_USER_HEIGHT_MAX;
 165.682  #endif
 165.683  
 165.684  #ifdef PNG_SETJMP_SUPPORTED
 165.685 +/* Applications that neglect to set up their own setjmp() and then
 165.686 +   encounter a png_error() will longjmp here.  Since the jmpbuf is
 165.687 +   then meaningless we abort instead of returning. */
 165.688  #ifdef USE_FAR_KEYWORD
 165.689 -   if (setjmp(jmpbuf))
 165.690 +   if (setjmp(tmp_jmpbuf))
 165.691  #else
 165.692 -   if (setjmp(png_ptr->jmpbuf))
 165.693 +   if (setjmp(png_jmpbuf(png_ptr))) /* sets longjmp to match setjmp */
 165.694  #endif
 165.695 -   {
 165.696 -      png_free(png_ptr, png_ptr->zbuf);
 165.697 -      png_ptr->zbuf=NULL;
 165.698 -      png_destroy_struct(png_ptr);
 165.699 -      return (NULL);
 165.700 -   }
 165.701  #ifdef USE_FAR_KEYWORD
 165.702 -   png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
 165.703 +   png_memcpy(png_jmpbuf(png_ptr), tmp_jmpbuf, png_sizeof(jmp_buf));
 165.704  #endif
 165.705 +      PNG_ABORT();
 165.706  #endif
 165.707  
 165.708  #ifdef PNG_USER_MEM_SUPPORTED
 165.709 @@ -523,208 +536,43 @@
 165.710  #endif /* PNG_USER_MEM_SUPPORTED */
 165.711     png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
 165.712  
 165.713 -   i=0;
 165.714 -   do
 165.715 +   if (!png_user_version_check(png_ptr, user_png_ver))
 165.716 +      png_cleanup_needed = 1;
 165.717 +
 165.718 +   /* Initialize zbuf - compression buffer */
 165.719 +   png_ptr->zbuf_size = PNG_ZBUF_SIZE;
 165.720 +
 165.721 +   if (!png_cleanup_needed)
 165.722     {
 165.723 -     if(user_png_ver[i] != png_libpng_ver[i])
 165.724 -        png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
 165.725 -   } while (png_libpng_ver[i++]);
 165.726 -
 165.727 -   if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
 165.728 -   {
 165.729 -     /* Libpng 0.90 and later are binary incompatible with libpng 0.89, so
 165.730 -      * we must recompile any applications that use any older library version.
 165.731 -      * For versions after libpng 1.0, we will be compatible, so we need
 165.732 -      * only check the first digit.
 165.733 -      */
 165.734 -     if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
 165.735 -         (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
 165.736 -         (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
 165.737 -     {
 165.738 -#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
 165.739 -        char msg[80];
 165.740 -        if (user_png_ver)
 165.741 -        {
 165.742 -          sprintf(msg, "Application was compiled with png.h from libpng-%.20s",
 165.743 -             user_png_ver);
 165.744 -          png_warning(png_ptr, msg);
 165.745 -        }
 165.746 -        sprintf(msg, "Application  is  running with png.c from libpng-%.20s",
 165.747 -           png_libpng_ver);
 165.748 -        png_warning(png_ptr, msg);
 165.749 -#endif
 165.750 -#ifdef PNG_ERROR_NUMBERS_SUPPORTED
 165.751 -        png_ptr->flags=0;
 165.752 -#endif
 165.753 -        png_error(png_ptr,
 165.754 -           "Incompatible libpng version in application and library");
 165.755 -     }
 165.756 +      png_ptr->zbuf = (png_bytep)png_malloc_warn(png_ptr,
 165.757 +          png_ptr->zbuf_size);
 165.758 +      if (png_ptr->zbuf == NULL)
 165.759 +         png_cleanup_needed = 1;
 165.760     }
 165.761  
 165.762 -   /* initialize zbuf - compression buffer */
 165.763 -   png_ptr->zbuf_size = PNG_ZBUF_SIZE;
 165.764 -   png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
 165.765 -      (png_uint_32)png_ptr->zbuf_size);
 165.766 +   if (png_cleanup_needed)
 165.767 +   {
 165.768 +       /* Clean up PNG structure and deallocate any memory. */
 165.769 +       png_free(png_ptr, png_ptr->zbuf);
 165.770 +       png_ptr->zbuf = NULL;
 165.771 +#ifdef PNG_USER_MEM_SUPPORTED
 165.772 +       png_destroy_struct_2((png_voidp)png_ptr,
 165.773 +           (png_free_ptr)free_fn, (png_voidp)mem_ptr);
 165.774 +#else
 165.775 +       png_destroy_struct((png_voidp)png_ptr);
 165.776 +#endif
 165.777 +       return (NULL);
 165.778 +   }
 165.779  
 165.780 -   png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL,
 165.781 -      png_flush_ptr_NULL);
 165.782 +   png_set_write_fn(png_ptr, NULL, NULL, NULL);
 165.783  
 165.784 -#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
 165.785 -   png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
 165.786 -      1, png_doublep_NULL, png_doublep_NULL);
 165.787 +#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
 165.788 +   png_reset_filter_heuristics(png_ptr);
 165.789  #endif
 165.790  
 165.791 -#ifdef PNG_SETJMP_SUPPORTED
 165.792 -/* Applications that neglect to set up their own setjmp() and then encounter
 165.793 -   a png_error() will longjmp here.  Since the jmpbuf is then meaningless we
 165.794 -   abort instead of returning. */
 165.795 -#ifdef USE_FAR_KEYWORD
 165.796 -   if (setjmp(jmpbuf))
 165.797 -      PNG_ABORT();
 165.798 -   png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
 165.799 -#else
 165.800 -   if (setjmp(png_ptr->jmpbuf))
 165.801 -      PNG_ABORT();
 165.802 -#endif
 165.803 -#endif
 165.804     return (png_ptr);
 165.805  }
 165.806  
 165.807 -/* Initialize png_ptr structure, and allocate any memory needed */
 165.808 -#if defined(PNG_1_0_X) || defined(PNG_1_2_X)
 165.809 -/* Deprecated. */
 165.810 -#undef png_write_init
 165.811 -void PNGAPI
 165.812 -png_write_init(png_structp png_ptr)
 165.813 -{
 165.814 -   /* We only come here via pre-1.0.7-compiled applications */
 165.815 -   png_write_init_2(png_ptr, "1.0.6 or earlier", 0, 0);
 165.816 -}
 165.817 -
 165.818 -void PNGAPI
 165.819 -png_write_init_2(png_structp png_ptr, png_const_charp user_png_ver,
 165.820 -   png_size_t png_struct_size, png_size_t png_info_size)
 165.821 -{
 165.822 -   /* We only come here via pre-1.0.12-compiled applications */
 165.823 -   if(png_ptr == NULL) return;
 165.824 -#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
 165.825 -   if(png_sizeof(png_struct) > png_struct_size ||
 165.826 -      png_sizeof(png_info) > png_info_size)
 165.827 -   {
 165.828 -      char msg[80];
 165.829 -      png_ptr->warning_fn=NULL;
 165.830 -      if (user_png_ver)
 165.831 -      {
 165.832 -        sprintf(msg, "Application was compiled with png.h from libpng-%.20s",
 165.833 -           user_png_ver);
 165.834 -        png_warning(png_ptr, msg);
 165.835 -      }
 165.836 -      sprintf(msg, "Application  is  running with png.c from libpng-%.20s",
 165.837 -         png_libpng_ver);
 165.838 -      png_warning(png_ptr, msg);
 165.839 -   }
 165.840 -#endif
 165.841 -   if(png_sizeof(png_struct) > png_struct_size)
 165.842 -     {
 165.843 -       png_ptr->error_fn=NULL;
 165.844 -#ifdef PNG_ERROR_NUMBERS_SUPPORTED
 165.845 -       png_ptr->flags=0;
 165.846 -#endif
 165.847 -       png_error(png_ptr,
 165.848 -       "The png struct allocated by the application for writing is too small.");
 165.849 -     }
 165.850 -   if(png_sizeof(png_info) > png_info_size)
 165.851 -     {
 165.852 -       png_ptr->error_fn=NULL;
 165.853 -#ifdef PNG_ERROR_NUMBERS_SUPPORTED
 165.854 -       png_ptr->flags=0;
 165.855 -#endif
 165.856 -       png_error(png_ptr,
 165.857 -       "The info struct allocated by the application for writing is too small.");
 165.858 -     }
 165.859 -   png_write_init_3(&png_ptr, user_png_ver, png_struct_size);
 165.860 -}
 165.861 -#endif /* PNG_1_0_X || PNG_1_2_X */
 165.862 -
 165.863 -
 165.864 -void PNGAPI
 165.865 -png_write_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
 165.866 -   png_size_t png_struct_size)
 165.867 -{
 165.868 -   png_structp png_ptr=*ptr_ptr;
 165.869 -#ifdef PNG_SETJMP_SUPPORTED
 165.870 -   jmp_buf tmp_jmp; /* to save current jump buffer */
 165.871 -#endif
 165.872 -
 165.873 -   int i = 0;
 165.874 -
 165.875 -   if (png_ptr == NULL)
 165.876 -      return;
 165.877 -
 165.878 -   do
 165.879 -   {
 165.880 -     if (user_png_ver[i] != png_libpng_ver[i])
 165.881 -     {
 165.882 -#ifdef PNG_LEGACY_SUPPORTED
 165.883 -       png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
 165.884 -#else
 165.885 -       png_ptr->warning_fn=NULL;
 165.886 -       png_warning(png_ptr,
 165.887 -     "Application uses deprecated png_write_init() and should be recompiled.");
 165.888 -       break;
 165.889 -#endif
 165.890 -     }
 165.891 -   } while (png_libpng_ver[i++]);
 165.892 -
 165.893 -   png_debug(1, "in png_write_init_3\n");
 165.894 -
 165.895 -#ifdef PNG_SETJMP_SUPPORTED
 165.896 -   /* save jump buffer and error functions */
 165.897 -   png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
 165.898 -#endif
 165.899 -
 165.900 -   if (png_sizeof(png_struct) > png_struct_size)
 165.901 -     {
 165.902 -       png_destroy_struct(png_ptr);
 165.903 -       png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
 165.904 -       *ptr_ptr = png_ptr;
 165.905 -     }
 165.906 -
 165.907 -   /* reset all variables to 0 */
 165.908 -   png_memset(png_ptr, 0, png_sizeof (png_struct));
 165.909 -
 165.910 -   /* added at libpng-1.2.6 */
 165.911 -#ifdef PNG_SET_USER_LIMITS_SUPPORTED
 165.912 -   png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
 165.913 -   png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
 165.914 -#endif
 165.915 -
 165.916 -#if !defined(PNG_1_0_X)
 165.917 -#ifdef PNG_ASSEMBLER_CODE_SUPPORTED
 165.918 -#ifdef PNG_MMX_CODE_SUPPORTED
 165.919 -   png_init_mmx_flags(png_ptr);   /* 1.2.0 addition */
 165.920 -#endif
 165.921 -#endif
 165.922 -#endif /* PNG_1_0_X */
 165.923 -
 165.924 -#ifdef PNG_SETJMP_SUPPORTED
 165.925 -   /* restore jump buffer */
 165.926 -   png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
 165.927 -#endif
 165.928 -
 165.929 -   png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL,
 165.930 -      png_flush_ptr_NULL);
 165.931 -
 165.932 -   /* initialize zbuf - compression buffer */
 165.933 -   png_ptr->zbuf_size = PNG_ZBUF_SIZE;
 165.934 -   png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
 165.935 -      (png_uint_32)png_ptr->zbuf_size);
 165.936 -
 165.937 -#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
 165.938 -   png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
 165.939 -      1, png_doublep_NULL, png_doublep_NULL);
 165.940 -#endif
 165.941 -}
 165.942  
 165.943  /* Write a few rows of image data.  If the image is interlaced,
 165.944   * either you will have to write the 7 sub images, or, if you
 165.945 @@ -733,17 +581,17 @@
 165.946   */
 165.947  void PNGAPI
 165.948  png_write_rows(png_structp png_ptr, png_bytepp row,
 165.949 -   png_uint_32 num_rows)
 165.950 +    png_uint_32 num_rows)
 165.951  {
 165.952     png_uint_32 i; /* row counter */
 165.953     png_bytepp rp; /* row pointer */
 165.954  
 165.955 -   png_debug(1, "in png_write_rows\n");
 165.956 +   png_debug(1, "in png_write_rows");
 165.957  
 165.958     if (png_ptr == NULL)
 165.959        return;
 165.960  
 165.961 -   /* loop through the rows */
 165.962 +   /* Loop through the rows */
 165.963     for (i = 0, rp = row; i < num_rows; i++, rp++)
 165.964     {
 165.965        png_write_row(png_ptr, *rp);
 165.966 @@ -763,18 +611,20 @@
 165.967     if (png_ptr == NULL)
 165.968        return;
 165.969  
 165.970 -   png_debug(1, "in png_write_image\n");
 165.971 -#if defined(PNG_WRITE_INTERLACING_SUPPORTED)
 165.972 -   /* intialize interlace handling.  If image is not interlaced,
 165.973 -      this will set pass to 1 */
 165.974 +   png_debug(1, "in png_write_image");
 165.975 +
 165.976 +#ifdef PNG_WRITE_INTERLACING_SUPPORTED
 165.977 +   /* Initialize interlace handling.  If image is not interlaced,
 165.978 +    * this will set pass to 1
 165.979 +    */
 165.980     num_pass = png_set_interlace_handling(png_ptr);
 165.981  #else
 165.982     num_pass = 1;
 165.983  #endif
 165.984 -   /* loop through passes */
 165.985 +   /* Loop through passes */
 165.986     for (pass = 0; pass < num_pass; pass++)
 165.987     {
 165.988 -      /* loop through image */
 165.989 +      /* Loop through image */
 165.990        for (i = 0, rp = image; i < png_ptr->height; i++, rp++)
 165.991        {
 165.992           png_write_row(png_ptr, *rp);
 165.993 @@ -782,58 +632,66 @@
 165.994     }
 165.995  }
 165.996  
 165.997 -/* called by user to write a row of image data */
 165.998 +/* Called by user to write a row of image data */
 165.999  void PNGAPI
165.1000 -png_write_row(png_structp png_ptr, png_bytep row)
165.1001 +png_write_row(png_structp png_ptr, png_const_bytep row)
165.1002  {
165.1003     if (png_ptr == NULL)
165.1004        return;
165.1005 -   png_debug2(1, "in png_write_row (row %ld, pass %d)\n",
165.1006 +
165.1007 +   png_debug2(1, "in png_write_row (row %u, pass %d)",
165.1008        png_ptr->row_number, png_ptr->pass);
165.1009  
165.1010 -   /* initialize transformations and other stuff if first time */
165.1011 +   /* Initialize transformations and other stuff if first time */
165.1012     if (png_ptr->row_number == 0 && png_ptr->pass == 0)
165.1013     {
165.1014 -   /* make sure we wrote the header info */
165.1015 -   if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
165.1016 -      png_error(png_ptr,
165.1017 -         "png_write_info was never called before png_write_row.");
165.1018 +      /* Make sure we wrote the header info */
165.1019 +      if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
165.1020 +         png_error(png_ptr,
165.1021 +             "png_write_info was never called before png_write_row");
165.1022  
165.1023 -   /* check for transforms that have been set but were defined out */
165.1024 +      /* Check for transforms that have been set but were defined out */
165.1025  #if !defined(PNG_WRITE_INVERT_SUPPORTED) && defined(PNG_READ_INVERT_SUPPORTED)
165.1026 -   if (png_ptr->transformations & PNG_INVERT_MONO)
165.1027 -      png_warning(png_ptr, "PNG_WRITE_INVERT_SUPPORTED is not defined.");
165.1028 +      if (png_ptr->transformations & PNG_INVERT_MONO)
165.1029 +         png_warning(png_ptr, "PNG_WRITE_INVERT_SUPPORTED is not defined");
165.1030  #endif
165.1031 +
165.1032  #if !defined(PNG_WRITE_FILLER_SUPPORTED) && defined(PNG_READ_FILLER_SUPPORTED)
165.1033 -   if (png_ptr->transformations & PNG_FILLER)
165.1034 -      png_warning(png_ptr, "PNG_WRITE_FILLER_SUPPORTED is not defined.");
165.1035 +      if (png_ptr->transformations & PNG_FILLER)
165.1036 +         png_warning(png_ptr, "PNG_WRITE_FILLER_SUPPORTED is not defined");
165.1037  #endif
165.1038 -#if !defined(PNG_WRITE_PACKSWAP_SUPPORTED) && defined(PNG_READ_PACKSWAP_SUPPORTED)
165.1039 -   if (png_ptr->transformations & PNG_PACKSWAP)
165.1040 -      png_warning(png_ptr, "PNG_WRITE_PACKSWAP_SUPPORTED is not defined.");
165.1041 +#if !defined(PNG_WRITE_PACKSWAP_SUPPORTED) && \
165.1042 +    defined(PNG_READ_PACKSWAP_SUPPORTED)
165.1043 +      if (png_ptr->transformations & PNG_PACKSWAP)
165.1044 +         png_warning(png_ptr,
165.1045 +             "PNG_WRITE_PACKSWAP_SUPPORTED is not defined");
165.1046  #endif
165.1047 +
165.1048  #if !defined(PNG_WRITE_PACK_SUPPORTED) && defined(PNG_READ_PACK_SUPPORTED)
165.1049 -   if (png_ptr->transformations & PNG_PACK)
165.1050 -      png_warning(png_ptr, "PNG_WRITE_PACK_SUPPORTED is not defined.");
165.1051 +      if (png_ptr->transformations & PNG_PACK)
165.1052 +         png_warning(png_ptr, "PNG_WRITE_PACK_SUPPORTED is not defined");
165.1053  #endif
165.1054 +
165.1055  #if !defined(PNG_WRITE_SHIFT_SUPPORTED) && defined(PNG_READ_SHIFT_SUPPORTED)
165.1056 -   if (png_ptr->transformations & PNG_SHIFT)
165.1057 -      png_warning(png_ptr, "PNG_WRITE_SHIFT_SUPPORTED is not defined.");
165.1058 +      if (png_ptr->transformations & PNG_SHIFT)
165.1059 +         png_warning(png_ptr, "PNG_WRITE_SHIFT_SUPPORTED is not defined");
165.1060  #endif
165.1061 +
165.1062  #if !defined(PNG_WRITE_BGR_SUPPORTED) && defined(PNG_READ_BGR_SUPPORTED)
165.1063 -   if (png_ptr->transformations & PNG_BGR)
165.1064 -      png_warning(png_ptr, "PNG_WRITE_BGR_SUPPORTED is not defined.");
165.1065 +      if (png_ptr->transformations & PNG_BGR)
165.1066 +         png_warning(png_ptr, "PNG_WRITE_BGR_SUPPORTED is not defined");
165.1067  #endif
165.1068 +
165.1069  #if !defined(PNG_WRITE_SWAP_SUPPORTED) && defined(PNG_READ_SWAP_SUPPORTED)
165.1070 -   if (png_ptr->transformations & PNG_SWAP_BYTES)
165.1071 -      png_warning(png_ptr, "PNG_WRITE_SWAP_SUPPORTED is not defined.");
165.1072 +      if (png_ptr->transformations & PNG_SWAP_BYTES)
165.1073 +         png_warning(png_ptr, "PNG_WRITE_SWAP_SUPPORTED is not defined");
165.1074  #endif
165.1075  
165.1076        png_write_start_row(png_ptr);
165.1077     }
165.1078  
165.1079 -#if defined(PNG_WRITE_INTERLACING_SUPPORTED)
165.1080 -   /* if interlaced and not interested in row, return */
165.1081 +#ifdef PNG_WRITE_INTERLACING_SUPPORTED
165.1082 +   /* If interlaced and not interested in row, return */
165.1083     if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
165.1084     {
165.1085        switch (png_ptr->pass)
165.1086 @@ -845,6 +703,7 @@
165.1087                 return;
165.1088              }
165.1089              break;
165.1090 +
165.1091           case 1:
165.1092              if ((png_ptr->row_number & 0x07) || png_ptr->width < 5)
165.1093              {
165.1094 @@ -852,6 +711,7 @@
165.1095                 return;
165.1096              }
165.1097              break;
165.1098 +
165.1099           case 2:
165.1100              if ((png_ptr->row_number & 0x07) != 4)
165.1101              {
165.1102 @@ -859,6 +719,7 @@
165.1103                 return;
165.1104              }
165.1105              break;
165.1106 +
165.1107           case 3:
165.1108              if ((png_ptr->row_number & 0x03) || png_ptr->width < 3)
165.1109              {
165.1110 @@ -866,6 +727,7 @@
165.1111                 return;
165.1112              }
165.1113              break;
165.1114 +
165.1115           case 4:
165.1116              if ((png_ptr->row_number & 0x03) != 2)
165.1117              {
165.1118 @@ -873,6 +735,7 @@
165.1119                 return;
165.1120              }
165.1121              break;
165.1122 +
165.1123           case 5:
165.1124              if ((png_ptr->row_number & 0x01) || png_ptr->width < 2)
165.1125              {
165.1126 @@ -880,6 +743,7 @@
165.1127                 return;
165.1128              }
165.1129              break;
165.1130 +
165.1131           case 6:
165.1132              if (!(png_ptr->row_number & 0x01))
165.1133              {
165.1134 @@ -887,11 +751,14 @@
165.1135                 return;
165.1136              }
165.1137              break;
165.1138 +
165.1139 +         default: /* error: ignore it */
165.1140 +            break;
165.1141        }
165.1142     }
165.1143  #endif
165.1144  
165.1145 -   /* set up row info for transformations */
165.1146 +   /* Set up row info for transformations */
165.1147     png_ptr->row_info.color_type = png_ptr->color_type;
165.1148     png_ptr->row_info.width = png_ptr->usr_width;
165.1149     png_ptr->row_info.channels = png_ptr->usr_channels;
165.1150 @@ -902,25 +769,25 @@
165.1151     png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
165.1152        png_ptr->row_info.width);
165.1153  
165.1154 -   png_debug1(3, "row_info->color_type = %d\n", png_ptr->row_info.color_type);
165.1155 -   png_debug1(3, "row_info->width = %lu\n", png_ptr->row_info.width);
165.1156 -   png_debug1(3, "row_info->channels = %d\n", png_ptr->row_info.channels);
165.1157 -   png_debug1(3, "row_info->bit_depth = %d\n", png_ptr->row_info.bit_depth);
165.1158 -   png_debug1(3, "row_info->pixel_depth = %d\n", png_ptr->row_info.pixel_depth);
165.1159 -   png_debug1(3, "row_info->rowbytes = %lu\n", png_ptr->row_info.rowbytes);
165.1160 +   png_debug1(3, "row_info->color_type = %d", png_ptr->row_info.color_type);
165.1161 +   png_debug1(3, "row_info->width = %u", png_ptr->row_info.width);
165.1162 +   png_debug1(3, "row_info->channels = %d", png_ptr->row_info.channels);
165.1163 +   png_debug1(3, "row_info->bit_depth = %d", png_ptr->row_info.bit_depth);
165.1164 +   png_debug1(3, "row_info->pixel_depth = %d", png_ptr->row_info.pixel_depth);
165.1165 +   png_debug1(3, "row_info->rowbytes = %lu",
165.1166 +       (unsigned long)png_ptr->row_info.rowbytes);
165.1167  
165.1168     /* Copy user's row into buffer, leaving room for filter byte. */
165.1169 -   png_memcpy_check(png_ptr, png_ptr->row_buf + 1, row,
165.1170 -      png_ptr->row_info.rowbytes);
165.1171 +   png_memcpy(png_ptr->row_buf + 1, row, png_ptr->row_info.rowbytes);
165.1172  
165.1173 -#if defined(PNG_WRITE_INTERLACING_SUPPORTED)
165.1174 -   /* handle interlacing */
165.1175 +#ifdef PNG_WRITE_INTERLACING_SUPPORTED
165.1176 +   /* Handle interlacing */
165.1177     if (png_ptr->interlaced && png_ptr->pass < 6 &&
165.1178 -      (png_ptr->transformations & PNG_INTERLACE))
165.1179 +       (png_ptr->transformations & PNG_INTERLACE))
165.1180     {
165.1181        png_do_write_interlace(&(png_ptr->row_info),
165.1182 -         png_ptr->row_buf + 1, png_ptr->pass);
165.1183 -      /* this should always get caught above, but still ... */
165.1184 +          png_ptr->row_buf + 1, png_ptr->pass);
165.1185 +      /* This should always get caught above, but still ... */
165.1186        if (!(png_ptr->row_info.width))
165.1187        {
165.1188           png_write_finish_row(png_ptr);
165.1189 @@ -929,11 +796,13 @@
165.1190     }
165.1191  #endif
165.1192  
165.1193 -   /* handle other transformations */
165.1194 +#ifdef PNG_WRITE_TRANSFORMS_SUPPORTED
165.1195 +   /* Handle other transformations */
165.1196     if (png_ptr->transformations)
165.1197        png_do_write_transformations(png_ptr);
165.1198 +#endif
165.1199  
165.1200 -#if defined(PNG_MNG_FEATURES_SUPPORTED)
165.1201 +#ifdef PNG_MNG_FEATURES_SUPPORTED
165.1202     /* Write filter_method 64 (intrapixel differencing) only if
165.1203      * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and
165.1204      * 2. Libpng did not write a PNG signature (this filter_method is only
165.1205 @@ -943,8 +812,8 @@
165.1206      * 4. The filter_method is 64 and
165.1207      * 5. The color_type is RGB or RGBA
165.1208      */
165.1209 -   if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
165.1210 -      (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
165.1211 +   if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
165.1212 +       (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
165.1213     {
165.1214        /* Intrapixel differencing */
165.1215        png_do_write_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1);
165.1216 @@ -958,73 +827,73 @@
165.1217        (*(png_ptr->write_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
165.1218  }
165.1219  
165.1220 -#if defined(PNG_WRITE_FLUSH_SUPPORTED)
165.1221 +#ifdef PNG_WRITE_FLUSH_SUPPORTED
165.1222  /* Set the automatic flush interval or 0 to turn flushing off */
165.1223  void PNGAPI
165.1224  png_set_flush(png_structp png_ptr, int nrows)
165.1225  {
165.1226 -   png_debug(1, "in png_set_flush\n");
165.1227 +   png_debug(1, "in png_set_flush");
165.1228 +
165.1229     if (png_ptr == NULL)
165.1230        return;
165.1231 +
165.1232     png_ptr->flush_dist = (nrows < 0 ? 0 : nrows);
165.1233  }
165.1234  
165.1235 -/* flush the current output buffers now */
165.1236 +/* Flush the current output buffers now */
165.1237  void PNGAPI
165.1238  png_write_flush(png_structp png_ptr)
165.1239  {
165.1240     int wrote_IDAT;
165.1241  
165.1242 -   png_debug(1, "in png_write_flush\n");
165.1243 +   png_debug(1, "in png_write_flush");
165.1244 +
165.1245     if (png_ptr == NULL)
165.1246        return;
165.1247 +
165.1248     /* We have already written out all of the data */
165.1249     if (png_ptr->row_number >= png_ptr->num_rows)
165.1250 -     return;
165.1251 +      return;
165.1252  
165.1253     do
165.1254     {
165.1255        int ret;
165.1256  
165.1257 -      /* compress the data */
165.1258 +      /* Compress the data */
165.1259        ret = deflate(&png_ptr->zstream, Z_SYNC_FLUSH);
165.1260        wrote_IDAT = 0;
165.1261  
165.1262 -      /* check for compression errors */
165.1263 +      /* Check for compression errors */
165.1264        if (ret != Z_OK)
165.1265        {
165.1266           if (png_ptr->zstream.msg != NULL)
165.1267              png_error(png_ptr, png_ptr->zstream.msg);
165.1268 +
165.1269           else
165.1270              png_error(png_ptr, "zlib error");
165.1271        }
165.1272  
165.1273        if (!(png_ptr->zstream.avail_out))
165.1274        {
165.1275 -         /* write the IDAT and reset the zlib output buffer */
165.1276 -         png_write_IDAT(png_ptr, png_ptr->zbuf,
165.1277 -                        png_ptr->zbuf_size);
165.1278 -         png_ptr->zstream.next_out = png_ptr->zbuf;
165.1279 -         png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
165.1280 +         /* Write the IDAT and reset the zlib output buffer */
165.1281 +         png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
165.1282           wrote_IDAT = 1;
165.1283        }
165.1284 -   } while(wrote_IDAT == 1);
165.1285 +   } while (wrote_IDAT == 1);
165.1286  
165.1287     /* If there is any data left to be output, write it into a new IDAT */
165.1288     if (png_ptr->zbuf_size != png_ptr->zstream.avail_out)
165.1289     {
165.1290 -      /* write the IDAT and reset the zlib output buffer */
165.1291 +      /* Write the IDAT and reset the zlib output buffer */
165.1292        png_write_IDAT(png_ptr, png_ptr->zbuf,
165.1293 -                     png_ptr->zbuf_size - png_ptr->zstream.avail_out);
165.1294 -      png_ptr->zstream.next_out = png_ptr->zbuf;
165.1295 -      png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
165.1296 +          png_ptr->zbuf_size - png_ptr->zstream.avail_out);
165.1297     }
165.1298     png_ptr->flush_rows = 0;
165.1299     png_flush(png_ptr);
165.1300  }
165.1301  #endif /* PNG_WRITE_FLUSH_SUPPORTED */
165.1302  
165.1303 -/* free all memory used by the write */
165.1304 +/* Free all memory used by the write */
165.1305  void PNGAPI
165.1306  png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)
165.1307  {
165.1308 @@ -1035,7 +904,8 @@
165.1309     png_voidp mem_ptr = NULL;
165.1310  #endif
165.1311  
165.1312 -   png_debug(1, "in png_destroy_write_struct\n");
165.1313 +   png_debug(1, "in png_destroy_write_struct");
165.1314 +
165.1315     if (png_ptr_ptr != NULL)
165.1316     {
165.1317        png_ptr = *png_ptr_ptr;
165.1318 @@ -1045,25 +915,35 @@
165.1319  #endif
165.1320     }
165.1321  
165.1322 +#ifdef PNG_USER_MEM_SUPPORTED
165.1323 +   if (png_ptr != NULL)
165.1324 +   {
165.1325 +      free_fn = png_ptr->free_fn;
165.1326 +      mem_ptr = png_ptr->mem_ptr;
165.1327 +   }
165.1328 +#endif
165.1329 +
165.1330     if (info_ptr_ptr != NULL)
165.1331        info_ptr = *info_ptr_ptr;
165.1332  
165.1333     if (info_ptr != NULL)
165.1334     {
165.1335 -      png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
165.1336 +      if (png_ptr != NULL)
165.1337 +      {
165.1338 +         png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
165.1339  
165.1340 -#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
165.1341 -      if (png_ptr->num_chunk_list)
165.1342 -      {
165.1343 -         png_free(png_ptr, png_ptr->chunk_list);
165.1344 -         png_ptr->chunk_list=NULL;
165.1345 -         png_ptr->num_chunk_list=0;
165.1346 +#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
165.1347 +         if (png_ptr->num_chunk_list)
165.1348 +         {
165.1349 +            png_free(png_ptr, png_ptr->chunk_list);
165.1350 +            png_ptr->num_chunk_list = 0;
165.1351 +         }
165.1352 +#endif
165.1353        }
165.1354 -#endif
165.1355  
165.1356  #ifdef PNG_USER_MEM_SUPPORTED
165.1357        png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn,
165.1358 -         (png_voidp)mem_ptr);
165.1359 +          (png_voidp)mem_ptr);
165.1360  #else
165.1361        png_destroy_struct((png_voidp)info_ptr);
165.1362  #endif
165.1363 @@ -1075,7 +955,7 @@
165.1364        png_write_destroy(png_ptr);
165.1365  #ifdef PNG_USER_MEM_SUPPORTED
165.1366        png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn,
165.1367 -         (png_voidp)mem_ptr);
165.1368 +          (png_voidp)mem_ptr);
165.1369  #else
165.1370        png_destroy_struct((png_voidp)png_ptr);
165.1371  #endif
165.1372 @@ -1089,63 +969,68 @@
165.1373  png_write_destroy(png_structp png_ptr)
165.1374  {
165.1375  #ifdef PNG_SETJMP_SUPPORTED
165.1376 -   jmp_buf tmp_jmp; /* save jump buffer */
165.1377 +   jmp_buf tmp_jmp; /* Save jump buffer */
165.1378  #endif
165.1379     png_error_ptr error_fn;
165.1380 +#ifdef PNG_WARNINGS_SUPPORTED
165.1381     png_error_ptr warning_fn;
165.1382 +#endif
165.1383     png_voidp error_ptr;
165.1384  #ifdef PNG_USER_MEM_SUPPORTED
165.1385     png_free_ptr free_fn;
165.1386  #endif
165.1387  
165.1388 -   png_debug(1, "in png_write_destroy\n");
165.1389 -   /* free any memory zlib uses */
165.1390 -   deflateEnd(&png_ptr->zstream);
165.1391 +   png_debug(1, "in png_write_destroy");
165.1392  
165.1393 -   /* free our memory.  png_free checks NULL for us. */
165.1394 +   /* Free any memory zlib uses */
165.1395 +   if (png_ptr->zlib_state != PNG_ZLIB_UNINITIALIZED)
165.1396 +      deflateEnd(&png_ptr->zstream);
165.1397 +
165.1398 +   /* Free our memory.  png_free checks NULL for us. */
165.1399     png_free(png_ptr, png_ptr->zbuf);
165.1400     png_free(png_ptr, png_ptr->row_buf);
165.1401 +#ifdef PNG_WRITE_FILTER_SUPPORTED
165.1402     png_free(png_ptr, png_ptr->prev_row);
165.1403     png_free(png_ptr, png_ptr->sub_row);
165.1404     png_free(png_ptr, png_ptr->up_row);
165.1405     png_free(png_ptr, png_ptr->avg_row);
165.1406     png_free(png_ptr, png_ptr->paeth_row);
165.1407 -
165.1408 -#if defined(PNG_TIME_RFC1123_SUPPORTED)
165.1409 -   png_free(png_ptr, png_ptr->time_buffer);
165.1410  #endif
165.1411  
165.1412 -#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
165.1413 -   png_free(png_ptr, png_ptr->prev_filters);
165.1414 -   png_free(png_ptr, png_ptr->filter_weights);
165.1415 -   png_free(png_ptr, png_ptr->inv_filter_weights);
165.1416 +#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
165.1417 +   /* Use this to save a little code space, it doesn't free the filter_costs */
165.1418 +   png_reset_filter_heuristics(png_ptr);
165.1419     png_free(png_ptr, png_ptr->filter_costs);
165.1420     png_free(png_ptr, png_ptr->inv_filter_costs);
165.1421  #endif
165.1422  
165.1423  #ifdef PNG_SETJMP_SUPPORTED
165.1424 -   /* reset structure */
165.1425 -   png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
165.1426 +   /* Reset structure */
165.1427 +   png_memcpy(tmp_jmp, png_ptr->longjmp_buffer, png_sizeof(jmp_buf));
165.1428  #endif
165.1429  
165.1430     error_fn = png_ptr->error_fn;
165.1431 +#ifdef PNG_WARNINGS_SUPPORTED
165.1432     warning_fn = png_ptr->warning_fn;
165.1433 +#endif
165.1434     error_ptr = png_ptr->error_ptr;
165.1435  #ifdef PNG_USER_MEM_SUPPORTED
165.1436     free_fn = png_ptr->free_fn;
165.1437  #endif
165.1438  
165.1439 -   png_memset(png_ptr, 0, png_sizeof (png_struct));
165.1440 +   png_memset(png_ptr, 0, png_sizeof(png_struct));
165.1441  
165.1442     png_ptr->error_fn = error_fn;
165.1443 +#ifdef PNG_WARNINGS_SUPPORTED
165.1444     png_ptr->warning_fn = warning_fn;
165.1445 +#endif
165.1446     png_ptr->error_ptr = error_ptr;
165.1447  #ifdef PNG_USER_MEM_SUPPORTED
165.1448     png_ptr->free_fn = free_fn;
165.1449  #endif
165.1450  
165.1451  #ifdef PNG_SETJMP_SUPPORTED
165.1452 -   png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
165.1453 +   png_memcpy(png_ptr->longjmp_buffer, tmp_jmp, png_sizeof(jmp_buf));
165.1454  #endif
165.1455  }
165.1456  
165.1457 @@ -1153,27 +1038,48 @@
165.1458  void PNGAPI
165.1459  png_set_filter(png_structp png_ptr, int method, int filters)
165.1460  {
165.1461 -   png_debug(1, "in png_set_filter\n");
165.1462 +   png_debug(1, "in png_set_filter");
165.1463 +
165.1464     if (png_ptr == NULL)
165.1465        return;
165.1466 -#if defined(PNG_MNG_FEATURES_SUPPORTED)
165.1467 -   if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
165.1468 -      (method == PNG_INTRAPIXEL_DIFFERENCING))
165.1469 -         method = PNG_FILTER_TYPE_BASE;
165.1470 +
165.1471 +#ifdef PNG_MNG_FEATURES_SUPPORTED
165.1472 +   if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
165.1473 +       (method == PNG_INTRAPIXEL_DIFFERENCING))
165.1474 +      method = PNG_FILTER_TYPE_BASE;
165.1475 +
165.1476  #endif
165.1477     if (method == PNG_FILTER_TYPE_BASE)
165.1478     {
165.1479        switch (filters & (PNG_ALL_FILTERS | 0x07))
165.1480        {
165.1481 +#ifdef PNG_WRITE_FILTER_SUPPORTED
165.1482           case 5:
165.1483           case 6:
165.1484           case 7: png_warning(png_ptr, "Unknown row filter for method 0");
165.1485 -         case PNG_FILTER_VALUE_NONE:  png_ptr->do_filter=PNG_FILTER_NONE; break;
165.1486 -         case PNG_FILTER_VALUE_SUB:   png_ptr->do_filter=PNG_FILTER_SUB;  break;
165.1487 -         case PNG_FILTER_VALUE_UP:    png_ptr->do_filter=PNG_FILTER_UP;   break;
165.1488 -         case PNG_FILTER_VALUE_AVG:   png_ptr->do_filter=PNG_FILTER_AVG;  break;
165.1489 -         case PNG_FILTER_VALUE_PAETH: png_ptr->do_filter=PNG_FILTER_PAETH;break;
165.1490 -         default: png_ptr->do_filter = (png_byte)filters; break;
165.1491 +#endif /* PNG_WRITE_FILTER_SUPPORTED */
165.1492 +         case PNG_FILTER_VALUE_NONE:
165.1493 +            png_ptr->do_filter = PNG_FILTER_NONE; break;
165.1494 +
165.1495 +#ifdef PNG_WRITE_FILTER_SUPPORTED
165.1496 +         case PNG_FILTER_VALUE_SUB:
165.1497 +            png_ptr->do_filter = PNG_FILTER_SUB; break;
165.1498 +
165.1499 +         case PNG_FILTER_VALUE_UP:
165.1500 +            png_ptr->do_filter = PNG_FILTER_UP; break;
165.1501 +
165.1502 +         case PNG_FILTER_VALUE_AVG:
165.1503 +            png_ptr->do_filter = PNG_FILTER_AVG; break;
165.1504 +
165.1505 +         case PNG_FILTER_VALUE_PAETH:
165.1506 +            png_ptr->do_filter = PNG_FILTER_PAETH; break;
165.1507 +
165.1508 +         default:
165.1509 +            png_ptr->do_filter = (png_byte)filters; break;
165.1510 +#else
165.1511 +         default:
165.1512 +            png_warning(png_ptr, "Unknown row filter for method 0");
165.1513 +#endif /* PNG_WRITE_FILTER_SUPPORTED */
165.1514        }
165.1515  
165.1516        /* If we have allocated the row_buf, this means we have already started
165.1517 @@ -1187,10 +1093,11 @@
165.1518         */
165.1519        if (png_ptr->row_buf != NULL)
165.1520        {
165.1521 +#ifdef PNG_WRITE_FILTER_SUPPORTED
165.1522           if ((png_ptr->do_filter & PNG_FILTER_SUB) && png_ptr->sub_row == NULL)
165.1523           {
165.1524              png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
165.1525 -              (png_ptr->rowbytes + 1));
165.1526 +                (png_ptr->rowbytes + 1));
165.1527              png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
165.1528           }
165.1529  
165.1530 @@ -1199,12 +1106,14 @@
165.1531              if (png_ptr->prev_row == NULL)
165.1532              {
165.1533                 png_warning(png_ptr, "Can't add Up filter after starting");
165.1534 -               png_ptr->do_filter &= ~PNG_FILTER_UP;
165.1535 +               png_ptr->do_filter = (png_byte)(png_ptr->do_filter &
165.1536 +                   ~PNG_FILTER_UP);
165.1537              }
165.1538 +
165.1539              else
165.1540              {
165.1541                 png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
165.1542 -                  (png_ptr->rowbytes + 1));
165.1543 +                   (png_ptr->rowbytes + 1));
165.1544                 png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
165.1545              }
165.1546           }
165.1547 @@ -1214,12 +1123,14 @@
165.1548              if (png_ptr->prev_row == NULL)
165.1549              {
165.1550                 png_warning(png_ptr, "Can't add Average filter after starting");
165.1551 -               png_ptr->do_filter &= ~PNG_FILTER_AVG;
165.1552 +               png_ptr->do_filter = (png_byte)(png_ptr->do_filter &
165.1553 +                   ~PNG_FILTER_AVG);
165.1554              }
165.1555 +
165.1556              else
165.1557              {
165.1558                 png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
165.1559 -                  (png_ptr->rowbytes + 1));
165.1560 +                   (png_ptr->rowbytes + 1));
165.1561                 png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
165.1562              }
165.1563           }
165.1564 @@ -1232,15 +1143,17 @@
165.1565                 png_warning(png_ptr, "Can't add Paeth filter after starting");
165.1566                 png_ptr->do_filter &= (png_byte)(~PNG_FILTER_PAETH);
165.1567              }
165.1568 +
165.1569              else
165.1570              {
165.1571                 png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
165.1572 -                  (png_ptr->rowbytes + 1));
165.1573 +                   (png_ptr->rowbytes + 1));
165.1574                 png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
165.1575              }
165.1576           }
165.1577  
165.1578           if (png_ptr->do_filter == PNG_NO_FILTERS)
165.1579 +#endif /* PNG_WRITE_FILTER_SUPPORTED */
165.1580              png_ptr->do_filter = PNG_FILTER_NONE;
165.1581        }
165.1582     }
165.1583 @@ -1255,131 +1168,253 @@
165.1584   * filtered data going to zlib more consistent, hopefully resulting in
165.1585   * better compression.
165.1586   */
165.1587 -#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)      /* GRR 970116 */
165.1588 -void PNGAPI
165.1589 -png_set_filter_heuristics(png_structp png_ptr, int heuristic_method,
165.1590 -   int num_weights, png_doublep filter_weights,
165.1591 -   png_doublep filter_costs)
165.1592 +#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED      /* GRR 970116 */
165.1593 +/* Convenience reset API. */
165.1594 +static void
165.1595 +png_reset_filter_heuristics(png_structp png_ptr)
165.1596  {
165.1597 -   int i;
165.1598 -
165.1599 -   png_debug(1, "in png_set_filter_heuristics\n");
165.1600 -   if (png_ptr == NULL)
165.1601 -      return;
165.1602 -   if (heuristic_method >= PNG_FILTER_HEURISTIC_LAST)
165.1603 +   /* Clear out any old values in the 'weights' - this must be done because if
165.1604 +    * the app calls set_filter_heuristics multiple times with different
165.1605 +    * 'num_weights' values we would otherwise potentially have wrong sized
165.1606 +    * arrays.
165.1607 +    */
165.1608 +   png_ptr->num_prev_filters = 0;
165.1609 +   png_ptr->heuristic_method = PNG_FILTER_HEURISTIC_UNWEIGHTED;
165.1610 +   if (png_ptr->prev_filters != NULL)
165.1611     {
165.1612 -      png_warning(png_ptr, "Unknown filter heuristic method");
165.1613 -      return;
165.1614 +      png_bytep old = png_ptr->prev_filters;
165.1615 +      png_ptr->prev_filters = NULL;
165.1616 +      png_free(png_ptr, old);
165.1617 +   }
165.1618 +   if (png_ptr->filter_weights != NULL)
165.1619 +   {
165.1620 +      png_uint_16p old = png_ptr->filter_weights;
165.1621 +      png_ptr->filter_weights = NULL;
165.1622 +      png_free(png_ptr, old);
165.1623     }
165.1624  
165.1625 -   if (heuristic_method == PNG_FILTER_HEURISTIC_DEFAULT)
165.1626 +   if (png_ptr->inv_filter_weights != NULL)
165.1627     {
165.1628 -      heuristic_method = PNG_FILTER_HEURISTIC_UNWEIGHTED;
165.1629 +      png_uint_16p old = png_ptr->inv_filter_weights;
165.1630 +      png_ptr->inv_filter_weights = NULL;
165.1631 +      png_free(png_ptr, old);
165.1632     }
165.1633  
165.1634 -   if (num_weights < 0 || filter_weights == NULL ||
165.1635 -      heuristic_method == PNG_FILTER_HEURISTIC_UNWEIGHTED)
165.1636 +   /* Leave the filter_costs - this array is fixed size. */
165.1637 +}
165.1638 +
165.1639 +static int
165.1640 +png_init_filter_heuristics(png_structp png_ptr, int heuristic_method,
165.1641 +   int num_weights)
165.1642 +{
165.1643 +   if (png_ptr == NULL)
165.1644 +      return 0;
165.1645 +
165.1646 +   /* Clear out the arrays */
165.1647 +   png_reset_filter_heuristics(png_ptr);
165.1648 +
165.1649 +   /* Check arguments; the 'reset' function makes the correct settings for the
165.1650 +    * unweighted case, but we must handle the weight case by initializing the
165.1651 +    * arrays for the caller.
165.1652 +    */
165.1653 +   if (heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
165.1654     {
165.1655 -      num_weights = 0;
165.1656 -   }
165.1657 +      int i;
165.1658  
165.1659 -   png_ptr->num_prev_filters = (png_byte)num_weights;
165.1660 -   png_ptr->heuristic_method = (png_byte)heuristic_method;
165.1661 -
165.1662 -   if (num_weights > 0)
165.1663 -   {
165.1664 -      if (png_ptr->prev_filters == NULL)
165.1665 +      if (num_weights > 0)
165.1666        {
165.1667           png_ptr->prev_filters = (png_bytep)png_malloc(png_ptr,
165.1668 -            (png_uint_32)(png_sizeof(png_byte) * num_weights));
165.1669 +             (png_uint_32)(png_sizeof(png_byte) * num_weights));
165.1670  
165.1671           /* To make sure that the weighting starts out fairly */
165.1672           for (i = 0; i < num_weights; i++)
165.1673           {
165.1674              png_ptr->prev_filters[i] = 255;
165.1675           }
165.1676 -      }
165.1677  
165.1678 -      if (png_ptr->filter_weights == NULL)
165.1679 -      {
165.1680           png_ptr->filter_weights = (png_uint_16p)png_malloc(png_ptr,
165.1681 -            (png_uint_32)(png_sizeof(png_uint_16) * num_weights));
165.1682 +             (png_uint_32)(png_sizeof(png_uint_16) * num_weights));
165.1683  
165.1684           png_ptr->inv_filter_weights = (png_uint_16p)png_malloc(png_ptr,
165.1685 -            (png_uint_32)(png_sizeof(png_uint_16) * num_weights));
165.1686 +             (png_uint_32)(png_sizeof(png_uint_16) * num_weights));
165.1687 +
165.1688           for (i = 0; i < num_weights; i++)
165.1689           {
165.1690              png_ptr->inv_filter_weights[i] =
165.1691              png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
165.1692           }
165.1693 +
165.1694 +         /* Safe to set this now */
165.1695 +         png_ptr->num_prev_filters = (png_byte)num_weights;
165.1696        }
165.1697  
165.1698 -      for (i = 0; i < num_weights; i++)
165.1699 +      /* If, in the future, there are other filter methods, this would
165.1700 +       * need to be based on png_ptr->filter.
165.1701 +       */
165.1702 +      if (png_ptr->filter_costs == NULL)
165.1703        {
165.1704 -         if (filter_weights[i] < 0.0)
165.1705 -         {
165.1706 -            png_ptr->inv_filter_weights[i] =
165.1707 -            png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
165.1708 -         }
165.1709 -         else
165.1710 -         {
165.1711 -            png_ptr->inv_filter_weights[i] =
165.1712 -               (png_uint_16)((double)PNG_WEIGHT_FACTOR*filter_weights[i]+0.5);
165.1713 -            png_ptr->filter_weights[i] =
165.1714 -               (png_uint_16)((double)PNG_WEIGHT_FACTOR/filter_weights[i]+0.5);
165.1715 -         }
165.1716 +         png_ptr->filter_costs = (png_uint_16p)png_malloc(png_ptr,
165.1717 +             (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
165.1718 +
165.1719 +         png_ptr->inv_filter_costs = (png_uint_16p)png_malloc(png_ptr,
165.1720 +             (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
165.1721        }
165.1722 -   }
165.1723 -
165.1724 -   /* If, in the future, there are other filter methods, this would
165.1725 -    * need to be based on png_ptr->filter.
165.1726 -    */
165.1727 -   if (png_ptr->filter_costs == NULL)
165.1728 -   {
165.1729 -      png_ptr->filter_costs = (png_uint_16p)png_malloc(png_ptr,
165.1730 -         (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
165.1731 -
165.1732 -      png_ptr->inv_filter_costs = (png_uint_16p)png_malloc(png_ptr,
165.1733 -         (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
165.1734  
165.1735        for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
165.1736        {
165.1737           png_ptr->inv_filter_costs[i] =
165.1738           png_ptr->filter_costs[i] = PNG_COST_FACTOR;
165.1739        }
165.1740 +
165.1741 +      /* All the arrays are inited, safe to set this: */
165.1742 +      png_ptr->heuristic_method = PNG_FILTER_HEURISTIC_WEIGHTED;
165.1743 +
165.1744 +      /* Return the 'ok' code. */
165.1745 +      return 1;
165.1746     }
165.1747 +   else if (heuristic_method == PNG_FILTER_HEURISTIC_DEFAULT ||
165.1748 +      heuristic_method == PNG_FILTER_HEURISTIC_UNWEIGHTED)
165.1749 +   {
165.1750 +      return 1;
165.1751 +   }
165.1752 +   else
165.1753 +   {
165.1754 +      png_warning(png_ptr, "Unknown filter heuristic method");
165.1755 +      return 0;
165.1756 +   }
165.1757 +}
165.1758  
165.1759 -   /* Here is where we set the relative costs of the different filters.  We
165.1760 -    * should take the desired compression level into account when setting
165.1761 -    * the costs, so that Paeth, for instance, has a high relative cost at low
165.1762 -    * compression levels, while it has a lower relative cost at higher
165.1763 -    * compression settings.  The filter types are in order of increasing
165.1764 -    * relative cost, so it would be possible to do this with an algorithm.
165.1765 +/* Provide floating and fixed point APIs */
165.1766 +#ifdef PNG_FLOATING_POINT_SUPPORTED
165.1767 +void PNGAPI
165.1768 +png_set_filter_heuristics(png_structp png_ptr, int heuristic_method,
165.1769 +    int num_weights, png_const_doublep filter_weights,
165.1770 +    png_const_doublep filter_costs)
165.1771 +{
165.1772 +   png_debug(1, "in png_set_filter_heuristics");
165.1773 +
165.1774 +   /* The internal API allocates all the arrays and ensures that the elements of
165.1775 +    * those arrays are set to the default value.
165.1776      */
165.1777 -   for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
165.1778 +   if (!png_init_filter_heuristics(png_ptr, heuristic_method, num_weights))
165.1779 +      return;
165.1780 +
165.1781 +   /* If using the weighted method copy in the weights. */
165.1782 +   if (heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
165.1783     {
165.1784 -      if (filter_costs == NULL || filter_costs[i] < 0.0)
165.1785 +      int i;
165.1786 +      for (i = 0; i < num_weights; i++)
165.1787 +      {
165.1788 +         if (filter_weights[i] <= 0.0)
165.1789 +         {
165.1790 +            png_ptr->inv_filter_weights[i] =
165.1791 +            png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
165.1792 +         }
165.1793 +
165.1794 +         else
165.1795 +         {
165.1796 +            png_ptr->inv_filter_weights[i] =
165.1797 +                (png_uint_16)(PNG_WEIGHT_FACTOR*filter_weights[i]+.5);
165.1798 +
165.1799 +            png_ptr->filter_weights[i] =
165.1800 +                (png_uint_16)(PNG_WEIGHT_FACTOR/filter_weights[i]+.5);
165.1801 +         }
165.1802 +      }
165.1803 +
165.1804 +      /* Here is where we set the relative costs of the different filters.  We
165.1805 +       * should take the desired compression level into account when setting
165.1806 +       * the costs, so that Paeth, for instance, has a high relative cost at low
165.1807 +       * compression levels, while it has a lower relative cost at higher
165.1808 +       * compression settings.  The filter types are in order of increasing
165.1809 +       * relative cost, so it would be possible to do this with an algorithm.
165.1810 +       */
165.1811 +      for (i = 0; i < PNG_FILTER_VALUE_LAST; i++) if (filter_costs[i] >= 1.0)
165.1812        {
165.1813           png_ptr->inv_filter_costs[i] =
165.1814 -         png_ptr->filter_costs[i] = PNG_COST_FACTOR;
165.1815 -      }
165.1816 -      else if (filter_costs[i] >= 1.0)
165.1817 -      {
165.1818 -         png_ptr->inv_filter_costs[i] =
165.1819 -            (png_uint_16)((double)PNG_COST_FACTOR / filter_costs[i] + 0.5);
165.1820 +             (png_uint_16)(PNG_COST_FACTOR / filter_costs[i] + .5);
165.1821 +
165.1822           png_ptr->filter_costs[i] =
165.1823 -            (png_uint_16)((double)PNG_COST_FACTOR * filter_costs[i] + 0.5);
165.1824 +             (png_uint_16)(PNG_COST_FACTOR * filter_costs[i] + .5);
165.1825        }
165.1826     }
165.1827  }
165.1828 +#endif /* FLOATING_POINT */
165.1829 +
165.1830 +#ifdef PNG_FIXED_POINT_SUPPORTED
165.1831 +void PNGAPI
165.1832 +png_set_filter_heuristics_fixed(png_structp png_ptr, int heuristic_method,
165.1833 +    int num_weights, png_const_fixed_point_p filter_weights,
165.1834 +    png_const_fixed_point_p filter_costs)
165.1835 +{
165.1836 +   png_debug(1, "in png_set_filter_heuristics_fixed");
165.1837 +
165.1838 +   /* The internal API allocates all the arrays and ensures that the elements of
165.1839 +    * those arrays are set to the default value.
165.1840 +    */
165.1841 +   if (!png_init_filter_heuristics(png_ptr, heuristic_method, num_weights))
165.1842 +      return;
165.1843 +
165.1844 +   /* If using the weighted method copy in the weights. */
165.1845 +   if (heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
165.1846 +   {
165.1847 +      int i;
165.1848 +      for (i = 0; i < num_weights; i++)
165.1849 +      {
165.1850 +         if (filter_weights[i] <= 0)
165.1851 +         {
165.1852 +            png_ptr->inv_filter_weights[i] =
165.1853 +            png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
165.1854 +         }
165.1855 +
165.1856 +         else
165.1857 +         {
165.1858 +            png_ptr->inv_filter_weights[i] = (png_uint_16)
165.1859 +               ((PNG_WEIGHT_FACTOR*filter_weights[i]+PNG_FP_HALF)/PNG_FP_1);
165.1860 +
165.1861 +            png_ptr->filter_weights[i] = (png_uint_16)((PNG_WEIGHT_FACTOR*
165.1862 +               PNG_FP_1+(filter_weights[i]/2))/filter_weights[i]);
165.1863 +         }
165.1864 +      }
165.1865 +
165.1866 +      /* Here is where we set the relative costs of the different filters.  We
165.1867 +       * should take the desired compression level into account when setting
165.1868 +       * the costs, so that Paeth, for instance, has a high relative cost at low
165.1869 +       * compression levels, while it has a lower relative cost at higher
165.1870 +       * compression settings.  The filter types are in order of increasing
165.1871 +       * relative cost, so it would be possible to do this with an algorithm.
165.1872 +       */
165.1873 +      for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
165.1874 +         if (filter_costs[i] >= PNG_FP_1)
165.1875 +      {
165.1876 +         png_uint_32 tmp;
165.1877 +
165.1878 +         /* Use a 32 bit unsigned temporary here because otherwise the
165.1879 +          * intermediate value will be a 32 bit *signed* integer (ANSI rules)
165.1880 +          * and this will get the wrong answer on division.
165.1881 +          */
165.1882 +         tmp = PNG_COST_FACTOR*PNG_FP_1 + (filter_costs[i]/2);
165.1883 +         tmp /= filter_costs[i];
165.1884 +
165.1885 +         png_ptr->inv_filter_costs[i] = (png_uint_16)tmp;
165.1886 +
165.1887 +         tmp = PNG_COST_FACTOR * filter_costs[i] + PNG_FP_HALF;
165.1888 +         tmp /= PNG_FP_1;
165.1889 +
165.1890 +         png_ptr->filter_costs[i] = (png_uint_16)tmp;
165.1891 +      }
165.1892 +   }
165.1893 +}
165.1894 +#endif /* FIXED_POINT */
165.1895  #endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
165.1896  
165.1897  void PNGAPI
165.1898  png_set_compression_level(png_structp png_ptr, int level)
165.1899  {
165.1900 -   png_debug(1, "in png_set_compression_level\n");
165.1901 +   png_debug(1, "in png_set_compression_level");
165.1902 +
165.1903     if (png_ptr == NULL)
165.1904        return;
165.1905 +
165.1906     png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_LEVEL;
165.1907     png_ptr->zlib_level = level;
165.1908  }
165.1909 @@ -1387,9 +1422,11 @@
165.1910  void PNGAPI
165.1911  png_set_compression_mem_level(png_structp png_ptr, int mem_level)
165.1912  {
165.1913 -   png_debug(1, "in png_set_compression_mem_level\n");
165.1914 +   png_debug(1, "in png_set_compression_mem_level");
165.1915 +
165.1916     if (png_ptr == NULL)
165.1917        return;
165.1918 +
165.1919     png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL;
165.1920     png_ptr->zlib_mem_level = mem_level;
165.1921  }
165.1922 @@ -1397,29 +1434,38 @@
165.1923  void PNGAPI
165.1924  png_set_compression_strategy(png_structp png_ptr, int strategy)
165.1925  {
165.1926 -   png_debug(1, "in png_set_compression_strategy\n");
165.1927 +   png_debug(1, "in png_set_compression_strategy");
165.1928 +
165.1929     if (png_ptr == NULL)
165.1930        return;
165.1931 +
165.1932     png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_STRATEGY;
165.1933     png_ptr->zlib_strategy = strategy;
165.1934  }
165.1935  
165.1936 +/* If PNG_WRITE_OPTIMIZE_CMF_SUPPORTED is defined, libpng will use a
165.1937 + * smaller value of window_bits if it can do so safely.
165.1938 + */
165.1939  void PNGAPI
165.1940  png_set_compression_window_bits(png_structp png_ptr, int window_bits)
165.1941  {
165.1942     if (png_ptr == NULL)
165.1943        return;
165.1944 +
165.1945     if (window_bits > 15)
165.1946        png_warning(png_ptr, "Only compression windows <= 32k supported by PNG");
165.1947 +
165.1948     else if (window_bits < 8)
165.1949        png_warning(png_ptr, "Only compression windows >= 256 supported by PNG");
165.1950 +
165.1951  #ifndef WBITS_8_OK
165.1952 -   /* avoid libpng bug with 256-byte windows */
165.1953 +   /* Avoid libpng bug with 256-byte windows */
165.1954     if (window_bits == 8)
165.1955 -     {
165.1956 -       png_warning(png_ptr, "Compression window is being reset to 512");
165.1957 -       window_bits=9;
165.1958 -     }
165.1959 +      {
165.1960 +        png_warning(png_ptr, "Compression window is being reset to 512");
165.1961 +        window_bits = 9;
165.1962 +      }
165.1963 +
165.1964  #endif
165.1965     png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS;
165.1966     png_ptr->zlib_window_bits = window_bits;
165.1967 @@ -1428,119 +1474,210 @@
165.1968  void PNGAPI
165.1969  png_set_compression_method(png_structp png_ptr, int method)
165.1970  {
165.1971 -   png_debug(1, "in png_set_compression_method\n");
165.1972 +   png_debug(1, "in png_set_compression_method");
165.1973 +
165.1974     if (png_ptr == NULL)
165.1975        return;
165.1976 +
165.1977     if (method != 8)
165.1978        png_warning(png_ptr, "Only compression method 8 is supported by PNG");
165.1979 +
165.1980     png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_METHOD;
165.1981     png_ptr->zlib_method = method;
165.1982  }
165.1983  
165.1984 +/* The following were added to libpng-1.5.4 */
165.1985 +#ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED
165.1986 +void PNGAPI
165.1987 +png_set_text_compression_level(png_structp png_ptr, int level)
165.1988 +{
165.1989 +   png_debug(1, "in png_set_text_compression_level");
165.1990 +
165.1991 +   if (png_ptr == NULL)
165.1992 +      return;
165.1993 +
165.1994 +   png_ptr->flags |= PNG_FLAG_ZTXT_CUSTOM_LEVEL;
165.1995 +   png_ptr->zlib_text_level = level;
165.1996 +}
165.1997 +
165.1998 +void PNGAPI
165.1999 +png_set_text_compression_mem_level(png_structp png_ptr, int mem_level)
165.2000 +{
165.2001 +   png_debug(1, "in png_set_text_compression_mem_level");
165.2002 +
165.2003 +   if (png_ptr == NULL)
165.2004 +      return;
165.2005 +
165.2006 +   png_ptr->flags |= PNG_FLAG_ZTXT_CUSTOM_MEM_LEVEL;
165.2007 +   png_ptr->zlib_text_mem_level = mem_level;
165.2008 +}
165.2009 +
165.2010 +void PNGAPI
165.2011 +png_set_text_compression_strategy(png_structp png_ptr, int strategy)
165.2012 +{
165.2013 +   png_debug(1, "in png_set_text_compression_strategy");
165.2014 +
165.2015 +   if (png_ptr == NULL)
165.2016 +      return;
165.2017 +
165.2018 +   png_ptr->flags |= PNG_FLAG_ZTXT_CUSTOM_STRATEGY;
165.2019 +   png_ptr->zlib_text_strategy = strategy;
165.2020 +}
165.2021 +
165.2022 +/* If PNG_WRITE_OPTIMIZE_CMF_SUPPORTED is defined, libpng will use a
165.2023 + * smaller value of window_bits if it can do so safely.
165.2024 + */
165.2025 +void PNGAPI
165.2026 +png_set_text_compression_window_bits(png_structp png_ptr, int window_bits)
165.2027 +{
165.2028 +   if (png_ptr == NULL)
165.2029 +      return;
165.2030 +
165.2031 +   if (window_bits > 15)
165.2032 +      png_warning(png_ptr, "Only compression windows <= 32k supported by PNG");
165.2033 +
165.2034 +   else if (window_bits < 8)
165.2035 +      png_warning(png_ptr, "Only compression windows >= 256 supported by PNG");
165.2036 +
165.2037 +#ifndef WBITS_8_OK
165.2038 +   /* Avoid libpng bug with 256-byte windows */
165.2039 +   if (window_bits == 8)
165.2040 +      {
165.2041 +        png_warning(png_ptr, "Text compression window is being reset to 512");
165.2042 +        window_bits = 9;
165.2043 +      }
165.2044 +
165.2045 +#endif
165.2046 +   png_ptr->flags |= PNG_FLAG_ZTXT_CUSTOM_WINDOW_BITS;
165.2047 +   png_ptr->zlib_text_window_bits = window_bits;
165.2048 +}
165.2049 +
165.2050 +void PNGAPI
165.2051 +png_set_text_compression_method(png_structp png_ptr, int method)
165.2052 +{
165.2053 +   png_debug(1, "in png_set_text_compression_method");
165.2054 +
165.2055 +   if (png_ptr == NULL)
165.2056 +      return;
165.2057 +
165.2058 +   if (method != 8)
165.2059 +      png_warning(png_ptr, "Only compression method 8 is supported by PNG");
165.2060 +
165.2061 +   png_ptr->flags |= PNG_FLAG_ZTXT_CUSTOM_METHOD;
165.2062 +   png_ptr->zlib_text_method = method;
165.2063 +}
165.2064 +#endif /* PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED */
165.2065 +/* end of API added to libpng-1.5.4 */
165.2066 +
165.2067  void PNGAPI
165.2068  png_set_write_status_fn(png_structp png_ptr, png_write_status_ptr write_row_fn)
165.2069  {
165.2070     if (png_ptr == NULL)
165.2071        return;
165.2072 +
165.2073     png_ptr->write_row_fn = write_row_fn;
165.2074  }
165.2075  
165.2076 -#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
165.2077 +#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
165.2078  void PNGAPI
165.2079  png_set_write_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
165.2080 -   write_user_transform_fn)
165.2081 +    write_user_transform_fn)
165.2082  {
165.2083 -   png_debug(1, "in png_set_write_user_transform_fn\n");
165.2084 +   png_debug(1, "in png_set_write_user_transform_fn");
165.2085 +
165.2086     if (png_ptr == NULL)
165.2087        return;
165.2088 +
165.2089     png_ptr->transformations |= PNG_USER_TRANSFORM;
165.2090     png_ptr->write_user_transform_fn = write_user_transform_fn;
165.2091  }
165.2092  #endif
165.2093  
165.2094  
165.2095 -#if defined(PNG_INFO_IMAGE_SUPPORTED)
165.2096 +#ifdef PNG_INFO_IMAGE_SUPPORTED
165.2097  void PNGAPI
165.2098  png_write_png(png_structp png_ptr, png_infop info_ptr,
165.2099 -              int transforms, voidp params)
165.2100 +    int transforms, voidp params)
165.2101  {
165.2102     if (png_ptr == NULL || info_ptr == NULL)
165.2103        return;
165.2104 -#if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
165.2105 -   /* invert the alpha channel from opacity to transparency */
165.2106 -   if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
165.2107 -       png_set_invert_alpha(png_ptr);
165.2108 -#endif
165.2109  
165.2110     /* Write the file header information. */
165.2111     png_write_info(png_ptr, info_ptr);
165.2112  
165.2113     /* ------ these transformations don't touch the info structure ------- */
165.2114  
165.2115 -#if defined(PNG_WRITE_INVERT_SUPPORTED)
165.2116 -   /* invert monochrome pixels */
165.2117 +#ifdef PNG_WRITE_INVERT_SUPPORTED
165.2118 +   /* Invert monochrome pixels */
165.2119     if (transforms & PNG_TRANSFORM_INVERT_MONO)
165.2120 -       png_set_invert_mono(png_ptr);
165.2121 +      png_set_invert_mono(png_ptr);
165.2122  #endif
165.2123  
165.2124 -#if defined(PNG_WRITE_SHIFT_SUPPORTED)
165.2125 +#ifdef PNG_WRITE_SHIFT_SUPPORTED
165.2126     /* Shift the pixels up to a legal bit depth and fill in
165.2127      * as appropriate to correctly scale the image.
165.2128      */
165.2129     if ((transforms & PNG_TRANSFORM_SHIFT)
165.2130 -               && (info_ptr->valid & PNG_INFO_sBIT))
165.2131 -       png_set_shift(png_ptr, &info_ptr->sig_bit);
165.2132 +       && (info_ptr->valid & PNG_INFO_sBIT))
165.2133 +      png_set_shift(png_ptr, &info_ptr->sig_bit);
165.2134  #endif
165.2135  
165.2136 -#if defined(PNG_WRITE_PACK_SUPPORTED)
165.2137 -   /* pack pixels into bytes */
165.2138 +#ifdef PNG_WRITE_PACK_SUPPORTED
165.2139 +   /* Pack pixels into bytes */
165.2140     if (transforms & PNG_TRANSFORM_PACKING)
165.2141         png_set_packing(png_ptr);
165.2142  #endif
165.2143  
165.2144 -#if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
165.2145 -   /* swap location of alpha bytes from ARGB to RGBA */
165.2146 +#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED
165.2147 +   /* Swap location of alpha bytes from ARGB to RGBA */
165.2148     if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
165.2149 -       png_set_swap_alpha(png_ptr);
165.2150 +      png_set_swap_alpha(png_ptr);
165.2151  #endif
165.2152  
165.2153 -#if defined(PNG_WRITE_FILLER_SUPPORTED)
165.2154 -   /* Get rid of filler (OR ALPHA) bytes, pack XRGB/RGBX/ARGB/RGBA into
165.2155 -    * RGB (4 channels -> 3 channels). The second parameter is not used.
165.2156 -    */
165.2157 -   if (transforms & PNG_TRANSFORM_STRIP_FILLER)
165.2158 -       png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
165.2159 +#ifdef PNG_WRITE_FILLER_SUPPORTED
165.2160 +   /* Pack XRGB/RGBX/ARGB/RGBA into RGB (4 channels -> 3 channels) */
165.2161 +   if (transforms & PNG_TRANSFORM_STRIP_FILLER_AFTER)
165.2162 +      png_set_filler(png_ptr, 0, PNG_FILLER_AFTER);
165.2163 +
165.2164 +   else if (transforms & PNG_TRANSFORM_STRIP_FILLER_BEFORE)
165.2165 +      png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
165.2166  #endif
165.2167  
165.2168 -#if defined(PNG_WRITE_BGR_SUPPORTED)
165.2169 -   /* flip BGR pixels to RGB */
165.2170 +#ifdef PNG_WRITE_BGR_SUPPORTED
165.2171 +   /* Flip BGR pixels to RGB */
165.2172     if (transforms & PNG_TRANSFORM_BGR)
165.2173 -       png_set_bgr(png_ptr);
165.2174 +      png_set_bgr(png_ptr);
165.2175  #endif
165.2176  
165.2177 -#if defined(PNG_WRITE_SWAP_SUPPORTED)
165.2178 -   /* swap bytes of 16-bit files to most significant byte first */
165.2179 +#ifdef PNG_WRITE_SWAP_SUPPORTED
165.2180 +   /* Swap bytes of 16-bit files to most significant byte first */
165.2181     if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
165.2182 -       png_set_swap(png_ptr);
165.2183 +      png_set_swap(png_ptr);
165.2184  #endif
165.2185  
165.2186 -#if defined(PNG_WRITE_PACKSWAP_SUPPORTED)
165.2187 -   /* swap bits of 1, 2, 4 bit packed pixel formats */
165.2188 +#ifdef PNG_WRITE_PACKSWAP_SUPPORTED
165.2189 +   /* Swap bits of 1, 2, 4 bit packed pixel formats */
165.2190     if (transforms & PNG_TRANSFORM_PACKSWAP)
165.2191 -       png_set_packswap(png_ptr);
165.2192 +      png_set_packswap(png_ptr);
165.2193 +#endif
165.2194 +
165.2195 +#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED
165.2196 +   /* Invert the alpha channel from opacity to transparency */
165.2197 +   if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
165.2198 +      png_set_invert_alpha(png_ptr);
165.2199  #endif
165.2200  
165.2201     /* ----------------------- end of transformations ------------------- */
165.2202  
165.2203 -   /* write the bits */
165.2204 +   /* Write the bits */
165.2205     if (info_ptr->valid & PNG_INFO_IDAT)
165.2206         png_write_image(png_ptr, info_ptr->row_pointers);
165.2207  
165.2208     /* It is REQUIRED to call this to finish writing the rest of the file */
165.2209     png_write_end(png_ptr, info_ptr);
165.2210  
165.2211 -   if(transforms == 0 || params == NULL)
165.2212 -      /* quiet compiler warnings */ return;
165.2213 +   PNG_UNUSED(transforms)   /* Quiet compiler warnings */
165.2214 +   PNG_UNUSED(params)
165.2215  }
165.2216  #endif
165.2217  #endif /* PNG_WRITE_SUPPORTED */
   166.1 --- a/src/share/native/sun/awt/libpng/pngwtran.c	Fri Sep 30 17:20:56 2011 -0700
   166.2 +++ b/src/share/native/sun/awt/libpng/pngwtran.c	Tue Oct 04 12:39:42 2011 -0700
   166.3 @@ -29,84 +29,98 @@
   166.4   * However, the following notice accompanied the original version of this
   166.5   * file and, per its terms, should not be removed:
   166.6   *
   166.7 - * Last changed in libpng 1.2.9 April 14, 2006
   166.8 - * For conditions of distribution and use, see copyright notice in png.h
   166.9 - * Copyright (c) 1998-2006 Glenn Randers-Pehrson
  166.10 + * Last changed in libpng 1.5.4 [July 7, 2011]
  166.11 + * Copyright (c) 1998-2011 Glenn Randers-Pehrson
  166.12   * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
  166.13   * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
  166.14 + *
  166.15 + * This code is released under the libpng license.
  166.16 + * For conditions of distribution and use, see the disclaimer
  166.17 + * and license in png.h
  166.18   */
  166.19  
  166.20 -#define PNG_INTERNAL
  166.21 -#include "png.h"
  166.22 +#include "pngpriv.h"
  166.23 +
  166.24  #ifdef PNG_WRITE_SUPPORTED
  166.25  
  166.26 +#ifdef PNG_WRITE_TRANSFORMS_SUPPORTED
  166.27  /* Transform the data according to the user's wishes.  The order of
  166.28   * transformations is significant.
  166.29   */
  166.30  void /* PRIVATE */
  166.31  png_do_write_transformations(png_structp png_ptr)
  166.32  {
  166.33 -   png_debug(1, "in png_do_write_transformations\n");
  166.34 +   png_debug(1, "in png_do_write_transformations");
  166.35  
  166.36     if (png_ptr == NULL)
  166.37        return;
  166.38  
  166.39 -#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  166.40 +#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
  166.41     if (png_ptr->transformations & PNG_USER_TRANSFORM)
  166.42 -      if(png_ptr->write_user_transform_fn != NULL)
  166.43 -        (*(png_ptr->write_user_transform_fn)) /* user write transform function */
  166.44 -          (png_ptr,                    /* png_ptr */
  166.45 -           &(png_ptr->row_info),       /* row_info:     */
  166.46 -             /*  png_uint_32 width;          width of row */
  166.47 -             /*  png_uint_32 rowbytes;       number of bytes in row */
  166.48 -             /*  png_byte color_type;        color type of pixels */
  166.49 -             /*  png_byte bit_depth;         bit depth of samples */
  166.50 -             /*  png_byte channels;          number of channels (1-4) */
  166.51 -             /*  png_byte pixel_depth;       bits per pixel (depth*channels) */
  166.52 -           png_ptr->row_buf + 1);      /* start of pixel data for row */
  166.53 +      if (png_ptr->write_user_transform_fn != NULL)
  166.54 +         (*(png_ptr->write_user_transform_fn)) /* User write transform
  166.55 +                                                 function */
  166.56 +             (png_ptr,                    /* png_ptr */
  166.57 +             &(png_ptr->row_info),           /* row_info: */
  166.58 +                /*  png_uint_32 width;       width of row */
  166.59 +                /*  png_size_t rowbytes;     number of bytes in row */
  166.60 +                /*  png_byte color_type;     color type of pixels */
  166.61 +                /*  png_byte bit_depth;      bit depth of samples */
  166.62 +                /*  png_byte channels;       number of channels (1-4) */
  166.63 +                /*  png_byte pixel_depth;    bits per pixel (depth*channels) */
  166.64 +             png_ptr->row_buf + 1);      /* start of pixel data for row */
  166.65  #endif
  166.66 -#if defined(PNG_WRITE_FILLER_SUPPORTED)
  166.67 +
  166.68 +#ifdef PNG_WRITE_FILLER_SUPPORTED
  166.69     if (png_ptr->transformations & PNG_FILLER)
  166.70 -      png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  166.71 -         png_ptr->flags);
  166.72 +      png_do_strip_channel(&(png_ptr->row_info), png_ptr->row_buf + 1,
  166.73 +         !(png_ptr->flags & PNG_FLAG_FILLER_AFTER));
  166.74  #endif
  166.75 -#if defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  166.76 +
  166.77 +#ifdef PNG_WRITE_PACKSWAP_SUPPORTED
  166.78     if (png_ptr->transformations & PNG_PACKSWAP)
  166.79        png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  166.80  #endif
  166.81 -#if defined(PNG_WRITE_PACK_SUPPORTED)
  166.82 +
  166.83 +#ifdef PNG_WRITE_PACK_SUPPORTED
  166.84     if (png_ptr->transformations & PNG_PACK)
  166.85        png_do_pack(&(png_ptr->row_info), png_ptr->row_buf + 1,
  166.86 -         (png_uint_32)png_ptr->bit_depth);
  166.87 +          (png_uint_32)png_ptr->bit_depth);
  166.88  #endif
  166.89 -#if defined(PNG_WRITE_SWAP_SUPPORTED)
  166.90 +
  166.91 +#ifdef PNG_WRITE_SWAP_SUPPORTED
  166.92     if (png_ptr->transformations & PNG_SWAP_BYTES)
  166.93        png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  166.94  #endif
  166.95 -#if defined(PNG_WRITE_SHIFT_SUPPORTED)
  166.96 +
  166.97 +#ifdef PNG_WRITE_SHIFT_SUPPORTED
  166.98     if (png_ptr->transformations & PNG_SHIFT)
  166.99        png_do_shift(&(png_ptr->row_info), png_ptr->row_buf + 1,
 166.100 -         &(png_ptr->shift));
 166.101 +          &(png_ptr->shift));
 166.102  #endif
 166.103 -#if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
 166.104 +
 166.105 +#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED
 166.106     if (png_ptr->transformations & PNG_SWAP_ALPHA)
 166.107        png_do_write_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
 166.108  #endif
 166.109 -#if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
 166.110 +
 166.111 +#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED
 166.112     if (png_ptr->transformations & PNG_INVERT_ALPHA)
 166.113        png_do_write_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
 166.114  #endif
 166.115 -#if defined(PNG_WRITE_BGR_SUPPORTED)
 166.116 +
 166.117 +#ifdef PNG_WRITE_BGR_SUPPORTED
 166.118     if (png_ptr->transformations & PNG_BGR)
 166.119        png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
 166.120  #endif
 166.121 -#if defined(PNG_WRITE_INVERT_SUPPORTED)
 166.122 +
 166.123 +#ifdef PNG_WRITE_INVERT_SUPPORTED
 166.124     if (png_ptr->transformations & PNG_INVERT_MONO)
 166.125        png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1);
 166.126  #endif
 166.127  }
 166.128  
 166.129 -#if defined(PNG_WRITE_PACK_SUPPORTED)
 166.130 +#ifdef PNG_WRITE_PACK_SUPPORTED
 166.131  /* Pack pixels into bytes.  Pass the true bit depth in bit_depth.  The
 166.132   * row_info bit depth should be 8 (one pixel per byte).  The channels
 166.133   * should be 1 (this only happens on grayscale and paletted images).
 166.134 @@ -114,11 +128,9 @@
 166.135  void /* PRIVATE */
 166.136  png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth)
 166.137  {
 166.138 -   png_debug(1, "in png_do_pack\n");
 166.139 +   png_debug(1, "in png_do_pack");
 166.140 +
 166.141     if (row_info->bit_depth == 8 &&
 166.142 -#if defined(PNG_USELESS_TESTS_SUPPORTED)
 166.143 -       row != NULL && row_info != NULL &&
 166.144 -#endif
 166.145        row_info->channels == 1)
 166.146     {
 166.147        switch ((int)bit_depth)
 166.148 @@ -139,9 +151,12 @@
 166.149              {
 166.150                 if (*sp != 0)
 166.151                    v |= mask;
 166.152 +
 166.153                 sp++;
 166.154 +
 166.155                 if (mask > 1)
 166.156                    mask >>= 1;
 166.157 +
 166.158                 else
 166.159                 {
 166.160                    mask = 0x80;
 166.161 @@ -150,10 +165,13 @@
 166.162                    v = 0;
 166.163                 }
 166.164              }
 166.165 +
 166.166              if (mask != 0x80)
 166.167                 *dp = (png_byte)v;
 166.168 +
 166.169              break;
 166.170           }
 166.171 +
 166.172           case 2:
 166.173           {
 166.174              png_bytep sp, dp;
 166.175 @@ -165,12 +183,14 @@
 166.176              dp = row;
 166.177              shift = 6;
 166.178              v = 0;
 166.179 +
 166.180              for (i = 0; i < row_width; i++)
 166.181              {
 166.182                 png_byte value;
 166.183  
 166.184                 value = (png_byte)(*sp & 0x03);
 166.185                 v |= (value << shift);
 166.186 +
 166.187                 if (shift == 0)
 166.188                 {
 166.189                    shift = 6;
 166.190 @@ -178,14 +198,19 @@
 166.191                    dp++;
 166.192                    v = 0;
 166.193                 }
 166.194 +
 166.195                 else
 166.196                    shift -= 2;
 166.197 +
 166.198                 sp++;
 166.199              }
 166.200 +
 166.201              if (shift != 6)
 166.202                 *dp = (png_byte)v;
 166.203 +
 166.204              break;
 166.205           }
 166.206 +
 166.207           case 4:
 166.208           {
 166.209              png_bytep sp, dp;
 166.210 @@ -197,6 +222,7 @@
 166.211              dp = row;
 166.212              shift = 4;
 166.213              v = 0;
 166.214 +
 166.215              for (i = 0; i < row_width; i++)
 166.216              {
 166.217                 png_byte value;
 166.218 @@ -211,25 +237,32 @@
 166.219                    dp++;
 166.220                    v = 0;
 166.221                 }
 166.222 +
 166.223                 else
 166.224                    shift -= 4;
 166.225  
 166.226                 sp++;
 166.227              }
 166.228 +
 166.229              if (shift != 4)
 166.230                 *dp = (png_byte)v;
 166.231 +
 166.232              break;
 166.233           }
 166.234 +
 166.235 +         default:
 166.236 +            break;
 166.237        }
 166.238 +
 166.239        row_info->bit_depth = (png_byte)bit_depth;
 166.240        row_info->pixel_depth = (png_byte)(bit_depth * row_info->channels);
 166.241        row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
 166.242 -         row_info->width);
 166.243 +          row_info->width);
 166.244     }
 166.245  }
 166.246  #endif
 166.247  
 166.248 -#if defined(PNG_WRITE_SHIFT_SUPPORTED)
 166.249 +#ifdef PNG_WRITE_SHIFT_SUPPORTED
 166.250  /* Shift pixel values to take advantage of whole range.  Pass the
 166.251   * true number of bits in bit_depth.  The row should be packed
 166.252   * according to row_info->bit_depth.  Thus, if you had a row of
 166.253 @@ -238,15 +271,12 @@
 166.254   * data to 0 to 15.
 166.255   */
 166.256  void /* PRIVATE */
 166.257 -png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
 166.258 +png_do_shift(png_row_infop row_info, png_bytep row,
 166.259 +    png_const_color_8p bit_depth)
 166.260  {
 166.261 -   png_debug(1, "in png_do_shift\n");
 166.262 -#if defined(PNG_USELESS_TESTS_SUPPORTED)
 166.263 -   if (row != NULL && row_info != NULL &&
 166.264 -#else
 166.265 -   if (
 166.266 -#endif
 166.267 -      row_info->color_type != PNG_COLOR_TYPE_PALETTE)
 166.268 +   png_debug(1, "in png_do_shift");
 166.269 +
 166.270 +   if (row_info->color_type != PNG_COLOR_TYPE_PALETTE)
 166.271     {
 166.272        int shift_start[4], shift_dec[4];
 166.273        int channels = 0;
 166.274 @@ -256,19 +286,23 @@
 166.275           shift_start[channels] = row_info->bit_depth - bit_depth->red;
 166.276           shift_dec[channels] = bit_depth->red;
 166.277           channels++;
 166.278 +
 166.279           shift_start[channels] = row_info->bit_depth - bit_depth->green;
 166.280           shift_dec[channels] = bit_depth->green;
 166.281           channels++;
 166.282 +
 166.283           shift_start[channels] = row_info->bit_depth - bit_depth->blue;
 166.284           shift_dec[channels] = bit_depth->blue;
 166.285           channels++;
 166.286        }
 166.287 +
 166.288        else
 166.289        {
 166.290           shift_start[channels] = row_info->bit_depth - bit_depth->gray;
 166.291           shift_dec[channels] = bit_depth->gray;
 166.292           channels++;
 166.293        }
 166.294 +
 166.295        if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
 166.296        {
 166.297           shift_start[channels] = row_info->bit_depth - bit_depth->alpha;
 166.298 @@ -276,18 +310,20 @@
 166.299           channels++;
 166.300        }
 166.301  
 166.302 -      /* with low row depths, could only be grayscale, so one channel */
 166.303 +      /* With low row depths, could only be grayscale, so one channel */
 166.304        if (row_info->bit_depth < 8)
 166.305        {
 166.306           png_bytep bp = row;
 166.307 -         png_uint_32 i;
 166.308 +         png_size_t i;
 166.309           png_byte mask;
 166.310 -         png_uint_32 row_bytes = row_info->rowbytes;
 166.311 +         png_size_t row_bytes = row_info->rowbytes;
 166.312  
 166.313           if (bit_depth->gray == 1 && row_info->bit_depth == 2)
 166.314              mask = 0x55;
 166.315 +
 166.316           else if (row_info->bit_depth == 4 && bit_depth->gray == 3)
 166.317              mask = 0x11;
 166.318 +
 166.319           else
 166.320              mask = 0xff;
 166.321  
 166.322 @@ -298,15 +334,18 @@
 166.323  
 166.324              v = *bp;
 166.325              *bp = 0;
 166.326 +
 166.327              for (j = shift_start[0]; j > -shift_dec[0]; j -= shift_dec[0])
 166.328              {
 166.329                 if (j > 0)
 166.330                    *bp |= (png_byte)((v << j) & 0xff);
 166.331 +
 166.332                 else
 166.333                    *bp |= (png_byte)((v >> (-j)) & mask);
 166.334              }
 166.335           }
 166.336        }
 166.337 +
 166.338        else if (row_info->bit_depth == 8)
 166.339        {
 166.340           png_bytep bp = row;
 166.341 @@ -322,15 +361,18 @@
 166.342  
 166.343              v = *bp;
 166.344              *bp = 0;
 166.345 +
 166.346              for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
 166.347              {
 166.348                 if (j > 0)
 166.349                    *bp |= (png_byte)((v << j) & 0xff);
 166.350 +
 166.351                 else
 166.352                    *bp |= (png_byte)((v >> (-j)) & 0xff);
 166.353              }
 166.354           }
 166.355        }
 166.356 +
 166.357        else
 166.358        {
 166.359           png_bytep bp;
 166.360 @@ -345,10 +387,12 @@
 166.361  
 166.362              v = (png_uint_16)(((png_uint_16)(*bp) << 8) + *(bp + 1));
 166.363              value = 0;
 166.364 +
 166.365              for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
 166.366              {
 166.367                 if (j > 0)
 166.368                    value |= (png_uint_16)((v << j) & (png_uint_16)0xffff);
 166.369 +
 166.370                 else
 166.371                    value |= (png_uint_16)((v >> (-j)) & (png_uint_16)0xffff);
 166.372              }
 166.373 @@ -360,23 +404,22 @@
 166.374  }
 166.375  #endif
 166.376  
 166.377 -#if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
 166.378 +#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED
 166.379  void /* PRIVATE */
 166.380  png_do_write_swap_alpha(png_row_infop row_info, png_bytep row)
 166.381  {
 166.382 -   png_debug(1, "in png_do_write_swap_alpha\n");
 166.383 -#if defined(PNG_USELESS_TESTS_SUPPORTED)
 166.384 -   if (row != NULL && row_info != NULL)
 166.385 -#endif
 166.386 +   png_debug(1, "in png_do_write_swap_alpha");
 166.387 +
 166.388     {
 166.389        if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
 166.390        {
 166.391 -         /* This converts from ARGB to RGBA */
 166.392           if (row_info->bit_depth == 8)
 166.393           {
 166.394 +            /* This converts from ARGB to RGBA */
 166.395              png_bytep sp, dp;
 166.396              png_uint_32 i;
 166.397              png_uint_32 row_width = row_info->width;
 166.398 +
 166.399              for (i = 0, sp = dp = row; i < row_width; i++)
 166.400              {
 166.401                 png_byte save = *(sp++);
 166.402 @@ -386,9 +429,11 @@
 166.403                 *(dp++) = save;
 166.404              }
 166.405           }
 166.406 -         /* This converts from AARRGGBB to RRGGBBAA */
 166.407 +
 166.408 +#ifdef PNG_WRITE_16BIT_SUPPORTED
 166.409           else
 166.410           {
 166.411 +            /* This converts from AARRGGBB to RRGGBBAA */
 166.412              png_bytep sp, dp;
 166.413              png_uint_32 i;
 166.414              png_uint_32 row_width = row_info->width;
 166.415 @@ -408,12 +453,14 @@
 166.416                 *(dp++) = save[1];
 166.417              }
 166.418           }
 166.419 +#endif /* PNG_WRITE_16BIT_SUPPORTED */
 166.420        }
 166.421 +
 166.422        else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
 166.423        {
 166.424 -         /* This converts from AG to GA */
 166.425           if (row_info->bit_depth == 8)
 166.426           {
 166.427 +            /* This converts from AG to GA */
 166.428              png_bytep sp, dp;
 166.429              png_uint_32 i;
 166.430              png_uint_32 row_width = row_info->width;
 166.431 @@ -425,9 +472,11 @@
 166.432                 *(dp++) = save;
 166.433              }
 166.434           }
 166.435 -         /* This converts from AAGG to GGAA */
 166.436 +
 166.437 +#ifdef PNG_WRITE_16BIT_SUPPORTED
 166.438           else
 166.439           {
 166.440 +            /* This converts from AAGG to GGAA */
 166.441              png_bytep sp, dp;
 166.442              png_uint_32 i;
 166.443              png_uint_32 row_width = row_info->width;
 166.444 @@ -443,31 +492,31 @@
 166.445                 *(dp++) = save[1];
 166.446              }
 166.447           }
 166.448 +#endif /* PNG_WRITE_16BIT_SUPPORTED */
 166.449        }
 166.450     }
 166.451  }
 166.452  #endif
 166.453  
 166.454 -#if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
 166.455 +#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED
 166.456  void /* PRIVATE */
 166.457  png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
 166.458  {
 166.459 -   png_debug(1, "in png_do_write_invert_alpha\n");
 166.460 -#if defined(PNG_USELESS_TESTS_SUPPORTED)
 166.461 -   if (row != NULL && row_info != NULL)
 166.462 -#endif
 166.463 +   png_debug(1, "in png_do_write_invert_alpha");
 166.464 +
 166.465     {
 166.466        if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
 166.467        {
 166.468 -         /* This inverts the alpha channel in RGBA */
 166.469           if (row_info->bit_depth == 8)
 166.470           {
 166.471 +            /* This inverts the alpha channel in RGBA */
 166.472              png_bytep sp, dp;
 166.473              png_uint_32 i;
 166.474              png_uint_32 row_width = row_info->width;
 166.475 +
 166.476              for (i = 0, sp = dp = row; i < row_width; i++)
 166.477              {
 166.478 -               /* does nothing
 166.479 +               /* Does nothing
 166.480                 *(dp++) = *(sp++);
 166.481                 *(dp++) = *(sp++);
 166.482                 *(dp++) = *(sp++);
 166.483 @@ -476,16 +525,18 @@
 166.484                 *(dp++) = (png_byte)(255 - *(sp++));
 166.485              }
 166.486           }
 166.487 -         /* This inverts the alpha channel in RRGGBBAA */
 166.488 +
 166.489 +#ifdef PNG_WRITE_16BIT_SUPPORTED
 166.490           else
 166.491           {
 166.492 +            /* This inverts the alpha channel in RRGGBBAA */
 166.493              png_bytep sp, dp;
 166.494              png_uint_32 i;
 166.495              png_uint_32 row_width = row_info->width;
 166.496  
 166.497              for (i = 0, sp = dp = row; i < row_width; i++)
 166.498              {
 166.499 -               /* does nothing
 166.500 +               /* Does nothing
 166.501                 *(dp++) = *(sp++);
 166.502                 *(dp++) = *(sp++);
 166.503                 *(dp++) = *(sp++);
 166.504 @@ -498,12 +549,14 @@
 166.505                 *(dp++) = (png_byte)(255 - *(sp++));
 166.506              }
 166.507           }
 166.508 +#endif /* PNG_WRITE_16BIT_SUPPORTED */
 166.509        }
 166.510 +
 166.511        else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
 166.512        {
 166.513 -         /* This inverts the alpha channel in GA */
 166.514           if (row_info->bit_depth == 8)
 166.515           {
 166.516 +            /* This inverts the alpha channel in GA */
 166.517              png_bytep sp, dp;
 166.518              png_uint_32 i;
 166.519              png_uint_32 row_width = row_info->width;
 166.520 @@ -514,16 +567,18 @@
 166.521                 *(dp++) = (png_byte)(255 - *(sp++));
 166.522              }
 166.523           }
 166.524 -         /* This inverts the alpha channel in GGAA */
 166.525 +
 166.526 +#ifdef PNG_WRITE_16BIT_SUPPORTED
 166.527           else
 166.528           {
 166.529 +            /* This inverts the alpha channel in GGAA */
 166.530              png_bytep sp, dp;
 166.531              png_uint_32 i;
 166.532              png_uint_32 row_width = row_info->width;
 166.533  
 166.534              for (i = 0, sp = dp = row; i < row_width; i++)
 166.535              {
 166.536 -               /* does nothing
 166.537 +               /* Does nothing
 166.538                 *(dp++) = *(sp++);
 166.539                 *(dp++) = *(sp++);
 166.540                 */
 166.541 @@ -532,22 +587,21 @@
 166.542                 *(dp++) = (png_byte)(255 - *(sp++));
 166.543              }
 166.544           }
 166.545 +#endif /* PNG_WRITE_16BIT_SUPPORTED */
 166.546        }
 166.547     }
 166.548  }
 166.549  #endif
 166.550 +#endif /* PNG_WRITE_TRANSFORMS_SUPPORTED */
 166.551  
 166.552 -#if defined(PNG_MNG_FEATURES_SUPPORTED)
 166.553 -/* undoes intrapixel differencing  */
 166.554 +#ifdef PNG_MNG_FEATURES_SUPPORTED
 166.555 +/* Undoes intrapixel differencing  */
 166.556  void /* PRIVATE */
 166.557  png_do_write_intrapixel(png_row_infop row_info, png_bytep row)
 166.558  {
 166.559 -   png_debug(1, "in png_do_write_intrapixel\n");
 166.560 -   if (
 166.561 -#if defined(PNG_USELESS_TESTS_SUPPORTED)
 166.562 -       row != NULL && row_info != NULL &&
 166.563 -#endif
 166.564 -       (row_info->color_type & PNG_COLOR_MASK_COLOR))
 166.565 +   png_debug(1, "in png_do_write_intrapixel");
 166.566 +
 166.567 +   if ((row_info->color_type & PNG_COLOR_MASK_COLOR))
 166.568     {
 166.569        int bytes_per_pixel;
 166.570        png_uint_32 row_width = row_info->width;
 166.571 @@ -558,17 +612,21 @@
 166.572  
 166.573           if (row_info->color_type == PNG_COLOR_TYPE_RGB)
 166.574              bytes_per_pixel = 3;
 166.575 +
 166.576           else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
 166.577              bytes_per_pixel = 4;
 166.578 +
 166.579           else
 166.580              return;
 166.581  
 166.582           for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
 166.583           {
 166.584 -            *(rp)   = (png_byte)((*rp     - *(rp+1))&0xff);
 166.585 -            *(rp+2) = (png_byte)((*(rp+2) - *(rp+1))&0xff);
 166.586 +            *(rp)     = (png_byte)((*rp       - *(rp + 1)) & 0xff);
 166.587 +            *(rp + 2) = (png_byte)((*(rp + 2) - *(rp + 1)) & 0xff);
 166.588           }
 166.589        }
 166.590 +
 166.591 +#ifdef PNG_WRITE_16BIT_SUPPORTED
 166.592        else if (row_info->bit_depth == 16)
 166.593        {
 166.594           png_bytep rp;
 166.595 @@ -576,24 +634,27 @@
 166.596  
 166.597           if (row_info->color_type == PNG_COLOR_TYPE_RGB)
 166.598              bytes_per_pixel = 6;
 166.599 +
 166.600           else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
 166.601              bytes_per_pixel = 8;
 166.602 +
 166.603           else
 166.604              return;
 166.605  
 166.606           for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
 166.607           {
 166.608 -            png_uint_32 s0   = (*(rp  ) << 8) | *(rp+1);
 166.609 -            png_uint_32 s1   = (*(rp+2) << 8) | *(rp+3);
 166.610 -            png_uint_32 s2   = (*(rp+4) << 8) | *(rp+5);
 166.611 -            png_uint_32 red  = (png_uint_32)((s0-s1) & 0xffffL);
 166.612 -            png_uint_32 blue = (png_uint_32)((s2-s1) & 0xffffL);
 166.613 -            *(rp  ) = (png_byte)((red >> 8) & 0xff);
 166.614 -            *(rp+1) = (png_byte)(red & 0xff);
 166.615 -            *(rp+4) = (png_byte)((blue >> 8) & 0xff);
 166.616 -            *(rp+5) = (png_byte)(blue & 0xff);
 166.617 +            png_uint_32 s0   = (*(rp    ) << 8) | *(rp + 1);
 166.618 +            png_uint_32 s1   = (*(rp + 2) << 8) | *(rp + 3);
 166.619 +            png_uint_32 s2   = (*(rp + 4) << 8) | *(rp + 5);
 166.620 +            png_uint_32 red  = (png_uint_32)((s0 - s1) & 0xffffL);
 166.621 +            png_uint_32 blue = (png_uint_32)((s2 - s1) & 0xffffL);
 166.622 +            *(rp    ) = (png_byte)((red >> 8) & 0xff);
 166.623 +            *(rp + 1) = (png_byte)(red & 0xff);
 166.624 +            *(rp + 4) = (png_byte)((blue >> 8) & 0xff);
 166.625 +            *(rp + 5) = (png_byte)(blue & 0xff);
 166.626           }
 166.627        }
 166.628 +#endif /* PNG_WRITE_16BIT_SUPPORTED */
 166.629     }
 166.630  }
 166.631  #endif /* PNG_MNG_FEATURES_SUPPORTED */
   167.1 --- a/src/share/native/sun/awt/libpng/pngwutil.c	Fri Sep 30 17:20:56 2011 -0700
   167.2 +++ b/src/share/native/sun/awt/libpng/pngwutil.c	Tue Oct 04 12:39:42 2011 -0700
   167.3 @@ -29,17 +29,21 @@
   167.4   * However, the following notice accompanied the original version of this
   167.5   * file and, per its terms, should not be removed:
   167.6   *
   167.7 - * Last changed in libpng 1.2.15 January 5, 2007
   167.8 - * For conditions of distribution and use, see copyright notice in png.h
   167.9 - * Copyright (c) 1998-2007 Glenn Randers-Pehrson
  167.10 + * Last changed in libpng 1.5.4 [July 7, 2011]
  167.11 + * Copyright (c) 1998-2011 Glenn Randers-Pehrson
  167.12   * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
  167.13   * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
  167.14 + *
  167.15 + * This code is released under the libpng license.
  167.16 + * For conditions of distribution and use, see the disclaimer
  167.17 + * and license in png.h
  167.18   */
  167.19  
  167.20 -#define PNG_INTERNAL
  167.21 -#include "png.h"
  167.22 +#include "pngpriv.h"
  167.23 +
  167.24  #ifdef PNG_WRITE_SUPPORTED
  167.25  
  167.26 +#ifdef PNG_WRITE_INT_FUNCTIONS_SUPPORTED
  167.27  /* Place a 32-bit number into a buffer in PNG byte order.  We work
  167.28   * with unsigned numbers for convenience, although one supported
  167.29   * ancillary chunk uses signed (two's complement) numbers.
  167.30 @@ -53,9 +57,12 @@
  167.31     buf[3] = (png_byte)(i & 0xff);
  167.32  }
  167.33  
  167.34 +#ifdef PNG_SAVE_INT_32_SUPPORTED
  167.35  /* The png_save_int_32 function assumes integers are stored in two's
  167.36   * complement format.  If this isn't the case, then this routine needs to
  167.37 - * be modified to write data in two's complement format.
  167.38 + * be modified to write data in two's complement format.  Note that,
  167.39 + * the following works correctly even if png_int_32 has more than 32 bits
  167.40 + * (compare the more complex code required on read for sign extention.)
  167.41   */
  167.42  void PNGAPI
  167.43  png_save_int_32(png_bytep buf, png_int_32 i)
  167.44 @@ -65,6 +72,7 @@
  167.45     buf[2] = (png_byte)((i >> 8) & 0xff);
  167.46     buf[3] = (png_byte)(i & 0xff);
  167.47  }
  167.48 +#endif
  167.49  
  167.50  /* Place a 16-bit number into a buffer in PNG byte order.
  167.51   * The parameter is declared unsigned int, not png_uint_16,
  167.52 @@ -76,6 +84,31 @@
  167.53     buf[0] = (png_byte)((i >> 8) & 0xff);
  167.54     buf[1] = (png_byte)(i & 0xff);
  167.55  }
  167.56 +#endif
  167.57 +
  167.58 +/* Simple function to write the signature.  If we have already written
  167.59 + * the magic bytes of the signature, or more likely, the PNG stream is
  167.60 + * being embedded into another stream and doesn't need its own signature,
  167.61 + * we should call png_set_sig_bytes() to tell libpng how many of the
  167.62 + * bytes have already been written.
  167.63 + */
  167.64 +void PNGAPI
  167.65 +png_write_sig(png_structp png_ptr)
  167.66 +{
  167.67 +   png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  167.68 +
  167.69 +#ifdef PNG_IO_STATE_SUPPORTED
  167.70 +   /* Inform the I/O callback that the signature is being written */
  167.71 +   png_ptr->io_state = PNG_IO_WRITING | PNG_IO_SIGNATURE;
  167.72 +#endif
  167.73 +
  167.74 +   /* Write the rest of the 8 byte signature */
  167.75 +   png_write_data(png_ptr, &png_signature[png_ptr->sig_bytes],
  167.76 +      (png_size_t)(8 - png_ptr->sig_bytes));
  167.77 +
  167.78 +   if (png_ptr->sig_bytes < 3)
  167.79 +      png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
  167.80 +}
  167.81  
  167.82  /* Write a PNG chunk all at once.  The type is an array of ASCII characters
  167.83   * representing the chunk name.  The array must be at least 4 bytes in
  167.84 @@ -87,12 +120,14 @@
  167.85   * functions instead.
  167.86   */
  167.87  void PNGAPI
  167.88 -png_write_chunk(png_structp png_ptr, png_bytep chunk_name,
  167.89 -   png_bytep data, png_size_t length)
  167.90 +png_write_chunk(png_structp png_ptr, png_const_bytep chunk_name,
  167.91 +   png_const_bytep data, png_size_t length)
  167.92  {
  167.93 -   if(png_ptr == NULL) return;
  167.94 +   if (png_ptr == NULL)
  167.95 +      return;
  167.96 +
  167.97     png_write_chunk_start(png_ptr, chunk_name, (png_uint_32)length);
  167.98 -   png_write_chunk_data(png_ptr, data, length);
  167.99 +   png_write_chunk_data(png_ptr, data, (png_size_t)length);
 167.100     png_write_chunk_end(png_ptr);
 167.101  }
 167.102  
 167.103 @@ -101,22 +136,43 @@
 167.104   * passing in png_write_chunk_data().
 167.105   */
 167.106  void PNGAPI
 167.107 -png_write_chunk_start(png_structp png_ptr, png_bytep chunk_name,
 167.108 -   png_uint_32 length)
 167.109 +png_write_chunk_start(png_structp png_ptr, png_const_bytep chunk_name,
 167.110 +    png_uint_32 length)
 167.111  {
 167.112 -   png_byte buf[4];
 167.113 -   png_debug2(0, "Writing %s chunk (%lu bytes)\n", chunk_name, length);
 167.114 -   if(png_ptr == NULL) return;
 167.115 -
 167.116 -   /* write the length */
 167.117 +   png_byte buf[8];
 167.118 +
 167.119 +   png_debug2(0, "Writing %s chunk, length = %lu", chunk_name,
 167.120 +      (unsigned long)length);
 167.121 +
 167.122 +   if (png_ptr == NULL)
 167.123 +      return;
 167.124 +
 167.125 +#ifdef PNG_IO_STATE_SUPPORTED
 167.126 +   /* Inform the I/O callback that the chunk header is being written.
 167.127 +    * PNG_IO_CHUNK_HDR requires a single I/O call.
 167.128 +    */
 167.129 +   png_ptr->io_state = PNG_IO_WRITING | PNG_IO_CHUNK_HDR;
 167.130 +#endif
 167.131 +
 167.132 +   /* Write the length and the chunk name */
 167.133     png_save_uint_32(buf, length);
 167.134 -   png_write_data(png_ptr, buf, (png_size_t)4);
 167.135 -
 167.136 -   /* write the chunk name */
 167.137 -   png_write_data(png_ptr, chunk_name, (png_size_t)4);
 167.138 -   /* reset the crc and run it over the chunk name */
 167.139 +   png_memcpy(buf + 4, chunk_name, 4);
 167.140 +   png_write_data(png_ptr, buf, (png_size_t)8);
 167.141 +
 167.142 +   /* Put the chunk name into png_ptr->chunk_name */
 167.143 +   png_memcpy(png_ptr->chunk_name, chunk_name, 4);
 167.144 +
 167.145 +   /* Reset the crc and run it over the chunk name */
 167.146     png_reset_crc(png_ptr);
 167.147 -   png_calculate_crc(png_ptr, chunk_name, (png_size_t)4);
 167.148 +
 167.149 +   png_calculate_crc(png_ptr, chunk_name, 4);
 167.150 +
 167.151 +#ifdef PNG_IO_STATE_SUPPORTED
 167.152 +   /* Inform the I/O callback that chunk data will (possibly) be written.
 167.153 +    * PNG_IO_CHUNK_DATA does NOT require a specific number of I/O calls.
 167.154 +    */
 167.155 +   png_ptr->io_state = PNG_IO_WRITING | PNG_IO_CHUNK_DATA;
 167.156 +#endif
 167.157  }
 167.158  
 167.159  /* Write the data of a PNG chunk started with png_write_chunk_start().
 167.160 @@ -125,14 +181,21 @@
 167.161   * given to png_write_chunk_start().
 167.162   */
 167.163  void PNGAPI
 167.164 -png_write_chunk_data(png_structp png_ptr, png_bytep data, png_size_t length)
 167.165 +png_write_chunk_data(png_structp png_ptr, png_const_bytep data,
 167.166 +    png_size_t length)
 167.167  {
 167.168 -   /* write the data, and run the CRC over it */
 167.169 -   if(png_ptr == NULL) return;
 167.170 +   /* Write the data, and run the CRC over it */
 167.171 +   if (png_ptr == NULL)
 167.172 +      return;
 167.173 +
 167.174     if (data != NULL && length > 0)
 167.175     {
 167.176 +      png_write_data(png_ptr, data, length);
 167.177 +
 167.178 +      /* Update the CRC after writing the data,
 167.179 +       * in case that the user I/O routine alters it.
 167.180 +       */
 167.181        png_calculate_crc(png_ptr, data, length);
 167.182 -      png_write_data(png_ptr, data, length);
 167.183     }
 167.184  }
 167.185  
 167.186 @@ -142,34 +205,165 @@
 167.187  {
 167.188     png_byte buf[4];
 167.189  
 167.190 -   if(png_ptr == NULL) return;
 167.191 -
 167.192 -   /* write the crc */
 167.193 +   if (png_ptr == NULL) return;
 167.194 +
 167.195 +#ifdef PNG_IO_STATE_SUPPORTED
 167.196 +   /* Inform the I/O callback that the chunk CRC is being written.
 167.197 +    * PNG_IO_CHUNK_CRC requires a single I/O function call.
 167.198 +    */
 167.199 +   png_ptr->io_state = PNG_IO_WRITING | PNG_IO_CHUNK_CRC;
 167.200 +#endif
 167.201 +
 167.202 +   /* Write the crc in a single operation */
 167.203     png_save_uint_32(buf, png_ptr->crc);
 167.204  
 167.205     png_write_data(png_ptr, buf, (png_size_t)4);
 167.206  }
 167.207  
 167.208 -/* Simple function to write the signature.  If we have already written
 167.209 - * the magic bytes of the signature, or more likely, the PNG stream is
 167.210 - * being embedded into another stream and doesn't need its own signature,
 167.211 - * we should call png_set_sig_bytes() to tell libpng how many of the
 167.212 - * bytes have already been written.
 167.213 +/* Initialize the compressor for the appropriate type of compression. */
 167.214 +static void
 167.215 +png_zlib_claim(png_structp png_ptr, png_uint_32 state)
 167.216 +{
 167.217 +   if (!(png_ptr->zlib_state & PNG_ZLIB_IN_USE))
 167.218 +   {
 167.219 +      /* If already initialized for 'state' do not re-init. */
 167.220 +      if (png_ptr->zlib_state != state)
 167.221 +      {
 167.222 +         int ret = Z_OK;
 167.223 +         png_const_charp who = "-";
 167.224 +
 167.225 +         /* If actually initialized for another state do a deflateEnd. */
 167.226 +         if (png_ptr->zlib_state != PNG_ZLIB_UNINITIALIZED)
 167.227 +         {
 167.228 +            ret = deflateEnd(&png_ptr->zstream);
 167.229 +            who = "end";
 167.230 +            png_ptr->zlib_state = PNG_ZLIB_UNINITIALIZED;
 167.231 +         }
 167.232 +
 167.233 +         /* zlib itself detects an incomplete state on deflateEnd */
 167.234 +         if (ret == Z_OK) switch (state)
 167.235 +         {
 167.236 +#           ifdef PNG_WRITE_COMPRESSED_TEXT_SUPPORTED
 167.237 +               case PNG_ZLIB_FOR_TEXT:
 167.238 +                  ret = deflateInit2(&png_ptr->zstream,
 167.239 +                     png_ptr->zlib_text_level, png_ptr->zlib_text_method,
 167.240 +                     png_ptr->zlib_text_window_bits,
 167.241 +                     png_ptr->zlib_text_mem_level, png_ptr->zlib_text_strategy);
 167.242 +                  who = "text";
 167.243 +                  break;
 167.244 +#           endif
 167.245 +
 167.246 +            case PNG_ZLIB_FOR_IDAT:
 167.247 +               ret = deflateInit2(&png_ptr->zstream, png_ptr->zlib_level,
 167.248 +                   png_ptr->zlib_method, png_ptr->zlib_window_bits,
 167.249 +                   png_ptr->zlib_mem_level, png_ptr->zlib_strategy);
 167.250 +               who = "IDAT";
 167.251 +               break;
 167.252 +
 167.253 +            default:
 167.254 +               png_error(png_ptr, "invalid zlib state");
 167.255 +         }
 167.256 +
 167.257 +         if (ret == Z_OK)
 167.258 +            png_ptr->zlib_state = state;
 167.259 +
 167.260 +         else /* an error in deflateEnd or deflateInit2 */
 167.261 +         {
 167.262 +            size_t pos = 0;
 167.263 +            char msg[64];
 167.264 +
 167.265 +            pos = png_safecat(msg, sizeof msg, pos,
 167.266 +               "zlib failed to initialize compressor (");
 167.267 +            pos = png_safecat(msg, sizeof msg, pos, who);
 167.268 +
 167.269 +            switch (ret)
 167.270 +            {
 167.271 +               case Z_VERSION_ERROR:
 167.272 +                  pos = png_safecat(msg, sizeof msg, pos, ") version error");
 167.273 +                  break;
 167.274 +
 167.275 +               case Z_STREAM_ERROR:
 167.276 +                  pos = png_safecat(msg, sizeof msg, pos, ") stream error");
 167.277 +                  break;
 167.278 +
 167.279 +               case Z_MEM_ERROR:
 167.280 +                  pos = png_safecat(msg, sizeof msg, pos, ") memory error");
 167.281 +                  break;
 167.282 +
 167.283 +               default:
 167.284 +                  pos = png_safecat(msg, sizeof msg, pos, ") unknown error");
 167.285 +                  break;
 167.286 +            }
 167.287 +
 167.288 +            png_error(png_ptr, msg);
 167.289 +         }
 167.290 +      }
 167.291 +
 167.292 +      /* Here on success, claim the zstream: */
 167.293 +      png_ptr->zlib_state |= PNG_ZLIB_IN_USE;
 167.294 +   }
 167.295 +
 167.296 +   else
 167.297 +      png_error(png_ptr, "zstream already in use (internal error)");
 167.298 +}
 167.299 +
 167.300 +/* The opposite: release the stream.  It is also reset, this API will warn on
 167.301 + * error but will not fail.
 167.302   */
 167.303 -void /* PRIVATE */
 167.304 -png_write_sig(png_structp png_ptr)
 167.305 +static void
 167.306 +png_zlib_release(png_structp png_ptr)
 167.307  {
 167.308 -   png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
 167.309 -   /* write the rest of the 8 byte signature */
 167.310 -   png_write_data(png_ptr, &png_signature[png_ptr->sig_bytes],
 167.311 -      (png_size_t)8 - png_ptr->sig_bytes);
 167.312 -   if(png_ptr->sig_bytes < 3)
 167.313 -      png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
 167.314 +   if (png_ptr->zlib_state & PNG_ZLIB_IN_USE)
 167.315 +   {
 167.316 +      int ret = deflateReset(&png_ptr->zstream);
 167.317 +
 167.318 +      png_ptr->zlib_state &= ~PNG_ZLIB_IN_USE;
 167.319 +
 167.320 +      if (ret != Z_OK)
 167.321 +      {
 167.322 +         png_const_charp err;
 167.323 +         PNG_WARNING_PARAMETERS(p)
 167.324 +
 167.325 +         switch (ret)
 167.326 +         {
 167.327 +            case Z_VERSION_ERROR:
 167.328 +               err = "version";
 167.329 +               break;
 167.330 +
 167.331 +            case Z_STREAM_ERROR:
 167.332 +               err = "stream";
 167.333 +               break;
 167.334 +
 167.335 +            case Z_MEM_ERROR:
 167.336 +               err = "memory";
 167.337 +               break;
 167.338 +
 167.339 +            default:
 167.340 +               err = "unknown";
 167.341 +               break;
 167.342 +         }
 167.343 +
 167.344 +         png_warning_parameter_signed(p, 1, PNG_NUMBER_FORMAT_d, ret);
 167.345 +         png_warning_parameter(p, 2, err);
 167.346 +
 167.347 +         if (png_ptr->zstream.msg)
 167.348 +            err = png_ptr->zstream.msg;
 167.349 +         else
 167.350 +            err = "[no zlib message]";
 167.351 +
 167.352 +         png_warning_parameter(p, 3, err);
 167.353 +
 167.354 +         png_formatted_warning(png_ptr, p,
 167.355 +            "zlib failed to reset compressor: @1(@2): @3");
 167.356 +      }
 167.357 +   }
 167.358 +
 167.359 +   else
 167.360 +      png_warning(png_ptr, "zstream not in use (internal error)");
 167.361  }
 167.362  
 167.363 -#if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_iCCP_SUPPORTED)
 167.364 -/*
 167.365 - * This pair of functions encapsulates the operation of (a) compressing a
 167.366 +#ifdef PNG_WRITE_COMPRESSED_TEXT_SUPPORTED
 167.367 +/* This pair of functions encapsulates the operation of (a) compressing a
 167.368   * text string, and (b) issuing it later as a series of chunk data writes.
 167.369   * The compression_state structure is shared context for these functions
 167.370   * set up by the caller in order to make the whole mess thread-safe.
 167.371 @@ -177,18 +371,18 @@
 167.372  
 167.373  typedef struct
 167.374  {
 167.375 -    char *input;   /* the uncompressed input data */
 167.376 -    int input_len;   /* its length */
 167.377 -    int num_output_ptr; /* number of output pointers used */
 167.378 -    int max_output_ptr; /* size of output_ptr */
 167.379 -    png_charpp output_ptr; /* array of pointers to output */
 167.380 +   png_const_bytep input;   /* The uncompressed input data */
 167.381 +   png_size_t input_len;    /* Its length */
 167.382 +   int num_output_ptr;      /* Number of output pointers used */
 167.383 +   int max_output_ptr;      /* Size of output_ptr */
 167.384 +   png_bytep *output_ptr;   /* Array of pointers to output */
 167.385  } compression_state;
 167.386  
 167.387 -/* compress given text into storage in the png_ptr structure */
 167.388 +/* Compress given text into storage in the png_ptr structure */
 167.389  static int /* PRIVATE */
 167.390  png_text_compress(png_structp png_ptr,
 167.391 -        png_charp text, png_size_t text_len, int compression,
 167.392 -        compression_state *comp)
 167.393 +    png_const_charp text, png_size_t text_len, int compression,
 167.394 +    compression_state *comp)
 167.395  {
 167.396     int ret;
 167.397  
 167.398 @@ -196,25 +390,22 @@
 167.399     comp->max_output_ptr = 0;
 167.400     comp->output_ptr = NULL;
 167.401     comp->input = NULL;
 167.402 -   comp->input_len = 0;
 167.403 -
 167.404 -   /* we may just want to pass the text right through */
 167.405 +   comp->input_len = text_len;
 167.406 +
 167.407 +   /* We may just want to pass the text right through */
 167.408     if (compression == PNG_TEXT_COMPRESSION_NONE)
 167.409     {
 167.410 -       comp->input = text;
 167.411 -       comp->input_len = text_len;
 167.412 -       return((int)text_len);
 167.413 +      comp->input = (png_const_bytep)text;
 167.414 +      return((int)text_len);
 167.415     }
 167.416  
 167.417     if (compression >= PNG_TEXT_COMPRESSION_LAST)
 167.418     {
 167.419 -#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
 167.420 -      char msg[50];
 167.421 -      sprintf(msg, "Unknown compression type %d", compression);
 167.422 -      png_warning(png_ptr, msg);
 167.423 -#else
 167.424 -      png_warning(png_ptr, "Unknown compression type");
 167.425 -#endif
 167.426 +      PNG_WARNING_PARAMETERS(p)
 167.427 +
 167.428 +      png_warning_parameter_signed(p, 1, PNG_NUMBER_FORMAT_d,
 167.429 +         compression);
 167.430 +      png_formatted_warning(png_ptr, p, "Unknown compression type @1");
 167.431     }
 167.432  
 167.433     /* We can't write the chunk until we find out how much data we have,
 167.434 @@ -231,30 +422,37 @@
 167.435      * data, or if the input string is incredibly large (although this
 167.436      * wouldn't cause a failure, just a slowdown due to swapping).
 167.437      */
 167.438 -
 167.439 -   /* set up the compression buffers */
 167.440 +   png_zlib_claim(png_ptr, PNG_ZLIB_FOR_TEXT);
 167.441 +
 167.442 +   /* Set up the compression buffers */
 167.443 +   /* TODO: the following cast hides a potential overflow problem. */
 167.444     png_ptr->zstream.avail_in = (uInt)text_len;
 167.445 +
 167.446 +   /* NOTE: assume zlib doesn't overwrite the input */
 167.447     png_ptr->zstream.next_in = (Bytef *)text;
 167.448 -   png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
 167.449 -   png_ptr->zstream.next_out = (Bytef *)png_ptr->zbuf;
 167.450 -
 167.451 -   /* this is the same compression loop as in png_write_row() */
 167.452 +   png_ptr->zstream.avail_out = png_ptr->zbuf_size;
 167.453 +   png_ptr->zstream.next_out = png_ptr->zbuf;
 167.454 +
 167.455 +   /* This is the same compression loop as in png_write_row() */
 167.456     do
 167.457     {
 167.458 -      /* compress the data */
 167.459 +      /* Compress the data */
 167.460        ret = deflate(&png_ptr->zstream, Z_NO_FLUSH);
 167.461 +
 167.462        if (ret != Z_OK)
 167.463        {
 167.464 -         /* error */
 167.465 +         /* Error */
 167.466           if (png_ptr->zstream.msg != NULL)
 167.467              png_error(png_ptr, png_ptr->zstream.msg);
 167.468 +
 167.469           else
 167.470              png_error(png_ptr, "zlib error");
 167.471        }
 167.472 -      /* check to see if we need more room */
 167.473 +
 167.474 +      /* Check to see if we need more room */
 167.475        if (!(png_ptr->zstream.avail_out))
 167.476        {
 167.477 -         /* make sure the output array has room */
 167.478 +         /* Make sure the output array has room */
 167.479           if (comp->num_output_ptr >= comp->max_output_ptr)
 167.480           {
 167.481              int old_max;
 167.482 @@ -263,48 +461,54 @@
 167.483              comp->max_output_ptr = comp->num_output_ptr + 4;
 167.484              if (comp->output_ptr != NULL)
 167.485              {
 167.486 -               png_charpp old_ptr;
 167.487 +               png_bytepp old_ptr;
 167.488  
 167.489                 old_ptr = comp->output_ptr;
 167.490 -               comp->output_ptr = (png_charpp)png_malloc(png_ptr,
 167.491 -                  (png_uint_32)(comp->max_output_ptr *
 167.492 -                  png_sizeof (png_charpp)));
 167.493 +
 167.494 +               comp->output_ptr = (png_bytepp)png_malloc(png_ptr,
 167.495 +                   (png_alloc_size_t)
 167.496 +                   (comp->max_output_ptr * png_sizeof(png_charpp)));
 167.497 +
 167.498                 png_memcpy(comp->output_ptr, old_ptr, old_max
 167.499 -                  * png_sizeof (png_charp));
 167.500 +                   * png_sizeof(png_charp));
 167.501 +
 167.502                 png_free(png_ptr, old_ptr);
 167.503              }
 167.504              else
 167.505 -               comp->output_ptr = (png_charpp)png_malloc(png_ptr,
 167.506 -                  (png_uint_32)(comp->max_output_ptr *
 167.507 -                  png_sizeof (png_charp)));
 167.508 +               comp->output_ptr = (png_bytepp)png_malloc(png_ptr,
 167.509 +                   (png_alloc_size_t)
 167.510 +                   (comp->max_output_ptr * png_sizeof(png_charp)));
 167.511           }
 167.512  
 167.513 -         /* save the data */
 167.514 -         comp->output_ptr[comp->num_output_ptr] = (png_charp)png_malloc(png_ptr,
 167.515 -            (png_uint_32)png_ptr->zbuf_size);
 167.516 +         /* Save the data */
 167.517 +         comp->output_ptr[comp->num_output_ptr] =
 167.518 +             (png_bytep)png_malloc(png_ptr,
 167.519 +             (png_alloc_size_t)png_ptr->zbuf_size);
 167.520 +
 167.521           png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
 167.522 -            png_ptr->zbuf_size);
 167.523 +             png_ptr->zbuf_size);
 167.524 +
 167.525           comp->num_output_ptr++;
 167.526  
 167.527           /* and reset the buffer */
 167.528           png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
 167.529           png_ptr->zstream.next_out = png_ptr->zbuf;
 167.530        }
 167.531 -   /* continue until we don't have any more to compress */
 167.532 +   /* Continue until we don't have any more to compress */
 167.533     } while (png_ptr->zstream.avail_in);
 167.534  
 167.535 -   /* finish the compression */
 167.536 +   /* Finish the compression */
 167.537     do
 167.538     {
 167.539 -      /* tell zlib we are finished */
 167.540 +      /* Tell zlib we are finished */
 167.541        ret = deflate(&png_ptr->zstream, Z_FINISH);
 167.542  
 167.543        if (ret == Z_OK)
 167.544        {
 167.545 -         /* check to see if we need more room */
 167.546 +         /* Check to see if we need more room */
 167.547           if (!(png_ptr->zstream.avail_out))
 167.548           {
 167.549 -            /* check to make sure our output array has room */
 167.550 +            /* Check to make sure our output array has room */
 167.551              if (comp->num_output_ptr >= comp->max_output_ptr)
 167.552              {
 167.553                 int old_max;
 167.554 @@ -313,28 +517,35 @@
 167.555                 comp->max_output_ptr = comp->num_output_ptr + 4;
 167.556                 if (comp->output_ptr != NULL)
 167.557                 {
 167.558 -                  png_charpp old_ptr;
 167.559 +                  png_bytepp old_ptr;
 167.560  
 167.561                    old_ptr = comp->output_ptr;
 167.562 +
 167.563                    /* This could be optimized to realloc() */
 167.564 -                  comp->output_ptr = (png_charpp)png_malloc(png_ptr,
 167.565 -                     (png_uint_32)(comp->max_output_ptr *
 167.566 -                     png_sizeof (png_charpp)));
 167.567 +                  comp->output_ptr = (png_bytepp)png_malloc(png_ptr,
 167.568 +                      (png_alloc_size_t)(comp->max_output_ptr *
 167.569 +                      png_sizeof(png_charp)));
 167.570 +
 167.571                    png_memcpy(comp->output_ptr, old_ptr,
 167.572 -                     old_max * png_sizeof (png_charp));
 167.573 +                      old_max * png_sizeof(png_charp));
 167.574 +
 167.575                    png_free(png_ptr, old_ptr);
 167.576                 }
 167.577 +
 167.578                 else
 167.579 -                  comp->output_ptr = (png_charpp)png_malloc(png_ptr,
 167.580 -                     (png_uint_32)(comp->max_output_ptr *
 167.581 -                     png_sizeof (png_charp)));
 167.582 +                  comp->output_ptr = (png_bytepp)png_malloc(png_ptr,
 167.583 +                      (png_alloc_size_t)(comp->max_output_ptr *
 167.584 +                      png_sizeof(png_charp)));
 167.585              }
 167.586  
 167.587 -            /* save off the data */
 167.588 +            /* Save the data */
 167.589              comp->output_ptr[comp->num_output_ptr] =
 167.590 -               (png_charp)png_malloc(png_ptr, (png_uint_32)png_ptr->zbuf_size);
 167.591 +                (png_bytep)png_malloc(png_ptr,
 167.592 +                (png_alloc_size_t)png_ptr->zbuf_size);
 167.593 +
 167.594              png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
 167.595 -               png_ptr->zbuf_size);
 167.596 +                png_ptr->zbuf_size);
 167.597 +
 167.598              comp->num_output_ptr++;
 167.599  
 167.600              /* and reset the buffer pointers */
 167.601 @@ -344,57 +555,121 @@
 167.602        }
 167.603        else if (ret != Z_STREAM_END)
 167.604        {
 167.605 -         /* we got an error */
 167.606 +         /* We got an error */
 167.607           if (png_ptr->zstream.msg != NULL)
 167.608              png_error(png_ptr, png_ptr->zstream.msg);
 167.609 +
 167.610           else
 167.611              png_error(png_ptr, "zlib error");
 167.612        }
 167.613     } while (ret != Z_STREAM_END);
 167.614  
 167.615 -   /* text length is number of buffers plus last buffer */
 167.616 +   /* Text length is number of buffers plus last buffer */
 167.617     text_len = png_ptr->zbuf_size * comp->num_output_ptr;
 167.618 +
 167.619     if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
 167.620        text_len += png_ptr->zbuf_size - (png_size_t)png_ptr->zstream.avail_out;
 167.621  
 167.622     return((int)text_len);
 167.623  }
 167.624  
 167.625 -/* ship the compressed text out via chunk writes */
 167.626 +/* Ship the compressed text out via chunk writes */
 167.627  static void /* PRIVATE */
 167.628  png_write_compressed_data_out(png_structp png_ptr, compression_state *comp)
 167.629  {
 167.630     int i;
 167.631  
 167.632 -   /* handle the no-compression case */
 167.633 +   /* Handle the no-compression case */
 167.634     if (comp->input)
 167.635     {
 167.636 -       png_write_chunk_data(png_ptr, (png_bytep)comp->input,
 167.637 -                            (png_size_t)comp->input_len);
 167.638 -       return;
 167.639 +      png_write_chunk_data(png_ptr, comp->input, comp->input_len);
 167.640 +
 167.641 +      return;
 167.642     }
 167.643  
 167.644 -   /* write saved output buffers, if any */
 167.645 +#ifdef PNG_WRITE_OPTIMIZE_CMF_SUPPORTED
 167.646 +   if (comp->input_len >= 2 && comp->input_len < 16384)
 167.647 +   {
 167.648 +      unsigned int z_cmf;  /* zlib compression method and flags */
 167.649 +
 167.650 +      /* Optimize the CMF field in the zlib stream.  This hack of the zlib
 167.651 +       * stream is compliant to the stream specification.
 167.652 +       */
 167.653 +
 167.654 +      if (comp->num_output_ptr)
 167.655 +        z_cmf = comp->output_ptr[0][0];
 167.656 +      else
 167.657 +        z_cmf = png_ptr->zbuf[0];
 167.658 +
 167.659 +      if ((z_cmf & 0x0f) == 8 && (z_cmf & 0xf0) <= 0x70)
 167.660 +      {
 167.661 +         unsigned int z_cinfo;
 167.662 +         unsigned int half_z_window_size;
 167.663 +         png_size_t uncompressed_text_size = comp->input_len;
 167.664 +
 167.665 +         z_cinfo = z_cmf >> 4;
 167.666 +         half_z_window_size = 1 << (z_cinfo + 7);
 167.667 +
 167.668 +         while (uncompressed_text_size <= half_z_window_size &&
 167.669 +             half_z_window_size >= 256)
 167.670 +         {
 167.671 +            z_cinfo--;
 167.672 +            half_z_window_size >>= 1;
 167.673 +         }
 167.674 +
 167.675 +         z_cmf = (z_cmf & 0x0f) | (z_cinfo << 4);
 167.676 +
 167.677 +         if (comp->num_output_ptr)
 167.678 +         {
 167.679 +
 167.680 +           if (comp->output_ptr[0][0] != z_cmf)
 167.681 +           {
 167.682 +              int tmp;
 167.683 +
 167.684 +              comp->output_ptr[0][0] = (png_byte)z_cmf;
 167.685 +              tmp = comp->output_ptr[0][1] & 0xe0;
 167.686 +              tmp += 0x1f - ((z_cmf << 8) + tmp) % 0x1f;
 167.687 +              comp->output_ptr[0][1] = (png_byte)tmp;
 167.688 +           }
 167.689 +         }
 167.690 +         else
 167.691 +         {
 167.692 +            int tmp;
 167.693 +
 167.694 +            png_ptr->zbuf[0] = (png_byte)z_cmf;
 167.695 +            tmp = png_ptr->zbuf[1] & 0xe0;
 167.696 +            tmp += 0x1f - ((z_cmf << 8) + tmp) % 0x1f;
 167.697 +            png_ptr->zbuf[1] = (png_byte)tmp;
 167.698 +         }
 167.699 +      }
 167.700 +
 167.701 +      else
 167.702 +         png_error(png_ptr,
 167.703 +             "Invalid zlib compression method or flags in non-IDAT chunk");
 167.704 +   }
 167.705 +#endif /* PNG_WRITE_OPTIMIZE_CMF_SUPPORTED */
 167.706 +
 167.707 +   /* Write saved output buffers, if any */
 167.708     for (i = 0; i < comp->num_output_ptr; i++)
 167.709     {
 167.710 -      png_write_chunk_data(png_ptr,(png_bytep)comp->output_ptr[i],
 167.711 -         png_ptr->zbuf_size);
 167.712 +      png_write_chunk_data(png_ptr, comp->output_ptr[i],
 167.713 +          (png_size_t)png_ptr->zbuf_size);
 167.714 +
 167.715        png_free(png_ptr, comp->output_ptr[i]);
 167.716 -      comp->output_ptr[i]=NULL;
 167.717     }
 167.718 +
 167.719     if (comp->max_output_ptr != 0)
 167.720        png_free(png_ptr, comp->output_ptr);
 167.721 -      comp->output_ptr=NULL;
 167.722 -   /* write anything left in zbuf */
 167.723 +
 167.724 +   /* Write anything left in zbuf */
 167.725     if (png_ptr->zstream.avail_out < (png_uint_32)png_ptr->zbuf_size)
 167.726        png_write_chunk_data(png_ptr, png_ptr->zbuf,
 167.727 -         png_ptr->zbuf_size - png_ptr->zstream.avail_out);
 167.728 -
 167.729 -   /* reset zlib for another zTXt/iTXt or image data */
 167.730 -   deflateReset(&png_ptr->zstream);
 167.731 -   png_ptr->zstream.data_type = Z_BINARY;
 167.732 +          (png_size_t)(png_ptr->zbuf_size - png_ptr->zstream.avail_out));
 167.733 +
 167.734 +   /* Reset zlib for another zTXt/iTXt or image data */
 167.735 +   png_zlib_release(png_ptr);
 167.736  }
 167.737 -#endif
 167.738 +#endif /* PNG_WRITE_COMPRESSED_TEXT_SUPPORTED */
 167.739  
 167.740  /* Write the IHDR chunk, and update the png_struct with the necessary
 167.741   * information.  Note that the rest of this code depends upon this
 167.742 @@ -402,15 +677,15 @@
 167.743   */
 167.744  void /* PRIVATE */
 167.745  png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height,
 167.746 -   int bit_depth, int color_type, int compression_type, int filter_type,
 167.747 -   int interlace_type)
 167.748 +    int bit_depth, int color_type, int compression_type, int filter_type,
 167.749 +    int interlace_type)
 167.750  {
 167.751 -#ifdef PNG_USE_LOCAL_ARRAYS
 167.752     PNG_IHDR;
 167.753 -#endif
 167.754 -   png_byte buf[13]; /* buffer to store the IHDR info */
 167.755 -
 167.756 -   png_debug(1, "in png_write_IHDR\n");
 167.757 +
 167.758 +   png_byte buf[13]; /* Buffer to store the IHDR info */
 167.759 +
 167.760 +   png_debug(1, "in png_write_IHDR");
 167.761 +
 167.762     /* Check that we have valid input data from the application info */
 167.763     switch (color_type)
 167.764     {
 167.765 @@ -421,35 +696,61 @@
 167.766              case 2:
 167.767              case 4:
 167.768              case 8:
 167.769 -            case 16: png_ptr->channels = 1; break;
 167.770 -            default: png_error(png_ptr,"Invalid bit depth for grayscale image");
 167.771 +#ifdef PNG_WRITE_16BIT_SUPPORTED
 167.772 +            case 16:
 167.773 +#endif
 167.774 +               png_ptr->channels = 1; break;
 167.775 +
 167.776 +            default:
 167.777 +               png_error(png_ptr,
 167.778 +                   "Invalid bit depth for grayscale image");
 167.779           }
 167.780           break;
 167.781 +
 167.782        case PNG_COLOR_TYPE_RGB:
 167.783 +#ifdef PNG_WRITE_16BIT_SUPPORTED
 167.784           if (bit_depth != 8 && bit_depth != 16)
 167.785 +#else
 167.786 +         if (bit_depth != 8)
 167.787 +#endif
 167.788              png_error(png_ptr, "Invalid bit depth for RGB image");
 167.789 +
 167.790           png_ptr->channels = 3;
 167.791           break;
 167.792 +
 167.793        case PNG_COLOR_TYPE_PALETTE:
 167.794           switch (bit_depth)
 167.795           {
 167.796              case 1:
 167.797              case 2:
 167.798              case 4:
 167.799 -            case 8: png_ptr->channels = 1; break;
 167.800 -            default: png_error(png_ptr, "Invalid bit depth for paletted image");
 167.801 +            case 8:
 167.802 +               png_ptr->channels = 1;
 167.803 +               break;
 167.804 +
 167.805 +            default:
 167.806 +               png_error(png_ptr, "Invalid bit depth for paletted image");
 167.807           }
 167.808           break;
 167.809 +
 167.810        case PNG_COLOR_TYPE_GRAY_ALPHA:
 167.811           if (bit_depth != 8 && bit_depth != 16)
 167.812              png_error(png_ptr, "Invalid bit depth for grayscale+alpha image");
 167.813 +
 167.814           png_ptr->channels = 2;
 167.815           break;
 167.816 +
 167.817        case PNG_COLOR_TYPE_RGB_ALPHA:
 167.818 +#ifdef PNG_WRITE_16BIT_SUPPORTED
 167.819           if (bit_depth != 8 && bit_depth != 16)
 167.820 +#else
 167.821 +         if (bit_depth != 8)
 167.822 +#endif
 167.823              png_error(png_ptr, "Invalid bit depth for RGBA image");
 167.824 +
 167.825           png_ptr->channels = 4;
 167.826           break;
 167.827 +
 167.828        default:
 167.829           png_error(png_ptr, "Invalid image color type specified");
 167.830     }
 167.831 @@ -470,14 +771,14 @@
 167.832      * 5. The color_type is RGB or RGBA
 167.833      */
 167.834     if (
 167.835 -#if defined(PNG_MNG_FEATURES_SUPPORTED)
 167.836 -      !((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
 167.837 -      ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
 167.838 -      (color_type == PNG_COLOR_TYPE_RGB ||
 167.839 -       color_type == PNG_COLOR_TYPE_RGB_ALPHA) &&
 167.840 -      (filter_type == PNG_INTRAPIXEL_DIFFERENCING)) &&
 167.841 +#ifdef PNG_MNG_FEATURES_SUPPORTED
 167.842 +       !((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
 167.843 +       ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
 167.844 +       (color_type == PNG_COLOR_TYPE_RGB ||
 167.845 +        color_type == PNG_COLOR_TYPE_RGB_ALPHA) &&
 167.846 +       (filter_type == PNG_INTRAPIXEL_DIFFERENCING)) &&
 167.847  #endif
 167.848 -      filter_type != PNG_FILTER_TYPE_BASE)
 167.849 +       filter_type != PNG_FILTER_TYPE_BASE)
 167.850     {
 167.851        png_warning(png_ptr, "Invalid filter type specified");
 167.852        filter_type = PNG_FILTER_TYPE_BASE;
 167.853 @@ -485,7 +786,7 @@
 167.854  
 167.855  #ifdef PNG_WRITE_INTERLACING_SUPPORTED
 167.856     if (interlace_type != PNG_INTERLACE_NONE &&
 167.857 -      interlace_type != PNG_INTERLACE_ADAM7)
 167.858 +       interlace_type != PNG_INTERLACE_ADAM7)
 167.859     {
 167.860        png_warning(png_ptr, "Invalid interlace type specified");
 167.861        interlace_type = PNG_INTERLACE_ADAM7;
 167.862 @@ -494,11 +795,11 @@
 167.863     interlace_type=PNG_INTERLACE_NONE;
 167.864  #endif
 167.865  
 167.866 -   /* save off the relevent information */
 167.867 +   /* Save the relevent information */
 167.868     png_ptr->bit_depth = (png_byte)bit_depth;
 167.869     png_ptr->color_type = (png_byte)color_type;
 167.870     png_ptr->interlaced = (png_byte)interlace_type;
 167.871 -#if defined(PNG_MNG_FEATURES_SUPPORTED)
 167.872 +#ifdef PNG_MNG_FEATURES_SUPPORTED
 167.873     png_ptr->filter_type = (png_byte)filter_type;
 167.874  #endif
 167.875     png_ptr->compression_type = (png_byte)compression_type;
 167.876 @@ -507,12 +808,12 @@
 167.877  
 167.878     png_ptr->pixel_depth = (png_byte)(bit_depth * png_ptr->channels);
 167.879     png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, width);
 167.880 -   /* set the usr info, so any transformations can modify it */
 167.881 +   /* Set the usr info, so any transformations can modify it */
 167.882     png_ptr->usr_width = png_ptr->width;
 167.883     png_ptr->usr_bit_depth = png_ptr->bit_depth;
 167.884     png_ptr->usr_channels = png_ptr->channels;
 167.885  
 167.886 -   /* pack the header information into the buffer */
 167.887 +   /* Pack the header information into the buffer */
 167.888     png_save_uint_32(buf, width);
 167.889     png_save_uint_32(buf + 4, height);
 167.890     buf[8] = (png_byte)bit_depth;
 167.891 @@ -521,93 +822,123 @@
 167.892     buf[11] = (png_byte)filter_type;
 167.893     buf[12] = (png_byte)interlace_type;
 167.894  
 167.895 -   /* write the chunk */
 167.896 -   png_write_chunk(png_ptr, (png_bytep)png_IHDR, buf, (png_size_t)13);
 167.897 -
 167.898 -   /* initialize zlib with PNG info */
 167.899 +   /* Write the chunk */
 167.900 +   png_write_chunk(png_ptr, png_IHDR, buf, (png_size_t)13);
 167.901 +
 167.902 +   /* Initialize zlib with PNG info */
 167.903     png_ptr->zstream.zalloc = png_zalloc;
 167.904     png_ptr->zstream.zfree = png_zfree;
 167.905     png_ptr->zstream.opaque = (voidpf)png_ptr;
 167.906 +
 167.907     if (!(png_ptr->do_filter))
 167.908     {
 167.909        if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE ||
 167.910 -         png_ptr->bit_depth < 8)
 167.911 +          png_ptr->bit_depth < 8)
 167.912           png_ptr->do_filter = PNG_FILTER_NONE;
 167.913 +
 167.914        else
 167.915           png_ptr->do_filter = PNG_ALL_FILTERS;
 167.916     }
 167.917 +
 167.918     if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_STRATEGY))
 167.919     {
 167.920        if (png_ptr->do_filter != PNG_FILTER_NONE)
 167.921           png_ptr->zlib_strategy = Z_FILTERED;
 167.922 +
 167.923        else
 167.924           png_ptr->zlib_strategy = Z_DEFAULT_STRATEGY;
 167.925     }
 167.926 +
 167.927     if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_LEVEL))
 167.928        png_ptr->zlib_level = Z_DEFAULT_COMPRESSION;
 167.929 +
 167.930     if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL))
 167.931        png_ptr->zlib_mem_level = 8;
 167.932 +
 167.933     if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS))
 167.934        png_ptr->zlib_window_bits = 15;
 167.935 +
 167.936     if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_METHOD))
 167.937        png_ptr->zlib_method = 8;
 167.938 -   if (deflateInit2(&png_ptr->zstream, png_ptr->zlib_level,
 167.939 -      png_ptr->zlib_method, png_ptr->zlib_window_bits,
 167.940 -      png_ptr->zlib_mem_level, png_ptr->zlib_strategy) != Z_OK)
 167.941 -       png_error(png_ptr, "zlib failed to initialize compressor");
 167.942 -   png_ptr->zstream.next_out = png_ptr->zbuf;
 167.943 -   png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
 167.944 -   /* libpng is not interested in zstream.data_type */
 167.945 -   /* set it to a predefined value, to avoid its evaluation inside zlib */
 167.946 -   png_ptr->zstream.data_type = Z_BINARY;
 167.947 -
 167.948 -   png_ptr->mode = PNG_HAVE_IHDR;
 167.949 +
 167.950 +#ifdef PNG_WRITE_COMPRESSED_TEXT_SUPPORTED
 167.951 +#ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED
 167.952 +   if (!(png_ptr->flags & PNG_FLAG_ZTXT_CUSTOM_STRATEGY))
 167.953 +      png_ptr->zlib_text_strategy = Z_DEFAULT_STRATEGY;
 167.954 +
 167.955 +   if (!(png_ptr->flags & PNG_FLAG_ZTXT_CUSTOM_LEVEL))
 167.956 +      png_ptr->zlib_text_level = png_ptr->zlib_level;
 167.957 +
 167.958 +   if (!(png_ptr->flags & PNG_FLAG_ZTXT_CUSTOM_MEM_LEVEL))
 167.959 +      png_ptr->zlib_text_mem_level = png_ptr->zlib_mem_level;
 167.960 +
 167.961 +   if (!(png_ptr->flags & PNG_FLAG_ZTXT_CUSTOM_WINDOW_BITS))
 167.962 +      png_ptr->zlib_text_window_bits = png_ptr->zlib_window_bits;
 167.963 +
 167.964 +   if (!(png_ptr->flags & PNG_FLAG_ZTXT_CUSTOM_METHOD))
 167.965 +      png_ptr->zlib_text_method = png_ptr->zlib_method;
 167.966 +#else
 167.967 +   png_ptr->zlib_text_strategy = Z_DEFAULT_STRATEGY;
 167.968 +   png_ptr->zlib_text_level = png_ptr->zlib_level;
 167.969 +   png_ptr->zlib_text_mem_level = png_ptr->zlib_mem_level;
 167.970 +   png_ptr->zlib_text_window_bits = png_ptr->zlib_window_bits;
 167.971 +   png_ptr->zlib_text_method = png_ptr->zlib_method;
 167.972 +#endif /* PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED */
 167.973 +#endif /* PNG_WRITE_COMPRESSED_TEXT_SUPPORTED */
 167.974 +
 167.975 +   /* Record that the compressor has not yet been initialized. */
 167.976 +   png_ptr->zlib_state = PNG_ZLIB_UNINITIALIZED;
 167.977 +
 167.978 +   png_ptr->mode = PNG_HAVE_IHDR; /* not READY_FOR_ZTXT */
 167.979  }
 167.980  
 167.981 -/* write the palette.  We are careful not to trust png_color to be in the
 167.982 +/* Write the palette.  We are careful not to trust png_color to be in the
 167.983   * correct order for PNG, so people can redefine it to any convenient
 167.984   * structure.
 167.985   */
 167.986  void /* PRIVATE */
 167.987 -png_write_PLTE(png_structp png_ptr, png_colorp palette, png_uint_32 num_pal)
 167.988 +png_write_PLTE(png_structp png_ptr, png_const_colorp palette,
 167.989 +    png_uint_32 num_pal)
 167.990  {
 167.991 -#ifdef PNG_USE_LOCAL_ARRAYS
 167.992     PNG_PLTE;
 167.993 +   png_uint_32 i;
 167.994 +   png_const_colorp pal_ptr;
 167.995 +   png_byte buf[3];
 167.996 +
 167.997 +   png_debug(1, "in png_write_PLTE");
 167.998 +
 167.999 +   if ((
167.1000 +#ifdef PNG_MNG_FEATURES_SUPPORTED
167.1001 +       !(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) &&
167.1002  #endif
167.1003 -   png_uint_32 i;
167.1004 -   png_colorp pal_ptr;
167.1005 -   png_byte buf[3];
167.1006 -
167.1007 -   png_debug(1, "in png_write_PLTE\n");
167.1008 -   if ((
167.1009 -#if defined(PNG_MNG_FEATURES_SUPPORTED)
167.1010 -        !(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) &&
167.1011 -#endif
167.1012 -        num_pal == 0) || num_pal > 256)
167.1013 +       num_pal == 0) || num_pal > 256)
167.1014     {
167.1015 -     if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
167.1016 -     {
167.1017 -        png_error(png_ptr, "Invalid number of colors in palette");
167.1018 -     }
167.1019 -     else
167.1020 -     {
167.1021 -        png_warning(png_ptr, "Invalid number of colors in palette");
167.1022 -        return;
167.1023 -     }
167.1024 +      if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
167.1025 +      {
167.1026 +         png_error(png_ptr, "Invalid number of colors in palette");
167.1027 +      }
167.1028 +
167.1029 +      else
167.1030 +      {
167.1031 +         png_warning(png_ptr, "Invalid number of colors in palette");
167.1032 +         return;
167.1033 +      }
167.1034     }
167.1035  
167.1036     if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR))
167.1037     {
167.1038        png_warning(png_ptr,
167.1039 -        "Ignoring request to write a PLTE chunk in grayscale PNG");
167.1040 +          "Ignoring request to write a PLTE chunk in grayscale PNG");
167.1041 +
167.1042        return;
167.1043     }
167.1044  
167.1045     png_ptr->num_palette = (png_uint_16)num_pal;
167.1046 -   png_debug1(3, "num_palette = %d\n", png_ptr->num_palette);
167.1047 -
167.1048 -   png_write_chunk_start(png_ptr, (png_bytep)png_PLTE, num_pal * 3);
167.1049 -#ifndef PNG_NO_POINTER_INDEXING
167.1050 +   png_debug1(3, "num_palette = %d", png_ptr->num_palette);
167.1051 +
167.1052 +   png_write_chunk_start(png_ptr, png_PLTE, (png_uint_32)(num_pal * 3));
167.1053 +#ifdef PNG_POINTER_INDEXING_SUPPORTED
167.1054 +
167.1055     for (i = 0, pal_ptr = palette; i < num_pal; i++, pal_ptr++)
167.1056     {
167.1057        buf[0] = pal_ptr->red;
167.1058 @@ -615,9 +946,13 @@
167.1059        buf[2] = pal_ptr->blue;
167.1060        png_write_chunk_data(png_ptr, buf, (png_size_t)3);
167.1061     }
167.1062 +
167.1063  #else
167.1064 -   /* This is a little slower but some buggy compilers need to do this instead */
167.1065 +   /* This is a little slower but some buggy compilers need to do this
167.1066 +    * instead
167.1067 +    */
167.1068     pal_ptr=palette;
167.1069 +
167.1070     for (i = 0; i < num_pal; i++)
167.1071     {
167.1072        buf[0] = pal_ptr[i].red;
167.1073 @@ -625,146 +960,159 @@
167.1074        buf[2] = pal_ptr[i].blue;
167.1075        png_write_chunk_data(png_ptr, buf, (png_size_t)3);
167.1076     }
167.1077 +
167.1078  #endif
167.1079     png_write_chunk_end(png_ptr);
167.1080     png_ptr->mode |= PNG_HAVE_PLTE;
167.1081  }
167.1082  
167.1083 -/* write an IDAT chunk */
167.1084 +/* Write an IDAT chunk */
167.1085  void /* PRIVATE */
167.1086  png_write_IDAT(png_structp png_ptr, png_bytep data, png_size_t length)
167.1087  {
167.1088 -#ifdef PNG_USE_LOCAL_ARRAYS
167.1089     PNG_IDAT;
167.1090 -#endif
167.1091 -   png_debug(1, "in png_write_IDAT\n");
167.1092 -
167.1093 -   /* Optimize the CMF field in the zlib stream. */
167.1094 -   /* This hack of the zlib stream is compliant to the stream specification. */
167.1095 +
167.1096 +   png_debug(1, "in png_write_IDAT");
167.1097 +
167.1098 +#ifdef PNG_WRITE_OPTIMIZE_CMF_SUPPORTED
167.1099     if (!(png_ptr->mode & PNG_HAVE_IDAT) &&
167.1100         png_ptr->compression_type == PNG_COMPRESSION_TYPE_BASE)
167.1101     {
167.1102 +      /* Optimize the CMF field in the zlib stream.  This hack of the zlib
167.1103 +       * stream is compliant to the stream specification.
167.1104 +       */
167.1105        unsigned int z_cmf = data[0];  /* zlib compression method and flags */
167.1106 +
167.1107        if ((z_cmf & 0x0f) == 8 && (z_cmf & 0xf0) <= 0x70)
167.1108        {
167.1109 -         /* Avoid memory underflows and multiplication overflows. */
167.1110 -         /* The conditions below are practically always satisfied;
167.1111 -            however, they still must be checked. */
167.1112 +         /* Avoid memory underflows and multiplication overflows.
167.1113 +          *
167.1114 +          * The conditions below are practically always satisfied;
167.1115 +          * however, they still must be checked.
167.1116 +          */
167.1117           if (length >= 2 &&
167.1118               png_ptr->height < 16384 && png_ptr->width < 16384)
167.1119           {
167.1120 +            /* Compute the maximum possible length of the datastream */
167.1121 +
167.1122 +            /* Number of pixels, plus for each row a filter byte
167.1123 +             * and possibly a padding byte, so increase the maximum
167.1124 +             * size to account for these.
167.1125 +             */
167.1126 +            unsigned int z_cinfo;
167.1127 +            unsigned int half_z_window_size;
167.1128              png_uint_32 uncompressed_idat_size = png_ptr->height *
167.1129 -               ((png_ptr->width *
167.1130 -               png_ptr->channels * png_ptr->bit_depth + 15) >> 3);
167.1131 -            unsigned int z_cinfo = z_cmf >> 4;
167.1132 -            unsigned int half_z_window_size = 1 << (z_cinfo + 7);
167.1133 +                ((png_ptr->width *
167.1134 +                png_ptr->channels * png_ptr->bit_depth + 15) >> 3);
167.1135 +
167.1136 +            /* If it's interlaced, each block of 8 rows is sent as up to
167.1137 +             * 14 rows, i.e., 6 additional rows, each with a filter byte
167.1138 +             * and possibly a padding byte
167.1139 +             */
167.1140 +            if (png_ptr->interlaced)
167.1141 +               uncompressed_idat_size += ((png_ptr->height + 7)/8) *
167.1142 +                   (png_ptr->bit_depth < 8 ? 12 : 6);
167.1143 +
167.1144 +            z_cinfo = z_cmf >> 4;
167.1145 +            half_z_window_size = 1 << (z_cinfo + 7);
167.1146 +
167.1147              while (uncompressed_idat_size <= half_z_window_size &&
167.1148 -                   half_z_window_size >= 256)
167.1149 +                half_z_window_size >= 256)
167.1150              {
167.1151                 z_cinfo--;
167.1152                 half_z_window_size >>= 1;
167.1153              }
167.1154 +
167.1155              z_cmf = (z_cmf & 0x0f) | (z_cinfo << 4);
167.1156 -            if (data[0] != (png_byte)z_cmf)
167.1157 +
167.1158 +            if (data[0] != z_cmf)
167.1159              {
167.1160 +               int tmp;
167.1161                 data[0] = (png_byte)z_cmf;
167.1162 -               data[1] &= 0xe0;
167.1163 -               data[1] += (png_byte)(0x1f - ((z_cmf << 8) + data[1]) % 0x1f);
167.1164 +               tmp = data[1] & 0xe0;
167.1165 +               tmp += 0x1f - ((z_cmf << 8) + tmp) % 0x1f;
167.1166 +               data[1] = (png_byte)tmp;
167.1167              }
167.1168           }
167.1169        }
167.1170 +
167.1171        else
167.1172           png_error(png_ptr,
167.1173 -            "Invalid zlib compression method or flags in IDAT");
167.1174 +             "Invalid zlib compression method or flags in IDAT");
167.1175     }
167.1176 -
167.1177 -   png_write_chunk(png_ptr, (png_bytep)png_IDAT, data, length);
167.1178 +#endif /* PNG_WRITE_OPTIMIZE_CMF_SUPPORTED */
167.1179 +
167.1180 +   png_write_chunk(png_ptr, png_IDAT, data, length);
167.1181     png_ptr->mode |= PNG_HAVE_IDAT;
167.1182 +
167.1183 +   /* Prior to 1.5.4 this code was replicated in every caller (except at the
167.1184 +    * end, where it isn't technically necessary).  Since this function has
167.1185 +    * flushed the data we can safely reset the zlib output buffer here.
167.1186 +    */
167.1187 +   png_ptr->zstream.next_out = png_ptr->zbuf;
167.1188 +   png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
167.1189  }
167.1190  
167.1191 -/* write an IEND chunk */
167.1192 +/* Write an IEND chunk */
167.1193  void /* PRIVATE */
167.1194  png_write_IEND(png_structp png_ptr)
167.1195  {
167.1196 -#ifdef PNG_USE_LOCAL_ARRAYS
167.1197     PNG_IEND;
167.1198 -#endif
167.1199 -   png_debug(1, "in png_write_IEND\n");
167.1200 -   png_write_chunk(png_ptr, (png_bytep)png_IEND, png_bytep_NULL,
167.1201 -     (png_size_t)0);
167.1202 +
167.1203 +   png_debug(1, "in png_write_IEND");
167.1204 +
167.1205 +   png_write_chunk(png_ptr, png_IEND, NULL, (png_size_t)0);
167.1206     png_ptr->mode |= PNG_HAVE_IEND;
167.1207  }
167.1208  
167.1209 -#if defined(PNG_WRITE_gAMA_SUPPORTED)
167.1210 -/* write a gAMA chunk */
167.1211 -#ifdef PNG_FLOATING_POINT_SUPPORTED
167.1212 -void /* PRIVATE */
167.1213 -png_write_gAMA(png_structp png_ptr, double file_gamma)
167.1214 -{
167.1215 -#ifdef PNG_USE_LOCAL_ARRAYS
167.1216 -   PNG_gAMA;
167.1217 -#endif
167.1218 -   png_uint_32 igamma;
167.1219 -   png_byte buf[4];
167.1220 -
167.1221 -   png_debug(1, "in png_write_gAMA\n");
167.1222 -   /* file_gamma is saved in 1/100,000ths */
167.1223 -   igamma = (png_uint_32)(file_gamma * 100000.0 + 0.5);
167.1224 -   png_save_uint_32(buf, igamma);
167.1225 -   png_write_chunk(png_ptr, (png_bytep)png_gAMA, buf, (png_size_t)4);
167.1226 -}
167.1227 -#endif
167.1228 -#ifdef PNG_FIXED_POINT_SUPPORTED
167.1229 +#ifdef PNG_WRITE_gAMA_SUPPORTED
167.1230 +/* Write a gAMA chunk */
167.1231  void /* PRIVATE */
167.1232  png_write_gAMA_fixed(png_structp png_ptr, png_fixed_point file_gamma)
167.1233  {
167.1234 -#ifdef PNG_USE_LOCAL_ARRAYS
167.1235     PNG_gAMA;
167.1236 -#endif
167.1237     png_byte buf[4];
167.1238  
167.1239 -   png_debug(1, "in png_write_gAMA\n");
167.1240 +   png_debug(1, "in png_write_gAMA");
167.1241 +
167.1242     /* file_gamma is saved in 1/100,000ths */
167.1243     png_save_uint_32(buf, (png_uint_32)file_gamma);
167.1244 -   png_write_chunk(png_ptr, (png_bytep)png_gAMA, buf, (png_size_t)4);
167.1245 +   png_write_chunk(png_ptr, png_gAMA, buf, (png_size_t)4);
167.1246  }
167.1247  #endif
167.1248 -#endif
167.1249 -
167.1250 -#if defined(PNG_WRITE_sRGB_SUPPORTED)
167.1251 -/* write a sRGB chunk */
167.1252 +
167.1253 +#ifdef PNG_WRITE_sRGB_SUPPORTED
167.1254 +/* Write a sRGB chunk */
167.1255  void /* PRIVATE */
167.1256  png_write_sRGB(png_structp png_ptr, int srgb_intent)
167.1257  {
167.1258 -#ifdef PNG_USE_LOCAL_ARRAYS
167.1259     PNG_sRGB;
167.1260 -#endif
167.1261     png_byte buf[1];
167.1262  
167.1263 -   png_debug(1, "in png_write_sRGB\n");
167.1264 -   if(srgb_intent >= PNG_sRGB_INTENT_LAST)
167.1265 -         png_warning(png_ptr,
167.1266 -            "Invalid sRGB rendering intent specified");
167.1267 +   png_debug(1, "in png_write_sRGB");
167.1268 +
167.1269 +   if (srgb_intent >= PNG_sRGB_INTENT_LAST)
167.1270 +      png_warning(png_ptr,
167.1271 +          "Invalid sRGB rendering intent specified");
167.1272 +
167.1273     buf[0]=(png_byte)srgb_intent;
167.1274 -   png_write_chunk(png_ptr, (png_bytep)png_sRGB, buf, (png_size_t)1);
167.1275 +   png_write_chunk(png_ptr, png_sRGB, buf, (png_size_t)1);
167.1276  }
167.1277  #endif
167.1278  
167.1279 -#if defined(PNG_WRITE_iCCP_SUPPORTED)
167.1280 -/* write an iCCP chunk */
167.1281 +#ifdef PNG_WRITE_iCCP_SUPPORTED
167.1282 +/* Write an iCCP chunk */
167.1283  void /* PRIVATE */
167.1284 -png_write_iCCP(png_structp png_ptr, png_charp name, int compression_type,
167.1285 -   png_charp profile, int profile_len)
167.1286 +png_write_iCCP(png_structp png_ptr, png_const_charp name, int compression_type,
167.1287 +    png_const_charp profile, int profile_len)
167.1288  {
167.1289 -#ifdef PNG_USE_LOCAL_ARRAYS
167.1290     PNG_iCCP;
167.1291 -#endif
167.1292     png_size_t name_len;
167.1293     png_charp new_name;
167.1294     compression_state comp;
167.1295     int embedded_profile_len = 0;
167.1296  
167.1297 -   png_debug(1, "in png_write_iCCP\n");
167.1298 +   png_debug(1, "in png_write_iCCP");
167.1299  
167.1300     comp.num_output_ptr = 0;
167.1301     comp.max_output_ptr = 0;
167.1302 @@ -772,133 +1120,149 @@
167.1303     comp.input = NULL;
167.1304     comp.input_len = 0;
167.1305  
167.1306 -   if (name == NULL || (name_len = png_check_keyword(png_ptr, name,
167.1307 -      &new_name)) == 0)
167.1308 +   if ((name_len = png_check_keyword(png_ptr, name, &new_name)) == 0)
167.1309 +      return;
167.1310 +
167.1311 +   if (compression_type != PNG_COMPRESSION_TYPE_BASE)
167.1312 +      png_warning(png_ptr, "Unknown compression type in iCCP chunk");
167.1313 +
167.1314 +   if (profile == NULL)
167.1315 +      profile_len = 0;
167.1316 +
167.1317 +   if (profile_len > 3)
167.1318 +      embedded_profile_len =
167.1319 +          ((*( (png_const_bytep)profile    ))<<24) |
167.1320 +          ((*( (png_const_bytep)profile + 1))<<16) |
167.1321 +          ((*( (png_const_bytep)profile + 2))<< 8) |
167.1322 +          ((*( (png_const_bytep)profile + 3))    );
167.1323 +
167.1324 +   if (embedded_profile_len < 0)
167.1325     {
167.1326 -      png_warning(png_ptr, "Empty keyword in iCCP chunk");
167.1327 +      png_warning(png_ptr,
167.1328 +          "Embedded profile length in iCCP chunk is negative");
167.1329 +
167.1330 +      png_free(png_ptr, new_name);
167.1331        return;
167.1332     }
167.1333  
167.1334 -   if (compression_type != PNG_COMPRESSION_TYPE_BASE)
167.1335 -      png_warning(png_ptr, "Unknown compression type in iCCP chunk");
167.1336 -
167.1337 -   if (profile == NULL)
167.1338 -      profile_len = 0;
167.1339 -
167.1340 -   if (profile_len > 3)
167.1341 -      embedded_profile_len =
167.1342 -          ((*( (png_bytep)profile  ))<<24) |
167.1343 -          ((*( (png_bytep)profile+1))<<16) |
167.1344 -          ((*( (png_bytep)profile+2))<< 8) |
167.1345 -          ((*( (png_bytep)profile+3))    );
167.1346 -
167.1347     if (profile_len < embedded_profile_len)
167.1348 -     {
167.1349 -        png_warning(png_ptr,
167.1350 +   {
167.1351 +      png_warning(png_ptr,
167.1352            "Embedded profile length too large in iCCP chunk");
167.1353 -        return;
167.1354 -     }
167.1355 +
167.1356 +      png_free(png_ptr, new_name);
167.1357 +      return;
167.1358 +   }
167.1359  
167.1360     if (profile_len > embedded_profile_len)
167.1361 -     {
167.1362 -        png_warning(png_ptr,
167.1363 +   {
167.1364 +      png_warning(png_ptr,
167.1365            "Truncating profile to actual length in iCCP chunk");
167.1366 -        profile_len = embedded_profile_len;
167.1367 -     }
167.1368 +
167.1369 +      profile_len = embedded_profile_len;
167.1370 +   }
167.1371  
167.1372     if (profile_len)
167.1373 -       profile_len = png_text_compress(png_ptr, profile, (png_size_t)profile_len,
167.1374 -          PNG_COMPRESSION_TYPE_BASE, &comp);
167.1375 -
167.1376 -   /* make sure we include the NULL after the name and the compression type */
167.1377 -   png_write_chunk_start(png_ptr, (png_bytep)png_iCCP,
167.1378 -          (png_uint_32)name_len+profile_len+2);
167.1379 -   new_name[name_len+1]=0x00;
167.1380 -   png_write_chunk_data(png_ptr, (png_bytep)new_name, name_len + 2);
167.1381 +      profile_len = png_text_compress(png_ptr, profile,
167.1382 +          (png_size_t)profile_len, PNG_COMPRESSION_TYPE_BASE, &comp);
167.1383 +
167.1384 +   /* Make sure we include the NULL after the name and the compression type */
167.1385 +   png_write_chunk_start(png_ptr, png_iCCP,
167.1386 +       (png_uint_32)(name_len + profile_len + 2));
167.1387 +
167.1388 +   new_name[name_len + 1] = 0x00;
167.1389 +
167.1390 +   png_write_chunk_data(png_ptr, (png_bytep)new_name,
167.1391 +       (png_size_t)(name_len + 2));
167.1392  
167.1393     if (profile_len)
167.1394 +   {
167.1395 +      comp.input_len = profile_len;
167.1396        png_write_compressed_data_out(png_ptr, &comp);
167.1397 +   }
167.1398  
167.1399     png_write_chunk_end(png_ptr);
167.1400     png_free(png_ptr, new_name);
167.1401  }
167.1402  #endif
167.1403  
167.1404 -#if defined(PNG_WRITE_sPLT_SUPPORTED)
167.1405 -/* write a sPLT chunk */
167.1406 +#ifdef PNG_WRITE_sPLT_SUPPORTED
167.1407 +/* Write a sPLT chunk */
167.1408  void /* PRIVATE */
167.1409 -png_write_sPLT(png_structp png_ptr, png_sPLT_tp spalette)
167.1410 +png_write_sPLT(png_structp png_ptr, png_const_sPLT_tp spalette)
167.1411  {
167.1412 -#ifdef PNG_USE_LOCAL_ARRAYS
167.1413     PNG_sPLT;
167.1414 -#endif
167.1415     png_size_t name_len;
167.1416     png_charp new_name;
167.1417     png_byte entrybuf[10];
167.1418 -   int entry_size = (spalette->depth == 8 ? 6 : 10);
167.1419 -   int palette_size = entry_size * spalette->nentries;
167.1420 +   png_size_t entry_size = (spalette->depth == 8 ? 6 : 10);
167.1421 +   png_size_t palette_size = entry_size * spalette->nentries;
167.1422     png_sPLT_entryp ep;
167.1423 -#ifdef PNG_NO_POINTER_INDEXING
167.1424 +#ifndef PNG_POINTER_INDEXING_SUPPORTED
167.1425     int i;
167.1426  #endif
167.1427  
167.1428 -   png_debug(1, "in png_write_sPLT\n");
167.1429 -   if (spalette->name == NULL || (name_len = png_check_keyword(png_ptr,
167.1430 -      spalette->name, &new_name))==0)
167.1431 +   png_debug(1, "in png_write_sPLT");
167.1432 +
167.1433 +   if ((name_len = png_check_keyword(png_ptr,spalette->name, &new_name))==0)
167.1434 +      return;
167.1435 +
167.1436 +   /* Make sure we include the NULL after the name */
167.1437 +   png_write_chunk_start(png_ptr, png_sPLT,
167.1438 +       (png_uint_32)(name_len + 2 + palette_size));
167.1439 +
167.1440 +   png_write_chunk_data(png_ptr, (png_bytep)new_name,
167.1441 +       (png_size_t)(name_len + 1));
167.1442 +
167.1443 +   png_write_chunk_data(png_ptr, &spalette->depth, (png_size_t)1);
167.1444 +
167.1445 +   /* Loop through each palette entry, writing appropriately */
167.1446 +#ifdef PNG_POINTER_INDEXING_SUPPORTED
167.1447 +   for (ep = spalette->entries; ep<spalette->entries + spalette->nentries; ep++)
167.1448     {
167.1449 -      png_warning(png_ptr, "Empty keyword in sPLT chunk");
167.1450 -      return;
167.1451 -   }
167.1452 -
167.1453 -   /* make sure we include the NULL after the name */
167.1454 -   png_write_chunk_start(png_ptr, (png_bytep)png_sPLT,
167.1455 -          (png_uint_32)(name_len + 2 + palette_size));
167.1456 -   png_write_chunk_data(png_ptr, (png_bytep)new_name, name_len + 1);
167.1457 -   png_write_chunk_data(png_ptr, (png_bytep)&spalette->depth, 1);
167.1458 -
167.1459 -   /* loop through each palette entry, writing appropriately */
167.1460 -#ifndef PNG_NO_POINTER_INDEXING
167.1461 -   for (ep = spalette->entries; ep<spalette->entries+spalette->nentries; ep++)
167.1462 -   {
167.1463 -       if (spalette->depth == 8)
167.1464 -       {
167.1465 -           entrybuf[0] = (png_byte)ep->red;
167.1466 -           entrybuf[1] = (png_byte)ep->green;
167.1467 -           entrybuf[2] = (png_byte)ep->blue;
167.1468 -           entrybuf[3] = (png_byte)ep->alpha;
167.1469 -           png_save_uint_16(entrybuf + 4, ep->frequency);
167.1470 -       }
167.1471 -       else
167.1472 -       {
167.1473 -           png_save_uint_16(entrybuf + 0, ep->red);
167.1474 -           png_save_uint_16(entrybuf + 2, ep->green);
167.1475 -           png_save_uint_16(entrybuf + 4, ep->blue);
167.1476 -           png_save_uint_16(entrybuf + 6, ep->alpha);
167.1477 -           png_save_uint_16(entrybuf + 8, ep->frequency);
167.1478 -       }
167.1479 -       png_write_chunk_data(png_ptr, entrybuf, (png_size_t)entry_size);
167.1480 +      if (spalette->depth == 8)
167.1481 +      {
167.1482 +         entrybuf[0] = (png_byte)ep->red;
167.1483 +         entrybuf[1] = (png_byte)ep->green;
167.1484 +         entrybuf[2] = (png_byte)ep->blue;
167.1485 +         entrybuf[3] = (png_byte)ep->alpha;
167.1486 +         png_save_uint_16(entrybuf + 4, ep->frequency);
167.1487 +      }
167.1488 +
167.1489 +      else
167.1490 +      {
167.1491 +         png_save_uint_16(entrybuf + 0, ep->red);
167.1492 +         png_save_uint_16(entrybuf + 2, ep->green);
167.1493 +         png_save_uint_16(entrybuf + 4, ep->blue);
167.1494 +         png_save_uint_16(entrybuf + 6, ep->alpha);
167.1495 +         png_save_uint_16(entrybuf + 8, ep->frequency);
167.1496 +      }
167.1497 +
167.1498 +      png_write_chunk_data(png_ptr, entrybuf, (png_size_t)entry_size);
167.1499     }
167.1500  #else
167.1501     ep=spalette->entries;
167.1502 -   for (i=0; i>spalette->nentries; i++)
167.1503 +   for (i = 0; i>spalette->nentries; i++)
167.1504     {
167.1505 -       if (spalette->depth == 8)
167.1506 -       {
167.1507 -           entrybuf[0] = (png_byte)ep[i].red;
167.1508 -           entrybuf[1] = (png_byte)ep[i].green;
167.1509 -           entrybuf[2] = (png_byte)ep[i].blue;
167.1510 -           entrybuf[3] = (png_byte)ep[i].alpha;
167.1511 -           png_save_uint_16(entrybuf + 4, ep[i].frequency);
167.1512 -       }
167.1513 -       else
167.1514 -       {
167.1515 -           png_save_uint_16(entrybuf + 0, ep[i].red);
167.1516 -           png_save_uint_16(entrybuf + 2, ep[i].green);
167.1517 -           png_save_uint_16(entrybuf + 4, ep[i].blue);
167.1518 -           png_save_uint_16(entrybuf + 6, ep[i].alpha);
167.1519 -           png_save_uint_16(entrybuf + 8, ep[i].frequency);
167.1520 -       }
167.1521 -       png_write_chunk_data(png_ptr, entrybuf, entry_size);
167.1522 +      if (spalette->depth == 8)
167.1523 +      {
167.1524 +         entrybuf[0] = (png_byte)ep[i].red;
167.1525 +         entrybuf[1] = (png_byte)ep[i].green;
167.1526 +         entrybuf[2] = (png_byte)ep[i].blue;
167.1527 +         entrybuf[3] = (png_byte)ep[i].alpha;
167.1528 +         png_save_uint_16(entrybuf + 4, ep[i].frequency);
167.1529 +      }
167.1530 +
167.1531 +      else
167.1532 +      {
167.1533 +         png_save_uint_16(entrybuf + 0, ep[i].red);
167.1534 +         png_save_uint_16(entrybuf + 2, ep[i].green);
167.1535 +         png_save_uint_16(entrybuf + 4, ep[i].blue);
167.1536 +         png_save_uint_16(entrybuf + 6, ep[i].alpha);
167.1537 +         png_save_uint_16(entrybuf + 8, ep[i].frequency);
167.1538 +      }
167.1539 +
167.1540 +      png_write_chunk_data(png_ptr, entrybuf, (png_size_t)entry_size);
167.1541     }
167.1542  #endif
167.1543  
167.1544 @@ -907,25 +1271,25 @@
167.1545  }
167.1546  #endif
167.1547  
167.1548 -#if defined(PNG_WRITE_sBIT_SUPPORTED)
167.1549 -/* write the sBIT chunk */
167.1550 +#ifdef PNG_WRITE_sBIT_SUPPORTED
167.1551 +/* Write the sBIT chunk */
167.1552  void /* PRIVATE */
167.1553 -png_write_sBIT(png_structp png_ptr, png_color_8p sbit, int color_type)
167.1554 +png_write_sBIT(png_structp png_ptr, png_const_color_8p sbit, int color_type)
167.1555  {
167.1556 -#ifdef PNG_USE_LOCAL_ARRAYS
167.1557     PNG_sBIT;
167.1558 -#endif
167.1559     png_byte buf[4];
167.1560     png_size_t size;
167.1561  
167.1562 -   png_debug(1, "in png_write_sBIT\n");
167.1563 -   /* make sure we don't depend upon the order of PNG_COLOR_8 */
167.1564 +   png_debug(1, "in png_write_sBIT");
167.1565 +
167.1566 +   /* Make sure we don't depend upon the order of PNG_COLOR_8 */
167.1567     if (color_type & PNG_COLOR_MASK_COLOR)
167.1568     {
167.1569        png_byte maxbits;
167.1570  
167.1571        maxbits = (png_byte)(color_type==PNG_COLOR_TYPE_PALETTE ? 8 :
167.1572 -                png_ptr->usr_bit_depth);
167.1573 +          png_ptr->usr_bit_depth);
167.1574 +
167.1575        if (sbit->red == 0 || sbit->red > maxbits ||
167.1576            sbit->green == 0 || sbit->green > maxbits ||
167.1577            sbit->blue == 0 || sbit->blue > maxbits)
167.1578 @@ -933,11 +1297,13 @@
167.1579           png_warning(png_ptr, "Invalid sBIT depth specified");
167.1580           return;
167.1581        }
167.1582 +
167.1583        buf[0] = sbit->red;
167.1584        buf[1] = sbit->green;
167.1585        buf[2] = sbit->blue;
167.1586        size = 3;
167.1587     }
167.1588 +
167.1589     else
167.1590     {
167.1591        if (sbit->gray == 0 || sbit->gray > png_ptr->usr_bit_depth)
167.1592 @@ -945,6 +1311,7 @@
167.1593           png_warning(png_ptr, "Invalid sBIT depth specified");
167.1594           return;
167.1595        }
167.1596 +
167.1597        buf[0] = sbit->gray;
167.1598        size = 1;
167.1599     }
167.1600 @@ -956,178 +1323,108 @@
167.1601           png_warning(png_ptr, "Invalid sBIT depth specified");
167.1602           return;
167.1603        }
167.1604 +
167.1605        buf[size++] = sbit->alpha;
167.1606     }
167.1607  
167.1608 -   png_write_chunk(png_ptr, (png_bytep)png_sBIT, buf, size);
167.1609 +   png_write_chunk(png_ptr, png_sBIT, buf, size);
167.1610  }
167.1611  #endif
167.1612  
167.1613 -#if defined(PNG_WRITE_cHRM_SUPPORTED)
167.1614 -/* write the cHRM chunk */
167.1615 -#ifdef PNG_FLOATING_POINT_SUPPORTED
167.1616 +#ifdef PNG_WRITE_cHRM_SUPPORTED
167.1617 +/* Write the cHRM chunk */
167.1618  void /* PRIVATE */
167.1619 -png_write_cHRM(png_structp png_ptr, double white_x, double white_y,
167.1620 -   double red_x, double red_y, double green_x, double green_y,
167.1621 -   double blue_x, double blue_y)
167.1622 +png_write_cHRM_fixed(png_structp png_ptr, png_fixed_point white_x,
167.1623 +    png_fixed_point white_y, png_fixed_point red_x, png_fixed_point red_y,
167.1624 +    png_fixed_point green_x, png_fixed_point green_y, png_fixed_point blue_x,
167.1625 +    png_fixed_point blue_y)
167.1626  {
167.1627 -#ifdef PNG_USE_LOCAL_ARRAYS
167.1628     PNG_cHRM;
167.1629 +   png_byte buf[32];
167.1630 +
167.1631 +   png_debug(1, "in png_write_cHRM");
167.1632 +
167.1633 +   /* Each value is saved in 1/100,000ths */
167.1634 +#ifdef PNG_CHECK_cHRM_SUPPORTED
167.1635 +   if (png_check_cHRM_fixed(png_ptr, white_x, white_y, red_x, red_y,
167.1636 +       green_x, green_y, blue_x, blue_y))
167.1637  #endif
167.1638 -   png_byte buf[32];
167.1639 -   png_uint_32 itemp;
167.1640 -
167.1641 -   png_debug(1, "in png_write_cHRM\n");
167.1642 -   /* each value is saved in 1/100,000ths */
167.1643 -   if (white_x < 0 || white_x > 0.8 || white_y < 0 || white_y > 0.8 ||
167.1644 -       white_x + white_y > 1.0)
167.1645     {
167.1646 -      png_warning(png_ptr, "Invalid cHRM white point specified");
167.1647 -#if !defined(PNG_NO_CONSOLE_IO)
167.1648 -      fprintf(stderr,"white_x=%f, white_y=%f\n",white_x, white_y);
167.1649 -#endif
167.1650 -      return;
167.1651 +      png_save_uint_32(buf, (png_uint_32)white_x);
167.1652 +      png_save_uint_32(buf + 4, (png_uint_32)white_y);
167.1653 +
167.1654 +      png_save_uint_32(buf + 8, (png_uint_32)red_x);
167.1655 +      png_save_uint_32(buf + 12, (png_uint_32)red_y);
167.1656 +
167.1657 +      png_save_uint_32(buf + 16, (png_uint_32)green_x);
167.1658 +      png_save_uint_32(buf + 20, (png_uint_32)green_y);
167.1659 +
167.1660 +      png_save_uint_32(buf + 24, (png_uint_32)blue_x);
167.1661 +      png_save_uint_32(buf + 28, (png_uint_32)blue_y);
167.1662 +
167.1663 +      png_write_chunk(png_ptr, png_cHRM, buf, (png_size_t)32);
167.1664     }
167.1665 -   itemp = (png_uint_32)(white_x * 100000.0 + 0.5);
167.1666 -   png_save_uint_32(buf, itemp);
167.1667 -   itemp = (png_uint_32)(white_y * 100000.0 + 0.5);
167.1668 -   png_save_uint_32(buf + 4, itemp);
167.1669 -
167.1670 -   if (red_x < 0 ||  red_y < 0 || red_x + red_y > 1.0)
167.1671 -   {
167.1672 -      png_warning(png_ptr, "Invalid cHRM red point specified");
167.1673 -      return;
167.1674 -   }
167.1675 -   itemp = (png_uint_32)(red_x * 100000.0 + 0.5);
167.1676 -   png_save_uint_32(buf + 8, itemp);
167.1677 -   itemp = (png_uint_32)(red_y * 100000.0 + 0.5);
167.1678 -   png_save_uint_32(buf + 12, itemp);
167.1679 -
167.1680 -   if (green_x < 0 || green_y < 0 || green_x + green_y > 1.0)
167.1681 -   {
167.1682 -      png_warning(png_ptr, "Invalid cHRM green point specified");
167.1683 -      return;
167.1684 -   }
167.1685 -   itemp = (png_uint_32)(green_x * 100000.0 + 0.5);
167.1686 -   png_save_uint_32(buf + 16, itemp);
167.1687 -   itemp = (png_uint_32)(green_y * 100000.0 + 0.5);
167.1688 -   png_save_uint_32(buf + 20, itemp);
167.1689 -
167.1690 -   if (blue_x < 0 || blue_y < 0 || blue_x + blue_y > 1.0)
167.1691 -   {
167.1692 -      png_warning(png_ptr, "Invalid cHRM blue point specified");
167.1693 -      return;
167.1694 -   }
167.1695 -   itemp = (png_uint_32)(blue_x * 100000.0 + 0.5);
167.1696 -   png_save_uint_32(buf + 24, itemp);
167.1697 -   itemp = (png_uint_32)(blue_y * 100000.0 + 0.5);
167.1698 -   png_save_uint_32(buf + 28, itemp);
167.1699 -
167.1700 -   png_write_chunk(png_ptr, (png_bytep)png_cHRM, buf, (png_size_t)32);
167.1701  }
167.1702  #endif
167.1703 -#ifdef PNG_FIXED_POINT_SUPPORTED
167.1704 +
167.1705 +#ifdef PNG_WRITE_tRNS_SUPPORTED
167.1706 +/* Write the tRNS chunk */
167.1707  void /* PRIVATE */
167.1708 -png_write_cHRM_fixed(png_structp png_ptr, png_fixed_point white_x,
167.1709 -   png_fixed_point white_y, png_fixed_point red_x, png_fixed_point red_y,
167.1710 -   png_fixed_point green_x, png_fixed_point green_y, png_fixed_point blue_x,
167.1711 -   png_fixed_point blue_y)
167.1712 +png_write_tRNS(png_structp png_ptr, png_const_bytep trans_alpha,
167.1713 +    png_const_color_16p tran, int num_trans, int color_type)
167.1714  {
167.1715 -#ifdef PNG_USE_LOCAL_ARRAYS
167.1716 -   PNG_cHRM;
167.1717 -#endif
167.1718 -   png_byte buf[32];
167.1719 -
167.1720 -   png_debug(1, "in png_write_cHRM\n");
167.1721 -   /* each value is saved in 1/100,000ths */
167.1722 -   if (white_x > 80000L || white_y > 80000L || white_x + white_y > 100000L)
167.1723 -   {
167.1724 -      png_warning(png_ptr, "Invalid fixed cHRM white point specified");
167.1725 -#if !defined(PNG_NO_CONSOLE_IO)
167.1726 -      fprintf(stderr,"white_x=%ld, white_y=%ld\n",white_x, white_y);
167.1727 -#endif
167.1728 -      return;
167.1729 -   }
167.1730 -   png_save_uint_32(buf, (png_uint_32)white_x);
167.1731 -   png_save_uint_32(buf + 4, (png_uint_32)white_y);
167.1732 -
167.1733 -   if (red_x + red_y > 100000L)
167.1734 -   {
167.1735 -      png_warning(png_ptr, "Invalid cHRM fixed red point specified");
167.1736 -      return;
167.1737 -   }
167.1738 -   png_save_uint_32(buf + 8, (png_uint_32)red_x);
167.1739 -   png_save_uint_32(buf + 12, (png_uint_32)red_y);
167.1740 -
167.1741 -   if (green_x + green_y > 100000L)
167.1742 -   {
167.1743 -      png_warning(png_ptr, "Invalid fixed cHRM green point specified");
167.1744 -      return;
167.1745 -   }
167.1746 -   png_save_uint_32(buf + 16, (png_uint_32)green_x);
167.1747 -   png_save_uint_32(buf + 20, (png_uint_32)green_y);
167.1748 -
167.1749 -   if (blue_x + blue_y > 100000L)
167.1750 -   {
167.1751 -      png_warning(png_ptr, "Invalid fixed cHRM blue point specified");
167.1752 -      return;
167.1753 -   }
167.1754 -   png_save_uint_32(buf + 24, (png_uint_32)blue_x);
167.1755 -   png_save_uint_32(buf + 28, (png_uint_32)blue_y);
167.1756 -
167.1757 -   png_write_chunk(png_ptr, (png_bytep)png_cHRM, buf, (png_size_t)32);
167.1758 -}
167.1759 -#endif
167.1760 -#endif
167.1761 -
167.1762 -#if defined(PNG_WRITE_tRNS_SUPPORTED)
167.1763 -/* write the tRNS chunk */
167.1764 -void /* PRIVATE */
167.1765 -png_write_tRNS(png_structp png_ptr, png_bytep trans, png_color_16p tran,
167.1766 -   int num_trans, int color_type)
167.1767 -{
167.1768 -#ifdef PNG_USE_LOCAL_ARRAYS
167.1769     PNG_tRNS;
167.1770 -#endif
167.1771     png_byte buf[6];
167.1772  
167.1773 -   png_debug(1, "in png_write_tRNS\n");
167.1774 +   png_debug(1, "in png_write_tRNS");
167.1775 +
167.1776     if (color_type == PNG_COLOR_TYPE_PALETTE)
167.1777     {
167.1778        if (num_trans <= 0 || num_trans > (int)png_ptr->num_palette)
167.1779        {
167.1780 -         png_warning(png_ptr,"Invalid number of transparent colors specified");
167.1781 +         png_warning(png_ptr, "Invalid number of transparent colors specified");
167.1782           return;
167.1783        }
167.1784 -      /* write the chunk out as it is */
167.1785 -      png_write_chunk(png_ptr, (png_bytep)png_tRNS, trans, (png_size_t)num_trans);
167.1786 +
167.1787 +      /* Write the chunk out as it is */
167.1788 +      png_write_chunk(png_ptr, png_tRNS, trans_alpha, (png_size_t)num_trans);
167.1789     }
167.1790 +
167.1791     else if (color_type == PNG_COLOR_TYPE_GRAY)
167.1792     {
167.1793 -      /* one 16 bit value */
167.1794 -      if(tran->gray >= (1 << png_ptr->bit_depth))
167.1795 +      /* One 16 bit value */
167.1796 +      if (tran->gray >= (1 << png_ptr->bit_depth))
167.1797        {
167.1798           png_warning(png_ptr,
167.1799 -           "Ignoring attempt to write tRNS chunk out-of-range for bit_depth");
167.1800 +             "Ignoring attempt to write tRNS chunk out-of-range for bit_depth");
167.1801 +
167.1802           return;
167.1803        }
167.1804 +
167.1805        png_save_uint_16(buf, tran->gray);
167.1806 -      png_write_chunk(png_ptr, (png_bytep)png_tRNS, buf, (png_size_t)2);
167.1807 +      png_write_chunk(png_ptr, png_tRNS, buf, (png_size_t)2);
167.1808     }
167.1809 +
167.1810     else if (color_type == PNG_COLOR_TYPE_RGB)
167.1811     {
167.1812 -      /* three 16 bit values */
167.1813 +      /* Three 16 bit values */
167.1814        png_save_uint_16(buf, tran->red);
167.1815        png_save_uint_16(buf + 2, tran->green);
167.1816        png_save_uint_16(buf + 4, tran->blue);
167.1817 -      if(png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
167.1818 -         {
167.1819 -            png_warning(png_ptr,
167.1820 -              "Ignoring attempt to write 16-bit tRNS chunk when bit_depth is 8");
167.1821 -            return;
167.1822 -         }
167.1823 -      png_write_chunk(png_ptr, (png_bytep)png_tRNS, buf, (png_size_t)6);
167.1824 +#ifdef PNG_WRITE_16BIT_SUPPORTED
167.1825 +      if (png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
167.1826 +#else
167.1827 +      if (buf[0] | buf[2] | buf[4])
167.1828 +#endif
167.1829 +      {
167.1830 +         png_warning(png_ptr,
167.1831 +           "Ignoring attempt to write 16-bit tRNS chunk when bit_depth is 8");
167.1832 +         return;
167.1833 +      }
167.1834 +
167.1835 +      png_write_chunk(png_ptr, png_tRNS, buf, (png_size_t)6);
167.1836     }
167.1837 +
167.1838     else
167.1839     {
167.1840        png_warning(png_ptr, "Can't write tRNS with an alpha channel");
167.1841 @@ -1135,85 +1432,97 @@
167.1842  }
167.1843  #endif
167.1844  
167.1845 -#if defined(PNG_WRITE_bKGD_SUPPORTED)
167.1846 -/* write the background chunk */
167.1847 +#ifdef PNG_WRITE_bKGD_SUPPORTED
167.1848 +/* Write the background chunk */
167.1849  void /* PRIVATE */
167.1850 -png_write_bKGD(png_structp png_ptr, png_color_16p back, int color_type)
167.1851 +png_write_bKGD(png_structp png_ptr, png_const_color_16p back, int color_type)
167.1852  {
167.1853 -#ifdef PNG_USE_LOCAL_ARRAYS
167.1854     PNG_bKGD;
167.1855 -#endif
167.1856     png_byte buf[6];
167.1857  
167.1858 -   png_debug(1, "in png_write_bKGD\n");
167.1859 +   png_debug(1, "in png_write_bKGD");
167.1860 +
167.1861     if (color_type == PNG_COLOR_TYPE_PALETTE)
167.1862     {
167.1863        if (
167.1864 -#if defined(PNG_MNG_FEATURES_SUPPORTED)
167.1865 +#ifdef PNG_MNG_FEATURES_SUPPORTED
167.1866            (png_ptr->num_palette ||
167.1867            (!(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE))) &&
167.1868  #endif
167.1869 -         back->index > png_ptr->num_palette)
167.1870 +         back->index >= png_ptr->num_palette)
167.1871        {
167.1872           png_warning(png_ptr, "Invalid background palette index");
167.1873           return;
167.1874        }
167.1875 +
167.1876        buf[0] = back->index;
167.1877 -      png_write_chunk(png_ptr, (png_bytep)png_bKGD, buf, (png_size_t)1);
167.1878 +      png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)1);
167.1879     }
167.1880 +
167.1881     else if (color_type & PNG_COLOR_MASK_COLOR)
167.1882     {
167.1883        png_save_uint_16(buf, back->red);
167.1884        png_save_uint_16(buf + 2, back->green);
167.1885        png_save_uint_16(buf + 4, back->blue);
167.1886 -      if(png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
167.1887 -         {
167.1888 -            png_warning(png_ptr,
167.1889 -              "Ignoring attempt to write 16-bit bKGD chunk when bit_depth is 8");
167.1890 -            return;
167.1891 -         }
167.1892 -      png_write_chunk(png_ptr, (png_bytep)png_bKGD, buf, (png_size_t)6);
167.1893 +#ifdef PNG_WRITE_16BIT_SUPPORTED
167.1894 +      if (png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
167.1895 +#else
167.1896 +      if (buf[0] | buf[2] | buf[4])
167.1897 +#endif
167.1898 +      {
167.1899 +         png_warning(png_ptr,
167.1900 +             "Ignoring attempt to write 16-bit bKGD chunk when bit_depth is 8");
167.1901 +
167.1902 +         return;
167.1903 +      }
167.1904 +
167.1905 +      png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)6);
167.1906     }
167.1907 +
167.1908     else
167.1909     {
167.1910 -      if(back->gray >= (1 << png_ptr->bit_depth))
167.1911 +      if (back->gray >= (1 << png_ptr->bit_depth))
167.1912        {
167.1913           png_warning(png_ptr,
167.1914 -           "Ignoring attempt to write bKGD chunk out-of-range for bit_depth");
167.1915 +             "Ignoring attempt to write bKGD chunk out-of-range for bit_depth");
167.1916 +
167.1917           return;
167.1918        }
167.1919 +
167.1920        png_save_uint_16(buf, back->gray);
167.1921 -      png_write_chunk(png_ptr, (png_bytep)png_bKGD, buf, (png_size_t)2);
167.1922 +      png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)2);
167.1923     }
167.1924  }
167.1925  #endif
167.1926  
167.1927 -#if defined(PNG_WRITE_hIST_SUPPORTED)
167.1928 -/* write the histogram */
167.1929 +#ifdef PNG_WRITE_hIST_SUPPORTED
167.1930 +/* Write the histogram */
167.1931  void /* PRIVATE */
167.1932 -png_write_hIST(png_structp png_ptr, png_uint_16p hist, int num_hist)
167.1933 +png_write_hIST(png_structp png_ptr, png_const_uint_16p hist, int num_hist)
167.1934  {
167.1935 -#ifdef PNG_USE_LOCAL_ARRAYS
167.1936     PNG_hIST;
167.1937 -#endif
167.1938     int i;
167.1939     png_byte buf[3];
167.1940  
167.1941 -   png_debug(1, "in png_write_hIST\n");
167.1942 +   png_debug(1, "in png_write_hIST");
167.1943 +
167.1944     if (num_hist > (int)png_ptr->num_palette)
167.1945     {
167.1946 -      png_debug2(3, "num_hist = %d, num_palette = %d\n", num_hist,
167.1947 -         png_ptr->num_palette);
167.1948 +      png_debug2(3, "num_hist = %d, num_palette = %d", num_hist,
167.1949 +          png_ptr->num_palette);
167.1950 +
167.1951        png_warning(png_ptr, "Invalid number of histogram entries specified");
167.1952        return;
167.1953     }
167.1954  
167.1955 -   png_write_chunk_start(png_ptr, (png_bytep)png_hIST, (png_uint_32)(num_hist * 2));
167.1956 +   png_write_chunk_start(png_ptr, png_hIST, (png_uint_32)(num_hist * 2));
167.1957 +
167.1958     for (i = 0; i < num_hist; i++)
167.1959     {
167.1960        png_save_uint_16(buf, hist[i]);
167.1961        png_write_chunk_data(png_ptr, buf, (png_size_t)2);
167.1962     }
167.1963 +
167.1964     png_write_chunk_end(png_ptr);
167.1965  }
167.1966  #endif
167.1967 @@ -1231,14 +1540,16 @@
167.1968   * static keywords without having to have duplicate copies of the strings.
167.1969   */
167.1970  png_size_t /* PRIVATE */
167.1971 -png_check_keyword(png_structp png_ptr, png_charp key, png_charpp new_key)
167.1972 +png_check_keyword(png_structp png_ptr, png_const_charp key, png_charpp new_key)
167.1973  {
167.1974     png_size_t key_len;
167.1975 +   png_const_charp ikp;
167.1976     png_charp kp, dp;
167.1977     int kflag;
167.1978     int kwarn=0;
167.1979  
167.1980 -   png_debug(1, "in png_check_keyword\n");
167.1981 +   png_debug(1, "in png_check_keyword");
167.1982 +
167.1983     *new_key = NULL;
167.1984  
167.1985     if (key == NULL || (key_len = png_strlen(key)) == 0)
167.1986 @@ -1247,9 +1558,10 @@
167.1987        return ((png_size_t)0);
167.1988     }
167.1989  
167.1990 -   png_debug1(2, "Keyword to be checked is '%s'\n", key);
167.1991 +   png_debug1(2, "Keyword to be checked is '%s'", key);
167.1992  
167.1993     *new_key = (png_charp)png_malloc_warn(png_ptr, (png_uint_32)(key_len + 2));
167.1994 +
167.1995     if (*new_key == NULL)
167.1996     {
167.1997        png_warning(png_ptr, "Out of memory while procesing keyword");
167.1998 @@ -1257,23 +1569,22 @@
167.1999     }
167.2000  
167.2001     /* Replace non-printing characters with a blank and print a warning */
167.2002 -   for (kp = key, dp = *new_key; *kp != '\0'; kp++, dp++)
167.2003 +   for (ikp = key, dp = *new_key; *ikp != '\0'; ikp++, dp++)
167.2004     {
167.2005 -      if (*kp < 0x20 || (*kp > 0x7E && (png_byte)*kp < 0xA1))
167.2006 +      if ((png_byte)*ikp < 0x20 ||
167.2007 +         ((png_byte)*ikp > 0x7E && (png_byte)*ikp < 0xA1))
167.2008        {
167.2009 -#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
167.2010 -         char msg[40];
167.2011 -
167.2012 -         sprintf(msg, "invalid keyword character 0x%02X", *kp);
167.2013 -         png_warning(png_ptr, msg);
167.2014 -#else
167.2015 -         png_warning(png_ptr, "invalid character in keyword");
167.2016 -#endif
167.2017 +         PNG_WARNING_PARAMETERS(p)
167.2018 +
167.2019 +         png_warning_parameter_unsigned(p, 1, PNG_NUMBER_FORMAT_02x,
167.2020 +            (png_byte)*ikp);
167.2021 +         png_formatted_warning(png_ptr, p, "invalid keyword character 0x@1");
167.2022           *dp = ' ';
167.2023        }
167.2024 +
167.2025        else
167.2026        {
167.2027 -         *dp = *kp;
167.2028 +         *dp = *ikp;
167.2029        }
167.2030     }
167.2031     *dp = '\0';
167.2032 @@ -1286,8 +1597,8 @@
167.2033  
167.2034        while (*kp == ' ')
167.2035        {
167.2036 -        *(kp--) = '\0';
167.2037 -        key_len--;
167.2038 +         *(kp--) = '\0';
167.2039 +         key_len--;
167.2040        }
167.2041     }
167.2042  
167.2043 @@ -1299,12 +1610,12 @@
167.2044  
167.2045        while (*kp == ' ')
167.2046        {
167.2047 -        kp++;
167.2048 -        key_len--;
167.2049 +         kp++;
167.2050 +         key_len--;
167.2051        }
167.2052     }
167.2053  
167.2054 -   png_debug1(2, "Checking for multiple internal spaces in '%s'\n", kp);
167.2055 +   png_debug1(2, "Checking for multiple internal spaces in '%s'", kp);
167.2056  
167.2057     /* Remove multiple internal spaces. */
167.2058     for (kflag = 0, dp = *new_key; *kp != '\0'; kp++)
167.2059 @@ -1314,11 +1625,13 @@
167.2060           *(dp++) = *kp;
167.2061           kflag = 1;
167.2062        }
167.2063 +
167.2064        else if (*kp == ' ')
167.2065        {
167.2066           key_len--;
167.2067 -         kwarn=1;
167.2068 +         kwarn = 1;
167.2069        }
167.2070 +
167.2071        else
167.2072        {
167.2073           *(dp++) = *kp;
167.2074 @@ -1326,20 +1639,19 @@
167.2075        }
167.2076     }
167.2077     *dp = '\0';
167.2078 -   if(kwarn)
167.2079 +   if (kwarn)
167.2080        png_warning(png_ptr, "extra interior spaces removed from keyword");
167.2081  
167.2082     if (key_len == 0)
167.2083     {
167.2084        png_free(png_ptr, *new_key);
167.2085 -      *new_key=NULL;
167.2086        png_warning(png_ptr, "Zero length keyword");
167.2087     }
167.2088  
167.2089     if (key_len > 79)
167.2090     {
167.2091        png_warning(png_ptr, "keyword length must be 1 - 79 characters");
167.2092 -      new_key[79] = '\0';
167.2093 +      (*new_key)[79] = '\0';
167.2094        key_len = 79;
167.2095     }
167.2096  
167.2097 @@ -1347,62 +1659,61 @@
167.2098  }
167.2099  #endif
167.2100  
167.2101 -#if defined(PNG_WRITE_tEXt_SUPPORTED)
167.2102 -/* write a tEXt chunk */
167.2103 +#ifdef PNG_WRITE_tEXt_SUPPORTED
167.2104 +/* Write a tEXt chunk */
167.2105  void /* PRIVATE */
167.2106 -png_write_tEXt(png_structp png_ptr, png_charp key, png_charp text,
167.2107 -   png_size_t text_len)
167.2108 +png_write_tEXt(png_structp png_ptr, png_const_charp key, png_const_charp text,
167.2109 +    png_size_t text_len)
167.2110  {
167.2111 -#ifdef PNG_USE_LOCAL_ARRAYS
167.2112     PNG_tEXt;
167.2113 -#endif
167.2114     png_size_t key_len;
167.2115     png_charp new_key;
167.2116  
167.2117 -   png_debug(1, "in png_write_tEXt\n");
167.2118 -   if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
167.2119 -   {
167.2120 -      png_warning(png_ptr, "Empty keyword in tEXt chunk");
167.2121 +   png_debug(1, "in png_write_tEXt");
167.2122 +
167.2123 +   if ((key_len = png_check_keyword(png_ptr, key, &new_key))==0)
167.2124        return;
167.2125 -   }
167.2126  
167.2127     if (text == NULL || *text == '\0')
167.2128        text_len = 0;
167.2129 +
167.2130     else
167.2131        text_len = png_strlen(text);
167.2132  
167.2133 -   /* make sure we include the 0 after the key */
167.2134 -   png_write_chunk_start(png_ptr, (png_bytep)png_tEXt, (png_uint_32)key_len+text_len+1);
167.2135 +   /* Make sure we include the 0 after the key */
167.2136 +   png_write_chunk_start(png_ptr, png_tEXt,
167.2137 +       (png_uint_32)(key_len + text_len + 1));
167.2138     /*
167.2139      * We leave it to the application to meet PNG-1.0 requirements on the
167.2140      * contents of the text.  PNG-1.0 through PNG-1.2 discourage the use of
167.2141      * any non-Latin-1 characters except for NEWLINE.  ISO PNG will forbid them.
167.2142      * The NUL character is forbidden by PNG-1.0 through PNG-1.2 and ISO PNG.
167.2143      */
167.2144 -   png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
167.2145 +   png_write_chunk_data(png_ptr, (png_bytep)new_key,
167.2146 +       (png_size_t)(key_len + 1));
167.2147 +
167.2148     if (text_len)
167.2149 -      png_write_chunk_data(png_ptr, (png_bytep)text, text_len);
167.2150 +      png_write_chunk_data(png_ptr, (png_const_bytep)text,
167.2151 +          (png_size_t)text_len);
167.2152  
167.2153     png_write_chunk_end(png_ptr);
167.2154     png_free(png_ptr, new_key);
167.2155  }
167.2156  #endif
167.2157  
167.2158 -#if defined(PNG_WRITE_zTXt_SUPPORTED)
167.2159 -/* write a compressed text chunk */
167.2160 +#ifdef PNG_WRITE_zTXt_SUPPORTED
167.2161 +/* Write a compressed text chunk */
167.2162  void /* PRIVATE */
167.2163 -png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,
167.2164 -   png_size_t text_len, int compression)
167.2165 +png_write_zTXt(png_structp png_ptr, png_const_charp key, png_const_charp text,
167.2166 +    png_size_t text_len, int compression)
167.2167  {
167.2168 -#ifdef PNG_USE_LOCAL_ARRAYS
167.2169     PNG_zTXt;
167.2170 -#endif
167.2171     png_size_t key_len;
167.2172 -   char buf[1];
167.2173 +   png_byte buf;
167.2174     png_charp new_key;
167.2175     compression_state comp;
167.2176  
167.2177 -   png_debug(1, "in png_write_zTXt\n");
167.2178 +   png_debug(1, "in png_write_zTXt");
167.2179  
167.2180     comp.num_output_ptr = 0;
167.2181     comp.max_output_ptr = 0;
167.2182 @@ -1410,9 +1721,9 @@
167.2183     comp.input = NULL;
167.2184     comp.input_len = 0;
167.2185  
167.2186 -   if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
167.2187 +   if ((key_len = png_check_keyword(png_ptr, key, &new_key)) == 0)
167.2188     {
167.2189 -      png_warning(png_ptr, "Empty keyword in zTXt chunk");
167.2190 +      png_free(png_ptr, new_key);
167.2191        return;
167.2192     }
167.2193  
167.2194 @@ -1425,55 +1736,58 @@
167.2195  
167.2196     text_len = png_strlen(text);
167.2197  
167.2198 -   png_free(png_ptr, new_key);
167.2199 -
167.2200 -   /* compute the compressed data; do it now for the length */
167.2201 +   /* Compute the compressed data; do it now for the length */
167.2202     text_len = png_text_compress(png_ptr, text, text_len, compression,
167.2203         &comp);
167.2204  
167.2205 -   /* write start of chunk */
167.2206 -   png_write_chunk_start(png_ptr, (png_bytep)png_zTXt, (png_uint_32)
167.2207 -      (key_len+text_len+2));
167.2208 -   /* write key */
167.2209 -   png_write_chunk_data(png_ptr, (png_bytep)key, key_len + 1);
167.2210 -   buf[0] = (png_byte)compression;
167.2211 -   /* write compression */
167.2212 -   png_write_chunk_data(png_ptr, (png_bytep)buf, (png_size_t)1);
167.2213 -   /* write the compressed data */
167.2214 +   /* Write start of chunk */
167.2215 +   png_write_chunk_start(png_ptr, png_zTXt,
167.2216 +       (png_uint_32)(key_len+text_len + 2));
167.2217 +
167.2218 +   /* Write key */
167.2219 +   png_write_chunk_data(png_ptr, (png_bytep)new_key,
167.2220 +       (png_size_t)(key_len + 1));
167.2221 +
167.2222 +   png_free(png_ptr, new_key);
167.2223 +
167.2224 +   buf = (png_byte)compression;
167.2225 +
167.2226 +   /* Write compression */
167.2227 +   png_write_chunk_data(png_ptr, &buf, (png_size_t)1);
167.2228 +
167.2229 +   /* Write the compressed data */
167.2230 +   comp.input_len = text_len;
167.2231     png_write_compressed_data_out(png_ptr, &comp);
167.2232  
167.2233 -   /* close the chunk */
167.2234 +   /* Close the chunk */
167.2235     png_write_chunk_end(png_ptr);
167.2236  }
167.2237  #endif
167.2238  
167.2239 -#if defined(PNG_WRITE_iTXt_SUPPORTED)
167.2240 -/* write an iTXt chunk */
167.2241 +#ifdef PNG_WRITE_iTXt_SUPPORTED
167.2242 +/* Write an iTXt chunk */
167.2243  void /* PRIVATE */
167.2244 -png_write_iTXt(png_structp png_ptr, int compression, png_charp key,
167.2245 -    png_charp lang, png_charp lang_key, png_charp text)
167.2246 +png_write_iTXt(png_structp png_ptr, int compression, png_const_charp key,
167.2247 +    png_const_charp lang, png_const_charp lang_key, png_const_charp text)
167.2248  {
167.2249 -#ifdef PNG_USE_LOCAL_ARRAYS
167.2250     PNG_iTXt;
167.2251 -#endif
167.2252     png_size_t lang_len, key_len, lang_key_len, text_len;
167.2253 -   png_charp new_lang, new_key;
167.2254 +   png_charp new_lang;
167.2255 +   png_charp new_key = NULL;
167.2256     png_byte cbuf[2];
167.2257     compression_state comp;
167.2258  
167.2259 -   png_debug(1, "in png_write_iTXt\n");
167.2260 +   png_debug(1, "in png_write_iTXt");
167.2261  
167.2262     comp.num_output_ptr = 0;
167.2263     comp.max_output_ptr = 0;
167.2264     comp.output_ptr = NULL;
167.2265     comp.input = NULL;
167.2266  
167.2267 -   if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
167.2268 -   {
167.2269 -      png_warning(png_ptr, "Empty keyword in iTXt chunk");
167.2270 +   if ((key_len = png_check_keyword(png_ptr, key, &new_key)) == 0)
167.2271        return;
167.2272 -   }
167.2273 -   if (lang == NULL || (lang_len = png_check_keyword(png_ptr, lang, &new_lang))==0)
167.2274 +
167.2275 +   if ((lang_len = png_check_keyword(png_ptr, lang, &new_lang)) == 0)
167.2276     {
167.2277        png_warning(png_ptr, "Empty language field in iTXt chunk");
167.2278        new_lang = NULL;
167.2279 @@ -1481,73 +1795,80 @@
167.2280     }
167.2281  
167.2282     if (lang_key == NULL)
167.2283 -     lang_key_len = 0;
167.2284 +      lang_key_len = 0;
167.2285 +
167.2286     else
167.2287 -     lang_key_len = png_strlen(lang_key);
167.2288 +      lang_key_len = png_strlen(lang_key);
167.2289  
167.2290     if (text == NULL)
167.2291        text_len = 0;
167.2292 +
167.2293     else
167.2294 -     text_len = png_strlen(text);
167.2295 -
167.2296 -   /* compute the compressed data; do it now for the length */
167.2297 -   text_len = png_text_compress(png_ptr, text, text_len, compression-2,
167.2298 -      &comp);
167.2299 -
167.2300 -
167.2301 -   /* make sure we include the compression flag, the compression byte,
167.2302 -    * and the NULs after the key, lang, and lang_key parts */
167.2303 -
167.2304 -   png_write_chunk_start(png_ptr, (png_bytep)png_iTXt,
167.2305 -          (png_uint_32)(
167.2306 +      text_len = png_strlen(text);
167.2307 +
167.2308 +   /* Compute the compressed data; do it now for the length */
167.2309 +   text_len = png_text_compress(png_ptr, text, text_len, compression - 2,
167.2310 +       &comp);
167.2311 +
167.2312 +
167.2313 +   /* Make sure we include the compression flag, the compression byte,
167.2314 +    * and the NULs after the key, lang, and lang_key parts
167.2315 +    */
167.2316 +
167.2317 +   png_write_chunk_start(png_ptr, png_iTXt, (png_uint_32)(
167.2318          5 /* comp byte, comp flag, terminators for key, lang and lang_key */
167.2319          + key_len
167.2320          + lang_len
167.2321          + lang_key_len
167.2322          + text_len));
167.2323  
167.2324 -   /*
167.2325 -    * We leave it to the application to meet PNG-1.0 requirements on the
167.2326 +   /* We leave it to the application to meet PNG-1.0 requirements on the
167.2327      * contents of the text.  PNG-1.0 through PNG-1.2 discourage the use of
167.2328      * any non-Latin-1 characters except for NEWLINE.  ISO PNG will forbid them.
167.2329      * The NUL character is forbidden by PNG-1.0 through PNG-1.2 and ISO PNG.
167.2330      */
167.2331 -   png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
167.2332 -
167.2333 -   /* set the compression flag */
167.2334 -   if (compression == PNG_ITXT_COMPRESSION_NONE || \
167.2335 +   png_write_chunk_data(png_ptr, (png_bytep)new_key, (png_size_t)(key_len + 1));
167.2336 +
167.2337 +   /* Set the compression flag */
167.2338 +   if (compression == PNG_ITXT_COMPRESSION_NONE ||
167.2339         compression == PNG_TEXT_COMPRESSION_NONE)
167.2340 -       cbuf[0] = 0;
167.2341 +      cbuf[0] = 0;
167.2342 +
167.2343     else /* compression == PNG_ITXT_COMPRESSION_zTXt */
167.2344 -       cbuf[0] = 1;
167.2345 -   /* set the compression method */
167.2346 +      cbuf[0] = 1;
167.2347 +
167.2348 +   /* Set the compression method */
167.2349     cbuf[1] = 0;
167.2350 -   png_write_chunk_data(png_ptr, cbuf, 2);
167.2351 +
167.2352 +   png_write_chunk_data(png_ptr, cbuf, (png_size_t)2);
167.2353  
167.2354     cbuf[0] = 0;
167.2355 -   png_write_chunk_data(png_ptr, (new_lang ? (png_bytep)new_lang : cbuf), lang_len + 1);
167.2356 -   png_write_chunk_data(png_ptr, (lang_key ? (png_bytep)lang_key : cbuf), lang_key_len + 1);
167.2357 +   png_write_chunk_data(png_ptr, (new_lang ? (png_const_bytep)new_lang : cbuf),
167.2358 +       (png_size_t)(lang_len + 1));
167.2359 +
167.2360 +   png_write_chunk_data(png_ptr, (lang_key ? (png_const_bytep)lang_key : cbuf),
167.2361 +       (png_size_t)(lang_key_len + 1));
167.2362 +
167.2363     png_write_compressed_data_out(png_ptr, &comp);
167.2364  
167.2365     png_write_chunk_end(png_ptr);
167.2366 +
167.2367     png_free(png_ptr, new_key);
167.2368 -   if (new_lang)
167.2369 -     png_free(png_ptr, new_lang);
167.2370 +   png_free(png_ptr, new_lang);
167.2371  }
167.2372  #endif
167.2373  
167.2374 -#if defined(PNG_WRITE_oFFs_SUPPORTED)
167.2375 -/* write the oFFs chunk */
167.2376 +#ifdef PNG_WRITE_oFFs_SUPPORTED
167.2377 +/* Write the oFFs chunk */
167.2378  void /* PRIVATE */
167.2379  png_write_oFFs(png_structp png_ptr, png_int_32 x_offset, png_int_32 y_offset,
167.2380 -   int unit_type)
167.2381 +    int unit_type)
167.2382  {
167.2383 -#ifdef PNG_USE_LOCAL_ARRAYS
167.2384     PNG_oFFs;
167.2385 -#endif
167.2386     png_byte buf[9];
167.2387  
167.2388 -   png_debug(1, "in png_write_oFFs\n");
167.2389 +   png_debug(1, "in png_write_oFFs");
167.2390 +
167.2391     if (unit_type >= PNG_OFFSET_LAST)
167.2392        png_warning(png_ptr, "Unrecognized unit type for oFFs chunk");
167.2393  
167.2394 @@ -1555,63 +1876,65 @@
167.2395     png_save_int_32(buf + 4, y_offset);
167.2396     buf[8] = (png_byte)unit_type;
167.2397  
167.2398 -   png_write_chunk(png_ptr, (png_bytep)png_oFFs, buf, (png_size_t)9);
167.2399 +   png_write_chunk(png_ptr, png_oFFs, buf, (png_size_t)9);
167.2400  }
167.2401  #endif
167.2402 -
167.2403 -#if defined(PNG_WRITE_pCAL_SUPPORTED)
167.2404 -/* write the pCAL chunk (described in the PNG extensions document) */
167.2405 +#ifdef PNG_WRITE_pCAL_SUPPORTED
167.2406 +/* Write the pCAL chunk (described in the PNG extensions document) */
167.2407  void /* PRIVATE */
167.2408  png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0,
167.2409 -   png_int_32 X1, int type, int nparams, png_charp units, png_charpp params)
167.2410 +    png_int_32 X1, int type, int nparams, png_const_charp units,
167.2411 +    png_charpp params)
167.2412  {
167.2413 -#ifdef PNG_USE_LOCAL_ARRAYS
167.2414     PNG_pCAL;
167.2415 -#endif
167.2416     png_size_t purpose_len, units_len, total_len;
167.2417     png_uint_32p params_len;
167.2418     png_byte buf[10];
167.2419     png_charp new_purpose;
167.2420     int i;
167.2421  
167.2422 -   png_debug1(1, "in png_write_pCAL (%d parameters)\n", nparams);
167.2423 +   png_debug1(1, "in png_write_pCAL (%d parameters)", nparams);
167.2424 +
167.2425     if (type >= PNG_EQUATION_LAST)
167.2426        png_warning(png_ptr, "Unrecognized equation type for pCAL chunk");
167.2427  
167.2428     purpose_len = png_check_keyword(png_ptr, purpose, &new_purpose) + 1;
167.2429 -   png_debug1(3, "pCAL purpose length = %d\n", (int)purpose_len);
167.2430 +   png_debug1(3, "pCAL purpose length = %d", (int)purpose_len);
167.2431     units_len = png_strlen(units) + (nparams == 0 ? 0 : 1);
167.2432 -   png_debug1(3, "pCAL units length = %d\n", (int)units_len);
167.2433 +   png_debug1(3, "pCAL units length = %d", (int)units_len);
167.2434     total_len = purpose_len + units_len + 10;
167.2435  
167.2436 -   params_len = (png_uint_32p)png_malloc(png_ptr, (png_uint_32)(nparams
167.2437 -      *png_sizeof(png_uint_32)));
167.2438 +   params_len = (png_uint_32p)png_malloc(png_ptr,
167.2439 +       (png_alloc_size_t)(nparams * png_sizeof(png_uint_32)));
167.2440  
167.2441     /* Find the length of each parameter, making sure we don't count the
167.2442 -      null terminator for the last parameter. */
167.2443 +    * null terminator for the last parameter.
167.2444 +    */
167.2445     for (i = 0; i < nparams; i++)
167.2446     {
167.2447        params_len[i] = png_strlen(params[i]) + (i == nparams - 1 ? 0 : 1);
167.2448 -      png_debug2(3, "pCAL parameter %d length = %lu\n", i, params_len[i]);
167.2449 +      png_debug2(3, "pCAL parameter %d length = %lu", i,
167.2450 +          (unsigned long)params_len[i]);
167.2451        total_len += (png_size_t)params_len[i];
167.2452     }
167.2453  
167.2454 -   png_debug1(3, "pCAL total length = %d\n", (int)total_len);
167.2455 -   png_write_chunk_start(png_ptr, (png_bytep)png_pCAL, (png_uint_32)total_len);
167.2456 -   png_write_chunk_data(png_ptr, (png_bytep)new_purpose, purpose_len);
167.2457 +   png_debug1(3, "pCAL total length = %d", (int)total_len);
167.2458 +   png_write_chunk_start(png_ptr, png_pCAL, (png_uint_32)total_len);
167.2459 +   png_write_chunk_data(png_ptr, (png_const_bytep)new_purpose,
167.2460 +       (png_size_t)purpose_len);
167.2461     png_save_int_32(buf, X0);
167.2462     png_save_int_32(buf + 4, X1);
167.2463     buf[8] = (png_byte)type;
167.2464     buf[9] = (png_byte)nparams;
167.2465     png_write_chunk_data(png_ptr, buf, (png_size_t)10);
167.2466 -   png_write_chunk_data(png_ptr, (png_bytep)units, (png_size_t)units_len);
167.2467 +   png_write_chunk_data(png_ptr, (png_const_bytep)units, (png_size_t)units_len);
167.2468  
167.2469     png_free(png_ptr, new_purpose);
167.2470  
167.2471     for (i = 0; i < nparams; i++)
167.2472     {
167.2473 -      png_write_chunk_data(png_ptr, (png_bytep)params[i],
167.2474 -         (png_size_t)params_len[i]);
167.2475 +      png_write_chunk_data(png_ptr, (png_const_bytep)params[i],
167.2476 +          (png_size_t)params_len[i]);
167.2477     }
167.2478  
167.2479     png_free(png_ptr, params_len);
167.2480 @@ -1619,63 +1942,22 @@
167.2481  }
167.2482  #endif
167.2483  
167.2484 -#if defined(PNG_WRITE_sCAL_SUPPORTED)
167.2485 -/* write the sCAL chunk */
167.2486 -#if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
167.2487 +#ifdef PNG_WRITE_sCAL_SUPPORTED
167.2488 +/* Write the sCAL chunk */
167.2489  void /* PRIVATE */
167.2490 -png_write_sCAL(png_structp png_ptr, int unit, double width, double height)
167.2491 +png_write_sCAL_s(png_structp png_ptr, int unit, png_const_charp width,
167.2492 +    png_const_charp height)
167.2493  {
167.2494 -#ifdef PNG_USE_LOCAL_ARRAYS
167.2495     PNG_sCAL;
167.2496 -#endif
167.2497 -   char buf[64];
167.2498 -   png_size_t total_len;
167.2499 -
167.2500 -   png_debug(1, "in png_write_sCAL\n");
167.2501 -
167.2502 -   buf[0] = (char)unit;
167.2503 -#if defined(_WIN32_WCE)
167.2504 -/* sprintf() function is not supported on WindowsCE */
167.2505 -   {
167.2506 -      wchar_t wc_buf[32];
167.2507 -      size_t wc_len;
167.2508 -      swprintf(wc_buf, TEXT("%12.12e"), width);
167.2509 -      wc_len = wcslen(wc_buf);
167.2510 -      WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + 1, wc_len, NULL, NULL);
167.2511 -      total_len = wc_len + 2;
167.2512 -      swprintf(wc_buf, TEXT("%12.12e"), height);
167.2513 -      wc_len = wcslen(wc_buf);
167.2514 -      WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + total_len, wc_len,
167.2515 -         NULL, NULL);
167.2516 -      total_len += wc_len;
167.2517 -   }
167.2518 -#else
167.2519 -   sprintf(buf + 1, "%12.12e", width);
167.2520 -   total_len = 1 + png_strlen(buf + 1) + 1;
167.2521 -   sprintf(buf + total_len, "%12.12e", height);
167.2522 -   total_len += png_strlen(buf + total_len);
167.2523 -#endif
167.2524 -
167.2525 -   png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len);
167.2526 -   png_write_chunk(png_ptr, (png_bytep)png_sCAL, (png_bytep)buf, total_len);
167.2527 -}
167.2528 -#else
167.2529 -#ifdef PNG_FIXED_POINT_SUPPORTED
167.2530 -void /* PRIVATE */
167.2531 -png_write_sCAL_s(png_structp png_ptr, int unit, png_charp width,
167.2532 -   png_charp height)
167.2533 -{
167.2534 -#ifdef PNG_USE_LOCAL_ARRAYS
167.2535 -   PNG_sCAL;
167.2536 -#endif
167.2537     png_byte buf[64];
167.2538     png_size_t wlen, hlen, total_len;
167.2539  
167.2540 -   png_debug(1, "in png_write_sCAL_s\n");
167.2541 +   png_debug(1, "in png_write_sCAL_s");
167.2542  
167.2543     wlen = png_strlen(width);
167.2544     hlen = png_strlen(height);
167.2545     total_len = wlen + hlen + 2;
167.2546 +
167.2547     if (total_len > 64)
167.2548     {
167.2549        png_warning(png_ptr, "Can't write sCAL (buffer too small)");
167.2550 @@ -1683,29 +1965,26 @@
167.2551     }
167.2552  
167.2553     buf[0] = (png_byte)unit;
167.2554 -   png_memcpy(buf + 1, width, wlen + 1);      /* append the '\0' here */
167.2555 -   png_memcpy(buf + wlen + 2, height, hlen);  /* do NOT append the '\0' here */
167.2556 -
167.2557 -   png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len);
167.2558 -   png_write_chunk(png_ptr, (png_bytep)png_sCAL, buf, total_len);
167.2559 +   png_memcpy(buf + 1, width, wlen + 1);      /* Append the '\0' here */
167.2560 +   png_memcpy(buf + wlen + 2, height, hlen);  /* Do NOT append the '\0' here */
167.2561 +
167.2562 +   png_debug1(3, "sCAL total length = %u", (unsigned int)total_len);
167.2563 +   png_write_chunk(png_ptr, png_sCAL, buf, total_len);
167.2564  }
167.2565  #endif
167.2566 -#endif
167.2567 -#endif
167.2568 -
167.2569 -#if defined(PNG_WRITE_pHYs_SUPPORTED)
167.2570 -/* write the pHYs chunk */
167.2571 +
167.2572 +#ifdef PNG_WRITE_pHYs_SUPPORTED
167.2573 +/* Write the pHYs chunk */
167.2574  void /* PRIVATE */
167.2575  png_write_pHYs(png_structp png_ptr, png_uint_32 x_pixels_per_unit,
167.2576 -   png_uint_32 y_pixels_per_unit,
167.2577 -   int unit_type)
167.2578 +    png_uint_32 y_pixels_per_unit,
167.2579 +    int unit_type)
167.2580  {
167.2581 -#ifdef PNG_USE_LOCAL_ARRAYS
167.2582     PNG_pHYs;
167.2583 -#endif
167.2584     png_byte buf[9];
167.2585  
167.2586 -   png_debug(1, "in png_write_pHYs\n");
167.2587 +   png_debug(1, "in png_write_pHYs");
167.2588 +
167.2589     if (unit_type >= PNG_RESOLUTION_LAST)
167.2590        png_warning(png_ptr, "Unrecognized unit type for pHYs chunk");
167.2591  
167.2592 @@ -1713,23 +1992,22 @@
167.2593     png_save_uint_32(buf + 4, y_pixels_per_unit);
167.2594     buf[8] = (png_byte)unit_type;
167.2595  
167.2596 -   png_write_chunk(png_ptr, (png_bytep)png_pHYs, buf, (png_size_t)9);
167.2597 +   png_write_chunk(png_ptr, png_pHYs, buf, (png_size_t)9);
167.2598  }
167.2599  #endif
167.2600  
167.2601 -#if defined(PNG_WRITE_tIME_SUPPORTED)
167.2602 +#ifdef PNG_WRITE_tIME_SUPPORTED
167.2603  /* Write the tIME chunk.  Use either png_convert_from_struct_tm()
167.2604   * or png_convert_from_time_t(), or fill in the structure yourself.
167.2605   */
167.2606  void /* PRIVATE */
167.2607 -png_write_tIME(png_structp png_ptr, png_timep mod_time)
167.2608 +png_write_tIME(png_structp png_ptr, png_const_timep mod_time)
167.2609  {
167.2610 -#ifdef PNG_USE_LOCAL_ARRAYS
167.2611     PNG_tIME;
167.2612 -#endif
167.2613     png_byte buf[7];
167.2614  
167.2615 -   png_debug(1, "in png_write_tIME\n");
167.2616 +   png_debug(1, "in png_write_tIME");
167.2617 +
167.2618     if (mod_time->month  > 12 || mod_time->month  < 1 ||
167.2619         mod_time->day    > 31 || mod_time->day    < 1 ||
167.2620         mod_time->hour   > 23 || mod_time->second > 60)
167.2621 @@ -1745,100 +2023,113 @@
167.2622     buf[5] = mod_time->minute;
167.2623     buf[6] = mod_time->second;
167.2624  
167.2625 -   png_write_chunk(png_ptr, (png_bytep)png_tIME, buf, (png_size_t)7);
167.2626 +   png_write_chunk(png_ptr, png_tIME, buf, (png_size_t)7);
167.2627  }
167.2628  #endif
167.2629  
167.2630 -/* initializes the row writing capability of libpng */
167.2631 +/* Initializes the row writing capability of libpng */
167.2632  void /* PRIVATE */
167.2633  png_write_start_row(png_structp png_ptr)
167.2634  {
167.2635 -#ifdef PNG_USE_LOCAL_ARRAYS
167.2636 -   /* arrays to facilitate easy interlacing - use pass (0 - 6) as index */
167.2637 -
167.2638 -   /* start of interlace block */
167.2639 +#ifdef PNG_WRITE_INTERLACING_SUPPORTED
167.2640 +   /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
167.2641 +
167.2642 +   /* Start of interlace block */
167.2643     int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
167.2644  
167.2645 -   /* offset to next interlace block */
167.2646 +   /* Offset to next interlace block */
167.2647     int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
167.2648  
167.2649 -   /* start of interlace block in the y direction */
167.2650 +   /* Start of interlace block in the y direction */
167.2651     int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
167.2652  
167.2653 -   /* offset to next interlace block in the y direction */
167.2654 +   /* Offset to next interlace block in the y direction */
167.2655     int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
167.2656  #endif
167.2657  
167.2658     png_size_t buf_size;
167.2659  
167.2660 -   png_debug(1, "in png_write_start_row\n");
167.2661 +   png_debug(1, "in png_write_start_row");
167.2662 +
167.2663     buf_size = (png_size_t)(PNG_ROWBYTES(
167.2664 -      png_ptr->usr_channels*png_ptr->usr_bit_depth,png_ptr->width)+1);
167.2665 -
167.2666 -   /* set up row buffer */
167.2667 -   png_ptr->row_buf = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size);
167.2668 +       png_ptr->usr_channels*png_ptr->usr_bit_depth, png_ptr->width) + 1);
167.2669 +
167.2670 +   /* Set up row buffer */
167.2671 +   png_ptr->row_buf = (png_bytep)png_malloc(png_ptr,
167.2672 +       (png_alloc_size_t)buf_size);
167.2673 +
167.2674     png_ptr->row_buf[0] = PNG_FILTER_VALUE_NONE;
167.2675  
167.2676 -   /* set up filtering buffer, if using this filter */
167.2677 +#ifdef PNG_WRITE_FILTER_SUPPORTED
167.2678 +   /* Set up filtering buffer, if using this filter */
167.2679     if (png_ptr->do_filter & PNG_FILTER_SUB)
167.2680     {
167.2681 -      png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
167.2682 -         (png_ptr->rowbytes + 1));
167.2683 +      png_ptr->sub_row = (png_bytep)png_malloc(png_ptr, png_ptr->rowbytes + 1);
167.2684 +
167.2685        png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
167.2686     }
167.2687  
167.2688     /* We only need to keep the previous row if we are using one of these. */
167.2689     if (png_ptr->do_filter & (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH))
167.2690     {
167.2691 -     /* set up previous row buffer */
167.2692 -      png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size);
167.2693 -      png_memset(png_ptr->prev_row, 0, buf_size);
167.2694 +      /* Set up previous row buffer */
167.2695 +      png_ptr->prev_row = (png_bytep)png_calloc(png_ptr,
167.2696 +          (png_alloc_size_t)buf_size);
167.2697  
167.2698        if (png_ptr->do_filter & PNG_FILTER_UP)
167.2699        {
167.2700 -         png_ptr->up_row = (png_bytep )png_malloc(png_ptr,
167.2701 -            (png_ptr->rowbytes + 1));
167.2702 +         png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
167.2703 +            png_ptr->rowbytes + 1);
167.2704 +
167.2705           png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
167.2706        }
167.2707  
167.2708        if (png_ptr->do_filter & PNG_FILTER_AVG)
167.2709        {
167.2710           png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
167.2711 -            (png_ptr->rowbytes + 1));
167.2712 +             png_ptr->rowbytes + 1);
167.2713 +
167.2714           png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
167.2715        }
167.2716  
167.2717        if (png_ptr->do_filter & PNG_FILTER_PAETH)
167.2718        {
167.2719 -         png_ptr->paeth_row = (png_bytep )png_malloc(png_ptr,
167.2720 -            (png_ptr->rowbytes + 1));
167.2721 +         png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
167.2722 +             png_ptr->rowbytes + 1);
167.2723 +
167.2724           png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
167.2725        }
167.2726     }
167.2727 +#endif /* PNG_WRITE_FILTER_SUPPORTED */
167.2728  
167.2729  #ifdef PNG_WRITE_INTERLACING_SUPPORTED
167.2730 -   /* if interlaced, we need to set up width and height of pass */
167.2731 +   /* If interlaced, we need to set up width and height of pass */
167.2732     if (png_ptr->interlaced)
167.2733     {
167.2734        if (!(png_ptr->transformations & PNG_INTERLACE))
167.2735        {
167.2736           png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
167.2737 -            png_pass_ystart[0]) / png_pass_yinc[0];
167.2738 +             png_pass_ystart[0]) / png_pass_yinc[0];
167.2739 +
167.2740           png_ptr->usr_width = (png_ptr->width + png_pass_inc[0] - 1 -
167.2741 -            png_pass_start[0]) / png_pass_inc[0];
167.2742 +             png_pass_start[0]) / png_pass_inc[0];
167.2743        }
167.2744 +
167.2745        else
167.2746        {
167.2747           png_ptr->num_rows = png_ptr->height;
167.2748           png_ptr->usr_width = png_ptr->width;
167.2749        }
167.2750     }
167.2751 +
167.2752     else
167.2753  #endif
167.2754     {
167.2755        png_ptr->num_rows = png_ptr->height;
167.2756        png_ptr->usr_width = png_ptr->width;
167.2757     }
167.2758 +
167.2759 +   png_zlib_claim(png_ptr, PNG_ZLIB_FOR_IDAT);
167.2760     png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
167.2761     png_ptr->zstream.next_out = png_ptr->zbuf;
167.2762  }
167.2763 @@ -1847,34 +2138,35 @@
167.2764  void /* PRIVATE */
167.2765  png_write_finish_row(png_structp png_ptr)
167.2766  {
167.2767 -#ifdef PNG_USE_LOCAL_ARRAYS
167.2768 -   /* arrays to facilitate easy interlacing - use pass (0 - 6) as index */
167.2769 -
167.2770 -   /* start of interlace block */
167.2771 +#ifdef PNG_WRITE_INTERLACING_SUPPORTED
167.2772 +   /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
167.2773 +
167.2774 +   /* Start of interlace block */
167.2775     int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
167.2776  
167.2777 -   /* offset to next interlace block */
167.2778 +   /* Offset to next interlace block */
167.2779     int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
167.2780  
167.2781 -   /* start of interlace block in the y direction */
167.2782 +   /* Start of interlace block in the y direction */
167.2783     int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
167.2784  
167.2785 -   /* offset to next interlace block in the y direction */
167.2786 +   /* Offset to next interlace block in the y direction */
167.2787     int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
167.2788  #endif
167.2789  
167.2790     int ret;
167.2791  
167.2792 -   png_debug(1, "in png_write_finish_row\n");
167.2793 -   /* next row */
167.2794 +   png_debug(1, "in png_write_finish_row");
167.2795 +
167.2796 +   /* Next row */
167.2797     png_ptr->row_number++;
167.2798  
167.2799 -   /* see if we are done */
167.2800 +   /* See if we are done */
167.2801     if (png_ptr->row_number < png_ptr->num_rows)
167.2802        return;
167.2803  
167.2804  #ifdef PNG_WRITE_INTERLACING_SUPPORTED
167.2805 -   /* if interlaced, go to next pass */
167.2806 +   /* If interlaced, go to next pass */
167.2807     if (png_ptr->interlaced)
167.2808     {
167.2809        png_ptr->row_number = 0;
167.2810 @@ -1882,50 +2174,58 @@
167.2811        {
167.2812           png_ptr->pass++;
167.2813        }
167.2814 +
167.2815        else
167.2816        {
167.2817 -         /* loop until we find a non-zero width or height pass */
167.2818 +         /* Loop until we find a non-zero width or height pass */
167.2819           do
167.2820           {
167.2821              png_ptr->pass++;
167.2822 +
167.2823              if (png_ptr->pass >= 7)
167.2824                 break;
167.2825 +
167.2826              png_ptr->usr_width = (png_ptr->width +
167.2827 -               png_pass_inc[png_ptr->pass] - 1 -
167.2828 -               png_pass_start[png_ptr->pass]) /
167.2829 -               png_pass_inc[png_ptr->pass];
167.2830 +                png_pass_inc[png_ptr->pass] - 1 -
167.2831 +                png_pass_start[png_ptr->pass]) /
167.2832 +                png_pass_inc[png_ptr->pass];
167.2833 +
167.2834              png_ptr->num_rows = (png_ptr->height +
167.2835 -               png_pass_yinc[png_ptr->pass] - 1 -
167.2836 -               png_pass_ystart[png_ptr->pass]) /
167.2837 -               png_pass_yinc[png_ptr->pass];
167.2838 +                png_pass_yinc[png_ptr->pass] - 1 -
167.2839 +                png_pass_ystart[png_ptr->pass]) /
167.2840 +                png_pass_yinc[png_ptr->pass];
167.2841 +
167.2842              if (png_ptr->transformations & PNG_INTERLACE)
167.2843                 break;
167.2844 +
167.2845           } while (png_ptr->usr_width == 0 || png_ptr->num_rows == 0);
167.2846  
167.2847        }
167.2848  
167.2849 -      /* reset the row above the image for the next pass */
167.2850 +      /* Reset the row above the image for the next pass */
167.2851        if (png_ptr->pass < 7)
167.2852        {
167.2853           if (png_ptr->prev_row != NULL)
167.2854              png_memset(png_ptr->prev_row, 0,
167.2855 -               (png_size_t)(PNG_ROWBYTES(png_ptr->usr_channels*
167.2856 -               png_ptr->usr_bit_depth,png_ptr->width))+1);
167.2857 +                (png_size_t)(PNG_ROWBYTES(png_ptr->usr_channels*
167.2858 +                png_ptr->usr_bit_depth, png_ptr->width)) + 1);
167.2859 +
167.2860           return;
167.2861        }
167.2862     }
167.2863  #endif
167.2864  
167.2865 -   /* if we get here, we've just written the last row, so we need
167.2866 +   /* If we get here, we've just written the last row, so we need
167.2867        to flush the compressor */
167.2868     do
167.2869     {
167.2870 -      /* tell the compressor we are done */
167.2871 +      /* Tell the compressor we are done */
167.2872        ret = deflate(&png_ptr->zstream, Z_FINISH);
167.2873 -      /* check for an error */
167.2874 +
167.2875 +      /* Check for an error */
167.2876        if (ret == Z_OK)
167.2877        {
167.2878 -         /* check to see if we need more room */
167.2879 +         /* Check to see if we need more room */
167.2880           if (!(png_ptr->zstream.avail_out))
167.2881           {
167.2882              png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
167.2883 @@ -1933,27 +2233,29 @@
167.2884              png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
167.2885           }
167.2886        }
167.2887 +
167.2888        else if (ret != Z_STREAM_END)
167.2889        {
167.2890           if (png_ptr->zstream.msg != NULL)
167.2891              png_error(png_ptr, png_ptr->zstream.msg);
167.2892 +
167.2893           else
167.2894              png_error(png_ptr, "zlib error");
167.2895        }
167.2896     } while (ret != Z_STREAM_END);
167.2897  
167.2898 -   /* write any extra space */
167.2899 +   /* Write any extra space */
167.2900     if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
167.2901     {
167.2902        png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size -
167.2903 -         png_ptr->zstream.avail_out);
167.2904 +          png_ptr->zstream.avail_out);
167.2905     }
167.2906  
167.2907 -   deflateReset(&png_ptr->zstream);
167.2908 +   png_zlib_release(png_ptr);
167.2909     png_ptr->zstream.data_type = Z_BINARY;
167.2910  }
167.2911  
167.2912 -#if defined(PNG_WRITE_INTERLACING_SUPPORTED)
167.2913 +#ifdef PNG_WRITE_INTERLACING_SUPPORTED
167.2914  /* Pick out the correct pixels for the interlace pass.
167.2915   * The basic idea here is to go through the row with a source
167.2916   * pointer and a destination pointer (sp and dp), and copy the
167.2917 @@ -1964,25 +2266,20 @@
167.2918  void /* PRIVATE */
167.2919  png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
167.2920  {
167.2921 -#ifdef PNG_USE_LOCAL_ARRAYS
167.2922 -   /* arrays to facilitate easy interlacing - use pass (0 - 6) as index */
167.2923 -
167.2924 -   /* start of interlace block */
167.2925 +   /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
167.2926 +
167.2927 +   /* Start of interlace block */
167.2928     int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
167.2929  
167.2930 -   /* offset to next interlace block */
167.2931 +   /* Offset to next interlace block */
167.2932     int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
167.2933 -#endif
167.2934 -
167.2935 -   png_debug(1, "in png_do_write_interlace\n");
167.2936 -   /* we don't have to do anything on the last pass (6) */
167.2937 -#if defined(PNG_USELESS_TESTS_SUPPORTED)
167.2938 -   if (row != NULL && row_info != NULL && pass < 6)
167.2939 -#else
167.2940 +
167.2941 +   png_debug(1, "in png_do_write_interlace");
167.2942 +
167.2943 +   /* We don't have to do anything on the last pass (6) */
167.2944     if (pass < 6)
167.2945 -#endif
167.2946     {
167.2947 -      /* each pixel depth is handled separately */
167.2948 +      /* Each pixel depth is handled separately */
167.2949        switch (row_info->pixel_depth)
167.2950        {
167.2951           case 1:
167.2952 @@ -1998,6 +2295,7 @@
167.2953              dp = row;
167.2954              d = 0;
167.2955              shift = 7;
167.2956 +
167.2957              for (i = png_pass_start[pass]; i < row_width;
167.2958                 i += png_pass_inc[pass])
167.2959              {
167.2960 @@ -2011,14 +2309,17 @@
167.2961                    *dp++ = (png_byte)d;
167.2962                    d = 0;
167.2963                 }
167.2964 +
167.2965                 else
167.2966                    shift--;
167.2967  
167.2968              }
167.2969              if (shift != 7)
167.2970                 *dp = (png_byte)d;
167.2971 +
167.2972              break;
167.2973           }
167.2974 +
167.2975           case 2:
167.2976           {
167.2977              png_bytep sp;
167.2978 @@ -2032,6 +2333,7 @@
167.2979              dp = row;
167.2980              shift = 6;
167.2981              d = 0;
167.2982 +
167.2983              for (i = png_pass_start[pass]; i < row_width;
167.2984                 i += png_pass_inc[pass])
167.2985              {
167.2986 @@ -2045,13 +2347,16 @@
167.2987                    *dp++ = (png_byte)d;
167.2988                    d = 0;
167.2989                 }
167.2990 +
167.2991                 else
167.2992                    shift -= 2;
167.2993              }
167.2994              if (shift != 6)
167.2995 -                   *dp = (png_byte)d;
167.2996 +               *dp = (png_byte)d;
167.2997 +
167.2998              break;
167.2999           }
167.3000 +
167.3001           case 4:
167.3002           {
167.3003              png_bytep sp;
167.3004 @@ -2066,7 +2371,7 @@
167.3005              shift = 4;
167.3006              d = 0;
167.3007              for (i = png_pass_start[pass]; i < row_width;
167.3008 -               i += png_pass_inc[pass])
167.3009 +                i += png_pass_inc[pass])
167.3010              {
167.3011                 sp = row + (png_size_t)(i >> 1);
167.3012                 value = (*sp >> ((1 - (int)(i & 0x01)) << 2)) & 0x0f;
167.3013 @@ -2078,13 +2383,16 @@
167.3014                    *dp++ = (png_byte)d;
167.3015                    d = 0;
167.3016                 }
167.3017 +
167.3018                 else
167.3019                    shift -= 4;
167.3020              }
167.3021              if (shift != 4)
167.3022                 *dp = (png_byte)d;
167.3023 +
167.3024              break;
167.3025           }
167.3026 +
167.3027           default:
167.3028           {
167.3029              png_bytep sp;
167.3030 @@ -2093,33 +2401,37 @@
167.3031              png_uint_32 row_width = row_info->width;
167.3032              png_size_t pixel_bytes;
167.3033  
167.3034 -            /* start at the beginning */
167.3035 +            /* Start at the beginning */
167.3036              dp = row;
167.3037 -            /* find out how many bytes each pixel takes up */
167.3038 +
167.3039 +            /* Find out how many bytes each pixel takes up */
167.3040              pixel_bytes = (row_info->pixel_depth >> 3);
167.3041 -            /* loop through the row, only looking at the pixels that
167.3042 -               matter */
167.3043 +
167.3044 +            /* Loop through the row, only looking at the pixels that matter */
167.3045              for (i = png_pass_start[pass]; i < row_width;
167.3046                 i += png_pass_inc[pass])
167.3047              {
167.3048 -               /* find out where the original pixel is */
167.3049 +               /* Find out where the original pixel is */
167.3050                 sp = row + (png_size_t)i * pixel_bytes;
167.3051 -               /* move the pixel */
167.3052 +
167.3053 +               /* Move the pixel */
167.3054                 if (dp != sp)
167.3055                    png_memcpy(dp, sp, pixel_bytes);
167.3056 -               /* next pixel */
167.3057 +
167.3058 +               /* Next pixel */
167.3059                 dp += pixel_bytes;
167.3060              }
167.3061              break;
167.3062           }
167.3063        }
167.3064 -      /* set new row width */
167.3065 +      /* Set new row width */
167.3066        row_info->width = (row_info->width +
167.3067 -         png_pass_inc[pass] - 1 -
167.3068 -         png_pass_start[pass]) /
167.3069 -         png_pass_inc[pass];
167.3070 -         row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
167.3071 -            row_info->width);
167.3072 +          png_pass_inc[pass] - 1 -
167.3073 +          png_pass_start[pass]) /
167.3074 +          png_pass_inc[pass];
167.3075 +
167.3076 +      row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
167.3077 +          row_info->width);
167.3078     }
167.3079  }
167.3080  #endif
167.3081 @@ -2128,6 +2440,8 @@
167.3082   * been specified by the application, and then writes the row out with the
167.3083   * chosen filter.
167.3084   */
167.3085 +static void png_write_filtered_row(png_structp png_ptr, png_bytep filtered_row);
167.3086 +
167.3087  #define PNG_MAXSUM (((png_uint_32)(-1)) >> 1)
167.3088  #define PNG_HISHIFT 10
167.3089  #define PNG_LOMASK ((png_uint_32)0xffffL)
167.3090 @@ -2135,20 +2449,34 @@
167.3091  void /* PRIVATE */
167.3092  png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
167.3093  {
167.3094 -   png_bytep prev_row, best_row, row_buf;
167.3095 +   png_bytep best_row;
167.3096 +#ifdef PNG_WRITE_FILTER_SUPPORTED
167.3097 +   png_bytep prev_row, row_buf;
167.3098     png_uint_32 mins, bpp;
167.3099     png_byte filter_to_do = png_ptr->do_filter;
167.3100 -   png_uint_32 row_bytes = row_info->rowbytes;
167.3101 -#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
167.3102 +   png_size_t row_bytes = row_info->rowbytes;
167.3103 +#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
167.3104     int num_p_filters = (int)png_ptr->num_prev_filters;
167.3105  #endif
167.3106  
167.3107 -   png_debug(1, "in png_write_find_filter\n");
167.3108 -   /* find out how many bytes offset each pixel is */
167.3109 +   png_debug(1, "in png_write_find_filter");
167.3110 +
167.3111 +#ifndef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
167.3112 +  if (png_ptr->row_number == 0 && filter_to_do == PNG_ALL_FILTERS)
167.3113 +  {
167.3114 +     /* These will never be selected so we need not test them. */
167.3115 +     filter_to_do &= ~(PNG_FILTER_UP | PNG_FILTER_PAETH);
167.3116 +  }
167.3117 +#endif
167.3118 +
167.3119 +   /* Find out how many bytes offset each pixel is */
167.3120     bpp = (row_info->pixel_depth + 7) >> 3;
167.3121  
167.3122     prev_row = png_ptr->prev_row;
167.3123 -   best_row = row_buf = png_ptr->row_buf;
167.3124 +#endif
167.3125 +   best_row = png_ptr->row_buf;
167.3126 +#ifdef PNG_WRITE_FILTER_SUPPORTED
167.3127 +   row_buf = best_row;
167.3128     mins = PNG_MAXSUM;
167.3129  
167.3130     /* The prediction method we use is to find which method provides the
167.3131 @@ -2163,11 +2491,14 @@
167.3132      * computationally expensive).
167.3133      *
167.3134      * GRR 980525:  consider also
167.3135 +    *
167.3136      *   (1) minimum sum of absolute differences from running average (i.e.,
167.3137      *       keep running sum of non-absolute differences & count of bytes)
167.3138      *       [track dispersion, too?  restart average if dispersion too large?]
167.3139 +    *
167.3140      *  (1b) minimum sum of absolute differences from sliding average, probably
167.3141      *       with window size <= deflate window (usually 32K)
167.3142 +    *
167.3143      *   (2) minimum sum of squared differences from zero or running average
167.3144      *       (i.e., ~ root-mean-square approach)
167.3145      */
167.3146 @@ -2176,12 +2507,11 @@
167.3147     /* We don't need to test the 'no filter' case if this is the only filter
167.3148      * that has been chosen, as it doesn't actually do anything to the data.
167.3149      */
167.3150 -   if ((filter_to_do & PNG_FILTER_NONE) &&
167.3151 -       filter_to_do != PNG_FILTER_NONE)
167.3152 +   if ((filter_to_do & PNG_FILTER_NONE) && filter_to_do != PNG_FILTER_NONE)
167.3153     {
167.3154        png_bytep rp;
167.3155        png_uint_32 sum = 0;
167.3156 -      png_uint_32 i;
167.3157 +      png_size_t i;
167.3158        int v;
167.3159  
167.3160        for (i = 0, rp = row_buf + 1; i < row_bytes; i++, rp++)
167.3161 @@ -2190,7 +2520,7 @@
167.3162           sum += (v < 128) ? v : 256 - v;
167.3163        }
167.3164  
167.3165 -#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
167.3166 +#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
167.3167        if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
167.3168        {
167.3169           png_uint_32 sumhi, sumlo;
167.3170 @@ -2204,9 +2534,10 @@
167.3171              if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
167.3172              {
167.3173                 sumlo = (sumlo * png_ptr->filter_weights[j]) >>
167.3174 -                  PNG_WEIGHT_SHIFT;
167.3175 +                   PNG_WEIGHT_SHIFT;
167.3176 +
167.3177                 sumhi = (sumhi * png_ptr->filter_weights[j]) >>
167.3178 -                  PNG_WEIGHT_SHIFT;
167.3179 +                   PNG_WEIGHT_SHIFT;
167.3180              }
167.3181           }
167.3182  
167.3183 @@ -2215,12 +2546,14 @@
167.3184            * it has the minimum possible computational cost - none).
167.3185            */
167.3186           sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >>
167.3187 -            PNG_COST_SHIFT;
167.3188 +             PNG_COST_SHIFT;
167.3189 +
167.3190           sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >>
167.3191 -            PNG_COST_SHIFT;
167.3192 +             PNG_COST_SHIFT;
167.3193  
167.3194           if (sumhi > PNG_HIMASK)
167.3195              sum = PNG_MAXSUM;
167.3196 +
167.3197           else
167.3198              sum = (sumhi << PNG_HISHIFT) + sumlo;
167.3199        }
167.3200 @@ -2228,22 +2561,25 @@
167.3201        mins = sum;
167.3202     }
167.3203  
167.3204 -   /* sub filter */
167.3205 +   /* Sub filter */
167.3206     if (filter_to_do == PNG_FILTER_SUB)
167.3207 -   /* it's the only filter so no testing is needed */
167.3208 +   /* It's the only filter so no testing is needed */
167.3209     {
167.3210        png_bytep rp, lp, dp;
167.3211 -      png_uint_32 i;
167.3212 +      png_size_t i;
167.3213 +
167.3214        for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
167.3215             i++, rp++, dp++)
167.3216        {
167.3217           *dp = *rp;
167.3218        }
167.3219 +
167.3220        for (lp = row_buf + 1; i < row_bytes;
167.3221           i++, rp++, lp++, dp++)
167.3222        {
167.3223           *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
167.3224        }
167.3225 +
167.3226        best_row = png_ptr->sub_row;
167.3227     }
167.3228  
167.3229 @@ -2251,10 +2587,10 @@
167.3230     {
167.3231        png_bytep rp, dp, lp;
167.3232        png_uint_32 sum = 0, lmins = mins;
167.3233 -      png_uint_32 i;
167.3234 +      png_size_t i;
167.3235        int v;
167.3236  
167.3237 -#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
167.3238 +#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
167.3239        /* We temporarily increase the "minimum sum" by the factor we
167.3240         * would reduce the sum of this filter, so that we can do the
167.3241         * early exit comparison without scaling the sum each time.
167.3242 @@ -2271,19 +2607,22 @@
167.3243              if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB)
167.3244              {
167.3245                 lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
167.3246 -                  PNG_WEIGHT_SHIFT;
167.3247 +                   PNG_WEIGHT_SHIFT;
167.3248 +
167.3249                 lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
167.3250 -                  PNG_WEIGHT_SHIFT;
167.3251 +                   PNG_WEIGHT_SHIFT;
167.3252              }
167.3253           }
167.3254  
167.3255           lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
167.3256 -            PNG_COST_SHIFT;
167.3257 +             PNG_COST_SHIFT;
167.3258 +
167.3259           lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
167.3260 -            PNG_COST_SHIFT;
167.3261 +             PNG_COST_SHIFT;
167.3262  
167.3263           if (lmhi > PNG_HIMASK)
167.3264              lmins = PNG_MAXSUM;
167.3265 +
167.3266           else
167.3267              lmins = (lmhi << PNG_HISHIFT) + lmlo;
167.3268        }
167.3269 @@ -2296,6 +2635,7 @@
167.3270  
167.3271           sum += (v < 128) ? v : 256 - v;
167.3272        }
167.3273 +
167.3274        for (lp = row_buf + 1; i < row_bytes;
167.3275           i++, rp++, lp++, dp++)
167.3276        {
167.3277 @@ -2307,7 +2647,7 @@
167.3278              break;
167.3279        }
167.3280  
167.3281 -#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
167.3282 +#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
167.3283        if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
167.3284        {
167.3285           int j;
167.3286 @@ -2320,19 +2660,22 @@
167.3287              if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB)
167.3288              {
167.3289                 sumlo = (sumlo * png_ptr->inv_filter_weights[j]) >>
167.3290 -                  PNG_WEIGHT_SHIFT;
167.3291 +                   PNG_WEIGHT_SHIFT;
167.3292 +
167.3293                 sumhi = (sumhi * png_ptr->inv_filter_weights[j]) >>
167.3294 -                  PNG_WEIGHT_SHIFT;
167.3295 +                   PNG_WEIGHT_SHIFT;
167.3296              }
167.3297           }
167.3298  
167.3299           sumlo = (sumlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
167.3300 -            PNG_COST_SHIFT;
167.3301 +             PNG_COST_SHIFT;
167.3302 +
167.3303           sumhi = (sumhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
167.3304 -            PNG_COST_SHIFT;
167.3305 +             PNG_COST_SHIFT;
167.3306  
167.3307           if (sumhi > PNG_HIMASK)
167.3308              sum = PNG_MAXSUM;
167.3309 +
167.3310           else
167.3311              sum = (sumhi << PNG_HISHIFT) + sumlo;
167.3312        }
167.3313 @@ -2345,18 +2688,19 @@
167.3314        }
167.3315     }
167.3316  
167.3317 -   /* up filter */
167.3318 +   /* Up filter */
167.3319     if (filter_to_do == PNG_FILTER_UP)
167.3320     {
167.3321        png_bytep rp, dp, pp;
167.3322 -      png_uint_32 i;
167.3323 +      png_size_t i;
167.3324  
167.3325        for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
167.3326 -           pp = prev_row + 1; i < row_bytes;
167.3327 -           i++, rp++, pp++, dp++)
167.3328 +          pp = prev_row + 1; i < row_bytes;
167.3329 +          i++, rp++, pp++, dp++)
167.3330        {
167.3331           *dp = (png_byte)(((int)*rp - (int)*pp) & 0xff);
167.3332        }
167.3333 +
167.3334        best_row = png_ptr->up_row;
167.3335     }
167.3336  
167.3337 @@ -2364,11 +2708,11 @@
167.3338     {
167.3339        png_bytep rp, dp, pp;
167.3340        png_uint_32 sum = 0, lmins = mins;
167.3341 -      png_uint_32 i;
167.3342 +      png_size_t i;
167.3343        int v;
167.3344  
167.3345  
167.3346 -#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
167.3347 +#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
167.3348        if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
167.3349        {
167.3350           int j;
167.3351 @@ -2381,26 +2725,29 @@
167.3352              if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP)
167.3353              {
167.3354                 lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
167.3355 -                  PNG_WEIGHT_SHIFT;
167.3356 +                   PNG_WEIGHT_SHIFT;
167.3357 +
167.3358                 lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
167.3359 -                  PNG_WEIGHT_SHIFT;
167.3360 +                   PNG_WEIGHT_SHIFT;
167.3361              }
167.3362           }
167.3363  
167.3364           lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >>
167.3365 -            PNG_COST_SHIFT;
167.3366 +             PNG_COST_SHIFT;
167.3367 +
167.3368           lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >>
167.3369 -            PNG_COST_SHIFT;
167.3370 +             PNG_COST_SHIFT;
167.3371  
167.3372           if (lmhi > PNG_HIMASK)
167.3373              lmins = PNG_MAXSUM;
167.3374 +
167.3375           else
167.3376              lmins = (lmhi << PNG_HISHIFT) + lmlo;
167.3377        }
167.3378  #endif
167.3379  
167.3380        for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
167.3381 -           pp = prev_row + 1; i < row_bytes; i++)
167.3382 +          pp = prev_row + 1; i < row_bytes; i++)
167.3383        {
167.3384           v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
167.3385  
167.3386 @@ -2410,7 +2757,7 @@
167.3387              break;
167.3388        }
167.3389  
167.3390 -#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
167.3391 +#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
167.3392        if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
167.3393        {
167.3394           int j;
167.3395 @@ -2423,19 +2770,22 @@
167.3396              if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP)
167.3397              {
167.3398                 sumlo = (sumlo * png_ptr->filter_weights[j]) >>
167.3399 -                  PNG_WEIGHT_SHIFT;
167.3400 +                   PNG_WEIGHT_SHIFT;
167.3401 +
167.3402                 sumhi = (sumhi * png_ptr->filter_weights[j]) >>
167.3403 -                  PNG_WEIGHT_SHIFT;
167.3404 +                   PNG_WEIGHT_SHIFT;
167.3405              }
167.3406           }
167.3407  
167.3408           sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >>
167.3409 -            PNG_COST_SHIFT;
167.3410 +             PNG_COST_SHIFT;
167.3411 +
167.3412           sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >>
167.3413 -            PNG_COST_SHIFT;
167.3414 +             PNG_COST_SHIFT;
167.3415  
167.3416           if (sumhi > PNG_HIMASK)
167.3417              sum = PNG_MAXSUM;
167.3418 +
167.3419           else
167.3420              sum = (sumhi << PNG_HISHIFT) + sumlo;
167.3421        }
167.3422 @@ -2448,16 +2798,18 @@
167.3423        }
167.3424     }
167.3425  
167.3426 -   /* avg filter */
167.3427 +   /* Avg filter */
167.3428     if (filter_to_do == PNG_FILTER_AVG)
167.3429     {
167.3430        png_bytep rp, dp, pp, lp;
167.3431        png_uint_32 i;
167.3432 +
167.3433        for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
167.3434             pp = prev_row + 1; i < bpp; i++)
167.3435        {
167.3436           *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
167.3437        }
167.3438 +
167.3439        for (lp = row_buf + 1; i < row_bytes; i++)
167.3440        {
167.3441           *dp++ = (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2))
167.3442 @@ -2470,10 +2822,10 @@
167.3443     {
167.3444        png_bytep rp, dp, pp, lp;
167.3445        png_uint_32 sum = 0, lmins = mins;
167.3446 -      png_uint_32 i;
167.3447 +      png_size_t i;
167.3448        int v;
167.3449  
167.3450 -#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
167.3451 +#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
167.3452        if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
167.3453        {
167.3454           int j;
167.3455 @@ -2486,19 +2838,22 @@
167.3456              if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_AVG)
167.3457              {
167.3458                 lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
167.3459 -                  PNG_WEIGHT_SHIFT;
167.3460 +                   PNG_WEIGHT_SHIFT;
167.3461 +
167.3462                 lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
167.3463 -                  PNG_WEIGHT_SHIFT;
167.3464 +                   PNG_WEIGHT_SHIFT;
167.3465              }
167.3466           }
167.3467  
167.3468           lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >>
167.3469 -            PNG_COST_SHIFT;
167.3470 +             PNG_COST_SHIFT;
167.3471 +
167.3472           lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >>
167.3473 -            PNG_COST_SHIFT;
167.3474 +             PNG_COST_SHIFT;
167.3475  
167.3476           if (lmhi > PNG_HIMASK)
167.3477              lmins = PNG_MAXSUM;
167.3478 +
167.3479           else
167.3480              lmins = (lmhi << PNG_HISHIFT) + lmlo;
167.3481        }
167.3482 @@ -2511,10 +2866,11 @@
167.3483  
167.3484           sum += (v < 128) ? v : 256 - v;
167.3485        }
167.3486 +
167.3487        for (lp = row_buf + 1; i < row_bytes; i++)
167.3488        {
167.3489           v = *dp++ =
167.3490 -          (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2)) & 0xff);
167.3491 +             (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2)) & 0xff);
167.3492  
167.3493           sum += (v < 128) ? v : 256 - v;
167.3494  
167.3495 @@ -2522,7 +2878,7 @@
167.3496              break;
167.3497        }
167.3498  
167.3499 -#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
167.3500 +#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
167.3501        if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
167.3502        {
167.3503           int j;
167.3504 @@ -2535,19 +2891,22 @@
167.3505              if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
167.3506              {
167.3507                 sumlo = (sumlo * png_ptr->filter_weights[j]) >>
167.3508 -                  PNG_WEIGHT_SHIFT;
167.3509 +                   PNG_WEIGHT_SHIFT;
167.3510 +
167.3511                 sumhi = (sumhi * png_ptr->filter_weights[j]) >>
167.3512 -                  PNG_WEIGHT_SHIFT;
167.3513 +                   PNG_WEIGHT_SHIFT;
167.3514              }
167.3515           }
167.3516  
167.3517           sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >>
167.3518 -            PNG_COST_SHIFT;
167.3519 +             PNG_COST_SHIFT;
167.3520 +
167.3521           sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >>
167.3522 -            PNG_COST_SHIFT;
167.3523 +             PNG_COST_SHIFT;
167.3524  
167.3525           if (sumhi > PNG_HIMASK)
167.3526              sum = PNG_MAXSUM;
167.3527 +
167.3528           else
167.3529              sum = (sumhi << PNG_HISHIFT) + sumlo;
167.3530        }
167.3531 @@ -2564,9 +2923,10 @@
167.3532     if (filter_to_do == PNG_FILTER_PAETH)
167.3533     {
167.3534        png_bytep rp, dp, pp, cp, lp;
167.3535 -      png_uint_32 i;
167.3536 +      png_size_t i;
167.3537 +
167.3538        for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
167.3539 -           pp = prev_row + 1; i < bpp; i++)
167.3540 +          pp = prev_row + 1; i < bpp; i++)
167.3541        {
167.3542           *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
167.3543        }
167.3544 @@ -2603,10 +2963,10 @@
167.3545     {
167.3546        png_bytep rp, dp, pp, cp, lp;
167.3547        png_uint_32 sum = 0, lmins = mins;
167.3548 -      png_uint_32 i;
167.3549 +      png_size_t i;
167.3550        int v;
167.3551  
167.3552 -#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
167.3553 +#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
167.3554        if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
167.3555        {
167.3556           int j;
167.3557 @@ -2619,26 +2979,29 @@
167.3558              if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH)
167.3559              {
167.3560                 lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
167.3561 -                  PNG_WEIGHT_SHIFT;
167.3562 +                   PNG_WEIGHT_SHIFT;
167.3563 +
167.3564                 lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
167.3565 -                  PNG_WEIGHT_SHIFT;
167.3566 +                   PNG_WEIGHT_SHIFT;
167.3567              }
167.3568           }
167.3569  
167.3570           lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >>
167.3571 -            PNG_COST_SHIFT;
167.3572 +             PNG_COST_SHIFT;
167.3573 +
167.3574           lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >>
167.3575 -            PNG_COST_SHIFT;
167.3576 +             PNG_COST_SHIFT;
167.3577  
167.3578           if (lmhi > PNG_HIMASK)
167.3579              lmins = PNG_MAXSUM;
167.3580 +
167.3581           else
167.3582              lmins = (lmhi << PNG_HISHIFT) + lmlo;
167.3583        }
167.3584  #endif
167.3585  
167.3586        for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
167.3587 -           pp = prev_row + 1; i < bpp; i++)
167.3588 +          pp = prev_row + 1; i < bpp; i++)
167.3589        {
167.3590           v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
167.3591  
167.3592 @@ -2671,10 +3034,13 @@
167.3593           pa = abs(p - a);
167.3594           pb = abs(p - b);
167.3595           pc = abs(p - c);
167.3596 +
167.3597           if (pa <= pb && pa <= pc)
167.3598              p = a;
167.3599 +
167.3600           else if (pb <= pc)
167.3601              p = b;
167.3602 +
167.3603           else
167.3604              p = c;
167.3605  #endif /* PNG_SLOW_PAETH */
167.3606 @@ -2687,7 +3053,7 @@
167.3607              break;
167.3608        }
167.3609  
167.3610 -#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
167.3611 +#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
167.3612        if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
167.3613        {
167.3614           int j;
167.3615 @@ -2700,19 +3066,22 @@
167.3616              if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH)
167.3617              {
167.3618                 sumlo = (sumlo * png_ptr->filter_weights[j]) >>
167.3619 -                  PNG_WEIGHT_SHIFT;
167.3620 +                   PNG_WEIGHT_SHIFT;
167.3621 +
167.3622                 sumhi = (sumhi * png_ptr->filter_weights[j]) >>
167.3623 -                  PNG_WEIGHT_SHIFT;
167.3624 +                   PNG_WEIGHT_SHIFT;
167.3625              }
167.3626           }
167.3627  
167.3628           sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >>
167.3629 -            PNG_COST_SHIFT;
167.3630 +             PNG_COST_SHIFT;
167.3631 +
167.3632           sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >>
167.3633 -            PNG_COST_SHIFT;
167.3634 +             PNG_COST_SHIFT;
167.3635  
167.3636           if (sumhi > PNG_HIMASK)
167.3637              sum = PNG_MAXSUM;
167.3638 +
167.3639           else
167.3640              sum = (sumhi << PNG_HISHIFT) + sumlo;
167.3641        }
167.3642 @@ -2723,64 +3092,96 @@
167.3643           best_row = png_ptr->paeth_row;
167.3644        }
167.3645     }
167.3646 -
167.3647 +#endif /* PNG_WRITE_FILTER_SUPPORTED */
167.3648     /* Do the actual writing of the filtered row data from the chosen filter. */
167.3649  
167.3650     png_write_filtered_row(png_ptr, best_row);
167.3651  
167.3652 -#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
167.3653 +#ifdef PNG_WRITE_FILTER_SUPPORTED
167.3654 +#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
167.3655     /* Save the type of filter we picked this time for future calculations */
167.3656     if (png_ptr->num_prev_filters > 0)
167.3657     {
167.3658        int j;
167.3659 +
167.3660        for (j = 1; j < num_p_filters; j++)
167.3661        {
167.3662           png_ptr->prev_filters[j] = png_ptr->prev_filters[j - 1];
167.3663        }
167.3664 +
167.3665        png_ptr->prev_filters[j] = best_row[0];
167.3666     }
167.3667  #endif
167.3668 +#endif /* PNG_WRITE_FILTER_SUPPORTED */
167.3669  }
167.3670  
167.3671  
167.3672  /* Do the actual writing of a previously filtered row. */
167.3673 -void /* PRIVATE */
167.3674 +static void
167.3675  png_write_filtered_row(png_structp png_ptr, png_bytep filtered_row)
167.3676  {
167.3677 -   png_debug(1, "in png_write_filtered_row\n");
167.3678 -   png_debug1(2, "filter = %d\n", filtered_row[0]);
167.3679 -   /* set up the zlib input buffer */
167.3680 +   png_size_t avail;
167.3681 +
167.3682 +   png_debug(1, "in png_write_filtered_row");
167.3683 +
167.3684 +   png_debug1(2, "filter = %d", filtered_row[0]);
167.3685 +   /* Set up the zlib input buffer */
167.3686  
167.3687     png_ptr->zstream.next_in = filtered_row;
167.3688 -   png_ptr->zstream.avail_in = (uInt)png_ptr->row_info.rowbytes + 1;
167.3689 -   /* repeat until we have compressed all the data */
167.3690 +   png_ptr->zstream.avail_in = 0;
167.3691 +   avail = png_ptr->row_info.rowbytes + 1;
167.3692 +   /* Repeat until we have compressed all the data */
167.3693     do
167.3694     {
167.3695 -      int ret; /* return of zlib */
167.3696 -
167.3697 -      /* compress the data */
167.3698 +      int ret; /* Return of zlib */
167.3699 +
167.3700 +      /* Record the number of bytes available - zlib supports at least 65535
167.3701 +       * bytes at one step, depending on the size of the zlib type 'uInt', the
167.3702 +       * maximum size zlib can write at once is ZLIB_IO_MAX (from pngpriv.h).
167.3703 +       * Use this because on 16 bit systems 'rowbytes' can be up to 65536 (i.e.
167.3704 +       * one more than 16 bits) and, in this case 'rowbytes+1' can overflow a
167.3705 +       * uInt.  ZLIB_IO_MAX can be safely reduced to cause zlib to be called
167.3706 +       * with smaller chunks of data.
167.3707 +       */
167.3708 +      if (png_ptr->zstream.avail_in == 0)
167.3709 +      {
167.3710 +         if (avail > ZLIB_IO_MAX)
167.3711 +         {
167.3712 +            png_ptr->zstream.avail_in  = ZLIB_IO_MAX;
167.3713 +            avail -= ZLIB_IO_MAX;
167.3714 +         }
167.3715 +
167.3716 +         else
167.3717 +         {
167.3718 +            /* So this will fit in the available uInt space: */
167.3719 +            png_ptr->zstream.avail_in = (uInt)avail;
167.3720 +            avail = 0;
167.3721 +         }
167.3722 +      }
167.3723 +
167.3724 +      /* Compress the data */
167.3725        ret = deflate(&png_ptr->zstream, Z_NO_FLUSH);
167.3726 -      /* check for compression errors */
167.3727 +
167.3728 +      /* Check for compression errors */
167.3729        if (ret != Z_OK)
167.3730        {
167.3731           if (png_ptr->zstream.msg != NULL)
167.3732              png_error(png_ptr, png_ptr->zstream.msg);
167.3733 +
167.3734           else
167.3735              png_error(png_ptr, "zlib error");
167.3736        }
167.3737  
167.3738 -      /* see if it is time to write another IDAT */
167.3739 +      /* See if it is time to write another IDAT */
167.3740        if (!(png_ptr->zstream.avail_out))
167.3741        {
167.3742 -         /* write the IDAT and reset the zlib output buffer */
167.3743 +         /* Write the IDAT and reset the zlib output buffer */
167.3744           png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
167.3745 -         png_ptr->zstream.next_out = png_ptr->zbuf;
167.3746 -         png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
167.3747        }
167.3748 -   /* repeat until all data has been compressed */
167.3749 -   } while (png_ptr->zstream.avail_in);
167.3750 -
167.3751 -   /* swap the current and previous rows */
167.3752 +   /* Repeat until all data has been compressed */
167.3753 +   } while (avail > 0 || png_ptr->zstream.avail_in > 0);
167.3754 +
167.3755 +   /* Swap the current and previous rows */
167.3756     if (png_ptr->prev_row != NULL)
167.3757     {
167.3758        png_bytep tptr;
167.3759 @@ -2790,10 +3191,10 @@
167.3760        png_ptr->row_buf = tptr;
167.3761     }
167.3762  
167.3763 -   /* finish row - updates counters and flushes zlib if last row */
167.3764 +   /* Finish row - updates counters and flushes zlib if last row */
167.3765     png_write_finish_row(png_ptr);
167.3766  
167.3767 -#if defined(PNG_WRITE_FLUSH_SUPPORTED)
167.3768 +#ifdef PNG_WRITE_FLUSH_SUPPORTED
167.3769     png_ptr->flush_rows++;
167.3770  
167.3771     if (png_ptr->flush_dist > 0 &&
   168.1 --- a/src/share/native/sun/awt/splashscreen/splashscreen_png.c	Fri Sep 30 17:20:56 2011 -0700
   168.2 +++ b/src/share/native/sun/awt/splashscreen/splashscreen_png.c	Tue Oct 04 12:39:42 2011 -0700
   168.3 @@ -36,7 +36,7 @@
   168.4  {
   168.5      png_uint_32 check;
   168.6  
   168.7 -    SplashStream * stream = (SplashStream*)png_ptr->io_ptr;
   168.8 +    SplashStream * stream = (SplashStream*)png_get_io_ptr(png_ptr);
   168.9      check = stream->read(stream, data, length);
  168.10      if (check != length)
  168.11          png_error(png_ptr, "Read Error");
  168.12 @@ -71,12 +71,11 @@
  168.13          goto done;
  168.14      }
  168.15  
  168.16 -    if (setjmp(png_ptr->jmpbuf)) {
  168.17 +    if (setjmp(png_jmpbuf(png_ptr))) {
  168.18          goto done;
  168.19      }
  168.20  
  168.21 -    png_ptr->io_ptr = io_ptr;
  168.22 -    png_ptr->read_data_fn = read_func;
  168.23 +    png_set_read_fn(png_ptr, io_ptr, read_func);
  168.24  
  168.25      png_set_sig_bytes(png_ptr, SIG_BYTES);      /* we already read the 8 signature bytes */
  168.26  
   169.1 --- a/src/solaris/classes/java/net/DefaultDatagramSocketImplFactory.java	Fri Sep 30 17:20:56 2011 -0700
   169.2 +++ b/src/solaris/classes/java/net/DefaultDatagramSocketImplFactory.java	Tue Oct 04 12:39:42 2011 -0700
   169.3 @@ -1,5 +1,5 @@
   169.4  /*
   169.5 - * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
   169.6 + * Copyright (c) 2007,2011, Oracle and/or its affiliates. All rights reserved.
   169.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   169.8   *
   169.9   * This code is free software; you can redistribute it and/or modify it
  169.10 @@ -35,7 +35,7 @@
  169.11   */
  169.12  
  169.13  class DefaultDatagramSocketImplFactory {
  169.14 -    static Class prefixImplClass = null;
  169.15 +    static Class<?> prefixImplClass = null;
  169.16  
  169.17      static {
  169.18          String prefix = null;
   170.1 --- a/src/solaris/classes/java/net/PlainDatagramSocketImpl.java	Fri Sep 30 17:20:56 2011 -0700
   170.2 +++ b/src/solaris/classes/java/net/PlainDatagramSocketImpl.java	Tue Oct 04 12:39:42 2011 -0700
   170.3 @@ -1,5 +1,5 @@
   170.4  /*
   170.5 - * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
   170.6 + * Copyright (c) 2007,2011, Oracle and/or its affiliates. All rights reserved.
   170.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   170.8   *
   170.9   * This code is free software; you can redistribute it and/or modify it
  170.10 @@ -54,8 +54,10 @@
  170.11  
  170.12      protected native int getTimeToLive() throws IOException;
  170.13  
  170.14 +    @Deprecated
  170.15      protected native void setTTL(byte ttl) throws IOException;
  170.16  
  170.17 +    @Deprecated
  170.18      protected native byte getTTL() throws IOException;
  170.19  
  170.20      protected native void join(InetAddress inetaddr, NetworkInterface netIf)
   171.1 --- a/src/solaris/classes/sun/net/dns/ResolverConfigurationImpl.java	Fri Sep 30 17:20:56 2011 -0700
   171.2 +++ b/src/solaris/classes/sun/net/dns/ResolverConfigurationImpl.java	Tue Oct 04 12:39:42 2011 -0700
   171.3 @@ -1,5 +1,5 @@
   171.4  /*
   171.5 - * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
   171.6 + * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
   171.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   171.8   *
   171.9   * This code is free software; you can redistribute it and/or modify it
  171.10 @@ -149,7 +149,7 @@
  171.11          sl = java.security.AccessController.doPrivileged(
  171.12                   new java.security.PrivilegedAction<LinkedList<String>>() {
  171.13                      public LinkedList<String> run() {
  171.14 -                        LinkedList ll;
  171.15 +                        LinkedList<String> ll;
  171.16  
  171.17                          // first try search keyword (max 6 domains)
  171.18                          ll = resolvconf("search", 6, 1);
  171.19 @@ -173,7 +173,7 @@
  171.20  
  171.21          String localDomain = localDomain0();
  171.22          if (localDomain != null && localDomain.length() > 0) {
  171.23 -            sl = new LinkedList();
  171.24 +            sl = new LinkedList<String>();
  171.25              sl.add(localDomain);
  171.26              return sl;
  171.27          }
  171.28 @@ -198,7 +198,7 @@
  171.29          }
  171.30  
  171.31          // no local domain so try fallback (RPC) domain or
  171.32 -        // hostname
  171.33 +        // hostName
  171.34  
  171.35          sl = new LinkedList<>();
  171.36          String domain = fallbackDomain0();
  171.37 @@ -216,22 +216,26 @@
  171.38          opts = new OptionsImpl();
  171.39      }
  171.40  
  171.41 +    @SuppressWarnings("unchecked")
  171.42      public List<String> searchlist() {
  171.43          synchronized (lock) {
  171.44              loadConfig();
  171.45  
  171.46              // List is mutable so return a shallow copy
  171.47 -            return (List)searchlist.clone();
  171.48 +            return (List<String>)searchlist.clone();
  171.49          }
  171.50      }
  171.51  
  171.52 +    @SuppressWarnings("unchecked")
  171.53      public List<String> nameservers() {
  171.54          synchronized (lock) {
  171.55              loadConfig();
  171.56  
  171.57              // List is mutable so return a shallow copy
  171.58 -            return (List)nameservers.clone();
  171.59 -         }
  171.60 +
  171.61 +          return (List<String>)nameservers.clone();
  171.62 +
  171.63 +        }
  171.64      }
  171.65  
  171.66      public Options options() {
   172.1 --- a/src/solaris/native/java/net/NetworkInterface.c	Fri Sep 30 17:20:56 2011 -0700
   172.2 +++ b/src/solaris/native/java/net/NetworkInterface.c	Tue Oct 04 12:39:42 2011 -0700
   172.3 @@ -139,8 +139,12 @@
   172.4  #ifdef __solaris__
   172.5  static netif *enumIPvXInterfaces(JNIEnv *env, int sock, netif *ifs, int family);
   172.6  static int    getMacFromDevice(JNIEnv *env, const char* ifname, unsigned char* retbuf);
   172.7 +
   172.8 +#ifndef SIOCGLIFHWADDR
   172.9 +#define SIOCGLIFHWADDR  _IOWR('i', 192, struct lifreq)
  172.10  #endif
  172.11  
  172.12 +#endif
  172.13  
  172.14  /******************* Java entry points *****************************/
  172.15  
  172.16 @@ -1567,6 +1571,20 @@
  172.17      struct sockaddr_in* sin;
  172.18      struct sockaddr_in ipAddr;
  172.19      int len, i;
  172.20 +    struct lifreq lif;
  172.21 +
  172.22 +    /* First, try the new (S11) SIOCGLIFHWADDR ioctl(). If that fails
  172.23 +     * try the old way.
  172.24 +     */
  172.25 +    memset(&lif, 0, sizeof(lif));
  172.26 +    strlcpy(lif.lifr_name, ifname, sizeof(lif.lifr_name));
  172.27 +
  172.28 +    if (ioctl(sock, SIOCGLIFHWADDR, &lif) != -1) {
  172.29 +        struct sockaddr_dl *sp;
  172.30 +        sp = (struct sockaddr_dl *)&lif.lifr_addr;
  172.31 +        memcpy(buf, &sp->sdl_data[0], sp->sdl_alen);
  172.32 +        return sp->sdl_alen;
  172.33 +    }
  172.34  
  172.35     /**
  172.36      * On Solaris we have to use DLPI, but it will only work if we have
  172.37 @@ -1576,34 +1594,29 @@
  172.38      if ((len = getMacFromDevice(env, ifname, buf))  == 0) {
  172.39          /*DLPI failed - trying to do arp lookup*/
  172.40  
  172.41 -       if (addr == NULL) {
  172.42 -          /**
  172.43 -           * No IPv4 address for that interface, so can't do an ARP lookup.
  172.44 -           */
  172.45 -           return -1;
  172.46 -      }
  172.47 +        if (addr == NULL) {
  172.48 +            /**
  172.49 +             * No IPv4 address for that interface, so can't do an ARP lookup.
  172.50 +             */
  172.51 +             return -1;
  172.52 +         }
  172.53  
  172.54 -      len = 6; //???
  172.55 +         len = 6; //???
  172.56  
  172.57 -      sin = (struct sockaddr_in *) &arpreq.arp_pa;
  172.58 -      memset((char *) &arpreq, 0, sizeof(struct arpreq));
  172.59 -      ipAddr.sin_port = 0;
  172.60 -      ipAddr.sin_family = AF_INET;
  172.61 -      memcpy(&ipAddr.sin_addr, addr, sizeof(struct in_addr));
  172.62 -      memcpy(&arpreq.arp_pa, &ipAddr, sizeof(struct sockaddr_in));
  172.63 -      arpreq.arp_flags= ATF_PUBL;
  172.64 +         sin = (struct sockaddr_in *) &arpreq.arp_pa;
  172.65 +         memset((char *) &arpreq, 0, sizeof(struct arpreq));
  172.66 +         ipAddr.sin_port = 0;
  172.67 +         ipAddr.sin_family = AF_INET;
  172.68 +         memcpy(&ipAddr.sin_addr, addr, sizeof(struct in_addr));
  172.69 +         memcpy(&arpreq.arp_pa, &ipAddr, sizeof(struct sockaddr_in));
  172.70 +         arpreq.arp_flags= ATF_PUBL;
  172.71  
  172.72 -      if (ioctl(sock, SIOCGARP, &arpreq) < 0) {
  172.73 -          if (errno != ENXIO) {
  172.74 -              // "No such device or address" means no hardware address, so it's
  172.75 -              // normal don't throw an exception
  172.76 -              NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "IOCTL failed");
  172.77 -              return -1;
  172.78 -          }
  172.79 -     }
  172.80 +         if (ioctl(sock, SIOCGARP, &arpreq) < 0) {
  172.81 +             return -1;
  172.82 +         }
  172.83  
  172.84 -     memcpy(buf, &arpreq.arp_ha.sa_data[0], len );
  172.85 -  }
  172.86 +         memcpy(buf, &arpreq.arp_ha.sa_data[0], len );
  172.87 +    }
  172.88  
  172.89      /*
  172.90       * All bytes to 0 means no hardware address.
   173.1 --- a/src/windows/classes/java/net/DefaultDatagramSocketImplFactory.java	Fri Sep 30 17:20:56 2011 -0700
   173.2 +++ b/src/windows/classes/java/net/DefaultDatagramSocketImplFactory.java	Tue Oct 04 12:39:42 2011 -0700
   173.3 @@ -1,5 +1,5 @@
   173.4  /*
   173.5 - * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
   173.6 + * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
   173.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   173.8   *
   173.9   * This code is free software; you can redistribute it and/or modify it
  173.10 @@ -45,7 +45,7 @@
  173.11  
  173.12  class DefaultDatagramSocketImplFactory
  173.13  {
  173.14 -    static Class prefixImplClass = null;
  173.15 +    static Class<?> prefixImplClass = null;
  173.16  
  173.17      /* the windows version. */
  173.18      private static float version;
   174.1 --- a/src/windows/classes/java/net/DualStackPlainDatagramSocketImpl.java	Fri Sep 30 17:20:56 2011 -0700
   174.2 +++ b/src/windows/classes/java/net/DualStackPlainDatagramSocketImpl.java	Tue Oct 04 12:39:42 2011 -0700
   174.3 @@ -1,5 +1,5 @@
   174.4  /*
   174.5 - * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
   174.6 + * Copyright (c) 2007,2011 Oracle and/or its affiliates. All rights reserved.
   174.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   174.8   *
   174.9   * This code is free software; you can redistribute it and/or modify it
  174.10 @@ -25,7 +25,6 @@
  174.11  package java.net;
  174.12  
  174.13  import java.io.IOException;
  174.14 -import java.io.FileDescriptor;
  174.15  import sun.misc.SharedSecrets;
  174.16  import sun.misc.JavaIOFileDescriptorAccess;
  174.17  
  174.18 @@ -215,11 +214,12 @@
  174.19          throw new IOException("Method not implemented!");
  174.20      }
  174.21  
  174.22 -
  174.23 +    @Deprecated
  174.24      protected void setTTL(byte ttl) throws IOException {
  174.25          throw new IOException("Method not implemented!");
  174.26      }
  174.27  
  174.28 +    @Deprecated
  174.29      protected byte getTTL() throws IOException {
  174.30          throw new IOException("Method not implemented!");
  174.31      }
   175.1 --- a/src/windows/classes/java/net/TwoStacksPlainDatagramSocketImpl.java	Fri Sep 30 17:20:56 2011 -0700
   175.2 +++ b/src/windows/classes/java/net/TwoStacksPlainDatagramSocketImpl.java	Tue Oct 04 12:39:42 2011 -0700
   175.3 @@ -68,7 +68,12 @@
   175.4  
   175.5      protected synchronized void create() throws SocketException {
   175.6          fd1 = new FileDescriptor();
   175.7 -        super.create();
   175.8 +        try {
   175.9 +            super.create();
  175.10 +        } catch (IOException e) {
  175.11 +            fd1 = null;
  175.12 +            throw e;
  175.13 +        }
  175.14      }
  175.15  
  175.16      protected synchronized void bind(int lport, InetAddress laddr)
  175.17 @@ -133,8 +138,10 @@
  175.18  
  175.19      protected native int getTimeToLive() throws IOException;
  175.20  
  175.21 +    @Deprecated
  175.22      protected native void setTTL(byte ttl) throws IOException;
  175.23  
  175.24 +    @Deprecated
  175.25      protected native byte getTTL() throws IOException;
  175.26  
  175.27      protected native void join(InetAddress inetaddr, NetworkInterface netIf)
   176.1 --- a/src/windows/classes/sun/net/dns/ResolverConfigurationImpl.java	Fri Sep 30 17:20:56 2011 -0700
   176.2 +++ b/src/windows/classes/sun/net/dns/ResolverConfigurationImpl.java	Tue Oct 04 12:39:42 2011 -0700
   176.3 @@ -57,8 +57,8 @@
   176.4      private static String os_nameservers;
   176.5  
   176.6      // Cached lists
   176.7 -    private static LinkedList searchlist;
   176.8 -    private static LinkedList nameservers;
   176.9 +    private static LinkedList<String> searchlist;
  176.10 +    private static LinkedList<String> nameservers;
  176.11  
  176.12      // Parse string that consists of token delimited by space or commas
  176.13      // and return LinkedHashMap
  176.14 @@ -111,21 +111,23 @@
  176.15          opts = new OptionsImpl();
  176.16      }
  176.17  
  176.18 +    @SuppressWarnings("unchecked") // clone()
  176.19      public List<String> searchlist() {
  176.20          synchronized (lock) {
  176.21              loadConfig();
  176.22  
  176.23              // List is mutable so return a shallow copy
  176.24 -            return (List)searchlist.clone();
  176.25 +            return (List<String>)searchlist.clone();
  176.26          }
  176.27      }
  176.28  
  176.29 +    @SuppressWarnings("unchecked") // clone()
  176.30      public List<String> nameservers() {
  176.31          synchronized (lock) {
  176.32              loadConfig();
  176.33  
  176.34              // List is mutable so return a shallow copy
  176.35 -            return (List)nameservers.clone();
  176.36 +            return (List<String>)nameservers.clone();
  176.37           }
  176.38      }
  176.39  
   177.1 --- a/src/windows/classes/sun/net/www/protocol/jar/JarFileFactory.java	Fri Sep 30 17:20:56 2011 -0700
   177.2 +++ b/src/windows/classes/sun/net/www/protocol/jar/JarFileFactory.java	Tue Oct 04 12:39:42 2011 -0700
   177.3 @@ -1,5 +1,5 @@
   177.4  /*
   177.5 - * Copyright (c) 1999, 2006, Oracle and/or its affiliates. All rights reserved.
   177.6 + * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
   177.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   177.8   *
   177.9   * This code is free software; you can redistribute it and/or modify it
  177.10 @@ -148,7 +148,7 @@
  177.11  
  177.12      private Permission getPermission(JarFile jarFile) {
  177.13          try {
  177.14 -            URLConnection uc = (URLConnection)getConnection(jarFile);
  177.15 +            URLConnection uc = getConnection(jarFile);
  177.16              if (uc != null)
  177.17                  return uc.getPermission();
  177.18          } catch (IOException ioe) {
   178.1 --- a/test/Makefile	Fri Sep 30 17:20:56 2011 -0700
   178.2 +++ b/test/Makefile	Tue Oct 04 12:39:42 2011 -0700
   178.3 @@ -342,7 +342,7 @@
   178.4  
   178.5  # Expect JT_HOME to be set for jtreg tests. (home for jtreg)
   178.6  ifndef JT_HOME
   178.7 -  JT_HOME = $(SLASH_JAVA)/re/jtreg/4.0/promoted/latest/binaries/jtreg
   178.8 +  JT_HOME = $(SLASH_JAVA)/re/jtreg/4.1/promoted/latest/binaries/jtreg
   178.9    ifdef JPRT_JTREG_HOME
  178.10      JT_HOME = $(JPRT_JTREG_HOME)
  178.11    endif
  178.12 @@ -353,19 +353,23 @@
  178.13    TESTDIRS = demo
  178.14  endif
  178.15  
  178.16 -# Samevm settings (default is false)
  178.17 -ifndef USE_JTREG_SAMEVM
  178.18 -  USE_JTREG_SAMEVM=false
  178.19 +# Agentvm settings (default is false)
  178.20 +ifndef USE_JTREG_AGENTVM
  178.21 +  USE_JTREG_AGENTVM=false
  178.22  endif
  178.23 -# With samevm, you cannot use -javaoptions?
  178.24 -ifeq ($(USE_JTREG_SAMEVM),true)
  178.25 -  JTREG_SAMEVM_OPTION = -samevm
  178.26 -  EXTRA_JTREG_OPTIONS += $(JTREG_SAMEVM_OPTION) $(JAVA_ARGS) $(JAVA_ARGS:%=-vmoption:%)
  178.27 +# With agentvm, you cannot use -javaoptions?
  178.28 +ifeq ($(USE_JTREG_AGENTVM),true)
  178.29 +  JTREG_AGENTVM_OPTION = -agentvm
  178.30 +  EXTRA_JTREG_OPTIONS += $(JTREG_AGENTVM_OPTION) $(JAVA_ARGS) $(JAVA_ARGS:%=-vmoption:%)
  178.31    JTREG_TEST_OPTIONS = $(JAVA_VM_ARGS:%=-vmoption:%)
  178.32  else
  178.33    JTREG_TEST_OPTIONS = $(JAVA_ARGS:%=-javaoptions:%) $(JAVA_VM_ARGS:%=-vmoption:%)
  178.34  endif
  178.35  
  178.36 +ifdef CONCURRENCY
  178.37 +  EXTRA_JTREG_OPTIONS += -concurrency:$(CONCURRENCY)
  178.38 +endif
  178.39 +
  178.40  # Some tests annoy me and fail frequently
  178.41  PROBLEM_LIST=ProblemList.txt
  178.42  PROBLEM_LISTS=$(PROBLEM_LIST) $(wildcard closed/$(PROBLEM_LIST))
  178.43 @@ -400,14 +404,14 @@
  178.44  define TestDirs
  178.45  $(foreach i,$1,$(wildcard ${i})) $(foreach i,$1,$(wildcard closed/${i}))
  178.46  endef
  178.47 -# Running batches of tests with or without samevm
  178.48 -define RunSamevmBatch
  178.49 -$(ECHO) "Running tests in samevm mode: $?"
  178.50 -$(MAKE) TEST_DEPENDENCIES="$?" TESTDIRS="$?" USE_JTREG_SAMEVM=true  UNIQUE_DIR=$@ jtreg_tests
  178.51 +# Running batches of tests with or without agentvm
  178.52 +define RunAgentvmBatch
  178.53 +$(ECHO) "Running tests in agentvm mode: $?"
  178.54 +$(MAKE) TEST_DEPENDENCIES="$?" TESTDIRS="$?" USE_JTREG_AGENTVM=true  UNIQUE_DIR=$@ jtreg_tests
  178.55  endef
  178.56  define RunOthervmBatch
  178.57  $(ECHO) "Running tests in othervm mode: $?"
  178.58 -$(MAKE) TEST_DEPENDENCIES="$?" TESTDIRS="$?" USE_JTREG_SAMEVM=false UNIQUE_DIR=$@ jtreg_tests
  178.59 +$(MAKE) TEST_DEPENDENCIES="$?" TESTDIRS="$?" USE_JTREG_AGENTVM=false UNIQUE_DIR=$@ jtreg_tests
  178.60  endef
  178.61  define SummaryInfo
  178.62  $(ECHO) "########################################################"
  178.63 @@ -421,22 +425,22 @@
  178.64  JDK_ALL_TARGETS =
  178.65  
  178.66  # Stable othervm testruns (minus items from PROBLEM_LIST)
  178.67 -#   Using samevm has problems, and doesn't help performance as much as others.
  178.68 +#   Using agentvm has problems, and doesn't help performance as much as others.
  178.69  JDK_ALL_TARGETS += jdk_awt
  178.70  jdk_awt: $(call TestDirs, com/sun/awt java/awt sun/awt \
  178.71           javax/imageio javax/print sun/pisces)
  178.72  	$(call RunOthervmBatch)
  178.73  
  178.74 -# Stable samevm testruns (minus items from PROBLEM_LIST)
  178.75 +# Stable agentvm testruns (minus items from PROBLEM_LIST)
  178.76  JDK_ALL_TARGETS += jdk_beans1
  178.77  jdk_beans1: $(call TestDirs, \
  178.78              java/beans/beancontext java/beans/PropertyChangeSupport \
  178.79              java/beans/Introspector java/beans/Performance \
  178.80              java/beans/VetoableChangeSupport java/beans/Statement)
  178.81 -	$(call RunSamevmBatch)
  178.82 +	$(call RunAgentvmBatch)
  178.83  
  178.84  # Stable othervm testruns (minus items from PROBLEM_LIST)
  178.85 -#   Using samevm has serious problems with these tests
  178.86 +#   Using agentvm has serious problems with these tests
  178.87  JDK_ALL_TARGETS += jdk_beans2
  178.88  jdk_beans2: $(call TestDirs, \
  178.89              java/beans/Beans java/beans/EventHandler java/beans/XMLDecoder \
  178.90 @@ -444,7 +448,7 @@
  178.91  	$(call RunOthervmBatch)
  178.92  
  178.93  # Stable othervm testruns (minus items from PROBLEM_LIST)
  178.94 -#   Using samevm has serious problems with these tests
  178.95 +#   Using agentvm has serious problems with these tests
  178.96  JDK_ALL_TARGETS += jdk_beans3
  178.97  jdk_beans3: $(call TestDirs, java/beans/XMLEncoder)
  178.98  	$(call RunOthervmBatch)
  178.99 @@ -453,24 +457,24 @@
 178.100  jdk_beans: jdk_beans1 jdk_beans2 jdk_beans3
 178.101  	@$(SummaryInfo)
 178.102  
 178.103 -# Stable samevm testruns (minus items from PROBLEM_LIST)
 178.104 +# Stable agentvm testruns (minus items from PROBLEM_LIST)
 178.105  JDK_ALL_TARGETS += jdk_io
 178.106  jdk_io: $(call TestDirs, java/io)
 178.107 -	$(call RunSamevmBatch)
 178.108 +	$(call RunAgentvmBatch)
 178.109  
 178.110 -# Stable samevm testruns (minus items from PROBLEM_LIST)
 178.111 +# Stable agentvm testruns (minus items from PROBLEM_LIST)
 178.112  JDK_ALL_TARGETS += jdk_lang
 178.113  jdk_lang: $(call TestDirs, java/lang)
 178.114 -	$(call RunSamevmBatch)
 178.115 +	$(call RunAgentvmBatch)
 178.116  
 178.117  # Stable othervm testruns (minus items from PROBLEM_LIST)
 178.118 -#   Using samevm has serious problems with these tests
 178.119 +#   Using agentvm has serious problems with these tests
 178.120  JDK_ALL_TARGETS += jdk_management1
 178.121  jdk_management1: $(call TestDirs, javax/management)
 178.122  	$(call RunOthervmBatch)
 178.123  
 178.124  # Stable othervm testruns (minus items from PROBLEM_LIST)
 178.125 -#   Using samevm has serious problems with these tests
 178.126 +#   Using agentvm has serious problems with these tests
 178.127  JDK_ALL_TARGETS += jdk_management2
 178.128  jdk_management2: $(call TestDirs, com/sun/jmx com/sun/management sun/management)
 178.129  	$(call RunOthervmBatch)
 178.130 @@ -479,114 +483,114 @@
 178.131  jdk_management: jdk_management1 jdk_management2
 178.132  	@$(SummaryInfo)
 178.133  
 178.134 -# Stable samevm testruns (minus items from PROBLEM_LIST)
 178.135 +# Stable agentvm testruns (minus items from PROBLEM_LIST)
 178.136  JDK_ALL_TARGETS += jdk_math
 178.137  jdk_math: $(call TestDirs, java/math)
 178.138 -	$(call RunSamevmBatch)
 178.139 +	$(call RunAgentvmBatch)
 178.140  
 178.141 -# Stable samevm testruns (minus items from PROBLEM_LIST)
 178.142 +# Stable agentvm testruns (minus items from PROBLEM_LIST)
 178.143  JDK_ALL_TARGETS += jdk_misc
 178.144  jdk_misc: $(call TestDirs, \
 178.145            demo/jvmti demo/zipfs javax/naming javax/script \
 178.146            javax/smartcardio com/sun/jndi com/sun/xml sun/misc)
 178.147 -	$(call RunSamevmBatch)
 178.148 +	$(call RunAgentvmBatch)
 178.149  
 178.150 -# Stable samevm testruns (minus items from PROBLEM_LIST)
 178.151 +# Stable agentvm testruns (minus items from PROBLEM_LIST)
 178.152  JDK_ALL_TARGETS += jdk_net
 178.153  jdk_net: $(call TestDirs, com/sun/net java/net sun/net)
 178.154 -	$(call RunSamevmBatch)
 178.155 +	$(call RunAgentvmBatch)
 178.156  
 178.157 -# Stable samevm testruns (minus items from PROBLEM_LIST)
 178.158 +# Stable agentvm testruns (minus items from PROBLEM_LIST)
 178.159  JDK_ALL_TARGETS += jdk_nio1
 178.160  jdk_nio1: $(call TestDirs, java/nio/file)
 178.161 -	$(call RunSamevmBatch)
 178.162 +	$(call RunAgentvmBatch)
 178.163  
 178.164 -# Stable samevm testruns (minus items from PROBLEM_LIST)
 178.165 +# Stable agentvm testruns (minus items from PROBLEM_LIST)
 178.166  JDK_ALL_TARGETS += jdk_nio2
 178.167  jdk_nio2: $(call TestDirs, java/nio/Buffer java/nio/ByteOrder \
 178.168            java/nio/channels java/nio/MappedByteBuffer)
 178.169  	$(call SharedLibraryPermissions,java/nio/channels)
 178.170 -	$(call RunSamevmBatch)
 178.171 +	$(call RunAgentvmBatch)
 178.172  
 178.173 -# Stable samevm testruns (minus items from PROBLEM_LIST)
 178.174 +# Stable agentvm testruns (minus items from PROBLEM_LIST)
 178.175  JDK_ALL_TARGETS += jdk_nio3
 178.176  jdk_nio3: $(call TestDirs, sun/nio)
 178.177 -	$(call RunSamevmBatch)
 178.178 +	$(call RunAgentvmBatch)
 178.179  
 178.180  # All nio tests
 178.181  jdk_nio: jdk_nio1 jdk_nio2 jdk_nio3
 178.182  	@$(SummaryInfo)
 178.183  
 178.184 -# Stable samevm testruns (minus items from PROBLEM_LIST)
 178.185 +# Stable agentvm testruns (minus items from PROBLEM_LIST)
 178.186  jdk_sctp: $(call TestDirs, com/sun/nio/sctp)
 178.187 -	$(call RunSamevmBatch)
 178.188 +	$(call RunAgentvmBatch)
 178.189  
 178.190  # Stable othervm testruns (minus items from PROBLEM_LIST)
 178.191 -#   Using samevm has serious problems with these tests
 178.192 +#   Using agentvm has serious problems with these tests
 178.193  JDK_ALL_TARGETS += jdk_rmi
 178.194  jdk_rmi: $(call TestDirs, java/rmi javax/rmi sun/rmi)
 178.195  	$(call RunOthervmBatch)
 178.196  
 178.197 -# Stable samevm testruns (minus items from PROBLEM_LIST)
 178.198 +# Stable agentvm testruns (minus items from PROBLEM_LIST)
 178.199  JDK_ALL_TARGETS += jdk_security1
 178.200  jdk_security1: $(call TestDirs, java/security)
 178.201 -	$(call RunSamevmBatch)
 178.202 +	$(call RunAgentvmBatch)
 178.203  
 178.204 -# Stable samevm testruns (minus items from PROBLEM_LIST)
 178.205 +# Stable agentvm testruns (minus items from PROBLEM_LIST)
 178.206  JDK_ALL_TARGETS += jdk_security2
 178.207  jdk_security2: $(call TestDirs, javax/crypto javax/xml/crypto com/sun/crypto)
 178.208 -	$(call RunSamevmBatch)
 178.209 +	$(call RunAgentvmBatch)
 178.210  
 178.211 -# Stable samevm testruns (minus items from PROBLEM_LIST)
 178.212 +# Stable agentvm testruns (minus items from PROBLEM_LIST)
 178.213  JDK_ALL_TARGETS += jdk_security3
 178.214  jdk_security3: $(call TestDirs, com/sun/security lib/security javax/security \
 178.215          sun/security com/sun/org/apache/xml/internal/security)
 178.216  	$(call SharedLibraryPermissions,sun/security)
 178.217 -	$(call RunSamevmBatch)
 178.218 +	$(call RunAgentvmBatch)
 178.219  
 178.220  # All security tests
 178.221  jdk_security: jdk_security1 jdk_security2 jdk_security3
 178.222  	@$(SummaryInfo)
 178.223  
 178.224 -# Stable samevm testruns (minus items from PROBLEM_LIST)
 178.225 +# Stable agentvm testruns (minus items from PROBLEM_LIST)
 178.226  JDK_ALL_TARGETS += jdk_sound
 178.227  jdk_sound: $(call TestDirs, javax/sound)
 178.228 -	$(call RunSamevmBatch)
 178.229 +	$(call RunAgentvmBatch)
 178.230  
 178.231  # Stable othervm testruns (minus items from PROBLEM_LIST)
 178.232 -#   Using samevm has problems, and doesn't help performance as much as others.
 178.233 +#   Using agentvm has problems, and doesn't help performance as much as others.
 178.234  JDK_ALL_TARGETS += jdk_swing
 178.235  jdk_swing: $(call TestDirs, javax/swing sun/java2d \
 178.236             demo/jfc com/sun/java/swing)
 178.237  	$(call RunOthervmBatch)
 178.238  
 178.239 -# Stable samevm testruns (minus items from PROBLEM_LIST)
 178.240 +# Stable agentvm testruns (minus items from PROBLEM_LIST)
 178.241  JDK_ALL_TARGETS += jdk_text
 178.242  jdk_text: $(call TestDirs, java/text sun/text)
 178.243 -	$(call RunSamevmBatch)
 178.244 +	$(call RunAgentvmBatch)
 178.245  
 178.246 -# Stable samevm testruns (minus items from PROBLEM_LIST)
 178.247 +# Stable agentvm testruns (minus items from PROBLEM_LIST)
 178.248  JDK_ALL_TARGETS += jdk_tools1
 178.249  jdk_tools1: $(call TestDirs, com/sun/jdi)
 178.250 -	$(call RunSamevmBatch)
 178.251 +	$(call RunAgentvmBatch)
 178.252  
 178.253  # Stable othervm testruns (minus items from PROBLEM_LIST)
 178.254 -#   Using samevm has serious problems with these tests
 178.255 +#   Using agentvm has serious problems with these tests
 178.256  JDK_ALL_TARGETS += jdk_tools2
 178.257  jdk_tools2: $(call TestDirs, \
 178.258              com/sun/tools sun/jvmstat sun/tools tools vm \
 178.259              com/sun/servicetag com/sun/tracing)
 178.260  	$(call SharedLibraryPermissions,tools/launcher)
 178.261 -	$(call RunSamevmBatch)
 178.262 +	$(call RunAgentvmBatch)
 178.263  
 178.264  # All tools tests
 178.265  jdk_tools: jdk_tools1 jdk_tools2
 178.266  	@$(SummaryInfo)
 178.267  
 178.268 -# Stable samevm testruns (minus items from PROBLEM_LIST)
 178.269 +# Stable agentvm testruns (minus items from PROBLEM_LIST)
 178.270  JDK_ALL_TARGETS += jdk_util
 178.271  jdk_util: $(call TestDirs, java/util sun/util)
 178.272 -	$(call RunSamevmBatch)
 178.273 +	$(call RunAgentvmBatch)
 178.274  
 178.275  # ------------------------------------------------------------------
 178.276  
 178.277 @@ -603,7 +607,7 @@
 178.278  
 178.279  # Default JTREG to run (win32 script works for everybody)
 178.280  JTREG = $(JT_HOME)/win32/bin/jtreg
 178.281 -# Add any extra options (samevm etc.)
 178.282 +# Add any extra options (agentvm etc.)
 178.283  JTREG_BASIC_OPTIONS += $(EXTRA_JTREG_OPTIONS)
 178.284  # Only run automatic tests
 178.285  JTREG_BASIC_OPTIONS += -a
   179.1 --- a/test/ProblemList.txt	Fri Sep 30 17:20:56 2011 -0700
   179.2 +++ b/test/ProblemList.txt	Tue Oct 04 12:39:42 2011 -0700
   179.3 @@ -43,11 +43,11 @@
   179.4  #
   179.5  # List items  are testnames followed by labels, all MUST BE commented
   179.6  #   as to why they are here and use a label:
   179.7 -#     generic-all	Problems on all platforms
   179.8 -#     generic-ARCH	Where ARCH is one of: sparc, sparcv9, x64, i586, etc.
   179.9 -#     OSNAME-all	Where OSNAME is one of: solaris, linux, windows
  179.10 -#     OSNAME-ARCH	Specific on to one OSNAME and ARCH, e.g. solaris-x64
  179.11 -#     OSNAME-REV	Specific on to one OSNAME and REV, e.g. solaris-5.8
  179.12 +#     generic-all       Problems on all platforms
  179.13 +#     generic-ARCH      Where ARCH is one of: sparc, sparcv9, x64, i586, etc.
  179.14 +#     OSNAME-all        Where OSNAME is one of: solaris, linux, windows
  179.15 +#     OSNAME-ARCH       Specific on to one OSNAME and ARCH, e.g. solaris-x64
  179.16 +#     OSNAME-REV        Specific on to one OSNAME and REV, e.g. solaris-5.8
  179.17  #
  179.18  # More than one label is allowed but must be on the same line.
  179.19  #
  179.20 @@ -123,38 +123,38 @@
  179.21  java/awt/event/MouseEvent/AcceptExtraButton/AcceptExtraButton.java generic-all
  179.22  
  179.23  # Causes hang in samevm mode??? Solaris 11 i586
  179.24 -java/awt/FullScreen/SetFSWindow/FSFrame.java			generic-all
  179.25 +java/awt/FullScreen/SetFSWindow/FSFrame.java                    generic-all
  179.26  
  179.27  # Fails on solaris 11 i586, -client, in othervm mode not sure why
  179.28 -java/awt/Component/PrintAllXcheckJNI/PrintAllXcheckJNI.java	generic-all
  179.29 +java/awt/Component/PrintAllXcheckJNI/PrintAllXcheckJNI.java     generic-all
  179.30  java/awt/Focus/CloseDialogActivateOwnerTest/CloseDialogActivateOwnerTest.java generic-all
  179.31 -java/awt/FontClass/FontAccess.java				generic-all
  179.32 -java/awt/Mixing/HWDisappear.java				generic-all
  179.33 -java/awt/Mixing/MixingInHwPanel.java				generic-all
  179.34 -java/awt/Mouse/MaximizedFrameTest/MaximizedFrameTest.html	generic-all
  179.35 +java/awt/FontClass/FontAccess.java                              generic-all
  179.36 +java/awt/Mixing/HWDisappear.java                                generic-all
  179.37 +java/awt/Mixing/MixingInHwPanel.java                            generic-all
  179.38 +java/awt/Mouse/MaximizedFrameTest/MaximizedFrameTest.html       generic-all
  179.39  java/awt/Robot/AcceptExtraMouseButtons/AcceptExtraMouseButtons.java generic-all
  179.40 -java/awt/Toolkit/SecurityTest/SecurityTest2.java		generic-all
  179.41 -java/awt/image/mlib/MlibOpsTest.java				generic-all
  179.42 +java/awt/Toolkit/SecurityTest/SecurityTest2.java                generic-all
  179.43 +java/awt/image/mlib/MlibOpsTest.java                            generic-all
  179.44  
  179.45  # Fails on windows, othervm mode, various errors
  179.46 -java/awt/Focus/NonFocusableWindowTest/NonfocusableOwnerTest.java	generic-all
  179.47 -java/awt/Focus/OwnedWindowFocusIMECrashTest/OwnedWindowFocusIMECrashTest.java	generic-all
  179.48 -java/awt/FullScreen/NoResizeEventOnDMChangeTest/NoResizeEventOnDMChangeTest.java	generic-all
  179.49 -java/awt/Mouse/MouseModifiersUnitTest/MouseModifiersUnitTest_Standard.java	generic-all
  179.50 -java/awt/event/KeyEvent/KeyTyped/CtrlASCII.html			generic-all
  179.51 -java/awt/font/Threads/FontThread.java				generic-all
  179.52 -java/awt/print/PrinterJob/PrtException.java			generic-all
  179.53 +java/awt/Focus/NonFocusableWindowTest/NonfocusableOwnerTest.java        generic-all
  179.54 +java/awt/Focus/OwnedWindowFocusIMECrashTest/OwnedWindowFocusIMECrashTest.java   generic-all
  179.55 +java/awt/FullScreen/NoResizeEventOnDMChangeTest/NoResizeEventOnDMChangeTest.java        generic-all
  179.56 +java/awt/Mouse/MouseModifiersUnitTest/MouseModifiersUnitTest_Standard.java      generic-all
  179.57 +java/awt/event/KeyEvent/KeyTyped/CtrlASCII.html                 generic-all
  179.58 +java/awt/font/Threads/FontThread.java                           generic-all
  179.59 +java/awt/print/PrinterJob/PrtException.java                     generic-all
  179.60  
  179.61  # Fails with windows X64, othervm, -server
  179.62 -com/sun/awt/Translucency/WindowOpacity.java			generic-all
  179.63 -java/awt/EventDispatchThread/HandleExceptionOnEDT/HandleExceptionOnEDT.java		generic-all
  179.64 -java/awt/EventDispatchThread/LoopRobustness/LoopRobustness.html	generic-all
  179.65 +com/sun/awt/Translucency/WindowOpacity.java                     generic-all
  179.66 +java/awt/EventDispatchThread/HandleExceptionOnEDT/HandleExceptionOnEDT.java             generic-all
  179.67 +java/awt/EventDispatchThread/LoopRobustness/LoopRobustness.html generic-all
  179.68  java/awt/Focus/AppletInitialFocusTest/AppletInitialFocusTest1.html generic-all
  179.69  java/awt/Focus/FocusEmbeddedFrameTest/FocusEmbeddedFrameTest.java generic-all
  179.70 -java/awt/Frame/LayoutOnMaximizeTest/LayoutOnMaximizeTest.java	generic-all
  179.71 -java/awt/FullScreen/TranslucentWindow/TranslucentWindow.java	generic-all
  179.72 -java/awt/Mixing/MixingOnShrinkingHWButton.java			generic-all
  179.73 -java/awt/Mouse/MouseModifiersUnitTest/ExtraButtonDrag.java	generic-all
  179.74 +java/awt/Frame/LayoutOnMaximizeTest/LayoutOnMaximizeTest.java   generic-all
  179.75 +java/awt/FullScreen/TranslucentWindow/TranslucentWindow.java    generic-all
  179.76 +java/awt/Mixing/MixingOnShrinkingHWButton.java                  generic-all
  179.77 +java/awt/Mouse/MouseModifiersUnitTest/ExtraButtonDrag.java      generic-all
  179.78  
  179.79  ############################################################################
  179.80  
  179.81 @@ -166,30 +166,30 @@
  179.82  #  So a large batch of beans tests are currently run with othervm mode.
  179.83  
  179.84  # Filed 6986807
  179.85 -java/beans/Introspector/TestTypeResolver.java   		generic-all
  179.86 +java/beans/Introspector/TestTypeResolver.java                   generic-all
  179.87  
  179.88  # Filed 6986813
  179.89 -java/beans/Introspector/memory/Test4508780.java			generic-all
  179.90 +java/beans/Introspector/memory/Test4508780.java                 generic-all
  179.91  
  179.92  # Linux, some kind of problems with X11 display
  179.93 -java/beans/PropertyChangeSupport/Test4682386.java		generic-all
  179.94 -java/beans/PropertyChangeSupport/TestSynchronization.java	generic-all
  179.95 -java/beans/Statement/Test4653179.java				generic-all
  179.96 +java/beans/PropertyChangeSupport/Test4682386.java               generic-all
  179.97 +java/beans/PropertyChangeSupport/TestSynchronization.java       generic-all
  179.98 +java/beans/Statement/Test4653179.java                           generic-all
  179.99  
 179.100  # Runs REALLY slow on Solaris sparc for some reason, both -client and -server
 179.101 -java/beans/XMLEncoder/Test4625418.java				solaris-sparc
 179.102 +java/beans/XMLEncoder/Test4625418.java                          solaris-sparc
 179.103  
 179.104  # Problems with samevm and setting security manager (speculation partially)
 179.105 -java/beans/Introspector/4168475/Test4168475.java		generic-all
 179.106 -java/beans/Introspector/4520754/Test4520754.java		generic-all
 179.107 -java/beans/Introspector/6380849/TestBeanInfo.java		generic-all
 179.108 -java/beans/Introspector/Test4144543.java			generic-all
 179.109 +java/beans/Introspector/4168475/Test4168475.java                generic-all
 179.110 +java/beans/Introspector/4520754/Test4520754.java                generic-all
 179.111 +java/beans/Introspector/6380849/TestBeanInfo.java               generic-all
 179.112 +java/beans/Introspector/Test4144543.java                        generic-all
 179.113  
 179.114  # Failed to call method solaris-sparc???
 179.115 -java/beans/EventHandler/Test6788531.java		 	generic-all
 179.116 +java/beans/EventHandler/Test6788531.java                        generic-all
 179.117  
 179.118  # Jar or class not found???
 179.119 -java/beans/XMLEncoder/6329581/Test6329581.java		 	generic-all
 179.120 +java/beans/XMLEncoder/6329581/Test6329581.java                  generic-all
 179.121  
 179.122  ############################################################################
 179.123  
 179.124 @@ -199,26 +199,26 @@
 179.125  java/lang/invoke/InvokeDynamicPrintArgs.java                    generic-all
 179.126  
 179.127  # 7079093
 179.128 -java/lang/instrument/ManifestTest.sh				windows-all
 179.129 +java/lang/instrument/ManifestTest.sh                            windows-all
 179.130  
 179.131  ############################################################################
 179.132  
 179.133  # jdk_management
 179.134  
 179.135  # 6944188
 179.136 -java/lang/management/ThreadMXBean/ThreadStateTest.java		generic-all
 179.137 +java/lang/management/ThreadMXBean/ThreadStateTest.java          generic-all
 179.138  
 179.139  # 7067973
 179.140  java/lang/management/MemoryMXBean/CollectionUsageThreshold.java generic-all
 179.141  
 179.142  # Failing, bug was filed: 6959636
 179.143 -javax/management/loading/LibraryLoader/LibraryLoaderTest.java	generic-all
 179.144 +javax/management/loading/LibraryLoader/LibraryLoaderTest.java   generic-all
 179.145  
 179.146  # Access denied messages on windows/mks, filed 6954450
 179.147 -sun/management/jmxremote/bootstrap/RmiSslNoKeyStoreTest.sh	windows-all
 179.148 +sun/management/jmxremote/bootstrap/RmiSslNoKeyStoreTest.sh      windows-all
 179.149  
 179.150  # Fails on linux: KO: StringMonitor notification missed or not emitted
 179.151 -javax/management/monitor/NonComparableAttributeValueTest.java	generic-all
 179.152 +javax/management/monitor/NonComparableAttributeValueTest.java   generic-all
 179.153  
 179.154  # Port conflict? Fails with communication error
 179.155  sun/management/jmxremote/bootstrap/PasswordFilePermissionTest.sh generic-all
 179.156 @@ -229,10 +229,10 @@
 179.157  javax/management/remote/mandatory/connection/ReconnectTest.java generic-all
 179.158  
 179.159  # Solaris 10 sparc, NPE from org.omg.stub.javax.management.remote.rmi._RMIConnectionImpl_Tie._invoke
 179.160 -javax/management/remote/mandatory/threads/ExecutorTest.java 	generic-all
 179.161 +javax/management/remote/mandatory/threads/ExecutorTest.java     generic-all
 179.162  
 179.163  # Linux 32bit Fedora 9, IllegalStateException
 179.164 -javax/management/monitor/RuntimeExceptionTest.java		generic-all
 179.165 +javax/management/monitor/RuntimeExceptionTest.java              generic-all
 179.166  
 179.167  # Problems with rmi connection, othervm
 179.168  javax/management/remote/mandatory/subjectDelegation/SubjectDelegation2Test.java generic-all
 179.169 @@ -241,16 +241,16 @@
 179.170  sun/management/jmxremote/bootstrap/SSLConfigFilePermissionTest.sh generic-all
 179.171  
 179.172  # Fails with port already in use
 179.173 -sun/management/jmxremote/bootstrap/RmiRegistrySslTest.sh	generic-all
 179.174 +sun/management/jmxremote/bootstrap/RmiRegistrySslTest.sh        generic-all
 179.175  
 179.176  # Windows, connection can't last that long
 179.177 -javax/management/eventService/LeaseTest.java			generic-all
 179.178 +javax/management/eventService/LeaseTest.java                    generic-all
 179.179  
 179.180  # Linux othervm, X64, java.lang.Exception: Failed: ratio=102.4027795593753
 179.181 -javax/management/remote/mandatory/notif/ListenerScaleTest.java	generic-all
 179.182 +javax/management/remote/mandatory/notif/ListenerScaleTest.java  generic-all
 179.183  
 179.184  # Windows run seems to have triggered a hotspot gc error (see 6801625)
 179.185 -com/sun/management/HotSpotDiagnosticMXBean/DumpHeap.sh		generic-all
 179.186 +com/sun/management/HotSpotDiagnosticMXBean/DumpHeap.sh          generic-all
 179.187  
 179.188  # rmi problem? othervm, java.lang.reflect.UndeclaredThrowableException
 179.189  javax/management/remote/mandatory/subjectDelegation/SubjectDelegation3Test.java generic-all
 179.190 @@ -259,30 +259,30 @@
 179.191  javax/management/remote/mandatory/notif/NotificationBufferDeadlockTest.java generic-all
 179.192  
 179.193  # Times out on solaris sparc, with othervm
 179.194 -javax/management/eventService/AddRemoveListenerTest.java	generic-all
 179.195 +javax/management/eventService/AddRemoveListenerTest.java        generic-all
 179.196  
 179.197  # Linux i586 and x64 -server, timed out waiting for threads to expire? othervm
 179.198 -javax/management/eventService/EventClientThreadTest.java	generic-all
 179.199 +javax/management/eventService/EventClientThreadTest.java        generic-all
 179.200  
 179.201  # Linux i586 -server, Expected to receive 20, but got 21, othervm
 179.202  #   Fails on Linux X64 -server 20!=21
 179.203 -javax/management/eventService/FetchingTest.java			generic-all
 179.204 +javax/management/eventService/FetchingTest.java                 generic-all
 179.205  
 179.206  # NPE on windows 2000 i586 -client and -server
 179.207 -javax/management/eventService/CustomForwarderTest.java	 	windows-all
 179.208 +javax/management/eventService/CustomForwarderTest.java          windows-all
 179.209  
 179.210  # Windows i586 failure, callback did not complete
 179.211 -javax/management/eventService/LeaseManagerDeadlockTest.java 	windows-all
 179.212 +javax/management/eventService/LeaseManagerDeadlockTest.java     windows-all
 179.213  
 179.214  # Port already in use
 179.215 -sun/management/jmxremote/bootstrap/LocalManagementTest.sh 	generic-all
 179.216 +sun/management/jmxremote/bootstrap/LocalManagementTest.sh       generic-all
 179.217  
 179.218  # Failed to initialize connector (also overflowing jtreg io buffers)
 179.219 -sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh	 	generic-all
 179.220 -sun/management/jmxremote/bootstrap/RmiSslBootstrapTest.sh 	generic-all
 179.221 +sun/management/jmxremote/bootstrap/RmiBootstrapTest.sh          generic-all
 179.222 +sun/management/jmxremote/bootstrap/RmiSslBootstrapTest.sh       generic-all
 179.223  
 179.224  # Windows X64, java.lang.IllegalStateException
 179.225 -javax/management/monitor/AttributeArbitraryDataTypeTest.java	generic-all
 179.226 +javax/management/monitor/AttributeArbitraryDataTypeTest.java    generic-all
 179.227  
 179.228  ############################################################################
 179.229  
 179.230 @@ -293,92 +293,89 @@
 179.231  # jdk_misc
 179.232  
 179.233  # Need to be marked othervm, or changed to be samevm safe
 179.234 -com/sun/jndi/rmi/registry/RegistryContext/UnbindIdempotent.java	generic-all
 179.235 +com/sun/jndi/rmi/registry/RegistryContext/UnbindIdempotent.java generic-all
 179.236  
 179.237  # Need to be marked othervm, or changed to be samevm safe
 179.238  com/sun/org/apache/xml/internal/security/transforms/ClassLoaderTest.java generic-all
 179.239  
 179.240  # Solaris sparc and others, exception in initializer
 179.241 -javax/imageio/CachePremissionsTest/CachePermissionsTest.java 	generic-all
 179.242 +javax/imageio/CachePremissionsTest/CachePermissionsTest.java    generic-all
 179.243  
 179.244  # Leaves file rgba_* open, fails with windows samevm
 179.245 -javax/imageio/plugins/png/PngOutputTypeTest.java		generic-all
 179.246 +javax/imageio/plugins/png/PngOutputTypeTest.java                generic-all
 179.247  
 179.248  # Suspect test.png file is left open, windows samevm problems
 179.249 -javax/imageio/plugins/png/ITXtTest.java				generic-all
 179.250 +javax/imageio/plugins/png/ITXtTest.java                         generic-all
 179.251  
 179.252  # Solaris sparc and others, failed to compile testcase
 179.253 -javax/imageio/metadata/DOML3Node.java			 	generic-all
 179.254 +javax/imageio/metadata/DOML3Node.java                           generic-all
 179.255  
 179.256  # One of these tests is leaving file IMGP1001.JPG open, windows samevm
 179.257 -javax/imageio/plugins/jpeg/ConcurrentReadingTest.java		generic-all
 179.258 -javax/imageio/plugins/jpeg/ReadingInterruptionTest.java		generic-all
 179.259 +javax/imageio/plugins/jpeg/ConcurrentReadingTest.java           generic-all
 179.260 +javax/imageio/plugins/jpeg/ReadingInterruptionTest.java         generic-all
 179.261  
 179.262  # One of these files is missing a close on writer_* files, windows samevm
 179.263 -javax/imageio/plugins/jpeg/ConcurrentWritingTest.java		generic-all
 179.264 -javax/imageio/plugins/jpeg/WritingInterruptionTest.java		generic-all
 179.265 +javax/imageio/plugins/jpeg/ConcurrentWritingTest.java           generic-all
 179.266 +javax/imageio/plugins/jpeg/WritingInterruptionTest.java         generic-all
 179.267  
 179.268  # Leaving file test.jpg open, windows samevm
 179.269 -javax/imageio/plugins/jpeg/ReadAsGrayTest.java			generic-all
 179.270 +javax/imageio/plugins/jpeg/ReadAsGrayTest.java                  generic-all
 179.271  
 179.272  # Missing close on file wbmp*, windows samevm
 179.273 -javax/imageio/plugins/wbmp/CanDecodeTest.java			generic-all
 179.274 +javax/imageio/plugins/wbmp/CanDecodeTest.java                   generic-all
 179.275  
 179.276  # Failures on OpenSolaris, cannot read input files? samevm issues?
 179.277 -javax/imageio/metadata/BooleanAttributes.java			generic-all
 179.278 -javax/imageio/plugins/bmp/BMPSubsamplingTest.java		generic-all
 179.279 -javax/imageio/plugins/bmp/TopDownTest.java			generic-all
 179.280 -javax/imageio/plugins/gif/EncodeSubImageTest.java		generic-all
 179.281 -javax/imageio/plugins/gif/GifTransparencyTest.java		generic-all
 179.282 -javax/imageio/plugins/png/GrayPngTest.java			generic-all
 179.283 -javax/imageio/plugins/png/ItxtUtf8Test.java			generic-all
 179.284 -javax/imageio/plugins/png/MergeStdCommentTest.java		generic-all
 179.285 -javax/imageio/plugins/png/ShortHistogramTest.java		generic-all
 179.286 -javax/imageio/plugins/shared/BitDepth.java			generic-all
 179.287 +javax/imageio/metadata/BooleanAttributes.java                   generic-all
 179.288 +javax/imageio/plugins/bmp/BMPSubsamplingTest.java               generic-all
 179.289 +javax/imageio/plugins/bmp/TopDownTest.java                      generic-all
 179.290 +javax/imageio/plugins/gif/EncodeSubImageTest.java               generic-all
 179.291 +javax/imageio/plugins/gif/GifTransparencyTest.java              generic-all
 179.292 +javax/imageio/plugins/png/GrayPngTest.java                      generic-all
 179.293 +javax/imageio/plugins/png/ItxtUtf8Test.java                     generic-all
 179.294 +javax/imageio/plugins/png/MergeStdCommentTest.java              generic-all
 179.295 +javax/imageio/plugins/png/ShortHistogramTest.java               generic-all
 179.296 +javax/imageio/plugins/shared/BitDepth.java                      generic-all
 179.297  
 179.298  # Exclude all javax/print tests, even if they passed, they may need samevm work
 179.299  
 179.300  # Times out on solaris-sparc, sparcv9, x64 -server, some on i586 -client
 179.301 -javax/print/attribute/autosense/PrintAutoSenseData.java 	generic-all
 179.302 -javax/print/attribute/Chroma.java			 	generic-all
 179.303 -javax/print/attribute/CollateAttr.java			 	generic-all
 179.304 -javax/print/attribute/PSCopiesFlavorTest.java		 	generic-all
 179.305 -javax/print/LookupServices.java 			 	generic-all
 179.306 -javax/print/TestRaceCond.java				 	generic-all
 179.307 +javax/print/attribute/autosense/PrintAutoSenseData.java         generic-all
 179.308 +javax/print/attribute/Chroma.java                               generic-all
 179.309 +javax/print/attribute/CollateAttr.java                          generic-all
 179.310 +javax/print/attribute/PSCopiesFlavorTest.java                   generic-all
 179.311 +javax/print/LookupServices.java                                 generic-all
 179.312 +javax/print/TestRaceCond.java                                   generic-all
 179.313  
 179.314  # These tests really require a printer (might all be windows only tests?)
 179.315 -javax/print/CheckDupFlavor.java					generic-all
 179.316 -javax/print/PrintSE/PrintSE.sh					generic-all
 179.317 -javax/print/attribute/ChromaticityValues.java			generic-all
 179.318 -javax/print/attribute/GetCopiesSupported.java			generic-all
 179.319 -javax/print/attribute/SidesPageRangesTest.java			generic-all
 179.320 -javax/print/attribute/SupportedPrintableAreas.java		generic-all
 179.321 +javax/print/CheckDupFlavor.java                                 generic-all
 179.322 +javax/print/PrintSE/PrintSE.sh                                  generic-all
 179.323 +javax/print/attribute/ChromaticityValues.java                   generic-all
 179.324 +javax/print/attribute/GetCopiesSupported.java                   generic-all
 179.325 +javax/print/attribute/SidesPageRangesTest.java                  generic-all
 179.326 +javax/print/attribute/SupportedPrintableAreas.java              generic-all
 179.327  javax/print/attribute/AttributeTest.java                        generic-all
 179.328  
 179.329  # Only print test left, excluding just because all print tests have been
 179.330 -javax/print/attribute/MediaMappingsTest.java 			generic-all
 179.331 +javax/print/attribute/MediaMappingsTest.java                    generic-all
 179.332  
 179.333  # Filed 7058852
 179.334 -javax/sound/sampled/FileWriter/AlawEncoderSync.java		generic-all
 179.335 +javax/sound/sampled/FileWriter/AlawEncoderSync.java             generic-all
 179.336  
 179.337  ############################################################################
 179.338  
 179.339  # jdk_net
 179.340  
 179.341  # Filed 7052625
 179.342 -com/sun/net/httpserver/bugs/6725892/Test.java			generic-all
 179.343 +com/sun/net/httpserver/bugs/6725892/Test.java                   generic-all
 179.344  
 179.345  # Filed 7036666
 179.346 -com/sun/net/httpserver/Test9a.java				generic-all
 179.347 +com/sun/net/httpserver/Test9a.java                              generic-all
 179.348  
 179.349  # 7079145 java/net/ipv6tests/UdpTest.java hang at IPv6 only data exchange
 179.350  java/net/ipv6tests/UdpTest.java                                 linux-all
 179.351  
 179.352 -# 7079012
 179.353 -java/net/NetworkInterface/NetParamsTest.java			solaris-all
 179.354 -
 179.355  # 7081476
 179.356 -java/net/InetSocketAddress/B6469803.java			generic-all
 179.357 +java/net/InetSocketAddress/B6469803.java                        generic-all
 179.358  
 179.359  ############################################################################
 179.360  
 179.361 @@ -388,10 +385,10 @@
 179.362  java/io/File/MaxPathLength.java                                 windows-all
 179.363  
 179.364  # 6671616
 179.365 -java/io/File/BlockIsDirectory.java				solaris-all
 179.366 +java/io/File/BlockIsDirectory.java                              solaris-all
 179.367  
 179.368  # 7076644
 179.369 -java/io/File/Basic.java						windows-all
 179.370 +java/io/File/Basic.java                                         windows-all
 179.371  
 179.372  ############################################################################
 179.373  
 179.374 @@ -401,14 +398,14 @@
 179.375  java/nio/channels/Selector/Wakeup.java                          windows-all
 179.376  
 179.377  # 7076700
 179.378 -java/nio/channels/SocketChannel/AdaptSocket.java		generic-all
 179.379 +java/nio/channels/SocketChannel/AdaptSocket.java                generic-all
 179.380  
 179.381  ############################################################################
 179.382  
 179.383  # jdk_rmi
 179.384  
 179.385  # Port already in use, fails on sparc, othervm
 179.386 -java/rmi/reliability/benchmark/runRmiBench.sh			generic-all
 179.387 +java/rmi/reliability/benchmark/runRmiBench.sh                   generic-all
 179.388  
 179.389  # Already in use port issues? othervm solaris
 179.390  java/rmi/activation/rmidViaInheritedChannel/InheritedChannelNotServerSocket.java generic-all
 179.391 @@ -418,21 +415,21 @@
 179.392  java/rmi/transport/dgcDeadLock/TestImpl_Stub.java                       generic-all
 179.393  
 179.394  # Address already in use, othervm mode, solaris
 179.395 -java/rmi/activation/Activatable/elucidateNoSuchMethod/ElucidateNoSuchMethod.java	generic-all
 179.396 -java/rmi/activation/Activatable/forceLogSnapshot/ForceLogSnapshot.java	generic-all
 179.397 +java/rmi/activation/Activatable/elucidateNoSuchMethod/ElucidateNoSuchMethod.java        generic-all
 179.398 +java/rmi/activation/Activatable/forceLogSnapshot/ForceLogSnapshot.java  generic-all
 179.399  
 179.400  # Registry already running on port, solaris
 179.401 -java/rmi/Naming/legalRegistryNames/LegalRegistryNames.java	generic-all
 179.402 +java/rmi/Naming/legalRegistryNames/LegalRegistryNames.java      generic-all
 179.403  
 179.404  # Fails on Linux 32 and 64bit -server?, impl not garbage collected???
 179.405 -java/rmi/transport/pinLastArguments/PinLastArguments.java	generic-all
 179.406 +java/rmi/transport/pinLastArguments/PinLastArguments.java       generic-all
 179.407  
 179.408  # Times out on solaris sparc
 179.409 -java/rmi/server/RemoteServer/AddrInUse.java			generic-all
 179.410 +java/rmi/server/RemoteServer/AddrInUse.java                     generic-all
 179.411  
 179.412  # Connection error on Windows i586 -server
 179.413  #  Also connection errors in othervm on Solaris 10 sparc, same port???
 179.414 -sun/rmi/transport/tcp/DeadCachedConnection.java 	 	generic-all
 179.415 +sun/rmi/transport/tcp/DeadCachedConnection.java                 generic-all
 179.416  
 179.417  # Connection errors in othervm on Solaris 10 sparc, same port???
 179.418  java/rmi/activation/Activatable/checkActivateRef/CheckActivateRef.java generic-all
 179.419 @@ -478,20 +475,20 @@
 179.420  # jdk_security
 179.421  
 179.422  # Failing on Solaris i586, 3/9/2010, not a -samevm issue (jdk_security3)
 179.423 -sun/security/pkcs11/Secmod/AddPrivateKey.java			solaris-i586
 179.424 -sun/security/pkcs11/ec/ReadCertificates.java			solaris-i586
 179.425 -sun/security/pkcs11/ec/ReadPKCS12.java				solaris-i586
 179.426 -sun/security/pkcs11/ec/TestCurves.java				solaris-i586
 179.427 -sun/security/pkcs11/ec/TestECDSA.java				solaris-i586
 179.428 -#sun/security/pkcs11/ec/TestECGenSpec.java			solaris-i586
 179.429 -#sun/security/pkcs11/ec/TestKeyFactory.java			solaris-i586
 179.430 -sun/security/pkcs11/sslecc/ClientJSSEServerJSSE.java		solaris-i586
 179.431 +sun/security/pkcs11/Secmod/AddPrivateKey.java                   solaris-i586
 179.432 +sun/security/pkcs11/ec/ReadCertificates.java                    solaris-i586
 179.433 +sun/security/pkcs11/ec/ReadPKCS12.java                          solaris-i586
 179.434 +sun/security/pkcs11/ec/TestCurves.java                          solaris-i586
 179.435 +sun/security/pkcs11/ec/TestECDSA.java                           solaris-i586
 179.436 +#sun/security/pkcs11/ec/TestECGenSpec.java                      solaris-i586
 179.437 +#sun/security/pkcs11/ec/TestKeyFactory.java                     solaris-i586
 179.438 +sun/security/pkcs11/sslecc/ClientJSSEServerJSSE.java            solaris-i586
 179.439  
 179.440  # Directly references PKCS11 class
 179.441  sun/security/pkcs11/Provider/Absolute.java                      windows-x64
 179.442  
 179.443  # Fails on Fedora 9/Ubuntu 10.04 64bit, PKCS11Exception: CKR_DEVICE_ERROR
 179.444 -sun/security/pkcs11/KeyAgreement/TestDH.java			generic-all
 179.445 +sun/security/pkcs11/KeyAgreement/TestDH.java                    generic-all
 179.446  
 179.447  # Run too slow on Solaris 10 sparc
 179.448  sun/security/ssl/com/sun/net/ssl/internal/ssl/InputRecord/SSLSocketTimeoutNulls.java solaris-sparc
 179.449 @@ -508,14 +505,14 @@
 179.450  
 179.451  # Times out on windows X64, othervm mode
 179.452  #    Solaris sparc and sparcv9 -server, timeout
 179.453 -sun/security/ssl/javax/net/ssl/NewAPIs/SessionTimeOutTests.java	generic-all
 179.454 +sun/security/ssl/javax/net/ssl/NewAPIs/SessionTimeOutTests.java generic-all
 179.455  
 179.456  # Various failures on Linux Fedora 9 X64, othervm mode
 179.457  sun/security/ssl/javax/net/ssl/NewAPIs/SSLEngine/TestAllSuites.java generic-all
 179.458 -sun/security/ssl/sanity/ciphersuites/CheckCipherSuites.java	generic-all
 179.459 +sun/security/ssl/sanity/ciphersuites/CheckCipherSuites.java     generic-all
 179.460  
 179.461  # Various failures on Linux Fedora 9 X64, othervm mode
 179.462 -sun/security/ssl/sanity/interop/ClientJSSEServerJSSE.java	generic-all
 179.463 +sun/security/ssl/sanity/interop/ClientJSSEServerJSSE.java       generic-all
 179.464  
 179.465  # 7079203 sun/security/tools/keytool/printssl.sh fails on solaris with timeout
 179.466  sun/security/tools/keytool/printssl.sh                          solaris-all
 179.467 @@ -524,7 +521,7 @@
 179.468  sun/security/tools/jarsigner/ec.sh                             solaris-all
 179.469  
 179.470  # 7081817
 179.471 -sun/security/provider/certpath/X509CertPath/IllegalCertiticates.java 	generic-all
 179.472 +sun/security/provider/certpath/X509CertPath/IllegalCertiticates.java    generic-all
 179.473  
 179.474  # 7041639, Solaris DSA keypair generation bug (Note: jdk_util also affected)
 179.475  java/security/KeyPairGenerator/SolarisShortDSA.java             solaris-all
 179.476 @@ -541,57 +538,57 @@
 179.477  # jdk_swing (not using samevm)
 179.478  
 179.479  # Fails on solaris 11 i586, with othervm
 179.480 -javax/swing/JFileChooser/6570445/bug6570445.java		generic-all
 179.481 -javax/swing/JFileChooser/6738668/bug6738668.java		generic-all
 179.482 -javax/swing/JPopupMenu/6675802/bug6675802.java			generic-all
 179.483 -javax/swing/system/6799345/TestShutdown.java			generic-all
 179.484 +javax/swing/JFileChooser/6570445/bug6570445.java                generic-all
 179.485 +javax/swing/JFileChooser/6738668/bug6738668.java                generic-all
 179.486 +javax/swing/JPopupMenu/6675802/bug6675802.java                  generic-all
 179.487 +javax/swing/system/6799345/TestShutdown.java                    generic-all
 179.488  
 179.489  ############################################################################
 179.490  
 179.491  # jdk_text
 179.492  
 179.493  # Linux x64 occasional errors, no details
 179.494 -java/text/Bidi/Bug6665028.java				 	linux-x64
 179.495 +java/text/Bidi/Bug6665028.java                                  linux-x64
 179.496  
 179.497  ############################################################################
 179.498  
 179.499  # jdk_tools
 179.500  
 179.501  # Filed 6952105
 179.502 -com/sun/jdi/SuspendThreadTest.java				generic-all
 179.503 +com/sun/jdi/SuspendThreadTest.java                              generic-all
 179.504  
 179.505  # Filed 6653793
 179.506 -com/sun/jdi/RedefineCrossEvent.java				generic-all
 179.507 +com/sun/jdi/RedefineCrossEvent.java                             generic-all
 179.508  
 179.509  # Filed 6987312
 179.510 -com/sun/jdi/DoubleAgentTest.java				generic-all
 179.511 +com/sun/jdi/DoubleAgentTest.java                                generic-all
 179.512  
 179.513  # Filed 7020857
 179.514 -com/sun/jdi/FieldWatchpoints.java				generic-all
 179.515 +com/sun/jdi/FieldWatchpoints.java                               generic-all
 179.516  
 179.517  # Filed 6402201
 179.518 -com/sun/jdi/ProcessAttachTest.sh				generic-all
 179.519 +com/sun/jdi/ProcessAttachTest.sh                                generic-all
 179.520  
 179.521  # Filed 6986875
 179.522 -sun/tools/jps/jps-Vvml.sh					generic-all
 179.523 +sun/tools/jps/jps-Vvml.sh                                       generic-all
 179.524  
 179.525  # Filed 6979016
 179.526 -sun/tools/jconsole/ResourceCheckTest.sh				generic-all
 179.527 +sun/tools/jconsole/ResourceCheckTest.sh                         generic-all
 179.528  
 179.529  ############################################################################
 179.530  
 179.531  # jdk_util
 179.532  
 179.533  # Filed 7027061
 179.534 -java/util/Locale/Bug6989440.java				windows-all
 179.535 +java/util/Locale/Bug6989440.java                                windows-all
 179.536  
 179.537  # Filed 6933803
 179.538 -java/util/concurrent/ThreadPoolExecutor/CoreThreadTimeOut.java	generic-all
 179.539 +java/util/concurrent/ThreadPoolExecutor/CoreThreadTimeOut.java  generic-all
 179.540  
 179.541  # Filed 7022325
 179.542  # Fails with assertion error on windows
 179.543  #   11 separate stacktraces created... file reuse problem?
 179.544 -java/util/zip/ZipFile/ReadLongZipFileName.java			generic-all
 179.545 +java/util/zip/ZipFile/ReadLongZipFileName.java                  generic-all
 179.546  
 179.547  # Filed 6772009
 179.548  java/util/concurrent/locks/ReentrantLock/CancelledLockLoops.java generic-all
   180.1 --- a/test/com/sun/jdi/sde/MangleStepTest.java	Fri Sep 30 17:20:56 2011 -0700
   180.2 +++ b/test/com/sun/jdi/sde/MangleStepTest.java	Tue Oct 04 12:39:42 2011 -0700
   180.3 @@ -10,11 +10,11 @@
   180.4   *  @run build TestScaffold VMConnection TargetListener TargetAdapter InstallSDE
   180.5   *  @run compile MangleStepTest.java
   180.6   *  @run compile -g  onion/pickle/Mangle.java
   180.7 - *  @run main MangleStepTest unset
   180.8 - *  @run main MangleStepTest Java
   180.9 - *  @run main MangleStepTest XYZ
  180.10 - *  @run main MangleStepTest Rats
  180.11 - *  @run main MangleStepTest bogus
  180.12 + *  @run main/othervm MangleStepTest unset
  180.13 + *  @run main/othervm MangleStepTest Java
  180.14 + *  @run main/othervm MangleStepTest XYZ
  180.15 + *  @run main/othervm MangleStepTest Rats
  180.16 + *  @run main/othervm MangleStepTest bogus
  180.17   */
  180.18  import com.sun.jdi.*;
  180.19  import com.sun.jdi.event.*;
   181.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   181.2 +++ b/test/java/io/etc/FileDescriptorSharing.java	Tue Oct 04 12:39:42 2011 -0700
   181.3 @@ -0,0 +1,336 @@
   181.4 +/*
   181.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
   181.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   181.7 + *
   181.8 + * This code is free software; you can redistribute it and/or modify it
   181.9 + * under the terms of the GNU General Public License version 2 only, as
  181.10 + * published by the Free Software Foundation.
  181.11 + *
  181.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  181.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  181.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  181.15 + * version 2 for more details (a copy is included in the LICENSE file that
  181.16 + * accompanied this code).
  181.17 + *
  181.18 + * You should have received a copy of the GNU General Public License version
  181.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  181.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  181.21 + *
  181.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  181.23 + * or visit www.oracle.com if you need additional information or have any
  181.24 + * questions.
  181.25 + */
  181.26 +
  181.27 +/*
  181.28 + * @test
  181.29 + * @bug 6322678 7082769
  181.30 + * @summary FileInputStream/FileOutputStream/RandomAccessFile allow file descriptor
  181.31 + *          to be closed while still in use.
  181.32 + * @run main/othervm FileDescriptorSharing
  181.33 + */
  181.34 +
  181.35 +import java.io.*;
  181.36 +import java.nio.channels.FileChannel;
  181.37 +import java.nio.channels.FileLock;
  181.38 +import java.util.concurrent.CountDownLatch;
  181.39 +
  181.40 +public class FileDescriptorSharing {
  181.41 +
  181.42 +    final static int numFiles = 10;
  181.43 +    volatile static boolean fail;
  181.44 +
  181.45 +    public static void main(String[] args) throws Exception {
  181.46 +        TestFinalizer();
  181.47 +        TestMultipleFD();
  181.48 +        TestIsValid();
  181.49 +        MultiThreadedFD();
  181.50 +    }
  181.51 +
  181.52 +    /**
  181.53 +     * We shouldn't discard a file descriptor until all streams have
  181.54 +     * finished with it
  181.55 +     */
  181.56 +    private static void TestFinalizer() throws Exception {
  181.57 +        FileDescriptor fd = null;
  181.58 +        File tempFile = new File("TestFinalizer1.txt");
  181.59 +        tempFile.deleteOnExit();
  181.60 +        try (Writer writer = new FileWriter(tempFile)) {
  181.61 +            for (int i=0; i<5; i++) {
  181.62 +                writer.write("test file content test file content");
  181.63 +            }
  181.64 +        }
  181.65 +
  181.66 +        FileInputStream fis1 = new FileInputStream(tempFile);
  181.67 +        fd = fis1.getFD();
  181.68 +        // Create a new FIS based on the existing FD (so the two FIS's share the same native fd)
  181.69 +        try (FileInputStream fis2 = new FileInputStream(fd)) {
  181.70 +            // allow fis1 to be gc'ed
  181.71 +            fis1 = null;
  181.72 +            int ret = 0;
  181.73 +            while(ret >= 0) {
  181.74 +                // encourage gc
  181.75 +                System.gc();
  181.76 +                // read from fis2 - when fis1 is gc'ed and finalizer is run, read will fail
  181.77 +                System.out.print(".");
  181.78 +                ret = fis2.read();
  181.79 +            }
  181.80 +        }
  181.81 +
  181.82 +        // variation of above. Use RandomAccessFile to obtain a filedescriptor
  181.83 +        File testFinalizerFile = new File("TestFinalizer");
  181.84 +        RandomAccessFile raf = new RandomAccessFile(testFinalizerFile, "rw");
  181.85 +        raf.writeBytes("test file content test file content");
  181.86 +        raf.seek(0L);
  181.87 +        fd = raf.getFD();
  181.88 +        try (FileInputStream fis3 = new FileInputStream(fd)) {
  181.89 +            // allow raf to be gc'ed
  181.90 +            raf = null;
  181.91 +            int ret = 0;
  181.92 +            while (ret >= 0) {
  181.93 +                // encourage gc
  181.94 +                System.gc();
  181.95 +                /*
  181.96 +                 * read from fis3 - when raf is gc'ed and finalizer is run,
  181.97 +                 * fd should still be valid.
  181.98 +                 */
  181.99 +                System.out.print(".");
 181.100 +                ret = fis3.read();
 181.101 +            }
 181.102 +            if(!fd.valid()) {
 181.103 +                throw new RuntimeException("TestFinalizer() : FileDescriptor should be valid");
 181.104 +            }
 181.105 +        } finally {
 181.106 +            testFinalizerFile.delete();
 181.107 +        }
 181.108 +    }
 181.109 +
 181.110 +    /**
 181.111 +     * Exercise FileDispatcher close()/preClose()
 181.112 +     */
 181.113 +    private static void TestMultipleFD() throws Exception {
 181.114 +        RandomAccessFile raf = null;
 181.115 +        FileOutputStream fos = null;
 181.116 +        FileInputStream fis = null;
 181.117 +        FileChannel fc = null;
 181.118 +        FileLock fileLock = null;
 181.119 +
 181.120 +        File test1 = new File("test1");
 181.121 +        try {
 181.122 +            raf = new RandomAccessFile(test1, "rw");
 181.123 +            fos = new FileOutputStream(raf.getFD());
 181.124 +            fis = new FileInputStream(raf.getFD());
 181.125 +            fc = raf.getChannel();
 181.126 +            fileLock = fc.lock();
 181.127 +            raf.setLength(0L);
 181.128 +            fos.flush();
 181.129 +            fos.write("TEST".getBytes());
 181.130 +        } finally {
 181.131 +            if (fileLock != null) fileLock.release();
 181.132 +            if (fis != null) fis.close();
 181.133 +            if (fos != null) fos.close();
 181.134 +            if (raf != null) raf.close();
 181.135 +            test1.delete();
 181.136 +        }
 181.137 +
 181.138 +        /*
 181.139 +         * Close out in different order to ensure FD is not
 181.140 +         * closed out too early
 181.141 +         */
 181.142 +        File test2 = new File("test2");
 181.143 +        try {
 181.144 +            raf = new RandomAccessFile(test2, "rw");
 181.145 +            fos = new FileOutputStream(raf.getFD());
 181.146 +            fis = new FileInputStream(raf.getFD());
 181.147 +            fc = raf.getChannel();
 181.148 +            fileLock = fc.lock();
 181.149 +            raf.setLength(0L);
 181.150 +            fos.flush();
 181.151 +            fos.write("TEST".getBytes());
 181.152 +        } finally {
 181.153 +            if (fileLock != null) fileLock.release();
 181.154 +            if (raf != null) raf.close();
 181.155 +            if (fos != null) fos.close();
 181.156 +            if (fis != null) fis.close();
 181.157 +            test2.delete();
 181.158 +        }
 181.159 +
 181.160 +        // one more time, fos first this time
 181.161 +        File test3 = new File("test3");
 181.162 +        try {
 181.163 +            raf = new RandomAccessFile(test3, "rw");
 181.164 +            fos = new FileOutputStream(raf.getFD());
 181.165 +            fis = new FileInputStream(raf.getFD());
 181.166 +            fc = raf.getChannel();
 181.167 +            fileLock = fc.lock();
 181.168 +            raf.setLength(0L);
 181.169 +            fos.flush();
 181.170 +            fos.write("TEST".getBytes());
 181.171 +        } finally {
 181.172 +            if (fileLock != null) fileLock.release();
 181.173 +            if (fos != null) fos.close();
 181.174 +            if (raf != null) raf.close();
 181.175 +            if (fis != null) fis.close();
 181.176 +            test3.delete();
 181.177 +        }
 181.178 +    }
 181.179 +
 181.180 +    /**
 181.181 +     * Similar to TestMultipleFD() but this time we
 181.182 +     * just get and use FileDescriptor.valid() for testing.
 181.183 +     */
 181.184 +    private static void TestIsValid() throws Exception {
 181.185 +        FileDescriptor fd = null;
 181.186 +        RandomAccessFile raf = null;
 181.187 +        FileOutputStream fos = null;
 181.188 +        FileInputStream fis = null;
 181.189 +        FileChannel fc = null;
 181.190 +
 181.191 +        File test1 = new File("test1");
 181.192 +        try {
 181.193 +            raf = new RandomAccessFile(test1, "rw");
 181.194 +            fd = raf.getFD();
 181.195 +            fos = new FileOutputStream(fd);
 181.196 +            fis = new FileInputStream(fd);
 181.197 +        } finally {
 181.198 +            try {
 181.199 +                if (fis != null) fis.close();
 181.200 +                if (fos != null) fos.close();
 181.201 +                if (!fd.valid()) {
 181.202 +                    throw new RuntimeException("FileDescriptor should be valid");
 181.203 +                }
 181.204 +                if (raf != null) raf.close();
 181.205 +                if (fd.valid()) {
 181.206 +                    throw new RuntimeException("close() called and FileDescriptor still valid");
 181.207 +                }
 181.208 +            } finally {
 181.209 +                if (raf != null) raf.close();
 181.210 +                test1.delete();
 181.211 +            }
 181.212 +        }
 181.213 +
 181.214 +        /*
 181.215 +         * Close out in different order to ensure FD is not
 181.216 +         * closed out too early
 181.217 +         */
 181.218 +        File test2 = new File("test2");
 181.219 +        try {
 181.220 +            raf = new RandomAccessFile(test2, "rw");
 181.221 +            fd = raf.getFD();
 181.222 +            fos = new FileOutputStream(fd);
 181.223 +            fis = new FileInputStream(fd);
 181.224 +        } finally {
 181.225 +            try {
 181.226 +                if (raf != null) raf.close();
 181.227 +                if (fos != null) fos.close();
 181.228 +                if (!fd.valid()) {
 181.229 +                    throw new RuntimeException("FileDescriptor should be valid");
 181.230 +                }
 181.231 +                if (fis != null) fis.close();
 181.232 +                if (fd.valid()) {
 181.233 +                    throw new RuntimeException("close() called and FileDescriptor still valid");
 181.234 +                }
 181.235 +            } finally {
 181.236 +                test2.delete();
 181.237 +            }
 181.238 +        }
 181.239 +
 181.240 +        // one more time, fos first this time
 181.241 +        File test3 = new File("test3");
 181.242 +        try {
 181.243 +            raf = new RandomAccessFile(test3, "rw");
 181.244 +            fd = raf.getFD();
 181.245 +            fos = new FileOutputStream(fd);
 181.246 +            fis = new FileInputStream(fd);
 181.247 +        } finally {
 181.248 +            try {
 181.249 +                if (fos != null) fos.close();
 181.250 +                if (raf != null) raf.close();
 181.251 +                if (!fd.valid()) {
 181.252 +                    throw new RuntimeException("FileDescriptor should be valid");
 181.253 +                }
 181.254 +                if (fis != null) fis.close();
 181.255 +                if (fd.valid()) {
 181.256 +                    throw new RuntimeException("close() called and FileDescriptor still valid");
 181.257 +                }
 181.258 +            } finally {
 181.259 +                test3.delete();
 181.260 +            }
 181.261 +        }
 181.262 +    }
 181.263 +
 181.264 +    /**
 181.265 +     * Test concurrent access to the same fd.useCount field
 181.266 +     */
 181.267 +    private static void MultiThreadedFD() throws Exception {
 181.268 +        RandomAccessFile raf = null;
 181.269 +        FileDescriptor fd = null;
 181.270 +        int numThreads = 2;
 181.271 +        CountDownLatch done = new CountDownLatch(numThreads);
 181.272 +        OpenClose[] fileOpenClose = new OpenClose[numThreads];
 181.273 +        File MultipleThreadedFD = new File("MultipleThreadedFD");
 181.274 +        try {
 181.275 +            raf = new RandomAccessFile(MultipleThreadedFD, "rw");
 181.276 +            fd = raf.getFD();
 181.277 +            for(int count=0;count<numThreads;count++) {
 181.278 +                fileOpenClose[count] = new OpenClose(fd, done);
 181.279 +                fileOpenClose[count].start();
 181.280 +            }
 181.281 +            done.await();
 181.282 +        } finally {
 181.283 +            try {
 181.284 +                if(raf != null) raf.close();
 181.285 +                // fd should now no longer be valid
 181.286 +                if(fd.valid()) {
 181.287 +                    throw new RuntimeException("FileDescriptor should not be valid");
 181.288 +                }
 181.289 +                // OpenClose thread tests failed
 181.290 +                if(fail) {
 181.291 +                    throw new RuntimeException("OpenClose thread tests failed.");
 181.292 +                }
 181.293 +            } finally {
 181.294 +                MultipleThreadedFD.delete();
 181.295 +            }
 181.296 +        }
 181.297 +    }
 181.298 +
 181.299 +    /**
 181.300 +     * A thread which will open and close a number of FileInputStreams and
 181.301 +     * FileOutputStreams referencing the same native file descriptor.
 181.302 +     */
 181.303 +    private static class OpenClose extends Thread {
 181.304 +        private FileDescriptor fd = null;
 181.305 +        private CountDownLatch done;
 181.306 +        FileInputStream[] fisArray = new FileInputStream[numFiles];
 181.307 +        FileOutputStream[] fosArray = new FileOutputStream[numFiles];
 181.308 +
 181.309 +        OpenClose(FileDescriptor filedescriptor, CountDownLatch done) {
 181.310 +            this.fd = filedescriptor;
 181.311 +            this.done = done;
 181.312 +        }
 181.313 +
 181.314 +        public void run() {
 181.315 +             try {
 181.316 +                 for(int i=0;i<numFiles;i++) {
 181.317 +                     fisArray[i] = new FileInputStream(fd);
 181.318 +                     fosArray[i] = new FileOutputStream(fd);
 181.319 +                 }
 181.320 +
 181.321 +                 // Now close out
 181.322 +                 for(int i=0;i<numFiles;i++) {
 181.323 +                     if(fisArray[i] != null) fisArray[i].close();
 181.324 +                     if(fosArray[i] != null) fosArray[i].close();
 181.325 +                 }
 181.326 +
 181.327 +             } catch(IOException ioe) {
 181.328 +                 System.out.println("OpenClose encountered IO issue :" + ioe);
 181.329 +                 fail = true;
 181.330 +             } finally {
 181.331 +                 if (!fd.valid()) { // fd should still be valid given RAF reference
 181.332 +                     System.out.println("OpenClose: FileDescriptor should be valid");
 181.333 +                     fail = true;
 181.334 +                 }
 181.335 +                 done.countDown();
 181.336 +             }
 181.337 +         }
 181.338 +    }
 181.339 +}
   182.1 --- a/test/java/lang/Double/ParseHexFloatingPoint.java	Fri Sep 30 17:20:56 2011 -0700
   182.2 +++ b/test/java/lang/Double/ParseHexFloatingPoint.java	Tue Oct 04 12:39:42 2011 -0700
   182.3 @@ -1,5 +1,5 @@
   182.4  /*
   182.5 - * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
   182.6 + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
   182.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   182.8   *
   182.9   * This code is free software; you can redistribute it and/or modify it
  182.10 @@ -30,7 +30,6 @@
  182.11  
  182.12  
  182.13  import java.util.regex.*;
  182.14 -import sun.misc.FpUtils;
  182.15  import sun.misc.DoubleConsts;
  182.16  
  182.17  public class ParseHexFloatingPoint {
  182.18 @@ -227,7 +226,7 @@
  182.19              new PairSD("0x1.000000000000001p-1075",     Double.MIN_VALUE),
  182.20  
  182.21              // More subnormal rounding tests
  182.22 -            new PairSD("0x0.fffffffffffff7fffffp-1022", FpUtils.nextDown(DoubleConsts.MIN_NORMAL)),
  182.23 +            new PairSD("0x0.fffffffffffff7fffffp-1022", Math.nextDown(DoubleConsts.MIN_NORMAL)),
  182.24              new PairSD("0x0.fffffffffffff8p-1022",      DoubleConsts.MIN_NORMAL),
  182.25              new PairSD("0x0.fffffffffffff800000001p-1022",DoubleConsts.MIN_NORMAL),
  182.26              new PairSD("0x0.fffffffffffff80000000000000001p-1022",DoubleConsts.MIN_NORMAL),
  182.27 @@ -242,10 +241,10 @@
  182.28              new PairSD("0x1.fffffffffffff8p1023",       infinityD),
  182.29              new PairSD("0x1.fffffffffffff8000001p1023", infinityD),
  182.30  
  182.31 -            new PairSD("0x1.ffffffffffffep1023",        FpUtils.nextDown(Double.MAX_VALUE)),
  182.32 -            new PairSD("0x1.ffffffffffffe0000p1023",    FpUtils.nextDown(Double.MAX_VALUE)),
  182.33 -            new PairSD("0x1.ffffffffffffe8p1023",       FpUtils.nextDown(Double.MAX_VALUE)),
  182.34 -            new PairSD("0x1.ffffffffffffe7p1023",       FpUtils.nextDown(Double.MAX_VALUE)),
  182.35 +            new PairSD("0x1.ffffffffffffep1023",        Math.nextDown(Double.MAX_VALUE)),
  182.36 +            new PairSD("0x1.ffffffffffffe0000p1023",    Math.nextDown(Double.MAX_VALUE)),
  182.37 +            new PairSD("0x1.ffffffffffffe8p1023",       Math.nextDown(Double.MAX_VALUE)),
  182.38 +            new PairSD("0x1.ffffffffffffe7p1023",       Math.nextDown(Double.MAX_VALUE)),
  182.39              new PairSD("0x1.ffffffffffffeffffffp1023",  Double.MAX_VALUE),
  182.40              new PairSD("0x1.ffffffffffffe8000001p1023", Double.MAX_VALUE),
  182.41          };
  182.42 @@ -284,8 +283,8 @@
  182.43          };
  182.44  
  182.45          double [] answers = {
  182.46 -            FpUtils.nextDown(FpUtils.nextDown(2.0)),
  182.47 -            FpUtils.nextDown(2.0),
  182.48 +            Math.nextDown(Math.nextDown(2.0)),
  182.49 +            Math.nextDown(2.0),
  182.50              2.0
  182.51          };
  182.52  
   183.1 --- a/test/java/lang/Double/ToHexString.java	Fri Sep 30 17:20:56 2011 -0700
   183.2 +++ b/test/java/lang/Double/ToHexString.java	Tue Oct 04 12:39:42 2011 -0700
   183.3 @@ -29,7 +29,6 @@
   183.4   */
   183.5  
   183.6  import java.util.regex.*;
   183.7 -import sun.misc.FpUtils;
   183.8  import sun.misc.DoubleConsts;
   183.9  
  183.10  public class ToHexString {
   184.1 --- a/test/java/lang/Math/CeilAndFloorTests.java	Fri Sep 30 17:20:56 2011 -0700
   184.2 +++ b/test/java/lang/Math/CeilAndFloorTests.java	Tue Oct 04 12:39:42 2011 -0700
   184.3 @@ -1,5 +1,5 @@
   184.4  /*
   184.5 - * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
   184.6 + * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
   184.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   184.8   *
   184.9   * This code is free software; you can redistribute it and/or modify it
  184.10 @@ -27,7 +27,6 @@
  184.11   * @summary Check for correct implementation of Math.ceil and Math.floor
  184.12   */
  184.13  
  184.14 -import sun.misc.FpUtils;
  184.15  import sun.misc.DoubleConsts;
  184.16  
  184.17  public class CeilAndFloorTests {
  184.18 @@ -69,7 +68,7 @@
  184.19  
  184.20          for(int i = Double.MIN_EXPONENT; i <= Double.MAX_EXPONENT; i++) {
  184.21              double powerOfTwo   = Math.scalb(1.0, i);
  184.22 -            double neighborDown = FpUtils.nextDown(powerOfTwo);
  184.23 +            double neighborDown = Math.nextDown(powerOfTwo);
  184.24              double neighborUp   = Math.nextUp(powerOfTwo);
  184.25  
  184.26              if (i < 0) {
  184.27 @@ -114,7 +113,7 @@
  184.28  
  184.29          for(int i = -(0x10000); i <= 0x10000; i++) {
  184.30              double d = (double) i;
  184.31 -            double neighborDown = FpUtils.nextDown(d);
  184.32 +            double neighborDown = Math.nextDown(d);
  184.33              double neighborUp   = Math.nextUp(d);
  184.34  
  184.35              failures += testCeilCase( d, d);
  184.36 @@ -140,8 +139,8 @@
  184.37          double [][] testCases = {
  184.38              { Double.MIN_VALUE,                           1.0},
  184.39              {-Double.MIN_VALUE,                          -0.0},
  184.40 -            { FpUtils.nextDown(DoubleConsts.MIN_NORMAL),  1.0},
  184.41 -            {-FpUtils.nextDown(DoubleConsts.MIN_NORMAL), -0.0},
  184.42 +            { Math.nextDown(DoubleConsts.MIN_NORMAL),     1.0},
  184.43 +            {-Math.nextDown(DoubleConsts.MIN_NORMAL),    -0.0},
  184.44              { DoubleConsts.MIN_NORMAL,                    1.0},
  184.45              {-DoubleConsts.MIN_NORMAL,                   -0.0},
  184.46  
  184.47 @@ -157,8 +156,8 @@
  184.48              { 2.5,                                        3.0},
  184.49              {-2.5,                                       -2.0},
  184.50  
  184.51 -            { FpUtils.nextDown(1.0),                      1.0},
  184.52 -            { FpUtils.nextDown(-1.0),                    -1.0},
  184.53 +            { Math.nextDown(1.0),                         1.0},
  184.54 +            { Math.nextDown(-1.0),                       -1.0},
  184.55  
  184.56              { Math.nextUp(1.0),                           2.0},
  184.57              { Math.nextUp(-1.0),                         -0.0},
  184.58 @@ -166,17 +165,17 @@
  184.59              { 0x1.0p51,                                 0x1.0p51},
  184.60              {-0x1.0p51,                                -0x1.0p51},
  184.61  
  184.62 -            { FpUtils.nextDown(0x1.0p51),               0x1.0p51},
  184.63 +            { Math.nextDown(0x1.0p51),                  0x1.0p51},
  184.64              {-Math.nextUp(0x1.0p51),                   -0x1.0p51},
  184.65  
  184.66              { Math.nextUp(0x1.0p51),                    0x1.0p51+1},
  184.67 -            {-FpUtils.nextDown(0x1.0p51),              -0x1.0p51+1},
  184.68 +            {-Math.nextDown(0x1.0p51),                 -0x1.0p51+1},
  184.69  
  184.70 -            { FpUtils.nextDown(0x1.0p52),               0x1.0p52},
  184.71 +            { Math.nextDown(0x1.0p52),                  0x1.0p52},
  184.72              {-Math.nextUp(0x1.0p52),                   -0x1.0p52-1.0},
  184.73  
  184.74              { Math.nextUp(0x1.0p52),                    0x1.0p52+1.0},
  184.75 -            {-FpUtils.nextDown(0x1.0p52),              -0x1.0p52+1.0},
  184.76 +            {-Math.nextDown(0x1.0p52),                 -0x1.0p52+1.0},
  184.77          };
  184.78  
  184.79          for(double[] testCase : testCases) {
   185.1 --- a/test/java/lang/Math/CubeRootTests.java	Fri Sep 30 17:20:56 2011 -0700
   185.2 +++ b/test/java/lang/Math/CubeRootTests.java	Tue Oct 04 12:39:42 2011 -0700
   185.3 @@ -1,5 +1,5 @@
   185.4  /*
   185.5 - * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
   185.6 + * Copyright (c) 2003, 2011 Oracle and/or its affiliates. All rights reserved.
   185.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   185.8   *
   185.9   * This code is free software; you can redistribute it and/or modify it
  185.10 @@ -28,7 +28,6 @@
  185.11   * @author Joseph D. Darcy
  185.12   */
  185.13  
  185.14 -import sun.misc.FpUtils;
  185.15  import sun.misc.DoubleConsts;
  185.16  
  185.17  public class CubeRootTests {
  185.18 @@ -95,14 +94,14 @@
  185.19  
  185.20          // Test cbrt(2^(3n)) = 2^n.
  185.21          for(int i = 18; i <= DoubleConsts.MAX_EXPONENT/3; i++) {
  185.22 -            failures += testCubeRootCase(FpUtils.scalb(1.0, 3*i),
  185.23 -                                         FpUtils.scalb(1.0, i) );
  185.24 +            failures += testCubeRootCase(Math.scalb(1.0, 3*i),
  185.25 +                                         Math.scalb(1.0, i) );
  185.26          }
  185.27  
  185.28          // Test cbrt(2^(-3n)) = 2^-n.
  185.29 -        for(int i = -1; i >= FpUtils.ilogb(Double.MIN_VALUE)/3; i--) {
  185.30 -            failures += testCubeRootCase(FpUtils.scalb(1.0, 3*i),
  185.31 -                                         FpUtils.scalb(1.0, i) );
  185.32 +        for(int i = -1; i >= DoubleConsts.MIN_SUB_EXPONENT/3; i--) {
  185.33 +            failures += testCubeRootCase(Math.scalb(1.0, 3*i),
  185.34 +                                         Math.scalb(1.0, i) );
  185.35          }
  185.36  
  185.37          // Test random perfect cubes.  Create double values with
  185.38 @@ -110,10 +109,10 @@
  185.39          // significant bits in the significand set; 17*3 = 51, which
  185.40          // is less than the number of bits in a double's significand.
  185.41          long exponentBits1 =
  185.42 -            Double.doubleToLongBits(FpUtils.scalb(1.0, 55)) &
  185.43 +            Double.doubleToLongBits(Math.scalb(1.0, 55)) &
  185.44              DoubleConsts.EXP_BIT_MASK;
  185.45          long exponentBits2=
  185.46 -            Double.doubleToLongBits(FpUtils.scalb(1.0, -55)) &
  185.47 +            Double.doubleToLongBits(Math.scalb(1.0, -55)) &
  185.48              DoubleConsts.EXP_BIT_MASK;
  185.49          for(int i = 0; i < 100; i++) {
  185.50              // Take 16 bits since the 17th bit is implicit in the
  185.51 @@ -177,16 +176,16 @@
  185.52  
  185.53              err = d - StrictMath.pow(y1, 3);
  185.54              if (err != 0.0) {
  185.55 -                if(FpUtils.isNaN(err)) {
  185.56 +                if(Double.isNaN(err)) {
  185.57                      failures++;
  185.58                      System.err.println("Encountered unexpected NaN value: d = " + d +
  185.59                                         "\tcbrt(d) = " + y1);
  185.60                  } else {
  185.61                      if (err < 0.0) {
  185.62 -                        err_adjacent = StrictMath.pow(FpUtils.nextUp(y1), 3) - d;
  185.63 +                        err_adjacent = StrictMath.pow(Math.nextUp(y1), 3) - d;
  185.64                      }
  185.65                      else  { // (err > 0.0)
  185.66 -                        err_adjacent = StrictMath.pow(FpUtils.nextAfter(y1,0.0), 3) - d;
  185.67 +                        err_adjacent = StrictMath.pow(Math.nextAfter(y1,0.0), 3) - d;
  185.68                      }
  185.69  
  185.70                      if (Math.abs(err) > Math.abs(err_adjacent)) {
  185.71 @@ -200,16 +199,16 @@
  185.72  
  185.73              err = d - StrictMath.pow(y2, 3);
  185.74              if (err != 0.0) {
  185.75 -                if(FpUtils.isNaN(err)) {
  185.76 +                if(Double.isNaN(err)) {
  185.77                      failures++;
  185.78                      System.err.println("Encountered unexpected NaN value: d = " + d +
  185.79                                         "\tcbrt(d) = " + y2);
  185.80                  } else {
  185.81                      if (err < 0.0) {
  185.82 -                        err_adjacent = StrictMath.pow(FpUtils.nextUp(y2), 3) - d;
  185.83 +                        err_adjacent = StrictMath.pow(Math.nextUp(y2), 3) - d;
  185.84                      }
  185.85                      else  { // (err > 0.0)
  185.86 -                        err_adjacent = StrictMath.pow(FpUtils.nextAfter(y2,0.0), 3) - d;
  185.87 +                        err_adjacent = StrictMath.pow(Math.nextAfter(y2,0.0), 3) - d;
  185.88                      }
  185.89  
  185.90                      if (Math.abs(err) > Math.abs(err_adjacent)) {
  185.91 @@ -242,13 +241,13 @@
  185.92  
  185.93              // Test near cbrt(2^(3n)) = 2^n.
  185.94              for(int i = 18; i <= DoubleConsts.MAX_EXPONENT/3; i++) {
  185.95 -                double pc = FpUtils.scalb(1.0, 3*i);
  185.96 +                double pc = Math.scalb(1.0, 3*i);
  185.97  
  185.98                  pcNeighbors[2] = pc;
  185.99 -                pcNeighbors[1] = FpUtils.nextDown(pc);
 185.100 -                pcNeighbors[0] = FpUtils.nextDown(pcNeighbors[1]);
 185.101 -                pcNeighbors[3] = FpUtils.nextUp(pc);
 185.102 -                pcNeighbors[4] = FpUtils.nextUp(pcNeighbors[3]);
 185.103 +                pcNeighbors[1] = Math.nextDown(pc);
 185.104 +                pcNeighbors[0] = Math.nextDown(pcNeighbors[1]);
 185.105 +                pcNeighbors[3] = Math.nextUp(pc);
 185.106 +                pcNeighbors[4] = Math.nextUp(pcNeighbors[3]);
 185.107  
 185.108                  for(int j = 0; j < pcNeighbors.length; j++) {
 185.109                      pcNeighborsCbrt[j] =           Math.cbrt(pcNeighbors[j]);
 185.110 @@ -280,14 +279,14 @@
 185.111              }
 185.112  
 185.113              // Test near cbrt(2^(-3n)) = 2^-n.
 185.114 -            for(int i = -1; i >= FpUtils.ilogb(Double.MIN_VALUE)/3; i--) {
 185.115 -                double pc = FpUtils.scalb(1.0, 3*i);
 185.116 +            for(int i = -1; i >= DoubleConsts.MIN_SUB_EXPONENT/3; i--) {
 185.117 +                double pc = Math.scalb(1.0, 3*i);
 185.118  
 185.119                  pcNeighbors[2] = pc;
 185.120 -                pcNeighbors[1] = FpUtils.nextDown(pc);
 185.121 -                pcNeighbors[0] = FpUtils.nextDown(pcNeighbors[1]);
 185.122 -                pcNeighbors[3] = FpUtils.nextUp(pc);
 185.123 -                pcNeighbors[4] = FpUtils.nextUp(pcNeighbors[3]);
 185.124 +                pcNeighbors[1] = Math.nextDown(pc);
 185.125 +                pcNeighbors[0] = Math.nextDown(pcNeighbors[1]);
 185.126 +                pcNeighbors[3] = Math.nextUp(pc);
 185.127 +                pcNeighbors[4] = Math.nextUp(pcNeighbors[3]);
 185.128  
 185.129                  for(int j = 0; j < pcNeighbors.length; j++) {
 185.130                      pcNeighborsCbrt[j] =           Math.cbrt(pcNeighbors[j]);
   186.1 --- a/test/java/lang/Math/Expm1Tests.java	Fri Sep 30 17:20:56 2011 -0700
   186.2 +++ b/test/java/lang/Math/Expm1Tests.java	Tue Oct 04 12:39:42 2011 -0700
   186.3 @@ -1,5 +1,5 @@
   186.4  /*
   186.5 - * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
   186.6 + * Copyright (c) 2003, 2011 Oracle and/or its affiliates. All rights reserved.
   186.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   186.8   *
   186.9   * This code is free software; you can redistribute it and/or modify it
  186.10 @@ -29,7 +29,6 @@
  186.11   */
  186.12  
  186.13  import sun.misc.DoubleConsts;
  186.14 -import sun.misc.FpUtils;
  186.15  
  186.16  /*
  186.17   * The Taylor expansion of expxm1(x) = exp(x) -1 is
  186.18 @@ -82,7 +81,7 @@
  186.19  
  186.20          // For |x| < 2^-54 expm1(x) ~= x
  186.21          for(int i = DoubleConsts.MIN_SUB_EXPONENT; i <= -54; i++) {
  186.22 -            double d = FpUtils.scalb(2, i);
  186.23 +            double d = Math.scalb(2, i);
  186.24              failures += testExpm1Case(d, d);
  186.25              failures += testExpm1Case(-d, -d);
  186.26          }
  186.27 @@ -101,7 +100,7 @@
  186.28  
  186.29          // For x > 710, expm1(x) should be infinity
  186.30          for(int i = 10; i <= DoubleConsts.MAX_EXPONENT; i++) {
  186.31 -            double d = FpUtils.scalb(2, i);
  186.32 +            double d = Math.scalb(2, i);
  186.33              failures += testExpm1Case(d, infinityD);
  186.34          }
  186.35  
  186.36 @@ -118,7 +117,7 @@
  186.37          }
  186.38  
  186.39          for(int i = 7; i <= DoubleConsts.MAX_EXPONENT; i++) {
  186.40 -            double d = -FpUtils.scalb(2, i);
  186.41 +            double d = -Math.scalb(2, i);
  186.42              failures += testExpm1CaseWithUlpDiff(d, -1.0, 1, reachedLimit);
  186.43          }
  186.44  
  186.45 @@ -143,10 +142,10 @@
  186.46                  double pc = StrictMath.log(2)*i;
  186.47  
  186.48                  pcNeighbors[2] = pc;
  186.49 -                pcNeighbors[1] = FpUtils.nextDown(pc);
  186.50 -                pcNeighbors[0] = FpUtils.nextDown(pcNeighbors[1]);
  186.51 -                pcNeighbors[3] = FpUtils.nextUp(pc);
  186.52 -                pcNeighbors[4] = FpUtils.nextUp(pcNeighbors[3]);
  186.53 +                pcNeighbors[1] = Math.nextDown(pc);
  186.54 +                pcNeighbors[0] = Math.nextDown(pcNeighbors[1]);
  186.55 +                pcNeighbors[3] = Math.nextUp(pc);
  186.56 +                pcNeighbors[4] = Math.nextUp(pcNeighbors[3]);
  186.57  
  186.58                  for(int j = 0; j < pcNeighbors.length; j++) {
  186.59                      pcNeighborsExpm1[j]       =       Math.expm1(pcNeighbors[j]);
   187.1 --- a/test/java/lang/Math/HyperbolicTests.java	Fri Sep 30 17:20:56 2011 -0700
   187.2 +++ b/test/java/lang/Math/HyperbolicTests.java	Tue Oct 04 12:39:42 2011 -0700
   187.3 @@ -1,5 +1,5 @@
   187.4  /*
   187.5 - * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
   187.6 + * Copyright (c) 2003, 2011 Oracle and/or its affiliates. All rights reserved.
   187.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   187.8   *
   187.9   * This code is free software; you can redistribute it and/or modify it
  187.10 @@ -29,7 +29,6 @@
  187.11   */
  187.12  
  187.13  import sun.misc.DoubleConsts;
  187.14 -import sun.misc.FpUtils;
  187.15  
  187.16  public class HyperbolicTests {
  187.17      private HyperbolicTests(){}
  187.18 @@ -266,7 +265,7 @@
  187.19          // double significand.
  187.20  
  187.21          for(int i = DoubleConsts.MIN_SUB_EXPONENT; i < -27; i++) {
  187.22 -            double d = FpUtils.scalb(2.0, i);
  187.23 +            double d = Math.scalb(2.0, i);
  187.24  
  187.25              // Result and expected are the same.
  187.26              failures += testSinhCaseWithUlpDiff(d, d, 2.5);
  187.27 @@ -280,7 +279,7 @@
  187.28          long trans22 = Double.doubleToLongBits(22.0);
  187.29          // (approximately) largest value such that exp shouldn't
  187.30          // overflow
  187.31 -        long transExpOvfl = Double.doubleToLongBits(FpUtils.nextDown(709.7827128933841));
  187.32 +        long transExpOvfl = Double.doubleToLongBits(Math.nextDown(709.7827128933841));
  187.33  
  187.34          for(long i = trans22;
  187.35              i < transExpOvfl;
  187.36 @@ -344,7 +343,7 @@
  187.37          // sinh(x) overflows for values greater than 710; in
  187.38          // particular, it overflows for all 2^i, i > 10.
  187.39          for(int i = 10; i <= DoubleConsts.MAX_EXPONENT; i++) {
  187.40 -            double d = FpUtils.scalb(2.0, i);
  187.41 +            double d = Math.scalb(2.0, i);
  187.42  
  187.43              // Result and expected are the same.
  187.44              failures += testSinhCaseWithUlpDiff(d,
  187.45 @@ -625,7 +624,7 @@
  187.46          // rounded.
  187.47  
  187.48          for(int i = DoubleConsts.MIN_SUB_EXPONENT; i < -27; i++) {
  187.49 -            double d = FpUtils.scalb(2.0, i);
  187.50 +            double d = Math.scalb(2.0, i);
  187.51  
  187.52              // Result and expected are the same.
  187.53              failures += testCoshCaseWithUlpDiff(d, 1.0, 2.5);
  187.54 @@ -639,7 +638,7 @@
  187.55          long trans22 = Double.doubleToLongBits(22.0);
  187.56          // (approximately) largest value such that exp shouldn't
  187.57          // overflow
  187.58 -        long transExpOvfl = Double.doubleToLongBits(FpUtils.nextDown(709.7827128933841));
  187.59 +        long transExpOvfl = Double.doubleToLongBits(Math.nextDown(709.7827128933841));
  187.60  
  187.61          for(long i = trans22;
  187.62              i < transExpOvfl;
  187.63 @@ -703,7 +702,7 @@
  187.64          // cosh(x) overflows for values greater than 710; in
  187.65          // particular, it overflows for all 2^i, i > 10.
  187.66          for(int i = 10; i <= DoubleConsts.MAX_EXPONENT; i++) {
  187.67 -            double d = FpUtils.scalb(2.0, i);
  187.68 +            double d = Math.scalb(2.0, i);
  187.69  
  187.70              // Result and expected are the same.
  187.71              failures += testCoshCaseWithUlpDiff(d,
  187.72 @@ -984,7 +983,7 @@
  187.73          // double significand.
  187.74  
  187.75          for(int i = DoubleConsts.MIN_SUB_EXPONENT; i < -27; i++) {
  187.76 -            double d = FpUtils.scalb(2.0, i);
  187.77 +            double d = Math.scalb(2.0, i);
  187.78  
  187.79              // Result and expected are the same.
  187.80              failures += testTanhCaseWithUlpDiff(d, d, 2.5);
  187.81 @@ -998,7 +997,7 @@
  187.82          }
  187.83  
  187.84          for(int i = 5; i <= DoubleConsts.MAX_EXPONENT; i++) {
  187.85 -            double d = FpUtils.scalb(2.0, i);
  187.86 +            double d = Math.scalb(2.0, i);
  187.87  
  187.88              failures += testTanhCaseWithUlpDiff(d, 1.0, 2.5);
  187.89          }
   188.1 --- a/test/java/lang/Math/HypotTests.java	Fri Sep 30 17:20:56 2011 -0700
   188.2 +++ b/test/java/lang/Math/HypotTests.java	Tue Oct 04 12:39:42 2011 -0700
   188.3 @@ -1,5 +1,5 @@
   188.4  /*
   188.5 - * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
   188.6 + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
   188.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   188.8   *
   188.9   * This code is free software; you can redistribute it and/or modify it
  188.10 @@ -90,7 +90,7 @@
  188.11          for(int i = DoubleConsts.MIN_SUB_EXPONENT;
  188.12              i <= DoubleConsts.MAX_EXPONENT;
  188.13              i++) {
  188.14 -            double input = FpUtils.scalb(2, i);
  188.15 +            double input = Math.scalb(2, i);
  188.16              failures += testHypotCase(input, 0.0, input);
  188.17          }
  188.18  
  188.19 @@ -126,7 +126,7 @@
  188.20          for(int i = 0; i < 1000; i++) {
  188.21              double d = rand.nextDouble();
  188.22              // Scale d to have an exponent equal to MAX_EXPONENT -15
  188.23 -            d = FpUtils.scalb(d, DoubleConsts.MAX_EXPONENT
  188.24 +            d = Math.scalb(d, DoubleConsts.MAX_EXPONENT
  188.25                                   -15 - FpUtils.ilogb(d));
  188.26              for(int j = 0; j <= 13; j += 1) {
  188.27                  failures += testHypotCase(3*d, 4*d, 5*d, 2.5);
  188.28 @@ -153,13 +153,13 @@
  188.29  
  188.30  
  188.31              for(int i = -18; i <= 18; i++) {
  188.32 -                double pc = FpUtils.scalb(1.0, i);
  188.33 +                double pc = Math.scalb(1.0, i);
  188.34  
  188.35                  pcNeighbors[2] = pc;
  188.36 -                pcNeighbors[1] = FpUtils.nextDown(pc);
  188.37 -                pcNeighbors[0] = FpUtils.nextDown(pcNeighbors[1]);
  188.38 -                pcNeighbors[3] = FpUtils.nextUp(pc);
  188.39 -                pcNeighbors[4] = FpUtils.nextUp(pcNeighbors[3]);
  188.40 +                pcNeighbors[1] = Math.nextDown(pc);
  188.41 +                pcNeighbors[0] = Math.nextDown(pcNeighbors[1]);
  188.42 +                pcNeighbors[3] = Math.nextUp(pc);
  188.43 +                pcNeighbors[4] = Math.nextUp(pcNeighbors[3]);
  188.44  
  188.45                  for(int j = 0; j < pcNeighbors.length; j++) {
  188.46                      pcNeighborsHypot[j]       =       Math.hypot(2.0, pcNeighbors[j]);
   189.1 --- a/test/java/lang/Math/IeeeRecommendedTests.java	Fri Sep 30 17:20:56 2011 -0700
   189.2 +++ b/test/java/lang/Math/IeeeRecommendedTests.java	Tue Oct 04 12:39:42 2011 -0700
   189.3 @@ -1,5 +1,5 @@
   189.4  /*
   189.5 - * Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved.
   189.6 + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
   189.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   189.8   *
   189.9   * This code is free software; you can redistribute it and/or modify it
  189.10 @@ -177,7 +177,7 @@
  189.11              }
  189.12  
  189.13              if (i > FloatConsts.MIN_EXPONENT) {
  189.14 -                float po2minus = FpUtils.nextAfter(po2,
  189.15 +                float po2minus = Math.nextAfter(po2,
  189.16                                                   Float.NEGATIVE_INFINITY);
  189.17                  failures += testGetExponentCase(po2minus, i-1);
  189.18              }
  189.19 @@ -205,7 +205,7 @@
  189.20              // Test largest value in next smaller binade
  189.21              if (i >= 3) {// (i == 1) would test 0.0;
  189.22                           // (i == 2) would just retest MIN_VALUE
  189.23 -                testGetExponentCase(FpUtils.nextAfter(top, 0.0f),
  189.24 +                testGetExponentCase(Math.nextAfter(top, 0.0f),
  189.25                                      FloatConsts.MIN_EXPONENT - 1);
  189.26  
  189.27                  if( i >= 10) {
  189.28 @@ -284,7 +284,7 @@
  189.29              }
  189.30  
  189.31              if (i > DoubleConsts.MIN_EXPONENT) {
  189.32 -                double po2minus = FpUtils.nextAfter(po2,
  189.33 +                double po2minus = Math.nextAfter(po2,
  189.34                                                      Double.NEGATIVE_INFINITY);
  189.35                  failures += testGetExponentCase(po2minus, i-1);
  189.36              }
  189.37 @@ -312,7 +312,7 @@
  189.38              // Test largest value in next smaller binade
  189.39              if (i >= 3) {// (i == 1) would test 0.0;
  189.40                           // (i == 2) would just retest MIN_VALUE
  189.41 -                testGetExponentCase(FpUtils.nextAfter(top, 0.0),
  189.42 +                testGetExponentCase(Math.nextAfter(top, 0.0),
  189.43                                      DoubleConsts.MIN_EXPONENT - 1);
  189.44  
  189.45                  if( i >= 10) {
  189.46 @@ -623,8 +623,11 @@
  189.47          };
  189.48  
  189.49          for(int i = 0; i < testCases.length; i++) {
  189.50 -            failures+=Tests.test("FpUtils.nextDown(float)",
  189.51 -                                 testCases[i][0], FpUtils.nextDown(testCases[i][0]), testCases[i][1]);
  189.52 +            failures+=Tests.test("Math.nextDown(float)",
  189.53 +                                 testCases[i][0], Math.nextDown(testCases[i][0]), testCases[i][1]);
  189.54 +
  189.55 +            failures+=Tests.test("StrictMath.nextDown(float)",
  189.56 +                                 testCases[i][0], StrictMath.nextDown(testCases[i][0]), testCases[i][1]);
  189.57          }
  189.58  
  189.59          return failures;
  189.60 @@ -659,8 +662,11 @@
  189.61          };
  189.62  
  189.63          for(int i = 0; i < testCases.length; i++) {
  189.64 -            failures+=Tests.test("FpUtils.nextDown(double)",
  189.65 -                                 testCases[i][0], FpUtils.nextDown(testCases[i][0]), testCases[i][1]);
  189.66 +            failures+=Tests.test("Math.nextDown(double)",
  189.67 +                                 testCases[i][0], Math.nextDown(testCases[i][0]), testCases[i][1]);
  189.68 +
  189.69 +            failures+=Tests.test("StrictMath.nextDown(double)",
  189.70 +                                 testCases[i][0], StrictMath.nextDown(testCases[i][0]), testCases[i][1]);
  189.71          }
  189.72  
  189.73          return failures;
  189.74 @@ -706,8 +712,8 @@
  189.75                                   FpUtils.isNaN(testCases[i]), (i ==0));
  189.76  
  189.77              // isFinite
  189.78 -            failures+=Tests.test("FpUtils.isFinite(float)", testCases[i],
  189.79 -                                 FpUtils.isFinite(testCases[i]), (i >= 3));
  189.80 +            failures+=Tests.test("Float.isFinite(float)", testCases[i],
  189.81 +                                 Float.isFinite(testCases[i]), (i >= 3));
  189.82  
  189.83              // isInfinite
  189.84              failures+=Tests.test("FpUtils.isInfinite(float)", testCases[i],
  189.85 @@ -756,8 +762,8 @@
  189.86                                   FpUtils.isNaN(testCases[i]), (i ==0));
  189.87  
  189.88              // isFinite
  189.89 -            failures+=Tests.test("FpUtils.isFinite(double)", testCases[i],
  189.90 -                                 FpUtils.isFinite(testCases[i]), (i >= 3));
  189.91 +            failures+=Tests.test("Double.isFinite(double)", testCases[i],
  189.92 +                                 Double.isFinite(testCases[i]), (i >= 3));
  189.93  
  189.94              // isInfinite
  189.95              failures+=Tests.test("FpUtils.isInfinite(double)", testCases[i],
  189.96 @@ -1061,7 +1067,7 @@
  189.97                      float value = someTestCases[i];
  189.98                      failures+=testScalbCase(value,
  189.99                                              scaleFactor,
 189.100 -                                            FpUtils.copySign( (scaleFactor>0?infinityF:0.0f), value) );
 189.101 +                                            Math.copySign( (scaleFactor>0?infinityF:0.0f), value) );
 189.102                  }
 189.103              }
 189.104          }
 189.105 @@ -1095,7 +1101,7 @@
 189.106                  failures+=testScalbCase(value,
 189.107                                          scaleFactor,
 189.108                                          (FpUtils.ilogb(value) +j > FloatConsts.MAX_EXPONENT ) ?
 189.109 -                                        FpUtils.copySign(infinityF, value) : // overflow
 189.110 +                                        Math.copySign(infinityF, value) : // overflow
 189.111                                          // calculate right answer
 189.112                                          twoToTheMaxExp*(twoToTheMaxExp*(scale*value)) );
 189.113                  scale*=2.0f;
 189.114 @@ -1268,7 +1274,7 @@
 189.115                      double value = someTestCases[i];
 189.116                      failures+=testScalbCase(value,
 189.117                                              scaleFactor,
 189.118 -                                            FpUtils.copySign( (scaleFactor>0?infinityD:0.0), value) );
 189.119 +                                            Math.copySign( (scaleFactor>0?infinityD:0.0), value) );
 189.120                  }
 189.121              }
 189.122          }
 189.123 @@ -1302,7 +1308,7 @@
 189.124                  failures+=testScalbCase(value,
 189.125                                          scaleFactor,
 189.126                                          (FpUtils.ilogb(value) +j > DoubleConsts.MAX_EXPONENT ) ?
 189.127 -                                        FpUtils.copySign(infinityD, value) : // overflow
 189.128 +                                        Math.copySign(infinityD, value) : // overflow
 189.129                                          // calculate right answer
 189.130                                          twoToTheMaxExp*(twoToTheMaxExp*(scale*value)) );
 189.131                  scale*=2.0;
 189.132 @@ -1423,7 +1429,7 @@
 189.133  
 189.134              // Create power of two
 189.135              float po2 = powerOfTwoF(i);
 189.136 -            expected = FpUtils.scalb(1.0f, i - (FloatConsts.SIGNIFICAND_WIDTH-1));
 189.137 +            expected = Math.scalb(1.0f, i - (FloatConsts.SIGNIFICAND_WIDTH-1));
 189.138  
 189.139              failures += testUlpCase(po2, expected);
 189.140  
 189.141 @@ -1443,7 +1449,7 @@
 189.142              }
 189.143  
 189.144              if (i > FloatConsts.MIN_EXPONENT) {
 189.145 -                float po2minus = FpUtils.nextAfter(po2,
 189.146 +                float po2minus = Math.nextAfter(po2,
 189.147                                                     Float.NEGATIVE_INFINITY);
 189.148                  failures += testUlpCase(po2minus, expected/2.0f);
 189.149              }
 189.150 @@ -1470,7 +1476,7 @@
 189.151              // Test largest value in next smaller binade
 189.152              if (i >= 3) {// (i == 1) would test 0.0;
 189.153                           // (i == 2) would just retest MIN_VALUE
 189.154 -                testUlpCase(FpUtils.nextAfter(top, 0.0f),
 189.155 +                testUlpCase(Math.nextAfter(top, 0.0f),
 189.156                              Float.MIN_VALUE);
 189.157  
 189.158                  if( i >= 10) {
 189.159 @@ -1528,7 +1534,7 @@
 189.160  
 189.161              // Create power of two
 189.162              double po2 = powerOfTwoD(i);
 189.163 -            expected = FpUtils.scalb(1.0, i - (DoubleConsts.SIGNIFICAND_WIDTH-1));
 189.164 +            expected = Math.scalb(1.0, i - (DoubleConsts.SIGNIFICAND_WIDTH-1));
 189.165  
 189.166              failures += testUlpCase(po2, expected);
 189.167  
 189.168 @@ -1548,7 +1554,7 @@
 189.169              }
 189.170  
 189.171              if (i > DoubleConsts.MIN_EXPONENT) {
 189.172 -                double po2minus = FpUtils.nextAfter(po2,
 189.173 +                double po2minus = Math.nextAfter(po2,
 189.174                                                      Double.NEGATIVE_INFINITY);
 189.175                  failures += testUlpCase(po2minus, expected/2.0f);
 189.176              }
 189.177 @@ -1575,7 +1581,7 @@
 189.178              // Test largest value in next smaller binade
 189.179              if (i >= 3) {// (i == 1) would test 0.0;
 189.180                           // (i == 2) would just retest MIN_VALUE
 189.181 -                testUlpCase(FpUtils.nextAfter(top, 0.0f),
 189.182 +                testUlpCase(Math.nextAfter(top, 0.0f),
 189.183                              Double.MIN_VALUE);
 189.184  
 189.185                  if( i >= 10) {
   190.1 --- a/test/java/lang/Math/Log10Tests.java	Fri Sep 30 17:20:56 2011 -0700
   190.2 +++ b/test/java/lang/Math/Log10Tests.java	Tue Oct 04 12:39:42 2011 -0700
   190.3 @@ -1,5 +1,5 @@
   190.4  /*
   190.5 - * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
   190.6 + * Copyright (c) 2003, 2011 Oracle and/or its affiliates. All rights reserved.
   190.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   190.8   *
   190.9   * This code is free software; you can redistribute it and/or modify it
  190.10 @@ -28,7 +28,6 @@
  190.11   * @author Joseph D. Darcy
  190.12   */
  190.13  
  190.14 -import sun.misc.FpUtils;
  190.15  import sun.misc.DoubleConsts;
  190.16  
  190.17  public class Log10Tests {
  190.18 @@ -98,13 +97,13 @@
  190.19          // within a few ulps of log(x)/log(10)
  190.20          for(int i = 0; i < 10000; i++) {
  190.21              double input = Double.longBitsToDouble(rand.nextLong());
  190.22 -            if(! FpUtils.isFinite(input))
  190.23 +            if(! Double.isFinite(input))
  190.24                  continue; // avoid testing NaN and infinite values
  190.25              else {
  190.26                  input = Math.abs(input);
  190.27  
  190.28                  double expected = StrictMath.log(input)/LN_10;
  190.29 -                if( ! FpUtils.isFinite(expected))
  190.30 +                if( ! Double.isFinite(expected))
  190.31                      continue; // if log(input) overflowed, try again
  190.32                  else {
  190.33                      double result;
  190.34 @@ -153,16 +152,16 @@
  190.35              for(int i = 0; i < half; i++) {
  190.36                  if (i == 0) {
  190.37                      input[half] = 1.0;
  190.38 -                    up   = FpUtils.nextUp(1.0);
  190.39 -                    down = FpUtils.nextDown(1.0);
  190.40 +                    up   = Math.nextUp(1.0);
  190.41 +                    down = Math.nextDown(1.0);
  190.42                  } else {
  190.43                      input[half + i] = up;
  190.44                      input[half - i] = down;
  190.45 -                    up   = FpUtils.nextUp(up);
  190.46 -                    down = FpUtils.nextDown(down);
  190.47 +                    up   = Math.nextUp(up);
  190.48 +                    down = Math.nextDown(down);
  190.49                  }
  190.50              }
  190.51 -            input[0] = FpUtils.nextDown(input[1]);
  190.52 +            input[0] = Math.nextDown(input[1]);
  190.53  
  190.54              for(int i = 0; i < neighbors.length; i++) {
  190.55                  neighbors[i] =          Math.log10(input[i]);
   191.1 --- a/test/java/lang/Math/Log1pTests.java	Fri Sep 30 17:20:56 2011 -0700
   191.2 +++ b/test/java/lang/Math/Log1pTests.java	Tue Oct 04 12:39:42 2011 -0700
   191.3 @@ -1,5 +1,5 @@
   191.4  /*
   191.5 - * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
   191.6 + * Copyright (c) 2003, 2011 Oracle and/or its affiliates. All rights reserved.
   191.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   191.8   *
   191.9   * This code is free software; you can redistribute it and/or modify it
  191.10 @@ -88,14 +88,14 @@
  191.11  
  191.12          // For |x| < 2^-54 log1p(x) ~= x
  191.13          for(int i = DoubleConsts.MIN_SUB_EXPONENT; i <= -54; i++) {
  191.14 -            double d = FpUtils.scalb(2, i);
  191.15 +            double d = Math.scalb(2, i);
  191.16              failures += testLog1pCase(d, d);
  191.17              failures += testLog1pCase(-d, -d);
  191.18          }
  191.19  
  191.20          // For x > 2^53 log1p(x) ~= log(x)
  191.21          for(int i = 53; i <= DoubleConsts.MAX_EXPONENT; i++) {
  191.22 -            double d = FpUtils.scalb(2, i);
  191.23 +            double d = Math.scalb(2, i);
  191.24              failures += testLog1pCaseWithUlpDiff(d, StrictMath.log(d), 2.001);
  191.25          }
  191.26  
  191.27 @@ -105,7 +105,7 @@
  191.28          for(int i = 0; i < 1000; i++) {
  191.29              double d = rand.nextDouble();
  191.30  
  191.31 -            d = FpUtils.scalb(d, -53 - FpUtils.ilogb(d));
  191.32 +            d = Math.scalb(d, -53 - FpUtils.ilogb(d));
  191.33  
  191.34              for(int j = -53; j <= 52; j++) {
  191.35                  failures += testLog1pCaseWithUlpDiff(d, hp15cLogp(d), 5);
  191.36 @@ -135,10 +135,10 @@
  191.37                  double pc = StrictMath.pow(Math.E, i) - 1;
  191.38  
  191.39                  pcNeighbors[2] = pc;
  191.40 -                pcNeighbors[1] = FpUtils.nextDown(pc);
  191.41 -                pcNeighbors[0] = FpUtils.nextDown(pcNeighbors[1]);
  191.42 -                pcNeighbors[3] = FpUtils.nextUp(pc);
  191.43 -                pcNeighbors[4] = FpUtils.nextUp(pcNeighbors[3]);
  191.44 +                pcNeighbors[1] = Math.nextDown(pc);
  191.45 +                pcNeighbors[0] = Math.nextDown(pcNeighbors[1]);
  191.46 +                pcNeighbors[3] = Math.nextUp(pc);
  191.47 +                pcNeighbors[4] = Math.nextUp(pcNeighbors[3]);
  191.48  
  191.49                  for(int j = 0; j < pcNeighbors.length; j++) {
  191.50                      pcNeighborsLog1p[j]       =       Math.log1p(pcNeighbors[j]);
  191.51 @@ -202,5 +202,4 @@
  191.52              throw new RuntimeException();
  191.53          }
  191.54      }
  191.55 -
  191.56  }
   192.1 --- a/test/java/lang/Math/Rint.java	Fri Sep 30 17:20:56 2011 -0700
   192.2 +++ b/test/java/lang/Math/Rint.java	Tue Oct 04 12:39:42 2011 -0700
   192.3 @@ -1,5 +1,5 @@
   192.4  /*
   192.5 - * Copyright (c) 1998, 2003, Oracle and/or its affiliates. All rights reserved.
   192.6 + * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
   192.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   192.8   *
   192.9   * This code is free software; you can redistribute it and/or modify it
  192.10 @@ -25,10 +25,8 @@
  192.11   * @test
  192.12   * @bug 4101566 4831589
  192.13   * @summary Check for correct implementation of Math.rint(double)
  192.14 - *
  192.15   */
  192.16  
  192.17 -import sun.misc.FpUtils;
  192.18  import sun.misc.DoubleConsts;
  192.19  
  192.20  public class Rint {
  192.21 @@ -48,28 +46,28 @@
  192.22  
  192.23      public static void main(String args[]) {
  192.24          int failures = 0;
  192.25 -        double twoToThe52 = FpUtils.scalb(1.0, 52); // 2^52
  192.26 +        double twoToThe52 = Math.scalb(1.0, 52); // 2^52
  192.27  
  192.28          double [][] testCases = {
  192.29              {0.0,                               0.0},
  192.30              {Double.MIN_VALUE,                  0.0},
  192.31 -            {FpUtils.nextDown(DoubleConsts.MIN_NORMAL), 0.0},
  192.32 +            {Math.nextDown(DoubleConsts.MIN_NORMAL), 0.0},
  192.33              {DoubleConsts.MIN_NORMAL,           0.0},
  192.34  
  192.35              {0.2,                               0.0},
  192.36  
  192.37 -            {FpUtils.nextDown(0.5),             0.0},
  192.38 -            {                 0.5,              0.0},
  192.39 -            {  FpUtils.nextUp(0.5),             1.0},
  192.40 +            {Math.nextDown(0.5),             0.0},
  192.41 +            {              0.5,              0.0},
  192.42 +            {  Math.nextUp(0.5),             1.0},
  192.43  
  192.44              {0.7,                               1.0},
  192.45 -            {FpUtils.nextDown(1.0),             1.0},
  192.46 -            {                 1.0,              1.0},
  192.47 -            {  FpUtils.nextUp(1.0),             1.0},
  192.48 +            {Math.nextDown(1.0),             1.0},
  192.49 +            {              1.0,              1.0},
  192.50 +            {  Math.nextUp(1.0),             1.0},
  192.51  
  192.52 -            {FpUtils.nextDown(1.5),             1.0},
  192.53 -            {                 1.5,              2.0},
  192.54 -            {  FpUtils.nextUp(1.5),             2.0},
  192.55 +            {Math.nextDown(1.5),             1.0},
  192.56 +            {              1.5,              2.0},
  192.57 +            {  Math.nextUp(1.5),             2.0},
  192.58  
  192.59              {4.2,                               4.0},
  192.60              {4.5,                               4.0},
  192.61 @@ -81,19 +79,19 @@
  192.62  
  192.63              {150000.75,                         150001.0},
  192.64              {300000.5,                          300000.0},
  192.65 -            {FpUtils.nextUp(300000.5),          300001.0},
  192.66 -            {FpUtils.nextDown(300000.75),       300001.0},
  192.67 +            {Math.nextUp(300000.5),          300001.0},
  192.68 +            {Math.nextDown(300000.75),       300001.0},
  192.69              {300000.75,                         300001.0},
  192.70 -            {FpUtils.nextUp(300000.75),         300001.0},
  192.71 +            {Math.nextUp(300000.75),         300001.0},
  192.72              {300000.99,                         300001.0},
  192.73              {262144.75,                         262145.0}, //(2^18 ) + 0.75
  192.74              {499998.75,                         499999.0},
  192.75              {524287.75,                         524288.0}, //(2^19 -1) + 0.75
  192.76              {524288.75,                         524289.0},
  192.77  
  192.78 -            {FpUtils.nextDown(twoToThe52),      twoToThe52},
  192.79 +            {Math.nextDown(twoToThe52),      twoToThe52},
  192.80              {twoToThe52,                        twoToThe52},
  192.81 -            {FpUtils.nextUp(twoToThe52),        FpUtils.nextUp(twoToThe52)},
  192.82 +            {Math.nextUp(twoToThe52),        Math.nextUp(twoToThe52)},
  192.83  
  192.84              {Double.MAX_VALUE,          Double.MAX_VALUE},
  192.85              {Double.POSITIVE_INFINITY,  Double.POSITIVE_INFINITY},
  192.86 @@ -118,5 +116,4 @@
  192.87              throw new RuntimeException();
  192.88          }
  192.89      }
  192.90 -
  192.91  }
   193.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   193.2 +++ b/test/java/math/BigInteger/TestValueExact.java	Tue Oct 04 12:39:42 2011 -0700
   193.3 @@ -0,0 +1,194 @@
   193.4 +/*
   193.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
   193.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   193.7 + *
   193.8 + * This code is free software; you can redistribute it and/or modify it
   193.9 + * under the terms of the GNU General Public License version 2 only, as
  193.10 + * published by the Free Software Foundation.
  193.11 + *
  193.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  193.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  193.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  193.15 + * version 2 for more details (a copy is included in the LICENSE file that
  193.16 + * accompanied this code).
  193.17 + *
  193.18 + * You should have received a copy of the GNU General Public License version
  193.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  193.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  193.21 + *
  193.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  193.23 + * or visit www.oracle.com if you need additional information or have any
  193.24 + * questions.
  193.25 + */
  193.26 +
  193.27 +/*
  193.28 + * @test
  193.29 + * @bug 6371401
  193.30 + * @summary Tests of fooValueExact methods
  193.31 + * @author Joseph D. Darcy
  193.32 + */
  193.33 +import java.math.BigInteger;
  193.34 +
  193.35 +public class TestValueExact {
  193.36 +    public static void main(String... args) {
  193.37 +        int errors = 0;
  193.38 +
  193.39 +        errors += testLongValueExact();
  193.40 +        errors += testIntValueExact();
  193.41 +        errors += testShortValueExact();
  193.42 +        errors += testByteValueExact();
  193.43 +
  193.44 +        if (errors > 0)
  193.45 +            throw new RuntimeException();
  193.46 +    }
  193.47 +
  193.48 +    private static int testLongValueExact() {
  193.49 +        int errors = 0;
  193.50 +        BigInteger[] inRange = {
  193.51 +            BigInteger.valueOf(Long.MIN_VALUE),
  193.52 +            BigInteger.ZERO,
  193.53 +            BigInteger.valueOf(Long.MAX_VALUE)
  193.54 +        };
  193.55 +
  193.56 +        BigInteger[] outOfRange = {
  193.57 +            BigInteger.valueOf(Long.MIN_VALUE).subtract(BigInteger.ONE),
  193.58 +            BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.ONE)
  193.59 +        };
  193.60 +
  193.61 +        for (BigInteger bi : inRange) {
  193.62 +            if (bi.longValueExact() != bi.longValue()) {
  193.63 +                System.err.println("Mismatching int conversion for " + bi);
  193.64 +                errors++;
  193.65 +            }
  193.66 +        }
  193.67 +
  193.68 +        for (BigInteger bi : outOfRange) {
  193.69 +            try {
  193.70 +                long value = bi.longValueExact();
  193.71 +                System.err.println("Failed to get expected exception on " +
  193.72 +                                   bi + " got " + value);
  193.73 +                errors++;
  193.74 +            } catch(ArithmeticException ae) {
  193.75 +                ; // Expected
  193.76 +            }
  193.77 +        }
  193.78 +        return errors;
  193.79 +    }
  193.80 +
  193.81 +    private static int testIntValueExact() {
  193.82 +        int errors = 0;
  193.83 +        BigInteger[] inRange = {
  193.84 +            BigInteger.valueOf(Integer.MIN_VALUE),
  193.85 +            BigInteger.ZERO,
  193.86 +            BigInteger.ONE,
  193.87 +            BigInteger.TEN,
  193.88 +            BigInteger.valueOf(Integer.MAX_VALUE)
  193.89 +        };
  193.90 +
  193.91 +        BigInteger[] outOfRange = {
  193.92 +            BigInteger.valueOf((long)Integer.MIN_VALUE - 1),
  193.93 +            BigInteger.valueOf((long)Integer.MAX_VALUE + 1)
  193.94 +        };
  193.95 +
  193.96 +        for (BigInteger bi : inRange) {
  193.97 +            if (bi.intValueExact() != bi.intValue()) {
  193.98 +                System.err.println("Mismatching int conversion for " + bi);
  193.99 +                errors++;
 193.100 +            }
 193.101 +        }
 193.102 +
 193.103 +        for (BigInteger bi : outOfRange) {
 193.104 +            try {
 193.105 +                int value = bi.intValueExact();
 193.106 +                System.err.println("Failed to get expected exception on " +
 193.107 +                                   bi + " got " + value);
 193.108 +                errors++;
 193.109 +            } catch(ArithmeticException ae) {
 193.110 +                ; // Expected
 193.111 +            }
 193.112 +        }
 193.113 +        return errors;
 193.114 +    }
 193.115 +
 193.116 +    private static int testShortValueExact() {
 193.117 +        int errors = 0;
 193.118 +        BigInteger[] inRange = {
 193.119 +            BigInteger.valueOf(Short.MIN_VALUE),
 193.120 +            BigInteger.ZERO,
 193.121 +            BigInteger.ONE,
 193.122 +            BigInteger.TEN,
 193.123 +            BigInteger.valueOf(Short.MAX_VALUE)
 193.124 +        };
 193.125 +
 193.126 +        BigInteger[] outOfRange = {
 193.127 +            BigInteger.valueOf((long)Integer.MIN_VALUE - 1),
 193.128 +            BigInteger.valueOf((long)Integer.MIN_VALUE),
 193.129 +            BigInteger.valueOf(   (int)Short.MIN_VALUE - 1),
 193.130 +            BigInteger.valueOf(   (int)Short.MAX_VALUE + 1),
 193.131 +            BigInteger.valueOf((long)Integer.MAX_VALUE),
 193.132 +            BigInteger.valueOf((long)Integer.MAX_VALUE + 1)
 193.133 +        };
 193.134 +
 193.135 +        for (BigInteger bi : inRange) {
 193.136 +            if (bi.shortValueExact() != bi.shortValue()) {
 193.137 +                System.err.println("Mismatching short  conversion for " + bi);
 193.138 +                errors++;
 193.139 +            }
 193.140 +        }
 193.141 +
 193.142 +        for (BigInteger bi : outOfRange) {
 193.143 +            try {
 193.144 +                int value = bi.shortValueExact();
 193.145 +                System.err.println("Failed to get expected exception on " +
 193.146 +                                   bi + " got " + value);
 193.147 +                errors++;
 193.148 +            } catch(ArithmeticException ae) {
 193.149 +                ; // Expected
 193.150 +            }
 193.151 +        }
 193.152 +        return errors;
 193.153 +    }
 193.154 +
 193.155 +    private static int testByteValueExact() {
 193.156 +        int errors = 0;
 193.157 +        BigInteger[] inRange = {
 193.158 +            BigInteger.valueOf(Byte.MIN_VALUE),
 193.159 +            BigInteger.valueOf(0),
 193.160 +            BigInteger.ONE,
 193.161 +            BigInteger.TEN,
 193.162 +            BigInteger.valueOf(Byte.MAX_VALUE)
 193.163 +        };
 193.164 +
 193.165 +        BigInteger[] outOfRange = {
 193.166 +            BigInteger.valueOf((long)Integer.MIN_VALUE - 1),
 193.167 +            BigInteger.valueOf((long)Integer.MIN_VALUE),
 193.168 +            BigInteger.valueOf(   (int)Short.MIN_VALUE - 1),
 193.169 +            BigInteger.valueOf(   (int)Short.MIN_VALUE),
 193.170 +            BigInteger.valueOf(    (int)Byte.MIN_VALUE - 1),
 193.171 +            BigInteger.valueOf(    (int)Byte.MAX_VALUE + 1),
 193.172 +            BigInteger.valueOf(   (int)Short.MAX_VALUE + 1),
 193.173 +            BigInteger.valueOf(   (int)Short.MAX_VALUE),
 193.174 +            BigInteger.valueOf((long)Integer.MAX_VALUE),
 193.175 +            BigInteger.valueOf((long)Integer.MAX_VALUE + 1)
 193.176 +        };
 193.177 +
 193.178 +        for (BigInteger bi : inRange) {
 193.179 +            if (bi.byteValueExact() != bi.byteValue()) {
 193.180 +                System.err.println("Mismatching byte conversion for " + bi);
 193.181 +                errors++;
 193.182 +            }
 193.183 +        }
 193.184 +
 193.185 +        for (BigInteger bi : outOfRange) {
 193.186 +            try {
 193.187 +                int value = bi.byteValueExact();
 193.188 +                System.err.println("Failed to get expected exception on " +
 193.189 +                                   bi + " got " + value);
 193.190 +                errors++;
 193.191 +            } catch(ArithmeticException ae) {
 193.192 +                ; // Expected
 193.193 +            }
 193.194 +        }
 193.195 +        return errors;
 193.196 +    }
 193.197 +}
   194.1 --- a/test/java/util/Formatter/Basic-X.java.template	Fri Sep 30 17:20:56 2011 -0700
   194.2 +++ b/test/java/util/Formatter/Basic-X.java.template	Tue Oct 04 12:39:42 2011 -0700
   194.3 @@ -1,5 +1,5 @@
   194.4  /*
   194.5 - * Copyright (c) 2003, 2007, Oracle and/or its affiliates. All rights reserved.
   194.6 + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
   194.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   194.8   *
   194.9   * This code is free software; you can redistribute it and/or modify it
  194.10 @@ -36,7 +36,6 @@
  194.11  import java.text.DateFormatSymbols;
  194.12  import java.util.*;
  194.13  #if[double]
  194.14 -import sun.misc.FpUtils;
  194.15  import sun.misc.DoubleConsts;
  194.16  #end[double]
  194.17  
  194.18 @@ -1301,9 +1300,9 @@
  194.19          test("%.11a", "0x1.00000000000p-1022", DoubleConsts.MIN_NORMAL);
  194.20          test("%.1a", "0x1.0p-1022", DoubleConsts.MIN_NORMAL);
  194.21          test("%.11a", "0x1.00000000000p-1022",
  194.22 -             FpUtils.nextDown(DoubleConsts.MIN_NORMAL));
  194.23 +             Math.nextDown(DoubleConsts.MIN_NORMAL));
  194.24          test("%.1a", "0x1.0p-1022",
  194.25 -             FpUtils.nextDown(DoubleConsts.MIN_NORMAL));
  194.26 +             Math.nextDown(DoubleConsts.MIN_NORMAL));
  194.27          test("%.11a", "0x1.ffffffffffep-1023",
  194.28               Double.parseDouble("0x0.fffffffffffp-1022"));
  194.29          test("%.1a", "0x1.0p-1022",
   195.1 --- a/test/java/util/Formatter/BasicBigDecimal.java	Fri Sep 30 17:20:56 2011 -0700
   195.2 +++ b/test/java/util/Formatter/BasicBigDecimal.java	Tue Oct 04 12:39:42 2011 -0700
   195.3 @@ -1,5 +1,5 @@
   195.4  /*
   195.5 - * Copyright (c) 2003, 2007, Oracle and/or its affiliates. All rights reserved.
   195.6 + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
   195.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   195.8   *
   195.9   * This code is free software; you can redistribute it and/or modify it
  195.10 @@ -39,7 +39,6 @@
  195.11  
  195.12  
  195.13  
  195.14 -
  195.15  import static java.util.Calendar.*;
  195.16  
  195.17  
   196.1 --- a/test/java/util/Formatter/BasicBigInteger.java	Fri Sep 30 17:20:56 2011 -0700
   196.2 +++ b/test/java/util/Formatter/BasicBigInteger.java	Tue Oct 04 12:39:42 2011 -0700
   196.3 @@ -1,5 +1,5 @@
   196.4  /*
   196.5 - * Copyright (c) 2003, 2007, Oracle and/or its affiliates. All rights reserved.
   196.6 + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
   196.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   196.8   *
   196.9   * This code is free software; you can redistribute it and/or modify it
  196.10 @@ -39,7 +39,6 @@
  196.11  
  196.12  
  196.13  
  196.14 -
  196.15  import static java.util.Calendar.*;
  196.16  
  196.17  
   197.1 --- a/test/java/util/Formatter/BasicBoolean.java	Fri Sep 30 17:20:56 2011 -0700
   197.2 +++ b/test/java/util/Formatter/BasicBoolean.java	Tue Oct 04 12:39:42 2011 -0700
   197.3 @@ -1,5 +1,5 @@
   197.4  /*
   197.5 - * Copyright (c) 2003, 2007, Oracle and/or its affiliates. All rights reserved.
   197.6 + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
   197.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   197.8   *
   197.9   * This code is free software; you can redistribute it and/or modify it
  197.10 @@ -39,7 +39,6 @@
  197.11  
  197.12  
  197.13  
  197.14 -
  197.15  import static java.util.Calendar.*;
  197.16  
  197.17  
   198.1 --- a/test/java/util/Formatter/BasicBooleanObject.java	Fri Sep 30 17:20:56 2011 -0700
   198.2 +++ b/test/java/util/Formatter/BasicBooleanObject.java	Tue Oct 04 12:39:42 2011 -0700
   198.3 @@ -1,5 +1,5 @@
   198.4  /*
   198.5 - * Copyright (c) 2003, 2007, Oracle and/or its affiliates. All rights reserved.
   198.6 + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
   198.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   198.8   *
   198.9   * This code is free software; you can redistribute it and/or modify it
  198.10 @@ -39,7 +39,6 @@
  198.11  
  198.12  
  198.13  
  198.14 -
  198.15  import static java.util.Calendar.*;
  198.16  
  198.17  
   199.1 --- a/test/java/util/Formatter/BasicByte.java	Fri Sep 30 17:20:56 2011 -0700
   199.2 +++ b/test/java/util/Formatter/BasicByte.java	Tue Oct 04 12:39:42 2011 -0700
   199.3 @@ -1,5 +1,5 @@
   199.4  /*
   199.5 - * Copyright (c) 2003, 2007, Oracle and/or its affiliates. All rights reserved.
   199.6 + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
   199.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   199.8   *
   199.9   * This code is free software; you can redistribute it and/or modify it
  199.10 @@ -39,7 +39,6 @@
  199.11  
  199.12  
  199.13  
  199.14 -
  199.15  import static java.util.Calendar.*;
  199.16  
  199.17  
   200.1 --- a/test/java/util/Formatter/BasicByteObject.java	Fri Sep 30 17:20:56 2011 -0700
   200.2 +++ b/test/java/util/Formatter/BasicByteObject.java	Tue Oct 04 12:39:42 2011 -0700
   200.3 @@ -1,5 +1,5 @@
   200.4  /*
   200.5 - * Copyright (c) 2003, 2007, Oracle and/or its affiliates. All rights reserved.
   200.6 + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
   200.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   200.8   *
   200.9   * This code is free software; you can redistribute it and/or modify it
  200.10 @@ -39,7 +39,6 @@
  200.11  
  200.12  
  200.13  
  200.14 -
  200.15  import static java.util.Calendar.*;
  200.16  
  200.17  
   201.1 --- a/test/java/util/Formatter/BasicChar.java	Fri Sep 30 17:20:56 2011 -0700
   201.2 +++ b/test/java/util/Formatter/BasicChar.java	Tue Oct 04 12:39:42 2011 -0700
   201.3 @@ -1,5 +1,5 @@
   201.4  /*
   201.5 - * Copyright (c) 2003, 2007, Oracle and/or its affiliates. All rights reserved.
   201.6 + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
   201.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   201.8   *
   201.9   * This code is free software; you can redistribute it and/or modify it
  201.10 @@ -39,7 +39,6 @@
  201.11  
  201.12  
  201.13  
  201.14 -
  201.15  import static java.util.Calendar.*;
  201.16  
  201.17  
   202.1 --- a/test/java/util/Formatter/BasicCharObject.java	Fri Sep 30 17:20:56 2011 -0700
   202.2 +++ b/test/java/util/Formatter/BasicCharObject.java	Tue Oct 04 12:39:42 2011 -0700
   202.3 @@ -1,5 +1,5 @@
   202.4  /*
   202.5 - * Copyright (c) 2003, 2007, Oracle and/or its affiliates. All rights reserved.
   202.6 + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
   202.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   202.8   *
   202.9   * This code is free software; you can redistribute it and/or modify it
  202.10 @@ -39,7 +39,6 @@
  202.11  
  202.12  
  202.13  
  202.14 -
  202.15  import static java.util.Calendar.*;
  202.16  
  202.17  
   203.1 --- a/test/java/util/Formatter/BasicDateTime.java	Fri Sep 30 17:20:56 2011 -0700
   203.2 +++ b/test/java/util/Formatter/BasicDateTime.java	Tue Oct 04 12:39:42 2011 -0700
   203.3 @@ -1,5 +1,5 @@
   203.4  /*
   203.5 - * Copyright (c) 2003, 2007, Oracle and/or its affiliates. All rights reserved.
   203.6 + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
   203.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   203.8   *
   203.9   * This code is free software; you can redistribute it and/or modify it
  203.10 @@ -39,7 +39,6 @@
  203.11  
  203.12  
  203.13  
  203.14 -
  203.15  import static java.util.Calendar.*;
  203.16  
  203.17  import static java.util.SimpleTimeZone.*;
   204.1 --- a/test/java/util/Formatter/BasicDouble.java	Fri Sep 30 17:20:56 2011 -0700
   204.2 +++ b/test/java/util/Formatter/BasicDouble.java	Tue Oct 04 12:39:42 2011 -0700
   204.3 @@ -1,5 +1,5 @@
   204.4  /*
   204.5 - * Copyright (c) 2003, 2007, Oracle and/or its affiliates. All rights reserved.
   204.6 + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
   204.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   204.8   *
   204.9   * This code is free software; you can redistribute it and/or modify it
  204.10 @@ -36,7 +36,6 @@
  204.11  import java.text.DateFormatSymbols;
  204.12  import java.util.*;
  204.13  
  204.14 -import sun.misc.FpUtils;
  204.15  import sun.misc.DoubleConsts;
  204.16  
  204.17  
  204.18 @@ -1301,9 +1300,9 @@
  204.19          test("%.11a", "0x1.00000000000p-1022", DoubleConsts.MIN_NORMAL);
  204.20          test("%.1a", "0x1.0p-1022", DoubleConsts.MIN_NORMAL);
  204.21          test("%.11a", "0x1.00000000000p-1022",
  204.22 -             FpUtils.nextDown(DoubleConsts.MIN_NORMAL));
  204.23 +             Math.nextDown(DoubleConsts.MIN_NORMAL));
  204.24          test("%.1a", "0x1.0p-1022",
  204.25 -             FpUtils.nextDown(DoubleConsts.MIN_NORMAL));
  204.26 +             Math.nextDown(DoubleConsts.MIN_NORMAL));
  204.27          test("%.11a", "0x1.ffffffffffep-1023",
  204.28               Double.parseDouble("0x0.fffffffffffp-1022"));
  204.29          test("%.1a", "0x1.0p-1022",
   205.1 --- a/test/java/util/Formatter/BasicDoubleObject.java	Fri Sep 30 17:20:56 2011 -0700
   205.2 +++ b/test/java/util/Formatter/BasicDoubleObject.java	Tue Oct 04 12:39:42 2011 -0700
   205.3 @@ -1,5 +1,5 @@
   205.4  /*
   205.5 - * Copyright (c) 2003, 2007, Oracle and/or its affiliates. All rights reserved.
   205.6 + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
   205.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   205.8   *
   205.9   * This code is free software; you can redistribute it and/or modify it
  205.10 @@ -39,7 +39,6 @@
  205.11  
  205.12  
  205.13  
  205.14 -
  205.15  import static java.util.Calendar.*;
  205.16  
  205.17  
   206.1 --- a/test/java/util/Formatter/BasicFloat.java	Fri Sep 30 17:20:56 2011 -0700
   206.2 +++ b/test/java/util/Formatter/BasicFloat.java	Tue Oct 04 12:39:42 2011 -0700
   206.3 @@ -1,5 +1,5 @@
   206.4  /*
   206.5 - * Copyright (c) 2003, 2007, Oracle and/or its affiliates. All rights reserved.
   206.6 + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
   206.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   206.8   *
   206.9   * This code is free software; you can redistribute it and/or modify it
  206.10 @@ -39,7 +39,6 @@
  206.11  
  206.12  
  206.13  
  206.14 -
  206.15  import static java.util.Calendar.*;
  206.16  
  206.17  
   207.1 --- a/test/java/util/Formatter/BasicFloatObject.java	Fri Sep 30 17:20:56 2011 -0700
   207.2 +++ b/test/java/util/Formatter/BasicFloatObject.java	Tue Oct 04 12:39:42 2011 -0700
   207.3 @@ -1,5 +1,5 @@
   207.4  /*
   207.5 - * Copyright (c) 2003, 2007, Oracle and/or its affiliates. All rights reserved.
   207.6 + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
   207.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   207.8   *
   207.9   * This code is free software; you can redistribute it and/or modify it
  207.10 @@ -39,7 +39,6 @@
  207.11  
  207.12  
  207.13  
  207.14 -
  207.15  import static java.util.Calendar.*;
  207.16  
  207.17  
   208.1 --- a/test/java/util/Formatter/BasicInt.java	Fri Sep 30 17:20:56 2011 -0700
   208.2 +++ b/test/java/util/Formatter/BasicInt.java	Tue Oct 04 12:39:42 2011 -0700
   208.3 @@ -1,5 +1,5 @@
   208.4  /*
   208.5 - * Copyright (c) 2003, 2007, Oracle and/or its affiliates. All rights reserved.
   208.6 + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
   208.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   208.8   *
   208.9   * This code is free software; you can redistribute it and/or modify it
  208.10 @@ -39,7 +39,6 @@
  208.11  
  208.12  
  208.13  
  208.14 -
  208.15  import static java.util.Calendar.*;
  208.16  
  208.17  
   209.1 --- a/test/java/util/Formatter/BasicIntObject.java	Fri Sep 30 17:20:56 2011 -0700
   209.2 +++ b/test/java/util/Formatter/BasicIntObject.java	Tue Oct 04 12:39:42 2011 -0700
   209.3 @@ -1,5 +1,5 @@
   209.4  /*
   209.5 - * Copyright (c) 2003, 2007, Oracle and/or its affiliates. All rights reserved.
   209.6 + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
   209.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   209.8   *
   209.9   * This code is free software; you can redistribute it and/or modify it
  209.10 @@ -39,7 +39,6 @@
  209.11  
  209.12  
  209.13  
  209.14 -
  209.15  import static java.util.Calendar.*;
  209.16  
  209.17  
   210.1 --- a/test/java/util/Formatter/BasicLong.java	Fri Sep 30 17:20:56 2011 -0700
   210.2 +++ b/test/java/util/Formatter/BasicLong.java	Tue Oct 04 12:39:42 2011 -0700
   210.3 @@ -1,5 +1,5 @@
   210.4  /*
   210.5 - * Copyright (c) 2003, 2007, Oracle and/or its affiliates. All rights reserved.
   210.6 + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
   210.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   210.8   *
   210.9   * This code is free software; you can redistribute it and/or modify it
  210.10 @@ -39,7 +39,6 @@
  210.11  
  210.12  
  210.13  
  210.14 -
  210.15  import static java.util.Calendar.*;
  210.16  
  210.17  
   211.1 --- a/test/java/util/Formatter/BasicLongObject.java	Fri Sep 30 17:20:56 2011 -0700
   211.2 +++ b/test/java/util/Formatter/BasicLongObject.java	Tue Oct 04 12:39:42 2011 -0700
   211.3 @@ -1,5 +1,5 @@
   211.4  /*
   211.5 - * Copyright (c) 2003, 2007, Oracle and/or its affiliates. All rights reserved.
   211.6 + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
   211.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   211.8   *
   211.9   * This code is free software; you can redistribute it and/or modify it
  211.10 @@ -39,7 +39,6 @@
  211.11  
  211.12  
  211.13  
  211.14 -
  211.15  import static java.util.Calendar.*;
  211.16  
  211.17  
   212.1 --- a/test/java/util/Formatter/BasicShort.java	Fri Sep 30 17:20:56 2011 -0700
   212.2 +++ b/test/java/util/Formatter/BasicShort.java	Tue Oct 04 12:39:42 2011 -0700
   212.3 @@ -1,5 +1,5 @@
   212.4  /*
   212.5 - * Copyright (c) 2003, 2007, Oracle and/or its affiliates. All rights reserved.
   212.6 + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
   212.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   212.8   *
   212.9   * This code is free software; you can redistribute it and/or modify it
  212.10 @@ -39,7 +39,6 @@
  212.11  
  212.12  
  212.13  
  212.14 -
  212.15  import static java.util.Calendar.*;
  212.16  
  212.17  
   213.1 --- a/test/java/util/Formatter/BasicShortObject.java	Fri Sep 30 17:20:56 2011 -0700
   213.2 +++ b/test/java/util/Formatter/BasicShortObject.java	Tue Oct 04 12:39:42 2011 -0700
   213.3 @@ -1,5 +1,5 @@
   213.4  /*
   213.5 - * Copyright (c) 2003, 2007, Oracle and/or its affiliates. All rights reserved.
   213.6 + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
   213.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   213.8   *
   213.9   * This code is free software; you can redistribute it and/or modify it
  213.10 @@ -39,7 +39,6 @@
  213.11  
  213.12  
  213.13  
  213.14 -
  213.15  import static java.util.Calendar.*;
  213.16  
  213.17  
   214.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   214.2 +++ b/test/java/util/concurrent/ScheduledThreadPoolExecutor/ZeroCorePoolSize.java	Tue Oct 04 12:39:42 2011 -0700
   214.3 @@ -0,0 +1,83 @@
   214.4 +/*
   214.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
   214.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   214.7 + *
   214.8 + * This code is free software; you can redistribute it and/or modify it
   214.9 + * under the terms of the GNU General Public License version 2 only, as
  214.10 + * published by the Free Software Foundation.
  214.11 + *
  214.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  214.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  214.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  214.15 + * version 2 for more details (a copy is included in the LICENSE file that
  214.16 + * accompanied this code).
  214.17 + *
  214.18 + * You should have received a copy of the GNU General Public License version
  214.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  214.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  214.21 + *
  214.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  214.23 + * or visit www.oracle.com if you need additional information or have any
  214.24 + * questions.
  214.25 + */
  214.26 +
  214.27 +/*
  214.28 + * @test
  214.29 + * @bug 7091003
  214.30 + * @summary ScheduledExecutorService never executes Runnable
  214.31 + *          with corePoolSize of zero
  214.32 + * @author Chris Hegarty
  214.33 + */
  214.34 +
  214.35 +import java.util.concurrent.ScheduledThreadPoolExecutor;
  214.36 +import java.util.concurrent.TimeUnit;
  214.37 +
  214.38 +/**
  214.39 + * Verify that tasks can be run even with a core pool size of 0.
  214.40 + */
  214.41 +public class ZeroCorePoolSize {
  214.42 +
  214.43 +    volatile boolean taskRun;
  214.44 +
  214.45 +    void test(String[] args) throws Throwable {
  214.46 +
  214.47 +        ScheduledThreadPoolExecutor pool = new ScheduledThreadPoolExecutor(0);
  214.48 +        Runnable task = new Runnable() {
  214.49 +            public void run() {
  214.50 +                taskRun = true;
  214.51 +            }
  214.52 +        };
  214.53 +        check(pool.getCorePoolSize() == 0);
  214.54 +
  214.55 +        pool.schedule(task, 1, TimeUnit.SECONDS);
  214.56 +
  214.57 +        pool.shutdown();
  214.58 +        check(pool.awaitTermination(20L, TimeUnit.SECONDS));
  214.59 +        check(pool.getCorePoolSize() == 0);
  214.60 +        check(taskRun);
  214.61 +    }
  214.62 +
  214.63 +    //--------------------- Infrastructure ---------------------------
  214.64 +    volatile int passed = 0, failed = 0;
  214.65 +    void pass() {passed++;}
  214.66 +    void fail() {failed++; Thread.dumpStack();}
  214.67 +    void fail(String msg) {System.err.println(msg); fail();}
  214.68 +    void unexpected(Throwable t) {failed++; t.printStackTrace();}
  214.69 +    void check(boolean cond) {if (cond) pass(); else fail();}
  214.70 +    void equal(Object x, Object y) {
  214.71 +        if (x == null ? y == null : x.equals(y)) pass();
  214.72 +        else fail(x + " not equal to " + y);}
  214.73 +    public static void main(String[] args) throws Throwable {
  214.74 +        new ZeroCorePoolSize().instanceMain(args);}
  214.75 +    void instanceMain(String[] args) throws Throwable {
  214.76 +        try {test(args);} catch (Throwable t) {unexpected(t);}
  214.77 +        System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
  214.78 +        if (failed > 0) throw new AssertionError("Some tests failed");}
  214.79 +    abstract class F {abstract void f() throws Throwable;}
  214.80 +    void THROWS(Class<? extends Throwable> k, F... fs) {
  214.81 +        for (F f : fs)
  214.82 +            try {f.f(); fail("Expected " + k.getName() + " not thrown");}
  214.83 +            catch (Throwable t) {
  214.84 +                if (k.isAssignableFrom(t.getClass())) pass();
  214.85 +                else unexpected(t);}}
  214.86 +}
   215.1 --- a/test/java/util/logging/ParentLoggersTest.java	Fri Sep 30 17:20:56 2011 -0700
   215.2 +++ b/test/java/util/logging/ParentLoggersTest.java	Tue Oct 04 12:39:42 2011 -0700
   215.3 @@ -6,7 +6,7 @@
   215.4   * @author  ss45998
   215.5   *
   215.6   * @build ParentLoggersTest
   215.7 - * @run main ParentLoggersTest
   215.8 + * @run main/othervm ParentLoggersTest
   215.9   */
  215.10  
  215.11  /*
   216.1 --- a/test/javax/security/auth/Subject/Synch.java	Fri Sep 30 17:20:56 2011 -0700
   216.2 +++ b/test/javax/security/auth/Subject/Synch.java	Tue Oct 04 12:39:42 2011 -0700
   216.3 @@ -35,15 +35,15 @@
   216.4  import javax.security.auth.x500.X500Principal;
   216.5  
   216.6  public class Synch {
   216.7 +    static volatile boolean finished = false;
   216.8      public static void main(String[] args) {
   216.9          Subject subject = new Subject();
  216.10          final Set principals = subject.getPrincipals();
  216.11          principals.add(new X500Principal("CN=Alice"));
  216.12          new Thread() {
  216.13 -            { setDaemon(true); }
  216.14              public void run() {
  216.15                  Principal last = new X500Principal("CN=Bob");
  216.16 -                for (int i = 0; true; i++) {
  216.17 +                for (int i = 0; !finished; i++) {
  216.18                      Principal next = new X500Principal("CN=Bob" + i);
  216.19                      principals.add(next);
  216.20                      principals.remove(last);
  216.21 @@ -70,5 +70,6 @@
  216.22                      }
  216.23                  });
  216.24          }
  216.25 +        finished = true;
  216.26      }
  216.27  }
   217.1 --- a/test/javax/security/auth/Subject/Synch2.java	Fri Sep 30 17:20:56 2011 -0700
   217.2 +++ b/test/javax/security/auth/Subject/Synch2.java	Tue Oct 04 12:39:42 2011 -0700
   217.3 @@ -35,6 +35,7 @@
   217.4  import javax.security.auth.x500.X500Principal;
   217.5  
   217.6  public class Synch2 {
   217.7 +    static volatile boolean finished = false;
   217.8      public static void main(String[] args) {
   217.9          System.setSecurityManager(new SecurityManager());
  217.10          Subject subject = new Subject();
  217.11 @@ -44,12 +45,11 @@
  217.12          credentials.add("Dummy credential");
  217.13          new Thread() {
  217.14              {
  217.15 -                setDaemon(true);
  217.16                  start();
  217.17              }
  217.18              public void run() {
  217.19                  X500Principal p = new X500Principal("CN=Bob");
  217.20 -                while (true) {
  217.21 +                while (!finished) {
  217.22                      principals.add(p);
  217.23                      principals.remove(p);
  217.24                  }
  217.25 @@ -62,5 +62,6 @@
  217.26                  }
  217.27              }
  217.28          }
  217.29 +        finished = true;
  217.30      }
  217.31  }
   218.1 --- a/test/javax/security/auth/Subject/Synch3.java	Fri Sep 30 17:20:56 2011 -0700
   218.2 +++ b/test/javax/security/auth/Subject/Synch3.java	Tue Oct 04 12:39:42 2011 -0700
   218.3 @@ -33,18 +33,18 @@
   218.4  import javax.security.auth.x500.X500Principal;
   218.5  
   218.6  public class Synch3 {
   218.7 +    static volatile boolean finished = false;
   218.8      public static void main(String[] args) {
   218.9          Subject subject = new Subject();
  218.10          final Set principals = subject.getPrincipals();
  218.11          principals.add(new X500Principal("CN=Alice"));
  218.12          new Thread() {
  218.13              {
  218.14 -                setDaemon(true);
  218.15                  start();
  218.16              }
  218.17              public void run() {
  218.18                  X500Principal p = new X500Principal("CN=Bob");
  218.19 -                while (true) {
  218.20 +                while (!finished) {
  218.21                      principals.add(p);
  218.22                      principals.remove(p);
  218.23                  }
  218.24 @@ -53,5 +53,6 @@
  218.25          for (int i = 0; i < 1000; i++) {
  218.26              subject.getPrincipals(X500Principal.class);
  218.27          }
  218.28 +        finished = true;
  218.29      }
  218.30  }
   219.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
   219.2 +++ b/test/javax/swing/SwingUtilities/7088744/bug7088744.java	Tue Oct 04 12:39:42 2011 -0700
   219.3 @@ -0,0 +1,221 @@
   219.4 +/*
   219.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
   219.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   219.7 + *
   219.8 + * This code is free software; you can redistribute it and/or modify it
   219.9 + * under the terms of the GNU General Public License version 2 only, as
  219.10 + * published by the Free Software Foundation.
  219.11 + *
  219.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
  219.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  219.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  219.15 + * version 2 for more details (a copy is included in the LICENSE file that
  219.16 + * accompanied this code).
  219.17 + *
  219.18 + * You should have received a copy of the GNU General Public License version
  219.19 + * 2 along with this work; if not, write to the Free Software Foundation,
  219.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  219.21 + *
  219.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  219.23 + * or visit www.oracle.com if you need additional information or have any
  219.24 + * questions.
  219.25 + */
  219.26 +
  219.27 +/* @test
  219.28 +   @bug 7088744
  219.29 +   @summary SwingUtilities.isMiddleMouseButton does not work with ALT/Meta keys
  219.30 +   @author Pavel Porvatov
  219.31 +*/
  219.32 +
  219.33 +import sun.awt.SunToolkit;
  219.34 +
  219.35 +import javax.swing.*;
  219.36 +import java.awt.*;
  219.37 +import java.awt.event.InputEvent;
  219.38 +import java.awt.event.MouseAdapter;
  219.39 +import java.awt.event.MouseEvent;
  219.40 +
  219.41 +public class bug7088744 {
  219.42 +    private static volatile JLabel label;
  219.43 +
  219.44 +    private static volatile Point point;
  219.45 +
  219.46 +    private static final int MOUSE_CLICKED = 1;
  219.47 +    private static final int MOUSE_PRESSED = 2;
  219.48 +    private static final int MOUSE_RELEASED = 3;
  219.49 +
  219.50 +    // Pair with (EventType, Mouse Button)
  219.51 +    private static final int[][] BUTTON_EVENTS_SEQUENCE = {
  219.52 +            {MOUSE_PRESSED, 1},
  219.53 +            {MOUSE_PRESSED, 2},
  219.54 +            {MOUSE_PRESSED, 3},
  219.55 +            {MOUSE_RELEASED, 1},
  219.56 +            {MOUSE_CLICKED, 1},
  219.57 +            {MOUSE_RELEASED, 2},
  219.58 +            {MOUSE_CLICKED, 2},
  219.59 +            {MOUSE_RELEASED, 3},
  219.60 +            {MOUSE_CLICKED, 3}
  219.61 +    };
  219.62 +
  219.63 +    private static int eventCount;
  219.64 +
  219.65 +    public static void main(String[] args) throws Exception {
  219.66 +        SwingUtilities.invokeAndWait(new Runnable() {
  219.67 +            public void run() {
  219.68 +                Component source = new JLabel();
  219.69 +
  219.70 +                MouseEvent mouseEventNoButtons = new MouseEvent(source, 0, System.currentTimeMillis(),
  219.71 +                        Event.ALT_MASK | Event.META_MASK | InputEvent.ALT_DOWN_MASK | InputEvent.META_DOWN_MASK,
  219.72 +                        0, 0, 0, false, MouseEvent.NOBUTTON);
  219.73 +
  219.74 +                // isLeftMouseButton
  219.75 +                if (SwingUtilities.isLeftMouseButton(mouseEventNoButtons)) {
  219.76 +                    throw new RuntimeException("SwingUtilities.isLeftMouseButton fails 1");
  219.77 +                }
  219.78 +
  219.79 +                if (!SwingUtilities.isLeftMouseButton(new MouseEvent(source, 0, System.currentTimeMillis(),
  219.80 +                        InputEvent.BUTTON1_MASK, 0, 0, 1, false, MouseEvent.BUTTON1))) {
  219.81 +                    throw new RuntimeException("SwingUtilities.isLeftMouseButton fails 2");
  219.82 +                }
  219.83 +
  219.84 +                if (!SwingUtilities.isLeftMouseButton(new MouseEvent(source, 0, System.currentTimeMillis(),
  219.85 +                        InputEvent.BUTTON1_DOWN_MASK, 0, 0, 1, false, MouseEvent.BUTTON1))) {
  219.86 +                    throw new RuntimeException("SwingUtilities.isLeftMouseButton fails 3");
  219.87 +                }
  219.88 +
  219.89 +                // isMiddleMouseButton
  219.90 +                if (SwingUtilities.isMiddleMouseButton(mouseEventNoButtons)) {
  219.91 +                    throw new RuntimeException("SwingUtilities.isMiddleMouseButton fails 1");
  219.92 +                }
  219.93 +
  219.94 +                if (!SwingUtilities.isMiddleMouseButton(new MouseEvent(source, 0, System.currentTimeMillis(),
  219.95 +                        InputEvent.BUTTON2_MASK, 0, 0, 1, false, MouseEvent.BUTTON2))) {
  219.96 +                    throw new RuntimeException("SwingUtilities.isMiddleMouseButton fails 2");
  219.97 +                }
  219.98 +
  219.99 +                if (!SwingUtilities.isMiddleMouseButton(new MouseEvent(source, 0, System.currentTimeMillis(),
 219.100 +                        InputEvent.BUTTON2_DOWN_MASK, 0, 0, 1, false, MouseEvent.BUTTON2))) {
 219.101 +                    throw new RuntimeException("SwingUtilities.isMiddleMouseButton fails 3");
 219.102 +                }
 219.103 +
 219.104 +                // isRightMouseButton
 219.105 +                if (SwingUtilities.isRightMouseButton(mouseEventNoButtons)) {
 219.106 +                    throw new RuntimeException("SwingUtilities.isRightMouseButton fails 1");
 219.107 +                }
 219.108 +
 219.109 +                if (!SwingUtilities.isRightMouseButton(new MouseEvent(source, 0, System.currentTimeMillis(),
 219.110 +                        InputEvent.BUTTON3_MASK, 0, 0, 1, false, MouseEvent.BUTTON3))) {
 219.111 +                    throw new RuntimeException("SwingUtilities.isRightMouseButton fails 2");
 219.112 +                }
 219.113 +
 219.114 +                if (!SwingUtilities.isRightMouseButton(new MouseEvent(source, 0, System.currentTimeMillis(),
 219.115 +                        InputEvent.BUTTON3_DOWN_MASK, 0, 0, 1, false, MouseEvent.BUTTON3))) {
 219.116 +                    throw new RuntimeException("SwingUtilities.isRightMouseButton fails 3");
 219.117 +                }
 219.118 +            }
 219.119 +        });
 219.120 +
 219.121 +        SwingUtilities.invokeAndWait(new Runnable() {
 219.122 +            public void run() {
 219.123 +                JFrame frame = new JFrame();
 219.124 +
 219.125 +                label = new JLabel("A label");
 219.126 +
 219.127 +                label.addMouseListener(new MouseAdapter() {
 219.128 +                    public void mouseClicked(MouseEvent e) {
 219.129 +                        processEvent(MOUSE_CLICKED, e);
 219.130 +                    }
 219.131 +
 219.132 +                    public void mousePressed(MouseEvent e) {
 219.133 +                        processEvent(MOUSE_PRESSED, e);
 219.134 +                    }
 219.135 +
 219.136 +                    public void mouseReleased(MouseEvent e) {
 219.137 +                        processEvent(MOUSE_RELEASED, e);
 219.138 +                    }
 219.139 +                });
 219.140 +                frame.add(label);
 219.141 +                frame.setSize(200, 100);
 219.142 +                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 219.143 +                frame.setVisible(true);
 219.144 +            }
 219.145 +        });
 219.146 +
 219.147 +        SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
 219.148 +
 219.149 +        toolkit.realSync();
 219.150 +
 219.151 +        // On Linux platforms realSync doesn't guaranties setSize completion
 219.152 +        Thread.sleep(1000);
 219.153 +
 219.154 +        SwingUtilities.invokeAndWait(new Runnable() {
 219.155 +            public void run() {
 219.156 +                point = label.getLocationOnScreen();
 219.157 +            }
 219.158 +        });
 219.159 +
 219.160 +        Robot robot = new Robot();
 219.161 +
 219.162 +        robot.setAutoDelay(100);
 219.163 +        robot.mouseMove(point.x, point.y);
 219.164 +        robot.mousePress(InputEvent.BUTTON1_MASK);
 219.165 +        robot.mousePress(InputEvent.BUTTON2_MASK);
 219.166 +        robot.mousePress(InputEvent.BUTTON3_MASK);
 219.167 +        robot.mouseRelease(InputEvent.BUTTON1_MASK);
 219.168 +        robot.mouseRelease(InputEvent.BUTTON2_MASK);
 219.169 +        robot.mouseRelease(InputEvent.BUTTON3_MASK);
 219.170 +
 219.171 +        toolkit.realSync();
 219.172 +
 219.173 +        SwingUtilities.invokeAndWait(new Runnable() {
 219.174 +            public void run() {
 219.175 +                if (eventCount != BUTTON_EVENTS_SEQUENCE.length) {
 219.176 +                    throw new RuntimeException("Not all events received");
 219.177 +                }
 219.178 +
 219.179 +            }
 219.180 +        });
 219.181 +
 219.182 +        System.out.println("Test passed");
 219.183 +    }
 219.184 +
 219.185 +    private static void processEvent(int eventType, MouseEvent e) {
 219.186 +        if (eventCount >= BUTTON_EVENTS_SEQUENCE.length) {
 219.187 +            throw new RuntimeException("Unexpected event " + e);
 219.188 +        }
 219.189 +
 219.190 +        int[] arr = BUTTON_EVENTS_SEQUENCE[eventCount];
 219.191 +
 219.192 +        if (arr[0] != eventType) {
 219.193 +            throw new RuntimeException("Unexpected eventType " + eventType + "on step " + eventCount);
 219.194 +        }
 219.195 +
 219.196 +        boolean result;
 219.197 +
 219.198 +        switch (arr[1]) {
 219.199 +            case 1:
 219.200 +                result = SwingUtilities.isLeftMouseButton(e);
 219.201 +
 219.202 +                break;
 219.203 +
 219.204 +            case 2:
 219.205 +                result = SwingUtilities.isMiddleMouseButton(e);
 219.206 +
 219.207 +                break;
 219.208 +
 219.209 +            case 3:
 219.210 +                result = SwingUtilities.isRightMouseButton(e);
 219.211 +
 219.212 +                break;
 219.213 +
 219.214 +            default:
 219.215 +                throw new RuntimeException("Incorrect arr[1] on step " + eventCount);
 219.216 +        }
 219.217 +
 219.218 +        if (!result) {
 219.219 +            throw new RuntimeException("Test failed on step " + eventCount);
 219.220 +        }
 219.221 +
 219.222 +        eventCount++;
 219.223 +    }
 219.224 +}
   220.1 --- a/test/sun/jvmstat/perfdata/PrologSanity/PrologSizeSanityCheck.java	Fri Sep 30 17:20:56 2011 -0700
   220.2 +++ b/test/sun/jvmstat/perfdata/PrologSanity/PrologSizeSanityCheck.java	Tue Oct 04 12:39:42 2011 -0700
   220.3 @@ -1,5 +1,5 @@
   220.4  /*
   220.5 - * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
   220.6 + * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
   220.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   220.8   *
   220.9   * This code is free software; you can redistribute it and/or modify it
  220.10 @@ -24,6 +24,7 @@
  220.11  /*
  220.12   * @test
  220.13   * @bug 4990825
  220.14 + * @run main/othervm -XX:+UsePerfData  PrologSizeSanityCheck
  220.15   * @summary prolog size and overflow sanity checks
  220.16   */
  220.17  
   221.1 --- a/test/sun/misc/JarIndex/metaInfFilenames/Basic.java	Fri Sep 30 17:20:56 2011 -0700
   221.2 +++ b/test/sun/misc/JarIndex/metaInfFilenames/Basic.java	Tue Oct 04 12:39:42 2011 -0700
   221.3 @@ -155,7 +155,7 @@
   221.4      static void compile(String... args) {
   221.5          debug("Running: javac " + Arrays.toString(args));
   221.6          com.sun.tools.javac.main.Main compiler = new com.sun.tools.javac.main.Main("javac");
   221.7 -        if (compiler.compile(args) != 0) {
   221.8 +        if (compiler.compile(args) != com.sun.tools.javac.main.Main.Result.OK) {
   221.9               throw new RuntimeException("javac failed: args=" + Arrays.toString(args));
  221.10          }
  221.11      }
   222.1 --- a/test/sun/tools/common/ApplicationSetup.sh	Fri Sep 30 17:20:56 2011 -0700
   222.2 +++ b/test/sun/tools/common/ApplicationSetup.sh	Tue Oct 04 12:39:42 2011 -0700
   222.3 @@ -1,7 +1,7 @@
   222.4  #!/bin/sh
   222.5  
   222.6  #
   222.7 -# Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
   222.8 +# Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
   222.9  # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  222.10  #
  222.11  # This code is free software; you can redistribute it and/or modify it
  222.12 @@ -43,7 +43,7 @@
  222.13  {
  222.14    appOutput="${TESTCLASSES}/Application.out"
  222.15  
  222.16 -  ${JAVA} -classpath "${TESTCLASSES}" "$@" > "$appOutput" 2>&1 &
  222.17 +  ${JAVA} -XX:+UsePerfData -classpath "${TESTCLASSES}" "$@" > "$appOutput" 2>&1 &
  222.18    appJavaPid="$!"
  222.19    appOtherPid=
  222.20    appPidList="$appJavaPid"
  222.21 @@ -131,7 +131,7 @@
  222.22  #
  222.23  stopApplication()
  222.24  {
  222.25 -  $JAVA -classpath "${TESTCLASSES}" ShutdownSimpleApplication $1
  222.26 +  $JAVA -XX:+UsePerfData -classpath "${TESTCLASSES}" ShutdownSimpleApplication $1
  222.27  }
  222.28  
  222.29  
   223.1 --- a/test/sun/tools/jinfo/Basic.sh	Fri Sep 30 17:20:56 2011 -0700
   223.2 +++ b/test/sun/tools/jinfo/Basic.sh	Tue Oct 04 12:39:42 2011 -0700
   223.3 @@ -1,7 +1,7 @@
   223.4  #!/bin/sh
   223.5  
   223.6  #
   223.7 -# Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
   223.8 +# Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
   223.9  # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  223.10  #
  223.11  # This code is free software; you can redistribute it and/or modify it
  223.12 @@ -46,39 +46,39 @@
  223.13  
  223.14  if [ $isWindows = false ]; then
  223.15      # -sysprops option
  223.16 -    ${JINFO} -sysprops $appJavaPid
  223.17 +    ${JINFO} -J-XX:+UsePerfData -sysprops $appJavaPid
  223.18      if [ $? != 0 ]; then failed=1; fi
  223.19  
  223.20      # -flags option
  223.21 -    ${JINFO} -flags $appJavaPid
  223.22 +    ${JINFO} -J-XX:+UsePerfData -flags $appJavaPid
  223.23      if [ $? != 0 ]; then failed=1; fi
  223.24  
  223.25      # no option
  223.26 -    ${JINFO} $appJavaPid
  223.27 +    ${JINFO} -J-XX:+UsePerfData $appJavaPid
  223.28      if [ $? != 0 ]; then failed=1; fi
  223.29  
  223.30  fi
  223.31  
  223.32  
  223.33  # -flag option
  223.34 -${JINFO} -flag +PrintGC $appJavaPid
  223.35 +${JINFO} -J-XX:+UsePerfData -flag +PrintGC $appJavaPid
  223.36  if [ $? != 0 ]; then failed=1; fi 
  223.37  
  223.38 -${JINFO} -flag -PrintGC $appJavaPid
  223.39 +${JINFO} -J-XX:+UsePerfData -flag -PrintGC $appJavaPid
  223.40  if [ $? != 0 ]; then failed=1; fi
  223.41  
  223.42 -${JINFO} -flag PrintGC $appJavaPid
  223.43 +${JINFO} -J-XX:+UsePerfData -flag PrintGC $appJavaPid
  223.44  if [ $? != 0 ]; then failed=1; fi
  223.45  
  223.46  if $isSolaris; then
  223.47  
  223.48 -    ${JINFO} -flag +ExtendedDTraceProbes $appJavaPid
  223.49 +    ${JINFO} -J-XX:+UsePerfData -flag +ExtendedDTraceProbes $appJavaPid
  223.50      if [ $? != 0 ]; then failed=1; fi
  223.51  
  223.52 -    ${JINFO} -flag -ExtendedDTraceProbes $appJavaPid
  223.53 +    ${JINFO} -J-XX:+UsePerfData -flag -ExtendedDTraceProbes $appJavaPid
  223.54      if [ $? != 0 ]; then failed=1; fi
  223.55  
  223.56 -    ${JINFO} -flag ExtendedDTraceProbes $appJavaPid
  223.57 +    ${JINFO} -J-XX:+UsePerfData -flag ExtendedDTraceProbes $appJavaPid
  223.58      if [ $? != 0 ]; then failed=1; fi
  223.59  
  223.60  fi
   224.1 --- a/test/sun/tools/jmap/Basic.sh	Fri Sep 30 17:20:56 2011 -0700
   224.2 +++ b/test/sun/tools/jmap/Basic.sh	Tue Oct 04 12:39:42 2011 -0700
   224.3 @@ -1,7 +1,7 @@
   224.4  #!/bin/sh
   224.5  
   224.6  #
   224.7 -# Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
   224.8 +# Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
   224.9  # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  224.10  #
  224.11  # This code is free software; you can redistribute it and/or modify it
  224.12 @@ -45,15 +45,15 @@
  224.13  failed=0
  224.14  
  224.15  # -histo[:live] option
  224.16 -${JMAP} -histo $appJavaPid
  224.17 +${JMAP} -J-XX:+UsePerfData -histo $appJavaPid
  224.18  if [ $? != 0 ]; then failed=1; fi
  224.19  
  224.20 -${JMAP} -histo:live $appJavaPid
  224.21 +${JMAP} -J-XX:+UsePerfData -histo:live $appJavaPid
  224.22  if [ $? != 0 ]; then failed=1; fi
  224.23  
  224.24  # -dump option
  224.25  DUMPFILE="java_pid${appJavaPid}.hprof"
  224.26 -${JMAP} -dump:format=b,file=${DUMPFILE} $appJavaPid
  224.27 +${JMAP} -J-XX:+UsePerfData -dump:format=b,file=${DUMPFILE} $appJavaPid
  224.28  if [ $? != 0 ]; then failed=1; fi
  224.29  
  224.30  # check that heap dump is parsable
  224.31 @@ -64,7 +64,7 @@
  224.32  rm ${DUMPFILE}
  224.33  
  224.34  # -dump:live option
  224.35 -${JMAP} -dump:live,format=b,file=${DUMPFILE} $appJavaPid
  224.36 +${JMAP} -J-XX:+UsePerfData -dump:live,format=b,file=${DUMPFILE} $appJavaPid
  224.37  if [ $? != 0 ]; then failed=1; fi
  224.38  
  224.39  # check that heap dump is parsable
   225.1 --- a/test/sun/tools/jps/jps-Defaults.sh	Fri Sep 30 17:20:56 2011 -0700
   225.2 +++ b/test/sun/tools/jps/jps-Defaults.sh	Tue Oct 04 12:39:42 2011 -0700
   225.3 @@ -1,5 +1,5 @@
   225.4  #
   225.5 -# Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
   225.6 +# Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
   225.7  # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   225.8  #
   225.9  # This code is free software; you can redistribute it and/or modify it
  225.10 @@ -33,4 +33,4 @@
  225.11  
  225.12  JPS="${TESTJAVA}/bin/jps"
  225.13  
  225.14 -${JPS} 2>&1 | awk -f ${TESTSRC}/jps_Output1.awk
  225.15 +${JPS} -J-XX:+UsePerfData 2>&1 | awk -f ${TESTSRC}/jps_Output1.awk
   226.1 --- a/test/sun/tools/jps/jps-V_2.sh	Fri Sep 30 17:20:56 2011 -0700
   226.2 +++ b/test/sun/tools/jps/jps-V_2.sh	Tue Oct 04 12:39:42 2011 -0700
   226.3 @@ -1,5 +1,5 @@
   226.4  #
   226.5 -# Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
   226.6 +# Copyright (c) 2004, 2011,Oracle and/or its affiliates. All rights reserved.
   226.7  # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   226.8  #
   226.9  # This code is free software; you can redistribute it and/or modify it
  226.10 @@ -33,4 +33,4 @@
  226.11  
  226.12  JPS="${TESTJAVA}/bin/jps"
  226.13  
  226.14 -${JPS} -J-XX:Flags=${TESTSRC}/vmflags -V | awk -f ${TESTSRC}/jps-V_Output2.awk
  226.15 +${JPS} -J-XX:+UsePerfData -J-XX:Flags=${TESTSRC}/vmflags -V | awk -f ${TESTSRC}/jps-V_Output2.awk
   227.1 --- a/test/sun/tools/jps/jps-Vm_2.sh	Fri Sep 30 17:20:56 2011 -0700
   227.2 +++ b/test/sun/tools/jps/jps-Vm_2.sh	Tue Oct 04 12:39:42 2011 -0700
   227.3 @@ -1,5 +1,5 @@
   227.4  #
   227.5 -# Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
   227.6 +# Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
   227.7  # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   227.8  #
   227.9  # This code is free software; you can redistribute it and/or modify it
  227.10 @@ -33,4 +33,4 @@
  227.11  
  227.12  JPS="${TESTJAVA}/bin/jps"
  227.13  
  227.14 -${JPS} -J-XX:Flags=${TESTSRC}/vmflags -Vm | awk -f ${TESTSRC}/jps-Vm_Output2.awk
  227.15 +${JPS} -J-XX:+UsePerfData -J-XX:Flags=${TESTSRC}/vmflags -Vm | awk -f ${TESTSRC}/jps-Vm_Output2.awk
   228.1 --- a/test/sun/tools/jps/jps-Vvm.sh	Fri Sep 30 17:20:56 2011 -0700
   228.2 +++ b/test/sun/tools/jps/jps-Vvm.sh	Tue Oct 04 12:39:42 2011 -0700
   228.3 @@ -1,5 +1,5 @@
   228.4  #
   228.5 -# Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
   228.6 +# Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
   228.7  # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   228.8  #
   228.9  # This code is free software; you can redistribute it and/or modify it
  228.10 @@ -33,4 +33,4 @@
  228.11  
  228.12  JPS="${TESTJAVA}/bin/jps"
  228.13  
  228.14 -${JPS} -J-XX:Flags=${TESTSRC}/vmflags -Vvm | awk -f ${TESTSRC}/jps-Vvm_Output1.awk
  228.15 +${JPS} -J-XX:+UsePerfData -J-XX:Flags=${TESTSRC}/vmflags -Vvm | awk -f ${TESTSRC}/jps-Vvm_Output1.awk
   229.1 --- a/test/sun/tools/jps/jps-Vvml.sh	Fri Sep 30 17:20:56 2011 -0700
   229.2 +++ b/test/sun/tools/jps/jps-Vvml.sh	Tue Oct 04 12:39:42 2011 -0700
   229.3 @@ -1,5 +1,5 @@
   229.4  #
   229.5 -# Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
   229.6 +# Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
   229.7  # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   229.8  #
   229.9  # This code is free software; you can redistribute it and/or modify it
  229.10 @@ -33,4 +33,4 @@
  229.11  
  229.12  JPS="${TESTJAVA}/bin/jps"
  229.13  
  229.14 -${JPS} -J-XX:Flags=${TESTSRC}/vmflags -Vvml | awk -f ${TESTSRC}/jps-Vvml_Output1.awk
  229.15 +${JPS} -J-XX:+UsePerfData -J-XX:Flags=${TESTSRC}/vmflags -Vvml | awk -f ${TESTSRC}/jps-Vvml_Output1.awk
   230.1 --- a/test/sun/tools/jps/jps-Vvml_2.sh	Fri Sep 30 17:20:56 2011 -0700
   230.2 +++ b/test/sun/tools/jps/jps-Vvml_2.sh	Tue Oct 04 12:39:42 2011 -0700
   230.3 @@ -1,5 +1,5 @@
   230.4  #
   230.5 -# Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
   230.6 +# Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
   230.7  # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   230.8  #
   230.9  # This code is free software; you can redistribute it and/or modify it
  230.10 @@ -47,6 +47,10 @@
  230.11  # any args to Sleeper.main() or any jvm flags or options, as we
  230.12  # need to inspect jps output for the no args condition.
  230.13  #
  230.14 +# Note: this test can not pass on a VM with UsePerfData disabled by default,
  230.15 +# and we can not set -XX:+UsePerfData as that invalidates the test premise of
  230.16 +# there being no jvm flags
  230.17 +
  230.18  ${JAVA} -cp ${TESTCLASSES} Sleeper &
  230.19  SLEEPER_PID=$!
  230.20  
   231.1 --- a/test/sun/tools/jps/jps-help.sh	Fri Sep 30 17:20:56 2011 -0700
   231.2 +++ b/test/sun/tools/jps/jps-help.sh	Tue Oct 04 12:39:42 2011 -0700
   231.3 @@ -1,5 +1,5 @@
   231.4  #
   231.5 -# Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
   231.6 +# Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
   231.7  # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   231.8  #
   231.9  # This code is free software; you can redistribute it and/or modify it
  231.10 @@ -33,7 +33,7 @@
  231.11  JPS="${TESTJAVA}/bin/jps"
  231.12  
  231.13  rm -f jps.out 2>/dev/null
  231.14 -${JPS} -? > jps.out 2>&1
  231.15 +${JPS} -J-XX:+UsePerfData -? > jps.out 2>&1
  231.16  
  231.17  diff -w jps.out ${TESTSRC}/usage.out
  231.18  if [ $? != 0 ]
  231.19 @@ -44,7 +44,7 @@
  231.20  fi
  231.21  
  231.22  rm -f jps.out 2>/dev/null
  231.23 -${JPS} -help > jps.out 2>&1
  231.24 +${JPS} -J-XX:+UsePerfData -help > jps.out 2>&1
  231.25  
  231.26  diff -w jps.out ${TESTSRC}/usage.out
  231.27  if [ $? != 0 ]
   232.1 --- a/test/sun/tools/jps/jps-l_1.sh	Fri Sep 30 17:20:56 2011 -0700
   232.2 +++ b/test/sun/tools/jps/jps-l_1.sh	Tue Oct 04 12:39:42 2011 -0700
   232.3 @@ -1,5 +1,5 @@
   232.4  #
   232.5 -# Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
   232.6 +# Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
   232.7  # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   232.8  #
   232.9  # This code is free software; you can redistribute it and/or modify it
  232.10 @@ -33,4 +33,4 @@
  232.11  
  232.12  JPS="${TESTJAVA}/bin/jps"
  232.13  
  232.14 -${JPS} -l 2>&1 | awk -f ${TESTSRC}/jps-l_Output1.awk
  232.15 +${JPS} -J-XX:+UsePerfData -l 2>&1 | awk -f ${TESTSRC}/jps-l_Output1.awk
   233.1 --- a/test/sun/tools/jps/jps-l_2.sh	Fri Sep 30 17:20:56 2011 -0700
   233.2 +++ b/test/sun/tools/jps/jps-l_2.sh	Tue Oct 04 12:39:42 2011 -0700
   233.3 @@ -1,5 +1,5 @@
   233.4  #
   233.5 -# Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
   233.6 +# Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
   233.7  # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   233.8  #
   233.9  # This code is free software; you can redistribute it and/or modify it
  233.10 @@ -33,4 +33,4 @@
  233.11  
  233.12  JPS="${TESTJAVA}/bin/jps"
  233.13  
  233.14 -${JPS} -l | awk -f ${TESTSRC}/jps-l_Output2.awk
  233.15 +${JPS} -J-XX:+UsePerfData -l | awk -f ${TESTSRC}/jps-l_Output2.awk
   234.1 --- a/test/sun/tools/jps/jps-lm.sh	Fri Sep 30 17:20:56 2011 -0700
   234.2 +++ b/test/sun/tools/jps/jps-lm.sh	Tue Oct 04 12:39:42 2011 -0700
   234.3 @@ -1,5 +1,5 @@
   234.4  #
   234.5 -# Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
   234.6 +# Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
   234.7  # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   234.8  #
   234.9  # This code is free software; you can redistribute it and/or modify it
  234.10 @@ -33,4 +33,4 @@
  234.11  
  234.12  JPS="${TESTJAVA}/bin/jps"
  234.13  
  234.14 -${JPS} -lm | awk -f ${TESTSRC}/jps-lm_Output1.awk
  234.15 +${JPS} -J-XX:+UsePerfData -lm | awk -f ${TESTSRC}/jps-lm_Output1.awk
   235.1 --- a/test/sun/tools/jps/jps-m.sh	Fri Sep 30 17:20:56 2011 -0700
   235.2 +++ b/test/sun/tools/jps/jps-m.sh	Tue Oct 04 12:39:42 2011 -0700
   235.3 @@ -1,5 +1,5 @@
   235.4  #
   235.5 -# Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
   235.6 +# Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
   235.7  # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   235.8  #
   235.9  # This code is free software; you can redistribute it and/or modify it
  235.10 @@ -33,4 +33,4 @@
  235.11  
  235.12  JPS="${TESTJAVA}/bin/jps"
  235.13  
  235.14 -${JPS} -m | awk -f ${TESTSRC}/jps-m_Output1.awk
  235.15 +${JPS} -J-XX:+UsePerfData -m | awk -f ${TESTSRC}/jps-m_Output1.awk
   236.1 --- a/test/sun/tools/jps/jps-m_2.sh	Fri Sep 30 17:20:56 2011 -0700
   236.2 +++ b/test/sun/tools/jps/jps-m_2.sh	Tue Oct 04 12:39:42 2011 -0700
   236.3 @@ -1,5 +1,5 @@
   236.4  #
   236.5 -# Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
   236.6 +# Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
   236.7  # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   236.8  #
   236.9  # This code is free software; you can redistribute it and/or modify it
  236.10 @@ -46,10 +46,10 @@
  236.11  # any args to Sleeper.main(), as we need to inspect jps output
  236.12  # for the no args condition.
  236.13  #
  236.14 -${JAVA} -cp ${TESTCLASSES} Sleeper &
  236.15 +${JAVA} -XX:+UsePerfData -cp ${TESTCLASSES} Sleeper &
  236.16  SLEEPER_PID=$!
  236.17  
  236.18 -${JPS} -m | awk -f ${TESTSRC}/jps-m_Output2.awk
  236.19 +${JPS} -J-XX:+UsePerfData -m | awk -f ${TESTSRC}/jps-m_Output2.awk
  236.20  RC=$?
  236.21  
  236.22  cleanup
   237.1 --- a/test/sun/tools/jps/jps-q.sh	Fri Sep 30 17:20:56 2011 -0700
   237.2 +++ b/test/sun/tools/jps/jps-q.sh	Tue Oct 04 12:39:42 2011 -0700
   237.3 @@ -1,5 +1,5 @@
   237.4  #
   237.5 -# Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
   237.6 +# Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
   237.7  # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   237.8  #
   237.9  # This code is free software; you can redistribute it and/or modify it
  237.10 @@ -33,4 +33,4 @@
  237.11  
  237.12  JPS="${TESTJAVA}/bin/jps"
  237.13  
  237.14 -${JPS} -q | awk -f ${TESTSRC}/jps-q_Output1.awk
  237.15 +${JPS} -J-XX:+UsePerfData -q | awk -f ${TESTSRC}/jps-q_Output1.awk
   238.1 --- a/test/sun/tools/jps/jps-v_1.sh	Fri Sep 30 17:20:56 2011 -0700
   238.2 +++ b/test/sun/tools/jps/jps-v_1.sh	Tue Oct 04 12:39:42 2011 -0700
   238.3 @@ -1,5 +1,5 @@
   238.4  #
   238.5 -# Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
   238.6 +# Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
   238.7  # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   238.8  #
   238.9  # This code is free software; you can redistribute it and/or modify it
  238.10 @@ -33,4 +33,4 @@
  238.11  
  238.12  JPS="${TESTJAVA}/bin/jps"
  238.13  
  238.14 -${JPS} -J-XX:+UseParallelGC -v | awk -f ${TESTSRC}/jps-v_Output1.awk
  238.15 +${JPS} -J-XX:+UsePerfData -J-XX:+UseParallelGC -v | awk -f ${TESTSRC}/jps-v_Output1.awk
   239.1 --- a/test/sun/tools/jps/jps-vm_1.sh	Fri Sep 30 17:20:56 2011 -0700
   239.2 +++ b/test/sun/tools/jps/jps-vm_1.sh	Tue Oct 04 12:39:42 2011 -0700
   239.3 @@ -1,5 +1,5 @@
   239.4  #
   239.5 -# Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
   239.6 +# Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
   239.7  # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   239.8  #
   239.9  # This code is free software; you can redistribute it and/or modify it
  239.10 @@ -33,4 +33,4 @@
  239.11  
  239.12  JPS="${TESTJAVA}/bin/jps"
  239.13  
  239.14 -${JPS} -J-XX:+UseParallelGC -vm | awk -f ${TESTSRC}/jps-vm_Output1.awk
  239.15 +${JPS} -J-XX:+UsePerfData -J-XX:+UseParallelGC -vm | awk -f ${TESTSRC}/jps-vm_Output1.awk
   240.1 --- a/test/sun/tools/jstack/Basic.sh	Fri Sep 30 17:20:56 2011 -0700
   240.2 +++ b/test/sun/tools/jstack/Basic.sh	Tue Oct 04 12:39:42 2011 -0700
   240.3 @@ -1,7 +1,7 @@
   240.4  #!/bin/sh
   240.5  
   240.6  #
   240.7 -# Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
   240.8 +# Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
   240.9  # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  240.10  #
  240.11  # This code is free software; you can redistribute it and/or modify it
  240.12 @@ -45,11 +45,11 @@
  240.13  failed=0
  240.14  
  240.15  # normal
  240.16 -$JSTACK $appJavaPid 2>&1
  240.17 +$JSTACK -J-XX:+UsePerfData $appJavaPid 2>&1
  240.18  if [ $? != 0 ]; then failed=1; fi
  240.19  
  240.20  # long
  240.21 -$JSTACK -l $appJavaPid 2>&1
  240.22 +$JSTACK -J-XX:+UsePerfData -l $appJavaPid 2>&1
  240.23  if [ $? != 0 ]; then failed=1; fi
  240.24  
  240.25  set -e
   241.1 --- a/test/sun/tools/jstat/jstatClassOutput1.sh	Fri Sep 30 17:20:56 2011 -0700
   241.2 +++ b/test/sun/tools/jstat/jstatClassOutput1.sh	Tue Oct 04 12:39:42 2011 -0700
   241.3 @@ -1,5 +1,5 @@
   241.4  #
   241.5 -# Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
   241.6 +# Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
   241.7  # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   241.8  #
   241.9  # This code is free software; you can redistribute it and/or modify it
  241.10 @@ -33,4 +33,4 @@
  241.11  
  241.12  JSTAT="${TESTJAVA}/bin/jstat"
  241.13  
  241.14 -${JSTAT} -class 0 2>&1 | awk -f ${TESTSRC}/classOutput1.awk
  241.15 +${JSTAT} -J-XX:+UsePerfData -class 0 2>&1 | awk -f ${TESTSRC}/classOutput1.awk
   242.1 --- a/test/sun/tools/jstat/jstatClassloadOutput1.sh	Fri Sep 30 17:20:56 2011 -0700
   242.2 +++ b/test/sun/tools/jstat/jstatClassloadOutput1.sh	Tue Oct 04 12:39:42 2011 -0700
   242.3 @@ -1,5 +1,5 @@
   242.4  #
   242.5 -# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
   242.6 +# Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
   242.7  # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   242.8  #
   242.9  # This code is free software; you can redistribute it and/or modify it
  242.10 @@ -33,4 +33,4 @@
  242.11  
  242.12  JSTAT="${TESTJAVA}/bin/jstat"
  242.13  
  242.14 -${JSTAT} -classload -J-Djstat.showUnsupported=true 0 2>&1 | awk -f ${TESTSRC}/classloadOutput1.awk
  242.15 +${JSTAT} -J-XX:+UsePerfData -classload -J-Djstat.showUnsupported=true 0 2>&1 | awk -f ${TESTSRC}/classloadOutput1.awk
   243.1 --- a/test/sun/tools/jstat/jstatCompilerOutput1.sh	Fri Sep 30 17:20:56 2011 -0700
   243.2 +++ b/test/sun/tools/jstat/jstatCompilerOutput1.sh	Tue Oct 04 12:39:42 2011 -0700
   243.3 @@ -1,5 +1,5 @@
   243.4  #
   243.5 -# Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
   243.6 +# Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
   243.7  # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   243.8  #
   243.9  # This code is free software; you can redistribute it and/or modify it
  243.10 @@ -33,4 +33,4 @@
  243.11  
  243.12  JSTAT="${TESTJAVA}/bin/jstat"
  243.13  
  243.14 -${JSTAT} -compiler 0 2>&1 | awk -f ${TESTSRC}/compilerOutput1.awk
  243.15 +${JSTAT} -J-XX:+UsePerfData -compiler 0 2>&1 | awk -f ${TESTSRC}/compilerOutput1.awk
   244.1 --- a/test/sun/tools/jstat/jstatFileURITest1.sh	Fri Sep 30 17:20:56 2011 -0700
   244.2 +++ b/test/sun/tools/jstat/jstatFileURITest1.sh	Tue Oct 04 12:39:42 2011 -0700
   244.3 @@ -1,5 +1,5 @@
   244.4  #
   244.5 -# Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
   244.6 +# Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
   244.7  # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   244.8  #
   244.9  # This code is free software; you can redistribute it and/or modify it
  244.10 @@ -40,12 +40,12 @@
  244.11      # characters into forward slash characters in an effort to convert
  244.12      # TESTSRC into a canonical form useable as URI path.
  244.13      cp ${TESTSRC}/hsperfdata_3433 .
  244.14 -    ${JSTAT} -gcutil file:/`pwd`/hsperfdata_3433 2>&1 | awk -f ${TESTSRC}/fileURITest1.awk
  244.15 +    ${JSTAT} -J-XX:+UsePerfData -gcutil file:/`pwd`/hsperfdata_3433 2>&1 | awk -f ${TESTSRC}/fileURITest1.awk
  244.16      RC=$?
  244.17      rm -f hsperfdata_3433 2>&1 > /dev/null
  244.18      ;;
  244.19  *)
  244.20 -    ${JSTAT} -gcutil file:${TESTSRC}/hsperfdata_3433 2>&1 | awk -f ${TESTSRC}/fileURITest1.awk
  244.21 +    ${JSTAT} -J-XX:+UsePerfData -gcutil file:${TESTSRC}/hsperfdata_3433 2>&1 | awk -f ${TESTSRC}/fileURITest1.awk
  244.22      RC=$?
  244.23      ;;
  244.24  esac
   245.1 --- a/test/sun/tools/jstat/jstatGcCapacityOutput1.sh	Fri Sep 30 17:20:56 2011 -0700
   245.2 +++ b/test/sun/tools/jstat/jstatGcCapacityOutput1.sh	Tue Oct 04 12:39:42 2011 -0700
   245.3 @@ -1,5 +1,5 @@
   245.4  #
   245.5 -# Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
   245.6 +# Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
   245.7  # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   245.8  #
   245.9  # This code is free software; you can redistribute it and/or modify it
  245.10 @@ -33,4 +33,4 @@
  245.11  
  245.12  JSTAT="${TESTJAVA}/bin/jstat"
  245.13  
  245.14 -${JSTAT} -gccapacity 0 2>&1 | awk -f ${TESTSRC}/gcCapacityOutput1.awk
  245.15 +${JSTAT} -J-XX:+UsePerfData -gccapacity 0 2>&1 | awk -f ${TESTSRC}/gcCapacityOutput1.awk
   246.1 --- a/test/sun/tools/jstat/jstatGcCauseOutput1.sh	Fri Sep 30 17:20:56 2011 -0700
   246.2 +++ b/test/sun/tools/jstat/jstatGcCauseOutput1.sh	Tue Oct 04 12:39:42 2011 -0700
   246.3 @@ -1,5 +1,5 @@
   246.4  #
   246.5 -# Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
   246.6 +# Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
   246.7  # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   246.8  #
   246.9  # This code is free software; you can redistribute it and/or modify it
  246.10 @@ -37,4 +37,4 @@
  246.11  # class machine, ergonomics will automatically use UseParallelGC.
  246.12  # The UseParallelGC collector does not currently update the gc cause counters.
  246.13  
  246.14 -${JSTAT} -J-XX:+UseSerialGC -gccause 0 2>&1 | awk -f ${TESTSRC}/gcCauseOutput1.awk
  246.15 +${JSTAT} -J-XX:+UsePerfData -J-XX:+UseSerialGC -gccause 0 2>&1 | awk -f ${TESTSRC}/gcCauseOutput1.awk
   247.1 --- a/test/sun/tools/jstat/jstatGcNewCapacityOutput1.sh	Fri Sep 30 17:20:56 2011 -0700
   247.2 +++ b/test/sun/tools/jstat/jstatGcNewCapacityOutput1.sh	Tue Oct 04 12:39:42 2011 -0700
   247.3 @@ -1,5 +1,5 @@
   247.4  #
   247.5 -# Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
   247.6 +# Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
   247.7  # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   247.8  #
   247.9  # This code is free software; you can redistribute it and/or modify it
  247.10 @@ -33,4 +33,4 @@
  247.11  
  247.12  JSTAT="${TESTJAVA}/bin/jstat"
  247.13  
  247.14 -${JSTAT} -gcnewcapacity 0 2>&1 | awk -f ${TESTSRC}/gcNewCapacityOutput1.awk
  247.15 +${JSTAT} -J-XX:+UsePerfData -gcnewcapacity 0 2>&1 | awk -f ${TESTSRC}/gcNewCapacityOutput1.awk
   248.1 --- a/test/sun/tools/jstat/jstatGcNewOutput1.sh	Fri Sep 30 17:20:56 2011 -0700
   248.2 +++ b/test/sun/tools/jstat/jstatGcNewOutput1.sh	Tue Oct 04 12:39:42 2011 -0700
   248.3 @@ -1,5 +1,5 @@
   248.4  #
   248.5 -# Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
   248.6 +# Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
   248.7  # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   248.8  #
   248.9  # This code is free software; you can redistribute it and/or modify it
  248.10 @@ -33,4 +33,4 @@
  248.11  
  248.12  JSTAT="${TESTJAVA}/bin/jstat"
  248.13  
  248.14 -${JSTAT} -gcnew 0 2>&1 | awk -f ${TESTSRC}/gcNewOutput1.awk
  248.15 +${JSTAT} -J-XX:+UsePerfData -gcnew 0 2>&1 | awk -f ${TESTSRC}/gcNewOutput1.awk
   249.1 --- a/test/sun/tools/jstat/jstatGcOldCapacityOutput1.sh	Fri Sep 30 17:20:56 2011 -0700
   249.2 +++ b/test/sun/tools/jstat/jstatGcOldCapacityOutput1.sh	Tue Oct 04 12:39:42 2011 -0700
   249.3 @@ -1,5 +1,5 @@
   249.4  #
   249.5 -# Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
   249.6 +# Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
   249.7  # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   249.8  #
   249.9  # This code is free software; you can redistribute it and/or modify it
  249.10 @@ -33,4 +33,4 @@
  249.11  
  249.12  JSTAT="${TESTJAVA}/bin/jstat"
  249.13  
  249.14 -${JSTAT} -gcoldcapacity 0 2>&1 | awk -f ${TESTSRC}/gcOldCapacityOutput1.awk
  249.15 +${JSTAT} -J-XX:+UsePerfData -gcoldcapacity 0 2>&1 | awk -f ${TESTSRC}/gcOldCapacityOutput1.awk
   250.1 --- a/test/sun/tools/jstat/jstatGcOldOutput1.sh	Fri Sep 30 17:20:56 2011 -0700
   250.2 +++ b/test/sun/tools/jstat/jstatGcOldOutput1.sh	Tue Oct 04 12:39:42 2011 -0700
   250.3 @@ -1,5 +1,5 @@
   250.4  #
   250.5 -# Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
   250.6 +# Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
   250.7  # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   250.8  #
   250.9  # This code is free software; you can redistribute it and/or modify it
  250.10 @@ -33,4 +33,4 @@
  250.11  
  250.12  JSTAT="${TESTJAVA}/bin/jstat"
  250.13  
  250.14 -${JSTAT} -gcold 0 2>&1 | awk -f ${TESTSRC}/gcOldOutput1.awk
  250.15 +${JSTAT} -J-XX:+UsePerfData -gcold 0 2>&1 | awk -f ${TESTSRC}/gcOldOutput1.awk
   251.1 --- a/test/sun/tools/jstat/jstatGcOutput1.sh	Fri Sep 30 17:20:56 2011 -0700
   251.2 +++ b/test/sun/tools/jstat/jstatGcOutput1.sh	Tue Oct 04 12:39:42 2011 -0700
   251.3 @@ -1,5 +1,5 @@
   251.4  #
   251.5 -# Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
   251.6 +# Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
   251.7  # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   251.8  #
   251.9  # This code is free software; you can redistribute it and/or modify it
  251.10 @@ -33,4 +33,4 @@
  251.11  
  251.12  JSTAT="${TESTJAVA}/bin/jstat"
  251.13  
  251.14 -${JSTAT} -gc 0 2>&1 | awk -f ${TESTSRC}/gcOutput1.awk
  251.15 +${JSTAT} -J-XX:+UsePerfData -gc 0 2>&1 | awk -f ${TESTSRC}/gcOutput1.awk
   252.1 --- a/test/sun/tools/jstat/jstatGcPermCapacityOutput1.sh	Fri Sep 30 17:20:56 2011 -0700
   252.2 +++ b/test/sun/tools/jstat/jstatGcPermCapacityOutput1.sh	Tue Oct 04 12:39:42 2011 -0700
   252.3 @@ -1,5 +1,5 @@
   252.4  #
   252.5 -# Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
   252.6 +# Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
   252.7  # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   252.8  #
   252.9  # This code is free software; you can redistribute it and/or modify it
  252.10 @@ -33,4 +33,4 @@
  252.11  
  252.12  JSTAT="${TESTJAVA}/bin/jstat"
  252.13  
  252.14 -${JSTAT} -gcpermcapacity 0 2>&1 | awk -f ${TESTSRC}/gcPermCapacityOutput1.awk
  252.15 +${JSTAT} -J-XX:+UsePerfData -gcpermcapacity 0 2>&1 | awk -f ${TESTSRC}/gcPermCapacityOutput1.awk
   253.1 --- a/test/sun/tools/jstat/jstatHelp.sh	Fri Sep 30 17:20:56 2011 -0700
   253.2 +++ b/test/sun/tools/jstat/jstatHelp.sh	Tue Oct 04 12:39:42 2011 -0700
   253.3 @@ -1,5 +1,5 @@
   253.4  #
   253.5 -# Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
   253.6 +# Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
   253.7  # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   253.8  #
   253.9  # This code is free software; you can redistribute it and/or modify it
  253.10 @@ -33,7 +33,7 @@
  253.11  JSTAT="${TESTJAVA}/bin/jstat"
  253.12  
  253.13  rm -f jstat.out 2>/dev/null
  253.14 -${JSTAT} -? > jstat.out 2>&1
  253.15 +${JSTAT} -J-XX:+UsePerfData -? > jstat.out 2>&1
  253.16  
  253.17  diff -w jstat.out ${TESTSRC}/usage.out
  253.18  if [ $? != 0 ]
  253.19 @@ -43,7 +43,7 @@
  253.20  fi
  253.21  
  253.22  rm -f jstat.out 2>/dev/null
  253.23 -${JSTAT} -help > jstat.out 2>&1
  253.24 +${JSTAT} -J-XX:+UsePerfData -help > jstat.out 2>&1
  253.25  
  253.26  diff -w jstat.out ${TESTSRC}/usage.out
  253.27  if [ $? != 0 ]
   254.1 --- a/test/sun/tools/jstat/jstatLineCounts1.sh	Fri Sep 30 17:20:56 2011 -0700
   254.2 +++ b/test/sun/tools/jstat/jstatLineCounts1.sh	Tue Oct 04 12:39:42 2011 -0700
   254.3 @@ -1,5 +1,5 @@
   254.4  #
   254.5 -# Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
   254.6 +# Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
   254.7  # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   254.8  #
   254.9  # This code is free software; you can redistribute it and/or modify it
  254.10 @@ -33,4 +33,4 @@
  254.11  
  254.12  JSTAT="${TESTJAVA}/bin/jstat"
  254.13  
  254.14 -${JSTAT} -gcutil 0 250 5 2>&1 | awk -f ${TESTSRC}/lineCounts1.awk
  254.15 +${JSTAT} -J-XX:+UsePerfData -gcutil 0 250 5 2>&1 | awk -f ${TESTSRC}/lineCounts1.awk
   255.1 --- a/test/sun/tools/jstat/jstatLineCounts2.sh	Fri Sep 30 17:20:56 2011 -0700
   255.2 +++ b/test/sun/tools/jstat/jstatLineCounts2.sh	Tue Oct 04 12:39:42 2011 -0700
   255.3 @@ -1,5 +1,5 @@
   255.4  #
   255.5 -# Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
   255.6 +# Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
   255.7  # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   255.8  #
   255.9  # This code is free software; you can redistribute it and/or modify it
  255.10 @@ -33,4 +33,4 @@
  255.11  
  255.12  JSTAT="${TESTJAVA}/bin/jstat"
  255.13  
  255.14 -${JSTAT} -gcutil 0 2>&1 | awk -f ${TESTSRC}/lineCounts2.awk
  255.15 +${JSTAT} -J-XX:+UsePerfData -gcutil 0 2>&1 | awk -f ${TESTSRC}/lineCounts2.awk
   256.1 --- a/test/sun/tools/jstat/jstatLineCounts3.sh	Fri Sep 30 17:20:56 2011 -0700
   256.2 +++ b/test/sun/tools/jstat/jstatLineCounts3.sh	Tue Oct 04 12:39:42 2011 -0700
   256.3 @@ -1,5 +1,5 @@
   256.4  #
   256.5 -# Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
   256.6 +# Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
   256.7  # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   256.8  #
   256.9  # This code is free software; you can redistribute it and/or modify it
  256.10 @@ -33,4 +33,4 @@
  256.11  
  256.12  JSTAT="${TESTJAVA}/bin/jstat"
  256.13  
  256.14 -${JSTAT} -gcutil -h 10 0 250 10 2>&1 | awk -f ${TESTSRC}/lineCounts3.awk
  256.15 +${JSTAT} -J-XX:+UsePerfData -gcutil -h 10 0 250 10 2>&1 | awk -f ${TESTSRC}/lineCounts3.awk
   257.1 --- a/test/sun/tools/jstat/jstatLineCounts4.sh	Fri Sep 30 17:20:56 2011 -0700
   257.2 +++ b/test/sun/tools/jstat/jstatLineCounts4.sh	Tue Oct 04 12:39:42 2011 -0700
   257.3 @@ -1,5 +1,5 @@
   257.4  #
   257.5 -# Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
   257.6 +# Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
   257.7  # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   257.8  #
   257.9  # This code is free software; you can redistribute it and/or modify it
  257.10 @@ -33,4 +33,4 @@
  257.11  
  257.12  JSTAT="${TESTJAVA}/bin/jstat"
  257.13  
  257.14 -${JSTAT} -gcutil -h 10 0 250 11 2>&1 | awk -f ${TESTSRC}/lineCounts4.awk
  257.15 +${JSTAT} -J-XX:+UsePerfData -gcutil -h 10 0 250 11 2>&1 | awk -f ${TESTSRC}/lineCounts4.awk
   258.1 --- a/test/sun/tools/jstat/jstatOptions1.sh	Fri Sep 30 17:20:56 2011 -0700
   258.2 +++ b/test/sun/tools/jstat/jstatOptions1.sh	Tue Oct 04 12:39:42 2011 -0700
   258.3 @@ -1,5 +1,5 @@
   258.4  #
   258.5 -# Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
   258.6 +# Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
   258.7  # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   258.8  #
   258.9  # This code is free software; you can redistribute it and/or modify it
  258.10 @@ -33,8 +33,8 @@
  258.11  JSTAT="${TESTJAVA}/bin/jstat"
  258.12  
  258.13  rm -f jstat.out1 jstat.out2 2>/dev/null
  258.14 -${JSTAT} -options > jstat.out1 2>&1
  258.15 -${JSTAT} -options -J-Djstat.showUnsupported=true > jstat.out2 2>&1
  258.16 +${JSTAT} -J-XX:+UsePerfData -options > jstat.out1 2>&1
  258.17 +${JSTAT} -J-XX:+UsePerfData -options -J-Djstat.showUnsupported=true > jstat.out2 2>&1
  258.18  
  258.19  diff -w jstat.out1 ${TESTSRC}/options1.out
  258.20  diff -w jstat.out2 ${TESTSRC}/options2.out
   259.1 --- a/test/sun/tools/jstat/jstatPrintCompilationOutput1.sh	Fri Sep 30 17:20:56 2011 -0700
   259.2 +++ b/test/sun/tools/jstat/jstatPrintCompilationOutput1.sh	Tue Oct 04 12:39:42 2011 -0700
   259.3 @@ -1,5 +1,5 @@
   259.4  #
   259.5 -# Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
   259.6 +# Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
   259.7  # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   259.8  #
   259.9  # This code is free software; you can redistribute it and/or modify it
  259.10 @@ -35,4 +35,4 @@
  259.11  
  259.12  # run with -Xcomp as jstat may complete too quickly to assure
  259.13  # that compilation occurs.
  259.14 -${JSTAT} -J-Xcomp -printcompilation 0 2>&1 | awk -f ${TESTSRC}/printCompilationOutput1.awk
  259.15 +${JSTAT} -J-XX:+UsePerfData -J-Xcomp -printcompilation 0 2>&1 | awk -f ${TESTSRC}/printCompilationOutput1.awk
   260.1 --- a/test/sun/tools/jstat/jstatSnap1.sh	Fri Sep 30 17:20:56 2011 -0700
   260.2 +++ b/test/sun/tools/jstat/jstatSnap1.sh	Tue Oct 04 12:39:42 2011 -0700
   260.3 @@ -1,5 +1,5 @@
   260.4  #
   260.5 -# Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
   260.6 +# Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
   260.7  # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   260.8  #
   260.9  # This code is free software; you can redistribute it and/or modify it
  260.10 @@ -33,4 +33,4 @@
  260.11  
  260.12  JSTAT="${TESTJAVA}/bin/jstat"
  260.13  
  260.14 -${JSTAT} -snap 0 2>&1 | awk -f ${TESTSRC}/snap1.awk
  260.15 +${JSTAT} -J-XX:+UsePerfData -snap 0 2>&1 | awk -f ${TESTSRC}/snap1.awk
   261.1 --- a/test/sun/tools/jstat/jstatSnap2.sh	Fri Sep 30 17:20:56 2011 -0700
   261.2 +++ b/test/sun/tools/jstat/jstatSnap2.sh	Tue Oct 04 12:39:42 2011 -0700
   261.3 @@ -1,5 +1,5 @@
   261.4  #
   261.5 -# Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
   261.6 +# Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
   261.7  # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   261.8  #
   261.9  # This code is free software; you can redistribute it and/or modify it
  261.10 @@ -33,4 +33,4 @@
  261.11  
  261.12  JSTAT="${TESTJAVA}/bin/jstat"
  261.13  
  261.14 -${JSTAT} -J-Djstat.showUnsupported=true -snap 0 2>&1 | awk -f ${TESTSRC}/snap2.awk
  261.15 +${JSTAT} -J-XX:+UsePerfData -J-Djstat.showUnsupported=true -snap 0 2>&1 | awk -f ${TESTSRC}/snap2.awk
   262.1 --- a/test/sun/tools/jstat/jstatTimeStamp1.sh	Fri Sep 30 17:20:56 2011 -0700
   262.2 +++ b/test/sun/tools/jstat/jstatTimeStamp1.sh	Tue Oct 04 12:39:42 2011 -0700
   262.3 @@ -1,5 +1,5 @@
   262.4  #
   262.5 -# Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
   262.6 +# Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
   262.7  # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   262.8  #
   262.9  # This code is free software; you can redistribute it and/or modify it
  262.10 @@ -33,4 +33,4 @@
  262.11  
  262.12  JSTAT="${TESTJAVA}/bin/jstat"
  262.13  
  262.14 -${JSTAT} -gcutil -t 0 2>&1 | awk -f ${TESTSRC}/timeStamp1.awk
  262.15 +${JSTAT} -J-XX:+UsePerfData -gcutil -t 0 2>&1 | awk -f ${TESTSRC}/timeStamp1.awk
   263.1 --- a/test/sun/tools/jstatd/jstatdDefaults.sh	Fri Sep 30 17:20:56 2011 -0700
   263.2 +++ b/test/sun/tools/jstatd/jstatdDefaults.sh	Tue Oct 04 12:39:42 2011 -0700
   263.3 @@ -1,5 +1,5 @@
   263.4  #
   263.5 -# Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
   263.6 +# Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
   263.7  # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   263.8  #
   263.9  # This code is free software; you can redistribute it and/or modify it
  263.10 @@ -45,13 +45,13 @@
  263.11  
  263.12  JSTATD_OUT="jstatd_$$.out"
  263.13  
  263.14 -${JSTATD} -J-Djava.security.policy=${TESTSRC}/all.policy 2>&1 > ${JSTATD_OUT} &
  263.15 +${JSTATD} -J-XX:+UsePerfData -J-Djava.security.policy=${TESTSRC}/all.policy 2>&1 > ${JSTATD_OUT} &
  263.16  JSTATD_PID=$!
  263.17  
  263.18  echo "jstatd started as pid ${JSTATD_PID}"
  263.19  sleep 3
  263.20  
  263.21 -${JPS} ${HOSTNAME} 2>&1 | awk -f ${TESTSRC}/jpsOutput1.awk
  263.22 +${JPS} -J-XX:+UsePerfData ${HOSTNAME} 2>&1 | awk -f ${TESTSRC}/jpsOutput1.awk
  263.23  
  263.24  if [ $? -ne 0 ]
  263.25  then
  263.26 @@ -60,7 +60,7 @@
  263.27      exit 1
  263.28  fi
  263.29  
  263.30 -${JSTAT} -gcutil ${JSTATD_PID}@${HOSTNAME} 250 5 2>&1 | awk -f ${TESTSRC}/jstatGcutilOutput1.awk
  263.31 +${JSTAT} -J-XX:+UsePerfData -gcutil ${JSTATD_PID}@${HOSTNAME} 250 5 2>&1 | awk -f ${TESTSRC}/jstatGcutilOutput1.awk
  263.32  RC=$?
  263.33  
  263.34  if [ ${RC} -ne 0 ]
   264.1 --- a/test/sun/tools/jstatd/jstatdExternalRegistry.sh	Fri Sep 30 17:20:56 2011 -0700
   264.2 +++ b/test/sun/tools/jstatd/jstatdExternalRegistry.sh	Tue Oct 04 12:39:42 2011 -0700
   264.3 @@ -1,5 +1,5 @@
   264.4  #
   264.5 -# Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
   264.6 +# Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
   264.7  # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   264.8  #
   264.9  # This code is free software; you can redistribute it and/or modify it
  264.10 @@ -53,19 +53,19 @@
  264.11  RMIREGISTRY_OUT="rmiregistry_$$.out"
  264.12  JSTATD_OUT="jstatd_$$.out"
  264.13  
  264.14 -${RMIREGISTRY} ${PORT} > ${RMIREGISTRY_OUT} 2>&1 &
  264.15 +${RMIREGISTRY} -J-XX:+UsePerfData ${PORT} > ${RMIREGISTRY_OUT} 2>&1 &
  264.16  RMIREGISTRY_PID=$!
  264.17  
  264.18  echo "rmiregistry started on port ${PORT} as pid ${RMIREGISTRY_PID}"
  264.19  sleep 3
  264.20  
  264.21 -${JSTATD} -J-Djava.security.policy=${TESTSRC}/all.policy -p ${PORT} > ${JSTATD_OUT} 2>&1 &
  264.22 +${JSTATD} -J-XX:+UsePerfData -J-Djava.security.policy=${TESTSRC}/all.policy -p ${PORT} > ${JSTATD_OUT} 2>&1 &
  264.23  JSTATD_PID=$!
  264.24  
  264.25  echo "jstatd started as pid ${JSTATD_PID}"
  264.26  sleep 3
  264.27  
  264.28 -${JPS} ${HOSTNAME}:${PORT} 2>&1 | awk -f ${TESTSRC}/jpsOutput1.awk
  264.29 +${JPS} -J-XX:+UsePerfData ${HOSTNAME}:${PORT} 2>&1 | awk -f ${TESTSRC}/jpsOutput1.awk
  264.30  
  264.31  if [ $? -ne 0 ]
  264.32  then
  264.33 @@ -73,7 +73,7 @@
  264.34      exit 1
  264.35  fi
  264.36  
  264.37 -${JSTAT} -gcutil ${JSTATD_PID}@${HOSTNAME}:${PORT} 250 5 2>&1 | awk -f ${TESTSRC}/jstatGcutilOutput1.awk
  264.38 +${JSTAT} -J-XX:+UsePerfData -gcutil ${JSTATD_PID}@${HOSTNAME}:${PORT} 250 5 2>&1 | awk -f ${TESTSRC}/jstatGcutilOutput1.awk
  264.39  RC=$?
  264.40  
  264.41  if [ ${RC} -ne 0 ]
   265.1 --- a/test/sun/tools/jstatd/jstatdPort.sh	Fri Sep 30 17:20:56 2011 -0700
   265.2 +++ b/test/sun/tools/jstatd/jstatdPort.sh	Tue Oct 04 12:39:42 2011 -0700
   265.3 @@ -1,5 +1,5 @@
   265.4  #
   265.5 -# Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
   265.6 +# Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
   265.7  # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   265.8  #
   265.9  # This code is free software; you can redistribute it and/or modify it
  265.10 @@ -50,13 +50,13 @@
  265.11  
  265.12  JSTATD_OUT="jstatd_$$.out"
  265.13  
  265.14 -${JSTATD} -J-Djava.security.policy=${TESTSRC}/all.policy -p ${PORT} 2>&1 > ${JSTATD_OUT} &
  265.15 +${JSTATD} -J-XX:+UsePerfData -J-Djava.security.policy=${TESTSRC}/all.policy -p ${PORT} 2>&1 > ${JSTATD_OUT} &
  265.16  JSTATD_PID=$!
  265.17  
  265.18  echo "jstatd started as pid ${JSTATD_PID} on port ${PORT}"
  265.19  sleep 3
  265.20  
  265.21 -${JPS} ${HOSTNAME}:${PORT} 2>&1 | awk -f ${TESTSRC}/jpsOutput1.awk
  265.22 +${JPS} -J-XX:+UsePerfData ${HOSTNAME}:${PORT} 2>&1 | tee jps.out | awk -f ${TESTSRC}/jpsOutput1.awk
  265.23  
  265.24  if [ $? -ne 0 ]
  265.25  then
  265.26 @@ -65,7 +65,7 @@
  265.27      exit 1
  265.28  fi
  265.29  
  265.30 -${JSTAT} -gcutil ${JSTATD_PID}@${HOSTNAME}:${PORT} 250 5 2>&1 | awk -f ${TESTSRC}/jstatGcutilOutput1.awk
  265.31 +${JSTAT} -J-XX:+UsePerfData -gcutil ${JSTATD_PID}@${HOSTNAME}:${PORT} 250 5 2>&1 | awk -f ${TESTSRC}/jstatGcutilOutput1.awk
  265.32  RC=$?
  265.33  
  265.34  if [ ${RC} -ne 0 ]
   266.1 --- a/test/sun/tools/jstatd/jstatdServerName.sh	Fri Sep 30 17:20:56 2011 -0700
   266.2 +++ b/test/sun/tools/jstatd/jstatdServerName.sh	Tue Oct 04 12:39:42 2011 -0700
   266.3 @@ -1,5 +1,5 @@
   266.4  #
   266.5 -# Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
   266.6 +# Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
   266.7  # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   266.8  #
   266.9  # This code is free software; you can redistribute it and/or modify it
  266.10 @@ -54,20 +54,20 @@
  266.11  JSTATD_1_OUT="jstatd_$$_1.out"
  266.12  JSTATD_2_OUT="jstatd_$$_2.out"
  266.13  
  266.14 -${JSTATD} -J-Djava.security.policy=${TESTSRC}/all.policy -p ${PORT_1} 2>&1 > ${JSTATD_1_OUT} &
  266.15 +${JSTATD} -J-XX:+UsePerfData -J-Djava.security.policy=${TESTSRC}/all.policy -p ${PORT_1} 2>&1 > ${JSTATD_1_OUT} &
  266.16  JSTATD_1_PID=$!
  266.17  
  266.18  echo "first jstatd started as pid ${JSTATD_1_PID} on port ${PORT_1} with default server name"
  266.19  sleep 3
  266.20  
  266.21 -${JSTATD} -J-Djava.security.policy=${TESTSRC}/all.policy -p ${PORT_2} -n ${SERVERNAME} 2>&1 > ${JSTATD_2_OUT} &
  266.22 +${JSTATD} -J-XX:+UsePerfData -J-Djava.security.policy=${TESTSRC}/all.policy -p ${PORT_2} -n ${SERVERNAME} 2>&1 > ${JSTATD_2_OUT} &
  266.23  JSTATD_2_PID=$!
  266.24  
  266.25  echo "second jstatd started as pid ${JSTATD_2_PID} on port ${PORT_2} with name ${SERVERNAME}"
  266.26  sleep 3
  266.27  
  266.28 -echo "running: ${JPS} ${HOSTNAME}:${PORT_1}"
  266.29 -${JPS} ${HOSTNAME}:${PORT_1} 2>&1 | awk -f ${TESTSRC}/jpsOutput1.awk
  266.30 +echo "running: ${JPS} -J-XX:+UsePerfData ${HOSTNAME}:${PORT_1}"
  266.31 +${JPS} -J-XX:+UsePerfData ${HOSTNAME}:${PORT_1} 2>&1 | awk -f ${TESTSRC}/jpsOutput1.awk
  266.32  
  266.33  if [ $? -ne 0 ]
  266.34  then
  266.35 @@ -76,8 +76,8 @@
  266.36      exit 1
  266.37  fi
  266.38  
  266.39 -echo "running: ${JPS} ${HOSTNAME}:${PORT_2}/${SERVERNAME}"
  266.40 -${JPS} ${HOSTNAME}:${PORT_2}/${SERVERNAME} 2>&1 | awk -f ${TESTSRC}/jpsOutput1.awk
  266.41 +echo "running: ${JPS} -J-XX:+UsePerfData ${HOSTNAME}:${PORT_2}/${SERVERNAME}"
  266.42 +${JPS} -J-XX:+UsePerfData ${HOSTNAME}:${PORT_2}/${SERVERNAME} 2>&1 | awk -f ${TESTSRC}/jpsOutput1.awk
  266.43  
  266.44  if [ $? -ne 0 ]
  266.45  then
  266.46 @@ -86,8 +86,8 @@
  266.47      exit 1
  266.48  fi
  266.49  
  266.50 -echo "running: ${JSTAT} -gcutil ${JSTATD_1_PID}@${HOSTNAME}:${PORT_1} 250 5"
  266.51 -${JSTAT} -gcutil ${JSTATD_1_PID}@${HOSTNAME}:${PORT_1} 250 5 2>&1 | awk -f ${TESTSRC}/jstatGcutilOutput1.awk
  266.52 +echo "running: ${JSTAT} -J-XX:+UsePerfData -gcutil ${JSTATD_1_PID}@${HOSTNAME}:${PORT_1} 250 5"
  266.53 +${JSTAT} -J-XX:+UsePerfData -gcutil ${JSTATD_1_PID}@${HOSTNAME}:${PORT_1} 250 5 2>&1 | awk -f ${TESTSRC}/jstatGcutilOutput1.awk
  266.54  RC=$?
  266.55  
  266.56  if [ ${RC} -ne 0 ]
  266.57 @@ -95,8 +95,8 @@
  266.58      echo "jstat output differs from expected output"
  266.59  fi
  266.60  
  266.61 -echo "running: ${JSTAT} -gcutil ${JSTATD_1_PID}@${HOSTNAME}:${PORT_2}/${SERVERNAME} 250 5"
  266.62 -${JSTAT} -gcutil ${JSTATD_1_PID}@${HOSTNAME}:${PORT_2}/${SERVERNAME} 250 5 2>&1 | awk -f ${TESTSRC}/jstatGcutilOutput1.awk
  266.63 +echo "running: ${JSTAT} -J-XX:+UsePerfData -gcutil ${JSTATD_1_PID}@${HOSTNAME}:${PORT_2}/${SERVERNAME} 250 5"
  266.64 +${JSTAT} -J-XX:+UsePerfData -gcutil ${JSTATD_1_PID}@${HOSTNAME}:${PORT_2}/${SERVERNAME} 250 5 2>&1 | awk -f ${TESTSRC}/jstatGcutilOutput1.awk
  266.65  RC=$?
  266.66  
  266.67  if [ ${RC} -ne 0 ]