65 lines
2.3 KiB
Rust
65 lines
2.3 KiB
Rust
//! Regression coverage for optimized Normal-blend adjustment compositing.
|
|
//!
|
|
//! **Purpose:** Verifies that bypassing the generic blend dispatcher preserves
|
|
//! exact RGB output for opaque and partially opaque adjustments.
|
|
//! **Logic & Workflow:** Builds a one-pixel base and Curves layer, composites
|
|
//! through the public tiled path, and compares deterministic channel values.
|
|
//! **Side Effects / Dependencies:** Allocates only one-pixel protocol layers.
|
|
|
|
use hcie_blend::Adjustment;
|
|
use hcie_composite::tiled::composite_tiled;
|
|
use hcie_protocol::Layer;
|
|
use hcie_tile::TiledLayer;
|
|
|
|
/// Builds a Curves adjustment whose lookup tables map selected input channels.
|
|
///
|
|
/// **Arguments:** `opacity` controls the layer-level adjustment mix.
|
|
/// **Returns:** A one-pixel adjustment layer. **Side Effects / Dependencies:** None.
|
|
fn curves_layer(opacity: f32) -> Layer {
|
|
let mut lut_r: Vec<u8> = (0..=255).map(|value| value as u8).collect();
|
|
let mut lut_g = lut_r.clone();
|
|
let mut lut_b = lut_r.clone();
|
|
lut_r[10] = 100;
|
|
lut_g[20] = 110;
|
|
lut_b[30] = 120;
|
|
|
|
let mut layer = Layer::new_transparent("Curves", 1, 1);
|
|
layer.adjustment = Some(Adjustment::Curves {
|
|
lut_r,
|
|
lut_g,
|
|
lut_b,
|
|
});
|
|
layer.opacity = opacity;
|
|
layer
|
|
}
|
|
|
|
/// Confirms a fully opaque Normal adjustment assigns the LUT result exactly.
|
|
#[test]
|
|
fn opaque_normal_adjustment_matches_lookup_result() {
|
|
let base = Layer::from_rgba("Base", 1, 1, vec![10, 20, 30, 255]);
|
|
let adjustment = curves_layer(1.0);
|
|
let tiles = vec![
|
|
Some(TiledLayer::from_dense(&base.pixels, 1, 1)),
|
|
Some(TiledLayer::from_dense(&adjustment.pixels, 1, 1)),
|
|
];
|
|
|
|
let output = composite_tiled(&[base, adjustment], &tiles, 1, 1);
|
|
|
|
assert_eq!(output, vec![100, 110, 120, 255]);
|
|
}
|
|
|
|
/// Confirms partial opacity retains the previous rounded interpolation behavior.
|
|
#[test]
|
|
fn partial_normal_adjustment_preserves_rounded_interpolation() {
|
|
let base = Layer::from_rgba("Base", 1, 1, vec![10, 20, 30, 255]);
|
|
let adjustment = curves_layer(0.5);
|
|
let tiles = vec![
|
|
Some(TiledLayer::from_dense(&base.pixels, 1, 1)),
|
|
Some(TiledLayer::from_dense(&adjustment.pixels, 1, 1)),
|
|
];
|
|
|
|
let output = composite_tiled(&[base, adjustment], &tiles, 1, 1);
|
|
|
|
assert_eq!(output, vec![55, 65, 75, 255]);
|
|
}
|