summaryrefslogtreecommitdiff
path: root/trunk/java
diff options
context:
space:
mode:
authordcommander <dcommander@3789f03b-4d11-0410-bbf8-ca57d06f2519>2011-02-16 03:26:48 +0000
committerdcommander <dcommander@3789f03b-4d11-0410-bbf8-ca57d06f2519>2011-02-16 03:26:48 +0000
commitb7481bbb92179beadda35732a15a5e9494696d5a (patch)
tree4f577fed410fe1c079cff26316f519470bdf77d7 /trunk/java
parent891b10a74e4aae0e2ae7c749cb9f4307aee936b0 (diff)
Expose TurboJPEG scaling features in Java wrapper
git-svn-id: https://libjpeg-turbo.svn.sourceforge.net/svnroot/libjpeg-turbo@375 3789f03b-4d11-0410-bbf8-ca57d06f2519
Diffstat (limited to 'trunk/java')
-rw-r--r--trunk/java/TJExample.java37
-rw-r--r--trunk/java/org/libjpegturbo/turbojpeg/TJDecompressor.java2
2 files changed, 34 insertions, 5 deletions
diff --git a/trunk/java/TJExample.java b/trunk/java/TJExample.java
index f6c2e43..6595f63 100644
--- a/trunk/java/TJExample.java
+++ b/trunk/java/TJExample.java
@@ -38,13 +38,33 @@ public class TJExample {
public static final String classname=new TJExample().getClass().getName();
+ private static void usage() {
+ System.out.println("\nUSAGE: java "+classname+" <Input file> <Output file> [options]\n");
+ System.out.println("Options:\n");
+ System.out.println("-scale 1/N = scale the width/height of the output image by a factor of 1/N");
+ System.out.println(" (N = 1, 2, 4, or 8}\n");
+ System.exit(1);
+ }
+
public static void main(String argv[]) {
try {
if(argv.length<2) {
- System.out.println("USAGE: java "+classname+" <Input file> <Output file>");
- System.exit(1);
+ usage();
+ }
+
+ int scalefactor=1;
+ if(argv.length>2) {
+ for(int i=2; i<argv.length; i++) {
+ if(argv[i].equalsIgnoreCase("-scale") && i<argv.length-1) {
+ String [] scalearg=argv[++i].split("/");
+ if(scalearg.length!=2 || Integer.parseInt(scalearg[0])!=1
+ || (scalefactor=Integer.parseInt(scalearg[1]))<1
+ || scalefactor>8 || (scalefactor&(scalefactor-1))!=0)
+ usage();
+ }
+ }
}
File file=new File(argv[0]);
@@ -68,9 +88,18 @@ public class TJExample {
case TJ.GRAYSCALE: System.out.println("Grayscale"); break;
default: System.out.println("Unknown subsampling"); break;
}
+
+ if(scalefactor!=1) {
+ tji.width=(tji.width+scalefactor-1)/scalefactor;
+ tji.height=(tji.height+scalefactor-1)/scalefactor;
+ System.out.println("Dest. Image: "+tji.width+" x "+tji.height
+ +" pixels");
+ }
+
+
byte [] tmpbuf=new byte[tji.width*tji.height*3];
- tjd.decompress(inputbuf, inputsize, tmpbuf, tji.width, tji.width*3,
- tji.height, 3, TJ.BOTTOMUP);
+ tjd.decompress(inputbuf, inputsize, tmpbuf, tji.width*3,
+ 3, 1, scalefactor, TJ.BOTTOMUP);
tjd.close();
TJCompressor tjc=new TJCompressor();
diff --git a/trunk/java/org/libjpegturbo/turbojpeg/TJDecompressor.java b/trunk/java/org/libjpegturbo/turbojpeg/TJDecompressor.java
index 6408d58..42b3b82 100644
--- a/trunk/java/org/libjpegturbo/turbojpeg/TJDecompressor.java
+++ b/trunk/java/org/libjpegturbo/turbojpeg/TJDecompressor.java
@@ -56,7 +56,7 @@ public class TJDecompressor {
throws Exception;
public native void decompress(byte [] srcbuf, long size, byte [] dstbuf,
- int width, int pitch, int height, int pixelsize, int flags)
+ int pitch, int pixelsize, int scale_num, int scale_denom, int flags)
throws Exception;
static {