Implement arithmetic coding with 12-bit precision

This actually works and apparently always has worked.  It only failed
because the libjpeg code, which did not originally support arithmetic
coding, assumed that optimize_coding should always be TRUE for 12-bit
data precision.
This commit is contained in:
DRC
2023-01-26 13:11:58 -06:00
parent fc01f4673b
commit 96bc40c1b3
19 changed files with 68 additions and 52 deletions

View File

@@ -775,6 +775,7 @@ final class TJBench {
System.out.println(" (use the CMYK pixel format for packed-pixel source/destination buffers)");
System.out.println("-precision N = Use N-bit data precision when compressing [N is 8, 12, or 16;");
System.out.println(" default = 8; if N is 16, then -lossless must also be specified]");
System.out.println(" (-precision 12 implies -optimize unless -arithmetic is also specified)");
System.out.println("-quiet = Output results in tabular rather than verbose format");
System.out.println("-restart N = When compressing, add a restart marker every N MCU rows (lossy) or");
System.out.println(" N sample rows (lossless) [default = 0 (no restart markers)]. Append 'B'");
@@ -793,7 +794,6 @@ final class TJBench {
System.out.println("------------------");
System.out.println("-arithmetic = Use arithmetic entropy coding in JPEG images generated by");
System.out.println(" compression and transform operations (can be combined with -progressive)");
System.out.println(" ** 8-bit data precision only **");
System.out.println("-crop WxH+X+Y = Decompress only the specified region of the JPEG image, where W");
System.out.println(" and H are the width and height of the region (0 = maximum possible width");
System.out.println(" or height) and X and Y are the left and upper boundary of the region, all");
@@ -804,8 +804,8 @@ final class TJBench {
System.out.println("-optimize = Use optimized baseline entropy coding in JPEG images generated by");
System.out.println(" compession and transform operations");
System.out.println("-progressive = Use progressive entropy coding in JPEG images generated by");
System.out.println(" compression and transform operations (implies -optimize; can be combined");
System.out.println(" with -arithmetic)");
System.out.println(" compression and transform operations (can be combined with -arithmetic;");
System.out.println(" implies -optimize unless -arithmetic is also specified)");
System.out.println("-limitscans = Refuse to decompress or transform progressive JPEG images that");
System.out.println(" have an unreasonably large number of scans");
System.out.println("-scale M/N = When decompressing, scale the width/height of the JPEG image by a");
@@ -1087,8 +1087,6 @@ final class TJBench {
if (precision == 16 && !lossless)
throw new Exception("-lossless must be specified along with -precision 16");
if (precision != 8 && arithmetic)
throw new Exception("-arithmetic requires 8-bit data precision");
if (precision != 8 && doYUV)
throw new Exception("-yuv requires 8-bit data precision");
if (lossless && doYUV)

Binary file not shown.

View File

@@ -1367,7 +1367,8 @@ extends java.lang.Object</pre>
<li> <code>8</code>, <code>12</code>, or <code>16</code>
</ul>
<p>12-bit data precision implies <a href="#PARAM_OPTIMIZE"><code>PARAM_OPTIMIZE</code></a>.</div>
<p>12-bit data precision implies <a href="#PARAM_OPTIMIZE"><code>PARAM_OPTIMIZE</code></a> unless
<a href="#PARAM_ARITHMETIC"><code>PARAM_ARITHMETIC</code></a> is set.</div>
<dl>
<dt><span class="seeLabel">See Also:</span></dt>
<dd><a href="../../../constant-values.html#org.libjpegturbo.turbojpeg.TJ.PARAM_PRECISION">Constant Field Values</a></dd>
@@ -1511,8 +1512,9 @@ extends java.lang.Object</pre>
<p>Progressive entropy coding will generally improve compression relative
to baseline entropy coding, but it will reduce compression and
decompression performance considerably. Implies <a href="#PARAM_OPTIMIZE"><code>PARAM_OPTIMIZE</code></a>.
Can be combined with <a href="#PARAM_ARITHMETIC"><code>PARAM_ARITHMETIC</code></a>.</div>
decompression performance considerably. Can be combined with
<a href="#PARAM_ARITHMETIC"><code>PARAM_ARITHMETIC</code></a>. Implies <a href="#PARAM_OPTIMIZE"><code>PARAM_OPTIMIZE</code></a> unless
<a href="#PARAM_ARITHMETIC"><code>PARAM_ARITHMETIC</code></a> is also set.</div>
<dl>
<dt><span class="seeLabel">See Also:</span></dt>
<dd><a href="../../../constant-values.html#org.libjpegturbo.turbojpeg.TJ.PARAM_PROGRESSIVE">Constant Field Values</a></dd>
@@ -1572,8 +1574,7 @@ extends java.lang.Object</pre>
<p>Arithmetic entropy coding will generally improve compression relative
to Huffman entropy coding, but it will reduce compression and
decompression performance considerably. Can be combined with
<a href="#PARAM_PROGRESSIVE"><code>PARAM_PROGRESSIVE</code></a>. Arithmetic entropy coding is currently only
implemented for 8-bit samples.</div>
<a href="#PARAM_PROGRESSIVE"><code>PARAM_PROGRESSIVE</code></a>.</div>
<dl>
<dt><span class="seeLabel">See Also:</span></dt>
<dd><a href="../../../constant-values.html#org.libjpegturbo.turbojpeg.TJ.PARAM_ARITHMETIC">Constant Field Values</a></dd>

View File

@@ -700,8 +700,8 @@ extends java.awt.Rectangle</pre>
generated by this particular transform. Progressive entropy coding will
generally improve compression relative to baseline entropy coding (the
default), but it will reduce decompression performance considerably.
Implies <a href="#OPT_OPTIMIZE"><code>OPT_OPTIMIZE</code></a>. Can be combined with
<a href="#OPT_ARITHMETIC"><code>OPT_ARITHMETIC</code></a>.</div>
Can be combined with <a href="#OPT_ARITHMETIC"><code>OPT_ARITHMETIC</code></a>. Implies
<a href="#OPT_OPTIMIZE"><code>OPT_OPTIMIZE</code></a> unless <a href="#OPT_ARITHMETIC"><code>OPT_ARITHMETIC</code></a> is also specified.</div>
<dl>
<dt><span class="seeLabel">See Also:</span></dt>
<dd><a href="../../../constant-values.html#org.libjpegturbo.turbojpeg.TJTransform.OPT_PROGRESSIVE">Constant Field Values</a></dd>

Binary file not shown.

Binary file not shown.

View File

@@ -465,7 +465,8 @@ public final class TJ {
* <li> <code>8</code>, <code>12</code>, or <code>16</code>
* </ul>
*
* <p>12-bit data precision implies {@link #PARAM_OPTIMIZE}.
* <p>12-bit data precision implies {@link #PARAM_OPTIMIZE} unless
* {@link #PARAM_ARITHMETIC} is set.
*/
public static final int PARAM_PRECISION = 7;
/**
@@ -559,8 +560,9 @@ public final class TJ {
*
* <p>Progressive entropy coding will generally improve compression relative
* to baseline entropy coding, but it will reduce compression and
* decompression performance considerably. Implies {@link #PARAM_OPTIMIZE}.
* Can be combined with {@link #PARAM_ARITHMETIC}.
* decompression performance considerably. Can be combined with
* {@link #PARAM_ARITHMETIC}. Implies {@link #PARAM_OPTIMIZE} unless
* {@link #PARAM_ARITHMETIC} is also set.
*/
public static final int PARAM_PROGRESSIVE = 12;
/**
@@ -601,8 +603,7 @@ public final class TJ {
* <p>Arithmetic entropy coding will generally improve compression relative
* to Huffman entropy coding, but it will reduce compression and
* decompression performance considerably. Can be combined with
* {@link #PARAM_PROGRESSIVE}. Arithmetic entropy coding is currently only
* implemented for 8-bit samples.
* {@link #PARAM_PROGRESSIVE}.
*/
public static final int PARAM_ARITHMETIC = 14;
/**

View File

@@ -133,8 +133,8 @@ public class TJTransform extends Rectangle {
* generated by this particular transform. Progressive entropy coding will
* generally improve compression relative to baseline entropy coding (the
* default), but it will reduce decompression performance considerably.
* Implies {@link #OPT_OPTIMIZE}. Can be combined with
* {@link #OPT_ARITHMETIC}.
* Can be combined with {@link #OPT_ARITHMETIC}. Implies
* {@link #OPT_OPTIMIZE} unless {@link #OPT_ARITHMETIC} is also specified.
*/
public static final int OPT_PROGRESSIVE = (1 << 5);
/**