Merge remote-tracking branch 'upstream/3.4' into merge-3.4

This commit is contained in:
Alexander Alekhin 2019-02-19 19:36:46 +00:00
commit 8bde6aea4b
137 changed files with 9339 additions and 4401 deletions

View File

@ -6063,9 +6063,34 @@ Version 1.6.35 [July 15, 2018]
Added missing parentheses to a macro definition
(suggested by "irwir" in GitHub issue #216)
Version 1.6.36 [December 1, 2018]
Optimized png_do_expand_palette for ARM processors.
Improved performance by around 10-22% on a recent ARM Chromebook.
(Contributed by Richard Townsend, ARM Holdings)
Fixed manipulation of machine-specific optimization options.
(Contributed by Vicki Pfau)
Used memcpy instead of manual pointer arithmetic on Intel SSE2.
(Contributed by Samuel Williams)
Fixed build errors with MSVC on ARM64.
(Contributed by Zhijie Liang)
Fixed detection of libm in CMakeLists.
(Contributed by Cameron Cawley)
Fixed incorrect creation of pkg-config file in CMakeLists.
(Contributed by Kyle Bentley)
Fixed the CMake build on Windows MSYS by avoiding symlinks.
Fixed a build warning on OpenBSD.
(Contributed by Theo Buehler)
Fixed various typos in comments.
(Contributed by "luz.paz")
Raised the minimum required CMake version from 3.0.2 to 3.1.
Removed yet more of the vestigial support for pre-ANSI C compilers.
Removed ancient makefiles for ancient systems that have been broken
across all previous libpng-1.6.x versions.
Removed the Y2K compliance statement and the export control
information.
Applied various code style and documentation fixes.
Send comments/corrections/commendations to png-mng-implement at lists.sf.net
(subscription required; visit
https://lists.sourceforge.net/lists/listinfo/png-mng-implement
to subscribe).
Glenn R-P

View File

@ -29,8 +29,11 @@ file(GLOB lib_hdrs *.h)
if(ARM OR AARCH64)
if(ENABLE_NEON AND NOT AARCH64)
list(APPEND lib_srcs arm/arm_init.c arm/filter_neon.S arm/filter_neon_intrinsics.c)
if(ENABLE_NEON)
if(NOT AARCH64)
list(APPEND lib_srcs arm/filter_neon.S)
endif()
list(APPEND lib_srcs arm/arm_init.c arm/filter_neon_intrinsics.c arm/palette_neon_intrinsics.c)
add_definitions(-DPNG_ARM_NEON_OPT=2)
else()
add_definitions(-DPNG_ARM_NEON_OPT=0) # NEON assembler is not supported
@ -63,7 +66,7 @@ endif(MSVC)
add_library(${PNG_LIBRARY} STATIC ${lib_srcs} ${lib_hdrs})
target_link_libraries(${PNG_LIBRARY} ${ZLIB_LIBRARIES})
ocv_warnings_disable(CMAKE_C_FLAGS -Wundef -Wcast-align -Wimplicit-fallthrough)
ocv_warnings_disable(CMAKE_C_FLAGS -Wundef -Wcast-align -Wimplicit-fallthrough -Wunused-parameter -Wsign-compare)
set_target_properties(${PNG_LIBRARY}
PROPERTIES OUTPUT_NAME ${PNG_LIBRARY}

View File

@ -1,14 +1,43 @@
COPYRIGHT NOTICE, DISCLAIMER, and LICENSE
=========================================
This copy of the libpng notices is provided for your convenience. In case of
any discrepancy between this copy and the notices in the file png.h that is
included in the libpng distribution, the latter shall prevail.
PNG Reference Library License version 2
---------------------------------------
COPYRIGHT NOTICE, DISCLAIMER, and LICENSE:
* Copyright (c) 1995-2018 The PNG Reference Library Authors.
* Copyright (c) 2018 Cosmin Truta.
* Copyright (c) 2000-2002, 2004, 2006-2018 Glenn Randers-Pehrson.
* Copyright (c) 1996-1997 Andreas Dilger.
* Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
If you modify libpng you may insert additional notices immediately following
this sentence.
The software is supplied "as is", without warranty of any kind,
express or implied, including, without limitation, the warranties
of merchantability, fitness for a particular purpose, title, and
non-infringement. In no even shall the Copyright owners, or
anyone distributing the software, be liable for any damages or
other liability, whether in contract, tort or otherwise, arising
from, out of, or in connection with the software, or the use or
other dealings in the software, even if advised of the possibility
of such damage.
This code is released under the libpng license.
Permission is hereby granted to use, copy, modify, and distribute
this software, or portions hereof, for any purpose, without fee,
subject to the following restrictions:
1. The origin of this software must not be misrepresented; you
must not claim that you wrote the original software. If you
use this software in a product, an acknowledgment in the product
documentation would be appreciated, but is not required.
2. Altered source versions must be plainly marked as such, and must
not be misrepresented as being the original software.
3. This Copyright notice may not be removed or altered from any
source or altered source distribution.
PNG Reference Library License version 1 (for libpng 0.5 through 1.6.35)
-----------------------------------------------------------------------
libpng versions 1.0.7, July 1, 2000 through 1.6.35, July 15, 2018 are
Copyright (c) 2000-2002, 2004, 2006-2018 Glenn Randers-Pehrson, are
@ -16,38 +45,38 @@ derived from libpng-1.0.6, and are distributed according to the same
disclaimer and license as libpng-1.0.6 with the following individuals
added to the list of Contributing Authors:
Simon-Pierre Cadieux
Eric S. Raymond
Mans Rullgard
Cosmin Truta
Gilles Vollant
James Yu
Mandar Sahastrabuddhe
Google Inc.
Vadim Barkov
Simon-Pierre Cadieux
Eric S. Raymond
Mans Rullgard
Cosmin Truta
Gilles Vollant
James Yu
Mandar Sahastrabuddhe
Google Inc.
Vadim Barkov
and with the following additions to the disclaimer:
There is no warranty against interference with your enjoyment of the
library or against infringement. There is no warranty that our
efforts or the library will fulfill any of your particular purposes
or needs. This library is provided with all faults, and the entire
risk of satisfactory quality, performance, accuracy, and effort is with
the user.
There is no warranty against interference with your enjoyment of
the library or against infringement. There is no warranty that our
efforts or the library will fulfill any of your particular purposes
or needs. This library is provided with all faults, and the entire
risk of satisfactory quality, performance, accuracy, and effort is
with the user.
Some files in the "contrib" directory and some configure-generated
files that are distributed with libpng have other copyright owners and
files that are distributed with libpng have other copyright owners, and
are released under other open source licenses.
libpng versions 0.97, January 1998, through 1.0.6, March 20, 2000, are
Copyright (c) 1998-2000 Glenn Randers-Pehrson, are derived from
libpng-0.96, and are distributed according to the same disclaimer and
license as libpng-0.96, with the following individuals added to the list
of Contributing Authors:
license as libpng-0.96, with the following individuals added to the
list of Contributing Authors:
Tom Lane
Glenn Randers-Pehrson
Willem van Schaik
Tom Lane
Glenn Randers-Pehrson
Willem van Schaik
libpng versions 0.89, June 1996, through 0.96, May 1997, are
Copyright (c) 1996-1997 Andreas Dilger, are derived from libpng-0.88,
@ -55,14 +84,14 @@ and are distributed according to the same disclaimer and license as
libpng-0.88, with the following individuals added to the list of
Contributing Authors:
John Bowler
Kevin Bracey
Sam Bushell
Magnus Holmgren
Greg Roelofs
Tom Tanner
John Bowler
Kevin Bracey
Sam Bushell
Magnus Holmgren
Greg Roelofs
Tom Tanner
Some files in the "scripts" directory have other copyright owners
Some files in the "scripts" directory have other copyright owners,
but are released under this license.
libpng versions 0.5, May 1995, through 0.88, January 1996, are
@ -71,63 +100,35 @@ Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
For the purposes of this copyright and license, "Contributing Authors"
is defined as the following set of individuals:
Andreas Dilger
Dave Martindale
Guy Eric Schalnat
Paul Schmidt
Tim Wegner
Andreas Dilger
Dave Martindale
Guy Eric Schalnat
Paul Schmidt
Tim Wegner
The PNG Reference Library is supplied "AS IS". The Contributing Authors
and Group 42, Inc. disclaim all warranties, expressed or implied,
including, without limitation, the warranties of merchantability and of
fitness for any purpose. The Contributing Authors and Group 42, Inc.
assume no liability for direct, indirect, incidental, special, exemplary,
or consequential damages, which may result from the use of the PNG
Reference Library, even if advised of the possibility of such damage.
The PNG Reference Library is supplied "AS IS". The Contributing
Authors and Group 42, Inc. disclaim all warranties, expressed or
implied, including, without limitation, the warranties of
merchantability and of fitness for any purpose. The Contributing
Authors and Group 42, Inc. assume no liability for direct, indirect,
incidental, special, exemplary, or consequential damages, which may
result from the use of the PNG Reference Library, even if advised of
the possibility of such damage.
Permission is hereby granted to use, copy, modify, and distribute this
source code, or portions hereof, for any purpose, without fee, subject
to the following restrictions:
1. The origin of this source code must not be misrepresented.
1. The origin of this source code must not be misrepresented.
2. Altered versions must be plainly marked as such and must not
be misrepresented as being the original source.
2. Altered versions must be plainly marked as such and must not
be misrepresented as being the original source.
3. This Copyright notice may not be removed or altered from any
source or altered source distribution.
3. This Copyright notice may not be removed or altered from any
source or altered source distribution.
The Contributing Authors and Group 42, Inc. specifically permit, without
fee, and encourage the use of this source code as a component to
supporting the PNG file format in commercial products. If you use this
source code in a product, acknowledgment is not required but would be
appreciated.
END OF COPYRIGHT NOTICE, DISCLAIMER, and LICENSE.
TRADEMARK:
The name "libpng" has not been registered by the Copyright owner
as a trademark in any jurisdiction. However, because libpng has
been distributed and maintained world-wide, continually since 1995,
the Copyright owner claims "common-law trademark protection" in any
jurisdiction where common-law trademark is recognized.
OSI CERTIFICATION:
Libpng is OSI Certified Open Source Software. OSI Certified Open Source is
a certification mark of the Open Source Initiative. OSI has not addressed
the additional disclaimers inserted at version 1.0.7.
EXPORT CONTROL:
The Copyright owner believes that the Export Control Classification
Number (ECCN) for libpng is EAR99, which means not subject to export
controls or International Traffic in Arms Regulations (ITAR) because
it is open source, publicly available software, that does not contain
any encryption software. See the EAR, paragraphs 734.3(b)(3) and
734.7(b).
Glenn Randers-Pehrson
glennrp at users.sourceforge.net
July 15, 2018
The Contributing Authors and Group 42, Inc. specifically permit,
without fee, and encourage the use of this source code as a component
to supporting the PNG file format in commercial products. If you use
this source code in a product, acknowledgment is not required but would
be appreciated.

109
3rdparty/libpng/README vendored
View File

@ -1,15 +1,16 @@
README for libpng version 1.6.35 - July 15, 2018 (shared library 16.0)
See the note about version numbers near the top of png.h
README for libpng version 1.6.36 - December 1, 2018
===================================================
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
@ -60,59 +61,37 @@ 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/pngdocs.html .
This code is currently being archived at libpng.sourceforge.io in the
[DOWNLOAD] area, and at http://libpng.download/src . If you
can't find it in any of those places, e-mail me, and I'll help you find it.
[DOWNLOAD] area, and at http://libpng.download/src .
I am not a lawyer, but I believe that the Export Control Classification
Number (ECCN) for libpng is EAR99, which means not subject to export
controls or International Traffic in Arms Regulations (ITAR) because it
is open source, publicly available software, that does not contain any
encryption software. See the EAR, paragraphs 734.3(b)(3) and 734.7(b).
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
@ -120,34 +99,21 @@ lists.sourceforge.net (subscription required; visit
https://lists.sourceforge.net/lists/listinfo/png-mng-implement
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 twenty 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
@ -208,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.)

View File

@ -1,14 +1,15 @@
/* arm_init.c - NEON optimised filter functions
*
* Copyright (c) 2018 Cosmin Truta
* Copyright (c) 2014,2016 Glenn Randers-Pehrson
* Written by Mans Rullgard, 2011.
* Last changed in libpng 1.6.22 [May 26, 2016]
*
* This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer
* and license in png.h
*/
/* Below, after checking __linux__, various non-C90 POSIX 1003.1 functions are
* called.
*/

View File

@ -1,9 +1,9 @@
/* filter_neon.S - NEON optimised filter functions
*
* Copyright (c) 2018 Cosmin Truta
* Copyright (c) 2014,2017 Glenn Randers-Pehrson
* Written by Mans Rullgard, 2011.
* Last changed in libpng 1.6.31 [July 27, 2017]
*
* This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer

View File

@ -1,12 +1,11 @@
/* filter_neon_intrinsics.c - NEON optimised filter functions
*
* Copyright (c) 2018 Cosmin Truta
* Copyright (c) 2014,2016 Glenn Randers-Pehrson
* Written by James Yu <james.yu at linaro.org>, October 2013.
* Based on filter_neon.S, written by Mans Rullgard, 2011.
*
* Last changed in libpng 1.6.22 [May 26, 2016]
*
* This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer
* and license in png.h
@ -19,7 +18,11 @@
/* This code requires -mfpu=neon on the command line: */
#if PNG_ARM_NEON_IMPLEMENTATION == 1 /* intrinsics code from pngpriv.h */
#include <arm_neon.h>
#if defined(_MSC_VER) && defined(_M_ARM64)
# include <arm64_neon.h>
#else
# include <arm_neon.h>
#endif
/* libpng row pointers are not necessarily aligned to any particular boundary,
* however this code will only work with appropriate alignment. arm/arm_init.c
@ -33,6 +36,11 @@
* 'type'. This is written this way just to hide the GCC strict aliasing
* warning; note that the code is safe because there never is an alias between
* the input and output pointers.
*
* When compiling with MSVC ARM64, the png_ldr macro can't be passed directly
* to vst4_lane_u32, because of an internal compiler error inside MSVC.
* To avoid this compiler bug, we use a temporary variable (vdest_val) to store
* the result of png_ldr.
*/
#define png_ldr(type,pointer)\
(temp_pointer = png_ptr(type,pointer), *temp_pointer)
@ -125,12 +133,15 @@ png_read_filter_row_sub4_neon(png_row_infop row_info, png_bytep row,
uint8x8x4_t *vrpt = png_ptr(uint8x8x4_t,&vtmp);
uint8x8x4_t vrp = *vrpt;
uint32x2x4_t *temp_pointer;
uint32x2x4_t vdest_val;
vdest.val[0] = vadd_u8(vdest.val[3], vrp.val[0]);
vdest.val[1] = vadd_u8(vdest.val[0], vrp.val[1]);
vdest.val[2] = vadd_u8(vdest.val[1], vrp.val[2]);
vdest.val[3] = vadd_u8(vdest.val[2], vrp.val[3]);
vst4_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2x4_t,&vdest), 0);
vdest_val = png_ldr(uint32x2x4_t, &vdest);
vst4_lane_u32(png_ptr(uint32_t,rp), vdest_val, 0);
}
PNG_UNUSED(prev_row)
@ -223,6 +234,7 @@ png_read_filter_row_avg4_neon(png_row_infop row_info, png_bytep row,
uint8x8x4_t *vrpt, *vppt;
uint8x8x4_t vrp, vpp;
uint32x2x4_t *temp_pointer;
uint32x2x4_t vdest_val;
vtmp = vld4_u32(png_ptr(uint32_t,rp));
vrpt = png_ptr(uint8x8x4_t,&vtmp);
@ -240,7 +252,8 @@ png_read_filter_row_avg4_neon(png_row_infop row_info, png_bytep row,
vdest.val[3] = vhadd_u8(vdest.val[2], vpp.val[3]);
vdest.val[3] = vadd_u8(vdest.val[3], vrp.val[3]);
vst4_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2x4_t,&vdest), 0);
vdest_val = png_ldr(uint32x2x4_t, &vdest);
vst4_lane_u32(png_ptr(uint32_t,rp), vdest_val, 0);
}
}
@ -359,6 +372,7 @@ png_read_filter_row_paeth4_neon(png_row_infop row_info, png_bytep row,
uint8x8x4_t *vrpt, *vppt;
uint8x8x4_t vrp, vpp;
uint32x2x4_t *temp_pointer;
uint32x2x4_t vdest_val;
vtmp = vld4_u32(png_ptr(uint32_t,rp));
vrpt = png_ptr(uint8x8x4_t,&vtmp);
@ -378,7 +392,8 @@ png_read_filter_row_paeth4_neon(png_row_infop row_info, png_bytep row,
vlast = vpp.val[3];
vst4_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2x4_t,&vdest), 0);
vdest_val = png_ldr(uint32x2x4_t, &vdest);
vst4_lane_u32(png_ptr(uint32_t,rp), vdest_val, 0);
}
}

View File

@ -0,0 +1,149 @@
/* palette_neon_intrinsics.c - NEON optimised palette expansion functions
*
* Copyright (c) 2018 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 RGBA palette from the RGB and separate alpha palettes. */
void
png_riffle_palette_rgba(png_structrp png_ptr, png_row_infop row_info)
{
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;
/* Initially black, opaque. */
uint8x16x4_t w = {{
vdupq_n_u8(0x00),
vdupq_n_u8(0x00),
vdupq_n_u8(0x00),
vdupq_n_u8(0xff),
}};
if (row_info->bit_depth != 8)
{
png_error(png_ptr, "bit_depth must be 8 for png_riffle_palette_rgba");
return;
}
/* First, riffle the RGB colours into a RGBA palette, the A value is
* set to opaque for now.
*/
for (i = 0; i < (1 << row_info->bit_depth); 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 RGBA. */
int
png_do_expand_palette_neon_rgba(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;
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 RGB format. */
int
png_do_expand_palette_neon_rgb(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;
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 */

View File

@ -1,12 +1,11 @@
/* filter_sse2_intrinsics.c - SSE2 optimized filter functions
*
* Copyright (c) 2018 Cosmin Truta
* Copyright (c) 2016-2017 Glenn Randers-Pehrson
* Written by Mike Klein and Matt Sarett
* Derived from arm/filter_neon_intrinsics.c
*
* Last changed in libpng 1.6.31 [July 27, 2017]
*
* This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer
* and license in png.h
@ -29,39 +28,25 @@
*/
static __m128i load4(const void* p) {
return _mm_cvtsi32_si128(*(const int*)p);
int tmp;
memcpy(&tmp, p, sizeof(tmp));
return _mm_cvtsi32_si128(tmp);
}
static void store4(void* p, __m128i v) {
*(int*)p = _mm_cvtsi128_si32(v);
int tmp = _mm_cvtsi128_si32(v);
memcpy(p, &tmp, sizeof(int));
}
static __m128i load3(const void* p) {
/* We'll load 2 bytes, then 1 byte,
* then mask them together, and finally load into SSE.
*/
const png_uint_16* p01 = (png_const_uint_16p)p;
const png_byte* p2 = (const png_byte*)(p01+1);
png_uint_32 v012 = (png_uint_32)(*p01)
| (png_uint_32)(*p2) << 16;
return load4(&v012);
png_uint_32 tmp = 0;
memcpy(&tmp, p, 3);
return _mm_cvtsi32_si128(tmp);
}
static void store3(void* p, __m128i v) {
/* We'll pull from SSE as a 32-bit int, then write
* its bottom two bytes, then its third byte.
*/
png_uint_32 v012;
png_uint_16* p01;
png_byte* p2;
store4(&v012, v);
p01 = (png_uint_16p)p;
p2 = (png_byte*)(p01+1);
*p01 = (png_uint_16)v012;
*p2 = (png_byte)(v012 >> 16);
int tmp = _mm_cvtsi128_si32(v);
memcpy(p, &tmp, 3);
}
void png_read_filter_row_sub3_sse2(png_row_infop row_info, png_bytep row,

View File

@ -1,12 +1,11 @@
/* intel_init.c - SSE2 optimized filter functions
*
* Copyright (c) 2018 Cosmin Truta
* Copyright (c) 2016-2017 Glenn Randers-Pehrson
* Written by Mike Klein and Matt Sarett, Google, Inc.
* Derived from arm/arm_init.c
*
* Last changed in libpng 1.6.29 [March 16, 2017]
*
* This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer
* and license in png.h

50
3rdparty/libpng/png.c vendored
View File

@ -1,10 +1,10 @@
/* png.c - location for general purpose libpng functions
*
* Last changed in libpng 1.6.35 [July 15, 2018]
* Copyright (c) 2018 Cosmin Truta
* Copyright (c) 1998-2002,2004,2006-2018 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) 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,7 +14,7 @@
#include "pngpriv.h"
/* Generate a compiler error if there is an old png.h in the search path. */
typedef png_libpng_version_1_6_35 Your_png_h_is_not_version_1_6_35;
typedef png_libpng_version_1_6_36 Your_png_h_is_not_version_1_6_36;
#ifdef __GNUC__
/* The version tests may need to be added to, but the problem warning has
@ -736,7 +736,7 @@ png_save_int_32(png_bytep buf, png_int_32 i)
int PNGAPI
png_convert_to_rfc1123_buffer(char out[29], png_const_timep ptime)
{
static PNG_CONST char short_months[12][4] =
static const char short_months[12][4] =
{"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
@ -814,20 +814,14 @@ png_get_copyright(png_const_structrp png_ptr)
#ifdef PNG_STRING_COPYRIGHT
return PNG_STRING_COPYRIGHT
#else
# ifdef __STDC__
return PNG_STRING_NEWLINE \
"libpng version 1.6.35 - July 15, 2018" PNG_STRING_NEWLINE \
"libpng version 1.6.36" PNG_STRING_NEWLINE \
"Copyright (c) 2018 Cosmin Truta" PNG_STRING_NEWLINE \
"Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson" \
PNG_STRING_NEWLINE \
"Copyright (c) 1996-1997 Andreas Dilger" PNG_STRING_NEWLINE \
"Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc." \
PNG_STRING_NEWLINE;
# else
return "libpng version 1.6.35 - July 15, 2018\
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.";
# endif
#endif
}
@ -1121,7 +1115,7 @@ png_colorspace_set_gamma(png_const_structrp png_ptr,
png_colorspacerp colorspace, png_fixed_point gAMA)
{
/* Changed in libpng-1.5.4 to limit the values to ensure overflow can't
* occur. Since the fixed point representation is asymetrical it is
* occur. Since the fixed point representation is asymmetrical it is
* possible for 1/gamma to overflow the limit of 21474 and this means the
* gamma value must be at least 5/100000 and hence at most 20000.0. For
* safety the limits here are a little narrower. The values are 0.00016 to
@ -3134,11 +3128,11 @@ png_ascii_from_fp(png_const_structrp png_ptr, png_charp ascii, size_t size,
/* The total output count (max) is now 4+precision */
/* Check for an exponent, if we don't need one we are
* done and just need to terminate the string. At
* this point exp_b10==(-1) is effectively a flag - it got
* to '-1' because of the decrement after outputting
* the decimal point above (the exponent required is
* *not* -1!)
* done and just need to terminate the string. At this
* point, exp_b10==(-1) is effectively a flag: it got
* to '-1' because of the decrement, after outputting
* the decimal point above. (The exponent required is
* *not* -1.)
*/
if (exp_b10 >= (-1) && exp_b10 <= 2)
{
@ -3976,18 +3970,18 @@ png_gamma_correct(png_structrp png_ptr, unsigned int value,
*/
static void
png_build_16bit_table(png_structrp png_ptr, png_uint_16pp *ptable,
PNG_CONST unsigned int shift, PNG_CONST png_fixed_point gamma_val)
unsigned int shift, png_fixed_point gamma_val)
{
/* Various values derived from 'shift': */
PNG_CONST unsigned int num = 1U << (8U - shift);
unsigned int num = 1U << (8U - shift);
#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED
/* CSE the division and work round wacky GCC warnings (see the comments
* in png_gamma_8bit_correct for where these come from.)
*/
PNG_CONST double fmax = 1./(((png_int_32)1 << (16U - shift))-1);
double fmax = 1.0 / (((png_int_32)1 << (16U - shift)) - 1);
#endif
PNG_CONST unsigned int max = (1U << (16U - shift))-1U;
PNG_CONST unsigned int max_by_2 = 1U << (15U-shift);
unsigned int max = (1U << (16U - shift)) - 1U;
unsigned int max_by_2 = 1U << (15U - shift);
unsigned int i;
png_uint_16pp table = *ptable =
@ -4053,10 +4047,10 @@ png_build_16bit_table(png_structrp png_ptr, png_uint_16pp *ptable,
*/
static void
png_build_16to8_table(png_structrp png_ptr, png_uint_16pp *ptable,
PNG_CONST unsigned int shift, PNG_CONST png_fixed_point gamma_val)
unsigned int shift, png_fixed_point gamma_val)
{
PNG_CONST unsigned int num = 1U << (8U - shift);
PNG_CONST unsigned int max = (1U << (16U - shift))-1U;
unsigned int num = 1U << (8U - shift);
unsigned int max = (1U << (16U - shift))-1U;
unsigned int i;
png_uint_32 last;
@ -4121,7 +4115,7 @@ png_build_16to8_table(png_structrp png_ptr, png_uint_16pp *ptable,
*/
static void
png_build_8bit_table(png_structrp png_ptr, png_bytepp ptable,
PNG_CONST png_fixed_point gamma_val)
png_fixed_point gamma_val)
{
unsigned int i;
png_bytep table = *ptable = (png_bytep)png_malloc(png_ptr, 256);

299
3rdparty/libpng/png.h vendored
View File

@ -1,29 +1,65 @@
/* png.h - header file for PNG reference library
*
* libpng version 1.6.35, July 15, 2018
* libpng version 1.6.36 - December 1, 2018
*
* Copyright (c) 2018 Cosmin Truta
* Copyright (c) 1998-2002,2004,2006-2018 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) 1996-1997 Andreas Dilger
* Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
*
* This code is released under the libpng license (See LICENSE, below)
* This code is released under the libpng license. (See LICENSE, below.)
*
* Authors and maintainers:
* libpng versions 0.71, May 1995, through 0.88, January 1996: Guy Schalnat
* libpng versions 0.89, June 1996, through 0.96, May 1997: Andreas Dilger
* libpng versions 0.97, January 1998, through 1.6.35, July 15, 2018:
* libpng versions 0.97, January 1998, through 1.6.35, July 2018:
* Glenn Randers-Pehrson.
* libpng version 1.6.36, December 1, 2018: Cosmin Truta
* See also "Contributing Authors", below.
*/
/*
* COPYRIGHT NOTICE, DISCLAIMER, and LICENSE:
* COPYRIGHT NOTICE, DISCLAIMER, and LICENSE
* =========================================
*
* If you modify libpng you may insert additional notices immediately following
* this sentence.
* PNG Reference Library License version 2
* ---------------------------------------
*
* This code is released under the libpng license.
* * Copyright (c) 1995-2018 The PNG Reference Library Authors.
* * Copyright (c) 2018 Cosmin Truta.
* * Copyright (c) 2000-2002, 2004, 2006-2018 Glenn Randers-Pehrson.
* * Copyright (c) 1996-1997 Andreas Dilger.
* * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.
*
* The software is supplied "as is", without warranty of any kind,
* express or implied, including, without limitation, the warranties
* of merchantability, fitness for a particular purpose, title, and
* non-infringement. In no even shall the Copyright owners, or
* anyone distributing the software, be liable for any damages or
* other liability, whether in contract, tort or otherwise, arising
* from, out of, or in connection with the software, or the use or
* other dealings in the software, even if advised of the possibility
* of such damage.
*
* Permission is hereby granted to use, copy, modify, and distribute
* this software, or portions hereof, for any purpose, without fee,
* subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you
* must not claim that you wrote the original software. If you
* use this software in a product, an acknowledgment in the product
* documentation would be appreciated, but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must
* not be misrepresented as being the original software.
*
* 3. This Copyright notice may not be removed or altered from any
* source or altered source distribution.
*
*
* PNG Reference Library License version 1 (for libpng 0.5 through 1.6.35)
* -----------------------------------------------------------------------
*
* libpng versions 1.0.7, July 1, 2000 through 1.6.35, July 15, 2018 are
* Copyright (c) 2000-2002, 2004, 2006-2018 Glenn Randers-Pehrson, are
@ -31,38 +67,38 @@
* disclaimer and license as libpng-1.0.6 with the following individuals
* added to the list of Contributing Authors:
*
* Simon-Pierre Cadieux
* Eric S. Raymond
* Mans Rullgard
* Cosmin Truta
* Gilles Vollant
* James Yu
* Mandar Sahastrabuddhe
* Google Inc.
* Vadim Barkov
* Simon-Pierre Cadieux
* Eric S. Raymond
* Mans Rullgard
* Cosmin Truta
* Gilles Vollant
* James Yu
* Mandar Sahastrabuddhe
* Google Inc.
* Vadim Barkov
*
* and with the following additions to the disclaimer:
*
* There is no warranty against interference with your enjoyment of the
* library or against infringement. There is no warranty that our
* efforts or the library will fulfill any of your particular purposes
* or needs. This library is provided with all faults, and the entire
* risk of satisfactory quality, performance, accuracy, and effort is with
* the user.
* There is no warranty against interference with your enjoyment of
* the library or against infringement. There is no warranty that our
* efforts or the library will fulfill any of your particular purposes
* or needs. This library is provided with all faults, and the entire
* risk of satisfactory quality, performance, accuracy, and effort is
* with the user.
*
* Some files in the "contrib" directory and some configure-generated
* files that are distributed with libpng have other copyright owners and
* files that are distributed with libpng have other copyright owners, and
* are released under other open source licenses.
*
* libpng versions 0.97, January 1998, through 1.0.6, March 20, 2000, are
* Copyright (c) 1998-2000 Glenn Randers-Pehrson, are derived from
* libpng-0.96, and are distributed according to the same disclaimer and
* license as libpng-0.96, with the following individuals added to the list
* of Contributing Authors:
* license as libpng-0.96, with the following individuals added to the
* list of Contributing Authors:
*
* Tom Lane
* Glenn Randers-Pehrson
* Willem van Schaik
* Tom Lane
* Glenn Randers-Pehrson
* Willem van Schaik
*
* libpng versions 0.89, June 1996, through 0.96, May 1997, are
* Copyright (c) 1996-1997 Andreas Dilger, are derived from libpng-0.88,
@ -70,14 +106,14 @@
* libpng-0.88, with the following individuals added to the list of
* Contributing Authors:
*
* John Bowler
* Kevin Bracey
* Sam Bushell
* Magnus Holmgren
* Greg Roelofs
* Tom Tanner
* John Bowler
* Kevin Bracey
* Sam Bushell
* Magnus Holmgren
* Greg Roelofs
* Tom Tanner
*
* Some files in the "scripts" directory have other copyright owners
* Some files in the "scripts" directory have other copyright owners,
* but are released under this license.
*
* libpng versions 0.5, May 1995, through 0.88, January 1996, are
@ -86,62 +122,49 @@
* For the purposes of this copyright and license, "Contributing Authors"
* is defined as the following set of individuals:
*
* Andreas Dilger
* Dave Martindale
* Guy Eric Schalnat
* Paul Schmidt
* Tim Wegner
* Andreas Dilger
* Dave Martindale
* Guy Eric Schalnat
* Paul Schmidt
* Tim Wegner
*
* The PNG Reference Library is supplied "AS IS". The Contributing Authors
* and Group 42, Inc. disclaim all warranties, expressed or implied,
* including, without limitation, the warranties of merchantability and of
* fitness for any purpose. The Contributing Authors and Group 42, Inc.
* assume no liability for direct, indirect, incidental, special, exemplary,
* or consequential damages, which may result from the use of the PNG
* Reference Library, even if advised of the possibility of such damage.
* The PNG Reference Library is supplied "AS IS". The Contributing
* Authors and Group 42, Inc. disclaim all warranties, expressed or
* implied, including, without limitation, the warranties of
* merchantability and of fitness for any purpose. The Contributing
* Authors and Group 42, Inc. assume no liability for direct, indirect,
* incidental, special, exemplary, or consequential damages, which may
* result from the use of the PNG Reference Library, even if advised of
* the possibility of such damage.
*
* Permission is hereby granted to use, copy, modify, and distribute this
* source code, or portions hereof, for any purpose, without fee, subject
* to the following restrictions:
*
* 1. The origin of this source code must not be misrepresented.
* 1. The origin of this source code must not be misrepresented.
*
* 2. Altered versions must be plainly marked as such and must not
* be misrepresented as being the original source.
* 2. Altered versions must be plainly marked as such and must not
* be misrepresented as being the original source.
*
* 3. This Copyright notice may not be removed or altered from any
* source or altered source distribution.
* 3. This Copyright notice may not be removed or altered from any
* source or altered source distribution.
*
* The Contributing Authors and Group 42, Inc. specifically permit, without
* fee, and encourage the use of this source code as a component to
* supporting the PNG file format in commercial products. If you use this
* source code in a product, acknowledgment is not required but would be
* appreciated.
* The Contributing Authors and Group 42, Inc. specifically permit,
* without fee, and encourage the use of this source code as a component
* to supporting the PNG file format in commercial products. If you use
* this source code in a product, acknowledgment is not required but would
* be appreciated.
*
* END OF COPYRIGHT NOTICE, DISCLAIMER, and LICENSE.
*
* TRADEMARK:
* TRADEMARK
* =========
*
* The name "libpng" has not been registered by the Copyright owner
* The name "libpng" has not been registered by the Copyright owners
* as a trademark in any jurisdiction. However, because libpng has
* been distributed and maintained world-wide, continually since 1995,
* the Copyright owner claims "common-law trademark protection" in any
* the Copyright owners claim "common-law trademark protection" in any
* jurisdiction where common-law trademark is recognized.
*
* OSI CERTIFICATION:
*
* Libpng is OSI Certified Open Source Software. OSI Certified Open Source is
* a certification mark of the Open Source Initiative. OSI has not addressed
* the additional disclaimers inserted at version 1.0.7.
*
* EXPORT CONTROL:
*
* The Copyright owner believes that the Export Control Classification
* Number (ECCN) for libpng is EAR99, which means not subject to export
* controls or International Traffic in Arms Regulations (ITAR) because
* it is open source, publicly available software, that does not contain
* any encryption software. See the EAR, paragraphs 734.3(b)(3) and
* 734.7(b).
*/
/*
@ -207,23 +230,25 @@
* 1.0.7rc1-2 1 10007 2.1.0.7rc1-2 (binary compatible)
* 1.0.7 1 10007 (still compatible)
* ...
* 1.0.19 10 10019 10.so.0.19[.0]
* 1.0.69 10 10069 10.so.0.69[.0]
* ...
* 1.2.59 13 10257 12.so.0.59[.0]
* 1.2.59 13 10259 12.so.0.59[.0]
* ...
* 1.5.30 15 10527 15.so.15.30[.0]
* 1.4.20 14 10420 14.so.0.20[.0]
* ...
* 1.6.35 16 10635 16.so.16.35[.0]
* 1.5.30 15 10530 15.so.15.30[.0]
* ...
* 1.6.36 16 10636 16.so.16.36[.0]
*
* Henceforth the source version will match the shared-library major
* and minor numbers; the shared-library major version number will be
* used for changes in backward compatibility, as it is intended. The
* PNG_LIBPNG_VER macro, which is not used within libpng but is available
* for applications, is an unsigned integer of the form xyyzz corresponding
* to the source version x.y.z (leading zeros in y and z). Beta versions
* were given the previous public release number plus a letter, until
* version 1.0.6j; from then on they were given the upcoming public
* release number plus "betaNN" or "rcNN".
* Henceforth the source version will match the shared-library major and
* minor numbers; the shared-library major version number will be used for
* changes in backward compatibility, as it is intended.
* The PNG_LIBPNG_VER macro, which is not used within libpng but is
* available for applications, is an unsigned integer of the form XYYZZ
* corresponding to the source version X.Y.Z (leading zeros in Y and Z).
* Beta versions were given the previous public release number plus a
* letter, until version 1.0.6j; from then on they were given the upcoming
* public release number plus "betaNN" or "rcNN".
*
* Binary incompatibility exists only when applications make direct access
* to the info_ptr or png_ptr members through png.h, and the compiled
@ -233,65 +258,8 @@
* in binary compatibility (e.g., when a new feature is added).
*
* See libpng.txt or libpng.3 for more information. The PNG specification
* is available as a W3C Recommendation and as an ISO Specification,
* <https://www.w3.org/TR/2003/REC-PNG-20031110/
*/
/*
* Y2K compliance in libpng:
* =========================
*
* July 15, 2018
*
* Since the PNG Development group is an ad-hoc body, we can't make
* an official declaration.
*
* This is your unofficial assurance that libpng from version 0.71 and
* upward through 1.6.35 are Y2K compliant. It is my belief that
* earlier versions were also Y2K compliant.
*
* Libpng only has two year fields. One is a 2-byte unsigned integer
* that will hold years up to 65535. The other, which is deprecated,
* holds the date in text format, and will hold years up to 9999.
*
* The integer is
* "png_uint_16 year" in png_time_struct.
*
* The string is
* "char time_buffer[29]" in png_struct. This is no longer used
* in libpng-1.6.x and will be removed from libpng-1.7.0.
*
* There are seven time-related functions:
* png.c: png_convert_to_rfc_1123_buffer() in png.c
* (formerly png_convert_to_rfc_1123() prior to libpng-1.5.x and
* png_convert_to_rfc_1152() in error prior to libpng-0.98)
* png_convert_from_struct_tm() in pngwrite.c, called in pngwrite.c
* png_convert_from_time_t() in pngwrite.c
* png_get_tIME() in pngget.c
* png_handle_tIME() in pngrutil.c, called in pngread.c
* png_set_tIME() in pngset.c
* png_write_tIME() in pngwutil.c, called in pngwrite.c
*
* All handle dates properly in a Y2K environment. The
* png_convert_from_time_t() function calls gmtime() to convert from system
* clock time, which returns (year - 1900), which we properly convert to
* the full 4-digit year. There is a possibility that libpng applications
* are not passing 4-digit years into the png_convert_to_rfc_1123_buffer()
* function, or that they are incorrectly passing only a 2-digit year
* instead of "year - 1900" into the png_convert_from_struct_tm() function,
* but this is not under our control. The libpng documentation has always
* stated that it works with 4-digit years, and the APIs have been
* documented as such.
*
* The tIME chunk itself is also Y2K compliant. It uses a 2-byte unsigned
* integer to hold the year, and can hold years as large as 65535.
*
* zlib, upon which libpng depends, is also Y2K compliant. It contains
* no date-related code.
*
* Glenn Randers-Pehrson
* libpng maintainer
* PNG Development Group
* is available as a W3C Recommendation and as an ISO/IEC Standard; see
* <https://www.w3.org/TR/2003/REC-PNG-20031110/>
*/
#ifndef PNG_H
@ -309,8 +277,8 @@
*/
/* Version information for png.h - this should match the version in png.c */
#define PNG_LIBPNG_VER_STRING "1.6.35"
#define PNG_HEADER_VERSION_STRING " libpng version 1.6.35 - July 15, 2018\n"
#define PNG_LIBPNG_VER_STRING "1.6.36"
#define PNG_HEADER_VERSION_STRING " libpng version 1.6.36 - December 1, 2018\n"
#define PNG_LIBPNG_VER_SONUM 16
#define PNG_LIBPNG_VER_DLLNUM 16
@ -318,13 +286,13 @@
/* These should match the first 3 components of PNG_LIBPNG_VER_STRING: */
#define PNG_LIBPNG_VER_MAJOR 1
#define PNG_LIBPNG_VER_MINOR 6
#define PNG_LIBPNG_VER_RELEASE 35
#define PNG_LIBPNG_VER_RELEASE 36
/* This should match the numeric part of the final component of
* PNG_LIBPNG_VER_STRING, omitting any leading zero:
*/
#define PNG_LIBPNG_VER_BUILD 02
#define PNG_LIBPNG_VER_BUILD 0
/* Release Status */
#define PNG_LIBPNG_BUILD_ALPHA 1
@ -341,15 +309,16 @@
#define PNG_LIBPNG_BUILD_SPECIAL 32 /* Cannot be OR'ed with
PNG_LIBPNG_BUILD_PRIVATE */
#define PNG_LIBPNG_BUILD_BASE_TYPE PNG_LIBPNG_BUILD_BETA
#define PNG_LIBPNG_BUILD_BASE_TYPE PNG_LIBPNG_BUILD_STABLE
/* Careful here. At one time, Guy wanted to use 082, but that would be octal.
* We must not include leading zeros.
* Versions 0.7 through 1.0.0 were in the range 0 to 100 here (only
* version 1.0.0 was mis-numbered 100 instead of 10000). From
* version 1.0.1 it's xxyyzz, where x=major, y=minor, z=release
/* Careful here. At one time, Guy wanted to use 082, but that
* would be octal. We must not include leading zeros.
* Versions 0.7 through 1.0.0 were in the range 0 to 100 here
* (only version 1.0.0 was mis-numbered 100 instead of 10000).
* From version 1.0.1 it is:
* XXYYZZ, where XX=major, YY=minor, ZZ=release
*/
#define PNG_LIBPNG_VER 10635 /* 1.6.35 */
#define PNG_LIBPNG_VER 10636 /* 1.6.36 */
/* Library configuration: these options cannot be changed after
* the library has been built.
@ -459,7 +428,7 @@ extern "C" {
/* This triggers a compiler error in png.c, if png.c and png.h
* do not agree upon the version number.
*/
typedef char* png_libpng_version_1_6_35;
typedef char* png_libpng_version_1_6_36;
/* Basic control structions. Read libpng-manual.txt or libpng.3 for more info.
*
@ -2013,12 +1982,12 @@ PNG_FIXED_EXPORT(233, void, png_set_cHRM_XYZ_fixed, (png_const_structrp png_ptr,
PNG_EXPORT(246, png_uint_32, png_get_eXIf, (png_const_structrp png_ptr,
png_inforp info_ptr, png_bytep *exif));
PNG_EXPORT(247, void, png_set_eXIf, (png_const_structrp png_ptr,
png_inforp info_ptr, const png_bytep exif));
png_inforp info_ptr, png_bytep exif));
PNG_EXPORT(248, png_uint_32, png_get_eXIf_1, (png_const_structrp png_ptr,
png_const_inforp info_ptr, png_uint_32 *num_exif, png_bytep *exif));
PNG_EXPORT(249, void, png_set_eXIf_1, (png_const_structrp png_ptr,
png_inforp info_ptr, const png_uint_32 num_exif, const png_bytep exif));
png_inforp info_ptr, png_uint_32 num_exif, png_bytep exif));
#endif
#ifdef PNG_gAMA_SUPPORTED
@ -2764,7 +2733,7 @@ typedef struct
*
* When the simplified API needs to convert between sRGB and linear colorspaces,
* the actual sRGB transfer curve defined in the sRGB specification (see the
* article at https://en.wikipedia.org/wiki/SRGB) is used, not the gamma=1/2.2
* article at <https://en.wikipedia.org/wiki/SRGB>) is used, not the gamma=1/2.2
* approximation used elsewhere in libpng.
*
* When an alpha channel is present it is expected to denote pixel coverage
@ -2967,7 +2936,7 @@ typedef struct
* 'flags' field of png_image.
*/
#define PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB 0x01
/* This indicates the the RGB values of the in-memory bitmap do not
/* This indicates that the RGB values of the in-memory bitmap do not
* correspond to the red, green and blue end-points defined by sRGB.
*/

View File

@ -1,11 +1,12 @@
/* pngconf.h - machine configurable file for libpng
*
* libpng version 1.6.35, July 15, 2018
* libpng version 1.6.36
*
* Copyright (c) 2018 Cosmin Truta
* Copyright (c) 1998-2002,2004,2006-2016,2018 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) 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
@ -57,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-bit 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.

View File

@ -1,10 +1,10 @@
/* pngdebug.h - Debugging macros for libpng, also used in pngtest.c
*
* Last changed in libpng 1.6.8 [December 19, 2013]
* Copyright (c) 2018 Cosmin Truta
* Copyright (c) 1998-2002,2004,2006-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) 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

View File

@ -1,10 +1,10 @@
/* pngerror.c - stub functions for i/o and memory allocation
*
* Last changed in libpng 1.6.31 [July 27, 2017]
* Copyright (c) 2018 Cosmin Truta
* Copyright (c) 1998-2002,2004,2006-2017 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) 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
@ -425,7 +425,7 @@ png_app_error(png_const_structrp png_ptr, png_const_charp error_message)
* 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'
};
@ -885,7 +885,7 @@ 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)
@ -920,7 +920,7 @@ png_safe_error),(png_structp png_nonconst_ptr, png_const_charp error_message),
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. */

View File

@ -1,10 +1,10 @@
/* pngget.c - retrieval of values from info struct
*
* Last changed in libpng 1.6.35 [July 15, 2018]
* Copyright (c) 2018 Cosmin Truta
* Copyright (c) 1998-2002,2004,2006-2018 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) 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

View File

@ -1,10 +1,10 @@
/* pnginfo.h - header file for PNG reference library
*
* Last changed in libpng 1.6.35 [July 15, 2018]
* Copyright (c) 2018 Cosmin Truta
* Copyright (c) 1998-2002,2004,2006-2013,2018 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) 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

View File

@ -1,10 +1,9 @@
/* libpng 1.6.34 STANDARD API DEFINITION */
/* pnglibconf.h - library build configuration */
/* Libpng version 1.6.34 - September 29, 2017 */
/* libpng version 1.6.36 */
/* Copyright (c) 1998-2017 Glenn Randers-Pehrson */
/* Copyright (c) 2018 Cosmin Truta */
/* Copyright (c) 1998-2002,2004,2006-2018 Glenn Randers-Pehrson */
/* This code is released under the libpng license. */
/* For conditions of distribution and use, see the disclaimer */
@ -20,8 +19,6 @@
#define PNG_ALIGNED_MEMORY_SUPPORTED
/*#undef PNG_ARM_NEON_API_SUPPORTED*/
/*#undef PNG_ARM_NEON_CHECK_SUPPORTED*/
/*#undef PNG_POWERPC_VSX_API_SUPPORTED*/
/*#undef PNG_POWERPC_VSX_CHECK_SUPPORTED*/
#define PNG_BENIGN_ERRORS_SUPPORTED
#define PNG_BENIGN_READ_ERRORS_SUPPORTED
/*#undef PNG_BENIGN_WRITE_ERRORS_SUPPORTED*/
@ -46,6 +43,8 @@
#define PNG_IO_STATE_SUPPORTED
#define PNG_MNG_FEATURES_SUPPORTED
#define PNG_POINTER_INDEXING_SUPPORTED
/*#undef PNG_POWERPC_VSX_API_SUPPORTED*/
/*#undef PNG_POWERPC_VSX_CHECK_SUPPORTED*/
#define PNG_PROGRESSIVE_READ_SUPPORTED
#define PNG_READ_16BIT_SUPPORTED
#define PNG_READ_ALPHA_MODE_SUPPORTED

View File

@ -1,10 +1,10 @@
/* pngmem.c - stub functions for memory allocation
*
* Last changed in libpng 1.6.26 [October 20, 2016]
* Copyright (c) 2018 Cosmin Truta
* Copyright (c) 1998-2002,2004,2006-2014,2016 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) 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

View File

@ -1,10 +1,10 @@
/* pngpread.c - read a png file in push mode
*
* Last changed in libpng 1.6.35 [July 15, 2018]
* Copyright (c) 2018 Cosmin Truta
* Copyright (c) 1998-2002,2004,2006-2018 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) 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
@ -972,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

View File

@ -1,10 +1,10 @@
/* pngpriv.h - private declarations for use inside libpng
*
* Last changed in libpng 1.6.35 [July 15, 2018]
* Copyright (c) 2018 Cosmin Truta
* Copyright (c) 1998-2002,2004,2006-2018 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) 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
@ -174,7 +174,10 @@
# else /* !defined __ARM_NEON__ */
/* The 'intrinsics' code simply won't compile without this -mfpu=neon:
*/
# define PNG_ARM_NEON_IMPLEMENTATION 2
# if !defined(__aarch64__)
/* The assembler code currently does not work on ARM64 */
# define PNG_ARM_NEON_IMPLEMENTATION 2
# endif /* __aarch64__ */
# endif /* __ARM_NEON__ */
# endif /* !PNG_ARM_NEON_IMPLEMENTATION */
@ -1534,10 +1537,10 @@ PNG_INTERNAL_FUNCTION(void,png_handle_zTXt,(png_structrp png_ptr,
#endif
PNG_INTERNAL_FUNCTION(void,png_check_chunk_name,(png_const_structrp png_ptr,
const png_uint_32 chunk_name),PNG_EMPTY);
png_uint_32 chunk_name),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_check_chunk_length,(png_const_structrp png_ptr,
const png_uint_32 chunk_length),PNG_EMPTY);
png_uint_32 chunk_length),PNG_EMPTY);
PNG_INTERNAL_FUNCTION(void,png_handle_unknown,(png_structrp png_ptr,
png_inforp info_ptr, png_uint_32 length, int keep),PNG_EMPTY);
@ -2114,6 +2117,29 @@ PNG_INTERNAL_FUNCTION(void, png_init_filter_functions_sse2,
PNG_INTERNAL_FUNCTION(png_uint_32, png_check_keyword, (png_structrp png_ptr,
png_const_charp key, png_bytep new_key), PNG_EMPTY);
#if PNG_ARM_NEON_IMPLEMENTATION == 1
PNG_INTERNAL_FUNCTION(void,
png_riffle_palette_rgba,
(png_structrp, png_row_infop),
PNG_EMPTY);
PNG_INTERNAL_FUNCTION(int,
png_do_expand_palette_neon_rgba,
(png_structrp,
png_row_infop,
png_const_bytep,
const png_bytepp,
const png_bytepp),
PNG_EMPTY);
PNG_INTERNAL_FUNCTION(int,
png_do_expand_palette_neon_rgb,
(png_structrp,
png_row_infop,
png_const_bytep,
const png_bytepp,
const png_bytepp),
PNG_EMPTY);
#endif
/* Maintainer: Put new private prototypes here ^ */
#include "pngdebug.h"

View File

@ -1,10 +1,10 @@
/* pngread.c - read a PNG file
*
* Last changed in libpng 1.6.35 [July 15, 2018]
* Copyright (c) 2018 Cosmin Truta
* Copyright (c) 1998-2002,2004,2006-2018 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) 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
@ -1621,7 +1621,7 @@ png_image_skip_unused_chunks(png_structrp png_ptr)
* errors (which are unfortunately quite common.)
*/
{
static PNG_CONST png_byte chunks_to_process[] = {
static const png_byte chunks_to_process[] = {
98, 75, 71, 68, '\0', /* bKGD */
99, 72, 82, 77, '\0', /* cHRM */
103, 65, 77, 65, '\0', /* gAMA */
@ -1758,9 +1758,9 @@ png_create_colormap_entry(png_image_read_control *display,
png_uint_32 alpha, int encoding)
{
png_imagep image = display->image;
const int output_encoding = (image->format & PNG_FORMAT_FLAG_LINEAR) != 0 ?
int output_encoding = (image->format & PNG_FORMAT_FLAG_LINEAR) != 0 ?
P_LINEAR : P_sRGB;
const int convert_to_Y = (image->format & PNG_FORMAT_FLAG_COLOR) == 0 &&
int convert_to_Y = (image->format & PNG_FORMAT_FLAG_COLOR) == 0 &&
(red != green || green != blue);
if (ip > 255)
@ -1869,13 +1869,13 @@ png_create_colormap_entry(png_image_read_control *display,
/* Store the value. */
{
# ifdef PNG_FORMAT_AFIRST_SUPPORTED
const int afirst = (image->format & PNG_FORMAT_FLAG_AFIRST) != 0 &&
int afirst = (image->format & PNG_FORMAT_FLAG_AFIRST) != 0 &&
(image->format & PNG_FORMAT_FLAG_ALPHA) != 0;
# else
# define afirst 0
# endif
# ifdef PNG_FORMAT_BGR_SUPPORTED
const int bgr = (image->format & PNG_FORMAT_FLAG_BGR) != 0 ? 2 : 0;
int bgr = (image->format & PNG_FORMAT_FLAG_BGR) != 0 ? 2 : 0;
# else
# define bgr 0
# endif
@ -2085,11 +2085,11 @@ png_image_read_colormap(png_voidp argument)
{
png_image_read_control *display =
png_voidcast(png_image_read_control*, argument);
const png_imagep image = display->image;
png_imagep image = display->image;
const png_structrp png_ptr = image->opaque->png_ptr;
const png_uint_32 output_format = image->format;
const int output_encoding = (output_format & PNG_FORMAT_FLAG_LINEAR) != 0 ?
png_structrp png_ptr = image->opaque->png_ptr;
png_uint_32 output_format = image->format;
int output_encoding = (output_format & PNG_FORMAT_FLAG_LINEAR) != 0 ?
P_LINEAR : P_sRGB;
unsigned int cmap_entries;
@ -2802,7 +2802,7 @@ png_image_read_colormap(png_voidp argument)
unsigned int num_trans = png_ptr->num_trans;
png_const_bytep trans = num_trans > 0 ? png_ptr->trans_alpha : NULL;
png_const_colorp colormap = png_ptr->palette;
const int do_background = trans != NULL &&
int do_background = trans != NULL &&
(output_format & PNG_FORMAT_FLAG_ALPHA) == 0;
unsigned int i;
@ -3946,7 +3946,7 @@ png_image_read_direct(png_voidp argument)
*/
if (linear != 0)
{
PNG_CONST png_uint_16 le = 0x0001;
png_uint_16 le = 0x0001;
if ((*(png_const_bytep) & le) != 0)
png_set_swap(png_ptr);
@ -4108,7 +4108,7 @@ png_image_finish_read(png_imagep image, png_const_colorp background,
* original PNG format because it may not occur in the output PNG format
* and libpng deals with the issues of reading the original.
*/
const unsigned int channels = PNG_IMAGE_PIXEL_CHANNELS(image->format);
unsigned int channels = PNG_IMAGE_PIXEL_CHANNELS(image->format);
/* The following checks just the 'row_stride' calculation to ensure it
* fits in a signed 32-bit value. Because channels/components can be
@ -4119,7 +4119,7 @@ png_image_finish_read(png_imagep image, png_const_colorp background,
if (image->width <= 0x7fffffffU/channels) /* no overflow */
{
png_uint_32 check;
const png_uint_32 png_row_stride = image->width * channels;
png_uint_32 png_row_stride = image->width * channels;
if (row_stride == 0)
row_stride = (png_int_32)/*SAFE*/png_row_stride;

View File

@ -1,10 +1,10 @@
/* pngrio.c - functions for data input
*
* Last changed in libpng 1.6.35 [July 15, 2018]
* Copyright (c) 2018 Cosmin Truta
* Copyright (c) 1998-2002,2004,2006-2016,2018 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) 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

View File

@ -1,10 +1,10 @@
/* pngrtran.c - transforms the data in a row for PNG readers
*
* Last changed in libpng 1.6.35 [July 15, 2018]
* Copyright (c) 2018 Cosmin Truta
* Copyright (c) 1998-2002,2004,2006-2018 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) 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
@ -18,6 +18,17 @@
#include "pngpriv.h"
#ifdef PNG_ARM_NEON_IMPLEMENTATION
# if PNG_ARM_NEON_IMPLEMENTATION == 1
# define PNG_ARM_NEON_INTRINSICS_AVAILABLE
# if defined(_MSC_VER) && defined(_M_ARM64)
# include <arm64_neon.h>
# else
# include <arm_neon.h>
# endif
# endif
#endif
#ifdef PNG_READ_SUPPORTED
/* Set the action on getting a CRC error for an ancillary or critical chunk. */
@ -2986,7 +2997,6 @@ png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
*/
static int
png_do_rgb_to_gray(png_structrp png_ptr, png_row_infop row_info, png_bytep row)
{
int rgb_error = 0;
@ -2995,12 +3005,11 @@ png_do_rgb_to_gray(png_structrp png_ptr, png_row_infop row_info, png_bytep row)
if ((row_info->color_type & PNG_COLOR_MASK_PALETTE) == 0 &&
(row_info->color_type & PNG_COLOR_MASK_COLOR) != 0)
{
PNG_CONST png_uint_32 rc = png_ptr->rgb_to_gray_red_coeff;
PNG_CONST png_uint_32 gc = png_ptr->rgb_to_gray_green_coeff;
PNG_CONST png_uint_32 bc = 32768 - rc - gc;
PNG_CONST png_uint_32 row_width = row_info->width;
PNG_CONST int have_alpha =
(row_info->color_type & PNG_COLOR_MASK_ALPHA) != 0;
png_uint_32 rc = png_ptr->rgb_to_gray_red_coeff;
png_uint_32 gc = png_ptr->rgb_to_gray_green_coeff;
png_uint_32 bc = 32768 - rc - gc;
png_uint_32 row_width = row_info->width;
int have_alpha = (row_info->color_type & PNG_COLOR_MASK_ALPHA) != 0;
if (row_info->bit_depth == 8)
{
@ -4143,12 +4152,11 @@ png_do_encode_alpha(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
{
if (row_info->bit_depth == 8)
{
PNG_CONST png_bytep table = png_ptr->gamma_from_1;
png_bytep table = png_ptr->gamma_from_1;
if (table != NULL)
{
PNG_CONST int step =
(row_info->color_type & PNG_COLOR_MASK_COLOR) ? 4 : 2;
int step = (row_info->color_type & PNG_COLOR_MASK_COLOR) ? 4 : 2;
/* The alpha channel is the last component: */
row += step - 1;
@ -4162,13 +4170,12 @@ png_do_encode_alpha(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
else if (row_info->bit_depth == 16)
{
PNG_CONST png_uint_16pp table = png_ptr->gamma_16_from_1;
PNG_CONST int gamma_shift = png_ptr->gamma_shift;
png_uint_16pp table = png_ptr->gamma_16_from_1;
int gamma_shift = png_ptr->gamma_shift;
if (table != NULL)
{
PNG_CONST int step =
(row_info->color_type & PNG_COLOR_MASK_COLOR) ? 8 : 4;
int step = (row_info->color_type & PNG_COLOR_MASK_COLOR) ? 8 : 4;
/* The alpha channel is the last component: */
row += step - 2;
@ -4199,8 +4206,9 @@ png_do_encode_alpha(png_row_infop row_info, png_bytep row, png_structrp png_ptr)
* upon whether you supply trans and num_trans.
*/
static void
png_do_expand_palette(png_row_infop row_info, png_bytep row,
png_const_colorp palette, png_const_bytep trans_alpha, int num_trans)
png_do_expand_palette(png_structrp png_ptr, png_row_infop row_info,
png_bytep row, png_const_colorp palette, png_const_bytep trans_alpha,
int num_trans)
{
int shift, value;
png_bytep sp, dp;
@ -4304,14 +4312,25 @@ png_do_expand_palette(png_row_infop row_info, png_bytep row,
sp = row + (size_t)row_width - 1;
dp = row + ((size_t)row_width << 2) - 1;
for (i = 0; i < row_width; i++)
i = 0;
#ifdef PNG_ARM_NEON_INTRINSICS_AVAILABLE
if (png_ptr->riffled_palette != NULL)
{
/* The RGBA optimization works with png_ptr->bit_depth == 8
* but sometimes row_info->bit_depth has been changed to 8.
* In these cases, the palette hasn't been riffled.
*/
i = png_do_expand_palette_neon_rgba(png_ptr, row_info, row,
&sp, &dp);
}
#endif
for (; i < row_width; i++)
{
if ((int)(*sp) >= num_trans)
*dp-- = 0xff;
else
*dp-- = trans_alpha[*sp];
*dp-- = palette[*sp].blue;
*dp-- = palette[*sp].green;
*dp-- = palette[*sp].red;
@ -4328,8 +4347,13 @@ png_do_expand_palette(png_row_infop row_info, png_bytep row,
{
sp = row + (size_t)row_width - 1;
dp = row + (size_t)(row_width * 3) - 1;
i = 0;
#ifdef PNG_ARM_NEON_INTRINSICS_AVAILABLE
i = png_do_expand_palette_neon_rgb(png_ptr, row_info, row,
&sp, &dp);
#endif
for (i = 0; i < row_width; i++)
for (; i < row_width; i++)
{
*dp-- = palette[*sp].blue;
*dp-- = palette[*sp].green;
@ -4743,8 +4767,22 @@ png_do_read_transformations(png_structrp png_ptr, png_row_infop row_info)
{
if (row_info->color_type == PNG_COLOR_TYPE_PALETTE)
{
png_do_expand_palette(row_info, png_ptr->row_buf + 1,
png_ptr->palette, png_ptr->trans_alpha, png_ptr->num_trans);
#ifdef PNG_ARM_NEON_INTRINSICS_AVAILABLE
if ((png_ptr->num_trans > 0) && (png_ptr->bit_depth == 8))
{
/* Allocate space for the decompressed full palette. */
if (png_ptr->riffled_palette == NULL)
{
png_ptr->riffled_palette = png_malloc(png_ptr, 256*4);
if (png_ptr->riffled_palette == NULL)
png_error(png_ptr, "NULL row buffer");
/* Build the RGBA palette. */
png_riffle_palette_rgba(png_ptr, row_info);
}
}
#endif
png_do_expand_palette(png_ptr, row_info, png_ptr->row_buf + 1,
png_ptr->palette, png_ptr->trans_alpha, png_ptr->num_trans);
}
else

View File

@ -1,10 +1,10 @@
/* pngrutil.c - utilities to read a PNG file
*
* Last changed in libpng 1.6.35 [July 15, 2018]
* Copyright (c) 2018 Cosmin Truta
* Copyright (c) 1998-2002,2004,2006-2018 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) 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
@ -1461,8 +1461,7 @@ png_handle_iCCP(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
{
/* We have the ICC profile header; do the basic header checks.
*/
const png_uint_32 profile_length =
png_get_uint_32(profile_header);
png_uint_32 profile_length = png_get_uint_32(profile_header);
if (png_icc_check_length(png_ptr, &png_ptr->colorspace,
keyword, profile_length) != 0)
@ -1479,8 +1478,8 @@ png_handle_iCCP(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)
* profile. The header check has already validated
* that none of this stuff will overflow.
*/
const png_uint_32 tag_count = png_get_uint_32(
profile_header+128);
png_uint_32 tag_count =
png_get_uint_32(profile_header + 128);
png_bytep profile = png_read_buffer(png_ptr,
profile_length, 2/*silent*/);
@ -3132,7 +3131,7 @@ png_handle_unknown(png_structrp png_ptr, png_inforp info_ptr,
*/
void /* PRIVATE */
png_check_chunk_name(png_const_structrp png_ptr, const png_uint_32 chunk_name)
png_check_chunk_name(png_const_structrp png_ptr, png_uint_32 chunk_name)
{
int i;
png_uint_32 cn=chunk_name;
@ -3151,7 +3150,7 @@ png_check_chunk_name(png_const_structrp png_ptr, const png_uint_32 chunk_name)
}
void /* PRIVATE */
png_check_chunk_length(png_const_structrp png_ptr, const png_uint_32 length)
png_check_chunk_length(png_const_structrp png_ptr, png_uint_32 length)
{
png_alloc_size_t limit = PNG_UINT_31_MAX;
@ -3363,7 +3362,7 @@ png_combine_row(png_const_structrp png_ptr, png_bytep dp, int display)
/* Hence the pre-compiled masks indexed by PACKSWAP (or not), depth and
* then pass:
*/
static PNG_CONST png_uint_32 row_mask[2/*PACKSWAP*/][3/*depth*/][6] =
static const png_uint_32 row_mask[2/*PACKSWAP*/][3/*depth*/][6] =
{
/* Little-endian byte masks for PACKSWAP */
{ S_MASKS(1,0), S_MASKS(2,0), S_MASKS(4,0) },
@ -3374,7 +3373,7 @@ png_combine_row(png_const_structrp png_ptr, png_bytep dp, int display)
/* display_mask has only three entries for the odd passes, so index by
* pass>>1.
*/
static PNG_CONST png_uint_32 display_mask[2][3][3] =
static const png_uint_32 display_mask[2][3][3] =
{
/* Little-endian byte masks for PACKSWAP */
{ B_MASKS(1,0), B_MASKS(2,0), B_MASKS(4,0) },
@ -3687,7 +3686,7 @@ png_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,
{
/* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
/* Offset to next interlace block */
static PNG_CONST unsigned int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
static const unsigned int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
png_debug(1, "in png_do_read_interlace");
if (row != NULL && row_info != NULL)
@ -4329,16 +4328,16 @@ png_read_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[7] = {0, 4, 0, 2, 0, 1, 0};
static const png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
/* Offset to next interlace block */
static PNG_CONST png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
static const png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
/* Start of interlace block in the y direction */
static PNG_CONST png_byte png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
static const png_byte png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
/* Offset to next interlace block in the y direction */
static PNG_CONST png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
static const png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
png_debug(1, "in png_read_finish_row");
png_ptr->row_number++;
@ -4394,16 +4393,16 @@ png_read_start_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[7] = {0, 4, 0, 2, 0, 1, 0};
static const png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
/* Offset to next interlace block */
static PNG_CONST png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
static const png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
/* Start of interlace block in the y direction */
static PNG_CONST png_byte png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
static const png_byte png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
/* Offset to next interlace block in the y direction */
static PNG_CONST png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
static const png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
unsigned int max_pixel_depth;
size_t row_bytes;

View File

@ -1,10 +1,10 @@
/* pngset.c - storage of image information into info struct
*
* Last changed in libpng 1.6.35 [July 15, 2018]
* Copyright (c) 2018 Cosmin Truta
* Copyright (c) 1998-2018 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) 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
@ -137,7 +137,7 @@ png_set_cHRM_XYZ(png_const_structrp png_ptr, png_inforp info_ptr, double red_X,
#ifdef PNG_eXIf_SUPPORTED
void PNGAPI
png_set_eXIf(png_const_structrp png_ptr, png_inforp info_ptr,
const png_bytep eXIf_buf)
png_bytep eXIf_buf)
{
png_warning(png_ptr, "png_set_eXIf does not work; use png_set_eXIf_1");
PNG_UNUSED(info_ptr)
@ -146,7 +146,7 @@ png_set_eXIf(png_const_structrp png_ptr, png_inforp info_ptr,
void PNGAPI
png_set_eXIf_1(png_const_structrp png_ptr, png_inforp info_ptr,
const png_uint_32 num_exif, const png_bytep eXIf_buf)
png_uint_32 num_exif, png_bytep eXIf_buf)
{
int i;
@ -1399,7 +1399,7 @@ png_set_keep_unknown_chunks(png_structrp png_ptr, int keep,
/* Ignore all unknown chunks and all chunks recognized by
* libpng except for IHDR, PLTE, tRNS, IDAT, and IEND
*/
static PNG_CONST png_byte chunks_to_ignore[] = {
static const png_byte chunks_to_ignore[] = {
98, 75, 71, 68, '\0', /* bKGD */
99, 72, 82, 77, '\0', /* cHRM */
101, 88, 73, 102, '\0', /* eXIf */

View File

@ -1,10 +1,10 @@
/* pngstruct.h - header file for PNG reference library
*
* Last changed in libpng 1.6.35 [July 15, 2018]
* Copyright (c) 2018 Cosmin Truta
* Copyright (c) 1998-2002,2004,2006-2018 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) 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
@ -228,6 +228,10 @@ struct png_struct_def
* big_row_buf; while writing it is separately
* allocated.
*/
#ifdef PNG_READ_EXPAND_SUPPORTED
/* Buffer to accelerate palette transformations. */
png_bytep riffled_palette;
#endif
#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 */

View File

@ -1,10 +1,10 @@
/* pngtrans.c - transforms the data in a row (used by both readers and writers)
*
* Last changed in libpng 1.6.35 [July 15, 2018]
* Copyright (c) 2018 Cosmin Truta
* Copyright (c) 1998-2002,2004,2006-2018 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) 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
@ -345,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,
@ -380,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,
@ -415,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,

View File

@ -1,10 +1,10 @@
/* pngwio.c - functions for data output
*
* Last changed in libpng 1.6.35 [July 15, 2018]
* Copyright (c) 2018 Cosmin Truta
* Copyright (c) 1998-2002,2004,2006-2014,2016,2018 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) 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

View File

@ -1,10 +1,10 @@
/* pngwrite.c - general routines to write a PNG file
*
* Last changed in libpng 1.6.35 [July 15, 2018]
* Copyright (c) 2018 Cosmin Truta
* Copyright (c) 1998-2002,2004,2006-2018 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) 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
@ -469,7 +469,7 @@ png_write_end(png_structrp png_ptr, png_inforp info_ptr)
#ifdef PNG_CONVERT_tIME_SUPPORTED
void PNGAPI
png_convert_from_struct_tm(png_timep ptime, PNG_CONST struct tm * ttime)
png_convert_from_struct_tm(png_timep ptime, const struct tm * ttime)
{
png_debug(1, "in png_convert_from_struct_tm");
@ -948,6 +948,10 @@ png_write_destroy(png_structrp png_ptr)
png_free_buffer_list(png_ptr, &png_ptr->zbuffer_list);
png_free(png_ptr, png_ptr->row_buf);
png_ptr->row_buf = NULL;
#ifdef PNG_READ_EXPANDED_SUPPORTED
png_free(png_ptr, png_ptr->riffled_palette);
png_ptr->riffled_palette = NULL;
#endif
#ifdef PNG_WRITE_FILTER_SUPPORTED
png_free(png_ptr, png_ptr->prev_row);
png_free(png_ptr, png_ptr->try_row);
@ -1536,7 +1540,7 @@ png_write_image_16bit(png_voidp argument)
display->first_row);
png_uint_16p output_row = png_voidcast(png_uint_16p, display->local_row);
png_uint_16p row_end;
const unsigned int channels = (image->format & PNG_FORMAT_FLAG_COLOR) != 0 ?
unsigned int channels = (image->format & PNG_FORMAT_FLAG_COLOR) != 0 ?
3 : 1;
int aindex = 0;
png_uint_32 y = image->height;
@ -1573,7 +1577,7 @@ png_write_image_16bit(png_voidp argument)
while (out_ptr < row_end)
{
const png_uint_16 alpha = in_ptr[aindex];
png_uint_16 alpha = in_ptr[aindex];
png_uint_32 reciprocal = 0;
int c;
@ -1695,7 +1699,7 @@ png_write_image_8bit(png_voidp argument)
display->first_row);
png_bytep output_row = png_voidcast(png_bytep, display->local_row);
png_uint_32 y = image->height;
const unsigned int channels = (image->format & PNG_FORMAT_FLAG_COLOR) != 0 ?
unsigned int channels = (image->format & PNG_FORMAT_FLAG_COLOR) != 0 ?
3 : 1;
if ((image->format & PNG_FORMAT_FLAG_ALPHA) != 0)
@ -1783,25 +1787,25 @@ png_write_image_8bit(png_voidp argument)
static void
png_image_set_PLTE(png_image_write_control *display)
{
const png_imagep image = display->image;
png_imagep image = display->image;
const void *cmap = display->colormap;
const int entries = image->colormap_entries > 256 ? 256 :
int entries = image->colormap_entries > 256 ? 256 :
(int)image->colormap_entries;
/* NOTE: the caller must check for cmap != NULL and entries != 0 */
const png_uint_32 format = image->format;
const unsigned int channels = PNG_IMAGE_SAMPLE_CHANNELS(format);
png_uint_32 format = image->format;
unsigned int channels = PNG_IMAGE_SAMPLE_CHANNELS(format);
# if defined(PNG_FORMAT_BGR_SUPPORTED) &&\
defined(PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED)
const int afirst = (format & PNG_FORMAT_FLAG_AFIRST) != 0 &&
int afirst = (format & PNG_FORMAT_FLAG_AFIRST) != 0 &&
(format & PNG_FORMAT_FLAG_ALPHA) != 0;
# else
# define afirst 0
# endif
# ifdef PNG_FORMAT_BGR_SUPPORTED
const int bgr = (format & PNG_FORMAT_FLAG_BGR) != 0 ? 2 : 0;
int bgr = (format & PNG_FORMAT_FLAG_BGR) != 0 ? 2 : 0;
# else
# define bgr 0
# endif
@ -1951,12 +1955,12 @@ png_image_write_main(png_voidp argument)
* and total image size to ensure that they are within the system limits.
*/
{
const unsigned int channels = PNG_IMAGE_PIXEL_CHANNELS(image->format);
unsigned int channels = PNG_IMAGE_PIXEL_CHANNELS(image->format);
if (image->width <= 0x7fffffffU/channels) /* no overflow */
{
png_uint_32 check;
const png_uint_32 png_row_stride = image->width * channels;
png_uint_32 png_row_stride = image->width * channels;
if (display->row_stride == 0)
display->row_stride = (png_int_32)/*SAFE*/png_row_stride;
@ -2052,7 +2056,7 @@ png_image_write_main(png_voidp argument)
*/
if (write_16bit != 0)
{
PNG_CONST png_uint_16 le = 0x0001;
png_uint_16 le = 0x0001;
if ((*(png_const_bytep) & le) != 0)
png_set_swap(png_ptr);
@ -2166,7 +2170,7 @@ image_memory_write)(png_structp png_ptr, png_bytep/*const*/ data, size_t size)
{
png_image_write_control *display = png_voidcast(png_image_write_control*,
png_ptr->io_ptr/*backdoor: png_get_io_ptr(png_ptr)*/);
const png_alloc_size_t ob = display->output_bytes;
png_alloc_size_t ob = display->output_bytes;
/* Check for overflow; this should never happen: */
if (size <= ((png_alloc_size_t)-1) - ob)

View File

@ -1,10 +1,10 @@
/* pngwtran.c - transforms the data in a row for PNG writers
*
* Last changed in libpng 1.6.35 [July 15, 2018]
* Copyright (c) 2018 Cosmin Truta
* Copyright (c) 1998-2002,2004,2006-2016,2018 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) 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
@ -254,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;
@ -283,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;

View File

@ -1,10 +1,10 @@
/* pngwutil.c - utilities to write a PNG file
*
* Last changed in libpng 1.6.35 [July 15, 2018]
* Copyright (c) 2018 Cosmin Truta
* Copyright (c) 1998-2002,2004,2006-2018 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) 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
@ -1893,16 +1893,16 @@ png_write_start_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[7] = {0, 4, 0, 2, 0, 1, 0};
static const png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
/* Offset to next interlace block */
static PNG_CONST png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
static const png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
/* Start of interlace block in the y direction */
static PNG_CONST png_byte png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
static const png_byte png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
/* Offset to next interlace block in the y direction */
static PNG_CONST png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
static const png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
#endif
png_alloc_size_t buf_size;
@ -2008,16 +2008,16 @@ png_write_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[7] = {0, 4, 0, 2, 0, 1, 0};
static const png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
/* Offset to next interlace block */
static PNG_CONST png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
static const png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
/* Start of interlace block in the y direction */
static PNG_CONST png_byte png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
static const png_byte png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
/* Offset to next interlace block in the y direction */
static PNG_CONST png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
static const png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
#endif
png_debug(1, "in png_write_finish_row");
@ -2098,10 +2098,10 @@ png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
/* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
/* Start of interlace block */
static PNG_CONST png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
static const png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
/* Offset to next interlace block */
static PNG_CONST png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
static const png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
png_debug(1, "in png_do_write_interlace");
@ -2276,7 +2276,7 @@ png_write_filtered_row(png_structrp png_ptr, png_bytep filtered_row,
#ifdef PNG_WRITE_FILTER_SUPPORTED
static size_t /* PRIVATE */
png_setup_sub_row(png_structrp png_ptr, const png_uint_32 bpp,
png_setup_sub_row(png_structrp png_ptr, png_uint_32 bpp,
size_t row_bytes, size_t lmins)
{
png_bytep rp, dp, lp;
@ -2315,7 +2315,7 @@ png_setup_sub_row(png_structrp png_ptr, const png_uint_32 bpp,
}
static void /* PRIVATE */
png_setup_sub_row_only(png_structrp png_ptr, const png_uint_32 bpp,
png_setup_sub_row_only(png_structrp png_ptr, png_uint_32 bpp,
size_t row_bytes)
{
png_bytep rp, dp, lp;
@ -2380,7 +2380,7 @@ png_setup_up_row_only(png_structrp png_ptr, size_t row_bytes)
}
static size_t /* PRIVATE */
png_setup_avg_row(png_structrp png_ptr, const png_uint_32 bpp,
png_setup_avg_row(png_structrp png_ptr, png_uint_32 bpp,
size_t row_bytes, size_t lmins)
{
png_bytep rp, dp, pp, lp;
@ -2420,7 +2420,7 @@ png_setup_avg_row(png_structrp png_ptr, const png_uint_32 bpp,
return (sum);
}
static void /* PRIVATE */
png_setup_avg_row_only(png_structrp png_ptr, const png_uint_32 bpp,
png_setup_avg_row_only(png_structrp png_ptr, png_uint_32 bpp,
size_t row_bytes)
{
png_bytep rp, dp, pp, lp;
@ -2442,7 +2442,7 @@ png_setup_avg_row_only(png_structrp png_ptr, const png_uint_32 bpp,
}
static size_t /* PRIVATE */
png_setup_paeth_row(png_structrp png_ptr, const png_uint_32 bpp,
png_setup_paeth_row(png_structrp png_ptr, png_uint_32 bpp,
size_t row_bytes, size_t lmins)
{
png_bytep rp, dp, pp, cp, lp;
@ -2503,7 +2503,7 @@ png_setup_paeth_row(png_structrp png_ptr, const png_uint_32 bpp,
return (sum);
}
static void /* PRIVATE */
png_setup_paeth_row_only(png_structrp png_ptr, const png_uint_32 bpp,
png_setup_paeth_row_only(png_structrp png_ptr, png_uint_32 bpp,
size_t row_bytes)
{
png_bytep rp, dp, pp, cp, lp;

View File

@ -1,13 +1,14 @@
/* filter_vsx_intrinsics.c - PowerPC optimised filter functions
*
* Copyright (c) 2018 Cosmin Truta
* Copyright (c) 2017 Glenn Randers-Pehrson
* Written by Vadim Barkov, 2017.
* Last changed in libpng 1.6.29 [March 16, 2017]
*
* This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer
* and license in png.h
*/
#include <stdio.h>
#include <stdint.h>
#include "../pngpriv.h"
@ -173,7 +174,7 @@ static const vector unsigned char VSX_SHORT_TO_CHAR4_3 = {16,16,16,16,16,16,16,1
void png_read_filter_row_sub4_vsx(png_row_infop row_info, png_bytep row,
png_const_bytep prev_row)
{
const png_byte bpp = 4;
png_byte bpp = 4;
vector unsigned char rp_vec;
vector unsigned char part_vec;
@ -230,7 +231,7 @@ void png_read_filter_row_sub4_vsx(png_row_infop row_info, png_bytep row,
void png_read_filter_row_sub3_vsx(png_row_infop row_info, png_bytep row,
png_const_bytep prev_row)
{
const png_byte bpp = 3;
png_byte bpp = 3;
vector unsigned char rp_vec;
vector unsigned char part_vec;
@ -294,7 +295,7 @@ void png_read_filter_row_sub3_vsx(png_row_infop row_info, png_bytep row,
void png_read_filter_row_avg4_vsx(png_row_infop row_info, png_bytep row,
png_const_bytep prev_row)
{
const png_byte bpp = 4;
png_byte bpp = 4;
vector unsigned char rp_vec;
vector unsigned char pp_vec;
@ -381,7 +382,7 @@ void png_read_filter_row_avg4_vsx(png_row_infop row_info, png_bytep row,
void png_read_filter_row_avg3_vsx(png_row_infop row_info, png_bytep row,
png_const_bytep prev_row)
{
const png_byte bpp = 3;
png_byte bpp = 3;
vector unsigned char rp_vec;
vector unsigned char pp_vec;
@ -499,7 +500,7 @@ void png_read_filter_row_avg3_vsx(png_row_infop row_info, png_bytep row,
void png_read_filter_row_paeth4_vsx(png_row_infop row_info, png_bytep row,
png_const_bytep prev_row)
{
const png_byte bpp = 4;
png_byte bpp = 4;
int a, b, c, pa, pb, pc, p;
vector unsigned char rp_vec;
@ -619,7 +620,7 @@ void png_read_filter_row_paeth4_vsx(png_row_infop row_info, png_bytep row,
void png_read_filter_row_paeth3_vsx(png_row_infop row_info, png_bytep row,
png_const_bytep prev_row)
{
const png_byte bpp = 3;
png_byte bpp = 3;
int a, b, c, pa, pb, pc, p;
vector unsigned char rp_vec;

View File

@ -1,14 +1,15 @@
/* powerpc_init.c - POWERPC optimised filter functions
*
* Copyright (c) 2018 Cosmin Truta
* Copyright (c) 2017 Glenn Randers-Pehrson
* Written by Vadim Barkov, 2017.
* Last changed in libpng 1.6.29 [March 16, 2017]
*
* This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer
* and license in png.h
*/
/* Below, after checking __linux__, various non-C90 POSIX 1003.1 functions are
* called.
*/

View File

@ -414,10 +414,11 @@ set(lib_srcs
tif_tile.c
tif_version.c
tif_warning.c
tif_webp.c
tif_write.c
tif_zip.c
tif_zstd.c
tif_stream.cxx
snprintf.c
t4.h
tif_dir.h
tif_fax3.h
@ -432,6 +433,10 @@ set(lib_srcs
"${CMAKE_CURRENT_BINARY_DIR}/tiffconf.h"
)
if(WIN32 AND NOT HAVE_SNPRINTF)
list(APPEND lib_srcs snprintf.c libport.h)
endif()
if(WIN32 AND NOT WINRT)
list(APPEND lib_srcs tif_win32.c)
else()
@ -444,7 +449,7 @@ ocv_warnings_disable(CMAKE_C_FLAGS -Wno-unused-but-set-variable -Wmissing-protot
-Wimplicit-fallthrough
)
ocv_warnings_disable(CMAKE_C_FLAGS -Wunused-parameter) # clang
ocv_warnings_disable(CMAKE_CXX_FLAGS -Wmissing-declarations -Wunused-parameter
ocv_warnings_disable(CMAKE_CXX_FLAGS -Wmissing-declarations -Wunused-parameter -Wmissing-prototypes
-Wundef # tiffiop.h: #if __clang_major__ >= 4
)
ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4018 /wd4100 /wd4127 /wd4311 /wd4701 /wd4706) # vs2005

File diff suppressed because it is too large Load Diff

67
3rdparty/libtiff/libport.h vendored Normal file
View File

@ -0,0 +1,67 @@
/*
* Copyright (c) 2009 Frank Warmerdam
*
* Permission to use, copy, modify, distribute, and sell this software and
* its documentation for any purpose is hereby granted without fee, provided
* that (i) the above copyright notices and this permission notice appear in
* all copies of the software and related documentation, and (ii) the names of
* Sam Leffler and Silicon Graphics may not be used in any advertising or
* publicity relating to the software without the specific, prior written
* permission of Sam Leffler and Silicon Graphics.
*
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
*
* IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
* ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
* OF THIS SOFTWARE.
*/
#ifndef _LIBPORT_
#define _LIBPORT_
int getopt(int argc, char * const argv[], const char *optstring);
extern char *optarg;
extern int opterr;
extern int optind;
extern int optopt;
int strcasecmp(const char *s1, const char *s2);
#ifndef HAVE_GETOPT
# define HAVE_GETOPT 1
#endif
#if HAVE_STRTOL
long strtol(const char *nptr, char **endptr, int base);
#endif
#if HAVE_STRTOLL
long long strtoll(const char *nptr, char **endptr, int base);
#endif
#if HAVE_STRTOUL
unsigned long strtoul(const char *nptr, char **endptr, int base);
#endif
#if HAVE_STRTOULL
unsigned long long strtoull(const char *nptr, char **endptr, int base);
#endif
#if 0
void *
lfind(const void *key, const void *base, size_t *nmemb, size_t size,
int(*compar)(const void *, const void *));
#endif
#if !defined(HAVE_SNPRINTF)
#undef vsnprintf
#define vsnprintf _TIFF_vsnprintf_f
#undef snprintf
#define snprintf _TIFF_snprintf_f
int snprintf(char* str, size_t size, const char* format, ...);
#endif
#endif /* ndef _LIBPORT_ */

View File

@ -9,6 +9,7 @@
#include <stdio.h>
#include <stdarg.h>
#include "libport.h"
int _TIFF_vsnprintf_f(char* str, size_t size, const char* format, va_list ap)
{
@ -35,4 +36,3 @@ int _TIFF_snprintf_f(char* str, size_t size, const char* format, ...)
}
#endif // _MSC_VER

View File

@ -1,5 +1,3 @@
/* $Id: t4.h,v 1.3 2010-03-10 18:56:48 bfriesen Exp $ */
/*
* Copyright (c) 1988-1997 Sam Leffler
* Copyright (c) 1991-1997 Silicon Graphics, Inc.

View File

@ -1,5 +1,3 @@
/* $Id: tif_aux.c,v 1.31 2017-11-17 20:21:00 erouault Exp $ */
/*
* Copyright (c) 1991-1997 Sam Leffler
* Copyright (c) 1991-1997 Silicon Graphics, Inc.

View File

@ -1,5 +1,3 @@
/* $Id: tif_close.c,v 1.21 2016-01-23 21:20:34 erouault Exp $ */
/*
* Copyright (c) 1988-1997 Sam Leffler
* Copyright (c) 1991-1997 Silicon Graphics, Inc.

View File

@ -1,5 +1,3 @@
/* $Id: tif_codec.c,v 1.17 2015-08-19 02:31:04 bfriesen Exp $ */
/*
* Copyright (c) 1988-1997 Sam Leffler
* Copyright (c) 1991-1997 Silicon Graphics, Inc.
@ -72,6 +70,12 @@ static int NotConfigured(TIFF*, int);
#ifndef LZMA_SUPPORT
#define TIFFInitLZMA NotConfigured
#endif
#ifndef ZSTD_SUPPORT
#define TIFFInitZSTD NotConfigured
#endif
#ifndef WEBP_SUPPORT
#define TIFFInitWebP NotConfigured
#endif
/*
* Compression schemes statically built into the library.
@ -99,6 +103,8 @@ TIFFCodec _TIFFBuiltinCODECS[] = {
{ "SGILog", COMPRESSION_SGILOG, TIFFInitSGILog },
{ "SGILog24", COMPRESSION_SGILOG24, TIFFInitSGILog },
{ "LZMA", COMPRESSION_LZMA, TIFFInitLZMA },
{ "ZSTD", COMPRESSION_ZSTD, TIFFInitZSTD },
{ "WEBP", COMPRESSION_WEBP, TIFFInitWebP },
{ NULL, 0, NULL }
};

View File

@ -1,5 +1,3 @@
/* $Id: tif_color.c,v 1.24 2017-05-29 10:12:54 erouault Exp $ */
/*
* Copyright (c) 1988-1997 Sam Leffler
* Copyright (c) 1991-1997 Silicon Graphics, Inc.
@ -168,7 +166,7 @@ TIFFCIELabToRGBInit(TIFFCIELabToRGB* cielab,
}
/*
* Convert color value from the YCbCr space to CIE XYZ.
* Convert color value from the YCbCr space to RGB.
* The colorspace conversion algorithm comes from the IJG v5a code;
* see below for more information on how it works.
*/

View File

@ -1,5 +1,3 @@
/* $Id: tif_compress.c,v 1.25 2016-10-25 20:04:22 erouault Exp $ */
/*
* Copyright (c) 1988-1997 Sam Leffler
* Copyright (c) 1991-1997 Silicon Graphics, Inc.

View File

@ -26,9 +26,6 @@
/* Define to 1 if you have the <fcntl.h> header file. */
#cmakedefine HAVE_FCNTL_H 1
/* Define to 1 if you have the `floor' function. */
#cmakedefine HAVE_FLOOR 1
/* Define to 1 if you have the `getopt' function. */
#cmakedefine HAVE_GETOPT 1
@ -50,30 +47,12 @@
/* Define to 1 if you have the <io.h> header file. */
#cmakedefine HAVE_IO_H 1
/* Define to 1 if you have the `isascii' function. */
#cmakedefine HAVE_ISASCII 1
/* Define to 1 if you have the `jbg_newlen' function. */
#cmakedefine HAVE_JBG_NEWLEN 1
/* Define to 1 if you have the `lfind' function. */
#cmakedefine HAVE_LFIND 1
/* Define to 1 if you have the <limits.h> header file. */
#cmakedefine HAVE_LIMITS_H 1
/* Define to 1 if you have the <malloc.h> header file. */
#cmakedefine HAVE_MALLOC_H 1
/* Define to 1 if you have the `memmove' function. */
#cmakedefine HAVE_MEMMOVE 1
/* Define to 1 if you have the <memory.h> header file. */
#cmakedefine HAVE_MEMORY_H 1
/* Define to 1 if you have the `memset' function. */
#cmakedefine HAVE_MEMSET 1
/* Define to 1 if you have the `mmap' function. */
#cmakedefine HAVE_MMAP 1
@ -83,9 +62,6 @@
/* Define to 1 if you have the <OpenGL/gl.h> header file. */
#cmakedefine HAVE_OPENGL_GL_H 1
/* Define to 1 if you have the `pow' function. */
#cmakedefine HAVE_POW 1
/* Define to 1 if you have the <search.h> header file. */
#cmakedefine HAVE_SEARCH_H 1
@ -95,33 +71,24 @@
/* Define to 1 if you have the `snprintf' function. */
#cmakedefine HAVE_SNPRINTF 1
/* Define to 1 if you have the `sqrt' function. */
#cmakedefine HAVE_SQRT 1
/* Define to 1 if you have the <stdint.h> header file. */
#cmakedefine HAVE_STDINT_H 1
/* Define to 1 if you have the `strcasecmp' function. */
#cmakedefine HAVE_STRCASECMP 1
/* Define to 1 if you have the `strchr' function. */
#cmakedefine HAVE_STRCHR 1
/* Define to 1 if you have the <strings.h> header file. */
#cmakedefine HAVE_STRINGS_H 1
/* Define to 1 if you have the <string.h> header file. */
#cmakedefine HAVE_STRING_H 1
/* Define to 1 if you have the `strrchr' function. */
#cmakedefine HAVE_STRRCHR 1
/* Define to 1 if you have the `strstr' function. */
#cmakedefine HAVE_STRSTR 1
/* Define to 1 if you have the `strtol' function. */
#cmakedefine HAVE_STRTOL 1
/* Define to 1 if you have the `strtoll' function. */
#cmakedefine HAVE_STRTOLL 1
/* Define to 1 if you have the `strtoul' function. */
#cmakedefine HAVE_STRTOUL 1
@ -146,6 +113,12 @@
/* Support LZMA2 compression */
#cmakedefine LZMA_SUPPORT 1
/* Support ZSTD compression */
#cmakedefine ZSTD_SUPPORT 1
/* Support WEBP compression */
#cmakedefine WEBP_SUPPORT 1
/* Name of package */
#define PACKAGE "@PACKAGE_NAME@"
@ -176,9 +149,6 @@
/* The size of `signed long long', as computed by sizeof. */
#define SIZEOF_SIGNED_LONG_LONG @SIZEOF_SIGNED_LONG_LONG@
/* The size of `signed short', as computed by sizeof. */
#define SIZEOF_SIGNED_SHORT @SIZEOF_SIGNED_SHORT@
/* The size of `unsigned char *', as computed by sizeof. */
#define SIZEOF_UNSIGNED_CHAR_P @SIZEOF_UNSIGNED_CHAR_P@
@ -245,6 +215,9 @@
# endif
#endif
/* Number of bits in a file offset, on hosts where this is settable. */
#define _FILE_OFFSET_BITS @FILE_OFFSET_BITS@
/* Define to `__inline__' or `__inline' if that's what the C compiler
calls it, or to nothing if 'inline' is not supported under any name. */
#ifndef __cplusplus

View File

@ -1,5 +1,3 @@
/* $Id: tif_dir.c,v 1.131 2017-07-11 21:38:04 erouault Exp $ */
/*
* Copyright (c) 1988-1997 Sam Leffler
* Copyright (c) 1991-1997 Silicon Graphics, Inc.
@ -863,14 +861,24 @@ _TIFFVGetField(TIFF* tif, uint32 tag, va_list ap)
const TIFFField* fip = TIFFFindField(tif, tag, TIFF_ANY);
if( fip == NULL ) /* cannot happen since TIFFGetField() already checks it */
return 0;
/*
* We want to force the custom code to be used for custom
* fields even if the tag happens to match a well known
* one - important for reinterpreted handling of standard
* tag values in custom directories (i.e. EXIF)
*/
if (fip->field_bit == FIELD_CUSTOM) {
standard_tag = 0;
}
if( tag == TIFFTAG_NUMBEROFINKS )
if( standard_tag == TIFFTAG_NUMBEROFINKS )
{
int i;
for (i = 0; i < td->td_customValueCount; i++) {
uint16 val;
TIFFTagValue *tv = td->td_customValues + i;
if (tv->info->field_tag != tag)
if (tv->info->field_tag != standard_tag)
continue;
if( tv->value == NULL )
return 0;
@ -892,16 +900,6 @@ _TIFFVGetField(TIFF* tif, uint32 tag, va_list ap)
return 0;
}
/*
* We want to force the custom code to be used for custom
* fields even if the tag happens to match a well known
* one - important for reinterpreted handling of standard
* tag values in custom directories (i.e. EXIF)
*/
if (fip->field_bit == FIELD_CUSTOM) {
standard_tag = 0;
}
switch (standard_tag) {
case TIFFTAG_SUBFILETYPE:
*va_arg(ap, uint32*) = td->td_subfiletype;
@ -1067,6 +1065,9 @@ _TIFFVGetField(TIFF* tif, uint32 tag, va_list ap)
if (td->td_samplesperpixel - td->td_extrasamples > 1) {
*va_arg(ap, uint16**) = td->td_transferfunction[1];
*va_arg(ap, uint16**) = td->td_transferfunction[2];
} else {
*va_arg(ap, uint16**) = NULL;
*va_arg(ap, uint16**) = NULL;
}
break;
case TIFFTAG_REFERENCEBLACKWHITE:

View File

@ -1,5 +1,3 @@
/* $Id: tif_dir.h,v 1.55 2017-06-01 12:44:04 erouault Exp $ */
/*
* Copyright (c) 1988-1997 Sam Leffler
* Copyright (c) 1991-1997 Silicon Graphics, Inc.
@ -26,6 +24,10 @@
#ifndef _TIFFDIR_
#define _TIFFDIR_
#include "tiff.h"
#include "tiffio.h"
/*
* ``Library-private'' Directory-related Definitions.
*/

View File

@ -1,5 +1,3 @@
/* $Id: tif_dirinfo.c,v 1.127 2017-06-01 12:44:04 erouault Exp $ */
/*
* Copyright (c) 1988-1997 Sam Leffler
* Copyright (c) 1991-1997 Silicon Graphics, Inc.
@ -979,6 +977,8 @@ _TIFFCheckFieldIsValidForCodec(TIFF *tif, ttag_t tag)
case TIFFTAG_CONSECUTIVEBADFAXLINES:
case TIFFTAG_GROUP3OPTIONS:
case TIFFTAG_GROUP4OPTIONS:
/* LERC */
case TIFFTAG_LERC_PARAMETERS:
break;
default:
return 1;
@ -1054,7 +1054,18 @@ _TIFFCheckFieldIsValidForCodec(TIFF *tif, ttag_t tag)
if (tag == TIFFTAG_PREDICTOR)
return 1;
break;
case COMPRESSION_ZSTD:
if (tag == TIFFTAG_PREDICTOR)
return 1;
break;
case COMPRESSION_LERC:
if (tag == TIFFTAG_LERC_PARAMETERS)
return 1;
break;
case COMPRESSION_WEBP:
if (tag == TIFFTAG_PREDICTOR)
return 1;
break;
}
return 0;
}

View File

@ -1,5 +1,3 @@
/* $Id: tif_dirread.c,v 1.218 2017-09-09 21:44:42 erouault Exp $ */
/*
* Copyright (c) 1988-1997 Sam Leffler
* Copyright (c) 1991-1997 Silicon Graphics, Inc.
@ -167,6 +165,7 @@ static int TIFFFetchStripThing(TIFF* tif, TIFFDirEntry* dir, uint32 nstrips, uin
static int TIFFFetchSubjectDistance(TIFF*, TIFFDirEntry*);
static void ChopUpSingleUncompressedStrip(TIFF*);
static uint64 TIFFReadUInt64(const uint8 *value);
static int _TIFFGetMaxColorChannels(uint16 photometric);
static int _TIFFFillStrilesInternal( TIFF *tif, int loadStripByteCount );
@ -776,7 +775,7 @@ static enum TIFFReadDirEntryErr TIFFReadDirEntryIfd8(TIFF* tif, TIFFDirEntry* di
static enum TIFFReadDirEntryErr TIFFReadDirEntryDataAndRealloc(
TIFF* tif, uint64 offset, tmsize_t size, void** pdest)
{
#if SIZEOF_VOIDP == 8 || SIZEOF_SIZE_T == 8
#if SIZEOF_SIZE_T == 8
tmsize_t threshold = INITIAL_THRESHOLD;
#endif
tmsize_t already_read = 0;
@ -797,7 +796,7 @@ static enum TIFFReadDirEntryErr TIFFReadDirEntryDataAndRealloc(
void* new_dest;
tmsize_t bytes_read;
tmsize_t to_read = size - already_read;
#if SIZEOF_VOIDP == 8 || SIZEOF_SIZE_T == 8
#if SIZEOF_SIZE_T == 8
if( to_read >= threshold && threshold < MAX_THRESHOLD )
{
to_read = threshold;
@ -3506,6 +3505,35 @@ static void TIFFReadDirEntryOutputErr(TIFF* tif, enum TIFFReadDirEntryErr err, c
}
}
/*
* Return the maximum number of color channels specified for a given photometric
* type. 0 is returned if photometric type isn't supported or no default value
* is defined by the specification.
*/
static int _TIFFGetMaxColorChannels( uint16 photometric )
{
switch (photometric) {
case PHOTOMETRIC_PALETTE:
case PHOTOMETRIC_MINISWHITE:
case PHOTOMETRIC_MINISBLACK:
return 1;
case PHOTOMETRIC_YCBCR:
case PHOTOMETRIC_RGB:
case PHOTOMETRIC_CIELAB:
case PHOTOMETRIC_LOGLUV:
case PHOTOMETRIC_ITULAB:
case PHOTOMETRIC_ICCLAB:
return 3;
case PHOTOMETRIC_SEPARATED:
case PHOTOMETRIC_MASK:
return 4;
case PHOTOMETRIC_LOGL:
case PHOTOMETRIC_CFA:
default:
return 0;
}
}
/*
* Read the next TIFF directory from a file and convert it to the internal
* format. We read directories sequentially.
@ -3522,6 +3550,7 @@ TIFFReadDirectory(TIFF* tif)
uint32 fii=FAILED_FII;
toff_t nextdiroff;
int bitspersample_read = FALSE;
int color_channels;
tif->tif_diroff=tif->tif_nextdiroff;
if (!TIFFCheckDirOffset(tif,tif->tif_nextdiroff))
@ -4026,6 +4055,37 @@ TIFFReadDirectory(TIFF* tif)
}
}
}
/*
* Make sure all non-color channels are extrasamples.
* If it's not the case, define them as such.
*/
color_channels = _TIFFGetMaxColorChannels(tif->tif_dir.td_photometric);
if (color_channels && tif->tif_dir.td_samplesperpixel - tif->tif_dir.td_extrasamples > color_channels) {
uint16 old_extrasamples;
uint16 *new_sampleinfo;
TIFFWarningExt(tif->tif_clientdata,module, "Sum of Photometric type-related "
"color channels and ExtraSamples doesn't match SamplesPerPixel. "
"Defining non-color channels as ExtraSamples.");
old_extrasamples = tif->tif_dir.td_extrasamples;
tif->tif_dir.td_extrasamples = (uint16) (tif->tif_dir.td_samplesperpixel - color_channels);
// sampleinfo should contain information relative to these new extra samples
new_sampleinfo = (uint16*) _TIFFcalloc(tif->tif_dir.td_extrasamples, sizeof(uint16));
if (!new_sampleinfo) {
TIFFErrorExt(tif->tif_clientdata, module, "Failed to allocate memory for "
"temporary new sampleinfo array (%d 16 bit elements)",
tif->tif_dir.td_extrasamples);
goto bad;
}
memcpy(new_sampleinfo, tif->tif_dir.td_sampleinfo, old_extrasamples * sizeof(uint16));
_TIFFsetShortArray(&tif->tif_dir.td_sampleinfo, new_sampleinfo, tif->tif_dir.td_extrasamples);
_TIFFfree(new_sampleinfo);
}
/*
* Verify Palette image has a Colormap.
*/
@ -4881,17 +4941,18 @@ TIFFFetchNormalTag(TIFF* tif, TIFFDirEntry* dp, int recover)
err=TIFFReadDirEntryByteArray(tif,dp,&data);
if (err==TIFFReadDirEntryErrOk)
{
uint8* ma;
uint32 mb;
uint32 mb = 0;
int n;
ma=data;
mb=0;
while (mb<(uint32)dp->tdir_count)
if (data != NULL)
{
if (*ma==0)
break;
ma++;
mb++;
uint8* ma = data;
while (mb<(uint32)dp->tdir_count)
{
if (*ma==0)
break;
ma++;
mb++;
}
}
if (mb+1<(uint32)dp->tdir_count)
TIFFWarningExt(tif->tif_clientdata,module,"ASCII value for tag \"%s\" contains null byte in value; value incorrectly truncated during reading due to implementation limitations",fip->field_name);
@ -5141,11 +5202,11 @@ TIFFFetchNormalTag(TIFF* tif, TIFFDirEntry* dp, int recover)
if (err==TIFFReadDirEntryErrOk)
{
int m;
if( dp->tdir_count > 0 && data[dp->tdir_count-1] != '\0' )
{
TIFFWarningExt(tif->tif_clientdata,module,"ASCII value for tag \"%s\" does not end in null byte. Forcing it to be null",fip->field_name);
data[dp->tdir_count-1] = '\0';
}
if( data != 0 && dp->tdir_count > 0 && data[dp->tdir_count-1] != '\0' )
{
TIFFWarningExt(tif->tif_clientdata,module,"ASCII value for tag \"%s\" does not end in null byte. Forcing it to be null",fip->field_name);
data[dp->tdir_count-1] = '\0';
}
m=TIFFSetField(tif,dp->tdir_tag,(uint16)(dp->tdir_count),data);
if (data!=0)
_TIFFfree(data);
@ -5318,11 +5379,11 @@ TIFFFetchNormalTag(TIFF* tif, TIFFDirEntry* dp, int recover)
if (err==TIFFReadDirEntryErrOk)
{
int m;
if( dp->tdir_count > 0 && data[dp->tdir_count-1] != '\0' )
{
TIFFWarningExt(tif->tif_clientdata,module,"ASCII value for tag \"%s\" does not end in null byte. Forcing it to be null",fip->field_name);
data[dp->tdir_count-1] = '\0';
}
if( data != 0 && dp->tdir_count > 0 && data[dp->tdir_count-1] != '\0' )
{
TIFFWarningExt(tif->tif_clientdata,module,"ASCII value for tag \"%s\" does not end in null byte. Forcing it to be null",fip->field_name);
data[dp->tdir_count-1] = '\0';
}
m=TIFFSetField(tif,dp->tdir_tag,(uint32)(dp->tdir_count),data);
if (data!=0)
_TIFFfree(data);
@ -5698,6 +5759,16 @@ ChopUpSingleUncompressedStrip(TIFF* tif)
if( nstrips == 0 )
return;
/* If we are going to allocate a lot of memory, make sure that the */
/* file is as big as needed */
if( tif->tif_mode == O_RDONLY &&
nstrips > 1000000 &&
(offset >= TIFFGetFileSize(tif) ||
stripbytes > (TIFFGetFileSize(tif) - offset) / (nstrips - 1)) )
{
return;
}
newcounts = (uint64*) _TIFFCheckMalloc(tif, nstrips, sizeof (uint64),
"for chopped \"StripByteCounts\" array");
newoffsets = (uint64*) _TIFFCheckMalloc(tif, nstrips, sizeof (uint64),

View File

@ -1,5 +1,3 @@
/* $Id: tif_dirwrite.c,v 1.89 2017-08-23 13:33:42 erouault Exp $ */
/*
* Copyright (c) 1988-1997 Sam Leffler
* Copyright (c) 1991-1997 Silicon Graphics, Inc.
@ -697,8 +695,11 @@ TIFFWriteDirectorySec(TIFF* tif, int isimage, int imagedone, uint64* pdiroff)
}
break;
default:
assert(0); /* we should never get here */
break;
TIFFErrorExt(tif->tif_clientdata,module,
"Cannot write tag %d (%s)",
TIFFFieldTag(o),
o->field_name ? o->field_name : "unknown");
goto bad;
}
}
}

View File

@ -1,5 +1,3 @@
/* $Header: /cvs/maptools/cvsroot/libtiff/libtiff/tif_dumpmode.c,v 1.15 2015-12-12 18:04:26 erouault Exp $ */
/*
* Copyright (c) 1988-1997 Sam Leffler
* Copyright (c) 1991-1997 Silicon Graphics, Inc.

View File

@ -1,5 +1,3 @@
/* $Header: /cvs/maptools/cvsroot/libtiff/libtiff/tif_error.c,v 1.6 2017-07-04 12:54:42 erouault Exp $ */
/*
* Copyright (c) 1988-1997 Sam Leffler
* Copyright (c) 1991-1997 Silicon Graphics, Inc.

View File

@ -1,5 +1,3 @@
/* $Header: /cvs/maptools/cvsroot/libtiff/libtiff/tif_extension.c,v 1.8 2015-12-06 11:13:43 erouault Exp $ */
/*
* Copyright (c) 1988-1997 Sam Leffler
* Copyright (c) 1991-1997 Silicon Graphics, Inc.

View File

@ -1,5 +1,3 @@
/* $Id: tif_fax3.c,v 1.81 2017-06-18 10:31:50 erouault Exp $ */
/*
* Copyright (c) 1990-1997 Sam Leffler
* Copyright (c) 1991-1997 Silicon Graphics, Inc.

View File

@ -1,5 +1,3 @@
/* $Id: tif_fax3.h,v 1.13 2016-12-14 18:36:27 faxguy Exp $ */
/*
* Copyright (c) 1990-1997 Sam Leffler
* Copyright (c) 1991-1997 Silicon Graphics, Inc.

View File

@ -1,5 +1,3 @@
/* $Id: tif_flush.c,v 1.9 2010-03-31 06:40:10 fwarmerdam Exp $ */
/*
* Copyright (c) 1988-1997 Sam Leffler
* Copyright (c) 1991-1997 Silicon Graphics, Inc.

View File

@ -1,5 +1,3 @@
/* $Id: tif_getimage.c,v 1.114 2017-11-17 20:21:00 erouault Exp $ */
/*
* Copyright (c) 1991-1997 Sam Leffler
* Copyright (c) 1991-1997 Silicon Graphics, Inc.

View File

@ -1,5 +1,3 @@
/* $Id: tif_jbig.c,v 1.16 2017-06-26 15:20:00 erouault Exp $ */
/*
* Copyright (c) 1988-1997 Sam Leffler
* Copyright (c) 1991-1997 Silicon Graphics, Inc.
@ -53,17 +51,18 @@ static int JBIGDecode(TIFF* tif, uint8* buffer, tmsize_t size, uint16 s)
struct jbg_dec_state decoder;
int decodeStatus = 0;
unsigned char* pImage = NULL;
(void) size, (void) s;
unsigned long decodedSize;
(void) s;
if (isFillOrder(tif, tif->tif_dir.td_fillorder))
{
TIFFReverseBits(tif->tif_rawdata, tif->tif_rawdatasize);
TIFFReverseBits(tif->tif_rawcp, tif->tif_rawcc);
}
jbg_dec_init(&decoder);
#if defined(HAVE_JBG_NEWLEN)
jbg_newlen(tif->tif_rawdata, (size_t)tif->tif_rawdatasize);
jbg_newlen(tif->tif_rawcp, (size_t)tif->tif_rawcc);
/*
* I do not check the return status of jbg_newlen because even if this
* function fails it does not necessarily mean that decoding the image
@ -76,8 +75,8 @@ static int JBIGDecode(TIFF* tif, uint8* buffer, tmsize_t size, uint16 s)
*/
#endif /* HAVE_JBG_NEWLEN */
decodeStatus = jbg_dec_in(&decoder, (unsigned char*)tif->tif_rawdata,
(size_t)tif->tif_rawdatasize, NULL);
decodeStatus = jbg_dec_in(&decoder, (unsigned char*)tif->tif_rawcp,
(size_t)tif->tif_rawcc, NULL);
if (JBG_EOK != decodeStatus)
{
/*
@ -98,9 +97,28 @@ static int JBIGDecode(TIFF* tif, uint8* buffer, tmsize_t size, uint16 s)
return 0;
}
decodedSize = jbg_dec_getsize(&decoder);
if( (tmsize_t)decodedSize < size )
{
TIFFWarningExt(tif->tif_clientdata, "JBIG",
"Only decoded %lu bytes, whereas %lu requested",
decodedSize, (unsigned long)size);
}
else if( (tmsize_t)decodedSize > size )
{
TIFFErrorExt(tif->tif_clientdata, "JBIG",
"Decoded %lu bytes, whereas %lu were requested",
decodedSize, (unsigned long)size);
jbg_dec_free(&decoder);
return 0;
}
pImage = jbg_dec_getimage(&decoder, 0);
_TIFFmemcpy(buffer, pImage, jbg_dec_getsize(&decoder));
_TIFFmemcpy(buffer, pImage, decodedSize);
jbg_dec_free(&decoder);
tif->tif_rawcp += tif->tif_rawcc;
tif->tif_rawcc = 0;
return 1;
}

View File

@ -1,5 +1,3 @@
/* $Id: tif_jpeg.c,v 1.134 2017-10-17 19:04:47 erouault Exp $ */
/*
* Copyright (c) 1994-1997 Sam Leffler
* Copyright (c) 1994-1997 Silicon Graphics, Inc.
@ -27,9 +25,9 @@
#define WIN32_LEAN_AND_MEAN
#define VC_EXTRALEAN
#include "tiffiop.h"
#include <stdlib.h>
#include "tiffiop.h"
#ifdef JPEG_SUPPORT
/*
@ -76,7 +74,7 @@ int TIFFJPEGIsFullStripRequired_12(TIFF* tif);
"JPEGLib: JPEG parameter struct mismatch: library thinks size is 432,
caller expects 464"
For such users we wil fix the problem here. See install.doc file from
For such users we will fix the problem here. See install.doc file from
the JPEG library distribution for details.
*/

View File

@ -1,5 +1,3 @@
/* $Id: tif_luv.c,v 1.49 2017-07-24 12:47:30 erouault Exp $ */
/*
* Copyright (c) 1997 Greg Ward Larson
* Copyright (c) 1997 Silicon Graphics, Inc.
@ -215,7 +213,7 @@ LogL16Decode(TIFF* tif, uint8* op, tmsize_t occ, uint16 s)
bp = (unsigned char*) tif->tif_rawcp;
cc = tif->tif_rawcc;
/* get each byte string */
for (shft = 2*8; (shft -= 8) >= 0; ) {
for (shft = 8; shft >= 0; shft -=8) {
for (i = 0; i < npixels && cc > 0; ) {
if (*bp >= 128) { /* run */
if( cc < 2 )
@ -349,7 +347,7 @@ LogLuvDecode32(TIFF* tif, uint8* op, tmsize_t occ, uint16 s)
bp = (unsigned char*) tif->tif_rawcp;
cc = tif->tif_rawcc;
/* get each byte string */
for (shft = 4*8; (shft -= 8) >= 0; ) {
for (shft = 24; shft >= 0; shft -=8) {
for (i = 0; i < npixels && cc > 0; ) {
if (*bp >= 128) { /* run */
if( cc < 2 )
@ -467,7 +465,7 @@ LogL16Encode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
/* compress each byte string */
op = tif->tif_rawcp;
occ = tif->tif_rawdatasize - tif->tif_rawcc;
for (shft = 2*8; (shft -= 8) >= 0; )
for (shft = 8; shft >= 0; shft -=8) {
for (i = 0; i < npixels; i += rc) {
if (occ < 4) {
tif->tif_rawcp = op;
@ -522,6 +520,7 @@ LogL16Encode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
} else
rc = 0;
}
}
tif->tif_rawcp = op;
tif->tif_rawcc = tif->tif_rawdatasize - occ;
@ -618,7 +617,7 @@ LogLuvEncode32(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
/* compress each byte string */
op = tif->tif_rawcp;
occ = tif->tif_rawdatasize - tif->tif_rawcc;
for (shft = 4*8; (shft -= 8) >= 0; )
for (shft = 24; shft >= 0; shft -=8) {
for (i = 0; i < npixels; i += rc) {
if (occ < 4) {
tif->tif_rawcp = op;
@ -673,6 +672,7 @@ LogLuvEncode32(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
} else
rc = 0;
}
}
tif->tif_rawcp = op;
tif->tif_rawcc = tif->tif_rawdatasize - occ;

View File

@ -1,5 +1,3 @@
/* $Id: tif_lzma.c,v 1.6 2016-09-17 09:18:59 erouault Exp $ */
/*
* Copyright (c) 2010, Andrey Kiselev <dron@ak4719.spb.edu>
*
@ -249,6 +247,7 @@ LZMAPreEncode(TIFF* tif, uint16 s)
{
static const char module[] = "LZMAPreEncode";
LZMAState *sp = EncoderState(tif);
lzma_ret ret;
(void) s;
assert(sp != NULL);
@ -262,7 +261,13 @@ LZMAPreEncode(TIFF* tif, uint16 s)
"Liblzma cannot deal with buffers this size");
return 0;
}
return (lzma_stream_encoder(&sp->stream, sp->filters, sp->check) == LZMA_OK);
ret = lzma_stream_encoder(&sp->stream, sp->filters, sp->check);
if (ret != LZMA_OK) {
TIFFErrorExt(tif->tif_clientdata, module,
"Error in lzma_stream_encoder(): %s", LZMAStrerror(ret));
return 0;
}
return 1;
}
/*

View File

@ -1,5 +1,3 @@
/* $Id: tif_lzw.c,v 1.57 2017-07-11 10:54:29 erouault Exp $ */
/*
* Copyright (c) 1988-1997 Sam Leffler
* Copyright (c) 1991-1997 Silicon Graphics, Inc.
@ -135,6 +133,7 @@ typedef struct {
long dec_restart; /* restart count */
#ifdef LZW_CHECKEOS
uint64 dec_bitsleft; /* available bits in raw data */
tmsize_t old_tif_rawcc; /* value of tif_rawcc at the end of the previous TIFLZWDecode() call */
#endif
decodeFunc dec_decode; /* regular or backwards compatible */
code_t* dec_codep; /* current recognized code */
@ -320,6 +319,7 @@ LZWPreDecode(TIFF* tif, uint16 s)
sp->dec_nbitsmask = MAXCODE(BITS_MIN);
#ifdef LZW_CHECKEOS
sp->dec_bitsleft = 0;
sp->old_tif_rawcc = 0;
#endif
sp->dec_free_entp = sp->dec_codetab + CODE_FIRST;
/*
@ -427,7 +427,7 @@ LZWDecode(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s)
bp = (unsigned char *)tif->tif_rawcp;
#ifdef LZW_CHECKEOS
sp->dec_bitsleft = (((uint64)tif->tif_rawcc) << 3);
sp->dec_bitsleft += (((uint64)tif->tif_rawcc - sp->old_tif_rawcc) << 3);
#endif
nbits = sp->lzw_nbits;
nextdata = sp->lzw_nextdata;
@ -555,6 +555,9 @@ LZWDecode(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s)
tif->tif_rawcc -= (tmsize_t)( (uint8*) bp - tif->tif_rawcp );
tif->tif_rawcp = (uint8*) bp;
#ifdef LZW_CHECKEOS
sp->old_tif_rawcc = tif->tif_rawcc;
#endif
sp->lzw_nbits = (unsigned short) nbits;
sp->lzw_nextdata = nextdata;
sp->lzw_nextbits = nextbits;
@ -604,6 +607,7 @@ LZWDecodeCompat(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s)
char *tp;
unsigned char *bp;
int code, nbits;
int len;
long nextbits, nextdata, nbitsmask;
code_t *codep, *free_entp, *maxcodep, *oldcodep;
@ -657,7 +661,7 @@ LZWDecodeCompat(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s)
bp = (unsigned char *)tif->tif_rawcp;
#ifdef LZW_CHECKEOS
sp->dec_bitsleft = (((uint64)tif->tif_rawcc) << 3);
sp->dec_bitsleft += (((uint64)tif->tif_rawcc - sp->old_tif_rawcc) << 3);
#endif
nbits = sp->lzw_nbits;
nextdata = sp->lzw_nextdata;
@ -755,13 +759,18 @@ LZWDecodeCompat(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s)
} while (--occ);
break;
}
assert(occ >= codep->length);
op += codep->length;
occ -= codep->length;
tp = op;
len = codep->length;
tp = op + len;
do {
*--tp = codep->value;
} while( (codep = codep->next) != NULL );
int t;
--tp;
t = codep->value;
codep = codep->next;
*tp = (char)t;
} while (codep && tp > op);
assert(occ >= len);
op += len;
occ -= len;
} else {
*op++ = (char)code;
occ--;
@ -770,6 +779,9 @@ LZWDecodeCompat(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s)
tif->tif_rawcc -= (tmsize_t)( (uint8*) bp - tif->tif_rawcp );
tif->tif_rawcp = (uint8*) bp;
#ifdef LZW_CHECKEOS
sp->old_tif_rawcc = tif->tif_rawcc;
#endif
sp->lzw_nbits = (unsigned short)nbits;
sp->lzw_nextdata = nextdata;
sp->lzw_nextbits = nextbits;

View File

@ -1,5 +1,3 @@
/* $Id: tif_next.c,v 1.19 2016-09-04 21:32:56 erouault Exp $ */
/*
* Copyright (c) 1988-1997 Sam Leffler
* Copyright (c) 1991-1997 Silicon Graphics, Inc.

View File

@ -1,5 +1,3 @@
/* $Id: tif_ojpeg.c,v 1.69 2017-04-27 17:29:26 erouault Exp $ */
/* WARNING: The type of JPEG encapsulation defined by the TIFF Version 6.0
specification is now totally obsolete and deprecated for new applications and
images. This file was was created solely in order to read unconverted images

View File

@ -1,5 +1,3 @@
/* $Id: tif_open.c,v 1.48 2016-11-20 22:29:47 erouault Exp $ */
/*
* Copyright (c) 1988-1997 Sam Leffler
* Copyright (c) 1991-1997 Silicon Graphics, Inc.

View File

@ -1,5 +1,3 @@
/* $Id: tif_packbits.c,v 1.26 2017-05-14 02:26:07 erouault Exp $ */
/*
* Copyright (c) 1988-1997 Sam Leffler
* Copyright (c) 1991-1997 Silicon Graphics, Inc.

View File

@ -1,5 +1,3 @@
/* $Id: tif_pixarlog.c,v 1.54 2017-07-10 10:40:28 erouault Exp $ */
/*
* Copyright (c) 1996-1997 Sam Leffler
* Copyright (c) 1996 Pixar

View File

@ -1,5 +1,3 @@
/* $Id: tif_predict.c,v 1.44 2017-06-18 10:31:50 erouault Exp $ */
/*
* Copyright (c) 1988-1997 Sam Leffler
* Copyright (c) 1991-1997 Silicon Graphics, Inc.

View File

@ -1,5 +1,3 @@
/* $Id: tif_predict.h,v 1.9 2016-10-31 17:24:26 erouault Exp $ */
/*
* Copyright (c) 1995-1997 Sam Leffler
* Copyright (c) 1995-1997 Silicon Graphics, Inc.
@ -26,6 +24,10 @@
#ifndef _TIFFPREDICT_
#define _TIFFPREDICT_
#include "tiffio.h"
#include "tiffiop.h"
/*
* ``Library-private'' Support for the Predictor Tag
*/

View File

@ -1,5 +1,3 @@
/* $Id: tif_print.c,v 1.65 2016-11-20 22:31:22 erouault Exp $ */
/*
* Copyright (c) 1988-1997 Sam Leffler
* Copyright (c) 1991-1997 Silicon Graphics, Inc.
@ -546,7 +544,7 @@ TIFFPrintDirectory(TIFF* tif, FILE* fd, long flags)
uint16 i;
fprintf(fd, " %2ld: %5u",
l, td->td_transferfunction[0][l]);
for (i = 1; i < td->td_samplesperpixel; i++)
for (i = 1; i < td->td_samplesperpixel - td->td_extrasamples && i < 3; i++)
fprintf(fd, " %5u",
td->td_transferfunction[i][l]);
fputc('\n', fd);
@ -667,13 +665,13 @@ TIFFPrintDirectory(TIFF* tif, FILE* fd, long flags)
#if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
fprintf(fd, " %3lu: [%8I64u, %8I64u]\n",
(unsigned long) s,
(unsigned __int64) td->td_stripoffset[s],
(unsigned __int64) td->td_stripbytecount[s]);
td->td_stripoffset ? (unsigned __int64) td->td_stripoffset[s] : 0,
td->td_stripbytecount ? (unsigned __int64) td->td_stripbytecount[s] : 0);
#else
fprintf(fd, " %3lu: [%8llu, %8llu]\n",
(unsigned long) s,
(unsigned long long) td->td_stripoffset[s],
(unsigned long long) td->td_stripbytecount[s]);
td->td_stripoffset ? (unsigned long long) td->td_stripoffset[s] : 0,
td->td_stripbytecount ? (unsigned long long) td->td_stripbytecount[s] : 0);
#endif
}
}

View File

@ -1,5 +1,3 @@
/* $Id: tif_read.c,v 1.66 2017-11-17 20:21:00 erouault Exp $ */
/*
* Copyright (c) 1988-1997 Sam Leffler
* Copyright (c) 1991-1997 Silicon Graphics, Inc.
@ -58,7 +56,7 @@ static int TIFFReadAndRealloc( TIFF* tif, tmsize_t size,
int is_strip, uint32 strip_or_tile,
const char* module )
{
#if SIZEOF_VOIDP == 8 || SIZEOF_SIZE_T == 8
#if SIZEOF_SIZE_T == 8
tmsize_t threshold = INITIAL_THRESHOLD;
#endif
tmsize_t already_read = 0;
@ -73,7 +71,7 @@ static int TIFFReadAndRealloc( TIFF* tif, tmsize_t size,
{
tmsize_t bytes_read;
tmsize_t to_read = size - already_read;
#if SIZEOF_VOIDP == 8 || SIZEOF_SIZE_T == 8
#if SIZEOF_SIZE_T == 8
if( to_read >= threshold && threshold < MAX_THRESHOLD &&
already_read + to_read + rawdata_offset > tif->tif_rawdatasize )
{
@ -348,6 +346,13 @@ TIFFSeek(TIFF* tif, uint32 row, uint16 sample )
return 0;
whole_strip = tif->tif_dir.td_stripbytecount[strip] < 10
|| isMapped(tif);
if( td->td_compression == COMPRESSION_LERC ||
td->td_compression == COMPRESSION_JBIG )
{
/* Ideally plugins should have a way to declare they don't support
* chunk strip */
whole_strip = 1;
}
#else
whole_strip = 1;
#endif

View File

@ -1,26 +1,24 @@
/* $Id: tif_stream.cxx,v 1.11 2010-12-11 23:12:29 faxguy Exp $ */
/*
* Copyright (c) 1988-1996 Sam Leffler
* Copyright (c) 1991-1996 Silicon Graphics, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software and
* Permission to use, copy, modify, distribute, and sell this software and
* its documentation for any purpose is hereby granted without fee, provided
* that (i) the above copyright notices and this permission notice appear in
* all copies of the software and related documentation, and (ii) the names of
* Sam Leffler and Silicon Graphics may not be used in any advertising or
* publicity relating to the software without the specific, prior written
* permission of Sam Leffler and Silicon Graphics.
*
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
*
*
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
*
* IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
* ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
* OF THIS SOFTWARE.
*/
@ -28,7 +26,6 @@
* TIFF Library UNIX-specific Routines.
*/
#include "tiffiop.h"
#include "tiffio.hxx"
#include <iostream>
#ifndef __VMS
@ -81,30 +78,30 @@ struct tiffos_data;
extern "C" {
static tmsize_t _tiffosReadProc(thandle_t, void*, tmsize_t);
static tmsize_t _tiffisReadProc(thandle_t fd, void* buf, tmsize_t size);
static tmsize_t _tiffosWriteProc(thandle_t fd, void* buf, tmsize_t size);
static tmsize_t _tiffisWriteProc(thandle_t, void*, tmsize_t);
static uint64 _tiffosSeekProc(thandle_t fd, uint64 off, int whence);
static uint64 _tiffisSeekProc(thandle_t fd, uint64 off, int whence);
static uint64 _tiffosSizeProc(thandle_t fd);
static uint64 _tiffisSizeProc(thandle_t fd);
static int _tiffosCloseProc(thandle_t fd);
static int _tiffisCloseProc(thandle_t fd);
static int _tiffDummyMapProc(thandle_t , void** base, toff_t* size );
static void _tiffDummyUnmapProc(thandle_t , void* base, toff_t size );
static TIFF* _tiffStreamOpen(const char* name, const char* mode, void *fd);
static tmsize_t _tiffosReadProc(thandle_t, void*, tmsize_t);
static tmsize_t _tiffisReadProc(thandle_t fd, void* buf, tmsize_t size);
static tmsize_t _tiffosWriteProc(thandle_t fd, void* buf, tmsize_t size);
static tmsize_t _tiffisWriteProc(thandle_t, void*, tmsize_t);
static uint64 _tiffosSeekProc(thandle_t fd, uint64 off, int whence);
static uint64 _tiffisSeekProc(thandle_t fd, uint64 off, int whence);
static uint64 _tiffosSizeProc(thandle_t fd);
static uint64 _tiffisSizeProc(thandle_t fd);
static int _tiffosCloseProc(thandle_t fd);
static int _tiffisCloseProc(thandle_t fd);
static int _tiffDummyMapProc(thandle_t , void** base, toff_t* size );
static void _tiffDummyUnmapProc(thandle_t , void* base, toff_t size );
static TIFF* _tiffStreamOpen(const char* name, const char* mode, void *fd);
struct tiffis_data
{
istream *stream;
istream *stream;
ios::pos_type start_pos;
};
struct tiffos_data
{
ostream *stream;
ios::pos_type start_pos;
ostream *stream;
ios::pos_type start_pos;
};
static tmsize_t
@ -131,222 +128,226 @@ _tiffisReadProc(thandle_t fd, void* buf, tmsize_t size)
static tmsize_t
_tiffosWriteProc(thandle_t fd, void* buf, tmsize_t size)
{
tiffos_data *data = reinterpret_cast<tiffos_data *>(fd);
ostream *os = data->stream;
ios::pos_type pos = os->tellp();
tiffos_data *data = reinterpret_cast<tiffos_data *>(fd);
ostream *os = data->stream;
ios::pos_type pos = os->tellp();
// Verify that type does not overflow.
streamsize request_size = size;
if (static_cast<tmsize_t>(request_size) != size)
return static_cast<tmsize_t>(-1);
os->write(reinterpret_cast<const char *>(buf), request_size);
os->write(reinterpret_cast<const char *>(buf), request_size);
return static_cast<tmsize_t>(os->tellp() - pos);
return static_cast<tmsize_t>(os->tellp() - pos);
}
static tmsize_t
_tiffisWriteProc(thandle_t, void*, tmsize_t)
{
return 0;
return 0;
}
static uint64
_tiffosSeekProc(thandle_t fd, uint64 off, int whence)
{
tiffos_data *data = reinterpret_cast<tiffos_data *>(fd);
ostream *os = data->stream;
tiffos_data *data = reinterpret_cast<tiffos_data *>(fd);
ostream *os = data->stream;
// if the stream has already failed, don't do anything
if( os->fail() )
return static_cast<uint64>(-1);
// if the stream has already failed, don't do anything
if( os->fail() )
return static_cast<uint64>(-1);
switch(whence) {
case SEEK_SET:
{
// Compute 64-bit offset
uint64 new_offset = static_cast<uint64>(data->start_pos) + off;
switch(whence) {
case SEEK_SET:
{
// Compute 64-bit offset
uint64 new_offset = static_cast<uint64>(data->start_pos) + off;
// Verify that value does not overflow
ios::off_type offset = static_cast<ios::off_type>(new_offset);
if (static_cast<uint64>(offset) != new_offset)
return static_cast<uint64>(-1);
// Verify that value does not overflow
ios::off_type offset = static_cast<ios::off_type>(new_offset);
if (static_cast<uint64>(offset) != new_offset)
return static_cast<uint64>(-1);
os->seekp(offset, ios::beg);
break;
}
case SEEK_CUR:
{
// Verify that value does not overflow
ios::off_type offset = static_cast<ios::off_type>(off);
if (static_cast<uint64>(offset) != off)
return static_cast<uint64>(-1);
os->seekp(offset, ios::beg);
break;
}
case SEEK_CUR:
{
// Verify that value does not overflow
ios::off_type offset = static_cast<ios::off_type>(off);
if (static_cast<uint64>(offset) != off)
return static_cast<uint64>(-1);
os->seekp(offset, ios::cur);
break;
}
case SEEK_END:
{
// Verify that value does not overflow
ios::off_type offset = static_cast<ios::off_type>(off);
if (static_cast<uint64>(offset) != off)
return static_cast<uint64>(-1);
os->seekp(offset, ios::cur);
break;
}
case SEEK_END:
{
// Verify that value does not overflow
ios::off_type offset = static_cast<ios::off_type>(off);
if (static_cast<uint64>(offset) != off)
return static_cast<uint64>(-1);
os->seekp(offset, ios::end);
break;
}
}
os->seekp(offset, ios::end);
break;
}
}
// Attempt to workaround problems with seeking past the end of the
// stream. ofstream doesn't have a problem with this but
// ostrstream/ostringstream does. In that situation, add intermediate
// '\0' characters.
if( os->fail() ) {
// Attempt to workaround problems with seeking past the end of the
// stream. ofstream doesn't have a problem with this but
// ostrstream/ostringstream does. In that situation, add intermediate
// '\0' characters.
if( os->fail() ) {
#ifdef __VMS
int old_state;
int old_state;
#else
ios::iostate old_state;
ios::iostate old_state;
#endif
ios::pos_type origin;
ios::pos_type origin;
old_state = os->rdstate();
// reset the fail bit or else tellp() won't work below
os->clear(os->rdstate() & ~ios::failbit);
switch( whence ) {
case SEEK_SET:
old_state = os->rdstate();
// reset the fail bit or else tellp() won't work below
os->clear(os->rdstate() & ~ios::failbit);
switch( whence ) {
case SEEK_SET:
default:
origin = data->start_pos;
break;
case SEEK_CUR:
origin = os->tellp();
break;
case SEEK_END:
os->seekp(0, ios::end);
origin = os->tellp();
break;
}
// restore original stream state
os->clear(old_state);
origin = data->start_pos;
break;
case SEEK_CUR:
origin = os->tellp();
break;
case SEEK_END:
os->seekp(0, ios::end);
origin = os->tellp();
break;
}
// restore original stream state
os->clear(old_state);
// only do something if desired seek position is valid
if( (static_cast<uint64>(origin) + off) > static_cast<uint64>(data->start_pos) ) {
uint64 num_fill;
// only do something if desired seek position is valid
if( (static_cast<uint64>(origin) + off) > static_cast<uint64>(data->start_pos) ) {
uint64 num_fill;
// clear the fail bit
os->clear(os->rdstate() & ~ios::failbit);
// clear the fail bit
os->clear(os->rdstate() & ~ios::failbit);
// extend the stream to the expected size
os->seekp(0, ios::end);
num_fill = (static_cast<uint64>(origin)) + off - os->tellp();
for( uint64 i = 0; i < num_fill; i++ )
os->put('\0');
// extend the stream to the expected size
os->seekp(0, ios::end);
num_fill = (static_cast<uint64>(origin)) + off - os->tellp();
for( uint64 i = 0; i < num_fill; i++ )
os->put('\0');
// retry the seek
os->seekp(static_cast<ios::off_type>(static_cast<uint64>(origin) + off), ios::beg);
}
}
// retry the seek
os->seekp(static_cast<ios::off_type>(static_cast<uint64>(origin) + off), ios::beg);
}
}
return static_cast<uint64>(os->tellp());
return static_cast<uint64>(os->tellp());
}
static uint64
_tiffisSeekProc(thandle_t fd, uint64 off, int whence)
{
tiffis_data *data = reinterpret_cast<tiffis_data *>(fd);
tiffis_data *data = reinterpret_cast<tiffis_data *>(fd);
switch(whence) {
case SEEK_SET:
{
// Compute 64-bit offset
uint64 new_offset = static_cast<uint64>(data->start_pos) + off;
switch(whence) {
case SEEK_SET:
{
// Compute 64-bit offset
uint64 new_offset = static_cast<uint64>(data->start_pos) + off;
// Verify that value does not overflow
ios::off_type offset = static_cast<ios::off_type>(new_offset);
if (static_cast<uint64>(offset) != new_offset)
return static_cast<uint64>(-1);
// Verify that value does not overflow
ios::off_type offset = static_cast<ios::off_type>(new_offset);
if (static_cast<uint64>(offset) != new_offset)
return static_cast<uint64>(-1);
data->stream->seekg(offset, ios::beg);
break;
}
case SEEK_CUR:
{
// Verify that value does not overflow
ios::off_type offset = static_cast<ios::off_type>(off);
if (static_cast<uint64>(offset) != off)
return static_cast<uint64>(-1);
data->stream->seekg(offset, ios::beg);
break;
}
case SEEK_CUR:
{
// Verify that value does not overflow
ios::off_type offset = static_cast<ios::off_type>(off);
if (static_cast<uint64>(offset) != off)
return static_cast<uint64>(-1);
data->stream->seekg(offset, ios::cur);
break;
}
case SEEK_END:
{
// Verify that value does not overflow
ios::off_type offset = static_cast<ios::off_type>(off);
if (static_cast<uint64>(offset) != off)
return static_cast<uint64>(-1);
data->stream->seekg(offset, ios::cur);
break;
}
case SEEK_END:
{
// Verify that value does not overflow
ios::off_type offset = static_cast<ios::off_type>(off);
if (static_cast<uint64>(offset) != off)
return static_cast<uint64>(-1);
data->stream->seekg(offset, ios::end);
break;
}
}
data->stream->seekg(offset, ios::end);
break;
}
}
return (uint64) (data->stream->tellg() - data->start_pos);
return (uint64) (data->stream->tellg() - data->start_pos);
}
static uint64
_tiffosSizeProc(thandle_t fd)
{
tiffos_data *data = reinterpret_cast<tiffos_data *>(fd);
ostream *os = data->stream;
ios::pos_type pos = os->tellp();
ios::pos_type len;
tiffos_data *data = reinterpret_cast<tiffos_data *>(fd);
ostream *os = data->stream;
ios::pos_type pos = os->tellp();
ios::pos_type len;
os->seekp(0, ios::end);
len = os->tellp();
os->seekp(pos);
os->seekp(0, ios::end);
len = os->tellp();
os->seekp(pos);
return (uint64) len;
return (uint64) len;
}
static uint64
_tiffisSizeProc(thandle_t fd)
{
tiffis_data *data = reinterpret_cast<tiffis_data *>(fd);
ios::pos_type pos = data->stream->tellg();
ios::pos_type len;
tiffis_data *data = reinterpret_cast<tiffis_data *>(fd);
ios::pos_type pos = data->stream->tellg();
ios::pos_type len;
data->stream->seekg(0, ios::end);
len = data->stream->tellg();
data->stream->seekg(pos);
data->stream->seekg(0, ios::end);
len = data->stream->tellg();
data->stream->seekg(pos);
return (uint64) len;
return (uint64) len;
}
static int
_tiffosCloseProc(thandle_t fd)
{
// Our stream was not allocated by us, so it shouldn't be closed by us.
delete reinterpret_cast<tiffos_data *>(fd);
return 0;
// Our stream was not allocated by us, so it shouldn't be closed by us.
delete reinterpret_cast<tiffos_data *>(fd);
return 0;
}
static int
_tiffisCloseProc(thandle_t fd)
{
// Our stream was not allocated by us, so it shouldn't be closed by us.
delete reinterpret_cast<tiffis_data *>(fd);
return 0;
// Our stream was not allocated by us, so it shouldn't be closed by us.
delete reinterpret_cast<tiffis_data *>(fd);
return 0;
}
static int
_tiffDummyMapProc(thandle_t , void** base, toff_t* size )
{
return (0);
(void) base;
(void) size;
return (0);
}
static void
_tiffDummyUnmapProc(thandle_t , void* base, toff_t size )
{
(void) base;
(void) size;
}
/*
@ -355,40 +356,46 @@ _tiffDummyUnmapProc(thandle_t , void* base, toff_t size )
static TIFF*
_tiffStreamOpen(const char* name, const char* mode, void *fd)
{
TIFF* tif;
TIFF* tif;
if( strchr(mode, 'w') ) {
tiffos_data *data = new tiffos_data;
data->stream = reinterpret_cast<ostream *>(fd);
data->start_pos = data->stream->tellp();
if( strchr(mode, 'w') ) {
tiffos_data *data = new tiffos_data;
data->stream = reinterpret_cast<ostream *>(fd);
data->start_pos = data->stream->tellp();
// Open for writing.
tif = TIFFClientOpen(name, mode,
reinterpret_cast<thandle_t>(data),
_tiffosReadProc,
// Open for writing.
tif = TIFFClientOpen(name, mode,
reinterpret_cast<thandle_t>(data),
_tiffosReadProc,
_tiffosWriteProc,
_tiffosSeekProc,
_tiffosSeekProc,
_tiffosCloseProc,
_tiffosSizeProc,
_tiffDummyMapProc,
_tiffosSizeProc,
_tiffDummyMapProc,
_tiffDummyUnmapProc);
} else {
tiffis_data *data = new tiffis_data;
data->stream = reinterpret_cast<istream *>(fd);
data->start_pos = data->stream->tellg();
// Open for reading.
tif = TIFFClientOpen(name, mode,
reinterpret_cast<thandle_t>(data),
_tiffisReadProc,
if (!tif) {
delete data;
}
} else {
tiffis_data *data = new tiffis_data;
data->stream = reinterpret_cast<istream *>(fd);
data->start_pos = data->stream->tellg();
// Open for reading.
tif = TIFFClientOpen(name, mode,
reinterpret_cast<thandle_t>(data),
_tiffisReadProc,
_tiffisWriteProc,
_tiffisSeekProc,
_tiffisSeekProc,
_tiffisCloseProc,
_tiffisSizeProc,
_tiffDummyMapProc,
_tiffisSizeProc,
_tiffDummyMapProc,
_tiffDummyUnmapProc);
}
if (!tif) {
delete data;
}
}
return (tif);
return (tif);
}
} /* extern "C" */
@ -396,31 +403,32 @@ _tiffStreamOpen(const char* name, const char* mode, void *fd)
TIFF*
TIFFStreamOpen(const char* name, ostream *os)
{
// If os is either a ostrstream or ostringstream, and has no data
// written to it yet, then tellp() will return -1 which will break us.
// We workaround this by writing out a dummy character and
// then seek back to the beginning.
if( !os->fail() && static_cast<int>(os->tellp()) < 0 ) {
*os << '\0';
os->seekp(0);
}
// If os is either a ostrstream or ostringstream, and has no data
// written to it yet, then tellp() will return -1 which will break us.
// We workaround this by writing out a dummy character and
// then seek back to the beginning.
if( !os->fail() && static_cast<int>(os->tellp()) < 0 ) {
*os << '\0';
os->seekp(0);
}
// NB: We don't support mapped files with streams so add 'm'
return _tiffStreamOpen(name, "wm", os);
// NB: We don't support mapped files with streams so add 'm'
return _tiffStreamOpen(name, "wm", os);
}
TIFF*
TIFFStreamOpen(const char* name, istream *is)
{
// NB: We don't support mapped files with streams so add 'm'
return _tiffStreamOpen(name, "rm", is);
// NB: We don't support mapped files with streams so add 'm'
return _tiffStreamOpen(name, "rm", is);
}
/* vim: set ts=8 sts=8 sw=8 noet: */
/*
Local Variables:
mode: c
indent-tabs-mode: true
c-basic-offset: 8
End:
*/
* Local Variables:
* mode: c
* c-basic-offset: 8
* fill-column: 78
* End:
*/

View File

@ -1,5 +1,3 @@
/* $Id: tif_strip.c,v 1.38 2016-12-03 11:02:15 erouault Exp $ */
/*
* Copyright (c) 1991-1997 Sam Leffler
* Copyright (c) 1991-1997 Silicon Graphics, Inc.

View File

@ -1,5 +1,3 @@
/* $Id: tif_swab.c,v 1.15 2017-06-08 16:39:50 erouault Exp $ */
/*
* Copyright (c) 1988-1997 Sam Leffler
* Copyright (c) 1991-1997 Silicon Graphics, Inc.

View File

@ -1,5 +1,3 @@
/* $Id: tif_thunder.c,v 1.13 2016-09-04 21:32:56 erouault Exp $ */
/*
* Copyright (c) 1988-1997 Sam Leffler
* Copyright (c) 1991-1997 Silicon Graphics, Inc.

View File

@ -1,5 +1,3 @@
/* $Id: tif_tile.c,v 1.24 2015-06-07 22:35:40 bfriesen Exp $ */
/*
* Copyright (c) 1991-1997 Sam Leffler
* Copyright (c) 1991-1997 Silicon Graphics, Inc.

View File

@ -1,5 +1,3 @@
/* $Id: tif_unix.c,v 1.28 2017-01-11 19:02:49 erouault Exp $ */
/*
* Copyright (c) 1988-1997 Sam Leffler
* Copyright (c) 1991-1997 Silicon Graphics, Inc.

View File

@ -1,4 +1,3 @@
/* $Header: /cvs/maptools/cvsroot/libtiff/libtiff/tif_version.c,v 1.3 2010-03-10 18:56:49 bfriesen Exp $ */
/*
* Copyright (c) 1992-1997 Sam Leffler
* Copyright (c) 1992-1997 Silicon Graphics, Inc.

View File

@ -1,5 +1,3 @@
/* $Header: /cvs/maptools/cvsroot/libtiff/libtiff/tif_warning.c,v 1.4 2017-07-04 12:54:42 erouault Exp $ */
/*
* Copyright (c) 1988-1997 Sam Leffler
* Copyright (c) 1991-1997 Silicon Graphics, Inc.

684
3rdparty/libtiff/tif_webp.c vendored Normal file
View File

@ -0,0 +1,684 @@
/*
* Copyright (c) 2018, Mapbox
* Author: <norman.barker at mapbox.com>
*
* Permission to use, copy, modify, distribute, and sell this software and
* its documentation for any purpose is hereby granted without fee, provided
* that (i) the above copyright notices and this permission notice appear in
* all copies of the software and related documentation, and (ii) the names of
* Sam Leffler and Silicon Graphics may not be used in any advertising or
* publicity relating to the software without the specific, prior written
* permission of Sam Leffler and Silicon Graphics.
*
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
*
* IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
* ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
* OF THIS SOFTWARE.
*/
#include "tiffiop.h"
#ifdef WEBP_SUPPORT
/*
* TIFF Library.
*
* WEBP Compression Support
*
*/
#include "webp/decode.h"
#include "webp/encode.h"
#include <stdio.h>
#define LSTATE_INIT_DECODE 0x01
#define LSTATE_INIT_ENCODE 0x02
/*
* State block for each open TIFF
* file using WEBP compression/decompression.
*/
typedef struct {
uint16 nSamples; /* number of samples per pixel */
int lossless; /* lossy/lossless compression */
int quality_level; /* compression level */
WebPPicture sPicture; /* WebP Picture */
WebPConfig sEncoderConfig; /* WebP encoder config */
uint8* pBuffer; /* buffer to hold raw data on encoding */
unsigned int buffer_offset; /* current offset into the buffer */
unsigned int buffer_size;
WebPIDecoder* psDecoder; /* WebPIDecoder */
WebPDecBuffer sDecBuffer; /* Decoder buffer */
int last_y; /* Last row decoded */
int state; /* state flags */
TIFFVGetMethod vgetparent; /* super-class method */
TIFFVSetMethod vsetparent; /* super-class method */
} WebPState;
#define LState(tif) ((WebPState*) (tif)->tif_data)
#define DecoderState(tif) LState(tif)
#define EncoderState(tif) LState(tif)
static int TWebPEncode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s);
static int TWebPDecode(TIFF* tif, uint8* op, tmsize_t occ, uint16 s);
static
int TWebPDatasetWriter(const uint8_t* data, size_t data_size,
const WebPPicture* const picture)
{
static const char module[] = "TWebPDatasetWriter";
TIFF* tif = (TIFF*)(picture->custom_ptr);
if ( (tif->tif_rawcc + (tmsize_t)data_size) > tif->tif_rawdatasize ) {
TIFFErrorExt(tif->tif_clientdata, module,
"Buffer too small by " TIFF_SIZE_FORMAT " bytes.",
(size_t) (tif->tif_rawcc + data_size - tif->tif_rawdatasize));
return 0;
} else {
_TIFFmemcpy(tif->tif_rawcp, data, data_size);
tif->tif_rawcc += data_size;
tif->tif_rawcp += data_size;
return 1;
}
}
/*
* Encode a chunk of pixels.
*/
static int
TWebPEncode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
{
static const char module[] = "TWebPEncode";
WebPState *sp = EncoderState(tif);
(void) s;
assert(sp != NULL);
assert(sp->state == LSTATE_INIT_ENCODE);
if( (uint64)sp->buffer_offset +
(uint64)cc > sp->buffer_size )
{
TIFFErrorExt(tif->tif_clientdata, module,
"Too many bytes to be written");
return 0;
}
memcpy(sp->pBuffer + sp->buffer_offset,
bp, cc);
sp->buffer_offset += (unsigned)cc;
return 1;
}
static int
TWebPDecode(TIFF* tif, uint8* op, tmsize_t occ, uint16 s)
{
static const char module[] = "WebPDecode";
VP8StatusCode status = VP8_STATUS_OK;
WebPState *sp = DecoderState(tif);
(void) s;
assert(sp != NULL);
assert(sp->state == LSTATE_INIT_DECODE);
if (occ % sp->sDecBuffer.u.RGBA.stride)
{
TIFFErrorExt(tif->tif_clientdata, module,
"Fractional scanlines cannot be read");
return 0;
}
status = WebPIAppend(sp->psDecoder, tif->tif_rawcp, tif->tif_rawcc);
if (status != VP8_STATUS_OK && status != VP8_STATUS_SUSPENDED) {
if (status == VP8_STATUS_INVALID_PARAM) {
TIFFErrorExt(tif->tif_clientdata, module,
"Invalid parameter used.");
} else if (status == VP8_STATUS_OUT_OF_MEMORY) {
TIFFErrorExt(tif->tif_clientdata, module,
"Out of memory.");
} else {
TIFFErrorExt(tif->tif_clientdata, module,
"Unrecognized error.");
}
return 0;
} else {
int current_y, stride;
uint8_t* buf;
/* Returns the RGB/A image decoded so far */
buf = WebPIDecGetRGB(sp->psDecoder, &current_y, NULL, NULL, &stride);
if ((buf != NULL) &&
(occ <= stride * (current_y - sp->last_y))) {
memcpy(op,
buf + (sp->last_y * stride),
occ);
tif->tif_rawcp += tif->tif_rawcc;
tif->tif_rawcc = 0;
sp->last_y += occ / sp->sDecBuffer.u.RGBA.stride;
return 1;
} else {
TIFFErrorExt(tif->tif_clientdata, module, "Unable to decode WebP data.");
return 0;
}
}
}
static int
TWebPFixupTags(TIFF* tif)
{
(void) tif;
if (tif->tif_dir.td_planarconfig != PLANARCONFIG_CONTIG) {
static const char module[] = "TWebPFixupTags";
TIFFErrorExt(tif->tif_clientdata, module,
"TIFF WEBP requires data to be stored contiguously in RGB e.g. RGBRGBRGB "
#if WEBP_ENCODER_ABI_VERSION >= 0x0100
"or RGBARGBARGBA"
#endif
);
return 0;
}
return 1;
}
static int
TWebPSetupDecode(TIFF* tif)
{
static const char module[] = "WebPSetupDecode";
uint16 nBitsPerSample = tif->tif_dir.td_bitspersample;
uint16 sampleFormat = tif->tif_dir.td_sampleformat;
WebPState* sp = DecoderState(tif);
assert(sp != NULL);
sp->nSamples = tif->tif_dir.td_samplesperpixel;
/* check band count */
if ( sp->nSamples != 3
#if WEBP_ENCODER_ABI_VERSION >= 0x0100
&& sp->nSamples != 4
#endif
)
{
TIFFErrorExt(tif->tif_clientdata, module,
"WEBP driver doesn't support %d bands. Must be 3 (RGB) "
#if WEBP_ENCODER_ABI_VERSION >= 0x0100
"or 4 (RGBA) "
#endif
"bands.",
sp->nSamples );
return 0;
}
/* check bits per sample and data type */
if ((nBitsPerSample != 8) && (sampleFormat != 1)) {
TIFFErrorExt(tif->tif_clientdata, module,
"WEBP driver requires 8 bit unsigned data");
return 0;
}
/* if we were last encoding, terminate this mode */
if (sp->state & LSTATE_INIT_ENCODE) {
WebPPictureFree(&sp->sPicture);
if (sp->pBuffer != NULL) {
_TIFFfree(sp->pBuffer);
sp->pBuffer = NULL;
}
sp->buffer_offset = 0;
sp->state = 0;
}
sp->state |= LSTATE_INIT_DECODE;
return 1;
}
/*
* Setup state for decoding a strip.
*/
static int
TWebPPreDecode(TIFF* tif, uint16 s)
{
static const char module[] = "TWebPPreDecode";
uint32 segment_width, segment_height;
WebPState* sp = DecoderState(tif);
TIFFDirectory* td = &tif->tif_dir;
(void) s;
assert(sp != NULL);
if (isTiled(tif)) {
segment_width = td->td_tilewidth;
segment_height = td->td_tilelength;
} else {
segment_width = td->td_imagewidth;
segment_height = td->td_imagelength - tif->tif_row;
if (segment_height > td->td_rowsperstrip)
segment_height = td->td_rowsperstrip;
}
if( (sp->state & LSTATE_INIT_DECODE) == 0 )
tif->tif_setupdecode(tif);
if (sp->psDecoder != NULL) {
WebPIDelete(sp->psDecoder);
WebPFreeDecBuffer(&sp->sDecBuffer);
sp->psDecoder = NULL;
}
sp->last_y = 0;
WebPInitDecBuffer(&sp->sDecBuffer);
sp->sDecBuffer.is_external_memory = 0;
sp->sDecBuffer.width = segment_width;
sp->sDecBuffer.height = segment_height;
sp->sDecBuffer.u.RGBA.stride = segment_width * sp->nSamples;
sp->sDecBuffer.u.RGBA.size = segment_width * sp->nSamples * segment_height;
if (sp->nSamples > 3) {
sp->sDecBuffer.colorspace = MODE_RGBA;
} else {
sp->sDecBuffer.colorspace = MODE_RGB;
}
sp->psDecoder = WebPINewDecoder(&sp->sDecBuffer);
if (sp->psDecoder == NULL) {
TIFFErrorExt(tif->tif_clientdata, module,
"Unable to allocate WebP decoder.");
return 0;
}
return 1;
}
static int
TWebPSetupEncode(TIFF* tif)
{
static const char module[] = "WebPSetupEncode";
uint16 nBitsPerSample = tif->tif_dir.td_bitspersample;
uint16 sampleFormat = tif->tif_dir.td_sampleformat;
WebPState* sp = EncoderState(tif);
assert(sp != NULL);
sp->nSamples = tif->tif_dir.td_samplesperpixel;
/* check band count */
if ( sp->nSamples != 3
#if WEBP_ENCODER_ABI_VERSION >= 0x0100
&& sp->nSamples != 4
#endif
)
{
TIFFErrorExt(tif->tif_clientdata, module,
"WEBP driver doesn't support %d bands. Must be 3 (RGB) "
#if WEBP_ENCODER_ABI_VERSION >= 0x0100
"or 4 (RGBA) "
#endif
"bands.",
sp->nSamples );
return 0;
}
/* check bits per sample and data type */
if ((nBitsPerSample != 8) && (sampleFormat != 1)) {
TIFFErrorExt(tif->tif_clientdata, module,
"WEBP driver requires 8 bit unsigned data");
return 0;
}
if (sp->state & LSTATE_INIT_DECODE) {
WebPIDelete(sp->psDecoder);
WebPFreeDecBuffer(&sp->sDecBuffer);
sp->psDecoder = NULL;
sp->last_y = 0;
sp->state = 0;
}
sp->state |= LSTATE_INIT_ENCODE;
if (!WebPConfigInitInternal(&sp->sEncoderConfig, WEBP_PRESET_DEFAULT,
sp->quality_level,
WEBP_ENCODER_ABI_VERSION)) {
TIFFErrorExt(tif->tif_clientdata, module,
"Error creating WebP encoder configuration.");
return 0;
}
#if WEBP_ENCODER_ABI_VERSION >= 0x0100
sp->sEncoderConfig.lossless = sp->lossless;
#endif
if (!WebPValidateConfig(&sp->sEncoderConfig)) {
TIFFErrorExt(tif->tif_clientdata, module,
"Error with WebP encoder configuration.");
return 0;
}
if (!WebPPictureInit(&sp->sPicture)) {
TIFFErrorExt(tif->tif_clientdata, module,
"Error initializing WebP picture.");
return 0;
}
return 1;
}
/*
* Reset encoding state at the start of a strip.
*/
static int
TWebPPreEncode(TIFF* tif, uint16 s)
{
static const char module[] = "TWebPPreEncode";
uint32 segment_width, segment_height;
WebPState *sp = EncoderState(tif);
TIFFDirectory* td = &tif->tif_dir;
(void) s;
assert(sp != NULL);
if( sp->state != LSTATE_INIT_ENCODE )
tif->tif_setupencode(tif);
/*
* Set encoding parameters for this strip/tile.
*/
if (isTiled(tif)) {
segment_width = td->td_tilewidth;
segment_height = td->td_tilelength;
} else {
segment_width = td->td_imagewidth;
segment_height = td->td_imagelength - tif->tif_row;
if (segment_height > td->td_rowsperstrip)
segment_height = td->td_rowsperstrip;
}
if( segment_width > 16383 || segment_height > 16383 ) {
TIFFErrorExt(tif->tif_clientdata, module,
"WEBP maximum image dimensions are 16383 x 16383.");
return 0;
}
/* set up buffer for raw data */
/* given above check and that nSamples <= 4, buffer_size is <= 1 GB */
sp->buffer_size = segment_width * segment_height * sp->nSamples;
sp->pBuffer = _TIFFmalloc(sp->buffer_size);
if( !sp->pBuffer) {
TIFFErrorExt(tif->tif_clientdata, module, "Cannot allocate buffer");
return 0;
}
sp->buffer_offset = 0;
sp->sPicture.width = segment_width;
sp->sPicture.height = segment_height;
sp->sPicture.writer = TWebPDatasetWriter;
sp->sPicture.custom_ptr = tif;
return 1;
}
/*
* Finish off an encoded strip by flushing it.
*/
static int
TWebPPostEncode(TIFF* tif)
{
static const char module[] = "WebPPostEncode";
int64_t stride;
WebPState *sp = EncoderState(tif);
assert(sp != NULL);
assert(sp->state == LSTATE_INIT_ENCODE);
stride = (int64_t)sp->sPicture.width * sp->nSamples;
#if WEBP_ENCODER_ABI_VERSION >= 0x0100
if (sp->nSamples == 4) {
if (!WebPPictureImportRGBA(&sp->sPicture, sp->pBuffer, (int)stride)) {
TIFFErrorExt(tif->tif_clientdata, module,
"WebPPictureImportRGBA() failed" );
return 0;
}
}
else
#endif
if (!WebPPictureImportRGB(&sp->sPicture, sp->pBuffer, (int)stride)) {
TIFFErrorExt(tif->tif_clientdata, module,
"WebPPictureImportRGB() failed");
return 0;
}
if (!WebPEncode(&sp->sEncoderConfig, &sp->sPicture)) {
#if WEBP_ENCODER_ABI_VERSION >= 0x0100
const char* pszErrorMsg = NULL;
switch(sp->sPicture.error_code) {
case VP8_ENC_ERROR_OUT_OF_MEMORY:
pszErrorMsg = "Out of memory"; break;
case VP8_ENC_ERROR_BITSTREAM_OUT_OF_MEMORY:
pszErrorMsg = "Out of memory while flushing bits"; break;
case VP8_ENC_ERROR_NULL_PARAMETER:
pszErrorMsg = "A pointer parameter is NULL"; break;
case VP8_ENC_ERROR_INVALID_CONFIGURATION:
pszErrorMsg = "Configuration is invalid"; break;
case VP8_ENC_ERROR_BAD_DIMENSION:
pszErrorMsg = "Picture has invalid width/height"; break;
case VP8_ENC_ERROR_PARTITION0_OVERFLOW:
pszErrorMsg = "Partition is bigger than 512k. Try using less "
"SEGMENTS, or increase PARTITION_LIMIT value";
break;
case VP8_ENC_ERROR_PARTITION_OVERFLOW:
pszErrorMsg = "Partition is bigger than 16M";
break;
case VP8_ENC_ERROR_BAD_WRITE:
pszErrorMsg = "Error while fludshing bytes"; break;
case VP8_ENC_ERROR_FILE_TOO_BIG:
pszErrorMsg = "File is bigger than 4G"; break;
case VP8_ENC_ERROR_USER_ABORT:
pszErrorMsg = "User interrupted";
break;
default:
TIFFErrorExt(tif->tif_clientdata, module,
"WebPEncode returned an unknown error code: %d",
sp->sPicture.error_code);
pszErrorMsg = "Unknown WebP error type.";
break;
}
TIFFErrorExt(tif->tif_clientdata, module,
"WebPEncode() failed : %s", pszErrorMsg);
#else
TIFFErrorExt(tif->tif_clientdata, module,
"Error in WebPEncode()");
#endif
return 0;
}
sp->sPicture.custom_ptr = NULL;
if (!TIFFFlushData1(tif))
{
TIFFErrorExt(tif->tif_clientdata, module,
"Error flushing TIFF WebP encoder.");
return 0;
}
return 1;
}
static void
TWebPCleanup(TIFF* tif)
{
WebPState* sp = LState(tif);
assert(sp != 0);
tif->tif_tagmethods.vgetfield = sp->vgetparent;
tif->tif_tagmethods.vsetfield = sp->vsetparent;
if (sp->state & LSTATE_INIT_ENCODE) {
WebPPictureFree(&sp->sPicture);
}
if (sp->psDecoder != NULL) {
WebPIDelete(sp->psDecoder);
WebPFreeDecBuffer(&sp->sDecBuffer);
sp->psDecoder = NULL;
sp->last_y = 0;
}
if (sp->pBuffer != NULL) {
_TIFFfree(sp->pBuffer);
sp->pBuffer = NULL;
}
if (tif->tif_data) {
_TIFFfree(tif->tif_data);
tif->tif_data = NULL;
}
_TIFFSetDefaultCompressionState(tif);
}
static int
TWebPVSetField(TIFF* tif, uint32 tag, va_list ap)
{
static const char module[] = "WebPVSetField";
WebPState* sp = LState(tif);
switch (tag) {
case TIFFTAG_WEBP_LEVEL:
sp->quality_level = (int) va_arg(ap, int);
if( sp->quality_level <= 0 ||
sp->quality_level > 100.0f ) {
TIFFWarningExt(tif->tif_clientdata, module,
"WEBP_LEVEL should be between 1 and 100");
}
return 1;
case TIFFTAG_WEBP_LOSSLESS:
#if WEBP_ENCODER_ABI_VERSION >= 0x0100
sp->lossless = va_arg(ap, int);
return 1;
#else
TIFFErrorExt(tif->tif_clientdata, module,
"Need to upgrade WEBP driver, this version doesn't support "
"lossless compression.");
return 0;
#endif
default:
return (*sp->vsetparent)(tif, tag, ap);
}
/*NOTREACHED*/
}
static int
TWebPVGetField(TIFF* tif, uint32 tag, va_list ap)
{
WebPState* sp = LState(tif);
switch (tag) {
case TIFFTAG_WEBP_LEVEL:
*va_arg(ap, int*) = sp->quality_level;
break;
case TIFFTAG_WEBP_LOSSLESS:
*va_arg(ap, int*) = sp->lossless;
break;
default:
return (*sp->vgetparent)(tif, tag, ap);
}
return 1;
}
static const TIFFField TWebPFields[] = {
{ TIFFTAG_WEBP_LEVEL, 0, 0, TIFF_ANY, 0, TIFF_SETGET_INT,
TIFF_SETGET_UNDEFINED,
FIELD_PSEUDO, TRUE, FALSE, "WEBP quality", NULL },
{ TIFFTAG_WEBP_LOSSLESS, 0, 0, TIFF_ANY, 0, TIFF_SETGET_INT,
TIFF_SETGET_UNDEFINED,
FIELD_PSEUDO, TRUE, FALSE, "WEBP lossless/lossy", NULL
},
};
int
TIFFInitWebP(TIFF* tif, int scheme)
{
static const char module[] = "TIFFInitWebP";
WebPState* sp;
assert( scheme == COMPRESSION_WEBP );
/*
* Merge codec-specific tag information.
*/
if ( !_TIFFMergeFields(tif, TWebPFields, TIFFArrayCount(TWebPFields)) ) {
TIFFErrorExt(tif->tif_clientdata, module,
"Merging WebP codec-specific tags failed");
return 0;
}
/*
* Allocate state block so tag methods have storage to record values.
*/
tif->tif_data = (uint8*) _TIFFmalloc(sizeof(WebPState));
if (tif->tif_data == NULL)
goto bad;
sp = LState(tif);
/*
* Override parent get/set field methods.
*/
sp->vgetparent = tif->tif_tagmethods.vgetfield;
tif->tif_tagmethods.vgetfield = TWebPVGetField; /* hook for codec tags */
sp->vsetparent = tif->tif_tagmethods.vsetfield;
tif->tif_tagmethods.vsetfield = TWebPVSetField; /* hook for codec tags */
/* Default values for codec-specific fields */
sp->quality_level = 75.0f; /* default comp. level */
sp->lossless = 0; /* default to false */
sp->state = 0;
sp->nSamples = 0;
sp->psDecoder = NULL;
sp->last_y = 0;
sp->buffer_offset = 0;
sp->pBuffer = NULL;
/*
* Install codec methods.
* Notes:
* encoderow is not supported
*/
tif->tif_fixuptags = TWebPFixupTags;
tif->tif_setupdecode = TWebPSetupDecode;
tif->tif_predecode = TWebPPreDecode;
tif->tif_decoderow = TWebPDecode;
tif->tif_decodestrip = TWebPDecode;
tif->tif_decodetile = TWebPDecode;
tif->tif_setupencode = TWebPSetupEncode;
tif->tif_preencode = TWebPPreEncode;
tif->tif_postencode = TWebPPostEncode;
tif->tif_encoderow = TWebPEncode;
tif->tif_encodestrip = TWebPEncode;
tif->tif_encodetile = TWebPEncode;
tif->tif_cleanup = TWebPCleanup;
return 1;
bad:
TIFFErrorExt(tif->tif_clientdata, module,
"No space for WebP state block");
return 0;
}
#endif /* WEBP_SUPPORT */

View File

@ -1,5 +1,3 @@
/* $Id: tif_win32.c,v 1.42 2017-01-11 19:02:49 erouault Exp $ */
/*
* Copyright (c) 1988-1997 Sam Leffler
* Copyright (c) 1991-1997 Silicon Graphics, Inc.
@ -407,60 +405,21 @@ _TIFFmemcmp(const void* p1, const void* p2, tmsize_t c)
static void
Win32WarningHandler(const char* module, const char* fmt, va_list ap)
{
#ifndef TIF_PLATFORM_CONSOLE
LPTSTR szTitle;
LPTSTR szTmp;
LPCTSTR szTitleText = "%s Warning";
LPCTSTR szDefaultModule = "LIBTIFF";
LPCTSTR szTmpModule = (module == NULL) ? szDefaultModule : module;
SIZE_T nBufSize = (strlen(szTmpModule) +
strlen(szTitleText) + strlen(fmt) + 256)*sizeof(char);
if ((szTitle = (LPTSTR)LocalAlloc(LMEM_FIXED, nBufSize)) == NULL)
return;
sprintf(szTitle, szTitleText, szTmpModule);
szTmp = szTitle + (strlen(szTitle)+2)*sizeof(char);
vsnprintf(szTmp, nBufSize-(strlen(szTitle)+2)*sizeof(char), fmt, ap);
MessageBoxA(GetFocus(), szTmp, szTitle, MB_OK | MB_ICONINFORMATION);
LocalFree(szTitle);
return;
#else
if (module != NULL)
fprintf(stderr, "%s: ", module);
fprintf(stderr, "Warning, ");
vfprintf(stderr, fmt, ap);
fprintf(stderr, ".\n");
#endif
}
TIFFErrorHandler _TIFFwarningHandler = Win32WarningHandler;
static void
Win32ErrorHandler(const char* module, const char* fmt, va_list ap)
{
#ifndef TIF_PLATFORM_CONSOLE
LPTSTR szTitle;
LPTSTR szTmp;
LPCTSTR szTitleText = "%s Error";
LPCTSTR szDefaultModule = "LIBTIFF";
LPCTSTR szTmpModule = (module == NULL) ? szDefaultModule : module;
SIZE_T nBufSize = (strlen(szTmpModule) +
strlen(szTitleText) + strlen(fmt) + 256)*sizeof(char);
if ((szTitle = (LPTSTR)LocalAlloc(LMEM_FIXED, nBufSize)) == NULL)
return;
sprintf(szTitle, szTitleText, szTmpModule);
szTmp = szTitle + (strlen(szTitle)+2)*sizeof(char);
vsnprintf(szTmp, nBufSize-(strlen(szTitle)+2)*sizeof(char), fmt, ap);
MessageBoxA(GetFocus(), szTmp, szTitle, MB_OK | MB_ICONEXCLAMATION);
LocalFree(szTitle);
return;
#else
if (module != NULL)
fprintf(stderr, "%s: ", module);
vfprintf(stderr, fmt, ap);
fprintf(stderr, ".\n");
#endif
}
TIFFErrorHandler _TIFFerrorHandler = Win32ErrorHandler;

View File

@ -1,5 +1,3 @@
/* $Id: tif_write.c,v 1.46 2016-12-03 21:57:44 erouault Exp $ */
/*
* Copyright (c) 1988-1997 Sam Leffler
* Copyright (c) 1991-1997 Silicon Graphics, Inc.
@ -540,9 +538,11 @@ TIFFSetupStrips(TIFF* tif)
if (td->td_planarconfig == PLANARCONFIG_SEPARATE)
td->td_stripsperimage /= td->td_samplesperpixel;
td->td_stripoffset = (uint64 *)
_TIFFmalloc(td->td_nstrips * sizeof (uint64));
_TIFFCheckMalloc(tif, td->td_nstrips, sizeof (uint64),
"for \"StripOffsets\" array");
td->td_stripbytecount = (uint64 *)
_TIFFmalloc(td->td_nstrips * sizeof (uint64));
_TIFFCheckMalloc(tif, td->td_nstrips, sizeof (uint64),
"for \"StripByteCounts\" array");
if (td->td_stripoffset == NULL || td->td_stripbytecount == NULL)
return (0);
/*

View File

@ -1,5 +1,3 @@
/* $Id: tif_zip.c,v 1.37 2017-05-10 15:21:16 erouault Exp $ */
/*
* Copyright (c) 1995-1997 Sam Leffler
* Copyright (c) 1995-1997 Silicon Graphics, Inc.

440
3rdparty/libtiff/tif_zstd.c vendored Normal file
View File

@ -0,0 +1,440 @@
/*
* Copyright (c) 2017, Planet Labs
* Author: <even.rouault at spatialys.com>
*
* Permission to use, copy, modify, distribute, and sell this software and
* its documentation for any purpose is hereby granted without fee, provided
* that (i) the above copyright notices and this permission notice appear in
* all copies of the software and related documentation, and (ii) the names of
* Sam Leffler and Silicon Graphics may not be used in any advertising or
* publicity relating to the software without the specific, prior written
* permission of Sam Leffler and Silicon Graphics.
*
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
*
* IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
* ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
* OF THIS SOFTWARE.
*/
#include "tiffiop.h"
#ifdef ZSTD_SUPPORT
/*
* TIFF Library.
*
* ZSTD Compression Support
*
*/
#include "tif_predict.h"
#include "zstd.h"
#include <stdio.h>
/*
* State block for each open TIFF file using ZSTD compression/decompression.
*/
typedef struct {
TIFFPredictorState predict;
ZSTD_DStream* dstream;
ZSTD_CStream* cstream;
int compression_level; /* compression level */
ZSTD_outBuffer out_buffer;
int state; /* state flags */
#define LSTATE_INIT_DECODE 0x01
#define LSTATE_INIT_ENCODE 0x02
TIFFVGetMethod vgetparent; /* super-class method */
TIFFVSetMethod vsetparent; /* super-class method */
} ZSTDState;
#define LState(tif) ((ZSTDState*) (tif)->tif_data)
#define DecoderState(tif) LState(tif)
#define EncoderState(tif) LState(tif)
static int ZSTDEncode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s);
static int ZSTDDecode(TIFF* tif, uint8* op, tmsize_t occ, uint16 s);
static int
ZSTDFixupTags(TIFF* tif)
{
(void) tif;
return 1;
}
static int
ZSTDSetupDecode(TIFF* tif)
{
ZSTDState* sp = DecoderState(tif);
assert(sp != NULL);
/* if we were last encoding, terminate this mode */
if (sp->state & LSTATE_INIT_ENCODE) {
ZSTD_freeCStream(sp->cstream);
sp->cstream = NULL;
sp->state = 0;
}
sp->state |= LSTATE_INIT_DECODE;
return 1;
}
/*
* Setup state for decoding a strip.
*/
static int
ZSTDPreDecode(TIFF* tif, uint16 s)
{
static const char module[] = "ZSTDPreDecode";
ZSTDState* sp = DecoderState(tif);
size_t zstd_ret;
(void) s;
assert(sp != NULL);
if( (sp->state & LSTATE_INIT_DECODE) == 0 )
tif->tif_setupdecode(tif);
if( sp->dstream )
{
ZSTD_freeDStream(sp->dstream);
sp->dstream = NULL;
}
sp->dstream = ZSTD_createDStream();
if( sp->dstream == NULL ) {
TIFFErrorExt(tif->tif_clientdata, module,
"Cannot allocate decompression stream");
return 0;
}
zstd_ret = ZSTD_initDStream(sp->dstream);
if( ZSTD_isError(zstd_ret) ) {
TIFFErrorExt(tif->tif_clientdata, module,
"Error in ZSTD_initDStream(): %s",
ZSTD_getErrorName(zstd_ret));
return 0;
}
return 1;
}
static int
ZSTDDecode(TIFF* tif, uint8* op, tmsize_t occ, uint16 s)
{
static const char module[] = "ZSTDDecode";
ZSTDState* sp = DecoderState(tif);
ZSTD_inBuffer in_buffer;
ZSTD_outBuffer out_buffer;
size_t zstd_ret;
(void) s;
assert(sp != NULL);
assert(sp->state == LSTATE_INIT_DECODE);
in_buffer.src = tif->tif_rawcp;
in_buffer.size = (size_t) tif->tif_rawcc;
in_buffer.pos = 0;
out_buffer.dst = op;
out_buffer.size = (size_t) occ;
out_buffer.pos = 0;
do {
zstd_ret = ZSTD_decompressStream(sp->dstream, &out_buffer,
&in_buffer);
if( ZSTD_isError(zstd_ret) ) {
TIFFErrorExt(tif->tif_clientdata, module,
"Error in ZSTD_decompressStream(): %s",
ZSTD_getErrorName(zstd_ret));
return 0;
}
} while( zstd_ret != 0 &&
in_buffer.pos < in_buffer.size &&
out_buffer.pos < out_buffer.size );
if (out_buffer.pos < (size_t)occ) {
TIFFErrorExt(tif->tif_clientdata, module,
"Not enough data at scanline %lu (short %lu bytes)",
(unsigned long) tif->tif_row,
(unsigned long) (size_t)occ - out_buffer.pos);
return 0;
}
tif->tif_rawcp += in_buffer.pos;
tif->tif_rawcc -= in_buffer.pos;
return 1;
}
static int
ZSTDSetupEncode(TIFF* tif)
{
ZSTDState* sp = EncoderState(tif);
assert(sp != NULL);
if (sp->state & LSTATE_INIT_DECODE) {
ZSTD_freeDStream(sp->dstream);
sp->dstream = NULL;
sp->state = 0;
}
sp->state |= LSTATE_INIT_ENCODE;
return 1;
}
/*
* Reset encoding state at the start of a strip.
*/
static int
ZSTDPreEncode(TIFF* tif, uint16 s)
{
static const char module[] = "ZSTDPreEncode";
ZSTDState *sp = EncoderState(tif);
size_t zstd_ret;
(void) s;
assert(sp != NULL);
if( sp->state != LSTATE_INIT_ENCODE )
tif->tif_setupencode(tif);
if (sp->cstream) {
ZSTD_freeCStream(sp->cstream);
sp->cstream = NULL;
}
sp->cstream = ZSTD_createCStream();
if( sp->cstream == NULL ) {
TIFFErrorExt(tif->tif_clientdata, module,
"Cannot allocate compression stream");
return 0;
}
zstd_ret = ZSTD_initCStream(sp->cstream, sp->compression_level);
if( ZSTD_isError(zstd_ret) ) {
TIFFErrorExt(tif->tif_clientdata, module,
"Error in ZSTD_initCStream(): %s",
ZSTD_getErrorName(zstd_ret));
return 0;
}
sp->out_buffer.dst = tif->tif_rawdata;
sp->out_buffer.size = (size_t)tif->tif_rawdatasize;
sp->out_buffer.pos = 0;
return 1;
}
/*
* Encode a chunk of pixels.
*/
static int
ZSTDEncode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s)
{
static const char module[] = "ZSTDEncode";
ZSTDState *sp = EncoderState(tif);
ZSTD_inBuffer in_buffer;
size_t zstd_ret;
assert(sp != NULL);
assert(sp->state == LSTATE_INIT_ENCODE);
(void) s;
in_buffer.src = bp;
in_buffer.size = (size_t)cc;
in_buffer.pos = 0;
do {
zstd_ret = ZSTD_compressStream(sp->cstream, &sp->out_buffer,
&in_buffer);
if( ZSTD_isError(zstd_ret) ) {
TIFFErrorExt(tif->tif_clientdata, module,
"Error in ZSTD_compressStream(): %s",
ZSTD_getErrorName(zstd_ret));
return 0;
}
if( sp->out_buffer.pos == sp->out_buffer.size ) {
tif->tif_rawcc = tif->tif_rawdatasize;
TIFFFlushData1(tif);
sp->out_buffer.dst = tif->tif_rawcp;
sp->out_buffer.pos = 0;
}
} while( in_buffer.pos < in_buffer.size );
return 1;
}
/*
* Finish off an encoded strip by flushing it.
*/
static int
ZSTDPostEncode(TIFF* tif)
{
static const char module[] = "ZSTDPostEncode";
ZSTDState *sp = EncoderState(tif);
size_t zstd_ret;
do {
zstd_ret = ZSTD_endStream(sp->cstream, &sp->out_buffer);
if( ZSTD_isError(zstd_ret) ) {
TIFFErrorExt(tif->tif_clientdata, module,
"Error in ZSTD_endStream(): %s",
ZSTD_getErrorName(zstd_ret));
return 0;
}
if( sp->out_buffer.pos > 0 ) {
tif->tif_rawcc = sp->out_buffer.pos;
TIFFFlushData1(tif);
sp->out_buffer.dst = tif->tif_rawcp;
sp->out_buffer.pos = 0;
}
} while (zstd_ret != 0);
return 1;
}
static void
ZSTDCleanup(TIFF* tif)
{
ZSTDState* sp = LState(tif);
assert(sp != 0);
(void)TIFFPredictorCleanup(tif);
tif->tif_tagmethods.vgetfield = sp->vgetparent;
tif->tif_tagmethods.vsetfield = sp->vsetparent;
if (sp->dstream) {
ZSTD_freeDStream(sp->dstream);
sp->dstream = NULL;
}
if (sp->cstream) {
ZSTD_freeCStream(sp->cstream);
sp->cstream = NULL;
}
_TIFFfree(sp);
tif->tif_data = NULL;
_TIFFSetDefaultCompressionState(tif);
}
static int
ZSTDVSetField(TIFF* tif, uint32 tag, va_list ap)
{
static const char module[] = "ZSTDVSetField";
ZSTDState* sp = LState(tif);
switch (tag) {
case TIFFTAG_ZSTD_LEVEL:
sp->compression_level = (int) va_arg(ap, int);
if( sp->compression_level <= 0 ||
sp->compression_level > ZSTD_maxCLevel() )
{
TIFFWarningExt(tif->tif_clientdata, module,
"ZSTD_LEVEL should be between 1 and %d",
ZSTD_maxCLevel());
}
return 1;
default:
return (*sp->vsetparent)(tif, tag, ap);
}
/*NOTREACHED*/
}
static int
ZSTDVGetField(TIFF* tif, uint32 tag, va_list ap)
{
ZSTDState* sp = LState(tif);
switch (tag) {
case TIFFTAG_ZSTD_LEVEL:
*va_arg(ap, int*) = sp->compression_level;
break;
default:
return (*sp->vgetparent)(tif, tag, ap);
}
return 1;
}
static const TIFFField ZSTDFields[] = {
{ TIFFTAG_ZSTD_LEVEL, 0, 0, TIFF_ANY, 0, TIFF_SETGET_INT,
TIFF_SETGET_UNDEFINED,
FIELD_PSEUDO, TRUE, FALSE, "ZSTD compression_level", NULL },
};
int
TIFFInitZSTD(TIFF* tif, int scheme)
{
static const char module[] = "TIFFInitZSTD";
ZSTDState* sp;
assert( scheme == COMPRESSION_ZSTD );
/*
* Merge codec-specific tag information.
*/
if (!_TIFFMergeFields(tif, ZSTDFields, TIFFArrayCount(ZSTDFields))) {
TIFFErrorExt(tif->tif_clientdata, module,
"Merging ZSTD codec-specific tags failed");
return 0;
}
/*
* Allocate state block so tag methods have storage to record values.
*/
tif->tif_data = (uint8*) _TIFFmalloc(sizeof(ZSTDState));
if (tif->tif_data == NULL)
goto bad;
sp = LState(tif);
/*
* Override parent get/set field methods.
*/
sp->vgetparent = tif->tif_tagmethods.vgetfield;
tif->tif_tagmethods.vgetfield = ZSTDVGetField; /* hook for codec tags */
sp->vsetparent = tif->tif_tagmethods.vsetfield;
tif->tif_tagmethods.vsetfield = ZSTDVSetField; /* hook for codec tags */
/* Default values for codec-specific fields */
sp->compression_level = 9; /* default comp. level */
sp->state = 0;
sp->dstream = 0;
sp->cstream = 0;
sp->out_buffer.dst = NULL;
sp->out_buffer.size = 0;
sp->out_buffer.pos = 0;
/*
* Install codec methods.
*/
tif->tif_fixuptags = ZSTDFixupTags;
tif->tif_setupdecode = ZSTDSetupDecode;
tif->tif_predecode = ZSTDPreDecode;
tif->tif_decoderow = ZSTDDecode;
tif->tif_decodestrip = ZSTDDecode;
tif->tif_decodetile = ZSTDDecode;
tif->tif_setupencode = ZSTDSetupEncode;
tif->tif_preencode = ZSTDPreEncode;
tif->tif_postencode = ZSTDPostEncode;
tif->tif_encoderow = ZSTDEncode;
tif->tif_encodestrip = ZSTDEncode;
tif->tif_encodetile = ZSTDEncode;
tif->tif_cleanup = ZSTDCleanup;
/*
* Setup predictor setup.
*/
(void) TIFFPredictorInit(tif);
return 1;
bad:
TIFFErrorExt(tif->tif_clientdata, module,
"No space for ZSTD state block");
return 0;
}
#endif /* ZSTD_SUPPORT */
/* vim: set ts=8 sts=8 sw=8 noet: */

View File

@ -1,5 +1,3 @@
/* $Id: tiff.h,v 1.70 2016-01-23 21:20:34 erouault Exp $ */
/*
* Copyright (c) 1988-1997 Sam Leffler
* Copyright (c) 1991-1997 Silicon Graphics, Inc.
@ -189,7 +187,11 @@ typedef enum {
#define COMPRESSION_SGILOG 34676 /* SGI Log Luminance RLE */
#define COMPRESSION_SGILOG24 34677 /* SGI Log 24-bit packed */
#define COMPRESSION_JP2000 34712 /* Leadtools JPEG2000 */
#define COMPRESSION_LERC 34887 /* ESRI Lerc codec: https://github.com/Esri/lerc */
/* compression codes 34887-34889 are reserved for ESRI */
#define COMPRESSION_LZMA 34925 /* LZMA2 */
#define COMPRESSION_ZSTD 50000 /* ZSTD: WARNING not registered in Adobe-maintained registry */
#define COMPRESSION_WEBP 50001 /* WEBP: WARNING not registered in Adobe-maintained registry */
#define TIFFTAG_PHOTOMETRIC 262 /* photometric interpretation */
#define PHOTOMETRIC_MINISWHITE 0 /* min value is white */
#define PHOTOMETRIC_MINISBLACK 1 /* min value is black */
@ -450,6 +452,8 @@ typedef enum {
/* tag 34929 is a private tag registered to FedEx */
#define TIFFTAG_FEDEX_EDR 34929 /* unknown use */
#define TIFFTAG_INTEROPERABILITYIFD 40965 /* Pointer to Interoperability private directory */
/* tags 50674 to 50677 are reserved for ESRI */
#define TIFFTAG_LERC_PARAMETERS 50674 /* Stores LERC version and additional compression method */
/* Adobe Digital Negative (DNG) format tags */
#define TIFFTAG_DNGVERSION 50706 /* &DNG version number */
#define TIFFTAG_DNGBACKWARDVERSION 50707 /* &DNG compatibility version */
@ -603,6 +607,16 @@ typedef enum {
#define TIFFTAG_PERSAMPLE 65563 /* interface for per sample tags */
#define PERSAMPLE_MERGED 0 /* present as a single value */
#define PERSAMPLE_MULTI 1 /* present as multiple values */
#define TIFFTAG_ZSTD_LEVEL 65564 /* ZSTD compression level */
#define TIFFTAG_LERC_VERSION 65565 /* LERC version */
#define LERC_VERSION_2_4 4
#define TIFFTAG_LERC_ADD_COMPRESSION 65566 /* LERC additional compression */
#define LERC_ADD_COMPRESSION_NONE 0
#define LERC_ADD_COMPRESSION_DEFLATE 1
#define LERC_ADD_COMPRESSION_ZSTD 2
#define TIFFTAG_LERC_MAXZERROR 65567 /* LERC maximum error */
#define TIFFTAG_WEBP_LEVEL 65568 /* WebP compression level: WARNING not registered in Adobe-maintained registry */
#define TIFFTAG_WEBP_LOSSLESS 65569 /* WebP lossless/lossy : WARNING not registered in Adobe-maintained registry */
/*
* EXIF tags

View File

@ -40,15 +40,6 @@
/* Pointer difference type */
#define TIFF_PTRDIFF_T @TIFF_PTRDIFF_T@
/* Define to 1 if the system has the type `int16'. */
#cmakedefine HAVE_INT16 1
/* Define to 1 if the system has the type `int32'. */
#cmakedefine HAVE_INT32 1
/* Define to 1 if the system has the type `int8'. */
#cmakedefine HAVE_INT8 1
/* Compatibility stuff. */
/* Define as 0 or 1 according to the floating point format suported by the

View File

@ -1,5 +1,3 @@
/* $Id: tiffio.h,v 1.94 2017-01-11 19:02:49 erouault Exp $ */
/*
* Copyright (c) 1988-1997 Sam Leffler
* Copyright (c) 1991-1997 Silicon Graphics, Inc.
@ -52,7 +50,7 @@ typedef struct tiff TIFF;
* promoted type (i.e. one of int, unsigned int, pointer,
* or double) and because we defined pseudo-tags that are
* outside the range of legal Aldus-assigned tags.
* NB: tsize_t is int32 and not uint32 because some functions
* NB: tsize_t is signed and not unsigned because some functions
* return -1.
* NB: toff_t is not off_t for many reasons; TIFFs max out at
* 32-bit file offsets, and BigTIFF maxes out at 64-bit

View File

@ -1,5 +1,3 @@
/* $Id: tiffio.hxx,v 1.3 2010-06-08 18:55:15 bfriesen Exp $ */
/*
* Copyright (c) 1988-1997 Sam Leffler
* Copyright (c) 1991-1997 Silicon Graphics, Inc.
@ -33,6 +31,7 @@
#include <iostream>
#include "tiff.h"
#include "tiffio.h"
extern TIFF* TIFFStreamOpen(const char*, std::ostream *);
extern TIFF* TIFFStreamOpen(const char*, std::istream *);

View File

@ -1,5 +1,3 @@
/* $Id: tiffiop.h,v 1.95 2017-09-07 14:02:52 erouault Exp $ */
/*
* Copyright (c) 1988-1997 Sam Leffler
* Copyright (c) 1991-1997 Silicon Graphics, Inc.
@ -72,6 +70,7 @@ extern int snprintf(char* str, size_t size, const char* format, ...);
#endif
#define streq(a,b) (strcmp(a,b) == 0)
#define strneq(a,b,n) (strncmp(a,b,n) == 0)
#ifndef TRUE
#define TRUE 1
@ -314,11 +313,15 @@ typedef size_t TIFFIOSize_t;
#define _TIFF_off_t off_t
#endif
#if __clang_major__ >= 4 || (__clang_major__ == 3 && __clang_minor__ >= 8)
#if defined(__has_attribute) && defined(__clang__)
#if __has_attribute(no_sanitize)
#define TIFF_NOSANITIZE_UNSIGNED_INT_OVERFLOW __attribute__((no_sanitize("unsigned-integer-overflow")))
#else
#define TIFF_NOSANITIZE_UNSIGNED_INT_OVERFLOW
#endif
#else
#define TIFF_NOSANITIZE_UNSIGNED_INT_OVERFLOW
#endif
#if defined(__cplusplus)
@ -424,6 +427,12 @@ extern int TIFFInitSGILog(TIFF*, int);
#ifdef LZMA_SUPPORT
extern int TIFFInitLZMA(TIFF*, int);
#endif
#ifdef ZSTD_SUPPORT
extern int TIFFInitZSTD(TIFF*, int);
#endif
#ifdef WEBP_SUPPORT
extern int TIFFInitWebP(TIFF*, int);
#endif
#ifdef VMS
extern const TIFFCodec _TIFFBuiltinCODECS[];
#else

View File

@ -1,4 +1,4 @@
#define TIFFLIB_VERSION_STR "LIBTIFF, Version 4.0.9\nCopyright (c) 1988-1996 Sam Leffler\nCopyright (c) 1991-1996 Silicon Graphics, Inc."
#define TIFFLIB_VERSION_STR "LIBTIFF, Version 4.0.10\nCopyright (c) 1988-1996 Sam Leffler\nCopyright (c) 1991-1996 Silicon Graphics, Inc."
/*
* This define can be used in code that requires
* compilation-related definitions specific to a
@ -6,4 +6,4 @@
* version checking should be done based on the
* string returned by TIFFGetVersion.
*/
#define TIFFLIB_VERSION 20171118
#define TIFFLIB_VERSION 20181110

View File

@ -251,8 +251,8 @@ OCV_OPTION(WITH_NVCUVID "Include NVidia Video Decoding library support" WITH_CUD
OCV_OPTION(WITH_EIGEN "Include Eigen2/Eigen3 support" (NOT CV_DISABLE_OPTIMIZATION)
VISIBLE_IF NOT WINRT AND NOT CMAKE_CROSSCOMPILING
VERIFY HAVE_EIGEN)
OCV_OPTION(WITH_FFMPEG "Include FFMPEG support" ON
VISIBLE_IF NOT ANDROID AND NOT IOS AND NOT WINRT
OCV_OPTION(WITH_FFMPEG "Include FFMPEG support" (NOT ANDROID)
VISIBLE_IF NOT IOS AND NOT WINRT
VERIFY HAVE_FFMPEG)
OCV_OPTION(WITH_GSTREAMER "Include Gstreamer support" ON
VISIBLE_IF NOT ANDROID AND NOT IOS AND NOT WINRT

View File

@ -5,6 +5,9 @@ ocv_add_dispatched_file(stat SSE4_2 AVX2)
ocv_add_dispatched_file(arithm SSE2 SSE4_1 AVX2 VSX3)
ocv_add_dispatched_file(convert SSE2 AVX2)
ocv_add_dispatched_file(convert_scale SSE2 AVX2)
ocv_add_dispatched_file(count_non_zero SSE2 AVX2)
ocv_add_dispatched_file(matmul SSE2 AVX2)
ocv_add_dispatched_file(sum SSE2 AVX2)
# dispatching for accuracy tests
ocv_add_dispatched_file_force_all(test_intrin128 TEST SSE2 SSE3 SSSE3 SSE4_1 SSE4_2 AVX FP16 AVX2)

View File

@ -15,6 +15,7 @@
#define CV_CPU_OPTIMIZATION_NAMESPACE cpu_baseline
#define CV_CPU_OPTIMIZATION_NAMESPACE_BEGIN namespace cpu_baseline {
#define CV_CPU_OPTIMIZATION_NAMESPACE_END }
#define CV_CPU_BASELINE_MODE 1
#endif

View File

@ -7,190 +7,18 @@
#include "opencl_kernels_core.hpp"
#include "stat.hpp"
#include "count_non_zero.simd.hpp"
#include "count_non_zero.simd_declarations.hpp" // defines CV_CPU_DISPATCH_MODES_ALL=AVX2,...,BASELINE based on CMakeLists.txt content
namespace cv {
template<typename T>
static int countNonZero_(const T* src, int len )
{
int i=0, nz = 0;
#if CV_ENABLE_UNROLLED
for(; i <= len - 4; i += 4 )
nz += (src[i] != 0) + (src[i+1] != 0) + (src[i+2] != 0) + (src[i+3] != 0);
#endif
for( ; i < len; i++ )
nz += src[i] != 0;
return nz;
}
static int countNonZero8u( const uchar* src, int len )
{
int i=0, nz = 0;
#if CV_SIMD
int len0 = len & -v_uint8::nlanes;
v_uint8 v_zero = vx_setzero_u8();
v_uint8 v_one = vx_setall_u8(1);
v_uint32 v_sum32 = vx_setzero_u32();
while (i < len0)
{
v_uint16 v_sum16 = vx_setzero_u16();
int j = i;
while (j < std::min(len0, i + 65280 * v_uint16::nlanes))
{
v_uint8 v_sum8 = vx_setzero_u8();
int k = j;
for (; k < std::min(len0, j + 255 * v_uint8::nlanes); k += v_uint8::nlanes)
v_sum8 += v_one & (vx_load(src + k) == v_zero);
v_uint16 part1, part2;
v_expand(v_sum8, part1, part2);
v_sum16 += part1 + part2;
j = k;
}
v_uint32 part1, part2;
v_expand(v_sum16, part1, part2);
v_sum32 += part1 + part2;
i = j;
}
nz = i - v_reduce_sum(v_sum32);
v_cleanup();
#endif
for( ; i < len; i++ )
nz += src[i] != 0;
return nz;
}
static int countNonZero16u( const ushort* src, int len )
{
int i = 0, nz = 0;
#if CV_SIMD
int len0 = len & -v_int8::nlanes;
v_uint16 v_zero = vx_setzero_u16();
v_int8 v_one = vx_setall_s8(1);
v_int32 v_sum32 = vx_setzero_s32();
while (i < len0)
{
v_int16 v_sum16 = vx_setzero_s16();
int j = i;
while (j < std::min(len0, i + 32766 * v_int16::nlanes))
{
v_int8 v_sum8 = vx_setzero_s8();
int k = j;
for (; k < std::min(len0, j + 127 * v_int8::nlanes); k += v_int8::nlanes)
v_sum8 += v_one & v_pack(v_reinterpret_as_s16(vx_load(src + k) == v_zero), v_reinterpret_as_s16(vx_load(src + k + v_uint16::nlanes) == v_zero));
v_int16 part1, part2;
v_expand(v_sum8, part1, part2);
v_sum16 += part1 + part2;
j = k;
}
v_int32 part1, part2;
v_expand(v_sum16, part1, part2);
v_sum32 += part1 + part2;
i = j;
}
nz = i - v_reduce_sum(v_sum32);
v_cleanup();
#endif
return nz + countNonZero_(src + i, len - i);
}
static int countNonZero32s( const int* src, int len )
{
int i = 0, nz = 0;
#if CV_SIMD
int len0 = len & -v_int8::nlanes;
v_int32 v_zero = vx_setzero_s32();
v_int8 v_one = vx_setall_s8(1);
v_int32 v_sum32 = vx_setzero_s32();
while (i < len0)
{
v_int16 v_sum16 = vx_setzero_s16();
int j = i;
while (j < std::min(len0, i + 32766 * v_int16::nlanes))
{
v_int8 v_sum8 = vx_setzero_s8();
int k = j;
for (; k < std::min(len0, j + 127 * v_int8::nlanes); k += v_int8::nlanes)
v_sum8 += v_one & v_pack(
v_pack(vx_load(src + k ) == v_zero, vx_load(src + k + v_int32::nlanes) == v_zero),
v_pack(vx_load(src + k + 2*v_int32::nlanes) == v_zero, vx_load(src + k + 3*v_int32::nlanes) == v_zero)
);
v_int16 part1, part2;
v_expand(v_sum8, part1, part2);
v_sum16 += part1 + part2;
j = k;
}
v_int32 part1, part2;
v_expand(v_sum16, part1, part2);
v_sum32 += part1 + part2;
i = j;
}
nz = i - v_reduce_sum(v_sum32);
v_cleanup();
#endif
return nz + countNonZero_(src + i, len - i);
}
static int countNonZero32f( const float* src, int len )
{
int i = 0, nz = 0;
#if CV_SIMD
int len0 = len & -v_int8::nlanes;
v_float32 v_zero = vx_setzero_f32();
v_int8 v_one = vx_setall_s8(1);
v_int32 v_sum32 = vx_setzero_s32();
while (i < len0)
{
v_int16 v_sum16 = vx_setzero_s16();
int j = i;
while (j < std::min(len0, i + 32766 * v_int16::nlanes))
{
v_int8 v_sum8 = vx_setzero_s8();
int k = j;
for (; k < std::min(len0, j + 127 * v_int8::nlanes); k += v_int8::nlanes)
v_sum8 += v_one & v_pack(
v_pack(v_reinterpret_as_s32(vx_load(src + k ) == v_zero), v_reinterpret_as_s32(vx_load(src + k + v_float32::nlanes) == v_zero)),
v_pack(v_reinterpret_as_s32(vx_load(src + k + 2*v_float32::nlanes) == v_zero), v_reinterpret_as_s32(vx_load(src + k + 3*v_float32::nlanes) == v_zero))
);
v_int16 part1, part2;
v_expand(v_sum8, part1, part2);
v_sum16 += part1 + part2;
j = k;
}
v_int32 part1, part2;
v_expand(v_sum16, part1, part2);
v_sum32 += part1 + part2;
i = j;
}
nz = i - v_reduce_sum(v_sum32);
v_cleanup();
#endif
return nz + countNonZero_(src + i, len - i);
}
static int countNonZero64f( const double* src, int len )
{
return countNonZero_(src, len);
}
typedef int (*CountNonZeroFunc)(const uchar*, int);
static CountNonZeroFunc getCountNonZeroTab(int depth)
{
static CountNonZeroFunc countNonZeroTab[] =
{
(CountNonZeroFunc)GET_OPTIMIZED(countNonZero8u), (CountNonZeroFunc)GET_OPTIMIZED(countNonZero8u),
(CountNonZeroFunc)GET_OPTIMIZED(countNonZero16u), (CountNonZeroFunc)GET_OPTIMIZED(countNonZero16u),
(CountNonZeroFunc)GET_OPTIMIZED(countNonZero32s), (CountNonZeroFunc)GET_OPTIMIZED(countNonZero32f),
(CountNonZeroFunc)GET_OPTIMIZED(countNonZero64f), 0
};
return countNonZeroTab[depth];
CV_INSTRUMENT_REGION();
CV_CPU_DISPATCH(getCountNonZeroTab, (depth),
CV_CPU_DISPATCH_MODES_ALL);
}
#ifdef HAVE_OPENCL
static bool ocl_countNonZero( InputArray _src, int & res )
{
@ -288,9 +116,7 @@ static bool ipp_countNonZero( Mat &src, int &res )
}
#endif
} // cv::
int cv::countNonZero( InputArray _src )
int countNonZero(InputArray _src)
{
CV_INSTRUMENT_REGION();
@ -324,10 +150,8 @@ int cv::countNonZero( InputArray _src )
return nz;
}
void cv::findNonZero( InputArray _src, OutputArray _idx )
void findNonZero(InputArray _src, OutputArray _idx)
{
CV_INSTRUMENT_REGION();
Mat src = _src.getMat();
CV_Assert( src.channels() == 1 && src.dims == 2 );
@ -386,3 +210,5 @@ void cv::findNonZero( InputArray _src, OutputArray _idx )
if( !idxvec.empty() )
Mat(idxvec).copyTo(_idx);
}
} // namespace

View File

@ -0,0 +1,201 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html
#include "precomp.hpp"
namespace cv {
typedef int (*CountNonZeroFunc)(const uchar*, int);
CV_CPU_OPTIMIZATION_NAMESPACE_BEGIN
CountNonZeroFunc getCountNonZeroTab(int depth);
#ifndef CV_CPU_OPTIMIZATION_DECLARATIONS_ONLY
template<typename T>
static int countNonZero_(const T* src, int len )
{
int i=0, nz = 0;
#if CV_ENABLE_UNROLLED
for(; i <= len - 4; i += 4 )
nz += (src[i] != 0) + (src[i+1] != 0) + (src[i+2] != 0) + (src[i+3] != 0);
#endif
for( ; i < len; i++ )
nz += src[i] != 0;
return nz;
}
static int countNonZero8u( const uchar* src, int len )
{
int i=0, nz = 0;
#if CV_SIMD
int len0 = len & -v_uint8::nlanes;
v_uint8 v_zero = vx_setzero_u8();
v_uint8 v_one = vx_setall_u8(1);
v_uint32 v_sum32 = vx_setzero_u32();
while (i < len0)
{
v_uint16 v_sum16 = vx_setzero_u16();
int j = i;
while (j < std::min(len0, i + 65280 * v_uint16::nlanes))
{
v_uint8 v_sum8 = vx_setzero_u8();
int k = j;
for (; k < std::min(len0, j + 255 * v_uint8::nlanes); k += v_uint8::nlanes)
v_sum8 += v_one & (vx_load(src + k) == v_zero);
v_uint16 part1, part2;
v_expand(v_sum8, part1, part2);
v_sum16 += part1 + part2;
j = k;
}
v_uint32 part1, part2;
v_expand(v_sum16, part1, part2);
v_sum32 += part1 + part2;
i = j;
}
nz = i - v_reduce_sum(v_sum32);
v_cleanup();
#endif
for( ; i < len; i++ )
nz += src[i] != 0;
return nz;
}
static int countNonZero16u( const ushort* src, int len )
{
int i = 0, nz = 0;
#if CV_SIMD
int len0 = len & -v_int8::nlanes;
v_uint16 v_zero = vx_setzero_u16();
v_int8 v_one = vx_setall_s8(1);
v_int32 v_sum32 = vx_setzero_s32();
while (i < len0)
{
v_int16 v_sum16 = vx_setzero_s16();
int j = i;
while (j < std::min(len0, i + 32766 * v_int16::nlanes))
{
v_int8 v_sum8 = vx_setzero_s8();
int k = j;
for (; k < std::min(len0, j + 127 * v_int8::nlanes); k += v_int8::nlanes)
v_sum8 += v_one & v_pack(v_reinterpret_as_s16(vx_load(src + k) == v_zero), v_reinterpret_as_s16(vx_load(src + k + v_uint16::nlanes) == v_zero));
v_int16 part1, part2;
v_expand(v_sum8, part1, part2);
v_sum16 += part1 + part2;
j = k;
}
v_int32 part1, part2;
v_expand(v_sum16, part1, part2);
v_sum32 += part1 + part2;
i = j;
}
nz = i - v_reduce_sum(v_sum32);
v_cleanup();
#endif
return nz + countNonZero_(src + i, len - i);
}
static int countNonZero32s( const int* src, int len )
{
int i = 0, nz = 0;
#if CV_SIMD
int len0 = len & -v_int8::nlanes;
v_int32 v_zero = vx_setzero_s32();
v_int8 v_one = vx_setall_s8(1);
v_int32 v_sum32 = vx_setzero_s32();
while (i < len0)
{
v_int16 v_sum16 = vx_setzero_s16();
int j = i;
while (j < std::min(len0, i + 32766 * v_int16::nlanes))
{
v_int8 v_sum8 = vx_setzero_s8();
int k = j;
for (; k < std::min(len0, j + 127 * v_int8::nlanes); k += v_int8::nlanes)
v_sum8 += v_one & v_pack(
v_pack(vx_load(src + k ) == v_zero, vx_load(src + k + v_int32::nlanes) == v_zero),
v_pack(vx_load(src + k + 2*v_int32::nlanes) == v_zero, vx_load(src + k + 3*v_int32::nlanes) == v_zero)
);
v_int16 part1, part2;
v_expand(v_sum8, part1, part2);
v_sum16 += part1 + part2;
j = k;
}
v_int32 part1, part2;
v_expand(v_sum16, part1, part2);
v_sum32 += part1 + part2;
i = j;
}
nz = i - v_reduce_sum(v_sum32);
v_cleanup();
#endif
return nz + countNonZero_(src + i, len - i);
}
static int countNonZero32f( const float* src, int len )
{
int i = 0, nz = 0;
#if CV_SIMD
int len0 = len & -v_int8::nlanes;
v_float32 v_zero = vx_setzero_f32();
v_int8 v_one = vx_setall_s8(1);
v_int32 v_sum32 = vx_setzero_s32();
while (i < len0)
{
v_int16 v_sum16 = vx_setzero_s16();
int j = i;
while (j < std::min(len0, i + 32766 * v_int16::nlanes))
{
v_int8 v_sum8 = vx_setzero_s8();
int k = j;
for (; k < std::min(len0, j + 127 * v_int8::nlanes); k += v_int8::nlanes)
v_sum8 += v_one & v_pack(
v_pack(v_reinterpret_as_s32(vx_load(src + k ) == v_zero), v_reinterpret_as_s32(vx_load(src + k + v_float32::nlanes) == v_zero)),
v_pack(v_reinterpret_as_s32(vx_load(src + k + 2*v_float32::nlanes) == v_zero), v_reinterpret_as_s32(vx_load(src + k + 3*v_float32::nlanes) == v_zero))
);
v_int16 part1, part2;
v_expand(v_sum8, part1, part2);
v_sum16 += part1 + part2;
j = k;
}
v_int32 part1, part2;
v_expand(v_sum16, part1, part2);
v_sum32 += part1 + part2;
i = j;
}
nz = i - v_reduce_sum(v_sum32);
v_cleanup();
#endif
return nz + countNonZero_(src + i, len - i);
}
static int countNonZero64f( const double* src, int len )
{
return countNonZero_(src, len);
}
CountNonZeroFunc getCountNonZeroTab(int depth)
{
static CountNonZeroFunc countNonZeroTab[] =
{
(CountNonZeroFunc)GET_OPTIMIZED(countNonZero8u), (CountNonZeroFunc)GET_OPTIMIZED(countNonZero8u),
(CountNonZeroFunc)GET_OPTIMIZED(countNonZero16u), (CountNonZeroFunc)GET_OPTIMIZED(countNonZero16u),
(CountNonZeroFunc)GET_OPTIMIZED(countNonZero32s), (CountNonZeroFunc)GET_OPTIMIZED(countNonZero32f),
(CountNonZeroFunc)GET_OPTIMIZED(countNonZero64f), 0
};
return countNonZeroTab[depth];
}
#endif
CV_CPU_OPTIMIZATION_NAMESPACE_END
} // namespace

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,245 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html
#include "precomp.hpp"
#include "opencl_kernels_core.hpp"
#include "stat.hpp"
#include "sum.simd.hpp"
#include "sum.simd_declarations.hpp" // defines CV_CPU_DISPATCH_MODES_ALL=AVX2,...,BASELINE based on CMakeLists.txt content
#undef HAVE_IPP
#undef CV_IPP_RUN_FAST
#define CV_IPP_RUN_FAST(f, ...)
#undef CV_IPP_RUN
#define CV_IPP_RUN(c, f, ...)
namespace cv
{
SumFunc getSumFunc(int depth)
{
CV_INSTRUMENT_REGION();
CV_CPU_DISPATCH(getSumFunc, (depth),
CV_CPU_DISPATCH_MODES_ALL);
}
#ifdef HAVE_OPENCL
bool ocl_sum( InputArray _src, Scalar & res, int sum_op, InputArray _mask,
InputArray _src2, bool calc2, const Scalar & res2 )
{
CV_Assert(sum_op == OCL_OP_SUM || sum_op == OCL_OP_SUM_ABS || sum_op == OCL_OP_SUM_SQR);
const ocl::Device & dev = ocl::Device::getDefault();
bool doubleSupport = dev.doubleFPConfig() > 0,
haveMask = _mask.kind() != _InputArray::NONE,
haveSrc2 = _src2.kind() != _InputArray::NONE;
int type = _src.type(), depth = CV_MAT_DEPTH(type), cn = CV_MAT_CN(type),
kercn = cn == 1 && !haveMask ? ocl::predictOptimalVectorWidth(_src, _src2) : 1,
mcn = std::max(cn, kercn);
CV_Assert(!haveSrc2 || _src2.type() == type);
int convert_cn = haveSrc2 ? mcn : cn;
if ( (!doubleSupport && depth == CV_64F) || cn > 4 )
return false;
int ngroups = dev.maxComputeUnits(), dbsize = ngroups * (calc2 ? 2 : 1);
size_t wgs = dev.maxWorkGroupSize();
int ddepth = std::max(sum_op == OCL_OP_SUM_SQR ? CV_32F : CV_32S, depth),
dtype = CV_MAKE_TYPE(ddepth, cn);
CV_Assert(!haveMask || _mask.type() == CV_8UC1);
int wgs2_aligned = 1;
while (wgs2_aligned < (int)wgs)
wgs2_aligned <<= 1;
wgs2_aligned >>= 1;
static const char * const opMap[3] = { "OP_SUM", "OP_SUM_ABS", "OP_SUM_SQR" };
char cvt[2][40];
String opts = format("-D srcT=%s -D srcT1=%s -D dstT=%s -D dstTK=%s -D dstT1=%s -D ddepth=%d -D cn=%d"
" -D convertToDT=%s -D %s -D WGS=%d -D WGS2_ALIGNED=%d%s%s%s%s -D kercn=%d%s%s%s -D convertFromU=%s",
ocl::typeToStr(CV_MAKE_TYPE(depth, mcn)), ocl::typeToStr(depth),
ocl::typeToStr(dtype), ocl::typeToStr(CV_MAKE_TYPE(ddepth, mcn)),
ocl::typeToStr(ddepth), ddepth, cn,
ocl::convertTypeStr(depth, ddepth, mcn, cvt[0]),
opMap[sum_op], (int)wgs, wgs2_aligned,
doubleSupport ? " -D DOUBLE_SUPPORT" : "",
haveMask ? " -D HAVE_MASK" : "",
_src.isContinuous() ? " -D HAVE_SRC_CONT" : "",
haveMask && _mask.isContinuous() ? " -D HAVE_MASK_CONT" : "", kercn,
haveSrc2 ? " -D HAVE_SRC2" : "", calc2 ? " -D OP_CALC2" : "",
haveSrc2 && _src2.isContinuous() ? " -D HAVE_SRC2_CONT" : "",
depth <= CV_32S && ddepth == CV_32S ? ocl::convertTypeStr(CV_8U, ddepth, convert_cn, cvt[1]) : "noconvert");
ocl::Kernel k("reduce", ocl::core::reduce_oclsrc, opts);
if (k.empty())
return false;
UMat src = _src.getUMat(), src2 = _src2.getUMat(),
db(1, dbsize, dtype), mask = _mask.getUMat();
ocl::KernelArg srcarg = ocl::KernelArg::ReadOnlyNoSize(src),
dbarg = ocl::KernelArg::PtrWriteOnly(db),
maskarg = ocl::KernelArg::ReadOnlyNoSize(mask),
src2arg = ocl::KernelArg::ReadOnlyNoSize(src2);
if (haveMask)
{
if (haveSrc2)
k.args(srcarg, src.cols, (int)src.total(), ngroups, dbarg, maskarg, src2arg);
else
k.args(srcarg, src.cols, (int)src.total(), ngroups, dbarg, maskarg);
}
else
{
if (haveSrc2)
k.args(srcarg, src.cols, (int)src.total(), ngroups, dbarg, src2arg);
else
k.args(srcarg, src.cols, (int)src.total(), ngroups, dbarg);
}
size_t globalsize = ngroups * wgs;
if (k.run(1, &globalsize, &wgs, true))
{
typedef Scalar (*part_sum)(Mat m);
part_sum funcs[3] = { ocl_part_sum<int>, ocl_part_sum<float>, ocl_part_sum<double> },
func = funcs[ddepth - CV_32S];
Mat mres = db.getMat(ACCESS_READ);
if (calc2)
const_cast<Scalar &>(res2) = func(mres.colRange(ngroups, dbsize));
res = func(mres.colRange(0, ngroups));
return true;
}
return false;
}
#endif
#ifdef HAVE_IPP
static bool ipp_sum(Mat &src, Scalar &_res)
{
CV_INSTRUMENT_REGION_IPP();
#if IPP_VERSION_X100 >= 700
int cn = src.channels();
if (cn > 4)
return false;
size_t total_size = src.total();
int rows = src.size[0], cols = rows ? (int)(total_size/rows) : 0;
if( src.dims == 2 || (src.isContinuous() && cols > 0 && (size_t)rows*cols == total_size) )
{
IppiSize sz = { cols, rows };
int type = src.type();
typedef IppStatus (CV_STDCALL* ippiSumFuncHint)(const void*, int, IppiSize, double *, IppHintAlgorithm);
typedef IppStatus (CV_STDCALL* ippiSumFuncNoHint)(const void*, int, IppiSize, double *);
ippiSumFuncHint ippiSumHint =
type == CV_32FC1 ? (ippiSumFuncHint)ippiSum_32f_C1R :
type == CV_32FC3 ? (ippiSumFuncHint)ippiSum_32f_C3R :
type == CV_32FC4 ? (ippiSumFuncHint)ippiSum_32f_C4R :
0;
ippiSumFuncNoHint ippiSum =
type == CV_8UC1 ? (ippiSumFuncNoHint)ippiSum_8u_C1R :
type == CV_8UC3 ? (ippiSumFuncNoHint)ippiSum_8u_C3R :
type == CV_8UC4 ? (ippiSumFuncNoHint)ippiSum_8u_C4R :
type == CV_16UC1 ? (ippiSumFuncNoHint)ippiSum_16u_C1R :
type == CV_16UC3 ? (ippiSumFuncNoHint)ippiSum_16u_C3R :
type == CV_16UC4 ? (ippiSumFuncNoHint)ippiSum_16u_C4R :
type == CV_16SC1 ? (ippiSumFuncNoHint)ippiSum_16s_C1R :
type == CV_16SC3 ? (ippiSumFuncNoHint)ippiSum_16s_C3R :
type == CV_16SC4 ? (ippiSumFuncNoHint)ippiSum_16s_C4R :
0;
CV_Assert(!ippiSumHint || !ippiSum);
if( ippiSumHint || ippiSum )
{
Ipp64f res[4];
IppStatus ret = ippiSumHint ?
CV_INSTRUMENT_FUN_IPP(ippiSumHint, src.ptr(), (int)src.step[0], sz, res, ippAlgHintAccurate) :
CV_INSTRUMENT_FUN_IPP(ippiSum, src.ptr(), (int)src.step[0], sz, res);
if( ret >= 0 )
{
for( int i = 0; i < cn; i++ )
_res[i] = res[i];
return true;
}
}
}
#else
CV_UNUSED(src); CV_UNUSED(_res);
#endif
return false;
}
#endif
Scalar sum(InputArray _src)
{
CV_INSTRUMENT_REGION();
#if defined HAVE_OPENCL || defined HAVE_IPP
Scalar _res;
#endif
#ifdef HAVE_OPENCL
CV_OCL_RUN_(OCL_PERFORMANCE_CHECK(_src.isUMat()) && _src.dims() <= 2,
ocl_sum(_src, _res, OCL_OP_SUM),
_res)
#endif
Mat src = _src.getMat();
CV_IPP_RUN(IPP_VERSION_X100 >= 700, ipp_sum(src, _res), _res);
int k, cn = src.channels(), depth = src.depth();
SumFunc func = getSumFunc(depth);
CV_Assert( cn <= 4 && func != 0 );
const Mat* arrays[] = {&src, 0};
uchar* ptrs[1] = {};
NAryMatIterator it(arrays, ptrs);
Scalar s;
int total = (int)it.size, blockSize = total, intSumBlockSize = 0;
int j, count = 0;
AutoBuffer<int> _buf;
int* buf = (int*)&s[0];
size_t esz = 0;
bool blockSum = depth < CV_32S;
if( blockSum )
{
intSumBlockSize = depth <= CV_8S ? (1 << 23) : (1 << 15);
blockSize = std::min(blockSize, intSumBlockSize);
_buf.allocate(cn);
buf = _buf.data();
for( k = 0; k < cn; k++ )
buf[k] = 0;
esz = src.elemSize();
}
for( size_t i = 0; i < it.nplanes; i++, ++it )
{
for( j = 0; j < total; j += blockSize )
{
int bsz = std::min(total - j, blockSize);
func( ptrs[0], 0, (uchar*)buf, bsz, cn );
count += bsz;
if( blockSum && (count + blockSize >= intSumBlockSize || (i+1 >= it.nplanes && j+bsz >= total)) )
{
for( k = 0; k < cn; k++ )
{
s[k] += buf[k];
buf[k] = 0;
}
count = 0;
}
ptrs[0] += bsz*esz;
}
}
return s;
}
} // namespace

View File

@ -4,17 +4,14 @@
#include "precomp.hpp"
#include "opencl_kernels_core.hpp"
#include "stat.hpp"
#undef HAVE_IPP
#undef CV_IPP_RUN_FAST
#define CV_IPP_RUN_FAST(f, ...)
#undef CV_IPP_RUN
#define CV_IPP_RUN(c, f, ...)
namespace cv {
CV_CPU_OPTIMIZATION_NAMESPACE_BEGIN
namespace cv
{
SumFunc getSumFunc(int depth);
#ifndef CV_CPU_OPTIMIZATION_DECLARATIONS_ONLY
template <typename T, typename ST>
struct Sum_SIMD
@ -415,25 +412,25 @@ static int sum_(const T* src0, const uchar* mask, ST* dst, int len, int cn )
static int sum8u( const uchar* src, const uchar* mask, int* dst, int len, int cn )
{ return sum_(src, mask, dst, len, cn); }
{ CV_INSTRUMENT_REGION(); return sum_(src, mask, dst, len, cn); }
static int sum8s( const schar* src, const uchar* mask, int* dst, int len, int cn )
{ return sum_(src, mask, dst, len, cn); }
{ CV_INSTRUMENT_REGION(); return sum_(src, mask, dst, len, cn); }
static int sum16u( const ushort* src, const uchar* mask, int* dst, int len, int cn )
{ return sum_(src, mask, dst, len, cn); }
{ CV_INSTRUMENT_REGION(); return sum_(src, mask, dst, len, cn); }
static int sum16s( const short* src, const uchar* mask, int* dst, int len, int cn )
{ return sum_(src, mask, dst, len, cn); }
{ CV_INSTRUMENT_REGION(); return sum_(src, mask, dst, len, cn); }
static int sum32s( const int* src, const uchar* mask, double* dst, int len, int cn )
{ return sum_(src, mask, dst, len, cn); }
{ CV_INSTRUMENT_REGION(); return sum_(src, mask, dst, len, cn); }
static int sum32f( const float* src, const uchar* mask, double* dst, int len, int cn )
{ return sum_(src, mask, dst, len, cn); }
{ CV_INSTRUMENT_REGION(); return sum_(src, mask, dst, len, cn); }
static int sum64f( const double* src, const uchar* mask, double* dst, int len, int cn )
{ return sum_(src, mask, dst, len, cn); }
{ CV_INSTRUMENT_REGION(); return sum_(src, mask, dst, len, cn); }
SumFunc getSumFunc(int depth)
{
@ -449,220 +446,7 @@ SumFunc getSumFunc(int depth)
return sumTab[depth];
}
#ifdef HAVE_OPENCL
bool ocl_sum( InputArray _src, Scalar & res, int sum_op, InputArray _mask,
InputArray _src2, bool calc2, const Scalar & res2 )
{
CV_Assert(sum_op == OCL_OP_SUM || sum_op == OCL_OP_SUM_ABS || sum_op == OCL_OP_SUM_SQR);
const ocl::Device & dev = ocl::Device::getDefault();
bool doubleSupport = dev.doubleFPConfig() > 0,
haveMask = _mask.kind() != _InputArray::NONE,
haveSrc2 = _src2.kind() != _InputArray::NONE;
int type = _src.type(), depth = CV_MAT_DEPTH(type), cn = CV_MAT_CN(type),
kercn = cn == 1 && !haveMask ? ocl::predictOptimalVectorWidth(_src, _src2) : 1,
mcn = std::max(cn, kercn);
CV_Assert(!haveSrc2 || _src2.type() == type);
int convert_cn = haveSrc2 ? mcn : cn;
if ( (!doubleSupport && depth == CV_64F) || cn > 4 )
return false;
int ngroups = dev.maxComputeUnits(), dbsize = ngroups * (calc2 ? 2 : 1);
size_t wgs = dev.maxWorkGroupSize();
int ddepth = std::max(sum_op == OCL_OP_SUM_SQR ? CV_32F : CV_32S, depth),
dtype = CV_MAKE_TYPE(ddepth, cn);
CV_Assert(!haveMask || _mask.type() == CV_8UC1);
int wgs2_aligned = 1;
while (wgs2_aligned < (int)wgs)
wgs2_aligned <<= 1;
wgs2_aligned >>= 1;
static const char * const opMap[3] = { "OP_SUM", "OP_SUM_ABS", "OP_SUM_SQR" };
char cvt[2][40];
String opts = format("-D srcT=%s -D srcT1=%s -D dstT=%s -D dstTK=%s -D dstT1=%s -D ddepth=%d -D cn=%d"
" -D convertToDT=%s -D %s -D WGS=%d -D WGS2_ALIGNED=%d%s%s%s%s -D kercn=%d%s%s%s -D convertFromU=%s",
ocl::typeToStr(CV_MAKE_TYPE(depth, mcn)), ocl::typeToStr(depth),
ocl::typeToStr(dtype), ocl::typeToStr(CV_MAKE_TYPE(ddepth, mcn)),
ocl::typeToStr(ddepth), ddepth, cn,
ocl::convertTypeStr(depth, ddepth, mcn, cvt[0]),
opMap[sum_op], (int)wgs, wgs2_aligned,
doubleSupport ? " -D DOUBLE_SUPPORT" : "",
haveMask ? " -D HAVE_MASK" : "",
_src.isContinuous() ? " -D HAVE_SRC_CONT" : "",
haveMask && _mask.isContinuous() ? " -D HAVE_MASK_CONT" : "", kercn,
haveSrc2 ? " -D HAVE_SRC2" : "", calc2 ? " -D OP_CALC2" : "",
haveSrc2 && _src2.isContinuous() ? " -D HAVE_SRC2_CONT" : "",
depth <= CV_32S && ddepth == CV_32S ? ocl::convertTypeStr(CV_8U, ddepth, convert_cn, cvt[1]) : "noconvert");
ocl::Kernel k("reduce", ocl::core::reduce_oclsrc, opts);
if (k.empty())
return false;
UMat src = _src.getUMat(), src2 = _src2.getUMat(),
db(1, dbsize, dtype), mask = _mask.getUMat();
ocl::KernelArg srcarg = ocl::KernelArg::ReadOnlyNoSize(src),
dbarg = ocl::KernelArg::PtrWriteOnly(db),
maskarg = ocl::KernelArg::ReadOnlyNoSize(mask),
src2arg = ocl::KernelArg::ReadOnlyNoSize(src2);
if (haveMask)
{
if (haveSrc2)
k.args(srcarg, src.cols, (int)src.total(), ngroups, dbarg, maskarg, src2arg);
else
k.args(srcarg, src.cols, (int)src.total(), ngroups, dbarg, maskarg);
}
else
{
if (haveSrc2)
k.args(srcarg, src.cols, (int)src.total(), ngroups, dbarg, src2arg);
else
k.args(srcarg, src.cols, (int)src.total(), ngroups, dbarg);
}
size_t globalsize = ngroups * wgs;
if (k.run(1, &globalsize, &wgs, true))
{
typedef Scalar (*part_sum)(Mat m);
part_sum funcs[3] = { ocl_part_sum<int>, ocl_part_sum<float>, ocl_part_sum<double> },
func = funcs[ddepth - CV_32S];
Mat mres = db.getMat(ACCESS_READ);
if (calc2)
const_cast<Scalar &>(res2) = func(mres.colRange(ngroups, dbsize));
res = func(mres.colRange(0, ngroups));
return true;
}
return false;
}
#endif
#ifdef HAVE_IPP
static bool ipp_sum(Mat &src, Scalar &_res)
{
CV_INSTRUMENT_REGION_IPP();
#if IPP_VERSION_X100 >= 700
int cn = src.channels();
if (cn > 4)
return false;
size_t total_size = src.total();
int rows = src.size[0], cols = rows ? (int)(total_size/rows) : 0;
if( src.dims == 2 || (src.isContinuous() && cols > 0 && (size_t)rows*cols == total_size) )
{
IppiSize sz = { cols, rows };
int type = src.type();
typedef IppStatus (CV_STDCALL* ippiSumFuncHint)(const void*, int, IppiSize, double *, IppHintAlgorithm);
typedef IppStatus (CV_STDCALL* ippiSumFuncNoHint)(const void*, int, IppiSize, double *);
ippiSumFuncHint ippiSumHint =
type == CV_32FC1 ? (ippiSumFuncHint)ippiSum_32f_C1R :
type == CV_32FC3 ? (ippiSumFuncHint)ippiSum_32f_C3R :
type == CV_32FC4 ? (ippiSumFuncHint)ippiSum_32f_C4R :
0;
ippiSumFuncNoHint ippiSum =
type == CV_8UC1 ? (ippiSumFuncNoHint)ippiSum_8u_C1R :
type == CV_8UC3 ? (ippiSumFuncNoHint)ippiSum_8u_C3R :
type == CV_8UC4 ? (ippiSumFuncNoHint)ippiSum_8u_C4R :
type == CV_16UC1 ? (ippiSumFuncNoHint)ippiSum_16u_C1R :
type == CV_16UC3 ? (ippiSumFuncNoHint)ippiSum_16u_C3R :
type == CV_16UC4 ? (ippiSumFuncNoHint)ippiSum_16u_C4R :
type == CV_16SC1 ? (ippiSumFuncNoHint)ippiSum_16s_C1R :
type == CV_16SC3 ? (ippiSumFuncNoHint)ippiSum_16s_C3R :
type == CV_16SC4 ? (ippiSumFuncNoHint)ippiSum_16s_C4R :
0;
CV_Assert(!ippiSumHint || !ippiSum);
if( ippiSumHint || ippiSum )
{
Ipp64f res[4];
IppStatus ret = ippiSumHint ?
CV_INSTRUMENT_FUN_IPP(ippiSumHint, src.ptr(), (int)src.step[0], sz, res, ippAlgHintAccurate) :
CV_INSTRUMENT_FUN_IPP(ippiSum, src.ptr(), (int)src.step[0], sz, res);
if( ret >= 0 )
{
for( int i = 0; i < cn; i++ )
_res[i] = res[i];
return true;
}
}
}
#else
CV_UNUSED(src); CV_UNUSED(_res);
#endif
return false;
}
#endif
} // cv::
cv::Scalar cv::sum( InputArray _src )
{
CV_INSTRUMENT_REGION();
#if defined HAVE_OPENCL || defined HAVE_IPP
Scalar _res;
#endif
#ifdef HAVE_OPENCL
CV_OCL_RUN_(OCL_PERFORMANCE_CHECK(_src.isUMat()) && _src.dims() <= 2,
ocl_sum(_src, _res, OCL_OP_SUM),
_res)
#endif
Mat src = _src.getMat();
CV_IPP_RUN(IPP_VERSION_X100 >= 700, ipp_sum(src, _res), _res);
int k, cn = src.channels(), depth = src.depth();
SumFunc func = getSumFunc(depth);
CV_Assert( cn <= 4 && func != 0 );
const Mat* arrays[] = {&src, 0};
uchar* ptrs[1] = {};
NAryMatIterator it(arrays, ptrs);
Scalar s;
int total = (int)it.size, blockSize = total, intSumBlockSize = 0;
int j, count = 0;
AutoBuffer<int> _buf;
int* buf = (int*)&s[0];
size_t esz = 0;
bool blockSum = depth < CV_32S;
if( blockSum )
{
intSumBlockSize = depth <= CV_8S ? (1 << 23) : (1 << 15);
blockSize = std::min(blockSize, intSumBlockSize);
_buf.allocate(cn);
buf = _buf.data();
for( k = 0; k < cn; k++ )
buf[k] = 0;
esz = src.elemSize();
}
for( size_t i = 0; i < it.nplanes; i++, ++it )
{
for( j = 0; j < total; j += blockSize )
{
int bsz = std::min(total - j, blockSize);
func( ptrs[0], 0, (uchar*)buf, bsz, cn );
count += bsz;
if( blockSum && (count + blockSize >= intSumBlockSize || (i+1 >= it.nplanes && j+bsz >= total)) )
{
for( k = 0; k < cn; k++ )
{
s[k] += buf[k];
buf[k] = 0;
}
count = 0;
}
ptrs[0] += bsz*esz;
}
}
return s;
}
CV_CPU_OPTIMIZATION_NAMESPACE_END
} // namespace

View File

@ -124,8 +124,7 @@ PERF_TEST_P_(DNNTestNetwork, SSD)
PERF_TEST_P_(DNNTestNetwork, OpenFace)
{
if (backend == DNN_BACKEND_HALIDE ||
(backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_OPENCL_FP16) ||
(backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_MYRIAD))
(backend == DNN_BACKEND_INFERENCE_ENGINE && target == DNN_TARGET_MYRIAD))
throw SkipTestException("");
processNet("dnn/openface_nn4.small2.v1.t7", "", "",
Mat(cv::Size(96, 96), CV_32FC3));

Some files were not shown because too many files have changed in this diff Show More