From 9b03b27b9ce8915f057487c5b050085a5cb0ea4c Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Wed, 25 Nov 2015 13:17:30 +0000 Subject: [PATCH] don't write JFIF headers with [strip] saving a jpg with [strip] turned on now stops the APP0 jfif headers being written thanks Benjamin, see: https://github.com/jcupitt/libvips/issues/349 --- libvips/foreign/vips2jpeg.c | 78 ++++++++++++++++++++----------------- 1 file changed, 43 insertions(+), 35 deletions(-) diff --git a/libvips/foreign/vips2jpeg.c b/libvips/foreign/vips2jpeg.c index 10bae518..dc153732 100644 --- a/libvips/foreign/vips2jpeg.c +++ b/libvips/foreign/vips2jpeg.c @@ -69,7 +69,9 @@ * - omit oversized jpeg markers * 15/7/15 * - exif tags use @name, not @title -* - set arbitrary exif tags from metadata + * - set arbitrary exif tags from metadata + * 25/11/15 + * - don't write JFIF headers if we are stripping, thanks Benjamin */ /* @@ -940,9 +942,9 @@ write_vips( Write *write, int qfac, const char *profile, #ifdef HAVE_JPEG_EXT_PARAMS /* Reset compression profile to libjpeg defaults */ - if( jpeg_c_int_param_supported( &write->cinfo, JINT_COMPRESS_PROFILE ) ) { - jpeg_c_set_int_param( &write->cinfo, JINT_COMPRESS_PROFILE, JCP_FASTEST ); - } + if( jpeg_c_int_param_supported( &write->cinfo, JINT_COMPRESS_PROFILE ) ) + jpeg_c_set_int_param( &write->cinfo, + JINT_COMPRESS_PROFILE, JCP_FASTEST ); #endif /* Rest to default. @@ -955,61 +957,62 @@ write_vips( Write *write, int qfac, const char *profile, write->cinfo.optimize_coding = optimize_coding; #ifdef HAVE_JPEG_EXT_PARAMS - /* Apply trellis quantisation to each 8x8 block. Infers "optimize_coding". + /* Apply trellis quantisation to each 8x8 block. Implies + * "optimize_coding". */ if( trellis_quant ) { - if ( jpeg_c_bool_param_supported( - &write->cinfo, JBOOLEAN_TRELLIS_QUANT ) ) { + if( jpeg_c_bool_param_supported( &write->cinfo, + JBOOLEAN_TRELLIS_QUANT ) ) { jpeg_c_set_bool_param( &write->cinfo, JBOOLEAN_TRELLIS_QUANT, TRUE ); write->cinfo.optimize_coding = TRUE; } - else { - vips_warn( "vips2jpeg", "%s", _( "trellis_quant unsupported" ) ); - } + else + vips_warn( "vips2jpeg", + "%s", _( "trellis_quant unsupported" ) ); } - /* Apply overshooting to samples with extreme values e.g. 0 & 255 for 8-bit. + + /* Apply overshooting to samples with extreme values e.g. 0 & 255 + * for 8-bit. */ if( overshoot_deringing ) { - if ( jpeg_c_bool_param_supported( - &write->cinfo, JBOOLEAN_OVERSHOOT_DERINGING ) ) { + if( jpeg_c_bool_param_supported( &write->cinfo, + JBOOLEAN_OVERSHOOT_DERINGING ) ) jpeg_c_set_bool_param( &write->cinfo, JBOOLEAN_OVERSHOOT_DERINGING, TRUE ); - } - else { - vips_warn( "vips2jpeg", "%s", _( "overshoot_deringing unsupported" ) ); - } + else + vips_warn( "vips2jpeg", + "%s", _( "overshoot_deringing unsupported" ) ); } /* Split the spectrum of DCT coefficients into separate scans. - * Requires progressive output. Must be set before jpeg_simple_progression. + * Requires progressive output. Must be set before + * jpeg_simple_progression. */ if( optimize_scans ) { if( progressive ) { - if( jpeg_c_bool_param_supported( - &write->cinfo, JBOOLEAN_OPTIMIZE_SCANS ) ) { - jpeg_c_set_bool_param( &write->cinfo, JBOOLEAN_OPTIMIZE_SCANS, TRUE ); - } - else { - vips_warn( "vips2jpeg", "%s", _( "Ignoring optimize_scans" ) ); - } + if( jpeg_c_bool_param_supported( &write->cinfo, + JBOOLEAN_OPTIMIZE_SCANS ) ) + jpeg_c_set_bool_param( &write->cinfo, + JBOOLEAN_OPTIMIZE_SCANS, TRUE ); + else + vips_warn( "vips2jpeg", + "%s", _( "Ignoring optimize_scans" ) ); } - else { + else vips_warn( "vips2jpeg", "%s", _( "Ignoring optimize_scans for baseline" ) ); - } } #else - /* Using jpeglib.h without extension parameters, warn of ignored options. + /* Using jpeglib.h without extension parameters, warn of ignored + * options. */ - if ( trellis_quant ) { + if( trellis_quant ) vips_warn( "vips2jpeg", "%s", _( "Ignoring trellis_quant" ) ); - } - if ( overshoot_deringing ) { - vips_warn( "vips2jpeg", "%s", _( "Ignoring overshoot_deringing" ) ); - } - if ( optimize_scans ) { + if( overshoot_deringing ) + vips_warn( "vips2jpeg", + "%s", _( "Ignoring overshoot_deringing" ) ); + if( optimize_scans ) vips_warn( "vips2jpeg", "%s", _( "Ignoring optimize_scans" ) ); - } #endif /* Enable progressive write. @@ -1028,6 +1031,11 @@ write_vips( Write *write, int qfac, const char *profile, } } + /* Don't write the APP0 JFIF headers if we are stripping. + */ + if( strip ) + write->cinfo.write_JFIF_header = FALSE; + /* Build compress tables. */ jpeg_start_compress( &write->cinfo, TRUE );