]> granicus.if.org Git - libjpeg-turbo/commitdiff
TurboJPEG: Improve error handling
authorDRC <information@libjpeg-turbo.org>
Tue, 27 Jun 2017 15:54:21 +0000 (10:54 -0500)
committerDRC <information@libjpeg-turbo.org>
Tue, 27 Jun 2017 16:03:26 +0000 (11:03 -0500)
- Provide a new C API function and TJException method that allows
  calling programs to query the severity of a compression/decompression/
  transform error.
- Provide a new flag that instructs the library to immediately stop
  compressing/decompressing/transforming if a warning is encountered.

Fixes #151

21 files changed:
ChangeLog.md
doc/html/group___turbo_j_p_e_g.html
doc/html/search/all_74.js
doc/html/search/enums_74.js
doc/html/search/enumvalues_74.js
doc/html/search/functions_74.js
java/TJBench.java
java/doc/constant-values.html
java/doc/index-all.html
java/doc/org/libjpegturbo/turbojpeg/TJ.html
java/doc/org/libjpegturbo/turbojpeg/TJException.html
java/doc/script.js [new file with mode: 0644]
java/doc/serialized-form.html
java/org/libjpegturbo/turbojpeg/TJ.java
java/org/libjpegturbo/turbojpeg/TJException.java
tjbench.c
turbojpeg-jni.c
turbojpeg-mapfile
turbojpeg-mapfile.jni
turbojpeg.c
turbojpeg.h

index f96d5fc7ae3cd9be3f9b70b6836cce7ffb0e47d3..731500b395dc78828a3106b60f2d96e7276fe2ad 100644 (file)
@@ -48,6 +48,17 @@ in a thread-safe manner.  Retrieving error messages from global functions, such
 as `tjInitCompress()` or `tjBufSize()`, is still thread-unsafe, but since those
 functions will only throw errors if passed an invalid argument or if a memory
 allocation failure occurs, thread safety is not as much of a concern.
+     - Introduced a new function (`tjGetErrorCode()`) in the TurboJPEG C API
+and a new method (`TJException.getErrorCode()`) in the TurboJPEG Java API that
+can be used to determine the severity of the last
+compression/decompression/transform error.  This allows applications to
+choose whether to ignore warnings (non-fatal errors) from the underlying
+libjpeg API or to treat them as fatal.
+     - Introduced a new flag (`TJFLAG_STOPONWARNING` in the TurboJPEG C API and
+`TJ.FLAG_STOPONWARNING` in the TurboJPEG Java API) that causes the library to
+immediately halt a compression/decompression/transform operation if it
+encounters a warning from the underlying libjpeg API (the default behavior is
+to allow the operation to complete unless a fatal error is encountered.)
 
 
 1.5.2
index fb5da8ca39569686bc4187d72d8a9867f166ce35..49c54ca4b4f81c4848ff8a9c9f5a5e8d43c14c64 100644 (file)
@@ -128,6 +128,12 @@ Macros</h2></td></tr>
 <tr class="memitem:gacb233cfd722d66d1ccbf48a7de81f0e0"><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___turbo_j_p_e_g.html#gacb233cfd722d66d1ccbf48a7de81f0e0">TJFLAG_ACCURATEDCT</a></td></tr>
 <tr class="memdesc:gacb233cfd722d66d1ccbf48a7de81f0e0"><td class="mdescLeft">&#160;</td><td class="mdescRight">Use the most accurate DCT/IDCT algorithm available in the underlying codec.  <a href="#gacb233cfd722d66d1ccbf48a7de81f0e0">More...</a><br/></td></tr>
 <tr class="separator:gacb233cfd722d66d1ccbf48a7de81f0e0"><td class="memSeparator" colspan="2">&#160;</td></tr>
+<tr class="memitem:ga519cfa4ef6c18d9e5b455fdf59306a3a"><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___turbo_j_p_e_g.html#ga519cfa4ef6c18d9e5b455fdf59306a3a">TJFLAG_STOPONWARNING</a></td></tr>
+<tr class="memdesc:ga519cfa4ef6c18d9e5b455fdf59306a3a"><td class="mdescLeft">&#160;</td><td class="mdescRight">Immediately discontinue the current compression/decompression/transform operation if the underlying codec throws a warning (non-fatal error).  <a href="#ga519cfa4ef6c18d9e5b455fdf59306a3a">More...</a><br/></td></tr>
+<tr class="separator:ga519cfa4ef6c18d9e5b455fdf59306a3a"><td class="memSeparator" colspan="2">&#160;</td></tr>
+<tr class="memitem:ga79bde1b4a3e2351e00887e47781b966e"><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___turbo_j_p_e_g.html#ga79bde1b4a3e2351e00887e47781b966e">TJ_NUMERR</a></td></tr>
+<tr class="memdesc:ga79bde1b4a3e2351e00887e47781b966e"><td class="mdescLeft">&#160;</td><td class="mdescRight">The number of error codes.  <a href="#ga79bde1b4a3e2351e00887e47781b966e">More...</a><br/></td></tr>
+<tr class="separator:ga79bde1b4a3e2351e00887e47781b966e"><td class="memSeparator" colspan="2">&#160;</td></tr>
 <tr class="memitem:ga0f6dbd18adf38b7d46ac547f0f4d562c"><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___turbo_j_p_e_g.html#ga0f6dbd18adf38b7d46ac547f0f4d562c">TJ_NUMXOP</a></td></tr>
 <tr class="memdesc:ga0f6dbd18adf38b7d46ac547f0f4d562c"><td class="mdescLeft">&#160;</td><td class="mdescRight">The number of transform operations.  <a href="#ga0f6dbd18adf38b7d46ac547f0f4d562c">More...</a><br/></td></tr>
 <tr class="separator:ga0f6dbd18adf38b7d46ac547f0f4d562c"><td class="memSeparator" colspan="2">&#160;</td></tr>
@@ -206,6 +212,11 @@ Enumerations</h2></td></tr>
  }</td></tr>
 <tr class="memdesc:ga4f83ad3368e0e29d1957be0efa7c3720"><td class="mdescLeft">&#160;</td><td class="mdescRight">JPEG colorspaces.  <a href="group___turbo_j_p_e_g.html#ga4f83ad3368e0e29d1957be0efa7c3720">More...</a><br/></td></tr>
 <tr class="separator:ga4f83ad3368e0e29d1957be0efa7c3720"><td class="memSeparator" colspan="2">&#160;</td></tr>
+<tr class="memitem:gafbc17cfa57d0d5d11fea35ac025950fe"><td class="memItemLeft" align="right" valign="top">enum &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___turbo_j_p_e_g.html#gafbc17cfa57d0d5d11fea35ac025950fe">TJERR</a> { <a class="el" href="group___turbo_j_p_e_g.html#ggafbc17cfa57d0d5d11fea35ac025950fea342dd6e2aedb47bb257b4e7568329b59">TJERR_WARNING</a>, 
+<a class="el" href="group___turbo_j_p_e_g.html#ggafbc17cfa57d0d5d11fea35ac025950feafc9cceeada13122b09e4851e3788039a">TJERR_FATAL</a>
+ }</td></tr>
+<tr class="memdesc:gafbc17cfa57d0d5d11fea35ac025950fe"><td class="mdescLeft">&#160;</td><td class="mdescRight">Error codes.  <a href="group___turbo_j_p_e_g.html#gafbc17cfa57d0d5d11fea35ac025950fe">More...</a><br/></td></tr>
+<tr class="separator:gafbc17cfa57d0d5d11fea35ac025950fe"><td class="memSeparator" colspan="2">&#160;</td></tr>
 <tr class="memitem:ga2de531af4e7e6c4f124908376b354866"><td class="memItemLeft" align="right" valign="top">enum &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___turbo_j_p_e_g.html#ga2de531af4e7e6c4f124908376b354866">TJXOP</a> { <br/>
 &#160;&#160;<a class="el" href="group___turbo_j_p_e_g.html#gga2de531af4e7e6c4f124908376b354866aad88c0366cd3f7d0eac9d7a3fa1c2c27">TJXOP_NONE</a>, 
 <a class="el" href="group___turbo_j_p_e_g.html#gga2de531af4e7e6c4f124908376b354866aa0df69776caa30f0fa28e26332d311ce">TJXOP_HFLIP</a>, 
@@ -298,6 +309,9 @@ Functions</h2></td></tr>
 <tr class="memitem:ga94a235bd4f1088f61ad87b4eadb64c9c"><td class="memItemLeft" align="right" valign="top">DLLEXPORT char *DLLCALL&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___turbo_j_p_e_g.html#ga94a235bd4f1088f61ad87b4eadb64c9c">tjGetErrorStr2</a> (<a class="el" href="group___turbo_j_p_e_g.html#ga758d2634ecb4949de7815cba621f5763">tjhandle</a> handle)</td></tr>
 <tr class="memdesc:ga94a235bd4f1088f61ad87b4eadb64c9c"><td class="mdescLeft">&#160;</td><td class="mdescRight">Returns a descriptive error message explaining why the last command failed.  <a href="#ga94a235bd4f1088f61ad87b4eadb64c9c">More...</a><br/></td></tr>
 <tr class="separator:ga94a235bd4f1088f61ad87b4eadb64c9c"><td class="memSeparator" colspan="2">&#160;</td></tr>
+<tr class="memitem:ga0be00a62bd1be897f170fa1fed5fb4cb"><td class="memItemLeft" align="right" valign="top">DLLEXPORT int DLLCALL&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group___turbo_j_p_e_g.html#ga0be00a62bd1be897f170fa1fed5fb4cb">tjGetErrorCode</a> (<a class="el" href="group___turbo_j_p_e_g.html#ga758d2634ecb4949de7815cba621f5763">tjhandle</a> handle)</td></tr>
+<tr class="memdesc:ga0be00a62bd1be897f170fa1fed5fb4cb"><td class="mdescLeft">&#160;</td><td class="mdescRight">Returns a code indicating the severity of the last error.  <a href="#ga0be00a62bd1be897f170fa1fed5fb4cb">More...</a><br/></td></tr>
+<tr class="separator:ga0be00a62bd1be897f170fa1fed5fb4cb"><td class="memSeparator" colspan="2">&#160;</td></tr>
 </table><table class="memberdecls">
 <tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="var-members"></a>
 Variables</h2></td></tr>
@@ -341,6 +355,20 @@ Variables</h2></td></tr>
 
 <p>The number of JPEG colorspaces. </p>
 
+</div>
+</div>
+<a class="anchor" id="ga79bde1b4a3e2351e00887e47781b966e"></a>
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">#define TJ_NUMERR</td>
+        </tr>
+      </table>
+</div><div class="memdoc">
+
+<p>The number of error codes. </p>
+
 </div>
 </div>
 <a class="anchor" id="ga7010a4402f54a45ba822ad8675a4655e"></a>
@@ -457,6 +485,21 @@ Variables</h2></td></tr>
 <p>Disable buffer (re)allocation. </p>
 <p>If passed to <a class="el" href="group___turbo_j_p_e_g.html#gaf38f2ed44bdc88e730e08b632fa6e88e" title="Compress an RGB, grayscale, or CMYK image into a JPEG image.">tjCompress2()</a> or <a class="el" href="group___turbo_j_p_e_g.html#gad02cd42b69f193a0623a9c801788df3a" title="Losslessly transform a JPEG image into another JPEG image.">tjTransform()</a>, this flag will cause those functions to generate an error if the JPEG image buffer is invalid or too small rather than attempting to allocate or reallocate that buffer. This reproduces the behavior of earlier versions of TurboJPEG. </p>
 
+</div>
+</div>
+<a class="anchor" id="ga519cfa4ef6c18d9e5b455fdf59306a3a"></a>
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">#define TJFLAG_STOPONWARNING</td>
+        </tr>
+      </table>
+</div><div class="memdoc">
+
+<p>Immediately discontinue the current compression/decompression/transform operation if the underlying codec throws a warning (non-fatal error). </p>
+<p>The default behavior is to allow the operation to complete unless a fatal error is encountered. </p>
+
 </div>
 </div>
 <a class="anchor" id="ga0aba955473315e405295d978f0c16511"></a>
@@ -642,6 +685,28 @@ Variables</h2></td></tr>
 </td></tr>
 </table>
 
+</div>
+</div>
+<a class="anchor" id="gafbc17cfa57d0d5d11fea35ac025950fe"></a>
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">enum <a class="el" href="group___turbo_j_p_e_g.html#gafbc17cfa57d0d5d11fea35ac025950fe">TJERR</a></td>
+        </tr>
+      </table>
+</div><div class="memdoc">
+
+<p>Error codes. </p>
+<table class="fieldtable">
+<tr><th colspan="2">Enumerator</th></tr><tr><td class="fieldname"><em><a class="anchor" id="ggafbc17cfa57d0d5d11fea35ac025950fea342dd6e2aedb47bb257b4e7568329b59"></a>TJERR_WARNING</em>&nbsp;</td><td class="fielddoc">
+<p>The error was non-fatal and recoverable, but the image may still be corrupt. </p>
+</td></tr>
+<tr><td class="fieldname"><em><a class="anchor" id="ggafbc17cfa57d0d5d11fea35ac025950feafc9cceeada13122b09e4851e3788039a"></a>TJERR_FATAL</em>&nbsp;</td><td class="fielddoc">
+<p>The error was fatal and non-recoverable. </p>
+</td></tr>
+</table>
+
 </div>
 </div>
 <a class="anchor" id="gac916144e26c3817ac514e64ae5d12e2a"></a>
@@ -1018,7 +1083,7 @@ If you choose option 1, <code>*jpegSize</code> should be set to the size of your
   </table>
   </dd>
 </dl>
-<dl class="section return"><dt>Returns</dt><dd>0 if successful, or -1 if an error occurred (see <a class="el" href="group___turbo_j_p_e_g.html#ga94a235bd4f1088f61ad87b4eadb64c9c" title="Returns a descriptive error message explaining why the last command failed.">tjGetErrorStr2()</a>.) </dd></dl>
+<dl class="section return"><dt>Returns</dt><dd>0 if successful, or -1 if an error occurred (see <a class="el" href="group___turbo_j_p_e_g.html#ga94a235bd4f1088f61ad87b4eadb64c9c" title="Returns a descriptive error message explaining why the last command failed.">tjGetErrorStr2()</a> and <a class="el" href="group___turbo_j_p_e_g.html#ga0be00a62bd1be897f170fa1fed5fb4cb" title="Returns a code indicating the severity of the last error.">tjGetErrorCode()</a>.) </dd></dl>
 
 </div>
 </div>
@@ -1115,7 +1180,7 @@ If you choose option 1, <code>*jpegSize</code> should be set to the size of your
   </table>
   </dd>
 </dl>
-<dl class="section return"><dt>Returns</dt><dd>0 if successful, or -1 if an error occurred (see <a class="el" href="group___turbo_j_p_e_g.html#ga94a235bd4f1088f61ad87b4eadb64c9c" title="Returns a descriptive error message explaining why the last command failed.">tjGetErrorStr2()</a>.) </dd></dl>
+<dl class="section return"><dt>Returns</dt><dd>0 if successful, or -1 if an error occurred (see <a class="el" href="group___turbo_j_p_e_g.html#ga94a235bd4f1088f61ad87b4eadb64c9c" title="Returns a descriptive error message explaining why the last command failed.">tjGetErrorStr2()</a> and <a class="el" href="group___turbo_j_p_e_g.html#ga0be00a62bd1be897f170fa1fed5fb4cb" title="Returns a code indicating the severity of the last error.">tjGetErrorCode()</a>.) </dd></dl>
 
 </div>
 </div>
@@ -1212,7 +1277,7 @@ If you choose option 1, <code>*jpegSize</code> should be set to the size of your
   </table>
   </dd>
 </dl>
-<dl class="section return"><dt>Returns</dt><dd>0 if successful, or -1 if an error occurred (see <a class="el" href="group___turbo_j_p_e_g.html#ga94a235bd4f1088f61ad87b4eadb64c9c" title="Returns a descriptive error message explaining why the last command failed.">tjGetErrorStr2()</a>.) </dd></dl>
+<dl class="section return"><dt>Returns</dt><dd>0 if successful, or -1 if an error occurred (see <a class="el" href="group___turbo_j_p_e_g.html#ga94a235bd4f1088f61ad87b4eadb64c9c" title="Returns a descriptive error message explaining why the last command failed.">tjGetErrorStr2()</a> and <a class="el" href="group___turbo_j_p_e_g.html#ga0be00a62bd1be897f170fa1fed5fb4cb" title="Returns a code indicating the severity of the last error.">tjGetErrorCode()</a>.) </dd></dl>
 
 </div>
 </div>
@@ -1305,7 +1370,7 @@ If you choose option 1, <code>*jpegSize</code> should be set to the size of your
   </table>
   </dd>
 </dl>
-<dl class="section return"><dt>Returns</dt><dd>0 if successful, or -1 if an error occurred (see <a class="el" href="group___turbo_j_p_e_g.html#ga94a235bd4f1088f61ad87b4eadb64c9c" title="Returns a descriptive error message explaining why the last command failed.">tjGetErrorStr2()</a>.) </dd></dl>
+<dl class="section return"><dt>Returns</dt><dd>0 if successful, or -1 if an error occurred (see <a class="el" href="group___turbo_j_p_e_g.html#ga94a235bd4f1088f61ad87b4eadb64c9c" title="Returns a descriptive error message explaining why the last command failed.">tjGetErrorStr2()</a> and <a class="el" href="group___turbo_j_p_e_g.html#ga0be00a62bd1be897f170fa1fed5fb4cb" title="Returns a code indicating the severity of the last error.">tjGetErrorCode()</a>.) </dd></dl>
 
 </div>
 </div>
@@ -1398,7 +1463,7 @@ If you choose option 1, <code>*jpegSize</code> should be set to the size of your
   </table>
   </dd>
 </dl>
-<dl class="section return"><dt>Returns</dt><dd>0 if successful, or -1 if an error occurred (see <a class="el" href="group___turbo_j_p_e_g.html#ga94a235bd4f1088f61ad87b4eadb64c9c" title="Returns a descriptive error message explaining why the last command failed.">tjGetErrorStr2()</a>.) </dd></dl>
+<dl class="section return"><dt>Returns</dt><dd>0 if successful, or -1 if an error occurred (see <a class="el" href="group___turbo_j_p_e_g.html#ga94a235bd4f1088f61ad87b4eadb64c9c" title="Returns a descriptive error message explaining why the last command failed.">tjGetErrorStr2()</a> and <a class="el" href="group___turbo_j_p_e_g.html#ga0be00a62bd1be897f170fa1fed5fb4cb" title="Returns a code indicating the severity of the last error.">tjGetErrorCode()</a>.) </dd></dl>
 
 </div>
 </div>
@@ -1483,7 +1548,7 @@ If you choose option 1, <code>*jpegSize</code> should be set to the size of your
   </table>
   </dd>
 </dl>
-<dl class="section return"><dt>Returns</dt><dd>0 if successful, or -1 if an error occurred (see <a class="el" href="group___turbo_j_p_e_g.html#ga94a235bd4f1088f61ad87b4eadb64c9c" title="Returns a descriptive error message explaining why the last command failed.">tjGetErrorStr2()</a>.) </dd></dl>
+<dl class="section return"><dt>Returns</dt><dd>0 if successful, or -1 if an error occurred (see <a class="el" href="group___turbo_j_p_e_g.html#ga94a235bd4f1088f61ad87b4eadb64c9c" title="Returns a descriptive error message explaining why the last command failed.">tjGetErrorStr2()</a> and <a class="el" href="group___turbo_j_p_e_g.html#ga0be00a62bd1be897f170fa1fed5fb4cb" title="Returns a code indicating the severity of the last error.">tjGetErrorCode()</a>.) </dd></dl>
 
 </div>
 </div>
@@ -1554,7 +1619,7 @@ If you choose option 1, <code>*jpegSize</code> should be set to the size of your
   </table>
   </dd>
 </dl>
-<dl class="section return"><dt>Returns</dt><dd>0 if successful, or -1 if an error occurred (see <a class="el" href="group___turbo_j_p_e_g.html#ga94a235bd4f1088f61ad87b4eadb64c9c" title="Returns a descriptive error message explaining why the last command failed.">tjGetErrorStr2()</a>.) </dd></dl>
+<dl class="section return"><dt>Returns</dt><dd>0 if successful, or -1 if an error occurred (see <a class="el" href="group___turbo_j_p_e_g.html#ga94a235bd4f1088f61ad87b4eadb64c9c" title="Returns a descriptive error message explaining why the last command failed.">tjGetErrorStr2()</a> and <a class="el" href="group___turbo_j_p_e_g.html#ga0be00a62bd1be897f170fa1fed5fb4cb" title="Returns a code indicating the severity of the last error.">tjGetErrorCode()</a>.) </dd></dl>
 
 </div>
 </div>
@@ -1633,7 +1698,7 @@ If you choose option 1, <code>*jpegSize</code> should be set to the size of your
   </table>
   </dd>
 </dl>
-<dl class="section return"><dt>Returns</dt><dd>0 if successful, or -1 if an error occurred (see <a class="el" href="group___turbo_j_p_e_g.html#ga94a235bd4f1088f61ad87b4eadb64c9c" title="Returns a descriptive error message explaining why the last command failed.">tjGetErrorStr2()</a>.) </dd></dl>
+<dl class="section return"><dt>Returns</dt><dd>0 if successful, or -1 if an error occurred (see <a class="el" href="group___turbo_j_p_e_g.html#ga94a235bd4f1088f61ad87b4eadb64c9c" title="Returns a descriptive error message explaining why the last command failed.">tjGetErrorStr2()</a> and <a class="el" href="group___turbo_j_p_e_g.html#ga0be00a62bd1be897f170fa1fed5fb4cb" title="Returns a code indicating the severity of the last error.">tjGetErrorCode()</a>.) </dd></dl>
 
 </div>
 </div>
@@ -1712,7 +1777,7 @@ If you choose option 1, <code>*jpegSize</code> should be set to the size of your
   </table>
   </dd>
 </dl>
-<dl class="section return"><dt>Returns</dt><dd>0 if successful, or -1 if an error occurred (see <a class="el" href="group___turbo_j_p_e_g.html#ga94a235bd4f1088f61ad87b4eadb64c9c" title="Returns a descriptive error message explaining why the last command failed.">tjGetErrorStr2()</a>.) </dd></dl>
+<dl class="section return"><dt>Returns</dt><dd>0 if successful, or -1 if an error occurred (see <a class="el" href="group___turbo_j_p_e_g.html#ga94a235bd4f1088f61ad87b4eadb64c9c" title="Returns a descriptive error message explaining why the last command failed.">tjGetErrorStr2()</a> and <a class="el" href="group___turbo_j_p_e_g.html#ga0be00a62bd1be897f170fa1fed5fb4cb" title="Returns a code indicating the severity of the last error.">tjGetErrorCode()</a>.) </dd></dl>
 
 </div>
 </div>
@@ -1830,7 +1895,7 @@ If you choose option 1, <code>*jpegSize</code> should be set to the size of your
   </table>
   </dd>
 </dl>
-<dl class="section return"><dt>Returns</dt><dd>0 if successful, or -1 if an error occurred (see <a class="el" href="group___turbo_j_p_e_g.html#ga94a235bd4f1088f61ad87b4eadb64c9c" title="Returns a descriptive error message explaining why the last command failed.">tjGetErrorStr2()</a>.) </dd></dl>
+<dl class="section return"><dt>Returns</dt><dd>0 if successful, or -1 if an error occurred (see <a class="el" href="group___turbo_j_p_e_g.html#ga94a235bd4f1088f61ad87b4eadb64c9c" title="Returns a descriptive error message explaining why the last command failed.">tjGetErrorStr2()</a> and <a class="el" href="group___turbo_j_p_e_g.html#ga0be00a62bd1be897f170fa1fed5fb4cb" title="Returns a code indicating the severity of the last error.">tjGetErrorCode()</a>.) </dd></dl>
 
 </div>
 </div>
@@ -1923,7 +1988,7 @@ If you choose option 1, <code>*jpegSize</code> should be set to the size of your
   </table>
   </dd>
 </dl>
-<dl class="section return"><dt>Returns</dt><dd>0 if successful, or -1 if an error occurred (see <a class="el" href="group___turbo_j_p_e_g.html#ga94a235bd4f1088f61ad87b4eadb64c9c" title="Returns a descriptive error message explaining why the last command failed.">tjGetErrorStr2()</a>.) </dd></dl>
+<dl class="section return"><dt>Returns</dt><dd>0 if successful, or -1 if an error occurred (see <a class="el" href="group___turbo_j_p_e_g.html#ga94a235bd4f1088f61ad87b4eadb64c9c" title="Returns a descriptive error message explaining why the last command failed.">tjGetErrorStr2()</a> and <a class="el" href="group___turbo_j_p_e_g.html#ga0be00a62bd1be897f170fa1fed5fb4cb" title="Returns a code indicating the severity of the last error.">tjGetErrorCode()</a>.) </dd></dl>
 
 </div>
 </div>
@@ -1951,6 +2016,32 @@ If you choose option 1, <code>*jpegSize</code> should be set to the size of your
 </dl>
 <dl class="section see"><dt>See Also</dt><dd><a class="el" href="group___turbo_j_p_e_g.html#ga5c9234bda6d993cdaffdd89bf81a00ff" title="Allocate an image buffer for use with TurboJPEG.">tjAlloc()</a> </dd></dl>
 
+</div>
+</div>
+<a class="anchor" id="ga0be00a62bd1be897f170fa1fed5fb4cb"></a>
+<div class="memitem">
+<div class="memproto">
+      <table class="memname">
+        <tr>
+          <td class="memname">DLLEXPORT int DLLCALL tjGetErrorCode </td>
+          <td>(</td>
+          <td class="paramtype"><a class="el" href="group___turbo_j_p_e_g.html#ga758d2634ecb4949de7815cba621f5763">tjhandle</a>&#160;</td>
+          <td class="paramname"><em>handle</em></td><td>)</td>
+          <td></td>
+        </tr>
+      </table>
+</div><div class="memdoc">
+
+<p>Returns a code indicating the severity of the last error. </p>
+<p>See <a class="el" href="group___turbo_j_p_e_g.html#gafbc17cfa57d0d5d11fea35ac025950fe">Error codes</a>.</p>
+<dl class="params"><dt>Parameters</dt><dd>
+  <table class="params">
+    <tr><td class="paramname">handle</td><td>a handle to a TurboJPEG compressor, decompressor or transformer instance</td></tr>
+  </table>
+  </dd>
+</dl>
+<dl class="section return"><dt>Returns</dt><dd>a code indicating the severity of the last error. See <a class="el" href="group___turbo_j_p_e_g.html#gafbc17cfa57d0d5d11fea35ac025950fe">Error codes</a>. </dd></dl>
+
 </div>
 </div>
 <a class="anchor" id="ga94a235bd4f1088f61ad87b4eadb64c9c"></a>
@@ -2285,7 +2376,7 @@ If you choose option 1, <code>dstSizes[i]</code> should be set to the size of yo
   </table>
   </dd>
 </dl>
-<dl class="section return"><dt>Returns</dt><dd>0 if successful, or -1 if an error occurred (see <a class="el" href="group___turbo_j_p_e_g.html#ga94a235bd4f1088f61ad87b4eadb64c9c" title="Returns a descriptive error message explaining why the last command failed.">tjGetErrorStr2()</a>.) </dd></dl>
+<dl class="section return"><dt>Returns</dt><dd>0 if successful, or -1 if an error occurred (see <a class="el" href="group___turbo_j_p_e_g.html#ga94a235bd4f1088f61ad87b4eadb64c9c" title="Returns a descriptive error message explaining why the last command failed.">tjGetErrorStr2()</a> and <a class="el" href="group___turbo_j_p_e_g.html#ga0be00a62bd1be897f170fa1fed5fb4cb" title="Returns a code indicating the severity of the last error.">tjGetErrorCode()</a>.) </dd></dl>
 
 </div>
 </div>
index eec0aee3e7e21804e474541d94bdd7a25f542155..b18cdcd0e951124bbb996bfbe40d933477785a48 100644 (file)
@@ -1,6 +1,7 @@
 var searchData=
 [
   ['tj_5fnumcs',['TJ_NUMCS',['../group___turbo_j_p_e_g.html#ga39f57a6fb02d9cf32e7b6890099b5a71',1,'turbojpeg.h']]],
+  ['tj_5fnumerr',['TJ_NUMERR',['../group___turbo_j_p_e_g.html#ga79bde1b4a3e2351e00887e47781b966e',1,'turbojpeg.h']]],
   ['tj_5fnumpf',['TJ_NUMPF',['../group___turbo_j_p_e_g.html#ga7010a4402f54a45ba822ad8675a4655e',1,'turbojpeg.h']]],
   ['tj_5fnumsamp',['TJ_NUMSAMP',['../group___turbo_j_p_e_g.html#ga5ef3d169162ce77ce348e292a0b7477c',1,'turbojpeg.h']]],
   ['tj_5fnumxop',['TJ_NUMXOP',['../group___turbo_j_p_e_g.html#ga0f6dbd18adf38b7d46ac547f0f4d562c',1,'turbojpeg.h']]],
@@ -26,12 +27,17 @@ var searchData=
   ['tjdestroy',['tjDestroy',['../group___turbo_j_p_e_g.html#ga674adee917b95ad4a896f1ba39e12540',1,'turbojpeg.h']]],
   ['tjencodeyuv3',['tjEncodeYUV3',['../group___turbo_j_p_e_g.html#gaabe05acd734990053ad1294b5ef239aa',1,'turbojpeg.h']]],
   ['tjencodeyuvplanes',['tjEncodeYUVPlanes',['../group___turbo_j_p_e_g.html#ga8a65ed3bd12df57c219d46afbc9008f1',1,'turbojpeg.h']]],
+  ['tjerr',['TJERR',['../group___turbo_j_p_e_g.html#gafbc17cfa57d0d5d11fea35ac025950fe',1,'turbojpeg.h']]],
+  ['tjerr_5ffatal',['TJERR_FATAL',['../group___turbo_j_p_e_g.html#ggafbc17cfa57d0d5d11fea35ac025950feafc9cceeada13122b09e4851e3788039a',1,'turbojpeg.h']]],
+  ['tjerr_5fwarning',['TJERR_WARNING',['../group___turbo_j_p_e_g.html#ggafbc17cfa57d0d5d11fea35ac025950fea342dd6e2aedb47bb257b4e7568329b59',1,'turbojpeg.h']]],
   ['tjflag_5faccuratedct',['TJFLAG_ACCURATEDCT',['../group___turbo_j_p_e_g.html#gacb233cfd722d66d1ccbf48a7de81f0e0',1,'turbojpeg.h']]],
   ['tjflag_5fbottomup',['TJFLAG_BOTTOMUP',['../group___turbo_j_p_e_g.html#ga72ecf4ebe6eb702d3c6f5ca27455e1ec',1,'turbojpeg.h']]],
   ['tjflag_5ffastdct',['TJFLAG_FASTDCT',['../group___turbo_j_p_e_g.html#gaabce235db80d3f698b27f36cbd453da2',1,'turbojpeg.h']]],
   ['tjflag_5ffastupsample',['TJFLAG_FASTUPSAMPLE',['../group___turbo_j_p_e_g.html#ga4ee4506c81177a06f77e2504a22efd2d',1,'turbojpeg.h']]],
   ['tjflag_5fnorealloc',['TJFLAG_NOREALLOC',['../group___turbo_j_p_e_g.html#ga8808d403c68b62aaa58a4c1e58e98963',1,'turbojpeg.h']]],
+  ['tjflag_5fstoponwarning',['TJFLAG_STOPONWARNING',['../group___turbo_j_p_e_g.html#ga519cfa4ef6c18d9e5b455fdf59306a3a',1,'turbojpeg.h']]],
   ['tjfree',['tjFree',['../group___turbo_j_p_e_g.html#ga8c4a1231dc06a450514c835f6471f137',1,'turbojpeg.h']]],
+  ['tjgeterrorcode',['tjGetErrorCode',['../group___turbo_j_p_e_g.html#ga0be00a62bd1be897f170fa1fed5fb4cb',1,'turbojpeg.h']]],
   ['tjgeterrorstr2',['tjGetErrorStr2',['../group___turbo_j_p_e_g.html#ga94a235bd4f1088f61ad87b4eadb64c9c',1,'turbojpeg.h']]],
   ['tjgetscalingfactors',['tjGetScalingFactors',['../group___turbo_j_p_e_g.html#ga6449044b9af402999ccf52f401333be8',1,'turbojpeg.h']]],
   ['tjgreenoffset',['tjGreenOffset',['../group___turbo_j_p_e_g.html#ga82d6e35da441112a411da41923c0ba2f',1,'turbojpeg.h']]],
@@ -70,7 +76,7 @@ var searchData=
   ['tjsamp_5fgray',['TJSAMP_GRAY',['../group___turbo_j_p_e_g.html#gga1d047060ea80bb9820d540bb928e9074a3f1c9504842ddc7a48d0f690754b6248',1,'turbojpeg.h']]],
   ['tjscaled',['TJSCALED',['../group___turbo_j_p_e_g.html#ga84878bb65404204743aa18cac02781df',1,'turbojpeg.h']]],
   ['tjscalingfactor',['tjscalingfactor',['../structtjscalingfactor.html',1,'']]],
-  ['tjtransform',['tjtransform',['../structtjtransform.html',1,'tjtransform'],['../group___turbo_j_p_e_g.html#gad02cd42b69f193a0623a9c801788df3a',1,'tjTransform(tjhandle handle, const unsigned char *jpegBuf, unsigned long jpegSize, int n, unsigned char **dstBufs, unsigned long *dstSizes, tjtransform *transforms, int flags):&#160;turbojpeg.h'],['../group___turbo_j_p_e_g.html#gaa29f3189c41be12ec5dee7caec318a31',1,'tjtransform():&#160;turbojpeg.h']]],
+  ['tjtransform',['tjtransform',['../structtjtransform.html',1,'tjtransform'],['../group___turbo_j_p_e_g.html#gaa29f3189c41be12ec5dee7caec318a31',1,'tjtransform():&#160;turbojpeg.h'],['../group___turbo_j_p_e_g.html#gad02cd42b69f193a0623a9c801788df3a',1,'tjTransform(tjhandle handle, const unsigned char *jpegBuf, unsigned long jpegSize, int n, unsigned char **dstBufs, unsigned long *dstSizes, tjtransform *transforms, int flags):&#160;turbojpeg.h']]],
   ['tjxop',['TJXOP',['../group___turbo_j_p_e_g.html#ga2de531af4e7e6c4f124908376b354866',1,'turbojpeg.h']]],
   ['tjxop_5fhflip',['TJXOP_HFLIP',['../group___turbo_j_p_e_g.html#gga2de531af4e7e6c4f124908376b354866aa0df69776caa30f0fa28e26332d311ce',1,'turbojpeg.h']]],
   ['tjxop_5fnone',['TJXOP_NONE',['../group___turbo_j_p_e_g.html#gga2de531af4e7e6c4f124908376b354866aad88c0366cd3f7d0eac9d7a3fa1c2c27',1,'turbojpeg.h']]],
index 276aa24165f0ecf92db381501d4be6f182095eca..19c20cfdd2a91769a2524d80e95f00c52aaf5c05 100644 (file)
@@ -1,6 +1,7 @@
 var searchData=
 [
   ['tjcs',['TJCS',['../group___turbo_j_p_e_g.html#ga4f83ad3368e0e29d1957be0efa7c3720',1,'turbojpeg.h']]],
+  ['tjerr',['TJERR',['../group___turbo_j_p_e_g.html#gafbc17cfa57d0d5d11fea35ac025950fe',1,'turbojpeg.h']]],
   ['tjpf',['TJPF',['../group___turbo_j_p_e_g.html#gac916144e26c3817ac514e64ae5d12e2a',1,'turbojpeg.h']]],
   ['tjsamp',['TJSAMP',['../group___turbo_j_p_e_g.html#ga1d047060ea80bb9820d540bb928e9074',1,'turbojpeg.h']]],
   ['tjxop',['TJXOP',['../group___turbo_j_p_e_g.html#ga2de531af4e7e6c4f124908376b354866',1,'turbojpeg.h']]]
index 7dc2f8dc939d33e4970700bb631d505e2691af9f..799f9acd2c5afab2ebd030e809f8fa6862d9bb19 100644 (file)
@@ -5,6 +5,8 @@ var searchData=
   ['tjcs_5frgb',['TJCS_RGB',['../group___turbo_j_p_e_g.html#gga4f83ad3368e0e29d1957be0efa7c3720a677cb7ccb85c4038ac41964a2e09e555',1,'turbojpeg.h']]],
   ['tjcs_5fycbcr',['TJCS_YCbCr',['../group___turbo_j_p_e_g.html#gga4f83ad3368e0e29d1957be0efa7c3720a7389b8f65bb387ffedce3efd0d78ec75',1,'turbojpeg.h']]],
   ['tjcs_5fycck',['TJCS_YCCK',['../group___turbo_j_p_e_g.html#gga4f83ad3368e0e29d1957be0efa7c3720a53839e0fe867b76b58d16b0a1a7c598e',1,'turbojpeg.h']]],
+  ['tjerr_5ffatal',['TJERR_FATAL',['../group___turbo_j_p_e_g.html#ggafbc17cfa57d0d5d11fea35ac025950feafc9cceeada13122b09e4851e3788039a',1,'turbojpeg.h']]],
+  ['tjerr_5fwarning',['TJERR_WARNING',['../group___turbo_j_p_e_g.html#ggafbc17cfa57d0d5d11fea35ac025950fea342dd6e2aedb47bb257b4e7568329b59',1,'turbojpeg.h']]],
   ['tjpf_5fabgr',['TJPF_ABGR',['../group___turbo_j_p_e_g.html#ggac916144e26c3817ac514e64ae5d12e2aa1ba1a7f1631dbeaa49a0a85fc4a40081',1,'turbojpeg.h']]],
   ['tjpf_5fargb',['TJPF_ARGB',['../group___turbo_j_p_e_g.html#ggac916144e26c3817ac514e64ae5d12e2aae8f846ed9d9de99b6e1dfe448848765c',1,'turbojpeg.h']]],
   ['tjpf_5fbgr',['TJPF_BGR',['../group___turbo_j_p_e_g.html#ggac916144e26c3817ac514e64ae5d12e2aab10624437fb8ef495a0b153e65749839',1,'turbojpeg.h']]],
index f284a2c0202a0b3cec7fa67361be2b551ace865c..d2164bb5fc6e358e538b7837e41645bba400073c 100644 (file)
@@ -16,6 +16,7 @@ var searchData=
   ['tjencodeyuv3',['tjEncodeYUV3',['../group___turbo_j_p_e_g.html#gaabe05acd734990053ad1294b5ef239aa',1,'turbojpeg.h']]],
   ['tjencodeyuvplanes',['tjEncodeYUVPlanes',['../group___turbo_j_p_e_g.html#ga8a65ed3bd12df57c219d46afbc9008f1',1,'turbojpeg.h']]],
   ['tjfree',['tjFree',['../group___turbo_j_p_e_g.html#ga8c4a1231dc06a450514c835f6471f137',1,'turbojpeg.h']]],
+  ['tjgeterrorcode',['tjGetErrorCode',['../group___turbo_j_p_e_g.html#ga0be00a62bd1be897f170fa1fed5fb4cb',1,'turbojpeg.h']]],
   ['tjgeterrorstr2',['tjGetErrorStr2',['../group___turbo_j_p_e_g.html#ga94a235bd4f1088f61ad87b4eadb64c9c',1,'turbojpeg.h']]],
   ['tjgetscalingfactors',['tjGetScalingFactors',['../group___turbo_j_p_e_g.html#ga6449044b9af402999ccf52f401333be8',1,'turbojpeg.h']]],
   ['tjinitcompress',['tjInitCompress',['../group___turbo_j_p_e_g.html#ga3d10c47fbe4a2489a2b30c931551d01a',1,'turbojpeg.h']]],
index 618cc977dfddcb065418f5be1aa80c16fc526ee7..3a635055280bb0ce94100f0b60e81211514dd5ff 100644 (file)
@@ -663,7 +663,10 @@ class TJBench {
     System.out.println("     taking performance measurements (default = 1)");
     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);
@@ -833,6 +836,8 @@ class TJBench {
               System.out.format("Warmup runs = %d\n\n", warmup);
             }
           }
+          if (argv[i].equalsIgnoreCase("-stoponwarning"))
+            flags |= TJ.FLAG_STOPONWARNING;
           if (argv[i].equalsIgnoreCase("-?"))
             usage();
         }
@@ -905,7 +910,12 @@ 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;
     }
index ec1b21d44b1d8573161e8bc07c77ffd14cbf9065..a180b68b8f04e5221d5cec8730a6f7fe9e713f2d 100644 (file)
 <td class="colLast"><code>4</code></td>
 </tr>
 <tr class="rowColor">
+<td class="colFirst"><a name="org.libjpegturbo.turbojpeg.TJ.ERR_FATAL">
+<!--   -->
+</a><code>public&nbsp;static&nbsp;final&nbsp;int</code></td>
+<td><code><a href="org/libjpegturbo/turbojpeg/TJ.html#ERR_FATAL">ERR_FATAL</a></code></td>
+<td class="colLast"><code>1</code></td>
+</tr>
+<tr class="altColor">
+<td class="colFirst"><a name="org.libjpegturbo.turbojpeg.TJ.ERR_WARNING">
+<!--   -->
+</a><code>public&nbsp;static&nbsp;final&nbsp;int</code></td>
+<td><code><a href="org/libjpegturbo/turbojpeg/TJ.html#ERR_WARNING">ERR_WARNING</a></code></td>
+<td class="colLast"><code>0</code></td>
+</tr>
+<tr class="rowColor">
 <td class="colFirst"><a name="org.libjpegturbo.turbojpeg.TJ.FLAG_ACCURATEDCT">
 <!--   -->
 </a><code>public&nbsp;static&nbsp;final&nbsp;int</code></td>
 <td class="colLast"><code>128</code></td>
 </tr>
 <tr class="rowColor">
+<td class="colFirst"><a name="org.libjpegturbo.turbojpeg.TJ.FLAG_STOPONWARNING">
+<!--   -->
+</a><code>public&nbsp;static&nbsp;final&nbsp;int</code></td>
+<td><code><a href="org/libjpegturbo/turbojpeg/TJ.html#FLAG_STOPONWARNING">FLAG_STOPONWARNING</a></code></td>
+<td class="colLast"><code>8192</code></td>
+</tr>
+<tr class="altColor">
 <td class="colFirst"><a name="org.libjpegturbo.turbojpeg.TJ.NUMCS">
 <!--   -->
 </a><code>public&nbsp;static&nbsp;final&nbsp;int</code></td>
 <td><code><a href="org/libjpegturbo/turbojpeg/TJ.html#NUMCS">NUMCS</a></code></td>
 <td class="colLast"><code>5</code></td>
 </tr>
+<tr class="rowColor">
+<td class="colFirst"><a name="org.libjpegturbo.turbojpeg.TJ.NUMERR">
+<!--   -->
+</a><code>public&nbsp;static&nbsp;final&nbsp;int</code></td>
+<td><code><a href="org/libjpegturbo/turbojpeg/TJ.html#NUMERR">NUMERR</a></code></td>
+<td class="colLast"><code>2</code></td>
+</tr>
 <tr class="altColor">
 <td class="colFirst"><a name="org.libjpegturbo.turbojpeg.TJ.NUMPF">
 <!--   -->
index a02d9c460a5f2473e0d46e8747c899e20e039a26..b88c20f9f6ac20008caa80f26f33aecb4c343497 100644 (file)
 <div class="block">Returns true or false, depending on whether this instance and
  <code>other</code> have the same numerator and denominator.</div>
 </dd>
+<dt><span class="strong"><a href="./org/libjpegturbo/turbojpeg/TJ.html#ERR_FATAL">ERR_FATAL</a></span> - Static variable in class org.libjpegturbo.turbojpeg.<a href="./org/libjpegturbo/turbojpeg/TJ.html" title="class in org.libjpegturbo.turbojpeg">TJ</a></dt>
+<dd>
+<div class="block">The error was fatal and non-recoverable.</div>
+</dd>
+<dt><span class="strong"><a href="./org/libjpegturbo/turbojpeg/TJ.html#ERR_WARNING">ERR_WARNING</a></span> - Static variable in class org.libjpegturbo.turbojpeg.<a href="./org/libjpegturbo/turbojpeg/TJ.html" title="class in org.libjpegturbo.turbojpeg">TJ</a></dt>
+<dd>
+<div class="block">The error was non-fatal and recoverable, but the image may still be
+ corrupt.</div>
+</dd>
 </dl>
 <a name="_F_">
 <!--   -->
 <dd>
 <div class="block"><span class="strong">Deprecated.</span></div>
 </dd>
+<dt><span class="strong"><a href="./org/libjpegturbo/turbojpeg/TJ.html#FLAG_STOPONWARNING">FLAG_STOPONWARNING</a></span> - Static variable in class org.libjpegturbo.turbojpeg.<a href="./org/libjpegturbo/turbojpeg/TJ.html" title="class in org.libjpegturbo.turbojpeg">TJ</a></dt>
+<dd>
+<div class="block">Immediately discontinue the current compression/decompression/transform
+ operation if the underlying codec throws a warning (non-fatal error).</div>
+</dd>
 </dl>
 <a name="_G_">
 <!--   -->
 <dd>
 <div class="block">Returns denominator</div>
 </dd>
+<dt><span class="strong"><a href="./org/libjpegturbo/turbojpeg/TJException.html#getErrorCode()">getErrorCode()</a></span> - Method in exception org.libjpegturbo.turbojpeg.<a href="./org/libjpegturbo/turbojpeg/TJException.html" title="class in org.libjpegturbo.turbojpeg">TJException</a></dt>
+<dd>
+<div class="block">Returns a code (one of <a href="./org/libjpegturbo/turbojpeg/TJ.html" title="class in org.libjpegturbo.turbojpeg"><code>TJ.ERR_*</code></a>) indicating the severity of the
+ last error.</div>
+</dd>
 <dt><span class="strong"><a href="./org/libjpegturbo/turbojpeg/TJ.html#getGreenOffset(int)">getGreenOffset(int)</a></span> - Static method in class org.libjpegturbo.turbojpeg.<a href="./org/libjpegturbo/turbojpeg/TJ.html" title="class in org.libjpegturbo.turbojpeg">TJ</a></dt>
 <dd>
 <div class="block">For the given pixel format, returns the number of bytes that the green
 <dd>
 <div class="block">The number of JPEG colorspaces</div>
 </dd>
+<dt><span class="strong"><a href="./org/libjpegturbo/turbojpeg/TJ.html#NUMERR">NUMERR</a></span> - Static variable in class org.libjpegturbo.turbojpeg.<a href="./org/libjpegturbo/turbojpeg/TJ.html" title="class in org.libjpegturbo.turbojpeg">TJ</a></dt>
+<dd>
+<div class="block">The number of error codes</div>
+</dd>
 <dt><span class="strong"><a href="./org/libjpegturbo/turbojpeg/TJTransform.html#NUMOP">NUMOP</a></span> - Static variable in class org.libjpegturbo.turbojpeg.<a href="./org/libjpegturbo/turbojpeg/TJTransform.html" title="class in org.libjpegturbo.turbojpeg">TJTransform</a></dt>
 <dd>
 <div class="block">The number of lossless transform operations</div>
 <dd>&nbsp;</dd>
 <dt><span class="strong"><a href="./org/libjpegturbo/turbojpeg/TJException.html#TJException(java.lang.String)">TJException(String)</a></span> - Constructor for exception org.libjpegturbo.turbojpeg.<a href="./org/libjpegturbo/turbojpeg/TJException.html" title="class in org.libjpegturbo.turbojpeg">TJException</a></dt>
 <dd>&nbsp;</dd>
+<dt><span class="strong"><a href="./org/libjpegturbo/turbojpeg/TJException.html#TJException(java.lang.String,%20int)">TJException(String, int)</a></span> - Constructor for exception org.libjpegturbo.turbojpeg.<a href="./org/libjpegturbo/turbojpeg/TJException.html" title="class in org.libjpegturbo.turbojpeg">TJException</a></dt>
+<dd>&nbsp;</dd>
 <dt><span class="strong"><a href="./org/libjpegturbo/turbojpeg/TJException.html#TJException(java.lang.Throwable)">TJException(Throwable)</a></span> - Constructor for exception org.libjpegturbo.turbojpeg.<a href="./org/libjpegturbo/turbojpeg/TJException.html" title="class in org.libjpegturbo.turbojpeg">TJException</a></dt>
 <dd>&nbsp;</dd>
 <dt><a href="./org/libjpegturbo/turbojpeg/TJScalingFactor.html" title="class in org.libjpegturbo.turbojpeg"><span class="strong">TJScalingFactor</span></a> - Class in <a href="./org/libjpegturbo/turbojpeg/package-summary.html">org.libjpegturbo.turbojpeg</a></dt>
index ffef65786399a80b7f16ea2fa42f745c44fe885b..6733749b28937ca69bfcc129134f707013f44e26 100644 (file)
@@ -145,6 +145,19 @@ extends java.lang.Object</pre>
 </tr>
 <tr class="rowColor">
 <td class="colFirst"><code>static int</code></td>
+<td class="colLast"><code><strong><a href="../../../org/libjpegturbo/turbojpeg/TJ.html#ERR_FATAL">ERR_FATAL</a></strong></code>
+<div class="block">The error was fatal and non-recoverable.</div>
+</td>
+</tr>
+<tr class="altColor">
+<td class="colFirst"><code>static int</code></td>
+<td class="colLast"><code><strong><a href="../../../org/libjpegturbo/turbojpeg/TJ.html#ERR_WARNING">ERR_WARNING</a></strong></code>
+<div class="block">The error was non-fatal and recoverable, but the image may still be
+ corrupt.</div>
+</td>
+</tr>
+<tr class="rowColor">
+<td class="colFirst"><code>static int</code></td>
 <td class="colLast"><code><strong><a href="../../../org/libjpegturbo/turbojpeg/TJ.html#FLAG_ACCURATEDCT">FLAG_ACCURATEDCT</a></strong></code>
 <div class="block">Use the most accurate DCT/IDCT algorithm available in the underlying
  codec.</div>
@@ -197,10 +210,23 @@ extends java.lang.Object</pre>
 </tr>
 <tr class="rowColor">
 <td class="colFirst"><code>static int</code></td>
+<td class="colLast"><code><strong><a href="../../../org/libjpegturbo/turbojpeg/TJ.html#FLAG_STOPONWARNING">FLAG_STOPONWARNING</a></strong></code>
+<div class="block">Immediately discontinue the current compression/decompression/transform
+ operation if the underlying codec throws a warning (non-fatal error).</div>
+</td>
+</tr>
+<tr class="altColor">
+<td class="colFirst"><code>static int</code></td>
 <td class="colLast"><code><strong><a href="../../../org/libjpegturbo/turbojpeg/TJ.html#NUMCS">NUMCS</a></strong></code>
 <div class="block">The number of JPEG colorspaces</div>
 </td>
 </tr>
+<tr class="rowColor">
+<td class="colFirst"><code>static int</code></td>
+<td class="colLast"><code><strong><a href="../../../org/libjpegturbo/turbojpeg/TJ.html#NUMERR">NUMERR</a></strong></code>
+<div class="block">The number of error codes</div>
+</td>
+</tr>
 <tr class="altColor">
 <td class="colFirst"><code>static int</code></td>
 <td class="colLast"><code><strong><a href="../../../org/libjpegturbo/turbojpeg/TJ.html#NUMPF">NUMPF</a></strong></code>
@@ -938,7 +964,7 @@ public static final&nbsp;int FLAG_FORCESSE3</pre>
 <a name="FLAG_ACCURATEDCT">
 <!--   -->
 </a>
-<ul class="blockListLast">
+<ul class="blockList">
 <li class="blockList">
 <h4>FLAG_ACCURATEDCT</h4>
 <pre>public static final&nbsp;int FLAG_ACCURATEDCT</pre>
@@ -952,6 +978,54 @@ public static final&nbsp;int FLAG_FORCESSE3</pre>
 <dl><dt><span class="strong">See Also:</span></dt><dd><a href="../../../constant-values.html#org.libjpegturbo.turbojpeg.TJ.FLAG_ACCURATEDCT">Constant Field Values</a></dd></dl>
 </li>
 </ul>
+<a name="FLAG_STOPONWARNING">
+<!--   -->
+</a>
+<ul class="blockList">
+<li class="blockList">
+<h4>FLAG_STOPONWARNING</h4>
+<pre>public static final&nbsp;int FLAG_STOPONWARNING</pre>
+<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>
+<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>
+<a name="NUMERR">
+<!--   -->
+</a>
+<ul class="blockList">
+<li class="blockList">
+<h4>NUMERR</h4>
+<pre>public static final&nbsp;int NUMERR</pre>
+<div class="block">The number of error codes</div>
+<dl><dt><span class="strong">See Also:</span></dt><dd><a href="../../../constant-values.html#org.libjpegturbo.turbojpeg.TJ.NUMERR">Constant Field Values</a></dd></dl>
+</li>
+</ul>
+<a name="ERR_WARNING">
+<!--   -->
+</a>
+<ul class="blockList">
+<li class="blockList">
+<h4>ERR_WARNING</h4>
+<pre>public static final&nbsp;int ERR_WARNING</pre>
+<div class="block">The error was non-fatal and recoverable, but the image may still be
+ corrupt.</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>
+<a name="ERR_FATAL">
+<!--   -->
+</a>
+<ul class="blockListLast">
+<li class="blockList">
+<h4>ERR_FATAL</h4>
+<pre>public static final&nbsp;int ERR_FATAL</pre>
+<div class="block">The error was fatal and non-recoverable.</div>
+<dl><dt><span class="strong">See Also:</span></dt><dd><a href="../../../constant-values.html#org.libjpegturbo.turbojpeg.TJ.ERR_FATAL">Constant Field Values</a></dd></dl>
+</li>
+</ul>
 </li>
 </ul>
 <!-- ========= CONSTRUCTOR DETAIL ======== -->
index 608806617ccc073d69ce3edb770e3f1771ced0f7..a57b351455619ed165cce168bb7217a03f0b374e 100644 (file)
 <li>Nested&nbsp;|&nbsp;</li>
 <li>Field&nbsp;|&nbsp;</li>
 <li><a href="#constructor_summary">Constr</a>&nbsp;|&nbsp;</li>
-<li><a href="#methods_inherited_from_class_java.lang.Throwable">Method</a></li>
+<li><a href="#method_summary">Method</a></li>
 </ul>
 <ul class="subNavList">
 <li>Detail:&nbsp;</li>
 <li>Field&nbsp;|&nbsp;</li>
 <li><a href="#constructor_detail">Constr</a>&nbsp;|&nbsp;</li>
-<li>Method</li>
+<li><a href="#method_detail">Method</a></li>
 </ul>
 </div>
 <a name="skip-navbar_top">
@@ -138,10 +138,14 @@ extends java.io.IOException</pre>
 <td class="colOne"><code><strong><a href="../../../org/libjpegturbo/turbojpeg/TJException.html#TJException(java.lang.String)">TJException</a></strong>(java.lang.String&nbsp;message)</code>&nbsp;</td>
 </tr>
 <tr class="altColor">
+<td class="colOne"><code><strong><a href="../../../org/libjpegturbo/turbojpeg/TJException.html#TJException(java.lang.String,%20int)">TJException</a></strong>(java.lang.String&nbsp;message,
+           int&nbsp;code)</code>&nbsp;</td>
+</tr>
+<tr class="rowColor">
 <td class="colOne"><code><strong><a href="../../../org/libjpegturbo/turbojpeg/TJException.html#TJException(java.lang.String,%20java.lang.Throwable)">TJException</a></strong>(java.lang.String&nbsp;message,
            java.lang.Throwable&nbsp;cause)</code>&nbsp;</td>
 </tr>
-<tr class="rowColor">
+<tr class="altColor">
 <td class="colOne"><code><strong><a href="../../../org/libjpegturbo/turbojpeg/TJException.html#TJException(java.lang.Throwable)">TJException</a></strong>(java.lang.Throwable&nbsp;cause)</code>&nbsp;</td>
 </tr>
 </table>
@@ -153,6 +157,20 @@ extends java.io.IOException</pre>
 <!--   -->
 </a>
 <h3>Method Summary</h3>
+<table class="overviewSummary" border="0" cellpadding="3" cellspacing="0" summary="Method Summary table, listing methods, and an explanation">
+<caption><span>Methods</span><span class="tabEnd">&nbsp;</span></caption>
+<tr>
+<th class="colFirst" scope="col">Modifier and Type</th>
+<th class="colLast" scope="col">Method and Description</th>
+</tr>
+<tr class="altColor">
+<td class="colFirst"><code>int</code></td>
+<td class="colLast"><code><strong><a href="../../../org/libjpegturbo/turbojpeg/TJException.html#getErrorCode()">getErrorCode</a></strong>()</code>
+<div class="block">Returns a code (one of <a href="../../../org/libjpegturbo/turbojpeg/TJ.html" title="class in org.libjpegturbo.turbojpeg"><code>TJ.ERR_*</code></a>) indicating the severity of the
+ last error.</div>
+</td>
+</tr>
+</table>
 <ul class="blockList">
 <li class="blockList"><a name="methods_inherited_from_class_java.lang.Throwable">
 <!--   -->
@@ -209,6 +227,16 @@ extends java.io.IOException</pre>
 <pre>public&nbsp;TJException(java.lang.String&nbsp;message)</pre>
 </li>
 </ul>
+<a name="TJException(java.lang.String, int)">
+<!--   -->
+</a>
+<ul class="blockList">
+<li class="blockList">
+<h4>TJException</h4>
+<pre>public&nbsp;TJException(java.lang.String&nbsp;message,
+           int&nbsp;code)</pre>
+</li>
+</ul>
 <a name="TJException(java.lang.Throwable)">
 <!--   -->
 </a>
@@ -220,6 +248,27 @@ extends java.io.IOException</pre>
 </ul>
 </li>
 </ul>
+<!-- ============ METHOD DETAIL ========== -->
+<ul class="blockList">
+<li class="blockList"><a name="method_detail">
+<!--   -->
+</a>
+<h3>Method Detail</h3>
+<a name="getErrorCode()">
+<!--   -->
+</a>
+<ul class="blockListLast">
+<li class="blockList">
+<h4>getErrorCode</h4>
+<pre>public&nbsp;int&nbsp;getErrorCode()</pre>
+<div class="block">Returns a code (one of <a href="../../../org/libjpegturbo/turbojpeg/TJ.html" title="class in org.libjpegturbo.turbojpeg"><code>TJ.ERR_*</code></a>) indicating the severity of the
+ last error.</div>
+<dl><dt><span class="strong">Returns:</span></dt><dd>a code (one of <a href="../../../org/libjpegturbo/turbojpeg/TJ.html" title="class in org.libjpegturbo.turbojpeg"><code>TJ.ERR_*</code></a>) indicating the severity of the
+ last error.</dd></dl>
+</li>
+</ul>
+</li>
+</ul>
 </li>
 </ul>
 </div>
@@ -270,13 +319,13 @@ extends java.io.IOException</pre>
 <li>Nested&nbsp;|&nbsp;</li>
 <li>Field&nbsp;|&nbsp;</li>
 <li><a href="#constructor_summary">Constr</a>&nbsp;|&nbsp;</li>
-<li><a href="#methods_inherited_from_class_java.lang.Throwable">Method</a></li>
+<li><a href="#method_summary">Method</a></li>
 </ul>
 <ul class="subNavList">
 <li>Detail:&nbsp;</li>
 <li>Field&nbsp;|&nbsp;</li>
 <li><a href="#constructor_detail">Constr</a>&nbsp;|&nbsp;</li>
-<li>Method</li>
+<li><a href="#method_detail">Method</a></li>
 </ul>
 </div>
 <a name="skip-navbar_bottom">
diff --git a/java/doc/script.js b/java/doc/script.js
new file mode 100644 (file)
index 0000000..b346356
--- /dev/null
@@ -0,0 +1,30 @@
+function show(type)
+{
+    count = 0;
+    for (var key in methods) {
+        var row = document.getElementById(key);
+        if ((methods[key] &  type) != 0) {
+            row.style.display = '';
+            row.className = (count++ % 2) ? rowColor : altColor;
+        }
+        else
+            row.style.display = 'none';
+    }
+    updateTabs(type);
+}
+
+function updateTabs(type)
+{
+    for (var value in tabs) {
+        var sNode = document.getElementById(tabs[value][0]);
+        var spanNode = sNode.firstChild;
+        if (value == type) {
+            sNode.className = activeTableTab;
+            spanNode.innerHTML = tabs[value][1];
+        }
+        else {
+            sNode.className = tableTab;
+            spanNode.innerHTML = "<a href=\"javascript:show("+ value + ");\">" + tabs[value][1] + "</a>";
+        }
+    }
+}
index 846cabc84e25dc75c73ccf3f15e2acc42e8a9a51..9ba3fd9e8c7a21585f018438fa34bb5d45777812 100644 (file)
 <dt>serialVersionUID:</dt>
 <dd>1L</dd>
 </dl>
+<ul class="blockList">
+<li class="blockList"><a name="serializedForm">
+<!--   -->
+</a>
+<h3>Serialized Fields</h3>
+<ul class="blockList">
+<li class="blockListLast">
+<h4>errorCode</h4>
+<pre>int errorCode</pre>
+</li>
+</ul>
+</li>
+</ul>
 </li>
 <li class="blockList"><a name="org.libjpegturbo.turbojpeg.TJTransform">
 <!--   -->
index 02d14c066c8cc0d932ae7ec48f218dd681d27b54..4e97aed04bcb3a7809dfb1e0bf9ddc0307e40153 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C)2011-2013 D. R. Commander.  All Rights Reserved.
+ * Copyright (C)2011-2013, 2017 D. R. Commander.  All Rights Reserved.
  * Copyright (C)2015 Viktor Szathmáry.  All Rights Reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -386,6 +386,28 @@ public final class TJ {
    * been shown to have a larger effect.
    */
   public static final int FLAG_ACCURATEDCT  =  4096;
+  /**
+   * 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.
+   */
+  public static final int FLAG_STOPONWARNING = 8192;
+
+
+  /**
+   * The number of error codes
+   */
+  public static final int NUMERR = 2;
+  /**
+   * The error was non-fatal and recoverable, but the image may still be
+   * corrupt.
+   */
+  public static final int ERR_WARNING = 0;
+  /**
+   * The error was fatal and non-recoverable.
+   */
+  public static final int ERR_FATAL = 1;
 
 
   /**
index 59c20413583cca0142c5cb6ec8650d8aa87f98cf..97659d42a0ef5ccd36a105691f4a1bf740f23064 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C)2015 Viktor Szathmáry.  All Rights Reserved.
+ * Copyright (C)2017 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:
@@ -46,8 +47,26 @@ public class TJException extends IOException {
     super(message);
   }
 
+  public TJException(String message, int code) {
+    super(message);
+    if (errorCode >= 0 && errorCode < TJ.NUMERR)
+      errorCode = code;
+  }
+
   public TJException(Throwable cause) {
     super(cause);
   }
 
+  /**
+   * Returns a code (one of {@link TJ TJ.ERR_*}) indicating the severity of the
+   * last error.
+   *
+   * @return a code (one of {@link TJ TJ.ERR_*}) indicating the severity of the
+   * last error.
+   */
+  public int getErrorCode() {
+    return errorCode;
+  }
+
+  private int errorCode = TJ.ERR_FATAL;
 }
index 12b4efe558b787a0a46ec6e2e050dec06c68e34b..50ac852036652607b75cd4ef73c8c95544c4a223 100644 (file)
--- a/tjbench.c
+++ b/tjbench.c
        printf("ERROR in line %d while %s:\n%s\n", __LINE__, op, err);  \
        retval=-1;  goto bailout;}
 #define _throwunix(m) _throw(m, strerror(errno))
-#define _throwtj(m) _throw(m, tjGetErrorStr())
+#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;}
 #define _throwbmp(m) _throw(m, bmpgeterr())
 
 int flags=TJFLAG_NOREALLOC, componly=0, decomponly=0, doyuv=0, quiet=0,
@@ -769,7 +773,10 @@ void usage(char *progname)
        printf("     taking performance measurements (default = 1)\n");
        printf("-componly = Stop after running compression tests.  Do not test decompression.\n");
        printf("-nowrite = Do not write reference or output images (improves consistency of\n");
-       printf("     performance measurements.)\n\n");
+       printf("     performance measurements.)\n");
+       printf("-stoponwarning = Immediately discontinue the current\n");
+       printf("     compression/decompression/transform operation if the underlying codec\n");
+       printf("     throws a warning (non-fatal error)\n\n");
        printf("NOTE:  If the quality is specified as a range (e.g. 90-100), a separate\n");
        printf("test will be performed for all quality values in the range.\n\n");
        exit(1);
@@ -783,7 +790,7 @@ int main(int argc, char *argv[])
        int minarg=2, retval=0, subsamp=-1;
 
        if((scalingfactors=tjGetScalingFactors(&nsf))==NULL || nsf==0)
-               _throwtj("executing tjGetScalingFactors()");
+               _throw("executing tjGetScalingFactors()", tjGetErrorStr());
 
        if(argc<minarg) usage(argv[0]);
 
@@ -920,6 +927,7 @@ int main(int argc, char *argv[])
                        }
                        if(!strcasecmp(argv[i], "-componly")) componly=1;
                        if(!strcasecmp(argv[i], "-nowrite")) dowrite=0;
+                       if(!strcasecmp(argv[i], "-stoponwarning")) flags|=TJFLAG_STOPONWARNING;
                }
        }
 
index b53a8b9ead7715a750f61fe05a42af426a463c64..4f39c9150bcf1462fb2003dc1d542eb1727cfd9a 100644 (file)
 
 #define PAD(v, p) ((v+(p)-1)&(~((p)-1)))
 
+#define bailif0(f) {if(!(f) || (*env)->ExceptionCheck(env)) {  \
+       goto bailout;  \
+}}
+
 #define _throw(msg, exceptionClass) {  \
        jclass _exccls=(*env)->FindClass(env, exceptionClass);  \
-       if(!_exccls || (*env)->ExceptionCheck(env)) goto bailout;  \
+       bailif0(_exccls);  \
        (*env)->ThrowNew(env, _exccls, msg);  \
        goto bailout;  \
 }
 
-#define _throwtj() _throw(tjGetErrorStr2(handle), "org/libjpegturbo/turbojpeg/TJException")
+#define _throwtj() {  \
+       jclass _exccls;  \
+       jmethodID _excid;  \
+       jobject _excobj;  \
+       jstring _errstr;  \
+       bailif0(_errstr = (*env)->NewStringUTF(env, tjGetErrorStr2(handle)));  \
+       bailif0(_exccls = (*env)->FindClass(env,  \
+               "org/libjpegturbo/turbojpeg/TJException"));  \
+       bailif0(_excid = (*env)->GetMethodID(env, _exccls, "<init>",  \
+               "(Ljava/lang/String;I)V"));  \
+       bailif0(_excobj = (*env)->NewObject(env, _exccls, _excid, _errstr,  \
+               tjGetErrorCode(handle)));  \
+       (*env)->Throw(env, _excobj);  \
+       goto bailout;  \
+}
 
 #define _throwarg(msg) _throw(msg, "java/lang/IllegalArgumentException")
 
 #define _throwmem() _throw("Memory allocation failure", "java/lang/OutOfMemoryError");
 
-#define bailif0(f) {if(!(f) || (*env)->ExceptionCheck(env)) {  \
-       goto bailout;  \
-}}
-
 #define gethandle()  \
        jclass _cls=(*env)->GetObjectClass(env, obj);  \
        jfieldID _fid;  \
-       if(!_cls || (*env)->ExceptionCheck(env)) goto bailout;  \
+       bailif0(_cls);  \
        bailif0(_fid=(*env)->GetFieldID(env, _cls, "handle", "J"));  \
        handle=(tjhandle)(size_t)(*env)->GetLongField(env, obj, _fid);  \
 
@@ -174,7 +188,7 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_init
        tjhandle handle;
 
        if((handle=tjInitCompress())==NULL)
-               _throwtj();
+               _throw(tjGetErrorStr(), "org/libjpegturbo/turbojpeg/TJException");
 
        bailif0(cls=(*env)->GetObjectClass(env, obj));
        bailif0(fid=(*env)->GetFieldID(env, cls, "handle", "J"));
@@ -551,7 +565,8 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_init
        jfieldID fid;
        tjhandle handle;
 
-       if((handle=tjInitDecompress())==NULL) _throwtj();
+       if((handle=tjInitDecompress())==NULL)
+               _throw(tjGetErrorStr(), "org/libjpegturbo/turbojpeg/TJException");
 
        bailif0(cls=(*env)->GetObjectClass(env, obj));
        bailif0(fid=(*env)->GetFieldID(env, cls, "handle", "J"));
@@ -958,7 +973,8 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJTransformer_init
        jfieldID fid;
        tjhandle handle;
 
-       if((handle=tjInitTransform())==NULL) _throwtj();
+       if((handle=tjInitTransform())==NULL)
+               _throw(tjGetErrorStr(), "org/libjpegturbo/turbojpeg/TJException");
 
        bailif0(cls=(*env)->GetObjectClass(env, obj));
        bailif0(fid=(*env)->GetFieldID(env, cls, "handle", "J"));
index 8c389aa6cdcad30b498e024965e956fc456c058e..8df3687d0e3a10a8c0c144bdc9e01613f6796cff 100755 (executable)
@@ -58,5 +58,6 @@ TURBOJPEG_1.4
 TURBOJPEG_1.6
 {
        global:
+               tjGetErrorCode;
                tjGetErrorStr2;
 } TURBOJPEG_1.4;
index 7aa014439e810c8df1a9a3b2ecb8f899591db57b..9395dca51be0831f29c316f5ef2002f45284f335 100755 (executable)
@@ -94,5 +94,6 @@ TURBOJPEG_1.4
 TURBOJPEG_1.6
 {
        global:
+               tjGetErrorCode;
                tjGetErrorStr2;
 } TURBOJPEG_1.4;
index 8b771006f91d47c7668a2ecd30eeb3ff5c4da784..569f114dbe89c5846ae3b0eecc37ef7191731250 100644 (file)
@@ -60,7 +60,7 @@ struct my_error_mgr
        struct jpeg_error_mgr pub;
        jmp_buf setjmp_buffer;
        void (*emit_message)(j_common_ptr, int);
-       boolean warning;
+       boolean warning, stopOnWarning;
 };
 typedef struct my_error_mgr *my_error_ptr;
 
@@ -82,7 +82,11 @@ static void my_emit_message(j_common_ptr cinfo, int msg_level)
 {
        my_error_ptr myerr=(my_error_ptr)cinfo->err;
        myerr->emit_message(cinfo, msg_level);
-       if(msg_level<0) myerr->warning=TRUE;
+       if(msg_level<0)
+       {
+               myerr->warning=TRUE;
+               if(myerr->stopOnWarning) longjmp(myerr->setjmp_buffer, 1);
+       }
 }
 
 
@@ -566,6 +570,14 @@ DLLEXPORT char* DLLCALL tjGetErrorStr(void)
 }
 
 
+DLLEXPORT int DLLCALL tjGetErrorCode(tjhandle handle)
+{
+       tjinstance *this=(tjinstance *)handle;
+       if(this && this->jerr.warning) return TJERR_WARNING;
+       else return TJERR_FATAL;
+}
+
+
 DLLEXPORT int DLLCALL tjDestroy(tjhandle handle)
 {
        getinstance(handle);
@@ -783,6 +795,7 @@ DLLEXPORT int DLLCALL tjCompress2(tjhandle handle, const unsigned char *srcBuf,
        #endif
 
        getcinstance(handle)
+       this->jerr.stopOnWarning=(flags & TJFLAG_STOPONWARNING) ? TRUE : FALSE;
        if((this->init&COMPRESS)==0)
                _throw("tjCompress2(): Instance has not been initialized for compression");
 
@@ -891,6 +904,7 @@ DLLEXPORT int DLLCALL tjEncodeYUVPlanes(tjhandle handle,
        #endif
 
        getcinstance(handle);
+       this->jerr.stopOnWarning=(flags & TJFLAG_STOPONWARNING) ? TRUE : FALSE;
 
        for(i=0; i<MAX_COMPONENTS; i++)
        {
@@ -1110,6 +1124,7 @@ DLLEXPORT int DLLCALL tjCompressFromYUVPlanes(tjhandle handle,
        JSAMPLE *_tmpbuf=NULL, *ptr;  JSAMPROW *tmpbuf[MAX_COMPONENTS];
 
        getcinstance(handle)
+       this->jerr.stopOnWarning=(flags & TJFLAG_STOPONWARNING) ? TRUE : FALSE;
 
        for(i=0; i<MAX_COMPONENTS; i++)
        {
@@ -1414,6 +1429,7 @@ DLLEXPORT int DLLCALL tjDecompress2(tjhandle handle,
        #endif
 
        getdinstance(handle);
+       this->jerr.stopOnWarning=(flags & TJFLAG_STOPONWARNING) ? TRUE : FALSE;
        if((this->init&DECOMPRESS)==0)
                _throw("tjDecompress2(): Instance has not been initialized for decompression");
 
@@ -1594,6 +1610,7 @@ DLLEXPORT int DLLCALL tjDecodeYUVPlanes(tjhandle handle,
        void (*old_reset_marker_reader)(j_decompress_ptr);
 
        getdinstance(handle);
+       this->jerr.stopOnWarning=(flags & TJFLAG_STOPONWARNING) ? TRUE : FALSE;
 
        for(i=0; i<MAX_COMPONENTS; i++)
        {
@@ -1795,6 +1812,7 @@ DLLEXPORT int DLLCALL tjDecompressToYUVPlanes(tjhandle handle,
        int dctsize;
 
        getdinstance(handle);
+       this->jerr.stopOnWarning=(flags & TJFLAG_STOPONWARNING) ? TRUE : FALSE;
 
        for(i=0; i<MAX_COMPONENTS; i++)
        {
@@ -1973,6 +1991,7 @@ DLLEXPORT int DLLCALL tjDecompressToYUV2(tjhandle handle,
        int i, jpegwidth, jpegheight, scaledw, scaledh;
 
        getdinstance(handle);
+       this->jerr.stopOnWarning=(flags & TJFLAG_STOPONWARNING) ? TRUE : FALSE;
 
        if(jpegBuf==NULL || jpegSize<=0 || dstBuf==NULL || width<0 || pad<1
                || !isPow2(pad) || height<0)
@@ -2068,6 +2087,7 @@ DLLEXPORT int DLLCALL tjTransform(tjhandle handle,
        int retval=0, i, jpegSubsamp;
 
        getinstance(handle);
+       this->jerr.stopOnWarning=(flags & TJFLAG_STOPONWARNING) ? TRUE : FALSE;
        if((this->init&COMPRESS)==0 || (this->init&DECOMPRESS)==0)
                _throw("tjTransform(): Instance has not been initialized for transformation");
 
index 7475fb36aabad0aa6426a3a26544ebb7369e50e7..dfe7b77369b8aa82f52d0087931d95b7dbde821f 100644 (file)
@@ -383,6 +383,35 @@ enum TJCS
  * when decompressing, because this has been shown to have a larger effect.
  */
 #define TJFLAG_ACCURATEDCT   4096
+/**
+ * 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.
+ */
+#define TJFLAG_STOPONWARNING 8192
+
+
+/**
+ * The number of error codes
+ */
+#define TJ_NUMERR 2
+
+/**
+ * Error codes
+ */
+enum TJERR
+{
+  /**
+   * The error was non-fatal and recoverable, but the image may still be
+   * corrupt.
+   */
+  TJERR_WARNING=0,
+  /**
+   * The error was fatal and non-recoverable.
+   */
+  TJERR_FATAL
+};
 
 
 /**
@@ -670,7 +699,8 @@ DLLEXPORT tjhandle DLLCALL tjInitCompress(void);
  * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP
  * "flags"
  *
- * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2().)
+ * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2()
+ * and #tjGetErrorCode().)
 */
 DLLEXPORT int DLLCALL tjCompress2(tjhandle handle, const unsigned char *srcBuf,
   int width, int pitch, int height, int pixelFormat, unsigned char **jpegBuf,
@@ -734,7 +764,8 @@ DLLEXPORT int DLLCALL tjCompress2(tjhandle handle, const unsigned char *srcBuf,
  * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP
  * "flags"
  *
- * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2().)
+ * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2()
+ * and #tjGetErrorCode().)
 */
 DLLEXPORT int DLLCALL tjCompressFromYUV(tjhandle handle,
   const unsigned char *srcBuf, int width, int pad, int height, int subsamp,
@@ -804,7 +835,8 @@ DLLEXPORT int DLLCALL tjCompressFromYUV(tjhandle handle,
  * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP
  * "flags"
  *
- * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2().)
+ * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2()
+ * and #tjGetErrorCode().)
 */
 DLLEXPORT int DLLCALL tjCompressFromYUVPlanes(tjhandle handle,
   const unsigned char **srcPlanes, int width, const int *strides, int height,
@@ -964,7 +996,8 @@ DLLEXPORT int tjPlaneHeight(int componentID, int height, int subsamp);
  * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP
  * "flags"
  *
- * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2().)
+ * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2()
+ * and #tjGetErrorCode().)
 */
 DLLEXPORT int DLLCALL tjEncodeYUV3(tjhandle handle,
   const unsigned char *srcBuf, int width, int pitch, int height,
@@ -1022,7 +1055,8 @@ DLLEXPORT int DLLCALL tjEncodeYUV3(tjhandle handle,
  * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP
  * "flags"
  *
- * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2().)
+ * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2()
+ * and #tjGetErrorCode().)
 */
 DLLEXPORT int DLLCALL tjEncodeYUVPlanes(tjhandle handle,
   const unsigned char *srcBuf, int width, int pitch, int height,
@@ -1062,7 +1096,8 @@ DLLEXPORT tjhandle DLLCALL tjInitDecompress(void);
  * of the JPEG colorspace constants, indicating the colorspace of the JPEG
  * image (see @ref TJCS "JPEG colorspaces".)
  *
- * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2().)
+ * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2()
+ * and #tjGetErrorCode().)
 */
 DLLEXPORT int DLLCALL tjDecompressHeader3(tjhandle handle,
   const unsigned char *jpegBuf, unsigned long jpegSize, int *width,
@@ -1129,7 +1164,8 @@ DLLEXPORT tjscalingfactor* DLLCALL tjGetScalingFactors(int *numscalingfactors);
  * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP
  * "flags"
  *
- * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2().)
+ * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2()
+ * and #tjGetErrorCode().)
  */
 DLLEXPORT int DLLCALL tjDecompress2(tjhandle handle,
   const unsigned char *jpegBuf, unsigned long jpegSize, unsigned char *dstBuf,
@@ -1179,7 +1215,8 @@ DLLEXPORT int DLLCALL tjDecompress2(tjhandle handle,
  * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP
  * "flags"
  *
- * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2().)
+ * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2()
+ * and #tjGetErrorCode().)
  */
 DLLEXPORT int DLLCALL tjDecompressToYUV2(tjhandle handle,
   const unsigned char *jpegBuf, unsigned long jpegSize, unsigned char *dstBuf,
@@ -1235,7 +1272,8 @@ DLLEXPORT int DLLCALL tjDecompressToYUV2(tjhandle handle,
  * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP
  * "flags"
  *
- * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2().)
+ * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2()
+ * and #tjGetErrorCode().)
  */
 DLLEXPORT int DLLCALL tjDecompressToYUVPlanes(tjhandle handle,
   const unsigned char *jpegBuf, unsigned long jpegSize,
@@ -1287,7 +1325,8 @@ DLLEXPORT int DLLCALL tjDecompressToYUVPlanes(tjhandle handle,
  * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP
  * "flags"
  *
- * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2().)
+ * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2()
+ * and #tjGetErrorCode().)
  */
 DLLEXPORT int DLLCALL tjDecodeYUV(tjhandle handle, const unsigned char *srcBuf,
   int pad, int subsamp, unsigned char *dstBuf, int width, int pitch,
@@ -1344,7 +1383,8 @@ DLLEXPORT int DLLCALL tjDecodeYUV(tjhandle handle, const unsigned char *srcBuf,
  * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP
  * "flags"
  *
- * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2().)
+ * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2()
+ * and #tjGetErrorCode().)
  */
 DLLEXPORT int DLLCALL tjDecodeYUVPlanes(tjhandle handle,
   const unsigned char **srcPlanes, const int *strides, int subsamp,
@@ -1414,7 +1454,8 @@ DLLEXPORT tjhandle DLLCALL tjInitTransform(void);
  * @param flags the bitwise OR of one or more of the @ref TJFLAG_BOTTOMUP
  * "flags"
  *
- * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2().)
+ * @return 0 if successful, or -1 if an error occurred (see #tjGetErrorStr2()
+ * and #tjGetErrorCode().)
  */
 DLLEXPORT int DLLCALL tjTransform(tjhandle handle,
   const unsigned char *jpegBuf, unsigned long jpegSize, int n,
@@ -1475,6 +1516,19 @@ DLLEXPORT void DLLCALL tjFree(unsigned char *buffer);
 DLLEXPORT char* DLLCALL tjGetErrorStr2(tjhandle handle);
 
 
+/**
+ * Returns a code indicating the severity of the last error.  See
+ * @ref TJERR "Error codes".
+ *
+ * @param handle a handle to a TurboJPEG compressor, decompressor or
+ * transformer instance
+ *
+ * @return a code indicating the severity of the last error.  See
+ * @ref TJERR "Error codes".
+ */
+DLLEXPORT int DLLCALL tjGetErrorCode(tjhandle handle);
+
+
 /* Deprecated functions and macros */
 #define TJFLAG_FORCEMMX        8
 #define TJFLAG_FORCESSE       16