Expose TurboJPEG scaling features in Java wrapper

git-svn-id: svn+ssh://svn.code.sf.net/p/libjpeg-turbo/code/trunk@375 632fc199-4ca6-4c93-a231-07263d6284db
This commit is contained in:
DRC
2011-02-16 03:26:48 +00:00
parent 942029fd93
commit e1303ef099
4 changed files with 38 additions and 8 deletions

View File

@@ -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();

View File

@@ -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 {

View File

@@ -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);

View File

@@ -7,6 +7,7 @@
tjDecompressHeader;
tjDecompressHeader2;
tjDecompress;
tjDecompress2;
tjDestroy;
tjGetErrorStr;
Java_org_libjpegturbo_turbojpeg_TJ_bufSize;