From e3100f714c2bae3da26877020048e2cf5906172b Mon Sep 17 00:00:00 2001 From: Aaron Boxer Date: Thu, 28 Jan 2016 19:34:00 -0500 Subject: [PATCH 01/39] issue #695 MQ Encode: ensure that bp pointer never points to uninitialized memory --- src/lib/openjp2/mqc.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/lib/openjp2/mqc.c b/src/lib/openjp2/mqc.c index 7e0f5637..e6e4cc87 100644 --- a/src/lib/openjp2/mqc.c +++ b/src/lib/openjp2/mqc.c @@ -203,13 +203,14 @@ static opj_mqc_state_t mqc_states[47 * 2] = { */ static void opj_mqc_byteout(opj_mqc_t *mqc) { - if (*mqc->bp == 0xff) { + OPJ_BYTE bp_in_bounds = (mqc->bp >= mqc->start); + if (bp_in_bounds & (*mqc->bp == 0xff)) { mqc->bp++; *mqc->bp = (OPJ_BYTE)(mqc->c >> 20); mqc->c &= 0xfffff; mqc->ct = 7; } else { - if ((mqc->c & 0x8000000) == 0) { /* ((mqc->c&0x8000000)==0) CHANGE */ + if ((bp_in_bounds ^ 1) | ((mqc->c & 0x8000000) == 0)) { mqc->bp++; *mqc->bp = (OPJ_BYTE)(mqc->c >> 19); mqc->c &= 0x7ffff; @@ -395,9 +396,6 @@ void opj_mqc_init_enc(opj_mqc_t *mqc, OPJ_BYTE *bp) { mqc->c = 0; mqc->bp = bp - 1; mqc->ct = 12; - if (*mqc->bp == 0xff) { - mqc->ct = 13; - } mqc->start = bp; } From 0069a2bd2f8055b7edf9699332f4f00ac5351564 Mon Sep 17 00:00:00 2001 From: Aaron Boxer Date: Sat, 30 Jan 2016 10:05:46 -0500 Subject: [PATCH 02/39] suppress valgrind error - avoid accessing uninitialized memory in mq encoder --- src/lib/openjp2/mqc.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/lib/openjp2/mqc.c b/src/lib/openjp2/mqc.c index e6e4cc87..4e409a7c 100644 --- a/src/lib/openjp2/mqc.c +++ b/src/lib/openjp2/mqc.c @@ -203,14 +203,20 @@ static opj_mqc_state_t mqc_states[47 * 2] = { */ static void opj_mqc_byteout(opj_mqc_t *mqc) { - OPJ_BYTE bp_in_bounds = (mqc->bp >= mqc->start); - if (bp_in_bounds & (*mqc->bp == 0xff)) { + /* avoid accessing uninitialized memory*/ + if (mqc->bp == mqc->start-1) { + mqc->bp++; + *mqc->bp = (OPJ_BYTE)(mqc->c >> 19); + mqc->c &= 0x7ffff; + mqc->ct = 8; + } + else if (*mqc->bp == 0xff) { mqc->bp++; *mqc->bp = (OPJ_BYTE)(mqc->c >> 20); mqc->c &= 0xfffff; mqc->ct = 7; } else { - if ((bp_in_bounds ^ 1) | ((mqc->c & 0x8000000) == 0)) { + if ((mqc->c & 0x8000000) == 0) { mqc->bp++; *mqc->bp = (OPJ_BYTE)(mqc->c >> 19); mqc->c &= 0x7ffff; From 5e5f6999a8e218f52584841ea6fdffde34743722 Mon Sep 17 00:00:00 2001 From: Julien Malik Date: Sat, 9 Apr 2016 18:34:11 +0200 Subject: [PATCH 03/39] Remove dead code in opj_dump --- src/bin/jp2/opj_dump.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/bin/jp2/opj_dump.c b/src/bin/jp2/opj_dump.c index 1e51f43c..bd608c2b 100644 --- a/src/bin/jp2/opj_dump.c +++ b/src/bin/jp2/opj_dump.c @@ -433,12 +433,6 @@ int main(int argc, char *argv[]) img_fol_t img_fol; dircnt_t *dirptr = NULL; -#ifdef MSD - OPJ_BOOL l_go_on = OPJ_TRUE; - OPJ_UINT32 l_max_data_size = 1000; - OPJ_BYTE * l_data = (OPJ_BYTE *) malloc(1000); -#endif - /* Set decoding parameters to default values */ opj_set_default_decoder_parameters(¶meters); From e7797b97a1922e0d38d705916117c29af96471a0 Mon Sep 17 00:00:00 2001 From: Julien Malik Date: Sat, 9 Apr 2016 19:02:05 +0200 Subject: [PATCH 04/39] Fix uninitialized variable reported by cppcheck Also reorder initialization to follow declaration order --- src/lib/openjp2/t1_generate_luts.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib/openjp2/t1_generate_luts.c b/src/lib/openjp2/t1_generate_luts.c index 1997d399..cba7245d 100644 --- a/src/lib/openjp2/t1_generate_luts.c +++ b/src/lib/openjp2/t1_generate_luts.c @@ -40,10 +40,12 @@ static int t1_init_ctxno_zc(int f, int orient) { int h, v, d, n, t, hv; - n = 0; h = ((f & T1_SIG_W) != 0) + ((f & T1_SIG_E) != 0); v = ((f & T1_SIG_N) != 0) + ((f & T1_SIG_S) != 0); d = ((f & T1_SIG_NW) != 0) + ((f & T1_SIG_NE) != 0) + ((f & T1_SIG_SE) != 0) + ((f & T1_SIG_SW) != 0); + n = 0; + t = 0; + hv = 0; switch (orient) { case 2: From 3436c4e9baac1fd847c4475b961802cd1c9bbe7e Mon Sep 17 00:00:00 2001 From: Julien Malik Date: Tue, 19 Apr 2016 15:22:49 +0200 Subject: [PATCH 05/39] upgrade cmake to 3.5.2 --- tools/travis-ci/install.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/travis-ci/install.sh b/tools/travis-ci/install.sh index c62feee8..be99383e 100755 --- a/tools/travis-ci/install.sh +++ b/tools/travis-ci/install.sh @@ -37,9 +37,9 @@ fi if [ "${OPJ_CI_ASAN:-}" == "1" ]; then # We need a new version of cmake than travis-ci provides - wget --no-check-certificate -qO - https://cmake.org/files/v3.3/cmake-3.3.2-Linux-x86_64.tar.gz | tar -xz + wget --no-check-certificate -qO - https://cmake.org/files/v3.5/cmake-3.5.2-Linux-x86_64.tar.gz | tar -xz # copy to a directory that will not changed every version - mv cmake-3.3.2-Linux-x86_64 cmake-install + mv cmake-3.5.2-Linux-x86_64 cmake-install fi if [ "${OPJ_CI_SKIP_TESTS:-}" != "1" ]; then From 6ea2ff0b0627655d36ad7cc7483de7592b8bcbd1 Mon Sep 17 00:00:00 2001 From: Julien Malik Date: Tue, 19 Apr 2016 15:25:42 +0200 Subject: [PATCH 06/39] Update jpylyzer to 1.17.0 --- tools/travis-ci/install.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tools/travis-ci/install.sh b/tools/travis-ci/install.sh index be99383e..003f8fa8 100755 --- a/tools/travis-ci/install.sh +++ b/tools/travis-ci/install.sh @@ -62,16 +62,17 @@ if [ "${OPJ_CI_SKIP_TESTS:-}" != "1" ]; then git clone --depth=1 --branch=${OPJ_DATA_BRANCH} git://github.com/uclouvain/openjpeg-data.git data # We need jpylyzer for the test suite + JPYLYZER_VERSION="1.17.0" echo "Retrieving jpylyzer" if [ "${APPVEYOR:-}" == "True" ]; then - wget --local-encoding=UTF-8 -q http://dl.bintray.com/openplanets/opf-windows/jpylyzer_1.14.2_win32.zip + wget --local-encoding=UTF-8 -q http://dl.bintray.com/openplanets/opf-windows/jpylyzer_${JPYLYZER_VERSION}_win32.zip mkdir jpylyzer cd jpylyzer - cmake -E tar -xf ../jpylyzer_1.14.2_win32.zip + cmake -E tar -xf ../jpylyzer_${JPYLYZER_VERSION}_win32.zip cd .. else - wget -qO - https://github.com/openpreserve/jpylyzer/archive/1.14.2.tar.gz | tar -xz - mv jpylyzer-1.14.2/jpylyzer ./ + wget -qO - https://github.com/openpreserve/jpylyzer/archive/${JPYLYZER_VERSION}.tar.gz | tar -xz + mv jpylyzer-${JPYLYZER_VERSION}/jpylyzer ./ chmod +x jpylyzer/jpylyzer.py fi From 889bf167913c202ee33b25c64063fd6db5bece96 Mon Sep 17 00:00:00 2001 From: Julien Malik Date: Thu, 21 Apr 2016 18:49:15 +0200 Subject: [PATCH 07/39] update libpng to from 1.6.17 to 1.6.21 --- thirdparty/libpng/LICENSE | 55 +- thirdparty/libpng/png.c | 171 +++--- thirdparty/libpng/png.h | 574 ++++++++------------ thirdparty/libpng/pngconf.h | 26 +- thirdparty/libpng/pngdebug.h | 2 +- thirdparty/libpng/pngerror.c | 4 +- thirdparty/libpng/pngget.c | 2 +- thirdparty/libpng/pnginfo.h | 4 +- thirdparty/libpng/pngmem.c | 5 +- thirdparty/libpng/pngpread.c | 119 +---- thirdparty/libpng/pngpriv.h | 58 +- thirdparty/libpng/pngread.c | 34 +- thirdparty/libpng/pngrio.c | 4 +- thirdparty/libpng/pngrtran.c | 32 +- thirdparty/libpng/pngrutil.c | 427 ++++++++------- thirdparty/libpng/pngset.c | 117 ++++- thirdparty/libpng/pngstruct.h | 35 +- thirdparty/libpng/pngtrans.c | 10 +- thirdparty/libpng/pngwio.c | 4 +- thirdparty/libpng/pngwrite.c | 617 +++++++--------------- thirdparty/libpng/pngwtran.c | 16 +- thirdparty/libpng/pngwutil.c | 964 ++++++++++------------------------ 22 files changed, 1287 insertions(+), 1993 deletions(-) diff --git a/thirdparty/libpng/LICENSE b/thirdparty/libpng/LICENSE index eb4a9a9d..fd93b1b4 100644 --- a/thirdparty/libpng/LICENSE +++ b/thirdparty/libpng/LICENSE @@ -10,21 +10,18 @@ this sentence. This code is released under the libpng license. -libpng versions 1.2.6, August 15, 2004, through 1.6.17, March 26, 2015, are -Copyright (c) 2004, 2006-2015 Glenn Randers-Pehrson, and are -distributed according to the same disclaimer and license as libpng-1.2.5 -with the following individual added to the list of Contributing Authors - - Cosmin Truta - -libpng versions 1.0.7, July 1, 2000, through 1.2.5 - October 3, 2002, are -Copyright (c) 2000-2002 Glenn Randers-Pehrson, and are -distributed according to the same disclaimer and license as libpng-1.0.6 -with the following individuals added to the list of Contributing Authors +libpng versions 1.0.7, July 1, 2000, through 1.6.21, January 15, 2016, are +Copyright (c) 2000-2002, 2004, 2006-2016 Glenn Randers-Pehrson, are +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 and with the following additions to the disclaimer: @@ -36,18 +33,20 @@ and with the following additions to the disclaimer: the user. libpng versions 0.97, January 1998, through 1.0.6, March 20, 2000, are -Copyright (c) 1998, 1999 Glenn Randers-Pehrson, 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: +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: 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 -Distributed according to the same disclaimer and license as libpng-0.88, -with the following individuals added to the list of Contributing Authors: +Copyright (c) 1996-1997 Andreas Dilger, are derived from libpng-0.88, +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 @@ -57,7 +56,7 @@ with the following individuals added to the list of Contributing Authors: Tom Tanner libpng versions 0.5, May 1995, through 0.88, January 1996, are -Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc. +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: @@ -80,13 +79,13 @@ 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 @@ -94,18 +93,20 @@ 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. A "png_get_copyright" function is available, for convenient use in "about" boxes and the like: - printf("%s",png_get_copyright(NULL)); + printf("%s", png_get_copyright(NULL)); Also, the PNG logo (in PNG format, of course) is supplied in the files "pngbar.png" and "pngbar.jpg (88x31) and "pngnow.png" (98x31). -Libpng is OSI Certified Open Source Software. OSI Certified Open Source is a -certification mark of the Open Source Initiative. +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. Glenn Randers-Pehrson glennrp at users.sourceforge.net -March 26, 2015 +January 15, 2016 diff --git a/thirdparty/libpng/png.c b/thirdparty/libpng/png.c index 7575ede9..1d1bde58 100644 --- a/thirdparty/libpng/png.c +++ b/thirdparty/libpng/png.c @@ -1,8 +1,8 @@ /* png.c - location for general purpose libpng functions * - * Last changed in libpng 1.6.17 [March 26, 2015] - * Copyright (c) 1998-2015 Glenn Randers-Pehrson + * Last changed in libpng 1.6.19 [November 12, 2015] + * Copyright (c) 1998-2002,2004,2006-2015 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.) * @@ -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_17 Your_png_h_is_not_version_1_6_17; +typedef png_libpng_version_1_6_21 Your_png_h_is_not_version_1_6_21; /* Tells libpng that we have already handled the first "num_bytes" bytes * of the PNG file signature. If the PNG data is embedded into another @@ -26,15 +26,20 @@ typedef png_libpng_version_1_6_17 Your_png_h_is_not_version_1_6_17; void PNGAPI png_set_sig_bytes(png_structrp png_ptr, int num_bytes) { + unsigned int nb = (unsigned int)num_bytes; + png_debug(1, "in png_set_sig_bytes"); if (png_ptr == NULL) return; - if (num_bytes > 8) + if (num_bytes < 0) + nb = 0; + + if (nb > 8) png_error(png_ptr, "Too many bytes for PNG signature"); - png_ptr->sig_bytes = (png_byte)((num_bytes < 0 ? 0 : num_bytes) & 0xff); + png_ptr->sig_bytes = (png_byte)nb; } /* Checks whether the supplied bytes match the PNG signature. We allow @@ -101,7 +106,7 @@ png_zfree(voidpf png_ptr, voidpf ptr) void /* PRIVATE */ png_reset_crc(png_structrp png_ptr) { - /* The cast is safe because the crc is a 32 bit value. */ + /* The cast is safe because the crc is a 32-bit value. */ png_ptr->crc = (png_uint_32)crc32(0, Z_NULL, 0); } @@ -129,7 +134,7 @@ png_calculate_crc(png_structrp png_ptr, png_const_bytep ptr, png_size_t length) } /* 'uLong' is defined in zlib.h as unsigned long; this means that on some - * systems it is a 64 bit value. crc32, however, returns 32 bits so the + * systems it is a 64-bit value. crc32, however, returns 32 bits so the * following cast is safe. 'uInt' may be no more than 16 bits, so it is * necessary to perform a loop here. */ @@ -243,15 +248,15 @@ png_create_png_struct,(png_const_charp user_png_ver, png_voidp error_ptr, create_struct.user_height_max = PNG_USER_HEIGHT_MAX; # ifdef PNG_USER_CHUNK_CACHE_MAX - /* Added at libpng-1.2.43 and 1.4.0 */ - create_struct.user_chunk_cache_max = PNG_USER_CHUNK_CACHE_MAX; + /* Added at libpng-1.2.43 and 1.4.0 */ + create_struct.user_chunk_cache_max = PNG_USER_CHUNK_CACHE_MAX; # endif # ifdef PNG_USER_CHUNK_MALLOC_MAX - /* Added at libpng-1.2.43 and 1.4.1, required only for read but exists - * in png_struct regardless. - */ - create_struct.user_chunk_malloc_max = PNG_USER_CHUNK_MALLOC_MAX; + /* Added at libpng-1.2.43 and 1.4.1, required only for read but exists + * in png_struct regardless. + */ + create_struct.user_chunk_malloc_max = PNG_USER_CHUNK_MALLOC_MAX; # endif # endif @@ -275,7 +280,9 @@ png_create_png_struct,(png_const_charp user_png_ver, png_voidp error_ptr, # ifdef PNG_SETJMP_SUPPORTED if (!setjmp(create_jmp_buf)) +# endif { +# ifdef PNG_SETJMP_SUPPORTED /* Temporarily fake out the longjmp information until we have * successfully completed this function. This only works if we have * setjmp() support compiled in, but it is safe - this stuff should @@ -284,8 +291,6 @@ png_create_png_struct,(png_const_charp user_png_ver, png_voidp error_ptr, create_struct.jmp_buf_ptr = &create_jmp_buf; create_struct.jmp_buf_size = 0; /*stack allocation*/ create_struct.longjmp_fn = longjmp; -# else - { # endif /* Call the general version checker (shared with read and write code): */ @@ -304,10 +309,10 @@ png_create_png_struct,(png_const_charp user_png_ver, png_voidp error_ptr, create_struct.zstream.opaque = png_ptr; # ifdef PNG_SETJMP_SUPPORTED - /* Eliminate the local error handling: */ - create_struct.jmp_buf_ptr = NULL; - create_struct.jmp_buf_size = 0; - create_struct.longjmp_fn = 0; + /* Eliminate the local error handling: */ + create_struct.jmp_buf_ptr = NULL; + create_struct.jmp_buf_size = 0; + create_struct.longjmp_fn = 0; # endif *png_ptr = create_struct; @@ -413,6 +418,8 @@ png_info_init_3,(png_infopp ptr_ptr, png_size_t png_info_struct_size), free(info_ptr); info_ptr = png_voidcast(png_inforp, png_malloc_base(NULL, (sizeof *info_ptr))); + if (info_ptr == NULL) + return; *ptr_ptr = info_ptr; } @@ -664,19 +671,20 @@ png_init_io(png_structrp png_ptr, png_FILE_p fp) # endif # ifdef PNG_SAVE_INT_32_SUPPORTED -/* The png_save_int_32 function assumes integers are stored in two's - * complement format. If this isn't the case, then this routine needs to - * be modified to write data in two's complement format. Note that, - * the following works correctly even if png_int_32 has more than 32 bits - * (compare the more complex code required on read for sign extension.) +/* PNG signed integers are saved in 32-bit 2's complement format. ANSI C-90 + * defines a cast of a signed integer to an unsigned integer either to preserve + * the value, if it is positive, or to calculate: + * + * (UNSIGNED_MAX+1) + integer + * + * Where UNSIGNED_MAX is the appropriate maximum unsigned value, so when the + * negative integral value is added the result will be an unsigned value + * correspnding to the 2's complement representation. */ void PNGAPI png_save_int_32(png_bytep buf, png_int_32 i) { - buf[0] = (png_byte)((i >> 24) & 0xff); - buf[1] = (png_byte)((i >> 16) & 0xff); - buf[2] = (png_byte)((i >> 8) & 0xff); - buf[3] = (png_byte)(i & 0xff); + png_save_uint_32(buf, i); } # endif @@ -722,6 +730,7 @@ png_convert_to_rfc1123_buffer(char out[29], png_const_timep ptime) APPEND(':'); APPEND_NUMBER(PNG_NUMBER_FORMAT_02u, (unsigned)ptime->second); APPEND_STRING(" +0000"); /* This reliably terminates the buffer */ + PNG_UNUSED (pos) # undef APPEND # undef APPEND_NUMBER @@ -766,14 +775,15 @@ png_get_copyright(png_const_structrp png_ptr) #else # ifdef __STDC__ return PNG_STRING_NEWLINE \ - "libpng version 1.6.17 - March 26, 2015" PNG_STRING_NEWLINE \ - "Copyright (c) 1998-2015 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; + "libpng version 1.6.21 - January 15, 2016" PNG_STRING_NEWLINE \ + "Copyright (c) 1998-2002,2004,2006-2016 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.17 - March 26, 2015\ - Copyright (c) 1998-2015 Glenn Randers-Pehrson\ + return "libpng version 1.6.21 - January 15, 2016\ + Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson\ Copyright (c) 1996-1997 Andreas Dilger\ Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc."; # endif @@ -811,9 +821,9 @@ png_get_header_version(png_const_structrp png_ptr) #ifdef __STDC__ return PNG_HEADER_VERSION_STRING # ifndef PNG_READ_SUPPORTED - " (NO READ SUPPORT)" + " (NO READ SUPPORT)" # endif - PNG_STRING_NEWLINE; + PNG_STRING_NEWLINE; #else return PNG_HEADER_VERSION_STRING; #endif @@ -1086,10 +1096,10 @@ png_colorspace_set_gamma(png_const_structrp png_ptr, errmsg = "gamma value out of range"; # ifdef PNG_READ_gAMA_SUPPORTED - /* Allow the application to set the gamma value more than once */ - else if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0 && - (colorspace->flags & PNG_COLORSPACE_FROM_gAMA) != 0) - errmsg = "duplicate"; + /* Allow the application to set the gamma value more than once */ + else if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0 && + (colorspace->flags & PNG_COLORSPACE_FROM_gAMA) != 0) + errmsg = "duplicate"; # endif /* Do nothing if the colorspace is already invalid */ @@ -1130,31 +1140,31 @@ png_colorspace_sync_info(png_const_structrp png_ptr, png_inforp info_ptr) PNG_INFO_iCCP); # ifdef PNG_COLORSPACE_SUPPORTED - /* Clean up the iCCP profile now if it won't be used. */ - png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, -1/*not used*/); + /* Clean up the iCCP profile now if it won't be used. */ + png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, -1/*not used*/); # else - PNG_UNUSED(png_ptr) + PNG_UNUSED(png_ptr) # endif } else { # ifdef PNG_COLORSPACE_SUPPORTED - /* Leave the INFO_iCCP flag set if the pngset.c code has already set - * it; this allows a PNG to contain a profile which matches sRGB and - * yet still have that profile retrievable by the application. - */ - if ((info_ptr->colorspace.flags & PNG_COLORSPACE_MATCHES_sRGB) != 0) - info_ptr->valid |= PNG_INFO_sRGB; + /* Leave the INFO_iCCP flag set if the pngset.c code has already set + * it; this allows a PNG to contain a profile which matches sRGB and + * yet still have that profile retrievable by the application. + */ + if ((info_ptr->colorspace.flags & PNG_COLORSPACE_MATCHES_sRGB) != 0) + info_ptr->valid |= PNG_INFO_sRGB; - else - info_ptr->valid &= ~PNG_INFO_sRGB; + else + info_ptr->valid &= ~PNG_INFO_sRGB; - if ((info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0) - info_ptr->valid |= PNG_INFO_cHRM; + if ((info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0) + info_ptr->valid |= PNG_INFO_cHRM; - else - info_ptr->valid &= ~PNG_INFO_cHRM; + else + info_ptr->valid &= ~PNG_INFO_cHRM; # endif if ((info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) != 0) @@ -1235,16 +1245,17 @@ png_XYZ_from_xy(png_XYZ *XYZ, const png_xy *xy) /* Check xy and, implicitly, z. Note that wide gamut color spaces typically * have end points with 0 tristimulus values (these are impossible end - * points, but they are used to cover the possible colors.) + * points, but they are used to cover the possible colors). We check + * xy->whitey against 5, not 0, to avoid a possible integer overflow. */ - if (xy->redx < 0 || xy->redx > PNG_FP_1) return 1; - if (xy->redy < 0 || xy->redy > PNG_FP_1-xy->redx) return 1; + if (xy->redx < 0 || xy->redx > PNG_FP_1) return 1; + if (xy->redy < 0 || xy->redy > PNG_FP_1-xy->redx) return 1; if (xy->greenx < 0 || xy->greenx > PNG_FP_1) return 1; if (xy->greeny < 0 || xy->greeny > PNG_FP_1-xy->greenx) return 1; - if (xy->bluex < 0 || xy->bluex > PNG_FP_1) return 1; - if (xy->bluey < 0 || xy->bluey > PNG_FP_1-xy->bluex) return 1; + if (xy->bluex < 0 || xy->bluex > PNG_FP_1) return 1; + if (xy->bluey < 0 || xy->bluey > PNG_FP_1-xy->bluex) return 1; if (xy->whitex < 0 || xy->whitex > PNG_FP_1) return 1; - if (xy->whitey < 0 || xy->whitey > PNG_FP_1-xy->whitex) return 1; + if (xy->whitey < 5 || xy->whitey > PNG_FP_1-xy->whitex) return 1; /* The reverse calculation is more difficult because the original tristimulus * value had 9 independent values (red,green,blue)x(X,Y,Z) however only 8 @@ -1702,7 +1713,6 @@ png_colorspace_set_chromaticities(png_const_structrp png_ptr, */ colorspace->flags |= PNG_COLORSPACE_INVALID; png_error(png_ptr, "internal error checking chromaticities"); - break; } return 0; /* failed */ @@ -1730,7 +1740,6 @@ png_colorspace_set_endpoints(png_const_structrp png_ptr, default: colorspace->flags |= PNG_COLORSPACE_INVALID; png_error(png_ptr, "internal error checking chromaticities"); - break; } return 0; /* failed */ @@ -2056,8 +2065,8 @@ png_icc_check_header(png_const_structrp png_ptr, png_colorspacerp colorspace, temp = png_get_uint_32(profile+12); /* profile/device class */ switch (temp) { - case 0x73636E72: /* 'scnr' */ - case 0x6D6E7472: /* 'mntr' */ + case 0x73636e72: /* 'scnr' */ + case 0x6d6e7472: /* 'mntr' */ case 0x70727472: /* 'prtr' */ case 0x73706163: /* 'spac' */ /* All supported */ @@ -2068,7 +2077,7 @@ png_icc_check_header(png_const_structrp png_ptr, png_colorspacerp colorspace, return png_icc_profile_error(png_ptr, colorspace, name, temp, "invalid embedded Abstract ICC profile"); - case 0x6C696E6B: /* 'link' */ + case 0x6c696e6b: /* 'link' */ /* DeviceLink profiles cannot be interpreted in a non-device specific * fashion, if an app uses the AToB0Tag in the profile the results are * undefined unless the result is sent to the intended device, @@ -2078,7 +2087,7 @@ png_icc_check_header(png_const_structrp png_ptr, png_colorspacerp colorspace, return png_icc_profile_error(png_ptr, colorspace, name, temp, "unexpected DeviceLink ICC profile class"); - case 0x6E6D636C: /* 'nmcl' */ + case 0x6e6d636c: /* 'nmcl' */ /* A NamedColor profile is also device specific, however it doesn't * contain an AToB0 tag that is open to misinterpretation. Almost * certainly it will fail the tests below. @@ -2104,8 +2113,8 @@ png_icc_check_header(png_const_structrp png_ptr, png_colorspacerp colorspace, temp = png_get_uint_32(profile+20); switch (temp) { - case 0x58595A20: /* 'XYZ ' */ - case 0x4C616220: /* 'Lab ' */ + case 0x58595a20: /* 'XYZ ' */ + case 0x4c616220: /* 'Lab ' */ break; default: @@ -2275,8 +2284,8 @@ png_compare_ICC_profile_with_sRGB(png_const_structrp png_ptr, } /* Length *and* intent must match */ - if (length == png_sRGB_checks[i].length && - intent == png_sRGB_checks[i].intent) + if (length == (png_uint_32) png_sRGB_checks[i].length && + intent == (png_uint_32) png_sRGB_checks[i].intent) { /* Now calculate the adler32 if not done already. */ if (adler == 0) @@ -2335,7 +2344,7 @@ png_compare_ICC_profile_with_sRGB(png_const_structrp png_ptr, * Fall through to "no match". */ png_chunk_report(png_ptr, - "Not recognizing known sRGB profile that has been edited", + "Not recognizing known sRGB profile that has been edited", PNG_CHUNK_WARNING); break; # endif @@ -2843,7 +2852,7 @@ png_ascii_from_fp(png_const_structrp png_ptr, png_charp ascii, png_size_t size, if (fp >= DBL_MIN && fp <= DBL_MAX) { - int exp_b10; /* A base 10 exponent */ + int exp_b10; /* A base 10 exponent */ double base; /* 10^exp_b10 */ /* First extract a base 10 exponent of the number, @@ -2891,7 +2900,7 @@ png_ascii_from_fp(png_const_structrp png_ptr, png_charp ascii, png_size_t size, */ { - int czero, clead, cdigits; + unsigned int czero, clead, cdigits; char exponent[10]; /* Allow up to two leading zeros - this will not lengthen @@ -2921,7 +2930,7 @@ png_ascii_from_fp(png_const_structrp png_ptr, png_charp ascii, png_size_t size, * of the loop don't break the number into parts so * that the final digit is rounded. */ - if (cdigits+czero-clead+1 < (int)precision) + if (cdigits+czero+1 < precision+clead) fp = modf(fp, &d); else @@ -3027,7 +3036,7 @@ png_ascii_from_fp(png_const_structrp png_ptr, png_charp ascii, png_size_t size, *ascii++ = (char)(48 + (int)d), ++cdigits; } } - while (cdigits+czero-clead < (int)precision && fp > DBL_MIN); + while (cdigits+czero < precision+clead && fp > DBL_MIN); /* The total output count (max) is now 4+precision */ @@ -3095,7 +3104,7 @@ png_ascii_from_fp(png_const_structrp png_ptr, png_charp ascii, png_size_t size, /* Need another size check here for the exponent digits, so * this need not be considered above. */ - if ((int)size > cdigits) + if (size > cdigits) { while (cdigits > 0) *ascii++ = exponent[--cdigits]; @@ -3143,7 +3152,7 @@ png_ascii_from_fixed(png_const_structrp png_ptr, png_charp ascii, /* Avoid overflow here on the minimum integer. */ if (fp < 0) - *ascii++ = 45, --size, num = -fp; + *ascii++ = 45, num = -fp; else num = fp; @@ -3674,7 +3683,7 @@ png_exp(png_fixed_point x) if (x > 0 && x <= 0xfffff) /* Else overflow or zero (underflow) */ { /* Obtain a 4-bit approximation */ - png_uint_32 e = png_32bit_exp[(x >> 12) & 0xf]; + png_uint_32 e = png_32bit_exp[(x >> 12) & 0x0f]; /* Incorporate the low 12 bits - these decrease the returned value by * multiplying by a number less than 1 if the bit is set. The multiplier @@ -4236,7 +4245,7 @@ png_set_option(png_structrp png_ptr, int option, int onoff) * contrib/tools/makesRGB.c. The actual sRGB transfer curve defined in the * specification (see the article at http://en.wikipedia.org/wiki/SRGB) * is used, not the gamma=1/2.2 approximation use elsewhere in libpng. - * The sRGB to linear table is exact (to the nearest 16 bit linear fraction). + * The sRGB to linear table is exact (to the nearest 16-bit linear fraction). * The inverse (linear to sRGB) table has accuracies as follows: * * For all possible (255*65535+1) input values: diff --git a/thirdparty/libpng/png.h b/thirdparty/libpng/png.h index 372599bf..123201d3 100644 --- a/thirdparty/libpng/png.h +++ b/thirdparty/libpng/png.h @@ -1,9 +1,9 @@ /* png.h - header file for PNG reference library * - * libpng version 1.6.17, March 26, 2015 + * libpng version 1.6.21, January 15, 2016 * - * Copyright (c) 1998-2015 Glenn Randers-Pehrson + * Copyright (c) 1998-2002,2004,2006-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.) * @@ -11,17 +11,137 @@ * * Authors and maintainers: * libpng versions 0.71, May 1995, through 0.88, January 1996: Guy Schalnat - * libpng versions 0.89c, June 1996, through 0.96, May 1997: Andreas Dilger - * libpng versions 0.97, January 1998, through 1.6.17, March 26, 2015: Glenn + * libpng versions 0.89, June 1996, through 0.96, May 1997: Andreas Dilger + * libpng versions 0.97, January 1998, through 1.6.21, January 15, 2016: + * Glenn Randers-Pehrson. * See also "Contributing Authors", below. + */ + +/* + * COPYRIGHT NOTICE, DISCLAIMER, and LICENSE: * - * Note about libpng version numbers: + * If you modify libpng you may insert additional notices immediately following + * this sentence. * - * Due to various miscommunications, unforeseen code incompatibilities - * and occasional factors outside the authors' control, version numbering - * on the library has not always been consistent and straightforward. - * The following table summarizes matters since version 0.89c, which was - * the first widely used release: + * This code is released under the libpng license. + * + * libpng versions 1.0.7, July 1, 2000, through 1.6.21, January 15, 2016, are + * Copyright (c) 2000-2002, 2004, 2006-2016 Glenn Randers-Pehrson, are + * 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 + * + * 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. + * + * 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: + * + * 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, + * 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 + * + * libpng versions 0.5, May 1995, through 0.88, January 1996, are + * 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 + * + * 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. + * + * 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. + * + * 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. + */ + +/* + * A "png_get_copyright" function is available, for convenient use in "about" + * boxes and the like: + * + * printf("%s", png_get_copyright(NULL)); + * + * Also, the PNG logo (in PNG format, of course) is supplied in the + * files "pngbar.png" and "pngbar.jpg (88x31) and "pngnow.png" (98x31). + */ + +/* + * 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. + */ + +/* + * The contributing authors would like to thank all those who helped + * with testing, bug fixes, and patience. This wouldn't have been + * possible without all of you. + * + * Thanks to Frank J. T. Wojcik for helping with the documentation. + */ + +/* Note about libpng version numbers: + * + * Due to various miscommunications, unforeseen code incompatibilities + * and occasional factors outside the authors' control, version numbering + * on the library has not always been consistent and straightforward. + * The following table summarizes matters since version 0.89c, which was + * the first widely used release: * * source png.h png.h shared-lib * version string int version @@ -59,313 +179,48 @@ * 1.0.7beta15-18 1 10007 2.1.0.7beta15-18 (binary compatible) * 1.0.7rc1-2 1 10007 2.1.0.7rc1-2 (binary compatible) * 1.0.7 1 10007 (still compatible) - * 1.0.8beta1-4 1 10008 2.1.0.8beta1-4 - * 1.0.8rc1 1 10008 2.1.0.8rc1 - * 1.0.8 1 10008 2.1.0.8 - * 1.0.9beta1-6 1 10009 2.1.0.9beta1-6 - * 1.0.9rc1 1 10009 2.1.0.9rc1 - * 1.0.9beta7-10 1 10009 2.1.0.9beta7-10 - * 1.0.9rc2 1 10009 2.1.0.9rc2 - * 1.0.9 1 10009 2.1.0.9 - * 1.0.10beta1 1 10010 2.1.0.10beta1 - * 1.0.10rc1 1 10010 2.1.0.10rc1 - * 1.0.10 1 10010 2.1.0.10 - * 1.0.11beta1-3 1 10011 2.1.0.11beta1-3 - * 1.0.11rc1 1 10011 2.1.0.11rc1 - * 1.0.11 1 10011 2.1.0.11 - * 1.0.12beta1-2 2 10012 2.1.0.12beta1-2 - * 1.0.12rc1 2 10012 2.1.0.12rc1 - * 1.0.12 2 10012 2.1.0.12 - * 1.1.0a-f - 10100 2.1.1.0a-f (branch abandoned) - * 1.2.0beta1-2 2 10200 2.1.2.0beta1-2 - * 1.2.0beta3-5 3 10200 3.1.2.0beta3-5 - * 1.2.0rc1 3 10200 3.1.2.0rc1 - * 1.2.0 3 10200 3.1.2.0 - * 1.2.1beta1-4 3 10201 3.1.2.1beta1-4 - * 1.2.1rc1-2 3 10201 3.1.2.1rc1-2 - * 1.2.1 3 10201 3.1.2.1 - * 1.2.2beta1-6 12 10202 12.so.0.1.2.2beta1-6 - * 1.0.13beta1 10 10013 10.so.0.1.0.13beta1 - * 1.0.13rc1 10 10013 10.so.0.1.0.13rc1 - * 1.2.2rc1 12 10202 12.so.0.1.2.2rc1 - * 1.0.13 10 10013 10.so.0.1.0.13 - * 1.2.2 12 10202 12.so.0.1.2.2 - * 1.2.3rc1-6 12 10203 12.so.0.1.2.3rc1-6 - * 1.2.3 12 10203 12.so.0.1.2.3 - * 1.2.4beta1-3 13 10204 12.so.0.1.2.4beta1-3 - * 1.0.14rc1 13 10014 10.so.0.1.0.14rc1 - * 1.2.4rc1 13 10204 12.so.0.1.2.4rc1 - * 1.0.14 10 10014 10.so.0.1.0.14 - * 1.2.4 13 10204 12.so.0.1.2.4 - * 1.2.5beta1-2 13 10205 12.so.0.1.2.5beta1-2 - * 1.0.15rc1-3 10 10015 10.so.0.1.0.15rc1-3 - * 1.2.5rc1-3 13 10205 12.so.0.1.2.5rc1-3 - * 1.0.15 10 10015 10.so.0.1.0.15 - * 1.2.5 13 10205 12.so.0.1.2.5 - * 1.2.6beta1-4 13 10206 12.so.0.1.2.6beta1-4 - * 1.0.16 10 10016 10.so.0.1.0.16 - * 1.2.6 13 10206 12.so.0.1.2.6 - * 1.2.7beta1-2 13 10207 12.so.0.1.2.7beta1-2 - * 1.0.17rc1 10 10017 12.so.0.1.0.17rc1 - * 1.2.7rc1 13 10207 12.so.0.1.2.7rc1 - * 1.0.17 10 10017 12.so.0.1.0.17 - * 1.2.7 13 10207 12.so.0.1.2.7 - * 1.2.8beta1-5 13 10208 12.so.0.1.2.8beta1-5 - * 1.0.18rc1-5 10 10018 12.so.0.1.0.18rc1-5 - * 1.2.8rc1-5 13 10208 12.so.0.1.2.8rc1-5 - * 1.0.18 10 10018 12.so.0.1.0.18 - * 1.2.8 13 10208 12.so.0.1.2.8 - * 1.2.9beta1-3 13 10209 12.so.0.1.2.9beta1-3 - * 1.2.9beta4-11 13 10209 12.so.0.9[.0] - * 1.2.9rc1 13 10209 12.so.0.9[.0] - * 1.2.9 13 10209 12.so.0.9[.0] - * 1.2.10beta1-7 13 10210 12.so.0.10[.0] - * 1.2.10rc1-2 13 10210 12.so.0.10[.0] - * 1.2.10 13 10210 12.so.0.10[.0] - * 1.4.0beta1-5 14 10400 14.so.0.0[.0] - * 1.2.11beta1-4 13 10211 12.so.0.11[.0] - * 1.4.0beta7-8 14 10400 14.so.0.0[.0] - * 1.2.11 13 10211 12.so.0.11[.0] - * 1.2.12 13 10212 12.so.0.12[.0] - * 1.4.0beta9-14 14 10400 14.so.0.0[.0] - * 1.2.13 13 10213 12.so.0.13[.0] - * 1.4.0beta15-36 14 10400 14.so.0.0[.0] - * 1.4.0beta37-87 14 10400 14.so.14.0[.0] - * 1.4.0rc01 14 10400 14.so.14.0[.0] - * 1.4.0beta88-109 14 10400 14.so.14.0[.0] - * 1.4.0rc02-08 14 10400 14.so.14.0[.0] - * 1.4.0 14 10400 14.so.14.0[.0] - * 1.4.1beta01-03 14 10401 14.so.14.1[.0] - * 1.4.1rc01 14 10401 14.so.14.1[.0] - * 1.4.1beta04-12 14 10401 14.so.14.1[.0] - * 1.4.1 14 10401 14.so.14.1[.0] - * 1.4.2 14 10402 14.so.14.2[.0] - * 1.4.3 14 10403 14.so.14.3[.0] - * 1.4.4 14 10404 14.so.14.4[.0] - * 1.5.0beta01-58 15 10500 15.so.15.0[.0] - * 1.5.0rc01-07 15 10500 15.so.15.0[.0] - * 1.5.0 15 10500 15.so.15.0[.0] - * 1.5.1beta01-11 15 10501 15.so.15.1[.0] - * 1.5.1rc01-02 15 10501 15.so.15.1[.0] - * 1.5.1 15 10501 15.so.15.1[.0] - * 1.5.2beta01-03 15 10502 15.so.15.2[.0] - * 1.5.2rc01-03 15 10502 15.so.15.2[.0] - * 1.5.2 15 10502 15.so.15.2[.0] - * 1.5.3beta01-10 15 10503 15.so.15.3[.0] - * 1.5.3rc01-02 15 10503 15.so.15.3[.0] - * 1.5.3beta11 15 10503 15.so.15.3[.0] - * 1.5.3 [omitted] - * 1.5.4beta01-08 15 10504 15.so.15.4[.0] - * 1.5.4rc01 15 10504 15.so.15.4[.0] - * 1.5.4 15 10504 15.so.15.4[.0] - * 1.5.5beta01-08 15 10505 15.so.15.5[.0] - * 1.5.5rc01 15 10505 15.so.15.5[.0] - * 1.5.5 15 10505 15.so.15.5[.0] - * 1.5.6beta01-07 15 10506 15.so.15.6[.0] - * 1.5.6rc01-03 15 10506 15.so.15.6[.0] - * 1.5.6 15 10506 15.so.15.6[.0] - * 1.5.7beta01-05 15 10507 15.so.15.7[.0] - * 1.5.7rc01-03 15 10507 15.so.15.7[.0] - * 1.5.7 15 10507 15.so.15.7[.0] - * 1.6.0beta01-40 16 10600 16.so.16.0[.0] - * 1.6.0rc01-08 16 10600 16.so.16.0[.0] - * 1.6.0 16 10600 16.so.16.0[.0] - * 1.6.1beta01-09 16 10601 16.so.16.1[.0] - * 1.6.1rc01 16 10601 16.so.16.1[.0] - * 1.6.1 16 10601 16.so.16.1[.0] - * 1.6.2beta01 16 10602 16.so.16.2[.0] - * 1.6.2rc01-06 16 10602 16.so.16.2[.0] - * 1.6.2 16 10602 16.so.16.2[.0] - * 1.6.3beta01-11 16 10603 16.so.16.3[.0] - * 1.6.3rc01 16 10603 16.so.16.3[.0] - * 1.6.3 16 10603 16.so.16.3[.0] - * 1.6.4beta01-02 16 10604 16.so.16.4[.0] - * 1.6.4rc01 16 10604 16.so.16.4[.0] - * 1.6.4 16 10604 16.so.16.4[.0] - * 1.6.5 16 10605 16.so.16.5[.0] - * 1.6.6 16 10606 16.so.16.6[.0] - * 1.6.7beta01-04 16 10607 16.so.16.7[.0] - * 1.6.7rc01-03 16 10607 16.so.16.7[.0] - * 1.6.7 16 10607 16.so.16.7[.0] - * 1.6.8beta01-02 16 10608 16.so.16.8[.0] - * 1.6.8rc01-02 16 10608 16.so.16.8[.0] - * 1.6.8 16 10608 16.so.16.8[.0] - * 1.6.9beta01-04 16 10609 16.so.16.9[.0] - * 1.6.9rc01-02 16 10609 16.so.16.9[.0] - * 1.6.9 16 10609 16.so.16.9[.0] - * 1.6.10beta01-03 16 10610 16.so.16.10[.0] - * 1.6.10rc01-03 16 10610 16.so.16.10[.0] - * 1.6.10 16 10610 16.so.16.10[.0] - * 1.6.11beta01-06 16 10611 16.so.16.11[.0] - * 1.6.11rc01-02 16 10611 16.so.16.11[.0] - * 1.6.11 16 10611 16.so.16.11[.0] - * 1.6.12rc01-03 16 10612 16.so.16.12[.0] - * 1.6.12 16 10612 16.so.16.12[.0] - * 1.6.13beta01-04 16 10613 16.so.16.13[.0] - * 1.6.13rc01-02 16 10613 16.so.16.13[.0] - * 1.6.13 16 10613 16.so.16.13[.0] - * 1.6.14beta01-07 16 10614 16.so.16.14[.0] - * 1.6.14rc01-02 16 10614 16.so.16.14[.0] - * 1.6.14 16 10614 16.so.16.14[.0] - * 1.6.15beta01-08 16 10615 16.so.16.15[.0] - * 1.6.15rc01-03 16 10615 16.so.16.15[.0] - * 1.6.15 16 10615 16.so.16.15[.0] - * 1.6.16beta01-03 16 10616 16.so.16.16[.0] - * 1.6.16rc01-02 16 10616 16.so.16.16[.0] - * 1.6.16 16 10616 16.so.16.16[.0] - * 1.6.17beta01-06 16 10617 16.so.16.17[.0] - * 1.6.17rc01-06 16 10617 16.so.16.17[.0] - * 1.6.17 16 10617 16.so.16.17[.0] + * ... + * 1.0.19 10 10019 10.so.0.19[.0] + * ... + * 1.2.53 13 10253 12.so.0.53[.0] + * ... + * 1.5.23 15 10523 15.so.15.23[.0] + * ... + * 1.6.21 16 10621 16.so.16.21[.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 - * application is loaded with a different version of the library. + * Binary incompatibility exists only when applications make direct access + * to the info_ptr or png_ptr members through png.h, and the compiled + * application is loaded with a different version of the library. * - * DLLNUM will change each time there are forward or backward changes - * in binary compatibility (e.g., when a new feature is added). + * DLLNUM will change each time there are forward or backward changes + * in binary compatibility (e.g., when a new feature is added). * - * See libpng-manual.txt or libpng.3 for more information. The PNG - * specification is available as a W3C Recommendation and as an ISO - * Specification, = 0x8000 /* else this might break */ #define PNG_INFO_IDAT 0x8000 /* ESR, 1.0.6 */ +#endif /* This is used for the transformation routines, as some of them * change these values for the row. It also should enable using @@ -993,7 +855,9 @@ PNG_FUNCTION(void, (PNGCAPI *png_longjmp_ptr), PNGARG((jmp_buf, int)), typedef); #define PNG_TRANSFORM_GRAY_TO_RGB 0x2000 /* read only */ /* Added to libpng-1.5.4 */ #define PNG_TRANSFORM_EXPAND_16 0x4000 /* read only */ +#if INT_MAX >= 0x8000 /* else this might break */ #define PNG_TRANSFORM_SCALE_16 0x8000 /* read only */ +#endif /* Flags for MNG supported features */ #define PNG_FLAG_MNG_EMPTY_PLTE 0x01 @@ -1010,7 +874,7 @@ typedef PNG_CALLBACK(png_voidp, *png_malloc_ptr, (png_structp, png_alloc_size_t)); typedef PNG_CALLBACK(void, *png_free_ptr, (png_structp, png_voidp)); -/* Section 3: exported functions +/* Section 4: exported functions * Here are the function definitions most commonly used. This is not * the place to find out how to use libpng. See libpng-manual.txt for the * full explanation, see example.c for the summary. This just provides @@ -1383,13 +1247,13 @@ PNG_EXPORT(38, void, png_set_invert_alpha, (png_structrp png_ptr)); #endif #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED) -/* Add a filler byte to 8-bit Gray or 24-bit RGB images. */ +/* Add a filler byte to 8-bit or 16-bit Gray or 24-bit or 48-bit RGB images. */ PNG_EXPORT(39, void, png_set_filler, (png_structrp png_ptr, png_uint_32 filler, int flags)); /* The values of the PNG_FILLER_ defines should NOT be changed */ # define PNG_FILLER_BEFORE 0 # define PNG_FILLER_AFTER 1 -/* Add an alpha byte to 8-bit Gray or 24-bit RGB images. */ +/* Add an alpha byte to 8-bit or 16-bit Gray or 24-bit or 48-bit RGB images. */ PNG_EXPORT(40, void, png_set_add_alpha, (png_structrp png_ptr, png_uint_32 filler, int flags)); #endif /* READ_FILLER || WRITE_FILLER */ @@ -1623,35 +1487,7 @@ PNG_EXPORT(67, void, png_set_filter, (png_structrp png_ptr, int method, #define PNG_FILTER_VALUE_LAST 5 #ifdef PNG_WRITE_SUPPORTED -#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED /* EXPERIMENTAL */ -/* The "heuristic_method" is given by one of the PNG_FILTER_HEURISTIC_ - * defines, either the default (minimum-sum-of-absolute-differences), or - * the experimental method (weighted-minimum-sum-of-absolute-differences). - * - * Weights are factors >= 1.0, indicating how important it is to keep the - * filter type consistent between rows. Larger numbers mean the current - * filter is that many times as likely to be the same as the "num_weights" - * previous filters. This is cumulative for each previous row with a weight. - * There needs to be "num_weights" values in "filter_weights", or it can be - * NULL if the weights aren't being specified. Weights have no influence on - * the selection of the first row filter. Well chosen weights can (in theory) - * improve the compression for a given image. - * - * Costs are factors >= 1.0 indicating the relative decoding costs of a - * filter type. Higher costs indicate more decoding expense, and are - * therefore less likely to be selected over a filter with lower computational - * costs. There needs to be a value in "filter_costs" for each valid filter - * type (given by PNG_FILTER_VALUE_LAST), or it can be NULL if you aren't - * setting the costs. Costs try to improve the speed of decompression without - * unduly increasing the compressed image size. - * - * A negative weight or cost indicates the default value is to be used, and - * values in the range [0.0, 1.0) indicate the value is to remain unchanged. - * The default values for both weights and costs are currently 1.0, but may - * change if good general weighting/cost heuristics can be found. If both - * the weights and costs are set to 1.0, this degenerates the WEIGHTED method - * to the UNWEIGHTED method, but with added encoding time/computation. - */ +#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED /* DEPRECATED */ PNG_FP_EXPORT(68, void, png_set_filter_heuristics, (png_structrp png_ptr, int heuristic_method, int num_weights, png_const_doublep filter_weights, png_const_doublep filter_costs)) @@ -1661,9 +1497,7 @@ PNG_FIXED_EXPORT(209, void, png_set_filter_heuristics_fixed, png_const_fixed_point_p filter_costs)) #endif /* WRITE_WEIGHTED_FILTER */ -/* Heuristic used for row filter selection. These defines should NOT be - * changed. - */ +/* The following are no longer used and will be removed from libpng-1.7: */ #define PNG_FILTER_HEURISTIC_DEFAULT 0 /* Currently "UNWEIGHTED" */ #define PNG_FILTER_HEURISTIC_UNWEIGHTED 1 /* Used by libpng < 0.95 */ #define PNG_FILTER_HEURISTIC_WEIGHTED 2 /* Experimental feature */ @@ -2744,7 +2578,7 @@ PNG_EXPORT(207, void, png_save_uint_16, (png_bytep buf, unsigned int i)); # define PNG_get_int_32(buf) \ ((png_int_32)((*(buf) & 0x80) \ - ? -((png_int_32)((png_get_uint_32(buf) ^ 0xffffffffL) + 1)) \ + ? -((png_int_32)(((png_get_uint_32(buf)^0xffffffffU)+1U)&0x7fffffffU)) \ : (png_int_32)png_get_uint_32(buf))) /* If PNG_PREFIX is defined the same thing as below happens in pnglibconf.h, @@ -2764,10 +2598,17 @@ PNG_EXPORT(207, void, png_save_uint_16, (png_bytep buf, unsigned int i)); # endif #endif -#if defined(PNG_SIMPLIFIED_READ_SUPPORTED) || \ - defined(PNG_SIMPLIFIED_WRITE_SUPPORTED) +#ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED +PNG_EXPORT(242, void, png_set_check_for_invalid_index, + (png_structrp png_ptr, int allowed)); +# ifdef PNG_GET_PALETTE_MAX_SUPPORTED +PNG_EXPORT(243, int, png_get_palette_max, (png_const_structp png_ptr, + png_const_infop info_ptr)); +# endif +#endif /* CHECK_FOR_INVALID_INDEX */ + /******************************************************************************* - * SIMPLIFIED API + * Section 5: SIMPLIFIED API ******************************************************************************* * * Please read the documentation in libpng-manual.txt (TODO: write said @@ -2783,8 +2624,9 @@ PNG_EXPORT(207, void, png_save_uint_16, (png_bytep buf, unsigned int i)); * * To read a PNG file using the simplified API: * - * 1) Declare a 'png_image' structure (see below) on the stack and set the - * version field to PNG_IMAGE_VERSION. + * 1) Declare a 'png_image' structure (see below) on the stack, set the + * version field to PNG_IMAGE_VERSION and the 'opaque' pointer to NULL + * (this is REQUIRED, your program may crash if you don't do it.) * 2) Call the appropriate png_image_begin_read... function. * 3) Set the png_image 'format' member to the required sample format. * 4) Allocate a buffer for the image and, if required, the color-map. @@ -2811,6 +2653,9 @@ PNG_EXPORT(207, void, png_save_uint_16, (png_bytep buf, unsigned int i)); * when it is being read or defines the in-memory format of an image that you * need to write: */ +#if defined(PNG_SIMPLIFIED_READ_SUPPORTED) || \ + defined(PNG_SIMPLIFIED_WRITE_SUPPORTED) + #define PNG_IMAGE_VERSION 1 typedef struct png_control *png_controlp; @@ -2910,7 +2755,7 @@ typedef struct * called to read or write the color-map and set the format correctly for the * image data. Do not set the PNG_FORMAT_FLAG_COLORMAP bit directly! * - * NOTE: libpng can be built with particular features disabled, if you see + * NOTE: libpng can be built with particular features disabled. If you see * compiler errors because the definition of one of the following flags has been * compiled out it is because libpng does not have the required support. It is * possible, however, for the libpng configuration to enable the format on just @@ -2922,7 +2767,7 @@ typedef struct */ #define PNG_FORMAT_FLAG_ALPHA 0x01U /* format with an alpha channel */ #define PNG_FORMAT_FLAG_COLOR 0x02U /* color format: otherwise grayscale */ -#define PNG_FORMAT_FLAG_LINEAR 0x04U /* 2 byte channels else 1 byte */ +#define PNG_FORMAT_FLAG_LINEAR 0x04U /* 2-byte channels else 1-byte */ #define PNG_FORMAT_FLAG_COLORMAP 0x08U /* image data is color-mapped */ #ifdef PNG_FORMAT_BGR_SUPPORTED @@ -3209,9 +3054,11 @@ PNG_EXPORT(240, int, png_image_write_to_stdio, (png_imagep image, FILE *file, * * With all APIs row_stride is handled as in the read APIs - it is the spacing * from one row to the next in component sized units (1 or 2 bytes) and if - * negative indicates a bottom-up row layout in the buffer. + * negative indicates a bottom-up row layout in the buffer. If row_stride is zero, + * libpng will calculate it for you from the image width and number of channels. * - * Note that the write API does not support interlacing or sub-8-bit pixels. + * Note that the write API does not support interlacing, sub-8-bit pixels, indexed + * PNG (color_type 3) or most ancillary chunks. */ #endif /* STDIO */ #endif /* SIMPLIFIED_WRITE */ @@ -3220,17 +3067,8 @@ PNG_EXPORT(240, int, png_image_write_to_stdio, (png_imagep image, FILE *file, ******************************************************************************/ #endif /* SIMPLIFIED_{READ|WRITE} */ -#ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED -PNG_EXPORT(242, void, png_set_check_for_invalid_index, - (png_structrp png_ptr, int allowed)); -# ifdef PNG_GET_PALETTE_MAX_SUPPORTED -PNG_EXPORT(243, int, png_get_palette_max, (png_const_structp png_ptr, - png_const_infop info_ptr)); -# endif -#endif /* CHECK_FOR_INVALID_INDEX */ - /******************************************************************************* - * IMPLEMENTATION OPTIONS + * Section 6: IMPLEMENTATION OPTIONS ******************************************************************************* * * Support for arbitrary implementation-specific optimizations. The API allows diff --git a/thirdparty/libpng/pngconf.h b/thirdparty/libpng/pngconf.h index 3f9493e4..93446545 100644 --- a/thirdparty/libpng/pngconf.h +++ b/thirdparty/libpng/pngconf.h @@ -1,9 +1,9 @@ /* pngconf.h - machine configurable file for libpng * - * libpng version 1.6.17, March 26, 2015 + * libpng version 1.6.21, January 15, 2016 * - * Copyright (c) 1998-2015 Glenn Randers-Pehrson + * Copyright (c) 1998-2002,2004,2006-2015 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.) * @@ -63,7 +63,7 @@ */ #define PNG_CONST const /* backward compatibility only */ -/* This controls optimization of the reading of 16 and 32 bit values +/* 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 @@ -295,11 +295,11 @@ * table entries, so we discard it here. See the .dfn files in the * scripts directory. */ -#ifndef PNG_EXPORTA -# define PNG_EXPORTA(ordinal, type, name, args, attributes)\ - PNG_FUNCTION(PNG_EXPORT_TYPE(type),(PNGAPI name),PNGARG(args), \ - extern attributes) +#ifndef PNG_EXPORTA +# define PNG_EXPORTA(ordinal, type, name, args, attributes) \ + PNG_FUNCTION(PNG_EXPORT_TYPE(type), (PNGAPI name), PNGARG(args), \ + PNG_LINKAGE_API attributes) #endif /* ANSI-C (C90) does not permit a macro to be invoked with an empty argument, @@ -307,7 +307,7 @@ */ #define PNG_EMPTY /*empty list*/ -#define PNG_EXPORT(ordinal, type, name, args)\ +#define PNG_EXPORT(ordinal, type, name, args) \ PNG_EXPORTA(ordinal, type, name, args, PNG_EMPTY) /* Use PNG_REMOVED to comment out a removed interface. */ @@ -480,7 +480,7 @@ #if CHAR_BIT == 8 && UCHAR_MAX == 255 typedef unsigned char png_byte; #else -# error "libpng requires 8 bit bytes" +# error "libpng requires 8-bit bytes" #endif #if INT_MIN == -32768 && INT_MAX == 32767 @@ -488,7 +488,7 @@ #elif SHRT_MIN == -32768 && SHRT_MAX == 32767 typedef short png_int_16; #else -# error "libpng requires a signed 16 bit type" +# error "libpng requires a signed 16-bit type" #endif #if UINT_MAX == 65535 @@ -496,7 +496,7 @@ #elif USHRT_MAX == 65535 typedef unsigned short png_uint_16; #else -# error "libpng requires an unsigned 16 bit type" +# error "libpng requires an unsigned 16-bit type" #endif #if INT_MIN < -2147483646 && INT_MAX > 2147483646 @@ -504,7 +504,7 @@ #elif LONG_MIN < -2147483646 && LONG_MAX > 2147483646 typedef long int png_int_32; #else -# error "libpng requires a signed 32 bit (or more) type" +# error "libpng requires a signed 32-bit (or more) type" #endif #if UINT_MAX > 4294967294 @@ -512,7 +512,7 @@ #elif ULONG_MAX > 4294967294 typedef unsigned long int png_uint_32; #else -# error "libpng requires an unsigned 32 bit (or more) type" +# error "libpng requires an unsigned 32-bit (or more) type" #endif /* Prior to 1.6.0 it was possible to disable the use of size_t, 1.6.0, however, diff --git a/thirdparty/libpng/pngdebug.h b/thirdparty/libpng/pngdebug.h index 6a01b106..15a7ed0c 100644 --- a/thirdparty/libpng/pngdebug.h +++ b/thirdparty/libpng/pngdebug.h @@ -2,7 +2,7 @@ /* pngdebug.h - Debugging macros for libpng, also used in pngtest.c * * Last changed in libpng 1.6.8 [December 19, 2013] - * Copyright (c) 1998-2013 Glenn Randers-Pehrson + * 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.) * diff --git a/thirdparty/libpng/pngerror.c b/thirdparty/libpng/pngerror.c index 0781866a..6904bea1 100644 --- a/thirdparty/libpng/pngerror.c +++ b/thirdparty/libpng/pngerror.c @@ -2,7 +2,7 @@ /* pngerror.c - stub functions for i/o and memory allocation * * Last changed in libpng 1.6.15 [November 20, 2014] - * Copyright (c) 1998-2014 Glenn Randers-Pehrson + * Copyright (c) 1998-2002,2004,2006-2014 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.) * @@ -768,7 +768,7 @@ png_longjmp,(png_const_structrp png_ptr, int val),PNG_NORETURN) /* If control reaches this point, png_longjmp() must not return. The only * choice is to terminate the whole process (or maybe the thread); to do - * this the ANSI-C abort() function is used unless a different method is + * this the ANSI-C abort() function is used unless a different method is * implemented by overriding the default configuration setting for * PNG_ABORT(). */ diff --git a/thirdparty/libpng/pngget.c b/thirdparty/libpng/pngget.c index 743a6a9b..ca44982a 100644 --- a/thirdparty/libpng/pngget.c +++ b/thirdparty/libpng/pngget.c @@ -2,7 +2,7 @@ /* pngget.c - retrieval of values from info struct * * Last changed in libpng 1.6.17 [March 26, 2015] - * Copyright (c) 1998-2015 Glenn Randers-Pehrson + * Copyright (c) 1998-2002,2004,2006-2015 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.) * diff --git a/thirdparty/libpng/pnginfo.h b/thirdparty/libpng/pnginfo.h index c8c874dd..361ed8be 100644 --- a/thirdparty/libpng/pnginfo.h +++ b/thirdparty/libpng/pnginfo.h @@ -2,7 +2,7 @@ /* pnginfo.h - header file for PNG reference library * * Last changed in libpng 1.6.1 [March 28, 2013] - * Copyright (c) 1998-2013 Glenn Randers-Pehrson + * 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.) * @@ -223,7 +223,7 @@ defined(PNG_READ_BACKGROUND_SUPPORTED) /* Storage for unknown chunks that the library doesn't recognize. */ png_unknown_chunkp unknown_chunks; - /* The type of this field is limited by the type of + /* The type of this field is limited by the type of * png_struct::user_chunk_cache_max, else overflow can occur. */ int unknown_chunks_num; diff --git a/thirdparty/libpng/pngmem.c b/thirdparty/libpng/pngmem.c index 8b157e54..7bcfd005 100644 --- a/thirdparty/libpng/pngmem.c +++ b/thirdparty/libpng/pngmem.c @@ -2,7 +2,7 @@ /* pngmem.c - stub functions for memory allocation * * Last changed in libpng 1.6.15 [November 20, 2014] - * Copyright (c) 1998-2014 Glenn Randers-Pehrson + * Copyright (c) 1998-2002,2004,2006-2014 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.) * @@ -77,6 +77,9 @@ png_malloc_base,(png_const_structrp png_ptr, png_alloc_size_t size), PNG_UNUSED(png_ptr) #endif + /* Some compilers complain that this is always true. However, it + * can be false when integer overflow happens. + */ if (size > 0 && size <= PNG_SIZE_MAX # ifdef PNG_MAX_MALLOC_64K && size <= 65536U diff --git a/thirdparty/libpng/pngpread.c b/thirdparty/libpng/pngpread.c index 823dcad8..0dc1e53c 100644 --- a/thirdparty/libpng/pngpread.c +++ b/thirdparty/libpng/pngpread.c @@ -1,8 +1,8 @@ /* pngpread.c - read a png file in push mode * - * Last changed in libpng 1.6.17 [March 26, 2015] - * Copyright (c) 1998-2015 Glenn Randers-Pehrson + * Last changed in libpng 1.6.18 [July 23, 2015] + * Copyright (c) 1998-2002,2004,2006-2015 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.) * @@ -19,7 +19,6 @@ #define PNG_READ_SIG_MODE 0 #define PNG_READ_CHUNK_MODE 1 #define PNG_READ_IDAT_MODE 2 -#define PNG_SKIP_MODE 3 #define PNG_READ_tEXt_MODE 4 #define PNG_READ_zTXt_MODE 5 #define PNG_READ_DONE_MODE 6 @@ -78,32 +77,14 @@ png_process_data_pause(png_structrp png_ptr, int save) png_uint_32 PNGAPI png_process_data_skip(png_structrp png_ptr) { - png_uint_32 remaining = 0; - - if (png_ptr != NULL && png_ptr->process_mode == PNG_SKIP_MODE && - png_ptr->skip_length > 0) - { - /* At the end of png_process_data the buffer size must be 0 (see the loop - * above) so we can detect a broken call here: - */ - if (png_ptr->buffer_size != 0) - png_error(png_ptr, - "png_process_data_skip called inside png_process_data"); - - /* If is impossible for there to be a saved buffer at this point - - * otherwise we could not be in SKIP mode. This will also happen if - * png_process_skip is called inside png_process_data (but only very - * rarely.) - */ - if (png_ptr->save_buffer_size != 0) - png_error(png_ptr, "png_process_data_skip called with saved data"); - - remaining = png_ptr->skip_length; - png_ptr->skip_length = 0; - png_ptr->process_mode = PNG_READ_CHUNK_MODE; - } - - return remaining; + /* TODO: Deprecate and remove this API. + * Somewhere the implementation of this seems to have been lost, + * or abandoned. It was only to support some internal back-door access + * to png_struct) in libpng-1.4.x. + */ + png_app_warning(png_ptr, +"png_process_data_skip is not implemented in any current version of libpng"); + return 0; } /* What we do with the incoming data depends on what we were previously @@ -135,12 +116,6 @@ png_process_some_data(png_structrp png_ptr, png_inforp info_ptr) break; } - case PNG_SKIP_MODE: - { - png_push_crc_finish(png_ptr); - break; - } - default: { png_ptr->buffer_size = 0; @@ -158,8 +133,8 @@ png_process_some_data(png_structrp png_ptr, png_inforp info_ptr) void /* PRIVATE */ png_push_read_sig(png_structrp png_ptr, png_inforp info_ptr) { - png_size_t num_checked = png_ptr->sig_bytes, /* SAFE, does not exceed 8 */ - num_to_check = 8 - num_checked; + png_size_t num_checked = png_ptr->sig_bytes, /* SAFE, does not exceed 8 */ + num_to_check = 8 - num_checked; if (png_ptr->buffer_size < num_to_check) { @@ -439,69 +414,6 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr) png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER; } -void /* PRIVATE */ -png_push_crc_skip(png_structrp png_ptr, png_uint_32 skip) -{ - png_ptr->process_mode = PNG_SKIP_MODE; - png_ptr->skip_length = skip; -} - -void /* PRIVATE */ -png_push_crc_finish(png_structrp png_ptr) -{ - if (png_ptr->skip_length != 0 && png_ptr->save_buffer_size != 0) - { - png_size_t save_size = png_ptr->save_buffer_size; - png_uint_32 skip_length = png_ptr->skip_length; - - /* We want the smaller of 'skip_length' and 'save_buffer_size', but - * they are of different types and we don't know which variable has the - * fewest bits. Carefully select the smaller and cast it to the type of - * the larger - this cannot overflow. Do not cast in the following test - * - it will break on either 16 or 64 bit platforms. - */ - if (skip_length < save_size) - save_size = (png_size_t)skip_length; - - else - skip_length = (png_uint_32)save_size; - - png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size); - - png_ptr->skip_length -= skip_length; - png_ptr->buffer_size -= save_size; - png_ptr->save_buffer_size -= save_size; - png_ptr->save_buffer_ptr += save_size; - } - if (png_ptr->skip_length != 0 && png_ptr->current_buffer_size != 0) - { - png_size_t save_size = png_ptr->current_buffer_size; - png_uint_32 skip_length = png_ptr->skip_length; - - /* We want the smaller of 'skip_length' and 'current_buffer_size', here, - * the same problem exists as above and the same solution. - */ - if (skip_length < save_size) - save_size = (png_size_t)skip_length; - - else - skip_length = (png_uint_32)save_size; - - png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size); - - png_ptr->skip_length -= skip_length; - png_ptr->buffer_size -= save_size; - png_ptr->current_buffer_size -= save_size; - png_ptr->current_buffer_ptr += save_size; - } - if (png_ptr->skip_length == 0) - { - PNG_PUSH_SAVE_BUFFER_IF_LT(4) - png_crc_finish(png_ptr, 0); - png_ptr->process_mode = PNG_READ_CHUNK_MODE; - } -} - void PNGCBAPI png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length) { @@ -584,13 +496,11 @@ png_push_save_buffer(png_structrp png_ptr) if (png_ptr->save_buffer == NULL) { png_free(png_ptr, old_buffer); - old_buffer = NULL; png_error(png_ptr, "Insufficient memory for save_buffer"); } memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size); png_free(png_ptr, old_buffer); - old_buffer = NULL; png_ptr->save_buffer_max = new_max; } if (png_ptr->current_buffer_size) @@ -653,7 +563,7 @@ png_push_read_IDAT(png_structrp png_ptr) * are of different types and we don't know which variable has the fewest * bits. Carefully select the smaller and cast it to the type of the * larger - this cannot overflow. Do not cast in the following test - it - * will break on either 16 or 64 bit platforms. + * will break on either 16-bit or 64-bit platforms. */ if (idat_size < save_size) save_size = (png_size_t)idat_size; @@ -696,6 +606,7 @@ png_push_read_IDAT(png_structrp png_ptr) png_ptr->current_buffer_size -= save_size; png_ptr->current_buffer_ptr += save_size; } + if (png_ptr->idat_size == 0) { PNG_PUSH_SAVE_BUFFER_IF_LT(4) @@ -751,7 +662,7 @@ png_process_IDAT_data(png_structrp png_ptr, png_bytep buffer, * change the current behavior (see comments in inflate.c * for why this doesn't happen at present with zlib 1.2.5). */ - ret = inflate(&png_ptr->zstream, Z_SYNC_FLUSH); + ret = PNG_INFLATE(png_ptr, Z_SYNC_FLUSH); /* Check for any failure before proceeding. */ if (ret != Z_OK && ret != Z_STREAM_END) diff --git a/thirdparty/libpng/pngpriv.h b/thirdparty/libpng/pngpriv.h index 5980a3fc..1295b514 100644 --- a/thirdparty/libpng/pngpriv.h +++ b/thirdparty/libpng/pngpriv.h @@ -1,8 +1,8 @@ /* pngpriv.h - private declarations for use inside libpng * - * Last changed in libpng 1.6.17 [March 26, 2015] - * Copyright (c) 1998-2015 Glenn Randers-Pehrson + * Last changed in libpng 1.6.21 [January 15, 2016] + * Copyright (c) 1998-2002,2004,2006-2015 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.) * @@ -118,8 +118,12 @@ * to compile with an appropriate #error if ALIGNED_MEMORY has been turned * off. * - * Note that gcc-4.9 defines __ARM_NEON instead of __ARM_NEON__, so we - * check both variants. + * Note that gcc-4.9 defines __ARM_NEON instead of the deprecated + * __ARM_NEON__, so we check both variants. + * + * To disable ARM_NEON optimizations entirely, and skip compiling the + * associated assembler code, pass --enable-arm-neon=no to configure + * or put -DPNG_ARM_NEON_OPT=0 in CPPFLAGS. */ # if (defined(__ARM_NEON__) || defined(__ARM_NEON)) && \ defined(PNG_ALIGNED_MEMORY_SUPPORTED) @@ -248,17 +252,18 @@ * always be used to declare an extern data or function object in this file. */ #ifndef PNG_INTERNAL_DATA -# define PNG_INTERNAL_DATA(type, name, array) extern type name array +# define PNG_INTERNAL_DATA(type, name, array) PNG_LINKAGE_DATA type name array #endif #ifndef PNG_INTERNAL_FUNCTION # define PNG_INTERNAL_FUNCTION(type, name, args, attributes)\ - extern PNG_FUNCTION(type, name, args, PNG_EMPTY attributes) + PNG_LINKAGE_FUNCTION PNG_FUNCTION(type, name, args, PNG_EMPTY attributes) #endif #ifndef PNG_INTERNAL_CALLBACK # define PNG_INTERNAL_CALLBACK(type, name, args, attributes)\ - extern PNG_FUNCTION(type, (PNGCBAPI name), args, PNG_EMPTY attributes) + PNG_LINKAGE_CALLBACK PNG_FUNCTION(type, (PNGCBAPI name), args,\ + PNG_EMPTY attributes) #endif /* If floating or fixed point APIs are disabled they may still be compiled @@ -296,6 +301,22 @@ # define PNG_DLL_EXPORT #endif +/* This is a global switch to set the compilation for an installed system + * (a release build). It can be set for testing debug builds to ensure that + * they will compile when the build type is switched to RC or STABLE, the + * default is just to use PNG_LIBPNG_BUILD_BASE_TYPE. Set this in CPPFLAGS + * with either: + * + * -DPNG_RELEASE_BUILD Turns on the release compile path + * -DPNG_RELEASE_BUILD=0 Turns it off + * or in your pngusr.h with + * #define PNG_RELEASE_BUILD=1 Turns on the release compile path + * #define PNG_RELEASE_BUILD=0 Turns it off + */ +#ifndef PNG_RELEASE_BUILD +# define PNG_RELEASE_BUILD (PNG_LIBPNG_BUILD_BASE_TYPE >= PNG_LIBPNG_BUILD_RC) +#endif + /* SECURITY and SAFETY: * * libpng is built with support for internal limits on image dimensions and @@ -554,10 +575,6 @@ #define PNG_STRUCT_PNG 0x0001 #define PNG_STRUCT_INFO 0x0002 -/* Scaling factor for filter heuristic weighting calculations */ -#define PNG_WEIGHT_FACTOR (1<<(PNG_WEIGHT_SHIFT)) -#define PNG_COST_FACTOR (1<<(PNG_COST_SHIFT)) - /* Flags for the png_ptr->flags rather than declaring a byte for each one */ #define PNG_FLAG_ZLIB_CUSTOM_STRATEGY 0x0001 #define PNG_FLAG_ZSTREAM_INITIALIZED 0x0002 /* Added to libpng-1.6.0 */ @@ -648,7 +665,7 @@ /* The fixed point conversion performs range checking and evaluates * its argument multiple times, so must be used with care. The * range checking uses the PNG specification values for a signed - * 32 bit fixed point value except that the values are deliberately + * 32-bit fixed point value except that the values are deliberately * rounded-to-zero to an integral value - 21474 (21474.83 is roughly * (2^31-1) * 100000). 's' is a string that describes the value being * converted. @@ -795,7 +812,7 @@ */ #endif -/* This is used for 16 bit gamma tables -- only the top level pointers are +/* This is used for 16-bit gamma tables -- only the top level pointers are * const; this could be changed: */ typedef const png_uint_16p * png_const_uint_16pp; @@ -1198,6 +1215,14 @@ PNG_INTERNAL_FUNCTION(void,png_read_finish_row,(png_structrp png_ptr), /* Initialize the row buffers, etc. */ PNG_INTERNAL_FUNCTION(void,png_read_start_row,(png_structrp png_ptr),PNG_EMPTY); +#if PNG_ZLIB_VERNUM >= 0x1240 +PNG_INTERNAL_FUNCTION(int,png_zlib_inflate,(png_structrp png_ptr, int flush), + PNG_EMPTY); +# define PNG_INFLATE(pp, flush) png_zlib_inflate(pp, flush) +#else /* Zlib < 1.2.4 */ +# define PNG_INFLATE(pp, flush) inflate(&(pp)->zstream, flush) +#endif /* Zlib < 1.2.4 */ + #ifdef PNG_READ_TRANSFORMS_SUPPORTED /* Optional call to update the users info structure */ PNG_INTERNAL_FUNCTION(void,png_read_transform_info,(png_structrp png_ptr, @@ -1372,10 +1397,6 @@ PNG_INTERNAL_FUNCTION(void,png_push_read_chunk,(png_structrp png_ptr, PNG_INTERNAL_FUNCTION(void,png_push_read_sig,(png_structrp png_ptr, png_inforp info_ptr),PNG_EMPTY); PNG_INTERNAL_FUNCTION(void,png_push_check_crc,(png_structrp png_ptr),PNG_EMPTY); -PNG_INTERNAL_FUNCTION(void,png_push_crc_skip,(png_structrp png_ptr, - png_uint_32 length),PNG_EMPTY); -PNG_INTERNAL_FUNCTION(void,png_push_crc_finish,(png_structrp png_ptr), - PNG_EMPTY); PNG_INTERNAL_FUNCTION(void,png_push_save_buffer,(png_structrp png_ptr), PNG_EMPTY); PNG_INTERNAL_FUNCTION(void,png_push_restore_buffer,(png_structrp png_ptr, @@ -1896,6 +1917,9 @@ PNG_INTERNAL_FUNCTION(void, png_init_filter_functions_neon, (png_structp png_ptr, unsigned int bpp), PNG_EMPTY); #endif +PNG_INTERNAL_FUNCTION(png_uint_32, png_check_keyword, (png_structrp png_ptr, + png_const_charp key, png_bytep new_key), PNG_EMPTY); + /* Maintainer: Put new private prototypes here ^ */ #include "pngdebug.h" diff --git a/thirdparty/libpng/pngread.c b/thirdparty/libpng/pngread.c index 6764dbe5..dca3d7d5 100644 --- a/thirdparty/libpng/pngread.c +++ b/thirdparty/libpng/pngread.c @@ -2,7 +2,7 @@ /* pngread.c - read a PNG file * * Last changed in libpng 1.6.17 [March 26, 2015] - * Copyright (c) 1998-2015 Glenn Randers-Pehrson + * Copyright (c) 1998-2002,2004,2006-2015 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.) * @@ -63,7 +63,7 @@ png_create_read_struct_2,(png_const_charp user_png_ver, png_voidp error_ptr, /* In stable builds only warn if an application error can be completely * handled. */ -# if PNG_LIBPNG_BUILD_BASE_TYPE >= PNG_LIBPNG_BUILD_RC +# if PNG_RELEASE_BUILD png_ptr->flags |= PNG_FLAG_APP_WARNINGS_WARN; # endif # endif @@ -1043,9 +1043,9 @@ png_read_png(png_structrp png_ptr, png_inforp info_ptr, /* Tell libpng to strip 16-bit/color files down to 8 bits per color. */ if ((transforms & PNG_TRANSFORM_SCALE_16) != 0) - /* Added at libpng-1.5.4. "strip_16" produces the same result that it - * did in earlier versions, while "scale_16" is now more accurate. - */ + /* Added at libpng-1.5.4. "strip_16" produces the same result that it + * did in earlier versions, while "scale_16" is now more accurate. + */ #ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED png_set_scale_16(png_ptr); #else @@ -1209,7 +1209,7 @@ png_read_png(png_structrp png_ptr, png_inforp info_ptr, for (iptr = 0; iptr < info_ptr->height; iptr++) info_ptr->row_pointers[iptr] = png_voidcast(png_bytep, - png_malloc(png_ptr, info_ptr->rowbytes)); + png_malloc(png_ptr, info_ptr->rowbytes)); } png_read_image(png_ptr, info_ptr->row_pointers); @@ -1683,10 +1683,11 @@ decode_gamma(png_image_read_control *display, png_uint_32 value, int encoding) value *= 257; break; +#ifdef __GNUC__ default: png_error(display->image->opaque->png_ptr, "unexpected encoding (internal error)"); - break; +#endif } return value; @@ -2837,7 +2838,6 @@ png_image_read_colormap(png_voidp argument) default: png_error(png_ptr, "invalid PNG color type"); /*NOT REACHED*/ - break; } /* Now deal with the output processing */ @@ -2847,10 +2847,6 @@ png_image_read_colormap(png_voidp argument) switch (data_encoding) { - default: - png_error(png_ptr, "bad data option (internal error)"); - break; - case P_sRGB: /* Change to 8-bit sRGB */ png_set_alpha_mode_fixed(png_ptr, PNG_ALPHA_PNG, PNG_GAMMA_sRGB); @@ -2860,6 +2856,11 @@ png_image_read_colormap(png_voidp argument) if (png_ptr->bit_depth > 8) png_set_scale_16(png_ptr); break; + +#ifdef __GNUC__ + default: + png_error(png_ptr, "bad data option (internal error)"); +#endif } if (cmap_entries > 256 || cmap_entries > image->colormap_entries) @@ -3410,10 +3411,6 @@ png_image_read_background(png_voidp argument) */ switch (info_ptr->bit_depth) { - default: - png_error(png_ptr, "unexpected bit depth"); - break; - case 8: /* 8-bit sRGB gray values with an alpha channel; the alpha channel is * to be removed by composing on a background: either the row if @@ -3631,6 +3628,11 @@ png_image_read_background(png_voidp argument) } } break; + +#ifdef __GNUC__ + default: + png_error(png_ptr, "unexpected bit depth"); +#endif } return 1; diff --git a/thirdparty/libpng/pngrio.c b/thirdparty/libpng/pngrio.c index bb5c8251..5101d54a 100644 --- a/thirdparty/libpng/pngrio.c +++ b/thirdparty/libpng/pngrio.c @@ -2,7 +2,7 @@ /* pngrio.c - functions for data input * * Last changed in libpng 1.6.17 [March 26, 2015] - * Copyright (c) 1998-2015 Glenn Randers-Pehrson + * Copyright (c) 1998-2002,2004,2006-2015 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * @@ -26,7 +26,7 @@ * reads from a file pointer. Note that this routine sometimes gets called * with very small lengths, so you should implement some kind of simple * buffering if you are using unbuffered reads. This should never be asked - * to read more than 64K on a 16 bit machine. + * to read more than 64K on a 16-bit machine. */ void /* PRIVATE */ png_read_data(png_structrp png_ptr, png_bytep data, png_size_t length) diff --git a/thirdparty/libpng/pngrtran.c b/thirdparty/libpng/pngrtran.c index cad7a8da..e2331788 100644 --- a/thirdparty/libpng/pngrtran.c +++ b/thirdparty/libpng/pngrtran.c @@ -1,8 +1,8 @@ /* pngrtran.c - transforms the data in a row for PNG readers * - * Last changed in libpng 1.6.17 [March 26, 2015] - * Copyright (c) 1998-2015 Glenn Randers-Pehrson + * Last changed in libpng 1.6.19 [November 12, 2015] + * Copyright (c) 1998-2002,2004,2006-2015 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.) * @@ -976,7 +976,6 @@ png_set_rgb_to_gray_fixed(png_structrp png_ptr, int error_action, default: png_error(png_ptr, "invalid error action to rgb_to_gray"); - break; } if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) @@ -1997,7 +1996,7 @@ png_read_transform_info(png_structrp png_ptr, png_inforp info_ptr) # endif # else - /* No 16 bit support: force chopping 16-bit input down to 8, in this case + /* No 16-bit support: force chopping 16-bit input down to 8, in this case * the app program can chose if both APIs are available by setting the * correct scaling to use. */ @@ -2098,10 +2097,10 @@ png_read_transform_info(png_structrp png_ptr, png_inforp info_ptr) defined(PNG_READ_USER_TRANSFORM_SUPPORTED) if ((png_ptr->transformations & PNG_USER_TRANSFORM) != 0) { - if (info_ptr->bit_depth < png_ptr->user_transform_depth) + if (png_ptr->user_transform_depth != 0) info_ptr->bit_depth = png_ptr->user_transform_depth; - if (info_ptr->channels < png_ptr->user_transform_channels) + if (png_ptr->user_transform_channels != 0) info_ptr->channels = png_ptr->user_transform_channels; } #endif @@ -2382,8 +2381,8 @@ png_do_scale_16_to_8(png_row_infop row_info, png_bytep row) while (sp < ep) { - /* The input is an array of 16 bit components, these must be scaled to - * 8 bits each. For a 16 bit value V the required value (from the PNG + /* The input is an array of 16-bit components, these must be scaled to + * 8 bits each. For a 16-bit value V the required value (from the PNG * specification) is: * * (V * 255) / 65535 @@ -2404,7 +2403,7 @@ png_do_scale_16_to_8(png_row_infop row_info, png_bytep row) * * The approximate differs from the exact answer only when (vlo-vhi) is * 128; it then gives a correction of +1 when the exact correction is - * 0. This gives 128 errors. The exact answer (correct for all 16 bit + * 0. This gives 128 errors. The exact answer (correct for all 16-bit * input values) is: * * error = (vlo-vhi+128)*65535 >> 24; @@ -3148,9 +3147,9 @@ png_do_rgb_to_gray(png_structrp png_ptr, png_row_infop row_info, png_bytep row) if (red != green || red != blue) rgb_error |= 1; - /* From 1.5.5 in the 16 bit case do the accurate conversion even + /* From 1.5.5 in the 16-bit case do the accurate conversion even * in the 'fast' case - this is because this is where the code - * ends up when handling linear 16 bit data. + * ends up when handling linear 16-bit data. */ gray16 = (png_uint_16)((rc*red + gc*green + bc*blue + 16384) >> 15); @@ -3315,7 +3314,7 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr) if ((png_uint_16)((*sp >> shift) & 0x0f) == png_ptr->trans_color.gray) { - unsigned int tmp = *sp & (0xf0f >> (4 - shift)); + unsigned int tmp = *sp & (0x0f0f >> (4 - shift)); tmp |= png_ptr->background.gray << shift; *sp = (png_byte)(tmp & 0xff); } @@ -3325,7 +3324,7 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr) unsigned int p = (*sp >> shift) & 0x0f; unsigned int g = (gamma_table[p | (p << 4)] >> 4) & 0x0f; - unsigned int tmp = *sp & (0xf0f >> (4 - shift)); + unsigned int tmp = *sp & (0x0f0f >> (4 - shift)); tmp |= g << shift; *sp = (png_byte)(tmp & 0xff); } @@ -3351,7 +3350,7 @@ png_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr) if ((png_uint_16)((*sp >> shift) & 0x0f) == png_ptr->trans_color.gray) { - unsigned int tmp = *sp & (0xf0f >> (4 - shift)); + unsigned int tmp = *sp & (0x0f0f >> (4 - shift)); tmp |= png_ptr->background.gray << shift; *sp = (png_byte)(tmp & 0xff); } @@ -4460,7 +4459,7 @@ png_do_expand(png_row_infop row_info, png_bytep row, for (i = 0; i < row_width; i++) { - if (*sp == gray) + if ((*sp & 0xffU) == gray) *dp-- = 0; else @@ -4478,7 +4477,8 @@ png_do_expand(png_row_infop row_info, png_bytep row, dp = row + (row_info->rowbytes << 1) - 1; for (i = 0; i < row_width; i++) { - if (*(sp - 1) == gray_high && *(sp) == gray_low) + if ((*(sp - 1) & 0xffU) == gray_high && + (*(sp) & 0xffU) == gray_low) { *dp-- = 0; *dp-- = 0; diff --git a/thirdparty/libpng/pngrutil.c b/thirdparty/libpng/pngrutil.c index 6c5c3752..c9747fc2 100644 --- a/thirdparty/libpng/pngrutil.c +++ b/thirdparty/libpng/pngrutil.c @@ -1,8 +1,8 @@ /* pngrutil.c - utilities to read a PNG file * - * Last changed in libpng 1.6.17 [March 26, 2015] - * Copyright (c) 1998-2015 Glenn Randers-Pehrson + * Last changed in libpng 1.6.20 [December 3, 2014] + * Copyright (c) 1998-2002,2004,2006-2015 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.) * @@ -89,7 +89,13 @@ png_get_int_32)(png_const_bytep buf) return uval; uval = (uval ^ 0xffffffff) + 1; /* 2's complement: -x = ~x+1 */ - return -(png_int_32)uval; + if ((uval & 0x80000000) == 0) /* no overflow */ + return -(png_int_32)uval; + /* The following has to be safe; this function only gets called on PNG data + * and if we get here that data is invalid. 0 is the most safe value and + * if not then an attacker would surely just generate a PNG with 0 instead. + */ + return 0; } /* Grab an unsigned 16-bit integer from a buffer in big-endian format. */ @@ -98,7 +104,7 @@ png_get_uint_16)(png_const_bytep buf) { /* ANSI-C requires an int value to accomodate at least 16 bits so this * works and allows the compiler not to worry about possible narrowing - * on 32 bit systems. (Pre-ANSI systems did not make integers smaller + * on 32-bit systems. (Pre-ANSI systems did not make integers smaller * than 16 bits either.) */ unsigned int val = @@ -341,7 +347,7 @@ png_inflate_claim(png_structrp png_ptr, png_uint_32 owner) * are minimal. */ (void)png_safecat(msg, (sizeof msg), 4, " using zstream"); -#if PNG_LIBPNG_BUILD_BASE_TYPE >= PNG_LIBPNG_BUILD_RC +#if PNG_RELEASE_BUILD png_chunk_warning(png_ptr, msg); png_ptr->zowner = 0; #else @@ -371,10 +377,16 @@ png_inflate_claim(png_structrp png_ptr, png_uint_32 owner) if (((png_ptr->options >> PNG_MAXIMUM_INFLATE_WINDOW) & 3) == PNG_OPTION_ON) + { window_bits = 15; + png_ptr->zstream_start = 0; /* fixed window size */ + } else + { window_bits = 0; + png_ptr->zstream_start = 1; + } # else # define window_bits 0 # endif @@ -423,6 +435,31 @@ png_inflate_claim(png_structrp png_ptr, png_uint_32 owner) #endif } +#if PNG_ZLIB_VERNUM >= 0x1240 +/* Handle the start of the inflate stream if we called inflateInit2(strm,0); + * in this case some zlib versions skip validation of the CINFO field and, in + * certain circumstances, libpng may end up displaying an invalid image, in + * contrast to implementations that call zlib in the normal way (e.g. libpng + * 1.5). + */ +int /* PRIVATE */ +png_zlib_inflate(png_structrp png_ptr, int flush) +{ + if (png_ptr->zstream_start && png_ptr->zstream.avail_in > 0) + { + if ((*png_ptr->zstream.next_in >> 4) > 7) + { + png_ptr->zstream.msg = "invalid window size (libpng)"; + return Z_DATA_ERROR; + } + + png_ptr->zstream_start = 0; + } + + return inflate(&png_ptr->zstream, flush); +} +#endif /* Zlib >= 1.2.4 */ + #ifdef PNG_READ_COMPRESSED_TEXT_SUPPORTED /* png_inflate now returns zlib error codes including Z_OK and Z_STREAM_END to * allow the caller to do multiple calls if required. If the 'finish' flag is @@ -516,7 +553,7 @@ png_inflate(png_structrp png_ptr, png_uint_32 owner, int finish, * the previous chunk of input data. Tell zlib if we have reached the * end of the output buffer. */ - ret = inflate(&png_ptr->zstream, avail_out > 0 ? Z_NO_FLUSH : + ret = PNG_INFLATE(png_ptr, avail_out > 0 ? Z_NO_FLUSH : (finish ? Z_FINISH : Z_SYNC_FLUSH)); } while (ret == Z_OK); @@ -575,7 +612,7 @@ png_decompress_chunk(png_structrp png_ptr, */ png_alloc_size_t limit = PNG_SIZE_MAX; -# ifdef PNG_SET_CHUNK_MALLOC_LIMIT_SUPPORTED +# ifdef PNG_SET_USER_LIMITS_SUPPORTED if (png_ptr->user_chunk_malloc_max > 0 && png_ptr->user_chunk_malloc_max < limit) limit = png_ptr->user_chunk_malloc_max; @@ -670,7 +707,6 @@ png_decompress_chunk(png_structrp png_ptr, * success) */ png_free(png_ptr, text); - text = NULL; /* This really is very benign, but it's still an error because * the extra space may otherwise be used as a Trojan Horse. @@ -766,7 +802,7 @@ png_inflate_read(png_structrp png_ptr, png_bytep read_buffer, uInt read_size, * the available output is produced; this allows reading of truncated * streams. */ - ret = inflate(&png_ptr->zstream, + ret = PNG_INFLATE(png_ptr, *chunk_bytes > 0 ? Z_NO_FLUSH : (finish ? Z_FINISH : Z_SYNC_FLUSH)); } while (ret == Z_OK && (*out_size > 0 || png_ptr->zstream.avail_out > 0)); @@ -867,7 +903,7 @@ void /* PRIVATE */ png_handle_PLTE(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) { png_color palette[PNG_MAX_PALETTE_LENGTH]; - int num, i; + int max_palette_length, num, i; #ifdef PNG_POINTER_INDEXING_SUPPORTED png_colorp pal_ptr; #endif @@ -928,6 +964,19 @@ png_handle_PLTE(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) /* The cast is safe because 'length' is less than 3*PNG_MAX_PALETTE_LENGTH */ num = (int)length / 3; + /* If the palette has 256 or fewer entries but is too large for the bit + * depth, we don't issue an error, to preserve the behavior of previous + * libpng versions. We silently truncate the unused extra palette entries + * here. + */ + if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) + max_palette_length = (1 << png_ptr->bit_depth); + else + max_palette_length = PNG_MAX_PALETTE_LENGTH; + + if (num > max_palette_length) + num = max_palette_length; + #ifdef PNG_POINTER_INDEXING_SUPPORTED for (i = 0, pal_ptr = palette; i < num; i++, pal_ptr++) { @@ -960,7 +1009,7 @@ png_handle_PLTE(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) #endif { - png_crc_finish(png_ptr, 0); + png_crc_finish(png_ptr, (int) length - num * 3); } #ifndef PNG_READ_OPT_PLTE_SUPPORTED @@ -1147,11 +1196,13 @@ png_handle_sBIT(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) return; for (i=0; i sample_depth) { png_chunk_benign_error(png_ptr, "invalid"); return; } + } if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR) != 0) { @@ -1462,10 +1513,10 @@ png_handle_iCCP(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) finished = 1; # ifdef PNG_sRGB_SUPPORTED - /* Check for a match against sRGB */ - png_icc_set_sRGB(png_ptr, - &png_ptr->colorspace, profile, - png_ptr->zstream.adler); + /* Check for a match against sRGB */ + png_icc_set_sRGB(png_ptr, + &png_ptr->colorspace, profile, + png_ptr->zstream.adler); # endif /* Steal the profile for info_ptr. */ @@ -1650,7 +1701,7 @@ png_handle_sPLT(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) ++entry_start; /* A sample depth should follow the separator, and we should be on it */ - if (entry_start > buffer + length - 2) + if (length < 2U || entry_start > buffer + (length - 2U)) { png_warning(png_ptr, "malformed sPLT chunk"); return; @@ -1675,8 +1726,8 @@ png_handle_sPLT(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) if (dl > max_dl) { - png_warning(png_ptr, "sPLT chunk too long"); - return; + png_warning(png_ptr, "sPLT chunk too long"); + return; } new_palette.nentries = (png_int_32)(data_length / entry_size); @@ -1686,8 +1737,8 @@ png_handle_sPLT(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) if (new_palette.entries == NULL) { - png_warning(png_ptr, "sPLT chunk requires too much memory"); - return; + png_warning(png_ptr, "sPLT chunk requires too much memory"); + return; } #ifdef PNG_POINTER_INDEXING_SUPPORTED @@ -1817,7 +1868,8 @@ png_handle_tRNS(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) return; } - if (length > png_ptr->num_palette || length > PNG_MAX_PALETTE_LENGTH || + if (length > (unsigned int) png_ptr->num_palette || + length > (unsigned int) PNG_MAX_PALETTE_LENGTH || length == 0) { png_crc_finish(png_ptr, length); @@ -1980,7 +2032,8 @@ png_handle_hIST(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) num = length / 2 ; - if (num != png_ptr->num_palette || num > PNG_MAX_PALETTE_LENGTH) + if (num != (unsigned int) png_ptr->num_palette || + num > (unsigned int) PNG_MAX_PALETTE_LENGTH) { png_crc_finish(png_ptr, length); png_chunk_benign_error(png_ptr, "invalid"); @@ -2152,7 +2205,7 @@ png_handle_pCAL(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length) /* We need to have at least 12 bytes after the purpose string * in order to get the parameter information. */ - if (endptr <= buf + 12) + if (endptr - buf <= 12) { png_chunk_benign_error(png_ptr, "invalid"); return; @@ -2715,14 +2768,14 @@ png_cache_unknown_chunk(png_structrp png_ptr, png_uint_32 length) png_ptr->unknown_chunk.data = NULL; } -# ifdef PNG_SET_CHUNK_MALLOC_LIMIT_SUPPORTED - if (png_ptr->user_chunk_malloc_max > 0 && - png_ptr->user_chunk_malloc_max < limit) - limit = png_ptr->user_chunk_malloc_max; +# ifdef PNG_SET_USER_LIMITS_SUPPORTED + if (png_ptr->user_chunk_malloc_max > 0 && + png_ptr->user_chunk_malloc_max < limit) + limit = png_ptr->user_chunk_malloc_max; # elif PNG_USER_CHUNK_MALLOC_MAX > 0 - if (PNG_USER_CHUNK_MALLOC_MAX < limit) - limit = PNG_USER_CHUNK_MALLOC_MAX; + if (PNG_USER_CHUNK_MALLOC_MAX < limit) + limit = PNG_USER_CHUNK_MALLOC_MAX; # endif if (length <= limit) @@ -2785,7 +2838,7 @@ png_handle_unknown(png_structrp png_ptr, png_inforp info_ptr, */ # ifndef PNG_HANDLE_AS_UNKNOWN_SUPPORTED # ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED - keep = png_chunk_unknown_handling(png_ptr, png_ptr->chunk_name); + keep = png_chunk_unknown_handling(png_ptr, png_ptr->chunk_name); # endif # endif @@ -2794,153 +2847,153 @@ png_handle_unknown(png_structrp png_ptr, png_inforp info_ptr, * PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) */ # ifdef PNG_READ_USER_CHUNKS_SUPPORTED - /* The user callback takes precedence over the chunk keep value, but the - * keep value is still required to validate a save of a critical chunk. - */ - if (png_ptr->read_user_chunk_fn != NULL) + /* The user callback takes precedence over the chunk keep value, but the + * keep value is still required to validate a save of a critical chunk. + */ + if (png_ptr->read_user_chunk_fn != NULL) + { + if (png_cache_unknown_chunk(png_ptr, length) != 0) { - if (png_cache_unknown_chunk(png_ptr, length) != 0) + /* Callback to user unknown chunk handler */ + int ret = (*(png_ptr->read_user_chunk_fn))(png_ptr, + &png_ptr->unknown_chunk); + + /* ret is: + * negative: An error occurred; png_chunk_error will be called. + * zero: The chunk was not handled, the chunk will be discarded + * unless png_set_keep_unknown_chunks has been used to set + * a 'keep' behavior for this particular chunk, in which + * case that will be used. A critical chunk will cause an + * error at this point unless it is to be saved. + * positive: The chunk was handled, libpng will ignore/discard it. + */ + if (ret < 0) + png_chunk_error(png_ptr, "error in user chunk"); + + else if (ret == 0) { - /* Callback to user unknown chunk handler */ - int ret = (*(png_ptr->read_user_chunk_fn))(png_ptr, - &png_ptr->unknown_chunk); - - /* ret is: - * negative: An error occurred; png_chunk_error will be called. - * zero: The chunk was not handled, the chunk will be discarded - * unless png_set_keep_unknown_chunks has been used to set - * a 'keep' behavior for this particular chunk, in which - * case that will be used. A critical chunk will cause an - * error at this point unless it is to be saved. - * positive: The chunk was handled, libpng will ignore/discard it. + /* If the keep value is 'default' or 'never' override it, but + * still error out on critical chunks unless the keep value is + * 'always' While this is weird it is the behavior in 1.4.12. + * A possible improvement would be to obey the value set for the + * chunk, but this would be an API change that would probably + * damage some applications. + * + * The png_app_warning below catches the case that matters, where + * the application has not set specific save or ignore for this + * chunk or global save or ignore. */ - if (ret < 0) - png_chunk_error(png_ptr, "error in user chunk"); - - else if (ret == 0) + if (keep < PNG_HANDLE_CHUNK_IF_SAFE) { - /* If the keep value is 'default' or 'never' override it, but - * still error out on critical chunks unless the keep value is - * 'always' While this is weird it is the behavior in 1.4.12. - * A possible improvement would be to obey the value set for the - * chunk, but this would be an API change that would probably - * damage some applications. - * - * The png_app_warning below catches the case that matters, where - * the application has not set specific save or ignore for this - * chunk or global save or ignore. - */ - if (keep < PNG_HANDLE_CHUNK_IF_SAFE) +# ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED + if (png_ptr->unknown_default < PNG_HANDLE_CHUNK_IF_SAFE) { -# ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED - if (png_ptr->unknown_default < PNG_HANDLE_CHUNK_IF_SAFE) - { - png_chunk_warning(png_ptr, "Saving unknown chunk:"); - png_app_warning(png_ptr, - "forcing save of an unhandled chunk;" - " please call png_set_keep_unknown_chunks"); - /* with keep = PNG_HANDLE_CHUNK_IF_SAFE */ - } -# endif - keep = PNG_HANDLE_CHUNK_IF_SAFE; + png_chunk_warning(png_ptr, "Saving unknown chunk:"); + png_app_warning(png_ptr, + "forcing save of an unhandled chunk;" + " please call png_set_keep_unknown_chunks"); + /* with keep = PNG_HANDLE_CHUNK_IF_SAFE */ } - } - - else /* chunk was handled */ - { - handled = 1; - /* Critical chunks can be safely discarded at this point. */ - keep = PNG_HANDLE_CHUNK_NEVER; +# endif + keep = PNG_HANDLE_CHUNK_IF_SAFE; } } - else - keep = PNG_HANDLE_CHUNK_NEVER; /* insufficient memory */ + else /* chunk was handled */ + { + handled = 1; + /* Critical chunks can be safely discarded at this point. */ + keep = PNG_HANDLE_CHUNK_NEVER; + } } else - /* Use the SAVE_UNKNOWN_CHUNKS code or skip the chunk */ + keep = PNG_HANDLE_CHUNK_NEVER; /* insufficient memory */ + } + + else + /* Use the SAVE_UNKNOWN_CHUNKS code or skip the chunk */ # endif /* READ_USER_CHUNKS */ # ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED + { + /* keep is currently just the per-chunk setting, if there was no + * setting change it to the global default now (not that this may + * still be AS_DEFAULT) then obtain the cache of the chunk if required, + * if not simply skip the chunk. + */ + if (keep == PNG_HANDLE_CHUNK_AS_DEFAULT) + keep = png_ptr->unknown_default; + + if (keep == PNG_HANDLE_CHUNK_ALWAYS || + (keep == PNG_HANDLE_CHUNK_IF_SAFE && + PNG_CHUNK_ANCILLARY(png_ptr->chunk_name))) { - /* keep is currently just the per-chunk setting, if there was no - * setting change it to the global default now (not that this may - * still be AS_DEFAULT) then obtain the cache of the chunk if required, - * if not simply skip the chunk. - */ - if (keep == PNG_HANDLE_CHUNK_AS_DEFAULT) - keep = png_ptr->unknown_default; - - if (keep == PNG_HANDLE_CHUNK_ALWAYS || - (keep == PNG_HANDLE_CHUNK_IF_SAFE && - PNG_CHUNK_ANCILLARY(png_ptr->chunk_name))) - { - if (png_cache_unknown_chunk(png_ptr, length) == 0) - keep = PNG_HANDLE_CHUNK_NEVER; - } - - else - png_crc_finish(png_ptr, length); + if (png_cache_unknown_chunk(png_ptr, length) == 0) + keep = PNG_HANDLE_CHUNK_NEVER; } + + else + png_crc_finish(png_ptr, length); + } # else # ifndef PNG_READ_USER_CHUNKS_SUPPORTED # error no method to support READ_UNKNOWN_CHUNKS # endif - { - /* If here there is no read callback pointer set and no support is - * compiled in to just save the unknown chunks, so simply skip this - * chunk. If 'keep' is something other than AS_DEFAULT or NEVER then - * the app has erroneously asked for unknown chunk saving when there - * is no support. - */ - if (keep > PNG_HANDLE_CHUNK_NEVER) - png_app_error(png_ptr, "no unknown chunk support available"); + { + /* If here there is no read callback pointer set and no support is + * compiled in to just save the unknown chunks, so simply skip this + * chunk. If 'keep' is something other than AS_DEFAULT or NEVER then + * the app has erroneously asked for unknown chunk saving when there + * is no support. + */ + if (keep > PNG_HANDLE_CHUNK_NEVER) + png_app_error(png_ptr, "no unknown chunk support available"); - png_crc_finish(png_ptr, length); - } + png_crc_finish(png_ptr, length); + } # endif # ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED - /* Now store the chunk in the chunk list if appropriate, and if the limits - * permit it. - */ - if (keep == PNG_HANDLE_CHUNK_ALWAYS || - (keep == PNG_HANDLE_CHUNK_IF_SAFE && - PNG_CHUNK_ANCILLARY(png_ptr->chunk_name))) + /* Now store the chunk in the chunk list if appropriate, and if the limits + * permit it. + */ + if (keep == PNG_HANDLE_CHUNK_ALWAYS || + (keep == PNG_HANDLE_CHUNK_IF_SAFE && + PNG_CHUNK_ANCILLARY(png_ptr->chunk_name))) + { +# ifdef PNG_USER_LIMITS_SUPPORTED + switch (png_ptr->user_chunk_cache_max) { -# ifdef PNG_USER_LIMITS_SUPPORTED - switch (png_ptr->user_chunk_cache_max) - { - case 2: - png_ptr->user_chunk_cache_max = 1; - png_chunk_benign_error(png_ptr, "no space in chunk cache"); - /* FALL THROUGH */ - case 1: - /* NOTE: prior to 1.6.0 this case resulted in an unknown critical - * chunk being skipped, now there will be a hard error below. - */ - break; + case 2: + png_ptr->user_chunk_cache_max = 1; + png_chunk_benign_error(png_ptr, "no space in chunk cache"); + /* FALL THROUGH */ + case 1: + /* NOTE: prior to 1.6.0 this case resulted in an unknown critical + * chunk being skipped, now there will be a hard error below. + */ + break; - default: /* not at limit */ - --(png_ptr->user_chunk_cache_max); - /* FALL THROUGH */ - case 0: /* no limit */ -# endif /* USER_LIMITS */ - /* Here when the limit isn't reached or when limits are compiled - * out; store the chunk. - */ - png_set_unknown_chunks(png_ptr, info_ptr, - &png_ptr->unknown_chunk, 1); - handled = 1; -# ifdef PNG_USER_LIMITS_SUPPORTED - break; - } -# endif + default: /* not at limit */ + --(png_ptr->user_chunk_cache_max); + /* FALL THROUGH */ + case 0: /* no limit */ +# endif /* USER_LIMITS */ + /* Here when the limit isn't reached or when limits are compiled + * out; store the chunk. + */ + png_set_unknown_chunks(png_ptr, info_ptr, + &png_ptr->unknown_chunk, 1); + handled = 1; +# ifdef PNG_USER_LIMITS_SUPPORTED + break; } +# endif + } # else /* no store support: the chunk must be handled by the user callback */ - PNG_UNUSED(info_ptr) + PNG_UNUSED(info_ptr) # endif /* Regardless of the error handling below the cached data (if any) can be @@ -3042,13 +3095,13 @@ png_combine_row(png_const_structrp png_ptr, png_bytep dp, int display) end_ptr = dp + PNG_ROWBYTES(pixel_depth, row_width) - 1; end_byte = *end_ptr; # ifdef PNG_READ_PACKSWAP_SUPPORTED - if ((png_ptr->transformations & PNG_PACKSWAP) != 0) - /* little-endian byte */ - end_mask = 0xff << end_mask; + if ((png_ptr->transformations & PNG_PACKSWAP) != 0) + /* little-endian byte */ + end_mask = 0xff << end_mask; - else /* big-endian byte */ + else /* big-endian byte */ # endif - end_mask = 0xff >> end_mask; + end_mask = 0xff >> end_mask; /* end_mask is now the bits to *keep* from the destination row */ } @@ -3206,12 +3259,12 @@ png_combine_row(png_const_structrp png_ptr, png_bytep dp, int display) png_uint_32 mask; # ifdef PNG_READ_PACKSWAP_SUPPORTED - if ((png_ptr->transformations & PNG_PACKSWAP) != 0) - mask = MASK(pass, pixel_depth, display, 0); + if ((png_ptr->transformations & PNG_PACKSWAP) != 0) + mask = MASK(pass, pixel_depth, display, 0); - else + else # endif - mask = MASK(pass, pixel_depth, display, 1); + mask = MASK(pass, pixel_depth, display, 1); for (;;) { @@ -3812,15 +3865,15 @@ png_read_filter_row_paeth_1byte_pixel(png_row_infop row_info, png_bytep row, p = b - c; pc = a - c; -# ifdef PNG_USE_ABS - pa = abs(p); - pb = abs(pc); - pc = abs(p + pc); -# else - pa = p < 0 ? -p : p; - pb = pc < 0 ? -pc : pc; - pc = (p + pc) < 0 ? -(p + pc) : p + pc; -# endif +#ifdef PNG_USE_ABS + pa = abs(p); + pb = abs(pc); + pc = abs(p + pc); +#else + pa = p < 0 ? -p : p; + pb = pc < 0 ? -pc : pc; + pc = (p + pc) < 0 ? -(p + pc) : p + pc; +#endif /* Find the best predictor, the least of pa, pb, pc favoring the earlier * ones in the case of a tie. @@ -3867,15 +3920,15 @@ png_read_filter_row_paeth_multibyte_pixel(png_row_infop row_info, png_bytep row, p = b - c; pc = a - c; -# ifdef PNG_USE_ABS - pa = abs(p); - pb = abs(pc); - pc = abs(p + pc); -# else - pa = p < 0 ? -p : p; - pb = pc < 0 ? -pc : pc; - pc = (p + pc) < 0 ? -(p + pc) : p + pc; -# endif +#ifdef PNG_USE_ABS + pa = abs(p); + pb = abs(pc); + pc = abs(p + pc); +#else + pa = p < 0 ? -p : p; + pb = pc < 0 ? -pc : pc; + pc = (p + pc) < 0 ? -(p + pc) : p + pc; +#endif if (pb < pa) pa = pb, a = b; if (pc < pa) a = c; @@ -4017,7 +4070,7 @@ png_read_IDAT_data(png_structrp png_ptr, png_bytep output, * * TODO: deal more elegantly with truncated IDAT lists. */ - ret = inflate(&png_ptr->zstream, Z_NO_FLUSH); + ret = PNG_INFLATE(png_ptr, Z_NO_FLUSH); /* Take the unconsumed output back. */ if (output != NULL) @@ -4280,18 +4333,18 @@ png_read_start_row(png_structrp png_ptr) #ifdef PNG_READ_EXPAND_16_SUPPORTED if ((png_ptr->transformations & PNG_EXPAND_16) != 0) { -# ifdef PNG_READ_EXPAND_SUPPORTED - /* In fact it is an error if it isn't supported, but checking is - * the safe way. - */ - if ((png_ptr->transformations & PNG_EXPAND) != 0) - { - if (png_ptr->bit_depth < 16) - max_pixel_depth *= 2; - } - else -# endif - png_ptr->transformations &= ~PNG_EXPAND_16; +# ifdef PNG_READ_EXPAND_SUPPORTED + /* In fact it is an error if it isn't supported, but checking is + * the safe way. + */ + if ((png_ptr->transformations & PNG_EXPAND) != 0) + { + if (png_ptr->bit_depth < 16) + max_pixel_depth *= 2; + } + else +# endif + png_ptr->transformations &= ~PNG_EXPAND_16; } #endif diff --git a/thirdparty/libpng/pngset.c b/thirdparty/libpng/pngset.c index fce30391..4bd5ab3c 100644 --- a/thirdparty/libpng/pngset.c +++ b/thirdparty/libpng/pngset.c @@ -1,7 +1,7 @@ /* pngset.c - storage of image information into info struct * - * Last changed in libpng 1.6.17 [March 26, 2015] + * Last changed in libpng 1.6.21 [January 15, 2016] * Copyright (c) 1998-2015 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.) @@ -123,12 +123,12 @@ png_set_cHRM_XYZ(png_const_structrp png_ptr, png_inforp info_ptr, double red_X, png_fixed(png_ptr, red_X, "cHRM Red X"), png_fixed(png_ptr, red_Y, "cHRM Red Y"), png_fixed(png_ptr, red_Z, "cHRM Red Z"), - png_fixed(png_ptr, green_X, "cHRM Red X"), - png_fixed(png_ptr, green_Y, "cHRM Red Y"), - png_fixed(png_ptr, green_Z, "cHRM Red Z"), - png_fixed(png_ptr, blue_X, "cHRM Red X"), - png_fixed(png_ptr, blue_Y, "cHRM Red Y"), - png_fixed(png_ptr, blue_Z, "cHRM Red Z")); + png_fixed(png_ptr, green_X, "cHRM Green X"), + png_fixed(png_ptr, green_Y, "cHRM Green Y"), + png_fixed(png_ptr, green_Z, "cHRM Green Z"), + png_fixed(png_ptr, blue_X, "cHRM Blue X"), + png_fixed(png_ptr, blue_Y, "cHRM Blue Y"), + png_fixed(png_ptr, blue_Z, "cHRM Blue Z")); } # endif /* FLOATING_POINT */ @@ -513,12 +513,17 @@ png_set_PLTE(png_structrp png_ptr, png_inforp info_ptr, png_const_colorp palette, int num_palette) { + png_uint_32 max_palette_length; + png_debug1(1, "in %s storage function", "PLTE"); if (png_ptr == NULL || info_ptr == NULL) return; - if (num_palette < 0 || num_palette > PNG_MAX_PALETTE_LENGTH) + max_palette_length = (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ? + (1 << info_ptr->bit_depth) : PNG_MAX_PALETTE_LENGTH; + + if (num_palette < 0 || num_palette > (int) max_palette_length) { if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) png_error(png_ptr, "Invalid palette length"); @@ -551,8 +556,8 @@ png_set_PLTE(png_structrp png_ptr, png_inforp info_ptr, png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0); /* Changed in libpng-1.2.1 to allocate PNG_MAX_PALETTE_LENGTH instead - * of num_palette entries, in case of an invalid PNG file that has - * too-large sample values. + * of num_palette entries, in case of an invalid PNG file or incorrect + * call to png_set_PLTE() with too-large sample values. */ png_ptr->palette = png_voidcast(png_colorp, png_calloc(png_ptr, PNG_MAX_PALETTE_LENGTH * (sizeof (png_color)))); @@ -673,7 +678,6 @@ png_set_iCCP(png_const_structrp png_ptr, png_inforp info_ptr, if (new_iccp_profile == NULL) { png_free(png_ptr, new_iccp_name); - new_iccp_name = NULL; png_benign_error(png_ptr, "Insufficient memory to process iCCP profile"); @@ -710,7 +714,7 @@ png_set_text_2(png_const_structrp png_ptr, png_inforp info_ptr, { int i; - png_debug1(1, "in %lx storage function", png_ptr == NULL ? "unexpected" : + png_debug1(1, "in %lx storage function", png_ptr == NULL ? 0xabadca11U : (unsigned long)png_ptr->chunk_name); if (png_ptr == NULL || info_ptr == NULL || num_text <= 0 || text_ptr == NULL) @@ -1522,6 +1526,9 @@ png_set_compression_buffer_size(png_structrp png_ptr, png_size_t size) } #ifndef __COVERITY__ + /* Some compilers complain that this is always false. However, it + * can be true when integer overflow happens. + */ if (size > ZLIB_IO_MAX) { png_warning(png_ptr, @@ -1566,7 +1573,7 @@ png_set_user_limits (png_structrp png_ptr, png_uint_32 user_width_max, { /* Images with dimensions larger than these limits will be * rejected by png_set_IHDR(). To accept any PNG datastream - * regardless of dimensions, set both limits to 0x7ffffffL. + * regardless of dimensions, set both limits to 0x7fffffff. */ if (png_ptr == NULL) return; @@ -1637,4 +1644,88 @@ png_set_check_for_invalid_index(png_structrp png_ptr, int allowed) png_ptr->num_palette_max = -1; } #endif + +#if defined(PNG_TEXT_SUPPORTED) || defined(PNG_pCAL_SUPPORTED) || \ + defined(PNG_iCCP_SUPPORTED) || defined(PNG_sPLT_SUPPORTED) +/* Check that the tEXt or zTXt keyword is valid per PNG 1.0 specification, + * and if invalid, correct the keyword rather than discarding the entire + * chunk. The PNG 1.0 specification requires keywords 1-79 characters in + * length, forbids leading or trailing whitespace, multiple internal spaces, + * and the non-break space (0x80) from ISO 8859-1. Returns keyword length. + * + * The 'new_key' buffer must be 80 characters in size (for the keyword plus a + * trailing '\0'). If this routine returns 0 then there was no keyword, or a + * valid one could not be generated, and the caller must png_error. + */ +png_uint_32 /* PRIVATE */ +png_check_keyword(png_structrp png_ptr, png_const_charp key, png_bytep new_key) +{ + png_const_charp orig_key = key; + png_uint_32 key_len = 0; + int bad_character = 0; + int space = 1; + + png_debug(1, "in png_check_keyword"); + + if (key == NULL) + { + *new_key = 0; + return 0; + } + + while (*key && key_len < 79) + { + png_byte ch = (png_byte)*key++; + + if ((ch > 32 && ch <= 126) || (ch >= 161 /*&& ch <= 255*/)) + *new_key++ = ch, ++key_len, space = 0; + + else if (space == 0) + { + /* A space or an invalid character when one wasn't seen immediately + * before; output just a space. + */ + *new_key++ = 32, ++key_len, space = 1; + + /* If the character was not a space then it is invalid. */ + if (ch != 32) + bad_character = ch; + } + + else if (bad_character == 0) + bad_character = ch; /* just skip it, record the first error */ + } + + if (key_len > 0 && space != 0) /* trailing space */ + { + --key_len, --new_key; + if (bad_character == 0) + bad_character = 32; + } + + /* Terminate the keyword */ + *new_key = 0; + + if (key_len == 0) + return 0; + +#ifdef PNG_WARNINGS_SUPPORTED + /* Try to only output one warning per keyword: */ + if (*key != 0) /* keyword too long */ + png_warning(png_ptr, "keyword truncated"); + + else if (bad_character != 0) + { + PNG_WARNING_PARAMETERS(p) + + png_warning_parameter(p, 1, orig_key); + png_warning_parameter_signed(p, 2, PNG_NUMBER_FORMAT_02x, bad_character); + + png_formatted_warning(png_ptr, p, "keyword \"@1\": bad character '0x@2'"); + } +#endif /* WARNINGS */ + + return key_len; +} +#endif /* TEXT || pCAL || iCCP || sPLT */ #endif /* READ || WRITE */ diff --git a/thirdparty/libpng/pngstruct.h b/thirdparty/libpng/pngstruct.h index 8420d099..c1f35ede 100644 --- a/thirdparty/libpng/pngstruct.h +++ b/thirdparty/libpng/pngstruct.h @@ -1,8 +1,8 @@ /* pngstruct.h - header file for PNG reference library * - * Last changed in libpng 1.6.1 [March 28, 2013] - * Copyright (c) 1998-2013 Glenn Randers-Pehrson + * Last changed in libpng 1.6.18 [July 23, 2015] + * Copyright (c) 1998-2002,2004,2006-2015 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.) * @@ -219,16 +219,18 @@ struct png_struct_def png_uint_32 row_number; /* current row in interlace pass */ png_uint_32 chunk_name; /* PNG_CHUNK() id of current chunk */ png_bytep prev_row; /* buffer to save previous (unfiltered) row. - * This is a pointer into big_prev_row + * While reading this is a pointer into + * big_prev_row; while writing it is separately + * allocated if needed. */ png_bytep row_buf; /* buffer to save current (unfiltered) row. - * This is a pointer into big_row_buf + * While reading, this is a pointer into + * big_row_buf; while writing it is separately + * allocated. */ -#ifdef PNG_WRITE_SUPPORTED - png_bytep sub_row; /* buffer to save "sub" row when filtering */ - png_bytep up_row; /* buffer to save "up" row when filtering */ - png_bytep avg_row; /* buffer to save "avg" row when filtering */ - png_bytep paeth_row; /* buffer to save "Paeth" row when filtering */ +#ifdef PNG_WRITE_FILTER_SUPPORTED + png_bytep try_row; /* buffer to save trial row when filtering */ + png_bytep tst_row; /* buffer to save best trial row when filtering */ #endif png_size_t info_rowbytes; /* Added in 1.5.4: cache of updated row bytes */ @@ -261,6 +263,9 @@ struct png_struct_def /* pixel depth used for the row buffers */ png_byte transformed_pixel_depth; /* pixel depth after read/write transforms */ +#if PNG_ZLIB_VERNUM >= 0x1240 + png_byte zstream_start; /* at start of an input zlib stream */ +#endif /* Zlib >= 1.2.4 */ #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED) png_uint_16 filler; /* filler bytes for pixel expansion */ #endif @@ -346,17 +351,7 @@ struct png_struct_def png_bytep quantize_index; /* index translation for palette files */ #endif -#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED - png_byte heuristic_method; /* heuristic for row filter selection */ - png_byte num_prev_filters; /* number of weights for previous rows */ - png_bytep prev_filters; /* filter type(s) of previous row(s) */ - png_uint_16p filter_weights; /* weight(s) for previous line(s) */ - png_uint_16p inv_filter_weights; /* 1/weight(s) for previous line(s) */ - png_uint_16p filter_costs; /* relative filter calculation cost */ - png_uint_16p inv_filter_costs; /* 1/relative filter calculation cost */ -#endif - - /* Options */ +/* Options */ #ifdef PNG_SET_OPTION_SUPPORTED png_byte options; /* On/off state (up to 4 options) */ #endif diff --git a/thirdparty/libpng/pngtrans.c b/thirdparty/libpng/pngtrans.c index cd3a79b6..7f8cc455 100644 --- a/thirdparty/libpng/pngtrans.c +++ b/thirdparty/libpng/pngtrans.c @@ -1,8 +1,8 @@ /* pngtrans.c - transforms the data in a row (used by both readers and writers) * - * Last changed in libpng 1.6.17 [March 26, 2015] - * Copyright (c) 1998-2015 Glenn Randers-Pehrson + * Last changed in libpng 1.6.18 [July 23, 2015] + * Copyright (c) 1998-2002,2004,2006-2015 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * @@ -30,7 +30,7 @@ png_set_bgr(png_structrp png_ptr) #endif #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED) -/* Turn on 16 bit byte swapping */ +/* Turn on 16-bit byte swapping */ void PNGAPI png_set_swap(png_structrp png_ptr) { @@ -313,7 +313,7 @@ png_do_invert(png_row_infop row_info, png_bytep row) #ifdef PNG_16BIT_SUPPORTED #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED) -/* Swaps byte order on 16 bit depth images */ +/* Swaps byte order on 16-bit depth images */ void /* PRIVATE */ png_do_swap(png_row_infop row_info, png_bytep row) { @@ -704,7 +704,7 @@ png_do_check_palette_indexes(png_structrp png_ptr, png_row_infop row_info) */ for (; rp > png_ptr->row_buf; rp--) { - if (*rp >> padding != 0) + if ((*rp >> padding) != 0) png_ptr->num_palette_max = 1; padding = 0; } diff --git a/thirdparty/libpng/pngwio.c b/thirdparty/libpng/pngwio.c index 0a40948a..586c03b7 100644 --- a/thirdparty/libpng/pngwio.c +++ b/thirdparty/libpng/pngwio.c @@ -2,7 +2,7 @@ /* pngwio.c - functions for data output * * Last changed in libpng 1.6.15 [November 20, 2014] - * Copyright (c) 1998-2014 Glenn Randers-Pehrson + * Copyright (c) 1998-2002,2004,2006-2014 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * @@ -26,7 +26,7 @@ * writes to a file pointer. Note that this routine sometimes gets called * with very small lengths, so you should implement some kind of simple * buffering if you are using unbuffered writes. This should never be asked - * to write more than 64K on a 16 bit machine. + * to write more than 64K on a 16-bit machine. */ void /* PRIVATE */ diff --git a/thirdparty/libpng/pngwrite.c b/thirdparty/libpng/pngwrite.c index e3c20349..f843796b 100644 --- a/thirdparty/libpng/pngwrite.c +++ b/thirdparty/libpng/pngwrite.c @@ -1,8 +1,8 @@ /* pngwrite.c - general routines to write a PNG file * - * Last changed in libpng 1.6.17 [March 26, 2015] - * Copyright (c) 1998-2015 Glenn Randers-Pehrson + * Last changed in libpng 1.6.19 [November 12, 2015] + * Copyright (c) 1998-2002,2004,2006-2015 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.) * @@ -90,43 +90,44 @@ png_write_info_before_PLTE(png_structrp png_ptr, png_const_inforp info_ptr) if ((png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE) == 0) { - /* Write PNG signature */ - png_write_sig(png_ptr); + /* Write PNG signature */ + png_write_sig(png_ptr); #ifdef PNG_MNG_FEATURES_SUPPORTED - if ((png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) != 0 && \ - png_ptr->mng_features_permitted != 0) - { - png_warning(png_ptr, "MNG features are not allowed in a PNG datastream"); - png_ptr->mng_features_permitted = 0; - } + if ((png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) != 0 && \ + png_ptr->mng_features_permitted != 0) + { + png_warning(png_ptr, + "MNG features are not allowed in a PNG datastream"); + png_ptr->mng_features_permitted = 0; + } #endif - /* Write IHDR information. */ - png_write_IHDR(png_ptr, info_ptr->width, info_ptr->height, - info_ptr->bit_depth, info_ptr->color_type, info_ptr->compression_type, - info_ptr->filter_type, + /* Write IHDR information. */ + png_write_IHDR(png_ptr, info_ptr->width, info_ptr->height, + info_ptr->bit_depth, info_ptr->color_type, info_ptr->compression_type, + info_ptr->filter_type, #ifdef PNG_WRITE_INTERLACING_SUPPORTED - info_ptr->interlace_type + info_ptr->interlace_type #else - 0 + 0 #endif - ); + ); - /* The rest of these check to see if the valid field has the appropriate - * flag set, and if it does, writes the chunk. - * - * 1.6.0: COLORSPACE support controls the writing of these chunks too, and - * the chunks will be written if the WRITE routine is there and information - * is available in the COLORSPACE. (See png_colorspace_sync_info in png.c - * for where the valid flags get set.) - * - * Under certain circumstances the colorspace can be invalidated without - * syncing the info_struct 'valid' flags; this happens if libpng detects and - * error and calls png_error while the color space is being set, yet the - * application continues writing the PNG. So check the 'invalid' flag here - * too. - */ + /* The rest of these check to see if the valid field has the appropriate + * flag set, and if it does, writes the chunk. + * + * 1.6.0: COLORSPACE support controls the writing of these chunks too, and + * the chunks will be written if the WRITE routine is there and + * information * is available in the COLORSPACE. (See + * png_colorspace_sync_info in png.c for where the valid flags get set.) + * + * Under certain circumstances the colorspace can be invalidated without + * syncing the info_struct 'valid' flags; this happens if libpng detects + * an error and calls png_error while the color space is being set, yet + * the application continues writing the PNG. So check the 'invalid' + * flag here too. + */ #ifdef PNG_GAMMA_SUPPORTED # ifdef PNG_WRITE_gAMA_SUPPORTED if ((info_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) == 0 && @@ -137,50 +138,50 @@ png_write_info_before_PLTE(png_structrp png_ptr, png_const_inforp info_ptr) #endif #ifdef PNG_COLORSPACE_SUPPORTED - /* Write only one of sRGB or an ICC profile. If a profile was supplied - * and it matches one of the known sRGB ones issue a warning. - */ + /* Write only one of sRGB or an ICC profile. If a profile was supplied + * and it matches one of the known sRGB ones issue a warning. + */ # ifdef PNG_WRITE_iCCP_SUPPORTED - if ((info_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) == 0 && - (info_ptr->valid & PNG_INFO_iCCP) != 0) - { -# ifdef PNG_WRITE_sRGB_SUPPORTED - if ((info_ptr->valid & PNG_INFO_sRGB) != 0) - png_app_warning(png_ptr, - "profile matches sRGB but writing iCCP instead"); -# endif + if ((info_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) == 0 && + (info_ptr->valid & PNG_INFO_iCCP) != 0) + { +# ifdef PNG_WRITE_sRGB_SUPPORTED + if ((info_ptr->valid & PNG_INFO_sRGB) != 0) + png_app_warning(png_ptr, + "profile matches sRGB but writing iCCP instead"); +# endif - png_write_iCCP(png_ptr, info_ptr->iccp_name, - info_ptr->iccp_profile); - } + png_write_iCCP(png_ptr, info_ptr->iccp_name, + info_ptr->iccp_profile); + } # ifdef PNG_WRITE_sRGB_SUPPORTED else # endif # endif # ifdef PNG_WRITE_sRGB_SUPPORTED - if ((info_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) == 0 && - (info_ptr->valid & PNG_INFO_sRGB) != 0) - png_write_sRGB(png_ptr, info_ptr->colorspace.rendering_intent); + if ((info_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) == 0 && + (info_ptr->valid & PNG_INFO_sRGB) != 0) + png_write_sRGB(png_ptr, info_ptr->colorspace.rendering_intent); # endif /* WRITE_sRGB */ #endif /* COLORSPACE */ #ifdef PNG_WRITE_sBIT_SUPPORTED - if ((info_ptr->valid & PNG_INFO_sBIT) != 0) - png_write_sBIT(png_ptr, &(info_ptr->sig_bit), info_ptr->color_type); + if ((info_ptr->valid & PNG_INFO_sBIT) != 0) + png_write_sBIT(png_ptr, &(info_ptr->sig_bit), info_ptr->color_type); #endif #ifdef PNG_COLORSPACE_SUPPORTED # ifdef PNG_WRITE_cHRM_SUPPORTED - if ((info_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) == 0 && - (info_ptr->colorspace.flags & PNG_COLORSPACE_FROM_cHRM) != 0 && - (info_ptr->valid & PNG_INFO_cHRM) != 0) - png_write_cHRM_fixed(png_ptr, &info_ptr->colorspace.end_points_xy); + if ((info_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) == 0 && + (info_ptr->colorspace.flags & PNG_COLORSPACE_FROM_cHRM) != 0 && + (info_ptr->valid & PNG_INFO_cHRM) != 0) + png_write_cHRM_fixed(png_ptr, &info_ptr->colorspace.end_points_xy); # endif #endif #ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED - write_unknown_chunks(png_ptr, info_ptr, PNG_HAVE_IHDR); + write_unknown_chunks(png_ptr, info_ptr, PNG_HAVE_IHDR); #endif png_ptr->mode |= PNG_WROTE_INFO_BEFORE_PLTE; @@ -205,7 +206,7 @@ png_write_info(png_structrp png_ptr, png_const_inforp info_ptr) png_write_PLTE(png_ptr, info_ptr->palette, (png_uint_32)info_ptr->num_palette); - else if ((info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) !=0) + else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) png_error(png_ptr, "Valid palette required for paletted images"); #ifdef PNG_WRITE_tRNS_SUPPORTED @@ -216,8 +217,13 @@ png_write_info(png_structrp png_ptr, png_const_inforp info_ptr) if ((png_ptr->transformations & PNG_INVERT_ALPHA) != 0 && info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) { - int j; - for (j = 0; j<(int)info_ptr->num_trans; j++) + int j, jend; + + jend = info_ptr->num_trans; + if (jend > PNG_MAX_PALETTE_LENGTH) + jend = PNG_MAX_PALETTE_LENGTH; + + for (j = 0; jtrans_alpha[j] = (png_byte)(255 - info_ptr->trans_alpha[j]); } @@ -538,7 +544,7 @@ png_create_write_struct_2,(png_const_charp user_png_ver, png_voidp error_ptr, /* App warnings are warnings in release (or release candidate) builds but * are errors during development. */ -#if PNG_LIBPNG_BUILD_BASE_TYPE >= PNG_LIBPNG_BUILD_RC +#if PNG_RELEASE_BUILD png_ptr->flags |= PNG_FLAG_APP_WARNINGS_WARN; #endif @@ -849,7 +855,7 @@ png_write_row(png_structrp png_ptr, png_const_bytep row) * which is also the output depth. */ if (row_info.pixel_depth != png_ptr->pixel_depth || - row_info.pixel_depth != png_ptr->transformed_pixel_depth) + row_info.pixel_depth != png_ptr->transformed_pixel_depth) png_error(png_ptr, "internal write transform logic error"); #ifdef PNG_MNG_FEATURES_SUPPORTED @@ -917,10 +923,6 @@ png_write_flush(png_structrp png_ptr) } #endif /* WRITE_FLUSH */ -#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED -static void png_reset_filter_heuristics(png_structrp png_ptr);/* forward decl */ -#endif - /* Free any memory used in png_ptr struct without freeing the struct itself. */ static void png_write_destroy(png_structrp png_ptr) @@ -937,24 +939,11 @@ png_write_destroy(png_structrp png_ptr) png_ptr->row_buf = NULL; #ifdef PNG_WRITE_FILTER_SUPPORTED png_free(png_ptr, png_ptr->prev_row); - png_free(png_ptr, png_ptr->sub_row); - png_free(png_ptr, png_ptr->up_row); - png_free(png_ptr, png_ptr->avg_row); - png_free(png_ptr, png_ptr->paeth_row); + png_free(png_ptr, png_ptr->try_row); + png_free(png_ptr, png_ptr->tst_row); png_ptr->prev_row = NULL; - png_ptr->sub_row = NULL; - png_ptr->up_row = NULL; - png_ptr->avg_row = NULL; - png_ptr->paeth_row = NULL; -#endif - -#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED - /* Use this to save a little code space, it doesn't free the filter_costs */ - png_reset_filter_heuristics(png_ptr); - png_free(png_ptr, png_ptr->filter_costs); - png_free(png_ptr, png_ptr->inv_filter_costs); - png_ptr->filter_costs = NULL; - png_ptr->inv_filter_costs = NULL; + png_ptr->try_row = NULL; + png_ptr->tst_row = NULL; #endif #ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED @@ -1044,6 +1033,7 @@ png_set_filter(png_structrp png_ptr, int method, int filters) #endif /* WRITE_FILTER */ } +#ifdef PNG_WRITE_FILTER_SUPPORTED /* If we have allocated the row_buf, this means we have already started * with the image and we should have allocated all of the filter buffers * that have been selected. If prev_row isn't already allocated, then @@ -1052,203 +1042,76 @@ png_set_filter(png_structrp png_ptr, int method, int filters) * wants to start and stop using particular filters during compression, * it should start out with all of the filters, and then remove them * or add them back after the start of compression. + * + * NOTE: this is a nasty constraint on the code, because it means that the + * prev_row buffer must be maintained even if there are currently no + * 'prev_row' requiring filters active. */ if (png_ptr->row_buf != NULL) { -#ifdef PNG_WRITE_FILTER_SUPPORTED - if ((png_ptr->do_filter & PNG_FILTER_SUB) != 0 && - png_ptr->sub_row == NULL) + int num_filters; + png_alloc_size_t buf_size; + + /* Repeat the checks in png_write_start_row; 1 pixel high or wide + * images cannot benefit from certain filters. If this isn't done here + * the check below will fire on 1 pixel high images. + */ + if (png_ptr->height == 1) + filters &= ~(PNG_FILTER_UP|PNG_FILTER_AVG|PNG_FILTER_PAETH); + + if (png_ptr->width == 1) + filters &= ~(PNG_FILTER_SUB|PNG_FILTER_AVG|PNG_FILTER_PAETH); + + if ((filters & (PNG_FILTER_UP|PNG_FILTER_AVG|PNG_FILTER_PAETH)) != 0 + && png_ptr->prev_row == NULL) { - png_ptr->sub_row = (png_bytep)png_malloc(png_ptr, - (png_ptr->rowbytes + 1)); - png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB; + /* This is the error case, however it is benign - the previous row + * is not available so the filter can't be used. Just warn here. + */ + png_app_warning(png_ptr, + "png_set_filter: UP/AVG/PAETH cannot be added after start"); + filters &= ~(PNG_FILTER_UP|PNG_FILTER_AVG|PNG_FILTER_PAETH); } - if ((png_ptr->do_filter & PNG_FILTER_UP) != 0 && - png_ptr->up_row == NULL) + num_filters = 0; + + if (filters & PNG_FILTER_SUB) + num_filters++; + + if (filters & PNG_FILTER_UP) + num_filters++; + + if (filters & PNG_FILTER_AVG) + num_filters++; + + if (filters & PNG_FILTER_PAETH) + num_filters++; + + /* Allocate needed row buffers if they have not already been + * allocated. + */ + buf_size = PNG_ROWBYTES(png_ptr->usr_channels * png_ptr->usr_bit_depth, + png_ptr->width) + 1; + + if (png_ptr->try_row == NULL) + png_ptr->try_row = png_voidcast(png_bytep, + png_malloc(png_ptr, buf_size)); + + if (num_filters > 1) { - if (png_ptr->prev_row == NULL) - { - png_warning(png_ptr, "Can't add Up filter after starting"); - png_ptr->do_filter = (png_byte)(png_ptr->do_filter & - ~PNG_FILTER_UP); - } - - else - { - png_ptr->up_row = (png_bytep)png_malloc(png_ptr, - (png_ptr->rowbytes + 1)); - png_ptr->up_row[0] = PNG_FILTER_VALUE_UP; - } + if (png_ptr->tst_row == NULL) + png_ptr->tst_row = png_voidcast(png_bytep, + png_malloc(png_ptr, buf_size)); } - - if ((png_ptr->do_filter & PNG_FILTER_AVG) != 0 && - png_ptr->avg_row == NULL) - { - if (png_ptr->prev_row == NULL) - { - png_warning(png_ptr, "Can't add Average filter after starting"); - png_ptr->do_filter = (png_byte)(png_ptr->do_filter & - ~PNG_FILTER_AVG); - } - - else - { - png_ptr->avg_row = (png_bytep)png_malloc(png_ptr, - (png_ptr->rowbytes + 1)); - png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG; - } - } - - if ((png_ptr->do_filter & PNG_FILTER_PAETH) != 0 && - png_ptr->paeth_row == NULL) - { - if (png_ptr->prev_row == NULL) - { - png_warning(png_ptr, "Can't add Paeth filter after starting"); - png_ptr->do_filter &= (png_byte)(~PNG_FILTER_PAETH); - } - - else - { - png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr, - (png_ptr->rowbytes + 1)); - png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH; - } - } - - if (png_ptr->do_filter == PNG_NO_FILTERS) -#endif /* WRITE_FILTER */ - png_ptr->do_filter = PNG_FILTER_NONE; } + png_ptr->do_filter = (png_byte)filters; +#endif } else png_error(png_ptr, "Unknown custom filter method"); } -/* This allows us to influence the way in which libpng chooses the "best" - * filter for the current scanline. While the "minimum-sum-of-absolute- - * differences metric is relatively fast and effective, there is some - * question as to whether it can be improved upon by trying to keep the - * filtered data going to zlib more consistent, hopefully resulting in - * better compression. - */ -#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED /* GRR 970116 */ -/* Convenience reset API. */ -static void -png_reset_filter_heuristics(png_structrp png_ptr) -{ - /* Clear out any old values in the 'weights' - this must be done because if - * the app calls set_filter_heuristics multiple times with different - * 'num_weights' values we would otherwise potentially have wrong sized - * arrays. - */ - png_ptr->num_prev_filters = 0; - png_ptr->heuristic_method = PNG_FILTER_HEURISTIC_UNWEIGHTED; - if (png_ptr->prev_filters != NULL) - { - png_bytep old = png_ptr->prev_filters; - png_ptr->prev_filters = NULL; - png_free(png_ptr, old); - } - if (png_ptr->filter_weights != NULL) - { - png_uint_16p old = png_ptr->filter_weights; - png_ptr->filter_weights = NULL; - png_free(png_ptr, old); - } - - if (png_ptr->inv_filter_weights != NULL) - { - png_uint_16p old = png_ptr->inv_filter_weights; - png_ptr->inv_filter_weights = NULL; - png_free(png_ptr, old); - } - - /* Leave the filter_costs - this array is fixed size. */ -} - -static int -png_init_filter_heuristics(png_structrp png_ptr, int heuristic_method, - int num_weights) -{ - if (png_ptr == NULL) - return 0; - - /* Clear out the arrays */ - png_reset_filter_heuristics(png_ptr); - - /* Check arguments; the 'reset' function makes the correct settings for the - * unweighted case, but we must handle the weight case by initializing the - * arrays for the caller. - */ - if (heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) - { - int i; - - if (num_weights > 0) - { - png_ptr->prev_filters = (png_bytep)png_malloc(png_ptr, - (png_uint_32)((sizeof (png_byte)) * num_weights)); - - /* To make sure that the weighting starts out fairly */ - for (i = 0; i < num_weights; i++) - { - png_ptr->prev_filters[i] = 255; - } - - png_ptr->filter_weights = (png_uint_16p)png_malloc(png_ptr, - (png_uint_32)((sizeof (png_uint_16)) * num_weights)); - - png_ptr->inv_filter_weights = (png_uint_16p)png_malloc(png_ptr, - (png_uint_32)((sizeof (png_uint_16)) * num_weights)); - - for (i = 0; i < num_weights; i++) - { - png_ptr->inv_filter_weights[i] = - png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR; - } - - /* Safe to set this now */ - png_ptr->num_prev_filters = (png_byte)num_weights; - } - - /* If, in the future, there are other filter methods, this would - * need to be based on png_ptr->filter. - */ - if (png_ptr->filter_costs == NULL) - { - png_ptr->filter_costs = (png_uint_16p)png_malloc(png_ptr, - (png_uint_32)((sizeof (png_uint_16)) * PNG_FILTER_VALUE_LAST)); - - png_ptr->inv_filter_costs = (png_uint_16p)png_malloc(png_ptr, - (png_uint_32)((sizeof (png_uint_16)) * PNG_FILTER_VALUE_LAST)); - } - - for (i = 0; i < PNG_FILTER_VALUE_LAST; i++) - { - png_ptr->inv_filter_costs[i] = - png_ptr->filter_costs[i] = PNG_COST_FACTOR; - } - - /* All the arrays are inited, safe to set this: */ - png_ptr->heuristic_method = PNG_FILTER_HEURISTIC_WEIGHTED; - - /* Return the 'ok' code. */ - return 1; - } - else if (heuristic_method == PNG_FILTER_HEURISTIC_DEFAULT || - heuristic_method == PNG_FILTER_HEURISTIC_UNWEIGHTED) - { - return 1; - } - else - { - png_warning(png_ptr, "Unknown filter heuristic method"); - return 0; - } -} - +#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED /* DEPRECATED */ /* Provide floating and fixed point APIs */ #ifdef PNG_FLOATING_POINT_SUPPORTED void PNGAPI @@ -1256,52 +1119,11 @@ png_set_filter_heuristics(png_structrp png_ptr, int heuristic_method, int num_weights, png_const_doublep filter_weights, png_const_doublep filter_costs) { - png_debug(1, "in png_set_filter_heuristics"); - - /* The internal API allocates all the arrays and ensures that the elements of - * those arrays are set to the default value. - */ - if (png_init_filter_heuristics(png_ptr, heuristic_method, num_weights) == 0) - return; - - /* If using the weighted method copy in the weights. */ - if (heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) - { - int i; - for (i = 0; i < num_weights; i++) - { - if (filter_weights[i] <= 0.0) - { - png_ptr->inv_filter_weights[i] = - png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR; - } - - else - { - png_ptr->inv_filter_weights[i] = - (png_uint_16)(PNG_WEIGHT_FACTOR*filter_weights[i]+.5); - - png_ptr->filter_weights[i] = - (png_uint_16)(PNG_WEIGHT_FACTOR/filter_weights[i]+.5); - } - } - - /* Here is where we set the relative costs of the different filters. We - * should take the desired compression level into account when setting - * the costs, so that Paeth, for instance, has a high relative cost at low - * compression levels, while it has a lower relative cost at higher - * compression settings. The filter types are in order of increasing - * relative cost, so it would be possible to do this with an algorithm. - */ - for (i = 0; i < PNG_FILTER_VALUE_LAST; i++) if (filter_costs[i] >= 1.0) - { - png_ptr->inv_filter_costs[i] = - (png_uint_16)(PNG_COST_FACTOR / filter_costs[i] + .5); - - png_ptr->filter_costs[i] = - (png_uint_16)(PNG_COST_FACTOR * filter_costs[i] + .5); - } - } + PNG_UNUSED(png_ptr) + PNG_UNUSED(heuristic_method) + PNG_UNUSED(num_weights) + PNG_UNUSED(filter_weights) + PNG_UNUSED(filter_costs) } #endif /* FLOATING_POINT */ @@ -1311,63 +1133,11 @@ png_set_filter_heuristics_fixed(png_structrp png_ptr, int heuristic_method, int num_weights, png_const_fixed_point_p filter_weights, png_const_fixed_point_p filter_costs) { - png_debug(1, "in png_set_filter_heuristics_fixed"); - - /* The internal API allocates all the arrays and ensures that the elements of - * those arrays are set to the default value. - */ - if (png_init_filter_heuristics(png_ptr, heuristic_method, num_weights) == 0) - return; - - /* If using the weighted method copy in the weights. */ - if (heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) - { - int i; - for (i = 0; i < num_weights; i++) - { - if (filter_weights[i] <= 0) - { - png_ptr->inv_filter_weights[i] = - png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR; - } - - else - { - png_ptr->inv_filter_weights[i] = (png_uint_16) - ((PNG_WEIGHT_FACTOR*filter_weights[i]+PNG_FP_HALF)/PNG_FP_1); - - png_ptr->filter_weights[i] = (png_uint_16)((PNG_WEIGHT_FACTOR* - PNG_FP_1+(filter_weights[i]/2))/filter_weights[i]); - } - } - - /* Here is where we set the relative costs of the different filters. We - * should take the desired compression level into account when setting - * the costs, so that Paeth, for instance, has a high relative cost at low - * compression levels, while it has a lower relative cost at higher - * compression settings. The filter types are in order of increasing - * relative cost, so it would be possible to do this with an algorithm. - */ - for (i = 0; i < PNG_FILTER_VALUE_LAST; i++) - if (filter_costs[i] >= PNG_FP_1) - { - png_uint_32 tmp; - - /* Use a 32 bit unsigned temporary here because otherwise the - * intermediate value will be a 32 bit *signed* integer (ANSI rules) - * and this will get the wrong answer on division. - */ - tmp = PNG_COST_FACTOR*PNG_FP_1 + (filter_costs[i]/2); - tmp /= filter_costs[i]; - - png_ptr->inv_filter_costs[i] = (png_uint_16)tmp; - - tmp = PNG_COST_FACTOR * filter_costs[i] + PNG_FP_HALF; - tmp /= PNG_FP_1; - - png_ptr->filter_costs[i] = (png_uint_16)tmp; - } - } + PNG_UNUSED(png_ptr) + PNG_UNUSED(heuristic_method) + PNG_UNUSED(num_weights) + PNG_UNUSED(filter_weights) + PNG_UNUSED(filter_costs) } #endif /* FIXED_POINT */ #endif /* WRITE_WEIGHTED_FILTER */ @@ -1616,14 +1386,14 @@ png_write_png(png_structrp png_ptr, png_inforp info_ptr, * alpha channel. */ if ((transforms & (PNG_TRANSFORM_STRIP_FILLER_AFTER| - PNG_TRANSFORM_STRIP_FILLER_BEFORE)) != 0) + PNG_TRANSFORM_STRIP_FILLER_BEFORE)) != 0) { #ifdef PNG_WRITE_FILLER_SUPPORTED if ((transforms & PNG_TRANSFORM_STRIP_FILLER_AFTER) != 0) { if ((transforms & PNG_TRANSFORM_STRIP_FILLER_BEFORE) != 0) png_app_error(png_ptr, - "PNG_TRANSFORM_STRIP_FILLER: BEFORE+AFTER not supported"); + "PNG_TRANSFORM_STRIP_FILLER: BEFORE+AFTER not supported"); /* Continue if ignored - this is the pre-1.6.10 behavior */ png_set_filler(png_ptr, 0, PNG_FILLER_AFTER); @@ -1652,7 +1422,7 @@ png_write_png(png_structrp png_ptr, png_inforp info_ptr, png_app_error(png_ptr, "PNG_TRANSFORM_SWAP_ENDIAN not supported"); #endif - /* Swap bits of 1, 2, 4 bit packed pixel formats */ + /* Swap bits of 1-bit, 2-bit, 4-bit packed pixel formats */ if ((transforms & PNG_TRANSFORM_PACKSWAP) != 0) #ifdef PNG_WRITE_PACKSWAP_SUPPORTED png_set_packswap(png_ptr); @@ -1682,13 +1452,13 @@ png_write_png(png_structrp png_ptr, png_inforp info_ptr, #ifdef PNG_SIMPLIFIED_WRITE_SUPPORTED -#ifdef PNG_STDIO_SUPPORTED /* currently required for png_image_write_* */ +# ifdef PNG_STDIO_SUPPORTED /* currently required for png_image_write_* */ /* Initialize the write structure - general purpose utility. */ static int png_image_write_init(png_imagep image) { png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, image, - png_safe_error, png_safe_warning); + png_safe_error, png_safe_warning); if (png_ptr != NULL) { @@ -1697,7 +1467,7 @@ png_image_write_init(png_imagep image) if (info_ptr != NULL) { png_controlp control = png_voidcast(png_controlp, - png_malloc_warn(png_ptr, (sizeof *control))); + png_malloc_warn(png_ptr, (sizeof *control))); if (control != NULL) { @@ -1744,12 +1514,12 @@ static int png_write_image_16bit(png_voidp argument) { png_image_write_control *display = png_voidcast(png_image_write_control*, - argument); + argument); png_imagep image = display->image; png_structrp png_ptr = image->opaque->png_ptr; png_const_uint_16p input_row = png_voidcast(png_const_uint_16p, - display->first_row); + display->first_row); png_uint_16p output_row = png_voidcast(png_uint_16p, display->local_row); png_uint_16p row_end; const int channels = (image->format & PNG_FORMAT_FLAG_COLOR) != 0 ? 3 : 1; @@ -1758,17 +1528,18 @@ png_write_image_16bit(png_voidp argument) if ((image->format & PNG_FORMAT_FLAG_ALPHA) != 0) { -# ifdef PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED - if ((image->format & PNG_FORMAT_FLAG_AFIRST) != 0) - { - aindex = -1; - ++input_row; /* To point to the first component */ - ++output_row; - } - +# ifdef PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED + if ((image->format & PNG_FORMAT_FLAG_AFIRST) != 0) + { + aindex = -1; + ++input_row; /* To point to the first component */ + ++output_row; + } else -# endif + aindex = channels; +# else aindex = channels; +# endif } else @@ -1850,7 +1621,7 @@ png_write_image_16bit(png_voidp argument) * calculation can be done to 15 bits of accuracy; however, the output needs to * be scaled in the range 0..255*65535, so include that scaling here. */ -#define UNP_RECIPROCAL(alpha) ((((0xffff*0xff)<<7)+(alpha>>1))/alpha) +# define UNP_RECIPROCAL(alpha) ((((0xffff*0xff)<<7)+(alpha>>1))/alpha) static png_byte png_unpremultiply(png_uint_32 component, png_uint_32 alpha, @@ -1901,12 +1672,12 @@ static int png_write_image_8bit(png_voidp argument) { png_image_write_control *display = png_voidcast(png_image_write_control*, - argument); + argument); png_imagep image = display->image; png_structrp png_ptr = image->opaque->png_ptr; png_const_uint_16p input_row = png_voidcast(png_const_uint_16p, - display->first_row); + display->first_row); png_bytep output_row = png_voidcast(png_bytep, display->local_row); png_uint_32 y = image->height; const int channels = (image->format & PNG_FORMAT_FLAG_COLOR) != 0 ? 3 : 1; @@ -1916,17 +1687,17 @@ png_write_image_8bit(png_voidp argument) png_bytep row_end; int aindex; -# ifdef PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED - if ((image->format & PNG_FORMAT_FLAG_AFIRST) != 0) - { - aindex = -1; - ++input_row; /* To point to the first component */ - ++output_row; - } +# ifdef PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED + if ((image->format & PNG_FORMAT_FLAG_AFIRST) != 0) + { + aindex = -1; + ++input_row; /* To point to the first component */ + ++output_row; + } - else -# endif - aindex = channels; + else +# endif + aindex = channels; /* Use row_end in place of a loop counter: */ row_end = output_row + image->width * (channels+1); @@ -1960,7 +1731,7 @@ png_write_image_8bit(png_voidp argument) } /* while out_ptr < row_end */ png_write_row(png_ptr, png_voidcast(png_const_bytep, - display->local_row)); + display->local_row)); input_row += display->row_bytes/(sizeof (png_uint_16)); } /* while y */ } @@ -1999,25 +1770,25 @@ png_image_set_PLTE(png_image_write_control *display) const png_imagep image = display->image; const void *cmap = display->colormap; const int entries = image->colormap_entries > 256 ? 256 : - (int)image->colormap_entries; + (int)image->colormap_entries; /* NOTE: the caller must check for cmap != NULL and entries != 0 */ const png_uint_32 format = image->format; const int channels = PNG_IMAGE_SAMPLE_CHANNELS(format); -# if defined(PNG_FORMAT_BGR_SUPPORTED) &&\ +# if defined(PNG_FORMAT_BGR_SUPPORTED) &&\ defined(PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED) const int afirst = (format & PNG_FORMAT_FLAG_AFIRST) != 0 && - (format & PNG_FORMAT_FLAG_ALPHA) != 0; -# else + (format & PNG_FORMAT_FLAG_ALPHA) != 0; +# else # define afirst 0 -# endif +# endif -# ifdef PNG_FORMAT_BGR_SUPPORTED +# ifdef PNG_FORMAT_BGR_SUPPORTED const int bgr = (format & PNG_FORMAT_FLAG_BGR) != 0 ? 2 : 0; -# else +# else # define bgr 0 -# endif +# endif int i, num_trans; png_color palette[256]; @@ -2042,11 +1813,11 @@ png_image_set_PLTE(png_image_write_control *display) if (channels >= 3) /* RGB */ { palette[i].blue = (png_byte)PNG_sRGB_FROM_LINEAR(255 * - entry[(2 ^ bgr)]); + entry[(2 ^ bgr)]); palette[i].green = (png_byte)PNG_sRGB_FROM_LINEAR(255 * - entry[1]); + entry[1]); palette[i].red = (png_byte)PNG_sRGB_FROM_LINEAR(255 * - entry[bgr]); + entry[bgr]); } else /* Gray */ @@ -2122,12 +1893,12 @@ png_image_set_PLTE(png_image_write_control *display) } } -# ifdef afirst +# ifdef afirst # undef afirst -# endif -# ifdef bgr +# endif +# ifdef bgr # undef bgr -# endif +# endif png_set_PLTE(image->opaque->png_ptr, image->opaque->info_ptr, palette, entries); @@ -2155,10 +1926,10 @@ png_image_write_main(png_voidp argument) int alpha = !colormap && (format & PNG_FORMAT_FLAG_ALPHA); int write_16bit = linear && !colormap && (display->convert_to_8bit == 0); -# ifdef PNG_BENIGN_ERRORS_SUPPORTED +# ifdef PNG_BENIGN_ERRORS_SUPPORTED /* Make sure we error out on any bad situation */ png_set_benign_errors(png_ptr, 0/*error*/); -# endif +# endif /* Default the 'row_stride' parameter if required. */ if (display->row_stride == 0) @@ -2227,7 +1998,7 @@ png_image_write_main(png_voidp argument) /* Now set up the data transformations (*after* the header is written), * remove the handled transformations from the 'format' flags for checking. * - * First check for a little endian system if writing 16 bit files. + * First check for a little endian system if writing 16-bit files. */ if (write_16bit != 0) { @@ -2237,23 +2008,23 @@ png_image_write_main(png_voidp argument) png_set_swap(png_ptr); } -# ifdef PNG_SIMPLIFIED_WRITE_BGR_SUPPORTED +# ifdef PNG_SIMPLIFIED_WRITE_BGR_SUPPORTED if ((format & PNG_FORMAT_FLAG_BGR) != 0) { if (colormap == 0 && (format & PNG_FORMAT_FLAG_COLOR) != 0) png_set_bgr(png_ptr); format &= ~PNG_FORMAT_FLAG_BGR; } -# endif +# endif -# ifdef PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED +# ifdef PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED if ((format & PNG_FORMAT_FLAG_AFIRST) != 0) { if (colormap == 0 && (format & PNG_FORMAT_FLAG_ALPHA) != 0) png_set_swap_alpha(png_ptr); format &= ~PNG_FORMAT_FLAG_AFIRST; } -# endif +# endif /* If there are 16 or fewer color-map entries we wrote a lower bit depth * above, but the application data is still byte packed. @@ -2289,9 +2060,9 @@ png_image_write_main(png_voidp argument) * it about 50 times. The speed-up in pngstest was about 10-20% of the * total (user) time on a heavily loaded system. */ -#ifdef PNG_WRITE_CUSTOMIZE_COMPRESSION_SUPPORTED +# ifdef PNG_WRITE_CUSTOMIZE_COMPRESSION_SUPPORTED png_set_compression_level(png_ptr, 3); -#endif +# endif } /* Check for the cases that currently require a pre-transform on the row @@ -2454,6 +2225,6 @@ png_image_write_to_file(png_imagep image, const char *file_name, else return 0; } -#endif /* STDIO */ +# endif /* STDIO */ #endif /* SIMPLIFIED_WRITE */ #endif /* WRITE */ diff --git a/thirdparty/libpng/pngwtran.c b/thirdparty/libpng/pngwtran.c index db82e27b..038a2ef5 100644 --- a/thirdparty/libpng/pngwtran.c +++ b/thirdparty/libpng/pngwtran.c @@ -1,8 +1,8 @@ /* pngwtran.c - transforms the data in a row for PNG writers * - * Last changed in libpng 1.6.17 [March 26, 2015] - * Copyright (c) 1998-2015 Glenn Randers-Pehrson + * Last changed in libpng 1.6.18 [July 23, 2015] + * Copyright (c) 1998-2002,2004,2006-2015 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.) * @@ -71,7 +71,8 @@ png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth) case 2: { png_bytep sp, dp; - int shift, v; + unsigned int shift; + int v; png_uint_32 i; png_uint_32 row_width = row_info->width; @@ -110,7 +111,8 @@ png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth) case 4: { png_bytep sp, dp; - int shift, v; + unsigned int shift; + int v; png_uint_32 i; png_uint_32 row_width = row_info->width; @@ -422,7 +424,7 @@ png_do_write_invert_alpha(png_row_infop row_info, png_bytep row) *(dp++) = *(sp++); */ sp+=3; dp = sp; - *(dp++) = (png_byte)(255 - *(sp++)); + *dp = (png_byte)(255 - *(sp++)); } } @@ -446,7 +448,7 @@ png_do_write_invert_alpha(png_row_infop row_info, png_bytep row) */ sp+=6; dp = sp; *(dp++) = (png_byte)(255 - *(sp++)); - *(dp++) = (png_byte)(255 - *(sp++)); + *dp = (png_byte)(255 - *(sp++)); } } #endif /* WRITE_16BIT */ @@ -484,7 +486,7 @@ png_do_write_invert_alpha(png_row_infop row_info, png_bytep row) */ sp+=2; dp = sp; *(dp++) = (png_byte)(255 - *(sp++)); - *(dp++) = (png_byte)(255 - *(sp++)); + *dp = (png_byte)(255 - *(sp++)); } } #endif /* WRITE_16BIT */ diff --git a/thirdparty/libpng/pngwutil.c b/thirdparty/libpng/pngwutil.c index b289671d..8cf4c2bb 100644 --- a/thirdparty/libpng/pngwutil.c +++ b/thirdparty/libpng/pngwutil.c @@ -1,8 +1,8 @@ /* pngwutil.c - utilities to write a PNG file * - * Last changed in libpng 1.6.17 [March 26, 2015] - * Copyright (c) 1998-2015 Glenn Randers-Pehrson + * Last changed in libpng 1.6.21 [January 15, 2016] + * Copyright (c) 1998-2002,2004,2006-2015 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.) * @@ -179,7 +179,7 @@ png_write_complete_chunk(png_structrp png_ptr, png_uint_32 chunk_name, if (png_ptr == NULL) return; - /* On 64 bit architectures 'length' may not fit in a png_uint_32. */ + /* On 64-bit architectures 'length' may not fit in a png_uint_32. */ if (length > PNG_UINT_31_MAX) png_error(png_ptr, "length exceeds PNG maximum"); @@ -308,7 +308,7 @@ png_deflate_claim(png_structrp png_ptr, png_uint_32 owner, */ (void)png_safecat(msg, (sizeof msg), 10, " using zstream"); #endif -#if PNG_LIBPNG_BUILD_BASE_TYPE >= PNG_LIBPNG_BUILD_RC +#if PNG_RELEASE_BUILD png_warning(png_ptr, msg); /* Attempt sane error recovery */ @@ -665,90 +665,6 @@ png_write_compressed_data_out(png_structrp png_ptr, compression_state *comp) } #endif /* WRITE_COMPRESSED_TEXT */ -#if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \ - defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED) -/* Check that the tEXt or zTXt keyword is valid per PNG 1.0 specification, - * and if invalid, correct the keyword rather than discarding the entire - * chunk. The PNG 1.0 specification requires keywords 1-79 characters in - * length, forbids leading or trailing whitespace, multiple internal spaces, - * and the non-break space (0x80) from ISO 8859-1. Returns keyword length. - * - * The 'new_key' buffer must be 80 characters in size (for the keyword plus a - * trailing '\0'). If this routine returns 0 then there was no keyword, or a - * valid one could not be generated, and the caller must png_error. - */ -static png_uint_32 -png_check_keyword(png_structrp png_ptr, png_const_charp key, png_bytep new_key) -{ - png_const_charp orig_key = key; - png_uint_32 key_len = 0; - int bad_character = 0; - int space = 1; - - png_debug(1, "in png_check_keyword"); - - if (key == NULL) - { - *new_key = 0; - return 0; - } - - while (*key && key_len < 79) - { - png_byte ch = (png_byte)*key++; - - if ((ch > 32 && ch <= 126) || (ch >= 161 /*&& ch <= 255*/)) - *new_key++ = ch, ++key_len, space = 0; - - else if (space == 0) - { - /* A space or an invalid character when one wasn't seen immediately - * before; output just a space. - */ - *new_key++ = 32, ++key_len, space = 1; - - /* If the character was not a space then it is invalid. */ - if (ch != 32) - bad_character = ch; - } - - else if (bad_character == 0) - bad_character = ch; /* just skip it, record the first error */ - } - - if (key_len > 0 && space != 0) /* trailing space */ - { - --key_len, --new_key; - if (bad_character == 0) - bad_character = 32; - } - - /* Terminate the keyword */ - *new_key = 0; - - if (key_len == 0) - return 0; - -#ifdef PNG_WARNINGS_SUPPORTED - /* Try to only output one warning per keyword: */ - if (*key != 0) /* keyword too long */ - png_warning(png_ptr, "keyword truncated"); - - else if (bad_character != 0) - { - PNG_WARNING_PARAMETERS(p) - - png_warning_parameter(p, 1, orig_key); - png_warning_parameter_signed(p, 2, PNG_NUMBER_FORMAT_02x, bad_character); - - png_formatted_warning(png_ptr, p, "keyword \"@1\": bad character '0x@2'"); - } -#endif /* WARNINGS */ - - return key_len; -} -#endif /* WRITE_TEXT || WRITE_pCAL || WRITE_iCCP || WRITE_sPLT */ - /* Write the IHDR chunk, and update the png_struct with the necessary * information. Note that the rest of this code depends upon this * information being correct. @@ -922,17 +838,20 @@ void /* PRIVATE */ png_write_PLTE(png_structrp png_ptr, png_const_colorp palette, png_uint_32 num_pal) { - png_uint_32 i; + png_uint_32 max_palette_length, i; png_const_colorp pal_ptr; png_byte buf[3]; png_debug(1, "in png_write_PLTE"); + max_palette_length = (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ? + (1 << png_ptr->bit_depth) : PNG_MAX_PALETTE_LENGTH; + if (( #ifdef PNG_MNG_FEATURES_SUPPORTED (png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) == 0 && #endif - num_pal == 0) || num_pal > 256) + num_pal == 0) || num_pal > max_palette_length) { if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) { @@ -1444,7 +1363,7 @@ png_write_tRNS(png_structrp png_ptr, png_const_bytep trans_alpha, else if (color_type == PNG_COLOR_TYPE_GRAY) { - /* One 16 bit value */ + /* One 16-bit value */ if (tran->gray >= (1 << png_ptr->bit_depth)) { png_app_warning(png_ptr, @@ -1459,7 +1378,7 @@ png_write_tRNS(png_structrp png_ptr, png_const_bytep trans_alpha, else if (color_type == PNG_COLOR_TYPE_RGB) { - /* Three 16 bit values */ + /* Three 16-bit values */ png_save_uint_16(buf, tran->red); png_save_uint_16(buf + 2, tran->green); png_save_uint_16(buf + 4, tran->blue); @@ -1961,6 +1880,10 @@ png_write_start_row(png_structrp png_ptr) png_alloc_size_t buf_size; int usr_pixel_depth; +#ifdef PNG_WRITE_FILTER_SUPPORTED + png_byte filters; +#endif + png_debug(1, "in png_write_start_row"); usr_pixel_depth = png_ptr->usr_channels * png_ptr->usr_bit_depth; @@ -1971,50 +1894,54 @@ png_write_start_row(png_structrp png_ptr) png_ptr->maximum_pixel_depth = (png_byte)usr_pixel_depth; /* Set up row buffer */ - png_ptr->row_buf = (png_bytep)png_malloc(png_ptr, buf_size); + png_ptr->row_buf = png_voidcast(png_bytep, png_malloc(png_ptr, buf_size)); png_ptr->row_buf[0] = PNG_FILTER_VALUE_NONE; #ifdef PNG_WRITE_FILTER_SUPPORTED - /* Set up filtering buffer, if using this filter */ - if (png_ptr->do_filter & PNG_FILTER_SUB) - { - png_ptr->sub_row = (png_bytep)png_malloc(png_ptr, png_ptr->rowbytes + 1); + filters = png_ptr->do_filter; - png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB; + if (png_ptr->height == 1) + filters &= 0xff & ~(PNG_FILTER_UP|PNG_FILTER_AVG|PNG_FILTER_PAETH); + + if (png_ptr->width == 1) + filters &= 0xff & ~(PNG_FILTER_SUB|PNG_FILTER_AVG|PNG_FILTER_PAETH); + + if (filters == 0) + filters = PNG_FILTER_NONE; + + png_ptr->do_filter = filters; + + if (((filters & (PNG_FILTER_SUB | PNG_FILTER_UP | PNG_FILTER_AVG | + PNG_FILTER_PAETH)) != 0) && png_ptr->try_row == NULL) + { + int num_filters = 0; + + png_ptr->try_row = png_voidcast(png_bytep, png_malloc(png_ptr, buf_size)); + + if (filters & PNG_FILTER_SUB) + num_filters++; + + if (filters & PNG_FILTER_UP) + num_filters++; + + if (filters & PNG_FILTER_AVG) + num_filters++; + + if (filters & PNG_FILTER_PAETH) + num_filters++; + + if (num_filters > 1) + png_ptr->tst_row = png_voidcast(png_bytep, png_malloc(png_ptr, + buf_size)); } - /* We only need to keep the previous row if we are using one of these. */ - if ((png_ptr->do_filter & - (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH)) != 0) - { - /* Set up previous row buffer */ - png_ptr->prev_row = (png_bytep)png_calloc(png_ptr, buf_size); - - if ((png_ptr->do_filter & PNG_FILTER_UP) != 0) - { - png_ptr->up_row = (png_bytep)png_malloc(png_ptr, - png_ptr->rowbytes + 1); - - png_ptr->up_row[0] = PNG_FILTER_VALUE_UP; - } - - if ((png_ptr->do_filter & PNG_FILTER_AVG) != 0) - { - png_ptr->avg_row = (png_bytep)png_malloc(png_ptr, - png_ptr->rowbytes + 1); - - png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG; - } - - if ((png_ptr->do_filter & PNG_FILTER_PAETH) != 0) - { - png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr, - png_ptr->rowbytes + 1); - - png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH; - } - } + /* We only need to keep the previous row if we are using one of the following + * filters. + */ + if ((filters & (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH)) != 0) + png_ptr->prev_row = png_voidcast(png_bytep, + png_calloc(png_ptr, buf_size)); #endif /* WRITE_FILTER */ #ifdef PNG_WRITE_INTERLACING_SUPPORTED @@ -2160,7 +2087,7 @@ png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass) { png_bytep sp; png_bytep dp; - int shift; + unsigned int shift; int d; int value; png_uint_32 i; @@ -2198,7 +2125,7 @@ png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass) { png_bytep sp; png_bytep dp; - int shift; + unsigned int shift; int d; int value; png_uint_32 i; @@ -2235,7 +2162,7 @@ png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass) { png_bytep sp; png_bytep dp; - int shift; + unsigned int shift; int d; int value; png_uint_32 i; @@ -2310,6 +2237,7 @@ png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass) } #endif + /* This filters the row, chooses which filter to use, if it has not already * been specified by the application, and then writes the row out with the * chosen filter. @@ -2318,42 +2246,172 @@ static void /* PRIVATE */ png_write_filtered_row(png_structrp png_ptr, png_bytep filtered_row, png_size_t row_bytes); -#define PNG_MAXSUM (((png_uint_32)(-1)) >> 1) -#define PNG_HISHIFT 10 -#define PNG_LOMASK ((png_uint_32)0xffffL) -#define PNG_HIMASK ((png_uint_32)(~PNG_LOMASK >> PNG_HISHIFT)) +#ifdef PNG_WRITE_FILTER_SUPPORTED +static png_size_t /* PRIVATE */ +png_setup_sub_row(png_structrp png_ptr, const png_uint_32 bpp, + const png_size_t row_bytes, const png_size_t lmins) +{ + png_bytep rp, dp, lp; + png_size_t i; + png_size_t sum = 0; + int v; + + png_ptr->try_row[0] = PNG_FILTER_VALUE_SUB; + + for (i = 0, rp = png_ptr->row_buf + 1, dp = png_ptr->try_row + 1; i < bpp; + i++, rp++, dp++) + { + v = *dp = *rp; + sum += (v < 128) ? v : 256 - v; + } + + for (lp = png_ptr->row_buf + 1; i < row_bytes; + i++, rp++, lp++, dp++) + { + v = *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff); + sum += (v < 128) ? v : 256 - v; + + if (sum > lmins) /* We are already worse, don't continue. */ + break; + } + + return (sum); +} + +static png_size_t /* PRIVATE */ +png_setup_up_row(png_structrp png_ptr, const png_size_t row_bytes, + const png_size_t lmins) +{ + png_bytep rp, dp, pp; + png_size_t i; + png_size_t sum = 0; + int v; + + png_ptr->try_row[0] = PNG_FILTER_VALUE_UP; + + for (i = 0, rp = png_ptr->row_buf + 1, dp = png_ptr->try_row + 1, + pp = png_ptr->prev_row + 1; i < row_bytes; + i++, rp++, pp++, dp++) + { + v = *dp = (png_byte)(((int)*rp - (int)*pp) & 0xff); + sum += (v < 128) ? v : 256 - v; + + if (sum > lmins) /* We are already worse, don't continue. */ + break; + } + + return (sum); +} + +static png_size_t /* PRIVATE */ +png_setup_avg_row(png_structrp png_ptr, const png_uint_32 bpp, + const png_size_t row_bytes, const png_size_t lmins) +{ + png_bytep rp, dp, pp, lp; + png_uint_32 i; + png_size_t sum = 0; + int v; + + png_ptr->try_row[0] = PNG_FILTER_VALUE_AVG; + + for (i = 0, rp = png_ptr->row_buf + 1, dp = png_ptr->try_row + 1, + pp = png_ptr->prev_row + 1; i < bpp; i++) + { + v = *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff); + + sum += (v < 128) ? v : 256 - v; + } + + for (lp = png_ptr->row_buf + 1; i < row_bytes; i++) + { + v = *dp++ = (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2)) + & 0xff); + + sum += (v < 128) ? v : 256 - v; + + if (sum > lmins) /* We are already worse, don't continue. */ + break; + } + + return (sum); +} + +static png_size_t /* PRIVATE */ +png_setup_paeth_row(png_structrp png_ptr, const png_uint_32 bpp, + const png_size_t row_bytes, const png_size_t lmins) +{ + png_bytep rp, dp, pp, cp, lp; + png_size_t i; + png_size_t sum = 0; + int v; + + png_ptr->try_row[0] = PNG_FILTER_VALUE_PAETH; + + for (i = 0, rp = png_ptr->row_buf + 1, dp = png_ptr->try_row + 1, + pp = png_ptr->prev_row + 1; i < bpp; i++) + { + v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff); + + sum += (v < 128) ? v : 256 - v; + } + + for (lp = png_ptr->row_buf + 1, cp = png_ptr->prev_row + 1; i < row_bytes; + i++) + { + int a, b, c, pa, pb, pc, p; + + b = *pp++; + c = *cp++; + a = *lp++; + + p = b - c; + pc = a - c; + +#ifdef PNG_USE_ABS + pa = abs(p); + pb = abs(pc); + pc = abs(p + pc); +#else + pa = p < 0 ? -p : p; + pb = pc < 0 ? -pc : pc; + pc = (p + pc) < 0 ? -(p + pc) : p + pc; +#endif + + p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c; + + v = *dp++ = (png_byte)(((int)*rp++ - p) & 0xff); + + sum += (v < 128) ? v : 256 - v; + + if (sum > lmins) /* We are already worse, don't continue. */ + break; + } + + return (sum); +} +#endif /* WRITE_FILTER */ + void /* PRIVATE */ png_write_find_filter(png_structrp png_ptr, png_row_infop row_info) { - png_bytep best_row; -#ifdef PNG_WRITE_FILTER_SUPPORTED - png_bytep prev_row, row_buf; - png_uint_32 mins, bpp; +#ifndef PNG_WRITE_FILTER_SUPPORTED + png_write_filtered_row(png_ptr, png_ptr->row_buf, row_info->rowbytes+1); +#else png_byte filter_to_do = png_ptr->do_filter; + png_bytep row_buf; + png_bytep best_row; + png_uint_32 bpp; + png_size_t mins; png_size_t row_bytes = row_info->rowbytes; -#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED - int num_p_filters = png_ptr->num_prev_filters; -#endif png_debug(1, "in png_write_find_filter"); -#ifndef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED - if (png_ptr->row_number == 0 && filter_to_do == PNG_ALL_FILTERS) - { - /* These will never be selected so we need not test them. */ - filter_to_do &= ~(PNG_FILTER_UP | PNG_FILTER_PAETH); - } -#endif - /* Find out how many bytes offset each pixel is */ bpp = (row_info->pixel_depth + 7) >> 3; - prev_row = png_ptr->prev_row; -#endif - best_row = png_ptr->row_buf; -#ifdef PNG_WRITE_FILTER_SUPPORTED - row_buf = best_row; - mins = PNG_MAXSUM; + row_buf = png_ptr->row_buf; + mins = PNG_SIZE_MAX - 256/* so we can detect potential overflow of the + running sum */; /* The prediction method we use is to find which method provides the * smallest value when summing the absolute values of the distances @@ -2383,57 +2441,37 @@ png_write_find_filter(png_structrp png_ptr, png_row_infop row_info) /* We don't need to test the 'no filter' case if this is the only filter * that has been chosen, as it doesn't actually do anything to the data. */ + best_row = png_ptr->row_buf; + + if ((filter_to_do & PNG_FILTER_NONE) != 0 && filter_to_do != PNG_FILTER_NONE) { png_bytep rp; - png_uint_32 sum = 0; + png_size_t sum = 0; png_size_t i; int v; - for (i = 0, rp = row_buf + 1; i < row_bytes; i++, rp++) + if (PNG_SIZE_MAX/128 <= row_bytes) { - v = *rp; - sum += (v < 128) ? v : 256 - v; - } - -#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED - if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) - { - png_uint_32 sumhi, sumlo; - int j; - sumlo = sum & PNG_LOMASK; - sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; /* Gives us some footroom */ - - /* Reduce the sum if we match any of the previous rows */ - for (j = 0; j < num_p_filters; j++) + for (i = 0, rp = row_buf + 1; i < row_bytes; i++, rp++) { - if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE) - { - sumlo = (sumlo * png_ptr->filter_weights[j]) >> - PNG_WEIGHT_SHIFT; + /* Check for overflow */ + if (sum > PNG_SIZE_MAX/128 - 256) + break; - sumhi = (sumhi * png_ptr->filter_weights[j]) >> - PNG_WEIGHT_SHIFT; - } + v = *rp; + sum += (v < 128) ? v : 256 - v; } - - /* Factor in the cost of this filter (this is here for completeness, - * but it makes no sense to have a "cost" for the NONE filter, as - * it has the minimum possible computational cost - none). - */ - sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >> - PNG_COST_SHIFT; - - sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >> - PNG_COST_SHIFT; - - if (sumhi > PNG_HIMASK) - sum = PNG_MAXSUM; - - else - sum = (sumhi << PNG_HISHIFT) + sumlo; } -#endif + else /* Overflow is not possible */ + { + for (i = 0, rp = row_buf + 1; i < row_bytes; i++, rp++) + { + v = *rp; + sum += (v < 128) ? v : 256 - v; + } + } + mins = sum; } @@ -2441,553 +2479,109 @@ png_write_find_filter(png_structrp png_ptr, png_row_infop row_info) if (filter_to_do == PNG_FILTER_SUB) /* It's the only filter so no testing is needed */ { - png_bytep rp, lp, dp; - png_size_t i; - - for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp; - i++, rp++, dp++) - { - *dp = *rp; - } - - for (lp = row_buf + 1; i < row_bytes; - i++, rp++, lp++, dp++) - { - *dp = (png_byte)((int)*rp - (int)*lp); - } - - best_row = png_ptr->sub_row; + (void) png_setup_sub_row(png_ptr, bpp, row_bytes, mins); + best_row = png_ptr->try_row; } else if ((filter_to_do & PNG_FILTER_SUB) != 0) { - png_bytep rp, dp, lp; - png_uint_32 sum = 0, lmins = mins; - png_size_t i; - int v; + png_size_t sum; + png_size_t lmins = mins; -#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED - /* We temporarily increase the "minimum sum" by the factor we - * would reduce the sum of this filter, so that we can do the - * early exit comparison without scaling the sum each time. - */ - if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) - { - int j; - png_uint_32 lmhi, lmlo; - lmlo = lmins & PNG_LOMASK; - lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK; - - for (j = 0; j < num_p_filters; j++) - { - if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB) - { - lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >> - PNG_WEIGHT_SHIFT; - - lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >> - PNG_WEIGHT_SHIFT; - } - } - - lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >> - PNG_COST_SHIFT; - - lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >> - PNG_COST_SHIFT; - - if (lmhi > PNG_HIMASK) - lmins = PNG_MAXSUM; - - else - lmins = (lmhi << PNG_HISHIFT) + lmlo; - } -#endif - - for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp; - i++, rp++, dp++) - { - v = *dp = *rp; - - sum += (v < 128) ? v : 256 - v; - } - - for (lp = row_buf + 1; i < row_bytes; - i++, rp++, lp++, dp++) - { - v = *dp = (png_byte)((int)*rp - (int)*lp); - - sum += (v < 128) ? v : 256 - v; - - if (sum > lmins) /* We are already worse, don't continue. */ - break; - } - -#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED - if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) - { - int j; - png_uint_32 sumhi, sumlo; - sumlo = sum & PNG_LOMASK; - sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; - - for (j = 0; j < num_p_filters; j++) - { - if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB) - { - sumlo = (sumlo * png_ptr->inv_filter_weights[j]) >> - PNG_WEIGHT_SHIFT; - - sumhi = (sumhi * png_ptr->inv_filter_weights[j]) >> - PNG_WEIGHT_SHIFT; - } - } - - sumlo = (sumlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >> - PNG_COST_SHIFT; - - sumhi = (sumhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >> - PNG_COST_SHIFT; - - if (sumhi > PNG_HIMASK) - sum = PNG_MAXSUM; - - else - sum = (sumhi << PNG_HISHIFT) + sumlo; - } -#endif + sum = png_setup_sub_row(png_ptr, bpp, row_bytes, lmins); if (sum < mins) { mins = sum; - best_row = png_ptr->sub_row; + best_row = png_ptr->try_row; + if (png_ptr->tst_row != NULL) + { + png_ptr->try_row = png_ptr->tst_row; + png_ptr->tst_row = best_row; + } } } /* Up filter */ if (filter_to_do == PNG_FILTER_UP) { - png_bytep rp, dp, pp; - png_size_t i; - - for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1, - pp = prev_row + 1; i < row_bytes; - i++, rp++, pp++, dp++) - { - *dp = (png_byte)((int)*rp - (int)*pp); - } - - best_row = png_ptr->up_row; + (void) png_setup_up_row(png_ptr, row_bytes, mins); + best_row = png_ptr->try_row; } else if ((filter_to_do & PNG_FILTER_UP) != 0) { - png_bytep rp, dp, pp; - png_uint_32 sum = 0, lmins = mins; - png_size_t i; - int v; + png_size_t sum; + png_size_t lmins = mins; - -#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED - if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) - { - int j; - png_uint_32 lmhi, lmlo; - lmlo = lmins & PNG_LOMASK; - lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK; - - for (j = 0; j < num_p_filters; j++) - { - if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP) - { - lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >> - PNG_WEIGHT_SHIFT; - - lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >> - PNG_WEIGHT_SHIFT; - } - } - - lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >> - PNG_COST_SHIFT; - - lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >> - PNG_COST_SHIFT; - - if (lmhi > PNG_HIMASK) - lmins = PNG_MAXSUM; - - else - lmins = (lmhi << PNG_HISHIFT) + lmlo; - } -#endif - - for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1, - pp = prev_row + 1; i < row_bytes; i++) - { - v = *dp++ = (png_byte)((int)*rp++ - (int)*pp++); - - sum += (v < 128) ? v : 256 - v; - - if (sum > lmins) /* We are already worse, don't continue. */ - break; - } - -#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED - if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) - { - int j; - png_uint_32 sumhi, sumlo; - sumlo = sum & PNG_LOMASK; - sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; - - for (j = 0; j < num_p_filters; j++) - { - if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP) - { - sumlo = (sumlo * png_ptr->filter_weights[j]) >> - PNG_WEIGHT_SHIFT; - - sumhi = (sumhi * png_ptr->filter_weights[j]) >> - PNG_WEIGHT_SHIFT; - } - } - - sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >> - PNG_COST_SHIFT; - - sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >> - PNG_COST_SHIFT; - - if (sumhi > PNG_HIMASK) - sum = PNG_MAXSUM; - - else - sum = (sumhi << PNG_HISHIFT) + sumlo; - } -#endif + sum = png_setup_up_row(png_ptr, row_bytes, lmins); if (sum < mins) { mins = sum; - best_row = png_ptr->up_row; + best_row = png_ptr->try_row; + if (png_ptr->tst_row != NULL) + { + png_ptr->try_row = png_ptr->tst_row; + png_ptr->tst_row = best_row; + } } } /* Avg filter */ if (filter_to_do == PNG_FILTER_AVG) { - png_bytep rp, dp, pp, lp; - png_uint_32 i; - - for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1, - pp = prev_row + 1; i < bpp; i++) - { - *dp++ = (png_byte)((int)*rp++ - ((int)*pp++ / 2)); - } - - for (lp = row_buf + 1; i < row_bytes; i++) - { - *dp++ = - (png_byte)((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2)); - } - best_row = png_ptr->avg_row; + (void) png_setup_avg_row(png_ptr, bpp, row_bytes, mins); + best_row = png_ptr->try_row; } else if ((filter_to_do & PNG_FILTER_AVG) != 0) { - png_bytep rp, dp, pp, lp; - png_uint_32 sum = 0, lmins = mins; - png_size_t i; - int v; + png_size_t sum; + png_size_t lmins = mins; -#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED - if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) - { - int j; - png_uint_32 lmhi, lmlo; - lmlo = lmins & PNG_LOMASK; - lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK; - - for (j = 0; j < num_p_filters; j++) - { - if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_AVG) - { - lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >> - PNG_WEIGHT_SHIFT; - - lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >> - PNG_WEIGHT_SHIFT; - } - } - - lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >> - PNG_COST_SHIFT; - - lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >> - PNG_COST_SHIFT; - - if (lmhi > PNG_HIMASK) - lmins = PNG_MAXSUM; - - else - lmins = (lmhi << PNG_HISHIFT) + lmlo; - } -#endif - - for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1, - pp = prev_row + 1; i < bpp; i++) - { - v = *dp++ = (png_byte)((int)*rp++ - ((int)*pp++ / 2)); - - sum += (v < 128) ? v : 256 - v; - } - - for (lp = row_buf + 1; i < row_bytes; i++) - { - v = *dp++ = - (png_byte)(((int)*rp++ - ((int)*pp++ + (int)*lp++) / 2)); - - sum += (v < 128) ? v : 256 - v; - - if (sum > lmins) /* We are already worse, don't continue. */ - break; - } - -#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED - if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) - { - int j; - png_uint_32 sumhi, sumlo; - sumlo = sum & PNG_LOMASK; - sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; - - for (j = 0; j < num_p_filters; j++) - { - if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE) - { - sumlo = (sumlo * png_ptr->filter_weights[j]) >> - PNG_WEIGHT_SHIFT; - - sumhi = (sumhi * png_ptr->filter_weights[j]) >> - PNG_WEIGHT_SHIFT; - } - } - - sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >> - PNG_COST_SHIFT; - - sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >> - PNG_COST_SHIFT; - - if (sumhi > PNG_HIMASK) - sum = PNG_MAXSUM; - - else - sum = (sumhi << PNG_HISHIFT) + sumlo; - } -#endif + sum= png_setup_avg_row(png_ptr, bpp, row_bytes, lmins); if (sum < mins) { mins = sum; - best_row = png_ptr->avg_row; + best_row = png_ptr->try_row; + if (png_ptr->tst_row != NULL) + { + png_ptr->try_row = png_ptr->tst_row; + png_ptr->tst_row = best_row; + } } } /* Paeth filter */ if ((filter_to_do == PNG_FILTER_PAETH) != 0) { - png_bytep rp, dp, pp, cp, lp; - png_size_t i; - - for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1, - pp = prev_row + 1; i < bpp; i++) - { - *dp++ = (png_byte)((int)*rp++ - (int)*pp++); - } - - for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++) - { - int a, b, c, pa, pb, pc, p; - - b = *pp++; - c = *cp++; - a = *lp++; - - p = b - c; - pc = a - c; - -#ifdef PNG_USE_ABS - pa = abs(p); - pb = abs(pc); - pc = abs(p + pc); -#else - pa = p < 0 ? -p : p; - pb = pc < 0 ? -pc : pc; - pc = (p + pc) < 0 ? -(p + pc) : p + pc; -#endif - - p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c; - - *dp++ = (png_byte)((int)*rp++ - p); - } - best_row = png_ptr->paeth_row; + (void) png_setup_paeth_row(png_ptr, bpp, row_bytes, mins); + best_row = png_ptr->try_row; } else if ((filter_to_do & PNG_FILTER_PAETH) != 0) { - png_bytep rp, dp, pp, cp, lp; - png_uint_32 sum = 0, lmins = mins; - png_size_t i; - int v; + png_size_t sum; + png_size_t lmins = mins; -#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED - if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) - { - int j; - png_uint_32 lmhi, lmlo; - lmlo = lmins & PNG_LOMASK; - lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK; - - for (j = 0; j < num_p_filters; j++) - { - if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH) - { - lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >> - PNG_WEIGHT_SHIFT; - - lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >> - PNG_WEIGHT_SHIFT; - } - } - - lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >> - PNG_COST_SHIFT; - - lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >> - PNG_COST_SHIFT; - - if (lmhi > PNG_HIMASK) - lmins = PNG_MAXSUM; - - else - lmins = (lmhi << PNG_HISHIFT) + lmlo; - } -#endif - - for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1, - pp = prev_row + 1; i < bpp; i++) - { - v = *dp++ = (png_byte)((int)*rp++ - (int)*pp++); - - sum += (v < 128) ? v : 256 - v; - } - - for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++) - { - int a, b, c, pa, pb, pc, p; - - b = *pp++; - c = *cp++; - a = *lp++; - -#ifndef PNG_SLOW_PAETH - p = b - c; - pc = a - c; -#ifdef PNG_USE_ABS - pa = abs(p); - pb = abs(pc); - pc = abs(p + pc); -#else - pa = p < 0 ? -p : p; - pb = pc < 0 ? -pc : pc; - pc = (p + pc) < 0 ? -(p + pc) : p + pc; -#endif - p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c; -#else /* SLOW_PAETH */ - p = a + b - c; - pa = abs(p - a); - pb = abs(p - b); - pc = abs(p - c); - - if (pa <= pb && pa <= pc) - p = a; - - else if (pb <= pc) - p = b; - - else - p = c; -#endif /* SLOW_PAETH */ - - v = *dp++ = (png_byte)((int)*rp++ - p); - - sum += (v < 128) ? v : 256 - v; - - if (sum > lmins) /* We are already worse, don't continue. */ - break; - } - -#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED - if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED) - { - int j; - png_uint_32 sumhi, sumlo; - sumlo = sum & PNG_LOMASK; - sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; - - for (j = 0; j < num_p_filters; j++) - { - if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH) - { - sumlo = (sumlo * png_ptr->filter_weights[j]) >> - PNG_WEIGHT_SHIFT; - - sumhi = (sumhi * png_ptr->filter_weights[j]) >> - PNG_WEIGHT_SHIFT; - } - } - - sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >> - PNG_COST_SHIFT; - - sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >> - PNG_COST_SHIFT; - - if (sumhi > PNG_HIMASK) - sum = PNG_MAXSUM; - - else - sum = (sumhi << PNG_HISHIFT) + sumlo; - } -#endif + sum = png_setup_paeth_row(png_ptr, bpp, row_bytes, lmins); if (sum < mins) { - best_row = png_ptr->paeth_row; + best_row = png_ptr->try_row; + if (png_ptr->tst_row != NULL) + { + png_ptr->try_row = png_ptr->tst_row; + png_ptr->tst_row = best_row; + } } } -#endif /* WRITE_FILTER */ /* Do the actual writing of the filtered row data from the chosen filter. */ png_write_filtered_row(png_ptr, best_row, row_info->rowbytes+1); -#ifdef PNG_WRITE_FILTER_SUPPORTED -#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED - /* Save the type of filter we picked this time for future calculations */ - if (png_ptr->num_prev_filters > 0) - { - int j; - - for (j = 1; j < num_p_filters; j++) - { - png_ptr->prev_filters[j] = png_ptr->prev_filters[j - 1]; - } - - png_ptr->prev_filters[j] = best_row[0]; - } -#endif #endif /* WRITE_FILTER */ } From 8611d127db0957aa0de65613a9d2626a6314122b Mon Sep 17 00:00:00 2001 From: Julien Malik Date: Fri, 22 Apr 2016 00:16:16 +0200 Subject: [PATCH 08/39] Import pnglibconf.h.prebuilt as new pnglibconf.h --- thirdparty/libpng/pnglibconf.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/thirdparty/libpng/pnglibconf.h b/thirdparty/libpng/pnglibconf.h index b4ec3c31..a1ef17f8 100644 --- a/thirdparty/libpng/pnglibconf.h +++ b/thirdparty/libpng/pnglibconf.h @@ -1,10 +1,10 @@ -/* libpng 1.6.17 STANDARD API DEFINITION */ +/* libpng 1.6.21 STANDARD API DEFINITION */ /* pnglibconf.h - library build configuration */ -/* Libpng version 1.6.17 - March 26, 2015 */ +/* Libpng version 1.6.21 - January 15, 2016 */ -/* Copyright (c) 1998-2014 Glenn Randers-Pehrson */ +/* Copyright (c) 1998-2015 Glenn Randers-Pehrson */ /* This code is released under the libpng license. */ /* For conditions of distribution and use, see the disclaimer */ @@ -101,8 +101,6 @@ #define PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED #define PNG_SEQUENTIAL_READ_SUPPORTED #define PNG_SETJMP_SUPPORTED -#define PNG_SET_CHUNK_CACHE_LIMIT_SUPPORTED -#define PNG_SET_CHUNK_MALLOC_LIMIT_SUPPORTED #define PNG_SET_OPTION_SUPPORTED #define PNG_SET_UNKNOWN_CHUNKS_SUPPORTED #define PNG_SET_USER_LIMITS_SUPPORTED @@ -187,11 +185,14 @@ /* end of options */ /* settings */ #define PNG_API_RULE 0 -#define PNG_COST_SHIFT 3 #define PNG_DEFAULT_READ_MACROS 1 #define PNG_GAMMA_THRESHOLD_FIXED 5000 #define PNG_IDAT_READ_SIZE PNG_ZBUF_SIZE #define PNG_INFLATE_BUF_SIZE 1024 +#define PNG_LINKAGE_API extern +#define PNG_LINKAGE_CALLBACK extern +#define PNG_LINKAGE_DATA extern +#define PNG_LINKAGE_FUNCTION extern #define PNG_MAX_GAMMA_8 11 #define PNG_QUANTIZE_BLUE_BITS 5 #define PNG_QUANTIZE_GREEN_BITS 5 @@ -202,7 +203,6 @@ #define PNG_USER_CHUNK_MALLOC_MAX 8000000 #define PNG_USER_HEIGHT_MAX 1000000 #define PNG_USER_WIDTH_MAX 1000000 -#define PNG_WEIGHT_SHIFT 8 #define PNG_ZBUF_SIZE 8192 #define PNG_ZLIB_VERNUM 0 /* unknown */ #define PNG_Z_DEFAULT_COMPRESSION (-1) From 54393d9e38ac9d170d1ca6ac0c348d5f539d117d Mon Sep 17 00:00:00 2001 From: mayeut Date: Sat, 23 Apr 2016 04:24:04 +0200 Subject: [PATCH 09/39] Allow to read 3/5/7/9/11/13/15 bpp TIF files --- src/bin/jp2/converttif.c | 408 +++++++++++++++++++++++- tests/nonregression/test_suite.ctest.in | 10 + 2 files changed, 416 insertions(+), 2 deletions(-) diff --git a/src/bin/jp2/converttif.c b/src/bin/jp2/converttif.c index dbda0741..ff30f422 100644 --- a/src/bin/jp2/converttif.c +++ b/src/bin/jp2/converttif.c @@ -313,6 +313,221 @@ int imagetotif(opj_image_t * image, const char *outfile) return 0; }/* imagetotif() */ +#define GETBITS(dest, nb) { \ + int needed = (nb); \ + unsigned int dst = 0U; \ + if (available == 0) { \ + val = *pSrc++; \ + available = 8; \ + } \ + while (needed > available) { \ + dst |= val & ((1U << available) - 1U); \ + needed -= available; \ + dst <<= needed; \ + val = *pSrc++; \ + available = 8; \ + } \ + dst |= (val >> (available - needed)) & ((1U << needed) - 1U); \ + available -= needed; \ + dest = (OPJ_INT32)dst; \ +} + +static void tif_3uto32s(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + for (i = 0; i < (length & ~(OPJ_SIZE_T)7U); i+=8U) { + OPJ_UINT32 val0 = *pSrc++; + OPJ_UINT32 val1 = *pSrc++; + OPJ_UINT32 val2 = *pSrc++; + + pDst[i+0] = (OPJ_INT32)((val0 >> 5)); + pDst[i+1] = (OPJ_INT32)(((val0 & 0x1FU) >> 2)); + pDst[i+2] = (OPJ_INT32)(((val0 & 0x3U) << 1) | (val1 >> 7)); + pDst[i+3] = (OPJ_INT32)(((val1 & 0x7FU) >> 4)); + pDst[i+4] = (OPJ_INT32)(((val1 & 0xFU) >> 1)); + pDst[i+5] = (OPJ_INT32)(((val1 & 0x1U) << 2) | (val2 >> 6)); + pDst[i+6] = (OPJ_INT32)(((val2 & 0x3FU) >> 3)); + pDst[i+7] = (OPJ_INT32)(((val2 & 0x7U))); + + } + if (length & 7U) { + unsigned int val; + int available = 0; + + length = length & 7U; + + GETBITS(pDst[i+0], 3) + + if (length > 1U) { + GETBITS(pDst[i+1], 3) + if (length > 2U) { + GETBITS(pDst[i+2], 3) + if (length > 3U) { + GETBITS(pDst[i+3], 3) + if (length > 4U) { + GETBITS(pDst[i+4], 3) + if (length > 5U) { + GETBITS(pDst[i+5], 3) + if (length > 6U) { + GETBITS(pDst[i+6], 3) + } + } + } + } + } + } + } +} +static void tif_5uto32s(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + for (i = 0; i < (length & ~(OPJ_SIZE_T)7U); i+=8U) { + OPJ_UINT32 val0 = *pSrc++; + OPJ_UINT32 val1 = *pSrc++; + OPJ_UINT32 val2 = *pSrc++; + OPJ_UINT32 val3 = *pSrc++; + OPJ_UINT32 val4 = *pSrc++; + + pDst[i+0] = (OPJ_INT32)((val0 >> 3)); + pDst[i+1] = (OPJ_INT32)(((val0 & 0x7U) << 2) | (val1 >> 6)); + pDst[i+2] = (OPJ_INT32)(((val1 & 0x3FU) >> 1)); + pDst[i+3] = (OPJ_INT32)(((val1 & 0x1U) << 4) | (val2 >> 4)); + pDst[i+4] = (OPJ_INT32)(((val2 & 0xFU) << 1) | (val3 >> 7)); + pDst[i+5] = (OPJ_INT32)(((val3 & 0x7FU) >> 2)); + pDst[i+6] = (OPJ_INT32)(((val3 & 0x3U) << 3) | (val4 >> 5)); + pDst[i+7] = (OPJ_INT32)(((val4 & 0x1FU))); + + } + if (length & 7U) { + unsigned int val; + int available = 0; + + length = length & 7U; + + GETBITS(pDst[i+0], 5) + + if (length > 1U) { + GETBITS(pDst[i+1], 5) + if (length > 2U) { + GETBITS(pDst[i+2], 5) + if (length > 3U) { + GETBITS(pDst[i+3], 5) + if (length > 4U) { + GETBITS(pDst[i+4], 5) + if (length > 5U) { + GETBITS(pDst[i+5], 5) + if (length > 6U) { + GETBITS(pDst[i+6], 5) + } + } + } + } + } + } + } +} +static void tif_7uto32s(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + for (i = 0; i < (length & ~(OPJ_SIZE_T)7U); i+=8U) { + OPJ_UINT32 val0 = *pSrc++; + OPJ_UINT32 val1 = *pSrc++; + OPJ_UINT32 val2 = *pSrc++; + OPJ_UINT32 val3 = *pSrc++; + OPJ_UINT32 val4 = *pSrc++; + OPJ_UINT32 val5 = *pSrc++; + OPJ_UINT32 val6 = *pSrc++; + + pDst[i+0] = (OPJ_INT32)((val0 >> 1)); + pDst[i+1] = (OPJ_INT32)(((val0 & 0x1U) << 6) | (val1 >> 2)); + pDst[i+2] = (OPJ_INT32)(((val1 & 0x3U) << 5) | (val2 >> 3)); + pDst[i+3] = (OPJ_INT32)(((val2 & 0x7U) << 4) | (val3 >> 4)); + pDst[i+4] = (OPJ_INT32)(((val3 & 0xFU) << 3) | (val4 >> 5)); + pDst[i+5] = (OPJ_INT32)(((val4 & 0x1FU) << 2) | (val5 >> 6)); + pDst[i+6] = (OPJ_INT32)(((val5 & 0x3FU) << 1) | (val6 >> 7)); + pDst[i+7] = (OPJ_INT32)(((val6 & 0x7FU))); + + } + if (length & 7U) { + unsigned int val; + int available = 0; + + length = length & 7U; + + GETBITS(pDst[i+0], 7) + + if (length > 1U) { + GETBITS(pDst[i+1], 7) + if (length > 2U) { + GETBITS(pDst[i+2], 7) + if (length > 3U) { + GETBITS(pDst[i+3], 7) + if (length > 4U) { + GETBITS(pDst[i+4], 7) + if (length > 5U) { + GETBITS(pDst[i+5], 7) + if (length > 6U) { + GETBITS(pDst[i+6], 7) + } + } + } + } + } + } + } +} +static void tif_9uto32s(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + for (i = 0; i < (length & ~(OPJ_SIZE_T)7U); i+=8U) { + OPJ_UINT32 val0 = *pSrc++; + OPJ_UINT32 val1 = *pSrc++; + OPJ_UINT32 val2 = *pSrc++; + OPJ_UINT32 val3 = *pSrc++; + OPJ_UINT32 val4 = *pSrc++; + OPJ_UINT32 val5 = *pSrc++; + OPJ_UINT32 val6 = *pSrc++; + OPJ_UINT32 val7 = *pSrc++; + OPJ_UINT32 val8 = *pSrc++; + + pDst[i+0] = (OPJ_INT32)((val0 << 1) | (val1 >> 7)); + pDst[i+1] = (OPJ_INT32)(((val1 & 0x7FU) << 2) | (val2 >> 6)); + pDst[i+2] = (OPJ_INT32)(((val2 & 0x3FU) << 3) | (val3 >> 5)); + pDst[i+3] = (OPJ_INT32)(((val3 & 0x1FU) << 4) | (val4 >> 4)); + pDst[i+4] = (OPJ_INT32)(((val4 & 0xFU) << 5) | (val5 >> 3)); + pDst[i+5] = (OPJ_INT32)(((val5 & 0x7U) << 6) | (val6 >> 2)); + pDst[i+6] = (OPJ_INT32)(((val6 & 0x3U) << 7) | (val7 >> 1)); + pDst[i+7] = (OPJ_INT32)(((val7 & 0x1U) << 8) | (val8)); + + } + if (length & 7U) { + unsigned int val; + int available = 0; + + length = length & 7U; + + GETBITS(pDst[i+0], 9) + + if (length > 1U) { + GETBITS(pDst[i+1], 9) + if (length > 2U) { + GETBITS(pDst[i+2], 9) + if (length > 3U) { + GETBITS(pDst[i+3], 9) + if (length > 4U) { + GETBITS(pDst[i+4], 9) + if (length > 5U) { + GETBITS(pDst[i+5], 9) + if (length > 6U) { + GETBITS(pDst[i+6], 9) + } + } + } + } + } + } + } +} static void tif_10uto32s(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, OPJ_SIZE_T length) { OPJ_SIZE_T i; @@ -345,6 +560,60 @@ static void tif_10uto32s(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, OPJ_SIZE_T lengt } } } +static void tif_11uto32s(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + for (i = 0; i < (length & ~(OPJ_SIZE_T)7U); i+=8U) { + OPJ_UINT32 val0 = *pSrc++; + OPJ_UINT32 val1 = *pSrc++; + OPJ_UINT32 val2 = *pSrc++; + OPJ_UINT32 val3 = *pSrc++; + OPJ_UINT32 val4 = *pSrc++; + OPJ_UINT32 val5 = *pSrc++; + OPJ_UINT32 val6 = *pSrc++; + OPJ_UINT32 val7 = *pSrc++; + OPJ_UINT32 val8 = *pSrc++; + OPJ_UINT32 val9 = *pSrc++; + OPJ_UINT32 val10 = *pSrc++; + + pDst[i+0] = (OPJ_INT32)((val0 << 3) | (val1 >> 5)); + pDst[i+1] = (OPJ_INT32)(((val1 & 0x1FU) << 6) | (val2 >> 2)); + pDst[i+2] = (OPJ_INT32)(((val2 & 0x3U) << 9) | (val3 << 1) | (val4 >> 7)); + pDst[i+3] = (OPJ_INT32)(((val4 & 0x7FU) << 4) | (val5 >> 4)); + pDst[i+4] = (OPJ_INT32)(((val5 & 0xFU) << 7) | (val6 >> 1)); + pDst[i+5] = (OPJ_INT32)(((val6 & 0x1U) << 10) | (val7 << 2) | (val8 >> 6)); + pDst[i+6] = (OPJ_INT32)(((val8 & 0x3FU) << 5) | (val9 >> 3)); + pDst[i+7] = (OPJ_INT32)(((val9 & 0x7U) << 8) | (val10)); + + } + if (length & 7U) { + unsigned int val; + int available = 0; + + length = length & 7U; + + GETBITS(pDst[i+0], 11) + + if (length > 1U) { + GETBITS(pDst[i+1], 11) + if (length > 2U) { + GETBITS(pDst[i+2], 11) + if (length > 3U) { + GETBITS(pDst[i+3], 11) + if (length > 4U) { + GETBITS(pDst[i+4], 11) + if (length > 5U) { + GETBITS(pDst[i+5], 11) + if (length > 6U) { + GETBITS(pDst[i+6], 11) + } + } + } + } + } + } + } +} static void tif_12uto32s(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, OPJ_SIZE_T length) { OPJ_SIZE_T i; @@ -362,6 +631,62 @@ static void tif_12uto32s(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, OPJ_SIZE_T lengt pDst[i+0] = (OPJ_INT32)((val0 << 4) | (val1 >> 4)); } } +static void tif_13uto32s(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + for (i = 0; i < (length & ~(OPJ_SIZE_T)7U); i+=8U) { + OPJ_UINT32 val0 = *pSrc++; + OPJ_UINT32 val1 = *pSrc++; + OPJ_UINT32 val2 = *pSrc++; + OPJ_UINT32 val3 = *pSrc++; + OPJ_UINT32 val4 = *pSrc++; + OPJ_UINT32 val5 = *pSrc++; + OPJ_UINT32 val6 = *pSrc++; + OPJ_UINT32 val7 = *pSrc++; + OPJ_UINT32 val8 = *pSrc++; + OPJ_UINT32 val9 = *pSrc++; + OPJ_UINT32 val10 = *pSrc++; + OPJ_UINT32 val11 = *pSrc++; + OPJ_UINT32 val12 = *pSrc++; + + pDst[i+0] = (OPJ_INT32)((val0 << 5) | (val1 >> 3)); + pDst[i+1] = (OPJ_INT32)(((val1 & 0x7U) << 10) | (val2 << 2) | (val3 >> 6)); + pDst[i+2] = (OPJ_INT32)(((val3 & 0x3FU) << 7) | (val4 >> 1)); + pDst[i+3] = (OPJ_INT32)(((val4 & 0x1U) << 12) | (val5 << 4) | (val6 >> 4)); + pDst[i+4] = (OPJ_INT32)(((val6 & 0xFU) << 9) | (val7 << 1) | (val8 >> 7)); + pDst[i+5] = (OPJ_INT32)(((val8 & 0x7FU) << 6) | (val9 >> 2)); + pDst[i+6] = (OPJ_INT32)(((val9 & 0x3U) << 11) | (val10 << 3) | (val11 >> 5)); + pDst[i+7] = (OPJ_INT32)(((val11 & 0x1FU) << 8) | (val12)); + + } + if (length & 7U) { + unsigned int val; + int available = 0; + + length = length & 7U; + + GETBITS(pDst[i+0], 13) + + if (length > 1U) { + GETBITS(pDst[i+1], 13) + if (length > 2U) { + GETBITS(pDst[i+2], 13) + if (length > 3U) { + GETBITS(pDst[i+3], 13) + if (length > 4U) { + GETBITS(pDst[i+4], 13) + if (length > 5U) { + GETBITS(pDst[i+5], 13) + if (length > 6U) { + GETBITS(pDst[i+6], 13) + } + } + } + } + } + } + } +} static void tif_14uto32s(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, OPJ_SIZE_T length) { OPJ_SIZE_T i; @@ -398,6 +723,64 @@ static void tif_14uto32s(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, OPJ_SIZE_T lengt } } } +static void tif_15uto32s(const OPJ_BYTE* pSrc, OPJ_INT32* pDst, OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + for (i = 0; i < (length & ~(OPJ_SIZE_T)7U); i+=8U) { + OPJ_UINT32 val0 = *pSrc++; + OPJ_UINT32 val1 = *pSrc++; + OPJ_UINT32 val2 = *pSrc++; + OPJ_UINT32 val3 = *pSrc++; + OPJ_UINT32 val4 = *pSrc++; + OPJ_UINT32 val5 = *pSrc++; + OPJ_UINT32 val6 = *pSrc++; + OPJ_UINT32 val7 = *pSrc++; + OPJ_UINT32 val8 = *pSrc++; + OPJ_UINT32 val9 = *pSrc++; + OPJ_UINT32 val10 = *pSrc++; + OPJ_UINT32 val11 = *pSrc++; + OPJ_UINT32 val12 = *pSrc++; + OPJ_UINT32 val13 = *pSrc++; + OPJ_UINT32 val14 = *pSrc++; + + pDst[i+0] = (OPJ_INT32)((val0 << 7) | (val1 >> 1)); + pDst[i+1] = (OPJ_INT32)(((val1 & 0x1U) << 14) | (val2 << 6) | (val3 >> 2)); + pDst[i+2] = (OPJ_INT32)(((val3 & 0x3U) << 13) | (val4 << 5) | (val5 >> 3)); + pDst[i+3] = (OPJ_INT32)(((val5 & 0x7U) << 12) | (val6 << 4) | (val7 >> 4)); + pDst[i+4] = (OPJ_INT32)(((val7 & 0xFU) << 11) | (val8 << 3) | (val9 >> 5)); + pDst[i+5] = (OPJ_INT32)(((val9 & 0x1FU) << 10) | (val10 << 2) | (val11 >> 6)); + pDst[i+6] = (OPJ_INT32)(((val11 & 0x3FU) << 9) | (val12 << 1) | (val13 >> 7)); + pDst[i+7] = (OPJ_INT32)(((val13 & 0x7FU) << 8) | (val14)); + + } + if (length & 7U) { + unsigned int val; + int available = 0; + + length = length & 7U; + + GETBITS(pDst[i+0], 15) + + if (length > 1U) { + GETBITS(pDst[i+1], 15) + if (length > 2U) { + GETBITS(pDst[i+2], 15) + if (length > 3U) { + GETBITS(pDst[i+3], 15) + if (length > 4U) { + GETBITS(pDst[i+4], 15) + if (length > 5U) { + GETBITS(pDst[i+5], 15) + if (length > 6U) { + GETBITS(pDst[i+6], 15) + } + } + } + } + } + } + } +} /* seems that libtiff decodes this to machine endianness */ static void tif_16uto32s(const OPJ_UINT16* pSrc, OPJ_INT32* pDst, OPJ_SIZE_T length) @@ -454,8 +837,8 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters) w= (int)tiWidth; h= (int)tiHeight; - if((tiBps > 16U) || ((tiBps != 1U) && (tiBps & 1U))) { - fprintf(stderr,"tiftoimage: Bits=%d, Only 1, 2, 4, 6, 8, 10, 12, 14 and 16 bits implemented\n",tiBps); + if(tiBps > 16U) { + fprintf(stderr,"tiftoimage: Bits=%d, Only 1 to 16 bits implemented\n",tiBps); fprintf(stderr,"\tAborting\n"); TIFFClose(tif); return NULL; @@ -476,15 +859,36 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters) cvtTifTo32s = convert_XXu32s_C1R_LUT[tiBps]; break; /* others are specific to TIFF */ + case 3: + cvtTifTo32s = tif_3uto32s; + break; + case 5: + cvtTifTo32s = tif_5uto32s; + break; + case 7: + cvtTifTo32s = tif_7uto32s; + break; + case 9: + cvtTifTo32s = tif_9uto32s; + break; case 10: cvtTifTo32s = tif_10uto32s; break; + case 11: + cvtTifTo32s = tif_11uto32s; + break; case 12: cvtTifTo32s = tif_12uto32s; break; + case 13: + cvtTifTo32s = tif_13uto32s; + break; case 14: cvtTifTo32s = tif_14uto32s; break; + case 15: + cvtTifTo32s = tif_15uto32s; + break; case 16: cvtTifTo32s = (convert_XXx32s_C1R)tif_16uto32s; break; diff --git a/tests/nonregression/test_suite.ctest.in b/tests/nonregression/test_suite.ctest.in index c316a5ea..97a53602 100644 --- a/tests/nonregression/test_suite.ctest.in +++ b/tests/nonregression/test_suite.ctest.in @@ -137,6 +137,16 @@ opj_compress -i @INPUT_NR_PATH@/pngsuite/ftp1n3p08.png -o @TEMP_PATH@/ftp1n3p08. # issue 571 Lossless is not lossless on linux x86 opj_compress -i @INPUT_NR_PATH@/issue571.tif -o @TEMP_PATH@/issue571.tif.j2k +# issue 729 Allow to read 3/5/7/9/11/13/15 bpp tif files +opj_compress -i @INPUT_NR_PATH@/flower-minisblack-03.tif -o @TEMP_PATH@/flower-minisblack-03.tif.jp2 +opj_compress -i @INPUT_NR_PATH@/flower-minisblack-05.tif -o @TEMP_PATH@/flower-minisblack-05.tif.jp2 +opj_compress -i @INPUT_NR_PATH@/flower-minisblack-07.tif -o @TEMP_PATH@/flower-minisblack-07.tif.jp2 +opj_compress -i @INPUT_NR_PATH@/flower-minisblack-09.tif -o @TEMP_PATH@/flower-minisblack-09.tif.jp2 +opj_compress -i @INPUT_NR_PATH@/flower-minisblack-11.tif -o @TEMP_PATH@/flower-minisblack-11.tif.jp2 +opj_compress -i @INPUT_NR_PATH@/flower-minisblack-13.tif -o @TEMP_PATH@/flower-minisblack-13.tif.jp2 +opj_compress -i @INPUT_NR_PATH@/flower-minisblack-15.tif -o @TEMP_PATH@/flower-minisblack-15.tif.jp2 + + # DECODER TEST SUITE opj_decompress -i @INPUT_NR_PATH@/Bretagne2.j2k -o @TEMP_PATH@/Bretagne2.j2k.pgx opj_decompress -i @INPUT_NR_PATH@/_00042.j2k -o @TEMP_PATH@/_00042.j2k.pgx From 74e814358c2530d238e3ada22d8eee6bf1d65283 Mon Sep 17 00:00:00 2001 From: mayeut Date: Sat, 23 Apr 2016 01:53:32 +0200 Subject: [PATCH 10/39] Allow to write 3/5/7/9/11/13/15 bpp TIF files Update uclouvain/openjpeg#729 --- src/bin/jp2/converttif.c | 413 +++++++++++++++++++++++- tests/nonregression/md5refs.txt | 28 ++ tests/nonregression/test_suite.ctest.in | 34 ++ 3 files changed, 473 insertions(+), 2 deletions(-) diff --git a/src/bin/jp2/converttif.c b/src/bin/jp2/converttif.c index ff30f422..143d3be6 100644 --- a/src/bin/jp2/converttif.c +++ b/src/bin/jp2/converttif.c @@ -56,6 +56,229 @@ TIFF IMAGE FORMAT <<-- <<-- <<-- <<-- */ +#define PUTBITS2(s, nb) \ + trailing <<= remaining; \ + trailing |= (unsigned int)((s) >> (nb - remaining)); \ + *pDst++ = (OPJ_BYTE)trailing; \ + trailing = (unsigned int)((s) & ((1U << (nb - remaining)) - 1U)); \ + if (nb >= (remaining + 8)) { \ + *pDst++ = (OPJ_BYTE)(trailing >> (nb - (remaining + 8))); \ + trailing &= (unsigned int)((1U << (nb - (remaining + 8))) - 1U); \ + remaining += 16 - nb; \ + } else { \ + remaining += 8 - nb; \ + } + +#define PUTBITS(s, nb) \ + if (nb >= remaining) { \ + PUTBITS2(s, nb) \ + } else { \ + trailing <<= nb; \ + trailing |= (unsigned int)(s); \ + remaining -= nb; \ + } +#define FLUSHBITS() \ + if (remaining != 8) { \ + trailing <<= remaining; \ + *pDst++ = (OPJ_BYTE)trailing; \ + } + +static void tif_32sto3u(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + + for (i = 0; i < (length & ~(OPJ_SIZE_T)7U); i+=8U) { + OPJ_UINT32 src0 = (OPJ_UINT32)pSrc[i+0]; + OPJ_UINT32 src1 = (OPJ_UINT32)pSrc[i+1]; + OPJ_UINT32 src2 = (OPJ_UINT32)pSrc[i+2]; + OPJ_UINT32 src3 = (OPJ_UINT32)pSrc[i+3]; + OPJ_UINT32 src4 = (OPJ_UINT32)pSrc[i+4]; + OPJ_UINT32 src5 = (OPJ_UINT32)pSrc[i+5]; + OPJ_UINT32 src6 = (OPJ_UINT32)pSrc[i+6]; + OPJ_UINT32 src7 = (OPJ_UINT32)pSrc[i+7]; + + *pDst++ = (OPJ_BYTE)((src0 << 5) | (src1 << 2) | (src2 >> 1)); + *pDst++ = (OPJ_BYTE)((src2 << 7) | (src3 << 4) | (src4 << 1) | (src5 >> 2)); + *pDst++ = (OPJ_BYTE)((src5 << 6) | (src6 << 3) | (src7)); + } + + if (length & 7U) { + unsigned int trailing = 0U; + int remaining = 8U; + length &= 7U; + PUTBITS((OPJ_UINT32)pSrc[i+0], 3) + if (length > 1U) { + PUTBITS((OPJ_UINT32)pSrc[i+1], 3) + if (length > 2U) { + PUTBITS((OPJ_UINT32)pSrc[i+2], 3) + if (length > 3U) { + PUTBITS((OPJ_UINT32)pSrc[i+3], 3) + if (length > 4U) { + PUTBITS((OPJ_UINT32)pSrc[i+4], 3) + if (length > 5U) { + PUTBITS((OPJ_UINT32)pSrc[i+5], 3) + if (length > 6U) { + PUTBITS((OPJ_UINT32)pSrc[i+6], 3) + } + } + } + } + } + } + FLUSHBITS() + } +} + +static void tif_32sto5u(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + + for (i = 0; i < (length & ~(OPJ_SIZE_T)7U); i+=8U) { + OPJ_UINT32 src0 = (OPJ_UINT32)pSrc[i+0]; + OPJ_UINT32 src1 = (OPJ_UINT32)pSrc[i+1]; + OPJ_UINT32 src2 = (OPJ_UINT32)pSrc[i+2]; + OPJ_UINT32 src3 = (OPJ_UINT32)pSrc[i+3]; + OPJ_UINT32 src4 = (OPJ_UINT32)pSrc[i+4]; + OPJ_UINT32 src5 = (OPJ_UINT32)pSrc[i+5]; + OPJ_UINT32 src6 = (OPJ_UINT32)pSrc[i+6]; + OPJ_UINT32 src7 = (OPJ_UINT32)pSrc[i+7]; + + *pDst++ = (OPJ_BYTE)((src0 << 3) | (src1 >> 2)); + *pDst++ = (OPJ_BYTE)((src1 << 6) | (src2 << 1) | (src3 >> 4)); + *pDst++ = (OPJ_BYTE)((src3 << 4) | (src4 >> 1)); + *pDst++ = (OPJ_BYTE)((src4 << 7) | (src5 << 2) | (src6 >> 3)); + *pDst++ = (OPJ_BYTE)((src6 << 5) | (src7)); + + } + + if (length & 7U) { + unsigned int trailing = 0U; + int remaining = 8U; + length &= 7U; + PUTBITS((OPJ_UINT32)pSrc[i+0], 5) + if (length > 1U) { + PUTBITS((OPJ_UINT32)pSrc[i+1], 5) + if (length > 2U) { + PUTBITS((OPJ_UINT32)pSrc[i+2], 5) + if (length > 3U) { + PUTBITS((OPJ_UINT32)pSrc[i+3], 5) + if (length > 4U) { + PUTBITS((OPJ_UINT32)pSrc[i+4], 5) + if (length > 5U) { + PUTBITS((OPJ_UINT32)pSrc[i+5], 5) + if (length > 6U) { + PUTBITS((OPJ_UINT32)pSrc[i+6], 5) + } + } + } + } + } + } + FLUSHBITS() + } +} + +static void tif_32sto7u(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + + for (i = 0; i < (length & ~(OPJ_SIZE_T)7U); i+=8U) { + OPJ_UINT32 src0 = (OPJ_UINT32)pSrc[i+0]; + OPJ_UINT32 src1 = (OPJ_UINT32)pSrc[i+1]; + OPJ_UINT32 src2 = (OPJ_UINT32)pSrc[i+2]; + OPJ_UINT32 src3 = (OPJ_UINT32)pSrc[i+3]; + OPJ_UINT32 src4 = (OPJ_UINT32)pSrc[i+4]; + OPJ_UINT32 src5 = (OPJ_UINT32)pSrc[i+5]; + OPJ_UINT32 src6 = (OPJ_UINT32)pSrc[i+6]; + OPJ_UINT32 src7 = (OPJ_UINT32)pSrc[i+7]; + + *pDst++ = (OPJ_BYTE)((src0 << 1) | (src1 >> 6)); + *pDst++ = (OPJ_BYTE)((src1 << 2) | (src2 >> 5)); + *pDst++ = (OPJ_BYTE)((src2 << 3) | (src3 >> 4)); + *pDst++ = (OPJ_BYTE)((src3 << 4) | (src4 >> 3)); + *pDst++ = (OPJ_BYTE)((src4 << 5) | (src5 >> 2)); + *pDst++ = (OPJ_BYTE)((src5 << 6) | (src6 >> 1)); + *pDst++ = (OPJ_BYTE)((src6 << 7) | (src7)); + } + + if (length & 7U) { + unsigned int trailing = 0U; + int remaining = 8U; + length &= 7U; + PUTBITS((OPJ_UINT32)pSrc[i+0], 7) + if (length > 1U) { + PUTBITS((OPJ_UINT32)pSrc[i+1], 7) + if (length > 2U) { + PUTBITS((OPJ_UINT32)pSrc[i+2], 7) + if (length > 3U) { + PUTBITS((OPJ_UINT32)pSrc[i+3], 7) + if (length > 4U) { + PUTBITS((OPJ_UINT32)pSrc[i+4], 7) + if (length > 5U) { + PUTBITS((OPJ_UINT32)pSrc[i+5], 7) + if (length > 6U) { + PUTBITS((OPJ_UINT32)pSrc[i+6], 7) + } + } + } + } + } + } + FLUSHBITS() + } +} + +static void tif_32sto9u(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + + for (i = 0; i < (length & ~(OPJ_SIZE_T)7U); i+=8U) { + OPJ_UINT32 src0 = (OPJ_UINT32)pSrc[i+0]; + OPJ_UINT32 src1 = (OPJ_UINT32)pSrc[i+1]; + OPJ_UINT32 src2 = (OPJ_UINT32)pSrc[i+2]; + OPJ_UINT32 src3 = (OPJ_UINT32)pSrc[i+3]; + OPJ_UINT32 src4 = (OPJ_UINT32)pSrc[i+4]; + OPJ_UINT32 src5 = (OPJ_UINT32)pSrc[i+5]; + OPJ_UINT32 src6 = (OPJ_UINT32)pSrc[i+6]; + OPJ_UINT32 src7 = (OPJ_UINT32)pSrc[i+7]; + + *pDst++ = (OPJ_BYTE)((src0 >> 1)); + *pDst++ = (OPJ_BYTE)((src0 << 7) | (src1 >> 2)); + *pDst++ = (OPJ_BYTE)((src1 << 6) | (src2 >> 3)); + *pDst++ = (OPJ_BYTE)((src2 << 5) | (src3 >> 4)); + *pDst++ = (OPJ_BYTE)((src3 << 4) | (src4 >> 5)); + *pDst++ = (OPJ_BYTE)((src4 << 3) | (src5 >> 6)); + *pDst++ = (OPJ_BYTE)((src5 << 2) | (src6 >> 7)); + *pDst++ = (OPJ_BYTE)((src6 << 1) | (src7 >> 8)); + *pDst++ = (OPJ_BYTE)(src7); + } + + if (length & 7U) { + unsigned int trailing = 0U; + int remaining = 8U; + length &= 7U; + PUTBITS2((OPJ_UINT32)pSrc[i+0], 9) + if (length > 1U) { + PUTBITS2((OPJ_UINT32)pSrc[i+1], 9) + if (length > 2U) { + PUTBITS2((OPJ_UINT32)pSrc[i+2], 9) + if (length > 3U) { + PUTBITS2((OPJ_UINT32)pSrc[i+3], 9) + if (length > 4U) { + PUTBITS2((OPJ_UINT32)pSrc[i+4], 9) + if (length > 5U) { + PUTBITS2((OPJ_UINT32)pSrc[i+5], 9) + if (length > 6U) { + PUTBITS2((OPJ_UINT32)pSrc[i+6], 9) + } + } + } + } + } + } + FLUSHBITS() + } +} static void tif_32sto10u(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, OPJ_SIZE_T length) { @@ -95,6 +318,59 @@ static void tif_32sto10u(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, OPJ_SIZE_T lengt } } } +static void tif_32sto11u(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + + for (i = 0; i < (length & ~(OPJ_SIZE_T)7U); i+=8U) { + OPJ_UINT32 src0 = (OPJ_UINT32)pSrc[i+0]; + OPJ_UINT32 src1 = (OPJ_UINT32)pSrc[i+1]; + OPJ_UINT32 src2 = (OPJ_UINT32)pSrc[i+2]; + OPJ_UINT32 src3 = (OPJ_UINT32)pSrc[i+3]; + OPJ_UINT32 src4 = (OPJ_UINT32)pSrc[i+4]; + OPJ_UINT32 src5 = (OPJ_UINT32)pSrc[i+5]; + OPJ_UINT32 src6 = (OPJ_UINT32)pSrc[i+6]; + OPJ_UINT32 src7 = (OPJ_UINT32)pSrc[i+7]; + + *pDst++ = (OPJ_BYTE)((src0 >> 3)); + *pDst++ = (OPJ_BYTE)((src0 << 5) | (src1 >> 6)); + *pDst++ = (OPJ_BYTE)((src1 << 2) | (src2 >> 9)); + *pDst++ = (OPJ_BYTE)((src2 >> 1)); + *pDst++ = (OPJ_BYTE)((src2 << 7) | (src3 >> 4)); + *pDst++ = (OPJ_BYTE)((src3 << 4) | (src4 >> 7)); + *pDst++ = (OPJ_BYTE)((src4 << 1) | (src5 >> 10)); + *pDst++ = (OPJ_BYTE)((src5 >> 2)); + *pDst++ = (OPJ_BYTE)((src5 << 6) | (src6 >> 5)); + *pDst++ = (OPJ_BYTE)((src6 << 3) | (src7 >> 8)); + *pDst++ = (OPJ_BYTE)(src7); + } + + if (length & 7U) { + unsigned int trailing = 0U; + int remaining = 8U; + length &= 7U; + PUTBITS2((OPJ_UINT32)pSrc[i+0], 11) + if (length > 1U) { + PUTBITS2((OPJ_UINT32)pSrc[i+1], 11) + if (length > 2U) { + PUTBITS2((OPJ_UINT32)pSrc[i+2], 11) + if (length > 3U) { + PUTBITS2((OPJ_UINT32)pSrc[i+3], 11) + if (length > 4U) { + PUTBITS2((OPJ_UINT32)pSrc[i+4], 11) + if (length > 5U) { + PUTBITS2((OPJ_UINT32)pSrc[i+5], 11) + if (length > 6U) { + PUTBITS2((OPJ_UINT32)pSrc[i+6], 11) + } + } + } + } + } + } + FLUSHBITS() + } +} static void tif_32sto12u(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, OPJ_SIZE_T length) { OPJ_SIZE_T i; @@ -113,6 +389,61 @@ static void tif_32sto12u(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, OPJ_SIZE_T lengt *pDst++ = (OPJ_BYTE)(((src0 & 0xFU) << 4)); } } +static void tif_32sto13u(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + + for (i = 0; i < (length & ~(OPJ_SIZE_T)7U); i+=8U) { + OPJ_UINT32 src0 = (OPJ_UINT32)pSrc[i+0]; + OPJ_UINT32 src1 = (OPJ_UINT32)pSrc[i+1]; + OPJ_UINT32 src2 = (OPJ_UINT32)pSrc[i+2]; + OPJ_UINT32 src3 = (OPJ_UINT32)pSrc[i+3]; + OPJ_UINT32 src4 = (OPJ_UINT32)pSrc[i+4]; + OPJ_UINT32 src5 = (OPJ_UINT32)pSrc[i+5]; + OPJ_UINT32 src6 = (OPJ_UINT32)pSrc[i+6]; + OPJ_UINT32 src7 = (OPJ_UINT32)pSrc[i+7]; + + *pDst++ = (OPJ_BYTE)((src0 >> 5)); + *pDst++ = (OPJ_BYTE)((src0 << 3) | (src1 >> 10)); + *pDst++ = (OPJ_BYTE)((src1 >> 2)); + *pDst++ = (OPJ_BYTE)((src1 << 6) | (src2 >> 7)); + *pDst++ = (OPJ_BYTE)((src2 << 1) | (src3 >> 12)); + *pDst++ = (OPJ_BYTE)((src3 >> 4)); + *pDst++ = (OPJ_BYTE)((src3 << 4) | (src4 >> 9)); + *pDst++ = (OPJ_BYTE)((src4 >> 1)); + *pDst++ = (OPJ_BYTE)((src4 << 7) | (src5 >> 6)); + *pDst++ = (OPJ_BYTE)((src5 << 2) | (src6 >> 11)); + *pDst++ = (OPJ_BYTE)((src6 >> 3)); + *pDst++ = (OPJ_BYTE)((src6 << 5) | (src7 >> 8)); + *pDst++ = (OPJ_BYTE)(src7); + } + + if (length & 7U) { + unsigned int trailing = 0U; + int remaining = 8U; + length &= 7U; + PUTBITS2((OPJ_UINT32)pSrc[i+0], 13) + if (length > 1U) { + PUTBITS2((OPJ_UINT32)pSrc[i+1], 13) + if (length > 2U) { + PUTBITS2((OPJ_UINT32)pSrc[i+2], 13) + if (length > 3U) { + PUTBITS2((OPJ_UINT32)pSrc[i+3], 13) + if (length > 4U) { + PUTBITS2((OPJ_UINT32)pSrc[i+4], 13) + if (length > 5U) { + PUTBITS2((OPJ_UINT32)pSrc[i+5], 13) + if (length > 6U) { + PUTBITS2((OPJ_UINT32)pSrc[i+6], 13) + } + } + } + } + } + } + FLUSHBITS() + } +} static void tif_32sto14u(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, OPJ_SIZE_T length) { OPJ_SIZE_T i; @@ -155,6 +486,63 @@ static void tif_32sto14u(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, OPJ_SIZE_T lengt } } } +static void tif_32sto15u(const OPJ_INT32* pSrc, OPJ_BYTE* pDst, OPJ_SIZE_T length) +{ + OPJ_SIZE_T i; + + for (i = 0; i < (length & ~(OPJ_SIZE_T)7U); i+=8U) { + OPJ_UINT32 src0 = (OPJ_UINT32)pSrc[i+0]; + OPJ_UINT32 src1 = (OPJ_UINT32)pSrc[i+1]; + OPJ_UINT32 src2 = (OPJ_UINT32)pSrc[i+2]; + OPJ_UINT32 src3 = (OPJ_UINT32)pSrc[i+3]; + OPJ_UINT32 src4 = (OPJ_UINT32)pSrc[i+4]; + OPJ_UINT32 src5 = (OPJ_UINT32)pSrc[i+5]; + OPJ_UINT32 src6 = (OPJ_UINT32)pSrc[i+6]; + OPJ_UINT32 src7 = (OPJ_UINT32)pSrc[i+7]; + + *pDst++ = (OPJ_BYTE)((src0 >> 7)); + *pDst++ = (OPJ_BYTE)((src0 << 1) | (src1 >> 14)); + *pDst++ = (OPJ_BYTE)((src1 >> 6)); + *pDst++ = (OPJ_BYTE)((src1 << 2) | (src2 >> 13)); + *pDst++ = (OPJ_BYTE)((src2 >> 5)); + *pDst++ = (OPJ_BYTE)((src2 << 3) | (src3 >> 12)); + *pDst++ = (OPJ_BYTE)((src3 >> 4)); + *pDst++ = (OPJ_BYTE)((src3 << 4) | (src4 >> 11)); + *pDst++ = (OPJ_BYTE)((src4 >> 3)); + *pDst++ = (OPJ_BYTE)((src4 << 5) | (src5 >> 10)); + *pDst++ = (OPJ_BYTE)((src5 >> 2)); + *pDst++ = (OPJ_BYTE)((src5 << 6) | (src6 >> 9)); + *pDst++ = (OPJ_BYTE)((src6 >> 1)); + *pDst++ = (OPJ_BYTE)((src6 << 7) | (src7 >> 8)); + *pDst++ = (OPJ_BYTE)(src7); + } + + if (length & 7U) { + unsigned int trailing = 0U; + int remaining = 8U; + length &= 7U; + PUTBITS2((OPJ_UINT32)pSrc[i+0], 15) + if (length > 1U) { + PUTBITS2((OPJ_UINT32)pSrc[i+1], 15) + if (length > 2U) { + PUTBITS2((OPJ_UINT32)pSrc[i+2], 15) + if (length > 3U) { + PUTBITS2((OPJ_UINT32)pSrc[i+3], 15) + if (length > 4U) { + PUTBITS2((OPJ_UINT32)pSrc[i+4], 15) + if (length > 5U) { + PUTBITS2((OPJ_UINT32)pSrc[i+5], 15) + if (length > 6U) { + PUTBITS2((OPJ_UINT32)pSrc[i+6], 15) + } + } + } + } + } + } + FLUSHBITS() + } +} static void tif_32sto16u(const OPJ_INT32* pSrc, OPJ_UINT16* pDst, OPJ_SIZE_T length) { OPJ_SIZE_T i; @@ -223,10 +611,10 @@ int imagetotif(opj_image_t * image, const char *outfile) return 1; } - if((bps > 16) || ((bps != 1) && (bps & 1))) bps = 0; + if(bps > 16) bps = 0; if(bps == 0) { - fprintf(stderr,"imagetotif: Bits=%d, Only 1, 2, 4, 6, 8, 10, 12, 14 and 16 bits implemented\n",bps); + fprintf(stderr,"imagetotif: Bits=%d, Only 1 to 16 bits implemented\n",bps); fprintf(stderr,"\tAborting\n"); return 1; } @@ -248,15 +636,36 @@ int imagetotif(opj_image_t * image, const char *outfile) case 8: cvt32sToTif = convert_32sXXu_C1R_LUT[bps]; break; + case 3: + cvt32sToTif = tif_32sto3u; + break; + case 5: + cvt32sToTif = tif_32sto5u; + break; + case 7: + cvt32sToTif = tif_32sto7u; + break; + case 9: + cvt32sToTif = tif_32sto9u; + break; case 10: cvt32sToTif = tif_32sto10u; break; + case 11: + cvt32sToTif = tif_32sto11u; + break; case 12: cvt32sToTif = tif_32sto12u; break; + case 13: + cvt32sToTif = tif_32sto13u; + break; case 14: cvt32sToTif = tif_32sto14u; break; + case 15: + cvt32sToTif = tif_32sto15u; + break; case 16: cvt32sToTif = (convert_32sXXx_C1R)tif_32sto16u; break; diff --git a/tests/nonregression/md5refs.txt b/tests/nonregression/md5refs.txt index 499441c0..541a44df 100644 --- a/tests/nonregression/md5refs.txt +++ b/tests/nonregression/md5refs.txt @@ -182,40 +182,68 @@ d33fb5dbddb9b9b4438eb51fa27445a3 issue495.jp2_0.pgx 97da625d2f2d0b75bf891d8083ce8bfb issue495.jp2_2.pgx 86729c5f2b74b2dfd42cb0d8e47aef79 a1_mono_tif-1.tif fa9b7b896536b25a7a1d8eeeacb59141 a1_mono_tif-10.tif +e1f194f69d1c58ce8bed62cd4f1d5b6a a1_mono_tif-11.tif b0ee13aa90ca4421e09a3b7b41f410c0 a1_mono_tif-12.tif +de53251a33356e206a793fbdbaf90db2 a1_mono_tif-13.tif 4699894fedd3758727d8288cd7adb56c a1_mono_tif-14.tif +012958af4207f4a779c0cdc9e18bc9be a1_mono_tif-15.tif 4ad682c58e63d3223914c10a6656c8ae a1_mono_tif-16.tif 22c2fa09a4d7b9fade6a3cddc6c6a4dc a1_mono_tif-2.tif +7aea003d047d6c26475d0d257a0cfdfc a1_mono_tif-3.tif 996c5e67a663218be90e86bff8ecad89 a1_mono_tif-4.tif +0489a5d490588fa603a8e59af60ef8fc a1_mono_tif-5.tif 7f451a5ac89915c5cdc023fd8c813a3c a1_mono_tif-6.tif +e164a6c0219737ee05a3d55d6e3a3104 a1_mono_tif-7.tif c3ebfcf478b1c4fc786748813f2b5d53 a1_mono_tif-8.tif +67adb084f1fe234f240a1d0b2698507e a1_mono_tif-9.tif 31650ec40241737634179fff6ad306f8 basn4a08_tif-1.tif abf884080bcfbf58c044a9d86bfa5e5d basn4a08_tif-10.tif +b0d82c12aa2c9b3ecd96c6a5b5663a8c basn4a08_tif-11.tif 916d97c098d9792993cc91fee4a83f77 basn4a08_tif-12.tif +90cabbb0f401b75dcfa64e4fbb987020 basn4a08_tif-13.tif 57643174986481d336db6ddf04b970df basn4a08_tif-14.tif +3cbf7868617a0dfdbeddd5c50ea96b31 basn4a08_tif-15.tif fb5cf848d63c61dc485c87c9246ee9c7 basn4a08_tif-16.tif 5d7b01d98c82ad563bb28c2d83484a2a basn4a08_tif-2.tif +7928de544e7d9731572a625beeb2b3ee basn4a08_tif-3.tif 2401cebbb1d5494fcbe0d899484c342d basn4a08_tif-4.tif +05ea9dfd48a6cd613bf935394988ec38 basn4a08_tif-5.tif 6dbeb5b708bbde76e204c0887da61f6b basn4a08_tif-6.tif +18a59ac6036ee64e92af19b7e3cd3d64 basn4a08_tif-7.tif dc40cc1da6de28e7e973c8ba796ca189 basn4a08_tif-8.tif +824b776a5aa3459b77894b5f77621311 basn4a08_tif-9.tif 59e32c45591fd3bb44fe99381a116ba1 basn6a08_tif-1.tif 630e6fb6deba0b3efd93b610561d607a basn6a08_tif-10.tif +5419fec92f0e0e5907d838dacf9712b4 basn6a08_tif-11.tif 765555e75e59de27f7b2177d04f36bc1 basn6a08_tif-12.tif +7d20d3e026fc1ac25be16dd44e9fb2e5 basn6a08_tif-13.tif 62384c112d5fe40aefd0a9b0b9a4bcc6 basn6a08_tif-14.tif +325de66e18e133f2ad865fc1faa20439 basn6a08_tif-15.tif d725d41557658a28ab31dff74e2467fa basn6a08_tif-16.tif 96d91df6b10e866ea26ebbf0b8ddc7da basn6a08_tif-2.tif +36690c1fe565b6efc229f5c7e486de31 basn6a08_tif-3.tif a324032339808d5fe85d6e354f14c183 basn6a08_tif-4.tif +64dfb6af672ea8e890e24cfb208c6755 basn6a08_tif-5.tif d60864a6a5c8a49a202d98ae6f5165c7 basn6a08_tif-6.tif +086fd12fec963995fe2e405dcef7e477 basn6a08_tif-7.tif c3e93f61125f82a9832d0b9440468034 basn6a08_tif-8.tif +a9723dcc0732e74c9e8cd2bf93474a7d basn6a08_tif-9.tif cfe04d15cf9d615fc36357dcb3b3956b p0_14_tif-1.tif 9ad87e7fddc77ac85e2e92509bee2365 p0_14_tif-10.tif +f144e26d6d5aa24d98f0415f10751025 p0_14_tif-11.tif 38e67f9d573e61166761d5eee0104448 p0_14_tif-12.tif +4e804903537e4c52a7e4c15bd74eb15c p0_14_tif-13.tif 77486f0468694b94290d0b55361498a0 p0_14_tif-14.tif +2aa3211823a8ee41cc5061f401dfd52d p0_14_tif-15.tif 51be675689949dd08b6ee1427af3eb4a p0_14_tif-16.tif 3e34e94bd8f7380c8d159676fee9ea57 p0_14_tif-2.tif +f623c6b98711ba8582f2b60620c6494a p0_14_tif-3.tif b6f71c941e3a5b8d2547792ccec58d54 p0_14_tif-4.tif +5a8498d473cc57318ab9d216fdc5dcc9 p0_14_tif-5.tif 81fcdd90917efb95aed94c6522d1c188 p0_14_tif-6.tif +951c99efbd922d8f3feb015e9ef8e350 p0_14_tif-7.tif 6808377b760b4ef3559ba8b14ed9b91a p0_14_tif-8.tif +96aa7dafa873d0ce33f84bb1ff78fa9b p0_14_tif-9.tif dd15b3d487d36a3682be0679300a4319 issue235.jp2_0.pgx b9cd6dc76b141fb1fec15f50c1f70e01 issue235.jp2_1.pgx 3edef2ae197ef30b08deda1b28825399 issue235.jp2_2.pgx diff --git a/tests/nonregression/test_suite.ctest.in b/tests/nonregression/test_suite.ctest.in index 97a53602..e6e90303 100644 --- a/tests/nonregression/test_suite.ctest.in +++ b/tests/nonregression/test_suite.ctest.in @@ -518,3 +518,37 @@ opj_decompress -i @INPUT_NR_PATH@/issue559-eci-091-CIELab.jp2 -o @TEMP_PATH@/iss # issue 653 Last box of undefined size byg opj_decompress -i @INPUT_NR_PATH@/issue653-zero-unknownbox.jp2 -o @TEMP_PATH@/issue653-zero-unknownbox.jp2.png -p 8S + +# issue 729 decompress 3/5/7/9/11/13/15 bits precision to tiff +# GRAYSCALE +opj_decompress -i @INPUT_CONF_PATH@/a1_mono.j2c -o @TEMP_PATH@/a1_mono_tif-3.tif -p 3S +opj_decompress -i @INPUT_CONF_PATH@/a1_mono.j2c -o @TEMP_PATH@/a1_mono_tif-5.tif -p 5S +opj_decompress -i @INPUT_CONF_PATH@/a1_mono.j2c -o @TEMP_PATH@/a1_mono_tif-7.tif -p 7S +opj_decompress -i @INPUT_CONF_PATH@/a1_mono.j2c -o @TEMP_PATH@/a1_mono_tif-9.tif -p 9S +opj_decompress -i @INPUT_CONF_PATH@/a1_mono.j2c -o @TEMP_PATH@/a1_mono_tif-11.tif -p 11S +opj_decompress -i @INPUT_CONF_PATH@/a1_mono.j2c -o @TEMP_PATH@/a1_mono_tif-13.tif -p 13S +opj_decompress -i @INPUT_CONF_PATH@/a1_mono.j2c -o @TEMP_PATH@/a1_mono_tif-15.tif -p 15S +# GRAYSCALE ALPHA +opj_decompress -i @INPUT_NR_PATH@/basn4a08.jp2 -o @TEMP_PATH@/basn4a08_tif-3.tif -p 3S +opj_decompress -i @INPUT_NR_PATH@/basn4a08.jp2 -o @TEMP_PATH@/basn4a08_tif-5.tif -p 5S +opj_decompress -i @INPUT_NR_PATH@/basn4a08.jp2 -o @TEMP_PATH@/basn4a08_tif-7.tif -p 7S +opj_decompress -i @INPUT_NR_PATH@/basn4a08.jp2 -o @TEMP_PATH@/basn4a08_tif-9.tif -p 9S +opj_decompress -i @INPUT_NR_PATH@/basn4a08.jp2 -o @TEMP_PATH@/basn4a08_tif-11.tif -p 11S +opj_decompress -i @INPUT_NR_PATH@/basn4a08.jp2 -o @TEMP_PATH@/basn4a08_tif-13.tif -p 13S +opj_decompress -i @INPUT_NR_PATH@/basn4a08.jp2 -o @TEMP_PATH@/basn4a08_tif-15.tif -p 15S +# RGB +opj_decompress -i @INPUT_CONF_PATH@/p0_14.j2k -o @TEMP_PATH@/p0_14_tif-3.tif -p 3S +opj_decompress -i @INPUT_CONF_PATH@/p0_14.j2k -o @TEMP_PATH@/p0_14_tif-5.tif -p 5S +opj_decompress -i @INPUT_CONF_PATH@/p0_14.j2k -o @TEMP_PATH@/p0_14_tif-7.tif -p 7S +opj_decompress -i @INPUT_CONF_PATH@/p0_14.j2k -o @TEMP_PATH@/p0_14_tif-9.tif -p 9S +opj_decompress -i @INPUT_CONF_PATH@/p0_14.j2k -o @TEMP_PATH@/p0_14_tif-11.tif -p 11S +opj_decompress -i @INPUT_CONF_PATH@/p0_14.j2k -o @TEMP_PATH@/p0_14_tif-13.tif -p 13S +opj_decompress -i @INPUT_CONF_PATH@/p0_14.j2k -o @TEMP_PATH@/p0_14_tif-15.tif -p 15S +# RGBA +opj_decompress -i @INPUT_NR_PATH@/basn6a08.jp2 -o @TEMP_PATH@/basn6a08_tif-3.tif -p 3S +opj_decompress -i @INPUT_NR_PATH@/basn6a08.jp2 -o @TEMP_PATH@/basn6a08_tif-5.tif -p 5S +opj_decompress -i @INPUT_NR_PATH@/basn6a08.jp2 -o @TEMP_PATH@/basn6a08_tif-7.tif -p 7S +opj_decompress -i @INPUT_NR_PATH@/basn6a08.jp2 -o @TEMP_PATH@/basn6a08_tif-9.tif -p 9S +opj_decompress -i @INPUT_NR_PATH@/basn6a08.jp2 -o @TEMP_PATH@/basn6a08_tif-11.tif -p 11S +opj_decompress -i @INPUT_NR_PATH@/basn6a08.jp2 -o @TEMP_PATH@/basn6a08_tif-13.tif -p 13S +opj_decompress -i @INPUT_NR_PATH@/basn6a08.jp2 -o @TEMP_PATH@/basn6a08_tif-15.tif -p 15S From c559c628539bc8956193a5ff8ac787a0c6fa090c Mon Sep 17 00:00:00 2001 From: Matthieu Darbois Date: Sat, 23 Apr 2016 14:17:31 +0200 Subject: [PATCH 11/39] Do not define __attribute__ in opj_includes.h (#751) Fix #727 --- src/lib/openjp2/opj_includes.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/lib/openjp2/opj_includes.h b/src/lib/openjp2/opj_includes.h index f855b7c6..5add0918 100644 --- a/src/lib/openjp2/opj_includes.h +++ b/src/lib/openjp2/opj_includes.h @@ -102,12 +102,6 @@ ========================================================== */ -/* Ignore GCC attributes if this is not GCC */ -#ifndef __GNUC__ - #define __attribute__(x) /* __attribute__(x) */ -#endif - - /* Are restricted pointers available? (C99) */ #if (__STDC_VERSION__ != 199901L) /* Not a C99 compiler */ From 6f2ac3ee366a9b587abe9a72febc400ba5b98c24 Mon Sep 17 00:00:00 2001 From: Matthieu Darbois Date: Tue, 26 Apr 2016 22:06:06 +0200 Subject: [PATCH 12/39] Fix negative shift left reported by UBSan (#757) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This shall have no performance impact on 2’s complement machine where the compiler replaces the multiplication by power of two (constant) by a left shift. Verified at least on MacOS Xcode 7.3, same assembly generated after fix. --- src/lib/openjp2/t1.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/openjp2/t1.c b/src/lib/openjp2/t1.c index 108ce78b..8d020bb5 100644 --- a/src/lib/openjp2/t1.c +++ b/src/lib/openjp2/t1.c @@ -1514,7 +1514,7 @@ OPJ_BOOL opj_t1_encode_cblks( opj_t1_t *t1, if (tccp->qmfbid == 1) { for (j = 0; j < cblk_h; ++j) { for (i = 0; i < cblk_w; ++i) { - tiledp[tileIndex] <<= T1_NMSEDEC_FRACBITS; + tiledp[tileIndex] *= 1 << T1_NMSEDEC_FRACBITS; tileIndex++; } tileIndex += tileLineAdvance; From 2296dc9e68e0ebc8342a8669aa2398a029b0fa3f Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Tue, 26 Apr 2016 22:12:11 +0200 Subject: [PATCH 13/39] Remove whitespace and CR at line endings (#678) Signed-off-by: Stefan Weil --- src/lib/openmj2/opj_malloc.h | 330 +++++++++++++++++------------------ 1 file changed, 165 insertions(+), 165 deletions(-) diff --git a/src/lib/openmj2/opj_malloc.h b/src/lib/openmj2/opj_malloc.h index 1b62ab02..ffac8961 100644 --- a/src/lib/openmj2/opj_malloc.h +++ b/src/lib/openmj2/opj_malloc.h @@ -1,165 +1,165 @@ -/* - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * Copyright (c) 2007, Callum Lerwick - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -#ifndef __OPJ_MALLOC_H -#define __OPJ_MALLOC_H -/** -@file opj_malloc.h -@brief Internal functions - -The functions in opj_malloc.h are internal utilities used for memory management. -*/ - -/** @defgroup MISC MISC - Miscellaneous internal functions */ -/*@{*/ - -/** @name Exported functions */ -/*@{*/ -/* ----------------------------------------------------------------------- */ - -/** -Allocate an uninitialized memory block -@param size Bytes to allocate -@return Returns a void pointer to the allocated space, or NULL if there is insufficient memory available -*/ -#ifdef ALLOC_PERF_OPT -void * OPJ_CALLCONV opj_malloc(size_t size); -#else -#define opj_malloc(size) malloc(size) -#endif - -/** -Allocate a memory block with elements initialized to 0 -@param num Blocks to allocate -@param size Bytes per block to allocate -@return Returns a void pointer to the allocated space, or NULL if there is insufficient memory available -*/ -#ifdef ALLOC_PERF_OPT -void * OPJ_CALLCONV opj_calloc(size_t _NumOfElements, size_t _SizeOfElements); -#else -#define opj_calloc(num, size) calloc(num, size) -#endif - -/** -Allocate memory aligned to a 16 byte boundary -@param size Bytes to allocate -@return Returns a void pointer to the allocated space, or NULL if there is insufficient memory available -*/ -/* FIXME: These should be set with cmake tests, but we're currently not requiring use of cmake */ -#ifdef _WIN32 - /* Someone should tell the mingw people that their malloc.h ought to provide _mm_malloc() */ - #ifdef __GNUC__ - #include - #define HAVE_MM_MALLOC - #else /* MSVC, Intel C++ */ - #include - #ifdef _mm_malloc - #define HAVE_MM_MALLOC - #endif - #endif -#else /* Not _WIN32 */ - #if defined(__sun) - #define HAVE_MEMALIGN - #elif defined(__FreeBSD__) - #define HAVE_POSIX_MEMALIGN - /* Linux x86_64 and OSX always align allocations to 16 bytes */ - #elif !defined(__amd64__) && !defined(__APPLE__) && !defined(_AIX) - #define HAVE_MEMALIGN - #include - #endif -#endif - -#define opj_aligned_malloc(size) malloc(size) -#define opj_aligned_free(m) free(m) - -#ifdef HAVE_MM_MALLOC - #undef opj_aligned_malloc - #define opj_aligned_malloc(size) _mm_malloc(size, 16) - #undef opj_aligned_free - #define opj_aligned_free(m) _mm_free(m) -#endif - -#ifdef HAVE_MEMALIGN - extern void* memalign(size_t, size_t); - #undef opj_aligned_malloc - #define opj_aligned_malloc(size) memalign(16, (size)) - #undef opj_aligned_free - #define opj_aligned_free(m) free(m) -#endif - -#ifdef HAVE_POSIX_MEMALIGN - #undef opj_aligned_malloc - extern int posix_memalign(void**, size_t, size_t); - - static INLINE void* __attribute__ ((malloc)) opj_aligned_malloc(size_t size){ - void* mem = NULL; - posix_memalign(&mem, 16, size); - return mem; - } - #undef opj_aligned_free - #define opj_aligned_free(m) free(m) -#endif - -#ifdef ALLOC_PERF_OPT - #undef opj_aligned_malloc - #define opj_aligned_malloc(size) opj_malloc(size) - #undef opj_aligned_free - #define opj_aligned_free(m) opj_free(m) -#endif - -/** -Reallocate memory blocks. -@param m Pointer to previously allocated memory block -@param s New size in bytes -@return Returns a void pointer to the reallocated (and possibly moved) memory block -*/ -#ifdef ALLOC_PERF_OPT -void * OPJ_CALLCONV opj_realloc(void * m, size_t s); -#else -#define opj_realloc(m, s) realloc(m, s) -#endif - -/** -Deallocates or frees a memory block. -@param m Previously allocated memory block to be freed -*/ -#ifdef ALLOC_PERF_OPT -void OPJ_CALLCONV opj_free(void * m); -#else -#define opj_free(m) free(m) -#endif - -#ifdef __GNUC__ -#pragma GCC poison malloc calloc realloc free -#endif - -/* ----------------------------------------------------------------------- */ -/*@}*/ - -/*@}*/ - -#endif /* __OPJ_MALLOC_H */ - +/* + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * Copyright (c) 2007, Callum Lerwick + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef __OPJ_MALLOC_H +#define __OPJ_MALLOC_H +/** +@file opj_malloc.h +@brief Internal functions + +The functions in opj_malloc.h are internal utilities used for memory management. +*/ + +/** @defgroup MISC MISC - Miscellaneous internal functions */ +/*@{*/ + +/** @name Exported functions */ +/*@{*/ +/* ----------------------------------------------------------------------- */ + +/** +Allocate an uninitialized memory block +@param size Bytes to allocate +@return Returns a void pointer to the allocated space, or NULL if there is insufficient memory available +*/ +#ifdef ALLOC_PERF_OPT +void * OPJ_CALLCONV opj_malloc(size_t size); +#else +#define opj_malloc(size) malloc(size) +#endif + +/** +Allocate a memory block with elements initialized to 0 +@param num Blocks to allocate +@param size Bytes per block to allocate +@return Returns a void pointer to the allocated space, or NULL if there is insufficient memory available +*/ +#ifdef ALLOC_PERF_OPT +void * OPJ_CALLCONV opj_calloc(size_t _NumOfElements, size_t _SizeOfElements); +#else +#define opj_calloc(num, size) calloc(num, size) +#endif + +/** +Allocate memory aligned to a 16 byte boundary +@param size Bytes to allocate +@return Returns a void pointer to the allocated space, or NULL if there is insufficient memory available +*/ +/* FIXME: These should be set with cmake tests, but we're currently not requiring use of cmake */ +#ifdef _WIN32 + /* Someone should tell the mingw people that their malloc.h ought to provide _mm_malloc() */ + #ifdef __GNUC__ + #include + #define HAVE_MM_MALLOC + #else /* MSVC, Intel C++ */ + #include + #ifdef _mm_malloc + #define HAVE_MM_MALLOC + #endif + #endif +#else /* Not _WIN32 */ + #if defined(__sun) + #define HAVE_MEMALIGN + #elif defined(__FreeBSD__) + #define HAVE_POSIX_MEMALIGN + /* Linux x86_64 and OSX always align allocations to 16 bytes */ + #elif !defined(__amd64__) && !defined(__APPLE__) && !defined(_AIX) + #define HAVE_MEMALIGN + #include + #endif +#endif + +#define opj_aligned_malloc(size) malloc(size) +#define opj_aligned_free(m) free(m) + +#ifdef HAVE_MM_MALLOC + #undef opj_aligned_malloc + #define opj_aligned_malloc(size) _mm_malloc(size, 16) + #undef opj_aligned_free + #define opj_aligned_free(m) _mm_free(m) +#endif + +#ifdef HAVE_MEMALIGN + extern void* memalign(size_t, size_t); + #undef opj_aligned_malloc + #define opj_aligned_malloc(size) memalign(16, (size)) + #undef opj_aligned_free + #define opj_aligned_free(m) free(m) +#endif + +#ifdef HAVE_POSIX_MEMALIGN + #undef opj_aligned_malloc + extern int posix_memalign(void**, size_t, size_t); + + static INLINE void* __attribute__ ((malloc)) opj_aligned_malloc(size_t size){ + void* mem = NULL; + posix_memalign(&mem, 16, size); + return mem; + } + #undef opj_aligned_free + #define opj_aligned_free(m) free(m) +#endif + +#ifdef ALLOC_PERF_OPT + #undef opj_aligned_malloc + #define opj_aligned_malloc(size) opj_malloc(size) + #undef opj_aligned_free + #define opj_aligned_free(m) opj_free(m) +#endif + +/** +Reallocate memory blocks. +@param m Pointer to previously allocated memory block +@param s New size in bytes +@return Returns a void pointer to the reallocated (and possibly moved) memory block +*/ +#ifdef ALLOC_PERF_OPT +void * OPJ_CALLCONV opj_realloc(void * m, size_t s); +#else +#define opj_realloc(m, s) realloc(m, s) +#endif + +/** +Deallocates or frees a memory block. +@param m Previously allocated memory block to be freed +*/ +#ifdef ALLOC_PERF_OPT +void OPJ_CALLCONV opj_free(void * m); +#else +#define opj_free(m) free(m) +#endif + +#ifdef __GNUC__ +#pragma GCC poison malloc calloc realloc free +#endif + +/* ----------------------------------------------------------------------- */ +/*@}*/ + +/*@}*/ + +#endif /* __OPJ_MALLOC_H */ + From e6881e75279627096fbbaca19e837252737a3892 Mon Sep 17 00:00:00 2001 From: Matthieu Darbois Date: Wed, 27 Apr 2016 21:56:09 +0200 Subject: [PATCH 14/39] Fix negative shift left reported by UBSan (#758) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Follow-up of #757 This shall have no performance impact on 2’s complement machine where the compiler replaces the multiplication by power of two (constant) by a left shift. Verified at least on MacOS Xcode 7.3, same assembly generated after fix. --- src/lib/openjp2/t1.c | 2 +- src/lib/openjp2/tcd.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/openjp2/t1.c b/src/lib/openjp2/t1.c index 8d020bb5..a3ca93e8 100644 --- a/src/lib/openjp2/t1.c +++ b/src/lib/openjp2/t1.c @@ -1514,7 +1514,7 @@ OPJ_BOOL opj_t1_encode_cblks( opj_t1_t *t1, if (tccp->qmfbid == 1) { for (j = 0; j < cblk_h; ++j) { for (i = 0; i < cblk_w; ++i) { - tiledp[tileIndex] *= 1 << T1_NMSEDEC_FRACBITS; + tiledp[tileIndex] *= (1 << T1_NMSEDEC_FRACBITS); tileIndex++; } tileIndex += tileLineAdvance; diff --git a/src/lib/openjp2/tcd.c b/src/lib/openjp2/tcd.c index 6eeb211e..af6b53f5 100644 --- a/src/lib/openjp2/tcd.c +++ b/src/lib/openjp2/tcd.c @@ -1911,7 +1911,7 @@ static OPJ_BOOL opj_tcd_dc_level_shift_encode ( opj_tcd_t *p_tcd ) } else { for (i = 0; i < l_nb_elem; ++i) { - *l_current_ptr = (*l_current_ptr - l_tccp->m_dc_level_shift) << 11 ; + *l_current_ptr = (*l_current_ptr - l_tccp->m_dc_level_shift) * (1 << 11); ++l_current_ptr; } } From 5947e10ff7bebdcc8f72ab9246f03db05582fa0a Mon Sep 17 00:00:00 2001 From: julienmalik Date: Wed, 27 Apr 2016 23:05:43 +0200 Subject: [PATCH 15/39] Add clang 3.9 build to Travis matrix (#753) --- .travis.yml | 4 +++ tools/travis-ci/install.sh | 30 +++++++++++++++++++ ...untu12.04-clang3.9.0-x86_64-Debug-3rdP.txt | 8 +++++ ...tu12.04-clang3.9.0-x86_64-Release-3rdP.txt | 8 +++++ 4 files changed, 50 insertions(+) create mode 100644 tools/travis-ci/knownfailures-Ubuntu12.04-clang3.9.0-x86_64-Debug-3rdP.txt create mode 100644 tools/travis-ci/knownfailures-Ubuntu12.04-clang3.9.0-x86_64-Release-3rdP.txt diff --git a/.travis.yml b/.travis.yml index 07dedbc4..d53145f3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,6 +21,10 @@ matrix: - os: linux compiler: clang env: OPJ_CI_ARCH=x86_64 OPJ_CI_BUILD_CONFIGURATION=Debug OPJ_CI_ASAN=1 + - os: linux + compiler: clang-3.9 + env: OPJ_CI_ARCH=x86_64 OPJ_CI_BUILD_CONFIGURATION=Release + sudo: true - os: linux compiler: x86_64-w64-mingw32-gcc env: OPJ_CI_ARCH=x86_64 OPJ_CI_BUILD_CONFIGURATION=Release diff --git a/tools/travis-ci/install.sh b/tools/travis-ci/install.sh index 003f8fa8..1a4c0bb9 100755 --- a/tools/travis-ci/install.sh +++ b/tools/travis-ci/install.sh @@ -115,3 +115,33 @@ if [ "${OPJ_CI_SKIP_TESTS:-}" != "1" ]; then fi fi fi + +# Install clang if necessary. +# clang-3.4 is available on base image +# For more up-to-date versions, use packages from http://llvm.org/apt +# Cannot use addons.apt.packages because clang-3.9 is currently on hold +# (see https://github.com/travis-ci/apt-package-whitelist/pull/2780 or https://github.com/travis-ci/apt-package-whitelist/pull/2770) +# "sudo: required" should be set in .travis.yml matrix for those configurations +if echo "${CC:-}" | egrep -q "^clang-3.[7-9]?$" ; then + case "${CC:-}" in + clang-3.7) + echo "deb http://llvm.org/apt/precise/ llvm-toolchain-precise-3.7 main" | sudo tee /etc/apt/sources.list.d/llvm.list + ;; + clang-3.8) + echo "deb http://llvm.org/apt/precise/ llvm-toolchain-precise-3.8 main" | sudo tee /etc/apt/sources.list.d/llvm.list + ;; + clang-3.9) + echo "deb http://llvm.org/apt/precise/ llvm-toolchain-precise main" | sudo tee /etc/apt/sources.list.d/llvm.list + ;; + *) + echo "We should never have been there. Exiting..." + exit 1 + esac + wget -O - http://llvm.org/apt/llvm-snapshot.gpg.key | sudo apt-key add - + + # On precise, ubuntu-toolchain ppa must be installed also (see http://llvm.org/apt) + sudo add-apt-repository --yes ppa:ubuntu-toolchain-r/test + + sudo apt-get update -qq + sudo apt-get install "${CC:-}" -y +fi diff --git a/tools/travis-ci/knownfailures-Ubuntu12.04-clang3.9.0-x86_64-Debug-3rdP.txt b/tools/travis-ci/knownfailures-Ubuntu12.04-clang3.9.0-x86_64-Debug-3rdP.txt new file mode 100644 index 00000000..2554d91c --- /dev/null +++ b/tools/travis-ci/knownfailures-Ubuntu12.04-clang3.9.0-x86_64-Debug-3rdP.txt @@ -0,0 +1,8 @@ +NR-ENC-X_4_2K_24_185_CBR_WB_000.tif-15-compare_dec-ref-out2base +NR-ENC-X_5_2K_24_235_CBR_STEM24_000.tif-16-compare_dec-ref-out2base +NR-ENC-X_6_2K_24_FULL_CBR_CIRCLE_000.tif-17-compare_dec-ref-out2base +NR-ENC-X_4_2K_24_185_CBR_WB_000.tif-18-compare_dec-ref-out2base +NR-ENC-X_5_2K_24_235_CBR_STEM24_000.tif-19-compare_dec-ref-out2base +NR-ENC-X_6_2K_24_FULL_CBR_CIRCLE_000.tif-20-compare_dec-ref-out2base +NR-ENC-ElephantDream_4K.tif-21-compare_dec-ref-out2base +NR-ENC-issue141.rawl-23-compare_dec-ref-out2base diff --git a/tools/travis-ci/knownfailures-Ubuntu12.04-clang3.9.0-x86_64-Release-3rdP.txt b/tools/travis-ci/knownfailures-Ubuntu12.04-clang3.9.0-x86_64-Release-3rdP.txt new file mode 100644 index 00000000..2554d91c --- /dev/null +++ b/tools/travis-ci/knownfailures-Ubuntu12.04-clang3.9.0-x86_64-Release-3rdP.txt @@ -0,0 +1,8 @@ +NR-ENC-X_4_2K_24_185_CBR_WB_000.tif-15-compare_dec-ref-out2base +NR-ENC-X_5_2K_24_235_CBR_STEM24_000.tif-16-compare_dec-ref-out2base +NR-ENC-X_6_2K_24_FULL_CBR_CIRCLE_000.tif-17-compare_dec-ref-out2base +NR-ENC-X_4_2K_24_185_CBR_WB_000.tif-18-compare_dec-ref-out2base +NR-ENC-X_5_2K_24_235_CBR_STEM24_000.tif-19-compare_dec-ref-out2base +NR-ENC-X_6_2K_24_FULL_CBR_CIRCLE_000.tif-20-compare_dec-ref-out2base +NR-ENC-ElephantDream_4K.tif-21-compare_dec-ref-out2base +NR-ENC-issue141.rawl-23-compare_dec-ref-out2base From 20789fed4ec7746e938dd2934a1fb5aa352f4d12 Mon Sep 17 00:00:00 2001 From: mayeut Date: Mon, 25 Jan 2016 22:16:49 +0100 Subject: [PATCH 16/39] Fix issue 135 dwt_interleave_h.gsr105.jp2 now has the same output as kakadu issue399 is corrupted. Only the corrupted part changes. Update known failures for x86 MD5 NR-DEC-kodak_2layers_lrcp.j2c-31-decode-md5 NR-DEC-kodak_2layers_lrcp.j2c-32-decode-md5 NR-DEC-issue135.j2k-68-decode-md5 --- src/lib/openjp2/t1.c | 2 +- tests/nonregression/md5refs.txt | 28 +++++++++---------- ...Ubuntu12.04-gcc4.6.3-i386-Release-3rdP.txt | 6 ++-- ...Ubuntu12.04-gcc4.6.4-i386-Release-3rdP.txt | 6 ++-- ...Ubuntu14.04-gcc4.8.4-i386-Release-3rdP.txt | 5 ++-- tools/travis-ci/knownfailures-all.txt | 1 - ...ilures-windows-vs2010-x86-Release-3rdP.txt | 5 ++-- ...ilures-windows-vs2015-x64-Release-3rdP.txt | 2 -- ...ilures-windows-vs2015-x86-Release-3rdP.txt | 2 -- 9 files changed, 27 insertions(+), 30 deletions(-) diff --git a/src/lib/openjp2/t1.c b/src/lib/openjp2/t1.c index a3ca93e8..05a3da66 100644 --- a/src/lib/openjp2/t1.c +++ b/src/lib/openjp2/t1.c @@ -1405,7 +1405,7 @@ static OPJ_BOOL opj_t1_decode_cblk(opj_t1_t *t1, } } - for (passno = 0; passno < seg->real_num_passes; ++passno) { + for (passno = 0; (passno < seg->real_num_passes) && (bpno_plus_one >= 1); ++passno) { switch (passtype) { case 0: if (type == T1_TYPE_RAW) { diff --git a/tests/nonregression/md5refs.txt b/tests/nonregression/md5refs.txt index 541a44df..ecd4f545 100644 --- a/tests/nonregression/md5refs.txt +++ b/tests/nonregression/md5refs.txt @@ -21,9 +21,9 @@ cccccccccccccccccccccccccccccccc issue104_jpxstream.jp2_2.pgx c74edbb49e132b2cfc1eaf7908197b17 issue134.jp2_0.pgx 16fe8ed450da10a6aaae4cf6f467fc21 issue134.jp2_1.pgx c6091c07bf0ff221008dfb60d893cdff issue134.jp2_2.pgx -cccccccccccccccccccccccccccccccc issue135.j2k_0.pgx -cccccccccccccccccccccccccccccccc issue135.j2k_1.pgx -cccccccccccccccccccccccccccccccc issue135.j2k_2.pgx +bee38bdc0dde1a891a8d9650f475db38 issue135.j2k_0.pgx +dbabd772b1e53959e1e1c4bdf58e0108 issue135.j2k_1.pgx +65d5ed69d3c994f33d3a9d649ec6f1da issue135.j2k_2.pgx aa7461b31e14641586803b23b7fb04f2 issue142.j2k_0.pgx a809006e7a0c1eed68bc86c96af43fe3 issue142.j2k_1.pgx 74f7a7a194a74a947245b843c62c4054 issue142.j2k_2.pgx @@ -52,12 +52,12 @@ e58242abc2c6d44df187397c55e6fbff issue254.jp2_2.pgx ce4e556aaa0844b92a92c35c200fc43e j2k32.j2k_1.pgx ea926520f990640862f3fe6616097613 j2k32.j2k_2.pgx 66b60e866991e03f9a2de18e80d3102b kakadu_v4-4_openjpegv2_broken.j2k_0.pgx -12a8a4668315d9ae27969991251ce85f kodak_2layers_lrcp.j2c_0.pgx -56d0b0c547d6d5bb12f0c36e88722b11 kodak_2layers_lrcp.j2c_1.pgx -48ba092fb40090c160bbd08bdf7bdbf2 kodak_2layers_lrcp.j2c_2.pgx -12a8a4668315d9ae27969991251ce85f kodak_2layers_lrcp-l2.j2c_0.pgx -56d0b0c547d6d5bb12f0c36e88722b11 kodak_2layers_lrcp-l2.j2c_1.pgx -48ba092fb40090c160bbd08bdf7bdbf2 kodak_2layers_lrcp-l2.j2c_2.pgx +bee38bdc0dde1a891a8d9650f475db38 kodak_2layers_lrcp.j2c_0.pgx +dbabd772b1e53959e1e1c4bdf58e0108 kodak_2layers_lrcp.j2c_1.pgx +65d5ed69d3c994f33d3a9d649ec6f1da kodak_2layers_lrcp.j2c_2.pgx +bee38bdc0dde1a891a8d9650f475db38 kodak_2layers_lrcp-l2.j2c_0.pgx +dbabd772b1e53959e1e1c4bdf58e0108 kodak_2layers_lrcp-l2.j2c_1.pgx +65d5ed69d3c994f33d3a9d649ec6f1da kodak_2layers_lrcp-l2.j2c_2.pgx 05c062aca83d13b8095460f38a690a08 MarkerIsNotCompliant.j2k_0.pgx ff73d2bd32951d9e55b02186aac24aff Marrin.jp2_0.pgx 55ce884dd2346af6a5172a434ee578fa Marrin.jp2_1.pgx @@ -148,7 +148,7 @@ c494419005e8aae82f46d3f48da6caf1 p1_06.j2k.png 6ae110e1fb5a869af3dbc5fbc735b0bd relax.jp2_0.pgx 518a8f28dacc034982507f43763b88dd relax.jp2_1.pgx c678b04f4d3e59b9d66a8bce37c553c0 relax.jp2_2.pgx -cdb1d69eb48ffd8545751326b86d9d7e test_lossless.j2k_0.pgx +1090301e16fcfdecf3419bccad61cdeb test_lossless.j2k_0.pgx efc9c7f21a542a7888a9eeb73b0f7092 text_GBR.jp2_0.pgx 54790b332b3dcbda28e1bcb31270b946 text_GBR.jp2_1.pgx d9bcbdc818febb8c0a6bc5f940a4ea85 text_GBR.jp2_2.pgx @@ -163,7 +163,7 @@ a73bec4d6d82c8a64203e8fdf893b86d issue428.jp2_0.pgx 8b96a253937c4c7dd6b41b4aa11367d9 issue414.jp2_2.pgx ec6886229ffaeaddfe22ce02b7a75e15 issue414.jp2_3.pgx 6aa5c69c83d6f4d5d65968f34f9bc2a3 issue414.jp2_4.pgx -00f34217ad2f88f4d4e1c5cd0d2c4329 issue399.j2k_0.pgx +296038e047bb6aaf0e6652cb1b301e60 issue399.j2k_0.pgx d8fb69def2a48a3686483c4353544f4b issue411-ycc444.jp2_0.pgx d2911f75ed1758057f9b1bf26bcb2400 issue411-ycc444.jp2_1.pgx f7c23ee589ceda07ffb77a83018606cc issue411-ycc444.jp2_2.pgx @@ -284,9 +284,9 @@ fc2844a9f3c8e924e349180ba9e122dd p0_14_png-2.png 0c1cc85c051dd95394d06103c8d9bbef p0_14_png-6.png 230e4968cb445b222ee2095014ba1d26 p0_14_png-8.png 5a6131ad9ea5d191ffcdf6435be89cb4 v4dwt_interleave_h.gsr105.j2k_0.pgx -4426ed46f75a45782c551d82818b9e60 dwt_interleave_h.gsr105.jp2_0.pgx -382e7297e062d729a7a7726e964f1a0a dwt_interleave_h.gsr105.jp2_1.pgx -64c1027db97421e348f823178b5d9c4b dwt_interleave_h.gsr105.jp2_2.pgx +65e41ed91283b5e2f0c79ee1c867a86c dwt_interleave_h.gsr105.jp2_0.pgx +8d7685f1569d446787476c0a56c93750 dwt_interleave_h.gsr105.jp2_1.pgx +ddfff2ce2df4a9102518c92a362e6d25 dwt_interleave_h.gsr105.jp2_2.pgx 63bf755af5a1f8a478d65079dc7c8964 issue205-tif.jp2.tif b01ed87dbac424bc820b2ac590e4884e issue236-ESYCC-CDEF.jp2_0.pgx 2635cc00b1e18ef11adcba09e845d459 issue236-ESYCC-CDEF.jp2_1.pgx diff --git a/tools/travis-ci/knownfailures-Ubuntu12.04-gcc4.6.3-i386-Release-3rdP.txt b/tools/travis-ci/knownfailures-Ubuntu12.04-gcc4.6.3-i386-Release-3rdP.txt index 2c74d31a..40b84e5f 100644 --- a/tools/travis-ci/knownfailures-Ubuntu12.04-gcc4.6.3-i386-Release-3rdP.txt +++ b/tools/travis-ci/knownfailures-Ubuntu12.04-gcc4.6.3-i386-Release-3rdP.txt @@ -21,8 +21,6 @@ NR-DEC-_00042.j2k-2-decode-md5 NR-DEC-buxI.j2k-9-decode-md5 NR-DEC-CT_Phillips_JPEG2K_Decompr_Problem.j2k-13-decode-md5 NR-DEC-Marrin.jp2-18-decode-md5 -NR-DEC-kodak_2layers_lrcp.j2c-31-decode-md5 -NR-DEC-kodak_2layers_lrcp.j2c-32-decode-md5 NR-DEC-file409752.jp2-40-decode-md5 NR-DEC-issue188_beach_64bitsbox.jp2-41-decode-md5 NR-DEC-issue206_image-000.jp2-42-decode-md5 @@ -31,7 +29,6 @@ NR-DEC-issue228.j2k-60-decode-md5 NR-DEC-issue134.jp2-67-decode-md5 NR-DEC-issue208.jp2-69-decode-md5 NR-DEC-issue211.jp2-70-decode-md5 -NR-DEC-issue135.j2k-68-decode-md5 NR-DEC-issue414.jp2-110-decode-md5 NR-DEC-p1_04.j2k-124-decode-md5 NR-DEC-p1_04.j2k-125-decode-md5 @@ -51,3 +48,6 @@ NR-DEC-issue559-eci-090-CIELab.jp2-255-decode-md5 NR-DEC-issue236-ESYCC-CDEF.jp2-254-decode-md5 NR-DEC-issue559-eci-091-CIELab.jp2-256-decode-md5 NR-DEC-p1_06.j2k-164-decode +NR-DEC-kodak_2layers_lrcp.j2c-31-decode-md5 +NR-DEC-kodak_2layers_lrcp.j2c-32-decode-md5 +NR-DEC-issue135.j2k-68-decode-md5 diff --git a/tools/travis-ci/knownfailures-Ubuntu12.04-gcc4.6.4-i386-Release-3rdP.txt b/tools/travis-ci/knownfailures-Ubuntu12.04-gcc4.6.4-i386-Release-3rdP.txt index 2c74d31a..40b84e5f 100644 --- a/tools/travis-ci/knownfailures-Ubuntu12.04-gcc4.6.4-i386-Release-3rdP.txt +++ b/tools/travis-ci/knownfailures-Ubuntu12.04-gcc4.6.4-i386-Release-3rdP.txt @@ -21,8 +21,6 @@ NR-DEC-_00042.j2k-2-decode-md5 NR-DEC-buxI.j2k-9-decode-md5 NR-DEC-CT_Phillips_JPEG2K_Decompr_Problem.j2k-13-decode-md5 NR-DEC-Marrin.jp2-18-decode-md5 -NR-DEC-kodak_2layers_lrcp.j2c-31-decode-md5 -NR-DEC-kodak_2layers_lrcp.j2c-32-decode-md5 NR-DEC-file409752.jp2-40-decode-md5 NR-DEC-issue188_beach_64bitsbox.jp2-41-decode-md5 NR-DEC-issue206_image-000.jp2-42-decode-md5 @@ -31,7 +29,6 @@ NR-DEC-issue228.j2k-60-decode-md5 NR-DEC-issue134.jp2-67-decode-md5 NR-DEC-issue208.jp2-69-decode-md5 NR-DEC-issue211.jp2-70-decode-md5 -NR-DEC-issue135.j2k-68-decode-md5 NR-DEC-issue414.jp2-110-decode-md5 NR-DEC-p1_04.j2k-124-decode-md5 NR-DEC-p1_04.j2k-125-decode-md5 @@ -51,3 +48,6 @@ NR-DEC-issue559-eci-090-CIELab.jp2-255-decode-md5 NR-DEC-issue236-ESYCC-CDEF.jp2-254-decode-md5 NR-DEC-issue559-eci-091-CIELab.jp2-256-decode-md5 NR-DEC-p1_06.j2k-164-decode +NR-DEC-kodak_2layers_lrcp.j2c-31-decode-md5 +NR-DEC-kodak_2layers_lrcp.j2c-32-decode-md5 +NR-DEC-issue135.j2k-68-decode-md5 diff --git a/tools/travis-ci/knownfailures-Ubuntu14.04-gcc4.8.4-i386-Release-3rdP.txt b/tools/travis-ci/knownfailures-Ubuntu14.04-gcc4.8.4-i386-Release-3rdP.txt index fe66aa36..2e33de84 100644 --- a/tools/travis-ci/knownfailures-Ubuntu14.04-gcc4.8.4-i386-Release-3rdP.txt +++ b/tools/travis-ci/knownfailures-Ubuntu14.04-gcc4.8.4-i386-Release-3rdP.txt @@ -15,8 +15,6 @@ NR-DEC-_00042.j2k-2-decode-md5 NR-DEC-buxI.j2k-9-decode-md5 NR-DEC-CT_Phillips_JPEG2K_Decompr_Problem.j2k-13-decode-md5 NR-DEC-Marrin.jp2-18-decode-md5 -NR-DEC-kodak_2layers_lrcp.j2c-31-decode-md5 -NR-DEC-kodak_2layers_lrcp.j2c-32-decode-md5 NR-DEC-file409752.jp2-40-decode-md5 NR-DEC-issue188_beach_64bitsbox.jp2-41-decode-md5 NR-DEC-issue206_image-000.jp2-42-decode-md5 @@ -43,3 +41,6 @@ NR-DEC-issue205.jp2-253-decode-md5 NR-DEC-issue236-ESYCC-CDEF.jp2-254-decode-md5 NR-DEC-issue559-eci-090-CIELab.jp2-255-decode-md5 NR-DEC-issue559-eci-091-CIELab.jp2-256-decode-md5 +NR-DEC-kodak_2layers_lrcp.j2c-31-decode-md5 +NR-DEC-kodak_2layers_lrcp.j2c-32-decode-md5 +NR-DEC-issue135.j2k-68-decode-md5 diff --git a/tools/travis-ci/knownfailures-all.txt b/tools/travis-ci/knownfailures-all.txt index e2c01aaa..bfcfa0a0 100644 --- a/tools/travis-ci/knownfailures-all.txt +++ b/tools/travis-ci/knownfailures-all.txt @@ -1,6 +1,5 @@ NR-DEC-p1_06.j2k-164-decode NR-DEC-issue104_jpxstream.jp2-33-decode-md5 -NR-DEC-issue135.j2k-68-decode-md5 NR-DEC-issue226.j2k-74-decode-md5 NR-DEC-p1_06.j2k-156-decode-md5 NR-DEC-p1_06.j2k-164-decode-md5 diff --git a/tools/travis-ci/knownfailures-windows-vs2010-x86-Release-3rdP.txt b/tools/travis-ci/knownfailures-windows-vs2010-x86-Release-3rdP.txt index d243c235..ac826b32 100644 --- a/tools/travis-ci/knownfailures-windows-vs2010-x86-Release-3rdP.txt +++ b/tools/travis-ci/knownfailures-windows-vs2010-x86-Release-3rdP.txt @@ -14,8 +14,6 @@ NR-DEC-_00042.j2k-2-decode-md5 NR-DEC-buxI.j2k-9-decode-md5 NR-DEC-CT_Phillips_JPEG2K_Decompr_Problem.j2k-13-decode-md5 NR-DEC-Marrin.jp2-18-decode-md5 -NR-DEC-kodak_2layers_lrcp.j2c-31-decode-md5 -NR-DEC-kodak_2layers_lrcp.j2c-32-decode-md5 NR-DEC-file409752.jp2-40-decode-md5 NR-DEC-issue188_beach_64bitsbox.jp2-41-decode-md5 NR-DEC-issue206_image-000.jp2-42-decode-md5 @@ -44,3 +42,6 @@ NR-DEC-issue559-eci-090-CIELab.jp2-255-decode-md5 NR-DEC-issue559-eci-091-CIELab.jp2-256-decode-md5 ETS-C1P0-p0_12.j2k-compare2ref NR-C1P0-p0_12.j2k-compare2base +NR-DEC-kodak_2layers_lrcp.j2c-31-decode-md5 +NR-DEC-kodak_2layers_lrcp.j2c-32-decode-md5 +NR-DEC-issue135.j2k-68-decode-md5 diff --git a/tools/travis-ci/knownfailures-windows-vs2015-x64-Release-3rdP.txt b/tools/travis-ci/knownfailures-windows-vs2015-x64-Release-3rdP.txt index e52efb85..dd0782c2 100644 --- a/tools/travis-ci/knownfailures-windows-vs2015-x64-Release-3rdP.txt +++ b/tools/travis-ci/knownfailures-windows-vs2015-x64-Release-3rdP.txt @@ -1,5 +1,3 @@ NR-ENC-Bretagne2.ppm-7-compare_dec-ref-out2base -NR-DEC-kodak_2layers_lrcp.j2c-31-decode-md5 -NR-DEC-kodak_2layers_lrcp.j2c-32-decode-md5 ETS-C1P0-p0_12.j2k-compare2ref NR-C1P0-p0_12.j2k-compare2base diff --git a/tools/travis-ci/knownfailures-windows-vs2015-x86-Release-3rdP.txt b/tools/travis-ci/knownfailures-windows-vs2015-x86-Release-3rdP.txt index e52efb85..dd0782c2 100644 --- a/tools/travis-ci/knownfailures-windows-vs2015-x86-Release-3rdP.txt +++ b/tools/travis-ci/knownfailures-windows-vs2015-x86-Release-3rdP.txt @@ -1,5 +1,3 @@ NR-ENC-Bretagne2.ppm-7-compare_dec-ref-out2base -NR-DEC-kodak_2layers_lrcp.j2c-31-decode-md5 -NR-DEC-kodak_2layers_lrcp.j2c-32-decode-md5 ETS-C1P0-p0_12.j2k-compare2ref NR-C1P0-p0_12.j2k-compare2base From 66fd497765939d02e8816d6d019839388fffdf79 Mon Sep 17 00:00:00 2001 From: Matthieu Darbois Date: Thu, 28 Apr 2016 00:18:37 +0200 Subject: [PATCH 17/39] Fix unsigned int overflow reported by UBSan (#759) --- src/lib/openjp2/tcd.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/lib/openjp2/tcd.c b/src/lib/openjp2/tcd.c index af6b53f5..d590046f 100644 --- a/src/lib/openjp2/tcd.c +++ b/src/lib/openjp2/tcd.c @@ -778,7 +778,7 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no, l_tilec->resolutions_size = l_data_size; } - l_level_no = l_tilec->numresolutions - 1; + l_level_no = l_tilec->numresolutions; l_res = l_tilec->resolutions; l_step_size = l_tccp->stepsizes; if (l_tccp->qmfbid == 0) { @@ -795,6 +795,8 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no, OPJ_UINT32 cbgwidthexpn, cbgheightexpn; OPJ_UINT32 cblkwidthexpn, cblkheightexpn; + --l_level_no; + /* border for each resolution level (global) */ l_res->x0 = opj_int_ceildivpow2(l_tilec->x0, (OPJ_INT32)l_level_no); l_res->y0 = opj_int_ceildivpow2(l_tilec->y0, (OPJ_INT32)l_level_no); @@ -1024,7 +1026,6 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no, ++l_step_size; } /* bandno */ ++l_res; - --l_level_no; } /* resno */ ++l_tccp; ++l_tilec; From e982d0396607a16ca0c373020cc93449504eb4e8 Mon Sep 17 00:00:00 2001 From: julienmalik Date: Thu, 28 Apr 2016 11:52:45 +0200 Subject: [PATCH 18/39] Fix implicit float-to-bool conversions (#752) --- src/bin/jp2/index.c | 2 +- src/lib/openjp2/j2k.c | 22 +++++++++++----------- src/lib/openjp2/tcd.c | 4 ++-- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/bin/jp2/index.c b/src/bin/jp2/index.c index af6e1381..478f556a 100644 --- a/src/bin/jp2/index.c +++ b/src/bin/jp2/index.c @@ -69,7 +69,7 @@ int write_index_file(opj_codestream_info_t *cstr_info, char *index) { return 1; } - if (cstr_info->tile[0].distotile) + if (cstr_info->tile[0].distotile > 0.0) disto_on = 1; else disto_on = 0; diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c index 20407498..be8e9442 100644 --- a/src/lib/openjp2/j2k.c +++ b/src/lib/openjp2/j2k.c @@ -4706,7 +4706,7 @@ static OPJ_BOOL opj_j2k_update_rates( opj_j2k_t *p_j2k, l_rates = l_tcp->rates; /* Modification of the RATE >> */ - if (*l_rates) { + if (*l_rates > 0.0f) { *l_rates = (( (OPJ_FLOAT32) (l_size_pixel * (OPJ_UINT32)(l_x1 - l_x0) * (OPJ_UINT32)(l_y1 - l_y0))) / ((*l_rates) * (OPJ_FLOAT32)l_bits_empty) @@ -4718,7 +4718,7 @@ static OPJ_BOOL opj_j2k_update_rates( opj_j2k_t *p_j2k, ++l_rates; for (k = 1; k < l_tcp->numlayers; ++k) { - if (*l_rates) { + if (*l_rates > 0.0f) { *l_rates = (( (OPJ_FLOAT32) (l_size_pixel * (OPJ_UINT32)(l_x1 - l_x0) * (OPJ_UINT32)(l_y1 - l_y0))) / ((*l_rates) * (OPJ_FLOAT32)l_bits_empty) @@ -4741,11 +4741,11 @@ static OPJ_BOOL opj_j2k_update_rates( opj_j2k_t *p_j2k, for (j=0;jtw;++j) { l_rates = l_tcp->rates; - if (*l_rates) { + if (*l_rates > 0.0f) { *l_rates -= l_sot_remove; - if (*l_rates < 30) { - *l_rates = 30; + if (*l_rates < 30.0f) { + *l_rates = 30.0f; } } @@ -4755,22 +4755,22 @@ static OPJ_BOOL opj_j2k_update_rates( opj_j2k_t *p_j2k, for (k = 1; k < l_last_res; ++k) { - if (*l_rates) { + if (*l_rates > 0.0f) { *l_rates -= l_sot_remove; - if (*l_rates < *(l_rates - 1) + 10) { - *l_rates = (*(l_rates - 1)) + 20; + if (*l_rates < *(l_rates - 1) + 10.0f) { + *l_rates = (*(l_rates - 1)) + 20.0f; } } ++l_rates; } - if (*l_rates) { + if (*l_rates > 0.0f) { *l_rates -= (l_sot_remove + 2.f); - if (*l_rates < *(l_rates - 1) + 10) { - *l_rates = (*(l_rates - 1)) + 20; + if (*l_rates < *(l_rates - 1) + 10.0f) { + *l_rates = (*(l_rates - 1)) + 20.0f; } } diff --git a/src/lib/openjp2/tcd.c b/src/lib/openjp2/tcd.c index d590046f..45d55e59 100644 --- a/src/lib/openjp2/tcd.c +++ b/src/lib/openjp2/tcd.c @@ -487,7 +487,7 @@ OPJ_BOOL opj_tcd_rateallocate( opj_tcd_t *tcd, OPJ_FLOAT64 lo = min; OPJ_FLOAT64 hi = max; OPJ_BOOL success = OPJ_FALSE; - OPJ_UINT32 maxlen = tcd_tcp->rates[layno] ? opj_uint_min(((OPJ_UINT32) ceil(tcd_tcp->rates[layno])), len) : len; + OPJ_UINT32 maxlen = tcd_tcp->rates[layno] > 0.0f ? opj_uint_min(((OPJ_UINT32) ceil(tcd_tcp->rates[layno])), len) : len; OPJ_FLOAT64 goodthresh = 0; OPJ_FLOAT64 stable_thresh = 0; OPJ_UINT32 i; @@ -500,7 +500,7 @@ OPJ_BOOL opj_tcd_rateallocate( opj_tcd_t *tcd, -r xx,yy,zz,0 (disto_alloc == 1 and rates == 0) -q xx,yy,zz,0 (fixed_quality == 1 and distoratio == 0) ==> possible to have some lossy layers and the last layer for sure lossless */ - if ( ((cp->m_specific_param.m_enc.m_disto_alloc==1) && (tcd_tcp->rates[layno]>0)) || ((cp->m_specific_param.m_enc.m_fixed_quality==1) && (tcd_tcp->distoratio[layno]>0))) { + if ( ((cp->m_specific_param.m_enc.m_disto_alloc==1) && (tcd_tcp->rates[layno]>0.0f)) || ((cp->m_specific_param.m_enc.m_fixed_quality==1) && (tcd_tcp->distoratio[layno]>0.0))) { opj_t2_t*t2 = opj_t2_create(tcd->image, cp); OPJ_FLOAT64 thresh = 0; From 29313eb5f1b2c01c7493087fa2d8f1a20495a34e Mon Sep 17 00:00:00 2001 From: Matthieu Darbois Date: Thu, 28 Apr 2016 13:16:43 +0200 Subject: [PATCH 19/39] Fix unsigned int overflow reported by UBSan (#761) * Fix unsigned int overflow reported by UBSan Please add -DOPJ_UBSAN_BUILD to CFLAGS when building with -fsanitize=undefined,unsigned-integer-overflow It seems clang/gcc do not allow to disable checking for block of code other than function or file. --- src/lib/openjp2/bio.c | 22 +++++++++++++++++----- src/lib/openjp2/j2k.c | 6 +++--- src/lib/openjp2/opj_includes.h | 8 ++++++++ src/lib/openjp2/pi.c | 5 +++-- 4 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/lib/openjp2/bio.c b/src/lib/openjp2/bio.c index e4edb372..269769b4 100644 --- a/src/lib/openjp2/bio.c +++ b/src/lib/openjp2/bio.c @@ -151,19 +151,31 @@ void opj_bio_init_dec(opj_bio_t *bio, OPJ_BYTE *bp, OPJ_UINT32 len) { bio->ct = 0; } +OPJ_NOSANITIZE("unsigned-integer-overflow") void opj_bio_write(opj_bio_t *bio, OPJ_UINT32 v, OPJ_UINT32 n) { OPJ_UINT32 i; - for (i = n - 1; i < n; i--) { + + assert((n > 0U) && (n <= 32U)); + for (i = n - 1; i < n; i--) { /* overflow used for end-loop condition */ opj_bio_putbit(bio, (v >> i) & 1); } } +OPJ_NOSANITIZE("unsigned-integer-overflow") OPJ_UINT32 opj_bio_read(opj_bio_t *bio, OPJ_UINT32 n) { OPJ_UINT32 i; - OPJ_UINT32 v; - v = 0; - for (i = n - 1; i < n; i--) { - v += opj_bio_getbit(bio) << i; + OPJ_UINT32 v; + + assert((n > 0U) /* && (n <= 32U)*/); +#ifdef OPJ_UBSAN_BUILD + /* This assert fails for some corrupted images which are gracefully rejected */ + /* Add this assert only for ubsan build. */ + /* This is the condition for overflow not to occur below which is needed because of OPJ_NOSANITIZE */ + assert(n <= 32U); +#endif + v = 0U; + for (i = n - 1; i < n; i--) { /* overflow used for end-loop condition */ + v |= opj_bio_getbit(bio) << i; /* can't overflow, opj_bio_getbit returns 0 or 1 */ } return v; } diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c index be8e9442..525f629a 100644 --- a/src/lib/openjp2/j2k.c +++ b/src/lib/openjp2/j2k.c @@ -2063,17 +2063,17 @@ static OPJ_BOOL opj_j2k_read_siz(opj_j2k_t *p_j2k, /* testcase 4035.pdf.SIGSEGV.d8b.3375 */ /* testcase issue427-null-image-size.jp2 */ if ((l_image->x0 >= l_image->x1) || (l_image->y0 >= l_image->y1)) { - opj_event_msg(p_manager, EVT_ERROR, "Error with SIZ marker: negative or zero image size (%d x %d)\n", l_image->x1 - l_image->x0, l_image->y1 - l_image->y0); + opj_event_msg(p_manager, EVT_ERROR, "Error with SIZ marker: negative or zero image size (%" PRId64 " x %" PRId64 ")\n", (OPJ_INT64)l_image->x1 - l_image->x0, (OPJ_INT64)l_image->y1 - l_image->y0); return OPJ_FALSE; } /* testcase 2539.pdf.SIGFPE.706.1712 (also 3622.pdf.SIGFPE.706.2916 and 4008.pdf.SIGFPE.706.3345 and maybe more) */ - if (!(l_cp->tdx * l_cp->tdy)) { + if ((l_cp->tdx == 0U) || (l_cp->tdy == 0U)) { opj_event_msg(p_manager, EVT_ERROR, "Error with SIZ marker: invalid tile size (tdx: %d, tdy: %d)\n", l_cp->tdx, l_cp->tdy); return OPJ_FALSE; } /* testcase 1610.pdf.SIGSEGV.59c.681 */ - if (((OPJ_UINT64)l_image->x1) * ((OPJ_UINT64)l_image->y1) != (l_image->x1 * l_image->y1)) { + if ((0xFFFFFFFFU / l_image->x1) < l_image->y1) { opj_event_msg(p_manager, EVT_ERROR, "Prevent buffer overflow (x1: %d, y1: %d)\n", l_image->x1, l_image->y1); return OPJ_FALSE; } diff --git a/src/lib/openjp2/opj_includes.h b/src/lib/openjp2/opj_includes.h index 5add0918..58a5a9a9 100644 --- a/src/lib/openjp2/opj_includes.h +++ b/src/lib/openjp2/opj_includes.h @@ -112,6 +112,14 @@ #endif #endif +#ifdef __has_attribute + #if __has_attribute(no_sanitize) + #define OPJ_NOSANITIZE(kind) __attribute__((no_sanitize(kind))) + #endif +#endif +#ifndef OPJ_NOSANITIZE + #define OPJ_NOSANITIZE(kind) +#endif /* MSVC before 2013 and Borland C do not have lrintf */ diff --git a/src/lib/openjp2/pi.c b/src/lib/openjp2/pi.c index bfee10a2..cffad668 100644 --- a/src/lib/openjp2/pi.c +++ b/src/lib/openjp2/pi.c @@ -747,10 +747,12 @@ static void opj_get_all_encoding_parameters( const opj_image_t *p_image, } /* use custom size for precincts*/ - l_level_no = l_tccp->numresolutions - 1; + l_level_no = l_tccp->numresolutions; for (resno = 0; resno < l_tccp->numresolutions; ++resno) { OPJ_UINT32 l_dx, l_dy; + --l_level_no; + /* precinct width and height*/ l_pdx = l_tccp->prcw[resno]; l_pdy = l_tccp->prch[resno]; @@ -782,7 +784,6 @@ static void opj_get_all_encoding_parameters( const opj_image_t *p_image, *p_max_prec = l_product; } - --l_level_no; } ++l_tccp; ++l_img_comp; From e166e4a209d9a3e4b583e4b2cdcbab2c57967eb1 Mon Sep 17 00:00:00 2001 From: Matthieu Darbois Date: Thu, 28 Apr 2016 19:20:14 +0200 Subject: [PATCH 20/39] Check SSIZ is valid in opj_j2k_read_siz (#762) --- src/lib/openjp2/j2k.c | 8 +++++++- tests/nonregression/CMakeLists.txt | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c index 525f629a..f6be14de 100644 --- a/src/lib/openjp2/j2k.c +++ b/src/lib/openjp2/j2k.c @@ -2154,10 +2154,16 @@ static OPJ_BOOL opj_j2k_read_siz(opj_j2k_t *p_j2k, if( l_img_comp->dx < 1 || l_img_comp->dx > 255 || l_img_comp->dy < 1 || l_img_comp->dy > 255 ) { opj_event_msg(p_manager, EVT_ERROR, - "Invalid values for comp = %d : dx=%u dy=%u\n (should be between 1 and 255 according the JPEG2000 norm)", + "Invalid values for comp = %d : dx=%u dy=%u (should be between 1 and 255 according to the JPEG2000 norm)\n", i, l_img_comp->dx, l_img_comp->dy); return OPJ_FALSE; } + if( l_img_comp->prec > 38) { /* TODO openjpeg won't handle more than ? */ + opj_event_msg(p_manager, EVT_ERROR, + "Invalid values for comp = %d : prec=%u (should be between 1 and 38 according to the JPEG2000 norm)\n", + i, l_img_comp->prec); + return OPJ_FALSE; + } #ifdef USE_JPWL if (l_cp->correct) { diff --git a/tests/nonregression/CMakeLists.txt b/tests/nonregression/CMakeLists.txt index ce95af87..40283169 100644 --- a/tests/nonregression/CMakeLists.txt +++ b/tests/nonregression/CMakeLists.txt @@ -37,7 +37,7 @@ set(BLACKLIST_JPEG2000_TMP #edf_c2_20.jp2 #looks ok as per kdu_jp2info edf_c2_1377017.jp2 edf_c2_1002767.jp2 - #edf_c2_10025.jp2 + edf_c2_10025.jp2 edf_c2_1000234.jp2 edf_c2_225881.jp2 edf_c2_1000671.jp2 @@ -46,6 +46,7 @@ set(BLACKLIST_JPEG2000_TMP edf_c2_101463.jp2 edf_c2_1674177.jp2 edf_c2_1673169.jp2 + issue418.jp2 issue429.jp2 issue427-null-image-size.jp2 issue427-illegal-tile-offset.jp2 From 319fc971fef8a1e1c1c543506c26805873e3f258 Mon Sep 17 00:00:00 2001 From: julienmalik Date: Fri, 29 Apr 2016 23:49:17 +0200 Subject: [PATCH 21/39] cppcheck fix for openjp2 (#740) --- src/bin/common/color.c | 208 ++++++++++++++++++++++++++++----- src/bin/jp2/convert.c | 11 +- src/bin/jp2/convertbmp.c | 8 +- src/bin/jp2/convertpng.c | 14 ++- src/bin/jp2/opj_compress.c | 29 ++++- src/bin/jp2/opj_decompress.c | 75 ++++++------ src/bin/jp2/opj_dump.c | 55 ++++++--- src/lib/openjp2/cidx_manager.c | 4 +- src/lib/openjp2/j2k.c | 9 +- src/lib/openjp2/jp2.c | 10 +- src/lib/openjp2/phix_manager.c | 4 +- src/lib/openjp2/ppix_manager.c | 4 +- src/lib/openjp2/t1.c | 6 +- src/lib/openjp2/thix_manager.c | 4 +- tests/test_tile_encoder.c | 11 +- 15 files changed, 345 insertions(+), 107 deletions(-) diff --git a/src/bin/common/color.c b/src/bin/common/color.c index 0f2b8dac..cd4fafdd 100644 --- a/src/bin/common/color.c +++ b/src/bin/common/color.c @@ -108,6 +108,8 @@ static void sycc444_to_rgb(opj_image_t *img) d1 = g = (int*)malloc(sizeof(int) * (size_t)max); d2 = b = (int*)malloc(sizeof(int) * (size_t)max); + if(r == NULL || g == NULL || b == NULL) goto fails; + for(i = 0U; i < max; ++i) { sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b); @@ -116,6 +118,12 @@ static void sycc444_to_rgb(opj_image_t *img) free(img->comps[0].data); img->comps[0].data = d0; free(img->comps[1].data); img->comps[1].data = d1; free(img->comps[2].data); img->comps[2].data = d2; + return; + +fails: + if(r) free(r); + if(g) free(g); + if(b) free(b); }/* sycc444_to_rgb() */ @@ -141,6 +149,8 @@ static void sycc422_to_rgb(opj_image_t *img) d1 = g = (int*)malloc(sizeof(int) * (size_t)max); d2 = b = (int*)malloc(sizeof(int) * (size_t)max); + if(r == NULL || g == NULL || b == NULL) goto fails; + for(i=0U; i < maxh; ++i) { for(j=0U; j < (maxw & ~(unsigned int)1U); j += 2U) @@ -170,6 +180,12 @@ static void sycc422_to_rgb(opj_image_t *img) img->comps[2].dx = img->comps[0].dx; img->comps[1].dy = img->comps[0].dy; img->comps[2].dy = img->comps[0].dy; + return; + +fails: + if(r) free(r); + if(g) free(g); + if(b) free(b); }/* sycc422_to_rgb() */ @@ -195,6 +211,8 @@ static void sycc420_to_rgb(opj_image_t *img) d1 = g = (int*)malloc(sizeof(int) * (size_t)max); d2 = b = (int*)malloc(sizeof(int) * (size_t)max); + if(r == NULL || g == NULL || b == NULL) goto fails; + for(i=0U; i < (maxh & ~(unsigned int)1U); i += 2U) { ny = y + maxw; @@ -255,6 +273,12 @@ static void sycc420_to_rgb(opj_image_t *img) img->comps[2].dx = img->comps[0].dx; img->comps[1].dy = img->comps[0].dy; img->comps[2].dy = img->comps[0].dy; + return; + +fails: + if(r) free(r); + if(g) free(g); + if(b) free(b); }/* sycc420_to_rgb() */ @@ -328,10 +352,11 @@ void color_apply_icc_profile(opj_image_t *image) cmsHPROFILE in_prof, out_prof; cmsHTRANSFORM transform; cmsColorSpaceSignature in_space, out_space; - cmsUInt32Number intent, in_type, out_type, nr_samples; + cmsUInt32Number intent, in_type, out_type; int *r, *g, *b; - int prec, i, max, max_w, max_h; - OPJ_COLOR_SPACE oldspace; + size_t nr_samples; + int prec, i, max, max_w, max_h, ok = 0; + OPJ_COLOR_SPACE new_space; in_prof = cmsOpenProfileFromMem(image->icc_profile_buf, image->icc_profile_len); @@ -351,7 +376,6 @@ void color_apply_icc_profile(opj_image_t *image) max_w = (int)image->comps[0].w; max_h = (int)image->comps[0].h; prec = (int)image->comps[0].prec; - oldspace = image->color_space; if(out_space == cmsSigRgbData) /* enumCS 16 */ { @@ -366,7 +390,7 @@ void color_apply_icc_profile(opj_image_t *image) out_type = TYPE_RGB_16; } out_prof = cmsCreate_sRGBProfile(); - image->color_space = OPJ_CLRSPC_SRGB; + new_space = OPJ_CLRSPC_SRGB; } else if(out_space == cmsSigGrayData) /* enumCS 17 */ @@ -374,7 +398,7 @@ void color_apply_icc_profile(opj_image_t *image) in_type = TYPE_GRAY_8; out_type = TYPE_RGB_8; out_prof = cmsCreate_sRGBProfile(); - image->color_space = OPJ_CLRSPC_SRGB; + new_space = OPJ_CLRSPC_SRGB; } else if(out_space == cmsSigYCbCrData) /* enumCS 18 */ @@ -382,7 +406,7 @@ void color_apply_icc_profile(opj_image_t *image) in_type = TYPE_YCbCr_16; out_type = TYPE_RGB_16; out_prof = cmsCreate_sRGBProfile(); - image->color_space = OPJ_CLRSPC_SRGB; + new_space = OPJ_CLRSPC_SRGB; } else { @@ -393,6 +417,14 @@ __FILE__,__LINE__,out_space, (out_space>>24) & 0xff,(out_space>>16) & 0xff, (out_space>>8) & 0xff, out_space & 0xff); #endif + cmsCloseProfile(in_prof); + + return; + } + if(out_prof == NULL) + { + cmsCloseProfile(in_prof); + return; } @@ -435,7 +467,7 @@ fprintf(stderr,"\trender_intent (%u)\n\t" fprintf(stderr,"%s:%d:color_apply_icc_profile\n\tcmsCreateTransform failed. " "ICC Profile ignored.\n",__FILE__,__LINE__); #endif - image->color_space = oldspace; + #ifdef OPJ_HAVE_LIBLCMS1 cmsCloseProfile(in_prof); cmsCloseProfile(out_prof); @@ -448,11 +480,14 @@ fprintf(stderr,"%s:%d:color_apply_icc_profile\n\tcmsCreateTransform failed. " if( prec <= 8 ) { unsigned char *inbuf, *outbuf, *in, *out; + max = max_w * max_h; - nr_samples = (cmsUInt32Number)max * 3 * (cmsUInt32Number)sizeof(unsigned char); + nr_samples = (size_t)(max * 3 * sizeof(unsigned char)); in = inbuf = (unsigned char*)malloc(nr_samples); out = outbuf = (unsigned char*)malloc(nr_samples); + if(inbuf == NULL || outbuf == NULL) goto fails0; + r = image->comps[0].data; g = image->comps[1].data; b = image->comps[2].data; @@ -476,16 +511,23 @@ fprintf(stderr,"%s:%d:color_apply_icc_profile\n\tcmsCreateTransform failed. " *g++ = (int)*out++; *b++ = (int)*out++; } - free(inbuf); free(outbuf); + ok = 1; + +fails0: + if(inbuf) free(inbuf); + if(outbuf) free(outbuf); } - else + else /* prec > 8 */ { unsigned short *inbuf, *outbuf, *in, *out; + max = max_w * max_h; - nr_samples = (cmsUInt32Number)max * 3 * (cmsUInt32Number)sizeof(unsigned short); + nr_samples = (size_t)(max * 3 * sizeof(unsigned short)); in = inbuf = (unsigned short*)malloc(nr_samples); out = outbuf = (unsigned short*)malloc(nr_samples); + if(inbuf == NULL || outbuf == NULL) goto fails1; + r = image->comps[0].data; g = image->comps[1].data; b = image->comps[2].data; @@ -509,37 +551,53 @@ fprintf(stderr,"%s:%d:color_apply_icc_profile\n\tcmsCreateTransform failed. " *g++ = (int)*out++; *b++ = (int)*out++; } - free(inbuf); free(outbuf); + ok = 1; + +fails1: + if(inbuf) free(inbuf); + if(outbuf) free(outbuf); } } - else /* GRAY, GRAYA */ + else /* image->numcomps <= 2 : GRAY, GRAYA */ { + if(prec <= 8) + { unsigned char *in, *inbuf, *out, *outbuf; + opj_image_comp_t *new_comps; + max = max_w * max_h; - nr_samples = (cmsUInt32Number)max * 3 * sizeof(unsigned char); + nr_samples = (size_t)(max * 3 * sizeof(unsigned char)); in = inbuf = (unsigned char*)malloc(nr_samples); out = outbuf = (unsigned char*)malloc(nr_samples); + g = (int*)calloc((size_t)max, sizeof(int)); + b = (int*)calloc((size_t)max, sizeof(int)); - image->comps = (opj_image_comp_t*) + if(inbuf == NULL || outbuf == NULL || g == NULL || b == NULL) goto fails2; + + new_comps = (opj_image_comp_t*) realloc(image->comps, (image->numcomps+2)*sizeof(opj_image_comp_t)); + if(new_comps == NULL) goto fails2; + + image->comps = new_comps; + if(image->numcomps == 2) image->comps[3] = image->comps[1]; image->comps[1] = image->comps[0]; image->comps[2] = image->comps[0]; - image->comps[1].data = (int*)calloc((size_t)max, sizeof(int)); - image->comps[2].data = (int*)calloc((size_t)max, sizeof(int)); + image->comps[1].data = g; + image->comps[2].data = b; image->numcomps += 2; r = image->comps[0].data; for(i = 0; i < max; ++i) - { + { *in++ = (unsigned char)*r++; - } + } cmsDoTransform(transform, inbuf, outbuf, (cmsUInt32Number)max); r = image->comps[0].data; @@ -547,12 +605,76 @@ fprintf(stderr,"%s:%d:color_apply_icc_profile\n\tcmsCreateTransform failed. " b = image->comps[2].data; for(i = 0; i < max; ++i) - { + { *r++ = (int)*out++; *g++ = (int)*out++; *b++ = (int)*out++; - } - free(inbuf); free(outbuf); + } + r = g = b = NULL; + ok = 1; - }/* if(image->numcomps */ +fails2: + if(inbuf) free(inbuf); + if(outbuf) free(outbuf); + if(g) free(g); + if(b) free(b); + } + else /* prec > 8 */ + { + unsigned short *in, *inbuf, *out, *outbuf; + opj_image_comp_t *new_comps; + + max = max_w * max_h; + nr_samples = (size_t)(max * 3 * sizeof(unsigned short)); + in = inbuf = (unsigned short*)malloc(nr_samples); + out = outbuf = (unsigned short*)malloc(nr_samples); + g = (int*)calloc((size_t)max, sizeof(int)); + b = (int*)calloc((size_t)max, sizeof(int)); + + if(inbuf == NULL || outbuf == NULL || g == NULL || b == NULL) goto fails3; + + new_comps = (opj_image_comp_t*) + realloc(image->comps, (image->numcomps+2)*sizeof(opj_image_comp_t)); + + if(new_comps == NULL) goto fails3; + + image->comps = new_comps; + + if(image->numcomps == 2) + image->comps[3] = image->comps[1]; + + image->comps[1] = image->comps[0]; + image->comps[2] = image->comps[0]; + + image->comps[1].data = g; + image->comps[2].data = b; + + image->numcomps += 2; + + r = image->comps[0].data; + + for(i = 0; i < max; ++i) + { + *in++ = (unsigned short)*r++; + } + cmsDoTransform(transform, inbuf, outbuf, (cmsUInt32Number)max); + + r = image->comps[0].data; + g = image->comps[1].data; + b = image->comps[2].data; + + for(i = 0; i < max; ++i) + { + *r++ = (int)*out++; *g++ = (int)*out++; *b++ = (int)*out++; + } + r = g = b = NULL; + ok = 1; + +fails3: + if(inbuf) free(inbuf); + if(outbuf) free(outbuf); + if(g) free(g); + if(b) free(b); + } + }/* if(image->numcomps > 2) */ cmsDeleteTransform(transform); @@ -560,15 +682,18 @@ fprintf(stderr,"%s:%d:color_apply_icc_profile\n\tcmsCreateTransform failed. " cmsCloseProfile(in_prof); cmsCloseProfile(out_prof); #endif + if(ok) + { + image->color_space = new_space; + } }/* color_apply_icc_profile() */ void color_cielab_to_rgb(opj_image_t *image) { int *row; int enumcs, numcomps; - - image->color_space = OPJ_CLRSPC_SRGB; - + OPJ_COLOR_SPACE new_space; + numcomps = (int)image->numcomps; if(numcomps != 3) @@ -595,8 +720,14 @@ void color_cielab_to_rgb(opj_image_t *image) cmsCIELab Lab; in = cmsCreateLab4Profile(NULL); + if(in == NULL){ + return; + } out = cmsCreate_sRGBProfile(); - + if(out == NULL){ + cmsCloseProfile(in); + return; + } transform = cmsCreateTransform(in, TYPE_Lab_DBL, out, TYPE_RGB_16, INTENT_PERCEPTUAL, 0); #ifdef OPJ_HAVE_LIBLCMS2 @@ -611,6 +742,8 @@ void color_cielab_to_rgb(opj_image_t *image) #endif return; } + new_space = OPJ_CLRSPC_SRGB; + prec0 = (double)image->comps[0].prec; prec1 = (double)image->comps[1].prec; prec2 = (double)image->comps[2].prec; @@ -639,7 +772,9 @@ void color_cielab_to_rgb(opj_image_t *image) red = dst0 = (int*)malloc(max * sizeof(int)); green = dst1 = (int*)malloc(max * sizeof(int)); blue = dst2 = (int*)malloc(max * sizeof(int)); - + + if(red == NULL || green == NULL || blue == NULL) goto fails; + minL = -(rl * ol)/(pow(2, prec0)-1); maxL = minL + rl; @@ -670,16 +805,27 @@ void color_cielab_to_rgb(opj_image_t *image) free(src1); image->comps[1].data = dst1; free(src2); image->comps[2].data = dst2; - image->color_space = OPJ_CLRSPC_SRGB; + image->color_space = new_space; image->comps[0].prec = 16; image->comps[1].prec = 16; image->comps[2].prec = 16; return; + +fails: + cmsDeleteTransform(transform); +#ifdef OPJ_HAVE_LIBLCMS1 + cmsCloseProfile(in); + cmsCloseProfile(out); +#endif + if(red) free(red); + if(green) free(green); + if(blue) free(blue); + return; } fprintf(stderr,"%s:%d:\n\tenumCS %d not handled. Ignoring.\n", __FILE__,__LINE__, enumcs); -}/* color_apply_conversion() */ +}/* color_cielab_to_rgb() */ #endif /* OPJ_HAVE_LIBLCMS2 || OPJ_HAVE_LIBLCMS1 */ diff --git a/src/bin/jp2/convert.c b/src/bin/jp2/convert.c index 13713204..940ac2fa 100644 --- a/src/bin/jp2/convert.c +++ b/src/bin/jp2/convert.c @@ -611,6 +611,10 @@ static int tga_readheader(FILE *fp, unsigned int *bits_per_pixel, if (id_len) { unsigned char *id = (unsigned char *) malloc(id_len); + if(id == 0){ + fprintf(stderr, "tga_readheader: memory out\n"); + return 0; + } if ( !fread(id, id_len, 1, fp) ) { fprintf(stderr, "\nError: fread return a number of element different from the expected.\n"); @@ -1249,6 +1253,7 @@ int imagetopgx(opj_image_t * image, const char *outfile) { name = (char*)malloc(total+1); if (name == NULL) { + fprintf(stderr, "imagetopgx: memory out\n"); goto fin; } } @@ -1906,7 +1911,11 @@ if(v > 65535) v = 65535; else if(v < 0) v = 0; fprintf(stderr," is written to the file\n"); } destname = (char*)malloc(strlen(outfile) + 8); - + if(destname == NULL){ + fprintf(stderr, "imagetopnm: memory out\n"); + fclose(fdest); + return 1; + } for (compno = 0; compno < ncomp; compno++) { if (ncomp > 1) diff --git a/src/bin/jp2/convertbmp.c b/src/bin/jp2/convertbmp.c index 910574b8..a09c0ae5 100644 --- a/src/bin/jp2/convertbmp.c +++ b/src/bin/jp2/convertbmp.c @@ -181,7 +181,7 @@ static void bmpmask32toimage(const OPJ_UINT8* pData, OPJ_UINT32 stride, opj_imag OPJ_UINT32 width, height; OPJ_UINT32 x, y; const OPJ_UINT8 *pSrc = NULL; - OPJ_BOOL hasAlpha = OPJ_FALSE; + OPJ_BOOL hasAlpha; OPJ_UINT32 redShift, redPrec; OPJ_UINT32 greenShift, greenPrec; OPJ_UINT32 blueShift, bluePrec; @@ -239,7 +239,7 @@ static void bmpmask16toimage(const OPJ_UINT8* pData, OPJ_UINT32 stride, opj_imag OPJ_UINT32 width, height; OPJ_UINT32 x, y; const OPJ_UINT8 *pSrc = NULL; - OPJ_BOOL hasAlpha = OPJ_FALSE; + OPJ_BOOL hasAlpha; OPJ_UINT32 redShift, redPrec; OPJ_UINT32 greenShift, greenPrec; OPJ_UINT32 blueShift, bluePrec; @@ -891,7 +891,7 @@ int imagetobmp(opj_image_t * image, const char *outfile) { fprintf(fdest, "%c%c%c", bc, gc, rc); if ((i + 1) % w == 0) { - for (pad = (3 * w) % 4 ? 4 - (3 * w) % 4 : 0; pad > 0; pad--) /* ADD */ + for (pad = ((3 * w) % 4) ? (4 - (3 * w) % 4) : 0; pad > 0; pad--) /* ADD */ fprintf(fdest, "%c", 0); } } @@ -967,7 +967,7 @@ int imagetobmp(opj_image_t * image, const char *outfile) { fprintf(fdest, "%c", (OPJ_UINT8)r); if ((i + 1) % w == 0) { - for (pad = w % 4 ? 4 - w % 4 : 0; pad > 0; pad--) /* ADD */ + for ((pad = w % 4) ? (4 - w % 4) : 0; pad > 0; pad--) /* ADD */ fprintf(fdest, "%c", 0); } } diff --git a/src/bin/jp2/convertpng.c b/src/bin/jp2/convertpng.c index 8d117412..5635c7d0 100644 --- a/src/bin/jp2/convertpng.c +++ b/src/bin/jp2/convertpng.c @@ -185,9 +185,17 @@ opj_image_t *pngtoimage(const char *read_idf, opj_cparameters_t * params) rows = (OPJ_BYTE**)calloc(height+1, sizeof(OPJ_BYTE*)); - for(i = 0; i < height; ++i) + if(rows == NULL){ + fprintf(stderr, "pngtoimage: memory out\n"); + goto fin; + } + for(i = 0; i < height; ++i){ rows[i] = (OPJ_BYTE*)malloc(png_get_rowbytes(png,info)); - + if(rows[i] == NULL){ + fprintf(stderr,"pngtoimage: memory out\n"); + goto fin; + } + } png_read_image(png, rows); /* Create image */ @@ -235,7 +243,7 @@ fin: if(rows) { for(i = 0; i < height; ++i) - free(rows[i]); + if(rows[i]) free(rows[i]); free(rows); } if (row32s) { diff --git a/src/bin/jp2/opj_compress.c b/src/bin/jp2/opj_compress.c index 9d690a56..5a63a9d6 100644 --- a/src/bin/jp2/opj_compress.c +++ b/src/bin/jp2/opj_compress.c @@ -647,6 +647,10 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param raw_cp->rawBitDepth = bitdepth; raw_cp->rawSigned = raw_signed; raw_cp->rawComps = (raw_comp_cparameters_t*) malloc(((OPJ_UINT32)(ncomp))*sizeof(raw_comp_cparameters_t)); + if(raw_cp->rawComps == NULL){ + free(substr1); + return 1; + } for (compno = 0; compno < ncomp && !wrong; compno++) { if (substr2 == NULL) { raw_cp->rawComps[compno].dx = lastdx; @@ -725,6 +729,9 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param numresolution = (OPJ_UINT32)parameters->numresolution; matrix_width = numresolution * 3; parameters->cp_matrice = (int *) malloc(numlayers * matrix_width * sizeof(int)); + if(parameters->cp_matrice == NULL){ + return 1; + } s = s + 2; for (i = 0; i < numlayers; i++) { @@ -995,6 +1002,9 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param case 'z': /* Image Directory path */ { img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1); + if(img_fol->imgdirpath == NULL){ + return 1; + } strcpy(img_fol->imgdirpath,opj_optarg); img_fol->set_imgdir=1; } @@ -1540,6 +1550,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param } return 0; + } /* -------------------------------------------------------------------------- */ @@ -1635,7 +1646,7 @@ int main(int argc, char **argv) { /* parse input and get user encoding parameters */ parameters.tcp_mct = (char) 255; /* This will be set later according to the input image or the provided option */ if(parse_cmdline_encoder(argc, argv, ¶meters,&img_fol, &raw_cp, indexfilename, sizeof(indexfilename)) == 1) { - return 1; + goto fails; } /* Read directory if necessary */ @@ -1848,7 +1859,9 @@ int main(int argc, char **argv) { OPJ_BYTE *l_data; OPJ_UINT32 l_data_size = 512*512*3; l_data = (OPJ_BYTE*) calloc( 1,l_data_size); - assert( l_data ); + if(l_data == NULL){ + goto fails; + } for (i=0;i test_tile_encoder: failed to write the tile %d!\n",i); @@ -1904,4 +1917,16 @@ int main(int argc, char **argv) { } return 0; + +fails: + if(parameters.cp_comment) free(parameters.cp_comment); + if(parameters.cp_matrice) free(parameters.cp_matrice); + if(raw_cp.rawComps) free(raw_cp.rawComps); + if(img_fol.imgdirpath) free(img_fol.imgdirpath); + if(dirptr){ + if(dirptr->filename_buf) free(dirptr->filename_buf); + if(dirptr->filename) free(dirptr->filename); + free(dirptr); + } + return 1; } diff --git a/src/bin/jp2/opj_decompress.c b/src/bin/jp2/opj_decompress.c index f3b1cd5c..ab7ff04a 100644 --- a/src/bin/jp2/opj_decompress.c +++ b/src/bin/jp2/opj_decompress.c @@ -680,6 +680,9 @@ int parse_cmdline_decoder(int argc, char **argv, opj_decompress_parameters *para case 'y': /* Image Directory path */ { img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1); + if(img_fol->imgdirpath == NULL){ + return 1; + } strcpy(img_fol->imgdirpath,opj_optarg); img_fol->set_imgdir=1; } @@ -1200,8 +1203,7 @@ int main(int argc, char **argv) /* parse input and get user encoding parameters */ if(parse_cmdline_decoder(argc, argv, ¶meters,&img_fol) == 1) { - destroy_parameters(¶meters); - return EXIT_FAILURE; + failed = 1; goto fin; } /* Initialize reading of directory */ @@ -1210,26 +1212,30 @@ int main(int argc, char **argv) num_images=get_num_images(img_fol.imgdirpath); dirptr=(dircnt_t*)malloc(sizeof(dircnt_t)); - if(dirptr){ - dirptr->filename_buf = (char*)malloc((size_t)num_images*OPJ_PATH_LEN*sizeof(char)); /* Stores at max 10 image file names*/ - dirptr->filename = (char**) malloc((size_t)num_images*sizeof(char*)); - - if(!dirptr->filename_buf){ - destroy_parameters(¶meters); - return EXIT_FAILURE; - } - for(it_image=0;it_imagefilename[it_image] = dirptr->filename_buf + it_image*OPJ_PATH_LEN; - } - } - if(load_images(dirptr,img_fol.imgdirpath)==1){ + if(!dirptr){ destroy_parameters(¶meters); return EXIT_FAILURE; } + dirptr->filename_buf = (char*)malloc((size_t)num_images*OPJ_PATH_LEN*sizeof(char)); /* Stores at max 10 image file names*/ + if(!dirptr->filename_buf){ + failed = 1; goto fin; + } + + dirptr->filename = (char**) malloc((size_t)num_images*sizeof(char*)); + + if(!dirptr->filename){ + failed = 1; goto fin; + } + for(it_image=0;it_imagefilename[it_image] = dirptr->filename_buf + it_image*OPJ_PATH_LEN; + } + + if(load_images(dirptr,img_fol.imgdirpath)==1){ + failed = 1; goto fin; + } if (num_images==0){ fprintf(stdout,"Folder is empty\n"); - destroy_parameters(¶meters); - return EXIT_FAILURE; + failed = 1; goto fin; } }else{ num_images=1; @@ -1254,8 +1260,7 @@ int main(int argc, char **argv) l_stream = opj_stream_create_default_file_stream(parameters.infile,1); if (!l_stream){ fprintf(stderr, "ERROR -> failed to create the stream from the file %s\n", parameters.infile); - destroy_parameters(¶meters); - return EXIT_FAILURE; + failed = 1; goto fin; } /* decode the JPEG2000 stream */ @@ -1297,21 +1302,19 @@ int main(int argc, char **argv) /* Setup the decoder decoding parameters using user parameters */ if ( !opj_setup_decoder(l_codec, &(parameters.core)) ){ fprintf(stderr, "ERROR -> opj_decompress: failed to setup the decoder\n"); - destroy_parameters(¶meters); opj_stream_destroy(l_stream); opj_destroy_codec(l_codec); - return EXIT_FAILURE; + failed = 1; goto fin; } /* Read the main header of the codestream and if necessary the JP2 boxes*/ if(! opj_read_header(l_stream, l_codec, &image)){ fprintf(stderr, "ERROR -> opj_decompress: failed to read the header\n"); - destroy_parameters(¶meters); opj_stream_destroy(l_stream); opj_destroy_codec(l_codec); opj_image_destroy(image); - return EXIT_FAILURE; + failed = 1; goto fin; } if (!parameters.nb_tile_to_decode) { @@ -1319,21 +1322,19 @@ int main(int argc, char **argv) if (!opj_set_decode_area(l_codec, image, (OPJ_INT32)parameters.DA_x0, (OPJ_INT32)parameters.DA_y0, (OPJ_INT32)parameters.DA_x1, (OPJ_INT32)parameters.DA_y1)){ fprintf(stderr, "ERROR -> opj_decompress: failed to set the decoded area\n"); - destroy_parameters(¶meters); opj_stream_destroy(l_stream); opj_destroy_codec(l_codec); opj_image_destroy(image); - return EXIT_FAILURE; + failed = 1; goto fin; } /* Get the decoded image */ if (!(opj_decode(l_codec, l_stream, image) && opj_end_decompress(l_codec, l_stream))) { fprintf(stderr,"ERROR -> opj_decompress: failed to decode image!\n"); - destroy_parameters(¶meters); opj_destroy_codec(l_codec); opj_stream_destroy(l_stream); opj_image_destroy(image); - return EXIT_FAILURE; + failed = 1; goto fin; } } else { @@ -1344,16 +1345,15 @@ int main(int argc, char **argv) opj_destroy_codec(l_codec); opj_stream_destroy(l_stream); opj_image_destroy(image); - return EXIT_FAILURE; + failed = 1; goto fin; }*/ if (!opj_get_decoded_tile(l_codec, l_stream, image, parameters.tile_index)) { fprintf(stderr, "ERROR -> opj_decompress: failed to decode tile!\n"); - destroy_parameters(¶meters); opj_destroy_codec(l_codec); opj_stream_destroy(l_stream); opj_image_destroy(image); - return EXIT_FAILURE; + failed = 1; goto fin; } fprintf(stdout, "tile %d is decoded!\n\n", parameters.tile_index); } @@ -1432,9 +1432,8 @@ int main(int argc, char **argv) image = upsample_image_components(image); if (image == NULL) { fprintf(stderr, "ERROR -> opj_decompress: failed to upsample image components!\n"); - destroy_parameters(¶meters); opj_destroy_codec(l_codec); - return EXIT_FAILURE; + failed = 1; goto fin; } } @@ -1456,9 +1455,8 @@ int main(int argc, char **argv) } if (image == NULL) { fprintf(stderr, "ERROR -> opj_decompress: failed to convert to RGB image!\n"); - destroy_parameters(¶meters); opj_destroy_codec(l_codec); - return EXIT_FAILURE; + failed = 1; goto fin; } } @@ -1567,10 +1565,17 @@ int main(int argc, char **argv) if(failed) (void)remove(parameters.outfile); /* ignore return value */ } +fin: destroy_parameters(¶meters); + if(failed && img_fol.imgdirpath) free(img_fol.imgdirpath); + if(dirptr){ + if(dirptr->filename) free(dirptr->filename); + if(dirptr->filename_buf) free(dirptr->filename_buf); + free(dirptr); + } if (numDecompressedImages) { fprintf(stdout, "decode time: %d ms\n", (int)( (tCumulative * 1000.0) / (OPJ_FLOAT64)numDecompressedImages)); } return failed ? EXIT_FAILURE : EXIT_SUCCESS; } -/*end main*/ +/*end main()*/ diff --git a/src/bin/jp2/opj_dump.c b/src/bin/jp2/opj_dump.c index bd608c2b..d62eea14 100644 --- a/src/bin/jp2/opj_dump.c +++ b/src/bin/jp2/opj_dump.c @@ -341,6 +341,9 @@ static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *param case 'y': /* Image Directory path */ { img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1); + if(img_fol->imgdirpath == NULL){ + return 1; + } strcpy(img_fol->imgdirpath,opj_optarg); img_fol->set_imgdir=1; } @@ -442,6 +445,8 @@ int main(int argc, char *argv[]) /* Parse input and get user encoding parameters */ if(parse_cmdline_decoder(argc, argv, ¶meters,&img_fol) == 1) { + if(img_fol.imgdirpath) free(img_fol.imgdirpath); + return EXIT_FAILURE; } @@ -451,25 +456,31 @@ int main(int argc, char *argv[]) num_images=get_num_images(img_fol.imgdirpath); dirptr=(dircnt_t*)malloc(sizeof(dircnt_t)); - if(dirptr){ - dirptr->filename_buf = (char*)malloc((size_t)num_images*OPJ_PATH_LEN*sizeof(char)); /* Stores at max 10 image file names*/ - dirptr->filename = (char**) malloc((size_t)num_images*sizeof(char*)); - - if(!dirptr->filename_buf){ - return EXIT_FAILURE; - } - - for(it_image=0;it_imagefilename[it_image] = dirptr->filename_buf + it_image*OPJ_PATH_LEN; - } - } - if(load_images(dirptr,img_fol.imgdirpath)==1){ + if(!dirptr){ return EXIT_FAILURE; } + dirptr->filename_buf = (char*)malloc((size_t)num_images*OPJ_PATH_LEN*sizeof(char)); /* Stores at max 10 image file names*/ + if(!dirptr->filename_buf){ + free(dirptr); + return EXIT_FAILURE; + } + dirptr->filename = (char**) malloc((size_t)num_images*sizeof(char*)); + + if(!dirptr->filename){ + goto fails; + } + + for(it_image=0;it_imagefilename[it_image] = dirptr->filename_buf + it_image*OPJ_PATH_LEN; + } + + if(load_images(dirptr,img_fol.imgdirpath)==1){ + goto fails; + } if (num_images==0){ fprintf(stdout,"Folder is empty\n"); - return EXIT_FAILURE; + goto fails; } }else{ num_images=1; @@ -480,7 +491,7 @@ int main(int argc, char *argv[]) fout = fopen(parameters.outfile,"w"); if (!fout){ fprintf(stderr, "ERROR -> failed to open %s for writing\n", parameters.outfile); - return EXIT_FAILURE; + goto fails; } } else @@ -504,7 +515,7 @@ int main(int argc, char *argv[]) l_stream = opj_stream_create_default_file_stream(parameters.infile,1); if (!l_stream){ fprintf(stderr, "ERROR -> failed to create the stream from the file %s\n",parameters.infile); - return EXIT_FAILURE; + goto fails; } /* Read the JPEG2000 stream */ @@ -546,7 +557,7 @@ int main(int argc, char *argv[]) opj_stream_destroy(l_stream); opj_destroy_codec(l_codec); fclose(fout); - return EXIT_FAILURE; + goto fails; } /* Read the main header of the codestream and if necessary the JP2 boxes*/ @@ -556,7 +567,7 @@ int main(int argc, char *argv[]) opj_destroy_codec(l_codec); opj_image_destroy(image); fclose(fout); - return EXIT_FAILURE; + goto fails; } opj_dump_codec(l_codec, img_fol.flag, fout ); @@ -588,4 +599,12 @@ int main(int argc, char *argv[]) fclose(fout); return EXIT_SUCCESS; + +fails: + if(dirptr){ + if(dirptr->filename) free(dirptr->filename); + if(dirptr->filename_buf) free(dirptr->filename_buf); + free(dirptr); + } + return EXIT_FAILURE; } diff --git a/src/lib/openjp2/cidx_manager.c b/src/lib/openjp2/cidx_manager.c index ff2dbdaa..30561ed2 100644 --- a/src/lib/openjp2/cidx_manager.c +++ b/src/lib/openjp2/cidx_manager.c @@ -60,7 +60,9 @@ int opj_write_cidx( int offset, opj_stream_private_t *cio, opj_codestream_info_t lenp = -1; box = (opj_jp2_box_t *)opj_calloc( 32, sizeof(opj_jp2_box_t)); - + if(box == NULL){ + return 0; + } for (i=0;i<2;i++){ if(i) diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c index f6be14de..4dc69773 100644 --- a/src/lib/openjp2/j2k.c +++ b/src/lib/openjp2/j2k.c @@ -2094,7 +2094,7 @@ static OPJ_BOOL opj_j2k_read_siz(opj_j2k_t *p_j2k, opj_event_msg(p_manager, EVT_ERROR, "JPWL: bad image size (%d x %d)\n", l_image->x1, l_image->y1); - if (!JPWL_ASSUME || JPWL_ASSUME) { + if (!JPWL_ASSUME) { opj_event_msg(p_manager, EVT_ERROR, "JPWL: giving up\n"); return OPJ_FALSE; } @@ -2276,7 +2276,7 @@ static OPJ_BOOL opj_j2k_read_siz(opj_j2k_t *p_j2k, if (!l_cp->tcps) { opj_event_msg(p_manager, JPWL_ASSUME ? EVT_WARNING : EVT_ERROR, "JPWL: could not alloc tcps field of cp\n"); - if (!JPWL_ASSUME || JPWL_ASSUME) { + if (!JPWL_ASSUME) { opj_event_msg(p_manager, EVT_ERROR, "JPWL: giving up\n"); return OPJ_FALSE; } @@ -2584,6 +2584,9 @@ static OPJ_BOOL opj_j2k_read_cod ( opj_j2k_t *p_j2k, p_j2k->cstr_info->prog = l_tcp->prg; p_j2k->cstr_info->numlayers = l_tcp->numlayers; p_j2k->cstr_info->numdecompos = (OPJ_INT32*) opj_malloc(l_image->numcomps * sizeof(OPJ_UINT32)); + if(!p_j2k->cstr_info->numdecompos){ + return OPJ_FALSE; + } for (i = 0; i < l_image->numcomps; ++i) { p_j2k->cstr_info->numdecompos[i] = l_tcp->tccps[i].numresolutions - 1; } @@ -4627,7 +4630,7 @@ static OPJ_BOOL opj_j2k_read_rgn (opj_j2k_t *p_j2k, opj_event_msg(p_manager, EVT_ERROR, "JPWL: bad component number in RGN (%d when there are only %d)\n", l_comp_room, l_nb_comp); - if (!JPWL_ASSUME || JPWL_ASSUME) { + if (!JPWL_ASSUME) { opj_event_msg(p_manager, EVT_ERROR, "JPWL: giving up\n"); return OPJ_FALSE; } diff --git a/src/lib/openjp2/jp2.c b/src/lib/openjp2/jp2.c index 6c6f6e83..a607c8a9 100644 --- a/src/lib/openjp2/jp2.c +++ b/src/lib/openjp2/jp2.c @@ -646,12 +646,13 @@ static OPJ_BYTE * opj_jp2_write_bpcc( opj_jp2_t *jp2, { OPJ_UINT32 i; /* room for 8 bytes for box and 1 byte for each component */ - OPJ_UINT32 l_bpcc_size = 8 + jp2->numcomps; + OPJ_UINT32 l_bpcc_size; OPJ_BYTE * l_bpcc_data,* l_current_bpcc_ptr; /* preconditions */ assert(jp2 != 00); assert(p_nb_bytes_written != 00); + l_bpcc_size = 8 + jp2->numcomps; l_bpcc_data = (OPJ_BYTE *) opj_calloc(1,l_bpcc_size); if (l_bpcc_data == 00) { @@ -1404,6 +1405,10 @@ static OPJ_BOOL opj_jp2_read_colr( opj_jp2_t *jp2, OPJ_UINT32 rl, ol, ra, oa, rb, ob, il; cielab = (OPJ_UINT32*)opj_malloc(9 * sizeof(OPJ_UINT32)); + if(cielab == NULL){ + opj_event_msg(p_manager, EVT_ERROR, "Not enough memory for cielab\n"); + return OPJ_FALSE; + } cielab[0] = 14; /* enumcs */ /* default values */ @@ -1639,7 +1644,7 @@ static OPJ_BOOL opj_jp2_write_ftyp(opj_jp2_t *jp2, opj_event_mgr_t * p_manager ) { OPJ_UINT32 i; - OPJ_UINT32 l_ftyp_size = 16 + 4 * jp2->numcl; + OPJ_UINT32 l_ftyp_size; OPJ_BYTE * l_ftyp_data, * l_current_data_ptr; OPJ_BOOL l_result; @@ -1647,6 +1652,7 @@ static OPJ_BOOL opj_jp2_write_ftyp(opj_jp2_t *jp2, assert(cio != 00); assert(jp2 != 00); assert(p_manager != 00); + l_ftyp_size = 16 + 4 * jp2->numcl; l_ftyp_data = (OPJ_BYTE *) opj_calloc(1,l_ftyp_size); diff --git a/src/lib/openjp2/phix_manager.c b/src/lib/openjp2/phix_manager.c index 5a3e8838..45e559d4 100644 --- a/src/lib/openjp2/phix_manager.c +++ b/src/lib/openjp2/phix_manager.c @@ -57,7 +57,9 @@ int opj_write_phix( int coff, opj_codestream_info_t cstr_info, OPJ_BOOL EPHused, OPJ_OFF_T lenp = 0; box = (opj_jp2_box_t *)opj_calloc( (size_t)cstr_info.numcomps, sizeof(opj_jp2_box_t)); - + if(box == NULL){ + return 0; + } for( i=0;i<2;i++){ if (i) opj_stream_seek( cio, lenp, p_manager); diff --git a/src/lib/openjp2/ppix_manager.c b/src/lib/openjp2/ppix_manager.c index fce51489..018a8812 100644 --- a/src/lib/openjp2/ppix_manager.c +++ b/src/lib/openjp2/ppix_manager.c @@ -61,7 +61,9 @@ int opj_write_ppix( int coff, opj_codestream_info_t cstr_info, OPJ_BOOL EPHused, lenp = -1; box = (opj_jp2_box_t *)opj_calloc( (size_t)cstr_info.numcomps, sizeof(opj_jp2_box_t)); - + if(box == NULL){ + return 0; + } for (i=0;i<2;i++){ if (i) diff --git a/src/lib/openjp2/t1.c b/src/lib/openjp2/t1.c index a3ca93e8..ae83fd52 100644 --- a/src/lib/openjp2/t1.c +++ b/src/lib/openjp2/t1.c @@ -381,7 +381,7 @@ static void opj_t1_enc_sigpass_step( opj_t1_t *t1, flag = vsc ? (OPJ_UINT32)((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (OPJ_UINT32)(*flagsp); if ((flag & T1_SIG_OTH) && !(flag & (T1_SIG | T1_VISIT))) { - v = opj_int_abs(*datap) & one ? 1 : 0; + v = (opj_int_abs(*datap) & one) ? 1 : 0; opj_mqc_setcurctx(mqc, opj_t1_getctxno_zc(flag, orient)); /* ESSAI */ if (type == T1_TYPE_RAW) { /* BYPASS/LAZY MODE */ opj_mqc_bypass_enc(mqc, (OPJ_UINT32)v); @@ -625,7 +625,7 @@ static void opj_t1_enc_refpass_step( opj_t1_t *t1, flag = vsc ? (OPJ_UINT32)((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (OPJ_UINT32)(*flagsp); if ((flag & (T1_SIG | T1_VISIT)) == T1_SIG) { *nmsedec += opj_t1_getnmsedec_ref((OPJ_UINT32)opj_int_abs(*datap), (OPJ_UINT32)(bpno)); - v = opj_int_abs(*datap) & one ? 1 : 0; + v = (opj_int_abs(*datap) & one) ? 1 : 0; opj_mqc_setcurctx(mqc, opj_t1_getctxno_mag(flag)); /* ESSAI */ if (type == T1_TYPE_RAW) { /* BYPASS/LAZY MODE */ opj_mqc_bypass_enc(mqc, (OPJ_UINT32)v); @@ -849,7 +849,7 @@ static void opj_t1_enc_clnpass_step( } if (!(*flagsp & (T1_SIG | T1_VISIT))) { opj_mqc_setcurctx(mqc, opj_t1_getctxno_zc(flag, orient)); - v = opj_int_abs(*datap) & one ? 1 : 0; + v = (opj_int_abs(*datap) & one) ? 1 : 0; opj_mqc_encode(mqc, (OPJ_UINT32)v); if (v) { LABEL_PARTIAL: diff --git a/src/lib/openjp2/thix_manager.c b/src/lib/openjp2/thix_manager.c index 0967b1e9..0bd79897 100644 --- a/src/lib/openjp2/thix_manager.c +++ b/src/lib/openjp2/thix_manager.c @@ -49,7 +49,9 @@ int opj_write_thix( int coff, opj_codestream_info_t cstr_info, opj_stream_privat lenp = 0; box = (opj_jp2_box_t *)opj_calloc( (size_t)(cstr_info.tw*cstr_info.th), sizeof(opj_jp2_box_t)); - + if(box == NULL){ + return 0; + } for ( i = 0; i < 2 ; i++ ){ if (i) opj_stream_seek( cio, lenp, p_manager); diff --git a/tests/test_tile_encoder.c b/tests/test_tile_encoder.c index 6ce628b5..d01a7e52 100644 --- a/tests/test_tile_encoder.c +++ b/tests/test_tile_encoder.c @@ -129,7 +129,9 @@ int main (int argc, char *argv[]) l_data_size = (OPJ_UINT32)tile_width * (OPJ_UINT32)tile_height * (OPJ_UINT32)num_comps * (OPJ_UINT32)(comp_prec/8); l_data = (OPJ_BYTE*) malloc(l_data_size * sizeof(OPJ_BYTE)); - + if(l_data == NULL){ + return 1; + } fprintf(stdout, "Encoding random values -> keep in mind that this is very hard to compress\n"); for (i=0;i test_tile_encoder: failed to setup the codec!\n"); opj_destroy_codec(l_codec); opj_image_destroy(l_image); + free(l_data); return 1; } @@ -268,6 +273,7 @@ int main (int argc, char *argv[]) fprintf(stderr, "ERROR -> test_tile_encoder: failed to create the stream from the output file %s !\n",output_file ); opj_destroy_codec(l_codec); opj_image_destroy(l_image); + free(l_data); return 1; } @@ -276,6 +282,7 @@ int main (int argc, char *argv[]) opj_stream_destroy(l_stream); opj_destroy_codec(l_codec); opj_image_destroy(l_image); + free(l_data); return 1; } @@ -285,6 +292,7 @@ int main (int argc, char *argv[]) opj_stream_destroy(l_stream); opj_destroy_codec(l_codec); opj_image_destroy(l_image); + free(l_data); return 1; } } @@ -294,6 +302,7 @@ int main (int argc, char *argv[]) opj_stream_destroy(l_stream); opj_destroy_codec(l_codec); opj_image_destroy(l_image); + free(l_data); return 1; } From ad593c9e0622e0d8d87228e67e4dbd36243ffd22 Mon Sep 17 00:00:00 2001 From: Matthieu Darbois Date: Fri, 29 Apr 2016 23:51:14 +0200 Subject: [PATCH 22/39] Fix heap-buffer-overflow in color_esycc_to_rgb (#748) When all components do not have the same dx/dy, components buffer are read beyond their end. Do not convert in this case. Update uclouvain/openjpeg#725 --- src/bin/common/color.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/bin/common/color.c b/src/bin/common/color.c index cd4fafdd..00eac515 100644 --- a/src/bin/common/color.c +++ b/src/bin/common/color.c @@ -890,7 +890,14 @@ void color_esycc_to_rgb(opj_image_t *image) int flip_value = (1 << (image->comps[0].prec-1)); int max_value = (1 << image->comps[0].prec) - 1; - if(image->numcomps < 3) return; + if ( + (image->numcomps < 3) + || (image->comps[0].dx != image->comps[1].dx) || (image->comps[0].dx != image->comps[2].dx) + || (image->comps[0].dy != image->comps[1].dy) || (image->comps[0].dy != image->comps[2].dy) + ) { + fprintf(stderr,"%s:%d:color_esycc_to_rgb\n\tCAN NOT CONVERT\n", __FILE__,__LINE__); + return; + } w = image->comps[0].w; h = image->comps[0].h; From 15f081c89650dccee4aa4ae66f614c3fdb268767 Mon Sep 17 00:00:00 2001 From: Matthieu Darbois Date: Sat, 30 Apr 2016 00:33:27 +0200 Subject: [PATCH 23/39] Fix Out-Of-Bounds Read in sycc42x_to_rgb function (#745) 42x Images with an odd x0/y0 lead to subsampled component starting at the 2nd column/line. That is offset = comp->dx * comp->x0 - image->x0 = 1 Fix #726 --- src/bin/common/color.c | 148 +++++++++++++++++++++++---------------- src/bin/jp2/convertbmp.c | 2 +- 2 files changed, 87 insertions(+), 63 deletions(-) diff --git a/src/bin/common/color.c b/src/bin/common/color.c index 00eac515..20aba2ba 100644 --- a/src/bin/common/color.c +++ b/src/bin/common/color.c @@ -91,22 +91,22 @@ static void sycc444_to_rgb(opj_image_t *img) { int *d0, *d1, *d2, *r, *g, *b; const int *y, *cb, *cr; - unsigned int maxw, maxh, max, i; + size_t maxw, maxh, max, i; int offset, upb; upb = (int)img->comps[0].prec; offset = 1<<(upb - 1); upb = (1<comps[0].w; maxh = (unsigned int)img->comps[0].h; + maxw = (size_t)img->comps[0].w; maxh = (size_t)img->comps[0].h; max = maxw * maxh; y = img->comps[0].data; cb = img->comps[1].data; cr = img->comps[2].data; - d0 = r = (int*)malloc(sizeof(int) * (size_t)max); - d1 = g = (int*)malloc(sizeof(int) * (size_t)max); - d2 = b = (int*)malloc(sizeof(int) * (size_t)max); + d0 = r = (int*)malloc(sizeof(int) * max); + d1 = g = (int*)malloc(sizeof(int) * max); + d2 = b = (int*)malloc(sizeof(int) * max); if(r == NULL || g == NULL || b == NULL) goto fails; @@ -118,107 +118,138 @@ static void sycc444_to_rgb(opj_image_t *img) free(img->comps[0].data); img->comps[0].data = d0; free(img->comps[1].data); img->comps[1].data = d1; free(img->comps[2].data); img->comps[2].data = d2; + img->color_space = OPJ_CLRSPC_SRGB; return; fails: - if(r) free(r); - if(g) free(g); - if(b) free(b); - + free(r); + free(g); + free(b); }/* sycc444_to_rgb() */ static void sycc422_to_rgb(opj_image_t *img) { int *d0, *d1, *d2, *r, *g, *b; const int *y, *cb, *cr; - unsigned int maxw, maxh, max; + size_t maxw, maxh, max, offx, loopmaxw; int offset, upb; - unsigned int i, j; + size_t i; upb = (int)img->comps[0].prec; offset = 1<<(upb - 1); upb = (1<comps[0].w; maxh = (unsigned int)img->comps[0].h; + maxw = (size_t)img->comps[0].w; maxh = (size_t)img->comps[0].h; max = maxw * maxh; y = img->comps[0].data; cb = img->comps[1].data; cr = img->comps[2].data; - d0 = r = (int*)malloc(sizeof(int) * (size_t)max); - d1 = g = (int*)malloc(sizeof(int) * (size_t)max); - d2 = b = (int*)malloc(sizeof(int) * (size_t)max); + d0 = r = (int*)malloc(sizeof(int) * max); + d1 = g = (int*)malloc(sizeof(int) * max); + d2 = b = (int*)malloc(sizeof(int) * max); if(r == NULL || g == NULL || b == NULL) goto fails; + /* if img->x0 is odd, then first column shall use Cb/Cr = 0 */ + offx = img->x0 & 1U; + loopmaxw = maxw - offx; + for(i=0U; i < maxh; ++i) { - for(j=0U; j < (maxw & ~(unsigned int)1U); j += 2U) + size_t j; + + if (offx > 0U) { + sycc_to_rgb(offset, upb, *y, 0, 0, r, g, b); + ++y; ++r; ++g; ++b; + } + + for(j=0U; j < (loopmaxw & ~(size_t)1U); j += 2U) { sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b); ++y; ++r; ++g; ++b; sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b); ++y; ++r; ++g; ++b; ++cb; ++cr; } - if (j < maxw) { + if (j < loopmaxw) { sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b); ++y; ++r; ++g; ++b; ++cb; ++cr; } } + free(img->comps[0].data); img->comps[0].data = d0; free(img->comps[1].data); img->comps[1].data = d1; free(img->comps[2].data); img->comps[2].data = d2; -#if defined(USE_JPWL) || defined(USE_MJ2) - img->comps[1].w = maxw; img->comps[1].h = maxh; - img->comps[2].w = maxw; img->comps[2].h = maxh; -#else - img->comps[1].w = (OPJ_UINT32)maxw; img->comps[1].h = (OPJ_UINT32)maxh; - img->comps[2].w = (OPJ_UINT32)maxw; img->comps[2].h = (OPJ_UINT32)maxh; -#endif - img->comps[1].dx = img->comps[0].dx; - img->comps[2].dx = img->comps[0].dx; - img->comps[1].dy = img->comps[0].dy; - img->comps[2].dy = img->comps[0].dy; + img->comps[1].w = img->comps[2].w = img->comps[0].w; + img->comps[1].h = img->comps[2].h = img->comps[0].h; + img->comps[1].dx = img->comps[2].dx = img->comps[0].dx; + img->comps[1].dy = img->comps[2].dy = img->comps[0].dy; + img->color_space = OPJ_CLRSPC_SRGB; return; fails: - if(r) free(r); - if(g) free(g); - if(b) free(b); - + free(r); + free(g); + free(b); }/* sycc422_to_rgb() */ static void sycc420_to_rgb(opj_image_t *img) { int *d0, *d1, *d2, *r, *g, *b, *nr, *ng, *nb; const int *y, *cb, *cr, *ny; - unsigned int maxw, maxh, max; + size_t maxw, maxh, max, offx, loopmaxw, offy, loopmaxh; int offset, upb; - unsigned int i, j; + size_t i; upb = (int)img->comps[0].prec; offset = 1<<(upb - 1); upb = (1<comps[0].w; maxh = (unsigned int)img->comps[0].h; + maxw = (size_t)img->comps[0].w; maxh = (size_t)img->comps[0].h; max = maxw * maxh; y = img->comps[0].data; cb = img->comps[1].data; cr = img->comps[2].data; - d0 = r = (int*)malloc(sizeof(int) * (size_t)max); - d1 = g = (int*)malloc(sizeof(int) * (size_t)max); - d2 = b = (int*)malloc(sizeof(int) * (size_t)max); + d0 = r = (int*)malloc(sizeof(int) * max); + d1 = g = (int*)malloc(sizeof(int) * max); + d2 = b = (int*)malloc(sizeof(int) * max); + + if (r == NULL || g == NULL || b == NULL) goto fails; + + /* if img->x0 is odd, then first column shall use Cb/Cr = 0 */ + offx = img->x0 & 1U; + loopmaxw = maxw - offx; + /* if img->y0 is odd, then first line shall use Cb/Cr = 0 */ + offy = img->y0 & 1U; + loopmaxh = maxh - offy; + + if (offy > 0U) { + size_t j; + + for(j=0; j < maxw; ++j) + { + sycc_to_rgb(offset, upb, *y, 0, 0, r, g, b); + ++y; ++r; ++g; ++b; + } + } - if(r == NULL || g == NULL || b == NULL) goto fails; - - for(i=0U; i < (maxh & ~(unsigned int)1U); i += 2U) + for(i=0U; i < (loopmaxh & ~(size_t)1U); i += 2U) { + size_t j; + ny = y + maxw; nr = r + maxw; ng = g + maxw; nb = b + maxw; + + if (offx > 0U) { + sycc_to_rgb(offset, upb, *y, 0, 0, r, g, b); + ++y; ++r; ++g; ++b; + sycc_to_rgb(offset, upb, *ny, *cb, *cr, nr, ng, nb); + ++ny; ++nr; ++ng; ++nb; + } - for(j=0; j < (maxw & ~(unsigned int)1U); j += 2U) + for(j=0; j < (loopmaxw & ~(size_t)1U); j += 2U) { sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b); ++y; ++r; ++g; ++b; @@ -230,7 +261,7 @@ static void sycc420_to_rgb(opj_image_t *img) sycc_to_rgb(offset, upb, *ny, *cb, *cr, nr, ng, nb); ++ny; ++nr; ++ng; ++nb; ++cb; ++cr; } - if(j < maxw) + if(j < loopmaxw) { sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b); ++y; ++r; ++g; ++b; @@ -240,9 +271,11 @@ static void sycc420_to_rgb(opj_image_t *img) } y += maxw; r += maxw; g += maxw; b += maxw; } - if(i < maxh) + if(i < loopmaxh) { - for(j=0U; j < (maxw & ~(unsigned int)1U); j += 2U) + size_t j; + + for(j=0U; j < (maxw & ~(size_t)1U); j += 2U) { sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b); @@ -262,24 +295,17 @@ static void sycc420_to_rgb(opj_image_t *img) free(img->comps[1].data); img->comps[1].data = d1; free(img->comps[2].data); img->comps[2].data = d2; -#if defined(USE_JPWL) || defined(USE_MJ2) - img->comps[1].w = maxw; img->comps[1].h = maxh; - img->comps[2].w = maxw; img->comps[2].h = maxh; -#else - img->comps[1].w = (OPJ_UINT32)maxw; img->comps[1].h = (OPJ_UINT32)maxh; - img->comps[2].w = (OPJ_UINT32)maxw; img->comps[2].h = (OPJ_UINT32)maxh; -#endif - img->comps[1].dx = img->comps[0].dx; - img->comps[2].dx = img->comps[0].dx; - img->comps[1].dy = img->comps[0].dy; - img->comps[2].dy = img->comps[0].dy; + img->comps[1].w = img->comps[2].w = img->comps[0].w; + img->comps[1].h = img->comps[2].h = img->comps[0].h; + img->comps[1].dx = img->comps[2].dx = img->comps[0].dx; + img->comps[1].dy = img->comps[2].dy = img->comps[0].dy; + img->color_space = OPJ_CLRSPC_SRGB; return; fails: - if(r) free(r); - if(g) free(g); - if(b) free(b); - + free(r); + free(g); + free(b); }/* sycc420_to_rgb() */ void color_sycc_to_rgb(opj_image_t *img) @@ -324,8 +350,6 @@ void color_sycc_to_rgb(opj_image_t *img) fprintf(stderr,"%s:%d:color_sycc_to_rgb\n\tCAN NOT CONVERT\n", __FILE__,__LINE__); return; } - img->color_space = OPJ_CLRSPC_SRGB; - }/* color_sycc_to_rgb() */ #if defined(OPJ_HAVE_LIBLCMS2) || defined(OPJ_HAVE_LIBLCMS1) diff --git a/src/bin/jp2/convertbmp.c b/src/bin/jp2/convertbmp.c index a09c0ae5..d264823f 100644 --- a/src/bin/jp2/convertbmp.c +++ b/src/bin/jp2/convertbmp.c @@ -967,7 +967,7 @@ int imagetobmp(opj_image_t * image, const char *outfile) { fprintf(fdest, "%c", (OPJ_UINT8)r); if ((i + 1) % w == 0) { - for ((pad = w % 4) ? (4 - w % 4) : 0; pad > 0; pad--) /* ADD */ + for (pad = (w % 4) ? (4 - w % 4) : 0; pad > 0; pad--) /* ADD */ fprintf(fdest, "%c", 0); } } From be42e72d220ffa89b33c8d24d0c0d4c8de8533cf Mon Sep 17 00:00:00 2001 From: Matthieu Darbois Date: Sat, 30 Apr 2016 01:12:16 +0200 Subject: [PATCH 24/39] Fix warnings (#763) --- src/bin/common/color.c | 453 ++++++++++++++++++++--------------------- src/lib/openjp2/j2k.c | 16 +- src/lib/openjp2/raw.c | 2 +- 3 files changed, 232 insertions(+), 239 deletions(-) diff --git a/src/bin/common/color.c b/src/bin/common/color.c index 20aba2ba..944df73b 100644 --- a/src/bin/common/color.c +++ b/src/bin/common/color.c @@ -378,16 +378,15 @@ void color_apply_icc_profile(opj_image_t *image) cmsColorSpaceSignature in_space, out_space; cmsUInt32Number intent, in_type, out_type; int *r, *g, *b; - size_t nr_samples; - int prec, i, max, max_w, max_h, ok = 0; + size_t nr_samples, i, max, max_w, max_h; + int prec, ok = 0; OPJ_COLOR_SPACE new_space; - in_prof = - cmsOpenProfileFromMem(image->icc_profile_buf, image->icc_profile_len); + in_prof = cmsOpenProfileFromMem(image->icc_profile_buf, image->icc_profile_len); #ifdef DEBUG_PROFILE - FILE *icm = fopen("debug.icm","wb"); - fwrite( image->icc_profile_buf,1, image->icc_profile_len,icm); - fclose(icm); + FILE *icm = fopen("debug.icm","wb"); + fwrite( image->icc_profile_buf,1, image->icc_profile_len,icm); + fclose(icm); #endif if(in_prof == NULL) return; @@ -397,87 +396,83 @@ void color_apply_icc_profile(opj_image_t *image) intent = cmsGetHeaderRenderingIntent(in_prof); - max_w = (int)image->comps[0].w; - max_h = (int)image->comps[0].h; + max_w = image->comps[0].w; + max_h = image->comps[0].h; prec = (int)image->comps[0].prec; if(out_space == cmsSigRgbData) /* enumCS 16 */ - { - if( prec <= 8 ) - { - in_type = TYPE_RGB_8; - out_type = TYPE_RGB_8; - } + { + if( prec <= 8 ) + { + in_type = TYPE_RGB_8; + out_type = TYPE_RGB_8; + } + else + { + in_type = TYPE_RGB_16; + out_type = TYPE_RGB_16; + } + out_prof = cmsCreate_sRGBProfile(); + new_space = OPJ_CLRSPC_SRGB; + } + else if(out_space == cmsSigGrayData) /* enumCS 17 */ + { + in_type = TYPE_GRAY_8; + out_type = TYPE_RGB_8; + out_prof = cmsCreate_sRGBProfile(); + new_space = OPJ_CLRSPC_SRGB; + } + else if(out_space == cmsSigYCbCrData) /* enumCS 18 */ + { + in_type = TYPE_YCbCr_16; + out_type = TYPE_RGB_16; + out_prof = cmsCreate_sRGBProfile(); + new_space = OPJ_CLRSPC_SRGB; + } else - { - in_type = TYPE_RGB_16; - out_type = TYPE_RGB_16; - } - out_prof = cmsCreate_sRGBProfile(); - new_space = OPJ_CLRSPC_SRGB; - } - else - if(out_space == cmsSigGrayData) /* enumCS 17 */ - { - in_type = TYPE_GRAY_8; - out_type = TYPE_RGB_8; - out_prof = cmsCreate_sRGBProfile(); - new_space = OPJ_CLRSPC_SRGB; - } - else - if(out_space == cmsSigYCbCrData) /* enumCS 18 */ - { - in_type = TYPE_YCbCr_16; - out_type = TYPE_RGB_16; - out_prof = cmsCreate_sRGBProfile(); - new_space = OPJ_CLRSPC_SRGB; - } - else - { + { #ifdef DEBUG_PROFILE -fprintf(stderr,"%s:%d: color_apply_icc_profile\n\tICC Profile has unknown " -"output colorspace(%#x)(%c%c%c%c)\n\tICC Profile ignored.\n", -__FILE__,__LINE__,out_space, - (out_space>>24) & 0xff,(out_space>>16) & 0xff, - (out_space>>8) & 0xff, out_space & 0xff); + fprintf(stderr,"%s:%d: color_apply_icc_profile\n\tICC Profile has unknown " + "output colorspace(%#x)(%c%c%c%c)\n\tICC Profile ignored.\n", + __FILE__,__LINE__,out_space, + (out_space>>24) & 0xff,(out_space>>16) & 0xff, + (out_space>>8) & 0xff, out_space & 0xff); #endif - cmsCloseProfile(in_prof); + cmsCloseProfile(in_prof); - return; - } + return; + } if(out_prof == NULL) - { - cmsCloseProfile(in_prof); - - return; - } + { + cmsCloseProfile(in_prof); + return; + } #ifdef DEBUG_PROFILE -fprintf(stderr,"%s:%d:color_apply_icc_profile\n\tchannels(%d) prec(%d) w(%d) h(%d)" -"\n\tprofile: in(%p) out(%p)\n",__FILE__,__LINE__,image->numcomps,prec, - max_w,max_h, (void*)in_prof,(void*)out_prof); + fprintf(stderr,"%s:%d:color_apply_icc_profile\n\tchannels(%d) prec(%d) w(%d) h(%d)" + "\n\tprofile: in(%p) out(%p)\n",__FILE__,__LINE__,image->numcomps,prec, + max_w,max_h, (void*)in_prof,(void*)out_prof); -fprintf(stderr,"\trender_intent (%u)\n\t" -"color_space: in(%#x)(%c%c%c%c) out:(%#x)(%c%c%c%c)\n\t" -" type: in(%u) out:(%u)\n", - intent, - in_space, - (in_space>>24) & 0xff,(in_space>>16) & 0xff, - (in_space>>8) & 0xff, in_space & 0xff, + fprintf(stderr,"\trender_intent (%u)\n\t" + "color_space: in(%#x)(%c%c%c%c) out:(%#x)(%c%c%c%c)\n\t" + " type: in(%u) out:(%u)\n", + intent, + in_space, + (in_space>>24) & 0xff,(in_space>>16) & 0xff, + (in_space>>8) & 0xff, in_space & 0xff, - out_space, - (out_space>>24) & 0xff,(out_space>>16) & 0xff, - (out_space>>8) & 0xff, out_space & 0xff, + out_space, + (out_space>>24) & 0xff,(out_space>>16) & 0xff, + (out_space>>8) & 0xff, out_space & 0xff, - in_type,out_type - ); + in_type,out_type + ); #else (void)prec; (void)in_space; #endif /* DEBUG_PROFILE */ - transform = cmsCreateTransform(in_prof, in_type, - out_prof, out_type, intent, 0); + transform = cmsCreateTransform(in_prof, in_type, out_prof, out_type, intent, 0); #ifdef OPJ_HAVE_LIBLCMS2 /* Possible for: LCMS_VERSION >= 2000 :*/ @@ -486,219 +481,217 @@ fprintf(stderr,"\trender_intent (%u)\n\t" #endif if(transform == NULL) - { + { #ifdef DEBUG_PROFILE -fprintf(stderr,"%s:%d:color_apply_icc_profile\n\tcmsCreateTransform failed. " -"ICC Profile ignored.\n",__FILE__,__LINE__); + fprintf(stderr,"%s:%d:color_apply_icc_profile\n\tcmsCreateTransform failed. " + "ICC Profile ignored.\n",__FILE__,__LINE__); #endif #ifdef OPJ_HAVE_LIBLCMS1 - cmsCloseProfile(in_prof); - cmsCloseProfile(out_prof); + cmsCloseProfile(in_prof); + cmsCloseProfile(out_prof); #endif - return; - } + return; + } if(image->numcomps > 2)/* RGB, RGBA */ - { - if( prec <= 8 ) - { - unsigned char *inbuf, *outbuf, *in, *out; + { + if( prec <= 8 ) + { + unsigned char *inbuf, *outbuf, *in, *out; - max = max_w * max_h; - nr_samples = (size_t)(max * 3 * sizeof(unsigned char)); - in = inbuf = (unsigned char*)malloc(nr_samples); - out = outbuf = (unsigned char*)malloc(nr_samples); + max = max_w * max_h; + nr_samples = (size_t)(max * 3U * sizeof(unsigned char)); + in = inbuf = (unsigned char*)malloc(nr_samples); + out = outbuf = (unsigned char*)malloc(nr_samples); - if(inbuf == NULL || outbuf == NULL) goto fails0; + if(inbuf == NULL || outbuf == NULL) goto fails0; - r = image->comps[0].data; - g = image->comps[1].data; - b = image->comps[2].data; + r = image->comps[0].data; + g = image->comps[1].data; + b = image->comps[2].data; - for(i = 0; i < max; ++i) - { - *in++ = (unsigned char)*r++; - *in++ = (unsigned char)*g++; - *in++ = (unsigned char)*b++; - } + for(i = 0U; i < max; ++i) + { + *in++ = (unsigned char)*r++; + *in++ = (unsigned char)*g++; + *in++ = (unsigned char)*b++; + } - cmsDoTransform(transform, inbuf, outbuf, (cmsUInt32Number)max); + cmsDoTransform(transform, inbuf, outbuf, (cmsUInt32Number)max); - r = image->comps[0].data; - g = image->comps[1].data; - b = image->comps[2].data; + r = image->comps[0].data; + g = image->comps[1].data; + b = image->comps[2].data; - for(i = 0; i < max; ++i) - { - *r++ = (int)*out++; - *g++ = (int)*out++; - *b++ = (int)*out++; - } - ok = 1; + for(i = 0U; i < max; ++i) + { + *r++ = (int)*out++; + *g++ = (int)*out++; + *b++ = (int)*out++; + } + ok = 1; fails0: - if(inbuf) free(inbuf); - if(outbuf) free(outbuf); - } - else /* prec > 8 */ - { - unsigned short *inbuf, *outbuf, *in, *out; + free(inbuf); + free(outbuf); + } + else /* prec > 8 */ + { + unsigned short *inbuf, *outbuf, *in, *out; - max = max_w * max_h; - nr_samples = (size_t)(max * 3 * sizeof(unsigned short)); - in = inbuf = (unsigned short*)malloc(nr_samples); - out = outbuf = (unsigned short*)malloc(nr_samples); + max = max_w * max_h; + nr_samples = (size_t)(max * 3U * sizeof(unsigned short)); + in = inbuf = (unsigned short*)malloc(nr_samples); + out = outbuf = (unsigned short*)malloc(nr_samples); - if(inbuf == NULL || outbuf == NULL) goto fails1; + if(inbuf == NULL || outbuf == NULL) goto fails1; - r = image->comps[0].data; - g = image->comps[1].data; - b = image->comps[2].data; + r = image->comps[0].data; + g = image->comps[1].data; + b = image->comps[2].data; - for(i = 0; i < max; ++i) - { - *in++ = (unsigned short)*r++; - *in++ = (unsigned short)*g++; - *in++ = (unsigned short)*b++; - } + for(i = 0U ; i < max; ++i) + { + *in++ = (unsigned short)*r++; + *in++ = (unsigned short)*g++; + *in++ = (unsigned short)*b++; + } - cmsDoTransform(transform, inbuf, outbuf, (cmsUInt32Number)max); + cmsDoTransform(transform, inbuf, outbuf, (cmsUInt32Number)max); - r = image->comps[0].data; - g = image->comps[1].data; - b = image->comps[2].data; + r = image->comps[0].data; + g = image->comps[1].data; + b = image->comps[2].data; - for(i = 0; i < max; ++i) - { - *r++ = (int)*out++; - *g++ = (int)*out++; - *b++ = (int)*out++; - } - ok = 1; + for(i = 0; i < max; ++i) + { + *r++ = (int)*out++; + *g++ = (int)*out++; + *b++ = (int)*out++; + } + ok = 1; fails1: - if(inbuf) free(inbuf); - if(outbuf) free(outbuf); - } - } + free(inbuf); + free(outbuf); + } + } else /* image->numcomps <= 2 : GRAY, GRAYA */ - { - if(prec <= 8) - { - unsigned char *in, *inbuf, *out, *outbuf; - opj_image_comp_t *new_comps; + { + if(prec <= 8) + { + unsigned char *in, *inbuf, *out, *outbuf; + opj_image_comp_t *new_comps; - max = max_w * max_h; - nr_samples = (size_t)(max * 3 * sizeof(unsigned char)); - in = inbuf = (unsigned char*)malloc(nr_samples); - out = outbuf = (unsigned char*)malloc(nr_samples); - g = (int*)calloc((size_t)max, sizeof(int)); - b = (int*)calloc((size_t)max, sizeof(int)); + max = max_w * max_h; + nr_samples = (size_t)(max * 3 * sizeof(unsigned char)); + in = inbuf = (unsigned char*)malloc(nr_samples); + out = outbuf = (unsigned char*)malloc(nr_samples); + g = (int*)calloc((size_t)max, sizeof(int)); + b = (int*)calloc((size_t)max, sizeof(int)); - if(inbuf == NULL || outbuf == NULL || g == NULL || b == NULL) goto fails2; + if(inbuf == NULL || outbuf == NULL || g == NULL || b == NULL) goto fails2; - new_comps = (opj_image_comp_t*) - realloc(image->comps, (image->numcomps+2)*sizeof(opj_image_comp_t)); + new_comps = (opj_image_comp_t*)realloc(image->comps, (image->numcomps+2)*sizeof(opj_image_comp_t)); - if(new_comps == NULL) goto fails2; + if(new_comps == NULL) goto fails2; - image->comps = new_comps; + image->comps = new_comps; - if(image->numcomps == 2) - image->comps[3] = image->comps[1]; + if(image->numcomps == 2) + image->comps[3] = image->comps[1]; - image->comps[1] = image->comps[0]; - image->comps[2] = image->comps[0]; + image->comps[1] = image->comps[0]; + image->comps[2] = image->comps[0]; - image->comps[1].data = g; - image->comps[2].data = b; + image->comps[1].data = g; + image->comps[2].data = b; - image->numcomps += 2; + image->numcomps += 2; - r = image->comps[0].data; + r = image->comps[0].data; - for(i = 0; i < max; ++i) - { - *in++ = (unsigned char)*r++; - } - cmsDoTransform(transform, inbuf, outbuf, (cmsUInt32Number)max); + for(i = 0U; i < max; ++i) + { + *in++ = (unsigned char)*r++; + } + cmsDoTransform(transform, inbuf, outbuf, (cmsUInt32Number)max); - r = image->comps[0].data; - g = image->comps[1].data; - b = image->comps[2].data; + r = image->comps[0].data; + g = image->comps[1].data; + b = image->comps[2].data; - for(i = 0; i < max; ++i) - { - *r++ = (int)*out++; *g++ = (int)*out++; *b++ = (int)*out++; - } - r = g = b = NULL; - ok = 1; + for(i = 0U; i < max; ++i) + { + *r++ = (int)*out++; *g++ = (int)*out++; *b++ = (int)*out++; + } + r = g = b = NULL; + ok = 1; fails2: - if(inbuf) free(inbuf); - if(outbuf) free(outbuf); - if(g) free(g); - if(b) free(b); - } - else /* prec > 8 */ - { - unsigned short *in, *inbuf, *out, *outbuf; - opj_image_comp_t *new_comps; + free(inbuf); + free(outbuf); + free(g); + free(b); + } + else /* prec > 8 */ + { + unsigned short *in, *inbuf, *out, *outbuf; + opj_image_comp_t *new_comps; - max = max_w * max_h; - nr_samples = (size_t)(max * 3 * sizeof(unsigned short)); - in = inbuf = (unsigned short*)malloc(nr_samples); - out = outbuf = (unsigned short*)malloc(nr_samples); - g = (int*)calloc((size_t)max, sizeof(int)); - b = (int*)calloc((size_t)max, sizeof(int)); + max = max_w * max_h; + nr_samples = (size_t)(max * 3U * sizeof(unsigned short)); + in = inbuf = (unsigned short*)malloc(nr_samples); + out = outbuf = (unsigned short*)malloc(nr_samples); + g = (int*)calloc((size_t)max, sizeof(int)); + b = (int*)calloc((size_t)max, sizeof(int)); - if(inbuf == NULL || outbuf == NULL || g == NULL || b == NULL) goto fails3; + if(inbuf == NULL || outbuf == NULL || g == NULL || b == NULL) goto fails3; - new_comps = (opj_image_comp_t*) - realloc(image->comps, (image->numcomps+2)*sizeof(opj_image_comp_t)); + new_comps = (opj_image_comp_t*)realloc(image->comps, (image->numcomps+2)*sizeof(opj_image_comp_t)); - if(new_comps == NULL) goto fails3; + if(new_comps == NULL) goto fails3; - image->comps = new_comps; + image->comps = new_comps; - if(image->numcomps == 2) - image->comps[3] = image->comps[1]; + if(image->numcomps == 2) + image->comps[3] = image->comps[1]; - image->comps[1] = image->comps[0]; - image->comps[2] = image->comps[0]; + image->comps[1] = image->comps[0]; + image->comps[2] = image->comps[0]; - image->comps[1].data = g; - image->comps[2].data = b; + image->comps[1].data = g; + image->comps[2].data = b; - image->numcomps += 2; + image->numcomps += 2; - r = image->comps[0].data; + r = image->comps[0].data; - for(i = 0; i < max; ++i) - { - *in++ = (unsigned short)*r++; - } - cmsDoTransform(transform, inbuf, outbuf, (cmsUInt32Number)max); + for(i = 0U; i < max; ++i) + { + *in++ = (unsigned short)*r++; + } + cmsDoTransform(transform, inbuf, outbuf, (cmsUInt32Number)max); - r = image->comps[0].data; - g = image->comps[1].data; - b = image->comps[2].data; + r = image->comps[0].data; + g = image->comps[1].data; + b = image->comps[2].data; - for(i = 0; i < max; ++i) - { - *r++ = (int)*out++; *g++ = (int)*out++; *b++ = (int)*out++; - } - r = g = b = NULL; - ok = 1; + for(i = 0; i < max; ++i) + { + *r++ = (int)*out++; *g++ = (int)*out++; *b++ = (int)*out++; + } + r = g = b = NULL; + ok = 1; fails3: - if(inbuf) free(inbuf); - if(outbuf) free(outbuf); - if(g) free(g); - if(b) free(b); - } - }/* if(image->numcomps > 2) */ + free(inbuf); + free(outbuf); + free(g); + free(b); + } + }/* if(image->numcomps > 2) */ cmsDeleteTransform(transform); @@ -707,9 +700,9 @@ fails3: cmsCloseProfile(out_prof); #endif if(ok) - { - image->color_space = new_space; - } + { + image->color_space = new_space; + } }/* color_apply_icc_profile() */ void color_cielab_to_rgb(opj_image_t *image) diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c index 4dc69773..323a3b80 100644 --- a/src/lib/openjp2/j2k.c +++ b/src/lib/openjp2/j2k.c @@ -2442,22 +2442,22 @@ static OPJ_BOOL opj_j2k_write_cod( opj_j2k_t *p_j2k, l_current_data = p_j2k->m_specific_param.m_encoder.m_header_tile_data; - opj_write_bytes(l_current_data,J2K_MS_COD,2); /* COD */ + opj_write_bytes(l_current_data,J2K_MS_COD,2); /* COD */ l_current_data += 2; - opj_write_bytes(l_current_data,l_code_size-2,2); /* L_COD */ + opj_write_bytes(l_current_data,l_code_size-2,2); /* L_COD */ l_current_data += 2; - opj_write_bytes(l_current_data,l_tcp->csty,1); /* Scod */ + opj_write_bytes(l_current_data,l_tcp->csty,1); /* Scod */ ++l_current_data; - opj_write_bytes(l_current_data,l_tcp->prg,1); /* SGcod (A) */ + opj_write_bytes(l_current_data,(OPJ_UINT32)l_tcp->prg,1); /* SGcod (A) */ ++l_current_data; - opj_write_bytes(l_current_data,l_tcp->numlayers,2); /* SGcod (B) */ + opj_write_bytes(l_current_data,l_tcp->numlayers,2); /* SGcod (B) */ l_current_data+=2; - opj_write_bytes(l_current_data,l_tcp->mct,1); /* SGcod (C) */ + opj_write_bytes(l_current_data,l_tcp->mct,1); /* SGcod (C) */ ++l_current_data; l_remaining_size -= 9; @@ -3174,7 +3174,7 @@ static void opj_j2k_write_poc_in_memory( opj_j2k_t *p_j2k, opj_write_bytes(l_current_data,l_current_poc->compno1,l_poc_room); /* CEpoc_i */ l_current_data+=l_poc_room; - opj_write_bytes(l_current_data,l_current_poc->prg,1); /* Ppoc_i */ + opj_write_bytes(l_current_data, (OPJ_UINT32)l_current_poc->prg,1); /* Ppoc_i */ ++l_current_data; /* change the value of the max layer according to the actual number of layers in the file, components and resolutions*/ @@ -5371,7 +5371,7 @@ static OPJ_BOOL opj_j2k_write_mcc_record( opj_j2k_t *p_j2k, l_current_data+=l_nb_bytes_for_comp; } - l_tmcc = ((!p_mcc_record->m_is_irreversible)&1)<<16; + l_tmcc = ((!p_mcc_record->m_is_irreversible) & 1U) << 16; if (p_mcc_record->m_decorrelation_array) { l_tmcc |= p_mcc_record->m_decorrelation_array->m_index; diff --git a/src/lib/openjp2/raw.c b/src/lib/openjp2/raw.c index 2498761c..d3581d1a 100644 --- a/src/lib/openjp2/raw.c +++ b/src/lib/openjp2/raw.c @@ -88,7 +88,7 @@ OPJ_UINT32 opj_raw_decode(opj_raw_t *raw) { } } raw->ct--; - d = (raw->c >> raw->ct) & 0x01; + d = ((OPJ_UINT32)raw->c >> raw->ct) & 0x01U; return d; } From f40a2ff2ad821cf6492761c01de136ac2bf48b4a Mon Sep 17 00:00:00 2001 From: mayeut Date: Sat, 30 Apr 2016 01:50:33 +0200 Subject: [PATCH 25/39] Fix bad call to fclose with NULL pointer --- src/bin/jp2/convert.c | 77 +++++++++++++++++++++---------------------- 1 file changed, 38 insertions(+), 39 deletions(-) diff --git a/src/bin/jp2/convert.c b/src/bin/jp2/convert.c index 940ac2fa..c130b3bf 100644 --- a/src/bin/jp2/convert.c +++ b/src/bin/jp2/convert.c @@ -1762,7 +1762,7 @@ int imagetopnm(opj_image_t * image, const char *outfile, int force_split) const char *tmp = outfile; char *destname; - alpha = NULL; + alpha = NULL; if((prec = (int)image->comps[0].prec) > 16) { @@ -1842,7 +1842,7 @@ int imagetopnm(opj_image_t * image, const char *outfile, int force_split) if(two) { v = *red + adjustR; ++red; -if(v > 65535) v = 65535; else if(v < 0) v = 0; + if(v > 65535) v = 65535; else if(v < 0) v = 0; /* netpbm: */ fprintf(fdest, "%c%c",(unsigned char)(v>>8), (unsigned char)v); @@ -1850,13 +1850,13 @@ if(v > 65535) v = 65535; else if(v < 0) v = 0; if(triple) { v = *green + adjustG; ++green; -if(v > 65535) v = 65535; else if(v < 0) v = 0; + if(v > 65535) v = 65535; else if(v < 0) v = 0; /* netpbm: */ fprintf(fdest, "%c%c",(unsigned char)(v>>8), (unsigned char)v); v = *blue + adjustB; ++blue; -if(v > 65535) v = 65535; else if(v < 0) v = 0; + if(v > 65535) v = 65535; else if(v < 0) v = 0; /* netpbm: */ fprintf(fdest, "%c%c",(unsigned char)(v>>8), (unsigned char)v); @@ -1866,7 +1866,7 @@ if(v > 65535) v = 65535; else if(v < 0) v = 0; if(has_alpha) { v = *alpha + adjustA; ++alpha; - if(v > 65535) v = 65535; else if(v < 0) v = 0; + if(v > 65535) v = 65535; else if(v < 0) v = 0; /* netpbm: */ fprintf(fdest, "%c%c",(unsigned char)(v>>8), (unsigned char)v); @@ -1876,28 +1876,28 @@ if(v > 65535) v = 65535; else if(v < 0) v = 0; } /* if(two) */ /* prec <= 8: */ - v = *red++; - if(v > 255) v = 255; else if(v < 0) v = 0; + v = *red++; + if(v > 255) v = 255; else if(v < 0) v = 0; - fprintf(fdest, "%c", (unsigned char)v); + fprintf(fdest, "%c", (unsigned char)v); if(triple) - { - v = *green++; - if(v > 255) v = 255; else if(v < 0) v = 0; + { + v = *green++; + if(v > 255) v = 255; else if(v < 0) v = 0; - fprintf(fdest, "%c", (unsigned char)v); - v = *blue++; - if(v > 255) v = 255; else if(v < 0) v = 0; + fprintf(fdest, "%c", (unsigned char)v); + v = *blue++; + if(v > 255) v = 255; else if(v < 0) v = 0; - fprintf(fdest, "%c", (unsigned char)v); - } + fprintf(fdest, "%c", (unsigned char)v); + } if(has_alpha) - { - v = *alpha++; - if(v > 255) v = 255; else if(v < 0) v = 0; + { + v = *alpha++; + if(v > 255) v = 255; else if(v < 0) v = 0; - fprintf(fdest, "%c", (unsigned char)v); - } + fprintf(fdest, "%c", (unsigned char)v); + } } /* for(i */ fclose(fdest); return 0; @@ -1911,22 +1911,21 @@ if(v > 65535) v = 65535; else if(v < 0) v = 0; fprintf(stderr," is written to the file\n"); } destname = (char*)malloc(strlen(outfile) + 8); - if(destname == NULL){ - fprintf(stderr, "imagetopnm: memory out\n"); - fclose(fdest); - return 1; - } + if(destname == NULL){ + fprintf(stderr, "imagetopnm: memory out\n"); + return 1; + } for (compno = 0; compno < ncomp; compno++) { - if (ncomp > 1) - { - /*sprintf(destname, "%d.%s", compno, outfile);*/ - const size_t olen = strlen(outfile); - const size_t dotpos = olen - 4; + if (ncomp > 1) + { + /*sprintf(destname, "%d.%s", compno, outfile);*/ + const size_t olen = strlen(outfile); + const size_t dotpos = olen - 4; - strncpy(destname, outfile, dotpos); - sprintf(destname+dotpos, "_%u.pgm", compno); - } + strncpy(destname, outfile, dotpos); + sprintf(destname+dotpos, "_%u.pgm", compno); + } else sprintf(destname, "%s", outfile); @@ -1953,7 +1952,7 @@ if(v > 65535) v = 65535; else if(v < 0) v = 0; for (i = 0; i < wr * hr; i++) { v = *red + adjustR; ++red; -if(v > 65535) v = 65535; else if(v < 0) v = 0; + if(v > 65535) v = 65535; else if(v < 0) v = 0; /* netpbm: */ fprintf(fdest, "%c%c",(unsigned char)(v>>8), (unsigned char)v); @@ -1961,7 +1960,7 @@ if(v > 65535) v = 65535; else if(v < 0) v = 0; if(has_alpha) { v = *alpha++; -if(v > 65535) v = 65535; else if(v < 0) v = 0; + if(v > 65535) v = 65535; else if(v < 0) v = 0; /* netpbm: */ fprintf(fdest, "%c%c",(unsigned char)(v>>8), (unsigned char)v); @@ -1972,10 +1971,10 @@ if(v > 65535) v = 65535; else if(v < 0) v = 0; { for(i = 0; i < wr * hr; ++i) { - v = *red + adjustR; ++red; - if(v > 255) v = 255; else if(v < 0) v = 0; + v = *red + adjustR; ++red; + if(v > 255) v = 255; else if(v < 0) v = 0; - fprintf(fdest, "%c", (unsigned char)v); + fprintf(fdest, "%c", (unsigned char)v); } } fclose(fdest); From cd77b6003b774dd337835630ea7b9b1fbc68d264 Mon Sep 17 00:00:00 2001 From: mayeut Date: Sat, 30 Apr 2016 12:15:22 +0200 Subject: [PATCH 26/39] Fix some coverity warnings --- src/lib/openjp2/j2k.c | 11 +++++++---- src/lib/openjp2/tcd.c | 7 ------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c index 323a3b80..8086b004 100644 --- a/src/lib/openjp2/j2k.c +++ b/src/lib/openjp2/j2k.c @@ -9343,16 +9343,19 @@ void j2k_dump (opj_j2k_t* p_j2k, OPJ_INT32 flag, FILE* out_stream) /* Dump the codestream info from main header */ if (flag & OPJ_J2K_MH_INFO){ - opj_j2k_dump_MH_info(p_j2k, out_stream); + if (p_j2k->m_private_image) + opj_j2k_dump_MH_info(p_j2k, out_stream); } /* Dump all tile/codestream info */ if (flag & OPJ_J2K_TCH_INFO){ OPJ_UINT32 l_nb_tiles = p_j2k->m_cp.th * p_j2k->m_cp.tw; OPJ_UINT32 i; opj_tcp_t * l_tcp = p_j2k->m_cp.tcps; - for (i=0;im_private_image->numcomps, out_stream); - ++l_tcp; + if (p_j2k->m_private_image) { + for (i=0;im_private_image->numcomps, out_stream); + ++l_tcp; + } } } diff --git a/src/lib/openjp2/tcd.c b/src/lib/openjp2/tcd.c index 45d55e59..7ecd97cf 100644 --- a/src/lib/openjp2/tcd.c +++ b/src/lib/openjp2/tcd.c @@ -486,7 +486,6 @@ OPJ_BOOL opj_tcd_rateallocate( opj_tcd_t *tcd, for (layno = 0; layno < tcd_tcp->numlayers; layno++) { OPJ_FLOAT64 lo = min; OPJ_FLOAT64 hi = max; - OPJ_BOOL success = OPJ_FALSE; OPJ_UINT32 maxlen = tcd_tcp->rates[layno] > 0.0f ? opj_uint_min(((OPJ_UINT32) ceil(tcd_tcp->rates[layno])), len) : len; OPJ_FLOAT64 goodthresh = 0; OPJ_FLOAT64 stable_thresh = 0; @@ -559,19 +558,13 @@ OPJ_BOOL opj_tcd_rateallocate( opj_tcd_t *tcd, } } - success = OPJ_TRUE; goodthresh = stable_thresh == 0? thresh : stable_thresh; opj_t2_destroy(t2); } else { - success = OPJ_TRUE; goodthresh = min; } - if (!success) { - return OPJ_FALSE; - } - if(cstr_info) { /* Threshold for Marcela Index */ cstr_info->tile[tcd->tcd_tileno].thresh[layno] = goodthresh; } From 9a20f8e8d1a91bd032e81ac53bf9a48dbb92bc29 Mon Sep 17 00:00:00 2001 From: Matthieu Darbois Date: Sat, 30 Apr 2016 17:58:04 +0200 Subject: [PATCH 27/39] Update lcms (#544) Update to mm2/Little-CMS@0e8234e090d6aab33f90e2eb0296f30aa0705e57 --- tests/compare_images.c | 2 + tests/nonregression/md5refs.txt | 18 +- thirdparty/liblcms2/COPYING | 2 +- thirdparty/liblcms2/include/lcms2.h | 114 +++-- thirdparty/liblcms2/include/lcms2_plugin.h | 40 +- thirdparty/liblcms2/src/cmsalpha.c | 481 +++++++++++++++++++++ thirdparty/liblcms2/src/cmscam02.c | 2 +- thirdparty/liblcms2/src/cmscgats.c | 28 +- thirdparty/liblcms2/src/cmscnvrt.c | 27 +- thirdparty/liblcms2/src/cmserr.c | 9 +- thirdparty/liblcms2/src/cmsgmt.c | 2 +- thirdparty/liblcms2/src/cmshalf.c | 2 +- thirdparty/liblcms2/src/cmsintrp.c | 6 +- thirdparty/liblcms2/src/cmsio0.c | 66 ++- thirdparty/liblcms2/src/cmsio1.c | 20 +- thirdparty/liblcms2/src/cmslut.c | 25 +- thirdparty/liblcms2/src/cmsmd5.c | 2 +- thirdparty/liblcms2/src/cmsmtrx.c | 2 +- thirdparty/liblcms2/src/cmsnamed.c | 78 ++-- thirdparty/liblcms2/src/cmsopt.c | 259 ++++++++--- thirdparty/liblcms2/src/cmspack.c | 337 +++++++-------- thirdparty/liblcms2/src/cmspcs.c | 11 +- thirdparty/liblcms2/src/cmsplugin.c | 42 +- thirdparty/liblcms2/src/cmsps2.c | 15 +- thirdparty/liblcms2/src/cmssamp.c | 29 +- thirdparty/liblcms2/src/cmssm.c | 7 +- thirdparty/liblcms2/src/cmstypes.c | 62 +-- thirdparty/liblcms2/src/cmsvirt.c | 41 +- thirdparty/liblcms2/src/cmswtpnt.c | 2 +- thirdparty/liblcms2/src/cmsxform.c | 478 ++++++++++++++------ thirdparty/liblcms2/src/lcms2.def | 341 --------------- thirdparty/liblcms2/src/lcms2_internal.h | 55 ++- 32 files changed, 1630 insertions(+), 975 deletions(-) create mode 100644 thirdparty/liblcms2/src/cmsalpha.c delete mode 100644 thirdparty/liblcms2/src/lcms2.def diff --git a/tests/compare_images.c b/tests/compare_images.c index b28d4957..b2ef00db 100644 --- a/tests/compare_images.c +++ b/tests/compare_images.c @@ -877,6 +877,8 @@ int main(int argc, char **argv) printf(" %d \n", it_comp, nbPixelDiff); printf(" %f \n", it_comp, sumDiff); + printf(" %f \n", it_comp, PEAK); + printf(" %f \n", it_comp, MSE); #ifdef OPJ_HAVE_LIBPNG { diff --git a/tests/nonregression/md5refs.txt b/tests/nonregression/md5refs.txt index ecd4f545..13b03c89 100644 --- a/tests/nonregression/md5refs.txt +++ b/tests/nonregression/md5refs.txt @@ -27,9 +27,9 @@ dbabd772b1e53959e1e1c4bdf58e0108 issue135.j2k_1.pgx aa7461b31e14641586803b23b7fb04f2 issue142.j2k_0.pgx a809006e7a0c1eed68bc86c96af43fe3 issue142.j2k_1.pgx 74f7a7a194a74a947245b843c62c4054 issue142.j2k_2.pgx -c44662b1f7fe01caa2ebf3ad62948e3e issue171.jp2_0.pgx -f70e8a4e5dbefeb44d50edd79b6c4cf6 issue171.jp2_1.pgx -18bc167a1c851db2fd9f8c7af3289134 issue171.jp2_2.pgx +f9d1ada7f0f16c8c4f929217a1924416 issue171.jp2_0.pgx +0d4a8507e226130bc44ef7de7e5539f6 issue171.jp2_1.pgx +fde95f3c3bd8639b2258332eb6f658e4 issue171.jp2_2.pgx adda4f5e46845b96dd3df14a76aa7229 issue188_beach_64bitsbox.jp2_0.pgx 90a9709c166019d1e101e7b96d257ed9 issue188_beach_64bitsbox.jp2_1.pgx 37e23d2df06ee60bf0f9f5e1c16054d8 issue188_beach_64bitsbox.jp2_2.pgx @@ -291,10 +291,10 @@ ddfff2ce2df4a9102518c92a362e6d25 dwt_interleave_h.gsr105.jp2_2.pgx b01ed87dbac424bc820b2ac590e4884e issue236-ESYCC-CDEF.jp2_0.pgx 2635cc00b1e18ef11adcba09e845d459 issue236-ESYCC-CDEF.jp2_1.pgx f9c95d0aec2f6e7b814fa1d09edcdbda issue236-ESYCC-CDEF.jp2_2.pgx -5f0c1d5c5127c1eabb86a5e0112f139b issue559-eci-090-CIELab.jp2_0.pgx -cdae87485eaada56be3671eec39452e6 issue559-eci-090-CIELab.jp2_1.pgx -e163102afcc857cf001337178241f518 issue559-eci-090-CIELab.jp2_2.pgx -b004b2e08b0dfb217c131b353cf157eb issue559-eci-091-CIELab.jp2_0.pgx -2400da6b8ed6b1747b9913af544580f9 issue559-eci-091-CIELab.jp2_1.pgx -cf73dda887967928dbcf5cc87ab204cc issue559-eci-091-CIELab.jp2_2.pgx +4c3a5c669aaaa330134c7014b26ed06f issue559-eci-090-CIELab.jp2_0.pgx +d6698c71d1ed3861edaadc430af928eb issue559-eci-090-CIELab.jp2_1.pgx +04f3ec1fea6049769c43b1ac3b05794e issue559-eci-090-CIELab.jp2_2.pgx +a190e10941e6145e69816c909f832c1a issue559-eci-091-CIELab.jp2_0.pgx +3fccf3c7ecd3b9de46b94b53a1fa0362 issue559-eci-091-CIELab.jp2_1.pgx +f3081c8e9e9a175f223382a7443b480f issue559-eci-091-CIELab.jp2_2.pgx 3bf91c974abc17e520c6a5efa883a58a issue653-zero-unknownbox.jp2.png diff --git a/thirdparty/liblcms2/COPYING b/thirdparty/liblcms2/COPYING index b147b1b9..fda5c9eb 100644 --- a/thirdparty/liblcms2/COPYING +++ b/thirdparty/liblcms2/COPYING @@ -1,5 +1,5 @@ Little CMS -Copyright (c) 1998-2010 Marti Maria Saguer +Copyright (c) 1998-2011 Marti Maria Saguer Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/thirdparty/liblcms2/include/lcms2.h b/thirdparty/liblcms2/include/lcms2.h index a0eeea73..6d3f4580 100644 --- a/thirdparty/liblcms2/include/lcms2.h +++ b/thirdparty/liblcms2/include/lcms2.h @@ -1,7 +1,7 @@ //--------------------------------------------------------------------------------- // // Little Color Management System -// Copyright (c) 1998-2014 Marti Maria Saguer +// Copyright (c) 1998-2016 Marti Maria Saguer // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), @@ -23,7 +23,7 @@ // //--------------------------------------------------------------------------------- // -// Version 2.6 +// Version 2.8beta0 // #ifndef _lcms2_H @@ -75,7 +75,7 @@ extern "C" { #endif // Version/release -#define LCMS_VERSION 2060 +#define LCMS_VERSION 2080 // I will give the chance of redefining basic types for compilers that are not fully C99 compliant #ifndef CMS_BASIC_TYPES_ALREADY_DEFINED @@ -173,46 +173,45 @@ typedef int cmsBool; # define CMS_IS_WINDOWS_ 1 #endif -// Try to detect big endian platforms. This list can be endless, so only some checks are performed over here. -// you can pass this toggle to the compiler by using -DCMS_USE_BIG_ENDIAN or something similar +// Try to detect big endian platforms. This list can be endless, so primarily rely on the configure script +// on Unix-like systems, and allow it to be set on the compiler command line using +// -DCMS_USE_BIG_ENDIAN or something similar +#ifdef CMS_USE_BIG_ENDIAN // set at compiler command line takes overall precedence -#if defined(__sgi__) || defined(__sgi) || defined(sparc) -# define CMS_USE_BIG_ENDIAN 1 -#endif - -#if defined(__s390__) || defined(__s390x__) -# define CMS_USE_BIG_ENDIAN 1 -#endif - -# ifdef TARGET_CPU_PPC -# if TARGET_CPU_PPC -# define CMS_USE_BIG_ENDIAN 1 -# endif +# if CMS_USE_BIG_ENDIAN == 0 +# undef CMS_USE_BIG_ENDIAN # endif -#if defined(__powerpc__) || defined(__ppc__) || defined(TARGET_CPU_PPC) -# define CMS_USE_BIG_ENDIAN 1 -# if defined (__GNUC__) && defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) -# if __BYTE_ORDER == __LITTLE_ENDIAN -// // Don't use big endian for PowerPC little endian mode -# undef CMS_USE_BIG_ENDIAN -# endif -# endif -#endif +#else // CMS_USE_BIG_ENDIAN -// WORDS_BIGENDIAN takes precedence -#if defined(_HOST_BIG_ENDIAN) || defined(__BIG_ENDIAN__) || defined(WORDS_BIGENDIAN) -# define CMS_USE_BIG_ENDIAN 1 -#endif +# ifdef WORDS_BIGENDIAN // set by configure (or explicitly on compiler command line) +# define CMS_USE_BIG_ENDIAN 1 +# else // WORDS_BIGENDIAN +// Fall back to platform/compiler specific tests +# if defined(__sgi__) || defined(__sgi) || defined(sparc) +# define CMS_USE_BIG_ENDIAN 1 +# endif + +# if defined(__s390__) || defined(__s390x__) +# define CMS_USE_BIG_ENDIAN 1 +# endif + +# ifdef macintosh +# ifdef __BIG_ENDIAN__ +# define CMS_USE_BIG_ENDIAN 1 +# endif +# ifdef __LITTLE_ENDIAN__ +# undef CMS_USE_BIG_ENDIAN +# endif +# endif +# endif // WORDS_BIGENDIAN + +# if defined(_HOST_BIG_ENDIAN) || defined(__BIG_ENDIAN__) +# define CMS_USE_BIG_ENDIAN 1 +# endif + +#endif // CMS_USE_BIG_ENDIAN -#ifdef macintosh -# ifdef __BIG_ENDIAN__ -# define CMS_USE_BIG_ENDIAN 1 -# endif -# ifdef __LITTLE_ENDIAN__ -# undef CMS_USE_BIG_ENDIAN -# endif -#endif // Calling convention -- this is hardly platform and compiler dependent #ifdef CMS_IS_WINDOWS_ @@ -221,7 +220,7 @@ typedef int cmsBool; # define CMSEXPORT __stdcall _export # define CMSAPI # else -# define CMSEXPORT _stdcall +# define CMSEXPORT __stdcall # ifdef CMS_DLL_BUILD # define CMSAPI __declspec(dllexport) # else @@ -383,7 +382,8 @@ typedef enum { cmsSigViewingCondDescTag = 0x76756564, // 'vued' cmsSigViewingConditionsTag = 0x76696577, // 'view' cmsSigVcgtTag = 0x76636774, // 'vcgt' - cmsSigMetaTag = 0x6D657461 // 'meta' + cmsSigMetaTag = 0x6D657461, // 'meta' + cmsSigArgyllArtsTag = 0x61727473 // 'arts' } cmsTagSignature; @@ -516,7 +516,7 @@ typedef enum { cmsSigNamedColorElemType = 0x6E636C20, // 'ncl ' cmsSigLabV2toV4 = 0x32203420, // '2 4 ' cmsSigLabV4toV2 = 0x34203220, // '4 2 ' - + // Identities cmsSigIdentityElemType = 0x69646E20, // 'idn ' @@ -524,7 +524,8 @@ typedef enum { cmsSigLab2FloatPCS = 0x64326C20, // 'd2l ' cmsSigFloatPCS2Lab = 0x6C326420, // 'l2d ' cmsSigXYZ2FloatPCS = 0x64327820, // 'd2x ' - cmsSigFloatPCS2XYZ = 0x78326420 // 'x2d ' + cmsSigFloatPCS2XYZ = 0x78326420, // 'x2d ' + cmsSigClipNegativesElemType = 0x636c7020 // 'clp ' } cmsStageSignature; @@ -898,7 +899,7 @@ typedef void* cmsHTRANSFORM; #define TYPE_ARGB_FLT (FLOAT_SH(1)|COLORSPACE_SH(PT_RGB)|EXTRA_SH(1)|CHANNELS_SH(3)|BYTES_SH(4)|SWAPFIRST_SH(1)) #define TYPE_BGR_FLT (FLOAT_SH(1)|COLORSPACE_SH(PT_RGB)|CHANNELS_SH(3)|BYTES_SH(4)|DOSWAP_SH(1)) #define TYPE_BGRA_FLT (FLOAT_SH(1)|COLORSPACE_SH(PT_RGB)|EXTRA_SH(1)|CHANNELS_SH(3)|BYTES_SH(4)|DOSWAP_SH(1)|SWAPFIRST_SH(1)) -#define TYPE_ABGR_FLT (FLOAT_SH(1)|COLORSPACE_SH(PT_RGB)|CHANNELS_SH(3)|BYTES_SH(4)|DOSWAP_SH(1)) +#define TYPE_ABGR_FLT (FLOAT_SH(1)|COLORSPACE_SH(PT_RGB)|EXTRA_SH(1)|CHANNELS_SH(3)|BYTES_SH(4)|DOSWAP_SH(1)) #define TYPE_CMYK_FLT (FLOAT_SH(1)|COLORSPACE_SH(PT_CMYK)|CHANNELS_SH(4)|BYTES_SH(4)) @@ -1002,6 +1003,10 @@ typedef struct { } cmsICCViewingConditions; +// Get LittleCMS version (for shared objects) ----------------------------------------------------------------------------- + +CMSAPI int CMSEXPORT cmsGetEncodedCMMversion(void); + // Support of non-standard functions -------------------------------------------------------------------------------------- CMSAPI int CMSEXPORT cmsstrcasecmp(const char* s1, const char* s2); @@ -1380,7 +1385,7 @@ typedef struct { typedef struct { cmsUInt32Number n; - cmsContext ContextID; + cmsContext ContextID; cmsPSEQDESC* seq; } cmsSEQ; @@ -1480,7 +1485,7 @@ CMSAPI int CMSEXPORT _cmsLCMScolorSpace(cmsColorSpaceSignat CMSAPI cmsUInt32Number CMSEXPORT cmsChannelsOf(cmsColorSpaceSignature ColorSpace); -// Build a suitable formatter for the colorspace of this profile +// Build a suitable formatter for the colorspace of this profile. nBytes=1 means 8 bits, nBytes=2 means 16 bits. CMSAPI cmsUInt32Number CMSEXPORT cmsFormatterForColorspaceOfProfile(cmsHPROFILE hProfile, cmsUInt32Number nBytes, cmsBool lIsFloat); CMSAPI cmsUInt32Number CMSEXPORT cmsFormatterForPCSOfProfile(cmsHPROFILE hProfile, cmsUInt32Number nBytes, cmsBool lIsFloat); @@ -1509,6 +1514,7 @@ CMSAPI cmsIOHANDLER* CMSEXPORT cmsOpenIOhandlerFromFile(cmsContext ContextID CMSAPI cmsIOHANDLER* CMSEXPORT cmsOpenIOhandlerFromStream(cmsContext ContextID, FILE* Stream); CMSAPI cmsIOHANDLER* CMSEXPORT cmsOpenIOhandlerFromMem(cmsContext ContextID, void *Buffer, cmsUInt32Number size, const char* AccessMode); CMSAPI cmsIOHANDLER* CMSEXPORT cmsOpenIOhandlerFromNULL(cmsContext ContextID); +CMSAPI cmsIOHANDLER* CMSEXPORT cmsGetProfileIOhandler(cmsHPROFILE hProfile); CMSAPI cmsBool CMSEXPORT cmsCloseIOhandler(cmsIOHANDLER* io); // MD5 message digest -------------------------------------------------------------------------------------------------- @@ -1643,6 +1649,12 @@ CMSAPI cmsUInt32Number CMSEXPORT cmsGetSupportedIntentsTHR(cmsContext ContextID #define cmsFLAGS_CLUT_POST_LINEARIZATION 0x0001 // create postlinearization tables if possible #define cmsFLAGS_CLUT_PRE_LINEARIZATION 0x0010 // create prelinearization tables if possible +// Specific to unbounded mode +#define cmsFLAGS_NONEGATIVES 0x8000 // Prevent negative numbers in floating point transforms + +// Copy alpha channels when transforming +#define cmsFLAGS_COPY_ALPHA 0x04000000 // Alpha channels are copied on cmsDoTransform() + // Fine-tune control over number of gridpoints #define cmsFLAGS_GRIDPOINTS(n) (((n) & 0xFF) << 16) @@ -1720,12 +1732,22 @@ CMSAPI void CMSEXPORT cmsDoTransform(cmsHTRANSFORM Transform, void * OutputBuffer, cmsUInt32Number Size); -CMSAPI void CMSEXPORT cmsDoTransformStride(cmsHTRANSFORM Transform, +CMSAPI void CMSEXPORT cmsDoTransformStride(cmsHTRANSFORM Transform, // Deprecated const void * InputBuffer, void * OutputBuffer, cmsUInt32Number Size, cmsUInt32Number Stride); +CMSAPI void CMSEXPORT cmsDoTransformLineStride(cmsHTRANSFORM Transform, + const void* InputBuffer, + void* OutputBuffer, + cmsUInt32Number PixelsPerLine, + cmsUInt32Number LineCount, + cmsUInt32Number BytesPerLineIn, + cmsUInt32Number BytesPerLineOut, + cmsUInt32Number BytesPerPlaneIn, + cmsUInt32Number BytesPerPlaneOut); + CMSAPI void CMSEXPORT cmsSetAlarmCodes(const cmsUInt16Number NewAlarm[cmsMAXCHANNELS]); CMSAPI void CMSEXPORT cmsGetAlarmCodes(cmsUInt16Number NewAlarm[cmsMAXCHANNELS]); diff --git a/thirdparty/liblcms2/include/lcms2_plugin.h b/thirdparty/liblcms2/include/lcms2_plugin.h index 0c95d1f7..bca8fa33 100644 --- a/thirdparty/liblcms2/include/lcms2_plugin.h +++ b/thirdparty/liblcms2/include/lcms2_plugin.h @@ -1,7 +1,7 @@ //--------------------------------------------------------------------------------- // // Little Color Management System -// Copyright (c) 1998-2011 Marti Maria Saguer +// Copyright (c) 1998-2016 Marti Maria Saguer // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), @@ -342,8 +342,8 @@ struct _cmstransform_struct; typedef cmsUInt8Number* (* cmsFormatter16)(register struct _cmstransform_struct* CMMcargo, register cmsUInt16Number Values[], - register cmsUInt8Number* Buffer, - register cmsUInt32Number Stride); + register cmsUInt8Number* Buffer, + register cmsUInt32Number Stride); typedef cmsUInt8Number* (* cmsFormatterFloat)(struct _cmstransform_struct* CMMcargo, cmsFloat32Number Values[], @@ -571,11 +571,28 @@ typedef struct { //---------------------------------------------------------------------------------------------------------- // Full xform -typedef void (* _cmsTransformFn)(struct _cmstransform_struct *CMMcargo, + +typedef struct { + cmsUInt32Number BytesPerLineIn; + cmsUInt32Number BytesPerLineOut; + cmsUInt32Number BytesPerPlaneIn; + cmsUInt32Number BytesPerPlaneOut; + +} cmsStride; + +typedef void (* _cmsTransformFn)(struct _cmstransform_struct *CMMcargo, // Legacy function, handles just ONE scanline. const void* InputBuffer, void* OutputBuffer, cmsUInt32Number Size, - cmsUInt32Number Stride); + cmsUInt32Number Stride); // Stride in bytes to the next plana in planar formats + + +typedef void (*_cmsTransform2Fn)(struct _cmstransform_struct *CMMcargo, + const void* InputBuffer, + void* OutputBuffer, + cmsUInt32Number PixelsPerLine, + cmsUInt32Number LineCount, + const cmsStride* Stride); typedef cmsBool (* _cmsTransformFactory)(_cmsTransformFn* xform, void** UserData, @@ -585,6 +602,14 @@ typedef cmsBool (* _cmsTransformFactory)(_cmsTransformFn* xform, cmsUInt32Number* OutputFormat, cmsUInt32Number* dwFlags); +typedef cmsBool (* _cmsTransform2Factory)(_cmsTransform2Fn* xform, + void** UserData, + _cmsFreeUserDataFn* FreePrivateDataFn, + cmsPipeline** Lut, + cmsUInt32Number* InputFormat, + cmsUInt32Number* OutputFormat, + cmsUInt32Number* dwFlags); + // Retrieve user data as specified by the factory CMSAPI void CMSEXPORT _cmsSetTransformUserData(struct _cmstransform_struct *CMMcargo, void* ptr, _cmsFreeUserDataFn FreePrivateDataFn); @@ -599,7 +624,10 @@ typedef struct { cmsPluginBase base; // Transform entry point - _cmsTransformFactory Factory; + union { + _cmsTransformFactory legacy_xform; + _cmsTransform2Factory xform; + } factories; } cmsPluginTransform; diff --git a/thirdparty/liblcms2/src/cmsalpha.c b/thirdparty/liblcms2/src/cmsalpha.c new file mode 100644 index 00000000..904ce715 --- /dev/null +++ b/thirdparty/liblcms2/src/cmsalpha.c @@ -0,0 +1,481 @@ +//--------------------------------------------------------------------------------- +// +// Little Color Management System +// Copyright (c) 1998-2016 Marti Maria Saguer +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the Software +// is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO +// THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// +//--------------------------------------------------------------------------------- +// + +#include "lcms2_internal.h" + + +// Alpha copy ------------------------------------------------------------------------------------------------------------------ + +// Floor to byte, taking care of saturation +cmsINLINE cmsUInt8Number _cmsQuickSaturateByte(cmsFloat64Number d) +{ + d += 0.5; + if (d <= 0) return 0; + if (d >= 255.0) return 255; + + return (cmsUInt8Number) _cmsQuickFloorWord(d); +} + + +// Return the size in bytes of a given formatter +static +int trueBytesSize(cmsUInt32Number Format) +{ + int fmt_bytes = T_BYTES(Format); + + // For double, the T_BYTES field returns zero + if (fmt_bytes == 0) + return sizeof(double); + + // Otherwise, it is already correct for all formats + return fmt_bytes; +} + + +// Several format converters + +typedef void(*cmsFormatterAlphaFn)(void* dst, const void* src); + + +// From 8 + +static +void copy8(void* dst, const void* src) +{ + memmove(dst, src, 1); +} + +static +void from8to16(void* dst, const void* src) +{ + cmsUInt8Number n = *(cmsUInt8Number*)src; + *(cmsUInt16Number*) dst = FROM_8_TO_16(n); +} + +static +void from8toFLT(void* dst, const void* src) +{ + *(cmsFloat32Number*)dst = (*(cmsUInt8Number*)src) / 255.0f; +} + +static +void from8toDBL(void* dst, const void* src) +{ + *(cmsFloat64Number*)dst = (*(cmsUInt8Number*)src) / 255.0; +} + +static +void from8toHLF(void* dst, const void* src) +{ + cmsFloat32Number n = (*(cmsUInt8Number*)src) / 255.0f; + *(cmsUInt16Number*)dst = _cmsFloat2Half(n); +} + +// From 16 + +static +void from16to8(void* dst, const void* src) +{ + cmsUInt16Number n = *(cmsUInt16Number*)src; + *(cmsUInt8Number*) dst = FROM_16_TO_8(n); +} + +static +void copy16(void* dst, const void* src) +{ + memmove(dst, src, 2); +} + +void from16toFLT(void* dst, const void* src) +{ + *(cmsFloat32Number*)dst = (*(cmsUInt16Number*)src) / 65535.0f; +} + +void from16toDBL(void* dst, const void* src) +{ + *(cmsFloat64Number*)dst = (*(cmsUInt16Number*)src) / 65535.0f; +} + +static +void from16toHLF(void* dst, const void* src) +{ + cmsFloat32Number n = (*(cmsUInt16Number*)src) / 65535.0f; + *(cmsUInt16Number*)dst = _cmsFloat2Half(n); +} + +// From Float + +static +void fromFLTto8(void* dst, const void* src) +{ + cmsFloat32Number n = *(cmsFloat32Number*)src; + *(cmsUInt8Number*)dst = _cmsQuickSaturateByte(n * 255.0f); +} + +static +void fromFLTto16(void* dst, const void* src) +{ + cmsFloat32Number n = *(cmsFloat32Number*)src; + *(cmsUInt16Number*)dst = _cmsQuickSaturateWord(n * 65535.0f); +} + +static +void copy32(void* dst, const void* src) +{ + memmove(dst, src, sizeof(cmsFloat32Number)); +} + +static +void fromFLTtoDBL(void* dst, const void* src) +{ + cmsFloat32Number n = *(cmsFloat32Number*)src; + *(cmsFloat64Number*)dst = (cmsFloat64Number)n; +} + +static +void fromFLTtoHLF(void* dst, const void* src) +{ + cmsFloat32Number n = *(cmsFloat32Number*)src; + *(cmsUInt16Number*)dst = _cmsFloat2Half(n); +} + + +// From HALF + +static +void fromHLFto8(void* dst, const void* src) +{ + cmsFloat32Number n = _cmsHalf2Float(*(cmsUInt16Number*)src); + *(cmsUInt8Number*)dst = _cmsQuickSaturateByte(n * 255.0f); +} + +static +void fromHLFto16(void* dst, const void* src) +{ + cmsFloat32Number n = _cmsHalf2Float(*(cmsUInt16Number*)src); + *(cmsUInt16Number*)dst = _cmsQuickSaturateWord(n * 65535.0f); +} + +static +void fromHLFtoFLT(void* dst, const void* src) +{ + *(cmsFloat32Number*)dst = _cmsHalf2Float(*(cmsUInt16Number*)src); +} + +static +void fromHLFtoDBL(void* dst, const void* src) +{ + *(cmsFloat64Number*)dst = (cmsFloat64Number)_cmsHalf2Float(*(cmsUInt16Number*)src); +} + +// From double +static +void fromDBLto8(void* dst, const void* src) +{ + cmsFloat64Number n = *(cmsFloat64Number*)src; + *(cmsUInt8Number*)dst = _cmsQuickSaturateByte(n * 255.0); +} + +static +void fromDBLto16(void* dst, const void* src) +{ + cmsFloat64Number n = *(cmsFloat64Number*)src; + *(cmsUInt16Number*)dst = _cmsQuickSaturateWord(n * 65535.0f); +} + +static +void fromDBLtoFLT(void* dst, const void* src) +{ + cmsFloat64Number n = *(cmsFloat64Number*)src; + *(cmsFloat32Number*)dst = (cmsFloat32Number) n; +} + +static +void fromDBLtoHLF(void* dst, const void* src) +{ + cmsFloat32Number n = (cmsFloat32Number) *(cmsFloat64Number*)src; + *(cmsUInt16Number*)dst = _cmsFloat2Half(n); +} + +static +void copy64(void* dst, const void* src) +{ + memmove(dst, src, sizeof(cmsFloat64Number)); +} + + +// Returns the position (x or y) of the formatter in the table of functions +static +int FormatterPos(cmsUInt32Number frm) +{ + int b = T_BYTES(frm); + + if (b == 0 && T_FLOAT(frm)) + return 4; // DBL + if (b == 2 && T_FLOAT(frm)) + return 2; // HLF + if (b == 4 && T_FLOAT(frm)) + return 3; // FLT + if (b == 2 && !T_FLOAT(frm)) + return 1; // 16 + if (b == 1 && !T_FLOAT(frm)) + return 0; // 8 + + return -1; // not recognized + +} + +// Obtains a alpha-to-alpha funmction formatter +static +cmsFormatterAlphaFn _cmsGetFormatterAlpha(cmsContext id, cmsUInt32Number in, cmsUInt32Number out) +{ +static cmsFormatterAlphaFn FormattersAlpha[5][5] = { + + /* from 8 */ { copy8, from8to16, from8toHLF, from8toFLT, from8toDBL }, + /* from 16*/ { from16to8, copy16, from16toHLF, from16toFLT, from16toDBL }, + /* from HLF*/ { fromHLFto8, fromHLFto16, copy16, fromHLFtoFLT, fromHLFtoDBL }, + /* from FLT*/ { fromFLTto8, fromFLTto16, fromFLTtoHLF, copy32, fromFLTtoDBL }, + /* from DBL*/ { fromDBLto8, fromDBLto16, fromDBLtoHLF, fromDBLtoFLT, copy64 }}; + + int in_n = FormatterPos(in); + int out_n = FormatterPos(out); + + if (in_n < 0 || out_n < 0 || in_n > 4 || out_n > 4) { + + cmsSignalError(id, cmsERROR_UNKNOWN_EXTENSION, "Unrecognized alpha channel width"); + return NULL; + } + + return FormattersAlpha[in_n][out_n]; +} + + + +// This function computes the distance from each component to the next one in bytes. +static +void ComputeIncrementsForChunky(cmsUInt32Number Format, + cmsUInt32Number ComponentStartingOrder[], + cmsUInt32Number ComponentPointerIncrements[]) +{ + cmsUInt32Number channels[cmsMAXCHANNELS]; + int extra = T_EXTRA(Format); + int nchannels = T_CHANNELS(Format); + int total_chans = nchannels + extra; + int i; + int channelSize = trueBytesSize(Format); + int pixelSize = channelSize * total_chans; + + // Sanity check + if (total_chans <= 0 || total_chans >= cmsMAXCHANNELS) + return; + + memset(channels, 0, sizeof(channels)); + + // Separation is independent of starting point and only depends on channel size + for (i = 0; i < extra; i++) + ComponentPointerIncrements[i] = pixelSize; + + // Handle do swap + for (i = 0; i < total_chans; i++) + { + if (T_DOSWAP(Format)) { + channels[i] = total_chans - i - 1; + } + else { + channels[i] = i; + } + } + + // Handle swap first (ROL of positions), example CMYK -> KCMY | 0123 -> 3012 + if (T_SWAPFIRST(Format) && total_chans > 1) { + + cmsUInt32Number tmp = channels[0]; + for (i = 0; i < total_chans-1; i++) + channels[i] = channels[i + 1]; + + channels[total_chans - 1] = tmp; + } + + // Handle size + if (channelSize > 1) + for (i = 0; i < total_chans; i++) { + channels[i] *= channelSize; + } + + for (i = 0; i < extra; i++) + ComponentStartingOrder[i] = channels[i + nchannels]; +} + + + +// On planar configurations, the distance is the stride added to any non-negative +static +void ComputeIncrementsForPlanar(cmsUInt32Number Format, + cmsUInt32Number BytesPerPlane, + cmsUInt32Number ComponentStartingOrder[], + cmsUInt32Number ComponentPointerIncrements[]) +{ + cmsUInt32Number channels[cmsMAXCHANNELS]; + int extra = T_EXTRA(Format); + int nchannels = T_CHANNELS(Format); + int total_chans = nchannels + extra; + int i; + int channelSize = trueBytesSize(Format); + + // Sanity check + if (total_chans <= 0 || total_chans >= cmsMAXCHANNELS) + return; + + memset(channels, 0, sizeof(channels)); + + // Separation is independent of starting point and only depends on channel size + for (i = 0; i < extra; i++) + ComponentPointerIncrements[i] = channelSize; + + // Handle do swap + for (i = 0; i < total_chans; i++) + { + if (T_DOSWAP(Format)) { + channels[i] = total_chans - i - 1; + } + else { + channels[i] = i; + } + } + + // Handle swap first (ROL of positions), example CMYK -> KCMY | 0123 -> 3012 + if (T_SWAPFIRST(Format) && total_chans > 0) { + + cmsUInt32Number tmp = channels[0]; + for (i = 0; i < total_chans - 1; i++) + channels[i] = channels[i + 1]; + + channels[total_chans - 1] = tmp; + } + + // Handle size + for (i = 0; i < total_chans; i++) { + channels[i] *= BytesPerPlane; + } + + for (i = 0; i < extra; i++) + ComponentStartingOrder[i] = channels[i + nchannels]; +} + + + +// Dispatcher por chunky and planar RGB +static +void ComputeComponentIncrements(cmsUInt32Number Format, + cmsUInt32Number BytesPerPlane, + cmsUInt32Number ComponentStartingOrder[], + cmsUInt32Number ComponentPointerIncrements[]) +{ + if (T_PLANAR(Format)) { + + ComputeIncrementsForPlanar(Format, BytesPerPlane, ComponentStartingOrder, ComponentPointerIncrements); + } + else { + ComputeIncrementsForChunky(Format, ComponentStartingOrder, ComponentPointerIncrements); + } + +} + + + +// Handles extra channels copying alpha if requested by the flags +void _cmsHandleExtraChannels(_cmsTRANSFORM* p, const void* in, + void* out, + cmsUInt32Number PixelsPerLine, + cmsUInt32Number LineCount, + const cmsStride* Stride) +{ + size_t i, j, k; + cmsUInt32Number nExtra; + cmsUInt32Number SourceStartingOrder[cmsMAXCHANNELS]; + cmsUInt32Number SourceIncrements[cmsMAXCHANNELS]; + cmsUInt32Number DestStartingOrder[cmsMAXCHANNELS]; + cmsUInt32Number DestIncrements[cmsMAXCHANNELS]; + cmsUInt32Number SourceStrideIncrements[cmsMAXCHANNELS]; + cmsUInt32Number DestStrideIncrements[cmsMAXCHANNELS]; + + cmsUInt8Number* SourcePtr[cmsMAXCHANNELS]; + cmsUInt8Number* DestPtr[cmsMAXCHANNELS]; + + cmsFormatterAlphaFn copyValueFn; + + // Make sure we need some copy + if (!(p->dwOriginalFlags & cmsFLAGS_COPY_ALPHA)) + return; + + // Make sure we have same number of alpha channels. If not, just return as this should be checked at transform creation time. + nExtra = T_EXTRA(p->InputFormat); + if (nExtra != T_EXTRA(p->OutputFormat)) + return; + + // Anything to do? + if (nExtra == 0) + return; + + // Compute the increments + ComputeComponentIncrements(p->InputFormat, Stride->BytesPerPlaneIn, SourceStartingOrder, SourceIncrements); + ComputeComponentIncrements(p->OutputFormat, Stride->BytesPerPlaneOut, DestStartingOrder, DestIncrements); + + // Check for conversions 8, 16, half, float, dbl + copyValueFn = _cmsGetFormatterAlpha(p->ContextID, p->InputFormat, p->OutputFormat); + + memset(SourceStrideIncrements, 0, sizeof(SourceStrideIncrements)); + memset(DestStrideIncrements, 0, sizeof(DestStrideIncrements)); + + // The loop itself + for (i = 0; i < LineCount; i++) { + + // Prepare pointers for the loop + for (j = 0; j < nExtra; j++) { + + SourcePtr[j] = (cmsUInt8Number*)in + SourceStartingOrder[j] + SourceStrideIncrements[j]; + DestPtr[j] = (cmsUInt8Number*)out + DestStartingOrder[j] + DestStrideIncrements[j]; + } + + for (j = 0; j < PixelsPerLine; j++) { + + for (k = 0; k < nExtra; k++) { + + copyValueFn(DestPtr[k], SourcePtr[k]); + + SourcePtr[k] += SourceIncrements[k]; + DestPtr[k] += DestIncrements[k]; + } + } + + for (j = 0; j < nExtra; j++) { + + SourceStrideIncrements[j] += Stride->BytesPerLineIn; + DestStrideIncrements[j] += Stride->BytesPerLineOut; + } + } +} + diff --git a/thirdparty/liblcms2/src/cmscam02.c b/thirdparty/liblcms2/src/cmscam02.c index 9d874aa2..5f0ac1f8 100644 --- a/thirdparty/liblcms2/src/cmscam02.c +++ b/thirdparty/liblcms2/src/cmscam02.c @@ -1,7 +1,7 @@ //--------------------------------------------------------------------------------- // // Little Color Management System -// Copyright (c) 1998-2012 Marti Maria Saguer +// Copyright (c) 1998-2016 Marti Maria Saguer // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), diff --git a/thirdparty/liblcms2/src/cmscgats.c b/thirdparty/liblcms2/src/cmscgats.c index 099b07bb..591e4caa 100644 --- a/thirdparty/liblcms2/src/cmscgats.c +++ b/thirdparty/liblcms2/src/cmscgats.c @@ -1,7 +1,7 @@ //--------------------------------------------------------------------------------- // // Little Color Management System -// Copyright (c) 1998-2012 Marti Maria Saguer +// Copyright (c) 1998-2016 Marti Maria Saguer // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), @@ -48,7 +48,7 @@ // Symbols typedef enum { - SNONE, + SUNDEFINED, SINUM, // Integer SDNUM, // Real SIDENT, // Identifier @@ -324,7 +324,7 @@ static const char* PredefinedSampleID[] = { "XYZ_X", // X component of tristimulus data "XYZ_Y", // Y component of tristimulus data "XYZ_Z", // Z component of tristimulus data - "XYY_X" // x component of chromaticity data + "XYY_X", // x component of chromaticity data "XYY_Y", // y component of chromaticity data "XYY_CAPY", // Y component of tristimulus data "LAB_L", // L* component of Lab data @@ -521,7 +521,7 @@ SYMBOL BinSrchKey(const char *id) else l = x + 1; } - return SNONE; + return SUNDEFINED; } @@ -706,7 +706,7 @@ void InSymbol(cmsIT8* it8) key = BinSrchKey(it8->id); - if (key == SNONE) it8->sy = SIDENT; + if (key == SUNDEFINED) it8->sy = SIDENT; else it8->sy = key; } @@ -801,11 +801,11 @@ void InSymbol(cmsIT8* it8) if (it8 ->sy == SINUM) { - sprintf(it8->id, "%d", it8->inum); + snprintf(it8->id, 127, "%d", it8->inum); } else { - sprintf(it8->id, it8 ->DoubleFormatter, it8->dnum); + snprintf(it8->id, 127, it8 ->DoubleFormatter, it8->dnum); } k = (int) strlen(it8 ->id); @@ -1297,7 +1297,7 @@ cmsHANDLE CMSEXPORT cmsIT8Alloc(cmsContext ContextID) it8->ValidKeywords = NULL; it8->ValidSampleID = NULL; - it8 -> sy = SNONE; + it8 -> sy = SUNDEFINED; it8 -> ch = ' '; it8 -> Source = NULL; it8 -> inum = 0; @@ -1363,7 +1363,7 @@ cmsBool CMSEXPORT cmsIT8SetPropertyDbl(cmsHANDLE hIT8, const char* cProp, cmsFlo cmsIT8* it8 = (cmsIT8*) hIT8; char Buffer[1024]; - sprintf(Buffer, it8->DoubleFormatter, Val); + snprintf(Buffer, 1023, it8->DoubleFormatter, Val); return AddToList(it8, &GetTable(it8)->HeaderList, cProp, NULL, Buffer, WRITE_UNCOOKED) != NULL; } @@ -1373,7 +1373,7 @@ cmsBool CMSEXPORT cmsIT8SetPropertyHex(cmsHANDLE hIT8, const char* cProp, cmsUIn cmsIT8* it8 = (cmsIT8*) hIT8; char Buffer[1024]; - sprintf(Buffer, "%u", Val); + snprintf(Buffer, 1023, "%u", Val); return AddToList(it8, &GetTable(it8)->HeaderList, cProp, NULL, Buffer, WRITE_HEXADECIMAL) != NULL; } @@ -2516,8 +2516,10 @@ int LocateSample(cmsIT8* it8, const char* cSample) for (i=0; i < t->nSamples; i++) { fld = GetDataFormat(it8, i); - if (cmsstrcasecmp(fld, cSample) == 0) - return i; + if (fld != NULL) { + if (cmsstrcasecmp(fld, cSample) == 0) + return i; + } } return -1; @@ -2575,7 +2577,7 @@ cmsBool CMSEXPORT cmsIT8SetDataRowColDbl(cmsHANDLE hIT8, int row, int col, cmsFl _cmsAssert(hIT8 != NULL); - sprintf(Buff, it8->DoubleFormatter, Val); + snprintf(Buff, 255, it8->DoubleFormatter, Val); return SetData(it8, row, col, Buff); } diff --git a/thirdparty/liblcms2/src/cmscnvrt.c b/thirdparty/liblcms2/src/cmscnvrt.c index 1a93e83f..42e5f78b 100644 --- a/thirdparty/liblcms2/src/cmscnvrt.c +++ b/thirdparty/liblcms2/src/cmscnvrt.c @@ -1,7 +1,7 @@ //--------------------------------------------------------------------------------- // // Little Color Management System -// Copyright (c) 1998-2012 Marti Maria Saguer +// Copyright (c) 1998-2016 Marti Maria Saguer // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), @@ -269,6 +269,9 @@ cmsBool ComputeAbsoluteIntent(cmsFloat64Number AdaptationState, { cmsMAT3 Scale, m1, m2, m3, m4; + // TODO: Follow Marc Mahy's recommendation to check if CHAD is same by using M1*M2 == M2*M1. If so, do nothing. + // TODO: Add support for ArgyllArts tag + // Adaptation state if (AdaptationState == 1.0) { @@ -288,7 +291,7 @@ cmsBool ComputeAbsoluteIntent(cmsFloat64Number AdaptationState, if (AdaptationState == 0.0) { - + m1 = *ChromaticAdaptationMatrixOut; _cmsMAT3per(&m2, &m1, &Scale); // m2 holds CHAD from output white to D50 times abs. col. scaling @@ -530,7 +533,7 @@ cmsPipeline* DefaultICCintents(cmsContext ContextID, cmsHPROFILE hProfile; cmsMAT3 m; cmsVEC3 off; - cmsColorSpaceSignature ColorSpaceIn, ColorSpaceOut, CurrentColorSpace; + cmsColorSpaceSignature ColorSpaceIn, ColorSpaceOut = cmsSigLabData, CurrentColorSpace; cmsProfileClassSignature ClassSig; cmsUInt32Number i, Intent; @@ -632,6 +635,22 @@ cmsPipeline* DefaultICCintents(cmsContext ContextID, CurrentColorSpace = ColorSpaceOut; } + // Check for non-negatives clip + if (dwFlags & cmsFLAGS_NONEGATIVES) { + + if (ColorSpaceOut == cmsSigGrayData || + ColorSpaceOut == cmsSigRgbData || + ColorSpaceOut == cmsSigCmykData) { + + cmsStage* clip = _cmsStageClipNegatives(Result->ContextID, cmsChannelsOf(ColorSpaceOut)); + if (clip == NULL) goto Error; + + if (!cmsPipelineInsertStage(Result, cmsAT_END, clip)) + goto Error; + } + + } + return Result; Error: @@ -1045,7 +1064,7 @@ cmsPipeline* _cmsLinkProfiles(cmsContext ContextID, if (TheIntents[i] == INTENT_PERCEPTUAL || TheIntents[i] == INTENT_SATURATION) { // Force BPC for V4 profiles in perceptual and saturation - if (cmsGetProfileVersion(hProfiles[i]) >= 4.0) + if (cmsGetEncodedICCversion(hProfiles[i]) >= 0x4000000) BPC[i] = TRUE; } } diff --git a/thirdparty/liblcms2/src/cmserr.c b/thirdparty/liblcms2/src/cmserr.c index 29516db4..78a1f947 100644 --- a/thirdparty/liblcms2/src/cmserr.c +++ b/thirdparty/liblcms2/src/cmserr.c @@ -1,7 +1,7 @@ //--------------------------------------------------------------------------------- // // Little Color Management System -// Copyright (c) 1998-2012 Marti Maria Saguer +// Copyright (c) 1998-2016 Marti Maria Saguer // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), @@ -25,6 +25,13 @@ #include "lcms2_internal.h" + +// This function is here to help applications to prevent mixing lcms versions on header and shared objects. +int CMSEXPORT cmsGetEncodedCMMversion(void) +{ + return LCMS_VERSION; +} + // I am so tired about incompatibilities on those functions that here are some replacements // that hopefully would be fully portable. diff --git a/thirdparty/liblcms2/src/cmsgmt.c b/thirdparty/liblcms2/src/cmsgmt.c index 09427650..51c2fefe 100644 --- a/thirdparty/liblcms2/src/cmsgmt.c +++ b/thirdparty/liblcms2/src/cmsgmt.c @@ -1,7 +1,7 @@ //--------------------------------------------------------------------------------- // // Little Color Management System -// Copyright (c) 1998-2012 Marti Maria Saguer +// Copyright (c) 1998-2016 Marti Maria Saguer // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), diff --git a/thirdparty/liblcms2/src/cmshalf.c b/thirdparty/liblcms2/src/cmshalf.c index 204dee96..cdd4e37b 100644 --- a/thirdparty/liblcms2/src/cmshalf.c +++ b/thirdparty/liblcms2/src/cmshalf.c @@ -1,7 +1,7 @@ //--------------------------------------------------------------------------------- // // Little Color Management System -// Copyright (c) 1998-2012 Marti Maria Saguer +// Copyright (c) 1998-2016 Marti Maria Saguer // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), diff --git a/thirdparty/liblcms2/src/cmsintrp.c b/thirdparty/liblcms2/src/cmsintrp.c index 5d5f35d3..889b6981 100644 --- a/thirdparty/liblcms2/src/cmsintrp.c +++ b/thirdparty/liblcms2/src/cmsintrp.c @@ -1,7 +1,7 @@ //--------------------------------------------------------------------------------- // // Little Color Management System -// Copyright (c) 1998-2012 Marti Maria Saguer +// Copyright (c) 1998-2016 Marti Maria Saguer // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), @@ -929,7 +929,7 @@ void Eval4Inputs(register const cmsUInt16Number Input[], Rest = c1 * rx + c2 * ry + c3 * rz; - Tmp1[OutChan] = (cmsUInt16Number) c0 + ROUND_FIXED_TO_INT(_cmsToFixedDomain(Rest)); + Tmp1[OutChan] = (cmsUInt16Number) ( c0 + ROUND_FIXED_TO_INT(_cmsToFixedDomain(Rest))); } @@ -993,7 +993,7 @@ void Eval4Inputs(register const cmsUInt16Number Input[], Rest = c1 * rx + c2 * ry + c3 * rz; - Tmp2[OutChan] = (cmsUInt16Number) c0 + ROUND_FIXED_TO_INT(_cmsToFixedDomain(Rest)); + Tmp2[OutChan] = (cmsUInt16Number) (c0 + ROUND_FIXED_TO_INT(_cmsToFixedDomain(Rest))); } diff --git a/thirdparty/liblcms2/src/cmsio0.c b/thirdparty/liblcms2/src/cmsio0.c index 4449acd4..2084c7c4 100644 --- a/thirdparty/liblcms2/src/cmsio0.c +++ b/thirdparty/liblcms2/src/cmsio0.c @@ -1,7 +1,7 @@ //--------------------------------------------------------------------------------- // // Little Color Management System -// Copyright (c) 1998-2012 Marti Maria Saguer +// Copyright (c) 1998-2016 Marti Maria Saguer // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), @@ -453,6 +453,14 @@ cmsBool CMSEXPORT cmsCloseIOhandler(cmsIOHANDLER* io) // ------------------------------------------------------------------------------------------------------- +cmsIOHANDLER* CMSEXPORT cmsGetProfileIOhandler(cmsHPROFILE hProfile) +{ + _cmsICCPROFILE* Icc = (_cmsICCPROFILE*)hProfile; + + if (Icc == NULL) return NULL; + return Icc->IOhandler; +} + // Creates an empty structure holding all required parameters cmsHPROFILE CMSEXPORT cmsCreateProfilePlaceholder(cmsContext ContextID) { @@ -623,6 +631,32 @@ cmsBool CMSEXPORT cmsIsTag(cmsHPROFILE hProfile, cmsTagSignature sig) } + +// Enforces that the profile version is per. spec. +// Operates on the big endian bytes from the profile. +// Called before converting to platform endianness. +// Byte 0 is BCD major version, so max 9. +// Byte 1 is 2 BCD digits, one per nibble. +// Reserved bytes 2 & 3 must be 0. +static +cmsUInt32Number _validatedVersion(cmsUInt32Number DWord) +{ + cmsUInt8Number* pByte = (cmsUInt8Number*) &DWord; + cmsUInt8Number temp1; + cmsUInt8Number temp2; + + if (*pByte > 0x09) *pByte = (cmsUInt8Number) 0x09; + temp1 = *(pByte+1) & 0xf0; + temp2 = *(pByte+1) & 0x0f; + if (temp1 > 0x90) temp1 = 0x90; + if (temp2 > 0x09) temp2 = 0x09; + *(pByte+1) = (cmsUInt8Number)(temp1 | temp2); + *(pByte+2) = (cmsUInt8Number)0; + *(pByte+3) = (cmsUInt8Number)0; + + return DWord; +} + // Read profile header and validate it cmsBool _cmsReadHeader(_cmsICCPROFILE* Icc) { @@ -657,7 +691,7 @@ cmsBool _cmsReadHeader(_cmsICCPROFILE* Icc) Icc -> creator = _cmsAdjustEndianess32(Header.creator); _cmsAdjustEndianess64(&Icc -> attributes, &Header.attributes); - Icc -> Version = _cmsAdjustEndianess32(Header.version); + Icc -> Version = _cmsAdjustEndianess32(_validatedVersion(Header.version)); // Get size as reported in header HeaderSize = _cmsAdjustEndianess32(Header.size); @@ -773,7 +807,7 @@ cmsBool _cmsWriteHeader(_cmsICCPROFILE* Icc, cmsUInt32Number UsedSpace) // Get true count for (i=0; i < Icc -> TagCount; i++) { - if (Icc ->TagNames[i] != 0) + if (Icc ->TagNames[i] != (cmsTagSignature) 0) Count++; } @@ -782,7 +816,7 @@ cmsBool _cmsWriteHeader(_cmsICCPROFILE* Icc, cmsUInt32Number UsedSpace) for (i=0; i < Icc -> TagCount; i++) { - if (Icc ->TagNames[i] == 0) continue; // It is just a placeholder + if (Icc ->TagNames[i] == (cmsTagSignature) 0) continue; // It is just a placeholder Tag.sig = (cmsTagSignature) _cmsAdjustEndianess32((cmsInt32Number) Icc -> TagNames[i]); Tag.offset = _cmsAdjustEndianess32((cmsInt32Number) Icc -> TagOffsets[i]); @@ -1132,7 +1166,7 @@ cmsBool SaveTags(_cmsICCPROFILE* Icc, _cmsICCPROFILE* FileOrig) for (i=0; i < Icc -> TagCount; i++) { - if (Icc ->TagNames[i] == 0) continue; + if (Icc ->TagNames[i] == (cmsTagSignature) 0) continue; // Linked tags are not written if (Icc ->TagLinked[i] != (cmsTagSignature) 0) continue; @@ -1265,12 +1299,16 @@ cmsUInt32Number CMSEXPORT cmsSaveProfileToIOhandler(cmsHPROFILE hProfile, cmsIOH cmsContext ContextID; _cmsAssert(hProfile != NULL); - + + if (!_cmsLockMutex(Icc->ContextID, Icc->UsrMutex)) return 0; memmove(&Keep, Icc, sizeof(_cmsICCPROFILE)); ContextID = cmsGetProfileContextID(hProfile); PrevIO = Icc ->IOhandler = cmsOpenIOhandlerFromNULL(ContextID); - if (PrevIO == NULL) return 0; + if (PrevIO == NULL) { + _cmsUnlockMutex(Icc->ContextID, Icc->UsrMutex); + return 0; + } // Pass #1 does compute offsets @@ -1290,7 +1328,10 @@ cmsUInt32Number CMSEXPORT cmsSaveProfileToIOhandler(cmsHPROFILE hProfile, cmsIOH } memmove(Icc, &Keep, sizeof(_cmsICCPROFILE)); - if (!cmsCloseIOhandler(PrevIO)) return 0; + if (!cmsCloseIOhandler(PrevIO)) + UsedSpace = 0; // As a error marker + + _cmsUnlockMutex(Icc->ContextID, Icc->UsrMutex); return UsedSpace; @@ -1298,6 +1339,8 @@ cmsUInt32Number CMSEXPORT cmsSaveProfileToIOhandler(cmsHPROFILE hProfile, cmsIOH Error: cmsCloseIOhandler(PrevIO); memmove(Icc, &Keep, sizeof(_cmsICCPROFILE)); + _cmsUnlockMutex(Icc->ContextID, Icc->UsrMutex); + return 0; } @@ -1794,7 +1837,7 @@ Error: // Similar to the anterior. This function allows to write directly to the ICC profile any data, without // checking anything. As a rule, mixing Raw with cooked doesn't work, so writting a tag as raw and then reading -// it as cooked without serializing does result into an error. If that is wha you want, you will need to dump +// it as cooked without serializing does result into an error. If that is what you want, you will need to dump // the profile to memry or disk and then reopen it. cmsBool CMSEXPORT cmsWriteRawTag(cmsHPROFILE hProfile, cmsTagSignature sig, const void* data, cmsUInt32Number Size) { @@ -1818,6 +1861,11 @@ cmsBool CMSEXPORT cmsWriteRawTag(cmsHPROFILE hProfile, cmsTagSignature sig, cons Icc ->TagSizes[i] = Size; _cmsUnlockMutex(Icc->ContextID, Icc ->UsrMutex); + + if (Icc->TagPtrs[i] == NULL) { + Icc->TagNames[i] = (cmsTagSignature) 0; + return FALSE; + } return TRUE; } diff --git a/thirdparty/liblcms2/src/cmsio1.c b/thirdparty/liblcms2/src/cmsio1.c index 89856e57..73ecbdc8 100644 --- a/thirdparty/liblcms2/src/cmsio1.c +++ b/thirdparty/liblcms2/src/cmsio1.c @@ -1,7 +1,7 @@ //--------------------------------------------------------------------------------- // // Little Color Management System -// Copyright (c) 1998-2012 Marti Maria Saguer +// Copyright (c) 1998-2016 Marti Maria Saguer // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), @@ -310,8 +310,8 @@ Error: cmsPipeline* _cmsReadInputLUT(cmsHPROFILE hProfile, int Intent) { cmsTagTypeSignature OriginalType; - cmsTagSignature tag16 = Device2PCS16[Intent]; - cmsTagSignature tagFloat = Device2PCSFloat[Intent]; + cmsTagSignature tag16; + cmsTagSignature tagFloat; cmsContext ContextID = cmsGetProfileContextID(hProfile); // On named color, take the appropiate tag @@ -340,6 +340,9 @@ cmsPipeline* _cmsReadInputLUT(cmsHPROFILE hProfile, int Intent) // matter other LUT are present and have precedence. Intent = -1 means just this. if (Intent != -1) { + tag16 = Device2PCS16[Intent]; + tagFloat = Device2PCSFloat[Intent]; + if (cmsIsTag(hProfile, tagFloat)) { // Float tag takes precedence // Floating point LUT are always V4, but the encoding range is no @@ -582,13 +585,16 @@ Error: cmsPipeline* _cmsReadOutputLUT(cmsHPROFILE hProfile, int Intent) { cmsTagTypeSignature OriginalType; - cmsTagSignature tag16 = PCS2Device16[Intent]; - cmsTagSignature tagFloat = PCS2DeviceFloat[Intent]; - cmsContext ContextID = cmsGetProfileContextID(hProfile); + cmsTagSignature tag16; + cmsTagSignature tagFloat; + cmsContext ContextID = cmsGetProfileContextID(hProfile); if (Intent != -1) { + tag16 = PCS2Device16[Intent]; + tagFloat = PCS2DeviceFloat[Intent]; + if (cmsIsTag(hProfile, tagFloat)) { // Float tag takes precedence // Floating point LUT are always V4 @@ -906,7 +912,7 @@ cmsBool _cmsWriteProfileSequence(cmsHPROFILE hProfile, const cmsSEQ* seq) { if (!cmsWriteTag(hProfile, cmsSigProfileSequenceDescTag, seq)) return FALSE; - if (cmsGetProfileVersion(hProfile) >= 4.0) { + if (cmsGetEncodedICCversion(hProfile) >= 0x4000000) { if (!cmsWriteTag(hProfile, cmsSigProfileSequenceIdTag, seq)) return FALSE; } diff --git a/thirdparty/liblcms2/src/cmslut.c b/thirdparty/liblcms2/src/cmslut.c index c491662b..df3dfc1a 100644 --- a/thirdparty/liblcms2/src/cmslut.c +++ b/thirdparty/liblcms2/src/cmslut.c @@ -1,7 +1,7 @@ //--------------------------------------------------------------------------------- // // Little Color Management System -// Copyright (c) 1998-2012 Marti Maria Saguer +// Copyright (c) 1998-2016 Marti Maria Saguer // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), @@ -505,7 +505,7 @@ void* CLUTElemDup(cmsStage* mpe) goto Error; } else { NewElem ->Tab.T = (cmsUInt16Number*) _cmsDupMem(mpe ->ContextID, Data ->Tab.T, Data ->nEntries * sizeof (cmsUInt16Number)); - if (NewElem ->Tab.TFloat == NULL) + if (NewElem ->Tab.T == NULL) goto Error; } } @@ -1125,7 +1125,23 @@ cmsStage* _cmsStageNormalizeToXyzFloat(cmsContext ContextID) return mpe; } +// Clips values smaller than zero +static +void Clipper(const cmsFloat32Number In[], cmsFloat32Number Out[], const cmsStage *mpe) +{ + cmsUInt32Number i; + for (i = 0; i < mpe->InputChannels; i++) { + cmsFloat32Number n = In[i]; + Out[i] = n < 0 ? 0 : n; + } +} + +cmsStage* _cmsStageClipNegatives(cmsContext ContextID, int nChannels) +{ + return _cmsStageAllocPlaceholder(ContextID, cmsSigClipNegativesElemType, + nChannels, nChannels, Clipper, NULL, NULL, NULL); +} // ******************************************************************************** // Type cmsSigXYZ2LabElemType @@ -1437,7 +1453,8 @@ cmsPipeline* CMSEXPORT cmsPipelineDup(const cmsPipeline* lut) First = FALSE; } else { - Anterior ->Next = NewMPE; + if (Anterior != NULL) + Anterior ->Next = NewMPE; } Anterior = NewMPE; @@ -1482,7 +1499,7 @@ int CMSEXPORT cmsPipelineInsertStage(cmsPipeline* lut, cmsStageLoc loc, cmsStage for (pt = lut ->Elements; pt != NULL; pt = pt -> Next) Anterior = pt; - + Anterior ->Next = mpe; mpe ->Next = NULL; } diff --git a/thirdparty/liblcms2/src/cmsmd5.c b/thirdparty/liblcms2/src/cmsmd5.c index 966730cf..c7380ca8 100644 --- a/thirdparty/liblcms2/src/cmsmd5.c +++ b/thirdparty/liblcms2/src/cmsmd5.c @@ -1,7 +1,7 @@ //--------------------------------------------------------------------------------- // // Little Color Management System -// Copyright (c) 1998-2012 Marti Maria Saguer +// Copyright (c) 1998-2016 Marti Maria Saguer // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), diff --git a/thirdparty/liblcms2/src/cmsmtrx.c b/thirdparty/liblcms2/src/cmsmtrx.c index 583b1ab2..1dbdc4c2 100644 --- a/thirdparty/liblcms2/src/cmsmtrx.c +++ b/thirdparty/liblcms2/src/cmsmtrx.c @@ -1,7 +1,7 @@ //--------------------------------------------------------------------------------- // // Little Color Management System -// Copyright (c) 1998-2012 Marti Maria Saguer +// Copyright (c) 1998-2016 Marti Maria Saguer // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), diff --git a/thirdparty/liblcms2/src/cmsnamed.c b/thirdparty/liblcms2/src/cmsnamed.c index acfd1c8c..0da01d99 100644 --- a/thirdparty/liblcms2/src/cmsnamed.c +++ b/thirdparty/liblcms2/src/cmsnamed.c @@ -1,7 +1,7 @@ //--------------------------------------------------------------------------------- // // Little Color Management System -// Copyright (c) 1998-2012 Marti Maria Saguer +// Copyright (c) 1998-2016 Marti Maria Saguer // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), @@ -92,7 +92,7 @@ cmsBool GrowMLUpool(cmsMLU* mlu) static cmsBool GrowMLUtable(cmsMLU* mlu) { - int AllocatedEntries; + cmsUInt32Number AllocatedEntries; _cmsMLUentry *NewPtr; // Sanity check @@ -118,7 +118,7 @@ cmsBool GrowMLUtable(cmsMLU* mlu) static int SearchMLUEntry(cmsMLU* mlu, cmsUInt16Number LanguageCode, cmsUInt16Number CountryCode) { - int i; + cmsUInt32Number i; // Sanity check if (mlu == NULL) return -1; @@ -178,6 +178,33 @@ cmsBool AddMLUBlock(cmsMLU* mlu, cmsUInt32Number size, const wchar_t *Block, return TRUE; } +// Convert from a 3-char code to a cmsUInt16Number. It is done inthis way because some +// compilers don't properly align beginning of strings + +static +cmsUInt16Number strTo16(const char str[3]) +{ + cmsUInt16Number n = ((cmsUInt16Number) str[0] << 8) | str[1]; + + return n; // Always big endian in this case +} + +static +void strFrom16(char str[3], cmsUInt16Number n) +{ + // Assiming this would be aligned + union { + + cmsUInt16Number n; + char str[2]; + + } c; + + c.n = n; // Always big endian in this case + + str[0] = c.str[0]; str[1] = c.str[1]; str[2] = 0; + +} // Add an ASCII entry. cmsBool CMSEXPORT cmsMLUsetASCII(cmsMLU* mlu, const char LanguageCode[3], const char CountryCode[3], const char* ASCIIString) @@ -185,8 +212,8 @@ cmsBool CMSEXPORT cmsMLUsetASCII(cmsMLU* mlu, const char LanguageCode[3], const cmsUInt32Number i, len = (cmsUInt32Number) strlen(ASCIIString)+1; wchar_t* WStr; cmsBool rc; - cmsUInt16Number Lang = _cmsAdjustEndianess16(*(cmsUInt16Number*) LanguageCode); - cmsUInt16Number Cntry = _cmsAdjustEndianess16(*(cmsUInt16Number*) CountryCode); + cmsUInt16Number Lang = strTo16(LanguageCode); + cmsUInt16Number Cntry = strTo16(CountryCode); if (mlu == NULL) return FALSE; @@ -220,8 +247,8 @@ cmsUInt32Number mywcslen(const wchar_t *s) // Add a wide entry cmsBool CMSEXPORT cmsMLUsetWide(cmsMLU* mlu, const char Language[3], const char Country[3], const wchar_t* WideString) { - cmsUInt16Number Lang = _cmsAdjustEndianess16(*(cmsUInt16Number*) Language); - cmsUInt16Number Cntry = _cmsAdjustEndianess16(*(cmsUInt16Number*) Country); + cmsUInt16Number Lang = strTo16(Language); + cmsUInt16Number Cntry = strTo16(Country); cmsUInt32Number len; if (mlu == NULL) return FALSE; @@ -298,8 +325,8 @@ const wchar_t* _cmsMLUgetWide(const cmsMLU* mlu, cmsUInt16Number LanguageCode, cmsUInt16Number CountryCode, cmsUInt16Number* UsedLanguageCode, cmsUInt16Number* UsedCountryCode) { - int i; - int Best = -1; + cmsUInt32Number i; + cmsInt32Number Best = -1; _cmsMLUentry* v; if (mlu == NULL) return NULL; @@ -350,8 +377,8 @@ cmsUInt32Number CMSEXPORT cmsMLUgetASCII(const cmsMLU* mlu, cmsUInt32Number StrLen = 0; cmsUInt32Number ASCIIlen, i; - cmsUInt16Number Lang = _cmsAdjustEndianess16(*(cmsUInt16Number*) LanguageCode); - cmsUInt16Number Cntry = _cmsAdjustEndianess16(*(cmsUInt16Number*) CountryCode); + cmsUInt16Number Lang = strTo16(LanguageCode); + cmsUInt16Number Cntry = strTo16(CountryCode); // Sanitize if (mlu == NULL) return 0; @@ -394,8 +421,8 @@ cmsUInt32Number CMSEXPORT cmsMLUgetWide(const cmsMLU* mlu, const wchar_t *Wide; cmsUInt32Number StrLen = 0; - cmsUInt16Number Lang = _cmsAdjustEndianess16(*(cmsUInt16Number*) LanguageCode); - cmsUInt16Number Cntry = _cmsAdjustEndianess16(*(cmsUInt16Number*) CountryCode); + cmsUInt16Number Lang = strTo16(LanguageCode); + cmsUInt16Number Cntry = strTo16(CountryCode); // Sanitize if (mlu == NULL) return 0; @@ -427,8 +454,8 @@ CMSAPI cmsBool CMSEXPORT cmsMLUgetTranslation(const cmsMLU* mlu, { const wchar_t *Wide; - cmsUInt16Number Lang = _cmsAdjustEndianess16(*(cmsUInt16Number*) LanguageCode); - cmsUInt16Number Cntry = _cmsAdjustEndianess16(*(cmsUInt16Number*) CountryCode); + cmsUInt16Number Lang = strTo16(LanguageCode); + cmsUInt16Number Cntry = strTo16(CountryCode); cmsUInt16Number ObtLang, ObtCode; // Sanitize @@ -438,10 +465,9 @@ CMSAPI cmsBool CMSEXPORT cmsMLUgetTranslation(const cmsMLU* mlu, if (Wide == NULL) return FALSE; // Get used language and code - *(cmsUInt16Number *)ObtainedLanguage = _cmsAdjustEndianess16(ObtLang); - *(cmsUInt16Number *)ObtainedCountry = _cmsAdjustEndianess16(ObtCode); + strFrom16(ObtainedLanguage, ObtLang); + strFrom16(ObtainedCountry, ObtCode); - ObtainedLanguage[2] = ObtainedCountry[2] = 0; return TRUE; } @@ -464,12 +490,12 @@ cmsBool CMSEXPORT cmsMLUtranslationsCodes(const cmsMLU* mlu, if (mlu == NULL) return FALSE; - if (idx >= (cmsUInt32Number) mlu->UsedEntries) return FALSE; + if (idx >= mlu->UsedEntries) return FALSE; entry = &mlu->Entries[idx]; - *(cmsUInt16Number *)LanguageCode = _cmsAdjustEndianess16(entry->Language); - *(cmsUInt16Number *)CountryCode = _cmsAdjustEndianess16(entry->Country); + strFrom16(LanguageCode, entry->Language); + strFrom16(CountryCode, entry->Country); return TRUE; } @@ -514,8 +540,9 @@ cmsNAMEDCOLORLIST* CMSEXPORT cmsAllocNamedColorList(cmsContext ContextID, cmsUIn v ->nColors = 0; v ->ContextID = ContextID; - while (v -> Allocated < n) - GrowNamedColorList(v); + while (v -> Allocated < n){ + if (!GrowNamedColorList(v)) return NULL; + } strncpy(v ->Prefix, Prefix, sizeof(v ->Prefix)-1); strncpy(v ->Suffix, Suffix, sizeof(v ->Suffix)-1); @@ -544,8 +571,9 @@ cmsNAMEDCOLORLIST* CMSEXPORT cmsDupNamedColorList(const cmsNAMEDCOLORLIST* v) if (NewNC == NULL) return NULL; // For really large tables we need this - while (NewNC ->Allocated < v ->Allocated) - GrowNamedColorList(NewNC); + while (NewNC ->Allocated < v ->Allocated){ + if (!GrowNamedColorList(NewNC)) return NULL; + } memmove(NewNC ->Prefix, v ->Prefix, sizeof(v ->Prefix)); memmove(NewNC ->Suffix, v ->Suffix, sizeof(v ->Suffix)); diff --git a/thirdparty/liblcms2/src/cmsopt.c b/thirdparty/liblcms2/src/cmsopt.c index bf950917..2fba94b2 100644 --- a/thirdparty/liblcms2/src/cmsopt.c +++ b/thirdparty/liblcms2/src/cmsopt.c @@ -1,8 +1,7 @@ - //--------------------------------------------------------------------------------- // // Little Color Management System -// Copyright (c) 1998-2011 Marti Maria Saguer +// Copyright (c) 1998-2016 Marti Maria Saguer // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), @@ -163,6 +162,89 @@ cmsBool _Remove2Op(cmsPipeline* Lut, cmsStageSignature Op1, cmsStageSignature Op return AnyOpt; } + +static +cmsBool CloseEnoughFloat(cmsFloat64Number a, cmsFloat64Number b) +{ + return fabs(b - a) < 0.00001f; +} + +static +cmsBool isFloatMatrixIdentity(const cmsMAT3* a) +{ + cmsMAT3 Identity; + int i, j; + + _cmsMAT3identity(&Identity); + + for (i = 0; i < 3; i++) + for (j = 0; j < 3; j++) + if (!CloseEnoughFloat(a->v[i].n[j], Identity.v[i].n[j])) return FALSE; + + return TRUE; +} +// if two adjacent matrices are found, multiply them. +static +cmsBool _MultiplyMatrix(cmsPipeline* Lut) +{ + cmsStage** pt1; + cmsStage** pt2; + cmsStage* chain; + cmsBool AnyOpt = FALSE; + + pt1 = &Lut->Elements; + if (*pt1 == NULL) return AnyOpt; + + while (*pt1 != NULL) { + + pt2 = &((*pt1)->Next); + if (*pt2 == NULL) return AnyOpt; + + if ((*pt1)->Implements == cmsSigMatrixElemType && (*pt2)->Implements == cmsSigMatrixElemType) { + + // Get both matrices + _cmsStageMatrixData* m1 = (_cmsStageMatrixData*) cmsStageData(*pt1); + _cmsStageMatrixData* m2 = (_cmsStageMatrixData*) cmsStageData(*pt2); + cmsMAT3 res; + + // Input offset and output offset should be zero to use this optimization + if (m1->Offset != NULL || m2 ->Offset != NULL || + cmsStageInputChannels(*pt1) != 3 || cmsStageOutputChannels(*pt1) != 3 || + cmsStageInputChannels(*pt2) != 3 || cmsStageOutputChannels(*pt2) != 3) + return FALSE; + + // Multiply both matrices to get the result + _cmsMAT3per(&res, (cmsMAT3*)m2->Double, (cmsMAT3*)m1->Double); + + // Get the next in chain afer the matrices + chain = (*pt2)->Next; + + // Remove both matrices + _RemoveElement(pt2); + _RemoveElement(pt1); + + // Now what if the result is a plain identity? + if (!isFloatMatrixIdentity(&res)) { + + // We can not get rid of full matrix + cmsStage* Multmat = cmsStageAllocMatrix(Lut->ContextID, 3, 3, (const cmsFloat64Number*) &res, NULL); + if (Multmat == NULL) return FALSE; // Should never happen + + // Recover the chain + Multmat->Next = chain; + *pt1 = Multmat; + } + + AnyOpt = TRUE; + } + else + pt1 = &((*pt1)->Next); + } + + return AnyOpt; +} + + // Preoptimize just gets rif of no-ops coming paired. Conversion from v2 to v4 followed // by a v4 to v2 and vice-versa. The elements are then discarded. static @@ -195,6 +277,9 @@ cmsBool PreOptimize(cmsPipeline* Lut) // Remove float pcs Lab conversions Opt |= _Remove2Op(Lut, cmsSigXYZ2FloatPCS, cmsSigFloatPCS2XYZ); + // Simplify matrix. + Opt |= _MultiplyMatrix(Lut); + if (Opt) AnyOpt = TRUE; } while (Opt); @@ -251,12 +336,12 @@ static void* Prelin16dup(cmsContext ContextID, const void* ptr) { Prelin16Data* p16 = (Prelin16Data*) ptr; - Prelin16Data* Duped = _cmsDupMem(ContextID, p16, sizeof(Prelin16Data)); + Prelin16Data* Duped = (Prelin16Data*) _cmsDupMem(ContextID, p16, sizeof(Prelin16Data)); if (Duped == NULL) return NULL; - Duped ->EvalCurveOut16 = _cmsDupMem(ContextID, p16 ->EvalCurveOut16, p16 ->nOutputs * sizeof(_cmsInterpFn16)); - Duped ->ParamsCurveOut16 = _cmsDupMem(ContextID, p16 ->ParamsCurveOut16, p16 ->nOutputs * sizeof(cmsInterpParams* )); + Duped->EvalCurveOut16 = (_cmsInterpFn16*) _cmsDupMem(ContextID, p16->EvalCurveOut16, p16->nOutputs * sizeof(_cmsInterpFn16)); + Duped->ParamsCurveOut16 = (cmsInterpParams**)_cmsDupMem(ContextID, p16->ParamsCurveOut16, p16->nOutputs * sizeof(cmsInterpParams*)); return Duped; } @@ -269,7 +354,7 @@ Prelin16Data* PrelinOpt16alloc(cmsContext ContextID, int nOutputs, cmsToneCurve** Out ) { int i; - Prelin16Data* p16 = _cmsMallocZero(ContextID, sizeof(Prelin16Data)); + Prelin16Data* p16 = (Prelin16Data*)_cmsMallocZero(ContextID, sizeof(Prelin16Data)); if (p16 == NULL) return NULL; p16 ->nInputs = nInputs; @@ -590,7 +675,7 @@ cmsBool OptimizeByResampling(cmsPipeline** Lut, cmsUInt32Number Intent, cmsUInt3 cmsStage* PreLin = cmsPipelineGetPtrToFirstStage(Src); // Check if suitable - if (PreLin ->Type == cmsSigCurveSetElemType) { + if (PreLin && PreLin ->Type == cmsSigCurveSetElemType) { // Maybe this is a linear tram, so we can avoid the whole stuff if (!AllCurvesAreLinear(PreLin)) { @@ -623,7 +708,7 @@ cmsBool OptimizeByResampling(cmsPipeline** Lut, cmsUInt32Number Intent, cmsUInt3 cmsStage* PostLin = cmsPipelineGetPtrToLastStage(Src); // Check if suitable - if (cmsStageType(PostLin) == cmsSigCurveSetElemType) { + if (PostLin && cmsStageType(PostLin) == cmsSigCurveSetElemType) { // Maybe this is a linear tram, so we can avoid the whole stuff if (!AllCurvesAreLinear(PostLin)) { @@ -758,7 +843,7 @@ Prelin8Data* PrelinOpt8alloc(cmsContext ContextID, const cmsInterpParams* p, cms cmsS15Fixed16Number v1, v2, v3; Prelin8Data* p8; - p8 = _cmsMallocZero(ContextID, sizeof(Prelin8Data)); + p8 = (Prelin8Data*)_cmsMallocZero(ContextID, sizeof(Prelin8Data)); if (p8 == NULL) return NULL; // Since this only works for 8 bit input, values comes always as x * 257, @@ -832,7 +917,7 @@ void PrelinEval8(register const cmsUInt16Number Input[], Prelin8Data* p8 = (Prelin8Data*) D; register const cmsInterpParams* p = p8 ->p; int TotalOut = p -> nOutputs; - const cmsUInt16Number* LutTable = p -> Table; + const cmsUInt16Number* LutTable = (const cmsUInt16Number*) p->Table; r = Input[0] >> 8; g = Input[1] >> 8; @@ -925,8 +1010,8 @@ cmsBool IsDegenerated(const cmsToneCurve* g) } if (Zeros == 1 && Poles == 1) return FALSE; // For linear tables - if (Zeros > (nEntries / 4)) return TRUE; // Degenerated, mostly zeros - if (Poles > (nEntries / 4)) return TRUE; // Degenerated, mostly poles + if (Zeros > (nEntries / 20)) return TRUE; // Degenerated, many zeros + if (Poles > (nEntries / 20)) return TRUE; // Degenerated, many poles return FALSE; } @@ -948,17 +1033,19 @@ cmsBool OptimizeByComputingLinearization(cmsPipeline** Lut, cmsUInt32Number Inte cmsColorSpaceSignature ColorSpace, OutputColorSpace; cmsStage* OptimizedPrelinMpe; cmsStage* mpe; - cmsToneCurve** OptimizedPrelinCurves; - _cmsStageCLutData* OptimizedPrelinCLUT; + cmsToneCurve** OptimizedPrelinCurves; + _cmsStageCLutData* OptimizedPrelinCLUT; // This is a loosy optimization! does not apply in floating-point cases if (_cmsFormatterIsFloat(*InputFormat) || _cmsFormatterIsFloat(*OutputFormat)) return FALSE; - // Only on RGB + // Only on chunky RGB if (T_COLORSPACE(*InputFormat) != PT_RGB) return FALSE; - if (T_COLORSPACE(*OutputFormat) != PT_RGB) return FALSE; + if (T_PLANAR(*InputFormat)) return FALSE; + if (T_COLORSPACE(*OutputFormat) != PT_RGB) return FALSE; + if (T_PLANAR(*OutputFormat)) return FALSE; // On 16 bits, user has to specify the feature if (!_cmsFormatterIs8bit(*InputFormat)) { @@ -982,6 +1069,22 @@ cmsBool OptimizeByComputingLinearization(cmsPipeline** Lut, cmsUInt32Number Inte memset(Trans, 0, sizeof(Trans)); memset(TransReverse, 0, sizeof(TransReverse)); + // If the last stage of the original lut are curves, and those curves are + // degenerated, it is likely the transform is squeezing and clipping + // the output from previous CLUT. We cannot optimize this case + { + cmsStage* last = cmsPipelineGetPtrToLastStage(OriginalLut); + + if (cmsStageType(last) == cmsSigCurveSetElemType) { + + _cmsStageToneCurvesData* Data = (_cmsStageToneCurvesData*)cmsStageData(last); + for (i = 0; i < Data->nCurves; i++) { + if (IsDegenerated(Data->TheCurves[i])) + goto Error; + } + } + } + for (t = 0; t < OriginalLut ->InputChannels; t++) { Trans[t] = cmsBuildTabulatedToneCurve16(OriginalLut ->ContextID, PRELINEARIZATION_POINTS, NULL); if (Trans[t] == NULL) goto Error; @@ -1151,15 +1254,15 @@ void CurvesFree(cmsContext ContextID, void* ptr) static void* CurvesDup(cmsContext ContextID, const void* ptr) { - Curves16Data* Data = _cmsDupMem(ContextID, ptr, sizeof(Curves16Data)); + Curves16Data* Data = (Curves16Data*)_cmsDupMem(ContextID, ptr, sizeof(Curves16Data)); int i; if (Data == NULL) return NULL; - Data ->Curves = _cmsDupMem(ContextID, Data ->Curves, Data ->nCurves * sizeof(cmsUInt16Number*)); + Data->Curves = (cmsUInt16Number**) _cmsDupMem(ContextID, Data->Curves, Data->nCurves * sizeof(cmsUInt16Number*)); for (i=0; i < Data -> nCurves; i++) { - Data ->Curves[i] = _cmsDupMem(ContextID, Data ->Curves[i], Data -> nElements * sizeof(cmsUInt16Number)); + Data->Curves[i] = (cmsUInt16Number*) _cmsDupMem(ContextID, Data->Curves[i], Data->nElements * sizeof(cmsUInt16Number)); } return (void*) Data; @@ -1172,18 +1275,18 @@ Curves16Data* CurvesAlloc(cmsContext ContextID, int nCurves, int nElements, cmsT int i, j; Curves16Data* c16; - c16 = _cmsMallocZero(ContextID, sizeof(Curves16Data)); + c16 = (Curves16Data*)_cmsMallocZero(ContextID, sizeof(Curves16Data)); if (c16 == NULL) return NULL; c16 ->nCurves = nCurves; c16 ->nElements = nElements; - c16 ->Curves = _cmsCalloc(ContextID, nCurves, sizeof(cmsUInt16Number*)); + c16->Curves = (cmsUInt16Number**) _cmsCalloc(ContextID, nCurves, sizeof(cmsUInt16Number*)); if (c16 ->Curves == NULL) return NULL; for (i=0; i < nCurves; i++) { - c16->Curves[i] = _cmsCalloc(ContextID, nElements, sizeof(cmsUInt16Number)); + c16->Curves[i] = (cmsUInt16Number*) _cmsCalloc(ContextID, nElements, sizeof(cmsUInt16Number)); if (c16->Curves[i] == NULL) { @@ -1315,7 +1418,10 @@ cmsBool OptimizeByJoiningCurves(cmsPipeline** Lut, cmsUInt32Number Intent, cmsUI GammaTables[i] = NULL; } - if (GammaTables != NULL) _cmsFree(Src ->ContextID, GammaTables); + if (GammaTables != NULL) { + _cmsFree(Src->ContextID, GammaTables); + GammaTables = NULL; + } // Maybe the curves are linear at the end if (!AllCurvesAreLinear(ObtainedCurves)) { @@ -1531,49 +1637,83 @@ cmsBool SetMatShaper(cmsPipeline* Dest, cmsToneCurve* Curve1[3], cmsMAT3* Mat, c } // 8 bits on input allows matrix-shaper boot up to 25 Mpixels per second on RGB. That's fast! -// TODO: Allow a third matrix for abs. colorimetric static cmsBool OptimizeMatrixShaper(cmsPipeline** Lut, cmsUInt32Number Intent, cmsUInt32Number* InputFormat, cmsUInt32Number* OutputFormat, cmsUInt32Number* dwFlags) { - cmsStage* Curve1, *Curve2; - cmsStage* Matrix1, *Matrix2; - _cmsStageMatrixData* Data1; - _cmsStageMatrixData* Data2; - cmsMAT3 res; - cmsBool IdentityMat; - cmsPipeline* Dest, *Src; + cmsStage* Curve1, *Curve2; + cmsStage* Matrix1, *Matrix2; + cmsMAT3 res; + cmsBool IdentityMat; + cmsPipeline* Dest, *Src; + cmsFloat64Number* Offset; - // Only works on RGB to RGB - if (T_CHANNELS(*InputFormat) != 3 || T_CHANNELS(*OutputFormat) != 3) return FALSE; + // Only works on RGB to RGB + if (T_CHANNELS(*InputFormat) != 3 || T_CHANNELS(*OutputFormat) != 3) return FALSE; - // Only works on 8 bit input - if (!_cmsFormatterIs8bit(*InputFormat)) return FALSE; + // Only works on 8 bit input + if (!_cmsFormatterIs8bit(*InputFormat)) return FALSE; - // Seems suitable, proceed - Src = *Lut; + // Seems suitable, proceed + Src = *Lut; - // Check for shaper-matrix-matrix-shaper structure, that is what this optimizer stands for - if (!cmsPipelineCheckAndRetreiveStages(Src, 4, - cmsSigCurveSetElemType, cmsSigMatrixElemType, cmsSigMatrixElemType, cmsSigCurveSetElemType, - &Curve1, &Matrix1, &Matrix2, &Curve2)) return FALSE; + // Check for: + // + // shaper-matrix-matrix-shaper + // shaper-matrix-shaper + // + // Both of those constructs are possible (first because abs. colorimetric). + // additionally, In the first case, the input matrix offset should be zero. - // Get both matrices - Data1 = (_cmsStageMatrixData*) cmsStageData(Matrix1); - Data2 = (_cmsStageMatrixData*) cmsStageData(Matrix2); + IdentityMat = FALSE; + if (cmsPipelineCheckAndRetreiveStages(Src, 4, + cmsSigCurveSetElemType, cmsSigMatrixElemType, cmsSigMatrixElemType, cmsSigCurveSetElemType, + &Curve1, &Matrix1, &Matrix2, &Curve2)) { - // Input offset should be zero - if (Data1 ->Offset != NULL) return FALSE; + // Get both matrices + _cmsStageMatrixData* Data1 = (_cmsStageMatrixData*)cmsStageData(Matrix1); + _cmsStageMatrixData* Data2 = (_cmsStageMatrixData*)cmsStageData(Matrix2); - // Multiply both matrices to get the result - _cmsMAT3per(&res, (cmsMAT3*) Data2 ->Double, (cmsMAT3*) Data1 ->Double); + // Input offset should be zero + if (Data1->Offset != NULL) return FALSE; - // Now the result is in res + Data2 -> Offset. Maybe is a plain identity? - IdentityMat = FALSE; - if (_cmsMAT3isIdentity(&res) && Data2 ->Offset == NULL) { + // Multiply both matrices to get the result + _cmsMAT3per(&res, (cmsMAT3*)Data2->Double, (cmsMAT3*)Data1->Double); - // We can get rid of full matrix - IdentityMat = TRUE; - } + // Only 2nd matrix has offset, or it is zero + Offset = Data2->Offset; + + // Now the result is in res + Data2 -> Offset. Maybe is a plain identity? + if (_cmsMAT3isIdentity(&res) && Offset == NULL) { + + // We can get rid of full matrix + IdentityMat = TRUE; + } + + } + else { + + if (cmsPipelineCheckAndRetreiveStages(Src, 3, + cmsSigCurveSetElemType, cmsSigMatrixElemType, cmsSigCurveSetElemType, + &Curve1, &Matrix1, &Curve2)) { + + _cmsStageMatrixData* Data = (_cmsStageMatrixData*)cmsStageData(Matrix1); + + // Copy the matrix to our result + memcpy(&res, Data->Double, sizeof(res)); + + // Preserve the Odffset (may be NULL as a zero offset) + Offset = Data->Offset; + + if (_cmsMAT3isIdentity(&res) && Offset == NULL) { + + // We can get rid of full matrix + IdentityMat = TRUE; + } + } + else + return FALSE; // Not optimizeable this time + + } // Allocate an empty LUT Dest = cmsPipelineAlloc(Src ->ContextID, Src ->InputChannels, Src ->OutputChannels); @@ -1583,9 +1723,12 @@ cmsBool OptimizeMatrixShaper(cmsPipeline** Lut, cmsUInt32Number Intent, cmsUInt3 if (!cmsPipelineInsertStage(Dest, cmsAT_BEGIN, cmsStageDup(Curve1))) goto Error; - if (!IdentityMat) - if (!cmsPipelineInsertStage(Dest, cmsAT_END, cmsStageAllocMatrix(Dest ->ContextID, 3, 3, (const cmsFloat64Number*) &res, Data2 ->Offset))) - goto Error; + if (!IdentityMat) { + + if (!cmsPipelineInsertStage(Dest, cmsAT_END, cmsStageAllocMatrix(Dest->ContextID, 3, 3, (const cmsFloat64Number*)&res, Offset))) + goto Error; + } + if (!cmsPipelineInsertStage(Dest, cmsAT_END, cmsStageDup(Curve2))) goto Error; @@ -1603,7 +1746,7 @@ cmsBool OptimizeMatrixShaper(cmsPipeline** Lut, cmsUInt32Number Intent, cmsUInt3 *dwFlags |= cmsFLAGS_NOCACHE; // Setup the optimizarion routines - SetMatShaper(Dest, mpeC1 ->TheCurves, &res, (cmsVEC3*) Data2 ->Offset, mpeC2->TheCurves, OutputFormat); + SetMatShaper(Dest, mpeC1 ->TheCurves, &res, (cmsVEC3*) Offset, mpeC2->TheCurves, OutputFormat); } cmsPipelineFree(Src); diff --git a/thirdparty/liblcms2/src/cmspack.c b/thirdparty/liblcms2/src/cmspack.c index c84fd822..12d6aae7 100644 --- a/thirdparty/liblcms2/src/cmspack.c +++ b/thirdparty/liblcms2/src/cmspack.c @@ -1,7 +1,7 @@ //--------------------------------------------------------------------------------- // // Little Color Management System -// Copyright (c) 1998-2010 Marti Maria Saguer +// Copyright (c) 1998-2016 Marti Maria Saguer // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), @@ -2409,9 +2409,6 @@ cmsUInt8Number* PackDoubleFrom16(register _cmsTRANSFORM* info, ((cmsFloat64Number*) output)[i + start] = v; } - if (!ExtraFirst) { - output += Extra * sizeof(cmsFloat64Number); - } if (Extra == 0 && SwapFirst) { @@ -2422,7 +2419,7 @@ cmsUInt8Number* PackDoubleFrom16(register _cmsTRANSFORM* info, if (T_PLANAR(info -> OutputFormat)) return output + sizeof(cmsFloat64Number); else - return output + nChan * sizeof(cmsFloat64Number); + return output + (nChan + Extra) * sizeof(cmsFloat64Number); } @@ -2433,50 +2430,47 @@ cmsUInt8Number* PackFloatFrom16(register _cmsTRANSFORM* info, register cmsUInt8Number* output, register cmsUInt32Number Stride) { - int nChan = T_CHANNELS(info -> OutputFormat); - int DoSwap = T_DOSWAP(info ->OutputFormat); - int Reverse = T_FLAVOR(info ->OutputFormat); - int Extra = T_EXTRA(info -> OutputFormat); - int SwapFirst = T_SWAPFIRST(info -> OutputFormat); - int Planar = T_PLANAR(info -> OutputFormat); - int ExtraFirst = DoSwap ^ SwapFirst; - cmsFloat64Number maximum = IsInkSpace(info ->OutputFormat) ? 655.35 : 65535.0; - cmsFloat64Number v = 0; - cmsFloat32Number* swap1 = (cmsFloat32Number*) output; - int i, start = 0; + int nChan = T_CHANNELS(info->OutputFormat); + int DoSwap = T_DOSWAP(info->OutputFormat); + int Reverse = T_FLAVOR(info->OutputFormat); + int Extra = T_EXTRA(info->OutputFormat); + int SwapFirst = T_SWAPFIRST(info->OutputFormat); + int Planar = T_PLANAR(info->OutputFormat); + int ExtraFirst = DoSwap ^ SwapFirst; + cmsFloat64Number maximum = IsInkSpace(info->OutputFormat) ? 655.35 : 65535.0; + cmsFloat64Number v = 0; + cmsFloat32Number* swap1 = (cmsFloat32Number*)output; + int i, start = 0; - if (ExtraFirst) - start = Extra; + if (ExtraFirst) + start = Extra; - for (i=0; i < nChan; i++) { + for (i = 0; i < nChan; i++) { - int index = DoSwap ? (nChan - i - 1) : i; + int index = DoSwap ? (nChan - i - 1) : i; - v = (cmsFloat64Number) wOut[index] / maximum; + v = (cmsFloat64Number)wOut[index] / maximum; - if (Reverse) - v = maximum - v; + if (Reverse) + v = maximum - v; - if (Planar) - ((cmsFloat32Number*) output)[(i + start ) * Stride]= (cmsFloat32Number) v; - else - ((cmsFloat32Number*) output)[i + start] = (cmsFloat32Number) v; - } + if (Planar) + ((cmsFloat32Number*)output)[(i + start) * Stride] = (cmsFloat32Number)v; + else + ((cmsFloat32Number*)output)[i + start] = (cmsFloat32Number)v; + } - if (!ExtraFirst) { - output += Extra * sizeof(cmsFloat32Number); - } + + if (Extra == 0 && SwapFirst) { - if (Extra == 0 && SwapFirst) { + memmove(swap1 + 1, swap1, (nChan - 1)* sizeof(cmsFloat32Number)); + *swap1 = (cmsFloat32Number)v; + } - memmove(swap1 + 1, swap1, (nChan-1)* sizeof(cmsFloat32Number)); - *swap1 = (cmsFloat32Number) v; - } - - if (T_PLANAR(info -> OutputFormat)) - return output + sizeof(cmsFloat32Number); - else - return output + nChan * sizeof(cmsFloat32Number); + if (T_PLANAR(info->OutputFormat)) + return output + sizeof(cmsFloat32Number); + else + return output + (nChan + Extra) * sizeof(cmsFloat32Number); } @@ -2489,50 +2483,47 @@ cmsUInt8Number* PackFloatsFromFloat(_cmsTRANSFORM* info, cmsUInt8Number* output, cmsUInt32Number Stride) { - int nChan = T_CHANNELS(info -> OutputFormat); - int DoSwap = T_DOSWAP(info ->OutputFormat); - int Reverse = T_FLAVOR(info ->OutputFormat); - int Extra = T_EXTRA(info -> OutputFormat); - int SwapFirst = T_SWAPFIRST(info -> OutputFormat); - int Planar = T_PLANAR(info -> OutputFormat); - int ExtraFirst = DoSwap ^ SwapFirst; - cmsFloat64Number maximum = IsInkSpace(info ->OutputFormat) ? 100.0 : 1.0; - cmsFloat32Number* swap1 = (cmsFloat32Number*) output; - cmsFloat64Number v = 0; - int i, start = 0; + int nChan = T_CHANNELS(info->OutputFormat); + int DoSwap = T_DOSWAP(info->OutputFormat); + int Reverse = T_FLAVOR(info->OutputFormat); + int Extra = T_EXTRA(info->OutputFormat); + int SwapFirst = T_SWAPFIRST(info->OutputFormat); + int Planar = T_PLANAR(info->OutputFormat); + int ExtraFirst = DoSwap ^ SwapFirst; + cmsFloat64Number maximum = IsInkSpace(info->OutputFormat) ? 100.0 : 1.0; + cmsFloat32Number* swap1 = (cmsFloat32Number*)output; + cmsFloat64Number v = 0; + int i, start = 0; - if (ExtraFirst) - start = Extra; + if (ExtraFirst) + start = Extra; - for (i=0; i < nChan; i++) { + for (i = 0; i < nChan; i++) { - int index = DoSwap ? (nChan - i - 1) : i; + int index = DoSwap ? (nChan - i - 1) : i; - v = wOut[index] * maximum; + v = wOut[index] * maximum; - if (Reverse) - v = maximum - v; + if (Reverse) + v = maximum - v; - if (Planar) - ((cmsFloat32Number*) output)[(i + start)* Stride]= (cmsFloat32Number) v; - else - ((cmsFloat32Number*) output)[i + start] = (cmsFloat32Number) v; - } + if (Planar) + ((cmsFloat32Number*)output)[(i + start)* Stride] = (cmsFloat32Number)v; + else + ((cmsFloat32Number*)output)[i + start] = (cmsFloat32Number)v; + } - if (!ExtraFirst) { - output += Extra * sizeof(cmsFloat32Number); - } - if (Extra == 0 && SwapFirst) { + if (Extra == 0 && SwapFirst) { - memmove(swap1 + 1, swap1, (nChan-1)* sizeof(cmsFloat32Number)); - *swap1 = (cmsFloat32Number) v; - } + memmove(swap1 + 1, swap1, (nChan - 1)* sizeof(cmsFloat32Number)); + *swap1 = (cmsFloat32Number)v; + } - if (T_PLANAR(info -> OutputFormat)) - return output + sizeof(cmsFloat32Number); - else - return output + nChan * sizeof(cmsFloat32Number); + if (T_PLANAR(info->OutputFormat)) + return output + sizeof(cmsFloat32Number); + else + return output + (nChan + Extra) * sizeof(cmsFloat32Number); } static @@ -2541,51 +2532,47 @@ cmsUInt8Number* PackDoublesFromFloat(_cmsTRANSFORM* info, cmsUInt8Number* output, cmsUInt32Number Stride) { - int nChan = T_CHANNELS(info -> OutputFormat); - int DoSwap = T_DOSWAP(info ->OutputFormat); - int Reverse = T_FLAVOR(info ->OutputFormat); - int Extra = T_EXTRA(info -> OutputFormat); - int SwapFirst = T_SWAPFIRST(info -> OutputFormat); - int Planar = T_PLANAR(info -> OutputFormat); - int ExtraFirst = DoSwap ^ SwapFirst; - cmsFloat64Number maximum = IsInkSpace(info ->OutputFormat) ? 100.0 : 1.0; - cmsFloat64Number v = 0; - cmsFloat64Number* swap1 = (cmsFloat64Number*) output; - int i, start = 0; + int nChan = T_CHANNELS(info->OutputFormat); + int DoSwap = T_DOSWAP(info->OutputFormat); + int Reverse = T_FLAVOR(info->OutputFormat); + int Extra = T_EXTRA(info->OutputFormat); + int SwapFirst = T_SWAPFIRST(info->OutputFormat); + int Planar = T_PLANAR(info->OutputFormat); + int ExtraFirst = DoSwap ^ SwapFirst; + cmsFloat64Number maximum = IsInkSpace(info->OutputFormat) ? 100.0 : 1.0; + cmsFloat64Number v = 0; + cmsFloat64Number* swap1 = (cmsFloat64Number*)output; + int i, start = 0; - if (ExtraFirst) - start = Extra; + if (ExtraFirst) + start = Extra; - for (i=0; i < nChan; i++) { + for (i = 0; i < nChan; i++) { - int index = DoSwap ? (nChan - i - 1) : i; + int index = DoSwap ? (nChan - i - 1) : i; - v = wOut[index] * maximum; + v = wOut[index] * maximum; - if (Reverse) - v = maximum - v; + if (Reverse) + v = maximum - v; - if (Planar) - ((cmsFloat64Number*) output)[(i + start) * Stride] = v; - else - ((cmsFloat64Number*) output)[i + start] = v; - } + if (Planar) + ((cmsFloat64Number*)output)[(i + start) * Stride] = v; + else + ((cmsFloat64Number*)output)[i + start] = v; + } - if (!ExtraFirst) { - output += Extra * sizeof(cmsFloat64Number); - } + if (Extra == 0 && SwapFirst) { - if (Extra == 0 && SwapFirst) { - - memmove(swap1 + 1, swap1, (nChan-1)* sizeof(cmsFloat64Number)); - *swap1 = v; - } + memmove(swap1 + 1, swap1, (nChan - 1)* sizeof(cmsFloat64Number)); + *swap1 = v; + } - if (T_PLANAR(info -> OutputFormat)) - return output + sizeof(cmsFloat64Number); - else - return output + nChan * sizeof(cmsFloat64Number); + if (T_PLANAR(info->OutputFormat)) + return output + sizeof(cmsFloat64Number); + else + return output + (nChan + Extra) * sizeof(cmsFloat64Number); } @@ -2821,50 +2808,47 @@ cmsUInt8Number* PackHalfFrom16(register _cmsTRANSFORM* info, register cmsUInt8Number* output, register cmsUInt32Number Stride) { - int nChan = T_CHANNELS(info -> OutputFormat); - int DoSwap = T_DOSWAP(info ->OutputFormat); - int Reverse = T_FLAVOR(info ->OutputFormat); - int Extra = T_EXTRA(info -> OutputFormat); - int SwapFirst = T_SWAPFIRST(info -> OutputFormat); - int Planar = T_PLANAR(info -> OutputFormat); - int ExtraFirst = DoSwap ^ SwapFirst; - cmsFloat32Number maximum = IsInkSpace(info ->OutputFormat) ? 655.35F : 65535.0F; - cmsFloat32Number v = 0; - cmsUInt16Number* swap1 = (cmsUInt16Number*) output; - int i, start = 0; + int nChan = T_CHANNELS(info->OutputFormat); + int DoSwap = T_DOSWAP(info->OutputFormat); + int Reverse = T_FLAVOR(info->OutputFormat); + int Extra = T_EXTRA(info->OutputFormat); + int SwapFirst = T_SWAPFIRST(info->OutputFormat); + int Planar = T_PLANAR(info->OutputFormat); + int ExtraFirst = DoSwap ^ SwapFirst; + cmsFloat32Number maximum = IsInkSpace(info->OutputFormat) ? 655.35F : 65535.0F; + cmsFloat32Number v = 0; + cmsUInt16Number* swap1 = (cmsUInt16Number*)output; + int i, start = 0; - if (ExtraFirst) - start = Extra; + if (ExtraFirst) + start = Extra; - for (i=0; i < nChan; i++) { + for (i = 0; i < nChan; i++) { - int index = DoSwap ? (nChan - i - 1) : i; + int index = DoSwap ? (nChan - i - 1) : i; - v = (cmsFloat32Number) wOut[index] / maximum; + v = (cmsFloat32Number)wOut[index] / maximum; - if (Reverse) - v = maximum - v; + if (Reverse) + v = maximum - v; - if (Planar) - ((cmsUInt16Number*) output)[(i + start ) * Stride]= _cmsFloat2Half(v); - else - ((cmsUInt16Number*) output)[i + start] = _cmsFloat2Half(v); - } + if (Planar) + ((cmsUInt16Number*)output)[(i + start) * Stride] = _cmsFloat2Half(v); + else + ((cmsUInt16Number*)output)[i + start] = _cmsFloat2Half(v); + } - if (!ExtraFirst) { - output += Extra * sizeof(cmsUInt16Number); - } - if (Extra == 0 && SwapFirst) { + if (Extra == 0 && SwapFirst) { - memmove(swap1 + 1, swap1, (nChan-1)* sizeof(cmsUInt16Number)); - *swap1 = _cmsFloat2Half(v); - } + memmove(swap1 + 1, swap1, (nChan - 1)* sizeof(cmsUInt16Number)); + *swap1 = _cmsFloat2Half(v); + } - if (T_PLANAR(info -> OutputFormat)) - return output + sizeof(cmsUInt16Number); - else - return output + nChan * sizeof(cmsUInt16Number); + if (T_PLANAR(info->OutputFormat)) + return output + sizeof(cmsUInt16Number); + else + return output + (nChan + Extra) * sizeof(cmsUInt16Number); } @@ -2875,50 +2859,47 @@ cmsUInt8Number* PackHalfFromFloat(_cmsTRANSFORM* info, cmsUInt8Number* output, cmsUInt32Number Stride) { - int nChan = T_CHANNELS(info -> OutputFormat); - int DoSwap = T_DOSWAP(info ->OutputFormat); - int Reverse = T_FLAVOR(info ->OutputFormat); - int Extra = T_EXTRA(info -> OutputFormat); - int SwapFirst = T_SWAPFIRST(info -> OutputFormat); - int Planar = T_PLANAR(info -> OutputFormat); - int ExtraFirst = DoSwap ^ SwapFirst; - cmsFloat32Number maximum = IsInkSpace(info ->OutputFormat) ? 100.0F : 1.0F; - cmsUInt16Number* swap1 = (cmsUInt16Number*) output; - cmsFloat32Number v = 0; - int i, start = 0; + int nChan = T_CHANNELS(info->OutputFormat); + int DoSwap = T_DOSWAP(info->OutputFormat); + int Reverse = T_FLAVOR(info->OutputFormat); + int Extra = T_EXTRA(info->OutputFormat); + int SwapFirst = T_SWAPFIRST(info->OutputFormat); + int Planar = T_PLANAR(info->OutputFormat); + int ExtraFirst = DoSwap ^ SwapFirst; + cmsFloat32Number maximum = IsInkSpace(info->OutputFormat) ? 100.0F : 1.0F; + cmsUInt16Number* swap1 = (cmsUInt16Number*)output; + cmsFloat32Number v = 0; + int i, start = 0; - if (ExtraFirst) - start = Extra; + if (ExtraFirst) + start = Extra; - for (i=0; i < nChan; i++) { + for (i = 0; i < nChan; i++) { - int index = DoSwap ? (nChan - i - 1) : i; + int index = DoSwap ? (nChan - i - 1) : i; - v = wOut[index] * maximum; + v = wOut[index] * maximum; - if (Reverse) - v = maximum - v; + if (Reverse) + v = maximum - v; - if (Planar) - ((cmsUInt16Number*) output)[(i + start)* Stride]= _cmsFloat2Half( v ); - else - ((cmsUInt16Number*) output)[i + start] = _cmsFloat2Half( v ); - } + if (Planar) + ((cmsUInt16Number*)output)[(i + start)* Stride] = _cmsFloat2Half(v); + else + ((cmsUInt16Number*)output)[i + start] = _cmsFloat2Half(v); + } - if (!ExtraFirst) { - output += Extra * sizeof(cmsUInt16Number); - } - if (Extra == 0 && SwapFirst) { + if (Extra == 0 && SwapFirst) { - memmove(swap1 + 1, swap1, (nChan-1)* sizeof(cmsUInt16Number)); - *swap1 = (cmsUInt16Number) _cmsFloat2Half( v ); - } + memmove(swap1 + 1, swap1, (nChan - 1)* sizeof(cmsUInt16Number)); + *swap1 = (cmsUInt16Number)_cmsFloat2Half(v); + } - if (T_PLANAR(info -> OutputFormat)) - return output + sizeof(cmsUInt16Number); - else - return output + nChan * sizeof(cmsUInt16Number); + if (T_PLANAR(info->OutputFormat)) + return output + sizeof(cmsUInt16Number); + else + return output + (nChan + Extra)* sizeof(cmsUInt16Number); } #endif @@ -3178,6 +3159,8 @@ cmsFormatter _cmsGetStockOutputFormatter(cmsUInt32Number dwInput, cmsUInt32Numbe cmsUInt32Number i; cmsFormatter fr; + // Optimization is only a hint + dwInput &= ~OPTIMIZED_SH(1); switch (dwFlags) { diff --git a/thirdparty/liblcms2/src/cmspcs.c b/thirdparty/liblcms2/src/cmspcs.c index 102cd7d2..a08538d3 100644 --- a/thirdparty/liblcms2/src/cmspcs.c +++ b/thirdparty/liblcms2/src/cmspcs.c @@ -1,7 +1,7 @@ //--------------------------------------------------------------------------------- // // Little Color Management System -// Copyright (c) 1998-2010 Marti Maria Saguer +// Copyright (c) 1998-2016 Marti Maria Saguer // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), @@ -106,6 +106,15 @@ void CMSEXPORT cmsxyY2XYZ(cmsCIEXYZ* Dest, const cmsCIExyY* Source) Dest -> Z = ((1 - Source -> x - Source -> y) / Source -> y) * Source -> Y; } +/* + The break point (24/116)^3 = (6/29)^3 is a very small amount of tristimulus + primary (0.008856). Generally, this only happens for + nearly ideal blacks and for some orange / amber colors in transmission mode. + For example, the Z value of the orange turn indicator lamp lens on an + automobile will often be below this value. But the Z does not + contribute to the perceived color directly. +*/ + static cmsFloat64Number f(cmsFloat64Number t) { diff --git a/thirdparty/liblcms2/src/cmsplugin.c b/thirdparty/liblcms2/src/cmsplugin.c index 317e33e2..dc13eadb 100644 --- a/thirdparty/liblcms2/src/cmsplugin.c +++ b/thirdparty/liblcms2/src/cmsplugin.c @@ -1,7 +1,7 @@ //--------------------------------------------------------------------------------- // // Little Color Management System -// Copyright (c) 1998-2010 Marti Maria Saguer +// Copyright (c) 1998-2016 Marti Maria Saguer // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), @@ -215,22 +215,6 @@ cmsBool CMSEXPORT _cmsRead15Fixed16Number(cmsIOHANDLER* io, cmsFloat64Number* n } -// Jun-21-2000: Some profiles (those that comes with W2K) comes -// with the media white (media black?) x 100. Add a sanity check - -static -void NormalizeXYZ(cmsCIEXYZ* Dest) -{ - while (Dest -> X > 2. && - Dest -> Y > 2. && - Dest -> Z > 2.) { - - Dest -> X /= 10.; - Dest -> Y /= 10.; - Dest -> Z /= 10.; - } -} - cmsBool CMSEXPORT _cmsReadXYZNumber(cmsIOHANDLER* io, cmsCIEXYZ* XYZ) { cmsEncodedXYZNumber xyz; @@ -244,8 +228,6 @@ cmsBool CMSEXPORT _cmsReadXYZNumber(cmsIOHANDLER* io, cmsCIEXYZ* XYZ) XYZ->X = _cms15Fixed16toDouble(_cmsAdjustEndianess32(xyz.X)); XYZ->Y = _cms15Fixed16toDouble(_cmsAdjustEndianess32(xyz.Y)); XYZ->Z = _cms15Fixed16toDouble(_cmsAdjustEndianess32(xyz.Z)); - - NormalizeXYZ(XYZ); } return TRUE; } @@ -525,6 +507,7 @@ void* _cmsPluginMalloc(cmsContext ContextID, cmsUInt32Number size) if (ContextID == NULL) { ctx->MemPool = _cmsCreateSubAlloc(0, 2*1024); + if (ctx->MemPool == NULL) return NULL; } else { cmsSignalError(ContextID, cmsERROR_CORRUPTION_DETECTED, "NULL memory pool on context"); @@ -683,15 +666,21 @@ struct _cmsContext_struct* _cmsGetContext(cmsContext ContextID) // Internal: get the memory area associanted with each context client -// Returns the block assigned to the specific zone. +// Returns the block assigned to the specific zone. Never return NULL. void* _cmsContextGetClientChunk(cmsContext ContextID, _cmsMemoryClient mc) { struct _cmsContext_struct* ctx; void *ptr; - if (mc < 0 || mc >= MemoryClientMax) { - cmsSignalError(ContextID, cmsERROR_RANGE, "Bad context client"); - return NULL; + if ((int) mc < 0 || mc >= MemoryClientMax) { + + cmsSignalError(ContextID, cmsERROR_INTERNAL, "Bad context client -- possible corruption"); + + // This is catastrophic. Should never reach here + _cmsAssert(0); + + // Reverts to global context + return globalContext.chunks[UserPtr]; } ctx = _cmsGetContext(ContextID); @@ -880,7 +869,7 @@ cmsContext CMSEXPORT cmsDupContext(cmsContext ContextID, void* NewUserData) } - +/* static struct _cmsContext_struct* FindPrev(struct _cmsContext_struct* id) { @@ -897,6 +886,7 @@ struct _cmsContext_struct* FindPrev(struct _cmsContext_struct* id) return NULL; // List is empty or only one element! } +*/ // Frees any resources associated with the given context, // and destroys the context placeholder. @@ -932,8 +922,8 @@ void CMSEXPORT cmsDeleteContext(cmsContext ContextID) // Search for previous for (prev = _cmsContextPoolHead; - prev != NULL; - prev = prev ->Next) + prev != NULL; + prev = prev ->Next) { if (prev -> Next == ctx) { prev -> Next = ctx ->Next; diff --git a/thirdparty/liblcms2/src/cmsps2.c b/thirdparty/liblcms2/src/cmsps2.c index 224b44b5..0f007732 100644 --- a/thirdparty/liblcms2/src/cmsps2.c +++ b/thirdparty/liblcms2/src/cmsps2.c @@ -1,7 +1,7 @@ //--------------------------------------------------------------------------------- // // Little Color Management System -// Copyright (c) 1998-2011 Marti Maria Saguer +// Copyright (c) 1998-2016 Marti Maria Saguer // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), @@ -1393,14 +1393,15 @@ void BuildColorantList(char *Colorant, int nColorant, cmsUInt16Number Out[]) if (nColorant > cmsMAXCHANNELS) nColorant = cmsMAXCHANNELS; - for (j=0; j < nColorant; j++) { + for (j = 0; j < nColorant; j++) { - sprintf(Buff, "%.3f", Out[j] / 65535.0); - strcat(Colorant, Buff); - if (j < nColorant -1) - strcat(Colorant, " "); + snprintf(Buff, 31, "%.3f", Out[j] / 65535.0); + Buff[31] = 0; + strcat(Colorant, Buff); + if (j < nColorant - 1) + strcat(Colorant, " "); - } + } } diff --git a/thirdparty/liblcms2/src/cmssamp.c b/thirdparty/liblcms2/src/cmssamp.c index 70e46916..a9997fa8 100644 --- a/thirdparty/liblcms2/src/cmssamp.c +++ b/thirdparty/liblcms2/src/cmssamp.c @@ -1,7 +1,7 @@ //--------------------------------------------------------------------------------- // // Little Color Management System -// Copyright (c) 1998-2010 Marti Maria Saguer +// Copyright (c) 1998-2016 Marti Maria Saguer // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), @@ -340,28 +340,7 @@ cmsFloat64Number RootOfLeastSquaresFitQuadraticCurve(int n, cmsFloat64Number x[] } -/* -static -cmsBool IsMonotonic(int n, const cmsFloat64Number Table[]) -{ - int i; - cmsFloat64Number last; - last = Table[n-1]; - - for (i = n-2; i >= 0; --i) { - - if (Table[i] > last) - - return FALSE; - else - last = Table[i]; - - } - - return TRUE; -} -*/ // Calculates the black point of a destination profile. // This algorithm comes from the Adobe paper disclosing its black point compensation method. @@ -486,7 +465,6 @@ cmsBool CMSEXPORT cmsDetectDestinationBlackPoint(cmsCIEXYZ* BlackPoint, cmsHPROF // Test for mid range straight (only on relative colorimetric) - NearlyStraightMidrange = TRUE; MinL = outRamp[0]; MaxL = outRamp[255]; if (Intent == INTENT_RELATIVE_COLORIMETRIC) { @@ -502,7 +480,6 @@ cmsBool CMSEXPORT cmsDetectDestinationBlackPoint(cmsCIEXYZ* BlackPoint, cmsHPROF // DestinationBlackPoint shall be the same as initialLab. // Otherwise, the DestinationBlackPoint shall be determined // using curve fitting. - if (NearlyStraightMidrange) { cmsLab2XYZ(NULL, BlackPoint, &InitialLab); @@ -513,15 +490,13 @@ cmsBool CMSEXPORT cmsDetectDestinationBlackPoint(cmsCIEXYZ* BlackPoint, cmsHPROF // curve fitting: The round-trip curve normally looks like a nearly constant section at the black point, - // with a corner and a nearly straight line to the white point. - + // with a corner and a nearly straight line to the white point. for (l=0; l < 256; l++) { yRamp[l] = (outRamp[l] - MinL) / (MaxL - MinL); } // find the black point using the least squares error quadratic curve fitting - if (Intent == INTENT_RELATIVE_COLORIMETRIC) { lo = 0.1; hi = 0.5; diff --git a/thirdparty/liblcms2/src/cmssm.c b/thirdparty/liblcms2/src/cmssm.c index e41cb68b..76c566b4 100644 --- a/thirdparty/liblcms2/src/cmssm.c +++ b/thirdparty/liblcms2/src/cmssm.c @@ -1,7 +1,7 @@ //--------------------------------------------------------------------------------- // // Little Color Management System -// Copyright (c) 1998-2011 Marti Maria Saguer +// Copyright (c) 1998-2016 Marti Maria Saguer // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), @@ -218,7 +218,8 @@ cmsBool ClosestLineToLine(cmsVEC3* r, const cmsLine* line1, const cmsLine* line2 { cmsFloat64Number a, b, c, d, e, D; cmsFloat64Number sc, sN, sD; - cmsFloat64Number tc, tN, tD; + //cmsFloat64Number tc; // left for future use + cmsFloat64Number tN, tD; cmsVEC3 w0; _cmsVEC3minus(&w0, &line1 ->a, &line2 ->a); @@ -286,7 +287,7 @@ cmsBool ClosestLineToLine(cmsVEC3* r, const cmsLine* line1, const cmsLine* line2 } // finally do the division to get sc and tc sc = (fabs(sN) < MATRIX_DET_TOLERANCE ? 0.0 : sN / sD); - tc = (fabs(tN) < MATRIX_DET_TOLERANCE ? 0.0 : tN / tD); + //tc = (fabs(tN) < MATRIX_DET_TOLERANCE ? 0.0 : tN / tD); // left for future use. GetPointOfLine(r, line1, sc); return TRUE; diff --git a/thirdparty/liblcms2/src/cmstypes.c b/thirdparty/liblcms2/src/cmstypes.c index 60c09ef8..010996ef 100644 --- a/thirdparty/liblcms2/src/cmstypes.c +++ b/thirdparty/liblcms2/src/cmstypes.c @@ -1,7 +1,7 @@ //--------------------------------------------------------------------------------- // // Little Color Management System -// Copyright (c) 1998-2014 Marti Maria Saguer +// Copyright (c) 1998-2016 Marti Maria Saguer // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), @@ -951,7 +951,7 @@ cmsBool Type_Text_Description_Write(struct _cms_typehandler_struct* self, cmsIO cmsMLU* mlu = (cmsMLU*) Ptr; char *Text = NULL; wchar_t *Wide = NULL; - cmsUInt32Number len, len_aligned, len_filler_alignment; + cmsUInt32Number len, len_text, len_tag_requirement, len_aligned; cmsBool rc = FALSE; char Filler[68]; @@ -961,17 +961,18 @@ cmsBool Type_Text_Description_Write(struct _cms_typehandler_struct* self, cmsIO // Get the len of string len = cmsMLUgetASCII(mlu, cmsNoLanguage, cmsNoCountry, NULL, 0); - // From ICC3.4: It has been found that textDescriptionType can contain misaligned data + // Specification ICC.1:2001-04 (v2.4.0): It has been found that textDescriptionType can contain misaligned data //(see clause 4.1 for the definition of “aligned”). Because the Unicode language // code and Unicode count immediately follow the ASCII description, their // alignment is not correct if the ASCII count is not a multiple of four. The // ScriptCode code is misaligned when the ASCII count is odd. Profile reading and // writing software must be written carefully in order to handle these alignment // problems. - - // Compute an aligned size - len_aligned = _cmsALIGNLONG(len); - len_filler_alignment = len_aligned - len; + // + // The above last sentence suggest to handle alignment issues in the + // parser. The provided example (Table 69 on Page 60) makes this clear. + // The padding only in the ASCII count is not sufficient for a aligned tag + // size, with the same text size in ASCII and Unicode. // Null strings if (len <= 0) { @@ -992,6 +993,12 @@ cmsBool Type_Text_Description_Write(struct _cms_typehandler_struct* self, cmsIO cmsMLUgetWide(mlu, cmsNoLanguage, cmsNoCountry, Wide, len * sizeof(wchar_t)); } + // Tell the real text len including the null terminator and padding + len_text = strlen(Text) + 1; + // Compute an total tag size requirement + len_tag_requirement = (8+4+len_text+4+4+2*len_text+2+1+67); + len_aligned = _cmsALIGNLONG(len_tag_requirement); + // * cmsUInt32Number count; * Description length // * cmsInt8Number desc[count] * NULL terminated ascii string // * cmsUInt32Number ucLangCode; * UniCode language code @@ -1001,20 +1008,14 @@ cmsBool Type_Text_Description_Write(struct _cms_typehandler_struct* self, cmsIO // * cmsUInt8Number scCount; * ScriptCode count // * cmsInt8Number scDesc[67]; * ScriptCode Description - if (!_cmsWriteUInt32Number(io, len_aligned)) goto Error; - if (!io ->Write(io, len, Text)) goto Error; - if (!io ->Write(io, len_filler_alignment, Filler)) goto Error; + if (!_cmsWriteUInt32Number(io, len_text)) goto Error; + if (!io ->Write(io, len_text, Text)) goto Error; if (!_cmsWriteUInt32Number(io, 0)) goto Error; // ucLanguageCode - // This part is tricky: we need an aligned tag size, and the ScriptCode part - // takes 70 bytes, so we need 2 extra bytes to do the alignment - - if (!_cmsWriteUInt32Number(io, len_aligned+1)) goto Error; - + if (!_cmsWriteUInt32Number(io, len_text)) goto Error; // Note that in some compilers sizeof(cmsUInt16Number) != sizeof(wchar_t) - if (!_cmsWriteWCharArray(io, len, Wide)) goto Error; - if (!_cmsWriteUInt16Array(io, len_filler_alignment+1, (cmsUInt16Number*) Filler)) goto Error; + if (!_cmsWriteWCharArray(io, len_text, Wide)) goto Error; // ScriptCode Code & count (unused) if (!_cmsWriteUInt16Number(io, 0)) goto Error; @@ -1022,6 +1023,10 @@ cmsBool Type_Text_Description_Write(struct _cms_typehandler_struct* self, cmsIO if (!io ->Write(io, 67, Filler)) goto Error; + // possibly add pad at the end of tag + if(len_aligned - len_tag_requirement > 0) + if (!io ->Write(io, len_aligned - len_tag_requirement, Filler)) goto Error; + rc = TRUE; Error: @@ -1503,7 +1508,7 @@ cmsBool Type_MLU_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, cmsMLU* mlu =(cmsMLU*) Ptr; cmsUInt32Number HeaderSize; cmsUInt32Number Len, Offset; - int i; + cmsUInt32Number i; if (Ptr == NULL) { @@ -1689,10 +1694,7 @@ cmsBool Write8bitTables(cmsContext ContextID, cmsIOHANDLER* io, cmsUInt32Number else for (j=0; j < 256; j++) { - if (Tables != NULL) - val = (cmsUInt8Number) FROM_16_TO_8(Tables->TheCurves[i]->Table16[j]); - else - val = (cmsUInt8Number) j; + val = (cmsUInt8Number) FROM_16_TO_8(Tables->TheCurves[i]->Table16[j]); if (!_cmsWriteUInt8Number(io, val)) return FALSE; } @@ -3107,6 +3109,8 @@ void *Type_NamedColor_Read(struct _cms_typehandler_struct* self, cmsIOHANDLER* i memset(Colorant, 0, sizeof(Colorant)); if (io -> Read(io, Root, 32, 1) != 1) return NULL; + Root[32] = 0; // To prevent exploits + if (!_cmsReadUInt16Array(io, 3, PCS)) goto Error; if (!_cmsReadUInt16Array(io, nDeviceCoords, Colorant)) goto Error; @@ -3129,8 +3133,8 @@ static cmsBool Type_NamedColor_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER* io, void* Ptr, cmsUInt32Number nItems) { cmsNAMEDCOLORLIST* NamedColorList = (cmsNAMEDCOLORLIST*) Ptr; - char prefix[32]; // Prefix for each color name - char suffix[32]; // Suffix for each color name + char prefix[33]; // Prefix for each color name + char suffix[33]; // Suffix for each color name int i, nColors; nColors = cmsNamedColorCount(NamedColorList); @@ -3142,7 +3146,7 @@ cmsBool Type_NamedColor_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER strncpy(prefix, (const char*) NamedColorList->Prefix, 32); strncpy(suffix, (const char*) NamedColorList->Suffix, 32); - suffix[31] = prefix[31] = 0; + suffix[32] = prefix[32] = 0; if (!io ->Write(io, 32, prefix)) return FALSE; if (!io ->Write(io, 32, suffix)) return FALSE; @@ -3154,6 +3158,7 @@ cmsBool Type_NamedColor_Write(struct _cms_typehandler_struct* self, cmsIOHANDLER char Root[33]; if (!cmsNamedColorInfo(NamedColorList, i, Root, NULL, NULL, PCS, Colorant)) return 0; + Root[32] = 0; if (!io ->Write(io, 32 , Root)) return FALSE; if (!_cmsWriteUInt16Array(io, 3, PCS)) return FALSE; if (!_cmsWriteUInt16Array(io, NamedColorList ->ColorantCount, Colorant)) return FALSE; @@ -3853,7 +3858,7 @@ cmsBool Type_ViewingConditions_Write(struct _cms_typehandler_struct* self, cmsIO static void* Type_ViewingConditions_Dup(struct _cms_typehandler_struct* self, const void *Ptr, cmsUInt32Number n) { - return _cmsDupMem(self ->ContextID, Ptr, sizeof(cmsScreening)); + return _cmsDupMem(self->ContextID, Ptr, sizeof(cmsICCViewingConditions)); cmsUNUSED_PARAMETER(n); } @@ -5451,8 +5456,9 @@ static _cmsTagLinkedList SupportedTags[] = { { cmsSigScreeningTag, { 1, 1, { cmsSigScreeningType}, NULL }, &SupportedTags[59]}, { cmsSigVcgtTag, { 1, 1, { cmsSigVcgtType}, NULL }, &SupportedTags[60]}, { cmsSigMetaTag, { 1, 1, { cmsSigDictType}, NULL }, &SupportedTags[61]}, - { cmsSigProfileSequenceIdTag, { 1, 1, { cmsSigProfileSequenceIdType}, NULL }, &SupportedTags[62]}, - { cmsSigProfileDescriptionMLTag,{ 1, 1, { cmsSigMultiLocalizedUnicodeType}, NULL}, NULL} + { cmsSigProfileSequenceIdTag, { 1, 1, { cmsSigProfileSequenceIdType}, NULL }, &SupportedTags[62]}, + { cmsSigProfileDescriptionMLTag,{ 1, 1, { cmsSigMultiLocalizedUnicodeType}, NULL}, &SupportedTags[63]}, + { cmsSigArgyllArtsTag, { 9, 1, { cmsSigS15Fixed16ArrayType}, NULL}, NULL} }; diff --git a/thirdparty/liblcms2/src/cmsvirt.c b/thirdparty/liblcms2/src/cmsvirt.c index b324c990..2897adb3 100644 --- a/thirdparty/liblcms2/src/cmsvirt.c +++ b/thirdparty/liblcms2/src/cmsvirt.c @@ -1,7 +1,7 @@ //--------------------------------------------------------------------------------- // // Little Color Management System -// Copyright (c) 1998-2014 Marti Maria Saguer +// Copyright (c) 1998-2016 Marti Maria Saguer // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), @@ -642,7 +642,7 @@ cmsToneCurve* Build_sRGBGamma(cmsContext ContextID) // Create the ICC virtual profile for sRGB space cmsHPROFILE CMSEXPORT cmsCreate_sRGBProfileTHR(cmsContext ContextID) { - cmsCIExyY D65; + cmsCIExyY D65 = { 0.3127, 0.3290, 1.0 }; cmsCIExyYTRIPLE Rec709Primaries = { {0.6400, 0.3300, 1.0}, {0.3000, 0.6000, 1.0}, @@ -651,7 +651,7 @@ cmsHPROFILE CMSEXPORT cmsCreate_sRGBProfileTHR(cmsContext ContextID) cmsToneCurve* Gamma22[3]; cmsHPROFILE hsRGB; - cmsWhitePointFromTemp(&D65, 6504); + // cmsWhitePointFromTemp(&D65, 6504); Gamma22[0] = Gamma22[1] = Gamma22[2] = Build_sRGBGamma(ContextID); if (Gamma22[0] == NULL) return NULL; @@ -679,6 +679,7 @@ typedef struct { cmsFloat64Number Contrast; cmsFloat64Number Hue; cmsFloat64Number Saturation; + cmsBool lAdjustWP; cmsCIEXYZ WPsrc, WPdest; } BCHSWADJUSTS, *LPBCHSWADJUSTS; @@ -708,9 +709,10 @@ int bchswSampler(register const cmsUInt16Number In[], register cmsUInt16Number O cmsLCh2Lab(&LabOut, &LChOut); // Move white point in Lab - - cmsLab2XYZ(&bchsw ->WPsrc, &XYZ, &LabOut); - cmsXYZ2Lab(&bchsw ->WPdest, &LabOut, &XYZ); + if (bchsw->lAdjustWP) { + cmsLab2XYZ(&bchsw->WPsrc, &XYZ, &LabOut); + cmsXYZ2Lab(&bchsw->WPdest, &LabOut, &XYZ); + } // Back to encoded @@ -744,18 +746,23 @@ cmsHPROFILE CMSEXPORT cmsCreateBCHSWabstractProfileTHR(cmsContext ContextID, bchsw.Contrast = Contrast; bchsw.Hue = Hue; bchsw.Saturation = Saturation; + if (TempSrc == TempDest) { - cmsWhitePointFromTemp(&WhitePnt, TempSrc ); - cmsxyY2XYZ(&bchsw.WPsrc, &WhitePnt); - - cmsWhitePointFromTemp(&WhitePnt, TempDest); - cmsxyY2XYZ(&bchsw.WPdest, &WhitePnt); + bchsw.lAdjustWP = FALSE; + } + else { + bchsw.lAdjustWP = TRUE; + cmsWhitePointFromTemp(&WhitePnt, TempSrc); + cmsxyY2XYZ(&bchsw.WPsrc, &WhitePnt); + cmsWhitePointFromTemp(&WhitePnt, TempDest); + cmsxyY2XYZ(&bchsw.WPdest, &WhitePnt); + + } hICC = cmsCreateProfilePlaceholder(ContextID); if (!hICC) // can't allocate return NULL; - cmsSetDeviceClass(hICC, cmsSigAbstractClass); cmsSetColorSpace(hICC, cmsSigLabData); cmsSetPCS(hICC, cmsSigLabData); @@ -988,12 +995,14 @@ typedef struct { } cmsAllowedLUT; +#define cmsSig0 ((cmsTagSignature) 0) + static const cmsAllowedLUT AllowedLUTTypes[] = { - { FALSE, 0, cmsSigLut16Type, 4, { cmsSigMatrixElemType, cmsSigCurveSetElemType, cmsSigCLutElemType, cmsSigCurveSetElemType}}, - { FALSE, 0, cmsSigLut16Type, 3, { cmsSigCurveSetElemType, cmsSigCLutElemType, cmsSigCurveSetElemType}}, - { FALSE, 0, cmsSigLut16Type, 2, { cmsSigCurveSetElemType, cmsSigCLutElemType}}, - { TRUE , 0, cmsSigLutAtoBType, 1, { cmsSigCurveSetElemType }}, + { FALSE, cmsSig0, cmsSigLut16Type, 4, { cmsSigMatrixElemType, cmsSigCurveSetElemType, cmsSigCLutElemType, cmsSigCurveSetElemType } }, + { FALSE, cmsSig0, cmsSigLut16Type, 3, { cmsSigCurveSetElemType, cmsSigCLutElemType, cmsSigCurveSetElemType } }, + { FALSE, cmsSig0, cmsSigLut16Type, 2, { cmsSigCurveSetElemType, cmsSigCLutElemType } }, + { TRUE, cmsSig0, cmsSigLutAtoBType, 1, { cmsSigCurveSetElemType } }, { TRUE , cmsSigAToB0Tag, cmsSigLutAtoBType, 3, { cmsSigCurveSetElemType, cmsSigMatrixElemType, cmsSigCurveSetElemType } }, { TRUE , cmsSigAToB0Tag, cmsSigLutAtoBType, 3, { cmsSigCurveSetElemType, cmsSigCLutElemType, cmsSigCurveSetElemType } }, { TRUE , cmsSigAToB0Tag, cmsSigLutAtoBType, 5, { cmsSigCurveSetElemType, cmsSigCLutElemType, cmsSigCurveSetElemType, cmsSigMatrixElemType, cmsSigCurveSetElemType }}, diff --git a/thirdparty/liblcms2/src/cmswtpnt.c b/thirdparty/liblcms2/src/cmswtpnt.c index e657b132..c6b61258 100644 --- a/thirdparty/liblcms2/src/cmswtpnt.c +++ b/thirdparty/liblcms2/src/cmswtpnt.c @@ -1,7 +1,7 @@ //--------------------------------------------------------------------------------- // // Little Color Management System -// Copyright (c) 1998-2014 Marti Maria Saguer +// Copyright (c) 1998-2016 Marti Maria Saguer // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), diff --git a/thirdparty/liblcms2/src/cmsxform.c b/thirdparty/liblcms2/src/cmsxform.c index 56afede2..0364d062 100644 --- a/thirdparty/liblcms2/src/cmsxform.c +++ b/thirdparty/liblcms2/src/cmsxform.c @@ -1,7 +1,7 @@ //--------------------------------------------------------------------------------- // // Little Color Management System -// Copyright (c) 1998-2014 Marti Maria Saguer +// Copyright (c) 1998-2016 Marti Maria Saguer // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), @@ -179,12 +179,18 @@ void CMSEXPORT cmsDoTransform(cmsHTRANSFORM Transform, { _cmsTRANSFORM* p = (_cmsTRANSFORM*) Transform; + cmsStride stride; - p -> xform(p, InputBuffer, OutputBuffer, Size, Size); + stride.BytesPerLineIn = 0; // Not used + stride.BytesPerLineOut = 0; + stride.BytesPerPlaneIn = Size; + stride.BytesPerPlaneOut = Size; + + p -> xform(p, InputBuffer, OutputBuffer, Size, 1, &stride); } -// Apply transform. +// This is a legacy stride for planar void CMSEXPORT cmsDoTransformStride(cmsHTRANSFORM Transform, const void* InputBuffer, void* OutputBuffer, @@ -192,10 +198,40 @@ void CMSEXPORT cmsDoTransformStride(cmsHTRANSFORM Transform, { _cmsTRANSFORM* p = (_cmsTRANSFORM*) Transform; + cmsStride stride; - p -> xform(p, InputBuffer, OutputBuffer, Size, Stride); + stride.BytesPerLineIn = 0; + stride.BytesPerLineOut = 0; + stride.BytesPerPlaneIn = Stride; + stride.BytesPerPlaneOut = Stride; + + p -> xform(p, InputBuffer, OutputBuffer, Size, 1, &stride); } +// This is the "fast" function for plugins +void CMSEXPORT cmsDoTransformLineStride(cmsHTRANSFORM Transform, + const void* InputBuffer, + void* OutputBuffer, + cmsUInt32Number PixelsPerLine, + cmsUInt32Number LineCount, + cmsUInt32Number BytesPerLineIn, + cmsUInt32Number BytesPerLineOut, + cmsUInt32Number BytesPerPlaneIn, + cmsUInt32Number BytesPerPlaneOut) + +{ + _cmsTRANSFORM* p = (_cmsTRANSFORM*) Transform; + cmsStride stride; + + stride.BytesPerLineIn = BytesPerLineIn; + stride.BytesPerLineOut = BytesPerLineOut; + stride.BytesPerPlaneIn = BytesPerPlaneIn; + stride.BytesPerPlaneOut = BytesPerPlaneOut; + + p->xform(p, InputBuffer, OutputBuffer, PixelsPerLine, LineCount, &stride); +} + + // Transform routines ---------------------------------------------------------------------------------------------------------- @@ -204,49 +240,64 @@ void CMSEXPORT cmsDoTransformStride(cmsHTRANSFORM Transform, static void FloatXFORM(_cmsTRANSFORM* p, const void* in, - void* out, cmsUInt32Number Size, cmsUInt32Number Stride) + void* out, + cmsUInt32Number PixelsPerLine, + cmsUInt32Number LineCount, + const cmsStride* Stride) { cmsUInt8Number* accum; cmsUInt8Number* output; cmsFloat32Number fIn[cmsMAXCHANNELS], fOut[cmsMAXCHANNELS]; cmsFloat32Number OutOfGamut; - cmsUInt32Number i, j; + cmsUInt32Number i, j, c, strideIn, strideOut; - accum = (cmsUInt8Number*) in; - output = (cmsUInt8Number*) out; + _cmsHandleExtraChannels(p, in, out, PixelsPerLine, LineCount, Stride); - for (i=0; i < Size; i++) { + strideIn = 0; + strideOut = 0; - accum = p -> FromInputFloat(p, fIn, accum, Stride); + for (i = 0; i < LineCount; i++) { - // Any gamut chack to do? - if (p ->GamutCheck != NULL) { + accum = (cmsUInt8Number*)in + strideIn; + output = (cmsUInt8Number*)out + strideOut; - // Evaluate gamut marker. - cmsPipelineEvalFloat( fIn, &OutOfGamut, p ->GamutCheck); + for (j = 0; j < PixelsPerLine; j++) { - // Is current color out of gamut? - if (OutOfGamut > 0.0) { + accum = p->FromInputFloat(p, fIn, accum, Stride->BytesPerPlaneIn); - // Certainly, out of gamut - for (j=0; j < cmsMAXCHANNELS; j++) - fOut[j] = -1.0; + // Any gamut chack to do? + if (p->GamutCheck != NULL) { + // Evaluate gamut marker. + cmsPipelineEvalFloat(fIn, &OutOfGamut, p->GamutCheck); + + // Is current color out of gamut? + if (OutOfGamut > 0.0) { + + // Certainly, out of gamut + for (c = 0; c < cmsMAXCHANNELS; c++) + fOut[c] = -1.0; + + } + else { + // No, proceed normally + cmsPipelineEvalFloat(fIn, fOut, p->Lut); + } } else { - // No, proceed normally - cmsPipelineEvalFloat(fIn, fOut, p -> Lut); + + // No gamut check at all + cmsPipelineEvalFloat(fIn, fOut, p->Lut); } - } - else { - // No gamut check at all - cmsPipelineEvalFloat(fIn, fOut, p -> Lut); + + output = p->ToOutputFloat(p, fOut, output, Stride->BytesPerPlaneOut); } - // Back to asked representation - output = p -> ToOutputFloat(p, fOut, output, Stride); + strideIn += Stride->BytesPerLineIn; + strideOut += Stride->BytesPerLineOut; } + } @@ -254,22 +305,34 @@ static void NullFloatXFORM(_cmsTRANSFORM* p, const void* in, void* out, - cmsUInt32Number Size, - cmsUInt32Number Stride) + cmsUInt32Number PixelsPerLine, + cmsUInt32Number LineCount, + const cmsStride* Stride) + { cmsUInt8Number* accum; cmsUInt8Number* output; cmsFloat32Number fIn[cmsMAXCHANNELS]; - cmsUInt32Number i, n; + cmsUInt32Number i, j, strideIn, strideOut; - accum = (cmsUInt8Number*) in; - output = (cmsUInt8Number*) out; - n = Size; + _cmsHandleExtraChannels(p, in, out, PixelsPerLine, LineCount, Stride); - for (i=0; i < n; i++) { + strideIn = 0; + strideOut = 0; - accum = p -> FromInputFloat(p, fIn, accum, Stride); - output = p -> ToOutputFloat(p, fIn, output, Stride); + for (i = 0; i < LineCount; i++) { + + accum = (cmsUInt8Number*) in + strideIn; + output = (cmsUInt8Number*) out + strideOut; + + for (j = 0; j < PixelsPerLine; j++) { + + accum = p->FromInputFloat(p, fIn, accum, Stride ->BytesPerPlaneIn); + output = p->ToOutputFloat(p, fIn, output, Stride->BytesPerPlaneOut); + } + + strideIn += Stride->BytesPerLineIn; + strideOut += Stride->BytesPerLineOut; } } @@ -279,23 +342,36 @@ void NullFloatXFORM(_cmsTRANSFORM* p, static void NullXFORM(_cmsTRANSFORM* p, const void* in, - void* out, cmsUInt32Number Size, - cmsUInt32Number Stride) + void* out, + cmsUInt32Number PixelsPerLine, + cmsUInt32Number LineCount, + const cmsStride* Stride) { cmsUInt8Number* accum; cmsUInt8Number* output; cmsUInt16Number wIn[cmsMAXCHANNELS]; - cmsUInt32Number i, n; + cmsUInt32Number i, j, strideIn, strideOut; - accum = (cmsUInt8Number*) in; - output = (cmsUInt8Number*) out; - n = Size; // Buffer len + _cmsHandleExtraChannels(p, in, out, PixelsPerLine, LineCount, Stride); - for (i=0; i < n; i++) { + strideIn = 0; + strideOut = 0; - accum = p -> FromInput(p, wIn, accum, Stride); - output = p -> ToOutput(p, wIn, output, Stride); + for (i = 0; i < LineCount; i++) { + + accum = (cmsUInt8Number*)in + strideIn; + output = (cmsUInt8Number*)out + strideOut; + + for (j = 0; j < PixelsPerLine; j++) { + + accum = p->FromInput(p, wIn, accum, Stride->BytesPerPlaneIn); + output = p->ToOutput(p, wIn, output, Stride->BytesPerPlaneOut); } + + strideIn += Stride->BytesPerLineIn; + strideOut += Stride->BytesPerLineOut; + } + } @@ -303,23 +379,37 @@ void NullXFORM(_cmsTRANSFORM* p, static void PrecalculatedXFORM(_cmsTRANSFORM* p, const void* in, - void* out, cmsUInt32Number Size, cmsUInt32Number Stride) + void* out, + cmsUInt32Number PixelsPerLine, + cmsUInt32Number LineCount, + const cmsStride* Stride) { register cmsUInt8Number* accum; register cmsUInt8Number* output; cmsUInt16Number wIn[cmsMAXCHANNELS], wOut[cmsMAXCHANNELS]; - cmsUInt32Number i, n; + cmsUInt32Number i, j, strideIn, strideOut; - accum = (cmsUInt8Number*) in; - output = (cmsUInt8Number*) out; - n = Size; + _cmsHandleExtraChannels(p, in, out, PixelsPerLine, LineCount, Stride); - for (i=0; i < n; i++) { + strideIn = 0; + strideOut = 0; - accum = p -> FromInput(p, wIn, accum, Stride); - p ->Lut ->Eval16Fn(wIn, wOut, p -> Lut->Data); - output = p -> ToOutput(p, wOut, output, Stride); + for (i = 0; i < LineCount; i++) { + + accum = (cmsUInt8Number*)in + strideIn; + output = (cmsUInt8Number*)out + strideOut; + + for (j = 0; j < PixelsPerLine; j++) { + + accum = p->FromInput(p, wIn, accum, Stride->BytesPerPlaneIn); + p->Lut->Eval16Fn(wIn, wOut, p->Lut->Data); + output = p->ToOutput(p, wOut, output, Stride->BytesPerPlaneOut); + } + + strideIn += Stride->BytesPerLineIn; + strideOut += Stride->BytesPerLineOut; } + } @@ -350,22 +440,35 @@ void TransformOnePixelWithGamutCheck(_cmsTRANSFORM* p, static void PrecalculatedXFORMGamutCheck(_cmsTRANSFORM* p, const void* in, - void* out, cmsUInt32Number Size, cmsUInt32Number Stride) + void* out, + cmsUInt32Number PixelsPerLine, + cmsUInt32Number LineCount, + const cmsStride* Stride) { cmsUInt8Number* accum; cmsUInt8Number* output; cmsUInt16Number wIn[cmsMAXCHANNELS], wOut[cmsMAXCHANNELS]; - cmsUInt32Number i, n; + cmsUInt32Number i, j, strideIn, strideOut; - accum = (cmsUInt8Number*) in; - output = (cmsUInt8Number*) out; - n = Size; // Buffer len + _cmsHandleExtraChannels(p, in, out, PixelsPerLine, LineCount, Stride); - for (i=0; i < n; i++) { + strideIn = 0; + strideOut = 0; - accum = p -> FromInput(p, wIn, accum, Stride); - TransformOnePixelWithGamutCheck(p, wIn, wOut); - output = p -> ToOutput(p, wOut, output, Stride); + for (i = 0; i < LineCount; i++) { + + accum = (cmsUInt8Number*)in + strideIn; + output = (cmsUInt8Number*)out + strideOut; + + for (j = 0; j < PixelsPerLine; j++) { + + accum = p->FromInput(p, wIn, accum, Stride->BytesPerPlaneIn); + TransformOnePixelWithGamutCheck(p, wIn, wOut); + output = p->ToOutput(p, wOut, output, Stride->BytesPerPlaneOut); + } + + strideIn += Stride->BytesPerLineIn; + strideOut += Stride->BytesPerLineOut; } } @@ -374,94 +477,120 @@ void PrecalculatedXFORMGamutCheck(_cmsTRANSFORM* p, static void CachedXFORM(_cmsTRANSFORM* p, const void* in, - void* out, cmsUInt32Number Size, cmsUInt32Number Stride) + void* out, + cmsUInt32Number PixelsPerLine, + cmsUInt32Number LineCount, + const cmsStride* Stride) { cmsUInt8Number* accum; cmsUInt8Number* output; cmsUInt16Number wIn[cmsMAXCHANNELS], wOut[cmsMAXCHANNELS]; - cmsUInt32Number i, n; _cmsCACHE Cache; + cmsUInt32Number i, j, strideIn, strideOut; - accum = (cmsUInt8Number*) in; - output = (cmsUInt8Number*) out; - n = Size; // Buffer len + _cmsHandleExtraChannels(p, in, out, PixelsPerLine, LineCount, Stride); // Empty buffers for quick memcmp - memset(wIn, 0, sizeof(wIn)); + memset(wIn, 0, sizeof(wIn)); memset(wOut, 0, sizeof(wOut)); // Get copy of zero cache - memcpy(&Cache, &p ->Cache, sizeof(Cache)); + memcpy(&Cache, &p->Cache, sizeof(Cache)); - for (i=0; i < n; i++) { + strideIn = 0; + strideOut = 0; - accum = p -> FromInput(p, wIn, accum, Stride); + for (i = 0; i < LineCount; i++) { - if (memcmp(wIn, Cache.CacheIn, sizeof(Cache.CacheIn)) == 0) { + accum = (cmsUInt8Number*)in + strideIn; + output = (cmsUInt8Number*)out + strideOut; - memcpy(wOut, Cache.CacheOut, sizeof(Cache.CacheOut)); - } - else { + for (j = 0; j < PixelsPerLine; j++) { - p ->Lut ->Eval16Fn(wIn, wOut, p -> Lut->Data); + accum = p->FromInput(p, wIn, accum, Stride->BytesPerPlaneIn); - memcpy(Cache.CacheIn, wIn, sizeof(Cache.CacheIn)); - memcpy(Cache.CacheOut, wOut, sizeof(Cache.CacheOut)); + if (memcmp(wIn, Cache.CacheIn, sizeof(Cache.CacheIn)) == 0) { + + memcpy(wOut, Cache.CacheOut, sizeof(Cache.CacheOut)); + } + else { + p->Lut->Eval16Fn(wIn, wOut, p->Lut->Data); + + memcpy(Cache.CacheIn, wIn, sizeof(Cache.CacheIn)); + memcpy(Cache.CacheOut, wOut, sizeof(Cache.CacheOut)); + } + + output = p->ToOutput(p, wOut, output, Stride->BytesPerPlaneOut); } - output = p -> ToOutput(p, wOut, output, Stride); + strideIn += Stride->BytesPerLineIn; + strideOut += Stride->BytesPerLineOut; } - } - // All those nice features together static void CachedXFORMGamutCheck(_cmsTRANSFORM* p, const void* in, - void* out, cmsUInt32Number Size, cmsUInt32Number Stride) + void* out, + cmsUInt32Number PixelsPerLine, + cmsUInt32Number LineCount, + const cmsStride* Stride) { - cmsUInt8Number* accum; - cmsUInt8Number* output; - cmsUInt16Number wIn[cmsMAXCHANNELS], wOut[cmsMAXCHANNELS]; - cmsUInt32Number i, n; - _cmsCACHE Cache; + cmsUInt8Number* accum; + cmsUInt8Number* output; + cmsUInt16Number wIn[cmsMAXCHANNELS], wOut[cmsMAXCHANNELS]; + _cmsCACHE Cache; + cmsUInt32Number i, j, strideIn, strideOut; - accum = (cmsUInt8Number*) in; - output = (cmsUInt8Number*) out; - n = Size; // Buffer len + _cmsHandleExtraChannels(p, in, out, PixelsPerLine, LineCount, Stride); - // Empty buffers for quick memcmp - memset(wIn, 0, sizeof(cmsUInt16Number) * cmsMAXCHANNELS); - memset(wOut, 0, sizeof(cmsUInt16Number) * cmsMAXCHANNELS); + // Empty buffers for quick memcmp + memset(wIn, 0, sizeof(wIn)); + memset(wOut, 0, sizeof(wOut)); - // Get copy of zero cache - memcpy(&Cache, &p ->Cache, sizeof(Cache)); + // Get copy of zero cache + memcpy(&Cache, &p->Cache, sizeof(Cache)); - for (i=0; i < n; i++) { + strideIn = 0; + strideOut = 0; - accum = p -> FromInput(p, wIn, accum, Stride); + for (i = 0; i < LineCount; i++) { + + accum = (cmsUInt8Number*)in + strideIn; + output = (cmsUInt8Number*)out + strideOut; + + for (j = 0; j < PixelsPerLine; j++) { + + accum = p->FromInput(p, wIn, accum, Stride->BytesPerPlaneIn); if (memcmp(wIn, Cache.CacheIn, sizeof(Cache.CacheIn)) == 0) { - memcpy(wOut, Cache.CacheOut, sizeof(Cache.CacheOut)); + + memcpy(wOut, Cache.CacheOut, sizeof(Cache.CacheOut)); } else { - TransformOnePixelWithGamutCheck(p, wIn, wOut); - memcpy(Cache.CacheIn, wIn, sizeof(Cache.CacheIn)); - memcpy(Cache.CacheOut, wOut, sizeof(Cache.CacheOut)); + TransformOnePixelWithGamutCheck(p, wIn, wOut); + + memcpy(Cache.CacheIn, wIn, sizeof(Cache.CacheIn)); + memcpy(Cache.CacheOut, wOut, sizeof(Cache.CacheOut)); } - output = p -> ToOutput(p, wOut, output, Stride); - } + output = p->ToOutput(p, wOut, output, Stride->BytesPerPlaneOut); + } + strideIn += Stride->BytesPerLineIn; + strideOut += Stride->BytesPerLineOut; + } } -// ------------------------------------------------------------------------------------------------------------- +// Transform plug-ins ---------------------------------------------------------------------------------------------------- // List of used-defined transform factories typedef struct _cmsTransformCollection_st { - _cmsTransformFactory Factory; + _cmsTransform2Factory Factory; + cmsBool OldXform; // Factory returns xform function in the old style + struct _cmsTransformCollection_st *Next; } _cmsTransformCollection; @@ -504,6 +633,7 @@ void DupPluginTransformList(struct _cmsContext_struct* ctx, ctx ->chunks[TransformPlugin] = _cmsSubAllocDup(ctx->MemPool, &newHead, sizeof(_cmsTransformPluginChunkType)); } +// Allocates memory for transform plugin factory void _cmsAllocTransformPluginChunk(struct _cmsContext_struct* ctx, const struct _cmsContext_struct* src) { @@ -518,6 +648,35 @@ void _cmsAllocTransformPluginChunk(struct _cmsContext_struct* ctx, } } +// Adaptor for old versions of plug-in +static +void _cmsTransform2toTransformAdaptor(struct _cmstransform_struct *CMMcargo, + const void* InputBuffer, + void* OutputBuffer, + cmsUInt32Number PixelsPerLine, + cmsUInt32Number LineCount, + const cmsStride* Stride) +{ + + cmsUInt32Number i, strideIn, strideOut; + + _cmsHandleExtraChannels(CMMcargo, InputBuffer, OutputBuffer, PixelsPerLine, LineCount, Stride); + + strideIn = 0; + strideOut = 0; + + for (i = 0; i < LineCount; i++) { + + void *accum = (cmsUInt8Number*)InputBuffer + strideIn; + void *output = (cmsUInt8Number*)OutputBuffer + strideOut; + + CMMcargo->OldXform(CMMcargo, accum, output, PixelsPerLine, Stride->BytesPerPlaneIn); + + strideIn += Stride->BytesPerLineIn; + strideOut += Stride->BytesPerLineOut; + } +} + // Register new ways to transform @@ -535,14 +694,22 @@ cmsBool _cmsRegisterTransformPlugin(cmsContext ContextID, cmsPluginBase* Data) } // Factory callback is required - if (Plugin ->Factory == NULL) return FALSE; + if (Plugin->factories.xform == NULL) return FALSE; fl = (_cmsTransformCollection*) _cmsPluginMalloc(ContextID, sizeof(_cmsTransformCollection)); if (fl == NULL) return FALSE; + // Check for full xform plug-ins previous to 2.8, we would need an adapter in that case + if (Plugin->base.ExpectedVersion < 2080) { + + fl->OldXform = TRUE; + } + else + fl->OldXform = FALSE; + // Copy the parameters - fl ->Factory = Plugin ->Factory; + fl->Factory = Plugin->factories.xform; // Keep linked list fl ->Next = ctx->TransformCollection; @@ -592,46 +759,54 @@ _cmsTRANSFORM* AllocEmptyTransform(cmsContext ContextID, cmsPipeline* lut, _cmsTransformPluginChunkType* ctx = ( _cmsTransformPluginChunkType*) _cmsContextGetClientChunk(ContextID, TransformPlugin); _cmsTransformCollection* Plugin; - // Allocate needed memory - _cmsTRANSFORM* p = (_cmsTRANSFORM*) _cmsMallocZero(ContextID, sizeof(_cmsTRANSFORM)); - if (!p) return NULL; + // Allocate needed memory + _cmsTRANSFORM* p = (_cmsTRANSFORM*)_cmsMallocZero(ContextID, sizeof(_cmsTRANSFORM)); + if (!p) return NULL; - // Store the proposed pipeline - p ->Lut = lut; + // Store the proposed pipeline + p->Lut = lut; - // Let's see if any plug-in want to do the transform by itself - for (Plugin = ctx ->TransformCollection; - Plugin != NULL; - Plugin = Plugin ->Next) { + // Let's see if any plug-in want to do the transform by itself + if (p->Lut != NULL) { - if (Plugin ->Factory(&p->xform, &p->UserData, &p ->FreeUserData, &p ->Lut, InputFormat, OutputFormat, dwFlags)) { - - // Last plugin in the declaration order takes control. We just keep - // the original parameters as a logging. - // Note that cmsFLAGS_CAN_CHANGE_FORMATTER is not set, so by default - // an optimized transform is not reusable. The plug-in can, however, change - // the flags and make it suitable. + for (Plugin = ctx->TransformCollection; + Plugin != NULL; + Plugin = Plugin->Next) { - p ->ContextID = ContextID; - p ->InputFormat = *InputFormat; - p ->OutputFormat = *OutputFormat; - p ->dwOriginalFlags = *dwFlags; - - // Fill the formatters just in case the optimized routine is interested. - // No error is thrown if the formatter doesn't exist. It is up to the optimization - // factory to decide what to do in those cases. - p ->FromInput = _cmsGetFormatter(ContextID, *InputFormat, cmsFormatterInput, CMS_PACK_FLAGS_16BITS).Fmt16; - p ->ToOutput = _cmsGetFormatter(ContextID, *OutputFormat, cmsFormatterOutput, CMS_PACK_FLAGS_16BITS).Fmt16; - p ->FromInputFloat = _cmsGetFormatter(ContextID, *InputFormat, cmsFormatterInput, CMS_PACK_FLAGS_FLOAT).FmtFloat; - p ->ToOutputFloat = _cmsGetFormatter(ContextID, *OutputFormat, cmsFormatterOutput, CMS_PACK_FLAGS_FLOAT).FmtFloat; + if (Plugin->Factory(&p->xform, &p->UserData, &p->FreeUserData, &p->Lut, InputFormat, OutputFormat, dwFlags)) { - return p; - } - } + // Last plugin in the declaration order takes control. We just keep + // the original parameters as a logging. + // Note that cmsFLAGS_CAN_CHANGE_FORMATTER is not set, so by default + // an optimized transform is not reusable. The plug-in can, however, change + // the flags and make it suitable. - // Not suitable for the transform plug-in, let's check the pipeline plug-in - if (p ->Lut != NULL) - _cmsOptimizePipeline(ContextID, &p->Lut, Intent, InputFormat, OutputFormat, dwFlags); + p->ContextID = ContextID; + p->InputFormat = *InputFormat; + p->OutputFormat = *OutputFormat; + p->dwOriginalFlags = *dwFlags; + + // Fill the formatters just in case the optimized routine is interested. + // No error is thrown if the formatter doesn't exist. It is up to the optimization + // factory to decide what to do in those cases. + p->FromInput = _cmsGetFormatter(ContextID, *InputFormat, cmsFormatterInput, CMS_PACK_FLAGS_16BITS).Fmt16; + p->ToOutput = _cmsGetFormatter(ContextID, *OutputFormat, cmsFormatterOutput, CMS_PACK_FLAGS_16BITS).Fmt16; + p->FromInputFloat = _cmsGetFormatter(ContextID, *InputFormat, cmsFormatterInput, CMS_PACK_FLAGS_FLOAT).FmtFloat; + p->ToOutputFloat = _cmsGetFormatter(ContextID, *OutputFormat, cmsFormatterOutput, CMS_PACK_FLAGS_FLOAT).FmtFloat; + + // Save the day? + if (Plugin->OldXform) { + p->OldXform = (_cmsTransformFn) p->xform; + p->xform = _cmsTransform2toTransformAdaptor; + } + + return p; + } + } + + // Not suitable for the transform plug-in, let's check the pipeline plug-in + _cmsOptimizePipeline(ContextID, &p->Lut, Intent, InputFormat, OutputFormat, dwFlags); + } // Check whatever this is a true floating point transform if (_cmsFormatterIsFloat(*InputFormat) && _cmsFormatterIsFloat(*OutputFormat)) { @@ -785,6 +960,22 @@ cmsBool IsProperColorSpace(cmsColorSpaceSignature Check, cmsUInt32Number dwForm // ---------------------------------------------------------------------------------------------------------------- +// Jun-21-2000: Some profiles (those that comes with W2K) comes +// with the media white (media black?) x 100. Add a sanity check + +static +void NormalizeXYZ(cmsCIEXYZ* Dest) +{ + while (Dest -> X > 2. && + Dest -> Y > 2. && + Dest -> Z > 2.) { + + Dest -> X /= 10.; + Dest -> Y /= 10.; + Dest -> Z /= 10.; + } +} + static void SetWhitePoint(cmsCIEXYZ* wtPt, const cmsCIEXYZ* src) { @@ -797,6 +988,8 @@ void SetWhitePoint(cmsCIEXYZ* wtPt, const cmsCIEXYZ* src) wtPt ->X = src->X; wtPt ->Y = src->Y; wtPt ->Z = src->Z; + + NormalizeXYZ(wtPt); } } @@ -1107,7 +1300,6 @@ cmsBool CMSEXPORT cmsChangeBuffersFormat(cmsHTRANSFORM hTransform, cmsUInt32Number InputFormat, cmsUInt32Number OutputFormat) { - _cmsTRANSFORM* xform = (_cmsTRANSFORM*) hTransform; cmsFormatter16 FromInput, ToOutput; diff --git a/thirdparty/liblcms2/src/lcms2.def b/thirdparty/liblcms2/src/lcms2.def deleted file mode 100644 index a1f69c42..00000000 --- a/thirdparty/liblcms2/src/lcms2.def +++ /dev/null @@ -1,341 +0,0 @@ -LIBRARY LCMS2.DLL - -EXPORTS - -_cms15Fixed16toDouble = _cms15Fixed16toDouble -_cms8Fixed8toDouble = _cms8Fixed8toDouble -cmsAdaptToIlluminant = cmsAdaptToIlluminant -_cmsAdjustEndianess16 = _cmsAdjustEndianess16 -_cmsAdjustEndianess32 = _cmsAdjustEndianess32 -_cmsAdjustEndianess64 = _cmsAdjustEndianess64 -cmsAllocNamedColorList = cmsAllocNamedColorList -cmsAllocProfileSequenceDescription = cmsAllocProfileSequenceDescription -cmsAppendNamedColor = cmsAppendNamedColor -cmsBFDdeltaE = cmsBFDdeltaE -cmsBuildGamma = cmsBuildGamma -cmsBuildParametricToneCurve = cmsBuildParametricToneCurve -cmsBuildSegmentedToneCurve = cmsBuildSegmentedToneCurve -cmsBuildTabulatedToneCurve16 = cmsBuildTabulatedToneCurve16 -cmsBuildTabulatedToneCurveFloat = cmsBuildTabulatedToneCurveFloat -_cmsCalloc = _cmsCalloc -cmsChannelsOf = cmsChannelsOf -cmsCIE2000DeltaE = cmsCIE2000DeltaE -cmsCIE94DeltaE = cmsCIE94DeltaE -cmsCIECAM02Done = cmsCIECAM02Done -cmsCIECAM02Forward = cmsCIECAM02Forward -cmsCIECAM02Init = cmsCIECAM02Init -cmsCIECAM02Reverse = cmsCIECAM02Reverse -cmsCloseIOhandler = cmsCloseIOhandler -cmsCloseProfile = cmsCloseProfile -cmsCMCdeltaE = cmsCMCdeltaE -cmsCreate_sRGBProfile = cmsCreate_sRGBProfile -cmsCreate_sRGBProfileTHR = cmsCreate_sRGBProfileTHR -cmsCreateBCHSWabstractProfile = cmsCreateBCHSWabstractProfile -cmsCreateBCHSWabstractProfileTHR = cmsCreateBCHSWabstractProfileTHR -cmsCreateExtendedTransform = cmsCreateExtendedTransform -cmsCreateGrayProfile = cmsCreateGrayProfile -cmsCreateGrayProfileTHR = cmsCreateGrayProfileTHR -cmsCreateInkLimitingDeviceLink = cmsCreateInkLimitingDeviceLink -cmsCreateInkLimitingDeviceLinkTHR = cmsCreateInkLimitingDeviceLinkTHR -cmsCreateLab2Profile = cmsCreateLab2Profile -cmsCreateLab2ProfileTHR = cmsCreateLab2ProfileTHR -cmsCreateLab4Profile = cmsCreateLab4Profile -cmsCreateLab4ProfileTHR = cmsCreateLab4ProfileTHR -cmsCreateLinearizationDeviceLink = cmsCreateLinearizationDeviceLink -cmsCreateLinearizationDeviceLinkTHR = cmsCreateLinearizationDeviceLinkTHR -cmsCreateMultiprofileTransform = cmsCreateMultiprofileTransform -cmsCreateMultiprofileTransformTHR = cmsCreateMultiprofileTransformTHR -cmsCreateNULLProfile = cmsCreateNULLProfile -cmsCreateNULLProfileTHR = cmsCreateNULLProfileTHR -cmsCreateProfilePlaceholder = cmsCreateProfilePlaceholder -cmsCreateProofingTransform = cmsCreateProofingTransform -cmsCreateProofingTransformTHR = cmsCreateProofingTransformTHR -cmsCreateRGBProfile = cmsCreateRGBProfile -cmsCreateRGBProfileTHR = cmsCreateRGBProfileTHR -cmsCreateTransform = cmsCreateTransform -cmsCreateTransformTHR = cmsCreateTransformTHR -cmsCreateXYZProfile = cmsCreateXYZProfile -cmsCreateXYZProfileTHR = cmsCreateXYZProfileTHR -cmsD50_xyY = cmsD50_xyY -cmsD50_XYZ = cmsD50_XYZ -_cmsDecodeDateTimeNumber = _cmsDecodeDateTimeNumber -_cmsDefaultICCintents = _cmsDefaultICCintents -cmsDeleteTransform = cmsDeleteTransform -cmsDeltaE = cmsDeltaE -cmsDetectBlackPoint = cmsDetectBlackPoint -cmsDetectDestinationBlackPoint = cmsDetectDestinationBlackPoint -cmsDetectTAC = cmsDetectTAC -cmsDesaturateLab = cmsDesaturateLab -cmsDoTransform = cmsDoTransform -cmsDoTransformStride = cmsDoTransformStride -_cmsDoubleTo15Fixed16 = _cmsDoubleTo15Fixed16 -_cmsDoubleTo8Fixed8 = _cmsDoubleTo8Fixed8 -_cmsDupMem = _cmsDupMem -cmsDupNamedColorList = cmsDupNamedColorList -cmsDupProfileSequenceDescription = cmsDupProfileSequenceDescription -cmsDupToneCurve = cmsDupToneCurve -_cmsEncodeDateTimeNumber = _cmsEncodeDateTimeNumber -cmsEstimateGamma = cmsEstimateGamma -cmsGetToneCurveEstimatedTableEntries = cmsGetToneCurveEstimatedTableEntries -cmsGetToneCurveEstimatedTable = cmsGetToneCurveEstimatedTable -cmsEvalToneCurve16 = cmsEvalToneCurve16 -cmsEvalToneCurveFloat = cmsEvalToneCurveFloat -cmsfilelength = cmsfilelength -cmsFloat2LabEncoded = cmsFloat2LabEncoded -cmsFloat2LabEncodedV2 = cmsFloat2LabEncodedV2 -cmsFloat2XYZEncoded = cmsFloat2XYZEncoded -cmsFormatterForColorspaceOfProfile = cmsFormatterForColorspaceOfProfile -cmsFormatterForPCSOfProfile = cmsFormatterForPCSOfProfile -_cmsFree = _cmsFree -cmsFreeNamedColorList = cmsFreeNamedColorList -cmsFreeProfileSequenceDescription = cmsFreeProfileSequenceDescription -cmsFreeToneCurve = cmsFreeToneCurve -cmsFreeToneCurveTriple = cmsFreeToneCurveTriple -cmsGBDAlloc = cmsGBDAlloc -cmsGBDFree = cmsGBDFree -cmsGDBAddPoint = cmsGDBAddPoint -cmsGDBCheckPoint = cmsGDBCheckPoint -cmsGDBCompute = cmsGDBCompute -cmsGetAlarmCodes = cmsGetAlarmCodes -cmsGetColorSpace = cmsGetColorSpace -cmsGetDeviceClass = cmsGetDeviceClass -cmsGetEncodedICCversion = cmsGetEncodedICCversion -cmsGetHeaderAttributes = cmsGetHeaderAttributes -cmsGetHeaderCreationDateTime = cmsGetHeaderCreationDateTime -cmsGetHeaderFlags = cmsGetHeaderFlags -cmsGetHeaderManufacturer = cmsGetHeaderManufacturer -cmsGetHeaderModel = cmsGetHeaderModel -cmsGetHeaderProfileID = cmsGetHeaderProfileID -cmsGetHeaderRenderingIntent = cmsGetHeaderRenderingIntent -cmsGetNamedColorList = cmsGetNamedColorList -cmsGetPCS = cmsGetPCS -cmsGetPostScriptColorResource = cmsGetPostScriptColorResource -cmsGetPostScriptCRD = cmsGetPostScriptCRD -cmsGetPostScriptCSA = cmsGetPostScriptCSA -cmsGetProfileInfo = cmsGetProfileInfo -cmsGetProfileInfoASCII = cmsGetProfileInfoASCII -cmsGetProfileContextID = cmsGetProfileContextID -cmsGetProfileVersion = cmsGetProfileVersion -cmsGetSupportedIntents = cmsGetSupportedIntents -cmsGetTagCount = cmsGetTagCount -cmsGetTagSignature = cmsGetTagSignature -cmsGetTransformContextID = cmsGetTransformContextID -_cmsICCcolorSpace = _cmsICCcolorSpace -_cmsIOPrintf = _cmsIOPrintf -cmsIsCLUT = cmsIsCLUT -cmsIsIntentSupported = cmsIsIntentSupported -cmsIsMatrixShaper = cmsIsMatrixShaper -cmsIsTag = cmsIsTag -cmsIsToneCurveDescending = cmsIsToneCurveDescending -cmsIsToneCurveLinear = cmsIsToneCurveLinear -cmsIsToneCurveMonotonic = cmsIsToneCurveMonotonic -cmsIsToneCurveMultisegment = cmsIsToneCurveMultisegment -cmsGetToneCurveParametricType = cmsGetToneCurveParametricType -cmsIT8Alloc = cmsIT8Alloc -cmsIT8DefineDblFormat = cmsIT8DefineDblFormat -cmsIT8EnumDataFormat = cmsIT8EnumDataFormat -cmsIT8EnumProperties = cmsIT8EnumProperties -cmsIT8EnumPropertyMulti = cmsIT8EnumPropertyMulti -cmsIT8Free = cmsIT8Free -cmsIT8GetData = cmsIT8GetData -cmsIT8GetDataDbl = cmsIT8GetDataDbl -cmsIT8FindDataFormat = cmsIT8FindDataFormat -cmsIT8GetDataRowCol = cmsIT8GetDataRowCol -cmsIT8GetDataRowColDbl = cmsIT8GetDataRowColDbl -cmsIT8GetPatchName = cmsIT8GetPatchName -cmsIT8GetPatchByName = cmsIT8GetPatchByName -cmsIT8GetProperty = cmsIT8GetProperty -cmsIT8GetPropertyDbl = cmsIT8GetPropertyDbl -cmsIT8GetPropertyMulti = cmsIT8GetPropertyMulti -cmsIT8GetSheetType = cmsIT8GetSheetType -cmsIT8LoadFromFile = cmsIT8LoadFromFile -cmsIT8LoadFromMem = cmsIT8LoadFromMem -cmsIT8SaveToFile = cmsIT8SaveToFile -cmsIT8SaveToMem = cmsIT8SaveToMem -cmsIT8SetComment = cmsIT8SetComment -cmsIT8SetData = cmsIT8SetData -cmsIT8SetDataDbl = cmsIT8SetDataDbl -cmsIT8SetDataFormat = cmsIT8SetDataFormat -cmsIT8SetDataRowCol = cmsIT8SetDataRowCol -cmsIT8SetDataRowColDbl = cmsIT8SetDataRowColDbl -cmsIT8SetPropertyDbl = cmsIT8SetPropertyDbl -cmsIT8SetPropertyHex = cmsIT8SetPropertyHex -cmsIT8SetPropertyStr = cmsIT8SetPropertyStr -cmsIT8SetPropertyMulti = cmsIT8SetPropertyMulti -cmsIT8SetPropertyUncooked = cmsIT8SetPropertyUncooked -cmsIT8SetSheetType = cmsIT8SetSheetType -cmsIT8SetTable = cmsIT8SetTable -cmsIT8SetTableByLabel = cmsIT8SetTableByLabel -cmsIT8SetIndexColumn = cmsIT8SetIndexColumn -cmsIT8TableCount = cmsIT8TableCount -cmsJoinToneCurve = cmsJoinToneCurve -cmsLab2LCh = cmsLab2LCh -cmsLab2XYZ = cmsLab2XYZ -cmsLabEncoded2Float = cmsLabEncoded2Float -cmsLabEncoded2FloatV2 = cmsLabEncoded2FloatV2 -cmsLCh2Lab = cmsLCh2Lab -_cmsLCMScolorSpace = _cmsLCMScolorSpace -cmsLinkTag = cmsLinkTag -cmsTagLinkedTo = cmsTagLinkedTo -cmsPipelineAlloc = cmsPipelineAlloc -cmsPipelineCat = cmsPipelineCat -cmsPipelineCheckAndRetreiveStages = cmsPipelineCheckAndRetreiveStages -cmsPipelineDup = cmsPipelineDup -cmsPipelineStageCount = cmsPipelineStageCount -cmsPipelineEval16 = cmsPipelineEval16 -cmsPipelineEvalFloat = cmsPipelineEvalFloat -cmsPipelineEvalReverseFloat = cmsPipelineEvalReverseFloat -cmsPipelineFree = cmsPipelineFree -cmsPipelineGetPtrToFirstStage = cmsPipelineGetPtrToFirstStage -cmsPipelineGetPtrToLastStage = cmsPipelineGetPtrToLastStage -cmsPipelineInputChannels = cmsPipelineInputChannels -cmsPipelineInsertStage = cmsPipelineInsertStage -cmsPipelineOutputChannels = cmsPipelineOutputChannels -cmsPipelineSetSaveAs8bitsFlag = cmsPipelineSetSaveAs8bitsFlag -_cmsPipelineSetOptimizationParameters = _cmsPipelineSetOptimizationParameters -cmsPipelineUnlinkStage = cmsPipelineUnlinkStage -_cmsMalloc = _cmsMalloc -_cmsMallocZero = _cmsMallocZero -_cmsMAT3eval = _cmsMAT3eval -_cmsMAT3identity = _cmsMAT3identity -_cmsMAT3inverse = _cmsMAT3inverse -_cmsMAT3isIdentity = _cmsMAT3isIdentity -_cmsMAT3per = _cmsMAT3per -_cmsMAT3solve = _cmsMAT3solve -cmsMD5computeID = cmsMD5computeID -cmsMLUalloc = cmsMLUalloc -cmsMLUdup = cmsMLUdup -cmsMLUfree = cmsMLUfree -cmsMLUgetASCII = cmsMLUgetASCII -cmsMLUgetTranslation = cmsMLUgetTranslation -cmsMLUgetWide = cmsMLUgetWide -cmsMLUsetASCII = cmsMLUsetASCII -cmsMLUsetWide = cmsMLUsetWide -cmsStageAllocCLut16bit = cmsStageAllocCLut16bit -cmsStageAllocCLut16bitGranular = cmsStageAllocCLut16bitGranular -cmsStageAllocCLutFloat = cmsStageAllocCLutFloat -cmsStageAllocCLutFloatGranular = cmsStageAllocCLutFloatGranular -cmsStageAllocToneCurves = cmsStageAllocToneCurves -cmsStageAllocIdentity = cmsStageAllocIdentity -cmsStageAllocMatrix = cmsStageAllocMatrix -_cmsStageAllocPlaceholder = _cmsStageAllocPlaceholder -cmsStageDup = cmsStageDup -cmsStageFree = cmsStageFree -cmsStageNext = cmsStageNext -cmsStageInputChannels = cmsStageInputChannels -cmsStageOutputChannels = cmsStageOutputChannels -cmsStageSampleCLut16bit = cmsStageSampleCLut16bit -cmsStageSampleCLutFloat = cmsStageSampleCLutFloat -cmsStageType = cmsStageType -cmsStageData = cmsStageData -cmsNamedColorCount = cmsNamedColorCount -cmsNamedColorIndex = cmsNamedColorIndex -cmsNamedColorInfo = cmsNamedColorInfo -cmsOpenIOhandlerFromFile = cmsOpenIOhandlerFromFile -cmsOpenIOhandlerFromMem = cmsOpenIOhandlerFromMem -cmsOpenIOhandlerFromNULL = cmsOpenIOhandlerFromNULL -cmsOpenIOhandlerFromStream = cmsOpenIOhandlerFromStream -cmsOpenProfileFromFile = cmsOpenProfileFromFile -cmsOpenProfileFromFileTHR = cmsOpenProfileFromFileTHR -cmsOpenProfileFromIOhandlerTHR = cmsOpenProfileFromIOhandlerTHR -cmsOpenProfileFromMem = cmsOpenProfileFromMem -cmsOpenProfileFromMemTHR = cmsOpenProfileFromMemTHR -cmsOpenProfileFromStream = cmsOpenProfileFromStream -cmsOpenProfileFromStreamTHR = cmsOpenProfileFromStreamTHR -cmsPlugin = cmsPlugin -_cmsRead15Fixed16Number = _cmsRead15Fixed16Number -_cmsReadAlignment = _cmsReadAlignment -_cmsReadFloat32Number = _cmsReadFloat32Number -cmsReadRawTag = cmsReadRawTag -cmsReadTag = cmsReadTag -_cmsReadTypeBase = _cmsReadTypeBase -_cmsReadUInt16Array = _cmsReadUInt16Array -_cmsReadUInt16Number = _cmsReadUInt16Number -_cmsReadUInt32Number = _cmsReadUInt32Number -_cmsReadUInt64Number = _cmsReadUInt64Number -_cmsReadUInt8Number = _cmsReadUInt8Number -_cmsReadXYZNumber = _cmsReadXYZNumber -_cmsRealloc = _cmsRealloc -cmsReverseToneCurve = cmsReverseToneCurve -cmsReverseToneCurveEx = cmsReverseToneCurveEx -cmsSaveProfileToFile = cmsSaveProfileToFile -cmsSaveProfileToIOhandler = cmsSaveProfileToIOhandler -cmsSaveProfileToMem = cmsSaveProfileToMem -cmsSaveProfileToStream = cmsSaveProfileToStream -cmsSetAdaptationState = cmsSetAdaptationState -cmsSetAlarmCodes = cmsSetAlarmCodes -cmsSetColorSpace = cmsSetColorSpace -cmsSetDeviceClass = cmsSetDeviceClass -cmsSetEncodedICCversion = cmsSetEncodedICCversion -cmsSetHeaderAttributes = cmsSetHeaderAttributes -cmsSetHeaderFlags = cmsSetHeaderFlags -cmsSetHeaderManufacturer = cmsSetHeaderManufacturer -cmsSetHeaderModel = cmsSetHeaderModel -cmsSetHeaderProfileID = cmsSetHeaderProfileID -cmsSetHeaderRenderingIntent = cmsSetHeaderRenderingIntent -cmsSetLogErrorHandler = cmsSetLogErrorHandler -cmsSetPCS = cmsSetPCS -cmsSetProfileVersion = cmsSetProfileVersion -cmsSignalError = cmsSignalError -cmsSmoothToneCurve = cmsSmoothToneCurve -cmsstrcasecmp = cmsstrcasecmp -cmsTempFromWhitePoint = cmsTempFromWhitePoint -cmsTransform2DeviceLink = cmsTransform2DeviceLink -cmsUnregisterPlugins = cmsUnregisterPlugins -_cmsVEC3cross = _cmsVEC3cross -_cmsVEC3distance = _cmsVEC3distance -_cmsVEC3dot = _cmsVEC3dot -_cmsVEC3init = _cmsVEC3init -_cmsVEC3length = _cmsVEC3length -_cmsVEC3minus = _cmsVEC3minus -cmsWhitePointFromTemp = cmsWhitePointFromTemp -_cmsWrite15Fixed16Number = _cmsWrite15Fixed16Number -_cmsWriteAlignment = _cmsWriteAlignment -_cmsWriteFloat32Number = _cmsWriteFloat32Number -cmsWriteRawTag = cmsWriteRawTag -cmsWriteTag = cmsWriteTag -_cmsWriteTypeBase = _cmsWriteTypeBase -_cmsWriteUInt16Array = _cmsWriteUInt16Array -_cmsWriteUInt16Number = _cmsWriteUInt16Number -_cmsWriteUInt32Number = _cmsWriteUInt32Number -_cmsWriteUInt64Number = _cmsWriteUInt64Number -_cmsWriteUInt8Number = _cmsWriteUInt8Number -_cmsWriteXYZNumber = _cmsWriteXYZNumber -cmsxyY2XYZ = cmsxyY2XYZ -cmsXYZ2Lab = cmsXYZ2Lab -cmsXYZ2xyY = cmsXYZ2xyY -cmsXYZEncoded2Float = cmsXYZEncoded2Float -cmsSliceSpace16 = cmsSliceSpace16 -cmsSliceSpaceFloat = cmsSliceSpaceFloat -cmsChangeBuffersFormat = cmsChangeBuffersFormat -cmsDictAlloc = cmsDictAlloc -cmsDictFree = cmsDictFree -cmsDictDup = cmsDictDup -cmsDictAddEntry = cmsDictAddEntry -cmsDictGetEntryList = cmsDictGetEntryList -cmsDictNextEntry = cmsDictNextEntry -_cmsGetTransformUserData = _cmsGetTransformUserData -_cmsSetTransformUserData = _cmsSetTransformUserData -_cmsGetTransformFormatters16 = _cmsGetTransformFormatters16 -_cmsGetTransformFormattersFloat = _cmsGetTransformFormattersFloat -cmsGetHeaderCreator = cmsGetHeaderCreator -cmsPluginTHR = cmsPluginTHR -cmsGetPipelineContextID = cmsGetPipelineContextID -cmsGetTransformInputFormat = cmsGetTransformInputFormat -cmsGetTransformOutputFormat = cmsGetTransformOutputFormat -cmsCreateContext = cmsCreateContext -cmsDupContext = cmsDupContext -cmsDeleteContext = cmsDeleteContext -cmsGetContextUserData = cmsGetContextUserData -cmsUnregisterPluginsTHR = cmsUnregisterPluginsTHR -cmsSetAlarmCodesTHR = cmsSetAlarmCodesTHR -cmsGetAlarmCodesTHR = cmsGetAlarmCodesTHR -cmsSetAdaptationStateTHR = cmsSetAdaptationStateTHR -cmsSetLogErrorHandlerTHR = cmsSetLogErrorHandlerTHR -cmsGetSupportedIntentsTHR = cmsGetSupportedIntentsTHR -cmsMLUtranslationsCount = cmsMLUtranslationsCount -cmsMLUtranslationsCodes = cmsMLUtranslationsCodes -_cmsCreateMutex = _cmsCreateMutex -_cmsDestroyMutex = _cmsDestroyMutex -_cmsLockMutex = _cmsLockMutex -_cmsUnlockMutex = _cmsUnlockMutex \ No newline at end of file diff --git a/thirdparty/liblcms2/src/lcms2_internal.h b/thirdparty/liblcms2/src/lcms2_internal.h index 1a648302..e1219036 100644 --- a/thirdparty/liblcms2/src/lcms2_internal.h +++ b/thirdparty/liblcms2/src/lcms2_internal.h @@ -1,7 +1,7 @@ // // Little Color Management System -// Copyright (c) 1998-2014 Marti Maria Saguer +// Copyright (c) 1998-2016 Marti Maria Saguer // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the "Software"), @@ -57,7 +57,15 @@ #define _cmsALIGNLONG(x) (((x)+(sizeof(cmsUInt32Number)-1)) & ~(sizeof(cmsUInt32Number)-1)) // Alignment to memory pointer -#define _cmsALIGNMEM(x) (((x)+(sizeof(void *) - 1)) & ~(sizeof(void *) - 1)) + +// (Ultra)SPARC with gcc requires ptr alignment of 8 bytes +// even though sizeof(void *) is only four: for greatest flexibility +// allow the build to specify ptr alignment. +#ifndef CMS_PTR_ALIGNMENT +# define CMS_PTR_ALIGNMENT sizeof(void *) +#endif + +#define _cmsALIGNMEM(x) (((x)+(CMS_PTR_ALIGNMENT - 1)) & ~(CMS_PTR_ALIGNMENT - 1)) // Maximum encodeable values in floating point #define MAX_ENCODEABLE_XYZ (1.0 + 32767.0/32768.0) @@ -194,11 +202,17 @@ cmsINLINE cmsUInt16Number _cmsQuickSaturateWord(cmsFloat64Number d) // Microsoft felt that it was necessary to keep it set at -1 for an unlocked critical // section, even when they changed the underlying algorithm to be more scalable. // The final parts of the critical section object are unimportant, and can be set -// to zero for their defaults. This yields an initialization macro: +// to zero for their defaults. This yields to an initialization macro: typedef CRITICAL_SECTION _cmsMutex; -#define CMS_MUTEX_INITIALIZER {(void*) -1,-1,0,0,0,0} +#define CMS_MUTEX_INITIALIZER {(PRTL_CRITICAL_SECTION_DEBUG) -1,-1,0,0,0,0} + +#ifdef _MSC_VER +# if (_MSC_VER >= 1800) +# pragma warning(disable : 26135) +# endif +#endif cmsINLINE int _cmsLockPrimitive(_cmsMutex *m) { @@ -284,38 +298,38 @@ typedef int _cmsMutex; cmsINLINE int _cmsLockPrimitive(_cmsMutex *m) { - return 0; cmsUNUSED_PARAMETER(m); + return 0; } cmsINLINE int _cmsUnlockPrimitive(_cmsMutex *m) { - return 0; cmsUNUSED_PARAMETER(m); + return 0; } cmsINLINE int _cmsInitMutexPrimitive(_cmsMutex *m) { - return 0; cmsUNUSED_PARAMETER(m); + return 0; } cmsINLINE int _cmsDestroyMutexPrimitive(_cmsMutex *m) { - return 0; cmsUNUSED_PARAMETER(m); + return 0; } cmsINLINE int _cmsEnterCriticalSectionPrimitive(_cmsMutex *m) { - return 0; cmsUNUSED_PARAMETER(m); + return 0; } cmsINLINE int _cmsLeaveCriticalSectionPrimitive(_cmsMutex *m) { - return 0; cmsUNUSED_PARAMETER(m); + return 0; } #endif @@ -656,8 +670,8 @@ struct _cms_MLU_struct { cmsContext ContextID; // The directory - int AllocatedEntries; - int UsedEntries; + cmsUInt32Number AllocatedEntries; + cmsUInt32Number UsedEntries; _cmsMLUentry* Entries; // Array of pointers to strings allocated in MemPool // The Pool @@ -823,6 +837,8 @@ cmsStage* _cmsStageNormalizeFromLabFloat(cmsContext ContextID); cmsStage* _cmsStageNormalizeFromXyzFloat(cmsContext ContextID); cmsStage* _cmsStageNormalizeToLabFloat(cmsContext ContextID); cmsStage* _cmsStageNormalizeToXyzFloat(cmsContext ContextID); +cmsStage* _cmsStageClipNegatives(cmsContext ContextID, int nChannels); + // For curve set only cmsToneCurve** _cmsStageGetPtrToCurveSet(const cmsStage* mpe); @@ -951,7 +967,7 @@ typedef struct _cmstransform_struct { cmsUInt32Number InputFormat, OutputFormat; // Keep formats for further reference // Points to transform code - _cmsTransformFn xform; + _cmsTransform2Fn xform; // Formatters, cannot be embedded into LUT because cache cmsFormatter16 FromInput; @@ -997,9 +1013,20 @@ typedef struct _cmstransform_struct { void* UserData; _cmsFreeUserDataFn FreeUserData; + // A way to provide backwards compatibility with full xform plugins + _cmsTransformFn OldXform; + } _cmsTRANSFORM; -// -------------------------------------------------------------------------------------------------- +// Copies extra channels from input to output if the original flags in the transform structure +// instructs to do so. This function is called on all standard transform functions. +void _cmsHandleExtraChannels(_cmsTRANSFORM* p, const void* in, + void* out, + cmsUInt32Number PixelsPerLine, + cmsUInt32Number LineCount, + const cmsStride* Stride); + +// ----------------------------------------------------------------------------------------------------------------------- cmsHTRANSFORM _cmsChain2Lab(cmsContext ContextID, cmsUInt32Number nProfiles, From 4f11e89c803fd9a332698bc36338a4be87c6d199 Mon Sep 17 00:00:00 2001 From: mayeut Date: Sat, 30 Apr 2016 18:51:36 +0200 Subject: [PATCH 28/39] Add tests for recent issues Update uclouvain/openjpeg#725 Update uclouvain/openjpeg#726 --- tests/nonregression/md5refs.txt | 1 + tests/nonregression/test_suite.ctest.in | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/tests/nonregression/md5refs.txt b/tests/nonregression/md5refs.txt index 13b03c89..ba3b7ad0 100644 --- a/tests/nonregression/md5refs.txt +++ b/tests/nonregression/md5refs.txt @@ -298,3 +298,4 @@ a190e10941e6145e69816c909f832c1a issue559-eci-091-CIELab.jp2_0.pgx 3fccf3c7ecd3b9de46b94b53a1fa0362 issue559-eci-091-CIELab.jp2_1.pgx f3081c8e9e9a175f223382a7443b480f issue559-eci-091-CIELab.jp2_2.pgx 3bf91c974abc17e520c6a5efa883a58a issue653-zero-unknownbox.jp2.png +8d7a866d29d5c68dc540b0f0011959a5 issue726.png diff --git a/tests/nonregression/test_suite.ctest.in b/tests/nonregression/test_suite.ctest.in index e6e90303..f22a89f5 100644 --- a/tests/nonregression/test_suite.ctest.in +++ b/tests/nonregression/test_suite.ctest.in @@ -552,3 +552,8 @@ opj_decompress -i @INPUT_NR_PATH@/basn6a08.jp2 -o @TEMP_PATH@/basn6a08_tif-9.tif opj_decompress -i @INPUT_NR_PATH@/basn6a08.jp2 -o @TEMP_PATH@/basn6a08_tif-11.tif -p 11S opj_decompress -i @INPUT_NR_PATH@/basn6a08.jp2 -o @TEMP_PATH@/basn6a08_tif-13.tif -p 13S opj_decompress -i @INPUT_NR_PATH@/basn6a08.jp2 -o @TEMP_PATH@/basn6a08_tif-15.tif -p 15S + +# issue 725 +!opj_decompress -i @INPUT_NR_PATH@/issue725.jp2 -o @TEMP_PATH@/issue725.png +# issue 726 +opj_decompress -i @INPUT_NR_PATH@/issue726.j2k -o @TEMP_PATH@/issue726.png From b51d088267cb88eb95555ea047755120e36c511b Mon Sep 17 00:00:00 2001 From: Matthieu Darbois Date: Sun, 1 May 2016 18:05:46 +0200 Subject: [PATCH 29/39] Update to libtiff-4.0.6 (#764) --- thirdparty/libtiff/CMakeLists.txt | 53 +++- thirdparty/libtiff/libport.h | 60 +++++ thirdparty/libtiff/snprintf.c | 38 +++ thirdparty/libtiff/tif_codec.c | 5 +- thirdparty/libtiff/tif_config.h.cmake.in | 309 +++++++---------------- thirdparty/libtiff/tif_config.h.in | 9 + thirdparty/libtiff/tif_dirread.c | 22 +- thirdparty/libtiff/tif_fax3.c | 5 +- thirdparty/libtiff/tif_jpeg.c | 30 ++- thirdparty/libtiff/tif_lzw.c | 21 +- thirdparty/libtiff/tif_predict.c | 144 ++++++----- thirdparty/libtiff/tif_print.c | 8 +- thirdparty/libtiff/tif_unix.c | 57 ++++- thirdparty/libtiff/tif_win32.c | 33 ++- thirdparty/libtiff/tiffconf.h.cmake.in | 33 +++ thirdparty/libtiff/tiffiop.h | 55 +++- thirdparty/libtiff/tiffvers.h | 4 +- 17 files changed, 538 insertions(+), 348 deletions(-) create mode 100644 thirdparty/libtiff/libport.h create mode 100644 thirdparty/libtiff/snprintf.c diff --git a/thirdparty/libtiff/CMakeLists.txt b/thirdparty/libtiff/CMakeLists.txt index efc86141..63a8f7e8 100644 --- a/thirdparty/libtiff/CMakeLists.txt +++ b/thirdparty/libtiff/CMakeLists.txt @@ -55,6 +55,11 @@ SET(TARGET_FILES IF(UNIX) SET(TARGET_FILES ${TARGET_FILES} tif_unix.c) + # Large file support + # This might not catch every possibility catered for by + # AC_SYS_LARGEFILE. + add_definitions(-D_FILE_OFFSET_BITS=64) + set(_FILE_OFFSET_BITS 64) ELSE() SET(TARGET_FILES ${TARGET_FILES} tif_win32.c) ENDIF() @@ -70,6 +75,7 @@ endif() include(CheckIncludeFiles) include(CheckSymbolExists) include(CheckFunctionExists) +include(CheckCSourceCompiles) CHECK_INCLUDE_FILES("zlib.h" HAVE_ZLIB_H) CHECK_INCLUDE_FILES("jpeglib.h" HAVE_JPEGLIB_H) @@ -135,6 +141,19 @@ CHECK_FUNCTION_EXISTS(strtol HAVE_STRTOL) CHECK_FUNCTION_EXISTS(strtoul HAVE_STRTOUL) CHECK_FUNCTION_EXISTS(strtoull HAVE_STRTOULL) +# May be inlined, so check it compiles: +check_c_source_compiles(" +#include +int main(void) { + char buf[10]; + snprintf(buf, 10, \"Test %d\", 1); + return 0; +}" HAVE_SNPRINTF) + +if(NOT HAVE_SNPRINTF) + SET(TARGET_FILES ${TARGET_FILES} snprintf.c) +endif() + include(CheckTypeSize) CHECK_TYPE_SIZE("signed int" SIZEOF_SIGNED_INT) @@ -162,20 +181,23 @@ if(HAVE_STDINT_H) if(NOT HAVE_SSIZE_T) if("${CMAKE_SIZEOF_VOID_P}" EQUAL 8) set(TIFF_SSIZE_T int64_t) + set(TIFF_SSIZE_FORMAT "%lld") + set(TIFF_SIZE_FORMAT "%llu") elseif("${CMAKE_SIZEOF_VOID_P}" EQUAL 4) set(TIFF_SSIZE_T int32_t) + set(TIFF_SSIZE_FORMAT "%d") + set(TIFF_SIZE_FORMAT "%u") else() message(FATAL_ERROR "unknown ssize_t") endif() else() set(TIFF_SSIZE_T ssize_t) endif() - set(TIFF_INT32_FORMAT "\"%d\"") - set(TIFF_UINT32_FORMAT "\"%u\"") - set(TIFF_INT64_FORMAT "\"%ld\"") - set(TIFF_UINT64_FORMAT "\"%lu\"") - set(TIFF_PTRDIFF_FORMAT "\"%ld\"") - set(TIFF_SSIZE_FORMAT "\"%ld\"") + set(TIFF_INT32_FORMAT "%d") + set(TIFF_UINT32_FORMAT "%u") + set(TIFF_INT64_FORMAT "%lld") + set(TIFF_UINT64_FORMAT "%llu") + set(TIFF_PTRDIFF_FORMAT "%ld") else() set(TIFF_INT8_T "signed __int8") set(TIFF_INT16_T "signed __int16") @@ -189,24 +211,27 @@ else() if(NOT HAVE_SSIZE_T) if("${CMAKE_SIZEOF_VOID_P}" EQUAL 8) set(TIFF_SSIZE_T "signed __int64") + set(TIFF_SSIZE_FORMAT "%lld") + set(TIFF_SIZE_FORMAT "%llu") elseif("${CMAKE_SIZEOF_VOID_P}" EQUAL 4) set(TIFF_SSIZE_T "signed __int32") + set(TIFF_SSIZE_FORMAT "%d") + set(TIFF_SIZE_FORMAT "%u") else() message(FATAL_ERROR "unknown ssize_t") endif() else() set(TIFF_SSIZE_T ssize_t) endif() - set(TIFF_INT32_FORMAT "\"%d\"") - set(TIFF_UINT32_FORMAT "\"%u\"") - set(TIFF_INT64_FORMAT "\"%ld\"") - set(TIFF_UINT64_FORMAT "\"%lu\"") - set(TIFF_PTRDIFF_FORMAT "\"%ld\"") - set(TIFF_SSIZE_FORMAT "\"%ld\"") + set(TIFF_INT32_FORMAT "%d") + set(TIFF_UINT32_FORMAT "%u") + set(TIFF_INT64_FORMAT "%lld") + set(TIFF_UINT64_FORMAT "%llu") + set(TIFF_PTRDIFF_FORMAT "%ld") endif() # -set(VERSION "\"4.0.1\"") +set(VERSION "\"4.0.6\"") set(PACKAGE_VERSION ${VERSION}) set(PACKAGE "\"tiff\"") @@ -232,7 +257,7 @@ FOREACH(KEYWORD "inline" "__inline__" "__inline") COMPILE_DEFINITIONS "-Dinline=${KEYWORD}") IF(C_HAS_${KEYWORD}) SET(C_INLINE TRUE) - SET(INLINE "${KEYWORD}") + SET(INLINE_KEYWORD "${KEYWORD}") ENDIF(C_HAS_${KEYWORD}) ENDIF(NOT DEFINED C_INLINE) ENDFOREACH(KEYWORD) diff --git a/thirdparty/libtiff/libport.h b/thirdparty/libtiff/libport.h new file mode 100644 index 00000000..d9b04215 --- /dev/null +++ b/thirdparty/libtiff/libport.h @@ -0,0 +1,60 @@ +/* $Id: libport.h,v 1.5 2015-08-19 02:31:04 bfriesen Exp $ */ + +/* + * 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 0 +unsigned long strtoul(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_ */ diff --git a/thirdparty/libtiff/snprintf.c b/thirdparty/libtiff/snprintf.c new file mode 100644 index 00000000..1c4ac087 --- /dev/null +++ b/thirdparty/libtiff/snprintf.c @@ -0,0 +1,38 @@ +/** + * Workaround for lack of snprintf(3) in Visual Studio. See + * http://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010/8712996#8712996 + * It's a trivial wrapper around the builtin _vsnprintf_s and + * _vscprintf functions. + */ + +#ifdef _MSC_VER + +#include +#include +#include "libport.h" + +int _TIFF_vsnprintf_f(char* str, size_t size, const char* format, va_list ap) +{ + int count = -1; + + if (size != 0) + count = _vsnprintf_s(str, size, _TRUNCATE, format, ap); + if (count == -1) + count = _vscprintf(format, ap); + + return count; +} + +int _TIFF_snprintf_f(char* str, size_t size, const char* format, ...) +{ + int count; + va_list ap; + + va_start(ap, format); + count = vsnprintf(str, size, format, ap); + va_end(ap); + + return count; +} + +#endif // _MSC_VER diff --git a/thirdparty/libtiff/tif_codec.c b/thirdparty/libtiff/tif_codec.c index 703e87d5..7cb46f63 100644 --- a/thirdparty/libtiff/tif_codec.c +++ b/thirdparty/libtiff/tif_codec.c @@ -1,4 +1,4 @@ -/* $Id: tif_codec.c,v 1.16 2013-05-02 14:44:29 tgl Exp $ */ +/* $Id: tif_codec.c,v 1.17 2015-08-19 02:31:04 bfriesen Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -108,8 +108,7 @@ _notConfigured(TIFF* tif) const TIFFCodec* c = TIFFFindCODEC(tif->tif_dir.td_compression); char compression_code[20]; - snprintf(compression_code, sizeof(compression_code), "%d", - tif->tif_dir.td_compression ); + sprintf(compression_code, "%d",tif->tif_dir.td_compression ); TIFFErrorExt(tif->tif_clientdata, tif->tif_name, "%s compression support is not configured", c ? c->name : compression_code ); diff --git a/thirdparty/libtiff/tif_config.h.cmake.in b/thirdparty/libtiff/tif_config.h.cmake.in index a556f3c4..9ddc3498 100644 --- a/thirdparty/libtiff/tif_config.h.cmake.in +++ b/thirdparty/libtiff/tif_config.h.cmake.in @@ -1,357 +1,237 @@ -/* libtiff/tif_config.h.in. Generated from configure.ac by autoheader. */ - -/* Define if building universal (internal helper macro) */ -#cmakedefine AC_APPLE_UNIVERSAL_BUILD +/* libtiff/tif_config.h.cmake.in. Not generated, but originated from autoheader. */ +/* This file must be kept up-to-date with needed substitutions from libtiff/tif_config.h.in. */ /* Support CCITT Group 3 & 4 algorithms */ -#cmakedefine CCITT_SUPPORT @CCITT_SUPPORT@ +#cmakedefine CCITT_SUPPORT 1 /* Pick up YCbCr subsampling info from the JPEG data stream to support files lacking the tag (default enabled). */ -#cmakedefine CHECK_JPEG_YCBCR_SUBSAMPLING @CHECK_JPEG_YCBCR_SUBSAMPLING@ +#cmakedefine CHECK_JPEG_YCBCR_SUBSAMPLING 1 /* enable partial strip reading for large strips (experimental) */ -#cmakedefine CHUNKY_STRIP_READ_SUPPORT +#cmakedefine CHUNKY_STRIP_READ_SUPPORT 1 /* Support C++ stream API (requires C++ compiler) */ -#cmakedefine CXX_SUPPORT @CXX_SUPPORT@ - -/* Treat extra sample as alpha (default enabled). The RGBA interface will - treat a fourth sample with no EXTRASAMPLE_ value as being ASSOCALPHA. Many - packages produce RGBA files but don't mark the alpha properly. */ -#cmakedefine DEFAULT_EXTRASAMPLE_AS_ALPHA @DEFAULT_EXTRASAMPLE_AS_ALPHA@ +#cmakedefine CXX_SUPPORT 1 /* enable deferred strip/tile offset/size loading (experimental) */ -#cmakedefine DEFER_STRILE_LOAD @DEFER_STRILE_LOAD@ +#cmakedefine DEFER_STRILE_LOAD 1 /* Define to 1 if you have the header file. */ -#cmakedefine HAVE_ASSERT_H @HAVE_ASSERT_H@ +#cmakedefine HAVE_ASSERT_H 1 /* Define to 1 if you have the header file. */ -#cmakedefine HAVE_DLFCN_H @HAVE_DLFCN_H@ +#cmakedefine HAVE_DLFCN_H 1 /* Define to 1 if you have the header file. */ -#cmakedefine HAVE_FCNTL_H @HAVE_FCNTL_H@ +#cmakedefine HAVE_FCNTL_H 1 /* Define to 1 if you have the `floor' function. */ -#cmakedefine HAVE_FLOOR @HAVE_FLOOR@ +#cmakedefine HAVE_FLOOR 1 /* Define to 1 if you have the `getopt' function. */ -#cmakedefine HAVE_GETOPT @HAVE_GETOPT@ +#cmakedefine HAVE_GETOPT 1 /* Define to 1 if you have the header file. */ -#cmakedefine HAVE_GLUT_GLUT_H @HAVE_GLUT_GLUT_H@ +#cmakedefine HAVE_GLUT_GLUT_H 1 /* Define to 1 if you have the header file. */ -#cmakedefine HAVE_GL_GLUT_H @HAVE_GL_GLUT_H@ +#cmakedefine HAVE_GL_GLUT_H 1 /* Define to 1 if you have the header file. */ -#cmakedefine HAVE_GL_GLU_H @HAVE_GL_GLU_H@ +#cmakedefine HAVE_GL_GLU_H 1 /* Define to 1 if you have the header file. */ -#cmakedefine HAVE_GL_GL_H @HAVE_GL_GL_H@ - -/* Define as 0 or 1 according to the floating point format suported by the - machine */ -#define HAVE_IEEEFP 1 - -/* Define to 1 if the system has the type `int16'. */ -#cmakedefine HAVE_INT16 - -/* Define to 1 if the system has the type `int32'. */ -#cmakedefine HAVE_INT32 - -/* Define to 1 if the system has the type `int8'. */ -#cmakedefine HAVE_INT8 +#cmakedefine HAVE_GL_GL_H 1 /* Define to 1 if you have the header file. */ -#cmakedefine HAVE_INTTYPES_H @HAVE_INTTYPES_H@ +#cmakedefine HAVE_INTTYPES_H 1 /* Define to 1 if you have the header file. */ -#cmakedefine HAVE_IO_H @HAVE_IO_H@ +#cmakedefine HAVE_IO_H 1 /* Define to 1 if you have the `isascii' function. */ -#cmakedefine HAVE_ISASCII @HAVE_ISASCII@ +#cmakedefine HAVE_ISASCII 1 /* Define to 1 if you have the `jbg_newlen' function. */ -#cmakedefine HAVE_JBG_NEWLEN @HAVE_JBG_NEWLEN@ +#cmakedefine HAVE_JBG_NEWLEN 1 /* Define to 1 if you have the `lfind' function. */ -#cmakedefine HAVE_LFIND @HAVE_LFIND@ - -/* Define to 1 if you have the `c' library (-lc). */ -#cmakedefine HAVE_LIBC @HAVE_LIBC@ - -/* Define to 1 if you have the `m' library (-lm). */ -#cmakedefine HAVE_LIBM @HAVE_LIBM@ +#cmakedefine HAVE_LFIND 1 /* Define to 1 if you have the header file. */ -#cmakedefine HAVE_LIMITS_H @HAVE_LIMITS_H@ +#cmakedefine HAVE_LIMITS_H 1 /* Define to 1 if you have the header file. */ -#cmakedefine HAVE_MALLOC_H @HAVE_MALLOC_H@ +#cmakedefine HAVE_MALLOC_H 1 /* Define to 1 if you have the `memmove' function. */ -#cmakedefine HAVE_MEMMOVE @HAVE_MEMMOVE@ +#cmakedefine HAVE_MEMMOVE 1 /* Define to 1 if you have the header file. */ -#cmakedefine HAVE_MEMORY_H @HAVE_MEMORY_H@ +#cmakedefine HAVE_MEMORY_H 1 /* Define to 1 if you have the `memset' function. */ -#cmakedefine HAVE_MEMSET @HAVE_MEMSET@ +#cmakedefine HAVE_MEMSET 1 /* Define to 1 if you have the `mmap' function. */ -#cmakedefine HAVE_MMAP @HAVE_MMAP@ +#cmakedefine HAVE_MMAP 1 /* Define to 1 if you have the header file. */ -#cmakedefine HAVE_OPENGL_GLU_H @HAVE_OPENGL_GLU_H@ +#cmakedefine HAVE_OPENGL_GLU_H 1 /* Define to 1 if you have the header file. */ -#cmakedefine HAVE_OPENGL_GL_H @HAVE_OPENGL_GL_H@ +#cmakedefine HAVE_OPENGL_GL_H 1 /* Define to 1 if you have the `pow' function. */ -#cmakedefine HAVE_POW @HAVE_POW@ - -/* Define if you have POSIX threads libraries and header files. */ -#cmakedefine HAVE_PTHREAD +#cmakedefine HAVE_POW 1 /* Define to 1 if you have the header file. */ -#cmakedefine HAVE_SEARCH_H @HAVE_SEARCH_H@ +#cmakedefine HAVE_SEARCH_H 1 /* Define to 1 if you have the `setmode' function. */ -#cmakedefine HAVE_SETMODE @HAVE_SETMODE@ +#cmakedefine HAVE_SETMODE 1 + +/* 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 @HAVE_SQRT@ +#cmakedefine HAVE_SQRT 1 /* Define to 1 if you have the header file. */ -#cmakedefine HAVE_STDINT_H @HAVE_STDINT_H@ - -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_STDLIB_H @HAVE_STDLIB_H@ +#cmakedefine HAVE_STDINT_H 1 /* Define to 1 if you have the `strcasecmp' function. */ -#cmakedefine HAVE_STRCASECMP @HAVE_STRCASECMP@ +#cmakedefine HAVE_STRCASECMP 1 /* Define to 1 if you have the `strchr' function. */ -#cmakedefine HAVE_STRCHR @HAVE_STRCHR@ +#cmakedefine HAVE_STRCHR 1 /* Define to 1 if you have the header file. */ -#cmakedefine HAVE_STRINGS_H @HAVE_STRINGS_H@ +#cmakedefine HAVE_STRINGS_H 1 /* Define to 1 if you have the header file. */ -#cmakedefine HAVE_STRING_H @HAVE_STRING_H@ +#cmakedefine HAVE_STRING_H 1 /* Define to 1 if you have the `strrchr' function. */ -#cmakedefine HAVE_STRRCHR @HAVE_STRRCHR@ +#cmakedefine HAVE_STRRCHR 1 /* Define to 1 if you have the `strstr' function. */ -#cmakedefine HAVE_STRSTR @HAVE_STRSTR@ +#cmakedefine HAVE_STRSTR 1 /* Define to 1 if you have the `strtol' function. */ -#cmakedefine HAVE_STRTOL @HAVE_STRTOL@ +#cmakedefine HAVE_STRTOL 1 /* Define to 1 if you have the `strtoul' function. */ -#cmakedefine HAVE_STRTOUL @HAVE_STRTOUL@ +#cmakedefine HAVE_STRTOUL 1 /* Define to 1 if you have the `strtoull' function. */ -#cmakedefine HAVE_STRTOULL @HAVE_STRTOULL@ - -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_SYS_STAT_H @HAVE_SYS_STAT_H@ +#cmakedefine HAVE_STRTOULL 1 /* Define to 1 if you have the header file. */ -#cmakedefine HAVE_SYS_TIME_H @HAVE_SYS_TIME_H@ +#cmakedefine HAVE_SYS_TIME_H 1 /* Define to 1 if you have the header file. */ -#cmakedefine HAVE_SYS_TYPES_H @HAVE_SYS_TYPES_H@ +#cmakedefine HAVE_SYS_TYPES_H 1 /* Define to 1 if you have the header file. */ -#cmakedefine HAVE_UNISTD_H @HAVE_UNISTD_H@ - -/* Use nonstandard varargs form for the GLU tesselator callback */ -#cmakedefine HAVE_VARARGS_GLU_TESSCB - -/* Define to 1 if you have the header file. */ -#cmakedefine HAVE_WINDOWS_H @HAVE_WINDOWS_H@ - -/* Native cpu byte order: 1 if big-endian (Motorola) or 0 if little-endian - (Intel) */ -#define HOST_BIGENDIAN @HOST_BIGENDIAN@ - -/* Set the native cpu bit order (FILLORDER_LSB2MSB or FILLORDER_MSB2LSB) */ -#cmakedefine HOST_FILLORDER @HOST_FILLORDER@ - -/* Support ISO JBIG compression (requires JBIG-KIT library) */ -#cmakedefine JBIG_SUPPORT +#cmakedefine HAVE_UNISTD_H 1 /* 8/12 bit libjpeg dual mode enabled */ -#cmakedefine JPEG_DUAL_MODE_8_12 - -/* Support JPEG compression (requires IJG JPEG library) */ -#cmakedefine JPEG_SUPPORT @JPEG_SUPPORT@ +#cmakedefine JPEG_DUAL_MODE_8_12 1 /* 12bit libjpeg primary include file with path */ -#cmakedefine LIBJPEG_12_PATH - -/* Support LogLuv high dynamic range encoding */ -#define LOGLUV_SUPPORT 1 - -/* Define to the sub-directory in which libtool stores uninstalled libraries. - */ -#undef LT_OBJDIR +#define LIBJPEG_12_PATH @LIBJPEG_12_PATH@ /* Support LZMA2 compression */ -#cmakedefine LZMA_SUPPORT @LZMA_SUPPORT@ - -/* Support LZW algorithm */ -#define LZW_SUPPORT 1 - -/* Support Microsoft Document Imaging format */ -#cmakedefine MDI_SUPPORT @MDI_SUPPORT@ - -/* Support NeXT 2-bit RLE algorithm */ -#define NEXT_SUPPORT 1 - -/* Define to 1 if your C compiler doesn't accept -c and -o together. */ -#cmakedefine NO_MINUS_C_MINUS_O @NO_MINUS_C_MINUS_O@ - -/* Support Old JPEG compresson (read-only) */ -#cmakedefine OJPEG_SUPPORT +#cmakedefine LZMA_SUPPORT 1 /* Name of package */ -#cmakedefine PACKAGE @PACKAGE@ +#define PACKAGE "@PACKAGE_NAME@" /* Define to the address where bug reports for this package should be sent. */ -#cmakedefine PACKAGE_BUGREPORT +#define PACKAGE_BUGREPORT "@PACKAGE_BUGREPORT@" /* Define to the full name of this package. */ -#cmakedefine PACKAGE_NAME +#define PACKAGE_NAME "@PACKAGE_NAME@" /* Define to the full name and version of this package. */ -#cmakedefine PACKAGE_STRING +#define PACKAGE_STRING "@PACKAGE_STRING@" /* Define to the one symbol short name of this package. */ -#cmakedefine PACKAGE_TARNAME +#define PACKAGE_TARNAME "@PACKAGE_TARNAME@" /* Define to the home page for this package. */ -#undef PACKAGE_URL +#define PACKAGE_URL "@PACKAGE_URL@" /* Define to the version of this package. */ -#cmakedefine PACKAGE_VERSION @PACKAGE_VERSION@ - -/* Support Macintosh PackBits algorithm */ -#define PACKBITS_SUPPORT 1 - -/* Support Pixar log-format algorithm (requires Zlib) */ -#cmakedefine PIXARLOG_SUPPORT @PIXARLOG_SUPPORT@ - -/* Define to necessary symbol if this constant uses a non-standard name on - your system. */ -#cmakedefine PTHREAD_CREATE_JOINABLE +#define PACKAGE_VERSION "@PACKAGE_VERSION@" /* The size of `signed int', as computed by sizeof. */ -#cmakedefine SIZEOF_SIGNED_INT @SIZEOF_SIGNED_INT@ +#define SIZEOF_SIGNED_INT @SIZEOF_SIGNED_INT@ /* The size of `signed long', as computed by sizeof. */ -#cmakedefine SIZEOF_SIGNED_LONG @SIZEOF_SIGNED_LONG@ +#define SIZEOF_SIGNED_LONG @SIZEOF_SIGNED_LONG@ /* The size of `signed long long', as computed by sizeof. */ -#cmakedefine SIZEOF_SIGNED_LONG_LONG @SIZEOF_SIGNED_LONG_LONG@ +#define SIZEOF_SIGNED_LONG_LONG @SIZEOF_SIGNED_LONG_LONG@ /* The size of `signed short', as computed by sizeof. */ -#cmakedefine SIZEOF_SIGNED_SHORT @SIZEOF_SIGNED_SHORT@ +#define SIZEOF_SIGNED_SHORT @SIZEOF_SIGNED_SHORT@ /* The size of `unsigned char *', as computed by sizeof. */ -#cmakedefine SIZEOF_UNSIGNED_CHAR_P @SIZEOF_UNSIGNED_CHAR_P@ +#define SIZEOF_UNSIGNED_CHAR_P @SIZEOF_UNSIGNED_CHAR_P@ /* The size of `unsigned int', as computed by sizeof. */ -#cmakedefine SIZEOF_UNSIGNED_INT @SIZEOF_UNSIGNED_INT@ +#define SIZEOF_UNSIGNED_INT @SIZEOF_UNSIGNED_INT@ /* The size of `unsigned long', as computed by sizeof. */ -#cmakedefine SIZEOF_UNSIGNED_LONG @SIZEOF_UNSIGNED_LONG@ +#define SIZEOF_UNSIGNED_LONG @SIZEOF_UNSIGNED_LONG@ /* The size of `unsigned long long', as computed by sizeof. */ -#cmakedefine SIZEOF_UNSIGNED_LONG_LONG @SIZEOF_UNSIGNED_LONG_LONG@ +#define SIZEOF_UNSIGNED_LONG_LONG @SIZEOF_UNSIGNED_LONG_LONG@ /* The size of `unsigned short', as computed by sizeof. */ -#cmakedefine SIZEOF_UNSIGNED_SHORT @SIZEOF_UNSIGNED_SHORT@ - -/* Define to 1 if you have the ANSI C header files. */ -#cmakedefine STDC_HEADERS @STDC_HEADERS@ - -/* Support strip chopping (whether or not to convert single-strip uncompressed - images to mutiple strips of specified size to reduce memory usage) */ -#cmakedefine STRIPCHOP_DEFAULT @STRIPCHOP_DEFAULT@ +#define SIZEOF_UNSIGNED_SHORT @SIZEOF_UNSIGNED_SHORT@ /* Default size of the strip in bytes (when strip chopping enabled) */ -#cmakedefine STRIP_SIZE_DEFAULT @STRIP_SIZE_DEFAULT@ - -/* Enable SubIFD tag (330) support */ -#cmakedefine SUBIFD_SUPPORT @SUBIFD_SUPPORT@ - -/* Support ThunderScan 4-bit RLE algorithm */ -#cmakedefine THUNDER_SUPPORT @THUNDER_SUPPORT@ - -/* Signed 16-bit type */ -#cmakedefine TIFF_INT16_T @TIFF_INT16_T@ +#define STRIP_SIZE_DEFAULT @STRIP_SIZE_DEFAULT@ /* Signed 32-bit type formatter */ -#cmakedefine TIFF_INT32_FORMAT @TIFF_INT32_FORMAT@ - -/* Signed 32-bit type */ -#cmakedefine TIFF_INT32_T @TIFF_INT32_T@ +#define TIFF_INT32_FORMAT "@TIFF_INT32_FORMAT@" /* Signed 64-bit type formatter */ -#cmakedefine TIFF_INT64_FORMAT @TIFF_INT64_FORMAT@ - -/* Signed 64-bit type */ -#cmakedefine TIFF_INT64_T @TIFF_INT64_T@ - -/* Signed 8-bit type */ -#cmakedefine TIFF_INT8_T @TIFF_INT8_T@ +#define TIFF_INT64_FORMAT "@TIFF_INT64_FORMAT@" /* Pointer difference type formatter */ -#cmakedefine TIFF_PTRDIFF_FORMAT @TIFF_PTRDIFF_FORMAT@ +#define TIFF_PTRDIFF_FORMAT "@TIFF_PTRDIFF_FORMAT@" -/* Pointer difference type */ -#cmakedefine TIFF_PTRDIFF_T @TIFF_PTRDIFF_T@ +/* Unsigned size type formatter */ +#define TIFF_SIZE_FORMAT "@TIFF_SIZE_FORMAT@" /* Signed size type formatter */ -#cmakedefine TIFF_SSIZE_FORMAT @TIFF_SSIZE_FORMAT@ - -/* Signed size type */ -#cmakedefine TIFF_SSIZE_T @TIFF_SSIZE_T@ - -/* Unsigned 16-bit type */ -#cmakedefine TIFF_UINT16_T @TIFF_UINT16_T@ +#define TIFF_SSIZE_FORMAT "@TIFF_SSIZE_FORMAT@" /* Unsigned 32-bit type formatter */ -#cmakedefine TIFF_UINT32_FORMAT @TIFF_UINT32_FORMAT@ - -/* Unsigned 32-bit type */ -#cmakedefine TIFF_UINT32_T @TIFF_UINT32_T@ +#define TIFF_UINT32_FORMAT "@TIFF_UINT32_FORMAT@" /* Unsigned 64-bit type formatter */ -#cmakedefine TIFF_UINT64_FORMAT @TIFF_UINT64_FORMAT@ - -/* Unsigned 64-bit type */ -#cmakedefine TIFF_UINT64_T @TIFF_UINT64_T@ +#define TIFF_UINT64_FORMAT "@TIFF_UINT64_FORMAT@" /* Unsigned 8-bit type */ -#cmakedefine TIFF_UINT8_T @TIFF_UINT8_T@ +#define TIFF_UINT8_T @TIFF_UINT8_T@ /* Define to 1 if you can safely include both and . */ -#cmakedefine TIME_WITH_SYS_TIME @TIME_WITH_SYS_TIME@ +#undef TIME_WITH_SYS_TIME /* Define to 1 if your declares `struct tm'. */ -#cmakedefine TM_IN_SYS_TIME +#cmakedefine TM_IN_SYS_TIME 1 /* define to use win32 IO system */ -#cmakedefine USE_WIN32_FILEIO +#cmakedefine USE_WIN32_FILEIO 1 /* Version number of package */ -#cmakedefine VERSION @VERSION@ +#define VERSION "@PACKAGE_VERSION@" /* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most significant byte first (like Motorola and SPARC, unlike Intel). */ @@ -361,38 +241,21 @@ # endif #else # ifndef WORDS_BIGENDIAN -#cmakedefine WORDS_BIGENDIAN @WORDS_BIGENDIAN@ +# undef WORDS_BIGENDIAN # endif #endif -/* Define to 1 if the X Window System is missing or not being used. */ -#cmakedefine X_DISPLAY_MISSING - -/* Support Deflate compression */ -#cmakedefine ZIP_SUPPORT @ZIP_SUPPORT@ - /* Number of bits in a file offset, on hosts where this is settable. */ #cmakedefine _FILE_OFFSET_BITS @_FILE_OFFSET_BITS@ -/* Define for large files, on AIX-style hosts. */ -#cmakedefine _LARGE_FILES - -/* Define to empty if `const' does not conform to ANSI C. */ -#cmakedefine const - -/* Visual Studio 2015 / VC 14 / MSVC 19.00 finally has snprintf() */ -#if defined(_MSC_VER) && _MSC_VER < 1900 -#define snprintf _snprintf -#endif - /* 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 -#define inline @INLINE@ +#define inline @INLINE_KEYWORD@ #endif /* Define to `long int' if does not define. */ -#cmakedefine off_t +#undef off_t /* Define to `unsigned int' if does not define. */ -#cmakedefine size_t +#undef size_t diff --git a/thirdparty/libtiff/tif_config.h.in b/thirdparty/libtiff/tif_config.h.in index 468ddbd3..a4b2e60a 100644 --- a/thirdparty/libtiff/tif_config.h.in +++ b/thirdparty/libtiff/tif_config.h.in @@ -40,6 +40,9 @@ /* Define to 1 if you have the `floor' function. */ #undef HAVE_FLOOR +/* Define to 1 if fseeko (and presumably ftello) exists and is declared. */ +#undef HAVE_FSEEKO + /* Define to 1 if you have the `getopt' function. */ #undef HAVE_GETOPT @@ -119,6 +122,9 @@ /* Define to 1 if you have the `setmode' function. */ #undef HAVE_SETMODE +/* Define to 1 if you have the `snprintf' function. */ +#undef HAVE_SNPRINTF + /* Define to 1 if you have the `sqrt' function. */ #undef HAVE_SQRT @@ -382,6 +388,9 @@ /* Number of bits in a file offset, on hosts where this is settable. */ #undef _FILE_OFFSET_BITS +/* Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2). */ +#undef _LARGEFILE_SOURCE + /* Define for large files, on AIX-style hosts. */ #undef _LARGE_FILES diff --git a/thirdparty/libtiff/tif_dirread.c b/thirdparty/libtiff/tif_dirread.c index 606366c8..a0dc68b7 100644 --- a/thirdparty/libtiff/tif_dirread.c +++ b/thirdparty/libtiff/tif_dirread.c @@ -1,4 +1,4 @@ -/* $Id: tif_dirread.c,v 1.187 2015-05-31 21:09:33 bfriesen Exp $ */ +/* $Id: tif_dirread.c,v 1.191 2015-09-05 20:31:41 bfriesen Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -3174,11 +3174,7 @@ static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeLongSlong(int32 value) /* * Largest 32-bit unsigned integer value. */ -#if defined(__WIN32__) && defined(_MSC_VER) -# define TIFF_UINT32_MAX 0xFFFFFFFFI64 -#else -# define TIFF_UINT32_MAX 0xFFFFFFFFLL -#endif +#define TIFF_UINT32_MAX 0xFFFFFFFFU static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeLongLong8(uint64 value) @@ -3192,7 +3188,7 @@ TIFFReadDirEntryCheckRangeLongLong8(uint64 value) static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeLongSlong8(int64 value) { - if ((value<0) || (value > TIFF_UINT32_MAX)) + if ((value < 0) || (value > (int64) TIFF_UINT32_MAX)) return(TIFFReadDirEntryErrRange); else return(TIFFReadDirEntryErrOk); @@ -3209,19 +3205,21 @@ TIFFReadDirEntryCheckRangeSlongLong(uint32 value) return(TIFFReadDirEntryErrOk); } +/* Check that the 8-byte unsigned value can fit in a 4-byte unsigned range */ static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSlongLong8(uint64 value) { - if (value > 0x7FFFFFFFUL) + if (value > 0x7FFFFFFF) return(TIFFReadDirEntryErrRange); else return(TIFFReadDirEntryErrOk); } +/* Check that the 8-byte signed value can fit in a 4-byte signed range */ static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSlongSlong8(int64 value) { - if ((value < 0L-0x80000000L) || (value > 0x7FFFFFFFL)) + if ((value < 0-((int64) 0x7FFFFFFF+1)) || (value > 0x7FFFFFFF)) return(TIFFReadDirEntryErrRange); else return(TIFFReadDirEntryErrOk); @@ -3266,11 +3264,7 @@ TIFFReadDirEntryCheckRangeLong8Slong8(int64 value) /* * Largest 64-bit signed integer value. */ -#if defined(__WIN32__) && defined(_MSC_VER) -# define TIFF_INT64_MAX 0x7FFFFFFFFFFFFFFFI64 -#else -# define TIFF_INT64_MAX 0x7FFFFFFFFFFFFFFFLL -#endif +#define TIFF_INT64_MAX ((int64)(((uint64) ~0) >> 1)) static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckRangeSlong8Long8(uint64 value) diff --git a/thirdparty/libtiff/tif_fax3.c b/thirdparty/libtiff/tif_fax3.c index 2b2dccd0..bbe72555 100644 --- a/thirdparty/libtiff/tif_fax3.c +++ b/thirdparty/libtiff/tif_fax3.c @@ -1,4 +1,4 @@ -/* $Id: tif_fax3.c,v 1.74 2012-06-21 02:01:31 fwarmerdam Exp $ */ +/* $Id: tif_fax3.c,v 1.75 2015-08-30 20:49:55 erouault Exp $ */ /* * Copyright (c) 1990-1997 Sam Leffler @@ -442,8 +442,9 @@ _TIFFFax3fillruns(unsigned char* buf, uint32* runs, uint32* erun, uint32 lastx) FILL(n, cp); run &= 7; } + /* Explicit 0xff masking to make icc -check=conversions happy */ if (run) - cp[0] |= 0xff00 >> run; + cp[0] = (unsigned char)((cp[0] | (0xff00 >> run))&0xff); } else cp[0] |= _fillmasks[run]>>bx; x += runs[1]; diff --git a/thirdparty/libtiff/tif_jpeg.c b/thirdparty/libtiff/tif_jpeg.c index d9276caf..a970eb15 100644 --- a/thirdparty/libtiff/tif_jpeg.c +++ b/thirdparty/libtiff/tif_jpeg.c @@ -1,4 +1,4 @@ -/* $Id: tif_jpeg.c,v 1.118 2015-06-10 13:17:41 bfriesen Exp $ */ +/* $Id: tif_jpeg.c,v 1.119 2015-08-15 20:13:07 bfriesen Exp $ */ /* * Copyright (c) 1994-1997 Sam Leffler @@ -252,6 +252,9 @@ TIFFjpeg_create_compress(JPEGState* sp) sp->err.error_exit = TIFFjpeg_error_exit; sp->err.output_message = TIFFjpeg_output_message; + /* set client_data to avoid UMR warning from tools like Purify */ + sp->cinfo.c.client_data = NULL; + return CALLVJPEG(sp, jpeg_create_compress(&sp->cinfo.c)); } @@ -263,6 +266,9 @@ TIFFjpeg_create_decompress(JPEGState* sp) sp->err.error_exit = TIFFjpeg_error_exit; sp->err.output_message = TIFFjpeg_output_message; + /* set client_data to avoid UMR warning from tools like Purify */ + sp->cinfo.d.client_data = NULL; + return CALLVJPEG(sp, jpeg_create_decompress(&sp->cinfo.d)); } @@ -1889,7 +1895,14 @@ JPEGEncode(TIFF* tif, uint8* buf, tmsize_t cc, uint16 s) { line16_count = (sp->bytesperline * 2) / 3; line16 = (short *) _TIFFmalloc(sizeof(short) * line16_count); - // FIXME: undiagnosed malloc failure + if (!line16) + { + TIFFErrorExt(tif->tif_clientdata, + "JPEGEncode", + "Failed to allocate memory"); + + return 0; + } } while (nrows-- > 0) { @@ -2379,8 +2392,17 @@ here hopefully is harmless. */ sp->jpegtables_length = SIZE_OF_JPEGTABLES; sp->jpegtables = (void *) _TIFFmalloc(sp->jpegtables_length); - // FIXME: NULL-deref after malloc failure - _TIFFmemset(sp->jpegtables, 0, SIZE_OF_JPEGTABLES); + if (sp->jpegtables) + { + _TIFFmemset(sp->jpegtables, 0, SIZE_OF_JPEGTABLES); + } + else + { + TIFFErrorExt(tif->tif_clientdata, + "TIFFInitJPEG", + "Failed to allocate memory for JPEG tables"); + return 0; + } #undef SIZE_OF_JPEGTABLES } diff --git a/thirdparty/libtiff/tif_lzw.c b/thirdparty/libtiff/tif_lzw.c index 58345f0a..9b76dd03 100644 --- a/thirdparty/libtiff/tif_lzw.c +++ b/thirdparty/libtiff/tif_lzw.c @@ -1,4 +1,4 @@ -/* $Id: tif_lzw.c,v 1.47 2015-06-13 05:03:50 faxguy Exp $ */ +/* $Id: tif_lzw.c,v 1.49 2015-08-30 21:07:44 erouault Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -94,7 +94,7 @@ typedef struct { unsigned short nbits; /* # of bits/code */ unsigned short maxcode; /* maximum code for lzw_nbits */ unsigned short free_ent; /* next free entry in hash table */ - long nextdata; /* next bits of i/o */ + unsigned long nextdata; /* next bits of i/o */ long nextbits; /* # of valid bits in lzw_nextdata */ int rw_mode; /* preserve rw_mode from init */ @@ -367,7 +367,8 @@ LZWDecode(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s) unsigned char *bp; hcode_t code; int len; - long nbits, nextbits, nextdata, nbitsmask; + long nbits, nextbits, nbitsmask; + unsigned long nextdata; code_t *codep, *free_entp, *maxcodep, *oldcodep; (void) s; @@ -836,13 +837,15 @@ LZWPreEncode(TIFF* tif, uint16 s) } else \ rat = (incount<<8) / outcount; \ } + +/* Explicit 0xff masking to make icc -check=conversions happy */ #define PutNextCode(op, c) { \ nextdata = (nextdata << nbits) | c; \ nextbits += nbits; \ - *op++ = (unsigned char)(nextdata >> (nextbits-8)); \ + *op++ = (unsigned char)((nextdata >> (nextbits-8))&0xff); \ nextbits -= 8; \ if (nextbits >= 8) { \ - *op++ = (unsigned char)(nextdata >> (nextbits-8)); \ + *op++ = (unsigned char)((nextdata >> (nextbits-8))&0xff); \ nextbits -= 8; \ } \ outcount += nbits; \ @@ -872,7 +875,8 @@ LZWEncode(TIFF* tif, uint8* bp, tmsize_t cc, uint16 s) hcode_t ent; long disp; long incount, outcount, checkpoint; - long nextdata, nextbits; + unsigned long nextdata; + long nextbits; int free_ent, maxcode, nbits; uint8* op; uint8* limit; @@ -1034,7 +1038,7 @@ LZWPostEncode(TIFF* tif) register LZWCodecState *sp = EncoderState(tif); uint8* op = tif->tif_rawcp; long nextbits = sp->lzw_nextbits; - long nextdata = sp->lzw_nextdata; + unsigned long nextdata = sp->lzw_nextdata; long outcount = sp->enc_outcount; int nbits = sp->lzw_nbits; @@ -1048,8 +1052,9 @@ LZWPostEncode(TIFF* tif) sp->enc_oldcode = (hcode_t) -1; } PutNextCode(op, CODE_EOI); + /* Explicit 0xff masking to make icc -check=conversions happy */ if (nextbits > 0) - *op++ = (unsigned char)(nextdata << (8-nextbits)); + *op++ = (unsigned char)((nextdata << (8-nextbits))&0xff); tif->tif_rawcc = (tmsize_t)(op - tif->tif_rawdata); return (1); } diff --git a/thirdparty/libtiff/tif_predict.c b/thirdparty/libtiff/tif_predict.c index f93c6645..1388dde5 100644 --- a/thirdparty/libtiff/tif_predict.c +++ b/thirdparty/libtiff/tif_predict.c @@ -1,4 +1,4 @@ -/* $Id: tif_predict.c,v 1.32 2010-03-10 18:56:49 bfriesen Exp $ */ +/* $Id: tif_predict.c,v 1.35 2015-08-31 15:05:57 erouault Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -42,6 +42,8 @@ static void swabHorAcc32(TIFF* tif, uint8* cp0, tmsize_t cc); static void horDiff8(TIFF* tif, uint8* cp0, tmsize_t cc); static void horDiff16(TIFF* tif, uint8* cp0, tmsize_t cc); static void horDiff32(TIFF* tif, uint8* cp0, tmsize_t cc); +static void swabHorDiff16(TIFF* tif, uint8* cp0, tmsize_t cc); +static void swabHorDiff32(TIFF* tif, uint8* cp0, tmsize_t cc); static void fpAcc(TIFF* tif, uint8* cp0, tmsize_t cc); static void fpDiff(TIFF* tif, uint8* cp0, tmsize_t cc); static int PredictorDecodeRow(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s); @@ -207,7 +209,24 @@ PredictorSetupEncode(TIFF* tif) sp->encodetile = tif->tif_encodetile; tif->tif_encodetile = PredictorEncodeTile; } - } + + /* + * If the data is horizontally differenced 16-bit data that + * requires byte-swapping, then it must be byte swapped after + * the differenciation step. We do this with a special-purpose + * routine and override the normal post decoding logic that + * the library setup when the directory was read. + */ + if (tif->tif_flags & TIFF_SWAB) { + if (sp->encodepfunc == horDiff16) { + sp->encodepfunc = swabHorDiff16; + tif->tif_postdecode = _TIFFNoPostDecode; + } else if (sp->encodepfunc == horDiff32) { + sp->encodepfunc = swabHorDiff32; + tif->tif_postdecode = _TIFFNoPostDecode; + } + } + } else if (sp->predictor == 3) { sp->encodepfunc = fpDiff; @@ -239,12 +258,18 @@ PredictorSetupEncode(TIFF* tif) case 0: ; \ } +/* Remarks related to C standard compliance in all below functions : */ +/* - to avoid any undefined behaviour, we only operate on unsigned types */ +/* since the behaviour of "overflows" is defined (wrap over) */ +/* - when storing into the byte stream, we explicitly mask with 0xff so */ +/* as to make icc -check=conversions happy (not necessary by the standard) */ + static void horAcc8(TIFF* tif, uint8* cp0, tmsize_t cc) { tmsize_t stride = PredictorState(tif)->stride; - char* cp = (char*) cp0; + unsigned char* cp = (unsigned char*) cp0; assert((cc%stride)==0); if (cc > stride) { /* @@ -257,9 +282,9 @@ horAcc8(TIFF* tif, uint8* cp0, tmsize_t cc) cc -= 3; cp += 3; while (cc>0) { - cp[0] = (char) (cr += cp[0]); - cp[1] = (char) (cg += cp[1]); - cp[2] = (char) (cb += cp[2]); + cp[0] = (unsigned char) ((cr += cp[0]) & 0xff); + cp[1] = (unsigned char) ((cg += cp[1]) & 0xff); + cp[2] = (unsigned char) ((cb += cp[2]) & 0xff); cc -= 3; cp += 3; } @@ -271,10 +296,10 @@ horAcc8(TIFF* tif, uint8* cp0, tmsize_t cc) cc -= 4; cp += 4; while (cc>0) { - cp[0] = (char) (cr += cp[0]); - cp[1] = (char) (cg += cp[1]); - cp[2] = (char) (cb += cp[2]); - cp[3] = (char) (ca += cp[3]); + cp[0] = (unsigned char) ((cr += cp[0]) & 0xff); + cp[1] = (unsigned char) ((cg += cp[1]) & 0xff); + cp[2] = (unsigned char) ((cb += cp[2]) & 0xff); + cp[3] = (unsigned char) ((ca += cp[3]) & 0xff); cc -= 4; cp += 4; } @@ -282,7 +307,7 @@ horAcc8(TIFF* tif, uint8* cp0, tmsize_t cc) cc -= stride; do { REPEAT4(stride, cp[stride] = - (char) (cp[stride] + *cp); cp++) + (unsigned char) ((cp[stride] + *cp) & 0xff); cp++) cc -= stride; } while (cc>0); } @@ -292,20 +317,11 @@ horAcc8(TIFF* tif, uint8* cp0, tmsize_t cc) static void swabHorAcc16(TIFF* tif, uint8* cp0, tmsize_t cc) { - tmsize_t stride = PredictorState(tif)->stride; uint16* wp = (uint16*) cp0; tmsize_t wc = cc / 2; - assert((cc%(2*stride))==0); - - if (wc > stride) { - TIFFSwabArrayOfShort(wp, wc); - wc -= stride; - do { - REPEAT4(stride, wp[stride] += wp[0]; wp++) - wc -= stride; - } while (wc > 0); - } + TIFFSwabArrayOfShort(wp, wc); + horAcc16(tif, cp0, cc); } static void @@ -320,7 +336,7 @@ horAcc16(TIFF* tif, uint8* cp0, tmsize_t cc) if (wc > stride) { wc -= stride; do { - REPEAT4(stride, wp[stride] += wp[0]; wp++) + REPEAT4(stride, wp[stride] = (uint16)(((unsigned int)wp[stride] + (unsigned int)wp[0]) & 0xffff); wp++) wc -= stride; } while (wc > 0); } @@ -329,20 +345,11 @@ horAcc16(TIFF* tif, uint8* cp0, tmsize_t cc) static void swabHorAcc32(TIFF* tif, uint8* cp0, tmsize_t cc) { - tmsize_t stride = PredictorState(tif)->stride; uint32* wp = (uint32*) cp0; tmsize_t wc = cc / 4; - assert((cc%(4*stride))==0); - - if (wc > stride) { - TIFFSwabArrayOfLong(wp, wc); - wc -= stride; - do { - REPEAT4(stride, wp[stride] += wp[0]; wp++) - wc -= stride; - } while (wc > 0); - } + TIFFSwabArrayOfLong(wp, wc); + horAcc32(tif, cp0, cc); } static void @@ -382,7 +389,8 @@ fpAcc(TIFF* tif, uint8* cp0, tmsize_t cc) return; while (count > stride) { - REPEAT4(stride, cp[stride] += cp[0]; cp++) + REPEAT4(stride, cp[stride] = + (unsigned char) ((cp[stride] + cp[0]) & 0xff); cp++) count -= stride; } @@ -456,7 +464,7 @@ horDiff8(TIFF* tif, uint8* cp0, tmsize_t cc) { TIFFPredictorState* sp = PredictorState(tif); tmsize_t stride = sp->stride; - char* cp = (char*) cp0; + unsigned char* cp = (unsigned char*) cp0; assert((cc%stride)==0); @@ -466,33 +474,33 @@ horDiff8(TIFF* tif, uint8* cp0, tmsize_t cc) * Pipeline the most common cases. */ if (stride == 3) { - int r1, g1, b1; - int r2 = cp[0]; - int g2 = cp[1]; - int b2 = cp[2]; + unsigned int r1, g1, b1; + unsigned int r2 = cp[0]; + unsigned int g2 = cp[1]; + unsigned int b2 = cp[2]; do { - r1 = cp[3]; cp[3] = r1-r2; r2 = r1; - g1 = cp[4]; cp[4] = g1-g2; g2 = g1; - b1 = cp[5]; cp[5] = b1-b2; b2 = b1; + r1 = cp[3]; cp[3] = (unsigned char)((r1-r2)&0xff); r2 = r1; + g1 = cp[4]; cp[4] = (unsigned char)((g1-g2)&0xff); g2 = g1; + b1 = cp[5]; cp[5] = (unsigned char)((b1-b2)&0xff); b2 = b1; cp += 3; } while ((cc -= 3) > 0); } else if (stride == 4) { - int r1, g1, b1, a1; - int r2 = cp[0]; - int g2 = cp[1]; - int b2 = cp[2]; - int a2 = cp[3]; + unsigned int r1, g1, b1, a1; + unsigned int r2 = cp[0]; + unsigned int g2 = cp[1]; + unsigned int b2 = cp[2]; + unsigned int a2 = cp[3]; do { - r1 = cp[4]; cp[4] = r1-r2; r2 = r1; - g1 = cp[5]; cp[5] = g1-g2; g2 = g1; - b1 = cp[6]; cp[6] = b1-b2; b2 = b1; - a1 = cp[7]; cp[7] = a1-a2; a2 = a1; + r1 = cp[4]; cp[4] = (unsigned char)((r1-r2)&0xff); r2 = r1; + g1 = cp[5]; cp[5] = (unsigned char)((g1-g2)&0xff); g2 = g1; + b1 = cp[6]; cp[6] = (unsigned char)((b1-b2)&0xff); b2 = b1; + a1 = cp[7]; cp[7] = (unsigned char)((a1-a2)&0xff); a2 = a1; cp += 4; } while ((cc -= 4) > 0); } else { cp += cc - 1; do { - REPEAT4(stride, cp[stride] -= cp[0]; cp--) + REPEAT4(stride, cp[stride] = (unsigned char)((cp[stride] - cp[0])&0xff); cp--) } while ((cc -= stride) > 0); } } @@ -503,7 +511,7 @@ horDiff16(TIFF* tif, uint8* cp0, tmsize_t cc) { TIFFPredictorState* sp = PredictorState(tif); tmsize_t stride = sp->stride; - int16 *wp = (int16*) cp0; + uint16 *wp = (uint16*) cp0; tmsize_t wc = cc/2; assert((cc%(2*stride))==0); @@ -512,18 +520,29 @@ horDiff16(TIFF* tif, uint8* cp0, tmsize_t cc) wc -= stride; wp += wc - 1; do { - REPEAT4(stride, wp[stride] -= wp[0]; wp--) + REPEAT4(stride, wp[stride] = (uint16)(((unsigned int)wp[stride] - (unsigned int)wp[0]) & 0xffff); wp--) wc -= stride; } while (wc > 0); } } +static void +swabHorDiff16(TIFF* tif, uint8* cp0, tmsize_t cc) +{ + uint16* wp = (uint16*) cp0; + tmsize_t wc = cc / 2; + + horDiff16(tif, cp0, cc); + + TIFFSwabArrayOfShort(wp, wc); +} + static void horDiff32(TIFF* tif, uint8* cp0, tmsize_t cc) { TIFFPredictorState* sp = PredictorState(tif); tmsize_t stride = sp->stride; - int32 *wp = (int32*) cp0; + uint32 *wp = (uint32*) cp0; tmsize_t wc = cc/4; assert((cc%(4*stride))==0); @@ -538,6 +557,17 @@ horDiff32(TIFF* tif, uint8* cp0, tmsize_t cc) } } +static void +swabHorDiff32(TIFF* tif, uint8* cp0, tmsize_t cc) +{ + uint32* wp = (uint32*) cp0; + tmsize_t wc = cc / 4; + + horDiff32(tif, cp0, cc); + + TIFFSwabArrayOfLong(wp, wc); +} + /* * Floating point predictor differencing routine. */ @@ -573,7 +603,7 @@ fpDiff(TIFF* tif, uint8* cp0, tmsize_t cc) cp = (uint8 *) cp0; cp += cc - stride - 1; for (count = cc; count > stride; count -= stride) - REPEAT4(stride, cp[stride] -= cp[0]; cp--) + REPEAT4(stride, cp[stride] = (unsigned char)((cp[stride] - cp[0])&0xff); cp--) } static int diff --git a/thirdparty/libtiff/tif_print.c b/thirdparty/libtiff/tif_print.c index 9e27ae25..7b1a4222 100644 --- a/thirdparty/libtiff/tif_print.c +++ b/thirdparty/libtiff/tif_print.c @@ -1,4 +1,4 @@ -/* $Id: tif_print.c,v 1.61 2012-12-12 22:50:18 tgl Exp $ */ +/* $Id: tif_print.c,v 1.62 2015-08-19 02:31:04 bfriesen Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -35,7 +35,7 @@ #include static void -_TIFFprintAsciiBounded(FILE* fd, const char* cp, int max_chars); +_TIFFprintAsciiBounded(FILE* fd, const char* cp, size_t max_chars); static const char *photoNames[] = { "min-is-white", /* PHOTOMETRIC_MINISWHITE */ @@ -395,7 +395,7 @@ TIFFPrintDirectory(TIFF* tif, FILE* fd, long flags) for (cp = td->td_inknames; i > 0 && cp < td->td_inknames + td->td_inknameslen; cp = strchr(cp,'\0')+1, i--) { - int max_chars = + size_t max_chars = td->td_inknameslen - (cp - td->td_inknames); fputs(sep, fd); _TIFFprintAsciiBounded(fd, cp, max_chars); @@ -679,7 +679,7 @@ _TIFFprintAscii(FILE* fd, const char* cp) } static void -_TIFFprintAsciiBounded(FILE* fd, const char* cp, int max_chars) +_TIFFprintAsciiBounded(FILE* fd, const char* cp, size_t max_chars) { for (; max_chars > 0 && *cp != '\0'; cp++, max_chars--) { const char* tp; diff --git a/thirdparty/libtiff/tif_unix.c b/thirdparty/libtiff/tif_unix.c index e96841a4..81e9d665 100644 --- a/thirdparty/libtiff/tif_unix.c +++ b/thirdparty/libtiff/tif_unix.c @@ -1,4 +1,4 @@ -/* $Id: tif_unix.c,v 1.26 2015-06-16 15:33:17 erouault Exp $ */ +/* $Id: tif_unix.c,v 1.27 2015-08-19 02:31:04 bfriesen Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -55,6 +55,10 @@ #include "tiffiop.h" + +#define TIFF_IO_MAX 2147483647U + + typedef union fd_as_handle_union { int fd; @@ -65,42 +69,71 @@ static tmsize_t _tiffReadProc(thandle_t fd, void* buf, tmsize_t size) { fd_as_handle_union_t fdh; - size_t size_io = (size_t) size; - if ((tmsize_t) size_io != size) + const size_t bytes_total = (size_t) size; + size_t bytes_read; + tmsize_t count = -1; + if ((tmsize_t) bytes_total != size) { errno=EINVAL; return (tmsize_t) -1; } fdh.h = fd; - return ((tmsize_t) read(fdh.fd, buf, size_io)); + for (bytes_read=0; bytes_read < bytes_total; bytes_read+=count) + { + char *buf_offset = (char *) buf+bytes_read; + size_t io_size = bytes_total-bytes_read; + if (io_size > TIFF_IO_MAX) + io_size = TIFF_IO_MAX; + count=read(fdh.fd, buf_offset, (TIFFIOSize_t) io_size); + if (count <= 0) + break; + } + if (count < 0) + return (tmsize_t)-1; + return (tmsize_t) bytes_read; } static tmsize_t _tiffWriteProc(thandle_t fd, void* buf, tmsize_t size) { fd_as_handle_union_t fdh; - size_t size_io = (size_t) size; - if ((tmsize_t) size_io != size) + const size_t bytes_total = (size_t) size; + size_t bytes_written; + tmsize_t count = -1; + if ((tmsize_t) bytes_total != size) { errno=EINVAL; return (tmsize_t) -1; } fdh.h = fd; - return ((tmsize_t) write(fdh.fd, buf, size_io)); + for (bytes_written=0; bytes_written < bytes_total; bytes_written+=count) + { + const char *buf_offset = (char *) buf+bytes_written; + size_t io_size = bytes_total-bytes_written; + if (io_size > TIFF_IO_MAX) + io_size = TIFF_IO_MAX; + count=write(fdh.fd, buf_offset, (TIFFIOSize_t) io_size); + if (count <= 0) + break; + } + if (count < 0) + return (tmsize_t)-1; + return (tmsize_t) bytes_written; + /* return ((tmsize_t) write(fdh.fd, buf, bytes_total)); */ } static uint64 _tiffSeekProc(thandle_t fd, uint64 off, int whence) { fd_as_handle_union_t fdh; - off_t off_io = (off_t) off; + _TIFF_off_t off_io = (_TIFF_off_t) off; if ((uint64) off_io != off) { errno=EINVAL; return (uint64) -1; /* this is really gross */ } fdh.h = fd; - return((uint64)lseek(fdh.fd,off_io,whence)); + return((uint64)_TIFF_lseek_f(fdh.fd,off_io,whence)); } static int @@ -114,10 +147,10 @@ _tiffCloseProc(thandle_t fd) static uint64 _tiffSizeProc(thandle_t fd) { - struct stat sb; + _TIFF_stat_s sb; fd_as_handle_union_t fdh; fdh.h = fd; - if (fstat(fdh.fd,&sb)<0) + if (_TIFF_fstat_f(fdh.fd,&sb)<0) return(0); else return((uint64)sb.st_size); @@ -245,7 +278,7 @@ TIFFOpenW(const wchar_t* name, const char* mode) fd = _wopen(name, m, 0666); if (fd < 0) { - TIFFErrorExt(0, module, "%s: Cannot open", name); + TIFFErrorExt(0, module, "%ls: Cannot open", name); return ((TIFF *)0); } diff --git a/thirdparty/libtiff/tif_win32.c b/thirdparty/libtiff/tif_win32.c index 5d294746..24b824f1 100644 --- a/thirdparty/libtiff/tif_win32.c +++ b/thirdparty/libtiff/tif_win32.c @@ -1,4 +1,4 @@ -/* $Id: tif_win32.c,v 1.40 2012-11-18 17:51:52 bfriesen Exp $ */ +/* $Id: tif_win32.c,v 1.41 2015-08-23 20:12:44 bfriesen Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -28,6 +28,31 @@ * TIFF Library Win32-specific Routines. Adapted from tif_unix.c 4/5/95 by * Scott Wagner (wagner@itek.com), Itek Graphix, Rochester, NY USA */ + +/* + CreateFileA/CreateFileW return type 'HANDLE'. + + thandle_t is declared like + + DECLARE_HANDLE(thandle_t); + + in tiffio.h. + + Windows (from winnt.h) DECLARE_HANDLE logic looks like + + #ifdef STRICT + typedef void *HANDLE; + #define DECLARE_HANDLE(name) struct name##__ { int unused; }; typedef struct name##__ *name + #else + typedef PVOID HANDLE; + #define DECLARE_HANDLE(name) typedef HANDLE name + #endif + + See http://bugzilla.maptools.org/show_bug.cgi?id=1941 for problems in WIN64 + builds resulting from this. Unfortunately, the proposed patch was lost. + +*/ + #include "tiffiop.h" #include @@ -214,7 +239,7 @@ TIFFFdOpen(int ifd, const char* name, const char* mode) break; } } - tif = TIFFClientOpen(name, mode, (thandle_t)ifd, + tif = TIFFClientOpen(name, mode, (thandle_t)ifd, /* FIXME: WIN64 cast to pointer warning */ _tiffReadProc, _tiffWriteProc, _tiffSeekProc, _tiffCloseProc, _tiffSizeProc, fSuppressMap ? _tiffDummyMapProc : _tiffMapProc, @@ -259,7 +284,7 @@ TIFFOpen(const char* name, const char* mode) return ((TIFF *)0); } - tif = TIFFFdOpen((int)fd, name, mode); + tif = TIFFFdOpen((int)fd, name, mode); /* FIXME: WIN64 cast from pointer to int warning */ if(!tif) CloseHandle(fd); return tif; @@ -314,7 +339,7 @@ TIFFOpenW(const wchar_t* name, const char* mode) NULL, NULL); } - tif = TIFFFdOpen((int)fd, + tif = TIFFFdOpen((int)fd, /* FIXME: WIN64 cast from pointer to int warning */ (mbname != NULL) ? mbname : "", mode); if(!tif) CloseHandle(fd); diff --git a/thirdparty/libtiff/tiffconf.h.cmake.in b/thirdparty/libtiff/tiffconf.h.cmake.in index 177c3010..6b8d9e5f 100644 --- a/thirdparty/libtiff/tiffconf.h.cmake.in +++ b/thirdparty/libtiff/tiffconf.h.cmake.in @@ -15,6 +15,39 @@ #include #endif +/* Signed 16-bit type */ +#define TIFF_INT16_T @TIFF_INT16_T@ + +/* Signed 32-bit type */ +#define TIFF_INT32_T @TIFF_INT32_T@ + +/* Signed 64-bit type */ +#define TIFF_INT64_T @TIFF_INT64_T@ + +/* Signed 8-bit type */ +#define TIFF_INT8_T @TIFF_INT8_T@ + +/* Unsigned 16-bit type */ +#define TIFF_UINT16_T @TIFF_UINT16_T@ + +/* Unsigned 32-bit type */ +#define TIFF_UINT32_T @TIFF_UINT32_T@ + +/* Unsigned 64-bit type */ +#define TIFF_UINT64_T @TIFF_UINT64_T@ + +/* Unsigned 8-bit type */ +#define TIFF_UINT8_T @TIFF_UINT8_T@ + +/* Unsigned size type */ +#define TIFF_SIZE_T @TIFF_SIZE_T@ + +/* Signed size type */ +#define TIFF_SSIZE_T @TIFF_SSIZE_T@ + +/* Pointer difference type */ +#define TIFF_PTRDIFF_T @TIFF_PTRDIFF_T@ + /* Define as 0 or 1 according to the floating point format suported by the machine */ #define HAVE_IEEEFP 1 diff --git a/thirdparty/libtiff/tiffiop.h b/thirdparty/libtiff/tiffiop.h index 53357d85..ca95d750 100644 --- a/thirdparty/libtiff/tiffiop.h +++ b/thirdparty/libtiff/tiffiop.h @@ -1,4 +1,4 @@ -/* $Id: tiffiop.h,v 1.84 2012-05-30 01:50:17 fwarmerdam Exp $ */ +/* $Id: tiffiop.h,v 1.87 2015-08-23 17:49:01 bfriesen Exp $ */ /* * Copyright (c) 1988-1997 Sam Leffler @@ -57,6 +57,12 @@ extern void *lfind(const void *, const void *, size_t *, size_t, int (*)(const void *, const void *)); #endif +#if !defined(HAVE_SNPRINTF) && !defined(HAVE__SNPRINTF) +#undef snprintf +#define snprintf _TIFF_snprintf_f +extern int snprintf(char* str, size_t size, const char* format, ...); +#endif + #include "tiffio.h" #include "tif_dir.h" @@ -258,6 +264,53 @@ struct tiff { #define TIFFArrayCount(a) (sizeof (a) / sizeof ((a)[0])) +/* + Support for large files. + + Windows read/write APIs support only 'unsigned int' rather than 'size_t'. + Windows off_t is only 32-bit, even in 64-bit builds. +*/ +#if defined(HAVE_FSEEKO) +/* + Use fseeko() and ftello() if they are available since they use + 'off_t' rather than 'long'. It is wrong to use fseeko() and + ftello() only on systems with special LFS support since some systems + (e.g. FreeBSD) support a 64-bit off_t by default. + + For MinGW, __MSVCRT_VERSION__ must be at least 0x800 to expose these + interfaces. The MinGW compiler must support the requested version. MinGW + does not distribute the CRT (it is supplied by Microsoft) so the correct CRT + must be available on the target computer in order for the program to run. +*/ +#if defined(HAVE_FSEEKO) +# define fseek(stream,offset,whence) fseeko(stream,offset,whence) +# define ftell(stream,offset,whence) ftello(stream,offset,whence) +#endif +#endif +#if defined(__WIN32__) && \ + !(defined(_MSC_VER) && _MSC_VER < 1400) && \ + !(defined(__MSVCRT_VERSION__) && __MSVCRT_VERSION__ < 0x800) +typedef unsigned int TIFFIOSize_t; +#define _TIFF_lseek_f(fildes,offset,whence) _lseeki64(fildes,/* __int64 */ offset,whence) +/* #define _TIFF_tell_f(fildes) /\* __int64 *\/ _telli64(fildes) */ +#define _TIFF_fseek_f(stream,offset,whence) _fseeki64(stream,/* __int64 */ offset,whence) +#define _TIFF_fstat_f(fildes,stat_buff) _fstati64(fildes,/* struct _stati64 */ stat_buff) +/* #define _TIFF_ftell_f(stream) /\* __int64 *\/ _ftelli64(stream) */ +/* #define _TIFF_stat_f(path,stat_buff) _stati64(path,/\* struct _stati64 *\/ stat_buff) */ +#define _TIFF_stat_s struct _stati64 +#define _TIFF_off_t __int64 +#else +typedef size_t TIFFIOSize_t; +#define _TIFF_lseek_f(fildes,offset,whence) lseek(fildes,offset,whence) +/* #define _TIFF_tell_f(fildes) (_TIFF_lseek_f(fildes,0,SEEK_CUR)) */ +#define _TIFF_fseek_f(stream,offset,whence) fseek(stream,offset,whence) +#define _TIFF_fstat_f(fildes,stat_buff) fstat(fildes,stat_buff) +/* #define _TIFF_ftell_f(stream) ftell(stream) */ +/* #define _TIFF_stat_f(path,stat_buff) stat(path,stat_buff) */ +#define _TIFF_stat_s struct stat +#define _TIFF_off_t off_t +#endif + #if defined(__cplusplus) extern "C" { #endif diff --git a/thirdparty/libtiff/tiffvers.h b/thirdparty/libtiff/tiffvers.h index 1ed5b8f3..e965814b 100644 --- a/thirdparty/libtiff/tiffvers.h +++ b/thirdparty/libtiff/tiffvers.h @@ -1,4 +1,4 @@ -#define TIFFLIB_VERSION_STR "LIBTIFF, Version 4.0.4\nCopyright (c) 1988-1996 Sam Leffler\nCopyright (c) 1991-1996 Silicon Graphics, Inc." +#define TIFFLIB_VERSION_STR "LIBTIFF, Version 4.0.6\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 20150621 +#define TIFFLIB_VERSION 20150912 From e1e018a8dc8c96f45486768356b7fb370ae0527c Mon Sep 17 00:00:00 2001 From: Julien Malik Date: Mon, 2 May 2016 12:13:24 +0200 Subject: [PATCH 30/39] Fix UBSan gcc warning for first arg to memset non null --- src/lib/openjp2/t1.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lib/openjp2/t1.c b/src/lib/openjp2/t1.c index 1e9480bd..1bf7205e 100644 --- a/src/lib/openjp2/t1.c +++ b/src/lib/openjp2/t1.c @@ -1180,7 +1180,10 @@ static OPJ_BOOL opj_t1_allocate_buffers( } t1->datasize=datasize; } - memset(t1->data,0,datasize * sizeof(OPJ_INT32)); + /* memset first arg is declared to never be null by gcc */ + if (t1->data != NULL) { + memset(t1->data,0,datasize * sizeof(OPJ_INT32)); + } } t1->flags_stride=w+2; flagssize=t1->flags_stride * (h+2); From 04b8cbd27aae2372b19598a38ba15e860952cae2 Mon Sep 17 00:00:00 2001 From: Julien Malik Date: Mon, 2 May 2016 12:55:43 +0200 Subject: [PATCH 31/39] Ignore clang's summary warning This assumes prior text has matched some other warning expression. This reduces the warnings reported for clang build on the dashboard, which were caused only by the "XXX warnings generated." message. For some reason they were not reported when not using ctest launchers. This commit allows to confidently use ctest launchers to improve dashboard reports. --- cmake/CTestCustom.cmake.in | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmake/CTestCustom.cmake.in b/cmake/CTestCustom.cmake.in index 70e045da..5afda93c 100644 --- a/cmake/CTestCustom.cmake.in +++ b/cmake/CTestCustom.cmake.in @@ -25,6 +25,9 @@ set(CTEST_CUSTOM_COVERAGE_EXCLUDE set(CTEST_CUSTOM_WARNING_EXCEPTION ${CTEST_CUSTOM_WARNING_EXCEPTION} + # Ignore clang's summary warning, assuming prior text has matched some + # other warning expression: + "[0-9,]+ warnings? generated." # Suppress warning caused by intentional messages about deprecation ".*warning,.* is deprecated" # java also warns about deprecated API From 17a0a8a195a9aad76a6bdb174edc8aa5fb8b7831 Mon Sep 17 00:00:00 2001 From: Julien Malik Date: Mon, 2 May 2016 16:03:16 +0200 Subject: [PATCH 32/39] Use lowercase for cmake commands consistenly Inspired from https://github.com/InsightSoftwareConsortium/ITK/blob/master/Utilities/Maintenance/HowToCreateTheCMakeCaseConversion.txt This needs vim 7.3 and fails with vim 7.4 This also fixes a number of : - missing empty line at end of files - useless space at end of lines --- CMakeLists.txt | 6 +- cmake/EnsureFileInclude.cmake | 4 +- doc/Doxyfile.dox.cmake.in | 2 +- src/bin/common/CMakeLists.txt | 4 +- src/bin/jp2/CMakeLists.txt | 4 +- src/bin/jp3d/CMakeLists.txt | 16 +-- src/bin/jpip/CMakeLists.txt | 2 +- src/bin/mj2/CMakeLists.txt | 4 +- src/lib/openjp2/CMakeLists.txt | 2 +- src/lib/openjp3d/CMakeLists.txt | 6 +- src/lib/openmj2/CMakeLists.txt | 6 +- tests/nonregression/CMakeLists.txt | 14 +-- tests/nonregression/checkmd5refs.cmake | 4 +- tests/unit/CMakeLists.txt | 2 +- thirdparty/CMakeLists.txt | 158 ++++++++++++------------- thirdparty/liblcms2/CMakeLists.txt | 20 ++-- thirdparty/libpng/CMakeLists.txt | 24 ++-- thirdparty/libtiff/CMakeLists.txt | 44 +++---- thirdparty/libz/CMakeLists.txt | 66 +++++------ tools/ctest_scripts/travis-ci.cmake | 12 +- wrapping/java/CMakeLists.txt | 2 +- 21 files changed, 201 insertions(+), 201 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3326b54e..6f3753ff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,7 +56,7 @@ set(PACKAGE_VERSION # you can specify your own OPENJPEG_SOVERSION at cmake configuration time: # cmake -DOPENJPEG_SOVERSION:STRING=42 /path/to/openjpeg if(NOT OPENJPEG_SOVERSION) - SET(OPENJPEG_SOVERSION 7) + set(OPENJPEG_SOVERSION 7) endif(NOT OPENJPEG_SOVERSION) set(OPENJPEG_LIBRARY_PROPERTIES VERSION "${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}" @@ -190,7 +190,7 @@ if(CMAKE_COMPILER_IS_GNUCC) # For all builds, make sure openjpeg is std99 compliant: # set(CMAKE_C_FLAGS "-Wall -std=c99 ${CMAKE_C_FLAGS}") # FIXME: this setting prevented us from setting a coverage build. # Do not use ffast-math for all build, it would produce incorrect results, only set for release: - SET(OPENJPEG_LIBRARY_COMPILE_OPTIONS ${OPENJPEG_LIBRARY_COMPILE_OPTIONS} "$<$:-ffast-math>") + set(OPENJPEG_LIBRARY_COMPILE_OPTIONS ${OPENJPEG_LIBRARY_COMPILE_OPTIONS} "$<$:-ffast-math>") endif() #----------------------------------------------------------------------------- @@ -281,7 +281,7 @@ configure_file( ${CMAKE_CURRENT_BINARY_DIR}/src/lib/openjp2/opj_config.h @ONLY ) - + configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjp2/opj_config_private.h.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/src/lib/openjp2/opj_config_private.h diff --git a/cmake/EnsureFileInclude.cmake b/cmake/EnsureFileInclude.cmake index e173ea1a..a4c064bb 100644 --- a/cmake/EnsureFileInclude.cmake +++ b/cmake/EnsureFileInclude.cmake @@ -1,5 +1,5 @@ # Ensure that an include file is provided by the system -# Add the check about the mandatory status to the check_include_file macro +# Add the check about the mandatory status to the check_include_file macro # provided by cmake include (${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake) @@ -23,4 +23,4 @@ if (NOT ${${VARIABLE_NAME}}) endif() endif() -endmacro() \ No newline at end of file +endmacro() diff --git a/doc/Doxyfile.dox.cmake.in b/doc/Doxyfile.dox.cmake.in index 8c2398ee..3163f991 100644 --- a/doc/Doxyfile.dox.cmake.in +++ b/doc/Doxyfile.dox.cmake.in @@ -145,7 +145,7 @@ HTML_STYLESHEET = HTML_COLORSTYLE_HUE = 220 HTML_COLORSTYLE_SAT = 100 HTML_COLORSTYLE_GAMMA = 80 -HTML_TIMESTAMP = NO +HTML_TIMESTAMP = NO HTML_ALIGN_MEMBERS = YES HTML_DYNAMIC_SECTIONS = NO GENERATE_DOCSET = NO diff --git a/src/bin/common/CMakeLists.txt b/src/bin/common/CMakeLists.txt index bb07ba7c..017c23df 100644 --- a/src/bin/common/CMakeLists.txt +++ b/src/bin/common/CMakeLists.txt @@ -1,7 +1,7 @@ #----------------------------------------------------------------------------- -# opj_apps_config.h generation +# opj_apps_config.h generation configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/opj_apps_config.h.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/opj_apps_config.h @ONLY - ) \ No newline at end of file + ) diff --git a/src/bin/jp2/CMakeLists.txt b/src/bin/jp2/CMakeLists.txt index d583c2e6..dc013c21 100644 --- a/src/bin/jp2/CMakeLists.txt +++ b/src/bin/jp2/CMakeLists.txt @@ -13,7 +13,7 @@ set(common_SRCS ${OPENJPEG_SOURCE_DIR}/src/bin/common/opj_getopt.h ${OPENJPEG_SOURCE_DIR}/src/bin/common/opj_string.h ) - + if(OPJ_HAVE_LIBTIFF) list(APPEND common_SRCS converttif.c) endif() @@ -64,7 +64,7 @@ foreach(exe opj_decompress opj_compress opj_dump) DESTINATION ${OPENJPEG_INSTALL_BIN_DIR} COMPONENT Applications ) if(OPJ_USE_DSYMUTIL) - add_custom_command(TARGET ${exe} POST_BUILD + add_custom_command(TARGET ${exe} POST_BUILD COMMAND "dsymutil" "$" COMMENT "dsymutil $" DEPENDS ${exe}) diff --git a/src/bin/jp3d/CMakeLists.txt b/src/bin/jp3d/CMakeLists.txt index 5a35a169..3cac1a8f 100644 --- a/src/bin/jp3d/CMakeLists.txt +++ b/src/bin/jp3d/CMakeLists.txt @@ -1,7 +1,7 @@ # Build the demo app, small examples # First thing define the common source: -SET(common_SRCS +set(common_SRCS convert.c ${OPENJPEG_SOURCE_DIR}/src/bin/common/opj_getopt.c ) @@ -26,15 +26,15 @@ if(WIN32) endif() # Loop over all executables: -FOREACH(exe opj_jp3d_compress opj_jp3d_decompress) - ADD_EXECUTABLE(${exe} ${exe}.c ${common_SRCS}) - TARGET_LINK_LIBRARIES(${exe} openjp3d) +foreach(exe opj_jp3d_compress opj_jp3d_decompress) + add_executable(${exe} ${exe}.c ${common_SRCS}) + target_link_libraries(${exe} openjp3d) # On unix you need to link to the math library: - IF(UNIX) - TARGET_LINK_LIBRARIES(${exe} m) - ENDIF(UNIX) + if(UNIX) + target_link_libraries(${exe} m) + endif(UNIX) # Install exe - INSTALL(TARGETS ${exe} + install(TARGETS ${exe} EXPORT OpenJP3DTargets DESTINATION ${OPENJPEG_INSTALL_BIN_DIR} COMPONENT Applications ) diff --git a/src/bin/jpip/CMakeLists.txt b/src/bin/jpip/CMakeLists.txt index 821b2015..301d885b 100644 --- a/src/bin/jpip/CMakeLists.txt +++ b/src/bin/jpip/CMakeLists.txt @@ -60,7 +60,7 @@ endforeach() find_package(Java 1.5 COMPONENTS Development) # javac, jar # User can override this: -if(NOT DEFINED JAVA_SOURCE_VERSION) +if(NOT DEFINED JAVA_SOURCE_VERSION) set(JAVA_SOURCE_VERSION 1.5) endif() if(NOT DEFINED JAVA_TARGET_VERSION) diff --git a/src/bin/mj2/CMakeLists.txt b/src/bin/mj2/CMakeLists.txt index 78ad7543..5d3e288b 100644 --- a/src/bin/mj2/CMakeLists.txt +++ b/src/bin/mj2/CMakeLists.txt @@ -37,11 +37,11 @@ foreach(exe APPEND PROPERTY COMPILE_DEFINITIONS USE_MJ2 ) target_link_libraries(${exe} ${LCMS_LIBNAME} openmj2) - + if(UNIX) target_link_libraries(${exe} m) endif() - + install(TARGETS ${exe} DESTINATION ${OPENJPEG_INSTALL_BIN_DIR}) endforeach() diff --git a/src/lib/openjp2/CMakeLists.txt b/src/lib/openjp2/CMakeLists.txt index 500e905c..367a7a8d 100644 --- a/src/lib/openjp2/CMakeLists.txt +++ b/src/lib/openjp2/CMakeLists.txt @@ -136,7 +136,7 @@ endif() if(OPJ_USE_DSYMUTIL) if(BUILD_SHARED_LIBS) - add_custom_command(TARGET ${OPENJPEG_LIBRARY_NAME} POST_BUILD + add_custom_command(TARGET ${OPENJPEG_LIBRARY_NAME} POST_BUILD COMMAND "dsymutil" "$" COMMENT "dsymutil $" DEPENDS ${OPENJPEG_LIBRARY_NAME}) diff --git a/src/lib/openjp3d/CMakeLists.txt b/src/lib/openjp3d/CMakeLists.txt index 0bbafea3..26bf1788 100644 --- a/src/lib/openjp3d/CMakeLists.txt +++ b/src/lib/openjp3d/CMakeLists.txt @@ -5,9 +5,9 @@ include_directories( ${OPENJPEG_BINARY_DIR}/src/lib/openjp2 # opj_config.h ) -SET(OPENJP3D_LIBRARY_NAME openjp3d) +set(OPENJP3D_LIBRARY_NAME openjp3d) # Defines the source code for the library -SET(OPENJP3D_SRCS +set(OPENJP3D_SRCS bio.c cio.c dwt.c event.c jp3d.c jp3d_lib.c mct.c mqc.c openjp3d.c pi.c raw.c t1.c t1_3d.c t2.c tcd.c tgt.c volume.c ) @@ -34,7 +34,7 @@ endif() # Install library install(TARGETS ${OPENJP3D_LIBRARY_NAME} EXPORT OpenJP3DTargets - DESTINATION ${OPENJPEG_INSTALL_LIB_DIR} + DESTINATION ${OPENJPEG_INSTALL_LIB_DIR} COMPONENT Libraries ) diff --git a/src/lib/openmj2/CMakeLists.txt b/src/lib/openmj2/CMakeLists.txt index dbb7e7ce..2ee1764b 100644 --- a/src/lib/openmj2/CMakeLists.txt +++ b/src/lib/openmj2/CMakeLists.txt @@ -53,12 +53,12 @@ endif() # Install library install(TARGETS ${OPENMJ2_LIBRARY_NAME} EXPORT OpenMJ2Targets - DESTINATION ${OPENJPEG_INSTALL_LIB_DIR} + DESTINATION ${OPENJPEG_INSTALL_LIB_DIR} COMPONENT Libraries ) # Install includes files -#INSTALL(FILES mj2.h -# DESTINATION ${OPENJPEG_INSTALL_INCLUDE_DIR}/${subdir} +#install(FILES mj2.h +# DESTINATION ${OPENJPEG_INSTALL_INCLUDE_DIR}/${subdir} # COMPONENT Headers #) diff --git a/tests/nonregression/CMakeLists.txt b/tests/nonregression/CMakeLists.txt index 40283169..31af7c05 100644 --- a/tests/nonregression/CMakeLists.txt +++ b/tests/nonregression/CMakeLists.txt @@ -55,7 +55,7 @@ set(BLACKLIST_JPEG2000_TMP # Define a list of file which should be gracefully rejected: set(BLACKLIST_JPEG2000 ${BLACKLIST_JPEG2000_TMP} - broken1.jp2 + broken1.jp2 broken2.jp2 broken3.jp2 broken4.jp2 @@ -340,7 +340,7 @@ foreach(OPJ_TEST_CMD_LINE ${OPJ_TEST_CMD_LINE_LIST}) NR-ENC-${INPUT_FILENAME_NAME}-${IT_TEST_ENC}-decode-ref) endif() - + # Test the encoded file is a valid JP2 file if (JPYLYZER_EXECUTABLE) if (${OUTPUT_FILENAME} MATCHES "\\.jp2$") @@ -348,13 +348,13 @@ foreach(OPJ_TEST_CMD_LINE ${OPJ_TEST_CMD_LINE_LIST}) COMMAND ${JPYLYZER_EXECUTABLE} ${OUTPUT_FILENAME} ) - set_tests_properties(NR-ENC-${INPUT_FILENAME_NAME}-${IT_TEST_ENC}-jpylyser PROPERTIES + set_tests_properties(NR-ENC-${INPUT_FILENAME_NAME}-${IT_TEST_ENC}-jpylyser PROPERTIES DEPENDS NR-ENC-${INPUT_FILENAME_NAME}-${IT_TEST_ENC}-encode PASS_REGULAR_EXPRESSION "True" ) endif() endif(JPYLYZER_EXECUTABLE) - + # If lossless compression (simple test is 4 arguments), decompress & compare list(LENGTH CMD_ARG_LIST_2 ARG_COUNT) if (ARG_COUNT EQUAL 4) @@ -363,13 +363,13 @@ foreach(OPJ_TEST_CMD_LINE ${OPJ_TEST_CMD_LINE_LIST}) add_test(NAME NR-ENC-${INPUT_FILENAME_NAME}-${IT_TEST_ENC}-lossless-decode COMMAND opj_decompress -i ${OUTPUT_FILENAME} -o ${OUTPUT_FILENAME}.lossless.tif ) - set_tests_properties(NR-ENC-${INPUT_FILENAME_NAME}-${IT_TEST_ENC}-lossless-decode PROPERTIES + set_tests_properties(NR-ENC-${INPUT_FILENAME_NAME}-${IT_TEST_ENC}-lossless-decode PROPERTIES DEPENDS NR-ENC-${INPUT_FILENAME_NAME}-${IT_TEST_ENC}-encode ) add_test(NAME NR-ENC-${INPUT_FILENAME_NAME}-${IT_TEST_ENC}-lossless-compare COMMAND compare_images -b ${INPUT_FILENAME} -t ${OUTPUT_FILENAME}.lossless.tif -n 1 -d ) - set_tests_properties(NR-ENC-${INPUT_FILENAME_NAME}-${IT_TEST_ENC}-lossless-compare PROPERTIES + set_tests_properties(NR-ENC-${INPUT_FILENAME_NAME}-${IT_TEST_ENC}-lossless-compare PROPERTIES DEPENDS NR-ENC-${INPUT_FILENAME_NAME}-${IT_TEST_ENC}-lossless-decode ) endif() @@ -401,7 +401,7 @@ foreach(OPJ_TEST_CMD_LINE ${OPJ_TEST_CMD_LINE_LIST}) -DOUTFILENAME:STRING=${OUTPUT_FILENAME} -P ${CMAKE_CURRENT_SOURCE_DIR}/checkmd5refs.cmake) - set_tests_properties(NR-DEC-${INPUT_FILENAME_NAME}-${IT_TEST_DEC}-decode-md5 + set_tests_properties(NR-DEC-${INPUT_FILENAME_NAME}-${IT_TEST_DEC}-decode-md5 PROPERTIES DEPENDS NR-DEC-${INPUT_FILENAME_NAME}-${IT_TEST_DEC}-decode ) diff --git a/tests/nonregression/checkmd5refs.cmake b/tests/nonregression/checkmd5refs.cmake index 40e019b7..75afbed0 100644 --- a/tests/nonregression/checkmd5refs.cmake +++ b/tests/nonregression/checkmd5refs.cmake @@ -43,11 +43,11 @@ file(READ ${REFFILE} variable) foreach(pgxfullpath ${globfiles}) file(MD5 ${pgxfullpath} output) get_filename_component(pgxfile ${pgxfullpath} NAME) - + string(REGEX MATCH "[0-9a-f]+ ${pgxfile}" output_var "${variable}") set(output "${output} ${pgxfile}") - + if("${output_var}" STREQUAL "${output}") message(STATUS "equal: [${output_var}] vs [${output}]") else() diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt index ae47b88e..772b1a30 100644 --- a/tests/unit/CMakeLists.txt +++ b/tests/unit/CMakeLists.txt @@ -1,4 +1,4 @@ -# UNIT TESTS +# UNIT TESTS include_directories( ${OPENJPEG_BINARY_DIR}/src/lib/openjp2 # opj_config.h diff --git a/thirdparty/CMakeLists.txt b/thirdparty/CMakeLists.txt index d1e68ca9..cb24b43b 100644 --- a/thirdparty/CMakeLists.txt +++ b/thirdparty/CMakeLists.txt @@ -2,117 +2,117 @@ #------------ # Try to find lib Z -IF(BUILD_THIRDPARTY) +if(BUILD_THIRDPARTY) # Try to build it message(STATUS "We will build Z lib from thirdparty") - ADD_SUBDIRECTORY(libz) - SET(Z_LIBNAME z PARENT_SCOPE) - SET(Z_INCLUDE_DIRNAME ${OPENJPEG_SOURCE_DIR}/thirdparty/include PARENT_SCOPE) - SET(ZLIB_FOUND 1) -ELSE (BUILD_THIRDPARTY) + add_subdirectory(libz) + set(Z_LIBNAME z PARENT_SCOPE) + set(Z_INCLUDE_DIRNAME ${OPENJPEG_SOURCE_DIR}/thirdparty/include PARENT_SCOPE) + set(ZLIB_FOUND 1) +else(BUILD_THIRDPARTY) # Try to find lib Z - FIND_PACKAGE(ZLIB) - IF(ZLIB_FOUND) - SET(Z_LIBNAME ${ZLIB_LIBRARIES} PARENT_SCOPE) - SET(Z_INCLUDE_DIRNAME ${ZLIB_INCLUDE_DIRS} PARENT_SCOPE) + find_package(ZLIB) + if(ZLIB_FOUND) + set(Z_LIBNAME ${ZLIB_LIBRARIES} PARENT_SCOPE) + set(Z_INCLUDE_DIRNAME ${ZLIB_INCLUDE_DIRS} PARENT_SCOPE) message(STATUS "Your system seems to have a Z lib available, we will use it to generate PNG lib") # message(STATUS "DEBUG: ${ZLIB_INCLUDE_DIRS} vs ${ZLIB_INCLUDE_DIR}") - ELSE (ZLIB_FOUND) # not found + else(ZLIB_FOUND) # not found message(STATUS "Z lib not found, activate BUILD_THIRDPARTY if you want build it (necessary to build libPNG)") - ENDIF(ZLIB_FOUND) -ENDIF(BUILD_THIRDPARTY) + endif(ZLIB_FOUND) +endif(BUILD_THIRDPARTY) #------------ # Try to find lib PNG (which depends on zlib) -IF(BUILD_THIRDPARTY) +if(BUILD_THIRDPARTY) # Try to build it message(STATUS "We will build PNG lib from thirdparty") - ADD_SUBDIRECTORY(libpng) - SET(OPJ_HAVE_PNG_H 1 PARENT_SCOPE) - SET(OPJ_HAVE_LIBPNG 1 PARENT_SCOPE) - SET(PNG_LIBNAME png PARENT_SCOPE) - SET(PNG_INCLUDE_DIRNAME ${OPENJPEG_SOURCE_DIR}/thirdparty/libpng PARENT_SCOPE) -ELSE (BUILD_THIRDPARTY) - IF (ZLIB_FOUND) - FIND_PACKAGE(PNG) - IF(PNG_FOUND) + add_subdirectory(libpng) + set(OPJ_HAVE_PNG_H 1 PARENT_SCOPE) + set(OPJ_HAVE_LIBPNG 1 PARENT_SCOPE) + set(PNG_LIBNAME png PARENT_SCOPE) + set(PNG_INCLUDE_DIRNAME ${OPENJPEG_SOURCE_DIR}/thirdparty/libpng PARENT_SCOPE) +else(BUILD_THIRDPARTY) + if(ZLIB_FOUND) + find_package(PNG) + if(PNG_FOUND) message(STATUS "Your system seems to have a PNG lib available, we will use it") - SET(OPJ_HAVE_PNG_H 1 PARENT_SCOPE) - SET(OPJ_HAVE_LIBPNG 1 PARENT_SCOPE) - SET(PNG_LIBNAME ${PNG_LIBRARIES} PARENT_SCOPE) - SET(PNG_INCLUDE_DIRNAME ${PNG_PNG_INCLUDE_DIR} PARENT_SCOPE) - ELSE(PNG_FOUND) # not found - SET(OPJ_HAVE_PNG_H 0 PARENT_SCOPE) - SET(OPJ_HAVE_LIBPNG 0 PARENT_SCOPE) + set(OPJ_HAVE_PNG_H 1 PARENT_SCOPE) + set(OPJ_HAVE_LIBPNG 1 PARENT_SCOPE) + set(PNG_LIBNAME ${PNG_LIBRARIES} PARENT_SCOPE) + set(PNG_INCLUDE_DIRNAME ${PNG_PNG_INCLUDE_DIR} PARENT_SCOPE) + else(PNG_FOUND) # not found + set(OPJ_HAVE_PNG_H 0 PARENT_SCOPE) + set(OPJ_HAVE_LIBPNG 0 PARENT_SCOPE) message(STATUS "PNG lib not found, activate BUILD_THIRDPARTY if you want build it") - ENDIF(PNG_FOUND) - ENDIF (ZLIB_FOUND) -ENDIF(BUILD_THIRDPARTY) + endif(PNG_FOUND) + endif(ZLIB_FOUND) +endif(BUILD_THIRDPARTY) #------------ # Try to find lib TIFF -IF(BUILD_THIRDPARTY) +if(BUILD_THIRDPARTY) # Try to build it message(STATUS "We will build TIFF lib from thirdparty") - ADD_SUBDIRECTORY(libtiff) - SET(TIFF_LIBNAME tiff PARENT_SCOPE) - SET(TIFF_INCLUDE_DIRNAME + add_subdirectory(libtiff) + set(TIFF_LIBNAME tiff PARENT_SCOPE) + set(TIFF_INCLUDE_DIRNAME ${OPENJPEG_SOURCE_DIR}/thirdparty/libtiff ${OPENJPEG_BINARY_DIR}/thirdparty/libtiff PARENT_SCOPE) - SET(OPJ_HAVE_TIFF_H 1 PARENT_SCOPE) - SET(OPJ_HAVE_LIBTIFF 1 PARENT_SCOPE) -ELSE (BUILD_THIRDPARTY) - FIND_PACKAGE(TIFF) - IF(TIFF_FOUND) + set(OPJ_HAVE_TIFF_H 1 PARENT_SCOPE) + set(OPJ_HAVE_LIBTIFF 1 PARENT_SCOPE) +else(BUILD_THIRDPARTY) + find_package(TIFF) + if(TIFF_FOUND) message(STATUS "Your system seems to have a TIFF lib available, we will use it") - SET(OPJ_HAVE_TIFF_H 1 PARENT_SCOPE) - SET(OPJ_HAVE_LIBTIFF 1 PARENT_SCOPE) - SET(TIFF_LIBNAME ${TIFF_LIBRARIES} PARENT_SCOPE) - SET(TIFF_INCLUDE_DIRNAME ${TIFF_INCLUDE_DIR} PARENT_SCOPE) - ELSE (TIFF_FOUND) # not found - SET(OPJ_HAVE_TIFF_H 0 PARENT_SCOPE) - SET(OPJ_HAVE_LIBTIFF 0 PARENT_SCOPE) + set(OPJ_HAVE_TIFF_H 1 PARENT_SCOPE) + set(OPJ_HAVE_LIBTIFF 1 PARENT_SCOPE) + set(TIFF_LIBNAME ${TIFF_LIBRARIES} PARENT_SCOPE) + set(TIFF_INCLUDE_DIRNAME ${TIFF_INCLUDE_DIR} PARENT_SCOPE) + else(TIFF_FOUND) # not found + set(OPJ_HAVE_TIFF_H 0 PARENT_SCOPE) + set(OPJ_HAVE_LIBTIFF 0 PARENT_SCOPE) message(STATUS "TIFF lib not found, activate BUILD_THIRDPARTY if you want build it") - ENDIF(TIFF_FOUND) -ENDIF(BUILD_THIRDPARTY) + endif(TIFF_FOUND) +endif(BUILD_THIRDPARTY) #------------ # Try to find lib LCMS2 (or by default LCMS) -SET(OPJ_HAVE_LCMS_H 0 PARENT_SCOPE) -SET(OPJ_HAVE_LIBLCMS 0 PARENT_SCOPE) +set(OPJ_HAVE_LCMS_H 0 PARENT_SCOPE) +set(OPJ_HAVE_LIBLCMS 0 PARENT_SCOPE) -IF( BUILD_THIRDPARTY) +if( BUILD_THIRDPARTY) # Try to build lcms2 message(STATUS "We will build LCMS2 lib from thirdparty") - ADD_SUBDIRECTORY(liblcms2) - SET(LCMS_LIBNAME lcms2 PARENT_SCOPE) - SET(LCMS_INCLUDE_DIRNAME ${OPENJPEG_SOURCE_DIR}/thirdparty/liblcms2/include PARENT_SCOPE) # - SET(OPJ_HAVE_LCMS2_H 1 PARENT_SCOPE) - SET(OPJ_HAVE_LIBLCMS2 1 PARENT_SCOPE) -ELSE (BUILD_THIRDPARTY) - FIND_PACKAGE(LCMS2) - IF(LCMS2_FOUND) + add_subdirectory(liblcms2) + set(LCMS_LIBNAME lcms2 PARENT_SCOPE) + set(LCMS_INCLUDE_DIRNAME ${OPENJPEG_SOURCE_DIR}/thirdparty/liblcms2/include PARENT_SCOPE) # + set(OPJ_HAVE_LCMS2_H 1 PARENT_SCOPE) + set(OPJ_HAVE_LIBLCMS2 1 PARENT_SCOPE) +else(BUILD_THIRDPARTY) + find_package(LCMS2) + if(LCMS2_FOUND) message(STATUS "Your system seems to have a LCMS2 lib available, we will use it") - SET(OPJ_HAVE_LCMS2_H 1 PARENT_SCOPE) - SET(OPJ_HAVE_LIBLCMS2 1 PARENT_SCOPE) - SET(LCMS_LIBNAME ${LCMS2_LIBRARIES} PARENT_SCOPE) - SET(LCMS_INCLUDE_DIRNAME ${LCMS2_INCLUDE_DIRS} PARENT_SCOPE) - ELSE (LCMS2_FOUND) # not found lcms2 + set(OPJ_HAVE_LCMS2_H 1 PARENT_SCOPE) + set(OPJ_HAVE_LIBLCMS2 1 PARENT_SCOPE) + set(LCMS_LIBNAME ${LCMS2_LIBRARIES} PARENT_SCOPE) + set(LCMS_INCLUDE_DIRNAME ${LCMS2_INCLUDE_DIRS} PARENT_SCOPE) + else(LCMS2_FOUND) # not found lcms2 # try to find LCMS - FIND_PACKAGE(LCMS) - IF(LCMS_FOUND) + find_package(LCMS) + if(LCMS_FOUND) message(STATUS "Your system seems to have a LCMS lib available, we will use it") - SET(OPJ_HAVE_LCMS_H 1 PARENT_SCOPE) - SET(OPJ_HAVE_LIBLCMS 1 PARENT_SCOPE) - SET(LCMS_LIBNAME ${LCMS_LIBRARIES} PARENT_SCOPE) - SET(LCMS_INCLUDE_DIRNAME ${LCMS_INCLUDE_DIRS} PARENT_SCOPE) - ELSE (LCMS_FOUND) # not found lcms - SET(OPJ_HAVE_LCMS2_H 0 PARENT_SCOPE) - SET(OPJ_HAVE_LIBLCMS2 0 PARENT_SCOPE) + set(OPJ_HAVE_LCMS_H 1 PARENT_SCOPE) + set(OPJ_HAVE_LIBLCMS 1 PARENT_SCOPE) + set(LCMS_LIBNAME ${LCMS_LIBRARIES} PARENT_SCOPE) + set(LCMS_INCLUDE_DIRNAME ${LCMS_INCLUDE_DIRS} PARENT_SCOPE) + else(LCMS_FOUND) # not found lcms + set(OPJ_HAVE_LCMS2_H 0 PARENT_SCOPE) + set(OPJ_HAVE_LIBLCMS2 0 PARENT_SCOPE) message(STATUS "LCMS2 or LCMS lib not found, activate BUILD_THIRDPARTY if you want build it") - ENDIF (LCMS_FOUND) - ENDIF(LCMS2_FOUND) -ENDIF(BUILD_THIRDPARTY) + endif(LCMS_FOUND) + endif(LCMS2_FOUND) +endif(BUILD_THIRDPARTY) diff --git a/thirdparty/liblcms2/CMakeLists.txt b/thirdparty/liblcms2/CMakeLists.txt index e05a42b7..debd41b3 100644 --- a/thirdparty/liblcms2/CMakeLists.txt +++ b/thirdparty/liblcms2/CMakeLists.txt @@ -1,19 +1,19 @@ -PROJECT(liblcms2 C) +project(liblcms2 C) # -INCLUDE_DIRECTORIES("${CMAKE_CURRENT_SOURCE_DIR}/include") +include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include") # -FILE(GLOB SRCS src/*.c) -FILE(GLOB HDRS include/*.h) +file(GLOB SRCS src/*.c) +file(GLOB HDRS include/*.h) # -SET(LIBTARGET "lcms2") +set(LIBTARGET "lcms2") # -ADD_LIBRARY(${LIBTARGET} STATIC ${SRCS} ${HDRS}) +add_library(${LIBTARGET} STATIC ${SRCS} ${HDRS}) # -IF(MSVC) - SET_TARGET_PROPERTIES(${LIBTARGET} PROPERTIES PREFIX "lib") -ENDIF(MSVC) +if(MSVC) + set_target_properties(${LIBTARGET} PROPERTIES PREFIX "lib") +endif(MSVC) # -SET_TARGET_PROPERTIES(${LIBTARGET} +set_target_properties(${LIBTARGET} PROPERTIES OUTPUT_NAME "${LIBTARGET}" ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/thirdparty/lib) diff --git a/thirdparty/libpng/CMakeLists.txt b/thirdparty/libpng/CMakeLists.txt index 0fde4f66..840bd850 100644 --- a/thirdparty/libpng/CMakeLists.txt +++ b/thirdparty/libpng/CMakeLists.txt @@ -1,28 +1,28 @@ -PROJECT(libpng C) +project(libpng C) -INCLUDE_DIRECTORIES( +include_directories( "${CMAKE_CURRENT_SOURCE_DIR}" ${OPENJPEG_SOURCE_DIR}/thirdparty/include ) -FILE(GLOB SRCS *.c) -FILE(GLOB HDRS *.h) -SET(EXT_HDRS +file(GLOB SRCS *.c) +file(GLOB HDRS *.h) +set(EXT_HDRS ${OPENJPEG_SOURCE_DIR}/thirdparty/include/zlib.h ${OPENJPEG_SOURCE_DIR}/thirdparty/include/zconf.h ) # -SET(LIBTARGET "png") +set(LIBTARGET "png") # -ADD_LIBRARY(${LIBTARGET} STATIC ${SRCS} ${HDRS} ${EXT_HDRS}) +add_library(${LIBTARGET} STATIC ${SRCS} ${HDRS} ${EXT_HDRS}) # -IF(MSVC) - SET_TARGET_PROPERTIES(${LIBTARGET} PROPERTIES PREFIX "lib") -ENDIF(MSVC) +if(MSVC) + set_target_properties(${LIBTARGET} PROPERTIES PREFIX "lib") +endif(MSVC) # -TARGET_LINK_LIBRARIES(${LIBTARGET} ${Z_LIBNAME} ${M_LIBRARY}) +target_link_libraries(${LIBTARGET} ${Z_LIBNAME} ${M_LIBRARY}) # -SET_TARGET_PROPERTIES(${LIBTARGET} +set_target_properties(${LIBTARGET} PROPERTIES OUTPUT_NAME "${LIBTARGET}" ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/thirdparty/lib) diff --git a/thirdparty/libtiff/CMakeLists.txt b/thirdparty/libtiff/CMakeLists.txt index 63a8f7e8..8a462263 100644 --- a/thirdparty/libtiff/CMakeLists.txt +++ b/thirdparty/libtiff/CMakeLists.txt @@ -1,12 +1,12 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +cmake_minimum_required(VERSION 2.6) project(libtiff C) # This convenient copy of libtiff does not support encapsulated zlib or jpeg # stream. see ZIP_SUPPORT and JPEG_SUPPORT values -INCLUDE_DIRECTORIES(BEFORE "${CMAKE_CURRENT_SOURCE_DIR}") -INCLUDE_DIRECTORIES(BEFORE "${CMAKE_CURRENT_BINARY_DIR}") +include_directories(BEFORE "${CMAKE_CURRENT_SOURCE_DIR}") +include_directories(BEFORE "${CMAKE_CURRENT_BINARY_DIR}") -SET(TARGET_FILES +set(TARGET_FILES t4.h tiffiop.h tif_aux.c @@ -53,16 +53,16 @@ SET(TARGET_FILES uvcode.h ) -IF(UNIX) - SET(TARGET_FILES ${TARGET_FILES} tif_unix.c) +if(UNIX) + set(TARGET_FILES ${TARGET_FILES} tif_unix.c) # Large file support # This might not catch every possibility catered for by # AC_SYS_LARGEFILE. add_definitions(-D_FILE_OFFSET_BITS=64) set(_FILE_OFFSET_BITS 64) -ELSE() - SET(TARGET_FILES ${TARGET_FILES} tif_win32.c) -ENDIF() +else() + set(TARGET_FILES ${TARGET_FILES} tif_win32.c) +endif() include(${CMAKE_ROOT}/Modules/TestBigEndian.cmake) TEST_BIG_ENDIAN(WORDS_BIGENDIAN) @@ -151,7 +151,7 @@ int main(void) { }" HAVE_SNPRINTF) if(NOT HAVE_SNPRINTF) - SET(TARGET_FILES ${TARGET_FILES} snprintf.c) + set(TARGET_FILES ${TARGET_FILES} snprintf.c) endif() include(CheckTypeSize) @@ -250,28 +250,28 @@ CHECK_SYMBOL_EXISTS(lfind "search.h" HAVE_LFIND) CHECK_SYMBOL_EXISTS(setmod "io.h" HAVE_SETMODE) # http://www.cmake.org/pipermail/cmake/2007-September/016285.html -FOREACH(KEYWORD "inline" "__inline__" "__inline") - IF(NOT DEFINED C_INLINE) - TRY_COMPILE(C_HAS_${KEYWORD} "${CMAKE_CURRENT_BINARY_DIR}" +foreach(KEYWORD "inline" "__inline__" "__inline") + if(NOT DEFINED C_INLINE) + try_compile(C_HAS_${KEYWORD} "${CMAKE_CURRENT_BINARY_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/test_inline.c" COMPILE_DEFINITIONS "-Dinline=${KEYWORD}") - IF(C_HAS_${KEYWORD}) - SET(C_INLINE TRUE) - SET(INLINE_KEYWORD "${KEYWORD}") - ENDIF(C_HAS_${KEYWORD}) - ENDIF(NOT DEFINED C_INLINE) -ENDFOREACH(KEYWORD) + if(C_HAS_${KEYWORD}) + set(C_INLINE TRUE) + set(INLINE_KEYWORD "${KEYWORD}") + endif(C_HAS_${KEYWORD}) + endif(NOT DEFINED C_INLINE) +endforeach(KEYWORD) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tiffconf.h.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/tiffconf.h @ONLY) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tif_config.h.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/tif_config.h @ONLY) -SET(LIBTARGET "tiff") +set(LIBTARGET "tiff") # -ADD_LIBRARY(${LIBTARGET} STATIC ${TARGET_FILES}) +add_library(${LIBTARGET} STATIC ${TARGET_FILES}) # -SET_TARGET_PROPERTIES(${LIBTARGET} +set_target_properties(${LIBTARGET} PROPERTIES OUTPUT_NAME "${LIBTARGET}" ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/thirdparty/lib diff --git a/thirdparty/libz/CMakeLists.txt b/thirdparty/libz/CMakeLists.txt index 7cd08180..d257a6b4 100644 --- a/thirdparty/libz/CMakeLists.txt +++ b/thirdparty/libz/CMakeLists.txt @@ -1,14 +1,14 @@ #based on zlib-1.2.5/CMakeLists.txt # cmake_minimum_required(VERSION 2.6) -SET(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON) +set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON) -PROJECT(zlib C) +project(zlib C) -INCLUDE(CheckTypeSize) -INCLUDE(CheckFunctionExists) -INCLUDE(CheckIncludeFile) -INCLUDE(CheckCSourceCompiles) +include(CheckTypeSize) +include(CheckFunctionExists) +include(CheckIncludeFile) +include(CheckCSourceCompiles) CHECK_INCLUDE_FILE(sys/types.h HAVE_SYS_TYPES_H) CHECK_INCLUDE_FILE(stdint.h HAVE_STDINT_H) @@ -17,47 +17,47 @@ CHECK_INCLUDE_FILE(stddef.h HAVE_STDDEF_H) # # Check to see if we have large file support # -SET(CMAKE_REQUIRED_DEFINITIONS -D_LARGEFILE64_SOURCE=1) +set(CMAKE_REQUIRED_DEFINITIONS -D_LARGEFILE64_SOURCE=1) # We add these other definitions here because CheckTypeSize.cmake # in CMake 2.4.x does not automatically do so and we want # compatibility with CMake 2.4.x. -IF(HAVE_SYS_TYPES_H) - LIST(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_SYS_TYPES_H) -ENDIF() -IF(HAVE_STDINT_H) - LIST(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDINT_H) -ENDIF() -IF(HAVE_STDDEF_H) - LIST(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDDEF_H) -ENDIF() +if(HAVE_SYS_TYPES_H) + list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_SYS_TYPES_H) +endif() +if(HAVE_STDINT_H) + list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDINT_H) +endif() +if(HAVE_STDDEF_H) + list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDDEF_H) +endif() CHECK_TYPE_SIZE(off64_t OFF64_T) -IF(HAVE_OFF64_T) - ADD_DEFINITIONS(-D_LARGEFILE64_SOURCE=1) -ENDIF() -SET(CMAKE_REQUIRED_DEFINITIONS) # clear variable +if(HAVE_OFF64_T) + add_definitions(-D_LARGEFILE64_SOURCE=1) +endif() +set(CMAKE_REQUIRED_DEFINITIONS) # clear variable # # Check for fseeko # CHECK_FUNCTION_EXISTS(fseeko HAVE_FSEEKO) -IF(NOT HAVE_FSEEKO) - ADD_DEFINITIONS(-DNO_FSEEKO) -ENDIF() +if(NOT HAVE_FSEEKO) + add_definitions(-DNO_FSEEKO) +endif() # # Check for unistd.h # CHECK_INCLUDE_FILE(unistd.h Z_HAVE_UNISTD_H) -INCLUDE_DIRECTORIES( +include_directories( ${CMAKE_CURRENT_SOURCE_DIR} ${OPENJPEG_SOURCE_DIR}/thirdparty/include ) # -SET(EXT_HDRS +set(EXT_HDRS ${OPENJPEG_SOURCE_DIR}/thirdparty/include/zlib.h ${OPENJPEG_SOURCE_DIR}/thirdparty/include/zconf.h ) -SET(HDRS +set(HDRS crc32.h deflate.h gzguts.h @@ -68,7 +68,7 @@ SET(HDRS trees.h zutil.h ) -SET(SRCS +set(SRCS adler32.c compress.c crc32.c @@ -86,15 +86,15 @@ SET(SRCS zutil.c ) -SET(LIBTARGET "z") +set(LIBTARGET "z") # -ADD_LIBRARY(${LIBTARGET} STATIC ${SRCS} ${EXT_HDRS} ${HDRS}) +add_library(${LIBTARGET} STATIC ${SRCS} ${EXT_HDRS} ${HDRS}) # -IF(MSVC) - SET_TARGET_PROPERTIES(${LIBTARGET} PROPERTIES PREFIX "lib") -ENDIF(MSVC) +if(MSVC) + set_target_properties(${LIBTARGET} PROPERTIES PREFIX "lib") +endif(MSVC) -SET_TARGET_PROPERTIES(${LIBTARGET} +set_target_properties(${LIBTARGET} PROPERTIES OUTPUT_NAME "${LIBTARGET}" ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/thirdparty/lib diff --git a/tools/ctest_scripts/travis-ci.cmake b/tools/ctest_scripts/travis-ci.cmake index f8b23ada..f8c50e5b 100644 --- a/tools/ctest_scripts/travis-ci.cmake +++ b/tools/ctest_scripts/travis-ci.cmake @@ -69,8 +69,8 @@ if("$ENV{CC}" MATCHES ".*mingw.*") endif() if(NOT "$ENV{OPJ_CI_SKIP_TESTS}" STREQUAL "1") - # To execute part of the encoding test suite, kakadu binaries are needed to decode encoded image and compare - # it to the baseline. Kakadu binaries are freely available for non-commercial purposes + # To execute part of the encoding test suite, kakadu binaries are needed to decode encoded image and compare + # it to the baseline. Kakadu binaries are freely available for non-commercial purposes # at http://www.kakadusoftware.com. # Here's the copyright notice from kakadu: # Copyright is owned by NewSouth Innovations Pty Limited, commercial arm of the UNSW Australia in Sydney. @@ -91,7 +91,7 @@ else() set(BUILD_TESTING "FALSE") endif(NOT "$ENV{OPJ_CI_SKIP_TESTS}" STREQUAL "1") -# Options +# Options set( CACHE_CONTENTS " # Build kind @@ -103,19 +103,19 @@ CMAKE_C_FLAGS:STRING= ${CCFLAGS_ARCH} ${CCFLAGS_WARNING} # Use to activate the test suite BUILD_TESTING:BOOL=${BUILD_TESTING} -# Build Thirdparty, useful but not required for test suite +# Build Thirdparty, useful but not required for test suite BUILD_THIRDPARTY:BOOL=TRUE # JPEG2000 test files are available with git clone https://github.com/uclouvain/openjpeg-data.git OPJ_DATA_ROOT:PATH=$ENV{PWD}/data -# jpylyzer is available with on GitHub: https://github.com/openpreserve/jpylyzer +# jpylyzer is available with on GitHub: https://github.com/openpreserve/jpylyzer JPYLYZER_EXECUTABLE=$ENV{PWD}/jpylyzer/jpylyzer.${JPYLYZER_EXT} " ) #--------------------- -#1. openjpeg specific: +#1. openjpeg specific: set( CTEST_PROJECT_NAME "OPENJPEG" ) if(NOT EXISTS $ENV{OPJ_SOURCE_DIR}) message(FATAL_ERROR "OPJ_SOURCE_DIR not defined or does not exist:$ENV{OPJ_SOURCE_DIR}") diff --git a/wrapping/java/CMakeLists.txt b/wrapping/java/CMakeLists.txt index dd7b66c2..fb28c236 100644 --- a/wrapping/java/CMakeLists.txt +++ b/wrapping/java/CMakeLists.txt @@ -1,2 +1,2 @@ -# +# add_subdirectory(openjp2) From 44a499f2acf10b55172d07abf387e5a579a585f7 Mon Sep 17 00:00:00 2001 From: Matthieu Darbois Date: Tue, 3 May 2016 22:22:03 +0200 Subject: [PATCH 33/39] Update lcms2 (#773) Update to mm2/Little-CMS@e342f44 --- thirdparty/liblcms2/src/lcms2_internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/thirdparty/liblcms2/src/lcms2_internal.h b/thirdparty/liblcms2/src/lcms2_internal.h index e1219036..695d4b8d 100644 --- a/thirdparty/liblcms2/src/lcms2_internal.h +++ b/thirdparty/liblcms2/src/lcms2_internal.h @@ -101,7 +101,7 @@ // A fast way to convert from/to 16 <-> 8 bits #define FROM_8_TO_16(rgb) (cmsUInt16Number) ((((cmsUInt16Number) (rgb)) << 8)|(rgb)) -#define FROM_16_TO_8(rgb) (cmsUInt8Number) ((((rgb) * 65281 + 8388608) >> 24) & 0xFF) +#define FROM_16_TO_8(rgb) (cmsUInt8Number) ((((cmsUInt32Number)(rgb) * 65281U + 8388608U) >> 24) & 0xFFU) // Code analysis is broken on asserts #ifdef _MSC_VER From 8f9cc62b3f9a1da9712329ddcedb9750d585505c Mon Sep 17 00:00:00 2001 From: mayeut Date: Sun, 8 May 2016 18:40:12 +0200 Subject: [PATCH 34/39] Fix division by zero Fix uclouvain/openjpeg#733 --- src/lib/openjp2/tcd.c | 3 ++- tests/nonregression/test_suite.ctest.in | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lib/openjp2/tcd.c b/src/lib/openjp2/tcd.c index 7ecd97cf..b8cd3072 100644 --- a/src/lib/openjp2/tcd.c +++ b/src/lib/openjp2/tcd.c @@ -720,7 +720,8 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no, /* compute l_data_size with overflow check */ l_data_size = (OPJ_UINT32)(l_tilec->x1 - l_tilec->x0); - if ((((OPJ_UINT32)-1) / l_data_size) < (OPJ_UINT32)(l_tilec->y1 - l_tilec->y0)) { + /* issue 733, l_data_size == 0U, probably something wrong should be checked before getting here */ + if ((l_data_size > 0U) && ((((OPJ_UINT32)-1) / l_data_size) < (OPJ_UINT32)(l_tilec->y1 - l_tilec->y0))) { opj_event_msg(manager, EVT_ERROR, "Not enough memory for tile data\n"); return OPJ_FALSE; } diff --git a/tests/nonregression/test_suite.ctest.in b/tests/nonregression/test_suite.ctest.in index f22a89f5..c48f66b2 100644 --- a/tests/nonregression/test_suite.ctest.in +++ b/tests/nonregression/test_suite.ctest.in @@ -557,3 +557,5 @@ opj_decompress -i @INPUT_NR_PATH@/basn6a08.jp2 -o @TEMP_PATH@/basn6a08_tif-15.ti !opj_decompress -i @INPUT_NR_PATH@/issue725.jp2 -o @TEMP_PATH@/issue725.png # issue 726 opj_decompress -i @INPUT_NR_PATH@/issue726.j2k -o @TEMP_PATH@/issue726.png +# issue 733 +!opj_decompress -i @INPUT_NR_PATH@/issue733.jp2 -o @TEMP_PATH@/issue733.png From 162f6199c0cd3ec1c6c6dc65e41b2faab92b2d91 Mon Sep 17 00:00:00 2001 From: mayeut Date: Sun, 8 May 2016 19:18:05 +0200 Subject: [PATCH 35/39] Fix Heap Buffer Overflow in function color_cmyk_to_rgb Fix uclouvain/openjpeg#774 --- src/bin/common/color.c | 9 ++++++++- tests/nonregression/test_suite.ctest.in | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/bin/common/color.c b/src/bin/common/color.c index 944df73b..234c7bdf 100644 --- a/src/bin/common/color.c +++ b/src/bin/common/color.c @@ -855,7 +855,14 @@ void color_cmyk_to_rgb(opj_image_t *image) w = image->comps[0].w; h = image->comps[0].h; - if(image->numcomps < 4) return; + if ( + (image->numcomps < 4) + || (image->comps[0].dx != image->comps[1].dx) || (image->comps[0].dx != image->comps[2].dx) || (image->comps[0].dx != image->comps[3].dx) + || (image->comps[0].dy != image->comps[1].dy) || (image->comps[0].dy != image->comps[2].dy) || (image->comps[0].dy != image->comps[3].dy) + ) { + fprintf(stderr,"%s:%d:color_cmyk_to_rgb\n\tCAN NOT CONVERT\n", __FILE__,__LINE__); + return; + } max = w * h; diff --git a/tests/nonregression/test_suite.ctest.in b/tests/nonregression/test_suite.ctest.in index c48f66b2..13112216 100644 --- a/tests/nonregression/test_suite.ctest.in +++ b/tests/nonregression/test_suite.ctest.in @@ -559,3 +559,5 @@ opj_decompress -i @INPUT_NR_PATH@/basn6a08.jp2 -o @TEMP_PATH@/basn6a08_tif-15.ti opj_decompress -i @INPUT_NR_PATH@/issue726.j2k -o @TEMP_PATH@/issue726.png # issue 733 !opj_decompress -i @INPUT_NR_PATH@/issue733.jp2 -o @TEMP_PATH@/issue733.png +# issue 774 +!opj_decompress -i @INPUT_NR_PATH@/issue774.jp2 -o @TEMP_PATH@/issue774.png From 1a8318f6c24623189ecb65e049267c6f2e005c0e Mon Sep 17 00:00:00 2001 From: mayeut Date: Sun, 8 May 2016 20:10:13 +0200 Subject: [PATCH 36/39] Fix Out-of-Bounds Access in function opj_tgt_reset Fix uclouvain/openjpeg#775 --- src/lib/openjp2/j2k.c | 4 ++++ src/lib/openjp2/t2.c | 9 +++++++-- tests/nonregression/test_suite.ctest.in | 3 +++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c index 8086b004..9eaa155e 100644 --- a/src/lib/openjp2/j2k.c +++ b/src/lib/openjp2/j2k.c @@ -8889,6 +8889,10 @@ static OPJ_BOOL opj_j2k_read_SPCod_SPCoc( opj_j2k_t *p_j2k, opj_read_bytes(l_current_ptr,&l_tccp->cblksty ,1); /* SPcoc (G) */ ++l_current_ptr; + if (l_tccp->cblksty & 0xC0U) { /* 2 msb are reserved, assume we can't read */ + opj_event_msg(p_manager, EVT_ERROR, "Error reading SPCod SPCoc element, Invalid code-block style found\n"); + return OPJ_FALSE; + } opj_read_bytes(l_current_ptr,&l_tccp->qmfbid ,1); /* SPcoc (H) */ ++l_current_ptr; diff --git a/src/lib/openjp2/t2.c b/src/lib/openjp2/t2.c index ebc26b2d..5a8d440c 100644 --- a/src/lib/openjp2/t2.c +++ b/src/lib/openjp2/t2.c @@ -868,9 +868,14 @@ static OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2, /* reset tagtrees */ for (bandno = 0; bandno < l_res->numbands; ++bandno) { - opj_tcd_precinct_t *l_prc = &l_band->precincts[p_pi->precno]; - if ( ! ((l_band->x1-l_band->x0 == 0)||(l_band->y1-l_band->y0 == 0)) ) { + opj_tcd_precinct_t *l_prc = &l_band->precincts[p_pi->precno]; + if (!(p_pi->precno < (l_band->precincts_data_size / sizeof(opj_tcd_precinct_t)))) { + opj_event_msg(p_manager, EVT_ERROR, "Invalid precinct\n"); + return OPJ_FALSE; + } + + opj_tgt_reset(l_prc->incltree); opj_tgt_reset(l_prc->imsbtree); l_cblk = l_prc->cblks.dec; diff --git a/tests/nonregression/test_suite.ctest.in b/tests/nonregression/test_suite.ctest.in index 13112216..e1eb7027 100644 --- a/tests/nonregression/test_suite.ctest.in +++ b/tests/nonregression/test_suite.ctest.in @@ -561,3 +561,6 @@ opj_decompress -i @INPUT_NR_PATH@/issue726.j2k -o @TEMP_PATH@/issue726.png !opj_decompress -i @INPUT_NR_PATH@/issue733.jp2 -o @TEMP_PATH@/issue733.png # issue 774 !opj_decompress -i @INPUT_NR_PATH@/issue774.jp2 -o @TEMP_PATH@/issue774.png +# issue 775 +!opj_decompress -i @INPUT_NR_PATH@/issue775.j2k -o @TEMP_PATH@/issue775.png +!opj_decompress -i @INPUT_NR_PATH@/issue775-2.j2k -o @TEMP_PATH@/issue775-2.png From 6609719b409be038c2d41765b64e42f7b92f79cb Mon Sep 17 00:00:00 2001 From: mayeut Date: Sun, 8 May 2016 20:26:12 +0200 Subject: [PATCH 37/39] Correct expected result for test of issue 495 --- tests/nonregression/CMakeLists.txt | 1 + tests/nonregression/test_suite.ctest.in | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/nonregression/CMakeLists.txt b/tests/nonregression/CMakeLists.txt index 31af7c05..53cdc9f4 100644 --- a/tests/nonregression/CMakeLists.txt +++ b/tests/nonregression/CMakeLists.txt @@ -50,6 +50,7 @@ set(BLACKLIST_JPEG2000_TMP issue429.jp2 issue427-null-image-size.jp2 issue427-illegal-tile-offset.jp2 + issue495.jp2 ) # Define a list of file which should be gracefully rejected: diff --git a/tests/nonregression/test_suite.ctest.in b/tests/nonregression/test_suite.ctest.in index e1eb7027..d393e6c6 100644 --- a/tests/nonregression/test_suite.ctest.in +++ b/tests/nonregression/test_suite.ctest.in @@ -338,7 +338,7 @@ opj_decompress -i @INPUT_NR_PATH@/issue458.jp2 -o @TEMP_PATH@/issue458.jp2.pgx # issue 475 Invalid number of layers !opj_decompress -i @INPUT_NR_PATH@/issue475.jp2 -o @TEMP_PATH@/issue475.jp2.pgx # issue 495 Overflow op_image_comp_header_updat -opj_decompress -i @INPUT_NR_PATH@/issue495.jp2 -o @TEMP_PATH@/issue495.jp2.pgx +!opj_decompress -i @INPUT_NR_PATH@/issue495.jp2 -o @TEMP_PATH@/issue495.jp2.pgx # decode with specific area From aae066debc29f6fe44bfcda1206bba0a68dfd00e Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Tue, 10 May 2016 22:02:49 +0200 Subject: [PATCH 38/39] Add missing source for the JPIP library and executables (issue #658) (#659) They all need opj_malloc and other functions from opc_malloc.c. Signed-off-by: Stefan Weil --- src/lib/openjpip/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib/openjpip/CMakeLists.txt b/src/lib/openjpip/CMakeLists.txt index 858a1095..7348b1ef 100644 --- a/src/lib/openjpip/CMakeLists.txt +++ b/src/lib/openjpip/CMakeLists.txt @@ -36,6 +36,7 @@ set(OPENJPIP_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/session_manager.c ${CMAKE_CURRENT_SOURCE_DIR}/jpip_parser.c ${CMAKE_CURRENT_SOURCE_DIR}/sock_manager.c + ${OPENJPEG_SOURCE_DIR}/src/lib/openjp2/opj_malloc.c ) set(SERVER_SRCS From 4d2b6a671a0431722cd4845b246fe0a09f7ca934 Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Tue, 10 May 2016 22:08:49 +0200 Subject: [PATCH 39/39] Update implementation of opj_calloc (#705) --- src/lib/openjp2/opj_malloc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/openjp2/opj_malloc.c b/src/lib/openjp2/opj_malloc.c index e04db912..4f8b1d6f 100644 --- a/src/lib/openjp2/opj_malloc.c +++ b/src/lib/openjp2/opj_malloc.c @@ -196,10 +196,10 @@ void * opj_malloc(size_t size) } void * opj_calloc(size_t num, size_t size) { - if (size == 0U) { /* prevent implementation defined behavior of realloc */ + if (num == 0 || size == 0) { + /* prevent implementation defined behavior of realloc */ return NULL; } - /* according to C89 standard, num == 0 shall return a valid pointer */ return calloc(num, size); }