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:
@@ -38,13 +38,33 @@ 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() {
|
||||||
|
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[]) {
|
public static void main(String argv[]) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
if(argv.length<2) {
|
if(argv.length<2) {
|
||||||
System.out.println("USAGE: java "+classname+" <Input file> <Output file>");
|
usage();
|
||||||
System.exit(1);
|
}
|
||||||
|
|
||||||
|
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]);
|
File file=new File(argv[0]);
|
||||||
@@ -68,9 +88,18 @@ public class TJExample {
|
|||||||
case TJ.GRAYSCALE: System.out.println("Grayscale"); break;
|
case TJ.GRAYSCALE: System.out.println("Grayscale"); break;
|
||||||
default: System.out.println("Unknown subsampling"); 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];
|
byte [] tmpbuf=new byte[tji.width*tji.height*3];
|
||||||
tjd.decompress(inputbuf, inputsize, tmpbuf, tji.width, tji.width*3,
|
tjd.decompress(inputbuf, inputsize, tmpbuf, tji.width*3,
|
||||||
tji.height, 3, TJ.BOTTOMUP);
|
3, 1, scalefactor, TJ.BOTTOMUP);
|
||||||
tjd.close();
|
tjd.close();
|
||||||
|
|
||||||
TJCompressor tjc=new TJCompressor();
|
TJCompressor tjc=new TJCompressor();
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ public class TJDecompressor {
|
|||||||
throws Exception;
|
throws Exception;
|
||||||
|
|
||||||
public native void decompress(byte [] srcbuf, long size, byte [] dstbuf,
|
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;
|
throws Exception;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
|||||||
@@ -169,7 +169,7 @@ JNIEXPORT jobject JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompr
|
|||||||
|
|
||||||
JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompress
|
JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompress
|
||||||
(JNIEnv *env, jobject obj, jbyteArray src, jlong size, jbyteArray dst,
|
(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;
|
tjhandle handle=0;
|
||||||
unsigned char *srcbuf=NULL, *dstbuf=NULL;
|
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(srcbuf=(*env)->GetPrimitiveArrayCritical(env, src, 0));
|
||||||
bailif0(dstbuf=(*env)->GetPrimitiveArrayCritical(env, dst, 0));
|
bailif0(dstbuf=(*env)->GetPrimitiveArrayCritical(env, dst, 0));
|
||||||
|
|
||||||
if(tjDecompress(handle, srcbuf, (unsigned long)size, dstbuf, width, pitch,
|
if(tjDecompress2(handle, srcbuf, (unsigned long)size, dstbuf, pitch,
|
||||||
height, pixelsize, flags)==-1)
|
pixelsize, scale_num, scale_denom, flags)==-1)
|
||||||
{
|
{
|
||||||
(*env)->ReleasePrimitiveArrayCritical(env, dst, dstbuf, 0);
|
(*env)->ReleasePrimitiveArrayCritical(env, dst, dstbuf, 0);
|
||||||
(*env)->ReleasePrimitiveArrayCritical(env, src, srcbuf, 0);
|
(*env)->ReleasePrimitiveArrayCritical(env, src, srcbuf, 0);
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
tjDecompressHeader;
|
tjDecompressHeader;
|
||||||
tjDecompressHeader2;
|
tjDecompressHeader2;
|
||||||
tjDecompress;
|
tjDecompress;
|
||||||
|
tjDecompress2;
|
||||||
tjDestroy;
|
tjDestroy;
|
||||||
tjGetErrorStr;
|
tjGetErrorStr;
|
||||||
Java_org_libjpegturbo_turbojpeg_TJ_bufSize;
|
Java_org_libjpegturbo_turbojpeg_TJ_bufSize;
|
||||||
|
|||||||
Reference in New Issue
Block a user