Skip to main content

luminosity_blend_core

Function luminosity_blend_core 

Source
pub fn luminosity_blend_core(
    backdrop_rgb: ArrayView3<'_, f32>,
    luminosity: ArrayView2<'_, f32>,
    out: &mut Array3<f32>,
)
Expand description

Replace the luminance of an RGB image with a target luminance, keeping its hue and saturation. The entry point for this blend.

§Arguments

  • backdrop_rgb - ArrayView3<f32>, shape (H, W, 3): the colour image, channels in R, G, B order, values nominally in [0, 1].
  • luminosity - ArrayView2<f32>, shape (H, W): the target luminance per pixel (e.g. a hillshade), values nominally in [0, 1].
  • out - &mut Array3<f32>, shape (H, W, 3): overwritten with the blended RGB image, every element in [0, 1].

Runs serially below PARALLEL_THRESHOLD pixels (H × W, not H × W × 3) and in parallel at or above it.

§Panics

  • If backdrop_rgb, luminosity and out disagree on H.
  • If the channel axis of backdrop_rgb or out has fewer than 3 entries (out-of-bounds index).

Shapes are only checked by indexing, so some mismatches pass silently instead of panicking: a W mismatch where backdrop_rgb or luminosity is wider than out ignores the extra columns, and a channel count above 3 reads and writes only channels 0 to 2. Always pass matching (H, W) and exactly 3 channels.

§Example

use ndarray::{Array2, Array3};
use terra_texture_rs::luminosity_blend_core;

// a flat mid-grey image, relit to luminance 0.8
let backdrop = Array3::<f32>::from_elem((2, 2, 3), 0.5);
let lum = Array2::<f32>::from_elem((2, 2), 0.8);
let mut out = Array3::<f32>::zeros(backdrop.raw_dim());
luminosity_blend_core(backdrop.view(), lum.view(), &mut out);

// grey stays grey, now at the target luminance
assert!(out.iter().all(|&v| (v - 0.8).abs() < 1e-5));