Java: Further style refinements
(detected by enabling additional checkstyle modules) This commit also removes unnecessary uses of the "private" modifier in the Java tests/examples. The default access modifier disallows access outside of the package, and none of these classes is in a package. The only reason we use "private" with member variables in these classes is to make checkstyle happy, because we want it to enforce that behavior in the TurboJPEG API code.
This commit is contained in:
@@ -42,20 +42,20 @@ import org.libjpegturbo.turbojpeg.*;
|
|||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("checkstyle:JavadocType")
|
@SuppressWarnings("checkstyle:JavadocType")
|
||||||
public class TJExample implements TJCustomFilter {
|
class TJExample implements TJCustomFilter {
|
||||||
|
|
||||||
private static final String CLASS_NAME =
|
static final String CLASS_NAME =
|
||||||
new TJExample().getClass().getName();
|
new TJExample().getClass().getName();
|
||||||
|
|
||||||
private static final int DEFAULT_SUBSAMP = TJ.SAMP_444;
|
static final int DEFAULT_SUBSAMP = TJ.SAMP_444;
|
||||||
private static final int DEFAULT_QUALITY = 95;
|
static final int DEFAULT_QUALITY = 95;
|
||||||
|
|
||||||
|
|
||||||
private static final String[] SUBSAMP_NAME = {
|
static final String[] SUBSAMP_NAME = {
|
||||||
"4:4:4", "4:2:2", "4:2:0", "Grayscale", "4:4:0", "4:1:1"
|
"4:4:4", "4:2:2", "4:2:0", "Grayscale", "4:4:0", "4:1:1"
|
||||||
};
|
};
|
||||||
|
|
||||||
private static final String[] COLORSPACE_NAME = {
|
static final String[] COLORSPACE_NAME = {
|
||||||
"RGB", "YCbCr", "GRAY", "CMYK", "YCCK"
|
"RGB", "YCbCr", "GRAY", "CMYK", "YCCK"
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -73,7 +73,7 @@ public class TJExample implements TJCustomFilter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static void usage() throws Exception {
|
static void usage() throws Exception {
|
||||||
System.out.println("\nUSAGE: java [Java options] " + CLASS_NAME +
|
System.out.println("\nUSAGE: java [Java options] " + CLASS_NAME +
|
||||||
" <Input image> <Output image> [options]\n");
|
" <Input image> <Output image> [options]\n");
|
||||||
|
|
||||||
@@ -400,6 +400,6 @@ public class TJExample implements TJCustomFilter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final TJScalingFactor[] SCALING_FACTORS =
|
static final TJScalingFactor[] SCALING_FACTORS =
|
||||||
TJ.getScalingFactors();
|
TJ.getScalingFactors();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -38,14 +38,14 @@ import java.nio.*;
|
|||||||
import org.libjpegturbo.turbojpeg.*;
|
import org.libjpegturbo.turbojpeg.*;
|
||||||
|
|
||||||
@SuppressWarnings("checkstyle:JavadocType")
|
@SuppressWarnings("checkstyle:JavadocType")
|
||||||
public final class TJUnitTest {
|
final class TJUnitTest {
|
||||||
|
|
||||||
private TJUnitTest() {}
|
private TJUnitTest() {}
|
||||||
|
|
||||||
private static final String CLASS_NAME =
|
static final String CLASS_NAME =
|
||||||
new TJUnitTest().getClass().getName();
|
new TJUnitTest().getClass().getName();
|
||||||
|
|
||||||
private static void usage() {
|
static void usage() {
|
||||||
System.out.println("\nUSAGE: java " + CLASS_NAME + " [options]\n");
|
System.out.println("\nUSAGE: java " + CLASS_NAME + " [options]\n");
|
||||||
System.out.println("Options:");
|
System.out.println("Options:");
|
||||||
System.out.println("-yuv = test YUV encoding/decoding support");
|
System.out.println("-yuv = test YUV encoding/decoding support");
|
||||||
@@ -55,39 +55,39 @@ public final class TJUnitTest {
|
|||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String[] SUBNAME_LONG = {
|
static final String[] SUBNAME_LONG = {
|
||||||
"4:4:4", "4:2:2", "4:2:0", "GRAY", "4:4:0", "4:1:1"
|
"4:4:4", "4:2:2", "4:2:0", "GRAY", "4:4:0", "4:1:1"
|
||||||
};
|
};
|
||||||
private static final String[] SUBNAME = {
|
static final String[] SUBNAME = {
|
||||||
"444", "422", "420", "GRAY", "440", "411"
|
"444", "422", "420", "GRAY", "440", "411"
|
||||||
};
|
};
|
||||||
|
|
||||||
private static final String[] PIXFORMATSTR = {
|
static final String[] PIXFORMATSTR = {
|
||||||
"RGB", "BGR", "RGBX", "BGRX", "XBGR", "XRGB", "Grayscale",
|
"RGB", "BGR", "RGBX", "BGRX", "XBGR", "XRGB", "Grayscale",
|
||||||
"RGBA", "BGRA", "ABGR", "ARGB", "CMYK"
|
"RGBA", "BGRA", "ABGR", "ARGB", "CMYK"
|
||||||
};
|
};
|
||||||
|
|
||||||
private static final int[] FORMATS_3BYTE = {
|
static final int[] FORMATS_3BYTE = {
|
||||||
TJ.PF_RGB, TJ.PF_BGR
|
TJ.PF_RGB, TJ.PF_BGR
|
||||||
};
|
};
|
||||||
private static final int[] FORMATS_3BYTEBI = {
|
static final int[] FORMATS_3BYTEBI = {
|
||||||
BufferedImage.TYPE_3BYTE_BGR
|
BufferedImage.TYPE_3BYTE_BGR
|
||||||
};
|
};
|
||||||
private static final int[] FORMATS_4BYTE = {
|
static final int[] FORMATS_4BYTE = {
|
||||||
TJ.PF_RGBX, TJ.PF_BGRX, TJ.PF_XBGR, TJ.PF_XRGB, TJ.PF_CMYK
|
TJ.PF_RGBX, TJ.PF_BGRX, TJ.PF_XBGR, TJ.PF_XRGB, TJ.PF_CMYK
|
||||||
};
|
};
|
||||||
private static final int[] FORMATS_4BYTEBI = {
|
static final int[] FORMATS_4BYTEBI = {
|
||||||
BufferedImage.TYPE_INT_BGR, BufferedImage.TYPE_INT_RGB,
|
BufferedImage.TYPE_INT_BGR, BufferedImage.TYPE_INT_RGB,
|
||||||
BufferedImage.TYPE_4BYTE_ABGR, BufferedImage.TYPE_4BYTE_ABGR_PRE,
|
BufferedImage.TYPE_4BYTE_ABGR, BufferedImage.TYPE_4BYTE_ABGR_PRE,
|
||||||
BufferedImage.TYPE_INT_ARGB, BufferedImage.TYPE_INT_ARGB_PRE
|
BufferedImage.TYPE_INT_ARGB, BufferedImage.TYPE_INT_ARGB_PRE
|
||||||
};
|
};
|
||||||
private static final int[] FORMATS_GRAY = {
|
static final int[] FORMATS_GRAY = {
|
||||||
TJ.PF_GRAY
|
TJ.PF_GRAY
|
||||||
};
|
};
|
||||||
private static final int[] FORMATS_GRAYBI = {
|
static final int[] FORMATS_GRAYBI = {
|
||||||
BufferedImage.TYPE_BYTE_GRAY
|
BufferedImage.TYPE_BYTE_GRAY
|
||||||
};
|
};
|
||||||
private static final int[] FORMATS_RGB = {
|
static final int[] FORMATS_RGB = {
|
||||||
TJ.PF_RGB
|
TJ.PF_RGB
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -97,7 +97,7 @@ public final class TJUnitTest {
|
|||||||
|
|
||||||
private static int exitStatus = 0;
|
private static int exitStatus = 0;
|
||||||
|
|
||||||
private static int biTypePF(int biType) {
|
static int biTypePF(int biType) {
|
||||||
ByteOrder byteOrder = ByteOrder.nativeOrder();
|
ByteOrder byteOrder = ByteOrder.nativeOrder();
|
||||||
switch (biType) {
|
switch (biType) {
|
||||||
case BufferedImage.TYPE_3BYTE_BGR:
|
case BufferedImage.TYPE_3BYTE_BGR:
|
||||||
@@ -119,7 +119,7 @@ public final class TJUnitTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String biTypeStr(int biType) {
|
static String biTypeStr(int biType) {
|
||||||
switch (biType) {
|
switch (biType) {
|
||||||
case BufferedImage.TYPE_3BYTE_BGR:
|
case BufferedImage.TYPE_3BYTE_BGR:
|
||||||
return "3BYTE_BGR";
|
return "3BYTE_BGR";
|
||||||
@@ -142,8 +142,8 @@ public final class TJUnitTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void initBuf(byte[] buf, int w, int pitch, int h, int pf,
|
static void initBuf(byte[] buf, int w, int pitch, int h, int pf, int flags)
|
||||||
int flags) throws Exception {
|
throws Exception {
|
||||||
int roffset = TJ.getRedOffset(pf);
|
int roffset = TJ.getRedOffset(pf);
|
||||||
int goffset = TJ.getGreenOffset(pf);
|
int goffset = TJ.getGreenOffset(pf);
|
||||||
int boffset = TJ.getBlueOffset(pf);
|
int boffset = TJ.getBlueOffset(pf);
|
||||||
@@ -211,8 +211,8 @@ public final class TJUnitTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void initIntBuf(int[] buf, int w, int pitch, int h, int pf,
|
static void initIntBuf(int[] buf, int w, int pitch, int h, int pf, int flags)
|
||||||
int flags) throws Exception {
|
throws Exception {
|
||||||
int rshift = TJ.getRedOffset(pf) * 8;
|
int rshift = TJ.getRedOffset(pf) * 8;
|
||||||
int gshift = TJ.getGreenOffset(pf) * 8;
|
int gshift = TJ.getGreenOffset(pf) * 8;
|
||||||
int bshift = TJ.getBlueOffset(pf) * 8;
|
int bshift = TJ.getBlueOffset(pf) * 8;
|
||||||
@@ -243,8 +243,7 @@ public final class TJUnitTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void initImg(BufferedImage img, int pf, int flags)
|
static void initImg(BufferedImage img, int pf, int flags) throws Exception {
|
||||||
throws Exception {
|
|
||||||
WritableRaster wr = img.getRaster();
|
WritableRaster wr = img.getRaster();
|
||||||
int imgType = img.getType();
|
int imgType = img.getType();
|
||||||
|
|
||||||
@@ -267,8 +266,8 @@ public final class TJUnitTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void checkVal(int row, int col, int v, String vname, int cv)
|
static void checkVal(int row, int col, int v, String vname, int cv)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
v = (v < 0) ? v + 256 : v;
|
v = (v < 0) ? v + 256 : v;
|
||||||
if (v < cv - 1 || v > cv + 1) {
|
if (v < cv - 1 || v > cv + 1) {
|
||||||
throw new Exception("Comp. " + vname + " at " + row + "," + col +
|
throw new Exception("Comp. " + vname + " at " + row + "," + col +
|
||||||
@@ -276,8 +275,8 @@ public final class TJUnitTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void checkVal0(int row, int col, int v, String vname)
|
static void checkVal0(int row, int col, int v, String vname)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
v = (v < 0) ? v + 256 : v;
|
v = (v < 0) ? v + 256 : v;
|
||||||
if (v > 1) {
|
if (v > 1) {
|
||||||
throw new Exception("Comp. " + vname + " at " + row + "," + col +
|
throw new Exception("Comp. " + vname + " at " + row + "," + col +
|
||||||
@@ -285,8 +284,8 @@ public final class TJUnitTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void checkVal255(int row, int col, int v, String vname)
|
static void checkVal255(int row, int col, int v, String vname)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
v = (v < 0) ? v + 256 : v;
|
v = (v < 0) ? v + 256 : v;
|
||||||
if (v < 254) {
|
if (v < 254) {
|
||||||
throw new Exception("Comp. " + vname + " at " + row + "," + col +
|
throw new Exception("Comp. " + vname + " at " + row + "," + col +
|
||||||
@@ -294,9 +293,8 @@ public final class TJUnitTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int checkBuf(byte[] buf, int w, int pitch, int h, int pf,
|
static int checkBuf(byte[] buf, int w, int pitch, int h, int pf, int subsamp,
|
||||||
int subsamp, TJScalingFactor sf, int flags)
|
TJScalingFactor sf, int flags) throws Exception {
|
||||||
throws Exception {
|
|
||||||
int roffset = TJ.getRedOffset(pf);
|
int roffset = TJ.getRedOffset(pf);
|
||||||
int goffset = TJ.getGreenOffset(pf);
|
int goffset = TJ.getGreenOffset(pf);
|
||||||
int boffset = TJ.getBlueOffset(pf);
|
int boffset = TJ.getBlueOffset(pf);
|
||||||
@@ -421,9 +419,9 @@ public final class TJUnitTest {
|
|||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int checkIntBuf(int[] buf, int w, int pitch, int h, int pf,
|
static int checkIntBuf(int[] buf, int w, int pitch, int h, int pf,
|
||||||
int subsamp, TJScalingFactor sf, int flags)
|
int subsamp, TJScalingFactor sf, int flags)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
int rshift = TJ.getRedOffset(pf) * 8;
|
int rshift = TJ.getRedOffset(pf) * 8;
|
||||||
int gshift = TJ.getGreenOffset(pf) * 8;
|
int gshift = TJ.getGreenOffset(pf) * 8;
|
||||||
int bshift = TJ.getBlueOffset(pf) * 8;
|
int bshift = TJ.getBlueOffset(pf) * 8;
|
||||||
@@ -499,8 +497,8 @@ public final class TJUnitTest {
|
|||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int checkImg(BufferedImage img, int pf, int subsamp,
|
static int checkImg(BufferedImage img, int pf, int subsamp,
|
||||||
TJScalingFactor sf, int flags) throws Exception {
|
TJScalingFactor sf, int flags) throws Exception {
|
||||||
WritableRaster wr = img.getRaster();
|
WritableRaster wr = img.getRaster();
|
||||||
int imgType = img.getType();
|
int imgType = img.getType();
|
||||||
if (imgType == BufferedImage.TYPE_INT_RGB ||
|
if (imgType == BufferedImage.TYPE_INT_RGB ||
|
||||||
@@ -524,13 +522,12 @@ public final class TJUnitTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int pad(int v, int p) {
|
static int pad(int v, int p) {
|
||||||
return ((v + (p) - 1) & (~((p) - 1)));
|
return ((v + (p) - 1) & (~((p) - 1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int checkBufYUV(byte[] buf, int size, int w, int h,
|
static int checkBufYUV(byte[] buf, int size, int w, int h, int subsamp,
|
||||||
int subsamp, TJScalingFactor sf)
|
TJScalingFactor sf) throws Exception {
|
||||||
throws Exception {
|
|
||||||
int row, col;
|
int row, col;
|
||||||
int hsf = TJ.getMCUWidth(subsamp) / 8, vsf = TJ.getMCUHeight(subsamp) / 8;
|
int hsf = TJ.getMCUWidth(subsamp) / 8, vsf = TJ.getMCUHeight(subsamp) / 8;
|
||||||
int pw = pad(w, hsf), ph = pad(h, vsf);
|
int pw = pad(w, hsf), ph = pad(h, vsf);
|
||||||
@@ -621,17 +618,17 @@ public final class TJUnitTest {
|
|||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void writeJPEG(byte[] jpegBuf, int jpegBufSize,
|
static void writeJPEG(byte[] jpegBuf, int jpegBufSize, String filename)
|
||||||
String filename) throws Exception {
|
throws Exception {
|
||||||
File file = new File(filename);
|
File file = new File(filename);
|
||||||
FileOutputStream fos = new FileOutputStream(file);
|
FileOutputStream fos = new FileOutputStream(file);
|
||||||
fos.write(jpegBuf, 0, jpegBufSize);
|
fos.write(jpegBuf, 0, jpegBufSize);
|
||||||
fos.close();
|
fos.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int compTest(TJCompressor tjc, byte[] dstBuf, int w,
|
static int compTest(TJCompressor tjc, byte[] dstBuf, int w, int h, int pf,
|
||||||
int h, int pf, String baseName, int subsamp,
|
String baseName, int subsamp, int jpegQual, int flags)
|
||||||
int jpegQual, int flags) throws Exception {
|
throws Exception {
|
||||||
String tempStr;
|
String tempStr;
|
||||||
byte[] srcBuf = null;
|
byte[] srcBuf = null;
|
||||||
BufferedImage img = null;
|
BufferedImage img = null;
|
||||||
@@ -698,10 +695,9 @@ public final class TJUnitTest {
|
|||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void decompTest(TJDecompressor tjd, byte[] jpegBuf,
|
static void decompTest(TJDecompressor tjd, byte[] jpegBuf, int jpegSize,
|
||||||
int jpegSize, int w, int h, int pf,
|
int w, int h, int pf, String baseName, int subsamp,
|
||||||
String baseName, int subsamp, int flags,
|
int flags, TJScalingFactor sf) throws Exception {
|
||||||
TJScalingFactor sf) throws Exception {
|
|
||||||
String pfStr, pfStrLong, tempStr;
|
String pfStr, pfStrLong, tempStr;
|
||||||
String buStrLong = (flags & TJ.FLAG_BOTTOMUP) != 0 ?
|
String buStrLong = (flags & TJ.FLAG_BOTTOMUP) != 0 ?
|
||||||
"Bottom-Up" : "Top-Down ";
|
"Bottom-Up" : "Top-Down ";
|
||||||
@@ -780,10 +776,9 @@ public final class TJUnitTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void decompTest(TJDecompressor tjd, byte[] jpegBuf,
|
static void decompTest(TJDecompressor tjd, byte[] jpegBuf, int jpegSize,
|
||||||
int jpegSize, int w, int h, int pf,
|
int w, int h, int pf, String baseName, int subsamp,
|
||||||
String baseName, int subsamp,
|
int flags) throws Exception {
|
||||||
int flags) throws Exception {
|
|
||||||
int i;
|
int i;
|
||||||
TJScalingFactor[] sf = TJ.getScalingFactors();
|
TJScalingFactor[] sf = TJ.getScalingFactors();
|
||||||
for (i = 0; i < sf.length; i++) {
|
for (i = 0; i < sf.length; i++) {
|
||||||
@@ -799,8 +794,8 @@ public final class TJUnitTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void doTest(int w, int h, int[] formats, int subsamp,
|
static void doTest(int w, int h, int[] formats, int subsamp, String baseName)
|
||||||
String baseName) throws Exception {
|
throws Exception {
|
||||||
TJCompressor tjc = null;
|
TJCompressor tjc = null;
|
||||||
TJDecompressor tjd = null;
|
TJDecompressor tjd = null;
|
||||||
int size;
|
int size;
|
||||||
@@ -842,7 +837,7 @@ public final class TJUnitTest {
|
|||||||
if (tjd != null) tjd.close();
|
if (tjd != null) tjd.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void bufSizeTest() throws Exception {
|
static void bufSizeTest() throws Exception {
|
||||||
int w, h, i, subsamp;
|
int w, h, i, subsamp;
|
||||||
byte[] srcBuf, dstBuf = null;
|
byte[] srcBuf, dstBuf = null;
|
||||||
YUVImage dstImage = null;
|
YUVImage dstImage = null;
|
||||||
|
|||||||
@@ -111,11 +111,11 @@ public class TJTransformer extends TJDecompressor {
|
|||||||
* which specifies the transform parameters and/or cropping region for the
|
* which specifies the transform parameters and/or cropping region for the
|
||||||
* corresponding transformed output image
|
* corresponding transformed output image
|
||||||
*
|
*
|
||||||
* @return an array of {@link TJDecompressor} instances, each of
|
|
||||||
* which has a transformed JPEG image associated with it.
|
|
||||||
*
|
|
||||||
* @param flags the bitwise OR of one or more of
|
* @param flags the bitwise OR of one or more of
|
||||||
* {@link TJ#FLAG_BOTTOMUP TJ.FLAG_*}
|
* {@link TJ#FLAG_BOTTOMUP TJ.FLAG_*}
|
||||||
|
*
|
||||||
|
* @return an array of {@link TJDecompressor} instances, each of
|
||||||
|
* which has a transformed JPEG image associated with it.
|
||||||
*/
|
*/
|
||||||
public TJDecompressor[] transform(TJTransform[] transforms, int flags)
|
public TJDecompressor[] transform(TJTransform[] transforms, int flags)
|
||||||
throws TJException {
|
throws TJException {
|
||||||
|
|||||||
Reference in New Issue
Block a user