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
This commit is contained in:
DRC
2014-08-15 16:20:06 +00:00
parent 32760451fe
commit e31e49478c

View File

@@ -98,11 +98,10 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_init
return; return;
} }
/* TurboJPEG 1.3.x: TJCompressor::compress() byte source */ JNIEXPORT jint JNICALL TJCompressor_compress
JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_compress___3BIIIIII_3BIII (JNIEnv *env, jobject obj, jarray src, jint srcElementSize, jint x, jint y,
(JNIEnv *env, jobject obj, jbyteArray src, jint x, jint y, jint width, jint width, jint pitch, jint height, jint pf, jbyteArray dst,
jint pitch, jint height, jint pf, jbyteArray dst, jint jpegSubsamp, jint jpegSubsamp, jint jpegQual, jint flags)
jint jpegQual, jint flags)
{ {
tjhandle handle=0; tjhandle handle=0;
unsigned long jpegSize=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"); _throw("Mismatch between Java and C API");
actualPitch=(pitch==0)? width*tjPixelSize[pf]:pitch; actualPitch=(pitch==0)? width*tjPixelSize[pf]:pitch;
arraySize=(y+height-1)*actualPitch + x+width; arraySize=(y+height-1)*actualPitch + (x+width)*tjPixelSize[pf];
if((*env)->GetArrayLength(env, src)<arraySize) if((*env)->GetArrayLength(env, src)*srcElementSize<arraySize)
_throw("Source buffer is not large enough"); _throw("Source buffer is not large enough");
jpegSize=tjBufSize(width, height, jpegSubsamp); jpegSize=tjBufSize(width, height, jpegSubsamp);
if((*env)->GetArrayLength(env, dst)<(jsize)jpegSize) if((*env)->GetArrayLength(env, dst)<(jsize)jpegSize)
@@ -139,15 +138,24 @@ JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_compress___3
return (jint)jpegSize; 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 */ /* TurboJPEG 1.2.x: TJCompressor::compress() byte source */
JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_compress___3BIIII_3BIII JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_compress___3BIIII_3BIII
(JNIEnv *env, jobject obj, jbyteArray src, jint width, jint pitch, (JNIEnv *env, jobject obj, jbyteArray src, jint width, jint pitch,
jint height, jint pf, jbyteArray dst, jint jpegSubsamp, jint jpegQual, jint height, jint pf, jbyteArray dst, jint jpegSubsamp, jint jpegQual,
jint flags) jint flags)
{ {
return Java_org_libjpegturbo_turbojpeg_TJCompressor_compress___3BIIIIII_3BIII( return TJCompressor_compress(env, obj, src, 1, 0, 0, width, pitch, height,
env, obj, src, 0, 0, width, pitch, height, pf, dst, jpegSubsamp, jpegQual, pf, dst, jpegSubsamp, jpegQual, flags);
flags);
} }
/* TurboJPEG 1.3.x: TJCompressor::compress() int source */ /* 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 stride, jint height, jint pf, jbyteArray dst, jint jpegSubsamp,
jint jpegQual, jint flags) jint jpegQual, jint flags)
{ {
tjhandle handle=0; if(pf<0 || pf>=org_libjpegturbo_turbojpeg_TJ_NUMPF)
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)
_throw("Invalid argument in compress()"); _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)) if(tjPixelSize[pf]!=sizeof(jint))
_throw("Pixel format must be 32-bit when compressing from an integer buffer."); _throw("Pixel format must be 32-bit when compressing from an integer buffer.");
actualStride=(stride==0)? width:stride; return TJCompressor_compress(env, obj, src, sizeof(jint), x, y, width,
arraySize=(y+height-1)*actualStride + x+width; stride*sizeof(jint), height, pf, dst, jpegSubsamp, jpegQual, flags);
if((*env)->GetArrayLength(env, src)<arraySize)
_throw("Source buffer is not large enough");
jpegSize=tjBufSize(width, height, jpegSubsamp);
if((*env)->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());
bailout: bailout:
if(jpegBuf) (*env)->ReleasePrimitiveArrayCritical(env, dst, jpegBuf, 0); return 0;
if(srcBuf) (*env)->ReleasePrimitiveArrayCritical(env, src, srcBuf, 0);
return (jint)jpegSize;
} }
/* TurboJPEG 1.2.x: TJCompressor::compress() int source */ /* TurboJPEG 1.2.x: TJCompressor::compress() int source */
JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_compress___3IIIII_3BIII 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 height, jint pf, jbyteArray dst, jint jpegSubsamp, jint jpegQual,
jint flags) jint flags)
{ {
return Java_org_libjpegturbo_turbojpeg_TJCompressor_compress___3IIIIIII_3BIII( if(pf<0 || pf>=org_libjpegturbo_turbojpeg_TJ_NUMPF)
env, obj, src, 0, 0, width, pitch, height, pf, dst, jpegSubsamp, jpegQual, _throw("Invalid argument in compress()");
flags); 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 TJCompressor_encodeYUV
JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___3BIIII_3BII (JNIEnv *env, jobject obj, jarray src, jint srcElementSize, jint width,
(JNIEnv *env, jobject obj, jbyteArray src, jint width, jint pitch, jint pitch, jint height, jint pf, jbyteArray dst, jint subsamp, jint flags)
jint height, jint pf, jbyteArray dst, jint subsamp, jint flags)
{ {
tjhandle handle=0; tjhandle handle=0;
jsize arraySize=0; jsize arraySize=0;
@@ -222,7 +211,7 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___
_throw("Mismatch between Java and C API"); _throw("Mismatch between Java and C API");
arraySize=(pitch==0)? width*tjPixelSize[pf]*height:pitch*height; arraySize=(pitch==0)? width*tjPixelSize[pf]*height:pitch*height;
if((*env)->GetArrayLength(env, src)<arraySize) if((*env)->GetArrayLength(env, src)*srcElementSize<arraySize)
_throw("Source buffer is not large enough"); _throw("Source buffer is not large enough");
if((*env)->GetArrayLength(env, dst) if((*env)->GetArrayLength(env, dst)
<(jsize)tjBufSizeYUV(width, height, subsamp)) <(jsize)tjBufSizeYUV(width, height, subsamp))
@@ -241,42 +230,29 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___
return; 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 */ /* TurboJPEG 1.2.x: TJCompressor::encodeYUV() int source */
JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___3IIIII_3BII JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___3IIIII_3BII
(JNIEnv *env, jobject obj, jintArray src, jint width, jint stride, (JNIEnv *env, jobject obj, jintArray src, jint width, jint stride,
jint height, jint pf, jbyteArray dst, jint subsamp, jint flags) jint height, jint pf, jbyteArray dst, jint subsamp, jint flags)
{ {
tjhandle handle=0; if(pf<0 || pf>=org_libjpegturbo_turbojpeg_TJ_NUMPF)
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)
_throw("Invalid argument in encodeYUV()"); _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)) if(tjPixelSize[pf]!=sizeof(jint))
_throw("Pixel format must be 32-bit when encoding from an integer buffer."); _throw("Pixel format must be 32-bit when encoding from an integer buffer.");
arraySize=(stride==0)? width*height:stride*height; TJCompressor_encodeYUV(env, obj, src, sizeof(jint), width,
if((*env)->GetArrayLength(env, src)<arraySize) stride*sizeof(jint), height, pf, dst, subsamp, flags);
_throw("Source buffer is not large enough");
if((*env)->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());
bailout: bailout:
if(dstBuf) (*env)->ReleasePrimitiveArrayCritical(env, dst, dstBuf, 0);
if(srcBuf) (*env)->ReleasePrimitiveArrayCritical(env, src, srcBuf, 0);
return; return;
} }
@@ -375,10 +351,10 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompress
return; return;
} }
/* TurboJPEG 1.3.x: TJDecompressor::decompress() byte destination */ JNIEXPORT void JNICALL TJDecompressor_decompress
JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompress___3BI_3BIIIIIII (JNIEnv *env, jobject obj, jbyteArray src, jint jpegSize, jarray dst,
(JNIEnv *env, jobject obj, jbyteArray src, jint jpegSize, jbyteArray dst, jint dstElementSize, jint x, jint y, jint width, jint pitch, jint height,
jint x, jint y, jint width, jint pitch, jint height, jint pf, jint flags) jint pf, jint flags)
{ {
tjhandle handle=0; tjhandle handle=0;
jsize arraySize=0, actualPitch; jsize arraySize=0, actualPitch;
@@ -395,7 +371,7 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompress
_throw("Source buffer is not large enough"); _throw("Source buffer is not large enough");
actualPitch=(pitch==0)? width*tjPixelSize[pf]:pitch; actualPitch=(pitch==0)? width*tjPixelSize[pf]:pitch;
arraySize=(y+height-1)*actualPitch + (x+width)*tjPixelSize[pf]; arraySize=(y+height-1)*actualPitch + (x+width)*tjPixelSize[pf];
if((*env)->GetArrayLength(env, dst)<arraySize) if((*env)->GetArrayLength(env, dst)*dstElementSize<arraySize)
_throw("Destination buffer is not large enough"); _throw("Destination buffer is not large enough");
bailif0(jpegBuf=(*env)->GetPrimitiveArrayCritical(env, src, 0)); bailif0(jpegBuf=(*env)->GetPrimitiveArrayCritical(env, src, 0));
@@ -412,13 +388,22 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompress
return; 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 */ /* TurboJPEG 1.2.x: TJDecompressor::decompress() byte destination */
JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompress___3BI_3BIIIII JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompress___3BI_3BIIIII
(JNIEnv *env, jobject obj, jbyteArray src, jint jpegSize, jbyteArray dst, (JNIEnv *env, jobject obj, jbyteArray src, jint jpegSize, jbyteArray dst,
jint width, jint pitch, jint height, jint pf, jint flags) jint width, jint pitch, jint height, jint pf, jint flags)
{ {
Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompress___3BI_3BIIIIIII TJDecompressor_decompress(env, obj, src, jpegSize, dst, 1, 0, 0, width,
(env, obj, src, jpegSize, dst, 0, 0, width, pitch, height, pf, flags); pitch, height, pf, flags);
} }
/* TurboJPEG 1.3.x: TJDecompressor::decompress() int destination */ /* 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, (JNIEnv *env, jobject obj, jbyteArray src, jint jpegSize, jintArray dst,
jint x, jint y, jint width, jint stride, jint height, jint pf, jint flags) 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) if(pf<0 || pf>=org_libjpegturbo_turbojpeg_TJ_NUMPF)
_throw("Invalid argument in decompress()"); _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)) if(tjPixelSize[pf]!=sizeof(jint))
_throw("Pixel format must be 32-bit when decompressing to an integer buffer."); _throw("Pixel format must be 32-bit when decompressing to an integer buffer.");
if((*env)->GetArrayLength(env, src)<jpegSize) TJDecompressor_decompress(env, obj, src, jpegSize, dst, sizeof(jint), x, y,
_throw("Source buffer is not large enough"); width, stride*sizeof(jint), height, pf, flags);
actualStride=(stride==0)? width:stride;
arraySize=(y+height-1)*actualStride + x+width;
if((*env)->GetArrayLength(env, dst)<arraySize)
_throw("Destination buffer is not large enough");
bailif0(jpegBuf=(*env)->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());
bailout: bailout:
if(dstBuf) (*env)->ReleasePrimitiveArrayCritical(env, dst, dstBuf, 0);
if(jpegBuf) (*env)->ReleasePrimitiveArrayCritical(env, src, jpegBuf, 0);
return; return;
} }
@@ -465,8 +428,16 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompress
(JNIEnv *env, jobject obj, jbyteArray src, jint jpegSize, jintArray dst, (JNIEnv *env, jobject obj, jbyteArray src, jint jpegSize, jintArray dst,
jint width, jint stride, jint height, jint pf, jint flags) jint width, jint stride, jint height, jint pf, jint flags)
{ {
Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompress___3BI_3IIIIIIII if(pf<0 || pf>=org_libjpegturbo_turbojpeg_TJ_NUMPF)
(env, obj, src, jpegSize, dst, 0, 0, width, stride, height, pf, flags); _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;
} }