Skip to main content

soft_light_core

Function soft_light_core 

Source
pub fn soft_light_core(
    a: ArrayView2<'_, f32>,
    b: ArrayView2<'_, f32>,
    out: &mut Array2<f32>,
)
Expand description

Soft light blend of two 2-D arrays. The entry point for 2-D inputs.

§Arguments

  • a - ArrayView2<f32>, shape (H, W): the base layer, values nominally in [0, 1]. Any memory layout.
  • b - ArrayView2<f32>, shape (H, W): the blend layer, values nominally in [0, 1]. Any memory layout.
  • out - &mut Array2<f32>, shape (H, W): overwritten with the result, every element in [0, 1]. Its previous contents are ignored.

Runs serially below PARALLEL_THRESHOLD elements and in parallel at or above it.

§Panics

If a, b and out do not all have the same shape.

§Example

use ndarray::{array, Array2};
use terra_texture_rs::soft_light_core;

let base = array![[0.2_f32, 0.8], [0.5, 1.0]];
let blend = array![[0.5_f32, 0.5], [0.0, 1.0]];
let mut out = Array2::<f32>::zeros(base.raw_dim());
soft_light_core(base.view(), blend.view(), &mut out);

// blend = 0.5 leaves the base unchanged
assert!((out[[0, 0]] - 0.2).abs() < 1e-6);
assert!(out.iter().all(|&v| (0.0..=1.0).contains(&v)));