in java/TJBench.java [162:329]
static void decomp(byte[][] jpegBufs, int[] jpegSizes, Object dstBuf, int w,
int h, int subsamp, int jpegQual, String fileName,
int tilew, int tileh) throws Exception {
String qualStr = new String(""), sizeStr, tempStr;
TJDecompressor tjd;
double elapsed, elapsedDecode;
int ps = TJ.getPixelSize(pf), i, iter = 0;
int scaledw, scaledh, pitch;
YUVImage yuvImage = null;
if (lossless)
sf = TJ.UNSCALED;
scaledw = sf.getScaled(w);
scaledh = sf.getScaled(h);
if (jpegQual > 0)
qualStr = new String((lossless ? "_PSV" : "_Q") + jpegQual);
tjd = new TJDecompressor();
tjd.set(TJ.PARAM_STOPONWARNING, stopOnWarning ? 1 : 0);
tjd.set(TJ.PARAM_BOTTOMUP, bottomUp ? 1 : 0);
tjd.set(TJ.PARAM_FASTUPSAMPLE, fastUpsample ? 1 : 0);
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 {
tjd.setSourceImage(jpegBufs[0], jpegSizes[0]);
} catch (TJException e) { handleTJException(e); }
}
tjd.setScalingFactor(sf);
tjd.setCroppingRegion(cr);
if (isCropped(cr)) {
scaledw = cr.width != 0 ? cr.width : scaledw - cr.x;
scaledh = cr.height != 0 ? cr.height : scaledh - cr.y;
}
pitch = scaledw * ps;
if (dstBuf == null) {
if ((long)pitch * (long)scaledh > (long)Integer.MAX_VALUE)
throw new Exception("Image is too large");
if (precision == 8)
dstBuf = new byte[pitch * scaledh];
else
dstBuf = new short[pitch * scaledh];
}
/* Set the destination buffer to gray so we know whether the decompressor
attempted to write to it */
if (precision == 8)
Arrays.fill((byte[])dstBuf, (byte)127);
else if (precision == 12)
Arrays.fill((short[])dstBuf, (short)2047);
else
Arrays.fill((short[])dstBuf, (short)32767);
if (doYUV) {
int width = doTile ? tilew : scaledw;
int height = doTile ? tileh : scaledh;
yuvImage = new YUVImage(width, yuvAlign, height, subsamp);
Arrays.fill(yuvImage.getBuf(), (byte)127);
}
/* Benchmark */
iter = -1;
elapsed = elapsedDecode = 0.0;
while (true) {
int tile = 0;
double start = getTime();
for (int y = 0; y < h; y += tileh) {
for (int x = 0; x < w; x += tilew, tile++) {
int width = doTile ? Math.min(tilew, w - x) : scaledw;
int height = doTile ? Math.min(tileh, h - y) : scaledh;
try {
tjd.setSourceImage(jpegBufs[tile], jpegSizes[tile]);
} catch (TJException e) { handleTJException(e); }
if (doYUV) {
yuvImage.setBuf(yuvImage.getBuf(), width, yuvAlign, height,
subsamp);
try {
tjd.decompressToYUV(yuvImage);
} catch (TJException e) { handleTJException(e); }
double startDecode = getTime();
tjd.setSourceImage(yuvImage);
try {
tjd.decompress8((byte[])dstBuf, x, y, pitch, pf);
} catch (TJException e) { handleTJException(e); }
if (iter >= 0)
elapsedDecode += getTime() - startDecode;
} else {
try {
if (precision == 8)
tjd.decompress8((byte[])dstBuf, x, y, pitch, pf);
else if (precision == 12)
tjd.decompress12((short[])dstBuf, x, y, pitch, pf);
else
tjd.decompress16((short[])dstBuf, x, y, pitch, pf);
} catch (TJException e) { handleTJException(e); }
}
}
}
elapsed += getTime() - start;
if (iter >= 0) {
iter++;
if (elapsed >= benchTime)
break;
} else if (elapsed >= warmup) {
iter = 0;
elapsed = elapsedDecode = 0.0;
}
}
if (doYUV)
elapsed -= elapsedDecode;
for (i = 0; i < jpegBufs.length; i++)
jpegBufs[i] = null;
jpegBufs = null; jpegSizes = null;
System.gc();
if (quiet != 0) {
System.out.format("%-6s%s",
sigFig((double)(w * h) / 1000000. *
(double)iter / elapsed, 4),
quiet == 2 ? "\n" : " ");
if (doYUV)
System.out.format("%s\n",
sigFig((double)(w * h) / 1000000. *
(double)iter / elapsedDecode, 4));
else if (quiet != 2)
System.out.print("\n");
} else {
System.out.format("%s --> Frame rate: %f fps\n",
(doYUV ? "Decomp to YUV" : "Decompress "),
(double)iter / elapsed);
System.out.format(" Throughput: %f Megapixels/sec\n",
(double)(w * h) / 1000000. * (double)iter / elapsed);
if (doYUV) {
System.out.format("YUV Decode --> Frame rate: %f fps\n",
(double)iter / elapsedDecode);
System.out.format(" Throughput: %f Megapixels/sec\n",
(double)(w * h) / 1000000. *
(double)iter / elapsedDecode);
}
}
if (!write) return;
if (sf.getNum() != 1 || sf.getDenom() != 1)
sizeStr = new String(sf.getNum() + "_" + sf.getDenom());
else if (tilew != w || tileh != h)
sizeStr = new String(tilew + "x" + tileh);
else
sizeStr = new String("full");
if (decompOnly)
tempStr = new String(fileName + "_" + sizeStr + (bmp ? ".bmp" : ".ppm"));
else
tempStr = new String(fileName + "_" +
(lossless ? "LOSSLS" : SUBNAME[subsamp]) + qualStr +
"_" + sizeStr + (bmp ? ".bmp" : ".ppm"));
tjd.saveImage(precision, tempStr, dstBuf, scaledw, 0, scaledh, pf);
}