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
This commit is contained in:
John Cupitt 2022-06-18 16:01:51 +01:00
parent 9c22d74cff
commit 156e6a91e4

View File

@ -34,8 +34,8 @@
*/
/*
#define DEBUG
*/
#define DEBUG
#ifdef HAVE_CONFIG_H
#include <config.h>
@ -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.
*/