Skip to content

Commit f0ed595

Browse files
kleisaukeDarthSim
andauthored
Fix build with upcoming libjxl 0.9 (#3774)
* Fix build with upcoming libjxl 0.9 * jxlsave: prefer use of `JxlEncoderDistanceFromQuality` * jxlsave: lower min effort value to 1 (cherry picked from commit 4caf924) * Update lossy `jxlsave` thresholds for libjxl 0.9 --------- Co-authored-by: DarthSim <darthsim@gmail.com>
1 parent 04819e1 commit f0ed595

File tree

5 files changed

+16
-4
lines changed

5 files changed

+16
-4
lines changed

ChangeLog

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ TBD 8.15.1
22

33
- reduceh: fix Highway path on SSE2 [DarthSim]
44
- fix JPEG in TIFF colourspace for Q >= 90 [heman1-test]
5+
- fix build with upcoming libjxl 0.9 [kleisauke]
6+
- jxlsave: lower min effort value to 1 [DarthSim]
57

68
11/11/23 8.15.0
79

libvips/foreign/jxlload.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,9 @@ vips_foreign_load_jxl_header(VipsForeignLoad *load)
564564

565565
case JXL_DEC_COLOR_ENCODING:
566566
if (JxlDecoderGetICCProfileSize(jxl->decoder,
567+
#ifndef HAVE_LIBJXL_0_9
567568
&jxl->format,
569+
#endif
568570
JXL_COLOR_PROFILE_TARGET_DATA,
569571
&jxl->icc_size)) {
570572
vips_foreign_load_jxl_error(jxl,
@@ -583,7 +585,9 @@ vips_foreign_load_jxl_header(VipsForeignLoad *load)
583585
return -1;
584586

585587
if (JxlDecoderGetColorAsICCProfile(jxl->decoder,
588+
#ifndef HAVE_LIBJXL_0_9
586589
&jxl->format,
590+
#endif
587591
JXL_COLOR_PROFILE_TARGET_DATA,
588592
jxl->icc_data, jxl->icc_size)) {
589593
vips_foreign_load_jxl_error(jxl,

libvips/foreign/jxlsave.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,13 +243,16 @@ vips_foreign_save_jxl_build(VipsObject *object)
243243
return -1;
244244

245245
/* If Q is set and distance is not, use Q to set a rough distance
246-
* value. Formula stolen from cjxl.c and very roughly approximates
247-
* libjpeg values.
246+
* value.
248247
*/
249248
if (!vips_object_argument_isset(object, "distance"))
249+
#ifdef HAVE_LIBJXL_0_9
250+
jxl->distance = JxlEncoderDistanceFromQuality((float) jxl->Q);
251+
#else
250252
jxl->distance = jxl->Q >= 30
251253
? 0.1 + (100 - jxl->Q) * 0.09
252254
: 53.0 / 3000.0 * jxl->Q * jxl->Q - 23.0 / 20.0 * jxl->Q + 25.0;
255+
#endif
253256

254257
/* Distance 0 is lossless. libjxl will fail for lossy distance 0.
255258
*/
@@ -558,7 +561,7 @@ vips_foreign_save_jxl_class_init(VipsForeignSaveJxlClass *class)
558561
_("Encoding effort"),
559562
VIPS_ARGUMENT_OPTIONAL_INPUT,
560563
G_STRUCT_OFFSET(VipsForeignSaveJxl, effort),
561-
3, 9, 7);
564+
1, 9, 7);
562565

563566
VIPS_ARG_BOOL(class, "lossless", 13,
564567
_("Lossless"),

meson.build

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,9 @@ if libjxl_found
527527
if libjxl_dep.version().version_compare('>=0.7')
528528
cfg_var.set('HAVE_LIBJXL_0_7', '1')
529529
endif
530+
if libjxl_dep.version().version_compare('>=0.9')
531+
cfg_var.set('HAVE_LIBJXL_0_9', '1')
532+
endif
530533
endif
531534

532535
libpoppler_dep = dependency('poppler-glib', version: '>=0.16.0', required: get_option('poppler'))

test/test-suite/test_foreign.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1533,7 +1533,7 @@ def test_jxlsave(self):
15331533
# remove the ICC profile: the RGB one will no longer be appropriate
15341534
rgb16.remove("icc-profile-data")
15351535
self.save_load_buffer("jxlsave_buffer", "jxlload_buffer",
1536-
rgb16, 10700)
1536+
rgb16, 12000)
15371537

15381538
# repeat for lossless mode
15391539
self.save_load_buffer("jxlsave_buffer", "jxlload_buffer",

0 commit comments

Comments
 (0)