From: DRC Date: Fri, 15 Aug 2014 16:20:06 +0000 (+0000) Subject: Allow the int pixel versions of the various TurboJPEG JNI functions to share the... X-Git-Tag: 1.3.90~26^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e31e49478c8f1d93cecdc40c18a1b8a189c5b157;p=libjpeg-turbo Allow the int pixel versions of the various TurboJPEG JNI functions to share the same code as the byte pixel versions. git-svn-id: svn+ssh://svn.code.sf.net/p/libjpeg-turbo/code/branches/1.3.x@1356 632fc199-4ca6-4c93-a231-07263d6284db --- diff --git a/turbojpeg-jni.c b/turbojpeg-jni.c index 361c491..58350c9 100644 --- a/turbojpeg-jni.c +++ b/turbojpeg-jni.c @@ -98,11 +98,10 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_init return; } -/* TurboJPEG 1.3.x: TJCompressor::compress() byte source */ -JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_compress___3BIIIIII_3BIII - (JNIEnv *env, jobject obj, jbyteArray src, jint x, jint y, jint width, - jint pitch, jint height, jint pf, jbyteArray dst, jint jpegSubsamp, - jint jpegQual, jint flags) +JNIEXPORT jint JNICALL TJCompressor_compress + (JNIEnv *env, jobject obj, jarray src, jint srcElementSize, jint x, jint y, + jint width, jint pitch, jint height, jint pf, jbyteArray dst, + jint jpegSubsamp, jint jpegQual, jint flags) { tjhandle handle=0; unsigned long jpegSize=0; @@ -118,8 +117,8 @@ JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_compress___3 _throw("Mismatch between Java and C API"); actualPitch=(pitch==0)? width*tjPixelSize[pf]:pitch; - arraySize=(y+height-1)*actualPitch + x+width; - if((*env)->GetArrayLength(env, src)GetArrayLength(env, src)*srcElementSizeGetArrayLength(env, dst)<(jsize)jpegSize) @@ -139,15 +138,24 @@ JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_compress___3 return (jint)jpegSize; } +/* TurboJPEG 1.3.x: TJCompressor::compress() byte source */ +JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_compress___3BIIIIII_3BIII + (JNIEnv *env, jobject obj, jbyteArray src, jint x, jint y, jint width, + jint pitch, jint height, jint pf, jbyteArray dst, jint jpegSubsamp, + jint jpegQual, jint flags) +{ + return TJCompressor_compress(env, obj, src, 1, x, y, width, pitch, height, + pf, dst, jpegSubsamp, jpegQual, flags); +} + /* TurboJPEG 1.2.x: TJCompressor::compress() byte source */ JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_compress___3BIIII_3BIII (JNIEnv *env, jobject obj, jbyteArray src, jint width, jint pitch, jint height, jint pf, jbyteArray dst, jint jpegSubsamp, jint jpegQual, jint flags) { - return Java_org_libjpegturbo_turbojpeg_TJCompressor_compress___3BIIIIII_3BIII( - env, obj, src, 0, 0, width, pitch, height, pf, dst, jpegSubsamp, jpegQual, - flags); + return TJCompressor_compress(env, obj, src, 1, 0, 0, width, pitch, height, + pf, dst, jpegSubsamp, jpegQual, flags); } /* TurboJPEG 1.3.x: TJCompressor::compress() int source */ @@ -156,58 +164,39 @@ JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_compress___3 jint stride, jint height, jint pf, jbyteArray dst, jint jpegSubsamp, jint jpegQual, jint flags) { - tjhandle handle=0; - unsigned long jpegSize=0; - jsize arraySize=0, actualStride; - unsigned char *srcBuf=NULL, *jpegBuf=NULL; - - gethandle(); - - if(pf<0 || pf>=org_libjpegturbo_turbojpeg_TJ_NUMPF || width<1 || height<1 - || stride<0) + if(pf<0 || pf>=org_libjpegturbo_turbojpeg_TJ_NUMPF) _throw("Invalid argument in compress()"); - if(org_libjpegturbo_turbojpeg_TJ_NUMPF!=TJ_NUMPF) - _throw("Mismatch between Java and C API"); if(tjPixelSize[pf]!=sizeof(jint)) _throw("Pixel format must be 32-bit when compressing from an integer buffer."); - actualStride=(stride==0)? width:stride; - arraySize=(y+height-1)*actualStride + x+width; - if((*env)->GetArrayLength(env, src)GetArrayLength(env, dst)<(jsize)jpegSize) - _throw("Destination buffer is not large enough"); - - bailif0(srcBuf=(*env)->GetPrimitiveArrayCritical(env, src, 0)); - bailif0(jpegBuf=(*env)->GetPrimitiveArrayCritical(env, dst, 0)); - - if(tjCompress2(handle, &srcBuf[(y*actualStride + x)*sizeof(int)], width, - stride*sizeof(jint), height, pf, &jpegBuf, &jpegSize, jpegSubsamp, - jpegQual, flags|TJFLAG_NOREALLOC)==-1) - _throw(tjGetErrorStr()); + return TJCompressor_compress(env, obj, src, sizeof(jint), x, y, width, + stride*sizeof(jint), height, pf, dst, jpegSubsamp, jpegQual, flags); bailout: - if(jpegBuf) (*env)->ReleasePrimitiveArrayCritical(env, dst, jpegBuf, 0); - if(srcBuf) (*env)->ReleasePrimitiveArrayCritical(env, src, srcBuf, 0); - return (jint)jpegSize; + return 0; } /* TurboJPEG 1.2.x: TJCompressor::compress() int source */ JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_compress___3IIIII_3BIII - (JNIEnv *env, jobject obj, jintArray src, jint width, jint pitch, + (JNIEnv *env, jobject obj, jintArray src, jint width, jint stride, jint height, jint pf, jbyteArray dst, jint jpegSubsamp, jint jpegQual, jint flags) { - return Java_org_libjpegturbo_turbojpeg_TJCompressor_compress___3IIIIIII_3BIII( - env, obj, src, 0, 0, width, pitch, height, pf, dst, jpegSubsamp, jpegQual, - flags); + if(pf<0 || pf>=org_libjpegturbo_turbojpeg_TJ_NUMPF) + _throw("Invalid argument in compress()"); + if(tjPixelSize[pf]!=sizeof(jint)) + _throw("Pixel format must be 32-bit when compressing from an integer buffer."); + + return TJCompressor_compress(env, obj, src, sizeof(jint), 0, 0, width, + stride*sizeof(jint), height, pf, dst, jpegSubsamp, jpegQual, flags); + + bailout: + return 0; } -/* TurboJPEG 1.2.x: TJCompressor::encodeYUV() byte source */ -JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___3BIIII_3BII - (JNIEnv *env, jobject obj, jbyteArray src, jint width, jint pitch, - jint height, jint pf, jbyteArray dst, jint subsamp, jint flags) +JNIEXPORT void JNICALL TJCompressor_encodeYUV + (JNIEnv *env, jobject obj, jarray src, jint srcElementSize, jint width, + jint pitch, jint height, jint pf, jbyteArray dst, jint subsamp, jint flags) { tjhandle handle=0; jsize arraySize=0; @@ -222,7 +211,7 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___ _throw("Mismatch between Java and C API"); arraySize=(pitch==0)? width*tjPixelSize[pf]*height:pitch*height; - if((*env)->GetArrayLength(env, src)GetArrayLength(env, src)*srcElementSizeGetArrayLength(env, dst) <(jsize)tjBufSizeYUV(width, height, subsamp)) @@ -241,42 +230,29 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___ return; } +/* TurboJPEG 1.2.x: TJCompressor::encodeYUV() byte source */ +JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___3BIIII_3BII + (JNIEnv *env, jobject obj, jbyteArray src, jint width, jint pitch, + jint height, jint pf, jbyteArray dst, jint subsamp, jint flags) +{ + TJCompressor_encodeYUV(env, obj, src, 1, width, pitch, height, pf, dst, + subsamp, flags); +} + /* TurboJPEG 1.2.x: TJCompressor::encodeYUV() int source */ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___3IIIII_3BII (JNIEnv *env, jobject obj, jintArray src, jint width, jint stride, jint height, jint pf, jbyteArray dst, jint subsamp, jint flags) { - tjhandle handle=0; - jsize arraySize=0; - unsigned char *srcBuf=NULL, *dstBuf=NULL; - - gethandle(); - - if(pf<0 || pf>=org_libjpegturbo_turbojpeg_TJ_NUMPF || width<1 || height<1 - || stride<0) + if(pf<0 || pf>=org_libjpegturbo_turbojpeg_TJ_NUMPF) _throw("Invalid argument in encodeYUV()"); - if(org_libjpegturbo_turbojpeg_TJ_NUMPF!=TJ_NUMPF) - _throw("Mismatch between Java and C API"); if(tjPixelSize[pf]!=sizeof(jint)) _throw("Pixel format must be 32-bit when encoding from an integer buffer."); - arraySize=(stride==0)? width*height:stride*height; - if((*env)->GetArrayLength(env, src)GetArrayLength(env, dst) - <(jsize)tjBufSizeYUV(width, height, subsamp)) - _throw("Destination buffer is not large enough"); - - bailif0(srcBuf=(*env)->GetPrimitiveArrayCritical(env, src, 0)); - bailif0(dstBuf=(*env)->GetPrimitiveArrayCritical(env, dst, 0)); - - if(tjEncodeYUV2(handle, srcBuf, width, stride*sizeof(jint), height, pf, - dstBuf, subsamp, flags)==-1) - _throw(tjGetErrorStr()); + TJCompressor_encodeYUV(env, obj, src, sizeof(jint), width, + stride*sizeof(jint), height, pf, dst, subsamp, flags); bailout: - if(dstBuf) (*env)->ReleasePrimitiveArrayCritical(env, dst, dstBuf, 0); - if(srcBuf) (*env)->ReleasePrimitiveArrayCritical(env, src, srcBuf, 0); return; } @@ -375,10 +351,10 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompress return; } -/* TurboJPEG 1.3.x: TJDecompressor::decompress() byte destination */ -JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompress___3BI_3BIIIIIII - (JNIEnv *env, jobject obj, jbyteArray src, jint jpegSize, jbyteArray dst, - jint x, jint y, jint width, jint pitch, jint height, jint pf, jint flags) +JNIEXPORT void JNICALL TJDecompressor_decompress + (JNIEnv *env, jobject obj, jbyteArray src, jint jpegSize, jarray dst, + jint dstElementSize, jint x, jint y, jint width, jint pitch, jint height, + jint pf, jint flags) { tjhandle handle=0; jsize arraySize=0, actualPitch; @@ -395,7 +371,7 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompress _throw("Source buffer is not large enough"); actualPitch=(pitch==0)? width*tjPixelSize[pf]:pitch; arraySize=(y+height-1)*actualPitch + (x+width)*tjPixelSize[pf]; - if((*env)->GetArrayLength(env, dst)GetArrayLength(env, dst)*dstElementSizeGetPrimitiveArrayCritical(env, src, 0)); @@ -412,13 +388,22 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompress return; } +/* TurboJPEG 1.3.x: TJDecompressor::decompress() byte destination */ +JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompress___3BI_3BIIIIIII + (JNIEnv *env, jobject obj, jbyteArray src, jint jpegSize, jbyteArray dst, + jint x, jint y, jint width, jint pitch, jint height, jint pf, jint flags) +{ + TJDecompressor_decompress(env, obj, src, jpegSize, dst, 1, x, y, width, + pitch, height, pf, flags); +} + /* TurboJPEG 1.2.x: TJDecompressor::decompress() byte destination */ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompress___3BI_3BIIIII (JNIEnv *env, jobject obj, jbyteArray src, jint jpegSize, jbyteArray dst, jint width, jint pitch, jint height, jint pf, jint flags) { - Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompress___3BI_3BIIIIIII - (env, obj, src, jpegSize, dst, 0, 0, width, pitch, height, pf, flags); + TJDecompressor_decompress(env, obj, src, jpegSize, dst, 1, 0, 0, width, + pitch, height, pf, flags); } /* TurboJPEG 1.3.x: TJDecompressor::decompress() int destination */ @@ -426,37 +411,15 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompress (JNIEnv *env, jobject obj, jbyteArray src, jint jpegSize, jintArray dst, jint x, jint y, jint width, jint stride, jint height, jint pf, jint flags) { - tjhandle handle=0; - jsize arraySize=0, actualStride; - unsigned char *jpegBuf=NULL, *dstBuf=NULL; - - gethandle(); - if(pf<0 || pf>=org_libjpegturbo_turbojpeg_TJ_NUMPF) _throw("Invalid argument in decompress()"); - if(org_libjpegturbo_turbojpeg_TJ_NUMPF!=TJ_NUMPF) - _throw("Mismatch between Java and C API"); if(tjPixelSize[pf]!=sizeof(jint)) _throw("Pixel format must be 32-bit when decompressing to an integer buffer."); - if((*env)->GetArrayLength(env, src)GetArrayLength(env, dst)GetPrimitiveArrayCritical(env, src, 0)); - bailif0(dstBuf=(*env)->GetPrimitiveArrayCritical(env, dst, 0)); - - if(tjDecompress2(handle, jpegBuf, (unsigned long)jpegSize, - &dstBuf[(y*actualStride + x)*sizeof(int)], width, stride*sizeof(jint), - height, pf, flags)==-1) - _throw(tjGetErrorStr()); + TJDecompressor_decompress(env, obj, src, jpegSize, dst, sizeof(jint), x, y, + width, stride*sizeof(jint), height, pf, flags); bailout: - if(dstBuf) (*env)->ReleasePrimitiveArrayCritical(env, dst, dstBuf, 0); - if(jpegBuf) (*env)->ReleasePrimitiveArrayCritical(env, src, jpegBuf, 0); return; } @@ -465,8 +428,16 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompress (JNIEnv *env, jobject obj, jbyteArray src, jint jpegSize, jintArray dst, jint width, jint stride, jint height, jint pf, jint flags) { - Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompress___3BI_3IIIIIIII - (env, obj, src, jpegSize, dst, 0, 0, width, stride, height, pf, flags); + if(pf<0 || pf>=org_libjpegturbo_turbojpeg_TJ_NUMPF) + _throw("Invalid argument in decompress()"); + if(tjPixelSize[pf]!=sizeof(jint)) + _throw("Pixel format must be 32-bit when decompressing to an integer buffer."); + + TJDecompressor_decompress(env, obj, src, jpegSize, dst, sizeof(jint), 0, 0, + width, stride*sizeof(jint), height, pf, flags); + + bailout: + return; }