diff --git a/jpegtran.c b/jpegtran.c index 73dbe530..f861464b 100644 --- a/jpegtran.c +++ b/jpegtran.c @@ -142,6 +142,7 @@ parse_switches (j_compress_ptr cinfo, int argc, char **argv, transformoption.trim = FALSE; transformoption.force_grayscale = FALSE; transformoption.crop = FALSE; + transformoption.slow_hflip = FALSE; cinfo->err->trace_level = 0; /* Scan command line options, adjust parameters */ diff --git a/transupp.c b/transupp.c index 5c314168..25136910 100644 --- a/transupp.c +++ b/transupp.c @@ -1022,7 +1022,7 @@ jtransform_request_workspace (j_decompress_ptr srcinfo, case JXFORM_FLIP_H: if (info->trim) trim_right_edge(info, srcinfo->output_width); - if (info->y_crop_offset != 0) + if (info->y_crop_offset != 0 || info->slow_hflip) need_workspace = TRUE; /* do_flip_h_no_crop doesn't need a workspace array */ break; @@ -1448,7 +1448,7 @@ jtransform_execute_transform (j_decompress_ptr srcinfo, src_coef_arrays, dst_coef_arrays); break; case JXFORM_FLIP_H: - if (info->y_crop_offset != 0) + if (info->y_crop_offset != 0 || info->slow_hflip) do_flip_h(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset, src_coef_arrays, dst_coef_arrays); else diff --git a/transupp.h b/transupp.h index 7c16c19c..122d448b 100644 --- a/transupp.h +++ b/transupp.h @@ -128,6 +128,13 @@ typedef struct { boolean trim; /* if TRUE, trim partial MCUs as needed */ boolean force_grayscale; /* if TRUE, convert color image to grayscale */ boolean crop; /* if TRUE, crop source image */ + boolean slow_hflip; /* For best performance, the JXFORM_FLIP_H transform + normally modifies the source coefficients in place. + Setting this to TRUE will instead use a slower, + double-buffered algorithm, which leaves the source + coefficients in tact (necessary if other transformed + images must be generated from the same set of + coefficients. */ /* Crop parameters: application need not set these unless crop is TRUE. * These can be filled in by jtransform_parse_crop_spec(). diff --git a/turbojpegl.c b/turbojpegl.c index c2ca1fcb..bc0ef7fb 100644 --- a/turbojpegl.c +++ b/turbojpegl.c @@ -751,6 +751,8 @@ DLLEXPORT int DLLCALL tjTransform(tjhandle hnd, xinfo[i].trim=(t[i].options&TJXFORM_TRIM)? 1:0; xinfo[i].force_grayscale=(t[i].options&TJXFORM_GRAY)? 1:0; xinfo[i].crop=(t[i].options&TJXFORM_CROP)? 1:0; + if(n!=1 && t[i].op==TJXFORM_HFLIP) xinfo[i].slow_hflip=1; + else xinfo[i].slow_hflip=0; if(xinfo[i].crop) {