Merge branch 'master' into new-dzsave-overlaps

This commit is contained in:
John Cupitt 2016-09-08 09:42:34 +01:00
commit 4ba083437a
6 changed files with 85 additions and 56 deletions

View File

@ -2,7 +2,6 @@ language: cpp
before_script: before_script:
- ./autogen.sh - ./autogen.sh
- ./configure
--disable-dependency-tracking --disable-dependency-tracking
--with-jpeg-includes=$JPEG/include --with-jpeg-includes=$JPEG/include
--with-jpeg-libraries=$JPEG/lib --with-jpeg-libraries=$JPEG/lib

View File

@ -1818,15 +1818,21 @@ vips_foreign_save_dz_build( VipsObject *object )
if( (p = (char *) vips__find_rightmost_brackets( dz->basename )) ) if( (p = (char *) vips__find_rightmost_brackets( dz->basename )) )
*p = '\0'; *p = '\0';
if( (p = strrchr( dz->basename, '.' )) ) { if( (p = strrchr( dz->basename, '.' )) ) {
*p = '\0';
/* If we're writing to thing.zip or thing.szi, default to zip /* If we're writing to thing.zip or thing.szi, default to zip
* container. * container.
*/ */
if( !vips_object_argument_isset( object, "container" ) ) if( !vips_object_argument_isset( object, "container" ) )
if( strcasecmp( p + 1, "zip" ) == 0 || if( strcasecmp( p + 1, "zip" ) == 0 ||
strcasecmp( p + 1, "szi" ) == 0 ) strcasecmp( p + 1, "szi" ) == 0 )
dz->container = VIPS_FOREIGN_DZ_CONTAINER_ZIP; dz->container = VIPS_FOREIGN_DZ_CONTAINER_ZIP;
/* Always remove .szi, .zip, .dz. We don't remove all suffixes
* since we might be writing to a dirname with a dot in.
*/
if( strcasecmp( p + 1, "zip" ) == 0 ||
strcasecmp( p + 1, "szi" ) == 0 ||
strcasecmp( p + 1, "dz" ) == 0 )
*p = '\0';
} }
} }
@ -2053,7 +2059,7 @@ static int bandfmt_dz[10] = {
UC, C, US, S, UI, I, F, F, D, D UC, C, US, S, UI, I, F, F, D, D
}; };
const char *dz_suffs[] = { ".dz", NULL }; static const char *dz_suffs[] = { ".dz", NULL };
static void static void
vips_foreign_save_dz_class_init( VipsForeignSaveDzClass *class ) vips_foreign_save_dz_class_init( VipsForeignSaveDzClass *class )

View File

@ -77,6 +77,8 @@ typedef struct {
void vips__new_output_message( j_common_ptr cinfo ); void vips__new_output_message( j_common_ptr cinfo );
void vips__new_error_exit( j_common_ptr cinfo ); void vips__new_error_exit( j_common_ptr cinfo );
int vips__set_exif_resolution( ExifData *ed, VipsImage *im );
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /*__cplusplus*/ #endif /*__cplusplus*/

View File

@ -76,6 +76,9 @@
* - switch to new orientation tag * - switch to new orientation tag
* 11/7/16 * 11/7/16
* - new --fail handling * - new --fail handling
* 07/09/16
* - Don't use the exif resolution if x_resolution / y_resolution /
* resolution_unit is missing
*/ */
/* /*
@ -347,6 +350,27 @@ show_values( ExifData *data )
#endif /*HAVE_EXIF*/ #endif /*HAVE_EXIF*/
#ifdef HAVE_EXIF #ifdef HAVE_EXIF
/* Like exif_data_new_from_data(), but don't default missing fields.
*
* If we do exif_data_new_from_data(), then missing fields are set to
* their default value and we won't know about it.
*/
static ExifData *
vips_exif_load_data_without_fix( void *data, int data_length )
{
ExifData *ed;
if( !(ed = exif_data_new()) ) {
vips_error( "VipsJpeg", "%s", _( "unable to init exif" ) );
return( NULL );
}
exif_data_unset_option( ed, EXIF_DATA_OPTION_FOLLOW_SPECIFICATION );
exif_data_load_data( ed, data, data_length );
return( ed );
}
static int static int
vips_exif_get_int( ExifData *ed, vips_exif_get_int( ExifData *ed,
ExifEntry *entry, unsigned long component, int *out ) ExifEntry *entry, unsigned long component, int *out )
@ -538,7 +562,7 @@ get_entry_int( ExifData *ed, int ifd, ExifTag tag, int *out )
return( vips_exif_get_int( ed, entry, 0, out ) ); return( vips_exif_get_int( ed, entry, 0, out ) );
} }
static void static int
res_from_exif( VipsImage *im, ExifData *ed ) res_from_exif( VipsImage *im, ExifData *ed )
{ {
double xres, yres; double xres, yres;
@ -552,7 +576,7 @@ res_from_exif( VipsImage *im, ExifData *ed )
get_entry_int( ed, 0, EXIF_TAG_RESOLUTION_UNIT, &unit ) ) { get_entry_int( ed, 0, EXIF_TAG_RESOLUTION_UNIT, &unit ) ) {
vips_warn( "VipsJpeg", vips_warn( "VipsJpeg",
"%s", _( "error reading resolution" ) ); "%s", _( "error reading resolution" ) );
return; return( -1 );
} }
#ifdef DEBUG #ifdef DEBUG
@ -589,7 +613,7 @@ res_from_exif( VipsImage *im, ExifData *ed )
default: default:
vips_warn( "VipsJpeg", vips_warn( "VipsJpeg",
"%s", _( "unknown EXIF resolution unit" ) ); "%s", _( "unknown EXIF resolution unit" ) );
return; return( -1 );
} }
#ifdef DEBUG #ifdef DEBUG
@ -599,6 +623,8 @@ res_from_exif( VipsImage *im, ExifData *ed )
im->Xres = xres; im->Xres = xres;
im->Yres = yres; im->Yres = yres;
return( 0 );
} }
static int static int
@ -626,7 +652,7 @@ parse_exif( VipsImage *im, void *data, int data_length )
ExifData *ed; ExifData *ed;
VipsExif ve; VipsExif ve;
if( !(ed = exif_data_new_from_data( data, data_length )) ) if( !(ed = vips_exif_load_data_without_fix( data, data_length )) )
return( -1 ); return( -1 );
#ifdef DEBUG_VERBOSE #ifdef DEBUG_VERBOSE
@ -634,27 +660,28 @@ parse_exif( VipsImage *im, void *data, int data_length )
show_values( ed ); show_values( ed );
#endif /*DEBUG_VERBOSE*/ #endif /*DEBUG_VERBOSE*/
/* Look for resolution fields and use them to set the VIPS
* xres/yres fields.
*
* If the fields are missing, write the ones from jfif.
*/
if( res_from_exif( im, ed ) &&
vips__set_exif_resolution( ed, im ) )
return( -1 );
/* Make sure all required fields are there before we attach to vips
* metadata.
*/
exif_data_fix( ed );
/* Attach informational fields for what we find. /* Attach informational fields for what we find.
FIXME ... better to have this in the UI layer?
Or we could attach non-human-readable tags here (int,
double etc) and then move the human stuff to the UI
layer?
*/ */
ve.image = im; ve.image = im;
ve.ed = ed; ve.ed = ed;
exif_data_foreach_content( ed, exif_data_foreach_content( ed,
(ExifDataForeachContentFunc) attach_exif_content, &ve ); (ExifDataForeachContentFunc) attach_exif_content, &ve );
/* Look for resolution fields and use them to set the VIPS
* xres/yres fields.
*/
res_from_exif( im, ed );
attach_thumbnail( im, ed ); attach_thumbnail( im, ed );
exif_data_free( ed ); exif_data_free( ed );
} }
#endif /*HAVE_EXIF*/ #endif /*HAVE_EXIF*/

View File

@ -424,7 +424,7 @@ vips_foreign_save_jpeg_mime_init( VipsForeignSaveJpegMime *mime )
* * @optimize_coding: %gboolean, compute optimal Huffman coding tables * * @optimize_coding: %gboolean, compute optimal Huffman coding tables
* * @interlace: %gboolean, write an interlaced (progressive) jpeg * * @interlace: %gboolean, write an interlaced (progressive) jpeg
* * @strip: %gboolean, remove all metadata from image * * @strip: %gboolean, remove all metadata from image
* * @no-subsample: %gboolean, disable chroma subsampling * * @no_subsample: %gboolean, disable chroma subsampling
* * @trellis_quant: %gboolean, apply trellis quantisation to each 8x8 block * * @trellis_quant: %gboolean, apply trellis quantisation to each 8x8 block
* * @overshoot_deringing: %gboolean, overshoot samples with extreme values * * @overshoot_deringing: %gboolean, overshoot samples with extreme values
* * @optimize_scans: %gboolean, split DCT coefficients into separate scans * * @optimize_scans: %gboolean, split DCT coefficients into separate scans
@ -453,7 +453,7 @@ vips_foreign_save_jpeg_mime_init( VipsForeignSaveJpegMime *mime )
* If @strip is set, no EXIF data, IPCT data, ICC profile or XMP metadata is * If @strip is set, no EXIF data, IPCT data, ICC profile or XMP metadata is
* written into the output file. * written into the output file.
* *
* If @no-subsample is set, chrominance subsampling is disabled. This will * If @no_subsample is set, chrominance subsampling is disabled. This will
* improve quality at the cost of larger file size. Useful for high Q factors. * improve quality at the cost of larger file size. Useful for high Q factors.
* *
* If @trellis_quant is set and the version of libjpeg supports it * If @trellis_quant is set and the version of libjpeg supports it
@ -534,12 +534,12 @@ vips_jpegsave( VipsImage *in, const char *filename, ... )
* *
* Optional arguments: * Optional arguments:
* *
* * @Q: JPEG quality factor * * @Q: %gint, quality factor
* * @profile: attach this ICC profile * * @profile: filename of ICC profile to attach
* * @optimize_coding: compute optimal Huffman coding tables * * @optimize_coding: %gboolean, compute optimal Huffman coding tables
* * @interlace: write an interlaced (progressive) jpeg * * @interlace: %gboolean, write an interlaced (progressive) jpeg
* * @strip: remove all metadata from image * * @strip: %gboolean, remove all metadata from image
* * @no-subsample: disable chroma subsampling * * @no_subsample: %gboolean, disable chroma subsampling
* * @trellis_quant: %gboolean, apply trellis quantisation to each 8x8 block * * @trellis_quant: %gboolean, apply trellis quantisation to each 8x8 block
* * @overshoot_deringing: %gboolean, overshoot samples with extreme values * * @overshoot_deringing: %gboolean, overshoot samples with extreme values
* * @optimize_scans: %gboolean, split DCT coefficients into separate scans * * @optimize_scans: %gboolean, split DCT coefficients into separate scans
@ -590,11 +590,12 @@ vips_jpegsave_buffer( VipsImage *in, void **buf, size_t *len, ... )
* *
* Optional arguments: * Optional arguments:
* *
* * @Q: JPEG quality factor * * @Q: %gint, quality factor
* * @profile: attach this ICC profile * * @profile: filename of ICC profile to attach
* * @optimize_coding: compute optimal Huffman coding tables * * @optimize_coding: %gboolean, compute optimal Huffman coding tables
* * @strip: remove all metadata from image * * @interlace: %gboolean, write an interlaced (progressive) jpeg
* * @no-subsample: disable chroma subsampling * * @strip: %gboolean, remove all metadata from image
* * @no_subsample: %gboolean, disable chroma subsampling
* * @trellis_quant: %gboolean, apply trellis quantisation to each 8x8 block * * @trellis_quant: %gboolean, apply trellis quantisation to each 8x8 block
* * @overshoot_deringing: %gboolean, overshoot samples with extreme values * * @overshoot_deringing: %gboolean, overshoot samples with extreme values
* * @optimize_scans: %gboolean, split DCT coefficients into separate scans * * @optimize_scans: %gboolean, split DCT coefficients into separate scans

View File

@ -273,29 +273,21 @@ vips_exif_set_int( ExifData *ed,
static void static void
vips_exif_double_to_rational( double value, ExifRational *rv ) vips_exif_double_to_rational( double value, ExifRational *rv )
{ {
unsigned int scale; /* We will usually set factors of 10, so use 1000 as the denominator
* and it'll probably be OK.
/* We scale up to fill uint32, then set that as the
* denominator. Try to avoid generating 0.
*/ */
scale = (unsigned int) ((UINT_MAX - 1000) / value); rv->numerator = value * 1000;
scale = scale == 0 ? 1 : scale; rv->denominator = 1000;
rv->numerator = value * scale;
rv->denominator = scale;
} }
static void static void
vips_exif_double_to_srational( double value, ExifSRational *srv ) vips_exif_double_to_srational( double value, ExifSRational *srv )
{ {
int scale; /* We will usually set factors of 10, so use 1000 as the denominator
* and it'll probably be OK.
/* We scale up to fill int32, then set that as the
* denominator. Try to avoid generating 0.
*/ */
scale = (int) ((INT_MAX - 1000) / value); srv->numerator = value * 1000;
scale = scale == 0 ? 1 : scale; srv->denominator = 1000;
srv->numerator = value * scale;
srv->denominator = scale;
} }
/* Parse a char* into an ExifRational. We allow floats as well. /* Parse a char* into an ExifRational. We allow floats as well.
@ -461,15 +453,17 @@ write_tag( ExifData *ed, int ifd, ExifTag tag, write_fn fn, void *data )
/* This is different, we set the xres/yres from the vips header rather than /* This is different, we set the xres/yres from the vips header rather than
* from the exif tags on the image metadata. * from the exif tags on the image metadata.
*
* This is also called from the jpg reader to fix up bad exif resoltion.
*/ */
static int int
set_exif_resolution( ExifData *ed, VipsImage *im ) vips__set_exif_resolution( ExifData *ed, VipsImage *im )
{ {
double xres, yres; double xres, yres;
const char *p; const char *p;
int unit; int unit;
VIPS_DEBUG_MSG( "set_exif_resolution: vips res of %g, %g\n", VIPS_DEBUG_MSG( "vips__set_exif_resolution: vips res of %g, %g\n",
im->Xres, im->Yres ); im->Xres, im->Yres );
/* Default to inches, more progs support it. /* Default to inches, more progs support it.
@ -823,7 +817,7 @@ write_exif( Write *write )
/* Update EXIF resolution from the vips image header. /* Update EXIF resolution from the vips image header.
*/ */
if( set_exif_resolution( ed, write->in ) ) { if( vips__set_exif_resolution( ed, write->in ) ) {
exif_data_free( ed ); exif_data_free( ed );
return( -1 ); return( -1 );
} }