Use new scaling API
git-svn-id: svn+ssh://svn.code.sf.net/p/libjpeg-turbo/code/trunk@482 632fc199-4ca6-4c93-a231-07263d6284db
This commit is contained in:
@@ -40,14 +40,23 @@ public class TJExample {
|
|||||||
|
|
||||||
public static final String classname = new TJExample().getClass().getName();
|
public static final String classname = new TJExample().getClass().getName();
|
||||||
|
|
||||||
private static void usage() {
|
private static void usage() throws Exception {
|
||||||
System.out.println("\nUSAGE: java " + classname + " <Input file> <Output file> [options]\n");
|
System.out.println("\nUSAGE: java " + classname + " <Input file> <Output file> [options]\n");
|
||||||
System.out.println("Input and output files can be any image format that the Java Image I/O");
|
System.out.println("Input and output files can be any image format that the Java Image I/O");
|
||||||
System.out.println("extensions understand. If either filename ends in a .jpg extension, then");
|
System.out.println("extensions understand. If either filename ends in a .jpg extension, then");
|
||||||
System.out.println("TurboJPEG will be used to compress or decompress the file.\n");
|
System.out.println("TurboJPEG will be used to compress or decompress the file.\n");
|
||||||
System.out.println("Options:\n");
|
System.out.println("Options:\n");
|
||||||
System.out.println("-scale 1/N = if the input image is a JPEG file, scale the width/height of the");
|
System.out.println("-scale M/N = if the input image is a JPEG file, scale the width/height of the");
|
||||||
System.out.println(" output image by a factor of 1/N (N = 1, 2, 4, or 8}\n");
|
System.out.print(" output image by a factor of M/N (M/N = ");
|
||||||
|
for(int i = 0; i < sf.length; i++) {
|
||||||
|
System.out.print(sf[i].num + "/" + sf[i].denom);
|
||||||
|
if(sf.length == 2 && i != sf.length - 1) System.out.print(" or ");
|
||||||
|
else if(sf.length > 2) {
|
||||||
|
if(i != sf.length - 1) System.out.print(", ");
|
||||||
|
if(i == sf.length - 2) System.out.print("or ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
System.out.println(")\n");
|
||||||
System.out.println("-samp <444|422|420|gray> = If the output image is a JPEG file, this specifies");
|
System.out.println("-samp <444|422|420|gray> = If the output image is a JPEG file, this specifies");
|
||||||
System.out.println(" the level of chrominance subsampling to use when");
|
System.out.println(" the level of chrominance subsampling to use when");
|
||||||
System.out.println(" recompressing it. Default is to use the same level");
|
System.out.println(" recompressing it. Default is to use the same level");
|
||||||
@@ -68,11 +77,13 @@ public class TJExample {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
sf = TJ.getScalingFactors();
|
||||||
|
|
||||||
if(argv.length < 2) {
|
if(argv.length < 2) {
|
||||||
usage();
|
usage();
|
||||||
}
|
}
|
||||||
|
|
||||||
int scaleFactor = 1;
|
int scaleNum = 1, scaleDenom = 1;
|
||||||
String inFormat = "jpg", outFormat = "jpg";
|
String inFormat = "jpg", outFormat = "jpg";
|
||||||
int outSubsamp = -1, outQual = 95;
|
int outSubsamp = -1, outQual = 95;
|
||||||
|
|
||||||
@@ -81,14 +92,22 @@ public class TJExample {
|
|||||||
if(argv[i].length() < 2) continue;
|
if(argv[i].length() < 2) continue;
|
||||||
if(argv[i].length() > 2
|
if(argv[i].length() > 2
|
||||||
&& argv[i].substring(0, 3).equalsIgnoreCase("-sc")) {
|
&& argv[i].substring(0, 3).equalsIgnoreCase("-sc")) {
|
||||||
|
int match = 0;
|
||||||
if(i < argv.length - 1) {
|
if(i < argv.length - 1) {
|
||||||
|
int temp1 = 0, temp2 = 0;
|
||||||
String[] scaleArg = argv[++i].split("/");
|
String[] scaleArg = argv[++i].split("/");
|
||||||
if(scaleArg.length != 2 || Integer.parseInt(scaleArg[0]) != 1
|
if(scaleArg.length == 2) {
|
||||||
|| (scaleFactor = Integer.parseInt(scaleArg[1])) < 1
|
temp1 = Integer.parseInt(scaleArg[0]);
|
||||||
|| scaleFactor > 8 || (scaleFactor & (scaleFactor - 1)) != 0)
|
temp2 = Integer.parseInt(scaleArg[1]);
|
||||||
usage();
|
for(int j = 0; j < sf.length; j++) {
|
||||||
|
if(temp1 == sf[j].num && temp2 == sf[j].denom) {
|
||||||
|
scaleNum = temp1; scaleDenom = temp2;
|
||||||
|
match = 1; break;
|
||||||
}
|
}
|
||||||
else usage();
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(match != 1) usage();
|
||||||
}
|
}
|
||||||
if(argv[i].substring(0, 2).equalsIgnoreCase("-h")
|
if(argv[i].substring(0, 2).equalsIgnoreCase("-h")
|
||||||
|| argv[i].equalsIgnoreCase("-?"))
|
|| argv[i].equalsIgnoreCase("-?"))
|
||||||
@@ -145,9 +164,9 @@ public class TJExample {
|
|||||||
+ " pixels, " + sampName[inSubsamp] + " subsampling");
|
+ " pixels, " + sampName[inSubsamp] + " subsampling");
|
||||||
if(outSubsamp < 0) outSubsamp = inSubsamp;
|
if(outSubsamp < 0) outSubsamp = inSubsamp;
|
||||||
|
|
||||||
if(scaleFactor != 1) {
|
if(scaleNum != 1 || scaleDenom != 1) {
|
||||||
width = (width + scaleFactor - 1) / scaleFactor;
|
width = (width * scaleNum + scaleDenom - 1) / scaleDenom;
|
||||||
height = (height + scaleFactor - 1) / scaleFactor;
|
height = (height * scaleNum + scaleDenom - 1) / scaleDenom;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!outFormat.equalsIgnoreCase("jpg"))
|
if(!outFormat.equalsIgnoreCase("jpg"))
|
||||||
@@ -203,4 +222,5 @@ public class TJExample {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static TJ.ScalingFactor sf [] = null;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user