TJBench: Require known subsamp type w/tiled decomp

(oversight from 386ec0abc7)

Tiled decompression will ultimately fail if the subsampling type of the
JPEG input image is unknown, but the C version of TJBench needs to fail
earlier in order to avoid using -1 (TJSAMP_UNKNOWN) as an array index
for tjMCUWidth[]/tjMCUHeight[].  The Java version now fails earlier as
well, although there is no benefit to that other than making the error
message less cryptic.
This commit is contained in:
DRC
2023-03-31 10:53:29 -05:00
parent cc8c6d3667
commit 0d20aa15ce
2 changed files with 13 additions and 4 deletions

View File

@@ -530,7 +530,7 @@ final class TJBench {
// Original image
int w = 0, h = 0, ntilesw = 1, ntilesh = 1, subsamp = -1, cs = -1;
// Transformed image
int minTile, tw, th, ttilew, ttileh, tntilesw, tntilesh, tsubsamp;
int minTile = 16, tw, th, ttilew, ttileh, tntilesw, tntilesh, tsubsamp;
FileInputStream fis = new FileInputStream(fileName);
if (fis.getChannel().size() > (long)Integer.MAX_VALUE)
@@ -593,7 +593,11 @@ final class TJBench {
precision, formatName(subsamp, cs), PIXFORMATSTR[pf],
bottomUp ? "Bottom-up" : "Top-down");
if (doTile) {
if (subsamp == TJ.SAMP_UNKNOWN)
throw new Exception("Could not determine subsampling level of JPEG image");
minTile = Math.max(TJ.getMCUWidth(subsamp), TJ.getMCUHeight(subsamp));
}
for (int tilew = doTile ? minTile : w, tileh = doTile ? minTile : h; ;
tilew *= 2, tileh *= 2) {
if (tilew > w)

View File

@@ -617,7 +617,7 @@ static int decompTest(char *fileName)
int ps = tjPixelSize[pf], tile, row, col, i, iter, retval = 0, decompsrc = 0;
char *temp = NULL, tempStr[80], tempStr2[80];
/* Original image */
int w = 0, h = 0, minTile, tilew, tileh, ntilesw = 1, ntilesh = 1,
int w = 0, h = 0, minTile = 16, tilew, tileh, ntilesw = 1, ntilesh = 1,
subsamp = -1, cs = -1;
/* Transformed image */
int tw, th, ttilew, ttileh, tntilesw, tntilesh, tsubsamp;
@@ -697,7 +697,12 @@ static int decompTest(char *fileName)
formatName(subsamp, cs, tempStr), pixFormatStr[pf],
bottomUp ? "Bottom-up" : "Top-down");
if (doTile) {
if (subsamp == TJSAMP_UNKNOWN)
THROW("transforming",
"Could not determine subsampling level of JPEG image");
minTile = max(tjMCUWidth[subsamp], tjMCUHeight[subsamp]);
}
for (tilew = doTile ? minTile : w, tileh = doTile ? minTile : h; ;
tilew *= 2, tileh *= 2) {
if (tilew > w) tilew = w;