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
This commit is contained in:
John Cupitt 2015-11-25 13:17:30 +00:00
parent 18baf40b1a
commit 9b03b27b9c

View File

@ -69,7 +69,9 @@
* - omit oversized jpeg markers * - omit oversized jpeg markers
* 15/7/15 * 15/7/15
* - exif tags use @name, not @title * - 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 #ifdef HAVE_JPEG_EXT_PARAMS
/* Reset compression profile to libjpeg defaults /* Reset compression profile to libjpeg defaults
*/ */
if( jpeg_c_int_param_supported( &write->cinfo, JINT_COMPRESS_PROFILE ) ) { if( jpeg_c_int_param_supported( &write->cinfo, JINT_COMPRESS_PROFILE ) )
jpeg_c_set_int_param( &write->cinfo, JINT_COMPRESS_PROFILE, JCP_FASTEST ); jpeg_c_set_int_param( &write->cinfo,
} JINT_COMPRESS_PROFILE, JCP_FASTEST );
#endif #endif
/* Rest to default. /* Rest to default.
@ -955,61 +957,62 @@ write_vips( Write *write, int qfac, const char *profile,
write->cinfo.optimize_coding = optimize_coding; write->cinfo.optimize_coding = optimize_coding;
#ifdef HAVE_JPEG_EXT_PARAMS #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( trellis_quant ) {
if ( jpeg_c_bool_param_supported( if( jpeg_c_bool_param_supported( &write->cinfo,
&write->cinfo, JBOOLEAN_TRELLIS_QUANT ) ) { JBOOLEAN_TRELLIS_QUANT ) ) {
jpeg_c_set_bool_param( &write->cinfo, jpeg_c_set_bool_param( &write->cinfo,
JBOOLEAN_TRELLIS_QUANT, TRUE ); JBOOLEAN_TRELLIS_QUANT, TRUE );
write->cinfo.optimize_coding = TRUE; write->cinfo.optimize_coding = TRUE;
} }
else { else
vips_warn( "vips2jpeg", "%s", _( "trellis_quant unsupported" ) ); 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( overshoot_deringing ) {
if ( jpeg_c_bool_param_supported( if( jpeg_c_bool_param_supported( &write->cinfo,
&write->cinfo, JBOOLEAN_OVERSHOOT_DERINGING ) ) { JBOOLEAN_OVERSHOOT_DERINGING ) )
jpeg_c_set_bool_param( &write->cinfo, jpeg_c_set_bool_param( &write->cinfo,
JBOOLEAN_OVERSHOOT_DERINGING, TRUE ); JBOOLEAN_OVERSHOOT_DERINGING, TRUE );
} else
else { vips_warn( "vips2jpeg",
vips_warn( "vips2jpeg", "%s", _( "overshoot_deringing unsupported" ) ); "%s", _( "overshoot_deringing unsupported" ) );
}
} }
/* Split the spectrum of DCT coefficients into separate scans. /* 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( optimize_scans ) {
if( progressive ) { if( progressive ) {
if( jpeg_c_bool_param_supported( if( jpeg_c_bool_param_supported( &write->cinfo,
&write->cinfo, JBOOLEAN_OPTIMIZE_SCANS ) ) { JBOOLEAN_OPTIMIZE_SCANS ) )
jpeg_c_set_bool_param( &write->cinfo, JBOOLEAN_OPTIMIZE_SCANS, TRUE ); jpeg_c_set_bool_param( &write->cinfo,
} JBOOLEAN_OPTIMIZE_SCANS, TRUE );
else { else
vips_warn( "vips2jpeg", "%s", _( "Ignoring optimize_scans" ) ); vips_warn( "vips2jpeg",
} "%s", _( "Ignoring optimize_scans" ) );
} }
else { else
vips_warn( "vips2jpeg", "%s", vips_warn( "vips2jpeg", "%s",
_( "Ignoring optimize_scans for baseline" ) ); _( "Ignoring optimize_scans for baseline" ) );
}
} }
#else #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" ) ); vips_warn( "vips2jpeg", "%s", _( "Ignoring trellis_quant" ) );
} if( overshoot_deringing )
if ( overshoot_deringing ) { vips_warn( "vips2jpeg",
vips_warn( "vips2jpeg", "%s", _( "Ignoring overshoot_deringing" ) ); "%s", _( "Ignoring overshoot_deringing" ) );
} if( optimize_scans )
if ( optimize_scans ) {
vips_warn( "vips2jpeg", "%s", _( "Ignoring optimize_scans" ) ); vips_warn( "vips2jpeg", "%s", _( "Ignoring optimize_scans" ) );
}
#endif #endif
/* Enable progressive write. /* 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. /* Build compress tables.
*/ */
jpeg_start_compress( &write->cinfo, TRUE ); jpeg_start_compress( &write->cinfo, TRUE );