Skip to content

Commit

Permalink
jxl-render: Fix requested color encoding not applied in some cases (#369
Browse files Browse the repository at this point in the history
)

* jxl-render: Fix requested color encoding not applied in some cases

* Update CHANGELOG.md
  • Loading branch information
tirr-c authored Oct 29, 2024
1 parent 9384537 commit 885c953
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 9 additions & 5 deletions crates/jxl-render/src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -730,17 +730,21 @@ impl<S: Sample> RenderedImage<S> {
}
}

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(),
Expand Down
6 changes: 1 addition & 5 deletions crates/jxl-render/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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);
}

Expand Down
6 changes: 4 additions & 2 deletions crates/jxl-render/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(())
}

Expand Down

0 comments on commit 885c953

Please sign in to comment.