}
+ 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];
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;
<div class="block">Immediately discontinue the current compression/decompression/transform
operation if the underlying codec throws a warning (non-fatal error). The
default behavior is to allow the operation to complete unless a fatal
- error is encountered.</div>
+ error is encountered.
+ <p>
+ NOTE: due to the design of the TurboJPEG Java API, only certain methods
+ (specifically, <a href="../../../org/libjpegturbo/turbojpeg/TJDecompressor.html" title="class in org.libjpegturbo.turbojpeg"><code>TJDecompressor.decompress*()</code></a> methods
+ with a void return type) will complete and leave the output image in a
+ fully recoverable state after a non-fatal error occurs.</div>
<dl><dt><span class="strong">See Also:</span></dt><dd><a href="../../../constant-values.html#org.libjpegturbo.turbojpeg.TJ.FLAG_STOPONWARNING">Constant Field Values</a></dd></dl>
</li>
</ul>
<h4>ERR_WARNING</h4>
<pre>public static final int ERR_WARNING</pre>
<div class="block">The error was non-fatal and recoverable, but the image may still be
- corrupt.</div>
+ corrupt.
+ <p>
+ NOTE: due to the design of the TurboJPEG Java API, only certain methods
+ (specifically, <a href="../../../org/libjpegturbo/turbojpeg/TJDecompressor.html" title="class in org.libjpegturbo.turbojpeg"><code>TJDecompressor.decompress*()</code></a> methods
+ with a void return type) will complete and leave the output image in a
+ fully recoverable state after a non-fatal error occurs.</div>
<dl><dt><span class="strong">See Also:</span></dt><dd><a href="../../../constant-values.html#org.libjpegturbo.turbojpeg.TJ.ERR_WARNING">Constant Field Values</a></dd></dl>
</li>
</ul>
throws <a href="../../../org/libjpegturbo/turbojpeg/TJException.html" title="class in org.libjpegturbo.turbojpeg">TJException</a></pre>
<div class="block">Decompress the JPEG source image or decode the YUV source image associated
with this decompressor instance and output a grayscale, RGB, or CMYK image
- to the given destination buffer.</div>
+ to the given destination buffer.
+ <p>
+ NOTE: The output image is fully recoverable if this method throws a
+ non-fatal <a href="../../../org/libjpegturbo/turbojpeg/TJException.html" title="class in org.libjpegturbo.turbojpeg"><code>TJException</code></a> (unless
+ <a href="../../../org/libjpegturbo/turbojpeg/TJ.html#FLAG_STOPONWARNING"><code>TJ.FLAG_STOPONWARNING</code></a> is specified.)</div>
<dl><dt><span class="strong">Parameters:</span></dt><dd><code>dstBuf</code> - buffer that will receive the decompressed/decoded image.
If the source image is a JPEG image, then this buffer should normally be
<code>pitch * scaledHeight</code> bytes in size, where
<code>YUVImage</code> instance. This method performs JPEG decompression
but leaves out the color conversion step, so a planar YUV image is
generated instead of an RGB or grayscale image. This method cannot be
- used to decompress JPEG source images with the CMYK or YCCK colorspace.</div>
+ used to decompress JPEG source images with the CMYK or YCCK colorspace.
+ <p>
+ NOTE: The YUV planar output image is fully recoverable if this method
+ throws a non-fatal <a href="../../../org/libjpegturbo/turbojpeg/TJException.html" title="class in org.libjpegturbo.turbojpeg"><code>TJException</code></a> (unless
+ <a href="../../../org/libjpegturbo/turbojpeg/TJ.html#FLAG_STOPONWARNING"><code>TJ.FLAG_STOPONWARNING</code></a> is specified.)</div>
<dl><dt><span class="strong">Parameters:</span></dt><dd><code>dstImage</code> - <a href="../../../org/libjpegturbo/turbojpeg/YUVImage.html" title="class in org.libjpegturbo.turbojpeg"><code>YUVImage</code></a> instance that will receive the YUV planar
image. The level of subsampling specified in this <code>YUVImage</code>
instance must match that of the JPEG image, and the width and height
throws <a href="../../../org/libjpegturbo/turbojpeg/TJException.html" title="class in org.libjpegturbo.turbojpeg">TJException</a></pre>
<div class="block">Decompress the JPEG source image or decode the YUV source image associated
with this decompressor instance and output a grayscale, RGB, or CMYK image
- to the given destination buffer.</div>
+ to the given destination buffer.
+ <p>
+ NOTE: The output image is fully recoverable if this method throws a
+ non-fatal <a href="../../../org/libjpegturbo/turbojpeg/TJException.html" title="class in org.libjpegturbo.turbojpeg"><code>TJException</code></a> (unless
+ <a href="../../../org/libjpegturbo/turbojpeg/TJ.html#FLAG_STOPONWARNING"><code>TJ.FLAG_STOPONWARNING</code></a> is specified.)</div>
<dl><dt><span class="strong">Parameters:</span></dt><dd><code>dstBuf</code> - buffer that will receive the decompressed/decoded image.
If the source image is a JPEG image, then this buffer should normally be
<code>stride * scaledHeight</code> pixels in size, where
throws <a href="../../../org/libjpegturbo/turbojpeg/TJException.html" title="class in org.libjpegturbo.turbojpeg">TJException</a></pre>
<div class="block">Decompress the JPEG source image or decode the YUV source image associated
with this decompressor instance and output a decompressed/decoded image to
- the given <code>BufferedImage</code> instance.</div>
+ the given <code>BufferedImage</code> instance.
+ <p>
+ NOTE: The output image is fully recoverable if this method throws a
+ non-fatal <a href="../../../org/libjpegturbo/turbojpeg/TJException.html" title="class in org.libjpegturbo.turbojpeg"><code>TJException</code></a> (unless
+ <a href="../../../org/libjpegturbo/turbojpeg/TJ.html#FLAG_STOPONWARNING"><code>TJ.FLAG_STOPONWARNING</code></a> is specified.)</div>
<dl><dt><span class="strong">Parameters:</span></dt><dd><code>dstImage</code> - a <code>BufferedImage</code> instance that will receive
the decompressed/decoded image. If the source image is a JPEG image, then
the width and height of the <code>BufferedImage</code> instance must match
* operation if the underlying codec throws a warning (non-fatal error). The
* default behavior is to allow the operation to complete unless a fatal
* error is encountered.
+ * <p>
+ * NOTE: due to the design of the TurboJPEG Java API, only certain methods
+ * (specifically, {@link TJDecompressor TJDecompressor.decompress*()} methods
+ * with a void return type) will complete and leave the output image in a
+ * fully recoverable state after a non-fatal error occurs.
*/
public static final int FLAG_STOPONWARNING = 8192;
/**
/**
* The error was non-fatal and recoverable, but the image may still be
* corrupt.
+ * <p>
+ * NOTE: due to the design of the TurboJPEG Java API, only certain methods
+ * (specifically, {@link TJDecompressor TJDecompressor.decompress*()} methods
+ * with a void return type) will complete and leave the output image in a
+ * fully recoverable state after a non-fatal error occurs.
*/
public static final int ERR_WARNING = 0;
/**
* Decompress the JPEG source image or decode the YUV source image associated
* with this decompressor instance and output a grayscale, RGB, or CMYK image
* to the given destination buffer.
+ * <p>
+ * NOTE: The output image is fully recoverable if this method throws a
+ * non-fatal {@link TJException} (unless
+ * {@link TJ#FLAG_STOPONWARNING TJ.FLAG_STOPONWARNING} is specified.)
*
* @param dstBuf buffer that will receive the decompressed/decoded image.
* If the source image is a JPEG image, then this buffer should normally be
* but leaves out the color conversion step, so a planar YUV image is
* generated instead of an RGB or grayscale image. This method cannot be
* used to decompress JPEG source images with the CMYK or YCCK colorspace.
+ * <p>
+ * NOTE: The YUV planar output image is fully recoverable if this method
+ * throws a non-fatal {@link TJException} (unless
+ * {@link TJ#FLAG_STOPONWARNING TJ.FLAG_STOPONWARNING} is specified.)
*
* @param dstImage {@link YUVImage} instance that will receive the YUV planar
* image. The level of subsampling specified in this <code>YUVImage</code>
* Decompress the JPEG source image or decode the YUV source image associated
* with this decompressor instance and output a grayscale, RGB, or CMYK image
* to the given destination buffer.
+ * <p>
+ * NOTE: The output image is fully recoverable if this method throws a
+ * non-fatal {@link TJException} (unless
+ * {@link TJ#FLAG_STOPONWARNING TJ.FLAG_STOPONWARNING} is specified.)
*
* @param dstBuf buffer that will receive the decompressed/decoded image.
* If the source image is a JPEG image, then this buffer should normally be
* Decompress the JPEG source image or decode the YUV source image associated
* with this decompressor instance and output a decompressed/decoded image to
* the given <code>BufferedImage</code> instance.
+ * <p>
+ * NOTE: The output image is fully recoverable if this method throws a
+ * non-fatal {@link TJException} (unless
+ * {@link TJ#FLAG_STOPONWARNING TJ.FLAG_STOPONWARNING} is specified.)
*
* @param dstImage a <code>BufferedImage</code> instance that will receive
* the decompressed/decoded image. If the source image is a JPEG image, then
#include "./turbojpeg.h"
-#define _throw(op, err) { \
+#define _throw(op, err) \
+{ \
printf("ERROR in line %d while %s:\n%s\n", __LINE__, op, err); \
- retval=-1; goto bailout;}
+ retval=-1; goto bailout; \
+}
#define _throwunix(m) _throw(m, strerror(errno))
-#define _throwtj(m) { \
- printf("%s in line %d while %s:\n%s\n", \
- tjGetErrorCode(handle)==TJERR_WARNING ? "WARNING" : "ERROR", __LINE__, \
- m, tjGetErrorStr2(handle)); \
- retval=-1; goto bailout;}
+
+char tjErrorStr[JMSG_LENGTH_MAX]="\0", tjErrorMsg[JMSG_LENGTH_MAX]="\0";
+int tjErrorLine=-1, tjErrorCode=-1;
+
+#define _throwtj(m) \
+{ \
+ int _tjErrorCode=tjGetErrorCode(handle); \
+ char *_tjErrorStr=tjGetErrorStr2(handle); \
+ \
+ if(!(flags&TJFLAG_STOPONWARNING) && _tjErrorCode==TJERR_WARNING) \
+ { \
+ if(strncmp(tjErrorStr, _tjErrorStr, JMSG_LENGTH_MAX) || \
+ strncmp(tjErrorMsg, m, JMSG_LENGTH_MAX) || \
+ tjErrorCode!=_tjErrorCode || tjErrorLine!=__LINE__) \
+ { \
+ strncpy(tjErrorStr, _tjErrorStr, JMSG_LENGTH_MAX); \
+ strncpy(tjErrorMsg, m, JMSG_LENGTH_MAX); \
+ tjErrorCode=_tjErrorCode; \
+ tjErrorLine=__LINE__; \
+ printf("WARNING in line %d while %s:\n%s\n", __LINE__, m, \
+ _tjErrorStr); \
+ } \
+ } \
+ else \
+ { \
+ printf("%s in line %d while %s:\n%s\n", \
+ _tjErrorCode==TJERR_WARNING ? "WARNING" : "ERROR", __LINE__, m, \
+ _tjErrorStr); \
+ retval=-1; goto bailout; \
+ } \
+}
+
#define _throwbmp(m) _throw(m, bmpgeterr())
int flags=TJFLAG_NOREALLOC, componly=0, decomponly=0, doyuv=0, quiet=0,