mirror of
https://github.com/davisking/dlib.git
synced 2024-11-01 10:14:53 +08:00
update libpng to version 1.6.37
This commit is contained in:
parent
23e506323a
commit
11101b6f4b
135
dlib/external/libpng/README
vendored
135
dlib/external/libpng/README
vendored
@ -1,15 +1,16 @@
|
||||
README for libpng version 1.6.7 - November 14, 2013 (shared library 16.0)
|
||||
See the note about version numbers near the top of png.h
|
||||
README for libpng version 1.6.37 - April 14, 2019
|
||||
=================================================
|
||||
|
||||
See the note about version numbers near the top of png.h.
|
||||
See INSTALL for instructions on how to install libpng.
|
||||
|
||||
Libpng comes in several distribution formats. Get libpng-*.tar.gz or
|
||||
libpng-*.tar.xz or if you want UNIX-style line endings in the text files,
|
||||
or lpng*.7z or lpng*.zip if you want DOS-style line endings.
|
||||
libpng-*.tar.xz or if you want UNIX-style line endings in the text
|
||||
files, or lpng*.7z or lpng*.zip if you want DOS-style line endings.
|
||||
|
||||
Version 0.89 was the first official release of libpng. Don't let the
|
||||
fact that it's the first release fool you. The libpng library has been in
|
||||
extensive use and testing since mid-1995. By late 1997 it had
|
||||
fact that it's the first release fool you. The libpng library has been
|
||||
in extensive use and testing since mid-1995. By late 1997 it had
|
||||
finally gotten to the stage where there hadn't been significant
|
||||
changes to the API in some time, and people have a bad feeling about
|
||||
libraries with versions < 1.0. Version 1.0.0 was released in
|
||||
@ -23,18 +24,25 @@ earlier versions if you are using a shared library. The type of the
|
||||
png_uint_32, which will affect shared-library applications that use
|
||||
this function.
|
||||
|
||||
To avoid problems with changes to the internals of png_info_struct,
|
||||
To avoid problems with changes to the internals of the png info_struct,
|
||||
new APIs have been made available in 0.95 to avoid direct application
|
||||
access to info_ptr. These functions are the png_set_<chunk> and
|
||||
png_get_<chunk> functions. These functions should be used when
|
||||
accessing/storing the info_struct data, rather than manipulating it
|
||||
directly, to avoid such problems in the future.
|
||||
|
||||
It is important to note that the APIs do not make current programs
|
||||
It is important to note that the APIs did not make current programs
|
||||
that access the info struct directly incompatible with the new
|
||||
library. However, it is strongly suggested that new programs use
|
||||
the new APIs (as shown in example.c and pngtest.c), and older programs
|
||||
be converted to the new format, to facilitate upgrades in the future.
|
||||
library, through libpng-1.2.x. In libpng-1.4.x, which was meant to
|
||||
be a transitional release, members of the png_struct and the
|
||||
info_struct can still be accessed, but the compiler will issue a
|
||||
warning about deprecated usage. Since libpng-1.5.0, direct access
|
||||
to these structs is not allowed, and the definitions of the structs
|
||||
reside in private pngstruct.h and pnginfo.h header files that are not
|
||||
accessible to applications. It is strongly suggested that new
|
||||
programs use the new APIs (as shown in example.c and pngtest.c), and
|
||||
older programs be converted to the new format, to facilitate upgrades
|
||||
in the future.
|
||||
****
|
||||
|
||||
Additions since 0.90 include the ability to compile libpng as a
|
||||
@ -53,88 +61,59 @@ the library action on the detection of chunk CRC errors. It is possible
|
||||
to set different actions based on whether the CRC error occurred in a
|
||||
critical or an ancillary chunk.
|
||||
|
||||
The changes made to the library, and bugs fixed are based on discussions
|
||||
on the PNG-implement mailing list and not on material submitted
|
||||
privately to Guy, Andreas, or Glenn. They will forward any good
|
||||
suggestions to the list.
|
||||
|
||||
For a detailed description on using libpng, read libpng-manual.txt. For
|
||||
examples of libpng in a program, see example.c and pngtest.c. For usage
|
||||
information and restrictions (what little they are) on libpng, see
|
||||
png.h. For a description on using zlib (the compression library used by
|
||||
libpng) and zlib's restrictions, see zlib.h
|
||||
For a detailed description on using libpng, read libpng-manual.txt.
|
||||
For examples of libpng in a program, see example.c and pngtest.c. For
|
||||
usage information and restrictions (what little they are) on libpng,
|
||||
see png.h. For a description on using zlib (the compression library
|
||||
used by libpng) and zlib's restrictions, see zlib.h
|
||||
|
||||
I have included a general makefile, as well as several machine and
|
||||
compiler specific ones, but you may have to modify one for your own needs.
|
||||
compiler specific ones, but you may have to modify one for your own
|
||||
needs.
|
||||
|
||||
You should use zlib 1.0.4 or later to run this, but it MAY work with
|
||||
versions as old as zlib 0.95. Even so, there are bugs in older zlib
|
||||
versions which can cause the output of invalid compression streams for
|
||||
some images. You will definitely need zlib 1.0.4 or later if you are
|
||||
taking advantage of the MS-DOS "far" structure allocation for the small
|
||||
and medium memory models. You should also note that zlib is a
|
||||
compression library that is useful for more things than just PNG files.
|
||||
You can use zlib as a drop-in replacement for fread() and fwrite() if
|
||||
you are so inclined.
|
||||
some images.
|
||||
|
||||
zlib should be available at the same place that libpng is, or at zlib.net.
|
||||
You should also note that zlib is a compression library that is useful
|
||||
for more things than just PNG files. You can use zlib as a drop-in
|
||||
replacement for fread() and fwrite(), if you are so inclined.
|
||||
|
||||
zlib should be available at the same place that libpng is, or at
|
||||
https://zlib.net.
|
||||
|
||||
You may also want a copy of the PNG specification. It is available
|
||||
as an RFC, a W3C Recommendation, and an ISO/IEC Standard. You can find
|
||||
these at http://www.libpng.org/pub/png/documents/
|
||||
these at http://www.libpng.org/pub/png/pngdocs.html .
|
||||
|
||||
This code is currently being archived at libpng.sf.net in the
|
||||
[DOWNLOAD] area, and at ftp://ftp.simplesystems.org. If you can't find it
|
||||
in any of those places, e-mail me, and I'll help you find it.
|
||||
This code is currently being archived at libpng.sourceforge.io in the
|
||||
[DOWNLOAD] area, and at http://libpng.download/src .
|
||||
|
||||
If you have any code changes, requests, problems, etc., please e-mail
|
||||
them to me. Also, I'd appreciate any make files or project files,
|
||||
and any modifications you needed to make to get libpng to compile,
|
||||
along with a #define variable to tell what compiler/system you are on.
|
||||
If you needed to add transformations to libpng, or wish libpng would
|
||||
provide the image in a different way, drop me a note (and code, if
|
||||
possible), so I can consider supporting the transformation.
|
||||
Finally, if you get any warning messages when compiling libpng
|
||||
(note: not zlib), and they are easy to fix, I'd appreciate the
|
||||
fix. Please mention "libpng" somewhere in the subject line. Thanks.
|
||||
|
||||
This release was created and will be supported by myself (of course
|
||||
based in a large way on Guy's and Andreas' earlier work), and the PNG
|
||||
This release, based in a large way on Glenn's, Guy's and Andreas'
|
||||
earlier work, was created and will be supported by myself and the PNG
|
||||
development group.
|
||||
|
||||
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
|
||||
to subscribe).
|
||||
|
||||
You can't reach Guy, the original libpng author, at the addresses
|
||||
given in previous versions of this document. He and Andreas will
|
||||
read mail addressed to the png-implement list, however.
|
||||
|
||||
Please do not send general questions about PNG. Send them to
|
||||
png-mng-misc at lists.sf.net (subscription required; visit
|
||||
Send general questions about the PNG specification to png-mng-misc
|
||||
at lists.sourceforge.net (subscription required; visit
|
||||
https://lists.sourceforge.net/lists/listinfo/png-mng-misc to
|
||||
subscribe). If you have a question about something
|
||||
in the PNG specification that is related to using libpng, send it
|
||||
to me. Send me any questions that start with "I was using libpng,
|
||||
and ...". If in doubt, send questions to me. I'll bounce them
|
||||
to others, if necessary.
|
||||
|
||||
Please do not send suggestions on how to change PNG. We have
|
||||
been discussing PNG for eighteen 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.
|
||||
subscribe).
|
||||
|
||||
Files in this distribution:
|
||||
|
||||
ANNOUNCE => Announcement of this version, with recent changes
|
||||
AUTHORS => List of contributing authors
|
||||
CHANGES => Description of changes between libpng versions
|
||||
KNOWNBUG => List of known bugs and deficiencies
|
||||
LICENSE => License to use and redistribute libpng
|
||||
README => This file
|
||||
TODO => Things not implemented in the current library
|
||||
Y2KINFO => Statement of Y2K compliance
|
||||
TRADEMARK => Trademark information
|
||||
example.c => Example code for using libpng functions
|
||||
libpng.3 => manual page for libpng (includes libpng-manual.txt)
|
||||
libpng-manual.txt => Description of libpng and its functions
|
||||
@ -166,18 +145,25 @@ Files in this distribution:
|
||||
pngwtran.c => Write data transformations
|
||||
pngwutil.c => Write utility functions
|
||||
arm => Contains optimized code for the ARM platform
|
||||
powerpc => Contains optimized code for the PowerPC platform
|
||||
contrib => Contributions
|
||||
arm-neon => Optimized code for ARM-NEON platform
|
||||
powerpc-vsx => Optimized code for POWERPC-VSX platform
|
||||
examples => Example programs
|
||||
gregbook => source code for PNG reading and writing, from
|
||||
Greg Roelofs' "PNG: The Definitive Guide",
|
||||
O'Reilly, 1999
|
||||
libtests => Test programs
|
||||
mips-msa => Optimized code for MIPS-MSA platform
|
||||
pngminim => Minimal decoder, encoder, and progressive decoder
|
||||
programs demonstrating use of pngusr.dfa
|
||||
pngminus => Simple pnm2png and png2pnm programs
|
||||
pngsuite => Test images
|
||||
testpngs
|
||||
tools => Various tools
|
||||
visupng => Contains a MSVC workspace for VisualPng
|
||||
visupng => Contains a MSVC workspace for VisualPng
|
||||
intel => Optimized code for INTEL-SSE2 platform
|
||||
mips => Optimized code for MIPS platform
|
||||
projects => Contains project files and workspaces for
|
||||
building a DLL
|
||||
owatcom => Contains a WATCOM project for building libpng
|
||||
@ -188,15 +174,10 @@ Files in this distribution:
|
||||
scripts => Directory containing scripts for building libpng:
|
||||
(see scripts/README.txt for the list of scripts)
|
||||
|
||||
Good luck, and happy coding.
|
||||
Good luck, and happy coding!
|
||||
|
||||
-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://www-mddsp.enel.ucalgary.ca/People/adilger/
|
||||
|
||||
-Guy Eric Schalnat (original author and former maintainer, 1995-1996)
|
||||
(formerly of Group 42, Inc)
|
||||
Internet: gschal at infinet.com
|
||||
* Cosmin Truta (current maintainer, since 2018)
|
||||
* Glenn Randers-Pehrson (former maintainer, 1998-2018)
|
||||
* Andreas Eric Dilger (former maintainer, 1996-1997)
|
||||
* Guy Eric Schalnat (original author and former maintainer, 1995-1996)
|
||||
(formerly of Group 42, Inc.)
|
||||
|
149
dlib/external/libpng/arm/palette_neon_intrinsics.c
vendored
Normal file
149
dlib/external/libpng/arm/palette_neon_intrinsics.c
vendored
Normal file
@ -0,0 +1,149 @@
|
||||
|
||||
/* palette_neon_intrinsics.c - NEON optimised palette expansion functions
|
||||
*
|
||||
* Copyright (c) 2018-2019 Cosmin Truta
|
||||
* Copyright (c) 2017-2018 Arm Holdings. All rights reserved.
|
||||
* Written by Richard Townsend <Richard.Townsend@arm.com>, February 2017.
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
* For conditions of distribution and use, see the disclaimer
|
||||
* and license in png.h
|
||||
*/
|
||||
|
||||
#include "../pngpriv.h"
|
||||
|
||||
#if PNG_ARM_NEON_IMPLEMENTATION == 1
|
||||
|
||||
#if defined(_MSC_VER) && defined(_M_ARM64)
|
||||
# include <arm64_neon.h>
|
||||
#else
|
||||
# include <arm_neon.h>
|
||||
#endif
|
||||
|
||||
/* Build an RGBA8 palette from the separate RGB and alpha palettes. */
|
||||
void
|
||||
png_riffle_palette_neon(png_structrp png_ptr)
|
||||
{
|
||||
png_const_colorp palette = png_ptr->palette;
|
||||
png_bytep riffled_palette = png_ptr->riffled_palette;
|
||||
png_const_bytep trans_alpha = png_ptr->trans_alpha;
|
||||
int num_trans = png_ptr->num_trans;
|
||||
int i;
|
||||
|
||||
png_debug(1, "in png_riffle_palette_neon");
|
||||
|
||||
/* Initially black, opaque. */
|
||||
uint8x16x4_t w = {{
|
||||
vdupq_n_u8(0x00),
|
||||
vdupq_n_u8(0x00),
|
||||
vdupq_n_u8(0x00),
|
||||
vdupq_n_u8(0xff),
|
||||
}};
|
||||
|
||||
/* First, riffle the RGB colours into an RGBA8 palette.
|
||||
* The alpha component is set to opaque for now.
|
||||
*/
|
||||
for (i = 0; i < 256; i += 16)
|
||||
{
|
||||
uint8x16x3_t v = vld3q_u8((png_const_bytep)(palette + i));
|
||||
w.val[0] = v.val[0];
|
||||
w.val[1] = v.val[1];
|
||||
w.val[2] = v.val[2];
|
||||
vst4q_u8(riffled_palette + (i << 2), w);
|
||||
}
|
||||
|
||||
/* Fix up the missing transparency values. */
|
||||
for (i = 0; i < num_trans; i++)
|
||||
riffled_palette[(i << 2) + 3] = trans_alpha[i];
|
||||
}
|
||||
|
||||
/* Expands a palettized row into RGBA8. */
|
||||
int
|
||||
png_do_expand_palette_rgba8_neon(png_structrp png_ptr, png_row_infop row_info,
|
||||
png_const_bytep row, png_bytepp ssp, png_bytepp ddp)
|
||||
{
|
||||
png_uint_32 row_width = row_info->width;
|
||||
const png_uint_32 *riffled_palette =
|
||||
(const png_uint_32 *)png_ptr->riffled_palette;
|
||||
const png_int_32 pixels_per_chunk = 4;
|
||||
int i;
|
||||
|
||||
png_debug(1, "in png_do_expand_palette_rgba8_neon");
|
||||
|
||||
if (row_width < pixels_per_chunk)
|
||||
return 0;
|
||||
|
||||
/* This function originally gets the last byte of the output row.
|
||||
* The NEON part writes forward from a given position, so we have
|
||||
* to seek this back by 4 pixels x 4 bytes.
|
||||
*/
|
||||
*ddp = *ddp - ((pixels_per_chunk * sizeof(png_uint_32)) - 1);
|
||||
|
||||
for (i = 0; i < row_width; i += pixels_per_chunk)
|
||||
{
|
||||
uint32x4_t cur;
|
||||
png_bytep sp = *ssp - i, dp = *ddp - (i << 2);
|
||||
cur = vld1q_dup_u32 (riffled_palette + *(sp - 3));
|
||||
cur = vld1q_lane_u32(riffled_palette + *(sp - 2), cur, 1);
|
||||
cur = vld1q_lane_u32(riffled_palette + *(sp - 1), cur, 2);
|
||||
cur = vld1q_lane_u32(riffled_palette + *(sp - 0), cur, 3);
|
||||
vst1q_u32((void *)dp, cur);
|
||||
}
|
||||
if (i != row_width)
|
||||
{
|
||||
/* Remove the amount that wasn't processed. */
|
||||
i -= pixels_per_chunk;
|
||||
}
|
||||
|
||||
/* Decrement output pointers. */
|
||||
*ssp = *ssp - i;
|
||||
*ddp = *ddp - (i << 2);
|
||||
return i;
|
||||
}
|
||||
|
||||
/* Expands a palettized row into RGB8. */
|
||||
int
|
||||
png_do_expand_palette_rgb8_neon(png_structrp png_ptr, png_row_infop row_info,
|
||||
png_const_bytep row, png_bytepp ssp, png_bytepp ddp)
|
||||
{
|
||||
png_uint_32 row_width = row_info->width;
|
||||
png_const_bytep palette = (png_const_bytep)png_ptr->palette;
|
||||
const png_uint_32 pixels_per_chunk = 8;
|
||||
int i;
|
||||
|
||||
png_debug(1, "in png_do_expand_palette_rgb8_neon");
|
||||
|
||||
if (row_width <= pixels_per_chunk)
|
||||
return 0;
|
||||
|
||||
/* Seeking this back by 8 pixels x 3 bytes. */
|
||||
*ddp = *ddp - ((pixels_per_chunk * sizeof(png_color)) - 1);
|
||||
|
||||
for (i = 0; i < row_width; i += pixels_per_chunk)
|
||||
{
|
||||
uint8x8x3_t cur;
|
||||
png_bytep sp = *ssp - i, dp = *ddp - ((i << 1) + i);
|
||||
cur = vld3_dup_u8(palette + sizeof(png_color) * (*(sp - 7)));
|
||||
cur = vld3_lane_u8(palette + sizeof(png_color) * (*(sp - 6)), cur, 1);
|
||||
cur = vld3_lane_u8(palette + sizeof(png_color) * (*(sp - 5)), cur, 2);
|
||||
cur = vld3_lane_u8(palette + sizeof(png_color) * (*(sp - 4)), cur, 3);
|
||||
cur = vld3_lane_u8(palette + sizeof(png_color) * (*(sp - 3)), cur, 4);
|
||||
cur = vld3_lane_u8(palette + sizeof(png_color) * (*(sp - 2)), cur, 5);
|
||||
cur = vld3_lane_u8(palette + sizeof(png_color) * (*(sp - 1)), cur, 6);
|
||||
cur = vld3_lane_u8(palette + sizeof(png_color) * (*(sp - 0)), cur, 7);
|
||||
vst3_u8((void *)dp, cur);
|
||||
}
|
||||
|
||||
if (i != row_width)
|
||||
{
|
||||
/* Remove the amount that wasn't processed. */
|
||||
i -= pixels_per_chunk;
|
||||
}
|
||||
|
||||
/* Decrement output pointers. */
|
||||
*ssp = *ssp - i;
|
||||
*ddp = *ddp - ((i << 1) + i);
|
||||
return i;
|
||||
}
|
||||
|
||||
#endif /* PNG_ARM_NEON_IMPLEMENTATION */
|
1598
dlib/external/libpng/png.c
vendored
1598
dlib/external/libpng/png.c
vendored
File diff suppressed because it is too large
Load Diff
1204
dlib/external/libpng/png.h
vendored
1204
dlib/external/libpng/png.h
vendored
File diff suppressed because it is too large
Load Diff
179
dlib/external/libpng/pngconf.h
vendored
179
dlib/external/libpng/pngconf.h
vendored
@ -1,56 +1,26 @@
|
||||
|
||||
/* pngconf.h - machine configurable file for libpng
|
||||
/* pngconf.h - machine-configurable file for libpng
|
||||
*
|
||||
* libpng version 1.6.7 - November 14, 2013
|
||||
* libpng version 1.6.37
|
||||
*
|
||||
* Copyright (c) 1998-2013 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.)
|
||||
* Copyright (c) 2018-2019 Cosmin Truta
|
||||
* Copyright (c) 1998-2002,2004,2006-2016,2018 Glenn Randers-Pehrson
|
||||
* Copyright (c) 1996-1997 Andreas Dilger
|
||||
* Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
* For conditions of distribution and use, see the disclaimer
|
||||
* and license in png.h
|
||||
*
|
||||
*/
|
||||
|
||||
/* Any machine specific code is near the front of this file, so if you
|
||||
* Any machine specific code is near the front of this file, so if you
|
||||
* are configuring libpng for a machine, you may want to read the section
|
||||
* starting here down to where it starts to typedef png_color, png_text,
|
||||
* and png_info.
|
||||
*/
|
||||
|
||||
#ifdef _MSC_VER
|
||||
// Disable the following warnings for Visual Studio
|
||||
// This is a warning you get from visual studio 2005 about things in the standard C++
|
||||
// library being "deprecated." I checked the C++ standard and it doesn't say jack
|
||||
// about any of them (I checked the searchable PDF). So this warning is total Bunk.
|
||||
#pragma warning(disable : 4996)
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef PNGCONF_H
|
||||
#define PNGCONF_H
|
||||
|
||||
/* To do: Do all of this in scripts/pnglibconf.dfa */
|
||||
#ifdef PNG_SAFE_LIMITS_SUPPORTED
|
||||
# ifdef PNG_USER_WIDTH_MAX
|
||||
# undef PNG_USER_WIDTH_MAX
|
||||
# define PNG_USER_WIDTH_MAX 1000000L
|
||||
# endif
|
||||
# ifdef PNG_USER_HEIGHT_MAX
|
||||
# undef PNG_USER_HEIGHT_MAX
|
||||
# define PNG_USER_HEIGHT_MAX 1000000L
|
||||
# endif
|
||||
# ifdef PNG_USER_CHUNK_MALLOC_MAX
|
||||
# undef PNG_USER_CHUNK_MALLOC_MAX
|
||||
# define PNG_USER_CHUNK_MALLOC_MAX 4000000L
|
||||
# endif
|
||||
# ifdef PNG_USER_CHUNK_CACHE_MAX
|
||||
# undef PNG_USER_CHUNK_CACHE_MAX
|
||||
# define PNG_USER_CHUNK_CACHE_MAX 128
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef PNG_BUILDING_SYMBOL_TABLE /* else includes may cause problems */
|
||||
|
||||
/* From libpng 1.6.0 libpng requires an ANSI X3.159-1989 ("ISOC90") compliant C
|
||||
@ -88,14 +58,13 @@
|
||||
|
||||
#endif /* PNG_BUILDING_SYMBOL_TABLE */
|
||||
|
||||
/* Prior to 1.6.0 it was possible to turn off 'const' in declarations using
|
||||
* PNG_NO_CONST; this is no longer supported except for data declarations which
|
||||
* apparently still cause problems in 2011 on some compilers.
|
||||
/* Prior to 1.6.0, it was possible to turn off 'const' in declarations,
|
||||
* using PNG_NO_CONST. This is no longer supported.
|
||||
*/
|
||||
#define PNG_CONST const /* backward compatibility only */
|
||||
|
||||
/* This controls optimization of the reading of 16 and 32 bit values
|
||||
* from PNG files. It can be set on a per-app-file basis - it
|
||||
/* This controls optimization of the reading of 16-bit and 32-bit
|
||||
* values from PNG files. It can be set on a per-app-file basis: it
|
||||
* just changes whether a macro is used when the function is called.
|
||||
* The library builder sets the default; if read functions are not
|
||||
* built into the library the macro implementation is forced on.
|
||||
@ -158,7 +127,7 @@
|
||||
*
|
||||
* These cases only differ if the operating system does not use the C
|
||||
* calling convention, at present this just means the above cases
|
||||
* (x86 DOS/Windows sytems) and, even then, this does not apply to
|
||||
* (x86 DOS/Windows systems) and, even then, this does not apply to
|
||||
* Cygwin running on those systems.
|
||||
*
|
||||
* Note that the value must be defined in pnglibconf.h so that what
|
||||
@ -219,27 +188,27 @@
|
||||
* compatible with GCC or Visual C because of different calling conventions.
|
||||
*/
|
||||
# if PNG_API_RULE == 2
|
||||
/* If this line results in an error, either because __watcall is not
|
||||
* understood or because of a redefine just below you cannot use *this*
|
||||
* build of the library with the compiler you are using. *This* build was
|
||||
* build using Watcom and applications must also be built using Watcom!
|
||||
*/
|
||||
/* If this line results in an error, either because __watcall is not
|
||||
* understood or because of a redefine just below you cannot use *this*
|
||||
* build of the library with the compiler you are using. *This* build was
|
||||
* build using Watcom and applications must also be built using Watcom!
|
||||
*/
|
||||
# define PNGCAPI __watcall
|
||||
# endif
|
||||
|
||||
# if defined(__GNUC__) || (defined(_MSC_VER) && (_MSC_VER >= 800))
|
||||
# define PNGCAPI __cdecl
|
||||
# if PNG_API_RULE == 1
|
||||
/* If this line results in an error __stdcall is not understood and
|
||||
* PNG_API_RULE should not have been set to '1'.
|
||||
*/
|
||||
/* If this line results in an error __stdcall is not understood and
|
||||
* PNG_API_RULE should not have been set to '1'.
|
||||
*/
|
||||
# define PNGAPI __stdcall
|
||||
# endif
|
||||
# else
|
||||
/* An older compiler, or one not detected (erroneously) above,
|
||||
* if necessary override on the command line to get the correct
|
||||
* variants for the compiler.
|
||||
*/
|
||||
/* An older compiler, or one not detected (erroneously) above,
|
||||
* if necessary override on the command line to get the correct
|
||||
* variants for the compiler.
|
||||
*/
|
||||
# ifndef PNGCAPI
|
||||
# define PNGCAPI _cdecl
|
||||
# endif
|
||||
@ -256,10 +225,10 @@
|
||||
|
||||
# if (defined(_MSC_VER) && _MSC_VER < 800) ||\
|
||||
(defined(__BORLANDC__) && __BORLANDC__ < 0x500)
|
||||
/* older Borland and MSC
|
||||
* compilers used '__export' and required this to be after
|
||||
* the type.
|
||||
*/
|
||||
/* older Borland and MSC
|
||||
* compilers used '__export' and required this to be after
|
||||
* the type.
|
||||
*/
|
||||
# ifndef PNG_EXPORT_TYPE
|
||||
# define PNG_EXPORT_TYPE(type) type PNG_IMPEXP
|
||||
# endif
|
||||
@ -275,9 +244,9 @@
|
||||
# if (defined(__IBMC__) || defined(__IBMCPP__)) && defined(__OS2__)
|
||||
# define PNGAPI _System
|
||||
# else /* !Windows/x86 && !OS/2 */
|
||||
/* Use the defaults, or define PNG*API on the command line (but
|
||||
* this will have to be done for every compile!)
|
||||
*/
|
||||
/* Use the defaults, or define PNG*API on the command line (but
|
||||
* this will have to be done for every compile!)
|
||||
*/
|
||||
# endif /* other system, !OS/2 */
|
||||
#endif /* !Windows/x86 */
|
||||
|
||||
@ -298,7 +267,7 @@
|
||||
*/
|
||||
#ifndef PNG_IMPEXP
|
||||
# if defined(PNG_USE_DLL) && defined(PNG_DLL_IMPORT)
|
||||
/* This forces use of a DLL, disallowing static linking */
|
||||
/* This forces use of a DLL, disallowing static linking */
|
||||
# define PNG_IMPEXP PNG_DLL_IMPORT
|
||||
# endif
|
||||
|
||||
@ -326,11 +295,11 @@
|
||||
* table entries, so we discard it here. See the .dfn files in the
|
||||
* scripts directory.
|
||||
*/
|
||||
#ifndef PNG_EXPORTA
|
||||
|
||||
# define PNG_EXPORTA(ordinal, type, name, args, attributes)\
|
||||
PNG_FUNCTION(PNG_EXPORT_TYPE(type),(PNGAPI name),PNGARG(args), \
|
||||
extern attributes)
|
||||
#ifndef PNG_EXPORTA
|
||||
# define PNG_EXPORTA(ordinal, type, name, args, attributes) \
|
||||
PNG_FUNCTION(PNG_EXPORT_TYPE(type), (PNGAPI name), PNGARG(args), \
|
||||
PNG_LINKAGE_API attributes)
|
||||
#endif
|
||||
|
||||
/* ANSI-C (C90) does not permit a macro to be invoked with an empty argument,
|
||||
@ -338,7 +307,7 @@
|
||||
*/
|
||||
#define PNG_EMPTY /*empty list*/
|
||||
|
||||
#define PNG_EXPORT(ordinal, type, name, args)\
|
||||
#define PNG_EXPORT(ordinal, type, name, args) \
|
||||
PNG_EXPORTA(ordinal, type, name, args, PNG_EMPTY)
|
||||
|
||||
/* Use PNG_REMOVED to comment out a removed interface. */
|
||||
@ -370,7 +339,33 @@
|
||||
* version 1.2.41. Disabling these removes the warnings but may also produce
|
||||
* less efficient code.
|
||||
*/
|
||||
# if defined(__GNUC__)
|
||||
# if defined(__clang__) && defined(__has_attribute)
|
||||
/* Clang defines both __clang__ and __GNUC__. Check __clang__ first. */
|
||||
# if !defined(PNG_USE_RESULT) && __has_attribute(__warn_unused_result__)
|
||||
# define PNG_USE_RESULT __attribute__((__warn_unused_result__))
|
||||
# endif
|
||||
# if !defined(PNG_NORETURN) && __has_attribute(__noreturn__)
|
||||
# define PNG_NORETURN __attribute__((__noreturn__))
|
||||
# endif
|
||||
# if !defined(PNG_ALLOCATED) && __has_attribute(__malloc__)
|
||||
# define PNG_ALLOCATED __attribute__((__malloc__))
|
||||
# endif
|
||||
# if !defined(PNG_DEPRECATED) && __has_attribute(__deprecated__)
|
||||
# define PNG_DEPRECATED __attribute__((__deprecated__))
|
||||
# endif
|
||||
# if !defined(PNG_PRIVATE)
|
||||
# ifdef __has_extension
|
||||
# if __has_extension(attribute_unavailable_with_message)
|
||||
# define PNG_PRIVATE __attribute__((__unavailable__(\
|
||||
"This function is not exported by libpng.")))
|
||||
# endif
|
||||
# endif
|
||||
# endif
|
||||
# ifndef PNG_RESTRICT
|
||||
# define PNG_RESTRICT __restrict
|
||||
# endif
|
||||
|
||||
# elif defined(__GNUC__)
|
||||
# ifndef PNG_USE_RESULT
|
||||
# define PNG_USE_RESULT __attribute__((__warn_unused_result__))
|
||||
# endif
|
||||
@ -393,12 +388,12 @@
|
||||
__attribute__((__deprecated__))
|
||||
# endif
|
||||
# endif
|
||||
# if ((__GNUC__ != 3) || !defined(__GNUC_MINOR__) || (__GNUC_MINOR__ >= 1))
|
||||
# if ((__GNUC__ > 3) || !defined(__GNUC_MINOR__) || (__GNUC_MINOR__ >= 1))
|
||||
# ifndef PNG_RESTRICT
|
||||
# define PNG_RESTRICT __restrict
|
||||
# endif
|
||||
# endif /* __GNUC__ == 3.0 */
|
||||
# endif /* __GNUC__ >= 3 */
|
||||
# endif /* __GNUC__.__GNUC_MINOR__ > 3.0 */
|
||||
# endif /* __GNUC__ >= 3 */
|
||||
|
||||
# elif defined(_MSC_VER) && (_MSC_VER >= 1300)
|
||||
# ifndef PNG_USE_RESULT
|
||||
@ -428,7 +423,7 @@
|
||||
# ifndef PNG_RESTRICT
|
||||
# define PNG_RESTRICT __restrict
|
||||
# endif
|
||||
# endif /* _MSC_VER */
|
||||
# endif
|
||||
#endif /* PNG_PEDANTIC_WARNINGS */
|
||||
|
||||
#ifndef PNG_DEPRECATED
|
||||
@ -449,6 +444,7 @@
|
||||
#ifndef PNG_RESTRICT
|
||||
# define PNG_RESTRICT /* The C99 "restrict" feature */
|
||||
#endif
|
||||
|
||||
#ifndef PNG_FP_EXPORT /* A floating point API. */
|
||||
# ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
# define PNG_FP_EXPORT(ordinal, type, name, args)\
|
||||
@ -484,7 +480,7 @@
|
||||
#if CHAR_BIT == 8 && UCHAR_MAX == 255
|
||||
typedef unsigned char png_byte;
|
||||
#else
|
||||
# error "libpng requires 8 bit bytes"
|
||||
# error "libpng requires 8-bit bytes"
|
||||
#endif
|
||||
|
||||
#if INT_MIN == -32768 && INT_MAX == 32767
|
||||
@ -492,7 +488,7 @@
|
||||
#elif SHRT_MIN == -32768 && SHRT_MAX == 32767
|
||||
typedef short png_int_16;
|
||||
#else
|
||||
# error "libpng requires a signed 16 bit type"
|
||||
# error "libpng requires a signed 16-bit type"
|
||||
#endif
|
||||
|
||||
#if UINT_MAX == 65535
|
||||
@ -500,7 +496,7 @@
|
||||
#elif USHRT_MAX == 65535
|
||||
typedef unsigned short png_uint_16;
|
||||
#else
|
||||
# error "libpng requires an unsigned 16 bit type"
|
||||
# error "libpng requires an unsigned 16-bit type"
|
||||
#endif
|
||||
|
||||
#if INT_MIN < -2147483646 && INT_MAX > 2147483646
|
||||
@ -508,19 +504,21 @@
|
||||
#elif LONG_MIN < -2147483646 && LONG_MAX > 2147483646
|
||||
typedef long int png_int_32;
|
||||
#else
|
||||
# error "libpng requires a signed 32 bit (or more) type"
|
||||
# error "libpng requires a signed 32-bit (or more) type"
|
||||
#endif
|
||||
|
||||
#if UINT_MAX > 4294967294
|
||||
#if UINT_MAX > 4294967294U
|
||||
typedef unsigned int png_uint_32;
|
||||
#elif ULONG_MAX > 4294967294
|
||||
#elif ULONG_MAX > 4294967294U
|
||||
typedef unsigned long int png_uint_32;
|
||||
#else
|
||||
# error "libpng requires an unsigned 32 bit (or more) type"
|
||||
# error "libpng requires an unsigned 32-bit (or more) type"
|
||||
#endif
|
||||
|
||||
/* Prior to 1.6.0 it was possible to disable the use of size_t, 1.6.0, however,
|
||||
* requires an ISOC90 compiler and relies on consistent behavior of sizeof.
|
||||
/* Prior to 1.6.0, it was possible to disable the use of size_t and ptrdiff_t.
|
||||
* From 1.6.0 onwards, an ISO C90 compiler, as well as a standard-compliant
|
||||
* behavior of sizeof and ptrdiff_t are required.
|
||||
* The legacy typedefs are provided here for backwards compatibility.
|
||||
*/
|
||||
typedef size_t png_size_t;
|
||||
typedef ptrdiff_t png_ptrdiff_t;
|
||||
@ -541,13 +539,12 @@ typedef ptrdiff_t png_ptrdiff_t;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* png_alloc_size_t is guaranteed to be no smaller than png_size_t, and no
|
||||
* smaller than png_uint_32. Casts from png_size_t or png_uint_32 to
|
||||
* png_alloc_size_t are not necessary; in fact, it is recommended not to use
|
||||
* them at all so that the compiler can complain when something turns out to be
|
||||
* problematic.
|
||||
/* png_alloc_size_t is guaranteed to be no smaller than size_t, and no smaller
|
||||
* than png_uint_32. Casts from size_t or png_uint_32 to png_alloc_size_t are
|
||||
* not necessary; in fact, it is recommended not to use them at all, so that
|
||||
* the compiler can complain when something turns out to be problematic.
|
||||
*
|
||||
* Casts in the other direction (from png_alloc_size_t to png_size_t or
|
||||
* Casts in the other direction (from png_alloc_size_t to size_t or
|
||||
* png_uint_32) should be explicitly applied; however, we do not expect to
|
||||
* encounter practical situations that require such conversions.
|
||||
*
|
||||
@ -557,7 +554,7 @@ typedef ptrdiff_t png_ptrdiff_t;
|
||||
#ifdef PNG_SMALL_SIZE_T
|
||||
typedef png_uint_32 png_alloc_size_t;
|
||||
#else
|
||||
typedef png_size_t png_alloc_size_t;
|
||||
typedef size_t png_alloc_size_t;
|
||||
#endif
|
||||
|
||||
/* Prior to 1.6.0 libpng offered limited support for Microsoft C compiler
|
||||
@ -593,8 +590,8 @@ typedef char * png_charp;
|
||||
typedef const char * png_const_charp;
|
||||
typedef png_fixed_point * png_fixed_point_p;
|
||||
typedef const png_fixed_point * png_const_fixed_point_p;
|
||||
typedef png_size_t * png_size_tp;
|
||||
typedef const png_size_t * png_const_size_tp;
|
||||
typedef size_t * png_size_tp;
|
||||
typedef const size_t * png_const_size_tp;
|
||||
|
||||
#ifdef PNG_STDIO_SUPPORTED
|
||||
typedef FILE * png_FILE_p;
|
||||
|
26
dlib/external/libpng/pngdebug.h
vendored
26
dlib/external/libpng/pngdebug.h
vendored
@ -1,11 +1,10 @@
|
||||
|
||||
/* pngdebug.h - Debugging macros for libpng, also used in pngtest.c
|
||||
*
|
||||
* Copyright (c) 1998-2011 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.)
|
||||
*
|
||||
* Last changed in libpng 1.5.0 [January 6, 2011]
|
||||
* Copyright (c) 2018 Cosmin Truta
|
||||
* Copyright (c) 1998-2002,2004,2006-2013 Glenn Randers-Pehrson
|
||||
* Copyright (c) 1996-1997 Andreas Dilger
|
||||
* Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
* For conditions of distribution and use, see the disclaimer
|
||||
@ -25,7 +24,7 @@
|
||||
* (actually ((void)0)).
|
||||
*
|
||||
* level: level of detail of message, starting at 0. A level 'n'
|
||||
* message is preceded by 'n' tab characters (not implemented
|
||||
* message is preceded by 'n' 3-space indentations (not implemented
|
||||
* on Microsoft compilers unless PNG_DEBUG_FILE is also
|
||||
* defined, to allow debug DLL compilation with no standard IO).
|
||||
* message: a printf(3) style text string. A trailing '\n' is added
|
||||
@ -77,32 +76,29 @@
|
||||
# endif /* PNG_DEBUG_FILE */
|
||||
|
||||
# if (PNG_DEBUG > 1)
|
||||
/* Note: ["%s"m PNG_STRING_NEWLINE] probably does not work on
|
||||
* non-ISO compilers
|
||||
*/
|
||||
# ifdef __STDC__
|
||||
# ifndef png_debug
|
||||
# define png_debug(l,m) \
|
||||
do { \
|
||||
int num_tabs=l; \
|
||||
fprintf(PNG_DEBUG_FILE,"%s"m PNG_STRING_NEWLINE,(num_tabs==1 ? "\t" : \
|
||||
(num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":"")))); \
|
||||
fprintf(PNG_DEBUG_FILE,"%s" m PNG_STRING_NEWLINE,(num_tabs==1 ? " " : \
|
||||
(num_tabs==2 ? " " : (num_tabs>2 ? " " : "")))); \
|
||||
} while (0)
|
||||
# endif
|
||||
# ifndef png_debug1
|
||||
# define png_debug1(l,m,p1) \
|
||||
do { \
|
||||
int num_tabs=l; \
|
||||
fprintf(PNG_DEBUG_FILE,"%s"m PNG_STRING_NEWLINE,(num_tabs==1 ? "\t" : \
|
||||
(num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1); \
|
||||
fprintf(PNG_DEBUG_FILE,"%s" m PNG_STRING_NEWLINE,(num_tabs==1 ? " " : \
|
||||
(num_tabs==2 ? " " : (num_tabs>2 ? " " : ""))),p1); \
|
||||
} while (0)
|
||||
# endif
|
||||
# ifndef png_debug2
|
||||
# define png_debug2(l,m,p1,p2) \
|
||||
do { \
|
||||
int num_tabs=l; \
|
||||
fprintf(PNG_DEBUG_FILE,"%s"m PNG_STRING_NEWLINE,(num_tabs==1 ? "\t" : \
|
||||
(num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1,p2); \
|
||||
fprintf(PNG_DEBUG_FILE,"%s" m PNG_STRING_NEWLINE,(num_tabs==1 ? " " : \
|
||||
(num_tabs==2 ? " " : (num_tabs>2 ? " " : ""))),p1,p2);\
|
||||
} while (0)
|
||||
# endif
|
||||
# else /* __STDC __ */
|
||||
|
195
dlib/external/libpng/pngerror.c
vendored
195
dlib/external/libpng/pngerror.c
vendored
@ -1,10 +1,10 @@
|
||||
|
||||
/* pngerror.c - stub functions for i/o and memory allocation
|
||||
*
|
||||
* Last changed in libpng 1.6.1 [March 28, 2013]
|
||||
* Copyright (c) 1998-2013 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.)
|
||||
* Copyright (c) 2018 Cosmin Truta
|
||||
* Copyright (c) 1998-2002,2004,2006-2017 Glenn Randers-Pehrson
|
||||
* Copyright (c) 1996-1997 Andreas Dilger
|
||||
* Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
* For conditions of distribution and use, see the disclaimer
|
||||
@ -26,8 +26,8 @@ static PNG_FUNCTION(void, png_default_error,PNGARG((png_const_structrp png_ptr,
|
||||
#ifdef PNG_WARNINGS_SUPPORTED
|
||||
static void /* PRIVATE */
|
||||
png_default_warning PNGARG((png_const_structrp png_ptr,
|
||||
png_const_charp warning_message));
|
||||
#endif /* PNG_WARNINGS_SUPPORTED */
|
||||
png_const_charp warning_message));
|
||||
#endif /* WARNINGS */
|
||||
|
||||
/* This function is called whenever there is a fatal error. This function
|
||||
* should not be changed. If there is a need to handle errors differently,
|
||||
@ -37,14 +37,14 @@ png_default_warning PNGARG((png_const_structrp png_ptr,
|
||||
#ifdef PNG_ERROR_TEXT_SUPPORTED
|
||||
PNG_FUNCTION(void,PNGAPI
|
||||
png_error,(png_const_structrp png_ptr, png_const_charp error_message),
|
||||
PNG_NORETURN)
|
||||
PNG_NORETURN)
|
||||
{
|
||||
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
|
||||
char msg[16];
|
||||
if (png_ptr != NULL)
|
||||
{
|
||||
if (png_ptr->flags&
|
||||
(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
|
||||
if ((png_ptr->flags &
|
||||
(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT)) != 0)
|
||||
{
|
||||
if (*error_message == PNG_LITERAL_SHARP)
|
||||
{
|
||||
@ -54,7 +54,7 @@ png_error,(png_const_structrp png_ptr, png_const_charp error_message),
|
||||
if (error_message[offset] == ' ')
|
||||
break;
|
||||
|
||||
if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
|
||||
if ((png_ptr->flags & PNG_FLAG_STRIP_ERROR_TEXT) != 0)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < offset - 1; i++)
|
||||
@ -65,18 +65,18 @@ png_error,(png_const_structrp png_ptr, png_const_charp error_message),
|
||||
|
||||
else
|
||||
error_message += offset;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
|
||||
{
|
||||
msg[0] = '0';
|
||||
msg[1] = '\0';
|
||||
error_message = msg;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
if ((png_ptr->flags & PNG_FLAG_STRIP_ERROR_TEXT) != 0)
|
||||
{
|
||||
msg[0] = '0';
|
||||
msg[1] = '\0';
|
||||
error_message = msg;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (png_ptr != NULL && png_ptr->error_fn != NULL)
|
||||
@ -103,14 +103,14 @@ png_err,(png_const_structrp png_ptr),PNG_NORETURN)
|
||||
use the default handler, which will not return. */
|
||||
png_default_error(png_ptr, "");
|
||||
}
|
||||
#endif /* PNG_ERROR_TEXT_SUPPORTED */
|
||||
#endif /* ERROR_TEXT */
|
||||
|
||||
/* Utility to safely appends strings to a buffer. This never errors out so
|
||||
* error checking is not required in the caller.
|
||||
*/
|
||||
size_t
|
||||
png_safecat(png_charp buffer, size_t bufsize, size_t pos,
|
||||
png_const_charp string)
|
||||
png_const_charp string)
|
||||
{
|
||||
if (buffer != NULL && pos < bufsize)
|
||||
{
|
||||
@ -131,7 +131,7 @@ png_safecat(png_charp buffer, size_t bufsize, size_t pos,
|
||||
*/
|
||||
png_charp
|
||||
png_format_number(png_const_charp start, png_charp end, int format,
|
||||
png_alloc_size_t number)
|
||||
png_alloc_size_t number)
|
||||
{
|
||||
int count = 0; /* number of digits output */
|
||||
int mincount = 1; /* minimum number required */
|
||||
@ -152,7 +152,7 @@ png_format_number(png_const_charp start, png_charp end, int format,
|
||||
case PNG_NUMBER_FORMAT_fixed:
|
||||
/* Needs five digits (the fraction) */
|
||||
mincount = 5;
|
||||
if (output || number % 10 != 0)
|
||||
if (output != 0 || number % 10 != 0)
|
||||
{
|
||||
*--end = digits[number % 10];
|
||||
output = 1;
|
||||
@ -163,7 +163,7 @@ png_format_number(png_const_charp start, png_charp end, int format,
|
||||
case PNG_NUMBER_FORMAT_02u:
|
||||
/* Expects at least 2 digits. */
|
||||
mincount = 2;
|
||||
/* FALL THROUGH */
|
||||
/* FALLTHROUGH */
|
||||
|
||||
case PNG_NUMBER_FORMAT_u:
|
||||
*--end = digits[number % 10];
|
||||
@ -173,7 +173,7 @@ png_format_number(png_const_charp start, png_charp end, int format,
|
||||
case PNG_NUMBER_FORMAT_02x:
|
||||
/* This format expects at least two digits */
|
||||
mincount = 2;
|
||||
/* FALL THROUGH */
|
||||
/* FALLTHROUGH */
|
||||
|
||||
case PNG_NUMBER_FORMAT_x:
|
||||
*--end = digits[number & 0xf];
|
||||
@ -189,13 +189,13 @@ png_format_number(png_const_charp start, png_charp end, int format,
|
||||
++count;
|
||||
|
||||
/* Float a fixed number here: */
|
||||
if (format == PNG_NUMBER_FORMAT_fixed) if (count == 5) if (end > start)
|
||||
if ((format == PNG_NUMBER_FORMAT_fixed) && (count == 5) && (end > start))
|
||||
{
|
||||
/* End of the fraction, but maybe nothing was output? In that case
|
||||
* drop the decimal point. If the number is a true zero handle that
|
||||
* here.
|
||||
*/
|
||||
if (output)
|
||||
if (output != 0)
|
||||
*--end = '.';
|
||||
else if (number == 0) /* and !output */
|
||||
*--end = '0';
|
||||
@ -219,8 +219,8 @@ png_warning(png_const_structrp png_ptr, png_const_charp warning_message)
|
||||
if (png_ptr != NULL)
|
||||
{
|
||||
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
|
||||
if (png_ptr->flags&
|
||||
(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
|
||||
if ((png_ptr->flags &
|
||||
(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT)) != 0)
|
||||
#endif
|
||||
{
|
||||
if (*warning_message == PNG_LITERAL_SHARP)
|
||||
@ -233,7 +233,7 @@ png_warning(png_const_structrp png_ptr, png_const_charp warning_message)
|
||||
}
|
||||
if (png_ptr != NULL && png_ptr->warning_fn != NULL)
|
||||
(*(png_ptr->warning_fn))(png_constcast(png_structrp,png_ptr),
|
||||
warning_message + offset);
|
||||
warning_message + offset);
|
||||
else
|
||||
png_default_warning(png_ptr, warning_message + offset);
|
||||
}
|
||||
@ -245,7 +245,7 @@ png_warning(png_const_structrp png_ptr, png_const_charp warning_message)
|
||||
*/
|
||||
void
|
||||
png_warning_parameter(png_warning_parameters p, int number,
|
||||
png_const_charp string)
|
||||
png_const_charp string)
|
||||
{
|
||||
if (number > 0 && number <= PNG_WARNING_PARAMETER_COUNT)
|
||||
(void)png_safecat(p[number-1], (sizeof p[number-1]), 0, string);
|
||||
@ -253,7 +253,7 @@ png_warning_parameter(png_warning_parameters p, int number,
|
||||
|
||||
void
|
||||
png_warning_parameter_unsigned(png_warning_parameters p, int number, int format,
|
||||
png_alloc_size_t value)
|
||||
png_alloc_size_t value)
|
||||
{
|
||||
char buffer[PNG_NUMBER_BUFFER_SIZE];
|
||||
png_warning_parameter(p, number, PNG_FORMAT_NUMBER(buffer, format, value));
|
||||
@ -261,7 +261,7 @@ png_warning_parameter_unsigned(png_warning_parameters p, int number, int format,
|
||||
|
||||
void
|
||||
png_warning_parameter_signed(png_warning_parameters p, int number, int format,
|
||||
png_int_32 value)
|
||||
png_int_32 value)
|
||||
{
|
||||
png_alloc_size_t u;
|
||||
png_charp str;
|
||||
@ -282,7 +282,7 @@ png_warning_parameter_signed(png_warning_parameters p, int number, int format,
|
||||
|
||||
void
|
||||
png_formatted_warning(png_const_structrp png_ptr, png_warning_parameters p,
|
||||
png_const_charp message)
|
||||
png_const_charp message)
|
||||
{
|
||||
/* The internal buffer is just 192 bytes - enough for all our messages,
|
||||
* overflow doesn't happen because this code checks! If someone figures
|
||||
@ -355,13 +355,13 @@ png_formatted_warning(png_const_structrp png_ptr, png_warning_parameters p,
|
||||
*/
|
||||
png_warning(png_ptr, msg);
|
||||
}
|
||||
#endif /* PNG_WARNINGS_SUPPORTED */
|
||||
#endif /* WARNINGS */
|
||||
|
||||
#ifdef PNG_BENIGN_ERRORS_SUPPORTED
|
||||
void PNGAPI
|
||||
png_benign_error(png_const_structrp png_ptr, png_const_charp error_message)
|
||||
{
|
||||
if (png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN)
|
||||
if ((png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN) != 0)
|
||||
{
|
||||
# ifdef PNG_READ_SUPPORTED
|
||||
if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0 &&
|
||||
@ -382,41 +382,54 @@ png_benign_error(png_const_structrp png_ptr, png_const_charp error_message)
|
||||
# endif
|
||||
png_error(png_ptr, error_message);
|
||||
}
|
||||
|
||||
# ifndef PNG_ERROR_TEXT_SUPPORTED
|
||||
PNG_UNUSED(error_message)
|
||||
# endif
|
||||
}
|
||||
|
||||
void /* PRIVATE */
|
||||
png_app_warning(png_const_structrp png_ptr, png_const_charp error_message)
|
||||
{
|
||||
if (png_ptr->flags & PNG_FLAG_APP_WARNINGS_WARN)
|
||||
png_warning(png_ptr, error_message);
|
||||
else
|
||||
png_error(png_ptr, error_message);
|
||||
if ((png_ptr->flags & PNG_FLAG_APP_WARNINGS_WARN) != 0)
|
||||
png_warning(png_ptr, error_message);
|
||||
else
|
||||
png_error(png_ptr, error_message);
|
||||
|
||||
# ifndef PNG_ERROR_TEXT_SUPPORTED
|
||||
PNG_UNUSED(error_message)
|
||||
# endif
|
||||
}
|
||||
|
||||
void /* PRIVATE */
|
||||
png_app_error(png_const_structrp png_ptr, png_const_charp error_message)
|
||||
{
|
||||
if (png_ptr->flags & PNG_FLAG_APP_ERRORS_WARN)
|
||||
png_warning(png_ptr, error_message);
|
||||
else
|
||||
png_error(png_ptr, error_message);
|
||||
if ((png_ptr->flags & PNG_FLAG_APP_ERRORS_WARN) != 0)
|
||||
png_warning(png_ptr, error_message);
|
||||
else
|
||||
png_error(png_ptr, error_message);
|
||||
|
||||
# ifndef PNG_ERROR_TEXT_SUPPORTED
|
||||
PNG_UNUSED(error_message)
|
||||
# endif
|
||||
}
|
||||
#endif /* BENIGN_ERRORS */
|
||||
|
||||
#define PNG_MAX_ERROR_TEXT 196 /* Currently limited by profile_error in png.c */
|
||||
#if defined(PNG_WARNINGS_SUPPORTED) || \
|
||||
(defined(PNG_READ_SUPPORTED) && defined(PNG_ERROR_TEXT_SUPPORTED))
|
||||
/* 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,
|
||||
* this is used to prefix the message. The message is limited in length
|
||||
* to 63 bytes, the name characters are output as hex digits wrapped in []
|
||||
* which is used to prefix the message. The message is limited in length
|
||||
* to 63 bytes. The name characters are output as hex digits wrapped in []
|
||||
* if the character is invalid.
|
||||
*/
|
||||
#define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
|
||||
static PNG_CONST char png_digit[16] = {
|
||||
static const char png_digit[16] = {
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
||||
'A', 'B', 'C', 'D', 'E', 'F'
|
||||
};
|
||||
|
||||
#define PNG_MAX_ERROR_TEXT 196 /* Currently limited be profile_error in png.c */
|
||||
#if defined(PNG_WARNINGS_SUPPORTED) || defined(PNG_ERROR_TEXT_SUPPORTED)
|
||||
static void /* PRIVATE */
|
||||
png_format_buffer(png_const_structrp png_ptr, png_charp buffer, png_const_charp
|
||||
error_message)
|
||||
@ -429,7 +442,7 @@ png_format_buffer(png_const_structrp png_ptr, png_charp buffer, png_const_charp
|
||||
int c = (int)(chunk_name >> ishift) & 0xff;
|
||||
|
||||
ishift -= 8;
|
||||
if (isnonalpha(c))
|
||||
if (isnonalpha(c) != 0)
|
||||
{
|
||||
buffer[iout++] = PNG_LITERAL_LEFT_SQUARE_BRACKET;
|
||||
buffer[iout++] = png_digit[(c & 0xf0) >> 4];
|
||||
@ -460,12 +473,12 @@ png_format_buffer(png_const_structrp png_ptr, png_charp buffer, png_const_charp
|
||||
buffer[iout] = '\0';
|
||||
}
|
||||
}
|
||||
#endif /* PNG_WARNINGS_SUPPORTED || PNG_ERROR_TEXT_SUPPORTED */
|
||||
#endif /* WARNINGS || ERROR_TEXT */
|
||||
|
||||
#if defined(PNG_READ_SUPPORTED) && defined(PNG_ERROR_TEXT_SUPPORTED)
|
||||
PNG_FUNCTION(void,PNGAPI
|
||||
png_chunk_error,(png_const_structrp png_ptr, png_const_charp error_message),
|
||||
PNG_NORETURN)
|
||||
PNG_NORETURN)
|
||||
{
|
||||
char msg[18+PNG_MAX_ERROR_TEXT];
|
||||
if (png_ptr == NULL)
|
||||
@ -477,7 +490,7 @@ png_chunk_error,(png_const_structrp png_ptr, png_const_charp error_message),
|
||||
png_error(png_ptr, msg);
|
||||
}
|
||||
}
|
||||
#endif /* PNG_READ_SUPPORTED && PNG_ERROR_TEXT_SUPPORTED */
|
||||
#endif /* READ && ERROR_TEXT */
|
||||
|
||||
#ifdef PNG_WARNINGS_SUPPORTED
|
||||
void PNGAPI
|
||||
@ -493,7 +506,7 @@ png_chunk_warning(png_const_structrp png_ptr, png_const_charp warning_message)
|
||||
png_warning(png_ptr, msg);
|
||||
}
|
||||
}
|
||||
#endif /* PNG_WARNINGS_SUPPORTED */
|
||||
#endif /* WARNINGS */
|
||||
|
||||
#ifdef PNG_READ_SUPPORTED
|
||||
#ifdef PNG_BENIGN_ERRORS_SUPPORTED
|
||||
@ -501,23 +514,31 @@ void PNGAPI
|
||||
png_chunk_benign_error(png_const_structrp png_ptr, png_const_charp
|
||||
error_message)
|
||||
{
|
||||
if (png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN)
|
||||
if ((png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN) != 0)
|
||||
png_chunk_warning(png_ptr, error_message);
|
||||
|
||||
else
|
||||
png_chunk_error(png_ptr, error_message);
|
||||
|
||||
# ifndef PNG_ERROR_TEXT_SUPPORTED
|
||||
PNG_UNUSED(error_message)
|
||||
# endif
|
||||
}
|
||||
#endif
|
||||
#endif /* PNG_READ_SUPPORTED */
|
||||
#endif /* READ */
|
||||
|
||||
void /* PRIVATE */
|
||||
png_chunk_report(png_const_structrp png_ptr, png_const_charp message, int error)
|
||||
{
|
||||
# ifndef PNG_WARNINGS_SUPPORTED
|
||||
PNG_UNUSED(message)
|
||||
# endif
|
||||
|
||||
/* This is always supported, but for just read or just write it
|
||||
* unconditionally does the right thing.
|
||||
*/
|
||||
# if defined(PNG_READ_SUPPORTED) && defined(PNG_WRITE_SUPPORTED)
|
||||
if (png_ptr->mode & PNG_IS_READ_STRUCT)
|
||||
if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0)
|
||||
# endif
|
||||
|
||||
# ifdef PNG_READ_SUPPORTED
|
||||
@ -531,7 +552,7 @@ png_chunk_report(png_const_structrp png_ptr, png_const_charp message, int error)
|
||||
# endif
|
||||
|
||||
# if defined(PNG_READ_SUPPORTED) && defined(PNG_WRITE_SUPPORTED)
|
||||
else if (!(png_ptr->mode & PNG_IS_READ_STRUCT))
|
||||
else if ((png_ptr->mode & PNG_IS_READ_STRUCT) == 0)
|
||||
# endif
|
||||
|
||||
# ifdef PNG_WRITE_SUPPORTED
|
||||
@ -552,15 +573,16 @@ png_fixed_error,(png_const_structrp png_ptr, png_const_charp name),PNG_NORETURN)
|
||||
{
|
||||
# define fixed_message "fixed point overflow in "
|
||||
# define fixed_message_ln ((sizeof fixed_message)-1)
|
||||
int iin;
|
||||
unsigned int iin;
|
||||
char msg[fixed_message_ln+PNG_MAX_ERROR_TEXT];
|
||||
memcpy(msg, fixed_message, fixed_message_ln);
|
||||
iin = 0;
|
||||
if (name != NULL) while (iin < (PNG_MAX_ERROR_TEXT-1) && name[iin] != 0)
|
||||
{
|
||||
msg[fixed_message_ln + iin] = name[iin];
|
||||
++iin;
|
||||
}
|
||||
if (name != NULL)
|
||||
while (iin < (PNG_MAX_ERROR_TEXT-1) && name[iin] != 0)
|
||||
{
|
||||
msg[fixed_message_ln + iin] = name[iin];
|
||||
++iin;
|
||||
}
|
||||
msg[fixed_message_ln + iin] = 0;
|
||||
png_error(png_ptr, msg);
|
||||
}
|
||||
@ -598,7 +620,7 @@ png_set_longjmp_fn(png_structrp png_ptr, png_longjmp_ptr longjmp_fn,
|
||||
else
|
||||
{
|
||||
png_ptr->jmp_buf_ptr = png_voidcast(jmp_buf *,
|
||||
png_malloc_warn(png_ptr, jmp_buf_size));
|
||||
png_malloc_warn(png_ptr, jmp_buf_size));
|
||||
|
||||
if (png_ptr->jmp_buf_ptr == NULL)
|
||||
return NULL; /* new NULL return on OOM */
|
||||
@ -687,7 +709,7 @@ png_free_jmpbuf(png_structrp png_ptr)
|
||||
*/
|
||||
static PNG_FUNCTION(void /* PRIVATE */,
|
||||
png_default_error,(png_const_structrp png_ptr, png_const_charp error_message),
|
||||
PNG_NORETURN)
|
||||
PNG_NORETURN)
|
||||
{
|
||||
#ifdef PNG_CONSOLE_IO_SUPPORTED
|
||||
#ifdef PNG_ERROR_NUMBERS_SUPPORTED
|
||||
@ -736,11 +758,20 @@ PNG_FUNCTION(void,PNGAPI
|
||||
png_longjmp,(png_const_structrp png_ptr, int val),PNG_NORETURN)
|
||||
{
|
||||
#ifdef PNG_SETJMP_SUPPORTED
|
||||
if (png_ptr && png_ptr->longjmp_fn && png_ptr->jmp_buf_ptr)
|
||||
if (png_ptr != NULL && png_ptr->longjmp_fn != NULL &&
|
||||
png_ptr->jmp_buf_ptr != NULL)
|
||||
png_ptr->longjmp_fn(*png_ptr->jmp_buf_ptr, val);
|
||||
#else
|
||||
PNG_UNUSED(png_ptr)
|
||||
PNG_UNUSED(val)
|
||||
#endif
|
||||
|
||||
/* Here if not setjmp support or if png_ptr is null. */
|
||||
/* If control reaches this point, png_longjmp() must not return. The only
|
||||
* choice is to terminate the whole process (or maybe the thread); to do
|
||||
* this the ANSI-C abort() function is used unless a different method is
|
||||
* implemented by overriding the default configuration setting for
|
||||
* PNG_ABORT().
|
||||
*/
|
||||
PNG_ABORT();
|
||||
}
|
||||
|
||||
@ -793,7 +824,7 @@ png_default_warning(png_const_structrp png_ptr, png_const_charp warning_message)
|
||||
#endif
|
||||
PNG_UNUSED(png_ptr) /* Make compiler happy */
|
||||
}
|
||||
#endif /* PNG_WARNINGS_SUPPORTED */
|
||||
#endif /* WARNINGS */
|
||||
|
||||
/* This function is called when the application wants to use another method
|
||||
* of handling errors and warnings. Note that the error function MUST NOT
|
||||
@ -850,11 +881,11 @@ png_set_strip_error_numbers(png_structrp png_ptr, png_uint_32 strip_mode)
|
||||
* possible to implement without setjmp support just so long as there is some
|
||||
* way to handle the error return here:
|
||||
*/
|
||||
PNG_FUNCTION(void /* PRIVATE */,
|
||||
png_safe_error,(png_structp png_nonconst_ptr, png_const_charp error_message),
|
||||
PNG_NORETURN)
|
||||
PNG_FUNCTION(void /* PRIVATE */, (PNGCBAPI
|
||||
png_safe_error),(png_structp png_nonconst_ptr, png_const_charp error_message),
|
||||
PNG_NORETURN)
|
||||
{
|
||||
const png_const_structrp png_ptr = png_nonconst_ptr;
|
||||
png_const_structrp png_ptr = png_nonconst_ptr;
|
||||
png_imagep image = png_voidcast(png_imagep, png_ptr->error_ptr);
|
||||
|
||||
/* An error is always logged here, overwriting anything (typically a warning)
|
||||
@ -875,7 +906,7 @@ png_safe_error,(png_structp png_nonconst_ptr, png_const_charp error_message),
|
||||
/* Missing longjmp buffer, the following is to help debugging: */
|
||||
{
|
||||
size_t pos = png_safecat(image->message, (sizeof image->message), 0,
|
||||
"bad longjmp: ");
|
||||
"bad longjmp: ");
|
||||
png_safecat(image->message, (sizeof image->message), pos,
|
||||
error_message);
|
||||
}
|
||||
@ -886,10 +917,10 @@ png_safe_error,(png_structp png_nonconst_ptr, png_const_charp error_message),
|
||||
}
|
||||
|
||||
#ifdef PNG_WARNINGS_SUPPORTED
|
||||
void /* PRIVATE */
|
||||
void /* PRIVATE */ PNGCBAPI
|
||||
png_safe_warning(png_structp png_nonconst_ptr, png_const_charp warning_message)
|
||||
{
|
||||
const png_const_structrp png_ptr = png_nonconst_ptr;
|
||||
png_const_structrp png_ptr = png_nonconst_ptr;
|
||||
png_imagep image = png_voidcast(png_imagep, png_ptr->error_ptr);
|
||||
|
||||
/* A warning is only logged if there is no prior warning or error. */
|
||||
@ -913,7 +944,7 @@ png_safe_execute(png_imagep image_in, int (*function)(png_voidp), png_voidp arg)
|
||||
saved_error_buf = image->opaque->error_buf;
|
||||
result = setjmp(safe_jmpbuf) == 0;
|
||||
|
||||
if (result)
|
||||
if (result != 0)
|
||||
{
|
||||
|
||||
image->opaque->error_buf = safe_jmpbuf;
|
||||
@ -923,10 +954,10 @@ png_safe_execute(png_imagep image_in, int (*function)(png_voidp), png_voidp arg)
|
||||
image->opaque->error_buf = saved_error_buf;
|
||||
|
||||
/* And do the cleanup prior to any failure return. */
|
||||
if (!result)
|
||||
if (result == 0)
|
||||
png_image_free(image);
|
||||
|
||||
return result;
|
||||
}
|
||||
#endif /* SIMPLIFIED READ/WRITE */
|
||||
#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
|
||||
#endif /* SIMPLIFIED READ || SIMPLIFIED_WRITE */
|
||||
#endif /* READ || WRITE */
|
||||
|
276
dlib/external/libpng/pngget.c
vendored
276
dlib/external/libpng/pngget.c
vendored
@ -1,10 +1,10 @@
|
||||
|
||||
/* pngget.c - retrieval of values from info struct
|
||||
*
|
||||
* Last changed in libpng 1.6.1 [March 28, 2013]
|
||||
* Copyright (c) 1998-2013 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.)
|
||||
* Copyright (c) 2018 Cosmin Truta
|
||||
* Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson
|
||||
* Copyright (c) 1996-1997 Andreas Dilger
|
||||
* Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
* For conditions of distribution and use, see the disclaimer
|
||||
@ -26,7 +26,7 @@ png_get_valid(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
return(0);
|
||||
}
|
||||
|
||||
png_size_t PNGAPI
|
||||
size_t PNGAPI
|
||||
png_get_rowbytes(png_const_structrp png_ptr, png_const_inforp info_ptr)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL)
|
||||
@ -116,7 +116,8 @@ png_get_x_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp
|
||||
info_ptr)
|
||||
{
|
||||
#ifdef PNG_pHYs_SUPPORTED
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_pHYs) != 0)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function",
|
||||
"png_get_x_pixels_per_meter");
|
||||
@ -124,6 +125,9 @@ png_get_x_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp
|
||||
if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER)
|
||||
return (info_ptr->x_pixels_per_unit);
|
||||
}
|
||||
#else
|
||||
PNG_UNUSED(png_ptr)
|
||||
PNG_UNUSED(info_ptr)
|
||||
#endif
|
||||
|
||||
return (0);
|
||||
@ -134,7 +138,8 @@ png_get_y_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp
|
||||
info_ptr)
|
||||
{
|
||||
#ifdef PNG_pHYs_SUPPORTED
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_pHYs) != 0)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function",
|
||||
"png_get_y_pixels_per_meter");
|
||||
@ -142,6 +147,9 @@ png_get_y_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp
|
||||
if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER)
|
||||
return (info_ptr->y_pixels_per_unit);
|
||||
}
|
||||
#else
|
||||
PNG_UNUSED(png_ptr)
|
||||
PNG_UNUSED(info_ptr)
|
||||
#endif
|
||||
|
||||
return (0);
|
||||
@ -151,7 +159,8 @@ png_uint_32 PNGAPI
|
||||
png_get_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp info_ptr)
|
||||
{
|
||||
#ifdef PNG_pHYs_SUPPORTED
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_pHYs) != 0)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "png_get_pixels_per_meter");
|
||||
|
||||
@ -159,6 +168,9 @@ png_get_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp info_ptr)
|
||||
info_ptr->x_pixels_per_unit == info_ptr->y_pixels_per_unit)
|
||||
return (info_ptr->x_pixels_per_unit);
|
||||
}
|
||||
#else
|
||||
PNG_UNUSED(png_ptr)
|
||||
PNG_UNUSED(info_ptr)
|
||||
#endif
|
||||
|
||||
return (0);
|
||||
@ -170,7 +182,8 @@ png_get_pixel_aspect_ratio(png_const_structrp png_ptr, png_const_inforp
|
||||
info_ptr)
|
||||
{
|
||||
#ifdef PNG_READ_pHYs_SUPPORTED
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_pHYs) != 0)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "png_get_aspect_ratio");
|
||||
|
||||
@ -193,10 +206,11 @@ png_get_pixel_aspect_ratio_fixed(png_const_structrp png_ptr,
|
||||
png_const_inforp info_ptr)
|
||||
{
|
||||
#ifdef PNG_READ_pHYs_SUPPORTED
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs)
|
||||
&& info_ptr->x_pixels_per_unit > 0 && info_ptr->y_pixels_per_unit > 0
|
||||
&& info_ptr->x_pixels_per_unit <= PNG_UINT_31_MAX
|
||||
&& info_ptr->y_pixels_per_unit <= PNG_UINT_31_MAX)
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_pHYs) != 0 &&
|
||||
info_ptr->x_pixels_per_unit > 0 && info_ptr->y_pixels_per_unit > 0 &&
|
||||
info_ptr->x_pixels_per_unit <= PNG_UINT_31_MAX &&
|
||||
info_ptr->y_pixels_per_unit <= PNG_UINT_31_MAX)
|
||||
{
|
||||
png_fixed_point res;
|
||||
|
||||
@ -206,7 +220,7 @@ png_get_pixel_aspect_ratio_fixed(png_const_structrp png_ptr,
|
||||
* range of 0..2^31-1; otherwise the cast might overflow.
|
||||
*/
|
||||
if (png_muldiv(&res, (png_int_32)info_ptr->y_pixels_per_unit, PNG_FP_1,
|
||||
(png_int_32)info_ptr->x_pixels_per_unit))
|
||||
(png_int_32)info_ptr->x_pixels_per_unit) != 0)
|
||||
return res;
|
||||
}
|
||||
#else
|
||||
@ -222,13 +236,17 @@ png_int_32 PNGAPI
|
||||
png_get_x_offset_microns(png_const_structrp png_ptr, png_const_inforp info_ptr)
|
||||
{
|
||||
#ifdef PNG_oFFs_SUPPORTED
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_oFFs) != 0)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "png_get_x_offset_microns");
|
||||
|
||||
if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER)
|
||||
return (info_ptr->x_offset);
|
||||
}
|
||||
#else
|
||||
PNG_UNUSED(png_ptr)
|
||||
PNG_UNUSED(info_ptr)
|
||||
#endif
|
||||
|
||||
return (0);
|
||||
@ -238,13 +256,17 @@ png_int_32 PNGAPI
|
||||
png_get_y_offset_microns(png_const_structrp png_ptr, png_const_inforp info_ptr)
|
||||
{
|
||||
#ifdef PNG_oFFs_SUPPORTED
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_oFFs) != 0)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "png_get_y_offset_microns");
|
||||
|
||||
if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER)
|
||||
return (info_ptr->y_offset);
|
||||
}
|
||||
#else
|
||||
PNG_UNUSED(png_ptr)
|
||||
PNG_UNUSED(info_ptr)
|
||||
#endif
|
||||
|
||||
return (0);
|
||||
@ -254,13 +276,17 @@ png_int_32 PNGAPI
|
||||
png_get_x_offset_pixels(png_const_structrp png_ptr, png_const_inforp info_ptr)
|
||||
{
|
||||
#ifdef PNG_oFFs_SUPPORTED
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_oFFs) != 0)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "png_get_x_offset_pixels");
|
||||
|
||||
if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL)
|
||||
return (info_ptr->x_offset);
|
||||
}
|
||||
#else
|
||||
PNG_UNUSED(png_ptr)
|
||||
PNG_UNUSED(info_ptr)
|
||||
#endif
|
||||
|
||||
return (0);
|
||||
@ -270,13 +296,17 @@ png_int_32 PNGAPI
|
||||
png_get_y_offset_pixels(png_const_structrp png_ptr, png_const_inforp info_ptr)
|
||||
{
|
||||
#ifdef PNG_oFFs_SUPPORTED
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_oFFs) != 0)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "png_get_y_offset_pixels");
|
||||
|
||||
if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL)
|
||||
return (info_ptr->y_offset);
|
||||
}
|
||||
#else
|
||||
PNG_UNUSED(png_ptr)
|
||||
PNG_UNUSED(info_ptr)
|
||||
#endif
|
||||
|
||||
return (0);
|
||||
@ -307,8 +337,8 @@ ppi_from_ppm(png_uint_32 ppm)
|
||||
*/
|
||||
png_fixed_point result;
|
||||
if (ppm <= PNG_UINT_31_MAX && png_muldiv(&result, (png_int_32)ppm, 127,
|
||||
5000))
|
||||
return result;
|
||||
5000) != 0)
|
||||
return (png_uint_32)result;
|
||||
|
||||
/* Overflow. */
|
||||
return 0;
|
||||
@ -337,7 +367,7 @@ png_get_y_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr)
|
||||
static png_fixed_point
|
||||
png_fixed_inches_from_microns(png_const_structrp png_ptr, png_int_32 microns)
|
||||
{
|
||||
/* Convert from metres * 1,000,000 to inches * 100,000, meters to
|
||||
/* Convert from meters * 1,000,000 to inches * 100,000, meters to
|
||||
* inches is simply *(100/2.54), so we want *(10/2.54) == 500/127.
|
||||
* Notice that this can overflow - a warning is output and 0 is
|
||||
* returned.
|
||||
@ -393,7 +423,8 @@ png_get_pHYs_dpi(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
{
|
||||
png_uint_32 retval = 0;
|
||||
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_pHYs) != 0)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "pHYs");
|
||||
|
||||
@ -424,12 +455,12 @@ png_get_pHYs_dpi(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
|
||||
return (retval);
|
||||
}
|
||||
#endif /* PNG_pHYs_SUPPORTED */
|
||||
#endif /* PNG_INCH_CONVERSIONS_SUPPORTED */
|
||||
#endif /* pHYs */
|
||||
#endif /* INCH_CONVERSIONS */
|
||||
|
||||
/* png_get_channels really belongs in here, too, but it's been around longer */
|
||||
|
||||
#endif /* PNG_EASY_ACCESS_SUPPORTED */
|
||||
#endif /* EASY_ACCESS */
|
||||
|
||||
|
||||
png_byte PNGAPI
|
||||
@ -455,10 +486,11 @@ png_get_signature(png_const_structrp png_ptr, png_const_inforp info_ptr)
|
||||
#ifdef PNG_bKGD_SUPPORTED
|
||||
png_uint_32 PNGAPI
|
||||
png_get_bKGD(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
png_color_16p *background)
|
||||
png_color_16p *background)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)
|
||||
&& background != NULL)
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_bKGD) != 0 &&
|
||||
background != NULL)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "bKGD");
|
||||
|
||||
@ -488,34 +520,34 @@ png_get_cHRM(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
* consistent.
|
||||
*/
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS))
|
||||
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "cHRM");
|
||||
|
||||
if (white_x != NULL)
|
||||
*white_x = png_float(png_ptr,
|
||||
info_ptr->colorspace.end_points_xy.whitex, "cHRM white X");
|
||||
info_ptr->colorspace.end_points_xy.whitex, "cHRM white X");
|
||||
if (white_y != NULL)
|
||||
*white_y = png_float(png_ptr,
|
||||
info_ptr->colorspace.end_points_xy.whitey, "cHRM white Y");
|
||||
info_ptr->colorspace.end_points_xy.whitey, "cHRM white Y");
|
||||
if (red_x != NULL)
|
||||
*red_x = png_float(png_ptr, info_ptr->colorspace.end_points_xy.redx,
|
||||
"cHRM red X");
|
||||
"cHRM red X");
|
||||
if (red_y != NULL)
|
||||
*red_y = png_float(png_ptr, info_ptr->colorspace.end_points_xy.redy,
|
||||
"cHRM red Y");
|
||||
"cHRM red Y");
|
||||
if (green_x != NULL)
|
||||
*green_x = png_float(png_ptr,
|
||||
info_ptr->colorspace.end_points_xy.greenx, "cHRM green X");
|
||||
info_ptr->colorspace.end_points_xy.greenx, "cHRM green X");
|
||||
if (green_y != NULL)
|
||||
*green_y = png_float(png_ptr,
|
||||
info_ptr->colorspace.end_points_xy.greeny, "cHRM green Y");
|
||||
info_ptr->colorspace.end_points_xy.greeny, "cHRM green Y");
|
||||
if (blue_x != NULL)
|
||||
*blue_x = png_float(png_ptr, info_ptr->colorspace.end_points_xy.bluex,
|
||||
"cHRM blue X");
|
||||
"cHRM blue X");
|
||||
if (blue_y != NULL)
|
||||
*blue_y = png_float(png_ptr, info_ptr->colorspace.end_points_xy.bluey,
|
||||
"cHRM blue Y");
|
||||
"cHRM blue Y");
|
||||
return (PNG_INFO_cHRM);
|
||||
}
|
||||
|
||||
@ -524,42 +556,42 @@ png_get_cHRM(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
|
||||
png_uint_32 PNGAPI
|
||||
png_get_cHRM_XYZ(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
double *red_X, double *red_Y, double *red_Z, double *green_X,
|
||||
double *green_Y, double *green_Z, double *blue_X, double *blue_Y,
|
||||
double *blue_Z)
|
||||
double *red_X, double *red_Y, double *red_Z, double *green_X,
|
||||
double *green_Y, double *green_Z, double *blue_X, double *blue_Y,
|
||||
double *blue_Z)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS))
|
||||
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "cHRM_XYZ(float)");
|
||||
|
||||
if (red_X != NULL)
|
||||
*red_X = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_X,
|
||||
"cHRM red X");
|
||||
"cHRM red X");
|
||||
if (red_Y != NULL)
|
||||
*red_Y = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_Y,
|
||||
"cHRM red Y");
|
||||
"cHRM red Y");
|
||||
if (red_Z != NULL)
|
||||
*red_Z = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_Z,
|
||||
"cHRM red Z");
|
||||
"cHRM red Z");
|
||||
if (green_X != NULL)
|
||||
*green_X = png_float(png_ptr,
|
||||
info_ptr->colorspace.end_points_XYZ.green_X, "cHRM green X");
|
||||
info_ptr->colorspace.end_points_XYZ.green_X, "cHRM green X");
|
||||
if (green_Y != NULL)
|
||||
*green_Y = png_float(png_ptr,
|
||||
info_ptr->colorspace.end_points_XYZ.green_Y, "cHRM green Y");
|
||||
info_ptr->colorspace.end_points_XYZ.green_Y, "cHRM green Y");
|
||||
if (green_Z != NULL)
|
||||
*green_Z = png_float(png_ptr,
|
||||
info_ptr->colorspace.end_points_XYZ.green_Z, "cHRM green Z");
|
||||
info_ptr->colorspace.end_points_XYZ.green_Z, "cHRM green Z");
|
||||
if (blue_X != NULL)
|
||||
*blue_X = png_float(png_ptr,
|
||||
info_ptr->colorspace.end_points_XYZ.blue_X, "cHRM blue X");
|
||||
info_ptr->colorspace.end_points_XYZ.blue_X, "cHRM blue X");
|
||||
if (blue_Y != NULL)
|
||||
*blue_Y = png_float(png_ptr,
|
||||
info_ptr->colorspace.end_points_XYZ.blue_Y, "cHRM blue Y");
|
||||
info_ptr->colorspace.end_points_XYZ.blue_Y, "cHRM blue Y");
|
||||
if (blue_Z != NULL)
|
||||
*blue_Z = png_float(png_ptr,
|
||||
info_ptr->colorspace.end_points_XYZ.blue_Z, "cHRM blue Z");
|
||||
info_ptr->colorspace.end_points_XYZ.blue_Z, "cHRM blue Z");
|
||||
return (PNG_INFO_cHRM);
|
||||
}
|
||||
|
||||
@ -577,7 +609,7 @@ png_get_cHRM_XYZ_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
png_fixed_point *int_blue_Z)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS))
|
||||
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "cHRM_XYZ");
|
||||
|
||||
@ -614,7 +646,7 @@ png_get_cHRM_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
png_debug1(1, "in %s retrieval function", "cHRM");
|
||||
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS))
|
||||
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)
|
||||
{
|
||||
if (white_x != NULL)
|
||||
*white_x = info_ptr->colorspace.end_points_xy.whitex;
|
||||
@ -649,8 +681,8 @@ png_get_gAMA_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
png_debug1(1, "in %s retrieval function", "gAMA");
|
||||
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) &&
|
||||
file_gamma != NULL)
|
||||
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) != 0 &&
|
||||
file_gamma != NULL)
|
||||
{
|
||||
*file_gamma = info_ptr->colorspace.gamma;
|
||||
return (PNG_INFO_gAMA);
|
||||
@ -668,11 +700,11 @@ png_get_gAMA(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
png_debug1(1, "in %s retrieval function", "gAMA(float)");
|
||||
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) &&
|
||||
(info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) != 0 &&
|
||||
file_gamma != NULL)
|
||||
{
|
||||
*file_gamma = png_float(png_ptr, info_ptr->colorspace.gamma,
|
||||
"png_get_gAMA");
|
||||
"png_get_gAMA");
|
||||
return (PNG_INFO_gAMA);
|
||||
}
|
||||
|
||||
@ -688,8 +720,8 @@ png_get_sRGB(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
{
|
||||
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)
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_sRGB) != 0 && file_srgb_intent != NULL)
|
||||
{
|
||||
*file_srgb_intent = info_ptr->colorspace.rendering_intent;
|
||||
return (PNG_INFO_sRGB);
|
||||
@ -707,9 +739,9 @@ png_get_iCCP(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "iCCP");
|
||||
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP)
|
||||
&& name != NULL && compression_type != NULL && profile != NULL &&
|
||||
proflen != NULL)
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_iCCP) != 0 &&
|
||||
name != NULL && profile != NULL && proflen != NULL)
|
||||
{
|
||||
*name = info_ptr->iccp_name;
|
||||
*profile = info_ptr->iccp_profile;
|
||||
@ -717,11 +749,13 @@ png_get_iCCP(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
/* This is somewhat irrelevant since the profile data returned has
|
||||
* actually been uncompressed.
|
||||
*/
|
||||
*compression_type = PNG_COMPRESSION_TYPE_BASE;
|
||||
if (compression_type != NULL)
|
||||
*compression_type = PNG_COMPRESSION_TYPE_BASE;
|
||||
return (PNG_INFO_iCCP);
|
||||
}
|
||||
|
||||
return (0);
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -740,6 +774,35 @@ png_get_sPLT(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PNG_eXIf_SUPPORTED
|
||||
png_uint_32 PNGAPI
|
||||
png_get_eXIf(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
png_bytep *exif)
|
||||
{
|
||||
png_warning(png_ptr, "png_get_eXIf does not work; use png_get_eXIf_1");
|
||||
PNG_UNUSED(info_ptr)
|
||||
PNG_UNUSED(exif)
|
||||
return 0;
|
||||
}
|
||||
|
||||
png_uint_32 PNGAPI
|
||||
png_get_eXIf_1(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
png_uint_32 *num_exif, png_bytep *exif)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "eXIf");
|
||||
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_eXIf) != 0 && exif != NULL)
|
||||
{
|
||||
*num_exif = info_ptr->num_exif;
|
||||
*exif = info_ptr->exif;
|
||||
return (PNG_INFO_eXIf);
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PNG_hIST_SUPPORTED
|
||||
png_uint_32 PNGAPI
|
||||
png_get_hIST(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
@ -747,8 +810,8 @@ png_get_hIST(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "hIST");
|
||||
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)
|
||||
&& hist != NULL)
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_hIST) != 0 && hist != NULL)
|
||||
{
|
||||
*hist = info_ptr->hist;
|
||||
return (PNG_INFO_hIST);
|
||||
@ -766,14 +829,20 @@ png_get_IHDR(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "IHDR");
|
||||
|
||||
if (png_ptr == NULL || info_ptr == NULL || width == NULL ||
|
||||
height == NULL || bit_depth == NULL || color_type == NULL)
|
||||
if (png_ptr == NULL || info_ptr == NULL)
|
||||
return (0);
|
||||
|
||||
*width = info_ptr->width;
|
||||
*height = info_ptr->height;
|
||||
*bit_depth = info_ptr->bit_depth;
|
||||
*color_type = info_ptr->color_type;
|
||||
if (width != NULL)
|
||||
*width = info_ptr->width;
|
||||
|
||||
if (height != NULL)
|
||||
*height = info_ptr->height;
|
||||
|
||||
if (bit_depth != NULL)
|
||||
*bit_depth = info_ptr->bit_depth;
|
||||
|
||||
if (color_type != NULL)
|
||||
*color_type = info_ptr->color_type;
|
||||
|
||||
if (compression_type != NULL)
|
||||
*compression_type = info_ptr->compression_type;
|
||||
@ -803,8 +872,9 @@ png_get_oFFs(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
{
|
||||
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)
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_oFFs) != 0 &&
|
||||
offset_x != NULL && offset_y != NULL && unit_type != NULL)
|
||||
{
|
||||
*offset_x = info_ptr->x_offset;
|
||||
*offset_y = info_ptr->y_offset;
|
||||
@ -824,8 +894,9 @@ png_get_pCAL(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
{
|
||||
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 &&
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_pCAL) != 0 &&
|
||||
purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
|
||||
nparams != NULL && units != NULL && params != NULL)
|
||||
{
|
||||
*purpose = info_ptr->pcal_purpose;
|
||||
@ -851,7 +922,7 @@ png_get_sCAL_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
int *unit, png_fixed_point *width, png_fixed_point *height)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_sCAL))
|
||||
(info_ptr->valid & PNG_INFO_sCAL) != 0)
|
||||
{
|
||||
*unit = info_ptr->scal_unit;
|
||||
/*TODO: make this work without FP support; the API is currently eliminated
|
||||
@ -860,7 +931,7 @@ png_get_sCAL_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
*/
|
||||
*width = png_fixed(png_ptr, atof(info_ptr->scal_s_width), "sCAL width");
|
||||
*height = png_fixed(png_ptr, atof(info_ptr->scal_s_height),
|
||||
"sCAL height");
|
||||
"sCAL height");
|
||||
return (PNG_INFO_sCAL);
|
||||
}
|
||||
|
||||
@ -874,7 +945,7 @@ png_get_sCAL(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
int *unit, double *width, double *height)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_sCAL))
|
||||
(info_ptr->valid & PNG_INFO_sCAL) != 0)
|
||||
{
|
||||
*unit = info_ptr->scal_unit;
|
||||
*width = atof(info_ptr->scal_s_width);
|
||||
@ -890,7 +961,7 @@ png_get_sCAL_s(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
int *unit, png_charpp width, png_charpp height)
|
||||
{
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_sCAL))
|
||||
(info_ptr->valid & PNG_INFO_sCAL) != 0)
|
||||
{
|
||||
*unit = info_ptr->scal_unit;
|
||||
*width = info_ptr->scal_s_width;
|
||||
@ -912,7 +983,7 @@ png_get_pHYs(png_const_structrp png_ptr, png_const_inforp info_ptr,
|
||||
png_debug1(1, "in %s retrieval function", "pHYs");
|
||||
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_pHYs))
|
||||
(info_ptr->valid & PNG_INFO_pHYs) != 0)
|
||||
{
|
||||
if (res_x != NULL)
|
||||
{
|
||||
@ -943,8 +1014,8 @@ png_get_PLTE(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "PLTE");
|
||||
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE)
|
||||
&& palette != NULL)
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_PLTE) != 0 && palette != NULL)
|
||||
{
|
||||
*palette = info_ptr->palette;
|
||||
*num_palette = info_ptr->num_palette;
|
||||
@ -962,8 +1033,8 @@ png_get_sBIT(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "sBIT");
|
||||
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)
|
||||
&& sig_bit != NULL)
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_sBIT) != 0 && sig_bit != NULL)
|
||||
{
|
||||
*sig_bit = &(info_ptr->sig_bit);
|
||||
return (PNG_INFO_sBIT);
|
||||
@ -1006,8 +1077,8 @@ png_get_tIME(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "tIME");
|
||||
|
||||
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)
|
||||
&& mod_time != NULL)
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_tIME) != 0 && mod_time != NULL)
|
||||
{
|
||||
*mod_time = &(info_ptr->mod_time);
|
||||
return (PNG_INFO_tIME);
|
||||
@ -1023,7 +1094,8 @@ png_get_tRNS(png_const_structrp png_ptr, png_inforp info_ptr,
|
||||
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))
|
||||
if (png_ptr != NULL && info_ptr != NULL &&
|
||||
(info_ptr->valid & PNG_INFO_tRNS) != 0)
|
||||
{
|
||||
png_debug1(1, "in %s retrieval function", "tRNS");
|
||||
|
||||
@ -1093,27 +1165,27 @@ png_get_user_chunk_ptr(png_const_structrp png_ptr)
|
||||
}
|
||||
#endif
|
||||
|
||||
png_size_t PNGAPI
|
||||
size_t PNGAPI
|
||||
png_get_compression_buffer_size(png_const_structrp png_ptr)
|
||||
{
|
||||
if (png_ptr == NULL)
|
||||
return 0;
|
||||
|
||||
# ifdef PNG_WRITE_SUPPORTED
|
||||
if (png_ptr->mode & PNG_IS_READ_STRUCT)
|
||||
# endif
|
||||
#ifdef PNG_WRITE_SUPPORTED
|
||||
if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0)
|
||||
#endif
|
||||
{
|
||||
# ifdef PNG_SEQUENTIAL_READ_SUPPORTED
|
||||
return png_ptr->IDAT_read_size;
|
||||
# else
|
||||
return PNG_IDAT_READ_SIZE;
|
||||
# endif
|
||||
#ifdef PNG_SEQUENTIAL_READ_SUPPORTED
|
||||
return png_ptr->IDAT_read_size;
|
||||
#else
|
||||
return PNG_IDAT_READ_SIZE;
|
||||
#endif
|
||||
}
|
||||
|
||||
# ifdef PNG_WRITE_SUPPORTED
|
||||
else
|
||||
return png_ptr->zbuffer_size;
|
||||
# endif
|
||||
#ifdef PNG_WRITE_SUPPORTED
|
||||
else
|
||||
return png_ptr->zbuffer_size;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef PNG_SET_USER_LIMITS_SUPPORTED
|
||||
@ -1144,7 +1216,7 @@ png_get_chunk_malloc_max (png_const_structrp png_ptr)
|
||||
{
|
||||
return (png_ptr ? png_ptr->user_chunk_malloc_max : 0);
|
||||
}
|
||||
#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
|
||||
#endif /* SET_USER_LIMITS */
|
||||
|
||||
/* These functions were added to libpng 1.4.0 */
|
||||
#ifdef PNG_IO_STATE_SUPPORTED
|
||||
@ -1159,7 +1231,7 @@ png_get_io_chunk_type (png_const_structrp png_ptr)
|
||||
{
|
||||
return png_ptr->chunk_name;
|
||||
}
|
||||
#endif /* ?PNG_IO_STATE_SUPPORTED */
|
||||
#endif /* IO_STATE */
|
||||
|
||||
#ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED
|
||||
# ifdef PNG_GET_PALETTE_MAX_SUPPORTED
|
||||
@ -1174,4 +1246,4 @@ png_get_palette_max(png_const_structp png_ptr, png_const_infop info_ptr)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
|
||||
#endif /* READ || WRITE */
|
||||
|
31
dlib/external/libpng/pnginfo.h
vendored
31
dlib/external/libpng/pnginfo.h
vendored
@ -1,11 +1,10 @@
|
||||
|
||||
/* pnginfo.h - header file for PNG reference library
|
||||
*
|
||||
* Copyright (c) 1998-2013 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.)
|
||||
*
|
||||
* Last changed in libpng 1.6.1 [March 28, 2013]
|
||||
* Copyright (c) 2018 Cosmin Truta
|
||||
* Copyright (c) 1998-2002,2004,2006-2013,2018 Glenn Randers-Pehrson
|
||||
* Copyright (c) 1996-1997 Andreas Dilger
|
||||
* Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
* For conditions of distribution and use, see the disclaimer
|
||||
@ -56,10 +55,10 @@
|
||||
struct png_info_def
|
||||
{
|
||||
/* The following are necessary for every PNG file */
|
||||
png_uint_32 width; /* width of image in pixels (from IHDR) */
|
||||
png_uint_32 height; /* height of image in pixels (from IHDR) */
|
||||
png_uint_32 valid; /* valid chunk data (see PNG_INFO_ below) */
|
||||
png_size_t rowbytes; /* bytes needed to hold an untransformed row */
|
||||
png_uint_32 width; /* width of image in pixels (from IHDR) */
|
||||
png_uint_32 height; /* height of image in pixels (from IHDR) */
|
||||
png_uint_32 valid; /* valid chunk data (see PNG_INFO_ below) */
|
||||
size_t rowbytes; /* bytes needed to hold an untransformed row */
|
||||
png_colorp palette; /* array of color values (valid & PNG_INFO_PLTE) */
|
||||
png_uint_16 num_palette; /* number of color entries in "palette" (PLTE) */
|
||||
png_uint_16 num_trans; /* number of transparent palette color (tRNS) */
|
||||
@ -121,7 +120,7 @@ struct png_info_def
|
||||
int num_text; /* number of comments read or comments to write */
|
||||
int max_text; /* current size of text array */
|
||||
png_textp text; /* array of comments read or comments to write */
|
||||
#endif /* PNG_TEXT_SUPPORTED */
|
||||
#endif /* TEXT */
|
||||
|
||||
#ifdef PNG_tIME_SUPPORTED
|
||||
/* The tIME chunk holds the last time the displayed image data was
|
||||
@ -186,6 +185,14 @@ defined(PNG_READ_BACKGROUND_SUPPORTED)
|
||||
png_byte phys_unit_type; /* resolution type (see PNG_RESOLUTION_ below) */
|
||||
#endif
|
||||
|
||||
#ifdef PNG_eXIf_SUPPORTED
|
||||
int num_exif; /* Added at libpng-1.6.31 */
|
||||
png_bytep exif;
|
||||
# ifdef PNG_READ_eXIf_SUPPORTED
|
||||
png_bytep eXIf_buf; /* Added at libpng-1.6.32 */
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef PNG_hIST_SUPPORTED
|
||||
/* The hIST chunk contains the relative frequency or importance of the
|
||||
* various palette entries, so that a viewer can intelligently select a
|
||||
@ -224,7 +231,7 @@ defined(PNG_READ_BACKGROUND_SUPPORTED)
|
||||
/* Storage for unknown chunks that the library doesn't recognize. */
|
||||
png_unknown_chunkp unknown_chunks;
|
||||
|
||||
/* The type of this field is limited by the type of
|
||||
/* The type of this field is limited by the type of
|
||||
* png_struct::user_chunk_cache_max, else overflow can occur.
|
||||
*/
|
||||
int unknown_chunks_num;
|
||||
@ -240,7 +247,7 @@ defined(PNG_READ_BACKGROUND_SUPPORTED)
|
||||
/* The sCAL chunk describes the actual physical dimensions of the
|
||||
* subject matter of the graphic. The chunk contains a unit specification
|
||||
* a byte value, and two ASCII strings representing floating-point
|
||||
* values. The values are width and height corresponsing to one pixel
|
||||
* values. The values are width and height corresponding to one pixel
|
||||
* in the image. Data values are valid if (valid & PNG_INFO_sCAL) is
|
||||
* non-zero.
|
||||
*/
|
||||
|
45
dlib/external/libpng/pngmem.c
vendored
45
dlib/external/libpng/pngmem.c
vendored
@ -1,10 +1,10 @@
|
||||
|
||||
/* pngmem.c - stub functions for memory allocation
|
||||
*
|
||||
* Last changed in libpng 1.6.0 [February 14, 2013]
|
||||
* Copyright (c) 1998-2013 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.)
|
||||
* Copyright (c) 2018 Cosmin Truta
|
||||
* Copyright (c) 1998-2002,2004,2006-2014,2016 Glenn Randers-Pehrson
|
||||
* Copyright (c) 1996-1997 Andreas Dilger
|
||||
* Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
* For conditions of distribution and use, see the disclaimer
|
||||
@ -41,7 +41,7 @@ png_destroy_png_struct(png_structrp png_ptr)
|
||||
}
|
||||
|
||||
/* Allocate memory. For reasonable files, size should never exceed
|
||||
* 64K. However, zlib may allocate more then 64K if you don't tell
|
||||
* 64K. However, zlib may allocate more than 64K if you don't tell
|
||||
* it not to. See zconf.h and png.h for more information. zlib does
|
||||
* need to allocate exactly 64K, so whatever you call here must
|
||||
* have the ability to do that.
|
||||
@ -66,16 +66,20 @@ png_calloc,(png_const_structrp png_ptr, png_alloc_size_t size),PNG_ALLOCATED)
|
||||
*/
|
||||
PNG_FUNCTION(png_voidp /* PRIVATE */,
|
||||
png_malloc_base,(png_const_structrp png_ptr, png_alloc_size_t size),
|
||||
PNG_ALLOCATED)
|
||||
PNG_ALLOCATED)
|
||||
{
|
||||
/* Moved to png_malloc_base from png_malloc_default in 1.6.0; the DOS
|
||||
* allocators have also been removed in 1.6.0, so any 16-bit system now has
|
||||
* to implement a user memory handler. This checks to be sure it isn't
|
||||
* called with big numbers.
|
||||
*/
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
#ifndef PNG_USER_MEM_SUPPORTED
|
||||
PNG_UNUSED(png_ptr)
|
||||
#endif
|
||||
|
||||
/* Some compilers complain that this is always true. However, it
|
||||
* can be false when integer overflow happens.
|
||||
*/
|
||||
if (size > 0 && size <= PNG_SIZE_MAX
|
||||
# ifdef PNG_MAX_MALLOC_64K
|
||||
&& size <= 65536U
|
||||
@ -95,15 +99,17 @@ png_malloc_base,(png_const_structrp png_ptr, png_alloc_size_t size),
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if defined(PNG_TEXT_SUPPORTED) || defined(PNG_sPLT_SUPPORTED) ||\
|
||||
defined(PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED)
|
||||
/* This is really here only to work round a spurious warning in GCC 4.6 and 4.7
|
||||
* that arises because of the checks in png_realloc_array that are repeated in
|
||||
* png_malloc_array.
|
||||
*/
|
||||
static png_voidp
|
||||
png_malloc_array_checked(png_const_structrp png_ptr, int nelements,
|
||||
size_t element_size)
|
||||
size_t element_size)
|
||||
{
|
||||
png_alloc_size_t req = nelements; /* known to be > 0 */
|
||||
png_alloc_size_t req = (png_alloc_size_t)nelements; /* known to be > 0 */
|
||||
|
||||
if (req <= PNG_SIZE_MAX/element_size)
|
||||
return png_malloc_base(png_ptr, req * element_size);
|
||||
@ -114,7 +120,7 @@ png_malloc_array_checked(png_const_structrp png_ptr, int nelements,
|
||||
|
||||
PNG_FUNCTION(png_voidp /* PRIVATE */,
|
||||
png_malloc_array,(png_const_structrp png_ptr, int nelements,
|
||||
size_t element_size),PNG_ALLOCATED)
|
||||
size_t element_size),PNG_ALLOCATED)
|
||||
{
|
||||
if (nelements <= 0 || element_size == 0)
|
||||
png_error(png_ptr, "internal error: array alloc");
|
||||
@ -124,7 +130,7 @@ png_malloc_array,(png_const_structrp png_ptr, int nelements,
|
||||
|
||||
PNG_FUNCTION(png_voidp /* PRIVATE */,
|
||||
png_realloc_array,(png_const_structrp png_ptr, png_const_voidp old_array,
|
||||
int old_elements, int add_elements, size_t element_size),PNG_ALLOCATED)
|
||||
int old_elements, int add_elements, size_t element_size),PNG_ALLOCATED)
|
||||
{
|
||||
/* These are internal errors: */
|
||||
if (add_elements <= 0 || element_size == 0 || old_elements < 0 ||
|
||||
@ -137,7 +143,7 @@ png_realloc_array,(png_const_structrp png_ptr, png_const_voidp old_array,
|
||||
if (add_elements <= INT_MAX - old_elements)
|
||||
{
|
||||
png_voidp new_array = png_malloc_array_checked(png_ptr,
|
||||
old_elements+add_elements, element_size);
|
||||
old_elements+add_elements, element_size);
|
||||
|
||||
if (new_array != NULL)
|
||||
{
|
||||
@ -148,7 +154,7 @@ png_realloc_array,(png_const_structrp png_ptr, png_const_voidp old_array,
|
||||
memcpy(new_array, old_array, element_size*(unsigned)old_elements);
|
||||
|
||||
memset((char*)new_array + element_size*(unsigned)old_elements, 0,
|
||||
element_size*(unsigned)add_elements);
|
||||
element_size*(unsigned)add_elements);
|
||||
|
||||
return new_array;
|
||||
}
|
||||
@ -156,6 +162,7 @@ png_realloc_array,(png_const_structrp png_ptr, png_const_voidp old_array,
|
||||
|
||||
return NULL; /* error */
|
||||
}
|
||||
#endif /* TEXT || sPLT || STORE_UNKNOWN_CHUNKS */
|
||||
|
||||
/* Various functions that have different error handling are derived from this.
|
||||
* png_malloc always exists, but if PNG_USER_MEM_SUPPORTED is defined a separate
|
||||
@ -180,7 +187,7 @@ png_malloc,(png_const_structrp png_ptr, png_alloc_size_t size),PNG_ALLOCATED)
|
||||
#ifdef PNG_USER_MEM_SUPPORTED
|
||||
PNG_FUNCTION(png_voidp,PNGAPI
|
||||
png_malloc_default,(png_const_structrp png_ptr, png_alloc_size_t size),
|
||||
PNG_ALLOCATED PNG_DEPRECATED)
|
||||
PNG_ALLOCATED PNG_DEPRECATED)
|
||||
{
|
||||
png_voidp ret;
|
||||
|
||||
@ -195,7 +202,7 @@ png_malloc_default,(png_const_structrp png_ptr, png_alloc_size_t size),
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||
#endif /* USER_MEM */
|
||||
|
||||
/* This function was added at libpng version 1.2.3. The png_malloc_warn()
|
||||
* function will issue a png_warning and return NULL instead of issuing a
|
||||
@ -203,7 +210,7 @@ png_malloc_default,(png_const_structrp png_ptr, png_alloc_size_t size),
|
||||
*/
|
||||
PNG_FUNCTION(png_voidp,PNGAPI
|
||||
png_malloc_warn,(png_const_structrp png_ptr, png_alloc_size_t size),
|
||||
PNG_ALLOCATED)
|
||||
PNG_ALLOCATED)
|
||||
{
|
||||
if (png_ptr != NULL)
|
||||
{
|
||||
@ -240,7 +247,7 @@ png_free_default,(png_const_structrp png_ptr, png_voidp ptr),PNG_DEPRECATED)
|
||||
{
|
||||
if (png_ptr == NULL || ptr == NULL)
|
||||
return;
|
||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||
#endif /* USER_MEM */
|
||||
|
||||
free(ptr);
|
||||
}
|
||||
@ -273,5 +280,5 @@ png_get_mem_ptr(png_const_structrp png_ptr)
|
||||
|
||||
return png_ptr->mem_ptr;
|
||||
}
|
||||
#endif /* PNG_USER_MEM_SUPPORTED */
|
||||
#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
|
||||
#endif /* USER_MEM */
|
||||
#endif /* READ || WRITE */
|
||||
|
441
dlib/external/libpng/pngpread.c
vendored
441
dlib/external/libpng/pngpread.c
vendored
@ -1,10 +1,10 @@
|
||||
|
||||
/* pngpread.c - read a png file in push mode
|
||||
*
|
||||
* Last changed in libpng 1.6.0 [February 14, 2013]
|
||||
* Copyright (c) 1998-2013 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.)
|
||||
* Copyright (c) 2018 Cosmin Truta
|
||||
* Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson
|
||||
* Copyright (c) 1996-1997 Andreas Dilger
|
||||
* Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
* For conditions of distribution and use, see the disclaimer
|
||||
@ -19,16 +19,22 @@
|
||||
#define PNG_READ_SIG_MODE 0
|
||||
#define PNG_READ_CHUNK_MODE 1
|
||||
#define PNG_READ_IDAT_MODE 2
|
||||
#define PNG_SKIP_MODE 3
|
||||
#define PNG_READ_tEXt_MODE 4
|
||||
#define PNG_READ_zTXt_MODE 5
|
||||
#define PNG_READ_DONE_MODE 6
|
||||
#define PNG_READ_iTXt_MODE 7
|
||||
#define PNG_ERROR_MODE 8
|
||||
|
||||
#define PNG_PUSH_SAVE_BUFFER_IF_FULL \
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size) \
|
||||
{ png_push_save_buffer(png_ptr); return; }
|
||||
#define PNG_PUSH_SAVE_BUFFER_IF_LT(N) \
|
||||
if (png_ptr->buffer_size < N) \
|
||||
{ png_push_save_buffer(png_ptr); return; }
|
||||
|
||||
void PNGAPI
|
||||
png_process_data(png_structrp png_ptr, png_inforp info_ptr,
|
||||
png_bytep buffer, png_size_t buffer_size)
|
||||
png_bytep buffer, size_t buffer_size)
|
||||
{
|
||||
if (png_ptr == NULL || info_ptr == NULL)
|
||||
return;
|
||||
@ -41,20 +47,20 @@ png_process_data(png_structrp png_ptr, png_inforp info_ptr,
|
||||
}
|
||||
}
|
||||
|
||||
png_size_t PNGAPI
|
||||
size_t PNGAPI
|
||||
png_process_data_pause(png_structrp png_ptr, int save)
|
||||
{
|
||||
if (png_ptr != NULL)
|
||||
{
|
||||
/* It's easiest for the caller if we do the save, then the caller doesn't
|
||||
/* It's easiest for the caller if we do the save; then the caller doesn't
|
||||
* have to supply the same data again:
|
||||
*/
|
||||
if (save)
|
||||
if (save != 0)
|
||||
png_push_save_buffer(png_ptr);
|
||||
else
|
||||
{
|
||||
/* This includes any pending saved bytes: */
|
||||
png_size_t remaining = png_ptr->buffer_size;
|
||||
size_t remaining = png_ptr->buffer_size;
|
||||
png_ptr->buffer_size = 0;
|
||||
|
||||
/* So subtract the saved buffer size, unless all the data
|
||||
@ -71,32 +77,14 @@ png_process_data_pause(png_structrp png_ptr, int save)
|
||||
png_uint_32 PNGAPI
|
||||
png_process_data_skip(png_structrp png_ptr)
|
||||
{
|
||||
png_uint_32 remaining = 0;
|
||||
|
||||
if (png_ptr != NULL && png_ptr->process_mode == PNG_SKIP_MODE &&
|
||||
png_ptr->skip_length > 0)
|
||||
{
|
||||
/* At the end of png_process_data the buffer size must be 0 (see the loop
|
||||
* above) so we can detect a broken call here:
|
||||
*/
|
||||
if (png_ptr->buffer_size != 0)
|
||||
png_error(png_ptr,
|
||||
"png_process_data_skip called inside png_process_data");
|
||||
|
||||
/* If is impossible for there to be a saved buffer at this point -
|
||||
* otherwise we could not be in SKIP mode. This will also happen if
|
||||
* png_process_skip is called inside png_process_data (but only very
|
||||
* rarely.)
|
||||
*/
|
||||
if (png_ptr->save_buffer_size != 0)
|
||||
png_error(png_ptr, "png_process_data_skip called with saved data");
|
||||
|
||||
remaining = png_ptr->skip_length;
|
||||
png_ptr->skip_length = 0;
|
||||
png_ptr->process_mode = PNG_READ_CHUNK_MODE;
|
||||
}
|
||||
|
||||
return remaining;
|
||||
/* TODO: Deprecate and remove this API.
|
||||
* Somewhere the implementation of this seems to have been lost,
|
||||
* or abandoned. It was only to support some internal back-door access
|
||||
* to png_struct) in libpng-1.4.x.
|
||||
*/
|
||||
png_app_warning(png_ptr,
|
||||
"png_process_data_skip is not implemented in any current version of libpng");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* What we do with the incoming data depends on what we were previously
|
||||
@ -128,12 +116,6 @@ png_process_some_data(png_structrp png_ptr, png_inforp info_ptr)
|
||||
break;
|
||||
}
|
||||
|
||||
case PNG_SKIP_MODE:
|
||||
{
|
||||
png_push_crc_finish(png_ptr);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
png_ptr->buffer_size = 0;
|
||||
@ -151,8 +133,8 @@ png_process_some_data(png_structrp png_ptr, png_inforp info_ptr)
|
||||
void /* PRIVATE */
|
||||
png_push_read_sig(png_structrp png_ptr, png_inforp info_ptr)
|
||||
{
|
||||
png_size_t num_checked = png_ptr->sig_bytes, /* SAFE, does not exceed 8 */
|
||||
num_to_check = 8 - num_checked;
|
||||
size_t num_checked = png_ptr->sig_bytes; /* SAFE, does not exceed 8 */
|
||||
size_t num_to_check = 8 - num_checked;
|
||||
|
||||
if (png_ptr->buffer_size < num_to_check)
|
||||
{
|
||||
@ -189,29 +171,25 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
|
||||
int keep; /* unknown handling method */
|
||||
#endif
|
||||
|
||||
/* 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
|
||||
/* 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
|
||||
* sure we have enough data in the buffer for the 4 byte CRC at the
|
||||
* sure we have enough data in the buffer for the 4-byte CRC at the
|
||||
* end of every chunk (except IDAT, which is handled separately).
|
||||
*/
|
||||
if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
|
||||
if ((png_ptr->mode & PNG_HAVE_CHUNK_HEADER) == 0)
|
||||
{
|
||||
png_byte chunk_length[4];
|
||||
png_byte chunk_tag[4];
|
||||
|
||||
if (png_ptr->buffer_size < 8)
|
||||
{
|
||||
png_push_save_buffer(png_ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
PNG_PUSH_SAVE_BUFFER_IF_LT(8)
|
||||
png_push_fill_buffer(png_ptr, chunk_length, 4);
|
||||
png_ptr->push_length = png_get_uint_31(png_ptr, chunk_length);
|
||||
png_reset_crc(png_ptr);
|
||||
png_crc_read(png_ptr, chunk_tag, 4);
|
||||
png_ptr->chunk_name = PNG_CHUNK_FROM_STRING(chunk_tag);
|
||||
png_check_chunk_name(png_ptr, png_ptr->chunk_name);
|
||||
png_check_chunk_length(png_ptr, png_ptr->push_length);
|
||||
png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
|
||||
}
|
||||
|
||||
@ -219,27 +197,30 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
|
||||
|
||||
if (chunk_name == png_IDAT)
|
||||
{
|
||||
if (png_ptr->mode & PNG_AFTER_IDAT)
|
||||
if ((png_ptr->mode & PNG_AFTER_IDAT) != 0)
|
||||
png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
|
||||
|
||||
/* If we reach an IDAT chunk, this means we have read all of the
|
||||
* header chunks, and we can start reading the image (or if this
|
||||
* is called after the image has been read - we have an error).
|
||||
*/
|
||||
if (!(png_ptr->mode & PNG_HAVE_IHDR))
|
||||
if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)
|
||||
png_error(png_ptr, "Missing IHDR before IDAT");
|
||||
|
||||
else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
|
||||
!(png_ptr->mode & PNG_HAVE_PLTE))
|
||||
(png_ptr->mode & PNG_HAVE_PLTE) == 0)
|
||||
png_error(png_ptr, "Missing PLTE before IDAT");
|
||||
|
||||
png_ptr->process_mode = PNG_READ_IDAT_MODE;
|
||||
|
||||
if ((png_ptr->mode & PNG_HAVE_IDAT) != 0)
|
||||
if ((png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT) == 0)
|
||||
if (png_ptr->push_length == 0)
|
||||
return;
|
||||
|
||||
png_ptr->mode |= PNG_HAVE_IDAT;
|
||||
|
||||
if (!(png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
|
||||
if (png_ptr->push_length == 0)
|
||||
return;
|
||||
|
||||
if (png_ptr->mode & PNG_AFTER_IDAT)
|
||||
if ((png_ptr->mode & PNG_AFTER_IDAT) != 0)
|
||||
png_benign_error(png_ptr, "Too many IDATs found");
|
||||
}
|
||||
|
||||
@ -248,23 +229,13 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
|
||||
if (png_ptr->push_length != 13)
|
||||
png_error(png_ptr, "Invalid IHDR length");
|
||||
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
{
|
||||
png_push_save_buffer(png_ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
PNG_PUSH_SAVE_BUFFER_IF_FULL
|
||||
png_handle_IHDR(png_ptr, info_ptr, png_ptr->push_length);
|
||||
}
|
||||
|
||||
else if (chunk_name == png_IEND)
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
{
|
||||
png_push_save_buffer(png_ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
PNG_PUSH_SAVE_BUFFER_IF_FULL
|
||||
png_handle_IEND(png_ptr, info_ptr, png_ptr->push_length);
|
||||
|
||||
png_ptr->process_mode = PNG_READ_DONE_MODE;
|
||||
@ -274,26 +245,17 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
|
||||
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
|
||||
else if ((keep = png_chunk_unknown_handling(png_ptr, chunk_name)) != 0)
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
{
|
||||
png_push_save_buffer(png_ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
PNG_PUSH_SAVE_BUFFER_IF_FULL
|
||||
png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length, keep);
|
||||
|
||||
if (chunk_name == png_PLTE)
|
||||
png_ptr->mode |= PNG_HAVE_PLTE;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
else if (chunk_name == png_PLTE)
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
{
|
||||
png_push_save_buffer(png_ptr);
|
||||
return;
|
||||
}
|
||||
PNG_PUSH_SAVE_BUFFER_IF_FULL
|
||||
png_handle_PLTE(png_ptr, info_ptr, png_ptr->push_length);
|
||||
}
|
||||
|
||||
@ -312,12 +274,7 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
|
||||
#ifdef PNG_READ_gAMA_SUPPORTED
|
||||
else if (png_ptr->chunk_name == png_gAMA)
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
{
|
||||
png_push_save_buffer(png_ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
PNG_PUSH_SAVE_BUFFER_IF_FULL
|
||||
png_handle_gAMA(png_ptr, info_ptr, png_ptr->push_length);
|
||||
}
|
||||
|
||||
@ -325,12 +282,7 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
|
||||
#ifdef PNG_READ_sBIT_SUPPORTED
|
||||
else if (png_ptr->chunk_name == png_sBIT)
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
{
|
||||
png_push_save_buffer(png_ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
PNG_PUSH_SAVE_BUFFER_IF_FULL
|
||||
png_handle_sBIT(png_ptr, info_ptr, png_ptr->push_length);
|
||||
}
|
||||
|
||||
@ -338,12 +290,7 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
|
||||
#ifdef PNG_READ_cHRM_SUPPORTED
|
||||
else if (png_ptr->chunk_name == png_cHRM)
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
{
|
||||
png_push_save_buffer(png_ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
PNG_PUSH_SAVE_BUFFER_IF_FULL
|
||||
png_handle_cHRM(png_ptr, info_ptr, png_ptr->push_length);
|
||||
}
|
||||
|
||||
@ -351,12 +298,7 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
|
||||
#ifdef PNG_READ_sRGB_SUPPORTED
|
||||
else if (chunk_name == png_sRGB)
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
{
|
||||
png_push_save_buffer(png_ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
PNG_PUSH_SAVE_BUFFER_IF_FULL
|
||||
png_handle_sRGB(png_ptr, info_ptr, png_ptr->push_length);
|
||||
}
|
||||
|
||||
@ -364,12 +306,7 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
|
||||
#ifdef PNG_READ_iCCP_SUPPORTED
|
||||
else if (png_ptr->chunk_name == png_iCCP)
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
{
|
||||
png_push_save_buffer(png_ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
PNG_PUSH_SAVE_BUFFER_IF_FULL
|
||||
png_handle_iCCP(png_ptr, info_ptr, png_ptr->push_length);
|
||||
}
|
||||
|
||||
@ -377,12 +314,7 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
|
||||
#ifdef PNG_READ_sPLT_SUPPORTED
|
||||
else if (chunk_name == png_sPLT)
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
{
|
||||
png_push_save_buffer(png_ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
PNG_PUSH_SAVE_BUFFER_IF_FULL
|
||||
png_handle_sPLT(png_ptr, info_ptr, png_ptr->push_length);
|
||||
}
|
||||
|
||||
@ -390,12 +322,7 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
|
||||
#ifdef PNG_READ_tRNS_SUPPORTED
|
||||
else if (chunk_name == png_tRNS)
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
{
|
||||
png_push_save_buffer(png_ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
PNG_PUSH_SAVE_BUFFER_IF_FULL
|
||||
png_handle_tRNS(png_ptr, info_ptr, png_ptr->push_length);
|
||||
}
|
||||
|
||||
@ -403,12 +330,7 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
|
||||
#ifdef PNG_READ_bKGD_SUPPORTED
|
||||
else if (chunk_name == png_bKGD)
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
{
|
||||
png_push_save_buffer(png_ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
PNG_PUSH_SAVE_BUFFER_IF_FULL
|
||||
png_handle_bKGD(png_ptr, info_ptr, png_ptr->push_length);
|
||||
}
|
||||
|
||||
@ -416,12 +338,7 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
|
||||
#ifdef PNG_READ_hIST_SUPPORTED
|
||||
else if (chunk_name == png_hIST)
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
{
|
||||
png_push_save_buffer(png_ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
PNG_PUSH_SAVE_BUFFER_IF_FULL
|
||||
png_handle_hIST(png_ptr, info_ptr, png_ptr->push_length);
|
||||
}
|
||||
|
||||
@ -429,12 +346,7 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
|
||||
#ifdef PNG_READ_pHYs_SUPPORTED
|
||||
else if (chunk_name == png_pHYs)
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
{
|
||||
png_push_save_buffer(png_ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
PNG_PUSH_SAVE_BUFFER_IF_FULL
|
||||
png_handle_pHYs(png_ptr, info_ptr, png_ptr->push_length);
|
||||
}
|
||||
|
||||
@ -442,12 +354,7 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
|
||||
#ifdef PNG_READ_oFFs_SUPPORTED
|
||||
else if (chunk_name == png_oFFs)
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
{
|
||||
png_push_save_buffer(png_ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
PNG_PUSH_SAVE_BUFFER_IF_FULL
|
||||
png_handle_oFFs(png_ptr, info_ptr, png_ptr->push_length);
|
||||
}
|
||||
#endif
|
||||
@ -455,12 +362,7 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
|
||||
#ifdef PNG_READ_pCAL_SUPPORTED
|
||||
else if (chunk_name == png_pCAL)
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
{
|
||||
png_push_save_buffer(png_ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
PNG_PUSH_SAVE_BUFFER_IF_FULL
|
||||
png_handle_pCAL(png_ptr, info_ptr, png_ptr->push_length);
|
||||
}
|
||||
|
||||
@ -468,12 +370,7 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
|
||||
#ifdef PNG_READ_sCAL_SUPPORTED
|
||||
else if (chunk_name == png_sCAL)
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
{
|
||||
png_push_save_buffer(png_ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
PNG_PUSH_SAVE_BUFFER_IF_FULL
|
||||
png_handle_sCAL(png_ptr, info_ptr, png_ptr->push_length);
|
||||
}
|
||||
|
||||
@ -481,12 +378,7 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
|
||||
#ifdef PNG_READ_tIME_SUPPORTED
|
||||
else if (chunk_name == png_tIME)
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
{
|
||||
png_push_save_buffer(png_ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
PNG_PUSH_SAVE_BUFFER_IF_FULL
|
||||
png_handle_tIME(png_ptr, info_ptr, png_ptr->push_length);
|
||||
}
|
||||
|
||||
@ -494,12 +386,7 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
|
||||
#ifdef PNG_READ_tEXt_SUPPORTED
|
||||
else if (chunk_name == png_tEXt)
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
{
|
||||
png_push_save_buffer(png_ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
PNG_PUSH_SAVE_BUFFER_IF_FULL
|
||||
png_handle_tEXt(png_ptr, info_ptr, png_ptr->push_length);
|
||||
}
|
||||
|
||||
@ -507,12 +394,7 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
|
||||
#ifdef PNG_READ_zTXt_SUPPORTED
|
||||
else if (chunk_name == png_zTXt)
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
{
|
||||
png_push_save_buffer(png_ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
PNG_PUSH_SAVE_BUFFER_IF_FULL
|
||||
png_handle_zTXt(png_ptr, info_ptr, png_ptr->push_length);
|
||||
}
|
||||
|
||||
@ -520,100 +402,23 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
|
||||
#ifdef PNG_READ_iTXt_SUPPORTED
|
||||
else if (chunk_name == png_iTXt)
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
{
|
||||
png_push_save_buffer(png_ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
PNG_PUSH_SAVE_BUFFER_IF_FULL
|
||||
png_handle_iTXt(png_ptr, info_ptr, png_ptr->push_length);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
else
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
{
|
||||
png_push_save_buffer(png_ptr);
|
||||
return;
|
||||
}
|
||||
PNG_PUSH_SAVE_BUFFER_IF_FULL
|
||||
png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length,
|
||||
PNG_HANDLE_CHUNK_AS_DEFAULT);
|
||||
PNG_HANDLE_CHUNK_AS_DEFAULT);
|
||||
}
|
||||
|
||||
png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
|
||||
}
|
||||
|
||||
void /* PRIVATE */
|
||||
png_push_crc_skip(png_structrp png_ptr, png_uint_32 skip)
|
||||
{
|
||||
png_ptr->process_mode = PNG_SKIP_MODE;
|
||||
png_ptr->skip_length = skip;
|
||||
}
|
||||
|
||||
void /* PRIVATE */
|
||||
png_push_crc_finish(png_structrp png_ptr)
|
||||
{
|
||||
if (png_ptr->skip_length && png_ptr->save_buffer_size)
|
||||
{
|
||||
png_size_t save_size = png_ptr->save_buffer_size;
|
||||
png_uint_32 skip_length = png_ptr->skip_length;
|
||||
|
||||
/* We want the smaller of 'skip_length' and 'save_buffer_size', but
|
||||
* they are of different types and we don't know which variable has the
|
||||
* fewest bits. Carefully select the smaller and cast it to the type of
|
||||
* the larger - this cannot overflow. Do not cast in the following test
|
||||
* - it will break on either 16 or 64 bit platforms.
|
||||
*/
|
||||
if (skip_length < save_size)
|
||||
save_size = (png_size_t)skip_length;
|
||||
|
||||
else
|
||||
skip_length = (png_uint_32)save_size;
|
||||
|
||||
png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
|
||||
|
||||
png_ptr->skip_length -= skip_length;
|
||||
png_ptr->buffer_size -= save_size;
|
||||
png_ptr->save_buffer_size -= save_size;
|
||||
png_ptr->save_buffer_ptr += save_size;
|
||||
}
|
||||
if (png_ptr->skip_length && png_ptr->current_buffer_size)
|
||||
{
|
||||
png_size_t save_size = png_ptr->current_buffer_size;
|
||||
png_uint_32 skip_length = png_ptr->skip_length;
|
||||
|
||||
/* We want the smaller of 'skip_length' and 'current_buffer_size', here,
|
||||
* the same problem exists as above and the same solution.
|
||||
*/
|
||||
if (skip_length < save_size)
|
||||
save_size = (png_size_t)skip_length;
|
||||
|
||||
else
|
||||
skip_length = (png_uint_32)save_size;
|
||||
|
||||
png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
|
||||
|
||||
png_ptr->skip_length -= skip_length;
|
||||
png_ptr->buffer_size -= save_size;
|
||||
png_ptr->current_buffer_size -= save_size;
|
||||
png_ptr->current_buffer_ptr += save_size;
|
||||
}
|
||||
if (!png_ptr->skip_length)
|
||||
{
|
||||
if (png_ptr->buffer_size < 4)
|
||||
{
|
||||
png_push_save_buffer(png_ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
png_crc_finish(png_ptr, 0);
|
||||
png_ptr->process_mode = PNG_READ_CHUNK_MODE;
|
||||
}
|
||||
}
|
||||
|
||||
void PNGCBAPI
|
||||
png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length)
|
||||
png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, size_t length)
|
||||
{
|
||||
png_bytep ptr;
|
||||
|
||||
@ -621,9 +426,9 @@ png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length)
|
||||
return;
|
||||
|
||||
ptr = buffer;
|
||||
if (png_ptr->save_buffer_size)
|
||||
if (png_ptr->save_buffer_size != 0)
|
||||
{
|
||||
png_size_t save_size;
|
||||
size_t save_size;
|
||||
|
||||
if (length < png_ptr->save_buffer_size)
|
||||
save_size = length;
|
||||
@ -638,9 +443,9 @@ png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length)
|
||||
png_ptr->save_buffer_size -= save_size;
|
||||
png_ptr->save_buffer_ptr += save_size;
|
||||
}
|
||||
if (length && png_ptr->current_buffer_size)
|
||||
if (length != 0 && png_ptr->current_buffer_size != 0)
|
||||
{
|
||||
png_size_t save_size;
|
||||
size_t save_size;
|
||||
|
||||
if (length < png_ptr->current_buffer_size)
|
||||
save_size = length;
|
||||
@ -658,11 +463,11 @@ png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length)
|
||||
void /* PRIVATE */
|
||||
png_push_save_buffer(png_structrp png_ptr)
|
||||
{
|
||||
if (png_ptr->save_buffer_size)
|
||||
if (png_ptr->save_buffer_size != 0)
|
||||
{
|
||||
if (png_ptr->save_buffer_ptr != png_ptr->save_buffer)
|
||||
{
|
||||
png_size_t i, istop;
|
||||
size_t i, istop;
|
||||
png_bytep sp;
|
||||
png_bytep dp;
|
||||
|
||||
@ -677,7 +482,7 @@ png_push_save_buffer(png_structrp png_ptr)
|
||||
if (png_ptr->save_buffer_size + png_ptr->current_buffer_size >
|
||||
png_ptr->save_buffer_max)
|
||||
{
|
||||
png_size_t new_max;
|
||||
size_t new_max;
|
||||
png_bytep old_buffer;
|
||||
|
||||
if (png_ptr->save_buffer_size > PNG_SIZE_MAX -
|
||||
@ -689,7 +494,7 @@ png_push_save_buffer(png_structrp 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_warn(png_ptr,
|
||||
(png_size_t)new_max);
|
||||
(size_t)new_max);
|
||||
|
||||
if (png_ptr->save_buffer == NULL)
|
||||
{
|
||||
@ -697,7 +502,10 @@ png_push_save_buffer(png_structrp png_ptr)
|
||||
png_error(png_ptr, "Insufficient memory for save_buffer");
|
||||
}
|
||||
|
||||
memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size);
|
||||
if (old_buffer)
|
||||
memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size);
|
||||
else if (png_ptr->save_buffer_size)
|
||||
png_error(png_ptr, "save_buffer error");
|
||||
png_free(png_ptr, old_buffer);
|
||||
png_ptr->save_buffer_max = new_max;
|
||||
}
|
||||
@ -714,7 +522,7 @@ png_push_save_buffer(png_structrp png_ptr)
|
||||
|
||||
void /* PRIVATE */
|
||||
png_push_restore_buffer(png_structrp png_ptr, png_bytep buffer,
|
||||
png_size_t buffer_length)
|
||||
size_t buffer_length)
|
||||
{
|
||||
png_ptr->current_buffer = buffer;
|
||||
png_ptr->current_buffer_size = buffer_length;
|
||||
@ -725,18 +533,13 @@ png_push_restore_buffer(png_structrp png_ptr, png_bytep buffer,
|
||||
void /* PRIVATE */
|
||||
png_push_read_IDAT(png_structrp png_ptr)
|
||||
{
|
||||
if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
|
||||
if ((png_ptr->mode & PNG_HAVE_CHUNK_HEADER) == 0)
|
||||
{
|
||||
png_byte chunk_length[4];
|
||||
png_byte chunk_tag[4];
|
||||
|
||||
/* TODO: this code can be commoned up with the same code in push_read */
|
||||
if (png_ptr->buffer_size < 8)
|
||||
{
|
||||
png_push_save_buffer(png_ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
PNG_PUSH_SAVE_BUFFER_IF_LT(8)
|
||||
png_push_fill_buffer(png_ptr, chunk_length, 4);
|
||||
png_ptr->push_length = png_get_uint_31(png_ptr, chunk_length);
|
||||
png_reset_crc(png_ptr);
|
||||
@ -748,7 +551,7 @@ png_push_read_IDAT(png_structrp png_ptr)
|
||||
{
|
||||
png_ptr->process_mode = PNG_READ_CHUNK_MODE;
|
||||
|
||||
if (!(png_ptr->flags & PNG_FLAG_ZSTREAM_ENDED))
|
||||
if ((png_ptr->flags & PNG_FLAG_ZSTREAM_ENDED) == 0)
|
||||
png_error(png_ptr, "Not enough compressed data");
|
||||
|
||||
return;
|
||||
@ -757,19 +560,19 @@ png_push_read_IDAT(png_structrp png_ptr)
|
||||
png_ptr->idat_size = png_ptr->push_length;
|
||||
}
|
||||
|
||||
if (png_ptr->idat_size && png_ptr->save_buffer_size)
|
||||
if (png_ptr->idat_size != 0 && png_ptr->save_buffer_size != 0)
|
||||
{
|
||||
png_size_t save_size = png_ptr->save_buffer_size;
|
||||
size_t save_size = png_ptr->save_buffer_size;
|
||||
png_uint_32 idat_size = png_ptr->idat_size;
|
||||
|
||||
/* We want the smaller of 'idat_size' and 'current_buffer_size', but they
|
||||
* are of different types and we don't know which variable has the fewest
|
||||
* bits. Carefully select the smaller and cast it to the type of the
|
||||
* larger - this cannot overflow. Do not cast in the following test - it
|
||||
* will break on either 16 or 64 bit platforms.
|
||||
* will break on either 16-bit or 64-bit platforms.
|
||||
*/
|
||||
if (idat_size < save_size)
|
||||
save_size = (png_size_t)idat_size;
|
||||
save_size = (size_t)idat_size;
|
||||
|
||||
else
|
||||
idat_size = (png_uint_32)save_size;
|
||||
@ -784,9 +587,9 @@ png_push_read_IDAT(png_structrp png_ptr)
|
||||
png_ptr->save_buffer_ptr += save_size;
|
||||
}
|
||||
|
||||
if (png_ptr->idat_size && png_ptr->current_buffer_size)
|
||||
if (png_ptr->idat_size != 0 && png_ptr->current_buffer_size != 0)
|
||||
{
|
||||
png_size_t save_size = png_ptr->current_buffer_size;
|
||||
size_t save_size = png_ptr->current_buffer_size;
|
||||
png_uint_32 idat_size = png_ptr->idat_size;
|
||||
|
||||
/* We want the smaller of 'idat_size' and 'current_buffer_size', but they
|
||||
@ -795,7 +598,7 @@ png_push_read_IDAT(png_structrp png_ptr)
|
||||
* larger - this cannot overflow.
|
||||
*/
|
||||
if (idat_size < save_size)
|
||||
save_size = (png_size_t)idat_size;
|
||||
save_size = (size_t)idat_size;
|
||||
|
||||
else
|
||||
idat_size = (png_uint_32)save_size;
|
||||
@ -809,14 +612,10 @@ png_push_read_IDAT(png_structrp png_ptr)
|
||||
png_ptr->current_buffer_size -= save_size;
|
||||
png_ptr->current_buffer_ptr += save_size;
|
||||
}
|
||||
if (!png_ptr->idat_size)
|
||||
{
|
||||
if (png_ptr->buffer_size < 4)
|
||||
{
|
||||
png_push_save_buffer(png_ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
if (png_ptr->idat_size == 0)
|
||||
{
|
||||
PNG_PUSH_SAVE_BUFFER_IF_LT(4)
|
||||
png_crc_finish(png_ptr, 0);
|
||||
png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
|
||||
png_ptr->mode |= PNG_AFTER_IDAT;
|
||||
@ -826,7 +625,7 @@ png_push_read_IDAT(png_structrp png_ptr)
|
||||
|
||||
void /* PRIVATE */
|
||||
png_process_IDAT_data(png_structrp png_ptr, png_bytep buffer,
|
||||
png_size_t buffer_length)
|
||||
size_t buffer_length)
|
||||
{
|
||||
/* The caller checks for a non-zero buffer length. */
|
||||
if (!(buffer_length > 0) || buffer == NULL)
|
||||
@ -844,7 +643,7 @@ png_process_IDAT_data(png_structrp png_ptr, png_bytep buffer,
|
||||
* or the stream marked as finished.
|
||||
*/
|
||||
while (png_ptr->zstream.avail_in > 0 &&
|
||||
!(png_ptr->flags & PNG_FLAG_ZSTREAM_ENDED))
|
||||
(png_ptr->flags & PNG_FLAG_ZSTREAM_ENDED) == 0)
|
||||
{
|
||||
int ret;
|
||||
|
||||
@ -869,7 +668,7 @@ png_process_IDAT_data(png_structrp png_ptr, png_bytep buffer,
|
||||
* change the current behavior (see comments in inflate.c
|
||||
* for why this doesn't happen at present with zlib 1.2.5).
|
||||
*/
|
||||
ret = inflate(&png_ptr->zstream, Z_SYNC_FLUSH);
|
||||
ret = PNG_INFLATE(png_ptr, Z_SYNC_FLUSH);
|
||||
|
||||
/* Check for any failure before proceeding. */
|
||||
if (ret != Z_OK && ret != Z_STREAM_END)
|
||||
@ -886,7 +685,12 @@ png_process_IDAT_data(png_structrp png_ptr, png_bytep buffer,
|
||||
png_warning(png_ptr, "Truncated compressed data in IDAT");
|
||||
|
||||
else
|
||||
png_error(png_ptr, "Decompression error in IDAT");
|
||||
{
|
||||
if (ret == Z_DATA_ERROR)
|
||||
png_benign_error(png_ptr, "IDAT: ADLER32 checksum mismatch");
|
||||
else
|
||||
png_error(png_ptr, "Decompression error in IDAT");
|
||||
}
|
||||
|
||||
/* Skip the check on unprocessed input */
|
||||
return;
|
||||
@ -961,7 +765,7 @@ png_push_process_row(png_structrp png_ptr)
|
||||
memcpy(png_ptr->prev_row, png_ptr->row_buf, row_info.rowbytes + 1);
|
||||
|
||||
#ifdef PNG_READ_TRANSFORMS_SUPPORTED
|
||||
if (png_ptr->transformations)
|
||||
if (png_ptr->transformations != 0)
|
||||
png_do_read_transformations(png_ptr, &row_info);
|
||||
#endif
|
||||
|
||||
@ -978,15 +782,16 @@ png_push_process_row(png_structrp png_ptr)
|
||||
|
||||
|
||||
#ifdef PNG_READ_INTERLACING_SUPPORTED
|
||||
/* Blow up interlaced rows to full size */
|
||||
if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
|
||||
/* Expand interlaced rows to full size */
|
||||
if (png_ptr->interlaced != 0 &&
|
||||
(png_ptr->transformations & PNG_INTERLACE) != 0)
|
||||
{
|
||||
if (png_ptr->pass < 6)
|
||||
png_do_read_interlace(&row_info, png_ptr->row_buf + 1, png_ptr->pass,
|
||||
png_ptr->transformations);
|
||||
png_ptr->transformations);
|
||||
|
||||
switch (png_ptr->pass)
|
||||
{
|
||||
switch (png_ptr->pass)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
int i;
|
||||
@ -1167,20 +972,20 @@ png_read_push_finish_row(png_structrp png_ptr)
|
||||
/* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
|
||||
|
||||
/* Start of interlace block */
|
||||
static PNG_CONST png_byte png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
|
||||
static const png_byte png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
|
||||
|
||||
/* Offset to next interlace block */
|
||||
static PNG_CONST png_byte png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
|
||||
static const png_byte png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
|
||||
|
||||
/* Start of interlace block in the y direction */
|
||||
static PNG_CONST png_byte png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
|
||||
static const png_byte png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
|
||||
|
||||
/* Offset to next interlace block in the y direction */
|
||||
static PNG_CONST png_byte png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
|
||||
static const png_byte 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
|
||||
static PNG_CONST png_byte png_pass_height[] = {8, 8, 4, 4, 2, 2, 1};
|
||||
static const png_byte png_pass_height[] = {8, 8, 4, 4, 2, 2, 1};
|
||||
*/
|
||||
#endif
|
||||
|
||||
@ -1189,7 +994,7 @@ png_read_push_finish_row(png_structrp png_ptr)
|
||||
return;
|
||||
|
||||
#ifdef PNG_READ_INTERLACING_SUPPORTED
|
||||
if (png_ptr->interlaced)
|
||||
if (png_ptr->interlaced != 0)
|
||||
{
|
||||
png_ptr->row_number = 0;
|
||||
memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
|
||||
@ -1213,7 +1018,7 @@ png_read_push_finish_row(png_structrp png_ptr)
|
||||
png_pass_start[png_ptr->pass]) /
|
||||
png_pass_inc[png_ptr->pass];
|
||||
|
||||
if (png_ptr->transformations & PNG_INTERLACE)
|
||||
if ((png_ptr->transformations & PNG_INTERLACE) != 0)
|
||||
break;
|
||||
|
||||
png_ptr->num_rows = (png_ptr->height +
|
||||
@ -1223,7 +1028,7 @@ png_read_push_finish_row(png_structrp png_ptr)
|
||||
|
||||
} while (png_ptr->iwidth == 0 || png_ptr->num_rows == 0);
|
||||
}
|
||||
#endif /* PNG_READ_INTERLACING_SUPPORTED */
|
||||
#endif /* READ_INTERLACING */
|
||||
}
|
||||
|
||||
void /* PRIVATE */
|
||||
@ -1245,7 +1050,7 @@ png_push_have_row(png_structrp png_ptr, png_bytep row)
|
||||
{
|
||||
if (png_ptr->row_fn != NULL)
|
||||
(*(png_ptr->row_fn))(png_ptr, row, png_ptr->row_number,
|
||||
(int)png_ptr->pass);
|
||||
(int)png_ptr->pass);
|
||||
}
|
||||
|
||||
#ifdef PNG_READ_INTERLACING_SUPPORTED
|
||||
@ -1261,9 +1066,9 @@ png_progressive_combine_row(png_const_structrp png_ptr, png_bytep old_row,
|
||||
* it must be png_ptr->row_buf+1
|
||||
*/
|
||||
if (new_row != NULL)
|
||||
png_combine_row(png_ptr, old_row, 1/*display*/);
|
||||
png_combine_row(png_ptr, old_row, 1/*blocky display*/);
|
||||
}
|
||||
#endif /* PNG_READ_INTERLACING_SUPPORTED */
|
||||
#endif /* READ_INTERLACING */
|
||||
|
||||
void PNGAPI
|
||||
png_set_progressive_read_fn(png_structrp png_ptr, png_voidp progressive_ptr,
|
||||
@ -1288,4 +1093,4 @@ png_get_progressive_ptr(png_const_structrp png_ptr)
|
||||
|
||||
return png_ptr->io_ptr;
|
||||
}
|
||||
#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
|
||||
#endif /* PROGRESSIVE_READ */
|
||||
|
767
dlib/external/libpng/pngpriv.h
vendored
767
dlib/external/libpng/pngpriv.h
vendored
File diff suppressed because it is too large
Load Diff
1113
dlib/external/libpng/pngread.c
vendored
1113
dlib/external/libpng/pngread.c
vendored
File diff suppressed because it is too large
Load Diff
24
dlib/external/libpng/pngrio.c
vendored
24
dlib/external/libpng/pngrio.c
vendored
@ -1,10 +1,10 @@
|
||||
|
||||
/* pngrio.c - functions for data input
|
||||
*
|
||||
* Last changed in libpng 1.6.0 [February 14, 2013]
|
||||
* Copyright (c) 1998-2013 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.)
|
||||
* Copyright (c) 2018 Cosmin Truta
|
||||
* Copyright (c) 1998-2002,2004,2006-2016,2018 Glenn Randers-Pehrson
|
||||
* Copyright (c) 1996-1997 Andreas Dilger
|
||||
* Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
* For conditions of distribution and use, see the disclaimer
|
||||
@ -26,10 +26,10 @@
|
||||
* reads from a file pointer. Note that this routine sometimes gets called
|
||||
* with very small lengths, so you should implement some kind of simple
|
||||
* buffering if you are using unbuffered reads. This should never be asked
|
||||
* to read more then 64K on a 16 bit machine.
|
||||
* to read more than 64K on a 16-bit machine.
|
||||
*/
|
||||
void /* PRIVATE */
|
||||
png_read_data(png_structrp png_ptr, png_bytep data, png_size_t length)
|
||||
png_read_data(png_structrp png_ptr, png_bytep data, size_t length)
|
||||
{
|
||||
png_debug1(4, "reading %d bytes", (int)length);
|
||||
|
||||
@ -47,14 +47,14 @@ png_read_data(png_structrp png_ptr, png_bytep data, png_size_t length)
|
||||
* than changing the library.
|
||||
*/
|
||||
void PNGCBAPI
|
||||
png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
png_default_read_data(png_structp png_ptr, png_bytep data, size_t length)
|
||||
{
|
||||
png_size_t check;
|
||||
size_t check;
|
||||
|
||||
if (png_ptr == NULL)
|
||||
return;
|
||||
|
||||
/* fread() returns 0 on error, so it is OK to store this in a png_size_t
|
||||
/* fread() returns 0 on error, so it is OK to store this in a size_t
|
||||
* instead of an int, which is what fread() actually returns.
|
||||
*/
|
||||
check = fread(data, 1, length, png_voidcast(png_FILE_p, png_ptr->io_ptr));
|
||||
@ -85,7 +85,7 @@ png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
*/
|
||||
void PNGAPI
|
||||
png_set_read_fn(png_structrp png_ptr, png_voidp io_ptr,
|
||||
png_rw_ptr read_data_fn)
|
||||
png_rw_ptr read_data_fn)
|
||||
{
|
||||
if (png_ptr == NULL)
|
||||
return;
|
||||
@ -102,6 +102,7 @@ png_set_read_fn(png_structrp png_ptr, png_voidp io_ptr,
|
||||
png_ptr->read_data_fn = read_data_fn;
|
||||
#endif
|
||||
|
||||
#ifdef PNG_WRITE_SUPPORTED
|
||||
/* It is an error to write to a read device */
|
||||
if (png_ptr->write_data_fn != NULL)
|
||||
{
|
||||
@ -110,9 +111,10 @@ png_set_read_fn(png_structrp png_ptr, png_voidp io_ptr,
|
||||
"Can't set both read_data_fn and write_data_fn in the"
|
||||
" same structure");
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PNG_WRITE_FLUSH_SUPPORTED
|
||||
png_ptr->output_flush_fn = NULL;
|
||||
#endif
|
||||
}
|
||||
#endif /* PNG_READ_SUPPORTED */
|
||||
#endif /* READ */
|
||||
|
3100
dlib/external/libpng/pngrtran.c
vendored
3100
dlib/external/libpng/pngrtran.c
vendored
File diff suppressed because it is too large
Load Diff
1446
dlib/external/libpng/pngrutil.c
vendored
1446
dlib/external/libpng/pngrutil.c
vendored
File diff suppressed because it is too large
Load Diff
539
dlib/external/libpng/pngset.c
vendored
539
dlib/external/libpng/pngset.c
vendored
File diff suppressed because it is too large
Load Diff
74
dlib/external/libpng/pngstruct.h
vendored
74
dlib/external/libpng/pngstruct.h
vendored
@ -1,11 +1,10 @@
|
||||
|
||||
/* pngstruct.h - header file for PNG reference library
|
||||
*
|
||||
* Copyright (c) 1998-2013 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.)
|
||||
*
|
||||
* Last changed in libpng 1.6.1 [March 28, 2013]
|
||||
* Copyright (c) 2018-2019 Cosmin Truta
|
||||
* Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson
|
||||
* Copyright (c) 1996-1997 Andreas Dilger
|
||||
* Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
* For conditions of distribution and use, see the disclaimer
|
||||
@ -48,7 +47,7 @@
|
||||
/* zlib.h declares a magic type 'uInt' that limits the amount of data that zlib
|
||||
* can handle at once. This type need be no larger than 16 bits (so maximum of
|
||||
* 65535), this define allows us to discover how big it is, but limited by the
|
||||
* maximuum for png_size_t. The value can be overriden in a library build
|
||||
* maximum for size_t. The value can be overridden in a library build
|
||||
* (pngusr.h, or set it in CPPFLAGS) and it works to set it to a considerably
|
||||
* lower value (e.g. 255 works). A lower value may help memory usage (slightly)
|
||||
* and may even improve performance on some systems (and degrade it on others.)
|
||||
@ -101,7 +100,7 @@ typedef struct png_XYZ
|
||||
#endif /* COLORSPACE */
|
||||
|
||||
#if defined(PNG_COLORSPACE_SUPPORTED) || defined(PNG_GAMMA_SUPPORTED)
|
||||
/* A colorspace is all the above plus, potentially, profile information,
|
||||
/* A colorspace is all the above plus, potentially, profile information;
|
||||
* however at present libpng does not use the profile internally so it is only
|
||||
* stored in the png_info struct (if iCCP is supported.) The rendering intent
|
||||
* is retained here and is checked.
|
||||
@ -215,23 +214,25 @@ struct png_struct_def
|
||||
png_uint_32 height; /* height of image in pixels */
|
||||
png_uint_32 num_rows; /* number of rows in current pass */
|
||||
png_uint_32 usr_width; /* width of row at start of write */
|
||||
png_size_t rowbytes; /* size of row in bytes */
|
||||
size_t rowbytes; /* size of row in bytes */
|
||||
png_uint_32 iwidth; /* width of current interlaced row in pixels */
|
||||
png_uint_32 row_number; /* current row in interlace pass */
|
||||
png_uint_32 chunk_name; /* PNG_CHUNK() id of current chunk */
|
||||
png_bytep prev_row; /* buffer to save previous (unfiltered) row.
|
||||
* This is a pointer into big_prev_row
|
||||
* While reading this is a pointer into
|
||||
* big_prev_row; while writing it is separately
|
||||
* allocated if needed.
|
||||
*/
|
||||
png_bytep row_buf; /* buffer to save current (unfiltered) row.
|
||||
* This is a pointer into big_row_buf
|
||||
* While reading, this is a pointer into
|
||||
* big_row_buf; while writing it is separately
|
||||
* allocated.
|
||||
*/
|
||||
#ifdef PNG_WRITE_SUPPORTED
|
||||
png_bytep sub_row; /* buffer to save "sub" row when filtering */
|
||||
png_bytep up_row; /* buffer to save "up" row when filtering */
|
||||
png_bytep avg_row; /* buffer to save "avg" row when filtering */
|
||||
png_bytep paeth_row; /* buffer to save "Paeth" row when filtering */
|
||||
#ifdef PNG_WRITE_FILTER_SUPPORTED
|
||||
png_bytep try_row; /* buffer to save trial row when filtering */
|
||||
png_bytep tst_row; /* buffer to save best trial row when filtering */
|
||||
#endif
|
||||
png_size_t info_rowbytes; /* Added in 1.5.4: cache of updated row bytes */
|
||||
size_t info_rowbytes; /* Added in 1.5.4: cache of updated row bytes */
|
||||
|
||||
png_uint_32 idat_size; /* current IDAT size for read */
|
||||
png_uint_32 crc; /* current chunk CRC value */
|
||||
@ -248,7 +249,7 @@ struct png_struct_def
|
||||
png_byte filter; /* file filter type (always 0) */
|
||||
png_byte interlaced; /* PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
|
||||
png_byte pass; /* current interlace pass (0 - 6) */
|
||||
png_byte do_filter; /* row filter flags (see PNG_FILTER_ below ) */
|
||||
png_byte do_filter; /* row filter flags (see PNG_FILTER_ in png.h ) */
|
||||
png_byte color_type; /* color type of file */
|
||||
png_byte bit_depth; /* bit depth of file */
|
||||
png_byte usr_bit_depth; /* bit depth of users row: write only */
|
||||
@ -262,6 +263,9 @@ struct png_struct_def
|
||||
/* pixel depth used for the row buffers */
|
||||
png_byte transformed_pixel_depth;
|
||||
/* pixel depth after read/write transforms */
|
||||
#if ZLIB_VERNUM >= 0x1240
|
||||
png_byte zstream_start; /* at start of an input zlib stream */
|
||||
#endif /* Zlib >= 1.2.4 */
|
||||
#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
|
||||
png_uint_16 filler; /* filler bytes for pixel expansion */
|
||||
#endif
|
||||
@ -274,7 +278,7 @@ struct png_struct_def
|
||||
#ifdef PNG_READ_GAMMA_SUPPORTED
|
||||
png_color_16 background_1; /* background normalized to gamma 1.0 */
|
||||
#endif
|
||||
#endif /* PNG_bKGD_SUPPORTED */
|
||||
#endif /* bKGD */
|
||||
|
||||
#ifdef PNG_WRITE_FLUSH_SUPPORTED
|
||||
png_flush_ptr output_flush_fn; /* Function for flushing output */
|
||||
@ -303,7 +307,7 @@ struct png_struct_def
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
|
||||
png_color_8 shift; /* shift for significant bit tranformation */
|
||||
png_color_8 shift; /* shift for significant bit transformation */
|
||||
#endif
|
||||
|
||||
#if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) \
|
||||
@ -324,14 +328,14 @@ struct png_struct_def
|
||||
png_bytep current_buffer; /* buffer for recently used data */
|
||||
png_uint_32 push_length; /* size of current input chunk */
|
||||
png_uint_32 skip_length; /* bytes to skip in input data */
|
||||
png_size_t save_buffer_size; /* amount of data now in save_buffer */
|
||||
png_size_t save_buffer_max; /* total size of save_buffer */
|
||||
png_size_t buffer_size; /* total amount of available input data */
|
||||
png_size_t current_buffer_size; /* amount of data now in current_buffer */
|
||||
size_t save_buffer_size; /* amount of data now in save_buffer */
|
||||
size_t save_buffer_max; /* total size of save_buffer */
|
||||
size_t buffer_size; /* total amount of available input data */
|
||||
size_t current_buffer_size; /* amount of data now in current_buffer */
|
||||
int process_mode; /* what push library is currently doing */
|
||||
int cur_palette; /* current push library palette index */
|
||||
|
||||
#endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
|
||||
#endif /* PROGRESSIVE_READ */
|
||||
|
||||
#if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
|
||||
/* For the Borland special 64K segment handler */
|
||||
@ -347,19 +351,9 @@ struct png_struct_def
|
||||
png_bytep quantize_index; /* index translation for palette files */
|
||||
#endif
|
||||
|
||||
#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
|
||||
png_byte heuristic_method; /* heuristic for row filter selection */
|
||||
png_byte num_prev_filters; /* number of weights for previous rows */
|
||||
png_bytep prev_filters; /* filter type(s) of previous row(s) */
|
||||
png_uint_16p filter_weights; /* weight(s) for previous line(s) */
|
||||
png_uint_16p inv_filter_weights; /* 1/weight(s) for previous line(s) */
|
||||
png_uint_16p filter_costs; /* relative filter calculation cost */
|
||||
png_uint_16p inv_filter_costs; /* 1/relative filter calculation cost */
|
||||
#endif
|
||||
|
||||
/* Options */
|
||||
/* Options */
|
||||
#ifdef PNG_SET_OPTION_SUPPORTED
|
||||
png_byte options; /* On/off state (up to 4 options) */
|
||||
png_uint_32 options; /* On/off state (up to 16 options) */
|
||||
#endif
|
||||
|
||||
#if PNG_LIBPNG_VER < 10700
|
||||
@ -398,6 +392,12 @@ struct png_struct_def
|
||||
/* deleted in 1.5.5: rgb_to_gray_blue_coeff; */
|
||||
#endif
|
||||
|
||||
/* New member added in libpng-1.6.36 */
|
||||
#if defined(PNG_READ_EXPAND_SUPPORTED) && \
|
||||
defined(PNG_ARM_NEON_IMPLEMENTATION)
|
||||
png_bytep riffled_palette; /* buffer for accelerated palette expansion */
|
||||
#endif
|
||||
|
||||
/* New member added in libpng-1.0.4 (renamed in 1.0.9) */
|
||||
#if defined(PNG_MNG_FEATURES_SUPPORTED)
|
||||
/* Changed from png_byte to png_uint_32 at version 1.2.0 */
|
||||
@ -457,7 +457,7 @@ struct png_struct_def
|
||||
#endif
|
||||
|
||||
/* New member added in libpng-1.2.26 */
|
||||
png_size_t old_big_row_buf_size;
|
||||
size_t old_big_row_buf_size;
|
||||
|
||||
#ifdef PNG_READ_SUPPORTED
|
||||
/* New member added in libpng-1.2.30 */
|
||||
|
121
dlib/external/libpng/pngtrans.c
vendored
121
dlib/external/libpng/pngtrans.c
vendored
@ -1,10 +1,10 @@
|
||||
|
||||
/* pngtrans.c - transforms the data in a row (used by both readers and writers)
|
||||
*
|
||||
* Last changed in libpng 1.6.2 [April 25, 2013]
|
||||
* Copyright (c) 1998-2013 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.)
|
||||
* Copyright (c) 2018 Cosmin Truta
|
||||
* Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson
|
||||
* Copyright (c) 1996-1997 Andreas Dilger
|
||||
* Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
* For conditions of distribution and use, see the disclaimer
|
||||
@ -30,7 +30,7 @@ png_set_bgr(png_structrp png_ptr)
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
|
||||
/* Turn on 16 bit byte swapping */
|
||||
/* Turn on 16-bit byte swapping */
|
||||
void PNGAPI
|
||||
png_set_swap(png_structrp png_ptr)
|
||||
{
|
||||
@ -57,7 +57,9 @@ png_set_packing(png_structrp png_ptr)
|
||||
if (png_ptr->bit_depth < 8)
|
||||
{
|
||||
png_ptr->transformations |= PNG_PACK;
|
||||
png_ptr->usr_bit_depth = 8;
|
||||
# ifdef PNG_WRITE_SUPPORTED
|
||||
png_ptr->usr_bit_depth = 8;
|
||||
# endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -98,7 +100,7 @@ png_set_interlace_handling(png_structrp png_ptr)
|
||||
{
|
||||
png_debug(1, "in png_set_interlace handling");
|
||||
|
||||
if (png_ptr && png_ptr->interlaced)
|
||||
if (png_ptr != 0 && png_ptr->interlaced != 0)
|
||||
{
|
||||
png_ptr->transformations |= PNG_INTERLACE;
|
||||
return (7);
|
||||
@ -125,7 +127,7 @@ png_set_filler(png_structrp png_ptr, png_uint_32 filler, int filler_loc)
|
||||
/* In libpng 1.6 it is possible to determine whether this is a read or write
|
||||
* operation and therefore to do more checking here for a valid call.
|
||||
*/
|
||||
if (png_ptr->mode & PNG_IS_READ_STRUCT)
|
||||
if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0)
|
||||
{
|
||||
# ifdef PNG_READ_FILLER_SUPPORTED
|
||||
/* On read png_set_filler is always valid, regardless of the base PNG
|
||||
@ -170,13 +172,14 @@ png_set_filler(png_structrp png_ptr, png_uint_32 filler, int filler_loc)
|
||||
* size!
|
||||
*/
|
||||
png_app_error(png_ptr,
|
||||
"png_set_filler is invalid for low bit depth gray output");
|
||||
"png_set_filler is invalid for"
|
||||
" low bit depth gray output");
|
||||
return;
|
||||
}
|
||||
|
||||
default:
|
||||
png_app_error(png_ptr,
|
||||
"png_set_filler: inappropriate color type");
|
||||
"png_set_filler: inappropriate color type");
|
||||
return;
|
||||
}
|
||||
# else
|
||||
@ -208,7 +211,7 @@ png_set_add_alpha(png_structrp png_ptr, png_uint_32 filler, int filler_loc)
|
||||
|
||||
png_set_filler(png_ptr, filler, filler_loc);
|
||||
/* The above may fail to do anything. */
|
||||
if (png_ptr->transformations & PNG_FILLER)
|
||||
if ((png_ptr->transformations & PNG_FILLER) != 0)
|
||||
png_ptr->transformations |= PNG_ADD_ALPHA;
|
||||
}
|
||||
|
||||
@ -266,8 +269,8 @@ png_do_invert(png_row_infop row_info, png_bytep row)
|
||||
if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
|
||||
{
|
||||
png_bytep rp = row;
|
||||
png_size_t i;
|
||||
png_size_t istop = row_info->rowbytes;
|
||||
size_t i;
|
||||
size_t istop = row_info->rowbytes;
|
||||
|
||||
for (i = 0; i < istop; i++)
|
||||
{
|
||||
@ -280,8 +283,8 @@ png_do_invert(png_row_infop row_info, png_bytep row)
|
||||
row_info->bit_depth == 8)
|
||||
{
|
||||
png_bytep rp = row;
|
||||
png_size_t i;
|
||||
png_size_t istop = row_info->rowbytes;
|
||||
size_t i;
|
||||
size_t istop = row_info->rowbytes;
|
||||
|
||||
for (i = 0; i < istop; i += 2)
|
||||
{
|
||||
@ -295,8 +298,8 @@ png_do_invert(png_row_infop row_info, png_bytep row)
|
||||
row_info->bit_depth == 16)
|
||||
{
|
||||
png_bytep rp = row;
|
||||
png_size_t i;
|
||||
png_size_t istop = row_info->rowbytes;
|
||||
size_t i;
|
||||
size_t istop = row_info->rowbytes;
|
||||
|
||||
for (i = 0; i < istop; i += 4)
|
||||
{
|
||||
@ -311,7 +314,7 @@ png_do_invert(png_row_infop row_info, png_bytep row)
|
||||
|
||||
#ifdef PNG_16BIT_SUPPORTED
|
||||
#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
|
||||
/* Swaps byte order on 16 bit depth images */
|
||||
/* Swaps byte order on 16-bit depth images */
|
||||
void /* PRIVATE */
|
||||
png_do_swap(png_row_infop row_info, png_bytep row)
|
||||
{
|
||||
@ -325,9 +328,16 @@ png_do_swap(png_row_infop row_info, png_bytep row)
|
||||
|
||||
for (i = 0; i < istop; i++, rp += 2)
|
||||
{
|
||||
#ifdef PNG_BUILTIN_BSWAP16_SUPPORTED
|
||||
/* Feature added to libpng-1.6.11 for testing purposes, not
|
||||
* enabled by default.
|
||||
*/
|
||||
*(png_uint_16*)rp = __builtin_bswap16(*(png_uint_16*)rp);
|
||||
#else
|
||||
png_byte t = *rp;
|
||||
*rp = *(rp + 1);
|
||||
*(rp + 1) = t;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -335,7 +345,7 @@ png_do_swap(png_row_infop row_info, png_bytep row)
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)
|
||||
static PNG_CONST png_byte onebppswaptable[256] = {
|
||||
static const png_byte onebppswaptable[256] = {
|
||||
0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0,
|
||||
0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
|
||||
0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8,
|
||||
@ -370,7 +380,7 @@ static PNG_CONST png_byte onebppswaptable[256] = {
|
||||
0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
|
||||
};
|
||||
|
||||
static PNG_CONST png_byte twobppswaptable[256] = {
|
||||
static const png_byte twobppswaptable[256] = {
|
||||
0x00, 0x40, 0x80, 0xC0, 0x10, 0x50, 0x90, 0xD0,
|
||||
0x20, 0x60, 0xA0, 0xE0, 0x30, 0x70, 0xB0, 0xF0,
|
||||
0x04, 0x44, 0x84, 0xC4, 0x14, 0x54, 0x94, 0xD4,
|
||||
@ -405,7 +415,7 @@ static PNG_CONST png_byte twobppswaptable[256] = {
|
||||
0x2F, 0x6F, 0xAF, 0xEF, 0x3F, 0x7F, 0xBF, 0xFF
|
||||
};
|
||||
|
||||
static PNG_CONST png_byte fourbppswaptable[256] = {
|
||||
static const png_byte fourbppswaptable[256] = {
|
||||
0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70,
|
||||
0x80, 0x90, 0xA0, 0xB0, 0xC0, 0xD0, 0xE0, 0xF0,
|
||||
0x01, 0x11, 0x21, 0x31, 0x41, 0x51, 0x61, 0x71,
|
||||
@ -469,7 +479,7 @@ png_do_packswap(png_row_infop row_info, png_bytep row)
|
||||
*rp = table[*rp];
|
||||
}
|
||||
}
|
||||
#endif /* PNG_READ_PACKSWAP_SUPPORTED or PNG_WRITE_PACKSWAP_SUPPORTED */
|
||||
#endif /* PACKSWAP || WRITE_PACKSWAP */
|
||||
|
||||
#if defined(PNG_WRITE_FILLER_SUPPORTED) || \
|
||||
defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
|
||||
@ -501,27 +511,35 @@ png_do_strip_channel(png_row_infop row_info, png_bytep row, int at_start)
|
||||
{
|
||||
if (row_info->bit_depth == 8)
|
||||
{
|
||||
if (at_start) /* Skip initial filler */
|
||||
if (at_start != 0) /* Skip initial filler */
|
||||
++sp;
|
||||
else /* Skip initial channel and, for sp, the filler */
|
||||
sp += 2, ++dp;
|
||||
{
|
||||
sp += 2; ++dp;
|
||||
}
|
||||
|
||||
/* For a 1 pixel wide image there is nothing to do */
|
||||
while (sp < ep)
|
||||
*dp++ = *sp, sp += 2;
|
||||
{
|
||||
*dp++ = *sp; sp += 2;
|
||||
}
|
||||
|
||||
row_info->pixel_depth = 8;
|
||||
}
|
||||
|
||||
else if (row_info->bit_depth == 16)
|
||||
{
|
||||
if (at_start) /* Skip initial filler */
|
||||
if (at_start != 0) /* Skip initial filler */
|
||||
sp += 2;
|
||||
else /* Skip initial channel and, for sp, the filler */
|
||||
sp += 4, dp += 2;
|
||||
{
|
||||
sp += 4; dp += 2;
|
||||
}
|
||||
|
||||
while (sp < ep)
|
||||
*dp++ = *sp++, *dp++ = *sp, sp += 3;
|
||||
{
|
||||
*dp++ = *sp++; *dp++ = *sp; sp += 3;
|
||||
}
|
||||
|
||||
row_info->pixel_depth = 16;
|
||||
}
|
||||
@ -541,31 +559,37 @@ png_do_strip_channel(png_row_infop row_info, png_bytep row, int at_start)
|
||||
{
|
||||
if (row_info->bit_depth == 8)
|
||||
{
|
||||
if (at_start) /* Skip initial filler */
|
||||
if (at_start != 0) /* Skip initial filler */
|
||||
++sp;
|
||||
else /* Skip initial channels and, for sp, the filler */
|
||||
sp += 4, dp += 3;
|
||||
{
|
||||
sp += 4; dp += 3;
|
||||
}
|
||||
|
||||
/* Note that the loop adds 3 to dp and 4 to sp each time. */
|
||||
while (sp < ep)
|
||||
*dp++ = *sp++, *dp++ = *sp++, *dp++ = *sp, sp += 2;
|
||||
{
|
||||
*dp++ = *sp++; *dp++ = *sp++; *dp++ = *sp; sp += 2;
|
||||
}
|
||||
|
||||
row_info->pixel_depth = 24;
|
||||
}
|
||||
|
||||
else if (row_info->bit_depth == 16)
|
||||
{
|
||||
if (at_start) /* Skip initial filler */
|
||||
if (at_start != 0) /* Skip initial filler */
|
||||
sp += 2;
|
||||
else /* Skip initial channels and, for sp, the filler */
|
||||
sp += 8, dp += 6;
|
||||
{
|
||||
sp += 8; dp += 6;
|
||||
}
|
||||
|
||||
while (sp < ep)
|
||||
{
|
||||
/* Copy 6 bytes, skip 2 */
|
||||
*dp++ = *sp++, *dp++ = *sp++;
|
||||
*dp++ = *sp++, *dp++ = *sp++;
|
||||
*dp++ = *sp++, *dp++ = *sp, sp += 3;
|
||||
*dp++ = *sp++; *dp++ = *sp++;
|
||||
*dp++ = *sp++; *dp++ = *sp++;
|
||||
*dp++ = *sp++; *dp++ = *sp; sp += 3;
|
||||
}
|
||||
|
||||
row_info->pixel_depth = 48;
|
||||
@ -585,7 +609,7 @@ png_do_strip_channel(png_row_infop row_info, png_bytep row, int at_start)
|
||||
return; /* The filler channel has gone already */
|
||||
|
||||
/* Fix the rowbytes value. */
|
||||
row_info->rowbytes = dp-row;
|
||||
row_info->rowbytes = (size_t)(dp-row);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -596,7 +620,7 @@ png_do_bgr(png_row_infop row_info, png_bytep row)
|
||||
{
|
||||
png_debug(1, "in png_do_bgr");
|
||||
|
||||
if ((row_info->color_type & PNG_COLOR_MASK_COLOR))
|
||||
if ((row_info->color_type & PNG_COLOR_MASK_COLOR) != 0)
|
||||
{
|
||||
png_uint_32 row_width = row_info->width;
|
||||
if (row_info->bit_depth == 8)
|
||||
@ -666,7 +690,7 @@ png_do_bgr(png_row_infop row_info, png_bytep row)
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif /* PNG_READ_BGR_SUPPORTED or PNG_WRITE_BGR_SUPPORTED */
|
||||
#endif /* READ_BGR || WRITE_BGR */
|
||||
|
||||
#if defined(PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED) || \
|
||||
defined(PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED)
|
||||
@ -683,8 +707,8 @@ png_do_check_palette_indexes(png_structrp png_ptr, png_row_infop row_info)
|
||||
* and this calculation is used because it avoids warnings that other
|
||||
* forms produced on either GCC or MSVC.
|
||||
*/
|
||||
int padding = (-row_info->pixel_depth * row_info->width) & 7;
|
||||
png_bytep rp = png_ptr->row_buf + row_info->rowbytes;
|
||||
int padding = PNG_PADBITS(row_info->pixel_depth, row_info->width);
|
||||
png_bytep rp = png_ptr->row_buf + row_info->rowbytes - 1;
|
||||
|
||||
switch (row_info->bit_depth)
|
||||
{
|
||||
@ -695,7 +719,7 @@ png_do_check_palette_indexes(png_structrp png_ptr, png_row_infop row_info)
|
||||
*/
|
||||
for (; rp > png_ptr->row_buf; rp--)
|
||||
{
|
||||
if (*rp >> padding != 0)
|
||||
if ((*rp >> padding) != 0)
|
||||
png_ptr->num_palette_max = 1;
|
||||
padding = 0;
|
||||
}
|
||||
@ -769,7 +793,7 @@ png_do_check_palette_indexes(png_structrp png_ptr, png_row_infop row_info)
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED */
|
||||
#endif /* CHECK_FOR_INVALID_INDEX */
|
||||
|
||||
#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
|
||||
defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
|
||||
@ -788,7 +812,7 @@ png_set_user_transform_info(png_structrp png_ptr, png_voidp
|
||||
(png_ptr->flags & PNG_FLAG_ROW_INIT) != 0)
|
||||
{
|
||||
png_app_error(png_ptr,
|
||||
"info change after png_start_read_image or png_read_update_info");
|
||||
"info change after png_start_read_image or png_read_update_info");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
@ -819,7 +843,7 @@ png_get_user_transform_ptr(png_const_structrp png_ptr)
|
||||
png_uint_32 PNGAPI
|
||||
png_get_current_row_number(png_const_structrp png_ptr)
|
||||
{
|
||||
/* See the comments in png.h - this is the sub-image row when reading and
|
||||
/* See the comments in png.h - this is the sub-image row when reading an
|
||||
* interlaced image.
|
||||
*/
|
||||
if (png_ptr != NULL)
|
||||
@ -835,7 +859,6 @@ png_get_current_pass_number(png_const_structrp png_ptr)
|
||||
return png_ptr->pass;
|
||||
return 8; /* invalid */
|
||||
}
|
||||
#endif /* PNG_USER_TRANSFORM_INFO_SUPPORTED */
|
||||
#endif /* PNG_READ_USER_TRANSFORM_SUPPORTED ||
|
||||
PNG_WRITE_USER_TRANSFORM_SUPPORTED */
|
||||
#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
|
||||
#endif /* USER_TRANSFORM_INFO */
|
||||
#endif /* READ_USER_TRANSFORM || WRITE_USER_TRANSFORM */
|
||||
#endif /* READ || WRITE */
|
||||
|
26
dlib/external/libpng/pngwio.c
vendored
26
dlib/external/libpng/pngwio.c
vendored
@ -1,10 +1,10 @@
|
||||
|
||||
/* pngwio.c - functions for data output
|
||||
*
|
||||
* Last changed in libpng 1.6.0 [February 14, 2013]
|
||||
* Copyright (c) 1998-2013 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.)
|
||||
* Copyright (c) 2018 Cosmin Truta
|
||||
* Copyright (c) 1998-2002,2004,2006-2014,2016,2018 Glenn Randers-Pehrson
|
||||
* Copyright (c) 1996-1997 Andreas Dilger
|
||||
* Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
* For conditions of distribution and use, see the disclaimer
|
||||
@ -26,16 +26,16 @@
|
||||
* writes to a file pointer. Note that this routine sometimes gets called
|
||||
* with very small lengths, so you should implement some kind of simple
|
||||
* buffering if you are using unbuffered writes. This should never be asked
|
||||
* to write more than 64K on a 16 bit machine.
|
||||
* to write more than 64K on a 16-bit machine.
|
||||
*/
|
||||
|
||||
void /* PRIVATE */
|
||||
png_write_data(png_structrp png_ptr, png_const_bytep data, png_size_t length)
|
||||
png_write_data(png_structrp png_ptr, png_const_bytep data, size_t length)
|
||||
{
|
||||
/* NOTE: write_data_fn must not change the buffer! */
|
||||
if (png_ptr->write_data_fn != NULL )
|
||||
(*(png_ptr->write_data_fn))(png_ptr, png_constcast(png_bytep,data),
|
||||
length);
|
||||
length);
|
||||
|
||||
else
|
||||
png_error(png_ptr, "Call to NULL write function");
|
||||
@ -48,9 +48,9 @@ png_write_data(png_structrp png_ptr, png_const_bytep data, png_size_t length)
|
||||
* than changing the library.
|
||||
*/
|
||||
void PNGCBAPI
|
||||
png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
png_default_write_data(png_structp png_ptr, png_bytep data, size_t length)
|
||||
{
|
||||
png_size_t check;
|
||||
size_t check;
|
||||
|
||||
if (png_ptr == NULL)
|
||||
return;
|
||||
@ -149,8 +149,11 @@ png_set_write_fn(png_structrp png_ptr, png_voidp io_ptr,
|
||||
# else
|
||||
png_ptr->output_flush_fn = output_flush_fn;
|
||||
# endif
|
||||
#endif /* PNG_WRITE_FLUSH_SUPPORTED */
|
||||
#else
|
||||
PNG_UNUSED(output_flush_fn)
|
||||
#endif /* WRITE_FLUSH */
|
||||
|
||||
#ifdef PNG_READ_SUPPORTED
|
||||
/* It is an error to read while writing a png file */
|
||||
if (png_ptr->read_data_fn != NULL)
|
||||
{
|
||||
@ -160,5 +163,6 @@ png_set_write_fn(png_structrp png_ptr, png_voidp io_ptr,
|
||||
"Can't set both read_data_fn and write_data_fn in the"
|
||||
" same structure");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif /* PNG_WRITE_SUPPORTED */
|
||||
#endif /* WRITE */
|
||||
|
1239
dlib/external/libpng/pngwrite.c
vendored
1239
dlib/external/libpng/pngwrite.c
vendored
File diff suppressed because it is too large
Load Diff
246
dlib/external/libpng/pngwtran.c
vendored
246
dlib/external/libpng/pngwtran.c
vendored
@ -1,10 +1,10 @@
|
||||
|
||||
/* pngwtran.c - transforms the data in a row for PNG writers
|
||||
*
|
||||
* Last changed in libpng 1.6.0 [February 14, 2013]
|
||||
* Copyright (c) 1998-2013 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.)
|
||||
* Copyright (c) 2018 Cosmin Truta
|
||||
* Copyright (c) 1998-2002,2004,2006-2016,2018 Glenn Randers-Pehrson
|
||||
* Copyright (c) 1996-1997 Andreas Dilger
|
||||
* Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
*
|
||||
* This code is released under the libpng license.
|
||||
* For conditions of distribution and use, see the disclaimer
|
||||
@ -14,90 +14,14 @@
|
||||
#include "pngpriv.h"
|
||||
|
||||
#ifdef PNG_WRITE_SUPPORTED
|
||||
|
||||
#ifdef PNG_WRITE_TRANSFORMS_SUPPORTED
|
||||
/* Transform the data according to the user's wishes. The order of
|
||||
* transformations is significant.
|
||||
*/
|
||||
void /* PRIVATE */
|
||||
png_do_write_transformations(png_structrp png_ptr, png_row_infop row_info)
|
||||
{
|
||||
png_debug(1, "in png_do_write_transformations");
|
||||
|
||||
if (png_ptr == NULL)
|
||||
return;
|
||||
|
||||
#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 */
|
||||
(png_ptr, /* png_ptr */
|
||||
row_info, /* row_info: */
|
||||
/* png_uint_32 width; width of row */
|
||||
/* png_size_t rowbytes; number of bytes in row */
|
||||
/* png_byte color_type; color type of pixels */
|
||||
/* png_byte bit_depth; bit depth of samples */
|
||||
/* png_byte channels; number of channels (1-4) */
|
||||
/* png_byte pixel_depth; bits per pixel (depth*channels) */
|
||||
png_ptr->row_buf + 1); /* start of pixel data for row */
|
||||
#endif
|
||||
|
||||
#ifdef PNG_WRITE_FILLER_SUPPORTED
|
||||
if (png_ptr->transformations & PNG_FILLER)
|
||||
png_do_strip_channel(row_info, png_ptr->row_buf + 1,
|
||||
!(png_ptr->flags & PNG_FLAG_FILLER_AFTER));
|
||||
#endif
|
||||
|
||||
#ifdef PNG_WRITE_PACKSWAP_SUPPORTED
|
||||
if (png_ptr->transformations & PNG_PACKSWAP)
|
||||
png_do_packswap(row_info, png_ptr->row_buf + 1);
|
||||
#endif
|
||||
|
||||
#ifdef PNG_WRITE_PACK_SUPPORTED
|
||||
if (png_ptr->transformations & PNG_PACK)
|
||||
png_do_pack(row_info, png_ptr->row_buf + 1,
|
||||
(png_uint_32)png_ptr->bit_depth);
|
||||
#endif
|
||||
|
||||
#ifdef PNG_WRITE_SWAP_SUPPORTED
|
||||
if (png_ptr->transformations & PNG_SWAP_BYTES)
|
||||
png_do_swap(row_info, png_ptr->row_buf + 1);
|
||||
#endif
|
||||
|
||||
#ifdef PNG_WRITE_SHIFT_SUPPORTED
|
||||
if (png_ptr->transformations & PNG_SHIFT)
|
||||
png_do_shift(row_info, png_ptr->row_buf + 1,
|
||||
&(png_ptr->shift));
|
||||
#endif
|
||||
|
||||
#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED
|
||||
if (png_ptr->transformations & PNG_SWAP_ALPHA)
|
||||
png_do_write_swap_alpha(row_info, png_ptr->row_buf + 1);
|
||||
#endif
|
||||
|
||||
#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED
|
||||
if (png_ptr->transformations & PNG_INVERT_ALPHA)
|
||||
png_do_write_invert_alpha(row_info, png_ptr->row_buf + 1);
|
||||
#endif
|
||||
|
||||
#ifdef PNG_WRITE_BGR_SUPPORTED
|
||||
if (png_ptr->transformations & PNG_BGR)
|
||||
png_do_bgr(row_info, png_ptr->row_buf + 1);
|
||||
#endif
|
||||
|
||||
#ifdef PNG_WRITE_INVERT_SUPPORTED
|
||||
if (png_ptr->transformations & PNG_INVERT_MONO)
|
||||
png_do_invert(row_info, png_ptr->row_buf + 1);
|
||||
#endif
|
||||
}
|
||||
|
||||
#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).
|
||||
*/
|
||||
void /* PRIVATE */
|
||||
static void
|
||||
png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth)
|
||||
{
|
||||
png_debug(1, "in png_do_pack");
|
||||
@ -147,7 +71,8 @@ png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth)
|
||||
case 2:
|
||||
{
|
||||
png_bytep sp, dp;
|
||||
int shift, v;
|
||||
unsigned int shift;
|
||||
int v;
|
||||
png_uint_32 i;
|
||||
png_uint_32 row_width = row_info->width;
|
||||
|
||||
@ -186,7 +111,8 @@ png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth)
|
||||
case 4:
|
||||
{
|
||||
png_bytep sp, dp;
|
||||
int shift, v;
|
||||
unsigned int shift;
|
||||
int v;
|
||||
png_uint_32 i;
|
||||
png_uint_32 row_width = row_info->width;
|
||||
|
||||
@ -242,7 +168,7 @@ png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth)
|
||||
* would pass 3 as bit_depth, and this routine would translate the
|
||||
* data to 0 to 15.
|
||||
*/
|
||||
void /* PRIVATE */
|
||||
static void
|
||||
png_do_shift(png_row_infop row_info, png_bytep row,
|
||||
png_const_color_8p bit_depth)
|
||||
{
|
||||
@ -251,9 +177,9 @@ png_do_shift(png_row_infop row_info, png_bytep row,
|
||||
if (row_info->color_type != PNG_COLOR_TYPE_PALETTE)
|
||||
{
|
||||
int shift_start[4], shift_dec[4];
|
||||
int channels = 0;
|
||||
unsigned int channels = 0;
|
||||
|
||||
if (row_info->color_type & PNG_COLOR_MASK_COLOR)
|
||||
if ((row_info->color_type & PNG_COLOR_MASK_COLOR) != 0)
|
||||
{
|
||||
shift_start[channels] = row_info->bit_depth - bit_depth->red;
|
||||
shift_dec[channels] = bit_depth->red;
|
||||
@ -275,7 +201,7 @@ png_do_shift(png_row_infop row_info, png_bytep row,
|
||||
channels++;
|
||||
}
|
||||
|
||||
if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
|
||||
if ((row_info->color_type & PNG_COLOR_MASK_ALPHA) != 0)
|
||||
{
|
||||
shift_start[channels] = row_info->bit_depth - bit_depth->alpha;
|
||||
shift_dec[channels] = bit_depth->alpha;
|
||||
@ -286,9 +212,9 @@ png_do_shift(png_row_infop row_info, png_bytep row,
|
||||
if (row_info->bit_depth < 8)
|
||||
{
|
||||
png_bytep bp = row;
|
||||
png_size_t i;
|
||||
size_t i;
|
||||
unsigned int mask;
|
||||
png_size_t row_bytes = row_info->rowbytes;
|
||||
size_t row_bytes = row_info->rowbytes;
|
||||
|
||||
if (bit_depth->gray == 1 && row_info->bit_depth == 2)
|
||||
mask = 0x55;
|
||||
@ -328,8 +254,7 @@ png_do_shift(png_row_infop row_info, png_bytep row,
|
||||
|
||||
for (i = 0; i < istop; i++, bp++)
|
||||
{
|
||||
|
||||
const unsigned int c = i%channels;
|
||||
unsigned int c = i%channels;
|
||||
int j;
|
||||
unsigned int v, out;
|
||||
|
||||
@ -357,7 +282,7 @@ png_do_shift(png_row_infop row_info, png_bytep row,
|
||||
|
||||
for (bp = row, i = 0; i < istop; i++)
|
||||
{
|
||||
const unsigned int c = i%channels;
|
||||
unsigned int c = i%channels;
|
||||
int j;
|
||||
unsigned int value, v;
|
||||
|
||||
@ -381,7 +306,7 @@ png_do_shift(png_row_infop row_info, png_bytep row,
|
||||
#endif
|
||||
|
||||
#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED
|
||||
void /* PRIVATE */
|
||||
static void
|
||||
png_do_write_swap_alpha(png_row_infop row_info, png_bytep row)
|
||||
{
|
||||
png_debug(1, "in png_do_write_swap_alpha");
|
||||
@ -429,7 +354,7 @@ png_do_write_swap_alpha(png_row_infop row_info, png_bytep row)
|
||||
*(dp++) = save[1];
|
||||
}
|
||||
}
|
||||
#endif /* PNG_WRITE_16BIT_SUPPORTED */
|
||||
#endif /* WRITE_16BIT */
|
||||
}
|
||||
|
||||
else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
|
||||
@ -468,14 +393,14 @@ png_do_write_swap_alpha(png_row_infop row_info, png_bytep row)
|
||||
*(dp++) = save[1];
|
||||
}
|
||||
}
|
||||
#endif /* PNG_WRITE_16BIT_SUPPORTED */
|
||||
#endif /* WRITE_16BIT */
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED
|
||||
void /* PRIVATE */
|
||||
static void
|
||||
png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
|
||||
{
|
||||
png_debug(1, "in png_do_write_invert_alpha");
|
||||
@ -498,7 +423,7 @@ png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
|
||||
*(dp++) = *(sp++);
|
||||
*/
|
||||
sp+=3; dp = sp;
|
||||
*(dp++) = (png_byte)(255 - *(sp++));
|
||||
*dp = (png_byte)(255 - *(sp++));
|
||||
}
|
||||
}
|
||||
|
||||
@ -522,10 +447,10 @@ png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
|
||||
*/
|
||||
sp+=6; dp = sp;
|
||||
*(dp++) = (png_byte)(255 - *(sp++));
|
||||
*(dp++) = (png_byte)(255 - *(sp++));
|
||||
*dp = (png_byte)(255 - *(sp++));
|
||||
}
|
||||
}
|
||||
#endif /* PNG_WRITE_16BIT_SUPPORTED */
|
||||
#endif /* WRITE_16BIT */
|
||||
}
|
||||
|
||||
else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
|
||||
@ -560,78 +485,91 @@ png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
|
||||
*/
|
||||
sp+=2; dp = sp;
|
||||
*(dp++) = (png_byte)(255 - *(sp++));
|
||||
*(dp++) = (png_byte)(255 - *(sp++));
|
||||
*dp = (png_byte)(255 - *(sp++));
|
||||
}
|
||||
}
|
||||
#endif /* PNG_WRITE_16BIT_SUPPORTED */
|
||||
#endif /* WRITE_16BIT */
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif /* PNG_WRITE_TRANSFORMS_SUPPORTED */
|
||||
|
||||
#ifdef PNG_MNG_FEATURES_SUPPORTED
|
||||
/* Undoes intrapixel differencing */
|
||||
/* Transform the data according to the user's wishes. The order of
|
||||
* transformations is significant.
|
||||
*/
|
||||
void /* PRIVATE */
|
||||
png_do_write_intrapixel(png_row_infop row_info, png_bytep row)
|
||||
png_do_write_transformations(png_structrp png_ptr, png_row_infop row_info)
|
||||
{
|
||||
png_debug(1, "in png_do_write_intrapixel");
|
||||
png_debug(1, "in png_do_write_transformations");
|
||||
|
||||
if ((row_info->color_type & PNG_COLOR_MASK_COLOR))
|
||||
{
|
||||
int bytes_per_pixel;
|
||||
png_uint_32 row_width = row_info->width;
|
||||
if (row_info->bit_depth == 8)
|
||||
{
|
||||
png_bytep rp;
|
||||
png_uint_32 i;
|
||||
if (png_ptr == NULL)
|
||||
return;
|
||||
|
||||
if (row_info->color_type == PNG_COLOR_TYPE_RGB)
|
||||
bytes_per_pixel = 3;
|
||||
#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
|
||||
if ((png_ptr->transformations & PNG_USER_TRANSFORM) != 0)
|
||||
if (png_ptr->write_user_transform_fn != NULL)
|
||||
(*(png_ptr->write_user_transform_fn)) /* User write transform
|
||||
function */
|
||||
(png_ptr, /* png_ptr */
|
||||
row_info, /* row_info: */
|
||||
/* png_uint_32 width; width of row */
|
||||
/* size_t rowbytes; number of bytes in row */
|
||||
/* png_byte color_type; color type of pixels */
|
||||
/* png_byte bit_depth; bit depth of samples */
|
||||
/* png_byte channels; number of channels (1-4) */
|
||||
/* png_byte pixel_depth; bits per pixel (depth*channels) */
|
||||
png_ptr->row_buf + 1); /* start of pixel data for row */
|
||||
#endif
|
||||
|
||||
else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
|
||||
bytes_per_pixel = 4;
|
||||
#ifdef PNG_WRITE_FILLER_SUPPORTED
|
||||
if ((png_ptr->transformations & PNG_FILLER) != 0)
|
||||
png_do_strip_channel(row_info, png_ptr->row_buf + 1,
|
||||
!(png_ptr->flags & PNG_FLAG_FILLER_AFTER));
|
||||
#endif
|
||||
|
||||
else
|
||||
return;
|
||||
#ifdef PNG_WRITE_PACKSWAP_SUPPORTED
|
||||
if ((png_ptr->transformations & PNG_PACKSWAP) != 0)
|
||||
png_do_packswap(row_info, png_ptr->row_buf + 1);
|
||||
#endif
|
||||
|
||||
for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
|
||||
{
|
||||
*(rp) = (png_byte)((*rp - *(rp + 1)) & 0xff);
|
||||
*(rp + 2) = (png_byte)((*(rp + 2) - *(rp + 1)) & 0xff);
|
||||
}
|
||||
}
|
||||
#ifdef PNG_WRITE_PACK_SUPPORTED
|
||||
if ((png_ptr->transformations & PNG_PACK) != 0)
|
||||
png_do_pack(row_info, png_ptr->row_buf + 1,
|
||||
(png_uint_32)png_ptr->bit_depth);
|
||||
#endif
|
||||
|
||||
#ifdef PNG_WRITE_16BIT_SUPPORTED
|
||||
else if (row_info->bit_depth == 16)
|
||||
{
|
||||
png_bytep rp;
|
||||
png_uint_32 i;
|
||||
#ifdef PNG_WRITE_SWAP_SUPPORTED
|
||||
# ifdef PNG_16BIT_SUPPORTED
|
||||
if ((png_ptr->transformations & PNG_SWAP_BYTES) != 0)
|
||||
png_do_swap(row_info, png_ptr->row_buf + 1);
|
||||
# endif
|
||||
#endif
|
||||
|
||||
if (row_info->color_type == PNG_COLOR_TYPE_RGB)
|
||||
bytes_per_pixel = 6;
|
||||
#ifdef PNG_WRITE_SHIFT_SUPPORTED
|
||||
if ((png_ptr->transformations & PNG_SHIFT) != 0)
|
||||
png_do_shift(row_info, png_ptr->row_buf + 1,
|
||||
&(png_ptr->shift));
|
||||
#endif
|
||||
|
||||
else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
|
||||
bytes_per_pixel = 8;
|
||||
#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED
|
||||
if ((png_ptr->transformations & PNG_SWAP_ALPHA) != 0)
|
||||
png_do_write_swap_alpha(row_info, png_ptr->row_buf + 1);
|
||||
#endif
|
||||
|
||||
else
|
||||
return;
|
||||
#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED
|
||||
if ((png_ptr->transformations & PNG_INVERT_ALPHA) != 0)
|
||||
png_do_write_invert_alpha(row_info, png_ptr->row_buf + 1);
|
||||
#endif
|
||||
|
||||
for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
|
||||
{
|
||||
png_uint_32 s0 = (*(rp ) << 8) | *(rp + 1);
|
||||
png_uint_32 s1 = (*(rp + 2) << 8) | *(rp + 3);
|
||||
png_uint_32 s2 = (*(rp + 4) << 8) | *(rp + 5);
|
||||
png_uint_32 red = (png_uint_32)((s0 - s1) & 0xffffL);
|
||||
png_uint_32 blue = (png_uint_32)((s2 - s1) & 0xffffL);
|
||||
*(rp ) = (png_byte)((red >> 8) & 0xff);
|
||||
*(rp + 1) = (png_byte)(red & 0xff);
|
||||
*(rp + 4) = (png_byte)((blue >> 8) & 0xff);
|
||||
*(rp + 5) = (png_byte)(blue & 0xff);
|
||||
}
|
||||
}
|
||||
#endif /* PNG_WRITE_16BIT_SUPPORTED */
|
||||
}
|
||||
#ifdef PNG_WRITE_BGR_SUPPORTED
|
||||
if ((png_ptr->transformations & PNG_BGR) != 0)
|
||||
png_do_bgr(row_info, png_ptr->row_buf + 1);
|
||||
#endif
|
||||
|
||||
#ifdef PNG_WRITE_INVERT_SUPPORTED
|
||||
if ((png_ptr->transformations & PNG_INVERT_MONO) != 0)
|
||||
png_do_invert(row_info, png_ptr->row_buf + 1);
|
||||
#endif
|
||||
}
|
||||
#endif /* PNG_MNG_FEATURES_SUPPORTED */
|
||||
#endif /* PNG_WRITE_SUPPORTED */
|
||||
#endif /* WRITE_TRANSFORMS */
|
||||
#endif /* WRITE */
|
||||
|
1434
dlib/external/libpng/pngwutil.c
vendored
1434
dlib/external/libpng/pngwutil.c
vendored
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user