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
diff --git a/turbojpeg-jni.c b/turbojpeg-jni.c
index cab57bd..76af1f2 100644
--- a/turbojpeg-jni.c
+++ b/turbojpeg-jni.c
@@ -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 @@
 	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 @@
 	}
 	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());