TurboJPEG: 8-bit lossless JPEG support

This commit is contained in:
DRC
2022-11-16 15:57:25 -06:00
parent 3fb10c35d8
commit 25ccad99a0
36 changed files with 541 additions and 304 deletions

View File

@@ -716,6 +716,11 @@ final class TJBench {
System.out.println("-arithmetic = Use arithmetic entropy coding in JPEG images generated by");
System.out.println(" compression and transform operations. (Can be combined with");
System.out.println(" -progressive.)");
System.out.println("-lossless = Generate lossless JPEG images (implies -subsamp 444). When");
System.out.println(" generating lossless JPEG images, Quality is psv * 10 + Pt, where psv is");
System.out.println(" the predictor selection value (1-7) and Pt is the point transform (0-7).");
System.out.println(" A point transform value of 0 is necessary in order to create a fully");
System.out.println(" lossless JPEG image.");
System.out.println("-subsamp <s> = When testing JPEG compression, this option specifies the level");
System.out.println(" of chrominance subsampling to use (<s> = 444, 422, 440, 420, 411, or");
System.out.println(" GRAY). The default is to test Grayscale, 4:2:0, 4:2:2, and 4:4:4 in");
@@ -822,6 +827,10 @@ final class TJBench {
} else if (argv[i].equalsIgnoreCase("-arithmetic")) {
System.out.println("Using arithmetic entropy coding\n");
flags |= TJ.FLAG_ARITHMETIC;
} else if (argv[i].equalsIgnoreCase("-lossless")) {
System.out.println("Using lossless JPEG\n\n");
flags |= TJ.FLAG_LOSSLESS;
subsamp = TJ.SAMP_444;
} else if (argv[i].equalsIgnoreCase("-rgb"))
pf = TJ.PF_RGB;
else if (argv[i].equalsIgnoreCase("-rgbx"))

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C)2011-2018 D. R. Commander. All Rights Reserved.
* Copyright (C)2011-2018, 2022 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:
@@ -51,6 +51,7 @@ final class TJUnitTest {
System.out.println("-yuv = test YUV encoding/decoding support");
System.out.println("-noyuvpad = do not pad each line of each Y, U, and V plane to the nearest");
System.out.println(" 4-byte boundary");
System.out.println("-lossless = test lossless JPEG compression/decompression");
System.out.println("-bi = test BufferedImage support\n");
System.exit(1);
}
@@ -92,6 +93,8 @@ final class TJUnitTest {
};
private static boolean doYUV = false;
private static boolean lossless = false;
private static int psv = 1;
private static int pad = 4;
private static boolean bi = false;
@@ -269,7 +272,7 @@ final class TJUnitTest {
static void checkVal(int row, int col, int v, String vname, int cv)
throws Exception {
v = (v < 0) ? v + 256 : v;
if (v < cv - 1 || v > cv + 1) {
if (v < cv - (lossless ? 0 : 1) || v > cv + (lossless ? 0 : 1)) {
throw new Exception("Comp. " + vname + " at " + row + "," + col +
" should be " + cv + ", not " + v);
}
@@ -278,7 +281,7 @@ final class TJUnitTest {
static void checkVal0(int row, int col, int v, String vname)
throws Exception {
v = (v < 0) ? v + 256 : v;
if (v > 1) {
if (v > (lossless ? 0 : 1)) {
throw new Exception("Comp. " + vname + " at " + row + "," + col +
" should be 0, not " + v);
}
@@ -287,7 +290,7 @@ final class TJUnitTest {
static void checkVal255(int row, int col, int v, String vname)
throws Exception {
v = (v < 0) ? v + 256 : v;
if (v < 254) {
if (v < 255 - (lossless ? 0 : 1)) {
throw new Exception("Comp. " + vname + " at " + row + "," + col +
" should be 255, not " + v);
}
@@ -717,6 +720,8 @@ final class TJUnitTest {
}
tjd.setSourceImage(jpegBuf, jpegSize);
if (lossless && subsamp != TJ.SAMP_444 && subsamp != TJ.SAMP_GRAY)
subsamp = TJ.SAMP_444;
if (tjd.getWidth() != w || tjd.getHeight() != h ||
tjd.getSubsamp() != subsamp)
throw new Exception("Incorrect JPEG header");
@@ -780,6 +785,14 @@ final class TJUnitTest {
int w, int h, int pf, String baseName, int subsamp,
int flags) throws Exception {
int i;
TJScalingFactor sf1 = new TJScalingFactor(1, 1);
if (lossless) {
decompTest(tjd, jpegBuf, jpegSize, w, h, pf, baseName, subsamp, flags,
sf1);
return;
}
TJScalingFactor[] sf = TJ.getScalingFactors();
for (i = 0; i < sf.length; i++) {
int num = sf[i].getNum();
@@ -798,7 +811,7 @@ final class TJUnitTest {
throws Exception {
TJCompressor tjc = null;
TJDecompressor tjd = null;
int size;
int size, quality = 100;
byte[] dstBuf;
dstBuf = new byte[TJ.bufSize(w, h, subsamp)];
@@ -811,12 +824,16 @@ final class TJUnitTest {
if (pf < 0) continue;
for (int i = 0; i < 2; i++) {
int flags = 0;
if (lossless) {
flags |= TJ.FLAG_LOSSLESS;
quality = (((psv++ - 1) % 7) + 1) * 10;
}
if (subsamp == TJ.SAMP_422 || subsamp == TJ.SAMP_420 ||
subsamp == TJ.SAMP_440 || subsamp == TJ.SAMP_411)
flags |= TJ.FLAG_FASTUPSAMPLE;
if (i == 1)
flags |= TJ.FLAG_BOTTOMUP;
size = compTest(tjc, dstBuf, w, h, pf, baseName, subsamp, 100,
size = compTest(tjc, dstBuf, w, h, pf, baseName, subsamp, quality,
flags);
decompTest(tjd, dstBuf, size, w, h, pf, baseName, subsamp, flags);
if (pf >= TJ.PF_RGBX && pf <= TJ.PF_XRGB && !bi) {
@@ -838,16 +855,22 @@ final class TJUnitTest {
}
static void bufSizeTest() throws Exception {
int w, h, i, subsamp;
int w, h, i, subsamp, flags = 0, quality = 100, numSamp = TJ.NUMSAMP;
byte[] srcBuf, dstBuf = null;
YUVImage dstImage = null;
TJCompressor tjc = null;
Random r = new Random();
try {
if (lossless) {
flags |= TJ.FLAG_LOSSLESS;
quality = (((psv++ - 1) % 7) + 1) * 10;
numSamp = 1;
}
tjc = new TJCompressor();
System.out.println("Buffer size regression test");
for (subsamp = 0; subsamp < TJ.NUMSAMP; subsamp++) {
for (subsamp = 0; subsamp < numSamp; subsamp++) {
for (w = 1; w < 48; w++) {
int maxh = (w == 1) ? 2048 : 48;
for (h = 1; h < maxh; h++) {
@@ -863,11 +886,11 @@ final class TJUnitTest {
}
tjc.setSourceImage(srcBuf, 0, 0, w, 0, h, TJ.PF_BGRX);
tjc.setSubsamp(subsamp);
tjc.setJPEGQuality(100);
tjc.setJPEGQuality(quality);
if (doYUV)
tjc.encodeYUV(dstImage, 0);
else
tjc.compress(dstBuf, 0);
tjc.compress(dstBuf, flags);
srcBuf = new byte[h * w * 4];
if (doYUV)
@@ -881,7 +904,7 @@ final class TJUnitTest {
if (doYUV)
tjc.encodeYUV(dstImage, 0);
else
tjc.compress(dstBuf, 0);
tjc.compress(dstBuf, flags);
}
dstImage = null;
dstBuf = null;
@@ -904,12 +927,16 @@ final class TJUnitTest {
doYUV = true;
else if (argv[i].equalsIgnoreCase("-noyuvpad"))
pad = 1;
else if (argv[i].equalsIgnoreCase("-lossless"))
lossless = true;
else if (argv[i].equalsIgnoreCase("-bi")) {
bi = true;
testName = "javabitest";
} else
usage();
}
if (lossless && doYUV)
throw new Exception("Lossless JPEG and YUV encoding/decoding are incompatible.");
if (doYUV)
FORMATS_4BYTE[4] = -1;
doTest(35, 39, bi ? FORMATS_3BYTEBI : FORMATS_3BYTE, TJ.SAMP_444,
@@ -918,27 +945,31 @@ final class TJUnitTest {
testName);
doTest(41, 35, bi ? FORMATS_3BYTEBI : FORMATS_3BYTE, TJ.SAMP_422,
testName);
doTest(35, 39, bi ? FORMATS_4BYTEBI : FORMATS_4BYTE, TJ.SAMP_422,
testName);
doTest(39, 41, bi ? FORMATS_3BYTEBI : FORMATS_3BYTE, TJ.SAMP_420,
testName);
doTest(41, 35, bi ? FORMATS_4BYTEBI : FORMATS_4BYTE, TJ.SAMP_420,
testName);
doTest(35, 39, bi ? FORMATS_3BYTEBI : FORMATS_3BYTE, TJ.SAMP_440,
testName);
doTest(39, 41, bi ? FORMATS_4BYTEBI : FORMATS_4BYTE, TJ.SAMP_440,
testName);
doTest(41, 35, bi ? FORMATS_3BYTEBI : FORMATS_3BYTE, TJ.SAMP_411,
testName);
doTest(35, 39, bi ? FORMATS_4BYTEBI : FORMATS_4BYTE, TJ.SAMP_411,
testName);
if (!lossless) {
doTest(35, 39, bi ? FORMATS_4BYTEBI : FORMATS_4BYTE, TJ.SAMP_422,
testName);
doTest(39, 41, bi ? FORMATS_3BYTEBI : FORMATS_3BYTE, TJ.SAMP_420,
testName);
doTest(41, 35, bi ? FORMATS_4BYTEBI : FORMATS_4BYTE, TJ.SAMP_420,
testName);
doTest(35, 39, bi ? FORMATS_3BYTEBI : FORMATS_3BYTE, TJ.SAMP_440,
testName);
doTest(39, 41, bi ? FORMATS_4BYTEBI : FORMATS_4BYTE, TJ.SAMP_440,
testName);
doTest(41, 35, bi ? FORMATS_3BYTEBI : FORMATS_3BYTE, TJ.SAMP_411,
testName);
doTest(35, 39, bi ? FORMATS_4BYTEBI : FORMATS_4BYTE, TJ.SAMP_411,
testName);
}
doTest(39, 41, bi ? FORMATS_GRAYBI : FORMATS_GRAY, TJ.SAMP_GRAY,
testName);
doTest(41, 35, bi ? FORMATS_3BYTEBI : FORMATS_3BYTE, TJ.SAMP_GRAY,
testName);
FORMATS_4BYTE[4] = -1;
doTest(35, 39, bi ? FORMATS_4BYTEBI : FORMATS_4BYTE, TJ.SAMP_GRAY,
testName);
if (!lossless) {
doTest(41, 35, bi ? FORMATS_3BYTEBI : FORMATS_3BYTE, TJ.SAMP_GRAY,
testName);
FORMATS_4BYTE[4] = -1;
doTest(35, 39, bi ? FORMATS_4BYTEBI : FORMATS_4BYTE, TJ.SAMP_GRAY,
testName);
}
if (!bi)
bufSizeTest();
if (doYUV && !bi) {

View File

@@ -175,167 +175,174 @@
<td class="colLast"><code>32768</code></td>
</tr>
<tr class="rowColor">
<td class="colFirst"><a name="org.libjpegturbo.turbojpeg.TJ.FLAG_LOSSLESS">
<!-- -->
</a><code>public&nbsp;static&nbsp;final&nbsp;int</code></td>
<td><code><a href="org/libjpegturbo/turbojpeg/TJ.html#FLAG_LOSSLESS">FLAG_LOSSLESS</a></code></td>
<td class="colLast"><code>131072</code></td>
</tr>
<tr class="altColor">
<td class="colFirst"><a name="org.libjpegturbo.turbojpeg.TJ.FLAG_PROGRESSIVE">
<!-- -->
</a><code>public&nbsp;static&nbsp;final&nbsp;int</code></td>
<td><code><a href="org/libjpegturbo/turbojpeg/TJ.html#FLAG_PROGRESSIVE">FLAG_PROGRESSIVE</a></code></td>
<td class="colLast"><code>16384</code></td>
</tr>
<tr class="altColor">
<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="rowColor">
<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="altColor">
<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="rowColor">
<tr class="altColor">
<td class="colFirst"><a name="org.libjpegturbo.turbojpeg.TJ.NUMPF">
<!-- -->
</a><code>public&nbsp;static&nbsp;final&nbsp;int</code></td>
<td><code><a href="org/libjpegturbo/turbojpeg/TJ.html#NUMPF">NUMPF</a></code></td>
<td class="colLast"><code>12</code></td>
</tr>
<tr class="altColor">
<tr class="rowColor">
<td class="colFirst"><a name="org.libjpegturbo.turbojpeg.TJ.NUMSAMP">
<!-- -->
</a><code>public&nbsp;static&nbsp;final&nbsp;int</code></td>
<td><code><a href="org/libjpegturbo/turbojpeg/TJ.html#NUMSAMP">NUMSAMP</a></code></td>
<td class="colLast"><code>6</code></td>
</tr>
<tr class="rowColor">
<tr class="altColor">
<td class="colFirst"><a name="org.libjpegturbo.turbojpeg.TJ.PF_ABGR">
<!-- -->
</a><code>public&nbsp;static&nbsp;final&nbsp;int</code></td>
<td><code><a href="org/libjpegturbo/turbojpeg/TJ.html#PF_ABGR">PF_ABGR</a></code></td>
<td class="colLast"><code>9</code></td>
</tr>
<tr class="altColor">
<tr class="rowColor">
<td class="colFirst"><a name="org.libjpegturbo.turbojpeg.TJ.PF_ARGB">
<!-- -->
</a><code>public&nbsp;static&nbsp;final&nbsp;int</code></td>
<td><code><a href="org/libjpegturbo/turbojpeg/TJ.html#PF_ARGB">PF_ARGB</a></code></td>
<td class="colLast"><code>10</code></td>
</tr>
<tr class="rowColor">
<tr class="altColor">
<td class="colFirst"><a name="org.libjpegturbo.turbojpeg.TJ.PF_BGR">
<!-- -->
</a><code>public&nbsp;static&nbsp;final&nbsp;int</code></td>
<td><code><a href="org/libjpegturbo/turbojpeg/TJ.html#PF_BGR">PF_BGR</a></code></td>
<td class="colLast"><code>1</code></td>
</tr>
<tr class="altColor">
<tr class="rowColor">
<td class="colFirst"><a name="org.libjpegturbo.turbojpeg.TJ.PF_BGRA">
<!-- -->
</a><code>public&nbsp;static&nbsp;final&nbsp;int</code></td>
<td><code><a href="org/libjpegturbo/turbojpeg/TJ.html#PF_BGRA">PF_BGRA</a></code></td>
<td class="colLast"><code>8</code></td>
</tr>
<tr class="rowColor">
<tr class="altColor">
<td class="colFirst"><a name="org.libjpegturbo.turbojpeg.TJ.PF_BGRX">
<!-- -->
</a><code>public&nbsp;static&nbsp;final&nbsp;int</code></td>
<td><code><a href="org/libjpegturbo/turbojpeg/TJ.html#PF_BGRX">PF_BGRX</a></code></td>
<td class="colLast"><code>3</code></td>
</tr>
<tr class="altColor">
<tr class="rowColor">
<td class="colFirst"><a name="org.libjpegturbo.turbojpeg.TJ.PF_CMYK">
<!-- -->
</a><code>public&nbsp;static&nbsp;final&nbsp;int</code></td>
<td><code><a href="org/libjpegturbo/turbojpeg/TJ.html#PF_CMYK">PF_CMYK</a></code></td>
<td class="colLast"><code>11</code></td>
</tr>
<tr class="rowColor">
<tr class="altColor">
<td class="colFirst"><a name="org.libjpegturbo.turbojpeg.TJ.PF_GRAY">
<!-- -->
</a><code>public&nbsp;static&nbsp;final&nbsp;int</code></td>
<td><code><a href="org/libjpegturbo/turbojpeg/TJ.html#PF_GRAY">PF_GRAY</a></code></td>
<td class="colLast"><code>6</code></td>
</tr>
<tr class="altColor">
<tr class="rowColor">
<td class="colFirst"><a name="org.libjpegturbo.turbojpeg.TJ.PF_RGB">
<!-- -->
</a><code>public&nbsp;static&nbsp;final&nbsp;int</code></td>
<td><code><a href="org/libjpegturbo/turbojpeg/TJ.html#PF_RGB">PF_RGB</a></code></td>
<td class="colLast"><code>0</code></td>
</tr>
<tr class="rowColor">
<tr class="altColor">
<td class="colFirst"><a name="org.libjpegturbo.turbojpeg.TJ.PF_RGBA">
<!-- -->
</a><code>public&nbsp;static&nbsp;final&nbsp;int</code></td>
<td><code><a href="org/libjpegturbo/turbojpeg/TJ.html#PF_RGBA">PF_RGBA</a></code></td>
<td class="colLast"><code>7</code></td>
</tr>
<tr class="altColor">
<tr class="rowColor">
<td class="colFirst"><a name="org.libjpegturbo.turbojpeg.TJ.PF_RGBX">
<!-- -->
</a><code>public&nbsp;static&nbsp;final&nbsp;int</code></td>
<td><code><a href="org/libjpegturbo/turbojpeg/TJ.html#PF_RGBX">PF_RGBX</a></code></td>
<td class="colLast"><code>2</code></td>
</tr>
<tr class="rowColor">
<tr class="altColor">
<td class="colFirst"><a name="org.libjpegturbo.turbojpeg.TJ.PF_XBGR">
<!-- -->
</a><code>public&nbsp;static&nbsp;final&nbsp;int</code></td>
<td><code><a href="org/libjpegturbo/turbojpeg/TJ.html#PF_XBGR">PF_XBGR</a></code></td>
<td class="colLast"><code>4</code></td>
</tr>
<tr class="altColor">
<tr class="rowColor">
<td class="colFirst"><a name="org.libjpegturbo.turbojpeg.TJ.PF_XRGB">
<!-- -->
</a><code>public&nbsp;static&nbsp;final&nbsp;int</code></td>
<td><code><a href="org/libjpegturbo/turbojpeg/TJ.html#PF_XRGB">PF_XRGB</a></code></td>
<td class="colLast"><code>5</code></td>
</tr>
<tr class="rowColor">
<tr class="altColor">
<td class="colFirst"><a name="org.libjpegturbo.turbojpeg.TJ.SAMP_411">
<!-- -->
</a><code>public&nbsp;static&nbsp;final&nbsp;int</code></td>
<td><code><a href="org/libjpegturbo/turbojpeg/TJ.html#SAMP_411">SAMP_411</a></code></td>
<td class="colLast"><code>5</code></td>
</tr>
<tr class="altColor">
<tr class="rowColor">
<td class="colFirst"><a name="org.libjpegturbo.turbojpeg.TJ.SAMP_420">
<!-- -->
</a><code>public&nbsp;static&nbsp;final&nbsp;int</code></td>
<td><code><a href="org/libjpegturbo/turbojpeg/TJ.html#SAMP_420">SAMP_420</a></code></td>
<td class="colLast"><code>2</code></td>
</tr>
<tr class="rowColor">
<tr class="altColor">
<td class="colFirst"><a name="org.libjpegturbo.turbojpeg.TJ.SAMP_422">
<!-- -->
</a><code>public&nbsp;static&nbsp;final&nbsp;int</code></td>
<td><code><a href="org/libjpegturbo/turbojpeg/TJ.html#SAMP_422">SAMP_422</a></code></td>
<td class="colLast"><code>1</code></td>
</tr>
<tr class="altColor">
<tr class="rowColor">
<td class="colFirst"><a name="org.libjpegturbo.turbojpeg.TJ.SAMP_440">
<!-- -->
</a><code>public&nbsp;static&nbsp;final&nbsp;int</code></td>
<td><code><a href="org/libjpegturbo/turbojpeg/TJ.html#SAMP_440">SAMP_440</a></code></td>
<td class="colLast"><code>4</code></td>
</tr>
<tr class="rowColor">
<tr class="altColor">
<td class="colFirst"><a name="org.libjpegturbo.turbojpeg.TJ.SAMP_444">
<!-- -->
</a><code>public&nbsp;static&nbsp;final&nbsp;int</code></td>
<td><code><a href="org/libjpegturbo/turbojpeg/TJ.html#SAMP_444">SAMP_444</a></code></td>
<td class="colLast"><code>0</code></td>
</tr>
<tr class="altColor">
<tr class="rowColor">
<td class="colFirst"><a name="org.libjpegturbo.turbojpeg.TJ.SAMP_GRAY">
<!-- -->
</a><code>public&nbsp;static&nbsp;final&nbsp;int</code></td>

View File

@@ -262,6 +262,10 @@
<div class="block">Limit the number of progressive JPEG scans that the decompression and
transform operations will process.</div>
</dd>
<dt><span class="strong"><a href="./org/libjpegturbo/turbojpeg/TJ.html#FLAG_LOSSLESS">FLAG_LOSSLESS</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">Generate a lossless JPEG image when compressing.</div>
</dd>
<dt><span class="strong"><a href="./org/libjpegturbo/turbojpeg/TJ.html#FLAG_PROGRESSIVE">FLAG_PROGRESSIVE</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">Use progressive entropy coding in JPEG images generated by compression and

View File

@@ -204,145 +204,151 @@ 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_LOSSLESS">FLAG_LOSSLESS</a></strong></code>
<div class="block">Generate a lossless JPEG image when compressing.</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#FLAG_PROGRESSIVE">FLAG_PROGRESSIVE</a></strong></code>
<div class="block">Use progressive entropy coding in JPEG images generated by compression and
transform operations.</div>
</td>
</tr>
<tr class="altColor">
<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="rowColor">
<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="altColor">
<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="rowColor">
<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>
<div class="block">The number of pixel formats</div>
</td>
</tr>
<tr class="altColor">
<tr class="rowColor">
<td class="colFirst"><code>static int</code></td>
<td class="colLast"><code><strong><a href="../../../org/libjpegturbo/turbojpeg/TJ.html#NUMSAMP">NUMSAMP</a></strong></code>
<div class="block">The number of chrominance subsampling options</div>
</td>
</tr>
<tr class="rowColor">
<tr class="altColor">
<td class="colFirst"><code>static int</code></td>
<td class="colLast"><code><strong><a href="../../../org/libjpegturbo/turbojpeg/TJ.html#PF_ABGR">PF_ABGR</a></strong></code>
<div class="block">ABGR pixel format.</div>
</td>
</tr>
<tr class="altColor">
<tr class="rowColor">
<td class="colFirst"><code>static int</code></td>
<td class="colLast"><code><strong><a href="../../../org/libjpegturbo/turbojpeg/TJ.html#PF_ARGB">PF_ARGB</a></strong></code>
<div class="block">ARGB pixel format.</div>
</td>
</tr>
<tr class="rowColor">
<tr class="altColor">
<td class="colFirst"><code>static int</code></td>
<td class="colLast"><code><strong><a href="../../../org/libjpegturbo/turbojpeg/TJ.html#PF_BGR">PF_BGR</a></strong></code>
<div class="block">BGR pixel format.</div>
</td>
</tr>
<tr class="altColor">
<tr class="rowColor">
<td class="colFirst"><code>static int</code></td>
<td class="colLast"><code><strong><a href="../../../org/libjpegturbo/turbojpeg/TJ.html#PF_BGRA">PF_BGRA</a></strong></code>
<div class="block">BGRA pixel format.</div>
</td>
</tr>
<tr class="rowColor">
<tr class="altColor">
<td class="colFirst"><code>static int</code></td>
<td class="colLast"><code><strong><a href="../../../org/libjpegturbo/turbojpeg/TJ.html#PF_BGRX">PF_BGRX</a></strong></code>
<div class="block">BGRX pixel format.</div>
</td>
</tr>
<tr class="altColor">
<tr class="rowColor">
<td class="colFirst"><code>static int</code></td>
<td class="colLast"><code><strong><a href="../../../org/libjpegturbo/turbojpeg/TJ.html#PF_CMYK">PF_CMYK</a></strong></code>
<div class="block">CMYK pixel format.</div>
</td>
</tr>
<tr class="rowColor">
<tr class="altColor">
<td class="colFirst"><code>static int</code></td>
<td class="colLast"><code><strong><a href="../../../org/libjpegturbo/turbojpeg/TJ.html#PF_GRAY">PF_GRAY</a></strong></code>
<div class="block">Grayscale pixel format.</div>
</td>
</tr>
<tr class="altColor">
<tr class="rowColor">
<td class="colFirst"><code>static int</code></td>
<td class="colLast"><code><strong><a href="../../../org/libjpegturbo/turbojpeg/TJ.html#PF_RGB">PF_RGB</a></strong></code>
<div class="block">RGB pixel format.</div>
</td>
</tr>
<tr class="rowColor">
<tr class="altColor">
<td class="colFirst"><code>static int</code></td>
<td class="colLast"><code><strong><a href="../../../org/libjpegturbo/turbojpeg/TJ.html#PF_RGBA">PF_RGBA</a></strong></code>
<div class="block">RGBA pixel format.</div>
</td>
</tr>
<tr class="altColor">
<tr class="rowColor">
<td class="colFirst"><code>static int</code></td>
<td class="colLast"><code><strong><a href="../../../org/libjpegturbo/turbojpeg/TJ.html#PF_RGBX">PF_RGBX</a></strong></code>
<div class="block">RGBX pixel format.</div>
</td>
</tr>
<tr class="rowColor">
<tr class="altColor">
<td class="colFirst"><code>static int</code></td>
<td class="colLast"><code><strong><a href="../../../org/libjpegturbo/turbojpeg/TJ.html#PF_XBGR">PF_XBGR</a></strong></code>
<div class="block">XBGR pixel format.</div>
</td>
</tr>
<tr class="altColor">
<tr class="rowColor">
<td class="colFirst"><code>static int</code></td>
<td class="colLast"><code><strong><a href="../../../org/libjpegturbo/turbojpeg/TJ.html#PF_XRGB">PF_XRGB</a></strong></code>
<div class="block">XRGB pixel format.</div>
</td>
</tr>
<tr class="rowColor">
<tr class="altColor">
<td class="colFirst"><code>static int</code></td>
<td class="colLast"><code><strong><a href="../../../org/libjpegturbo/turbojpeg/TJ.html#SAMP_411">SAMP_411</a></strong></code>
<div class="block">4:1:1 chrominance subsampling.</div>
</td>
</tr>
<tr class="altColor">
<tr class="rowColor">
<td class="colFirst"><code>static int</code></td>
<td class="colLast"><code><strong><a href="../../../org/libjpegturbo/turbojpeg/TJ.html#SAMP_420">SAMP_420</a></strong></code>
<div class="block">4:2:0 chrominance subsampling.</div>
</td>
</tr>
<tr class="rowColor">
<tr class="altColor">
<td class="colFirst"><code>static int</code></td>
<td class="colLast"><code><strong><a href="../../../org/libjpegturbo/turbojpeg/TJ.html#SAMP_422">SAMP_422</a></strong></code>
<div class="block">4:2:2 chrominance subsampling.</div>
</td>
</tr>
<tr class="altColor">
<tr class="rowColor">
<td class="colFirst"><code>static int</code></td>
<td class="colLast"><code><strong><a href="../../../org/libjpegturbo/turbojpeg/TJ.html#SAMP_440">SAMP_440</a></strong></code>
<div class="block">4:4:0 chrominance subsampling.</div>
</td>
</tr>
<tr class="rowColor">
<tr class="altColor">
<td class="colFirst"><code>static int</code></td>
<td class="colLast"><code><strong><a href="../../../org/libjpegturbo/turbojpeg/TJ.html#SAMP_444">SAMP_444</a></strong></code>
<div class="block">4:4:4 chrominance subsampling (no chrominance subsampling).</div>
</td>
</tr>
<tr class="altColor">
<tr class="rowColor">
<td class="colFirst"><code>static int</code></td>
<td class="colLast"><code><strong><a href="../../../org/libjpegturbo/turbojpeg/TJ.html#SAMP_GRAY">SAMP_GRAY</a></strong></code>
<div class="block">Grayscale.</div>
@@ -978,6 +984,31 @@ extends java.lang.Object</pre>
<dl><dt><span class="strong">See Also:</span></dt><dd><a href="../../../constant-values.html#org.libjpegturbo.turbojpeg.TJ.FLAG_ARITHMETIC">Constant Field Values</a></dd></dl>
</li>
</ul>
<a name="FLAG_LOSSLESS">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>FLAG_LOSSLESS</h4>
<pre>public static final&nbsp;int FLAG_LOSSLESS</pre>
<div class="block">Generate a lossless JPEG image when compressing. In most cases,
compressing and decompressing lossless JPEG images is considerably slower
than compressing and decompressing lossy JPEG images. Also note that the
following features are not available with lossless JPEG images:
<ul>
<li> Colorspace conversion
<li> Chrominance subsampling
<li> JPEG quality selection
<li> DCT/IDCT algorithm selection
<li> Progressive entropy coding
<li> Arithmetic entropy coding
<li> Compression from/decompression to YUV planar images
<li> Decompression scaling
<li> Lossless transformations
</ul></div>
<dl><dt><span class="strong">See Also:</span></dt><dd><a href="../../../constant-values.html#org.libjpegturbo.turbojpeg.TJ.FLAG_LOSSLESS">Constant Field Values</a></dd></dl>
</li>
</ul>
<a name="NUMERR">
<!-- -->
</a>

View File

@@ -471,7 +471,14 @@ implements java.io.Closeable</pre>
<pre>public&nbsp;void&nbsp;setJPEGQuality(int&nbsp;quality)</pre>
<div class="block">Set the JPEG image quality level for subsequent compress operations.</div>
<dl><dt><span class="strong">Parameters:</span></dt><dd><code>quality</code> - the new JPEG image quality level (1 to 100, 1 = worst,
100 = best)</dd></dl>
100 = best.) When generating a lossless JPEG image (see
<a href="../../../org/libjpegturbo/turbojpeg/TJ.html#FLAG_LOSSLESS"><code>TJ.FLAG_LOSSLESS</code></a>), <code>quality</code> is
<code>psv * 10 + Pt</code>, where <code>psv</code> is the predictor
selection value (1-7) and <code>Pt</code> is the point transform (0-7). A
point transform value of 0 is necessary in order to create a fully
lossless JPEG image. (A non-zero point transform value right-shifts the
input samples by the specified number of bits, which is effectively a form
of lossy color quantization.)</dd></dl>
</li>
</ul>
<a name="compress(byte[], int)">

View File

@@ -377,7 +377,7 @@ public final class TJ {
* The uncompressed source/destination image is stored in bottom-up (Windows,
* OpenGL) order, not top-down (X11) order.
*/
public static final int FLAG_BOTTOMUP = 2;
public static final int FLAG_BOTTOMUP = (1 << 1);
/**
* When decompressing an image that was compressed using chrominance
@@ -386,7 +386,7 @@ public final class TJ {
* creates a smooth transition between neighboring chrominance components in
* order to reduce upsampling artifacts in the decompressed image.
*/
public static final int FLAG_FASTUPSAMPLE = 256;
public static final int FLAG_FASTUPSAMPLE = (1 << 8);
/**
* Use the fastest DCT/IDCT algorithm available in the underlying codec. The
* default if this flag is not specified is implementation-specific. For
@@ -395,7 +395,7 @@ public final class TJ {
* only a very slight effect on accuracy, but it uses the accurate algorithm
* when decompressing, because this has been shown to have a larger effect.
*/
public static final int FLAG_FASTDCT = 2048;
public static final int FLAG_FASTDCT = (1 << 11);
/**
* Use the most accurate DCT/IDCT algorithm available in the underlying
* codec. The default if this flag is not specified is
@@ -405,7 +405,7 @@ public final class TJ {
* but it uses the accurate algorithm when decompressing, because this has
* been shown to have a larger effect.
*/
public static final int FLAG_ACCURATEDCT = 4096;
public static final int FLAG_ACCURATEDCT = (1 << 12);
/**
* Immediately discontinue the current compression/decompression/transform
* operation if the underlying codec throws a warning (non-fatal error). The
@@ -417,7 +417,7 @@ public final class TJ {
* 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;
public static final int FLAG_STOPONWARNING = (1 << 13);
/**
* Use progressive entropy coding in JPEG images generated by compression and
* transform operations. Progressive entropy coding will generally improve
@@ -425,7 +425,7 @@ public final class TJ {
* reduce compression and decompression performance considerably. Can be
* combined with {@link #FLAG_ARITHMETIC}.
*/
public static final int FLAG_PROGRESSIVE = 16384;
public static final int FLAG_PROGRESSIVE = (1 << 14);
/**
* Limit the number of progressive JPEG scans that the decompression and
* transform operations will process. If a progressive JPEG image contains
@@ -435,7 +435,7 @@ public final class TJ {
* against an exploit of the progressive JPEG format described in
* <a href="https://libjpeg-turbo.org/pmwiki/uploads/About/TwoIssueswiththeJPEGStandard.pdf" target="_blank">this report</a>.
*/
public static final int FLAG_LIMITSCANS = 32768;
public static final int FLAG_LIMITSCANS = (1 << 15);
/**
* Use arithmetic entropy coding in JPEG images generated by compression and
* transform operations. Arithmetic entropy coding will generally improve
@@ -443,7 +443,25 @@ public final class TJ {
* reduce compression and decompression performance considerably. Can be
* combined with {@link #FLAG_PROGRESSIVE}.
*/
public static final int FLAG_ARITHMETIC = 65536;
public static final int FLAG_ARITHMETIC = (1 << 16);
/**
* Generate a lossless JPEG image when compressing. In most cases,
* compressing and decompressing lossless JPEG images is considerably slower
* than compressing and decompressing lossy JPEG images. Also note that the
* following features are not available with lossless JPEG images:
* <ul>
* <li> Colorspace conversion
* <li> Chrominance subsampling
* <li> JPEG quality selection
* <li> DCT/IDCT algorithm selection
* <li> Progressive entropy coding
* <li> Arithmetic entropy coding
* <li> Compression from/decompression to YUV planar images
* <li> Decompression scaling
* <li> Lossless transformations
* </ul>
*/
public static final int FLAG_LOSSLESS = (1 << 17);
/**
* The number of error codes

View File

@@ -1,5 +1,6 @@
/*
* Copyright (C)2011-2015, 2018, 2020 D. R. Commander. All Rights Reserved.
* Copyright (C)2011-2015, 2018, 2020, 2022 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
@@ -283,7 +284,14 @@ public class TJCompressor implements Closeable {
* Set the JPEG image quality level for subsequent compress operations.
*
* @param quality the new JPEG image quality level (1 to 100, 1 = worst,
* 100 = best)
* 100 = best.) When generating a lossless JPEG image (see
* {@link TJ#FLAG_LOSSLESS}), <code>quality</code> is
* <code>psv * 10 + Pt</code>, where <code>psv</code> is the predictor
* selection value (1-7) and <code>Pt</code> is the point transform (0-7). A
* point transform value of 0 is necessary in order to create a fully
* lossless JPEG image. (A non-zero point transform value right-shifts the
* input samples by the specified number of bits, which is effectively a form
* of lossy color quantization.)
*/
public void setJPEGQuality(int quality) {
if (quality < 1 || quality > 100)

View File

@@ -103,21 +103,21 @@ public class TJTransform extends Rectangle {
* partial MCU blocks that cannot be transformed will be left in place, which
* will create odd-looking strips on the right or bottom edge of the image.
*/
public static final int OPT_PERFECT = 1;
public static final int OPT_PERFECT = (1 << 0);
/**
* This option will discard any partial MCU blocks that cannot be
* transformed.
*/
public static final int OPT_TRIM = 2;
public static final int OPT_TRIM = (1 << 1);
/**
* This option will enable lossless cropping.
*/
public static final int OPT_CROP = 4;
public static final int OPT_CROP = (1 << 2);
/**
* This option will discard the color data in the input image and produce
* a grayscale output image.
*/
public static final int OPT_GRAY = 8;
public static final int OPT_GRAY = (1 << 3);
/**
* This option will prevent {@link TJTransformer#transform
* TJTransformer.transform()} from outputting a JPEG image for this
@@ -125,7 +125,7 @@ public class TJTransform extends Rectangle {
* filter to capture the transformed DCT coefficients without transcoding
* them.
*/
public static final int OPT_NOOUTPUT = 16;
public static final int OPT_NOOUTPUT = (1 << 4);
/**
* This option will enable progressive entropy coding in the output image
* generated by this particular transform. Progressive entropy coding will
@@ -133,13 +133,13 @@ public class TJTransform extends Rectangle {
* default), but it will reduce compression and decompression performance
* considerably. Can be combined with {@link #OPT_ARITHMETIC}.
*/
public static final int OPT_PROGRESSIVE = 32;
public static final int OPT_PROGRESSIVE = (1 << 5);
/**
* This option will prevent {@link TJTransformer#transform
* TJTransformer.transform()} from copying any extra markers (including EXIF
* and ICC profile data) from the source image to the output image.
*/
public static final int OPT_COPYNONE = 64;
public static final int OPT_COPYNONE = (1 << 6);
/**
* This option will enable arithmetic entropy coding in the output image
* generated by this particular transform. Arithmetic entropy coding will
@@ -147,7 +147,7 @@ public class TJTransform extends Rectangle {
* default), but it will reduce compression and decompression performance
* considerably. Can be combined with {@link #OPT_PROGRESSIVE}.
*/
public static final int OPT_ARITHMETIC = 128;
public static final int OPT_ARITHMETIC = (1 << 7);
/**