TurboJPEG: Expose/extend hidden "max pixels" param

TJPARAM_MAXPIXELS was previously hidden and used only for fuzz testing,
but it is potentially useful for calling applications as well,
particularly if they want to guard against excessive memory consumption
by the tj3LoadImage*() functions.  The parameter has also been extended
to decompression and lossless transformation functions/methods, mainly
as a convenience.  (It was already possible for calling applications to
impose their own JPEG image size limits by reading the JPEG header prior
to decompressing or transforming the image.)
This commit is contained in:
DRC
2023-11-16 15:36:47 -05:00
parent 6136a9e285
commit 55d342c788
41 changed files with 409 additions and 309 deletions

View File

@@ -41,8 +41,9 @@ final class TJBench {
private static boolean stopOnWarning, bottomUp, fastUpsample, fastDCT,
optimize, progressive, limitScans, arithmetic, lossless;
private static int maxMemory = 0, precision = 8, quiet = 0, pf = TJ.PF_BGR,
yuvAlign = 1, restartIntervalBlocks, restartIntervalRows = 0;
private static int maxMemory = 0, maxPixels = 0, precision = 8, quiet = 0,
pf = TJ.PF_BGR, yuvAlign = 1, restartIntervalBlocks,
restartIntervalRows = 0;
private static boolean compOnly, decompOnly, doTile, doYUV, write = true,
bmp = false;
@@ -184,6 +185,7 @@ final class TJBench {
tjd.set(TJ.PARAM_FASTDCT, fastDCT ? 1 : 0);
tjd.set(TJ.PARAM_SCANLIMIT, limitScans ? 500 : 0);
tjd.set(TJ.PARAM_MAXMEMORY, maxMemory);
tjd.set(TJ.PARAM_MAXPIXELS, maxPixels);
if (isCropped(cr)) {
try {
@@ -553,6 +555,7 @@ final class TJBench {
tjt.set(TJ.PARAM_FASTDCT, fastDCT ? 1 : 0);
tjt.set(TJ.PARAM_SCANLIMIT, limitScans ? 500 : 0);
tjt.set(TJ.PARAM_MAXMEMORY, maxMemory);
tjt.set(TJ.PARAM_MAXPIXELS, maxPixels);
try {
tjt.setSourceImage(srcBuf, srcSize);
@@ -782,6 +785,7 @@ final class TJBench {
System.out.println(" progressive JPEG compression and decompression, optimized baseline entropy");
System.out.println(" coding, lossless JPEG compression, and lossless transformation");
System.out.println(" [default = no limit]");
System.out.println("-maxpixels = Input image size limit (in pixels) [default = no limit]");
System.out.println("-nowrite = Do not write reference or output images (improves consistency of");
System.out.println(" benchmark results)");
System.out.println("-rgb, -bgr, -rgbx, -bgrx, -xbgr, -xrgb =");
@@ -1091,6 +1095,16 @@ final class TJBench {
if (temp < 0)
usage();
maxMemory = temp;
} else if (argv[i].equalsIgnoreCase("-maxpixels") &&
i < argv.length - 1) {
int temp = -1;
try {
temp = Integer.parseInt(argv[++i]);
} catch (NumberFormatException e) {}
if (temp < 0)
usage();
maxPixels = temp;
} else if (argv[i].equalsIgnoreCase("-restart") &&
i < argv.length - 1) {
int temp = -1;
@@ -1147,6 +1161,7 @@ final class TJBench {
tjc = new TJCompressor();
tjc.set(TJ.PARAM_STOPONWARNING, stopOnWarning ? 1 : 0);
tjc.set(TJ.PARAM_BOTTOMUP, bottomUp ? 1 : 0);
tjc.set(TJ.PARAM_MAXPIXELS, maxPixels);
pixelFormat[0] = pf;
srcBuf = tjc.loadImage(precision, argv[0], width, 1, height,