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)
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)
}
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());
#include <stdio.h>
#include <stdlib.h>
+#include <ctype.h>
#include <jinclude.h>
#define JPEG_INTERNALS
#include <jpeglib.h>
int pixelFormat, int subsamp, int jpegQual, int flags)
{
int retval=0;
+ char *env=NULL;
switch(pixelFormat)
{
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);
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;