From dadebcd79ad37c8b1ca32f8acae194e721bc3ae1 Mon Sep 17 00:00:00 2001 From: DRC Date: Wed, 28 Jun 2017 11:43:08 -0500 Subject: [PATCH] TurboJPEG: Add "copy none", progressive xform opts Allow progressive entropy coding to be enabled on a transform-by-transform basis, and implement a new transform option for disabling the copying of markers. Closes #153 --- ChangeLog.md | 10 +++- doc/html/group___turbo_j_p_e_g.html | 35 ++++++++++++++ doc/html/search/all_74.js | 4 +- java/TJBench.java | 4 ++ java/doc/constant-values.html | 20 ++++++-- java/doc/index-all.html | 10 ++++ .../libjpegturbo/turbojpeg/TJTransform.html | 47 +++++++++++++++++-- .../libjpegturbo/turbojpeg/TJTransform.java | 24 ++++++++-- tjbench.c | 3 ++ turbojpeg.c | 10 ++-- turbojpeg.h | 24 ++++++++-- 11 files changed, 169 insertions(+), 22 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index ab1e769..8e2c563 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -63,7 +63,15 @@ 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. +transform operations. Additionally, a new transform option +(`TJXOPT_PROGRESSIVE` in the C API and `TJTransform.OPT_PROGRESSIVE` in the +Java API) has been introduced, allowing progressive entropy coding to be +enabled for selected transforms in a multi-transform operation. + +6. Introduced a new transform option in the TurboJPEG API (`TJXOPT_COPYNONE` in +the C API and `TJTransform.OPT_COPYNONE` in the Java API) that allows the +copying of markers (including EXIF and ICC profile data) to be disabled for a +particular transform. 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 3246eaa..cdaab54 100644 --- a/doc/html/group___turbo_j_p_e_g.html +++ b/doc/html/group___turbo_j_p_e_g.html @@ -155,6 +155,12 @@ Macros #define TJXOPT_NOOUTPUT  This option will prevent tjTransform() from outputting a JPEG image for this particular transform (this can be used in conjunction with a custom filter to capture the transformed DCT coefficients without transcoding them.) More...
  +#define TJXOPT_PROGRESSIVE + This option will enable progressive entropy coding in the output image generated by this particular transform. More...
+  +#define TJXOPT_COPYNONE + This option will prevent tjTransform() from copying any extra markers (including EXIF and ICC profile data) from the source image to the output image. More...
+  #define TJPAD(width)  Pad the given width to the nearest 32-bit boundary. More...
  @@ -565,6 +571,20 @@ Variables

Compute the scaled value of dimension using the given scaling factor.

This macro performs the integer equivalent of ceil(dimension * scalingFactor).

+ + + +
+
+ + + + +
#define TJXOPT_COPYNONE
+
+ +

This option will prevent tjTransform() from copying any extra markers (including EXIF and ICC profile data) from the source image to the output image.

+
@@ -623,6 +643,21 @@ Variables

This option will cause tjTransform() to return an error if the transform is not perfect.

Lossless transforms operate on MCU blocks, whose size depends on the level of chrominance subsampling used (see tjMCUWidth and tjMCUHeight.) If the image's width or height is not evenly divisible by the MCU block size, then there will be partial MCU blocks on the right and/or bottom edges. It is not possible to move these partial MCU blocks to the top or left of the image, so any transform that would require that is "imperfect." If this option is not specified, then any partial MCU blocks that cannot be transformed will be left in place, which will create odd-looking strips on the right or bottom edge of the image.

+ + + +
+
+ + + + +
#define TJXOPT_PROGRESSIVE
+
+ +

This option will enable progressive entropy coding in the output image generated by this particular transform.

+

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 d56e332..a211e3d 100644 --- a/doc/html/search/all_74.js +++ b/doc/html/search/all_74.js @@ -77,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#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']]], + ['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']]], ['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']]], @@ -87,10 +87,12 @@ var searchData= ['tjxop_5ftranspose',['TJXOP_TRANSPOSE',['../group___turbo_j_p_e_g.html#gga2de531af4e7e6c4f124908376b354866a31060aed199f886afdd417f80499c32d',1,'turbojpeg.h']]], ['tjxop_5ftransverse',['TJXOP_TRANSVERSE',['../group___turbo_j_p_e_g.html#gga2de531af4e7e6c4f124908376b354866af3b14d488aea6ece9e5b3df73a74d6a4',1,'turbojpeg.h']]], ['tjxop_5fvflip',['TJXOP_VFLIP',['../group___turbo_j_p_e_g.html#gga2de531af4e7e6c4f124908376b354866a324eddfbec53b7e691f61e56929d0d5d',1,'turbojpeg.h']]], + ['tjxopt_5fcopynone',['TJXOPT_COPYNONE',['../group___turbo_j_p_e_g.html#ga153b468cfb905d0de61706c838986fe8',1,'turbojpeg.h']]], ['tjxopt_5fcrop',['TJXOPT_CROP',['../group___turbo_j_p_e_g.html#ga9c771a757fc1294add611906b89ab2d2',1,'turbojpeg.h']]], ['tjxopt_5fgray',['TJXOPT_GRAY',['../group___turbo_j_p_e_g.html#ga3acee7b48ade1b99e5588736007c2589',1,'turbojpeg.h']]], ['tjxopt_5fnooutput',['TJXOPT_NOOUTPUT',['../group___turbo_j_p_e_g.html#gafbf992bbf6e006705886333703ffab31',1,'turbojpeg.h']]], ['tjxopt_5fperfect',['TJXOPT_PERFECT',['../group___turbo_j_p_e_g.html#ga50e03cb5ed115330e212417429600b00',1,'turbojpeg.h']]], + ['tjxopt_5fprogressive',['TJXOPT_PROGRESSIVE',['../group___turbo_j_p_e_g.html#gad2371c80674584ecc1a7d75e564cf026',1,'turbojpeg.h']]], ['tjxopt_5ftrim',['TJXOPT_TRIM',['../group___turbo_j_p_e_g.html#ga319826b7eb1583c0595bbe7b95428709',1,'turbojpeg.h']]], ['turbojpeg',['TurboJPEG',['../group___turbo_j_p_e_g.html',1,'']]] ]; diff --git a/java/TJBench.java b/java/TJBench.java index 6f5f335..f1de27a 100644 --- a/java/TJBench.java +++ b/java/TJBench.java @@ -669,6 +669,8 @@ class TJBench { System.out.println(" decompression (these options are mutually exclusive)"); System.out.println("-grayscale = Perform lossless grayscale conversion prior to decompression"); System.out.println(" test (can be combined with the other transforms above)"); + System.out.println("-copynone = Do not copy any extra markers (including EXIF and ICC profile data)"); + System.out.println(" when transforming the image."); System.out.println("-benchtime = Run each benchmark for at least seconds (default = 5.0)"); System.out.println("-warmup = Run each benchmark for seconds (default = 1.0) prior to"); System.out.println(" starting the timer, in order to prime the caches and thus improve the"); @@ -801,6 +803,8 @@ class TJBench { xformOpt |= TJTransform.OPT_GRAY; if (argv[i].equalsIgnoreCase("-nooutput")) xformOpt |= TJTransform.OPT_NOOUTPUT; + if (argv[i].equalsIgnoreCase("-copynone")) + xformOpt |= TJTransform.OPT_COPYNONE; if (argv[i].equalsIgnoreCase("-benchtime") && i < argv.length - 1) { double temp = -1; try { diff --git a/java/doc/constant-values.html b/java/doc/constant-values.html index 74366d4..985784e 100644 --- a/java/doc/constant-values.html +++ b/java/doc/constant-values.html @@ -428,33 +428,47 @@ 2 + + +public static final int +OPT_COPYNONE +64 + + public static final int OPT_CROP 4 - + public static final int OPT_GRAY 8 - + public static final int OPT_NOOUTPUT 16 - + public static final int OPT_PERFECT 1 + + + +public static final int +OPT_PROGRESSIVE +32 + diff --git a/java/doc/index-all.html b/java/doc/index-all.html index 8f05a42..a9d139a 100644 --- a/java/doc/index-all.html +++ b/java/doc/index-all.html @@ -599,6 +599,11 @@
Flip (mirror) image vertically.
+
OPT_COPYNONE - Static variable in class org.libjpegturbo.turbojpeg.TJTransform
+
+
This option will prevent TJTransformer.transform() from copying any extra markers (including EXIF + and ICC profile data) from the source image to the output image.
+
OPT_CROP - Static variable in class org.libjpegturbo.turbojpeg.TJTransform
This option will enable lossless cropping.
@@ -618,6 +623,11 @@
This option will cause TJTransformer.transform() to throw an exception if the transform is not perfect.
+
OPT_PROGRESSIVE - Static variable in class org.libjpegturbo.turbojpeg.TJTransform
+
+
This option will enable progressive entropy coding in the output image + generated by this particular transform.
+
OPT_TRIM - Static variable in class org.libjpegturbo.turbojpeg.TJTransform
This option will discard any partial MCU blocks that cannot be diff --git a/java/doc/org/libjpegturbo/turbojpeg/TJTransform.html b/java/doc/org/libjpegturbo/turbojpeg/TJTransform.html index cf65bd2..86fafa3 100644 --- a/java/doc/org/libjpegturbo/turbojpeg/TJTransform.html +++ b/java/doc/org/libjpegturbo/turbojpeg/TJTransform.html @@ -217,31 +217,45 @@ extends java.awt.Rectangle static int +OPT_COPYNONE +
This option will prevent TJTransformer.transform() from copying any extra markers (including EXIF + and ICC profile data) from the source image to the output image.
+ + + +static int OPT_CROP
This option will enable lossless cropping.
- + static int OPT_GRAY
This option will discard the color data in the input image and produce a grayscale output image.
- + static int OPT_NOOUTPUT
This option will prevent TJTransformer.transform() from outputting a JPEG image for this particular transform.
- + static int OPT_PERFECT
This option will cause TJTransformer.transform() to throw an exception if the transform is not perfect.
+ +static int +OPT_PROGRESSIVE +
This option will enable progressive entropy coding in the output image + generated by this particular transform.
+ + static int OPT_TRIM @@ -548,6 +562,33 @@ extends java.awt.Rectangle
See Also:
Constant Field Values
+ + + +
    +
  • +

    OPT_PROGRESSIVE

    +
    public static final int OPT_PROGRESSIVE
    +
    This option will enable progressive entropy coding in the output image + generated by this particular transform. 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
    +
  • +
+ + + +
    +
  • +

    OPT_COPYNONE

    +
    public static final int OPT_COPYNONE
    +
    This option will prevent TJTransformer.transform() from copying any extra markers (including EXIF + and ICC profile data) from the source image to the output image.
    +
    See Also:
    Constant Field Values
    +
  • +
diff --git a/java/org/libjpegturbo/turbojpeg/TJTransform.java b/java/org/libjpegturbo/turbojpeg/TJTransform.java index 7381f36..1b10d3d 100644 --- a/java/org/libjpegturbo/turbojpeg/TJTransform.java +++ b/java/org/libjpegturbo/turbojpeg/TJTransform.java @@ -103,21 +103,21 @@ public class TJTransform extends Rectangle { * partial MCU blocks that cannot be transformed will be left in place, which * will create odd-looking strips on the right or bottom edge of the image. */ - public static final int OPT_PERFECT = 1; + public static final int OPT_PERFECT = 1; /** * This option will discard any partial MCU blocks that cannot be * transformed. */ - public static final int OPT_TRIM = 2; + public static final int OPT_TRIM = 2; /** * This option will enable lossless cropping. */ - public static final int OPT_CROP = 4; + public static final int OPT_CROP = 4; /** * This option will discard the color data in the input image and produce * a grayscale output image. */ - public static final int OPT_GRAY = 8; + public static final int OPT_GRAY = 8; /** * This option will prevent {@link TJTransformer#transform * TJTransformer.transform()} from outputting a JPEG image for this @@ -125,7 +125,21 @@ public class TJTransform extends Rectangle { * filter to capture the transformed DCT coefficients without transcoding * them. */ - public static final int OPT_NOOUTPUT = 16; + public static final int OPT_NOOUTPUT = 16; + /** + * This option will enable progressive entropy coding in the output image + * generated by this particular transform. 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 OPT_PROGRESSIVE = 32; + /** + * This option will prevent {@link TJTransformer#transform + * TJTransformer.transform()} from copying any extra markers (including EXIF + * and ICC profile data) from the source image to the output image. + */ + public static final int OPT_COPYNONE = 64; /** diff --git a/tjbench.c b/tjbench.c index a5be7d4..450e128 100644 --- a/tjbench.c +++ b/tjbench.c @@ -785,6 +785,8 @@ void usage(char *progname) printf(" decompression (these options are mutually exclusive)\n"); printf("-grayscale = Perform lossless grayscale conversion prior to decompression\n"); printf(" test (can be combined with the other transforms above)\n"); + printf("-copynone = Do not copy any extra markers (including EXIF and ICC profile data)\n"); + printf(" when transforming the image.\n"); printf("-benchtime = Run each benchmark for at least seconds (default = 5.0)\n"); printf("-warmup = Run each benchmark for seconds (default = 1.0) prior to\n"); printf(" starting the timer, in order to prime the caches and thus improve the\n"); @@ -902,6 +904,7 @@ int main(int argc, char *argv[]) if(!strcasecmp(argv[i], "-grayscale")) xformopt|=TJXOPT_GRAY; if(!strcasecmp(argv[i], "-custom")) customFilter=dummyDCTFilter; if(!strcasecmp(argv[i], "-nooutput")) xformopt|=TJXOPT_NOOUTPUT; + if(!strcasecmp(argv[i], "-copynone")) xformopt|=TJXOPT_COPYNONE; if(!strcasecmp(argv[i], "-benchtime") && ijerr.stopOnWarning=(flags & TJFLAG_STOPONWARNING) ? TRUE : FALSE; @@ -2140,9 +2140,10 @@ DLLEXPORT int DLLCALL tjTransform(tjhandle handle, } else xinfo[i].crop_height=JCROP_UNSET; } + if(!(t[i].options&TJXOPT_COPYNONE)) saveMarkers=1; } - jcopy_markers_setup(dinfo, JCOPYOPT_ALL); + jcopy_markers_setup(dinfo, saveMarkers ? JCOPYOPT_ALL:JCOPYOPT_NONE); jpeg_read_header(dinfo, TRUE); jpegSubsamp=getSubsamp(dinfo); if(jpegSubsamp<0) @@ -2189,12 +2190,13 @@ 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) + if(flags&TJFLAG_PROGRESSIVE || t[i].options&TJXOPT_PROGRESSIVE) jpeg_simple_progression(cinfo); if(!(t[i].options&TJXOPT_NOOUTPUT)) { jpeg_write_coefficients(cinfo, dstcoefs); - jcopy_markers_execute(dinfo, cinfo, JCOPYOPT_ALL); + jcopy_markers_execute(dinfo, cinfo, + t[i].options&TJXOPT_COPYNONE ? JCOPYOPT_NONE:JCOPYOPT_ALL); } else jinit_c_master_control(cinfo, TRUE); jtransform_execute_transformation(dinfo, cinfo, srccoefs, diff --git a/turbojpeg.h b/turbojpeg.h index 8b4a4da..c4e48cc 100644 --- a/turbojpeg.h +++ b/turbojpeg.h @@ -488,29 +488,43 @@ enum TJXOP * that cannot be transformed will be left in place, which will create * odd-looking strips on the right or bottom edge of the image. */ -#define TJXOPT_PERFECT 1 +#define TJXOPT_PERFECT 1 /** * This option will cause #tjTransform() to discard any partial MCU blocks that * cannot be transformed. */ -#define TJXOPT_TRIM 2 +#define TJXOPT_TRIM 2 /** * This option will enable lossless cropping. See #tjTransform() for more * information. */ -#define TJXOPT_CROP 4 +#define TJXOPT_CROP 4 /** * This option will discard the color data in the input image and produce * a grayscale output image. */ -#define TJXOPT_GRAY 8 +#define TJXOPT_GRAY 8 /** * This option will prevent #tjTransform() from outputting a JPEG image for * this particular transform (this can be used in conjunction with a custom * filter to capture the transformed DCT coefficients without transcoding * them.) */ -#define TJXOPT_NOOUTPUT 16 +#define TJXOPT_NOOUTPUT 16 +/** + * This option will enable progressive entropy coding in the output image + * generated by this particular transform. Progressive entropy coding will + * generally improve compression relative to baseline entropy coding (the + * default), but it will reduce compression and decompression performance + * considerably. + */ +#define TJXOPT_PROGRESSIVE 32 +/** + * This option will prevent #tjTransform() from copying any extra markers + * (including EXIF and ICC profile data) from the source image to the output + * image. + */ +#define TJXOPT_COPYNONE 64 /** -- 2.40.0