@@ -1,3 +1,11 @@
|
|||||||
|
2.0.6
|
||||||
|
=====
|
||||||
|
|
||||||
|
1. Fixed "using JNI after critical get" errors that occurred on Android
|
||||||
|
platforms when using any of the YUV encoding/compression/decompression/decoding
|
||||||
|
methods in the TurboJPEG Java API.
|
||||||
|
|
||||||
|
|
||||||
2.0.5
|
2.0.5
|
||||||
=====
|
=====
|
||||||
|
|
||||||
|
|||||||
200
turbojpeg-jni.c
200
turbojpeg-jni.c
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C)2011-2019 D. R. Commander. All Rights Reserved.
|
* Copyright (C)2011-2020 D. R. Commander. All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions are met:
|
* modification, are permitted provided that the following conditions are met:
|
||||||
@@ -326,9 +326,11 @@ JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_compressFrom
|
|||||||
tjhandle handle = 0;
|
tjhandle handle = 0;
|
||||||
unsigned long jpegSize = 0;
|
unsigned long jpegSize = 0;
|
||||||
jbyteArray jSrcPlanes[3] = { NULL, NULL, NULL };
|
jbyteArray jSrcPlanes[3] = { NULL, NULL, NULL };
|
||||||
const unsigned char *srcPlanes[3];
|
const unsigned char *srcPlanesTmp[3] = { NULL, NULL, NULL };
|
||||||
|
const unsigned char *srcPlanes[3] = { NULL, NULL, NULL };
|
||||||
|
int *srcOffsetsTmp = NULL, srcOffsets[3] = { 0, 0, 0 };
|
||||||
|
int *srcStridesTmp = NULL, srcStrides[3] = { 0, 0, 0 };
|
||||||
unsigned char *jpegBuf = NULL;
|
unsigned char *jpegBuf = NULL;
|
||||||
int *srcOffsets = NULL, *srcStrides = NULL;
|
|
||||||
int nc = (subsamp == org_libjpegturbo_turbojpeg_TJ_SAMP_GRAY ? 1 : 3), i;
|
int nc = (subsamp == org_libjpegturbo_turbojpeg_TJ_SAMP_GRAY ? 1 : 3), i;
|
||||||
|
|
||||||
GET_HANDLE();
|
GET_HANDLE();
|
||||||
@@ -351,56 +353,49 @@ JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_compressFrom
|
|||||||
|
|
||||||
if (ProcessSystemProperties(env) < 0) goto bailout;
|
if (ProcessSystemProperties(env) < 0) goto bailout;
|
||||||
|
|
||||||
#define RELEASE_ARRAYS_COMPRESSFROMYUV() { \
|
BAILIF0(srcOffsetsTmp =
|
||||||
SAFE_RELEASE(dst, jpegBuf); \
|
(*env)->GetPrimitiveArrayCritical(env, jSrcOffsets, 0));
|
||||||
for (i = 0; i < nc; i++) \
|
for (i = 0; i < nc; i++) srcOffsets[i] = srcOffsetsTmp[i];
|
||||||
SAFE_RELEASE(jSrcPlanes[i], srcPlanes[i]); \
|
SAFE_RELEASE(jSrcOffsets, srcOffsetsTmp);
|
||||||
SAFE_RELEASE(jSrcStrides, srcStrides); \
|
|
||||||
SAFE_RELEASE(jSrcOffsets, srcOffsets); \
|
BAILIF0(srcStridesTmp =
|
||||||
}
|
(*env)->GetPrimitiveArrayCritical(env, jSrcStrides, 0));
|
||||||
|
for (i = 0; i < nc; i++) srcStrides[i] = srcStridesTmp[i];
|
||||||
|
SAFE_RELEASE(jSrcStrides, srcStridesTmp);
|
||||||
|
|
||||||
BAILIF0(srcOffsets = (*env)->GetPrimitiveArrayCritical(env, jSrcOffsets, 0));
|
|
||||||
BAILIF0(srcStrides = (*env)->GetPrimitiveArrayCritical(env, jSrcStrides, 0));
|
|
||||||
for (i = 0; i < nc; i++) {
|
for (i = 0; i < nc; i++) {
|
||||||
int planeSize = tjPlaneSizeYUV(i, width, srcStrides[i], height, subsamp);
|
int planeSize = tjPlaneSizeYUV(i, width, srcStrides[i], height, subsamp);
|
||||||
int pw = tjPlaneWidth(i, width, subsamp);
|
int pw = tjPlaneWidth(i, width, subsamp);
|
||||||
|
|
||||||
if (planeSize < 0 || pw < 0) {
|
if (planeSize < 0 || pw < 0)
|
||||||
RELEASE_ARRAYS_COMPRESSFROMYUV();
|
|
||||||
THROW_ARG(tjGetErrorStr());
|
THROW_ARG(tjGetErrorStr());
|
||||||
}
|
|
||||||
|
|
||||||
if (srcOffsets[i] < 0) {
|
if (srcOffsets[i] < 0)
|
||||||
RELEASE_ARRAYS_COMPRESSFROMYUV();
|
|
||||||
THROW_ARG("Invalid argument in compressFromYUV()");
|
THROW_ARG("Invalid argument in compressFromYUV()");
|
||||||
}
|
if (srcStrides[i] < 0 && srcOffsets[i] - planeSize + pw < 0)
|
||||||
if (srcStrides[i] < 0 && srcOffsets[i] - planeSize + pw < 0) {
|
|
||||||
RELEASE_ARRAYS_COMPRESSFROMYUV();
|
|
||||||
THROW_ARG("Negative plane stride would cause memory to be accessed below plane boundary");
|
THROW_ARG("Negative plane stride would cause memory to be accessed below plane boundary");
|
||||||
}
|
|
||||||
|
|
||||||
BAILIF0(jSrcPlanes[i] = (*env)->GetObjectArrayElement(env, srcobjs, i));
|
BAILIF0(jSrcPlanes[i] = (*env)->GetObjectArrayElement(env, srcobjs, i));
|
||||||
if ((*env)->GetArrayLength(env, jSrcPlanes[i]) <
|
if ((*env)->GetArrayLength(env, jSrcPlanes[i]) <
|
||||||
srcOffsets[i] + planeSize) {
|
srcOffsets[i] + planeSize)
|
||||||
RELEASE_ARRAYS_COMPRESSFROMYUV();
|
|
||||||
THROW_ARG("Source plane is not large enough");
|
THROW_ARG("Source plane is not large enough");
|
||||||
}
|
|
||||||
|
|
||||||
BAILIF0(srcPlanes[i] =
|
BAILIF0(srcPlanesTmp[i] =
|
||||||
(*env)->GetPrimitiveArrayCritical(env, jSrcPlanes[i], 0));
|
(*env)->GetPrimitiveArrayCritical(env, jSrcPlanes[i], 0));
|
||||||
srcPlanes[i] = &srcPlanes[i][srcOffsets[i]];
|
srcPlanes[i] = &srcPlanesTmp[i][srcOffsets[i]];
|
||||||
|
SAFE_RELEASE(jSrcPlanes[i], srcPlanesTmp[i]);
|
||||||
}
|
}
|
||||||
BAILIF0(jpegBuf = (*env)->GetPrimitiveArrayCritical(env, dst, 0));
|
BAILIF0(jpegBuf = (*env)->GetPrimitiveArrayCritical(env, dst, 0));
|
||||||
|
|
||||||
if (tjCompressFromYUVPlanes(handle, srcPlanes, width, srcStrides, height,
|
if (tjCompressFromYUVPlanes(handle, srcPlanes, width, srcStrides, height,
|
||||||
subsamp, &jpegBuf, &jpegSize, jpegQual,
|
subsamp, &jpegBuf, &jpegSize, jpegQual,
|
||||||
flags | TJFLAG_NOREALLOC) == -1) {
|
flags | TJFLAG_NOREALLOC) == -1) {
|
||||||
RELEASE_ARRAYS_COMPRESSFROMYUV();
|
SAFE_RELEASE(dst, jpegBuf);
|
||||||
THROW_TJ();
|
THROW_TJ();
|
||||||
}
|
}
|
||||||
|
|
||||||
bailout:
|
bailout:
|
||||||
RELEASE_ARRAYS_COMPRESSFROMYUV();
|
SAFE_RELEASE(dst, jpegBuf);
|
||||||
return (jint)jpegSize;
|
return (jint)jpegSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -411,9 +406,12 @@ static void TJCompressor_encodeYUV
|
|||||||
{
|
{
|
||||||
tjhandle handle = 0;
|
tjhandle handle = 0;
|
||||||
jsize arraySize = 0, actualPitch;
|
jsize arraySize = 0, actualPitch;
|
||||||
|
unsigned char *srcBuf = NULL;
|
||||||
jbyteArray jDstPlanes[3] = { NULL, NULL, NULL };
|
jbyteArray jDstPlanes[3] = { NULL, NULL, NULL };
|
||||||
unsigned char *srcBuf = NULL, *dstPlanes[3];
|
unsigned char *dstPlanesTmp[3] = { NULL, NULL, NULL };
|
||||||
int *dstOffsets = NULL, *dstStrides = NULL;
|
unsigned char *dstPlanes[3] = { NULL, NULL, NULL };
|
||||||
|
int *dstOffsetsTmp = NULL, dstOffsets[3] = { 0, 0, 0 };
|
||||||
|
int *dstStridesTmp = NULL, dstStrides[3] = { 0, 0, 0 };
|
||||||
int nc = (subsamp == org_libjpegturbo_turbojpeg_TJ_SAMP_GRAY ? 1 : 3), i;
|
int nc = (subsamp == org_libjpegturbo_turbojpeg_TJ_SAMP_GRAY ? 1 : 3), i;
|
||||||
|
|
||||||
GET_HANDLE();
|
GET_HANDLE();
|
||||||
@@ -438,56 +436,49 @@ static void TJCompressor_encodeYUV
|
|||||||
if ((*env)->GetArrayLength(env, src) * srcElementSize < arraySize)
|
if ((*env)->GetArrayLength(env, src) * srcElementSize < arraySize)
|
||||||
THROW_ARG("Source buffer is not large enough");
|
THROW_ARG("Source buffer is not large enough");
|
||||||
|
|
||||||
#define RELEASE_ARRAYS_ENCODEYUV() { \
|
BAILIF0(dstOffsetsTmp =
|
||||||
SAFE_RELEASE(src, srcBuf); \
|
(*env)->GetPrimitiveArrayCritical(env, jDstOffsets, 0));
|
||||||
for (i = 0; i < nc; i++) \
|
for (i = 0; i < nc; i++) dstOffsets[i] = dstOffsetsTmp[i];
|
||||||
SAFE_RELEASE(jDstPlanes[i], dstPlanes[i]); \
|
SAFE_RELEASE(jDstOffsets, dstOffsetsTmp);
|
||||||
SAFE_RELEASE(jDstStrides, dstStrides); \
|
|
||||||
SAFE_RELEASE(jDstOffsets, dstOffsets); \
|
BAILIF0(dstStridesTmp =
|
||||||
}
|
(*env)->GetPrimitiveArrayCritical(env, jDstStrides, 0));
|
||||||
|
for (i = 0; i < nc; i++) dstStrides[i] = dstStridesTmp[i];
|
||||||
|
SAFE_RELEASE(jDstStrides, dstStridesTmp);
|
||||||
|
|
||||||
BAILIF0(dstOffsets = (*env)->GetPrimitiveArrayCritical(env, jDstOffsets, 0));
|
|
||||||
BAILIF0(dstStrides = (*env)->GetPrimitiveArrayCritical(env, jDstStrides, 0));
|
|
||||||
for (i = 0; i < nc; i++) {
|
for (i = 0; i < nc; i++) {
|
||||||
int planeSize = tjPlaneSizeYUV(i, width, dstStrides[i], height, subsamp);
|
int planeSize = tjPlaneSizeYUV(i, width, dstStrides[i], height, subsamp);
|
||||||
int pw = tjPlaneWidth(i, width, subsamp);
|
int pw = tjPlaneWidth(i, width, subsamp);
|
||||||
|
|
||||||
if (planeSize < 0 || pw < 0) {
|
if (planeSize < 0 || pw < 0)
|
||||||
RELEASE_ARRAYS_ENCODEYUV();
|
|
||||||
THROW_ARG(tjGetErrorStr());
|
THROW_ARG(tjGetErrorStr());
|
||||||
}
|
|
||||||
|
|
||||||
if (dstOffsets[i] < 0) {
|
if (dstOffsets[i] < 0)
|
||||||
RELEASE_ARRAYS_ENCODEYUV();
|
|
||||||
THROW_ARG("Invalid argument in encodeYUV()");
|
THROW_ARG("Invalid argument in encodeYUV()");
|
||||||
}
|
if (dstStrides[i] < 0 && dstOffsets[i] - planeSize + pw < 0)
|
||||||
if (dstStrides[i] < 0 && dstOffsets[i] - planeSize + pw < 0) {
|
|
||||||
RELEASE_ARRAYS_ENCODEYUV();
|
|
||||||
THROW_ARG("Negative plane stride would cause memory to be accessed below plane boundary");
|
THROW_ARG("Negative plane stride would cause memory to be accessed below plane boundary");
|
||||||
}
|
|
||||||
|
|
||||||
BAILIF0(jDstPlanes[i] = (*env)->GetObjectArrayElement(env, dstobjs, i));
|
BAILIF0(jDstPlanes[i] = (*env)->GetObjectArrayElement(env, dstobjs, i));
|
||||||
if ((*env)->GetArrayLength(env, jDstPlanes[i]) <
|
if ((*env)->GetArrayLength(env, jDstPlanes[i]) <
|
||||||
dstOffsets[i] + planeSize) {
|
dstOffsets[i] + planeSize)
|
||||||
RELEASE_ARRAYS_ENCODEYUV();
|
|
||||||
THROW_ARG("Destination plane is not large enough");
|
THROW_ARG("Destination plane is not large enough");
|
||||||
}
|
|
||||||
|
|
||||||
BAILIF0(dstPlanes[i] =
|
BAILIF0(dstPlanesTmp[i] =
|
||||||
(*env)->GetPrimitiveArrayCritical(env, jDstPlanes[i], 0));
|
(*env)->GetPrimitiveArrayCritical(env, jDstPlanes[i], 0));
|
||||||
dstPlanes[i] = &dstPlanes[i][dstOffsets[i]];
|
dstPlanes[i] = &dstPlanesTmp[i][dstOffsets[i]];
|
||||||
|
SAFE_RELEASE(jDstPlanes[i], dstPlanesTmp[i]);
|
||||||
}
|
}
|
||||||
BAILIF0(srcBuf = (*env)->GetPrimitiveArrayCritical(env, src, 0));
|
BAILIF0(srcBuf = (*env)->GetPrimitiveArrayCritical(env, src, 0));
|
||||||
|
|
||||||
if (tjEncodeYUVPlanes(handle, &srcBuf[y * actualPitch + x * tjPixelSize[pf]],
|
if (tjEncodeYUVPlanes(handle, &srcBuf[y * actualPitch + x * tjPixelSize[pf]],
|
||||||
width, pitch, height, pf, dstPlanes, dstStrides,
|
width, pitch, height, pf, dstPlanes, dstStrides,
|
||||||
subsamp, flags) == -1) {
|
subsamp, flags) == -1) {
|
||||||
RELEASE_ARRAYS_ENCODEYUV();
|
SAFE_RELEASE(src, srcBuf);
|
||||||
THROW_TJ();
|
THROW_TJ();
|
||||||
}
|
}
|
||||||
|
|
||||||
bailout:
|
bailout:
|
||||||
RELEASE_ARRAYS_ENCODEYUV();
|
SAFE_RELEASE(src, srcBuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TurboJPEG 1.4.x: TJCompressor::encodeYUV() byte source */
|
/* TurboJPEG 1.4.x: TJCompressor::encodeYUV() byte source */
|
||||||
@@ -785,9 +776,12 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompress
|
|||||||
jintArray jDstStrides, jint desiredHeight, jint flags)
|
jintArray jDstStrides, jint desiredHeight, jint flags)
|
||||||
{
|
{
|
||||||
tjhandle handle = 0;
|
tjhandle handle = 0;
|
||||||
|
unsigned char *jpegBuf = NULL;
|
||||||
jbyteArray jDstPlanes[3] = { NULL, NULL, NULL };
|
jbyteArray jDstPlanes[3] = { NULL, NULL, NULL };
|
||||||
unsigned char *jpegBuf = NULL, *dstPlanes[3];
|
unsigned char *dstPlanesTmp[3] = { NULL, NULL, NULL };
|
||||||
int *dstOffsets = NULL, *dstStrides = NULL;
|
unsigned char *dstPlanes[3] = { NULL, NULL, NULL };
|
||||||
|
int *dstOffsetsTmp = NULL, dstOffsets[3] = { 0, 0, 0 };
|
||||||
|
int *dstStridesTmp = NULL, dstStrides[3] = { 0, 0, 0 };
|
||||||
int jpegSubsamp = -1, jpegWidth = 0, jpegHeight = 0;
|
int jpegSubsamp = -1, jpegWidth = 0, jpegHeight = 0;
|
||||||
int nc = 0, i, width, height, scaledWidth, scaledHeight, nsf = 0;
|
int nc = 0, i, width, height, scaledWidth, scaledHeight, nsf = 0;
|
||||||
tjscalingfactor *sf;
|
tjscalingfactor *sf;
|
||||||
@@ -821,57 +815,50 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJDecompressor_decompress
|
|||||||
if (i >= nsf)
|
if (i >= nsf)
|
||||||
THROW_ARG("Could not scale down to desired image dimensions");
|
THROW_ARG("Could not scale down to desired image dimensions");
|
||||||
|
|
||||||
#define RELEASE_ARRAYS_DECOMPRESSTOYUV() { \
|
BAILIF0(dstOffsetsTmp =
|
||||||
SAFE_RELEASE(src, jpegBuf); \
|
(*env)->GetPrimitiveArrayCritical(env, jDstOffsets, 0));
|
||||||
for (i = 0; i < nc; i++) \
|
for (i = 0; i < nc; i++) dstOffsets[i] = dstOffsetsTmp[i];
|
||||||
SAFE_RELEASE(jDstPlanes[i], dstPlanes[i]); \
|
SAFE_RELEASE(jDstOffsets, dstOffsetsTmp);
|
||||||
SAFE_RELEASE(jDstStrides, dstStrides); \
|
|
||||||
SAFE_RELEASE(jDstOffsets, dstOffsets); \
|
BAILIF0(dstStridesTmp =
|
||||||
}
|
(*env)->GetPrimitiveArrayCritical(env, jDstStrides, 0));
|
||||||
|
for (i = 0; i < nc; i++) dstStrides[i] = dstStridesTmp[i];
|
||||||
|
SAFE_RELEASE(jDstStrides, dstStridesTmp);
|
||||||
|
|
||||||
BAILIF0(dstOffsets = (*env)->GetPrimitiveArrayCritical(env, jDstOffsets, 0));
|
|
||||||
BAILIF0(dstStrides = (*env)->GetPrimitiveArrayCritical(env, jDstStrides, 0));
|
|
||||||
for (i = 0; i < nc; i++) {
|
for (i = 0; i < nc; i++) {
|
||||||
int planeSize = tjPlaneSizeYUV(i, scaledWidth, dstStrides[i], scaledHeight,
|
int planeSize = tjPlaneSizeYUV(i, scaledWidth, dstStrides[i], scaledHeight,
|
||||||
jpegSubsamp);
|
jpegSubsamp);
|
||||||
int pw = tjPlaneWidth(i, scaledWidth, jpegSubsamp);
|
int pw = tjPlaneWidth(i, scaledWidth, jpegSubsamp);
|
||||||
|
|
||||||
if (planeSize < 0 || pw < 0) {
|
if (planeSize < 0 || pw < 0)
|
||||||
RELEASE_ARRAYS_DECOMPRESSTOYUV();
|
|
||||||
THROW_ARG(tjGetErrorStr());
|
THROW_ARG(tjGetErrorStr());
|
||||||
}
|
|
||||||
|
|
||||||
if (dstOffsets[i] < 0) {
|
if (dstOffsets[i] < 0)
|
||||||
RELEASE_ARRAYS_DECOMPRESSTOYUV();
|
|
||||||
THROW_ARG("Invalid argument in decompressToYUV()");
|
THROW_ARG("Invalid argument in decompressToYUV()");
|
||||||
}
|
if (dstStrides[i] < 0 && dstOffsets[i] - planeSize + pw < 0)
|
||||||
if (dstStrides[i] < 0 && dstOffsets[i] - planeSize + pw < 0) {
|
|
||||||
RELEASE_ARRAYS_DECOMPRESSTOYUV();
|
|
||||||
THROW_ARG("Negative plane stride would cause memory to be accessed below plane boundary");
|
THROW_ARG("Negative plane stride would cause memory to be accessed below plane boundary");
|
||||||
}
|
|
||||||
|
|
||||||
BAILIF0(jDstPlanes[i] = (*env)->GetObjectArrayElement(env, dstobjs, i));
|
BAILIF0(jDstPlanes[i] = (*env)->GetObjectArrayElement(env, dstobjs, i));
|
||||||
if ((*env)->GetArrayLength(env, jDstPlanes[i]) <
|
if ((*env)->GetArrayLength(env, jDstPlanes[i]) <
|
||||||
dstOffsets[i] + planeSize) {
|
dstOffsets[i] + planeSize)
|
||||||
RELEASE_ARRAYS_DECOMPRESSTOYUV();
|
|
||||||
THROW_ARG("Destination plane is not large enough");
|
THROW_ARG("Destination plane is not large enough");
|
||||||
}
|
|
||||||
|
|
||||||
BAILIF0(dstPlanes[i] =
|
BAILIF0(dstPlanesTmp[i] =
|
||||||
(*env)->GetPrimitiveArrayCritical(env, jDstPlanes[i], 0));
|
(*env)->GetPrimitiveArrayCritical(env, jDstPlanes[i], 0));
|
||||||
dstPlanes[i] = &dstPlanes[i][dstOffsets[i]];
|
dstPlanes[i] = &dstPlanesTmp[i][dstOffsets[i]];
|
||||||
|
SAFE_RELEASE(jDstPlanes[i], dstPlanesTmp[i]);
|
||||||
}
|
}
|
||||||
BAILIF0(jpegBuf = (*env)->GetPrimitiveArrayCritical(env, src, 0));
|
BAILIF0(jpegBuf = (*env)->GetPrimitiveArrayCritical(env, src, 0));
|
||||||
|
|
||||||
if (tjDecompressToYUVPlanes(handle, jpegBuf, (unsigned long)jpegSize,
|
if (tjDecompressToYUVPlanes(handle, jpegBuf, (unsigned long)jpegSize,
|
||||||
dstPlanes, desiredWidth, dstStrides,
|
dstPlanes, desiredWidth, dstStrides,
|
||||||
desiredHeight, flags) == -1) {
|
desiredHeight, flags) == -1) {
|
||||||
RELEASE_ARRAYS_DECOMPRESSTOYUV();
|
SAFE_RELEASE(src, jpegBuf);
|
||||||
THROW_TJ();
|
THROW_TJ();
|
||||||
}
|
}
|
||||||
|
|
||||||
bailout:
|
bailout:
|
||||||
RELEASE_ARRAYS_DECOMPRESSTOYUV();
|
SAFE_RELEASE(src, jpegBuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TurboJPEG 1.2.x: TJDecompressor::decompressToYUV() */
|
/* TurboJPEG 1.2.x: TJDecompressor::decompressToYUV() */
|
||||||
@@ -920,9 +907,11 @@ static void TJDecompressor_decodeYUV
|
|||||||
tjhandle handle = 0;
|
tjhandle handle = 0;
|
||||||
jsize arraySize = 0, actualPitch;
|
jsize arraySize = 0, actualPitch;
|
||||||
jbyteArray jSrcPlanes[3] = { NULL, NULL, NULL };
|
jbyteArray jSrcPlanes[3] = { NULL, NULL, NULL };
|
||||||
const unsigned char *srcPlanes[3];
|
const unsigned char *srcPlanesTmp[3] = { NULL, NULL, NULL };
|
||||||
|
const unsigned char *srcPlanes[3] = { NULL, NULL, NULL };
|
||||||
|
int *srcOffsetsTmp = NULL, srcOffsets[3] = { 0, 0, 0 };
|
||||||
|
int *srcStridesTmp = NULL, srcStrides[3] = { 0, 0, 0 };
|
||||||
unsigned char *dstBuf = NULL;
|
unsigned char *dstBuf = NULL;
|
||||||
int *srcOffsets = NULL, *srcStrides = NULL;
|
|
||||||
int nc = (subsamp == org_libjpegturbo_turbojpeg_TJ_SAMP_GRAY ? 1 : 3), i;
|
int nc = (subsamp == org_libjpegturbo_turbojpeg_TJ_SAMP_GRAY ? 1 : 3), i;
|
||||||
|
|
||||||
GET_HANDLE();
|
GET_HANDLE();
|
||||||
@@ -946,56 +935,49 @@ static void TJDecompressor_decodeYUV
|
|||||||
if ((*env)->GetArrayLength(env, dst) * dstElementSize < arraySize)
|
if ((*env)->GetArrayLength(env, dst) * dstElementSize < arraySize)
|
||||||
THROW_ARG("Destination buffer is not large enough");
|
THROW_ARG("Destination buffer is not large enough");
|
||||||
|
|
||||||
#define RELEASE_ARRAYS_DECODEYUV() { \
|
BAILIF0(srcOffsetsTmp =
|
||||||
SAFE_RELEASE(dst, dstBuf); \
|
(*env)->GetPrimitiveArrayCritical(env, jSrcOffsets, 0));
|
||||||
for (i = 0; i < nc; i++) \
|
for (i = 0; i < nc; i++) srcOffsets[i] = srcOffsetsTmp[i];
|
||||||
SAFE_RELEASE(jSrcPlanes[i], srcPlanes[i]); \
|
SAFE_RELEASE(jSrcOffsets, srcOffsetsTmp);
|
||||||
SAFE_RELEASE(jSrcStrides, srcStrides); \
|
|
||||||
SAFE_RELEASE(jSrcOffsets, srcOffsets); \
|
BAILIF0(srcStridesTmp =
|
||||||
}
|
(*env)->GetPrimitiveArrayCritical(env, jSrcStrides, 0));
|
||||||
|
for (i = 0; i < nc; i++) srcStrides[i] = srcStridesTmp[i];
|
||||||
|
SAFE_RELEASE(jSrcStrides, srcStridesTmp);
|
||||||
|
|
||||||
BAILIF0(srcOffsets = (*env)->GetPrimitiveArrayCritical(env, jSrcOffsets, 0));
|
|
||||||
BAILIF0(srcStrides = (*env)->GetPrimitiveArrayCritical(env, jSrcStrides, 0));
|
|
||||||
for (i = 0; i < nc; i++) {
|
for (i = 0; i < nc; i++) {
|
||||||
int planeSize = tjPlaneSizeYUV(i, width, srcStrides[i], height, subsamp);
|
int planeSize = tjPlaneSizeYUV(i, width, srcStrides[i], height, subsamp);
|
||||||
int pw = tjPlaneWidth(i, width, subsamp);
|
int pw = tjPlaneWidth(i, width, subsamp);
|
||||||
|
|
||||||
if (planeSize < 0 || pw < 0) {
|
if (planeSize < 0 || pw < 0)
|
||||||
RELEASE_ARRAYS_DECODEYUV();
|
|
||||||
THROW_ARG(tjGetErrorStr());
|
THROW_ARG(tjGetErrorStr());
|
||||||
}
|
|
||||||
|
|
||||||
if (srcOffsets[i] < 0) {
|
if (srcOffsets[i] < 0)
|
||||||
RELEASE_ARRAYS_DECODEYUV();
|
|
||||||
THROW_ARG("Invalid argument in decodeYUV()");
|
THROW_ARG("Invalid argument in decodeYUV()");
|
||||||
}
|
if (srcStrides[i] < 0 && srcOffsets[i] - planeSize + pw < 0)
|
||||||
if (srcStrides[i] < 0 && srcOffsets[i] - planeSize + pw < 0) {
|
|
||||||
RELEASE_ARRAYS_DECODEYUV();
|
|
||||||
THROW_ARG("Negative plane stride would cause memory to be accessed below plane boundary");
|
THROW_ARG("Negative plane stride would cause memory to be accessed below plane boundary");
|
||||||
}
|
|
||||||
|
|
||||||
BAILIF0(jSrcPlanes[i] = (*env)->GetObjectArrayElement(env, srcobjs, i));
|
BAILIF0(jSrcPlanes[i] = (*env)->GetObjectArrayElement(env, srcobjs, i));
|
||||||
if ((*env)->GetArrayLength(env, jSrcPlanes[i]) <
|
if ((*env)->GetArrayLength(env, jSrcPlanes[i]) <
|
||||||
srcOffsets[i] + planeSize) {
|
srcOffsets[i] + planeSize)
|
||||||
RELEASE_ARRAYS_DECODEYUV();
|
|
||||||
THROW_ARG("Source plane is not large enough");
|
THROW_ARG("Source plane is not large enough");
|
||||||
}
|
|
||||||
|
|
||||||
BAILIF0(srcPlanes[i] =
|
BAILIF0(srcPlanesTmp[i] =
|
||||||
(*env)->GetPrimitiveArrayCritical(env, jSrcPlanes[i], 0));
|
(*env)->GetPrimitiveArrayCritical(env, jSrcPlanes[i], 0));
|
||||||
srcPlanes[i] = &srcPlanes[i][srcOffsets[i]];
|
srcPlanes[i] = &srcPlanesTmp[i][srcOffsets[i]];
|
||||||
|
SAFE_RELEASE(jSrcPlanes[i], srcPlanesTmp[i]);
|
||||||
}
|
}
|
||||||
BAILIF0(dstBuf = (*env)->GetPrimitiveArrayCritical(env, dst, 0));
|
BAILIF0(dstBuf = (*env)->GetPrimitiveArrayCritical(env, dst, 0));
|
||||||
|
|
||||||
if (tjDecodeYUVPlanes(handle, srcPlanes, srcStrides, subsamp,
|
if (tjDecodeYUVPlanes(handle, srcPlanes, srcStrides, subsamp,
|
||||||
&dstBuf[y * actualPitch + x * tjPixelSize[pf]], width,
|
&dstBuf[y * actualPitch + x * tjPixelSize[pf]], width,
|
||||||
pitch, height, pf, flags) == -1) {
|
pitch, height, pf, flags) == -1) {
|
||||||
RELEASE_ARRAYS_DECODEYUV();
|
SAFE_RELEASE(dst, dstBuf);
|
||||||
THROW_TJ();
|
THROW_TJ();
|
||||||
}
|
}
|
||||||
|
|
||||||
bailout:
|
bailout:
|
||||||
RELEASE_ARRAYS_DECODEYUV();
|
SAFE_RELEASE(dst, dstBuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TurboJPEG 1.4.x: TJDecompressor::decodeYUV() byte destination */
|
/* TurboJPEG 1.4.x: TJDecompressor::decodeYUV() byte destination */
|
||||||
|
|||||||
Reference in New Issue
Block a user