From: DRC Date: Tue, 27 Jun 2017 18:24:08 +0000 (-0500) Subject: TurboJPEG: Opt. enable progressive entropy coding X-Git-Tag: 1.5.90~69 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=aba6ae5950702d85dcc3989d23b2ec5872f6ddc4;p=libjpeg-turbo TurboJPEG: Opt. enable progressive entropy coding Fulfills part of the feature request in #153. Also paves the way for SIMD-accelerated progressive Huffman coding (refer to #46.) --- diff --git a/ChangeLog.md b/ChangeLog.md index 731500b..d59e90f 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -60,6 +60,11 @@ immediately halt a compression/decompression/transform operation if it encounters a warning from the underlying libjpeg API (the default behavior is to allow the operation to complete unless a fatal error is encountered.) +5. Introduced a new flag in the TurboJPEG C and Java APIs (`TJFLAG_PROGRESSIVE` +and `TJ.FLAG_PROGRESSIVE`, respectively) that causes the library to use +progressive entropy coding in JPEG images generated by compression and +transform operations. + 1.5.2 ===== diff --git a/doc/html/group___turbo_j_p_e_g.html b/doc/html/group___turbo_j_p_e_g.html index f5f6399..8c66c4b 100644 --- a/doc/html/group___turbo_j_p_e_g.html +++ b/doc/html/group___turbo_j_p_e_g.html @@ -131,6 +131,9 @@ Macros #define TJFLAG_STOPONWARNING  Immediately discontinue the current compression/decompression/transform operation if the underlying codec throws a warning (non-fatal error). More...
  +#define TJFLAG_PROGRESSIVE + Use progressive entropy coding in JPEG images generated by the compression and transform functions. More...
+  #define TJ_NUMERR  The number of error codes. More...
  @@ -485,6 +488,21 @@ Variables

Disable buffer (re)allocation.

If passed to one of the JPEG compression or transform functions, this flag will cause those functions to generate an error if the JPEG image buffer is invalid or too small rather than attempting to allocate or reallocate that buffer. This reproduces the behavior of earlier versions of TurboJPEG.

+ + + +
+
+ + + + +
#define TJFLAG_PROGRESSIVE
+
+ +

Use progressive entropy coding in JPEG images generated by the compression and transform functions.

+

Progressive entropy coding will generally improve compression relative to baseline entropy coding (the default), but it will reduce compression and decompression performance considerably.

+
diff --git a/doc/html/search/all_74.js b/doc/html/search/all_74.js index b18cdcd..d56e332 100644 --- a/doc/html/search/all_74.js +++ b/doc/html/search/all_74.js @@ -35,6 +35,7 @@ var searchData= ['tjflag_5ffastdct',['TJFLAG_FASTDCT',['../group___turbo_j_p_e_g.html#gaabce235db80d3f698b27f36cbd453da2',1,'turbojpeg.h']]], ['tjflag_5ffastupsample',['TJFLAG_FASTUPSAMPLE',['../group___turbo_j_p_e_g.html#ga4ee4506c81177a06f77e2504a22efd2d',1,'turbojpeg.h']]], ['tjflag_5fnorealloc',['TJFLAG_NOREALLOC',['../group___turbo_j_p_e_g.html#ga8808d403c68b62aaa58a4c1e58e98963',1,'turbojpeg.h']]], + ['tjflag_5fprogressive',['TJFLAG_PROGRESSIVE',['../group___turbo_j_p_e_g.html#ga43b426750b46190a25d34a67ef76df1b',1,'turbojpeg.h']]], ['tjflag_5fstoponwarning',['TJFLAG_STOPONWARNING',['../group___turbo_j_p_e_g.html#ga519cfa4ef6c18d9e5b455fdf59306a3a',1,'turbojpeg.h']]], ['tjfree',['tjFree',['../group___turbo_j_p_e_g.html#ga8c4a1231dc06a450514c835f6471f137',1,'turbojpeg.h']]], ['tjgeterrorcode',['tjGetErrorCode',['../group___turbo_j_p_e_g.html#ga0be00a62bd1be897f170fa1fed5fb4cb',1,'turbojpeg.h']]], @@ -76,7 +77,7 @@ var searchData= ['tjsamp_5fgray',['TJSAMP_GRAY',['../group___turbo_j_p_e_g.html#gga1d047060ea80bb9820d540bb928e9074a3f1c9504842ddc7a48d0f690754b6248',1,'turbojpeg.h']]], ['tjscaled',['TJSCALED',['../group___turbo_j_p_e_g.html#ga84878bb65404204743aa18cac02781df',1,'turbojpeg.h']]], ['tjscalingfactor',['tjscalingfactor',['../structtjscalingfactor.html',1,'']]], - ['tjtransform',['tjtransform',['../structtjtransform.html',1,'tjtransform'],['../group___turbo_j_p_e_g.html#gaa29f3189c41be12ec5dee7caec318a31',1,'tjtransform(): turbojpeg.h'],['../group___turbo_j_p_e_g.html#gad02cd42b69f193a0623a9c801788df3a',1,'tjTransform(tjhandle handle, const unsigned char *jpegBuf, unsigned long jpegSize, int n, unsigned char **dstBufs, unsigned long *dstSizes, tjtransform *transforms, int flags): turbojpeg.h']]], + ['tjtransform',['tjtransform',['../structtjtransform.html',1,'tjtransform'],['../group___turbo_j_p_e_g.html#gad02cd42b69f193a0623a9c801788df3a',1,'tjTransform(tjhandle handle, const unsigned char *jpegBuf, unsigned long jpegSize, int n, unsigned char **dstBufs, unsigned long *dstSizes, tjtransform *transforms, int flags): turbojpeg.h'],['../group___turbo_j_p_e_g.html#gaa29f3189c41be12ec5dee7caec318a31',1,'tjtransform(): turbojpeg.h']]], ['tjxop',['TJXOP',['../group___turbo_j_p_e_g.html#ga2de531af4e7e6c4f124908376b354866',1,'turbojpeg.h']]], ['tjxop_5fhflip',['TJXOP_HFLIP',['../group___turbo_j_p_e_g.html#gga2de531af4e7e6c4f124908376b354866aa0df69776caa30f0fa28e26332d311ce',1,'turbojpeg.h']]], ['tjxop_5fnone',['TJXOP_NONE',['../group___turbo_j_p_e_g.html#gga2de531af4e7e6c4f124908376b354866aad88c0366cd3f7d0eac9d7a3fa1c2c27',1,'turbojpeg.h']]], diff --git a/java/TJBench.java b/java/TJBench.java index 3a63505..e76f1a2 100644 --- a/java/TJBench.java +++ b/java/TJBench.java @@ -627,6 +627,8 @@ class TJBench { System.out.println(" codec"); System.out.println("-accuratedct = Use the most accurate DCT/IDCT algorithms available in the"); System.out.println(" underlying codec"); + System.out.println("-progressive = Use progressive entropy coding in JPEG images generated by"); + System.out.println(" compression and transform operations."); System.out.println("-subsamp = When testing JPEG compression, this option specifies the level"); System.out.println(" of chrominance subsampling to use ( = 444, 422, 440, 420, 411, or"); System.out.println(" GRAY). The default is to test Grayscale, 4:2:0, 4:2:2, and 4:4:4 in"); @@ -726,6 +728,10 @@ class TJBench { System.out.println("Using most accurate DCT/IDCT algorithm\n"); flags |= TJ.FLAG_ACCURATEDCT; } + if (argv[i].equalsIgnoreCase("-progressive")) { + System.out.println("Using progressive entropy coding\n"); + flags |= TJ.FLAG_PROGRESSIVE; + } if (argv[i].equalsIgnoreCase("-rgb")) pf = TJ.PF_RGB; if (argv[i].equalsIgnoreCase("-rgbx")) diff --git a/java/doc/constant-values.html b/java/doc/constant-values.html index a180b68..74366d4 100644 --- a/java/doc/constant-values.html +++ b/java/doc/constant-values.html @@ -185,160 +185,167 @@ 128 + + +public static final int +FLAG_PROGRESSIVE +16384 + + public static final int FLAG_STOPONWARNING 8192 - + public static final int NUMCS 5 - + public static final int NUMERR 2 - + public static final int NUMPF 12 - + public static final int NUMSAMP 6 - + public static final int PF_ABGR 9 - + public static final int PF_ARGB 10 - + public static final int PF_BGR 1 - + public static final int PF_BGRA 8 - + public static final int PF_BGRX 3 - + public static final int PF_CMYK 11 - + public static final int PF_GRAY 6 - + public static final int PF_RGB 0 - + public static final int PF_RGBA 7 - + public static final int PF_RGBX 2 - + public static final int PF_XBGR 4 - + public static final int PF_XRGB 5 - + public static final int SAMP_411 5 - + public static final int SAMP_420 2 - + public static final int SAMP_422 1 - + public static final int SAMP_440 4 - + public static final int SAMP_444 0 - + public static final int diff --git a/java/doc/index-all.html b/java/doc/index-all.html index b88c20f..8f05a42 100644 --- a/java/doc/index-all.html +++ b/java/doc/index-all.html @@ -333,6 +333,11 @@
Deprecated.
+
FLAG_PROGRESSIVE - Static variable in class org.libjpegturbo.turbojpeg.TJ
+
+
Use progressive entropy coding in JPEG images generated by compression and + transform operations.
+
FLAG_STOPONWARNING - Static variable in class org.libjpegturbo.turbojpeg.TJ
Immediately discontinue the current compression/decompression/transform diff --git a/java/doc/org/libjpegturbo/turbojpeg/TJ.html b/java/doc/org/libjpegturbo/turbojpeg/TJ.html index 6733749..a544179 100644 --- a/java/doc/org/libjpegturbo/turbojpeg/TJ.html +++ b/java/doc/org/libjpegturbo/turbojpeg/TJ.html @@ -210,138 +210,145 @@ extends java.lang.Object static int +FLAG_PROGRESSIVE +
Use progressive entropy coding in JPEG images generated by compression and + transform operations.
+ + + +static int FLAG_STOPONWARNING
Immediately discontinue the current compression/decompression/transform operation if the underlying codec throws a warning (non-fatal error).
- + static int NUMCS
The number of JPEG colorspaces
- + static int NUMERR
The number of error codes
- + static int NUMPF
The number of pixel formats
- + static int NUMSAMP
The number of chrominance subsampling options
- + static int PF_ABGR
ABGR pixel format.
- + static int PF_ARGB
ARGB pixel format.
- + static int PF_BGR
BGR pixel format.
- + static int PF_BGRA
BGRA pixel format.
- + static int PF_BGRX
BGRX pixel format.
- + static int PF_CMYK
CMYK pixel format.
- + static int PF_GRAY
Grayscale pixel format.
- + static int PF_RGB
RGB pixel format.
- + static int PF_RGBA
RGBA pixel format.
- + static int PF_RGBX
RGBX pixel format.
- + static int PF_XBGR
XBGR pixel format.
- + static int PF_XRGB
XRGB pixel format.
- + static int SAMP_411
4:1:1 chrominance subsampling.
- + static int SAMP_420
4:2:0 chrominance subsampling.
- + static int SAMP_422
4:2:2 chrominance subsampling.
- + static int SAMP_440
4:4:0 chrominance subsampling.
- + static int SAMP_444
4:4:4 chrominance subsampling (no chrominance subsampling).
- + static int SAMP_GRAY
Grayscale.
@@ -992,6 +999,20 @@ public static final int FLAG_FORCESSE3
See Also:
Constant Field Values
+ + + +
    +
  • +

    FLAG_PROGRESSIVE

    +
    public static final int FLAG_PROGRESSIVE
    +
    Use progressive entropy coding in JPEG images generated by compression and + transform operations. Progressive entropy coding will generally improve + compression relative to baseline entropy coding (the default), but it will + reduce compression and decompression performance considerably.
    +
    See Also:
    Constant Field Values
    +
  • +
diff --git a/java/org/libjpegturbo/turbojpeg/TJ.java b/java/org/libjpegturbo/turbojpeg/TJ.java index 4e97aed..045e829 100644 --- a/java/org/libjpegturbo/turbojpeg/TJ.java +++ b/java/org/libjpegturbo/turbojpeg/TJ.java @@ -348,16 +348,16 @@ public final class TJ { * The uncompressed source/destination image is stored in bottom-up (Windows, * OpenGL) order, not top-down (X11) order. */ - public static final int FLAG_BOTTOMUP = 2; + public static final int FLAG_BOTTOMUP = 2; @Deprecated - public static final int FLAG_FORCEMMX = 8; + public static final int FLAG_FORCEMMX = 8; @Deprecated - public static final int FLAG_FORCESSE = 16; + public static final int FLAG_FORCESSE = 16; @Deprecated - public static final int FLAG_FORCESSE2 = 32; + public static final int FLAG_FORCESSE2 = 32; @Deprecated - public static final int FLAG_FORCESSE3 = 128; + public static final int FLAG_FORCESSE3 = 128; /** * When decompressing an image that was compressed using chrominance @@ -366,7 +366,7 @@ public final class TJ { * creates a smooth transition between neighboring chrominance components in * order to reduce upsampling artifacts in the decompressed image. */ - public static final int FLAG_FASTUPSAMPLE = 256; + public static final int FLAG_FASTUPSAMPLE = 256; /** * Use the fastest DCT/IDCT algorithm available in the underlying codec. The * default if this flag is not specified is implementation-specific. For @@ -375,7 +375,7 @@ public final class TJ { * only a very slight effect on accuracy, but it uses the accurate algorithm * when decompressing, because this has been shown to have a larger effect. */ - public static final int FLAG_FASTDCT = 2048; + public static final int FLAG_FASTDCT = 2048; /** * Use the most accurate DCT/IDCT algorithm available in the underlying * codec. The default if this flag is not specified is @@ -385,7 +385,7 @@ public final class TJ { * but it uses the accurate algorithm when decompressing, because this has * been shown to have a larger effect. */ - public static final int FLAG_ACCURATEDCT = 4096; + public static final int FLAG_ACCURATEDCT = 4096; /** * Immediately discontinue the current compression/decompression/transform * operation if the underlying codec throws a warning (non-fatal error). The @@ -393,6 +393,13 @@ public final class TJ { * error is encountered. */ public static final int FLAG_STOPONWARNING = 8192; + /** + * Use progressive entropy coding in JPEG images generated by compression and + * transform operations. Progressive entropy coding will generally improve + * compression relative to baseline entropy coding (the default), but it will + * reduce compression and decompression performance considerably. + */ + public static final int FLAG_PROGRESSIVE = 16384; /** diff --git a/tjbench.c b/tjbench.c index 50ac852..36ea6cf 100644 --- a/tjbench.c +++ b/tjbench.c @@ -740,6 +740,8 @@ void usage(char *progname) printf(" codec\n"); printf("-accuratedct = Use the most accurate DCT/IDCT algorithms available in the\n"); printf(" underlying codec\n"); + printf("-progressive = Use progressive entropy coding in JPEG images generated by\n"); + printf(" compression and transform operations.\n"); printf("-subsamp = When testing JPEG compression, this option specifies the level\n"); printf(" of chrominance subsampling to use ( = 444, 422, 440, 420, 411, or\n"); printf(" GRAY). The default is to test Grayscale, 4:2:0, 4:2:2, and 4:4:4 in\n"); @@ -841,6 +843,11 @@ int main(int argc, char *argv[]) printf("Using most accurate DCT/IDCT algorithm\n\n"); flags|=TJFLAG_ACCURATEDCT; } + if(!strcasecmp(argv[i], "-progressive")) + { + printf("Using progressive entropy coding\n\n"); + flags|=TJFLAG_PROGRESSIVE; + } if(!strcasecmp(argv[i], "-rgb")) pf=TJPF_RGB; if(!strcasecmp(argv[i], "-rgbx")) pf=TJPF_RGBX; if(!strcasecmp(argv[i], "-bgr")) pf=TJPF_BGR; diff --git a/turbojpeg.c b/turbojpeg.c index 569f114..3b29c22 100644 --- a/turbojpeg.c +++ b/turbojpeg.c @@ -263,8 +263,10 @@ static int setCompDefaults(struct jpeg_compress_struct *cinfo, jpeg_set_colorspace(cinfo, JCS_YCCK); else jpeg_set_colorspace(cinfo, JCS_YCbCr); + if(flags&TJFLAG_PROGRESSIVE) + jpeg_simple_progression(cinfo); #ifndef NO_GETENV - if((env=getenv("TJ_PROGRESSIVE"))!=NULL && strlen(env)>0 + else if((env=getenv("TJ_PROGRESSIVE"))!=NULL && strlen(env)>0 && !strcmp(env, "1")) jpeg_simple_progression(cinfo); #endif @@ -2187,6 +2189,8 @@ DLLEXPORT int DLLCALL tjTransform(tjhandle handle, jpeg_copy_critical_parameters(dinfo, cinfo); dstcoefs=jtransform_adjust_parameters(dinfo, cinfo, srccoefs, &xinfo[i]); + if(flags&TJFLAG_PROGRESSIVE) + jpeg_simple_progression(cinfo); if(!(t[i].options&TJXOPT_NOOUTPUT)) { jpeg_write_coefficients(cinfo, dstcoefs); diff --git a/turbojpeg.h b/turbojpeg.h index b512ecb..4edcc68 100644 --- a/turbojpeg.h +++ b/turbojpeg.h @@ -390,6 +390,13 @@ enum TJCS * is encountered. */ #define TJFLAG_STOPONWARNING 8192 +/** + * Use progressive entropy coding in JPEG images generated by the compression + * and transform functions. Progressive entropy coding will generally improve + * compression relative to baseline entropy coding (the default), but it will + * reduce compression and decompression performance considerably. + */ +#define TJFLAG_PROGRESSIVE 16384 /**