diff options
Diffstat (limited to 'java/TJBench.java')
-rw-r--r-- | java/TJBench.java | 328 |
1 files changed, 203 insertions, 125 deletions
diff --git a/java/TJBench.java b/java/TJBench.java index ddc414c..bd55562 100644 --- a/java/TJBench.java +++ b/java/TJBench.java @@ -1,5 +1,5 @@ /* - * Copyright (C)2009-2014, 2016-2017 D. R. Commander. All Rights Reserved. + * Copyright (C)2009-2014, 2016-2018 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: @@ -32,50 +32,73 @@ import javax.imageio.*; import java.util.*; import org.libjpegturbo.turbojpeg.*; -class TJBench { +final class TJBench { - static int flags = 0, quiet = 0, pf = TJ.PF_BGR, yuvpad = 1; - static boolean compOnly, decompOnly, doTile, doYUV, write = true; + private TJBench() {} - static final String[] pixFormatStr = { + private static int flags = 0, quiet = 0, pf = TJ.PF_BGR, yuvPad = 1; + private static boolean compOnly, decompOnly, doTile, doYUV, write = true; + + static final String[] PIXFORMATSTR = { "RGB", "BGR", "RGBX", "BGRX", "XBGR", "XRGB", "GRAY" }; - static final String[] subNameLong = { + static final String[] SUBNAME_LONG = { "4:4:4", "4:2:2", "4:2:0", "GRAY", "4:4:0", "4:1:1" }; - static final String[] subName = { + static final String[] SUBNAME = { "444", "422", "420", "GRAY", "440", "411" }; - static final String[] csName = { + static final String[] CSNAME = { "RGB", "YCbCr", "GRAY", "CMYK", "YCCK" }; - static TJScalingFactor sf; - static int xformOp = TJTransform.OP_NONE, xformOpt = 0; - static double benchTime = 5.0, warmup = 1.0; + private static TJScalingFactor sf; + private static int xformOp = TJTransform.OP_NONE, xformOpt = 0; + private static double benchTime = 5.0, warmup = 1.0; - static final double getTime() { + static double getTime() { return (double)System.nanoTime() / 1.0e9; } + private static String tjErrorMsg; + private static int tjErrorCode = -1; + + static void handleTJException(TJException e) throws TJException { + String errorMsg = e.getMessage(); + int errorCode = e.getErrorCode(); + + if ((flags & TJ.FLAG_STOPONWARNING) == 0 && + errorCode == TJ.ERR_WARNING) { + if (tjErrorMsg == null || !tjErrorMsg.equals(errorMsg) || + tjErrorCode != errorCode) { + tjErrorMsg = errorMsg; + tjErrorCode = errorCode; + System.out.println("WARNING: " + errorMsg); + } + } else + throw e; + } + + static String formatName(int subsamp, int cs) { if (cs == TJ.CS_YCbCr) - return subNameLong[subsamp]; + return SUBNAME_LONG[subsamp]; else if (cs == TJ.CS_YCCK) - return csName[cs] + " " + subNameLong[subsamp]; + return CSNAME[cs] + " " + SUBNAME_LONG[subsamp]; else - return csName[cs]; + return CSNAME[cs]; } static String sigFig(double val, int figs) { String format; int digitsAfterDecimal = figs - (int)Math.ceil(Math.log10(Math.abs(val))); + if (digitsAfterDecimal < 1) format = new String("%.0f"); else @@ -87,10 +110,12 @@ class TJBench { static byte[] loadImage(String fileName, int[] w, int[] h, int pixelFormat) throws Exception { BufferedImage img = ImageIO.read(new File(fileName)); + if (img == null) throw new Exception("Could not read " + fileName); w[0] = img.getWidth(); h[0] = img.getHeight(); + int[] rgb = img.getRGB(0, 0, w[0], h[0], null, 0, w[0]); int ps = TJ.getPixelSize(pixelFormat); int rindex = TJ.getRedOffset(pixelFormat); @@ -98,6 +123,7 @@ class TJBench { int bindex = TJ.getBlueOffset(pixelFormat); byte[] dstBuf = new byte[w[0] * h[0] * ps]; int pixels = w[0] * h[0], dstPtr = 0, rgbPtr = 0; + while (pixels-- > 0) { dstBuf[dstPtr + rindex] = (byte)((rgb[rgbPtr] >> 16) & 0xff); dstBuf[dstPtr + gindex] = (byte)((rgb[rgbPtr] >> 8) & 0xff); @@ -117,11 +143,13 @@ class TJBench { int rindex = TJ.getRedOffset(pixelFormat); int gindex = TJ.getGreenOffset(pixelFormat); int bindex = TJ.getBlueOffset(pixelFormat); + for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++, srcPtr += ps) { int pixel = (srcBuf[srcPtr + rindex] & 0xff) << 16 | (srcBuf[srcPtr + gindex] & 0xff) << 8 | (srcBuf[srcPtr + bindex] & 0xff); + img.setRGB(x, y, pixel); } } @@ -157,7 +185,8 @@ class TJBench { if (doYUV) { int width = doTile ? tilew : scaledw; int height = doTile ? tileh : scaledh; - yuvImage = new YUVImage(width, yuvpad, height, subsamp); + + yuvImage = new YUVImage(width, yuvPad, height, subsamp); Arrays.fill(yuvImage.getBuf(), (byte)127); } @@ -167,21 +196,30 @@ class TJBench { 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; + tjd.setSourceImage(jpegBuf[tile], jpegSize[tile]); if (doYUV) { - yuvImage.setBuf(yuvImage.getBuf(), width, yuvpad, height, subsamp); - tjd.decompressToYUV(yuvImage, flags); + yuvImage.setBuf(yuvImage.getBuf(), width, yuvPad, height, subsamp); + try { + tjd.decompressToYUV(yuvImage, flags); + } catch (TJException e) { handleTJException(e); } double startDecode = getTime(); tjd.setSourceImage(yuvImage); - tjd.decompress(dstBuf, x, y, width, pitch, height, pf, flags); + try { + tjd.decompress(dstBuf, x, y, width, pitch, height, pf, flags); + } catch (TJException e) { handleTJException(e); } if (iter >= 0) elapsedDecode += getTime() - startDecode; - } else - tjd.decompress(dstBuf, x, y, width, pitch, height, pf, flags); + } else { + try { + tjd.decompress(dstBuf, x, y, width, pitch, height, pf, flags); + } catch (TJException e) { handleTJException(e); } + } } } elapsed += getTime() - start; @@ -194,7 +232,7 @@ class TJBench { elapsed = elapsedDecode = 0.0; } } - if(doYUV) + if (doYUV) elapsed -= elapsedDecode; tjd = null; @@ -205,16 +243,18 @@ class TJBench { if (quiet != 0) { System.out.format("%-6s%s", - sigFig((double)(w * h) / 1000000. * (double)iter / elapsed, 4), - quiet == 2 ? "\n" : " "); + 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)); + 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 "), + (doYUV ? "Decomp to YUV" : "Decompress "), (double)iter / elapsed); System.out.format(" Throughput: %f Megapixels/sec\n", (double)(w * h) / 1000000. * (double)iter / elapsed); @@ -222,7 +262,8 @@ class TJBench { 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); + (double)(w * h) / 1000000. * + (double)iter / elapsedDecode); } } @@ -237,7 +278,7 @@ class TJBench { if (decompOnly) tempStr = new String(fileName + "_" + sizeStr + ".bmp"); else - tempStr = new String(fileName + "_" + subName[subsamp] + qualStr + + tempStr = new String(fileName + "_" + SUBNAME[subsamp] + qualStr + "_" + sizeStr + ".bmp"); saveImage(tempStr, dstBuf, scaledw, scaledh, pf); @@ -255,6 +296,7 @@ class TJBench { int lum = (int)((double)(srcBuf[rindex] & 0xff) * 0.299 + (double)(srcBuf[gindex] & 0xff) * 0.587 + (double)(srcBuf[bindex] & 0xff) * 0.114 + 0.5); + if (lum > 255) lum = 255; if (lum < 0) lum = 0; dstBuf[rindex] = (byte)Math.abs((dstBuf[rindex] & 0xff) - lum); @@ -284,15 +326,16 @@ class TJBench { int totalJpegSize = 0, tilew, tileh, i, iter; int ps = TJ.getPixelSize(pf); int ntilesw = 1, ntilesh = 1, pitch = w * ps; - String pfStr = pixFormatStr[pf]; + String pfStr = PIXFORMATSTR[pf]; YUVImage yuvImage = null; tmpBuf = new byte[pitch * h]; if (quiet == 0) System.out.format(">>>>> %s (%s) <--> JPEG %s Q%d <<<<<\n", pfStr, - (flags & TJ.FLAG_BOTTOMUP) != 0 ? "Bottom-up" : "Top-down", - subNameLong[subsamp], jpegQual); + (flags & TJ.FLAG_BOTTOMUP) != 0 ? + "Bottom-up" : "Top-down", + SUBNAME_LONG[subsamp], jpegQual); tjc = new TJCompressor(); @@ -312,14 +355,14 @@ class TJBench { if (quiet == 1) System.out.format("%-4s (%s) %-5s %-3d ", pfStr, (flags & TJ.FLAG_BOTTOMUP) != 0 ? "BU" : "TD", - subNameLong[subsamp], jpegQual); + SUBNAME_LONG[subsamp], jpegQual); for (i = 0; i < h; i++) System.arraycopy(srcBuf, w * ps * i, tmpBuf, pitch * i, w * ps); tjc.setJPEGQuality(jpegQual); tjc.setSubsamp(subsamp); if (doYUV) { - yuvImage = new YUVImage(tilew, yuvpad, tileh, subsamp); + yuvImage = new YUVImage(tilew, yuvPad, tileh, subsamp); Arrays.fill(yuvImage.getBuf(), (byte)127); } @@ -328,16 +371,19 @@ class TJBench { elapsed = elapsedEncode = 0.0; while (true) { int tile = 0; + totalJpegSize = 0; start = getTime(); for (int y = 0; y < h; y += tileh) { for (int x = 0; x < w; x += tilew, tile++) { int width = Math.min(tilew, w - x); int height = Math.min(tileh, h - y); + tjc.setSourceImage(srcBuf, x, y, width, pitch, height, pf); if (doYUV) { double startEncode = getTime(); - yuvImage.setBuf(yuvImage.getBuf(), width, yuvpad, height, + + yuvImage.setBuf(yuvImage.getBuf(), width, yuvPad, height, subsamp); tjc.encodeYUV(yuvImage, flags); if (iter >= 0) @@ -367,14 +413,17 @@ class TJBench { if (quiet != 0) { if (doYUV) System.out.format("%-6s%s", - sigFig((double)(w * h) / 1000000. * (double)iter / elapsedEncode, 4), - quiet == 2 ? "\n" : " "); + sigFig((double)(w * h) / 1000000. * + (double)iter / elapsedEncode, 4), + quiet == 2 ? "\n" : " "); System.out.format("%-6s%s", - sigFig((double)(w * h) / 1000000. * (double)iter / elapsed, 4), - quiet == 2 ? "\n" : " "); + sigFig((double)(w * h) / 1000000. * + (double)iter / elapsed, 4), + quiet == 2 ? "\n" : " "); System.out.format("%-6s%s", - sigFig((double)(w * h * ps) / (double)totalJpegSize, 4), - quiet == 2 ? "\n" : " "); + sigFig((double)(w * h * ps) / (double)totalJpegSize, + 4), + quiet == 2 ? "\n" : " "); } else { System.out.format("\n%s size: %d x %d\n", doTile ? "Tile" : "Image", tilew, tileh); @@ -386,9 +435,11 @@ class TJBench { System.out.format(" Compression ratio: %f:1\n", (double)(w * h * ps) / (double)yuvImage.getSize()); System.out.format(" Throughput: %f Megapixels/sec\n", - (double)(w * h) / 1000000. * (double)iter / elapsedEncode); + (double)(w * h) / 1000000. * + (double)iter / elapsedEncode); System.out.format(" Output bit stream: %f Megabits/sec\n", - (double)yuvImage.getSize() * 8. / 1000000. * (double)iter / elapsedEncode); + (double)yuvImage.getSize() * 8. / 1000000. * + (double)iter / elapsedEncode); } System.out.format("%s --> Frame rate: %f fps\n", doYUV ? "Comp from YUV" : "Compress ", @@ -400,12 +451,14 @@ class TJBench { System.out.format(" Throughput: %f Megapixels/sec\n", (double)(w * h) / 1000000. * (double)iter / elapsed); System.out.format(" Output bit stream: %f Megabits/sec\n", - (double)totalJpegSize * 8. / 1000000. * (double)iter / elapsed); + (double)totalJpegSize * 8. / 1000000. * + (double)iter / elapsed); } if (tilew == w && tileh == h && write) { - String tempStr = fileName + "_" + subName[subsamp] + "_" + "Q" + + String tempStr = fileName + "_" + SUBNAME[subsamp] + "_" + "Q" + jpegQual + ".jpg"; FileOutputStream fos = new FileOutputStream(tempStr); + fos.write(jpegBuf[0], 0, jpegSize[0]); fos.close(); if (quiet == 0) @@ -428,11 +481,12 @@ class TJBench { byte[] srcBuf; int[] jpegSize = null; int totalJpegSize; - int w = 0, h = 0, subsamp = -1, cs = -1, _w, _h, _tilew, _tileh, - _ntilesw, _ntilesh, _subsamp, x, y, iter; - int ntilesw = 1, ntilesh = 1; double start, elapsed; - int ps = TJ.getPixelSize(pf), tile; + int ps = TJ.getPixelSize(pf), tile, x, y, iter; + // Original image + int w = 0, h = 0, ntilesw = 1, ntilesh = 1, subsamp = -1, cs = -1; + // Transformed image + int tw, th, ttilew, ttileh, tntilesw, tntilesh, tsubsamp; FileInputStream fis = new FileInputStream(fileName); int srcSize = (int)fis.getChannel().size(); @@ -466,8 +520,9 @@ class TJBench { System.out.println("\n"); } else if (quiet == 0) System.out.format(">>>>> JPEG %s --> %s (%s) <<<<<\n", - formatName(subsamp, cs), pixFormatStr[pf], - (flags & TJ.FLAG_BOTTOMUP) != 0 ? "Bottom-up" : "Top-down"); + formatName(subsamp, cs), PIXFORMATSTR[pf], + (flags & TJ.FLAG_BOTTOMUP) != 0 ? + "Bottom-up" : "Top-down"); for (int tilew = doTile ? 16 : w, tileh = doTile ? 16 : h; ; tilew *= 2, tileh *= 2) { @@ -478,65 +533,66 @@ class TJBench { ntilesw = (w + tilew - 1) / tilew; ntilesh = (h + tileh - 1) / tileh; - _w = w; _h = h; _tilew = tilew; _tileh = tileh; + tw = w; th = h; ttilew = tilew; ttileh = tileh; if (quiet == 0) { System.out.format("\n%s size: %d x %d", (doTile ? "Tile" : "Image"), - _tilew, _tileh); + ttilew, ttileh); if (sf.getNum() != 1 || sf.getDenom() != 1) - System.out.format(" --> %d x %d", sf.getScaled(_w), - sf.getScaled(_h)); + System.out.format(" --> %d x %d", sf.getScaled(tw), + sf.getScaled(th)); System.out.println(""); } else if (quiet == 1) { - System.out.format("%-4s (%s) %-5s %-5s ", pixFormatStr[pf], + System.out.format("%-4s (%s) %-5s %-5s ", PIXFORMATSTR[pf], (flags & TJ.FLAG_BOTTOMUP) != 0 ? "BU" : "TD", - csName[cs], subNameLong[subsamp]); + CSNAME[cs], SUBNAME_LONG[subsamp]); System.out.format("%-5d %-5d ", tilew, tileh); } - _subsamp = subsamp; + tsubsamp = subsamp; if (doTile || xformOp != TJTransform.OP_NONE || xformOpt != 0) { if (xformOp == TJTransform.OP_TRANSPOSE || xformOp == TJTransform.OP_TRANSVERSE || xformOp == TJTransform.OP_ROT90 || xformOp == TJTransform.OP_ROT270) { - _w = h; _h = w; _tilew = tileh; _tileh = tilew; + tw = h; th = w; ttilew = tileh; ttileh = tilew; } if ((xformOpt & TJTransform.OPT_GRAY) != 0) - _subsamp = TJ.SAMP_GRAY; + tsubsamp = TJ.SAMP_GRAY; if (xformOp == TJTransform.OP_HFLIP || xformOp == TJTransform.OP_ROT180) - _w = _w - (_w % TJ.getMCUWidth(_subsamp)); + tw = tw - (tw % TJ.getMCUWidth(tsubsamp)); if (xformOp == TJTransform.OP_VFLIP || xformOp == TJTransform.OP_ROT180) - _h = _h - (_h % TJ.getMCUHeight(_subsamp)); + th = th - (th % TJ.getMCUHeight(tsubsamp)); if (xformOp == TJTransform.OP_TRANSVERSE || xformOp == TJTransform.OP_ROT90) - _w = _w - (_w % TJ.getMCUHeight(_subsamp)); + tw = tw - (tw % TJ.getMCUHeight(tsubsamp)); if (xformOp == TJTransform.OP_TRANSVERSE || xformOp == TJTransform.OP_ROT270) - _h = _h - (_h % TJ.getMCUWidth(_subsamp)); - _ntilesw = (_w + _tilew - 1) / _tilew; - _ntilesh = (_h + _tileh - 1) / _tileh; + th = th - (th % TJ.getMCUWidth(tsubsamp)); + tntilesw = (tw + ttilew - 1) / ttilew; + tntilesh = (th + ttileh - 1) / ttileh; if (xformOp == TJTransform.OP_TRANSPOSE || xformOp == TJTransform.OP_TRANSVERSE || xformOp == TJTransform.OP_ROT90 || xformOp == TJTransform.OP_ROT270) { - if (_subsamp == TJ.SAMP_422) - _subsamp = TJ.SAMP_440; - else if (_subsamp == TJ.SAMP_440) - _subsamp = TJ.SAMP_422; + if (tsubsamp == TJ.SAMP_422) + tsubsamp = TJ.SAMP_440; + else if (tsubsamp == TJ.SAMP_440) + tsubsamp = TJ.SAMP_422; } - TJTransform[] t = new TJTransform[_ntilesw * _ntilesh]; - jpegBuf = new byte[_ntilesw * _ntilesh][TJ.bufSize(_tilew, _tileh, subsamp)]; + TJTransform[] t = new TJTransform[tntilesw * tntilesh]; + jpegBuf = + new byte[tntilesw * tntilesh][TJ.bufSize(ttilew, ttileh, subsamp)]; - for (y = 0, tile = 0; y < _h; y += _tileh) { - for (x = 0; x < _w; x += _tilew, tile++) { + for (y = 0, tile = 0; y < th; y += ttileh) { + for (x = 0; x < tw; x += ttilew, tile++) { t[tile] = new TJTransform(); - t[tile].width = Math.min(_tilew, _w - x); - t[tile].height = Math.min(_tileh, _h - y); + t[tile].width = Math.min(ttilew, tw - x); + t[tile].height = Math.min(ttileh, th - y); t[tile].x = x; t[tile].y = y; t[tile].op = xformOp; @@ -565,15 +621,16 @@ class TJBench { } t = null; - for (tile = 0, totalJpegSize = 0; tile < _ntilesw * _ntilesh; tile++) + for (tile = 0, totalJpegSize = 0; tile < tntilesw * tntilesh; tile++) totalJpegSize += jpegSize[tile]; if (quiet != 0) { System.out.format("%-6s%s%-6s%s", - sigFig((double)(w * h) / 1000000. / elapsed, 4), - quiet == 2 ? "\n" : " ", - sigFig((double)(w * h * ps) / (double)totalJpegSize, 4), - quiet == 2 ? "\n" : " "); + sigFig((double)(w * h) / 1000000. / elapsed, 4), + quiet == 2 ? "\n" : " ", + sigFig((double)(w * h * ps) / + (double)totalJpegSize, 4), + quiet == 2 ? "\n" : " "); } else if (quiet == 0) { System.out.format("Transform --> Frame rate: %f fps\n", 1.0 / elapsed); @@ -589,19 +646,19 @@ class TJBench { } else { if (quiet == 1) System.out.print("N/A N/A "); - jpegBuf = new byte[1][TJ.bufSize(_tilew, _tileh, subsamp)]; + jpegBuf = new byte[1][TJ.bufSize(ttilew, ttileh, subsamp)]; jpegSize = new int[1]; jpegBuf[0] = srcBuf; jpegSize[0] = srcSize; } if (w == tilew) - _tilew = _w; + ttilew = tw; if (h == tileh) - _tileh = _h; + ttileh = th; if ((xformOpt & TJTransform.OPT_NOOUTPUT) == 0) - decomp(null, jpegBuf, jpegSize, null, _w, _h, _subsamp, 0, - fileName, _tilew, _tileh); + decomp(null, jpegBuf, jpegSize, null, tw, th, tsubsamp, 0, + fileName, ttilew, ttileh); else if (quiet == 1) System.out.println("N/A"); @@ -636,6 +693,8 @@ class TJBench { System.out.println(" codec"); System.out.println("-accuratedct = Use the most accurate DCT/IDCT algorithms available in the"); System.out.println(" underlying codec"); + System.out.println("-progressive = Use progressive entropy coding in JPEG images generated by"); + System.out.println(" compression and transform operations."); System.out.println("-subsamp <s> = When testing JPEG compression, this option specifies the level"); System.out.println(" of chrominance subsampling to use (<s> = 444, 422, 440, 420, 411, or"); System.out.println(" GRAY). The default is to test Grayscale, 4:2:0, 4:2:2, and 4:4:4 in"); @@ -667,13 +726,18 @@ class TJBench { System.out.println(" decompression (these options are mutually exclusive)"); System.out.println("-grayscale = Perform lossless grayscale conversion prior to decompression"); System.out.println(" test (can be combined with the other transforms above)"); + System.out.println("-copynone = Do not copy any extra markers (including EXIF and ICC profile data)"); + System.out.println(" when transforming the image."); System.out.println("-benchtime <t> = Run each benchmark for at least <t> seconds (default = 5.0)"); System.out.println("-warmup <t> = Run each benchmark for <t> seconds (default = 1.0) prior to"); System.out.println(" starting the timer, in order to prime the caches and thus improve the"); System.out.println(" consistency of the results."); System.out.println("-componly = Stop after running compression tests. Do not test decompression."); System.out.println("-nowrite = Do not write reference or output images (improves consistency"); - System.out.println(" of performance measurements.)\n"); + System.out.println(" of performance measurements.)"); + System.out.println("-stoponwarning = Immediately discontinue the current"); + System.out.println(" compression/decompression/transform operation if the underlying codec"); + System.out.println(" throws a warning (non-fatal error)\n"); System.out.println("NOTE: If the quality is specified as a range (e.g. 90-100), a separate"); System.out.println("test will be performed for all quality values in the range.\n"); System.exit(1); @@ -681,9 +745,9 @@ class TJBench { public static void main(String[] argv) { - byte[] srcBuf = null; int w = 0, h = 0; - int minQual = -1, maxQual = -1; - int minArg = 1; int retval = 0; + byte[] srcBuf = null; + int w = 0, h = 0, minQual = -1, maxQual = -1; + int minArg = 1, retval = 0; int subsamp = -1; try { @@ -720,20 +784,19 @@ class TJBench { for (int i = minArg; i < argv.length; i++) { if (argv[i].equalsIgnoreCase("-tile")) { doTile = true; xformOpt |= TJTransform.OPT_CROP; - } - else if (argv[i].equalsIgnoreCase("-fastupsample")) { + } else if (argv[i].equalsIgnoreCase("-fastupsample")) { System.out.println("Using fast upsampling code\n"); flags |= TJ.FLAG_FASTUPSAMPLE; - } - else if (argv[i].equalsIgnoreCase("-fastdct")) { + } else if (argv[i].equalsIgnoreCase("-fastdct")) { System.out.println("Using fastest DCT/IDCT algorithm\n"); flags |= TJ.FLAG_FASTDCT; - } - else if (argv[i].equalsIgnoreCase("-accuratedct")) { + } else if (argv[i].equalsIgnoreCase("-accuratedct")) { System.out.println("Using most accurate DCT/IDCT algorithm\n"); flags |= TJ.FLAG_ACCURATEDCT; - } - else if (argv[i].equalsIgnoreCase("-rgb")) + } else if (argv[i].equalsIgnoreCase("-progressive")) { + System.out.println("Using progressive entropy coding\n"); + flags |= TJ.FLAG_PROGRESSIVE; + } else if (argv[i].equalsIgnoreCase("-rgb")) pf = TJ.PF_RGB; else if (argv[i].equalsIgnoreCase("-rgbx")) pf = TJ.PF_RGBX; @@ -755,26 +818,27 @@ class TJBench { int temp1 = 0, temp2 = 0; boolean match = false, scanned = true; Scanner scanner = new Scanner(argv[++i]).useDelimiter("/"); + try { temp1 = scanner.nextInt(); temp2 = scanner.nextInt(); - } catch(Exception e) {} + } catch (Exception e) {} if (temp2 <= 0) temp2 = 1; if (temp1 > 0) { TJScalingFactor[] scalingFactors = TJ.getScalingFactors(); + for (int j = 0; j < scalingFactors.length; j++) { if ((double)temp1 / (double)temp2 == (double)scalingFactors[j].getNum() / (double)scalingFactors[j].getDenom()) { sf = scalingFactors[j]; - match = true; break; + match = true; break; } } if (!match) usage(); } else usage(); - } - else if (argv[i].equalsIgnoreCase("-hflip")) + } else if (argv[i].equalsIgnoreCase("-hflip")) xformOp = TJTransform.OP_HFLIP; else if (argv[i].equalsIgnoreCase("-vflip")) xformOp = TJTransform.OP_VFLIP; @@ -792,8 +856,12 @@ class TJBench { xformOpt |= TJTransform.OPT_GRAY; else if (argv[i].equalsIgnoreCase("-nooutput")) xformOpt |= TJTransform.OPT_NOOUTPUT; - else if (argv[i].equalsIgnoreCase("-benchtime") && i < argv.length - 1) { + else if (argv[i].equalsIgnoreCase("-copynone")) + xformOpt |= TJTransform.OPT_COPYNONE; + else if (argv[i].equalsIgnoreCase("-benchtime") && + i < argv.length - 1) { double temp = -1; + try { temp = Double.parseDouble(argv[++i]); } catch (NumberFormatException e) {} @@ -801,20 +869,32 @@ class TJBench { benchTime = temp; else usage(); - } - else if (argv[i].equalsIgnoreCase("-yuv")) { + } else if (argv[i].equalsIgnoreCase("-warmup") && + i < argv.length - 1) { + double temp = -1; + + try { + temp = Double.parseDouble(argv[++i]); + } catch (NumberFormatException e) {} + if (temp >= 0.0) { + warmup = temp; + System.out.format("Warmup time = %.1f seconds\n\n", warmup); + } else + usage(); + } else if (argv[i].equalsIgnoreCase("-yuv")) { System.out.println("Testing YUV planar encoding/decoding\n"); doYUV = true; - } - else if (argv[i].equalsIgnoreCase("-yuvpad") && i < argv.length - 1) { + } else if (argv[i].equalsIgnoreCase("-yuvpad") && + i < argv.length - 1) { int temp = 0; + try { - temp = Integer.parseInt(argv[++i]); + temp = Integer.parseInt(argv[++i]); } catch (NumberFormatException e) {} if (temp >= 1) - yuvpad = temp; - } - else if (argv[i].equalsIgnoreCase("-subsamp") && i < argv.length - 1) { + yuvPad = temp; + } else if (argv[i].equalsIgnoreCase("-subsamp") && + i < argv.length - 1) { i++; if (argv[i].toUpperCase().startsWith("G")) subsamp = TJ.SAMP_GRAY; @@ -828,22 +908,12 @@ class TJBench { subsamp = TJ.SAMP_420; else if (argv[i].equals("411")) subsamp = TJ.SAMP_411; - } - else if (argv[i].equalsIgnoreCase("-componly")) + } else if (argv[i].equalsIgnoreCase("-componly")) compOnly = true; else if (argv[i].equalsIgnoreCase("-nowrite")) write = false; - else if (argv[i].equalsIgnoreCase("-warmup") && i < argv.length - 1) { - double temp = -1; - try { - temp = Double.parseDouble(argv[++i]); - } catch (NumberFormatException e) {} - if (temp >= 0.0) { - warmup = temp; - System.out.format("Warmup time = %.1f seconds\n\n", warmup); - } else - usage(); - } + else if (argv[i].equalsIgnoreCase("-stoponwarning")) + flags |= TJ.FLAG_STOPONWARNING; else usage(); } } @@ -859,6 +929,7 @@ class TJBench { if (!decompOnly) { int[] width = new int[1], height = new int[1]; + srcBuf = loadImage(argv[0], width, height, pf); w = width[0]; h = height[0]; int index = -1; @@ -869,7 +940,8 @@ class TJBench { if (quiet == 1 && !decompOnly) { System.out.println("All performance values in Mpixels/sec\n"); System.out.format("Bitmap JPEG JPEG %s %s ", - (doTile ? "Tile " : "Image"), (doTile ? "Tile " : "Image")); + (doTile ? "Tile " : "Image"), + (doTile ? "Tile " : "Image")); if (doYUV) System.out.print("Encode "); System.out.print("Comp Comp Decomp "); @@ -915,7 +987,13 @@ class TJBench { } } catch (Exception e) { - System.out.println("ERROR: " + e.getMessage()); + if (e instanceof TJException) { + TJException tje = (TJException)e; + + System.out.println((tje.getErrorCode() == TJ.ERR_WARNING ? + "WARNING: " : "ERROR: ") + tje.getMessage()); + } else + System.out.println("ERROR: " + e.getMessage()); e.printStackTrace(); retval = -1; } |