jxl_render/features/
spot_colors.rs

1use jxl_grid::AlignedGrid;
2use jxl_image::ExtraChannelType;
3
4/// Renders a spot color channel onto color_channels
5pub fn render_spot_color(
6    mut color_channels: [&mut AlignedGrid<f32>; 3],
7    ec_grid: &AlignedGrid<f32>,
8    ec_ty: &ExtraChannelType,
9) -> crate::Result<()> {
10    let ExtraChannelType::SpotColour {
11        red,
12        green,
13        blue,
14        solidity,
15    } = ec_ty
16    else {
17        return Err(crate::Error::NotSupported("EC type is not SpotColour"));
18    };
19    if color_channels.len() != 3 {
20        return Ok(());
21    }
22
23    let spot_colors = [red, green, blue];
24    let s = ec_grid.buf();
25
26    (0..3).for_each(|c| {
27        let channel = color_channels[c].buf_mut();
28        let color = spot_colors[c];
29        assert_eq!(channel.len(), s.len());
30
31        (0..channel.len()).for_each(|i| {
32            let mix = s[i] * solidity;
33            channel[i] = mix * color + (1.0 - mix) * channel[i];
34        });
35    });
36    Ok(())
37}