mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 22:32:46 +00:00
Bug 532645 - "Upgrade libpng to version 1.4.0" [r+rs=joe]
This commit is contained in:
parent
d14fd0b5cb
commit
2c053cb495
File diff suppressed because it is too large
Load Diff
@ -10,8 +10,8 @@ this sentence.
|
||||
|
||||
This code is released under the libpng license.
|
||||
|
||||
libpng versions 1.2.6, August 15, 2004, through 1.2.40, September 10, 2009, are
|
||||
Copyright (c) 2004, 2006-2009 Glenn Randers-Pehrson, and are
|
||||
libpng versions 1.2.6, August 15, 2004, through 1.4.0, January 3, 2010, are
|
||||
Copyright (c) 2004, 2006-2007 Glenn Randers-Pehrson, and are
|
||||
distributed according to the same disclaimer and license as libpng-1.2.5
|
||||
with the following individual added to the list of Contributing Authors
|
||||
|
||||
@ -108,4 +108,4 @@ certification mark of the Open Source Initiative.
|
||||
|
||||
Glenn Randers-Pehrson
|
||||
glennrp at users.sourceforge.net
|
||||
September 10, 2009
|
||||
January 3, 2010
|
||||
|
@ -1,6 +1,8 @@
|
||||
|
||||
Changes made to pristine png source by mozilla.org developers.
|
||||
|
||||
2010/01/04 -- Synced with libpng-1.4.0 (bug #532645).
|
||||
|
||||
2009/09/10 -- Synced with libpng-1.2.40 (bug #492200 and #504805).
|
||||
Moved location of acTL chunk to just after IHDR
|
||||
in output PNG file.
|
||||
|
@ -1,15 +1,11 @@
|
||||
README for libpng version 1.2.40 - September 10, 2009 (shared library 12.0)
|
||||
README for libpng version 1.4.0 - January 3, 2010 (shared library 14.0)
|
||||
See the note about version numbers near the top of png.h
|
||||
|
||||
See INSTALL for instructions on how to install libpng.
|
||||
|
||||
Libpng comes in several distribution formats. Get libpng-*.tar.gz,
|
||||
libpng-*.tar.lzma, or libpng-*.tar.bz2 if you want UNIX-style line
|
||||
endings in the text files, or lpng*.7z or lpng*.zip if you want DOS-style
|
||||
line endings. You can get UNIX-style line endings from the *.zip file
|
||||
by using "unzip -a" but there seems to be no simple way to recover
|
||||
UNIX-style line endings from the *.7z file. The *.tar.lzma file is
|
||||
recommended for *NIX users instead.
|
||||
libpng-*.tar.xz or libpng-*.tar.bz2 if you want UNIX-style line endings
|
||||
in the text files, or lpng*.zip if you want DOS-style line endings.
|
||||
|
||||
Version 0.89 was the first official release of libpng. Don't let the
|
||||
fact that it's the first release fool you. The libpng library has been in
|
||||
@ -58,9 +54,9 @@ to set different actions based on whether the CRC error occurred in a
|
||||
critical or an ancillary chunk.
|
||||
|
||||
The changes made to the library, and bugs fixed are based on discussions
|
||||
on the png-mng-implement mailing list
|
||||
and not on material submitted privately to Guy, Andreas, or Glenn. They will
|
||||
forward any good suggestions to the list.
|
||||
on the PNG-implement mailing list and not on material submitted
|
||||
privately to Guy, Andreas, or Glenn. They will forward any good
|
||||
suggestions to the list.
|
||||
|
||||
For a detailed description on using libpng, read libpng.txt. For
|
||||
examples of libpng in a program, see example.c and pngtest.c. For usage
|
||||
@ -81,12 +77,12 @@ compression library that is useful for more things than just PNG files.
|
||||
You can use zlib as a drop-in replacement for fread() and fwrite() if
|
||||
you are so inclined.
|
||||
|
||||
zlib should be available at the same place that libpng is, or at
|
||||
ftp://ftp.simplesystems.org/pub/png/src/
|
||||
zlib should be available at the same place that libpng is, or at.
|
||||
ftp://ftp.info-zip.org/pub/infozip/zlib
|
||||
|
||||
You may also want a copy of the PNG specification. It is available
|
||||
as an RFC, a W3C Recommendation, and an ISO/IEC Standard. You can find
|
||||
these at http://www.libpng.org/pub/png/pngdocs.html
|
||||
these at http://www.libpng.org/pub/png/documents/
|
||||
|
||||
This code is currently being archived at libpng.sf.net in the
|
||||
[DOWNLOAD] area, and on CompuServe, Lib 20 (PNG SUPPORT)
|
||||
@ -105,23 +101,24 @@ Finally, if you get any warning messages when compiling libpng
|
||||
fix. Please mention "libpng" somewhere in the subject line. Thanks.
|
||||
|
||||
This release was created and will be supported by myself (of course
|
||||
based in a large way on Guy's and Andreas' earlier work), and the PNG group.
|
||||
based in a large way on Guy's and Andreas' earlier work), and the PNG
|
||||
development group.
|
||||
|
||||
Send comments/corrections/commendations to png-mng-implement at lists.sf.net
|
||||
(subscription required; visit
|
||||
Send comments/corrections/commendations to png-mng-implement at
|
||||
lists.sourceforge.net (subscription required; visit
|
||||
https://lists.sourceforge.net/lists/listinfo/png-mng-implement
|
||||
to subscribe) or to glennrp at users.sourceforge.net
|
||||
|
||||
You can't reach Guy, the original libpng author, at the addresses
|
||||
given in previous versions of this document. He and Andreas will read mail
|
||||
addressed to the png-mng-implement list, however.
|
||||
given in previous versions of this document. He and Andreas will
|
||||
read mail addressed to the png-implement list, however.
|
||||
|
||||
Please do not send general questions about PNG. Send them to
|
||||
the (png-mng-misc at lists.sourceforge.net, subscription required, visit
|
||||
https://lists.sourceforge.net/lists/listinfo/png-mng-implement to subscribe)
|
||||
the (png-list at ccrc.wustl.edu, subscription required, write to
|
||||
majordomo at ccrc.wustl.edu with "subscribe png-list" in your message).
|
||||
On the other hand,
|
||||
please do not send libpng questions to that address, send them to me
|
||||
or to the png-mng-implement list. I'll
|
||||
or to the png-implement list. I'll
|
||||
get them in the end anyway. If you have a question about something
|
||||
in the PNG specification that is related to using libpng, send it
|
||||
to me. Send me any questions that start with "I was using libpng,
|
||||
@ -129,7 +126,7 @@ and ...". If in doubt, send questions to me. I'll bounce them
|
||||
to others, if necessary.
|
||||
|
||||
Please do not send suggestions on how to change PNG. We have
|
||||
been discussing PNG for twelve years now, and it is official and
|
||||
been discussing PNG for nine years now, and it is official and
|
||||
finished. If you have suggestions for libpng, however, I'll
|
||||
gladly listen. Even if your suggestion is not used immediately,
|
||||
it may be used later.
|
||||
@ -144,7 +141,6 @@ Files in this distribution:
|
||||
TODO => Things not implemented in the current library
|
||||
Y2KINFO => Statement of Y2K compliance
|
||||
example.c => Example code for using libpng functions
|
||||
libpng-*-*-diff.txt => Diff from previous release
|
||||
libpng.3 => manual page for libpng (includes libpng.txt)
|
||||
libpng.txt => Description of libpng and its functions
|
||||
libpngpf.3 => manual page for libpng's private functions
|
||||
@ -178,28 +174,20 @@ Files in this distribution:
|
||||
pngminus => Simple pnm2png and png2pnm programs
|
||||
pngsuite => Test images
|
||||
visupng => Contains a MSVC workspace for VisualPng
|
||||
projects => Contains project files and workspaces for building DLL
|
||||
beos => Contains a Beos workspace for building libpng
|
||||
c5builder => Contains a Borland workspace for building libpng
|
||||
and zlib
|
||||
visualc6 => Contains a Microsoft Visual C++ (MSVC) workspace
|
||||
for building libpng and zlib
|
||||
netware.txt => Contains instructions for downloading a set of
|
||||
project files for building libpng and zlib on
|
||||
Netware.
|
||||
wince.txt => Contains instructions for downloading a Microsoft
|
||||
Visual C++ (Windows CD Toolkit) workspace for
|
||||
building libpng and zlib on WindowsCE
|
||||
projects => Contains project files and workspaces for
|
||||
building a DLL
|
||||
c5builder => Contains a Borland workspace for building
|
||||
libpng and zlib
|
||||
visualc6 => Contains a Microsoft Visual C++ (MSVC)
|
||||
workspace for building libpng and zlib
|
||||
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.std => Generic UNIX makefile (cc, creates static
|
||||
libpng.a)
|
||||
makefile.elf => Linux/ELF makefile symbol versioning,
|
||||
gcc, creates libpng12.so.0.1.2.40)
|
||||
gcc, creates libpng14.so.14.1.4.0)
|
||||
makefile.linux => Linux/ELF makefile
|
||||
(gcc, creates libpng12.so.0.1.2.40)
|
||||
makefile.gcmmx => Linux/ELF makefile
|
||||
(gcc, creates libpng12.so.0.1.2.40,
|
||||
uses assembler code tuned for Intel MMX platform)
|
||||
(gcc, creates libpng14.so.14.1.4.0)
|
||||
makefile.gcc => Generic makefile (gcc, creates static libpng.a)
|
||||
makefile.knr => Archaic UNIX Makefile that converts files with
|
||||
ansi2knr (Requires ansi2knr.c from
|
||||
@ -214,18 +202,19 @@ Files in this distribution:
|
||||
makefile.hp64 => HPUX (10.20 and 11.00) makefile, 64 bit
|
||||
makefile.ibmc => IBM C/C++ version 3.x for Win32 and OS/2 (static)
|
||||
makefile.intel => Intel C/C++ version 4.0 and later
|
||||
libpng.icc => Project file, IBM VisualAge/C++ 4.0 or later
|
||||
makefile.netbsd => NetBSD/cc makefile, PNGGCCRD, makes libpng.so.
|
||||
makefile.ne12bsd => NetBSD/cc makefile, PNGGCCRD, makes libpng12.so
|
||||
makefile.mingw => Mingw/gcc makefile
|
||||
makefile.netbsd => NetBSD/cc makefile, makes libpng.so.
|
||||
makefile.ne14bsd => NetBSD/cc makefile, makes
|
||||
libpng14.so
|
||||
makefile.openbsd => OpenBSD makefile
|
||||
makefile.sgi => Silicon Graphics IRIX (cc, creates static lib)
|
||||
makefile.sggcc => Silicon Graphics
|
||||
(gcc, creates libpng12.so.0.1.2.40)
|
||||
(gcc, creates libpng14.so.14.1.4.0)
|
||||
makefile.sunos => Sun makefile
|
||||
makefile.solaris => Solaris 2.X makefile
|
||||
(gcc, creates libpng12.so.0.1.2.40)
|
||||
(gcc, creates libpng14.so.14.1.4.0)
|
||||
makefile.so9 => Solaris 9 makefile
|
||||
(gcc, creates libpng12.so.0.1.2.40)
|
||||
(gcc, creates libpng14.so.14.1.4.0)
|
||||
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
|
||||
@ -242,25 +231,26 @@ Files in this distribution:
|
||||
makefile.tc3 => Turbo C 3.0 makefile
|
||||
makefile.dj2 => DJGPP 2 makefile
|
||||
makefile.msc => Microsoft C makefile
|
||||
makefile.vcawin32=> makefile for Microsoft Visual C++ 5.0 and
|
||||
later (uses assembler code tuned for Intel MMX
|
||||
platform)
|
||||
makefile.vcwin32 => makefile for Microsoft Visual C++ 4.0 and
|
||||
later (does not use assembler code)
|
||||
makefile.os2 => OS/2 Makefile (gcc and emx, requires pngos2.def)
|
||||
pngos2.def => OS/2 module definition file used by makefile.os2
|
||||
png32ce.def => module definition for makefile.cegccg
|
||||
pngos2.def => OS/2 module definition file used by
|
||||
makefile.os2
|
||||
pngwin.def => module definition file used by
|
||||
makefile.cygwin and makefile.mingw
|
||||
makefile.watcom => Watcom 10a+ Makefile, 32-bit flat memory model
|
||||
makevms.com => VMS build script
|
||||
SCOPTIONS.ppc => Used with smakefile.ppc
|
||||
|
||||
Good luck, and happy coding.
|
||||
|
||||
-Glenn Randers-Pehrson (current maintainer)
|
||||
-Glenn Randers-Pehrson (current maintainer, since 1998)
|
||||
Internet: glennrp at users.sourceforge.net
|
||||
|
||||
-Andreas Eric Dilger (former maintainer, 1996-1997)
|
||||
Internet: adilger at enel.ucalgary.ca
|
||||
Web: http://members.shaw.ca/adilger/
|
||||
Web: http://www-mddsp.enel.ucalgary.ca/People/adilger/
|
||||
|
||||
-Guy Eric Schalnat (original author and former maintainer, 1995-1996)
|
||||
(formerly of Group 42, Inc)
|
||||
|
@ -1,6 +1,6 @@
|
||||
libpng.txt - A description on how to use and modify libpng
|
||||
|
||||
libpng version 1.2.40 - September 10, 2009
|
||||
libpng version 1.4.0 - January 3, 2010
|
||||
Updated and distributed by Glenn Randers-Pehrson
|
||||
<glennrp at users.sourceforge.net>
|
||||
Copyright (c) 1998-2009 Glenn Randers-Pehrson
|
||||
@ -11,7 +11,7 @@ libpng.txt - A description on how to use and modify libpng
|
||||
|
||||
Based on:
|
||||
|
||||
libpng versions 0.97, January 1998, through 1.2.40 - September 10, 2009
|
||||
libpng versions 0.97, January 1998, through 1.4.0 - January 3, 2010
|
||||
Updated and distributed by Glenn Randers-Pehrson
|
||||
Copyright (c) 1998-2009 Glenn Randers-Pehrson
|
||||
|
||||
@ -40,8 +40,8 @@ will need. We assume that libpng is already installed; see the
|
||||
INSTALL file for instructions on how to install libpng.
|
||||
|
||||
For examples of libpng usage, see the files "example.c", "pngtest.c",
|
||||
and the files in the "contrib" directory, all of which are included in the
|
||||
libpng distribution.
|
||||
and the files in the "contrib" directory, all of which are included in
|
||||
the libpng distribution.
|
||||
|
||||
Libpng was written as a companion to the PNG specification, as a way
|
||||
of reducing the amount of time and effort it takes to support the PNG
|
||||
@ -410,6 +410,19 @@ If you need to retrieve the limits that are being applied, use
|
||||
width_max = png_get_user_width_max(png_ptr);
|
||||
height_max = png_get_user_height_max(png_ptr);
|
||||
|
||||
The PNG specification sets no limit on the number of ancillary chunks
|
||||
allowed in a PNG datastream. You can impose a limit on the total number
|
||||
of sPLT, tEXt, iTXt, zTXt, and unknown chunks that will be stored, with
|
||||
|
||||
png_set_chunk_cache_max(png_ptr, user_chunk_cache_max);
|
||||
|
||||
where 0x7fffffffL means unlimited. You can retrieve this limit with
|
||||
|
||||
chunk_cache_max = png_get_chunk_cache_max(png_ptr);
|
||||
|
||||
This limit also applies to the number of buffers that can be allocated
|
||||
by png_decompress_chunk() while decompressing iTXt, zTXt, and iCCP chunks.
|
||||
|
||||
The high-level read interface
|
||||
|
||||
At this point there are two ways to proceed; through the high-level
|
||||
@ -437,14 +450,16 @@ you want to do are limited to the following set:
|
||||
PNG_TRANSFORM_INVERT_ALPHA Change alpha from opacity
|
||||
to transparency
|
||||
PNG_TRANSFORM_SWAP_ENDIAN Byte-swap 16-bit samples
|
||||
PNG_TRANSFORM_GRAY_TO_RGB Expand grayscale samples
|
||||
to RGB (or GA to RGBA)
|
||||
|
||||
(This excludes setting a background color, doing gamma transformation,
|
||||
dithering, and setting filler.) If this is the case, simply do this:
|
||||
|
||||
png_read_png(png_ptr, info_ptr, png_transforms, NULL)
|
||||
|
||||
where png_transforms is an integer containing the bitwise OR of
|
||||
some set of transformation flags. This call is equivalent to png_read_info(),
|
||||
where png_transforms is an integer containing the bitwise OR of some
|
||||
set of transformation flags. This call is equivalent to png_read_info(),
|
||||
followed the set of transformations indicated by the transform mask,
|
||||
then png_read_image(), and finally png_read_end().
|
||||
|
||||
@ -545,10 +560,33 @@ in until png_read_end() has read the chunk data following the image.
|
||||
for PNG 1.0)
|
||||
interlace_type - (PNG_INTERLACE_NONE or
|
||||
PNG_INTERLACE_ADAM7)
|
||||
Any or all of interlace_type, compression_type, of
|
||||
|
||||
Any or all of interlace_type, compression_type, or
|
||||
filter_method can be NULL if you are
|
||||
not interested in their values.
|
||||
|
||||
Note that png_get_IHDR() returns 32-bit data into
|
||||
the application's width and height variables.
|
||||
This is an unsafe situation if these are 16-bit
|
||||
variables. In such situations, the
|
||||
png_get_image_width() and png_get_image_height()
|
||||
functions described below are safer.
|
||||
|
||||
width = png_get_image_width(png_ptr,
|
||||
info_ptr);
|
||||
height = png_get_image_height(png_ptr,
|
||||
info_ptr);
|
||||
bit_depth = png_get_bit_depth(png_ptr,
|
||||
info_ptr);
|
||||
color_type = png_get_color_type(png_ptr,
|
||||
info_ptr);
|
||||
filter_method = png_get_filter_type(png_ptr,
|
||||
info_ptr);
|
||||
compression_type = png_get_compression_type(png_ptr,
|
||||
info_ptr);
|
||||
interlace_type = png_get_interlace_type(png_ptr,
|
||||
info_ptr);
|
||||
|
||||
channels = png_get_channels(png_ptr, info_ptr);
|
||||
channels - number of channels of info for the
|
||||
color type (valid values are 1 (GRAY,
|
||||
@ -568,29 +606,12 @@ in until png_read_end() has read the chunk data following the image.
|
||||
be in signature[4] through signature[7]
|
||||
(see png_set_sig_bytes())).
|
||||
|
||||
|
||||
width = png_get_image_width(png_ptr,
|
||||
info_ptr);
|
||||
height = png_get_image_height(png_ptr,
|
||||
info_ptr);
|
||||
bit_depth = png_get_bit_depth(png_ptr,
|
||||
info_ptr);
|
||||
color_type = png_get_color_type(png_ptr,
|
||||
info_ptr);
|
||||
filter_method = png_get_filter_type(png_ptr,
|
||||
info_ptr);
|
||||
compression_type = png_get_compression_type(png_ptr,
|
||||
info_ptr);
|
||||
interlace_type = png_get_interlace_type(png_ptr,
|
||||
info_ptr);
|
||||
|
||||
|
||||
These are also important, but their validity depends on whether the chunk
|
||||
has been read. The png_get_valid(png_ptr, info_ptr, PNG_INFO_<chunk>) and
|
||||
png_get_<chunk>(png_ptr, info_ptr, ...) functions return non-zero if the
|
||||
data has been read, or zero if it is missing. The parameters to the
|
||||
png_get_<chunk> are set directly if they are simple data types, or a pointer
|
||||
into the info_ptr is returned for any complex types.
|
||||
png_get_<chunk> are set directly if they are simple data types, or a
|
||||
pointer into the info_ptr is returned for any complex types.
|
||||
|
||||
png_get_PLTE(png_ptr, info_ptr, &palette,
|
||||
&num_palette);
|
||||
@ -628,11 +649,11 @@ into the info_ptr is returned for any complex types.
|
||||
whichever are appropriate for the
|
||||
given color type (png_color_16)
|
||||
|
||||
png_get_tRNS(png_ptr, info_ptr, &trans, &num_trans,
|
||||
&trans_values);
|
||||
trans - array of transparent entries for
|
||||
palette (PNG_INFO_tRNS)
|
||||
trans_values - graylevel or color sample values of
|
||||
png_get_tRNS(png_ptr, info_ptr, &trans_alpha,
|
||||
&num_trans, &trans_color);
|
||||
trans_alpha - array of alpha (transparency)
|
||||
entries for palette (PNG_INFO_tRNS)
|
||||
trans_color - graylevel or color sample values of
|
||||
the single transparent color for
|
||||
non-paletted images (PNG_INFO_tRNS)
|
||||
num_trans - number of transparent entries
|
||||
@ -674,6 +695,10 @@ into the info_ptr is returned for any complex types.
|
||||
string for unknown).
|
||||
text_ptr[i].lang_key - keyword in UTF-8
|
||||
(empty string for unknown).
|
||||
Note that the itxt_length, lang, and lang_key
|
||||
members of the text_ptr structure only exist
|
||||
when the library is built with iTXt chunk support.
|
||||
|
||||
num_text - number of comments (same as
|
||||
num_comments; you can put NULL here
|
||||
to avoid the duplication)
|
||||
@ -853,6 +878,43 @@ things.
|
||||
As of libpng version 1.2.9, png_set_expand_gray_1_2_4_to_8() was
|
||||
added. It expands the sample depth without changing tRNS to alpha.
|
||||
|
||||
As of libpng version 1.4.0, not all possible expansions are supported.
|
||||
|
||||
In the following table, the 01 means grayscale with depth<8, 31 means
|
||||
indexed with depth<8, other numerals represent the color type, "T" means
|
||||
the tRNS chunk is present, A means an alpha channel is present, and O
|
||||
means tRNS or alpha is present but all pixels in the image are opaque.
|
||||
|
||||
FROM 01 31 0 0T 0O 2 2T 2O 3 3T 3O 4A 4O 6A 6O
|
||||
TO
|
||||
01 -
|
||||
31 -
|
||||
0 1 -
|
||||
0T -
|
||||
0O -
|
||||
2 GX -
|
||||
2T -
|
||||
2O -
|
||||
3 1 -
|
||||
3T -
|
||||
3O -
|
||||
4A T -
|
||||
4O -
|
||||
6A GX TX TX -
|
||||
6O GX TX -
|
||||
|
||||
Within the matrix,
|
||||
"-" means the transformation is not supported.
|
||||
"X" means the transformation is obtained by png_set_expand().
|
||||
"1" means the transformation is obtained by
|
||||
png_set_expand_gray_1_2_4_to_8
|
||||
"G" means the transformation is obtained by
|
||||
png_set_gray_to_rgb().
|
||||
"P" means the transformation is obtained by
|
||||
png_set_expand_palette_to_rgb().
|
||||
"T" means the transformation is obtained by
|
||||
png_set_tRNS_to_alpha().
|
||||
|
||||
PNG can have files with 16 bits per channel. If you only can handle
|
||||
8 bits per channel, this will strip the pixels down to 8 bit.
|
||||
|
||||
@ -886,10 +948,10 @@ values of the pixels:
|
||||
|
||||
PNG files have possible bit depths of 1, 2, 4, 8, and 16. All pixels
|
||||
stored in a PNG image have been "scaled" or "shifted" up to the next
|
||||
higher possible bit depth (e.g. from 5 bits/sample in the range [0,31] to
|
||||
8 bits/sample in the range [0, 255]). However, it is also possible 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:
|
||||
higher possible bit depth (e.g. from 5 bits/sample in the range [0,31]
|
||||
to 8 bits/sample in the range [0, 255]). However, it is also possible
|
||||
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_8p sig_bit;
|
||||
|
||||
@ -1076,40 +1138,6 @@ recommended that PNG viewers support gamma correction.
|
||||
else
|
||||
png_set_gamma(png_ptr, screen_gamma, 0.45455);
|
||||
|
||||
If you need to reduce an RGB file to a paletted file, or if a paletted
|
||||
file has more entries then will fit on your screen, png_set_dither()
|
||||
will do that. Note that this is a simple match dither that merely
|
||||
finds the closest color available. This should work fairly well with
|
||||
optimized palettes, and fairly badly with linear color cubes. If you
|
||||
pass a palette that is larger then maximum_colors, the file will
|
||||
reduce the number of colors in the palette so it will fit into
|
||||
maximum_colors. If there is a histogram, it will use it to make
|
||||
more intelligent choices when reducing the palette. If there is no
|
||||
histogram, it may not do as good a job.
|
||||
|
||||
if (color_type & PNG_COLOR_MASK_COLOR)
|
||||
{
|
||||
if (png_get_valid(png_ptr, info_ptr,
|
||||
PNG_INFO_PLTE))
|
||||
{
|
||||
png_uint_16p histogram = NULL;
|
||||
|
||||
png_get_hIST(png_ptr, info_ptr,
|
||||
&histogram);
|
||||
png_set_dither(png_ptr, palette, num_palette,
|
||||
max_screen_colors, histogram, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
png_color std_color_cube[MAX_SCREEN_COLORS] =
|
||||
{ ... colors ... };
|
||||
|
||||
png_set_dither(png_ptr, std_color_cube,
|
||||
MAX_SCREEN_COLORS, MAX_SCREEN_COLORS,
|
||||
NULL,0);
|
||||
}
|
||||
}
|
||||
|
||||
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):
|
||||
@ -1336,12 +1364,11 @@ point to libpng-allocated storage with the following function:
|
||||
|
||||
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 "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 in the structure
|
||||
is freed, where n is "seq".
|
||||
by the user and not by libpng, and will in those 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 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,
|
||||
@ -1380,8 +1407,8 @@ if you transfer responsibility for free'ing text_ptr from libpng to your
|
||||
application, your application must not separately free those members.
|
||||
|
||||
The png_free_data() function will turn off the "valid" flag for anything
|
||||
it frees. If you need to turn the flag off for a chunk that was freed by your
|
||||
application instead of by libpng, you can use
|
||||
it frees. If you need to turn the flag off for a chunk that was freed by
|
||||
your application instead of by libpng, you can use
|
||||
|
||||
png_set_invalid(png_ptr, info_ptr, mask);
|
||||
mask - identifies the chunks to be made invalid,
|
||||
@ -1691,8 +1718,8 @@ the filter method, for which the only valid values are 0 (as of the
|
||||
July 1999 PNG specification, version 1.2) or 64 (if you are writing
|
||||
a PNG datastream that is to be embedded in a MNG datastream). The third
|
||||
parameter is a flag that indicates which filter type(s) are to be tested
|
||||
for each scanline. See the PNG specification for details on the specific filter
|
||||
types.
|
||||
for each scanline. See the PNG specification for details on the specific
|
||||
filter types.
|
||||
|
||||
|
||||
/* turn on or off filtering, and/or choose
|
||||
@ -1858,11 +1885,11 @@ width, height, bit_depth, and color_type must be the same in each call.
|
||||
appropriate for the given color type
|
||||
(png_color_16)
|
||||
|
||||
png_set_tRNS(png_ptr, info_ptr, trans, num_trans,
|
||||
trans_values);
|
||||
trans - array of transparent entries for
|
||||
palette (PNG_INFO_tRNS)
|
||||
trans_values - graylevel or color sample values
|
||||
png_set_tRNS(png_ptr, info_ptr, trans_alpha,
|
||||
num_trans, trans_color);
|
||||
trans_alpha - array of alpha (transparency)
|
||||
entries for palette (PNG_INFO_tRNS)
|
||||
trans_color - graylevel or color sample values
|
||||
(in order red, green, blue) of the
|
||||
single transparent color for
|
||||
non-paletted images (PNG_INFO_tRNS)
|
||||
@ -1901,6 +1928,10 @@ width, height, bit_depth, and color_type must be the same in each call.
|
||||
empty for unknown).
|
||||
text_ptr[i].translated_keyword - keyword in UTF-8 (NULL
|
||||
or empty for unknown).
|
||||
Note that the itxt_length, lang, and lang_key
|
||||
members of the text_ptr structure only exist
|
||||
when the library is built with iTXt chunk support.
|
||||
|
||||
num_text - number of comments
|
||||
|
||||
png_set_sPLT(png_ptr, info_ptr, &palette_ptr,
|
||||
@ -2106,10 +2137,10 @@ this with a call to png_write_info().
|
||||
|
||||
Note that there is one transformation you may need to do before
|
||||
png_write_info(). In PNG files, the alpha channel in an image is the
|
||||
level of opacity. If your data is supplied as a level of
|
||||
transparency, you can invert the alpha channel before you write it, so
|
||||
that 0 is fully transparent and 255 (in 8-bit or paletted images) or
|
||||
65535 (in 16-bit images) is fully opaque, with
|
||||
level of opacity. If your data is supplied as a level of transparency,
|
||||
you can invert the alpha channel before you write it, so that 0 is
|
||||
fully transparent and 255 (in 8-bit or paletted images) or 65535
|
||||
(in 16-bit images) is fully opaque, with
|
||||
|
||||
png_set_invert_alpha(png_ptr);
|
||||
|
||||
@ -2296,14 +2327,13 @@ a single row_pointer instead of an array of row_pointers:
|
||||
|
||||
png_write_row(png_ptr, row_pointer);
|
||||
|
||||
When the file is interlaced, things can get a good deal more
|
||||
complicated. The only currently (as of the PNG Specification
|
||||
version 1.2, dated July 1999) defined interlacing scheme for PNG files
|
||||
is the "Adam7" interlace scheme, that breaks down an
|
||||
image into seven smaller images of varying size. libpng will build
|
||||
these images for you, or you can do them yourself. If you want to
|
||||
build them yourself, see the PNG specification for details of which
|
||||
pixels to write when.
|
||||
When the file is interlaced, things can get a good deal more complicated.
|
||||
The only currently (as of the PNG Specification version 1.2, dated July
|
||||
1999) defined interlacing scheme for PNG files is the "Adam7" interlace
|
||||
scheme, that breaks down an image into seven smaller images of varying
|
||||
size. libpng will build these images for you, or you can do them
|
||||
yourself. If you want to build them yourself, see the PNG specification
|
||||
for details of which pixels to write when.
|
||||
|
||||
If you don't want libpng to handle the interlacing details, just
|
||||
use png_set_interlace_handling() and call png_write_rows() the
|
||||
@ -2315,17 +2345,17 @@ writing any rows:
|
||||
number_of_passes =
|
||||
png_set_interlace_handling(png_ptr);
|
||||
|
||||
This will return the number of passes needed. Currently, this
|
||||
is seven, but may change if another interlace type is added.
|
||||
This will return the number of passes needed. Currently, this is seven,
|
||||
but may change if another interlace type is added.
|
||||
|
||||
Then write the complete image number_of_passes times.
|
||||
|
||||
png_write_rows(png_ptr, row_pointers,
|
||||
number_of_rows);
|
||||
|
||||
As some of these rows are not used, and thus return immediately,
|
||||
you may want to read about interlacing in the PNG specification,
|
||||
and only update the rows that are actually used.
|
||||
As some of these rows are not used, and thus return immediately, you may
|
||||
want to read about interlacing in the PNG specification, and only update
|
||||
the rows that are actually used.
|
||||
|
||||
Finishing a sequential write
|
||||
|
||||
@ -2358,15 +2388,14 @@ point to libpng-allocated storage with the following function:
|
||||
|
||||
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 "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 in the structure
|
||||
is freed, where n is "seq".
|
||||
by the user and not by libpng, and will in those 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 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
|
||||
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
|
||||
png_destroy_write_struct().
|
||||
|
||||
The default behavior is only to free data that was allocated internally
|
||||
@ -2432,16 +2461,18 @@ 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()
|
||||
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.
|
||||
These functions also provide a void pointer that can be retrieved via
|
||||
Memory allocation is done through the functions png_malloc(), png_calloc(),
|
||||
and png_free(). These currently just call the standard C functions.
|
||||
png_calloc() calls png_malloc() and then png_memset() to clear the newly
|
||||
allocated memory to zero. 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. These functions also provide a void pointer that can be retrieved
|
||||
via
|
||||
|
||||
mem_ptr=png_get_mem_ptr(png_ptr);
|
||||
|
||||
@ -2533,10 +2564,10 @@ The motivation behind using setjmp() and longjmp() is the C++ throw and
|
||||
catch exception handling methods. This makes the code much easier to write,
|
||||
as there is no need to check every return code of every function call.
|
||||
However, there are some uncertainties about the status of local variables
|
||||
after a longjmp, so the user may want to be careful about doing anything after
|
||||
setjmp returns non-zero besides returning itself. Consult your compiler
|
||||
documentation for more details. For an alternative approach, you may wish
|
||||
to use the "cexcept" facility (see http://cexcept.sourceforge.net).
|
||||
after a longjmp, so the user may want to be careful about doing anything
|
||||
after setjmp returns non-zero besides returning itself. Consult your
|
||||
compiler documentation for more details. For an alternative approach, you
|
||||
may wish to use the "cexcept" facility (see http://cexcept.sourceforge.net).
|
||||
|
||||
Custom chunks
|
||||
|
||||
@ -2548,15 +2579,14 @@ library code itself needs to know about interactions between your
|
||||
chunk and existing `intrinsic' chunks.
|
||||
|
||||
If you need to write a new intrinsic chunk, first read the PNG
|
||||
specification. Acquire a first level of
|
||||
understanding of how it works. Pay particular attention to the
|
||||
sections that describe chunk names, and look at how other chunks were
|
||||
designed, so you can do things similarly. Second, check out the
|
||||
sections of libpng that read and write chunks. Try to find a chunk
|
||||
that is similar to yours and use it as a template. More details can
|
||||
be found in the comments inside the code. It is best to handle unknown
|
||||
chunks in a generic method, via callback functions, instead of by
|
||||
modifying libpng functions.
|
||||
specification. Acquire a first level of understanding of how it works.
|
||||
Pay particular attention to the sections that describe chunk names,
|
||||
and look at how other chunks were designed, so you can do things
|
||||
similarly. Second, check out the sections of libpng that read and
|
||||
write chunks. Try to find a chunk that is similar to yours and use
|
||||
it as a template. More details can be found in the comments inside
|
||||
the code. It is best to handle unknown chunks in a generic method,
|
||||
via callback functions, instead of by modifying libpng functions.
|
||||
|
||||
If you wish to write your own transformation for the data, look through
|
||||
the part of the code that does the transformations, and check out some of
|
||||
@ -2600,10 +2630,10 @@ Configuring for compiler xxx:
|
||||
|
||||
All includes for libpng are in pngconf.h. If you need to add, change
|
||||
or delete an include, this is the place to do it.
|
||||
The includes that are not needed outside libpng are protected by the
|
||||
PNG_INTERNAL definition, which is only defined for those routines inside
|
||||
libpng itself. The files in libpng proper only include png.h, which
|
||||
includes pngconf.h.
|
||||
The includes that are not needed outside libpng are placed in pngpriv.h,
|
||||
which is only used by the routines inside libpng itself.
|
||||
The files in libpng proper only include pngpriv.h and png.h, which
|
||||
in turn includes pngconf.h.
|
||||
|
||||
Configuring zlib:
|
||||
|
||||
@ -2733,14 +2763,14 @@ off en masse with compiler directives that define
|
||||
PNG_NO_READ[or WRITE]_TRANSFORMS, or PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS,
|
||||
or all four,
|
||||
along with directives to turn on any of the capabilities that you do
|
||||
want. The PNG_NO_READ[or WRITE]_TRANSFORMS directives disable
|
||||
the extra transformations but still leave the library fully capable of reading
|
||||
and writing PNG files with all known public chunks
|
||||
Use of the PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS directive
|
||||
produces a library that is incapable of reading or writing ancillary chunks.
|
||||
If you are not using the progressive reading capability, you can
|
||||
turn that off with PNG_NO_PROGRESSIVE_READ (don't confuse
|
||||
this with the INTERLACING capability, which you'll still have).
|
||||
want. The PNG_NO_READ[or WRITE]_TRANSFORMS directives disable the extra
|
||||
transformations but still leave the library fully capable of reading
|
||||
and writing PNG files with all known public chunks. Use of the
|
||||
PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS directive produces a library
|
||||
that is incapable of reading or writing ancillary chunks. If you are
|
||||
not using the progressive reading capability, you can turn that off
|
||||
with PNG_NO_PROGRESSIVE_READ (don't confuse this with the INTERLACING
|
||||
capability, which you'll still have).
|
||||
|
||||
All the reading and writing specific code are in separate files, so the
|
||||
linker should only grab the files it needs. However, if you want to
|
||||
@ -2875,6 +2905,9 @@ accomplish this, the functions png_create_read_struct_2(),
|
||||
png_create_write_struct_2(), png_set_mem_fn(), png_get_mem_ptr(),
|
||||
png_malloc_default(), and png_free_default() were added.
|
||||
|
||||
Support for the iTXt chunk has been enabled by default as of
|
||||
version 1.2.41.
|
||||
|
||||
Support for certain MNG features was enabled.
|
||||
|
||||
Support for numbered error messages was added. However, we never got
|
||||
@ -2929,7 +2962,127 @@ selection of assembler code features:
|
||||
We replaced all of these functions with simple stubs in libpng-1.2.20,
|
||||
when the Intel assembler code was removed due to a licensing issue.
|
||||
|
||||
IX. (Omitted)
|
||||
These macros are deprecated:
|
||||
|
||||
PNG_READ_TRANSFORMS_NOT_SUPPORTED
|
||||
PNG_PROGRESSIVE_READ_NOT_SUPPORTED
|
||||
PNG_NO_SEQUENTIAL_READ_SUPPORTED
|
||||
PNG_WRITE_TRANSFORMS_NOT_SUPPORTED
|
||||
PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED
|
||||
PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED
|
||||
|
||||
They have been replaced, respectively, by:
|
||||
|
||||
PNG_NO_READ_TRANSFORMS
|
||||
PNG_NO_PROGRESSIVE_READ
|
||||
PNG_NO_SEQUENTIAL_READ
|
||||
PNG_NO_WRITE_TRANSFORMS
|
||||
PNG_NO_READ_ANCILLARY_CHUNKS
|
||||
PNG_NO_WRITE_ANCILLARY_CHUNKS
|
||||
|
||||
PNG_MAX_UINT was replaced with PNG_UINT_31_MAX. It has been
|
||||
deprecated since libpng-1.0.16 and libpng-1.2.6.
|
||||
|
||||
The function
|
||||
png_check_sig(sig, num)
|
||||
was replaced with
|
||||
!png_sig_cmp(sig, 0, num)
|
||||
It has been deprecated since libpng-0.90.
|
||||
|
||||
The function
|
||||
png_set_gray_1_2_4_to_8()
|
||||
which also expands tRNS to alpha was replaced with
|
||||
png_set_expand_gray_1_2_4_to_8()
|
||||
which does not. It has been deprecated since libpng-1.0.18 and 1.2.9.
|
||||
|
||||
IX. Changes to Libpng from version 1.0.x/1.2.x to 1.4.x
|
||||
|
||||
Private libpng prototypes and macro definitions were moved from
|
||||
png.h and pngconf.h into a new pngpriv.h header file.
|
||||
|
||||
Functions png_set_benign_errors(), png_benign_error(), and
|
||||
png_chunk_benign_error() were added.
|
||||
|
||||
Support for setting the maximum amount of memory that the application
|
||||
will allocate for reading chunks was added, as a security measure.
|
||||
The functions png_set_chunk_cache_max() and png_get_chunk_cache_max()
|
||||
were added to the library.
|
||||
|
||||
We implemented support for I/O states by adding png_ptr member io_state
|
||||
and functions png_get_io_chunk_name() and png_get_io_state() in pngget.c
|
||||
|
||||
We added PNG_TRANSFORM_GRAY_TO_RGB to the available high-level
|
||||
input transforms.
|
||||
|
||||
Checking for and reporting of errors in the IHDR chunk is more thorough.
|
||||
|
||||
Support for global arrays was removed, to improve thread safety.
|
||||
|
||||
Some obsolete/deprecated macros and functions have been removed.
|
||||
|
||||
Typecasted NULL definitions such as
|
||||
#define png_voidp_NULL (png_voidp)NULL
|
||||
were eliminated. If you used these in your application, just use
|
||||
NULL instead.
|
||||
|
||||
The png_struct and info_struct members "trans" and "trans_values" were
|
||||
changed to "trans_alpha" and "trans_color", respectively.
|
||||
|
||||
The obsolete, unused pnggccrd.c and pngvcrd.c files and related makefiles
|
||||
were removed.
|
||||
|
||||
The PNG_1_0_X and PNG_1_2_X macros were eliminated.
|
||||
|
||||
The PNG_LEGACY_SUPPORTED macro was eliminated.
|
||||
|
||||
Many WIN32_WCE #ifdefs were removed.
|
||||
|
||||
The functions png_read_init(info_ptr), png_write_init(info_ptr),
|
||||
png_info_init(info_ptr), png_read_destroy(), and png_write_destroy()
|
||||
have been removed. They have been deprecated since libpng-0.95.
|
||||
|
||||
The png_permit_empty_plte() was removed. It has been deprecated
|
||||
since libpng-1.0.9. Use png_permit_mng_features() instead.
|
||||
|
||||
We removed the obsolete stub functions png_get_mmx_flagmask(),
|
||||
png_set_mmx_thresholds(), png_get_asm_flags(),
|
||||
png_get_mmx_bitdepth_threshold(), png_get_mmx_rowbytes_threshold(),
|
||||
png_set_asm_flags(), and png_mmx_supported()
|
||||
|
||||
We removed the obsolete png_check_sig(), png_memcpy_check(), and
|
||||
png_memset_check() functions. Instead use !png_sig_cmp(), png_memcpy(),
|
||||
and png_memset(), respectively.
|
||||
|
||||
The function png_set_gray_1_2_4_to_8() was removed. It has been
|
||||
deprecated since libpng-1.0.18 and 1.2.9, when it was replaced with
|
||||
png_set_expand_gray_1_2_4_to_8() because the former function also
|
||||
expanded palette images.
|
||||
|
||||
We changed the prototype for png_malloc() from
|
||||
png_malloc(png_structp png_ptr, png_uint_32 size)
|
||||
to
|
||||
png_malloc(png_structp png_ptr, png_alloc_size_t size)
|
||||
|
||||
The png_calloc() function was added and is used in place of
|
||||
of "png_malloc(); png_memset();" except in the case in png_read_png()
|
||||
where the array consists of pointers; in this case a "for" loop is used
|
||||
after the png_malloc() to set the pointers to NULL, to give robust.
|
||||
behavior in case the application runs out of memory part-way through
|
||||
the process.
|
||||
|
||||
We changed the prototypes of png_get_compression_buffer_size() and
|
||||
png_set_compression_buffer_size() to work with png_size_t instead of
|
||||
png_uint_32.
|
||||
|
||||
Support for numbered error messages was removed by default, since we
|
||||
never got around to actually numbering the error messages. The function
|
||||
png_set_strip_error_numbers() was removed from the library by default.
|
||||
|
||||
The png_zalloc() and png_zfree() functions are no longer exported.
|
||||
The png_zalloc() function no longer zeroes out the memory that it
|
||||
allocates.
|
||||
|
||||
We removed the trailing '.' from the warning and error messages.
|
||||
|
||||
X. Detecting libpng
|
||||
|
||||
@ -2983,6 +3136,15 @@ We use 3-space indentation, except for continued statements which
|
||||
are usually indented the same as the first line of the statement
|
||||
plus four more spaces.
|
||||
|
||||
For macro definitions we use 2-space indentation, always leaving the "#"
|
||||
in the first column.
|
||||
|
||||
#ifndef PNG_NO_FEATURE
|
||||
# ifndef PNG_FEATURE_SUPPORTED
|
||||
# define PNG_FEATURE_SUPPORTED
|
||||
# endif
|
||||
#endif
|
||||
|
||||
Comments appear with the leading "/*" at the same indentation as
|
||||
the statement that follows the comment:
|
||||
|
||||
@ -3030,7 +3192,7 @@ We mark all non-exported functions with "/* PRIVATE */"":
|
||||
|
||||
The prototypes for non-exported functions (except for those in
|
||||
pngtest) appear in
|
||||
the PNG_INTERNAL section of png.h
|
||||
pngpriv.h
|
||||
above the comment that says
|
||||
|
||||
/* Maintainer: Put new private prototypes here ^ and in libpngpf.3 */
|
||||
@ -3047,23 +3209,26 @@ cast, nor do we put one between a function name and the
|
||||
left parenthesis that follows it:
|
||||
|
||||
for (i = 2; i > 0; --i)
|
||||
x[i] = a(x) + (int)b;
|
||||
y[i] = a(x) + (int)b;
|
||||
|
||||
We prefer #ifdef and #ifndef to #if defined() and if !defined()
|
||||
when there is only one macro being tested.
|
||||
|
||||
Other rules can be inferred by inspecting the libpng
|
||||
source.
|
||||
We do not use the TAB character for indentation in the C sources.
|
||||
|
||||
Lines do not exceed 80 characters.
|
||||
|
||||
Other rules can be inferred by inspecting the libpng source.
|
||||
|
||||
XIII. Y2K Compliance in libpng
|
||||
|
||||
September 10, 2009
|
||||
January 3, 2010
|
||||
|
||||
Since the PNG Development group is an ad-hoc body, we can't make
|
||||
an official declaration.
|
||||
|
||||
This is your unofficial assurance that libpng from version 0.71 and
|
||||
upward through 1.2.40 are Y2K compliant. It is my belief that earlier
|
||||
upward through 1.4.0 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
|
||||
|
@ -19,7 +19,7 @@
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): Tim Rowley <tor@cs.brown.edu>
|
||||
* Glenn Randers-Pehrson <glennrp+bmo at gmail.com>
|
||||
* Glenn Randers-Pehrson <glennrp@gmail.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
@ -240,13 +240,9 @@
|
||||
#define png_get_iCCP MOZ_PNG_get_iCCP
|
||||
#define png_get_image_height MOZ_PNG_get_image_h
|
||||
#define png_get_image_width MOZ_PNG_get_image_w
|
||||
#define png_get_int_32 MOZ_PNG_get_int_32
|
||||
#define png_get_interlace_type MOZ_PNG_get_interlace_type
|
||||
#define png_get_libpng_ver MOZ_PNG_get_libpng_ver
|
||||
#define png_get_mem_ptr MOZ_PNG_get_mem_ptr
|
||||
#define png_get_mmx_bitdepth_threshold MOZ_PNG_get_mmx_bitdepth_thr
|
||||
#define png_get_mmx_flagmask MOZ_PNG_get_mmx_flagmask
|
||||
#define png_get_mmx_rowbytes_threshold MOZ_PNG_get_mmx_rowbytes_thr
|
||||
#define png_get_oFFs MOZ_PNG_get_oFFs
|
||||
#define png_get_pCAL MOZ_PNG_get_pCAL
|
||||
#define png_get_pHYs MOZ_PNG_get_pHYs
|
||||
@ -265,8 +261,6 @@
|
||||
#define png_get_tIME MOZ_PNG_get_tIME
|
||||
#define png_get_tRNS MOZ_PNG_get_tRNS
|
||||
#define png_get_text MOZ_PNG_get_text
|
||||
#define png_get_uint_16 MOZ_PNG_get_uint_16
|
||||
#define png_get_uint_32 MOZ_PNG_get_uint_32
|
||||
#define png_get_unknown_chunks MOZ_PNG_get_unk_chunks
|
||||
#define png_get_user_chunk_ptr MOZ_PNG_get_user_chunk_ptr
|
||||
#define png_get_user_transform_ptr MOZ_PNG_get_user_transform_ptr
|
||||
|
@ -1,8 +1,8 @@
|
||||
|
||||
/* png.c - location for general purpose libpng functions
|
||||
*
|
||||
* Last changed in libpng 1.2.39 [August 13, 2009]
|
||||
* Copyright (c) 1998-2009 Glenn Randers-Pehrson
|
||||
* Last changed in libpng 1.4.0 [January 3, 2010]
|
||||
* Copyright (c) 1998-2010 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,79 +11,17 @@
|
||||
* and license in png.h
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
#define PNG_NO_EXTERN
|
||||
#define PNG_NO_PEDANTIC_WARNINGS
|
||||
#include "png.h"
|
||||
#include "pngpriv.h"
|
||||
|
||||
/* Generate a compiler error if there is an old png.h in the search path. */
|
||||
typedef version_1_2_40 Your_png_h_is_not_version_1_2_40;
|
||||
typedef version_1_4_0 Your_png_h_is_not_version_1_4_0;
|
||||
|
||||
/* 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 */
|
||||
PNG_CONST char png_libpng_ver[18] = PNG_LIBPNG_VER_STRING;
|
||||
|
||||
#ifdef PNG_READ_SUPPORTED
|
||||
|
||||
/* png_sig was changed to a function in version 1.0.5c */
|
||||
/* Place to hold the signature string for a PNG file. */
|
||||
PNG_CONST png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
|
||||
#endif /* PNG_READ_SUPPORTED */
|
||||
|
||||
/* Invoke global declarations for constant strings for known chunk types */
|
||||
PNG_IHDR;
|
||||
PNG_IDAT;
|
||||
PNG_IEND;
|
||||
PNG_PLTE;
|
||||
PNG_bKGD;
|
||||
PNG_cHRM;
|
||||
PNG_gAMA;
|
||||
PNG_hIST;
|
||||
PNG_iCCP;
|
||||
PNG_iTXt;
|
||||
PNG_oFFs;
|
||||
PNG_pCAL;
|
||||
PNG_sCAL;
|
||||
PNG_pHYs;
|
||||
PNG_sBIT;
|
||||
PNG_sPLT;
|
||||
PNG_sRGB;
|
||||
PNG_tEXt;
|
||||
PNG_tIME;
|
||||
PNG_tRNS;
|
||||
PNG_zTXt;
|
||||
|
||||
#ifdef PNG_READ_SUPPORTED
|
||||
/* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
|
||||
|
||||
/* Start of interlace block */
|
||||
PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
|
||||
|
||||
/* Offset to next interlace block */
|
||||
PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
|
||||
|
||||
/* Start of interlace block in the y direction */
|
||||
PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
|
||||
|
||||
/* Offset to next interlace block in the y direction */
|
||||
PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
|
||||
|
||||
/* Height of interlace block. This is not currently used - if you need
|
||||
* it, uncomment it here and in png.h
|
||||
PNG_CONST int FARDATA png_pass_height[] = {8, 8, 4, 4, 2, 2, 1};
|
||||
*/
|
||||
|
||||
/* Mask to determine which pixels are valid in a pass */
|
||||
PNG_CONST int FARDATA png_pass_mask[] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
|
||||
|
||||
/* Mask to determine which pixels to overwrite while displaying */
|
||||
PNG_CONST int FARDATA png_pass_dsp_mask[]
|
||||
= {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
|
||||
|
||||
#endif /* PNG_READ_SUPPORTED */
|
||||
#endif /* PNG_USE_GLOBAL_ARRAYS */
|
||||
* string defined in png.h.
|
||||
*/
|
||||
|
||||
/* Tells libpng that we have already handled the first "num_bytes" bytes
|
||||
* of the PNG file signature. If the PNG data is embedded into another
|
||||
@ -95,11 +33,13 @@ PNG_CONST int FARDATA png_pass_dsp_mask[]
|
||||
void PNGAPI
|
||||
png_set_sig_bytes(png_structp png_ptr, int num_bytes)
|
||||
{
|
||||
png_debug(1, "in png_set_sig_bytes");
|
||||
|
||||
if (png_ptr == NULL)
|
||||
return;
|
||||
png_debug(1, "in png_set_sig_bytes");
|
||||
|
||||
if (num_bytes > 8)
|
||||
png_error(png_ptr, "Too many bytes for PNG signature.");
|
||||
png_error(png_ptr, "Too many bytes for PNG signature");
|
||||
|
||||
png_ptr->sig_bytes = (png_byte)(num_bytes < 0 ? 0 : num_bytes);
|
||||
}
|
||||
@ -130,32 +70,17 @@ png_sig_cmp(png_bytep sig, png_size_t start, png_size_t num_to_check)
|
||||
return ((int)(png_memcmp(&sig[start], &png_signature[start], num_to_check)));
|
||||
}
|
||||
|
||||
#if defined(PNG_1_0_X) || defined(PNG_1_2_X)
|
||||
/* (Obsolete) function to check signature bytes. It does not allow one
|
||||
* to check a partial signature. This function might be removed in the
|
||||
* future - use png_sig_cmp(). Returns true (nonzero) if the file is PNG.
|
||||
*/
|
||||
int PNGAPI
|
||||
png_check_sig(png_bytep sig, int num)
|
||||
{
|
||||
return ((int)!png_sig_cmp(sig, (png_size_t)0, (png_size_t)num));
|
||||
}
|
||||
#endif
|
||||
#endif /* PNG_READ_SUPPORTED */
|
||||
|
||||
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
|
||||
/* 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_voidp ptr;
|
||||
png_structp p=(png_structp)png_ptr;
|
||||
png_uint_32 save_flags=p->flags;
|
||||
png_uint_32 num_bytes;
|
||||
png_alloc_size_t num_bytes;
|
||||
|
||||
if (png_ptr == NULL)
|
||||
return (NULL);
|
||||
@ -164,36 +89,17 @@ png_zalloc(voidpf png_ptr, uInt items, uInt size)
|
||||
png_warning (p, "Potential overflow in png_zalloc()");
|
||||
return (NULL);
|
||||
}
|
||||
num_bytes = (png_uint_32)items * size;
|
||||
num_bytes = (png_alloc_size_t)items * size;
|
||||
|
||||
p->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
|
||||
ptr = (png_voidp)png_malloc((png_structp)png_ptr, num_bytes);
|
||||
p->flags=save_flags;
|
||||
|
||||
#if defined(PNG_1_0_X) && !defined(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);
|
||||
png_memset((png_bytep)ptr + (png_size_t)0x8000L, 0,
|
||||
(png_size_t)(num_bytes - (png_uint_32)0x8000L));
|
||||
}
|
||||
else
|
||||
{
|
||||
png_memset(ptr, 0, (png_size_t)num_bytes);
|
||||
}
|
||||
#endif
|
||||
return ((voidpf)ptr);
|
||||
}
|
||||
|
||||
/* 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);
|
||||
@ -246,8 +152,10 @@ png_create_info_struct(png_structp png_ptr)
|
||||
png_infop info_ptr;
|
||||
|
||||
png_debug(1, "in png_create_info_struct");
|
||||
|
||||
if (png_ptr == NULL)
|
||||
return (NULL);
|
||||
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
info_ptr = (png_infop)png_create_struct_2(PNG_STRUCT_INFO,
|
||||
png_ptr->malloc_fn, png_ptr->mem_ptr);
|
||||
@ -269,10 +177,12 @@ void PNGAPI
|
||||
png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr)
|
||||
{
|
||||
png_infop info_ptr = NULL;
|
||||
|
||||
png_debug(1, "in png_destroy_info_struct");
|
||||
|
||||
if (png_ptr == NULL)
|
||||
return;
|
||||
|
||||
png_debug(1, "in png_destroy_info_struct");
|
||||
if (info_ptr_ptr != NULL)
|
||||
info_ptr = *info_ptr_ptr;
|
||||
|
||||
@ -294,26 +204,17 @@ png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr)
|
||||
* and applications using it are urged to use png_create_info_struct()
|
||||
* instead.
|
||||
*/
|
||||
#if defined(PNG_1_0_X) || defined(PNG_1_2_X)
|
||||
#undef png_info_init
|
||||
void PNGAPI
|
||||
png_info_init(png_infop info_ptr)
|
||||
{
|
||||
/* We only come here via pre-1.0.12-compiled applications */
|
||||
png_info_init_3(&info_ptr, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
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");
|
||||
|
||||
if (info_ptr == NULL)
|
||||
return;
|
||||
|
||||
png_debug(1, "in png_info_init_3");
|
||||
|
||||
if (png_sizeof(png_info) > png_info_struct_size)
|
||||
{
|
||||
png_destroy_struct(info_ptr);
|
||||
@ -325,39 +226,36 @@ png_info_init_3(png_infopp ptr_ptr, png_size_t png_info_struct_size)
|
||||
png_memset(info_ptr, 0, png_sizeof(png_info));
|
||||
}
|
||||
|
||||
#ifdef PNG_FREE_ME_SUPPORTED
|
||||
void PNGAPI
|
||||
png_data_freer(png_structp png_ptr, png_infop info_ptr,
|
||||
int freer, png_uint_32 mask)
|
||||
{
|
||||
png_debug(1, "in png_data_freer");
|
||||
|
||||
if (png_ptr == NULL || info_ptr == NULL)
|
||||
return;
|
||||
|
||||
if (freer == PNG_DESTROY_WILL_FREE_DATA)
|
||||
info_ptr->free_me |= mask;
|
||||
else if (freer == PNG_USER_WILL_FREE_DATA)
|
||||
info_ptr->free_me &= ~mask;
|
||||
else
|
||||
png_warning(png_ptr,
|
||||
"Unknown freer parameter in png_data_freer.");
|
||||
"Unknown freer parameter in png_data_freer");
|
||||
}
|
||||
#endif
|
||||
|
||||
void PNGAPI
|
||||
png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask,
|
||||
int num)
|
||||
{
|
||||
png_debug(1, "in png_free_data");
|
||||
|
||||
if (png_ptr == NULL || info_ptr == NULL)
|
||||
return;
|
||||
|
||||
#if defined(PNG_TEXT_SUPPORTED)
|
||||
#ifdef PNG_TEXT_SUPPORTED
|
||||
/* Free text item num or (if num == -1) all text items */
|
||||
#ifdef PNG_FREE_ME_SUPPORTED
|
||||
if ((mask & PNG_FREE_TEXT) & info_ptr->free_me)
|
||||
#else
|
||||
if (mask & PNG_FREE_TEXT)
|
||||
#endif
|
||||
{
|
||||
if (num != -1)
|
||||
{
|
||||
@ -379,30 +277,19 @@ png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask,
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_tRNS_SUPPORTED)
|
||||
#ifdef PNG_tRNS_SUPPORTED
|
||||
/* Free any tRNS entry */
|
||||
#ifdef PNG_FREE_ME_SUPPORTED
|
||||
if ((mask & PNG_FREE_TRNS) & info_ptr->free_me)
|
||||
#else
|
||||
if ((mask & PNG_FREE_TRNS) && (png_ptr->flags & PNG_FLAG_FREE_TRNS))
|
||||
#endif
|
||||
{
|
||||
png_free(png_ptr, info_ptr->trans);
|
||||
info_ptr->trans = NULL;
|
||||
png_free(png_ptr, info_ptr->trans_alpha);
|
||||
info_ptr->trans_alpha = NULL;
|
||||
info_ptr->valid &= ~PNG_INFO_tRNS;
|
||||
#ifndef PNG_FREE_ME_SUPPORTED
|
||||
png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_sCAL_SUPPORTED)
|
||||
#ifdef PNG_sCAL_SUPPORTED
|
||||
/* Free any sCAL entry */
|
||||
#ifdef PNG_FREE_ME_SUPPORTED
|
||||
if ((mask & PNG_FREE_SCAL) & info_ptr->free_me)
|
||||
#else
|
||||
if (mask & PNG_FREE_SCAL)
|
||||
#endif
|
||||
{
|
||||
#if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
|
||||
png_free(png_ptr, info_ptr->scal_s_width);
|
||||
@ -414,13 +301,9 @@ png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask,
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_pCAL_SUPPORTED)
|
||||
#ifdef PNG_pCAL_SUPPORTED
|
||||
/* Free any pCAL entry */
|
||||
#ifdef PNG_FREE_ME_SUPPORTED
|
||||
if ((mask & PNG_FREE_PCAL) & info_ptr->free_me)
|
||||
#else
|
||||
if (mask & PNG_FREE_PCAL)
|
||||
#endif
|
||||
{
|
||||
png_free(png_ptr, info_ptr->pcal_purpose);
|
||||
png_free(png_ptr, info_ptr->pcal_units);
|
||||
@ -432,7 +315,7 @@ png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask,
|
||||
for (i = 0; i < (int)info_ptr->pcal_nparams; i++)
|
||||
{
|
||||
png_free(png_ptr, info_ptr->pcal_params[i]);
|
||||
info_ptr->pcal_params[i]=NULL;
|
||||
info_ptr->pcal_params[i] = NULL;
|
||||
}
|
||||
png_free(png_ptr, info_ptr->pcal_params);
|
||||
info_ptr->pcal_params = NULL;
|
||||
@ -441,13 +324,9 @@ png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask,
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_iCCP_SUPPORTED)
|
||||
#ifdef PNG_iCCP_SUPPORTED
|
||||
/* Free any iCCP entry */
|
||||
#ifdef PNG_FREE_ME_SUPPORTED
|
||||
if ((mask & PNG_FREE_ICCP) & info_ptr->free_me)
|
||||
#else
|
||||
if (mask & PNG_FREE_ICCP)
|
||||
#endif
|
||||
{
|
||||
png_free(png_ptr, info_ptr->iccp_name);
|
||||
png_free(png_ptr, info_ptr->iccp_profile);
|
||||
@ -457,13 +336,9 @@ png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask,
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_sPLT_SUPPORTED)
|
||||
#ifdef PNG_sPLT_SUPPORTED
|
||||
/* Free a given sPLT entry, or (if num == -1) all sPLT entries */
|
||||
#ifdef PNG_FREE_ME_SUPPORTED
|
||||
if ((mask & PNG_FREE_SPLT) & info_ptr->free_me)
|
||||
#else
|
||||
if (mask & PNG_FREE_SPLT)
|
||||
#endif
|
||||
{
|
||||
if (num != -1)
|
||||
{
|
||||
@ -492,18 +367,14 @@ png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask,
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
|
||||
#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
|
||||
if (png_ptr->unknown_chunk.data)
|
||||
{
|
||||
png_free(png_ptr, png_ptr->unknown_chunk.data);
|
||||
png_ptr->unknown_chunk.data = NULL;
|
||||
}
|
||||
|
||||
#ifdef PNG_FREE_ME_SUPPORTED
|
||||
if ((mask & PNG_FREE_UNKN) & info_ptr->free_me)
|
||||
#else
|
||||
if (mask & PNG_FREE_UNKN)
|
||||
#endif
|
||||
{
|
||||
if (num != -1)
|
||||
{
|
||||
@ -530,46 +401,28 @@ png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask,
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_hIST_SUPPORTED)
|
||||
#ifdef PNG_hIST_SUPPORTED
|
||||
/* Free any hIST entry */
|
||||
#ifdef PNG_FREE_ME_SUPPORTED
|
||||
if ((mask & PNG_FREE_HIST) & info_ptr->free_me)
|
||||
#else
|
||||
if ((mask & PNG_FREE_HIST) && (png_ptr->flags & PNG_FLAG_FREE_HIST))
|
||||
#endif
|
||||
{
|
||||
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
|
||||
|
||||
/* Free any PLTE entry that was internally allocated */
|
||||
#ifdef PNG_FREE_ME_SUPPORTED
|
||||
if ((mask & PNG_FREE_PLTE) & info_ptr->free_me)
|
||||
#else
|
||||
if ((mask & PNG_FREE_PLTE) && (png_ptr->flags & PNG_FLAG_FREE_PLTE))
|
||||
#endif
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
#if defined(PNG_INFO_IMAGE_SUPPORTED)
|
||||
#ifdef PNG_INFO_IMAGE_SUPPORTED
|
||||
/* Free any image bits attached to the info structure */
|
||||
#ifdef PNG_FREE_ME_SUPPORTED
|
||||
if ((mask & PNG_FREE_ROWS) & info_ptr->free_me)
|
||||
#else
|
||||
if (mask & PNG_FREE_ROWS)
|
||||
#endif
|
||||
{
|
||||
if (info_ptr->row_pointers)
|
||||
{
|
||||
@ -577,21 +430,19 @@ png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask,
|
||||
for (row = 0; row < (int)info_ptr->height; row++)
|
||||
{
|
||||
png_free(png_ptr, info_ptr->row_pointers[row]);
|
||||
info_ptr->row_pointers[row]=NULL;
|
||||
info_ptr->row_pointers[row] = NULL;
|
||||
}
|
||||
png_free(png_ptr, info_ptr->row_pointers);
|
||||
info_ptr->row_pointers=NULL;
|
||||
info_ptr->row_pointers = NULL;
|
||||
}
|
||||
info_ptr->valid &= ~PNG_INFO_IDAT;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PNG_FREE_ME_SUPPORTED
|
||||
if (num == -1)
|
||||
info_ptr->free_me &= ~mask;
|
||||
else
|
||||
info_ptr->free_me &= ~(mask & ~PNG_FREE_MUL);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* This is an internal routine to free any memory that the info struct is
|
||||
@ -605,11 +456,11 @@ png_info_destroy(png_structp png_ptr, png_infop info_ptr)
|
||||
|
||||
png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
|
||||
|
||||
#if defined(PNG_HANDLE_AS_UNKNOWN_SUPPORTED)
|
||||
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
|
||||
if (png_ptr->num_chunk_list)
|
||||
{
|
||||
png_free(png_ptr, png_ptr->chunk_list);
|
||||
png_ptr->chunk_list=NULL;
|
||||
png_ptr->chunk_list = NULL;
|
||||
png_ptr->num_chunk_list = 0;
|
||||
}
|
||||
#endif
|
||||
@ -631,7 +482,7 @@ png_get_io_ptr(png_structp png_ptr)
|
||||
}
|
||||
|
||||
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
|
||||
#if !defined(PNG_NO_STDIO)
|
||||
#ifdef PNG_STDIO_SUPPORTED
|
||||
/* Initialize the default input/output functions for the PNG file. If you
|
||||
* use your own read or write routines, you can call either png_set_read_fn()
|
||||
* or png_set_write_fn() instead of png_init_io(). If you have defined
|
||||
@ -642,13 +493,15 @@ void PNGAPI
|
||||
png_init_io(png_structp png_ptr, png_FILE_p fp)
|
||||
{
|
||||
png_debug(1, "in png_init_io");
|
||||
|
||||
if (png_ptr == NULL)
|
||||
return;
|
||||
|
||||
png_ptr->io_ptr = (png_voidp)fp;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_TIME_RFC1123_SUPPORTED)
|
||||
#ifdef PNG_TIME_RFC1123_SUPPORTED
|
||||
/* Convert the supplied time into an RFC 1123 string suitable for use in
|
||||
* a "Creation Time" or other text-based time string.
|
||||
*/
|
||||
@ -667,17 +520,6 @@ png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime)
|
||||
png_sizeof(char)));
|
||||
}
|
||||
|
||||
#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);
|
||||
}
|
||||
#else
|
||||
#ifdef USE_FAR_KEYWORD
|
||||
{
|
||||
char near_time_buf[29];
|
||||
@ -694,7 +536,6 @@ png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime)
|
||||
ptime->year, ptime->hour % 24, ptime->minute % 60,
|
||||
ptime->second % 61);
|
||||
#endif
|
||||
#endif /* _WIN32_WCE */
|
||||
return ((png_charp)png_ptr->time_buffer);
|
||||
}
|
||||
#endif /* PNG_TIME_RFC1123_SUPPORTED */
|
||||
@ -705,10 +546,23 @@ png_charp PNGAPI
|
||||
png_get_copyright(png_structp png_ptr)
|
||||
{
|
||||
png_ptr = png_ptr; /* Silence compiler warning about unused png_ptr */
|
||||
return ((png_charp) "\n libpng version 1.2.40 - September 10, 2009\n\
|
||||
Copyright (c) 1998-2009 Glenn Randers-Pehrson\n\
|
||||
Copyright (c) 1996-1997 Andreas Dilger\n\
|
||||
Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.\n");
|
||||
#ifdef PNG_STRING_COPYRIGHT
|
||||
return PNG_STRING_COPYRIGHT
|
||||
#else
|
||||
#ifdef __STDC__
|
||||
return ((png_charp) PNG_STRING_NEWLINE \
|
||||
"libpng version 1.4.0 - January 3, 2010" PNG_STRING_NEWLINE \
|
||||
"Copyright (c) 1998-2010 Glenn Randers-Pehrson" PNG_STRING_NEWLINE \
|
||||
"Copyright (c) 1996-1997 Andreas Dilger" PNG_STRING_NEWLINE \
|
||||
"Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc." \
|
||||
PNG_STRING_NEWLINE);
|
||||
#else
|
||||
return ((png_charp) "libpng version 1.4.0 - January 3, 2010\
|
||||
Copyright (c) 1998-2010 Glenn Randers-Pehrson\
|
||||
Copyright (c) 1996-1997 Andreas Dilger\
|
||||
Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.");
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
/* The following return the library version as a short string in the
|
||||
@ -740,11 +594,15 @@ png_get_header_version(png_structp png_ptr)
|
||||
{
|
||||
/* Returns longer string containing both version and date */
|
||||
png_ptr = png_ptr; /* Silence compiler warning about unused png_ptr */
|
||||
#ifdef __STDC__
|
||||
return ((png_charp) PNG_HEADER_VERSION_STRING
|
||||
#ifndef PNG_READ_SUPPORTED
|
||||
" (NO READ SUPPORT)"
|
||||
#endif
|
||||
"\n");
|
||||
PNG_STRING_NEWLINE);
|
||||
#else
|
||||
return ((png_charp) PNG_HEADER_VERSION_STRING);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
|
||||
@ -784,17 +642,6 @@ png_access_version_number(void)
|
||||
}
|
||||
|
||||
|
||||
#if defined(PNG_READ_SUPPORTED) && defined(PNG_ASSEMBLER_CODE_SUPPORTED)
|
||||
#if !defined(PNG_1_0_X)
|
||||
/* This function was added to libpng 1.2.0 */
|
||||
int PNGAPI
|
||||
png_mmx_support(void)
|
||||
{
|
||||
/* Obsolete, to be removed from libpng-1.4.0 */
|
||||
return -1;
|
||||
}
|
||||
#endif /* PNG_1_0_X */
|
||||
#endif /* PNG_READ_SUPPORTED && PNG_ASSEMBLER_CODE_SUPPORTED */
|
||||
|
||||
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
|
||||
#ifdef PNG_SIZE_T
|
||||
@ -810,8 +657,8 @@ png_convert_size(size_t size)
|
||||
#endif /* PNG_SIZE_T */
|
||||
|
||||
/* Added at libpng version 1.2.34 and 1.4.0 (moved from pngset.c) */
|
||||
#if defined(PNG_cHRM_SUPPORTED)
|
||||
#if !defined(PNG_NO_CHECK_cHRM)
|
||||
#ifdef PNG_cHRM_SUPPORTED
|
||||
#ifdef PNG_CHECK_cHRM_SUPPORTED
|
||||
|
||||
/*
|
||||
* Multiply two 32-bit numbers, V1 and V2, using 32-bit
|
||||
@ -863,6 +710,7 @@ png_check_cHRM_fixed(png_structp png_ptr,
|
||||
unsigned long xy_hi,xy_lo,yx_hi,yx_lo;
|
||||
|
||||
png_debug(1, "in function png_check_cHRM_fixed");
|
||||
|
||||
if (png_ptr == NULL)
|
||||
return 0;
|
||||
|
||||
@ -921,6 +769,148 @@ png_check_cHRM_fixed(png_structp png_ptr,
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif /* NO_PNG_CHECK_cHRM */
|
||||
#endif /* PNG_CHECK_cHRM_SUPPORTED */
|
||||
#endif /* PNG_cHRM_SUPPORTED */
|
||||
|
||||
void /* PRIVATE */
|
||||
png_check_IHDR(png_structp png_ptr,
|
||||
png_uint_32 width, png_uint_32 height, int bit_depth,
|
||||
int color_type, int interlace_type, int compression_type,
|
||||
int filter_type)
|
||||
{
|
||||
int error = 0;
|
||||
|
||||
/* Check for width and height valid values */
|
||||
if (width == 0)
|
||||
{
|
||||
png_warning(png_ptr, "Image width is zero in IHDR");
|
||||
error = 1;
|
||||
}
|
||||
|
||||
if (height == 0)
|
||||
{
|
||||
png_warning(png_ptr, "Image height is zero in IHDR");
|
||||
error = 1;
|
||||
}
|
||||
|
||||
#ifdef PNG_SET_USER_LIMITS_SUPPORTED
|
||||
if (width > png_ptr->user_width_max || width > PNG_USER_WIDTH_MAX)
|
||||
#else
|
||||
if (width > PNG_USER_WIDTH_MAX)
|
||||
#endif
|
||||
{
|
||||
png_warning(png_ptr, "Image width exceeds user limit in IHDR");
|
||||
error = 1;
|
||||
}
|
||||
|
||||
#ifdef PNG_SET_USER_LIMITS_SUPPORTED
|
||||
if (height > png_ptr->user_height_max || height > PNG_USER_HEIGHT_MAX)
|
||||
#else
|
||||
if (height > PNG_USER_HEIGHT_MAX)
|
||||
#endif
|
||||
{
|
||||
png_warning(png_ptr, "Image height exceeds user limit in IHDR");
|
||||
error = 1;
|
||||
}
|
||||
|
||||
if (width > PNG_UINT_31_MAX)
|
||||
{
|
||||
png_warning(png_ptr, "Invalid image width in IHDR");
|
||||
error = 1;
|
||||
}
|
||||
|
||||
if ( height > PNG_UINT_31_MAX)
|
||||
{
|
||||
png_warning(png_ptr, "Invalid image height in IHDR");
|
||||
error = 1;
|
||||
}
|
||||
|
||||
if ( width > (PNG_UINT_32_MAX
|
||||
>> 3) /* 8-byte RGBA pixels */
|
||||
- 64 /* bigrowbuf hack */
|
||||
- 1 /* filter byte */
|
||||
- 7*8 /* rounding of width to multiple of 8 pixels */
|
||||
- 8) /* extra max_pixel_depth pad */
|
||||
png_warning(png_ptr, "Width is too large for libpng to process pixels");
|
||||
|
||||
/* Check other values */
|
||||
if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 &&
|
||||
bit_depth != 8 && bit_depth != 16)
|
||||
{
|
||||
png_warning(png_ptr, "Invalid bit depth in IHDR");
|
||||
error = 1;
|
||||
}
|
||||
|
||||
if (color_type < 0 || color_type == 1 ||
|
||||
color_type == 5 || color_type > 6)
|
||||
{
|
||||
png_warning(png_ptr, "Invalid color type in IHDR");
|
||||
error = 1;
|
||||
}
|
||||
|
||||
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_warning(png_ptr, "Invalid color type/bit depth combination in IHDR");
|
||||
error = 1;
|
||||
}
|
||||
|
||||
if (interlace_type >= PNG_INTERLACE_LAST)
|
||||
{
|
||||
png_warning(png_ptr, "Unknown interlace method in IHDR");
|
||||
error = 1;
|
||||
}
|
||||
|
||||
if (compression_type != PNG_COMPRESSION_TYPE_BASE)
|
||||
{
|
||||
png_warning(png_ptr, "Unknown compression method in IHDR");
|
||||
error = 1;
|
||||
}
|
||||
|
||||
#ifdef 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");
|
||||
|
||||
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_warning(png_ptr, "Unknown filter method in IHDR");
|
||||
error = 1;
|
||||
}
|
||||
|
||||
if (png_ptr->mode & PNG_HAVE_PNG_SIGNATURE)
|
||||
{
|
||||
png_warning(png_ptr, "Invalid filter method in IHDR");
|
||||
error = 1;
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
if (filter_type != PNG_FILTER_TYPE_BASE)
|
||||
{
|
||||
png_warning(png_ptr, "Unknown filter method in IHDR");
|
||||
error = 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (error == 1)
|
||||
png_error(png_ptr, "Invalid IHDR data");
|
||||
}
|
||||
#endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,8 +1,8 @@
|
||||
|
||||
/* pngerror.c - stub functions for i/o and memory allocation
|
||||
*
|
||||
* Last changed in libpng 1.2.37 [June 4, 2009]
|
||||
* Copyright (c) 1998-2009 Glenn Randers-Pehrson
|
||||
* Last changed in libpng 1.4.0 [January 3, 2010]
|
||||
* Copyright (c) 1998-2010 Glenn Randers-Pehrson
|
||||
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
|
||||
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
|
||||
*
|
||||
@ -16,25 +16,26 @@
|
||||
* at each function.
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
#define PNG_NO_PEDANTIC_WARNINGS
|
||||
#include "png.h"
|
||||
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
|
||||
#include "pngpriv.h"
|
||||
|
||||
static void /* PRIVATE */
|
||||
png_default_error PNGARG((png_structp png_ptr,
|
||||
png_const_charp error_message));
|
||||
#ifndef PNG_NO_WARNINGS
|
||||
png_const_charp error_message)) PNG_NORETURN;
|
||||
#ifdef PNG_WARNINGS_SUPPORTED
|
||||
static void /* PRIVATE */
|
||||
png_default_warning PNGARG((png_structp png_ptr,
|
||||
png_const_charp warning_message));
|
||||
#endif /* PNG_NO_WARNINGS */
|
||||
#endif /* PNG_WARNINGS_SUPPORTED */
|
||||
|
||||
/* This function is called whenever there is a fatal error. This function
|
||||
* should not be changed. If there is a need to handle errors differently,
|
||||
* you should supply a replacement error function and use png_set_error_fn()
|
||||
* to replace the error function at run-time.
|
||||
*/
|
||||
#ifndef PNG_NO_ERROR_TEXT
|
||||
#ifdef PNG_ERROR_TEXT_SUPPORTED
|
||||
void PNGAPI
|
||||
png_error(png_structp png_ptr, png_const_charp error_message)
|
||||
{
|
||||
@ -45,7 +46,7 @@ png_error(png_structp png_ptr, png_const_charp error_message)
|
||||
if (png_ptr->flags&
|
||||
(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
|
||||
{
|
||||
if (*error_message == '#')
|
||||
if (*error_message == PNG_LITERAL_SHARP)
|
||||
{
|
||||
/* Strip "#nnnn " from beginning of error message. */
|
||||
int offset;
|
||||
@ -93,9 +94,9 @@ png_err(png_structp png_ptr)
|
||||
use the default handler, which will not return. */
|
||||
png_default_error(png_ptr, '\0');
|
||||
}
|
||||
#endif /* PNG_NO_ERROR_TEXT */
|
||||
#endif /* PNG_ERROR_TEXT_SUPPORTED */
|
||||
|
||||
#ifndef PNG_NO_WARNINGS
|
||||
#ifdef PNG_WARNINGS_SUPPORTED
|
||||
/* This function is called whenever there is a non-fatal error. This function
|
||||
* should not be changed. If there is a need to handle warnings differently,
|
||||
* you should supply a replacement warning function and use
|
||||
@ -112,7 +113,7 @@ png_warning(png_structp png_ptr, png_const_charp warning_message)
|
||||
(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
|
||||
#endif
|
||||
{
|
||||
if (*warning_message == '#')
|
||||
if (*warning_message == PNG_LITERAL_SHARP)
|
||||
{
|
||||
for (offset = 1; offset < 15; offset++)
|
||||
if (warning_message[offset] == ' ')
|
||||
@ -125,8 +126,18 @@ png_warning(png_structp png_ptr, png_const_charp warning_message)
|
||||
else
|
||||
png_default_warning(png_ptr, warning_message + offset);
|
||||
}
|
||||
#endif /* PNG_NO_WARNINGS */
|
||||
#endif /* PNG_WARNINGS_SUPPORTED */
|
||||
|
||||
#ifdef PNG_BENIGN_ERRORS_SUPPORTED
|
||||
void PNGAPI
|
||||
png_benign_error(png_structp png_ptr, png_const_charp error_message)
|
||||
{
|
||||
if (png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN)
|
||||
png_warning(png_ptr, error_message);
|
||||
else
|
||||
png_error(png_ptr, error_message);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* These utilities are used internally to build an error message that relates
|
||||
* to the current chunk. The chunk name comes from png_ptr->chunk_name,
|
||||
@ -141,8 +152,7 @@ static PNG_CONST char png_digit[16] = {
|
||||
};
|
||||
|
||||
#define PNG_MAX_ERROR_TEXT 64
|
||||
|
||||
#if !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT)
|
||||
#if defined(PNG_WARNINGS_SUPPORTED) || defined(PNG_ERROR_TEXT_SUPPORTED)
|
||||
static void /* PRIVATE */
|
||||
png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp
|
||||
error_message)
|
||||
@ -154,10 +164,10 @@ png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp
|
||||
int c = png_ptr->chunk_name[iin++];
|
||||
if (isnonalpha(c))
|
||||
{
|
||||
buffer[iout++] = '[';
|
||||
buffer[iout++] = PNG_LITERAL_LEFT_SQUARE_BRACKET;
|
||||
buffer[iout++] = png_digit[(c & 0xf0) >> 4];
|
||||
buffer[iout++] = png_digit[c & 0x0f];
|
||||
buffer[iout++] = ']';
|
||||
buffer[iout++] = PNG_LITERAL_RIGHT_SQUARE_BRACKET;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -190,9 +200,9 @@ png_chunk_error(png_structp png_ptr, png_const_charp error_message)
|
||||
}
|
||||
}
|
||||
#endif /* PNG_READ_SUPPORTED */
|
||||
#endif /* !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT) */
|
||||
#endif /* PNG_WARNINGS_SUPPORTED || PNG_ERROR_TEXT_SUPPORTED */
|
||||
|
||||
#ifndef PNG_NO_WARNINGS
|
||||
#ifdef PNG_WARNINGS_SUPPORTED
|
||||
void PNGAPI
|
||||
png_chunk_warning(png_structp png_ptr, png_const_charp warning_message)
|
||||
{
|
||||
@ -205,8 +215,36 @@ png_chunk_warning(png_structp png_ptr, png_const_charp warning_message)
|
||||
png_warning(png_ptr, msg);
|
||||
}
|
||||
}
|
||||
#endif /* PNG_NO_WARNINGS */
|
||||
#endif /* PNG_WARNINGS_SUPPORTED */
|
||||
|
||||
#ifdef PNG_READ_SUPPORTED
|
||||
#ifdef PNG_BENIGN_ERRORS_SUPPORTED
|
||||
void PNGAPI
|
||||
png_chunk_benign_error(png_structp png_ptr, png_const_charp error_message)
|
||||
{
|
||||
if (png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN)
|
||||
png_chunk_warning(png_ptr, error_message);
|
||||
else
|
||||
png_chunk_error(png_ptr, error_message);
|
||||
}
|
||||
#endif
|
||||
#endif /* PNG_READ_SUPPORTED */
|
||||
|
||||
#ifdef PNG_SETJMP_SUPPORTED
|
||||
/* This API only exists if ANSI-C style error handling is used,
|
||||
* otherwise it is necessary for png_default_error to be overridden.
|
||||
*/
|
||||
jmp_buf* PNGAPI
|
||||
png_set_longjmp_fn(png_structp png_ptr, png_longjmp_ptr longjmp_fn,
|
||||
size_t jmp_buf_size)
|
||||
{
|
||||
if (png_ptr == NULL || jmp_buf_size != png_sizeof(jmp_buf))
|
||||
return NULL;
|
||||
|
||||
png_ptr->longjmp_fn = longjmp_fn;
|
||||
return &png_ptr->jmpbuf;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* This is the default error handling function. Note that replacements for
|
||||
* this function MUST NOT RETURN, or the program will likely crash. This
|
||||
@ -216,9 +254,9 @@ png_chunk_warning(png_structp png_ptr, png_const_charp warning_message)
|
||||
static void /* PRIVATE */
|
||||
png_default_error(png_structp png_ptr, png_const_charp error_message)
|
||||
{
|
||||
#ifndef PNG_NO_CONSOLE_IO
|
||||
#ifdef PNG_CONSOLE_IO_SUPPORTED
|
||||
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
|
||||
if (*error_message == '#')
|
||||
if (*error_message == PNG_LITERAL_SHARP)
|
||||
{
|
||||
/* Strip "#nnnn " from beginning of error message. */
|
||||
int offset;
|
||||
@ -252,27 +290,27 @@ png_default_error(png_structp png_ptr, png_const_charp error_message)
|
||||
#endif
|
||||
|
||||
#ifdef PNG_SETJMP_SUPPORTED
|
||||
if (png_ptr)
|
||||
if (png_ptr && png_ptr->longjmp_fn)
|
||||
{
|
||||
# ifdef USE_FAR_KEYWORD
|
||||
{
|
||||
jmp_buf jmpbuf;
|
||||
png_memcpy(jmpbuf, png_ptr->jmpbuf, png_sizeof(jmp_buf));
|
||||
longjmp(jmpbuf, 1);
|
||||
png_ptr->longjmp_fn(jmpbuf, 1);
|
||||
}
|
||||
# else
|
||||
longjmp(png_ptr->jmpbuf, 1);
|
||||
png_ptr->longjmp_fn(png_ptr->jmpbuf, 1);
|
||||
# endif
|
||||
}
|
||||
#else
|
||||
PNG_ABORT();
|
||||
#endif
|
||||
#ifdef PNG_NO_CONSOLE_IO
|
||||
/* Here if not setjmp support or if png_ptr is null. */
|
||||
PNG_ABORT();
|
||||
#ifndef PNG_CONSOLE_IO_SUPPORTED
|
||||
error_message = error_message; /* Make compiler happy */
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef PNG_NO_WARNINGS
|
||||
#ifdef PNG_WARNINGS_SUPPORTED
|
||||
/* This function is called when there is a warning, but the library thinks
|
||||
* it can continue anyway. Replacement functions don't have to do anything
|
||||
* here if you don't want them to. In the default configuration, png_ptr is
|
||||
@ -281,9 +319,9 @@ png_default_error(png_structp png_ptr, png_const_charp error_message)
|
||||
static void /* PRIVATE */
|
||||
png_default_warning(png_structp png_ptr, png_const_charp warning_message)
|
||||
{
|
||||
#ifndef PNG_NO_CONSOLE_IO
|
||||
#ifdef PNG_CONSOLE_IO_SUPPORTED
|
||||
# ifdef PNG_ERROR_NUMBERS_SUPPORTED
|
||||
if (*warning_message == '#')
|
||||
if (*warning_message == PNG_LITERAL_SHARP)
|
||||
{
|
||||
int offset;
|
||||
char warning_number[16];
|
||||
@ -318,7 +356,7 @@ png_default_warning(png_structp png_ptr, png_const_charp warning_message)
|
||||
#endif
|
||||
png_ptr = png_ptr; /* Make compiler happy */
|
||||
}
|
||||
#endif /* PNG_NO_WARNINGS */
|
||||
#endif /* PNG_WARNINGS_SUPPORTED */
|
||||
|
||||
/* This function is called when the application wants to use another method
|
||||
* of handling errors and warnings. Note that the error function MUST NOT
|
||||
|
@ -1,8 +1,8 @@
|
||||
|
||||
/* pngget.c - retrieval of values from info struct
|
||||
*
|
||||
* Last changed in libpng 1.2.37 [June 4, 2009]
|
||||
* Copyright (c) 1998-2009 Glenn Randers-Pehrson
|
||||
* Last changed in libpng 1.4.0 [January 3, 2010]
|
||||
* Copyright (c) 1998-2010 Glenn Randers-Pehrson
|
||||
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
|
||||
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
|
||||
*
|
||||
@ -12,9 +12,10 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
#define PNG_NO_PEDANTIC_WARNINGS
|
||||
#include "png.h"
|
||||
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
|
||||
#include "pngpriv.h"
|
||||
|
||||
png_uint_32 PNGAPI
|
||||
png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag)
|
||||
@ -26,7 +27,7 @@ png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag)
|
||||
return(0);
|
||||
}
|
||||
|
||||
png_uint_32 PNGAPI
|
||||
png_size_t PNGAPI
|
||||
png_get_rowbytes(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL)
|
||||
@ -36,7 +37,7 @@ png_get_rowbytes(png_structp png_ptr, png_infop info_ptr)
|
||||
return(0);
|
||||
}
|
||||
|
||||
#if defined(PNG_INFO_IMAGE_SUPPORTED)
|
||||
#ifdef PNG_INFO_IMAGE_SUPPORTED
|
||||
png_bytepp PNGAPI
|
||||
png_get_rows(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
@ -117,7 +118,7 @@ png_uint_32 PNGAPI
|
||||
png_get_x_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL)
|
||||
#if defined(PNG_pHYs_SUPPORTED)
|
||||
#ifdef PNG_pHYs_SUPPORTED
|
||||
if (info_ptr->valid & PNG_INFO_pHYs)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "png_get_x_pixels_per_meter");
|
||||
@ -138,7 +139,7 @@ png_uint_32 PNGAPI
|
||||
png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL)
|
||||
#if defined(PNG_pHYs_SUPPORTED)
|
||||
#ifdef PNG_pHYs_SUPPORTED
|
||||
if (info_ptr->valid & PNG_INFO_pHYs)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "png_get_y_pixels_per_meter");
|
||||
@ -159,7 +160,7 @@ png_uint_32 PNGAPI
|
||||
png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL)
|
||||
#if defined(PNG_pHYs_SUPPORTED)
|
||||
#ifdef PNG_pHYs_SUPPORTED
|
||||
if (info_ptr->valid & PNG_INFO_pHYs)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "png_get_pixels_per_meter");
|
||||
@ -182,13 +183,15 @@ float PNGAPI
|
||||
png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL)
|
||||
#if defined(PNG_pHYs_SUPPORTED)
|
||||
#ifdef PNG_pHYs_SUPPORTED
|
||||
|
||||
if (info_ptr->valid & PNG_INFO_pHYs)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "png_get_aspect_ratio");
|
||||
|
||||
if (info_ptr->x_pixels_per_unit == 0)
|
||||
return ((float)0.0);
|
||||
|
||||
else
|
||||
return ((float)((float)info_ptr->y_pixels_per_unit
|
||||
/(float)info_ptr->x_pixels_per_unit));
|
||||
@ -204,7 +207,7 @@ png_int_32 PNGAPI
|
||||
png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL)
|
||||
#if defined(PNG_oFFs_SUPPORTED)
|
||||
#ifdef PNG_oFFs_SUPPORTED
|
||||
|
||||
if (info_ptr->valid & PNG_INFO_oFFs)
|
||||
{
|
||||
@ -227,7 +230,7 @@ png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL)
|
||||
|
||||
#if defined(PNG_oFFs_SUPPORTED)
|
||||
#ifdef PNG_oFFs_SUPPORTED
|
||||
if (info_ptr->valid & PNG_INFO_oFFs)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "png_get_y_offset_microns");
|
||||
@ -249,7 +252,7 @@ png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL)
|
||||
|
||||
#if defined(PNG_oFFs_SUPPORTED)
|
||||
#ifdef PNG_oFFs_SUPPORTED
|
||||
if (info_ptr->valid & PNG_INFO_oFFs)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "png_get_x_offset_microns");
|
||||
@ -271,7 +274,7 @@ png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL)
|
||||
|
||||
#if defined(PNG_oFFs_SUPPORTED)
|
||||
#ifdef PNG_oFFs_SUPPORTED
|
||||
if (info_ptr->valid & PNG_INFO_oFFs)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "png_get_y_offset_microns");
|
||||
@ -324,7 +327,7 @@ png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr)
|
||||
*.00003937);
|
||||
}
|
||||
|
||||
#if defined(PNG_pHYs_SUPPORTED)
|
||||
#ifdef 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)
|
||||
@ -334,6 +337,7 @@ png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr,
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "pHYs");
|
||||
|
||||
if (res_x != NULL)
|
||||
{
|
||||
*res_x = info_ptr->x_pixels_per_unit;
|
||||
@ -382,7 +386,7 @@ png_get_signature(png_structp png_ptr, png_infop info_ptr)
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
#if defined(PNG_bKGD_SUPPORTED)
|
||||
#ifdef PNG_bKGD_SUPPORTED
|
||||
png_uint_32 PNGAPI
|
||||
png_get_bKGD(png_structp png_ptr, png_infop info_ptr,
|
||||
png_color_16p *background)
|
||||
@ -391,6 +395,7 @@ png_get_bKGD(png_structp png_ptr, png_infop info_ptr,
|
||||
&& background != NULL)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "bKGD");
|
||||
|
||||
*background = &(info_ptr->background);
|
||||
return (PNG_INFO_bKGD);
|
||||
}
|
||||
@ -398,7 +403,7 @@ png_get_bKGD(png_structp png_ptr, png_infop info_ptr,
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_cHRM_SUPPORTED)
|
||||
#ifdef PNG_cHRM_SUPPORTED
|
||||
#ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
png_uint_32 PNGAPI
|
||||
png_get_cHRM(png_structp png_ptr, png_infop info_ptr,
|
||||
@ -408,6 +413,7 @@ png_get_cHRM(png_structp png_ptr, png_infop info_ptr,
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "cHRM");
|
||||
|
||||
if (white_x != NULL)
|
||||
*white_x = (double)info_ptr->x_white;
|
||||
if (white_y != NULL)
|
||||
@ -436,9 +442,10 @@ png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
|
||||
png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y,
|
||||
png_fixed_point *blue_x, png_fixed_point *blue_y)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "cHRM");
|
||||
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "cHRM");
|
||||
if (white_x != NULL)
|
||||
*white_x = info_ptr->int_x_white;
|
||||
if (white_y != NULL)
|
||||
@ -462,15 +469,16 @@ png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(PNG_gAMA_SUPPORTED)
|
||||
#ifdef 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)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "gAMA");
|
||||
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
|
||||
&& file_gamma != NULL)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "gAMA");
|
||||
*file_gamma = (double)info_ptr->gamma;
|
||||
return (PNG_INFO_gAMA);
|
||||
}
|
||||
@ -482,10 +490,11 @@ png_uint_32 PNGAPI
|
||||
png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr,
|
||||
png_fixed_point *int_file_gamma)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "gAMA");
|
||||
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
|
||||
&& int_file_gamma != NULL)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "gAMA");
|
||||
*int_file_gamma = info_ptr->int_gamma;
|
||||
return (PNG_INFO_gAMA);
|
||||
}
|
||||
@ -494,14 +503,15 @@ png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr,
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(PNG_sRGB_SUPPORTED)
|
||||
#ifdef PNG_sRGB_SUPPORTED
|
||||
png_uint_32 PNGAPI
|
||||
png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "sRGB");
|
||||
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)
|
||||
&& file_srgb_intent != NULL)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "sRGB");
|
||||
*file_srgb_intent = (int)info_ptr->srgb_intent;
|
||||
return (PNG_INFO_sRGB);
|
||||
}
|
||||
@ -509,16 +519,17 @@ png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_iCCP_SUPPORTED)
|
||||
#ifdef PNG_iCCP_SUPPORTED
|
||||
png_uint_32 PNGAPI
|
||||
png_get_iCCP(png_structp png_ptr, png_infop info_ptr,
|
||||
png_charpp name, int *compression_type,
|
||||
png_charpp profile, png_uint_32 *proflen)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "iCCP");
|
||||
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP)
|
||||
&& name != NULL && profile != NULL && proflen != NULL)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "iCCP");
|
||||
*name = info_ptr->iccp_name;
|
||||
*profile = info_ptr->iccp_profile;
|
||||
/* Compression_type is a dummy so the API won't have to change
|
||||
@ -532,7 +543,7 @@ png_get_iCCP(png_structp png_ptr, png_infop info_ptr,
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_sPLT_SUPPORTED)
|
||||
#ifdef PNG_sPLT_SUPPORTED
|
||||
png_uint_32 PNGAPI
|
||||
png_get_sPLT(png_structp png_ptr, png_infop info_ptr,
|
||||
png_sPLT_tpp spalettes)
|
||||
@ -546,14 +557,15 @@ png_get_sPLT(png_structp png_ptr, png_infop info_ptr,
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_hIST_SUPPORTED)
|
||||
#ifdef PNG_hIST_SUPPORTED
|
||||
png_uint_32 PNGAPI
|
||||
png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "hIST");
|
||||
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)
|
||||
&& hist != NULL)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "hIST");
|
||||
*hist = info_ptr->hist;
|
||||
return (PNG_INFO_hIST);
|
||||
}
|
||||
@ -568,62 +580,48 @@ png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
|
||||
int *filter_type)
|
||||
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL && width != NULL && height != NULL &&
|
||||
bit_depth != NULL && color_type != NULL)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "IHDR");
|
||||
*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");
|
||||
png_debug1(1, "in %s retrieval function", "IHDR");
|
||||
|
||||
*color_type = info_ptr->color_type;
|
||||
if (png_ptr == NULL || info_ptr == NULL || width == NULL ||
|
||||
height == NULL || bit_depth == NULL || color_type == NULL)
|
||||
return (0);
|
||||
|
||||
if (info_ptr->color_type > 6)
|
||||
png_error(png_ptr, "Invalid color type");
|
||||
*width = info_ptr->width;
|
||||
*height = info_ptr->height;
|
||||
*bit_depth = info_ptr->bit_depth;
|
||||
*color_type = info_ptr->color_type;
|
||||
|
||||
if (compression_type != NULL)
|
||||
*compression_type = info_ptr->compression_type;
|
||||
if (compression_type != NULL)
|
||||
*compression_type = info_ptr->compression_type;
|
||||
|
||||
if (filter_type != NULL)
|
||||
*filter_type = info_ptr->filter_type;
|
||||
if (filter_type != NULL)
|
||||
*filter_type = info_ptr->filter_type;
|
||||
|
||||
if (interlace_type != NULL)
|
||||
*interlace_type = info_ptr->interlace_type;
|
||||
if (interlace_type != NULL)
|
||||
*interlace_type = info_ptr->interlace_type;
|
||||
|
||||
/* Check for potential overflow of rowbytes */
|
||||
if (*width == 0 || *width > PNG_UINT_31_MAX)
|
||||
png_error(png_ptr, "Invalid image width");
|
||||
/* This is redundant if we can be sure that the info_ptr values were all
|
||||
* assigned in png_set_IHDR(). We do the check anyhow in case an
|
||||
* application has ignored our advice not to mess with the members
|
||||
* of info_ptr directly.
|
||||
*/
|
||||
png_check_IHDR (png_ptr, info_ptr->width, info_ptr->height,
|
||||
info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type,
|
||||
info_ptr->compression_type, info_ptr->filter_type);
|
||||
|
||||
if (*height == 0 || *height > PNG_UINT_31_MAX)
|
||||
png_error(png_ptr, "Invalid image height");
|
||||
|
||||
if (info_ptr->width > (PNG_UINT_32_MAX
|
||||
>> 3) /* 8-byte RGBA pixels */
|
||||
- 64 /* bigrowbuf hack */
|
||||
- 1 /* filter byte */
|
||||
- 7*8 /* rounding of width to multiple of 8 pixels */
|
||||
- 8) /* extra max_pixel_depth pad */
|
||||
{
|
||||
png_warning(png_ptr,
|
||||
"Width too large for libpng to process image data.");
|
||||
}
|
||||
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
return (1);
|
||||
}
|
||||
|
||||
#if defined(PNG_oFFs_SUPPORTED)
|
||||
#ifdef 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)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "oFFs");
|
||||
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)
|
||||
&& offset_x != NULL && offset_y != NULL && unit_type != NULL)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "oFFs");
|
||||
*offset_x = info_ptr->x_offset;
|
||||
*offset_y = info_ptr->y_offset;
|
||||
*unit_type = (int)info_ptr->offset_unit_type;
|
||||
@ -633,17 +631,18 @@ png_get_oFFs(png_structp png_ptr, png_infop info_ptr,
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_pCAL_SUPPORTED)
|
||||
#ifdef 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,
|
||||
png_charp *units, png_charpp *params)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "pCAL");
|
||||
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)
|
||||
&& purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
|
||||
nparams != NULL && units != NULL && params != NULL)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "pCAL");
|
||||
*purpose = info_ptr->pcal_purpose;
|
||||
*X0 = info_ptr->pcal_X0;
|
||||
*X1 = info_ptr->pcal_X1;
|
||||
@ -657,7 +656,7 @@ png_get_pCAL(png_structp png_ptr, png_infop info_ptr,
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_sCAL_SUPPORTED)
|
||||
#ifdef PNG_sCAL_SUPPORTED
|
||||
#ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
png_uint_32 PNGAPI
|
||||
png_get_sCAL(png_structp png_ptr, png_infop info_ptr,
|
||||
@ -693,18 +692,18 @@ png_get_sCAL_s(png_structp png_ptr, png_infop info_ptr,
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(PNG_pHYs_SUPPORTED)
|
||||
#ifdef 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)
|
||||
{
|
||||
png_uint_32 retval = 0;
|
||||
|
||||
png_debug1(1, "in %s retrieval function", "pHYs");
|
||||
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_pHYs))
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "pHYs");
|
||||
|
||||
if (res_x != NULL)
|
||||
{
|
||||
*res_x = info_ptr->x_pixels_per_unit;
|
||||
@ -731,10 +730,11 @@ png_uint_32 PNGAPI
|
||||
png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette,
|
||||
int *num_palette)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "PLTE");
|
||||
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE)
|
||||
&& palette != NULL)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "PLTE");
|
||||
*palette = info_ptr->palette;
|
||||
*num_palette = info_ptr->num_palette;
|
||||
png_debug1(3, "num_palette = %d", *num_palette);
|
||||
@ -743,14 +743,15 @@ png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette,
|
||||
return (0);
|
||||
}
|
||||
|
||||
#if defined(PNG_sBIT_SUPPORTED)
|
||||
#ifdef PNG_sBIT_SUPPORTED
|
||||
png_uint_32 PNGAPI
|
||||
png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "sBIT");
|
||||
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)
|
||||
&& sig_bit != NULL)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "sBIT");
|
||||
*sig_bit = &(info_ptr->sig_bit);
|
||||
return (PNG_INFO_sBIT);
|
||||
}
|
||||
@ -758,7 +759,7 @@ png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_TEXT_SUPPORTED)
|
||||
#ifdef 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)
|
||||
@ -783,14 +784,15 @@ png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr,
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_tIME_SUPPORTED)
|
||||
#ifdef PNG_tIME_SUPPORTED
|
||||
png_uint_32 PNGAPI
|
||||
png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "tIME");
|
||||
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)
|
||||
&& mod_time != NULL)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "tIME");
|
||||
*mod_time = &(info_ptr->mod_time);
|
||||
return (PNG_INFO_tIME);
|
||||
}
|
||||
@ -798,36 +800,37 @@ png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_tRNS_SUPPORTED)
|
||||
#ifdef 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)
|
||||
png_bytep *trans_alpha, int *num_trans, png_color_16p *trans_color)
|
||||
{
|
||||
png_uint_32 retval = 0;
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "tRNS");
|
||||
|
||||
if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
|
||||
{
|
||||
if (trans != NULL)
|
||||
if (trans_alpha != NULL)
|
||||
{
|
||||
*trans = info_ptr->trans;
|
||||
*trans_alpha = info_ptr->trans_alpha;
|
||||
retval |= PNG_INFO_tRNS;
|
||||
}
|
||||
|
||||
if (trans_values != NULL)
|
||||
*trans_values = &(info_ptr->trans_values);
|
||||
if (trans_color != NULL)
|
||||
*trans_color = &(info_ptr->trans_color);
|
||||
}
|
||||
else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
|
||||
{
|
||||
if (trans_values != NULL)
|
||||
if (trans_color != NULL)
|
||||
{
|
||||
*trans_values = &(info_ptr->trans_values);
|
||||
*trans_color = &(info_ptr->trans_color);
|
||||
retval |= PNG_INFO_tRNS;
|
||||
}
|
||||
|
||||
if (trans != NULL)
|
||||
*trans = NULL;
|
||||
if (trans_alpha != NULL)
|
||||
*trans_alpha = NULL;
|
||||
}
|
||||
if (num_trans != NULL)
|
||||
{
|
||||
@ -999,7 +1002,7 @@ png_get_first_frame_is_hidden(png_structp png_ptr, png_infop info_ptr)
|
||||
return 0;
|
||||
}
|
||||
#endif /* PNG_APNG_SUPPORTED */
|
||||
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
|
||||
#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED
|
||||
png_uint_32 PNGAPI
|
||||
png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr,
|
||||
png_unknown_chunkpp unknowns)
|
||||
@ -1013,7 +1016,7 @@ png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr,
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
|
||||
#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED
|
||||
png_byte PNGAPI
|
||||
png_get_rgb_to_gray_status (png_structp png_ptr)
|
||||
{
|
||||
@ -1021,7 +1024,7 @@ png_get_rgb_to_gray_status (png_structp png_ptr)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_USER_CHUNKS_SUPPORTED)
|
||||
#ifdef PNG_USER_CHUNKS_SUPPORTED
|
||||
png_voidp PNGAPI
|
||||
png_get_user_chunk_ptr(png_structp png_ptr)
|
||||
{
|
||||
@ -1030,60 +1033,13 @@ png_get_user_chunk_ptr(png_structp png_ptr)
|
||||
#endif
|
||||
|
||||
#ifdef PNG_WRITE_SUPPORTED
|
||||
png_uint_32 PNGAPI
|
||||
png_size_t PNGAPI
|
||||
png_get_compression_buffer_size(png_structp png_ptr)
|
||||
{
|
||||
return (png_uint_32)(png_ptr? png_ptr->zbuf_size : 0L);
|
||||
return (png_ptr ? png_ptr->zbuf_size : 0L);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PNG_ASSEMBLER_CODE_SUPPORTED
|
||||
#ifndef PNG_1_0_X
|
||||
/* 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)
|
||||
{
|
||||
/* Obsolete, to be removed from libpng-1.4.0 */
|
||||
return (png_ptr? 0L: 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)
|
||||
{
|
||||
/* Obsolete, to be removed from libpng-1.4.0 */
|
||||
flag_select=flag_select;
|
||||
return 0L;
|
||||
}
|
||||
|
||||
/* 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)
|
||||
{
|
||||
/* Obsolete, to be removed from libpng-1.4.0 */
|
||||
flag_select=flag_select;
|
||||
*compilerID = -1; /* unknown (i.e., no asm/MMX code compiled) */
|
||||
return 0L;
|
||||
}
|
||||
|
||||
/* This function was added to libpng 1.2.0 */
|
||||
png_byte PNGAPI
|
||||
png_get_mmx_bitdepth_threshold (png_structp png_ptr)
|
||||
{
|
||||
/* Obsolete, to be removed from libpng-1.4.0 */
|
||||
return (png_ptr? 0: 0);
|
||||
}
|
||||
|
||||
/* This function was added to libpng 1.2.0 */
|
||||
png_uint_32 PNGAPI
|
||||
png_get_mmx_rowbytes_threshold (png_structp png_ptr)
|
||||
{
|
||||
/* Obsolete, to be removed from libpng-1.4.0 */
|
||||
return (png_ptr? 0L: 0L);
|
||||
}
|
||||
#endif /* ?PNG_1_0_X */
|
||||
#endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
|
||||
|
||||
#ifdef PNG_SET_USER_LIMITS_SUPPORTED
|
||||
/* These functions were added to libpng 1.2.6 */
|
||||
@ -1097,7 +1053,27 @@ png_get_user_height_max (png_structp png_ptr)
|
||||
{
|
||||
return (png_ptr? png_ptr->user_height_max : 0);
|
||||
}
|
||||
/* This function was added to libpng 1.4.0 */
|
||||
png_uint_32 PNGAPI
|
||||
png_get_chunk_cache_max (png_structp png_ptr)
|
||||
{
|
||||
return (png_ptr? png_ptr->user_chunk_cache_max? 0x7fffffffL :
|
||||
png_ptr->user_chunk_cache_max - 1 : 0);
|
||||
}
|
||||
#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
|
||||
|
||||
#ifdef PNG_IO_STATE_SUPPORTED
|
||||
png_uint_32 PNGAPI
|
||||
png_get_io_state (png_structp png_ptr)
|
||||
{
|
||||
return png_ptr->io_state;
|
||||
}
|
||||
|
||||
png_bytep PNGAPI
|
||||
png_get_io_chunk_name (png_structp png_ptr)
|
||||
{
|
||||
return png_ptr->chunk_name;
|
||||
}
|
||||
#endif /* ?PNG_IO_STATE_SUPPORTED */
|
||||
|
||||
#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
|
||||
|
@ -1,8 +1,8 @@
|
||||
|
||||
/* pngmem.c - stub functions for memory allocation
|
||||
*
|
||||
* Last changed in libpng 1.2.37 [June 4, 2009]
|
||||
* Copyright (c) 1998-2009 Glenn Randers-Pehrson
|
||||
* Last changed in libpng 1.4.0 [January 3, 2010]
|
||||
* Copyright (c) 1998-2010 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,9 +17,10 @@
|
||||
* identify the replacement functions.
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
#define PNG_NO_PEDANTIC_WARNINGS
|
||||
#include "png.h"
|
||||
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
|
||||
#include "pngpriv.h"
|
||||
|
||||
/* Borland DOS special memory handler */
|
||||
#if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
|
||||
@ -31,7 +32,7 @@ png_voidp /* PRIVATE */
|
||||
png_create_struct(int type)
|
||||
{
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL));
|
||||
return (png_create_struct_2(type, NULL, NULL));
|
||||
}
|
||||
|
||||
/* Alternate version of png_create_struct, for use with user-defined malloc. */
|
||||
@ -70,7 +71,7 @@ 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_voidp_NULL);
|
||||
png_destroy_struct_2(struct_ptr, NULL, NULL);
|
||||
}
|
||||
|
||||
/* Free memory allocated by a png_create_struct() call */
|
||||
@ -114,9 +115,19 @@ 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_calloc(png_structp png_ptr, png_alloc_size_t size)
|
||||
{
|
||||
png_voidp ret;
|
||||
|
||||
ret = (png_malloc(png_ptr, size));
|
||||
if (ret != NULL)
|
||||
png_memset(ret,0,(png_size_t)size);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
png_voidp PNGAPI
|
||||
png_malloc(png_structp png_ptr, png_uint_32 size)
|
||||
png_malloc(png_structp png_ptr, png_alloc_size_t size)
|
||||
{
|
||||
png_voidp ret;
|
||||
|
||||
@ -129,12 +140,12 @@ png_malloc(png_structp png_ptr, png_uint_32 size)
|
||||
else
|
||||
ret = (png_malloc_default(png_ptr, size));
|
||||
if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
|
||||
png_error(png_ptr, "Out of memory!");
|
||||
png_error(png_ptr, "Out of memory");
|
||||
return (ret);
|
||||
}
|
||||
|
||||
png_voidp PNGAPI
|
||||
png_malloc_default(png_structp png_ptr, png_uint_32 size)
|
||||
png_malloc_default(png_structp png_ptr, png_alloc_size_t size)
|
||||
{
|
||||
png_voidp ret;
|
||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||
@ -190,9 +201,9 @@ png_malloc_default(png_structp png_ptr, png_uint_32 size)
|
||||
{
|
||||
#ifndef PNG_USER_MEM_SUPPORTED
|
||||
if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
|
||||
png_error(png_ptr, "Out Of Memory."); /* Note "O" and "M" */
|
||||
png_error(png_ptr, "Out Of Memory"); /* Note "O" and "M" */
|
||||
else
|
||||
png_warning(png_ptr, "Out Of Memory.");
|
||||
png_warning(png_ptr, "Out Of Memory");
|
||||
#endif
|
||||
return (NULL);
|
||||
}
|
||||
@ -218,9 +229,9 @@ png_malloc_default(png_structp png_ptr, png_uint_32 size)
|
||||
{
|
||||
#ifndef PNG_USER_MEM_SUPPORTED
|
||||
if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
|
||||
png_error(png_ptr, "Out Of memory."); /* Note "O" and "M" */
|
||||
png_error(png_ptr, "Out Of memory"); /* Note "O" and "M" */
|
||||
else
|
||||
png_warning(png_ptr, "Out Of memory.");
|
||||
png_warning(png_ptr, "Out Of memory");
|
||||
#endif
|
||||
return (NULL);
|
||||
}
|
||||
@ -247,9 +258,9 @@ png_malloc_default(png_structp png_ptr, png_uint_32 size)
|
||||
{
|
||||
#ifndef PNG_USER_MEM_SUPPORTED
|
||||
if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
|
||||
png_error(png_ptr, "Out of Memory."); /* Note "o" and "M" */
|
||||
png_error(png_ptr, "Out of Memory"); /* Note "o" and "M" */
|
||||
else
|
||||
png_warning(png_ptr, "Out of Memory.");
|
||||
png_warning(png_ptr, "Out of Memory");
|
||||
#endif
|
||||
return (NULL);
|
||||
}
|
||||
@ -263,9 +274,9 @@ png_malloc_default(png_structp png_ptr, png_uint_32 size)
|
||||
if (ret == NULL)
|
||||
{
|
||||
if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
|
||||
png_error(png_ptr, "Out of memory."); /* Note "o" and "m" */
|
||||
png_error(png_ptr, "Out of memory"); /* Note "o" and "m" */
|
||||
else
|
||||
png_warning(png_ptr, "Out of memory."); /* Note "o" and "m" */
|
||||
png_warning(png_ptr, "Out of memory"); /* Note "o" and "m" */
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -337,7 +348,7 @@ png_voidp /* PRIVATE */
|
||||
png_create_struct(int type)
|
||||
{
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL));
|
||||
return (png_create_struct_2(type, NULL, NULL));
|
||||
}
|
||||
|
||||
/* Allocate memory for a png_struct or a png_info. The malloc and
|
||||
@ -391,7 +402,7 @@ 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_voidp_NULL);
|
||||
png_destroy_struct_2(struct_ptr, NULL, NULL);
|
||||
}
|
||||
|
||||
/* Free memory allocated by a png_create_struct() call */
|
||||
@ -431,9 +442,19 @@ png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
|
||||
* have the ability to do that.
|
||||
*/
|
||||
|
||||
png_voidp PNGAPI
|
||||
png_calloc(png_structp png_ptr, png_alloc_size_t size)
|
||||
{
|
||||
png_voidp ret;
|
||||
|
||||
ret = (png_malloc(png_ptr, size));
|
||||
if (ret != NULL)
|
||||
png_memset(ret,0,(png_size_t)size);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
png_voidp PNGAPI
|
||||
png_malloc(png_structp png_ptr, png_uint_32 size)
|
||||
png_malloc(png_structp png_ptr, png_alloc_size_t size)
|
||||
{
|
||||
png_voidp ret;
|
||||
|
||||
@ -446,12 +467,12 @@ png_malloc(png_structp png_ptr, png_uint_32 size)
|
||||
else
|
||||
ret = (png_malloc_default(png_ptr, size));
|
||||
if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
|
||||
png_error(png_ptr, "Out of Memory!");
|
||||
png_error(png_ptr, "Out of Memory");
|
||||
return (ret);
|
||||
}
|
||||
|
||||
png_voidp PNGAPI
|
||||
png_malloc_default(png_structp png_ptr, png_uint_32 size)
|
||||
png_malloc_default(png_structp png_ptr, png_alloc_size_t size)
|
||||
{
|
||||
png_voidp ret;
|
||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||
@ -538,16 +559,13 @@ png_free_default(png_structp png_ptr, png_voidp ptr)
|
||||
|
||||
#endif /* Not Borland DOS special memory handler */
|
||||
|
||||
#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 set up png_malloc() to 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_malloc_warn(png_structp png_ptr, png_alloc_size_t size)
|
||||
{
|
||||
png_voidp ptr;
|
||||
png_uint_32 save_flags;
|
||||
@ -560,34 +578,7 @@ png_malloc_warn(png_structp png_ptr, png_uint_32 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)
|
||||
{
|
||||
png_size_t size;
|
||||
|
||||
size = (png_size_t)length;
|
||||
if ((png_uint_32)size != length)
|
||||
png_error(png_ptr, "Overflow in png_memcpy_check.");
|
||||
|
||||
return(png_memcpy (s1, s2, size));
|
||||
}
|
||||
|
||||
png_voidp PNGAPI
|
||||
png_memset_check (png_structp png_ptr, png_voidp s1, int value,
|
||||
png_uint_32 length)
|
||||
{
|
||||
png_size_t size;
|
||||
|
||||
size = (png_size_t)length;
|
||||
if ((png_uint_32)size != length)
|
||||
png_error(png_ptr, "Overflow in png_memset_check.");
|
||||
|
||||
return (png_memset (s1, value, size));
|
||||
|
||||
}
|
||||
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
/* This function is called when the application wants to use another method
|
||||
|
@ -1,8 +1,8 @@
|
||||
|
||||
/* pngpread.c - read a png file in push mode
|
||||
*
|
||||
* Last changed in libpng 1.2.38 [July 16, 2009]
|
||||
* Copyright (c) 1998-2009 Glenn Randers-Pehrson
|
||||
* Last changed in libpng 1.4.0 [January 3, 2010]
|
||||
* Copyright (c) 1998-2010 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,9 +11,10 @@
|
||||
* and license in png.h
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
#define PNG_NO_PEDANTIC_WARNINGS
|
||||
#include "png.h"
|
||||
#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
|
||||
#include "pngpriv.h"
|
||||
|
||||
/* Push model modes */
|
||||
#define PNG_READ_SIG_MODE 0
|
||||
@ -70,7 +71,7 @@ png_process_some_data(png_structp png_ptr, png_infop info_ptr)
|
||||
break;
|
||||
}
|
||||
|
||||
#if defined(PNG_READ_tEXt_SUPPORTED)
|
||||
#ifdef PNG_READ_tEXt_SUPPORTED
|
||||
case PNG_READ_tEXt_MODE:
|
||||
{
|
||||
png_push_read_tEXt(png_ptr, info_ptr);
|
||||
@ -78,7 +79,7 @@ png_process_some_data(png_structp png_ptr, png_infop info_ptr)
|
||||
}
|
||||
|
||||
#endif
|
||||
#if defined(PNG_READ_zTXt_SUPPORTED)
|
||||
#ifdef PNG_READ_zTXt_SUPPORTED
|
||||
case PNG_READ_zTXt_MODE:
|
||||
{
|
||||
png_push_read_zTXt(png_ptr, info_ptr);
|
||||
@ -86,7 +87,7 @@ png_process_some_data(png_structp png_ptr, png_infop info_ptr)
|
||||
}
|
||||
|
||||
#endif
|
||||
#if defined(PNG_READ_iTXt_SUPPORTED)
|
||||
#ifdef PNG_READ_iTXt_SUPPORTED
|
||||
case PNG_READ_iTXt_MODE:
|
||||
{
|
||||
png_push_read_iTXt(png_ptr, info_ptr);
|
||||
@ -149,68 +150,67 @@ png_push_read_sig(png_structp png_ptr, png_infop info_ptr)
|
||||
void /* PRIVATE */
|
||||
png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
PNG_CONST PNG_IHDR;
|
||||
PNG_CONST PNG_IDAT;
|
||||
PNG_CONST PNG_IEND;
|
||||
PNG_CONST PNG_PLTE;
|
||||
#if defined(PNG_READ_bKGD_SUPPORTED)
|
||||
PNG_CONST PNG_bKGD;
|
||||
PNG_IHDR;
|
||||
PNG_IDAT;
|
||||
PNG_IEND;
|
||||
PNG_PLTE;
|
||||
#ifdef PNG_READ_bKGD_SUPPORTED
|
||||
PNG_bKGD;
|
||||
#endif
|
||||
#if defined(PNG_READ_cHRM_SUPPORTED)
|
||||
PNG_CONST PNG_cHRM;
|
||||
#ifdef PNG_READ_cHRM_SUPPORTED
|
||||
PNG_cHRM;
|
||||
#endif
|
||||
#if defined(PNG_READ_gAMA_SUPPORTED)
|
||||
PNG_CONST PNG_gAMA;
|
||||
#ifdef PNG_READ_gAMA_SUPPORTED
|
||||
PNG_gAMA;
|
||||
#endif
|
||||
#if defined(PNG_READ_hIST_SUPPORTED)
|
||||
PNG_CONST PNG_hIST;
|
||||
#ifdef PNG_READ_hIST_SUPPORTED
|
||||
PNG_hIST;
|
||||
#endif
|
||||
#if defined(PNG_READ_iCCP_SUPPORTED)
|
||||
PNG_CONST PNG_iCCP;
|
||||
#ifdef PNG_READ_iCCP_SUPPORTED
|
||||
PNG_iCCP;
|
||||
#endif
|
||||
#if defined(PNG_READ_iTXt_SUPPORTED)
|
||||
PNG_CONST PNG_iTXt;
|
||||
#ifdef PNG_READ_iTXt_SUPPORTED
|
||||
PNG_iTXt;
|
||||
#endif
|
||||
#if defined(PNG_READ_oFFs_SUPPORTED)
|
||||
PNG_CONST PNG_oFFs;
|
||||
#ifdef PNG_READ_oFFs_SUPPORTED
|
||||
PNG_oFFs;
|
||||
#endif
|
||||
#if defined(PNG_READ_pCAL_SUPPORTED)
|
||||
PNG_CONST PNG_pCAL;
|
||||
#ifdef PNG_READ_pCAL_SUPPORTED
|
||||
PNG_pCAL;
|
||||
#endif
|
||||
#if defined(PNG_READ_pHYs_SUPPORTED)
|
||||
PNG_CONST PNG_pHYs;
|
||||
#ifdef PNG_READ_pHYs_SUPPORTED
|
||||
PNG_pHYs;
|
||||
#endif
|
||||
#if defined(PNG_READ_sBIT_SUPPORTED)
|
||||
PNG_CONST PNG_sBIT;
|
||||
#ifdef PNG_READ_sBIT_SUPPORTED
|
||||
PNG_sBIT;
|
||||
#endif
|
||||
#if defined(PNG_READ_sCAL_SUPPORTED)
|
||||
PNG_CONST PNG_sCAL;
|
||||
#ifdef PNG_READ_sCAL_SUPPORTED
|
||||
PNG_sCAL;
|
||||
#endif
|
||||
#if defined(PNG_READ_sRGB_SUPPORTED)
|
||||
PNG_CONST PNG_sRGB;
|
||||
#ifdef PNG_READ_sRGB_SUPPORTED
|
||||
PNG_sRGB;
|
||||
#endif
|
||||
#if defined(PNG_READ_sPLT_SUPPORTED)
|
||||
PNG_CONST PNG_sPLT;
|
||||
#ifdef PNG_READ_sPLT_SUPPORTED
|
||||
PNG_sPLT;
|
||||
#endif
|
||||
#if defined(PNG_READ_tEXt_SUPPORTED)
|
||||
PNG_CONST PNG_tEXt;
|
||||
#ifdef PNG_READ_tEXt_SUPPORTED
|
||||
PNG_tEXt;
|
||||
#endif
|
||||
#if defined(PNG_READ_tIME_SUPPORTED)
|
||||
PNG_CONST PNG_tIME;
|
||||
#ifdef PNG_READ_tIME_SUPPORTED
|
||||
PNG_tIME;
|
||||
#endif
|
||||
#if defined(PNG_READ_tRNS_SUPPORTED)
|
||||
PNG_CONST PNG_tRNS;
|
||||
#ifdef PNG_READ_tRNS_SUPPORTED
|
||||
PNG_tRNS;
|
||||
#endif
|
||||
#if defined(PNG_READ_zTXt_SUPPORTED)
|
||||
PNG_CONST PNG_zTXt;
|
||||
#ifdef PNG_READ_zTXt_SUPPORTED
|
||||
PNG_zTXt;
|
||||
#endif
|
||||
#if defined(PNG_READ_APNG_SUPPORTED)
|
||||
PNG_CONST PNG_acTL;
|
||||
PNG_CONST PNG_fcTL;
|
||||
PNG_CONST PNG_fdAT;
|
||||
PNG_acTL;
|
||||
PNG_fcTL;
|
||||
PNG_fdAT;
|
||||
#endif
|
||||
#endif /* PNG_USE_LOCAL_ARRAYS */
|
||||
|
||||
/* First we make sure we have enough data for the 4 byte chunk name
|
||||
* and the 4 byte chunk length before proceeding with decoding the
|
||||
* chunk data. To fully decode each of these chunks, we also make
|
||||
@ -424,9 +424,8 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
|
||||
return;
|
||||
|
||||
if (png_ptr->mode & PNG_AFTER_IDAT)
|
||||
png_error(png_ptr, "Too many IDAT's found");
|
||||
png_benign_error(png_ptr, "Too many IDATs found");
|
||||
}
|
||||
|
||||
#if defined(PNG_READ_APNG_SUPPORTED)
|
||||
png_have_info(png_ptr, info_ptr);
|
||||
#endif
|
||||
@ -439,7 +438,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
|
||||
return;
|
||||
}
|
||||
|
||||
#if defined(PNG_READ_gAMA_SUPPORTED)
|
||||
#ifdef PNG_READ_gAMA_SUPPORTED
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
@ -452,7 +451,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
|
||||
}
|
||||
|
||||
#endif
|
||||
#if defined(PNG_READ_sBIT_SUPPORTED)
|
||||
#ifdef PNG_READ_sBIT_SUPPORTED
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
@ -465,7 +464,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
|
||||
}
|
||||
|
||||
#endif
|
||||
#if defined(PNG_READ_cHRM_SUPPORTED)
|
||||
#ifdef PNG_READ_cHRM_SUPPORTED
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
@ -478,7 +477,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
|
||||
}
|
||||
|
||||
#endif
|
||||
#if defined(PNG_READ_sRGB_SUPPORTED)
|
||||
#ifdef PNG_READ_sRGB_SUPPORTED
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
@ -491,7 +490,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
|
||||
}
|
||||
|
||||
#endif
|
||||
#if defined(PNG_READ_iCCP_SUPPORTED)
|
||||
#ifdef PNG_READ_iCCP_SUPPORTED
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
@ -504,7 +503,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
|
||||
}
|
||||
|
||||
#endif
|
||||
#if defined(PNG_READ_sPLT_SUPPORTED)
|
||||
#ifdef PNG_READ_sPLT_SUPPORTED
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
@ -517,7 +516,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
|
||||
}
|
||||
|
||||
#endif
|
||||
#if defined(PNG_READ_tRNS_SUPPORTED)
|
||||
#ifdef PNG_READ_tRNS_SUPPORTED
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
@ -530,7 +529,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
|
||||
}
|
||||
|
||||
#endif
|
||||
#if defined(PNG_READ_bKGD_SUPPORTED)
|
||||
#ifdef PNG_READ_bKGD_SUPPORTED
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
@ -543,7 +542,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
|
||||
}
|
||||
|
||||
#endif
|
||||
#if defined(PNG_READ_hIST_SUPPORTED)
|
||||
#ifdef PNG_READ_hIST_SUPPORTED
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
@ -556,7 +555,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
|
||||
}
|
||||
|
||||
#endif
|
||||
#if defined(PNG_READ_pHYs_SUPPORTED)
|
||||
#ifdef PNG_READ_pHYs_SUPPORTED
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
@ -569,7 +568,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
|
||||
}
|
||||
|
||||
#endif
|
||||
#if defined(PNG_READ_oFFs_SUPPORTED)
|
||||
#ifdef PNG_READ_oFFs_SUPPORTED
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
@ -582,7 +581,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_pCAL_SUPPORTED)
|
||||
#ifdef PNG_READ_pCAL_SUPPORTED
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
@ -595,7 +594,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
|
||||
}
|
||||
|
||||
#endif
|
||||
#if defined(PNG_READ_sCAL_SUPPORTED)
|
||||
#ifdef PNG_READ_sCAL_SUPPORTED
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
@ -608,7 +607,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
|
||||
}
|
||||
|
||||
#endif
|
||||
#if defined(PNG_READ_tIME_SUPPORTED)
|
||||
#ifdef PNG_READ_tIME_SUPPORTED
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
@ -621,7 +620,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
|
||||
}
|
||||
|
||||
#endif
|
||||
#if defined(PNG_READ_tEXt_SUPPORTED)
|
||||
#ifdef 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)
|
||||
@ -634,7 +633,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
|
||||
}
|
||||
|
||||
#endif
|
||||
#if defined(PNG_READ_zTXt_SUPPORTED)
|
||||
#ifdef 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)
|
||||
@ -647,7 +646,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
|
||||
}
|
||||
|
||||
#endif
|
||||
#if defined(PNG_READ_iTXt_SUPPORTED)
|
||||
#ifdef 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)
|
||||
@ -833,7 +832,7 @@ png_push_save_buffer(png_structp png_ptr)
|
||||
new_max = png_ptr->save_buffer_size + png_ptr->current_buffer_size + 256;
|
||||
old_buffer = png_ptr->save_buffer;
|
||||
png_ptr->save_buffer = (png_bytep)png_malloc(png_ptr,
|
||||
(png_uint_32)new_max);
|
||||
(png_size_t)new_max);
|
||||
png_memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size);
|
||||
png_free(png_ptr, old_buffer);
|
||||
png_ptr->save_buffer_max = new_max;
|
||||
@ -862,12 +861,10 @@ png_push_restore_buffer(png_structp png_ptr, png_bytep buffer,
|
||||
void /* PRIVATE */
|
||||
png_push_read_IDAT(png_structp png_ptr)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
PNG_IDAT;
|
||||
#if defined(PNG_READ_APNG_SUPPORTED)
|
||||
PNG_fdAT;
|
||||
PNG_IEND;
|
||||
#endif
|
||||
#endif
|
||||
if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
|
||||
{
|
||||
@ -1012,7 +1009,7 @@ png_process_IDAT_data(png_structp png_ptr, png_bytep buffer,
|
||||
int ret;
|
||||
|
||||
if ((png_ptr->flags & PNG_FLAG_ZLIB_FINISHED) && buffer_length)
|
||||
png_error(png_ptr, "Extra compression data");
|
||||
png_benign_error(png_ptr, "Extra compression data");
|
||||
|
||||
png_ptr->zstream.next_in = buffer;
|
||||
png_ptr->zstream.avail_in = (uInt)buffer_length;
|
||||
@ -1024,7 +1021,7 @@ png_process_IDAT_data(png_structp png_ptr, png_bytep buffer,
|
||||
if (ret == Z_STREAM_END)
|
||||
{
|
||||
if (png_ptr->zstream.avail_in)
|
||||
png_error(png_ptr, "Extra compressed data");
|
||||
png_benign_error(png_ptr, "Extra compressed data");
|
||||
|
||||
if (!(png_ptr->zstream.avail_out))
|
||||
{
|
||||
@ -1044,7 +1041,7 @@ png_process_IDAT_data(png_structp png_ptr, png_bytep buffer,
|
||||
if (!(png_ptr->zstream.avail_out))
|
||||
{
|
||||
if ((
|
||||
#if defined(PNG_READ_INTERLACING_SUPPORTED)
|
||||
#ifdef PNG_READ_INTERLACING_SUPPORTED
|
||||
png_ptr->interlaced && png_ptr->pass > 6) ||
|
||||
(!png_ptr->interlaced &&
|
||||
#endif
|
||||
@ -1081,13 +1078,12 @@ png_push_process_row(png_structp png_ptr)
|
||||
png_ptr->row_buf + 1, png_ptr->prev_row + 1,
|
||||
(int)(png_ptr->row_buf[0]));
|
||||
|
||||
png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
|
||||
png_ptr->rowbytes + 1);
|
||||
png_memcpy(png_ptr->prev_row, png_ptr->row_buf, png_ptr->rowbytes + 1);
|
||||
|
||||
if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
|
||||
png_do_read_transformations(png_ptr);
|
||||
|
||||
#if defined(PNG_READ_INTERLACING_SUPPORTED)
|
||||
#ifdef PNG_READ_INTERLACING_SUPPORTED
|
||||
/* Blow up interlaced rows to full size */
|
||||
if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
|
||||
{
|
||||
@ -1113,7 +1109,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, png_bytep_NULL);
|
||||
png_push_have_row(png_ptr, NULL);
|
||||
png_read_push_finish_row(png_ptr);
|
||||
}
|
||||
}
|
||||
@ -1122,14 +1118,14 @@ png_push_process_row(png_structp png_ptr)
|
||||
{
|
||||
for (i = 0; i < 2 && png_ptr->pass == 4; i++)
|
||||
{
|
||||
png_push_have_row(png_ptr, png_bytep_NULL);
|
||||
png_push_have_row(png_ptr, NULL);
|
||||
png_read_push_finish_row(png_ptr);
|
||||
}
|
||||
}
|
||||
|
||||
if (png_ptr->pass == 6 && png_ptr->height <= 4)
|
||||
{
|
||||
png_push_have_row(png_ptr, png_bytep_NULL);
|
||||
png_push_have_row(png_ptr, NULL);
|
||||
png_read_push_finish_row(png_ptr);
|
||||
}
|
||||
|
||||
@ -1149,7 +1145,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, png_bytep_NULL);
|
||||
png_push_have_row(png_ptr, NULL);
|
||||
png_read_push_finish_row(png_ptr);
|
||||
}
|
||||
}
|
||||
@ -1169,7 +1165,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, png_bytep_NULL);
|
||||
png_push_have_row(png_ptr, NULL);
|
||||
png_read_push_finish_row(png_ptr);
|
||||
}
|
||||
|
||||
@ -1177,7 +1173,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, png_bytep_NULL);
|
||||
png_push_have_row(png_ptr, NULL);
|
||||
png_read_push_finish_row(png_ptr);
|
||||
}
|
||||
}
|
||||
@ -1199,7 +1195,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, png_bytep_NULL);
|
||||
png_push_have_row(png_ptr, NULL);
|
||||
png_read_push_finish_row(png_ptr);
|
||||
}
|
||||
}
|
||||
@ -1219,13 +1215,13 @@ png_push_process_row(png_structp png_ptr)
|
||||
|
||||
for (i = 0; i < 2 && png_ptr->pass == 4; i++)
|
||||
{
|
||||
png_push_have_row(png_ptr, png_bytep_NULL);
|
||||
png_push_have_row(png_ptr, NULL);
|
||||
png_read_push_finish_row(png_ptr);
|
||||
}
|
||||
|
||||
if (png_ptr->pass == 6) /* Pass 5 might be empty */
|
||||
{
|
||||
png_push_have_row(png_ptr, png_bytep_NULL);
|
||||
png_push_have_row(png_ptr, NULL);
|
||||
png_read_push_finish_row(png_ptr);
|
||||
}
|
||||
|
||||
@ -1244,7 +1240,7 @@ png_push_process_row(png_structp png_ptr)
|
||||
|
||||
if (png_ptr->pass == 6) /* Skip top generated row */
|
||||
{
|
||||
png_push_have_row(png_ptr, png_bytep_NULL);
|
||||
png_push_have_row(png_ptr, NULL);
|
||||
png_read_push_finish_row(png_ptr);
|
||||
}
|
||||
|
||||
@ -1258,7 +1254,7 @@ png_push_process_row(png_structp png_ptr)
|
||||
if (png_ptr->pass != 6)
|
||||
break;
|
||||
|
||||
png_push_have_row(png_ptr, png_bytep_NULL);
|
||||
png_push_have_row(png_ptr, NULL);
|
||||
png_read_push_finish_row(png_ptr);
|
||||
}
|
||||
}
|
||||
@ -1274,7 +1270,6 @@ png_push_process_row(png_structp png_ptr)
|
||||
void /* PRIVATE */
|
||||
png_read_push_finish_row(png_structp png_ptr)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
/* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
|
||||
|
||||
/* Start of interlace block */
|
||||
@ -1293,17 +1288,16 @@ png_read_push_finish_row(png_structp png_ptr)
|
||||
* it, uncomment it here and in png.h
|
||||
PNG_CONST int FARDATA png_pass_height[] = {8, 8, 4, 4, 2, 2, 1};
|
||||
*/
|
||||
#endif
|
||||
|
||||
png_ptr->row_number++;
|
||||
if (png_ptr->row_number < png_ptr->num_rows)
|
||||
return;
|
||||
|
||||
#if defined(PNG_READ_INTERLACING_SUPPORTED)
|
||||
#ifdef PNG_READ_INTERLACING_SUPPORTED
|
||||
if (png_ptr->interlaced)
|
||||
{
|
||||
png_ptr->row_number = 0;
|
||||
png_memset_check(png_ptr, png_ptr->prev_row, 0,
|
||||
png_memset(png_ptr->prev_row, 0,
|
||||
png_ptr->rowbytes + 1);
|
||||
do
|
||||
{
|
||||
@ -1340,7 +1334,7 @@ png_read_push_finish_row(png_structp png_ptr)
|
||||
#endif /* PNG_READ_INTERLACING_SUPPORTED */
|
||||
}
|
||||
|
||||
#if defined(PNG_READ_tEXt_SUPPORTED)
|
||||
#ifdef PNG_READ_tEXt_SUPPORTED
|
||||
void /* PRIVATE */
|
||||
png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
|
||||
length)
|
||||
@ -1363,7 +1357,7 @@ png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
|
||||
#endif
|
||||
|
||||
png_ptr->current_text = (png_charp)png_malloc(png_ptr,
|
||||
(png_uint_32)(length + 1));
|
||||
(png_size_t)(length + 1));
|
||||
png_ptr->current_text[length] = '\0';
|
||||
png_ptr->current_text_ptr = png_ptr->current_text;
|
||||
png_ptr->current_text_size = (png_size_t)length;
|
||||
@ -1403,7 +1397,7 @@ png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr)
|
||||
|
||||
png_push_crc_finish(png_ptr);
|
||||
|
||||
#if defined(PNG_MAX_MALLOC_64K)
|
||||
#ifdef PNG_MAX_MALLOC_64K
|
||||
if (png_ptr->skip_length)
|
||||
return;
|
||||
#endif
|
||||
@ -1417,7 +1411,7 @@ png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr)
|
||||
text++;
|
||||
|
||||
text_ptr = (png_textp)png_malloc(png_ptr,
|
||||
(png_uint_32)png_sizeof(png_text));
|
||||
png_sizeof(png_text));
|
||||
text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
|
||||
text_ptr->key = key;
|
||||
#ifdef PNG_iTXt_SUPPORTED
|
||||
@ -1433,12 +1427,12 @@ png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr)
|
||||
png_ptr->current_text = NULL;
|
||||
|
||||
if (ret)
|
||||
png_warning(png_ptr, "Insufficient memory to store text chunk.");
|
||||
png_warning(png_ptr, "Insufficient memory to store text chunk");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_zTXt_SUPPORTED)
|
||||
#ifdef PNG_READ_zTXt_SUPPORTED
|
||||
void /* PRIVATE */
|
||||
png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
|
||||
length)
|
||||
@ -1463,7 +1457,7 @@ png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
|
||||
#endif
|
||||
|
||||
png_ptr->current_text = (png_charp)png_malloc(png_ptr,
|
||||
(png_uint_32)(length + 1));
|
||||
(png_size_t)(length + 1));
|
||||
png_ptr->current_text[length] = '\0';
|
||||
png_ptr->current_text_ptr = png_ptr->current_text;
|
||||
png_ptr->current_text_size = (png_size_t)length;
|
||||
@ -1556,7 +1550,7 @@ 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->zbuf_size
|
||||
- png_ptr->zstream.avail_out + key_size + 1));
|
||||
|
||||
png_memcpy(text + key_size, png_ptr->zbuf,
|
||||
@ -1575,7 +1569,7 @@ png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
|
||||
|
||||
tmp = text;
|
||||
text = (png_charp)png_malloc(png_ptr, text_size +
|
||||
(png_uint_32)(png_ptr->zbuf_size
|
||||
(png_ptr->zbuf_size
|
||||
- png_ptr->zstream.avail_out + 1));
|
||||
|
||||
png_memcpy(text, tmp, text_size);
|
||||
@ -1619,7 +1613,7 @@ png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
|
||||
text += key_size;
|
||||
|
||||
text_ptr = (png_textp)png_malloc(png_ptr,
|
||||
(png_uint_32)png_sizeof(png_text));
|
||||
png_sizeof(png_text));
|
||||
text_ptr->compression = PNG_TEXT_COMPRESSION_zTXt;
|
||||
text_ptr->key = key;
|
||||
#ifdef PNG_iTXt_SUPPORTED
|
||||
@ -1634,12 +1628,12 @@ png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
|
||||
png_free(png_ptr, text_ptr);
|
||||
|
||||
if (ret)
|
||||
png_warning(png_ptr, "Insufficient memory to store text chunk.");
|
||||
png_warning(png_ptr, "Insufficient memory to store text chunk");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_iTXt_SUPPORTED)
|
||||
#ifdef PNG_READ_iTXt_SUPPORTED
|
||||
void /* PRIVATE */
|
||||
png_push_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
|
||||
length)
|
||||
@ -1662,7 +1656,7 @@ png_push_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
|
||||
#endif
|
||||
|
||||
png_ptr->current_text = (png_charp)png_malloc(png_ptr,
|
||||
(png_uint_32)(length + 1));
|
||||
(png_size_t)(length + 1));
|
||||
png_ptr->current_text[length] = '\0';
|
||||
png_ptr->current_text_ptr = png_ptr->current_text;
|
||||
png_ptr->current_text_size = (png_size_t)length;
|
||||
@ -1706,7 +1700,7 @@ png_push_read_iTXt(png_structp png_ptr, png_infop info_ptr)
|
||||
|
||||
png_push_crc_finish(png_ptr);
|
||||
|
||||
#if defined(PNG_MAX_MALLOC_64K)
|
||||
#ifdef PNG_MAX_MALLOC_64K
|
||||
if (png_ptr->skip_length)
|
||||
return;
|
||||
#endif
|
||||
@ -1739,7 +1733,7 @@ png_push_read_iTXt(png_structp png_ptr, png_infop info_ptr)
|
||||
text++;
|
||||
|
||||
text_ptr = (png_textp)png_malloc(png_ptr,
|
||||
(png_uint_32)png_sizeof(png_text));
|
||||
png_sizeof(png_text));
|
||||
|
||||
text_ptr->compression = comp_flag + 2;
|
||||
text_ptr->key = key;
|
||||
@ -1755,7 +1749,7 @@ png_push_read_iTXt(png_structp png_ptr, png_infop info_ptr)
|
||||
|
||||
png_free(png_ptr, text_ptr);
|
||||
if (ret)
|
||||
png_warning(png_ptr, "Insufficient memory to store iTXt chunk.");
|
||||
png_warning(png_ptr, "Insufficient memory to store iTXt chunk");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -1772,10 +1766,10 @@ png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32
|
||||
|
||||
if (!(png_ptr->chunk_name[0] & 0x20))
|
||||
{
|
||||
#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
|
||||
#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
|
||||
if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
|
||||
PNG_HANDLE_CHUNK_ALWAYS
|
||||
#if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
|
||||
#ifdef PNG_READ_USER_CHUNKS_SUPPORTED
|
||||
&& png_ptr->read_user_chunk_fn == NULL
|
||||
#endif
|
||||
)
|
||||
@ -1785,7 +1779,7 @@ png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32
|
||||
info_ptr = info_ptr; /* To quiet some compiler warnings */
|
||||
}
|
||||
|
||||
#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
|
||||
#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
|
||||
if (png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS)
|
||||
{
|
||||
#ifdef PNG_MAX_MALLOC_64K
|
||||
@ -1810,11 +1804,11 @@ png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32
|
||||
else
|
||||
{
|
||||
png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr,
|
||||
(png_uint_32)length);
|
||||
(png_size_t)length);
|
||||
png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
|
||||
}
|
||||
|
||||
#if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
|
||||
#ifdef PNG_READ_USER_CHUNKS_SUPPORTED
|
||||
if (png_ptr->read_user_chunk_fn != NULL)
|
||||
{
|
||||
/* Callback to user unknown chunk handler */
|
||||
@ -1875,10 +1869,9 @@ void PNGAPI
|
||||
png_progressive_combine_row (png_structp png_ptr,
|
||||
png_bytep old_row, png_bytep new_row)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
PNG_CONST int FARDATA png_pass_dsp_mask[7] =
|
||||
{0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
|
||||
#endif
|
||||
|
||||
if (png_ptr == NULL)
|
||||
return;
|
||||
|
||||
|
1001
modules/libimg/png/pngpriv.h
Normal file
1001
modules/libimg/png/pngpriv.h
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,8 +1,8 @@
|
||||
|
||||
/* pngrio.c - functions for data input
|
||||
*
|
||||
* Last changed in libpng 1.2.37 [June 4, 2009]
|
||||
* Copyright (c) 1998-2009 Glenn Randers-Pehrson
|
||||
* Last changed in libpng 1.4.0 [January 3, 2010]
|
||||
* Copyright (c) 1998-2010 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,9 +18,10 @@
|
||||
* libpng use it at run time with png_set_read_fn(...).
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
#define PNG_NO_PEDANTIC_WARNINGS
|
||||
#include "png.h"
|
||||
#if defined(PNG_READ_SUPPORTED)
|
||||
#ifdef PNG_READ_SUPPORTED
|
||||
#include "pngpriv.h"
|
||||
|
||||
/* Read the data from whatever input you are using. The default routine
|
||||
* reads from a file pointer. Note that this routine sometimes gets called
|
||||
@ -32,13 +33,14 @@ void /* PRIVATE */
|
||||
png_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
{
|
||||
png_debug1(4, "reading %d bytes", (int)length);
|
||||
|
||||
if (png_ptr->read_data_fn != NULL)
|
||||
(*(png_ptr->read_data_fn))(png_ptr, data, length);
|
||||
else
|
||||
png_error(png_ptr, "Call to NULL read function");
|
||||
}
|
||||
|
||||
#if !defined(PNG_NO_STDIO)
|
||||
#ifdef PNG_STDIO_SUPPORTED
|
||||
/* This is the function that does the actual reading of data. If you are
|
||||
* not reading from a standard C stream, you should create a replacement
|
||||
* read_data function and use it at run time with png_set_read_fn(), rather
|
||||
@ -55,13 +57,7 @@ png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
/* fread() returns 0 on error, so it is OK to store this in a png_size_t
|
||||
* instead of an int, which is what fread() actually returns.
|
||||
*/
|
||||
#if defined(_WIN32_WCE)
|
||||
if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
|
||||
check = 0;
|
||||
#else
|
||||
check = (png_size_t)fread(data, (png_size_t)1, length,
|
||||
(png_FILE_p)png_ptr->io_ptr);
|
||||
#endif
|
||||
check = fread(data, 1, length, (png_FILE_p)png_ptr->io_ptr);
|
||||
|
||||
if (check != length)
|
||||
png_error(png_ptr, "Read Error");
|
||||
@ -78,7 +74,7 @@ png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
static void PNGAPI
|
||||
png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
{
|
||||
int check;
|
||||
png_size_t check;
|
||||
png_byte *n_data;
|
||||
png_FILE_p io_ptr;
|
||||
|
||||
@ -89,12 +85,7 @@ png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
|
||||
if ((png_bytep)n_data == data)
|
||||
{
|
||||
#if defined(_WIN32_WCE)
|
||||
if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
|
||||
check = 0;
|
||||
#else
|
||||
check = fread(n_data, 1, length, io_ptr);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -105,12 +96,7 @@ png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
do
|
||||
{
|
||||
read = MIN(NEAR_BUF_SIZE, remaining);
|
||||
#if defined(_WIN32_WCE)
|
||||
if ( !ReadFile((HANDLE)(io_ptr), buf, read, &err, NULL) )
|
||||
err = 0;
|
||||
#else
|
||||
err = fread(buf, (png_size_t)1, read, io_ptr);
|
||||
#endif
|
||||
err = fread(buf, 1, read, io_ptr);
|
||||
png_memcpy(data, buf, read); /* copy far buffer to near buffer */
|
||||
if (err != read)
|
||||
break;
|
||||
@ -151,7 +137,7 @@ png_set_read_fn(png_structp png_ptr, png_voidp io_ptr,
|
||||
return;
|
||||
png_ptr->io_ptr = io_ptr;
|
||||
|
||||
#if !defined(PNG_NO_STDIO)
|
||||
#ifdef PNG_STDIO_SUPPORTED
|
||||
if (read_data_fn != NULL)
|
||||
png_ptr->read_data_fn = read_data_fn;
|
||||
else
|
||||
@ -167,10 +153,10 @@ png_set_read_fn(png_structp png_ptr, png_voidp io_ptr,
|
||||
png_warning(png_ptr,
|
||||
"It's an error to set both read_data_fn and write_data_fn in the ");
|
||||
png_warning(png_ptr,
|
||||
"same structure. Resetting write_data_fn to NULL.");
|
||||
"same structure. Resetting write_data_fn to NULL");
|
||||
}
|
||||
|
||||
#if defined(PNG_WRITE_FLUSH_SUPPORTED)
|
||||
#ifdef PNG_WRITE_FLUSH_SUPPORTED
|
||||
png_ptr->output_flush_fn = NULL;
|
||||
#endif
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,8 +1,8 @@
|
||||
|
||||
/* pngset.c - storage of image information into info struct
|
||||
*
|
||||
* Last changed in libpng 1.2.40 [September 10, 2009]
|
||||
* Copyright (c) 1998-2009 Glenn Randers-Pehrson
|
||||
* Last changed in libpng 1.4.0 [January 3, 2010]
|
||||
* Copyright (c) 1998-2010 Glenn Randers-Pehrson
|
||||
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
|
||||
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
|
||||
*
|
||||
@ -16,11 +16,12 @@
|
||||
* info struct and allows us to change the structure in the future.
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
#define PNG_NO_PEDANTIC_WARNINGS
|
||||
#include "png.h"
|
||||
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
|
||||
#include "pngpriv.h"
|
||||
|
||||
#if defined(PNG_bKGD_SUPPORTED)
|
||||
#ifdef PNG_bKGD_SUPPORTED
|
||||
void PNGAPI
|
||||
png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background)
|
||||
{
|
||||
@ -34,7 +35,7 @@ png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_cHRM_SUPPORTED)
|
||||
#ifdef PNG_cHRM_SUPPORTED
|
||||
#ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
void PNGAPI
|
||||
png_set_cHRM(png_structp png_ptr, png_infop info_ptr,
|
||||
@ -80,7 +81,7 @@ png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
|
||||
if (png_ptr == NULL || info_ptr == NULL)
|
||||
return;
|
||||
|
||||
#if !defined(PNG_NO_CHECK_cHRM)
|
||||
#ifdef PNG_CHECK_cHRM_SUPPORTED
|
||||
if (png_check_cHRM_fixed(png_ptr,
|
||||
white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y))
|
||||
#endif
|
||||
@ -109,7 +110,7 @@ png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
|
||||
#endif /* PNG_FIXED_POINT_SUPPORTED */
|
||||
#endif /* PNG_cHRM_SUPPORTED */
|
||||
|
||||
#if defined(PNG_gAMA_SUPPORTED)
|
||||
#ifdef PNG_gAMA_SUPPORTED
|
||||
#ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
void PNGAPI
|
||||
png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma)
|
||||
@ -176,7 +177,7 @@ png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_hIST_SUPPORTED)
|
||||
#ifdef PNG_hIST_SUPPORTED
|
||||
void PNGAPI
|
||||
png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist)
|
||||
{
|
||||
@ -191,21 +192,19 @@ png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist)
|
||||
> PNG_MAX_PALETTE_LENGTH)
|
||||
{
|
||||
png_warning(png_ptr,
|
||||
"Invalid palette size, hIST allocation skipped.");
|
||||
"Invalid palette size, hIST allocation skipped");
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef PNG_FREE_ME_SUPPORTED
|
||||
png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0);
|
||||
#endif
|
||||
/* Changed from info->num_palette to PNG_MAX_PALETTE_LENGTH in
|
||||
* version 1.2.1
|
||||
*/
|
||||
png_ptr->hist = (png_uint_16p)png_malloc_warn(png_ptr,
|
||||
(png_uint_32)(PNG_MAX_PALETTE_LENGTH * png_sizeof(png_uint_16)));
|
||||
PNG_MAX_PALETTE_LENGTH * png_sizeof(png_uint_16));
|
||||
if (png_ptr->hist == NULL)
|
||||
{
|
||||
png_warning(png_ptr, "Insufficient memory for hIST chunk data.");
|
||||
png_warning(png_ptr, "Insufficient memory for hIST chunk data");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -214,11 +213,7 @@ png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist)
|
||||
info_ptr->hist = png_ptr->hist;
|
||||
info_ptr->valid |= PNG_INFO_hIST;
|
||||
|
||||
#ifdef PNG_FREE_ME_SUPPORTED
|
||||
info_ptr->free_me |= PNG_FREE_HIST;
|
||||
#else
|
||||
png_ptr->flags |= PNG_FLAG_FREE_HIST;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -233,82 +228,18 @@ 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");
|
||||
#ifdef PNG_SET_USER_LIMITS_SUPPORTED
|
||||
if (width > png_ptr->user_width_max || height > png_ptr->user_height_max)
|
||||
png_error(png_ptr, "image size exceeds user limits in IHDR");
|
||||
#else
|
||||
if (width > PNG_USER_WIDTH_MAX || height > PNG_USER_HEIGHT_MAX)
|
||||
png_error(png_ptr, "image size exceeds user limits in IHDR");
|
||||
#endif
|
||||
if (width > PNG_UINT_31_MAX || height > PNG_UINT_31_MAX)
|
||||
png_error(png_ptr, "Invalid image size in IHDR");
|
||||
if ( width > (PNG_UINT_32_MAX
|
||||
>> 3) /* 8-byte RGBA pixels */
|
||||
- 64 /* bigrowbuf hack */
|
||||
- 1 /* filter byte */
|
||||
- 7*8 /* rounding of width to multiple of 8 pixels */
|
||||
- 8) /* extra max_pixel_depth pad */
|
||||
png_warning(png_ptr, "Width is too large for libpng to process pixels");
|
||||
|
||||
/* 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");
|
||||
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;
|
||||
info_ptr->color_type =(png_byte) color_type;
|
||||
info_ptr->color_type = (png_byte)color_type;
|
||||
info_ptr->compression_type = (png_byte)compression_type;
|
||||
info_ptr->filter_type = (png_byte)filter_type;
|
||||
info_ptr->interlace_type = (png_byte)interlace_type;
|
||||
|
||||
png_check_IHDR (png_ptr, info_ptr->width, info_ptr->height,
|
||||
info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type,
|
||||
info_ptr->compression_type, info_ptr->filter_type);
|
||||
|
||||
if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
|
||||
info_ptr->channels = 1;
|
||||
else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
|
||||
@ -326,17 +257,17 @@ png_set_IHDR(png_structp png_ptr, png_infop info_ptr,
|
||||
- 1 /* filter byte */
|
||||
- 7*8 /* rounding of width to multiple of 8 pixels */
|
||||
- 8) /* extra max_pixel_depth pad */
|
||||
info_ptr->rowbytes = (png_size_t)0;
|
||||
info_ptr->rowbytes = 0;
|
||||
else
|
||||
info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, width);
|
||||
|
||||
#if defined(PNG_APNG_SUPPORTED)
|
||||
/* for non-animated png. this may be overritten from an acTL chunk later */
|
||||
/* for non-animated png. this may be overwritten from an acTL chunk later */
|
||||
info_ptr->num_frames = 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(PNG_oFFs_SUPPORTED)
|
||||
#ifdef PNG_oFFs_SUPPORTED
|
||||
void PNGAPI
|
||||
png_set_oFFs(png_structp png_ptr, png_infop info_ptr,
|
||||
png_int_32 offset_x, png_int_32 offset_y, int unit_type)
|
||||
@ -353,13 +284,13 @@ png_set_oFFs(png_structp png_ptr, png_infop info_ptr,
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_pCAL_SUPPORTED)
|
||||
#ifdef PNG_pCAL_SUPPORTED
|
||||
void PNGAPI
|
||||
png_set_pCAL(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)
|
||||
{
|
||||
png_uint_32 length;
|
||||
png_size_t length;
|
||||
int i;
|
||||
|
||||
png_debug1(1, "in %s storage function", "pCAL");
|
||||
@ -373,10 +304,10 @@ png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
|
||||
info_ptr->pcal_purpose = (png_charp)png_malloc_warn(png_ptr, length);
|
||||
if (info_ptr->pcal_purpose == NULL)
|
||||
{
|
||||
png_warning(png_ptr, "Insufficient memory for pCAL purpose.");
|
||||
png_warning(png_ptr, "Insufficient memory for pCAL purpose");
|
||||
return;
|
||||
}
|
||||
png_memcpy(info_ptr->pcal_purpose, purpose, (png_size_t)length);
|
||||
png_memcpy(info_ptr->pcal_purpose, purpose, length);
|
||||
|
||||
png_debug(3, "storing X0, X1, type, and nparams in info");
|
||||
info_ptr->pcal_X0 = X0;
|
||||
@ -390,16 +321,16 @@ png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
|
||||
info_ptr->pcal_units = (png_charp)png_malloc_warn(png_ptr, length);
|
||||
if (info_ptr->pcal_units == NULL)
|
||||
{
|
||||
png_warning(png_ptr, "Insufficient memory for pCAL units.");
|
||||
png_warning(png_ptr, "Insufficient memory for pCAL units");
|
||||
return;
|
||||
}
|
||||
png_memcpy(info_ptr->pcal_units, units, (png_size_t)length);
|
||||
png_memcpy(info_ptr->pcal_units, units, length);
|
||||
|
||||
info_ptr->pcal_params = (png_charpp)png_malloc_warn(png_ptr,
|
||||
(png_uint_32)((nparams + 1) * png_sizeof(png_charp)));
|
||||
(png_size_t)((nparams + 1) * png_sizeof(png_charp)));
|
||||
if (info_ptr->pcal_params == NULL)
|
||||
{
|
||||
png_warning(png_ptr, "Insufficient memory for pCAL params.");
|
||||
png_warning(png_ptr, "Insufficient memory for pCAL params");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -413,16 +344,14 @@ png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
|
||||
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.");
|
||||
png_warning(png_ptr, "Insufficient memory for pCAL parameter");
|
||||
return;
|
||||
}
|
||||
png_memcpy(info_ptr->pcal_params[i], params[i], (png_size_t)length);
|
||||
png_memcpy(info_ptr->pcal_params[i], params[i], length);
|
||||
}
|
||||
|
||||
info_ptr->valid |= PNG_INFO_pCAL;
|
||||
#ifdef PNG_FREE_ME_SUPPORTED
|
||||
info_ptr->free_me |= PNG_FREE_PCAL;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -449,7 +378,7 @@ void PNGAPI
|
||||
png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr,
|
||||
int unit, png_charp swidth, png_charp sheight)
|
||||
{
|
||||
png_uint_32 length;
|
||||
png_size_t length;
|
||||
|
||||
png_debug1(1, "in %s storage function", "sCAL");
|
||||
|
||||
@ -465,10 +394,10 @@ png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr,
|
||||
if (info_ptr->scal_s_width == NULL)
|
||||
{
|
||||
png_warning(png_ptr,
|
||||
"Memory allocation failed while processing sCAL.");
|
||||
"Memory allocation failed while processing sCAL");
|
||||
return;
|
||||
}
|
||||
png_memcpy(info_ptr->scal_s_width, swidth, (png_size_t)length);
|
||||
png_memcpy(info_ptr->scal_s_width, swidth, length);
|
||||
|
||||
length = png_strlen(sheight) + 1;
|
||||
png_debug1(3, "allocating unit for info (%u bytes)",
|
||||
@ -479,20 +408,18 @@ png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr,
|
||||
png_free (png_ptr, info_ptr->scal_s_width);
|
||||
info_ptr->scal_s_width = NULL;
|
||||
png_warning(png_ptr,
|
||||
"Memory allocation failed while processing sCAL.");
|
||||
"Memory allocation failed while processing sCAL");
|
||||
return;
|
||||
}
|
||||
png_memcpy(info_ptr->scal_s_height, sheight, (png_size_t)length);
|
||||
png_memcpy(info_ptr->scal_s_height, sheight, length);
|
||||
info_ptr->valid |= PNG_INFO_sCAL;
|
||||
#ifdef PNG_FREE_ME_SUPPORTED
|
||||
info_ptr->free_me |= PNG_FREE_SCAL;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(PNG_pHYs_SUPPORTED)
|
||||
#ifdef PNG_pHYs_SUPPORTED
|
||||
void PNGAPI
|
||||
png_set_pHYs(png_structp png_ptr, png_infop info_ptr,
|
||||
png_uint_32 res_x, png_uint_32 res_y, int unit_type)
|
||||
@ -535,32 +462,24 @@ png_set_PLTE(png_structp png_ptr, png_infop info_ptr,
|
||||
* we do it for backward compatibility with the way the png_handle_tRNS
|
||||
* function used to do the allocation.
|
||||
*/
|
||||
#ifdef PNG_FREE_ME_SUPPORTED
|
||||
png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0);
|
||||
#endif
|
||||
|
||||
/* Changed in libpng-1.2.1 to allocate PNG_MAX_PALETTE_LENGTH instead
|
||||
* of num_palette entries, in case of an invalid PNG file that has
|
||||
* too-large sample values.
|
||||
*/
|
||||
png_ptr->palette = (png_colorp)png_malloc(png_ptr,
|
||||
png_ptr->palette = (png_colorp)png_calloc(png_ptr,
|
||||
PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color));
|
||||
png_memset(png_ptr->palette, 0, PNG_MAX_PALETTE_LENGTH *
|
||||
png_sizeof(png_color));
|
||||
png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof(png_color));
|
||||
info_ptr->palette = png_ptr->palette;
|
||||
info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;
|
||||
|
||||
#ifdef PNG_FREE_ME_SUPPORTED
|
||||
info_ptr->free_me |= PNG_FREE_PLTE;
|
||||
#else
|
||||
png_ptr->flags |= PNG_FLAG_FREE_PLTE;
|
||||
#endif
|
||||
|
||||
info_ptr->valid |= PNG_INFO_PLTE;
|
||||
}
|
||||
|
||||
#if defined(PNG_sBIT_SUPPORTED)
|
||||
#ifdef PNG_sBIT_SUPPORTED
|
||||
void PNGAPI
|
||||
png_set_sBIT(png_structp png_ptr, png_infop info_ptr,
|
||||
png_color_8p sig_bit)
|
||||
@ -575,7 +494,7 @@ png_set_sBIT(png_structp png_ptr, png_infop info_ptr,
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_sRGB_SUPPORTED)
|
||||
#ifdef PNG_sRGB_SUPPORTED
|
||||
void PNGAPI
|
||||
png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int intent)
|
||||
{
|
||||
@ -592,7 +511,7 @@ void PNGAPI
|
||||
png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
|
||||
int intent)
|
||||
{
|
||||
#if defined(PNG_gAMA_SUPPORTED)
|
||||
#ifdef PNG_gAMA_SUPPORTED
|
||||
#ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
float file_gamma;
|
||||
#endif
|
||||
@ -600,7 +519,7 @@ png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
|
||||
png_fixed_point int_file_gamma;
|
||||
#endif
|
||||
#endif
|
||||
#if defined(PNG_cHRM_SUPPORTED)
|
||||
#ifdef PNG_cHRM_SUPPORTED
|
||||
#ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
|
||||
#endif
|
||||
@ -614,7 +533,7 @@ png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
|
||||
|
||||
png_set_sRGB(png_ptr, info_ptr, intent);
|
||||
|
||||
#if defined(PNG_gAMA_SUPPORTED)
|
||||
#ifdef PNG_gAMA_SUPPORTED
|
||||
#ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
file_gamma = (float).45455;
|
||||
png_set_gAMA(png_ptr, info_ptr, file_gamma);
|
||||
@ -625,7 +544,7 @@ png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(PNG_cHRM_SUPPORTED)
|
||||
#ifdef PNG_cHRM_SUPPORTED
|
||||
int_white_x = 31270L;
|
||||
int_white_y = 32900L;
|
||||
int_red_x = 64000L;
|
||||
@ -646,28 +565,21 @@ png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
|
||||
blue_y = (float).06;
|
||||
#endif
|
||||
|
||||
#if !defined(PNG_NO_CHECK_cHRM)
|
||||
if (png_check_cHRM_fixed(png_ptr,
|
||||
int_white_x, int_white_y, int_red_x, int_red_y, int_green_x,
|
||||
int_green_y, int_blue_x, int_blue_y))
|
||||
#endif
|
||||
{
|
||||
#ifdef PNG_FIXED_POINT_SUPPORTED
|
||||
png_set_cHRM_fixed(png_ptr, info_ptr,
|
||||
int_white_x, int_white_y, int_red_x, int_red_y, int_green_x,
|
||||
int_green_y, int_blue_x, int_blue_y);
|
||||
png_set_cHRM_fixed(png_ptr, info_ptr,
|
||||
int_white_x, int_white_y, int_red_x, int_red_y, int_green_x,
|
||||
int_green_y, int_blue_x, int_blue_y);
|
||||
#endif
|
||||
#ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
png_set_cHRM(png_ptr, info_ptr,
|
||||
white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
|
||||
png_set_cHRM(png_ptr, info_ptr,
|
||||
white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
|
||||
#endif
|
||||
}
|
||||
#endif /* cHRM */
|
||||
}
|
||||
#endif /* sRGB */
|
||||
|
||||
|
||||
#if defined(PNG_iCCP_SUPPORTED)
|
||||
#ifdef PNG_iCCP_SUPPORTED
|
||||
void PNGAPI
|
||||
png_set_iCCP(png_structp png_ptr, png_infop info_ptr,
|
||||
png_charp name, int compression_type,
|
||||
@ -686,7 +598,7 @@ png_set_iCCP(png_structp png_ptr, png_infop info_ptr,
|
||||
new_iccp_name = (png_charp)png_malloc_warn(png_ptr, length);
|
||||
if (new_iccp_name == NULL)
|
||||
{
|
||||
png_warning(png_ptr, "Insufficient memory to process iCCP chunk.");
|
||||
png_warning(png_ptr, "Insufficient memory to process iCCP chunk");
|
||||
return;
|
||||
}
|
||||
png_memcpy(new_iccp_name, name, length);
|
||||
@ -695,7 +607,7 @@ png_set_iCCP(png_structp png_ptr, png_infop info_ptr,
|
||||
{
|
||||
png_free (png_ptr, new_iccp_name);
|
||||
png_warning(png_ptr,
|
||||
"Insufficient memory to process iCCP profile.");
|
||||
"Insufficient memory to process iCCP profile");
|
||||
return;
|
||||
}
|
||||
png_memcpy(new_iccp_profile, profile, (png_size_t)proflen);
|
||||
@ -708,14 +620,12 @@ png_set_iCCP(png_structp png_ptr, png_infop info_ptr,
|
||||
/* Compression is always zero but is here so the API and info structure
|
||||
* does not have to change if we introduce multiple compression types */
|
||||
info_ptr->iccp_compression = (png_byte)compression_type;
|
||||
#ifdef PNG_FREE_ME_SUPPORTED
|
||||
info_ptr->free_me |= PNG_FREE_ICCP;
|
||||
#endif
|
||||
info_ptr->valid |= PNG_INFO_iCCP;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_TEXT_SUPPORTED)
|
||||
#ifdef PNG_TEXT_SUPPORTED
|
||||
void PNGAPI
|
||||
png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
|
||||
int num_text)
|
||||
@ -753,7 +663,7 @@ png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
|
||||
info_ptr->max_text = info_ptr->num_text + num_text + 8;
|
||||
old_text = info_ptr->text;
|
||||
info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
|
||||
(png_uint_32)(info_ptr->max_text * png_sizeof(png_text)));
|
||||
(png_size_t)(info_ptr->max_text * png_sizeof(png_text)));
|
||||
if (info_ptr->text == NULL)
|
||||
{
|
||||
png_free(png_ptr, old_text);
|
||||
@ -768,12 +678,10 @@ png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
|
||||
info_ptr->max_text = num_text + 8;
|
||||
info_ptr->num_text = 0;
|
||||
info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
|
||||
(png_uint_32)(info_ptr->max_text * png_sizeof(png_text)));
|
||||
(png_size_t)(info_ptr->max_text * png_sizeof(png_text)));
|
||||
if (info_ptr->text == NULL)
|
||||
return(1);
|
||||
#ifdef PNG_FREE_ME_SUPPORTED
|
||||
info_ptr->free_me |= PNG_FREE_TEXT;
|
||||
#endif
|
||||
}
|
||||
png_debug1(3, "allocated %d entries for info_ptr->text",
|
||||
info_ptr->max_text);
|
||||
@ -794,10 +702,12 @@ png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
|
||||
lang_len = 0;
|
||||
lang_key_len = 0;
|
||||
}
|
||||
|
||||
else
|
||||
#ifdef PNG_iTXt_SUPPORTED
|
||||
{
|
||||
/* Set iTXt data */
|
||||
|
||||
if (text_ptr[i].lang != NULL)
|
||||
lang_len = png_strlen(text_ptr[i].lang);
|
||||
else
|
||||
@ -807,9 +717,9 @@ png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
|
||||
else
|
||||
lang_key_len = 0;
|
||||
}
|
||||
#else
|
||||
#else /* PNG_iTXt_SUPPORTED */
|
||||
{
|
||||
png_warning(png_ptr, "iTXt chunk not supported.");
|
||||
png_warning(png_ptr, "iTXt chunk not supported");
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
@ -824,6 +734,7 @@ png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
|
||||
#endif
|
||||
textp->compression = PNG_TEXT_COMPRESSION_NONE;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
text_length = png_strlen(text_ptr[i].text);
|
||||
@ -831,12 +742,12 @@ png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
|
||||
}
|
||||
|
||||
textp->key = (png_charp)png_malloc_warn(png_ptr,
|
||||
(png_uint_32)
|
||||
(png_size_t)
|
||||
(key_len + text_length + lang_len + lang_key_len + 4));
|
||||
if (textp->key == NULL)
|
||||
return(1);
|
||||
png_debug2(2, "Allocated %lu bytes at %x in png_set_text",
|
||||
(png_uint_32)
|
||||
(unsigned long)(png_uint_32)
|
||||
(key_len + lang_len + lang_key_len + text_length + 4),
|
||||
(int)textp->key);
|
||||
|
||||
@ -875,6 +786,7 @@ png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
|
||||
}
|
||||
else
|
||||
#endif
|
||||
|
||||
{
|
||||
textp->text_length = text_length;
|
||||
#ifdef PNG_iTXt_SUPPORTED
|
||||
@ -888,7 +800,7 @@ png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_tIME_SUPPORTED)
|
||||
#ifdef PNG_tIME_SUPPORTED
|
||||
void PNGAPI
|
||||
png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time)
|
||||
{
|
||||
@ -903,47 +815,44 @@ png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_tRNS_SUPPORTED)
|
||||
#ifdef PNG_tRNS_SUPPORTED
|
||||
void PNGAPI
|
||||
png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
|
||||
png_bytep trans, int num_trans, png_color_16p trans_values)
|
||||
png_bytep trans_alpha, int num_trans, png_color_16p trans_color)
|
||||
{
|
||||
png_debug1(1, "in %s storage function", "tRNS");
|
||||
|
||||
if (png_ptr == NULL || info_ptr == NULL)
|
||||
return;
|
||||
|
||||
if (trans != NULL)
|
||||
if (trans_alpha != NULL)
|
||||
{
|
||||
/*
|
||||
* It may not actually be necessary to set png_ptr->trans here;
|
||||
/* It may not actually be necessary to set png_ptr->trans_alpha 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
|
||||
|
||||
/* Changed from num_trans to PNG_MAX_PALETTE_LENGTH in version 1.2.1 */
|
||||
png_ptr->trans = info_ptr->trans = (png_bytep)png_malloc(png_ptr,
|
||||
(png_uint_32)PNG_MAX_PALETTE_LENGTH);
|
||||
png_ptr->trans_alpha = info_ptr->trans_alpha = (png_bytep)png_malloc(png_ptr,
|
||||
(png_size_t)PNG_MAX_PALETTE_LENGTH);
|
||||
if (num_trans > 0 && num_trans <= PNG_MAX_PALETTE_LENGTH)
|
||||
png_memcpy(info_ptr->trans, trans, (png_size_t)num_trans);
|
||||
png_memcpy(info_ptr->trans_alpha, trans_alpha, (png_size_t)num_trans);
|
||||
}
|
||||
|
||||
if (trans_values != NULL)
|
||||
if (trans_color != NULL)
|
||||
{
|
||||
int sample_max = (1 << info_ptr->bit_depth);
|
||||
if ((info_ptr->color_type == PNG_COLOR_TYPE_GRAY &&
|
||||
(int)trans_values->gray > sample_max) ||
|
||||
(int)trans_color->gray > sample_max) ||
|
||||
(info_ptr->color_type == PNG_COLOR_TYPE_RGB &&
|
||||
((int)trans_values->red > sample_max ||
|
||||
(int)trans_values->green > sample_max ||
|
||||
(int)trans_values->blue > sample_max)))
|
||||
((int)trans_color->red > sample_max ||
|
||||
(int)trans_color->green > sample_max ||
|
||||
(int)trans_color->blue > sample_max)))
|
||||
png_warning(png_ptr,
|
||||
"tRNS chunk has out-of-range samples for bit_depth");
|
||||
png_memcpy(&(info_ptr->trans_values), trans_values,
|
||||
png_memcpy(&(info_ptr->trans_color), trans_color,
|
||||
png_sizeof(png_color_16));
|
||||
if (num_trans == 0)
|
||||
num_trans = 1;
|
||||
@ -953,16 +862,12 @@ png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
|
||||
if (num_trans != 0)
|
||||
{
|
||||
info_ptr->valid |= PNG_INFO_tRNS;
|
||||
#ifdef PNG_FREE_ME_SUPPORTED
|
||||
info_ptr->free_me |= PNG_FREE_TRNS;
|
||||
#else
|
||||
png_ptr->flags |= PNG_FLAG_FREE_TRNS;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_sPLT_SUPPORTED)
|
||||
#ifdef PNG_sPLT_SUPPORTED
|
||||
void PNGAPI
|
||||
png_set_sPLT(png_structp png_ptr,
|
||||
png_infop info_ptr, png_sPLT_tp entries, int nentries)
|
||||
@ -982,10 +887,10 @@ png_set_sPLT(png_structp png_ptr,
|
||||
|
||||
np = (png_sPLT_tp)png_malloc_warn(png_ptr,
|
||||
(info_ptr->splt_palettes_num + nentries) *
|
||||
(png_uint_32)png_sizeof(png_sPLT_t));
|
||||
(png_size_t)png_sizeof(png_sPLT_t));
|
||||
if (np == NULL)
|
||||
{
|
||||
png_warning(png_ptr, "No memory for sPLT palettes.");
|
||||
png_warning(png_ptr, "No memory for sPLT palettes");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1001,7 +906,7 @@ png_set_sPLT(png_structp png_ptr,
|
||||
png_uint_32 length;
|
||||
|
||||
length = png_strlen(from->name) + 1;
|
||||
to->name = (png_charp)png_malloc_warn(png_ptr, length);
|
||||
to->name = (png_charp)png_malloc_warn(png_ptr, (png_size_t)length);
|
||||
if (to->name == NULL)
|
||||
{
|
||||
png_warning(png_ptr,
|
||||
@ -1010,7 +915,7 @@ png_set_sPLT(png_structp png_ptr,
|
||||
}
|
||||
png_memcpy(to->name, from->name, length);
|
||||
to->entries = (png_sPLT_entryp)png_malloc_warn(png_ptr,
|
||||
(png_uint_32)(from->nentries * png_sizeof(png_sPLT_entry)));
|
||||
(png_size_t)(from->nentries * png_sizeof(png_sPLT_entry)));
|
||||
if (to->entries == NULL)
|
||||
{
|
||||
png_warning(png_ptr,
|
||||
@ -1028,9 +933,7 @@ png_set_sPLT(png_structp png_ptr,
|
||||
info_ptr->splt_palettes = np;
|
||||
info_ptr->splt_palettes_num += nentries;
|
||||
info_ptr->valid |= PNG_INFO_sPLT;
|
||||
#ifdef PNG_FREE_ME_SUPPORTED
|
||||
info_ptr->free_me |= PNG_FREE_SPLT;
|
||||
#endif
|
||||
}
|
||||
#endif /* PNG_sPLT_SUPPORTED */
|
||||
|
||||
@ -1174,7 +1077,7 @@ png_set_first_frame_is_hidden(png_structp png_ptr, png_infop info_ptr,
|
||||
}
|
||||
#endif /* PNG_APNG_SUPPORTED */
|
||||
|
||||
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
|
||||
#ifdef 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)
|
||||
@ -1186,19 +1089,18 @@ png_set_unknown_chunks(png_structp png_ptr,
|
||||
return;
|
||||
|
||||
np = (png_unknown_chunkp)png_malloc_warn(png_ptr,
|
||||
(png_uint_32)((info_ptr->unknown_chunks_num + num_unknowns) *
|
||||
(png_size_t)((info_ptr->unknown_chunks_num + num_unknowns) *
|
||||
png_sizeof(png_unknown_chunk)));
|
||||
if (np == NULL)
|
||||
{
|
||||
png_warning(png_ptr,
|
||||
"Out of memory while processing unknown chunk.");
|
||||
"Out of memory while processing unknown chunk");
|
||||
return;
|
||||
}
|
||||
|
||||
png_memcpy(np, info_ptr->unknown_chunks,
|
||||
info_ptr->unknown_chunks_num * png_sizeof(png_unknown_chunk));
|
||||
png_free(png_ptr, info_ptr->unknown_chunks);
|
||||
info_ptr->unknown_chunks=NULL;
|
||||
|
||||
for (i = 0; i < num_unknowns; i++)
|
||||
{
|
||||
@ -1218,11 +1120,11 @@ png_set_unknown_chunks(png_structp png_ptr,
|
||||
else
|
||||
{
|
||||
to->data = (png_bytep)png_malloc_warn(png_ptr,
|
||||
(png_uint_32)from->size);
|
||||
(png_size_t)from->size);
|
||||
if (to->data == NULL)
|
||||
{
|
||||
png_warning(png_ptr,
|
||||
"Out of memory while processing unknown chunk.");
|
||||
"Out of memory while processing unknown chunk");
|
||||
to->size = 0;
|
||||
}
|
||||
else
|
||||
@ -1232,9 +1134,7 @@ png_set_unknown_chunks(png_structp png_ptr,
|
||||
|
||||
info_ptr->unknown_chunks = np;
|
||||
info_ptr->unknown_chunks_num += num_unknowns;
|
||||
#ifdef PNG_FREE_ME_SUPPORTED
|
||||
info_ptr->free_me |= PNG_FREE_UNKN;
|
||||
#endif
|
||||
}
|
||||
void PNGAPI
|
||||
png_set_unknown_chunk_location(png_structp png_ptr, png_infop info_ptr,
|
||||
@ -1246,27 +1146,8 @@ png_set_unknown_chunk_location(png_structp png_ptr, png_infop info_ptr,
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_1_0_X) || defined(PNG_1_2_X)
|
||||
#if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
|
||||
defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
|
||||
void PNGAPI
|
||||
png_permit_empty_plte (png_structp png_ptr, int empty_plte_permitted)
|
||||
{
|
||||
/* This function is deprecated in favor of png_permit_mng_features()
|
||||
and will be removed from libpng-1.3.0 */
|
||||
|
||||
png_debug(1, "in png_permit_empty_plte, DEPRECATED.");
|
||||
|
||||
if (png_ptr == NULL)
|
||||
return;
|
||||
png_ptr->mng_features_permitted = (png_byte)
|
||||
((png_ptr->mng_features_permitted & (~PNG_FLAG_MNG_EMPTY_PLTE)) |
|
||||
((empty_plte_permitted & PNG_FLAG_MNG_EMPTY_PLTE)));
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(PNG_MNG_FEATURES_SUPPORTED)
|
||||
#ifdef PNG_MNG_FEATURES_SUPPORTED
|
||||
png_uint_32 PNGAPI
|
||||
png_permit_mng_features (png_structp png_ptr, png_uint_32 mng_features)
|
||||
{
|
||||
@ -1306,7 +1187,7 @@ png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep
|
||||
return;
|
||||
old_num_chunks = png_ptr->num_chunk_list;
|
||||
new_list=(png_bytep)png_malloc(png_ptr,
|
||||
(png_uint_32)
|
||||
(png_size_t)
|
||||
(5*(num_chunks + old_num_chunks)));
|
||||
if (png_ptr->chunk_list != NULL)
|
||||
{
|
||||
@ -1321,13 +1202,11 @@ png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep
|
||||
*p=(png_byte)keep;
|
||||
png_ptr->num_chunk_list = old_num_chunks + num_chunks;
|
||||
png_ptr->chunk_list = new_list;
|
||||
#ifdef PNG_FREE_ME_SUPPORTED
|
||||
png_ptr->free_me |= PNG_FREE_LIST;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
|
||||
#ifdef PNG_READ_USER_CHUNKS_SUPPORTED
|
||||
void PNGAPI
|
||||
png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp user_chunk_ptr,
|
||||
png_user_chunk_ptr read_user_chunk_fn)
|
||||
@ -1342,7 +1221,7 @@ png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp user_chunk_ptr,
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_INFO_IMAGE_SUPPORTED)
|
||||
#ifdef PNG_INFO_IMAGE_SUPPORTED
|
||||
void PNGAPI
|
||||
png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers)
|
||||
{
|
||||
@ -1362,12 +1241,12 @@ png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers)
|
||||
#ifdef PNG_WRITE_SUPPORTED
|
||||
void PNGAPI
|
||||
png_set_compression_buffer_size(png_structp png_ptr,
|
||||
png_uint_32 size)
|
||||
png_size_t size)
|
||||
{
|
||||
if (png_ptr == NULL)
|
||||
return;
|
||||
png_free(png_ptr, png_ptr->zbuf);
|
||||
png_ptr->zbuf_size = (png_size_t)size;
|
||||
png_ptr->zbuf_size = size;
|
||||
png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, size);
|
||||
png_ptr->zstream.next_out = png_ptr->zbuf;
|
||||
png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
|
||||
@ -1382,32 +1261,6 @@ png_set_invalid(png_structp png_ptr, png_infop info_ptr, int mask)
|
||||
}
|
||||
|
||||
|
||||
#ifndef PNG_1_0_X
|
||||
#ifdef PNG_ASSEMBLER_CODE_SUPPORTED
|
||||
/* 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)
|
||||
{
|
||||
/* Obsolete as of libpng-1.2.20 and will be removed from libpng-1.4.0 */
|
||||
if (png_ptr != NULL)
|
||||
png_ptr->asm_flags = 0;
|
||||
asm_flags = asm_flags; /* Quiet the compiler */
|
||||
}
|
||||
|
||||
/* 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)
|
||||
{
|
||||
/* Obsolete as of libpng-1.2.20 and will be removed from libpng-1.4.0 */
|
||||
if (png_ptr == NULL)
|
||||
return;
|
||||
/* Quiet the compiler */
|
||||
mmx_bitdepth_threshold = mmx_bitdepth_threshold;
|
||||
mmx_rowbytes_threshold = mmx_rowbytes_threshold;
|
||||
}
|
||||
#endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
|
||||
|
||||
#ifdef PNG_SET_USER_LIMITS_SUPPORTED
|
||||
/* This function was added to libpng 1.2.6 */
|
||||
@ -1424,7 +1277,32 @@ png_set_user_limits (png_structp png_ptr, png_uint_32 user_width_max,
|
||||
png_ptr->user_width_max = user_width_max;
|
||||
png_ptr->user_height_max = user_height_max;
|
||||
}
|
||||
/* This function was added to libpng 1.4.0 */
|
||||
void PNGAPI
|
||||
png_set_chunk_cache_max (png_structp png_ptr,
|
||||
png_uint_32 user_chunk_cache_max)
|
||||
{
|
||||
if (png_ptr == NULL)
|
||||
return;
|
||||
png_ptr->user_chunk_cache_max = user_chunk_cache_max;
|
||||
if (user_chunk_cache_max == 0x7fffffffL) /* Unlimited */
|
||||
png_ptr->user_chunk_cache_max = 0;
|
||||
else
|
||||
png_ptr->user_chunk_cache_max = user_chunk_cache_max + 1;
|
||||
}
|
||||
#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
|
||||
|
||||
#endif /* ?PNG_1_0_X */
|
||||
|
||||
#ifdef PNG_BENIGN_ERRORS_SUPPORTED
|
||||
void PNGAPI
|
||||
png_set_benign_errors(png_structp png_ptr, int allowed)
|
||||
{
|
||||
png_debug(1, "in png_set_benign_errors");
|
||||
|
||||
if (allowed)
|
||||
png_ptr->flags |= PNG_FLAG_BENIGN_ERRORS_WARN;
|
||||
else
|
||||
png_ptr->flags &= ~PNG_FLAG_BENIGN_ERRORS_WARN;
|
||||
}
|
||||
#endif /* PNG_BENIGN_ERRORS_SUPPORTED */
|
||||
#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
|
||||
|
@ -1,8 +1,8 @@
|
||||
|
||||
/* pngtrans.c - transforms the data in a row (used by both readers and writers)
|
||||
*
|
||||
* Last changed in libpng 1.2.36 [May 14, 2009]
|
||||
* Copyright (c) 1998-2009 Glenn Randers-Pehrson
|
||||
* Last changed in libpng 1.4.0 [January 3, 2010]
|
||||
* Copyright (c) 1998-2010 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,9 +11,10 @@
|
||||
* and license in png.h
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
#define PNG_NO_PEDANTIC_WARNINGS
|
||||
#include "png.h"
|
||||
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
|
||||
#include "pngpriv.h"
|
||||
|
||||
#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
|
||||
/* Turn on BGR-to-RGB mapping */
|
||||
@ -21,6 +22,7 @@ void PNGAPI
|
||||
png_set_bgr(png_structp png_ptr)
|
||||
{
|
||||
png_debug(1, "in png_set_bgr");
|
||||
|
||||
if (png_ptr == NULL)
|
||||
return;
|
||||
png_ptr->transformations |= PNG_BGR;
|
||||
@ -33,6 +35,7 @@ void PNGAPI
|
||||
png_set_swap(png_structp png_ptr)
|
||||
{
|
||||
png_debug(1, "in png_set_swap");
|
||||
|
||||
if (png_ptr == NULL)
|
||||
return;
|
||||
if (png_ptr->bit_depth == 16)
|
||||
@ -46,6 +49,7 @@ void PNGAPI
|
||||
png_set_packing(png_structp png_ptr)
|
||||
{
|
||||
png_debug(1, "in png_set_packing");
|
||||
|
||||
if (png_ptr == NULL)
|
||||
return;
|
||||
if (png_ptr->bit_depth < 8)
|
||||
@ -62,6 +66,7 @@ void PNGAPI
|
||||
png_set_packswap(png_structp png_ptr)
|
||||
{
|
||||
png_debug(1, "in png_set_packswap");
|
||||
|
||||
if (png_ptr == NULL)
|
||||
return;
|
||||
if (png_ptr->bit_depth < 8)
|
||||
@ -74,6 +79,7 @@ void PNGAPI
|
||||
png_set_shift(png_structp png_ptr, png_color_8p true_bits)
|
||||
{
|
||||
png_debug(1, "in png_set_shift");
|
||||
|
||||
if (png_ptr == NULL)
|
||||
return;
|
||||
png_ptr->transformations |= PNG_SHIFT;
|
||||
@ -87,6 +93,7 @@ int PNGAPI
|
||||
png_set_interlace_handling(png_structp png_ptr)
|
||||
{
|
||||
png_debug(1, "in png_set_interlace handling");
|
||||
|
||||
if (png_ptr && png_ptr->interlaced)
|
||||
{
|
||||
png_ptr->transformations |= PNG_INTERLACE;
|
||||
@ -107,10 +114,11 @@ void PNGAPI
|
||||
png_set_filler(png_structp png_ptr, png_uint_32 filler, int filler_loc)
|
||||
{
|
||||
png_debug(1, "in png_set_filler");
|
||||
|
||||
if (png_ptr == NULL)
|
||||
return;
|
||||
png_ptr->transformations |= PNG_FILLER;
|
||||
png_ptr->filler = (png_byte)filler;
|
||||
png_ptr->filler = (png_uint_16)filler;
|
||||
if (filler_loc == PNG_FILLER_AFTER)
|
||||
png_ptr->flags |= PNG_FLAG_FILLER_AFTER;
|
||||
else
|
||||
@ -135,18 +143,17 @@ png_set_filler(png_structp png_ptr, png_uint_32 filler, int filler_loc)
|
||||
}
|
||||
}
|
||||
|
||||
#if !defined(PNG_1_0_X)
|
||||
/* Added to libpng-1.2.7 */
|
||||
void PNGAPI
|
||||
png_set_add_alpha(png_structp png_ptr, png_uint_32 filler, int filler_loc)
|
||||
{
|
||||
png_debug(1, "in png_set_add_alpha");
|
||||
|
||||
if (png_ptr == NULL)
|
||||
return;
|
||||
png_set_filler(png_ptr, filler, filler_loc);
|
||||
png_ptr->transformations |= PNG_ADD_ALPHA;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@ -156,6 +163,7 @@ void PNGAPI
|
||||
png_set_swap_alpha(png_structp png_ptr)
|
||||
{
|
||||
png_debug(1, "in png_set_swap_alpha");
|
||||
|
||||
if (png_ptr == NULL)
|
||||
return;
|
||||
png_ptr->transformations |= PNG_SWAP_ALPHA;
|
||||
@ -168,6 +176,7 @@ void PNGAPI
|
||||
png_set_invert_alpha(png_structp png_ptr)
|
||||
{
|
||||
png_debug(1, "in png_set_invert_alpha");
|
||||
|
||||
if (png_ptr == NULL)
|
||||
return;
|
||||
png_ptr->transformations |= PNG_INVERT_ALPHA;
|
||||
@ -179,6 +188,7 @@ void PNGAPI
|
||||
png_set_invert_mono(png_structp png_ptr)
|
||||
{
|
||||
png_debug(1, "in png_set_invert_mono");
|
||||
|
||||
if (png_ptr == NULL)
|
||||
return;
|
||||
png_ptr->transformations |= PNG_INVERT_MONO;
|
||||
@ -189,13 +199,10 @@ void /* PRIVATE */
|
||||
png_do_invert(png_row_infop row_info, png_bytep row)
|
||||
{
|
||||
png_debug(1, "in png_do_invert");
|
||||
|
||||
/* 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)
|
||||
if (row == NULL || row_info == NULL)
|
||||
return;
|
||||
#endif
|
||||
if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
|
||||
{
|
||||
png_bytep rp = row;
|
||||
@ -244,10 +251,8 @@ void /* PRIVATE */
|
||||
png_do_swap(png_row_infop row_info, png_bytep row)
|
||||
{
|
||||
png_debug(1, "in png_do_swap");
|
||||
|
||||
if (
|
||||
#if defined(PNG_USELESS_TESTS_SUPPORTED)
|
||||
row != NULL && row_info != NULL &&
|
||||
#endif
|
||||
row_info->bit_depth == 16)
|
||||
{
|
||||
png_bytep rp = row;
|
||||
@ -375,10 +380,8 @@ void /* PRIVATE */
|
||||
png_do_packswap(png_row_infop row_info, png_bytep row)
|
||||
{
|
||||
png_debug(1, "in png_do_packswap");
|
||||
|
||||
if (
|
||||
#if defined(PNG_USELESS_TESTS_SUPPORTED)
|
||||
row != NULL && row_info != NULL &&
|
||||
#endif
|
||||
row_info->bit_depth < 8)
|
||||
{
|
||||
png_bytep rp, end, table;
|
||||
@ -407,9 +410,7 @@ void /* PRIVATE */
|
||||
png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags)
|
||||
{
|
||||
png_debug(1, "in png_do_strip_filler");
|
||||
#if defined(PNG_USELESS_TESTS_SUPPORTED)
|
||||
if (row != NULL && row_info != NULL)
|
||||
#endif
|
||||
|
||||
{
|
||||
png_bytep sp=row;
|
||||
png_bytep dp=row;
|
||||
@ -565,10 +566,8 @@ void /* PRIVATE */
|
||||
png_do_bgr(png_row_infop row_info, png_bytep row)
|
||||
{
|
||||
png_debug(1, "in png_do_bgr");
|
||||
|
||||
if (
|
||||
#if defined(PNG_USELESS_TESTS_SUPPORTED)
|
||||
row != NULL && row_info != NULL &&
|
||||
#endif
|
||||
(row_info->color_type & PNG_COLOR_MASK_COLOR))
|
||||
{
|
||||
png_uint_32 row_width = row_info->width;
|
||||
@ -637,16 +636,16 @@ png_do_bgr(png_row_infop row_info, png_bytep row)
|
||||
#endif /* PNG_READ_BGR_SUPPORTED or PNG_WRITE_BGR_SUPPORTED */
|
||||
|
||||
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
|
||||
defined(PNG_LEGACY_SUPPORTED) || \
|
||||
defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
|
||||
void PNGAPI
|
||||
png_set_user_transform_info(png_structp png_ptr, png_voidp
|
||||
user_transform_ptr, int user_transform_depth, int user_transform_channels)
|
||||
{
|
||||
png_debug(1, "in png_set_user_transform_info");
|
||||
|
||||
if (png_ptr == NULL)
|
||||
return;
|
||||
#if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
|
||||
#ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED
|
||||
png_ptr->user_transform_ptr = user_transform_ptr;
|
||||
png_ptr->user_transform_depth = (png_byte)user_transform_depth;
|
||||
png_ptr->user_transform_channels = (png_byte)user_transform_channels;
|
||||
@ -668,7 +667,7 @@ png_get_user_transform_ptr(png_structp png_ptr)
|
||||
{
|
||||
if (png_ptr == NULL)
|
||||
return (NULL);
|
||||
#if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
|
||||
#ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED
|
||||
return ((png_voidp)png_ptr->user_transform_ptr);
|
||||
#else
|
||||
return (NULL);
|
||||
|
@ -1,8 +1,8 @@
|
||||
|
||||
/* pngwio.c - functions for data output
|
||||
*
|
||||
* Last changed in libpng 1.2.37 [June 4, 2009]
|
||||
* Copyright (c) 1998-2009 Glenn Randers-Pehrson
|
||||
* Last changed in libpng 1.4.0 [January 3, 2010]
|
||||
* Copyright (c) 1998-2010 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,9 +18,10 @@
|
||||
* them at run time with png_set_write_fn(...).
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
#define PNG_NO_PEDANTIC_WARNINGS
|
||||
#include "png.h"
|
||||
#ifdef PNG_WRITE_SUPPORTED
|
||||
#include "pngpriv.h"
|
||||
|
||||
/* Write the data to whatever output you are using. The default routine
|
||||
* writes to a file pointer. Note that this routine sometimes gets called
|
||||
@ -38,7 +39,7 @@ png_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
png_error(png_ptr, "Call to NULL write function");
|
||||
}
|
||||
|
||||
#if !defined(PNG_NO_STDIO)
|
||||
#ifdef PNG_STDIO_SUPPORTED
|
||||
/* This is the function that does the actual writing of data. If you are
|
||||
* not writing to a standard C stream, you should create a replacement
|
||||
* write_data function and use it at run time with png_set_write_fn(), rather
|
||||
@ -52,12 +53,7 @@ png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
|
||||
if (png_ptr == NULL)
|
||||
return;
|
||||
#if defined(_WIN32_WCE)
|
||||
if ( !WriteFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
|
||||
check = 0;
|
||||
#else
|
||||
check = fwrite(data, 1, length, (png_FILE_p)(png_ptr->io_ptr));
|
||||
#endif
|
||||
if (check != length)
|
||||
png_error(png_ptr, "Write Error");
|
||||
}
|
||||
@ -84,12 +80,7 @@ png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
|
||||
if ((png_bytep)near_data == data)
|
||||
{
|
||||
#if defined(_WIN32_WCE)
|
||||
if ( !WriteFile(io_ptr, near_data, length, &check, NULL) )
|
||||
check = 0;
|
||||
#else
|
||||
check = fwrite(near_data, 1, length, io_ptr);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -101,12 +92,7 @@ png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
{
|
||||
written = MIN(NEAR_BUF_SIZE, remaining);
|
||||
png_memcpy(buf, data, written); /* Copy far buffer to near buffer */
|
||||
#if defined(_WIN32_WCE)
|
||||
if ( !WriteFile(io_ptr, buf, written, &err, NULL) )
|
||||
err = 0;
|
||||
#else
|
||||
err = fwrite(buf, 1, written, io_ptr);
|
||||
#endif
|
||||
if (err != written)
|
||||
break;
|
||||
|
||||
@ -129,7 +115,7 @@ png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
* to disk). After png_flush is called, there should be no data pending
|
||||
* writing in any buffers.
|
||||
*/
|
||||
#if defined(PNG_WRITE_FLUSH_SUPPORTED)
|
||||
#ifdef PNG_WRITE_FLUSH_SUPPORTED
|
||||
void /* PRIVATE */
|
||||
png_flush(png_structp png_ptr)
|
||||
{
|
||||
@ -137,19 +123,15 @@ png_flush(png_structp png_ptr)
|
||||
(*(png_ptr->output_flush_fn))(png_ptr);
|
||||
}
|
||||
|
||||
#if !defined(PNG_NO_STDIO)
|
||||
#ifdef PNG_STDIO_SUPPORTED
|
||||
void PNGAPI
|
||||
png_default_flush(png_structp png_ptr)
|
||||
{
|
||||
#if !defined(_WIN32_WCE)
|
||||
png_FILE_p io_ptr;
|
||||
#endif
|
||||
if (png_ptr == NULL)
|
||||
return;
|
||||
#if !defined(_WIN32_WCE)
|
||||
io_ptr = (png_FILE_p)CVT_PTR((png_ptr->io_ptr));
|
||||
fflush(io_ptr);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@ -192,7 +174,7 @@ png_set_write_fn(png_structp png_ptr, png_voidp io_ptr,
|
||||
|
||||
png_ptr->io_ptr = io_ptr;
|
||||
|
||||
#if !defined(PNG_NO_STDIO)
|
||||
#ifdef PNG_STDIO_SUPPORTED
|
||||
if (write_data_fn != NULL)
|
||||
png_ptr->write_data_fn = write_data_fn;
|
||||
|
||||
@ -202,8 +184,8 @@ png_set_write_fn(png_structp png_ptr, png_voidp io_ptr,
|
||||
png_ptr->write_data_fn = write_data_fn;
|
||||
#endif
|
||||
|
||||
#if defined(PNG_WRITE_FLUSH_SUPPORTED)
|
||||
#if !defined(PNG_NO_STDIO)
|
||||
#ifdef PNG_WRITE_FLUSH_SUPPORTED
|
||||
#ifdef PNG_STDIO_SUPPORTED
|
||||
if (output_flush_fn != NULL)
|
||||
png_ptr->output_flush_fn = output_flush_fn;
|
||||
|
||||
@ -221,12 +203,12 @@ png_set_write_fn(png_structp png_ptr, png_voidp io_ptr,
|
||||
png_warning(png_ptr,
|
||||
"Attempted to set both read_data_fn and write_data_fn in");
|
||||
png_warning(png_ptr,
|
||||
"the same structure. Resetting read_data_fn to NULL.");
|
||||
"the same structure. Resetting read_data_fn to NULL");
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(USE_FAR_KEYWORD)
|
||||
#if defined(_MSC_VER)
|
||||
#ifdef USE_FAR_KEYWORD
|
||||
#ifdef _MSC_VER
|
||||
void *png_far_to_near(png_structp png_ptr, png_voidp ptr, int check)
|
||||
{
|
||||
void *near_ptr;
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,8 +1,8 @@
|
||||
|
||||
/* pngwtran.c - transforms the data in a row for PNG writers
|
||||
*
|
||||
* Last changed in libpng 1.2.37 [June 4, 2009]
|
||||
* Copyright (c) 1998-2009 Glenn Randers-Pehrson
|
||||
* Last changed in libpng 1.4.0 [January 3, 2010]
|
||||
* Copyright (c) 1998-2010 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,9 +11,10 @@
|
||||
* and license in png.h
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
#define PNG_NO_PEDANTIC_WARNINGS
|
||||
#include "png.h"
|
||||
#ifdef PNG_WRITE_SUPPORTED
|
||||
#include "pngpriv.h"
|
||||
|
||||
/* Transform the data according to the user's wishes. The order of
|
||||
* transformations is significant.
|
||||
@ -26,7 +27,7 @@ png_do_write_transformations(png_structp png_ptr)
|
||||
if (png_ptr == NULL)
|
||||
return;
|
||||
|
||||
#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
|
||||
#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
|
||||
if (png_ptr->transformations & PNG_USER_TRANSFORM)
|
||||
if (png_ptr->write_user_transform_fn != NULL)
|
||||
(*(png_ptr->write_user_transform_fn)) /* User write transform function */
|
||||
@ -40,48 +41,48 @@ png_do_write_transformations(png_structp png_ptr)
|
||||
/* png_byte pixel_depth; bits per pixel (depth*channels) */
|
||||
png_ptr->row_buf + 1); /* start of pixel data for row */
|
||||
#endif
|
||||
#if defined(PNG_WRITE_FILLER_SUPPORTED)
|
||||
#ifdef PNG_WRITE_FILLER_SUPPORTED
|
||||
if (png_ptr->transformations & PNG_FILLER)
|
||||
png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
|
||||
png_ptr->flags);
|
||||
#endif
|
||||
#if defined(PNG_WRITE_PACKSWAP_SUPPORTED)
|
||||
#ifdef PNG_WRITE_PACKSWAP_SUPPORTED
|
||||
if (png_ptr->transformations & PNG_PACKSWAP)
|
||||
png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1);
|
||||
#endif
|
||||
#if defined(PNG_WRITE_PACK_SUPPORTED)
|
||||
#ifdef PNG_WRITE_PACK_SUPPORTED
|
||||
if (png_ptr->transformations & PNG_PACK)
|
||||
png_do_pack(&(png_ptr->row_info), png_ptr->row_buf + 1,
|
||||
(png_uint_32)png_ptr->bit_depth);
|
||||
#endif
|
||||
#if defined(PNG_WRITE_SWAP_SUPPORTED)
|
||||
#ifdef PNG_WRITE_SWAP_SUPPORTED
|
||||
if (png_ptr->transformations & PNG_SWAP_BYTES)
|
||||
png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
|
||||
#endif
|
||||
#if defined(PNG_WRITE_SHIFT_SUPPORTED)
|
||||
#ifdef PNG_WRITE_SHIFT_SUPPORTED
|
||||
if (png_ptr->transformations & PNG_SHIFT)
|
||||
png_do_shift(&(png_ptr->row_info), png_ptr->row_buf + 1,
|
||||
&(png_ptr->shift));
|
||||
#endif
|
||||
#if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
|
||||
#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED
|
||||
if (png_ptr->transformations & PNG_SWAP_ALPHA)
|
||||
png_do_write_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
|
||||
#endif
|
||||
#if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
|
||||
#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED
|
||||
if (png_ptr->transformations & PNG_INVERT_ALPHA)
|
||||
png_do_write_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
|
||||
#endif
|
||||
#if defined(PNG_WRITE_BGR_SUPPORTED)
|
||||
#ifdef PNG_WRITE_BGR_SUPPORTED
|
||||
if (png_ptr->transformations & PNG_BGR)
|
||||
png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
|
||||
#endif
|
||||
#if defined(PNG_WRITE_INVERT_SUPPORTED)
|
||||
#ifdef PNG_WRITE_INVERT_SUPPORTED
|
||||
if (png_ptr->transformations & PNG_INVERT_MONO)
|
||||
png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(PNG_WRITE_PACK_SUPPORTED)
|
||||
#ifdef PNG_WRITE_PACK_SUPPORTED
|
||||
/* Pack pixels into bytes. Pass the true bit depth in bit_depth. The
|
||||
* row_info bit depth should be 8 (one pixel per byte). The channels
|
||||
* should be 1 (this only happens on grayscale and paletted images).
|
||||
@ -90,10 +91,8 @@ void /* PRIVATE */
|
||||
png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth)
|
||||
{
|
||||
png_debug(1, "in png_do_pack");
|
||||
|
||||
if (row_info->bit_depth == 8 &&
|
||||
#if defined(PNG_USELESS_TESTS_SUPPORTED)
|
||||
row != NULL && row_info != NULL &&
|
||||
#endif
|
||||
row_info->channels == 1)
|
||||
{
|
||||
switch ((int)bit_depth)
|
||||
@ -204,7 +203,7 @@ png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_WRITE_SHIFT_SUPPORTED)
|
||||
#ifdef PNG_WRITE_SHIFT_SUPPORTED
|
||||
/* Shift pixel values to take advantage of whole range. Pass the
|
||||
* true number of bits in bit_depth. The row should be packed
|
||||
* according to row_info->bit_depth. Thus, if you had a row of
|
||||
@ -216,11 +215,8 @@ void /* PRIVATE */
|
||||
png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
|
||||
{
|
||||
png_debug(1, "in png_do_shift");
|
||||
#if defined(PNG_USELESS_TESTS_SUPPORTED)
|
||||
if (row != NULL && row_info != NULL &&
|
||||
#else
|
||||
|
||||
if (
|
||||
#endif
|
||||
row_info->color_type != PNG_COLOR_TYPE_PALETTE)
|
||||
{
|
||||
int shift_start[4], shift_dec[4];
|
||||
@ -335,14 +331,12 @@ png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
|
||||
#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED
|
||||
void /* PRIVATE */
|
||||
png_do_write_swap_alpha(png_row_infop row_info, png_bytep row)
|
||||
{
|
||||
png_debug(1, "in png_do_write_swap_alpha");
|
||||
#if defined(PNG_USELESS_TESTS_SUPPORTED)
|
||||
if (row != NULL && row_info != NULL)
|
||||
#endif
|
||||
|
||||
{
|
||||
if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
|
||||
{
|
||||
@ -423,14 +417,12 @@ png_do_write_swap_alpha(png_row_infop row_info, png_bytep row)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
|
||||
#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED
|
||||
void /* PRIVATE */
|
||||
png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
|
||||
{
|
||||
png_debug(1, "in png_do_write_invert_alpha");
|
||||
#if defined(PNG_USELESS_TESTS_SUPPORTED)
|
||||
if (row != NULL && row_info != NULL)
|
||||
#endif
|
||||
|
||||
{
|
||||
if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
|
||||
{
|
||||
@ -512,16 +504,14 @@ png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_MNG_FEATURES_SUPPORTED)
|
||||
#ifdef PNG_MNG_FEATURES_SUPPORTED
|
||||
/* Undoes intrapixel differencing */
|
||||
void /* PRIVATE */
|
||||
png_do_write_intrapixel(png_row_infop row_info, png_bytep row)
|
||||
{
|
||||
png_debug(1, "in png_do_write_intrapixel");
|
||||
|
||||
if (
|
||||
#if defined(PNG_USELESS_TESTS_SUPPORTED)
|
||||
row != NULL && row_info != NULL &&
|
||||
#endif
|
||||
(row_info->color_type & PNG_COLOR_MASK_COLOR))
|
||||
{
|
||||
int bytes_per_pixel;
|
||||
|
@ -1,8 +1,8 @@
|
||||
|
||||
/* pngwutil.c - utilities to write a PNG file
|
||||
*
|
||||
* Last changed in libpng 1.2.40 [September 10, 2009]
|
||||
* Copyright (c) 1998-2009 Glenn Randers-Pehrson
|
||||
* Last changed in libpng 1.4.0 [January 3, 2010]
|
||||
* Copyright (c) 1998-2010 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,9 +11,10 @@
|
||||
* and license in png.h
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
#define PNG_NO_PEDANTIC_WARNINGS
|
||||
#include "png.h"
|
||||
#ifdef PNG_WRITE_SUPPORTED
|
||||
#include "pngpriv.h"
|
||||
|
||||
/* Place a 32-bit number into a buffer in PNG byte order. We work
|
||||
* with unsigned numbers for convenience, although one supported
|
||||
@ -28,6 +29,7 @@ png_save_uint_32(png_bytep buf, png_uint_32 i)
|
||||
buf[3] = (png_byte)(i & 0xff);
|
||||
}
|
||||
|
||||
#ifdef PNG_SAVE_INT_32_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.
|
||||
@ -40,6 +42,7 @@ png_save_int_32(png_bytep buf, png_int_32 i)
|
||||
buf[2] = (png_byte)((i >> 8) & 0xff);
|
||||
buf[3] = (png_byte)(i & 0xff);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Place a 16-bit number into a buffer in PNG byte order.
|
||||
* The parameter is declared unsigned int, not png_uint_16,
|
||||
@ -58,11 +61,16 @@ png_save_uint_16(png_bytep buf, unsigned int i)
|
||||
* we should call png_set_sig_bytes() to tell libpng how many of the
|
||||
* bytes have already been written.
|
||||
*/
|
||||
void /* PRIVATE */
|
||||
void PNGAPI
|
||||
png_write_sig(png_structp png_ptr)
|
||||
{
|
||||
png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
|
||||
|
||||
#ifdef PNG_IO_STATE_SUPPORTED
|
||||
/* Inform the I/O callback that the signature is being written */
|
||||
png_ptr->io_state = PNG_IO_WRITING | PNG_IO_SIGNATURE;
|
||||
#endif
|
||||
|
||||
/* Write the rest of the 8 byte signature */
|
||||
png_write_data(png_ptr, &png_signature[png_ptr->sig_bytes],
|
||||
(png_size_t)(8 - png_ptr->sig_bytes));
|
||||
@ -106,6 +114,13 @@ png_write_chunk_start(png_structp png_ptr, png_bytep chunk_name,
|
||||
if (png_ptr == NULL)
|
||||
return;
|
||||
|
||||
#ifdef PNG_IO_STATE_SUPPORTED
|
||||
/* Inform the I/O callback that the chunk header is being written.
|
||||
* PNG_IO_CHUNK_HDR requires a single I/O call.
|
||||
*/
|
||||
png_ptr->io_state = PNG_IO_WRITING | PNG_IO_CHUNK_HDR;
|
||||
#endif
|
||||
|
||||
/* Write the length and the chunk name */
|
||||
png_save_uint_32(buf, length);
|
||||
png_memcpy(buf + 4, chunk_name, 4);
|
||||
@ -114,7 +129,14 @@ png_write_chunk_start(png_structp png_ptr, png_bytep chunk_name,
|
||||
png_memcpy(png_ptr->chunk_name, chunk_name, 4);
|
||||
/* Reset the crc and run it over the chunk name */
|
||||
png_reset_crc(png_ptr);
|
||||
png_calculate_crc(png_ptr, chunk_name, (png_size_t)4);
|
||||
png_calculate_crc(png_ptr, chunk_name, 4);
|
||||
|
||||
#ifdef PNG_IO_STATE_SUPPORTED
|
||||
/* Inform the I/O callback that chunk data will (possibly) be written.
|
||||
* PNG_IO_CHUNK_DATA does NOT require a specific number of I/O calls.
|
||||
*/
|
||||
png_ptr->io_state = PNG_IO_WRITING | PNG_IO_CHUNK_DATA;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Write the data of a PNG chunk started with png_write_chunk_start().
|
||||
@ -146,6 +168,13 @@ png_write_chunk_end(png_structp png_ptr)
|
||||
|
||||
if (png_ptr == NULL) return;
|
||||
|
||||
#ifdef PNG_IO_STATE_SUPPORTED
|
||||
/* Inform the I/O callback that the chunk CRC is being written.
|
||||
* PNG_IO_CHUNK_CRC requires a single I/O function call.
|
||||
*/
|
||||
png_ptr->io_state = PNG_IO_WRITING | PNG_IO_CHUNK_CRC;
|
||||
#endif
|
||||
|
||||
/* Write the crc in a single operation */
|
||||
png_save_uint_32(buf, png_ptr->crc);
|
||||
|
||||
@ -192,7 +221,7 @@ png_text_compress(png_structp png_ptr,
|
||||
|
||||
if (compression >= PNG_TEXT_COMPRESSION_LAST)
|
||||
{
|
||||
#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
|
||||
#ifdef PNG_STDIO_SUPPORTED
|
||||
char msg[50];
|
||||
png_snprintf(msg, 50, "Unknown compression type %d", compression);
|
||||
png_warning(png_ptr, msg);
|
||||
@ -251,7 +280,7 @@ png_text_compress(png_structp png_ptr,
|
||||
|
||||
old_ptr = comp->output_ptr;
|
||||
comp->output_ptr = (png_charpp)png_malloc(png_ptr,
|
||||
(png_uint_32)
|
||||
(png_alloc_size_t)
|
||||
(comp->max_output_ptr * png_sizeof(png_charpp)));
|
||||
png_memcpy(comp->output_ptr, old_ptr, old_max
|
||||
* png_sizeof(png_charp));
|
||||
@ -259,14 +288,14 @@ png_text_compress(png_structp png_ptr,
|
||||
}
|
||||
else
|
||||
comp->output_ptr = (png_charpp)png_malloc(png_ptr,
|
||||
(png_uint_32)
|
||||
(png_alloc_size_t)
|
||||
(comp->max_output_ptr * png_sizeof(png_charp)));
|
||||
}
|
||||
|
||||
/* Save the data */
|
||||
comp->output_ptr[comp->num_output_ptr] =
|
||||
(png_charp)png_malloc(png_ptr,
|
||||
(png_uint_32)png_ptr->zbuf_size);
|
||||
(png_alloc_size_t)png_ptr->zbuf_size);
|
||||
png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
|
||||
png_ptr->zbuf_size);
|
||||
comp->num_output_ptr++;
|
||||
@ -303,7 +332,7 @@ png_text_compress(png_structp png_ptr,
|
||||
old_ptr = comp->output_ptr;
|
||||
/* This could be optimized to realloc() */
|
||||
comp->output_ptr = (png_charpp)png_malloc(png_ptr,
|
||||
(png_uint_32)(comp->max_output_ptr *
|
||||
(png_alloc_size_t)(comp->max_output_ptr *
|
||||
png_sizeof(png_charp)));
|
||||
png_memcpy(comp->output_ptr, old_ptr,
|
||||
old_max * png_sizeof(png_charp));
|
||||
@ -311,14 +340,14 @@ png_text_compress(png_structp png_ptr,
|
||||
}
|
||||
else
|
||||
comp->output_ptr = (png_charpp)png_malloc(png_ptr,
|
||||
(png_uint_32)(comp->max_output_ptr *
|
||||
(png_alloc_size_t)(comp->max_output_ptr *
|
||||
png_sizeof(png_charp)));
|
||||
}
|
||||
|
||||
/* Save the data */
|
||||
comp->output_ptr[comp->num_output_ptr] =
|
||||
(png_charp)png_malloc(png_ptr,
|
||||
(png_uint_32)png_ptr->zbuf_size);
|
||||
(png_alloc_size_t)png_ptr->zbuf_size);
|
||||
png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
|
||||
png_ptr->zbuf_size);
|
||||
comp->num_output_ptr++;
|
||||
@ -366,11 +395,9 @@ png_write_compressed_data_out(png_structp png_ptr, compression_state *comp)
|
||||
png_write_chunk_data(png_ptr, (png_bytep)comp->output_ptr[i],
|
||||
(png_size_t)png_ptr->zbuf_size);
|
||||
png_free(png_ptr, comp->output_ptr[i]);
|
||||
comp->output_ptr[i]=NULL;
|
||||
}
|
||||
if (comp->max_output_ptr != 0)
|
||||
png_free(png_ptr, comp->output_ptr);
|
||||
comp->output_ptr=NULL;
|
||||
/* Write anything left in zbuf */
|
||||
if (png_ptr->zstream.avail_out < (png_uint_32)png_ptr->zbuf_size)
|
||||
png_write_chunk_data(png_ptr, png_ptr->zbuf,
|
||||
@ -391,9 +418,7 @@ png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height,
|
||||
int bit_depth, int color_type, int compression_type, int filter_type,
|
||||
int interlace_type)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
PNG_IHDR;
|
||||
#endif
|
||||
int ret;
|
||||
|
||||
png_byte buf[13]; /* Buffer to store the IHDR info */
|
||||
@ -459,7 +484,7 @@ png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height,
|
||||
* 5. The color_type is RGB or RGBA
|
||||
*/
|
||||
if (
|
||||
#if defined(PNG_MNG_FEATURES_SUPPORTED)
|
||||
#ifdef 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 ||
|
||||
@ -487,7 +512,7 @@ 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)
|
||||
#ifdef PNG_MNG_FEATURES_SUPPORTED
|
||||
png_ptr->filter_type = (png_byte)filter_type;
|
||||
#endif
|
||||
png_ptr->compression_type = (png_byte)compression_type;
|
||||
@ -574,9 +599,7 @@ png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height,
|
||||
void /* PRIVATE */
|
||||
png_write_PLTE(png_structp png_ptr, png_colorp palette, png_uint_32 num_pal)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
PNG_PLTE;
|
||||
#endif
|
||||
png_uint_32 i;
|
||||
png_colorp pal_ptr;
|
||||
png_byte buf[3];
|
||||
@ -584,7 +607,7 @@ png_write_PLTE(png_structp png_ptr, png_colorp palette, png_uint_32 num_pal)
|
||||
png_debug(1, "in png_write_PLTE");
|
||||
|
||||
if ((
|
||||
#if defined(PNG_MNG_FEATURES_SUPPORTED)
|
||||
#ifdef PNG_MNG_FEATURES_SUPPORTED
|
||||
!(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) &&
|
||||
#endif
|
||||
num_pal == 0) || num_pal > 256)
|
||||
@ -612,7 +635,7 @@ png_write_PLTE(png_structp png_ptr, png_colorp palette, png_uint_32 num_pal)
|
||||
|
||||
png_write_chunk_start(png_ptr, (png_bytep)png_PLTE,
|
||||
(png_uint_32)(num_pal * 3));
|
||||
#ifndef PNG_NO_POINTER_INDEXING
|
||||
#ifdef PNG_POINTER_INDEXING_SUPPORTED
|
||||
for (i = 0, pal_ptr = palette; i < num_pal; i++, pal_ptr++)
|
||||
{
|
||||
buf[0] = pal_ptr->red;
|
||||
@ -639,11 +662,9 @@ png_write_PLTE(png_structp png_ptr, png_colorp palette, png_uint_32 num_pal)
|
||||
void /* PRIVATE */
|
||||
png_write_IDAT(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
PNG_IDAT;
|
||||
#if defined(PNG_WRITE_APNG_SUPPORTED)
|
||||
PNG_fdAT;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
png_debug(1, "in png_write_IDAT");
|
||||
@ -718,26 +739,22 @@ png_write_IDAT(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
void /* PRIVATE */
|
||||
png_write_IEND(png_structp png_ptr)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
PNG_IEND;
|
||||
#endif
|
||||
|
||||
png_debug(1, "in png_write_IEND");
|
||||
|
||||
png_write_chunk(png_ptr, (png_bytep)png_IEND, png_bytep_NULL,
|
||||
png_write_chunk(png_ptr, (png_bytep)png_IEND, NULL,
|
||||
(png_size_t)0);
|
||||
png_ptr->mode |= PNG_HAVE_IEND;
|
||||
}
|
||||
|
||||
#if defined(PNG_WRITE_gAMA_SUPPORTED)
|
||||
#ifdef PNG_WRITE_gAMA_SUPPORTED
|
||||
/* Write a gAMA chunk */
|
||||
#ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
void /* PRIVATE */
|
||||
png_write_gAMA(png_structp png_ptr, double file_gamma)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
PNG_gAMA;
|
||||
#endif
|
||||
png_uint_32 igamma;
|
||||
png_byte buf[4];
|
||||
|
||||
@ -753,9 +770,7 @@ png_write_gAMA(png_structp png_ptr, double file_gamma)
|
||||
void /* PRIVATE */
|
||||
png_write_gAMA_fixed(png_structp png_ptr, png_fixed_point file_gamma)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
PNG_gAMA;
|
||||
#endif
|
||||
png_byte buf[4];
|
||||
|
||||
png_debug(1, "in png_write_gAMA");
|
||||
@ -767,14 +782,12 @@ png_write_gAMA_fixed(png_structp png_ptr, png_fixed_point file_gamma)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(PNG_WRITE_sRGB_SUPPORTED)
|
||||
#ifdef PNG_WRITE_sRGB_SUPPORTED
|
||||
/* Write a sRGB chunk */
|
||||
void /* PRIVATE */
|
||||
png_write_sRGB(png_structp png_ptr, int srgb_intent)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
PNG_sRGB;
|
||||
#endif
|
||||
png_byte buf[1];
|
||||
|
||||
png_debug(1, "in png_write_sRGB");
|
||||
@ -787,15 +800,13 @@ png_write_sRGB(png_structp png_ptr, int srgb_intent)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_WRITE_iCCP_SUPPORTED)
|
||||
#ifdef PNG_WRITE_iCCP_SUPPORTED
|
||||
/* Write an iCCP chunk */
|
||||
void /* PRIVATE */
|
||||
png_write_iCCP(png_structp png_ptr, png_charp name, int compression_type,
|
||||
png_charp profile, int profile_len)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
PNG_iCCP;
|
||||
#endif
|
||||
png_size_t name_len;
|
||||
png_charp new_name;
|
||||
compression_state comp;
|
||||
@ -868,21 +879,19 @@ png_write_iCCP(png_structp png_ptr, png_charp name, int compression_type,
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_WRITE_sPLT_SUPPORTED)
|
||||
#ifdef PNG_WRITE_sPLT_SUPPORTED
|
||||
/* Write a sPLT chunk */
|
||||
void /* PRIVATE */
|
||||
png_write_sPLT(png_structp png_ptr, png_sPLT_tp spalette)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
PNG_sPLT;
|
||||
#endif
|
||||
png_size_t name_len;
|
||||
png_charp new_name;
|
||||
png_byte entrybuf[10];
|
||||
int entry_size = (spalette->depth == 8 ? 6 : 10);
|
||||
int palette_size = entry_size * spalette->nentries;
|
||||
png_size_t entry_size = (spalette->depth == 8 ? 6 : 10);
|
||||
png_size_t palette_size = entry_size * spalette->nentries;
|
||||
png_sPLT_entryp ep;
|
||||
#ifdef PNG_NO_POINTER_INDEXING
|
||||
#ifndef PNG_POINTER_INDEXING_SUPPORTED
|
||||
int i;
|
||||
#endif
|
||||
|
||||
@ -899,7 +908,7 @@ png_write_sPLT(png_structp png_ptr, png_sPLT_tp spalette)
|
||||
png_write_chunk_data(png_ptr, (png_bytep)&spalette->depth, (png_size_t)1);
|
||||
|
||||
/* Loop through each palette entry, writing appropriately */
|
||||
#ifndef PNG_NO_POINTER_INDEXING
|
||||
#ifdef PNG_POINTER_INDEXING_SUPPORTED
|
||||
for (ep = spalette->entries; ep<spalette->entries + spalette->nentries; ep++)
|
||||
{
|
||||
if (spalette->depth == 8)
|
||||
@ -949,14 +958,12 @@ png_write_sPLT(png_structp png_ptr, png_sPLT_tp spalette)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_WRITE_sBIT_SUPPORTED)
|
||||
#ifdef PNG_WRITE_sBIT_SUPPORTED
|
||||
/* Write the sBIT chunk */
|
||||
void /* PRIVATE */
|
||||
png_write_sBIT(png_structp png_ptr, png_color_8p sbit, int color_type)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
PNG_sBIT;
|
||||
#endif
|
||||
png_byte buf[4];
|
||||
png_size_t size;
|
||||
|
||||
@ -1006,7 +1013,7 @@ png_write_sBIT(png_structp png_ptr, png_color_8p sbit, int color_type)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_WRITE_cHRM_SUPPORTED)
|
||||
#ifdef PNG_WRITE_cHRM_SUPPORTED
|
||||
/* Write the cHRM chunk */
|
||||
#ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
void /* PRIVATE */
|
||||
@ -1014,9 +1021,7 @@ png_write_cHRM(png_structp png_ptr, double white_x, double white_y,
|
||||
double red_x, double red_y, double green_x, double green_y,
|
||||
double blue_x, double blue_y)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
PNG_cHRM;
|
||||
#endif
|
||||
png_byte buf[32];
|
||||
|
||||
png_fixed_point int_white_x, int_white_y, int_red_x, int_red_y,
|
||||
@ -1033,7 +1038,7 @@ png_write_cHRM(png_structp png_ptr, double white_x, double white_y,
|
||||
int_blue_x = (png_uint_32)(blue_x * 100000.0 + 0.5);
|
||||
int_blue_y = (png_uint_32)(blue_y * 100000.0 + 0.5);
|
||||
|
||||
#if !defined(PNG_NO_CHECK_cHRM)
|
||||
#ifdef PNG_CHECK_cHRM_SUPPORTED
|
||||
if (png_check_cHRM_fixed(png_ptr, int_white_x, int_white_y,
|
||||
int_red_x, int_red_y, int_green_x, int_green_y, int_blue_x, int_blue_y))
|
||||
#endif
|
||||
@ -1063,15 +1068,13 @@ png_write_cHRM_fixed(png_structp png_ptr, png_fixed_point white_x,
|
||||
png_fixed_point green_x, png_fixed_point green_y, png_fixed_point blue_x,
|
||||
png_fixed_point blue_y)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
PNG_cHRM;
|
||||
#endif
|
||||
png_byte buf[32];
|
||||
|
||||
png_debug(1, "in png_write_cHRM");
|
||||
|
||||
/* Each value is saved in 1/100,000ths */
|
||||
#if !defined(PNG_NO_CHECK_cHRM)
|
||||
#ifdef PNG_CHECK_cHRM_SUPPORTED
|
||||
if (png_check_cHRM_fixed(png_ptr, white_x, white_y, red_x, red_y,
|
||||
green_x, green_y, blue_x, blue_y))
|
||||
#endif
|
||||
@ -1094,15 +1097,13 @@ png_write_cHRM_fixed(png_structp png_ptr, png_fixed_point white_x,
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(PNG_WRITE_tRNS_SUPPORTED)
|
||||
#ifdef PNG_WRITE_tRNS_SUPPORTED
|
||||
/* Write the tRNS chunk */
|
||||
void /* PRIVATE */
|
||||
png_write_tRNS(png_structp png_ptr, png_bytep trans, png_color_16p tran,
|
||||
png_write_tRNS(png_structp png_ptr, png_bytep trans_alpha, png_color_16p tran,
|
||||
int num_trans, int color_type)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
PNG_tRNS;
|
||||
#endif
|
||||
png_byte buf[6];
|
||||
|
||||
png_debug(1, "in png_write_tRNS");
|
||||
@ -1115,7 +1116,7 @@ png_write_tRNS(png_structp png_ptr, png_bytep trans, png_color_16p tran,
|
||||
return;
|
||||
}
|
||||
/* Write the chunk out as it is */
|
||||
png_write_chunk(png_ptr, (png_bytep)png_tRNS, trans,
|
||||
png_write_chunk(png_ptr, (png_bytep)png_tRNS, trans_alpha,
|
||||
(png_size_t)num_trans);
|
||||
}
|
||||
else if (color_type == PNG_COLOR_TYPE_GRAY)
|
||||
@ -1151,14 +1152,12 @@ png_write_tRNS(png_structp png_ptr, png_bytep trans, png_color_16p tran,
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_WRITE_bKGD_SUPPORTED)
|
||||
#ifdef PNG_WRITE_bKGD_SUPPORTED
|
||||
/* Write the background chunk */
|
||||
void /* PRIVATE */
|
||||
png_write_bKGD(png_structp png_ptr, png_color_16p back, int color_type)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
PNG_bKGD;
|
||||
#endif
|
||||
png_byte buf[6];
|
||||
|
||||
png_debug(1, "in png_write_bKGD");
|
||||
@ -1166,7 +1165,7 @@ png_write_bKGD(png_structp png_ptr, png_color_16p back, int color_type)
|
||||
if (color_type == PNG_COLOR_TYPE_PALETTE)
|
||||
{
|
||||
if (
|
||||
#if defined(PNG_MNG_FEATURES_SUPPORTED)
|
||||
#ifdef PNG_MNG_FEATURES_SUPPORTED
|
||||
(png_ptr->num_palette ||
|
||||
(!(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE))) &&
|
||||
#endif
|
||||
@ -1205,14 +1204,12 @@ png_write_bKGD(png_structp png_ptr, png_color_16p back, int color_type)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_WRITE_hIST_SUPPORTED)
|
||||
#ifdef PNG_WRITE_hIST_SUPPORTED
|
||||
/* Write the histogram */
|
||||
void /* PRIVATE */
|
||||
png_write_hIST(png_structp png_ptr, png_uint_16p hist, int num_hist)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
PNG_hIST;
|
||||
#endif
|
||||
int i;
|
||||
png_byte buf[3];
|
||||
|
||||
@ -1282,7 +1279,7 @@ png_check_keyword(png_structp png_ptr, png_charp key, png_charpp new_key)
|
||||
if ((png_byte)*kp < 0x20 ||
|
||||
((png_byte)*kp > 0x7E && (png_byte)*kp < 0xA1))
|
||||
{
|
||||
#if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
|
||||
#ifdef PNG_STDIO_SUPPORTED
|
||||
char msg[40];
|
||||
|
||||
png_snprintf(msg, 40,
|
||||
@ -1354,7 +1351,6 @@ png_check_keyword(png_structp png_ptr, png_charp key, png_charpp new_key)
|
||||
if (key_len == 0)
|
||||
{
|
||||
png_free(png_ptr, *new_key);
|
||||
*new_key=NULL;
|
||||
png_warning(png_ptr, "Zero length keyword");
|
||||
}
|
||||
|
||||
@ -1369,15 +1365,13 @@ png_check_keyword(png_structp png_ptr, png_charp key, png_charpp new_key)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_WRITE_tEXt_SUPPORTED)
|
||||
#ifdef PNG_WRITE_tEXt_SUPPORTED
|
||||
/* Write a tEXt chunk */
|
||||
void /* PRIVATE */
|
||||
png_write_tEXt(png_structp png_ptr, png_charp key, png_charp text,
|
||||
png_size_t text_len)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
PNG_tEXt;
|
||||
#endif
|
||||
png_size_t key_len;
|
||||
png_charp new_key;
|
||||
|
||||
@ -1410,15 +1404,13 @@ png_write_tEXt(png_structp png_ptr, png_charp key, png_charp text,
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_WRITE_zTXt_SUPPORTED)
|
||||
#ifdef PNG_WRITE_zTXt_SUPPORTED
|
||||
/* Write a compressed text chunk */
|
||||
void /* PRIVATE */
|
||||
png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,
|
||||
png_size_t text_len, int compression)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
PNG_zTXt;
|
||||
#endif
|
||||
png_size_t key_len;
|
||||
char buf[1];
|
||||
png_charp new_key;
|
||||
@ -1470,15 +1462,13 @@ png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_WRITE_iTXt_SUPPORTED)
|
||||
#ifdef PNG_WRITE_iTXt_SUPPORTED
|
||||
/* Write an iTXt chunk */
|
||||
void /* PRIVATE */
|
||||
png_write_iTXt(png_structp png_ptr, int compression, png_charp key,
|
||||
png_charp lang, png_charp lang_key, png_charp text)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
PNG_iTXt;
|
||||
#endif
|
||||
png_size_t lang_len, key_len, lang_key_len, text_len;
|
||||
png_charp new_lang;
|
||||
png_charp new_key = NULL;
|
||||
@ -1559,15 +1549,13 @@ png_write_iTXt(png_structp png_ptr, int compression, png_charp key,
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_WRITE_oFFs_SUPPORTED)
|
||||
#ifdef PNG_WRITE_oFFs_SUPPORTED
|
||||
/* Write the oFFs chunk */
|
||||
void /* PRIVATE */
|
||||
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
|
||||
PNG_oFFs;
|
||||
#endif
|
||||
png_byte buf[9];
|
||||
|
||||
png_debug(1, "in png_write_oFFs");
|
||||
@ -1582,15 +1570,13 @@ png_write_oFFs(png_structp png_ptr, png_int_32 x_offset, png_int_32 y_offset,
|
||||
png_write_chunk(png_ptr, (png_bytep)png_oFFs, buf, (png_size_t)9);
|
||||
}
|
||||
#endif
|
||||
#if defined(PNG_WRITE_pCAL_SUPPORTED)
|
||||
#ifdef PNG_WRITE_pCAL_SUPPORTED
|
||||
/* Write the pCAL chunk (described in the PNG extensions document) */
|
||||
void /* PRIVATE */
|
||||
png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0,
|
||||
png_int_32 X1, int type, int nparams, png_charp units, png_charpp params)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
PNG_pCAL;
|
||||
#endif
|
||||
png_size_t purpose_len, units_len, total_len;
|
||||
png_uint_32p params_len;
|
||||
png_byte buf[10];
|
||||
@ -1609,7 +1595,7 @@ png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0,
|
||||
total_len = purpose_len + units_len + 10;
|
||||
|
||||
params_len = (png_uint_32p)png_malloc(png_ptr,
|
||||
(png_uint_32)(nparams * png_sizeof(png_uint_32)));
|
||||
(png_alloc_size_t)(nparams * png_sizeof(png_uint_32)));
|
||||
|
||||
/* Find the length of each parameter, making sure we don't count the
|
||||
null terminator for the last parameter. */
|
||||
@ -1645,42 +1631,23 @@ png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0,
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_WRITE_sCAL_SUPPORTED)
|
||||
#ifdef PNG_WRITE_sCAL_SUPPORTED
|
||||
/* Write the sCAL chunk */
|
||||
#if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
|
||||
#if defined(PNG_FLOATING_POINT_SUPPORTED) && defined(PNG_STDIO_SUPPORTED)
|
||||
void /* PRIVATE */
|
||||
png_write_sCAL(png_structp png_ptr, int unit, double width, double height)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
PNG_sCAL;
|
||||
#endif
|
||||
char buf[64];
|
||||
png_size_t total_len;
|
||||
|
||||
png_debug(1, "in png_write_sCAL");
|
||||
|
||||
buf[0] = (char)unit;
|
||||
#if defined(_WIN32_WCE)
|
||||
/* sprintf() function is not supported on WindowsCE */
|
||||
{
|
||||
wchar_t wc_buf[32];
|
||||
size_t wc_len;
|
||||
swprintf(wc_buf, TEXT("%12.12e"), width);
|
||||
wc_len = wcslen(wc_buf);
|
||||
WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + 1, wc_len, NULL, NULL);
|
||||
total_len = wc_len + 2;
|
||||
swprintf(wc_buf, TEXT("%12.12e"), height);
|
||||
wc_len = wcslen(wc_buf);
|
||||
WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + total_len, wc_len,
|
||||
NULL, NULL);
|
||||
total_len += wc_len;
|
||||
}
|
||||
#else
|
||||
png_snprintf(buf + 1, 63, "%12.12e", width);
|
||||
total_len = 1 + png_strlen(buf + 1) + 1;
|
||||
png_snprintf(buf + total_len, 64-total_len, "%12.12e", height);
|
||||
total_len += png_strlen(buf + total_len);
|
||||
#endif
|
||||
|
||||
png_debug1(3, "sCAL total length = %u", (unsigned int)total_len);
|
||||
png_write_chunk(png_ptr, (png_bytep)png_sCAL, (png_bytep)buf, total_len);
|
||||
@ -1691,9 +1658,7 @@ void /* PRIVATE */
|
||||
png_write_sCAL_s(png_structp png_ptr, int unit, png_charp width,
|
||||
png_charp height)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
PNG_sCAL;
|
||||
#endif
|
||||
png_byte buf[64];
|
||||
png_size_t wlen, hlen, total_len;
|
||||
|
||||
@ -1719,16 +1684,14 @@ png_write_sCAL_s(png_structp png_ptr, int unit, png_charp width,
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(PNG_WRITE_pHYs_SUPPORTED)
|
||||
#ifdef PNG_WRITE_pHYs_SUPPORTED
|
||||
/* Write the pHYs chunk */
|
||||
void /* PRIVATE */
|
||||
png_write_pHYs(png_structp png_ptr, png_uint_32 x_pixels_per_unit,
|
||||
png_uint_32 y_pixels_per_unit,
|
||||
int unit_type)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
PNG_pHYs;
|
||||
#endif
|
||||
png_byte buf[9];
|
||||
|
||||
png_debug(1, "in png_write_pHYs");
|
||||
@ -1744,16 +1707,14 @@ png_write_pHYs(png_structp png_ptr, png_uint_32 x_pixels_per_unit,
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_WRITE_tIME_SUPPORTED)
|
||||
#ifdef PNG_WRITE_tIME_SUPPORTED
|
||||
/* Write the tIME chunk. Use either png_convert_from_struct_tm()
|
||||
* or png_convert_from_time_t(), or fill in the structure yourself.
|
||||
*/
|
||||
void /* PRIVATE */
|
||||
png_write_tIME(png_structp png_ptr, png_timep mod_time)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
PNG_tIME;
|
||||
#endif
|
||||
png_byte buf[7];
|
||||
|
||||
png_debug(1, "in png_write_tIME");
|
||||
@ -1846,7 +1807,6 @@ void /* PRIVATE */
|
||||
png_write_start_row(png_structp png_ptr)
|
||||
{
|
||||
#ifdef PNG_WRITE_INTERLACING_SUPPORTED
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
/* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
|
||||
|
||||
/* Start of interlace block */
|
||||
@ -1860,7 +1820,6 @@ png_write_start_row(png_structp png_ptr)
|
||||
|
||||
/* Offset to next interlace block in the y direction */
|
||||
int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
|
||||
#endif
|
||||
#endif
|
||||
|
||||
png_size_t buf_size;
|
||||
@ -1872,48 +1831,47 @@ png_write_start_row(png_structp png_ptr)
|
||||
|
||||
/* Set up row buffer */
|
||||
png_ptr->row_buf = (png_bytep)png_malloc(png_ptr,
|
||||
(png_uint_32)buf_size);
|
||||
(png_alloc_size_t)buf_size);
|
||||
png_ptr->row_buf[0] = PNG_FILTER_VALUE_NONE;
|
||||
|
||||
#ifndef PNG_NO_WRITE_FILTER
|
||||
#ifdef PNG_WRITE_FILTER_SUPPORTED
|
||||
/* Set up filtering buffer, if using this filter */
|
||||
if (png_ptr->do_filter & PNG_FILTER_SUB)
|
||||
{
|
||||
png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
|
||||
(png_uint_32)(png_ptr->rowbytes + 1));
|
||||
(png_alloc_size_t)(png_ptr->rowbytes + 1));
|
||||
png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
|
||||
}
|
||||
|
||||
/* We only need to keep the previous row if we are using one of these. */
|
||||
if (png_ptr->do_filter & (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH))
|
||||
{
|
||||
/* Set up previous row buffer */
|
||||
png_ptr->prev_row = (png_bytep)png_malloc(png_ptr,
|
||||
(png_uint_32)buf_size);
|
||||
png_memset(png_ptr->prev_row, 0, buf_size);
|
||||
/* Set up previous row buffer */
|
||||
png_ptr->prev_row = (png_bytep)png_calloc(png_ptr,
|
||||
(png_alloc_size_t)buf_size);
|
||||
|
||||
if (png_ptr->do_filter & PNG_FILTER_UP)
|
||||
{
|
||||
png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
|
||||
(png_uint_32)(png_ptr->rowbytes + 1));
|
||||
(png_size_t)(png_ptr->rowbytes + 1));
|
||||
png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
|
||||
}
|
||||
|
||||
if (png_ptr->do_filter & PNG_FILTER_AVG)
|
||||
{
|
||||
png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
|
||||
(png_uint_32)(png_ptr->rowbytes + 1));
|
||||
(png_alloc_size_t)(png_ptr->rowbytes + 1));
|
||||
png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
|
||||
}
|
||||
|
||||
if (png_ptr->do_filter & PNG_FILTER_PAETH)
|
||||
{
|
||||
png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
|
||||
(png_uint_32)(png_ptr->rowbytes + 1));
|
||||
(png_size_t)(png_ptr->rowbytes + 1));
|
||||
png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
|
||||
}
|
||||
}
|
||||
#endif /* PNG_NO_WRITE_FILTER */
|
||||
#endif /* PNG_WRITE_FILTER_SUPPORTED */
|
||||
|
||||
#ifdef PNG_WRITE_INTERLACING_SUPPORTED
|
||||
/* If interlaced, we need to set up width and height of pass */
|
||||
@ -1947,7 +1905,6 @@ void /* PRIVATE */
|
||||
png_write_finish_row(png_structp png_ptr)
|
||||
{
|
||||
#ifdef PNG_WRITE_INTERLACING_SUPPORTED
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
/* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
|
||||
|
||||
/* Start of interlace block */
|
||||
@ -1961,7 +1918,6 @@ png_write_finish_row(png_structp png_ptr)
|
||||
|
||||
/* Offset to next interlace block in the y direction */
|
||||
int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
|
||||
#endif
|
||||
#endif
|
||||
|
||||
int ret;
|
||||
@ -2055,7 +2011,7 @@ png_write_finish_row(png_structp png_ptr)
|
||||
png_ptr->zstream.data_type = Z_BINARY;
|
||||
}
|
||||
|
||||
#if defined(PNG_WRITE_INTERLACING_SUPPORTED)
|
||||
#ifdef PNG_WRITE_INTERLACING_SUPPORTED
|
||||
/* Pick out the correct pixels for the interlace pass.
|
||||
* The basic idea here is to go through the row with a source
|
||||
* pointer and a destination pointer (sp and dp), and copy the
|
||||
@ -2066,7 +2022,6 @@ png_write_finish_row(png_structp png_ptr)
|
||||
void /* PRIVATE */
|
||||
png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
/* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
|
||||
|
||||
/* Start of interlace block */
|
||||
@ -2074,16 +2029,11 @@ png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
|
||||
|
||||
/* Offset to next interlace block */
|
||||
int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
|
||||
#endif
|
||||
|
||||
png_debug(1, "in png_do_write_interlace");
|
||||
|
||||
/* We don't have to do anything on the last pass (6) */
|
||||
#if defined(PNG_USELESS_TESTS_SUPPORTED)
|
||||
if (row != NULL && row_info != NULL && pass < 6)
|
||||
#else
|
||||
if (pass < 6)
|
||||
#endif
|
||||
{
|
||||
/* Each pixel depth is handled separately */
|
||||
switch (row_info->pixel_depth)
|
||||
@ -2239,7 +2189,7 @@ void /* PRIVATE */
|
||||
png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
|
||||
{
|
||||
png_bytep best_row;
|
||||
#ifndef PNG_NO_WRITE_FILTER
|
||||
#ifdef PNG_WRITE_FILTER_SUPPORTED
|
||||
png_bytep prev_row, row_buf;
|
||||
png_uint_32 mins, bpp;
|
||||
png_byte filter_to_do = png_ptr->do_filter;
|
||||
@ -2250,13 +2200,21 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
|
||||
|
||||
png_debug(1, "in png_write_find_filter");
|
||||
|
||||
#ifndef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
|
||||
if (png_ptr->row_number == 0 && filter_to_do == PNG_ALL_FILTERS)
|
||||
{
|
||||
/* These will never be selected so we need not test them. */
|
||||
filter_to_do &= ~(PNG_FILTER_UP | PNG_FILTER_PAETH);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Find out how many bytes offset each pixel is */
|
||||
bpp = (row_info->pixel_depth + 7) >> 3;
|
||||
|
||||
prev_row = png_ptr->prev_row;
|
||||
#endif
|
||||
best_row = png_ptr->row_buf;
|
||||
#ifndef PNG_NO_WRITE_FILTER
|
||||
#ifdef PNG_WRITE_FILTER_SUPPORTED
|
||||
row_buf = best_row;
|
||||
mins = PNG_MAXSUM;
|
||||
|
||||
@ -2299,7 +2257,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
|
||||
sum += (v < 128) ? v : 256 - v;
|
||||
}
|
||||
|
||||
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
|
||||
#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
|
||||
if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
|
||||
{
|
||||
png_uint_32 sumhi, sumlo;
|
||||
@ -2363,7 +2321,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
|
||||
png_uint_32 i;
|
||||
int v;
|
||||
|
||||
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
|
||||
#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
|
||||
/* We temporarily increase the "minimum sum" by the factor we
|
||||
* would reduce the sum of this filter, so that we can do the
|
||||
* early exit comparison without scaling the sum each time.
|
||||
@ -2416,7 +2374,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
|
||||
break;
|
||||
}
|
||||
|
||||
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
|
||||
#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
|
||||
if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
|
||||
{
|
||||
int j;
|
||||
@ -2477,7 +2435,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
|
||||
int v;
|
||||
|
||||
|
||||
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
|
||||
#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
|
||||
if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
|
||||
{
|
||||
int j;
|
||||
@ -2519,7 +2477,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
|
||||
break;
|
||||
}
|
||||
|
||||
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
|
||||
#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
|
||||
if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
|
||||
{
|
||||
int j;
|
||||
@ -2582,7 +2540,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
|
||||
png_uint_32 i;
|
||||
int v;
|
||||
|
||||
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
|
||||
#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
|
||||
if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
|
||||
{
|
||||
int j;
|
||||
@ -2631,7 +2589,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
|
||||
break;
|
||||
}
|
||||
|
||||
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
|
||||
#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
|
||||
if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
|
||||
{
|
||||
int j;
|
||||
@ -2715,7 +2673,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
|
||||
png_uint_32 i;
|
||||
int v;
|
||||
|
||||
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
|
||||
#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
|
||||
if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
|
||||
{
|
||||
int j;
|
||||
@ -2796,7 +2754,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
|
||||
break;
|
||||
}
|
||||
|
||||
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
|
||||
#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
|
||||
if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
|
||||
{
|
||||
int j;
|
||||
@ -2832,13 +2790,13 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
|
||||
best_row = png_ptr->paeth_row;
|
||||
}
|
||||
}
|
||||
#endif /* PNG_NO_WRITE_FILTER */
|
||||
#endif /* PNG_WRITE_FILTER_SUPPORTED */
|
||||
/* Do the actual writing of the filtered row data from the chosen filter. */
|
||||
|
||||
png_write_filtered_row(png_ptr, best_row);
|
||||
|
||||
#ifndef PNG_NO_WRITE_FILTER
|
||||
#if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
|
||||
#ifdef PNG_WRITE_FILTER_SUPPORTED
|
||||
#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
|
||||
/* Save the type of filter we picked this time for future calculations */
|
||||
if (png_ptr->num_prev_filters > 0)
|
||||
{
|
||||
@ -2850,7 +2808,7 @@ png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
|
||||
png_ptr->prev_filters[j] = best_row[0];
|
||||
}
|
||||
#endif
|
||||
#endif /* PNG_NO_WRITE_FILTER */
|
||||
#endif /* PNG_WRITE_FILTER_SUPPORTED */
|
||||
}
|
||||
|
||||
|
||||
@ -2905,7 +2863,7 @@ png_write_filtered_row(png_structp png_ptr, png_bytep filtered_row)
|
||||
/* Finish row - updates counters and flushes zlib if last row */
|
||||
png_write_finish_row(png_ptr);
|
||||
|
||||
#if defined(PNG_WRITE_FLUSH_SUPPORTED)
|
||||
#ifdef PNG_WRITE_FLUSH_SUPPORTED
|
||||
png_ptr->flush_rows++;
|
||||
|
||||
if (png_ptr->flush_dist > 0 &&
|
||||
|
@ -25,6 +25,7 @@
|
||||
* Andrew Smith
|
||||
* Federico Mena-Quintero <federico@novell.com>
|
||||
* Bobby Holley <bobbyholley@gmail.com>
|
||||
* Glenn Randers-Pehrson <glennrp@gmail.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
@ -128,15 +129,17 @@ void nsPNGDecoder::CreateFrame(png_uint_32 x_offset, png_uint_32 y_offset,
|
||||
nsresult rv = mImage->AppendFrame(x_offset, y_offset, width, height, format,
|
||||
&mImageData, &imageDataLength);
|
||||
if (NS_FAILED(rv))
|
||||
longjmp(mPNG->jmpbuf, 5); // NS_ERROR_OUT_OF_MEMORY
|
||||
longjmp(png_jmpbuf(mPNG), 5); // NS_ERROR_OUT_OF_MEMORY
|
||||
|
||||
mFrameRect.x = x_offset;
|
||||
mFrameRect.y = y_offset;
|
||||
mFrameRect.width = width;
|
||||
mFrameRect.height = height;
|
||||
|
||||
#ifdef PNG_APNG_SUPPORTED
|
||||
if (png_get_valid(mPNG, mInfo, PNG_INFO_acTL))
|
||||
SetAnimFrameInfo();
|
||||
#endif
|
||||
|
||||
PRUint32 numFrames = 0;
|
||||
mImage->GetNumFrames(&numFrames);
|
||||
@ -145,14 +148,15 @@ void nsPNGDecoder::CreateFrame(png_uint_32 x_offset, png_uint_32 y_offset,
|
||||
mObserver->OnStartFrame(nsnull, numFrames - 1);
|
||||
|
||||
PR_LOG(gPNGDecoderAccountingLog, PR_LOG_DEBUG,
|
||||
("PNGDecoderAccounting: nsPNGDecoder::CreateFrame -- created image"
|
||||
" frame with %dx%d pixels in container %p",
|
||||
("PNGDecoderAccounting: nsPNGDecoder::CreateFrame -- created "
|
||||
"image frame with %dx%d pixels in container %p",
|
||||
width, height,
|
||||
mImage.get ()));
|
||||
|
||||
mFrameHasNoAlpha = PR_TRUE;
|
||||
}
|
||||
|
||||
#ifdef PNG_APNG_SUPPORTED
|
||||
// set timeout and frame disposal method for the current frame
|
||||
void nsPNGDecoder::SetAnimFrameInfo()
|
||||
{
|
||||
@ -199,11 +203,13 @@ void nsPNGDecoder::SetAnimFrameInfo()
|
||||
/*else // 'over' is the default
|
||||
mImage->SetFrameBlendMethod(numFrames - 1, imgIContainer::kBlendOver); */
|
||||
}
|
||||
#endif
|
||||
|
||||
// set timeout and frame disposal method for the current frame
|
||||
void nsPNGDecoder::EndImageFrame()
|
||||
{
|
||||
PRUint32 numFrames = 0;
|
||||
PRUint32 numFrames = 1;
|
||||
#ifdef PNG_APNG_SUPPORTED
|
||||
mImage->GetNumFrames(&numFrames);
|
||||
|
||||
// We can't use mPNG->num_frames_read as it may be one ahead.
|
||||
@ -222,6 +228,7 @@ void nsPNGDecoder::EndImageFrame()
|
||||
mObserver->OnDataAvailable(nsnull, curFrame == numFrames - 1,
|
||||
&mFrameRect);
|
||||
}
|
||||
#endif
|
||||
|
||||
mImage->EndFrameDecode(numFrames - 1);
|
||||
if (mObserver)
|
||||
@ -280,9 +287,8 @@ NS_IMETHODIMP nsPNGDecoder::Init(imgIContainer *aImage,
|
||||
|
||||
mPNG = png_create_read_struct(PNG_LIBPNG_VER_STRING,
|
||||
NULL, error_callback, warning_callback);
|
||||
if (!mPNG) {
|
||||
if (!mPNG)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
mInfo = png_create_info_struct(mPNG);
|
||||
if (!mInfo) {
|
||||
@ -292,9 +298,9 @@ NS_IMETHODIMP nsPNGDecoder::Init(imgIContainer *aImage,
|
||||
|
||||
#if defined(PNG_HANDLE_AS_UNKNOWN_SUPPORTED)
|
||||
/* Ignore unused chunks */
|
||||
if (gfxPlatform::GetCMSMode() == eCMSMode_Off) {
|
||||
if (gfxPlatform::GetCMSMode() == eCMSMode_Off)
|
||||
png_set_keep_unknown_chunks(mPNG, 1, color_chunks, 2);
|
||||
}
|
||||
|
||||
png_set_keep_unknown_chunks(mPNG, 1, unused_chunks,
|
||||
(int)sizeof(unused_chunks)/5);
|
||||
#endif
|
||||
@ -385,7 +391,7 @@ nsPNGDecoder::Write(const char *aBuffer, PRUint32 aCount)
|
||||
else {
|
||||
|
||||
// libpng uses setjmp/longjmp for error handling - set the buffer
|
||||
if (setjmp(mPNG->jmpbuf)) {
|
||||
if (setjmp(png_jmpbuf(mPNG))) {
|
||||
png_destroy_read_struct(&mPNG, &mInfo, NULL);
|
||||
goto error;
|
||||
}
|
||||
@ -566,13 +572,14 @@ info_callback(png_structp png_ptr, png_infop info_ptr)
|
||||
|
||||
/* Are we too big? */
|
||||
if (width > MOZ_PNG_MAX_DIMENSION || height > MOZ_PNG_MAX_DIMENSION)
|
||||
longjmp(decoder->mPNG->jmpbuf, 1);
|
||||
longjmp(png_jmpbuf(decoder->mPNG), 1);
|
||||
|
||||
// Set the size and notify that the container is set up
|
||||
rv = decoder->mImage->SetSize(width, height);
|
||||
if (NS_FAILED(rv)) {
|
||||
longjmp(decoder->mPNG->jmpbuf, 5); // NS_ERROR_UNEXPECTED
|
||||
}
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
longjmp(png_jmpbuf(decoder->mPNG), 5); // NS_ERROR_UNEXPECTED
|
||||
|
||||
if (decoder->mObserver)
|
||||
decoder->mObserver->OnStartContainer(nsnull, decoder->mImage);
|
||||
|
||||
@ -596,12 +603,12 @@ info_callback(png_structp png_ptr, png_infop info_ptr)
|
||||
((int)trans_values->red > sample_max ||
|
||||
(int)trans_values->green > sample_max ||
|
||||
(int)trans_values->blue > sample_max)))
|
||||
{
|
||||
/* clear the tRNS valid flag and release tRNS memory */
|
||||
png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
|
||||
}
|
||||
{
|
||||
/* clear the tRNS valid flag and release tRNS memory */
|
||||
png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
|
||||
}
|
||||
else
|
||||
png_set_expand(png_ptr);
|
||||
png_set_expand(png_ptr);
|
||||
}
|
||||
|
||||
if (bit_depth == 16)
|
||||
@ -682,14 +689,18 @@ info_callback(png_structp png_ptr, png_infop info_ptr)
|
||||
else if (channels == 2 || channels == 4)
|
||||
decoder->format = gfxASurface::ImageFormatARGB32;
|
||||
|
||||
#ifdef PNG_APNG_SUPPORTED
|
||||
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_acTL))
|
||||
png_set_progressive_frame_fn(png_ptr, frame_info_callback, NULL);
|
||||
|
||||
if (png_get_first_frame_is_hidden(png_ptr, info_ptr)) {
|
||||
decoder->mFrameIsHidden = PR_TRUE;
|
||||
} else {
|
||||
#endif
|
||||
decoder->CreateFrame(0, 0, width, height, decoder->format);
|
||||
#ifdef PNG_APNG_SUPPORTED
|
||||
}
|
||||
#endif
|
||||
|
||||
if (decoder->mTransform &&
|
||||
(channels <= 2 || interlace_type == PNG_INTERLACE_ADAM7)) {
|
||||
@ -697,7 +708,7 @@ info_callback(png_structp png_ptr, png_infop info_ptr)
|
||||
decoder->mCMSLine =
|
||||
(PRUint8 *)nsMemory::Alloc(bpp[channels] * width);
|
||||
if (!decoder->mCMSLine) {
|
||||
longjmp(decoder->mPNG->jmpbuf, 5); // NS_ERROR_OUT_OF_MEMORY
|
||||
longjmp(png_jmpbuf(decoder->mPNG), 5); // NS_ERROR_OUT_OF_MEMORY
|
||||
}
|
||||
}
|
||||
|
||||
@ -706,7 +717,7 @@ info_callback(png_structp png_ptr, png_infop info_ptr)
|
||||
decoder->interlacebuf = (PRUint8 *)nsMemory::Alloc(channels *
|
||||
width * height);
|
||||
if (!decoder->interlacebuf) {
|
||||
longjmp(decoder->mPNG->jmpbuf, 5); // NS_ERROR_OUT_OF_MEMORY
|
||||
longjmp(png_jmpbuf(decoder->mPNG), 5); // NS_ERROR_OUT_OF_MEMORY
|
||||
}
|
||||
}
|
||||
|
||||
@ -857,6 +868,7 @@ row_callback(png_structp png_ptr, png_bytep new_row,
|
||||
void
|
||||
frame_info_callback(png_structp png_ptr, png_uint_32 frame_num)
|
||||
{
|
||||
#ifdef PNG_APNG_SUPPORTED
|
||||
png_uint_32 x_offset, y_offset;
|
||||
PRInt32 width, height;
|
||||
|
||||
@ -875,6 +887,7 @@ frame_info_callback(png_structp png_ptr, png_uint_32 frame_num)
|
||||
height = png_get_next_frame_height(png_ptr, decoder->mInfo);
|
||||
|
||||
decoder->CreateFrame(x_offset, y_offset, width, height, decoder->format);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
@ -898,10 +911,12 @@ end_callback(png_structp png_ptr, png_infop info_ptr)
|
||||
// We shouldn't get here if we've hit an error
|
||||
NS_ABORT_IF_FALSE(!decoder->mError, "Finishing up PNG but hit error!");
|
||||
|
||||
#ifdef PNG_APNG_SUPPORTED
|
||||
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_acTL)) {
|
||||
PRInt32 num_plays = png_get_num_plays(png_ptr, info_ptr);
|
||||
decoder->mImage->SetLoopCount(num_plays - 1);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Send final notifications
|
||||
decoder->NotifyDone(/* aSuccess = */ PR_TRUE);
|
||||
@ -912,7 +927,7 @@ void
|
||||
error_callback(png_structp png_ptr, png_const_charp error_msg)
|
||||
{
|
||||
PR_LOG(gPNGLog, PR_LOG_ERROR, ("libpng error: %s\n", error_msg));
|
||||
longjmp(png_ptr->jmpbuf, 1);
|
||||
longjmp(png_jmpbuf(png_ptr), 1);
|
||||
}
|
||||
|
||||
|
||||
|
@ -23,6 +23,7 @@
|
||||
* Brett Wilson <brettw@gmail.com>
|
||||
* Stuart Parmenter <pavlov@pavlov.net>
|
||||
* Justin Dolske <dolske@mozilla.com>
|
||||
* Glenn Randers-Pehrson <glennrp@gmail.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
@ -77,12 +78,13 @@ nsPNGEncoder::~nsPNGEncoder()
|
||||
// See also modules/libimg/png/libpng.txt
|
||||
|
||||
NS_IMETHODIMP nsPNGEncoder::InitFromData(const PRUint8* aData,
|
||||
PRUint32 aLength, // (unused, req'd by JS)
|
||||
PRUint32 aWidth,
|
||||
PRUint32 aHeight,
|
||||
PRUint32 aStride,
|
||||
PRUint32 aInputFormat,
|
||||
const nsAString& aOutputOptions)
|
||||
PRUint32 aLength, // (unused,
|
||||
// req'd by JS)
|
||||
PRUint32 aWidth,
|
||||
PRUint32 aHeight,
|
||||
PRUint32 aStride,
|
||||
PRUint32 aInputFormat,
|
||||
const nsAString& aOutputOptions)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
@ -90,7 +92,8 @@ NS_IMETHODIMP nsPNGEncoder::InitFromData(const PRUint8* aData,
|
||||
if (!NS_SUCCEEDED(rv))
|
||||
return rv;
|
||||
|
||||
rv = AddImageFrame(aData, aLength, aWidth, aHeight, aStride, aInputFormat, aOutputOptions);
|
||||
rv = AddImageFrame(aData, aLength, aWidth, aHeight, aStride,
|
||||
aInputFormat, aOutputOptions);
|
||||
if (!NS_SUCCEEDED(rv))
|
||||
return rv;
|
||||
|
||||
@ -127,15 +130,18 @@ NS_IMETHODIMP nsPNGEncoder::StartImageEncode(PRUint32 aWidth,
|
||||
nsresult rv = ParseOptions(aOutputOptions, &useTransparency, &skipFirstFrame,
|
||||
&numFrames, &numPlays, nsnull, nsnull,
|
||||
nsnull, nsnull, nsnull);
|
||||
if (rv != NS_OK) { return rv; }
|
||||
if (rv != NS_OK)
|
||||
return rv;
|
||||
|
||||
if (numFrames > 1) {
|
||||
#ifdef PNG_APNG_SUPPORTED
|
||||
if (numFrames > 1)
|
||||
mIsAnimation = PR_TRUE;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// initialize
|
||||
mPNG = png_create_write_struct(PNG_LIBPNG_VER_STRING,
|
||||
png_voidp_NULL,
|
||||
nsnull,
|
||||
ErrorCallback,
|
||||
ErrorCallback);
|
||||
if (! mPNG)
|
||||
@ -167,12 +173,13 @@ NS_IMETHODIMP nsPNGEncoder::StartImageEncode(PRUint32 aWidth,
|
||||
mImageBufferUsed = 0;
|
||||
|
||||
// set our callback for libpng to give us the data
|
||||
png_set_write_fn(mPNG, this, WriteCallback, NULL);
|
||||
png_set_write_fn(mPNG, this, WriteCallback, nsnull);
|
||||
|
||||
// include alpha?
|
||||
int colorType;
|
||||
if ((aInputFormat == INPUT_FORMAT_HOSTARGB ||
|
||||
aInputFormat == INPUT_FORMAT_RGBA) && useTransparency)
|
||||
aInputFormat == INPUT_FORMAT_RGBA) &&
|
||||
useTransparency)
|
||||
colorType = PNG_COLOR_TYPE_RGB_ALPHA;
|
||||
else
|
||||
colorType = PNG_COLOR_TYPE_RGB;
|
||||
@ -181,10 +188,12 @@ NS_IMETHODIMP nsPNGEncoder::StartImageEncode(PRUint32 aWidth,
|
||||
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT,
|
||||
PNG_FILTER_TYPE_DEFAULT);
|
||||
|
||||
#ifdef PNG_APNG_SUPPORTED
|
||||
if (mIsAnimation) {
|
||||
png_set_first_frame_is_hidden(mPNG, mPNGinfo, skipFirstFrame);
|
||||
png_set_acTL(mPNG, mPNGinfo, numFrames, numPlays);
|
||||
}
|
||||
#endif
|
||||
|
||||
// XXX: support PLTE, gAMA, tRNS, bKGD?
|
||||
|
||||
@ -195,7 +204,8 @@ NS_IMETHODIMP nsPNGEncoder::StartImageEncode(PRUint32 aWidth,
|
||||
|
||||
|
||||
NS_IMETHODIMP nsPNGEncoder::AddImageFrame(const PRUint8* aData,
|
||||
PRUint32 aLength, // (unused, req'd by JS)
|
||||
PRUint32 aLength, // (unused,
|
||||
// req'd by JS)
|
||||
PRUint32 aWidth,
|
||||
PRUint32 aHeight,
|
||||
PRUint32 aStride,
|
||||
@ -204,8 +214,13 @@ NS_IMETHODIMP nsPNGEncoder::AddImageFrame(const PRUint8* aData,
|
||||
{
|
||||
PRBool useTransparency= PR_TRUE;
|
||||
PRUint32 delay_ms = 500;
|
||||
#ifdef PNG_APNG_SUPPORTED
|
||||
PRUint32 dispose_op = PNG_DISPOSE_OP_NONE;
|
||||
PRUint32 blend_op = PNG_BLEND_OP_SOURCE;
|
||||
#else
|
||||
PRUint32 dispose_op;
|
||||
PRUint32 blend_op;
|
||||
#endif
|
||||
PRUint32 x_offset = 0, y_offset = 0;
|
||||
|
||||
// must be initialized
|
||||
@ -232,21 +247,26 @@ NS_IMETHODIMP nsPNGEncoder::AddImageFrame(const PRUint8* aData,
|
||||
nsresult rv = ParseOptions(aFrameOptions, &useTransparency, nsnull,
|
||||
nsnull, nsnull, &dispose_op, &blend_op,
|
||||
&delay_ms, &x_offset, &y_offset);
|
||||
if (rv != NS_OK) { return rv; }
|
||||
if (rv != NS_OK)
|
||||
return rv;
|
||||
|
||||
#ifdef PNG_APNG_SUPPORTED
|
||||
if (mIsAnimation) {
|
||||
// XXX the row pointers arg (#3) is unused, can it be removed?
|
||||
png_write_frame_head(mPNG, mPNGinfo, nsnull,
|
||||
aWidth, aHeight, x_offset, y_offset,
|
||||
delay_ms, 1000, dispose_op, blend_op);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Stride is the padded width of each row, so it better be longer (I'm afraid
|
||||
// people will not understand what stride means, so check it well)
|
||||
// Stride is the padded width of each row, so it better be longer
|
||||
// (I'm afraid people will not understand what stride means, so
|
||||
// check it well)
|
||||
if ((aInputFormat == INPUT_FORMAT_RGB &&
|
||||
aStride < aWidth * 3) ||
|
||||
((aInputFormat == INPUT_FORMAT_RGBA || aInputFormat == INPUT_FORMAT_HOSTARGB) &&
|
||||
aStride < aWidth * 4)) {
|
||||
aStride < aWidth * 3) ||
|
||||
((aInputFormat == INPUT_FORMAT_RGBA ||
|
||||
aInputFormat == INPUT_FORMAT_HOSTARGB) &&
|
||||
aStride < aWidth * 4)) {
|
||||
NS_WARNING("Invalid stride for InitFromData/AddImageFrame");
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
@ -254,7 +274,8 @@ NS_IMETHODIMP nsPNGEncoder::AddImageFrame(const PRUint8* aData,
|
||||
// write each row: if we add more input formats, we may want to
|
||||
// generalize the conversions
|
||||
if (aInputFormat == INPUT_FORMAT_HOSTARGB) {
|
||||
// PNG requires RGBA with post-multiplied alpha, so we need to convert
|
||||
// PNG requires RGBA with post-multiplied alpha, so we need to
|
||||
// convert
|
||||
PRUint8* row = new PRUint8[aWidth * 4];
|
||||
for (PRUint32 y = 0; y < aHeight; y ++) {
|
||||
ConvertHostARGBRow(&aData[y * aStride], row, aWidth, useTransparency);
|
||||
@ -283,9 +304,11 @@ NS_IMETHODIMP nsPNGEncoder::AddImageFrame(const PRUint8* aData,
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
#ifdef PNG_APNG_SUPPORTED
|
||||
if (mIsAnimation) {
|
||||
png_write_frame_tail(mPNG, mPNGinfo);
|
||||
}
|
||||
#endif
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@ -297,7 +320,8 @@ NS_IMETHODIMP nsPNGEncoder::EndImageEncode()
|
||||
if (mImageBuffer == nsnull)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
// EndImageEncode has already been called, or some error occurred earlier
|
||||
// EndImageEncode has already been called, or some error
|
||||
// occurred earlier
|
||||
if (!mPNG)
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
|
||||
@ -330,6 +354,7 @@ nsPNGEncoder::ParseOptions(const nsAString& aOptions,
|
||||
PRUint32* offsetX,
|
||||
PRUint32* offsetY)
|
||||
{
|
||||
#ifdef PNG_APNG_SUPPORTED
|
||||
// Make a copy of aOptions, because strtok() will modify it.
|
||||
nsCAutoString optionsCopy;
|
||||
optionsCopy.Assign(NS_ConvertUTF16toUTF8(aOptions));
|
||||
@ -338,16 +363,22 @@ nsPNGEncoder::ParseOptions(const nsAString& aOptions,
|
||||
while (char* token = nsCRT::strtok(options, ";", &options)) {
|
||||
// If there's an '=' character, split the token around it.
|
||||
char* equals = token, *value = nsnull;
|
||||
while(*equals != '=' && *equals) { ++equals; }
|
||||
if (*equals == '=') { value = equals + 1; }
|
||||
while(*equals != '=' && *equals) {
|
||||
++equals;
|
||||
}
|
||||
if (*equals == '=')
|
||||
value = equals + 1;
|
||||
|
||||
if (value) { *equals = '\0'; } // temporary null
|
||||
if (value)
|
||||
*equals = '\0'; // temporary null
|
||||
|
||||
// transparency=[yes|no|none]
|
||||
if (nsCRT::strcmp(token, "transparency") == 0 && useTransparency) {
|
||||
if (!value) { return NS_ERROR_INVALID_ARG; }
|
||||
if (!value)
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
if (nsCRT::strcmp(value, "none") == 0 || nsCRT::strcmp(value, "no") == 0) {
|
||||
if (nsCRT::strcmp(value, "none") == 0 ||
|
||||
nsCRT::strcmp(value, "no") == 0) {
|
||||
*useTransparency = PR_FALSE;
|
||||
} else if (nsCRT::strcmp(value, "yes") == 0) {
|
||||
*useTransparency = PR_TRUE;
|
||||
@ -356,8 +387,10 @@ nsPNGEncoder::ParseOptions(const nsAString& aOptions,
|
||||
}
|
||||
|
||||
// skipfirstframe=[yes|no]
|
||||
} else if (nsCRT::strcmp(token, "skipfirstframe") == 0 && skipFirstFrame) {
|
||||
if (!value) { return NS_ERROR_INVALID_ARG; }
|
||||
} else if (nsCRT::strcmp(token, "skipfirstframe") == 0 &&
|
||||
skipFirstFrame) {
|
||||
if (!value)
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
if (nsCRT::strcmp(value, "no") == 0) {
|
||||
*skipFirstFrame = PR_FALSE;
|
||||
@ -369,23 +402,31 @@ nsPNGEncoder::ParseOptions(const nsAString& aOptions,
|
||||
|
||||
// frames=#
|
||||
} else if (nsCRT::strcmp(token, "frames") == 0 && numFrames) {
|
||||
if (!value) { return NS_ERROR_INVALID_ARG; }
|
||||
if (!value)
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
if (PR_sscanf(value, "%u", numFrames) != 1) { return NS_ERROR_INVALID_ARG; }
|
||||
if (PR_sscanf(value, "%u", numFrames) != 1) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
// frames=0 is nonsense.
|
||||
if (*numFrames == 0) { return NS_ERROR_INVALID_ARG; }
|
||||
if (*numFrames == 0)
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
// plays=#
|
||||
} else if (nsCRT::strcmp(token, "plays") == 0 && numPlays) {
|
||||
if (!value) { return NS_ERROR_INVALID_ARG; }
|
||||
if (!value)
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
// plays=0 to loop forever, otherwise play sequence specified number of times
|
||||
if (PR_sscanf(value, "%u", numPlays) != 1) { return NS_ERROR_INVALID_ARG; }
|
||||
// plays=0 to loop forever, otherwise play sequence specified
|
||||
// number of times
|
||||
if (PR_sscanf(value, "%u", numPlays) != 1)
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
// dispose=[none|background|previous]
|
||||
} else if (nsCRT::strcmp(token, "dispose") == 0 && frameDispose) {
|
||||
if (!value) { return NS_ERROR_INVALID_ARG; }
|
||||
if (!value)
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
if (nsCRT::strcmp(value, "none") == 0) {
|
||||
*frameDispose = PNG_DISPOSE_OP_NONE;
|
||||
@ -399,7 +440,8 @@ nsPNGEncoder::ParseOptions(const nsAString& aOptions,
|
||||
|
||||
// blend=[source|over]
|
||||
} else if (nsCRT::strcmp(token, "blend") == 0 && frameBlend) {
|
||||
if (!value) { return NS_ERROR_INVALID_ARG; }
|
||||
if (!value)
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
if (nsCRT::strcmp(value, "source") == 0) {
|
||||
*frameBlend = PNG_BLEND_OP_SOURCE;
|
||||
@ -411,30 +453,37 @@ nsPNGEncoder::ParseOptions(const nsAString& aOptions,
|
||||
|
||||
// delay=# (in ms)
|
||||
} else if (nsCRT::strcmp(token, "delay") == 0 && frameDelay) {
|
||||
if (!value) { return NS_ERROR_INVALID_ARG; }
|
||||
if (!value)
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
if (PR_sscanf(value, "%u", frameDelay) != 1) { return NS_ERROR_INVALID_ARG; }
|
||||
if (PR_sscanf(value, "%u", frameDelay) != 1)
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
// xoffset=#
|
||||
} else if (nsCRT::strcmp(token, "xoffset") == 0 && offsetX) {
|
||||
if (!value) { return NS_ERROR_INVALID_ARG; }
|
||||
if (!value)
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
if (PR_sscanf(value, "%u", offsetX) != 1) { return NS_ERROR_INVALID_ARG; }
|
||||
if (PR_sscanf(value, "%u", offsetX) != 1)
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
// yoffset=#
|
||||
} else if (nsCRT::strcmp(token, "yoffset") == 0 && offsetY) {
|
||||
if (!value) { return NS_ERROR_INVALID_ARG; }
|
||||
if (!value)
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
if (PR_sscanf(value, "%u", offsetY) != 1) { return NS_ERROR_INVALID_ARG; }
|
||||
if (PR_sscanf(value, "%u", offsetY) != 1)
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
// unknown token name
|
||||
} else {
|
||||
} else
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
if (value) { *equals = '='; } // restore '=' so strtok doesn't get lost
|
||||
if (value)
|
||||
*equals = '='; // restore '=' so strtok doesn't get lost
|
||||
}
|
||||
|
||||
#endif
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -462,14 +511,17 @@ NS_IMETHODIMP nsPNGEncoder::Available(PRUint32 *_retval)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* [noscript] unsigned long read (in charPtr aBuf, in unsigned long aCount); */
|
||||
/* [noscript] unsigned long read (in charPtr aBuf,
|
||||
in unsigned long aCount); */
|
||||
NS_IMETHODIMP nsPNGEncoder::Read(char * aBuf, PRUint32 aCount,
|
||||
PRUint32 *_retval)
|
||||
{
|
||||
return ReadSegments(NS_CopySegmentToBuffer, aBuf, aCount, _retval);
|
||||
}
|
||||
|
||||
/* [noscript] unsigned long readSegments (in nsWriteSegmentFun aWriter, in voidPtr aClosure, in unsigned long aCount); */
|
||||
/* [noscript] unsigned long readSegments (in nsWriteSegmentFun aWriter,
|
||||
in voidPtr aClosure,
|
||||
in unsigned long aCount); */
|
||||
NS_IMETHODIMP nsPNGEncoder::ReadSegments(nsWriteSegmentFun aWriter,
|
||||
void *aClosure, PRUint32 aCount,
|
||||
PRUint32 *_retval)
|
||||
@ -482,9 +534,10 @@ NS_IMETHODIMP nsPNGEncoder::ReadSegments(nsWriteSegmentFun aWriter,
|
||||
|
||||
if (aCount > maxCount)
|
||||
aCount = maxCount;
|
||||
nsresult rv = aWriter(this, aClosure,
|
||||
reinterpret_cast<const char*>(mImageBuffer+mImageBufferReadPoint),
|
||||
0, aCount, _retval);
|
||||
nsresult rv =
|
||||
aWriter(this, aClosure,
|
||||
reinterpret_cast<const char*>(mImageBuffer+mImageBufferReadPoint),
|
||||
0, aCount, _retval);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
NS_ASSERTION(*_retval <= aCount, "bad write count");
|
||||
mImageBufferReadPoint += *_retval;
|
||||
@ -511,7 +564,8 @@ NS_IMETHODIMP nsPNGEncoder::IsNonBlocking(PRBool *_retval)
|
||||
|
||||
void
|
||||
nsPNGEncoder::ConvertHostARGBRow(const PRUint8* aSrc, PRUint8* aDest,
|
||||
PRUint32 aPixelWidth, PRBool aUseTransparency)
|
||||
PRUint32 aPixelWidth,
|
||||
PRBool aUseTransparency)
|
||||
{
|
||||
PRUint32 pixelStride = aUseTransparency ? 4 : 3;
|
||||
for (PRUint32 x = 0; x < aPixelWidth; x ++) {
|
||||
@ -553,10 +607,12 @@ nsPNGEncoder::StripAlpha(const PRUint8* aSrc, PRUint8* aDest,
|
||||
// nsPNGEncoder::ErrorCallback
|
||||
|
||||
void // static
|
||||
nsPNGEncoder::ErrorCallback(png_structp png_ptr, png_const_charp warning_msg)
|
||||
nsPNGEncoder::ErrorCallback(png_structp png_ptr,
|
||||
png_const_charp warning_msg)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
// XXX: these messages are probably useful callers... use nsIConsoleService?
|
||||
// XXX: these messages are probably useful callers...
|
||||
// use nsIConsoleService?
|
||||
PR_fprintf(PR_STDERR, "PNG Encoder: %s\n", warning_msg);;
|
||||
#endif
|
||||
}
|
||||
@ -565,7 +621,8 @@ nsPNGEncoder::ErrorCallback(png_structp png_ptr, png_const_charp warning_msg)
|
||||
// nsPNGEncoder::WriteCallback
|
||||
|
||||
void // static
|
||||
nsPNGEncoder::WriteCallback(png_structp png, png_bytep data, png_size_t size)
|
||||
nsPNGEncoder::WriteCallback(png_structp png, png_bytep data,
|
||||
png_size_t size)
|
||||
{
|
||||
nsPNGEncoder* that = static_cast<nsPNGEncoder*>(png_get_io_ptr(png));
|
||||
if (! that->mImageBuffer)
|
||||
|
@ -64,15 +64,15 @@ private:
|
||||
|
||||
protected:
|
||||
nsresult ParseOptions(const nsAString& aOptions,
|
||||
PRBool* useTransparency,
|
||||
PRBool* skipFirstFrame,
|
||||
PRUint32* numAnimatedFrames,
|
||||
PRUint32* numIterations,
|
||||
PRUint32* frameDispose,
|
||||
PRUint32* frameBlend,
|
||||
PRUint32* frameDelay,
|
||||
PRUint32* offsetX,
|
||||
PRUint32* offsetY);
|
||||
PRBool* useTransparency,
|
||||
PRBool* skipFirstFrame,
|
||||
PRUint32* numAnimatedFrames,
|
||||
PRUint32* numIterations,
|
||||
PRUint32* frameDispose,
|
||||
PRUint32* frameBlend,
|
||||
PRUint32* frameDelay,
|
||||
PRUint32* offsetX,
|
||||
PRUint32* offsetY);
|
||||
void ConvertHostARGBRow(const PRUint8* aSrc, PRUint8* aDest,
|
||||
PRUint32 aPixelWidth, PRBool aUseTransparency);
|
||||
void StripAlpha(const PRUint8* aSrc, PRUint8* aDest,
|
||||
|
Loading…
Reference in New Issue
Block a user