From cae57d5670c01f302032efe7545526768104a0e2 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Wed, 20 Feb 2019 12:30:12 +0000 Subject: [PATCH] make heif load/save work with 1.3.2 --- configure.ac | 12 ++++++++++++ libvips/foreign/heifload.c | 2 ++ libvips/foreign/heifsave.c | 2 ++ test/test-suite/test_foreign.py | 8 +++++--- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index 47846761..6285d5e3 100644 --- a/configure.ac +++ b/configure.ac @@ -927,6 +927,18 @@ if test x"$with_heif" != x"no"; then ) fi +# color profile support added in 1.3.3 +if test x"$with_heif" = x"yes"; then + save_LIBS="$LIBS" + LIBS="$LIBS $HEIF_LIBS" + AC_CHECK_FUNCS(heif_image_handle_get_raw_color_profile,[ + AC_DEFINE(HAVE_HEIF_COLOR_PROFILE,1, + [define if you have heif_image_handle_get_raw_color_profile.]) + ],[] + ) + LIBS="$save_LIBS" +fi + # pdfium AC_ARG_WITH([pdfium], AS_HELP_STRING([--without-pdfium], [build without pdfium (default: test)])) diff --git a/libvips/foreign/heifload.c b/libvips/foreign/heifload.c index 80615ee5..4f6d8826 100644 --- a/libvips/foreign/heifload.c +++ b/libvips/foreign/heifload.c @@ -356,6 +356,7 @@ vips_foreign_load_heif_set_header( VipsForeignLoadHeif *heif, VipsImage *out ) } #endif /*DEBUG*/ +#ifdef HAVE_HEIF_COLOR_PROFILE /* FIXME should probably check the profile type ... lcms seems to be * able to load at least rICC and prof. */ @@ -381,6 +382,7 @@ vips_foreign_load_heif_set_header( VipsForeignLoadHeif *heif, VipsImage *out ) vips_image_set_blob( out, VIPS_META_ICC_NAME, (VipsCallbackFn) NULL, data, length ); } +#endif /*HAVE_HEIF_COLOR_PROFILE*/ return( 0 ); } diff --git a/libvips/foreign/heifsave.c b/libvips/foreign/heifsave.c index 53cc4add..d9493ba6 100644 --- a/libvips/foreign/heifsave.c +++ b/libvips/foreign/heifsave.c @@ -162,6 +162,7 @@ vips_foreign_save_heif_write_page( VipsForeignSaveHeif *heif, int page ) struct heif_error error; struct heif_encoding_options *options; +#ifdef HAVE_HEIF_COLOR_PROFILE if( !save->strip && vips_image_get_typeof( save->ready, VIPS_META_ICC_NAME ) ) { const void *data; @@ -184,6 +185,7 @@ vips_foreign_save_heif_write_page( VipsForeignSaveHeif *heif, int page ) return( -1 ); } } +#endif /*HAVE_HEIF_COLOR_PROFILE*/ options = heif_encoding_options_alloc(); /* FIXME .. should be an option, though I don't know of any way to diff --git a/test/test-suite/test_foreign.py b/test/test-suite/test_foreign.py index d3acdf4c..35d44c72 100644 --- a/test/test-suite/test_foreign.py +++ b/test/test-suite/test_foreign.py @@ -843,7 +843,7 @@ class TestForeign: self.file_loader("heifload", HEIC_FILE, heif_valid) self.buffer_loader("heifload_buffer", HEIC_FILE, heif_valid) self.save_load_buffer("heifsave_buffer", "heifload_buffer", - self.colour, 70) + self.colour, 80) self.save_load("%s.heic", self.colour) # test lossless mode @@ -859,11 +859,13 @@ class TestForeign: assert len(b2) > len(b1) # try saving an image with an ICC profile and reading it back + # not all libheif have profile support, so put it in an if buf = self.colour.heifsave_buffer() im = pyvips.Image.new_from_buffer(buf, "") p1 = self.colour.get("icc-profile-data") - p2 = im.get("icc-profile-data") - assert p1 == p2 + if im.get_typeof("icc-profile-data") != 0: + p2 = im.get("icc-profile-data") + assert p1 == p2 # add tests for exif, xmp, ipct # the exif test will need us to be able to walk the header,