Java: Reformat code per checkstyle recommendations
... and modify tjbench.c to match the variable name changes made to
TJBench.java
("checkstyle" = http://checkstyle.sourceforge.net, not our regex-based
checkstyle script)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C)2009-2014, 2016-2017 D. R. Commander. All Rights Reserved.
|
||||
* Copyright (C)2009-2014, 2016-2018 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:
|
||||
@@ -32,51 +32,53 @@ import javax.imageio.*;
|
||||
import java.util.*;
|
||||
import org.libjpegturbo.turbojpeg.*;
|
||||
|
||||
class TJBench {
|
||||
final class TJBench {
|
||||
|
||||
static int flags = 0, quiet = 0, pf = TJ.PF_BGR, yuvPad = 1;
|
||||
static boolean compOnly, decompOnly, doTile, doYUV, write = true;
|
||||
private TJBench() {}
|
||||
|
||||
static final String[] pixFormatStr = {
|
||||
private static int flags = 0, quiet = 0, pf = TJ.PF_BGR, yuvPad = 1;
|
||||
private static boolean compOnly, decompOnly, doTile, doYUV, write = true;
|
||||
|
||||
static final String[] PIXFORMATSTR = {
|
||||
"RGB", "BGR", "RGBX", "BGRX", "XBGR", "XRGB", "GRAY"
|
||||
};
|
||||
|
||||
static final String[] subNameLong = {
|
||||
static final String[] SUBNAME_LONG = {
|
||||
"4:4:4", "4:2:2", "4:2:0", "GRAY", "4:4:0", "4:1:1"
|
||||
};
|
||||
|
||||
static final String[] subName = {
|
||||
static final String[] SUBNAME = {
|
||||
"444", "422", "420", "GRAY", "440", "411"
|
||||
};
|
||||
|
||||
static final String[] csName = {
|
||||
static final String[] CSNAME = {
|
||||
"RGB", "YCbCr", "GRAY", "CMYK", "YCCK"
|
||||
};
|
||||
|
||||
static TJScalingFactor sf;
|
||||
static int xformOp = TJTransform.OP_NONE, xformOpt = 0;
|
||||
static double benchTime = 5.0, warmup = 1.0;
|
||||
private static TJScalingFactor sf;
|
||||
private static int xformOp = TJTransform.OP_NONE, xformOpt = 0;
|
||||
private static double benchTime = 5.0, warmup = 1.0;
|
||||
|
||||
|
||||
static final double getTime() {
|
||||
static double getTime() {
|
||||
return (double)System.nanoTime() / 1.0e9;
|
||||
}
|
||||
|
||||
|
||||
static String tjErrorMsg;
|
||||
static int tjErrorCode = -1;
|
||||
private static String tjErrorMsg;
|
||||
private static int tjErrorCode = -1;
|
||||
|
||||
static void handleTJException(TJException e) throws TJException {
|
||||
String _tjErrorMsg = e.getMessage();
|
||||
int _tjErrorCode = e.getErrorCode();
|
||||
String errorMsg = e.getMessage();
|
||||
int errorCode = e.getErrorCode();
|
||||
|
||||
if ((flags & TJ.FLAG_STOPONWARNING) == 0 &&
|
||||
_tjErrorCode == TJ.ERR_WARNING) {
|
||||
if (tjErrorMsg == null || !tjErrorMsg.equals(_tjErrorMsg) ||
|
||||
tjErrorCode != _tjErrorCode) {
|
||||
tjErrorMsg = _tjErrorMsg;
|
||||
tjErrorCode = _tjErrorCode;
|
||||
System.out.println("WARNING: " + _tjErrorMsg);
|
||||
errorCode == TJ.ERR_WARNING) {
|
||||
if (tjErrorMsg == null || !tjErrorMsg.equals(errorMsg) ||
|
||||
tjErrorCode != errorCode) {
|
||||
tjErrorMsg = errorMsg;
|
||||
tjErrorCode = errorCode;
|
||||
System.out.println("WARNING: " + errorMsg);
|
||||
}
|
||||
} else
|
||||
throw e;
|
||||
@@ -85,11 +87,11 @@ class TJBench {
|
||||
|
||||
static String formatName(int subsamp, int cs) {
|
||||
if (cs == TJ.CS_YCbCr)
|
||||
return subNameLong[subsamp];
|
||||
return SUBNAME_LONG[subsamp];
|
||||
else if (cs == TJ.CS_YCCK)
|
||||
return csName[cs] + " " + subNameLong[subsamp];
|
||||
return CSNAME[cs] + " " + SUBNAME_LONG[subsamp];
|
||||
else
|
||||
return csName[cs];
|
||||
return CSNAME[cs];
|
||||
}
|
||||
|
||||
|
||||
@@ -276,7 +278,7 @@ class TJBench {
|
||||
if (decompOnly)
|
||||
tempStr = new String(fileName + "_" + sizeStr + ".bmp");
|
||||
else
|
||||
tempStr = new String(fileName + "_" + subName[subsamp] + qualStr +
|
||||
tempStr = new String(fileName + "_" + SUBNAME[subsamp] + qualStr +
|
||||
"_" + sizeStr + ".bmp");
|
||||
|
||||
saveImage(tempStr, dstBuf, scaledw, scaledh, pf);
|
||||
@@ -324,7 +326,7 @@ class TJBench {
|
||||
int totalJpegSize = 0, tilew, tileh, i, iter;
|
||||
int ps = TJ.getPixelSize(pf);
|
||||
int ntilesw = 1, ntilesh = 1, pitch = w * ps;
|
||||
String pfStr = pixFormatStr[pf];
|
||||
String pfStr = PIXFORMATSTR[pf];
|
||||
YUVImage yuvImage = null;
|
||||
|
||||
tmpBuf = new byte[pitch * h];
|
||||
@@ -333,7 +335,7 @@ class TJBench {
|
||||
System.out.format(">>>>> %s (%s) <--> JPEG %s Q%d <<<<<\n", pfStr,
|
||||
(flags & TJ.FLAG_BOTTOMUP) != 0 ?
|
||||
"Bottom-up" : "Top-down",
|
||||
subNameLong[subsamp], jpegQual);
|
||||
SUBNAME_LONG[subsamp], jpegQual);
|
||||
|
||||
tjc = new TJCompressor();
|
||||
|
||||
@@ -353,7 +355,7 @@ class TJBench {
|
||||
if (quiet == 1)
|
||||
System.out.format("%-4s (%s) %-5s %-3d ", pfStr,
|
||||
(flags & TJ.FLAG_BOTTOMUP) != 0 ? "BU" : "TD",
|
||||
subNameLong[subsamp], jpegQual);
|
||||
SUBNAME_LONG[subsamp], jpegQual);
|
||||
for (i = 0; i < h; i++)
|
||||
System.arraycopy(srcBuf, w * ps * i, tmpBuf, pitch * i, w * ps);
|
||||
tjc.setJPEGQuality(jpegQual);
|
||||
@@ -453,7 +455,7 @@ class TJBench {
|
||||
(double)iter / elapsed);
|
||||
}
|
||||
if (tilew == w && tileh == h && write) {
|
||||
String tempStr = fileName + "_" + subName[subsamp] + "_" + "Q" +
|
||||
String tempStr = fileName + "_" + SUBNAME[subsamp] + "_" + "Q" +
|
||||
jpegQual + ".jpg";
|
||||
FileOutputStream fos = new FileOutputStream(tempStr);
|
||||
|
||||
@@ -479,11 +481,12 @@ class TJBench {
|
||||
byte[] srcBuf;
|
||||
int[] jpegSize = null;
|
||||
int totalJpegSize;
|
||||
int w = 0, h = 0, subsamp = -1, cs = -1, _w, _h, _tilew, _tileh,
|
||||
_ntilesw, _ntilesh, _subsamp, x, y, iter;
|
||||
int ntilesw = 1, ntilesh = 1;
|
||||
double start, elapsed;
|
||||
int ps = TJ.getPixelSize(pf), tile;
|
||||
int ps = TJ.getPixelSize(pf), tile, x, y, iter;
|
||||
// Original image
|
||||
int w = 0, h = 0, ntilesw = 1, ntilesh = 1, subsamp = -1, cs = -1;
|
||||
// Transformed image
|
||||
int tw, th, ttilew, ttileh, tntilesw, tntilesh, tsubsamp;
|
||||
|
||||
FileInputStream fis = new FileInputStream(fileName);
|
||||
int srcSize = (int)fis.getChannel().size();
|
||||
@@ -517,7 +520,7 @@ class TJBench {
|
||||
System.out.println("\n");
|
||||
} else if (quiet == 0)
|
||||
System.out.format(">>>>> JPEG %s --> %s (%s) <<<<<\n",
|
||||
formatName(subsamp, cs), pixFormatStr[pf],
|
||||
formatName(subsamp, cs), PIXFORMATSTR[pf],
|
||||
(flags & TJ.FLAG_BOTTOMUP) != 0 ?
|
||||
"Bottom-up" : "Top-down");
|
||||
|
||||
@@ -530,66 +533,66 @@ class TJBench {
|
||||
ntilesw = (w + tilew - 1) / tilew;
|
||||
ntilesh = (h + tileh - 1) / tileh;
|
||||
|
||||
_w = w; _h = h; _tilew = tilew; _tileh = tileh;
|
||||
tw = w; th = h; ttilew = tilew; ttileh = tileh;
|
||||
if (quiet == 0) {
|
||||
System.out.format("\n%s size: %d x %d", (doTile ? "Tile" : "Image"),
|
||||
_tilew, _tileh);
|
||||
ttilew, ttileh);
|
||||
if (sf.getNum() != 1 || sf.getDenom() != 1)
|
||||
System.out.format(" --> %d x %d", sf.getScaled(_w),
|
||||
sf.getScaled(_h));
|
||||
System.out.format(" --> %d x %d", sf.getScaled(tw),
|
||||
sf.getScaled(th));
|
||||
System.out.println("");
|
||||
} else if (quiet == 1) {
|
||||
System.out.format("%-4s (%s) %-5s %-5s ", pixFormatStr[pf],
|
||||
System.out.format("%-4s (%s) %-5s %-5s ", PIXFORMATSTR[pf],
|
||||
(flags & TJ.FLAG_BOTTOMUP) != 0 ? "BU" : "TD",
|
||||
csName[cs], subNameLong[subsamp]);
|
||||
CSNAME[cs], SUBNAME_LONG[subsamp]);
|
||||
System.out.format("%-5d %-5d ", tilew, tileh);
|
||||
}
|
||||
|
||||
_subsamp = subsamp;
|
||||
tsubsamp = subsamp;
|
||||
if (doTile || xformOp != TJTransform.OP_NONE || xformOpt != 0) {
|
||||
if (xformOp == TJTransform.OP_TRANSPOSE ||
|
||||
xformOp == TJTransform.OP_TRANSVERSE ||
|
||||
xformOp == TJTransform.OP_ROT90 ||
|
||||
xformOp == TJTransform.OP_ROT270) {
|
||||
_w = h; _h = w; _tilew = tileh; _tileh = tilew;
|
||||
tw = h; th = w; ttilew = tileh; ttileh = tilew;
|
||||
}
|
||||
|
||||
if ((xformOpt & TJTransform.OPT_GRAY) != 0)
|
||||
_subsamp = TJ.SAMP_GRAY;
|
||||
tsubsamp = TJ.SAMP_GRAY;
|
||||
if (xformOp == TJTransform.OP_HFLIP ||
|
||||
xformOp == TJTransform.OP_ROT180)
|
||||
_w = _w - (_w % TJ.getMCUWidth(_subsamp));
|
||||
tw = tw - (tw % TJ.getMCUWidth(tsubsamp));
|
||||
if (xformOp == TJTransform.OP_VFLIP ||
|
||||
xformOp == TJTransform.OP_ROT180)
|
||||
_h = _h - (_h % TJ.getMCUHeight(_subsamp));
|
||||
th = th - (th % TJ.getMCUHeight(tsubsamp));
|
||||
if (xformOp == TJTransform.OP_TRANSVERSE ||
|
||||
xformOp == TJTransform.OP_ROT90)
|
||||
_w = _w - (_w % TJ.getMCUHeight(_subsamp));
|
||||
tw = tw - (tw % TJ.getMCUHeight(tsubsamp));
|
||||
if (xformOp == TJTransform.OP_TRANSVERSE ||
|
||||
xformOp == TJTransform.OP_ROT270)
|
||||
_h = _h - (_h % TJ.getMCUWidth(_subsamp));
|
||||
_ntilesw = (_w + _tilew - 1) / _tilew;
|
||||
_ntilesh = (_h + _tileh - 1) / _tileh;
|
||||
th = th - (th % TJ.getMCUWidth(tsubsamp));
|
||||
tntilesw = (tw + ttilew - 1) / ttilew;
|
||||
tntilesh = (th + ttileh - 1) / ttileh;
|
||||
|
||||
if (xformOp == TJTransform.OP_TRANSPOSE ||
|
||||
xformOp == TJTransform.OP_TRANSVERSE ||
|
||||
xformOp == TJTransform.OP_ROT90 ||
|
||||
xformOp == TJTransform.OP_ROT270) {
|
||||
if (_subsamp == TJ.SAMP_422)
|
||||
_subsamp = TJ.SAMP_440;
|
||||
else if (_subsamp == TJ.SAMP_440)
|
||||
_subsamp = TJ.SAMP_422;
|
||||
if (tsubsamp == TJ.SAMP_422)
|
||||
tsubsamp = TJ.SAMP_440;
|
||||
else if (tsubsamp == TJ.SAMP_440)
|
||||
tsubsamp = TJ.SAMP_422;
|
||||
}
|
||||
|
||||
TJTransform[] t = new TJTransform[_ntilesw * _ntilesh];
|
||||
TJTransform[] t = new TJTransform[tntilesw * tntilesh];
|
||||
jpegBuf =
|
||||
new byte[_ntilesw * _ntilesh][TJ.bufSize(_tilew, _tileh, subsamp)];
|
||||
new byte[tntilesw * tntilesh][TJ.bufSize(ttilew, ttileh, subsamp)];
|
||||
|
||||
for (y = 0, tile = 0; y < _h; y += _tileh) {
|
||||
for (x = 0; x < _w; x += _tilew, tile++) {
|
||||
for (y = 0, tile = 0; y < th; y += ttileh) {
|
||||
for (x = 0; x < tw; x += ttilew, tile++) {
|
||||
t[tile] = new TJTransform();
|
||||
t[tile].width = Math.min(_tilew, _w - x);
|
||||
t[tile].height = Math.min(_tileh, _h - y);
|
||||
t[tile].width = Math.min(ttilew, tw - x);
|
||||
t[tile].height = Math.min(ttileh, th - y);
|
||||
t[tile].x = x;
|
||||
t[tile].y = y;
|
||||
t[tile].op = xformOp;
|
||||
@@ -618,7 +621,7 @@ class TJBench {
|
||||
}
|
||||
t = null;
|
||||
|
||||
for (tile = 0, totalJpegSize = 0; tile < _ntilesw * _ntilesh; tile++)
|
||||
for (tile = 0, totalJpegSize = 0; tile < tntilesw * tntilesh; tile++)
|
||||
totalJpegSize += jpegSize[tile];
|
||||
|
||||
if (quiet != 0) {
|
||||
@@ -643,19 +646,19 @@ class TJBench {
|
||||
} else {
|
||||
if (quiet == 1)
|
||||
System.out.print("N/A N/A ");
|
||||
jpegBuf = new byte[1][TJ.bufSize(_tilew, _tileh, subsamp)];
|
||||
jpegBuf = new byte[1][TJ.bufSize(ttilew, ttileh, subsamp)];
|
||||
jpegSize = new int[1];
|
||||
jpegBuf[0] = srcBuf;
|
||||
jpegSize[0] = srcSize;
|
||||
}
|
||||
|
||||
if (w == tilew)
|
||||
_tilew = _w;
|
||||
ttilew = tw;
|
||||
if (h == tileh)
|
||||
_tileh = _h;
|
||||
ttileh = th;
|
||||
if ((xformOpt & TJTransform.OPT_NOOUTPUT) == 0)
|
||||
decomp(null, jpegBuf, jpegSize, null, _w, _h, _subsamp, 0,
|
||||
fileName, _tilew, _tileh);
|
||||
decomp(null, jpegBuf, jpegSize, null, tw, th, tsubsamp, 0,
|
||||
fileName, ttilew, ttileh);
|
||||
else if (quiet == 1)
|
||||
System.out.println("N/A");
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (C)2011-2012, 2014-2015, 2017 D. R. Commander.
|
||||
* All Rights Reserved.
|
||||
* Copyright (C)2011-2012, 2014-2015, 2017-2018 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:
|
||||
@@ -41,25 +41,28 @@ import javax.swing.*;
|
||||
import org.libjpegturbo.turbojpeg.*;
|
||||
|
||||
|
||||
@SuppressWarnings("checkstyle:JavadocType")
|
||||
public class TJExample implements TJCustomFilter {
|
||||
|
||||
private static final String classname = new TJExample().getClass().getName();
|
||||
private static final String CLASS_NAME =
|
||||
new TJExample().getClass().getName();
|
||||
|
||||
private static final int DEFAULT_SUBSAMP = TJ.SAMP_444;
|
||||
private static final int DEFAULT_QUALITY = 95;
|
||||
|
||||
|
||||
private static final String[] subsampName = {
|
||||
private static final String[] SUBSAMP_NAME = {
|
||||
"4:4:4", "4:2:2", "4:2:0", "Grayscale", "4:4:0", "4:1:1"
|
||||
};
|
||||
|
||||
private static final String[] colorspaceName = {
|
||||
private static final String[] COLORSPACE_NAME = {
|
||||
"RGB", "YCbCr", "GRAY", "CMYK", "YCCK"
|
||||
};
|
||||
|
||||
|
||||
/* DCT filter example. This produces a negative of the image. */
|
||||
|
||||
@SuppressWarnings("checkstyle:JavadocMethod")
|
||||
public void customFilter(ShortBuffer coeffBuffer, Rectangle bufferRegion,
|
||||
Rectangle planeRegion, int componentIndex,
|
||||
int transformIndex, TJTransform transform)
|
||||
@@ -71,7 +74,7 @@ public class TJExample implements TJCustomFilter {
|
||||
|
||||
|
||||
private static void usage() throws Exception {
|
||||
System.out.println("\nUSAGE: java [Java options] " + classname +
|
||||
System.out.println("\nUSAGE: java [Java options] " + CLASS_NAME +
|
||||
" <Input image> <Output image> [options]\n");
|
||||
|
||||
System.out.println("Input and output images can be in any image format that the Java Image I/O");
|
||||
@@ -85,7 +88,9 @@ public class TJExample implements TJCustomFilter {
|
||||
System.out.println(" compressing the output image. The default is to use the same level of");
|
||||
System.out.println(" subsampling as in the input image, if the input image is also a JPEG");
|
||||
System.out.println(" image, or to use grayscale if the input image is a grayscale non-JPEG");
|
||||
System.out.println(" image, or to use " + subsampName[DEFAULT_SUBSAMP] + " subsampling otherwise.\n");
|
||||
System.out.println(" image, or to use " +
|
||||
SUBSAMP_NAME[DEFAULT_SUBSAMP] +
|
||||
" subsampling otherwise.\n");
|
||||
|
||||
System.out.println("-q <1-100> = Compress the output image with this JPEG quality level");
|
||||
System.out.println(" (default = " + DEFAULT_QUALITY + ").\n");
|
||||
@@ -95,15 +100,15 @@ public class TJExample implements TJCustomFilter {
|
||||
|
||||
System.out.println("-scale M/N = Scale the input image by a factor of M/N when decompressing it.");
|
||||
System.out.print("(M/N = ");
|
||||
for (int i = 0; i < scalingFactors.length; i++) {
|
||||
System.out.print(scalingFactors[i].getNum() + "/" +
|
||||
scalingFactors[i].getDenom());
|
||||
if (scalingFactors.length == 2 && i != scalingFactors.length - 1)
|
||||
for (int i = 0; i < SCALING_FACTORS.length; i++) {
|
||||
System.out.print(SCALING_FACTORS[i].getNum() + "/" +
|
||||
SCALING_FACTORS[i].getDenom());
|
||||
if (SCALING_FACTORS.length == 2 && i != SCALING_FACTORS.length - 1)
|
||||
System.out.print(" or ");
|
||||
else if (scalingFactors.length > 2) {
|
||||
if (i != scalingFactors.length - 1)
|
||||
else if (SCALING_FACTORS.length > 2) {
|
||||
if (i != SCALING_FACTORS.length - 1)
|
||||
System.out.print(", ");
|
||||
if (i == scalingFactors.length - 2)
|
||||
if (i == SCALING_FACTORS.length - 2)
|
||||
System.out.print("or ");
|
||||
}
|
||||
}
|
||||
@@ -177,9 +182,9 @@ public class TJExample implements TJCustomFilter {
|
||||
TJScalingFactor tempsf =
|
||||
new TJScalingFactor(Integer.parseInt(scaleArg[0]),
|
||||
Integer.parseInt(scaleArg[1]));
|
||||
for (int j = 0; j < scalingFactors.length; j++) {
|
||||
if (tempsf.equals(scalingFactors[j])) {
|
||||
scalingFactor = scalingFactors[j];
|
||||
for (int j = 0; j < SCALING_FACTORS.length; j++) {
|
||||
if (tempsf.equals(SCALING_FACTORS[j])) {
|
||||
scalingFactor = SCALING_FACTORS[j];
|
||||
match = 1;
|
||||
break;
|
||||
}
|
||||
@@ -302,8 +307,8 @@ public class TJExample implements TJCustomFilter {
|
||||
|
||||
System.out.println((doTransform ? "Transformed" : "Input") +
|
||||
" Image (jpg): " + width + " x " + height +
|
||||
" pixels, " + subsampName[inSubsamp] +
|
||||
" subsampling, " + colorspaceName[inColorspace]);
|
||||
" pixels, " + SUBSAMP_NAME[inSubsamp] +
|
||||
" subsampling, " + COLORSPACE_NAME[inColorspace]);
|
||||
|
||||
if (outFormat.equalsIgnoreCase("jpg") && doTransform &&
|
||||
scalingFactor.isOne() && outSubsamp < 0 && outQual < 0) {
|
||||
@@ -362,7 +367,7 @@ public class TJExample implements TJCustomFilter {
|
||||
/* Output image format is JPEG. Compress the uncompressed image. */
|
||||
if (outQual < 0)
|
||||
outQual = DEFAULT_QUALITY;
|
||||
System.out.println(", " + subsampName[outSubsamp] +
|
||||
System.out.println(", " + SUBSAMP_NAME[outSubsamp] +
|
||||
" subsampling, quality = " + outQual);
|
||||
|
||||
TJCompressor tjc = new TJCompressor();
|
||||
@@ -395,5 +400,6 @@ public class TJExample implements TJCustomFilter {
|
||||
}
|
||||
}
|
||||
|
||||
private static final TJScalingFactor[] scalingFactors = TJ.getScalingFactors();
|
||||
private static final TJScalingFactor[] SCALING_FACTORS =
|
||||
TJ.getScalingFactors();
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C)2011-2017 D. R. Commander. All Rights Reserved.
|
||||
* Copyright (C)2011-2018 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:
|
||||
@@ -37,13 +37,16 @@ import javax.imageio.*;
|
||||
import java.nio.*;
|
||||
import org.libjpegturbo.turbojpeg.*;
|
||||
|
||||
public class TJUnitTest {
|
||||
@SuppressWarnings("checkstyle:JavadocType")
|
||||
public final class TJUnitTest {
|
||||
|
||||
private static final String classname =
|
||||
private TJUnitTest() {}
|
||||
|
||||
private static final String CLASS_NAME =
|
||||
new TJUnitTest().getClass().getName();
|
||||
|
||||
private static void usage() {
|
||||
System.out.println("\nUSAGE: java " + classname + " [options]\n");
|
||||
System.out.println("\nUSAGE: java " + CLASS_NAME + " [options]\n");
|
||||
System.out.println("Options:");
|
||||
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");
|
||||
@@ -52,39 +55,39 @@ public class TJUnitTest {
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
private static final String[] subNameLong = {
|
||||
private static final String[] SUBNAME_LONG = {
|
||||
"4:4:4", "4:2:2", "4:2:0", "GRAY", "4:4:0", "4:1:1"
|
||||
};
|
||||
private static final String[] subName = {
|
||||
private static final String[] SUBNAME = {
|
||||
"444", "422", "420", "GRAY", "440", "411"
|
||||
};
|
||||
|
||||
private static final String[] pixFormatStr = {
|
||||
private static final String[] PIXFORMATSTR = {
|
||||
"RGB", "BGR", "RGBX", "BGRX", "XBGR", "XRGB", "Grayscale",
|
||||
"RGBA", "BGRA", "ABGR", "ARGB", "CMYK"
|
||||
};
|
||||
|
||||
private static final int[] _3byteFormats = {
|
||||
private static final int[] FORMATS_3BYTE = {
|
||||
TJ.PF_RGB, TJ.PF_BGR
|
||||
};
|
||||
private static final int[] _3byteFormatsBI = {
|
||||
private static final int[] FORMATS_3BYTEBI = {
|
||||
BufferedImage.TYPE_3BYTE_BGR
|
||||
};
|
||||
private static final int[] _4byteFormats = {
|
||||
private static final int[] FORMATS_4BYTE = {
|
||||
TJ.PF_RGBX, TJ.PF_BGRX, TJ.PF_XBGR, TJ.PF_XRGB, TJ.PF_CMYK
|
||||
};
|
||||
private static final int[] _4byteFormatsBI = {
|
||||
private static final int[] FORMATS_4BYTEBI = {
|
||||
BufferedImage.TYPE_INT_BGR, BufferedImage.TYPE_INT_RGB,
|
||||
BufferedImage.TYPE_4BYTE_ABGR, BufferedImage.TYPE_4BYTE_ABGR_PRE,
|
||||
BufferedImage.TYPE_INT_ARGB, BufferedImage.TYPE_INT_ARGB_PRE
|
||||
};
|
||||
private static final int[] onlyGray = {
|
||||
private static final int[] FORMATS_GRAY = {
|
||||
TJ.PF_GRAY
|
||||
};
|
||||
private static final int[] onlyGrayBI = {
|
||||
private static final int[] FORMATS_GRAYBI = {
|
||||
BufferedImage.TYPE_BYTE_GRAY
|
||||
};
|
||||
private static final int[] onlyRGB = {
|
||||
private static final int[] FORMATS_RGB = {
|
||||
TJ.PF_RGB
|
||||
};
|
||||
|
||||
@@ -111,8 +114,9 @@ public class TJUnitTest {
|
||||
case BufferedImage.TYPE_INT_ARGB:
|
||||
case BufferedImage.TYPE_INT_ARGB_PRE:
|
||||
return TJ.PF_BGRA;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static String biTypeStr(int biType) {
|
||||
@@ -133,8 +137,9 @@ public class TJUnitTest {
|
||||
return "INT_ARGB";
|
||||
case BufferedImage.TYPE_INT_ARGB_PRE:
|
||||
return "INT_ARGB_PRE";
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
return "Unknown";
|
||||
}
|
||||
|
||||
private static void initBuf(byte[] buf, int w, int pitch, int h, int pf,
|
||||
@@ -519,7 +524,7 @@ public class TJUnitTest {
|
||||
}
|
||||
}
|
||||
|
||||
private static int PAD(int v, int p) {
|
||||
private static int pad(int v, int p) {
|
||||
return ((v + (p) - 1) & (~((p) - 1)));
|
||||
}
|
||||
|
||||
@@ -528,9 +533,9 @@ public class TJUnitTest {
|
||||
throws Exception {
|
||||
int row, col;
|
||||
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);
|
||||
int cw = pw / hsf, ch = ph / vsf;
|
||||
int ypitch = PAD(pw, pad), uvpitch = PAD(cw, pad);
|
||||
int ypitch = pad(pw, pad), uvpitch = pad(cw, pad);
|
||||
int retval = 1;
|
||||
int correctsize = ypitch * ph +
|
||||
(subsamp == TJ.SAMP_GRAY ? 0 : uvpitch * ch * 2);
|
||||
@@ -639,9 +644,9 @@ public class TJUnitTest {
|
||||
if (bi) {
|
||||
pf = biTypePF(imgType);
|
||||
pfStr = biTypeStr(imgType);
|
||||
pfStrLong = pfStr + " (" + pixFormatStr[pf] + ")";
|
||||
pfStrLong = pfStr + " (" + PIXFORMATSTR[pf] + ")";
|
||||
} else {
|
||||
pfStr = pixFormatStr[pf];
|
||||
pfStr = PIXFORMATSTR[pf];
|
||||
pfStrLong = pfStr;
|
||||
}
|
||||
ps = TJ.getPixelSize(pf);
|
||||
@@ -650,7 +655,7 @@ public class TJUnitTest {
|
||||
img = new BufferedImage(w, h, imgType);
|
||||
initImg(img, pf, flags);
|
||||
tempStr = baseName + "_enc_" + pfStr + "_" + buStr + "_" +
|
||||
subName[subsamp] + "_Q" + jpegQual + ".png";
|
||||
SUBNAME[subsamp] + "_Q" + jpegQual + ".png";
|
||||
File file = new File(tempStr);
|
||||
ImageIO.write(img, "png", file);
|
||||
tjc.setSourceImage(img, 0, 0, 0, 0);
|
||||
@@ -665,7 +670,7 @@ public class TJUnitTest {
|
||||
tjc.setJPEGQuality(jpegQual);
|
||||
if (doYUV) {
|
||||
System.out.format("%s %s -> YUV %s ... ", pfStrLong, buStrLong,
|
||||
subNameLong[subsamp]);
|
||||
SUBNAME_LONG[subsamp]);
|
||||
YUVImage yuvImage = tjc.encodeYUV(pad, flags);
|
||||
if (checkBufYUV(yuvImage.getBuf(), yuvImage.getSize(), w, h, subsamp,
|
||||
new TJScalingFactor(1, 1)) == 1)
|
||||
@@ -675,18 +680,18 @@ public class TJUnitTest {
|
||||
exitStatus = -1;
|
||||
}
|
||||
|
||||
System.out.format("YUV %s %s -> JPEG Q%d ... ", subNameLong[subsamp],
|
||||
System.out.format("YUV %s %s -> JPEG Q%d ... ", SUBNAME_LONG[subsamp],
|
||||
buStrLong, jpegQual);
|
||||
tjc.setSourceImage(yuvImage);
|
||||
} else {
|
||||
System.out.format("%s %s -> %s Q%d ... ", pfStrLong, buStrLong,
|
||||
subNameLong[subsamp], jpegQual);
|
||||
SUBNAME_LONG[subsamp], jpegQual);
|
||||
}
|
||||
tjc.compress(dstBuf, flags);
|
||||
size = tjc.getCompressedSize();
|
||||
|
||||
tempStr = baseName + "_enc_" + pfStr + "_" + buStr + "_" +
|
||||
subName[subsamp] + "_Q" + jpegQual + ".jpg";
|
||||
SUBNAME[subsamp] + "_Q" + jpegQual + ".jpg";
|
||||
writeJPEG(dstBuf, size, tempStr);
|
||||
System.out.println("Done.\n Result in " + tempStr);
|
||||
|
||||
@@ -709,9 +714,9 @@ public class TJUnitTest {
|
||||
if (bi) {
|
||||
pf = biTypePF(imgType);
|
||||
pfStr = biTypeStr(imgType);
|
||||
pfStrLong = pfStr + " (" + pixFormatStr[pf] + ")";
|
||||
pfStrLong = pfStr + " (" + PIXFORMATSTR[pf] + ")";
|
||||
} else {
|
||||
pfStr = pixFormatStr[pf];
|
||||
pfStr = PIXFORMATSTR[pf];
|
||||
pfStrLong = pfStr;
|
||||
}
|
||||
|
||||
@@ -728,7 +733,7 @@ public class TJUnitTest {
|
||||
throw new Exception("Scaled size mismatch");
|
||||
|
||||
if (doYUV) {
|
||||
System.out.format("JPEG -> YUV %s ", subNameLong[subsamp]);
|
||||
System.out.format("JPEG -> YUV %s ", SUBNAME_LONG[subsamp]);
|
||||
if (!sf.isOne())
|
||||
System.out.format("%d/%d ... ", sf.getNum(), sf.getDenom());
|
||||
else System.out.print("... ");
|
||||
@@ -741,7 +746,7 @@ public class TJUnitTest {
|
||||
System.out.print("FAILED!\n"); exitStatus = -1;
|
||||
}
|
||||
|
||||
System.out.format("YUV %s -> %s %s ... ", subNameLong[subsamp],
|
||||
System.out.format("YUV %s -> %s %s ... ", SUBNAME_LONG[subsamp],
|
||||
pfStrLong, buStrLong);
|
||||
tjd.setSourceImage(yuvImage);
|
||||
} else {
|
||||
@@ -758,7 +763,7 @@ public class TJUnitTest {
|
||||
if (bi) {
|
||||
tempStr = baseName + "_dec_" + pfStr + "_" +
|
||||
(((flags & TJ.FLAG_BOTTOMUP) != 0) ? "BU" : "TD") + "_" +
|
||||
subName[subsamp] + "_" +
|
||||
SUBNAME[subsamp] + "_" +
|
||||
(double)sf.getNum() / (double)sf.getDenom() + "x" + ".png";
|
||||
File file = new File(tempStr);
|
||||
ImageIO.write(img, "png", file);
|
||||
@@ -911,44 +916,45 @@ public class TJUnitTest {
|
||||
usage();
|
||||
}
|
||||
if (doYUV)
|
||||
_4byteFormats[4] = -1;
|
||||
doTest(35, 39, bi ? _3byteFormatsBI : _3byteFormats, TJ.SAMP_444,
|
||||
FORMATS_4BYTE[4] = -1;
|
||||
doTest(35, 39, bi ? FORMATS_3BYTEBI : FORMATS_3BYTE, TJ.SAMP_444,
|
||||
testName);
|
||||
doTest(39, 41, bi ? _4byteFormatsBI : _4byteFormats, TJ.SAMP_444,
|
||||
doTest(39, 41, bi ? FORMATS_4BYTEBI : FORMATS_4BYTE, TJ.SAMP_444,
|
||||
testName);
|
||||
doTest(41, 35, bi ? _3byteFormatsBI : _3byteFormats, TJ.SAMP_422,
|
||||
doTest(41, 35, bi ? FORMATS_3BYTEBI : FORMATS_3BYTE, TJ.SAMP_422,
|
||||
testName);
|
||||
doTest(35, 39, bi ? _4byteFormatsBI : _4byteFormats, TJ.SAMP_422,
|
||||
doTest(35, 39, bi ? FORMATS_4BYTEBI : FORMATS_4BYTE, TJ.SAMP_422,
|
||||
testName);
|
||||
doTest(39, 41, bi ? _3byteFormatsBI : _3byteFormats, TJ.SAMP_420,
|
||||
doTest(39, 41, bi ? FORMATS_3BYTEBI : FORMATS_3BYTE, TJ.SAMP_420,
|
||||
testName);
|
||||
doTest(41, 35, bi ? _4byteFormatsBI : _4byteFormats, TJ.SAMP_420,
|
||||
doTest(41, 35, bi ? FORMATS_4BYTEBI : FORMATS_4BYTE, TJ.SAMP_420,
|
||||
testName);
|
||||
doTest(35, 39, bi ? _3byteFormatsBI : _3byteFormats, TJ.SAMP_440,
|
||||
doTest(35, 39, bi ? FORMATS_3BYTEBI : FORMATS_3BYTE, TJ.SAMP_440,
|
||||
testName);
|
||||
doTest(39, 41, bi ? _4byteFormatsBI : _4byteFormats, TJ.SAMP_440,
|
||||
doTest(39, 41, bi ? FORMATS_4BYTEBI : FORMATS_4BYTE, TJ.SAMP_440,
|
||||
testName);
|
||||
doTest(41, 35, bi ? _3byteFormatsBI : _3byteFormats, TJ.SAMP_411,
|
||||
doTest(41, 35, bi ? FORMATS_3BYTEBI : FORMATS_3BYTE, TJ.SAMP_411,
|
||||
testName);
|
||||
doTest(35, 39, bi ? _4byteFormatsBI : _4byteFormats, TJ.SAMP_411,
|
||||
doTest(35, 39, bi ? FORMATS_4BYTEBI : FORMATS_4BYTE, TJ.SAMP_411,
|
||||
testName);
|
||||
doTest(39, 41, bi ? onlyGrayBI : onlyGray, TJ.SAMP_GRAY, testName);
|
||||
doTest(41, 35, bi ? _3byteFormatsBI : _3byteFormats, TJ.SAMP_GRAY,
|
||||
doTest(39, 41, bi ? FORMATS_GRAYBI : FORMATS_GRAY, TJ.SAMP_GRAY,
|
||||
testName);
|
||||
_4byteFormats[4] = -1;
|
||||
doTest(35, 39, bi ? _4byteFormatsBI : _4byteFormats, TJ.SAMP_GRAY,
|
||||
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) {
|
||||
System.out.print("\n--------------------\n\n");
|
||||
doTest(48, 48, onlyRGB, TJ.SAMP_444, "javatest_yuv0");
|
||||
doTest(48, 48, onlyRGB, TJ.SAMP_422, "javatest_yuv0");
|
||||
doTest(48, 48, onlyRGB, TJ.SAMP_420, "javatest_yuv0");
|
||||
doTest(48, 48, onlyRGB, TJ.SAMP_440, "javatest_yuv0");
|
||||
doTest(48, 48, onlyRGB, TJ.SAMP_411, "javatest_yuv0");
|
||||
doTest(48, 48, onlyRGB, TJ.SAMP_GRAY, "javatest_yuv0");
|
||||
doTest(48, 48, onlyGray, TJ.SAMP_GRAY, "javatest_yuv0");
|
||||
doTest(48, 48, FORMATS_RGB, TJ.SAMP_444, "javatest_yuv0");
|
||||
doTest(48, 48, FORMATS_RGB, TJ.SAMP_422, "javatest_yuv0");
|
||||
doTest(48, 48, FORMATS_RGB, TJ.SAMP_420, "javatest_yuv0");
|
||||
doTest(48, 48, FORMATS_RGB, TJ.SAMP_440, "javatest_yuv0");
|
||||
doTest(48, 48, FORMATS_RGB, TJ.SAMP_411, "javatest_yuv0");
|
||||
doTest(48, 48, FORMATS_RGB, TJ.SAMP_GRAY, "javatest_yuv0");
|
||||
doTest(48, 48, FORMATS_GRAY, TJ.SAMP_GRAY, "javatest_yuv0");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -810,8 +810,6 @@
|
||||
<dd>
|
||||
<div class="block">TurboJPEG utility class (cannot be instantiated)</div>
|
||||
</dd>
|
||||
<dt><span class="strong"><a href="./org/libjpegturbo/turbojpeg/TJ.html#TJ()">TJ()</a></span> - Constructor for class org.libjpegturbo.turbojpeg.<a href="./org/libjpegturbo/turbojpeg/TJ.html" title="class in org.libjpegturbo.turbojpeg">TJ</a></dt>
|
||||
<dd> </dd>
|
||||
<dt><a href="./org/libjpegturbo/turbojpeg/TJCompressor.html" title="class in org.libjpegturbo.turbojpeg"><span class="strong">TJCompressor</span></a> - Class in <a href="./org/libjpegturbo/turbojpeg/package-summary.html">org.libjpegturbo.turbojpeg</a></dt>
|
||||
<dd>
|
||||
<div class="block">TurboJPEG compressor</div>
|
||||
@@ -885,7 +883,9 @@
|
||||
<div class="block">Fractional scaling factor</div>
|
||||
</dd>
|
||||
<dt><span class="strong"><a href="./org/libjpegturbo/turbojpeg/TJScalingFactor.html#TJScalingFactor(int,%20int)">TJScalingFactor(int, int)</a></span> - Constructor for class org.libjpegturbo.turbojpeg.<a href="./org/libjpegturbo/turbojpeg/TJScalingFactor.html" title="class in org.libjpegturbo.turbojpeg">TJScalingFactor</a></dt>
|
||||
<dd> </dd>
|
||||
<dd>
|
||||
<div class="block">Create a TurboJPEG scaling factor instance.</div>
|
||||
</dd>
|
||||
<dt><a href="./org/libjpegturbo/turbojpeg/TJTransform.html" title="class in org.libjpegturbo.turbojpeg"><span class="strong">TJTransform</span></a> - Class in <a href="./org/libjpegturbo/turbojpeg/package-summary.html">org.libjpegturbo.turbojpeg</a></dt>
|
||||
<dd>
|
||||
<div class="block">Lossless transform parameters</div>
|
||||
|
||||
@@ -63,13 +63,13 @@
|
||||
<li>Summary: </li>
|
||||
<li>Nested | </li>
|
||||
<li><a href="#field_summary">Field</a> | </li>
|
||||
<li><a href="#constructor_summary">Constr</a> | </li>
|
||||
<li>Constr | </li>
|
||||
<li><a href="#method_summary">Method</a></li>
|
||||
</ul>
|
||||
<ul class="subNavList">
|
||||
<li>Detail: </li>
|
||||
<li><a href="#field_detail">Field</a> | </li>
|
||||
<li><a href="#constructor_detail">Constr</a> | </li>
|
||||
<li>Constr | </li>
|
||||
<li><a href="#method_detail">Method</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
@@ -361,23 +361,6 @@ extends java.lang.Object</pre>
|
||||
</table>
|
||||
</li>
|
||||
</ul>
|
||||
<!-- ======== CONSTRUCTOR SUMMARY ======== -->
|
||||
<ul class="blockList">
|
||||
<li class="blockList"><a name="constructor_summary">
|
||||
<!-- -->
|
||||
</a>
|
||||
<h3>Constructor Summary</h3>
|
||||
<table class="overviewSummary" border="0" cellpadding="3" cellspacing="0" summary="Constructor Summary table, listing constructors, and an explanation">
|
||||
<caption><span>Constructors</span><span class="tabEnd"> </span></caption>
|
||||
<tr>
|
||||
<th class="colOne" scope="col">Constructor and Description</th>
|
||||
</tr>
|
||||
<tr class="altColor">
|
||||
<td class="colOne"><code><strong><a href="../../../org/libjpegturbo/turbojpeg/TJ.html#TJ()">TJ</a></strong>()</code> </td>
|
||||
</tr>
|
||||
</table>
|
||||
</li>
|
||||
</ul>
|
||||
<!-- ========== METHOD SUMMARY =========== -->
|
||||
<ul class="blockList">
|
||||
<li class="blockList"><a name="method_summary">
|
||||
@@ -1070,23 +1053,6 @@ public static final int FLAG_FORCESSE3</pre>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
<!-- ========= CONSTRUCTOR DETAIL ======== -->
|
||||
<ul class="blockList">
|
||||
<li class="blockList"><a name="constructor_detail">
|
||||
<!-- -->
|
||||
</a>
|
||||
<h3>Constructor Detail</h3>
|
||||
<a name="TJ()">
|
||||
<!-- -->
|
||||
</a>
|
||||
<ul class="blockListLast">
|
||||
<li class="blockList">
|
||||
<h4>TJ</h4>
|
||||
<pre>public TJ()</pre>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
<!-- ============ METHOD DETAIL ========== -->
|
||||
<ul class="blockList">
|
||||
<li class="blockList"><a name="method_detail">
|
||||
@@ -1372,13 +1338,13 @@ public static int bufSizeYUV(int width,
|
||||
<li>Summary: </li>
|
||||
<li>Nested | </li>
|
||||
<li><a href="#field_summary">Field</a> | </li>
|
||||
<li><a href="#constructor_summary">Constr</a> | </li>
|
||||
<li>Constr | </li>
|
||||
<li><a href="#method_summary">Method</a></li>
|
||||
</ul>
|
||||
<ul class="subNavList">
|
||||
<li>Detail: </li>
|
||||
<li><a href="#field_detail">Field</a> | </li>
|
||||
<li><a href="#constructor_detail">Constr</a> | </li>
|
||||
<li>Constr | </li>
|
||||
<li><a href="#method_detail">Method</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@@ -118,7 +118,9 @@ extends java.lang.Object</pre>
|
||||
</tr>
|
||||
<tr class="altColor">
|
||||
<td class="colOne"><code><strong><a href="../../../org/libjpegturbo/turbojpeg/TJScalingFactor.html#TJScalingFactor(int,%20int)">TJScalingFactor</a></strong>(int num,
|
||||
int denom)</code> </td>
|
||||
int denom)</code>
|
||||
<div class="block">Create a TurboJPEG scaling factor instance.</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</li>
|
||||
@@ -197,6 +199,8 @@ extends java.lang.Object</pre>
|
||||
<h4>TJScalingFactor</h4>
|
||||
<pre>public TJScalingFactor(int num,
|
||||
int denom)</pre>
|
||||
<div class="block">Create a TurboJPEG scaling factor instance.</div>
|
||||
<dl><dt><span class="strong">Parameters:</span></dt><dd><code>num</code> - numerator</dd><dd><code>denom</code> - denominator</dd></dl>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
@@ -239,7 +243,8 @@ extends java.lang.Object</pre>
|
||||
<div class="block">Returns the scaled value of <code>dimension</code>. This function
|
||||
performs the integer equivalent of
|
||||
<code>ceil(dimension * scalingFactor)</code>.</div>
|
||||
<dl><dt><span class="strong">Returns:</span></dt><dd>the scaled value of <code>dimension</code>.</dd></dl>
|
||||
<dl><dt><span class="strong">Parameters:</span></dt><dd><code>dimension</code> - width or height to multiply by this scaling factor</dd>
|
||||
<dt><span class="strong">Returns:</span></dt><dd>the scaled value of <code>dimension</code>.</dd></dl>
|
||||
</li>
|
||||
</ul>
|
||||
<a name="equals(org.libjpegturbo.turbojpeg.TJScalingFactor)">
|
||||
@@ -251,7 +256,8 @@ extends java.lang.Object</pre>
|
||||
<pre>public boolean equals(<a href="../../../org/libjpegturbo/turbojpeg/TJScalingFactor.html" title="class in org.libjpegturbo.turbojpeg">TJScalingFactor</a> other)</pre>
|
||||
<div class="block">Returns true or false, depending on whether this instance and
|
||||
<code>other</code> have the same numerator and denominator.</div>
|
||||
<dl><dt><span class="strong">Returns:</span></dt><dd>true or false, depending on whether this instance and
|
||||
<dl><dt><span class="strong">Parameters:</span></dt><dd><code>other</code> - the scaling factor against which to compare this one</dd>
|
||||
<dt><span class="strong">Returns:</span></dt><dd>true or false, depending on whether this instance and
|
||||
<code>other</code> have the same numerator and denominator.</dd></dl>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C)2011-2013, 2017 D. R. Commander. All Rights Reserved.
|
||||
* Copyright (C)2011-2013, 2017-2018 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
|
||||
@@ -34,6 +34,8 @@ package org.libjpegturbo.turbojpeg;
|
||||
*/
|
||||
public final class TJ {
|
||||
|
||||
private TJ() {}
|
||||
|
||||
/**
|
||||
* The number of chrominance subsampling options
|
||||
*/
|
||||
@@ -89,10 +91,10 @@ public final class TJ {
|
||||
*/
|
||||
public static int getMCUWidth(int subsamp) {
|
||||
checkSubsampling(subsamp);
|
||||
return mcuWidth[subsamp];
|
||||
return MCU_WIDTH[subsamp];
|
||||
}
|
||||
|
||||
private static final int[] mcuWidth = {
|
||||
private static final int[] MCU_WIDTH = {
|
||||
8, 16, 16, 8, 8, 32
|
||||
};
|
||||
|
||||
@@ -109,10 +111,10 @@ public final class TJ {
|
||||
*/
|
||||
public static int getMCUHeight(int subsamp) {
|
||||
checkSubsampling(subsamp);
|
||||
return mcuHeight[subsamp];
|
||||
return MCU_HEIGHT[subsamp];
|
||||
}
|
||||
|
||||
private static final int[] mcuHeight = {
|
||||
private static final int[] MCU_HEIGHT = {
|
||||
8, 8, 16, 8, 16, 8
|
||||
};
|
||||
|
||||
@@ -217,10 +219,10 @@ public final class TJ {
|
||||
*/
|
||||
public static int getPixelSize(int pixelFormat) {
|
||||
checkPixelFormat(pixelFormat);
|
||||
return pixelSize[pixelFormat];
|
||||
return PIXEL_SIZE[pixelFormat];
|
||||
}
|
||||
|
||||
private static final int[] pixelSize = {
|
||||
private static final int[] PIXEL_SIZE = {
|
||||
3, 3, 4, 4, 4, 4, 1, 4, 4, 4, 4, 4
|
||||
};
|
||||
|
||||
@@ -239,10 +241,10 @@ public final class TJ {
|
||||
*/
|
||||
public static int getRedOffset(int pixelFormat) {
|
||||
checkPixelFormat(pixelFormat);
|
||||
return redOffset[pixelFormat];
|
||||
return RED_OFFSET[pixelFormat];
|
||||
}
|
||||
|
||||
private static final int[] redOffset = {
|
||||
private static final int[] RED_OFFSET = {
|
||||
0, 2, 0, 2, 3, 1, -1, 0, 2, 3, 1, -1
|
||||
};
|
||||
|
||||
@@ -261,10 +263,10 @@ public final class TJ {
|
||||
*/
|
||||
public static int getGreenOffset(int pixelFormat) {
|
||||
checkPixelFormat(pixelFormat);
|
||||
return greenOffset[pixelFormat];
|
||||
return GREEN_OFFSET[pixelFormat];
|
||||
}
|
||||
|
||||
private static final int[] greenOffset = {
|
||||
private static final int[] GREEN_OFFSET = {
|
||||
1, 1, 1, 1, 2, 2, -1, 1, 1, 2, 2, -1
|
||||
};
|
||||
|
||||
@@ -283,10 +285,10 @@ public final class TJ {
|
||||
*/
|
||||
public static int getBlueOffset(int pixelFormat) {
|
||||
checkPixelFormat(pixelFormat);
|
||||
return blueOffset[pixelFormat];
|
||||
return BLUE_OFFSET[pixelFormat];
|
||||
}
|
||||
|
||||
private static final int[] blueOffset = {
|
||||
private static final int[] BLUE_OFFSET = {
|
||||
2, 0, 2, 0, 1, 3, -1, 2, 0, 1, 3, -1
|
||||
};
|
||||
|
||||
@@ -305,10 +307,10 @@ public final class TJ {
|
||||
*/
|
||||
public static int getAlphaOffset(int pixelFormat) {
|
||||
checkPixelFormat(pixelFormat);
|
||||
return alphaOffset[pixelFormat];
|
||||
return ALPHA_OFFSET[pixelFormat];
|
||||
}
|
||||
|
||||
private static final int[] alphaOffset = {
|
||||
private static final int[] ALPHA_OFFSET = {
|
||||
-1, -1, -1, -1, -1, -1, -1, 3, 3, 0, 0, -1
|
||||
};
|
||||
|
||||
@@ -340,6 +342,7 @@ public final class TJ {
|
||||
* can be compressed from and decompressed to any of the extended RGB pixel
|
||||
* formats or grayscale, or they can be decompressed to YUV planar images.
|
||||
*/
|
||||
@SuppressWarnings("checkstyle:ConstantName")
|
||||
public static final int CS_YCbCr = 1;
|
||||
/**
|
||||
* Grayscale colorspace. The JPEG image retains only the luminance data (Y
|
||||
@@ -374,12 +377,16 @@ public final class TJ {
|
||||
*/
|
||||
public static final int FLAG_BOTTOMUP = 2;
|
||||
|
||||
@SuppressWarnings("checkstyle:JavadocVariable")
|
||||
@Deprecated
|
||||
public static final int FLAG_FORCEMMX = 8;
|
||||
@SuppressWarnings("checkstyle:JavadocVariable")
|
||||
@Deprecated
|
||||
public static final int FLAG_FORCESSE = 16;
|
||||
@SuppressWarnings("checkstyle:JavadocVariable")
|
||||
@Deprecated
|
||||
public static final int FLAG_FORCESSE2 = 32;
|
||||
@SuppressWarnings("checkstyle:JavadocVariable")
|
||||
@Deprecated
|
||||
public static final int FLAG_FORCESSE3 = 128;
|
||||
|
||||
@@ -490,6 +497,7 @@ public final class TJ {
|
||||
/**
|
||||
* @deprecated Use {@link #bufSizeYUV(int, int, int, int)} instead.
|
||||
*/
|
||||
@SuppressWarnings("checkstyle:JavadocMethod")
|
||||
@Deprecated
|
||||
public static native int bufSizeYUV(int width, int height, int subsamp);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C)2011-2015 D. R. Commander. All Rights Reserved.
|
||||
* Copyright (C)2011-2015, 2018 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
|
||||
@@ -77,6 +77,7 @@ public class TJCompressor implements Closeable {
|
||||
* @deprecated Use
|
||||
* {@link #TJCompressor(byte[], int, int, int, int, int, int)} instead.
|
||||
*/
|
||||
@SuppressWarnings("checkstyle:JavadocMethod")
|
||||
@Deprecated
|
||||
public TJCompressor(byte[] srcImage, int width, int pitch, int height,
|
||||
int pixelFormat) throws TJException {
|
||||
@@ -164,6 +165,7 @@ public class TJCompressor implements Closeable {
|
||||
* @deprecated Use
|
||||
* {@link #setSourceImage(byte[], int, int, int, int, int, int)} instead.
|
||||
*/
|
||||
@SuppressWarnings("checkstyle:JavadocMethod")
|
||||
@Deprecated
|
||||
public void setSourceImage(byte[] srcImage, int width, int pitch,
|
||||
int height, int pixelFormat) throws TJException {
|
||||
@@ -386,6 +388,7 @@ public class TJCompressor implements Closeable {
|
||||
* {@link #setSourceImage(BufferedImage, int, int, int, int)} and
|
||||
* {@link #compress(byte[], int)} instead.
|
||||
*/
|
||||
@SuppressWarnings("checkstyle:JavadocMethod")
|
||||
@Deprecated
|
||||
public void compress(BufferedImage srcImage, byte[] dstBuf, int flags)
|
||||
throws TJException {
|
||||
@@ -398,6 +401,7 @@ public class TJCompressor implements Closeable {
|
||||
* {@link #setSourceImage(BufferedImage, int, int, int, int)} and
|
||||
* {@link #compress(int)} instead.
|
||||
*/
|
||||
@SuppressWarnings("checkstyle:JavadocMethod")
|
||||
@Deprecated
|
||||
public byte[] compress(BufferedImage srcImage, int flags)
|
||||
throws TJException {
|
||||
@@ -445,14 +449,16 @@ public class TJCompressor implements Closeable {
|
||||
/**
|
||||
* @deprecated Use {@link #encodeYUV(YUVImage, int)} instead.
|
||||
*/
|
||||
@SuppressWarnings("checkstyle:JavadocMethod")
|
||||
@Deprecated
|
||||
public void encodeYUV(byte[] dstBuf, int flags) throws TJException {
|
||||
if (dstBuf == null)
|
||||
throw new IllegalArgumentException("Invalid argument in encodeYUV()");
|
||||
checkSourceImage();
|
||||
checkSubsampling();
|
||||
YUVImage yuvImage = new YUVImage(dstBuf, srcWidth, 4, srcHeight, subsamp);
|
||||
encodeYUV(yuvImage, flags);
|
||||
YUVImage dstYUVImage = new YUVImage(dstBuf, srcWidth, 4, srcHeight,
|
||||
subsamp);
|
||||
encodeYUV(dstYUVImage, flags);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -477,9 +483,9 @@ public class TJCompressor implements Closeable {
|
||||
checkSubsampling();
|
||||
if (pad < 1 || ((pad & (pad - 1)) != 0))
|
||||
throw new IllegalStateException("Invalid argument in encodeYUV()");
|
||||
YUVImage yuvImage = new YUVImage(srcWidth, pad, srcHeight, subsamp);
|
||||
encodeYUV(yuvImage, flags);
|
||||
return yuvImage;
|
||||
YUVImage dstYUVImage = new YUVImage(srcWidth, pad, srcHeight, subsamp);
|
||||
encodeYUV(dstYUVImage, flags);
|
||||
return dstYUVImage;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -506,21 +512,22 @@ public class TJCompressor implements Closeable {
|
||||
public YUVImage encodeYUV(int[] strides, int flags) throws TJException {
|
||||
checkSourceImage();
|
||||
checkSubsampling();
|
||||
YUVImage yuvImage = new YUVImage(srcWidth, strides, srcHeight, subsamp);
|
||||
encodeYUV(yuvImage, flags);
|
||||
return yuvImage;
|
||||
YUVImage dstYUVImage = new YUVImage(srcWidth, strides, srcHeight, subsamp);
|
||||
encodeYUV(dstYUVImage, flags);
|
||||
return dstYUVImage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #encodeYUV(int, int)} instead.
|
||||
*/
|
||||
@SuppressWarnings("checkstyle:JavadocMethod")
|
||||
@Deprecated
|
||||
public byte[] encodeYUV(int flags) throws TJException {
|
||||
checkSourceImage();
|
||||
checkSubsampling();
|
||||
YUVImage yuvImage = new YUVImage(srcWidth, 4, srcHeight, subsamp);
|
||||
encodeYUV(yuvImage, flags);
|
||||
return yuvImage.getBuf();
|
||||
YUVImage dstYUVImage = new YUVImage(srcWidth, 4, srcHeight, subsamp);
|
||||
encodeYUV(dstYUVImage, flags);
|
||||
return dstYUVImage.getBuf();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -528,6 +535,7 @@ public class TJCompressor implements Closeable {
|
||||
* {@link #setSourceImage(BufferedImage, int, int, int, int)} and
|
||||
* {@link #encodeYUV(byte[], int)} instead.
|
||||
*/
|
||||
@SuppressWarnings("checkstyle:JavadocMethod")
|
||||
@Deprecated
|
||||
public void encodeYUV(BufferedImage srcImage, byte[] dstBuf, int flags)
|
||||
throws TJException {
|
||||
@@ -540,6 +548,7 @@ public class TJCompressor implements Closeable {
|
||||
* {@link #setSourceImage(BufferedImage, int, int, int, int)} and
|
||||
* {@link #encodeYUV(int, int)} instead.
|
||||
*/
|
||||
@SuppressWarnings("checkstyle:JavadocMethod")
|
||||
@Deprecated
|
||||
public byte[] encodeYUV(BufferedImage srcImage, int flags)
|
||||
throws TJException {
|
||||
@@ -567,6 +576,7 @@ public class TJCompressor implements Closeable {
|
||||
destroy();
|
||||
}
|
||||
|
||||
@SuppressWarnings("checkstyle:DesignForExtension")
|
||||
@Override
|
||||
protected void finalize() throws Throwable {
|
||||
try {
|
||||
@@ -582,44 +592,53 @@ public class TJCompressor implements Closeable {
|
||||
private native void destroy() throws TJException;
|
||||
|
||||
// JPEG size in bytes is returned
|
||||
@SuppressWarnings("checkstyle:HiddenField")
|
||||
@Deprecated
|
||||
private native int compress(byte[] srcBuf, int width, int pitch,
|
||||
int height, int pixelFormat, byte[] dstBuf, int jpegSubsamp, int jpegQual,
|
||||
int height, int pixelFormat, byte[] jpegBuf, int jpegSubsamp, int jpegQual,
|
||||
int flags) throws TJException;
|
||||
|
||||
@SuppressWarnings("checkstyle:HiddenField")
|
||||
private native int compress(byte[] srcBuf, int x, int y, int width,
|
||||
int pitch, int height, int pixelFormat, byte[] dstBuf, int jpegSubsamp,
|
||||
int pitch, int height, int pixelFormat, byte[] jpegBuf, int jpegSubsamp,
|
||||
int jpegQual, int flags) throws TJException;
|
||||
|
||||
@SuppressWarnings("checkstyle:HiddenField")
|
||||
@Deprecated
|
||||
private native int compress(int[] srcBuf, int width, int stride,
|
||||
int height, int pixelFormat, byte[] dstBuf, int jpegSubsamp, int jpegQual,
|
||||
int height, int pixelFormat, byte[] jpegBuf, int jpegSubsamp, int jpegQual,
|
||||
int flags) throws TJException;
|
||||
|
||||
@SuppressWarnings("checkstyle:HiddenField")
|
||||
private native int compress(int[] srcBuf, int x, int y, int width,
|
||||
int stride, int height, int pixelFormat, byte[] dstBuf, int jpegSubsamp,
|
||||
int stride, int height, int pixelFormat, byte[] jpegBuf, int jpegSubsamp,
|
||||
int jpegQual, int flags) throws TJException;
|
||||
|
||||
@SuppressWarnings("checkstyle:HiddenField")
|
||||
private native int compressFromYUV(byte[][] srcPlanes, int[] srcOffsets,
|
||||
int width, int[] srcStrides, int height, int subsamp, byte[] dstBuf,
|
||||
int width, int[] srcStrides, int height, int subsamp, byte[] jpegBuf,
|
||||
int jpegQual, int flags)
|
||||
throws TJException;
|
||||
|
||||
@SuppressWarnings("checkstyle:HiddenField")
|
||||
@Deprecated
|
||||
private native void encodeYUV(byte[] srcBuf, int width, int pitch,
|
||||
int height, int pixelFormat, byte[] dstBuf, int subsamp, int flags)
|
||||
throws TJException;
|
||||
|
||||
@SuppressWarnings("checkstyle:HiddenField")
|
||||
private native void encodeYUV(byte[] srcBuf, int x, int y, int width,
|
||||
int pitch, int height, int pixelFormat, byte[][] dstPlanes,
|
||||
int[] dstOffsets, int[] dstStrides, int subsamp, int flags)
|
||||
throws TJException;
|
||||
|
||||
@SuppressWarnings("checkstyle:HiddenField")
|
||||
@Deprecated
|
||||
private native void encodeYUV(int[] srcBuf, int width, int stride,
|
||||
int height, int pixelFormat, byte[] dstBuf, int subsamp, int flags)
|
||||
throws TJException;
|
||||
|
||||
@SuppressWarnings("checkstyle:HiddenField")
|
||||
private native void encodeYUV(int[] srcBuf, int x, int y, int width,
|
||||
int srcStride, int height, int pixelFormat, byte[][] dstPlanes,
|
||||
int[] dstOffsets, int[] dstStrides, int subsamp, int flags)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C)2011-2015 D. R. Commander. All Rights Reserved.
|
||||
* Copyright (C)2011-2015, 2018 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
|
||||
@@ -82,6 +82,7 @@ public class TJDecompressor implements Closeable {
|
||||
* @param yuvImage {@link YUVImage} instance containing a YUV planar
|
||||
* image to be decoded. This image is not modified.
|
||||
*/
|
||||
@SuppressWarnings("checkstyle:HiddenField")
|
||||
public TJDecompressor(YUVImage yuvImage) throws TJException {
|
||||
init();
|
||||
setSourceImage(yuvImage);
|
||||
@@ -109,6 +110,7 @@ public class TJDecompressor implements Closeable {
|
||||
/**
|
||||
* @deprecated Use {@link #setSourceImage(byte[], int)} instead.
|
||||
*/
|
||||
@SuppressWarnings("checkstyle:JavadocMethod")
|
||||
@Deprecated
|
||||
public void setJPEGImage(byte[] jpegImage, int imageSize)
|
||||
throws TJException {
|
||||
@@ -400,6 +402,7 @@ public class TJDecompressor implements Closeable {
|
||||
* @deprecated Use
|
||||
* {@link #decompress(byte[], int, int, int, int, int, int, int)} instead.
|
||||
*/
|
||||
@SuppressWarnings("checkstyle:JavadocMethod")
|
||||
@Deprecated
|
||||
public void decompress(byte[] dstBuf, int desiredWidth, int pitch,
|
||||
int desiredHeight, int pixelFormat, int flags)
|
||||
@@ -494,11 +497,12 @@ public class TJDecompressor implements Closeable {
|
||||
/**
|
||||
* @deprecated Use {@link #decompressToYUV(YUVImage, int)} instead.
|
||||
*/
|
||||
@SuppressWarnings("checkstyle:JavadocMethod")
|
||||
@Deprecated
|
||||
public void decompressToYUV(byte[] dstBuf, int flags) throws TJException {
|
||||
YUVImage dstImage = new YUVImage(dstBuf, jpegWidth, 4, jpegHeight,
|
||||
jpegSubsamp);
|
||||
decompressToYUV(dstImage, flags);
|
||||
YUVImage dstYUVImage = new YUVImage(dstBuf, jpegWidth, 4, jpegHeight,
|
||||
jpegSubsamp);
|
||||
decompressToYUV(dstYUVImage, flags);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -553,10 +557,10 @@ public class TJDecompressor implements Closeable {
|
||||
|
||||
int scaledWidth = getScaledWidth(desiredWidth, desiredHeight);
|
||||
int scaledHeight = getScaledHeight(desiredWidth, desiredHeight);
|
||||
YUVImage yuvImage = new YUVImage(scaledWidth, null, scaledHeight,
|
||||
jpegSubsamp);
|
||||
decompressToYUV(yuvImage, flags);
|
||||
return yuvImage;
|
||||
YUVImage dstYUVImage = new YUVImage(scaledWidth, null, scaledHeight,
|
||||
jpegSubsamp);
|
||||
decompressToYUV(dstYUVImage, flags);
|
||||
return dstYUVImage;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -606,20 +610,21 @@ public class TJDecompressor implements Closeable {
|
||||
|
||||
int scaledWidth = getScaledWidth(desiredWidth, desiredHeight);
|
||||
int scaledHeight = getScaledHeight(desiredWidth, desiredHeight);
|
||||
YUVImage yuvImage = new YUVImage(scaledWidth, pad, scaledHeight,
|
||||
jpegSubsamp);
|
||||
decompressToYUV(yuvImage, flags);
|
||||
return yuvImage;
|
||||
YUVImage dstYUVImage = new YUVImage(scaledWidth, pad, scaledHeight,
|
||||
jpegSubsamp);
|
||||
decompressToYUV(dstYUVImage, flags);
|
||||
return dstYUVImage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #decompressToYUV(int, int, int, int)} instead.
|
||||
*/
|
||||
@SuppressWarnings("checkstyle:JavadocMethod")
|
||||
@Deprecated
|
||||
public byte[] decompressToYUV(int flags) throws TJException {
|
||||
YUVImage dstImage = new YUVImage(jpegWidth, 4, jpegHeight, jpegSubsamp);
|
||||
decompressToYUV(dstImage, flags);
|
||||
return dstImage.getBuf();
|
||||
YUVImage dstYUVImage = new YUVImage(jpegWidth, 4, jpegHeight, jpegSubsamp);
|
||||
decompressToYUV(dstYUVImage, flags);
|
||||
return dstYUVImage.getBuf();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -858,6 +863,7 @@ public class TJDecompressor implements Closeable {
|
||||
destroy();
|
||||
}
|
||||
|
||||
@SuppressWarnings("checkstyle:DesignForExtension")
|
||||
@Override
|
||||
protected void finalize() throws Throwable {
|
||||
try {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (C)2015 Viktor Szathmáry. All Rights Reserved.
|
||||
* Copyright (C)2017 D. R. Commander. All Rights Reserved.
|
||||
* Copyright (C)2017-2018 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:
|
||||
@@ -31,28 +31,34 @@ package org.libjpegturbo.turbojpeg;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@SuppressWarnings("checkstyle:JavadocType")
|
||||
public class TJException extends IOException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@SuppressWarnings("checkstyle:JavadocMethod")
|
||||
public TJException() {
|
||||
super();
|
||||
}
|
||||
|
||||
@SuppressWarnings("checkstyle:JavadocMethod")
|
||||
public TJException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
@SuppressWarnings("checkstyle:JavadocMethod")
|
||||
public TJException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
@SuppressWarnings("checkstyle:JavadocMethod")
|
||||
public TJException(String message, int code) {
|
||||
super(message);
|
||||
if (errorCode >= 0 && errorCode < TJ.NUMERR)
|
||||
errorCode = code;
|
||||
}
|
||||
|
||||
@SuppressWarnings("checkstyle:JavadocMethod")
|
||||
public TJException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C)2011 D. R. Commander. All Rights Reserved.
|
||||
* Copyright (C)2011, 2018 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
|
||||
@@ -34,6 +34,13 @@ package org.libjpegturbo.turbojpeg;
|
||||
*/
|
||||
public class TJScalingFactor {
|
||||
|
||||
/**
|
||||
* Create a TurboJPEG scaling factor instance.
|
||||
*
|
||||
* @param num numerator
|
||||
* @param denom denominator
|
||||
*/
|
||||
@SuppressWarnings("checkstyle:HiddenField")
|
||||
public TJScalingFactor(int num, int denom) {
|
||||
if (num < 1 || denom < 1)
|
||||
throw new IllegalArgumentException("Numerator and denominator must be >= 1");
|
||||
@@ -64,6 +71,8 @@ public class TJScalingFactor {
|
||||
* performs the integer equivalent of
|
||||
* <code>ceil(dimension * scalingFactor)</code>.
|
||||
*
|
||||
* @param dimension width or height to multiply by this scaling factor
|
||||
*
|
||||
* @return the scaled value of <code>dimension</code>.
|
||||
*/
|
||||
public int getScaled(int dimension) {
|
||||
@@ -74,6 +83,8 @@ public class TJScalingFactor {
|
||||
* Returns true or false, depending on whether this instance and
|
||||
* <code>other</code> have the same numerator and denominator.
|
||||
*
|
||||
* @param other the scaling factor against which to compare this one
|
||||
*
|
||||
* @return true or false, depending on whether this instance and
|
||||
* <code>other</code> have the same numerator and denominator.
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C)2011, 2013 D. R. Commander. All Rights Reserved.
|
||||
* Copyright (C)2011, 2013, 2018 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:
|
||||
@@ -173,6 +173,7 @@ public class TJTransform extends Rectangle {
|
||||
* @param cf an instance of an object that implements the {@link
|
||||
* TJCustomFilter} interface, or null if no custom filter is needed
|
||||
*/
|
||||
@SuppressWarnings("checkstyle:HiddenField")
|
||||
public TJTransform(int x, int y, int w, int h, int op, int options,
|
||||
TJCustomFilter cf) {
|
||||
super(x, y, w, h);
|
||||
@@ -197,6 +198,7 @@ public class TJTransform extends Rectangle {
|
||||
* @param cf an instance of an object that implements the {@link
|
||||
* TJCustomFilter} interface, or null if no custom filter is needed
|
||||
*/
|
||||
@SuppressWarnings("checkstyle:HiddenField")
|
||||
public TJTransform(Rectangle r, int op, int options,
|
||||
TJCustomFilter cf) {
|
||||
super(r);
|
||||
@@ -208,15 +210,18 @@ public class TJTransform extends Rectangle {
|
||||
/**
|
||||
* Transform operation (one of <code>OP_*</code>)
|
||||
*/
|
||||
@SuppressWarnings("checkstyle:VisibilityModifier")
|
||||
public int op = 0;
|
||||
|
||||
/**
|
||||
* Transform options (bitwise OR of one or more of <code>OPT_*</code>)
|
||||
*/
|
||||
@SuppressWarnings("checkstyle:VisibilityModifier")
|
||||
public int options = 0;
|
||||
|
||||
/**
|
||||
* Custom filter instance
|
||||
*/
|
||||
@SuppressWarnings("checkstyle:VisibilityModifier")
|
||||
public TJCustomFilter cf = null;
|
||||
}
|
||||
|
||||
@@ -247,9 +247,11 @@ public class YUVImage {
|
||||
if (planes[i] == null || offsets[i] < 0)
|
||||
throw new IllegalArgumentException("Invalid argument in YUVImage::setBuf()");
|
||||
if (strides[i] < 0 && offsets[i] - planeSize + pw < 0)
|
||||
throw new IllegalArgumentException("Stride for plane " + i + " would cause memory to be accessed below plane boundary");
|
||||
throw new IllegalArgumentException("Stride for plane " + i +
|
||||
" would cause memory to be accessed below plane boundary");
|
||||
if (planes[i].length < offsets[i] + planeSize)
|
||||
throw new IllegalArgumentException("Image plane " + i + " is not large enough");
|
||||
throw new IllegalArgumentException("Image plane " + i +
|
||||
" is not large enough");
|
||||
}
|
||||
|
||||
yuvPlanes = planes;
|
||||
@@ -294,9 +296,9 @@ public class YUVImage {
|
||||
int[] offsets = new int[nc];
|
||||
|
||||
planes[0] = yuvImage;
|
||||
strides[0] = PAD(TJ.planeWidth(0, width, subsamp), pad);
|
||||
strides[0] = pad(TJ.planeWidth(0, width, subsamp), pad);
|
||||
if (subsamp != TJ.SAMP_GRAY) {
|
||||
strides[1] = strides[2] = PAD(TJ.planeWidth(1, width, subsamp), pad);
|
||||
strides[1] = strides[2] = pad(TJ.planeWidth(1, width, subsamp), pad);
|
||||
planes[1] = planes[2] = yuvImage;
|
||||
offsets[1] = offsets[0] +
|
||||
strides[0] * TJ.planeHeight(0, height, subsamp);
|
||||
@@ -428,7 +430,7 @@ public class YUVImage {
|
||||
return TJ.bufSizeYUV(yuvWidth, yuvPad, yuvHeight, yuvSubsamp);
|
||||
}
|
||||
|
||||
private static int PAD(int v, int p) {
|
||||
private static int pad(int v, int p) {
|
||||
return (v + p - 1) & (~(p - 1));
|
||||
}
|
||||
|
||||
|
||||
66
tjbench.c
66
tjbench.c
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C)2009-2017 D. R. Commander. All Rights Reserved.
|
||||
* Copyright (C)2009-2018 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:
|
||||
@@ -511,12 +511,14 @@ int decompTest(char *fileName)
|
||||
unsigned char **jpegBuf = NULL, *srcBuf = NULL;
|
||||
unsigned long *jpegSize = NULL, srcSize, totalJpegSize;
|
||||
tjtransform *t = NULL;
|
||||
int w = 0, h = 0, subsamp = -1, cs = -1, _w, _h, _tilew, _tileh, _ntilesw,
|
||||
_ntilesh, _subsamp;
|
||||
char *temp = NULL, tempStr[80], tempStr2[80];
|
||||
int row, col, i, iter, tilew, tileh, ntilesw = 1, ntilesh = 1, retval = 0;
|
||||
double start, elapsed;
|
||||
int ps = tjPixelSize[pf], tile, decompsrc = 0;
|
||||
int ps = tjPixelSize[pf], tile, row, col, i, iter, retval = 0, decompsrc = 0;
|
||||
char *temp = NULL, tempStr[80], tempStr2[80];
|
||||
/* Original image */
|
||||
int w = 0, h = 0, tilew, tileh, ntilesw = 1, ntilesh = 1, subsamp = -1,
|
||||
cs = -1;
|
||||
/* Transformed image */
|
||||
int tw, th, ttilew, ttileh, tntilesw, tntilesh, tsubsamp;
|
||||
|
||||
if ((file = fopen(fileName, "rb")) == NULL)
|
||||
_throwunix("opening file");
|
||||
@@ -580,11 +582,11 @@ int decompTest(char *fileName)
|
||||
_throwunix("allocating JPEG tiles");
|
||||
}
|
||||
|
||||
_w = w; _h = h; _tilew = tilew; _tileh = tileh;
|
||||
tw = w; th = h; ttilew = tilew; ttileh = tileh;
|
||||
if (!quiet) {
|
||||
printf("\n%s size: %d x %d", doTile ? "Tile" : "Image", _tilew, _tileh);
|
||||
printf("\n%s size: %d x %d", doTile ? "Tile" : "Image", ttilew, ttileh);
|
||||
if (sf.num != 1 || sf.denom != 1)
|
||||
printf(" --> %d x %d", TJSCALED(_w, sf), TJSCALED(_h, sf));
|
||||
printf(" --> %d x %d", TJSCALED(tw, sf), TJSCALED(th, sf));
|
||||
printf("\n");
|
||||
} else if (quiet == 1) {
|
||||
printf("%-4s (%s) %-5s %-5s ", pixFormatStr[pf],
|
||||
@@ -593,7 +595,7 @@ int decompTest(char *fileName)
|
||||
printf("%-5d %-5d ", tilew, tileh);
|
||||
}
|
||||
|
||||
_subsamp = subsamp;
|
||||
tsubsamp = subsamp;
|
||||
if (doTile || xformOp != TJXOP_NONE || xformOpt != 0 || customFilter) {
|
||||
if ((t = (tjtransform *)malloc(sizeof(tjtransform) * ntilesw *
|
||||
ntilesh)) == NULL)
|
||||
@@ -601,33 +603,33 @@ int decompTest(char *fileName)
|
||||
|
||||
if (xformOp == TJXOP_TRANSPOSE || xformOp == TJXOP_TRANSVERSE ||
|
||||
xformOp == TJXOP_ROT90 || xformOp == TJXOP_ROT270) {
|
||||
_w = h; _h = w; _tilew = tileh; _tileh = tilew;
|
||||
tw = h; th = w; ttilew = tileh; ttileh = tilew;
|
||||
}
|
||||
|
||||
if (xformOpt & TJXOPT_GRAY) _subsamp = TJ_GRAYSCALE;
|
||||
if (xformOpt & TJXOPT_GRAY) tsubsamp = TJ_GRAYSCALE;
|
||||
if (xformOp == TJXOP_HFLIP || xformOp == TJXOP_ROT180)
|
||||
_w = _w - (_w % tjMCUWidth[_subsamp]);
|
||||
tw = tw - (tw % tjMCUWidth[tsubsamp]);
|
||||
if (xformOp == TJXOP_VFLIP || xformOp == TJXOP_ROT180)
|
||||
_h = _h - (_h % tjMCUHeight[_subsamp]);
|
||||
th = th - (th % tjMCUHeight[tsubsamp]);
|
||||
if (xformOp == TJXOP_TRANSVERSE || xformOp == TJXOP_ROT90)
|
||||
_w = _w - (_w % tjMCUHeight[_subsamp]);
|
||||
tw = tw - (tw % tjMCUHeight[tsubsamp]);
|
||||
if (xformOp == TJXOP_TRANSVERSE || xformOp == TJXOP_ROT270)
|
||||
_h = _h - (_h % tjMCUWidth[_subsamp]);
|
||||
_ntilesw = (_w + _tilew - 1) / _tilew;
|
||||
_ntilesh = (_h + _tileh - 1) / _tileh;
|
||||
th = th - (th % tjMCUWidth[tsubsamp]);
|
||||
tntilesw = (tw + ttilew - 1) / ttilew;
|
||||
tntilesh = (th + ttileh - 1) / ttileh;
|
||||
|
||||
if (xformOp == TJXOP_TRANSPOSE || xformOp == TJXOP_TRANSVERSE ||
|
||||
xformOp == TJXOP_ROT90 || xformOp == TJXOP_ROT270) {
|
||||
if (_subsamp == TJSAMP_422) _subsamp = TJSAMP_440;
|
||||
else if (_subsamp == TJSAMP_440) _subsamp = TJSAMP_422;
|
||||
if (tsubsamp == TJSAMP_422) tsubsamp = TJSAMP_440;
|
||||
else if (tsubsamp == TJSAMP_440) tsubsamp = TJSAMP_422;
|
||||
}
|
||||
|
||||
for (row = 0, tile = 0; row < _ntilesh; row++) {
|
||||
for (col = 0; col < _ntilesw; col++, tile++) {
|
||||
t[tile].r.w = min(_tilew, _w - col * _tilew);
|
||||
t[tile].r.h = min(_tileh, _h - row * _tileh);
|
||||
t[tile].r.x = col * _tilew;
|
||||
t[tile].r.y = row * _tileh;
|
||||
for (row = 0, tile = 0; row < tntilesh; row++) {
|
||||
for (col = 0; col < tntilesw; col++, tile++) {
|
||||
t[tile].r.w = min(ttilew, tw - col * ttilew);
|
||||
t[tile].r.h = min(ttileh, th - row * ttileh);
|
||||
t[tile].r.x = col * ttilew;
|
||||
t[tile].r.y = row * ttileh;
|
||||
t[tile].op = xformOp;
|
||||
t[tile].options = xformOpt | TJXOPT_TRIM;
|
||||
t[tile].customFilter = customFilter;
|
||||
@@ -641,7 +643,7 @@ int decompTest(char *fileName)
|
||||
elapsed = 0.;
|
||||
while (1) {
|
||||
start = getTime();
|
||||
if (tjTransform(handle, srcBuf, srcSize, _ntilesw * _ntilesh, jpegBuf,
|
||||
if (tjTransform(handle, srcBuf, srcSize, tntilesw * tntilesh, jpegBuf,
|
||||
jpegSize, t, flags) == -1)
|
||||
_throwtj("executing tjTransform()");
|
||||
elapsed += getTime() - start;
|
||||
@@ -656,7 +658,7 @@ int decompTest(char *fileName)
|
||||
|
||||
free(t); t = NULL;
|
||||
|
||||
for (tile = 0, totalJpegSize = 0; tile < _ntilesw * _ntilesh; tile++)
|
||||
for (tile = 0, totalJpegSize = 0; tile < tntilesw * tntilesh; tile++)
|
||||
totalJpegSize += jpegSize[tile];
|
||||
|
||||
if (quiet) {
|
||||
@@ -685,12 +687,12 @@ int decompTest(char *fileName)
|
||||
decompsrc = 1;
|
||||
}
|
||||
|
||||
if (w == tilew) _tilew = _w;
|
||||
if (h == tileh) _tileh = _h;
|
||||
if (w == tilew) ttilew = tw;
|
||||
if (h == tileh) ttileh = th;
|
||||
if (!(xformOpt & TJXOPT_NOOUTPUT)) {
|
||||
if (decomp(NULL, decompsrc ? &srcBuf : jpegBuf,
|
||||
decompsrc ? &srcSize : jpegSize, NULL, _w, _h, _subsamp, 0,
|
||||
fileName, _tilew, _tileh) == -1)
|
||||
decompsrc ? &srcSize : jpegSize, NULL, tw, th, tsubsamp, 0,
|
||||
fileName, ttilew, ttileh) == -1)
|
||||
goto bailout;
|
||||
} else if (quiet == 1) printf("N/A\n");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user