From 6acb5fde3e620b8c4d3276158dc1b62764a993af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Novomesk=C3=BD?= Date: Sat, 1 Jan 2022 17:40:52 +0100 Subject: [PATCH] configure, meson: bump libjxl dependency to 0.6.1 JPEG XL plug-in always imported all JXL images in 32-bit float precision in the past. Now it also supports direct import in 8-bit and 16-bit integer precision too. --- configure.ac | 2 +- meson.build | 2 +- plug-ins/common/file-jpegxl.c | 34 +++++++++++++++++++++++++++++----- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/configure.ac b/configure.ac index 4d9de9d605..aa8ace294c 100644 --- a/configure.ac +++ b/configure.ac @@ -75,7 +75,7 @@ m4_define([json_glib_required_version], [1.2.6]) m4_define([lcms_required_version], [2.8]) m4_define([libgudev_required_version], [167]) m4_define([libheif_required_version], [1.3.2]) -m4_define([libjxl_required_version], [0.5.0]) +m4_define([libjxl_required_version], [0.6.1]) m4_define([liblzma_required_version], [5.0.0]) m4_define([libmypaint_required_version], [1.3.0]) m4_define([libpng_required_version], [1.6.25]) diff --git a/meson.build b/meson.build index cb353ec138..2f9527ee46 100644 --- a/meson.build +++ b/meson.build @@ -800,7 +800,7 @@ if openjpeg.found() MIMEtypes += [ 'image/jp2', 'image/jpeg2000', 'image/jpx', ] endif -jpegxl_minver = '0.5.0' +jpegxl_minver = '0.6.1' libjxl = dependency('libjxl', version: '>='+jpegxl_minver, required: get_option('jpeg-xl') diff --git a/plug-ins/common/file-jpegxl.c b/plug-ins/common/file-jpegxl.c index d4d5743fcd..86802b2ead 100644 --- a/plug-ins/common/file-jpegxl.c +++ b/plug-ins/common/file-jpegxl.c @@ -214,12 +214,15 @@ load_image (GFile *file, size_t icc_size = 0; GimpColorProfile *profile = NULL; gboolean loadlinear = FALSE; + size_t channel_depth; size_t result_size; gpointer picture_buffer; GimpImage *image; GimpLayer *layer; GeglBuffer *buffer; + GimpPrecision precision_linear; + GimpPrecision precision_non_linear; if (!inputFile) { @@ -374,7 +377,28 @@ load_image (GFile *file, pixel_format.endianness = JXL_NATIVE_ENDIAN; pixel_format.align = 0; - pixel_format.data_type = JXL_TYPE_FLOAT; + + if (basicinfo.bits_per_sample <= 8) + { + pixel_format.data_type = JXL_TYPE_UINT8; + channel_depth = 1; + precision_linear = GIMP_PRECISION_U8_LINEAR; + precision_non_linear = GIMP_PRECISION_U8_NON_LINEAR; + } + else if (basicinfo.bits_per_sample > 16) + { + pixel_format.data_type = JXL_TYPE_FLOAT; + channel_depth = 4; + precision_linear = GIMP_PRECISION_FLOAT_LINEAR; + precision_non_linear = GIMP_PRECISION_FLOAT_NON_LINEAR; + } + else + { + pixel_format.data_type = JXL_TYPE_UINT16; + channel_depth = 2; + precision_linear = GIMP_PRECISION_U16_LINEAR; + precision_non_linear = GIMP_PRECISION_U16_NON_LINEAR; + } if (basicinfo.num_color_channels == 1) /* grayscale */ { @@ -400,7 +424,7 @@ load_image (GFile *file, } } - result_size = 4 * pixel_format.num_channels * (size_t) basicinfo.xsize * (size_t) basicinfo.ysize; + result_size = channel_depth * pixel_format.num_channels * (size_t) basicinfo.xsize * (size_t) basicinfo.ysize; if (JxlDecoderGetColorAsEncodedProfile (decoder, &pixel_format, JXL_COLOR_PROFILE_TARGET_DATA, @@ -551,7 +575,7 @@ load_image (GFile *file, if (basicinfo.num_color_channels == 1) /* grayscale */ { image = gimp_image_new_with_precision (basicinfo.xsize, basicinfo.ysize, GIMP_GRAY, - loadlinear ? GIMP_PRECISION_FLOAT_LINEAR : GIMP_PRECISION_FLOAT_NON_LINEAR); + loadlinear ? precision_linear : precision_non_linear); if (profile) { @@ -569,7 +593,7 @@ load_image (GFile *file, else /* RGB */ { image = gimp_image_new_with_precision (basicinfo.xsize, basicinfo.ysize, GIMP_RGB, - loadlinear ? GIMP_PRECISION_FLOAT_LINEAR : GIMP_PRECISION_FLOAT_NON_LINEAR); + loadlinear ? precision_linear : precision_non_linear); if (profile) { @@ -723,7 +747,7 @@ save_image (GFile *file, drawable_width = gimp_drawable_get_width (drawable); drawable_height = gimp_drawable_get_height (drawable); - memset (&output_info, 0, sizeof output_info); + JxlEncoderInitBasicInfo(&output_info); if (uses_original_profile) {