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;
_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)<arraySize)
+ arraySize=(y+height-1)*actualPitch + (x+width)*tjPixelSize[pf];
+ if((*env)->GetArrayLength(env, src)*srcElementSize<arraySize)
_throw("Source buffer is not large enough");
jpegSize=tjBufSize(width, height, jpegSubsamp);
if((*env)->GetArrayLength(env, dst)<(jsize)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 */
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 */
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)<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());
+ 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;
_throw("Mismatch between Java and C API");
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");
if((*env)->GetArrayLength(env, dst)
<(jsize)tjBufSizeYUV(width, height, subsamp))
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)<arraySize)
- _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());
+ 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;
}
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;
_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)<arraySize)
+ if((*env)->GetArrayLength(env, dst)*dstElementSize<arraySize)
_throw("Destination buffer is not large enough");
bailif0(jpegBuf=(*env)->GetPrimitiveArrayCritical(env, src, 0));
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 */
(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)<jpegSize)
- _throw("Source buffer is not large enough");
- 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());
+ 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;
}
(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;
}