diff --git a/COPYRIGHT.txt b/COPYRIGHT.txt
index 9116e0eaaf2..3513ec564c4 100644
--- a/COPYRIGHT.txt
+++ b/COPYRIGHT.txt
@@ -372,7 +372,7 @@ License: BSD-3-clause
Files: thirdparty/libjpeg-turbo/*
Comment: libjpeg-turbo
-Copyright: 2009-2024, D. R. Commander
+Copyright: 2009-2025, D. R. Commander
2015, Viktor Szathmáry.
1991-2020, Thomas G. Lane, Guido Vollbeding
License: BSD-3-clause and IJG
diff --git a/thirdparty/README.md b/thirdparty/README.md
index 14cc8d7e1d9..62fe3e0f573 100644
--- a/thirdparty/README.md
+++ b/thirdparty/README.md
@@ -538,7 +538,7 @@ Patches:
## libjpeg-turbo
- Upstream: https://github.com/libjpeg-turbo/libjpeg-turbo
-- Version: 3.1.0 (20ade4dea9589515a69793e447a6c6220b464535, 2024)
+- Version: 3.1.3 (af9c1c268520a29adf98cad5138dafe612b3d318, 2025)
- License: BSD-3-Clause and IJG
Files extracted from upstream source:
diff --git a/thirdparty/libjpeg-turbo/LICENSE.md b/thirdparty/libjpeg-turbo/LICENSE.md
index a785258bcda..f299cf39e74 100644
--- a/thirdparty/libjpeg-turbo/LICENSE.md
+++ b/thirdparty/libjpeg-turbo/LICENSE.md
@@ -94,7 +94,7 @@ intended solely for clarification.
The Modified (3-clause) BSD License
===================================
-Copyright (C)2009-2024 D. R. Commander. All Rights Reserved.
+Copyright (C)2009-2025 D. R. Commander. All Rights Reserved.
Copyright (C)2015 Viktor Szathmáry. All Rights Reserved.
Redistribution and use in source and binary forms, with or without
diff --git a/thirdparty/libjpeg-turbo/patches/0001-cmake-generated-headers.patch b/thirdparty/libjpeg-turbo/patches/0001-cmake-generated-headers.patch
index a3c5de0b4bf..7d31486c376 100644
--- a/thirdparty/libjpeg-turbo/patches/0001-cmake-generated-headers.patch
+++ b/thirdparty/libjpeg-turbo/patches/0001-cmake-generated-headers.patch
@@ -1,280 +1,3 @@
-diff --git a/thirdparty/libjpeg-turbo/patches/0001-cmake-generated-headers.patch b/thirdparty/libjpeg-turbo/patches/0001-cmake-generated-headers.patch
-index 72354390a6..e69de29bb2 100644
---- a/thirdparty/libjpeg-turbo/patches/0001-cmake-generated-headers.patch
-+++ b/thirdparty/libjpeg-turbo/patches/0001-cmake-generated-headers.patch
-@@ -1,272 +0,0 @@
--diff --git a/thirdparty/libjpeg-turbo/src/jconfig.h b/thirdparty/libjpeg-turbo/src/jconfig.h
--new file mode 100644
--index 0000000000..42d9654c0f
----- /dev/null
--+++ b/thirdparty/libjpeg-turbo/src/jconfig.h
--@@ -0,0 +1,62 @@
--+// Originally generated by libjpeg-turbo's cmake build, then modified to support multiple platforms.
--+
--+/* Version ID for the JPEG library.
--+ * Might be useful for tests like "#if JPEG_LIB_VERSION >= 60".
--+ */
--+#define JPEG_LIB_VERSION 62
--+
--+/* libjpeg-turbo version */
--+#define LIBJPEG_TURBO_VERSION 3.1.0
--+
--+/* libjpeg-turbo version in integer form */
--+#define LIBJPEG_TURBO_VERSION_NUMBER 3001000
--+
--+/* Support arithmetic encoding when using 8-bit samples */
--+#define C_ARITH_CODING_SUPPORTED 1
--+
--+/* Support arithmetic decoding when using 8-bit samples */
--+#define D_ARITH_CODING_SUPPORTED 1
--+
--+/* Support in-memory source/destination managers */
--+#define MEM_SRCDST_SUPPORTED 1
--+
--+/* Use accelerated SIMD routines when using 8-bit samples */
--+//#define WITH_SIMD 1
--+
--+/* This version of libjpeg-turbo supports run-time selection of data precision,
--+ * so BITS_IN_JSAMPLE is no longer used to specify the data precision at build
--+ * time. However, some downstream software expects the macro to be defined.
--+ * Since 12-bit data precision is an opt-in feature that requires explicitly
--+ * calling 12-bit-specific libjpeg API functions and using 12-bit-specific data
--+ * types, the unmodified portion of the libjpeg API still behaves as if it were
--+ * built for 8-bit precision, and JSAMPLE is still literally an 8-bit data
--+ * type. Thus, it is correct to define BITS_IN_JSAMPLE to 8 here.
--+ */
--+#ifndef BITS_IN_JSAMPLE
--+#define BITS_IN_JSAMPLE 8
--+#endif
--+
--+#ifdef _WIN32
--+
--+#undef RIGHT_SHIFT_IS_UNSIGNED
--+
--+/* Define "boolean" as unsigned char, not int, per Windows custom */
--+#ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
--+typedef unsigned char boolean;
--+#endif
--+#define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
--+
--+/* Define "INT32" as int, not long, per Windows custom */
--+#if !(defined(_BASETSD_H_) || defined(_BASETSD_H)) /* don't conflict if basetsd.h already read */
--+typedef short INT16;
--+typedef signed int INT32;
--+#endif
--+#define XMD_H /* prevent jmorecfg.h from redefining it */
--+
--+#else
--+
--+/* Define if your (broken) compiler shifts signed values as if they were
--+ unsigned. */
--+/* #undef RIGHT_SHIFT_IS_UNSIGNED */
--+
--+#endif
--diff --git a/thirdparty/libjpeg-turbo/src/jconfigint.h b/thirdparty/libjpeg-turbo/src/jconfigint.h
--new file mode 100644
----- /dev/null
--+++ b/thirdparty/libjpeg-turbo/src/jconfigint.h
--@@ -0,0 +1,102 @@
--+// Originally generated by libjpeg-turbo's cmake build, then modified to support multiple platforms.
--+
--+/* libjpeg-turbo build number */
--+#define BUILD "20250317"
--+
--+/* How to hide global symbols. */
--+#ifndef HIDDEN
--+ #if defined(__GNUC__) && (__GNUC__ >= 4) && !defined(__MINGW32__)
--+ #define HIDDEN __attribute__((visibility("hidden")))
--+ #else
--+ #define HIDDEN
--+ #endif
--+#endif
--+
--+/* Compiler's inline keyword */
--+#undef inline
--+
--+/* How to obtain function inlining. */
--+#if defined(__GNUC__) && (__GNUC__ >= 4) && !defined(__MINGW32__)
--+ #define INLINE __inline__ __attribute__((always_inline))
--+#else
--+ #define INLINE inline
--+#endif
--+
--+/* How to obtain thread-local storage */
--+#if defined(_MSC_VER)
--+#define THREAD_LOCAL __declspec(thread)
--+#else
--+#define THREAD_LOCAL __thread
--+#endif
--+
--+/* Define to the full name of this package. */
--+#define PACKAGE_NAME "libjpeg-turbo"
--+
--+/* Version number of package */
--+#define VERSION "3.1.0"
--+
--+/* The size of `size_t', as computed by sizeof. */
--+#if defined(__SIZEOF_SIZE_T__)
--+ #define SIZEOF_SIZE_T __SIZEOF_SIZE_T__
--+#elif defined(_WIN64)
--+ #define SIZEOF_SIZE_T 8
--+#elif defined(_WIN32)
--+ #define SIZEOF_SIZE_T 4
--+#else
--+ #error "Cannot determine size of size_t"
--+#endif
--+
--+/* Define if your compiler has __builtin_ctzl() and sizeof(unsigned long) == sizeof(size_t). */
--+#if defined(__GNUC__)
--+ #define HAVE_BUILTIN_CTZL
--+#endif
--+
--+/* Define to 1 if you have the header file. */
--+/* #undef HAVE_INTRIN_H */
--+
--+#if defined(_MSC_VER) && defined(HAVE_INTRIN_H)
--+#if (SIZEOF_SIZE_T == 8)
--+#define HAVE_BITSCANFORWARD64
--+#elif (SIZEOF_SIZE_T == 4)
--+#define HAVE_BITSCANFORWARD
--+#endif
--+#endif
--+
--+#if defined(__has_attribute)
--+#if __has_attribute(fallthrough)
--+#define FALLTHROUGH __attribute__((fallthrough));
--+#else
--+#define FALLTHROUGH
--+#endif
--+#else
--+#define FALLTHROUGH
--+#endif
--+
--+/*
--+ * Define BITS_IN_JSAMPLE as either
--+ * 8 for 8-bit sample values (the usual setting)
--+ * 12 for 12-bit sample values
--+ * Only 8 and 12 are legal data precisions for lossy JPEG according to the
--+ * JPEG standard, and the IJG code does not support anything else!
--+ */
--+
--+#ifndef BITS_IN_JSAMPLE
--+#define BITS_IN_JSAMPLE 8 /* use 8 or 12 */
--+#endif
--+
--+#undef C_ARITH_CODING_SUPPORTED
--+#undef D_ARITH_CODING_SUPPORTED
--+#undef WITH_SIMD
--+
--+#if BITS_IN_JSAMPLE == 8
--+
--+/* Support arithmetic encoding */
--+#define C_ARITH_CODING_SUPPORTED 1
--+
--+/* Support arithmetic decoding */
--+#define D_ARITH_CODING_SUPPORTED 1
--+
--+/* Use accelerated SIMD routines. */
--+//#define WITH_SIMD 1
--+
--+#endif
--diff --git a/thirdparty/libjpeg-turbo/src/jmorecfg.h b/thirdparty/libjpeg-turbo/src/jmorecfg.h
----- a/thirdparty/libjpeg-turbo/src/jmorecfg.h
--+++ b/thirdparty/libjpeg-turbo/src/jmorecfg.h
--@@ -1,3 +1,5 @@
--+// Modified to remove lossless jpeg support.
--+
-- /*
-- * jmorecfg.h
-- *
--@@ -8,6 +10,6 @@
-- * Copyright (C) 1999, Ken Murchison.
-- * libjpeg-turbo Modifications:
-- * Copyright (C) 2009, 2011, 2014-2015, 2018, 2020, 2022, D. R. Commander.
-- * For conditions of distribution and use, see the accompanying README.ijg
-- * file.
-- *
--@@ -242,7 +244,7 @@ typedef int boolean;
--
-- #define C_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
-- #define C_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
---#define C_LOSSLESS_SUPPORTED /* Lossless JPEG? */
--+//#define C_LOSSLESS_SUPPORTED /* Lossless JPEG? */
-- #define ENTROPY_OPT_SUPPORTED /* Optimization of entropy coding parms? */
-- /* Note: if you selected 12-bit data precision, it is dangerous to turn off
-- * ENTROPY_OPT_SUPPORTED. The standard Huffman tables are only good for 8-bit
--@@ -259,7 +263,7 @@ typedef int boolean;
--
-- #define D_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
-- #define D_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
---#define D_LOSSLESS_SUPPORTED /* Lossless JPEG? */
--+//#define D_LOSSLESS_SUPPORTED /* Lossless JPEG? */
-- #define SAVE_MARKERS_SUPPORTED /* jpeg_save_markers() needed? */
-- #define BLOCK_SMOOTHING_SUPPORTED /* Block smoothing? (Progressive only) */
-- #define IDCT_SCALING_SUPPORTED /* Output rescaling via IDCT? */
--diff --git a/thirdparty/libjpeg-turbo/src/jversion.h b/thirdparty/libjpeg-turbo/src/jversion.h
--new file mode 100644
----- /dev/null
--+++ b/thirdparty/libjpeg-turbo/src/jversion.h
--@@ -0,0 +18446744073709551615,58 @@
--+// Originally generated by libjpeg-turbo's cmake build, then modified to support multiple platforms.
--+
--+/*
--+ * jversion.h
--+ *
--+ * This file was part of the Independent JPEG Group's software:
--+ * Copyright (C) 1991-2020, Thomas G. Lane, Guido Vollbeding.
--+ * libjpeg-turbo Modifications:
--+ * Copyright (C) 2010, 2012-2024, D. R. Commander.
--+ * For conditions of distribution and use, see the accompanying README.ijg
--+ * file.
--+ *
--+ * This file contains software version identification.
--+ */
--+
--+
--+#if JPEG_LIB_VERSION >= 80
--+
--+#define JVERSION "8d 15-Jan-2012"
--+
--+#elif JPEG_LIB_VERSION >= 70
--+
--+#define JVERSION "7 27-Jun-2009"
--+
--+#else
--+
--+#define JVERSION "6b 27-Mar-1998"
--+
--+#endif
--+
--+/*
--+ * NOTE: It is our convention to place the authors in the following order:
--+ * - libjpeg-turbo authors (2009-) in descending order of the date of their
--+ * most recent contribution to the project, then in ascending order of the
--+ * date of their first contribution to the project, then in alphabetical
--+ * order
--+ * - Upstream authors in descending order of the date of the first inclusion of
--+ * their code
--+ */
--+
--+#define JCOPYRIGHT1 \
--+ "Copyright (C) 2009-2024 D. R. Commander\n" \
--+ "Copyright (C) 2015, 2020 Google, Inc.\n" \
--+ "Copyright (C) 2019-2020 Arm Limited\n" \
--+ "Copyright (C) 2015-2016, 2018 Matthieu Darbois\n" \
--+ "Copyright (C) 2011-2016 Siarhei Siamashka\n" \
--+ "Copyright (C) 2015 Intel Corporation\n"
--+#define JCOPYRIGHT2 \
--+ "Copyright (C) 2013-2014 Linaro Limited\n" \
--+ "Copyright (C) 2013-2014 MIPS Technologies, Inc.\n" \
--+ "Copyright (C) 2009, 2012 Pierre Ossman for Cendio AB\n" \
--+ "Copyright (C) 2009-2011 Nokia Corporation and/or its subsidiary(-ies)\n" \
--+ "Copyright (C) 1999-2006 MIYASAKA Masaru\n" \
--+ "Copyright (C) 1999 Ken Murchison\n" \
--+ "Copyright (C) 1991-2020 Thomas G. Lane, Guido Vollbeding\n"
--+
--+#define JCOPYRIGHT_SHORT \
--+ "Copyright (C) 1991-2024 The libjpeg-turbo Project and many others"
diff --git a/thirdparty/libjpeg-turbo/src/jconfig.h b/thirdparty/libjpeg-turbo/src/jconfig.h
new file mode 100644
index 0000000000..42d9654c0f
diff --git a/thirdparty/libjpeg-turbo/patches/0002-disable-16bitlossless.patch b/thirdparty/libjpeg-turbo/patches/0002-disable-16bitlossless.patch
index beb2a9b0aa1..c93a8d977b1 100644
--- a/thirdparty/libjpeg-turbo/patches/0002-disable-16bitlossless.patch
+++ b/thirdparty/libjpeg-turbo/patches/0002-disable-16bitlossless.patch
@@ -1,14 +1,21 @@
-commit 462c1cd875ae8f6b5f6406dda01881fb173ac30c
-Author: Daniel Kinsman
-Date: Thu Mar 20 12:21:28 2025 +1100
-
- remove unneeded source files and lossless jpeg support
-
+diff --git a/thirdparty/README.md b/thirdparty/README.md
+index c22ef77af7..52b635df05 100644
+--- a/thirdparty/README.md
++++ b/thirdparty/README.md
+@@ -539,7 +539,7 @@ Patches:
+ ## libjpeg-turbo
+
+ - Upstream: https://github.com/libjpeg-turbo/libjpeg-turbo
+-- Version: 3.1.0 (20ade4dea9589515a69793e447a6c6220b464535, 2024)
++- Version: 3.1.3 (af9c1c268520a29adf98cad5138dafe612b3d318, 2025)
+ - License: BSD-3-Clause and IJG
+
+ Files extracted from upstream source:
diff --git a/thirdparty/libjpeg-turbo/src/turbojpeg.c b/thirdparty/libjpeg-turbo/src/turbojpeg.c
-index 389aea55d3..eec8e2a616 100644
+index 45fc0f954c..d514da43d2 100644
--- a/thirdparty/libjpeg-turbo/src/turbojpeg.c
+++ b/thirdparty/libjpeg-turbo/src/turbojpeg.c
-@@ -1200,9 +1200,6 @@ bailout:
+@@ -1196,9 +1196,6 @@ bailout:
#define BITS_IN_JSAMPLE 12
#include "turbojpeg-mp.c"
#undef BITS_IN_JSAMPLE
diff --git a/thirdparty/libjpeg-turbo/patches/0003-remove-bmp-ppm-support.patch b/thirdparty/libjpeg-turbo/patches/0003-remove-bmp-ppm-support.patch
index e4214269a25..b16e81ccd1b 100644
--- a/thirdparty/libjpeg-turbo/patches/0003-remove-bmp-ppm-support.patch
+++ b/thirdparty/libjpeg-turbo/patches/0003-remove-bmp-ppm-support.patch
@@ -1,5 +1,18 @@
+diff --git a/thirdparty/README.md b/thirdparty/README.md
+index c22ef77af7..52b635df05 100644
+--- a/thirdparty/README.md
++++ b/thirdparty/README.md
+@@ -539,7 +539,7 @@ Patches:
+ ## libjpeg-turbo
+
+ - Upstream: https://github.com/libjpeg-turbo/libjpeg-turbo
+-- Version: 3.1.0 (20ade4dea9589515a69793e447a6c6220b464535, 2024)
++- Version: 3.1.3 (af9c1c268520a29adf98cad5138dafe612b3d318, 2025)
+ - License: BSD-3-Clause and IJG
+
+ Files extracted from upstream source:
diff --git a/thirdparty/libjpeg-turbo/src/turbojpeg-mp.c b/thirdparty/libjpeg-turbo/src/turbojpeg-mp.c
-index 1fa63b8185..72f99e236a 100644
+index 6fecc5cb80..21d26536c1 100644
--- a/thirdparty/libjpeg-turbo/src/turbojpeg-mp.c
+++ b/thirdparty/libjpeg-turbo/src/turbojpeg-mp.c
@@ -286,271 +286,6 @@ bailout:
@@ -275,10 +288,20 @@ index 1fa63b8185..72f99e236a 100644
#undef _JSAMPROW
#undef _buffer
diff --git a/thirdparty/libjpeg-turbo/src/turbojpeg.c b/thirdparty/libjpeg-turbo/src/turbojpeg.c
-index eec8e2a616..8ce446148a 100644
+index 45fc0f954c..969174f72e 100644
--- a/thirdparty/libjpeg-turbo/src/turbojpeg.c
+++ b/thirdparty/libjpeg-turbo/src/turbojpeg.c
-@@ -3095,48 +3095,3 @@ bailout:
+@@ -1196,9 +1196,6 @@ bailout:
+ #define BITS_IN_JSAMPLE 12
+ #include "turbojpeg-mp.c"
+ #undef BITS_IN_JSAMPLE
+-#define BITS_IN_JSAMPLE 16
+-#include "turbojpeg-mp.c"
+-#undef BITS_IN_JSAMPLE
+
+ /* TurboJPEG 1.2+ */
+ DLLEXPORT int tjCompress2(tjhandle handle, const unsigned char *srcBuf,
+@@ -3094,48 +3091,3 @@ bailout:
free(sizes);
return retval;
}
diff --git a/thirdparty/libjpeg-turbo/src/cmyk.h b/thirdparty/libjpeg-turbo/src/cmyk.h
index 4127b14d4ed..586db441275 100644
--- a/thirdparty/libjpeg-turbo/src/cmyk.h
+++ b/thirdparty/libjpeg-turbo/src/cmyk.h
@@ -1,7 +1,7 @@
/*
* cmyk.h
*
- * Copyright (C) 2017-2018, 2022, 2024, D. R. Commander.
+ * Copyright (C) 2017-2018, 2022, 2024-2025, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
@@ -14,9 +14,9 @@
#ifndef CMYK_H
#define CMYK_H
-#include
+#include "jinclude.h"
#define JPEG_INTERNALS
-#include
+#include "jpeglib.h"
#include "jsamplecomp.h"
diff --git a/thirdparty/libjpeg-turbo/src/jcapimin.c b/thirdparty/libjpeg-turbo/src/jcapimin.c
index eb4599fbfad..e99569035ba 100644
--- a/thirdparty/libjpeg-turbo/src/jcapimin.c
+++ b/thirdparty/libjpeg-turbo/src/jcapimin.c
@@ -195,13 +195,19 @@ jpeg_finish_compress(j_compress_ptr cinfo)
* all work is being done from the coefficient buffer.
*/
if (cinfo->data_precision <= 8) {
+ if (cinfo->coef->compress_data == NULL)
+ ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
if (!(*cinfo->coef->compress_data) (cinfo, (JSAMPIMAGE)NULL))
ERREXIT(cinfo, JERR_CANT_SUSPEND);
} else if (cinfo->data_precision <= 12) {
+ if (cinfo->coef->compress_data_12 == NULL)
+ ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
if (!(*cinfo->coef->compress_data_12) (cinfo, (J12SAMPIMAGE)NULL))
ERREXIT(cinfo, JERR_CANT_SUSPEND);
} else {
#ifdef C_LOSSLESS_SUPPORTED
+ if (cinfo->coef->compress_data_16 == NULL)
+ ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
if (!(*cinfo->coef->compress_data_16) (cinfo, (J16SAMPIMAGE)NULL))
ERREXIT(cinfo, JERR_CANT_SUSPEND);
#else
diff --git a/thirdparty/libjpeg-turbo/src/jcapistd.c b/thirdparty/libjpeg-turbo/src/jcapistd.c
index 2226094ba65..b61590df9df 100644
--- a/thirdparty/libjpeg-turbo/src/jcapistd.c
+++ b/thirdparty/libjpeg-turbo/src/jcapistd.c
@@ -130,6 +130,8 @@ _jpeg_write_scanlines(j_compress_ptr cinfo, _JSAMPARRAY scanlines,
num_lines = rows_left;
row_ctr = 0;
+ if (cinfo->main->_process_data == NULL)
+ ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
(*cinfo->main->_process_data) (cinfo, scanlines, &row_ctr, num_lines);
cinfo->next_scanline += row_ctr;
return row_ctr;
@@ -187,6 +189,8 @@ _jpeg_write_raw_data(j_compress_ptr cinfo, _JSAMPIMAGE data,
ERREXIT(cinfo, JERR_BUFFER_SIZE);
/* Directly compress the row. */
+ if (cinfo->coef->_compress_data == NULL)
+ ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
if (!(*cinfo->coef->_compress_data) (cinfo, data)) {
/* If compressor did not consume the whole row, suspend processing. */
return 0;
diff --git a/thirdparty/libjpeg-turbo/src/jccoefct.c b/thirdparty/libjpeg-turbo/src/jccoefct.c
index 2a5dde2d07e..4a47b3cbe5c 100644
--- a/thirdparty/libjpeg-turbo/src/jccoefct.c
+++ b/thirdparty/libjpeg-turbo/src/jccoefct.c
@@ -4,7 +4,7 @@
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1994-1997, Thomas G. Lane.
* libjpeg-turbo Modifications:
- * Copyright (C) 2022, D. R. Commander.
+ * Copyright (C) 2022, 2024, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
@@ -414,6 +414,7 @@ _jinit_c_coef_controller(j_compress_ptr cinfo, boolean need_full_buffer)
coef = (my_coef_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(my_coef_controller));
+ memset(coef, 0, sizeof(my_coef_controller));
cinfo->coef = (struct jpeg_c_coef_controller *)coef;
coef->pub.start_pass = start_pass_coef;
diff --git a/thirdparty/libjpeg-turbo/src/jchuff.c b/thirdparty/libjpeg-turbo/src/jchuff.c
index 8cdd5bd35dc..781e1ca7043 100644
--- a/thirdparty/libjpeg-turbo/src/jchuff.c
+++ b/thirdparty/libjpeg-turbo/src/jchuff.c
@@ -6,7 +6,7 @@
* Lossless JPEG Modifications:
* Copyright (C) 1999, Ken Murchison.
* libjpeg-turbo Modifications:
- * Copyright (C) 2009-2011, 2014-2016, 2018-2024, D. R. Commander.
+ * Copyright (C) 2009-2011, 2014-2016, 2018-2025, D. R. Commander.
* Copyright (C) 2015, Matthieu Darbois.
* Copyright (C) 2018, Matthias Räncker.
* Copyright (C) 2020, Arm Limited.
@@ -55,7 +55,8 @@ typedef size_t bit_buf_type;
* retain the old Huffman encoder behavior when using the GAS implementation.
*/
#if defined(WITH_SIMD) && !(defined(__arm__) || defined(__aarch64__) || \
- defined(_M_ARM) || defined(_M_ARM64))
+ defined(_M_ARM) || defined(_M_ARM64) || \
+ defined(_M_ARM64EC))
typedef unsigned long long simd_bit_buf_type;
#else
typedef bit_buf_type simd_bit_buf_type;
diff --git a/thirdparty/libjpeg-turbo/src/jcmainct.c b/thirdparty/libjpeg-turbo/src/jcmainct.c
index 954e94017c9..b72f8deb6c9 100644
--- a/thirdparty/libjpeg-turbo/src/jcmainct.c
+++ b/thirdparty/libjpeg-turbo/src/jcmainct.c
@@ -159,6 +159,7 @@ _jinit_c_main_controller(j_compress_ptr cinfo, boolean need_full_buffer)
main_ptr = (my_main_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(my_main_controller));
+ memset(main_ptr, 0, sizeof(my_main_controller));
cinfo->main = (struct jpeg_c_main_controller *)main_ptr;
main_ptr->pub.start_pass = start_pass_main;
diff --git a/thirdparty/libjpeg-turbo/src/jdapistd.c b/thirdparty/libjpeg-turbo/src/jdapistd.c
index d0e5c0e5b9f..813e21268e8 100644
--- a/thirdparty/libjpeg-turbo/src/jdapistd.c
+++ b/thirdparty/libjpeg-turbo/src/jdapistd.c
@@ -4,7 +4,7 @@
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1994-1996, Thomas G. Lane.
* libjpeg-turbo Modifications:
- * Copyright (C) 2010, 2015-2020, 2022-2024, D. R. Commander.
+ * Copyright (C) 2010, 2015-2020, 2022-2025, D. R. Commander.
* Copyright (C) 2015, Google, Inc.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
@@ -128,19 +128,28 @@ output_pass_setup(j_decompress_ptr cinfo)
}
/* Process some data */
last_scanline = cinfo->output_scanline;
- if (cinfo->data_precision <= 8)
+ if (cinfo->data_precision <= 8) {
+ if (cinfo->main->process_data == NULL)
+ ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
(*cinfo->main->process_data) (cinfo, (JSAMPARRAY)NULL,
&cinfo->output_scanline, (JDIMENSION)0);
- else if (cinfo->data_precision <= 12)
+ } else if (cinfo->data_precision <= 12) {
+ if (cinfo->main->process_data_12 == NULL)
+ ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
(*cinfo->main->process_data_12) (cinfo, (J12SAMPARRAY)NULL,
&cinfo->output_scanline,
(JDIMENSION)0);
+ } else {
#ifdef D_LOSSLESS_SUPPORTED
- else
+ if (cinfo->main->process_data_16 == NULL)
+ ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
(*cinfo->main->process_data_16) (cinfo, (J16SAMPARRAY)NULL,
&cinfo->output_scanline,
(JDIMENSION)0);
+#else
+ ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
#endif
+ }
if (cinfo->output_scanline == last_scanline)
return FALSE; /* No progress made, must suspend */
}
@@ -345,6 +354,8 @@ _jpeg_read_scanlines(j_decompress_ptr cinfo, _JSAMPARRAY scanlines,
/* Process some data */
row_ctr = 0;
+ if (cinfo->main->_process_data == NULL)
+ ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
(*cinfo->main->_process_data) (cinfo, scanlines, &row_ctr, max_lines);
cinfo->output_scanline += row_ctr;
return row_ctr;
@@ -397,7 +408,8 @@ read_and_discard_scanlines(j_decompress_ptr cinfo, JDIMENSION num_lines)
void (*color_quantize) (j_decompress_ptr cinfo, _JSAMPARRAY input_buf,
_JSAMPARRAY output_buf, int num_rows) = NULL;
- if (cinfo->cconvert && cinfo->cconvert->_color_convert) {
+ if (!master->using_merged_upsample && cinfo->cconvert &&
+ cinfo->cconvert->_color_convert) {
color_convert = cinfo->cconvert->_color_convert;
cinfo->cconvert->_color_convert = noop_convert;
/* This just prevents UBSan from complaining about adding 0 to a NULL
@@ -406,7 +418,8 @@ read_and_discard_scanlines(j_decompress_ptr cinfo, JDIMENSION num_lines)
scanlines = &dummy_row;
}
- if (cinfo->cquantize && cinfo->cquantize->_color_quantize) {
+ if (cinfo->quantize_colors && cinfo->cquantize &&
+ cinfo->cquantize->_color_quantize) {
color_quantize = cinfo->cquantize->_color_quantize;
cinfo->cquantize->_color_quantize = noop_quantize;
}
@@ -691,6 +704,8 @@ _jpeg_read_raw_data(j_decompress_ptr cinfo, _JSAMPIMAGE data,
ERREXIT(cinfo, JERR_BUFFER_SIZE);
/* Decompress directly into user's buffer. */
+ if (cinfo->coef->_decompress_data == NULL)
+ ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
if (!(*cinfo->coef->_decompress_data) (cinfo, data))
return 0; /* suspension forced, can do nothing more */
diff --git a/thirdparty/libjpeg-turbo/src/jdatadst-tj.c b/thirdparty/libjpeg-turbo/src/jdatadst-tj.c
index 270b2c2c3ea..e4a97d2bc42 100644
--- a/thirdparty/libjpeg-turbo/src/jdatadst-tj.c
+++ b/thirdparty/libjpeg-turbo/src/jdatadst-tj.c
@@ -5,7 +5,7 @@
* Copyright (C) 1994-1996, Thomas G. Lane.
* Modified 2009-2012 by Guido Vollbeding.
* libjpeg-turbo Modifications:
- * Copyright (C) 2011, 2014, 2016, 2019, 2022-2023, D. R. Commander.
+ * Copyright (C) 2011, 2014, 2016, 2019, 2022-2023, 2025, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
@@ -181,7 +181,7 @@ jpeg_mem_dest_tj(j_compress_ptr cinfo, unsigned char **outbuffer,
dest->outsize = outsize;
dest->alloc = alloc;
- if (*outbuffer == NULL || *outsize == 0) {
+ if (*outbuffer == NULL || (*outsize == 0 && !reused)) {
if (alloc) {
/* Allocate initial buffer */
dest->newbuffer = *outbuffer = (unsigned char *)MALLOC(OUTPUT_BUF_SIZE);
diff --git a/thirdparty/libjpeg-turbo/src/jdcoefct.c b/thirdparty/libjpeg-turbo/src/jdcoefct.c
index 40ce27259ba..194d5a5cb7b 100644
--- a/thirdparty/libjpeg-turbo/src/jdcoefct.c
+++ b/thirdparty/libjpeg-turbo/src/jdcoefct.c
@@ -5,7 +5,7 @@
* Copyright (C) 1994-1997, Thomas G. Lane.
* libjpeg-turbo Modifications:
* Copyright 2009 Pierre Ossman for Cendio AB
- * Copyright (C) 2010, 2015-2016, 2019-2020, 2022-2023, D. R. Commander.
+ * Copyright (C) 2010, 2015-2016, 2019-2020, 2022-2024, D. R. Commander.
* Copyright (C) 2015, 2020, Google, Inc.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
@@ -824,6 +824,7 @@ _jinit_d_coef_controller(j_decompress_ptr cinfo, boolean need_full_buffer)
coef = (my_coef_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(my_coef_controller));
+ memset(coef, 0, sizeof(my_coef_controller));
cinfo->coef = (struct jpeg_d_coef_controller *)coef;
coef->pub.start_input_pass = start_input_pass;
coef->pub.start_output_pass = start_output_pass;
diff --git a/thirdparty/libjpeg-turbo/src/jdmainct.c b/thirdparty/libjpeg-turbo/src/jdmainct.c
index fed1866ee98..fc97073e3d8 100644
--- a/thirdparty/libjpeg-turbo/src/jdmainct.c
+++ b/thirdparty/libjpeg-turbo/src/jdmainct.c
@@ -450,6 +450,7 @@ _jinit_d_main_controller(j_decompress_ptr cinfo, boolean need_full_buffer)
main_ptr = (my_main_ptr)
(*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
sizeof(my_main_controller));
+ memset(main_ptr, 0, sizeof(my_main_controller));
cinfo->main = (struct jpeg_d_main_controller *)main_ptr;
main_ptr->pub.start_pass = start_pass_main;
diff --git a/thirdparty/libjpeg-turbo/src/jdsample.c b/thirdparty/libjpeg-turbo/src/jdsample.c
index e5a127de42b..022471dc37e 100644
--- a/thirdparty/libjpeg-turbo/src/jdsample.c
+++ b/thirdparty/libjpeg-turbo/src/jdsample.c
@@ -5,7 +5,7 @@
* Copyright (C) 1991-1996, Thomas G. Lane.
* libjpeg-turbo Modifications:
* Copyright 2009 Pierre Ossman for Cendio AB
- * Copyright (C) 2010, 2015-2016, 2022, 2024, D. R. Commander.
+ * Copyright (C) 2010, 2015-2016, 2022, 2024-2025, D. R. Commander.
* Copyright (C) 2014, MIPS Technologies, Inc., California.
* Copyright (C) 2015, Google, Inc.
* Copyright (C) 2019-2020, Arm Limited.
@@ -501,7 +501,8 @@ _jinit_upsampler(j_decompress_ptr cinfo)
v_in_group * 2 == v_out_group && do_fancy) {
/* Non-fancy upsampling is handled by the generic method */
#if defined(WITH_SIMD) && (defined(__arm__) || defined(__aarch64__) || \
- defined(_M_ARM) || defined(_M_ARM64))
+ defined(_M_ARM) || defined(_M_ARM64) || \
+ defined(_M_ARM64EC))
if (jsimd_can_h1v2_fancy_upsample())
upsample->methods[ci] = jsimd_h1v2_fancy_upsample;
else
diff --git a/thirdparty/libjpeg-turbo/src/jpeg_nbits.c b/thirdparty/libjpeg-turbo/src/jpeg_nbits.c
index c8ee6b056cb..752a163653e 100644
--- a/thirdparty/libjpeg-turbo/src/jpeg_nbits.c
+++ b/thirdparty/libjpeg-turbo/src/jpeg_nbits.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2024, D. R. Commander.
+ * Copyright (C) 2024-2025, D. R. Commander.
*
* For conditions of distribution and use, see the accompanying README.ijg
* file.
@@ -17,7 +17,7 @@
* encoders can reuse jpeg_nbits_table from the SSE2 baseline Huffman encoder.
*/
#if (defined(__x86_64__) || defined(__i386__) || defined(_M_IX86) || \
- defined(_M_X64)) && defined(WITH_SIMD)
+ (defined(_M_X64) && !defined(_M_ARM64EC))) && defined(WITH_SIMD)
#undef INCLUDE_JPEG_NBITS_TABLE
#endif
diff --git a/thirdparty/libjpeg-turbo/src/jpeg_nbits.h b/thirdparty/libjpeg-turbo/src/jpeg_nbits.h
index 6481a1228d1..61666fd57a9 100644
--- a/thirdparty/libjpeg-turbo/src/jpeg_nbits.h
+++ b/thirdparty/libjpeg-turbo/src/jpeg_nbits.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2014, 2021, 2024, D. R. Commander.
+ * Copyright (C) 2014, 2021, 2024-2025, D. R. Commander.
* Copyright (C) 2014, Olle Liljenzin.
* Copyright (C) 2020, Arm Limited.
*
@@ -23,7 +23,7 @@
/* NOTE: Both GCC and Clang define __GNUC__ */
#if (defined(__GNUC__) && (defined(__arm__) || defined(__aarch64__))) || \
- defined(_M_ARM) || defined(_M_ARM64)
+ defined(_M_ARM) || defined(_M_ARM64) || defined(_M_ARM64EC)
#if !defined(__thumb__) || defined(__thumb2__)
#define USE_CLZ_INTRINSIC
#endif
diff --git a/thirdparty/libjpeg-turbo/src/turbojpeg-mp.c b/thirdparty/libjpeg-turbo/src/turbojpeg-mp.c
index 72f99e236ab..21d26536c18 100644
--- a/thirdparty/libjpeg-turbo/src/turbojpeg-mp.c
+++ b/thirdparty/libjpeg-turbo/src/turbojpeg-mp.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C)2009-2024 D. R. Commander. All Rights Reserved.
+ * Copyright (C)2009-2025 D. R. Commander. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -113,7 +113,7 @@ DLLEXPORT int GET_NAME(tj3Compress, BITS_IN_JSAMPLE)
#endif
cinfo->data_precision = this->precision;
- setCompDefaults(this, pixelFormat);
+ setCompDefaults(this, pixelFormat, FALSE);
if (this->noRealloc) alloc = FALSE;
jpeg_mem_dest_tj(cinfo, jpegBuf, jpegSize, alloc);
diff --git a/thirdparty/libjpeg-turbo/src/turbojpeg.c b/thirdparty/libjpeg-turbo/src/turbojpeg.c
index 8ce446148a0..969174f72eb 100644
--- a/thirdparty/libjpeg-turbo/src/turbojpeg.c
+++ b/thirdparty/libjpeg-turbo/src/turbojpeg.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C)2009-2024 D. R. Commander. All Rights Reserved.
+ * Copyright (C)2009-2025 D. R. Commander. All Rights Reserved.
* Copyright (C)2021 Alex Richardson. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -35,17 +35,17 @@
#if !defined(_MSC_VER) || _MSC_VER > 1600
#include
#endif
-#include
+#include "jinclude.h"
#define JPEG_INTERNALS
-#include
-#include
+#include "jpeglib.h"
+#include "jerror.h"
#include
#include
-#include "./turbojpeg.h"
-#include "./tjutil.h"
+#include "turbojpeg.h"
+#include "tjutil.h"
#include "transupp.h"
-#include "./jpegapicomp.h"
-#include "./cdjpeg.h"
+#include "jpegapicomp.h"
+#include "cdjpeg.h"
extern void jpeg_mem_dest_tj(j_compress_ptr, unsigned char **, size_t *,
boolean);
@@ -330,9 +330,9 @@ static int getPixelFormat(int pixelSize, int flags)
return -1;
}
-static void setCompDefaults(tjinstance *this, int pixelFormat)
+static void setCompDefaults(tjinstance *this, int pixelFormat, boolean yuv)
{
- int subsamp = this->subsamp;
+ int colorspace = yuv ? -1 : this->colorspace;
this->cinfo.in_color_space = pf2cs[pixelFormat];
this->cinfo.input_components = tjPixelSize[pixelFormat];
@@ -345,21 +345,17 @@ static void setCompDefaults(tjinstance *this, int pixelFormat)
this->cinfo.density_unit = (UINT8)this->densityUnits;
this->cinfo.mem->max_memory_to_use = (long)this->maxMemory * 1048576L;
- if (this->lossless) {
+ if (this->lossless && !yuv) {
#ifdef C_LOSSLESS_SUPPORTED
jpeg_enable_lossless(&this->cinfo, this->losslessPSV, this->losslessPt);
#endif
- if (pixelFormat == TJPF_GRAY)
- subsamp = TJSAMP_GRAY;
- else if (subsamp != TJSAMP_GRAY)
- subsamp = TJSAMP_444;
return;
}
jpeg_set_quality(&this->cinfo, this->quality, TRUE);
this->cinfo.dct_method = this->fastDCT ? JDCT_FASTEST : JDCT_ISLOW;
- switch (this->colorspace) {
+ switch (colorspace) {
case TJCS_RGB:
jpeg_set_colorspace(&this->cinfo, JCS_RGB); break;
case TJCS_YCbCr:
@@ -371,7 +367,7 @@ static void setCompDefaults(tjinstance *this, int pixelFormat)
case TJCS_YCCK:
jpeg_set_colorspace(&this->cinfo, JCS_YCCK); break;
default:
- if (subsamp == TJSAMP_GRAY)
+ if (this->subsamp == TJSAMP_GRAY)
jpeg_set_colorspace(&this->cinfo, JCS_GRAYSCALE);
else if (pixelFormat == TJPF_CMYK)
jpeg_set_colorspace(&this->cinfo, JCS_YCCK);
@@ -386,16 +382,16 @@ static void setCompDefaults(tjinstance *this, int pixelFormat)
#endif
this->cinfo.arith_code = this->arithmetic;
- this->cinfo.comp_info[0].h_samp_factor = tjMCUWidth[subsamp] / 8;
+ this->cinfo.comp_info[0].h_samp_factor = tjMCUWidth[this->subsamp] / 8;
this->cinfo.comp_info[1].h_samp_factor = 1;
this->cinfo.comp_info[2].h_samp_factor = 1;
if (this->cinfo.num_components > 3)
- this->cinfo.comp_info[3].h_samp_factor = tjMCUWidth[subsamp] / 8;
- this->cinfo.comp_info[0].v_samp_factor = tjMCUHeight[subsamp] / 8;
+ this->cinfo.comp_info[3].h_samp_factor = tjMCUWidth[this->subsamp] / 8;
+ this->cinfo.comp_info[0].v_samp_factor = tjMCUHeight[this->subsamp] / 8;
this->cinfo.comp_info[1].v_samp_factor = 1;
this->cinfo.comp_info[2].v_samp_factor = 1;
if (this->cinfo.num_components > 3)
- this->cinfo.comp_info[3].v_samp_factor = tjMCUHeight[subsamp] / 8;
+ this->cinfo.comp_info[3].v_samp_factor = tjMCUHeight[this->subsamp] / 8;
}
@@ -1302,7 +1298,7 @@ DLLEXPORT int tj3CompressFromYUVPlanes8(tjhandle handle,
if (this->noRealloc) alloc = FALSE;
jpeg_mem_dest_tj(cinfo, jpegBuf, jpegSize, alloc);
- setCompDefaults(this, TJPF_RGB);
+ setCompDefaults(this, TJPF_RGB, TRUE);
cinfo->raw_data_in = TRUE;
jpeg_start_compress(cinfo, TRUE);
@@ -1553,7 +1549,7 @@ DLLEXPORT int tj3EncodeYUVPlanes8(tjhandle handle, const unsigned char *srcBuf,
cinfo->image_height = height;
cinfo->data_precision = 8;
- setCompDefaults(this, pixelFormat);
+ setCompDefaults(this, pixelFormat, TRUE);
/* Execute only the parts of jpeg_start_compress() that we need. If we
were to call the whole jpeg_start_compress() function, then it would try
diff --git a/thirdparty/libjpeg-turbo/src/turbojpeg.h b/thirdparty/libjpeg-turbo/src/turbojpeg.h
index 274eb7a3644..0370cfb5b5e 100644
--- a/thirdparty/libjpeg-turbo/src/turbojpeg.h
+++ b/thirdparty/libjpeg-turbo/src/turbojpeg.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C)2009-2015, 2017, 2020-2024 D. R. Commander.
+ * Copyright (C)2009-2015, 2017, 2020-2025 D. R. Commander.
* All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -737,7 +737,8 @@ enum TJPARAM {
* - DCT/IDCT algorithm selection
* - Progressive JPEG
* - Arithmetic entropy coding
- * - Compression from/decompression to planar YUV images
+ * - Compression from/decompression to planar YUV images (this parameter is
+ * ignored by #tj3CompressFromYUV8() and #tj3CompressFromYUVPlanes8())
* - Decompression scaling
* - Lossless transformation
*
@@ -1496,17 +1497,16 @@ DLLEXPORT int tj3SetICCProfile(tjhandle handle, unsigned char *iccBuf,
* #tj3SetICCProfile().) This should ensure that the buffer never has to be
* re-allocated. (Setting #TJPARAM_NOREALLOC guarantees that it won't be.)
* .
- * If you choose option 1 or 3, then `*jpegSize` should be set to the size of
- * your pre-allocated buffer. In any case, unless you have set
- * #TJPARAM_NOREALLOC, you should always check `*jpegBuf` upon return from this
- * function, as it may have changed.
+ * Unless you have set #TJPARAM_NOREALLOC, you should always check `*jpegBuf`
+ * upon return from this function, as it may have changed.
*
* @param jpegSize pointer to a size_t variable that holds the size of the JPEG
* buffer. If `*jpegBuf` points to a pre-allocated buffer, then `*jpegSize`
- * should be set to the size of the buffer. Upon return, `*jpegSize` will
- * contain the size of the JPEG image (in bytes.) If `*jpegBuf` points to a
- * JPEG buffer that is being reused from a previous call to one of the JPEG
- * compression functions, then `*jpegSize` is ignored.
+ * should be set to the size of the buffer. Otherwise, `*jpegSize` is
+ * ignored. If `*jpegBuf` points to a JPEG buffer that is being reused from a
+ * previous call to one of the JPEG compression functions, then `*jpegSize` is
+ * also ignored. Upon return, `*jpegSize` will contain the size of the JPEG
+ * image (in bytes.)
*
* @return 0 if successful, or -1 if an error occurred (see #tj3GetErrorStr()
* and #tj3GetErrorCode().)
@@ -1557,17 +1557,16 @@ DLLEXPORT int tj3Compress8(tjhandle handle, const unsigned char *srcBuf,
* #tj3SetICCProfile().) This should ensure that the buffer never has to be
* re-allocated. (Setting #TJPARAM_NOREALLOC guarantees that it won't be.)
* .
- * If you choose option 1 or 3, then `*jpegSize` should be set to the size of
- * your pre-allocated buffer. In any case, unless you have set
- * #TJPARAM_NOREALLOC, you should always check `*jpegBuf` upon return from this
- * function, as it may have changed.
+ * Unless you have set #TJPARAM_NOREALLOC, you should always check `*jpegBuf`
+ * upon return from this function, as it may have changed.
*
* @param jpegSize pointer to a size_t variable that holds the size of the JPEG
* buffer. If `*jpegBuf` points to a pre-allocated buffer, then `*jpegSize`
- * should be set to the size of the buffer. Upon return, `*jpegSize` will
- * contain the size of the JPEG image (in bytes.) If `*jpegBuf` points to a
- * JPEG buffer that is being reused from a previous call to one of the JPEG
- * compression functions, then `*jpegSize` is ignored.
+ * should be set to the size of the buffer. Otherwise, `*jpegSize` is
+ * ignored. If `*jpegBuf` points to a JPEG buffer that is being reused from a
+ * previous call to one of the JPEG compression functions, then `*jpegSize` is
+ * also ignored. Upon return, `*jpegSize` will contain the size of the JPEG
+ * image (in bytes.)
*
* @return 0 if successful, or -1 if an error occurred (see #tj3GetErrorStr()
* and #tj3GetErrorCode().)
@@ -1619,17 +1618,16 @@ DLLEXPORT int tj3Compress12(tjhandle handle, const short *srcBuf, int width,
* #tj3SetICCProfile().) This should ensure that the buffer never has to be
* re-allocated. (Setting #TJPARAM_NOREALLOC guarantees that it won't be.)
* .
- * If you choose option 1 or 3, then `*jpegSize` should be set to the size of
- * your pre-allocated buffer. In any case, unless you have set
- * #TJPARAM_NOREALLOC, you should always check `*jpegBuf` upon return from this
- * function, as it may have changed.
+ * Unless you have set #TJPARAM_NOREALLOC, you should always check `*jpegBuf`
+ * upon return from this function, as it may have changed.
*
* @param jpegSize pointer to a size_t variable that holds the size of the JPEG
* buffer. If `*jpegBuf` points to a pre-allocated buffer, then `*jpegSize`
- * should be set to the size of the buffer. Upon return, `*jpegSize` will
- * contain the size of the JPEG image (in bytes.) If `*jpegBuf` points to a
- * JPEG buffer that is being reused from a previous call to one of the JPEG
- * compression functions, then `*jpegSize` is ignored.
+ * should be set to the size of the buffer. Otherwise, `*jpegSize` is
+ * ignored. If `*jpegBuf` points to a JPEG buffer that is being reused from a
+ * previous call to one of the JPEG compression functions, then `*jpegSize` is
+ * also ignored. Upon return, `*jpegSize` will contain the size of the JPEG
+ * image (in bytes.)
*
* @return 0 if successful, or -1 if an error occurred (see #tj3GetErrorStr()
* and #tj3GetErrorCode().)
@@ -1641,7 +1639,8 @@ DLLEXPORT int tj3Compress16(tjhandle handle, const unsigned short *srcBuf,
/**
* Compress a set of 8-bit-per-sample Y, U (Cb), and V (Cr) image planes into
- * an 8-bit-per-sample JPEG image.
+ * an 8-bit-per-sample lossy @ref TJCS_YCbCr "YCbCr" or
+ * @ref TJCS_GRAY "grayscale" JPEG image.
*
* @param handle handle to a TurboJPEG instance that has been initialized for
* compression
@@ -1684,17 +1683,16 @@ DLLEXPORT int tj3Compress16(tjhandle handle, const unsigned short *srcBuf,
* #tj3SetICCProfile().) This should ensure that the buffer never has to be
* re-allocated. (Setting #TJPARAM_NOREALLOC guarantees that it won't be.)
* .
- * If you choose option 1 or 3, then `*jpegSize` should be set to the size of
- * your pre-allocated buffer. In any case, unless you have set
- * #TJPARAM_NOREALLOC, you should always check `*jpegBuf` upon return from this
- * function, as it may have changed.
+ * Unless you have set #TJPARAM_NOREALLOC, you should always check `*jpegBuf`
+ * upon return from this function, as it may have changed.
*
* @param jpegSize pointer to a size_t variable that holds the size of the JPEG
* buffer. If `*jpegBuf` points to a pre-allocated buffer, then `*jpegSize`
- * should be set to the size of the buffer. Upon return, `*jpegSize` will
- * contain the size of the JPEG image (in bytes.) If `*jpegBuf` points to a
- * JPEG buffer that is being reused from a previous call to one of the JPEG
- * compression functions, then `*jpegSize` is ignored.
+ * should be set to the size of the buffer. Otherwise, `*jpegSize` is
+ * ignored. If `*jpegBuf` points to a JPEG buffer that is being reused from a
+ * previous call to one of the JPEG compression functions, then `*jpegSize` is
+ * also ignored. Upon return, `*jpegSize` will contain the size of the JPEG
+ * image (in bytes.)
*
* @return 0 if successful, or -1 if an error occurred (see #tj3GetErrorStr()
* and #tj3GetErrorCode().)
@@ -1708,7 +1706,8 @@ DLLEXPORT int tj3CompressFromYUVPlanes8(tjhandle handle,
/**
* Compress an 8-bit-per-sample unified planar YUV image into an
- * 8-bit-per-sample JPEG image.
+ * 8-bit-per-sample lossy @ref TJCS_YCbCr "YCbCr" or @ref TJCS_GRAY "grayscale"
+ * JPEG image.
*
* @param handle handle to a TurboJPEG instance that has been initialized for
* compression
@@ -1746,17 +1745,16 @@ DLLEXPORT int tj3CompressFromYUVPlanes8(tjhandle handle,
* #tj3SetICCProfile().) This should ensure that the buffer never has to be
* re-allocated. (Setting #TJPARAM_NOREALLOC guarantees that it won't be.)
* .
- * If you choose option 1 or 3, then `*jpegSize` should be set to the size of
- * your pre-allocated buffer. In any case, unless you have set
- * #TJPARAM_NOREALLOC, you should always check `*jpegBuf` upon return from this
- * function, as it may have changed.
+ * Unless you have set #TJPARAM_NOREALLOC, you should always check `*jpegBuf`
+ * upon return from this function, as it may have changed.
*
* @param jpegSize pointer to a size_t variable that holds the size of the JPEG
* buffer. If `*jpegBuf` points to a pre-allocated buffer, then `*jpegSize`
- * should be set to the size of the buffer. Upon return, `*jpegSize` will
- * contain the size of the JPEG image (in bytes.) If `*jpegBuf` points to a
- * JPEG buffer that is being reused from a previous call to one of the JPEG
- * compression functions, then `*jpegSize` is ignored.
+ * should be set to the size of the buffer. Otherwise, `*jpegSize` is
+ * ignored. If `*jpegBuf` points to a JPEG buffer that is being reused from a
+ * previous call to one of the JPEG compression functions, then `*jpegSize` is
+ * also ignored. Upon return, `*jpegSize` will contain the size of the JPEG
+ * image (in bytes.)
*
* @return 0 if successful, or -1 if an error occurred (see #tj3GetErrorStr()
* and #tj3GetErrorCode().)
@@ -1770,8 +1768,9 @@ DLLEXPORT int tj3CompressFromYUV8(tjhandle handle,
/**
* Encode an 8-bit-per-sample packed-pixel RGB or grayscale image into separate
* 8-bit-per-sample Y, U (Cb), and V (Cr) image planes. This function performs
- * color conversion (which is accelerated in the libjpeg-turbo implementation)
- * but does not execute any of the other steps in the JPEG compression process.
+ * color conversion and downsampling (which are accelerated in the
+ * libjpeg-turbo implementation) but does not execute any of the other steps in
+ * the JPEG compression process.
*
* @param handle handle to a TurboJPEG instance that has been initialized for
* compression
@@ -1825,8 +1824,9 @@ DLLEXPORT int tj3EncodeYUVPlanes8(tjhandle handle, const unsigned char *srcBuf,
/**
* Encode an 8-bit-per-sample packed-pixel RGB or grayscale image into an
* 8-bit-per-sample unified planar YUV image. This function performs color
- * conversion (which is accelerated in the libjpeg-turbo implementation) but
- * does not execute any of the other steps in the JPEG compression process.
+ * conversion and downsampling (which are accelerated in the libjpeg-turbo
+ * implementation) but does not execute any of the other steps in the JPEG
+ * compression process.
*
* @param handle handle to a TurboJPEG instance that has been initialized for
* compression
@@ -2065,11 +2065,12 @@ DLLEXPORT int tj3Decompress16(tjhandle handle, const unsigned char *jpegBuf,
/**
- * Decompress an 8-bit-per-sample JPEG image into separate 8-bit-per-sample Y,
- * U (Cb), and V (Cr) image planes. This function performs JPEG decompression
- * but leaves out the color conversion step, so a planar YUV image is generated
- * instead of a packed-pixel image. The @ref TJPARAM "parameters" that
- * describe the JPEG image will be set when this function returns.
+ * Decompress an 8-bit-per-sample lossy JPEG image into separate
+ * 8-bit-per-sample Y, U (Cb), and V (Cr) image planes. This function performs
+ * JPEG decompression but leaves out the color conversion step, so a planar YUV
+ * image is generated instead of a packed-pixel image. The
+ * @ref TJPARAM "parameters" that describe the JPEG image will be set when this
+ * function returns.
*
* @param handle handle to a TurboJPEG instance that has been initialized for
* decompression
@@ -2108,11 +2109,11 @@ DLLEXPORT int tj3DecompressToYUVPlanes8(tjhandle handle,
/**
- * Decompress an 8-bit-per-sample JPEG image into an 8-bit-per-sample unified
- * planar YUV image. This function performs JPEG decompression but leaves out
- * the color conversion step, so a planar YUV image is generated instead of a
- * packed-pixel image. The @ref TJPARAM "parameters" that describe the JPEG
- * image will be set when this function returns.
+ * Decompress an 8-bit-per-sample lossy JPEG image into an 8-bit-per-sample
+ * unified planar YUV image. This function performs JPEG decompression but
+ * leaves out the color conversion step, so a planar YUV image is generated
+ * instead of a packed-pixel image. The @ref TJPARAM "parameters" that
+ * describe the JPEG image will be set when this function returns.
*
* @param handle handle to a TurboJPEG instance that has been initialized for
* decompression
@@ -2310,22 +2311,21 @@ DLLEXPORT size_t tj3TransformBufSize(tjhandle handle,
* -# pre-allocate the buffer to a "worst case" size determined by calling
* #tj3TransformBufSize(). Under normal circumstances, this should ensure that
* the buffer never has to be re-allocated. (Setting #TJPARAM_NOREALLOC
- * guarantees that it won't be.) Note, however, that there are some rare cases
- * (such as transforming images with a large amount of embedded Exif data) in
- * which the transformed JPEG image will be larger than the worst-case size,
- * and #TJPARAM_NOREALLOC cannot be used in those cases unless the embedded
- * data is discarded using #TJXOPT_COPYNONE or #TJPARAM_SAVEMARKERS.
+ * guarantees that it won't be. However, if the source image has a large
+ * amount of embedded Exif data, then the transformed JPEG image may be larger
+ * than the worst-case size. #TJPARAM_NOREALLOC cannot be used in that case
+ * unless the embedded data is discarded using #TJXOPT_COPYNONE or
+ * #TJPARAM_SAVEMARKERS.)
* .
- * If you choose option 1 or 3, then `dstSizes[i]` should be set to the size of
- * your pre-allocated buffer. In any case, unless you have set
- * #TJPARAM_NOREALLOC, you should always check `dstBufs[i]` upon return from
- * this function, as it may have changed.
+ * Unless you have set #TJPARAM_NOREALLOC, you should always check `dstBufs[i]`
+ * upon return from this function, as it may have changed.
*
* @param dstSizes pointer to an array of n size_t variables that will receive
* the actual sizes (in bytes) of each transformed JPEG image. If `dstBufs[i]`
* points to a pre-allocated buffer, then `dstSizes[i]` should be set to the
- * size of the buffer. Upon return, `dstSizes[i]` will contain the size of the
- * transformed JPEG image (in bytes.)
+ * size of the buffer. Otherwise, `dstSizes[i]` is ignored. Upon return,
+ * `dstSizes[i]` will contain the size of the transformed JPEG image (in
+ * bytes.)
*
* @param transforms pointer to an array of n #tjtransform structures, each of
* which specifies the transform parameters and/or cropping region for the