From 156e6a91e4cba186e99b8f48e64325c3bd85513d Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Sat, 18 Jun 2022 16:01:51 +0100 Subject: [PATCH] try to improve jxl lossless, again now seems to handle scrgb and srgb, lossless and lossy, with and without an ICC profile see https://github.com/libvips/libvips/issues/2872 --- libvips/foreign/jxlsave.c | 41 +++++++++------------------------------ 1 file changed, 9 insertions(+), 32 deletions(-) diff --git a/libvips/foreign/jxlsave.c b/libvips/foreign/jxlsave.c index ddd84f92..b1fe1b9f 100644 --- a/libvips/foreign/jxlsave.c +++ b/libvips/foreign/jxlsave.c @@ -34,8 +34,8 @@ */ /* -#define DEBUG */ +#define DEBUG #ifdef HAVE_CONFIG_H #include @@ -350,17 +350,21 @@ vips_foreign_save_jxl_build( VipsObject *object ) jxl->info.intensity_target = stonits; } - /* We will be setting the ICC profile, and/or calling - * JxlEncoderSetColorEncoding(). + /* uses_original_profile forces libjxl to not use lossy XYB + * colourspace. The name is very confusing. */ - jxl->info.uses_original_profile = TRUE; + jxl->info.uses_original_profile = jxl->lossless; if( JxlEncoderSetBasicInfo( jxl->encoder, &jxl->info ) ) { vips_foreign_save_jxl_error( jxl, "JxlEncoderSetBasicInfo" ); return( -1 ); } - /* Set ICC profile. + /* Set the colour encoding. Either ICC based, or sRGB. + * + * libjxl will use linear 0 - 1 by default for float, so we + * don't need to call JxlColorEncodingSetToLinearSRGB() or + * JxlColorEncodingSetToSRGB(). */ if( vips_image_get_typeof( in, VIPS_META_ICC_NAME ) ) { const void *data; @@ -381,33 +385,6 @@ vips_foreign_save_jxl_build( VipsObject *object ) } } - /* libjxl will use linear 0 - 1 by default for float, so we don't need - * to call JxlColorEncodingSetToLinearSRGB() or - * JxlColorEncodingSetToSRGB(). - */ - if( in->Type == VIPS_INTERPRETATION_scRGB ) { -#ifdef DEBUG - printf( "setting scRGB colourspace\n" ); -#endif /*DEBUG*/ - - JxlColorEncodingSetToLinearSRGB( &jxl->color_encoding, - jxl->format.num_channels < 3 ); - } - else { -#ifdef DEBUG - printf( "setting sRGB colourspace\n" ); -#endif /*DEBUG*/ - - JxlColorEncodingSetToSRGB( &jxl->color_encoding, - jxl->format.num_channels < 3 ); - } - - if( JxlEncoderSetColorEncoding( jxl->encoder, &jxl->color_encoding ) ) { - vips_foreign_save_jxl_error( jxl, - "JxlEncoderSetColorEncoding" ); - return( -1 ); - } - /* Render the entire image in memory. libjxl seems to be missing * tile-based write at the moment. */