]> granicus.if.org Git - libjpeg-turbo/commitdiff
Add a set of undocumented environment variables and Java system properties that allow...
authorDRC <dcommander@users.sourceforge.net>
Fri, 22 Aug 2014 13:43:33 +0000 (13:43 +0000)
committerDRC <dcommander@users.sourceforge.net>
Fri, 22 Aug 2014 13:43:33 +0000 (13:43 +0000)
git-svn-id: svn+ssh://svn.code.sf.net/p/libjpeg-turbo/code/trunk@1376 632fc199-4ca6-4c93-a231-07263d6284db

turbojpeg-jni.c
turbojpeg.c

index cab57bdf98c9108ddf2b1692e186cdd1a844daed..76af1f2b5034268f2ffb2c0fcbba8f872c0c5c6e 100644 (file)
        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());
index 0daa86ab6118cbf1e2913aae756235b4edec7b06..1acf7c4430230f8bc602a059881bf89f1476a62c 100644 (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;