Merge branch 'master' of github.com:libvips/libvips

This commit is contained in:
John Cupitt 2019-03-16 11:53:53 +00:00
commit 8c2fff0a44
4 changed files with 66 additions and 11 deletions

View File

@ -927,6 +927,42 @@ if test x"$with_heif" != x"no"; then
) )
fi fi
# heif_context_set_primary_image not in 1.1
if test x"$with_heif" = x"yes"; then
save_LIBS="$LIBS"
LIBS="$LIBS $HEIF_LIBS"
AC_CHECK_FUNCS(heif_context_set_primary_image,[
AC_DEFINE(HAVE_HEIF_CONTEXT_SET_PRIMARY_IMAGE,1,
[define if you have heif_context_set_primary_image.])
],[]
)
LIBS="$save_LIBS"
fi
# heif_encoding_options_alloc not in 1.1
if test x"$with_heif" = x"yes"; then
save_LIBS="$LIBS"
LIBS="$LIBS $HEIF_LIBS"
AC_CHECK_FUNCS(heif_encoding_options_alloc,[
AC_DEFINE(HAVE_HEIF_ENCODING_OPTIONS_ALLOC,1,
[define if you have heif_encoding_options_alloc.])
],[]
)
LIBS="$save_LIBS"
fi
# exif/xmp profile support not in 1.1
if test x"$with_heif" = x"yes"; then
save_LIBS="$LIBS"
LIBS="$LIBS $HEIF_LIBS"
AC_CHECK_FUNCS(heif_context_add_exif_metadata,[
AC_DEFINE(HAVE_HEIF_CONTEXT_ADD_EXIF_METADATA,1,
[define if you have heif_context_add_exif_metadata.])
],[]
)
LIBS="$save_LIBS"
fi
# color profile support added in 1.3.3 # color profile support added in 1.3.3
if test x"$with_heif" = x"yes"; then if test x"$with_heif" = x"yes"; then
save_LIBS="$LIBS" save_LIBS="$LIBS"

View File

@ -108,6 +108,7 @@ vips_foreign_save_heif_dispose( GObject *gobject )
dispose( gobject ); dispose( gobject );
} }
#ifdef HAVE_HEIF_CONTEXT_ADD_EXIF_METADATA
typedef struct heif_error (*libheif_metadata_fn)( struct heif_context *, typedef struct heif_error (*libheif_metadata_fn)( struct heif_context *,
const struct heif_image_handle *, const struct heif_image_handle *,
const void *, int ); const void *, int );
@ -119,10 +120,12 @@ struct _VipsForeignSaveHeifMetadata {
{ VIPS_META_EXIF_NAME, heif_context_add_exif_metadata }, { VIPS_META_EXIF_NAME, heif_context_add_exif_metadata },
{ VIPS_META_XMP_NAME, heif_context_add_XMP_metadata } { VIPS_META_XMP_NAME, heif_context_add_XMP_metadata }
}; };
#endif /*HAVE_HEIF_CONTEXT_ADD_EXIF_METADATA*/
static int static int
vips_foreign_save_heif_write_metadata( VipsForeignSaveHeif *heif ) vips_foreign_save_heif_write_metadata( VipsForeignSaveHeif *heif )
{ {
#ifdef HAVE_HEIF_CONTEXT_ADD_EXIF_METADATA
VipsForeignSave *save = (VipsForeignSave *) heif; VipsForeignSave *save = (VipsForeignSave *) heif;
int i; int i;
@ -150,6 +153,7 @@ vips_foreign_save_heif_write_metadata( VipsForeignSaveHeif *heif )
return( -1 ); return( -1 );
} }
} }
#endif /*HAVE_HEIF_CONTEXT_ADD_EXIF_METADATA*/
return( 0 ); return( 0 );
} }
@ -187,22 +191,32 @@ vips_foreign_save_heif_write_page( VipsForeignSaveHeif *heif, int page )
} }
#endif /*HAVE_HEIF_COLOR_PROFILE*/ #endif /*HAVE_HEIF_COLOR_PROFILE*/
#ifdef HAVE_HEIF_ENCODING_OPTIONS_ALLOC
options = heif_encoding_options_alloc(); options = heif_encoding_options_alloc();
/* FIXME .. should be an option, though I don't know of any way to /* FIXME .. should be an option, though I don't know of any way to
* test it * test it
*/ */
options->save_alpha_channel = 1; options->save_alpha_channel = 1;
#else /*!HAVE_HEIF_ENCODING_OPTIONS_ALLOC*/
options = NULL;
#endif /*HAVE_HEIF_ENCODING_OPTIONS_ALLOC*/
#ifdef DEBUG #ifdef DEBUG
printf( "encoding ..\n" ); printf( "encoding ..\n" );
#endif /*DEBUG*/ #endif /*DEBUG*/
error = heif_context_encode_image( heif->ctx, error = heif_context_encode_image( heif->ctx,
heif->img, heif->encoder, NULL, &heif->handle ); heif->img, heif->encoder, options, &heif->handle );
#ifdef HAVE_HEIF_ENCODING_OPTIONS_ALLOC
heif_encoding_options_free( options ); heif_encoding_options_free( options );
#endif /*HAVE_HEIF_ENCODING_OPTIONS_ALLOC*/
if( error.code ) { if( error.code ) {
vips__heif_error( &error ); vips__heif_error( &error );
return( -1 ); return( -1 );
} }
#ifdef HAVE_HEIF_CONTEXT_SET_PRIMARY_IMAGE
if( vips_image_get_typeof( save->ready, "heif-primary" ) ) { if( vips_image_get_typeof( save->ready, "heif-primary" ) ) {
int primary; int primary;
@ -219,6 +233,7 @@ vips_foreign_save_heif_write_page( VipsForeignSaveHeif *heif, int page )
} }
} }
} }
#endif /*HAVE_HEIF_CONTEXT_SET_PRIMARY_IMAGE*/
if( !save->strip && if( !save->strip &&
vips_foreign_save_heif_write_metadata( heif ) ) vips_foreign_save_heif_write_metadata( heif ) )

View File

@ -535,14 +535,15 @@ vips__openslide_read( const char *filename, VipsImage *out,
NULL, vips__openslide_generate, NULL, rslide, NULL ) ) NULL, vips__openslide_generate, NULL, rslide, NULL ) )
return( -1 ); return( -1 );
/* Copy to out, adding a cache. Enough tiles for a complete row, plus /* Copy to out, adding a cache. Enough tiles for two complete rows,
* 50%. * plus 50%. We need at least two rows, or we'll constantly reload
* tiles if they cross a tile boundary.
*/ */
if( vips_tilecache( raw, &t, if( vips_tilecache( raw, &t,
"tile_width", rslide->tile_width, "tile_width", rslide->tile_width,
"tile_height", rslide->tile_height, "tile_height", rslide->tile_height,
"max_tiles", "max_tiles",
(int) (1.5 * (1 + raw->Xsize / rslide->tile_width)), (int) (2.5 * (1 + raw->Xsize / rslide->tile_width)),
"threaded", TRUE, "threaded", TRUE,
NULL ) ) NULL ) )
return( -1 ); return( -1 );

View File

@ -871,15 +871,18 @@ class TestForeign:
# the exif test will need us to be able to walk the header, # the exif test will need us to be able to walk the header,
# we can't just check exif-data # we can't just check exif-data
# libheif 1.1 (on ubuntu 18.04, current LTS) does not support exif
# write, so this test is commented out
# test that exif changes change the output of heifsave # test that exif changes change the output of heifsave
# first make sure we have exif support # first make sure we have exif support
z = pyvips.Image.new_from_file(JPEG_FILE) #z = pyvips.Image.new_from_file(JPEG_FILE)
if z.get_typeof("exif-ifd0-Orientation") != 0: #if z.get_typeof("exif-ifd0-Orientation") != 0:
x = self.colour.copy() # x = self.colour.copy()
x.set("exif-ifd0-Make", "banana") # x.set("exif-ifd0-Make", "banana")
buf = x.heifsave_buffer() # buf = x.heifsave_buffer()
y = pyvips.Image.new_from_buffer(buf, "") # y = pyvips.Image.new_from_buffer(buf, "")
assert y.get("exif-ifd0-Make").split(" ")[0] == "banana" # assert y.get("exif-ifd0-Make").split(" ")[0] == "banana"
if __name__ == '__main__': if __name__ == '__main__':
pytest.main() pytest.main()