From 885c953cacb490a25907c37c3041d656ddd74d19 Mon Sep 17 00:00:00 2001 From: Wonwoo Choi Date: Tue, 29 Oct 2024 16:37:41 +0900 Subject: [PATCH] jxl-render: Fix requested color encoding not applied in some cases (#369) * jxl-render: Fix requested color encoding not applied in some cases * Update CHANGELOG.md --- CHANGELOG.md | 3 +++ crates/jxl-render/src/image.rs | 14 +++++++++----- crates/jxl-render/src/lib.rs | 6 +----- crates/jxl-render/src/util.rs | 6 ++++-- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3652f931..0ba902db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - `jxl-color`: Use better PQ to HLG method (#348). +### Fixed +- `jxl-render`: Fix requested color encoding not applied in some cases (#369). + ## [0.9.1] - 2024-10-12 ### Fixed diff --git a/crates/jxl-render/src/image.rs b/crates/jxl-render/src/image.rs index a8f71756..59aecdd1 100644 --- a/crates/jxl-render/src/image.rs +++ b/crates/jxl-render/src/image.rs @@ -730,17 +730,21 @@ impl RenderedImage { } } - if !frame_header.frame_type.is_normal_frame() || frame_header.resets_canvas { + let skip_blending = + !frame_header.frame_type.is_normal_frame() || frame_header.resets_canvas; + + if !(grid.ct_done() || frame_header.save_before_ct || skip_blending && frame_header.is_last) + { + util::convert_color_for_record(image_header, frame_header.do_ycbcr, &mut grid, pool)?; + } + + if skip_blending { grid.blend_done = true; let image = Arc::new(grid); *grid_lock = FrameRender::Blended(Arc::clone(&image)); return Ok(image); } - if !grid.ct_done() { - util::convert_color_for_record(image_header, frame_header.do_ycbcr, &mut grid, pool)?; - } - let image = crate::blend::blend( image_header, self.image.refs.clone(), diff --git a/crates/jxl-render/src/lib.rs b/crates/jxl-render/src/lib.rs index 4d2db6a6..cd2024cc 100644 --- a/crates/jxl-render/src/lib.rs +++ b/crates/jxl-render/src/lib.rs @@ -805,10 +805,6 @@ impl RenderContext { tracing::trace!(requested_color_encoding = ?self.requested_color_encoding); tracing::trace!(do_ycbcr = frame_header.do_ycbcr); - if grid.ct_done() { - return Ok(grid); - } - let mut transform = jxl_color::ColorTransform::builder(); transform.set_srgb_icc(!self.cms.supports_linear_tf()); transform.from_pq(self.suggested_hdr_tf() == Some(jxl_color::TransferFunction::Pq)); @@ -818,7 +814,7 @@ impl RenderContext { &metadata.opsin_inverse_matrix, &metadata.tone_mapping, )?; - if transform.is_noop() && !frame_header.do_ycbcr { + if grid.ct_done() || (transform.is_noop() && !frame_header.do_ycbcr) { return Ok(grid); } diff --git a/crates/jxl-render/src/util.rs b/crates/jxl-render/src/util.rs index 0d6e0875..040bd740 100644 --- a/crates/jxl-render/src/util.rs +++ b/crates/jxl-render/src/util.rs @@ -325,6 +325,8 @@ pub(crate) fn convert_color_for_record( if metadata.colour_encoding.colour_space() == ColourSpace::Grey { fb.remove_color_channels(1); } + + fb.set_ct_done(true); } else if metadata.xyb_encoded { // want_icc = false || is_last = true // in any case, blending does not occur when want_icc = true @@ -367,10 +369,10 @@ pub(crate) fn convert_color_for_record( fb.remove_color_channels(output_channels); Ok(()) })?; + + fb.set_ct_done(true); } - // color transform is done - fb.set_ct_done(true); Ok(()) }