Add a set of undocumented environment variables and Java system properties that allow compression features of libjpeg that are not normally exposed in the TurboJPEG API to be enabled. These features are not normally exposed because, for the most part, they aren't "turbo" features, but it is still useful to be able to benchmark them without modifying the code.

git-svn-id: svn+ssh://svn.code.sf.net/p/libjpeg-turbo/code/trunk@1376 632fc199-4ca6-4c93-a231-07263d6284db
This commit is contained in:
DRC
2014-08-22 13:43:33 +00:00
parent 2e2ce5a1da
commit 0713c1bb54
2 changed files with 63 additions and 0 deletions

View File

@@ -59,6 +59,39 @@
bailif0(_fid=(*env)->GetFieldID(env, _cls, "handle", "J")); \
handle=(tjhandle)(size_t)(*env)->GetLongField(env, obj, _fid); \
#define prop2env(property, envvar) \
{ \
if((jName=(*env)->NewStringUTF(env, property))!=NULL \
&& (jValue=(*env)->CallStaticObjectMethod(env, cls, mid, jName))!=NULL) \
{ \
if((value=(*env)->GetStringUTFChars(env, jValue, 0))!=NULL) \
{ \
setenv(envvar, value, 1); \
(*env)->ReleaseStringUTFChars(env, jValue, value); \
} \
} \
}
int ProcessSystemProperties(JNIEnv *env)
{
jclass cls; jmethodID mid;
jstring jName, jValue;
const char *value;
bailif0(cls=(*env)->FindClass(env, "java/lang/System"));
bailif0(mid=(*env)->GetStaticMethodID(env, cls, "getProperty",
"(Ljava/lang/String;)Ljava/lang/String;"));
prop2env("turbojpeg.optimize", "TJ_OPTIMIZE");
prop2env("turbojpeg.arithmetic", "TJ_ARITHMETIC");
prop2env("turbojpeg.restart", "TJ_RESTART");
prop2env("turbojpeg.progressive", "TJ_PROGRESSIVE");
return 0;
bailout:
return -1;
}
/* TurboJPEG 1.2.x: TJ::bufSize() */
JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJ_bufSize
(JNIEnv *env, jclass cls, jint width, jint height, jint jpegSubsamp)
@@ -172,6 +205,8 @@ static jint TJCompressor_compress
bailif0(srcBuf=(*env)->GetPrimitiveArrayCritical(env, src, 0));
bailif0(jpegBuf=(*env)->GetPrimitiveArrayCritical(env, dst, 0));
if(ProcessSystemProperties(env)<0) goto bailout;
if(tjCompress2(handle, &srcBuf[y*actualPitch + x*tjPixelSize[pf]], width,
pitch, height, pf, &jpegBuf, &jpegSize, jpegSubsamp, jpegQual,
flags|TJFLAG_NOREALLOC)==-1)
@@ -295,6 +330,8 @@ JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_compressFrom
}
bailif0(jpegBuf=(*env)->GetPrimitiveArrayCritical(env, dst, 0));
if(ProcessSystemProperties(env)<0) goto bailout;
if(tjCompressFromYUVPlanes(handle, srcPlanes, width, srcStrides, height,
subsamp, &jpegBuf, &jpegSize, jpegQual, flags|TJFLAG_NOREALLOC)==-1)
_throw(tjGetErrorStr());

View File

@@ -31,6 +31,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <jinclude.h>
#define JPEG_INTERNALS
#include <jpeglib.h>
@@ -161,6 +162,7 @@ static int setCompDefaults(struct jpeg_compress_struct *cinfo,
int pixelFormat, int subsamp, int jpegQual, int flags)
{
int retval=0;
char *env=NULL;
switch(pixelFormat)
{
@@ -203,6 +205,26 @@ static int setCompDefaults(struct jpeg_compress_struct *cinfo,
cinfo->input_components=tjPixelSize[pixelFormat];
jpeg_set_defaults(cinfo);
if((env=getenv("TJ_OPTIMIZE"))!=NULL && strlen(env)>0 && !strcmp(env, "1"))
cinfo->optimize_coding=TRUE;
if((env=getenv("TJ_ARITHMETIC"))!=NULL && strlen(env)>0 && !strcmp(env, "1"))
cinfo->arith_code=TRUE;
if((env=getenv("TJ_RESTART"))!=NULL && strlen(env)>0)
{
int temp=-1; char tempc=0;
if(sscanf(env, "%d%c", &temp, &tempc)>=1 && temp>=0 && temp<=65535)
{
if(toupper(tempc)=='B')
{
cinfo->restart_interval=temp;
cinfo->restart_in_rows=0;
}
else
cinfo->restart_in_rows=temp;
}
}
if(jpegQual>=0)
{
jpeg_set_quality(cinfo, jpegQual, TRUE);
@@ -215,6 +237,10 @@ static int setCompDefaults(struct jpeg_compress_struct *cinfo,
jpeg_set_colorspace(cinfo, JCS_YCCK);
else jpeg_set_colorspace(cinfo, JCS_YCbCr);
if((env=getenv("TJ_PROGRESSIVE"))!=NULL && strlen(env)>0
&& !strcmp(env, "1"))
jpeg_simple_progression(cinfo);
cinfo->comp_info[0].h_samp_factor=tjMCUWidth[subsamp]/8;
cinfo->comp_info[1].h_samp_factor=1;
cinfo->comp_info[2].h_samp_factor=1;