aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJake Weinstein <jake@aospa.co>2022-09-01 06:16:28 +0900
committerJake Weinstein <jake@aospa.co>2022-09-01 13:32:07 +0000
commited683925e4897a84b3bffc5c1414c85b97a129a3 (patch)
treeede67ceca0ec34c3ca432e2a3221b4c407614a01
parent22f1a22c99e9dde8cd3c72ead333f425c5a7aa77 (diff)
downloadlibjpeg-turbo-ed683925e4897a84b3bffc5c1414c85b97a129a3.tar.gz
Update libjpeg-turbo to upstream stable release 2.1.4
This release consists mostly of bug fixes. Change-Id: I6fb6ee09c86588ffea242dfc660612948ae73496
-rw-r--r--BUILDING.md12
-rw-r--r--ChangeLog.md35
-rw-r--r--README.chromium4
-rw-r--r--cjpeg.c15
-rw-r--r--djpeg.c15
-rw-r--r--jconfig.h4
-rw-r--r--jconfigint.h2
-rw-r--r--jdapistd.c13
-rw-r--r--jdcoefct.c6
-rw-r--r--jerror.c4
-rw-r--r--jinclude.h12
-rw-r--r--jmemmgr.c13
-rw-r--r--jpegtran.c15
-rw-r--r--libjpeg.txt20
-rw-r--r--rdjpgcom.c15
-rw-r--r--simd/arm/aarch32/jsimd.c2
-rw-r--r--simd/arm/aarch64/jsimd.c2
-rw-r--r--tjbench.c24
-rw-r--r--tjunittest.c8
-rw-r--r--tjutil.h13
-rw-r--r--turbojpeg-jni.c2
-rw-r--r--turbojpeg.c44
-rw-r--r--turbojpeg.h25
-rw-r--r--usage.txt27
-rw-r--r--wrjpgcom.c15
25 files changed, 174 insertions, 173 deletions
diff --git a/BUILDING.md b/BUILDING.md
index e682769e..2ce65d61 100644
--- a/BUILDING.md
+++ b/BUILDING.md
@@ -26,8 +26,8 @@ Build Requirements
slashes rather than backslashes in the path (for example,
**c:/nasm/nasm.exe**).
* NASM and Yasm are located in the CRB (Code Ready Builder) repository on
- Red Hat Enterprise Linux 8 and in the PowerTools repository on CentOS 8,
- which is not enabled by default.
+ Red Hat Enterprise Linux 8 and in the PowerTools repository on RHEL
+ derivatives, which is not enabled by default.
### Un*x Platforms (including Linux, Mac, FreeBSD, Solaris, and Cygwin)
@@ -79,6 +79,14 @@ Build Requirements
* If using JDK 11 or later, CMake 3.10.x or later must also be used.
+Sub-Project Builds
+------------------
+
+The libjpeg-turbo build system does not support being included as a sub-project
+using the CMake `add_subdirectory()` function. Use the CMake
+`ExternalProject_Add()` function instead.
+
+
Out-of-Tree Builds
------------------
diff --git a/ChangeLog.md b/ChangeLog.md
index e6700c3c..b0d166ea 100644
--- a/ChangeLog.md
+++ b/ChangeLog.md
@@ -1,3 +1,38 @@
+2.1.4
+=====
+
+### Significant changes relative to 2.1.3
+
+1. Fixed a regression introduced in 2.1.3 that caused build failures with
+Visual Studio 2010.
+
+2. The `tjDecompressHeader3()` function in the TurboJPEG C API and the
+`TJDecompressor.setSourceImage()` method in the TurboJPEG Java API now accept
+"abbreviated table specification" (AKA "tables-only") datastreams, which can be
+used to prime the decompressor with quantization and Huffman tables that can be
+used when decompressing subsequent "abbreviated image" datastreams.
+
+3. libjpeg-turbo now performs run-time detection of AltiVec instructions on
+OS X/PowerPC systems if AltiVec instructions are not enabled at compile time.
+This allows both AltiVec-equipped (PowerPC G4 and G5) and non-AltiVec-equipped
+(PowerPC G3) CPUs to be supported using the same build of libjpeg-turbo.
+
+4. Fixed an error ("Bogus virtual array access") that occurred when attempting
+to decompress a progressive JPEG image with a height less than or equal to one
+iMCU (8 * the vertical sampling factor) using buffered-image mode with
+interblock smoothing enabled. This was a regression introduced by
+2.1 beta1[6(b)].
+
+5. Fixed two issues that prevented partial image decompression from working
+properly with buffered-image mode:
+
+ - Attempting to call `jpeg_crop_scanline()` after
+`jpeg_start_decompress()` but before `jpeg_start_output()` resulted in an error
+("Improper call to JPEG library in state 207".)
+ - Attempting to use `jpeg_skip_scanlines()` resulted in an error ("Bogus
+virtual array access") under certain circumstances.
+
+
2.1.3
=====
diff --git a/README.chromium b/README.chromium
index 4a0cbdff..f0159a0d 100644
--- a/README.chromium
+++ b/README.chromium
@@ -1,6 +1,6 @@
Name: libjpeg-turbo
URL: https://github.com/libjpeg-turbo/libjpeg-turbo/
-Version: 2.1.3
+Version: 2.1.4
License: Custom license
License File: LICENSE.md
Security Critical: yes
@@ -8,7 +8,7 @@ License Android Compatible: yes
Description:
This consists of the components:
-* libjpeg-turbo 2.1.3
+* libjpeg-turbo 2.1.4
* This file (README.chromium)
* A build file (BUILD.gn)
* An OWNERS file
diff --git a/cjpeg.c b/cjpeg.c
index 156b67da..12eb4ab6 100644
--- a/cjpeg.c
+++ b/cjpeg.c
@@ -38,16 +38,6 @@
#include "jversion.h" /* for version message */
#include "jconfigint.h"
-#ifdef USE_CCOMMAND /* command-line reader for Macintosh */
-#ifdef __MWERKS__
-#include <SIOUX.h> /* Metrowerks needs this */
-#include <console.h> /* ... and this */
-#endif
-#ifdef THINK_C
-#include <console.h> /* Think declares it here */
-#endif
-#endif
-
/* Create the add-on message string table. */
@@ -588,11 +578,6 @@ main(int argc, char **argv)
unsigned long outsize = 0;
JDIMENSION num_scanlines;
- /* On Mac, fetch a command line. */
-#ifdef USE_CCOMMAND
- argc = ccommand(&argv);
-#endif
-
progname = argv[0];
if (progname == NULL || progname[0] == 0)
progname = "cjpeg"; /* in case C library doesn't provide it */
diff --git a/djpeg.c b/djpeg.c
index bbd9d18d..68ffed26 100644
--- a/djpeg.c
+++ b/djpeg.c
@@ -38,16 +38,6 @@
#include <ctype.h> /* to declare isprint() */
-#ifdef USE_CCOMMAND /* command-line reader for Macintosh */
-#ifdef __MWERKS__
-#include <SIOUX.h> /* Metrowerks needs this */
-#include <console.h> /* ... and this */
-#endif
-#ifdef THINK_C
-#include <console.h> /* Think declares it here */
-#endif
-#endif
-
/* Create the add-on message string table. */
@@ -554,11 +544,6 @@ main(int argc, char **argv)
#endif
JDIMENSION num_scanlines;
- /* On Mac, fetch a command line. */
-#ifdef USE_CCOMMAND
- argc = ccommand(&argv);
-#endif
-
progname = argv[0];
if (progname == NULL || progname[0] == 0)
progname = "djpeg"; /* in case C library doesn't provide it */
diff --git a/jconfig.h b/jconfig.h
index 7eb5f5f1..2366cf12 100644
--- a/jconfig.h
+++ b/jconfig.h
@@ -4,10 +4,10 @@
#define JPEG_LIB_VERSION 62
/* libjpeg-turbo version */
-#define LIBJPEG_TURBO_VERSION 2.1.3
+#define LIBJPEG_TURBO_VERSION 2.1.4
/* libjpeg-turbo version in integer form */
-#define LIBJPEG_TURBO_VERSION_NUMBER 2001003
+#define LIBJPEG_TURBO_VERSION_NUMBER 2001004
/* Support arithmetic encoding */
/* #define C_ARITH_CODING_SUPPORTED 1 */
diff --git a/jconfigint.h b/jconfigint.h
index 41952fc8..093659b5 100644
--- a/jconfigint.h
+++ b/jconfigint.h
@@ -26,7 +26,7 @@
#define PACKAGE_NAME "libjpeg-turbo"
/* Version number of package */
-#define VERSION "2.1.3"
+#define VERSION "2.1.4"
/* The size of `size_t', as computed by sizeof. */
#include <stdint.h>
diff --git a/jdapistd.c b/jdapistd.c
index 8827d8ab..02cd0cb9 100644
--- a/jdapistd.c
+++ b/jdapistd.c
@@ -159,9 +159,12 @@ jpeg_crop_scanline(j_decompress_ptr cinfo, JDIMENSION *xoffset,
JDIMENSION input_xoffset;
boolean reinit_upsampler = FALSE;
jpeg_component_info *compptr;
+#ifdef UPSAMPLE_MERGING_SUPPORTED
my_master_ptr master = (my_master_ptr)cinfo->master;
+#endif
- if (cinfo->global_state != DSTATE_SCANNING || cinfo->output_scanline != 0)
+ if ((cinfo->global_state != DSTATE_SCANNING &&
+ cinfo->global_state != DSTATE_BUFIMAGE) || cinfo->output_scanline != 0)
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
if (!xoffset || !width)
@@ -209,11 +212,13 @@ jpeg_crop_scanline(j_decompress_ptr cinfo, JDIMENSION *xoffset,
*/
*width = *width + input_xoffset - *xoffset;
cinfo->output_width = *width;
+#ifdef UPSAMPLE_MERGING_SUPPORTED
if (master->using_merged_upsample && cinfo->max_v_samp_factor == 2) {
my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample;
upsample->out_row_width =
cinfo->output_width * cinfo->out_color_components;
}
+#endif
/* Set the first and last iMCU columns that we must decompress. These values
* will be used in single-scan decompressions.
@@ -324,7 +329,9 @@ LOCAL(void)
read_and_discard_scanlines(j_decompress_ptr cinfo, JDIMENSION num_lines)
{
JDIMENSION n;
+#ifdef UPSAMPLE_MERGING_SUPPORTED
my_master_ptr master = (my_master_ptr)cinfo->master;
+#endif
JSAMPLE dummy_sample[1] = { 0 };
JSAMPROW dummy_row = dummy_sample;
JSAMPARRAY scanlines = NULL;
@@ -348,10 +355,12 @@ read_and_discard_scanlines(j_decompress_ptr cinfo, JDIMENSION num_lines)
cinfo->cquantize->color_quantize = noop_quantize;
}
+#ifdef UPSAMPLE_MERGING_SUPPORTED
if (master->using_merged_upsample && cinfo->max_v_samp_factor == 2) {
my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample;
scanlines = &upsample->spare_row;
}
+#endif
for (n = 0; n < num_lines; n++)
jpeg_read_scanlines(cinfo, scanlines, 1);
@@ -517,7 +526,7 @@ jpeg_skip_scanlines(j_decompress_ptr cinfo, JDIMENSION num_lines)
* all of the entropy decoding occurs in jpeg_start_decompress(), assuming
* that the input data source is non-suspending. This makes skipping easy.
*/
- if (cinfo->inputctl->has_multiple_scans) {
+ if (cinfo->inputctl->has_multiple_scans || cinfo->buffered_image) {
if (cinfo->upsample->need_context_rows) {
cinfo->output_scanline += lines_to_skip;
cinfo->output_iMCU_row += lines_to_skip / lines_per_iMCU_row;
diff --git a/jdcoefct.c b/jdcoefct.c
index 15e6cded..88e10c08 100644
--- a/jdcoefct.c
+++ b/jdcoefct.c
@@ -5,7 +5,7 @@
* Copyright (C) 1994-1997, Thomas G. Lane.
* libjpeg-turbo Modifications:
* Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
- * Copyright (C) 2010, 2015-2016, 2019-2020, D. R. Commander.
+ * Copyright (C) 2010, 2015-2016, 2019-2020, 2022, D. R. Commander.
* Copyright (C) 2015, 2020, Google, Inc.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
@@ -475,7 +475,7 @@ decompress_smooth_data(j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
if (!compptr->component_needed)
continue;
/* Count non-dummy DCT block rows in this iMCU row. */
- if (cinfo->output_iMCU_row < last_iMCU_row - 1) {
+ if (cinfo->output_iMCU_row + 1 < last_iMCU_row) {
block_rows = compptr->v_samp_factor;
access_rows = block_rows * 3; /* this and next two iMCU rows */
} else if (cinfo->output_iMCU_row < last_iMCU_row) {
@@ -560,7 +560,7 @@ decompress_smooth_data(j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
next_block_row = buffer_ptr;
if (block_row < block_rows - 2 ||
- cinfo->output_iMCU_row < last_iMCU_row - 1)
+ cinfo->output_iMCU_row + 1 < last_iMCU_row)
next_next_block_row =
buffer[block_row + 2] + cinfo->master->first_MCU_col[ci];
else
diff --git a/jerror.c b/jerror.c
index d5447029..d0ab5b88 100644
--- a/jerror.c
+++ b/jerror.c
@@ -189,9 +189,9 @@ format_message(j_common_ptr cinfo, char *buffer)
/* Format the message into the passed buffer */
if (isstring)
- snprintf(buffer, JMSG_LENGTH_MAX, msgtext, err->msg_parm.s);
+ SNPRINTF(buffer, JMSG_LENGTH_MAX, msgtext, err->msg_parm.s);
else
- snprintf(buffer, JMSG_LENGTH_MAX, msgtext,
+ SNPRINTF(buffer, JMSG_LENGTH_MAX, msgtext,
err->msg_parm.i[0], err->msg_parm.i[1],
err->msg_parm.i[2], err->msg_parm.i[3],
err->msg_parm.i[4], err->msg_parm.i[5],
diff --git a/jinclude.h b/jinclude.h
index 120614b2..e8d983ac 100644
--- a/jinclude.h
+++ b/jinclude.h
@@ -45,6 +45,18 @@
*/
+#ifdef _MSC_VER
+
+#define SNPRINTF(str, n, format, ...) \
+ _snprintf_s(str, n, _TRUNCATE, format, ##__VA_ARGS__)
+
+#else
+
+#define SNPRINTF snprintf
+
+#endif
+
+
#ifndef NO_GETENV
#ifdef _MSC_VER
diff --git a/jmemmgr.c b/jmemmgr.c
index 8f5a4ab1..a40446f6 100644
--- a/jmemmgr.c
+++ b/jmemmgr.c
@@ -68,10 +68,13 @@ round_up_pow2(size_t a, size_t b)
* There isn't any really portable way to determine the worst-case alignment
* requirement. This module assumes that the alignment requirement is
* multiples of ALIGN_SIZE.
- * By default, we define ALIGN_SIZE as sizeof(double). This is necessary on
- * some workstations (where doubles really do need 8-byte alignment) and will
- * work fine on nearly everything. If your machine has lesser alignment needs,
- * you can save a few bytes by making ALIGN_SIZE smaller.
+ * By default, we define ALIGN_SIZE as the maximum of sizeof(double) and
+ * sizeof(void *). This is necessary on some workstations (where doubles
+ * really do need 8-byte alignment) and will work fine on nearly everything.
+ * We use the maximum of sizeof(double) and sizeof(void *) since sizeof(double)
+ * may be insufficient, for example, on CHERI-enabled platforms with 16-byte
+ * pointers and a 16-byte alignment requirement. If your machine has lesser
+ * alignment needs, you can save a few bytes by making ALIGN_SIZE smaller.
* The only place I know of where this will NOT work is certain Macintosh
* 680x0 compilers that define double as a 10-byte IEEE extended float.
* Doing 10-byte alignment is counterproductive because longwords won't be
@@ -81,7 +84,7 @@ round_up_pow2(size_t a, size_t b)
#ifndef ALIGN_SIZE /* so can override from jconfig.h */
#ifndef WITH_SIMD
-#define ALIGN_SIZE sizeof(double)
+#define ALIGN_SIZE MAX(sizeof(void *), sizeof(double))
#else
#define ALIGN_SIZE 32 /* Most of the SIMD instructions we support require
16-byte (128-bit) alignment, but AVX2 requires
diff --git a/jpegtran.c b/jpegtran.c
index 0d89a0a4..c7bee837 100644
--- a/jpegtran.c
+++ b/jpegtran.c
@@ -23,16 +23,6 @@
#include "jversion.h" /* for version message */
#include "jconfigint.h"
-#ifdef USE_CCOMMAND /* command-line reader for Macintosh */
-#ifdef __MWERKS__
-#include <SIOUX.h> /* Metrowerks needs this */
-#include <console.h> /* ... and this */
-#endif
-#ifdef THINK_C
-#include <console.h> /* Think declares it here */
-#endif
-#endif
-
/*
* Argument-parsing code.
@@ -487,11 +477,6 @@ main(int argc, char **argv)
JOCTET *icc_profile = NULL;
long icc_len = 0;
- /* On Mac, fetch a command line. */
-#ifdef USE_CCOMMAND
- argc = ccommand(&argv);
-#endif
-
progname = argv[0];
if (progname == NULL || progname[0] == 0)
progname = "jpegtran"; /* in case C library doesn't provide it */
diff --git a/libjpeg.txt b/libjpeg.txt
index 3c680b5f..309f9d3b 100644
--- a/libjpeg.txt
+++ b/libjpeg.txt
@@ -3,7 +3,7 @@ USING THE IJG JPEG LIBRARY
This file was part of the Independent JPEG Group's software:
Copyright (C) 1994-2013, Thomas G. Lane, Guido Vollbeding.
libjpeg-turbo Modifications:
-Copyright (C) 2010, 2014-2018, 2020, D. R. Commander.
+Copyright (C) 2010, 2014-2018, 2020, 2022, D. R. Commander.
Copyright (C) 2015, Google, Inc.
For conditions of distribution and use, see the accompanying README.ijg file.
@@ -840,18 +840,7 @@ is to prepare a library file ("libjpeg.a", or a corresponding name on non-Unix
machines) and reference it at your link step. If you use only half of the
library (only compression or only decompression), only that much code will be
included from the library, unless your linker is hopelessly brain-damaged.
-The supplied makefiles build libjpeg.a automatically (see install.txt).
-
-While you can build the JPEG library as a shared library if the whim strikes
-you, we don't really recommend it. The trouble with shared libraries is that
-at some point you'll probably try to substitute a new version of the library
-without recompiling the calling applications. That generally doesn't work
-because the parameter struct declarations usually change with each new
-version. In other words, the library's API is *not* guaranteed binary
-compatible across versions; we only try to ensure source-code compatibility.
-(In hindsight, it might have been smarter to hide the parameter structs from
-applications and introduce a ton of access functions instead. Too late now,
-however.)
+The supplied build system builds libjpeg.a automatically.
It may be worth pointing out that the core JPEG library does not actually
require the stdio library: only the default source/destination managers and
@@ -3075,9 +3064,8 @@ BITS_IN_JSAMPLE as 12 rather than 8. Note that this causes JSAMPLE to be
larger than a char, so it affects the surrounding application's image data.
The sample applications cjpeg and djpeg can support 12-bit mode only for PPM
and GIF file formats; you must disable the other file formats to compile a
-12-bit cjpeg or djpeg. (install.txt has more information about that.)
-At present, a 12-bit library can handle *only* 12-bit images, not both
-precisions.
+12-bit cjpeg or djpeg. At present, a 12-bit library can handle *only* 12-bit
+images, not both precisions.
Note that a 12-bit library always compresses in Huffman optimization mode,
in order to generate valid Huffman tables. This is necessary because our
diff --git a/rdjpgcom.c b/rdjpgcom.c
index 9910a634..d9a6f85a 100644
--- a/rdjpgcom.c
+++ b/rdjpgcom.c
@@ -30,16 +30,6 @@
#include <io.h> /* to declare setmode() */
#endif
-#ifdef USE_CCOMMAND /* command-line reader for Macintosh */
-#ifdef __MWERKS__
-#include <SIOUX.h> /* Metrowerks needs this */
-#include <console.h> /* ... and this */
-#endif
-#ifdef THINK_C
-#include <console.h> /* Think declares it here */
-#endif
-#endif
-
#ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */
#define READ_BINARY "r"
#else
@@ -450,11 +440,6 @@ main(int argc, char **argv)
char *arg;
int verbose = 0, raw = 0;
- /* On Mac, fetch a command line. */
-#ifdef USE_CCOMMAND
- argc = ccommand(&argv);
-#endif
-
progname = argv[0];
if (progname == NULL || progname[0] == 0)
progname = "rdjpgcom"; /* in case C library doesn't provide it */
diff --git a/simd/arm/aarch32/jsimd.c b/simd/arm/aarch32/jsimd.c
index e3adf23d..920f7656 100644
--- a/simd/arm/aarch32/jsimd.c
+++ b/simd/arm/aarch32/jsimd.c
@@ -25,8 +25,6 @@
#include "../../../jsimddct.h"
#include "../../jsimd.h"
-#include <stdio.h>
-#include <string.h>
#include <ctype.h>
static unsigned int simd_support = ~0;
diff --git a/simd/arm/aarch64/jsimd.c b/simd/arm/aarch64/jsimd.c
index 604d5472..41c06d31 100644
--- a/simd/arm/aarch64/jsimd.c
+++ b/simd/arm/aarch64/jsimd.c
@@ -25,8 +25,6 @@
#include "../../jsimd.h"
#include "jconfigint.h"
-#include <stdio.h>
-#include <string.h>
#include <ctype.h>
#define JSIMD_FASTLD3 1
diff --git a/tjbench.c b/tjbench.c
index 5381f927..b8d41c66 100644
--- a/tjbench.c
+++ b/tjbench.c
@@ -110,7 +110,7 @@ static char *formatName(int subsamp, int cs, char *buf)
if (cs == TJCS_YCbCr)
return (char *)subNameLong[subsamp];
else if (cs == TJCS_YCCK || cs == TJCS_CMYK) {
- snprintf(buf, 80, "%s %s", csName[cs], subNameLong[subsamp]);
+ SNPRINTF(buf, 80, "%s %s", csName[cs], subNameLong[subsamp]);
return buf;
} else
return (char *)csName[cs];
@@ -123,10 +123,10 @@ static char *sigfig(double val, int figs, char *buf, int len)
int digitsAfterDecimal = figs - (int)ceil(log10(fabs(val)));
if (digitsAfterDecimal < 1)
- snprintf(format, 80, "%%.0f");
+ SNPRINTF(format, 80, "%%.0f");
else
- snprintf(format, 80, "%%.%df", digitsAfterDecimal);
- snprintf(buf, len, format, val);
+ SNPRINTF(format, 80, "%%.%df", digitsAfterDecimal);
+ SNPRINTF(buf, len, format, val);
return buf;
}
@@ -163,7 +163,7 @@ static int decomp(unsigned char *srcBuf, unsigned char **jpegBuf,
unsigned char *dstPtr, *dstPtr2, *yuvBuf = NULL;
if (jpegQual > 0) {
- snprintf(qualStr, 13, "_Q%d", jpegQual);
+ SNPRINTF(qualStr, 13, "_Q%d", jpegQual);
qualStr[12] = 0;
}
@@ -267,20 +267,20 @@ static int decomp(unsigned char *srcBuf, unsigned char **jpegBuf,
if (!doWrite) goto bailout;
if (sf.num != 1 || sf.denom != 1)
- snprintf(sizeStr, 24, "%d_%d", sf.num, sf.denom);
+ SNPRINTF(sizeStr, 24, "%d_%d", sf.num, sf.denom);
else if (tilew != w || tileh != h)
- snprintf(sizeStr, 24, "%dx%d", tilew, tileh);
- else snprintf(sizeStr, 24, "full");
+ SNPRINTF(sizeStr, 24, "%dx%d", tilew, tileh);
+ else SNPRINTF(sizeStr, 24, "full");
if (decompOnly)
- snprintf(tempStr, 1024, "%s_%s.%s", fileName, sizeStr, ext);
+ SNPRINTF(tempStr, 1024, "%s_%s.%s", fileName, sizeStr, ext);
else
- snprintf(tempStr, 1024, "%s_%s%s_%s.%s", fileName, subName[subsamp],
+ SNPRINTF(tempStr, 1024, "%s_%s%s_%s.%s", fileName, subName[subsamp],
qualStr, sizeStr, ext);
if (tjSaveImage(tempStr, dstBuf, scaledw, 0, scaledh, pf, flags) == -1)
THROW_TJG("saving bitmap");
ptr = strrchr(tempStr, '.');
- snprintf(ptr, 1024 - (ptr - tempStr), "-err.%s", ext);
+ SNPRINTF(ptr, 1024 - (ptr - tempStr), "-err.%s", ext);
if (srcBuf && sf.num == 1 && sf.denom == 1) {
if (!quiet) fprintf(stderr, "Compression error written to %s.\n", tempStr);
if (subsamp == TJ_GRAYSCALE) {
@@ -489,7 +489,7 @@ static int fullTest(unsigned char *srcBuf, int w, int h, int subsamp,
(double)totalJpegSize * 8. / 1000000. * (double)iter / elapsed);
}
if (tilew == w && tileh == h && doWrite) {
- snprintf(tempStr, 1024, "%s_%s_Q%d.jpg", fileName, subName[subsamp],
+ SNPRINTF(tempStr, 1024, "%s_%s_Q%d.jpg", fileName, subName[subsamp],
jpegQual);
if ((file = fopen(tempStr, "wb")) == NULL)
THROW_UNIX("opening reference image");
diff --git a/tjunittest.c b/tjunittest.c
index 29ecc463..04be30d4 100644
--- a/tjunittest.c
+++ b/tjunittest.c
@@ -359,7 +359,7 @@ static void writeJPEG(unsigned char *jpegBuf, unsigned long jpegSize,
{
#if defined(ANDROID) && defined(GTEST)
char path[filePathSize];
- snprintf(path, filePathSize, "/sdcard/%s", filename);
+ SNPRINTF(path, filePathSize, "/sdcard/%s", filename);
FILE *file = fopen(path, "wb");
#else
FILE *file = fopen(filename, "wb");
@@ -423,7 +423,7 @@ static void compTest(tjhandle handle, unsigned char **dstBuf,
jpegQual, flags));
}
- snprintf(tempStr, filePathSize, "%s_enc_%s_%s_%s_Q%d.jpg", basename, pfStr,
+ SNPRINTF(tempStr, filePathSize, "%s_enc_%s_%s_%s_Q%d.jpg", basename, pfStr,
buStr, subName[subsamp], jpegQual);
writeJPEG(*dstBuf, *dstSize, tempStr);
fprintf(stderr, "Done.\n Result in %s\n", tempStr);
@@ -802,11 +802,11 @@ static int doBmpTest(const char *ext, int width, int align, int height, int pf,
initBitmap(buf, width, pitch, height, pf, flags);
#if defined(ANDROID) && defined(GTEST)
- snprintf(filename, filenameSize, "/sdcard/test_bmp_%s_%d_%s.%s",
+ SNPRINTF(filename, filenameSize, "/sdcard/test_bmp_%s_%d_%s.%s",
pixFormatStr[pf], align, (flags & TJFLAG_BOTTOMUP) ? "bu" : "td",
ext);
#else
- snprintf(filename, filenameSize, "test_bmp_%s_%d_%s.%s", pixFormatStr[pf],
+ SNPRINTF(filename, filenameSize, "test_bmp_%s_%d_%s.%s", pixFormatStr[pf],
align, (flags & TJFLAG_BOTTOMUP) ? "bu" : "td", ext);
#endif
TRY_TJ(tjSaveImage(filename, buf, width, pitch, height, pf, flags));
diff --git a/tjutil.h b/tjutil.h
index fc8a17a7..10272e98 100644
--- a/tjutil.h
+++ b/tjutil.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C)2011 D. R. Commander. All Rights Reserved.
+ * Copyright (C)2011, 2022 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:
@@ -27,9 +27,20 @@
*/
#ifdef _WIN32
+#ifndef strcasecmp
#define strcasecmp stricmp
+#endif
+#ifndef strncasecmp
#define strncasecmp strnicmp
#endif
+#endif
+
+#ifdef _MSC_VER
+#define SNPRINTF(str, n, format, ...) \
+ _snprintf_s(str, n, _TRUNCATE, format, ##__VA_ARGS__)
+#else
+#define SNPRINTF snprintf
+#endif
#ifndef min
#define min(a, b) ((a) < (b) ? (a) : (b))
diff --git a/turbojpeg-jni.c b/turbojpeg-jni.c
index ba76634e..0cf5f702 100644
--- a/turbojpeg-jni.c
+++ b/turbojpeg-jni.c
@@ -26,8 +26,6 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-#include <stdlib.h>
-#include <string.h>
#include "turbojpeg.h"
#include "jinclude.h"
#include <jni.h>
diff --git a/turbojpeg.c b/turbojpeg.c
index d5e31360..a1544f24 100644
--- a/turbojpeg.c
+++ b/turbojpeg.c
@@ -30,8 +30,6 @@
/* TurboJPEG/LJT: this implements the TurboJPEG API using libjpeg or
libjpeg-turbo */
-#include <stdio.h>
-#include <stdlib.h>
#include <ctype.h>
#include <jinclude.h>
#define JPEG_INTERNALS
@@ -128,9 +126,9 @@ static void my_progress_monitor(j_common_ptr dinfo)
int scan_no = ((j_decompress_ptr)dinfo)->input_scan_number;
if (scan_no > 500) {
- snprintf(myprog->this->errStr, JMSG_LENGTH_MAX,
+ SNPRINTF(myprog->this->errStr, JMSG_LENGTH_MAX,
"Progressive JPEG image has more than 500 scans");
- snprintf(errStr, JMSG_LENGTH_MAX,
+ SNPRINTF(errStr, JMSG_LENGTH_MAX,
"Progressive JPEG image has more than 500 scans");
myprog->this->isInstanceError = TRUE;
myerr->warning = FALSE;
@@ -193,24 +191,24 @@ static int cs2pf[JPEG_NUMCS] = {
};
#define THROWG(m) { \
- snprintf(errStr, JMSG_LENGTH_MAX, "%s", m); \
+ SNPRINTF(errStr, JMSG_LENGTH_MAX, "%s", m); \
retval = -1; goto bailout; \
}
#ifdef _MSC_VER
#define THROW_UNIX(m) { \
char strerrorBuf[80] = { 0 }; \
strerror_s(strerrorBuf, 80, errno); \
- snprintf(errStr, JMSG_LENGTH_MAX, "%s\n%s", m, strerrorBuf); \
+ SNPRINTF(errStr, JMSG_LENGTH_MAX, "%s\n%s", m, strerrorBuf); \
retval = -1; goto bailout; \
}
#else
#define THROW_UNIX(m) { \
- snprintf(errStr, JMSG_LENGTH_MAX, "%s\n%s", m, strerror(errno)); \
+ SNPRINTF(errStr, JMSG_LENGTH_MAX, "%s\n%s", m, strerror(errno)); \
retval = -1; goto bailout; \
}
#endif
#define THROW(m) { \
- snprintf(this->errStr, JMSG_LENGTH_MAX, "%s", m); \
+ SNPRINTF(this->errStr, JMSG_LENGTH_MAX, "%s", m); \
this->isInstanceError = TRUE; THROWG(m) \
}
@@ -225,7 +223,7 @@ static int cs2pf[JPEG_NUMCS] = {
j_decompress_ptr dinfo = NULL; \
\
if (!this) { \
- snprintf(errStr, JMSG_LENGTH_MAX, "Invalid handle"); \
+ SNPRINTF(errStr, JMSG_LENGTH_MAX, "Invalid handle"); \
return -1; \
} \
cinfo = &this->cinfo; dinfo = &this->dinfo; \
@@ -237,7 +235,7 @@ static int cs2pf[JPEG_NUMCS] = {
j_compress_ptr cinfo = NULL; \
\
if (!this) { \
- snprintf(errStr, JMSG_LENGTH_MAX, "Invalid handle"); \
+ SNPRINTF(errStr, JMSG_LENGTH_MAX, "Invalid handle"); \
return -1; \
} \
cinfo = &this->cinfo; \
@@ -249,7 +247,7 @@ static int cs2pf[JPEG_NUMCS] = {
j_decompress_ptr dinfo = NULL; \
\
if (!this) { \
- snprintf(errStr, JMSG_LENGTH_MAX, "Invalid handle"); \
+ SNPRINTF(errStr, JMSG_LENGTH_MAX, "Invalid handle"); \
return -1; \
} \
dinfo = &this->dinfo; \
@@ -521,12 +519,12 @@ DLLEXPORT tjhandle tjInitCompress(void)
tjinstance *this = NULL;
if ((this = (tjinstance *)malloc(sizeof(tjinstance))) == NULL) {
- snprintf(errStr, JMSG_LENGTH_MAX,
+ SNPRINTF(errStr, JMSG_LENGTH_MAX,
"tjInitCompress(): Memory allocation failure");
return NULL;
}
memset(this, 0, sizeof(tjinstance));
- snprintf(this->errStr, JMSG_LENGTH_MAX, "No error");
+ SNPRINTF(this->errStr, JMSG_LENGTH_MAX, "No error");
return _tjInitCompress(this);
}
@@ -1195,12 +1193,12 @@ DLLEXPORT tjhandle tjInitDecompress(void)
tjinstance *this;
if ((this = (tjinstance *)malloc(sizeof(tjinstance))) == NULL) {
- snprintf(errStr, JMSG_LENGTH_MAX,
+ SNPRINTF(errStr, JMSG_LENGTH_MAX,
"tjInitDecompress(): Memory allocation failure");
return NULL;
}
memset(this, 0, sizeof(tjinstance));
- snprintf(this->errStr, JMSG_LENGTH_MAX, "No error");
+ SNPRINTF(this->errStr, JMSG_LENGTH_MAX, "No error");
return _tjInitDecompress(this);
}
@@ -1227,7 +1225,13 @@ DLLEXPORT int tjDecompressHeader3(tjhandle handle,
}
jpeg_mem_src_tj(dinfo, jpegBuf, jpegSize);
- jpeg_read_header(dinfo, TRUE);
+
+ /* jpeg_read_header() calls jpeg_abort() and returns JPEG_HEADER_TABLES_ONLY
+ if the datastream is a tables-only datastream. Since we aren't using a
+ suspending data source, the only other value it can return is
+ JPEG_HEADER_OK. */
+ if (jpeg_read_header(dinfo, FALSE) == JPEG_HEADER_TABLES_ONLY)
+ return 0;
*width = dinfo->image_width;
*height = dinfo->image_height;
@@ -1279,7 +1283,7 @@ DLLEXPORT int tjDecompressHeader(tjhandle handle, unsigned char *jpegBuf,
DLLEXPORT tjscalingfactor *tjGetScalingFactors(int *numscalingfactors)
{
if (numscalingfactors == NULL) {
- snprintf(errStr, JMSG_LENGTH_MAX,
+ SNPRINTF(errStr, JMSG_LENGTH_MAX,
"tjGetScalingFactors(): Invalid argument");
return NULL;
}
@@ -1886,12 +1890,12 @@ DLLEXPORT tjhandle tjInitTransform(void)
tjhandle handle = NULL;
if ((this = (tjinstance *)malloc(sizeof(tjinstance))) == NULL) {
- snprintf(errStr, JMSG_LENGTH_MAX,
+ SNPRINTF(errStr, JMSG_LENGTH_MAX,
"tjInitTransform(): Memory allocation failure");
return NULL;
}
memset(this, 0, sizeof(tjinstance));
- snprintf(this->errStr, JMSG_LENGTH_MAX, "No error");
+ SNPRINTF(this->errStr, JMSG_LENGTH_MAX, "No error");
handle = _tjInitCompress(this);
if (!handle) return NULL;
handle = _tjInitDecompress(this);
@@ -1982,7 +1986,7 @@ DLLEXPORT int tjTransform(tjhandle handle, const unsigned char *jpegBuf,
if (xinfo[i].crop) {
if ((t[i].r.x % tjMCUWidth[jpegSubsamp]) != 0 ||
(t[i].r.y % tjMCUHeight[jpegSubsamp]) != 0) {
- snprintf(this->errStr, JMSG_LENGTH_MAX,
+ SNPRINTF(this->errStr, JMSG_LENGTH_MAX,
"To crop this JPEG image, x must be a multiple of %d\n"
"and y must be a multiple of %d.\n",
tjMCUWidth[jpegSubsamp], tjMCUHeight[jpegSubsamp]);
diff --git a/turbojpeg.h b/turbojpeg.h
index 5b33ad84..02b54ca9 100644
--- a/turbojpeg.h
+++ b/turbojpeg.h
@@ -1129,27 +1129,38 @@ DLLEXPORT tjhandle tjInitDecompress(void);
/**
- * Retrieve information about a JPEG image without decompressing it.
+ * Retrieve information about a JPEG image without decompressing it, or prime
+ * the decompressor with quantization and Huffman tables.
*
* @param handle a handle to a TurboJPEG decompressor or transformer instance
*
- * @param jpegBuf pointer to a buffer containing a JPEG image
+ * @param jpegBuf pointer to a buffer containing a JPEG image or an
+ * "abbreviated table specification" (AKA "tables-only") datastream. Passing a
+ * tables-only datastream to this function primes the decompressor with
+ * quantization and Huffman tables that can be used when decompressing
+ * subsequent "abbreviated image" datastreams. This is useful, for instance,
+ * when decompressing video streams in which all frames share the same
+ * quantization and Huffman tables.
*
- * @param jpegSize size of the JPEG image (in bytes)
+ * @param jpegSize size of the JPEG image or tables-only datastream (in bytes)
*
* @param width pointer to an integer variable that will receive the width (in
- * pixels) of the JPEG image
+ * pixels) of the JPEG image. If <tt>jpegBuf</tt> points to a tables-only
+ * datastream, then <tt>width</tt> is ignored.
*
* @param height pointer to an integer variable that will receive the height
- * (in pixels) of the JPEG image
+ * (in pixels) of the JPEG image. If <tt>jpegBuf</tt> points to a tables-only
+ * datastream, then <tt>height</tt> is ignored.
*
* @param jpegSubsamp pointer to an integer variable that will receive the
* level of chrominance subsampling used when the JPEG image was compressed
- * (see @ref TJSAMP "Chrominance subsampling options".)
+ * (see @ref TJSAMP "Chrominance subsampling options".) If <tt>jpegBuf</tt>
+ * points to a tables-only datastream, then <tt>jpegSubsamp</tt> is ignored.
*
* @param jpegColorspace pointer to an integer variable that will receive one
* of the JPEG colorspace constants, indicating the colorspace of the JPEG
- * image (see @ref TJCS "JPEG colorspaces".)
+ * image (see @ref TJCS "JPEG colorspaces".) If <tt>jpegBuf</tt>
+ * points to a tables-only datastream, then <tt>jpegColorspace</tt> is ignored.
*
* @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2()
* and #tjGetErrorCode().)
diff --git a/usage.txt b/usage.txt
index bc2253f1..0b6036ac 100644
--- a/usage.txt
+++ b/usage.txt
@@ -25,7 +25,7 @@ GENERAL USAGE
We provide two programs, cjpeg to compress an image file into JPEG format,
and djpeg to decompress a JPEG file back into a conventional image format.
-On Unix-like systems, you say:
+On most systems, you say:
cjpeg [switches] [imagefile] >jpegfile
or
djpeg [switches] [jpegfile] >imagefile
@@ -34,19 +34,19 @@ named. They always write to standard output (with trace/error messages to
standard error). These conventions are handy for piping images between
programs.
-On most non-Unix systems, you say:
+If you defined TWO_FILE_COMMANDLINE when compiling the programs, you can
+instead say:
cjpeg [switches] imagefile jpegfile
or
djpeg [switches] jpegfile imagefile
i.e., both the input and output files are named on the command line. This
style is a little more foolproof, and it loses no functionality if you don't
-have pipes. (You can get this style on Unix too, if you prefer, by defining
-TWO_FILE_COMMANDLINE when you compile the programs; see install.txt.)
+have pipes.
You can also say:
cjpeg [switches] -outfile jpegfile imagefile
or
- djpeg [switches] -outfile imagefile jpegfile
+ djpeg [switches] -outfile imagefile jpegfile
This syntax works on all systems, so it is useful for scripts.
The currently supported image file formats are: PPM (PBMPLUS color format),
@@ -143,8 +143,8 @@ customized) quantization tables can be set with the -qtables option and
assigned to components with the -qslots option (see the "wizard" switches
below.)
-JPEG files generated with separate luminance and chrominance quality are
-fully compliant with standard JPEG decoders.
+JPEG files generated with separate luminance and chrominance quality are fully
+compliant with standard JPEG decoders.
CAUTION: For this setting to be useful, be sure to pass an argument of
-sample 1x1 to cjpeg to disable chrominance subsampling. Otherwise, the
@@ -218,7 +218,7 @@ Switches for advanced users:
space is needed, an error will occur.
-verbose Enable debug printout. More -v's give more printout.
- or -debug Also, version information is printed at startup.
+ or -debug Also, version information is printed at startup.
The -restart option inserts extra markers that allow a JPEG decoder to
resynchronize after a transmission error. Without restart markers, any damage
@@ -467,9 +467,10 @@ quality. However, while the image data is losslessly transformed, metadata
can be removed. See the -copy option for specifics.
jpegtran uses a command line syntax similar to cjpeg or djpeg.
-On Unix-like systems, you say:
+On most systems, you say:
jpegtran [switches] [inputfile] >outputfile
-On most non-Unix systems, you say:
+If you defined TWO_FILE_COMMANDLINE when compiling the program, you can instead
+say:
jpegtran [switches] inputfile outputfile
where both the input and output files are JPEG files.
@@ -649,13 +650,13 @@ file; it does not modify the input file. DO NOT try to overwrite the input
file by directing wrjpgcom's output back into it; on most systems this will
just destroy your file.
-The command line syntax for wrjpgcom is similar to cjpeg's. On Unix-like
-systems, it is
+The command line syntax for wrjpgcom is similar to cjpeg's. On most systems,
+it is
wrjpgcom [switches] [inputfilename]
The output file is written to standard output. The input file comes from
the named file, or from standard input if no input file is named.
-On most non-Unix systems, the syntax is
+If you defined TWO_FILE_COMMANDLINE when compiling the program, the syntax is:
wrjpgcom [switches] inputfilename outputfilename
where both input and output file names must be given explicitly.
diff --git a/wrjpgcom.c b/wrjpgcom.c
index 3ee08a0e..060925fe 100644
--- a/wrjpgcom.c
+++ b/wrjpgcom.c
@@ -28,16 +28,6 @@
#include <io.h> /* to declare setmode() */
#endif
-#ifdef USE_CCOMMAND /* command-line reader for Macintosh */
-#ifdef __MWERKS__
-#include <SIOUX.h> /* Metrowerks needs this */
-#include <console.h> /* ... and this */
-#endif
-#ifdef THINK_C
-#include <console.h> /* Think declares it here */
-#endif
-#endif
-
#ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */
#define READ_BINARY "r"
#define WRITE_BINARY "w"
@@ -415,11 +405,6 @@ main(int argc, char **argv)
unsigned int comment_length = 0;
int marker;
- /* On Mac, fetch a command line. */
-#ifdef USE_CCOMMAND
- argc = ccommand(&argv);
-#endif
-
progname = argv[0];
if (progname == NULL || progname[0] == 0)
progname = "wrjpgcom"; /* in case C library doesn't provide it */