This commit is contained in:
tor%cs.brown.edu 2002-10-04 06:34:53 +00:00
Родитель ba14827b28
Коммит 2781ac8ac1
26 изменённых файлов: 3508 добавлений и 1341 удалений

Просмотреть файл

@ -78,7 +78,7 @@ _SUBDIR_CONFIG_ARGS="$ac_configure_args"
dnl Set the version number of the libs included with mozilla
dnl ========================================================
MOZJPEG=62
MOZPNG=10009
MOZPNG=10205
MOZMNG="((1<<16)|(0<<8)|(4))"
NSPR_VERSION=4

Просмотреть файл

@ -1,3 +1,4 @@
CHANGES - changes for libpng
version 0.2
@ -732,10 +733,11 @@ version 1.0.6j [May 3, 2000]
version 1.0.7beta11 [May 7, 2000]
Removed the new PNG_CREATED_READ_STRUCT and PNG_CREATED_WRITE_STRUCT modes
which are no longer used.
Eliminated the three new members of png_text when PNG_NO_iTXt_SUPPORTED
or PNG_LEGACY_SUPPORTED is defined.
Made PNG_NO_ITXT_SUPPORTED the default setting, to avoid memory overrun
when old applications fill the info_ptr->text structure directly.
Eliminated the three new members of png_text when PNG_LEGACY_SUPPORTED is
defined or when neither PNG_READ_iTXt_SUPPORTED nor PNG_WRITE_iTXT_SUPPORTED
is defined.
Made PNG_NO_READ|WRITE_iTXt the default setting, to avoid memory
overrun when old applications fill the info_ptr->text structure directly.
Added PNGAPI macro, and added it to the definitions of all exported functions.
Relocated version macro definitions ahead of the includes of zlib.h and
pngconf.h in png.h.
@ -893,6 +895,287 @@ version 1.0.9rc2 [January 22, 2001]
version 1.0.9 [January 31, 2001]
Added check of cygwin's ALL_STATIC in pngconf.h
Added "-nommx" parameter to contrib/gregbook/rpng2-win and rpng2-x demos.
version 1.0.10beta1 [March 14, 2001]
Revised makefile.dec, makefile.sgi, and makefile.sggcc; added makefile.hpgcc.
Reformatted libpng.3 to eliminate bad line breaks.
Added checks for _mmx_supported in the read_filter_row function of pnggccrd.c
Added prototype for png_mmx_support() near the top of pnggccrd.c
Moved some error checking from png_handle_IHDR to png_set_IHDR.
Added PNG_NO_READ_SUPPORTED and PNG_NO_WRITE_SUPPORTED macros.
Revised png_mmx_support() function in pnggccrd.c
Restored version 1.0.8 PNG_WRITE_EMPTY_PLTE_SUPPORTED behavior in pngwutil.c
Fixed memory leak in contrib/visupng/PngFile.c
Fixed bugs in png_combine_row() in pnggccrd.c and pngvcrd.c (C version)
Added warnings when retrieving or setting gamma=0.
Increased the first part of msg buffer from 16 to 18 in png_chunk_warning().
version 1.0.10rc1 [March 23, 2001]
Changed all instances of memcpy, strcpy, and strlen to png_memcpy, png_strcpy,
and png_strlen.
Revised png_mmx_supported() function in pnggccrd.c to return proper value.
Fixed bug in progressive reading (pngpread.c) with small images (height < 8).
version 1.0.10 [March 30, 2001]
Deleted extraneous space (introduced in 1.0.9) from line 42 of makefile.cygwin
Added beos project files (Chris Herborth)
version 1.0.11beta1 [April 3, 2001]
Added type casts on several png_malloc() calls (Dimitri Papadapoulos).
Removed a no-longer needed AIX work-around from pngconf.h
Changed several "//" single-line comments to C-style in pnggccrd.c
version 1.0.11beta2 [April 11, 2001]
Removed PNGAPI from several functions whose prototypes did not have PNGAPI.
Updated scripts/pngos2.def
version 1.0.11beta3 [April 14, 2001]
Added checking the results of many instances of png_malloc() for NULL
version 1.0.11beta4 [April 20, 2001]
Undid the changes from version 1.0.11beta3. Added a check for NULL return
from user's malloc_fn().
Removed some useless type casts of the NULL pointer.
Added makefile.netbsd
version 1.0.11 [April 27, 2001]
Revised makefile.netbsd
version 1.0.12beta1 [May 14, 2001]
Test for Windows platform in pngconf.h when including malloc.h (Emmanuel Blot)
Updated makefile.cygwin and handling of Cygwin's ALL_STATIC in pngconf.h
Added some never-to-be-executed code in pnggccrd.c to quiet compiler warnings.
Eliminated the png_error about apps using png_read|write_init(). Instead,
libpng will reallocate the png_struct and info_struct if they are too small.
This retains future binary compatibility for old applications written for
libpng-0.88 and earlier.
version 1.2.0beta1 [May 6, 2001]
Bumped DLLNUM to 2.
Re-enabled PNG_MNG_FEATURES_SUPPORTED and enabled PNG_ASSEMBLER_CODE_SUPPORTED
by default.
Added runtime selection of MMX features.
Added png_set_strip_error_numbers function and related macros.
version 1.2.0beta2 [May 7, 2001]
Finished merging 1.2.0beta1 with version 1.0.11
Added a check for attempts to read or write PLTE in grayscale PNG datastreams.
version 1.2.0beta3 [May 17, 2001]
Enabled user memory function by default.
Modified png_create_struct so it passes user mem_ptr to user memory allocator.
Increased png_mng_features flag from png_byte to png_uint_32.
Bumped shared-library (so-number) and dll-number to 3.
version 1.2.0beta4 [June 23, 2001]
Check for missing profile length field in iCCP chunk and free chunk_data
in case of truncated iCCP chunk.
Bumped shared-library number to 3 in makefile.sgi and makefile.sggcc
Bumped dll-number from 2 to 3 in makefile.cygwin
Revised contrib/gregbook/rpng*-x.c to avoid a memory leak and to exit cleanly
if user attempts to run it on an 8-bit display.
Updated contrib/gregbook
Use png_malloc instead of png_zalloc to allocate palette in pngset.c
Updated makefile.ibmc
Added some typecasts to eliminate gcc 3.0 warnings. Changed prototypes
of png_write_oFFS width and height from png_uint_32 to png_int_32.
Updated example.c
Revised prototypes for png_debug_malloc and png_debug_free in pngtest.c
version 1.2.0beta5 [August 8, 2001]
Revised contrib/gregbook
Revised makefile.gcmmx
Revised pnggccrd.c to conditionally compile some thread-unsafe code only
when PNG_THREAD_UNSAFE_OK is defined.
Added tests to prevent pngwutil.c from writing a bKGD or tRNS chunk with
value exceeding 2^bit_depth-1
Revised makefile.sgi and makefile.sggcc
Replaced calls to fprintf(stderr,...) with png_warning() in pnggccrd.c
Removed restriction that do_invert_mono only operate on 1-bit opaque files
version 1.2.0 [September 1, 2001]
Changed a png_warning() to png_debug() in pnggccrd.c
Fixed contrib/gregbook/rpng-x.c, rpng2-x.c to avoid crash with XFreeGC().
version 1.2.1beta1 [October 19, 2001]
Revised makefile.std in contrib/pngminus
Include background_1 in png_struct regardless of gamma support.
Revised makefile.netbsd and makefile.macosx, added makefile.darwin.
Revised example.c to provide more details about using row_callback().
version 1.2.1beta2 [October 25, 2001]
Added type cast to each NULL appearing in a function call, except for
WINCE functions.
Added makefile.so9.
version 1.2.1beta3 [October 27, 2001]
Removed type casts from all NULLs.
Simplified png_create_struct_2().
version 1.2.1beta4 [November 7, 2001]
Revised png_create_info_struct() and png_creat_struct_2().
Added error message if png_write_info() was omitted.
Type cast NULLs appearing in function calls when _NO_PROTO or
PNG_TYPECAST_NULL is defined.
version 1.2.1rc1 [November 24, 2001]
Type cast NULLs appearing in function calls except when PNG_NO_TYPECAST_NULL
is defined.
Changed typecast of "size" argument to png_size_t in pngmem.c calls to
the user malloc_fn, to agree with the prototype in png.h
Added a pop/push operation to pnggccrd.c, to preserve Eflag (Maxim Sobolev)
Updated makefile.sgi to recognize LIBPATH and INCPATH.
Updated various makefiles so "make clean" does not remove previous major
version of the shared library.
version 1.2.1rc2 [December 4, 2001]
Always allocate 256-entry internal palette, hist, and trans arrays, to
avoid out-of-bounds memory reference caused by invalid PNG datastreams.
Added a check for prefix_length > data_length in iCCP chunk handler.
version 1.2.1 [December 7, 2001]
None.
version 1.2.2beta1 [February 22, 2002]
Fixed a bug with reading the length of iCCP profiles (Larry Reeves).
Revised makefile.linux, makefile.gcmmx, and makefile.sgi to generate
libpng.a, libpng12.so (not libpng.so.3), and libpng12/png.h
Revised makefile.darwin to remove "-undefined suppress" option.
Added checks for gamma and chromaticity values over 21474.83, which exceed
the limit for PNG unsigned 32-bit integers when encoded.
Revised calls to png_create_read_struct() and png_create_write_struct()
for simpler debugging.
Revised png_zalloc() so zlib handles errors (uses PNG_FLAG_MALLOC_NULL_MEM_OK)
version 1.2.2beta2 [February 23, 2002]
Check chunk_length and idat_size for invalid (over PNG_MAX_UINT) lengths.
Check for invalid image dimensions in png_get_IHDR.
Added missing "fi;" in the install target of the SGI makefiles.
Added install-static to all makefiles that make shared libraries.
Always do gamma compensation when image is partially transparent.
version 1.2.2beta3 [March 7, 2002]
Compute background.gray and background_1.gray even when color_type is RGB
in case image gets reduced to gray later.
Modified shared-library makefiles to install pkgconfig/libpngNN.pc.
Export (with PNGAPI) png_zalloc, png_zfree, and png_handle_as_unknown
Removed unused png_write_destroy_info prototype from png.h
Eliminated incorrect use of width_mmx from pnggccrd.c in pixel_bytes == 8 case
Added install-shared target to all makefiles that make shared libraries.
Stopped a double free of palette, hist, and trans when not using free_me.
Added makefile.32sunu for Sun Ultra 32 and makefile.64sunu for Sun Ultra 64.
version 1.2.2beta4 [March 8, 2002]
Compute background.gray and background_1.gray even when color_type is RGB
in case image gets reduced to gray later (Jason Summers).
Relocated a misplaced /bin/rm in the "install-shared" makefile targets
Added PNG_1_0_X macro which can be used to build a 1.0.x-compatible library.
version 1.2.2beta5 [March 26, 2002]
Added missing PNGAPI to several function definitions.
Check for invalid bit_depth or color_type in png_get_IHDR(), and
check for missing PLTE or IHDR in png_push_read_chunk() (Matthias Clasen).
Revised iTXt support to accept NULL for lang and lang_key.
Compute gamma for color components of background even when color_type is gray.
Changed "()" to "{}" in scripts/libpng.pc.in.
Revised makefiles to put png.h and pngconf.h only in $prefix/include/libpngNN
Revised makefiles to make symlink to libpng.so.NN in addition to libpngNN.so
version 1.2.2beta6 [March 31, 2002]
version 1.0.13beta1 [March 31, 2002]
Prevent png_zalloc() from trying to memset memory that it failed to acquire.
Add typecasts of PNG_MAX_UINT in pngset_cHRM_fixed() (Matt Holgate).
Ensure that the right function (user or default) is used to free the
png_struct after an error in png_create_read_struct_2().
version 1.2.2rc1 [April 7, 2002]
version 1.0.13rc1 [April 7, 2002]
Save the ebx register in pnggccrd.c (Sami Farin)
Add "mem_ptr = png_ptr->mem_ptr" in png_destroy_write_struct() (Paul Gardner).
Updated makefiles to put headers in include/libpng and remove old include/*.h.
version 1.2.2 [April 15, 2002]
version 1.0.13 [April 15, 2002]
Revised description of png_set_filter() in libpng.3/libpng.txt.
Revised makefile.netbsd and added makefile.neNNbsd and makefile.freebsd
version 1.0.13patch01 [April 17, 2002]
version 1.2.2patch01 [April 17, 2002]
Changed ${PNGMAJ}.${PNGVER} bug to ${PNGVER} in makefile.sgi and makefile.sggcc
Fixed VER -> PNGVER typo in makefile.macosx and added install-static to install
Added install: target to makefile.32sunu and makefile.64sunu
version 1.0.13patch03 [April 18, 2002]
version 1.2.2patch03 [April 18, 2002]
Revised 15 makefiles to link libpng.a to libpngNN.a and the include libpng
subdirectory to libpngNN subdirectory without the full pathname.
Moved generation of libpng.pc from "install" to "all" in 15 makefiles.
version 1.2.3rc1 [April 28, 2002]
Added install-man target to 15 makefiles (Dimitri Papadopolous-Orfanos).
Added $(DESTDIR) feature to 24 makefiles (Tim Mooney)
Fixed bug with $prefix, should be $(prefix) in makefile.hpux.
Updated cygwin-specific portion of pngconf.h and revised makefile.cygwin
Added a link from libpngNN.pc to libpng.pc in 15 makefiles.
Added links from include/libpngNN/*.h to include/*.h in 24 makefiles.
Revised makefile.darwin to make relative links without full pathname.
Added setjmp() at the end of png_create_*_struct_2() in case user forgets
to put one in their application.
Restored png_zalloc() and png_zfree() prototypes to version 1.2.1 and
removed them from module definition files.
version 1.2.3rc2 [May 1, 2002]
Fixed bug in reporting number of channels in pngget.c and pngset.c,
that was introduced in version 1.2.2beta5.
Exported png_zalloc(), png_zfree(), png_default_read(), png_default_write(),
png_default_flush(), and png_push_fill_buffer() and included them in
module definition files.
Added "libpng.pc" dependency to the "install-shared" target in 15 makefiles.
version 1.2.3rc3 [May 1, 2002]
Revised prototype for png_default_flush()
Remove old libpng.pc and libpngNN.pc before installing new ones.
version 1.2.3rc4 [May 2, 2002]
Typos in *.def files (png_default_read|write -> png_default_read|write_data)
In makefiles, changed rm libpng.NN.pc to rm libpngNN.pc
Added libpng-config and libpngNN-config and modified makefiles to install them.
Changed $(MANPATH) to $(DESTDIR)$(MANPATH) in makefiles
Added "Win32 DLL VB" configuration to projects/msvc/libpng.dsp
version 1.2.3rc5 [May 11, 2002]
Changed "error" and "message" in prototypes to "error_message" and
"warning_message" to avoid namespace conflict.
Revised 15 makefiles to build libpng-config from libpng-config-*.in
Once more restored png_zalloc and png_zfree to regular nonexported form.
Restored png_default_read|write_data, png_default_flush, png_read_fill_buffer
to nonexported form, but with PNGAPI, and removed them from module def files.
version 1.2.3rc6 [May 14, 2002]
Removed "PNGAPI" from png_zalloc() and png_zfree() in png.c
Changed "Gz" to "Gd" in projects/msvc/libpng.dsp and zlib.dsp.
Removed leftover libpng-config "sed" script from four makefiles.
Revised libpng-config creating script in 16 makefiles.
version 1.2.3 [May 22, 2002]
Revised libpng-config target in makefile.cygwin.
Removed description of png_set_mem_fn() from documentation.
Revised makefile.freebsd.
Minor cosmetic changes to 15 makefiles, e.g., $(DI) = $(DESTDIR)/$(INCDIR).
Revised projects/msvc/README.txt
Changed -lpng to -lpngNN in LDFLAGS in several makefiles.
version 1.2.4beta1 [May 24, 2002]
Added libpng.pc and libpng-config to "all:" target in 16 makefiles.
Fixed bug in 16 makefiles: $(DESTDIR)/$(LIBPATH) to $(DESTDIR)$(LIBPATH)
Added missing "\" before closing double quote in makefile.gcmmx.
Plugged various memory leaks; added png_malloc_warn() and png_set_text_2()
functions.
version 1.2.4beta2 [June 25, 2002]
Plugged memory leak of png_ptr->current_text (Matt Holgate).
Check for buffer overflow before reading CRC in pngpread.c (Warwick Allison)
Added -soname to the loader flags in makefile.dec, makefile.sgi, and
makefile.sggcc.
Added "test-installed" target to makefile.linux, makefile.gcmmx,
makefile.sgi, and makefile.sggcc.
version 1.2.4beta3 [June 28, 2002]
Plugged memory leak of row_buf in pngtest.c when there is a png_error().
Detect buffer overflow in pngpread.c when IDAT is corrupted with extra data.
Added "test-installed" target to makefile.32sunu, makefile.64sunu,
makefile.beos, makefile.darwin, makefile.dec, makefile.macosx,
makefile.solaris, makefile.hpux, makefile.hpgcc, and makefile.so9.
version 1.2.4rc1 and 1.0.14rc1 [July 2, 2002]
Added "test-installed" target to makefile.cygwin and makefile.sco.
Revised pnggccrd.c to be able to back out version 1.0.x via PNG_1_0_X macro.
version 1.2.4 and 1.0.14 [July 8, 2002]
Changed png_warning() to png_error() when width is too large to process.
version 1.2.4patch01 [July 20, 2002]
Revised makefile.cygwin to use DLL number 12 instead of 13.
version 1.2.5beta1 [August 6, 2002]
Added code to contrib/gregbook/readpng2.c to ignore unused chunks.
Replaced toucan.png in contrib/gregbook (it has been corrupt since 1.0.11)
Removed some stray *.o files from contrib/gregbook.
Changed png_error() to png_warning() about "Too much data" in pngpread.c
and about "Extra compressed data" in pngrutil.c.
Prevent png_ptr->pass from exceeding 7 in png_push_finish_row().
Updated makefile.hpgcc
Updated png.c and pnggccrd.c handling of return from png_mmx_support()
version 1.2.5beta2 [August 15, 2002]
Only issue png_warning() about "Too much data" in pngpread.c when avail_in
is nonzero.
Updated makefiles to install a separate libpng.so.3 with its own rpath.
version 1.2.5rc1 and 1.0.15rc1 [August 24, 2002]
Revised makefiles to not remove previous minor versions of shared libraries.
version 1.2.5rc2 and 1.0.15rc2 [September 16, 2002]
Revised 13 makefiles to remove "-lz" and "-L$(ZLIBLIB)", etc., from shared
library loader directive.
Added missing "$OBJSDLL" line to makefile.gcmmx.
Added missing "; fi" to makefile.32sunu.
version 1.2.5rc3 and 1.0.15rc3 [September 18, 2002]
Revised libpng-config script.
version 1.2.5 and 1.0.15 [October 2, 2002]
Revised makefile.macosx, makefile.darwin, makefile.hpgcc, and makefile.hpux,
and makefile.aix.
Send comments/corrections/commendations to
png-implement@ccrc.wustl.edu or to randeg@alum.rpi.edu

Просмотреть файл

@ -8,8 +8,8 @@ COPYRIGHT NOTICE, DISCLAIMER, and LICENSE:
If you modify libpng you may insert additional notices immediately following
this sentence.
libpng versions 1.0.7, July 1, 2000, through 1.0.9, January 31, 2001, are
Copyright (c) 2000 Glenn Randers-Pehrson
libpng versions 1.0.7, July 1, 2000, through 1.2.5, October 2, 2002, are
Copyright (c) 2000-2002 Glenn Randers-Pehrson
and are distributed according to the same disclaimer and license as libpng-1.0.6
with the following individuals added to the list of Contributing Authors
@ -99,4 +99,4 @@ certification mark of the Open Source Initiative.
Glenn Randers-Pehrson
randeg@alum.rpi.edu
January 31, 2001
October 2, 2002

Просмотреть файл

@ -1,21 +1,5 @@
Changes made to pristine png source by mozilla.org developers.
2002/02/15 -- Synced with 1.0.9 tree
2002/10/03 -- Synced with libpng-1.2.5 tree
Following changes applied:
Bug 78649 - Wrapped stderr fprintfs inside DEBUG ifdef.
Affected files: pnggccrd.c, ipng.cpp, if.cpp
Bug 81794 - crash/leak fix for pngrutil.c
Affected files: pngrutil.c
Bug 135579 - small interlaced PNG images not decoded correctly.
Affected files: pngpread.c
Bug 154996 - PNG files with invalid IHDR can crash/hand browser.
Affected files: pngpread.c
Bug 155222 - PNG files with invalid IHDR can corrupt heap.
Affected files: pngget.c

Просмотреть файл

@ -1,4 +1,4 @@
README for libpng 1.0.9 - January 31, 2001 (shared library 2.1)
README for libpng 1.2.5 - October 2, 2002 (shared library 12.0)
See the note about version numbers near the top of png.h
See INSTALL for instructions on how to install libpng.
@ -172,19 +172,24 @@ Files in this distribution:
pngsuite => Test images
visupng => Contains a MSVC workspace for VisualPng
projects => Contains project files and workspaces for building DLL
beos => Contains a Beos workspace for building libpng
borland => Contains a Borland workspace for building libpng
and zlib
msvc => Contains a Microsoft Visual C++ (MSVC) workspace
for building libpng and zlib
wince => Contains a Microsoft Visual C++ (Windows CD Toolkit)
workspace for building libpng and zlib on WindowsCE
netware.txt => Contains instructions for downloading a set of
project files for building libpng and zlib on
Netware.
wince.txt => Contains instructions for downloading a Microsoft
Visual C++ (Windows CD Toolkit) workspace for
building libpng and zlib on WindowsCE
scripts => Directory containing scripts for building libpng:
descrip.mms => VMS makefile for MMS or MMK
makefile.std => Generic UNIX makefile (cc, creates static libpng.a)
makefile.linux => Linux/ELF makefile
(gcc, creates libpng.so.2.1.0.9)
(gcc, creates libpng12.so.0.1.2.5)
makefile.gcmmx => Linux/ELF makefile (gcc, creates
libpng.so.2.1.0.9, uses assembler code
libpng12.so.0.1.2.5, uses assembler code
tuned for Intel MMX platform)
makefile.gcc => Generic makefile (gcc, creates static libpng.a)
makefile.knr => Archaic UNIX Makefile that converts files with
@ -192,17 +197,27 @@ Files in this distribution:
ftp://ftp.cs.wisc.edu/ghost)
makefile.aix => AIX makefile
makefile.cygwin => Cygwin/gcc makefile
makefile.darwin => Darwin makefile
makefile.dec => DEC Alpha UNIX makefile
makefile.freebsd => FreeBSD makefile
makefile.hpgcc => HPUX makefile using gcc
makefile.hpux => HPUX (10.20 and 11.00) makefile
makefile.ibmc => IBM C/C++ version 3.x for Win32 and OS/2 (static)
makefile.intel => Intel C/C++ version 4.0 and later
libpng.icc => Project file, IBM VisualAge/C++ 4.0 or later
makefile.macosx => MACOS X Makefile
makefile.netbsd => NetBSD/cc makefile, PNGGCCRD, makes libpng.so.
makefile.ne0bsd => NetBSD/cc makefile, PNGGCCRD, makes libpng0.so
makefile.openbsd => OpenBSD makefile
makefile.sgi => Silicon Graphics IRIX (cc, creates static lib)
makefile.sggcc => Silicon Graphics (gcc, creates libpng.so.2.1.0.9)
makefile.sggcc => Silicon Graphics (gcc, creates libpng12.so.0.1.2.5)
makefile.sunos => Sun makefile
makefile.solaris => Solaris 2.X makefile
(gcc, creates libpng.so.2.1.0.9)
(gcc, creates libpng12.so.0.1.2.5)
makefile.so9 => Solaris 9 makefile
(gcc, creates libpng12.so.0.1.2.5)
makefile.32sunu => Sun Ultra 32-bit makefile
makefile.64sunu => Sun Ultra 64-bit makefile
makefile.sco => For SCO OSr5 ELF and Unixware 7 with Native cc
makefile.mips => MIPS makefile
makefile.acorn => Acorn makefile
@ -229,6 +244,16 @@ Files in this distribution:
makevms.com => VMS build script
pngdef.pas => Defines for a png32bd.dll with Borland C++ 4.5
SCOPTIONS.ppc => Used with smakefile.ppc
mangle => Directory containing scripts to build libpng12m.so:
mangle.in => Function-decoration macros added to png.h by the
makefiles.
makefile.linux => Linux/ELF makefile
(gcc, creates libpng12m.so.0.1.2.5)
makefile.gcmmx => Linux/ELF makefile (gcc, creates
libpng12.so.0m.1.2.5, uses assembler code
tuned for Intel MMX platform)
makefile.sgi => Silicon Graphics (cc, creates libpng12m.so)
makefile.sggcc => Silicon Graphics (gcc, creates libpng12m.so)
Good luck, and happy coding.

Просмотреть файл

@ -1,9 +1,9 @@
libpng.txt - A description on how to use and modify libpng
libpng version 1.0.9 - January 31, 2001
libpng version 1.2.5 - October 2, 2002
Updated and distributed by Glenn Randers-Pehrson
<randeg@alum.rpi.edu>
Copyright (c) 1998, 1999, 2000 Glenn Randers-Pehrson
Copyright (c) 1998-2002 Glenn Randers-Pehrson
For conditions of distribution and use, see copyright
notice in png.h.
@ -78,7 +78,9 @@ Libpng is thread safe, provided the threads are using different
instances of the structures. Each thread should have its own
png_struct and png_info instances, and thus its own image.
Libpng does not protect itself against two threads using the
same instance of a structure.
same instance of a structure. Note: thread safety may be defeated
by use of some of the MMX assembler code in pnggccrd.c, which is only
compiled when the user defines PNG_THREAD_UNSAFE_OK.
II. Structures
@ -257,10 +259,11 @@ input stream. You must supply the function
png_byte name[5];
png_byte *data;
png_size_t size;
/* Note that libpng has already taken care of the
CRC handling */
/* Note that libpng has already taken care of
the CRC handling */
/* put your code here. Return one of the following: */
/* put your code here. Return one of the
following: */
return (-n); /* chunk had an error */
return (0); /* did not recognize */
@ -285,7 +288,8 @@ called after each row has been read, which you can use to control
a progress meter or the like. It's demonstrated in pngtest.c.
You must supply a function
void read_row_callback(png_ptr ptr, png_uint_32 row, int pass);
void read_row_callback(png_ptr ptr, png_uint_32 row,
int pass);
{
/* put your code here */
}
@ -331,16 +335,23 @@ the entire image into memory, and (b) the input transformations
you want to do are limited to the following set:
PNG_TRANSFORM_IDENTITY No transformation
PNG_TRANSFORM_STRIP_16 Strip 16-bit samples to 8 bits
PNG_TRANSFORM_STRIP_16 Strip 16-bit samples to
8 bits
PNG_TRANSFORM_STRIP_ALPHA Discard the alpha channel
PNG_TRANSFORM_PACKING Expand 1, 2 and 4-bit samples to bytes
PNG_TRANSFORM_PACKSWAP Change order of packed pixels to LSB first
PNG_TRANSFORM_PACKING Expand 1, 2 and 4-bit
samples to bytes
PNG_TRANSFORM_PACKSWAP Change order of packed
pixels to LSB first
PNG_TRANSFORM_EXPAND Perform set_expand()
PNG_TRANSFORM_INVERT_MONO Invert monochrome images
PNG_TRANSFORM_SHIFT Normalize pixels to the sBIT depth
PNG_TRANSFORM_BGR Flip RGB to BGR, RGBA to BGRA
PNG_TRANSFORM_SWAP_ALPHA Flip RGBA to ARGB or GA to AG
PNG_TRANSFORM_INVERT_ALPHA Change alpha from opacity to transparency
PNG_TRANSFORM_SHIFT Normalize pixels to the
sBIT depth
PNG_TRANSFORM_BGR Flip RGB to BGR, RGBA
to BGRA
PNG_TRANSFORM_SWAP_ALPHA Flip RGBA to ARGB or GA
to AG
PNG_TRANSFORM_INVERT_ALPHA Change alpha from opacity
to transparency
PNG_TRANSFORM_SWAP_ENDIAN Byte-swap 16-bit samples
(This excludes setting a background color, doing gamma transformation,
@ -368,9 +379,11 @@ where row_pointers is an array of pointers to the pixel data for each row:
If you know your image size and pixel size ahead of time, you can allocate
row_pointers prior to calling png_read_png() with
row_pointers = png_malloc(png_ptr, height*sizeof(png_bytep));
row_pointers = png_malloc(png_ptr,
height*sizeof(png_bytep));
for (int i=0; i<height, i++)
row_pointers[i]=png_malloc(png_ptr, width*pixel_size);
row_pointers[i]=png_malloc(png_ptr,
width*pixel_size);
png_set_rows(png_ptr, info_ptr, &row_pointers);
Alternatively you could allocate your image in one big block and define
@ -438,8 +451,8 @@ in until png_read_end() has read the chunk data following the image.
interlace_type - (PNG_INTERLACE_NONE or
PNG_INTERLACE_ADAM7)
Any or all of interlace_type, compression_type, of
filter_method can be NULL if you are
not interested in their values.
filter_method can be NULL if you are
not interested in their values.
channels = png_get_channels(png_ptr, info_ptr);
channels - number of channels of info for the
@ -502,14 +515,15 @@ into the info_ptr is returned for any complex types.
implies specific values of gAMA and
cHRM.
png_get_iCCP(png_ptr, info_ptr, &name, &compression_type,
&profile, &proflen);
png_get_iCCP(png_ptr, info_ptr, &name,
&compression_type, &profile, &proflen);
name - The profile name.
compression - The compression type; always PNG_COMPRESSION_TYPE_BASE
for PNG 1.0. You may give NULL to this argument
to ignore it.
profile - International Color Consortium color profile
data. May contain NULs.
compression - The compression type; always
PNG_COMPRESSION_TYPE_BASE for PNG 1.0.
You may give NULL to this argument to
ignore it.
profile - International Color Consortium color
profile data. May contain NULs.
proflen - length of profile data in bytes.
png_get_sBIT(png_ptr, info_ptr, &sig_bit);
@ -563,23 +577,26 @@ into the info_ptr is returned for any complex types.
after decompression, 0 for tEXt/zTXt
text_ptr[i].lang - language of comment (empty
string for unknown).
text_ptr[i].translated_keyword - keyword in UTF-8
text_ptr[i].lang_key - keyword in UTF-8
(empty string for unknown).
num_text - number of comments (same as num_comments;
you can put NULL here to avoid the duplication)
Note while png_set_text() will accept text, language, and
translated keywords that can be NULL pointers, the structure
returned by png_get_text will always contain regular
zero-terminated C strings. They might be empty strings but
they will never be NULL pointers.
num_text - number of comments (same as
num_comments; you can put NULL here
to avoid the duplication)
Note while png_set_text() will accept text, language,
and translated keywords that can be NULL pointers, the
structure returned by png_get_text will always contain
regular zero-terminated C strings. They might be
empty strings but they will never be NULL pointers.
num_spalettes = png_get_sPLT(png_ptr, info_ptr, &palette_ptr);
num_spalettes = png_get_sPLT(png_ptr, info_ptr,
&palette_ptr);
palette_ptr - array of palette structures holding
contents of one or more sPLT chunks read.
contents of one or more sPLT chunks
read.
num_spalettes - number of sPLT chunks read.
png_get_oFFs(png_ptr, info_ptr, &offset_x, &offset_y,
&unit_type);
&unit_type);
offset_x - positive offset from the left edge
of the screen
offset_y - positive offset from the top edge
@ -587,7 +604,7 @@ into the info_ptr is returned for any complex types.
unit_type - PNG_OFFSET_PIXEL, PNG_OFFSET_MICROMETER
png_get_pHYs(png_ptr, info_ptr, &res_x, &res_y,
&unit_type);
&unit_type);
res_x - pixels/unit physical resolution in
x direction
res_y - pixels/unit physical resolution in
@ -595,47 +612,50 @@ into the info_ptr is returned for any complex types.
unit_type - PNG_RESOLUTION_UNKNOWN,
PNG_RESOLUTION_METER
png_get_sCAL(png_ptr, info_ptr, &unit, &width, &height)
png_get_sCAL(png_ptr, info_ptr, &unit, &width,
&height)
unit - physical scale units (an integer)
width - width of a pixel in physical scale units
height - height of a pixel in physical scale units
(width and height are doubles)
png_get_sCAL_s(png_ptr, info_ptr, &unit, &width, &height)
png_get_sCAL_s(png_ptr, info_ptr, &unit, &width,
&height)
unit - physical scale units (an integer)
width - width of a pixel in physical scale units
height - height of a pixel in physical scale units
(width and height are strings like "2.54")
num_unknown_chunks = png_get_unknown_chunks(png_ptr, info_ptr,
&unknowns)
unknowns - array of png_unknown_chunk structures holding
unknown chunks
num_unknown_chunks = png_get_unknown_chunks(png_ptr,
info_ptr, &unknowns)
unknowns - array of png_unknown_chunk
structures holding unknown chunks
unknowns[i].name - name of unknown chunk
unknowns[i].data - data of unknown chunk
unknowns[i].size - size of unknown chunk's data
unknowns[i].location - position of chunk in file
The value of "i" corresponds to the order in which the chunks were read
from the PNG file or inserted with the png_set_unknown_chunks() function.
The value of "i" corresponds to the order in which the
chunks were read from the PNG file or inserted with the
png_set_unknown_chunks() function.
The data from the pHYs chunk can be retrieved in several convenient
forms:
res_x = png_get_x_pixels_per_meter(png_ptr,
info_ptr)
info_ptr)
res_y = png_get_y_pixels_per_meter(png_ptr,
info_ptr)
info_ptr)
res_x_and_y = png_get_pixels_per_meter(png_ptr,
info_ptr)
info_ptr)
res_x = png_get_x_pixels_per_inch(png_ptr,
info_ptr)
info_ptr)
res_y = png_get_y_pixels_per_inch(png_ptr,
info_ptr)
info_ptr)
res_x_and_y = png_get_pixels_per_inch(png_ptr,
info_ptr)
info_ptr)
aspect_ratio = png_get_pixel_aspect_ratio(png_ptr,
info_ptr)
info_ptr)
(Each of these returns 0 [signifying "unknown"] if
the data is not present or if res_x is 0;
@ -650,8 +670,8 @@ forms:
y_offset = png_get_y_offset_inches(png_ptr, info_ptr);
(Each of these returns 0 [signifying "unknown" if both
x and y are 0] if the data is not present or if the chunk
is present but the unit is the pixel)
x and y are 0] if the data is not present or if the
chunk is present but the unit is the pixel)
For more information, see the png_info definition in png.h and the
PNG specification for chunk contents. Be careful with trusting
@ -772,7 +792,7 @@ higher possible bit depth (e.g. from 5 bits/sample in the range [0,31] to
convert the PNG pixel data back to the original bit depth of the image.
This call reduces the pixels back down to the original bit depth:
png_color_16p sig_bit;
png_color_8p sig_bit;
if (png_get_sBIT(png_ptr, info_ptr, &sig_bit))
png_set_shift(png_ptr, sig_bit);
@ -784,17 +804,18 @@ changes the storage of the pixels to blue, green, red:
color_type == PNG_COLOR_TYPE_RGB_ALPHA)
png_set_bgr(png_ptr);
PNG files store RGB pixels packed into 3 bytes. This code expands them
into 4 bytes for windowing systems that need them in this format:
PNG files store RGB pixels packed into 3 or 6 bytes. This code expands them
into 4 or 8 bytes for windowing systems that need them in this format:
if (bit_depth == 8 && color_type ==
PNG_COLOR_TYPE_RGB) png_set_filler(png_ptr,
filler, PNG_FILLER_BEFORE);
if (color_type == PNG_COLOR_TYPE_RGB)
png_set_filler(png_ptr, filler, PNG_FILLER_BEFORE);
where "filler" is the 8 or 16-bit number to fill with, and the location is
either PNG_FILLER_BEFORE or PNG_FILLER_AFTER, depending upon whether
you want the filler before the RGB or after. This transformation
does not affect images that already have full alpha channels.
does not affect images that already have full alpha channels. To add an
opaque alpha channel, use filler=0xff or 0xffff and PNG_FILLER_AFTER which
will generate RGBA pixels.
If you are reading an image with an alpha channel, and you need the
data as ARGB instead of the normal PNG format RGBA:
@ -864,8 +885,8 @@ which can be expressed with integers as
The calculation is done in a linear colorspace, if the image gamma
is known.
If you have a grayscale and you are using png_set_expand_depth() or
png_set_expand() to change to
If you have a grayscale and you are using png_set_expand_depth(),
png_set_expand(), or png_set_gray_to_rgb to change to truecolor or to
a higher bit-depth, you must either supply the background color as a gray
value at the original file bit-depth (need_expand = 1) or else supply the
background color as an RGB triplet at the final, expanded bit depth
@ -962,7 +983,7 @@ histogram, it may not do as good a job.
if (png_get_valid(png_ptr, info_ptr,
PNG_INFO_PLTE))
{
png_uint_16p histogram;
png_uint_16p histogram = NULL;
png_get_hIST(png_ptr, info_ptr,
&histogram);
@ -984,7 +1005,13 @@ PNG files describe monochrome as black being zero and white being one.
The following code will reverse this (make black be one and white be
zero):
if (bit_depth == 1 && color_type == PNG_COLOR_GRAY)
if (bit_depth == 1 && color_type == PNG_COLOR_TYPE_GRAY)
png_set_invert_mono(png_ptr);
This function can also be used to invert grayscale and gray-alpha images:
if (color_type == PNG_COLOR_TYPE_GRAY ||
color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
png_set_invert_mono(png_ptr);
PNG files store 16 bit pixels in network byte order (big-endian,
@ -1185,7 +1212,7 @@ When you are done, you can free all memory allocated by libpng like this:
It is also possible to individually free the info_ptr members that
point to libpng-allocated storage with the following function:
png_free_data(png_ptr, info_ptr, mask, n)
png_free_data(png_ptr, info_ptr, mask, seq)
mask - identifies data to be freed, a mask
containing the logical OR of one or
more of
@ -1195,16 +1222,17 @@ point to libpng-allocated storage with the following function:
PNG_FREE_SCAL, PNG_FREE_SPLT,
PNG_FREE_TEXT, PNG_FREE_UNKN,
or simply PNG_FREE_ALL
n - sequence number of item to be freed
seq - sequence number of item to be freed
(-1 for all items)
This function may be safely called when the relevant storage has
already been freed, or has not yet been allocated, or was allocated
by the user and not by libpng, and will in those
cases do nothing. The "n" parameter is ignored if only one item
of the selected data type, such as PLTE, is allowed. If "n" is not
cases do nothing. The "seq" parameter is ignored if only one item
of the selected data type, such as PLTE, is allowed. If "seq" is not
-1, and multiple items are allowed for the data type identified in
the mask, such as text or sPLT, only the n'th item is freed.
the mask, such as text or sPLT, only the n'th item in the structure
is freed, where n is "seq".
The default behavior is only to free data that was allocated internally
by libpng. This can be changed, so that libpng will not free the data,
@ -1228,8 +1256,7 @@ or png_destroy_*() is supposed to free the data. When the user assumes
responsibility for libpng-allocated data, the application must use
png_free() to free it, and when the user transfers responsibility to libpng
for data that the user has allocated, the user must have used png_malloc()
or png_zalloc() to allocate it (the png_zalloc() function is the same
as png_malloc() except that it also zeroes the newly-allocated memory).
or png_zalloc() to allocate it.
If you allocated your row_pointers in a single block, as suggested above in
the description of the high level read interface, you must not transfer
@ -1523,7 +1550,8 @@ called after each row has been written, which you can use to control
a progress meter or the like. It's demonstrated in pngtest.c.
You must supply a function
void write_row_callback(png_ptr, png_uint_32 row, int pass);
void write_row_callback(png_ptr, png_uint_32 row,
int pass);
{
/* put your code here */
}
@ -1551,8 +1579,9 @@ types.
/* turn on or off filtering, and/or choose
specific filters. You can use either a single PNG_FILTER_VALUE_NAME
or the logical OR of one or more PNG_FILTER_NAME masks. */
specific filters. You can use either a single
PNG_FILTER_VALUE_NAME or the logical OR of one
or more PNG_FILTER_NAME masks. */
png_set_filter(png_ptr, 0,
PNG_FILTER_NONE | PNG_FILTER_VALUE_NONE |
PNG_FILTER_SUB | PNG_FILTER_VALUE_SUB |
@ -1688,11 +1717,12 @@ Some of the more important parts of the png_info are:
png_set_iCCP(png_ptr, info_ptr, name, compression_type,
profile, proflen);
name - The profile name.
compression - The compression type; always PNG_COMPRESSION_TYPE_BASE
for PNG 1.0. You may give NULL to this argument
to ignore it.
profile - International Color Consortium color profile
data. May contain NULs.
compression - The compression type; always
PNG_COMPRESSION_TYPE_BASE for PNG 1.0.
You may give NULL to this argument to
ignore it.
profile - International Color Consortium color
profile data. May contain NULs.
proflen - length of profile data in bytes.
png_set_sBIT(png_ptr, info_ptr, sig_bit);
@ -1746,11 +1776,13 @@ Some of the more important parts of the png_info are:
or empty for unknown).
num_text - number of comments
png_set_sPLT(png_ptr, info_ptr, &palette_ptr, num_spalettes);
palette_ptr - array of png_sPLT_struct structures to be
added to the list of palettes in the info
structure.
num_spalettes - number of palette structures to be added.
png_set_sPLT(png_ptr, info_ptr, &palette_ptr,
num_spalettes);
palette_ptr - array of png_sPLT_struct structures
to be added to the list of palettes
in the info structure.
num_spalettes - number of palette structures to be
added.
png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y,
unit_type);
@ -1781,9 +1813,10 @@ Some of the more important parts of the png_info are:
height - height of a pixel in physical scale units
(width and height are strings like "2.54")
png_set_unknown_chunks(png_ptr, info_ptr, &unknowns, num_unknowns)
unknowns - array of png_unknown_chunk structures holding
unknown chunks
png_set_unknown_chunks(png_ptr, info_ptr, &unknowns,
num_unknowns)
unknowns - array of png_unknown_chunk
structures holding unknown chunks
unknowns[i].name - name of unknown chunk
unknowns[i].data - data of unknown chunk
unknowns[i].size - size of unknown chunk's data
@ -1792,14 +1825,15 @@ Some of the more important parts of the png_info are:
PNG_HAVE_IHDR: before PLTE
PNG_HAVE_PLTE: before IDAT
PNG_AFTER_IDAT: after IDAT
The "location" member is set automatically according to
what part of the output file has already been written.
You can change its value after calling png_set_unknown_chunks()
as demonstrated in pngtest.c. Within each of the "locations",
the chunks are sequenced according to their position in the
structure (that is, the value of "i", which is the order in which
the chunk was either read from the input file or defined with
png_set_unknown_chunks).
The "location" member is set automatically according to
what part of the output file has already been written.
You can change its value after calling png_set_unknown_chunks()
as demonstrated in pngtest.c. Within each of the "locations",
the chunks are sequenced according to their position in the
structure (that is, the value of "i", which is the order in which
the chunk was either read from the input file or defined with
png_set_unknown_chunks).
A quick word about text and num_text. text is an array of png_text
structures. num_text is the number of valid structures in the array.
@ -1900,12 +1934,17 @@ transformations are permitted, enabled by the following masks.
PNG_TRANSFORM_IDENTITY No transformation
PNG_TRANSFORM_PACKING Pack 1, 2 and 4-bit samples
PNG_TRANSFORM_PACKSWAP Change order of packed pixels to LSB first
PNG_TRANSFORM_PACKSWAP Change order of packed
pixels to LSB first
PNG_TRANSFORM_INVERT_MONO Invert monochrome images
PNG_TRANSFORM_SHIFT Normalize pixels to the sBIT depth
PNG_TRANSFORM_BGR Flip RGB to BGR, RGBA to BGRA
PNG_TRANSFORM_SWAP_ALPHA Flip RGBA to ARGB or GA to AG
PNG_TRANSFORM_INVERT_ALPHA Change alpha from opacity to transparency
PNG_TRANSFORM_SHIFT Normalize pixels to the
sBIT depth
PNG_TRANSFORM_BGR Flip RGB to BGR, RGBA
to BGRA
PNG_TRANSFORM_SWAP_ALPHA Flip RGBA to ARGB or GA
to AG
PNG_TRANSFORM_INVERT_ALPHA Change alpha from opacity
to transparency
PNG_TRANSFORM_SWAP_ENDIAN Byte-swap 16-bit samples
PNG_TRANSFORM_STRIP_FILLER Strip out filler bytes.
@ -2169,7 +2208,7 @@ When you are done, you can free all memory used by libpng like this:
It is also possible to individually free the info_ptr members that
point to libpng-allocated storage with the following function:
png_free_data(png_ptr, info_ptr, mask, n)
png_free_data(png_ptr, info_ptr, mask, seq)
mask - identifies data to be freed, a mask
containing the logical OR of one or
more of
@ -2179,16 +2218,17 @@ point to libpng-allocated storage with the following function:
PNG_FREE_SCAL, PNG_FREE_SPLT,
PNG_FREE_TEXT, PNG_FREE_UNKN,
or simply PNG_FREE_ALL
n - sequence number of item to be freed
seq - sequence number of item to be freed
(-1 for all items)
This function may be safely called when the relevant storage has
already been freed, or has not yet been allocated, or was allocated
by the user and not by libpng, and will in those
cases do nothing. The "n" parameter is ignored if only one item
of the selected data type, such as PLTE, is allowed. If "n" is not
cases do nothing. The "seq" parameter is ignored if only one item
of the selected data type, such as PLTE, is allowed. If "seq" is not
-1, and multiple items are allowed for the data type identified in
the mask, such as text or sPLT, only the n'th item is freed.
the mask, such as text or sPLT, only the n'th item in the structure
is freed, where n is "seq".
If you allocated data such as a palette that you passed
in to libpng with png_set_*, you must not free it until just before the call to
@ -2261,26 +2301,30 @@ goes through callbacks that are user-settable. The default routines are
in pngmem.c, pngrio.c, pngwio.c, and pngerror.c, respectively. To change
these functions, call the appropriate png_set_*_fn() function.
Memory allocation is done through the functions png_malloc(), png_zalloc(),
Memory allocation is done through the functions png_malloc()
and png_free(). These currently just call the standard C functions. If
your pointers can't access more then 64K at a time, you will want to set
MAXSEG_64K in zlib.h. Since it is unlikely that the method of handling
memory allocation on a platform will change between applications, these
functions must be modified in the library at compile time. If you prefer
to use a different method of allocating and freeing data, you can use
png_create_read_struct_2() or png_create_write_struct_2() to register
your own functions as described above.
png_set_mem_fn(png_structp png_ptr, png_voidp mem_ptr, png_malloc_ptr
malloc_fn, png_free_ptr free_fn)
This function also provides a void pointer that can be retrieved via
These functions also provide a void pointer that can be retrieved via
mem_ptr=png_get_mem_ptr(png_ptr);
Your replacement memory functions must have prototypes as follows:
png_voidp malloc_fn(png_structp png_ptr, png_uint_32 size);
png_voidp malloc_fn(png_structp png_ptr,
png_size_t size);
void free_fn(png_structp png_ptr, png_voidp ptr);
Your malloc_fn() should return NULL in case of failure. The png_malloc()
function will call png_error() if it receives a NULL from the system
memory allocator or from your replacement malloc_fn().
Input/Output in libpng is done through png_read() and png_write(),
which currently just call fread() and fwrite(). The FILE * is stored in
png_struct and is initialized via png_init_io(). If you wish to change
@ -2303,9 +2347,9 @@ png_get_io_ptr(). For example:
The replacement I/O functions must have prototypes as follows:
void user_read_data(png_structp png_ptr,
png_bytep data, png_uint_32 length);
png_bytep data, png_size_t length);
void user_write_data(png_structp png_ptr,
png_bytep data, png_uint_32 length);
png_bytep data, png_size_t length);
void user_flush_data(png_structp png_ptr);
Supplying NULL for the read, write, or flush functions sets them back
@ -2440,6 +2484,10 @@ compression level by calling:
Another useful one is to reduce the memory level used by the library.
The memory level defaults to 8, but it can be lowered if you are
short on memory (running DOS, for example, where you only have 640K).
Note that the memory level does have an effect on compression; among
other things, lower levels will result in sections of incompressible
data being emitted in smaller stored blocks, with a correspondingly
larger relative overhead of up to 15% in the worst case.
png_set_compression_mem_level(png_ptr, level);
@ -2474,38 +2522,39 @@ to turn filtering on and off, respectively.
Individual filter types are PNG_FILTER_NONE, PNG_FILTER_SUB,
PNG_FILTER_UP, PNG_FILTER_AVG, PNG_FILTER_PAETH, which can be bitwise
ORed together with '|' to specify one or more filters to use.
These filters are described in more detail in the PNG specification. If
you intend to change the filter type during the course of writing
These filters are described in more detail in the PNG specification.
If you intend to change the filter type during the course of writing
the image, you should start with flags set for all of the filters
you intend to use so that libpng can initialize its internal
structures appropriately for all of the filter types.
structures appropriately for all of the filter types. (Note that this
means the first row must always be adaptively filtered, because libpng
currently does not allocate the filter buffers until png_write_row()
is called for the first time.)
filters = PNG_FILTER_NONE | PNG_FILTER_SUB
PNG_FILTER_UP | PNG_FILTER_AVE |
PNG_FILTER_PAETH | PNG_ALL_FILTERS;
or
filters = one of PNG_FILTER_VALUE_NONE,
PNG_FILTER_VALUE_SUB, PNG_FILTER_VALUE_UP,
PNG_FILTER_VALUE_AVE, PNG_FILTER_VALUE_PAETH
png_set_filter(png_ptr, PNG_FILTER_TYPE_BASE,
filters);
The second parameter can also be PNG_INTRAPIXEL_DIFFERENCING
if you are writing a PNG to be embedded in a MNG
datastream. This parameter must be the same as the
value of filter_method used in png_set_IHDR().
The second parameter can also be
PNG_INTRAPIXEL_DIFFERENCING if you are
writing a PNG to be embedded in a MNG
datastream. This parameter must be the
same as the value of filter_method used
in png_set_IHDR().
It is also possible to influence how libpng chooses from among the
available filters. This is done in two ways - by telling it how
important it is to keep the same filter for successive rows, and
by telling it the relative computational costs of the filters.
available filters. This is done in one or both of two ways - by
telling it how important it is to keep the same filter for successive
rows, and by telling it the relative computational costs of the filters.
double weights[3] = {1.5, 1.3, 1.1},
costs[PNG_FILTER_VALUE_LAST] =
{1.0, 1.3, 1.3, 1.5, 1.7};
png_set_filter_selection(png_ptr,
PNG_FILTER_SELECTION_WEIGHTED, 3,
png_set_filter_heuristics(png_ptr,
PNG_FILTER_HEURISTIC_WEIGHTED, 3,
weights, costs);
The weights are multiplying factors that indicate to libpng that the
@ -2605,8 +2654,127 @@ When PNG_DEBUG = 1, the macros are defined, but only png_debug statements
having level = 0 will be printed. There aren't any such statements in
this version of libpng, but if you insert some they will be printed.
VI. Runtime optimization
VI. MNG support
A new feature in libpng 1.2.0 is the ability to dynamically switch between
standard and optimized versions of some routines. Currently these are
limited to three computationally intensive tasks when reading PNG files:
decoding row filters, expanding interlacing, and combining interlaced or
transparent row data with previous row data. Currently the optimized
versions are available only for x86 (Intel, AMD, etc.) platforms with
MMX support, though this may change in future versions. (For example,
the non-MMX assembler optimizations for zlib might become similarly
runtime-selectable in future releases, in which case libpng could be
extended to support them. Alternatively, the compile-time choice of
floating-point versus integer routines for gamma correction might become
runtime-selectable.)
Because such optimizations tend to be very platform- and compiler-dependent,
both in how they are written and in how they perform, the new runtime code
in libpng has been written to allow programs to query, enable, and disable
either specific optimizations or all such optimizations. For example, to
enable all possible optimizations (bearing in mind that some "optimizations"
may actually run more slowly in rare cases):
#if defined(PNG_LIBPNG_VER) && (PNG_LIBPNG_VER >= 10200)
png_uint_32 mask, flags;
flags = png_get_asm_flags(png_ptr);
mask = png_get_asm_flagmask(PNG_SELECT_READ | PNG_SELECT_WRITE);
png_set_asm_flags(png_ptr, flags | mask);
#endif
To enable only optimizations relevant to reading PNGs, use PNG_SELECT_READ
by itself when calling png_get_asm_flagmask(); similarly for optimizing
only writing. To disable all optimizations:
#if defined(PNG_LIBPNG_VER) && (PNG_LIBPNG_VER >= 10200)
flags = png_get_asm_flags(png_ptr);
mask = png_get_asm_flagmask(PNG_SELECT_READ | PNG_SELECT_WRITE);
png_set_asm_flags(png_ptr, flags & ~mask);
#endif
To enable or disable only MMX-related features, use png_get_mmx_flagmask()
in place of png_get_asm_flagmask(). The mmx version takes one additional
parameter:
#if defined(PNG_LIBPNG_VER) && (PNG_LIBPNG_VER >= 10200)
int selection = PNG_SELECT_READ | PNG_SELECT_WRITE;
int compilerID;
mask = png_get_mmx_flagmask(selection, &compilerID);
#endif
On return, compilerID will indicate which version of the MMX assembler
optimizations was compiled. Currently two flavors exist: Microsoft
Visual C++ (compilerID == 1) and GNU C (a.k.a. gcc/gas, compilerID == 2).
On non-x86 platforms or on systems compiled without MMX optimizations, a
value of -1 is used.
Note that both png_get_asm_flagmask() and png_get_mmx_flagmask() return
all valid, settable optimization bits for the version of the library that's
currently in use. In the case of shared (dynamically linked) libraries,
this may include optimizations that did not exist at the time the code was
written and compiled. It is also possible, of course, to enable only known,
specific optimizations; for example:
#if defined(PNG_LIBPNG_VER) && (PNG_LIBPNG_VER >= 10200)
flags = PNG_ASM_FLAG_MMX_READ_COMBINE_ROW \
| PNG_ASM_FLAG_MMX_READ_INTERLACE \
| PNG_ASM_FLAG_MMX_READ_FILTER_SUB \
| PNG_ASM_FLAG_MMX_READ_FILTER_UP \
| PNG_ASM_FLAG_MMX_READ_FILTER_AVG \
| PNG_ASM_FLAG_MMX_READ_FILTER_PAETH ;
png_set_asm_flags(png_ptr, flags);
#endif
This method would enable only the MMX read-optimizations available at the
time of libpng 1.2.0's release, regardless of whether a later version of
the DLL were actually being used. (Also note that these functions did not
exist in versions older than 1.2.0, so any attempt to run a dynamically
linked app on such an older version would fail.)
To determine whether the processor supports MMX instructions at all, use
the png_mmx_support() function:
#if defined(PNG_LIBPNG_VER) && (PNG_LIBPNG_VER >= 10200)
mmxsupport = png_mmx_support();
#endif
It returns -1 if MMX support is not compiled into libpng, 0 if MMX code
is compiled but MMX is not supported by the processor, or 1 if MMX support
is fully available. Note that png_mmx_support(), png_get_mmx_flagmask(),
and png_get_asm_flagmask() all may be called without allocating and ini-
tializing any PNG structures (for example, as part of a usage screen or
"about" box).
The following code can be used to prevent an application from using the
thread_unsafe features, even if libpng was built with PNG_THREAD_UNSAFE_OK
defined:
#if defined(PNG_USE_PNGGCCRD) && defined(PNG_ASSEMBLER_CODE_SUPPORTED) \
&& defined(PNG_THREAD_UNSAFE_OK)
/* Disable thread-unsafe features of pnggccrd */
if (png_access_version() >= 10200)
{
png_uint_32 mmx_disable_mask = 0;
png_uint_32 asm_flags;
mmx_disable_mask |= ( PNG_ASM_FLAG_MMX_READ_COMBINE_ROW \
| PNG_ASM_FLAG_MMX_READ_FILTER_SUB \
| PNG_ASM_FLAG_MMX_READ_FILTER_AVG \
| PNG_ASM_FLAG_MMX_READ_FILTER_PAETH );
asm_flags = png_get_asm_flags(png_ptr);
png_set_asm_flags(png_ptr, asm_flags & ~mmx_disable_mask);
}
#endif
For more extensive examples of runtime querying, enabling and disabling
of optimized features, see contrib/gregbook/readpng2.c in the libpng
source-code distribution.
VII. MNG support
The MNG specification (available at http://www.libpng.org/pub/mng) allows
certain extensions to PNG for PNG images that are embedded in MNG datastreams.
@ -2631,7 +2799,7 @@ or any other MNG chunks; your application must provide its own support for
them. You may wish to consider using libmng (available at
http://www.libmng.com) instead.
VII. Changes to Libpng from version 0.88
VIII. Changes to Libpng from version 0.88
It should be noted that versions of libpng later than 0.96 are not
distributed by the original libpng author, Guy Schalnat, nor by
@ -2641,7 +2809,7 @@ of the original PNG Group, Glenn Randers-Pehrson. Guy and Andreas are
still alive and well, but they have moved on to other things.
The old libpng functions png_read_init(), png_write_init(),
png_info_init(), png_read_destroy(), and png_write_destory() have been
png_info_init(), png_read_destroy(), and png_write_destroy() have been
moved to PNG_INTERNAL in version 0.95 to discourage their use. These
functions will be removed from libpng version 2.0.0.
@ -2680,15 +2848,15 @@ application:
png_uint_32 application_vn = PNG_LIBPNG_VER;
VIII. Y2K Compliance in libpng
IX. Y2K Compliance in libpng
January 31, 2001
October 2, 2002
Since the PNG Development group is an ad-hoc body, we can't make
an official declaration.
This is your unofficial assurance that libpng from version 0.71 and
upward through 1.0.9 are Y2K compliant. It is my belief that earlier
upward through 1.2.5 are Y2K compliant. It is my belief that earlier
versions were also Y2K compliant.
Libpng only has three year fields. One is a 2-byte unsigned integer that
@ -2706,7 +2874,8 @@ There are seven time-related functions:
png_convert_to_rfc_1123() in png.c
(formerly png_convert_to_rfc_1152() in error)
png_convert_from_struct_tm() in pngwrite.c, called in pngwrite.c
png_convert_from_struct_tm() in pngwrite.c, called
in pngwrite.c
png_convert_from_time_t() in pngwrite.c
png_get_tIME() in pngget.c
png_handle_tIME() in pngrutil.c, called in pngread.c

Просмотреть файл

@ -1,8 +1,8 @@
/* png.c - location for general purpose libpng functions
*
* libpng version 1.0.9 - January 31, 2001
* Copyright (c) 1998-2001 Glenn Randers-Pehrson
* libpng version 1.2.5 - October 2, 2002
* Copyright (c) 1998-2002 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*
@ -13,14 +13,14 @@
#include "png.h"
/* Generate a compiler error if there is an old png.h in the search path. */
typedef version_1_0_9 Your_png_h_is_not_version_1_0_9;
typedef version_1_2_5 Your_png_h_is_not_version_1_2_5;
/* Version information for C files. This had better match the version
* string defined in png.h. */
#ifdef PNG_USE_GLOBAL_ARRAYS
/* png_libpng_ver was changed to a function in version 1.0.5c */
const char png_libpng_ver[18] = "1.0.9";
const char png_libpng_ver[18] = "1.2.5";
/* png_sig was changed to a function in version 1.0.5c */
/* Place to hold the signature string for a PNG file. */
@ -135,13 +135,26 @@ png_check_sig(png_bytep sig, int num)
}
/* Function to allocate memory for zlib and clear it to 0. */
#ifdef PNG_1_0_X
voidpf PNGAPI
#else
voidpf /* private */
#endif
png_zalloc(voidpf png_ptr, uInt items, uInt size)
{
png_uint_32 num_bytes = (png_uint_32)items * size;
png_voidp ptr = (png_voidp)png_malloc((png_structp)png_ptr, num_bytes);
png_voidp ptr;
png_structp p=png_ptr;
png_uint_32 save_flags=p->flags;
p->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
ptr = (png_voidp)png_malloc((png_structp)png_ptr, num_bytes);
p->flags=save_flags;
#ifndef PNG_NO_ZALLOC_ZERO
if (ptr == NULL)
return ((voidpf)ptr);
if (num_bytes > (png_uint_32)0x8000L)
{
png_memset(ptr, 0, (png_size_t)0x8000L);
@ -157,7 +170,11 @@ png_zalloc(voidpf png_ptr, uInt items, uInt size)
}
/* function to free memory for zlib */
#ifdef PNG_1_0_X
void PNGAPI
#else
void /* private */
#endif
png_zfree(voidpf png_ptr, voidpf ptr)
{
png_free((png_structp)png_ptr, (png_voidp)ptr);
@ -212,14 +229,13 @@ png_create_info_struct(png_structp png_ptr)
png_debug(1, "in png_create_info_struct\n");
if(png_ptr == NULL) return (NULL);
#ifdef PNG_USER_MEM_SUPPORTED
if ((info_ptr = (png_infop)png_create_struct_2(PNG_STRUCT_INFO,
png_ptr->malloc_fn)) != NULL)
info_ptr = (png_infop)png_create_struct_2(PNG_STRUCT_INFO,
png_ptr->malloc_fn, png_ptr->mem_ptr);
#else
if ((info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO)) != NULL)
info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
#endif
{
png_info_init(info_ptr);
}
if (info_ptr != NULL)
png_info_init_3(&info_ptr, sizeof(png_info));
return (info_ptr);
}
@ -243,11 +259,12 @@ png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr)
png_info_destroy(png_ptr, info_ptr);
#ifdef PNG_USER_MEM_SUPPORTED
png_destroy_struct_2((png_voidp)info_ptr, png_ptr->free_fn);
png_destroy_struct_2((png_voidp)info_ptr, png_ptr->free_fn,
png_ptr->mem_ptr);
#else
png_destroy_struct((png_voidp)info_ptr);
#endif
*info_ptr_ptr = (png_infop)NULL;
*info_ptr_ptr = NULL;
}
}
@ -255,10 +272,28 @@ png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr)
* and applications using it are urged to use png_create_info_struct()
* instead.
*/
#undef png_info_init
void PNGAPI
png_info_init(png_infop info_ptr)
{
png_debug(1, "in png_info_init\n");
/* We only come here via pre-1.0.12-compiled applications */
png_info_init_3(&info_ptr, 0);
}
void PNGAPI
png_info_init_3(png_infopp ptr_ptr, png_size_t png_info_struct_size)
{
png_infop info_ptr = *ptr_ptr;
png_debug(1, "in png_info_init_3\n");
if(sizeof(png_info) > png_info_struct_size)
{
png_destroy_struct(info_ptr);
info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
*ptr_ptr = info_ptr;
}
/* set everything to 0 */
png_memset(info_ptr, 0, sizeof (png_info));
}
@ -282,7 +317,8 @@ png_data_freer(png_structp png_ptr, png_infop info_ptr,
#endif
void PNGAPI
png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask, int num)
png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask,
int num)
{
png_debug(1, "in png_free_data\n");
if (png_ptr == NULL || info_ptr == NULL)
@ -326,6 +362,9 @@ if ((mask & PNG_FREE_TRNS) && (png_ptr->flags & PNG_FLAG_FREE_TRNS))
{
png_free(png_ptr, info_ptr->trans);
info_ptr->valid &= ~PNG_INFO_tRNS;
#ifndef PNG_FREE_ME_SUPPORTED
png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
#endif
info_ptr->trans = NULL;
}
#endif
@ -469,6 +508,9 @@ if ((mask & PNG_FREE_HIST) && (png_ptr->flags & PNG_FLAG_FREE_HIST))
png_free(png_ptr, info_ptr->hist);
info_ptr->hist = NULL;
info_ptr->valid &= ~PNG_INFO_hIST;
#ifndef PNG_FREE_ME_SUPPORTED
png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
#endif
}
#endif
@ -482,6 +524,9 @@ if ((mask & PNG_FREE_PLTE) && (png_ptr->flags & PNG_FLAG_FREE_PLTE))
png_zfree(png_ptr, info_ptr->palette);
info_ptr->palette = NULL;
info_ptr->valid &= ~PNG_INFO_PLTE;
#ifndef PNG_FREE_ME_SUPPORTED
png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;
#endif
info_ptr->num_palette = 0;
}
@ -536,7 +581,7 @@ png_info_destroy(png_structp png_ptr, png_infop info_ptr)
}
#endif
png_info_init(info_ptr);
png_info_init_3(&info_ptr, sizeof(png_info));
}
/* This function returns a pointer to the io_ptr associated with the user
@ -582,31 +627,31 @@ png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime)
}
#if defined(_WIN32_WCE)
{
wchar_t time_buf[29];
wsprintf(time_buf, TEXT("%d %S %d %02d:%02d:%02d +0000"),
ptime->day % 32, short_months[(ptime->month - 1) % 12],
ptime->year, ptime->hour % 24, ptime->minute % 60,
ptime->second % 61);
WideCharToMultiByte(CP_ACP, 0, time_buf, -1, png_ptr->time_buffer, 29,
NULL, NULL);
}
{
wchar_t time_buf[29];
wsprintf(time_buf, TEXT("%d %S %d %02d:%02d:%02d +0000"),
ptime->day % 32, short_months[(ptime->month - 1) % 12],
ptime->year, ptime->hour % 24, ptime->minute % 60,
ptime->second % 61);
WideCharToMultiByte(CP_ACP, 0, time_buf, -1, png_ptr->time_buffer, 29,
NULL, NULL);
}
#else
#ifdef USE_FAR_KEYWORD
{
char near_time_buf[29];
sprintf(near_time_buf, "%d %s %d %02d:%02d:%02d +0000",
ptime->day % 32, short_months[(ptime->month - 1) % 12],
ptime->year, ptime->hour % 24, ptime->minute % 60,
ptime->second % 61);
ptime->day % 32, short_months[(ptime->month - 1) % 12],
ptime->year, ptime->hour % 24, ptime->minute % 60,
ptime->second % 61);
png_memcpy(png_ptr->time_buffer, near_time_buf,
29*sizeof(char));
29*sizeof(char));
}
#else
sprintf(png_ptr->time_buffer, "%d %s %d %02d:%02d:%02d +0000",
ptime->day % 32, short_months[(ptime->month - 1) % 12],
ptime->year, ptime->hour % 24, ptime->minute % 60,
ptime->second % 61);
ptime->day % 32, short_months[(ptime->month - 1) % 12],
ptime->year, ptime->hour % 24, ptime->minute % 60,
ptime->second % 61);
#endif
#endif /* _WIN32_WCE */
return ((png_charp)png_ptr->time_buffer);
@ -626,10 +671,10 @@ png_charp PNGAPI
png_get_copyright(png_structp png_ptr)
{
if (png_ptr != NULL || png_ptr == NULL) /* silence compiler warning */
return ((png_charp) "\n libpng version 1.0.9 - January 31, 2001\n\
Copyright (c) 1998-2001 Glenn Randers-Pehrson\n\
Copyright (c) 1996, 1997 Andreas Dilger\n\
Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.\n");
return ((png_charp) "\n libpng version 1.2.5 - October 2, 2002\n\
Copyright (c) 1998-2002 Glenn Randers-Pehrson\n\
Copyright (c) 1996-1997 Andreas Dilger\n\
Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.\n");
return ((png_charp) "");
}
@ -644,8 +689,8 @@ png_get_libpng_ver(png_structp png_ptr)
{
/* Version of *.c files used when building libpng */
if(png_ptr != NULL) /* silence compiler warning about unused png_ptr */
return((png_charp) "1.0.9");
return((png_charp) "1.0.9");
return((png_charp) "1.2.5");
return((png_charp) "1.2.5");
}
png_charp PNGAPI
@ -695,17 +740,66 @@ png_uint_32 PNGAPI
png_access_version_number(void)
{
/* Version of *.c files used when building libpng */
return((png_uint_32) 10009L);
return((png_uint_32) 10205L);
}
#if 0 /* delay this until version 1.2.0 */
/* this function was added to libpng 1.0.9 (porting aid to libpng-1.2.0) */
#ifndef PNG_ASSEMBLER_CODE_SUPPORTED
#if !defined(PNG_1_0_X)
#if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
/* GRR: could add this: && defined(PNG_MMX_CODE_SUPPORTED) */
/* this INTERNAL function was added to libpng 1.2.0 */
void /* PRIVATE */
png_init_mmx_flags (png_structp png_ptr)
{
png_ptr->mmx_rowbytes_threshold = 0;
png_ptr->mmx_bitdepth_threshold = 0;
# if (defined(PNG_USE_PNGVCRD) || defined(PNG_USE_PNGGCCRD))
png_ptr->asm_flags |= PNG_ASM_FLAG_MMX_SUPPORT_COMPILED;
if (png_mmx_support() > 0) {
png_ptr->asm_flags |= PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU
# ifdef PNG_HAVE_ASSEMBLER_COMBINE_ROW
| PNG_ASM_FLAG_MMX_READ_COMBINE_ROW
# endif
# ifdef PNG_HAVE_ASSEMBLER_READ_INTERLACE
| PNG_ASM_FLAG_MMX_READ_INTERLACE
# endif
# ifndef PNG_HAVE_ASSEMBLER_READ_FILTER_ROW
;
# else
| PNG_ASM_FLAG_MMX_READ_FILTER_SUB
| PNG_ASM_FLAG_MMX_READ_FILTER_UP
| PNG_ASM_FLAG_MMX_READ_FILTER_AVG
| PNG_ASM_FLAG_MMX_READ_FILTER_PAETH ;
png_ptr->mmx_rowbytes_threshold = PNG_MMX_ROWBYTES_THRESHOLD_DEFAULT;
png_ptr->mmx_bitdepth_threshold = PNG_MMX_BITDEPTH_THRESHOLD_DEFAULT;
# endif
} else {
png_ptr->asm_flags &= ~( PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU
| PNG_MMX_READ_FLAGS
| PNG_MMX_WRITE_FLAGS );
}
# else /* !((PNGVCRD || PNGGCCRD) && PNG_ASSEMBLER_CODE_SUPPORTED)) */
/* clear all MMX flags; no support is compiled in */
png_ptr->asm_flags &= ~( PNG_MMX_FLAGS );
# endif /* ?(PNGVCRD || PNGGCCRD) */
}
#endif /* !(PNG_ASSEMBLER_CODE_SUPPORTED) */
/* this function was added to libpng 1.2.0 */
#if !defined(PNG_USE_PNGGCCRD) && \
!(defined(PNG_ASSEMBLER_CODE_SUPPORTED) && defined(PNG_USE_PNGVCRD))
int PNGAPI
png_mmx_support(void)
{
return -1;
}
#endif
#endif /* 0 */
#endif /* PNG_1_0_X */

Просмотреть файл

@ -1,15 +1,14 @@
/* png.h - header file for PNG reference library
*
* libpng version 1.0.9 - January 31, 2001
* Copyright (c) 1998-2001 Glenn Randers-Pehrson
* libpng version 1.2.5 - October 2, 2002
* Copyright (c) 1998-2002 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*
* Authors and maintainers:
* libpng versions 0.71, May 1995, through 0.88, January 1996: Guy Schalnat
* libpng versions 0.89c, June 1996, through 0.96, May 1997: Andreas Dilger
* libpng versions 0.97, January 1998, through 1.0.9 - January 31, 2001: Glenn
* libpng versions 0.97, January 1998, through 1.2.5 - October 2, 2002: Glenn
* See also "Contributing Authors", below.
*
* Note about libpng version numbers:
@ -64,6 +63,41 @@
* 1.0.9beta7-10 1 10009 2.1.0.9beta7-10
* 1.0.9rc2 1 10009 2.1.0.9rc2
* 1.0.9 1 10009 2.1.0.9
* 1.0.10beta1 1 10010 2.1.0.10beta1
* 1.0.10rc1 1 10010 2.1.0.10rc1
* 1.0.10 1 10010 2.1.0.10
* 1.0.11beta1-3 1 10011 2.1.0.11beta1-3
* 1.0.11rc1 1 10011 2.1.0.11rc1
* 1.0.11 1 10011 2.1.0.11
* 1.0.12beta1-2 2 10012 2.1.0.12beta1-2
* 1.0.12rc1 2 10012 2.1.0.12rc1
* 1.0.12 2 10012 2.1.0.12
* 1.1.0a-f - 10100 2.1.1.0a-f (branch abandoned)
* 1.2.0beta1-2 2 10200 2.1.2.0beta1-2
* 1.2.0beta3-5 3 10200 3.1.2.0beta3-5
* 1.2.0rc1 3 10200 3.1.2.0rc1
* 1.2.0 3 10200 3.1.2.0
* 1.2.1beta1-4 3 10201 3.1.2.1beta1-4
* 1.2.1rc1-2 3 10201 3.1.2.1rc1-2
* 1.2.1 3 10201 3.1.2.1
* 1.2.2beta1-6 12 10202 12.so.0.1.2.2beta1-6
* 1.0.13beta1 10 10013 10.so.0.1.0.13beta1
* 1.0.13rc1 10 10013 10.so.0.1.0.13rc1
* 1.2.2rc1 12 10202 12.so.0.1.2.2rc1
* 1.0.13 10 10013 10.so.0.1.0.13
* 1.2.2 12 10202 12.so.0.1.2.2
* 1.2.3rc1-6 12 10203 12.so.0.1.2.3rc1-6
* 1.2.3 12 10203 12.so.0.1.2.3
* 1.2.4beta1-3 13 10204 12.so.0.1.2.4beta1-3
* 1.0.14rc1 13 10014 10.so.0.1.0.14rc1
* 1.2.4rc1 13 10204 12.so.0.1.2.4rc1
* 1.0.14 10 10014 10.so.0.1.0.14
* 1.2.4 13 10204 12.so.0.1.2.4
* 1.2.5beta1-2 13 10205 12.so.0.1.2.5beta1-2
* 1.0.15rc1-3 10 10015 10.so.0.1.0.15rc1-3
* 1.2.5rc1-3 13 10205 12.so.0.1.2.5rc1-3
* 1.0.15 10 10015 10.so.0.1.0.15
* 1.2.5 13 10205 12.so.0.1.2.5
*
* Henceforth the source version will match the shared-library major
* and minor numbers; the shared-library major version number will be
@ -93,8 +127,8 @@
* If you modify libpng you may insert additional notices immediately following
* this sentence.
*
* libpng versions 1.0.7, July 1, 2000, through 1.0.9, January 31, 2001, are
* Copyright (c) 2000, 2001 Glenn Randers-Pehrson, and are
* libpng versions 1.0.7, July 1, 2000, through 1.2.5, October 2, 2002, are
* Copyright (c) 2000-2002 Glenn Randers-Pehrson, and are
* distributed according to the same disclaimer and license as libpng-1.0.6
* with the following individuals added to the list of Contributing Authors
*
@ -158,11 +192,11 @@
*
* 1. The origin of this source code must not be misrepresented.
*
* 2. Altered versions must be plainly marked as such and must not
* be misrepresented as being the original source.
* 2. Altered versions must be plainly marked as such and
* must not be misrepresented as being the original source.
*
* 3. This Copyright notice may not be removed or altered from any
* source or altered source distribution.
* 3. This Copyright notice may not be removed or altered from
* any source or altered source distribution.
*
* The Contributing Authors and Group 42, Inc. specifically permit, without
* fee, and encourage the use of this source code as a component to
@ -198,13 +232,13 @@
* Y2K compliance in libpng:
* =========================
*
* January 31, 2001
* October 2, 2002
*
* Since the PNG Development group is an ad-hoc body, we can't make
* an official declaration.
*
* This is your unofficial assurance that libpng from version 0.71 and
* upward through 1.0.9 are Y2K compliant. It is my belief that earlier
* upward through 1.2.5 are Y2K compliant. It is my belief that earlier
* versions were also Y2K compliant.
*
* Libpng only has three year fields. One is a 2-byte unsigned integer
@ -260,15 +294,15 @@
*/
/* Version information for png.h - this should match the version in png.c */
#define PNG_LIBPNG_VER_STRING "1.0.9"
#define PNG_LIBPNG_VER_STRING "1.2.5"
#define PNG_LIBPNG_VER_SONUM 2
#define PNG_LIBPNG_VER_SONUM 0
#define PNG_LIBPNG_VER_DLLNUM %DLLNUM%
/* These should match the first 3 components of PNG_LIBPNG_VER_STRING: */
#define PNG_LIBPNG_VER_MAJOR 1
#define PNG_LIBPNG_VER_MINOR 0
#define PNG_LIBPNG_VER_RELEASE 9
#define PNG_LIBPNG_VER_MINOR 2
#define PNG_LIBPNG_VER_RELEASE 5
/* This should match the numeric part of the final component of
* PNG_LIBPNG_VER_STRING, omitting any leading zero: */
@ -287,7 +321,7 @@
* Versions 0.7 through 1.0.0 were in the range 0 to 100 here (only
* version 1.0.0 was mis-numbered 100 instead of 10000). From
* version 1.0.1 it's xxyyzz, where x=major, y=minor, z=release */
#define PNG_LIBPNG_VER 10009 /* 1.0.9 */
#define PNG_LIBPNG_VER 10205 /* 1.2.5 */
#ifndef PNG_VERSION_INFO_ONLY
@ -308,6 +342,40 @@ extern "C" {
* which applications aren't expected to use directly.
*/
#ifndef PNG_NO_TYPECAST_NULL
#define int_p_NULL (int *)NULL
#define png_bytep_NULL (png_bytep)NULL
#define png_bytepp_NULL (png_bytepp)NULL
#define png_doublep_NULL (png_doublep)NULL
#define png_error_ptr_NULL (png_error_ptr)NULL
#define png_flush_ptr_NULL (png_flush_ptr)NULL
#define png_free_ptr_NULL (png_free_ptr)NULL
#define png_infopp_NULL (png_infopp)NULL
#define png_malloc_ptr_NULL (png_malloc_ptr)NULL
#define png_read_status_ptr_NULL (png_read_status_ptr)NULL
#define png_rw_ptr_NULL (png_rw_ptr)NULL
#define png_structp_NULL (png_structp)NULL
#define png_uint_16p_NULL (png_uint_16p)NULL
#define png_voidp_NULL (png_voidp)NULL
#define png_write_status_ptr_NULL (png_write_status_ptr)NULL
#else
#define int_p_NULL NULL
#define png_bytep_NULL NULL
#define png_bytepp_NULL NULL
#define png_doublep_NULL NULL
#define png_error_ptr_NULL NULL
#define png_flush_ptr_NULL NULL
#define png_free_ptr_NULL NULL
#define png_infopp_NULL NULL
#define png_malloc_ptr_NULL NULL
#define png_read_status_ptr_NULL NULL
#define png_rw_ptr_NULL NULL
#define png_structp_NULL NULL
#define png_uint_16p_NULL NULL
#define png_voidp_NULL NULL
#define png_write_status_ptr_NULL NULL
#endif
/* variables declared in png.c - only it needs to define PNG_NO_EXTERN */
#if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
/* Version information for C files, stored in png.c. This had better match
@ -315,7 +383,7 @@ extern "C" {
*/
#ifdef PNG_USE_GLOBAL_ARRAYS
PNG_EXPORT_VAR (const char) png_libpng_ver[18];
/* need room for 99.99.99beta99z*/
/* need room for 99.99.99beta99z */
#else
#define png_libpng_ver png_get_header_ver(NULL)
#endif
@ -541,7 +609,7 @@ typedef struct png_info_struct
png_byte interlace_type; /* One of PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
/* The following is informational only on read, and not used on writes. */
png_byte channels; /* number of data channels per pixel (1, 2, 3, 4)*/
png_byte channels; /* number of data channels per pixel (1, 2, 3, 4) */
png_byte pixel_depth; /* number of bits per pixel */
png_byte spare_byte; /* to align the data, and for future use */
png_byte signature[8]; /* magic bytes read by libpng from start of file */
@ -693,6 +761,7 @@ defined(PNG_READ_BACKGROUND_SUPPORTED)
png_byte pcal_nparams; /* number of parameters given in pcal_params */
#endif
/* New members added in libpng-1.0.6 */
#ifdef PNG_FREE_ME_SUPPORTED
png_uint_32 free_me; /* flags items libpng is responsible for freeing */
#endif
@ -830,7 +899,7 @@ typedef png_info FAR * FAR * png_infopp;
#define PNG_KEYWORD_MAX_LENGTH 79
/* Maximum number of entries in PLTE/sPLT/tRNS arrays */
#define PNG_MAX_PALETTE_LENGTH 256
#define PNG_MAX_PALETTE_LENGTH 256
/* These determine if an ancillary chunk's data has been successfully read
* from the PNG header, or if the application has filled in the corresponding
@ -902,10 +971,10 @@ typedef void (PNGAPI *png_user_transform_ptr) PNGARG((png_structp,
png_row_infop, png_bytep));
#endif
#if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
#if defined(PNG_USER_CHUNKS_SUPPORTED)
typedef int (PNGAPI *png_user_chunk_ptr) PNGARG((png_structp, png_unknown_chunkp));
#endif
#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
typedef void (PNGAPI *png_unknown_chunk_ptr) PNGARG((png_structp));
#endif
@ -949,7 +1018,7 @@ struct png_struct_def
png_voidp error_ptr; /* user supplied struct for error functions */
png_rw_ptr write_data_fn; /* function for writing output data */
png_rw_ptr read_data_fn; /* function for reading input data */
png_voidp io_ptr; /* ptr to application struct for I/O functions*/
png_voidp io_ptr; /* ptr to application struct for I/O functions */
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
png_user_transform_ptr read_user_transform_fn; /* user read transform */
@ -1025,16 +1094,16 @@ struct png_struct_def
#endif
#endif
#if defined(PNG_READ_bKGD_SUPPORTED)
#if defined(PNG_bKGD_SUPPORTED)
png_byte background_gamma_type;
# ifdef PNG_FLOATING_POINT_SUPPORTED
float background_gamma;
# endif
png_color_16 background; /* background color in screen gamma space */
# if defined(PNG_READ_GAMMA_SUPPORTED)
png_color_16 background_1; /* background normalized to gamma 1.0 */
# endif /* PNG_READ_GAMMA && PNG_READ_bKGD_SUPPORTED */
#endif /* PNG_READ_bKGD_SUPPORTED */
#if defined(PNG_READ_GAMMA_SUPPORTED)
png_color_16 background_1; /* background normalized to gamma 1.0 */
#endif
#endif /* PNG_bKGD_SUPPORTED */
#if defined(PNG_WRITE_FLUSH_SUPPORTED)
png_flush_ptr output_flush_fn;/* Function for flushing output */
@ -1059,7 +1128,7 @@ struct png_struct_def
png_uint_16pp gamma_16_to_1; /* converts from file to 1.0 */
#endif
#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_sBIT_SUPPORTED)
#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_sBIT_SUPPORTED)
png_color_8 sig_bit; /* significant bits in each available channel */
#endif
@ -1067,7 +1136,7 @@ struct png_struct_def
png_color_8 shift; /* shift for significant bit tranformation */
#endif
#if defined(PNG_READ_tRNS_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) \
#if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) \
|| defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
png_bytep trans; /* transparency values for paletted files */
png_color_16 trans_values; /* transparency values for non-paletted files */
@ -1092,12 +1161,12 @@ struct png_struct_def
int process_mode; /* what push library is currently doing */
int cur_palette; /* current push library palette index */
# if defined(PNG_READ_TEXT_SUPPORTED)
# if defined(PNG_TEXT_SUPPORTED)
png_size_t current_text_size; /* current size of text input data */
png_size_t current_text_left; /* how much text left to read in input */
png_charp current_text; /* current text chunk buffer */
png_charp current_text_ptr; /* current location in current_text */
# endif /* PNG_PROGRESSIVE_READ_SUPPORTED && PNG_READ_TEXT_SUPPORTED */
# endif /* PNG_PROGRESSIVE_READ_SUPPORTED && PNG_TEXT_SUPPORTED */
#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
@ -1115,7 +1184,7 @@ struct png_struct_def
png_bytep dither_index; /* index translation for palette files */
#endif
#if defined(PNG_READ_DITHER_SUPPORTED) || defined(PNG_READ_hIST_SUPPORTED)
#if defined(PNG_READ_DITHER_SUPPORTED) || defined(PNG_hIST_SUPPORTED)
png_uint_16p hist; /* histogram */
#endif
@ -1133,19 +1202,13 @@ struct png_struct_def
png_charp time_buffer; /* String to hold RFC 1123 time text */
#endif
#ifdef PNG_USER_MEM_SUPPORTED
png_voidp mem_ptr; /* user supplied struct for mem functions */
png_malloc_ptr malloc_fn; /* function for allocating memory */
png_free_ptr free_fn; /* function for freeing memory */
#endif
/* New members added in libpng-1.0.6 */
#ifdef PNG_FREE_ME_SUPPORTED
png_uint_32 free_me; /* flags items libpng is responsible for freeing */
#endif
#if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
#if defined(PNG_USER_CHUNKS_SUPPORTED)
png_voidp user_chunk_ptr;
png_user_chunk_ptr read_user_chunk_fn; /* user read chunk handler */
#endif
@ -1155,33 +1218,75 @@ struct png_struct_def
png_bytep chunk_list;
#endif
/* New members added in libpng-1.0.3 */
#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
png_byte rgb_to_gray_status;
/* These were changed from png_byte in libpng-1.0.6 */
png_uint_16 rgb_to_gray_red_coeff;
png_uint_16 rgb_to_gray_green_coeff;
png_uint_16 rgb_to_gray_blue_coeff;
#endif
/* New member added in libpng-1.0.4 (renamed in 1.0.9) */
#if defined(PNG_MNG_FEATURES_SUPPORTED) || \
defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
/* Note to maintainer: change this to png_uint_32 at next opportunity */
/* changed from png_byte to png_uint_32 at version 1.2.0 */
#ifdef PNG_1_0_X
png_byte mng_features_permitted;
#else
png_uint_32 mng_features_permitted;
#endif /* PNG_1_0_X */
#endif
/* New member added in libpng-1.0.7 */
#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
png_fixed_point int_gamma;
#endif
/* New member added in libpng-1.0.9, ifdef'ed out in 1.0.12, enabled in 1.2.0 */
#if defined(PNG_MNG_FEATURES_SUPPORTED)
png_byte filter_type;
#endif
#if defined(PNG_1_0_X) || (defined(PNG_DEBUG) && defined(PNG_USE_PNGGCCRD))
/* New member added in libpng-1.0.10, ifdef'ed out in 1.2.0 */
png_uint_32 row_buf_size;
#endif
/* New members added in libpng-1.2.0 */
#if !defined(PNG_1_0_X) && defined(PNG_ASSEMBLER_CODE_SUPPORTED)
png_byte mmx_bitdepth_threshold;
png_uint_32 mmx_rowbytes_threshold;
png_uint_32 asm_flags;
#endif
/* New members added in libpng-1.0.2 but first enabled by default in 1.2.0 */
#ifdef PNG_USER_MEM_SUPPORTED
png_voidp mem_ptr; /* user supplied struct for mem functions */
png_malloc_ptr malloc_fn; /* function for allocating memory */
png_free_ptr free_fn; /* function for freeing memory */
#endif
/* New member added in libpng-1.0.13 and 1.2.0 */
png_bytep big_row_buf; /* buffer to save current (unfiltered) row */
#if defined(PNG_READ_DITHER_SUPPORTED)
/* The following three members were added at version 1.0.14 and 1.2.4 */
png_bytep dither_sort; /* working sort array */
png_bytep index_to_palette; /* where the original index currently is */
/* in the palette */
png_bytep palette_to_index; /* which original index points to this */
/* palette color */
#endif
};
/* This prevents a compiler error in png_get_copyright() in png.c if png.c
and png.h are both at * version 1.0.9
/* This prevents a compiler error in png.c if png.c and png.h are both at
version 1.2.5
*/
typedef png_structp version_1_0_9;
typedef png_structp version_1_2_5;
typedef png_struct FAR * FAR * png_structpp;
@ -1232,6 +1337,7 @@ extern PNG_EXPORT(void,png_set_compression_buffer_size)
/* Reset the compression stream */
extern PNG_EXPORT(int,png_reset_zstream) PNGARG((png_structp png_ptr));
/* New functions added in libpng-1.0.2 (not enabled by default until 1.2.0) */
#ifdef PNG_USER_MEM_SUPPORTED
extern PNG_EXPORT(png_structp,png_create_read_struct_2)
PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
@ -1262,8 +1368,12 @@ extern PNG_EXPORT(void,png_write_chunk_end) PNGARG((png_structp png_ptr));
extern PNG_EXPORT(png_infop,png_create_info_struct)
PNGARG((png_structp png_ptr));
/* Initialize the info structure (old interface - NOT DLL EXPORTED) */
extern void png_info_init PNGARG((png_infop info_ptr));
/* Initialize the info structure (old interface - DEPRECATED) */
extern PNG_EXPORT(void,png_info_init) PNGARG((png_infop info_ptr));
#undef png_info_init
#define png_info_init(info_ptr) png_info_init_3(&info_ptr, sizeof(png_info));
extern PNG_EXPORT(void,png_info_init_3) PNGARG((png_infopp info_ptr,
png_size_t png_info_struct_size));
/* Writes all the PNG information before the image. */
extern PNG_EXPORT(void,png_write_info_before_PLTE) PNGARG((png_structp png_ptr,
@ -1436,11 +1546,11 @@ extern PNG_EXPORT(void,png_start_read_image) PNGARG((png_structp png_ptr));
extern PNG_EXPORT(void,png_read_update_info) PNGARG((png_structp png_ptr,
png_infop info_ptr));
/* read a one or more rows of image data.*/
/* read one or more rows of image data. */
extern PNG_EXPORT(void,png_read_rows) PNGARG((png_structp png_ptr,
png_bytepp row, png_bytepp display_row, png_uint_32 num_rows));
/* read a row of data.*/
/* read a row of data. */
extern PNG_EXPORT(void,png_read_row) PNGARG((png_structp png_ptr,
png_bytep row,
png_bytep display_row));
@ -1485,9 +1595,6 @@ extern void png_read_destroy PNGARG((png_structp png_ptr, png_infop info_ptr,
extern PNG_EXPORT(void,png_destroy_write_struct)
PNGARG((png_structpp png_ptr_ptr, png_infopp info_ptr_ptr));
/* free any memory used in info_ptr struct (old method - NOT DLL EXPORTED) */
extern void png_write_destroy_info PNGARG((png_infop info_ptr));
/* free any memory used in png_ptr struct (old method - NOT DLL EXPORTED) */
extern void png_write_destroy PNGARG((png_structp png_ptr));
@ -1695,7 +1802,7 @@ extern PNG_EXPORT(png_voidp,png_get_user_transform_ptr)
PNGARG((png_structp png_ptr));
#endif
#ifdef PNG_READ_USER_CHUNKS_SUPPORTED
#ifdef PNG_USER_CHUNKS_SUPPORTED
extern PNG_EXPORT(void,png_set_read_user_chunk_fn) PNGARG((png_structp png_ptr,
png_voidp user_chunk_ptr, png_user_chunk_ptr read_user_chunk_fn));
extern PNG_EXPORT(png_voidp,png_get_user_chunk_ptr) PNGARG((png_structp
@ -1729,9 +1836,26 @@ extern PNG_EXPORT(void,png_progressive_combine_row) PNGARG((png_structp png_ptr,
extern PNG_EXPORT(png_voidp,png_malloc) PNGARG((png_structp png_ptr,
png_uint_32 size));
#if defined(PNG_1_0_X)
# define png_malloc_warn png_malloc
#else
/* Added at libpng version 1.2.4 */
extern PNG_EXPORT(png_voidp,png_malloc_warn) PNGARG((png_structp png_ptr,
png_uint_32 size));
#endif
/* frees a pointer allocated by png_malloc() */
extern PNG_EXPORT(void,png_free) PNGARG((png_structp png_ptr, png_voidp ptr));
#if defined(PNG_1_0_X)
/* Function to allocate memory for zlib. */
extern PNG_EXPORT(voidpf,png_zalloc) PNGARG((voidpf png_ptr, uInt items,
uInt size));
/* Function to free memory for zlib */
extern PNG_EXPORT(void,png_zfree) PNGARG((voidpf png_ptr, voidpf ptr));
#endif
/* Free data that was allocated internally */
extern PNG_EXPORT(void,png_free_data) PNGARG((png_structp png_ptr,
png_infop info_ptr, png_uint_32 free_me, int num));
@ -1780,19 +1904,19 @@ extern void *png_far_to_near PNGARG((png_structp png_ptr,png_voidp ptr,
/* Fatal error in PNG image of libpng - can't continue */
extern PNG_EXPORT(void,png_error) PNGARG((png_structp png_ptr,
png_const_charp error));
png_const_charp error_message));
/* The same, but the chunk name is prepended to the error string. */
extern PNG_EXPORT(void,png_chunk_error) PNGARG((png_structp png_ptr,
png_const_charp error));
png_const_charp error_message));
/* Non-fatal error in libpng. Can continue, but may have a problem. */
extern PNG_EXPORT(void,png_warning) PNGARG((png_structp png_ptr,
png_const_charp message));
png_const_charp warning_message));
/* Non-fatal error in libpng, chunk name is prepended to message. */
extern PNG_EXPORT(void,png_chunk_warning) PNGARG((png_structp png_ptr,
png_const_charp message));
png_const_charp warning_message));
/* The png_set_<chunk> functions are for storing values in the png_info_struct.
* Similarly, the png_get_<chunk> calls are used to read values from the
@ -1888,7 +2012,7 @@ png_ptr, png_infop info_ptr));
extern PNG_EXPORT(png_bytep,png_get_signature) PNGARG((png_structp png_ptr,
png_infop info_ptr));
#if defined(PNG_READ_bKGD_SUPPORTED)
#if defined(PNG_bKGD_SUPPORTED)
extern PNG_EXPORT(png_uint_32,png_get_bKGD) PNGARG((png_structp png_ptr,
png_infop info_ptr, png_color_16p *background));
#endif
@ -1898,7 +2022,7 @@ extern PNG_EXPORT(void,png_set_bKGD) PNGARG((png_structp png_ptr,
png_infop info_ptr, png_color_16p background));
#endif
#if defined(PNG_READ_cHRM_SUPPORTED)
#if defined(PNG_cHRM_SUPPORTED)
#ifdef PNG_FLOATING_POINT_SUPPORTED
extern PNG_EXPORT(png_uint_32,png_get_cHRM) PNGARG((png_structp png_ptr,
png_infop info_ptr, double *white_x, double *white_y, double *red_x,
@ -1929,7 +2053,7 @@ extern PNG_EXPORT(void,png_set_cHRM_fixed) PNGARG((png_structp png_ptr,
#endif
#endif
#if defined(PNG_READ_gAMA_SUPPORTED)
#if defined(PNG_gAMA_SUPPORTED)
#ifdef PNG_FLOATING_POINT_SUPPORTED
extern PNG_EXPORT(png_uint_32,png_get_gAMA) PNGARG((png_structp png_ptr,
png_infop info_ptr, double *file_gamma));
@ -1947,7 +2071,7 @@ extern PNG_EXPORT(void,png_set_gAMA_fixed) PNGARG((png_structp png_ptr,
png_infop info_ptr, png_fixed_point int_file_gamma));
#endif
#if defined(PNG_READ_hIST_SUPPORTED)
#if defined(PNG_hIST_SUPPORTED)
extern PNG_EXPORT(png_uint_32,png_get_hIST) PNGARG((png_structp png_ptr,
png_infop info_ptr, png_uint_16p *hist));
#endif
@ -1967,7 +2091,7 @@ extern PNG_EXPORT(void,png_set_IHDR) PNGARG((png_structp png_ptr,
int color_type, int interlace_method, int compression_method,
int filter_method));
#if defined(PNG_READ_oFFs_SUPPORTED)
#if defined(PNG_oFFs_SUPPORTED)
extern PNG_EXPORT(png_uint_32,png_get_oFFs) PNGARG((png_structp png_ptr,
png_infop info_ptr, png_int_32 *offset_x, png_int_32 *offset_y,
int *unit_type));
@ -1979,7 +2103,7 @@ extern PNG_EXPORT(void,png_set_oFFs) PNGARG((png_structp png_ptr,
int unit_type));
#endif
#if defined(PNG_READ_pCAL_SUPPORTED)
#if defined(PNG_pCAL_SUPPORTED)
extern PNG_EXPORT(png_uint_32,png_get_pCAL) PNGARG((png_structp png_ptr,
png_infop info_ptr, png_charp *purpose, png_int_32 *X0, png_int_32 *X1,
int *type, int *nparams, png_charp *units, png_charpp *params));
@ -1991,7 +2115,7 @@ extern PNG_EXPORT(void,png_set_pCAL) PNGARG((png_structp png_ptr,
int type, int nparams, png_charp units, png_charpp params));
#endif
#if defined(PNG_READ_pHYs_SUPPORTED)
#if defined(PNG_pHYs_SUPPORTED)
extern PNG_EXPORT(png_uint_32,png_get_pHYs) PNGARG((png_structp png_ptr,
png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type));
#endif
@ -2007,7 +2131,7 @@ extern PNG_EXPORT(png_uint_32,png_get_PLTE) PNGARG((png_structp png_ptr,
extern PNG_EXPORT(void,png_set_PLTE) PNGARG((png_structp png_ptr,
png_infop info_ptr, png_colorp palette, int num_palette));
#if defined(PNG_READ_sBIT_SUPPORTED)
#if defined(PNG_sBIT_SUPPORTED)
extern PNG_EXPORT(png_uint_32,png_get_sBIT) PNGARG((png_structp png_ptr,
png_infop info_ptr, png_color_8p *sig_bit));
#endif
@ -2017,7 +2141,7 @@ extern PNG_EXPORT(void,png_set_sBIT) PNGARG((png_structp png_ptr,
png_infop info_ptr, png_color_8p sig_bit));
#endif
#if defined(PNG_READ_sRGB_SUPPORTED)
#if defined(PNG_sRGB_SUPPORTED)
extern PNG_EXPORT(png_uint_32,png_get_sRGB) PNGARG((png_structp png_ptr,
png_infop info_ptr, int *intent));
#endif
@ -2029,7 +2153,7 @@ extern PNG_EXPORT(void,png_set_sRGB_gAMA_and_cHRM) PNGARG((png_structp png_ptr,
png_infop info_ptr, int intent));
#endif
#if defined(PNG_READ_iCCP_SUPPORTED)
#if defined(PNG_iCCP_SUPPORTED)
extern PNG_EXPORT(png_uint_32,png_get_iCCP) PNGARG((png_structp png_ptr,
png_infop info_ptr, png_charpp name, int *compression_type,
png_charpp profile, png_uint_32 *proflen));
@ -2043,7 +2167,7 @@ extern PNG_EXPORT(void,png_set_iCCP) PNGARG((png_structp png_ptr,
/* Note to maintainer: profile should be png_bytep */
#endif
#if defined(PNG_READ_sPLT_SUPPORTED)
#if defined(PNG_sPLT_SUPPORTED)
extern PNG_EXPORT(png_uint_32,png_get_sPLT) PNGARG((png_structp png_ptr,
png_infop info_ptr, png_sPLT_tpp entries));
#endif
@ -2053,7 +2177,7 @@ extern PNG_EXPORT(void,png_set_sPLT) PNGARG((png_structp png_ptr,
png_infop info_ptr, png_sPLT_tp entries, int nentries));
#endif
#if defined(PNG_READ_TEXT_SUPPORTED)
#if defined(PNG_TEXT_SUPPORTED)
/* png_get_text also returns the number of text chunks in *num_text */
extern PNG_EXPORT(png_uint_32,png_get_text) PNGARG((png_structp png_ptr,
png_infop info_ptr, png_textp *text_ptr, int *num_text));
@ -2072,7 +2196,7 @@ extern PNG_EXPORT(void,png_set_text) PNGARG((png_structp png_ptr,
png_infop info_ptr, png_textp text_ptr, int num_text));
#endif
#if defined(PNG_READ_tIME_SUPPORTED)
#if defined(PNG_tIME_SUPPORTED)
extern PNG_EXPORT(png_uint_32,png_get_tIME) PNGARG((png_structp png_ptr,
png_infop info_ptr, png_timep *mod_time));
#endif
@ -2082,7 +2206,7 @@ extern PNG_EXPORT(void,png_set_tIME) PNGARG((png_structp png_ptr,
png_infop info_ptr, png_timep mod_time));
#endif
#if defined(PNG_READ_tRNS_SUPPORTED)
#if defined(PNG_tRNS_SUPPORTED)
extern PNG_EXPORT(png_uint_32,png_get_tRNS) PNGARG((png_structp png_ptr,
png_infop info_ptr, png_bytep *trans, int *num_trans,
png_color_16p *trans_values));
@ -2097,7 +2221,7 @@ extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr,
#if defined(PNG_tRNS_SUPPORTED)
#endif
#if defined(PNG_READ_sCAL_SUPPORTED)
#if defined(PNG_sCAL_SUPPORTED)
#ifdef PNG_FLOATING_POINT_SUPPORTED
extern PNG_EXPORT(png_uint_32,png_get_sCAL) PNGARG((png_structp png_ptr,
png_infop info_ptr, int *unit, double *width, double *height));
@ -2107,7 +2231,7 @@ extern PNG_EXPORT(png_uint_32,png_get_sCAL_s) PNGARG((png_structp png_ptr,
png_infop info_ptr, int *unit, png_charpp swidth, png_charpp sheight));
#endif
#endif
#endif /* PNG_READ_sCAL_SUPPORTED */
#endif /* PNG_sCAL_SUPPORTED */
#if defined(PNG_sCAL_SUPPORTED)
#ifdef PNG_FLOATING_POINT_SUPPORTED
@ -2118,7 +2242,7 @@ extern PNG_EXPORT(void,png_set_sCAL) PNGARG((png_structp png_ptr,
extern PNG_EXPORT(void,png_set_sCAL_s) PNGARG((png_structp png_ptr,
png_infop info_ptr, int unit, png_charp swidth, png_charp sheight));
#endif
#endif /* PNG_READ_sCAL_SUPPORTED || PNG_WRITE_sCAL_SUPPORTED */
#endif /* PNG_sCAL_SUPPORTED || PNG_WRITE_sCAL_SUPPORTED */
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
/* provide a list of chunks and how they are to be handled, if the built-in
@ -2139,6 +2263,10 @@ extern PNG_EXPORT(void, png_set_unknown_chunk_location)
extern PNG_EXPORT(png_uint_32,png_get_unknown_chunks) PNGARG((png_structp
png_ptr, png_infop info_ptr, png_unknown_chunkpp entries));
#endif
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
PNG_EXPORT(int,png_handle_as_unknown) PNGARG((png_structp png_ptr, png_bytep
chunk_name));
#endif
/* Png_free_data() will turn off the "valid" flag for anything it frees.
If you need to turn it off for a chunk that your application has freed,
@ -2221,15 +2349,84 @@ extern PNG_EXPORT(png_uint_32,png_permit_mng_features) PNGARG((png_structp
png_ptr, png_uint_32 mng_features_permitted));
#endif
#if 0 /* delay these until version 1.2.0 */
/* Added to version 1.2.0 */
#if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
#define PNG_ASM_FLAG_MMX_SUPPORT_COMPILED 0x01 /* not user-settable */
#define PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU 0x02 /* not user-settable */
#define PNG_ASM_FLAG_MMX_READ_COMBINE_ROW 0x04
#define PNG_ASM_FLAG_MMX_READ_INTERLACE 0x08
#define PNG_ASM_FLAG_MMX_READ_FILTER_SUB 0x10
#define PNG_ASM_FLAG_MMX_READ_FILTER_UP 0x20
#define PNG_ASM_FLAG_MMX_READ_FILTER_AVG 0x40
#define PNG_ASM_FLAG_MMX_READ_FILTER_PAETH 0x80
#define PNG_ASM_FLAGS_INITIALIZED 0x80000000 /* not user-settable */
#define PNG_MMX_READ_FLAGS ( PNG_ASM_FLAG_MMX_READ_COMBINE_ROW \
| PNG_ASM_FLAG_MMX_READ_INTERLACE \
| PNG_ASM_FLAG_MMX_READ_FILTER_SUB \
| PNG_ASM_FLAG_MMX_READ_FILTER_UP \
| PNG_ASM_FLAG_MMX_READ_FILTER_AVG \
| PNG_ASM_FLAG_MMX_READ_FILTER_PAETH )
#define PNG_MMX_WRITE_FLAGS ( 0 )
#define PNG_MMX_FLAGS ( PNG_ASM_FLAG_MMX_SUPPORT_COMPILED \
| PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU \
| PNG_MMX_READ_FLAGS \
| PNG_MMX_WRITE_FLAGS )
#define PNG_SELECT_READ 1
#define PNG_SELECT_WRITE 2
#if !defined(PNG_1_0_X)
/* pngget.c */
extern PNG_EXPORT(png_uint_32,png_get_mmx_flagmask)
PNGARG((int flag_select, int *compilerID));
/* pngget.c */
extern PNG_EXPORT(png_uint_32,png_get_asm_flagmask)
PNGARG((int flag_select));
/* pngget.c */
extern PNG_EXPORT(png_uint_32,png_get_asm_flags)
PNGARG((png_structp png_ptr));
/* pngget.c */
extern PNG_EXPORT(png_byte,png_get_mmx_bitdepth_threshold)
PNGARG((png_structp png_ptr));
/* pngget.c */
extern PNG_EXPORT(png_uint_32,png_get_mmx_rowbytes_threshold)
PNGARG((png_structp png_ptr));
/* pngset.c */
extern PNG_EXPORT(void,png_set_asm_flags)
PNGARG((png_structp png_ptr, png_uint_32 asm_flags));
/* pngset.c */
extern PNG_EXPORT(void,png_set_mmx_thresholds)
PNGARG((png_structp png_ptr, png_byte mmx_bitdepth_threshold,
png_uint_32 mmx_rowbytes_threshold));
#endif /* PNG_1_0_X */
#endif /* PNG_ASSEMBLER_CODE_SUPPORTED */
#if !defined(PNG_1_0_X)
/* png.c, pnggccrd.c, or pngvcrd.c */
extern PNG_EXPORT(int,png_mmx_support) PNGARG((void));
/* Strip the prepended error numbers ("#nnn ") from error and warning
* messages before passing them to the error or warning handler. */
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
extern PNG_EXPORT(void,png_set_strip_error_numbers) PNGARG((png_structp
png_ptr, png_uint_32 strip_mode));
#endif
#endif /* PNG_1_0_X */
/* Maintainer: Put new public prototypes here ^, in libpng.3, and project defs */
#define PNG_HEADER_VERSION_STRING \
" libpng version 1.0.9 - January 31, 2001 (header)\n"
" libpng version 1.2.5 - October 2, 2002 (header)\n"
#ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED
/* With these routines we avoid an integer divide, which will be slower on
@ -2352,6 +2549,9 @@ extern PNG_EXPORT(int,png_mmx_support) PNGARG((void));
#define PNG_FLAG_KEEP_UNKNOWN_CHUNKS 0x8000L
#define PNG_FLAG_KEEP_UNSAFE_CHUNKS 0x10000L
#define PNG_FLAG_LIBRARY_MISMATCH 0x20000L
#define PNG_FLAG_STRIP_ERROR_NUMBERS 0x40000L
#define PNG_FLAG_STRIP_ERROR_TEXT 0x80000L
#define PNG_FLAG_MALLOC_NULL_MEM_OK 0x100000L
/* For use in png_set_keep_unknown, png_handle_as_unknown */
#define HANDLE_CHUNK_AS_DEFAULT 0
@ -2443,13 +2643,13 @@ PNG_EXPORT_VAR (const png_byte FARDATA) png_zTXt[5];
* values, which is almost certainly true.
*/
#if defined(PNG_READ_BIG_ENDIAN_SUPPORTED)
# if defined(PNG_READ_pCAL_SUPPORTED) || defined(PNG_READ_oFFs_SUPPORTED)
# if defined(PNG_pCAL_SUPPORTED) || defined(PNG_oFFs_SUPPORTED)
# define png_get_int_32(buf) ( *((png_int_32p) (buf)))
# endif
# define png_get_uint_32(buf) ( *((png_uint_32p) (buf)))
# define png_get_uint_16(buf) ( *((png_uint_16p) (buf)))
#else
# if defined(PNG_READ_pCAL_SUPPORTED) || defined(PNG_READ_oFFs_SUPPORTED)
# if defined(PNG_pCAL_SUPPORTED) || defined(PNG_oFFs_SUPPORTED)
PNG_EXTERN png_int_32 png_get_int_32 PNGARG((png_bytep buf));
# endif
PNG_EXTERN png_uint_32 png_get_uint_32 PNGARG((png_bytep buf));
@ -2460,8 +2660,11 @@ PNG_EXTERN png_uint_16 png_get_uint_16 PNGARG((png_bytep buf));
* (old interface - DEPRECATED - use png_create_read_struct instead).
*/
extern PNG_EXPORT(void,png_read_init) PNGARG((png_structp png_ptr));
#define png_read_init(png_ptr) png_read_init_2(png_ptr, \
PNG_LIBPNG_VER_STRING, sizeof(png_struct), sizeof(png_info));
#undef png_read_init
#define png_read_init(png_ptr) png_read_init_3(&png_ptr, \
PNG_LIBPNG_VER_STRING, sizeof(png_struct));
extern PNG_EXPORT(void,png_read_init_3) PNGARG((png_structpp ptr_ptr,
png_const_charp user_png_ver, png_size_t png_struct_size));
extern PNG_EXPORT(void,png_read_init_2) PNGARG((png_structp png_ptr,
png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t
png_info_size));
@ -2470,8 +2673,11 @@ extern PNG_EXPORT(void,png_read_init_2) PNGARG((png_structp png_ptr,
* (old interface - DEPRECATED - use png_create_write_struct instead).
*/
extern PNG_EXPORT(void,png_write_init) PNGARG((png_structp png_ptr));
#define png_write_init(png_ptr) png_write_init_2(png_ptr, \
PNG_LIBPNG_VER_STRING, sizeof(png_struct), sizeof(png_info));
#undef png_write_init
#define png_write_init(png_ptr) png_write_init_3(&png_ptr, \
PNG_LIBPNG_VER_STRING, sizeof(png_struct));
extern PNG_EXPORT(void,png_write_init_3) PNGARG((png_structpp ptr_ptr,
png_const_charp user_png_ver, png_size_t png_struct_size));
extern PNG_EXPORT(void,png_write_init_2) PNGARG((png_structp png_ptr,
png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t
png_info_size));
@ -2483,20 +2689,47 @@ PNG_EXTERN png_voidp png_create_struct PNGARG((int type));
PNG_EXTERN void png_destroy_struct PNGARG((png_voidp struct_ptr));
PNG_EXTERN png_voidp png_create_struct_2 PNGARG((int type, png_malloc_ptr
malloc_fn));
malloc_fn, png_voidp mem_ptr));
PNG_EXTERN void png_destroy_struct_2 PNGARG((png_voidp struct_ptr,
png_free_ptr free_fn));
png_free_ptr free_fn, png_voidp mem_ptr));
/* Free any memory that info_ptr points to and reset struct. */
PNG_EXTERN void png_info_destroy PNGARG((png_structp png_ptr,
png_infop info_ptr));
#ifndef PNG_1_0_X
/* Function to allocate memory for zlib. */
PNG_EXTERN voidpf png_zalloc PNGARG((voidpf png_ptr, uInt items, uInt size));
/* Function to free memory for zlib */
PNG_EXTERN void png_zfree PNGARG((voidpf png_ptr, voidpf ptr));
/* Next four functions are used internally as callbacks. PNGAPI is required
* but not PNG_EXPORT. PNGAPI added at libpng version 1.2.3. */
PNG_EXTERN void PNGAPI png_default_read_data PNGARG((png_structp png_ptr,
png_bytep data, png_size_t length));
#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
PNG_EXTERN void PNGAPI png_push_fill_buffer PNGARG((png_structp png_ptr,
png_bytep buffer, png_size_t length));
#endif
PNG_EXTERN void PNGAPI png_default_write_data PNGARG((png_structp png_ptr,
png_bytep data, png_size_t length));
#if defined(PNG_WRITE_FLUSH_SUPPORTED)
#if !defined(PNG_NO_STDIO)
PNG_EXTERN void PNGAPI png_default_flush PNGARG((png_structp png_ptr));
#endif
#endif
#else /* PNG_1_0_X */
#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
PNG_EXTERN void png_push_fill_buffer PNGARG((png_structp png_ptr,
png_bytep buffer, png_size_t length));
#endif
#endif /* PNG_1_0_X */
/* Reset the CRC variable */
PNG_EXTERN void png_reset_crc PNGARG((png_structp png_ptr));
@ -2513,8 +2746,8 @@ PNG_EXTERN void png_crc_read PNGARG((png_structp png_ptr, png_bytep buf,
png_size_t length));
/* Decompress data in a chunk that uses compression */
#if defined(PNG_READ_zTXt_SUPPORTED) || defined(PNG_READ_iTXt_SUPPORTED) || \
defined(PNG_READ_iCCP_SUPPORTED) || defined(PNG_READ_sPLT_SUPPORTED)
#if defined(PNG_zTXt_SUPPORTED) || defined(PNG_iTXt_SUPPORTED) || \
defined(PNG_iCCP_SUPPORTED) || defined(PNG_sPLT_SUPPORTED)
PNG_EXTERN png_charp png_decompress_chunk PNGARG((png_structp png_ptr,
int comp_type, png_charp chunkdata, png_size_t chunklength,
png_size_t prefix_length, png_size_t *data_length));
@ -2537,13 +2770,14 @@ PNG_EXTERN void png_calculate_crc PNGARG((png_structp png_ptr, png_bytep ptr,
PNG_EXTERN void png_flush PNGARG((png_structp png_ptr));
#endif
/* Place a 32-bit number into a buffer in PNG byte order (big-endian).
* The only currently known PNG chunks that use signed numbers are
* the ancillary extension chunks, oFFs and pCAL.
*/
PNG_EXTERN void png_save_uint_32 PNGARG((png_bytep buf, png_uint_32 i));
#if defined(PNG_WRITE_pCAL_SUPPORTED)
#if defined(PNG_WRITE_pCAL_SUPPORTED) || defined(PNG_WRITE_oFFs_SUPPORTED)
PNG_EXTERN void png_save_int_32 PNGARG((png_bytep buf, png_int_32 i));
#endif
@ -2659,9 +2893,14 @@ PNG_EXTERN void png_write_iTXt PNGARG((png_structp png_ptr,
png_charp text));
#endif
#if defined(PNG_TEXT_SUPPORTED) /* Added at version 1.0.14 and 1.2.4 */
PNG_EXTERN int png_set_text_2 PNGARG((png_structp png_ptr,
png_infop info_ptr, png_textp text_ptr, int num_text));
#endif
#if defined(PNG_WRITE_oFFs_SUPPORTED)
PNG_EXTERN void png_write_oFFs PNGARG((png_structp png_ptr,
png_uint_32 x_offset, png_uint_32 y_offset, int unit_type));
png_int_32 x_offset, png_int_32 y_offset, int unit_type));
#endif
#if defined(PNG_WRITE_pCAL_SUPPORTED)
@ -2709,7 +2948,7 @@ PNG_EXTERN void png_combine_row PNGARG((png_structp png_ptr, png_bytep row,
#if defined(PNG_READ_INTERLACING_SUPPORTED)
/* expand an interlaced row */
/* OLD interface:
/* OLD pre-1.0.9 interface:
PNG_EXTERN void png_do_read_interlace PNGARG((png_row_infop row_info,
png_bytep row, int pass, png_uint_32 transformations));
*/
@ -2836,12 +3075,17 @@ PNG_EXTERN void png_do_shift PNGARG((png_row_infop row_info, png_bytep row,
#endif
#if defined(PNG_READ_BACKGROUND_SUPPORTED)
#if defined(PNG_READ_GAMMA_SUPPORTED)
PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row,
png_color_16p trans_values, png_color_16p background,
png_color_16p background_1,
png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1,
png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1,
png_uint_16pp gamma_16_to_1, int gamma_shift));
#else
PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row,
png_color_16p trans_values, png_color_16p background));
#endif
#endif
#if defined(PNG_READ_GAMMA_SUPPORTED)
@ -2954,11 +3198,6 @@ PNG_EXTERN void png_handle_zTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
png_uint_32 length));
#endif
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
PNG_EXTERN int png_handle_as_unknown PNGARG((png_structp png_ptr, png_bytep
chunk_name));
#endif
PNG_EXTERN void png_handle_unknown PNGARG((png_structp png_ptr,
png_infop info_ptr, png_uint_32 length));
@ -2980,8 +3219,6 @@ PNG_EXTERN void png_push_check_crc PNGARG((png_structp png_ptr));
PNG_EXTERN void png_push_crc_skip PNGARG((png_structp png_ptr,
png_uint_32 length));
PNG_EXTERN void png_push_crc_finish PNGARG((png_structp png_ptr));
PNG_EXTERN void png_push_fill_buffer PNGARG((png_structp png_ptr,
png_bytep buffer, png_size_t length));
PNG_EXTERN void png_push_save_buffer PNGARG((png_structp png_ptr));
PNG_EXTERN void png_push_restore_buffer PNGARG((png_structp png_ptr,
png_bytep buffer, png_size_t buffer_length));
@ -3029,6 +3266,10 @@ PNG_EXTERN void png_do_write_intrapixel PNGARG((png_row_infop row_info,
png_bytep row));
#endif
#if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
/* png.c */ /* PRIVATE */
PNG_EXTERN void png_init_mmx_flags PNGARG((png_structp png_ptr));
#endif
/* Maintainer: Put new private prototypes here ^ and in libpngpf.3 */
#endif /* PNG_INTERNAL */

Просмотреть файл

@ -1,11 +0,0 @@
/* pngasmrd.h - assembler version of utilities to read a PNG file
*
* libpng 1.0.9 - January 31, 2001
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 2001 Glenn Randers-Pehrson
*
*/
/* This file is obsolete in libpng-1.0.9 and later; its contents now appear
* at the end of pngconf.h.
*/

Просмотреть файл

@ -1,8 +1,8 @@
/* pngconf.h - machine configurable file for libpng
*
* libpng 1.0.9 - January 31, 2001
* libpng 1.2.5 - October 2, 2002
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2001 Glenn Randers-Pehrson
* Copyright (c) 1998-2002 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*/
@ -33,8 +33,30 @@
# define PNG_ZBUF_SIZE 8192
#endif
/* Enable if you want a write-only libpng */
#ifndef PNG_NO_READ_SUPPORTED
# define PNG_READ_SUPPORTED
#endif
/* Enable if you want a read-only libpng */
#ifndef PNG_NO_WRITE_SUPPORTED
# define PNG_WRITE_SUPPORTED
#endif
/* Enabled by default in 1.2.0. You can disable this if you don't need to
support PNGs that are embedded in MNG datastreams */
#if !defined(PNG_1_0_X) && !defined(PNG_NO_MNG_FEATURES)
# ifndef PNG_MNG_FEATURES_SUPPORTED
# define PNG_MNG_FEATURES_SUPPORTED
# endif
#endif
#ifndef PNG_NO_FLOATING_POINT_SUPPORTED
# define PNG_FLOATING_POINT_SUPPORTED
# ifndef PNG_FLOATING_POINT_SUPPORTED
# define PNG_FLOATING_POINT_SUPPORTED
# endif
#endif
/* If you are running on a machine where you cannot allocate more
@ -56,58 +78,77 @@
* (no define) -- building static library, or building an
* application and linking to the static lib
* 'Cygwin' defines/defaults:
* PNG_BUILD_DLL -- building the dll
* (no define) -- building an application, linking to the dll
* PNG_STATIC -- building the static lib, or building an application
* that links to the static lib.
* ALL_STATIC -- building various static libs, or building an application
* that links to the static libs.
* PNG_BUILD_DLL -- (ignored) building the dll
* (no define) -- (ignored) building an application, linking to the dll
* PNG_STATIC -- (ignored) building the static lib, or building an
* application that links to the static lib.
* ALL_STATIC -- (ignored) building various static libs, or building an
* application that links to the static libs.
* Thus,
* a cygwin user should define either PNG_BUILD_DLL or PNG_STATIC, and
* this bit of #ifdefs will define the 'correct' config variables based on
* that. If a cygwin user *wants* to define 'PNG_USE_DLL' that's okay, but
* unnecessary.
*
* Also, the precedence order is:
* ALL_STATIC (since we can't #undef something outside our namespace)
* PNG_BUILD_DLL
* PNG_STATIC
* (nothing) == PNG_USE_DLL
*
* CYGWIN (2002-01-20): The preceding is now obsolete. With the advent
* of auto-import in binutils, we no longer need to worry about
* __declspec(dllexport) / __declspec(dllimport) and friends. Therefore,
* we don't need to worry about PNG_STATIC or ALL_STATIC when it comes
* to __declspec() stuff. However, we DO need to worry about
* PNG_BUILD_DLL and PNG_STATIC because those change some defaults
* such as CONSOLE_IO and whether GLOBAL_ARRAYS are allowed.
*/
#if defined(__CYGWIN__)
# if defined(PNG_BUILD_DLL)
# if defined(ALL_STATIC)
# if defined(PNG_BUILD_DLL)
# undef PNG_BUILD_DLL
# endif
# if defined(PNG_USE_DLL)
# undef PNG_USE_DLL
# endif
# if !defined(PNG_DLL)
# define PNG_DLL
# if defined(PNG_DLL)
# undef PNG_DLL
# endif
# if defined(PNG_STATIC)
# undef PNG_STATIC
# endif
# else
# if defined(ALL_STATIC)
# if !defined(PNG_STATIC)
# define PNG_STATIC
# endif
# if defined(PNG_STATIC)
# else
# if defined (PNG_BUILD_DLL)
# if defined(PNG_STATIC)
# undef PNG_STATIC
# endif
# if defined(PNG_USE_DLL)
# undef PNG_USE_DLL
# endif
# if defined(PNG_DLL)
# undef PNG_DLL
# if !defined(PNG_DLL)
# define PNG_DLL
# endif
# else
# if defined(PNG_USE_DLL)
# if defined(PNG_STATIC)
# if defined(PNG_USE_DLL)
# undef PNG_USE_DLL
# endif
# if defined(PNG_DLL)
# undef PNG_DLL
# endif
# else
# if !defined(PNG_USE_DLL)
# define PNG_USE_DLL
# endif
# if !defined(PNG_DLL)
# define PNG_DLL
# endif
# else
# if defined(PNG_DLL)
# define PNG_USE_DLL
# else
# define PNG_USE_DLL
# define PNG_DLL
# endif
# endif
# endif
# endif
# endif
# endif
#endif
/* This protects us against compilers that run on a windowing system
* and thus don't have or would rather us not use the stdio types:
* stdin, stdout, and stderr. The only one currently used is stderr
@ -169,6 +210,9 @@
#ifdef _NO_PROTO
# define PNGARG(arglist) ()
# ifndef PNG_TYPECAST_NULL
# define PNG_TYPECAST_NULL
# endif
#else
# define PNGARG(arglist) arglist
#endif /* _NO_PROTO */
@ -193,7 +237,7 @@
# include <sys/types.h>
#endif
#ifndef PNG_SETJMP_NOT_SUPPORTED
#if !defined(PNG_SETJMP_NOT_SUPPORTED) && !defined(PNG_NO_SETJMP_SUPPORTED)
# define PNG_SETJMP_SUPPORTED
#endif
@ -224,12 +268,6 @@
# endif /* __linux__ */
#endif /* PNG_SETJMP_SUPPORTED */
#if defined(_AIX) && defined(__xlC__)
/* This prevents "AIX/xlC" from generating an "index(s,c)" macro in strings.h
* that conflicts with libpng's png_color_16.index */
# undef __STR__
#endif
#ifdef BSD
# include <strings.h>
#else
@ -288,7 +326,8 @@
# include "alloc.h"
#endif
#ifdef _MSC_VER
#if defined(_MSC_VER) && (defined(WIN32) || defined(_Windows) || \
defined(_WINDOWS) || defined(_WIN32) || defined(__WIN32__))
# include <malloc.h>
#endif
@ -367,14 +406,14 @@
* iTXt is supported. It is turned off by default, to support old apps
* that malloc the png_text structure instead of calling png_set_text()
* and letting libpng malloc it. It will be turned on by default in
* libpng-2.0.0.
* libpng-1.3.0.
*/
#ifndef PNG_iTXt_SUPPORTED
# ifndef PNG_READ_iTXt_SUPPORTED
# if !defined(PNG_READ_iTXt_SUPPORTED) && !defined(PNG_NO_READ_iTXt)
# define PNG_NO_READ_iTXt
# endif
# ifndef PNG_WRITE_iTXt_SUPPORTED
# if !defined(PNG_WRITE_iTXt_SUPPORTED) && !defined(PNG_NO_WRITE_iTXt)
# define PNG_NO_WRITE_iTXt
# endif
#endif
@ -418,14 +457,12 @@
# define PNG_FREE_ME_SUPPORTED
#endif
#if defined(PNG_READ_SUPPORTED)
#if !defined(PNG_READ_TRANSFORMS_NOT_SUPPORTED) && \
!defined(PNG_NO_READ_TRANSFORMS)
!defined(PNG_NO_READ_TRANSFORMS)
# define PNG_READ_TRANSFORMS_SUPPORTED
#endif
#if !defined(PNG_WRITE_TRANSFORMS_NOT_SUPPORTED) && \
!defined(PNG_NO_WRITE_TRANSFORMS)
# define PNG_WRITE_TRANSFORMS_SUPPORTED
#endif
#ifdef PNG_READ_TRANSFORMS_SUPPORTED
# ifndef PNG_NO_READ_EXPAND
@ -498,19 +535,21 @@
# endif
#endif
/* Enable if you need to support PNGs that are embedded in MNG
datastreams */
/*
#ifndef PNG_NO_MNG_FEATURES
# define PNG_MNG_FEATURES_SUPPORTED
#endif
*/
/* Deprecated, will be removed from version 2.0.0 */
/* Deprecated, will be removed from version 2.0.0.
Use PNG_MNG_FEATURES_SUPPORTED instead. */
#ifndef PNG_NO_READ_EMPTY_PLTE
# define PNG_READ_EMPTY_PLTE_SUPPORTED
#endif
#endif /* PNG_READ_SUPPORTED */
#if defined(PNG_WRITE_SUPPORTED)
# if !defined(PNG_WRITE_TRANSFORMS_NOT_SUPPORTED) && \
!defined(PNG_NO_WRITE_TRANSFORMS)
# define PNG_WRITE_TRANSFORMS_SUPPORTED
#endif
#ifdef PNG_WRITE_TRANSFORMS_SUPPORTED
# ifndef PNG_NO_WRITE_SHIFT
# define PNG_WRITE_SHIFT_SUPPORTED
@ -560,6 +599,12 @@
# define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
#endif
#ifndef PNG_1_0_X
#ifndef PNG_NO_ERROR_NUMBERS
#define PNG_ERROR_NUMBERS_SUPPORTED
#endif
#endif /* PNG_1_0_X */
#ifndef PNG_NO_WRITE_FLUSH
# define PNG_WRITE_FLUSH_SUPPORTED
#endif
@ -569,6 +614,8 @@
# define PNG_WRITE_EMPTY_PLTE_SUPPORTED
#endif
#endif /* PNG_WRITE_SUPPORTED */
#ifndef PNG_NO_STDIO
# define PNG_TIME_RFC1123_SUPPORTED
#endif
@ -589,36 +636,52 @@
* png_get_x_offset_microns()
* png_get_y_offset_microns()
*/
#ifndef PNG_NO_EASY_ACCESS
#if !defined(PNG_NO_EASY_ACCESS) && !defined(PNG_EASY_ACCESS_SUPPORTED)
# define PNG_EASY_ACCESS_SUPPORTED
#endif
/* PNG_ASSEMBLER_CODE will be enabled by default in version 1.2.0
/* PNG_ASSEMBLER_CODE was enabled by default in version 1.2.0
even when PNG_USE_PNGVCRD or PNG_USE_PNGGCCRD is not defined */
#ifndef PNG_NO_ASSEMBLER_CODE
# if defined(PNG_USE_PNGVCRD) || defined(PNG_USE_PNGGCCRD)
#if defined(PNG_READ_SUPPORTED) && !defined(PNG_NO_ASSEMBLER_CODE)
# ifndef PNG_ASSEMBLER_CODE_SUPPORTED
# define PNG_ASSEMBLER_CODE_SUPPORTED
# endif
# if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
# define PNG_MMX_CODE_SUPPORTED
# endif
#endif
/* If you are sure that you don't need thread safety and you are compiling
with PNG_USE_PNGCCRD for an MMX application, you can define this for
faster execution. See pnggccrd.c.
#define PNG_THREAD_UNSAFE_OK
*/
#if !defined(PNG_1_0_X)
#if !defined(PNG_NO_USER_MEM) && !defined(PNG_USER_MEM_SUPPORTED)
# define PNG_USER_MEM_SUPPORTED
#endif
#endif /* PNG_1_0_X */
/* These are currently experimental features, define them if you want */
/* very little testing */
/*
#define PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED
#ifndef PNG_NO_USER_MEM
# define PNG_USER_MEM_SUPPORTED
#endif
#ifndef PNG_NO_ZALLOC_ZERO
# define PNG_ZALLOC_ZERO
#ifdef PNG_READ_SUPPORTED
# ifndef PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED
# define PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED
# endif
#endif
*/
/* This is only for PowerPC big-endian and 680x0 systems */
/* some testing */
/*
#define PNG_READ_BIG_ENDIAN_SUPPORTED
#ifdef PNG_READ_SUPPORTED
# ifndef PNG_PNG_READ_BIG_ENDIAN_SUPPORTED
# define PNG_READ_BIG_ENDIAN_SUPPORTED
# endif
#endif
*/
/* Buggy compilers (e.g., gcc 2.7.2.2) need this */
@ -638,11 +701,14 @@
* a bit smaller.
*/
#if !defined(PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \
#if defined(PNG_READ_SUPPORTED) && \
!defined(PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \
!defined(PNG_NO_READ_ANCILLARY_CHUNKS)
# define PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
#endif
#if !defined(PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \
#if defined(PNG_WRITE_SUPPORTED) && \
!defined(PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \
!defined(PNG_NO_WRITE_ANCILLARY_CHUNKS)
# define PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
#endif
@ -675,8 +741,12 @@
# define PNG_iCCP_SUPPORTED
#endif
#ifndef PNG_NO_READ_iTXt
# define PNG_READ_iTXt_SUPPORTED
# define PNG_iTXt_SUPPORTED
# ifndef PNG_READ_iTXt_SUPPORTED
# define PNG_READ_iTXt_SUPPORTED
# endif
# ifndef PNG_iTXt_SUPPORTED
# define PNG_iTXt_SUPPORTED
# endif
#endif
#ifndef PNG_NO_READ_oFFs
# define PNG_READ_oFFs_SUPPORTED
@ -791,7 +861,9 @@
# endif
#endif
#ifndef PNG_NO_WRITE_iTXt
# define PNG_WRITE_iTXt_SUPPORTED
# ifndef PNG_WRITE_iTXt_SUPPORTED
# define PNG_WRITE_iTXt_SUPPORTED
# endif
# ifndef PNG_iTXt_SUPPORTED
# define PNG_iTXt_SUPPORTED
# endif
@ -1085,10 +1157,23 @@ typedef z_stream FAR * png_zstreamp;
# endif
#endif
#if defined(__CYGWIN__)
# undef PNGAPI
# define PNGAPI __cdecl
# undef PNG_IMPEXP
# define PNG_IMPEXP
#endif
/* If you define PNGAPI, e.g., with compiler option "-DPNGAPI=__stdcall",
* you may get warnings regarding the linkage of png_zalloc and png_zfree.
* Don't ignore those warnings; you must also reset the default calling
* convention in your compiler to match your PNGAPI, and you must build
* zlib and your applications the same way you build libpng.
*/
#ifndef PNGAPI
#if defined(__MINGW32__) || defined(__CYGWIN__) && !defined(PNG_MODULEDEF)
#if defined(__MINGW32__) && !defined(PNG_MODULEDEF)
# ifndef PNG_NO_MODULEDEF
# define PNG_NO_MODULEDEF
# endif
@ -1100,8 +1185,7 @@ typedef z_stream FAR * png_zstreamp;
#if defined(PNG_DLL) || defined(_DLL) || defined(__DLL__ ) || \
(( defined(_Windows) || defined(_WINDOWS) || \
defined(WIN32) || defined(_WIN32) || defined(__WIN32__) \
) && !defined(__CYGWIN__))
defined(WIN32) || defined(_WIN32) || defined(__WIN32__) ))
# if defined(__GNUC__) || (defined (_MSC_VER) && (_MSC_VER >= 800))
# define PNGAPI __cdecl
@ -1128,8 +1212,8 @@ typedef z_stream FAR * png_zstreamp;
# if defined(PNG_BUILD_DLL)
# define PNG_IMPEXP __export
# else
# define PNG_IMPEXP /*__import*/ /* doesn't exist AFAIK in
VC++*/
# define PNG_IMPEXP /*__import */ /* doesn't exist AFAIK in
VC++ */
# endif /* Exists in Borland C++ for
C++ classes (== huge) */
# endif
@ -1144,18 +1228,16 @@ typedef z_stream FAR * png_zstreamp;
# endif
# endif /* PNG_IMPEXP */
#else /* !(DLL || non-cygwin WINDOWS) */
# if defined(__CYGWIN__) && !defined(PNG_DLL)
# if !defined(PNG_IMPEXP)
# if (defined(__IBMC__) || defined(IBMCPP__)) && defined(__OS2__)
# define PNGAPI _System
# define PNG_IMPEXP
# endif
# define PNGAPI __cdecl
# else
# if 0 /* ... other platforms, with other meanings */
# else
# define PNGAPI
# define PNG_IMPEXP
# if 0 /* ... other platforms, with other meanings */
# else
# define PNGAPI
# define PNG_IMPEXP
# endif
# endif
# endif
#endif
#endif
@ -1221,8 +1303,9 @@ typedef z_stream FAR * png_zstreamp;
# define PNG_ZBUF_SIZE 65536
#endif
#ifdef PNG_READ_SUPPORTED
/* Prior to libpng-1.0.9, this block was in pngasmrd.h */
#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) && defined(PNG_INTERNAL)
#if defined(PNG_INTERNAL)
/* These are the default thresholds before the MMX code kicks in; if either
* rowbytes or bitdepth is below the threshold, plain C code is used. These
@ -1258,7 +1341,8 @@ typedef z_stream FAR * png_zstreamp;
#endif
/* - see pnggccrd.c for info about what is currently enabled */
#endif /* PNG_ASSEMBLER_CODE_SUPPORTED */
#endif /* PNG_INTERNAL */
#endif /* PNG_READ_SUPPORTED */
#endif /* PNGCONF_H */

Просмотреть файл

@ -1,9 +1,9 @@
/* pngerror.c - stub functions for i/o and memory allocation
*
* libpng 1.0.9 - January 31, 2001
* libpng 1.2.5 - October 2, 2002
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2001 Glenn Randers-Pehrson
* Copyright (c) 1998-2002 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*
@ -18,10 +18,10 @@
static void /* PRIVATE */
png_default_error PNGARG((png_structp png_ptr,
png_const_charp message));
png_const_charp error_message));
static void /* PRIVATE */
png_default_warning PNGARG((png_structp png_ptr,
png_const_charp message));
png_const_charp warning_message));
/* This function is called whenever there is a fatal error. This function
* should not be changed. If there is a need to handle errors differently,
@ -29,14 +29,46 @@ png_default_warning PNGARG((png_structp png_ptr,
* to replace the error function at run-time.
*/
void PNGAPI
png_error(png_structp png_ptr, png_const_charp message)
png_error(png_structp png_ptr, png_const_charp error_message)
{
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
char msg[16];
if (png_ptr->flags&(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
{
int offset = 0;
if (*error_message == '#')
{
for (offset=1; offset<15; offset++)
if (*(error_message+offset) == ' ')
break;
if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
{
int i;
for (i=0; i<offset-1; i++)
msg[i]=error_message[i+1];
msg[i]='\0';
error_message=msg;
}
else
error_message+=offset;
}
else
{
if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
{
msg[0]='0';
msg[1]='\0';
error_message=msg;
}
}
}
#endif
if (png_ptr->error_fn != NULL)
(*(png_ptr->error_fn))(png_ptr, message);
(*(png_ptr->error_fn))(png_ptr, error_message);
/* if the following returns or doesn't exist, use the default function,
which will not return */
png_default_error(png_ptr, message);
png_default_error(png_ptr, error_message);
}
/* This function is called whenever there is a non-fatal error. This function
@ -45,12 +77,25 @@ png_error(png_structp png_ptr, png_const_charp message)
* png_set_error_fn() to replace the warning function at run-time.
*/
void PNGAPI
png_warning(png_structp png_ptr, png_const_charp message)
png_warning(png_structp png_ptr, png_const_charp warning_message)
{
int offset = 0;
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
if (png_ptr->flags&(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
#endif
{
if (*warning_message == '#')
{
for (offset=1; offset<15; offset++)
if (*(warning_message+offset) == ' ')
break;
}
}
if (png_ptr->warning_fn != NULL)
(*(png_ptr->warning_fn))(png_ptr, message);
(*(png_ptr->warning_fn))(png_ptr,
(png_const_charp)(warning_message+offset));
else
png_default_warning(png_ptr, message);
png_default_warning(png_ptr, (png_const_charp)(warning_message+offset));
}
/* These utilities are used internally to build an error message that relates
@ -61,11 +106,12 @@ png_warning(png_structp png_ptr, png_const_charp message)
*/
#define isnonalpha(c) ((c) < 41 || (c) > 122 || ((c) > 90 && (c) < 97))
static PNG_CONST char png_digit[16] = {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
};
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E',
'F' };
static void /* PRIVATE */
png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp message)
png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp
error_message)
{
int iout = 0, iin = 0;
@ -85,30 +131,30 @@ png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp message
}
}
if (message == NULL)
if (error_message == NULL)
buffer[iout] = 0;
else
{
buffer[iout++] = ':';
buffer[iout++] = ' ';
png_memcpy(buffer+iout, message, 64);
png_memcpy(buffer+iout, error_message, 64);
buffer[iout+63] = 0;
}
}
void PNGAPI
png_chunk_error(png_structp png_ptr, png_const_charp message)
png_chunk_error(png_structp png_ptr, png_const_charp error_message)
{
char msg[18+64];
png_format_buffer(png_ptr, msg, message);
png_format_buffer(png_ptr, msg, error_message);
png_error(png_ptr, msg);
}
void PNGAPI
png_chunk_warning(png_structp png_ptr, png_const_charp message)
png_chunk_warning(png_structp png_ptr, png_const_charp warning_message)
{
char msg[16+64];
png_format_buffer(png_ptr, msg, message);
char msg[18+64];
png_format_buffer(png_ptr, msg, warning_message);
png_warning(png_ptr, msg);
}
@ -118,12 +164,34 @@ png_chunk_warning(png_structp png_ptr, png_const_charp message)
* error function pointer in png_set_error_fn().
*/
static void /* PRIVATE */
png_default_error(png_structp png_ptr, png_const_charp message)
png_default_error(png_structp png_ptr, png_const_charp error_message)
{
#ifndef PNG_NO_CONSOLE_IO
fprintf(stderr, "libpng error: %s\n", message);
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
if (*error_message == '#')
{
int offset;
char error_number[16];
for (offset=0; offset<15; offset++)
{
error_number[offset] = *(error_message+offset+1);
if (*(error_message+offset) == ' ')
break;
}
if((offset > 1) && (offset < 15))
{
error_number[offset-1]='\0';
fprintf(stderr, "libpng error no. %s: %s\n", error_number,
error_message+offset);
}
else
fprintf(stderr, "libpng error: %s, offset=%d\n", error_message,offset);
}
else
#endif
fprintf(stderr, "libpng error: %s\n", error_message);
#else
if (message)
if (error_message)
/* make compiler happy */ ;
#endif
@ -150,12 +218,34 @@ png_default_error(png_structp png_ptr, png_const_charp message)
* not used, but it is passed in case it may be useful.
*/
static void /* PRIVATE */
png_default_warning(png_structp png_ptr, png_const_charp message)
png_default_warning(png_structp png_ptr, png_const_charp warning_message)
{
#ifndef PNG_NO_CONSOLE_IO
fprintf(stderr, "libpng warning: %s\n", message);
# ifdef PNG_ERROR_NUMBERS_SUPPORTED
if (*warning_message == '#')
{
int offset;
char warning_number[16];
for (offset=0; offset<15; offset++)
{
warning_number[offset]=*(warning_message+offset+1);
if (*(warning_message+offset) == ' ')
break;
}
if((offset > 1) && (offset < 15))
{
warning_number[offset-1]='\0';
fprintf(stderr, "libpng warning no. %s: %s\n", warning_number,
warning_message+offset);
}
else
fprintf(stderr, "libpng warning: %s\n", warning_message);
}
else
# endif
fprintf(stderr, "libpng warning: %s\n", warning_message);
#else
if (message)
if (warning_message)
/* appease compiler */ ;
#endif
if (png_ptr)
@ -188,4 +278,14 @@ png_get_error_ptr(png_structp png_ptr)
}
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
void PNGAPI
png_set_strip_error_numbers(png_structp png_ptr, png_uint_32 strip_mode)
{
if(png_ptr != NULL)
{
png_ptr->flags &=
((~(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))&strip_mode);
}
}
#endif

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1,9 +1,9 @@
/* pngget.c - retrieval of values from info struct
*
* libpng 1.0.9 - January 31, 2001
* libpng 1.2.5 - October 2, 2002
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2001 Glenn Randers-Pehrson
* Copyright (c) 1998-2002 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*/
@ -137,7 +137,7 @@ png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
#if defined(PNG_pHYs_SUPPORTED)
if (info_ptr->valid & PNG_INFO_pHYs)
{
png_debug1(1, "in %s retrieval function\n", "png_get_y_pixels_per_meter");
png_debug1(1, "in %s retrieval function\n", "png_get_y_pixels_per_meter");
if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
return (0);
else return (info_ptr->y_pixels_per_unit);
@ -297,7 +297,7 @@ png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr)
*.00003937);
}
#if defined(PNG_READ_pHYs_SUPPORTED)
#if defined(PNG_pHYs_SUPPORTED)
png_uint_32 PNGAPI
png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr,
png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
@ -330,7 +330,7 @@ png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr,
}
return (retval);
}
#endif /* PNG_READ_pHYs_SUPPORTED */
#endif /* PNG_pHYs_SUPPORTED */
#endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
/* png_get_channels really belongs in here, too, but it's been around longer */
@ -355,7 +355,7 @@ png_get_signature(png_structp png_ptr, png_infop info_ptr)
return (NULL);
}
#if defined(PNG_READ_bKGD_SUPPORTED)
#if defined(PNG_bKGD_SUPPORTED)
png_uint_32 PNGAPI
png_get_bKGD(png_structp png_ptr, png_infop info_ptr,
png_color_16p *background)
@ -371,7 +371,7 @@ png_get_bKGD(png_structp png_ptr, png_infop info_ptr,
}
#endif
#if defined(PNG_READ_cHRM_SUPPORTED)
#if defined(PNG_cHRM_SUPPORTED)
#ifdef PNG_FLOATING_POINT_SUPPORTED
png_uint_32 PNGAPI
png_get_cHRM(png_structp png_ptr, png_infop info_ptr,
@ -435,7 +435,7 @@ png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
#endif
#endif
#if defined(PNG_READ_gAMA_SUPPORTED)
#if defined(PNG_gAMA_SUPPORTED)
#ifdef PNG_FLOATING_POINT_SUPPORTED
png_uint_32 PNGAPI
png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma)
@ -467,7 +467,7 @@ png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr,
#endif
#endif
#if defined(PNG_READ_sRGB_SUPPORTED)
#if defined(PNG_sRGB_SUPPORTED)
png_uint_32 PNGAPI
png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent)
{
@ -482,7 +482,7 @@ png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent)
}
#endif
#if defined(PNG_READ_iCCP_SUPPORTED)
#if defined(PNG_iCCP_SUPPORTED)
png_uint_32 PNGAPI
png_get_iCCP(png_structp png_ptr, png_infop info_ptr,
png_charpp name, int *compression_type,
@ -504,7 +504,7 @@ png_get_iCCP(png_structp png_ptr, png_infop info_ptr,
}
#endif
#if defined(PNG_READ_sPLT_SUPPORTED)
#if defined(PNG_sPLT_SUPPORTED)
png_uint_32 PNGAPI
png_get_sPLT(png_structp png_ptr, png_infop info_ptr,
png_sPLT_tpp spalettes)
@ -515,7 +515,7 @@ png_get_sPLT(png_structp png_ptr, png_infop info_ptr,
}
#endif
#if defined(PNG_READ_hIST_SUPPORTED)
#if defined(PNG_hIST_SUPPORTED)
png_uint_32 PNGAPI
png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist)
{
@ -547,7 +547,11 @@ png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
*width = info_ptr->width;
*height = info_ptr->height;
*bit_depth = info_ptr->bit_depth;
if (info_ptr->bit_depth < 1 || info_ptr->bit_depth > 16)
png_error(png_ptr, "Invalid bit depth");
*color_type = info_ptr->color_type;
if (info_ptr->color_type > 6)
png_error(png_ptr, "Invalid color type");
if (compression_type != NULL)
*compression_type = info_ptr->compression_type;
if (filter_type != NULL)
@ -566,6 +570,10 @@ png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
channels++;
pixel_depth = *bit_depth * channels;
rowbytes_per_pixel = (pixel_depth + 7) >> 3;
if (width == 0 || *width > PNG_MAX_UINT)
png_error(png_ptr, "Invalid image width");
if (height == 0 || *height > PNG_MAX_UINT)
png_error(png_ptr, "Invalid image height");
if (*width > PNG_MAX_UINT/rowbytes_per_pixel - 64)
{
png_error(png_ptr,
@ -576,7 +584,7 @@ png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
return (0);
}
#if defined(PNG_READ_oFFs_SUPPORTED)
#if defined(PNG_oFFs_SUPPORTED)
png_uint_32 PNGAPI
png_get_oFFs(png_structp png_ptr, png_infop info_ptr,
png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
@ -594,7 +602,7 @@ png_get_oFFs(png_structp png_ptr, png_infop info_ptr,
}
#endif
#if defined(PNG_READ_pCAL_SUPPORTED)
#if defined(PNG_pCAL_SUPPORTED)
png_uint_32 PNGAPI
png_get_pCAL(png_structp png_ptr, png_infop info_ptr,
png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
@ -618,7 +626,7 @@ png_get_pCAL(png_structp png_ptr, png_infop info_ptr,
}
#endif
#if defined(PNG_READ_sCAL_SUPPORTED) || defined(PNG_WRITE_sCAL_SUPPORTED)
#if defined(PNG_sCAL_SUPPORTED)
#ifdef PNG_FLOATING_POINT_SUPPORTED
png_uint_32 PNGAPI
png_get_sCAL(png_structp png_ptr, png_infop info_ptr,
@ -654,7 +662,7 @@ png_get_sCAL_s(png_structp png_ptr, png_infop info_ptr,
#endif
#endif
#if defined(PNG_READ_pHYs_SUPPORTED)
#if defined(PNG_pHYs_SUPPORTED)
png_uint_32 PNGAPI
png_get_pHYs(png_structp png_ptr, png_infop info_ptr,
png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
@ -701,7 +709,7 @@ png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette,
return (0);
}
#if defined(PNG_READ_sBIT_SUPPORTED)
#if defined(PNG_sBIT_SUPPORTED)
png_uint_32 PNGAPI
png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit)
{
@ -716,7 +724,7 @@ png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit)
}
#endif
#if defined(PNG_READ_TEXT_SUPPORTED)
#if defined(PNG_TEXT_SUPPORTED)
png_uint_32 PNGAPI
png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr,
int *num_text)
@ -738,7 +746,7 @@ png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr,
}
#endif
#if defined(PNG_READ_tIME_SUPPORTED)
#if defined(PNG_tIME_SUPPORTED)
png_uint_32 PNGAPI
png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time)
{
@ -753,7 +761,7 @@ png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time)
}
#endif
#if defined(PNG_READ_tRNS_SUPPORTED)
#if defined(PNG_tRNS_SUPPORTED)
png_uint_32 PNGAPI
png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
png_bytep *trans, int *num_trans, png_color_16p *trans_values)
@ -792,7 +800,7 @@ png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
}
#endif
#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
png_uint_32 PNGAPI
png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr,
png_unknown_chunkpp unknowns)
@ -811,7 +819,7 @@ png_get_rgb_to_gray_status (png_structp png_ptr)
}
#endif
#if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
#if defined(PNG_USER_CHUNKS_SUPPORTED)
png_voidp PNGAPI
png_get_user_chunk_ptr(png_structp png_ptr)
{
@ -826,3 +834,94 @@ png_get_compression_buffer_size(png_structp png_ptr)
return (png_uint_32)(png_ptr? png_ptr->zbuf_size : 0L);
}
#ifndef PNG_1_0_X
#ifdef PNG_ASSEMBLER_CODE_SUPPORTED
/* this function was added to libpng 1.2.0 and should exist by default */
png_uint_32 PNGAPI
png_get_asm_flags (png_structp png_ptr)
{
return (png_uint_32)(png_ptr? png_ptr->asm_flags : 0L);
}
/* this function was added to libpng 1.2.0 and should exist by default */
png_uint_32 PNGAPI
png_get_asm_flagmask (int flag_select)
{
png_uint_32 settable_asm_flags = 0;
if (flag_select & PNG_SELECT_READ)
settable_asm_flags |=
PNG_ASM_FLAG_MMX_READ_COMBINE_ROW |
PNG_ASM_FLAG_MMX_READ_INTERLACE |
PNG_ASM_FLAG_MMX_READ_FILTER_SUB |
PNG_ASM_FLAG_MMX_READ_FILTER_UP |
PNG_ASM_FLAG_MMX_READ_FILTER_AVG |
PNG_ASM_FLAG_MMX_READ_FILTER_PAETH ;
/* no non-MMX flags yet */
#if 0
/* GRR: no write-flags yet, either, but someday... */
if (flag_select & PNG_SELECT_WRITE)
settable_asm_flags |=
PNG_ASM_FLAG_MMX_WRITE_ [whatever] ;
#endif /* 0 */
return settable_asm_flags; /* _theoretically_ settable capabilities only */
}
#endif /* PNG_ASSEMBLER_CODE_SUPPORTED */
#if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
/* GRR: could add this: && defined(PNG_MMX_CODE_SUPPORTED) */
/* this function was added to libpng 1.2.0 */
png_uint_32 PNGAPI
png_get_mmx_flagmask (int flag_select, int *compilerID)
{
png_uint_32 settable_mmx_flags = 0;
if (flag_select & PNG_SELECT_READ)
settable_mmx_flags |=
PNG_ASM_FLAG_MMX_READ_COMBINE_ROW |
PNG_ASM_FLAG_MMX_READ_INTERLACE |
PNG_ASM_FLAG_MMX_READ_FILTER_SUB |
PNG_ASM_FLAG_MMX_READ_FILTER_UP |
PNG_ASM_FLAG_MMX_READ_FILTER_AVG |
PNG_ASM_FLAG_MMX_READ_FILTER_PAETH ;
#if 0
/* GRR: no MMX write support yet, but someday... */
if (flag_select & PNG_SELECT_WRITE)
settable_mmx_flags |=
PNG_ASM_FLAG_MMX_WRITE_ [whatever] ;
#endif /* 0 */
if (compilerID != NULL) {
#ifdef PNG_USE_PNGVCRD
*compilerID = 1; /* MSVC */
#else
#ifdef PNG_USE_PNGGCCRD
*compilerID = 2; /* gcc/gas */
#else
*compilerID = -1; /* unknown (i.e., no asm/MMX code compiled) */
#endif
#endif
}
return settable_mmx_flags; /* _theoretically_ settable capabilities only */
}
/* this function was added to libpng 1.2.0 */
png_byte PNGAPI
png_get_mmx_bitdepth_threshold (png_structp png_ptr)
{
return (png_byte)(png_ptr? png_ptr->mmx_bitdepth_threshold : 0);
}
/* this function was added to libpng 1.2.0 */
png_uint_32 PNGAPI
png_get_mmx_rowbytes_threshold (png_structp png_ptr)
{
return (png_uint_32)(png_ptr? png_ptr->mmx_rowbytes_threshold : 0L);
}
#endif /* PNG_ASSEMBLER_CODE_SUPPORTED */
#endif /* PNG_1_0_X */

Просмотреть файл

@ -1,9 +1,9 @@
/* pngmem.c - stub functions for memory allocation
*
* libpng 1.0.9 - January 31, 2001
* libpng 1.2.5 - October 2, 2002
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2001 Glenn Randers-Pehrson
* Copyright (c) 1998-2002 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*
@ -27,12 +27,12 @@ png_voidp /* PRIVATE */
png_create_struct(int type)
{
#ifdef PNG_USER_MEM_SUPPORTED
return (png_create_struct_2(type, NULL));
return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL));
}
/* Alternate version of png_create_struct, for use with user-defined malloc. */
png_voidp /* PRIVATE */
png_create_struct_2(int type, png_malloc_ptr malloc_fn)
png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
{
#endif /* PNG_USER_MEM_SUPPORTED */
png_size_t size;
@ -43,35 +43,36 @@ png_create_struct_2(int type, png_malloc_ptr malloc_fn)
else if (type == PNG_STRUCT_PNG)
size = sizeof(png_struct);
else
return ((png_voidp)NULL);
return (png_get_copyright());
#ifdef PNG_USER_MEM_SUPPORTED
if(malloc_fn != NULL)
{
if ((struct_ptr = (*(malloc_fn))(NULL, size)) != NULL)
png_memset(struct_ptr, 0, size);
return (struct_ptr);
png_struct dummy_struct;
png_structp png_ptr = &dummy_struct;
png_ptr->mem_ptr=mem_ptr;
struct_ptr = (*(malloc_fn))(png_ptr, (png_uint_32)size);
}
else
#endif /* PNG_USER_MEM_SUPPORTED */
if ((struct_ptr = (png_voidp)farmalloc(size)) != NULL)
{
struct_ptr = (png_voidp)farmalloc(size));
if (struct_ptr != NULL)
png_memset(struct_ptr, 0, size);
}
return (struct_ptr);
}
/* Free memory allocated by a png_create_struct() call */
void /* PRIVATE */
png_destroy_struct(png_voidp struct_ptr)
{
#ifdef PNG_USER_MEM_SUPPORTED
png_destroy_struct_2(struct_ptr, (png_free_ptr)NULL);
png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL);
}
/* Free memory allocated by a png_create_struct() call */
void /* PRIVATE */
png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn)
png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
png_voidp mem_ptr)
{
#endif
if (struct_ptr != NULL)
@ -81,6 +82,7 @@ png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn)
{
png_struct dummy_struct;
png_structp png_ptr = &dummy_struct;
png_ptr->mem_ptr=mem_ptr;
(*(free_fn))(png_ptr, struct_ptr);
return;
}
@ -108,18 +110,23 @@ png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn)
* result, we would be truncating potentially larger memory requests
* (which should cause a fatal error) and introducing major problems.
*/
png_voidp PNGAPI
png_malloc(png_structp png_ptr, png_uint_32 size)
{
#ifndef PNG_USER_MEM_SUPPORTED
png_voidp ret;
#endif
if (png_ptr == NULL || size == 0)
return ((png_voidp)NULL);
return (NULL);
#ifdef PNG_USER_MEM_SUPPORTED
if(png_ptr->malloc_fn != NULL)
return ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, size));
{
ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
png_error(png_ptr, "Out of memory!");
return (ret);
}
else
return png_malloc_default(png_ptr, size);
}
@ -170,12 +177,22 @@ png_malloc_default(png_structp png_ptr, png_uint_32 size)
if (table == NULL)
{
png_error(png_ptr, "Out Of Memory."); /* Note "O" and "M" */
if (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
png_error(png_ptr, "Out Of Memory."); /* Note "O" and "M" */
else
png_warning(png_ptr, "Out Of Memory.");
return (NULL);
}
if ((png_size_t)table & 0xfff0)
{
png_error(png_ptr, "Farmalloc didn't return normalized pointer");
if (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
png_error(png_ptr,
"Farmalloc didn't return normalized pointer");
else
png_warning(png_ptr,
"Farmalloc didn't return normalized pointer");
return (NULL);
}
png_ptr->offset_table = table;
@ -184,7 +201,11 @@ png_malloc_default(png_structp png_ptr, png_uint_32 size)
if (png_ptr->offset_table_ptr == NULL)
{
png_error(png_ptr, "Out Of memory.");
if (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
png_error(png_ptr, "Out Of memory."); /* Note "O" and "M" */
else
png_warning(png_ptr, "Out Of memory.");
return (NULL);
}
hptr = (png_byte huge *)table;
@ -206,7 +227,13 @@ png_malloc_default(png_structp png_ptr, png_uint_32 size)
}
if (png_ptr->offset_table_count >= png_ptr->offset_table_number)
png_error(png_ptr, "Out of Memory.");
{
if (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
png_error(png_ptr, "Out of Memory."); /* Note "o" and "M" */
else
png_warning(png_ptr, "Out of Memory.");
return (NULL);
}
ret = png_ptr->offset_table_ptr[png_ptr->offset_table_count++];
}
@ -215,7 +242,10 @@ png_malloc_default(png_structp png_ptr, png_uint_32 size)
if (ret == NULL)
{
png_error(png_ptr, "Out of memory."); /* Note "o" and "m" */
if (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
png_error(png_ptr, "Out of memory."); /* Note "o" and "m" */
else
png_warning(png_ptr, "Out of memory."); /* Note "o" and "m" */
}
return (ret);
@ -276,19 +306,19 @@ png_free_default(png_structp png_ptr, png_voidp ptr)
/* Allocate memory for a png_struct or a png_info. The malloc and
memset can be replaced by a single call to calloc() if this is thought
to improve performance noticably.*/
to improve performance noticably. */
png_voidp /* PRIVATE */
png_create_struct(int type)
{
#ifdef PNG_USER_MEM_SUPPORTED
return (png_create_struct_2(type, NULL));
return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL));
}
/* Allocate memory for a png_struct or a png_info. The malloc and
memset can be replaced by a single call to calloc() if this is thought
to improve performance noticably.*/
to improve performance noticably. */
png_voidp /* PRIVATE */
png_create_struct_2(int type, png_malloc_ptr malloc_fn)
png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
{
#endif /* PNG_USER_MEM_SUPPORTED */
png_size_t size;
@ -299,12 +329,16 @@ png_create_struct_2(int type, png_malloc_ptr malloc_fn)
else if (type == PNG_STRUCT_PNG)
size = sizeof(png_struct);
else
return ((png_voidp)NULL);
return (NULL);
#ifdef PNG_USER_MEM_SUPPORTED
if(malloc_fn != NULL)
{
if ((struct_ptr = (*(malloc_fn))(NULL, size)) != NULL)
png_struct dummy_struct;
png_structp png_ptr = &dummy_struct;
png_ptr->mem_ptr=mem_ptr;
struct_ptr = (*(malloc_fn))(png_ptr, size);
if (struct_ptr != NULL)
png_memset(struct_ptr, 0, size);
return (struct_ptr);
}
@ -332,12 +366,13 @@ void /* PRIVATE */
png_destroy_struct(png_voidp struct_ptr)
{
#ifdef PNG_USER_MEM_SUPPORTED
png_destroy_struct_2(struct_ptr, (png_free_ptr)NULL);
png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL);
}
/* Free memory allocated by a png_create_struct() call */
void /* PRIVATE */
png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn)
png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
png_voidp mem_ptr)
{
#endif /* PNG_USER_MEM_SUPPORTED */
if (struct_ptr != NULL)
@ -347,6 +382,7 @@ png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn)
{
png_struct dummy_struct;
png_structp png_ptr = &dummy_struct;
png_ptr->mem_ptr=mem_ptr;
(*(free_fn))(png_ptr, struct_ptr);
return;
}
@ -363,7 +399,6 @@ png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn)
}
}
/* Allocate memory. For reasonable files, size should never exceed
64K. However, zlib may allocate more then 64K if you don't tell
it not to. See zconf.h and png.h for more information. zlib does
@ -373,19 +408,24 @@ png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn)
png_voidp PNGAPI
png_malloc(png_structp png_ptr, png_uint_32 size)
{
#ifndef PNG_USER_MEM_SUPPORTED
png_voidp ret;
#endif
if (png_ptr == NULL || size == 0)
return ((png_voidp)NULL);
return (NULL);
#ifdef PNG_USER_MEM_SUPPORTED
if(png_ptr->malloc_fn != NULL)
return ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, size));
{
ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
png_error(png_ptr, "Out of Memory!");
return (ret);
}
else
return (png_malloc_default(png_ptr, size));
}
png_voidp /* PRIVATE */
png_voidp PNGAPI
png_malloc_default(png_structp png_ptr, png_uint_32 size)
{
png_voidp ret;
@ -393,7 +433,12 @@ png_malloc_default(png_structp png_ptr, png_uint_32 size)
#ifdef PNG_MAX_MALLOC_64K
if (size > (png_uint_32)65536L)
png_error(png_ptr, "Cannot Allocate > 64K");
{
if(png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
png_error(png_ptr, "Cannot Allocate > 64K");
else
return NULL;
}
#endif
#if defined(__TURBOC__) && !defined(__FLAT__)
@ -406,10 +451,8 @@ png_malloc_default(png_structp png_ptr, png_uint_32 size)
# endif
#endif
if (ret == NULL)
{
if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
png_error(png_ptr, "Out of Memory");
}
return (ret);
}
@ -430,7 +473,7 @@ png_free(png_structp png_ptr, png_voidp ptr)
}
else png_free_default(png_ptr, ptr);
}
void /* PRIVATE */
void PNGAPI
png_free_default(png_structp png_ptr, png_voidp ptr)
{
if (png_ptr == NULL || ptr == NULL)
@ -451,7 +494,27 @@ png_free_default(png_structp png_ptr, png_voidp ptr)
#endif /* Not Borland DOS special memory handler */
png_voidp /* PRIVATE */
#if defined(PNG_1_0_X)
# define png_malloc_warn png_malloc
#else
/* This function was added at libpng version 1.2.3. The png_malloc_warn()
* function will issue a png_warning and return NULL instead of issuing a
* png_error, if it fails to allocate the requested memory.
*/
png_voidp PNGAPI
png_malloc_warn(png_structp png_ptr, png_uint_32 size)
{
png_voidp ptr;
png_uint_32 save_flags=png_ptr->flags;
png_ptr->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
ptr = (png_voidp)png_malloc((png_structp)png_ptr, size);
png_ptr->flags=save_flags;
return(ptr);
}
#endif
png_voidp PNGAPI
png_memcpy_check (png_structp png_ptr, png_voidp s1, png_voidp s2,
png_uint_32 length)
{
@ -464,7 +527,7 @@ png_memcpy_check (png_structp png_ptr, png_voidp s1, png_voidp s2,
return(png_memcpy (s1, s2, size));
}
png_voidp /* PRIVATE */
png_voidp PNGAPI
png_memset_check (png_structp png_ptr, png_voidp s1, int value,
png_uint_32 length)
{

Просмотреть файл

@ -1,9 +1,9 @@
/* pngpread.c - read a png file in push mode
*
* libpng 1.0.9 - January 31, 2001
* libpng 1.2.5 - October 2, 2002
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2001 Glenn Randers-Pehrson
* Copyright (c) 1998-2002 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*/
@ -221,7 +221,6 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
png_push_save_buffer(png_ptr);
return;
}
png_handle_IHDR(png_ptr, info_ptr, png_ptr->push_length);
}
else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
@ -231,7 +230,6 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
png_push_save_buffer(png_ptr);
return;
}
png_handle_PLTE(png_ptr, info_ptr, png_ptr->push_length);
}
else if (!png_memcmp(png_ptr->chunk_name, (png_bytep)png_IDAT, 4))
@ -240,6 +238,12 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
* header chunks, and we can start reading the image (or if this
* is called after the image has been read - we have an error).
*/
if (!(png_ptr->mode & PNG_HAVE_IHDR))
png_error(png_ptr, "Missing IHDR before IDAT");
else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
!(png_ptr->mode & PNG_HAVE_PLTE))
png_error(png_ptr, "Missing PLTE before IDAT");
if (png_ptr->mode & PNG_HAVE_IDAT)
{
if (png_ptr->push_length == 0)
@ -264,8 +268,8 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
png_push_save_buffer(png_ptr);
return;
}
png_handle_IEND(png_ptr, info_ptr, png_ptr->push_length);
png_ptr->process_mode = PNG_READ_DONE_MODE;
png_push_have_end(png_ptr, info_ptr);
}
@ -277,7 +281,6 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
png_push_save_buffer(png_ptr);
return;
}
png_handle_gAMA(png_ptr, info_ptr, png_ptr->push_length);
}
#endif
@ -289,7 +292,6 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
png_push_save_buffer(png_ptr);
return;
}
png_handle_sBIT(png_ptr, info_ptr, png_ptr->push_length);
}
#endif
@ -301,7 +303,6 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
png_push_save_buffer(png_ptr);
return;
}
png_handle_cHRM(png_ptr, info_ptr, png_ptr->push_length);
}
#endif
@ -313,7 +314,6 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
png_push_save_buffer(png_ptr);
return;
}
png_handle_sRGB(png_ptr, info_ptr, png_ptr->push_length);
}
#endif
@ -325,7 +325,6 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
png_push_save_buffer(png_ptr);
return;
}
png_handle_iCCP(png_ptr, info_ptr, png_ptr->push_length);
}
#endif
@ -337,7 +336,6 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
png_push_save_buffer(png_ptr);
return;
}
png_handle_sPLT(png_ptr, info_ptr, png_ptr->push_length);
}
#endif
@ -349,7 +347,6 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
png_push_save_buffer(png_ptr);
return;
}
png_handle_tRNS(png_ptr, info_ptr, png_ptr->push_length);
}
#endif
@ -361,7 +358,6 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
png_push_save_buffer(png_ptr);
return;
}
png_handle_bKGD(png_ptr, info_ptr, png_ptr->push_length);
}
#endif
@ -373,7 +369,6 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
png_push_save_buffer(png_ptr);
return;
}
png_handle_hIST(png_ptr, info_ptr, png_ptr->push_length);
}
#endif
@ -385,7 +380,6 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
png_push_save_buffer(png_ptr);
return;
}
png_handle_pHYs(png_ptr, info_ptr, png_ptr->push_length);
}
#endif
@ -397,7 +391,6 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
png_push_save_buffer(png_ptr);
return;
}
png_handle_oFFs(png_ptr, info_ptr, png_ptr->push_length);
}
#endif
@ -409,7 +402,6 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
png_push_save_buffer(png_ptr);
return;
}
png_handle_pCAL(png_ptr, info_ptr, png_ptr->push_length);
}
#endif
@ -421,7 +413,6 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
png_push_save_buffer(png_ptr);
return;
}
png_handle_sCAL(png_ptr, info_ptr, png_ptr->push_length);
}
#endif
@ -433,30 +424,49 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
png_push_save_buffer(png_ptr);
return;
}
png_handle_tIME(png_ptr, info_ptr, png_ptr->push_length);
}
#endif
#if defined(PNG_READ_tEXt_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
{
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
{
png_push_save_buffer(png_ptr);
return;
}
png_push_handle_tEXt(png_ptr, info_ptr, png_ptr->push_length);
}
#endif
#if defined(PNG_READ_zTXt_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
{
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
{
png_push_save_buffer(png_ptr);
return;
}
png_push_handle_zTXt(png_ptr, info_ptr, png_ptr->push_length);
}
#endif
#if defined(PNG_READ_iTXt_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
{
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
{
png_push_save_buffer(png_ptr);
return;
}
png_push_handle_iTXt(png_ptr, info_ptr, png_ptr->push_length);
}
#endif
else
{
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
{
png_push_save_buffer(png_ptr);
return;
}
png_push_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
}
@ -518,7 +528,7 @@ png_push_crc_finish(png_structp png_ptr)
}
}
void /* PRIVATE */
void PNGAPI
png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length)
{
png_bytep ptr;
@ -658,8 +668,8 @@ png_push_read_IDAT(png_structp png_ptr)
save_size = png_ptr->save_buffer_size;
png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
png_process_IDAT_data(png_ptr, png_ptr->save_buffer_ptr, save_size);
if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
png_process_IDAT_data(png_ptr, png_ptr->save_buffer_ptr, save_size);
png_ptr->idat_size -= save_size;
png_ptr->buffer_size -= save_size;
png_ptr->save_buffer_size -= save_size;
@ -680,7 +690,8 @@ png_push_read_IDAT(png_structp png_ptr)
save_size = png_ptr->current_buffer_size;
png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
png_process_IDAT_data(png_ptr, png_ptr->current_buffer_ptr, save_size);
if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
png_process_IDAT_data(png_ptr, png_ptr->current_buffer_ptr, save_size);
png_ptr->idat_size -= save_size;
png_ptr->buffer_size -= save_size;
@ -697,6 +708,7 @@ png_push_read_IDAT(png_structp png_ptr)
png_crc_finish(png_ptr, 0);
png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
png_ptr->mode |= PNG_AFTER_IDAT;
}
}
@ -742,7 +754,12 @@ png_process_IDAT_data(png_structp png_ptr, png_bytep buffer,
(!png_ptr->interlaced &&
#endif
png_ptr->row_number == png_ptr->num_rows-1))
png_error(png_ptr, "Too much data in IDAT chunks");
{
if (png_ptr->zstream.avail_in)
png_warning(png_ptr, "Too much data in IDAT chunks");
png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
break;
}
png_push_process_row(png_ptr);
png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
png_ptr->zstream.next_out = png_ptr->row_buf;
@ -799,21 +816,21 @@ png_push_process_row(png_structp png_ptr)
{
for (i = 0; i < 4 && png_ptr->pass == 2; i++)
{
png_push_have_row(png_ptr, NULL);
png_push_have_row(png_ptr, png_bytep_NULL);
png_read_push_finish_row(png_ptr);
}
}
if (png_ptr->pass == 4 && png_ptr->height <= 4)
{
for (i = 0; i < 2 && png_ptr->pass == 4; i++)
{
png_push_have_row(png_ptr, NULL);
png_read_push_finish_row(png_ptr);
}
if (png_ptr->pass == 4 && png_ptr->height <= 4)
{
for (i = 0; i < 2 && png_ptr->pass == 4; i++)
{
png_push_have_row(png_ptr, png_bytep_NULL);
png_read_push_finish_row(png_ptr);
}
}
if (png_ptr->pass == 6 && png_ptr->height <= 4)
{
png_push_have_row(png_ptr, NULL);
png_push_have_row(png_ptr, png_bytep_NULL);
png_read_push_finish_row(png_ptr);
}
break;
@ -830,7 +847,7 @@ png_push_process_row(png_structp png_ptr)
{
for (i = 0; i < 4 && png_ptr->pass == 2; i++)
{
png_push_have_row(png_ptr, NULL);
png_push_have_row(png_ptr, png_bytep_NULL);
png_read_push_finish_row(png_ptr);
}
}
@ -846,14 +863,14 @@ png_push_process_row(png_structp png_ptr)
}
for (i = 0; i < 4 && png_ptr->pass == 2; i++)
{
png_push_have_row(png_ptr, NULL);
png_push_have_row(png_ptr, png_bytep_NULL);
png_read_push_finish_row(png_ptr);
}
if (png_ptr->pass == 4) /* pass 3 might be empty */
{
for (i = 0; i < 2 && png_ptr->pass == 4; i++)
{
png_push_have_row(png_ptr, NULL);
png_push_have_row(png_ptr, png_bytep_NULL);
png_read_push_finish_row(png_ptr);
}
}
@ -871,7 +888,7 @@ png_push_process_row(png_structp png_ptr)
{
for (i = 0; i < 2 && png_ptr->pass == 4; i++)
{
png_push_have_row(png_ptr, NULL);
png_push_have_row(png_ptr, png_bytep_NULL);
png_read_push_finish_row(png_ptr);
}
}
@ -887,12 +904,12 @@ png_push_process_row(png_structp png_ptr)
}
for (i = 0; i < 2 && png_ptr->pass == 4; i++)
{
png_push_have_row(png_ptr, NULL);
png_push_have_row(png_ptr, png_bytep_NULL);
png_read_push_finish_row(png_ptr);
}
if (png_ptr->pass == 6) /* pass 5 might be empty */
{
png_push_have_row(png_ptr, NULL);
png_push_have_row(png_ptr, png_bytep_NULL);
png_read_push_finish_row(png_ptr);
}
break;
@ -907,7 +924,7 @@ png_push_process_row(png_structp png_ptr)
}
if (png_ptr->pass == 6) /* skip top generated row */
{
png_push_have_row(png_ptr, NULL);
png_push_have_row(png_ptr, png_bytep_NULL);
png_read_push_finish_row(png_ptr);
}
break;
@ -918,7 +935,7 @@ png_push_process_row(png_structp png_ptr)
png_read_push_finish_row(png_ptr);
if (png_ptr->pass != 6)
break;
png_push_have_row(png_ptr, NULL);
png_push_have_row(png_ptr, png_bytep_NULL);
png_read_push_finish_row(png_ptr);
}
}
@ -977,6 +994,8 @@ png_read_push_finish_row(png_structp png_ptr)
(png_ptr->pass == 5 && png_ptr->width < 2))
png_ptr->pass++;
if (png_ptr->pass > 7)
png_ptr->pass--;
if (png_ptr->pass >= 7)
break;
@ -1002,7 +1021,8 @@ png_read_push_finish_row(png_structp png_ptr)
#if defined(PNG_READ_tEXt_SUPPORTED)
void /* PRIVATE */
png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
length)
{
if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
{
@ -1014,7 +1034,7 @@ png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length
#ifdef PNG_MAX_MALLOC_64K
png_ptr->skip_length = 0; /* This may not be necessary */
if (length > (png_uint_32)65535L) /* Can't hold the entire string in memory */
if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */
{
png_warning(png_ptr, "tEXt chunk too large to fit in memory");
png_ptr->skip_length = length - (png_uint_32)65535L;
@ -1051,6 +1071,7 @@ png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr)
png_textp text_ptr;
png_charp text;
png_charp key;
int ret;
if (png_ptr->buffer_size < 4)
{
@ -1066,7 +1087,6 @@ png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr)
#endif
key = png_ptr->current_text;
png_ptr->current_text = 0;
for (text = key; *text; text++)
/* empty loop */ ;
@ -1078,22 +1098,27 @@ png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr)
text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
text_ptr->key = key;
#ifdef PNG_iTXt_SUPPORTED
text_ptr->lang = (char *)NULL;
text_ptr->lang_key = (char *)NULL;
text_ptr->lang = NULL;
text_ptr->lang_key = NULL;
#endif
text_ptr->text = text;
png_set_text(png_ptr, info_ptr, text_ptr, 1);
ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
png_free(png_ptr, key);
png_free(png_ptr, text_ptr);
png_ptr->current_text = NULL;
if (ret)
png_warning(png_ptr, "Insufficient memory to store text chunk.");
}
}
#endif
#if defined(PNG_READ_zTXt_SUPPORTED)
void /* PRIVATE */
png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
length)
{
if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
{
@ -1156,7 +1181,6 @@ png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
png_push_crc_finish(png_ptr);
key = png_ptr->current_text;
png_ptr->current_text = 0;
for (text = key; *text; text++)
/* empty loop */ ;
@ -1164,6 +1188,7 @@ png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
/* zTXt can't have zero text */
if (text == key + png_ptr->current_text_size)
{
png_ptr->current_text = NULL;
png_free(png_ptr, key);
return;
}
@ -1172,6 +1197,7 @@ png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
if (*text != PNG_TEXT_COMPRESSION_zTXt) /* check compression byte */
{
png_ptr->current_text = NULL;
png_free(png_ptr, key);
return;
}
@ -1196,6 +1222,7 @@ png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
{
inflateReset(&png_ptr->zstream);
png_ptr->zstream.avail_in = 0;
png_ptr->current_text = NULL;
png_free(png_ptr, key);
png_free(png_ptr, text);
return;
@ -1205,8 +1232,8 @@ png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
if (text == NULL)
{
text = (png_charp)png_malloc(png_ptr,
(png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out +
key_size + 1));
(png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out
+ key_size + 1));
png_memcpy(text + key_size, png_ptr->zbuf,
png_ptr->zbuf_size - png_ptr->zstream.avail_out);
png_memcpy(text, key, key_size);
@ -1249,11 +1276,13 @@ png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
if (ret != Z_STREAM_END)
{
png_ptr->current_text = NULL;
png_free(png_ptr, key);
png_free(png_ptr, text);
return;
}
png_ptr->current_text = NULL;
png_free(png_ptr, key);
key = text;
text += key_size;
@ -1262,22 +1291,26 @@ png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
text_ptr->compression = PNG_TEXT_COMPRESSION_zTXt;
text_ptr->key = key;
#ifdef PNG_iTXt_SUPPORTED
text_ptr->lang = (char *)NULL;
text_ptr->lang_key = (char *)NULL;
text_ptr->lang = NULL;
text_ptr->lang_key = NULL;
#endif
text_ptr->text = text;
png_set_text(png_ptr, info_ptr, text_ptr, 1);
ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
png_free(png_ptr, key);
png_free(png_ptr, text_ptr);
if (ret)
png_warning(png_ptr, "Insufficient memory to store text chunk.");
}
}
#endif
#if defined(PNG_READ_iTXt_SUPPORTED)
void /* PRIVATE */
png_push_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_push_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
length)
{
if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
{
@ -1289,7 +1322,7 @@ png_push_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length
#ifdef PNG_MAX_MALLOC_64K
png_ptr->skip_length = 0; /* This may not be necessary */
if (length > (png_uint_32)65535L) /* Can't hold the entire string in memory */
if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */
{
png_warning(png_ptr, "iTXt chunk too large to fit in memory");
png_ptr->skip_length = length - (png_uint_32)65535L;
@ -1330,6 +1363,7 @@ png_push_read_iTXt(png_structp png_ptr, png_infop info_ptr)
png_charp lang;
png_charp lang_key;
png_charp text;
int ret;
if (png_ptr->buffer_size < 4)
{
@ -1345,7 +1379,6 @@ png_push_read_iTXt(png_structp png_ptr, png_infop info_ptr)
#endif
key = png_ptr->current_text;
png_ptr->current_text = 0;
for (lang = key; *lang; lang++)
/* empty loop */ ;
@ -1375,9 +1408,13 @@ png_push_read_iTXt(png_structp png_ptr, png_infop info_ptr)
text_ptr->text_length = 0;
text_ptr->itxt_length = png_strlen(text);
png_set_text(png_ptr, info_ptr, text_ptr, 1);
ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
png_ptr->current_text = NULL;
png_free(png_ptr, text_ptr);
if (ret)
png_warning(png_ptr, "Insufficient memory to store iTXt chunk.");
}
}
#endif
@ -1387,7 +1424,8 @@ png_push_read_iTXt(png_structp png_ptr, png_infop info_ptr)
* name or a critical chunk), the chunk is (currently) silently ignored.
*/
void /* PRIVATE */
png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32
length)
{
png_uint_32 skip=0;
png_check_chunk_name(png_ptr, png_ptr->chunk_name);
@ -1398,7 +1436,7 @@ png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 len
if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
HANDLE_CHUNK_ALWAYS
#if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
&& png_ptr->read_user_chunk_fn == (png_user_chunk_ptr)NULL
&& png_ptr->read_user_chunk_fn == NULL
#endif
)
#endif
@ -1423,12 +1461,12 @@ png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 len
}
#endif
strcpy((png_charp)chunk.name, (png_charp)png_ptr->chunk_name);
png_strcpy((png_charp)chunk.name, (png_charp)png_ptr->chunk_name);
chunk.data = (png_bytep)png_malloc(png_ptr, length);
png_crc_read(png_ptr, chunk.data, length);
chunk.size = length;
#if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
if(png_ptr->read_user_chunk_fn != (png_user_chunk_ptr)NULL)
if(png_ptr->read_user_chunk_fn != NULL)
{
/* callback to user unknown chunk handler */
if ((*(png_ptr->read_user_chunk_fn)) (png_ptr, &chunk) <= 0)
@ -1502,6 +1540,4 @@ png_get_progressive_ptr(png_structp png_ptr)
{
return png_ptr->io_ptr;
}
#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */

Просмотреть файл

@ -1,9 +1,9 @@
/* pngread.c - read a PNG file
*
* libpng 1.0.9 - January 31, 2001
* libpng 1.2.5 - October 2, 2002
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2001 Glenn Randers-Pehrson
* Copyright (c) 1998-2002 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*
@ -22,7 +22,7 @@ png_create_read_struct(png_const_charp user_png_ver, png_voidp error_ptr,
#ifdef PNG_USER_MEM_SUPPORTED
return (png_create_read_struct_2(user_png_ver, error_ptr, error_fn,
warn_fn, NULL, NULL, NULL));
warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL));
}
/* Alternate create PNG structure for reading, and allocate any memory needed. */
@ -45,14 +45,19 @@ png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
png_debug(1, "in png_create_read_struct\n");
#ifdef PNG_USER_MEM_SUPPORTED
if ((png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
(png_malloc_ptr)malloc_fn)) == NULL)
png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
(png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
#else
if ((png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG)) == NULL)
png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
#endif
{
return (png_structp)NULL;
}
if (png_ptr == NULL)
return (NULL);
#if !defined(PNG_1_0_X)
#ifdef PNG_ASSEMBLER_CODE_SUPPORTED
png_init_mmx_flags(png_ptr); /* 1.2.0 addition */
#endif
#endif /* PNG_1_0_X */
#ifdef PNG_SETJMP_SUPPORTED
#ifdef USE_FAR_KEYWORD
@ -63,8 +68,13 @@ png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
{
png_free(png_ptr, png_ptr->zbuf);
png_ptr->zbuf=NULL;
png_destroy_struct(png_ptr);
return (png_structp)NULL;
#ifdef PNG_USER_MEM_SUPPORTED
png_destroy_struct_2((png_voidp)png_ptr,
(png_free_ptr)free_fn, (png_voidp)mem_ptr);
#else
png_destroy_struct((png_voidp)png_ptr);
#endif
return (NULL);
}
#ifdef USE_FAR_KEYWORD
png_memcpy(png_ptr->jmpbuf,jmpbuf,sizeof(jmp_buf));
@ -92,23 +102,27 @@ png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
* only check the first digit.
*/
if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
(user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
(user_png_ver[0] == '0' && user_png_ver[2] < '9'))
{
#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
char msg[80];
if (user_png_ver)
{
sprintf(msg, "Application was compiled with png.h from libpng-%.20s",
user_png_ver);
png_warning(png_ptr, msg);
}
sprintf(msg, "Application is running with png.c from libpng-%.20s",
png_libpng_ver);
png_warning(png_ptr, msg);
#endif
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
png_ptr->flags=0;
#endif
png_error(png_ptr,
"Incompatible libpng version in application and library");
}
/* Libpng 1.0.6 was not binary compatible, due to insertion of the
info_ptr->free_me member. Note to maintainer: this test can be
removed from version 2.0.0 and beyond because the previous test
would have already rejected it. */
if (user_png_ver[4] == '6' && user_png_ver[2] == '0' &&
user_png_ver[0] == '1' && user_png_ver[5] == '\0')
{
png_error(png_ptr,
"Application must be recompiled; version 1.0.6 was incompatible");
}
}
/* initialize zbuf - compression buffer */
@ -131,8 +145,21 @@ png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
png_ptr->zstream.next_out = png_ptr->zbuf;
png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
png_set_read_fn(png_ptr, NULL, NULL);
png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL);
#ifdef PNG_SETJMP_SUPPORTED
/* Applications that neglect to set up their own setjmp() and then encounter
a png_error() will longjmp here. Since the jmpbuf is then meaningless we
abort instead of returning. */
#ifdef USE_FAR_KEYWORD
if (setjmp(jmpbuf))
PNG_ABORT();
png_memcpy(png_ptr->jmpbuf,jmpbuf,sizeof(jmp_buf));
#else
if (setjmp(png_ptr->jmpbuf))
PNG_ABORT();
#endif
#endif
return (png_ptr);
}
@ -144,18 +171,63 @@ void PNGAPI
png_read_init(png_structp png_ptr)
{
/* We only come here via pre-1.0.7-compiled applications */
png_read_init_2(png_ptr, "1.0.0", 10000, 10000);
png_read_init_2(png_ptr, "1.0.6 or earlier", 0, 0);
}
void PNGAPI
png_read_init_2(png_structp png_ptr, png_const_charp user_png_ver,
png_size_t png_struct_size, png_size_t png_info_size)
{
/* We only come here via pre-1.0.12-compiled applications */
#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
if(sizeof(png_struct) > png_struct_size || sizeof(png_info) > png_info_size)
{
char msg[80];
png_ptr->warning_fn=NULL;
if (user_png_ver)
{
sprintf(msg, "Application was compiled with png.h from libpng-%.20s",
user_png_ver);
png_warning(png_ptr, msg);
}
sprintf(msg, "Application is running with png.c from libpng-%.20s",
png_libpng_ver);
png_warning(png_ptr, msg);
}
#endif
if(sizeof(png_struct) > png_struct_size)
{
png_ptr->error_fn=NULL;
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
png_ptr->flags=0;
#endif
png_error(png_ptr,
"The png struct allocated by the application for reading is too small.");
}
if(sizeof(png_info) > png_info_size)
{
png_ptr->error_fn=NULL;
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
png_ptr->flags=0;
#endif
png_error(png_ptr,
"The info struct allocated by application for reading is too small.");
}
png_read_init_3(&png_ptr, user_png_ver, png_struct_size);
}
void PNGAPI
png_read_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
png_size_t png_struct_size)
{
#ifdef PNG_SETJMP_SUPPORTED
jmp_buf tmp_jmp; /* to save current jump buffer */
#endif
int i=0;
png_structp png_ptr=*ptr_ptr;
do
{
if(user_png_ver[i] != png_libpng_ver[i])
@ -163,28 +235,28 @@ png_read_init_2(png_structp png_ptr, png_const_charp user_png_ver,
#ifdef PNG_LEGACY_SUPPORTED
png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
#else
png_ptr->error_fn=(png_error_ptr)NULL;
png_error(png_ptr,
"Application uses deprecated png_read_init() and must be recompiled.");
png_ptr->warning_fn=NULL;
png_warning(png_ptr,
"Application uses deprecated png_read_init() and should be recompiled.");
break;
#endif
}
} while (png_libpng_ver[i++]);
if(sizeof(png_struct) > png_struct_size ||
sizeof(png_info) > png_info_size)
{
png_ptr->error_fn=(png_error_ptr)NULL;
png_error(png_ptr,
"Application and library have different sized structs. Please recompile.");
}
png_debug(1, "in png_read_init_2\n");
png_debug(1, "in png_read_init_3\n");
#ifdef PNG_SETJMP_SUPPORTED
/* save jump buffer and error functions */
png_memcpy(tmp_jmp, png_ptr->jmpbuf, sizeof (jmp_buf));
#endif
if(sizeof(png_struct) > png_struct_size)
{
png_destroy_struct(png_ptr);
*ptr_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
png_ptr = *ptr_ptr;
}
/* reset all variables to 0 */
png_memset(png_ptr, 0, sizeof (png_struct));
@ -213,7 +285,7 @@ png_read_init_2(png_structp png_ptr, png_const_charp user_png_ver,
png_ptr->zstream.next_out = png_ptr->zbuf;
png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
png_set_read_fn(png_ptr, NULL, NULL);
png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL);
}
/* Read the information before the actual image data. This has been
@ -228,7 +300,6 @@ void PNGAPI
png_read_info(png_structp png_ptr, png_infop info_ptr)
{
png_debug(1, "in png_read_info\n");
/* save jump buffer and error functions */
/* If we haven't checked all of the PNG signature bytes, do so now. */
if (png_ptr->sig_bytes < 8)
{
@ -321,6 +392,9 @@ png_read_info(png_structp png_ptr, png_infop info_ptr)
png_debug2(0, "Reading %s chunk, length=%lu.\n", png_ptr->chunk_name,
length);
if (length > PNG_MAX_UINT)
png_error(png_ptr, "Invalid chunk length.");
/* This should be a binary subdivision search or a hash for
* matching the chunk name rather than a linear search.
*/
@ -439,7 +513,6 @@ void PNGAPI
png_read_update_info(png_structp png_ptr, png_infop info_ptr)
{
png_debug(1, "in png_read_update_info\n");
/* save jump buffer and error functions */
if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
png_read_start_row(png_ptr);
else
@ -457,7 +530,6 @@ void PNGAPI
png_start_read_image(png_structp png_ptr)
{
png_debug(1, "in png_start_read_image\n");
/* save jump buffer and error functions */
if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
png_read_start_row(png_ptr);
}
@ -473,7 +545,6 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
int ret;
png_debug2(1, "in png_read_row (row %lu, pass %d)\n",
png_ptr->row_number, png_ptr->pass);
/* save jump buffer and error functions */
if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
png_read_start_row(png_ptr);
if (png_ptr->row_number == 0 && png_ptr->pass == 0)
@ -604,6 +675,9 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
png_read_data(png_ptr, chunk_length, 4);
png_ptr->idat_size = png_get_uint_32(chunk_length);
if (png_ptr->idat_size > PNG_MAX_UINT)
png_error(png_ptr, "Invalid chunk length.");
png_reset_crc(png_ptr);
png_crc_read(png_ptr, png_ptr->chunk_name, 4);
if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
@ -715,7 +789,7 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
* not called png_set_interlace_handling(), the display_row buffer will
* be ignored, so pass NULL to it.
*
* [*] png_handle_alpha() does not exist yet, as of libpng version 1.0.9
* [*] png_handle_alpha() does not exist yet, as of libpng version 1.2.5
*/
void PNGAPI
@ -727,7 +801,6 @@ png_read_rows(png_structp png_ptr, png_bytepp row,
png_bytepp dp;
png_debug(1, "in png_read_rows\n");
/* save jump buffer and error functions */
rp = row;
dp = display_row;
if (rp != NULL && dp != NULL)
@ -742,14 +815,14 @@ png_read_rows(png_structp png_ptr, png_bytepp row,
for (i = 0; i < num_rows; i++)
{
png_bytep rptr = *rp;
png_read_row(png_ptr, rptr, NULL);
png_read_row(png_ptr, rptr, png_bytep_NULL);
rp++;
}
else if(dp != NULL)
for (i = 0; i < num_rows; i++)
{
png_bytep dptr = *dp;
png_read_row(png_ptr, NULL, dptr);
png_read_row(png_ptr, png_bytep_NULL, dptr);
dp++;
}
}
@ -764,7 +837,7 @@ png_read_rows(png_structp png_ptr, png_bytepp row,
* only call this function once. If you desire to have an image for
* each pass of a interlaced image, use png_read_rows() instead.
*
* [*] png_handle_alpha() does not exist yet, as of libpng version 1.0.9
* [*] png_handle_alpha() does not exist yet, as of libpng version 1.2.5
*/
void PNGAPI
png_read_image(png_structp png_ptr, png_bytepp image)
@ -774,7 +847,6 @@ png_read_image(png_structp png_ptr, png_bytepp image)
png_bytepp rp;
png_debug(1, "in png_read_image\n");
/* save jump buffer and error functions */
#ifdef PNG_READ_INTERLACING_SUPPORTED
pass = png_set_interlace_handling(png_ptr);
@ -794,7 +866,7 @@ png_read_image(png_structp png_ptr, png_bytepp image)
rp = image;
for (i = 0; i < image_height; i++)
{
png_read_row(png_ptr, *rp, NULL);
png_read_row(png_ptr, *rp, png_bytep_NULL);
rp++;
}
}
@ -811,7 +883,6 @@ png_read_end(png_structp png_ptr, png_infop info_ptr)
png_uint_32 length;
png_debug(1, "in png_read_end\n");
/* save jump buffer and error functions */
png_crc_finish(png_ptr, 0); /* Finish off CRC from last IDAT chunk */
do
@ -882,6 +953,9 @@ png_read_end(png_structp png_ptr, png_infop info_ptr)
png_debug1(0, "Reading %s chunk.\n", png_ptr->chunk_name);
if (length > PNG_MAX_UINT)
png_error(png_ptr, "Invalid chunk length.");
if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
png_handle_IHDR(png_ptr, info_ptr, length);
else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
@ -994,10 +1068,10 @@ png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
png_infop info_ptr = NULL, end_info_ptr = NULL;
#ifdef PNG_USER_MEM_SUPPORTED
png_free_ptr free_fn = NULL;
png_voidp mem_ptr = NULL;
#endif
png_debug(1, "in png_destroy_read_struct\n");
/* save jump buffer and error functions */
if (png_ptr_ptr != NULL)
png_ptr = *png_ptr_ptr;
@ -1009,6 +1083,7 @@ png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
#ifdef PNG_USER_MEM_SUPPORTED
free_fn = png_ptr->free_fn;
mem_ptr = png_ptr->mem_ptr;
#endif
png_read_destroy(png_ptr, info_ptr, end_info_ptr);
@ -1020,11 +1095,12 @@ png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
#endif
#ifdef PNG_USER_MEM_SUPPORTED
png_destroy_struct_2((png_voidp)info_ptr, free_fn);
png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn,
(png_voidp)mem_ptr);
#else
png_destroy_struct((png_voidp)info_ptr);
#endif
*info_ptr_ptr = (png_infop)NULL;
*info_ptr_ptr = NULL;
}
if (end_info_ptr != NULL)
@ -1033,26 +1109,28 @@ png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
png_free_data(png_ptr, end_info_ptr, PNG_FREE_TEXT, -1);
#endif
#ifdef PNG_USER_MEM_SUPPORTED
png_destroy_struct_2((png_voidp)end_info_ptr, free_fn);
png_destroy_struct_2((png_voidp)end_info_ptr, (png_free_ptr)free_fn,
(png_voidp)mem_ptr);
#else
png_destroy_struct((png_voidp)end_info_ptr);
#endif
*end_info_ptr_ptr = (png_infop)NULL;
*end_info_ptr_ptr = NULL;
}
if (png_ptr != NULL)
{
#ifdef PNG_USER_MEM_SUPPORTED
png_destroy_struct_2((png_voidp)png_ptr, free_fn);
png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn,
(png_voidp)mem_ptr);
#else
png_destroy_struct((png_voidp)png_ptr);
#endif
*png_ptr_ptr = (png_structp)NULL;
*png_ptr_ptr = NULL;
}
}
/* free all memory used by the read (old method) */
void PNGAPI
void /* PRIVATE */
png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr)
{
#ifdef PNG_SETJMP_SUPPORTED
@ -1066,7 +1144,6 @@ png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr
#endif
png_debug(1, "in png_read_destroy\n");
/* save jump buffer and error functions */
if (info_ptr != NULL)
png_info_destroy(png_ptr, info_ptr);
@ -1074,7 +1151,7 @@ png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr
png_info_destroy(png_ptr, end_info_ptr);
png_free(png_ptr, png_ptr->zbuf);
png_free(png_ptr, png_ptr->row_buf);
png_free(png_ptr, png_ptr->big_row_buf);
png_free(png_ptr, png_ptr->prev_row);
#if defined(PNG_READ_DITHER_SUPPORTED)
png_free(png_ptr, png_ptr->palette_lookup);
@ -1162,6 +1239,12 @@ png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr
png_free(png_ptr, png_ptr->save_buffer);
#endif
#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
#ifdef PNG_TEXT_SUPPORTED
png_free(png_ptr, png_ptr->current_text);
#endif /* PNG_TEXT_SUPPORTED */
#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
/* Save the important info out of the png_struct, in case it is
* being used again.
*/
@ -1305,7 +1388,7 @@ png_read_png(png_structp png_ptr, png_infop info_ptr,
/* Optional call to gamma correct and add the background to the palette
* and update info structure. REQUIRED if you are expecting libpng to
* update the palette for you (ie you selected such a transform above).
* update the palette for you (i.e., you selected such a transform above).
*/
png_read_update_info(png_ptr, info_ptr);
@ -1317,13 +1400,15 @@ png_read_png(png_structp png_ptr, png_infop info_ptr,
if(info_ptr->row_pointers == NULL)
{
info_ptr->row_pointers = (png_bytepp)png_malloc(png_ptr,
info_ptr->height * sizeof(png_bytep));
info_ptr->height * sizeof(png_bytep));
#ifdef PNG_FREE_ME_SUPPORTED
info_ptr->free_me |= PNG_FREE_ROWS;
#endif
for (row = 0; row < (int)info_ptr->height; row++)
info_ptr->row_pointers[row] = png_malloc(png_ptr,
{
info_ptr->row_pointers[row] = (png_bytep)png_malloc(png_ptr,
png_get_rowbytes(png_ptr, info_ptr));
}
}
png_read_image(png_ptr, info_ptr->row_pointers);
@ -1332,7 +1417,7 @@ png_read_png(png_structp png_ptr, png_infop info_ptr,
/* read rest of file, and get additional chunks in info_ptr - REQUIRED */
png_read_end(png_ptr, info_ptr);
if(transforms == 0 || params == (voidp)NULL)
if(transforms == 0 || params == NULL)
/* quiet compiler warnings */ return;
}

Просмотреть файл

@ -1,9 +1,9 @@
/* pngrio.c - functions for data input
*
* libpng 1.0.9 - January 31, 2001
* libpng 1.2.5 - October 2, 2002
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2001 Glenn Randers-Pehrson
* Copyright (c) 1998-2002 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*
@ -26,7 +26,7 @@
void /* PRIVATE */
png_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
{
png_debug1(4,"reading %d bytes\n", length);
png_debug1(4,"reading %d bytes\n", (int)length);
if (png_ptr->read_data_fn != NULL)
(*(png_ptr->read_data_fn))(png_ptr, data, length);
else
@ -39,7 +39,7 @@ png_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
read_data function and use it at run time with png_set_read_fn(), rather
than changing the library. */
#ifndef USE_FAR_KEYWORD
static void /* PRIVATE */
void PNGAPI
png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
{
png_size_t check;
@ -159,4 +159,3 @@ png_set_read_fn(png_structp png_ptr, png_voidp io_ptr,
png_ptr->output_flush_fn = NULL;
#endif
}

Просмотреть файл

@ -1,9 +1,9 @@
/* pngrtran.c - transforms the data in a row for PNG readers
*
* libpng 1.0.9 - January 31, 2001
* libpng 1.2.5 - October 2, 2002
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2001 Glenn Randers-Pehrson
* Copyright (c) 1998-2002 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*
@ -167,15 +167,14 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
Perhaps not the best solution, but good enough. */
int i;
png_bytep sort;
/* initialize an array to sort colors */
sort = (png_bytep)png_malloc(png_ptr, (png_uint_32)(num_palette
* sizeof (png_byte)));
png_ptr->dither_sort = (png_bytep)png_malloc(png_ptr,
(png_uint_32)(num_palette * sizeof (png_byte)));
/* initialize the sort array */
/* initialize the dither_sort array */
for (i = 0; i < num_palette; i++)
sort[i] = (png_byte)i;
png_ptr->dither_sort[i] = (png_byte)i;
/* Find the least used palette entries by starting a
bubble sort, and running it until we have sorted
@ -191,13 +190,14 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
done = 1;
for (j = 0; j < i; j++)
{
if (histogram[sort[j]] < histogram[sort[j + 1]])
if (histogram[png_ptr->dither_sort[j]]
< histogram[png_ptr->dither_sort[j + 1]])
{
png_byte t;
t = sort[j];
sort[j] = sort[j + 1];
sort[j + 1] = t;
t = png_ptr->dither_sort[j];
png_ptr->dither_sort[j] = png_ptr->dither_sort[j + 1];
png_ptr->dither_sort[j + 1] = t;
done = 0;
}
}
@ -214,11 +214,11 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
move the others */
for (i = 0; i < maximum_colors; i++)
{
if ((int)sort[i] >= maximum_colors)
if ((int)png_ptr->dither_sort[i] >= maximum_colors)
{
do
j--;
while ((int)sort[j] >= maximum_colors);
while ((int)png_ptr->dither_sort[j] >= maximum_colors);
palette[i] = palette[j];
}
}
@ -232,13 +232,13 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
for (i = 0; i < maximum_colors; i++)
{
/* only move the colors we need to */
if ((int)sort[i] >= maximum_colors)
if ((int)png_ptr->dither_sort[i] >= maximum_colors)
{
png_color tmp_color;
do
j--;
while ((int)sort[j] >= maximum_colors);
while ((int)png_ptr->dither_sort[j] >= maximum_colors);
tmp_color = palette[j];
palette[j] = palette[i];
@ -276,7 +276,8 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
}
}
}
png_free(png_ptr, sort);
png_free(png_ptr, png_ptr->dither_sort);
png_ptr->dither_sort=NULL;
}
else
{
@ -291,23 +292,22 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
int i;
int max_d;
int num_new_palette;
png_dsortp t;
png_dsortpp hash;
png_bytep index_to_palette;
/* where the original index currently is in the palette */
png_bytep palette_to_index;
/* which original index points to this palette color */
t=NULL;
/* initialize palette index arrays */
index_to_palette = (png_bytep)png_malloc(png_ptr,
png_ptr->index_to_palette = (png_bytep)png_malloc(png_ptr,
(png_uint_32)(num_palette * sizeof (png_byte)));
palette_to_index = (png_bytep)png_malloc(png_ptr,
png_ptr->palette_to_index = (png_bytep)png_malloc(png_ptr,
(png_uint_32)(num_palette * sizeof (png_byte)));
/* initialize the sort array */
for (i = 0; i < num_palette; i++)
{
index_to_palette[i] = (png_byte)i;
palette_to_index[i] = (png_byte)i;
png_ptr->index_to_palette[i] = (png_byte)i;
png_ptr->palette_to_index[i] = (png_byte)i;
}
hash = (png_dsortpp)png_malloc(png_ptr, (png_uint_32)(769 *
@ -342,18 +342,22 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
if (d <= max_d)
{
png_dsortp t;
t = (png_dsortp)png_malloc(png_ptr, (png_uint_32)(sizeof
(png_dsort)));
t = (png_dsortp)png_malloc_warn(png_ptr,
(png_uint_32)(sizeof(png_dsort)));
if (t == NULL)
break;
t->next = hash[d];
t->left = (png_byte)i;
t->right = (png_byte)j;
hash[d] = t;
}
}
if (t == NULL)
break;
}
if (t != NULL)
for (i = 0; i <= max_d; i++)
{
if (hash[i] != NULL)
@ -362,8 +366,10 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
for (p = hash[i]; p; p = p->next)
{
if ((int)index_to_palette[p->left] < num_new_palette &&
(int)index_to_palette[p->right] < num_new_palette)
if ((int)png_ptr->index_to_palette[p->left]
< num_new_palette &&
(int)png_ptr->index_to_palette[p->right]
< num_new_palette)
{
int j, next_j;
@ -379,7 +385,8 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
}
num_new_palette--;
palette[index_to_palette[j]] = palette[num_new_palette];
palette[png_ptr->index_to_palette[j]]
= palette[num_new_palette];
if (!full_dither)
{
int k;
@ -387,23 +394,23 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
for (k = 0; k < num_palette; k++)
{
if (png_ptr->dither_index[k] ==
index_to_palette[j])
png_ptr->index_to_palette[j])
png_ptr->dither_index[k] =
index_to_palette[next_j];
png_ptr->index_to_palette[next_j];
if ((int)png_ptr->dither_index[k] ==
num_new_palette)
png_ptr->dither_index[k] =
index_to_palette[j];
png_ptr->index_to_palette[j];
}
}
index_to_palette[palette_to_index[num_new_palette]] =
index_to_palette[j];
palette_to_index[index_to_palette[j]] =
palette_to_index[num_new_palette];
png_ptr->index_to_palette[png_ptr->palette_to_index
[num_new_palette]] = png_ptr->index_to_palette[j];
png_ptr->palette_to_index[png_ptr->index_to_palette[j]]
= png_ptr->palette_to_index[num_new_palette];
index_to_palette[j] = (png_byte)num_new_palette;
palette_to_index[num_new_palette] = (png_byte)j;
png_ptr->index_to_palette[j] = (png_byte)num_new_palette;
png_ptr->palette_to_index[num_new_palette] = (png_byte)j;
}
if (num_new_palette <= maximum_colors)
break;
@ -420,8 +427,6 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
png_dsortp p = hash[i];
while (p)
{
png_dsortp t;
t = p->next;
png_free(png_ptr, p);
p = t;
@ -432,8 +437,10 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
max_d += 96;
}
png_free(png_ptr, hash);
png_free(png_ptr, palette_to_index);
png_free(png_ptr, index_to_palette);
png_free(png_ptr, png_ptr->palette_to_index);
png_free(png_ptr, png_ptr->index_to_palette);
png_ptr->palette_to_index=NULL;
png_ptr->index_to_palette=NULL;
}
num_palette = maximum_colors;
}
@ -510,13 +517,19 @@ png_set_dither(png_structp png_ptr, png_colorp palette,
* only do transformations on images where the file_gamma and screen_gamma
* are not close reciprocals, otherwise it slows things down slightly, and
* also needlessly introduces small errors.
*
* We will turn off gamma transformation later if no semitransparent entries
* are present in the tRNS array for palette images. We can't do it here
* because we don't necessarily have the tRNS chunk yet.
*/
void PNGAPI
png_set_gamma(png_structp png_ptr, double scrn_gamma, double file_gamma)
{
png_debug(1, "in png_set_gamma\n");
if (fabs(scrn_gamma * file_gamma - 1.0) > PNG_GAMMA_THRESHOLD)
png_ptr->transformations |= PNG_GAMMA;
if ((fabs(scrn_gamma * file_gamma - 1.0) > PNG_GAMMA_THRESHOLD) ||
(png_ptr->color_type & PNG_COLOR_MASK_ALPHA) ||
(png_ptr->color_type == PNG_COLOR_TYPE_PALETTE))
png_ptr->transformations |= PNG_GAMMA;
png_ptr->gamma = (float)file_gamma;
png_ptr->screen_gamma = (float)scrn_gamma;
}
@ -692,23 +705,23 @@ png_init_read_transformations(png_structp png_ptr)
{
case 1:
png_ptr->background.gray *= (png_uint_16)0xff;
png_ptr->background.red = png_ptr->background.green =
png_ptr->background.blue = png_ptr->background.gray;
png_ptr->background.red = png_ptr->background.green
= png_ptr->background.blue = png_ptr->background.gray;
break;
case 2:
png_ptr->background.gray *= (png_uint_16)0x55;
png_ptr->background.red = png_ptr->background.green =
png_ptr->background.blue = png_ptr->background.gray;
png_ptr->background.red = png_ptr->background.green
= png_ptr->background.blue = png_ptr->background.gray;
break;
case 4:
png_ptr->background.gray *= (png_uint_16)0x11;
png_ptr->background.red = png_ptr->background.green =
png_ptr->background.blue = png_ptr->background.gray;
png_ptr->background.red = png_ptr->background.green
= png_ptr->background.blue = png_ptr->background.gray;
break;
case 8:
case 16:
png_ptr->background.red = png_ptr->background.green =
png_ptr->background.blue = png_ptr->background.gray;
png_ptr->background.red = png_ptr->background.green
= png_ptr->background.blue = png_ptr->background.gray;
break;
}
}
@ -742,10 +755,26 @@ png_init_read_transformations(png_structp png_ptr)
}
#endif
#if defined(PNG_READ_BACKGROUND_SUPPORTED)
#if defined(PNG_READ_BACKGROUND_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
png_ptr->background_1 = png_ptr->background;
#endif
#if defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
if ((color_type == PNG_COLOR_TYPE_PALETTE && png_ptr->num_trans != 0)
&& (fabs(png_ptr->screen_gamma * png_ptr->gamma - 1.0)
< PNG_GAMMA_THRESHOLD))
{
int i,k;
k=0;
for (i=0; i<png_ptr->num_trans; i++)
{
if (png_ptr->trans[i] != 0 && png_ptr->trans[i] != 0xff)
k=1; /* partial transparency is present */
}
if (k == 0)
png_ptr->transformations &= (~PNG_GAMMA);
}
if (png_ptr->transformations & (PNG_GAMMA | PNG_RGB_TO_GRAY))
{
png_build_gamma_table(png_ptr);
@ -754,6 +783,8 @@ png_init_read_transformations(png_structp png_ptr)
{
if (color_type == PNG_COLOR_TYPE_PALETTE)
{
/* could skip if no transparency and
*/
png_color back, back_1;
png_colorp palette = png_ptr->palette;
int num_palette = png_ptr->num_palette;
@ -848,7 +879,7 @@ png_init_read_transformations(png_structp png_ptr)
}
}
}
/* if (png_ptr->background_gamma_type!=PNG_BACKGROUND_GAMMA_UNKNOWN)*/
/* if (png_ptr->background_gamma_type!=PNG_BACKGROUND_GAMMA_UNKNOWN) */
else
/* color_type != PNG_COLOR_TYPE_PALETTE */
{
@ -873,9 +904,16 @@ png_init_read_transformations(png_structp png_ptr)
break;
}
if (color_type & PNG_COLOR_MASK_COLOR)
png_ptr->background_1.gray = (png_uint_16)(pow(
(double)png_ptr->background.gray / m, g) * m + .5);
png_ptr->background.gray = (png_uint_16)(pow(
(double)png_ptr->background.gray / m, gs) * m + .5);
if ((png_ptr->background.red != png_ptr->background.green) ||
(png_ptr->background.red != png_ptr->background.blue) ||
(png_ptr->background.red != png_ptr->background.gray))
{
/* RGB or RGBA */
/* RGB or RGBA with color background */
png_ptr->background_1.red = (png_uint_16)(pow(
(double)png_ptr->background.red / m, g) * m + .5);
png_ptr->background_1.green = (png_uint_16)(pow(
@ -891,17 +929,17 @@ png_init_read_transformations(png_structp png_ptr)
}
else
{
/* GRAY or GRAY ALPHA */
png_ptr->background_1.gray = (png_uint_16)(pow(
(double)png_ptr->background.gray / m, g) * m + .5);
png_ptr->background.gray = (png_uint_16)(pow(
(double)png_ptr->background.gray / m, gs) * m + .5);
/* GRAY, GRAY ALPHA, RGB, or RGBA with gray background */
png_ptr->background_1.red = png_ptr->background_1.green
= png_ptr->background_1.blue = png_ptr->background_1.gray;
png_ptr->background.red = png_ptr->background.green
= png_ptr->background.blue = png_ptr->background.gray;
}
}
}
else
/* transformation does not include PNG_BACKGROUND */
#endif
#endif /* PNG_READ_BACKGROUND_SUPPORTED */
if (color_type == PNG_COLOR_TYPE_PALETTE)
{
png_colorp palette = png_ptr->palette;
@ -919,7 +957,7 @@ png_init_read_transformations(png_structp png_ptr)
#if defined(PNG_READ_BACKGROUND_SUPPORTED)
else
#endif
#endif
#endif /* PNG_READ_GAMMA_SUPPORTED && PNG_FLOATING_POINT_SUPPORTED */
#if defined(PNG_READ_BACKGROUND_SUPPORTED)
/* No GAMMA transformation */
if ((png_ptr->transformations & PNG_BACKGROUND) &&
@ -952,7 +990,7 @@ png_init_read_transformations(png_structp png_ptr)
}
}
}
#endif
#endif /* PNG_READ_BACKGROUND_SUPPORTED */
#if defined(PNG_READ_SHIFT_SUPPORTED)
if ((png_ptr->transformations & PNG_SHIFT) &&
@ -977,7 +1015,7 @@ png_init_read_transformations(png_structp png_ptr)
png_ptr->palette[i].blue >>= sb;
}
}
#endif
#endif /* PNG_READ_SHIFT_SUPPORTED */
}
#if !defined(PNG_READ_GAMMA_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED) \
&& !defined(PNG_READ_BACKGROUND_SUPPORTED)
@ -1227,12 +1265,15 @@ From Andreas Dilger e-mail to png-implement, 26 March 1998:
((png_ptr->num_trans != 0 ) ||
(png_ptr->color_type & PNG_COLOR_MASK_ALPHA)))
png_do_background(&(png_ptr->row_info), png_ptr->row_buf + 1,
&(png_ptr->trans_values), &(png_ptr->background),
&(png_ptr->background_1),
&(png_ptr->trans_values), &(png_ptr->background)
#if defined(PNG_READ_GAMMA_SUPPORTED)
, &(png_ptr->background_1),
png_ptr->gamma_table, png_ptr->gamma_from_1,
png_ptr->gamma_to_1, png_ptr->gamma_16_table,
png_ptr->gamma_16_from_1, png_ptr->gamma_16_to_1,
png_ptr->gamma_shift);
png_ptr->gamma_shift
#endif
);
#endif
#if defined(PNG_READ_GAMMA_SUPPORTED)
@ -2312,7 +2353,7 @@ png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
* paletted. Most useful for gamma correction and simplification
* of code.
*/
void /* PRIVATE */
void PNGAPI
png_build_grayscale_palette(int bit_depth, png_colorp palette)
{
int num_palette;
@ -2545,11 +2586,14 @@ png_correct_palette(png_structp png_ptr, png_colorp palette,
*/
void /* PRIVATE */
png_do_background(png_row_infop row_info, png_bytep row,
png_color_16p trans_values, png_color_16p background,
png_color_16p background_1,
png_color_16p trans_values, png_color_16p background
#if defined(PNG_READ_GAMMA_SUPPORTED)
, png_color_16p background_1,
png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1,
png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1,
png_uint_16pp gamma_16_to_1, int gamma_shift)
png_uint_16pp gamma_16_to_1, int gamma_shift
#endif
)
{
png_bytep sp, dp;
png_uint_32 i;
@ -2932,6 +2976,7 @@ png_do_background(png_row_infop row_info, png_bytep row,
{
*dp = *sp;
}
#if defined(PNG_READ_GAMMA_SUPPORTED)
else if (a == 0)
{
*dp = (png_byte)background->gray;
@ -2940,6 +2985,9 @@ png_do_background(png_row_infop row_info, png_bytep row,
{
png_composite(*dp, *sp, a, background_1->gray);
}
#else
*dp = (png_byte)background->gray;
#endif
}
}
}
@ -2963,12 +3011,17 @@ png_do_background(png_row_infop row_info, png_bytep row,
*dp = (png_byte)((v >> 8) & 0xff);
*(dp + 1) = (png_byte)(v & 0xff);
}
#if defined(PNG_READ_GAMMA_SUPPORTED)
else if (a == 0)
#else
else
#endif
{
/* background is already in screen gamma */
*dp = (png_byte)((background->gray >> 8) & 0xff);
*(dp + 1) = (png_byte)(background->gray & 0xff);
}
#if defined(PNG_READ_GAMMA_SUPPORTED)
else
{
png_uint_16 g, v, w;
@ -2979,6 +3032,7 @@ png_do_background(png_row_infop row_info, png_bytep row,
*dp = (png_byte)((w >> 8) & 0xff);
*(dp + 1) = (png_byte)(w & 0xff);
}
#endif
}
}
else
@ -2993,11 +3047,16 @@ png_do_background(png_row_infop row_info, png_bytep row,
{
png_memcpy(dp, sp, 2);
}
#if defined(PNG_READ_GAMMA_SUPPORTED)
else if (a == 0)
#else
else
#endif
{
*dp = (png_byte)((background->gray >> 8) & 0xff);
*(dp + 1) = (png_byte)(background->gray & 0xff);
}
#if defined(PNG_READ_GAMMA_SUPPORTED)
else
{
png_uint_16 g, v;
@ -3007,6 +3066,7 @@ png_do_background(png_row_infop row_info, png_bytep row,
*dp = (png_byte)((v >> 8) & 0xff);
*(dp + 1) = (png_byte)(v & 0xff);
}
#endif
}
}
}
@ -3128,17 +3188,17 @@ png_do_background(png_row_infop row_info, png_bytep row,
png_uint_16 v, w, x;
v = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
png_composite_16(w, v, a, background->red);
png_composite_16(w, v, a, background_1->red);
x = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8];
*dp = (png_byte)((x >> 8) & 0xff);
*(dp + 1) = (png_byte)(x & 0xff);
v = gamma_16_to_1[*(sp + 3) >> gamma_shift][*(sp + 2)];
png_composite_16(w, v, a, background->green);
png_composite_16(w, v, a, background_1->green);
x = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8];
*(dp + 2) = (png_byte)((x >> 8) & 0xff);
*(dp + 3) = (png_byte)(x & 0xff);
v = gamma_16_to_1[*(sp + 5) >> gamma_shift][*(sp + 4)];
png_composite_16(w, v, a, background->blue);
png_composite_16(w, v, a, background_1->blue);
x = gamma_16_from_1[(w & 0xff) >> gamma_shift][w >> 8];
*(dp + 4) = (png_byte)((x >> 8) & 0xff);
*(dp + 5) = (png_byte)(x & 0xff);

Просмотреть файл

@ -1,9 +1,9 @@
/* pngrutil.c - utilities to read a PNG file
*
* libpng 1.0.9 - January 31, 2001
* libpng 1.2.5 - October 2, 2002
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2001 Glenn Randers-Pehrson
* Copyright (c) 1998-2002 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*
@ -30,7 +30,7 @@ __inline double strtod(const char *nptr, char **endptr)
MultiByteToWideChar(CP_ACP, 0, nptr, -1, str, len);
result = wcstod(str, &end);
len = WideCharToMultiByte(CP_ACP, 0, end, -1, NULL, 0, NULL, NULL);
*endptr = (char *)nptr + (strlen(nptr) - len + 1);
*endptr = (char *)nptr + (png_strlen(nptr) - len + 1);
free(str);
}
return result;
@ -200,7 +200,12 @@ png_decompress_chunk(png_structp png_ptr, int comp_type,
if (text == NULL)
{
text_size = prefix_size + sizeof(msg) + 1;
text = (png_charp)png_malloc(png_ptr, text_size);
text = (png_charp)png_malloc_warn(png_ptr, text_size);
if (text == NULL)
{
png_free(png_ptr,chunkdata);
png_error(png_ptr,"Not enough memory to decompress chunk");
}
png_memcpy(text, chunkdata, prefix_size);
}
@ -218,9 +223,14 @@ png_decompress_chunk(png_structp png_ptr, int comp_type,
{
text_size = prefix_size +
png_ptr->zbuf_size - png_ptr->zstream.avail_out;
text = (png_charp)png_malloc(png_ptr, text_size + 1);
text = (png_charp)png_malloc_warn(png_ptr, text_size + 1);
if (text == NULL)
{
png_free(png_ptr,chunkdata);
png_error(png_ptr,"Not enough memory to decompress chunk.");
}
png_memcpy(text + prefix_size, png_ptr->zbuf,
text_size - prefix_size);
text_size - prefix_size);
png_memcpy(text, chunkdata, prefix_size);
*(text + text_size) = 0x00;
}
@ -229,8 +239,15 @@ png_decompress_chunk(png_structp png_ptr, int comp_type,
png_charp tmp;
tmp = text;
text = (png_charp)png_malloc(png_ptr, (png_uint_32)(text_size +
text = (png_charp)png_malloc_warn(png_ptr,
(png_uint_32)(text_size +
png_ptr->zbuf_size - png_ptr->zstream.avail_out + 1));
if (text == NULL)
{
png_free(png_ptr, tmp);
png_free(png_ptr, chunkdata);
png_error(png_ptr,"Not enough memory to decompress chunk..");
}
png_memcpy(text, tmp, text_size);
png_free(png_ptr, tmp);
png_memcpy(text + text_size, png_ptr->zbuf,
@ -269,7 +286,12 @@ png_decompress_chunk(png_structp png_ptr, int comp_type,
text_size=prefix_size;
if (text == NULL)
{
text = (png_charp)png_malloc(png_ptr, text_size+1);
text = (png_charp)png_malloc_warn(png_ptr, text_size+1);
if (text == NULL)
{
png_free(png_ptr, chunkdata);
png_error(png_ptr,"Not enough memory for text.");
}
png_memcpy(text, chunkdata, prefix_size);
}
*(text + text_size) = 0x00;
@ -332,59 +354,6 @@ png_handle_IHDR(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
filter_type = buf[11];
interlace_type = buf[12];
/* check for width and height valid values */
if (width == 0 || width > PNG_MAX_UINT || height == 0 ||
height > PNG_MAX_UINT)
png_error(png_ptr, "Invalid image size in IHDR");
/* check other values */
if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 &&
bit_depth != 8 && bit_depth != 16)
png_error(png_ptr, "Invalid bit depth in IHDR");
if (color_type < 0 || color_type == 1 ||
color_type == 5 || color_type > 6)
png_error(png_ptr, "Invalid color type in IHDR");
if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) ||
((color_type == PNG_COLOR_TYPE_RGB ||
color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8))
png_error(png_ptr, "Invalid color type/bit depth combination in IHDR");
if (interlace_type >= PNG_INTERLACE_LAST)
png_error(png_ptr, "Unknown interlace method in IHDR");
if (compression_type != PNG_COMPRESSION_TYPE_BASE)
png_error(png_ptr, "Unknown compression method in IHDR");
#if defined(PNG_MNG_FEATURES_SUPPORTED)
/* Accept filter_method 64 (intrapixel differencing) only if
* 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and
* 2. Libpng did not read a PNG signature (this filter_method is only
* used in PNG datastreams that are embedded in MNG datastreams) and
* 3. The application called png_permit_mng_features with a mask that
* included PNG_FLAG_MNG_FILTER_64 and
* 4. The filter_method is 64 and
* 5. The color_type is RGB or RGBA
*/
if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&png_ptr->mng_features_permitted)
png_warning(png_ptr,"MNG features are not allowed in a PNG datastream\n");
if(filter_type != PNG_FILTER_TYPE_BASE)
{
if(!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
(filter_type == PNG_INTRAPIXEL_DIFFERENCING) &&
((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
(color_type == PNG_COLOR_TYPE_RGB ||
color_type == PNG_COLOR_TYPE_RGB_ALPHA)))
png_error(png_ptr, "Unknown filter method in IHDR");
if(png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)
png_warning(png_ptr, "Invalid filter method in IHDR");
}
#else
if(filter_type != PNG_FILTER_TYPE_BASE)
png_error(png_ptr, "Unknown filter method in IHDR");
#endif
/* set internal variables */
png_ptr->width = width;
@ -392,7 +361,9 @@ png_handle_IHDR(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_ptr->bit_depth = (png_byte)bit_depth;
png_ptr->interlaced = (png_byte)interlace_type;
png_ptr->color_type = (png_byte)color_type;
#if defined(PNG_MNG_FEATURES_SUPPORTED)
png_ptr->filter_type = (png_byte)filter_type;
#endif
/* find number of channels */
switch (png_ptr->color_type)
@ -449,6 +420,13 @@ png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_ptr->mode |= PNG_HAVE_PLTE;
if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR))
{
png_warning(png_ptr,
"Ignoring PLTE chunk in grayscale PNG");
png_crc_finish(png_ptr, length);
return;
}
#if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
{
@ -565,9 +543,7 @@ png_handle_IEND(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
{
png_error(png_ptr, "No image in file");
/* to quiet compiler warnings about unused info_ptr */
if (info_ptr == NULL)
return;
info_ptr = info_ptr; /* quiet compiler warnings about unused info_ptr */
}
png_ptr->mode |= (PNG_AFTER_IDAT | PNG_HAVE_IEND);
@ -628,7 +604,11 @@ png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
igamma = (png_fixed_point)png_get_uint_32(buf);
/* check for zero gamma */
if (igamma == 0)
return;
{
png_warning(png_ptr,
"Ignoring gAMA chunk with gamma=0");
return;
}
#if defined(PNG_READ_sRGB_SUPPORTED)
if (info_ptr->valid & PNG_INFO_sRGB)
@ -733,6 +713,8 @@ png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_fixed_point int_x_white, int_y_white, int_x_red, int_y_red, int_x_green,
int_y_green, int_x_blue, int_y_blue;
png_uint_32 uint_x, uint_y;
png_debug(1, "in png_handle_cHRM\n");
if (!(png_ptr->mode & PNG_HAVE_IHDR))
@ -766,60 +748,69 @@ png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
}
png_crc_read(png_ptr, buf, 4);
int_x_white = (png_fixed_point)png_get_uint_32(buf);
uint_x = png_get_uint_32(buf);
png_crc_read(png_ptr, buf, 4);
int_y_white = (png_fixed_point)png_get_uint_32(buf);
uint_y = png_get_uint_32(buf);
if (int_x_white > 80000L || int_y_white > 80000L ||
int_x_white + int_y_white > 100000L)
if (uint_x > 80000L || uint_y > 80000L ||
uint_x + uint_y > 100000L)
{
png_warning(png_ptr, "Invalid cHRM white point");
png_crc_finish(png_ptr, 24);
return;
}
int_x_white = (png_fixed_point)uint_x;
int_y_white = (png_fixed_point)uint_y;
png_crc_read(png_ptr, buf, 4);
int_x_red = (png_fixed_point)png_get_uint_32(buf);
uint_x = png_get_uint_32(buf);
png_crc_read(png_ptr, buf, 4);
int_y_red = (png_fixed_point)png_get_uint_32(buf);
uint_y = png_get_uint_32(buf);
if (int_x_red > 80000L || int_y_red > 80000L ||
int_x_red + int_y_red > 100000L)
if (uint_x > 80000L || uint_y > 80000L ||
uint_x + uint_y > 100000L)
{
png_warning(png_ptr, "Invalid cHRM red point");
png_crc_finish(png_ptr, 16);
return;
}
int_x_red = (png_fixed_point)uint_x;
int_y_red = (png_fixed_point)uint_y;
png_crc_read(png_ptr, buf, 4);
int_x_green = (png_fixed_point)png_get_uint_32(buf);
uint_x = png_get_uint_32(buf);
png_crc_read(png_ptr, buf, 4);
int_y_green = (png_fixed_point)png_get_uint_32(buf);
uint_y = png_get_uint_32(buf);
if (int_x_green > 80000L || int_y_green > 80000L ||
int_x_green + int_y_green > 100000L)
if (uint_x > 80000L || uint_y > 80000L ||
uint_x + uint_y > 100000L)
{
png_warning(png_ptr, "Invalid cHRM green point");
png_crc_finish(png_ptr, 8);
return;
}
int_x_green = (png_fixed_point)uint_x;
int_y_green = (png_fixed_point)uint_y;
png_crc_read(png_ptr, buf, 4);
int_x_blue = (png_fixed_point)png_get_uint_32(buf);
uint_x = png_get_uint_32(buf);
png_crc_read(png_ptr, buf, 4);
int_y_blue = (png_fixed_point)png_get_uint_32(buf);
uint_y = png_get_uint_32(buf);
if (int_x_blue > 80000L || int_y_blue > 80000L ||
int_x_blue + int_y_blue > 100000L)
if (uint_x > 80000L || uint_y > 80000L ||
uint_x + uint_y > 100000L)
{
png_warning(png_ptr, "Invalid cHRM blue point");
png_crc_finish(png_ptr, 0);
return;
}
int_x_blue = (png_fixed_point)uint_x;
int_y_blue = (png_fixed_point)uint_y;
#ifdef PNG_FLOATING_POINT_SUPPORTED
white_x = (float)int_x_white / (float)100000.0;
white_y = (float)int_y_white / (float)100000.0;
@ -836,12 +827,12 @@ png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
{
if (abs(int_x_white - 31270L) > 1000 ||
abs(int_y_white - 32900L) > 1000 ||
abs( int_x_red - 64000L) > 1000 ||
abs( int_y_red - 33000L) > 1000 ||
abs(int_x_red - 64000L) > 1000 ||
abs(int_y_red - 33000L) > 1000 ||
abs(int_x_green - 30000L) > 1000 ||
abs(int_y_green - 60000L) > 1000 ||
abs( int_x_blue - 15000L) > 1000 ||
abs( int_y_blue - 6000L) > 1000)
abs(int_x_blue - 15000L) > 1000 ||
abs(int_y_blue - 6000L) > 1000)
{
png_warning(png_ptr,
@ -936,17 +927,6 @@ png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
# ifdef PNG_FLOATING_POINT_SUPPORTED
igamma=(int)(info_ptr->gamma * 100000.);
# endif
#endif
#if 0 && defined(PNG_cHRM_SUPPORTED) && !defined(PNG_FIXED_POINT_SUPPORTED)
/* We need to define these here because they aren't in png.h */
png_fixed_point int_x_white;
png_fixed_point int_y_white;
png_fixed_point int_x_red;
png_fixed_point int_y_red;
png_fixed_point int_x_green;
png_fixed_point int_y_green;
png_fixed_point int_x_blue;
png_fixed_point int_y_blue;
#endif
if(igamma < 45000L || igamma > 46000L)
{
@ -970,12 +950,12 @@ png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
if (info_ptr->valid & PNG_INFO_cHRM)
if (abs(info_ptr->int_x_white - 31270L) > 1000 ||
abs(info_ptr->int_y_white - 32900L) > 1000 ||
abs( info_ptr->int_x_red - 64000L) > 1000 ||
abs( info_ptr->int_y_red - 33000L) > 1000 ||
abs(info_ptr->int_x_red - 64000L) > 1000 ||
abs(info_ptr->int_y_red - 33000L) > 1000 ||
abs(info_ptr->int_x_green - 30000L) > 1000 ||
abs(info_ptr->int_y_green - 60000L) > 1000 ||
abs( info_ptr->int_x_blue - 15000L) > 1000 ||
abs( info_ptr->int_y_blue - 6000L) > 1000)
abs(info_ptr->int_x_blue - 15000L) > 1000 ||
abs(info_ptr->int_y_blue - 6000L) > 1000)
{
png_warning(png_ptr,
"Ignoring incorrect cHRM value when sRGB is also present");
@ -994,6 +974,7 @@ png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
{
png_charp chunkdata;
png_byte compression_type;
png_bytep pC;
png_charp profile;
png_uint_32 skip = 0;
png_uint_32 profile_size = 0;
@ -1070,18 +1051,20 @@ png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
slength, prefix_length, &data_length);
profile_length = data_length - prefix_length;
if (profile_length < 4)
if ( prefix_length > data_length || profile_length < 4)
{
png_free(png_ptr, chunkdata);
png_warning(png_ptr, "Profile length missing in iCCP chunk");
png_warning(png_ptr, "Profile size field missing from iCCP chunk");
return;
}
/* Check the profile_size recorded in the first 32 bits of the ICC profile */
profile_size = ((*(chunkdata+prefix_length))<<24) |
((*(chunkdata+prefix_length+1))<<16) |
((*(chunkdata+prefix_length+2))<< 8) |
((*(chunkdata+prefix_length+3)) );
pC = (png_bytep)(chunkdata+prefix_length);
profile_size = ((*(pC ))<<24) |
((*(pC+1))<<16) |
((*(pC+2))<< 8) |
((*(pC+3)) );
if(profile_size < profile_length)
profile_length = profile_size;
@ -1136,7 +1119,7 @@ png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
chunkdata = (png_bytep)png_malloc(png_ptr, length + 1);
slength = (png_size_t)length;
png_crc_read(png_ptr, chunkdata, slength);
png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
if (png_crc_finish(png_ptr, skip))
{
@ -1166,7 +1149,8 @@ png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
if (data_length % entry_size)
{
png_free(png_ptr, chunkdata);
png_error(png_ptr, "sPLT chunk has bad length");
png_warning(png_ptr, "sPLT chunk has bad length");
return;
}
new_palette.nentries = data_length / entry_size;
@ -1231,7 +1215,7 @@ png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
void /* PRIVATE */
png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
{
png_byte readbuf[PNG_MAX_PALETTE_LENGTH];
png_byte readbuf[PNG_MAX_PALETTE_LENGTH];
png_debug(1, "in png_handle_tRNS\n");
@ -1414,7 +1398,7 @@ void /* PRIVATE */
png_handle_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
{
int num, i;
png_uint_16 readbuf[PNG_MAX_PALETTE_LENGTH];
png_uint_16 readbuf[PNG_MAX_PALETTE_LENGTH];
png_debug(1, "in png_handle_hIST\n");
@ -1580,7 +1564,12 @@ png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_debug1(2, "Allocating and reading pCAL chunk data (%lu bytes)\n",
length + 1);
purpose = (png_charp)png_malloc(png_ptr, length + 1);
purpose = (png_charp)png_malloc_warn(png_ptr, length + 1);
if (purpose == NULL)
{
png_warning(png_ptr, "No memory for pCAL purpose.");
return;
}
slength = (png_size_t)length;
png_crc_read(png_ptr, (png_bytep)purpose, slength);
@ -1635,8 +1624,14 @@ png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
/* Empty loop to move past the units string. */ ;
png_debug(3, "Allocating pCAL parameters array\n");
params = (png_charpp)png_malloc(png_ptr, (png_uint_32)(nparams
params = (png_charpp)png_malloc_warn(png_ptr, (png_uint_32)(nparams
*sizeof(png_charp))) ;
if (params == NULL)
{
png_free(png_ptr, purpose);
png_warning(png_ptr, "No memory for pCAL params.");
return;
}
/* Get pointers to the start of each parameter string. */
for (i = 0; i < (int)nparams; i++)
@ -1700,7 +1695,12 @@ png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_debug1(2, "Allocating and reading sCAL chunk data (%lu bytes)\n",
length + 1);
buffer = (png_charp)png_malloc(png_ptr, length + 1);
buffer = (png_charp)png_malloc_warn(png_ptr, length + 1);
if (buffer == NULL)
{
png_warning(png_ptr, "Out of memory while processing sCAL chunk");
return;
}
slength = (png_size_t)length;
png_crc_read(png_ptr, (png_bytep)buffer, slength);
@ -1723,8 +1723,13 @@ png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
}
#else
#ifdef PNG_FIXED_POINT_SUPPORTED
swidth = (png_charp)png_malloc(png_ptr, strlen(ep) + 1);
png_memcpy(swidth, ep, (png_size_t)strlen(ep));
swidth = (png_charp)png_malloc_warn(png_ptr, png_strlen(ep) + 1);
if (swidth == NULL)
{
png_warning(png_ptr, "Out of memory while processing sCAL chunk width");
return;
}
png_memcpy(swidth, ep, (png_size_t)png_strlen(ep));
#endif
#endif
@ -1741,8 +1746,13 @@ png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
}
#else
#ifdef PNG_FIXED_POINT_SUPPORTED
sheight = (png_charp)png_malloc(png_ptr, strlen(ep) + 1);
png_memcpy(sheight, ep, (png_size_t)strlen(ep));
sheight = (png_charp)png_malloc_warn(png_ptr, png_strlen(ep) + 1);
if (swidth == NULL)
{
png_warning(png_ptr, "Out of memory while processing sCAL chunk height");
return;
}
png_memcpy(sheight, ep, (png_size_t)png_strlen(ep));
#endif
#endif
@ -1831,6 +1841,7 @@ png_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_charp text;
png_uint_32 skip = 0;
png_size_t slength;
int ret;
png_debug(1, "in png_handle_tEXt\n");
@ -1849,7 +1860,12 @@ png_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
}
#endif
key = (png_charp)png_malloc(png_ptr, length + 1);
key = (png_charp)png_malloc_warn(png_ptr, length + 1);
if (key == NULL)
{
png_warning(png_ptr, "No memory to process text chunk.");
return;
}
slength = (png_size_t)length;
png_crc_read(png_ptr, (png_bytep)key, slength);
@ -1867,7 +1883,13 @@ png_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
if (text != key + slength)
text++;
text_ptr = (png_textp)png_malloc(png_ptr, (png_uint_32)sizeof(png_text));
text_ptr = (png_textp)png_malloc_warn(png_ptr, (png_uint_32)sizeof(png_text));
if (text_ptr == NULL)
{
png_warning(png_ptr, "Not enough memory to process text chunk.");
png_free(png_ptr, key);
return;
}
text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
text_ptr->key = key;
#ifdef PNG_iTXt_SUPPORTED
@ -1878,10 +1900,12 @@ png_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
text_ptr->text = text;
text_ptr->text_length = png_strlen(text);
png_set_text(png_ptr, info_ptr, text_ptr, 1);
ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
png_free(png_ptr, key);
png_free(png_ptr, text_ptr);
if (ret)
png_warning(png_ptr, "Insufficient memory to process text chunk.");
}
#endif
@ -1894,6 +1918,7 @@ png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_charp chunkdata;
png_charp text;
int comp_type;
int ret;
png_size_t slength, prefix_len, data_len;
png_debug(1, "in png_handle_zTXt\n");
@ -1914,7 +1939,12 @@ png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
}
#endif
chunkdata = (png_charp)png_malloc(png_ptr, length + 1);
chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
if (chunkdata == NULL)
{
png_warning(png_ptr,"Out of memory processing zTXt chunk.");
return;
}
slength = (png_size_t)length;
png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
if (png_crc_finish(png_ptr, 0))
@ -1949,7 +1979,13 @@ png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
chunkdata = (png_charp)png_decompress_chunk(png_ptr, comp_type, chunkdata,
(png_size_t)length, prefix_len, &data_len);
text_ptr = (png_textp)png_malloc(png_ptr, (png_uint_32)sizeof(png_text));
text_ptr = (png_textp)png_malloc_warn(png_ptr, (png_uint_32)sizeof(png_text));
if (text_ptr == NULL)
{
png_warning(png_ptr,"Not enough memory to process zTXt chunk.");
png_free(png_ptr, chunkdata);
return;
}
text_ptr->compression = comp_type;
text_ptr->key = chunkdata;
#ifdef PNG_iTXt_SUPPORTED
@ -1960,10 +1996,12 @@ png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
text_ptr->text = chunkdata + prefix_len;
text_ptr->text_length = data_len;
png_set_text(png_ptr, info_ptr, text_ptr, 1);
ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
png_free(png_ptr, text_ptr);
png_free(png_ptr, chunkdata);
if (ret)
png_error(png_ptr, "Insufficient memory to store zTXt chunk.");
}
#endif
@ -1977,6 +2015,7 @@ png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_charp key, lang, text, lang_key;
int comp_flag;
int comp_type = 0;
int ret;
png_size_t slength, prefix_len, data_len;
png_debug(1, "in png_handle_iTXt\n");
@ -1998,7 +2037,12 @@ png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
}
#endif
chunkdata = (png_charp)png_malloc(png_ptr, length + 1);
chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
if (chunkdata == NULL)
{
png_warning(png_ptr, "No memory to process iTXt chunk.");
return;
}
slength = (png_size_t)length;
png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
if (png_crc_finish(png_ptr, 0))
@ -2044,7 +2088,13 @@ png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
(size_t)length, prefix_len, &data_len);
else
data_len=png_strlen(chunkdata + prefix_len);
text_ptr = (png_textp)png_malloc(png_ptr, (png_uint_32)sizeof(png_text));
text_ptr = (png_textp)png_malloc_warn(png_ptr, (png_uint_32)sizeof(png_text));
if (text_ptr == NULL)
{
png_warning(png_ptr,"Not enough memory to process iTXt chunk.");
png_free(png_ptr, chunkdata);
return;
}
text_ptr->compression = (int)comp_flag + 1;
text_ptr->lang_key = chunkdata+(lang_key-key);
text_ptr->lang = chunkdata+(lang-key);
@ -2053,10 +2103,12 @@ png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
text_ptr->key = chunkdata;
text_ptr->text = chunkdata + prefix_len;
png_set_text(png_ptr, info_ptr, text_ptr, 1);
ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
png_free(png_ptr, text_ptr);
png_free(png_ptr, chunkdata);
if (ret)
png_error(png_ptr, "Insufficient memory to store iTXt chunk.");
}
#endif
@ -2089,7 +2141,7 @@ png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
HANDLE_CHUNK_ALWAYS
#if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
&& png_ptr->read_user_chunk_fn == (png_user_chunk_ptr)NULL
&& png_ptr->read_user_chunk_fn == NULL
#endif
)
#endif
@ -2109,12 +2161,12 @@ png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
length = (png_uint_32)65535L;
}
#endif
strcpy((png_charp)chunk.name, (png_charp)png_ptr->chunk_name);
png_strcpy((png_charp)chunk.name, (png_charp)png_ptr->chunk_name);
chunk.data = (png_bytep)png_malloc(png_ptr, length);
png_crc_read(png_ptr, chunk.data, length);
chunk.size = length;
chunk.size = (png_size_t)length;
png_crc_read(png_ptr, (png_bytep)chunk.data, length);
#if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
if(png_ptr->read_user_chunk_fn != (png_user_chunk_ptr)NULL)
if(png_ptr->read_user_chunk_fn != NULL)
{
/* callback to user unknown chunk handler */
if ((*(png_ptr->read_user_chunk_fn)) (png_ptr, &chunk) <= 0)
@ -2122,7 +2174,10 @@ png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
if (!(png_ptr->chunk_name[0] & 0x20))
if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
HANDLE_CHUNK_ALWAYS)
{
png_free(png_ptr, chunk.data);
png_chunk_error(png_ptr, "unknown critical chunk");
}
png_set_unknown_chunks(png_ptr, info_ptr, &chunk, 1);
}
}
@ -2138,8 +2193,7 @@ png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_crc_finish(png_ptr, skip);
#if !defined(PNG_READ_USER_CHUNKS_SUPPORTED)
if (info_ptr == NULL)
/* quiet compiler warnings about unused info_ptr */ ;
info_ptr = info_ptr; /* quiet compiler warnings about unused info_ptr */
#endif
}
@ -2378,6 +2432,10 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask)
#ifdef PNG_READ_INTERLACING_SUPPORTED
#ifndef PNG_HAVE_ASSEMBLER_READ_INTERLACE /* else in pngvcrd.c, pnggccrd.c */
/* OLD pre-1.0.9 interface:
void png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
png_uint_32 transformations)
*/
void /* PRIVATE */
png_do_read_interlace(png_structp png_ptr)
{
@ -2596,9 +2654,7 @@ png_do_read_interlace(png_structp png_ptr)
(png_uint_32)row_info->pixel_depth + 7) >> 3);
}
#if !defined(PNG_READ_PACKSWAP_SUPPORTED)
/* silence compiler warning */
if (transformations)
return;
transformations = transformations; /* silence compiler warning */
#endif
}
#endif /* !PNG_HAVE_ASSEMBLER_READ_INTERLACE */
@ -2827,7 +2883,7 @@ png_read_finish_row(png_structp png_ptr)
{
if (!(png_ptr->zstream.avail_out) || png_ptr->zstream.avail_in ||
png_ptr->idat_size)
png_error(png_ptr, "Extra compressed data");
png_warning(png_ptr, "Extra compressed data");
png_ptr->mode |= PNG_AFTER_IDAT;
png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
break;
@ -2837,14 +2893,19 @@ png_read_finish_row(png_structp png_ptr)
"Decompression Error");
if (!(png_ptr->zstream.avail_out))
png_error(png_ptr, "Extra compressed data");
{
png_warning(png_ptr, "Extra compressed data.");
png_ptr->mode |= PNG_AFTER_IDAT;
png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
break;
}
}
png_ptr->zstream.avail_out = 0;
}
if (png_ptr->idat_size || png_ptr->zstream.avail_in)
png_error(png_ptr, "Extra compression data");
png_warning(png_ptr, "Extra compression data");
inflateReset(&png_ptr->zstream);
@ -3014,7 +3075,11 @@ defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
if (row_bytes > (png_uint_32)65536L)
png_error(png_ptr, "This image requires a row greater than 64KB");
#endif
png_ptr->row_buf = (png_bytep)png_malloc(png_ptr, row_bytes);
png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes+64);
png_ptr->row_buf = png_ptr->big_row_buf+32;
#if defined(PNG_DEBUG) && defined(PNG_USE_PNGGCCRD)
png_ptr->row_buf_size = row_bytes;
#endif
#ifdef PNG_MAX_MALLOC_64K
if ((png_uint_32)png_ptr->rowbytes + 1 > (png_uint_32)65536L)

Просмотреть файл

@ -1,9 +1,9 @@
/* pngset.c - storage of image information into info struct
*
* libpng 1.0.9 - January 31, 2001
* libpng 1.2.5 - October 2, 2002
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2001 Glenn Randers-Pehrson
* Copyright (c) 1998-2002 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*
@ -40,6 +40,25 @@ png_set_cHRM(png_structp png_ptr, png_infop info_ptr,
if (png_ptr == NULL || info_ptr == NULL)
return;
if (white_x < 0.0 || white_y < 0.0 ||
red_x < 0.0 || red_y < 0.0 ||
green_x < 0.0 || green_y < 0.0 ||
blue_x < 0.0 || blue_y < 0.0)
{
png_warning(png_ptr,
"Ignoring attempt to set negative chromaticity value");
return;
}
if (white_x > 21474.83 || white_y > 21474.83 ||
red_x > 21474.83 || red_y > 21474.83 ||
green_x > 21474.83 || green_y > 21474.83 ||
blue_x > 21474.83 || blue_y > 21474.83)
{
png_warning(png_ptr,
"Ignoring attempt to set chromaticity value exceeding 21474.83");
return;
}
info_ptr->x_white = (float)white_x;
info_ptr->y_white = (float)white_y;
info_ptr->x_red = (float)red_x;
@ -51,12 +70,12 @@ png_set_cHRM(png_structp png_ptr, png_infop info_ptr,
#ifdef PNG_FIXED_POINT_SUPPORTED
info_ptr->int_x_white = (png_fixed_point)(white_x*100000.+0.5);
info_ptr->int_y_white = (png_fixed_point)(white_y*100000.+0.5);
info_ptr->int_x_red = (png_fixed_point)(red_x*100000.+0.5);
info_ptr->int_y_red = (png_fixed_point)(red_y*100000.+0.5);
info_ptr->int_x_red = (png_fixed_point)( red_x*100000.+0.5);
info_ptr->int_y_red = (png_fixed_point)( red_y*100000.+0.5);
info_ptr->int_x_green = (png_fixed_point)(green_x*100000.+0.5);
info_ptr->int_y_green = (png_fixed_point)(green_y*100000.+0.5);
info_ptr->int_x_blue = (png_fixed_point)(blue_x*100000.+0.5);
info_ptr->int_y_blue = (png_fixed_point)(blue_y*100000.+0.5);
info_ptr->int_x_blue = (png_fixed_point)( blue_x*100000.+0.5);
info_ptr->int_y_blue = (png_fixed_point)( blue_y*100000.+0.5);
#endif
info_ptr->valid |= PNG_INFO_cHRM;
}
@ -72,6 +91,24 @@ png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
if (png_ptr == NULL || info_ptr == NULL)
return;
if (white_x < 0 || white_y < 0 ||
red_x < 0 || red_y < 0 ||
green_x < 0 || green_y < 0 ||
blue_x < 0 || blue_y < 0)
{
png_warning(png_ptr,
"Ignoring attempt to set negative chromaticity value");
return;
}
if (white_x > (double) PNG_MAX_UINT || white_y > (double) PNG_MAX_UINT ||
red_x > (double) PNG_MAX_UINT || red_y > (double) PNG_MAX_UINT ||
green_x > (double) PNG_MAX_UINT || green_y > (double) PNG_MAX_UINT ||
blue_x > (double) PNG_MAX_UINT || blue_y > (double) PNG_MAX_UINT)
{
png_warning(png_ptr,
"Ignoring attempt to set chromaticity value exceeding 21474.83");
return;
}
info_ptr->int_x_white = white_x;
info_ptr->int_y_white = white_y;
info_ptr->int_x_red = red_x;
@ -83,12 +120,12 @@ png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
#ifdef PNG_FLOATING_POINT_SUPPORTED
info_ptr->x_white = (float)(white_x/100000.);
info_ptr->y_white = (float)(white_y/100000.);
info_ptr->x_red = (float)(red_x/100000.);
info_ptr->y_red = (float)(red_y/100000.);
info_ptr->x_red = (float)( red_x/100000.);
info_ptr->y_red = (float)( red_y/100000.);
info_ptr->x_green = (float)(green_x/100000.);
info_ptr->y_green = (float)(green_y/100000.);
info_ptr->x_blue = (float)(blue_x/100000.);
info_ptr->y_blue = (float)(blue_y/100000.);
info_ptr->x_blue = (float)( blue_x/100000.);
info_ptr->y_blue = (float)( blue_y/100000.);
#endif
info_ptr->valid |= PNG_INFO_cHRM;
}
@ -100,53 +137,92 @@ png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
void PNGAPI
png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma)
{
double gamma;
png_debug1(1, "in %s storage function\n", "gAMA");
if (png_ptr == NULL || info_ptr == NULL)
return;
info_ptr->gamma = (float)file_gamma;
/* Check for overflow */
if (file_gamma > 21474.83)
{
png_warning(png_ptr, "Limiting gamma to 21474.83");
gamma=21474.83;
}
else
gamma=file_gamma;
info_ptr->gamma = (float)gamma;
#ifdef PNG_FIXED_POINT_SUPPORTED
info_ptr->int_gamma = (int)(file_gamma*100000.+.5);
info_ptr->int_gamma = (int)(gamma*100000.+.5);
#endif
info_ptr->valid |= PNG_INFO_gAMA;
if(gamma == 0.0)
png_warning(png_ptr, "Setting gamma=0");
}
#endif
#endif
void PNGAPI
png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point
int_gamma)
{
png_fixed_point gamma;
png_debug1(1, "in %s storage function\n", "gAMA");
if (png_ptr == NULL || info_ptr == NULL)
return;
if (int_gamma > (png_fixed_point) PNG_MAX_UINT)
{
png_warning(png_ptr, "Limiting gamma to 21474.83");
gamma=PNG_MAX_UINT;
}
else
{
if (int_gamma < 0)
{
png_warning(png_ptr, "Setting negative gamma to zero");
gamma=0;
}
else
gamma=int_gamma;
}
#ifdef PNG_FLOATING_POINT_SUPPORTED
info_ptr->gamma = (float)(int_gamma/100000.);
info_ptr->gamma = (float)(gamma/100000.);
#endif
#ifdef PNG_FIXED_POINT_SUPPORTED
info_ptr->int_gamma = int_gamma;
info_ptr->int_gamma = gamma;
#endif
info_ptr->valid |= PNG_INFO_gAMA;
if(gamma == 0)
png_warning(png_ptr, "Setting gamma=0");
}
#endif
#if defined(PNG_hIST_SUPPORTED)
void PNGAPI
png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist)
{
int i;
int i;
png_debug1(1, "in %s storage function\n", "hIST");
if (png_ptr == NULL || info_ptr == NULL)
return;
if (info_ptr->num_palette == 0)
{
png_warning(png_ptr,
"Palette size 0, hIST allocation skipped.");
"Palette size 0, hIST allocation skipped.");
return;
}
#ifdef PNG_FREE_ME_SUPPORTED
png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0);
#endif
png_ptr->hist = (png_uint_16p)png_malloc(png_ptr,
(png_uint_32)(info_ptr->num_palette * sizeof (png_uint_16)));
/* Changed from info->num_palette to 256 in version 1.2.1 */
png_ptr->hist = (png_uint_16p)png_malloc_warn(png_ptr,
(png_uint_32)(256 * sizeof (png_uint_16)));
if (png_ptr->hist == NULL)
{
png_warning(png_ptr, "Insufficient memory for hIST chunk data.");
return;
}
for (i = 0; i < info_ptr->num_palette; i++)
png_ptr->hist[i] = hist[i];
@ -172,6 +248,61 @@ png_set_IHDR(png_structp png_ptr, png_infop info_ptr,
if (png_ptr == NULL || info_ptr == NULL)
return;
/* check for width and height valid values */
if (width == 0 || height == 0)
png_error(png_ptr, "Image width or height is zero in IHDR");
if (width > PNG_MAX_UINT || height > PNG_MAX_UINT)
png_error(png_ptr, "Invalid image size in IHDR");
/* check other values */
if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 &&
bit_depth != 8 && bit_depth != 16)
png_error(png_ptr, "Invalid bit depth in IHDR");
if (color_type < 0 || color_type == 1 ||
color_type == 5 || color_type > 6)
png_error(png_ptr, "Invalid color type in IHDR");
if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) ||
((color_type == PNG_COLOR_TYPE_RGB ||
color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8))
png_error(png_ptr, "Invalid color type/bit depth combination in IHDR");
if (interlace_type >= PNG_INTERLACE_LAST)
png_error(png_ptr, "Unknown interlace method in IHDR");
if (compression_type != PNG_COMPRESSION_TYPE_BASE)
png_error(png_ptr, "Unknown compression method in IHDR");
#if defined(PNG_MNG_FEATURES_SUPPORTED)
/* Accept filter_method 64 (intrapixel differencing) only if
* 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and
* 2. Libpng did not read a PNG signature (this filter_method is only
* used in PNG datastreams that are embedded in MNG datastreams) and
* 3. The application called png_permit_mng_features with a mask that
* included PNG_FLAG_MNG_FILTER_64 and
* 4. The filter_method is 64 and
* 5. The color_type is RGB or RGBA
*/
if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&png_ptr->mng_features_permitted)
png_warning(png_ptr,"MNG features are not allowed in a PNG datastream\n");
if(filter_type != PNG_FILTER_TYPE_BASE)
{
if(!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
(filter_type == PNG_INTRAPIXEL_DIFFERENCING) &&
((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
(color_type == PNG_COLOR_TYPE_RGB ||
color_type == PNG_COLOR_TYPE_RGB_ALPHA)))
png_error(png_ptr, "Unknown filter method in IHDR");
if(png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)
png_warning(png_ptr, "Invalid filter method in IHDR");
}
#else
if(filter_type != PNG_FILTER_TYPE_BASE)
png_error(png_ptr, "Unknown filter method in IHDR");
#endif
info_ptr->width = width;
info_ptr->height = height;
info_ptr->bit_depth = (png_byte)bit_depth;
@ -191,7 +322,7 @@ png_set_IHDR(png_structp png_ptr, png_infop info_ptr,
/* check for overflow */
rowbytes_per_pixel = (info_ptr->pixel_depth + 7) >> 3;
if (( width > PNG_MAX_UINT/rowbytes_per_pixel))
if ( width > PNG_MAX_UINT/rowbytes_per_pixel - 64)
{
png_warning(png_ptr,
"Width too large to process image data; rowbytes will overflow.");
@ -232,7 +363,12 @@ png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
length = png_strlen(purpose) + 1;
png_debug1(3, "allocating purpose for info (%lu bytes)\n", length);
info_ptr->pcal_purpose = (png_charp)png_malloc(png_ptr, length);
info_ptr->pcal_purpose = (png_charp)png_malloc_warn(png_ptr, length);
if (info_ptr->pcal_purpose == NULL)
{
png_warning(png_ptr, "Insufficient memory for pCAL purpose.");
return;
}
png_memcpy(info_ptr->pcal_purpose, purpose, (png_size_t)length);
png_debug(3, "storing X0, X1, type, and nparams in info\n");
@ -243,18 +379,34 @@ png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
length = png_strlen(units) + 1;
png_debug1(3, "allocating units for info (%lu bytes)\n", length);
info_ptr->pcal_units = (png_charp)png_malloc(png_ptr, length);
info_ptr->pcal_units = (png_charp)png_malloc_warn(png_ptr, length);
if (info_ptr->pcal_units == NULL)
{
png_warning(png_ptr, "Insufficient memory for pCAL units.");
return;
}
png_memcpy(info_ptr->pcal_units, units, (png_size_t)length);
info_ptr->pcal_params = (png_charpp)png_malloc(png_ptr,
info_ptr->pcal_params = (png_charpp)png_malloc_warn(png_ptr,
(png_uint_32)((nparams + 1) * sizeof(png_charp)));
if (info_ptr->pcal_params == NULL)
{
png_warning(png_ptr, "Insufficient memory for pCAL params.");
return;
}
info_ptr->pcal_params[nparams] = NULL;
for (i = 0; i < nparams; i++)
{
length = png_strlen(params[i]) + 1;
png_debug2(3, "allocating parameter %d for info (%lu bytes)\n", i, length);
info_ptr->pcal_params[i] = (png_charp)png_malloc(png_ptr, length);
info_ptr->pcal_params[i] = (png_charp)png_malloc_warn(png_ptr, length);
if (info_ptr->pcal_params[i] == NULL)
{
png_warning(png_ptr, "Insufficient memory for pCAL parameter.");
return;
}
png_memcpy(info_ptr->pcal_params[i], params[i], (png_size_t)length);
}
@ -302,7 +454,7 @@ png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr,
length = png_strlen(sheight) + 1;
png_debug1(3, "allocating unit for info (%d bytes)\n", length);
info_ptr->scal_s_width = (png_charp)png_malloc(png_ptr, length);
info_ptr->scal_s_height = (png_charp)png_malloc(png_ptr, length);
png_memcpy(info_ptr->scal_s_height, sheight, (png_size_t)length);
info_ptr->valid |= PNG_INFO_sCAL;
@ -347,9 +499,13 @@ png_set_PLTE(png_structp png_ptr, png_infop info_ptr,
#ifdef PNG_FREE_ME_SUPPORTED
png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0);
#endif
png_ptr->palette = (png_colorp)png_zalloc(png_ptr, (uInt)num_palette,
/* Changed in libpng-1.2.1 to allocate 256 instead of num_palette entries,
in case of an invalid PNG file that has too-large sample values. */
png_ptr->palette = (png_colorp)png_zalloc(png_ptr, (uInt)256,
sizeof (png_color));
memcpy(png_ptr->palette, palette, num_palette * sizeof (png_color));
if (png_ptr->palette == NULL)
png_error(png_ptr, "Unable to malloc palette");
png_memcpy(png_ptr->palette, palette, num_palette * sizeof (png_color));
info_ptr->palette = png_ptr->palette;
info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;
@ -472,9 +628,9 @@ png_set_iCCP(png_structp png_ptr, png_infop info_ptr,
if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL)
return;
new_iccp_name = png_malloc(png_ptr, png_strlen(name)+1);
strcpy(new_iccp_name, name);
new_iccp_profile = png_malloc(png_ptr, proflen);
new_iccp_name = (png_charp)png_malloc(png_ptr, png_strlen(name)+1);
png_strcpy(new_iccp_name, name);
new_iccp_profile = (png_charp)png_malloc(png_ptr, proflen);
png_memcpy(new_iccp_profile, profile, (png_size_t)proflen);
png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, 0);
@ -496,6 +652,16 @@ png_set_iCCP(png_structp png_ptr, png_infop info_ptr,
void PNGAPI
png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
int num_text)
{
int ret;
ret=png_set_text_2(png_ptr, info_ptr, text_ptr, num_text);
if (ret)
png_error(png_ptr, "Insufficient memory to store text");
}
int /* PRIVATE */
png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
int num_text)
{
int i;
@ -503,7 +669,7 @@ png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
"text" : (png_const_charp)png_ptr->chunk_name));
if (png_ptr == NULL || info_ptr == NULL || num_text == 0)
return;
return(0);
/* Make sure we have enough space in the "text" array in info_struct
* to hold all of the incoming text_ptr objects.
@ -518,8 +684,13 @@ png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
old_max = info_ptr->max_text;
info_ptr->max_text = info_ptr->num_text + num_text + 8;
old_text = info_ptr->text;
info_ptr->text = (png_textp)png_malloc(png_ptr,
info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
(png_uint_32)(info_ptr->max_text * sizeof (png_text)));
if (info_ptr->text == NULL)
{
png_free(png_ptr, old_text);
return(1);
}
png_memcpy(info_ptr->text, old_text, (png_size_t)(old_max *
sizeof(png_text)));
png_free(png_ptr, old_text);
@ -528,8 +699,10 @@ png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
{
info_ptr->max_text = num_text + 8;
info_ptr->num_text = 0;
info_ptr->text = (png_textp)png_malloc(png_ptr,
info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
(png_uint_32)(info_ptr->max_text * sizeof (png_text)));
if (info_ptr->text == NULL)
return(1);
#ifdef PNG_FREE_ME_SUPPORTED
info_ptr->free_me |= PNG_FREE_TEXT;
#endif
@ -543,7 +716,7 @@ png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
png_size_t lang_len,lang_key_len;
png_textp textp = &(info_ptr->text[info_ptr->num_text]);
if (text_ptr[i].key == (png_charp)NULL)
if (text_ptr[i].key == NULL)
continue;
key_len = png_strlen(text_ptr[i].key);
@ -557,11 +730,11 @@ png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
#ifdef PNG_iTXt_SUPPORTED
{
/* set iTXt data */
if (text_ptr[i].key != (png_charp)NULL)
if (text_ptr[i].lang != NULL)
lang_len = png_strlen(text_ptr[i].lang);
else
lang_len = 0;
if (text_ptr[i].lang_key != (png_charp)NULL)
if (text_ptr[i].lang_key != NULL)
lang_key_len = png_strlen(text_ptr[i].lang_key);
else
lang_key_len = 0;
@ -573,7 +746,7 @@ png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
}
#endif
if (text_ptr[i].text == (png_charp)NULL || text_ptr[i].text[0] == '\0')
if (text_ptr[i].text == NULL || text_ptr[i].text[0] == '\0')
{
text_length = 0;
#ifdef PNG_iTXt_SUPPORTED
@ -589,10 +762,13 @@ png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
textp->compression = text_ptr[i].compression;
}
textp->key = (png_charp)png_malloc(png_ptr,
textp->key = (png_charp)png_malloc_warn(png_ptr,
(png_uint_32)(key_len + text_length + lang_len + lang_key_len + 4));
png_debug2(2, "Allocated %d bytes at %x in png_set_text\n",
key_len + lang_len + lang_key_len + text_length + 4, (int)textp->key);
if (textp->key == NULL)
return(1);
png_debug2(2, "Allocated %lu bytes at %x in png_set_text\n",
(png_uint_32)(key_len + lang_len + lang_key_len + text_length + 4),
(int)textp->key);
png_memcpy(textp->key, text_ptr[i].key,
(png_size_t)(key_len));
@ -612,8 +788,8 @@ png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
#endif
{
#ifdef PNG_iTXt_SUPPORTED
textp->lang=(png_charp)NULL;
textp->lang_key=(png_charp)NULL;
textp->lang=NULL;
textp->lang_key=NULL;
#endif
textp->text=textp->key + key_len + 1;
}
@ -640,6 +816,7 @@ png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
info_ptr->num_text++;
png_debug1(3, "transferred text chunk %d\n", info_ptr->num_text);
}
return(0);
}
#endif
@ -669,15 +846,17 @@ png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
if (trans != NULL)
{
/*
* It may not actually be necessary to set png_ptr->trans here;
* we do it for backward compatibility with the way the png_handle_tRNS
* function used to do the allocation.
*/
* It may not actually be necessary to set png_ptr->trans here;
* we do it for backward compatibility with the way the png_handle_tRNS
* function used to do the allocation.
*/
#ifdef PNG_FREE_ME_SUPPORTED
png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
#endif
png_ptr->trans = info_ptr->trans = png_malloc(png_ptr, num_trans);
memcpy(info_ptr->trans, trans, num_trans);
/* Changed from num_trans to 256 in version 1.2.1 */
png_ptr->trans = info_ptr->trans = (png_bytep)png_malloc(png_ptr,
(png_uint_32)256);
png_memcpy(info_ptr->trans, trans, (png_size_t)num_trans);
#ifdef PNG_FREE_ME_SUPPORTED
info_ptr->free_me |= PNG_FREE_TRNS;
#else
@ -705,8 +884,13 @@ png_set_sPLT(png_structp png_ptr,
png_sPLT_tp np;
int i;
np = (png_sPLT_tp)png_malloc(png_ptr,
np = (png_sPLT_tp)png_malloc_warn(png_ptr,
(info_ptr->splt_palettes_num + nentries) * sizeof(png_sPLT_t));
if (np == NULL)
{
png_warning(png_ptr, "No memory for sPLT palettes.");
return;
}
png_memcpy(np, info_ptr->splt_palettes,
info_ptr->splt_palettes_num * sizeof(png_sPLT_t));
@ -719,12 +903,12 @@ png_set_sPLT(png_structp png_ptr,
png_sPLT_tp from = entries + i;
to->name = (png_charp)png_malloc(png_ptr,
png_strlen(from->name) + 1);
png_strlen(from->name) + 1);
png_strcpy(to->name, from->name);
to->entries = (png_sPLT_entryp)png_malloc(png_ptr,
from->nentries * sizeof(png_sPLT_t));
from->nentries * sizeof(png_sPLT_t));
png_memcpy(to->entries, from->entries,
from->nentries * sizeof(png_sPLT_t));
from->nentries * sizeof(png_sPLT_t));
to->nentries = from->nentries;
to->depth = from->depth;
}
@ -738,7 +922,7 @@ png_set_sPLT(png_structp png_ptr,
}
#endif /* PNG_sPLT_SUPPORTED */
#if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
void PNGAPI
png_set_unknown_chunks(png_structp png_ptr,
png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns)
@ -749,9 +933,14 @@ png_set_unknown_chunks(png_structp png_ptr,
if (png_ptr == NULL || info_ptr == NULL || num_unknowns == 0)
return;
np = (png_unknown_chunkp)png_malloc(png_ptr,
np = (png_unknown_chunkp)png_malloc_warn(png_ptr,
(info_ptr->unknown_chunks_num + num_unknowns) *
sizeof(png_unknown_chunk));
if (np == NULL)
{
png_warning(png_ptr, "Out of memory while processing unknown chunk.");
return;
}
png_memcpy(np, info_ptr->unknown_chunks,
info_ptr->unknown_chunks_num * sizeof(png_unknown_chunk));
@ -765,11 +954,16 @@ png_set_unknown_chunks(png_structp png_ptr,
png_strcpy((png_charp)to->name, (png_charp)from->name);
to->data = (png_bytep)png_malloc(png_ptr, from->size);
png_memcpy(to->data, from->data, from->size);
to->size = from->size;
if (to->data == NULL)
png_warning(png_ptr, "Out of memory while processing unknown chunk.");
else
{
png_memcpy(to->data, from->data, from->size);
to->size = from->size;
/* note our location in the read or write sequence */
to->location = (png_byte)(png_ptr->mode & 0xff);
/* note our location in the read or write sequence */
to->location = (png_byte)(png_ptr->mode & 0xff);
}
}
info_ptr->unknown_chunks = np;
@ -840,14 +1034,17 @@ png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep
if (chunk_list == NULL)
return;
old_num_chunks=png_ptr->num_chunk_list;
new_list=png_malloc(png_ptr,5*(num_chunks+old_num_chunks));
if(png_ptr->chunk_list != (png_bytep)NULL)
new_list=(png_bytep)png_malloc(png_ptr,
(png_uint_32)(5*(num_chunks+old_num_chunks)));
if(png_ptr->chunk_list != NULL)
{
png_memcpy(new_list, png_ptr->chunk_list, 5*old_num_chunks);
png_memcpy(new_list, png_ptr->chunk_list,
(png_size_t)(5*old_num_chunks));
png_free(png_ptr, png_ptr->chunk_list);
png_ptr->chunk_list=NULL;
}
png_memcpy(new_list+5*old_num_chunks, chunk_list, 5*num_chunks);
png_memcpy(new_list+5*old_num_chunks, chunk_list,
(png_size_t)(5*num_chunks));
for (p=new_list+5*old_num_chunks+4, i=0; i<num_chunks; i++, p+=5)
*p=(png_byte)keep;
png_ptr->num_chunk_list=old_num_chunks+num_chunks;
@ -883,7 +1080,6 @@ png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers)
info_ptr->row_pointers = row_pointers;
if(row_pointers)
info_ptr->valid |= PNG_INFO_IDAT;
}
#endif
@ -894,8 +1090,6 @@ png_set_compression_buffer_size(png_structp png_ptr, png_uint_32 size)
png_free(png_ptr, png_ptr->zbuf);
png_ptr->zbuf_size = (png_size_t)size;
png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, size);
if(!png_ptr->zbuf)
png_error(png_ptr,"Unable to malloc zbuf");
png_ptr->zstream.next_out = png_ptr->zbuf;
png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
}
@ -907,3 +1101,60 @@ png_set_invalid(png_structp png_ptr, png_infop info_ptr, int mask)
info_ptr->valid &= ~(mask);
}
#ifndef PNG_1_0_X
#ifdef PNG_ASSEMBLER_CODE_SUPPORTED
/* this function was added to libpng 1.2.0 and should always exist by default */
void PNGAPI
png_set_asm_flags (png_structp png_ptr, png_uint_32 asm_flags)
{
png_uint_32 settable_asm_flags;
png_uint_32 settable_mmx_flags;
settable_mmx_flags =
#ifdef PNG_HAVE_ASSEMBLER_COMBINE_ROW
PNG_ASM_FLAG_MMX_READ_COMBINE_ROW |
#endif
#ifdef PNG_HAVE_ASSEMBLER_READ_INTERLACE
PNG_ASM_FLAG_MMX_READ_INTERLACE |
#endif
#ifdef PNG_HAVE_ASSEMBLER_READ_FILTER_ROW
PNG_ASM_FLAG_MMX_READ_FILTER_SUB |
PNG_ASM_FLAG_MMX_READ_FILTER_UP |
PNG_ASM_FLAG_MMX_READ_FILTER_AVG |
PNG_ASM_FLAG_MMX_READ_FILTER_PAETH |
#endif
0;
/* could be some non-MMX ones in the future, but not currently: */
settable_asm_flags = settable_mmx_flags;
if (!(png_ptr->asm_flags & PNG_ASM_FLAG_MMX_SUPPORT_COMPILED) ||
!(png_ptr->asm_flags & PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU))
{
/* clear all MMX flags if MMX isn't supported */
settable_asm_flags &= ~settable_mmx_flags;
png_ptr->asm_flags &= ~settable_mmx_flags;
}
/* we're replacing the settable bits with those passed in by the user,
* so first zero them out of the master copy, then logical-OR in the
* allowed subset that was requested */
png_ptr->asm_flags &= ~settable_asm_flags; /* zero them */
png_ptr->asm_flags |= (asm_flags & settable_asm_flags); /* set them */
}
#endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
#ifdef PNG_ASSEMBLER_CODE_SUPPORTED
/* this function was added to libpng 1.2.0 */
void PNGAPI
png_set_mmx_thresholds (png_structp png_ptr,
png_byte mmx_bitdepth_threshold,
png_uint_32 mmx_rowbytes_threshold)
{
png_ptr->mmx_bitdepth_threshold = mmx_bitdepth_threshold;
png_ptr->mmx_rowbytes_threshold = mmx_rowbytes_threshold;
}
#endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
#endif /* ?PNG_1_0_X */

Просмотреть файл

@ -1,9 +1,9 @@
/* pngtrans.c - transforms the data in a row (used by both readers and writers)
*
* libpng 1.0.9 - January 31, 2001
* libpng 1.2.5 - October 2, 2002
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2001 Glenn Randers-Pehrson
* Copyright (c) 1998-2002 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*/
@ -153,11 +153,14 @@ void /* PRIVATE */
png_do_invert(png_row_infop row_info, png_bytep row)
{
png_debug(1, "in png_do_invert\n");
if (row_info->bit_depth == 1 &&
/* This test removed from libpng version 1.0.13 and 1.2.0:
* if (row_info->bit_depth == 1 &&
*/
#if defined(PNG_USELESS_TESTS_SUPPORTED)
row != NULL && row_info != NULL &&
if (row == NULL || row_info == NULL)
return;
#endif
row_info->color_type == PNG_COLOR_TYPE_GRAY)
if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
{
png_bytep rp = row;
png_uint_32 i;
@ -169,6 +172,33 @@ png_do_invert(png_row_infop row_info, png_bytep row)
rp++;
}
}
else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
row_info->bit_depth == 8)
{
png_bytep rp = row;
png_uint_32 i;
png_uint_32 istop = row_info->rowbytes;
for (i = 0; i < istop; i+=2)
{
*rp = (png_byte)(~(*rp));
rp+=2;
}
}
else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
row_info->bit_depth == 16)
{
png_bytep rp = row;
png_uint_32 i;
png_uint_32 istop = row_info->rowbytes;
for (i = 0; i < istop; i+=4)
{
*rp = (png_byte)(~(*rp));
*(rp+1) = (png_byte)(~(*(rp+1)));
rp+=4;
}
}
}
#endif
@ -392,11 +422,12 @@ png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags)
sp += 8; dp += 6;
for (i = 1; i < row_width; i++)
{
/* This could be (although memcpy is probably slower):
/* This could be (although png_memcpy is probably slower):
png_memcpy(dp, sp, 6);
sp += 8;
dp += 6;
*/
*dp++ = *sp++;
*dp++ = *sp++;
*dp++ = *sp++;
@ -411,11 +442,12 @@ png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags)
/* This converts from XXRRGGBB or AARRGGBB to RRGGBB */
for (i = 0; i < row_width; i++)
{
/* This could be (although memcpy is probably slower):
/* This could be (although png_memcpy is probably slower):
png_memcpy(dp, sp, 6);
sp += 8;
dp += 6;
*/
sp+=2;
*dp++ = *sp++;
*dp++ = *sp++;
@ -606,4 +638,3 @@ png_get_user_transform_ptr(png_structp png_ptr)
return (NULL);
#endif
}

Просмотреть файл

@ -2,14 +2,14 @@
*
* For Intel x86 CPU and Microsoft Visual C++ compiler
*
* libpng 1.0.9 - January 31, 2001
* libpng version 1.2.5 - October 2, 2002
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2001 Glenn Randers-Pehrson
* Copyright (c) 1998-2002 Glenn Randers-Pehrson
* Copyright (c) 1998, Intel Corporation
*
* Contributed by Nirav Chhatrapati, Intel Corporation, 1998
* Interface to libpng contributed by Gilles Vollant, 1999
* Debugging and cleanup by Greg Roelofs, 2000, 2001
*
*
* In png_do_read_interlace() in libpng versions 1.0.3a through 1.0.4d,
* a sign error in the post-MMX cleanup code for each pixel_depth resulted
@ -19,6 +19,8 @@
*
* [png_read_filter_row_mmx_avg() bpp == 2 bugfix, GRR 20000916]
*
* [runtime MMX configuration, GRR 20010102]
*
*/
#define PNG_INTERNAL
@ -37,6 +39,7 @@ png_mmx_support(void)
push ebx //CPUID will trash these
push ecx
push edx
pushfd //Save Eflag to stack
pop eax //Get Eflag from stack into eax
mov ecx, eax //Make another copy of Eflag in ecx
@ -46,6 +49,8 @@ png_mmx_support(void)
popfd //Restored modified value back to Eflag reg
pushfd //Save Eflag to stack
pop eax //Get Eflag from stack
push ecx // save original Eflag to stack
popfd // restore original Eflag
xor eax, ecx //Compare the new Eflag with the original Eflag
jz NOT_SUPPORTED //If the same, CPUID instruction is not supported,
//skip following instructions and jump to
@ -110,6 +115,8 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask)
png_debug(1,"in png_combine_row_asm\n");
if (mmx_supported == 2) {
/* this should have happened in png_init_mmx_flags() already */
png_warning(png_ptr, "asm_flags may not have been initialized");
png_mmx_support();
}
@ -300,7 +307,8 @@ png_combine_row(png_structp png_ptr, png_bytep row, int mask)
__int64 mask0=0x0102040810204080;
if ( mmx_supported )
if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)
/* && mmx_supported */ )
{
srcptr = png_ptr->row_buf + 1;
dstptr = row;
@ -400,7 +408,8 @@ end8:
__int64 mask1=0x0101020204040808,
mask0=0x1010202040408080;
if ( mmx_supported )
if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)
/* && mmx_supported */ )
{
srcptr = png_ptr->row_buf + 1;
dstptr = row;
@ -520,7 +529,8 @@ end16:
len = (png_ptr->width)&~7;
diff = (png_ptr->width)&7;
if ( mmx_supported )
if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)
/* && mmx_supported */ )
{
_asm
{
@ -651,7 +661,8 @@ end24:
len = (png_ptr->width)&~7;
diff = (png_ptr->width)&7;
if ( mmx_supported )
if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)
/* && mmx_supported */ )
{
_asm
{
@ -785,7 +796,8 @@ end32:
mask1=0x2020202040404040,
mask0=0x4040808080808080;
if ( mmx_supported )
if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_COMBINE_ROW)
/* && mmx_supported */ )
{
srcptr = png_ptr->row_buf + 1;
dstptr = row;
@ -975,6 +987,8 @@ png_do_read_interlace(png_structp png_ptr)
png_debug(1,"in png_do_read_interlace\n");
if (mmx_supported == 2) {
/* this should have happened in png_init_mmx_flags() already */
png_warning(png_ptr, "asm_flags may not have been initialized");
png_mmx_support();
}
@ -1175,7 +1189,8 @@ png_do_read_interlace(png_structp png_ptr)
// NOTE: there is NO MMX code for 48-bit and 64-bit images
// use MMX routine if machine supports it
if ( mmx_supported )
if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_INTERLACE)
/* && mmx_supported */ )
{
if (pixel_bytes == 3)
{
@ -3637,6 +3652,8 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep
#endif
if (mmx_supported == 2) {
/* this should have happened in png_init_mmx_flags() already */
png_warning(png_ptr, "asm_flags may not have been initialized");
png_mmx_support();
}
@ -3646,13 +3663,17 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep
{
case 0: sprintf(filnm, "none");
break;
case 1: sprintf(filnm, "sub-%s", "MMX");
case 1: sprintf(filnm, "sub-%s",
(png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_SUB)? "MMX" : "x86");
break;
case 2: sprintf(filnm, "up-%s", "MMX");
case 2: sprintf(filnm, "up-%s",
(png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_UP)? "MMX" : "x86");
break;
case 3: sprintf(filnm, "avg-%s", "MMX");
case 3: sprintf(filnm, "avg-%s",
(png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_AVG)? "MMX" : "x86");
break;
case 4: sprintf(filnm, "Paeth-%s", "MMX");
case 4: sprintf(filnm, "Paeth-%s",
(png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_PAETH)? "MMX":"x86");
break;
default: sprintf(filnm, "unknw");
break;
@ -3670,9 +3691,9 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep
case PNG_FILTER_VALUE_SUB:
{
if (
(row_info->pixel_depth >= PNG_MMX_BITDEPTH_THRESHOLD_DEFAULT) &&
(row_info->rowbytes >= PNG_MMX_ROWBYTES_THRESHOLD_DEFAULT))
if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_SUB) &&
(row_info->pixel_depth >= png_ptr->mmx_bitdepth_threshold) &&
(row_info->rowbytes >= png_ptr->mmx_rowbytes_threshold))
{
png_read_filter_row_mmx_sub(row_info, row);
}
@ -3695,9 +3716,9 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep
case PNG_FILTER_VALUE_UP:
{
if (
(row_info->pixel_depth >= PNG_MMX_BITDEPTH_THRESHOLD_DEFAULT) &&
(row_info->rowbytes >= PNG_MMX_ROWBYTES_THRESHOLD_DEFAULT))
if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_UP) &&
(row_info->pixel_depth >= png_ptr->mmx_bitdepth_threshold) &&
(row_info->rowbytes >= png_ptr->mmx_rowbytes_threshold))
{
png_read_filter_row_mmx_up(row_info, row, prev_row);
}
@ -3719,9 +3740,9 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep
case PNG_FILTER_VALUE_AVG:
{
if (
(row_info->pixel_depth >= PNG_MMX_BITDEPTH_THRESHOLD_DEFAULT) &&
(row_info->rowbytes >= PNG_MMX_ROWBYTES_THRESHOLD_DEFAULT))
if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_AVG) &&
(row_info->pixel_depth >= png_ptr->mmx_bitdepth_threshold) &&
(row_info->rowbytes >= png_ptr->mmx_rowbytes_threshold))
{
png_read_filter_row_mmx_avg(row_info, row, prev_row);
}
@ -3753,9 +3774,9 @@ png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep
case PNG_FILTER_VALUE_PAETH:
{
if (
(row_info->pixel_depth >= PNG_MMX_BITDEPTH_THRESHOLD_DEFAULT) &&
(row_info->rowbytes >= PNG_MMX_ROWBYTES_THRESHOLD_DEFAULT))
if ((png_ptr->asm_flags & PNG_ASM_FLAG_MMX_READ_FILTER_PAETH) &&
(row_info->pixel_depth >= png_ptr->mmx_bitdepth_threshold) &&
(row_info->rowbytes >= png_ptr->mmx_rowbytes_threshold))
{
png_read_filter_row_mmx_paeth(row_info, row, prev_row);
}

Просмотреть файл

@ -1,9 +1,9 @@
/* pngwio.c - functions for data output
*
* libpng 1.0.9 - January 31, 2001
* libpng 1.2.5 - October 2, 2002
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2001 Glenn Randers-Pehrson
* Copyright (c) 1998-2002 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*
@ -17,6 +17,7 @@
#define PNG_INTERNAL
#include "png.h"
#ifdef PNG_WRITE_SUPPORTED
/* Write the data to whatever output you are using. The default routine
writes to a file pointer. Note that this routine sometimes gets called
@ -39,7 +40,7 @@ png_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
write_data function and use it at run time with png_set_write_fn(), rather
than changing the library. */
#ifndef USE_FAR_KEYWORD
static void /* PRIVATE */
void PNGAPI
png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
{
png_uint_32 check;
@ -62,7 +63,7 @@ png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
#define NEAR_BUF_SIZE 1024
#define MIN(a,b) (a <= b ? a : b)
static void /* PRIVATE */
void PNGAPI
png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
{
png_uint_32 check;
@ -125,7 +126,7 @@ png_flush(png_structp png_ptr)
}
#if !defined(PNG_NO_STDIO)
static void /* PRIVATE */
void PNGAPI
png_default_flush(png_structp png_ptr)
{
#if !defined(_WIN32_WCE)
@ -224,3 +225,4 @@ void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check)
}
# endif
# endif
#endif /* PNG_WRITE_SUPPORTED */

Просмотреть файл

@ -1,9 +1,9 @@
/* pngwrite.c - general routines to write a PNG file
*
* libpng 1.0.9 - January 31, 2001
* libpng 1.2.5 - October 2, 2002
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2001 Glenn Randers-Pehrson
* Copyright (c) 1998-2002 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*/
@ -11,6 +11,7 @@
/* get internal access to png.h */
#define PNG_INTERNAL
#include "png.h"
#ifdef PNG_WRITE_SUPPORTED
/* Writes all the PNG information. This is the suggested way to use the
* library. If you have a new chunk to add, make a function to write it,
@ -423,7 +424,7 @@ png_create_write_struct(png_const_charp user_png_ver, png_voidp error_ptr,
{
#ifdef PNG_USER_MEM_SUPPORTED
return (png_create_write_struct_2(user_png_ver, error_ptr, error_fn,
warn_fn, NULL, NULL, NULL));
warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL));
}
/* Alternate initialize png_ptr structure, and allocate any memory needed */
@ -442,14 +443,19 @@ png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
int i;
png_debug(1, "in png_create_write_struct\n");
#ifdef PNG_USER_MEM_SUPPORTED
if ((png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
(png_malloc_ptr)malloc_fn)) == NULL)
png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
(png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
#else
if ((png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG)) == NULL)
png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
#endif /* PNG_USER_MEM_SUPPORTED */
{
return ((png_structp)NULL);
}
if (png_ptr == NULL)
return (NULL);
#if !defined(PNG_1_0_X)
#ifdef PNG_ASSEMBLER_CODE_SUPPORTED
png_init_mmx_flags(png_ptr); /* 1.2.0 addition */
#endif
#endif /* PNG_1_0_X */
#ifdef PNG_SETJMP_SUPPORTED
#ifdef USE_FAR_KEYWORD
@ -461,7 +467,7 @@ png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
png_free(png_ptr, png_ptr->zbuf);
png_ptr->zbuf=NULL;
png_destroy_struct(png_ptr);
return ((png_structp)NULL);
return (NULL);
}
#ifdef USE_FAR_KEYWORD
png_memcpy(png_ptr->jmpbuf,jmpbuf,sizeof(jmp_buf));
@ -488,23 +494,27 @@ png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
* only check the first digit.
*/
if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
(user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
(user_png_ver[0] == '0' && user_png_ver[2] < '9'))
{
#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
char msg[80];
if (user_png_ver)
{
sprintf(msg, "Application was compiled with png.h from libpng-%.20s",
user_png_ver);
png_warning(png_ptr, msg);
}
sprintf(msg, "Application is running with png.c from libpng-%.20s",
png_libpng_ver);
png_warning(png_ptr, msg);
#endif
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
png_ptr->flags=0;
#endif
png_error(png_ptr,
"Incompatible libpng version in application and library");
}
/* Libpng 1.0.6 was not binary compatible, due to insertion of the
info_ptr->free_me member. Note to maintainer: this test can be
removed from version 2.0.0 and beyond because the previous test
would have already rejected it. */
if (user_png_ver[4] == '6' && user_png_ver[2] == '0' &&
user_png_ver[0] == '1' && user_png_ver[5] == '\0')
{
png_error(png_ptr,
"Application must be recompiled; version 1.0.6 was incompatible");
}
}
/* initialize zbuf - compression buffer */
@ -512,14 +522,28 @@ png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
(png_uint_32)png_ptr->zbuf_size);
png_set_write_fn(png_ptr, NULL, NULL, NULL);
png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL,
png_flush_ptr_NULL);
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
1, NULL, NULL);
1, png_doublep_NULL, png_doublep_NULL);
#endif
return ((png_structp)png_ptr);
#ifdef PNG_SETJMP_SUPPORTED
/* Applications that neglect to set up their own setjmp() and then encounter
a png_error() will longjmp here. Since the jmpbuf is then meaningless we
abort instead of returning. */
#ifdef USE_FAR_KEYWORD
if (setjmp(jmpbuf))
PNG_ABORT();
png_memcpy(png_ptr->jmpbuf,jmpbuf,sizeof(jmp_buf));
#else
if (setjmp(png_ptr->jmpbuf))
PNG_ABORT();
#endif
#endif
return (png_ptr);
}
/* Initialize png_ptr structure, and allocate any memory needed */
@ -528,13 +552,57 @@ void PNGAPI
png_write_init(png_structp png_ptr)
{
/* We only come here via pre-1.0.7-compiled applications */
png_write_init_2(png_ptr, "1.0.0", 10000, 10000);
png_write_init_2(png_ptr, "1.0.6 or earlier", 0, 0);
}
void PNGAPI
png_write_init_2(png_structp png_ptr, png_const_charp user_png_ver,
png_size_t png_struct_size, png_size_t png_info_size)
{
/* We only come here via pre-1.0.12-compiled applications */
#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
if(sizeof(png_struct) > png_struct_size || sizeof(png_info) > png_info_size)
{
char msg[80];
png_ptr->warning_fn=NULL;
if (user_png_ver)
{
sprintf(msg, "Application was compiled with png.h from libpng-%.20s",
user_png_ver);
png_warning(png_ptr, msg);
}
sprintf(msg, "Application is running with png.c from libpng-%.20s",
png_libpng_ver);
png_warning(png_ptr, msg);
}
#endif
if(sizeof(png_struct) > png_struct_size)
{
png_ptr->error_fn=NULL;
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
png_ptr->flags=0;
#endif
png_error(png_ptr,
"The png struct allocated by the application for writing is too small.");
}
if(sizeof(png_info) > png_info_size)
{
png_ptr->error_fn=NULL;
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
png_ptr->flags=0;
#endif
png_error(png_ptr,
"The info struct allocated by the application for writing is too small.");
}
png_write_init_3(&png_ptr, user_png_ver, png_struct_size);
}
void PNGAPI
png_write_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
png_size_t png_struct_size)
{
png_structp png_ptr=*ptr_ptr;
#ifdef PNG_SETJMP_SUPPORTED
jmp_buf tmp_jmp; /* to save current jump buffer */
#endif
@ -546,45 +614,53 @@ png_write_init_2(png_structp png_ptr, png_const_charp user_png_ver,
#ifdef PNG_LEGACY_SUPPORTED
png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
#else
png_ptr->error_fn=(png_error_ptr)NULL;
png_error(png_ptr,
"Application uses deprecated png_write_init() and must be recompiled.");
png_ptr->warning_fn=NULL;
png_warning(png_ptr,
"Application uses deprecated png_write_init() and should be recompiled.");
break;
#endif
}
} while (png_libpng_ver[i++]);
if (sizeof(png_struct) > png_struct_size ||
sizeof(png_info) > png_info_size)
{
png_ptr->error_fn=(png_error_ptr)NULL;
png_error(png_ptr,
"Application and library have different sized structs. Please recompile.");
}
png_debug(1, "in png_write_init_2\n");
png_debug(1, "in png_write_init_3\n");
#ifdef PNG_SETJMP_SUPPORTED
/* save jump buffer and error functions */
png_memcpy(tmp_jmp, png_ptr->jmpbuf, sizeof (jmp_buf));
#endif
if (sizeof(png_struct) > png_struct_size)
{
png_destroy_struct(png_ptr);
png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
*ptr_ptr = png_ptr;
}
/* reset all variables to 0 */
png_memset(png_ptr, 0, sizeof (png_struct));
#if !defined(PNG_1_0_X)
#ifdef PNG_ASSEMBLER_CODE_SUPPORTED
png_init_mmx_flags(png_ptr); /* 1.2.0 addition */
#endif
#endif /* PNG_1_0_X */
#ifdef PNG_SETJMP_SUPPORTED
/* restore jump buffer */
png_memcpy(png_ptr->jmpbuf, tmp_jmp, sizeof (jmp_buf));
#endif
png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL,
png_flush_ptr_NULL);
/* initialize zbuf - compression buffer */
png_ptr->zbuf_size = PNG_ZBUF_SIZE;
png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
(png_uint_32)png_ptr->zbuf_size);
png_set_write_fn(png_ptr, NULL, NULL, NULL);
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
1, NULL, NULL);
1, png_doublep_NULL, png_doublep_NULL);
#endif
}
@ -646,6 +722,11 @@ png_write_row(png_structp png_ptr, png_bytep row)
/* initialize transformations and other stuff if first time */
if (png_ptr->row_number == 0 && png_ptr->pass == 0)
{
/* make sure we wrote the header info */
if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
png_error(png_ptr,
"png_write_info was never called before png_write_row.");
/* check for transforms that have been set but were defined out */
#if !defined(PNG_WRITE_INVERT_SUPPORTED) && defined(PNG_READ_INVERT_SUPPORTED)
if (png_ptr->transformations & PNG_INVERT_MONO)
@ -875,6 +956,7 @@ png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)
png_infop info_ptr = NULL;
#ifdef PNG_USER_MEM_SUPPORTED
png_free_ptr free_fn = NULL;
png_voidp mem_ptr = NULL;
#endif
png_debug(1, "in png_destroy_write_struct\n");
@ -883,6 +965,7 @@ png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)
png_ptr = *png_ptr_ptr;
#ifdef PNG_USER_MEM_SUPPORTED
free_fn = png_ptr->free_fn;
mem_ptr = png_ptr->mem_ptr;
#endif
}
@ -903,28 +986,30 @@ png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)
#endif
#ifdef PNG_USER_MEM_SUPPORTED
png_destroy_struct_2((png_voidp)info_ptr, free_fn);
png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn,
(png_voidp)mem_ptr);
#else
png_destroy_struct((png_voidp)info_ptr);
#endif
*info_ptr_ptr = (png_infop)NULL;
*info_ptr_ptr = NULL;
}
if (png_ptr != NULL)
{
png_write_destroy(png_ptr);
#ifdef PNG_USER_MEM_SUPPORTED
png_destroy_struct_2((png_voidp)png_ptr, free_fn);
png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn,
(png_voidp)mem_ptr);
#else
png_destroy_struct((png_voidp)png_ptr);
#endif
*png_ptr_ptr = (png_structp)NULL;
*png_ptr_ptr = NULL;
}
}
/* Free any memory used in png_ptr struct (old method) */
void PNGAPI
void /* PRIVATE */
png_write_destroy(png_structp png_ptr)
{
#ifdef PNG_SETJMP_SUPPORTED
@ -1137,12 +1222,11 @@ png_set_filter_heuristics(png_structp png_ptr, int heuristic_method,
if (png_ptr->filter_weights == NULL)
{
png_ptr->filter_weights = (png_uint_16p) png_malloc(png_ptr,
png_ptr->filter_weights = (png_uint_16p)png_malloc(png_ptr,
(png_uint_32)(sizeof(png_uint_16) * num_weights));
png_ptr->inv_filter_weights = (png_uint_16p) png_malloc(png_ptr,
png_ptr->inv_filter_weights = (png_uint_16p)png_malloc(png_ptr,
(png_uint_32)(sizeof(png_uint_16) * num_weights));
for (i = 0; i < num_weights; i++)
{
png_ptr->inv_filter_weights[i] =
@ -1172,10 +1256,10 @@ png_set_filter_heuristics(png_structp png_ptr, int heuristic_method,
*/
if (png_ptr->filter_costs == NULL)
{
png_ptr->filter_costs = (png_uint_16p) png_malloc(png_ptr,
png_ptr->filter_costs = (png_uint_16p)png_malloc(png_ptr,
(png_uint_32)(sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
png_ptr->inv_filter_costs = (png_uint_16p) png_malloc(png_ptr,
png_ptr->inv_filter_costs = (png_uint_16p)png_malloc(png_ptr,
(png_uint_32)(sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
@ -1359,7 +1443,8 @@ png_write_png(png_structp png_ptr, png_infop info_ptr,
/* It is REQUIRED to call this to finish writing the rest of the file */
png_write_end(png_ptr, info_ptr);
if(transforms == 0 || params == (voidp)NULL)
if(transforms == 0 || params == NULL)
/* quiet compiler warnings */ return;
}
#endif
#endif /* PNG_WRITE_SUPPORTED */

Просмотреть файл

@ -1,15 +1,16 @@
/* pngwtran.c - transforms the data in a row for PNG writers
*
* libpng 1.0.9 - January 31, 2001
* libpng 1.2.5 - October 2, 2002
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2001 Glenn Randers-Pehrson
* Copyright (c) 1998-2002 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*/
#define PNG_INTERNAL
#include "png.h"
#ifdef PNG_WRITE_SUPPORTED
/* Transform the data according to the user's wishes. The order of
* transformations is significant.
@ -559,3 +560,4 @@ png_do_write_intrapixel(png_row_infop row_info, png_bytep row)
}
}
#endif /* PNG_MNG_FEATURES_SUPPORTED */
#endif /* PNG_WRITE_SUPPORTED */

Просмотреть файл

@ -1,15 +1,16 @@
/* pngwutil.c - utilities to write a PNG file
*
* libpng 1.0.9 - January 31, 2001
* libpng 1.2.5 - October 2, 2002
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2001 Glenn Randers-Pehrson
* Copyright (c) 1998-2002 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*/
#define PNG_INTERNAL
#include "png.h"
#ifdef PNG_WRITE_SUPPORTED
/* Place a 32-bit number into a buffer in PNG byte order. We work
* with unsigned numbers for convenience, although one supported
@ -24,7 +25,7 @@ png_save_uint_32(png_bytep buf, png_uint_32 i)
buf[3] = (png_byte)(i & 0xff);
}
#if defined(PNG_WRITE_pCAL_SUPPORTED)
#if defined(PNG_WRITE_pCAL_SUPPORTED) || defined(PNG_WRITE_oFFs_SUPPORTED)
/* The png_save_int_32 function assumes integers are stored in two's
* complement format. If this isn't the case, then this routine needs to
* be modified to write data in two's complement format.
@ -234,8 +235,8 @@ png_text_compress(png_structp png_ptr,
old_ptr = comp->output_ptr;
comp->output_ptr = (png_charpp)png_malloc(png_ptr,
(png_uint_32)(comp->max_output_ptr * sizeof (png_charpp)));
png_memcpy(comp->output_ptr, old_ptr,
old_max * sizeof (png_charp));
png_memcpy(comp->output_ptr, old_ptr, old_max
* sizeof (png_charp));
png_free(png_ptr, old_ptr);
}
else
@ -284,7 +285,7 @@ png_text_compress(png_structp png_ptr,
comp->output_ptr = (png_charpp)png_malloc(png_ptr,
(png_uint_32)(comp->max_output_ptr * sizeof (png_charpp)));
png_memcpy(comp->output_ptr, old_ptr,
old_max * sizeof (png_charp));
old_max * sizeof (png_charp));
png_free(png_ptr, old_ptr);
}
else
@ -331,7 +332,8 @@ png_write_compressed_data_out(png_structp png_ptr, compression_state *comp)
/* handle the no-compression case */
if (comp->input)
{
png_write_chunk_data(png_ptr, (png_bytep)comp->input, comp->input_len);
png_write_chunk_data(png_ptr, (png_bytep)comp->input,
(png_size_t)comp->input_len);
return;
}
@ -434,7 +436,7 @@ png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height,
#if defined(PNG_MNG_FEATURES_SUPPORTED)
!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
(color_type == PNG_COLOR_TYPE_RGB ||
(color_type == PNG_COLOR_TYPE_RGB ||
color_type == PNG_COLOR_TYPE_RGB_ALPHA) &&
(filter_type == PNG_INTRAPIXEL_DIFFERENCING)) &&
#endif
@ -459,7 +461,9 @@ png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height,
png_ptr->bit_depth = (png_byte)bit_depth;
png_ptr->color_type = (png_byte)color_type;
png_ptr->interlaced = (png_byte)interlace_type;
#if defined(PNG_MNG_FEATURES_SUPPORTED)
png_ptr->filter_type = (png_byte)filter_type;
#endif
png_ptr->width = width;
png_ptr->height = height;
@ -538,16 +542,23 @@ png_write_PLTE(png_structp png_ptr, png_colorp palette, png_uint_32 num_pal)
!(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) &&
#endif
num_pal == 0) || num_pal > 256)
{
if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
{
if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
{
png_error(png_ptr, "Invalid number of colors in palette");
}
else
{
png_warning(png_ptr, "Invalid number of colors in palette");
return;
}
png_error(png_ptr, "Invalid number of colors in palette");
}
else
{
png_warning(png_ptr, "Invalid number of colors in palette");
return;
}
}
if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR))
{
png_warning(png_ptr,
"Ignoring request to write a PLTE chunk in grayscale PNG");
return;
}
png_ptr->num_palette = (png_uint_16)num_pal;
@ -597,7 +608,8 @@ png_write_IEND(png_structp png_ptr)
PNG_IEND;
#endif
png_debug(1, "in png_write_IEND\n");
png_write_chunk(png_ptr, (png_bytep)png_IEND, NULL, (png_size_t)0);
png_write_chunk(png_ptr, (png_bytep)png_IEND, png_bytep_NULL,
(png_size_t)0);
png_ptr->mode |= PNG_HAVE_IEND;
}
@ -631,7 +643,7 @@ png_write_gAMA_fixed(png_structp png_ptr, png_fixed_point file_gamma)
png_debug(1, "in png_write_gAMA\n");
/* file_gamma is saved in 1/100,000ths */
png_save_uint_32(buf, file_gamma);
png_save_uint_32(buf, (png_uint_32)file_gamma);
png_write_chunk(png_ptr, (png_bytep)png_gAMA, buf, (png_size_t)4);
}
#endif
@ -728,7 +740,7 @@ png_write_sPLT(png_structp png_ptr, png_sPLT_tp spalette)
}
/* make sure we include the NULL after the name */
png_write_chunk_start(png_ptr, (png_bytep) png_sPLT,
png_write_chunk_start(png_ptr, (png_bytep)png_sPLT,
(png_uint_32)(name_len + 2 + palette_size));
png_write_chunk_data(png_ptr, (png_bytep)new_name, name_len + 1);
png_write_chunk_data(png_ptr, (png_bytep)&spalette->depth, 1);
@ -753,7 +765,7 @@ png_write_sPLT(png_structp png_ptr, png_sPLT_tp spalette)
png_save_uint_16(entrybuf + 6, ep->alpha);
png_save_uint_16(entrybuf + 8, ep->frequency);
}
png_write_chunk_data(png_ptr, entrybuf, entry_size);
png_write_chunk_data(png_ptr, entrybuf, (png_size_t)entry_size);
}
#else
ep=spalette->entries;
@ -928,32 +940,32 @@ png_write_cHRM_fixed(png_structp png_ptr, png_fixed_point white_x,
#endif
return;
}
png_save_uint_32(buf, white_x);
png_save_uint_32(buf + 4, white_y);
png_save_uint_32(buf, (png_uint_32)white_x);
png_save_uint_32(buf + 4, (png_uint_32)white_y);
if (red_x > 80000L || red_y > 80000L || red_x + red_y > 100000L)
{
png_warning(png_ptr, "Invalid cHRM fixed red point specified");
return;
}
png_save_uint_32(buf + 8, red_x);
png_save_uint_32(buf + 12, red_y);
png_save_uint_32(buf + 8, (png_uint_32)red_x);
png_save_uint_32(buf + 12, (png_uint_32)red_y);
if (green_x > 80000L || green_y > 80000L || green_x + green_y > 100000L)
{
png_warning(png_ptr, "Invalid fixed cHRM green point specified");
return;
}
png_save_uint_32(buf + 16, green_x);
png_save_uint_32(buf + 20, green_y);
png_save_uint_32(buf + 16, (png_uint_32)green_x);
png_save_uint_32(buf + 20, (png_uint_32)green_y);
if (blue_x > 80000L || blue_y > 80000L || blue_x + blue_y > 100000L)
{
png_warning(png_ptr, "Invalid fixed cHRM blue point specified");
return;
}
png_save_uint_32(buf + 24, blue_x);
png_save_uint_32(buf + 28, blue_y);
png_save_uint_32(buf + 24, (png_uint_32)blue_x);
png_save_uint_32(buf + 28, (png_uint_32)blue_y);
png_write_chunk(png_ptr, (png_bytep)png_cHRM, buf, (png_size_t)32);
}
@ -985,6 +997,12 @@ png_write_tRNS(png_structp png_ptr, png_bytep trans, png_color_16p tran,
else if (color_type == PNG_COLOR_TYPE_GRAY)
{
/* one 16 bit value */
if(tran->gray >= (1 << png_ptr->bit_depth))
{
png_warning(png_ptr,
"Ignoring attempt to write tRNS chunk out-of-range for bit_depth");
return;
}
png_save_uint_16(buf, tran->gray);
png_write_chunk(png_ptr, (png_bytep)png_tRNS, buf, (png_size_t)2);
}
@ -994,6 +1012,12 @@ png_write_tRNS(png_structp png_ptr, png_bytep trans, png_color_16p tran,
png_save_uint_16(buf, tran->red);
png_save_uint_16(buf + 2, tran->green);
png_save_uint_16(buf + 4, tran->blue);
if(png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
{
png_warning(png_ptr,
"Ignoring attempt to write 16-bit tRNS chunk when bit_depth is 8");
return;
}
png_write_chunk(png_ptr, (png_bytep)png_tRNS, buf, (png_size_t)6);
}
else
@ -1034,10 +1058,22 @@ png_write_bKGD(png_structp png_ptr, png_color_16p back, int color_type)
png_save_uint_16(buf, back->red);
png_save_uint_16(buf + 2, back->green);
png_save_uint_16(buf + 4, back->blue);
if(png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
{
png_warning(png_ptr,
"Ignoring attempt to write 16-bit bKGD chunk when bit_depth is 8");
return;
}
png_write_chunk(png_ptr, (png_bytep)png_bKGD, buf, (png_size_t)6);
}
else
{
if(back->gray >= (1 << png_ptr->bit_depth))
{
png_warning(png_ptr,
"Ignoring attempt to write bKGD chunk out-of-range for bit_depth");
return;
}
png_save_uint_16(buf, back->gray);
png_write_chunk(png_ptr, (png_bytep)png_bKGD, buf, (png_size_t)2);
}
@ -1313,22 +1349,28 @@ png_write_iTXt(png_structp png_ptr, int compression, png_charp key,
png_warning(png_ptr, "Empty keyword in iTXt chunk");
return;
}
if (lang == NULL || (lang_len = png_check_keyword(png_ptr, lang,
&new_lang))==0)
if (lang == NULL || (lang_len = png_check_keyword(png_ptr, lang, &new_lang))==0)
{
png_warning(png_ptr, "Empty language field in iTXt chunk");
return;
new_lang = NULL;
lang_len = 0;
}
lang_key_len = png_strlen(lang_key);
text_len = png_strlen(text);
if (text == NULL || *text == '\0')
if (lang_key == NULL)
lang_key_len = 0;
else
lang_key_len = png_strlen(lang_key);
if (text == NULL)
text_len = 0;
else
text_len = png_strlen(text);
/* compute the compressed data; do it now for the length */
text_len = png_text_compress(png_ptr, text, text_len, compression-2,
&comp);
/* make sure we include the compression flag, the compression byte,
* and the NULs after the key, lang, and lang_key parts */
@ -1358,23 +1400,22 @@ png_write_iTXt(png_structp png_ptr, int compression, png_charp key,
cbuf[1] = 0;
png_write_chunk_data(png_ptr, cbuf, 2);
png_write_chunk_data(png_ptr, (png_bytep)new_lang, lang_len + 1);
png_write_chunk_data(png_ptr, (png_bytep)lang_key, lang_key_len+1);
png_write_chunk_data(png_ptr, '\0', 1);
cbuf[0] = 0;
png_write_chunk_data(png_ptr, (new_lang ? (png_bytep)new_lang : cbuf), lang_len + 1);
png_write_chunk_data(png_ptr, (lang_key ? (png_bytep)lang_key : cbuf), lang_key_len + 1);
png_write_compressed_data_out(png_ptr, &comp);
png_write_chunk_end(png_ptr);
png_free(png_ptr, new_key);
png_free(png_ptr, new_lang);
if (new_lang)
png_free(png_ptr, new_lang);
}
#endif
#if defined(PNG_WRITE_oFFs_SUPPORTED)
/* write the oFFs chunk */
void /* PRIVATE */
png_write_oFFs(png_structp png_ptr, png_uint_32 x_offset,
png_uint_32 y_offset,
png_write_oFFs(png_structp png_ptr, png_int_32 x_offset, png_int_32 y_offset,
int unit_type)
{
#ifdef PNG_USE_LOCAL_ARRAYS
@ -1386,8 +1427,8 @@ png_write_oFFs(png_structp png_ptr, png_uint_32 x_offset,
if (unit_type >= PNG_OFFSET_LAST)
png_warning(png_ptr, "Unrecognized unit type for oFFs chunk");
png_save_uint_32(buf, x_offset);
png_save_uint_32(buf + 4, y_offset);
png_save_int_32(buf, x_offset);
png_save_int_32(buf + 4, y_offset);
buf[8] = (png_byte)unit_type;
png_write_chunk(png_ptr, (png_bytep)png_oFFs, buf, (png_size_t)9);
@ -1414,9 +1455,9 @@ png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0,
png_warning(png_ptr, "Unrecognized equation type for pCAL chunk");
purpose_len = png_check_keyword(png_ptr, purpose, &new_purpose) + 1;
png_debug1(3, "pCAL purpose length = %d\n", purpose_len);
png_debug1(3, "pCAL purpose length = %d\n", (int)purpose_len);
units_len = png_strlen(units) + (nparams == 0 ? 0 : 1);
png_debug1(3, "pCAL units length = %d\n", units_len);
png_debug1(3, "pCAL units length = %d\n", (int)units_len);
total_len = purpose_len + units_len + 10;
params_len = (png_uint_32p)png_malloc(png_ptr, (png_uint_32)(nparams
@ -1431,7 +1472,7 @@ png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0,
total_len += (png_size_t)params_len[i];
}
png_debug1(3, "pCAL total length = %d\n", total_len);
png_debug1(3, "pCAL total length = %d\n", (int)total_len);
png_write_chunk_start(png_ptr, (png_bytep)png_pCAL, (png_uint_32)total_len);
png_write_chunk_data(png_ptr, (png_bytep)new_purpose, purpose_len);
png_save_int_32(buf, X0);
@ -1483,11 +1524,11 @@ png_write_sCAL(png_structp png_ptr, int unit, double width,double height)
#endif
total_len = 1 + png_strlen(wbuf)+1 + png_strlen(hbuf);
png_debug1(3, "sCAL total length = %d\n", total_len);
png_debug1(3, "sCAL total length = %d\n", (int)total_len);
png_write_chunk_start(png_ptr, (png_bytep)png_sCAL, (png_uint_32)total_len);
png_write_chunk_data(png_ptr, (png_bytep)&unit, 1);
png_write_chunk_data(png_ptr, (png_bytep)wbuf, strlen(wbuf)+1);
png_write_chunk_data(png_ptr, (png_bytep)hbuf, strlen(hbuf));
png_write_chunk_data(png_ptr, (png_bytep)wbuf, png_strlen(wbuf)+1);
png_write_chunk_data(png_ptr, (png_bytep)hbuf, png_strlen(hbuf));
png_write_chunk_end(png_ptr);
}
@ -1505,15 +1546,15 @@ png_write_sCAL_s(png_structp png_ptr, int unit, png_charp width,
png_debug(1, "in png_write_sCAL_s\n");
strcpy(wbuf,(const char *)width);
strcpy(hbuf,(const char *)height);
png_strcpy(wbuf,(const char *)width);
png_strcpy(hbuf,(const char *)height);
total_len = 1 + png_strlen(wbuf)+1 + png_strlen(hbuf);
png_debug1(3, "sCAL total length = %d\n", total_len);
png_write_chunk_start(png_ptr, (png_bytep)png_sCAL, (png_uint_32)total_len);
png_write_chunk_data(png_ptr, (png_bytep)&unit, 1);
png_write_chunk_data(png_ptr, (png_bytep)wbuf, strlen(wbuf)+1);
png_write_chunk_data(png_ptr, (png_bytep)hbuf, strlen(hbuf));
png_write_chunk_data(png_ptr, (png_bytep)wbuf, png_strlen(wbuf)+1);
png_write_chunk_data(png_ptr, (png_bytep)hbuf, png_strlen(hbuf));
png_write_chunk_end(png_ptr);
}
@ -2631,3 +2672,4 @@ png_write_filtered_row(png_structp png_ptr, png_bytep filtered_row)
}
#endif
}
#endif /* PNG_WRITE_SUPPORTED */