TJBench: Recover from non-fatal errors if possible
Previously, -stoponwarning only had an effect on the underlying TurboJPEG C functions, but TJBench still aborted if a non-fatal error occurred. This commit modifies the C version of TJBench such that it always recovers from a non-fatal error unless -stoponwarning is specified. Furthermore, the benchmark stores the details of the last non-fatal error and does not print any subsequent non-fatal error messages unless they differ from the last one. Due to limitations in the Java API (specifically, the fact that it cannot communicate errors, fatal or otherwise, to the calling program without throwing a TJException), it was only possible to make decompression operations fully recoverable within TJBench. With other operations, -stoponwarning still has an effect on the underlying C library but has no effect at the Java level. The Java API documentation has been amended to reflect that only certain methods are truly recoverable, regardless of the state of TJ.FLAG_STOPONWARNING.
This commit is contained in:
@@ -63,6 +63,26 @@ class TJBench {
|
||||
}
|
||||
|
||||
|
||||
static String tjErrorMsg;
|
||||
static int tjErrorCode = -1;
|
||||
|
||||
static void handleTJException(TJException e) throws TJException {
|
||||
String _tjErrorMsg = e.getMessage();
|
||||
int _tjErrorCode = e.getErrorCode();
|
||||
|
||||
if ((flags & TJ.FLAG_STOPONWARNING) == 0 &&
|
||||
_tjErrorCode == TJ.ERR_WARNING) {
|
||||
if (tjErrorMsg == null || !tjErrorMsg.equals(_tjErrorMsg) ||
|
||||
tjErrorCode != _tjErrorCode) {
|
||||
tjErrorMsg = _tjErrorMsg;
|
||||
tjErrorCode = _tjErrorCode;
|
||||
System.out.println("WARNING: " + _tjErrorMsg);
|
||||
}
|
||||
} else
|
||||
throw e;
|
||||
}
|
||||
|
||||
|
||||
static String formatName(int subsamp, int cs) {
|
||||
if (cs == TJ.CS_YCbCr)
|
||||
return subNameLong[subsamp];
|
||||
@@ -174,14 +194,21 @@ class TJBench {
|
||||
tjd.setSourceImage(jpegBuf[tile], jpegSize[tile]);
|
||||
if (doYUV) {
|
||||
yuvImage.setBuf(yuvImage.getBuf(), width, yuvpad, height, subsamp);
|
||||
tjd.decompressToYUV(yuvImage, flags);
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user