From 26dd86bd89a05598f7d1b97d0d02b09f83cc8a43 Mon Sep 17 00:00:00 2001 From: DRC Date: Fri, 15 Aug 2014 14:01:21 +0000 Subject: [PATCH] Restore backward compatibility between libjpeg-turbo 1.3.x JAR and the new JNI library git-svn-id: svn+ssh://svn.code.sf.net/p/libjpeg-turbo/code/trunk@1349 632fc199-4ca6-4c93-a231-07263d6284db --- .../turbojpeg/TJDecompressor.java | 68 +++++++++---------- turbojpeg-jni.c | 24 ++++--- 2 files changed, 47 insertions(+), 45 deletions(-) diff --git a/java/org/libjpegturbo/turbojpeg/TJDecompressor.java b/java/org/libjpegturbo/turbojpeg/TJDecompressor.java index 8305721..c71ce77 100644 --- a/java/org/libjpegturbo/turbojpeg/TJDecompressor.java +++ b/java/org/libjpegturbo/turbojpeg/TJDecompressor.java @@ -37,7 +37,7 @@ import java.nio.*; public class TJDecompressor { private static final String NO_ASSOC_ERROR = - "No source image is associated with this instance"; + "No JPEG image is associated with this instance"; /** * Create a TurboJPEG decompresssor instance. @@ -139,9 +139,9 @@ public class TJDecompressor { public int getWidth() throws Exception { if (yuvImage != null) return yuvImage.getWidth(); - if (srcWidth < 1) + if (jpegWidth < 1) throw new Exception(NO_ASSOC_ERROR); - return srcWidth; + return jpegWidth; } /** @@ -154,9 +154,9 @@ public class TJDecompressor { public int getHeight() throws Exception { if (yuvImage != null) return yuvImage.getHeight(); - if (srcHeight < 1) + if (jpegHeight < 1) throw new Exception(NO_ASSOC_ERROR); - return srcHeight; + return jpegHeight; } /** @@ -170,11 +170,11 @@ public class TJDecompressor { public int getSubsamp() throws Exception { if (yuvImage != null) return yuvImage.getSubsamp(); - if (srcSubsamp < 0) + if (jpegSubsamp < 0) throw new Exception(NO_ASSOC_ERROR); - if (srcSubsamp >= TJ.NUMSAMP) + if (jpegSubsamp >= TJ.NUMSAMP) throw new Exception("JPEG header information is invalid"); - return srcSubsamp; + return jpegSubsamp; } /** @@ -188,11 +188,11 @@ public class TJDecompressor { public int getColorspace() throws Exception { if (yuvImage != null) return TJ.CS_YCbCr; - if (srcColorspace < 0) + if (jpegColorspace < 0) throw new Exception(NO_ASSOC_ERROR); - if (srcColorspace >= TJ.NUMCS) + if (jpegColorspace >= TJ.NUMCS) throw new Exception("JPEG header information is invalid"); - return srcColorspace; + return jpegColorspace; } /** @@ -265,19 +265,19 @@ public class TJDecompressor { */ public int getScaledWidth(int desiredWidth, int desiredHeight) throws Exception { - if (srcWidth < 1 || srcHeight < 1) + if (jpegWidth < 1 || jpegHeight < 1) throw new Exception(NO_ASSOC_ERROR); if (desiredWidth < 0 || desiredHeight < 0) throw new Exception("Invalid argument in getScaledWidth()"); TJScalingFactor[] sf = TJ.getScalingFactors(); if (desiredWidth == 0) - desiredWidth = srcWidth; + desiredWidth = jpegWidth; if (desiredHeight == 0) - desiredHeight = srcHeight; - int scaledWidth = srcWidth, scaledHeight = srcHeight; + desiredHeight = jpegHeight; + int scaledWidth = jpegWidth, scaledHeight = jpegHeight; for (int i = 0; i < sf.length; i++) { - scaledWidth = sf[i].getScaled(srcWidth); - scaledHeight = sf[i].getScaled(srcHeight); + scaledWidth = sf[i].getScaled(jpegWidth); + scaledHeight = sf[i].getScaled(jpegHeight); if (scaledWidth <= desiredWidth && scaledHeight <= desiredHeight) break; } @@ -307,19 +307,19 @@ public class TJDecompressor { */ public int getScaledHeight(int desiredWidth, int desiredHeight) throws Exception { - if (srcWidth < 1 || srcHeight < 1) + if (jpegWidth < 1 || jpegHeight < 1) throw new Exception(NO_ASSOC_ERROR); if (desiredWidth < 0 || desiredHeight < 0) throw new Exception("Invalid argument in getScaledHeight()"); TJScalingFactor[] sf = TJ.getScalingFactors(); if (desiredWidth == 0) - desiredWidth = srcWidth; + desiredWidth = jpegWidth; if (desiredHeight == 0) - desiredHeight = srcHeight; - int scaledWidth = srcWidth, scaledHeight = srcHeight; + desiredHeight = jpegHeight; + int scaledWidth = jpegWidth, scaledHeight = jpegHeight; for (int i = 0; i < sf.length; i++) { - scaledWidth = sf[i].getScaled(srcWidth); - scaledHeight = sf[i].getScaled(srcHeight); + scaledWidth = sf[i].getScaled(jpegWidth); + scaledHeight = sf[i].getScaled(jpegHeight); if (scaledWidth <= desiredWidth && scaledHeight <= desiredHeight) break; } @@ -497,7 +497,7 @@ public class TJDecompressor { if (scaledWidth != dstImage.getWidth() || scaledHeight != dstImage.getHeight()) throw new Exception("YUVImage dimensions do not match one of the scaled image sizes that TurboJPEG is capable of generating."); - if (srcSubsamp != dstImage.getSubsamp()) + if (jpegSubsamp != dstImage.getSubsamp()) throw new Exception("YUVImage subsampling level does not match that of the JPEG image"); decompressToYUV(jpegBuf, jpegBufSize, dstImage.getBuf(), @@ -510,8 +510,8 @@ public class TJDecompressor { */ @Deprecated public void decompressToYUV(byte[] dstBuf, int flags) throws Exception { - YUVImage dstImage = new YUVImage(dstBuf, srcWidth, 4, srcHeight, - srcSubsamp); + YUVImage dstImage = new YUVImage(dstBuf, jpegWidth, 4, jpegHeight, + jpegSubsamp); decompressToYUV(dstImage, flags); } @@ -553,9 +553,9 @@ public class TJDecompressor { int flags) throws Exception { if (flags < 0) throw new Exception("Invalid argument in decompressToYUV()"); - if (srcWidth < 1 || srcHeight < 1 || srcSubsamp < 0) + if (jpegWidth < 1 || jpegHeight < 1 || jpegSubsamp < 0) throw new Exception(NO_ASSOC_ERROR); - if (srcSubsamp >= TJ.NUMSAMP) + if (jpegSubsamp >= TJ.NUMSAMP) throw new Exception("JPEG header information is invalid"); if (yuvImage != null) throw new Exception("Source image is the wrong type"); @@ -563,7 +563,7 @@ public class TJDecompressor { int scaledWidth = getScaledWidth(desiredWidth, desiredHeight); int scaledHeight = getScaledHeight(desiredWidth, desiredHeight); YUVImage yuvImage = new YUVImage(scaledWidth, pad, scaledHeight, - srcSubsamp); + jpegSubsamp); decompressToYUV(yuvImage, flags); return yuvImage; } @@ -573,7 +573,7 @@ public class TJDecompressor { */ @Deprecated public byte[] decompressToYUV(int flags) throws Exception { - YUVImage dstImage = new YUVImage(srcWidth, 4, srcHeight, srcSubsamp); + YUVImage dstImage = new YUVImage(jpegWidth, 4, jpegHeight, jpegSubsamp); decompressToYUV(dstImage, flags); return dstImage.getBuf(); } @@ -855,9 +855,9 @@ public class TJDecompressor { protected byte[] jpegBuf = null; protected int jpegBufSize = 0; protected YUVImage yuvImage = null; - protected int srcWidth = 0; - protected int srcHeight = 0; - protected int srcSubsamp = -1; - protected int srcColorspace = -1; + protected int jpegWidth = 0; + protected int jpegHeight = 0; + protected int jpegSubsamp = -1; + protected int jpegColorspace = -1; private ByteOrder byteOrder = null; }; diff --git a/turbojpeg-jni.c b/turbojpeg-jni.c index 5c1f6e3..55dc4ad 100644 --- a/turbojpeg-jni.c +++ b/turbojpeg-jni.c @@ -394,13 +394,15 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompress (*env)->ReleasePrimitiveArrayCritical(env, src, jpegBuf, 0); jpegBuf=NULL; - bailif0(_fid=(*env)->GetFieldID(env, _cls, "srcSubsamp", "I")); + bailif0(_fid=(*env)->GetFieldID(env, _cls, "jpegSubsamp", "I")); (*env)->SetIntField(env, obj, _fid, jpegSubsamp); - bailif0(_fid=(*env)->GetFieldID(env, _cls, "srcColorspace", "I")); - (*env)->SetIntField(env, obj, _fid, jpegColorspace); - bailif0(_fid=(*env)->GetFieldID(env, _cls, "srcWidth", "I")); + if((_fid=(*env)->GetFieldID(env, _cls, "jpegColorspace", "I"))==0) + (*env)->ExceptionClear(env); + else + (*env)->SetIntField(env, obj, _fid, jpegColorspace); + bailif0(_fid=(*env)->GetFieldID(env, _cls, "jpegWidth", "I")); (*env)->SetIntField(env, obj, _fid, width); - bailif0(_fid=(*env)->GetFieldID(env, _cls, "srcHeight", "I")); + bailif0(_fid=(*env)->GetFieldID(env, _cls, "jpegHeight", "I")); (*env)->SetIntField(env, obj, _fid, height); bailout: @@ -507,11 +509,11 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompress if((*env)->GetArrayLength(env, src)GetFieldID(env, _cls, "srcSubsamp", "I")); + bailif0(_fid=(*env)->GetFieldID(env, _cls, "jpegSubsamp", "I")); jpegSubsamp=(int)(*env)->GetIntField(env, obj, _fid); - bailif0(_fid=(*env)->GetFieldID(env, _cls, "srcWidth", "I")); + bailif0(_fid=(*env)->GetFieldID(env, _cls, "jpegWidth", "I")); jpegWidth=(int)(*env)->GetIntField(env, obj, _fid); - bailif0(_fid=(*env)->GetFieldID(env, _cls, "srcHeight", "I")); + bailif0(_fid=(*env)->GetFieldID(env, _cls, "jpegHeight", "I")); jpegHeight=(int)(*env)->GetIntField(env, obj, _fid); yuvSize=(jsize)tjBufSizeYUV2(desiredWidth==0? jpegWidth:desiredWidth, @@ -702,11 +704,11 @@ JNIEXPORT jintArray JNICALL Java_org_libjpegturbo_turbojpeg_TJTransformer_transf if((*env)->GetArrayLength(env, jsrcBuf)GetFieldID(env, _cls, "srcWidth", "I")); + bailif0(_fid=(*env)->GetFieldID(env, _cls, "jpegWidth", "I")); jpegWidth=(int)(*env)->GetIntField(env, obj, _fid); - bailif0(_fid=(*env)->GetFieldID(env, _cls, "srcHeight", "I")); + bailif0(_fid=(*env)->GetFieldID(env, _cls, "jpegHeight", "I")); jpegHeight=(int)(*env)->GetIntField(env, obj, _fid); - bailif0(_fid=(*env)->GetFieldID(env, _cls, "srcSubsamp", "I")); + bailif0(_fid=(*env)->GetFieldID(env, _cls, "jpegSubsamp", "I")); jpegSubsamp=(int)(*env)->GetIntField(env, obj, _fid); n=(*env)->GetArrayLength(env, dstobjs); -- 2.40.0