diff --git a/java/TJExample.java b/java/TJExample.java index f6c2e43b..6595f63d 100644 --- a/java/TJExample.java +++ b/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+" [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+" "); - System.exit(1); + usage(); + } + + int scalefactor=1; + if(argv.length>2) { + for(int i=2; i8 || (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/java/org/libjpegturbo/turbojpeg/TJDecompressor.java b/java/org/libjpegturbo/turbojpeg/TJDecompressor.java index 6408d588..42b3b82f 100644 --- a/java/org/libjpegturbo/turbojpeg/TJDecompressor.java +++ b/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 { diff --git a/turbojpeg-jni.c b/turbojpeg-jni.c index 892e51b2..1ab5e28a 100644 --- a/turbojpeg-jni.c +++ b/turbojpeg-jni.c @@ -169,7 +169,7 @@ JNIEXPORT jobject JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompr JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompress (JNIEnv *env, jobject obj, jbyteArray src, jlong size, jbyteArray dst, - jint width, jint pitch, jint height, jint pixelsize, jint flags) + jint pitch, jint pixelsize, jint scale_num, jint scale_denom, jint flags) { tjhandle handle=0; unsigned char *srcbuf=NULL, *dstbuf=NULL; @@ -179,8 +179,8 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompress bailif0(srcbuf=(*env)->GetPrimitiveArrayCritical(env, src, 0)); bailif0(dstbuf=(*env)->GetPrimitiveArrayCritical(env, dst, 0)); - if(tjDecompress(handle, srcbuf, (unsigned long)size, dstbuf, width, pitch, - height, pixelsize, flags)==-1) + if(tjDecompress2(handle, srcbuf, (unsigned long)size, dstbuf, pitch, + pixelsize, scale_num, scale_denom, flags)==-1) { (*env)->ReleasePrimitiveArrayCritical(env, dst, dstbuf, 0); (*env)->ReleasePrimitiveArrayCritical(env, src, srcbuf, 0); diff --git a/turbojpeg-mapfile.jni b/turbojpeg-mapfile.jni index 5aaa1e0c..cc11fadf 100755 --- a/turbojpeg-mapfile.jni +++ b/turbojpeg-mapfile.jni @@ -7,6 +7,7 @@ tjDecompressHeader; tjDecompressHeader2; tjDecompress; + tjDecompress2; tjDestroy; tjGetErrorStr; Java_org_libjpegturbo_turbojpeg_TJ_bufSize;