summaryrefslogtreecommitdiff
path: root/turbojpeg-jni.c
diff options
context:
space:
mode:
authornoel@chromium.org <noel@chromium.org@4ff67af0-8c30-449e-8e8b-ad334ec8d88c>2014-04-14 06:56:00 +0000
committernoel@chromium.org <noel@chromium.org@4ff67af0-8c30-449e-8e8b-ad334ec8d88c>2014-04-14 06:56:00 +0000
commit3395bcc26e390d2960d15020d4a4d27ae0c122fe (patch)
tree70d532ca62c1eb0b3c8d44f818dc304a9a2a80ae /turbojpeg-jni.c
parent24cafe92b7a98c36a8062e1ac2fef9832588ac85 (diff)
Upgrade libjpeg_turbo to 1.3.1 (r1219)
Remove google.jdmarker.patch, since the fixes for CVE-2013-6629 and CVE-2013-6630 are upstream most everywhere now [1]. Version number to 1.3.1 (config.h, jconfig.h). README.chromium: "Fixed valgrind error" patch was upstreamed in r839 http://sourceforge.net/p/libjpeg-turbo/code/839. The r1188 cherry-pick was put in config.h, say that. [1] http://seclists.org/fulldisclosure/2013/Nov/83 TBR=darin@chromium.org BUG=258723, 299835 Review URL: https://codereview.appspot.com/87110044 git-svn-id: http://src.chromium.org/svn/trunk/deps/third_party/libjpeg_turbo@263594 4ff67af0-8c30-449e-8e8b-ad334ec8d88c
Diffstat (limited to 'turbojpeg-jni.c')
-rw-r--r--turbojpeg-jni.c77
1 files changed, 55 insertions, 22 deletions
diff --git a/turbojpeg-jni.c b/turbojpeg-jni.c
index c98845b..634bedf 100644
--- a/turbojpeg-jni.c
+++ b/turbojpeg-jni.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C)2011-2012 D. R. Commander. All Rights Reserved.
+ * Copyright (C)2011-2013 D. R. Commander. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@@ -29,6 +29,9 @@
#include <stdlib.h>
#include <string.h>
#include "turbojpeg.h"
+#ifdef WIN32
+#include "tjutil.h"
+#endif
#include <jni.h>
#include "java/org_libjpegturbo_turbojpeg_TJCompressor.h"
#include "java/org_libjpegturbo_turbojpeg_TJDecompressor.h"
@@ -41,7 +44,11 @@
goto bailout; \
}
-#define bailif0(f) {if(!(f)) goto bailout;}
+#define bailif0(f) {if(!(f)) { \
+ char temps[80]; \
+ snprintf(temps, 80, "Unexpected NULL condition in line %d", __LINE__); \
+ _throw(temps); \
+}}
#define gethandle() \
jclass _cls=(*env)->GetObjectClass(env, obj); \
@@ -88,13 +95,14 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_init
return;
}
-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)
+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)
{
tjhandle handle=0;
- unsigned long jpegSize=0; jsize arraySize=0;
+ unsigned long jpegSize=0;
+ jsize arraySize=0, actualPitch;
unsigned char *srcBuf=NULL, *jpegBuf=NULL;
gethandle();
@@ -105,7 +113,8 @@ JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_compress___3
if(org_libjpegturbo_turbojpeg_TJ_NUMPF!=TJ_NUMPF)
_throw("Mismatch between Java and C API");
- arraySize=(pitch==0)? width*tjPixelSize[pf]*height:pitch*height;
+ actualPitch=(pitch==0)? width*tjPixelSize[pf]:pitch;
+ arraySize=(y+height-1)*actualPitch + x+width;
if((*env)->GetArrayLength(env, src)<arraySize)
_throw("Source buffer is not large enough");
jpegSize=tjBufSize(width, height, jpegSubsamp);
@@ -115,8 +124,9 @@ JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_compress___3
bailif0(srcBuf=(*env)->GetPrimitiveArrayCritical(env, src, 0));
bailif0(jpegBuf=(*env)->GetPrimitiveArrayCritical(env, dst, 0));
- if(tjCompress2(handle, srcBuf, width, pitch, height, pf, &jpegBuf,
- &jpegSize, jpegSubsamp, jpegQual, flags|TJFLAG_NOREALLOC)==-1)
+ if(tjCompress2(handle, &srcBuf[y*actualPitch + x*tjPixelSize[pf]], width,
+ pitch, height, pf, &jpegBuf, &jpegSize, jpegSubsamp, jpegQual,
+ flags|TJFLAG_NOREALLOC)==-1)
{
(*env)->ReleasePrimitiveArrayCritical(env, dst, jpegBuf, 0);
(*env)->ReleasePrimitiveArrayCritical(env, src, srcBuf, 0);
@@ -130,26 +140,38 @@ JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_compress___3
return (jint)jpegSize;
}
-JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_compress___3IIIII_3BIII
- (JNIEnv *env, jobject obj, jintArray src, jint width, jint pitch,
+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);
+}
+
+JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_compress___3IIIIIII_3BIII
+ (JNIEnv *env, jobject obj, jintArray src, jint x, jint y, jint width,
+ jint stride, jint height, jint pf, jbyteArray dst, jint jpegSubsamp,
+ jint jpegQual, jint flags)
+{
tjhandle handle=0;
- unsigned long jpegSize=0; jsize arraySize=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
- || pitch<0)
+ || stride<0)
_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.");
- arraySize=(pitch==0)? width*height:pitch*height;
+ 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);
@@ -159,8 +181,9 @@ JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_compress___3
bailif0(srcBuf=(*env)->GetPrimitiveArrayCritical(env, src, 0));
bailif0(jpegBuf=(*env)->GetPrimitiveArrayCritical(env, dst, 0));
- if(tjCompress2(handle, srcBuf, width, pitch*sizeof(jint), height, pf,
- &jpegBuf, &jpegSize, jpegSubsamp, jpegQual, flags|TJFLAG_NOREALLOC)==-1)
+ if(tjCompress2(handle, &srcBuf[(y*actualStride + x)*sizeof(int)], width,
+ stride*sizeof(jint), height, pf, &jpegBuf, &jpegSize, jpegSubsamp,
+ jpegQual, flags|TJFLAG_NOREALLOC)==-1)
{
(*env)->ReleasePrimitiveArrayCritical(env, dst, jpegBuf, 0);
(*env)->ReleasePrimitiveArrayCritical(env, src, srcBuf, 0);
@@ -174,6 +197,16 @@ JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_compress___3
return (jint)jpegSize;
}
+JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_compress___3IIIII_3BIII
+ (JNIEnv *env, jobject obj, jintArray src, jint width, jint pitch,
+ 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);
+}
+
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)
@@ -216,7 +249,7 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___
}
JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___3IIIII_3BII
- (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 subsamp, jint flags)
{
tjhandle handle=0;
@@ -226,14 +259,14 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___
gethandle();
if(pf<0 || pf>=org_libjpegturbo_turbojpeg_TJ_NUMPF || width<1 || height<1
- || pitch<0)
- _throw("Invalid argument in compress()");
+ || stride<0)
+ _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=(pitch==0)? width*height:pitch*height;
+ 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)
@@ -243,7 +276,7 @@ JNIEXPORT void JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_encodeYUV___
bailif0(srcBuf=(*env)->GetPrimitiveArrayCritical(env, src, 0));
bailif0(dstBuf=(*env)->GetPrimitiveArrayCritical(env, dst, 0));
- if(tjEncodeYUV2(handle, srcBuf, width, pitch*sizeof(jint), height, pf,
+ if(tjEncodeYUV2(handle, srcBuf, width, stride*sizeof(jint), height, pf,
dstBuf, subsamp, flags)==-1)
{
(*env)->ReleasePrimitiveArrayCritical(env, dst, dstBuf, 0);