From f36196db1b6a4a9ca0958b0f7e10d21ca5a5ccb1 Mon Sep 17 00:00:00 2001 From: Kleis Auke Wolthuizen Date: Sun, 14 Aug 2022 16:54:21 +0200 Subject: [PATCH] jxlsave: avoid using deprecated functions (#2989) * jxlsave: avoid using deprecated functions The upcoming libjxl 0.7 has deprecated a number of functions. * Prefer to use `ifdef` instead --- configure.ac | 7 +++++++ libvips/foreign/jxlsave.c | 30 ++++++++++++++++++++++-------- meson.build | 3 +++ 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/configure.ac b/configure.ac index 04a0da51..3573a76e 100644 --- a/configure.ac +++ b/configure.ac @@ -847,6 +847,13 @@ if test x"$with_libjxl" != x"no"; then with_libjxl=yes AS_IF([test x"$with_libjxl_module" = x"no"], [PACKAGES_USED="$PACKAGES_USED libjxl"]) + + PKG_CHECK_MODULES(LIBJXL_0_7, libjxl >= 0.7, + [AC_DEFINE(HAVE_LIBJXL_0_7,1,[define if you have libjxl >= 0.7]) + ], + [: + ] + ) ], [AS_IF([test x"$with_libjxl" = x"test"], AC_MSG_WARN([libjxl not found; disabling libjxl support]), diff --git a/libvips/foreign/jxlsave.c b/libvips/foreign/jxlsave.c index cd2c51b7..9c49b95d 100644 --- a/libvips/foreign/jxlsave.c +++ b/libvips/foreign/jxlsave.c @@ -229,7 +229,11 @@ vips_foreign_save_jxl_build( VipsObject *object ) VipsForeignSaveJxl *jxl = (VipsForeignSaveJxl *) object; VipsImage **t = (VipsImage **) vips_object_local_array( object, 5 ); - JxlEncoderOptions *options; +#ifdef HAVE_LIBJXL_0_7 + JxlEncoderFrameSettings *frame_settings; +#else + JxlEncoderOptions *frame_settings; +#endif JxlEncoderStatus status; VipsImage *in; VipsBandFormat format; @@ -415,23 +419,33 @@ vips_foreign_save_jxl_build( VipsObject *object ) if( vips_image_wio_input( in ) ) return( -1 ); - options = JxlEncoderOptionsCreate( jxl->encoder, NULL ); - JxlEncoderOptionsSetDecodingSpeed( options, jxl->tier ); - JxlEncoderOptionsSetDistance( options, jxl->distance ); - JxlEncoderOptionsSetEffort( options, jxl->effort ); - JxlEncoderOptionsSetLossless( options, jxl->lossless ); +#ifdef HAVE_LIBJXL_0_7 + frame_settings = JxlEncoderFrameSettingsCreate( jxl->encoder, NULL ); + JxlEncoderFrameSettingsSetOption( frame_settings, + JXL_ENC_FRAME_SETTING_DECODING_SPEED, jxl->tier ); + JxlEncoderSetFrameDistance( frame_settings, jxl->distance ); + JxlEncoderFrameSettingsSetOption( frame_settings, + JXL_ENC_FRAME_SETTING_EFFORT, jxl->effort ); + JxlEncoderSetFrameLossless( frame_settings, jxl->lossless ); +#else + frame_settings = JxlEncoderOptionsCreate( jxl->encoder, NULL ); + JxlEncoderOptionsSetDecodingSpeed( frame_settings, jxl->tier ); + JxlEncoderOptionsSetDistance( frame_settings, jxl->distance ); + JxlEncoderOptionsSetEffort( frame_settings, jxl->effort ); + JxlEncoderOptionsSetLossless( frame_settings, jxl->lossless ); +#endif #ifdef DEBUG vips_foreign_save_jxl_print_info( &jxl->info ); vips_foreign_save_jxl_print_format( &jxl->format ); - printf( "JxlEncoderOptions:\n" ); + printf( "JxlEncoderFrameSettings:\n" ); printf( " tier = %d\n", jxl->tier ); printf( " distance = %g\n", jxl->distance ); printf( " effort = %d\n", jxl->effort ); printf( " lossless = %d\n", jxl->lossless ); #endif /*DEBUG*/ - if( JxlEncoderAddImageFrame( options, &jxl->format, + if( JxlEncoderAddImageFrame( frame_settings, &jxl->format, VIPS_IMAGE_ADDR( in, 0, 0 ), VIPS_IMAGE_SIZEOF_IMAGE( in ) ) ) { vips_foreign_save_jxl_error( jxl, "JxlEncoderAddImageFrame" ); diff --git a/meson.build b/meson.build index d5fd4dfe..1040b6a8 100644 --- a/meson.build +++ b/meson.build @@ -484,6 +484,9 @@ if libjxl_found if cc.has_function('JxlEncoderInitBasicInfo', prefix: '#include ', dependencies: libjxl_dep) cfg_var.set('HAVE_LIBJXL_JXLENCODERINITBASICINFO', '1') endif + if libjxl_dep.version().version_compare('>=0.7') + cfg_var.set('HAVE_LIBJXL_0_7', '1') + endif endif libpoppler_dep = dependency('poppler-glib', version: '>=0.16.0', required: get_option('poppler'))